Work-sensitive Dynamic Complexity of Formal Languages
Jonas Schmidt, Thomas Schwentick, Till Tantau, Nils Vortmeier, Thomas Zeume
aa r X i v : . [ c s . L O ] J a n Work-sensitive Dynamic Complexity of FormalLanguages
Jonas Schmidt , Thomas Schwentick , Till Tantau , Nils Vortmeier , andThomas Zeume TU Dortmund University, Germany {jonas2.schmidt,thomas.schwentick}@tu-dortmund.de Universität zu Lübeck, Germany [email protected] University of Zurich, Switzerland [email protected] Ruhr University Bochum, Germany [email protected]
Abstract.
Which amount of parallel resources is needed for updating aquery result after changing an input? In this work we study the amount ofwork required for dynamically answering membership and range queriesfor formal languages in parallel constant time with polynomially manyprocessors. As a prerequisite, we propose a framework for specifying dy-namic, parallel, constant-time programs that require small amounts ofwork. This framework is based on the dynamic descriptive complexityframework by Patnaik and Immerman.
Keywords:
Dynamic complexity · work · parallel constant time.
Which amount of parallel resources is needed for updating a query result afterchanging an input, in particular if we only want to spend constant parallel time?In classical, non-dynamic computations, parallel constant time is well under-stood. Constant time on CRAMs, a variant of CRCW-PRAMs used by Immer-man [16], corresponds to constant-depth in circuits, so, to the circuit class AC ,as well as to expressibility in first-order logic with built-in arithmetic (see, forinstance, the books of Immerman [16, Theorem 5.2] and Vollmer [28, Theorems4.69 and 4.73]). Even more, the amount of work, that is, the overall number ofoperations of all processors, is connected to the number of variables required bya first-order formula [16, Theorem 5.10].However, the work aspect of constant parallel time algorithms is less under-stood for scenarios where the input is subject to changes. To the best of ourknowledge, there is only little previous work on constant-time PRAMs in dy-namic scenarios. A notable exception is early work showing that spanning treesand connected components can be computed in constant time by CRCW-PRAMswith O ( n ) and O ( n ) processors, respectively [26]. J. Schmidt, T. Schwentick, T. Tantau, N. Vortmeier, and T. Zeume
In an orthogonal line of research, parallel dynamic constant time has beenstudied from a logical perspective in the dynamic complexity framework by Pat-naik and Immerman [23] and Dong, Su, and Topor [7,6]. In this framework, theupdate of query results after a change is expressed by first-order formulas. Theformulas may refer to auxiliary relations, whose updates in turn are also specifiedby first-order formulas (see Section 3 for more details). The queries maintainablein this fashion constitute the dynamic complexity class
DynFO . Such queries canbe updated by PRAMs in constant time with a polynomial number of proces-sors. In this line of work, the main focus in recent years has been on proving thatqueries are in
DynFO , and thus emphasised the constant time aspect. It has, forinstance, been shown that all context-free languages [12] and the reachabilityquery [5] are in
DynFO .However, if one tries to make the “
DynFO approach” for dynamic problemsrelevant for practical considerations, the work that is needed to carry out thespecified updates, hence the work of a parallel algorithm implementing them, isa crucial factor. The current general polynomial upper bounds are too coarse. Inthis paper, we therefore initiate the investigation of more work-efficient dynamicprograms that can be specified by first-order logic and that can therefore becarried out by PRAMs in constant time. To do so, we propose a framework forspecifying such dynamic, parallel, constant-time programs, which is based onthe
DynFO framework, but allows for more precise (and better) bounds on thenecessary work of a program.
Goal 1.1.
Extend the formal framework of dynamic complexity towards the con-sideration of parallel work.
Towards this goal, we link the framework we propose to the CRAM framework inSection 3. In fact, the new framework also takes a somewhat wider perspective,since it does not focus exclusively at one query under a set of change operations,but rather considers dynamic problems that may have several change and queryoperations (and could even have operations that combine the two). Therefore,from now on we speak about dynamic problems and not about (single) queries.
Goal 1.2.
Find work-efficient
DynFO -programs for dynamic problems that areknown to be in
DynFO (but whose dynamic programs are not competitive, work-wise). Ideally we aim at showing that dynamic problems can be maintained in
DynFO with sublinear or even polylogarithmic work. One line of attack for thisgoal is to study dynamic algorithms and to see whether they can be transformedinto parallel O (1) -time algorithms with small work. There is a plethora of workthat achieves polylogarithmic sequential update time (even though, sometimesonly amortised), see for instance [3,9,13,14]. For many of these problems, it is In the field of dynamic complexity the term “dynamic program” is traditionally usedfor the programs for updating the auxiliary data after a change. The term should notbe confused with the “dynamic programming” technique used in algorithm design.ork-sensitive Dynamic Complexity of Formal Languages 3 known that they can be maintained in constant parallel time with polynomialwork, e.g. as mentioned above, it has been shown that connectivity and mainte-nance of regular (and even context-free) languages is in
DynFO .In this paper, we follow this approach for dynamic string problems, morespecifically, dynamic problems that allow membership and range queries for reg-ular and context-free languages. Our results can be summarised as follows.We show in Section 5 that regular languages can be maintained in constanttime with O ( n ǫ ) work for all ǫ > and that for star-free languages even work O (log n ) can be achieved. These results hold for range and membership queries.For context-free languages, the situation is not as nice, as we observe inSection 6. We show that subject to a well-known conjecture, we cannot hope formaintaining membership in general context-free languages in DynFO with lessthan O ( n . − ǫ ) work. The same statement holds even for the bound O ( n − ǫ ) and “combinatorial dynamic programs”. For Dyck languages, that is, sets of well-formed strings of parentheses, we show that this barrier does not apply. Theirmembership problem can be maintained with O ( n (log n ) ) work in general, andwith polylogarithmic work if there is only one kind of parentheses. By a differentapproach, range queries can be maintained with work O ( n ǫ ) in general, and O ( n ǫ ) for one parenthesis type. Related work.
A complexity theory of incremental time has been developedin [22]. We discuss previous work on dynamic complexity of formal languages inSections 5 and 6.
Since dynamic programs are based on first-order logic, we represent inputs likegraphs and strings as well as “internal” data structures as logical structures.A schema τ consists of a set of relation symbols and function symbols witha corresponding arity. A constant symbol is a function symbol with arity . A structure D over schema τ with finite domain D has, for every k -ary relationsymbol R ∈ τ , a relation R D ⊆ D k , as well as a function f D : D k → D for every k -ary function symbol f ∈ τ . We allow partially defined functions and write f D (¯ a ) = ⊥ if f D is not defined for ¯ a in D . Formally, this can be realized usingan additional relation that contains the domain of f D . We occasionally also usefunctions f D : D k → D ℓ for some ℓ > . Formally, such a function represents ℓ functions f D , . . . , f D ℓ : D k → D with f D (¯ a ) def = ( f D (¯ a ) , . . . , f D ℓ (¯ a )) .Throughout this work, the structures we consider provide a linear order ≤ on their domain D . As we can thus identify D with an initial sequence of thenatural numbers, we usually just assume that D = [ n ] def = { , . . . , n − } for somenatural number n .We assume familiarity with first-order logic FO , and refer to [19] for basics ofFinite Model Theory. In this paper, unless stated otherwise, first-order formulas always have access to a linear order on the domain, as well as compatible func-tions + and × that express addition and multiplication, respectively. This holds J. Schmidt, T. Schwentick, T. Tantau, N. Vortmeier, and T. Zeume in particular for formulas in dynamic programs. We use the following “if-then-else” construct: if ϕ is a formula, and t and t are terms, then ITE ( ϕ, t , t ) isa term. Such a term evaluates to the result of t if ϕ is satisfied, otherwise to t .Following [12], we encode words of length (at most) n over an alphabet Σ by word structures , that is, as relational structures W with universe { , . . . , n − } ,one unary relation R σ for each symbol σ ∈ Σ and the canonical linear order ≤ on { , . . . , n − } . We only consider structures for which, for every position i , R σ ( i ) holds for at most one σ ∈ Σ and write W ( i ) = σ if R σ ( i ) holds and W ( i ) = ǫ ifno such σ exists. We write word ( W ) for the word represented by W , that is, theconcatenation w = W (0) ◦ . . . ◦ W ( n − . As an example, the word structure W with domain { , , , } , W (1) = a , W (3) = b and W (0) = W (2) = ǫ representsthe string ab . We write word ( W )[ ℓ, r ] for the word W ( ℓ ) ◦ . . . ◦ W ( r ) .Informally, a dynamic problem can be seen as a data type: it consists of someunderlying structure together with a set ∆ of operations. We distinguish between change operations that can modify the structure and query operations that yieldinformation about the structure, but combined operations could be allowed, aswell. Thus, a dynamic problem is characterised by the schema of its underlyingstructures and the operations that it supports. In this paper, we are particularly interested in dynamic language problems,defined as follows. Words are represented as word structures W with elementarychange operations set σ ( i ) (with the effect that W ( i ) becomes σ if it was ǫ before)and reset ( i ) (with the effect that W ( i ) becomes ǫ ).For some fixed language L over some alphabet Σ , the dynamic problem RangeMember ( L ) further supports one query operation range ( ℓ, r ) . It yieldsthe result true, if word ( W )[ ℓ, r ] is in L , and otherwise false.In the following, we denote a word structure W as a sequence w . . . w n − of letters with w i ∈ Σ ∪ { ǫ } in order to have an easier, less formal notation.Altogether, the dynamic problem RangeMember ( L ) is defined as follows. Problem:
RangeMember ( L ) Input:
A sequence w = w . . . w n − of letters with w i ∈ Σ ∪ { ǫ } Changes: set σ ( i ) for σ ∈ Σ : Sets w i to σ , if w i = ǫ reset ( i ) : Sets w i to ǫ Queries: range ( ℓ, r ) : Is w ℓ ◦ · · · ◦ w r ∈ L ?In this example, the query range maps (binary) pairs of domain elements to atruth value and thus defines a (binary) relation over the universe of the inputword structure. We call such a query relational . We will also consider functional queries mapping tuples of elements to elements.Another dynamic problem considered here is Member ( L ) which is definedsimilarly as RangeMember ( L ) but instead of range only has the Booleanquery operation member that yields true if w ◦ . . . ◦ w n − ∈ L holds. This view is a bit broader than the traditional setting of Dynamic Complexity, wherethere can be various change operations but usually only one fixed query is supported.ork-sensitive Dynamic Complexity of Formal Languages 5
Since we are interested in the work that a dynamic program does, our specifica-tion mechanism for dynamic programs is considerably more elaborated than theone used in previous papers on dynamic complexity. We introduce the mecha-nism in this section in two steps. First the general form of dynamic programsand then a more pseudo-code oriented syntax. Afterwards, we discuss how thesedynamic programs translate into work-efficient constant-time parallel programs.
Our general form of dynamic programs mainly follows [25], but is adapted to theslightly broader view of a dynamic problem as a data type. For a more gentleintroduction to dynamic complexity, we refer to [24].The goal of a dynamic program for a dynamic problem Π is to support allits operations ∆ . To do so, it stores and updates an auxiliary structure A oversome schema τ aux , over the same domain as the input structure I for Π .A (first-order) dynamic program P consists of a set of (first-order) updaterules for change operations and query rules for query operations. More precisely,a program has one query rule over schema τ aux per query operation that speci-fies how the (relational) result of that operation is obtained from the auxiliarystructure. Furthermore, for each change operation δ ∈ ∆ , it has one updaterule per auxiliary relation or function that specifies the updates after a changebased on δ .A query rule is of the form on query Q (¯ p ) yield ϕ Q (¯ p ) , where ϕ Q is the(first-order) query formula with free variables from ¯ p .An update rule for a k -ary auxiliary relation R is of the form on change δ (¯ p ) update R at ( t (¯ p ; ¯ x ) , . . . , t k (¯ p ; ¯ x )) as ϕ Rδ (¯ p ; ¯ x ) where C (¯ x ) . Here, ϕ Rδ is the (first-order) update formula , t , . . . , t k are first-order terms (pos-sibly using the ITE construct) over τ aux , and C (¯ x ) , called a constraint for thetuple ¯ x = x , . . . , x ℓ of variables, is a conjunction of inequalities x i ≤ f i ( n ) usingfunctions f i : N → N , where n is the size of the domain and ≤ i ≤ ℓ . Wedemand that all functions f i are first-order definable from + and × .The effect of such an update rule after a change operation δ (¯ a ) is as follows:the new relation R A ′ in the updated auxiliary structure A ′ contains all tuplesfrom R A that are not equal to ( t (¯ a ; ¯ b ) , . . . , t k (¯ a ; ¯ b )) for any tuple ¯ b that satisfiesthe constraints C ; and additionally R A ′ contains all tuples ( t (¯ a ; ¯ b ) , . . . , t k (¯ a ; ¯ b )) such that ¯ b satisfies C and A | = ϕ Rδ (¯ a ; ¯ b ) holds.Phrased more operationally, an update is performed by enumerating all tu-ples ¯ b that satisfy C , evaluating ϕ Rδ (¯ a ; ¯ b ) on the old auxiliary structure A , anddepending on the result adding the tuple ( t (¯ a ; ¯ b ) , . . . , t k (¯ a ; ¯ b )) to R (if it wasnot already present), or removing that tuple from R (if it was present).Update rules for auxiliary functions are similar, but instead of an updateformula that decides whether a tuple of the form ( t (¯ a ; ¯ b ) , . . . , t k (¯ a ; ¯ b )) is con- J. Schmidt, T. Schwentick, T. Tantau, N. Vortmeier, and T. Zeume tained in the updated relation, it features an update term that determines thenew function value for a function argument of the form ( t (¯ a ; ¯ b ) , . . . , t k (¯ a ; ¯ b )) .We say that P is a dynamic program for a dynamic problem Π if it sup-ports all its operations and, in particular, always yields correct results for queryoperations. More precisely, if the result of applying a query operation after asequence α of change operations on an initial structure I yields the same resultas the evaluation of the query rule on the auxiliary structure that is obtained byapplying the update rules corresponding to the change operations in α to an ini-tial auxiliary structure A . Here, an initial input structure I over some domain D is empty , that is, it is a structure with empty relations and with all functionvalues being undefined ( ⊥ ). The initial auxiliary structure A is over the samedomain D as I and is defined from I by some FO -definable initialization.By DynFO , we denote the class of all dynamic problems that have a dynamicprogram in the sense we just defined.
In this paper we are particularly interested in dynamic programs that requirelittle work to update the auxiliary structure after every change operation andto compute the result of a query operation. However, since dynamic programsdo not come with an execution model, there is no direct way to define, say,when a
DynFO -programs has polylogarithmic-work, syntactically. But it is evennot clear how a semantic definition could be obtained: the obvious approach torequire that the program has an implementation as a parallel program that onlyneeds polylogarithmic-work does not work, since it is not clear how to definewhen a parallel program implements a given dynamic program. This difficultyoccurs in particular if one wants to prove that some problem does not have awork-efficient dynamic program.Since, we are not interested in lower bounds in this paper, we follow a prag-matic approach here. We define a pseudo-code-based syntax for update and queryprocedures that will be used in place of the update and query formulas in rules ofdynamic programs. This syntax has three important properties: (1) it is reason-ably well readable (as opposed to strict first-order logic formulas), (2) it allows astraightforward translation of rules into proper
DynFO -programs, and (3) it al-lows to associate a “work-bounding function” to each rule and to translate it intoa PRAM program with O (1) parallel time and work bounded by this function.The syntax of the pseudo-code has similarities with Abstract State Ma-chines [4] and the PRAM-syntax of [17]. For simplicity, we describe a minimalset of syntactic elements that suffice for the dynamic programs in this paper.We encourage readers to have a look at Section 4 for examples of update ruleswith pseudo-code syntax. However, we mention some extensions that could beconsidered for more complicated programs.We only spell out a syntax for update procedures that can be used in placeof the update formula ϕ Rδ (¯ p ; ¯ x ) of an update rule on change δ (¯ p ) update R at ( t (¯ p ; ¯ x ) , . . . , t k (¯ p ; ¯ x )) as ϕ Rδ (¯ p ; ¯ x ) where C (¯ x ) . ork-sensitive Dynamic Complexity of Formal Languages 7 Query procedures are defined similarly, but they can not invoke any changeoperations for supplementary instances, and their only free variables are from ¯ p .We allow some compositionality: a dynamic program on some main instance can use supplementary instances of other dynamic problems and invoke changeor query operations of other dynamic programs on those instances. These sup-plementary instances are declared on a global level of the dynamic program andeach has an associated identifier.Update procedures P = P ; P consist of two parts. In the initial procedure P no reference to the free variables from ¯ x are allowed, but change operationsfor supplementary instances can be invoked. We require that, for each changeoperation δ of the main instance and each supplementary instance S , at mostone update rule for δ invokes change operations for S . In general, some moreflexibility could be added, e.g., additional local instances.In the main procedure P , no change operations for supplementary instancescan be invoked, but references to ¯ x are allowed.More precisely, both P and P can use (a series of) instructions of thefollowing forms: – assignments f (¯ y ) ← term of a function value, – assignments R (¯ y ) ← condition of a Boolean value, – conditional branches if condition then P ′ else P ′′ , and – parallel branches for z ≤ g ( n ) pardo P ′ .Semantically, here and in the following n always refers to the size of thedomain of the main instance. The initial procedure P can further use changeinvocations instance .δ (¯ y ) . – change invocations instance .δ (¯ y ) .However, they are not allowed in the scope of parallel branches. And we recallthat in P no variables from ¯ x can be used.The main procedure P can further use return statements return condition or return term , but not inside parallel branches. – return statements return condition or return term , but not inside parallelbranches.Of course, initial procedures can only have initial procedures P ′ and P ′′ inconditional and parallel branches, and analogously for main procedures.Conditions and terms are defined as follows. In all cases, ¯ y denotes a tupleof terms and z is a local variable , not occurring in ¯ p or ¯ x . In general, a term evaluates to a domain element (or to ⊥ ). It is built from – local variables and variables from ¯ p and ¯ x , – function symbols from τ aux and previous function assignments, – if-then-else terms if condition then term ′ else term ′′ , – functional queries instance .Q (¯ y ) , and – expressions getUnique ( z ≤ g ( n ) | condition ). J. Schmidt, T. Schwentick, T. Tantau, N. Vortmeier, and T. Zeume
For the latter expression it is required that there is always exactly one domainelement a ≤ g ( n ) satisfying condition .A condition evaluates to true or false . It may be – an atomic formula with relation symbols from τ aux or previous assignments,with terms as above, – an expression exists ( z ≤ g ( n ) | condition ), – a relational query instance .Q (¯ y ) with terms ¯ y , and – a Boolean combination of conditions.All functions g : N → N in these definitions are required to be FO -definable.For assignments of relations R and functions f we demand that these symbolsdo not appear in τ aux . If an assignment with a head f (¯ y ) or R (¯ y ) occurs in thescope of a parallel branch that binds variable z , then z has to occur as a term y i in ¯ y . We further demand that update procedures are well-formed, in the sensethat every execution path ends with a return statement of appropriate type.In our pseudo-code algorithms, we display update procedures P = P ; P with initial procedure P and main procedure P as on change δ (¯ p ) with P update R at ( t (¯ p, ¯ x ) , . . . , t k (¯ p, ¯ x )) , for all C (¯ x ) , by : P .to emphasise that P only needs to be evaluated once for the update of R , andnot once for every different value of ¯ x .In a nutshell, the semantics of an update rule on change δ (¯ p ) update R at ( t (¯ p ; ¯ x ) , . . . , t k (¯ p ; ¯ x )) as P where C (¯ x ) is defined as in Subsection 3.1, but A | = ϕ Rδ (¯ a, ¯ b ) has to be replaced by thecondition that P returns true under the assignment (¯ p ¯ a ; ¯ x ¯ b ) .For update rules for auxiliary functions, P returns the new function valueinstead of a Boolean value.Since P is independent of ¯ x , in the semantics, it is only evaluated once. Inparticular, any change invocations are triggered only once.We refer to the above class of dynamic update programs as Procedural-DynFO-programs. Here and later we will introduce abbreviations as syntactic sugar, forexample the sequential loop for z ≤ m do P , where m ∈ N needs to be a fixednatural number.We show next that update and query procedures can be translated intoconstant-time CRAM programs. Since the latter can be translated into FO -formulas [15, Theorem 5.2], therefore Procedural-DynFO-programs can be trans-lated in DynFO -programs.It is not hard to see that Procedural-DynFO-programs can be transformedinto
DynFO -programs, as stated in the following proposition.
Proposition 3.1.
If a dynamic problem Π can be specified by a Procedural-DynFO-program then Π ∈ DynFO . ork-sensitive Dynamic Complexity of Formal Languages 9 However, we do not need to prove this proposition, since we show next thatProcedural-DynFO-programs can be translated into constant-time CRAMs andit is known that such programs can be translated into FO ( ≤ , + , × ) -formulas [15,Theorem 5.2]. We use
Parallel Random Access Machines (PRAMs) as the computational modelto measure the work of our dynamic programs. A PRAM consists of a numberof processors that work in parallel and use a shared memory. We only consider
CRAMs , a special case of Concurrent-Read Concurrent-Write model (CRCWPRAM), i.e. processors are allowed to read and write concurrently from andto the same memory location, but if multiple processors concurrently write thesame memory location, then all of them need to write the same value. For aninput of size n we denote the time that a PRAM algorithm needs to computethe solution as T ( n ) . The work W ( n ) of a PRAM algorithm is the sum of thenumber of all computation steps of all processors made during the computation.For further details we refer to [15,17].It is easy to see that Procedural-DynFO programs P can be translated into O (1) -time CRAM-programs C . To be able to make a statement about (an upperbound of) the work of C , we associate a function w with update rules and showthat every update rule π can be implemented by a O (1) -time CRAM-programwith work O ( w ) . Likewise for query rules.In a nutshell, the work of an update procedure mainly depends on the scopesof the (nested) parallel branches and the amount of work needed to query andupdate the supplementary instances. The work of a whole update rule is thendetermined by adding the work of the initial procedure once and adding thework of the main procedure for each tuple that satisfies the constraint of theupdate rule.The function w is defined as follows. Let the update rule π be of the form on change δ (¯ p ) update R at ( t (¯ p, ¯ x ) , . . . , t k (¯ p, ¯ x )) , for all x ≤ g ( n ) ∧ . . . ∧ x ℓ ≤ g ℓ ( n ) , by : P with P = P ; P consisting of an initial procedure P and a main procedure P . For simplicity we require that for each variable x i there is an inequality x i ≤ g i ( n ) , but it could be g i ( n ) = n . We set w ( π ) def = max( w ( P ) , g ( n ) · . . . · g ℓ ( n ) · w ( P )) , where w ( P ) is inductively defined as follows.For terms t and conditions C , we define w ( t ) and w ( C ) , inductively. w ( t ) def = if t is a constant or a variable max( w ( t ) , . . . , w ( t ℓ )) if t = f ( t , . . . , t ℓ ) , max( w ( C ) , w ( t ) , w ( t )) if t = if C then t else t g ( n ) · w ( C ) if t = getUnique ( z ≤ g ( n ) | C ) . w ( C ) def = if C is atomic, max( w ( C ) , . . . , w ( C m )) if C is a Boolean combinationof conditions C , . . . , C m ,g ( n ) · w ( C ′ ) if C = exists ( z ≤ g ( n ) | C ′ ) ,w ( π ′ ) if C is instance .Q (¯ y ) and π ′ isits query rule.Furthermore, – w ( f (¯ y ) ← C ) def = w ( C ) , – w ( R (¯ y ) ← t ) def = w ( t ) , – w ( if C then P ′ else P ′′ ) def = max( w ( C ) , w ( P ′ ) , w ( P ′′ )) , – w ( for z ≤ g ( n ) pardo P ′ ) def = g ( n ) · w ( P ′ ) , – w ( return ϕ ) def = 1 , – w ( instance .δ (¯ y )) def = max( w ( π ) , . . . , w ( π m )) , where π , . . . , π m are the up-date rules for change operation δ . Proposition 3.2.
For every update rule π a O (1) -time PRAM-program withwork O ( w ( π )) can be constructed. Likewise for query rules. A sketch for the straightforward proof can be found in the appendix.It follows from Proposition 3.2 that a dynamic program P can be imple-mented by a O (1) -time PRAM-program with work O ( f ) , if for each update rule π of P it holds w ( π ) ≤ f . In this section we consider a simple dynamic problem with a fairly work-efficientdynamic program. It serves as an example for our framework but will also beused as a subroutine in later sections.The dynamic problem is to maintain a subset K of an ordered set D ofelements under insertion and removal of elements in K , allowing for navigationfrom an element of D to the next larger and smaller element in K . That is, weconsider the following dynamic problem: Problem:
NextInK
Input:
A set K ⊆ D with canonical linear order ≤ on D Changes: ins ( i ) : Inserts i ∈ D into K del ( i ) : Deletes i ∈ D from K Queries: pred ( i ) : Returns predecessor of i in K , that is, max { j ∈ K | i > j } succ ( i ) : Returns successor of i in K , that is, min { j ∈ K | i < j } For the smallest (largest) element the result of a pred ( succ ) query is unde-fined, i.e. ⊥ . For simplicity, we assume in the following that D is always of theform [ n ] , for some n ∈ N . ork-sensitive Dynamic Complexity of Formal Languages 11 Algorithm 1
Querying a successor. on query succ ( i ) :2: if max( T. root ) ≤ i then return ⊥ else k ← getUnique (1 ≤ k ≤ log( n ) | max( T. anc ( i, k )) > i ) ∧ max( T. anc ( i, k − ≤ i return min( T. ( T. anc ( i, k ))) Sequentially, the changes and queries of
NextInK can be handled in sequen-tial time O (log log n ) [9]. Here we show that the problem also has a dynamicprogram with parallel time O (1) and work O (log n ) . Lemma 4.1.
There is a
DynFO -program for
NextInK with O (log n ) work perchange and query operation. Proof.
The dynamic program uses an ordered binary balanced tree T with leaveset [ n ] , and with as its leftmost leaf. Each inner node v represents the interval S ( v ) of numbers labelling the leafs of the subtree of v . To traverse the tree, thedynamic program uses functions 1st and 2nd that map an inner node to its first orsecond child, respectively, and a function anc ( v, j ) that returns the j -th ancestorof v in the tree. Formally, the | D | nodes of T can be represented by pairs ( a, b ) of elements from the domain D , where b indicates the height of the node in thetree, and a gives the left-to-right position of the node among all nodes with thesame height. Then, we have to use pairs of binary functions 1st , etc. thatmap encodings of a node to the components of the encoding of another node. Wedisregard these technical issues and use nodes of T just as domain elements, andalso identify an element i ∈ [ n ] with the i -th leaf of T . The technical translationis straightforward and does not affect our reasoning regarding FO -expressibilityand work of dynamic programs. So, anc ( v, returns the parent of the parentof v . If there is no j -th ancestor of a node v , then anc ( v, j ) is undefined.The functions 1st, 2nd and anc are static, that is, they are initialized before-hand and not affected by change operations.The idea of the dynamic program is to maintain, for each node v , the max-imal and minimal element in K ∩ S ( v ) (which is undefined if K ∩ S ( v ) = ∅ ),by maintaining two functions min and max . It is easy to see that this informa-tion can be updated and queries be answered in O (log n ) time as the tree hasdepth O (log n ) . For achieving O (log n ) work and constant time, we need to havea closer look.Using min and max , it is easy to determine the K -successor of an ele-ment i ∈ D : if v is the lowest ancestor of i with max( v ) > i , then the K -successorof i is min( w ) for the second child w def = ( v ) of v . Algorithm 1 shows a queryrule for the query operation succ ( i ) . The update of these functions is easy whenan element i is inserted into K . This is spelled out for min in Algorithm 2. Thedynamic program only needs to check if the new element becomes the minimalelement in S ( v ) , for every node v that is an ancestor of the leaf i . Algorithm 2
Updating min after an insertion. on change ins ( i ) update min at T. anc ( i, k ) , for all k ≤ log n , by :2: v ← T. anc ( i, k ) if min( v ) > i then return i else return min( v ) Algorithm 3
Updating min after a deletion. on change del ( i ) with s ← succ ( i ) update min at T. anc ( i, k ) , for all k ≤ log n , by :5: v ← T. anc ( i, k ) if min( v ) = i then return min( v ) else if max( v ) = i then return ⊥ else return s Algorithm 3 shows how min can be updated if an element i is deleted from K :if i is the minimal element of K in S ( v ) , for some node v , then min( v ) needs tobe replaced by its K -successor, assuming it is in S ( v ) .It is easy to verify the claimed work upper bounds for P . Querying a suc-cessor or predecessor via Algorithm 1 needs O (log n ) work, since Line 6 requires O (log n ) and all others require O (1) work. For maintaining the function min the programs in Algorithms 2 and 3 update the value of log n tuples, but thework per tuple is constant. In the case of a deletion, Line 3 requires O (log n ) work but is executed only once. The remaining part consists of O (log n ) parallelexecutions of statements, each with O (1) work.The handling of max and its work analysis is analogous. ⊓⊔ In this section, we show that the range problem can be maintained with o ( n ) workfor all regular languages and with polylogarithmic work for star-free languages.For the former we show how to reduce the work of a known DynFO -program.For the latter we translate the idea of [9] for maintaining the range problem forstar-free languages in O (log log n ) sequential time into a dynamic program with O (1) parallel time. ork-sensitive Dynamic Complexity of Formal Languages 13 Let L be a regular language. Then RangeMember ( L ) can bemaintained in DynFO with work O ( n ǫ ) per query and change operation, for every ǫ > . The proof of this theorem makes use of the algebraic view of regular lan-guages. For readers not familiar with this view, the basic idea is as follows: for afixed DFA A = ( Q, Σ, δ, q , F ) , we first associate with each string w a function f w on Q that is induced by the behaviour of A on w via f w ( q ) def = δ ∗ ( q, w ) ,where δ ∗ is the extension of the transition function δ to strings. The set of allfunctions f : Q → Q with composition as binary operation is a monoid , that is,a structure with an associative binary operation ◦ and a neutral element, theidentity function. Thus, composing the effect of A on subsequent substrings ofa string corresponds to multiplication of the monoid elements associated withthese substrings. The syntactic monoid M ( L ) of a regular language L is basicallythe monoid associated with its minimal automaton.It is thus clear that, for the dynamic problem RangeMember ( L ) where L is regular, a dynamic program can be easily obtained from a dynamic programfor the dynamic problem RangeEval ( M ( L )) , where RangeEval ( M ) , for finitemonoids M , is defined as follows. Problem:
RangeEval ( M ) Input:
A sequence m . . . m n − of monoid elements m i ∈ M Changes: set m ( i ) for m ∈ M : Replaces m i by m Queries: range ( ℓ, r ) : m ℓ ◦ · · · ◦ m r For the proof of Theorem 5.1 we do not need any insights into monoid the-ory. However, when studying languages definable by first-order formulas in The-orem 5.3 below, we will make use of a known decomposition result.From the discussion above it is now clear that in order to prove Theorem 5.1,it suffices to prove the following result.
Proposition 5.2.
Let M be a finite monoid. For every ǫ > , RangeEval ( M ) can be maintained in DynFO with work O ( n ǫ ) per query and change operation.Proof sketch. In [12], it was (implicitly) shown that
RangeMember ( L ) is in DynProp (that is, quantifier-free
DynFO ), for regular languages L . The idea wasto maintain the effect of a DFA for L on w [ ℓ, r ] , for each interval ( ℓ, r ) of positions.This approach can be easily used for RangeEval ( M ) as well, but it requires aquadratic number of updates after a change operation, in the worst case.We adapt this approach and only store the effect of the DFA for O ( n ǫ ) intervals, by considering a hierarchy of intervals of bounded depth. We note that, unlike for words, each position always carries a monoid element.However, the empty string of the word case corresponds to the neutral element inthe monoid case. In particular, the initial “empty” sequence consists of n copies ofthe neutral element.4 J. Schmidt, T. Schwentick, T. Tantau, N. Vortmeier, and T. Zeume m m m m m m m m m m m m m m m m m m m m m m m m m m m level level level Fig. 1.
Illustration of special intervals, for t = 3 . The special intervals of level are [0 , , [9 , , [18 , , [0 , and [9 , with base interval [0 , . The result of aquery range (2 , can be computed as Q i =2 m i = (cid:0) m [2 , ◦ m [3 , (cid:1) ◦ m [9 , ◦ (cid:0) m [18 , ◦ m [21 , (cid:1) , illustrated above in blue. The affected base intervals for a changeat position are marked in red. E.g., the new product m ′ [18 , can be computed by m ′ [18 ,
27) = m [18 , ◦ m ′ [21 , ◦ m [24 , . As the products are recomputed bottomup, m ′ [21 , is already updated. The first level in the hierarchy of intervals is obtained by decomposing theinput sequence into intervals of length t , for a carefully chosen t . We call theseintervals base intervals of height and their subintervals special intervals ofheight . The latter are special in the sense that they are exactly the intervalsfor which the dynamic program maintaines the product of monoid elements. Inparticular, each base interval of height gives rise to O ( t ) special intervalsof height . The second level of the hierarchy is obtained by decomposing thesequence of base intervals of height into sequences of length t . Each suchsequence of length t is combined to one base interval of height ; and eachcontiguous subsequence of such a sequence is combined to one special intervalof height . Again, each base interval of height gives rise to O ( t ) specialintervals of height . This process is continued recursively for the higher levelsof the hierarchy, until only one base interval of height h remains. We refer toFigure 1 for an illustration of this construction.The splitting factor t is chosen in dependence of n and ǫ such that the heightof this hierarchy of special intervals only depends on ǫ and is thus constant forall n . More precisely, we fix λ def = ǫ and t def = n λ , rounded up. For simplicity ofexposition, we assume from now on that n = t λ . Therefore, h = log t ( n ) = λ .The idea for the dynamic program is to store the product of monoid elementsfor each special interval. The two crucial observations are then, that (1) theproduct of each (not necessary special) interval can be computed with the helpof a constant number of special intervals, and (2) that each change operationaffects at most t special intervals per level of the hierarchy and thus at most ht ∈ O ( n ǫ ) special intervals in total. We refer to the appendix for more details. ⊓⊔ ork-sensitive Dynamic Complexity of Formal Languages 15 Although the work bound of Theorem 5.1 for regular languages is strongly sublin-ear, one might aim for an even more work-efficient dynamic program, especially,since
RangeMember ( L ) can be maintained sequentially with logarithmic up-date time for regular languages [9]. We leave it as an open problem whether forevery regular language L there is a DynFO -program for
RangeMember ( L ) witha polylogarithmic work bound. However, we show next that such programs existfor star-free regular languages, in fact they even have a logarithmic work bound.The star-free languages are those that can be expressed by regular expressionsthat do not use the Kleene star operator but can use complementation. Theorem 5.3.
Let L be a star-free regular language. Then RangeMember ( L ) can be maintained in DynFO with work O (log n ) per query and change operation. It is well-known that star-free regular languages are just the regular languagesthat can be defined in first-order logic (without arithmetic!) [20]. Readers mightask why we consider dynamic first-order maintainability of a problem that canactually be expressed in first-order logic. The key point is the parallel work here:even though the membership problem for star-free languages can be solved by aparallel algorithm in time O (1) , it inherently requires parallel work Ω ( n ) . Proof sketch.
The proof uses the well-known connection between star-free lan-guages and group-free monoids (see, e.g., [27, Chapter V.3] and [27, TheoremV.3.2]). It thus follows the approach of [9].In a nutshell, our dynamic program simply implements the algorithms of theproof of Theorem 2.4.2 in [9]. Those algorithms consist of a constantly boundednumber of simple operations and a constantly bounded number of searches fora next neighbour in a set. Since the latter can be done in
DynFO with work O (log n ) thanks to Lemma 4.1, we get the desired result for group-free monoidsand then for star-free languages. We refer to the appendix for more details. ⊓⊔ As we have seen in Section 5, range queries to regular languages can be main-tained in
DynFO with strongly sublinear work. An immediate question is whethercontext-free languages are equally well-behaved. Already the initial paper by Pat-naik and Immerman showed that
DynFO can maintain the membership problemfor
Dyck languages D k , for k ≥ , that is, the languages of well-balanced paren-theses expressions with k types of parentheses [23]. It was shown afterwards in[12, Theorem 4.1] that DynFO actually captures the membership problem for allcontext-free languages and that Dyck languages even do not require quantifiersin formulas (but functions in the auxiliary structure) [12, Proposition 4.4]. Theseresults can easily be seen to apply to range queries as well. However, the dynamicprogram of [12, Theorem 4.1] uses 4-ary relations and three nested existentialquantifiers, yielding work in the order of n . In the following, we show that the membership problem for context-free lan-guages is likely not solvable in
DynFO with sublinear work, but that the Dycklanguage D with one bracket type can be handled with polylogarithmic workfor the membership problem and work O ( n ǫ ) for the range problem, and thatfor other Dyck languages these bounds hold with an additional linear factor n . Our conditional lower bound for context-free languages is based on a resultfrom Abboud et al. [2] and the simple observation that the word problem for alanguage L can be solved, given a dynamic program for its membership problem. Lemma 6.1.
Let L be a language. If Member ( L ) can be maintained in DynFO with work f ( n ) , then the word problem for L can be decided sequentially in time O ( n · f ( n )) . The announced lower bound is relative to the following conjecture [1].
Conjecture 6.2 ( k -Clique conjecture). For any ǫ > , and k ≥ , k -Clique has noalgorithm with time bound O ( n (1 − ǫ ) ω k ) .Here, ω is the matrix multiplication exponent [11,29], which is known to besmaller than . and believed to be exactly two [11,29].In [2], the word problem for context-free languages was linked to the k -Cliqueproblem as follows. Theorem 6.3 ([2, Theorem 1.1]).
There is a context free grammar G suchthat, if the word problem for L ( G ) can be solved in time T ( n ) , k -Clique can besolved on n node graphs in O ( T ( n k +1 )) time, for any k ≥ . Putting Lemma 6.1 and Theorem 6.3 together, we get the following result.
Theorem 6.4.
There is a context free grammar G such that, if the membershipproblem for L ( G ) can be solved by a DynFO -program with work O ( n ω − − ǫ ) , forsome ǫ > , then the k -Clique conjecture fails. The simple proofs of Lemma 6.1 and Theorem 6.4 are presented in the appendix.Thus, we can not reasonably expect any
DynFO -programs for general context-free languages with considerable less work than O ( n . ) barring any break-throughs for matrix multiplication. In fact, for “combinatorial DynFO -programs”,an analogous reasoning yields a work lower bound of O ( n − ǫ ) . We next turn to Dyck languages. Clearly, all Dyck languages are deterministiccontext-free, their word problem can therefore be solved in linear time, andthus the lower bound approach of the previous subsection does not work forthem. In [8] it was shown that D is maintainable by a sequential dynamic ork-sensitive Dynamic Complexity of Formal Languages 17 algorithm in time O (log n ) , per change and query operation, and D k in time O ((log n ) · log ∗ n ) , for every k > . We already mentioned that their membershipproblem can be maintained in DynFO . The challenge is to find dynamic programs(with parallel time O (1) ) with little work.We show that it is actually possibly by suitably adapting the idea from [8] toget a DynFO -program for D with polylogarithmic work, but for D k , for k > ,the approach so far only yields DynFO -programs with an additional linear factorin the work bound. We first present the
DynFO -program with polylogarithmicwork for the membership problem of D . It basically mimics the sequential al-gorithm from [8] that maintains D . Theorem 6.5.
Member ( D ) can be maintained in DynFO with O ((log n ) ) work.Proof sketch. Let Σ = {h , i} be the alphabet underlying D . The dynamicprogram uses an ordered binary tree T such that each leaf corresponds to oneposition from left-to right. A parent node corresponds to the set of positions ofits children. We assume for simplicity that the domain is [ n ] , for some number n that is a power of 2. If the input string is w then each node x of T representsa substring str ( x ) of w via the leaves of the induced subtree at x in a naturalfashion. The main idea from [8] is to maintain for each node x of T informa-tion about the unmatched parentheses of str ( x ) . The input word is in the Dycklanguage if there are no unmatched parentheses in the root of T .In a nutshell, the dynamic program for Member ( D ) maintains for eachnode x of T the numbers ℓ ( x ) and r ( x ) that represent the number of unmatchedclosing and unmatched opening brackets of the string str ( x ) . E.g., if that stringis ihiihhi for x , then ℓ ( x ) = 2 and r ( x ) = 1 . The overall string w is in D exactlyif r ( root ) = ℓ ( root ) = 0 .In the algorithm of [8], the functions ℓ and r are updated in a bottom-up fash-ion. However, we will observe that they do not need to be updated sequentiallyin that fashion, but can be updated in parallel constant time. In the following,we describe how P can update ℓ ( x ) and r ( x ) for all ancestor nodes x of a posi-tion p , after a closing parenthesis i was inserted at p . Maintaining ℓ and r forthe other change operations is analogous.There are two types of effects that an insertion of a closing parenthesis couldhave on x : either ℓ ( x ) is increased by one and r ( x ) remains unchanged, or r ( x ) is decreased by one and ℓ ( x ) remains unchanged. We denote these effects by thepairs (+1 , and (0 , − , respectively.Table 1 shows how the effect of a change at a position p below a node x with children y and y relates to the effect at the affected child. This dependson whether r ( y ) ≤ ℓ ( y ) and whether the affected child is y or y . A closerinspection of Table 1 reveals a crucial observation: in the upper left and thelower right field of the table, the effect on x is independent of the effect on thechild (being it y or y ). That is, these cases induce an effect on x independent ofthe children. We thus call these cases effect-inducing . In the other two fields, theeffect on x depends on the effect at the child, but in the simplest possible way: p is in str ( y ) p is in str ( y ) r ( y ) ≤ ℓ ( y ) (+1 , → (+1 , , − → (+1 ,
0) (+1 , → (+1 , , − → (0 , − r ( y ) > ℓ ( y ) (+1 , → (+1 , , − → (0 , −
1) (+1 , → (0 , − , − → (0 , − Table 1.
The effect on x after a closing parenthesis was inserted at position p . Theeffects depend on the effect on the children y and y of x : for example, an entry’ (0 , − → (+1 , ’ in the column ’ p is in str ( y ) ’ means that if the change operationhas effect (0 , − on y then the change operation has effect (+1 , on x . they are just the same. That is the effect at the child is just adopted by x . Wecall these cases effect-preserving . To determine the effect at x it is thus sufficientto identify the highest affected descendant node z of x , where an effect-inducingcase applies, such that for all intermediate nodes between x and z only effect-preserving cases apply.Our dynamic program implements this idea. First it determines, for eachancestor x of the change position p , whether it is effect-inducing and whicheffect is induced. Then it identifies, for each x , the node z (represented by itsheight i above p ) as the unique effect-inducing node that has no effect-inducingnode on its path to x . The node z can be identified with work O ((log n ) ) , as z is one of at most log n many nodes on the path from x to the leaf of p , andone needs to check that all nodes between x and z are effect-preserving. As theauxiliary relations need to be updated for log n many nodes, the overall work of P is O ((log n ) ) . We refer to the appendix for more details. ⊓⊔ A work-efficient dynamic program for range queries for D and D k Unfortunately, the program of Theorem 6.5 does not support range queries,since it seems that one would need to combine the unmatched parentheses of log n many nodes of the binary tree in the worst case. However, its idea can becombined with the idea of Proposition 5.2, yielding a program that maintains ℓ and r for O ( n ǫ ) special intervals on a constant number of levels.In fact, this approach even works for D k for k > . Indeed, with the helpof ℓ and r , it is possible to identify for each position of an opening parenthesisthe position of the corresponding closing parenthesis in O (1) parallel time withwork n ǫ , and then one only needs to check that they match everywhere. Thelatter contributes an extra factor O ( n ) to the work, for k > , but can beskipped for k = 1 . Theorem 6.6.
For all ǫ > , k > ,a) RangeMember ( D ) can be maintained in DynFO with O ( n ǫ ) work, andb) RangeMember ( D k ) can be maintained in DynFO with O ( n ǫ ) work per changeoperation and O ( n ǫ ) work per query operation. ork-sensitive Dynamic Complexity of Formal Languages 19 Proof sketch.
In the following we reuse the definition of special intervals fromthe proof of Proposition 5.2 as well as the definition of ℓ and r from the proof ofProposition 6.5. We first describe a dynamic program P for RangeMember ( D ) .It maintains ℓ and r for all special intervals, which is clearly doable with O ( n ǫ ) work per change operation. Similar to the proof of Proposition 5.2, the two cru-cial observations (justified in the appendix) are that (1) a range query can beanswered with the help of a constant number of special intervals, and (2) thechange operation affects only a bounded number of special intervals per level.As stated before, the program for RangeMember ( D k ) also maintains ℓ and r , but it should be emphasised that also in the case of several parenthe-sis types, the definition of these functions ignores the bracket type. With thatinformation it computes, for each opening bracket the position of its matchingclosing bracket, with the help of ℓ and r , and checks that they match. This canbe done in parallel and with work O ( n ǫ ) per position. We refer to the appendixfor more details. ⊓⊔ Moderately work-efficient dynamic programs for D k We now turn to themembership query for D k with k > . Again, our program basically mimics thesequential algorithm from [8] which heavily depends on the dynamic problem StringEquality that asks whether two given strings are equal.
Problem:
StringEquality
Input:
Two Sequences u = u . . . u n − and v = v . . . v n − of letterswith u i , v i ∈ Σ ∪ { ǫ } Changes: set x,σ ( i ) for σ ∈ Σ, x ∈ { u, v } : Sets x i to σ , if x i = ǫ reset x ( i ) for x ∈ { u, v } : Sets x i to ǫ Queries: equals : Is u ◦ . . . ◦ u n − = v ◦ . . . ◦ v n − ?It is easy to show that a linear amount of work is sufficient to maintain StringEquality . Lemma 6.7.
StringEquality is in
DynFO with work O ( n ) . Because of the linear work bound for
StringEquality our dynamic programfor
Member ( D k ) also has a linear factor in the work bound. Theorem 6.8.
Member ( D k ) is maintainable in DynFO with O ( n log n +(log n ) ) work for every fixed k ∈ N .Proof sketch. The program can be seen as an extension of the one for
Member ( D ) .As unmatched parentheses are no longer well-defined if we have more than onetype of parenthesis the idea of [8] is to maintain the parentheses to the leftand right that remain if we reduce the string by matching opening and closingparentheses regardless of their type. To be able to answer Member ( D k ) , thedynamic program maintains the unmatched parentheses for every node x of atree spanning the input word, and a bit M ( x ) that indicates whether the typesof the parentheses match properly. How the unmatched parentheses can be maintained for a node x after achange operation depends on the “segment” of str ( x ) in which the change hap-pened and in some cases reduces to finding a node z with a local property onthe path from x to the leaf that corresponds to the changed position.To update M ( x ) for a node x with children y and y the dynamic programcompares the unmatched parentheses to the right of y with the ones to the leftof y using StringEquality . We refer to the appendix for more details. ⊓⊔ Maintaining string equality and membership in D k for k > is even closerrelated which is stated in the following lemma. Lemma 6.9. a) If
StringEquality can be maintained in
DynFO with work W ( n ) then Member ( D k ) can be maintained in DynFO with work O ( W ( n ) · log n + (log n ) ) , for each k ≥ .b) If Member ( D k ) can be maintained in DynFO with work W ( n ) for all k , then StringEquality can be maintained in
DynFO with work O ( W ( n )) . In this paper we proposed a framework for studying the aspect of work forthe dynamic, parallel complexity class
DynFO . We established that all regularlanguages can be maintained in
DynFO with O ( n ǫ ) work for all ǫ > , and evenwith O (log n ) work for star-free regular languages. For context-free languageswe argued that it will be hard to achieve work bounds lower than O ( n ω − − ǫ ) ingeneral, where ω is the matrix multiplication exponent. For the special case ofDyck languages D k we showed that O ( n · (log n ) ) work suffices, which can befurther reduced to O (log n ) work for D . For range queries, dynamic programswith work O ( n ǫ ) and O ( n ǫ ) exist, respectively.We highlight some research directions. One direction is to improve the upperbounds on work obtained here. For instance, it would be interesting to knowwhether all regular languages can be maintained with polylog or even O (log n ) work and how close the lower bounds for context-free languages can be matched.Finding important subclasses of context-free languages for which polylogarithmicwork suffices is another interesting question. Apart from string problems, many DynFO results concern problems on dynamic graphs, especially the reachabilityquery [5]. How large is the work of the proposed dynamic programs, and aremore work-efficient dynamic programs possible?The latter question also leads to another research direction: to establish fur-ther lower bounds. The lower bounds obtained here are relative to strong con-jectures. Absolute lower bounds are an interesting goal which seems in closerreach than lower bounds for
DynFO without bounds on the work.
References
1. Abboud, A., Backurs, A., Bringmann, K., Künnemann, M.: Fine-grained complex-ity of analyzing compressed data: Quantifying improvements over decompress-and-ork-sensitive Dynamic Complexity of Formal Languages 21solve. In: Umans, C. (ed.) 58th IEEE Annual Symposium on Foundations of Com-puter Science, FOCS 2017, Berkeley, CA, USA, October 15-17, 2017. pp. 192–203.IEEE Computer Society (2017). https://doi.org/10.1109/FOCS.2017.262. Abboud, A., Backurs, A., Williams, V.V.: If the current clique algorithms areoptimal, so is Valiant’s parser. SIAM J. Comput. (6), 2527–2555 (2018)3. Alstrup, S., Husfeldt, T., Rauhe, T.: Dynamic nested brackets. Inf.Comput. (2), 75–83 (2004). https://doi.org/10.1016/j.ic.2004.04.006, https://doi.org/10.1016/j.ic.2004.04.006
4. Börger, E.: Abstract state machines: a unifying view of models of computationand of system design frameworks. Ann. Pure Appl. Log. (1-3), 149–171 (2005).https://doi.org/10.1016/j.apal.2004.10.0075. Datta, S., Kulkarni, R., Mukherjee, A., Schwentick, T., Zeume, T.: Reachability isin DynFO. J. ACM (5), 33:1–33:24 (2018). https://doi.org/10.1145/32126856. Dong, G., Su, J.: First-order incremental evaluation of datalog queries. In: DatabaseProgramming Languages (DBPL-4), Proceedings of the Fourth InternationalWorkshop on Database Programming Languages - Object Models and Languages,Manhattan, New York City, USA, 30 August - 1 September 1993. pp. 295–308(1993)7. Dong, G., Topor, R.W.: Incremental evaluation of datalog queries. In: DatabaseTheory - ICDT’92, 4th International Conference, Berlin, Germany, October 14-16,1992, Proceedings. pp. 282–296 (1992). https://doi.org/10.1007/3-540-56039-4_488. Frandsen, G.S., Husfeldt, T., Miltersen, P.B., Rauhe, T., Skyum, S.: Dynamicalgorithms for the Dyck languages. In: Akl, S.G., Dehne, F.K.H.A., Sack, J.,Santoro, N. (eds.) Algorithms and Data Structures, 4th International Work-shop, WADS ’95, Kingston, Ontario, Canada, August 16-18, 1995, Proceed-ings. Lecture Notes in Computer Science, vol. 955, pp. 98–108. Springer (1995).https://doi.org/10.1007/3-540-60220-8_549. Frandsen, G.S., Miltersen, P.B., Skyum, S.: Dynamic word problems. J. ACM (2), 257–271 (1997). https://doi.org/10.1145/256303.25630910. Freydenberger, D.D., Thompson, S.M.: Dynamic complexity of documentspanners. In: Lutz, C., Jung, J.C. (eds.) 23rd International Conferenceon Database Theory, ICDT 2020, March 30-April 2, 2020, Copenhagen,Denmark. LIPIcs, vol. 155, pp. 11:1–11:21. Schloss Dagstuhl - Leibniz-Zentrum für Informatik (2020). https://doi.org/10.4230/LIPIcs.ICDT.2020.11,
11. Gall, F.L.: Powers of tensors and fast matrix multiplication. In: International Sym-posium on Symbolic and Algebraic Computation, ISSAC ’14, Kobe, Japan, July23-25, 2014. pp. 296–303 (2014)12. Gelade, W., Marquardt, M., Schwentick, T.: The dynamic complexityof formal languages. ACM Trans. Comput. Log. (3), 19 (2012).https://doi.org/10.1145/2287718.228771913. Holm, J., de Lichtenberg, K., Thorup, M.: Poly-logarithmic deterministic fully-dynamic algorithms for connectivity, minimum spanning tree, 2-edge, and bicon-nectivity. J. ACM (4), 723–760 (2001). https://doi.org/10.1145/502090.50209514. Holm, J., Rotenberg, E.: Fully-dynamic planarity testing in polylogarithmic time.In: Makarychev, K., Makarychev, Y., Tulsiani, M., Kamath, G., Chuzhoy, J. (eds.)Proccedings of the 52nd Annual ACM SIGACT Symposium on Theory of Comput-ing, STOC 2020, Chicago, IL, USA, June 22-26, 2020. pp. 167–180. ACM (2020).https://doi.org/10.1145/3357713.338424915. Immerman, N.: Descriptive complexity. Graduate texts in computer science,Springer (1999). https://doi.org/10.1007/978-1-4612-0539-52 J. Schmidt, T. Schwentick, T. Tantau, N. Vortmeier, and T. Zeume16. Immerman, N.: Descriptive complexity. Springer Science & Business Media (2012)17. JáJá, J.: An Introduction to Parallel Algorithms. Addison-Wesley (1992)18. Krohn, K., Rhodes, J.: Algebraic theory of machines. i. prime decomposition theo-rem for finite semigroups and machines. Transactions of the American Mathemat-ical Society , 450–464 (1965)19. Libkin, L.: Elements of Finite Model Theory. Springer (2004).https://doi.org/10.1007/978-3-662-07003-120. McNaughton, R., Papert, S.: Counter-Free Automata. MIT Press (1971)21. Mehlhorn, K., Sundar, R., Uhrig, C.: Maintaining dynamic sequences underequality tests in polylogarithmic time. Algorithmica (2), 183–198 (1997).https://doi.org/10.1007/BF0252282522. Miltersen, P.B., Subramanian, S., Vitter, J.S., Tamassia, R.: Complexity mod-els for incremental computation. Theor. Comput. Sci. (1), 203–236 (1994).https://doi.org/10.1016/0304-3975(94)90159-723. Patnaik, S., Immerman, N.: Dyn-FO: A parallel, dynamic complexity class. In:PODS. pp. 210–221 (1994)24. Schwentick, T., Vortmeier, N., Zeume, T.: Sketches of dynamic complexity. SIG-MOD Rec. (2), 18–29 (2020). https://doi.org/10.1145/3442322.344232525. Schwentick, T., Zeume, T.: Dynamic Complexity: Recent Updates. SIGLOG News (2), 30–52 (2016). https://doi.org/10.1145/2948896.294889926. Sherlekar, D.D., Pawagi, S., Ramakrishnan, I.V.: O(1) parallel time incrementalgraph algorithms. In: Maheshwari, S.N. (ed.) Foundations of Software Technologyand Theoretical Computer Science, Fifth Conference, New Delhi, India, December16-18, 1985, Proceedings. Lecture Notes in Computer Science, vol. 206, pp. 477–495. Springer (1985). https://doi.org/10.1007/3-540-16042-6_2727. Straubing, H.: Finite automata, formal logic, and circuit complexity. BirkhauserVerlag (1994)28. Vollmer, H.: Introduction to circuit complexity: a uniform approach. Springer Sci-ence & Business Media (2013)29. Williams, V.V.: Multiplying matrices faster than Coppersmith-Winograd. In:Karloff, H.J., Pitassi, T. (eds.) Proceedings of the 44th Symposium on Theoryof Computing Conference, STOC 2012, New York, NY, USA, May 19 - 22, 2012.pp. 887–898. ACM (2012). https://doi.org/10.1145/2213977.2214056ork-sensitive Dynamic Complexity of Formal Languages 23 A Appendix for Section 3
Proof sketch (for Proposition 3.2).
We briefly sketch, how a PRAM P can eval-uate an update rule π of the form on change δ (¯ p ) update R at ( t (¯ p, ¯ x ) , . . . , t k (¯ p, ¯ x )) , for all x ≤ g ( n ) ∧ . . . ∧ x ℓ ≤ g ℓ ( n ) , by : P .with P = P ; P as before, in constant time and with work O ( w ( π )) . The initialprocedure P has to be evaluated only once and therefore contributes at most w ( P ) . The main procedure P has to be evaluated once, for every tuple ¯ x thatfulfils x ≤ g ( n ) ∧ . . . ∧ x k ≤ g ℓ ( n ) . To this end, it can use m def = g ( n ) · . . . · g ℓ ( n ) processors, each taking care of one evaluation, as in the following pseudo-code.This amounts to at most m evaluations of P and it thus suffices to show that Algorithm 4
Evaluation of the update rule for δ (¯ p ) . procedure Evaluate Rδ ( ¯ p )2: Evaluate P for x = 1 to g ( n ) pardo
4: . . .5: for x ℓ = 1 to g ℓ ( n ) pardo R (cid:0) t (¯ p, ¯ x ) , . . . , t k (¯ p, ¯ x ) (cid:1) ← Eval P (¯ p, ¯ x ) one evaluation of P only requires work O ( w ( P )) .The proof of this is relatively straightforward, but tedious. Each computationpath consists only of a constant number of steps (unless a query towards asupplementary instance occurs). Thus, assuming sufficient parallelisation, thePRAM only needs time O (1) . Along each path, w basically yields only 1, butany constant number is captured by the big O . This explains, why we can use max instead of addition, everywhere. Parallel branches, exists -expressions and unique -expressions translate into parallel branching of the PRAM, and that iscaptured in the definition of w by respective factors. Likewise, query operationsto supplementary instances are captured, by respective factors in the definitionof w . ⊓⊔ B Appendix for Section 5
Proof sketch (of Proposition 5.2, continued).
We start by introducing necessarynotation. In the following we fix the length n of a sequence m , . . . , m n − ofmonoid elements, we chose t as described above, and assume that t h = n . Wewrite m [ ℓ, r ) for the subsequence m ℓ , . . . , m r − , and, depending on the context,for the product m ℓ ◦ . . . ◦ m r − . If r ≤ ℓ then m [ ℓ, r ) is the neutral monoidelement.In order to define special intervals, we consider positions j ∈ [ n ] in t -adicrepresentation as P h − i =0 j i t i , where j i ∈ [ t ] , for every ≤ i < h . We saythat a number j has height k if k < h is the maximum number such that P h − i = k j i t i = P h − i =0 j i t i , that is, if j , . . . , j k − are zero and j k is not (or j = 0 and k = h − ).We say that an interval [ i, j ) of positions is special if, for some k and p , theheight of i and j is at least k and pt k +1 ≤ i ≤ j ≤ ( p + 1) t k +1 . It is easy to seethat, for each k and p there are O ( t ) such special intervals.The dynamic program maintains the product m [ i, j ) for all special intervals [ i, j ) .To show that the two crucial observations (1) and (2) stated above are correct,we need some more notation. For a number j ∈ [ n ] we write ⌊ j ⌋ k for the largestnumber p of height at least k with p ≤ j and ⌈ j ⌉ k for the smallest number q ofheight at least k with j ≤ q , i.e. ⌊ j ⌋ k def = j k t k + h − X i = k +1 j i t i and ⌈ j ⌉ k def = ( j k + 1) t k + h − X i = k +1 j i t i . Towards observation (1), it is not hard to see that the following equality holdsfor all ≤ ℓ, r ≤ n − and that the product consists of h −
1) + 1 = O (1) factors. Suppose that k < h is the smallest number such that ⌈ ℓ ⌉ k +1 > ⌊ r ⌋ k +1 ,then: m [ ℓ, r ) = k − Y j =0 m [ ⌈ ℓ ⌉ j , ⌈ ℓ ⌉ j +1 ) ◦ m [ ⌈ ℓ ⌉ k , ⌊ r ⌋ k ) ◦ k − Y j =0 m [ ⌊ r ⌋ j +1 , ⌊ r ⌋ j ) It is thus straightforward to answer range queries by a dynamic program withwork O (1) .Furthermore, towards observation (2), if position p is changed, only the in-formation for the ht special intervals that include p needs to be updated. Thiscan be done in h = O (1) phases. In phase k , the special intervals with height k are updated. The new product m ′ [ i, j ) can be obtained via m ′ [ i, j ) = m [ i, ⌊ p ⌋ k ) ◦ m ′ [ ⌊ p ⌋ k , ⌈ p ⌉ k ) ◦ m [ ⌈ p ⌉ k , j ) , where m ′ [ ⌊ p ⌋ k , ⌈ p ⌉ k ) is the already computed new value of the special interval [ ⌊ p ⌋ k , ⌈ p ⌉ k ) of height k − . This completes the proof sketch for Proposition 5.2. ⊓⊔ ork-sensitive Dynamic Complexity of Formal Languages 25 Towards a proof of Theorem 5.3, we employ the following algebraic propertyof syntactic monoids of star-free languages, due to Schützenberger, McNaughtonand Papert (see, e.g., [27, Chapter V.3]). A monoid M is called a group if foreach m ∈ M there is an inverse m − with m · m − = 1 . A monoid is called group-free if it does not contain a nontrivial group. Lemma B.1 ([27, Theorem V.3.2]).
A language L is star-free iff M ( L ) isfinite and group-free. In [9] it was shown that
RangeEval ( M ) for a group-free monoid M canbe maintained in O (log log n ) sequential time on RAMs with cell size O (log n ) .We adapt their algorithm to show that RangeEval ( M ) can be maintained in DynFO with logarithmic work.The main ingredient for the algorithm of [9] is the following consequence ofa decomposition theorem by Krohn and Rhodes.
Lemma B.2 ([18][9]).
Let M be a finite, group-free monoid. Then one of thefollowing holds:(a) M = { } ,(b) there is a k such that M − { } = { σ, σ , . . . , σ k = σ k +1 } ,(c) σσ ′ = σ , for all σ, σ ′ ∈ M − { } , or(d) M = V ∪ T where T = M and V = M are submonoids of M and T − { } isa left ideal of M , i.e. σ M σ T ∈ T − { } for all σ M ∈ M and σ T ∈ T − { } We illustrate this lemma by the following example. It will be reused to illus-trate the construction in our dynamic program for maintaining
RangeEval ( M ) . Example B.3.
Consider the language L = L (cid:0) c ∗ ac ∗ ac ∗ b ( a + b + c ) ∗ (cid:1) that containsall words over the alphabet Σ = { a, b, c } having at least one b and at least two a ’s somewhere before the first b . It syntactic monoid is M = { , A, A , B, D, E } with the following multiplication table: x \ y A A B D E
A A B D EA A A A D E EA A A A E E EB B B B B B BD D D D D D DE E E E E E E
The elements of M (and thus the states of the minimal automaton for L )correspond to the following languages. In particular, E corresponds to L . L (cid:0) c ∗ (cid:1) A L (cid:0) c ∗ ac ∗ (cid:1) A L (cid:0) c ∗ ac ∗ ac ∗ (cid:1) B L (cid:0) c ∗ b ( a + b + c ) ∗ (cid:1) D L (cid:0) c ∗ ac ∗ b ( a + b + c ) ∗ (cid:1) E L (cid:0) c ∗ ac ∗ ac ∗ b ( a + b + c ) ∗ (cid:1) The monoid can be decomposed as M = V ∪ T with T = { , B, D, E } and V = { , A, A } , which are Type (c) and Type (b) submonoids, respectively, of M in the sense of Lemma B.2.The characterization of group-free monoids provided by Lemma B.2 is thebasis for a recursive approach for maintaining RangeEval ( M ) . Theorem B.4.
Let M be a group-free monoid. Then RangeEval ( M ) can bemaintained in DynFO with work O (log n ) for each change and query operation.Proof. The proof is by induction on the decomposition of M . We describe, foreach case of Lemma B.2, how a dynamic program P can maintain RangeEval ( M ) with O (log n ) work.Let m = m . . . m n − be an input sequence. Case (a) from Lemma B.2 istrivial.For Case (b), suppose that M = { , σ, σ , . . . , σ k = σ k +1 } for some fixed k .As in this case the monoid elements (except for ) only differ in their exponents,the result of a range query range ( ℓ, r ) can be computed by summing over theexponents of all elements = 1 between ℓ and r . A closer look reveals that itsuffices to sum over the exponents of the first up to k elements differing fromthe identity element , because σ k = σ k +1 . For finding these up to k elementsquickly, the program uses a supplementary instance of NextInK for the set K = { i | w i = 1 } .These ideas lead to Algorithm 5 for answering range queries. As only a con-stant number of successors are queried from K , it requires at most O (log n ) workdue to Lemma 4.1. For changes of the input instance, only the supplementary NextInK instance needs to be updated, which also requires at most O (log n ) work by Lemma 4.1.For Case (c), suppose that M is a monoid with σσ ′ = σ for all σ, σ ′ ∈ M −{ } .In this case, a range query range ( ℓ, r ) results in the first element in the interval [ ℓ, r ] which is not the identity element (if such an element does not exist, thenthe result is the identity element). In order to find such an element quickly,the dynamic program maintains a supplementary NextInK instance for the set K = { i | w i = 1 } .Now range queries can be answered according to Algorithm 6, which clearlyrequires at most O (log n ) work. For changes of the input instance, again onlythe supplementary NextInK instance needs to be updated, which also requiresat most O (log n ) work. ork-sensitive Dynamic Complexity of Formal Languages 27 Algorithm 5
Querying the product m ℓ · . . . · m r in Case (b) of the proof ofTheorem B.4. on query range ( ℓ, r ) :2: s ← i ← ( ℓ − for to k do i = K. succ ( i ) if i ≤ r then s ← s + exponent ( i ) if s > then return a s else return Algorithm 6
Querying the product m ℓ · . . . · m r in Case (c) of the proof ofTheorem B.4. on query range ( ℓ, r ) :2: i ← K. succ ( ℓ − if i ≤ r then return m i else return For Case (d), suppose that M = V ∪ T where T = M and V = M aresubmonoids of M and T − { } is a left ideal of M . Because of T = M and V = M , by induction we can assume that RangeEval ( T ) and RangeEval ( V ) can be maintained with work O (log n ) .Denote T −{ } by T =1 . The idea of the dynamic program is to split the inputsequence m into T =1 -blocks, consisting of a maximal sequence of consecutive el-ements of T =1 only, and T =1 -blocks consisting of maximal sequence of elementsof T =1 only. The program maintains precomputed products of each T =1 -blockcombined with its successive T =1 -block. Because T =1 is a left ideal, all these pre-computed block products result in elements of T =1 . A range query range ( ℓ, r ) for m can then be answered by computing the product of these precomputedblock products between ℓ and r and adding the at most two incomplete blockproducts at the beginning and the end of the queried range.For encoding the blocks as well as the precomputed products, the programuses three sequences t , v and u with the following intention. The sequences v and t partition m into elements of T =1 and V − T =1 , respectively. For the definitionof u , let K = { i | w i ∈ T =1 ∧ w i +1 / ∈ T =1 } be the set of switching positions , i.e.positions of the input sequence where the monoid element changes from T =1 to V − T =1 . At a switching position i , u i stores the product of elements between theprevious switching position and i . In order to find switching positions quickly,the dynamic program maintains a supplementary NextInK instance for theset K . Algorithm 7
Querying the product m ℓ · . . . · m r in Case (d) of the proof ofTheorem B.4. on query range ( ℓ, r ) :2: k ← K. succ ( ℓ − k q ← K. pred ( r ) return v. range ( ℓ, k ) ◦ t. range ( ℓ, k ) ◦ u. range ( k + 1 , k q ) ◦ v. range ( k q + 1 , r ) ◦ t. range ( k q + 1 , r ) More precisely, the three sequences are defined as t i = ( m i if m i ∈ T =1 otherwise ,v i = ( m i if m i ∈ V − T =1 otherwise ,u i = (Q ij = k i +1 m j if i ∈ K T otherwise , where k i = K. pred ( i ) if K. pred ( i ) = ⊥ and k i = 0 otherwise. Note that m i ∈ T =1 for all i with u i = 1 because T =1 is a left interval. We refer toExample B.5 for an illustration of these sequences.The result of a range query range ( ℓ, r ) can then be computed as r Y i = ℓ m i = k Y i = ℓ v i k Y i = ℓ t i k q Y i = k +1 u i r Y i = k q +1 v i r Y i = k q +1 t i where k < . . . < k q are all positions in K ∩{ ℓ − , . . . , r } . The resulting dynamicprogram, see Algorithm 7, clearly requires at most O (log n ) work.For changes of the input instance, the supplementary NextInK instance forthe switching positions needs to be updated, which requires at most O (log n ) work. Also the sequences t , v and u need to be updated. For v and t this is easy,but updating u requires some effort.For maintaining u after a change of the input instance at position p , we dis-tinguish the cases as summarized in Table 2. In every case, the precomputedblock product stored in the next switching position after p needs to be recom-puted. Additionally, if the insertion created a new block by splitting a block (seeCases (4) and (5)) or removed a block by merging two blocks (see Cases (2) and(3)) either u p or u p − has to be updated as well.In all cases, u is updated with a constant number of range queries to v and t which results overall in O (log n ) work. ⊓⊔ Combining Lemma B.1 and Theorem B.4 we get the desired upper workbound for FO definable languages. ork-sensitive Dynamic Complexity of Formal Languages 29 Case condition Changes to u (1) Switching positions do not change, i.e.either(a) m p ∈ T =1 iff m ′ p ∈ T =1 ,(b) m p − / ∈ T =1 and m ′ p , m p +1 ∈ T =1 ,or(c) m p − , m ′ p / ∈ T =1 and m p +1 ∈ T =1 u k ← k Y i = j +1 v i ◦ k Y i = j +1 t i (2) Two T =1 -blocks are merged, i.e. m p − , m ′ p , m p +1 ∈ T =1 and m p / ∈ T =1 , u k as in Case (1) and u p − ← (3) Two T =1 -blocks are merged, i.e. m p − , m ′ p , m p +1 / ∈ T =1 and m p ∈ T =1 , analogous to (2)(4) A T =1 -block is split, i.e. m p − , m p ∈ T =1 and m ′ p / ∈ T =1 , u k ← p − Y i = j +1 v i ◦ p − Y i = j +1 t i and u p − ← k Y i = p v i ◦ k Y i = p t i ,(5) A T =1 -block is split, i.e. m ′ p , m p +1 / ∈ T =1 and m p ∈ T =1 , analogous to (4) Table 2.
Summary of the cases for updating u after a change at position p . Supposethat v, t and K are already updated. By m p and m ′ p we denote the elements at position p before and after the change operation, respectively. In all cases k = K. succ ( p ) isdefined as the next switching position after p . For Case (1), j is defined as K. pred ( p ) ;for Case (3) as K. pred ( p − . Example B.5.
We revisit the monoid M with decomposition into T and V in-troduced in Example B.3. Consider the sequence m with its sequences t, v and u as defined in the proof of Theorem B.4: m = AA1AABBA11A1AABAA1B11A1B1A1A11BB t = v = AA1AA11A11A1AA1AA1111A111A1A1111 u = The sequences t and u consist of T =1 -elements and v of V − T =1 -elements only.For a query range (1 , on m the set of switching positions is { , , , } ,so the result of the query can be computed as follows: Y i =1 m i = Y i =1 v i Y i =1 t i Y i =7 u i Y i =24 v i Y i =24 t i = A BEA1 = E Note, that the results of the five subproducts are determined by subqueries to t, v and u and can be evaluated as described in Case (b) for v and Case (c) for t and u . C Appendix for Section 6
Proof sketch (of Lemma 6.1).
Let P be a dynamic program that maintains Member ( L ) with work f ( n ) . Whether w ∈ L holds for a given input string w = σ σ . . . σ n − can be decided by simulating P on the sequence of changeoperations that inserts σ to σ n one after the other. By simulating the PRAMsequentially, the work O ( f ( n )) for one change step translates into sequentialtime O ( f ( n )) , thus yielding an overall sequential time O ( n · f ( n )) . ⊓⊔ Proof of Theorem 6.3.
Let G be the grammar from Theorem 6.3 and let us as-sume, towards a contradiction, that there is a dynamic program for L ( G ) withwork O ( n ω − − ǫ ) . By Lemma 6.1 this would yield an algorithm for the word prob-lem for L ( G ) with time O ( n ω − ǫ ) . Theorem 6.3 would then give an algorithm for k -Clique with time bound O ( n ( k +1)( ω − ǫ ) ) .However, for k ≥ ǫ , this yields a contradiction as follows.We have ( k + 1)( ω − ǫ ) = ω k + ω − ( ǫ k + ǫ ) ≤ ω k − ǫ k , since ǫ k + ǫ = ǫ k + ǫ k + ǫ ≥ ǫ k + ǫ . Thus, k -Clique could be solved in time O ( n (1 − ǫ ) k ) . ⊓⊔ Proof of Theorem 6.5.
We give a complete proof here, repeating parts of theproof sketch in the body, for convenience.With a string w over Σ we associate the reduced string µ ( w ) that basicallyconsists of the unmatched closing parentheses of w followed by the unmatchedopening parentheses of w .Formally, µ ( w ) can be defined for strings w ∈ Σ ∗ as µ ( ǫ ) = ǫ and µ ( zσ ) = ( z ′ if µ ( z ) = z ′ h and σ = i µ ( z ) σ elsefor every σ ∈ Σ and z ∈ Σ ∗ . As indicated before, a reduced string can besplit into two strings u and v of the forms i ∗ and h ∗ , respectively. We call u theunmatched (closing) parentheses of w to the left and v the unmatched (opening)parentheses of w to the right.The algorithm of [8] stores, for each node x of T , the reduced string µ ( str ( x )) of its associated string, and updates these strings bottom up after each change,starting from the changed position, resulting in logarithmic (sequential) update-time. We show that the new reduced strings can be computed in constant paralleltime. To this end, we show that for each affected node x of T its new reducedstring can be determined by a parallel computation that does not need to knowthe new reduced string of its affected child.We describe a dynamic program P that maintains Member ( D ) , using abinary tree T as sketched above, which is constructed by the first-order initiali-sation as in the proof of Lemma 4.1. For each node x of the tree, P representsits reduced string by the number of unmatched closing parentheses of str ( x ) tothe left and to the right as auxiliary functions ℓ ( x ) and r ( x ) , respectively. Inparticular, the current word is well-balanced if r ( root ) = ℓ ( root ) = 0 . ork-sensitive Dynamic Complexity of Formal Languages 31 In the following, we describe how P can update ℓ ( x ) and r ( x ) for a node x after a closing parenthesis i was inserted at some position p . Maintaining ℓ and r for the other change operations is analogous. Note that ℓ and r only need tobe updated for nodes whose substring contains the changed position p , that is,for ancestors of the leaf at position p .There are two types of effects that an insertion of a closing parenthesis couldhave on x : Either ℓ ( x ) is increased by one and r ( x ) remains unchanged, or r ( x ) is decreased by one and ℓ ( x ) remains unchanged. We denote these effects bythe pairs (+1 , and (0 , − , respectively. We next analyse how the effect thatapplies to x depends on the effect of its affected child. We will see then thatthe effect on the child needs not to be known to update x , but that it can bedetermined by a direct parallel exploration of the nodes on the path from x to p .To this end, let y be the left child of x and y its right child. The effect on x depends on whether the changed position p is in str ( y ) or in str ( y ) , and onthe relation between r ( y ) and ℓ ( y ) before the change. Table 3 lists all possiblecombinations for (1) whether the changed position p is in str ( y ) or in str ( y ) ,(2) which effect occurs there, and (3) the relation between r ( y ) and ℓ ( y ) , andwhich effect is applied to x in each case. For example, if p is in the subtreeof y , the effect on y is (0 , − , and r ( y ) ≤ ℓ ( y ) holds. Then, the insertedclosing parenthesis matches (and is to the right of) a former unmatched openingparenthesis in str ( y ) . As r ( y ) ≤ ℓ ( y ) , all unmatched opening parentheses ofstr ( y ) could previously be matched by unmatched closing parentheses of str ( y ) .Since after the change there is one unmatched opening parenthesis less in str ( y ) ,the unmatched opening parentheses of y can still be matched but, on the otherhand, one more closing parenthesis of y cannot be matched in str ( x ) , so theeffect on x is (+1 , . p is in str ( y ) p is in str ( y ) r ( y ) ≤ ℓ ( y ) (+1 , → (+1 , , − → (+1 ,
0) (+1 , → (+1 , , − → (0 , − r ( y ) > ℓ ( y ) (+1 , → (+1 , , − → (0 , −
1) (+1 , → (0 , − , − → (0 , − Table 3.
The effect on x after a closing parenthesis was inserted at position p . Theeffects depend on the effect on the children y and y of x : for example, an entry’ (0 , − → (+1 , ’ in the column ’ p is in str ( y ) ’ means that if the change operationhas effect (0 , − on y then the change operation has effect (+1 , on x . A closer inspection of Table 3 reveals a crucial observation: in the upperleft and the lower right field of the table, the effect on x is independent of theeffect on the child (being it y or y ). That is, these cases induce an effect on x independent of the children. We thus call these cases effect-inducing . In theother two fields, the effect on x depends on the effect at the child, but in thesimplest possible way: they are just the same. That is the effect at the child Algorithm 8
Updating ( ℓ, r ) after the insertion of a closing parenthesis in theproof of Theorem 6.5. on change ins i ( p ) with for ≤ i ≤ log n pardo x ( i ) ← T. anc ( p, i ) c ( i ) ← T. anc ( p, i −
6: Ind+ ( i ) ← ( x ( i )) = c ( i ) ∧ r ( ( x ( i ))) ≤ ℓ ( ( x ( i )))
7: Ind- ( i ) ← ( x ( i )) = c ( i ) ∧ r ( ( x ( i ))) > ℓ ( ( x ( i )))
8: Ind ( i ) ← Ind+ ( i ) ∨ Ind- ( i ) update ( ℓ, r ) at T. anc ( p, k ) , for all k ≤ log n , by :10: if k = 0 then return (1 , else x ← T. anc ( p, k ) if exists ( ≤ i ≤ k | Ind ( i ) ) then i ← getUnique (1 ≤ i ≤ k | Ind ( i ) ∧ ¬ exists ( i < j ≤ k | Ind ( j ))) if Ind+ ( i ) then return ( ℓ ( x ) + 1 , r ( x )) else return ( ℓ ( x ) , r ( x ) − else return ( ℓ ( x ) + 1 , r ( x )) is just adopted by x . We call these cases effect-preserving . To determine theeffect at x it is thus sufficient to identify the highest affected descendant node z of x , where an effect-inducing case applies, such that for all intermediate nodesbetween x and z only effect-preserving cases apply.Algorithm 8 implements this idea. First it determines, for each ancestor x of the change position p , whether it is effect-inducing (Ind) and which effect isinduced (Ind + for (+1 , and Ind − for (0 , − ). Then it identifies, for each x ,the node z (represented by its height i above p ) as the unique effect-inducingnode that has no effect-inducing node on its path to x .The node z can be identified with work O ((log n ) ) , as z is one of at most log n many nodes on the path from x to v , and one needs to check that allnodes between x and z are effect-preserving. As the auxiliary relations need tobe updated for log n many nodes, the overall work of P is O ((log n ) ) . ⊓⊔ Proof sketch (of Theorem 6.6).
In the following we reuse the definition of specialintervals from the proof of Proposition 5.2 as well as the definition of ℓ and r from the proof of Proposition 6.5. We first describe a dynamic program P for RangeMember ( D ) . It maintains ℓ and r for all special intervals. Similar tothe proof of Proposition 5.2, the two crucial observations are that (1) a rangequery can be answered with the help of a constant number of special intervals, ork-sensitive Dynamic Complexity of Formal Languages 33 and (2) the change operation affects only a bounded number of special intervalsper level.Towards observation (1), recall that each (not necessarily special) intervalcan be split into a constant number of special intervals. To answer a query range ( p, q ) the program can verify whether the balance factor , that is the sumof the differences ℓ − r over all special intervals splitting [ p, q ] , is zero, and thatthe balance factor is not negative for any prefix of the sequence of the specialintervals.Towards observation (2), note that a change operation only affects the specialintervals that contain the changed position and that ℓ and r can be updatedbottom up in the same fashion as in the proof of Proposition 5.2.We turn now to RangeMember ( D k ) . Here, P maintains again ℓ and r for allspecial intervals but ignoring the type of parenthesis. If the query asks whetherthe string from position p to position q is in D k , then the program checks thatinside [ p, q ] all opening parentheses have consistent closing parentheses and thatthe “level” of p is the same as of q , that is, that the number of opening parenthesesis the same as the number of closing parentheses. This can be done by inspectingthe special intervals that lead from p to q in the canonical way.As there are a bounded number of levels in the hierarchy the work is O ( n ǫ ) per position and therefore O ( n ǫ ) in total. ⊓⊔ Proof sketch (of Lemma 6.7).
The proof is not entirely trivial, as we allowstrings to have positions labelled by ǫ , so we cannot simply compare the positionsof the input strings one by one in parallel. To deal with positions labelled by ǫ , the dynamic program maintain a bijection between the non- ǫ positions of thetwo given strings s and s such that the i -th non- ǫ position of s is mapped tothe i -th non- ǫ position in s , and vice versa. The strings are equal if all mappedpositions have the same label, which can be checked with work O ( n ) after eachchange.Such a bijection can be defined using the functions rank j ( i ) that map a non- ǫ position i in the string s j to the number m , if i is the m -th non- ǫ position i in s j ,and the inverse rank − j ( i ) of this function. The function rank j for a string s j canbe maintained as follows. If a (non- ǫ ) symbol is inserted at position p , the rankof all non- ǫ positions i > p is increased by and the changed position p getsrank j ( i ′ ) + 1 where i ′ is the next non- ǫ position to the left of p . Finding thisposition can be done in DynFO with O (log n ) work thanks to Lemma 4.1. Ifa symbol is deleted from a position p , the rank of all non- ǫ positions i > p is decreased by and the rank j ( p ) is no longer defined. The inverse can bemaintained in a very similar way. The necessary work for updating the functionsrank j and rank − j at the changed position p is bounded by O (log n ) , for all otherpositions it is bounded by a constant. So, the overall work is O ( n ) . ⊓⊔ Unfortunately, if we generalize the definition of a reduced string µ ( w ) toarbitrary many types of parentheses, the result is in general not a string ofclosing parentheses followed by a string of opening ones. The idea of [8] is nowto maintain the parentheses to the left and right that remain if we reduce thestring by matching opening and closing parenthesis regardless of their type. For a string w over the alphabet Σ k = Σ h k ∪ Σ i k = {h , . . . , h k } ∪ {i , . . . , i k } we define a type-aware reduced string µ a ( w ) and a type-unaware reduced string µ u ( w ) as µ a ( ǫ ) = µ u ( ǫ ) = ǫ and µ a ( zσ ) = ( z ′ if µ a ( z ) = z ′ h i and σ = i i , for some i ≤ kµ a ( z ) σ else µ u ( zσ ) = ( z ′ if µ u ( z ) = z ′ h i and σ = i j , for some i, j ≤ kµ u ( z ) σ else.Note that, as before, the type-unaware reduced string can always be split intoa first and second part that consist only of closing and opening parentheses, re-spectively. For a string w ∈ Σ ∗ k , we therefore use the type-unaware reduced stringto define the unmatched parentheses to the left µ ℓu ( w ) and to the right µ ru ( w ) . Weslightly abuse the notation by writing µ ℓu ( x ) for a node x instead of µ ℓu ( str ( x )) (as well as µ ru ( x ) , µ a ( x ) and µ u ( x ) ).To be able to answer Member ( D k ) , the dynamic program we construct main-tains the unmatched parentheses for every node x of a tree spanning the inputword, and a bit M ( x ) that indicates whether µ a ( x ) = µ u ( x ) holds.In [8] the unmatched parentheses and the bit M ( x ) are updated bottom upafter a change operation. For a node x with children y and y the bit M ( x ) isset to if both M ( y ) and M ( y ) are set to and if the unmatched openingparentheses of str ( y ) match correctly with the unmatched closing parenthesesof str ( y ) to the left. The latter condition can be tested by testing whethertwo strings are equal, namely the string µ ru ( y ) and the string that results from µ ℓu ( y ) by reversing the string and exchanging a closing parenthesis by an openingparenthesis of the same type (assuming that both strings have equal length,otherwise surplus symbols in the longer string are ignored).In [8], StringEquality is maintained in polylogarithmic sequential timeusing [21], in [10] it is shown that maintaining whether two substrings are equalis in
DynFO with a polynomial amount of work. Lemma 6.7 tells us that a linearamount of work is sufficient if one is only interested in equality of entire strings.
Proof sketch (of Lemma 6.8).
We describe a dynamic program P that maintains Member ( D k ) , using a precomputed binary tree T spanning the input word.For each node x of T the program maintains µ ℓu ( x ) and µ ru ( x ) , represented bythe subset of positions that constitute these strings, the bit M ( x ) , as well asthe string (cid:0) µ ℓu ( x ) (cid:1) R that results from µ ℓu ( x ) by first exchanging each closingparenthesis by an opening parenthesis of the same type, and then reversing thestring. Further auxiliary information is introduced later on. The input word isin D k if the root of the tree satisfies M ( root ) = 1 and µ ℓu ( root ) = µ ru ( root ) = ǫ .We first describe how µ ℓu ( x ) and µ ru ( x ) can be maintained with work O ((log n ) ) for a node x after a closing parenthesis is inserted at a position p correspond-ing to a leaf below x . Similar to D , after such an insertion either an openingparenthesis has to be removed from µ ru ( x ) or a closing one has to be insertedinto µ ℓu ( x ) . In contrast to D it is not sufficient to maintain only the number ork-sensitive Dynamic Complexity of Formal Languages 35 of unmatched parentheses, as we have to check whether only parenthesis of thesame type are matched, so the unmatched parentheses will be maintained explic-itly. But similar to D , one can infer how the unmatched parentheses need to beupdated for a tree node x either directly from the existing auxiliary informationof x and its children, or from the auxiliary information of some easy-to-identifynode that lies on the path from x to the leaf corresponding to the changed po-sition p . Which case applies depends on in which “segment” of str ( x ) the changehappened.Suppose that y and y are the children of x . We call x right-heavy if | µ ru ( y ) | ≤ | µ ℓu ( y ) | and left-heavy otherwise. Denote by p r ( x ) the position ofthe first unmatched opening parenthesis in µ ru ( x ) (if it exists), let p m ( x ) be theposition of the first unmatched opening parenthesis in µ ru ( y ) (if it exists), andlet p ′ m ( x ) be the position of the parenthesis that is matched with the parenthesisat position p m (so, the parenthesis at position | µ ru ( y ) | − in µ ℓu ( y ) ).We first assume that x is right-heavy. In this case we have that p m ( x )
p r ( x ) ,(2) p m ( x ) is defined and p m ( x ) < p < p ′ m ( x ) ,(3) Cases (1) and (2) do not apply and(3a) there is a node z on the path from x to the leaf for p such that Case (2)applies for z , or(3b) there is no such node z .In Case (1), that is, if p r ( x ) is defined and p > p r ( x ) , the next openingparenthesis to the left of p in µ ru ( x ) has to be removed from µ ru ( x ) since it isnow matched by the new parenthesis. The problem of finding this position is aninstance of NextInK for the set of opening parentheses, which can be solvedwith work O (log n ) thanks to Lemma 4.1.In all other cases, a closing parenthesis has to be inserted into µ ℓu ( x ) .In Case (2), that is, if p m ( x ) is defined and p m ( x ) < p < p ′ m ( x ) , the closingparenthesis at position p ′ m ( x ) is no longer matched by the opening parenthesisat position p m ( x ) . It is also not matched by any other opening parenthesis, asno such unmatched parentheses exist, so it needs to be inserted into µ ℓu ( x ) .In Case (3) we distinguish two subcases. For Case (3a), suppose that z is thefirst right-heavy node on the path from x to the leaf of p such that p m ( z ) < p
Part a) follows directly from the proof of The-orem 6.8 as the linear factor in the work bound is due to maintaining stringequality for log n many nodes. For b), observe that two strings s = σ . . . σ n and s = σ . . . σ n over an alphabet of size k are equal if and only if the word w def = h σ . . . h σ n i σ n . . . i σ is in D k ..