Dynamic Complexity under Definable Changes

This paper studies dynamic complexity under definable change operations in the DynFO framework by Patnaik and Immerman. It is shown that for changes definable by parameter-free first-order formulas, all (uniform) $AC^1$ queries can be maintained by first-order dynamic programs. Furthermore, many maintenance results for single-tuple changes are extended to more powerful change operations: (1) The reachability query for undirected graphs is first-order maintainable under single tuple changes and first-order defined insertions, likewise the reachability query for directed acyclic graphs under quantifier-free insertions. (2) Context-free languages are first-order maintainable under $\Sigma_1$-defined changes. These results are complemented by several inexpressibility results, for example, that the reachability query cannot be maintained by quantifier-free programs under definable, quantifier-free deletions.


Introduction
In the setting of Dynamic Complexity, a database D is being changed and an update program P tries to answer a standing query q after each change. The program usually consists of logical formulas which can make use of additional, auxiliary relations which in turn need to be updated after each change. Dynamic Complexity can be seen as a logic-based counterpart of Dynamic Algorithms, where algorithms use auxiliary data structures to keep track of properties of structures like graphs under change operations. The Dynamic Complexity framework was introduced in [23] and a similar framework, FOIES, in [8].
In Dynamic Complexity, one usually allows first-order logic formulas as update mechanism for the auxiliary relations. This is in line with the database-oriented framework, since firstorder logic correspond to database languages like relational algebra. Just as in Dynamic Algorithms, for most investigations the possible change operations are limited to insertions and deletions of single tuples. The class of queries maintainable in this fashion is called DynFO. This line of research has seen recent progress, particular with respect to the question whether the reachability query can be maintained in DynFO for directed graphs [2,3].
Although the restriction to single-tuple changes can be justified by the need to concentrate on the basic phenomena of dynamic maintainability of queries, it is also clear that from a more practical perspective one would be interested in more complex change operations at a time. One approach is to specify changes by "∆-relations", e.g., by sets of tuples to be relation of arity Ar(R) over D and to every constant symbol c ∈ τ const an element (called constant) from D. A τ -structure S is a pair (D, D) where D is a domain and D is a database with domain D over schema τ . By dom(S) we refer to D. For a relation symbol R ∈ τ and a constant symbol c ∈ τ we denote by R S and c S the relation and constant, respectively, that are assigned to those symbols in S. A k-ary query q on τ -structures is a mapping that assigns a subset of D k to every τ -structure over domain D and is closed under isomorphisms.
We represent graphs as structures over a schema that contains a single binary relation E. The reachability query q Reach maps graphs to their transitive closure relation.
In Section 6 we consider databases that represent words over some alphabet Σ. In a nutshell, the positions of a word correspond to elements of the domain and the letters at positions are indicated by unary relations. More formally, words are represented by databases with an immutable linear order on their domain and one unary relation R σ for every σ ∈ Σ. For simplicity, we always assume that the domain of such a database is of the form {1, . . . , n} and the linear order ist just the natural order. At any point in time, an element of the domain is allowed to be in at most 1 one relation R σ . However, elements need not to be in any relation R σ and, in this case, they do not correspond to a position with a symbol but rather to the empty word . Thus, we first associate with every position i an element w i ∈ Σ , where by Σ we denote the set Σ ∪ { }, and say that the database represents the string w = w 1 · · · w n . As an example, the database with domain {1, 2, 3, 4, 5} and R a = {2, 4}, R b = {1} represents the string baa. As a further convenience, we assume that databases have constants min and max that represent the smallest and the largest element, 1 and n, respectively. 2 We will not allow the linear order, min or max to be modified by change operations. In this paper, we will rarely distinguish between a database and the string it represents.
We use several notions from finite model theory (see, e.g., [20]). By qd(ϕ), we denote the quantifier-rank of a first-order formula ϕ, that is, its maximum nesting depth of quantifiers. We denote the set of rank-k types of tuples of arity by FO[k, ] (cf. [20, Definition 3.14]). The existential fragment of first-order logic is denoted by Σ 1 .

Dynamic Programs with Complex Changes
In this section we lift the definitions from [25] to more general change operations. We first define (general) change operations, then we adapt the definition of dynamic programs presented in [25] to those more complex changes.

Change Operations
The change operations that we consider in this paper are based on queries. In their most general form, they can modify a given database over schema τ by replacing some of its relations with the results of first-order-defined queries on the database. These queries are allowed to use parameters.
To this end, a replacement rule ρ R for relation R is of the form replace R by µ R (p;x). Here, R is a relation symbol and µ R (p;x) is a first-order formula over τ , where the tuplē x has the same arity as R andp is another tuple of variables, called the parameter tuple. A replacement query ρ(p) is a set of replacement rules for distinct relations with the same parameter tuplep. In the case of replacement queries ρ that consist of a single replacement rule, we usually do not distinguish between ρ and its single replacement formula µ R .
For a database D, a change operation δ = (ρ,ā) consists of a replacement query and a tuple of elements of (the domain of) D with the same arity as the parameter tuple of ρ. We often use the more concise notation ρ(ā) and refer to change operations simply as changes.
The result δ(D) of an application of a change operation δ = (ρ,ā) to a database D is defined in a straightforward way: each relation R in D, for which there is a replacement rule ρ R in ρ, is replaced by the relation resulting from evaluating µ R , that is, by {b | D |= µ R (ā;b)}.
If a replacement query has no parameters we say that it is parameter-free.
Example 1. (a) As a first example, we consider directed graph structures, that is, structures with a single binary relation E. Let, for some graph G, δ 1 = (ρ 1 , u) be the change operation with replacement query µ E (p; x, y) = E(x, y) ∨ (x = p) and node u. Then, in δ 1 (G), there is an edge from u to every node of G. (b) We recall that words over the alphabet Σ = {a, b, c} are represented by databases with a linear order on their domain and one unary relation R σ for every σ ∈ Σ. Let D be a database representing a word w and i an element of D. Let δ 2 = (ρ 2 , i) be a change operation, where the replacement query ρ 2 consists of the rules replace R a by µ Ra (p; x) and replace . Then, δ 2 (D) represents the word obtained from w by swapping a and b symbols on all positions before i and leaving all other positions unchanged.
Some of our investigations will focus on (syntactically) restricted replacement queries that either only remove or only insert tuples to relations. For an insertion rule ρ R , the replacement formula µ R (p;x) has the form R(x) ∨ ϕ R . Similarly, deletion rules have replacement formulas µ R (p;x) of the form R(x)∧ϕ R . In [1], the change operations replace, insert, delete and modify have been studied, in particular with respect to their expressive power. These operations are captured by our change operations 3 .
Another syntactic restriction to be studied extensively in this work are the quantifier-free replacement queries, that allow only quantifier-free change formulas to be used. A special case of quantifier-free changes are the single tuple changes. We refer by insertp into R to the insertion query replace R by µ R (p;x), where µ E (p;x) = R(x) ∨ (p =x) and by deletep from R to the deletion query replace R by µ R (p;x), where µ R (p;x) = R(x) ∧ ¬(p =x). As mentioned before, single tuple changes are the best studied change operations in previous work on dynamic complexity. To emphasize the difference we sometimes refer to arbitrary (not single-tuple) change operations as complex changes. For any schema τ we denote by ∆ τ the set of single-tuple replacement queries for the relations (with symbols) in τ . In the case of graphs, we simply write ∆ E . In case of strings over some alphabet Σ, we write ∆ Σ .

Dynamic Programs
We now introduce dynamic programs, closely following the exposition in [25]. Inputs in dynamic complexity are represented as relational structures as defined in Section 2. The domain is fixed from the beginning, but the database in the initial structure is empty. This initially empty structure is then modified by a sequence of change operations.
The goal of a dynamic program is to answer a given query for the database that results from any change sequence. To this end, the program can use an auxiliary data structure represented by an auxiliary database over the same domain. Depending on the exact setting, the auxiliary database might be initially empty or not.
A dynamic program P operates on an input database I over a schema τ in and updates an auxiliary database A over a schema 4 τ aux , both sharing the same domain D which is fixed during a computation. We call (D, I, A) a state and consider it as one relational structure. The relations of I and A are called input and auxiliary relations, respectively.
A dynamic program has a set of update rules that specify how auxiliary relations are updated after a change. An update rule for updating an auxiliary relation T after a replacement query ρ(p) is of the form on change ρ(p) update T (x) as ϕ T (p,x) where the update formula ϕ T is over τ in ∪ τ aux .
The semantics of a dynamic program is as follows. When a change operation δ = ρ(ā) is applied to the input database I, then the new state S of P is obtained by replacing the input database by δ(I) and by defining each auxiliary relation For a change operation δ we denote the updated state by P δ (S). For a sequence α = (δ 1 , . . . , δ k ) we write P α (S) for the state obtained after successively applying δ 1 , . . . , δ k to S.
A dynamic query is a tuple (q, ∆) where q is a query over schema τ in and ∆ is a set of replacement queries. The dynamic program P maintains a dynamic query (q, ∆) with k-ary q if it has a k-ary auxiliary relation Q that, after each change sequence over ∆, contains the result of q on the current input database. More precisely, for each non-empty 5 sequence α of changes and each empty input structure I ∅ , relation Q in P α (S ∅ ) and q(α(I ∅ )) coincide. Here, S ∅ = (I ∅ , A ∅ ), where A ∅ denotes the empty auxiliary structure over the domain of I ∅ .
The class of dynamic queries (q, ∆) that can be maintained by a dynamic program with update formulas from first-order logic is called DynFO. We also say that the query q can be maintained in DynFO under change operations ∆. The class of dynamic queries maintainable by quantifier-free update formulas is called DynProp.
The following very simple example shows how the transitive closure of a directed graph subject to single edge insertions can be maintained in this set-up.

Example 2.
Let q Reach be the reachability query that returns all pairs (u, v) of a graph, for which there is a path from u to v. The dynamic query (q Reach , {insertp into E}) can be maintained by a dynamic program that uses one auxiliary relation T , which always contains the transitive closure of the edge relation E. Its only update rule is given by the formula ϕ T (p 1 , p 2 ; x, y) = T (x, y) ∨ T (x, p 1 ) ∧ T (p 2 , y) .
Our general framework follows [23] and thus does not allow inserting new elements into or removing existing elements from the domain as in the FOIES framework [8]. The step from Dynamic Complexity to FOIES can be done by adding two more change operations, add(x) and remove(x). Our results of Section 4 easily carry over, and those of Section 6 carry over if, say, new elements are always added at the end of the string. Since add(x) and remove(x) have parameters, they do not quite fit into the parameter-free framework of Section 5. However, Theorem 7 survives if parameter-free remove queries are allowed.

Complex Change Operations and Initialization of Dynamic Programs.
In the presence of complex replacement queries, the initialization of the auxiliary relations requires some attention. In the original setting of Patnaik and Immerman, the input database is empty at the beginning, and the auxiliary relations are initialized by first-order formulas evaluated on this (empty) initial input database. Since tuples can be inserted only one-by-one, the auxiliary relations can be adapted slowly and it can be ensured that, e.g., always a linear order [23] or arithmetic [10] on the active domain is available.
For complex changes, the situation is more challenging for a dynamic program: as an example, in the setting of strings, the first change could insert all positions of the domain into relation R a and thus let the database represent the word a n , if n is the size of the underlying domain. To enable the dynamic program to answer whether the string is in some language after this change, it needs some suitable (often: non-empty) initial values of the auxiliary relations. Since in this paper, we are mainly interested in the maintenance of queries and not so much in the specific complexity of the initialization, we do not define variants of DynFO with different power of initialization, but rather follow a pragmatic approach: whenever initialization is required, we say that the query can be maintained with suitable initialization and specify in the context what is actually needed. In all cases, it is easy to see that the initialization of the auxiliary relations can be computed in polynomial time.
An alternative approach would be to restrict the semantics of replacement queries to elements of the active domain of the current database and to allow the activation of elements only via tuple insertions.

Reachability and Definable Insertions
In this section, we study the impact of first-order definable complex change operations on the (binary) reachability query q Reach . We present positive cases, where previous maintainability results survive under such stronger change operations. Negative results, where such operations destroy previous maintainability results, are given in Section 7.
In the classical DynFO setting with single-tuple change operations it was shown early on that q Reach can be maintained in DynFO for two important graph classes: undirected graphs and directed, acyclic graphs (dags). It turns out that these results still hold in the presence of complex insertions: first-order insertions for undirected graphs and quantifier-free insertions for dags. In fact, in both cases basically the same auxiliary relations can be used as in the case of single-tuple changes.
We first show that for undirected graphs, the reachability query can be maintained in DynFO, for first-order insertions and the set ∆ E of single-edge insertions and deletions. We follow the convention from [14] that modifications for undirected graphs are symmetric in the sense that if an edge (a, b) is inserted then so is the edge (b, a) (and likewise for deletions). We use the approach for maintaining q Reach for undirected graphs under single-edge insertions and deletions from [23, Theorem 4.1] and maintain a spanning forest and (essentially) its transitive closure relation. The crucial observation for extending this approach to first-order insertions is that, after such an insertion, between each pair of nodes in a (new) connected component, there is a connecting path that uses only a bounded number of newly inserted edges. This allows the update of the spanning forest and its transitive closure in a first-order definable way.
The observation is stated more precisely next. For two connected nodes u, v in a graph G = δ(G) that is obtained from a graph G by an insertion δ, we define 6 the bridge distance bd(u, v) as the minimal number d, such that there is a path from u to v in G that uses d edges that were newly inserted by δ.

Lemma 4.
For each first-order insertion query ρ there is a constant m ∈ N such that for each undirected graph G, each change δ = ρ(ā) and all nodes u and v of G that are connected in δ(G) it holds bd(u, v) ≤ m.
We informally refer to this property as the bridge boundedness property.
Proof. The proof makes use of the result by Feferman-Vaught that the depth k first-order type of the disjoint union of two structures is determined by the depth k first-order types of these two structures [11,12] (see also [21]).
Let µ(p;x) be the first-order formula underlying ρ and k its quantifier-rank. Let be the arity ofp, m the number of FO[k, 1]-types of undirected graphs and m = + m .
Let G be an undirected graph and let δ = ρ(ā) for some tupleā of nodes of G. Let u, v be two nodes that are connected by some path π of the form u = w 0 , w 1 , . . . , w r = v in δ(G) with q bridges, that is, edges that are not in G. Our goal is to show that there exists such a path with at most m bridges. Thus, if q ≤ m, there is nothing to prove, so we assume q > m. It suffices to show that there is a path from u to v with fewer than q bridges. Let (u 1 , v 1 ), . . . , (u q , v q ) be the bridges in π. If for some i, the nodes u i and v i are in the same connected component of G (before the application of δ), we can replace the bridge (u i , v i ) by a path of "old" edges resulting in an overall path with q − 1 bridges. Similarly, if u i and u j are in the same connected component of G, for some i < j, we can shortcut π by a path from u i to u j inside G. Therefore, we can assume that, for every i, the nodes u i and v i are in different connected components of G, and likewise u i and u j for i < j.
We show that in this case there are i, j with i < j such that µ defines an edge between u i and v j , and therefore a path with fewer bridges can be constructed by shortcutting the path π with the edge (u i , v j ). By the choice of m there must be two nodes u i and u j , with i < j, in distinct connected components of G that do not contain any element fromā, such that u i and u j have the same FO[k, 1]-type in their respective connected components. By Feferman-Vaught, it follows that (u i , v j ,ā) and (u j , v j ,ā) have the same FO[k, + 2]-types and therefore, since µ defines an edge between u j and v j , it also defines one between u i and v j .

Proof (of Theorem 3).
The dynamic program presented in [23, Theorem 4.1] maintains the transitive closure of undirected graphs under single-edge changes with the help of auxiliary relations F and P V . The binary relation F is a spanning forest of the input graph G and (u, v, w) ∈ P V means that w is a node in the path from u to v in F . Observe that two nodes u and v are connected in an undirected graph if and only if (u, u, v) ∈ P V holds.
We show how to maintain the relation F and P V under FO insertions. For the moment we assume a predefined linear order ≤ on the domain to be present. Let ρ be an insertion query and m the bound on the number of bridges by Lemma 4. Let G be an undirected graph and δ = ρ(ā) an insertion, F a spanning forest of G and P V as described above. We show how to FO-define the auxiliary relations F and P V for the modified graph G = δ(G).
We first describe a strategy to define F and then argue that it can be implemented by a first-order formula. Let C be a (new) connected component in δ(G). We call the smallest node of C with respect to ≤ the queen u 0 of C . For each connected component C of G that is a subgraph of C , we define its queen level as the (unique) number bd(u, u 0 ), for nodes u ∈ C. A bridge in C is inserted into F if for a connected component C of G of some level i it is the lexicographically smallest edge with respect to ≤ that connects C with some component of level i − 1. This clearly defines a spanning forest. The chosen edges can be defined by a first-order formula because, for each number h, there are formulas θ h (x, y) expressing that bd(x, y) ≤ h.
Since the construction of F ensures that each path in F from a node to the queen of its connected component only contains at most m new edges, and thus each path in F contains at most 2m new edges, it is straightforward to extend the update formula for P V from [23, Theorem 4.1].
It remains to show how the assumption of a predefined linear order can be eliminated. For a change sequence α, we denote by A α the set of parameters used in α. When applying α to an initially empty graph, a linear order on A α can be easily constructed as in the case of single-tuple changes [10]. The remaining nodes in V \ A α behave very similarly. More precisely, one can show by induction on |α|, that for all nodes The dynamic program for maintaining q Reach for undirected graphs now maintains the relations F and P V as described above, yet restricted to the induced (and ordered) subgraph of G on A α . The transitive closure can be defined from those relations and the edge relation by a simple case distinction.
Two nodes a, a ∈ A α are connected by a path if and only if there is a path from a to a in F or if there are nodes b, b ∈ A α and a node c ∈ V \ A α such that there are paths from a to b and from a to b in F as well as edges (b, c) and (b , c).
Two nodes a ∈ A α and b ∈ V \ A are connected by a path if and only if there is a node a ∈ A α such that there is a path from a to a in F and an edge (a , b).
Finally, two nodes a, a ∈ V \ A α are connected if and only if there is an edge (a, a ) or there is an edge (a, b) for some b ∈ A α (and therefore also an edge (a , b)).
Now we turn to the other graph class, acyclic graphs, for which DynFO maintainability under complex insertions (and single-edge deletions) is preserved; albeit (we are able to show that) only for quantifier-free insertions. In [23, Theorem 4.2], edge insertions are only allowed if they do not add cycles. Of course, given the transitive closure of the current edge relation it can be easily checked by a first-order formula (a guard), whether a new edge closes a cycle. We will see that this is also possible for the complex insertions we consider.

Theorem 5.
Let ∆ be a finite set of quantifier-free insertion queries. Then (q Reach , ∆∪∆ E ) can be maintained in DynFO for directed, acyclic graphs. Furthermore, for each quantifierfree insertion, there is a first-order guard which checks whether the insertion destroys the acyclicity of the graph.
As in the case of undirected graphs, the proof relies on a bridge boundedness property. This property allows extending the technique for maintaining the transitive closure relation of acyclic graphs under single tuple changes used in [23] and [7] to quantifier-free insertions. As in [23] and [7] no further auxiliary relations besides the transitive closure relation are needed. In Section 7 we show that the transitive closure relation does not suffice for maintaining q Reach for acyclic graphs subjected to Σ 1 -definable insertions 7 .
In the following lemma, the bridge distance bd is defined just as above. However, we can no longer assume that bridges connect (formerly) different connected components, therefore the lemma only holds for quantifier-free insertions. The proof can be found in the full version of this paper.

Lemma 6.
For each quantifier-free insertion query ρ there is a constant m ∈ N such that for each directed, acyclic graph G and each change δ = ρ(ā) it holds that δ(G) has a cycle with at most m bridges, or for all nodes u and v of G with a path from Proof (of Theorem 5). In [23, Theorem 4.2] and [7, Theorem 3.3], dynamic programs are given that maintain the transitive closure of acyclic graphs under single-edge modification, using only the transitive closure as auxiliary relation. Thanks to Lemma 6, these programs can be easily extended. Indeed, since the number of bridges of cycles created by the insertion, and, if the graph remains acyclic, the bridge distance between two path-connected nodes are bounded by a constant, a guard formula and an update formula for the transitive closure can be constructed in a straightforward manner.

Parameter-free Changes
In this section we consider replacement queries without parameters on ordered databases. It turns out that in this case a large class of queries can be maintained in DynFO: all queries that can be expressed in uniform AC 1 and thus, in particular, all queries that can be answered in logarithmic space. This result exploits the fact that for a fixed set of replacement queries without parameters there is only a constant number of possible changes to a structure. An ordered database D contains a built-in linear order ≤ on its domain that is not modified by any changes. One might suspect that parameter-free replacement queries are not very powerful, especially when they are applied to the initially empty input database. However, thanks to the linear order, one can actually construct every finite graph with relatively simple replacement queries (and similarly for other kinds of databases). For instance, one can cycle through all pairs of nodes in lexicographic order. If (u, v) is the current maximal pair, operation keep can move to (u, v + 1) (inserting it into E) while leaving (u, v) in E and drop can move to (u, v + 1) while taking (u, v) out from E.
The update programs constructed in this section use, as additional auxiliary relation, a binary BIT-relation containing all pairs (i, j) of numbers, for which the i-th bit of the binary representation of j is 1. Here, we identify elements of an ordered database with numbers. In the following, the minimal element with respect to ≤ is considered as 0.
By AC 1 we denote the class of problems that can be decided by a uniform 8 family of circuits of "and", "or" and "not" gates with polynomial size, depth O(log n) and unbounded fan-in. We show the following theorem. Theorem 7. Let q be an AC 1 query over ordered databases and ∆ a finite set of parameterfree first-order definable replacement queries. Then (q, ∆) is in DynFO with suitable initialization.
Proof. We first explain the idea underlying the proof.
It uses the characterization of AC 1 by iterated first-order formulas. More precisely, we use the equality AC 1 = IND[log n] from [18,Theorem 5.22], where IND[t(n)] is the class of problems that can be expressed by applying a first-order formula O(t(n)) times and n is the size of the domain 9 . We only give an example and refer to [18,Definition 4.16] for a formal definition. Consider the formula ϕ TC (x, y) When applying the formula to a graph and an empty relation R it defines the relation R 1 of paths of length 1, applying it to R def = R 1 defines the paths of length 2; in general applying the formula to R def = R i defines the paths of length 2 i . Thus log n-fold application of ϕ TC defines the transitive closure relation of a graph with n vertices and therefore q Reach is in Let q be a query in AC 1 and let k be such that q can be evaluated by k log n applications of a formula ϕ q .
The program P uses a technique inspired from prefetching, which was called squirrel technique in [31]. At any point t in time 10 , it starts a thread θ β , for each possible future sequence β of 2 log n change operations.
Within the next log n steps (i.e. changes), it compares whether the actual change sequence α is the prefix of β of length log n. If not, thread θ β is abandoned, as soon as α departs from β. For each of these log n steps, θ β simulates two change operations of β and applies them to the graph G t at time t, consecutively. After log n steps, that is, at time t + log n, thread θ β has computed the target graph β(G t ).
During the next log n steps until time t + 2 log n, θ β evaluates q on β(G t ) by repeatedly applying the formula ϕ q , k times for each single step. Again, if the actual change sequence departs from β then θ β is abandoned. However, if β is the actual change sequence from time t to t + 2 log n, the thread θ β does not stop and has the correct query result q(β(G t )) at time t + 2 log n.
We note that, although the time window in the above sketch stretches over 2 log n change operations from time t to t + 2 log n, the actual sequences whose effect on the current graph is precomputed are never longer than log n. This is because the application of all 2 log n operations of a sequence takes until time t + log n and by that time the first log n of these operations already lie in the past.
Of course, P uses a lot of prefetching. However, this is possible, because only a constant number, d = |∆|, of change operations is available at any time (and there are no parameters). Thus, there are only d 2 log n = 2 2 log d log n = n 2 log d many different change sequences, each of which can be encoded by a tuple of arity 2 log d over the domain.
This explains how P can give correct answers for all times t ≥ 2 log n. All previous time points have to be dealt with by the initialization. This initialization also equips the program with the BIT relation. Clearly, the initialization can be computed in AC 1 , and therefore also in polynomial time. More details of this proof can be found in the full version of this paper.

Formal Languages and Σ 1 -definable Change Operations
In this section, we consider the membership problem for formal languages and how it can be maintained, for regular and context-free languages, under certain kinds of complex changes. The problem of maintaining formal languages dynamically has been studied intensely in the context of single insertions to and deletions from the relations R σ (cf. Section 2). In that setting, the class of regular languages is exactly the class of languages maintainable in DynProp 11 and all context-free languages can be maintained in DynFO [13]. All regular, some context-free, and even some non-context-free languages can be maintained in DynFO with only unary auxiliary relations [16], but this is not possible for all context-free languages [30,27].
Here, we consider the problem of maintaining formal languages under first-order definable change operations. We assume that only replacement queries are used whose application results in structures where each position is in at most one R σ relation. For a given formal language L we denote the membership query for L as q L .
We prove that regular and context-free languages can be maintained dynamically for large classes of change operations: all regular languages can be maintained in DynProp under quantifier-free change operations and all context-free languages can be maintained in DynFO under Σ 1 -definable (and, dually, Π 1 -definable) change operations. A setting, in which language membership can be maintained with respect to simple changes but not with respect to definable change operations is exhibited in Section 7. For quantifier-free change operations, the results are obtained by generalizations of the techniques of [13]. Proof. Let L be a regular language of strings over alphabet Σ and A = (Q, Σ, γ, s, F ) a corresponding deterministic finite automaton with set Q of states, transition function 12 γ, initial state s, and set F of accepting states. In [13,Proposition 3.3], the main auxiliary relations are of the form S q,r (i, j) where q, r are states of A and i, j are positions of the string under consideration. The intended meaning of S q,r is that (i, j) ∈ S q,r if and only if γ * (q, w i+1 · · · w j−1 ) = r. 13 Notice that w i and w j are not relevant for determining whether (i, j) ∈ S q,r .
In the presence of quantifier-free change operations it suffices to maintain binary auxiliary relations of the form S f q,r , where f : Σ → Σ is a relabeling function. The intended meaning is that (i, j) ∈ S f q,r if and only if γ * (q, f (w i+1 · · · w j−1 )) = r, where f is extended to strings in the straightforward way. 14 Clearly, S q,r = S id q,r . For simplicity we show how to update S f q,r for replacement queries of the form ρ(p) with one parameter p. The general case works analogously, but is notationally more involved. A replacement query with one parameter basically consists of one quantifier free formula µ σ (p; x), for each element σ ∈ Σ.
We show how the relations S f q,r can be maintained by quantifier-free update formulas 11 So, only using quantifier-free update formulas. 12 Since in this paper δ denotes change operations, we use γ for transition functions. 13 The relations Sq,r were actually named Rq,r in [13], but we want to avoid confusion with the Rσ relations. Since [13] did not use constants min and max, it used further auxiliary relations of the form Ir and Fq that contain all positions i with γ * (s, w1 · · · w i−1 ) = r, and γ * (q, w i+1 · · · wn) ∈ F , respectively. 14 It should be noted that f need not be a homomorphism since f ( ) = is allowed. where ψ q,r (x) is a formula that expresses that δ(q, w x ) = r. Intuitively, each formula µ σ (p; x) determines whether position x carries σ after the change. Whether this is the case only depends on (1) the current symbol at position x, (2) the current symbol at position p, and (3) on the relative order of x and p. Thus, the impact of a change can be described as follows: some relabeling function f ← is applied at all positions x < p, some change might occur at position p and some relabeling function f → is applied at all positions x > p. More precisely, from ρ one can derive, for each 15 τ ∈ Σ , relabeling functions f τ ← , f τ → and a symbol σ(τ ) such that the update formula for a relation S f q,r can be described by the formula where formulas of the form χ q ,a,r are defined as if δ(q , a) = r and ⊥, otherwise. The initialization of the relations S f q,r is straightforward. If, for a relabeling function f , We next turn to context-free languages. The ideas underlying the proof of Theorem 8 can be adapted to show that the result from [13], that (membership for) context-free languages can be maintained in DynFO under simple change operations, survives under quantifier-free change operations. Through some little extra effort, this can be extended to Σ 1 -definable change operations (and dually, Π 1 -definable change operations).

Theorem 9.
Let L be a context-free language and ∆ a finite set of Σ 1 -definable replacement queries. Then (q L , ∆) can be maintained in DynFO with suitable initialization.
The proof of Theorem 9 can be found in the full version of this article. It first shows how context-free languages can be maintained under quantifier-free changes, basically combining the idea of the proof of Theorem 8 with that of [13, Theorem 4.1]. Then it shows how the case of Σ 1 -definable changes can be reduced to the quantifier-free case.

Inexpressibility Results
We finally turn to inexpressibility results. It is notoriously difficult to show that a query cannot be maintained by a DynFO program. Indeed, there are no inexpressibility results for DynFO besides those that follow from the easy observation that every query that can be maintained in DynFO under single-tuple insertions is computable in polynomial time.
We expect that it should be easier to prove inexpressibility results for DynFO in the presence of first-order definable change operations. However, we have no results of this form yet. But the following results confirm that, unsurprisingly, complex change operations can make it harder to maintain a query. We give two examples where allowing complex changes 1:13 destroy a previous maintainability result, Theorems 10 and 13, and one example, Theorem 12 where we are able to show an inexpressibility result in the presence of complex deletions but not yet for single-tuple changes.
Towards our first result, we recall that the reachability query can be maintained under single-tuple insertions with the transitive closure of the edge relation as only auxiliary relation and that this does not hold if one allows single-tuple deletions [4]. We show next that the transitive closure also does not suffice in the presence of single-tuple insertions and one complex insertion query.
For general directed graphs, a parameter-free and quantifier-free insertion query suffices, for acyclic graphs a parameter-free insertion query defined by an existential formula suffices. The latter result should be contrasted with Theorem 5.

Theorem 10. (a) There is a quantifier-free and parameter-free insertion query ρ such that (q Reach , {insertp into E, ρ}) cannot be maintained in DynFO on ordered directed graphs, if all auxiliary relations besides the query relation and the linear order are unary. (b)
There exists an Σ 1 -definable and parameter-free insertion query ρ , for which the above statement holds even restricted to acyclic, directed graphs.
Proof. For ease of presentation, we first give a proof for unordered directed graphs. The proof follows an approach that has been used often before and that was made precise in [30]. We say that a k-ary query q is expressed by a formula ϕ(x) with help relations of schema τ , if, for every database D, there is a τ -structure H over the same domain such that for every k-tupleā over the domain of D it holds 16

:ā ∈ q(D) if and only if (D, H) |= ϕ(ā).
The proof is by contradiction and proceeds in the same way in both cases, (a) and (b). Our goal is to show that, under the assumption that there is a dynamic program for (a) or (b), the transitive closure of path graphs, that is, graphs that consist of a single directed path, can be expressed with unary help relations, contradicting the following lemma from [30], which is not hard to prove with the help of locality arguments.

Lemma 11 ([30, Lemma 4.3.2]). The transitive closure of path graphs cannot be expressed by a first-order formula with unary help relations.
We refer to Figure 1 for an illustration of the following high-level sketch. We start from an arbitrary path graph G 0 and equip it with some unary relations C 0 , C 1 , C 2 . From G 0 , C 0 , C 1 , C 2 we define a graph G in a first-order fashion, whose simple directed paths have length at most 2, so the transitive closure relation T C of G is definable by a first-order formula. Finally, the crucial step happens: the change operation δ transforms G into a graph G = δ(G) with the property that q Reach (G 0 ) can be defined from q Reach (G ) by a first-order formula. We can conclude that q Reach (G 0 ) can be defined by a first-order formula with the help of suitable unary help relations, since all steps from G 0 to G are first-order definable, T C is first-order definable from G, and we assume that there is a dynamic program that computes q Reach (G ) from G, T C and some unary auxiliary relations. This contradicts Lemma 11.
For (a), we use the insertion query ρ = µ E (x, y) def = E(x, y) ∨ E(x, x) ∧ E(y, y) ∧ E(y, x) that adds all edges (x, y) for which there is an edge (y, x) and both x and y have self-loops. We assume that there is a DynFO-program P that maintains the reachability query on directed graphs under insertion queries {insertp into E, ρ}. We further assume that P uses (only) unary auxiliary relations B 1 , . . . , B k , for some k, besides the binary relation Q intended to store the query result. We show how to construct from P a first-order formula ϕ that expresses the reachability query q Reach for simple paths with unary help relations B 1 , . . . , B k , C 0 , C 1 , C 2 , contradicting Lemma 11.
Let G 0 = (V 0 , E 0 ) be a simple path with V 0 = {v 0 , . . . , v n }, for which we want to define q Reach using unary help relations B 1 , . . . , B k , C 0 where ≡ 3 denotes modulo 3 equivalence. From G 0 and C 0 , C 1 , C 2 we define the following graph G with nodes v 0 , . . . , v n . The graph G has an edge from vertex v to w if one of the following cases holds: We observe that the graph G can be first-order defined from G 0 and C 0 , C 1 , C 2 . Let δ def = ρ and 17 G def = δ(G). The graphs G 0 , G and G for n = 11 are depicted in Figure 1. By our assumption, the update formula ψ = φ Q δ (x 1 , x 2 ) of P for the query relation Q and operation δ defines the reachability query for δ(G) = G with the help of suitable auxiliary relations B 1 , . . . , B k and the transitive closure T C of the edge relation of G.
The proof for (b) and the extension to ordered graphs can be found in the full version of this paper.
We now turn towards inexpressibility by quantifier-free update formulas. Very likely quantifier-free update formulas are too weak to maintain q Reach even under single-tuple changes. Yet only restricted inexpressibility results have been obtained so far. The query q Reach cannot be maintained in DynProp under single-tuple changes when the auxiliary relations are at most binary or when the initialization is severely restricted [32]. For the more general alternating reachability query quantifier-free update formulas do not suffice [13]. The next result shows that q Reach cannot be maintained in DynProp, even if besides single-edge insertions only a single, very simple deletion query is allowed.

Theorem 12.
There is a quantifier-free deletion query ρ with one parameter such that (q Reach , ∆ E ∪ {ρ}) cannot be maintained in DynProp.
Proof. For the proof, we combine the standard tool for obtaining inexpressibility results for DynProp, the Substructure Lemma [32,13], with a combinatorial technique based on upper and lower bounds of Ramsey numbers [29].
The intuition behind the Substructure Lemma is as follows. When updating an auxiliary tupled after a quantifier-free change parameterized byp, a quantifier-free update formula only has access tod andp. Thus, if a change operation changes a tuple inside a substructure A of a state S of a dynamic program, the auxiliary data of A is not affected by any information from outside of A. In particular, two isomorphic substructures A and B remain isomorphic, when corresponding changes are applied to them. The Substructure Lemma is formally stated in [32, Lemma 2]. Even though the lemma is phrased for single-tuple changes only, the same proof, using the intuition explained above, extends to quantifier-free replacement queries.
For the actual proof, we assume, towards a contradiction, that there is a quantifier-free dynamic program P over schema τ of arity k that maintains q Reach under the quantifier-free deletion ρ(p) = µ(p; x, y) def = E(x, y) ∧ ¬E(p, x) which deletes an edge (x, y) if there is an edge (p, x). Our goal is to construct a graph G such that not all change sequences of length k + 1 can be maintained, no matter the initial auxiliary data.
Let n be a sufficiently large number, to be specified later. The vertex set of the graph is of the form {s, t} ∪ A ∪ C, for some disjoint sets A and C, with |C| = n. The set A contains a node for every subset of size k + 1 of C, that is, A def = {a X | X ⊆ C and |X| = k + 1}. Let B be a subset of A, to be specified later.
The graph has the following edges: (a) For each a X ∈ A there is an edge (s, a X ). (b) For each a X ∈ B there is an edge (a X , t).
(c) There is an edge (c, a X ) for nodes c ∈ C, a X ∈ A if c ∈ X.
Intuitively, the nodes in C control how edges from A to t can be removed. Each node c ∈ C is connected to a subset A ⊆ A, and thus applying a change ρ(c) will result in removing all edges (a X , t) for all a X ∈ A . The graph is constructed in such a way that ( ) for a change sequence α = (ρ(c 1 ), . . . , ρ(c k+1 )) with |{c 1 , . . . , c k+1 }| = k + 1 it holds (s, t) ∈ q Reach (α(G)) if and only if a {c1,...,c k+1 } ∈ B.
For choosing the size of C and the set B, we employ the combinatorial Lemma 2 from [29]. The lemma guarantees that, depending on the schema τ ∪ {c s , c t }, there is an n 0 such that for every n > n 0 there is some m such that the following holds. (S1) For every state S of the dynamic program for G, and each set C with at least n vertices of G with a linear order <, there is a subset C of C of size at least m such that the k-ary auxiliary data on C is <-monochromatic in the structure (S, s, t), i.e. all <-ordered k-tuples over C have the same quantifier-free type (including their relationships to the interpretations s, t of the constants c s , c t ). (S2) There is a subset B of A such that for every subsetĈ of C of size m, there are We outline how the graph G is used to obtain a contradiction. Let S be a state of the dynamic program for the graph G with |C| = n > n 0 and let < be a linear order. Choose B as described above and a subset C of C of size |C | = m that is <-monochromatic in (S, s, t).
By the Substructure Lemma from [32] generalized to quantifier-free changes, the dynamic program P yields the same result for the tuple (s, t) for the change sequences (ρ(c 1 ), . . . , ρ(c k+1 )) and (ρ(c 1 ), . . . , ρ(c k+1 )) since C is <-monochromatic. Yet the result should be different due to ( ) and a Y ∈ B, a Y / ∈ B. This is a contradiction.
Finally, we turn to lower bounds for the maintenance of languages. We exhibit an example that illustrates that maintaining regular languages under full first-order replacement queries might be hard: there is a regular language L that can be maintained in DynFO under single-tuple changes with nullary auxiliary relations, but there is a relatively simple replacement query, for which this no longer holds. This is no general hardness result, as we only allow very restricted auxiliary relations, but it demonstrates the barrier of our techniques. The proof of the following result can be found in the full version of this paper.

Theorem 13.
There is a regular language L over some alphabet Σ and a replacement query ρ, such that (q L , ∆ Σ ) can be maintained in DynFO with nullary auxiliary relations, but not (q L , ∆ Σ ∪ {ρ}).

Conclusion
In this paper, we studied the maintainability of queries in the Dynamic Complexity setting under first-order defined replacement queries. The main insight of this study is that many maintainability results carry over from the single-tuple world to settings with more general change operations. We were actually quite surprised to see that so many positive results survive this transition. However, many questions remain open, for instance: To which extent can the reachability query for (undirected or acyclic) graphs be maintained under definable deletions? What about reachability for unrestricted directed graphs under definable insertions? What about other queries? Are binary auxiliary relations sufficient in Theorem 3? We were less surprised by the fact that stronger change operations can yield inexpressibility, but even these results required some care. Our main contribution in that respect is the proof that DynProp cannot maintain the reachability query under quantifier-free replacement queries.
From Theorem 7 about parameter-free changes and its proof, we take another insight regarding inexpressibility proofs: the squirrel technique is quite powerful to prepare an update program for a non-constant (i.e., logarithmic) number of changes. Inexpressibility proofs need to take that into account and to argue "around it". Let G be an ordered graph with n vertices. For simplicity we assume that n is a power of 2.
We encode change sequences by elements of the domain as follows: A sequence α = δ 1 · · · δ log n is encoded by the node w α , whose bit string representation (when viewed as a number) has 1 at position i if and only if δ i = ρ 1 . We denote the change sequence encoded by node w as α w .
We first describe the auxiliary relations needed for time points t ≥ log n. We denote the length i prefix of a change sequence α by α[..i]. In the following, we assume that relations for the arithmetic operations +, × and the BIT-predicate are provided by the initialization 18 .
Relation F represents the graphs that result when particular change sequences occur during the next log n steps. The tuple (w, u, v) is in F if after applying α w to the current graph G, the edge (u, v) is included in the resulting graph α w (G). Relation T contains the temporary query result after some applications of ϕ q to a modified graph: The tuple (i, w,ā) is in T if after i + 1 applications of ϕ q to α w [..j](G), the tuplē a is included in the defined relation, for i ≤ log n and j = (log n) − i − 1. Here, j is the length of the prefix of α w that still needs to be applied to the current graph G to obtain the target graph. In particular, a tupleā is in the query result for the current graph if (log n, w,ā) ∈ T for all w. The query relation Q.
It turns out that maintaining F and T is even easier than indicated in the above sketch since the computation that starts at time t + 1 can reuse information computed by that at time t and so forth.
Relation F is very easy to maintain. We recall that its first version (for time t = 0) is given by the initialization. Whether a tuple (w, u, v) is in F after change operation δ can be determined as follows: Let δ be the last symbol (operation) of α w and α be its prefix of length (log n) − 1, hence α w = α δ . Let G be the graph represented by all tuples of the form (w δα , ·, ·). Then (w, u, v) is in F after applying δ if and only if (u, v) is in δ (G ).
Relation T can be maintained similarly. A tuple (0, w,ā) is in T ifā is in ϕ q (∅) applied to the graph F (w, ·, ·). A tuple (i + 1, w,ā) is in T after operation δ, for i < log n, if and only if the tupleā is in the relation ϕ q (A), where A consists of all tuplesb, for which (i, w δα ,b) is in T before operation δ, where α is as above. Here we assume, without loss of generality, that ϕ q (R) uses the graph relation only when R is empty.
The query relation Q can be obtained from the tuples of the form (log n, w,ā) in T .

Proof (of Theorem 9).
We proceed in two steps. We first prove the result for quantifier-free change operations and show afterwards that the case of Σ 1 -definable change operations can be replaced reduced by quantifier-free change operations. For the first step, we simply adapt the proof of [13,Theorem 4.1]. Let L be a context-free language over alphabet Σ and G a corresponding context-free grammar in Chomsky normal form, where we additionally allow rules of the form X → and assume the existence of a non-terminal E with E → and X → XE, X → EX, for every non-terminal X. 19

Figure 2
Conditions for the update of S f 1 ,f 2 X,Y in the proof of Theorem 9 (see also [13,Fig. 2]). In the bottom layer there is the string before the modification. One layer above the changes of the modification are depicted, the next layer shows the transformation assumed by the auxiliary relation. On top, we see the partial derivation tree checked by the update formula.
We adapt this approach in a similar fashion as in the proof of Theorem 8. To this end, we use auxiliary relations of the form S f1,f2 X,Y where f 1 , f 2 are relabeling functions. The intension is that (i 1 , j 1 , i 2 , j 2 ) ∈ S f1,f2 X,Y if and only if i 1 ≤ j 1 < i 2 ≤ j 2 and X ⇒ * f 1 (w i1 ) · · · f 1 (w j1 )Y f 2 (w i2 ) · · · f 2 (w j2 ).
We show next how to maintain these relations under quantifier-free replacement queries ρ(p) with one parameter. As in the proof of Theorem 8, the generalization for any number of parameters is straightforward, but tedious.
Let S be a program state and δ = (ρ, a) a change operation. Similarly as in the proof of Theorem 8, from ρ and the symbol τ at position a, one can derive relabeling functions f ← , f → and a symbol σ = σ(τ ) that represent the modifications applied to the input string.
We explain the part of the update formula of S f1,f2 X,Y that deals with the case i 1 < a < j 1 . The other cases are similar. Inside this case, we omit some border sub-cases. The update formula essentially checks whether for some non-terminals U, U 1 , U 2 and Z with Z → f 1 (σ) and U → U 1 U 2 there are positions u 1 , u 2 , u 3 with i 1 ≤ u 1 < a < u 2 < j 1 and i 2 ≤ a − 1, a + 1, u 2 ), and hold. An illustration is given in Figure 2.
The initialization of the relations S f1,f2 X,Y is straightforward. If, for relabeling functions f 1 , f 2 it holds f 1 ( ) = σ 1 and f 2 ( ) = σ 2 , then a tuple (i 1 , j 1 , It remains to show how the case of Σ 1 -definable change operations can be reduced to the 20 Actually, the choice of indices is slightly different in [13] but this difference is inessential. quantifier-free case. More precisely, we show that for each Σ 1 -definable change operation ρ(p) there exists a quantifier-free change operation ρ (p,q) with many additional parameters collected inq such that, for each string w and each position a, there is a tuplec of positions such that δ(w) = δ (w), where δ = (ρ, a) and δ = (ρ , (a,c)). Since we already showed that quantifier-free change operations of any arity can be handled in DynFO, the theorem then follows.
To this end, let µ σ (p; x) be a Σ 1 -formula which expresses whether after change operation ρ(p), position x will carry symbol σ. Without loss of generality, we can assume that µ σ (p; x) = m θ m , where each θ m (p; x) is of the form ∃y 1 . . . , y k ψ m , for some k, and each ψ m (p,ȳ; x) describes a full atomic type over p, y 1 . . . , y k , x with respect to the linear order and the letter relations. That is, ψ m completely specifies the relative order of the positions bound to the variables and the symbols they carry.
We claim that, for every m, for each word w and each position a there exists a tuplē c = (c 1 , . . . , c k ) of positions in w such that for every position i it holds w |= θ m (a, i) if and only if w |= ψ m (a,c; i).
We can assume without loss of generality that the order-type specified by ψ m fulfills y 1 < · · · y < x < y +1 < · · · < y k and y j = p, for some j and . This can be achieved by adding or removing and renaming variables accordingly.
Then, if w |= θ m (a, i) holds, positions c 1 , . . . , c for variables y 1 , . . . , y can be chosen such that the tuple (c 1 , . . . , c ) is lexicographically minimal and c k , . . . , c +1 for y k , . . . , y +1 such that the tuple (c k , . . . , c +1 ) is lexicographically maximal. It is easy to see that this tuplec fulfills the condition of the claim. We callc the canonical tuple for θ m with respect to w and a.
The update formulas for ρ(p) can now be obtained as follows. First, the update program for the replacement queries given by the formulas m ψ m (p,c m ; x), where all tuplesc m are pairwise disjoint, is determined. In the resulting update formulas, a block of existential quantifiers for the tuplesc m is added and it is verified that each tuple is bound to a canonical tuple of positions.
Proof (of Theorem 10, continued). Both graphs G and G are not acyclic and thus not suitable for (b). Yet a slight modification of the above construction yields acyclic graphs G and G but it uses an existential quantifier in the definition of the change operation. The graphs are depicted in Figure 3. The graph G is obtained by applying the operation δ = µ E (x, y) def = E(x, y) ∨ ∃z E(z, x) ∧ E(z, y) to G. The proof is now analogous to (a) except that G has to be first-order interpreted into the path graph G 0 , as it uses a slightly larger domain. The rest of the argument for (b) is analogous, but q Reach (G 0 ) is obtained from q Reach (G ) as q Reach This completes the proof for DynFO. For the full statement, with ordered graphs, it suffices to replace Lemma 11 by the following Lemma 14.

Lemma 14.
For every first-order formula ϕ(x, y) over a signature σ = {E, <, A 1 , . . . , A m }, where A 1 , . . . , A m are unary, there is a graph G, consisting of a single path, and a linear order < on its vertices, such that for all sets A 1 , . . . , A m of nodes of G, there are nodes u, v 1 , v 2 such that (G, <, A 1 , . . . , A m ) |= ϕ(u, v 1 ) ↔ ϕ(u, v 2 ), but v 2 is reachable from u and v 1 is not.
Proof. Let ϕ(x, y) be a formula as stated in the lemma and let k be its quantifier rank. Let τ be the signature σ ∪ {B 1 , . . . , B r } with r = 2 k+1 + 1, and let be the number of FO[k, 1]-types of τ -structures. The additional relations B 1 , . . . , B r will be useful later in the proof, when the so-called Extension Theorem is applied.  Figure 3 The graphs from the proof of Theorem 10(b).
Let G be the graph with vertex set V = {(i, j) | 0 ≤ i ≤ r, 1 ≤ j ≤ + 1} and edges between (i 1 , j 1 ) and (i 2 , j 2 ) if i 1 + 1 = i 2 and j 1 = j 2 or if i 1 = r, i 2 = 0, and j 1 + 1 = j 2 . That is, G consists of a path with ( + 1)(r + 1) nodes from (0, 1) to (r, + 1) that consists of + 1 sub-paths of length r from nodes (0, i) to (r, i), which are connected by edges of the form ((r, i), (0, i + 1)). We refer to i in (i, j) as its column number and to j as its row number and to columns and rows of the graph, accordingly. This graph is depicted in Figure 4.

Figure 4
The graph from the proof of Lemma 14.
Let < be just the lexicographic order (or stated otherwise: column-major order) on V . Let now A 1 , . . . , A m be arbitrary sets of nodes of G. Let B be the τ -structure that is obtained from (G, <, A 1 , . . . , A m ) by removing column 0 and its adjacent edges, and by adding the unary relations B 1 , . . . , B r , where each set B i is just the set of nodes of column i. Since G has more rows than there are FO[k, 1]-types of τ -structures, there must be two nodes v 1 def = (2 k + 1, i) and v 2 def = (2 k + 1, j), i < j, which have the same FO[k, 1]-type in the τ -structure B.
Clearly, there is a path from u def = (0, j) to v 2 in G, but not from u to v 1 . However, we will show in the following that (G, <, A 1 , . . . , A m ) |= ϕ(u, v 1 ) ↔ ϕ(u, v 2 ). To this end, we show that the duplicator has a winning strategy in the k-round Ehrenfeucht game on the two structures (G, <, A 1 , . . . , A m , u, v 1 ) and (G, <, A 1 , . . . , A m , u, v 2 ). This follows with the help of the Extension Theorem (Theorem 8) from [24], as we explain next. For the convenience of readers, we repeat it as Theorem 15 below.
In a nutshell, the Extension Theorem guarantees the existence of a winning strategy for the duplicator by combining two strategies. To explain the first strategy, let H denote column 2 k + 1 of B with the distinguished element v 1 and H the same column but with v 2 as distinguished element. The first winning strategy is for the game on the neighborhoods of diameter 2 k of H and H , that is on (B, v 1 ) and (B, v 2 ). Such a winning strategy exists, because v 1 and v 2 have the same FO[k, 1]-type in B. Thanks to the B i -relations this strategy has the additional property that the duplicator answers each move of the spoiler by a move (node) in the same column. The second winning strategy is trivial: it is for the game on two identical copies of the structure obtained from (G, <, A 1 , . . . , A m , u) by removing column H. The Extension Theorem allows to combine these two strategies, thanks to the additional property and because the linear order is very homogeneous with respect to the column structure.
As signature S in the application of the Extension Theorem we choose σ ∪ {c 1 , c 2 }. The structures A and A are (G, <, A 1 , . . . , A m , u, v 1 ) and (G, <, A 1 , . . . , A m , u, v 2 ), respectively. The distance function is just the distance with respect to E, in both structures. The sets H H are chosen as above (and there are no other H i or H i required). Clearly, if we remove H and H the resulting structures A − H and A − H are isomorphic via the identity mapping id. To apply the Extension Theorem it remains to verify that its conditions (i)-(iii) are fulfilled.
Condition (i) just states that the duplicator has a winning structure on B and B that has the additional, "distance from H"-respecting property. It holds as explained above.
Condition (ii) holds, because the structures are identical and thus id is the required isomorphism.
Condition (iii) is more complicated. For nodes x 1 , x 2 from A and x 1 , x 2 from A , let ( * ) be the condition that (x 1 , x 2 ) ∈ E if and only if (x 1 , x 2 ) ∈ E, and x 1 < x 2 if and only if x 1 < x 2 .
To establish Condition (iii), we have to show that ( * ) holds under the assumption that there exists a number e < 2 k such that the following statements hold.
(a) None of x 1 , x 2 , x 1 , x 2 has distance e from H (or H ). (Henceforth, we call nodes whose distance is smaller than e inner nodes and the others outer nodes). (b) If x 1 is an inner node then x 1 has the same distance from H . Otherwise, even x 1 = x 1 .
And likewise for x 2 and x 2 . (c) For the inner nodes from x 1 , x 2 the (joint) atomic σ-type is the same as for the respective nodes from x 1 , x 2 . To conclude ( * ) from (a)-(c), we distinguish three cases: If x 1 and x 2 are both inner nodes, then ( * ) follows from (c). If both are outer nodes, it follows from (b). Finally, if x 1 is an inner node and x 2 an outer node then (a) guarantees that neither (x 1 , x 2 ) nor (x 1 , x 2 ) are edges and the relations B i guarantee that x 1 < x 2 if and only if x 1 < x 2 .
This concludes the proof of the lemma.  R 1 , . . . , R s of arities a 1 , . . . , a s and constant symbols c 1 , . . . , c t . Let A, A be S-structures. Let δ, δ be distance functions on A and A , respectively. Let H 1 , . . . , H l and H 1 , . . . , H l be sequences of subsets of U A and U A respectively, such that N δ 2 k (H i ) ∩ N δ 2 k (H j ) = ∅ and N δ 2 k (H i ) ∩ N δ 2 k (H j ) = ∅ for i = j. Let α be an isomorphism from A ↓ (U A − (H 1 ∪ · · · ∪ H l )) to A ↓ (U A − (H 1 ∪ · · · ∪ H l )).
We first prove that for every number of times we apply ρ to the strings, (1) P will assign the same auxiliary bits to both strings, so for the states (ρ (w(I 1 )), A 1 ) = P ρ (S 1 ) and (ρ (w(I 2 )), A 2 ) = P ρ (S 2 ) for the update program P of P, it holds that A 1 = A 2 ; and (2) ρ (w(I 1 )) ≡ k ρ (w(I 2 )), so the two strings cannot be distinguished by first-order formulas of quantifier depth k. By choice of I 1 and I 2 (1) is the case for = 0. For (2), observe that if w(I 1 ) and w(I 2 ) have a different number of substrings of the form ab j , then both numbers n 1 j and n 2 j are at least 2 k . By a standard Ehrenfeucht-Fraïsse argument, these numbers cannot be distinguished by first-order formulas of quantifier depth k. There are no other differences that could help differentiating w(I 1 ) and w(I 2 ). For the inductive step, observe that (1) has to be true after applying ρ for the -th time, as the update formulas can only access the auxiliary bits and the strings after − 1 changes, but the former are equal and the latter are not distinguishable by the first-order update formulas of quantifier depth k. Therefore, the result of applying the update formulas has to be equal for every auxiliary bit. (2) is true with an analogous argumentation as in the base case.
It remains to prove that after some number of applications of ρ, one modified string is in L while the other is not. As P gives the same answer for both instances after each change, this shows that P is not correct.
Assume that w(I 1 ) and w(I 2 ) are either both in L or both not on L. Otherwise, P is not correct and we are done. Let i be smallest index on which I 1 and I 2 differ. Without loss of generality, i ∈ I 1 and i / ∈ I 2 . Assume further that after each of the first i applications of ρ, either both modified strings are in L, or both are not. Again, otherwise we are done. It follows that before ρ has been applied for the i-th time, the number of substrings ab was either even for both strings or odd for both strings. By applying ρ for the i-th time, in the first string an even number of substring a i ba are modified to a i+1 , so an even number of substrings ab is removed, while in the second string an odd number of substrings ab is removed. So, when ρ is applied for the i + 1-th time, the number of positions whose label changes from b to a has for the first string the same parity as that number from the application before, while for the second string the parity of that number changes. As we assumed that after i applications of ρ both strings are in L or both are not, after i + 1 applications of ρ exactly one of the modified strings is in L.