ConceptioArchivearXiv CS
arXiv CSopen access

Tractable Gap-Constraint Languages for Complex Event Recognition

Unknown · 2026 · arxiv_cs
arXiv CS · Papers · License: Open Access · 2026
Open Source ↗Direct PDF ↓
databasesdatamanagementsqlstorage
databases, sql, data management, storage

Tractable Gap-Constraint Languages for Complex Event Recognition

arXiv:2606.18878v1 [cs.DS] 17 Jun 2026

ANTOINE AMARILLI, Univ. Lille, Inria, CNRS, Centrale Lille, UMR 9189 CRIStAL, France FLORIN MANEA, University of Göttingen, Institute for Computer Science and CIDAS, Germany TINA RINGLEB, University of Göttingen, Institute for Computer Science and CIDAS, Germany MARKUS L. SCHMID, Humboldt-Universität zu Berlin, Germany For strings 𝑢, D ∈ Σ∗ , a subsequence embedding of 𝑢 in D is a function 𝑒 : {1, 2, . . . , |𝑢 |} → {1, 2, . . . , |D|} with 𝑒 (𝑖) < 𝑒 (𝑖 + 1) for every 𝑖 ∈ {1, 2, . . . , |𝑢 | − 1} and the 𝑖 th symbol of 𝑢 equals the 𝑒 (𝑖) th symbol of D. A gap-constraint for 𝑢 is a triple (𝑖, 𝑗, 𝐿) with 1 ≤ 𝑖 < 𝑗 ≤ |𝑢 | and 𝐿 is a regular language over Σ. An embedding 𝑒 satisfies a gap-constraint (𝑖, 𝑗, 𝐿) if the factor of D strictly between positions 𝑒 (𝑖) and 𝑒 ( 𝑗) is a word from 𝐿. We investigate the subsequence matching problem with gap-constraints, which is relevant in the context of complex event recognition (CER): given 𝑢, D ∈ Σ∗ and a set C of gap-constraints, find an embedding of 𝑢 in D that satisfies all gap-constraints from C. In general, subsequence matching is NP-complete and the only known tractable variants restrict the interval structure of the gap-constraints. In this work, we show that we can solve subsequence matching with gap-constraints with an arbitrary interval structure rather efficiently (in fact, optimally under SETH) in time 𝑂 (|D|(|𝑢 | + ∥C∥)) if the gap-constraint languages satisfy a property which we dub left-convexity: whenever 𝑢𝑣𝑤 ∈ 𝐿 and 𝑣 ∈ 𝐿, then also 𝑢𝑣 ∈ 𝐿. Left-convex languages are sufficiently expressive to model interesting real-world scenarios considered in CER, e.g., length constraints 𝐿 = {𝑤 | 𝑎 ≤ |𝑤 | ≤ 𝑏} for 𝑎, 𝑏 ∈ N. We also show how our algorithm can be used in order to efficiently enumerate all satisfying embeddings, which is particularly relevant for possible applications in CER. Finally, we show how non-left-convex languages can lead to intractability, i.e., if in addition to length constraints we allow {aa, 𝜀} as the only non-left-convex constraint language, then the problem is NP-complete again.

1

Introduction

In complex event recognition (CER), we receive a long sequence of events generated by the run of a large system (e.g., a distributed computer system with many interacting components, or a surveillance system that continuously produces measurements); see the introductions of the surveys [7, 28]. The task is to process the received event sequence and search for certain patterns (i.e., strings of events), which are called complex events. This explains why several query languages for CER are rooted in pattern matching and automata theory (see [4, 30, 67]). However, CER deviates from the classical string pattern matching paradigm because pattern occurrences are formalised as subsequences rather than consecutive factors, and there are additional constraints on how the subsequences are embedded (e.g., by asking for two events of type A that are not separated by an event of type B), which often amounts to regular constraints on some gaps in the embeddings. A reasonable mathematical abstraction of (a core functionality of) CER is therefore subsequence matching with (regular) gap-constraints. This task is defined as searching for a suitable embedding of a string 𝑢 ∈ Σ∗ (over some finite alphabet Σ) in a larger document D ∈ Σ∗ , namely, a total function 𝑒 : {1, 2, . . . , |𝑢 |} → {1, 2, . . . , |D|} such that 𝑒 (𝑖) < 𝑒 (𝑖 + 1) for every 𝑖 ∈ {1, 2, . . . , |𝑢 | − 1} and 𝑢 [𝑖] = D[𝑒 (𝑖)] for every 𝑖 ∈ {1, 2, . . . , |𝑢 |} (i.e., the 𝑖-th symbol of 𝑢 equals the 𝑒 (𝑖)-th symbol of D). If 𝑒 exists, then 𝑢 is also called a (scattered) subsequence of D. Finding an embedding of 𝑢 in D is a trivial computational task that can be solved greedily in linear time. However, the situation becomes more interesting if we require 𝑒 to satisfy some additional constraints, and motivated Authors’ Contact Information: Antoine Amarilli, [email protected], Univ. Lille, Inria, CNRS, Centrale Lille, UMR 9189 CRIStAL, F-59000 Lille, France; Florin Manea, [email protected], University of Göttingen, Institute for Computer Science and CIDAS, D-37077 Göttingen, Germany; Tina Ringleb, [email protected], University of Göttingen, Institute for Computer Science and CIDAS, D-37077 Göttingen, Germany; Markus L. Schmid, [email protected], Humboldt-Universität zu Berlin, Unter den Linden 6, D-10099, Berlin, Germany.

, Vol. 1, No. 1, Article . Publication date: June 2026.

2

Antoine Amarilli, Florin Manea, Tina Ringleb, and Markus L. Schmid

u=

D=

c

a

a

a

b

b

b

a

b

c

a

b

a

c

b

c

gap constraints: (1, 3, {ambn | m, n ≥ 0}) (2, 4, {w | 3 ≤ |w| ≤ 6}) (1, 4, {w | |w|b ≥ 5})

(1, 3)-gap (2, 4)-gap (1, 4)-gap

Fig. 1. Example of an embedding of 𝑢 in D with gap-constraints (here, |𝑤 |𝑥 denotes the number of occurrences of letter 𝑥 in the string 𝑤).

by the CER setting we are concerned with so-called gap-constraints. For every 𝑖, 𝑗 ∈ {1, 2, . . . , |𝑢 |} with 𝑖 < 𝑗, the (𝑖, 𝑗)-gap induced by 𝑒 is the factor D[𝑒 (𝑖) + 1 : 𝑒 ( 𝑗) − 1], i.e., the factor of D strictly between the images of 𝑖 and 𝑗 under 𝑒. A gap-constraint is a triple (𝑖, 𝑗, 𝐿) with 1 ≤ 𝑖 < 𝑗 ≤ |𝑢 | and 𝐿 ⊆ Σ∗ , and the embedding 𝑒 satisfies (𝑖, 𝑗, 𝐿) if and only if the (𝑖, 𝑗)-gap induced by 𝑒 is in 𝐿. If 𝐿 is a regular language, then (𝑖, 𝑗, 𝐿) is a regular gap-constraint. Figure 1 illustrates an example for 𝑢 = abac and D = caabbbabacbc, and three gap-constraints displayed at the right. In general, there are several possible embeddings of 𝑢 in D, but the specific one illustrated by the arrows in Figure 1 is one that satisfies all three gap-constraints. If we change 𝑒 (4) from 12 to 10, we still have an embedding of 𝑢 in D, but the (1, 4)-gap D[3 : 9] = abbbaba has only 4 occurrences of b and therefore does not satisfy the (1, 4)-gap-constraint. Changing 𝑒 (2) from 5 to 4 violates the (2, 4)-gap-constraint, while changing 𝑒 (2) from 5 to 6 results in an embedding that still satisfies all gap-constraints. Coming back to the literature on CER, we observe that, inspired by the SASE-language [4, 65, 67], the papers [24, 25, 41, 42, 56, 57] introduce and investigate subsequence queries with gap-constraints.1 In this model, a string and a set of gap-constraints is interpreted as a query, and the corresponding result set contains all embeddings of the string into the event sequence such that all gap-constraints are satisfied. An important observation is that CER scenarios mostly consider very simple constraint languages – both in practically motivated settings and in their theoretical abstractions – with the most prominent example of a very simple yet practically relevant such class being so-called length constraints, i.e., gap-constraints (𝑖, 𝑗, 𝐿) with 𝐿 = {𝑤 ∈ Σ∗ | 𝑎 ≤ |𝑤 | ≤ 𝑏} for some 𝑎, 𝑏 ∈ N ∪ {0}. More precisely, the initial model of [41] considers length constraints and only allows constraints between neighbouring positions. In [24], this setting has been extended to possibly overlapping gap-constraints between arbitrary positions (a feature also used in the example from Figure 1), and the query language of the recent proposal [27] can also formulate overlapping gap-constraints. Motivated by CER, we are interested in the following tasks: Given 𝑢, D ∈ Σ∗ and a set C of regular gap-constraints, (1) compute a C-embedding (i.e., one that satisfies the constraints of C) of 𝑢 in D, or report that none exists; (2) enumerate all such C-embeddings with bounded delay. As a first step, we observe that task (1) has already been investigated in the literature on string pattern matching. Particularly relevant to us is [19], where the authors investigate subsequence matching with arbitrary regular gap-constraints and with length constraints (note that although length constraints are a special case of regular constraints, they can be concisely represented by two numbers written in binary, which can have an impact on the complexity). Moreover, [19] only considers constraints between neighbouring positions (like [41] mentioned above), while the general case of regular gap-constraints between arbitrary pairs of positions has been investigated in [50]. In this work [50], it is also shown that task (1) is NP-complete in general, but it becomes tractable if 1 The queries investigated in these papers also allow variables in order to model equality constraints of the SASE-language.

This is a functionality that goes beyond the setting of this paper and is also well-known to lead to intractability (see [41]).

, Vol. 1, No. 1, Article . Publication date: June 2026.

Tractable Gap-Constraint Languages for Complex Event Recognition

3

the gap-constraints have a restricted nested structure, namely, for any two gap-constraints (𝑖, 𝑗, 𝐿) and (𝑖 ′, 𝑗 ′, 𝐿), we have that 𝑗 ≤ 𝑖 ′ or 𝑗 ′ ≤ 𝑖 or 𝑖 ≤ 𝑖 ′ < 𝑗 ′ ≤ 𝑗 or 𝑖 ′ ≤ 𝑖 < 𝑗 ≤ 𝑗 ′ . In terms of the CER setting, a drawback of the intractability result of [50] is that the case of simple constraint languages is neglected. As possible examples of such languages we have already mentioned length constraints, but other simple language classes with conceivable practical relevance are easily found: alphabet restrictions, i.e., languages Γ ∗ for Γ ⊊ Σ; singleton languages; languages that upper and lower bound the number of occurrences of certain symbols; languages with unique start or end delimiters; languages defined by forbidden and required factors; etc. For such language classes, the hardness result of [50] does not apply. This motivates the study of the scenario where the structure of the gap-constraints is unrestricted, but the constraint languages are from some simple class of languages. Surprisingly, even the tractability of task (1) in the case of only length constraints (or in the case of only singleton languages) is still open.2 Thus, our goal in this paper is to find classes of simple constraint languages for which subsequence matching with gap-constraints can be done efficiently. As usual in data management tasks, we are interested in algorithms that are linear in the size of the data (i.e., the document D), and instead of just solving decision problems (or computing a single witness), we are interested in efficiently computing the whole set of solutions by enumerating them with bounded delay (i.e., task (2) mentioned above). 1.1

Our Contribution

As a first step, we observe that known results in the field of constraint satisfaction problems (CSP) can be used in a black-box fashion in order to obtain an efficient algorithm for restricted cases of our task (1). Namely, we call a set C of regular gap-constraints min-closed for some 𝑢, D ∈ Σ∗ if for every two C-embeddings 𝑒, 𝑒 ′ : {1, . . . , |𝑢 |} → {1, . . . , |D|}, their pointwise minimum 𝑒 min is also a C-embedding (where we define 𝑒 min (𝑥) ≔ min{𝑒 (𝑥), 𝑒 ′ (𝑥)} for every 𝑥 ∈ {1, . . . , |𝑢 |}). For min-closed instances, we can show the following result, where ∥C∥ is the total size of all regular expressions that represent the regular gap-constraints. Theorem 1.1. Restricted to min-closed instances, task (1) can be solved in time 𝑂 ((|𝑢 | + ∥C∥)|D| 2 ). It is not difficult to see that instances with only length constraints are necessarily min-closed, which already answers one of the open questions mentioned above. In general, for a given instance 𝑢, D ∈ Σ∗ and C, we can check in polynomial time whether C is min-closed for 𝑢 and D. While this first result is a relevant observation, it seems to be of limited value in the context of CER, since the same set of gap-constraints might be min-closed for some pair (𝑢, D), but not for another pair (𝑢, D′ ); thus, the min-closed property does not yield a reasonable query class. Instead, we are interested in finding language classes such that queries using constraints from these classes are necessarily tractable on every possible document D. Moreover, our main focus is not a complexity classification with respect to task (1), but finding efficient and natural algorithms for also solving task (2), for which the CSP meta-theorems do not seem to be helpful. We identify a rather simple language property, called left-convexity, which (as we will show) serves as a unifying explanation of the tractability of many cases: Definition 1.2. A language 𝐿 ⊆ Σ∗ is left-convex if, for all 𝑢, 𝑣, 𝑤 ∈ Σ∗ , whenever 𝑢𝑣𝑤 ∈ 𝐿 and 𝑣 ∈ 𝐿, then 𝑢𝑣 ∈ 𝐿. A gap-constraint (𝑖, 𝑗, 𝐿) is left-convex if 𝐿 is a left-convex regular language. Intuitively speaking, left-convexity of 𝐿 means that if a factor in a word from 𝐿 is also from 𝐿, then the whole prefix including this factor must be in 𝐿. For example, length constraints are left-convex, and so are all the languages of the example given in Figure 1. The name “left-convex” is inspired by 2 These questions were posed at the Dagstuhl Seminar 24472 “Regular Expressions: Matching and Indexing” [29, Section 3.11].

, Vol. 1, No. 1, Article . Publication date: June 2026.

4

Antoine Amarilli, Florin Manea, Tina Ringleb, and Markus L. Schmid

other notions of convexity for formal languages as investigated in [5, 6, 15, 63], but to the best of our knowledge the specific left-convex property defined above has not been considered earlier in the literature. The symmetric notion of right-convex is analogous and all our results for left-convex gap-constraints also hold for right-convex gap-constraints. See Appendix A for more information (including language theoretical considerations and several examples of left-convex classes). The point of left-convexity is the following: we can show that whenever C only contains leftconvex constraint languages then C is necessarily min-closed for every 𝑢, D ∈ Σ∗ . Hence, as a direct consequence of Theorem 1.1, if C only contains left-convex constraint languages, then we can solve task (1) in time 𝑂 ((|𝑢 | + ∥C∥)|D| 2 ). For data management, the quadratic dependency on the data size |D| is unrealistic, so we give an algorithm that makes it linear, with the following structure. We maintain a candidate mapping 𝑒 : {1, . . . , |𝑢 |} → {1, . . . , |D|}, which is initialised with 𝑒 (𝑖) = 𝑖 for every 𝑖 ∈ {1, . . . , |𝑢 |}. As long as 𝑒 is not a C-embedding of 𝑢 in D that satisfies all constraints from C, we move some position 𝑖 to the right, i.e., we set 𝑒 (𝑖) ≔ 𝑒 (𝑖) + 𝑐, until we have found such a satisfying embedding. This requires us to efficiently answer queries of the form D[𝑒 (𝑖) + 1 : 𝑒 ( 𝑗) − 1] ∈ 𝐿, which we show can be done because of left-convexity by computing, for every 𝑘 ∈ [|D|] and language 𝐿 with (𝑖, 𝑗, 𝐿) ∈ C, the size of a longest factor of D starting at position 𝑘 + 1 that is contained in 𝐿. In the following informal statements of our main results, we let 𝑢, D ∈ Σ∗ and C be a set of regular left-convex gap-constraints for 𝑢. We then have: Theorem 1.3. We can compute a C-embedding of 𝑢 in D, or report that no such embedding exists, in time 𝑂 (|D|(|𝑢 | + ∥C∥)). This algorithm is optimal, assuming the strong exponential time hypothesis SETH (Section 4.1). A special property of our algorithm is that it can be called with an initial mapping 𝑒 0 and then produces (if possible) a C-embedding 𝑒 of 𝑢 in D with 𝑒 0 (𝑖) ≤ 𝑒 (𝑖) for every 𝑖 ∈ [|𝑢 |] that is minimal among all such embeddings. By carefully using this property, we are able to devise an algorithm for task (2). In the next theorem, let 𝑢 C (D) be the set of all C-embeddings of 𝑢 in D. Theorem 1.4. We can enumerate the set 𝑢 C (D) with preprocessing time 𝑂 (𝑇 ) and delay 𝑂 (|𝑢 | · 𝑇 ), where 𝑇 is the running time of the matching algorithm of Theorem 1.3 above. (Note that this entails a total computation of 𝑢 C (D) in time 𝑂 (|𝑢 C (D)| · |𝑢 | · 𝑇 ).) In the special case where all constraint languages are both left- and right-convex (as, e.g., length constraints), we can even get rid of the factor |𝑢 | in the above theorem. Finally, we investigate whether the left-convex property is necessary for tractability by considering a smallest language that is not left-convex: {aa, 𝜀}. Note that every language with strictly smaller cardinality or smaller maximum word size is immediately left-convex. Our algorithm solves the setting with length constraints rather efficiently, but we can show that if we additionally allow {aa, 𝜀} as a constraint language, then the problem is NP-complete again, even if all other constraints are length constraints. By modifying our hardness reduction, we can derive two more relevant intractability results: there is a fixed regular language 𝐿 such that subsequence matching is NPcomplete if all gap-constraints use 𝐿 as their constraint language, and the case where all constraints are left- or right-convex is also intractable. These hardness results are shown in Section 6. 1.2 Further Related Work The classical concept of subsequences is employed in different areas of computer science: formal languages and logics (e.g., piecewise testable languages [38–40, 52, 61, 62], subword order and downward closures [31, 44, 45, 66]), combinatorics on words [23, 46, 47, 51, 54, 55, 58, 59], modelling concurrency [17, 53, 60], database theory (especially event stream processing [7, 24, 28, 41, 42, 67]). , Vol. 1, No. 1, Article . Publication date: June 2026.

Tractable Gap-Constraint Languages for Complex Event Recognition

5

Moreover, many classical algorithmic problems are based on subsequences, e.g., longest common subsequence [9] or shortest common supersequence [49] (see [3, 21] and the survey [43], for recent results on string problems concerned with subsequences). The longest common subsequence problem has also recently received substantial attention in fine-grained complexity (see [1, 2, 12, 14]). 2

Preliminaries

Let N = {1, 2, 3, . . .} and, for every 𝑖, 𝑗 ∈ N with 𝑖 ≤ 𝑗, we define [𝑖, 𝑗] = {𝑖, 𝑖 + 1, . . . , 𝑗 } and [𝑖] = {1, 2, . . . , 𝑖}; for convenience we define [0] = ∅. We let Σ be a finite alphabet of symbols (sometimes called letters) and write Σ∗ for the set of strings (sometimes called words) over Σ. We write 𝜀 for the empty string. For a string 𝑤 ∈ Σ∗ , we denote by |𝑤 | its length and, for every 𝑖 ∈ {1, 2, . . . , |𝑤 |}, we denote by 𝑤 [𝑖] the 𝑖 th symbol of 𝑤. For 𝑖, 𝑗 ∈ {1, 2, . . . , |𝑤 |} with 𝑖 ≤ 𝑗, we denote by 𝑤 [𝑖 : 𝑗] the factor (also called infix) 𝑤 [𝑖]𝑤 [𝑖 + 1] · · · 𝑤 [ 𝑗]; in particular, 𝑤 [𝑖 : 𝑖] = 𝑤 [𝑖]. We extend the notation for 𝑖 > 𝑗 as follows. If 𝑖 = 𝑗 + 1, then we set 𝑤 [𝑖 : 𝑗] = 𝜀 and if 𝑖 > 𝑗 + 1, then we set 𝑤 [𝑖 : 𝑗] = ⊥, where ⊥ means undefined. This technical particularity is due to the fact that we often want to talk about the factor of a string 𝑤 strictly in between positions 𝑖 and 𝑗, which is 𝜀 if 𝑗 = 𝑖 + 1 and undefined if 𝑗 ≤ 𝑖. Thus, with our definition, we can use 𝑤 [𝑖 + 1 : 𝑗 − 1] to refer to this factor that lies strictly in between positions 𝑖 and 𝑗. Regular expressions, nondeterministic finite automata with 𝜀-transitions, called 𝜀NFA for brevity, and the class REG of regular languages are defined in the usual way (see, e.g., [33]). We write L (𝑋 ) for the language of a regular expression 𝑋 or an 𝜀NFA 𝑋 . We use the classical result that a given regular expression 𝑟 can be converted in time 𝑂 (|𝑟 |) into an 𝜀NFA 𝐴 such that L (𝐴) = L (𝑟 ) and |𝐴| = 𝑂 (|𝑟 |) (see [33, Section 3.2.3]). Embeddings, Subsequences and Gap-Constraints. Let us define embeddings and subsequences: Definition 2.1. Given strings 𝑤, 𝑢 ∈ Σ∗ with |𝑢 | ≤ |𝑤 |, we say that a mapping 𝑒 : [|𝑢 |] → [|𝑤 |] is an embedding of 𝑢 in 𝑤 if 𝑒 (1) < 𝑒 (2) < . . . < 𝑒 (|𝑢 |) and 𝑤 [𝑒 (𝑖)] = 𝑢 [𝑖] for every 𝑖 ∈ [|𝑢 |], i.e., 𝑢 = 𝑤 [𝑒 (1)]𝑤 [𝑒 (2)] · · · 𝑤 [𝑒 (|𝑢 |)]. In this case, we write 𝑢 ⪯𝑒 𝑤 and call 𝑢 a subsequence of 𝑤 induced by 𝑒. We write 𝑢 ⪯ 𝑤 to denote that 𝑢 ⪯𝑒 𝑤 for some embedding 𝑒 of 𝑢 in 𝑤 and also say that 𝑒 witnesses 𝑢 ⪯ 𝑤. For 𝑖 ∈ [|𝑢 |], we say that 𝑢𝑒 [𝑖] is embedded on position 𝑒 (𝑖) of 𝑤. Definition 2.2. Let 𝑤, 𝑢 ∈ Σ∗ with |𝑢 | ≤ |𝑤 | and let 𝑒 : [|𝑢 |] → [|𝑤 |] be a mapping. For every 𝑖, 𝑗 ∈ [|𝑢 |], with 𝑖 < 𝑗, we define the (𝑖, 𝑗)-gap induced by 𝑤 and 𝑒 as 𝑤 [𝑒 (𝑖) + 1 : 𝑒 ( 𝑗) − 1]. We define gaps not only between two consecutive positions (i.e., the (𝑖, 𝑖 + 1)-gap which is strictly between 𝑒 (𝑖) and 𝑒 (𝑖 + 1)), but also between positions that are further apart (i.e., the (𝑖, 𝑗)-gap with 𝑖 < 𝑗, which contains in particular the images 𝑒 (𝑘) for each 𝑖 < 𝑘 < 𝑗). Intuitively, the (𝑖, 𝑗)-gap 𝑤 [𝑒 (𝑖) + 1 : 𝑒 ( 𝑗) − 1] is the factor that occurs strictly between the positions corresponding to the images of 𝑖 and 𝑗 under the mapping 𝑒. Note that gaps may be empty or undefined strings: 𝑤 [𝑒 (𝑖) + 1 : 𝑒 ( 𝑗) − 1] = 𝜀 iff 𝑗 = 𝑖 + 1 and 𝑒 ( 𝑗) = 𝑒 (𝑖) + 1, and 𝑤 [𝑒 (𝑖) + 1 : 𝑒 ( 𝑗) − 1] = ⊥ iff 𝑒 (𝑖) ≥ 𝑒 ( 𝑗). Next, we introduce gap-constraints. Definition 2.3. For a language 𝐿 ⊆ Σ∗ , an 𝐿-gap-constraint for a string 𝑢 ∈ Σ∗ is a triple (𝑖, 𝑗, 𝐿), where 𝑖, 𝑗 ∈ [|𝑢 |] such that 𝑖 < 𝑗. A mapping 𝑒 : [|𝑢 |] → [|𝑤 |], where 𝑤 ∈ Σ∗ with |𝑢 | ≤ |𝑤 |, satisfies the gap-constraint (𝑖, 𝑗, 𝐿) if and only if the gap 𝑤 [𝑒 (𝑖) + 1 : 𝑒 ( 𝑗) − 1] belongs to 𝐿. We call 𝐿 the gap-constraint language of an 𝐿-gap-constraint. For any 𝐿-gap-constraint 𝑐 = (𝑖, 𝑗, 𝐿), we also say that 𝑐 is an (𝑖, 𝑗)-gap-constraint and we use the term gap-constraint to denote any 𝐿-gapconstraint for an arbitrary language 𝐿. We say that 𝑐 = (𝑖, 𝑗, 𝐿) is a regular constraint if 𝐿 ∈ REG. For our algorithms, we will assume that regular gap-constraints 𝑐 = (𝑖, 𝑗, 𝐿) are represented by the numbers 𝑖, 𝑗 and a regular expression 𝑟 with L (𝑟 ) = 𝐿; thus, we will also write them as 𝑐 = (𝑖, 𝑗, 𝑟 ). , Vol. 1, No. 1, Article . Publication date: June 2026.

6

Antoine Amarilli, Florin Manea, Tina Ringleb, and Markus L. Schmid

The size |𝑐 | of the constraint is defined as |𝑐 | = |𝑟 |. Note that, as we explained above, we can also assume that any regular expression 𝑟 is given by an 𝜀NFA. We call 𝑐 a length constraint if 𝐿 = {𝑣 ∈ Σ∗ | 𝑎 ≤ |𝑣 | ≤ 𝑏} for some 𝑎, 𝑏 ∈ N ∪ {0} with 𝑎 ≤ 𝑏. In this case, a regular expression 𝑟 for 𝐿 can be concisely described by the interval [𝑎, 𝑏]; thus, we will write length constraints as (𝑖, 𝑗, [𝑎, 𝑏]) instead of 𝑐 = (𝑖, 𝑗, 𝐿) or 𝑐 = (𝑖, 𝑗, 𝑟 ), and we consider such a length constraint 𝑐 to be of constant size (since it is represented by 4 numbers). For a set C of gap-constraints for 𝑢 ∈ Σ∗ , 𝑤 ∈ Σ∗ with |𝑤 | ≥ |𝑢 | and mapping 𝑒 : [|𝑢 |] → [|𝑤 |], we say that 𝑒 satisfies C if and only if it satisfies every 𝑐 ∈ C. An embedding 𝑒 : [|𝑢 |] → [|𝑤 |] of 𝑢 in 𝑤 is a C-embedding of 𝑢 in 𝑤 (denoted by 𝑢 ⪯𝑒,C 𝑤) if it satisfies the set C of gap-constraints for 𝑢. We shall also just write 𝑢 ⪯ C 𝑤 to denote that 𝑢 ⪯𝑒,C 𝑤 holds for some 𝑒. When we are dealing with a set Íinput for an algorithm, then we Í C of regular gap-constraints as measure the size of C as ∥C∥ = 𝑐 ∈ C |𝑐 |, which by the above is (𝑖,𝑗,𝑟 ) ∈ C |𝑟 |. Further, the number of gap-constraints is |C|. Obviously, we always have ∥C∥ ≥ |C|. Subsequence Matching with Gap-Constraints. In the rest of this paper, we are interested in the following computational problem. The input is a query string 𝑢 ∈ Σ∗ along with a set C of regular3 gap-constraints for 𝑢, and a document D ∈ Σ∗ . Our interpretation is that the pair (𝑢, C) is a query and 𝑢 C (D) = {𝑒 | 𝑢 ⪯𝑒,C D} is the result set of (𝑢, C) on D, i.e., the set of all C-embeddings of 𝑢 in D. We study the matching problem, which is to compute a witness from 𝑢 C (D) or to report that 𝑢 C (D) = ∅ (for our hardness results, we will consider the obvious decision problem variant that simply checks whether 𝑢 C (D) ≠ ∅). We will also consider the problem of computing the whole result set 𝑢 C (D), which we approach as the problem to enumerate its contents (i.e., each C-embedding is produced exactly once, with no duplicates). As is common in such query evaluation scenarios, we assume that the query (𝑢, C) is much smaller than the data |D|; thus, for running times, our focus is on the dependency on |D|. Further, when computing a set, we are interested in the total time to do that (in dependency of the size of the set), while for enumerating a set we are interested in two dimensions: the running time of the preprocessing phase (i.e., until the first answer is produced), and the bound on the worst-case delay after each answer (i.e., the time until we produce either the next answer or signal that the enumeration is finished). 3

Subsequence Matching With Gap-Constraints as a CSP

In this section, we show that interpreting the subsequence matching with gap-constraints problem as a Constraint Satisfaction Problem (for short, CSP) leads to some initial tractability results. For instance, it gives a polynomial algorithm for the setting where left-convex regular constraints (e.g., length constraints) are considered. Let us briefly introduce the CSP-related machinery that we will use in this section; we follow the definitions from [10, 22]. A more thorough discussion on this topic is given in Appendix B. A constraint satisfaction problem is a triple P = ⟨𝑉 ,𝑇 , 𝐾⟩, where 𝑉 = {1, . . . , 𝑚} is a set of variables (denoted, for simplicity, by natural numbers), 𝑇 is a set called the domain, and 𝐾 is a set of constraints {𝐾1, . . . , 𝐾𝑞 }, such that each 𝐾𝑖 ∈ 𝐾 is a pair ⟨𝑠𝑖 , 𝑅𝑖 ⟩, where 𝑠𝑖 ⊆ 𝑉 is a set of variables of size 𝑛𝑖 , called the constraint scope, and 𝑅𝑖 ⊆ 𝑇 𝑛𝑖 is an 𝑛𝑖 -ary relation over 𝑇 , called the constraint relation; w.l.o.g., we assume 𝑠𝑖 to be increasingly ordered, and denote by 𝑠𝑖 [ 𝑗] the 𝑗 𝑡ℎ element of 𝑠𝑖 . A solution for P is a function 𝜙 : 𝑉 → 𝑇 such that for each ⟨𝑠, 𝑅⟩ ∈ 𝐾 the tuple ⟨𝜙 (1), . . . , 𝜙 (𝑚)⟩ is in 𝑅. The CSP P = ⟨𝑉 ,𝑇 , 𝐾⟩ is normalised if no two distinct constraints from 𝐾 have the same scope. 3 Note that we will always assume that the gap-constraints are regular.

, Vol. 1, No. 1, Article . Publication date: June 2026.

Tractable Gap-Constraint Languages for Complex Event Recognition

7

In general, for a CSP P, we are interested in whether it admits a solution or not. To this end, it was shown [70] that the tractability of P is exactly determined by structural properties of the class of relations over 𝑇 from which the constraints of 𝐾 stem. But already the less recent survey [18] showed two particularly relevant such classes of constraints (which also allow for simpler CSP-solving algorithms, compared to the general algorithm given in [70]): the min-closed and, respectively, max-closed relations. A 𝑘-ary relation 𝑅 is min-closed if for every pair of 𝑘-tuples 𝑡, 𝑡 ′ ∈ 𝑅 we have that the 𝑘-tuple ⟨min{𝑡 [1], 𝑡 ′ [1]}, . . . , min{𝑡 [𝑘], 𝑡 ′ [𝑘]}⟩ also belongs to 𝑅 (max-closed relations are defined analogously). The following result holds. Proposition 3.1 (Example 6.39 in [18], originally in [37]). We can decide in polynomial time whether a CSP P = ⟨𝑉 ,𝑇 , 𝐾⟩, where all constraints of 𝐾 are min-closed (resp., max-closed), admits a solution. Let us make some remarks on the above result. Firstly, note that there are quite a few interesting examples of min- or max-closed relations, as shown in [37]. For instance, all unary constraints are min- and max-closed, and the same holds for all basic arithmetic constraints over the natural numbers in the constraint programming language CHIP [32], which include, e.g., relations defined by linear (in)equalities between variables. Secondly, many efficient algorithms support the above statement, not only the one from [37]; in particular, if there is a constant upper bound on the arity of all constraint relations, then algorithms implementing the technique of enforcing generalised arc consistency, see [10], achieve a polynomial running time for the above problem with a polynomial degree that depends on the arity bound. For normalised CSPs where each constraint is unary or binary, such an algorithm is AC4 (defined in [68], as an efficient implementation of AC3 [48]) which works in 𝑂 (|𝐾 ||𝑇 | 2 ) time (which is optimal [10]). Coming now back to the subsequence matching with gap-constraints problem, we show how this can be formalised as a CSP. Recall that we are given a query string 𝑢 ∈ Σ∗ , |𝑢 | = 𝑚, along with a set C of regular gap-constraints for 𝑢, and a document D ∈ Σ∗ , |D| = 𝑛, and we want to see if there exists a C-embedding of 𝑢 in D. Let 𝑉 = [𝑚] and 𝑇 = [𝑛]. The set 𝐾 ′ contains the following constraints: • ⟨(𝑖), 𝑅𝑖 ⟩, where 𝑖 ∈ [𝑚] and 𝑅𝑖 = {𝑎 ∈ [𝑛] | D[𝑎] = 𝑢 [𝑖]}. • ⟨(𝑖, 𝑖 + 1), 𝑅 (𝑖,𝑖+1) ⟩, where 𝑖 ∈ [𝑚 − 1] and 𝑅 (𝑖,𝑖+1) = {(𝑎, 𝑏) ∈ [𝑛] × [𝑛] | 𝑎 < 𝑏}. • ⟨(𝑖, 𝑗), 𝑅 (𝑖,𝑗,𝐿) ⟩, where (𝑖, 𝑗, 𝐿) ∈ C and 𝑅 (𝑖,𝑗,𝐿) = {(𝑎, 𝑏) ∈ [𝑛] × [𝑛] | D[𝑎 + 1 : 𝑏 − 1] ∈ 𝐿}. ′ Let CSP𝑢,D,C = ⟨𝑉 ,𝑇 , 𝐾 ′ ⟩ be the constraint satisfaction problem defined for the instance 𝑢, D, C of the subsequence matching with gap-constraints problem. It is immediate that this CSP has a solution if and only if there exists a C-embedding of 𝑢 in D. Note that, while having only unary and binary constraints, this CSP is not necessarily normalised (as there can be multiple constraints for the same pair of variables). Fortunately, we can show the following result (see Appendix B for a proof). ′ Lemma 3.2. Given 𝑢, D, and C, we can construct in 𝑂 (∥C∥|D| 2 ) time the problem CSP𝑢,D,C = ′ ⟨𝑉 ,𝑇 , 𝐾 ⟩. In the same time complexity, we can construct CSP𝑢,D,C = ⟨𝑉 ,𝑇 , 𝐾⟩, a normalised problem with 𝑂 (|𝑢 | + |C|) constraints, which has a solution if and only if there exists a C-embedding of 𝑢 in D.

Now, in the case where all the constraints of CSP𝑢,D,C happen to be min-closed, we can use Proposition 3.1 to get the following result, using, e.g., the AC4 algorithm to enforce arc consistency. Theorem 3.3. Given 𝑢, D, and C, let CSP𝑢,D,C = ⟨𝑉 ,𝑇 , 𝐾⟩ be constructed as in Lemma 3.2. Assuming that the set of constraints 𝐾 is min-closed, then we can decide whether there exists a C-embedding of 𝑢 in D in time 𝑂 (|D| 2 (|𝑢 | + ∥C∥)) (which includes the construction of CSP𝑢,D,C ). We note that we can easily test in polynomial time whether it is the case that the set of constraints 𝐾 is min-closed, once we have constructed CSP𝑢,D,C . However, the above result provides no algorithm to solve the problem when 𝐾 is not min-closed, and we also have no guarantee on , Vol. 1, No. 1, Article . Publication date: June 2026.

8

Antoine Amarilli, Florin Manea, Tina Ringleb, and Markus L. Schmid

when this might happen. In the sequel we will see how enforcing the left-convexity of the regular languages used as gap-constraints can ensure that the constraints are min-closed. Recall the definition of left-convex languages from the Introduction (Definition 1.2): a language 𝐿 is left-convex if 𝑢𝑣𝑤 ∈ 𝐿 and 𝑣 ∈ 𝐿 implies 𝑢𝑣 ∈ 𝐿. Let LCON be the class of left-convex languages. Lemma 3.4. If 𝐿 ∈ LCON for all (𝑖, 𝑗, 𝐿) ∈ C, then all constraints of CSP𝑢,D,C are min-closed. Clearly, if 𝐿 is right-convex, then all constraints of CSP𝑢,D,C are max-closed. So, the result of Theorem 3.3 applies for the case when all gap-constraints in C are left-convex (respectively, rightconvex). In the following, and as the main technical contribution of our work, we show that this result can be improved in a non-trivial way regarding two different aspects. Firstly, we are able to improve the running time from 𝑂 (|D| 2 (|𝑢 | + ∥C∥)) to 𝑂 (|D|(|𝑢 | + ∥C∥)) (i.e., from quadratic to linear in the data size, which is highly relevant for applications in complex event recognition), which is conditionally optimal, and secondly we are able to extend our algorithm to enumerating all solutions with bounded delay instead of producing only one witness. 4

Improvement to Linear Dependency on the Data Size

In this section, we substantially improve the upper bound from the previous section obtained by the CSP-based approach. More precisely, we show that the quadratic dependency on the size of the data |D| can be lowered to a linear dependency: Theorem 4.1. The matching problem with left-convex constraints can be solved in 𝑂 (|D|(|𝑢 | + ∥C∥)). We can also show that under the strong exponential time hypothesis (SETH, for short), this bound cannot be improved, i.e., for 𝜖 > 0, there is most likely no algorithm with running time 𝑂 ((|D|(|𝑢 | + ∥C∥)) 1−𝜖 ) (see Section 4.1 below). Before we can state our algorithm for Theorem 4.1, we will need the following crucial definition. For every 𝑘 ∈ [|D|] and language 𝐿 with (𝑖, 𝑗, 𝐿) ∈ C, we define longestRight(𝑘, 𝐿) = max({𝑡 ∈ [𝑘 + 1, |D|] | D[𝑘 + 1 : 𝑡 − 1] ∈ 𝐿} ∪ {0}), i.e., if longestRight(𝑘, 𝐿) = 𝑡, then D[𝑘 + 1 : 𝑡 − 1] is the longest factor of D starting at position 𝑘 + 1 that belongs to 𝐿. Analogously, we define shortestLeft(𝑘, 𝐿) = max({𝑡 ∈ [𝑘 − 1] | D[𝑡 + 1 : 𝑘 − 1] ∈ 𝐿} ∪ {0}), i.e., if shortestLeft(𝑘, 𝐿) = 𝑡, then D[𝑡 + 1 : 𝑘 − 1] is the shortest factor of D ending at position 𝑘 − 1 that belongs to 𝐿. Moreover, if no such factor exists or if 𝑘 ∉ [|D|], then longestRight(𝑘, 𝐿) and shortestLeft(𝑘, 𝐿) return 0. Let us explain our algorithm (given as Algorithm 1) on an intuitive level. The algorithm starts with an initial mapping 𝑒 ≔ 𝑒 0 : [|𝑢 |] → [|D|], which is then changed into a C-embedding of 𝑢 in D (if one exists) by only moving single positions to the right, i.e., by single steps that redefine some 𝑒 (𝑖) ≔ 𝑒 (𝑖) + 𝑐 and leave all other 𝑒 (𝑖 ′ ) with 𝑖 ′ ∈ [|𝑢 |] \ {𝑖} unchanged. Now for our current mapping 𝑒 there are three types of violations that may cause 𝑒 to not be a C-embedding of 𝑢 in D: (1) 𝑢 [𝑠] ≠ D[𝑒 (𝑠)] for some 𝑠 ∈ [|𝑢 |], (2) 𝑒 (𝑠) ≥ 𝑒 (𝑠 + 1) for some 𝑠 ∈ [|𝑢 | − 1], and (3) D[𝑒 (𝑖) + 1 : 𝑒 ( 𝑗) − 1] ∉ 𝐿 for some (𝑖, 𝑗, 𝐿) ∈ C. In the set 𝑆, we maintain positions 𝑠 ∈ [|𝑢 |] for which we still have to check whether they participate in one of these violations, i.e., we maintain the invariant that if 𝑠 ∉ 𝑆, then 𝑠 does not participate in any violations of any of these three types. Therefore, as soon as 𝑆 is empty, we have found our C-embedding of 𝑢 in D. Let us next discuss how we modify the current mapping 𝑒. As long as 𝑆 is not empty, we consider some 𝑠 ∈ 𝑆, and remove it from 𝑆. If 𝑠 participates in a violation of type (1), then we move 𝑒 (𝑠) one step to the right (see Line 5) and if 𝑠 participates in a violation of type (2), then we move 𝑒 (𝑠 + 1) to 𝑒 (𝑠) + 1 (see Line 7). If 𝑠 is responsible for a violation of type (3), then there is some (𝑖, 𝑗, 𝐿) ∈ C with 𝑠 ∈ {𝑖, 𝑗 } and D[𝑒 (𝑖) + 1 : 𝑒 ( 𝑗) − 1] ∉ 𝐿. In this case, we move either 𝑒 ( 𝑗) or 𝑒 (𝑖) one step to the right, depending on whether or not longestRight(𝑒 (𝑖), 𝐿) > 𝑒 ( 𝑗) (see Line 11). Moreover, whenever we move some position, we have to put it in 𝑆, since moving it may cause violations that have to be checked later. , Vol. 1, No. 1, Article . Publication date: June 2026.

Tractable Gap-Constraint Languages for Complex Event Recognition

9

Algorithm 1: EmbedLCONSubseq(𝑢, C, D, 𝑒 0 ) Input: 𝑢, C s.t. C only contains left-convex gap-constraints, D ∈ Σ∗ , 𝑒 0 : [|𝑢 |] → [|D|]. Output: 𝑒 0 -minimal C-embedding of 𝑢 in D if it exists, and ⊥ otherwise. 1 𝑒 ≔ 𝑒 0 ; 𝑆 ≔ {1, 2, . . . , |𝑢 |}; 2 while 𝑆 ≠ ∅ do 3 Let 𝑠 ∈ 𝑆 be arbitrarily chosen and 𝑆 ← 𝑆 \ {𝑠}; 4 if 𝑒 (𝑠) > |D| then return ⊥; 5 if 𝑢 [𝑠] ≠ D[𝑒 (𝑠)] then 6 𝑒 (𝑠) ← 𝑒 (𝑠) + 1; 𝑆 ← 𝑆 ∪ {𝑠}; 7 if 𝑠 < |𝑢 | and 𝑒 (𝑠) ≥ 𝑒 (𝑠 + 1) then 8 𝑒 (𝑠 + 1) ← 𝑒 (𝑠) + 1; 𝑆 ← 𝑆 ∪ {𝑠 + 1}; 9 foreach (𝑖, 𝑗, 𝐿) ∈ C with 𝑠 ∈ {𝑖, 𝑗 } do 10 if D[𝑒 (𝑖) + 1 : 𝑒 ( 𝑗) − 1] ∉ 𝐿 then 11 if longestRight(𝑒 (𝑖), 𝐿) > 𝑒 ( 𝑗) then 𝑠 ′ ← 𝑗 else 𝑠 ′ ← 𝑖 ; 12 𝑒 (𝑠 ′ ) ← 𝑒 (𝑠 ′ ) + 1; 𝑆 ← 𝑆 ∪ {𝑠 ′ }; 13 return 𝑒;

In every iteration of the while-loop, either we move a position of the current mapping 𝑒 to the right, or, if we do not change 𝑒, then we remove an element from 𝑆 without adding new elements. Consequently, at some point either 𝑆 will be empty, in which case we output the current mapping, or the current mapping 𝑒 satisfies 𝑒 (𝑖) > |D|, in which case we conclude that no C-embedding exists. We will next prove the correctness of this approach and then we prove the running time claimed in Theorem 4.1 (for some proofs we only provide sketches; full details can be found in Appendix C). However, before we can proceed, we need some more definitions and statements. In the following, we fix an instance (𝑢, C, D) of the matching problem, where every gap-constraint from C is a left-convex gap-constraint. We denote by ≤ the pointwise order on mappings, i.e., for two mappings 𝑒, 𝑒 ′ : [|𝑢 |] → [|D|], we write 𝑒 ≤ 𝑒 ′ if and only if 𝑒 (𝑖) ≤ 𝑒 ′ (𝑖) for every 𝑖 ∈ [|𝑢 |]. Clearly, ‘≤’ is a partial order, which means that we can talk about mappings that are minimal (with respect to a set of mappings). For some mapping 𝑒 0 : [|𝑢 |] → [|D|], we say that 𝑒 : [|𝑢 |] → [|D|] is an 𝑒 0 -minimal C-embedding of 𝑢 in D if and only if 𝑒 is a C-embedding of 𝑢 in D with 𝑒 0 ≤ 𝑒 and 𝑒 is minimal within the set of all C-embeddings 𝑒 ′ of 𝑢 in D with 𝑒 0 ≤ 𝑒 ′ . Note that this notion is defined for a mapping 𝑒 0 : [|𝑢 |] → [|D|], i.e., 𝑒 0 is not necessarily an embedding of 𝑢 in D (and, even when it is an embedding of 𝑢 in D, it may still violate gap-constraints from C). A key point of the left-convex property is stated by the next lemma (similar to Lemma 3.4). Lemma 4.2. Let 𝑒 0 : [|𝑢 |] → [|D|] be a mapping, and assume that there exists a C-embedding 𝑒 of 𝑢 in D with 𝑒 0 ≤ 𝑒. Then there is a unique 𝑒 0 -minimal C-embedding of 𝑢 in D. Proof. If there are two 𝑒 0 -minimal C-embeddings 𝑒 1 and 𝑒 2 of 𝑢 in D, then we can consider the pointwise minimum 𝑒 min of 𝑒 1 and 𝑒 2 , which is an embedding of 𝑢 in D. Obviously, 𝑒 0 ≤ 𝑒 min . We show that 𝑒 min is a C-embedding of 𝑢 in D. To this end, let (𝑖, 𝑗, 𝐿) ∈ C be arbitrarily chosen. If (𝑒 min (𝑖), 𝑒 min ( 𝑗)) = (𝑒 1 (𝑖), 𝑒 1 ( 𝑗)) or (𝑒 min (𝑖), 𝑒 min ( 𝑗)) = (𝑒 2 (𝑖), 𝑒 2 ( 𝑗)), then 𝑒 min obviously satisfies (𝑖, 𝑗, 𝐿). If (𝑒 min (𝑖), 𝑒 min ( 𝑗)) = (𝑒 1 (𝑖), 𝑒 2 ( 𝑗)) (the case (𝑒 min (𝑖), 𝑒 min ( 𝑗)) = (𝑒 2 (𝑖), 𝑒 1 ( 𝑗)) is analogous), then we have 𝑒 1 (𝑖) ≤ 𝑒 2 (𝑖) < 𝑒 2 ( 𝑗) ≤ 𝑒 1 ( 𝑗) and D[𝑒 1 (𝑖) + 1 : 𝑒 1 ( 𝑗) − 1] ∈ 𝐿 and D[𝑒 2 (𝑖) + 1 : 𝑒 2 ( 𝑗) − 1] ∈ 𝐿. Since 𝐿 is left-convex, this implies D[𝑒 1 (𝑖) + 1 : 𝑒 2 ( 𝑗) − 1] ∈ 𝐿 and therefore , Vol. 1, No. 1, Article . Publication date: June 2026.

10

Antoine Amarilli, Florin Manea, Tina Ringleb, and Markus L. Schmid

D[𝑒 min (𝑖) + 1 : 𝑒 min ( 𝑗) − 1] ∈ 𝐿. Hence, (𝑖, 𝑗, 𝐿) is satisfied by 𝑒 min . Finally, we note that 𝑒 1 ≠ 𝑒 min or 𝑒 2 ≠ 𝑒 min contradicts the 𝑒 0 -minimality of 𝑒 1 or 𝑒 2 ; thus, 𝑒 1 = 𝑒 2 = 𝑒 min . □ We are now ready to state the correctness of Algorithm 1 in the form of the following lemma. Lemma 4.3. On input 𝑢 ∈ Σ∗ , C (where C only contains left-convex gap-constraints), D ∈ Σ∗ and 𝑒 0 : [|𝑢 |] → [|D|], Algorithm 1 returns an 𝑒 0 -minimal C-embedding of 𝑢 in D if it exists, and ⊥ otherwise. Proof Sketch. For every 𝑒 : [|𝑢 |] → [|D|], we define the following invariant. Invariant (†)𝑒 : If there exists a C-embedding 𝑒 ∗ of 𝑢 in D with 𝑒 0 ≤ 𝑒 ∗ , then 𝑒 ≤ 𝑒 ∗ (where 𝑒 is the current mapping of the algorithm). It can be easily verified that (†)𝑒 holds at the beginning of the algorithm, and it can be shown that the modifications of 𝑒 carried out by an iteration of the while-loop maintain (†)𝑒 . For the modifications possibly caused by the if-statements in Line 5 and 7 this is not too hard to see. If the condition of Line 5 is satisfied, then 𝑢 [𝑠] ≠ D[𝑒 (𝑠)] and we will change 𝑒 into 𝑒 ′ with 𝑒 ′ (𝑖) = 𝑒 (𝑖) for every 𝑖 ∈ [|𝑢 |] \ {𝑠} and 𝑒 ′ (𝑠) = 𝑒 (𝑠) + 1. Since (†)𝑒 is satisfied, we know that any C-embedding 𝑒 ∗ of 𝑢 in D with 𝑒 0 ≤ 𝑒 ∗ satisfies 𝑒 ≤ 𝑒 ∗ . But since 𝑢 [𝑠] ≠ D[𝑒 (𝑠)], we also know that 𝑒 ∗ (𝑠) ≠ 𝑒 (𝑠), which means that 𝑒 ′ (𝑠) = 𝑒 (𝑠) + 1 ≤ 𝑒 ∗ (𝑠). Consequently, any C-embedding 𝑒 ∗ of 𝑢 in D with 𝑒 0 ≤ 𝑒 ∗ satisfies 𝑒 ′ ≤ 𝑒 ∗ ; thus, (†)𝑒 ′ is satisfied. A similar reasoning applies to the case of Line 7. The more difficult cases are the calls of Line 10 inside the foreach-loop, whose correctness hinges on the left-convex property. Let us assume that the condition of Line 10 is satisfied for some (𝑖, 𝑗, 𝐿) ∈ C with 𝑠 ∈ {𝑖, 𝑗 }, i.e., D[𝑒 (𝑖) + 1 : 𝑒 ( 𝑗) − 1] ∉ 𝐿. Moreover, let us assume that longestRight(𝑒 (𝑖), 𝐿) > 𝑒 ( 𝑗), which means that we change 𝑒 into 𝑒 ′ with 𝑒 ′ (𝑘) = 𝑒 (𝑘) for every 𝑘 ∈ [|𝑢 |] \ { 𝑗 } and 𝑒 ′ ( 𝑗) = 𝑒 ( 𝑗) + 1. In particular, we also know that D[𝑒 (𝑖) + 1 : longestRight(𝑒 (𝑖), 𝐿) − 1] ∈ 𝐿. If (†)𝑒 ′ is not satisfied, then there is some C-embedding 𝑒 ∗ of 𝑢 in D with 𝑒 0 ≤ 𝑒 ∗ , but 𝑒 ′ ≰ 𝑒 ∗ . Since (†)𝑒 is satisfied, we know that 𝑒 ≤ 𝑒 ∗ , which means that 𝑒 ( 𝑗) = 𝑒 ∗ ( 𝑗). Since D[𝑒 (𝑖) + 1 : 𝑒 ( 𝑗) − 1] ∉ 𝐿, we also know that 𝑒 ′ (𝑖) = 𝑒 (𝑖) < 𝑒 ∗ (𝑖). Let us now consider the string 𝑢𝑣𝑤 with 𝑢 = D[𝑒 (𝑖) + 1 : 𝑒 ∗ (𝑖)], 𝑣 = D[𝑒 ∗ (𝑖)+1 : 𝑒 ∗ ( 𝑗)−1] and 𝑤 = D[𝑒 ∗ ( 𝑗) : longestRight(𝑒 (𝑖), 𝐿)−1]. As observed above, 𝑢𝑣𝑤 ∈ 𝐿, and since 𝑒 ∗ is a C-embedding of 𝑢 in D, we also know that 𝑣 ∈ 𝐿, which, by the left-convexity of 𝐿, implies that 𝑢𝑣 = D[𝑒 (𝑖) + 1 : 𝑒 ( 𝑗) − 1] ∈ 𝐿; a contradiction. The case longestRight(𝑒 (𝑖), 𝐿) ≤ 𝑒 ( 𝑗), where we have 𝑒 ′ (𝑘) = 𝑒 (𝑘) for every 𝑘 ∈ [|𝑢 |] \ {𝑖} and 𝑒 ′ (𝑖) = 𝑒 (𝑖) + 1, is a bit simpler. If (†)𝑒 ′ is not satisfied, then there is some C-embedding 𝑒 ∗ of 𝑢 in D with 𝑒 0 ≤ 𝑒 ∗ , but 𝑒 ′ ≰ 𝑒 ∗ . Since (†)𝑒 is satisfied, we know that 𝑒 ≤ 𝑒 ∗ , which means that 𝑒 (𝑖) = 𝑒 ∗ (𝑖). Since D[𝑒 (𝑖) +1 : 𝑒 ( 𝑗) −1] ∉ 𝐿, we also know that 𝑒 ′ ( 𝑗) = 𝑒 ( 𝑗) < 𝑒 ∗ ( 𝑗), which means that longestRight(𝑒 (𝑖), 𝐿) > 𝑒 ( 𝑗); a contradiction. Note that we might also call Line 10 in the case where 𝑒 (𝑖) ≥ 𝑒 ( 𝑗), which means that D[𝑒 (𝑖) + 1 : 𝑒 ( 𝑗) − 1] = ⊥ ∉ 𝐿. This constitutes a special case, for which correctness can nevertheless be proven in a very similar way as sketched above (see Appendix C). This shows that (†)𝑒 holds before every iteration of the while-loop. Next, we formulate another invariant, for which we need the following terminology. We say that 𝑠 ∈ [|𝑢 |] satisfies the symbol condition with respect to 𝑒 if 𝑢 [𝑠] = D[𝑒 (𝑠)], 𝑠 ∈ [|𝑢 | − 1] satisfies the order condition with respect to 𝑒 if 𝑒 (𝑠) < 𝑒 (𝑠 + 1), and 𝑠, 𝑠 ′ ∈ [|𝑢 |] satisfy the gap condition with respect to 𝑒 if (𝑖, 𝑗, 𝐿) ∈ C with {𝑖, 𝑗 } = {𝑠, 𝑠 ′ } implies D[𝑒 (𝑖) + 1 : 𝑒 ( 𝑗) − 1] ∈ 𝐿. For every 𝑒 : [|𝑢 |] → [|D|] and 𝑆 ⊆ [|𝑢 |], we define: Invariant (‡)𝑒,𝑆 : Each 𝑠 ∈ [|𝑢 |] \ 𝑆 satisfies the symbol condition and the order condition with respect to 𝑒, and all 𝑠, 𝑠 ′ ∈ [|𝑢 |] \ 𝑆 satisfy the gap condition with respect to 𝑒. Obviously, (‡)𝑒,𝑆 is satisfied at the beginning of the algorithm, since 𝑆 = [|𝑢 |]. It can be shown that (‡)𝑒,𝑆 is maintained by iterations of the while-loop as follows. We can first show that if (‡)𝑒,𝑆 is satisfied before an iteration, then (‡)𝑒,𝑆∪{𝑠 } is satisfied after the iteration (note that 𝑒 and 𝑆 always , Vol. 1, No. 1, Article . Publication date: June 2026.

Tractable Gap-Constraint Languages for Complex Event Recognition

11

refer to these program variables at the point of the algorithm we refer to). This is because whenever we change any position of 𝑒 then we also put it into 𝑆. So it remains to prove that (‡)𝑒,𝑆 holds after the iteration. The fact that (‡)𝑒,𝑆∪{𝑠 } holds directly means that all 𝑠 ′ ∈ [|𝑢 |] \ (𝑆 ∪ {𝑠}) satisfy the symbol and order condition, and all 𝑠 ′, 𝑠 ′′ ∈ [|𝑢 |] \ (𝑆 ∪ {𝑠}) satisfy the gap condition. Now if 𝑠 ∈ 𝑆, then (‡)𝑒,𝑆∪{𝑠 } = (‡)𝑒,𝑆 and we are done. If 𝑠 ∉ 𝑆, then the fact that 𝑠 was never added to 𝑆 by any of the Lines 5, 7 and 10 directly means that 𝑠 must also satisfy the symbol and order condition, and all 𝑖, 𝑗 ∈ [|𝑢 |] \ 𝑆 with 𝑠 ∈ {𝑖, 𝑗 } satisfy the gap condition. Thus, (‡)𝑒,𝑆 holds after the iteration. These two invariants directly imply the correctness. The algorithm obviously terminates at some point. If 𝑆 gets empty in the last iteration, then we return 𝑒, which, due to (‡)𝑒,𝑆 has to be a C-embedding of 𝑢 in D, and due to (†)𝑒 , has to be 𝑒 0 -minimal. If 𝑒 (𝑖) > |D| in the last iteration, then, due to (†)𝑒 , there is no C-embedding 𝑒 ∗ of 𝑢 in D with 𝑒 0 ≤ 𝑒 ∗ and therefore we return ⊥. □ Let us next come to estimating the running time of Algorithm 1. If we can perform the checks of Lines 10 and 11, i.e., checking D[𝑒 (𝑖) + 1 : 𝑒 ( 𝑗) − 1] ∉ 𝐿 and longestRight(𝑒 (𝑖), 𝐿) > 𝑒 ( 𝑗), in constant time, then Algorithm 1 has indeed the running time claimed in Theorem 4.1. Lemma 4.4. Under the assumption that we can check the conditions of Lines 10 and 11 in constant time, Algorithm 1 terminates after time 𝑂 (|D|(|𝑢 | + |C|)). Proof Sketch. We call an iteration of the while-loop an 𝑠-iteration if 𝑠 is removed from 𝑆 in Line 3. We note that for each 𝑠 ∈ [|𝑢 |] there are 𝑂 (|D|) 𝑠-iterations, so there are 𝑂 (|D| · |𝑢 |) iterations of the while-loop. Hence, executing Lines 3 to 8 of all iterations requires time 𝑂 (|D| · |𝑢 |). Each 𝑠-iteration performs 𝑘𝑠 iterations of the foreach-loop, where 𝑘𝑠 is the number of gap-constraints (𝑖, 𝑗, 𝐿) with 𝑠 ∈ {𝑖, 𝑗 }. Thus, we need time 𝑂 (|D|𝑘𝑠 ) for all the foreach-loops inside of 𝑠-iterations, Í |𝑢 | which over all 𝑠 ∈ [|𝑢 |] sums up to 𝑂 (|D| · |C|) (note that 𝑖=1 𝑘𝑖 = 𝑂 (|C|)). □ In order to conclude the proof of Theorem 4.1, we have to show how the checks of Lines 10 and 11 can be carried out efficiently. First, we will see that, as a consequence of the left-convex property of 𝐿, the numbers longestRight(𝑝, 𝐿) and shortestLeft(𝑞, 𝐿) tell us whether D[𝑝 + 1 : 𝑞 − 1] ∈ 𝐿: Lemma 4.5. Given 𝑝, 𝑞 ∈ [|D|] and given a language 𝐿 ∈ LCON, we have D[𝑝 + 1 : 𝑞 − 1] ∈ 𝐿 if and only if longestRight(𝑝, 𝐿) ≥ 𝑞 and shortestLeft(𝑞, 𝐿) ≥ 𝑝. Proof. If D[𝑝 + 1 : 𝑞 − 1] ∈ 𝐿, then longestRight(𝑝, 𝐿) ≥ 𝑞 and shortestLeft(𝑞, 𝐿) ≥ 𝑝 trivially hold. Thus, for 𝑥 ≔ shortestLeft(𝑞, 𝐿) and 𝑦 ≔ longestRight(𝑝, 𝐿), let us assume that we have 𝑥 ≥ 𝑝 and 𝑦 ≥ 𝑞. Then D[𝑝 +1 : 𝑦 −1] = D[𝑝 +1 : 𝑥]D[𝑥 +1 : 𝑞 −1]D[𝑞 : 𝑦 −1] ∈ 𝐿 and D[𝑥 +1 : 𝑞 −1] ∈ 𝐿 hold. Since 𝐿 ∈ LCON, we know that D[𝑝 + 1 : 𝑥]D[𝑥 + 1 : 𝑞 − 1] = D[𝑝 + 1 : 𝑞 − 1] ∈ 𝐿 holds. □ Consequently, if we have all the numbers longestRight(𝑘, 𝐿) and shortestLeft(𝑘, 𝐿) for every 𝑘 ∈ [|D|] and (𝑖, 𝑗, 𝐿) ∈ C at our disposal, then we can perform the checks of Lines 10 and 11 in constant time. Thus, let LR and SL be arrays such that, for every 𝑘 ∈ [|D|] and language 𝐿 with (𝑖, 𝑗, 𝐿) ∈ C for some 𝑖 and 𝑗, we have LR[𝑘] [𝐿] = longestRight(𝑘, 𝐿) and SL[𝑘] [𝐿] = shortestLeft(𝑘, 𝐿). We can compute these arrays using the NFA 𝑀𝐿 for 𝐿, i.e., we construct a product graph of 𝑀𝐿 and D and then use dynamic programming on this graph; see Appendix C.3 for details. Lemma 4.6. We can compute the arrays LR and SL in time 𝑂 (|D| · ∥C∥). In order to conclude the proof of Theorem 4.1, we note that we can solve the matching problem with left-convex gap-constraints for some instance (𝑢, C, D) by simply running Algorithm 1 on this instance with the initial mapping 𝑒 0 defined by 𝑒 0 (𝑖) ≔ 𝑖 for every 𝑖 ∈ [|𝑢 |]. , Vol. 1, No. 1, Article . Publication date: June 2026.

12

4.1

Antoine Amarilli, Florin Manea, Tina Ringleb, and Markus L. Schmid

Conditional Lower Bound

We can show that the upper bound 𝑂 (|D|(|𝑢 | + ∥C∥)) of Theorem 4.1 is conditionally optimal. Let 𝑟 be a regular expression over Σ and let 𝑤 ∈ Σ∗ . We define the strings D = #$𝑤$# and 𝑢 = ##, where $, # ∉ Σ, and the set of gap-constraints C = {(1, 2, 𝐿)}, where 𝐿 = {$𝑤$ | 𝑤 ∈ L (𝑟 )}. Obviously, (1, 2, 𝐿) is a left-convex gap-constraint, which means that (𝑢, C, D) is an instance of the matching problem, and this instance can be obtained in linear time from 𝑤 and 𝑟 . Moreover, 𝑤 ∈ L (𝑟 ) if and only if 𝑢 ⪯ C D. Hence, if we can check 𝑢 ⪯ C D in time 𝑂 ((|D|∥C∥) 1−𝜖 ), for some 𝜖 > 0, then we can also check 𝑤 ∈ L (𝑟 ) in time 𝑂 ((|𝑤 ||𝑟 |) 1−𝜖 ). The latter contradicts SETH (as it contradicts the orthogonal vectors hypothesis, see [8, 13]); clearly, if 𝐿 is specified by an arbitrary 𝜀NFA, the same lower bound holds. Similarly, even if the languages defining the gap-constraints are chosen from some very simple classes (e.g., length constraints), the upper bound 𝑂 (|D|(|𝑢 | + ∥C∥)) of Theorem 4.1 is still conditionally optimal. In [19, Theorem 3] it was shown that, even if we only allow gap-constraints of the form (𝑖, 𝑖 +1, [𝑎, 𝑏]), with 𝑎, 𝑏 constants, then checking whether 𝑢 ⪯ C D in time 𝑂 ((|D|(|𝑢 | + ∥C∥)) 1−𝜖 ), for 𝜖 > 0, would contradict the orthogonal vectors hypothesis, and, as such, SETH [64].

4.2

Jumping Over Larger Factors and Other Alternative Approaches

We observe that, when 𝑢 [𝑠] is not mapped to the right letter by 𝑒, then Line 6 only increments 𝑒 (𝑠) by one. One easy improvement in practice would be to jump directly to the next occurrence of the letter 𝑢 [𝑠] in D (or fail if none exists). Similarly, we observe that when in an iteration of the while-loop the condition of Line 10 is satisfied, i.e., D[𝑒 (𝑖) + 1 : 𝑒 ( 𝑗) − 1] ∉ 𝐿, then Algorithm 1 moves either position 𝑖 or 𝑗 by only one position, i.e., either 𝑒 (𝑖) ≔ 𝑒 (𝑖) + 1 or 𝑒 ( 𝑗) ≔ 𝑒 ( 𝑗) + 1. However, it can be shown that in such a case, we could as well set 𝑒 (𝑖) ≔ 𝑝 and 𝑒 ( 𝑗) ≔ 𝑞, where 𝑝, 𝑞 ∈ [|D|] such that 𝑒 (𝑖) ≤ 𝑝, 𝑒 ( 𝑗) ≤ 𝑞, D[𝑝 + 1 : 𝑞 − 1] ∈ 𝐿 and 𝑝, 𝑞 are minimal with this property. (The uniqueness of the (pointwise) minimal pair (𝑝, 𝑞) is a direct consequence of the left-convexity of 𝐿; see Lemma 4.2.) The correctness of this follows again from the left-convexity property. Especially for instances where D is sparse with respect to factors that match the constraint languages, shifting positions over larger chunks of D as explained above could help finding a valid embedding (or verifying that none exists) much faster. Of course, the question is how the pair (𝑝, 𝑞) can be computed efficiently. For this, we can again exploit the numbers longestRight(𝑘, 𝐿) and shortestLeft(𝑘, 𝐿). More precisely, our desired 𝑝 and 𝑞 are given as 𝑝 = min{𝑥 ∈ [𝑒 (𝑖), |D|] | longestRight(𝑥, 𝐿) ≥ 𝑒 ( 𝑗)} and 𝑞 = min{𝑥 ∈ [𝑒 ( 𝑗), |D|] | shortestLeft(𝑥, 𝐿) ≥ 𝑒 (𝑖)}. However, it is too costly to naïvely compute 𝑝 and 𝑞 according to these definitions; we can instead use a data structure result by Gao et al. [26] for orthogonal range successor queries to speed up this computation. Unfortunately, this approach leads to an overall running time of 𝑂˜ (|D|(|𝑢 | + ∥C∥)), i.e., asymptotically worse by logarithmic factors. On the positive side, it can be shown that for the special cases where all gap-constraints are just length constraints, or all gap-constraints are singleton languages, the above described variant of Algorithm 1 that allows jumping over larger chunks of D can actually be implemented to run, in the worst case, in time 𝑂 (∥C∥ + |D|(|𝑢 | + |C|)), so faster than the general approach from Theorem 4.1. Moreover, in the general case, even though in an asymptotic worst-case analysis we have to pay with logarithmic factors if we want to be able to jump over larger portions of D, such an improvement could still pay off in an experimental analysis on real-world instances (which would go beyond the scope of this work). All the technical details of the approach described in this subsection are provided in Appendix D.

, Vol. 1, No. 1, Article . Publication date: June 2026.

Tractable Gap-Constraint Languages for Complex Event Recognition

5

13

Computing and Enumerating All Satisfying Embeddings

Our Algorithm 1 from the previous section decides the matching problem (i.e., it checks whether 𝑢 C (D) ≠ ∅) by producing a witness embedding 𝑒 ∈ 𝑢 C (D). Next, we extend the procedure to enumerate with bounded delay all C-embeddings of 𝑢 in D. This is motivated by the fact that, in practical tasks like complex event recognition, computing or enumerating all solutions is more important than just computing some witness. For presentational reasons, we first devise an algorithm that computes 𝑢 C (D), which shall then be extended to an enumeration algorithm. This extension hinges on the property of Algorithm 1 that, called for some starting mapping 𝑒 0 , it returns not just any C-embedding of 𝑢 in D, but the 𝑒 0 -minimal C-embedding 𝑒 min of 𝑢 in D, if it exists. Hence, our algorithm can be employed recursively in the following general way: We first call Algorithm 1 for the trivial initial mapping 𝑒 0 , where 𝑒 0 (𝑖) = 𝑖 for all 𝑖 ∈ [|𝑢 |], to obtain the 𝑒 0 minimal C-embedding 𝑒 min of 𝑢 in D. Next, we want to call Algorithm 1 again to compute somehow ′ a “next” C-embedding 𝑒 min of 𝑢 in D that is larger than 𝑒 min , and so on. Obviously, we cannot just choose 𝑒 min as initial mapping for the next call of Algorithm 1, since 𝑒 min is a C-embedding of 𝑢 in D, so the algorithm would simply output 𝑒 min again. Instead, we have to slightly modify 𝑒 min before using it as the initial mapping of the next call, and simply moving one of its positions one step to the right seems to be a natural choice of such a modification. However, we have to be careful to explore the complete solution space while ensuring that each embedding is discovered exactly once. Let us next sketch how this recursion has to be organised. For a given initial mapping 𝑒 0 and for every 𝑖 ∈ {0, 1, 2 . . . , |𝑢 | − 1}, we define 𝑆 (𝑒 0, 𝑖) = {𝑒 | 𝑒 0 ≤ 𝑒, 𝑒 (1) = 𝑒 0 (1), . . . , 𝑒 (𝑖) = 𝑒 0 (𝑖), 𝑢 ⪯𝑒,C D}, i.e., the set of all C-embeddings of 𝑢 in D lower bounded by 𝑒 0 that agree with 𝑒 0 on the first 𝑖 positions. This set can be partitioned in a natural way as follows. Let us first note that 𝑆 (𝑒 0, 𝑖) = ∅ if and only if we have property (1): 𝑆 (𝑒 0, 0) = ∅ (i.e., there is no C-embedding 𝑒 of 𝑢 in D with 𝑒 0 ≤ 𝑒) or property (2): the 𝑒 0 -minimal C-embedding 𝑒 min of 𝑢 in D does exist, but 𝑒 min (𝑘) > 𝑒 0 (𝑘) for some 𝑘 ∈ [𝑖] (i.e., no C-embedding of 𝑢 in D that is lower bounded by 𝑒 0 also agrees with 𝑒 0 on the first 𝑖 positions). These properties can be checked by one call of Algorithm 1 with initial mapping 𝑒 0 : If the algorithm returns ⊥, then property (1) holds, and if it returns some C-embedding 𝑒 min , we can simply check whether 𝑒 min (𝑘) > 𝑒 0 (𝑘) for some 𝑘 ∈ [𝑖] in order to check property (2). In the following, for every 𝑗 ∈ {𝑖 +1, . . . , |𝑢 |} and mapping 𝑒, let 𝑒 ( 𝑗 ) be obtained from 𝑒 by moving the image of 𝑗 one position to the right. If 𝑆 (𝑒 0, 𝑖) ≠ ∅ and 𝑒 min is the 𝑒 0 -minimal C-embedding of 𝑢 in D (which has been computed by one call to Algorithm 1), then it can be shown that 𝑆 (𝑒 0, 𝑖) (𝑖+1) (𝑖+2) ( |𝑢 | ) is the disjoint union of {𝑒 min } and all the sets 𝑆 (𝑒 min , 𝑖), 𝑆 (𝑒 min , 𝑖 + 1), . . . , 𝑆 (𝑒 min , |𝑢 | − 1). This entails a recursive procedure to compute the set 𝑆 (𝑒 0, 0), which equals 𝑢 C (D) if 𝑒 0 is chosen such that 𝑒 0 (𝑖) = 𝑖 for all 𝑖 ∈ [|𝑢 |]. We can now sketch our procedure. Initially, we are given the trivial mapping 𝑒 0 with 𝑒 0 (𝑖) = 𝑖 for all 𝑖 ∈ [|𝑢 |], and compute the 𝑒 0 -minimal C-embedding 𝑒 min of 𝑢 in D. Then, for every 𝑖 ∈ [|𝑢 |], we recursively determine the set of all C-embeddings 𝑒 ′ with 𝑒 min < 𝑒 ′ , where 𝑒 ′ and 𝑒 min coincide on the first 𝑖 − 1 positions, and where 𝑒 ′ (𝑖) > 𝑒 min (𝑖). Assume we are given some mapping 𝑒 and 𝑗 ∈ {0, 1, . . . , |𝑢 | − 1}, indicating that we are not allowed to move positions 1, . . . , 𝑗, and the 𝑒-minimal C-embedding 𝑒 ∗ of 𝑢 in D exists and coincides with 𝑒 on the first 𝑗 positions. Then, we output 𝑒 ∗ , determine which parts (characterised by (𝑒 ∗ ) (𝑖 ) and 𝑖 ∈ [ 𝑗 + 1, |𝑢 |]) of the partition still contain embeddings, and recursively output the elements of all non-empty subsets. Recall that, as explained above, we can check whether a subset given by (𝑒 ∗ ) (𝑖 ) for some 𝑖 ∈ [ 𝑗 + 1, |𝑢 |] is empty. In order to obtain an enumeration algorithm with bounded delay, we have to be careful with respect to one aspect. It might be possible that some of the sets 𝑆 (𝑒 ( 𝑗 ) , 𝑗 − 1) with 𝑗 ∈ {𝑖 + 1, . . . , |𝑢 |} are empty, so if we start a recursive call for it this may lead to many chains of recursive calls

, Vol. 1, No. 1, Article . Publication date: June 2026.

14

Antoine Amarilli, Florin Manea, Tina Ringleb, and Markus L. Schmid

that will terminate without a new result, which blows-up the delay. Thus, we need a procedure nextMove(𝑒, 𝑖) that, given a C-embedding 𝑒 of 𝑢 in D and 𝑖 ∈ {0, 1, . . . , |𝑢 | − 1}, determines the ′ smallest 𝑖 ′ ∈ [𝑖 + 1, |𝑢 |] such that there is an 𝑒 (𝑖 ) -minimal C-embedding that does not increase ′ any position 𝑘 ∈ [𝑖 − 1] of 𝑒. Thus, after having finished a recursive call for computing some (𝑖 ) 𝑆 (𝑒 min , 𝑖 − 1), nextMove(𝑒 min, 𝑖) tells us for which 𝑖 ′ > 𝑖 we should recursively compute the set (𝑖 ′ ) ′ (𝑖+1) (𝑖 ′ −1) ′ 𝑆 (𝑒 min , 𝑖 − 1) next, i.e., it tells us that the computation of the sets 𝑆 (𝑒 min , 𝑖), . . . , 𝑆 (𝑒 min , 𝑖 − 2) can be skipped, since they are empty anyway. Such a nextMove procedure can be devised as follows: We (𝑖+1) (𝑖+2) simply use Algorithm 1 (as explained above) to check emptiness for 𝑆 (𝑒 min , 𝑖), 𝑆 (𝑒 min , 𝑖 + 1), . . . until we find a non-empty such set (this obviously introduces a factor 𝑂 (|𝑢 |), which can be removed in the case that our constraint languages are both left- and right-convex; see explanations below). For the enumeration algorithm, it is also important that we can organise our recursive calls in such a way that the algorithm is tail-recursive. Let us now state our result (see Appendix E for details). Theorem 5.1. Let 𝑢 ∈ Σ∗ be a query string, let C be a set of left-convex gap-constraints for 𝑢, and let D ∈ Σ∗ with |𝑢 | ≤ |D|. Then we can enumerate the set 𝑢 C (D) of all C-embeddings of 𝑢 in D with 𝑂 (|D|(|𝑢 | + ∥C∥)) preprocessing time and 𝑂 (|𝑢 | · |D|(|𝑢 | + ∥C∥)) delay. (Note that this entails a total computation of 𝑢 C (D) in time 𝑂 (|𝑢 C (D)| · |𝑢 | · |D|(|𝑢 | + ∥C∥)).) Setting 𝑇 to be the running time of Algorithm 1, we can therefore compute (or enumerate) 𝑢 C (D) in time 𝑂 (|𝑢 C (D)| · |𝑢 | · 𝑇 ) (or with 𝑂 (𝑇 ) preprocessing time and 𝑂 (|𝑢 | · 𝑇 ) delay). This leads to the natural question of whether the factor |𝑢 | can be removed. We can show that this is indeed possible, if the constraint languages are all left- and right-convex. This is not too unlikely, e.g., it is provided by the practically relevant length constraints. The reason for this factor |𝑢 | is that after having completed the recursive call for one set ′ 𝑆 (𝑒 (𝑖 ) , 𝑖 − 1), we need to know the smallest 𝑖 ′ with 𝑖 ′ > 𝑖 such that 𝑆 (𝑒 (𝑖 ) , 𝑖 ′ − 1) is non-empty so that we can start a recursive call for this set. We determine this by the nextMove procedure mentioned above. Now if all constraint languages are left- and right-convex, we can apply the following trick in order to implement the nextMove procedure more efficiently. Recall that, given some C-embedding 𝑒 of 𝑢 in D and 𝑖 ∈ {0, 1, . . . , |𝑢 | − 1}, the procedure ′ nextMove(𝑒, 𝑖) determines the smallest 𝑖 ′ ∈ [𝑖 + 1, |𝑢 |] such that there is an 𝑒 (𝑖 ) -minimal Cembedding that does not increase any position 𝑘 ∈ [𝑖 ′ − 1] of 𝑒. Instead of checking this for each 𝑖 +1, 𝑖 +2, . . . individually, we construct a mapping 𝑒 ′ that agrees on its first 𝑖 positions with 𝑒 and has its remaining positions 𝑖 + 1, 𝑖 + 2, . . . , |𝑢 | pushed all the way to the right, i.e., 𝑒 ′ ( 𝑗) = |D| − (|𝑢 | − 𝑗) for every 𝑗 ∈ [𝑖 + 1, |𝑢 |]. Then, we compute a C-embedding 𝑒 max of 𝑢 in D that is 𝑒 ′ -maximal. For this, we simply apply a reversed version of Algorithm 1 (note that the concept of 𝑒 ′ -maximality of C-embeddings and the uniqueness Lemma 4.2 apply analogously). Obviously, this reversed version of Algorithm 1 is correct due to the right-convexity of the constraint languages. This 𝑒 ′ -maximal C-embedding of 𝑢 in D determines the desired 𝑖 ′ as follows. Since 𝑒 max is 𝑒 ′ -maximal, we have that 𝑒 max ≤ 𝑒 ′ . Moreover, 𝑒 ≤ 𝑒 ′ and 𝑒 is a C-embedding of 𝑢 in D, which means that 𝑒 itself is also a candidate for an 𝑒 ′ -maximal C-embedding of 𝑢 in D and therefore 𝑒 ≤ 𝑒 max . Consequently, 𝑒 ≤ 𝑒 max ≤ 𝑒 ′ , which means that 𝑒 max ( 𝑗) = 𝑒 ′ ( 𝑗) for every 𝑗 ∈ [𝑖], since, by definition, we have that 𝑒 ( 𝑗) = 𝑒 ′ ( 𝑗) for every 𝑗 ∈ [𝑖]. Let now 𝑘 be the smallest position of [𝑖 + 1, |𝑢|] such that 𝑒 max (𝑘) > 𝑒 (𝑘). This means that there must be an 𝑒 (𝑘 ) -minimal C-embedding of 𝑢 in D that does not increase any position 𝑗 ∈ [𝑘 − 1] of 𝑒. Moreover, since 𝑘 is chosen minimal, we can conclude that 𝑘 is our desired position 𝑖 ′ . On the other hand, if there is no such 𝑘, then 𝑒 max = 𝑒 and there can be no C-embedding 𝑒 ∗ of 𝑢 in D with 𝑒 < 𝑒 ∗ that agrees with 𝑒 on the first 𝑖 positions. Thus, 𝑆 (𝑒, 𝑖) = {𝑒} and there are no further subsets left to consider. In particular, we need only one call to Algorithm 1 for this procedure. , Vol. 1, No. 1, Article . Publication date: June 2026.

Tractable Gap-Constraint Languages for Complex Event Recognition

15

Adapting our procedure for Theorem 5.1 with this trick allows us to prove the following improvement in the case where all constraint languages are left- and right-convex (full details can be found in Appendix E): Theorem 5.2. Let 𝑢 ∈ Σ∗ be a query string, let C be a set of gap-constraints for 𝑢 that are both left- and right-convex, and let D ∈ Σ∗ with |𝑢 | ≤ |D|. Then we can enumerate the set 𝑢 C (D) with 𝑂 (|D|(|𝑢 | + ∥C∥)) preprocessing time and 𝑂 (|D|(|𝑢 | + ∥C∥)) delay. (Note that this entails a total computation of 𝑢 C (D) in time 𝑂 (|𝑢 C (D)| · |D|(|𝑢 | + ∥C∥)).) 6

Hardness Results for Subsequence Matching with Non-Left-Convex Languages

Having presented our algorithm for subsequence matching with left-convex constraint languages, we now present complexity lower bounds in the case of non-left-convex languages. It is known that the matching problem is NP-complete in general (see [50]). However, the reduction from [50] requires complicated non-left-convex constraint languages. In the following, we will demonstrate that if we even slightly deviate from the left-convex setting of the previous section, then we will obtain intractability again. More precisely, even if we only allow length constraints (which are rather simple left-convex gap-constraints) and in addition {aa, 𝜀} as the only non-left-convex4 gap-language, then we will show that subsequence matching is again NP-complete. Note that the language {aa, 𝜀} could be considered as one of the smallest non-left-convex languages, since every language with strictly smaller cardinality or smaller maximum word size is necessarily left-convex. Let us first introduce some terminology. For a fixed language 𝐿, the matching problem with 𝐿constraints is the restricted case of the matching problem where the input query string 𝑢 and regular gap-constraints C satisfy C ⊆ {(𝑖, 𝑗, 𝐿) | 𝑖, 𝑗 ∈ [|𝑢 |]}, i.e., all gap-constraints are 𝐿-constraints. For the matching problem with length constraints and 𝐿-constraints, we additionally allow length constraints, i.e., we consider the restricted case of the matching problem where the input is assumed to obey the restriction that C ⊆ {(𝑖, 𝑗, 𝐿), (𝑖, 𝑗, [ℓ, 𝑟 ]) | 𝑖, 𝑗 ∈ [|𝑢 |], ℓ, 𝑟 ∈ {0, 1, . . . , |D|}}, where D is the input document. In the rest of this section, we assume that Σ = {a, b}. We first show that the matching problem is NP-complete, even if every constraint from C is either a length constraint or an 𝐿-constraint with 𝐿 = {aa, 𝜀}. Theorem 6.1. The matching problem with length constraints and {aa, 𝜀}-constraints is NP-complete. From this result we can also derive other interesting lower bounds. A main ingredient of our reduction (see Appendix F) is that we can use the constraint language {aa, 𝜀} to enforce that aa is embedded into aaaa either by mapping to the middle two a-occurrences or to the outer two a-occurrences. However, by a slightly more involved construction, we can show that using the language {ab, 𝜀} instead of {aa, 𝜀} also works. This implies that the matching problem becomes intractable even when we restrict instances to require that each constraint language 𝐿 is either left-convex or right-convex, or is a length constraint. Indeed, since {ab, a, 𝜀} ∩ {ab, b, 𝜀} = {ab, 𝜀}, we can “simulate” a constraint (𝑖, 𝑗, {ab, 𝜀}) (which is neither left- nor right-convex, and leads to intractability) by a left-convex constraint (𝑖, 𝑗, {ab, a, 𝜀}) and a right-convex constraint (𝑖, 𝑗, {ab, b, 𝜀}). Our reductions heavily use the property that we can use different constraints on different pairs of positions of 𝑢. This leads to the question of whether we could regain tractability by disallowing length constraints and only allowing one single regular language for all constraints in C. By a nontrivial modification of the reduction from Theorem 6.1 we can answer this question in the negative: there is a fixed (non-left-convex) regular language 𝐿 over Σ = {a, b} such that the matching problem with only 𝐿-constraints is NP-complete even in the absence of length constraints. 4 This language is indeed not left-convex: for 𝑢 = 𝑤 = a and 𝑣 = 𝜀, we have 𝑢𝑣𝑤 = aa ∈ 𝐿 and 𝑣 = 𝜀 ∈ 𝐿, but 𝑢𝑣 = a ∉ 𝐿.

, Vol. 1, No. 1, Article . Publication date: June 2026.

16

7

Antoine Amarilli, Florin Manea, Tina Ringleb, and Markus L. Schmid

Conclusions and Future Work

We have shown that using left-convex (or right-convex) languages as constraint languages in the context of CER based on subsequence matching entails efficient matching and enumeration algorithms. Moreover, our hardness results suggest that even using simple non-left-convex languages can lead to intractability. What is missing is a full dichotomy in the sense of finding a language class such that subsequence matching is tractable if and only if we use constraint languages from that language class. We believe that this is a rather challenging research task. Following the CSP approach of Section 3, one direction could be to study whether more general conditions on gap-constraint languages can ensure the tractability of the CSP-instances that we construct. Other than that, our algorithms are easy to implement and have running times that make them competitive also in a practical scenario. Consequently, prototype implementations and an experimental analysis would be a possible future research task. Furthermore, it would be interesting to investigate whether our general algorithmic approach can be adapted to query languages for complex event processing tailored to more practical scenarios (e.g. [27]). References [1] Amir Abboud, Arturs Backurs, and Virginia Vassilevska Williams. 2015. Tight hardness results for LCS and other sequence similarity measures. In FOCS. doi:10.1109/FOCS.2015.14 [2] Amir Abboud, Virginia Vassilevska Williams, and Oren Weimann. 2014. Consequences of faster alignment of sequences. In ICALP. doi:10.1007/978-3-662-43948-7_4 [3] Duncan Adamson, Paul Sarnighausen-Cahn, Marius Dumitran, Maria Kosche, Tore Koß, Florin Manea, and Stefan Siemer. 2025. Longest common subsequence with gap constraints. Theory Comput. Syst. 69, 2 (2025). doi:10.1007/S00224025-10223-0 [4] Jagrati Agrawal, Yanlei Diao, Daniel Gyllstrom, and Neil Immerman. 2008. Efficient pattern matching over event streams. In SIGMOD. ACM. doi:10.1145/1376616.1376634 [5] Thomas Ang and Janusz A. Brzozowski. 2008. Continuous languages. In AFL. [6] Thomas Ang and Janusz A. Brzozowski. 2009. Languages convex with respect to binary relations, and their closure properties. Acta Cybern. 19, 2 (2009). https://cyber.bibl.u-szeged.hu/index.php/actcybern/article/view/3776 [7] Alexander Artikis, Alessandro Margara, Martín Ugarte, Stijn Vansummeren, and Matthias Weidlich. 2017. Complex event recognition languages: Tutorial. In DEBS. doi:10.1145/3093742.3095106 [8] Arturs Backurs and Piotr Indyk. 2016. Which regular expression patterns are hard to match?. In FOCS. [9] Ricardo A Baeza-Yates. 1991. Searching subsequences. Theoretical Computer Science 78, 2 (1991). [10] Christian Bessiere. 2006. Constraint propagation. In Handbook of Constraint Programming. Elsevier. doi:10.1016/S15746526(06)80007-6 [11] Christian Bessière, Jean-Charles Régin, Roland H. C. Yap, and Yuanlin Zhang. 2005. An optimal coarse-grained arc consistency algorithm. Artif. Intell. 165, 2 (2005). doi:10.1016/J.ARTINT.2005.02.004 [12] Karl Bringmann and Bhaskar Ray Chaudhury. 2018. Sketching, streaming, and fine-grained complexity of (weighted) LCS. In FSTTCS. [13] Karl Bringmann, Allan Grønlund, Marvin Künnemann, and Kasper Green Larsen. 2024. The NFA acceptance hypothesis: Non-combinatorial and dynamic lower bounds. TheoretiCS 3 (2024). doi:10.46298/THEORETICS.24.22 [14] Karl Bringmann and Marvin Künnemann. 2018. Multivariate fine-grained complexity of longest common subsequence. In SODA. [15] Janusz A. Brzozowski, Jeffrey O. Shallit, and Zhi Xu. 2011. Decision problems for convex languages. Inf. Comput. 209, 3 (2011). doi:10.1016/J.IC.2010.11.009 [16] Andrei A. Bulatov. 2017. A dichotomy theorem for nonuniform CSPs. In FOCS. doi:10.1109/FOCS.2017.37 [17] Sam Buss and Michael Soltys. 2014. Unshuffling a square is NP-hard. J. Comput. Syst. Sci. 80, 4 (2014). doi:10.1016/j. jcss.2013.11.002 [18] David A. Cohen and Peter Jeavons. 2006. The complexity of constraint languages. In Handbook of Constraint Programming. Elsevier. doi:10.1016/S1574-6526(06)80012-X [19] Joel D. Day, Maria Kosche, Florin Manea, and Markus L. Schmid. 2022. Subsequences with gap constraints: Complexity bounds for matching and analysis problems. In ISAAC. doi:10.4230/LIPICS.ISAAC.2022.64 [20] Johannes Fischer and Volker Heun. 2006. Theoretical and practical improvements on the RMQ-problem, with applications to LCA and LCE. In CPM. doi:10.1007/11780441_5

, Vol. 1, No. 1, Article . Publication date: June 2026.

Tractable Gap-Constraint Languages for Complex Event Recognition

17

[21] Pamela Fleischmann, Sungmin Kim, Tore Koß, Florin Manea, Dirk Nowotka, Stefan Siemer, and Max Wiedenhöft. 2023. Matching patterns with variables under Simon’s congruence. In RP. https://doi.org/10.1007/978-3-031-45286-4_12 [22] Eugene C. Freuder and Alan K. Mackworth. 2006. Constraint Satisfaction: An Emerging Paradigm. In Handbook of Constraint Programming, Francesca Rossi, Peter van Beek, and Toby Walsh (Eds.). Elsevier, 13–27. doi:10.1016/S15746526(06)80006-4 [23] Dominik D. Freydenberger, Pawel Gawrychowski, Juhani Karhumäki, Florin Manea, and Wojciech Rytter. 2015. Testing 𝑘-binomial equivalence. In Multidisciplinary Creativity, a collection of papers dedicated to G. Păun 65th birthday. available in CoRR abs/1509.00622. [24] André Frochaux and Sarah Kleest-Meißner. 2023. Puzzling over subsequence-query extensions: Disjunction and generalised gaps. In AMW. https://ceur-ws.org/Vol-3409/paper3.pdf [25] André Frochaux, Sarah Kleest-Meißner, and Benjamin Scheidt. 2025. Reaching new limits: Discovery of multidimensional disjunctive subsequence-queries with intervals. In Datenbanksysteme für Business, Technologie und Web (BTW 2025), 21. Fachtagung des GI-Fachbereichs „Datenbanken und Informationssysteme" (DBIS). doi:10.18420/BTW202502 [26] Younan Gao, Meng He, and Yakov Nekrich. 2020. Fast preprocessing for optimal orthogonal range reporting and range successor with applications to text indexing. In ESA. doi:10.4230/LIPIcs.ESA.2020.54 [27] Julián García and Cristian Riveros. 2025. Complex event recognition under time constraints: Towards a formal framework for efficient query evaluation. Proc. ACM Manag. Data 3, 2 (2025). doi:10.1145/3725231 [28] Nikos Giatrakos, Elias Alevizos, Alexander Artikis, Antonios Deligiannakis, and Minos N. Garofalakis. 2020. Complex event recognition in the Big Data era: A survey. VLDB J. 29, 1 (2020). doi:10.1007/s00778-019-00557-w [29] Inge Li Gørtz, Sebastian Maneth, Gonzalo Navarro, and Nicola Prezza. 2024. Regular expressions: Matching and indexing (Dagstuhl Seminar 24472). Dagstuhl Reports 14, 11 (2024). doi:10.4230/DAGREP.14.11.108 [30] Alejandro Grez, Cristian Riveros, Martín Ugarte, and Stijn Vansummeren. 2021. A formal framework for complex event recognition. ACM Trans. Database Syst. 46, 4 (2021). doi:10.1145/3485463 [31] Simon Halfon, Philippe Schnoebelen, and Georg Zetzsche. 2017. Decidability, complexity, and expressiveness of first-order logic over the subword ordering. In LICS. [32] Pascal Van Hentenryck, Yves Deville, and Choh Man Teng. 1992. A generic arc-consistency algorithm and its specializations. Artif. Intell. 57, 2-3 (1992). doi:10.1016/0004-3702(92)90020-X [33] John E. Hopcroft, Rajeev Motwani, and Jeffrey D. Ullman. 2001. Introduction to automata theory, languages, and computation. Addison-Wesley. [34] Lucian Ilie, Gonzalo Navarro, and Liviu Tinta. 2010. The longest common extension problem revisited and applications to approximate string searching. J. Discrete Algorithms 8, 4 (2010). doi:10.1016/J.JDA.2010.08.004 [35] Peter Jeavons. 1998. On the algebraic structure of combinatorial problems. Theor. Comput. Sci. 200, 1-2 (1998). doi:10.1016/S0304-3975(97)00230-2 [36] Peter Jeavons, David A. Cohen, and Marc Gyssens. 1997. Closure properties of constraints. J. ACM 44, 4 (1997). doi:10.1145/263867.263489 [37] Peter Jeavons and Martin C. Cooper. 1995. Tractable constraints on ordered domains. Artif. Intell. 79, 2 (1995). doi:10.1016/0004-3702(95)00107-7 [38] Prateek Karandikar, Manfred Kufleitner, and Philippe Schnoebelen. 2015. On the index of Simon’s congruence for piecewise testability. Inf. Process. Lett. 115, 4 (2015). [39] Prateek Karandikar and Philippe Schnoebelen. 2016. The height of piecewise-testable languages with applications in logical complexity. In CSL (LIPIcs, Vol. 62). [40] Prateek Karandikar and Philippe Schnoebelen. 2019. The height of piecewise-testable languages and the complexity of the logic of subwords. Log. Methods Comput. Sci. 15, 2 (2019). [41] Sarah Kleest-Meißner, Rebecca Sattler, Markus L. Schmid, Nicole Schweikardt, and Matthias Weidlich. 2022. Discovering event queries from traces: Laying foundations for subsequence-queries with wildcards and gap-size constraints. In ICDT. [42] Sarah Kleest-Meißner, Rebecca Sattler, Markus L. Schmid, Nicole Schweikardt, and Matthias Weidlich. 2023. Discovering multi-dimensional subsequence queries from traces - From theory to practice. In Datenbanksysteme für Business, Technologie und Web (BTW 2023), 20. Fachtagung des GI-Fachbereichs „Datenbanken und Informationssysteme" (DBIS). doi:10.18420/BTW2023-24 [43] Maria Kosche, Tore Koß, Florin Manea, and Stefan Siemer. 2022. Combinatorial algorithms for subsequence matching: A survey. In NCMA (EPTCS, Vol. 367). doi:10.4204/EPTCS.367.2 [44] Dietrich Kuske. 2020. The subtrace order and counting first-order logic. In CSR. [45] Dietrich Kuske and Georg Zetzsche. 2019. Languages ordered by the subword order. In FOSSACS (LNCS, Vol. 11425). [46] Marie Lejeune, Julien Leroy, and Michel Rigo. 2019. Computing the 𝑘-binomial complexity of the Thue-Morse word. In DLT.

, Vol. 1, No. 1, Article . Publication date: June 2026.

18

Antoine Amarilli, Florin Manea, Tina Ringleb, and Markus L. Schmid

[47] Julien Leroy, Michel Rigo, and Manon Stipulanti. 2017. Generalized Pascal triangle for binomial coefficients of words. Electron. J. Combin. 24, 1.44 (2017). [48] Alan K. Mackworth. 1977. Consistency in networks of relations. Artif. Intell. 8, 1 (1977). doi:10.1016/0004-3702(77)900078 [49] David Maier. 1978. The complexity of some problems on subsequences and supersequences. J. ACM 25, 2 (1978), 15 pages. [50] Florin Manea, Jonas Richardsen, and Markus L. Schmid. 2024. Subsequences with generalised gap constraints: Upper and lower complexity bounds. In CPM. doi:10.4230/LIPIcs.CPM.2024.22 [51] Alexandru Mateescu, Arto Salomaa, and Sheng Yu. 2004. Subword histories and Parikh matrices. J. Comput. Syst. Sci. 68, 1 (2004). doi:10.1016/J.JCSS.2003.04.001 [52] M. Praveen, Philippe Schnoebelen, Julien Veron, and Isa Vialard. 2024. On the piecewise complexity of words and periodic words. In SOFSEM. doi:10.1007/978-3-031-52113-3_32 [53] William E. Riddle. 1979. An approach to software system modelling and analysis. Comput. Lang. 4, 1 (1979). doi:10. 1016/0096-0551(79)90009-2 [54] Michel Rigo and Pavel Salimov. 2015. Another generalization of abelian equivalence: Binomial complexity of infinite words. Theor. Comput. Sci. 601 (2015). [55] Arto Salomaa. 2005. Connections between subwords and certain matrix mappings. Theor. Comput. Sci. 340, 1 (2005). doi:10.1016/J.TCS.2005.03.024 [56] Rebecca Sattler, Sarah Kleest-Meißner, Steven Lange, Markus L. Schmid, Nicole Schweikardt, and Matthias Weidlich. 2025. DISCES: Systematic discovery of event stream queries. Proc. ACM Manag. Data 3, 1 (2025). doi:10.1145/3709682 [57] Rebecca Sattler, Sarah Kleest-Meißner, Steven Lange, Markus L. Schmid, Nicole Schweikardt, and Matthias Weidlich. 2025. Embracing change: Incremental updates of discovered event queries. In Datenbanksysteme für Business, Technologie und Web (BTW 2025), 21. Fachtagung des GI-Fachbereichs „Datenbanken und Informationssysteme" (DBIS), 03.-07, März 2025, Bamberg, Germany, Proceedings. doi:10.18420/BTW2025-19 [58] Philippe Schnoebelen and Julien Veron. 2023. On arch factorization and subword universality for words and compressed words. In WORDS. doi:10.1007/978-3-031-33180-0_21 [59] Shinnosuke Seki. 2012. Absoluteness of subword inequality is undecidable. Theor. Comput. Sci. 418 (2012). [60] Alan C. Shaw. 1978. Software descriptions with flow expressions. IEEE Trans. Software Eng. 4, 3 (1978). doi:10.1109/ TSE.1978.231501 [61] Imre Simon. 1972. Hierarchies of events with dot-depth one. Ph. D. Dissertation. University of Waterloo. [62] Imre Simon. 1975. Piecewise testable events. In Automata Theory and Formal Languages, 2nd GI Conference. [63] Gabriel Thierrin. 1972. Convex languages. In ICALP. [64] Virginia Vassilevska Williams. 2018. On some fine-grained questions in algorithms and complexity. In ICM. doi:10. 1142/9789813272880_0188 [65] Eugene Wu, Yanlei Diao, and Shariq Rizvi. 2006. High-performance complex event processing over streams. In SIGMOD. doi:10.1145/1142473.1142520 [66] Georg Zetzsche. 2016. The complexity of downward closure comparisons. In ICALP, Vol. 55. [67] Haopeng Zhang, Yanlei Diao, and Neil Immerman. 2014. On complexity and optimization of expensive queries in complex event processing. In SIGMOD. doi:10.1145/2588555.2593671 [68] Yuanlin Zhang and Roland H. C. Yap. 2001. Making AC-3 an optimal algorithm. In IJCAI. [69] Dmitriy Zhuk. 2017. A proof of CSP dichotomy conjecture. In FOCS. doi:10.1109/FOCS.2017.38 [70] Dmitriy Zhuk. 2020. A proof of the CSP dichotomy conjecture. J. ACM 67, 5 (2020). doi:10.1145/3402029

A

More Information About the Left-Convex Property

In this section, we explore in more detail the class of left-convex languages for which we have presented an efficient algorithm. We show that left-convex languages serve as a unifying explanation of the tractability of many classes of regular languages that are interesting on their own. Then, we discuss the closure properties of the class of left-convex languages, showing that they are closed under intersection but not under union. We last discuss the complexity of testing whether a language is left-convex: we show that it is PSPACE-complete given an NFA, but that it is in polynomial time when the input is a deterministic finite automaton (DFA). Recall the definition of the left-convex property given in the Introduction (Definition 1.2). Analogously, we define a language 𝐿 to be right-convex if 𝑢𝑣𝑤 ∈ 𝐿 and 𝑣 ∈ 𝐿 implies 𝑣𝑤 ∈ 𝐿. We , Vol. 1, No. 1, Article . Publication date: June 2026.

Tractable Gap-Constraint Languages for Complex Event Recognition

19

shall use RCON to denote the class of right-convex languages. Also note that 𝐿 is right-convex if and only if 𝐿𝑅 is left-convex. Examples of Left-Convex Languages. We overview here more example languages which have the left-convex property (the proofs that the respective classes of languages have this property are immediate and omitted): • Infix-closed (respectively, prefix-closed) languages, i.e., 𝑣 ∈ 𝐿 =⇒ 𝑢 ∈ 𝐿 for all proper infixes (respectively, prefixes) 𝑢 of 𝑣. • Infix-free languages, i.e., 𝑣 ∈ 𝐿 =⇒ 𝑢 ∉ 𝐿 for all proper infixes 𝑢 of 𝑣. • Finite languages where all words have the same length, i.e., 𝐿 = {𝑣 1, 𝑣 2, . . . , 𝑣𝑘 | |𝑣 1 | = |𝑣 2 | = . . . = |𝑣𝑘 |}. Indeed, these are a special case of infix-free languages. • Languages with unique start or end delimiter, i.e., 𝐿 ⊆ {𝑥𝑣 | 𝑣 ∈ Σ∗ } or 𝐿 ⊆ {𝑣𝑥 | 𝑣 ∈ Σ∗ }, where 𝑥 ∉ Σ. • Languages closed under left-extension, i.e., 𝑣 ∈ 𝐿 ⇒ 𝑢𝑣 ∈ 𝐿 for all 𝑢, 𝑣 ∈ Σ∗ . • Languages defined by a forbidden set of infixes and a required set of infixes, i.e., given sets of words 𝐹, 𝑅 ⊆ Σ∗ , 𝐿 = (Σ∗ \ Σ∗ 𝐹 Σ∗ ) ∩ (Σ∗𝑅Σ∗ ), for some alphabet Σ. Note that we can additionally add a set of forbidden prefixes and a set of required suffixes and the languages thus defined are still left-convex. • Downward and upward closures of any language. Recall that the downward and upward closure of a language 𝐿 is the set of all subsequences (respectively, supersequences) of the words of 𝐿. • Length constraints, i.e., languages 𝐿 = {𝑤 | 𝑎 ≤ |𝑤 | ≤ 𝑏} for some integers 𝑎 ≤ 𝑏. • Languages defined by upper and lower bounding the number of occurrences of certain symbols, e.g., 𝐿 = {𝑤 | 3 ≤ |𝑤 | a ≤ 7 ∧ 5 ≤ |𝑤 | b ≤ 23}, where |𝑤 | a denotes the number of occurrences of a in 𝑤. Note that prefix- and suffix-free languages are not necessarily left-convex. For instance, the language 𝐿 = {aba, b} is both prefix-free and suffix-free, but is not left-convex, as for 𝑢 = a, 𝑣 = b, 𝑤 = a we have that 𝑢𝑣𝑤 = aba ∈ 𝐿, 𝑣 = b ∈ 𝐿, but 𝑢𝑣 = ab ∉ 𝐿. Also, languages defined by a required set of prefixes (𝐿 = 𝑆 Σ∗ for some set 𝑆 ⊆ Σ∗ , over alphabet Σ) are not necessarily left-convex. For instance, for 𝑆 = {aba, b}, let 𝑢 = a, 𝑣 = b, 𝑤 = a, so 𝑢𝑣𝑤 = aba ∈ 𝐿, 𝑣 = b ∈ 𝐿, but 𝑢𝑣 = ab ∉ 𝐿. With respect to left-convex languages that are not right-convex (or right-convex languages that are not left-convex), we observe that any language of the form 𝑆 Σ∗ for some 𝑆 ⊆ Σ∗ , even if it is not left-convex, is right-convex. Thus, the language defined by 𝑆 = {aba, b} is an example of a right-convex language that is not left-convex (and reversing it yields an example of a left-convex language that is not right-convex). The language {aa, 𝜀} is a very simple example of a language that is neither left- nor right-convex. This can be easily extended to classes of languages that are neither left- nor right-convex, e.g., languages of the form {𝑤, 𝜀} with |𝑤 | ≥ 2, or languages of the form 𝐿 = {𝑤 ∈ {a, b}∗ | |𝑤 | a is divisible by 𝑘 } and 𝑘 ≥ 2. Closure Properties. The class of left-convex languages (or right-convex languages) is obviously not closed under union, because the singleton languages {𝜀} and {aa} are trivially both left-convex and right-convex but their union {𝜀, aa} is neither. However, the class of left-convex languages (as well as the class of right-convex languages) is easily seen to be closed under intersection; this is particularly interesting in the context of this paper, as it shows that multiple left-convex gap-constraints (𝑖, 𝑗, 𝐿1 ), (𝑖, 𝑗, 𝐿2 ), . . . , (𝑖, 𝑗, 𝐿𝑚 ) for the same Ñ𝑚 pair (𝑖, 𝑗) of positions could always be interpreted as a single left-convex gap-constraint (𝑖, 𝑗, 𝑘=1 𝐿𝑘 ). However, obtaining a representaÑ tion of the language 𝑚 𝑘=1 𝐿𝑘 from the representations of the languages 𝐿𝑘 with 𝑘 ∈ [𝑚] is usually computationally inefficient. Thus, it is a relevant feature of our algorithm that it can handle the , Vol. 1, No. 1, Article . Publication date: June 2026.

20

Antoine Amarilli, Florin Manea, Tina Ringleb, and Markus L. Schmid

situation of several left-convex constraints for the same pair of positions without the necessity of computing a representation of the intersection. Membership Testing. Let us next consider the problem of checking whether a given regular language is left-convex. Theorem A.1. Checking whether a given NFA accepts a left-convex language is PSPACE-complete, but it can be done in polynomial time for a given DFA. Proof. Let us first start with a proof for the DFA-case, since we shall use parts of it for the NFA-case later on. Let 𝑀 be a DFA. We observe that L (𝑀) is not left-convex if 𝑀 accepts a word 𝑥 that can be factorised into 𝑥 = 𝑢𝑣𝑤 such that 𝑀 accepts 𝑣, but not 𝑢𝑣. This is the case if and only if there is a path from the start state 𝑞 0 to an accepting state 𝑞 𝑓 such that: • there are states 𝑝 1 and 𝑝 2 that lie on this path in that order, • 𝑝 2 is non-accepting, • the word 𝑣 read between 𝑝 1 and 𝑝 2 is accepted by 𝑀 (i.e., there is a 𝑣-labelled path from 𝑞 0 to some accepting state). For the if-direction, note that if we denote the word read between 𝑞 0 and 𝑝 1 as 𝑢, the word read between 𝑝 1 and 𝑝 2 as 𝑣, and the word read between 𝑝 2 and 𝑞 𝑓 as 𝑤, then we have that 𝑢𝑣𝑤 ∈ L (𝑀) and 𝑣 ∈ L (𝑀), but 𝑢𝑣 ∉ L (𝑀) (since 𝑝 2 is not accepting). For the only-if-direction, assume that 𝑀 accepts a word 𝑥 = 𝑢𝑣𝑤 such that 𝑀 accepts 𝑣, but not 𝑢𝑣. Then we take the accepting path of 𝑀 on 𝑥 and let 𝑝 1 and 𝑝 2 be the states reached after reading 𝑢 and 𝑢𝑣, respectively. Obviously, the conditions stated above are satisfied. We can therefore solve the problem as follows: In polynomial time, we can make sure that every state of 𝑀 is reachable from the start state and that there is exactly one state that cannot reach an accepting state, which we call the trap state. For every pair (𝑝 1, 𝑝 2 ) of states such that neither 𝑝 1 nor 𝑝 2 are the trap state and 𝑝 2 is not accepting, we check whether there is a string 𝑣 that brings 𝑀 from 𝑝 1 to 𝑝 2 and from 𝑞 0 to an accepting state. To this end, we construct the DFA 𝑀𝑝 1,𝑝 2 that accepts all words that 𝑀 can read between 𝑝 1 and 𝑝 2 , and then the DFA 𝑀∩ that accepts L (𝑀) ∩ L (𝑀𝑝 1,𝑝 2 ). Finally, we only have to check emptiness for 𝑀∩ . This algorithm can clearly be carried out in polynomial time. Let us now come to the NFA-case and let us start with the upper bound, i.e., membership to PSPACE. Let 𝑀 be an NFA with state set 𝑄 and let 𝑀D be the DFA obtained from 𝑀 by the subset construction (obviously, we cannot afford to explicitly construct 𝑀D ), and let us also assume that the state set 𝑄 D of 𝑀D is the full power set of 𝑄. We can now check whether L (𝑀) is left-convex, by checking whether L (𝑀D ) is left-convex as described above in the DFA-case. Hence, we have to explain how we can do this nondeterministically in space polynomial in |𝑀 |. We first guess two states 𝑃1 and 𝑃2 of 𝑀D (recall that states of 𝑀D are just subsets of 𝑀’s states) such that 𝑃 2 is not an accepting state of 𝑀D . Next, we check whether there is a word that brings 𝑀D from the start state to the state 𝑃 1 . To this end, let us first observe that there is such a word if and only if there is such a word of length at most 2 |𝑄 | (due to standard pumping arguments). Hence, we can guess a word of length 2 |𝑄 | symbol by symbol and in parallel simulate 𝑀D on this word, and we stop as soon as we reached 𝑃 1 or the word length has reached 2 |𝑄 | . In each step of this simulation, we only have to store 𝑂 (|𝑄 |) states of 𝑀 and a number that is at most 2 |𝑄 | (to keep track of the word length). Since we can store a number that is at most 2 |𝑄 | with |𝑄 | bits, we only require space polynomial in |𝑄 |. In a similar way, we can nondeterministically check whether there is a word that brings 𝑀D from 𝑃 2 to some accepting state. , Vol. 1, No. 1, Article . Publication date: June 2026.

Tractable Gap-Constraint Languages for Complex Event Recognition

21

Now, it only remains to check whether there is a word 𝑣 that brings 𝑀D from 𝑃1 to 𝑃2 and also from the start state to some accepting state. We first observe that there is such a word if and only if there is such a word of length at most |𝑄 D | 2 (recall that 𝑄 D is the state set of 𝑀D ). Indeed, this follows again from a pumping argument, as we now explain. If the shortest such word 𝑣 satisfies |𝑣 | > |𝑄 D | 2 and there is a 𝑣-path (𝑆 0, 𝑆 1, . . . , 𝑆 |𝑣 | ) from the start to an accepting state and a 𝑣-path (𝑇0,𝑇1, . . . ,𝑇|𝑣 | ) from 𝑃1 to 𝑃2 , then (𝑆𝑖 ,𝑇𝑖 ) = (𝑆 𝑗 ,𝑇 𝑗 ) for some 𝑖, 𝑗 with 0 ≤ 𝑖 < 𝑗 ≤ |𝑣 |. This means that (𝑆 0, . . . , 𝑆𝑖 , 𝑆 𝑗+1, . . . , 𝑆 |𝑣 | ) is a path from the start to an accepting state and (𝑇0, . . . ,𝑇𝑖 ,𝑇 𝑗+1, . . . ,𝑇|𝑣 | ) is a path from 𝑃 1 to 𝑃2 , and the label of both paths is identical. This contradicts the minimality of 𝑣. Hence, we only have to check if there is a word 𝑣 of size at most |𝑄 D | 2 = (2 |𝑄 | ) 2 that brings 𝑀D from 𝑃1 to 𝑃2 and also from the start to an accepting state. This can be done as follows: We guess a word of length (2 |𝑄 | ) 2 symbol by symbol and in parallel simulate 𝑀D on this word starting in the start state and also simulate 𝑀D on this word starting in 𝑃1 . We stop as soon as we reach an accepting state with the first simulation and 𝑃2 with the second simulation, or when the word length has reached (2 |𝑄 | ) 2 . Again, we only require space that is polynomial in |𝑄 |, since we have to store 𝑂 (|𝑄 |) states of 𝑀 and a number of size at most (2 |𝑄 | ) 2 . This concludes the proof that the problem is in PSPACE. Let us next come to the lower bound, i.e., that the problem is PSPACE-hard. We prove this by reducing from the PSPACE-hard universality problem for NFAs, i.e., the problem to decide L (𝑀) = Σ∗ for a given NFA 𝑀 over Σ. Let 𝑀 be an arbitrary NFA that accepts a language 𝐿 and we want to decide whether 𝐿 = Σ∗ . We define the regular language 𝐾 = {#𝑥# | 𝑥 ∈ 𝐿} ∪ {#𝑥## | 𝑥 ∈ Σ∗ } ∪ {#}, where # is a fresh letter not in Σ, and we note that an NFA for 𝐾 can be easily constructed in polynomial time from 𝑀. We now claim that 𝐾 is not left-convex if and only if 𝐿 ≠ Σ∗ . Let us first prove the if-direction and assume that 𝐿 ≠ Σ∗ , which means that there is some 𝑥 ∈ Σ∗ with 𝑥 ∉ 𝐿. We will now consider the word #𝑥## and its factorisation 𝑢 = #𝑥, 𝑣 = # and 𝑤 = #. Obviously, 𝑢𝑣𝑤 ∈ 𝐾 and 𝑣 ∈ 𝐾, but 𝑢𝑣 = #𝑥# ∉ 𝐾 because 𝑥 ∉ 𝐿. Consequently, 𝐾 is not left-convex. For the only-if-direction, let us assume that 𝐾 is not left-convex, which means that there is some 𝑢𝑣𝑤 ∈ 𝐾 with 𝑣 ∈ 𝐾, but 𝑢𝑣 ∉ 𝐾. Since 𝑢𝑣𝑤 ∈ 𝐾, we have that 𝑢𝑣𝑤 ∈ {#𝑥# | 𝑥 ∈ 𝐿} or 𝑢𝑣𝑤 ∈ {#𝑥## | 𝑥 ∈ Σ∗ } or 𝑢𝑣𝑤 ∈ {#}. We observe that 𝑢𝑣𝑤 ∈ {#𝑥# | 𝑥 ∈ 𝐿} is not possible, since then 𝑣 ∈ 𝐾 implies that 𝑣 is the first or last #-occurrence or 𝑣 = 𝑢𝑣𝑤, which contradicts 𝑢𝑣 ∉ 𝐿. Likewise, 𝑢𝑣𝑤 = # is not possible while ensuring 𝑣 ∈ 𝐾 and 𝑢𝑣 ∉ 𝐾. Hence, we must have 𝑢𝑣𝑤 = #𝑥## for some 𝑥 ∈ Σ∗ . If 𝑣 is a prefix or a suffix, we would have 𝑣 = 𝑢𝑣 or 𝑢𝑣 = 𝑢𝑣𝑤, respectively, which would contradict 𝑢𝑣 ∉ 𝐾. Since 𝑣 ∈ 𝐾, we conclude that 𝑣 must be the second occurrence of #. Thus, 𝑢 = #𝑥, 𝑣 = # and 𝑤 = #. Therefore, 𝑢𝑣 ∉ 𝐾 implies #𝑥# ∉ 𝐾, which means that 𝑥 ∉ 𝐿. Consequently, 𝐿 ≠ Σ∗ . □

B

Full Details for Section 3

In this section, we discuss in more details the formulation of the subsequence matching with gap-constraints problem as a Constraint Satisfaction Problem (for short, CSP), and how this leads to a series of interesting results. As mentioned in the main part of the paper, this allows us to show that the respective problem can be solved in polynomial time when left-convex regular constraints (e.g., length constraints) are considered. Let us first introduce the CSP-related machinery that we will use in this section; we follow the definitions from [18], which extend the terminology from the main part of the paper to a more general setting. This setting allows us a more precise and detailed presentation compared to that from the main part.

, Vol. 1, No. 1, Article . Publication date: June 2026.

22

Antoine Amarilli, Florin Manea, Tina Ringleb, and Markus L. Schmid

Let 𝑇 be a set (called domain in the following) and let 𝑅𝑇 denote the set of all finitary relations over 𝑇 (subsets of 𝑇 𝑘 for any 𝑘 ≥ 1). A constraint language Γ over 𝑇 is a subset of 𝑅𝑇 . We also define the set 𝑂𝑇 of all mappings 𝑓 : 𝑇 𝑘 → 𝑇 , for all 𝑘 ≥ 1. A 𝑘-ary operation 𝑓 ∈ 𝑂𝑇 is called a weak near-unanimity operation (WNU, for short) if it satisfies 𝑓 (𝑦, 𝑥, . . . , 𝑥) = 𝑓 (𝑥, 𝑦, 𝑥, . . . , 𝑥) = · · · = 𝑓 (𝑥, 𝑥, . . . , 𝑥, 𝑦) for all 𝑥, 𝑦 ∈ 𝑇 ; 𝑓 is called idempotent if 𝑓 (𝑥, 𝑥, . . . , 𝑥) = 𝑥 for all 𝑥 ∈ 𝑇 . A binary mapping 𝑓 ∈ 𝑂𝑇 which satisfies the identities 𝑓 (𝑥, 𝑓 (𝑦, 𝑧)) = 𝑓 (𝑓 (𝑥, 𝑦), 𝑧) (associativity), 𝑓 (𝑥, 𝑦) = 𝑓 (𝑦, 𝑥) (commutativity), and which is idempotent is called a semilattice operation over 𝑇 . For 𝑓 : 𝑇 𝑘 → 𝑇 and tuples 𝑡 1, . . . , 𝑡𝑘 ∈ 𝑇 𝑛 , we define 𝑓 (𝑡 1, . . . , 𝑡𝑘 ) ∈ 𝑇 𝑛 to be the 𝑛-tuple ⟨𝑓 (𝑡 1 [1], . . . , 𝑡𝑘 [1]), . . . , 𝑓 (𝑡 1 [𝑛], . . . , 𝑡𝑘 [𝑛])⟩. We say that 𝑓 : 𝑇 𝑘 → 𝑇 preserves an 𝑛-ary relation 𝑅 over 𝑇 (or 𝑓 is a polymorphism of 𝑅) if 𝑓 (𝑡 1, . . . , 𝑡𝑘 ) ∈ 𝑅 for all 𝑛-tuples 𝑡 1, . . . , 𝑡𝑘 ∈ 𝑅. For some constraint language Γ over 𝑇 , we define Pol(Γ) = {𝑓 ∈ 𝑂𝑇 | 𝑓 preserves each relation from Γ}. Now, for any domain 𝑇 and any constraint language Γ over 𝑇 , the constraint satisfaction problem CSP(Γ) is the decision problem which has as instance (as input) a triple P = ⟨𝑉 ,𝑇 , 𝐾⟩, where 𝑉 = {1, . . . , 𝑚} is a set of variables (denoted, for simplicity, with the first 𝑚 natural numbers) and 𝐾 is a set of constraints {𝐾1, . . . , 𝐾𝑞 }, such that each constraint 𝐾𝑖 ∈ 𝐾 is a pair ⟨𝑠𝑖 , 𝑅𝑖 ⟩, where 𝑠𝑖 ⊆ 𝑉 is a set of variables of size 𝑛𝑖 (called the constraint scope) and 𝑅𝑖 ∈ Γ is an 𝑛𝑖 -ary relation over 𝑇 , called the constraint relation; w.l.o.g., we assume that 𝑠𝑖 is increasingly ordered, and by 𝑠𝑖 [ 𝑗] we denote the 𝑗 𝑡ℎ element of 𝑠𝑖 . An instance P = ⟨𝑉 ,𝑇 , 𝐾⟩ of CSP(Γ) is called normalised if there do not exist two different constraints in 𝐾 that have the same scope. A solution for an instance P of CSP(Γ) is a function 𝜙 : 𝑉 → 𝑇 such that for each ⟨𝑠𝑖 , 𝑅𝑖 ⟩ ∈ 𝐾 the tuple ⟨𝜙 (𝑠𝑖 [1]), . . . , 𝜙 (𝑠𝑖 [𝑛𝑖 ])⟩ is in 𝑅𝑖 . Accordingly, for some instance P of CSP(Γ), we are interested in whether it admits a solution. Note that, in this definition of CSPs, the problems are parameterised by the constraint language Γ, which restricts the type of allowed constraints. A constraint language Γ is said to be tractable if CSP(Γ ′ ) can be solved in polynomial time, for each finite subset Γ ′ ⊆ Γ. For the sake of completeness, let us mention also that a constraint language Γ is said to be NP-complete if CSP(Γ ′ ) is NP-complete, for each finite subset Γ ′ ⊆ Γ. In [35, 36] it was shown that the tractability of CSP(Γ) depends on the algebraic properties of the set Pol(Γ) of operations which preserve all relations of Γ. Consequently, in [18] and the references therein, a series of results are overviewed, where one is interested in the complexity of solving CSP(Γ) when the constraint language Γ fulfils a series of structural and algebraic properties. Finally, in a breakthrough result, a complete characterisation of the type of constraints (i.e., the constraint languages) for which the corresponding CSPs are solvable in polynomial time was given in [70] (see also [16, 69]). Theorem B.1 ([70]). For any constraint language Γ over a finite domain 𝑇 , if Pol(Γ) contains a WNU, then Γ is tractable. Otherwise, CSP(Γ) is NP-complete. In particular, the next proposition follows now immediately. Proposition B.2 (Proposition 6.37 from [18], originally from [36]). For any constraint language Γ over a finite domain 𝑇 , if Pol(Γ) contains a semilattice operation, then Γ is tractable. Indeed, semilattice operations are particular WNUs. Interestingly (see [10, 18]), the tractability of Γ, under the conditions of Proposition B.2 and moreover assuming that there is a constant upper bound on the arity of the constraint relations, follows from the fact that all instances in CSP(Γ) can be solved in polynomial time by a class of concrete algorithms which implement an algorithmic technique called enforcing generalised arc consistency (these algorithms are significantly less complex compared to the general algorithm from [70], but the degree of the polynomial describing their , Vol. 1, No. 1, Article . Publication date: June 2026.

Tractable Gap-Constraint Languages for Complex Event Recognition

23

runtime depends on the aforementioned arity-bound). In particular, we recall the algorithms AC4 (defined in [68], as a more efficient implementation of AC3 [48]), AC2001/3.1 or GAC2001/3.1 [11], which solve a normalised instance P = ⟨𝑉 , 𝐾,𝑇 ⟩, which only contains unary or binary constraints, in 𝑂 (|𝐾 ||𝑇 | 2 ) time (which is also optimal [10]). Further, there are quite a few interesting examples of constraint languages Γ such that Pol(Γ) contains a semilattice operation; see [18]. Relevant for our paper is that for any constraint language Γ which is a collection of min-closed (or max-closed) relations, CSP(Γ) can be solved in polynomial time. A relation is min-closed (respectively, max-closed) if min{·, ·}, the binary operation computing the minimum of its two arguments, is a polymorphism of 𝑅 (respectively, max{·, ·}, the binary operation computing the maximum of its two arguments, is a polymorphism of 𝑅). In more detail, this means that a 𝑘-ary relation 𝑅 is min-closed, if for every pair of 𝑘-tuples 𝑡, 𝑡 ′ ∈ 𝑅 we have that the 𝑘-tuple ⟨min{𝑡 [1], 𝑡 ′ [1]}, . . . , min{𝑡 [𝑘], 𝑡 ′ [𝑘]}⟩ ∈ 𝑅 (max-closed relations can also be defined analogously). Clearly, if Γ is a collection of min-closed (or max-closed) relations, then min (respectively, max) can be used as the semilattice operation from the statement of Proposition B.2, so we know from that proposition that Γ is tractable. As shown in [37], there are many relevant classes of min-closed and max-closed constraint languages. For instance, all unary constraints are min-closed, and all basic arithmetic constraints over the natural numbers in the constraint programming language CHIP [32] are min- and max-closed; such relations include, e.g., those relations that are defined by linear integer (in)equations on the set of variables. After this long introduction, let us come back to the subsequence matching with gap-constraints problem, and see how this can be formalised as a CSP-instance. Recall that we are given a query string 𝑢 ∈ Σ∗ , |𝑢 | = 𝑚, along with a set C of regular gap-constraints for 𝑢, and a document D ∈ Σ∗ , |D| = 𝑛, and we want to see whether there is a C-embedding of 𝑢 in D. We define 𝑉 = {1, . . . , 𝑚} and 𝑇 = {1, . . . , 𝑛}. The constraints 𝐾 ′ are defined as follows: • For every 𝑖 ∈ [𝑚], we define a unary constraint ⟨(𝑖), 𝑅𝑖 ⟩, where 𝑅𝑖 = {𝑎 ∈ [𝑛] | D[𝑎] = 𝑢 [𝑖]}. • For every 𝑖 ∈ [𝑚 − 1], we define a binary constraint ⟨(𝑖, 𝑖 + 1), 𝑅 (𝑖,𝑖+1) ⟩, where 𝑅 (𝑖,𝑖+1) = {(𝑎, 𝑏) ∈ [𝑛] × [𝑛] | 𝑎 < 𝑏}. • For every gap-constraint (𝑖, 𝑗, 𝐿) ∈ C, we define a binary constraint ⟨(𝑖, 𝑗), 𝑅 (𝑖,𝑗,𝐿) ⟩, where 𝑅 (𝑖,𝑗,𝐿) = {(𝑎, 𝑏) ∈ [𝑛] × [𝑛] | D[𝑎 + 1 : 𝑏 − 1] ∈ 𝐿}. ′ Let CSP𝑢,D,C = ⟨𝑉 ,𝑇 , 𝐾 ′ ⟩ be the CSP-instance defined for the instance 𝑢, D, C of the subsequence matching with gap-constraints problem. It is immediate that this CSP-instance has a solution if and only if there exists a C-embedding of 𝑢 in D. Note that, while having only unary and binary constraints, this CSP-instance is not necessarily normalised (as there can be multiple constraints for the same pair of variables). Fortunately, it can be shown that in 𝑂 (∥C∥|D| 2 ) time we can construct ′ CSP𝑢,D,C = ⟨𝑉 ,𝑇 , 𝐾 ′ ⟩ and then turn it into an equivalent normalised CSP-instance by efficiently intersecting the constraints having the same scope (the same proof obviously works for Lemma 3.2):

Lemma B.3 (Lemma 3.2, restated in the more general setting). Given 𝑢, D, and C, we can construct ′ in 𝑂 (∥C∥|D| 2 ) time the CSP-instance CSP𝑢,D,C = ⟨𝑉 ,𝑇 , 𝐾 ′ ⟩. In the same time complexity, we can construct CSP𝑢,D,C = ⟨𝑉 ,𝑇 , 𝐾⟩, a normalised CSP-instance with 𝑂 (|𝑢 | + |C|) constraints, which has a solution if and only if there exists a C-embedding of 𝑢 in D. Proof. Let 𝑛 = |D| and 𝑚 = |𝑢 |. To show the first part of our claim, let us recall our assumption that each regular language 𝐿 appearing in C is given as an 𝜀NFA. Thus, for each constraint (𝑖, 𝑗, 𝐿) ∈ C and each position 𝑎 of D, we run (in the standard way, sometimes called state-set simulation) the 𝜀NFA accepting 𝐿 with the suffix D[𝑎 : 𝑛] of D as input string: we start in the initial state of the respective 𝜀NFA, and maintain the set of reached states after the substring D[𝑎 : 𝑏] was processed. Whenever we reach a position 𝑏 such that the maintained state-set contains a final , Vol. 1, No. 1, Article . Publication date: June 2026.

24

Antoine Amarilli, Florin Manea, Tina Ringleb, and Markus L. Schmid

′ state, we add (𝑎 − 1, 𝑏 + 1) to the set 𝑅 (𝑖,𝑗,𝐿) (defined above when CSP𝑢,D,C was introduced); for simplicity, the sets 𝑅 (𝑖,𝑗,𝐿) are implemented as lists. This whole process (executed for all constraints and all suffixes of D) correctly constructs all binary constraints ⟨(𝑖, 𝑗), 𝑅 (𝑖,𝑗,𝐿) ⟩ from the set 𝐾 ′ of constraints. For a fixed position of D and a fixed constraint (𝑖, 𝑗, 𝐿) ∈ C this process described above takes 𝑂 (𝑛 · 𝑠𝐿 ) time, where 𝑠𝐿 is the total size of the 𝜀NFA accepting 𝐿. Thus, the processing done for a fixed constraint and all positions of D takes 𝑂 (𝑛 2𝑠𝐿 ) time in total. Consequently, the time needed to process all constraints is 𝑂 (𝑛 2 ∥C∥) = 𝑂 (∥C∥|D| 2 ). The other constraints can be trivially constructed in 𝑂 (𝑛𝑚) time. As 𝑛 ≥ 𝑚, the total time ′ needed to construct CSP𝑢,D,C = ⟨𝑉 ,𝑇 , 𝐾 ′ ⟩ is 𝑂 (∥C∥|D| 2 ). The total number of constraints in this CSP-instance is 𝑂 (|𝑢 | + |C|). In the next step, we normalise this CSP-instance. For each pair (𝑖, 𝑗) ∈ [𝑚] × [𝑚] such that ′ CSP𝑢,D,C = ⟨𝑉 ,𝑇 , 𝐾 ′ ⟩ has at least one constraint ⟨(𝑖, 𝑗), 𝑅 (𝑖,𝑗,𝐿) ⟩, we proceed as follows. Let ⟨(𝑖, 𝑗), 𝑋 1 ⟩, . . . , ⟨(𝑖, 𝑗), 𝑋𝑝 ⟩ be all constraints involving that pair (𝑖, 𝑗) (note that an 𝑋 ℓ can have the form 𝑅 (𝑖,𝑗,𝐿) or the form 𝑅 (𝑖,𝑗 ) in the case where 𝑗 = 𝑖 + 1). We define an 𝑛 × 𝑛 matrix 𝑀, whose elements are initialised with 0; then, we traverse the lists 𝑋𝑐 , with 𝑐 ∈ [𝑝], and each time we meet a pair (𝑎, 𝑏) we increase 𝑀 [𝑎, 𝑏] by 1. In the end, we produce the list 𝑅b(𝑖,𝑗 ) of all pairs (𝑎, 𝑏) such that 𝑀 [𝑎, 𝑏] = 𝑝, and define the new constraint ⟨(𝑖, 𝑗), 𝑅b(𝑖,𝑗 ) ⟩ as the single constraint involving the pair (𝑖, 𝑗). This process is equivalent to intersecting the lists 𝑋 1, . . . , 𝑋𝑝 , and takes ′ 𝑂 (𝑝 · 𝑛 2 ) time. So, running it on all constraints from CSP𝑢,D,C = ⟨𝑉 ,𝑇 , 𝐾 ′ ⟩ produces a normalised ′ CSP-instance, equivalent to CSP𝑢,D,C , in time 𝑂 (|C|𝑛 2 ). The total number of constraints in this instance is still 𝑂 (|𝑢| + |C|). The conclusion now follows immediately. □

Now, if CSP𝑢,D,C is an instance of CSP(Γ) for some constraint language Γ over 𝑇 such that Pol(Γ) contains a WNU, then CSP𝑢,D,C can be solved in polynomial time. If Pol(Γ) contains a semilattice operation, then CSP𝑢,D,C can be solved, by algorithms such as AC4, which enforce arc consistency, in 𝑂 ((|𝑢 | + |C|)|D| 2 ) time. In particular, this holds for the case when the constraints of CSP𝑢,D,C are min-closed. We directly get the following result. Theorem 3.3. Given 𝑢, D, and C, let CSP𝑢,D,C = ⟨𝑉 ,𝑇 , 𝐾⟩ be constructed as in Lemma 3.2. Assuming that the set of constraints 𝐾 is min-closed, then we can decide whether there exists a C-embedding of 𝑢 in D in time 𝑂 (|D| 2 (|𝑢 | + ∥C∥)) (which includes the construction of CSP𝑢,D,C ). This CSP-centred approach is interesting as it seems to provide the right level of abstraction for the fundamental understanding of the subsequence matching with gap-constraints problem. Due to the very particular type of the domain and of the constraints involved in the definition of CSP𝑢,D,C , the general results regarding CSP do not immediately provide a dichotomy regarding the tractability of this problem; however, they suggest that there is some hope in reaching such a result based on insights inherited from the general theory. Looking a bit closer at Theorem 3.3, we also notice a downside. Our theorem assumes that the constraints of CSP𝑢,D,C are min-closed. But, in fact, we can also check this property, in a straightforward manner, in polynomial time (once 𝑇 is determined by D). However, this does not fit our approach to (and motivation of) the subsequence matching problem: it would mean that if the constraints of CSP𝑢,D,C are not min-closed, then this algorithm would not work, and this situation is only detected after the CSP is constructed. So, in the following we focus on identifying classes of regular languages which, when used as gap-constraints, guarantee that 𝐾 is always min-closed (respectively, max-closed), irrespective of the document D. To this end, recall the definition of left-convex languages from Section 1 (Definition 1.2): a language 𝐿 is left-convex if 𝑢𝑣𝑤 ∈ 𝐿 and 𝑣 ∈ 𝐿 implies 𝑢𝑣 ∈ 𝐿. Let LCON be the class of left-convex , Vol. 1, No. 1, Article . Publication date: June 2026.

Tractable Gap-Constraint Languages for Complex Event Recognition

25

languages. We can immediately see that if all (𝑖, 𝑗, 𝐿) ∈ C satisfy 𝐿 ∈ LCON, then all constraints of CSP𝑢,D,C are min-closed. Lemma 3.4. If 𝐿 ∈ LCON for all (𝑖, 𝑗, 𝐿) ∈ C, then all constraints of CSP𝑢,D,C are min-closed. Proof. The statement holds for the unary constraints by definition. For a constraint ⟨(𝑖, 𝑗), 𝑅⟩ of CSP𝑢,D,C , we have, on the one hand, that 𝑅 contains only pairs (𝑎, 𝑏) with 𝑎 < 𝑏 and, on the other hand, that there exist left-convex languages 𝐻 1, . . . , 𝐻𝑝 such that (𝑖, 𝑗, 𝐻𝑐 ) ∈ C for all 𝑐 ∈ [𝑝], and for each pair (𝑎, 𝑏) ∈ 𝑅 we have that D[𝑎 + 1 : 𝑏 − 1] ∈ 𝐿 = ∩𝑐 ∈ [𝑝 ] 𝐻𝑐 . As the class of left-convex languages is closed under intersection, 𝐿 is left-convex. (In particular, in the case where 𝑗 = 𝑖 + 1 it may be the case that the constraint ⟨(𝑖, 𝑗), 𝑅⟩ only arises from a constraint of the form 𝑅 (𝑖,𝑖+1) and there might be no gap-constraint (𝑖, 𝑗, 𝐻𝑐 ) ∈ C. In this case, we have 𝑝 = 0 and 𝐿 = Σ∗ , which is left-convex.) Now, if (𝑎, 𝑏), (𝑐, 𝑑) ∈ 𝑅, the situation is as follows. If the intervals (𝑎, 𝑏) and (𝑐, 𝑑) are completely disjoint or they properly overlap (i.e., 𝑎 ≤ 𝑐 ≤ 𝑏 ≤ 𝑑 or 𝑐 ≤ 𝑎 ≤ 𝑑 ≤ 𝑏), then (min{𝑎, 𝑐}, min{𝑏, 𝑑 }) ∈ {(𝑎, 𝑏), (𝑐, 𝑑)}. If, on the other hand, 𝑎 ≤ 𝑐 < 𝑑 ≤ 𝑏 (the case 𝑐 ≤ 𝑎 < 𝑏 ≤ 𝑑 is analogous), then, setting 𝑢 = D[𝑎 + 1 : 𝑐], 𝑣 = D[𝑐 + 1 : 𝑑 − 1] and 𝑤 = D[𝑑 : 𝑏 − 1], we have that 𝑢𝑣𝑤 ∈ 𝐿 and 𝑣 ∈ 𝐿. Thus, due to the left-convexity of 𝐿, 𝑢𝑣 ∈ 𝐿 and 𝑢𝑣 = D[𝑎 + 1 : 𝑑 − 1] = D[min{𝑎, 𝑐} + 1 : min{𝑏, 𝑑 } − 1]. □ Similarly, if 𝐿 is right-convex, then all constraints of CSP𝑢,D,C , the CSP-instance produced in Lemma 3.2, are max-closed. So, the result of Theorem 3.3 holds for the case when all gap-constraints in C are left-convex (respectively, right-convex). As mentioned in the introduction, the matching problem is NP-complete in general, and we have just shown that requiring left-convexity (or right-convexity) for the regular gap-constraint languages is sufficient for tractability. Interestingly, Appendix A exhibits a plethora of left-convex languages which cover important practically relevant cases for the subsequence matching with gapconstraints problem, especially length-constrained languages. Also, Section 6 shows that even slight deviations from the left-convex setting lead to intractability, thus suggesting that left-convexity (and right-convexity) might be a good property to consider in trying to show a dichotomy regarding the tractability of CSP𝑢,D,C . C

Full Details for Section 4

C.1 Full Proof of Lemma 4.3 Lemma 4.3. On input 𝑢 ∈ Σ∗ , C (where C only contains left-convex gap-constraints), D ∈ Σ∗ and 𝑒 0 : [|𝑢 |] → [|D|], Algorithm 1 returns an 𝑒 0 -minimal C-embedding of 𝑢 in D if it exists, and ⊥ otherwise. Proof. For every 𝑒 : [|𝑢 |] → [|D|], we define the following invariant. Invariant (†)𝑒 : If there exists a C-embedding 𝑒 ∗ of 𝑢 in D with 𝑒 0 ≤ 𝑒 ∗ , then 𝑒 ≤ 𝑒 ∗ (where 𝑒 is the current mapping of the algorithm). Let us first observe that before the first iteration, we have that 𝑒 = 𝑒 0 ; thus, if there exists a C-embedding 𝑒 ∗ of 𝑢 in D with 𝑒 0 ≤ 𝑒 ∗ , then 𝑒 ≤ 𝑒 ∗ is trivially true. This shows that (†)𝑒 is satisfied before the first iteration. Let us now assume that (†)𝑒 is satisfied before an iteration of the while-loop. We will consider the if-statements of Lines 5, 7, and 10 separately. Line 5: If the condition is satisfied, then we have that 𝑢 [𝑠] ≠ D[𝑒 (𝑠)] and we will change 𝑒 into 𝑒 ′ with 𝑒 ′ (𝑖) = 𝑒 (𝑖) for every 𝑖 ∈ [|𝑢 |] \ {𝑠} and 𝑒 ′ (𝑠) = 𝑒 (𝑠) + 1. Since (†)𝑒 is satisfied, we know that any C-embedding 𝑒 ∗ of 𝑢 in D with 𝑒 0 ≤ 𝑒 ∗ satisfies 𝑒 ≤ 𝑒 ∗ . But since 𝑢 [𝑠] ≠ D[𝑒 (𝑠)], we also know , Vol. 1, No. 1, Article . Publication date: June 2026.

26

Antoine Amarilli, Florin Manea, Tina Ringleb, and Markus L. Schmid

that 𝑒 ∗ (𝑠) ≠ 𝑒 (𝑠), which means that 𝑒 ′ (𝑠) = 𝑒 (𝑠) + 1 ≤ 𝑒 ∗ (𝑠). Consequently, any C-embedding 𝑒 ∗ of 𝑢 in D with 𝑒 0 ≤ 𝑒 ∗ satisfies 𝑒 ′ ≤ 𝑒 ∗ , which means that (†)𝑒 ′ is satisfied. Line 7: If the condition is satisfied, then we have that 𝑠 < |𝑢 | and 𝑒 (𝑠) ≥ 𝑒 (𝑠 + 1). Moreover, we will change 𝑒 into 𝑒 ′ with 𝑒 ′ (𝑖) = 𝑒 (𝑖) for every 𝑖 ∈ [|𝑢 |] \ {𝑠 + 1} and 𝑒 ′ (𝑠 + 1) = 𝑒 (𝑠) + 1. Since (†)𝑒 is satisfied, we know that any C-embedding 𝑒 ∗ of 𝑢 in D with 𝑒 0 ≤ 𝑒 ∗ satisfies 𝑒 ≤ 𝑒 ∗ . But since 𝑒 ∗ is an embedding of 𝑢 in D, we know that 𝑒 ∗ (𝑠) + 1 ≤ 𝑒 ∗ (𝑠 + 1), which means that 𝑒 ′ (𝑠 + 1) = 𝑒 (𝑠) + 1 ≤ 𝑒 ∗ (𝑠) + 1 ≤ 𝑒 ∗ (𝑠 + 1). Consequently, any C-embedding 𝑒 ∗ of 𝑢 in D with 𝑒 0 ≤ 𝑒 ∗ satisfies 𝑒 ′ ≤ 𝑒 ∗ , which means that (†)𝑒 ′ is satisfied. Line 10: If the condition is satisfied for some (𝑖, 𝑗, 𝐿) ∈ C with 𝑠 ∈ {𝑖, 𝑗 }, then we have that D[𝑒 (𝑖) +1 : 𝑒 ( 𝑗)−1] ∉ 𝐿. There are two cases: (1.) either 𝑒 (𝑖) < 𝑒 ( 𝑗), in which case D[𝑒 (𝑖)+1 : 𝑒 ( 𝑗)−1] is defined (and possibly 𝜀, if 𝑒 ( 𝑗) = 𝑒 (𝑖) + 1); (2.) or 𝑒 (𝑖) ≥ 𝑒 ( 𝑗), in which case D[𝑒 (𝑖) + 1 : 𝑒 ( 𝑗) − 1] = ⊥ ∉ 𝐿 (recall that we define D[𝑝 : 𝑞] = ⊥ in the case that 𝑝 > 𝑞 + 1). We first discuss case (1.). There are two subcases, depending on whether longestRight(𝑒 (𝑖), 𝐿) > 𝑒 ( 𝑗) or not. In the first subcase, where longestRight(𝑒 (𝑖), 𝐿) > 𝑒 ( 𝑗), we change 𝑒 into 𝑒 ′ with 𝑒 ′ (𝑘) ≔ 𝑒 (𝑘) for every 𝑘 ∈ [|𝑢 |] \ { 𝑗 } and 𝑒 ′ ( 𝑗) ≔ 𝑒 ( 𝑗) + 1. In particular, we also know that D[𝑒 (𝑖) + 1 : longestRight(𝑒 (𝑖), 𝐿) − 1] ∈ 𝐿. If (†)𝑒 ′ is not satisfied, then there is some C-embedding 𝑒 ∗ of 𝑢 in D with 𝑒 0 ≤ 𝑒 ∗ , but 𝑒 ′ ≰ 𝑒 ∗ . Since (†)𝑒 is satisfied, we know that 𝑒 ≤ 𝑒 ∗ , which means that 𝑒 ( 𝑗) = 𝑒 ∗ ( 𝑗). Since D[𝑒 (𝑖) + 1 : 𝑒 ( 𝑗) − 1] ∉ 𝐿, we also know that 𝑒 ′ (𝑖) = 𝑒 (𝑖) < 𝑒 ∗ (𝑖). Let us now consider the string 𝑢𝑣𝑤 with 𝑢 = D[𝑒 (𝑖) + 1 : 𝑒 ∗ (𝑖)], 𝑣 = D[𝑒 ∗ (𝑖) + 1 : 𝑒 ∗ ( 𝑗) − 1] and 𝑤 = D[𝑒 ∗ ( 𝑗) : longestRight(𝑒 (𝑖), 𝐿) − 1]. As observed above, 𝑢𝑣𝑤 ∈ 𝐿, and since 𝑒 ∗ is a C-embedding of 𝑢 in D, we also know that 𝑣 ∈ 𝐿, which, by the left-convexity of 𝐿, implies that 𝑢𝑣 = D[𝑒 (𝑖) + 1 : 𝑒 ( 𝑗) − 1] ∈ 𝐿; a contradiction. In the second subcase, where longestRight(𝑒 (𝑖), 𝐿) ≤ 𝑒 ( 𝑗), we change 𝑒 into 𝑒 ′ with 𝑒 ′ (𝑘) ≔ 𝑒 (𝑘) for every 𝑘 ∈ [|𝑢 |] \ {𝑖} and 𝑒 ′ (𝑖) ≔ 𝑒 (𝑖) + 1. If (†)𝑒 ′ is not satisfied, then there is some C-embedding 𝑒 ∗ of 𝑢 in D with 𝑒 0 ≤ 𝑒 ∗ , but 𝑒 ′ ≰ 𝑒 ∗ . Since (†)𝑒 is satisfied, we know that 𝑒 ≤ 𝑒 ∗ , which means that 𝑒 (𝑖) = 𝑒 ∗ (𝑖). Since D[𝑒 (𝑖) + 1 : 𝑒 ( 𝑗) − 1] ∉ 𝐿, we also know that 𝑒 ′ ( 𝑗) = 𝑒 ( 𝑗) < 𝑒 ∗ ( 𝑗), which means that longestRight(𝑒 (𝑖), 𝐿) > 𝑒 ( 𝑗); a contradiction. Let us now discuss case (2.), where 𝑒 (𝑖) ≥ 𝑒 ( 𝑗). Again there are two subcases, depending on whether longestRight(𝑒 (𝑖), 𝐿) > 𝑒 ( 𝑗) or not. In the first subcase, where longestRight(𝑒 (𝑖), 𝐿) > 𝑒 ( 𝑗), the algorithm changes 𝑒 into 𝑒 ′ in the same way as for case (1.) (i.e., by shifting 𝑒 ( 𝑗) by one position) and, just like discussed above, we can conclude that if (†)𝑒 ′ is not satisfied, then there is some C-embedding 𝑒 ∗ of 𝑢 in D with 𝑒 0 ≤ 𝑒 ∗ and 𝑒 ′ ≰ 𝑒 ∗ , which means that 𝑒 ( 𝑗) = 𝑒 ∗ ( 𝑗) and 𝑒 ′ (𝑖) = 𝑒 (𝑖) < 𝑒 ∗ (𝑖). Hence, 𝑒 ∗ (𝑖) > 𝑒 ∗ ( 𝑗) and therefore D[𝑒 ∗ (𝑖) + 1 : 𝑒 ∗ ( 𝑗) − 1] = ⊥ ∉ 𝐿, which is a contradiction. In the second subcase, where longestRight(𝑒 (𝑖), 𝐿) ≤ 𝑒 ( 𝑗), the algorithm changes 𝑒 into 𝑒 ′ by shifting 𝑒 (𝑖) by one position. As in case (1.), if (†)𝑒 ′ is not satisfied, then there is some C-embedding 𝑒 ∗ of 𝑢 in D with 𝑒 (𝑖) = 𝑒 ∗ (𝑖) and 𝑒 ′ ( 𝑗) = 𝑒 ( 𝑗) < 𝑒 ∗ ( 𝑗). If 𝑒 ∗ (𝑖) < 𝑒 ∗ ( 𝑗), then longestRight(𝑒 ∗ (𝑖), 𝐿) ≥ 𝑒 ∗ ( 𝑗), which, since 𝑒 (𝑖) = 𝑒 ∗ (𝑖) and 𝑒 ( 𝑗) < 𝑒 ∗ ( 𝑗), means that longestRight(𝑒 (𝑖), 𝐿) > 𝑒 ( 𝑗) — a contradiction. If 𝑒 ∗ (𝑖) ≥ 𝑒 ∗ ( 𝑗), then D[𝑒 ∗ (𝑖) + 1 : 𝑒 ∗ ( 𝑗) − 1] = ⊥, which contradicts D[𝑒 ∗ (𝑖) + 1 : 𝑒 ∗ ( 𝑗) − 1] ∈ 𝐿. This shows that (†)𝑒 holds before every iteration of the while-loop. For the next part, we need the following terminology. We say that 𝑠 ∈ [|𝑢 |] satisfies the symbol condition with respect to 𝑒 if 𝑢 [𝑠] = D[𝑒 (𝑠)], 𝑠 ∈ [|𝑢 | − 1] satisfies the order condition with respect to 𝑒 if 𝑒 (𝑠) < 𝑒 (𝑠 + 1), and 𝑠, 𝑠 ′ ∈ [|𝑢 |] satisfy the gap condition with respect to 𝑒 if (𝑖, 𝑗, 𝐿) ∈ C with {𝑖, 𝑗 } = {𝑠, 𝑠 ′ } implies D[𝑒 (𝑖) + 1 : 𝑒 ( 𝑗) − 1] ∈ 𝐿. Obviously, if all 𝑠 ∈ [|𝑢 |] satisfy the symbol condition and the order condition with respect to 𝑒, and all 𝑠, 𝑠 ′ ∈ [|𝑢 |] satisfy the gap condition with respect to 𝑒, then 𝑒 is a C-embedding of 𝑢 in D. Next, for every 𝑒 : [|𝑢 |] → [|D|] and 𝑆 ⊆ [|𝑢 |], we define another invariant. , Vol. 1, No. 1, Article . Publication date: June 2026.

Tractable Gap-Constraint Languages for Complex Event Recognition

27

Invariant (‡)𝑒,𝑆 : Each 𝑠 ∈ [|𝑢 |] \ 𝑆 satisfies the symbol condition and the order condition with respect to 𝑒, and all 𝑠, 𝑠 ′ ∈ [|𝑢 |] \ 𝑆 satisfy the gap condition with respect to 𝑒. Obviously, (‡)𝑒,𝑆 is satisfied at the beginning of the algorithm, since 𝑆 = [|𝑢 |]. Claim C.1. Let 𝑒 : [|𝑢 |] → [|D|] and let 𝑆 ⊆ [|𝑢 |] such that (‡)𝑒,𝑆 is satisfied. For some 𝑠 ∈ [|𝑢 |], let 𝑒 ′ : [|𝑢 |] → [|D|] be such that 𝑒 ′ (𝑖) = 𝑒 (𝑖) for every 𝑖 ∈ [|𝑢 |] \ {𝑠} and 𝑒 ′ (𝑠) > 𝑒 (𝑠), and let 𝑆 ′ = 𝑆 ∪ {𝑠}. Then (‡)𝑒 ′ ,𝑆 ′ is satisfied. Proof. We first show that every 𝑠 ′ ∈ [|𝑢 |] \ 𝑆 ′ satisfies the symbol condition and order condition with respect to 𝑒 ′ . Note that 𝑠 ′ ∉ 𝑆 ′ implies that 𝑠 ′ ∉ 𝑆, which, due to (‡)𝑒,𝑆 , means that the symbol and order conditions for 𝑠 ′ are satisfied with respect to 𝑒. Since 𝑠 ′ ≠ 𝑠, we know that 𝑒 ′ (𝑠 ′ ) = 𝑒 (𝑠 ′ ); thus, the symbol condition for 𝑠 ′ is satisfied with respect to 𝑒 ′ . We further note that 𝑒 ′ is obtained from 𝑒 by only moving symbol 𝑠 ≠ 𝑠 ′ to the right, which means that 𝑒 ′ (𝑠 ′ ) = 𝑒 (𝑠 ′ ) is also sufficient to conclude that the order condition for 𝑠 ′ is satisfied with respect to 𝑒 ′ . Let us now consider some 𝑠 1, 𝑠 2 ∈ [|𝑢 |] \ 𝑆 ′ , and some arbitrary gap-constraint (𝑖, 𝑗, 𝐿) ∈ C with {𝑖, 𝑗 } = {𝑠 1, 𝑠 2 } (if no such gap-constraint exists, then, by definition, 𝑠 1, 𝑠 2 satisfy the gap condition with respect to 𝑒 ′ ). By definition, 𝑖, 𝑗 ∉ 𝑆 ′ implies that 𝑖, 𝑗 ∉ 𝑆, which, due to (‡)𝑒,𝑆 , means that 𝑖, 𝑗 satisfy the gap condition with respect to 𝑒. Since 𝑠 ∈ 𝑆 ′ , we also know that 𝑠 ∉ {𝑖, 𝑗 }, which means that 𝑒 ′ (𝑖) = 𝑒 (𝑖) and 𝑒 ′ ( 𝑗) = 𝑒 ( 𝑗); thus, 𝑖, 𝑗 satisfy the gap condition with respect to 𝑒 ′ . Consequently, (‡)𝑒 ′ ,𝑆 ′ is satisfied. □ Note that Claim C.1 also covers the case where 𝑠 ∈ 𝑆. We can now use Claim C.1 to show that the invariant (‡)𝑒,𝑆 is maintained by any iteration of the while-loop. Let us assume that (‡)𝑒,𝑆 holds before an iteration of the while-loop. Since the iteration may repeatedly change 𝑆, let us consistently use 𝑆b to denote the current version of that set, i.e., the original set 𝑆 with elements removed and added as done by the iteration up to the point that we currently consider in our argument. Analogously, we denote by b 𝑒 the current mapping. In order to prove that (‡)𝑒b,𝑆b holds after the iteration, we proceed in two steps: We will first show that (‡)𝑒b,𝑆∪{𝑠 b } holds after the iteration (for which we use Claim C.1), and then we show that (‡)𝑒b,𝑆b holds. Let us first observe that (‡) b trivially holds before the iteration since 𝑆b = 𝑆b ∪ {𝑠}, and let 𝑒b,𝑆∪{𝑠 }

us next argue that (‡)𝑒b,𝑆∪{𝑠 b } is maintained by the iteration. Indeed, if we perform any of the code inside one of the if-statements of Lines 5, 7, and 10, then we will change b 𝑒 by only moving a single position 𝑠 ′ to the right and adding 𝑠 ′ to the current set 𝑆b and therefore to 𝑆b∪ {𝑠} (note that 𝑠 ′ might already be in 𝑆b∪ {𝑠}). With Claim C.1, this directly implies that (‡)𝑒b,𝑆∪{𝑠 b } is maintained by all these if-statements and therefore (‡)𝑒b,𝑆∪{𝑠 b } is satisfied after the iteration. Next, let us see that in fact (‡) b must be satisfied. If we have 𝑠 ∈ 𝑆b after the iteration, then 𝑒b,𝑆

b (‡)𝑒b,𝑆∪{𝑠 b } = (‡)𝑒b,𝑆b and we are done. Hence, let us consider the remaining case where 𝑠 ∉ 𝑆, which particularly means that 𝑒 (𝑠) is not moved by any modification of b 𝑒 in the iteration. In this case, we can conclude that 𝑠 satisfies the symbol condition with respect to b 𝑒 due to the fact that we did b Similarly, 𝑠 must satisfy not carry out the if-statement of Line 5, which would have added 𝑠 to 𝑆. the order condition with respect to b 𝑒 due to the if-statement of Line 7 (if this if-statement has not been carried out, then the order condition was already satisfied, and if it has been carried out, then moving 𝑒 (𝑠 +1) to 𝑒 (𝑠) +1 makes the order condition satisfied). Finally, let us consider some arbitrary b If 𝑠 ∉ {𝑖, 𝑗 }, then 𝑖, 𝑗 satisfy the gap condition with respect to b 𝑖, 𝑗 ∈ [|𝑢 |] \ 𝑆. 𝑒 due to (‡)𝑒b,𝑆∪{𝑠 b } . If, on the other hand, 𝑠 ∈ {𝑖, 𝑗 } and there is some (𝑖, 𝑗, 𝐿) ∈ C, then D[𝑒 (𝑖) + 1 : 𝑒 ( 𝑗) − 1] ∈ 𝐿 due to the if-statements of Line 10 in the foreach-loop. Indeed, since neither 𝑖 nor 𝑗 are in 𝑆b after the iteration, neither 𝑖 nor 𝑗 could have been added to 𝑆b when this instance of Line 10 was executed, , Vol. 1, No. 1, Article . Publication date: June 2026.

28

Antoine Amarilli, Florin Manea, Tina Ringleb, and Markus L. Schmid

which means that D[𝑒 (𝑖) + 1 : 𝑒 ( 𝑗) − 1] ∈ 𝐿 must have been satisfied. Moreover, neither 𝑒 (𝑖) nor 𝑒 ( 𝑗) are changed in the remainder of the iteration, since neither 𝑖 nor 𝑗 are in 𝑆b after the iteration. Hence, 𝑖, 𝑗 satisfy the gap condition with respect to b 𝑒 . Therefore, we can conclude that (‡)𝑒b,𝑆b holds. It can be easily seen that our algorithm always terminates: In every iteration of the while-loop, we remove a position from 𝑆 without adding a new one to it, or we move at least one position at least one step to the right. This means that at some point either 𝑆 becomes empty or it contains some 𝑠 with 𝑒 (𝑠) > |D|. In both cases our algorithm terminates. As proven above, before the last iteration of the while-loop, both (†)𝑒 and (‡)𝑒,𝑆 are satisfied. In the last iteration, we either turn 𝑆 = {𝑠} into 𝑆 = ∅ and return 𝑒 in Line 13, or we return ⊥ due to Line 4. In the first case, the conditions of Lines 5 and 7 are not satisfied and we find no gap-constraint such that the condition in Line 10 is satisfied. As a result, 𝑒 is not changed, and 𝑠 satisfies the symbol condition and the order condition with respect to 𝑒, and, due to (‡)𝑒,𝑆 , all other positions 𝑠 ′ ∈ [|𝑢 |] \ {𝑠} also satisfy the symbol condition and the order condition with respect to 𝑒. Now for every 𝑖, 𝑗 ∈ [|𝑢 |] with a gap-constraint (𝑖, 𝑗, 𝐿) ∈ C, if 𝑠 ∉ {𝑖, 𝑗 }, then D[𝑒 (𝑖) + 1 : 𝑒 ( 𝑗) − 1] ∈ 𝐿 is implied by (‡)𝑒,𝑆 , and if 𝑠 ∈ {𝑖, 𝑗 }, then D[𝑒 (𝑖) + 1 : 𝑒 ( 𝑗) − 1] ∈ 𝐿 is implied by the fact that in this last iteration, we did not find a gap-constraint such that the condition in Line 10 is satisfied. Consequently, all 𝑖 ∈ [|𝑢 |] satisfy the symbol condition and the order condition with respect to 𝑒, and all 𝑖, 𝑗 ∈ [|𝑢 |] satisfy the gap condition with respect to 𝑒, which means that 𝑒 is a C-embedding of 𝑢 in D. Moreover, (†)𝑒 implies that if there exists a C-embedding 𝑒 ∗ of 𝑢 in D with 𝑒 0 ≤ 𝑒 ∗ , then 𝑒 ≤ 𝑒 ∗ , which means that 𝑒 is 𝑒 0 -minimal. On the other hand, if we return ⊥ in the last iteration, then this means that 𝑒 (𝑠) > |D|. Due to (†)𝑒 , we know that if there exists a C-embedding 𝑒 ∗ of 𝑢 in D with 𝑒 0 ≤ 𝑒 ∗ , then 𝑒 ≤ 𝑒 ∗ , which would mean that 𝑒 ∗ (𝑠) > |D|; a contradiction. Hence, if we return ⊥, then there is no C-embedding 𝑒 ∗ of 𝑢 in D. □ C.2

Full Proof of Lemma 4.4

Lemma 4.4. Under the assumption that we can check the conditions of Lines 10 and 11 in constant time, Algorithm 1 terminates after time 𝑂 (|D|(|𝑢 | + |C|)). Proof. We say that an iteration of the while-loop is an 𝑠-iteration if 𝑠 is the position removed from 𝑆 in Line 3 at the beginning of the loop. Each single 𝑠 ∈ [|𝑢 |] can cause only 𝑂 (|D|) 𝑠-iterations, since when it is added to 𝑆 it is also moved by at least one position, and if it is removed from 𝑆, it has to be moved first in order to be added again to 𝑆. Moreover, everything except the foreach-loop of an 𝑠-iteration is executed in constant time. Consequently, over the whole course of the algorithm, executing Lines 3 to 8 of all iterations of the while-loop requires time 𝑂 (|D| · |𝑢 |). Let us next estimate the total time needed for executing the foreach-loop of all iterations of the while-loop. For every 𝑠 ∈ [|𝑢 |], let 𝑘𝑠 be the number of gap-constraints (𝑖, 𝑗, 𝐿) with 𝑠 ∈ {𝑖, 𝑗 }. Obviously, Í |𝑢 | 𝑖=1 𝑘𝑖 = 2|C|. In every 𝑠-iteration there are at most 𝑘𝑠 iterations of the foreach-loop, assuming that we have precomputed for each 𝑠 ∈ [|𝑢 |] a list of the 𝑘𝑠 constraints in which 𝑠 occurs: this preprocessing takes 𝑂 (|𝑢 | + |C|) time and therefore has no effect on the overall complexity. Thus, we need time 𝑂 (|D|𝑘𝑠 ) for all the foreach-loops inside of 𝑠-iterations, using our assumption that theÍconditions of Lines 10Íand 11 can be checked in constant time. This means that we need time |𝑢 | |𝑢 | 𝑂 ( 𝑖=1 |D| · 𝑘𝑖 ) = 𝑂 (|D| 𝑖=1 𝑘𝑖 ) = 𝑂 (|D| · |C|) for all the foreach-loops in total. Consequently, the total time is 𝑂 (|D| · |𝑢 | + |D| · |C|) = 𝑂 (|D|(|𝑢 | + |C|)). □ C.3

Full Proof of Lemma 4.6

Lemma 4.6. We can compute the arrays LR and SL in time 𝑂 (|D| · ∥C∥). , Vol. 1, No. 1, Article . Publication date: June 2026.

Tractable Gap-Constraint Languages for Complex Event Recognition

29

Proof. Let us first recall the definition of longestRight(𝑘, 𝐿) = max{𝑡 ∈ [𝑘 + 1, |D|] | D[𝑘 + 1 : 𝑡 − 1] ∈ 𝐿} and shortestLeft(𝑘, 𝐿) = max{𝑡 ∈ [𝑘 − 1] | D[𝑡 + 1 : 𝑘 − 1] ∈ 𝐿}, with the value being 0 if such a factor does not exist. Intuitively speaking, if longestRight(𝑘, 𝐿) = 𝑡, then D[𝑘 +1 : 𝑡 −1] is the longest substring of D starting at position 𝑘 + 1 that is contained in 𝐿, and if shortestLeft(𝑘, 𝐿) = 𝑡, then D[𝑡 + 1 : 𝑘 − 1] is the shortest substring of D ending at position 𝑘 − 1 that is contained in 𝐿. The arrays LR and SL are the data structures that contain the values given by longestRight and shortestLeft, i.e., LR[𝑘] [𝐿] = longestRight(𝑘, 𝐿) and SL[𝑘] [𝐿] = shortestLeft(𝑘, 𝐿). In the following, given an 𝜀NFA 𝑀𝐿 = (𝑄, Σ, 𝑞 0, 𝐹, 𝛿) accepting the gap-constraint language 𝐿, we will build a product graph 𝐺 𝐿 = (𝑉 , 𝐸) with nodes (𝑘, 𝑞) for 𝑘 ∈ [|D|], 𝑞 ∈ 𝑄 such that there is a path from (𝑘, 𝑞) to (𝑘 ′, 𝑞 ′ ) in 𝐺 𝐿 if and only if there is a path from 𝑞 to 𝑞 ′ in 𝑀𝐿 that is labelled with D[𝑘 + 1 : 𝑘 ′ ] (when ignoring 𝜀-transitions). Clearly, LR[𝑘] [𝐿] = max{𝑡 ∈ [|D|] | there is a path from (𝑘, 𝑞 0 ) to (𝑡 − 1, 𝑞 𝑓 ) in 𝐺 𝐿 for some 𝑞 𝑓 ∈ 𝐹 }. Thus, we can compute LR[𝑘] [𝐿] by finding the longest (ignoring 𝜀-transitions) path from (𝑘, 𝑞 0 ), corresponding to the initial state 𝑞 0 at position 𝑘, to (𝑡 − 1, 𝑞 𝑓 ), corresponding to some final state 𝑞 𝑓 ∈ 𝐹 at position 𝑡 − 1: This path from (𝑘, 𝑞 0 ) to (𝑡 − 1, 𝑞 𝑓 ) in 𝐺 𝐿 corresponds to an accepting run in 𝑀𝐿 and is labelled with D[𝑘 + 1 : 𝑡 − 1]. Similarly, SL[𝑘] [𝐿] = max{𝑡 ∈ [|D|] | there is a path from (𝑡, 𝑞 0 ) to (𝑘 −1, 𝑞 𝑓 ) in 𝐺 𝐿 for some 𝑞 𝑓 ∈ 𝐹 } and we can compute SL[𝑘] [𝐿] by finding the shortest (when ignoring 𝜀-transitions) path from (𝑡, 𝑞 0 ) to (𝑘 − 1, 𝑞 𝑓 ), corresponding to some accepting run in 𝑀𝐿 that is labelled with D[𝑡 + 1 : 𝑘 − 1]. Before constructing 𝐺 𝐿 , we will preprocess the 𝜀NFA 𝑀𝐿 to remove cycles consisting only of 𝜀-transitions. To do this, let 𝑀𝜀 = (𝑄, Σ, 𝑞 0, 𝐹, {(𝑝, 𝜀, 𝑞) ∈ 𝛿 }) be the 𝜀NFA that we obtain from 𝑀𝐿 when only considering 𝜀-transitions. Using a depth-first search, we construct the set of strongly connected components of 𝑀𝜀 in time 𝑂 (|𝑀𝜀 |) = 𝑂 (|𝑀𝐿 |). For ease of notation, let 𝑆𝐶𝐶 [𝑞] be the strongly connected component that contains state 𝑞 ∈ 𝑄 and let 𝑆𝐶𝐶 [𝐴] = {𝑆𝐶𝐶 [𝑞] | 𝑞 ∈ 𝐴} for subset 𝐴 ⊆ 𝑄. Then, instead of 𝑀𝐿 we will from now on work with the 𝜀NFA 𝑀𝐿′ = (𝑆𝐶𝐶 [𝑄], Σ, 𝑆𝐶𝐶 [𝑞 0 ], 𝑆𝐶𝐶 [𝐹 ], 𝛿 ′ ), where 𝛿 ′ = {(𝑆𝐶𝐶 [𝑝], 𝑎, 𝑆𝐶𝐶 [𝑞]) | (𝑝, 𝑎, 𝑞) ∈ 𝛿 }. Since we collapse states 𝑝 and 𝑞 into a single strongly connected component (i.e., 𝑆𝐶𝐶 [𝑝] = 𝑆𝐶𝐶 [𝑞]) if and only if there is an 𝜀-labelled path from 𝑝 to 𝑞 and an 𝜀-labelled path from 𝑞 to 𝑝, it is easy to see that L (𝑀𝐿 ) = L (𝑀𝐿′ ) and |𝑀𝐿′ | ≤ |𝑀𝐿 |. For ease of notation, from now on we write 𝑀𝐿 = (𝑄, Σ, 𝑞 0, 𝐹, 𝛿) while meaning 𝑀𝐿′ . Now, let us construct 𝐺 𝐿 = (𝑉 , 𝐸). As explained above, every node in 𝑉 = {(𝑘, 𝑞) | 𝑘 ∈ [|D|], 𝑞 ∈ 𝑄 } consists of two components: 𝑘 ∈ [|D|] symbolises that we already consumed prefix D[1 : 𝑘] (or some suffix thereof) when reaching node (𝑘, 𝑞), while 𝑞 stores the current state of the automaton after reading the already consumed symbols. For ease of notation, we say that node (𝑘, 𝑞) has index 𝑘. We add an edge from (𝑘, 𝑞) to (𝑘, 𝑞 ′ ) if there is an 𝜀-labelled edge from 𝑞 to 𝑞 ′ in 𝑀𝐿 , and an edge from (𝑘, 𝑞) to (𝑘 + 1, 𝑞 ′ ) if there is an edge from 𝑞 to 𝑞 ′ in 𝑀𝐿 that is labelled with letter D[𝑘 + 1]. Clearly, there is a path from (𝑘, 𝑞) to (𝑘 ′, 𝑞 ′ ) for 𝑘 ′ > 𝑘 if and only if there is a D[𝑘 + 1 : 𝑘 ′ ]-labelled path (when ignoring 𝜀-transitions) from state 𝑞 to 𝑞 ′ in 𝑀𝐿 , and there is a path from (𝑘, 𝑞) to (𝑘, 𝑞 ′ ) if and only if there is an 𝜀-labelled path from 𝑞 to 𝑞 ′ in 𝑀𝐿 . Clearly, we can build 𝐺 𝐿 in 𝑂 (|D||𝑀𝐿 |) time. We can now compute LR and SL using dynamic programming. Let us first consider the procedure for LR. Since we removed all 𝜀-cycles, we can topologically sort all nodes with index 𝑘 ∈ [|D|] in time 𝑂 (|𝑀𝐿 |) (and for the whole graph thus in overall time 𝑂 (|D||𝑀𝐿 |)), to maintain the following invariant: When considering node (𝑘, 𝑞), we already computed the values of all nodes reachable from (𝑘, 𝑞). Indeed, we consider all nodes (𝑘, 𝑞) in decreasing order, such that when computing the value of node (𝑘, 𝑞), all nodes with index 𝑘 + 1 have already been considered, and such that, if 𝑞 ′ is larger than 𝑞 in the topological sorting for index 𝑘, then the value of (𝑘, 𝑞 ′ ) has been computed before the value of (𝑘, 𝑞). Now, for every (𝑘, 𝑞) we compute the value 𝑣 𝑗 (𝑘, 𝑞), which is the largest 𝑘 ′ such that there is a path from (𝑘, 𝑞) to some node (𝑘 ′, 𝑞 𝑓 ) with 𝑞 𝑓 ∈ 𝐹 , or −1 if there is no such , Vol. 1, No. 1, Article . Publication date: June 2026.

30

Antoine Amarilli, Florin Manea, Tina Ringleb, and Markus L. Schmid

𝑘 ′ . It is easy to see that ( 𝑣 𝑗 (𝑘, 𝑞) =

max({𝑣 𝑗 (𝑘 ′, 𝑞 ′ ) | ((𝑘, 𝑞), (𝑘 ′, 𝑞 ′ )) ∈ 𝐸}) max({𝑣 𝑗 (𝑘 ′, 𝑞 ′ ) | ((𝑘, 𝑞), (𝑘 ′, 𝑞 ′ )) ∈ 𝐸} ∪ {𝑘 })

if 𝑞 ∉ 𝐹, if 𝑞 ∈ 𝐹,

where max(∅) is denoted by −1. Finally, we set LR[𝑘] [𝐿] = 𝑣 𝑗 (𝑘, 𝑞 0 ) + 1. This is correct, since for 𝑡 = 𝑣 𝑗 (𝑘, 𝑞 0 ) + 1, if 𝑡 > 0 we have that D[𝑘 + 1 : 𝑡 − 1] ∈ 𝐿 and 𝑡 is the largest such value with 𝑡 ∈ [𝑘 + 1, |D|], and if 𝑡 = 0 we had 𝑣 𝑗 (𝑘, 𝑞 0 ) = −1 which witnesses that we do not have any suitable factor. A similar approach can be used for SL: we consider the nodes (𝑘, 𝑞) in increasing order according to their index 𝑘, again in decreasing order of the topological sorting of index 𝑘. For every node (𝑘, 𝑞) we compute the value 𝑣𝑖 (𝑘, 𝑞), which is the largest 𝑘 ′ such that there is a path from (𝑘 ′, 𝑞 0 ) to node (𝑘, 𝑞), or −1 if there is no such 𝑘 ′ . Now, SL[𝑘] [𝐿] = max{𝑣𝑖 (𝑘 − 1, 𝑞 𝑓 ) | 𝑞 𝑓 ∈ 𝐹 } with similar reasoning. Since there are 𝑂 (|𝑀𝐿 |) edges to be considered for every index 𝑘, this dynamic programming approach clearly takes time 𝑂 (|D||𝑀𝐿 |). □ D

Full Details for the Approach of Section 4.2

As noted in Section 4.2, when in an iteration of the while-loop the condition of Line 10 is satisfied, i.e., D[𝑒 (𝑖) + 1 : 𝑒 ( 𝑗) − 1] ∉ 𝐿, then Algorithm 1 moves either position 𝑖 or 𝑗 by only one position, i.e., either 𝑒 (𝑖) ≔ 𝑒 (𝑖) + 1 or 𝑒 ( 𝑗) ≔ 𝑒 ( 𝑗) + 1. However, we could as well set 𝑒 (𝑖) ≔ 𝑝 and 𝑒 ( 𝑗) ≔ 𝑞, where 𝑝, 𝑞 ∈ [|D|] such that 𝑒 (𝑖) ≤ 𝑝, 𝑒 ( 𝑗) ≤ 𝑞, D[𝑝 + 1 : 𝑞 − 1] ∈ 𝐿 and 𝑝, 𝑞 are minimal with this property (note that if there are any 𝑝 ′ ≥ 𝑒 (𝑖), 𝑞 ′ ≥ 𝑒 ( 𝑗) such that D[𝑝 ′ + 1 : 𝑞 ′ − 1] ∈ 𝐿, then the uniqueness of the (pointwise) minimal pair (𝑝, 𝑞) is a direct consequence of the left-convexity of 𝐿; see Lemma 4.2). Similarly, if D[𝑒 (𝑖)] ≠ 𝑢 [𝑖], then 𝑒 cannot be a C-embedding of 𝑢 in D, so when evaluating the symbol condition, it suffices to only consider positions 𝑥 > 𝑒 (𝑖) with D[𝑥] = 𝑢 [𝑖]. The correctness of this follows again from the left-convexity property, as shown below. The resulting algorithm is not asymptotically faster in the worst case. However, we expect that the algorithm could be more efficient in practice, especially for instances where D is sparse with respect to factors that match the constraint languages; indeed, shifting positions over larger chunks of D as explained above could help finding a valid embedding (or verifying that none exists) more efficiently. We can state the following result: √︁ Theorem D.1. Algorithm 2 solves the matching problem in 𝑂 (|D|(|𝑢 | log log |D|+|C| log |D|+∥C∥)) time. Proof. The result of Theorem D.1 relies on Algorithm 2. To show the correctness and complexity of this algorithm, we show the following several intermediate results. Lemma D.2. On input 𝑢 ∈ Σ∗ , C (where C only contains left-convex gap-constraints), D ∈ Σ∗ and 𝑒 0 : [|𝑢 |] → [|D|], Algorithm 2 returns an 𝑒 0 -minimal C-embedding of 𝑢 in D if it exists, and ⊥ otherwise. Proof. The general correctness of Algorithm 2 follows the correctness proof given of Lemma 4.3. We will only highlight the differences. Let us assume the invariant (†)𝑒 is satisfied for the current mapping of the algorithm. We will first show that this invariant is maintained by the modifications caused by the if-statements of Line 5 and 10. Line 5: If the condition is satisfied, then we have that 𝑢 [𝑠] ≠ D[𝑒 (𝑠)] and we will change 𝑒 into 𝑒 ′ with 𝑒 ′ (𝑖) = 𝑒 (𝑖) for every 𝑖 ∈ [|𝑢 |] \ {𝑠} and 𝑒 ′ (𝑠) = min({𝑥 ∈ [𝑒 (𝑠) +1 : |D|] | D[𝑥] = 𝑢 [𝑠]} ∪ {|D| +1}), i.e., the smallest position where letter 𝑢 [𝑠] appears in D[𝑒 (𝑠) + 1 : |D|] (or |D| + 1, if 𝑢 [𝑠] does not , Vol. 1, No. 1, Article . Publication date: June 2026.

Tractable Gap-Constraint Languages for Complex Event Recognition

31

Algorithm 2: EmbedLCONSubseq(𝑢, C, D, 𝑒 0 ) Input: 𝑢, C s.t. C only contains left-convex gap-constraints, D ∈ Σ∗ , 𝑒 0 : [|𝑢 |] → [|D|]. Output: 𝑒 0 -minimal C-embedding of 𝑢 in D if it exists, and ⊥ otherwise. 1 𝑒 ≔ 𝑒 0 ; 𝑆 ≔ {1, 2, . . . , |𝑢 |}; 2 while 𝑆 ≠ ∅ do 3 Let 𝑠 ∈ 𝑆 be arbitrarily chosen and 𝑆 ← 𝑆 \ {𝑠}; 4 if 𝑒 (𝑠) > |D| then return ⊥; 5 if 𝑢 [𝑠] ≠ D[𝑒 (𝑠)] then 6 𝑒 (𝑠) ← min({𝑥 ∈ [𝑒 (𝑠) + 1, |D|] | D[𝑥] = 𝑢 [𝑠]} ∪ {|D| + 1}); 𝑆 ← 𝑆 ∪ {𝑠}; 7 if 𝑠 < |𝑢 | and 𝑒 (𝑠) ≥ 𝑒 (𝑠 + 1) then 8 𝑒 (𝑠 + 1) ← 𝑒 (𝑠) + 1; 𝑆 ← 𝑆 ∪ {𝑠 + 1}; 9 foreach (𝑖, 𝑗, 𝐿) ∈ C with 𝑠 ∈ {𝑖, 𝑗 } do 10 if D[𝑒 (𝑖) + 1 : 𝑒 ( 𝑗) − 1] ∉ 𝐿 then 11 𝑝 ← min({𝑥 ∈ [𝑒 (𝑖), |D|] | longestRight(𝑥, 𝐿) ≥ 𝑒 ( 𝑗)} ∪ {|D| + 1}); 12 𝑞 ← min({𝑥 ∈ [𝑒 ( 𝑗), |D|] | shortestLeft(𝑥, 𝐿) ≥ 𝑒 (𝑖)} ∪ {|D| + 1}); 13 if 𝑝 > 𝑒 (𝑖) then 𝑒 (𝑖) ← 𝑝; 𝑆 ← 𝑆 ∪ {𝑖}; 14 if 𝑞 > 𝑒 ( 𝑗) then 𝑒 ( 𝑗) ← 𝑞; 𝑆 ← 𝑆 ∪ { 𝑗 }; 15 return 𝑒;

occur in D after position 𝑒 (𝑠)). Since (†)𝑒 is satisfied, we know that any C-embedding 𝑒 ∗ of 𝑢 in D with 𝑒 0 ≤ 𝑒 ∗ satisfies 𝑒 ≤ 𝑒 ∗ . But since 𝑢 [𝑠] ≠ D[𝑒 (𝑠)], we also know that 𝑒 ∗ (𝑠) > 𝑒 (𝑠). Further, if 𝑢 [𝑠] appears in D[𝑒 (𝑠) : |D|], then its first occurrence must be at position 𝑒 ′ (𝑠), by definition. Since 𝑒 ∗ has to satisfy D[𝑒 ∗ (𝑠)] = 𝑢 [𝑠], we can conclude that 𝑒 ∗ (𝑠) ≥ 𝑒 ′ (𝑠) and thus the invariant (†)𝑒 ′ holds. Line 10: If the condition is satisfied for some (𝑖, 𝑗, 𝐿) ∈ C with 𝑠 ∈ {𝑖, 𝑗 }, then we have that D[𝑒 (𝑖) + 1 : 𝑒 ( 𝑗) − 1] ∉ 𝐿. Let us consider the following claim, which is reminiscent of Lemma 4.5: Claim D.3. Let 𝑒 : [|𝑢 |] → [|D|] and (𝑖, 𝑗, 𝐿) ∈ C with 𝑒 (𝑖) = 𝑎, 𝑒 ( 𝑗) = 𝑏 such that the sets {𝑥 ∈ [𝑎, |D|] | longestRight(𝑥, 𝐿) ≥ 𝑏} and {𝑥 ∈ [𝑏, |D|] | shortestLeft(𝑥, 𝐿) ≥ 𝑎} are not empty. Let 𝑝 = min{𝑥 ∈ [𝑎, |D|] | longestRight(𝑥, 𝐿) ≥ 𝑏} and 𝑞 = min{𝑥 ∈ [𝑏, |D|] | shortestLeft(𝑥, 𝐿) ≥ 𝑎}. Then D[𝑝 + 1 : 𝑞 − 1] ∈ 𝐿 and (𝑝, 𝑞) is pointwise minimal with this property, i.e., there is no pair (𝑝 ′, 𝑞 ′ ) ∈ [𝑎, |D|] × [𝑏, |D|] with D[𝑝 ′ + 1 : 𝑞 ′ − 1] ∈ 𝐿 and 𝑝 ′ < 𝑝 or 𝑞 ′ < 𝑞. Proof. Firstly, let us assume that 𝑒 satisfies gap-constraint (𝑖, 𝑗, 𝐿). By Lemma 4.5, we have longestRight(𝑒 (𝑖), 𝐿) ≥ 𝑒 ( 𝑗) = 𝑏 and shortestLeft(𝑒 ( 𝑗), 𝐿) ≥ 𝑒 (𝑖) = 𝑎, thus 𝑒 (𝑖) = 𝑝 and 𝑒 ( 𝑗) = 𝑞 and the pair (𝑝, 𝑞) is clearly minimal with this property. Let us now assume that D[𝑎 + 1 : 𝑏 − 1] ∉ 𝐿, i.e., 𝑒 does not satisfy constraint (𝑖, 𝑗, 𝐿). Let 𝑡𝑝 = longestRight(𝑝, 𝐿) and 𝑡𝑞 = shortestLeft(𝑞, 𝐿). These positions are well-defined, since 𝑝 = min{𝑥 ∈ [𝑎, |D|] | longestRight(𝑥, 𝐿) ≥ 𝑏} and 𝑞 = min{𝑥 ∈ [𝑏, |D|] | shortestLeft(𝑥, 𝐿) ≥ 𝑎} and both sets are non-empty. Since 𝑡𝑞 is a valid choice for 𝑥 in the condition longestRight(𝑥, 𝐿) ≥ 𝑏 and 𝑡𝑝 is a valid choice for 𝑥 in the condition shortestLeft(𝑥, 𝐿) ≥ 𝑎, by the definition of 𝑝 and 𝑞, we can conclude that 𝑝 ≤ 𝑡𝑞 and 𝑞 ≤ 𝑡𝑝 . Hence, 𝑝 ≤ 𝑡𝑞 < 𝑞 ≤ 𝑡𝑝 with D[𝑝 + 1 : 𝑡𝑝 − 1] ∈ 𝐿 and D[𝑡𝑞 + 1 : 𝑞 − 1] ∈ 𝐿. Since 𝐿 ∈ LCON, this means that D[𝑝 + 1 : 𝑞 − 1] ∈ 𝐿. Further, if there was a factor D[𝑝 ′ + 1 : 𝑞 ′ − 1] ∈ 𝐿 for some 𝑝 ′ ≥ 𝑎 = 𝑒 (𝑖), 𝑞 ′ ≥ 𝑏 = 𝑒 ( 𝑗) with 𝑝 ′ < 𝑝 (the case 𝑞 ′ < 𝑞 is analogous), then longestRight(𝑝 ′, 𝐿) ≥ 𝑞 ′ ≥ 𝑏 must hold, contradicting the minimality of 𝑝. See also Figure 2. □ , Vol. 1, No. 1, Article . Publication date: June 2026.

32

Antoine Amarilli, Florin Manea, Tina Ringleb, and Markus L. Schmid ∈L ∈L D=

a

p

tq

b

q

tp

∈ L (∗)

Fig. 2. Proof of Claim D.3, where (∗) follows by left-convexity.

It directly follows from Claim D.3 that if there is a C-embedding 𝑒 ∗ of 𝑢 in D with 𝑒 ≤ 𝑒 ∗ , then ≥ 𝑝 and 𝑒 ∗ ( 𝑗) ≥ 𝑞 must hold. Thus, if we change 𝑒 into 𝑒 ′ with 𝑒 ′ (𝑘) = 𝑒 (𝑘) for every 𝑘 ∈ [|𝑢 |] \ {𝑖, 𝑗 }, 𝑒 ′ (𝑖) = 𝑝, and 𝑒 ′ ( 𝑗) = 𝑞, then (†)𝑒 ′ is satisfied as well. 𝑒 ∗ (𝑖)

As a direct consequence of Claim C.1, the second invariant (‡)𝑒,𝑆 is also clearly satisfied after every iteration of the algorithm, concluding our proof. □ To achieve the stated complexity, we need the following result (based on the availability of data structures allowing us to quickly answer the queries in Lines 6 and 11-12, respectively). Lemma D.4. Under the assumption that we can compute the query in Line 6 in constant time and the queries in Lines 11 and 12 in time 𝑂 (log log |D|), we have that Algorithm 2 terminates after time 𝑂 (|D|(|𝑢 | log log |D| + |C|)). Proof. Apart from the time needed to execute the Lines 6, 11 and 12, the complexity directly carries over from the proof of Lemma 4.4. Namely, the time needed to check the conditions of Lines 5, 7, and 10, as well as the time needed for updating 𝑒 and 𝑆, is 𝑂 (|D|(|𝑢 | + |C|)). Further, over the whole computation, the time spent computing Line 6 is clearly 𝑂 (|D| · |𝑢 |), since we evaluate the symbol condition in Line 5 only 𝑂 (|D| · |𝑢 |) many times, thus upper bounding the number of times Line 6 is executed. Now, let us consider the time needed to execute Lines 11 and 12. We can trivially bound the number of iterations of those lines by 𝑂 (|D| · |C|), thus leading to an overall factor of 𝑂 (|D| · |C| log log |D|). However, this is not optimal. As we only execute the Lines 11 and 12 for a given (𝑖, 𝑗, 𝐿)-iteration if and only if D[𝑒 (𝑖) + 1 : 𝑒 ( 𝑗) − 1] ∉ 𝐿, we know that at least one position must be increased by this call. Thus, there can be at most 𝑂 (|D| · |𝑢 |) many (𝑖, 𝑗, 𝐿)-iterations that satisfy the condition of Line 10, so the time needed to execute Lines 11 and 12 is 𝑂 (|D| · |𝑢 | log log |D|), concluding the proof. □ As stated before the previous lemma, in order to conclude the proof of Theorem D.1, we have to show that the queries in Line 6, as well as Lines 11 and 12, can be computed in constant, respectively 𝑂 (log log |D|), time. Firstly, it is not hard to see that we can precompute a matrix next[𝑖] [𝑎] = min{𝑥 ∈ [𝑖, |D|] | D[𝑥] = 𝑎} for 𝑖 ∈ [|D|] and 𝑎 ∈ Σ′ , where Σ′ = {𝑢 [𝑖] | 𝑖 ∈ [|𝑢 |]} is the alphabet of 𝑢, by a simple dynamic programming approach in 𝑂 (|D| · |𝑢 |) time. To efficiently compute the values 𝑝 = min{𝑥 ∈ [𝑒 (𝑖), |D|] | longestRight(𝑥, 𝐿) ≥ 𝑒 ( 𝑗)} and 𝑞 = min{𝑥 ∈ [𝑒 ( 𝑗), |D|] | shortestLeft(𝑥, 𝐿) ≥ 𝑒 (𝑖)} for given 𝑒 : [|𝑢 |] → [|D|] and gap-constraint (𝑖, 𝑗, 𝐿) ∈ C, we employ a data structure result by Gao √︁ et al. [26]. They show that, given a set 𝑃 of 𝑁 points over an 𝑁 × 𝑁 grid, we can construct in 𝑂 (𝑁 log 𝑁 ) time a data structure that allows us to answer orthogonal range successor queries: given a rectangle 𝑅, the query returns the point in 𝑃 ∩ 𝑅 with the smallest 𝑥-coordinate in 𝑂 (log log 𝑁 ) time. With this data structure we can compute 𝑝 and 𝑞 in Lines 11 and 12 as follows. For every gap-constraint language 𝐿 in C, we construct two data structures for orthogonal range successor queries on the |D|×|D| grid. The first one is for the set of points 𝑃𝐿LR = {(𝑘, LR[𝑘] [𝐿]) | 𝑘 ∈ [|D|]}, while the second is for the set of points 𝑃𝐿SL = {(𝑘, SL[𝑘] [𝐿]) | 𝑘 ∈ [|D|]}; given the arrays , Vol. 1, No. 1, Article . Publication date: June 2026.

Tractable Gap-Constraint Languages for Complex Event Recognition

33

LR[k][L]

(p, LR[p][L])

e(j)

k e(i)

Fig. 3. Illustration of the computation of 𝑝 = min{𝑥 ∈ [𝑒 (𝑖), |D|] | longestRight(𝑥, 𝐿) ≥ 𝑒 ( 𝑗)} using orthogonal range successor queries.

√︁ LR[·] [𝐿] and SL[·] [𝐿] computed earlier, this takes 𝑂 (|D| log |D|) time. In order to compute 𝑝 and 𝑞, we use these data structures as follows. Since 𝑝 = min{𝑥 ∈ [𝑒 (𝑖), |D|] | longestRight(𝑥, 𝐿) ≥ 𝑒 ( 𝑗)}, we obtain 𝑝 as the 𝑥-coordinate of the point of minimal 𝑥-coordinate in 𝑅 ∩ 𝑃𝐿LR , where 𝑅 ≔ [𝑒 (𝑖), |D|] × [𝑒 ( 𝑗), |D|]; see also Figure 3 for an illustration of the procedure for 𝑃𝐿LR . Similarly, 𝑞 = min{𝑥 ∈ [𝑒 ( 𝑗), |D|] | shortestLeft(𝑥, 𝐿) ≥ 𝑒 (𝑖)} is obtained as the 𝑥-coordinate of the point of minimal 𝑥-coordinate in 𝑃𝐿SL ∩ 𝑅 ′ , where 𝑅 ′ ≔ [𝑒 ( 𝑗), |D|] × [𝑒 (𝑖), |D|]. If any of the two orthogonal ′ ′ range successor queries does not return any point, then there is no pair (𝑝 ′, 𝑞 ′ ) with √︁ 𝑝 ≥ 𝑒 (𝑖), 𝑞 ≥ ′ ′ 𝑒 ( 𝑗) and D[𝑝 + 1 : 𝑞 − 1] ∈ 𝐿. Thus, after a preprocessing time of 𝑂 (|C| · |D| log |D|), for each gap-constraint language 𝐿 we can execute the queries in Lines 11 and 12 in 𝑂 (log log |D|) time. This shows that the statement of Theorem D.1 holds, and concludes the proof of Theorem D.1. □ We conclude this section with a series of observations about two particularly relevant classes of gap-constraints, for which we can implement the variant of the algorithm from Theorem 4.1, which jumps over larger factors, quicker than the standard variant of this algorithm. Observation D.5. First, let us consider the case when all gap-constraints are length constraints, i.e., constraints of the form (𝑖, 𝑗, 𝐿), with 𝐿 = {𝑤 ∈ Σ∗ | 𝑎 ≤ |𝑤 | ≤ 𝑏}. In this case, it is natural to assume that these constraints are simply given as triples (𝑖, 𝑗, [𝑎, 𝑏]), with both 𝑎 and 𝑏 given in their binary representation; moreover, we can assume 𝑎 ≥ 𝑗 − 𝑖 − 1 (otherwise, we can replace the constraint [𝑎, 𝑏] by [ 𝑗 −𝑖 −1, 𝑏]). It is not hard to see that, in this case, one can check, for a constraint (𝑖, 𝑗, [𝑎, 𝑏]), in constant time (without any preprocessing) whether some factor D[𝑝 + 1 : 𝑞 − 1] satisfies the respective constraint; one simply needs to check whether 𝑎 ≤ 𝑞 − 𝑝 − 1 ≤ 𝑏. So, we run the variant of our algorithm which jumps over longer factors, without any of the usual preprocessing. According to our approach, if in an iteration of the while-loop the condition of Line 10 (of the general algorithm) is satisfied, i.e., D[𝑒 (𝑖) + 1 : 𝑒 ( 𝑗) − 1] ∉ 𝐿, we would like to set 𝑒 (𝑖) ≔ 𝑝 and 𝑒 ( 𝑗) ≔ 𝑞, where 𝑝, 𝑞 ∈ [|D|] such that 𝑒 (𝑖) ≤ 𝑝, 𝑒 ( 𝑗) ≤ 𝑞, D[𝑝 + 1 : 𝑞 − 1] ∈ 𝐿 and 𝑝, 𝑞 are minimal with this property. Let us note that if D[𝑒 (𝑖) + 1 : 𝑒 ( 𝑗) − 1] ∉ 𝐿, then either the factor D[𝑒 (𝑖) + 1 : 𝑒 ( 𝑗) − 1] is too long or too short w.r.t. the constraint [𝑎, 𝑏]. If |D[𝑒 (𝑖) + 1 : 𝑒 ( 𝑗) − 1] | < 𝑎, then we can set 𝑒 (𝑖), 𝑒 ( 𝑗) to be the pair (𝑒 (𝑖), 𝑒 (𝑖) + 𝑎 + 1), and if |D[𝑒 (𝑖) + 1 : 𝑒 ( 𝑗) − 1] | > 𝑏, then we return the pair (𝑒 ( 𝑗) − 𝑏 − 1, 𝑒 ( 𝑗)). Based on these insights, in this case, our algorithm runs in 𝑂 (|D|(|𝑢 | + |C|)) time. Secondly, we consider the case when all gap-constraints are singletons, i.e., constraints of the form (𝑖, 𝑗, 𝐿), with 𝐿 = {𝑤 }, for some string 𝑤. Assume that 𝐿1 = {𝑤 1 }, . . . , 𝐿 | C | = {𝑤 | C | } are the singleton languages which appear in the gap-constraints. In this case, the preprocessing is done differently. We construct the word 𝑤 = D𝑤 1 · · · 𝑤 | C | , and longest common extension data structures for it [20, 34] , Vol. 1, No. 1, Article . Publication date: June 2026.

34

Antoine Amarilli, Florin Manea, Tina Ringleb, and Markus L. Schmid

(also sometimes called longest common prefix data structures); this takes 𝑂 (∥C∥ + |D|) time and allows us to test in 𝑂 (1) time, for some 𝑖 ∈ [|C|] and 𝑗 ∈ [|D|], whether 𝑤𝑖 = D[ 𝑗 : 𝑗 + |𝑤𝑖 | − 1]. Using these data structures, we can trivially compute in 𝑂 (|D| · |C|) time the arrays LR[·] [𝐿𝑖 ] and SL[·] [𝐿𝑖 ]. Indeed, we have LR[𝑘] [𝐿𝑖 ] = 𝑘 + |𝑤𝑖 | + 1 if and only if 𝑤𝑖 = D[𝑘 + 1 : 𝑘 + |𝑤𝑖 |]; for convenience, we set LR[𝑘] [𝐿𝑖 ] = ∞ otherwise. Similarly, SL[𝑘] [𝐿𝑖 ] = 𝑘 − |𝑤𝑖 | − 1 if and only if 𝑤𝑖 = D[𝑘 − |𝑤𝑖 | : 𝑘 − 1], and SL[𝑘] [𝐿𝑖 ] = ∞ otherwise. Moreover, we construct data structures in total 𝑂 (|D| · |C|) time (for all 𝑖) to answer range minimum queries [20] for the arrays SL[·] [𝐿𝑖 ] allowing us to retrieve in 𝑂 (1) time the minimum value from a range SL[𝑎 : 𝑏] [𝐿𝑖 ]; these (more efficient) structures replace, in this particular case, the structures we had for orthogonal range successor in the alternative implementation of the matching algorithm. As above, if in an iteration of the while-loop the condition of Line 10 (of the general algorithm) is satisfied, i.e., D[𝑒 (𝑖) + 1 : 𝑒 ( 𝑗) − 1] ∉ 𝐿, with 𝐿 = {𝑤 }, we would like to set 𝑒 (𝑖) ≔ 𝑝 and 𝑒 ( 𝑗) ≔ 𝑞, where 𝑝, 𝑞 ∈ [|D|] such that 𝑒 (𝑖) ≤ 𝑝, 𝑒 ( 𝑗) ≤ 𝑞, D[𝑝 + 1 : 𝑞 − 1] = 𝑤 and 𝑝, 𝑞 are minimal with this property. In this case, for 𝑏 ′ = max{𝑒 (𝑖) + |𝑤 | + 1, 𝑒 ( 𝑗)}, we now compute 𝑝 ′ as the answer to the range minimum query for SL[𝑏 ′ : |D|] [𝐿] (i.e., 𝑝 ′ + 1 is the leftmost position, greater or equal to max{𝑒 (𝑖) + 1, 𝑒 ( 𝑗) − |𝑤 |}, where 𝑤 occurs) and set (𝑒 (𝑖), 𝑒 ( 𝑗)) to be the pair (𝑝 ′, 𝑝 ′ + |𝑤 | + 1). The matching algorithm runs, in this case, in 𝑂 (∥C∥ + |D|(|𝑢 | + |C|)) time. In the case of singleton gap-constraints, this approach of jumping over larger factors may even work better in practical settings, as the expected number of occurrences of a constraint string 𝑤 (corresponding to the constraint (𝑖, 𝑗, 𝑤)) in a random input document D (over an alphabet of size 𝜎, and independent from the constraints) is 𝑂 (|D|/𝜎 |𝑤 | ) – so the number of positions we need to consider for 𝑒 (𝑖) and 𝑒 ( 𝑗) can be significantly smaller than |D|. However, a full average-case complexity analysis of our algorithms is out of the scope of the present paper. ⊳ E

Full Details for Section 5

Algorithm 3: EmbedLCONAll(𝑢, C, D, 𝑒, 𝑖) Input: 𝑢, C s.t. C only contains LCON-constraints, D ∈ Σ∗ , 𝑒 : [|𝑢 |] → [|D|], positions 1, . . . , 𝑖 locked for 𝑖 ∈ {0, 1, . . . , |𝑢 | − 1}. Output: output all embeddings from 𝑆 (𝑒, 𝑖). ∗ 1 𝑒 ← EmbedLCONSubseq(𝑢, C, D, 𝑒); ∗ 2 if 𝑒 = ⊥ then return; ∗ 3 output 𝑒 ; ∗ 4 𝑗 ← nextMove(𝑒 , 𝑖); 5 while 𝑗 ≠ ⊥ do 6 (𝑒 ∗ ) ( 𝑗 ) ← incr(𝑒 ∗, 𝑗); 7 EmbedLCONAll(𝑢, C, D, (𝑒 ∗ ) ( 𝑗 ) , 𝑗 − 1); 8 𝑗 ← nextMove(𝑒 ∗, 𝑗); Theorem E.1. Let 𝑢 ∈ Σ∗ be a query string with a set C of gap-constraints for 𝑢 such that C only contains left-convex gap-constraints, and let D ∈ Σ∗ with |𝑢 | ≤ |D|. Then we can compute the set 𝑢 C (D) of all C-embeddings of 𝑢 in D in time 𝑂 (|𝑢 C (D)| · |𝑢 | · |D|(|𝑢 | + ∥C∥)). Proof. For simplicity, let us denote by 𝑇 (|𝑢 |, |D|, ∥C∥) the running time of Algorithm 1, i.e., 𝑂 (|D|(|𝑢 | + ∥C∥)). Let us first give some definitions. We say that position 𝑖 is locked (w.r.t. mapping 𝑒 0 ) if, when finding the 𝑒 0 -minimal C-embedding 𝑒 of 𝑢 in D, we only consider the set {𝑒 | 𝑒 0 ≤ 𝑒, 𝑒 (𝑖) = 𝑒 0 (𝑖)}. , Vol. 1, No. 1, Article . Publication date: June 2026.

Tractable Gap-Constraint Languages for Complex Event Recognition

35

In other words, by locking position 𝑖, we only look at embeddings 𝑒 that have the same value for position 𝑖 as mapping 𝑒 0 (i.e., 𝑒 (𝑖) = 𝑒 0 (𝑖)), and return ⊥ (signaling that the solution set is empty) if there is a constraint that can only be satisfied by shifting 𝑒 (𝑖) to some value greater than 𝑒 0 (𝑖). Further, given some mapping 𝑒 and position 𝑖 ∈ {0, 1, . . . , |𝑢 |}, we define the solution set 𝑆 (𝑒, 𝑖) = {𝑒 ′ | 𝑒 ≤ 𝑒 ′, 𝑒 ′ (1) = 𝑒 (1), . . . , 𝑒 ′ (𝑖) = 𝑒 (𝑖), 𝑢 ⪯𝑒 ′ ,C D} as the set of C-embeddings 𝑒 ′ of 𝑢 in D that can be obtained from 𝑒 by increasing some (or none) of its positions 𝑖 + 1, . . . , |𝑢 |, and locking positions 1, . . . , 𝑖. Note that 𝑆 (𝑒, 0) contains all C-embeddings 𝑒 ′ of 𝑢 in D with 𝑒 ≤ 𝑒 ′ and is empty if and only if there is no 𝑒-minimal C-embedding of 𝑢 in D; clearly, if 𝑢 ⪯𝑒,C D then 𝑒 is contained in 𝑆 (𝑒, 𝑖) for any 𝑖 ∈ {0, 1, . . . , |𝑢 |}. Next, in order to obtain subsets of 𝑆 (𝑒, 𝑖), let us define the minimal mappings 𝑒 ( 𝑗 ) that are strictly larger than 𝑒 and can be obtained from 𝑒 by shifting 𝑒 ( 𝑗) to 𝑒 ( 𝑗) + 1 for some 𝑗 ∈ [|𝑢 |]. In particular, for every mapping 𝑒 : [|𝑢 |] → [|D|] and 𝑗 ∈ [|𝑢 |], the mapping 𝑒 ( 𝑗 ) : [|𝑢 |] → [|D|] moves 𝑒 ( 𝑗) to position 𝑒 ( 𝑗) + 1, and coincides with 𝑒 on all other positions. Formally, 𝑒 ( 𝑗 ) is defined by 𝑒 ( 𝑗 ) (𝑝) ≔ 𝑒 (𝑝) for all 𝑝 ∈ [|𝑢 |] \ { 𝑗 } and 𝑒 ( 𝑗 ) ( 𝑗) ≔ 𝑒 ( 𝑗) + 1. Let incr(𝑒, 𝑗) be the function that computes 𝑒 ( 𝑗 ) for a given mapping 𝑒 and 𝑗 ∈ [|𝑢 |]; obviously, 𝑒 ( 𝑗 ) = incr(𝑒, 𝑗) can be computed in 𝑂 (|𝑢 |) time. Note that, whenever 𝑒 ( 𝑗 ) ( 𝑗) > |D|, then Algorithm 1 returns ⊥ after evaluating 𝑗 ∈ 𝑆 for the first time and 𝑆 (𝑒 ( 𝑗 ) , 𝑗 − 1) must necessarily be empty. It is not hard to see that, given some 𝑖 ∈ {0, 1, . . . , |𝑢 | − 1} and 𝑗 > 𝑖, the set 𝑆 (𝑒 ( 𝑗 ) , 𝑖) is a (not necessarily strict) subset of 𝑆 (𝑒, 𝑖). We can even use these mappings to partition 𝑆 (𝑒, 𝑖): Claim E.2. Let 𝑒 : [|𝑢 |] → [|D|] be a mapping and 𝑖 ∈ {0, 1, . . . , |𝑢 |}. • 𝑆 (𝑒, 𝑖) = ∅ if and only if 𝑆 (𝑒, 0) = ∅ or 𝑒 min (𝑘) > 𝑒 (𝑘) for some 𝑘 ∈ [𝑖], where 𝑒 min is the 𝑒-minimal C-embedding of 𝑢 in D. • If 𝑆 (𝑒, 𝑖) ≠ ∅, then 𝑆 (𝑒, 𝑖) is the disjoint union of the sets (𝑖+1) (𝑖+2) ( |𝑢 | ) {𝑒 min }, 𝑆 (𝑒 min , 𝑖), 𝑆 (𝑒 min , 𝑖 + 1), . . . , 𝑆 (𝑒 min , |𝑢 | − 1) ,

where 𝑒 min is the 𝑒-minimal C-embedding of 𝑢 in D. Proof. We start with the if-direction of the first bullet point. If 𝑆 (𝑒, 0) = ∅, then 𝑆 (𝑒, 𝑖) is empty by definition. Therefore, let us assume in the following that the 𝑒-minimal C-embedding 𝑒 min of 𝑢 in D exists (and thus is an element of 𝑆 (𝑒, 0)). If there is some 𝑘 ∈ [𝑖] such that 𝑒 min (𝑘) > 𝑒 (𝑘), then, by minimality of 𝑒 min , there cannot be a C-embedding of 𝑢 in D that agrees with 𝑒 on positions 1, . . . , 𝑖. For the only-if-direction, let us assume that 𝑆 (𝑒, 𝑖) = ∅, which also means that 𝑒 min ∉ 𝑆 (𝑒, 𝑖). Hence, there must be a 𝑘 ∈ [𝑖] with 𝑒 min (𝑘) > 𝑒 (𝑘). Now, let us consider the second bullet point. By assumption 𝑆 (𝑒, 𝑖) ≠ ∅; thus, using the first bullet point, the first 𝑖 positions of 𝑒 min must coincide with 𝑒. This means that 𝑒 min ∈ 𝑆 (𝑒, 𝑖). Further, by the minimality of 𝑒 min , 𝑒 min ≤ 𝑒 ′ must hold for all 𝑒 ′ ∈ 𝑆 (𝑒, 𝑖) and thus 𝑆 (𝑒, 𝑖) = 𝑆 (𝑒 min, 𝑖). By (𝑗) (𝑗) definition of 𝑒 min , any set 𝑆 (𝑒 min , 𝑗 − 1) with 𝑗 ∈ [𝑖 + 1, |𝑢 |] must be contained in 𝑆 (𝑒, 𝑖). This proves the inclusion from right to left. For the inclusion from left to right, we first observe that 𝑒 min ∈ 𝑆 (𝑒, 𝑖) is included in the right side by definition. Let us consider some embedding 𝑒 ′ ∈ 𝑆 (𝑒, 𝑖) with 𝑒 ′ ≠ 𝑒 min , then 𝑒 min < 𝑒 ′ and there (𝑗) must be a minimal 𝑗 ∈ [𝑖 + 1, |𝑢 |] such that 𝑒 ′ ( 𝑗) > 𝑒 min ( 𝑗). Thus, 𝑒 min ≤ 𝑒 ′ and 𝑒 ′ (𝑘) = 𝑒 min (𝑘) for (𝑗) all 𝑘 ∈ [ 𝑗 − 1], so 𝑒 ′ must be contained in 𝑆 (𝑒 min , 𝑗 − 1). This proves the inclusion from left to right. ( 𝑗 ) (𝑗′) ′ ′ For disjointness, let 𝑒 ∈ 𝑆 (𝑒 min, 𝑗 − 1) ∩ 𝑆 (𝑒 min , 𝑗 − 1) with 𝑗 ≠ 𝑗 ′ ∈ [𝑖 + 1, |𝑢 |]. If 𝑗 < 𝑗 ′ , then (𝑗) (𝑗′) ′ ′ 𝑒 ∈ 𝑆 (𝑒 min , 𝑗 − 1) implies 𝑒 ′ ( 𝑗) > 𝑒 min ( 𝑗) and 𝑒 ′ ∈ 𝑆 (𝑒 min , 𝑗 − 1) implies 𝑒 ′ ( 𝑗) = 𝑒 min ( 𝑗), which is a contradiction. □ (𝑗) The nextMove Procedure. To efficiently test which subsets 𝑆 (𝑒 min , 𝑗 −1), for 𝑗 ∈ [𝑖 +1, |𝑢 |], defined in Claim E.2, are non-empty, we use the following procedure, which will be crucial for the running

, Vol. 1, No. 1, Article . Publication date: June 2026.

36

Antoine Amarilli, Florin Manea, Tina Ringleb, and Markus L. Schmid

time of Algorithm 3. For every 𝑖 ∈ {0, 1, . . . , |𝑢 | − 1} and every C-embedding 𝑒 : [|𝑢 |] → [|D|] of 𝑢 in D, the procedure nextMove(𝑒, 𝑖) returns the minimal 𝑗 ∈ [𝑖 + 1, |𝑢 |] such that the subset 𝑆 (𝑒 ( 𝑗 ) , 𝑗 − 1) of 𝑆 (𝑒, 𝑖) is not empty, or returns ⊥ if there is no such 𝑗. Naïvely, as implemented in Algorithm 4, this can be done in time 𝑂 (|𝑢 | · 𝑇 (|𝑢 |, |D|, ∥C∥)) by testing for every 𝑗 = 𝑖 + 1, . . . , |𝑢 | whether there is an 𝑒 ( 𝑗 ) -minimal C-embedding of 𝑢 in D that agrees with 𝑒 on the first 𝑗 − 1 positions and returning the first 𝑗 for which this condition is true, or ⊥ if there is no such 𝑗. It is easy to see that this implementation runs in time 𝑂 (( 𝑗 − 𝑖) · 𝑇 (|𝑢 |, |D|, ∥C∥)) if nextMove(𝑒, 𝑖) = 𝑗, and in time 𝑂 ((|𝑢 | − 𝑖) · 𝑇 (|𝑢 |, |D|, ∥C∥)) if nextMove(𝑒, 𝑖) = ⊥. Algorithm 4: nextMove(𝑒, 𝑖) Input: mapping 𝑒 : [|𝑢 |] → [|D|], positions 1, . . . , 𝑖 locked for 𝑖 ∈ {0, 1, . . . , |𝑢 | − 1}. Output: minimal 𝑗 ∈ [𝑖 + 1, |𝑢 |] s.t. 𝑆 (𝑒 ( 𝑗 ) , 𝑗 − 1) ≠ ∅, or ⊥ if there is none. 1 for 𝑗 = 𝑖 + 1 to |𝑢 | do 2 𝑒 ( 𝑗 ) ← incr(𝑒, 𝑗); 3 𝑒 ∗𝑗 ← EmbedLCONSubseq(𝑢, C, D, 𝑒 ( 𝑗 ) ); 4 if (𝑒 ∗𝑗 ≠ ⊥) ∧ (∀ 𝑘 ∈ [ 𝑗 − 1] : 𝑒 ∗𝑗 (𝑘) = 𝑒 ( 𝑗 ) (𝑘)) then 5 return 𝑗; 6 return ⊥; Our algorithm (see Algorithm 3) now works by recursively computing, given mapping 𝑒 and locked positions 1, . . . , 𝑖 for some 𝑖 ∈ {0, 1, . . . , |𝑢 | − 1}, the 𝑒-minimal C-embedding 𝑒 min of 𝑢 in D and partitioning the remaining space of solutions (i.e., C-embeddings) into disjoint subsets. In particular, we compute 𝑆 (𝑒, 𝑖) as follows: First, compute 𝑒 min as the 𝑒-minimal C-embedding of 𝑢 in D. If, as in the first case of Claim E.2, 𝑒 min = ⊥ or 𝑒 min (𝑘) > 𝑒 (𝑘) for some position 𝑘 ∈ [𝑖], (𝑗) then 𝑆 (𝑒, 𝑖) is empty.5 Otherwise we recursively compute the non-empty sets 𝑆 (𝑒 min , 𝑗 − 1) for (𝑗) 𝑗 ∈ [𝑖+1, |𝑢 |]. Finding all values 𝑗 ∈ [𝑖+1, |𝑢 |] with corresponding non-empty set 𝑆 (𝑒 min , 𝑗 −1) can be done using successive calls of the nextMove procedure: first, we determine 𝑗 ′ = nextMove(𝑒 min, 𝑖) corresponding to the minimal (w.r.t. 𝑗 ′ ) non-empty subset, and then iteratively find the next such subset by updating 𝑗 ′ = nextMove(𝑒 min, 𝑗 ′ ) (thus finding the smallest non-empty subset of 𝑆 (𝑒 min, 𝑗 ′ ) ⊆ 𝑆 (𝑒 min, 𝑖)), until the procedure returns ⊥, signaling that we found all subsets. Initially, we call the procedure for 𝑆 (𝑒 0, 0), where 𝑒 0 : [|𝑢 |] → [|D|] is the trivial mapping with 𝑒 0 (𝑘) = 𝑘 for all 𝑘 ∈ [|𝑢 |], and thus compute all C-embeddings of 𝑢 in D (since there can be no C-embedding 𝑒 ′ of 𝑢 in D with 𝑒 ′ < 𝑒 0 ). If the first call to EmbedLCONSubseq indicates in Line 2 that there is no embedding, then we stop the computation immediately. Otherwise, given a mapping 𝑒 with locked positions 1, . . . , 𝑖 for some 𝑖 ∈ {0, . . . , |𝑢 | − 1}, we can compute the 𝑒-minimal C-embedding 𝑒 min of 𝑢 in D by calling Algorithm 1 in time 𝑂 (𝑇 (|𝑢 |, |D|, ∥C∥)). Then, we have to determine all non-empty subsets of 𝑆 (𝑒 min, 𝑖) = 𝑆 (𝑒, 𝑖) using calls to nextMove. If ( 𝑗ℓ ) { 𝑗1, . . . , 𝑗𝑟 } ⊆ [𝑖 + 1, |𝑢 |] are the positions corresponding to the non-empty subsets (i.e., 𝑆 (𝑒 min , 𝑗ℓ − 1) ≠ ∅ for all ℓ ∈ [𝑟 ]), then we have exactly 𝑟 + 1 calls of nextMove(𝑒 min, ·), namely with the parameters 𝑖, 𝑗1, . . . , 𝑗𝑟 , where nextMove(𝑒 min, 𝑗ℓ ) = 𝑗ℓ+1 for all ℓ ∈ [𝑟 − 1], nextMove(𝑒 min, 𝑖) = 𝑗1 , and nextMove(𝑒 min, 𝑗𝑟 ) = ⊥. The time needed to execute these calls adds up to a telescopic sum, resulting in 𝑂 (|𝑢 | · 𝑇 (|𝑢 |, |D|, ∥C∥)) time for each recursive call. We can then recursively generate 5 Note that this can only occur in the initial call to compute 𝑆 (𝑒 , 0), where 𝑒 (𝑘 ) = 𝑘 for all 𝑘 ∈ [ |𝑢 | ]. In all other cases 0 0 we only recursively call the algorithm to compute 𝑆 (𝑒, 𝑖 ) if we already determined that this set is non-empty, and thus 𝑒 min ∈ 𝑆 (𝑒, 𝑖 ).

, Vol. 1, No. 1, Article . Publication date: June 2026.

Tractable Gap-Constraint Languages for Complex Event Recognition

37

( 𝑗ℓ ) all elements of the sets 𝑆 (𝑒 min , 𝑗ℓ − 1) for ℓ ∈ [𝑟 ]. Overall, since we have exactly one recursive call for every embedding 𝑒 ∈ 𝑢 C (D) (in which this embedding is also output), we produce all elements of 𝑢 C (D) in time 𝑂 (|𝑢 C (D)| · |𝑢 | · 𝑇 (|𝑢 |, |D|, ∥C∥)). This concludes the proof of Theorem E.1. □

We can argue that we can use the algorithm computing the set 𝑢 C (D) to directly obtain an enumeration algorithm for 𝑢 C (D). Theorem E.3. Let 𝑢 ∈ Σ∗ be a query string with a set C of gap-constraints for 𝑢 such that C only contains left-convex gap-constraints, and let D ∈ Σ∗ with |𝑢 | ≤ |D|. Then we can enumerate the set 𝑢 C (D) of all C-embeddings of 𝑢 in D with 𝑂 (|D|(|𝑢 | + ∥C∥)) preprocessing time and 𝑂 (|𝑢 | · |D|(|𝑢 | + ∥C∥)) delay. Proof. We modify Algorithm 3 to make sure that the last recursive call performed (if any) is tail-recursive, as described in Algorithm 5. Algorithm 5: EmbedLCONAll(𝑢, C, D, 𝑒, 𝑖) Input: 𝑢, C s.t. C only contains LCON-constraints, D ∈ Σ∗ , 𝑒 : [|𝑢 |] → [|D|], positions 1, . . . , 𝑖 locked for 𝑖 ∈ {0, 1, . . . , |𝑢 | − 1}. Output: output all embeddings from 𝑆 (𝑒, 𝑖). ∗ 1 𝑒 ← EmbedLCONSubseq(𝑢, C, D, 𝑒); ∗ 2 if 𝑒 = ⊥ then return; ∗ 3 output 𝑒 ; ∗ 4 𝑗 ← nextMove(𝑒 , 𝑖); 5 if 𝑗 = ⊥ then return; ∗ 6 while nextMove(𝑒 , 𝑗) ≠ ⊥ do ∗ ( 𝑗 ) 7 (𝑒 ) ← incr(𝑒 ∗, 𝑗); 8 EmbedLCONAll(𝑢, C, D, (𝑒 ∗ ) ( 𝑗 ) , 𝑗 − 1); 9 𝑗 ← nextMove(𝑒 ∗, 𝑗); ∗ ( 𝑗 ) ← incr(𝑒 ∗, 𝑗); 10 (𝑒 ) ∗ ( 𝑗 ) , 𝑗 − 1); 11 EmbedLCONAll(𝑢, C, D, (𝑒 ) To ensure this, we basically unravel the last iteration of the while-loop of Line 6. This is achieved by simply changing the condition from Line 5 of Algorithm 3 (Line 6 in Algorithm 5) from 𝑗 ≠ ⊥ to nextMove(𝑒 ∗, 𝑗) ≠ ⊥, and treating the case when nextMove(𝑒 ∗, 𝑗) = ⊥ separately, as the case that corresponds to the tail call (which will not be added to the stack of function calls); as long as nextMove(𝑒 ∗, 𝑗) ≠ ⊥, there will be at least one subsequent call and we deal with that in a standard recursive call. The correctness of the algorithm follows from the fact that it correctly computes the solution set, with no duplicates, as we had already argued: it restates, in a straightforward manner, Algorithm 3 with the last iteration of the while-loop executed separately (since, in that iteration, Line 9 does not need to be executed). The preprocessing time bound is immediate. Note that the preprocessing covers in particular the root-level call to EmbedLCONAll, so we can in particular use it to detect whether the solution space is empty and abort otherwise. Let us now argue that the delay bound is respected. For this, we observe that our modification to the algorithm ensures (†): every recursive call to EmbedLCONAll will produce one solution, after a time of 𝑂 (𝑇 (|𝑢 |, |D|, ∥C∥)), namely, the complexity of the call at Line 1. (The fact that this is true already at the root-level call is ensured because we use the preprocessing to handle the case where there are no solutions at all.) , Vol. 1, No. 1, Article . Publication date: June 2026.

38

Antoine Amarilli, Florin Manea, Tina Ringleb, and Markus L. Schmid

From then on, when considering one given call of EmbedLCONAll, there are two possibilities. The first one is that we do no recursive call. The other possibility is that we do recursive calls, with the last call being tail-recursive. Let us argue that the delay bound is respected by considering the current recursive call and bounding the number of computation steps after the solution that it outputs at Line 3, until either the next output or the end of the enumeration. In the first case, we conclude after time 𝑂 (|𝑢 | · 𝑇 (|𝑢 |, |D|, ∥C∥)) (namely, the complexity of Algorithm 4) that no recursive calls are necessary, and we exit the current call. Thanks to the use of tail-recursion, either this terminates the overall algorithm, or it returns to a parent call in which some subsequent recursive call still needed to be made (i.e., the parent call was not tail-recursive). In the latter case, after time 𝑂 (|𝑢 | · 𝑇 (|𝑢 |, |D|, ∥C∥)), we know that a subsequent recursive call will be made, and by invariant (†) we know that this call will produce a result after time 𝑂 (𝑇 (|𝑢 |, |D|, ∥C∥)). Thus the overall delay satisfies our bound of 𝑂 (|𝑢 | · 𝑇 (|𝑢 |, |D|, ∥C∥)). In the second case, we conclude after time 𝑂 (|𝑢 | · 𝑇 (|𝑢 |, |D|, ∥C∥)) that some recursive call needs to be made. Note that this includes two invocations of Algorithm 4: the one at Line 4, and the one done in anticipation to check whether the first recursive call is tail-recursive (which is at Line 6): however this just amounts to a factor of two, so the time since the output is still 𝑂 (|𝑢 | · 𝑇 (|𝑢 |, |D|, ∥C∥)). We then do the first recursive call to EmbedLCONAll of the current call, which by invariant (†) will produce a result after time 𝑂 (𝑇 (|𝑢 |, |D|, ∥C∥)). Hence, the delay bound is respected again. The time spent between two recursive calls originating in two consecutive iterations of the while-loop (and, thus, between two consecutive outputs caused by these calls) is, by similar arguments, 𝑂 (|𝑢 | · 𝑇 (|𝑢 |, |D|, ∥C∥)). This concludes the proof. □ As we have seen in the proof of Theorem E.1, the running time of Algorithm 3 depends significantly on the implementation of the nextMove procedure. We can now show that if C consists of only constraints that are not just left-convex but also right-convex, then we can implement nextMove more efficiently, leading to the following, improved result. Recall that RCON denotes the class of right-convex languages (see Appendix A). Theorem 5.2. Let 𝑢 ∈ Σ∗ be a query string, let C be a set of gap-constraints for 𝑢 that are both left- and right-convex, and let D ∈ Σ∗ with |𝑢 | ≤ |D|. Then we can enumerate the set 𝑢 C (D) with 𝑂 (|D|(|𝑢 | + ∥C∥)) preprocessing time and 𝑂 (|D|(|𝑢 | + ∥C∥)) delay. (Note that this entails a total computation of 𝑢 C (D) in time 𝑂 (|𝑢 C (D)| · |D|(|𝑢 | + ∥C∥)).) Proof. For simplicity, let us again denote by 𝑇 (|𝑢 |, |D|, ∥C∥) the running time of Algorithm 1, i.e., 𝑂 (|D|(|𝑢 | + ∥C∥)). The general approach follows Algorithm 3 (Theorem E.1), with the same modifications to ensure that the last recursive call is tail-recursive. However, we can now exploit that every language 𝐿 is not just left- but also right-convex, and use this to find the next non-empty subset 𝑆 (𝑒 ( 𝑗 ) , 𝑗 − 1) in time 𝑂 (𝑇 (|𝑢 |, |D|, ∥C∥)), instead of time 𝑂 (|𝑢 | ·𝑇 (|𝑢 |, |D|, ∥C∥)). Recall that a language 𝐿 is right-convex if and only if its mirror image 𝐿𝑅 = {𝑤 [|𝑤 |]𝑤 [|𝑤 | − 1] · · · 𝑤 [1] | 𝑤 ∈ 𝐿} is left-convex. Analogously to minimal embeddings, given mapping 𝑒 0 : [|𝑢 |] → [|D|], we say an embedding 𝑒 is an 𝑒 0 -maximal C-embedding of 𝑢 in D if and only if 𝑒 is a C-embedding of 𝑢 in D with 𝑒 ≤ 𝑒 0 and 𝑒 is maximal within the set of all C-embeddings 𝑒 ′ of 𝑢 in D with 𝑒 ′ ≤ 𝑒 0 . Analogously to Lemma 4.2 for left-convex languages, if C consists of only right-convex gap-constraints, then the 𝑒 0 -maximal C-embedding of 𝑢 in D is unique (if it exists). By symmetry, it is immediate that, given strings 𝑢, D, a set C of right-convex gap-constraints for 𝑢, and a mapping 𝑒 0 , we can compute the 𝑒 0 -maximal C-embedding of 𝑢 in D in time 𝑂 (𝑇 (|𝑢 |, |D|, ∥C∥)). Let us call this procedure EmbedRCONMax (see an implementation in Algorithm 6). , Vol. 1, No. 1, Article . Publication date: June 2026.

Tractable Gap-Constraint Languages for Complex Event Recognition

39

Algorithm 6: EmbedRCONMax(𝑢, C, D, 𝑒 0 ) Input: 𝑢, C s.t. C contains only RCON-constraints, D ∈ Σ∗ . Output: C-embedding 𝑒 of 𝑢 in D, s.t. 𝑒 ≤ 𝑒 0 and 𝑒 is maximal with this property, if it exists, and ⊥ otherwise. 𝑅 𝑅 𝑅 1 set C as the reverse of C, i.e., C ← {(|𝑢 | − 𝑗 + 1, |𝑢 | − 𝑖 + 1, 𝐿 ) | (𝑖, 𝑗, 𝐿) ∈ C}; 𝑅 𝑅 𝑅 𝑅 𝑅 2 set 𝑒 0 as the reverse of 𝑒 0 , i.e., 𝑒 0 : [|𝑢 |] → [|D |] s.t. 𝑒 0 (𝑘) = |D| − 𝑒 0 (|𝑢 | − 𝑘 + 1) + 1 for all 𝑘 ∈ [|𝑢 |]; 𝑅 𝑅 𝑅 𝑅 𝑅 3 𝑒 ← EmbedLCONSubseq(𝑢 , C , D , 𝑒 0 ); 𝑅 4 if 𝑒 = ⊥ then return ⊥; 𝑅 5 set 𝑒 as the reverse of 𝑒 ; 6 return 𝑒; We recall the nextMove procedure. Given C-embedding 𝑒 and 𝑖 ∈ {0, 1, . . . , |𝑢 |−1}, nextMove(𝑒, 𝑖) computes the minimal 𝑗 ∈ [𝑖 + 1, |𝑢 |] such that 𝑆 (𝑒 ( 𝑗 ) , 𝑗 − 1) ≠ ∅, and returns ⊥ if there is no such 𝑗. As we have seen in the proof of Theorem E.1, if C consists of left-convex languages, this can be implemented in 𝑂 (( 𝑗 − 𝑖) · 𝑇 (|𝑢 |, |D|, ∥C∥)) time. However, if C consists of only constraints in LCON∩RCON, then we can compute nextMove(𝑒, 𝑖) faster by analysing the 𝑒 ′ -maximal C-embedding 𝑒 max of 𝑢 in D (computed using EmbedRCONMax), where 𝑒 ′ (𝑘) = 𝑒 (𝑘) for all 𝑘 ∈ [𝑖] and 𝑒 ′ (𝑘) = |D| − (|𝑢 | − 𝑘) for all 𝑘 ∈ [𝑖 + 1, |𝑢 |]. Intuitively, 𝑒 ′ coincides with 𝑒 for all locked positions and all other positions are maximal (i.e., 𝑒 (|𝑢 |) = |D|, 𝑒 (|𝑢 | − 1) = |D| − 1, . . .), in order to not restrict their placement in 𝑒 max . Thus, when computing the maximal embedding, we only consider embeddings 𝑒 ′′ with 𝑒 ′′ (𝑘) ≤ 𝑒 (𝑘) for all 𝑘 ∈ [𝑖], and, because 𝑒 itself is a C-embedding of 𝑢 in D, 𝑒 ≤ 𝑒 max and 𝑒 (𝑘) = 𝑒 max (𝑘) for all 𝑖 ∈ [|𝑢 |] must hold. Now, nextMove(𝑒, 𝑖) returns the smallest 𝑗 ∈ [𝑖 + 1, |𝑢 |] with 𝑒 ( 𝑗) < 𝑒 max ( 𝑗), or ⊥ if 𝑒 = 𝑒 max . See Algorithm 7 for an implementation. Algorithm 7: nextMoveLRCON(𝑒, 𝑖) Input: C-embedding 𝑒 of 𝑢 in D, positions 1, . . . , 𝑖 locked for 𝑖 ∈ {0, 1, . . . , |𝑢 | − 1}. Output: minimal 𝑗 ∈ [𝑖 + 1, |𝑢 |] s.t. 𝑆 (𝑒 ( 𝑗 ) , 𝑗 − 1) ≠ ∅, or ⊥ if there is none. 1 for 𝑗 ∈ [𝑖] do 2 set 𝑒 ′ ( 𝑗) = 𝑒 ( 𝑗); 3 for 𝑗 ∈ [𝑖 + 1, |𝑢 |] do 4 set 𝑒 ′ ( 𝑗) = |D| − (|𝑢 | − 𝑗); ′ 5 𝑒 max ← EmbedRCONMax(𝑢, C, D, 𝑒 ); 6 if š 𝑘 ∈ [𝑖 + 1, |𝑢 |] s.t. 𝑒 max (𝑘) > 𝑒 (𝑘) then return ⊥; 7 return min{𝑘 ∈ [𝑖 + 1, |𝑢 |] | 𝑒 max (𝑘) > 𝑒 (𝑘)}; Let us write nextMove𝐿 (𝑒, 𝑖) for the 𝑂 (( 𝑗 − 𝑖) · 𝑇 (|𝑢 |, |D|, ∥C∥)) time naïve implementation for left-convex languages, and nextMove𝐿𝑅 (𝑒, 𝑖) for the variant that requires all languages to be both left- and right-convex. We can now argue that nextMove𝐿 (𝑒, 𝑖) = nextMove𝐿𝑅 (𝑒, 𝑖) for all C-embeddings 𝑒 of 𝑢 in D and 𝑖 ∈ {0, 1, . . . , |𝑢 | − 1}. Claim E.4. Let 𝑒 : [|𝑢 |] → [|D|] be a C-embedding of 𝑢 in D and 𝑖 ∈ {0, 1, . . . , |𝑢 | − 1}. • 𝑆 (𝑒, 𝑖) = {𝑒} if and only if nextMove𝐿𝑅 (𝑒, 𝑖) = ⊥. • If nextMove𝐿𝑅 (𝑒, 𝑖) = 𝑗 ∈ [𝑖 + 1, |𝑢 |] then 𝑆 (𝑒 ( 𝑗 ) , 𝑗 − 1) is the smallest (w.r.t. 𝑗) non-empty subset of 𝑆 (𝑒, 𝑖) \ {𝑒}. , Vol. 1, No. 1, Article . Publication date: June 2026.

40

Antoine Amarilli, Florin Manea, Tina Ringleb, and Markus L. Schmid

Proof. Let 𝑒 ′ : [|𝑢 |] → [|D|] be a mapping with 𝑒 ′ (𝑘) = 𝑒 (𝑘) for all 𝑘 ∈ [𝑖] and 𝑒 ′ (𝑘) = |D| − (|𝑢 | − 𝑘) for all 𝑘 ∈ [𝑖 + 1, |𝑢 |], like in the computation of nextMove𝐿𝑅 (𝑒, 𝑖). We will first show that the 𝑒 ′ -maximal C-embedding 𝑒 max of 𝑢 in D is the maximal element of 𝑆 (𝑒, 𝑖). By definition, 𝑒 max ≤ 𝑒 ′ and thus 𝑒 max (𝑘) ≤ 𝑒 ′ (𝑘) = 𝑒 (𝑘) for all 𝑘 ∈ [𝑖]. Since all other positions of 𝑒 ′ are shifted as far as possible to the right (there cannot be an embedding 𝑒 ′′ with 𝑒 ′′ (𝑘) > |D| − (|𝑢 | − 𝑘) for any 𝑘 ∈ [|𝑢 |], as this would contradict the order condition 1 ≤ 𝑒 ′′ (1) < 𝑒 ′′ (2) < . . . < 𝑒 ′′ (|𝑢 |) ≤ |D|), and because 𝑒 is a possible candidate for 𝑒 max , we have that 𝑒 max (𝑘) ≥ 𝑒 (𝑘) for all 𝑘 ∈ [𝑖 + 1, |𝑢 |]. Thus, 𝑒 max ∈ 𝑆 (𝑒, 𝑖). Assume now that there is an 𝑒 ′′ ∈ 𝑆 (𝑒, 𝑖) with 𝑒 max ≤ 𝑒 ′′ . By definition of 𝑆 (𝑒, 𝑖), 𝑒 ′′ must satisfy 𝑒 ′′ (𝑘) = 𝑒 (𝑘) = 𝑒 max (𝑘) for all 𝑘 ∈ [𝑖] and 𝑒 ′′ (𝑘) > 𝑒 max (𝑘) for some 𝑘 ∈ [𝑖 + 1, |𝑢 |]. However, this contradicts that 𝑒 max is 𝑒 ′ -maximal. Therefore, 𝑒 max must be the maximal element of 𝑆 (𝑒, 𝑖). Now, if 𝑒 max = 𝑒, then the minimal and maximal element of 𝑆 (𝑒, 𝑖) coincide and there cannot be another embedding 𝑒 ′′ ∈ 𝑆 (𝑒, 𝑖) with 𝑒 ′′ ≠ 𝑒. Since nextMove𝐿𝑅 (𝑒, 𝑖) returns ⊥ if and only if 𝑒 max = 𝑒, the procedure correctly determines if there is no non-empty subset of 𝑆 (𝑒, 𝑖) \ {𝑒} = ∅. On the other hand, assume that 𝑆 (𝑒, 𝑖) ≠ {𝑒}. Then 𝑒 max ≠ 𝑒 and 𝑒 max ∈ 𝑆 (𝑒, 𝑖), i.e., 𝑆 (𝑒, 𝑖) \ {𝑒} must contain at least one element. Therefore, there is at least one non-empty subset 𝑆 (𝑒 ( 𝑗 ) , 𝑗 − 1) for 𝑗 ∈ [𝑖 + 1, |𝑢 |], namely the one containing 𝑒 max . If 𝑗 ∈ [𝑖 + 1, |𝑢 |] is the minimal position such that 𝑒 max ( 𝑗) > 𝑒 ( 𝑗), then, by definition, 𝑒 max ∈ 𝑆 (𝑒 ( 𝑗 ) , 𝑗 − 1). Because 𝑒 max is 𝑒 ′ -maximal, there can be no non-empty subset 𝑆 (𝑒 (𝑘 ) , 𝑘 − 1) for 𝑘 ∈ [𝑖 + 1, 𝑗 − 1]: If there was some embedding 𝑒 ′′ ∈ 𝑆 (𝑒 (𝑘 ) , 𝑘 − 1), then 𝑒 ′′ (𝑘) > 𝑒 max (𝑘) would contradict that 𝑒 max is the unique 𝑒 ′ -maximal C-embedding of 𝑢 in D. Therefore, nextMove(𝑒, 𝑖) correctly returns value 𝑗 if 𝑆 (𝑒 ( 𝑗 ) , 𝑗 − 1) is the smallest (w.r.t. 𝑗) non-empty subset of 𝑆 (𝑒, 𝑖) \ {𝑒}. □ Given some C-embedding 𝑒 of 𝑢 in D and 𝑖 ∈ {0, 1, . . . , |𝑢 |}, the time needed to compute nextMove𝐿𝑅 (𝑒, 𝑖) is 𝑂 (𝑇 (|𝑢 |, |D|, ∥C∥)): We first compute the 𝑒 ′ -maximal C-embedding 𝑒 max of 𝑢 in D in time 𝑂 (𝑇 (|𝑢 |, |D|, ∥C∥)) and then determine the smallest 𝑗 ∈ [𝑖 + 1, |𝑢 |] with 𝑒 max ( 𝑗) > 𝑒 ( 𝑗), which takes 𝑂 (|𝑢 |) time. Since 𝑆 (𝑒, 𝑗 ′ ) ⊆ 𝑆 (𝑒, 𝑗) holds for all mappings 𝑒 and 𝑗 < 𝑗 ′ , we compute all 𝑗 ∈ [𝑖 + 1, |𝑢 |] such that 𝑆 (𝑒 ( 𝑗 ) , 𝑗 − 1) ≠ ∅ as follows: If nextMove𝐿𝑅 (𝑒, 𝑖) = ⊥, there is no such 𝑗. Otherwise, let 𝑗1 = nextMove𝐿𝑅 (𝑒, 𝑖), then we compute 𝑗ℓ = nextMove𝐿𝑅 (𝑒, 𝑗ℓ −1 ) for increasing ℓ until 𝑗ℓ = ⊥. Now, 𝑆 (𝑒 (𝑘 ) , 𝑘 − 1) ≠ ∅ if and only if 𝑘 ∈ { 𝑗1, . . . , 𝑗ℓ −1 } by Claim E.4. The rest of the procedure follows Algorithm 3 but replaces the nextMove𝐿 function (Algorithm 4), having a running time of 𝑂 (|𝑢 | ·𝑇 (|𝑢 |, |D|, ∥C∥)), by the nextMove𝐿𝑅 function (Algorithm 7), having a running time of 𝑂 (𝑇 (|𝑢 |, |D|, ∥C∥)). Thus, the correctness and complexity are immediate by a similar analysis to that of the proof of Algorithm 3, concluding the proof of Theorem 5.2. □ F

Full Details for Section 6

In this section, we give full proofs for the hardness results of Section 6. Theorem 6.1. The matching problem with length constraints and {aa, 𝜀}-constraints is NP-complete. Proof. Let 𝐹 = {𝑐 1, 𝑐 2, . . . , 𝑐𝑚 } be a 3-CNF formula, where every conjunction 𝑐 𝑗 = {𝑙 𝑗,1, 𝑙 𝑗,2, 𝑙 𝑗,3 } ⊆ {𝑥 1, ¬𝑥 1, 𝑥 2, ¬𝑥 2, . . . , 𝑥𝑛 , ¬𝑥𝑛 } is a clause with three literals. We will construct an instance of the matching problem with length constraints and 𝐿-constraints as strings 𝑢, D ∈ Σ∗ and a set of b D, e with 𝑢b and D b intuitively describing a choice gap-constraints. We will define 𝑢 ≔ 𝑢b 𝑢e and D = D of Boolean values for each variable of {𝑥 1, . . . , 𝑥𝑛 } (each of them will formally be the concatenation e intuitively verifying the satisfaction of 𝑥𝑖 -assignment gadgets for each variable 𝑥𝑖 ); and with 𝑢e and D of each clause (each of them will formally be the concatenation of 𝑐 𝑗 -clause gadgets for each clause 𝑐 𝑗 ). We will explain how length constraints can be used to ensure that each assignment gadget in 𝑢b b and likewise for clause gadgets. is mapped in the corresponding assignment gadget in D, , Vol. 1, No. 1, Article . Publication date: June 2026.

Tractable Gap-Constraint Languages for Complex Event Recognition

41

The rest of the proof is structured as follows. First, we define assignment gadgets. Then, we define clause gadgets. Afterwards, we explain how length constraints allow us to synchronise the gadgets. Then, we explain how 𝐿-constraints are used to enforce the semantics of the clause gadgets; this finishes the definition of the instance of the matching problem that we are reducing to, i.e., concludes the presentation of the reduction. Finally, we show that the reduction is correct. We now go through these successive steps. Assignment gadgets. For every 𝑖 ∈ {1, 2, . . . , 𝑛}, the 𝑥𝑖 -assignment gadget is the following (where the 0’s and 1’s below correspond to an intuitive explanation given just below): 𝑢b𝑖 = b a a b b D𝑖 = b aa aa b 01 01 We interpret the first a of 𝑢b𝑖 to correspond to 𝑥𝑖 and the second a of 𝑢b𝑖 to correspond to ¬𝑥𝑖 . b𝑖 are interpreted as either 0 or 1 as illustrated above, which Furthermore, the occurrences of a of D indicate whether the literal mapped to this position is true or false. Consequently, embedding 𝑢b𝑖 b𝑖 can be interpreted as mapping 𝑥𝑖 to either 0 or 1 and mapping ¬𝑥𝑖 to either 0 or 1. By into D b𝑖 , then this can using gap-constraints, we want to enforce that whenever 𝑢b𝑖 is embedded into D only happen in one of the following two ways (where the 0’s and 1’s drawn below illustrate the intuitive intended semantics of the gadgets): b a a b b a a b b a a a a b b a a a a b or 0 1 0 1 0 1 0 1 The first embedding is interpreted as assigning 𝑥𝑖 to 1 (and accordingly assigning ¬𝑥𝑖 to 0), while the second one is interpreted as assigning 𝑥𝑖 to 0 (and accordingly assigning ¬𝑥𝑖 to 1). We enforce that the two embeddings depicted above are the only possible ones as follows. We use an 𝐿-constraint between the two a-occurrences in 𝑢b𝑖 , which excludes embeddings that would map both 𝑥𝑖 and ¬𝑥𝑖 to 0 or both 𝑥𝑖 and ¬𝑥𝑖 to 1. Then, in order to exclude embeddings that map b𝑖 or both a-occurrences of 𝑢b𝑖 to the both a-occurrences of 𝑢b𝑖 to the two leftmost a-occurrences of D b𝑖 , we use a [0, 1]-length constraint between the first b-occurrence two rightmost a-occurrences of D and the first a-occurrence in 𝑢b𝑖 and a [0, 1]-length constraint between the second a-occurrence and the second b-occurrence in 𝑢b𝑖 . It can be easily seen that these constraints are only satisfied by the two embeddings illustrated above. b=D b1 D b2 · · · D b𝑛 , and we note that if 𝑢b can be embedded into D, b We define 𝑢b = 𝑢b1𝑢b2 · · · 𝑢b𝑛 and D b𝑖 , which, as observed above, induces an assignment then this means that every 𝑢b𝑖 is embedded into D 𝜋 : {𝑥 1, 𝑥 2, . . . , 𝑥𝑛 } → {0, 1}. Clause gadgets. For every 𝑗 ∈ {1, 2, . . . , 𝑚}, the 𝑐 𝑗 -clause gadget is defined as follows: 𝐿1 𝑆 1 𝐿2 𝑆 2 𝐿∨ 𝐿3 𝑢e𝑗 = b a a a b a a a b e 𝑗 = b aa aaa aa b aaa aa aa b D 01 10 10 01 As shown in the alignment above, we mark the 6 occurrences of a in 𝑢e𝑗 with 𝐿1, 𝐿2, 𝐿3 (representing the three literals 𝑙 𝑗,1, 𝑙 𝑗,2 and 𝑙 𝑗,3 of clause 𝑐 𝑗 ), 𝐿∨ (representing the disjunction 𝑙 𝑗,1 ∨ 𝑙 𝑗,2 ), and 𝑆 1 and 𝑆 2 (used for auxiliary purposes). In particular, we can then talk about the 𝐿1 -a, 𝑆 1 -a, 𝐿2 -a, 𝑆 2 -a, e 𝑗 is the aa-factor aligned with 𝐿∨ -a and 𝐿3 -a of 𝑢e𝑗 . Moreover, for ℓ ∈ {1, 2, 3, ∨}, the 𝐿ℓ -a-block of D e 𝑗 is the the 𝐿ℓ -a (according to the alignment given above), and the 𝑆 1 -a-block and 𝑆 2 -a-block of D aaa-factor aligned with the 𝑆 1 -a and 𝑆 2 -a, respectively. , Vol. 1, No. 1, Article . Publication date: June 2026.

42

Antoine Amarilli, Florin Manea, Tina Ringleb, and Markus L. Schmid

e=D e1 D e2 · · · D e𝑚 , and finally 𝑢 = 𝑢b 𝑢e and D = D b D. e Due to the We define 𝑢e = 𝑢e1𝑢e2 · · · 𝑢e𝑚 and D b𝑖 and every 𝑢e𝑗 is occurrences of b, if 𝑢 can be embedded into D, then every 𝑢b𝑖 is embedded into D e𝑗 . embedded into D Synchronising the gadgets. In the following, we will add further gap-constraints that enforce that if 𝑢 can be embedded into D (such that all gap-constraints are satisfied), then the assignment 𝜋 induced by the embedding is satisfying, and if there is some satisfying assignment 𝜋, then 𝑢 can be embedded into D (such that all gap-constraints are satisfied). The first step is to achieve a synchronisation between the assignment gadgets and the clause gadgets: For every ℓ ∈ {1, 2, 3}, if 𝑙 𝑗,ℓ ∈ {𝑥𝑖 , ¬𝑥𝑖 }, then the 𝐿ℓ -a of 𝑢e𝑗 is synchronised with the 𝑥𝑖 -assignment gadget, i.e., if 𝑙 𝑗,ℓ = 𝑥𝑖 , then the 𝐿ℓ -a of 𝑢e𝑗 is mapped to 1 if and only if 𝑥𝑖 is assigned b𝑖 according to the first of the two possible to 1 (in the sense defined above, i.e., 𝑢b𝑖 is mapped to D embeddings), and if 𝑙 𝑗,ℓ = ¬𝑥𝑖 , then 𝐿ℓ -a is mapped to 1 if and only if ¬𝑥𝑖 is assigned to 1. We first define, for every 𝑖 ∈ {1, 2, . . . , 𝑛}, 𝑗 ∈ {1, 2, . . . , 𝑚} and ℓ ∈ {1, 2, 3}, the number 𝛼 (𝑖, 𝑗, ℓ) b𝑖 and the 𝐿ℓ -a-block of D e 𝑗 , and of symbols of D that lie strictly between the first a-occurrence of D let 𝛽 (𝑖, 𝑗, ℓ) denote the number of symbols of D that lie strictly between the third a-occurrence of b𝑖 and the 𝐿ℓ -a-block of D e 𝑗 . Obviously, these numbers 𝛼 (𝑖, 𝑗, ℓ) and 𝛽 (𝑖, 𝑗, ℓ) only depend on 𝑖, 𝑗 D and ℓ. For every 𝑗 ∈ {1, 2, . . . , 𝑚}, we add the following length constraints. If 𝑙 𝑗,1 = 𝑥𝑖 , then we add the length constraint (𝛼 (𝑖, 𝑗, 1), 𝛼 (𝑖, 𝑗, 1)) between the first a-occurrence of 𝑢b𝑖 and the 𝐿1 -a of 𝑢e𝑗 , and if 𝑙 𝑗,1 = ¬𝑥𝑖 , then we add the length constraint (𝛽 (𝑖, 𝑗, 1), 𝛽 (𝑖, 𝑗, 1)) between the second a-occurrence of 𝑢b𝑖 and the 𝐿1 -a of 𝑢e𝑗 . We proceed analogously with respect to the 𝐿3 -a: if 𝑙 𝑗,3 = 𝑥𝑖 , then we add the length constraint (𝛼 (𝑖, 𝑗, 3), 𝛼 (𝑖, 𝑗, 3)) between the first a-occurrence of 𝑢b𝑖 and the 𝐿3 -a of 𝑢e𝑗 , and if 𝑙 𝑗,3 = ¬𝑥𝑖 , then we add the length constraint (𝛽 (𝑖, 𝑗, 3), 𝛽 (𝑖, 𝑗, 3)) between the second a-occurrence of 𝑢b𝑖 and the 𝐿3 -a of 𝑢e𝑗 . With respect to the 𝐿2 -a, the situation is slightly different, e 𝑗 : if 𝑙 𝑗,2 = 𝑥𝑖 , then we add the length due to the swapped order of 0 and 1 in the 𝐿2 -a-block of D constraint (𝛽 (𝑖, 𝑗, 2), 𝛽 (𝑖, 𝑗, 2)) between the second a-occurrence of 𝑢b𝑖 and the 𝐿2 -a of 𝑢e𝑗 , and if 𝑙 𝑗,2 = ¬𝑥𝑖 , then we add the length constraint (𝛼 (𝑖, 𝑗, 2), 𝛼 (𝑖, 𝑗, 2)) between the first a-occurrence of 𝑢b𝑖 and the 𝐿2 -a of 𝑢e𝑗 . It can be easily seen that these length constraints enforce the desired synchronisation property, e.g., if 𝑙 𝑗,1 = 𝑥𝑖 and the first a-occurrence of 𝑢b𝑖 is mapped to 0, then due to the definition of 𝛼 (𝑖, 𝑗, 1), the 𝐿1 -a of 𝑢e𝑗 is also mapped to 0, and if instead the first a-occurrence of 𝑢b𝑖 is mapped to 1, then the 𝐿1 -a of 𝑢e𝑗 is also mapped to 1. This means that embedding 𝑢 into D induces an assignment 𝜋 such that 𝜋 (𝑙 𝑗,ℓ ) = 1 if and only if the 𝐿ℓ -a of 𝑢e𝑗 is mapped to 1. Enforcing clause satisfaction. Next, we have to introduce gap-constraints that enforce that 𝑢e𝑗 can e 𝑗 if and only if 𝜋 satisfies clause 𝑐 𝑗 . We start with gap-constraints that enforce be embedded into D that 𝜋 (𝑙 𝑗,1 ) ∨ 𝜋 (𝑙 𝑗,2 ) = 0 implies that the 𝑆 1 -a is necessarily mapped to the middle of the 𝑆 1 -a-block. This can be achieved by using a [0, 2]-length constraint between the 𝐿1 -a and the 𝑆 1 -a, and a [0, 2]-length constraint between the 𝑆 1 -a and the 𝐿2 -a. Now, if 𝜋 (𝑙 𝑗,1 ) ∨ 𝜋 (𝑙 𝑗,2 ) = 0, then the 𝐿1 -a is mapped to 0 and the 𝐿2 -a is mapped to 0, which means that mapping 𝑆 1 -a to the left or to the right of the 𝑆 1 -a-block would violate one of these [0, 2]-length constraints, while mapping the 𝑆 1 -a to the middle satisfies both these [0, 2]-length constraints. Moreover, we observe that we can still map 𝑆 1 -a in all other constellations, i.e., if 𝜋 (𝑙 𝑗,1 ) = 1 and 𝜋 (𝑙 𝑗,2 ) = 0, then the 𝑆 1 -a can be mapped to the right or to the middle of the 𝑆 1 -a-block, if 𝜋 (𝑙 𝑗,1 ) = 0 and 𝜋 (𝑙 𝑗,2 ) = 1, then the 𝑆 1 -a can be mapped to the left or to the middle of the 𝑆 1 -a-block, and if 𝜋 (𝑙 𝑗,1 ) = 𝜋 (𝑙 𝑗,2 ) = 1, then the 𝑆 1 -a can be mapped to the left or to the right or to the middle of the 𝑆 1 -a-block. In summary: if 𝜋 (𝑙 𝑗,1 ) ∨ 𝜋 (𝑙 𝑗,2 ) = 0, then 𝑆 1 -a must be mapped to the middle of the 𝑆 1 -a-block, and if 𝜋 (𝑙 𝑗,1 ) ∨ 𝜋 (𝑙 𝑗,2 ) = 1, then it is , Vol. 1, No. 1, Article . Publication date: June 2026.

Tractable Gap-Constraint Languages for Complex Event Recognition

43

possible that 𝑆 1 -a is not mapped to the middle of the 𝑆 1 -a-block (whether it is mapped to the left or right depends on the actual values of 𝜋 (𝑙 𝑗,1 ) and 𝜋 (𝑙 𝑗,2 )). We next synchronise the 𝑆 1 -a and the 𝑆 2 -a such that the 𝑆 1 -a is mapped to the left (middle, right) of the 𝑆 1 -a-block if and only if the 𝑆 2 -a is mapped to the left (middle, right) of the 𝑆 2 -a-block. This can be done by a [5, 5]-length constraint between the 𝑆 1 -a and the 𝑆 2 -a. In particular, this means that 𝜋 (𝑙 𝑗,1 ) ∨ 𝜋 (𝑙 𝑗,2 ) = 0 implies that the 𝑆 2 -a is necessarily mapped to the middle of the 𝑆 2 -a-block, and 𝜋 (𝑙 𝑗,1 ) ∨ 𝜋 (𝑙 𝑗,2 ) = 1 implies that it is possible to map 𝑆 2 -a not to the middle of the 𝑆 2 -a-block. We also want to achieve that if the 𝑆 2 -a is mapped to the left or to the right of the 𝑆 2 -a-block, then the 𝐿∨ -a is necessarily mapped to 1, and if the 𝑆 2 -a is mapped to the middle of the 𝑆 2 -a-block, then the 𝐿∨ -a is necessarily mapped to 0. To this end, we add a [3, 4]-length constraint between the second b in 𝑢e𝑗 and the 𝐿∨ -a, which means that the 𝐿∨ -a can only be mapped to the 𝐿∨ -a-block. Then, we add an 𝐿-constraint between the 𝑆 2 -a and 𝐿∨ -a, which means that if the 𝑆 2 -a is mapped to the left or to the right of the 𝑆 2 -a-block, then 𝐿∨ -a is necessarily mapped to 1, and if the 𝑆 2 -a is mapped to the middle of the 𝑆 2 -a-block, then 𝐿∨ -a is necessarily mapped to 0. Hence, if 𝜋 (𝑙 𝑗,1 ) ∨ 𝜋 (𝑙 𝑗,2 ) = 0, then 𝑆 2 -a is mapped to the middle of the 𝑆 2 -a-block and therefore 𝐿∨ -a is mapped to 0, and if 𝜋 (𝑙 𝑗,1 ) ∨ 𝜋 (𝑙 𝑗,2 ) = 1, then it is possible to map 𝑆 2 -a not to the middle of the 𝑆 2 -a-block and therefore 𝐿∨ -a can be mapped to 1. Finally we add a [1, 2]-length constraint for 𝐿∨ -a and 𝐿3 -a. This means that if 𝐿∨ -a is mapped to 0, then 𝐿3 -a must be mapped to 1, and if 𝐿∨ -a is mapped to 1, then 𝐿3 -a can be mapped to 0 or 1. This concludes the definition of the gap-constraints and therefore concludes the definition of the instance of the matching problem. Correctness proof. We now assume that there is a satisfying assignment 𝜋, i.e., 𝜋 (𝑙 𝑗,1 ) ∨ 𝜋 (𝑙 𝑗,2 ) ∨ 𝜋 (𝑙 𝑗,3 ) = 1 for every 𝑗 ∈ {1, 2, . . . , 𝑚}, and we will show that this implies that 𝑢 can be embedded b𝑖 as determined into D such that all gap-constraints are satisfied. First, we embed each 𝑢b𝑖 into D by 𝜋, i.e., if 𝜋 (𝑥𝑖 ) = 1, we use the first embedding mentioned above, and if 𝜋 (𝑥𝑖 ) = 0, we use the b second embedding mentioned above. This describes an embedding of 𝑢b in D. e we explain how we can embed 𝑢e𝑗 into D e 𝑗 . For every ℓ ∈ {1, 2, 3}, we map To embed 𝑢e into D, 𝐿ℓ -a to 1 if 𝜋 (𝑙 𝑗,ℓ ) = 1 and to 0 if 𝜋 (𝑙 𝑗,ℓ ) = 0 (this obviously satisfies all the gap-constraints between 𝑢e𝑗 and the corresponding assignment gadgets). If 𝜋 (𝑙 𝑗,1 ) ∨ 𝜋 (𝑙 𝑗,2 ) = 1, then, as observed above, we can map the 𝑆 1 -a to the left or to the right, depending on the actual values of 𝜋 (𝑙 𝑗,1 ) and 𝜋 (𝑙 𝑗,2 ). This means that we can map the 𝑆 2 -a to the left or to the right, and in both cases mapping 𝐿∨ -a to 1 satisfies the 𝐿-constraint between 𝑆 2 -a and 𝐿∨ -a. Furthermore, regardless of where 𝐿3 -a is mapped to, the [1, 2]-length constraint between 𝐿∨ -a and 𝐿3 -a is satisfied. Consequently, we have e 𝑗 that satisfies all gap-constraints. We have to consider the case that an embedding of 𝑢e𝑗 into D 𝜋 (𝑙 𝑗,1 ) ∨ 𝜋 (𝑙 𝑗,2 ) = 0, which means that 𝜋 (𝑙 𝑗,1 ) = 0 and 𝜋 (𝑙 𝑗,2 ) = 0. In this case, 𝑆 1 -a (and therefore 𝑆 2 -a) can only be mapped to the middle, which means that 𝐿∨ -a must be mapped to 0. However, since 𝜋 (𝑙 𝑗,1 ) ∨ 𝜋 (𝑙 𝑗,2 ) ∨ 𝜋 (𝑙 𝑗,3 ) = 1, we know that 𝜋 (𝑙 𝑗,3 ) = 1, which means that 𝐿3 -a is mapped to 1, which satisfies the [1, 2]-length constraint for 𝐿∨ -a and 𝐿3 -a. We conclude that also in this case, e 𝑗 that satisfies all gap-constraints. we have an embedding of 𝑢e𝑗 into D Assume now that we can embed 𝑢 into D such that all gap-constraints are satisfied, and let 𝜋 be b We know that, for every 𝑗 ∈ {1, 2, . . . , 𝑚}, 𝑢e𝑗 is the assignment induced by embedding 𝑢b into D. e 𝑗 such that all gap-constraints are satisfied. For the sake of a contradiction, let embedded into D us assume that 𝜋 (𝑙 𝑗,1 ) ∨ 𝜋 (𝑙 𝑗,2 ) ∨ 𝜋 (𝑙 𝑗,3 ) = 0, which means that 𝜋 (𝑙 𝑗,1 ) = 𝜋 (𝑙 𝑗,2 ) = 𝜋 (𝑙 𝑗,3 ) = 0. This implies that 𝐿1 -a and 𝐿2 -a are both mapped to 0, which means that 𝑆 1 -a (and therefore 𝑆 2 -a) is mapped to the middle, which means that 𝐿∨ -a is mapped to 0. Since 𝐿3 -a is also mapped to 0, the gap induced by 𝐿∨ -a and 𝐿3 -a has length 0, which violates the [1, 2]-length constraint for 𝐿∨ -a and 𝐿3 -a. , Vol. 1, No. 1, Article . Publication date: June 2026.

44

Antoine Amarilli, Florin Manea, Tina Ringleb, and Markus L. Schmid

e 𝑗 such that all gap-constraints This is a contradiction to our assumption that 𝑢e𝑗 is embedded into D are satisfied; thus, 𝜋 (𝑙 𝑗,1 ) ∨ 𝜋 (𝑙 𝑗,2 ) ∨ 𝜋 (𝑙 𝑗,3 ) = 0 is not possible. Hence, 𝜋 is satisfying. □ Theorem F.1. The matching problem with length constraints and {ab, 𝜀}-constraints is NP-complete. Proof. We use a similar reduction as for Theorem 6.1. Let 𝐹 = {𝑐 1, 𝑐 2, . . . , 𝑐𝑚 } be a 3-CNF formula, where every 𝑐 𝑗 = {𝑙 𝑗,1, 𝑙 𝑗,2, 𝑙 𝑗,3 } ⊆ {𝑥 1, ¬𝑥 1, 𝑥 2, ¬𝑥 2, . . . , 𝑥𝑛 , ¬𝑥𝑛 } is a clause with three literals. We first construct an instance over the alphabet {a, b, c} and then explain later how this can be adapted to the binary alphabet {a, b}. For every 𝑖 ∈ {1, 2, . . . , 𝑛}, the 𝑥𝑖 -assignment gadget is defined as follows: 𝑢b𝑖 = c a b c b𝑖 = c aa bb c D 01 01 We interpret the a of 𝑢b𝑖 to correspond to 𝑥𝑖 and the b of 𝑢b𝑖 to correspond to ¬𝑥𝑖 . Furthermore, b𝑖 are interpreted as either 0 or 1 as illustrated above. Consequently, the occurrences of a and b of D b embedding 𝑢b𝑖 into D𝑖 can be interpreted as mapping 𝑥𝑖 to either 0 or 1 and mapping ¬𝑥𝑖 to either 0 b𝑖 , then this or 1. By using gap-constraints, we want to enforce that whenever 𝑢b𝑖 is embedded into D can only happen in one of the following two ways: c a b c c a b c c a a b b c c a a b b c or 0 1 0 1 0 1 0 1 The first embedding is interpreted as assigning 𝑥𝑖 to 1 (and accordingly assigning ¬𝑥𝑖 to 0), while the second one is interpreted as assigning 𝑥𝑖 to 0 (and accordingly assigning ¬𝑥𝑖 to 1). We enforce that the two embeddings depicted above are the only possible ones as follows. We use an 𝐿-constraint between the a- and b-occurrence in 𝑢b𝑖 , which excludes embeddings that would map both 𝑥𝑖 and ¬𝑥𝑖 to 0 or both 𝑥𝑖 and ¬𝑥𝑖 to 1. It can be easily seen that this constraint is only satisfied by the two embeddings illustrated above. b=D b1 D b2 · · · D b𝑛 , and we note that if 𝑢b can be As for Theorem 6.1, we define 𝑢b = 𝑢b1𝑢b2 · · · 𝑢b𝑛 and D b b𝑖 , which, as observed above, embedded into D, then this means that every 𝑢b𝑖 is embedded into D induces an assignment 𝜋 : {𝑥 1, 𝑥 2, . . . , 𝑥𝑛 } → {0, 1}. For every 𝑗 ∈ {1, 2, . . . , 𝑚}, the 𝑐 𝑗 -clause gadget is defined as follows: 𝐿1 𝑆 1 𝐿2 𝐿∨ 𝐿3 𝑆2 𝑢e𝑗 c a a a a a ab c e 𝑗 c aa aaa aa aa aa abaabb c D 01 10 10 01 As shown in the alignment above, we mark 3 occurrences of a in 𝑢e𝑗 with 𝐿1, 𝐿2, 𝐿3 (representing the three literals 𝑙 𝑗,1, 𝑙 𝑗,2 and 𝑙 𝑗,3 of clause 𝑐 𝑗 ), one occurrence of a with 𝐿∨ (representing the disjunction 𝑙 𝑗,1 ∨ 𝑙 𝑗,2 ), one occurrence of a with 𝑆 1 and a factor ab with 𝑆 2 (used for auxiliary purposes). In particular, we can then talk about the 𝐿1 -a, 𝑆 1 -a, 𝐿2 -a, 𝐿∨ -a, 𝐿3 -a, 𝑆 2 -a and 𝑆 2 -b of 𝑢e𝑗 ; note that 𝑆 2 corresponds to two letters a and b, where the a has to occur before the b in the same block. e 𝑗 is the aa-factor aligned with the 𝐿ℓ -a (according Moreover, for ℓ ∈ {1, 2, 3, ∨}, the 𝐿ℓ -a-block of D e 𝑗 is the aaa-factor aligned with the 𝑆 1 -a. The to the alignment given above), and the 𝑆 1 -a-block of D e 𝑆 2 -a-block (and 𝑆 2 -b-block, respectively) of D 𝑗 is the aaa-subsequence (bbb-subsequence) of the abaabb-factor aligned with the 𝑆 2 -a (𝑆 2 -b). e=D e1 D e2 · · · D e𝑚 , and finally 𝑢 = 𝑢b 𝑢e and D = D b D. e Due to the We define 𝑢e = 𝑢e1𝑢e2 · · · 𝑢e𝑚 and D b𝑖 and every 𝑢e𝑗 is occurrences of c, if 𝑢 can be embedded into D, then every 𝑢b𝑖 is embedded into D e𝑗 . embedded into D , Vol. 1, No. 1, Article . Publication date: June 2026.

Tractable Gap-Constraint Languages for Complex Event Recognition

45

In the following, we will add further gap-constraints that enforce that if 𝑢 can be embedded into D (such that all gap-constraints are satisfied), then the assignment 𝜋 induced by the embedding is satisfying, and if there is some satisfying assignment 𝜋, then 𝑢 can be embedded into D (such that all gap-constraints are satisfied). The first step is to achieve a synchronisation between the assignment gadgets and the clause gadgets: For every ℓ ∈ {1, 2, 3}, if 𝑙 𝑗,ℓ ∈ {𝑥𝑖 , ¬𝑥𝑖 }, then the 𝐿ℓ -a of 𝑢e𝑗 is synchronised with the 𝑥𝑖 -assignment gadget, i.e., if 𝑙 𝑗,ℓ = 𝑥𝑖 , then the 𝐿ℓ -a of 𝑢e𝑗 is mapped to 1 if and only if 𝑥𝑖 is assigned b𝑖 according to the first of the two possible to 1 (in the sense defined above, i.e., 𝑢b𝑖 is mapped to D embeddings), and if 𝑙 𝑗,ℓ = ¬𝑥𝑖 , then 𝐿ℓ -a is mapped to 1 if and only if ¬𝑥𝑖 is assigned to 1. We first define, for every 𝑖 ∈ {1, 2, . . . , 𝑛}, 𝑗 ∈ {1, 2, . . . , 𝑚} and ℓ ∈ {1, 2, 3}, the number 𝛼 (𝑖, 𝑗, ℓ) b𝑖 and the 𝐿ℓ -a-block of D e 𝑗 , and of symbols of D that lie strictly between the first a-occurrence of D b𝑖 let 𝛽 (𝑖, 𝑗, ℓ) denote the number of symbols of D that lie strictly between the first b-occurrence of D e 𝑗 . Obviously, these numbers 𝛼 (𝑖, 𝑗, ℓ) and 𝛽 (𝑖, 𝑗, ℓ) only depend on 𝑖, 𝑗 and ℓ. and the 𝐿ℓ -a-block of D For every 𝑗 ∈ {1, 2, . . . , 𝑚}, we add the following length constraints. If 𝑙 𝑗,1 = 𝑥𝑖 , then we add an [𝛼 (𝑖, 𝑗, 1), 𝛼 (𝑖, 𝑗, 1)]-length constraint between the a-occurrence of 𝑢b𝑖 and the 𝐿1 -a of 𝑢e𝑗 , and if 𝑙 𝑗,1 = ¬𝑥𝑖 , then we add a [𝛽 (𝑖, 𝑗, 1), 𝛽 (𝑖, 𝑗, 1)]-length constraint between the b-occurrence of 𝑢b𝑖 and the 𝐿1 -a of 𝑢e𝑗 . We proceed analogously with respect to the 𝐿3 -a: if 𝑙 𝑗,3 = 𝑥𝑖 , then we add an [𝛼 (𝑖, 𝑗, 3), 𝛼 (𝑖, 𝑗, 3)]-length constraint between the a-occurrence of 𝑢b𝑖 and the 𝐿3 -a of 𝑢e𝑗 , and if 𝑙 𝑗,3 = ¬𝑥𝑖 , then we add a [𝛽 (𝑖, 𝑗, 3), 𝛽 (𝑖, 𝑗, 3)]-length constraint between the b-occurrence of 𝑢b𝑖 and the 𝐿3 -a of 𝑢e𝑗 . With respect to the 𝐿2 -a, the situation is slightly different, due to the swapped e 𝑗 : if 𝑙 𝑗,2 = 𝑥𝑖 , then we add a [𝛽 (𝑖, 𝑗, 2), 𝛽 (𝑖, 𝑗, 2)]-length order of 0 and 1 in the 𝐿2 -a-block of D constraint between the b-occurrence of 𝑢b𝑖 and the 𝐿2 -a of 𝑢e𝑗 , and if 𝑙 𝑗,2 = ¬𝑥𝑖 , then we add an [𝛼 (𝑖, 𝑗, 2), 𝛼 (𝑖, 𝑗, 2)]-length constraint between the a-occurrence of 𝑢b𝑖 and the 𝐿2 -a of 𝑢e𝑗 . It can be easily seen that these length constraints enforce the desired synchronisation property, e.g., if 𝑙 𝑗,1 = 𝑥𝑖 and the a-occurrence of 𝑢b𝑖 is mapped to 0, then due to the definition of 𝛼 (𝑖, 𝑗, 1), the 𝐿1 -a of 𝑢e𝑗 is also mapped to 0, and if instead the a-occurrence of 𝑢b𝑖 is mapped to 1, then the 𝐿1 -a of 𝑢e𝑗 is also mapped to 1. This means that embedding 𝑢 into D induces an assignment 𝜋 such that 𝜋 (𝑙 𝑗,ℓ ) = 1 if and only if the 𝐿ℓ -a of 𝑢e𝑗 is mapped to 1. e𝑗 , In order to enforce that each position of 𝑢e𝑗 can only be mapped to its corresponding block in D we also add gap-constraints between the first c of 𝑢e𝑗 and all other positions of 𝑢e𝑗 , e.g. we add a [0, 1]-length constraint between the first c and the 𝐿1 -a, and an [11, 16]-length constraint from the first c to both 𝑆 2 -a and 𝑆 2 -b. e 𝑗 if and Next, we have to introduce gap-constraints that enforce that 𝑢e𝑗 can be embedded into D only if 𝜋 satisfies clause 𝑐 𝑗 . We start with gap-constraints that enforce that 𝜋 (𝑙 𝑗,1 ) ∨ 𝜋 (𝑙 𝑗,2 ) = 0 implies that 𝑆 1 -a is necessarily mapped to the middle of the 𝑆 1 -a-block. This can be achieved by using a [0, 2]-length constraint between the 𝐿1 -a and the 𝑆 1 -a, and a [0, 2]-length constraint between the 𝑆 1 -a and the 𝐿2 -a. Now, if 𝜋 (𝑙 𝑗,1 ) ∨ 𝜋 (𝑙 𝑗,2 ) = 0, then 𝐿1 -a is mapped to 0 and 𝐿2 -a is mapped to 0, which means that mapping 𝑆 1 -a to the left or to the right of the 𝑆 1 -a-block would violate one of these [0, 2]-length constraints, while mapping 𝑆 1 -a to the middle satisfies both these [0, 2]-length constraints. Moreover, we observe that we can still map 𝑆 1 -a in all other constellations, i.e., if 𝜋 (𝑙 𝑗,1 ) = 1 and 𝜋 (𝑙 𝑗,2 ) = 0, then the 𝑆 1 -a can be mapped to the right or to the middle of the 𝑆 1 -a-block, if 𝜋 (𝑙 𝑗,1 ) = 0 and 𝜋 (𝑙 𝑗,2 ) = 1, then the 𝑆 1 -a can be mapped to the left or to the middle of the 𝑆 1 -a-block, and if 𝜋 (𝑙 𝑗,1 ) = 𝜋 (𝑙 𝑗,2 ) = 1, then the 𝑆 1 -a can be mapped to the left or to the right or to the middle of the 𝑆 1 -a-block. In summary: if 𝜋 (𝑙 𝑗,1 ) ∨ 𝜋 (𝑙 𝑗,2 ) = 0, then 𝑆 1 -a must be mapped to the middle of the 𝑆 1 -a-block, and if 𝜋 (𝑙 𝑗,1 ) ∨ 𝜋 (𝑙 𝑗,2 ) = 1, then it is possible that 𝑆 1 -a is not mapped to the middle of the 𝑆 1 -a-block (whether it is mapped to the left or right depends on the actual values of 𝜋 (𝑙 𝑗,1 ) and 𝜋 (𝑙 𝑗,2 )). , Vol. 1, No. 1, Article . Publication date: June 2026.

46

Antoine Amarilli, Florin Manea, Tina Ringleb, and Markus L. Schmid

We synchronise 𝑆 1 -a and 𝑆 2 -a such that 𝑆 2 -a can be mapped to the left (right) of the 𝑆 2 -a-block if and only if 𝑆 1 -a is mapped to the left (right) of the 𝑆 1 -a-block and 𝑆 2 -a is mapped to the middle of the 𝑆 2 -a-block if 𝑆 1 -a is mapped to the middle of the 𝑆 1 -a-block. This can be done by an [8, 9]-length constraint between 𝑆 1 -a and 𝑆 2 -a, which enforces the following: • If 𝑆 1 -a is mapped to the left of the 𝑆 1 -a-block, then 𝑆 2 -a can only be mapped to the left of the 𝑆 2 -a-block, • if 𝑆 1 -a is mapped to the middle of the 𝑆 1 -a-block, then 𝑆 2 -a can only be mapped to the middle of the 𝑆 2 -a-block, and • if 𝑆 1 -a is mapped to the right of the 𝑆 1 -a-block, then 𝑆 2 -a can be mapped to the middle or the right of the 𝑆 2 -a-block. In particular, this means that 𝜋 (𝑙 𝑗,1 ) ∨ 𝜋 (𝑙 𝑗,2 ) = 0 implies that 𝑆 2 -a is necessarily mapped to the middle of the 𝑆 2 -a-block. In order to map the three values of the 𝑆 2 -a-block to two positions, we need to permute its values. To this end, we add an 𝐿-constraint between 𝑆 2 -a and 𝑆 2 -b: • If 𝑆 2 -a is mapped to the left of the 𝑆 2 -a-block, 𝑆 2 -b can only be mapped to the left of the 𝑆 2 -b-block, • if 𝑆 2 -a is mapped to the middle of the 𝑆 2 -a-block, 𝑆 2 -b can only be mapped to the right of the 𝑆 2 -b-block, and • if 𝑆 2 -a is mapped to the right of the 𝑆 2 -a-block, 𝑆 2 -b can only be mapped to the middle of the 𝑆 2 -b-block. Thus, 𝜋 (𝑙 𝑗,1 ) ∨ 𝜋 (𝑙 𝑗,2 ) = 0 implies that 𝑆 2 -b has to be mapped to the right of the 𝑆 2 -b-block. Using an additional [3, 7]-length constraint between the 𝑆 2 -b and the 𝐿∨ -a (note that we utilise gapconstraints to the first c to guarantee that the 𝐿∨ -a is mapped to the 𝐿∨ -a-block), we can therefore enforce that if 𝑆 2 -b is mapped to the right of the 𝑆 2 -b-block, then the 𝐿∨ -a can only be mapped to the right of the 𝐿∨ -a-block. Otherwise, if 𝑆 2 -b is mapped to the left or the middle of the 𝑆 2 -b-block, then the 𝐿∨ -a can be mapped to either position of the 𝐿∨ -a-block. In particular, if 𝜋 (𝑙 𝑗,1 ) ∨𝜋 (𝑙 𝑗,2 ) = 0 then the 𝐿∨ -a can only be mapped to the right of the 𝐿∨ -a-block and if 𝜋 (𝑙 𝑗,1 ) ∨ 𝜋 (𝑙 𝑗,2 ) = 1 then there is an embedding such that the 𝐿∨ -a is mapped to the left of the 𝐿∨ -a-block. Finally, we add a [1, 2]-length constraint between the 𝐿∨ -a and the 𝐿3 -a. This means that if 𝐿∨ -a is mapped to the right of the 𝐿∨ -a-block (corresponding to value 0), then the 𝐿3 -a must be mapped to 1 (i.e., to the right of the 𝐿3 -a-block), and if the 𝐿∨ -a is mapped to the left of the 𝐿∨ -a-block (corresponding to 1), then the 𝐿3 -a can be mapped to 0 or 1. This concludes the definition of the gap-constraints and therefore concludes the definition of the instance of the matching problem. We now assume that there is a satisfying assignment 𝜋, i.e., 𝜋 (𝑙 𝑗,1 ) ∨ 𝜋 (𝑙 𝑗,2 ) ∨ 𝜋 (𝑙 𝑗,3 ) = 1 for every 𝑗 ∈ {1, 2, . . . , 𝑚}, and we will show that this implies that 𝑢 can be embedded into D such that all b𝑖 as determined by 𝜋, i.e., if 𝜋 (𝑥𝑖 ) = 1, gap-constraints are satisfied. First, we embed each 𝑢b𝑖 into D we use the first embedding mentioned above, and if 𝜋 (𝑥𝑖 ) = 0, we use the second embedding b mentioned above. This describes an embedding of 𝑢b in D. e we explain how we can embed 𝑢e𝑗 into D e 𝑗 . For every ℓ ∈ {1, 2, 3}, we For embedding 𝑢e into D, map the 𝐿ℓ -a to 1 if 𝜋 (𝑙 𝑗,ℓ ) = 1 and to 0 if 𝜋 (𝑙 𝑗,ℓ ) = 0 (this obviously satisfies all the gap-constraints between 𝑢e𝑗 and the corresponding assignment gadgets). If 𝜋 (𝑙 𝑗,1 ) ∨ 𝜋 (𝑙 𝑗,2 ) = 1, then, as observed above, we can map 𝑆 1 -a to the left or to the right, depending on the actual values of 𝜋 (𝑙 𝑗,1 ) and 𝜋 (𝑙 𝑗,2 ). This means that we can map 𝑆 2 -a to the left or to the right, and therefore the 𝑆 2 -b can be mapped to the left or the middle. In both cases, mapping the 𝐿∨ -a to 1 (i.e., the left) satisfies the length constraint between the 𝑆 2 -b and the 𝐿∨ -a. Furthermore, regardless of where the 𝐿3 -a is mapped to, the [1, 2]-length constraint between the 𝐿∨ -a and the 𝐿3 -a is satisfied. Consequently,

, Vol. 1, No. 1, Article . Publication date: June 2026.

Tractable Gap-Constraint Languages for Complex Event Recognition

47

e 𝑗 that satisfies all gap-constraints. We have to consider the case we have an embedding of 𝑢e𝑗 into D that 𝜋 (𝑙 𝑗,1 ) ∨ 𝜋 (𝑙 𝑗,2 ) = 0, which means that 𝜋 (𝑙 𝑗,1 ) = 0 and 𝜋 (𝑙 𝑗,2 ) = 0. In this case, the 𝑆 1 -a (and therefore the 𝑆 2 -a) can only be mapped to the middle, which means that the 𝑆 2 -b has to be mapped to the right and further, the 𝐿∨ -a must be mapped to 0. However, since 𝜋 (𝑙 𝑗,1 ) ∨ 𝜋 (𝑙 𝑗,2 ) ∨ 𝜋 (𝑙 𝑗,3 ) = 1, we know that 𝜋 (𝑙 𝑗,3 ) = 1, which means that the 𝐿3 -a is mapped to 1, which satisfies the [1, 2]-length constraint for 𝐿∨ -a and 𝐿3 -a. We conclude that also in this case, we have an embedding of 𝑢e𝑗 into e 𝑗 that satisfies all gap-constraints. D Assume now that we can embed 𝑢 into D such that all gap-constraints are satisfied, and let 𝜋 be b We know that, for every 𝑗 ∈ {1, 2, . . . , 𝑚}, 𝑢e𝑗 is the assignment induced by embedding 𝑢b into D. e embedded into D 𝑗 such that all gap-constraints are satisfied. For the sake of a contradiction, let us assume that 𝜋 (𝑙 𝑗,1 ) ∨ 𝜋 (𝑙 𝑗,2 ) ∨ 𝜋 (𝑙 𝑗,3 ) = 0, which means that 𝜋 (𝑙 𝑗,1 ) = 𝜋 (𝑙 𝑗,2 ) = 𝜋 (𝑙 𝑗,3 ) = 0. This implies that the 𝐿1 -a and the 𝐿2 -a are both mapped to 0, which means that 𝑆 1 -a (and therefore 𝑆 2 -a) is mapped to the middle and 𝑆 2 -b is mapped to the right, which means that the 𝐿∨ -a is mapped to 0. Since the 𝐿3 -a is also mapped to 0, the gap induced by the 𝐿∨ -a and the 𝐿3 -a has length 0, which violates the [1, 2]-length constraint for the 𝐿∨ -a and the 𝐿3 -a. This is a contradiction e 𝑗 such that all gap-constraints are satisfied; thus, to our assumption that 𝑢e𝑗 is embedded into D 𝜋 (𝑙 𝑗,1 ) ∨ 𝜋 (𝑙 𝑗,2 ) ∨ 𝜋 (𝑙 𝑗,3 ) = 0 is not possible. Hence, 𝜋 is satisfying. It now only remains to adjust the reduction above to only require a binary alphabet Σ = {a, b}. We will only discuss the necessary adjustments. For every 𝑖 ∈ [𝑛], the 𝑥𝑖 -assignment gadget is defined as: 𝑢b𝑖 = a b b𝑖 = aa bb D 01 01 b=D b1 D b2 · · · D b𝑛 , and we note that if 𝑢b can be Like defined above, we define 𝑢b = 𝑢b1𝑢b2 · · · 𝑢b𝑛 and D b b𝑖 , which, as observed above, embedded into D, then this means that every 𝑢b𝑖 is embedded into D induces an assignment 𝜋 : {𝑥 1, 𝑥 2, . . . , 𝑥𝑛 } → {0, 1}. Further, for every 𝑗 ∈ [𝑚], the 𝑐 𝑗 -clause gadget is defined as: 𝐿1 𝑆 1 𝐿2 𝐿∨ 𝐿3 𝑆2 𝑢e𝑗 a a a a a ab e 𝑗 aa aaa aa aa aa abaabb D 01 10 10 01 Note that the assignment (resp., clause) gadgets directly correspond to the assignment (resp., clause) gadgets as used above, but without the occurrences of letter c. Again, we define 𝑢e = e=D e1 D e2 · · · D e𝑚 . Now, let 𝑢 = bb b Db. e We will add a [|D| − 2, |D| − 2]𝑢e1𝑢e2 · · · 𝑢e𝑚 and D 𝑢 𝑢eb and D = bD gap-constraint between the first and last letter (i.e., the b before 𝑢b and the b after 𝑢e) of 𝑢, where |D| = 4𝑛 + 17𝑚 + 2. Thus, we force every satisfying embedding to contain the first and last position of D, which fixes the position of the first and last letter of 𝑢. Using these two fixed letters, we can now use length constraints to guarantee that every position of 𝑢 can only be mapped to its corresponding block in D. E.g. we add a [4𝑛 − 2, 4𝑛 − 1]-constraint between the first b of 𝑢 and the b-occurrence of the 𝑥𝑛 -assignment gadget, which enforces that 𝑢b b These constraints also enforce that 𝑢e𝑗 is embedded in D e 𝑗 for all 𝑗 ∈ [𝑚] has to be embedded in D. and that every position is embedded in its corresponding block. This process works analogously to the length constraints for the occurrences of c used in the construction above. The rest of the proof is now identical to the case discussed above for alphabet {a, b, c}. □ Theorem F.2. The matching problem where every gap-constraint is left-convex or right-convex is NP-complete. , Vol. 1, No. 1, Article . Publication date: June 2026.

48

Antoine Amarilli, Florin Manea, Tina Ringleb, and Markus L. Schmid

Proof. The language {ab, a, 𝜀} is left-convex (but not right-convex) and {ab, b, 𝜀} is right-convex (but not left-convex), but their intersection {ab, a, 𝜀} ∩ {ab, b, 𝜀} = {ab, 𝜀} is the language that we used in Theorem F.1 in addition to length constraints. (Note that this language is neither left-convex nor right-convex.) Consequently, we can prove the theorem by the same reduction that we used for the proof of Theorem F.1, but each constraint (𝑖, 𝑗, {ab, 𝜀}) is replaced by the two left- respectively right-convex constraints (𝑖, 𝑗, {ab, a, 𝜀}) and (𝑖, 𝑗, {ab, b, 𝜀}). □ Theorem F.3. There is a fixed regular language 𝐿 such that the matching problem with 𝐿-constraints is NP-complete. Proof. We use a similar reduction as for Theorem 6.1. Let 𝐹 = {𝑐 1, 𝑐 2, . . . , 𝑐𝑚 } be a 3-CNF formula, where every 𝑐 𝑗 = {𝑙 𝑗,1, 𝑙 𝑗,2, 𝑙 𝑗,3 } ⊆ {𝑥 1, ¬𝑥 1, 𝑥 2, ¬𝑥 2, . . . , 𝑥𝑛 , ¬𝑥𝑛 } is a clause with three literals. For convenience, we first define a reduction to the matching problem with different constraint languages. Later on, we will explain why this is indeed a reduction to the matching problem with 𝐿-constraints for a fixed language 𝐿. For every 𝑖 ∈ {1, 2, . . . , 𝑛}, the 𝑥𝑖 -assignment gadget is defined as: 𝑢b𝑖 = b a bbbb a b b𝑖 = b aa bbbb aa b D 01 01 Let 𝐿0 = {bbbb, abbbba}. We add an 𝐿0 -constraint between the two a-occurrences of 𝑢b𝑖 , which b𝑖 corresponds to assigning 𝑥𝑖 means that, just like in the proof of Theorem 6.1, embedding 𝑢b𝑖 into D to 1 and ¬𝑥𝑖 to 0, or the other way around. For every 𝑗 ∈ {1, 2, . . . , 𝑚}, the 𝑐 𝑗 -clause gadget is defined as: 𝐿1 𝑆1 𝐿2 𝑆2 𝐿∨ 𝐿3 𝑢e𝑗 = b a b a bb a b a bbb a bbbbb a b e 𝑗 = b aa b aaa bb aa b aaa bbb aa bbbbb aa b D 01 10 10 01 We use the same terminology of the proof of Theorem 6.1 to talk about the 𝐿1 -a, 𝐿2 -a and so e 𝑗 . Again, we set 𝑢b = 𝑢b1𝑢b2 · · · 𝑢b𝑛 , D b=D b1 D b2 · · · D b𝑛 , on, and about the corresponding a-blocks in D 7 7 e e e e b e 𝑢e = 𝑢e1𝑢e2 · · · 𝑢e𝑚 , D = D1 D2 · · · D𝑚 , but we define 𝑢 = 𝑢b b 𝑢e and D = D b D. b𝑖 | = 10 and | D e 𝑗 | = 28 for every 𝑖 ∈ {1, 2, . . . , 𝑛} and 𝑗 ∈ {1, 2, . . . , 𝑚}. We observe that | D b𝑖 and Note that for every 𝑖 ∈ {1, 2, . . . , 𝑛}, 𝑗 ∈ {1, 2, . . . , 𝑚}, the factor of D strictly between D e 𝑗 is D b𝑖+1 · · · D b𝑛 b7 D e1 · · · D e 𝑗 −1 . This means that the factors of D that strictly lie between the first D b𝑖 and the 𝐿1 -a-block, the 𝐿2 -a-block, and the 𝐿3 -a-block of the D e 𝑗 are a-occurrence of D 4 7 b𝑖+1 · · · D b𝑛 b D e1 · · · D e 𝑗 −1 b, • ab aab D 4 7 b b e e 𝑗 −1 baaba3 bb, and • ab aab D𝑖+1 · · · D𝑛 b D1 · · · D 4 7 b b e e 𝑗 −1 baaba3 bbaaba3 b3 aab5 , respectively. • ab aab D𝑖+1 · · · D𝑛 b D1 · · · D For convenience, for every 𝑝, 𝑞 ∈ N ∪ {0}, we define 𝛼 (𝑝, 𝑞, 1) ≔ 16 + 10𝑝 + 28𝑞, 𝛼 (𝑝, 𝑞, 2) ≔ 24 + 10𝑝 + 28𝑞 and 𝛼 (𝑝, 𝑞, 3) ≔ 40 + 10𝑝 + 28𝑞. From the considerations from above it follows that, for every 𝑖 ∈ {1, 2, . . . , 𝑛}, 𝑗 ∈ {1, 2, . . . , 𝑚} and ℓ ∈ {1, 2, 3}, there are exactly 𝛼 (𝑛 − 𝑖, 𝑗 − 1, ℓ) b𝑖 and the 𝐿ℓ -a-block of D e 𝑗 . Moreover, symbols that lie strictly between the first a-occurrence of D with 𝛽 (𝑝, 𝑞, ℓ) = 𝛼 (𝑝, 𝑞, ℓ) − 6 for every 𝑝, 𝑞 ∈ N ∪ {0} and ℓ ∈ {1, 2, 3}, we have that there are b𝑖 and the exactly 𝛽 (𝑛 − 𝑖, 𝑗 − 1, ℓ) symbols that lie strictly between the third a-occurrence of D e 𝑗 . In order to verify this, just observe that 𝛼 (𝑛 − 𝑖, 𝑗 − 1, 1), 𝛼 (𝑛 − 𝑖, 𝑗 − 1, 2), and 𝐿ℓ -a-block of D 𝛼 (𝑛 −𝑖, 𝑗 − 1, 3) are exactly the lengths of the factors displayed above (and an analogous explanation applies to 𝛽 (𝑛 − 𝑖, 𝑗 − 1, 1), 𝛽 (𝑛 − 𝑖, 𝑗 − 1, 2), and 𝛽 (𝑛 − 𝑖, 𝑗 − 1, 3) just with the prefix ab4 aab of the above factors replaced by ab). , Vol. 1, No. 1, Article . Publication date: June 2026.

Tractable Gap-Constraint Languages for Complex Event Recognition

49

We also define 𝐿𝛼 (𝑝,𝑞,ℓ ) as the language of strings over {a, b} of size 𝛼 (𝑝, 𝑞, ℓ) and 𝐿𝛽 (𝑝,𝑞,ℓ ) as the language of strings over {a, b} of size 𝛽 (𝑝, 𝑞, ℓ). We can now achieve the synchronisation between the assignment gadgets and the clause gadgets in the same way as in the proof of Theorem 6.1, but instead of a length constraint [𝛼 (𝑛 − 𝑖, 𝑗 − 1, ℓ), 𝛼 (𝑛 −𝑖, 𝑗 −1, ℓ)] or [𝛽 (𝑛 −𝑖, 𝑗 −1, ℓ), 𝛽 (𝑛 −𝑖, 𝑗 −1, ℓ)], we use the constraint language 𝐿𝛼 (𝑛−𝑖,𝑗 −1,ℓ ) or 𝐿𝛽 (𝑛−𝑖,𝑗 −1,ℓ ) , respectively. Finally, we use gap-constraints in order to make the clause gadgets work, i.e., we want to enforce the following properties: e𝑗 . • Every a of 𝑢e𝑗 is mapped to its corresponding a-block of D • If 𝐿1 -a is mapped to the left and 𝐿2 -a is mapped to the left, then 𝑆 1 -a can be mapped to the left or middle. • If 𝐿1 -a is mapped to the right and 𝐿2 -a is mapped to the left, then 𝑆 1 -a can be mapped to the left, middle or right. • If 𝐿1 -a is mapped to the right and 𝐿2 -a is mapped to the right, then 𝑆 1 -a can be mapped to the right or middle. • If 𝐿1 -a is mapped to the left and 𝐿2 -a is mapped to the right, then 𝑆 1 -a can only be mapped to the middle. • 𝑆 1 -a is mapped to the left (middle, right) if and only if 𝑆 2 -a is mapped to the left (middle, right). • If 𝑆 2 -a is mapped to the left or to the right, then 𝐿∨ -a is mapped to 1, and if 𝑆 2 -a is mapped to the middle, then 𝐿∨ -a is mapped to 0. • If 𝐿∨ -a is mapped to 1, then 𝐿3 -a can be mapped to 0 or to 1, and if 𝐿∨ -a is mapped to 0, then 𝐿3 -a must be mapped to 1. We can achieve this by defining the following gap-constraints: • We use 𝐿𝐶,1 = {b, ba, baa, ab, aba} as constraint language between 𝐿1 -a and 𝑆 1 -a. • We use 𝐿𝐶,2 = {bb, bba, abb, aabb, abba} as constraint language between 𝐿2 -a and 𝑆 1 -a. • We use 𝐿𝐶,3 = {aabbaab, abbaaba, bbaabaa} as constraint language between 𝑆 1 -a and 𝑆 2 -a. • We use 𝐿𝐶,4 = {aabbb, bbb, abbba} as constraint language between 𝑆 2 -a and 𝐿∨ -a. • We use 𝐿𝐶,5 = {bbbbba, abbbbb, abbbbba} as constraint language between 𝐿∨ -a and 𝐿3 -a. In order to see this, it is sufficient to observe that the allowed gap-strings of the languages above are exactly chosen such that the desired properties are enforced. The correctness of the reduction follows in the same way as in the proof of Theorem 6.1. It remains to show how this reduction can be changed into a reduction that only uses 𝐿-constraints for a fixed language 𝐿 (i.e., a language independent of the actual instance of the Boolean satisfiability problem). We first observe that the languages 𝐿0 , 𝐿𝐶,1 , 𝐿𝐶,2 , 𝐿𝐶,3 , 𝐿𝐶,4 and 𝐿𝐶,5 are pairwise disjoint. Moreover, if we use a constraint language 𝐿 ∈ {𝐿0, 𝐿𝐶,1, 𝐿𝐶,2, 𝐿𝐶,3, 𝐿𝐶,4, 𝐿𝐶,5 } for any two positions 𝑖 and 𝑗 of 𝑢, then 𝑖 and 𝑗 will be necessarily embedded such that in between their images 𝑒 (𝑖) and 𝑒 ( 𝑗) in D no string from (𝐿0 ∪ 𝐿𝐶,1 ∪ 𝐿𝐶,2 ∪ 𝐿𝐶,3 ∪ 𝐿𝐶,4 ∪ 𝐿𝐶,5 ) \ 𝐿 can occur. This is directly implied by the fact that in between 𝑒 (𝑖) and 𝑒 ( 𝑗) there is either exactly one occurrence of b, or exactly one occurrence of factor bb, or exactly one occurrence of a factor of the form bba+ b, or exactly one occurrence of a factor bbb, or exactly one occurrence of a factor bbbbb. Consequently, we can define 𝐾 ≔ 𝐿0 ∪ 𝐿𝐶,1 ∪ 𝐿𝐶,2 ∪ 𝐿𝐶,3 ∪ 𝐿𝐶,4 ∪ 𝐿𝐶,5 and simply use 𝐾 as constraint language whenever we have used one of 𝐿0 , 𝐿𝐶,1 , 𝐿𝐶,2 , 𝐿𝐶,3 , 𝐿𝐶,4 or 𝐿𝐶,5 . Let 𝑢 be embedded into D by some embedding (not necessarily satisfying any gap-constraints), and let the first a of some 𝑢b𝑖 be mapped to position 𝑝 of D and let 𝐿ℓ -a of some 𝑢e𝑗 be mapped to position 𝑞 of D. Then (𝑞 − 𝑝 − 1) ∈ {𝛼 (𝑛 − 𝑖, 𝑗 − 1, ℓ) − 1, 𝛼 (𝑛 − 𝑖, 𝑗 − 1, ℓ), 𝛼 (𝑛 − 𝑖, 𝑗 − 1, ℓ) + 1} (note

, Vol. 1, No. 1, Article . Publication date: June 2026.

50

Antoine Amarilli, Florin Manea, Tina Ringleb, and Markus L. Schmid

that 𝑞 − 𝑝 − 1 is the number of symbols strictly between positions 𝑞 and 𝑝 of D, i.e., the number of symbols strictly between the positions where we mapped the mentioned a-occurrences of 𝑢). Similarly, if the second a of some 𝑢b𝑖 is mapped to position 𝑝 of D and 𝐿ℓ -a of some 𝑢e𝑗 is mapped to position 𝑞 of D, then (𝑞 − 𝑝 − 1) ∈ {𝛽 (𝑛 − 𝑖, 𝑗 − 1, ℓ) − 1, 𝛽 (𝑛 − 𝑖, 𝑗 − 1, ℓ), 𝛽 (𝑛 − 𝑖, 𝑗 − 1, ℓ) + 1}. This is a consequence of the fact that any embedding that embeds 𝑢 in D must map each b-occurrence of 𝑢 to the corresponding b-occurrence of D. For every 𝑛, 𝑚 ∈ N, 𝑖 ∈ {1, 2, . . . , 𝑛}, 𝑗 ∈ {1, 2, . . . , 𝑚} and ℓ ∈ {1, 2, 3}, the numbers 𝛼 (𝑛−𝑖, 𝑗 −1, ℓ) and 𝛽 (𝑛 −𝑖, 𝑗 − 1, ℓ) are even, which means that the numbers 𝛼 (𝑛 −𝑖, 𝑗 − 1, ℓ) − 1, 𝛼 (𝑛 −𝑖, 𝑗 − 1, ℓ) + 1, 𝛽 (𝑛 − 𝑖, 𝑗 − 1, ℓ) − 1, 𝛽 (𝑛 − 𝑖, 𝑗 − 1, ℓ) + 1 (which are odd numbers) do not appear in the set {𝛼 (𝑛 − 𝑖, 𝑗 − 1, ℓ), 𝛽 (𝑛 − 𝑖, 𝑗 − 1, ℓ) | 𝑛, 𝑚 ∈ N, 𝑖 ∈ {1, 2, . . . , 𝑛}, 𝑗 ∈ {1, 2, . . . , 𝑚}, ℓ ∈ {1, 2, 3}}. Hence, we can define Ø 𝐿𝑠 ≔ (𝐿𝛼 (𝑛−𝑖,𝑗 −1,ℓ ) ∪ 𝐿𝛽 (𝑛−𝑖,𝑗 −1,ℓ ) ) 𝑛,𝑚∈N,𝑖 ∈ {1,...,𝑛},𝑗 ∈ {1,...,𝑚},ℓ ∈ {1,2,3}

and simply replace every constraint language 𝐿𝛼 (𝑛−𝑖,𝑗 −1,ℓ ) or 𝐿𝛽 (𝑛−𝑖,𝑗 −1,ℓ ) by 𝐿𝑠 . Note that 𝐿𝑠 is a regular language. It is important that 𝐿𝑠 caters for every possible choice of 𝑛 and 𝑚, since we need a single fixed constraint language that works for any possible SAT-instance (i.e., we can have an arbitrary number 𝑛 of variables and an arbitrary number 𝑚 of clauses). This is correct, since in any embedding of 𝑢 in D (where 𝑢 and D result from some arbitrary SAT-instance) the distance b𝑖 and the 𝐿ℓ -a-block of some D e 𝑗 is 𝛼 (𝑛 − 𝑖, 𝑗 − 1, ℓ) − 1, between the first a-occurrence of some D 𝛼 (𝑛−𝑖, 𝑗 −1, ℓ) or 𝛼 (𝑛−𝑖, 𝑗 −1, ℓ)+1, but only 𝐿𝛼 (𝑛−𝑖,𝑗 −1,ℓ ) is contained in 𝐿𝑠 , while both 𝐿𝛼 (𝑛−𝑖,𝑗 −1,ℓ ) −1 b𝑖 and the and 𝐿𝛼 (𝑛−𝑖,𝑗 −1,ℓ )+1 are disjoint from 𝐿𝑠 (and analogously for the third a-occurrence of D 𝛽-numbers). Consequently, for those pairs of positions of 𝑢 where we use the constraint language 𝐿𝛼 (𝑛−𝑖,𝑗 −1,ℓ ) (or 𝐿𝛽 (𝑛−𝑖,𝑗 −1,ℓ ) ), using 𝐿𝑠 instead has the exact same effect. Finally, we note that 𝐿𝑠 ∩ 𝐾 = ∅, since the longest strings of 𝐾 have length 7, while the smallest strings of 𝐿𝑠 have length 𝛽 (0, 0, 1) = 10. Hence, we can replace every constraint language by the constraint language 𝐿 ≔ 𝐿𝑠 ∪ 𝐾. It is obvious that 𝐿 is a regular language. □

, Vol. 1, No. 1, Article . Publication date: June 2026.

Related documents

Record · ID 287203 · SHA-256 c34ee048f2dc074c
Retrieved via Conceptio — every document is proof-bundled with source, license, and retrieval metadata.