Dynamic Data Structures for Timed Automata Acceptance

We study a variant of the classical membership problem in automata theory, which consists of deciding whether a given input word is accepted by a given automaton. We do so through the lenses of parameterized dynamic data structures: we assume that the automaton is fixed and its size is the parameter, while the input word is revealed as in a stream, one symbol at a time following the natural order on positions. The goal is to design a dynamic data structure that can be efficiently updated upon revealing the next symbol, while maintaining the answer to the query on whether the word consisting of symbols revealed so far is accepted by the automaton. We provide complexity bounds for this dynamic acceptance problem for timed automata that process symbols interleaved with time spans. The main contribution is a dynamic data structure that maintains acceptance of a fixed one-clock timed automaton \documentclass[12pt]{minimal} \usepackage{amsmath} \usepackage{wasysym} \usepackage{amsfonts} \usepackage{amssymb} \usepackage{amsbsy} \usepackage{mathrsfs} \usepackage{upgreek} \setlength{\oddsidemargin}{-69pt} \begin{document}$${\mathcal {A}}$$\end{document}A with amortized update time \documentclass[12pt]{minimal} \usepackage{amsmath} \usepackage{wasysym} \usepackage{amsfonts} \usepackage{amssymb} \usepackage{amsbsy} \usepackage{mathrsfs} \usepackage{upgreek} \setlength{\oddsidemargin}{-69pt} \begin{document}$$2^{{\mathcal {O}}(|{\mathcal {A}}|)}$$\end{document}2O(|A|) per input symbol.


Introduction
Imagine we would like to monitor whether the behaviour of a server is correct. The run of the server can be abstracted by an infinite stream w = a 1 a 2 a 3 . . . ∈ ω , where is a finite alphabet of possible events. The events are disclosed one at a time on the input, and at every moment we should tell whether the prefix consisting of the events observed so far is correct.
A simple yet expressive formalism for describing properties of such data streams is provided by classical finite automata. For example, suppose we would like to verify the property that a certain resource is being used by at most one process. Assume that the alphabet is = {o, r } ∪ , where o denotes a request of the resource, r denotes a release of the resource, and contains other immaterial events. The streams satisfying the discussed property can be then characterised as those where every prefix is accepted by the two-state automaton A of Fig. 1. Here, a state indicates whether the resource is currently available or not.
Verifying the correctness of a stream over time can be formalized through the following dynamic acceptance problem: for a fixed automaton A, design a data structure that upon receiving subsequent events from the stream, monitors whether the prefix read so far is accepted by A. An obvious, though usually suboptimal solution would be to store in the data structure the prefix read so far, and, upon receiving a new symbol, run the automaton on the whole prefix. This would require time linear in the total length of the prefix, which after a while can become very large compared to |A|, the size of the automaton A. So we would like to minimize the update time by smartly organizing and reusing information computed before.
Cast in this way, the dynamic acceptance problem naturally lends itself to a treatment using the notions of parametrised complexity. Namely, we consider the automaton A fixed and use the parameter |A| as a measure for expressing guarantees on the update time. Ideally, we would like to obtain update time bounded by a computable function of |A| only. This way, our work inscribes into the area of parameterized dynamic data structures, which is a direction that is still relatively unexplored, but starts to attract considerable attention; see e.g., [1][2][3] and references therein for an overview of recent advances.
For finite automata, the dynamic acceptance problem can be solved easily with update time O(|A|), as follows. After reading a prefix u, the data structure stores the subset of states S ⊆ Q in which the automaton may be after reading u (in general, we allow the automaton to be non-deterministic). Upon receiving the next input symbol, the set S is updated by applying the possible transitions on every state in S. Moreover, telling whether A accepts the current input prefix boils down to checking whether S contains an accepting state. Both the update and the query described above can be implemented in time linear in |A|.
Unfortunately, real-life scenarios involve many aspects that cannot be captured by a simple formalism such as finite automata. One of these aspects is time. Consider the following example of property that needs to be verified: at every moment in time when an event occurs, a special backup operation has been performed within the last 24 hours, but not within the last 1 hour. A natural choice to model this and similar properties is to enhance finite automata with the ability of measuring time, by adding one or more clocks and allowing transitions with constraints on clocks -a formal definition of this automaton model, called timed automaton, will be given in Sect. 2. The above property could be verified at every incoming event by testing whether the sequence of events received is accepted by a suitable timed automaton. The timed automaton would have one clock x and two states, "before backup" and "after backup", and would behave as follows (see the right hand-side of Fig. 1). More precisely, for every incoming event, the timed automaton non-deterministically guesses a backup event b and verifies that it occurred within the last 24 hours, but not within the last 1 hour. Thus, upon reading an occurrence of a backup event b, the timed automaton may either ignore this event and remain in the initial state "before backup", or move from state "before backup" to state "after backup" while resetting the clock. A sequence u of events is accepted if the automaton reaches the final state "after backup" and, for those events that occurred after the reset, the value of the clock is in the range (1,24]. Timed automata are a central topic in the area of verification, and they have a rich and diverse literature, see e.g., [4][5][6]. In this work we are interested in the dynamic acceptance problem for timed automata, defined analogously to that for finite automata. Note that in the setting of timed automata, the same technique that worked for finite automata will not work so easily. The reason is that for a finite automaton A, the set of configurations in which A may be is a subset of the set of control states, whose size is bounded by the size of A. On the other hand, a configuration of a timed automaton consists of a control state and a tuple of clock values, so the number of possible configurations is a priori unbounded. Concretely, after reading a prefix of length n, there may be as many as O(|A| · n k ) different configurations which the given k-clock timed automaton may possibly reach, due to non-determinism and clock resets. Efficient maintenance of this configuration set in a data structure poses the main conceptual challenge in this paper. Our contribution We design a dynamic data structure that, for a fixed timed automaton A with one clock, monitors whether A accepts the prefix read so far with amortized update time O (2 3|A| ). This can be improved to worst-case (i.e., non-amortized) update time when the input stream is discrete, that is, when all time spans between consecutive events are equal. Our data structure actually works in a slightly more general setting, where the automaton A is not entirely fixed, but rather is provided on input upon initialization of the data structure.
We also give a somewhat complementary lower bound: under the 3SUM Conjecture, we prove that there exists a fixed timed automaton A with two clocks and additive constraints on them such that no data structure for the dynamic acceptance problem for A may achieve strongly sublinear amortized update time (i.e., time O(n 1−δ ) for δ > 0). Here, by additive constraints we mean that in the transition relation of A we may use affine clock conditions that involve more than one clock, e.g., x + y = c, where x, y are clocks and c is a constant.
If the given timed automaton A has more than one clock, but only constraints involving a single clock are allowed, it remains open whether there is an efficient data structure for the dynamic acceptance problem or a lower bound similar to the above one. Related work A preliminary version of this work appeared in [7].
The setting is close to runtime verification [8], an area that focuses on verification techniques that could be performed at runtime, e.g. using timed automata [9,10]. However, while we study monitoring a data stream through a suitable data structure in the dynamic setting, studies on runtime verification typically focus on static problems. An example of such a problem is: given an input prefix u, verify whether there is a sequence of events that extends u to a word accepted by the device (e.g., a finite automaton). The problem studied in [11] is similar to the setting presented here; however, this line of work considers clock constants (e.g., 24 in Fig. 1) as part of the input, contributing to the parameter of the complexity bounds, and this considerably simplifies the setting (see Sects. 2 and 3).
The dynamic acceptance problem that we consider here resembles the setting of streaming algorithms; see e.g., [12][13][14] for works with a similar motivation. In this context, a typical problem is to compute (possibly approximately) some statistics or an aggregate function over the sequence of data, where the main point is to assume severe restrictions on the space usage. Note that in our setting, we focus on obtaining low time complexity per update and query, rather than optimizing the space complexity. In this respect, our work leans more towards the area of dynamic data structures, in particular dynamic query evaluation [15,16]. For Boolean properties several papers [17][18][19] have considered streaming algorithms for testing membership in regular and context-free languages. Another variant of the problem was considered in [20][21][22], where the regular property is verified on the last N letters of the stream, instead of the entire prefix up to the current position.
The closest to our setting is the work [23], which studies the dynamic evaluation problem for monoids over a sliding window, and describes a data structure that can be updated in constant time for a fixed finite monoid. When the monoid is finite, the considered problem is basically the same as monitoring whether the input stream restricted to the sliding window is accepted by a finite automaton. We show in Example 1, that in this case, the problem can be reduced to the dynamic acceptance problem for a special form of timed automaton.

Preliminaries
Finite automata A finite automaton is a tuple A = ( , Q, I , E, F), where is a finite alphabet, Q is a finite set of states, E ⊆ Q× ×Q is a transition relation, and I , F ⊆ Q are the sets of initial and final states. A run of A on a word w = a 1 . . . a n ∈ * is a sequence ρ = q 0 Moreover, ρ is a successful run if q 0 ∈ I and q n ∈ F. A word w is accepted by A if there is a successful run of A on w. Timed automata Let X be a finite set of clocks, usually denoted x, y, . . .. A clock valuation is a function ν : X → R ≥0 from clocks to non-negative reals. Clock conditions are formulas defined by the grammar: , where x ∈ X and c ∈ R ≥0 . By a slight abuse of notation, we also denote by C X the set of clock conditions over X . Given a clock condition γ and a valuation ν, we say that ν satisfies γ and write ν | γ , if the arithmetic expression obtained from γ by substituting each clock x with its value ν(x) evaluates to true.
A timed automaton is a tuple A = ( , Q, X , I , E, F), where , Q, I , F are defined exactly as for finite automata, X is a finite set of clocks, and E ⊆ Q × ×C X × Q ×2 X is a finite transition relation. We say that c ∈ R ≥0 is a clock constant of A if c appears in some clock condition of a transition from E. A configuration of A is a pair (q, ν), where q ∈ Q and ν is a clock valuation. Recall that finite automata process words over a finite alphabet ; likewise, timed automata process timed words over an alphabet of the form R >0 , with finite. A run of a timed automaton A on a timed word w = e 1 . . . e n ∈ ( ∪ R >0 ) * is a sequence ρ = (q 0 , ν 0 ) Thus, the set Z in a transition (q i , e i , γ, q i+1 , Z ) ∈ E corresponds to the subset of clocks that are reset when firing the transition. Note that the values of the other clocks stay unchanged. An example of a one clock timed automaton was given in the introduction (see Fig. 1). A run ρ as above is successful if q 0 ∈ I , ν 0 (x) = 0 for all x ∈ X , and q n ∈ F. A word w ∈ ( ∪ R >0 ) * is accepted by A if there is a successful run of A on w.
Size of an automaton The size of a finite automaton A = ( , Q, I , E, F) is defined as |A| = |Q| + |E|. This is asymptotically equivalent to essentially every possible definition of size of a finite automaton that can be found in the literature. The size of a timed automaton A = ( , Q, X , I , E, F) is instead defined as |A| = |Q| + |X | + ( p,a,γ ,q,Z )∈E |γ |, where |γ | is the number of atomic expressions (i.e., expressions of the form true, x < c, x > c, x = c) appearing in the clock condition γ . Note that the size of a timed automaton does not take into account the magnitude of the clock constants. These constants are specified with the automaton and stored in suitable floating-point memory cells (see the computation model below). Computation model As clock constants and time spans in the input stream are arbitrary real numbers, it is convenient to use the real RAM model of computation [24]. This is a standard model with integer memory cells that can store integers and floating-point memory cells that can store real numbers. There are no bounds on the bit length or precision of the stored numbers. However, in practice, our model will only receive inputs with real numbers that are represented symbolically (e.g., rational numbers).
Basic arithmetic operations -addition, subtraction, multiplication, and divisioncan be performed in unit time, but modulo arithmetics and rounding are not included in the model. In fact, we do not use multiplication or division on real numbers either.

The Dynamic Acceptance Problem
The dynamic acceptance problem amounts to designing a data structure that can be initialized for a given timed automaton A with one clock, and afterwards, upon consuming consecutive elements of the data stream, efficiently maintains the information on whether the word read so far is accepted by A. Formally, the data structure should support the following operations: • init(A): Initialize the data structure for a given automaton A. This automaton is fixed for the entire lifespan of the data structure. • accepted: Query whether the prefix of the stream consumed up to the current moment is accepted by A. • read(e): Consume the next element e from the input stream, be it a letter from or a time span from R >0 , and update the data structure accordingly.
The running time of each of these operations needs to be as low as possible. More precisely, we shall say that a data structure supports dynamic acceptance in time f (s, n) if the first operation init(A) takes at most f (s, 0) time, and every subsequent execution of accepted or read(e) takes at most f (s, n) time, where s = |A| and n is the number of stream elements consumed so far. Similarly, a data structure supports dynamic acceptance in amortized time f (s, n) if the first operation init(A) takes at most f (s, 0) time and, for every n, the first n operations of the form accepted and read(e) take at most n · f (s, n) time in total. Ultimately, we are interested in designing data structures where the complexity guarantee f (s, n) is independent of n, that is, the (amortized) update time is a function of |A| only. Before presenting the complexity results in detail, we provide an example of application of the dynamic acceptance problem.

Example 1
We discuss the relationship between our dynamic acceptance problem for timed automata and an aggregation problem for monoids over a sliding window, as considered in [23]. When the monoid is finite, every element of it represents a regular language, and thus the aggregation problem can be seen as an acceptance problem. This means that the aggregation problem for finite monoids over a sliding window is reducible to an automaton acceptance problem in the sliding window model (see also [22]). We formalize this problem below.
Let A = ( , Q, I , E, F) be a finite automaton and C a positive integer defining the width of the sliding window. The acceptance problem of A with a sliding window of width C consists of processing, from left to right, an arbitrary input w = a 1 a 2 a 3 . . . over , while maintaining the answer to the following query: is the sequence of the last C consumed letters accepted by A? The goal is to design a data structure that, upon consuming a new letter of a potentially infinite stream, can be updated in a time that only depends on the automaton A, and not on size of the window C. Next, we explain how the above problem can be reduced to our dynamic acceptance problem. Here, we consider only streams that are discrete, and in fact even slightly more restricted: we assume that every input stream belongs to the language ({1} · ) ω , namely, that the letters from are interleaved by the time unit 1. We map the input word w = a 1 a 2 a 3 . . . to a corresponding discrete stream w = 1a 1 1a 2 1a 3 . . ., and modify the finite automaton A to obtain a corresponding timed automaton A, as follows. We introduce a new state q, which will be the only final state of A, and a clock x. We then replace every transition (q, a, q ) of A with the transition (q, a, true, q , ∅). Note that these transitions have a vacuous clock condition, hence they are applicable in A whenever the original transitions of A are so. In addition, when the former transition (q, a, q ) reaches a final state q ∈ F, we also have a transition (q, a, x = C, q, ∅) in A. Finally, we add looping transitions on the initial states that reset the clock, that is, transitions of the form (q, a, true, q, {x}), with q ∈ I and a ∈ . Figure 2 shows the timed automaton A corresponding to an automaton A recognising ab * a.
From the above construction it is clear that A accepts a prefix 1a 1 . . . 1a n of w if and only if A accepts the C-letter factor a n−C+1 . . . a n of w. Thus, the acceptance problem for A in the C-width sliding window model is reduced to the dynamic acceptance problem for A over the stream w. We will see later (Theorem 1) that there is a data structure that supports dynamic acceptance for A with update time O(2 3| A| ) = O (2 6|A| ). This means that we can process one letter at a time from a word w, while answering in time O(2 6|A| ) whether A accepts the sequence of the last C consumed letters. Note that the complexity here is independent of the parameter C.
Given a word w = a 1 a 2 . . . and an expression ϕ, we would like to read w sequentially, as in a stream, and decide, at each position n = 1, 2, . . . , whether the prefix w n = a 1 . . . a n matches a fixed expression ϕ. One can reduce this latter problem to the dynamic acceptance problem for timed automata, by using a discrete timed word w = 1a 1 1a 2 1 . . . as before and by translating the expression ϕ into an appropriate timed automaton. We omit the straightforward details of the translation of a CEL expression to an equivalent timed automaton, and we only remark that every occurrence of the Within operator in an expression corresponds to a condition on a specific clock in the equivalent timed automaton. This means that, in general, the translation may require a timed automaton with multiple clocks. However, there are simple cases where, even in the presence of nested Within operators, one can construct an equivalent timed automaton with a single clock. More precisely, this is possible when, for every occurrence of a Within operator, say (ϕ Within t), and for every sub-expression of ϕ of the form (ϕ 1 ϕ 2 ), ϕ 2 does not contain a Within operator. This is the case, for instance, of the expression ϕ = (((a b) Within 4) c) Within 10. This expression describes a sequence containing three (possibly not contiguous) events a, b, c, with a and b at distance at most 4 and a and c at distance at most 10. Figure 3 shows a single-clock timed automaton that is equivalent to ϕ, in the sense that it accepts a timed word of the form 1a 1 1a 2 1 . . . 1a n if and only if a 1 a 2 . . . a n ϕ. In this case one can validate any input stream against a fixed expression ϕ in time that is constant per input letter, by simply reducing to our dynamic acceptance problem for single-clock timed automata and discrete timed words.

Results
We say that a stream w is discrete if its elements range over {1}, that is, if all time spans in the stream coincide with the time unit 1. Our main result is the following: We stress that the complexity in Theorem 1 depends only on the size of A. In particular, it does not depend on the bit-length of clock constants (e.g., constant 24 in Fig. 1). Note that thanks to the assumption of the real RAM model, the question of the complexity of arithmetic operations on reals is separated from the running time analysis in the Proof of Theorem 1. This feature reflects the real-life scenarios, where the automaton is small, while real numbers involved can be efficiently manipulated by the processor despite having large bit-length The Proof of Theorem 1 is presented in Sect. 4.
We do not know whether this theorem can be generalized to timed automata with more than one clock while preserving independence of the time complexity of updates from the length of the consumed stream prefix. However, we establish a negative result for a slightly more powerful model of timed automata, called timed automata with additive constraints (see e.g., [5]). Formally, a timed automaton with additive constraints is defined exactly as a timed automaton -that is, as a tuple A = ( , Q, X , I , E, F) consisting of an input alphabet, a set of states, a set of clocks, etc. -but clock conditions are now allowed to satisfy an extended grammar obtained by adding new rules of the form ( x∈Z x) ∼ c, where Z ⊆ X and ∼ ∈ {<, >, =}. For instance, one can write x + y ≤ c, where c is a clock constant. To give some background, let us briefly discuss in more detail the power of this extension. Allowing additive constraints is a non-trivial extension of timed automata and in particular it makes the emptiness problem undecidable [5,Theorem 2]. However, undecidability holds when at least four clocks are available. Moreover, it is shown that for timed automata with additive constraints with two clocks the emptiness problem is decidable; and the proof is a straightforward modification of the standard region construction [5, Proposition 1].
Our negative result relies on the 3SUM Conjecture, stated just below. Recall that in the 3SUM problem we are given a set S of positive real numbers and the question is to determine whether there exist a, b, c ∈ S satisfying a + b = c. It is easy to solve the problem in time O(n 2 ), where n = |S|; the 3SUM Conjecture asserts that this cannot be significantly improved: [3SUM Conjecture] In the real RAM model, the 3SUM problem cannot be solved in strongly sub-quadratic time, that is, in time O(n 2−δ ) for any δ > 0, where n is the number of values forming the Theorem 2 If the 3SUM Conjecture holds, then there is a two-clock timed automaton A with additive constraints such that there is no data structure that, when initialized on A, supports dynamic acceptance in time O(n 1−δ ) for any δ > 0, where n is the length of the consumed stream prefix.
A detailed discussion on the 3SUM Conjecture and the Proof of Theorem 2 are postponed to Sect. 5.

Data Structure: Proof of Theorem 1
Notation Let us fix, once and for all, the timed automaton A = ( , Q, X , I , E, F) with a single clock x that is provided upon initialization. By adding a non-accepting sink state, if necessary, we may assume that for every q ∈ Q and a ∈ , some transition over letter a can be always applied at q at any time (with a trivial clock condition). Note that this means that the number of runs never decreases over time.
As A uses only one clock x, every configuration of A can be written simply as a pair (q, t), where q ∈ Q is the state and t ∈ R ≥0 is the value of the clock x. Let 0 = C 0 < C 1 < . . . < C m be the clock constants used in A, where we assume without loss of generality that C 0 = 0. For simplicity we also let C m+1 = ∞. Note that m ≤ |A|.
Consider now an arbitrary stream w ∈ ( ∪ R >0 ) ω . For every n ∈ N, let w n = w[1 . . . n] be the n-element prefix of w. Recall that w n can be thought of as the stream prefix that is disclosed after n operations read(e). We say that a configuration (q, t) is active at step n if there is a run of A on w n that starts in a configuration (q 0 , 0) for some q 0 ∈ I and ends in (q, t). We let K n be the set of all configurations (q, t) that are active at step n. Partitioning the problem It is clear that the dynamic acceptance problem essentially boils down to designing an efficient data structure that maintains K n upon reading subsequent elements from the stream. This data structure should offer a query on whether K n contains an accepting configuration. The main observation is that any two clock values t and t that are in the same relative order with respect to the clock constants C 1 , . . . , C m (i.e., for every i = 1, . . . , m, t < C i iff t < C i , and similarly t ≤ C i iff t ≤ C i ) satisfy exactly the same clock conditions in E. Precisely, let us consider the partition of R ≥0 into intervals J 0 , . . , m}. The following assertion holds: for any two configurations (q, t), (q, t ), with t, t ∈ J i for some 0 ≤ i ≤ 2m + 1, exactly the same transitions are available in (q, t) as in (q, t ).
For n ∈ N and i ∈ {0, . . . , 2m + 1}, let The idea is to maintain each set K n [i] in a separate data structure. Each of these data structures follows the same design, which we call the inner data structure. Inner data structure: an overview Every inner data structure is constructed for an interval J ∈ {J 0 , . . . , J 2m+1 }. The inner data structure should support the following methods: • Method init(J ) stores interval J and initializes D[J ] by setting L = ∅.
• Method accepted() returns true or false, depending on whether or not L contains an accepting configuration, that is, a configuration (q, t) such that q ∈ F. • Method insert(q, t) adds a configuration (q, t) to L. This method will be always applied with a promise that t ∈ J and t ≤ t for all configurations (q , t ) already present in L. • Method updateTime(r ), where r ∈ R >0 , increments the clock values of all configurations in L by r . All configurations whose clock values ceased to belong to J are removed from L, and they are returned by the method on output. This output is organised as a doubly linked list of configurations, sorted by non-decreasing clock values. • Method updateLetter(a) updates L by applying to all configurations in L all possible transitions over the given letter a ∈ . Precisely, the updated set comprises all configurations (q, t) that can be obtained from configurations belonging to L before the update using transitions over a that do not reset the clock. The configurations (q, 0) which can be obtained from L using transitions over a that do reset the clock are not included in the updated set, but are instead returned by the method as a doubly linked list.
In Sect. 4.2 we will provide an efficient implementation of the inner data structure, which is encapsulated in the following lemma.
We postpone the Proof of Lemma 3 and we show now how to use it to prove Theorem 1. That is, we design an outer data structure that monitors the acceptance of A.

Outer Data Structure
The outer data structure consists of a list D We first explain how the outer data structure implements the promised operations: initialization, queries about the acceptance, and updates upon reading the next element of the stream w. Then we discuss the amortized complexity of the updates. Initialization Given A, we store A in the data structure and we read the clock constants 0 = C 0 < C 1 < ... < C m from A. Then we initialize 2m + 1 copies D[0], . . . , D[2m + 1] of the inner data structure by calling method init(J ) for each interval J among J 0 , J 1 , . . . , J 2m+1 . Finally, for each initial state q, we apply method insert(q, 0) on D[0]. As K 0 = {(q, 0) : q ∈ I }, after this we have that Invariant (I1) holds for n = 0. Query We query all the data structures D[0], . . . , D[2m + 1] for the existence of accepting configurations using the accepted() method, and return the disjunction of the answers. The correctness follows directly from Invariant (I1). Update by a time span Suppose the next element from the stream is a time span r ∈ R >0 . We update the outer data structure as follows. First, we apply method updateTime(r ) to each data structure D[i]. This operation increments the clock values of all configurations stored in D[i] by r , but may output a set of configurations whose clock values ceased to fit in the interval J i . Recall that this set is organised as a doubly linked list of configurations, sorted by non-decreasing clock values; call this list S i . Now, we need to insert each configuration (q, t) that appears on those lists into the appropriate data structure D[ j], where j is such that t ∈ J j . However, we have to be careful about the order of insertions: we process the lists S 2m+1 , S 2m , . . . , S 0 in this precise order, and each list S i is processed from the end, that is, following the non-increasing order of clock values. When processing a configuration (q, t) from the list S i , we find the index j > i such that t ∈ J j and apply the method insert(q, t) on the structure D[ j]. In this way the condition required by the insert methodthat t ≤ t for every configuration (q , t ) currently stored in D[ j] -is satisfied. It is also easy to see that Invariant (I1) is preserved after the update. Update by a letter Suppose the next symbol read from the stream is a letter a ∈ . We update the outer data structure as follows. First, we apply method updateLetter(a) to each data structure D[i]. This operation applies all possible transitions on letter a to all configurations stored in D[i], and outputs a list of configurations R i where the clock got reset. All these configurations have clock value 0, hence the length of R i is at most |Q|. It now suffices to insert all the configurations (q, 0) appearing on all the lists R i to D[0] using method insert(q, 0). We may do this in any order, as the condition required by the insert method is trivially satisfied. Again, Invariant (I1) is clearly preserved after the update.
This concludes the implementation of the outer data structure. While the correctness is clear from the description, we are left with arguing that the time complexity is as promised.
From Lemma 3 it readily follows that each of the following operations takes time O(2 |A| ): initialization, a query about the acceptance, and an update by a letter. As for an update by a time span r ∈ R >0 , by Lemma 3 the complexity of such an update is O(2 |A| ) · 2m+1 i=0 |S i |, where S 0 , . . . , S 2m+1 are the sets returned by the applications of method updateTime(r ) to data structures D[0], . . . , D[2m + 1], respectively. We need to argue that the amortized time complexity of all these updates is bounded by O(2 |A| ).
Consider the following definition: a clock value t ∈ R ≥0 is active at step n if K n contains a configuration with clock value t. Observe that upon an update by a time span r ∈ R >0 , the set of active clock values simply gets shifted by r , while upon an update by a letter a ∈ it stays the same, except that clock value 0 may also become active. Since at step 0 the only active clock value is 0, we conclude that for every n ∈ N, at most n + 1 active clock values may have appeared until step n. Note that there may be at most |Q| different active configurations with the same active clock value, hence the complexity of each update by a time span is bounded by O(2 |A| ) · |Q| times the number of active clock values that change membership from an interval to another one, where we imagine that each active clock value is shifted by the time span. Since every active clock value can change membership in an interval at most 2m + 1 times, and since the total number of active values that appear until step n is at most n + 1, we derive that the total time spent on updates by time spans throughout the first n steps is bounded by O(2 |A| ) · |Q| · (2m + 1) · (n + 1). Hence, by recalling that |Q|, m ≤ |A|, we conclude that the amortized time complexity is O(2 3|A| ).
Finally, note that in the case of discrete streams each set S i consists of configurations with the same clock value, hence |S i | ≤ |Q| ≤ |A| for all i ∈ {0, . . . , 2m + 1}. So in this case, the complexity of an update by a time span is bounded by O(2 3|A| ), without any amortization.
This finishes the Proof of Theorem 1, assuming Lemma 3. We prove the latter next.

Inner Data Structure
We now describe the inner data structure D[J ] and prove Lemma 3. Let us fix an interval J ∈ {J 0 , . . . , J 2m+1 }. We denote by L the set of configurations currently stored by the inner data structure D[J ]. It is convenient to represent L by a function λ : R ≥0 → 2 Q defined by We let L be the set of all clock values that are active in L, that is, L comprises all t ∈ R ≥0 such that λ(t) = ∅. Recall that we assume that L ⊆ J . Before we dive into the details, let us discuss the intuition. The basic idea is to store all the configurations in L in a queue, implemented as a doubly-linked list ordered by non-decreasing clock values. To handle clock values efficiently, we do not store them directly. Instead, we maintain a global clock that measures the total time since the initialization of the data structure, and each configuration bears a timestamp that is the value of this global clock at the moment of the last reset. Thus, updating by a time span boils down to increasing the value of the global clock and popping any configurations at the back of the queue whose clock values ceased to fit into the interval J .
Updating by a letter is more problematic, as we need to apply the transition relation of the automaton A to all the configurations of L simultaneously. In the data structure we store a partition of the active clock values L according to their images under λ(·), so that for each block of this partition (whose number is at most 2 |Q| ), we can simultaneously update all corresponding configurations in constant time. There is a caveat here: it is possible that for some t, t ∈ L we have λ(t) = λ(t ) before the update, but λ(t) = λ(t ) after the update. That is, the blocks of the partition may require merging upon updates. We resolve this issue by representing the partition in a forest, similarly as the union-find data structure would do. The key point is that the height of this forest can be kept bounded by 2 |Q| . Description of the structure In short, the data structure D[J ] consists of three elements: • The clock, denoted y, is a real that represents the total time elapsed since initialization. • The list, denoted l, stores the set of active clock values L.
• The forest, denoted f, is built on top of the elements of l and describes the function λ.
We describe the list and the forest in more details (the reader can refer to Fig. 4).
The list The list l encodes the clock values present in L, sorted in the increasing order and organised into a doubly linked list. Each node α on l is a record consisting of: • next(α): a pointer to the next node on the list; • prev(α): a pointer to the previous node on the list; and • timestamp(α) ∈ R: the timestamp of the node.
As usual, the data structure stores l by maintaining pointers to the first and last nodes. The clock value represented by a node α on l is equal to clock(α) = y − timestamp(α); this will always be a non-negative real. Thus, the timestamp is essentially the total elapsed time recorded at the moment of the last reset of the clock. Note that this implementation allows for a simultaneous increment of clock(α) for all nodes α on l in constant time: it suffices to simply increment y.
The forest Forest f represents the mapping from elements t ∈ L, encoded in l, to respective sets of control states λ(t). It is a rooted forest where nodes may have The leaves of the forest will always coincide with the nodes on the list l. In particular, we augment the records stored for the nodes on l by adding the parent(·) pointer, and treat them as nodes of the forest f at the same time. The counter #children(·) would always be equal to 0 for those nodes, so we may omit it.
The roots of the forest are the nodes β with no parent, i.e., parent(β) = ⊥. We will maintain the invariant that no root is a leaf in f, that is, every root has at least one child. In the data structure we store a doubly linked list containing all the roots of f. This list will be denoted r, and again it is stored by pointers to its first and last element. Thus, the records of the roots of f are augmented by next(·) and prev(·) pointers describing the structure of r, with the usual meaning. In addition to this, every root β of f carries two additional values: • states(β) ⊆ Q: a non-empty subset of control states for which β is responsible; and • rank(β): an integer from the set {1, 2, 3, . . . , 2 |Q| }.
We will maintain two invariants about these values. First, the sets states(β) must be different for distinct roots β of f, and the same holds for the ranks rank(β). Note that this implies that f has at most 2 |Q| − 1 roots. Second, for every root β, the tree rooted at β -which is the tree containing β and all its descendants in f -has depth at most rank(β) + 1 where the depth of a forest is the maximum number of edges on a path from a leaf to a root. Note that this implies that the depth of the forest f is bounded by 2 |Q| + 1.
Function λ is then represented as follows. For every node α on l, let root(α) be the root of the tree of f that contains α. Then denoting t = clock(α), we have λ(t) = states(root(α)). Note that the invariant stated above implies that from every leaf α of f, root(α) can be computed from α by following the parent(·) pointer at most 2 |Q| ≤ 2 |A| times. Hence, given t ∈ L and a node α on l satisfying t = clock(α), we can compute λ(t) in time O(2 |A| ). Invariants For convenience, we gather here all the invariants maintained by the inner data structure which we mentioned before: I2. For each node α on l, the value clock(α) = y − timestamp(α) belongs to J . I3. The nodes on l are sorted by increasing clock values, or equally by decreasing timestamps. That is, timestamp(α) > timestamp(next(α)) for every nonlast node α on l. I4. Every root of f has at least one child, and the leaves of f are exactly all the nodes on l. I5. The roots of f carry pairwise different, non-empty sets of control states, and they have pairwise different ranks. Moreover, all the ranks belong to the set {1, 2, . . . , 2 |Q| }. I6. For each root β of f, the depth of the tree rooted at β is at most rank(β) + 1.
Implementation Now we show how to implement the methods init(J ), accepted(), insert(q, t), updateTime(r ), and updateLetter(a) in the data structure.
Recall that all these methods should work in time O(2 |A| ), with the exception of updateTime(r ) which is allowed to work in time O(2 |A| ) · , where is the size of its output. The description of each method is supplied by a running time analysis and an argumentation of the correctness, which includes a discussion on why the invariants stated above are maintained. Removing nodes Before we proceed to the description of the required methods, we briefly discuss an auxiliary procedure of removing a node from the list l and from the forest f, as this procedure will be used several times. Suppose we are given a node α on the list l and we would like to remove it, which corresponds to removing from L all configurations (q, t) where t = clock(α) and q ∈ λ(t). We can remove α from l in the usual way. Then we remove α from f as follows. First, we decrement the counter of children in the parent of α. If this counter stays positive then there is nothing more to do. Otherwise, we need to remove the parent of α as well, and accordingly decrement the counter of children in the grandparent of α. This can again trigger removal of the grandparent and so on. If eventually we need to remove a root of f, we also remove it from the list r in the usual way. Since, by Invariants (I5) and (I6), the depth of f is bounded by 2 |Q| + 1 = O(2 |A| ), the whole procedure can be performed in time O(2 |A| ). It is clear that all the invariants are maintained. Initialization The init(J ) method stores the interval J , that defines the range of clock values that could be represented in the data structure. It also sets y = 0 and initializes l and r as empty lists. The correctness and the running time are clear. Acceptance query The accepted() method is implemented as follows. We iterate through the list r to check whether there exists a root β of f such that states(f) contains any accepting state, say q. If this is the case, then by Invariant (I4) there is a node α on l satisfying root(α) = β, hence (q, t) is an accepting configuration that belongs to L, where t = clock(α). So we may return a positive answer from the query. Otherwise, all configurations in L have non-accepting states, and we may return a negative answer. Note that since by Invariant (I5) the list r has length at most 2 |Q| − 1, the above procedure works in time O(2 |A| ).
Insertion We now implement the method insert(q, t), where (q, t) is a configuration. Recall that when this method is executed, we have a promise that t ∈ J and t ≤ t for all configurations (q , t ) that are currently present in D[J ].
Let α be the first node on the list l. Let t = clock(α). By the promise, we have t ≤ t . We consider cases: either t < t or t = t . The former case also captures the situation when l is empty. When t < t or l is empty, the new configuration (q, t) gives rise to a new active clock value t. Therefore, we create a new list node α 0 and insert it at the front of the list l. We set the timestamp as timestamp(α 0 ) = y − t, so that the node correctly represents the clock value t. It is clear that Invariants (I2) and (I3) are thus satisfied.
Next, we need to insert the new node α 0 to the forest f. We iterate through the list r in search for a root β that satisfies states(β) = {q}. In case there is one, we simply set parent(α 0 ) = β and increment #children(β). Otherwise, we construct a new root β 0 with states(β 0 ) = {q} and #children(β 0 ) = 1, insert it at the front of the list r, and set parent(α 0 ) = β 0 . To determine the rank of β 0 , we find the smallest integer k ∈ {1, . . . , 2 |Q| } that is not used as the rank of any other root of f. Observe that, by Invariant (I5), the forest f has at most 2 |Q| − 1 roots, so there is always such a number k, and it can be found in time O(2 |A| ) by inspecting the list r. We then set rank(β 0 ) = k. It is clear that this operation can be performed again in time O(2 |A| ), and that Invariants (I4), (I5), and (I6) are maintained. For the last one, observe that the new leaf α 0 is attached directly under a root of f, so no tree in f existing before the insertion could have increased its depth.
We are left with the case when t = t . We first compute the set X equal to λ(t) before the insertion: it suffices to find root(α) in time O(2 |A| ) and read X = states(root(α)). If q ∈ X then the configuration (q, t) is already present in L, so there is nothing to do. Otherwise, we need to update the data structure so that λ(t) is equal to X ∪ {q} instead of X . Consequently, we remove the node α from l and from f, using the operation described earlier, and we insert a new node α at the front of l, with the same timestamp equal to that of α. Thus, clock(α ) = t. We next insert the new node α to the forest f using the same procedure as described in the previous paragraph, but applied to the state set X ∪ {q} instead of {q}. Again, it is clear that these operations can be performed in time O(2 |A| ), and the same argumentation shows that all the invariants are maintained. Update by a time span Next, we implement the method updateTime(r ), for r ∈ R >0 . First, we increment y by r . Thus, for every node α in the list l, the value clock(α) is incremented by r . However, the Invariant (I2) may have ceased to hold, as some active clock values could have been shifted outside of the interval J . The configurations with these clock values should be removed from the data structure and their list should be the output of the method.
We extract these configurations as follows. Construct an initially empty list of configuration lret, on which we shall build the output. Iterate through the list l, starting from its back. For each consecutive node α, compute t = clock(α). If t ∈ J , then break the iteration and return lret, as there are no more configurations to remove. Otherwise, find root(α) in time O(2 |A| ), read λ(t) = states(root(α)), and add at the front of lret all configurations (q, t) for q ∈ λ(t), in any order. Then remove α from the list l and from the forest f, and proceed to the previous node in l (if there is none, finish the iteration).
By Invariant (I3), it is clear that in this way we remove from D[J ] exactly all the configurations whose clock values got shifted outside of J , hence Invariants (I2) and (I3) are maintained. As the forest structure was influenced only by removals, Invariants (I4), (I5), and (I6) are maintained as well. Note that the output list lret is ordered by non-decreasing clock values, as required. As for the time complexity, the procedure presented above takes time O(2 |A| ) · , where is the number of nodes that we remove from l. As for every node α the set states(root(α)) is non-empty and of size at most |Q|, with every removed node we add to lret between 1 and |Q| new configurations. Hence, we can also bound the complexity by O(2 |A| ) · , where is the number of configurations that appear in the output list lret. Update by a letter We proceed to the method updateLetter(a), where a ∈ . As argued before, every clock condition appearing in A is either true for all clock values in J , or false for all clock values in J . For every subset of states S ⊆ Q, let (S) be the set of all states q such that there is a transition ( p, a, q, γ, ∅) in E for some p ∈ S and clock condition γ that is true in J . In other words, (S) comprises states reachable from the states of S by non-resetting transitions over a that are available for clock values in J . We define (S) in a similar way, but for resetting transitions over a that are available for clock values in J .
First, we compute the output of the method, which is {(q, 0) : q ∈ (S)} where S is the set of all states appearing in the configurations of L. Note that, by Invariant (I4), S can be computed in time O(2 |A| ) by iterating through the list r and computing the union of sets states(β) for roots β appearing on it. Thus, the output can be computed in time O(2 |A| ).
Second, we need to update the values of function λ by applying all possible nonresetting transitions over a. This can be done by iterating through the list r and, for each root β appearing on it, substituting states(β) with (states(β)). Note that since we assumed that for every state q, some transition over a is always available at q, it follows that maps non-empty sets of states to non-empty sets of states. Hence, after this substitution the roots of f will still be assigned non-empty sets of states. However, Invariant (I5) may cease to hold, as some roots may now be assigned the same set of states.
We fix this as follows. For every root β of f, inspect the list r and find the root β that has the largest rank among those satisfying states(β) = states(β ). If β = β , then do nothing. Otherwise, turn β into a non-root node of f, remove it from the list r, set parent(β) = β , and increment #children(β ) by one. Note that after applying this modification, the function λ stored in the data structure stays the same, while Invariant (I5) becomes satisfied.
As for the other invariants, the satisfaction of Invariants (I2), (I3), and (I4) after the update is clear. However, we need to be careful about Invariant (I6), as we might have substantially modified the structure of the forest f. Observe that each modification of f that we applied boils down to attaching a tree with a root of some rank i as a child of a tree with a root of some rank j > i. By Invariant (I6), the former tree has depth at most i + 1, which is bounded from above by j. Thus, after the attachment, the depth of the latter tree cannot become larger than j + 1. We conclude that Invariant (I6) is maintained as well.
Finally, note that since the number of roots of f is always bounded by 2 |Q| − 1, all the operations described above can be performed in time O(2 |A| ).

Lower Bound for Two-Clock Timed Automata with Additive Constraints
In this section, we prove a complexity lower bound for a variant of the dynamic acceptance problem. Ideally, we would like to prove that there is a timed automaton A with two clocks such that no data structure can support dynamic acceptance for A in time depending only on |A|. This would imply that our result (Theorem 1) for the dynamic acceptance problem for single-clock timed automata cannot be generalised to the multiple-clock setting. We are not able to establish optimality in this sense. We can however prove a result along the same line, by considering timed automata extended with additive constraints, that is, having clock conditions of the form x∈Z x ∼ c, and by relying on certain complexity assumptions (Conjecture 3, also known as 3SUM Conjecture).
The 3SUM Conjecture was introduced by Gajentaan and Overmars [27,28] in a stronger form, which postulated the non-existence of sub-quadratic algorithms, that is, achieving running time o(n 2 ). This formulation was refuted by Grønlund and Pettie [29], who gave an algorithm for 3SUM with running time O(n 2 /(log n/ log log n) 2/3 ) in the real RAM model, which can be improved to O(n 2 (log log n) 2 / log n) when randomization is allowed. However, the existence of a strongly sub-quadratic algorithm is conjectured to be hard.
Recall that in the 3SUM problem, we are given a set S of positive real numbers and the question is to determine whether there exist a, b, c ∈ S satisfying a + b = c. We remark that the original phrasing of the conjecture allows non-positive numbers on input and asks for a, b, c ∈ S such that a + b + c = 0. It is easy to reduce this standard formulation to our setting, for example by replacing S with S = {3M + x : x ∈ S} ∪ {6M − x : x ∈ S}, where M is any real that is larger than the absolute value of a, for all a ∈ S.
The 3SUM Conjecture has received significant attention in the recent years, as it was realised that it can be used as a base for tight complexity lower bounds for a variety of discrete graph problems, including questions about efficient dynamic data structures [1,[30][31][32]. In this setting, it is common to assume the integer formulation of the conjecture: there exists d ∈ N such that the 3SUM problem, where the input numbers are integers from the range [−n d , n d ], cannot be solved in strongly subquadratic time, assuming the word RAM model with words of bit-length O(log n). The construction we are going to present in this section proves an analogous lower bound for the dynamic acceptance problem, assuming the former integer formulation of the 3SUM Conjecture. For this, we would need to amend the formulation of the dynamic acceptance problem, so that it makes sense to use the word RAM model instead of the real RAM model. More precisely, we assume that (1) the input stream is finite and expected to have total length at most N , (2) the clock constants and the time spans in the stream are integers of bit-length at most M, and (3) the data structure solving the monitoring problem should work in the word RAM model with words of bit-length O(M + log N ).
We now prove Theorem 2. That is, we provide a lower bound for the dynamic acceptance problem for two-clock timed automata with additive constraints under the 3SUM Conjecture.
Our approach is similar in spirit to the other lower bounds on dynamic problems, which we mentioned above [1,[30][31][32]. We first prove 3SUM-hardness of deciding acceptance by a timed automaton with additive constraints in the static setting. We then show that any data structure that supports monitoring in amortized strongly sub-linear time would violate the 3SUM-hardness of the former static acceptance problem, thus proving Theorem 2.
The Proof of Theorem 2 follows almost directly from an analogous 3SUM-hardness result in the static setting:

Lemma 4
If the 3SUM Conjecture holds, then there is a two-clock timed automaton A with additive constraints for which there is no algorithm that, given a finite timed word w ∈ ( R >0 ) * as input, where is a two-letter alphabet, decides whether A accepts w in time O(n 2−δ ) for any δ > 0 and for n = |w|.
Proof We construct a two-clock timed automaton A with additive constraints and an algorithm that, given a set S of n positive reals, outputs in time O(n log n) a word w ∈ ( R >0 ) * such that w is accepted by A if and only if there are a, b, c ∈ S satisfying a + b = c. We find it more convenient to first present the construction of w from S. Then we present the automaton A and analyse its runs on w.
Let S = {s 1 , s 2 , . . . , s n } be a set of positive real numbers and let M = max(S) + 1. By sorting S we may assume that 0 < s 1 < . . . < s n < M. We set = {♦, ♠}. The word obtained from S is defined as Note that w has length O(n) and can be constructed from S in time O(n log n). Intuitively, the factors u, u, and v above are responsible for the choice of a, b, and c, respectively.
We now describe a timed automaton A that accepts w if and only if there are a, b, c ∈ S such that a +b = c. The automaton is depicted in Fig. 5. It uses two clocks, named x and y. All the transitions have trivial (always true) clock conditions, apart from the transition from r 1 to r 2 , where we check that the sum of clock values is equal to 4M. The only initial state is p 1 ; the only accepting state is r 2 .
Next, we analyse the runs of A on w, with the goal of showing that A accepts w if and only if there are a, b, c ∈ S such that a + b = c. Consider any successful run ρ of A on w. Observe that the moment of reading the first symbol ♠ in w must coincide with firing the transition from p 2 to q 1 . At this moment, the automaton has consumed the first factor u of w, and there was a moment where it moved from state p 1 to state p 2 upon reading one of the ♦ symbols from u. Supposing that the transition in ρ from p 1 to p 2 happens at the i-th symbol ♦ of u, the clock valuation at the moment of reaching q 1 for the first time must satisfy x = 2(s i − s i−1 ) + . . . + 2(s 2 − s 1 ) + 2s 1 (= 2s i ). We conclude the following. Next, observe that the moment of reading the second occurrence of ♠ in w must coincide with firing the transition from q 2 to r 1 . Between the first and the second symbol ♠ the automaton consumes the second factor u, and the clock x increases exactly by the sum of the time spans within u, i.e., by 2M. On consuming the second factor u, the clock y is reset once, and precisely when firing the transition from q 1 to q 2 , which happens upon reading one of the occurrences of ♦ in u. Again, if this happens when reading the j-th occurrence of ♦, then, after the reset, y is incremented by exactly 2s j units. We conclude the following. Based on the above arguments, we infer that a successful run like ρ exists on input w if and only if there are a, b, c ∈ S such that a + b = c. To conclude the proof, we observe that if an algorithm could decide whether A accepts w in time O(n 2−δ ) for any δ > 0, then by combining this algorithm with the presented construction, one could solve 3SUM in time O(n 2−δ ). This would contradict the 3SUM Conjecture. Now, Theorem 2, which we restate below for convenience, follows almost directly from the previous lemma.
Theorem 2 If the 3SUM Conjecture holds, then there is a two-clock timed automaton A with additive constraints such that there is no data structure that, when initialized on A, supports dynamic acceptance in time O(n 1−δ ) for any δ > 0, where n is the length of the consumed stream prefix.
Proof Consider the timed automaton A provided by Lemma 4. If a data structure as in the statement of the theorem existed, then using this data structure one could decide in strongly sub-quadratic time whether any input timed word w is accepted by A, by simply applying the sequence of read(·) operations corresponding to w, followed by the query accepted.

Concluding Remarks and Future Work
In this work we studied the dynamic acceptance problem for timed automata processing data streams. We designed a suitable data structure for one-clock timed automata, where the amortized update time depends only on the size of the automaton. We leave as an open question whether this result can be generalised to the case of multiple clocks.
More generally speaking, it seems that our work identifies dynamic variants of classic automata problems as a potential area of interest for the paradigm of parametrised dynamic data structures. More precisely, if the automaton model in question allows for the device to potentially be in an unbounded number of configurations, then the dynamic maintenance of this set of configurations is a computationally challenging problem, as show-cased in this paper. There are multiple models of devices where similar questions can be asked. Examples include counter automata, register automata, weighted automata, or pushdown automata.

Declarations
Competing interest The authors have no competing interests to declare that are relevant to the content of this article.
Open Access This article is licensed under a Creative Commons Attribution 4.0 International License, which permits use, sharing, adaptation, distribution and reproduction in any medium or format, as long as you give appropriate credit to the original author(s) and the source, provide a link to the Creative Commons licence, and indicate if changes were made. The images or other third party material in this article are included in the article's Creative Commons licence, unless indicated otherwise in a credit line to the material. If material is not included in the article's Creative Commons licence and your intended use is not permitted by statutory regulation or exceeds the permitted use, you will need to obtain permission directly from the copyright holder. To view a copy of this licence, visit http://creativecommons.org/licenses/by/4.0/.