Iovka Boneva

Joachim Niehren

Momar Sakho

Certain Query Answering on Compressed String Patterns: From Streams to Hyperstreams

We study the problem of certain query answering (Cqa) on compressed string patterns. These are incomplete singleton context-free grammars, that can model systems of multiple streams with references to others, called hyperstreams more recently. In order to capture regular path queries on strings, we consider nondeterministic finite automata (Nfas) for query definition. It turns out that Cqa for Boolean Nfa queries is equivalent to regular string pattern inclusion, i.e., whether all strings completing a compressed string pattern belong to a regular language. We prove that Cqa on compressed string patterns is PSpacecomplete for Nfa queries. The PSpace-hardness even applies to Boolean queries defined by deterministic finite automata (Dfas) and without compression. We also show that Cqa on compressed linear string patterns can be solved in PTime for Dfa queries.

Introduction

A stream is a sequence of events that arrive incrementally one by one from the left to the right. Most typically, streams are produced by social networks such as Twitter, database systems as for producing financial transactions, information systems, sensor systems, or more generally when communicating semi-structured data over the internet. We are interested in the problem of monitoring streams in a reactive manner [START_REF] Mozafari | High-performance complex event processing over XML streams[END_REF][START_REF] Kay | A streaming XSLT processor[END_REF][START_REF] Schmidt | Combined static and dynamic analysis for effective buffer minimization in streaming XQuery evaluation[END_REF][START_REF] Olteanu | SPEX: Streamed and progressive evaluation of XPath[END_REF]. The objective is to select the relevant events of a stream as quickly as possible upon their arrival. This requires to decide whether an event of the stream is a certain answer of the logical query that defines the relevant events of the monitoring task. Lowering the latency of this decision process increases the reactivity of the stream processing system and reduces its memory costs. A limitation to constant memory may seem ideal in theory, but is too restrictive for many monitoring tasks in practice. A less restrictive objective is thus to minimize the latency and thereby to reduce the memory consumption.

In the present paper we study a generalization of streams to multiple streams with references as introduced by Maneth, Pereira and Seidl [START_REF] Maneth | Transforming XML streams with references[END_REF]. The references point to unknown parts in the middle of a stream. The same reference may be used multiple times, allowing to share unknown parts. Streams with similar references were named hyperstreams in own previous work [START_REF] Labath | A functional language for hyperstreaming XSLT[END_REF]. Here, we propose to formalize hyperstream containing words (rather than linearizations of trees or nested words) as incomplete versions of singleton context-free grammars [START_REF] Plandowski | The complexity of the morphism equivalence problem for contextfree languages[END_REF] (also termed straight line programs [START_REF] Babai | On the complexity of matrix group problems i[END_REF]), where the rules of some nonterminals may be missing. The hyperstream G 1 = (Σ, N, R, S) is illustrated graphically in Fig. 1. It has the terminals in Σ = {a, b, c}, the nonterminals in N = {S, X, Y, Z}, the set R with the rules S → aXbbY aX and X → Y cZa, and the start symbol S. The nonterminals are called the references of the hyperstream. For some of these references there exists a rule in the grammar, and if so, this rule is unique. For any grammar rule, the reference on its left is said to refer to the string pattern on its right. The hyperstream G 1 has a rule for S and X, while it misses those of Y and Z. The missing rules for these references may be added in the future one by one by the hyperstream's environment. Alternatively, hyperstreams can be identified with compressed string patterns. The hyperstream G 1 for instance represents the string pattern p 1 = aYcZabbYaYcZa, while sharing the underlined factors substituted for the two occurrences of X. Streams are a special case of string patterns that have a unique occurrence of a variable in their last position. The landscape from streams to hyperstreams, over linear string patterns, string patterns, and compressed string patterns is illustrated in Fig. 2.

In this paper, we study the decision problem of certain query answering (Cqa) on compressed string patterns, i.e., whether a tuple of positions is a certain answer of a query on a compressed string pattern. Here we consider the positions of the string pattern after decompression rather than the positions of the grammar. Intuitively, a tuple of positions is a certain query answer on a compressed string pattern G if it is an answer to the query on all completions of G, up to the offsets raised by the completion of G on its decompression. We will also consider the symmetric problem for certain query non-answers.

Motivated by regular path queries [START_REF] Angles | Foundations of modern graph query languages[END_REF], we consider nondeterministic finite automata (Nfas) for defining such queries. For instance, the query Q 1 on strings over Σ = {a, b, c} that selects all a-positions that are followed eventually by bb can be defined by the following regular path in XPath-like notation: It can also be defined by the x-pointed regular expression Σ * a x Σ * bbΣ * where x is a variable for the position that is to be selected. Now, consider the case, where the string is not given explicitly but only described partially by some (compressed) string pattern. On the string pattern p 1 , for instance, the a-positions 1 and 5 are certain query answers for Q 1 , while the a-positions 9 and 13 are not. The position 13 is even a certain non-answer.

Q 1 =
When restricted to Boolean Nfa queries, Cqa becomes equivalent to the problem of whether all strings described by the completions of a compressed string pattern are accepted by the Nfa. For the string pattern Y (for some variable Y ), this problem clearly generalizes on the universality problem of Nfas, which is well-known to be PSpace-complete [START_REF] Kozen | Lower bounds for natural proof systems[END_REF]. The following questions, however, are open to the best of our knowledge, even in the case of string patterns without compression: Is Cqa on (compressed) string patterns decidable for Nfadefined queries, and if yes, what is the complexity? Does Cqa on (compressed) string patterns remain hard for queries defined by deterministic finite automata (Dfas)? For which restrictions of (compressed) string patterns is Cqa in PTime? And what about the symmetric questions concerning certain query non-answers? The objective of the present paper is to answer these questions in all possible cases.

Our first contribution is that Cqa on string patterns is PSpace-complete, both for Nfa queries and Dfa queries, with and without compression, Boolean or not, see Fig. 3. This upper bound is not fully obvious, as the set of strings defined by a string pattern may be non-regular and even non-context-free. Furthermore, the lower bound may be surprising in that Cqa for Dfa queries on string patterns is more complex than on streams, where it is in PTime (Theorem 1 of [START_REF] Gauwin | Earliest Query Answering for Deterministic Nested Word Automata[END_REF]), and also more complex than string pattern matching, which is np-complete (Theorem 3.6 of [START_REF] Angluin | Finding patterns common to a set of strings[END_REF]) even with compression (Theorem 4.10 of [START_REF] Gascón | Context matching for compressed terms[END_REF]).

Our second contribution is that Cqa for Dfa queries can be decided in PTime on compressed linear string patterns, see Fig. 4. The linearity restriction matches with the worst case complexity for streams, even though linear compressed string patterns allow for unknown factors and compression in addition. This result (Corollary 2) is based on a novel algorithm for partial decompression of compressed string patterns that we present (Lemma 6), followed by a test of a reachability property (Theorem 3).

Our third contribution is that the certainty of query non-answers on compressed string patterns is PSpace-complete, both for Boolean and non-Boolean queries, and independently of whether they are defined by Dfas or Nfas. In the Boolean case, the problem is equivalent to whether a compressed string pattern does not match the regular language accepted by the automaton. This problem

Dfas Nfas Answers

PSpace-c PSpace-c Non-answers PSpace-c PSpace-c Fig. 3: Query certainty on (compressed) string patterns or hyperstreams.

Dfas Nfas Answers

PTime PSpace-c Non-answers PTime PTime generalizes on the complement of compressed string pattern matching, and thus is coNP-hard. So while certain query non-answering can be solved in PTime on streams, the complexity increases to PSpace on compressed string patterns. Finally, we show that the restriction of the problem to compressed linear string patterns -that is, regular compressed linear string pattern matching -can also be solved in PTime even for queries defined by Nfas.

Outline. In Section 2 we start with some preliminaries on finite automata theory. Section 3 recalls the notion of compressed string patterns and in Section 4 we study the problems of regular compressed pattern inclusion and matching. Section 5 recalls how to define non-Boolean queries on strings by automata. In Sections 6 and 7 we generalize the notions of certain query answers and nonanswers to (compressed) string patterns and study their complexity. All omitted proofs can be found in the long online version3 . Related Work. The notion of certain query answers for incomplete relational structures is standard in databases research [START_REF] David | Certain answers for XML queries[END_REF]. In the context of stream processing, certain query answers were called answers that are safe for selection and certain query non-answers were called safe for rejection [START_REF] Gauwin | Streamable fragments of forward XPath[END_REF]. Certain query non-answers were studied for fast failure [START_REF] Benedikt | Stream Firewalling of XML Constraints[END_REF] and for reducing the memory consumption of streaming systems. The problem of certain query answering and non-answering on streams has been shown to be computationally hard even for queries defined in tiny fragments of first-order logic [START_REF] Gauwin | Streamable fragments of forward XPath[END_REF]. Certain query nonanswering was shown to be hard in the context of online verification [START_REF] Benedikt | Stream Firewalling of XML Constraints[END_REF][START_REF] Kupferman | Model checking of safety properties[END_REF].

As shown by [START_REF] Gauwin | Streamable fragments of forward XPath[END_REF], those classes of queries on strings for which the problem of certain query answering on streams is known to be feasible, are either such that certainty is always determined with 0-delay [START_REF] Mozafari | High-performance complex event processing over XML streams[END_REF][START_REF] Benedikt | Stream Firewalling of XML Constraints[END_REF][START_REF] Gauwin | Queries on XML streams with bounded delay and concurrency[END_REF]) or such that the queries in the class can be compiled to Dfas in PTime.

Algorithms for processing Xml streams or complex event streams raised much interest in the literature [START_REF] Kay | A streaming XSLT processor[END_REF][START_REF] Schmidt | Combined static and dynamic analysis for effective buffer minimization in streaming XQuery evaluation[END_REF][START_REF] Green | Processing XML streams with deterministic automata and stream indexes[END_REF] and motivated the work on hyperstreams. Xml streams contain nested words [START_REF] Mozafari | High-performance complex event processing over XML streams[END_REF][START_REF] Kumar | Visibly pushdown automata for streaming XML[END_REF] rather than strings without bracket structure. The best existing algorithms for answering navigational XPath queries (i.e. first-order logic queries) on Xml streams are based on compilation to nested word automata [START_REF] Debarbieux | Early nested word automata for xpath query answering on XML streams[END_REF][START_REF] Olteanu | SPEX: Streamed and progressive evaluation of XPath[END_REF]. Low but not lowest latency is achieved with high efficiency by approximating certain answers for queries defined by nondeterministic nested word automata.

Preliminaries

Words. The set of natural numbers with 0 is denoted by N. For any set Σ, a word over Σ is a tuple (a 1 , . . . , a n ) ∈ Σ n where n ∈ N. We denote such words by a 1 . . . a n and by ε if n = 0. We denote the i th letter of a word u = a 1 ...a n by u[i] = def a i . The set of all words over Σ is denoted by Σ * . The concatenation of two words

u 1 , u 2 ∈ Σ * is denoted by u 1 •u 2 ∈ Σ * . For instance, if Σ = {a, b} then aba • a = abaa. The set of positions of a word u = a 1 . . . a n is pos(u) = {1, . . . , n}.
For any subset Σ ⊆ Σ the set pos Σ (u) is the subset of positions i of u such that a i ∈ Σ . Given a word w = a 1 . . . a n and a second word u = b 1 . . . b n of the same length possibly on a different alphabet, we define the zipped word over the product alphabet by w * u = (a 1 , b 1 ) . . . (a n , b n ). As a convention throughout the paper, we use the term string for words over the default alphabet Σ, as opposed to words over other alphabets such as Σ ∪ Y for string patterns, and Σ V for V-annotated strings, that will be introduced later on.

Monoids. A monoid is a triple (M, • M , 1 M ) where M is a set, • M : M × M → M is an associative binary operation and 1 M ∈ M is the neutral element, i.e. 1 M • M m = m • M 1 M = m for all m ∈ M . Given a word u = m 1 . . . m n ∈ M * we define its evaluation by u M = m 1 • M . . . • M m n where ε M = 1 M .
Most typically, we will consider the monoid of words (Σ * , •, ε) on some alphabet Σ, with the concatenation operation • : Σ * × Σ * → Σ * , and the empty word ε as neutral element. Alternatively, given another set Q, we will consider the transition monoid (T Q , •, id ), where T Q = 2 Q×Q is the set of binary relations over Q, • : T Q × T Q → T Q is the composition operation of binary relations on Q, and id = {(q, q) | q ∈ Q} is the identity transition. Finite Automata. A nondeterministic finite-state automaton (Nfa) is a tuple A = (Q, Σ, δ, I, F ) where Q and Σ are finite sets, δ ⊆ Q × Σ × Q, and I, F ⊆ Q. We call Q the state set, Σ the alphabet, δ the transition relation, I the set of initial states, and F the set of final states of the automaton. An Nfa A is deterministic, or a Dfa, if it has exactly one initial state and the transition relation δ forms a partial function from Q × Σ to Q. The elements of T Q are called the transitions of A. Any transition relation δ : Q×Σ ×Q can be extended homomorphically to a transition function δ : Σ * → T Q that assigns to any string a transition of A. Here we overload the symbol δ to stand for the transition relation and the transition function. The transition δ(a) of a letter a ∈ Σ is {(q, q ) | (q, a, q ) ∈ δ} and the transition δ(w) of a string w = a 1 . . . a n ∈ Σ * is δ(w) = (δ(a 1 ) . . . δ(a n )) T Q . This is the composition of the transitions of all letters of w based on the operations of the transition monoid T Q , and its neutral element for the empty word. Note that if A is a Dfa then all transitions δ(w)

are partial functions. A transition τ is called I,F -successful if τ ∩ (I × F ) = ∅. The language of an Nfa A = (Q, Σ, δ, I, F ) is the set L(A) = {w ∈ Σ * | δ(w) is I,F -successful}. The size of an automaton is |A| = |Q| + |δ|.
Example 1. Nfas can be used to define Boolean queries on strings such as query Q 2 which tests whether some position will be selected by query Q 1 , i.e., whether a string contains an a-letter followed eventually by a factor bb. The language of all such strings is defined by the automaton on Fig. 5.

A transition τ is called δ-inhabited if there exists a word w ∈ Σ * such that δ(w) = τ . Transition inhabitation Inh Σ is the decision problem that receives as input a finite set Q, a transition relation δ ⊆ Q × Σ × Q and a transition τ ∈ T Q , and outputs whether τ is δ-inhabited. Inh Σ is also called the membership problem of the transition monoid δ(Σ * ) ⊆ T Q [START_REF] Blondin | The complexity of intersecting finite automata having few final states[END_REF].

Theorem 1 (Kozen [START_REF] Kozen | Lower bounds for natural proof systems[END_REF]). For any set Σ with at least 2 elements, the transition inhabitation problem Inh Σ is PSpace-complete.

The PSpace hardness proof can be done by reduction from the problem of non-emptiness of the intersection of sequences of Dfas, which was shown to be PSpace-complete in [START_REF] Kozen | Lower bounds for natural proof systems[END_REF] too.

Compressed String Patterns

We fix an infinite set Y of string variables for the rest of the paper. A string pattern over a finite alphabet Σ is a word in (Σ ∪ Y) * . The set of all string patterns over Σ is denoted by Pat Σ . The set of variables that occur in a string pattern p is denoted by fv(p). An instance of a string pattern p ∈ Pat Σ is a string that can be obtained by substituting the variables of p by strings in Σ * . Any substitution σ : Y → Σ * can be lifted to a substitution on string patterns σ : Pat Σ → Σ * such that for all p, p ∈ Pat Σ , a ∈ Σ, and Y ∈ Y: σ(pp ) = σ(p) • σ(p ), σ(ε) = ε, σ(a) = a, and σ(Y ) = σ(Y ). We define the set of instances of a string pattern p ∈ Pat Σ as:

Inst(p) = {σ(p) | σ : Y → Σ * }.
For example, the string acbcbabbcba is an instance of the pattern aY cZabbY a, obtained with the substitution [Y /cb, Z/b]. A string pattern is called linear, if all its variables occur at most once. The set of all linear string patterns over Σ is denoted LinPat Σ .

Definition 1 (Compressed string pattern). A compressed string pattern is an acyclic CFG G = (N, Σ, R, S) where N ⊆ Y is a finite set of nonterminals, Σ is an alphabet of terminal symbols disjoint from Y, the ruling function R is a partial function that maps some of the nonterminals in N to string patterns in (N ∪ Σ) * , and S ∈ N is the start symbol. The set of all compressed string patterns over Σ is denoted by cPat Σ .

We recall that a CFG G is acyclic if the binary relation

> G = {(Y, Z) | Y ∈ dom(R), Z ∈ fv(R(Y ))
} is acyclic. The compressed string pattern from the introduction for instance has the rules R(S) = aXbbY aX, R(X) = Y cZa. These rules induce the binary relation

{(S, X), (S, Y ), (X, Y ), (X, Z)} which is acyclic. The size of G is |G| = |N | + Y ∈dom(R) |R(Y )|. The set of free variables of G is fv(G) = N \ dom(R).
A compressed string pattern G is called a singleton context-free grammar (sCFG) if it has no free variables, that is fv(G) = ∅. It is well-known that any sCFG defines a single string in Σ * . The object of interest here is the set of strings that can be obtained by completing a compressed string pattern G to a sCFG, or equivalently, the set of instances of the string pattern of G defined as follows. For any compressed string pattern G = (N, Σ, R, S), the grammar G = (N \fv(G), Σ∪fv(G), R, S) is a sCFG. We define the string pattern pat(G) ∈ Pat Σ∪fv(G) as the unique word in the language of G . Formally, for every

Y ∈ dom(R), let G Y be the compressed string pattern G Y = (N, Σ, R, Y ). If S ∈ dom(R) then pat(G) = σ(R(S)) where σ(Y ) = pat(G Y ) for all Y ∈ dom(R) \ {S}. This recursive definition is well-founded because G is an acyclic CFG. Otherwise, if S ∈ fv(G), then pat(G) = S. For instance, if G 1 is the hyperstream from the introduction, then pat(G 1 ) = p 1 .
A compressed string pattern G is called a compressed linear string pattern if pat(G) is linear. The set of all compressed linear string patterns over Σ is denoted cLinPat Σ . Finally for any string pattern p ∈ Pat Σ there exists a compressed string pattern G p having p as pattern, namely G p = ({S} ∪ fv(p), Σ, R, S) with dom(R) = {S} and R(S) = p. Clearly pat(G p ) = p. Therefore we will identify p with G p , so that Pat Σ ⊆ cPat Σ .

Regular Pattern Inclusion and Matching

We consider the problems of regular compressed pattern inclusion, i.e. testing whether all strings described by a completion of a compressed string pattern to a sCFG are accepted by a finite automaton, and of regular compressed pattern matching, whether some string described by a completion of a compressed string pattern is accepted by a finite automaton.

A class of compressed string patterns G is a function from finite sets Σ to subsets G Σ ⊆ cPat Σ such as for instance G ∈ {Pat, cPat, LinPat, cLinPat}. A class of Nfas A is a function from finite sets Σ to subsets A Σ ⊆ Nfa Σ , where Nfa Σ is the set of Nfas with alphabet Σ. Most typically, A ∈ {Dfa, Nfa}. For any class G of compressed string patterns, any class A of Nfas, and any finite set Σ we define the following two decision problems. i.e., the instance set of pat(G 1 ) is included in the language of Nfa A 2 in Fig. 5.

Regular compressed pattern inclusion

Let sDfa be the subclass of Dfas that recognize a singleton language. Note that the well-known problem of string pattern matching is Match Σ (Pat, sDfa), and Match Σ (cPat, sDfa) is its extension with compression. We recall from [START_REF] Gascón | Context matching for compressed terms[END_REF] that string pattern matching with and without compression respectively are npcomplete for all alphabets Σ with at least 2 letters, but in PTime when restricted to linear string patterns even with compression.

Our first main contribution is the following complexity result for regular compressed pattern matching and inclusion (see Fig. 3).

Theorem 2 (Non-linear patterns). For any G ∈ {Pat, cPat} and A ∈ {Dfa, Nfa} and for any finite alphabet Σ with at least 2 letters, the problems of regular compressed pattern inclusion Incl Σ (G, A) and matching Match Σ (G, A) are PSpace-complete. This shows that these problems are decidable even though the instance sets of nonlinear patterns like Inst(Y Y Y ) are neither regular nor context-free. The theorem also shows that regular pattern matching Match Σ (Pat, Dfa) is PSpace-complete and thus harder than compressed string pattern matching Match Σ (Pat, sDfa) which is np-complete.

Proof. We will present a sequence of PSpace reductions from Lemma 1 until Lemma 4 that imply the theorem when composed as in Fig. 6.

For two decision problems A and B, we write A = p B when A reduces polynomially to B and B reduces polynomially to A.

Lemma 1. Incl Σ (LinPat, Nfa) is PSpace-hard if |Σ| ≥ 2.
The proof is straightforward by reduction from the universality of Nfas.

We now show the PSpace upper bound for Incl Σ (cPat, Nfa). For any transition relation δ ⊆ Q × Σ × Q and any substitution into the transition monoid σ : Y → T Q , we define δ σ to be the function that takes a string pattern in Pat Σ as input, and returns a transition, such that for all p, p ∈ Pat Σ , w ∈ Σ * , and Y ∈ Y: Proof. Given an Nfa A, a compressed string pattern G over Σ, we have to check whether Inst(pat(G)) ⊆ L(A). By definition, this is equivalent to checking whether δ(ŝ(pat(G))) is I,F -successful for every substitution s : fv(G) → Σ * . The latter is equivalent to checking whether δ σ (pat(G)) is I,F -successful for all substitution σ : fv(G) → T Q that maps the free variables of G to δinhabited transitions. A decision procedure can thus enumerate all substitutions σ : fv(G) → T Q to δ-inhabited transitions, compute δ σ (pat(G)) and check whether it is I,F -successful. The number of substitutions σ that is to be checked is exponential, but they can be enumerated in PSpace. Whether σ maps only to δ-inhabited transition can be tested in PSpace by Theorem 1. Computing δ σ (pat(G)) can be done in PTime by Lemma 2.

δ σ (w) = δ(w), δ σ (y) = σ(y), δ σ (pp ) = δ σ (p) • δ σ (p ).
So far we have shown that Incl Σ (cPat, Nfa) is PSpace-complete. We next consider regular matching. This will permit us to show that Incl Σ (cPat, Dfa) is PSpace-hard too.

Proposition 2. Match Σ (cPat, Nfa) is in PSpace.
The proof is analogous to that of Proposition 1, except that it is now sufficient to guess some substitution to δ-inhabited transition.

Proposition 3. Match Σ (Pat, Dfa) is PSpace-hard.
The proof is by reduction from the non-emptiness problem of the intersection of a sequence of n Dfas A 1 , . . . , A n over Σ by matching the non-linear string pattern y# . . . #y of length n against a Dfa A over

Σ {#} recognizing L(A) = L(A 1 )# . . . #L(A n ). Lemma 3. The problem coMatch Σ (Pat, Dfa) is PSpace-complete.
In order to complete the proof of Theorem 2 it remains to relate regular inclusion and matching in the case of Dfas. Proof. This follows from Inst(pat(G)) ∩ L(A) = ∅ ⇔ Inst(pat(G)) ⊆ L(A) and the fact that any Dfa A can be complemented in PTime to some Dfa A such that L(A) = L(A).

The complexity of inclusion and matching decreases for linear string patterns, with or without compression. We indeed obtain the same complexity as known for streams (see Fig. 4), even though unknown factors and compression are permitted in addition.

Theorem 3 (Linear patterns). Restricted to linear string patterns, regular compressed pattern inclusion and matching have the following complexities:

1. Incl Σ (LinPat, Nfa) and Incl Σ (cLinPat, Nfa) are PSpace-complete if |Σ| ≥ 2 while the problem Incl Σ (cLinPat, Dfa) can be solved in PTime.

Match

Σ (cLinPat, Nfa) is in PTime.
For any linear compressed string pattern G there exist a Dfa of that recognizes Inst(pat(G)), but this Dfa may be of exponential size in |G| due to compression. Instead, the PTime proof for Incl Σ (cLinPat, Dfa) relies on an evaluator of compressed string patterns in the transition monoid, that replaces free variables by the accessibility transition of the Dfa, thereby testing a reachability property.

Defining Queries by Automata

We now recall the notion of queries on strings over some alphabet Σ with variables in some finite set V and relate them to languages of V-annotated strings called V-structures in [START_REF] Straubing | Finite Automata, Formal Logic, and Circuit Complexity[END_REF]. We fix two disjoint finite sets Σ and V. Definition 2 (Query). A query with variables in V on strings over Σ, or a Σ,V-query for short, is a function Q that maps any string w ∈ Σ * to a set Q(w) of total assignments from V to pos(w). A Boolean query is a Σ,∅-query.

Example 3. Let V = {x, x }. The query Q 1 selects all pairs of letters (x, x ) such that position x is labeled by a, position x immediately follows x and is labeled by b. This query then satisfies

Q 1 (aa) = ∅, Q 1 (ab) = {[x/1, x /2]}, Q 1 (abab) = {[x/1, x /2], [x/3, x /4]}, etc.
We next show how a Σ,V-query can be identified with a language of Vannotated strings, i.e., of words over the alphabet Σ V = Σ × 2 V . A (query variable) assignment α to positions of a string w ∈ Σ * is a partial function from V to pos(w). We will identify such variable assignments with words whose letters are sets of variables. For any partial function α from V to pos(w) where w ∈ Σ n , we define a corresponding word in (2 V ) n by word (α) = α -1 (1) . . . α -1 (n). That is, word (α)[i] is the set of variables x ∈ dom(α) s.t. α(x) = i. Furthermore, for any string w ∈ Σ * and variable assignment α into positions of w, we define the V-annotated string w * α as a word over Σ V by w * α = w * word (α). In examples we will write a V instead of letters (a, V ) ∈ Σ V . For instance, ab * [x/1, x /2] is written as a {x} b {x } . Definition 3 (V-structure [START_REF] Straubing | Finite Automata, Formal Logic, and Circuit Complexity[END_REF]). The set of V-structures over Σ is the following set of V-annotated strings, i.e., of words over Σ V :

Struct V = {w * α ∈ (Σ V ) * | w ∈ Σ * , α : V → pos(w)}.
We note that all the assignments α in the definition of V-structures are total functions. For instance for V = {x, x } and Σ = {a, b}, the words a ∅ b {x ,x} and a {x } b {x} are V-structures while the words a ∅ b {x } and a {x } b {x ,x} are not. Essentially, V-structures represent total variable assignments to the positions of a string without naming the positions.

Definition 4 (Language of V-structures of a query). For any Σ,V-query

Q, the language of V-structures of Q is L(Q) = {w * α | w ∈ Σ * , α ∈ Q(w)}.
We will be interested in queries whose languages are definable by Nfas.

Definition 5 (Query automata). An Σ,V-query automaton is an Nfa A such that L(A) is a language of V-structures over Σ. The unique Σ,V-query such that L(Q) = L(A) is called the query defined by A and is denoted by Q(A) = Q.

Certain Query Answers and Non-Answers

We next formalize the notions of certain query answers and non-answers on string patterns. For streams, these definitions coincide with the notions of earliest query answers from [START_REF] Gauwin | Streamable fragments of forward XPath[END_REF] and fast-failure from [START_REF] Benedikt | Stream Firewalling of XML Constraints[END_REF], respectively.

A Σ-assignment for V on p ∈ Pat Σ is a partial function α from V to pos Σ (p), the Σ-positions of the pattern p. For any Σ-assignment α on p, the word p * α is a string pattern over Σ V , still with string variables in Y. Therefore, the set Inst(p * α) is a well-defined set of words over Σ V . Note, however, that some of these V-annotated strings may not be V-structures. For instance, if x ∈ V, a ∈ Σ, and Y ∈ Y, then a {x} a {x} ∈ Inst(Y * []) is not a V-structure since x occurs twice (where [] is the empty Σ-assignment).

Definition 6 (Certain query answers and non-answers). Let Q be a Σ,Vquery, and let p ∈ Pat Σ be a string pattern. A Σ-assignment α for V on p is:

a certain answer for query Q on p if α is total and Inst(p * α) ∩ Struct V ⊆ L(Q), and a certain non-answer for query

Q on p if Inst(p * α) ∩ L(Q) = ∅.
Given an instance w ∈ Inst(p), each Σ-assignment α on p defines a set of total Σ-assignments on w, where all variables not in dom(α) must be mapped to some Σ-positions "created" by the instantiation. More formally:

C p,w (α) = {α | α is a total Σ-assignment on w, w * α ∈ Inst(p * α)}.
The offsets of positions of query variables due to the instantiation of pattern variables raise two issues that we illustrate in the following example: 1. even a total Σ-assignment α of p might have several completions for the same string w, and 2. it might be the case that α ∈ C p,w (α).

Example 4. Consider the string pattern p = ay 1 ay 2 , the string w = aaba in Inst(p), V = {x}, and the total Σ-assignment α = [x/3] on p. In order to make p match w, the second a-letter of p matches either the second or the fourth position in w. Therefore, there are exactly two substitutions that make p match w, which are σ 1 = [y 1 /ε, y 2 /ba] and σ

2 = [y 1 /ab, y 2 /ε]. Now, σ1 (p * α) = σ1 (ay 1 a {x} y 2 ) = aa {x} ba = w * [x/2], thus [x/2] ∈ C p,w (α). Also, σ2 (p * α) = σ1 (ay 1 a {x} y 2 ) = aaba {x} = w * [x/4], thus [x/4] ∈ C p,w (
α). Given that there is no further way to match p with w, there is no further completion. That is, C p,w (α) = {[x/2], [x/4]}, and α ∈ C p,w (α).

The next proposition relates certain query answers (resp. non-answers) on a pattern p to query answers (resp. non-answers) on its instances. Proposition 4. Let α be a Σ-assignment on string pattern p and Q be a Σ,Vquery. It then holds for all instances w ∈ Inst(p):

-If α is a certain answer for query Q on p then C p,w (α) ⊆ Q(w).

-If α is a certain non-answer for query Q on p then C p,w (α) ∩ Q(w) = ∅.

Certain Query Answering and Non-Answering

We introduce the problems of certain query answering and non-answering for classes of compressed string patterns G and of query Nfas A:

Certain query answering Cert ans Σ,V (G, A). Input: a compressed string pattern G ∈ G Σ , a Σ-assignment α for V on pat(G), and a query Nfa A ∈ A Σ V . Output: whether α is a certain answer for query Q(A) on pat(G). Certain query non-answering Cert ¬ans Σ,V (G, A). Input: as above Output: whether α is a certain non-answer for query Q(A) on pat(G).

Note that α is an assignment to positions of pat(G) and not to positions of G. This is necessary because due to compression, a position of G might correspond to several positions of the underlying word which need to be distinguished. Indeed, considering G to be the compressed string pattern in the introduction, the a-letter in the rule for X corresponds to positions 5 and 13 in the decompressed pattern aYcZabbYaYcZa, and position 5 is a certain answer for query Q 1 , while position 13 is a certain non-answer.

The following straightforward lemma relates certain query answering to regular inclusion and certain query non-answering to regular matching. Σ,∅ (G, A) where B ∈ {¬ans, ans}, G ∈ {Pat, cPat}, and A ∈ {Dfa, Nfa} are PSpace-hard. In the sequel we show that all these problems can be solved in PSpace for arbitrary finite sets Σ and V. Basically, these results will be corollaries of Theorem 2, Lemma 5 on Boolean queries, and the following partial decompression lemma. This result is new to the best of our knowledge, even though its proof relies on similar techniques as used for instance in [START_REF] Bille | Random access to grammar-compressed strings and trees[END_REF] for computing in PTime the letter at the n-th position of pat(G) for a singleton grammar G.

Lemma 6 (Partial Decompression). For any G ∈ cPat Σ and any Σ-assignment α for V on pat(G), we can compute in PTime some G ∈ cPat Σ V such that pat(G) * α = pat(G ). In particular, if pat(G) was linear then pat(G ) is linear.

For illustration, let V = {x}, α = [x/5]. Fig. 8 shows a compressed string pattern G obtained by partially decompressing the compressed string pattern G in Fig. 7 at the position 5 of its pattern, such that pat(G) * α = pat(G ).

Proposition 5. For all B in {ans, ¬ans}, all G in {Pat, cPat, LinPat, cLinPat}, and all A in {Dfa, Nfa}, there is a PTime reduction from Cert B Σ,V (G, A) to Cert B Σ V ,∅ (G, A). Corollary 1 (Non-linear patterns). For all B ∈ {ans, ¬ans}, G ∈ {Pat, cPat} and A ∈ {Dfa, Nfa}, the problem Cert B Σ,V (G, A) is PSpace-complete. Corollary 2 (Linear patterns). For all A ∈ {Dfa, Nfa}, the certainty problems Cert ¬ans Σ,V (cLinPat, A) (1) and Cert ans Σ,V (cLinPat, Dfa) (2) can be solved in PTime. The problem Cert ans Σ,V (G, Nfa) is PSpace-complete for all G ∈ {LinPat, cLinPat} (3).

Conclusion

There exist highly efficient streaming algorithms for answering queries defined by Nfas [START_REF] Debarbieux | Early nested word automata for xpath query answering on XML streams[END_REF] on complex event streams with low latency, but not with lowest latency, since they approximate the sets of certain query answers at any event. The positive results presented here yield good hope that similar algorithms could be developed for hyperstreams when approximated by compressed linear string patterns. As shown by the authors in a follow-up paper, the linearity restriction is not sufficient. But with a further restriction it is possible to approximate certain query answers efficiently and with decent precision [START_REF] Boneva | Approximating Certain Query Answering on Hyperstreams[END_REF]. However, this still requires more research. First, one needs to understand how such algorithms may deal with unknown factors incrementally, without requiring cubic time per step such as previous algorithms on incremental evaluation of queries defined by Nfas [START_REF] Björklund | Incremental XPath evaluation[END_REF]. Second, one has to understand how to deal with nested word automata rather than Nfas for dealing with regular path queries on complex event streams. Another point is to develop streaming algorithms for hyperstreams with data values from an infinite signature. Finally, the feasibility of hyperstreaming algorithms needs to be proven in practice.

Fig. 1 :Fig. 2 :

 12 Fig. 1: The hyperstream G 1 and its string pattern p 1 .

  successor * ::a[successor * ::b/successor::b].

Fig. 4 :

 4 Fig. 4: Query certainty on (compressed) linear string patterns or streams.

Fig. 5 :

 5 Fig. 5: Automaton A 2 defining the Boolean query Q 2 with alphabet Σ = {a, b, c}

Example 2 .

 2 Incl Σ (G, A). Input: A compressed string pattern G ∈ G Σ and a finite automaton A ∈ A Σ . Output: The truth value of whether Inst(pat(G)) ⊆ L(A). Regular compressed pattern matching Match Σ (G, A). Input: A compressed string pattern G ∈ G Σ and a finite automaton A ∈ A Σ . Output: The truth value of whether Inst(pat(G)) ∩ L(A) = ∅. The problem coMatch Σ (G, A) is the complement of the problem Match Σ (G, A), and thus outputs for a given compressed string pattern G ∈ G Σ and a finite automaton A ∈ A Σ whether Inst(pat(G)) ∩ L(A) = ∅. Any instance of pat(G 1 ) = aYcZabbYaYcZa answers the Boolean query Q 2 = [successor * ::a/successor * ::b/successor::b] from Example 1,

1 ∈. 3 ∈. 3 Fig. 6 :Lemma 2 .

 13362 Fig. 6: Regular inclusion and matching problems relationship and complexity classes

Lemma 4 .

 4 coMatch Σ (G, Dfa) = p Incl Σ (G, Dfa) for all G up to PTime red.

Fig. 7 :

 7 Fig. 7: G with red thick path to the shared position 5.

Fig. 8 :

 8 Fig.8:G on Σ V with pat(G ) = pat(G) * [x/5].

The long version can be found at the address https://hal.inria.fr/hal-01846016

Acknowledgments. We are thankful to C. Paperman, who saw the PSpacehardness of regular string pattern matching in a discussion on the topic. We thank S. Salvati and S. Tison for discussions on regular string pattern matching. It is a pleasure to thank all the anonymous reviewers for their extraordinary helpful feedback.