{'fraction_non_alphanumeric': 0.05643623828053589, 'fraction_numerical': 0.009414744979237942, 'mean_word_length': 3.5685736443357396, 'pattern_counts': {'":': 0, '<': 79, '<?xml version=': 0, '>': 0, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 20, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
Towards an Efficient Tree Automata based technique for Timed Systems

The focus of this paper is the analysis of real-time systems with recursion, through the development of good theoretical techniques which are implementable. Time is modeled using clock variables, and recursion using stacks. Our technique consists of modeling the behaviours of the timed system as graphs, and interpreting these graphs on tree terms by showing a bound on their tree-width. We then build a tree automaton that accepts exactly those tree terms that describe realizable runs of the timed system. The emptiness of the timed system thus boils down to emptiness of a finite tree automaton that accepts these tree terms. This approach helps us in obtaining an optimal complexity, not just in theory (as done in earlier work), but also in going towards an efficient implementation of our technique. To do this, we make several improvements in the theory and exploit these to build a first prototype tool that can analyze timed systems with recursion.


Introduction
Development of efficient techniques for the verification of real time systems is a practically relevant problem. Timed automata [5] are a prominent and well accepted abstraction of timed systems. The development of this model originally began with highly theoretical results, starting from the PSPACE-decision procedure for the emptiness of timed automata. But later, this theory has led to the development of state of the art and industrial strength tools like UPPAAL [6]. Currently, such tools are being adapted to build prototypes that handle other systems such timed games, stochastic timed systems etc. While this helps in analysis of certain systems, there are complicated real life examples that require paradigms like recursion, multi-threaded concurrency and so on.
For timed systems with recursion, a popular theoretical framework is the model of timed pushdown automata (TPDA). In this model, in addition to clock variables as in timed automata, a stack is used to model recursion. Depending on how clocks and stack operations are integrated, several variants [7], [1], [13], [11], [8] have been looked at. For many of these variants, the basic problem of checking emptiness has been shown decidable (and EXPTIMEcomplete) using different techniques. The proofs in [7], [1], [13] work by adapting the technique of region abstraction to untime the stack and obtain a usual untimed pushdown automaton, while [8] gives a proof by reasoning with sets of timed atoms. Recently,in [4], a new proof technique was introduced which modeled the behaviours of the TPDA as graphs with timing constraints and analyzed these infinite collections of time-constrained graphs using tree automata. This approach follows the template which has been explored in depth for various untimed systems in [12], [10], [3]. The basic idea can be outlined as follows: (1) describe behaviours of the underlying system as graphs, (2) show that this class of graphs has bounded width, (3) either appeal to Courcelle's theorem [9] by showing that the desired properties are MSO-defineable or explicitly construct a tree-automaton to capture the class of graphs that are the desired behaviours. The work in [4] extends this approach to timed systems, by considering their behaviors as time-constrained words. The main difficulty here is to obtain a tree automaton that accepts only those time-constrained words that are realizable via a valid time-stamping.
Despite the amount of theoretical work in this area [7,12,10,4,1,8], none of these algorithms have been implemented to the best of our knowledge. Applying Courcelle's theorem is known to involve a blowup in the complexity (depending on the quantifieralternation of the MSO formula). The algorithm for checking emptiness in [4] for the timed setting which directly constructs the tree automaton avoiding the MSO translation also turns out to be unimplementable even for small examples due to the following reasons: First, it has a pre-processing step where each transition in the underlying automaton is broken into several micro transitions, one for each constraint that is checked there, and one corresponding to each clock that gets reset on that transition. This results in a blowup in the size of the automaton. Second, the number of states of the tree automaton that is built to check realizabilty as well as the existence of a run of a system is bounded by (M × T ) O(K 2 ) 2 O(K 2 lgK) , where M is one more than the maximal constant used in the given system, T is the number of transitions, and K = 4|X| + 6 is the so-called split-width, where |X| is the number of clocks used. This implies that even for a system that has 1 clock, 5 transitions and uses a maximum constant 5, we have more than 30 100 states.
In this paper, we take the first steps towards an efficient implementation. While we broadly follow the graph and tree-automata based approach (and in particular [4]), our main contribution is to give an efficient technique for analyzing TPDA. This requires several fundamental advances: (i) we avoid the preprocessing step, obtaining a direct bound on tree width for timed automata and TPDA. This is established by playing a split-game which decomposes the graph representing behaviours of the timed system into tree terms; by coloring some vertices of the graph and removing certain edges whose endpoints are colored. The minimum number of colors used in a winning strategy is 1 plus the tree-width of the graph. (ii) we develop a new algorithm for building the tree automaton for emptiness, whose complexity is in ETIME, i.e., bounded by (M × T ) 3|X|+3 with an exponent which is a linear function of the input size (improved from EXPTIME, where the exponent is a polynomial function of the input). Thus, if the system has 1 clock, 5 transitions and uses a maximum constant 5, we have only ∼ 30 6 states. In particular, our tree-automaton is strategy-driven, i.e., it manipulates only those tree terms that arise out of a winning strategy of our split-game. As a result of this strategy-guided approach, the number of states of our tree automaton is highly optimized, and an accepting run exactly corresponds to the moves in a winning strategy of our split-game. (iii) Finally, our algorithm outputs a witness for realizability (and non-emptiness). As a proof-of-concept, we implemented our algorithm and despite the worst-case complexity, in Section 6, we discuss optimizations, results and a modeling example where our implementation performs well.

Graphs for behaviors of timed systems
We fix an alphabet Σ and use Σ ε to denote Σ ∪ {ε}, where ε is the silent action. We also fix a finite set of intervals I with bounds in N ∪ {∞}. For a set S, we use ≤ ⊆ S × S to denote a partial or total order on S. For any x, y ∈ S, we write x < y if x ≤ y and x = y, and x y if x < y and there does not exist z ∈ S such that x < z < y.

Abstractions of timed behaviors
Definition 1. A word with timing constraints (TCW) over (Σ, I) is a structure V=(V, →, λ, ( I ) I∈I ) where V is a finite set of vertices or positions, λ : V → Σ ε labels each position, the reflexive transitive closure ≤ = → * is a total order on V and → = is the successor relation, while I ⊆ < connects pairs of positions carrying a timing constraint, given by an interval in I ∈ I. A TCW V=(V, →, λ, ( I ) I∈I ) is called realizable if there exists a timestamp map ts : V → R + such that ts(i) ≤ ts(j) for all i ≤ j (time is non-decreasing) and ts(j) − ts(i) ∈ I for all i I j (timing constraints are satisfied).
An example of a TCW is given in Figure 1 (right), with positions 0, 1, 2, 3 labelled by Σ = {a, b, c}. Curved edges decorated with intervals connect positions related by I , while straight edges define the successor relation →. This TCW is realizable by the sequence of timestamps 0, 0.9, 2.89, 3.1 but not by 0, 0.9, 2.99, 3.1. We let Real(Σ, I) be the set of TCWs over (Σ, I) which are realizable.

TPDA and their semantics as TCWs
Dense-timed pushdown automata (TPDA), introduced in [1], are an extension of timed automata, and operate on a finite set of real-valued clocks and a stack which holds symbols with their ages. The age of a symbol represents the time elapsed since it was pushed onto the stack. Formally, a TPDA S is a tuple (S, s 0 , Σ, Λ, ∆, X, F ) where S is a finite set of states, s 0 ∈ S is the initial state, Σ, Λ, are respectively finite sets of input, stack symbols, ∆ is a finite set of transitions, X is a finite set of real-valued variables called clocks, F ⊆ S are final states. A transition t ∈ ∆ is a tuple (s, γ, a, op, R, s ) where s, s ∈ S, a ∈ Σ, γ is a finite conjunction of atomic formulae of the kind x ∈ I for x ∈ X and I ∈ I, R ⊆ X are the clocks reset, op is one of the following stack operations: 1. nop does not change the contents of the stack, 2. ↓ c , c ∈ Λ is a push operation that adds c on top of the stack, with age 0. 3. ↑ I c , c ∈ Λ is a stack symbol and I ∈ I is an interval, is a pop operation that removes the top most symbol of the stack provided it is a c with age in the interval I.
Timed automata (TA) can be seen as TPDA using nop operations only. This definition of TPDA is equivalent to the one in [1], but allows checking conjunctive constraints and stack operations together. In [8], it is shown that TPDA of [1] are expressively equivalent to timed automata with an untimed stack. As our technique is oblivious to whether the stack is timed or not, we focus on the syntactically more succinct model TPDA with a timed stack.
Next, we define the semantics of a TPDA in terms of TCWs.
is said to be generated or accepted by a TPDA S if there is an accepting abstract run ρ = (s 0 , γ 1 , a 1 , op 1 , R 1 , s 1 ) (s 1 , γ 2 , a 2 , op 2 , R 2 , s 2 ) · · · (s n−1 , γ n , a n , op n , R n , s n ) of S such that, s n ∈ F and the sequence of push-pop operations is well-nested: in each prefix op 1 · · · op k with 1 ≤ k ≤ n, number of pops is at most number of pushes, and in the full sequence op 1 · · · op n , they are equal; and V = {0, 1, . . . , n} with λ(0) = ε and λ(i) = a i for all 1 ≤ i ≤ n and 0 → 1 → · · · → n and, for all I ∈ I, the relation I is the set of pairs (i, j) with 0 ≤ i < j ≤ n such that Figure 1 A timed automaton and a TCW capturing a run either for some x ∈ X we have x ∈ R i (assuming R 0 = X) and x ∈ I is a conjunct of γ j and x / ∈ R k for all i < k < j, is a push and op j = ↑ I b is the matching pop (same number of pushes and pops in op i+1 · · · op j−1 ).
We denote by TCW(S) the set of TCWs generated by S. The non-emptiness problem for the TPDA S amounts to asking whether some TCW generated by S is realizable, i.e., whether TCW(S) ∩ Real(Σ, I) = ∅. The TCW semantics of timed automata (TA) can be obtained from the above discussion by just ignoring the stack components (using nop operations only). Figure 1 depicts a simple example of a timed automaton and a TCW generated by it.
Remark. The classical semantics of timed systems is given in terms of timed words. A timed word is a sequence w = (a 1 , t 1 ) · · · (a n , t n ) with a 1 , . . . , a n ∈ Σ and (t i ) 1≤i≤n is a non-decreasing sequence of values in (1)) . . . (λ(n), ts(n)) where the timestamp map ts : V → R + (with ts(0) = 0) is non decreasing and satisfies all timing constraints of V. For example, the timed word (a, 0.9)(b, 2.89)(c, 3.1) is a realization of the TCW in Figure 1 while (a, 0.9)(b, 2.99)(c, 3.1) is not. It is not difficult to check that the language L(S) of timed words accepted by S with the classical semantics is precisely the set of realizations of TCWs in TCW(S). Therefore, L(S) = ∅ iff TCW(S) ∩ Real(Σ, I) = ∅.
We now identify some important properties satisfied by TCWs generated from a TPDA. Let V = (V, →, λ, ( I ) I∈I ) be a TCW. The matching relation ( I ) I∈I is used in two contexts: (i) while connecting a clock reset point (say for clock x) to a point where a guard of the form x ∈ I is checked, and (ii) while connecting a point where a push was made to its corresponding pop, where the age of the topmost stack symbol is checked to be in interval I. We use the notations x∈I and s∈I to denote the matching relation I corresponding to a clock-reset-check as well as push on stack-check respectively. We say that V is well timed w.r.t. a set of clocks X and a stack s if for each interval I ∈ I the matching relation I can be partitioned as I = s∈I x∈X x∈I where (T 1 ) the stack relation s = I∈I s∈I corresponds to the matching push-pop events, hence it is well-nested: for all i s j and i s j , if i < i < j then j < j.
(T 2 ) For each x ∈ X, the clock relation x = I∈I x∈I corresponds to the timing constraints for clock x and respects the last reset condition: for all i x j and i x j , if i < i , then j ≤ i . See Figure 1 for example, where 0 x 2 and 2 x 3.
It is then easy to check that TCWs defined by a TPDA with set of clocks X are well-timed for the set of clocks X, i.e., satisfy the properties above. We obtain the same for TA by just ignoring the stack edges, i.e., (T 1 ) above.

Tree-Width for Timed Systems
In this section, we discuss tree-algebra by introducing the basic terms, the operations on terms, their syntax and semantics. This will help us in analyzing the graphs obtained in the previous section using tree-terms, and establishing a bound on the tree-width. We introduce tree terms TTs from Courcelle [9] and their semantics as graphs which are both vertex-labeled and edge-labeled. Let Σ be a set of vertex labels and let Ξ be a set of edge labels. Let K ∈ N. The syntax of K-tree terms K-TTs over (Σ, Ξ) is given by . . , K} are colors (i = j), a, b ∈ Σ are vertex labels and ξ ∈ Ξ is an edge label. The semantics of a K-TT τ is a colored graph τ = (G τ , χ τ ) where G τ = (V, E) is a graph and χ τ : {1, 2, . . . , K} → V is a partial injective function assigning a color to some vertices of G τ . Note that any color in {1, 2, . . . , K} is assigned to at most one vertex of G τ .
The atomic term (a, i) is a single vertex colored i and labeled a and the atomic term (a, i)ξ(b, j) represents a ξ-labeled edge between two vertices colored i, j and labeled a, b respectively. Given a tree term τ , Forget i (τ ) forgets the color i from a node colored i, leaving it uncolored. The operation Rename i,j (τ ) renames the color i of a node to color j, provided no nodes are already colored j. Since any color appears at most once in G τ , the operations Forget i (τ ) and Rename i,j (τ ) are deterministic, when colors i, j, are fixed. Finally, the operation τ 1 ⊕ τ 2 (read as combine) combines two terms τ 1 , τ 2 by fusing the nodes of τ 1 , τ 2 which have the same color. See Figure 2.
The tree-width of a graph G is defined as the least K such that G = G τ for some TT τ using K + 1 colors. Let TW K denote the set of all graphs having tree width at most K. For TCWs, we have successor edges → and matching edges I where I ∈ I is an interval. Hence, the set of edge labels is Ξ I = {→} ∪ { I | I ∈ I} and we use TTs over (Σ, Ξ I ). An example is given in Appendix A.

TCWs and Games
We find it convenient to prove that TCWs have bounded tree-width by playing a game, whose game positions are TCWs in which some successor edges may have been cut, i.e., are missing. Such TCWs, where some successor edges may be missing, are called split-TCWs. A split-TCW which is a connected graph is called a connected split-TCW, while a split-TCW which is a disconnected graph, is called a disconnected split-TCW. For example, is a connected split-TCW, while is a disconnected split-TCW consisting of two connected split TCWs, namely and . A TCW is atomic if it is denoted by an atomic term ((a, i) or (a, i) → (b, j) or (a, i) I (b, j)). The split-game is a two player turn based game G = (Pos ∃ Pos ∀ , Moves) where Eve's set of game positions Pos ∃ consists of all connected (wrt. → ∪ ) split-TCWs and Adam's set of game positions Pos ∀ consists of dis-connected split-TCWs. Eve's moves consist of adding colors to the vertices of the split-TCW, and dividing the split-TCW. For example, if we have the connected split-TCW , and Eve colors two nodes (we use shapes in place of colors for better visibility) we obtain . This graph can be divided obtaining the disconnected graph and . As a result, we obtain the connected parts and and . Now Adam's choices are on this disconnected split-TCW and he can choose either of the above three connected split-TCWs to continue the game. Thus, divide is the reverse of the combine operation ⊕. Adam's moves amount to choosing a connected component of the split-TCW. Eve has to continue coloring and dividing on the connected split-TCW chosen by Adam. Atomic split-TCWs are terminal positions in the game: neither Eve nor Adam can move from an atomic split-TCW. A play on a split-TCW V is a path in G starting from V and leading to an atomic split-TCW. The cost of the play is the maximum width (number of colors-1) of any split-TCW encountered in the path. In our example above, is already an atomic split-TCW. If Adam chooses any of the other two, it is easy to see that Eve has a strategy using at most 2 colors in any of the split-TCWs that will be obtained till termination. The cost of a strategy σ for Eve from a split-TCW V is the maximal cost of the plays starting from V and following strategy σ. The tree-width of a (split-)TCW V is the minimal cost of Eve's (positional) strategies starting from V. Let TCW K denote the set of TCWs with tree-width bounded by K.
A block in a split-TCW is a maximal set of points of V connected by →. For example, the split-TCW has one non-trivial block and one trivial block . Points that are not left or right endpoints of blocks of V are called internal.
The Bound. We show that we can find a K such that all the behaviors of the given timed system have tree-width bounded by K.
Theorem 3. Given a timed system S using a set of clocks X, all graphs in its TCW language have tree-width bounded by K, i.e., TCW(S) ⊆ TCW K , where 1. K = |X| + 1 if S is a timed automaton, 2. K = 3|X| + 2 if S is a timed pushdown automaton.
The following lemma completes the proof of Theorem 3 (2).
Lemma 4. The tree-width of a well-timed TCW is bounded by 3|X| + 2.
We prove this by playing the "split game" between Adam and Eve in which Eve has a strategy to disconnect the word without introducing more than 3|X| + 3 colors. Eve's strategy processes the word from right to left. Starting from any TCW, Eve colors the end points of the TCW, as well as the last reset points (from the right end) corresponding to each clock. Here she uses at most |X| + 2 colors. On top of this, depending on the last point, we have different cases. A detailed proof can be seen in Appendix B, while we give a sketch here.
If the last point is the target of a x edge for some clock x, then Eve simply removes the clock edge, since both the source and target points of this edge are colored. We only discuss in some detail the case when the last point is the target of a s edge, and the source of this edge is an internal point in the non-trivial block. Figure 3 illustrates this case.
To keep a bound on the number of colors needed, Eve divides the TCW as follows: First Eve adds a color to the source of the stack edge If there are any clock edges crossing this stack edge, Eve adds colors to the corresponding reset points. Note that this results in adding atmost |X| colors. Eve disconnects the TCW into two parts, such that the right part V 2 consists of one non-trivial block whose end points are the source and target points of the stack edge, and also contains to the left of this block, atmost |X| trivial blocks. Each of these trivial blocks are the reset points of those clock edges which cross over. The left part V 1 is a TCW consisting of all points to the left of the source of the stack edge, and has all remaining edges other than the clock edges which have crossed over. Adam can now continue the game choosing V 1 or V 2 . Note that in one of the words so obtained, the stack edge completely spans the non-trivial block, and can be easily removed.

Figure 3
The last point is the target of a s (top figure). After the split, we obtain the words V1 (the middle one) and V2 (the bottom one).
Invariants and bound on tree-width. We now discuss some invariants on the structure of the split-TCWs as we play the game using the above strategy.
(I1) We have ≤ |X| colored trivial blocks to the left of the only non-trivial block, (I2) The last reset node of each clock on the non-trivial block is colored, (I3) The end points of the non-trivial block are colored.
To maintain the above invariants, we need |X| + 1 extra colors than the at most 2|X| + 2 mentioned above. This proves that the tree-width of a TPDA with set of clocks X is bounded by 3|X| + 2. If the underlying system is a timed automaton, then we have a single non-trivial block in the game at any point of time. There are no trivial blocks, unlike the TPDA, due to the absence of stack edges. This results in using only ≤ |X| + 2 colors at any point of time, where |X| colors are needed to color the last reset points of the clocks in the block, and the remaining two colors are used to color the right and left end points of the block.

Tree automata for Validity
In this section, we give one of the most challenging constructions (Theorem 6) of the paper, namely, the tree automaton that accepts all valid and realizable K-TTs which are "good". Good K-TTs are defined below. In this section, we restrict ourselves to closed intervals; that is, those of the form [a, b] and [a, ∞), where a, b ∈ N. Fix K ≥ 2. Not all graphs defined by K-TTs are realizable TCWs. Indeed, if τ is such a TT, the edge relation → may have cycles or may be branching, which is not possible in a TCW. Also, the timing constraints given by I need not comply with the → relation: for instance, we may have a timing constraint e I f with f → + e (→ + is the transitive closure of →, i.e., e can be reached from f after taking ≥ 1 successor edges →). Moreover, some terms may define graphs denoting TCWs which are not realizable. So we use A K,M valid to check for validity. Since we have only closed intervals in timing constraints, integer timestamps suffice for realizability, as can be seen from the following lemma (Appendix C.1).
) be a TCW using only closed intervals in its timing constraints. Then, V is realizable iff there exists an integer valued timestamp map satisfying all timing constraints.
Consider a set of colors P ⊆ {1, . . . , K}. For each i ∈ P we let i + = min{j ∈ P ∪ {∞} | i < j} and i − = max{j ∈ P ∪ {0} | j < i}. If P is not clear from the context, then we write next P (i) and prev P (i). Given a K-TT τ with semantics τ = (G, χ), we denote by Act = dom(χ) the set of active colors in τ , we let Right = max(Act) and Left = min{i ∈ Act | χ(i) → * χ(Right)}. If τ is not clear from the context, then we write Act τ , Left τ and Rename4,5  Table 1 The second row gives tree representations of three good 6-TTs τ1, τ2, τ3. In all these terms, we ignore vertex labels and we use Add I i,j τ as a macro for τ ⊕ i I j. The third row gives their semantics τ = (Gτ , χτ ) together with a realization ts, the fourth row gives possible states q of A K,M valid with M = 4 after reading the terms. Here, L is the circled color. The boolean value acc(i) for each non maximal color i is written between tsm(i) and tsm(i + ).
The intuition is that these good tree terms will give rise to split TC words preserving invariants (I1)-(I3) of the previous section, following the strategy driven approach. In addition, we ensure that the natural order on the colors is consistent with the linear ordering of the points of the TCW.
Examples of good TTs and their semantics are given in Table 1. Note that the semantics of a K-TT τ is a colored graph τ = (G τ , χ τ ). Below, we provide a direct construction of a tree automaton, which gives a clear upper bound on the size of A K,M valid , since obtaining this bound gets very technical if we stick to MSO.

Theorem 6. We can build a tree automaton
is the set of good K-TTs τ such that τ is a realizable TCW and the endpoints of τ are the only colored points.

Proof. The tree automaton A K,M
valid reads the TT bottom-up and stores in its state a finite abstraction of the associated graph. The finite abstraction will keep only the colored points of the graph. We will only accept good terms for which the natural order on the active colors coincides with the order of the corresponding vertices in the final TCW. The restriction to good terms ensures that the graph defined by the TT is a split-TCW.
Moreover, to ensure realizability of the TCW defined by a term, we will guess timestamps of vertices modulo M . We also guess while reading a subterm whether the time elapsed between two consecutive active colors is big (≥ M ) or small (< M ). We see below that the time elapsed is small iff it can be recovered accurately with the modulo M abstraction.
is a transition if i < j and P = {i, j}, L = i and acc(j) = ff. The values for tsm(i), tsm(j) and acc(i) are guessed.
is a transition if i < j and P = {i, j}, L = j and acc(j) = ff. Here, i and j are trivial blocks. The values for tsm(i), tsm(j) and acc(i) are guessed such that (acc(i) = tt and d(i, j) ∈ I) or (acc(i) = ff and I.up = ∞).
Renamei,j q = (P, L, tsm, acc) Then, q is obtained from q by replacing i by j.
(we cannot insert a new point from the second argument in the non-trivial block of the first argument). P = P1 ∪ P2, L = L1, and tsm |P 1 = tsm1 and tsm |P 2 = tsm2: these updates are deterministic. In particular, this implies that tsm1 and tsm2 coincide on P1 ∩ P2.
Finally, acc satisfies acc(max(P )) = ff and  Figure 6 for some intuitions. I.up in row 2 represents upper bound of interval I.
Then, the automaton has to check that all these guesses are coherent and using these values it will check that every timing constraint is satisfied.
Formally, states of A K,M valid are tuples of the form q = (P, L, tsm, acc), where P ⊆ {1, . . . , K}, L ∈ P , tsm : P → [M ] = {0, . . . , M − 1} and acc : P → B. acc is a flag which stands for "accurate", and is used to check if the time elapse between two points is accurate or not, based on the time stamps.
Intuitively, when reading bottom-up a K-TT τ with τ = (V, →, λ, ( I ) I∈I , χ), the automaton A K,M valid will reach a state q = (P, L, tsm, acc) such that This extra relation serves at ordering the blocks of a split-TCW. Then, ( τ , ) is an ordered split-TCW, i.e., < = (→ ∪ ) + is a total order on V , timing constraints in τ are <-compatible I ⊆ < for all I, the direct successor relation of < is = → ∪ and → ∩ = ∅. Moreover, targets of timing constraints are in the last block: for all and acc(i) = tt iff i + = ∞ and ts(χ(i + )) − ts(χ(i)) < M .
We say that the state q is a realizable abstraction of a term τ if it satisfies conditions (A 1 -A 4 ).
Indeed, the finite state automaton A K,M valid cannot store the timestamp map ts witnessing realizability. Instead, it stores the modulo M abstraction (tsm, acc). We will see that A K,M valid can check realizability based on the abstraction (tsm, acc) of ts and can maintain this abstraction while reading the term bottom-up.
We introduce some notations. Let q = (P, L, tsm, acc) be a state and let i, . For instance, with the state q 3 corresponding to the term τ 3 of Table 1 Table 2. Accepting condition. The accepting states of A K,M valid should correspond to abstractions of TCWs. Hence the accepting states are of the form ({i, j}, L, tsm, acc) with i, j ∈ {1, . . . , K}, i < j, L = i and acc(j) = ff. The correctness of this construction is in Appendix C.2, and is obtained by proving (i) the transitions of A K,M valid indeed preserve the conditions (A 1 -A 4 ), (ii) (A 1 -A 4 ) ensure among other things, that the boolean values acc(i), ACC(i, j) for i < j indeed defines when the elapse of time is accurately captured by the modulo M abstraction: that is, ACC(i, j) is true iff the actual time elapse between i and j is captured using the modulo M abstraction D(i, j).

Tree automata for timed systems
The goal of this section is to build a tree automaton which accepts tree terms denoting TCWs accepted by a TPDA. The existence of a tree automaton can be proved by showing the MSO definability of the runs of the TPDA S on a TCW. However, as seen in section 4, we directly construct a tree automaton for better complexity. Given the timed system S, let K be the bound on tree-width given by Theorem 3 and let M be one more than the maximal constant occurring in the guards of S. The automaton A K,M S will accept good K-TTs with the additional restriction that a timing constraint is immediately combined with an existing term. That is, restricted K-TTs are good K-TTs restricted to the following syntax: Theorem 7. Let S be a TPDA of size |S| (constants encoded in unary) with set of clocks X and using constants less than M . Let K be the bound on tree-width given by Theorem 3. Then, we can build a tree automaton P is the set of active colors, and L = Left ∈ P is the left-most point that is connected to the right-end-point R = Right = max(P ) by successor edges on the non-trivial block. δ is a map that assigns to each color k ∈ P the transition δ(k) guessed at the leaf corresponding to color k, Push and Pop are two boolean variables: Push = 1 iff a push-pop edge has been added to L and Pop = 1 iff a push-pop edge has been added to R, G = (G x ) x∈X is a boolean vector of size |X|: for each clock x ∈ X, G x = 1 iff some constraint on x has already been checked at R, Z = (Z x ) x∈X assigns to each clock x either the color i ∈ P with i < L of the unique point on the left of the non-trivial block which is the source of a timing constraint i I j for clock x, or ⊥ if no such points exist.
For j ∈ P , let Reset(j) be the set of clocks that are reset in the transition δ(j). We describe here the most involved kind of transition q ⊕ q for states q , q . The remaining transitions as well as the full proof can be seen in Appendix D. Let q = (P , L , δ , Push , Pop , G , Z ), q = (P , L , δ , Push , Pop , G , Z ) and q = (P, L, δ, Push, Pop, G, Z). Then q , q ⊕ − → q is a transition if the following hold: from the second argument in the non-trivial block of the first argument). Note that according to C 1 , the points , and in P lying between L , R are already points in the non-trivial block connecting L to R . C 2 : ∀i ∈ P ∩ P , δ (i) = δ (i) (the guessed transitions match). By C 2 , the transitions δ , δ of , and must match. C 3 : if there is a Push operation in δ (L ) then Push = 1 and if there is a pop operation in δ (R ) then Pop = 1 (the push-pop edges corresponding to the merging point have been added, if they exist). By C 3 , if δ(R ) = δ(L ) contains a pop (resp. push) operation then R = L is the target (resp. source) of a push-pop edge. C 4 : if some guard x ∈ I is in δ(R ), then G x = 1 (before we merge, we ensure that the clock guard for x in the transition guessed at R , if any, has been checked). After the merge, R = L becomes an internal point; hence by C 4 , any guard x ∈ I in δ (R ) must be checked already, i.e., G x = 1. After the merge, it is no more possible to add an edge I leading into R . a matching edge starting at Z x < L had been seen earlier in run leading to q , then x should not have been reset in q between Z x and L , else it would violate the consistency of clocks). By C 5 , if Z x is (resp. ), i.e., (resp. ) is the source of a timing constraint I for clock x whose target is in the L -R block, then clock x cannot be reset at and (resp. ). a matching edge starting at Z x < L had been seen earlier in run leading to q , then x should not have been reset in q between Z x and L ). By C 6 , if Z x is , then x cannot be reset at , , , or . Likewise, if Z x was , then clock x cannot be reset at , , or .
C 7 says that on merging, we obtain the third split-TCW. After the merge, if Z x is defined, it must be on the left of L , i.e., one of , , , . Notice that the above three conditions ensure the well-nestedness of clocks. By C 5 and is some dummy ε-transition resetting all clocks and leading to the initial state, target(δ(R)) is a final state and if δ(R) has a pop operation then Pop = 1, if it has a constraint/guard for clock x, then G x = 1. Note that the above automaton only accepts restricted K-TTs; this is sufficient for emptiness checking since Eve's winning strategy in Section 3 captures all behaviours of the TCW(S) while generating only restricted K-TTs. As a corollary we obtain (see Appendix D.2), If the underlying system is a timed automaton, we can restrict the state space to storing just the tuple (P, δ, G) as the other components are not required and L is always min(P ).
Possible Extensions. We now briefly explain how to extend our technique in the presence of diagonal guards: these are guards of the form x − y ∈ I or x − pop ∈ I or pop − x ∈ I where x, y are clocks, and I is a time interval. The first is a guard that checks the difference between two clock values, while the other two check the difference between the value of a clock and the age of the topmost stack symbol at the time of the pop. To handle a constraint of the form x − y ∈ I, it is enough to check the difference between the guessed time stamps at the last reset points of clocks y, x to be in I. Likewise, to check x−pop ∈ I or pop−x ∈ I, we check the difference between the guessed time stamps at the points where the top symbol was pushed on the stack and the last reset of clock x. Based on the strategy-guided approach for building the tree automaton, note that the last reset points of x, y will not be forgotten until the automaton decides to accept; likewise, the push point will not be forgotten until the pop transition is encountered. Given this, our construction of the tree automaton can be extended with the above checks to handle diagonal guards as well.

Implementation and a case-study
We have implemented the emptiness checking procedure for TPDA using our tree-automata based approach, and describe some results here. As discussed earlier, the EXPTIME-completeness of this problem for TPDA in general 1 suggests that in the worst-case, we cannot really hope to do well. However, for certain interesting subclasses of TPDA, we obtain good performance results.
As a concrete subclass, the complexity significantly improves when there is no extra clock other than the timing constraints associated with the stack; while popping a symbol, we simply check the time elapsed since the push. Note that this can be used to model systems where timing constraints are well-nested: clock resets correspond to push and checking guards corresponds to checking the age of the topmost stack symbol. Thus, this gives a technique for reducing the number of clocks for a timed system with nested timing constraints. For this subclass, the exact number of states of the tree automaton can be improved to 2 × (M × T ) 2 , where M is 1 plus the maximum constant, and T is the number of transitions. This idea can be extended further to incorporate clocks whose constraints are well-nested with respect to the stack. We can also handle clocks which are reset and checked in consecutive transitions. For the general model (one stack + any number of clocks), we can use optimizations to reduce the number of states of the tree automaton to (M × T ) 2|X|+2 × 2 2|X|+1 , where |X| is the number of clocks, M is 1 plus the maximum constant and T is the number of transitions. To see this, consider the worst case scenario, where a state of the tree automaton has |X| hanging points and |X| reset points. In total there can be 2|X| + 2 active points including Figure 4 A simple maze. Every junction, dead end, entry point or exit point is called a place, numbered from 1 to 7. 6 is the entry, 2 the exit, 1, 7 and 4 are dead ends. Time intervals denote the time taken between adjacent places; e.g., between 1 and 2 time units must elapse between places 3 and 7. On the right, is the TPDA model of the maze.
the left and right end-points of the non-trivial block. After a combine operation, we can forget a point i of the new state, if it is the case that every clock x reset at the transition (guessed) at point i is also reset at some transition at a point after i. Following this strategy, if we aggressively forget as many points as we can, we will have at most |X| internal (reset) active points between the left and right end-points of the non-trivial block. Thus, we reduce the number of active points from 3|X| + 2 to 2|X| + 2. As a proof of concept, we have implemented our approach with these optimizations. We will now describe some examples we modelled and their experimental results. These experiments were run on a 3.5 GHz i5 PC with 8GB RAM, with number of cores=4.

A Modeling Example : Maze with Constraints
As a first interesting example, we model a situation of a robot successfully traversing a maze respecting multiple constraints (see Figure 4). These constraints may include logical constraints: the robot must visit location 1 before exit, or the robot must load something at a certain place i and unload it at another place j (so number of visits to i must equal visits to j). We may also have local and global time constraints which check whether adjacent places are visited within a time bound, or the total time taken in the maze is within a given duration. We show below, via an illustrative example, that certain classes of such constraints can be converted into a 1-clock TPDA.
One can go from place p to some of its adjacent place q if there is an arrow from place p to place q. In addition, the following types of constraints must be respected.

1.
Logical constraints specify certain order between visiting places, the number of times (upper/lower bounds) to visit a place or places, and so on. The logical constraints we have in our example are (a) place 1 must be visited exactly once, (b) from the time we enter the maze, to visiting place 1, one must visit place 7 (load) and place 4 (unload) equal number of times, and at any point of time, the number of visits to place 7 is not less than number of visits to place 4. (c) from visiting place 1 to exiting the maze, one must visit place 7 and place 4 equal number of times and, at any point during time, number of visits to place 7 is not less than number of visits to place 4. 2. Local time constraints specify time intervals which must be respected while going from a place to its adjacent place. The time taken from some place i to another adjacent place j is given as a closed interval [a, b] along with the arrow. One cannot spend any time between a pair of adjacent places other than the ones specified in the maze. For example, the time bound for going from place 7 to 3 is given, while the time taken from place 3 to place 7 and place 6 to place 1 is zero ([0,0]), since it is not mentioned. Further, one cannot stay in any place for non-zero duration. 3. Global time constraints specify the total time that can be elapsed between visiting any two places. From entering into the maze to visiting of place 1, time taken should be exactly m units (a parameter). From visiting place 1 to exit, time bound should be exactly n units (another parameter).
A maze respecting multiple constraints as above is converted into a 1-clock TPDA. While the details of this conversion are given in Appendix E, the main idea is to encode local time bounds with the clock which is reset on all transitions. A logical constraint specifying equal number of visits to places p 1 , p 2 is modelled by pushing symbols while at p 1 , and popping them at p 2 . Likewise, if there is a global time constraint that requires a time elapse in [a, b] between the entry and some place p, then push on the stack at entry, and check its age while at p. Note that all these are well-nested properties.
To check the existence of a legitimate path in the maze respecting the constraints, our tool checks the existence of a run in the TPDA. By running our tool on the TPDA constructed (and fixing the parameters to be m = 7, n = 8), we obtain the following run:

Conclusion
We have obtained a new construction for the emptiness checking of TPDA, using tree-width. The earlier approaches [1], [2] which handle dense time and discrete time push down systems respectively use an adaptation of the well-known idea of timed regions. The technique in [2] does not extend to dense time systems, and it is not clear whether the approach in [1] will work for say, multi stack push down automata even with bounded scope/phase restrictions. Unlike this, our approach is uniform : all our proofs except the tree automaton for realizability already work even if we have open guards. Our realizability proof has to be adapted for open guards and this is work under progress; in this paper, we focussed on closed guards to obtain an efficient tool based on our theory. Likewise, our proofs can be extended to bounded phase/scope/rounds multi stack timed push down automata : we need to show a bound on the tree-width, and then adapt the tree automaton construction for the system automaton. The tree automaton checking realizability requires no change. Further, our ETIME complexity is the best known upper bound, as far as we know. With the theoretical improvements in this paper, we implement our approach and examine its performance on real examples. To the best of our knowledge, this is the first tool implementing timed push down systems. We plan to optimize our implementation to get a more robust and scalable tool : for instance, when the language is non-empty, a witness for non-emptiness can be produced. For the subclasses we have, it would be good to have a characterization and automatic translation (currently this is done by hand) that replaces well-nested clock constraints by stack edges, and thus leading to better implementability. We also plan to extend our implementations to give bounded under-approximations for timed automata with multiple stacks that can be used to model and analyze recursive programs with timers.  Figure 5 shows the construction of a TCW using tree terms. The example uses 4 colors: think of the shapes as colors. The example starts out with 3 atomic terms, and builds the TCW using the operations of combine and forget. In each step, the resultant TCW obtained is drawn in the dialogue box.

Figure 5
An example constructing a TCW using atomic tree terms

B Proof of Lemma 4
We prove this by playing the "split game" between Adam and Eve in which Eve has a strategy to disconnect the word without introducing more than 3|X| + 3 colors. Eve's strategy processes the word from right to left. Starting from any TCW, Eve colors the end points of the TCW, as well as the last reset points (from the right end) corresponding to each clock. Here she uses at most |X| + 2 colors. On top of this, depending on the last point, we have different cases. A detailed example of the split-game is given in Table 3.

1.
If the last point is the target of a x relation for some clock x, then Eve's strategy is to divide the TCW by removing the clock edge (Step 2 in Table 3). Notice that the source and target points of this clock edge are colored. This results in two TCWs, one of which is atomic, consisting of the matching clock edge, while in the other TCW, the last point is no longer the target of a matching relation for x. We apply Case 1 until the last point of the TCW is no longer the target of a clock edge z . 2. If the last point is not the target of a relation, then Eve adds a color to the immediate previous point and divides the TCW removing the atomic edge consisting of the last two points (Step 3 of Table 3). Note that when this last point happens to be a reset point for some clock x, then while removing this point as explained above, Eve also adds a color to the new last reset point for x in the resulting TCW. This ensures that the last reset points for every clock x is colored. 3. The most interesting case is when the last point is the target of a s relation of the stack. There are two cases here. The simple case is when the source and target nodes Consider the following TCW with two clocks. The green and blue edges represent two clocks while the red edges represent the stack.
Step 1: In the figure below, Eve adds colors to end points, and to last reset points.
Step 2: Eve removes the last clock edge, and adds a color to the before last point.
Step 3: This enables a divide, resulting in the removal of . The last point of the resultant word will be . This point is also removed after removing the clock edge, and adding a color to the preceding point, making it . This will be the last point now, and is the target of a stack edge.
Step 4: Eve adds a color to the source of the stack edge and to the reset points of clock edges which cross over the stack. This enables a divide, resulting in two words shown below Step 5: Yet another divide when the last point is the target of a stack edge, and the source of the stack edge is an internal point. In this case, both resultant words have trivial blocks and one non-trivial block. of the stack edge are the end points of a non-trivial block in the TCW. In this case, Eve simply disconnects the stack edge. The harder case is when the source of the stack edge is an internal point. In this case, unlike the removal of the clock edge, adding a color to the source of the stack edge and removing it is not a good strategy since we might have unboundedly many stack edges, resulting in the use of unboundedly many colors. To keep a bound on the number of colors needed, Eve divides the TCW as follows: First Eve adds a color to the source of the stack edge If there are any clock edges crossing this stack edge, Eve adds colors to the corresponding reset points. Note that this results in adding atmost |X| colors. Eve disconnects the TCW into two parts, such that the right part V 2 consists of one non-trivial block whose end points are the source and target points of the stack edge, and also contains to the left of this block, atmost |X| trivial blocks. Each of these trivial blocks are the reset points of those clock edges which cross over. The left part V 1 is a TCW consisting of all points to the left of the source of the stack edge, and has all remaining edges other than the clock edges which have crossed over. Adam can now continue the game choosing V 1 or V 2 . We illustrate this case below. Note that in one of the words so obtained, the stack edge completely spans the non-trivial block, and can be easily removed.
Invariants and bound on tree-width. We now discuss some invariants on the structure of the split-TCWs as we play the game using the above described strategy of Eve. The last two split TCWs in Table 3 are representatives of the split TCWs that may occur during the game after a divide operation. These TCWs satisfy the following invariants: (I1) We have at most |X| colored trivial blocks to the left of the only non-trivial block, (I2) The last reset node of each clock on the non-trivial block is colored (I3) The end points of the non-trivial block are colored To maintain the above invariants, we need |X| + 1 extra colors than the at most 2|X| + 2 mentioned above. To prove the bound on the tree-width, we use the following lemma.
Lemma 9. Any split TCW formed during the game has exactly one non-trivial block. It is divided using Eve's strategy described above using at most 3|X| + 3 colors, and the resultant words satisfy (I1-I3). The tree-width is hence at most 3|X| + 2.
Proof. Let us start from a split TCW satisfying (I1)-(I3). The case when the last point is not the target of a clock/stack edge is easy: we simply add one color to the predecessor of the last point, and detach the linear edge. If this point was a reset point of say clock x, then we need to add a color to the last reset point of x to maintain the invariant. Note that Eve's strategy does this. If the last point is the target of a clock edge, then simply removing the clock edge suffices. In both cases, the invariant is satisfied. Now consider the case when the last point is the target of a stack edge. The simple case is when the stack spans the non-trivial block. In this case, we simply remove the stack edge, preserving the invariant. If the source of the stack is an internal point in the non-trivial block, then as in steps 4 and 5 of Table 3, the resulting split-TCWs V 1 and V 2 will consist of a non-trivial block, and trivial blocks to its left, corresponding to the resets of clocks whose edges cross over to the block. The number of colors in V 2 is hence at most 2|X| + 2 (|X| + 2 on the non-trivial block and |X| to the left of the block). Whenever the right most point is the target of a stack edge which does not span the non-trivial block, then Eve has to repeat case 3 above by (1) adding a color to the source of the stack edge, (2) color the reset points to the left of the source of the stack edge, of those clocks whose edges cross over. Note that this needs introducing at most |X| + 1 colors. The split TCW V now uses at most 3|X| + 3 colors.
Let S (|S| ≤ |X|) be the set of trivial blocks/hanging reset points to the left of the block in V. On division of the (split)-TCW V, we obtain the right part as the TCW V 2 containing the last stack edge of V spanning the non-trivial block; along with a set S 2 of hanging reset points to the left of the block. Some of the points of S 2 could be from S while the remaining |S 2 \ S| are the reset points of clocks which were on the non-trivial block of V to the left of the stack edge, and whose clock edges were crossing the stack edge. The left part V 1 consists of hanging reset points S 1 along with a non-trivial block whose left end point is the same as the left end point of V, and whose right end point is the source of the stack edge in V. Note that S 1 ⊆ S; (1) If there is a reset point in S all of whose clock edges cross the stack edge, then this reset point will be in S 2 \ S 1 (2) If there is a reset point in S all of whose clock edges are to the left of the stack edge, then this reset point will be in S 1 \ S 2 , and (3) If there is a reset point in S such that some clock edges cross the stack edge, while some dont, it will be in S 2 ∩ S 1 . (I1)-(I3) are satisfied for V 1 , V 2 , and hence the number of colors in both is at most |X| + |X| + 2.
In our running example, when we encounter the next stack edge, Eve needs to add two colors, one (the triangle) for the source of the stack edge, and one (the pentagon) for the clock which crosses the stack edge. The last reset point of the other clock is still the one hanging to the left of the block (colored diamond). On division, we obtain two split TCW V 1 , V 2 both having the same form: a sequence of y ≤ |X| hanging points to the left of a block. Each of these hanging points have a clock edge whose target lies in the non-trivial block. Whichever of these words is chosen by Adam, the subsequent split-TCWs obtained during the game will continue to have the normal form and the number of colors needed before any divide is at most 3|X| + 3.
Remark. Note that if there are no stack edges in the TCW, then Eve's strategy is simply to keep colors on the last reset points (from the right end) for all clocks and on the right point (no need to color the leftmost point of the word). It is necessary to keep colors at the last reset points of all the clocks in order to divide the TCW, since any of the clocks can be checked at the last point. This results in the use of |X| + 1 colors. If the last point is the target of a matching clock edge, then division is just removing the clock edge. If not, then we add one color to the predecessor of the last point, and remove the last linear edge. This results in the use of |X| + 2 colors. Note that the division of the TCW is always by removing an atomic term in this case, which may be a linear edge or a clock edge, as a result of which, one of the words obtained after divsion is always atomic. Adam will hence always choose the left word to prolong the game. The word chosen by Adam is always a single block with no hanging points to the left. This already shows the tree-width to be at most |X| + 1 in case of timed automata.

C Proofs from Section 4 C.1 Proof of Lemma 5
Proof. Consider two non-negative real numbers a, b ∈ R + and let i = a and j = b be their integral parts. Then, j − i − 1 < b − a < j − i + 1. It follows that for all closed intervals I with integer bounds, we have b − a ∈ I implies j − i ∈ I.
Assume there exists a non-negative real-valued timestamp map ts : V → R + satisfying all timing constraints of V. Since all the time constraints are closed, we deduce that ts : V → N also realizes all timing constraints of V. The converse direction is clear.

C.2 Proof of Theorem 6
To prove Theorem 6, we prove the following.
Claim 10. Let q be a state and τ be a TT. Then the following hold: 1. Assume (A 1 -A 3 ) are satisfied. Then, for all i, j ∈ P we have i < j iff χ(i) < χ(j): the natural ordering on colors coincide with the ordering of colored points in the split-TCW ( τ , ).

2.
Assume that ts is a timestamp map satisfying items 2 and 3 of (A 4 ). Then, for all i, j ∈ P such that i ≤ j, we have d(i, j) = D(i, j)[M ] = (ts(χ(j)) − ts(χ(i)))[M ] and d(i, j) ≤ D(i, j) ≤ ts(χ(j)) − ts(χ(i)) (d and D give modulo M under-approximations of the actual time elapsed). Moreover, ACC tells whether D gives the accurate elapse of time: By transitivity we obtain χ(i) < χ(j) for all i, j ∈ P with i < j. Since < is a strict total order on V , we deduce that, if χ(i) < χ(j) for some i, j ∈ P , then j ≤ i is not possible.
Next we show that the transitions of A K,M valid indeed preserve the conditions (A 1 ) to (A 4 ). That is, any run of A K,M valid is such that A 1 -A 4 hold good.
Lemma 11. Let τ be a K-TT and assume that A K,M valid has a run on τ reaching state q. Then, τ is good and q is a realizable abstraction of τ .
Proof. The conditions on the transitions for Rename i,j , Add → i,j and Add I i,j in Table 2 directly ensure that the term is good. We show that (A 1 -A 4 ) are maintained by transitions of A K,M valid .
Atomic TTs (1): Consider a transition ⊥ valid . It is clear that (A 1 -A 3 ) are satisfied for state q and term τ = (a, i) ⊕ (b, j) ⊕ i I j. Now, we define ts(χ(i)) = tsm(i) and ts(χ(j)) = tsm(i) + d (i, j) if acc (i)=tt tsm(i) + d(i, j) + M otherwise. Using the last condition (acc(i) = tt and d(i, j) ∈ I) or (acc(i) = ff and I.up = ∞) of the transition we can easily check that (A 4 ) is satisfied.
valid . Assume that q is a realizable abstraction of some K-TT τ and let τ = Rename i,j τ . It is easy to check that q is a realizable abstraction of τ .
valid . Assume that q is a realizable abstraction of some K-TT τ and let τ = Forget i τ . It is easy to check that q is a realizable abstraction of τ . In particular, the correctness of the update acc (i − ) follows from Claim 10. ⊕: Consider a transition q 1 , q 2 ⊕ − → q of A K,M valid . Assume that q 1 and q 2 are realizable abstractions of some K-TTs τ 1 and τ 2 with timestamp maps ts 1 and ts 2 respectively. Let τ = τ 1 ⊕ τ 2 . We show that q is a realizable abstraction of τ .
(A 3 ) Let = {(χ(i), χ(next P (i))) | i ∈ P ∧ i < L}. Let < = (→ ∪ ) + . Using (A 2 ) and the definition of <, it is easy to see that for all i, j ∈ P , if i < j then χ(i) < χ(j). Using → = → 1 → 2 , we deduce that < 1 ∪ < 2 ⊆ <. Let u I v be a timing constraint in τ . Either it is in τ 1 and it is compatible with < 1 , hence also with <. Or it is in τ 2 and it is compatible with < 2 and with <. Using conditions R 1 = max(P 1 ) = L 2 and {i ∈ P 2 | L 1 ≤ i ≤ R 1 } ⊆ P 1 of the transition, we deduce easily that < is a total order on V and that ( τ , ) is a split-TCW. Also, since the last block of ( τ 1 , 1 ) is concatenated with the last block of ( τ 2 , 2 ), targets of timing constraints are indeed in the last block of ( τ , ).
(A 4 ) We construct the timestamp map ts for τ inductively on V = V 1 V 2 following the successor relation = → ∪ . If v = min(V ) is the first point of the split-TCW, we let Next, if ts(u) is defined and u → v then we let Finally, if ts(u) is defined and u v then, with i, j ∈ P being the colors of u and v (χ(i) = u and χ(j) = v), we let With this definition, the following hold Time is clearly non-decreasing: ts(u) ≤ ts(v) for all u ≤ v (tsm, acc) is the modulo M abstraction of ts. The proof is by induction. First, if i = min(P ) then v = min(V ) = χ(i) and i ∈ P 1 iff v ∈ V 1 . Using the definitions of tsm and ts, we deduce easily that tsm(i) = ts(v)[M ]. Next, let i ∈ P with j = next P (i) < ∞. Let u = χ(i), v = χ(j) and assume that tsm ( Moreover, j = next P (i) = next P1 (i) and we get acc(i) = acc 1 (i). Also, ts(v) − ts(u) = ts 1 (v) − ts 1 (u). We deduce that acc(i) = tt iff ts(v) − ts(u) < M . The proof is similar if u → + v and u, v ∈ V 2 . Now, if u → + v then u v (endpoints are always colored). We deduce that Moreover, it is clear that ts(v) − ts(u) < M iff acc(i) = tt. Constraints are satisfied. Let u I v be a timing constraint in τ . Wlog we assume that u, v ∈ V 1 . We know that ts 1 (v) − ts 1 (u) ∈ I. If u → + v then we get ts(v) − ts(u) = ts 1 (v) − ts 1 (u) from the definition of ts above. Hence, ts(v) − ts(u) ∈ I. Now assume there are holes between u and v in ( τ , ). Then, we have u = χ(i) for some i ∈ P 1 with i < L = L 1 . Since targets of timing constraints are always in the last block (A 3 ), we get v = χ(L 1 ) → * v. We deduce from the definition of ts that ts(v) − ts(v ) = ts 1 (v) − ts 1 (v ). Now, using Claim 12 below we obtain: * Either ACC q1 (i, L 1 ) = ff and ts(v ) − ts(u) ≥ M . From Claim 10 we also have ts 1 (v ) − ts 1 (u) ≥ M . We deduce that I.up = ∞ and ts(v) − ts(u) ∈ I. * Or ACC q1 (i, L) = tt and ts(v ) − ts(u) = ts 1 (v ) − ts 1 (u). Therefore, While doing ⊕, the "accuracy" of a point i < L or i < L can change from false to true, depending on the new next point obtained after the combine. However, if i was accurate before the combine, it will stay accurate after the combine Claim 12. Let i, j ∈ P 1 with i ≤ j and let u = χ(i) and v = χ(j).
Proof. The proof is by induction on the number of points in P 1 between i and j. The result is clear if i = j. So assume that k = next P1 (i) ≤ j and let w = χ(k). By induction, the claim holds for the pair (k, j).
In the first case, by definition of the transition for ⊕, we have either ACC q (i, k) = ff or D q (i, k) ≥ M . In both cases, we get ts(w) − ts(u) ≥ M by Claim 10.
In the second case, we get ts(v) − ts(w) ≥ M by induction.

C.3 Correctness of A K,M valid , Complexity
Correctness of the Construction (⊆) Let τ be a TT accepted by A K,M valid . There is an accepting run of A K,M valid reading τ and reaching state q at the root of τ . By Lemma 11, the term τ is good and state q is a realizable abstraction of τ , hence ( τ , ) is a split-TCW. But since q is accepting, we have = ∅. Hence τ is a TCW. From (A 4 ) we deduce that τ is realizable and the endpoints of τ are the only colored points by (A 1 ) and the acceptance condition.
(⊇) Let τ be a good K-TTs such that τ = (G, χ) is a realizable TCW and the endpoints of τ are the only colored points. Let ts : V → N be a timestamp map satisfying all the timing constraints in τ . We construct a run of A K,M valid on τ by resolving the non-deterministic choices as explained below. Notice that the transitions for Rename i,j and Forget i are deterministic. We will obtain an accepting run ρ of A K,M valid on τ such that for every subterm τ , the state ρ(τ ) satisfies (A 4 ) with timestamp map ts, or more precisely, with the restriction of ts to the vertices in τ .
A leaf (a, i) → (b, j) of the term τ corresponds to two vertices u, v ∈ V with u → v. We have i < j since τ is good so the transition is enabled for this atomic subterm. We resolve non-determinism by setting tsm(i) = ts(u)[M ], tsm(j) = ts(v)[M ] and acc(i) = tt iff ts(v) − ts(u) < M . Therefore, (A 4 ) holds with ts. A leaf (a, i) I (b, j) of the term τ corresponds to two vertices u, v ∈ V with u I v.
Since ts satisfies all timing constraints, we have ts(v) − ts(u) ∈ I. The transition taken at this leaf resolves non-determinism by setting tsm(i) = ts(u)[M ], tsm(j) = ts(v) [M ] and acc(i) = tt iff ts(v) − ts(u) < M . We can check that all conditions enabling this transition are satisfied. Moreover, (A 4 ) holds with ts. We can check that the conditions enabling transitions at Rename i,j or Forget i nodes are satisfied since τ is good and τ is a TCW whose endpoints are colored.

Complexity of
valid has the form (P, L, tsm, acc) where P is a subset of K, and tsm, acc are maps from P . Clearly, the complexity is dominated by the map tsm as long as M ≥ 2. Thus, the number of states of A K,M valid is M O(K) .

D Tree Automaton for the Timed System
In this section, we give the full list of transitions of the tree automaton

D.1 Proof of Theorem 7
Proof sketch. Let τ be a K-TT. We will show that τ is accepted by A K,M S iff τ is restricted and τ ∈ TCW(S).
Assume that A K,M S has an accepting run on τ . Clearly, τ is restricted. Now, the first two components (P, L) of A K,M S behave as the corresponding ones in A K,M valid and ensure that V = τ is indeed a TCW (which need not be realizable). It remains to check that S admits a run on V.
1. We first define the sequence of transitions. Each vertex v of V is introduced as node colored j in (1) some atomic term i → j if v is not minimal in V or in (2) some atomic term j → k if v is not maximal in V. We let δ(v) = δ(j) be the transition guessed by A K,M S when reading this atomic term. Notice that if both cases above occur, i.e., if v is internal, then A K,M S has to guess the same transition by C 2 . Notice also that if u → v in V then for some atomic term i → j occurring in τ we have δ(u) = δ(i) and δ(v) = δ(j). Therefore, target(δ(u)) = source(δ(v)). So we have constructed a sequence of transitions (δ(v)) v which forms a path in S reading V. By the acceptance condition, if v is the minimal (resp. maximal) vertex of V then δ(v) is the initial dummy transition (resp. target(δ(v)) is final).

2.
To ensure that the TCW is generated by the system, we check that the sequence of pushpop operations is well-nested. This is achieved using bits Push, Pop and the following facts (i) by C 3 and the accepting condition, every vertex v such that δ(v) contains a push (resp. pop) operation is the source (resp. target) of a matching push-pop edge, (ii) push-pop edges are only within the non-trivial block, (iii) the left end-point is the source of a push-pop edge iff Push = 1 and the right end-point is the target of a push-pop edge is a transition if i < j and P = {i, j}, L = i, Push = Pop = 0, Gx = 0 and Zx = ⊥ for all x ∈ X, δ is guessed such that target(δ(i)) = source(δ(j)). Further, if a = then we take a special initial dummy transition δ(i) = (s dummy , tt, ε, nop, X, s0).

Renamei,j q
Rename i,j − −−−−− → q is a transition if i ∈ P and i − < j < i + , and q is obtained from q by replacing i by j.
is a transition if i ∈ P , L < i < max(P ) (endpoints should stay colored) and for each x ∈ Reset(i) there exists j ∈ P such that i < j ≤ R and x ∈ Reset(j) (the last reset point of each clock is never forgotten, even if it is an internal point). Then, state q is deterministically given by P = P \ {i}, L = L, δ = δ |P , Push = Push, Pop = Pop, G = G and Z = Z. M2: Or, the automaton guesses that it is a constraint for some clock x ∈ X: (a) i < j = R = max(P ), Gx = 0, x ∈ I is in δ(j) and G x = 1, (b) (i ∈ P or i < L) and x ∈ Reset (i) and x ∈ Reset(k) for all k ∈ P with i < k < j (c) Either (L ≤ i and Z x = Zx) or (i < L and Zx ∈ {⊥, i} and Z x = i). Then, P = P ∪ {i}, L = L, δ (k) = δ(k) for all k ∈ P , Push = Push, Pop = Pop, G y = Gy and Z y = Zy for all y ∈ X \ {x}. Note that if i ∈ P , then δ (i) is guessed. The figure below considers the case when i < L, i / ∈ P , that is, i is a new reset point. This i gets added in the set of active colors P . Table 4 Transitions  iff Pop = 1, (iv) by M 1 a push-pop edge is added only between the left and right end points of the non-trivial block and only when Push = 0 = Pop, which are updated to 1, (v) a combine fuses the right end of a non-trivial block with the left end of another one. Because the transition of this fused point cannot carry both a push operation and a pop operation, this ensures well-nesting under the combine operation.
3. The last subtle point concerns clock constraints. First, M 2 , C 4 and the acceptance condition, with the help of G x make sure that if the transition δ(v) of some point v contains a guard x ∈ I then v is the target of a I edge whose source is some node u such that x is reset in δ(u). Let us explain why u is the last reset for clock x in the past of v. By M 2 when the edge u I v is added, v is the current right most point and no colored points between u and v reset clock x. Since the last reset of clock x is never forgotten (see transition for Forget i ), we deduce that there are no resets of clock x between u and v in the current split-TCW. If u is in the non-trivial block, no further points will be added between u and v, hence we are done. Assume now that u is a reset point colored i < L on the left of the non-trivial block in the current split-TCW. By M 2 we store the color i of u in Z x . When we later use a combine operation, C 5 and C 6 ensure that no transitions resetting clock x are inserted between u and (the non-trivial ⊕ q , q ⊕ − → q is a transition if the following hold: C1: R = max(P ) = L and {i ∈ P | L ≤ i ≤ R } ⊆ P (we cannot insert a new point from the second argument in the →-block of the first argument). Note that according to C1, the points , and in P lying between L , R are already points in the non-trivial block connecting L to R . C2: ∀i ∈ P ∩ P , δ (i) = δ (i) (the guessed transitions match). By C2, the transitions δ , δ of , , , , and must match. C3: if there is a Push operation in δ (L ) then Push = 1 and if there is a pop operation in δ (R ) then Pop = 1 (the push-pop edges corresponding to the merging point have been added, if they exist). By C3, if δ(R ) = δ(L ) contains a pop (resp. push) operation then R = L is the target (resp. source) of a push-pop edge. C4: if some guard x ∈ I is in δ(R ), then G x = 1 (before we merge, we ensure that the clock guard for x in the transition guessed at R , if any, has been checked). After the merge, R = L becomes an internal point; hence by C4, any guard x ∈ I in δ (R ) must be checked already, i.e., G x = 1. After the merge, it is no more possible to add an edge I leading into R . C5: if Z x = ⊥, then ∀j ∈ P , Z x < j < L implies x ∈ Reset (j) (If a matching edge starting at Z x < L had been seen earlier in run leading to q , then x should not have been reset in q between Z x and L , else it would violate the consistency of clocks). By C5, if Z x is (resp. ), i.e., (resp. ) is the source of a timing constraint I for clock x whose target is in the L -R block, then clock x cannot be reset at and (resp. ). C6: if Z x = ⊥, then ∀j ∈ P , Z x < j < L implies x ∈ Reset (j) (If a matching edge starting at Z x < L had been seen earlier in run leading to q , then x should not have been reset in q between Z x and L ). By C6, if Z x is , then x cannot be reset at , , , or . Likewise, if Z x was , then clock x cannot be reset at , , or .
C7 says that on merging, we obtain the third split-TCW. After the merge, if Zx is defined, it must be on the left of L , i.e., one of , , , . Notice that the above three conditions ensure the well-nestedness of clocks. By C5 and C6 we cannot have both Z x ∈ { , } and Z x ∈ { , }. So if Z x ∈ { , } then Zx = Z x and otherwise Zx = Z x (including when Z x ∈ { , } and Z x = ⊥).   Thus, we obtain that V is indeed generated by S, i.e., V ∈ TCW(S). In the reverse direction, if V ∈ TCW(S), then there is a sequence of transitions which lead to the accepting state on reading V. By guessing each of these transitions correctly at every point, we can generate the run of our automaton A K,M S .

S
Recall that a state of A K,M S is a tuple q = (P, L, δ, Push, Pop, G, Z) where, P is the set of active colors, and L = Left ∈ P is the left-most point that is connected to the right-end-point R = Right = max(P ) by successor edges on the non-trivial block. P thus any subset of K. δ is a map that assigns to each color k ∈ P the transition δ(k) guessed at the leaf corresponding to color k, δ has size |S| O(K) where |S| denotes the size (number of transitions) of the TPDA, Push and Pop are two boolean variables: Push = 1 iff a push-pop edge has been added to L and Pop = 1 iff a push-pop edge has been added to R, G = (G x ) x∈X is a boolean vector of size |X|: for each clock x ∈ X, G x = 1 iff some constraint on x has already been checked at R. The number of possible vectors is thus 2 O(|X|) , Z = (Z x ) x∈X assigns to each clock x either the color i ∈ P with i < L of the unique point on the left of the non-trivial block which is the source of a timing constraint i I j for clock x, or ⊥ if no such points exist. The size of Z is thus (K + 1) O(|X|) .

D.2 Proof of Theorem 8
Proof sketch. ( =⇒ ) If L(S) is not empty, then there exists a realiziable TCW W accepted by S. Now W is well-timed and hence we know that its tree-width is bounded by a constant K ≤ 3|X| + 3. That is, by the proof of Lemma 4 in Section 3, Eve has a winning-strategy on W with at most K colors. Further, we may observe that Eve's strategy on W gives us a K-TT τ which a good and, in fact, a restricted K-TT, such that τ = W . Now, τ is a good K-TT such that τ = W is a realizable TCW. Thus, by Theorem 6, τ ∈ L(A K,M valid ). Further, as τ is restricted and W ∈ L(S), by Theorem 7 ). Then, by Theorem 7, we get that τ ∈ TCW(S). Again by Theorem 6, τ is a realizable TCW. Thus, we get that τ ∈ L(S).

E Implmententation and Experimental Results
In this section, we give the missing details regarding constraints of the maze in Figure 4, rules for constructing the TPDA from the maze, and finally the performance of our tool on some examples.

E.1 Detailed constraints for Figure 4
For convenience, we reproduce the figure here.
The following are the constraints that must be respected to traverse the maze and successfully exit it, starting at the entry point.
Type (1) Logical constraints: Place 1 must be visited exactly once. From the time we enter the maze to the visiting of place 1, one must visit place 7 and place 4 equal number of times and at any point during time, number of visits to place 7 is not less than number of visits to place 4. Similarly, from visiting place 1 to exiting the maze, one must visit place 7 and place 4 equal number of times and again at any point during time, number of visits Figure 7 A simple maze. Every junction, dead end, entry point or exit point is called a place. The places are 1 to 7. 6 is the entry and 2 is the exit. 1, 7 and 4 are dead ends. Time intervals denote the time taken between adjacent places; for instance, a time between 1 and 2 units must be elapsed to go between places 3,7. A unidirectional arrow represents a one way, for example, places 3 to 5. On the right, is the TPDA model of the maze.
to place 7 is not less than number of visits to place 4. (thus, we model loading at 7 and unloading at 4). Type (2) Local time constraints: Time taken from one place to another adjacent place is as given in the Figure. The time taken from some place i to another adjacent place j is given as a closed interval [a ij , b ij ] along with the arrow. a ij is the least time taken from place i to j and b ij is the upper bound on time taken from place i to place j. One cannot spend any time between a pair of adjacent places other than the ones specified in the maze. For example, we have not also specified time taken from place 6 to place 1. So time bound for going from place 6 to 1 is [0, 0]. Further, one cannot stay in any place for non-zero duration. Type (3) Global time constraints: From entering into the maze to visiting of place 1, time taken should be exactly m units (a parameter). From visiting place 1 to exit, time bound should be exactly n units (another parameter).

E.2 Maze to TPDA construction details
States of the automaton : For each place of the maze we have a corresponding state in the automaton. We call these states as regular states. For each of the constraints, we may have to add extra states in the automaton. For the constraints of type (2), if there is a time bound other than zero([0, 0]) from place i to place j, then we add an extra state k in the automaton between regular state i and regular state j. If it has been given time bound from entry of the maze to visiting of some place, then we have to add one more extra state before the entry point.
Transitions of the automaton : If two states i and j are adjacent, then there is a transition T ij for this. By default, we can't stay non-zero time in a regular state i. So, clock x 1 is reset in the incoming transitions to state i and there is a check x 1 == 0 in the outgoing transitions from state i for each state i. If we have to stay [a i , b i ] time in the state i, then the check could have been a i <= x 1 <= b i . If there is a time bound [a, b] going from place p to some of its adjacent place q(Type (2) constraint) and if place r is added in between, then one transition added from place p to r, where clock x reset and one transtion from place r to q added, where check of clock x happens with constraint [a, b]. Nested time bound can be done using pushing and popping of same symbol between two events. If it has been given that time bound from entering into the maze to visiting of place p must be [a, b](Type (3) constraint), then push some symbol while entering into the maze and pop the same symbol while visiting place p such that age of the stack symbol must belong to [a, b]. If one has to visit place p 1 and place p 2 same number of times(Type (1) Constraint), then it can be done by pushing some symbol while visiting place p 1 and popping of the same symbol while visiting place p 2 .

E.3.1 Constraints on maze 2
Type (1) Place 1 and place 2 must be visited exactly once. Type (2) Time taken from one place to another adjacent place is given in the maze itself. One cannot spend any time between a pair of adjacent places other than the ones specified in the maze. Further, one cannot stay in any place for non-zero duration. For any two adjacent places p and q, one can go from p to q or q to p. In other words all corridors in the maze are bidirectional. Type (3) Total time taken to visit the maze should be at least 5 time units and at most 7 time units.

Figure 8
Maze 2 and its corresponding plot

E.3.2 Constraints on maze 3
Type (1) You must visit place 1, place 2 and place 3 exactly once. Between entering into the maze and visiting of place 1, one must visit place 4 and place 5 same number of times, but in any moment number of visits to place 4 is not less than the number of visits to place 5. Same type of constraints on place 4 and 5 applied between visiting of place 2 and visiting of place 3. Again Same type of constraints on place 4 and 5 applied between visiting of place 3 and exiting from the maze. Type (2) Time spent between two adjacent places is given on the maze itself. You have to stay in place 1 and place 2 exactly one time unit for each of them. You can't stay in other places except 1 and 2. All corridors in the maze are bidirectional.
Type (3) Total time taken to visit the maze is [9,9]. After entering into the maze, one must visit place 1 within [1,3]. After visiting place 1, one must visit place 2 within [5,5]. After visiting place 2, one must exit from the maze in [3,5] time.

Figure 9
Maze 3 and its corresponding plot

E.3.3 Constraints on maze 4
Type (1) You must visit place 1 and place 2 exactly once. Type (2) You can't spend any time between two places except the ones specified in the maze itself. One can't stay in any places for non-zero time except for place 4, where one can stay for [1,2] time unit. All corridors in the maze are bidirectional. Type (3) Global time bound or total time taken to visit the maze is [3,4]. After visiting place 1, one must visit place 2 within [3,3] time. After visiting place 2, one must exit from the maze within [2,3] time.