Memoization for Unary Logic Programming: Characterizing PTIME
MMemoization for Unary Logic Programming:Characterizing P
T I M E
Clément Aubert
InriaUniversité Paris-Est, LACL (EA 4219), UPEC,F-94010 Créteil, France
Marc Bagnol
Aix Marseille Université,CNRS, Centrale Marseille, I2M UMR 7373,13453, Marseille, France
Thomas Seiller
IHÉS
Abstract —We give a characterization of deterministic polyno-mial time computation based on an algebraic structure called theresolution semiring, whose elements can be understood as logicprograms or sets of rewriting rules over first-order terms.More precisely, we study the restriction of this framework toterms (and logic programs, rewriting rules) using only unary sym-bols. We prove it is complete for polynomial time computation,using an encoding of pushdown automata. We then introduce analgebraic counterpart of the memoization technique in order toshow its P
TIME soundness.We finally relate our approach and complexity results tocomplexity of logic programming. As an application of ourtechniques, we show a P
TIME -completeness result for a classof logic programming queries which use only unary functionsymbols.
Index Terms —Implicit Complexity, Resolution, Logic Program-ming, Polynomial Time, Proof Theory, Pushdown Automata,Geometry of Interaction.
I. I
NTRODUCTION
Complexity theory focuses on questions related to resourceusage of computer programs, such as the amount of time ormemory a given program will need to solve a problem.Complexity classes are defined as sets of problems that canbe solved by algorithms whose executions need comparableamounts of resources. For instance, the class P
TIME is theset of predicates over binary words that can be decided by aTuring machine implementing an algorithm whose executiontime is bounded by a polynomial in the size of its input.However, these definitions depend on the notion of machineand cost-model considered, for the efficiency of an algorithmis sensible to these. The “invariance thesis” [1] is a way tobypass this limitation by defining what “a reasonable model”is: all the “reasonable” models (endowed with cost models)can simulate each other with a “reasonable” overhead. Thebootstrap for this notion to apply largely was to remark thatpolynomial bounds on execution time are robust, as the classof problems captured by different models where this boundcoincide. The definition is still machine-dependent, but notdependent of a particular model of computation .One of the main motivations for an implicit computa-tional complexity (ICC) theory is to find completely machine-
This work was partly supported by the ANR-10-BLAN-0213 Logoi, theANR-11- BS02-0010 Récré and the ANR-11-INSE-0007 REVER. independent characterizations of complexity classes. The aimis to characterize classes not “ by constraining the amount ofresources a machine is allowed to use, but rather by imposinglinguistic constraints on the way algorithms are formulated.” [2,p. 90] This has been already achieved via different approaches,one of which is based on considering restricted programminglanguages or computational principles [3], [4], [5].A number of results also arose from proof theory throughthe study of subsystems of linear logic [6]. More precisely,the Curry-Howard — or proofs as programs — correspondenceexpresses a deep relation between formal proofs and typedprograms. For instance, one can define a formula
Nat whichcorresponds to the type of binary integers, in the sense that agiven (cut-free, i.e. normal, already evaluated) proof of thistype represents a given natural number. A proof of the formula
Nat ⇒ Nat then corresponds to an algorithm computinga function from integers to integers, where the computationitself amounts to a rewriting on proofs: the cut-eliminationprocedure.By restricting the rules of the logical system, one obtainsa subsystem where less proofs of type
Nat ⇒ Nat can bewritten, hence less algorithms can be represented. In a numberof such restricted systems the class of accepted proofs, i.e. ofprograms, corresponds to some complexity class: elementarycomplexity [7], [8], polynomial time [9], [10], logarithmic [11]and polynomial [12] space.More recently, new methods for obtaining implicit charac-terizations of complexity classes based on the geometry ofinteraction (G O I) research program [13] have been developed.The G O I approach offers a more abstract and algebraic pointof view on the cut-elimination procedure of linear logic. Oneworks with a set of untyped programs represented as somegeometric objects, e.g. graphs [14], [15] or generalizationsof graphs [16], bounded linear maps between Hilbert spaces(operators) [17], [18], [19], clauses (or “flows”) [20], [21].This set of objects is then considered together with an abstractnotion of execution, seen as an interactive process: a functiondoes not process a static input, but rather communicate withit, asking for values, reading its answers, asking for anothervalue, etc. We mean extensional correspondence: they compute the same functions. a r X i v : . [ c s . L O ] F e b ypes can then be defined as sets of program representationssharing comparable behaviors. For instance the type Nat ⇒ Nat is the set of untyped programs which, given an integeras input, produce an integer as output.This approach based on the G O I differs from previous ICCworks using linear logic in that they do not rely on a restrictionof some type system, but rather on a restriction on the set ofprogram representations considered. Still, they benefit fromprevious works in type theory: for instance the representationof integers used here comes from their representation in linearlogic, translated in the G O I setting, whose interactive pointof view on computation has proven crucial in characterizinglogarithmic space computation [11].The first results that used those innovative considerationswere based on operator algebras [22], [23], [24]. Here weconsider a more syntactic flavor of the G O I where untyped pro-grams are represented in the so-called resolution semiring [21],a semiring based on the resolution rule [25] and a specific classof logic programs. This setting presents some advantages: itavoids the involvement of operator algebras theory, it eases thediscussions in terms of complexity (we manipulate first-orderterms, which have natural notions of size, height, etc.) and itoffers a straightforward connection with complexity of logicprogramming [26].Previous works in this direction led to characterizationsof logarithmic space predicates L
OGSPACE and CO -NL OG - SPACE [27], [28], by considering for instance restrictions onthe height of variables.Our main contribution here is a characterization of the classP
TIME by studying a natural restriction, namely that one isallowed to use exclusively unary function symbols. Pushdownautomata are easily related to this simple restriction, for theycan be represented as logical programs satisfying this “unarity”restriction. This will imply the completeness of the modelunder consideration for polynomial time predicates.We then complete the characterization by showing that anysuch unary logic program can be decided in polynomial time.This part of the proof consists in an adaptation of S. Cook’smemoization technique [29] to the context of logic programs.The last part of the paper presents consequences of theseresults in terms of complexity of logic programming, namelythat the corresponding class of queries are P TIME -complete,when considering combined complexity [26, p. 380].Compared to other ICC characterizations of P
TIME , and inparticular those coming from proof theory, our results have asimple formulation and provide an original point of view oncomplexity classes.A byproduct of this work is to provide a method to testmembership in P
TIME : if one can rephrase a problem withclauses H (cid:97) B using only unary function symbols, then ourresult ensures that the problem lies in P TIME . Conversely if aproblem cannot be rephrased that way, it lies outside of P
TIME . More precisely, -way k -head non-deterministic finite automata withpushdown stack. See Sect. III-A1. A. Outline of the paper
We begin by giving in Sect. II-A the formal definition ofthe resolution semiring; then briefly explain how words canbe represented in this structure (Sect. II-B) and recall thecharacterization of logarithmic space obtained in earlier work(Sect. II-C). In Sect. II-D we introduce the restricted semiringthat will be under study in this paper: the S tack semiring.The next two sections are respectively devoted to the com-pleteness and soundness results for P TIME . For completeness,we first review the fact that multi-head finite automata withpushdown stack characterize P
TIME and review the memoiza-tion technique in this case (Sect. III-A), and then show howto represent them as elements built from the S tack semiring(Sect. III-B). The soundness result is then obtained by adaptingmemoization to the S tack semiring. This adaptation, whichwe call the saturation technique, is introduced in Sect. IV-A.In the last section, we formulate our results in terms ofcomplexity of logic programming. In particular, we explainhow elements of the S tack semiring can be seen as a particularkind of unary logic programs to which the saturation techniquecan be applied. This allows us to show that the combined com-plexity problem for unary logic program is P TIME -complete.As an illustration, we show in Sect. V-B that the circuitvalue problem can be solved with this method.II. T HE R ESOLUTION S EMIRING
A. Flows and Wirings
Let us begin with some reminders and notations on first-orderterms and unification theory.
Notation II.1 (terms).
We consider first-order terms, written t , u , v , . . . , built from variables and function symbols withassigned finite arity. Symbols of arity will be called constants .Sets of variables and of function symbols of any arity are sup-posed infinite. Variables will be noted in italics font (e.g. x, y )and function symbols in typewriter font (e.g. c , f ( · ) , g ( · , · ) ).We distinguish a binary function symbol • (in infix notation)and a constant symbol (cid:63) . We will omit the parentheses for • and write t • u • v for t • ( u • v ) .We write var ( t ) the set of variables occurring in the term t and say that t is closed if var ( t ) = ∅ . The height h ( t ) ofa term t is the maximal distance between its root and leaves;a variable occurrence’s height in t is its distance to the root.We will write θ t the result of applying the substitution θ to the term t and will call renaming a substitution α thatbijectively maps variables to variables. We will be concerned with formal solving of equations of theform t = u where t and u are terms. Let us introduce a preciseformulation of this problem and some associated vocabulary. Definition II.2 (unification, matching and disjointness).
Two terms t , u are: ◦ unifiable if there exists a substitution θ — a unifier of t and u — such that θ t = θ u . If any other unifier of t and u is annstance of θ , we say θ is the most general unifier (MGU)of t and u ; ◦ matchable if t (cid:48) , u (cid:48) are unifiable, where t (cid:48) , u (cid:48) are renamingsof t , u such that var ( t (cid:48) ) ∩ var ( u (cid:48) ) = ∅ ; ◦ disjoint if they are not matchable. A fundamental result of unification theory is that when twoterms are unifiable, a MGU exists and is computable. Morespecifically, the problem of deciding whether two terms areunifiable is P
TIME -complete [30, Theorem 1].The notion of MGU allows to formulate the resolution rule , akey concept of logic programming that defines the compositionof Horn clauses (expressions of the form H (cid:97) B , . . . , B n ): V (cid:97) T , . . . , T n H (cid:97) B , . . . , B m , U var ( U ) ∩ var ( V ) = ∅ θ is a MGU of U and V Res θH (cid:97) θB , . . . , θB m , θT , . . . , θT n Note that the condition on variables implies that we arematching U and V rather than unifying them. In other words,the resolution rule deals with variables as if they were bounded.From this perspective, “flows” — defined below — are aspecific type of Horn clauses H (cid:97) B , with exactly oneformula B on the right of (cid:97) and all the variables of H already appearing in B . The product of flows will be definedas the resolution rule restricted to this specific type of clauses. Definition II.3 (flow). A flow is an ordered pair f of terms f := t (cid:40) u , with var ( t ) ⊆ var ( u ) . Flows are considered upto renaming: for any renaming α , t (cid:40) u = α t (cid:40) α u . A flow t (cid:40) u can also be understood as a rewriting rule overthe set of first-order terms. For instance, the flow g ( x ) (cid:40) f ( x ) corresponds to the following rewriting rule: terms of the form f ( v ) where v is a term are rewritten as g ( v ) and all otherterms are left unchanged.We will soon define the product of flows which provides away of composing them; from the term-rewriting perspective,this operation corresponds to composing two rules — whenpossible, i.e. when the result of the first rewriting rule allowsthe application of the second — into a single one.For instance, one can compose the flows f := h ( x ) (cid:40) g ( x ) and f := g ( x ) (cid:40) f ( x ) to produce the flow f f = h ( x ) (cid:40) f ( x ) . Notice by the way that this (partial) product is notcommutative as composing these rules the other way aroundis impossible, i.e. f f is not defined. Definition II.4 (product of flows).
Let t (cid:40) u and v (cid:40) w betwo flows. Suppose we picked representatives of the renamingclasses such that var ( u ) ∩ var ( v ) = ∅ .The product of t (cid:40) u and v (cid:40) w is defined when u and v are unifiable, with MGU θ , as ( t (cid:40) u )( v (cid:40) w ) := θ t (cid:40) θ w . We now define wirings, which are simply finite sets of flowsand therefore correspond to logic programs. From the term-rewriting perspective they are just sets of rewriting rules. Thedefinition of product of flows is naturally lifted to wirings.
Definition II.5 (wiring). A wiring is a finite set of flows. Theirproduct is defined as F G := { f g | f ∈ F, g ∈ G, f g defined } .The resolution semiring R is the set of all wirings. The set of wirings R indeed enjoys a structure of semiring. We will use an additive notation for sets of flows to highlightthis situation: ◦ The symbol + will be used in place of ∪ , and we write setsas sums of their elements: { f , . . . , f n } := f + · · · + f n . ◦ We denote by the empty set, i.e. the unit of + . ◦ We have a unit for the product, the wiring I := x (cid:40) x .As we will always be working within R , the term “semiring”will be used instead of “subsemiring of R ”.Finally, let us recall the notion of nilpotency in a semiringand extend the notion of height (of terms) to flows and wirings. Definition II.6 (height).
The height h ( f ) of a flow f = t (cid:40) u is defined as max { h ( t ) , h ( u ) } . A wiring’s height is defined as h ( F ) = max { h ( f ) | f ∈ F } . By convention h (0) = 0 . Definition II.7 (nilpotency).
A wiring F is nilpotent — written Nil ( F ) — if and only if F n = 0 for some n . The above classical notion from abstract algebra has a specificreading in our case of study. In terms of logic programming, itmeans that all chains obtained by applying the resolution ruleto the set of clauses we consider cannot be longer than a certainbound. From the point of view of rewriting, it means that theset of rewriting rules we consider is terminating with a uniformbound on the length of rewriting chains — note however thatwe consider rewriting that occur only at the root of terms,while the usual notion from term rewriting systems [31] allowsin-context rewriting.
B. Representation of Words and Programs
This section explains and motivates the representation ofwords as flows. By studying their interactions with wiringsfrom a specific semiring, notions of program and language aredefined.First, let us see how the binary function symbol • usedto construct terms can be extended to build flows and thensemirings. Definition II.8.
Let u (cid:40) v and t (cid:40) w be two flows. Supposewe have chosen representatives of their renaming classes thathave disjoint sets of variables.We define ( u (cid:40) v ) • ( t (cid:40) w ) := u • t (cid:40) v • w . The operationis extended to wirings by ( (cid:80) i f i ) • ( (cid:80) j g j ) := (cid:80) i,j f i • g j .Then, given two semirings A and B , we define the semiring A • B := { (cid:80) i F i • G i | F i ∈ A , G i ∈ B } . A semiring is a set R equipped with two operations + (the sum) and × (the product, whose symbol is usually omitted), and an element ∈ R such that: ( R, + , is a commutative monoid; ( R, × ) is a semigroup , i.e. amonoid which may not have a neutral element; the product distributes overthe sum; the element is absorbent: r = r for all r ∈ R . he operation indeed defines a semiring because for any wirings F, F (cid:48) , G, G (cid:48) we have ( F • G )( F • G ) = F F (cid:48) • GG (cid:48) . Moreover,we carry on the convention of writing A • B • C for A • ( B • C ) . Notation II.9.
We write t (cid:11) u the sum t (cid:40) u + u (cid:40) t . Definition II.10 (word representations).
From now on, wesuppose fixed an infinite set of constant symbols P (the positionconstants ) and a finite alphabet Σ disjoint from P with (cid:63) (cid:54)∈ Σ (we write Σ ∗ the set of words over Σ ).Let W = c · · · c n ∈ Σ ∗ and p = p , p , . . . , p n bepairwise distinct elements of P .Writing p n +1 = p and c n +1 = c = (cid:63) , we define the representation of W associated with p , p , . . . , p n as thefollowing wiring: ¯ W p = n (cid:88) i =0 c i • r • x • y • HEAD ( p i ) (cid:11) c i +1 • l • x • y • HEAD ( p i +1 ) In this definition, the position constants represent memory cellsstoring the symbols (cid:63) , c , c , . . . .The representation of words is dynamic , i.e. we may thinkintuitively of movement instructions from a symbol to the nextor the previous (hence the choice of symbols l and r for“left/previous” and “right/next”) for some kind of automatonreading the input. More details on this will be given in theproof of Theorem III.3.Hence, for a given position constant p i , we use terms c i • r and c i • l which will be linked (by flows of the representation)to elements c i +1 • l at position p i +1 and c i − • r at position p i − respectively.Note moreover that the representation of the input is circular(this is a consequence of using the Church encoding of words),as we take c n +1 = c = (cid:63) . Flows representing the word c · · · c n can be pictured as follows: p (cid:63) • r (cid:63) • l p c • rc • l p c • rc • l . . . p n c n • rc n • l On the other hand, the notion of observation will be thecounterpart of a program in our construction. We first give ageneral definition, that will be instantiated later to classes ofobservations that characterize specific complexity classes. Theimportant point here is that we forbid an observation to useany position constant, in order to have it interact the same waywith all the representations ¯ W p of a word W . Definition II.11 (observation semiring).
We define the semir-ings P ⊥ of flows that do not use the symbols in P ; and Σ lr the semiring generated by flows of the form c • d (cid:40) c (cid:48) • d (cid:48) with c , c (cid:48) ∈ Σ ∪ { (cid:63) } and d , d (cid:48) ∈ { l , r } .We define the semiring of observations as: O := (Σ lr • R ) ∩ P ⊥ and the semiring of observations over the semiring A as O [ A ] := (Σ lr • A ) ∩ P ⊥ The following theorem is a consequence [21, Theorem IV.5]of the fact that observations cannot use position constants.
Theorem II.12 (normativity).
Let ¯ W p and ¯ W q be two rep-resentations of a word W and O an observation.Then Nil ( O ¯ W p ) if and only if Nil ( O ¯ W q ) . With this theorem, we can safely define how a word can beaccepted by an observation: the notion is independent of thespecific choice of a representation of position constants.
Definition II.13 (accepted language).
Let O be an observa-tion. We define the language accepted by O as L ( O ) := { W ∈ Σ ∗ | ∀ p, Nil ( O ¯ W p ) } C. Balanced Flows and Logarithmic Space
In previous work [28], we investigated the semiring of balanced wirings , that are defined as sets of balanced — or“height-preserving” — flows.
Definition II.14 (balance).
A flow f = t (cid:40) u is balanced iffor any variable x ∈ var ( t ) ∪ var ( u ) , all occurrences of x in both t and u have the same height (recall notations p. 2).A balanced wiring F is a sum of balanced flows.We write R b for the set of balanced wirings. Definition II.15 (balanced observation). A balanced observa-tion is an element of O [ R b • R b ] . This natural restriction was shown to characterize logarithmicspace computation [28, Theorems 34-35].
Theorem II.16 (balance and logarithmic space). If O isa balanced observation, then L ( O ) ∈ CO -NL OGSPACE . If L ∈ CO -NL OGSPACE then there exists a balanced observationsuch that L ( O ) = L . It also appears that a natural subclass of balanced wirings char-acterizes DL
OGSPACE , the class of deterministic logarithmicspace computable predicates.
D. The S tack Semiring
This paper deals with another restriction on flows, namelythe restriction to unary flows , i.e. flows defined from unaryfunction symbols only. The semiring of wirings composed onlyof unary flows is called the S tack semiring, and will be shownto characterize polynomial time computation. Here we brieflygive the definitions and results about this semiring that will beneeded in this paper. A more complete picture can be foundin the second author’s Ph.D. thesis [21]. Definition II.17 (unary flows). A unary flow is a flow builtusing only unary function symbols and a variable.The semiring S tack is the set of wirings of the form (cid:80) i t i (cid:40) u i where the t i (cid:40) u i are unary flows.Example II.18 . The flows f ( f ( x )) (cid:40) g ( x ) and x (cid:40) g ( x ) areunary, while x • f ( x ) (cid:40) g ( x ) and f ( c ) (cid:40) x are not. otation II.19 (stack operations). If τ = g , . . . , g n is afinite sequence of unary function symbols and t is a term,we write τ ( t ) := g (cid:0) g ( · · · g n ( t ) · · · (cid:1) . We will write τ σ theconcatenation of the sequences τ and σ . Given two sequences τ and σ we define the flow O P τ, σ := τ ( x ) (cid:40) σ ( x ) whichwe call a stack operation . Note that, by definition, an element of the S tack semiringmust be a sum of stack operations.The notion of cyclic flow is crucial in the proof of thecharacterization of polynomial time computation. As we willsee, it is complementary to the nilpotency property for elementsof S tack , i.e. a wiring in S tack will be shown to be eithercyclic or nilpotent. Definition II.20 (cyclicity).
A flow t (cid:40) u is a cycle if t and u are matchable (Definition II.2). A wiring F is cyclic if thereis a k such that F k contains a cycle.For (cid:126)s = f , . . . , f n a sequence of stack operations, define: ◦ its height as h ( (cid:126)s ) := max i (cid:8) h ( f i ) (cid:9) ◦ its cardinality Card( (cid:126)s ) := Card { f i | ≤ i ≤ n } . ◦ its product p ( (cid:126)s ) as f · · · f n .We say the sequence (cid:126)s is cyclic if there is a sub-sequence (cid:126)s i,j = f i , . . . , f j ( ≤ i ≤ j ≤ n ) such that p ( (cid:126)s i,j ) is a cycle.Remark II.21 . A flow f is a cycle iff f (cid:54) = 0 .To carry on the proof evoked above that cyclicity andnilpotency are complementary notions in S tack , we borrow aresult from an earlier work about G O I and complexity in thecontext of an algebra of Horn clauses.
Lemma II.22 (acyclic sequence [32, lemma 5.3]). If (cid:126)s is anacyclic sequence of stack operations, then we have h (cid:0) p ( (cid:126)s ) (cid:1) ≤ h ( (cid:126)s )(Card( (cid:126)s ) + 1) The following property says that cycles in S tack can beiterated indefinitely, i.e. a stack operation O P τ, σ such that ( O P τ, σ ) (cid:54) = 0 is never nilpotent. Proposition II.23.
If a stack operation f is a cycle, then f n (cid:54) = 0 for all n .Remark II.24 . This does not hold for general flows. For instance, f = x • c (cid:40) d • x is a cycle because f = c • c (cid:40) d • d (cid:54) = 0 (by Remark II.21), but f = ( x • c (cid:40) d • x )( c • c (cid:40) d • d ) = 0 . Theorem II.25 (nilpotency in S tack ). A wiring F ∈ S tack is nilpotent iff it is acyclic.Proof (cid:73) Suppose F is not nilpotent, so that there is at leastone stack operation in F n for any n , and let S be thenumber of different function symbols appearing in F . Set k := ( S h ( F )(Card( F )+1) + S h ( F )(Card( F )+1) − + · · · + 1) ,i.e. the total number of different flows of height at most h ( F )(Card( F ) + 1) using the symbols appearing in F . Note that the cardinality of (cid:126)s is not necessarily equal to the length of (cid:126)s .For instance, if (cid:126)s = f , f , f with f (cid:54) = f then Card( (cid:126)s ) = 2 . Let f (cid:54) = 0 be an element of F k +1 . It is the product p ( (cid:126)s ) ofa sequence (cid:126)s = f , . . . , f k +1 of stack operations that belongto F . We show by contradiction that this sequence must becyclic, so let us suppose it is not. By Lemma II.22, we knowthat for any i > , setting (cid:126)s i := f , . . . , f i we have h (cid:0) p ( (cid:126)s i ) (cid:1) ≤ h ( (cid:126)s i )(Card( (cid:126)s i ) + 1) ≤ h ( F )(Card( F ) + 1) Therefore, for any i > the flow p ( (cid:126)s i ) is of height at most h ( F )(Card( F ) + 1) and uses only symbols appearing in F ,i.e. it wanders in a set of cardinal k , so there must be ≤ i < j ≤ k + 1 such that p ( (cid:126)s i ) = p ( (cid:126)s j ) .Now, setting (cid:126)s i +1 ,j := f i +1 , . . . , f j , we have that p ( (cid:126)s i ) p ( (cid:126)s i +1 ,j ) = p ( (cid:126)s j ) = p ( (cid:126)s i ) hence p ( (cid:126)s i ) p ( (cid:126)s i +1 ,j ) = p ( (cid:126)s i ) (cid:54) = 0 and thus p ( (cid:126)s i +1 ,j ) (cid:54) = 0 i.e. p ( (cid:126)s i +1 ,j ) is a cycle.As p ( (cid:126)s i +1 ,j ) ∈ F j − i we can conclude that F is cyclic.The converse is an immediate consequence of Proposi-tion II.23. (cid:74) Example
II.26 . Consider the wiring F := f ( x ) (cid:40) f ( x )+ f ( f ( x )) (cid:40) f ( f ( x ))+ f ( f ( f ( x ))) (cid:40) f ( f ( f ( x )))+ f ( f ( f ( x ))) (cid:40) f ( f ( f ( x ))) which implements a sort of counter from to in binarynotation that resets to when it reaches (we see the sequence f x f y f z as the integer x +2 y +4 z ). It is clear with this intuitionin mind that this wiring is cyclic. Indeed, an easy computationshows that f ( f ( f ( x ))) (cid:40) f ( f ( f ( x ))) ∈ F .If we lift this example to the case of a counter from to n − that resets to when it reaches n , we obtain anexample of a wiring F of cardinal n and height n − suchthat F n contains a cycle, but F n − does not. This showsthat the number of iterations needed to find a cycle may beexponential in the height and the cardinal of F , which rulesout a polynomial time decision procedure for the nilpotencyproblem that would simply compute the iterations of F untilit finds a cycle in it.Finally, let us define a new class of observations, based onthe S tack semiring. Definition II.27. A balanced observation with stack is anelement of O b + s := O [ S tack • R b ] . III. P
USHDOWN A UTOMATA AND P TIME C OMPLETENESS
A. Characterization of P TIME by Pushdown Automata
The class of deterministic polynomial time computablepredicates P
TIME is the most studied complexity class, mainlybecause it supposedly contains all “tractable” problems.Extending our approach to this class was a long-standinggoal, whose completeness part is attained thanks to the con-nection with pushdown automata. In this subsection, we recalltheir definition, the P
TIME characterization theorem we willrely on and the memoization technique. ) Definition and classical results:
Automata form a verybasic model of computation that can be extended in differentways. For instance, allowing multiple heads that can movein two directions on the input tape, one gets a model ofcomputation equivalent to read-only Turing machines.Among possible extensions, our interest will focus on theaddition of a “pushdown stack” (together with multiple heads),which we referred to as “pushdown automata” until now. Wewill see that this leads to a characterization of P
TIME .Let us give below the most general definition, for the non-deterministic case.
Definition III.1 ( + S ). For k (cid:62) , a -way k -headfinite automaton with pushdown stack ( + S(k) ) is a tuple M = { S , i , A, B, (cid:66) , (cid:67) , (cid:26) , σ } where: ◦ S is the finite set of states , with i ∈ S the initial state ; ◦ A is the input alphabet , B the stack alphabet ; ◦ (cid:66) and (cid:67) are the left and right endmarkers , (cid:66) , (cid:67) / ∈ A ; ◦ (cid:26) is the bottom symbol of the stack , (cid:26) / ∈ B ; ◦ σ is the transition relation , i.e. a subset of the product ( S × ( A (cid:46)(cid:47) } ) k × B (cid:26) ) × ( S ×{− , , +1 } k ×{ pop , push ( b ) } ) where A (cid:46)(cid:47) (resp. B (cid:26) ) denotes A ∪{ (cid:66) , (cid:67) } (resp. B ∪{ (cid:26) } ).The instruction − corresponds to moving the head onecell to the left, corresponds to keeping the head on thecurrent cell and +1 corresponds to moving it one cell tothe right. Regarding the pushdown stack, the instruction pop means “erase the top symbol”, while, for all b ∈ B , push ( b ) means “write b on top of the stack”. The automaton rejects the input if it loops, otherwise it accepts .This condition is equivalent to the standard way of definingacceptance and rejection by “reaching a special state” [33,Theorem 2, p. 125]. Modulo another standard transformation,we restrict the transition relation so that at most one headmoves at each transition.Without pushdown stacks, -way k -head finite automatacharacterize L OGSPACE and NL
OGSPACE , depending on theautomata being deterministic or not.This result, used in our previous work [28], [24], was firststated informally by Juris Hartmanis [34, pp. 338–339] andis often [35, p. 13], [34, pp. 338–339], attributed to AlanCobham. However, a detailed proof can be found in a classicalhandbook [36, pp. 223–225]. The addition of a pushdown stackimproves the expressivity of the machine model, as stated inthe following theorem.
Theorem III.2. + S characterize P TIME . Without reproving this classical result of complexity theory,we review the main ideas that support it.
Simulating a polynomial-time Turing machine with a + S amounts to designing an equivalent Turing machinewhose movements of heads follow a regular pattern. Thatpermits to seamlessly simulate their contents with a pushdownstack. A complete proof [35, pp. 9–11] as well as a precise algorithm [36, pp. 238–240] can be found in the literature. Simulating a + S with a polynomial-time Turingmachine cannot amount to simply simulate step-by-step theautomaton with the Turing machine. The reason is that forany automaton, one can design an automaton that recognizesthe same language but runs exponentially slower [37, p. 197].That the automaton can accept its input after an exponentialcomputation time is similar with the situation of the counterin Example II.26.The technique invented by Alfred V. Aho et al. [37] andmade popular by Stephen A. Cook consists in building a“memoization table” that allows the Turing machine to cre-ate shortcuts in the simulation of the automaton, decreasingdrastically its computation time. In some cases, an automatonwith an exponentially long run can even be simulated in lineartime [29].We give more details on this technique in the next subsection,as its adaptation to our context will be a key ingredient in thesoundness proof in Sect. IV.
2) The memoization technique:
Although the name comesfrom machine-learning [38], this technique is usually attributedto S. A. Cook and has provided fundamental as well as practicalresults. In the specific case of automata with stack, it can becondensed in the following remark: if at a given time you arein state q with b on top of a stack of height h (cid:62) , and if youend up later on in the state q (cid:48) with some symbol b (cid:48) on top ofa stack of height h , without having popped a symbol at heightinferior to h , and if you are about to pop this symbol, thenyou can save this progression ( q , b ) → ( q (cid:48) , b (cid:48) ) . If later on youfind yourself in the same state q , with b on top of your stackand with the heads in the same positions, you can directlyskip to the saved progression, as there is no need to performthis part of the computation again. This “partial information”,the description of your automaton without the contents of thestack, apart from its top symbol, is sometimes called “surfaceconfiguration” or “partial identifier”.The memoization technique consists in building and using thetransitive closure of the relation between surface configuration.Differently expressed, memoization is a “ clever evaluationstrategy , applicable whenever the results of certain computa-tions are needed more than once” [39, p. 348]. One looking forsubtle refinements could look for a technique of memoizationcomputed independently from the input, allowing to “compile”a stack program into equivalent online memoizing program [40]that runs exponentially faster. A nice explanation in the caseof single head automata can be found in a recent and shortarticle by R. Glück [41].We will be adapting this idea to our context in Sect. IV-A,which will amount to a form of exponentiation by squaring . B. Encoding + S as Observations: P TIME
Completeness
The encoding proposed below is similar to the previouslydeveloped [28, Sect. 4.1] encoding of -way k -head finite au-tomata (without pushdown stack) by flows. The only differences the addition of a “plug-in” that allows for a representationof stacks in observations.Remember that acceptance by observations is phrased interms of nilpotency of the product O ¯ W p of the observation andthe representation of the input (Definition II.13). Hence the com-putation in this model is defined as an iteration: one computesby considering the sequence O ¯ W p , ( O ¯ W p ) , ( O ¯ W p ) , . . . andthe computation either ends at some point (i.e. accepts) — thatis ( O ¯ W p ) n = 0 for some integer n — or loops (i.e. rejects).One can think of this iteration as representing a dialogue, or agame, between the observation and its input.We turn now to the proof of P TIME -completeness for theset of balanced observations with stacks.
Theorem III.3. If L ∈ P TIME , then there exists a balancedobservation with stack O ∈ O b + s such that L = L ( O ) .Proof (cid:73) The proof relies on encoding a + S(k) M thatrecognizes L — whose existence is ensured by Theorem III.2 —as an observation of O b + s . Taking A = Σ the input alphabet, k + 1 the number of heads of the automaton, we will encodethe transition relation of M as a balanced observation withstack. More precisely, the automaton will be represented asan element O M of O b + s = O [ S tack • R b ] which can bewritten as a sum of flows of the form c (cid:48) • d (cid:48) • σ ( x ) • q (cid:48) • AUX k ( y (cid:48) , . . . , y (cid:48) k ) • HEAD ( z (cid:48) ) (cid:40) c • d • s ( x ) • q • AUX k ( y , . . . , y k ) • HEAD ( z ) with ◦ c , c (cid:48) ∈ Σ ∪ { (cid:63) } , ◦ d , d (cid:48) ∈ { l , r } , ◦ σ a finite sequence of unary function symbols, ◦ s a unary function symbol, ◦ q , q (cid:48) two constant symbols, ◦ AUX k , HEAD functions symbols of respective arity k and .The intuition behind the encoding is that a configuration of a + S(k + 1) processing an input can be seen as a closedterm c • d • τ ( (cid:26) ) • q • AUX k ( p i , . . . , p i k ) • HEAD ( p j ) where the p i are position constants representing the positionsof the main pointer ( HEAD ( p j ) ) and of the auxiliary pointers ( AUX k ( p i , . . . , p i k ) ); the symbol q represents the state theautomaton is in; τ ( (cid:26) ) represents the current stack; the symbol d represents the direction of the next move of the main pointer;the symbol c represents the symbol currently read by the mainpointer.When a configuration matches the right side of the flow, thetransition is followed, leading to an updated configuration.More precisely, we will be encoding M as an observation O M , and observe the iterations of O M ¯ W p , its product with aword representation. Let us explain how the basic operationsof M are encoded: Moving the pointers.
Looking back at the definition of theencoding of words (Definition II.10), we see that we can have a new reading of what the representation of a word does: it movesthe main pointer in the required direction. From that perspective,the position holding the symbol (cid:63) in Definition II.10 allowsto simulate the behavior of the endmarkers (cid:66) and (cid:67) .On the other hand, the observation is not able to manipulatethe position of pointers directly (remember observations areforbidden to use the position constants) but can change thedirection symbol d , rearrange pointers (hence changing whichone is the main pointer) and modify its state and the symbol c accordingly. For instance, a flow of the form · · · • AUX k ( x, . . . , y k ) • HEAD ( y ) (cid:40) · · · • AUX k ( y , . . . , y k ) • HEAD ( x ) encodes the instruction “swap the main pointer and the firstauxiliary pointer”.Note however that our model has no built-in way to remem-ber the values of the auxiliary pointers — it remembers onlytheir positions as arguments of AUX k ( · · · ) —, but this can beimplemented easily using additional states.One can see that it is the interaction between the observation O M and the word representation ¯ W p that simulates thebehavior of the automaton, and not the observation on itsown manipulating some passive data. Handling the stack.
Suppose we have a unary function symbol b ( · ) for each symbol b of the stack alphabet B (cid:26) .A transition that reads b and pops it is simply written as · · · • x • · · · (cid:40) · · · • b ( x ) • · · · A transition that reads b and pushes a symbol c is written · · · • c ( b ( x )) • · · · (cid:40) · · · • b ( x ) • · · · Changing the state.
We suppose that we have a constant q for each state q of M . Then, updating the state amountsto picking the right q and q (cid:48) in the flow representing thetransition. Acceptance and rejection.
The encoding of acceptance andrejection is slightly more delicate, as detailed in a previousarticle [23, 6.2.3.].The basic idea is that acceptance in our model is defined asnilpotency, that is to say: the absence of loops. If no transitionin the automaton can be fired, then no flow in our encodingcan be unified, and the computation ends.Conversely, a loop in the automaton will refrain the wiringfrom being nilpotent. The point we need to be careful aboutis the encoding of loops: those should be represented as are-initialization of the computation, as discussed in detailsin earlier work [23]. The reason for this is that anotherencoding may interfere with the representation of acceptationas termination: the existence of a loop in the observation O M representing the automaton M , even one that is not used in thecomputation with the input W , prevents the wiring O M ¯ W p from being nilpotent.Indeed, the “loop” in Definition III.1 of + S is to beread as “perform forever the same computation”. (cid:74) otice that the encoding of pushdown automata as observa-tions with stacks produces only specific observations, namelythose that are sums of flows of a particular form (shown atthe beginning of the preceding proof). This is due to the factthat one encodes the transitions directly, so that each flowcorresponds to a transition step.In particular, as the transition relation of automata dependsonly on the top of the stack, the body (i.e. the right-hand part)of the flows must be of the form · · · • b ( x ) • · · · . However,a general observation with stack is not constrained in thisway, and allows a more compact representation of programswhere one can read, pop and push several symbols of the stacksimultaneously.Nevertheless, this does not increase the expressive power: thenext section is devoted to prove that the language recognizedby any observation with stack lies in P TIME .IV. N
ILPOTENCY IN S tack AND P TIME SOUNDNESS
A. The Saturation Technique
We now introduce the saturation technique, which allows todecide nilpotency of S tack elements in polynomial time. Thistechnique relies on the fact that under certain conditions, theheight of flows does not grow when computing their product.It adapts memoization to our setting: we repeatedly extendthe wiring by adding pairwise products of flows, allowing formore and more “transitions” at each step. Notation IV.1.
Let τ and σ be sequences of unary functionsymbols.If h (cid:0) τ ( x ) (cid:1) ≥ h (cid:0) σ ( x ) (cid:1) we say that O P τ, σ is increasing .If h (cid:0) τ ( x ) (cid:1) ≤ h (cid:0) σ ( x ) (cid:1) we say that O P τ, σ is decreasing .A wiring in S tack is increasing (resp. decreasing ) if itcontains only increasing (resp. decreasing ) stack operations. Lemma IV.2 (stability of height).
Let f = O P τ, σ and g = O P ρ, χ be stack operations. If f is decreasing and g is increasing, we have h ( f g ) ≤ max { h ( f ) , h ( g ) } .Proof (cid:73) If f g = 0 , the property holds because h (0) = 0 .Otherwise, we have either σ = ρµ or σµ = ρ .Suppose we are in the first case (the second being symmetric).Then we have f g = O P τ, χµ and h ( σ ) = h ( ρµ ) .As g is increasing, h ( χ ) ≤ h ( ρ ) and therefore we have h ( χµ ) ≤ h ( ρµ ) = h ( σ ) ≤ h ( f ) ≤ max { h ( f ) , h ( g ) } . (cid:74) With this lemma in mind, we can define a shortcut operationthat augments an element of S tack by adding new flows whilekeeping the maximal height unchanged. Iterating this operation,we obtain a saturated version of the initial wiring, containingshortcuts, shortcuts of shortcuts, etc.We are designing in fact an exponentiation by squaring procedure for elements of S tack , the algebraic reading ofmemoization. Definition IV.3 (saturation). If F ∈ S tack we define itsincreasing F ↑ := { f ∈ F | f is increasing } and decreasing F ↓ := { f ∈ F | f is decreasing } subsets.We set the shortcut operation short ( F ) := F + F ↓ F ↑ andits least fixpoint, which we call the saturation of F : satur ( F ) := (cid:88) n ∈ N short n ( F ) where short n denotes the n th iteration of short . Now, as we are only manipulating flows with a limited height,the iteration of the shortcut operation is bound to stabilize atsome point.
Proposition IV.4 (stability of saturation).
Let F ∈ S tack be a wiring and S the number of distinct function symbolsappearing in F .For any n , we have h (cid:0) short n ( F ) (cid:1) = h ( F ) .Moreover if n ≥ ( S h ( F ) + S h ( F ) − + · · · + 1) then short n ( F ) = satur ( F ) .Proof (cid:73) By Lemma IV.2 we have h ( F ↓ F ↑ ) ≤ max { h ( F ↓ ) , h ( F ↑ ) } = h ( F ) Therefore h (cid:0) short ( F ) (cid:1) = h ( F ) , and we get the first prop-erty by induction.For any n , the elements of short n ( F ) are stack operationsof height at most h ( F ) built from the function symbolsappearing in F , therefore short n ( F ) is a subset of aset of cardinality k := ( S h ( F ) + S h ( F ) − + · · · + 1) . As G ⊆ short ( G ) for all G , the iteration of short ( · ) on F must be stable after at most k steps. (cid:74) In the following, we let FP
TIME be the class of functionscomputable by Turing machine in polynomial time. Here weneed to specify how the size of a wiring is measured.
Definition IV.5 (size).
The size | F | of a wiring F is definedas the total number of function symbol occurrences in it. By computing the fixpoint of short ( · ) we have first a FP TIME procedure computing the saturation.
Corollary IV.6 (computing the saturation).
Given any inte-ger h , there is procedure S ATUR h ( · ) ∈ FP TIME that, given anelement F ∈ S tack such that h ( F ) ≤ h as an input, outputs satur ( F ) . Moreover, we can obtain a further reduction of the nilpotencyproblem in S tack related to saturation. Lemma IV.7 (rotation).
Let f and g be stack operations.Then f g is a cycle iff gf is a cycle.Proof (cid:73) If f g is a cycle, then ( f g ) n (cid:54) = 0 for any n byProposition II.23. In particular ( f g ) (cid:54) = 0 and as we have ( f g ) = f ( gf )( gf ) g we get ( gf ) (cid:54) = 0 , i.e. gf is a cycle. (cid:74) Theorem IV.8 (cyclicity and saturation).
An element F of S tack is cyclic (Definition II.20) iff either satur ( F ) ↑ or satur ( F ) ↓ is.roof (cid:73) The cyclicity of satur ( F ) ↑ or satur ( F ) ↓ obvi-ously implies that of F because short ( F ) ⊆ F + F , hence satur ( F ) ⊆ (cid:80) n ∈ N F n .Conversely, suppose F is cyclic and let (cid:126)s = f , . . . , f n ∈ F be such that the product p ( (cid:126)s ) ∈ F n is a cycle.We are going to produce from (cid:126)s a sequence of elements of satur ( F ) ↑ or satur ( F ) ↓ whose product is a cycle. For thiswe apply to the sequence the following rewriting procedure:1) If there are f i and f i +1 such that f i is decreasing and f i +1 is increasing, then rewrite (cid:126)s as f , . . . , f i f i +1 , . . . , f n .2) If step 1 does not apply and (cid:126)s = (cid:126)s (cid:126)s ( (cid:126)s and (cid:126)s both non-empty) with all elements of (cid:126)s increasing and all elementsof (cid:126)s decreasing, then rewrite (cid:126)s as (cid:126)s (cid:126)s .This rewriting procedure preserves the following invariants: ◦ All elements of the sequence are in satur ( F ) : step 2does not affect the elements of the sequence (only theirorder) and step 1 replaces the flows f i ∈ satur ( F ) ↓ and f i +1 ∈ satur ( F ) ↑ by f i f i +1 ∈ satur ( F ) . ◦ The product p ( (cid:126)s ) of the sequence is a cycle: step 1 doesnot alter p ( (cid:126)s ) and step 2 does not alter the fact that p ( (cid:126)s ) is a cycle by Lemma IV.7.The rewriting terminates as step 1 strictly reduces the lengthof the sequence and step 2 can never be applied twice in arow (it can be applied only when step 1 is impossible andits application makes step 1 possible). Let g , . . . , g n be theresulting sequence, as it cannot be reduced, the g i must beeither all increasing or all decreasing.Therefore, by the invariants above g , . . . , g n is either asequence of elements of satur ( F ) ↓ or satur ( F ) ↑ suchthat the product g · · · g n is a cycle. (cid:74) Finally, we need a way to decide cyclicity of elements of S tack that are either increasing or decreasing. Lemma IV.9.
Given any integer h , there is a procedure I NCR h ( · ) ∈ P TIME that, given an element F ∈ S tack whichis either increasing or decreasing and satisfying h ( F ) ≤ h asan input, accepts iff F is nilpotent.Proof (cid:73) Let S be a set of function symbols and h an integer.We define the truncation wiring associated to S and hT h,S := (cid:88) τ = f , ... , f h ∈ S τ ( (cid:63) ) (cid:40) τ ( x ) and set for the rest of the proof T := T h ( F ) ,E where E is theset of function symbols occurring in F .As it contains only flows of the form τ ( (cid:63) ) (cid:40) σ ( x ) , i.e. withonly one variable, T F is balanced and can be computed inpolynomial time since T is of polynomial size in | F | .If F is increasing, an easy computation shows that we have ( T F ) n = T F n . From this, we deduce that F is nilpotentiff T F is. If F = (cid:80) i σ i ( x ) (cid:40) τ i ( x ) is decreasing, we canconsider F † := (cid:80) i τ i ( x ) (cid:40) σ i ( x ) which is increasing andnilpotent iff F is. Then, as we know [28, p. 54], [21, Theorem IV.12] thenilpotency problem for balanced wirings to be in CO -NL OG - SPACE ⊆ P TIME , we are done. (cid:74)
Theorem IV.10 (nilpotency is in P
TIME ). Given any integer h , there is a procedure N ILP h ( · ) ∈ P TIME that, given a F ∈ S tack such that h ( F ) ≤ h as an input, accepts iff F isnilpotent.Proof (cid:73) Simply take N
ILP h ( · ) = I NCR h ( S ATUR h ( · )) . Bycompositionality of P TIME and FP
TIME algorithms, thisprocedure is in P
TIME . (cid:74) Remark
IV.11 . All the results we gave in this section areparametrized by a height limit h , but this is only to ease thepresentation. Indeed, it is possible to transform any elementof S tack with an unspecified height into another elementof comparable size but of height at most , preserving itsnilpotency.More precisely: consider a flow l = σ ( x ) (cid:40) τ ( x ) , with σ = f , . . . , f m and τ = g , . . . , g n . Let us introduce newfunction symbols l pop i ( · ) and l push j ( · ) for ≤ i ≤ m and ≤ j ≤ n . We can rewrite l as the sum g ( x ) (cid:40) l push ( x ) + l push ( g ( x )) (cid:40) l push ( x ) + · · ·· · · + l push n ( x ) (cid:40) l pop ( x ) + · · ·· · · + l pop m − ( x ) (cid:40) l pop m ( f m − ( x )) + l pop m ( x ) (cid:40) f m ( x ) with the idea that instead of popping and pushing severalsymbols at the same time, we do this step by step: we push/poponly one symbol and then leave a marker (either l pop i ( · ) or l push j ( · ) ) for the next operation to be performed. Moreover,we see that this flow of size (Definition IV.5) | l | = m + n istransformed in a wiring containing three flows of size (thecentral and two extremal ones) and ( m −
1) + ( n − flowsof size ; hence the sum has size | l | .When dealing with a wiring W , we can do the same byconsidering one family of l pop i ( · ) and l push j ( · ) symbols foreach flow l of W . It is not hard to see that the resulting wiring W flat has the same behavior as the original one in terms ofnilpotency. It is also clear that the height of W flat is indeed .Finally, if we started with a wiring W of size N , which isthe sum of the sizes of the flows in it, we get in the end that | W flat | = 3 | W | using the one-flow case above.This suggests by the way that the bound in Proposition IV.4is probably too rough, but a way to sharpen it still needs tobe found. B. P TIME
Soundness
We will now use the saturation technique to prove that thelanguage recognized by an observation with stack belongsto the class P
TIME . The important point in the proof is that,given an observation O and a representation ¯ W p of a word W , one can produce in polynomial time an element of S tack whose nilpotency is equivalent to the nilpotency of O ¯ W p . Onecan then decide the nilpotency of this element thanks to theprocedure described in the previous section. roposition IV.12. Let O ∈ O b + s be an observation withstack. There is a procedure R ED O ( · ) ∈ FP TIME that, givena word W as an input, outputs a wiring F ∈ S tack with h ( F ) ≤ h ( O ) such that F is nilpotent iff O ¯ W p is for anychoice of (cid:126) p .Proof (sketch [21, proposition IV.21]) (cid:73) The idea is that theproduct O ¯ W p can be seen as an element of R b • S tack . Then,its balanced part can be replaced in polynomial time by closedterms without altering the nilpotency in a way similar to whatis done to treat the nilpotency of elements of R b [28].We are left with a flow (cid:80) i t i • σ i ( x ) (cid:40) u i • τ i ( x ) such thatt i (cid:40) u i is balanced and σ i ( x ) (cid:40) τ i ( x ) is a stack operation,and we can associate to each closed t i , u i , unary functionsymbols t i ( · ) , u i ( · ) , and rewrite our flow as (cid:80) i t i ( σ i ( x )) (cid:40) u i ( τ i ( x )) ∈ S tack . (cid:74) Theorem IV.13 (soundness). If O ∈ O b + s is an observationwith stack, then L ( O ) ∈ P TIME .Proof (cid:73)
We have, using the compositionality of P
TIME andFP
TIME again, that N
ILP h ( O ) ( R ED O ( · )) is a decision proce-dure in P TIME for L ( O ) . (cid:74) V. U
NARY L OGIC P ROGRAMMING
In previous sections, we showed how the S tack semiringcaptures polynomial time computation. As we already men-tioned, the elements of this semiring correspond to a specificclass of logic programs.We cover in here the consequences in terms of logicprogramming of the results and techniques introduced so far.The basic definitions and a list of previously known results— that highlight the novelty of our result — regarding logicprogramming can be found in an extensive survey [26].As an illustration, we show in Sect. V-B how the classicalboolean circuit value problem (CVP) [42] can be encoded asa unary logic program, thus providing an alternative proof ofits inclusion in P TIME . A. Unary Queries
Definition V.1 (data, goal, query). A unary query is a triple Q = ( D, P, G ) , where: ◦ D is a set of closed unary terms (a unary data ), ◦ P is a an element of S tack (a unary program ), ◦ G is a closed unary term (a unary goal ).We say that the query Q succeeds if G (cid:97) can be derivedcombining d (cid:97) for d ∈ D and the elements of P by theresolution rule exposed in Sect. II-A, otherwise we say thequery fails .The size | Q | of the query is defined as the total number ofoccurrences of symbols in it. To apply the saturation technique directly, we need to representall the elements of the unary query (data, program, goal) aselements of S tack . This requires an encoding. Definition V.2 (encoding unary queries).
We suppose that forany constant symbol c , we have a unary function symbol c ( · ) .We also need two unary functions, START ( · ) and ACCEPT ( · ) .To any unary data D we associate an element of S tack : [ D ] := { τ ( c ( x )) (cid:40) START ( x ) | τ ( c ) ∈ D } and to any unary goal G = τ ( c ) we associate (cid:104) G (cid:105) := ACCEPT ( x ) (cid:40) τ ( c ( x )) Remark
V.3 . The program part P of the query needs not tobe encoded as it is already an element of S tack .Once a query is encoded, we can tell if it is successful ornot using the language of the resolution semiring. Lemma V.4 (success).
A unary query Q = ( D, P, G ) suc-ceeds if and only if ACCEPT ( x ) (cid:40) START ( x ) ∈ (cid:104) G (cid:105) P n [ D ] for some n Then, we can show that the saturation technique applies tothe problem of deciding whether a unary query accepts. Theproof uses the saturation technique (Sect. IV-A) to rewrite asequence of flows, adding to them “pre-computed” rewritingrules.
Lemma V.5 (saturation of unary queries).
A unary query Q = ( D, P, G ) succeeds if and only if ACCEPT ( x ) (cid:40) START ( x ) ∈ satur (cid:0) [ D ] + P + (cid:104) G (cid:105) (cid:1) Theorem V.6 (P
TIME -completeness).
The UQ UERY problem(given a unary query, is it successful?) is P TIME -complete.Proof (cid:73)
The lemma above, combined with Corollary IV.6,ensures that the problem lies indeed in the class P
TIME , modulo the considerations on the height of Remark IV.11.The hardness part follows from a variation on the encod-ing presented in Sect. III-B and the reduction derived fromProposition IV.12. (cid:74) Remark
V.7 . We presented the result in a restricted form, tostay in line with the previous sections. However, it should beclear to the reader that this construction would not be impactedif we allowed ◦ non-closed goals and data; ◦ that in t (cid:40) u the variables of t does not appear in u; ◦ constants in the program part of the query.A harder question is whether everything scales up to logicprograms of the form H (cid:97) B , . . . , B n , with more than oneformula on the right of (cid:97) . Indeed we would no longer haveobvious notions of increasing or decreasing (Notation IV.1)clause anymore, and these are crucial to the saturation tech-nique. It is already known [26, pp. 386–387] that in the caseof propositional (i.e. with no variables) logic programming,allowing more than one B i makes the combined complexity(see Remark V.8 below) switch from L OGSPACE to P
TIME :ne can expect by analogy a higher complexity than P
TIME inour unary case, but nothing has been proven yet.
Remark
V.8 . In terms of complexity of logic programs, we areconsidering the combined complexity [26, p. 380]: every partof the query Q = ( D, P, G ) is variable. If for instance wefixed P and G (thus considering data complexity ), we wouldhave a problem that is still in P TIME , but it is unclear to usif it would be complete. Indeed, the encoding of Sect. III-Brelies on a representation of inputs as plain programs, and onthe fact that the evaluation process is a matter of interactionbetween programs rather than mere data processing.
B. Circuit Value Problem
To illustrate our point in the introduction about rephrasing aproblem with unary symbols to tell whether it lies in P
TIME ,we present an encoding of the classical P
TIME -complete circuitvalue problem (CVP) [26] as a unary query.An instance of CVP is a boolean circuit composed of and , or , not , and gates and is accepted if the circuit computesthe value at its output gate.More formally, we can see an instance of CVP as ( G, o ) with G an acyclic directed hypergraph with a distinguishedoutput vertex o built with edges among a, b (cid:66) and c a, b (cid:66) or c a (cid:66) not b (cid:66) a (cid:66) a such that any vertex is the target of exactly one edge.First, we associate to each vertex v of the graph a pair v ( · ) , v ( · ) , of unary function symbols. Then to each edge e weassociate a flow [ e ] as follows: [ a, b (cid:66) and c ] := a ( b ( x )) (cid:40) c ( x )+ a ( x ) (cid:40) c ( x ) + b ( x ) (cid:40) c ( x )[ a, b (cid:66) or c ] := a ( x ) (cid:40) c ( x ) + b ( x ) (cid:40) c ( x )+ a ( b ( x )) (cid:40) c ( x )[ a (cid:66) not b ] := a ( x ) (cid:40) b ( x ) + a ( x ) (cid:40) b ( x )[ (cid:66) a ] := x (cid:40) a ( x )[ (cid:66) a ] := x (cid:40) a ( x ) The intuition behind this encoding is that we are handling astack of needed values, v ( · ) (resp. v ( · ) ) meaning “we needthe value (resp. ) at v ”. The flows associated to gates arethen meant to handle this stack, popping and pushing neededvalues.Then, to a circuit ( G, o ) we associate the unary query (cid:0) o ( (cid:63) ) , (cid:88) e vertex of G [ e ] , (cid:63) (cid:1) This query succeeds iff the circuit computes the value atthe gate o : the data o ( (cid:63) ) initiates a stack with the intuitive A directed hypergraph is given as a set of vertices V and a set of edges E ⊆ P ( V ) × P ( V ) . We say that ( S, T ) ∈ E is an edge from S to T .We consider labeled edges and write x , . . . , x n (cid:66) k y , . . . , y m an edgelabeled by k from { x , . . . , x n } to { y , . . . , y m } . meaning “we need the value at o ”, the encodings of edgespropagate the needed values to the point where they can be“popped” if the correct (cid:66) x or (cid:66) x is available. The querysucceeds if we can derive the goal (cid:63) — i.e. the empty stack —with the intuitive meaning “all the needed values have beenprovided”.Note the parallel nature of this way of solving the problem:when we compute the saturation of (the encoding of) the query,we unify the terms that match at any point of the circuit withouthaving to worry in which order we perform the operations.For instance, the two elements a ( x ) (cid:40) o ( (cid:63) ) and b ( x ) (cid:40) o ( (cid:63) ) of [ a, b (cid:66) or o ( (cid:63) )] would be unified with o ( (cid:63) ) (cid:40) (cid:63) ,providing two flows a ( x ) (cid:40) (cid:63) and b ( x ) (cid:40) (cid:63) . Those flowswould be, at the next execution step, tested for unificationagainst all (provided we respect the increasing/decreasingdiscipline at work in Definition IV.3) the other flows and so on,without having to wait to know whether a or b will hold thevalue . A partial evaluation happens at any point of the graph,independently of the input: [ a, b (cid:66) and c ] and [ c (cid:66) not d ] willgive after one step of evaluation the flows a ( b ( x )) (cid:40) d ( x ) , a ( x ) (cid:40) d ( x ) and b ( x ) (cid:40) d ( x ) . The execution does not haveto sequentially wait for the propagation of the needed values.Finally, let us say a word about the stabilization time of satur ( · ) (Definition IV.3) in this case. Given a circuit with S gates, we are dealing with flows of height at most , writtenwith at most S different symbols. In view of Proposition IV.4we have that the iterations of short ( · ) will stabilize in at most ( S + S + 1) steps. A bound that is rough, due the absenceof optimization and fine-grained analysis of the procedure.VI. P ERSPECTIVES
This article extends modularly on our previous approaches[23], [24], [27], [28] to obtain a characterization of P
TIME ,by adding a sort of “stack plugin” to observations. Thisenhancement was guided by the intuition of a stack addedto an automaton, allowing to move from L
OGSPACE to P
TIME and providing a decisive proof technique: memoization.We saw that to a qualitative constraint on the way memoryis handled by automata corresponds a syntactical restrictionon flows. These flows are evaluated in a setting inspired bythe representation of inputs in the interactive approach to theCurry-Howard correspondence — geometry of interaction —,which makes the complexity parametric in the program and the input. However, despite the evaluation being highly paralleland different from the step-by-step evaluation performed byautomata, a precise simulation of pushdown automata by unarylogic program is given, leading to complexity results.We were able to adapt the mechanism of pre-computationof transitions, known as memoization, in a setting where logicprograms are represented as algebraic objects. This technique— that we called the saturation technique — computes shortcutsin a logic program in order to decide its nilpotency faster.This approach to complexity was earlier based on vonNeumann algebras [22], [23], [24] and now explore unificationtheory [21], [27], [28]: it is emerging as a meeting point foromputer science, logic and mathematics. This raises multiplequestions and perspectives.A number of interrogations come from the relations of thiswork to proof theory. First, we could consider the Churchencoding of other data types — trees for instance — anddefine “orthogonally” set of programs interacting with them,wondering what is their computational nature. In the distance,one may hope for a connection between our approach andongoing work on higher order trees and model checking; allalike, one could study the interaction between observations andone-way integers — briefly discussed in earlier work [28] —or non-deterministic data. Second, a still unanswered questionof interest is to give an account of observations in terms of aproof-system.One could also investigate possible relations with other mod-els of computation, such as the interaction abstract machine [43]that already developed and used — although with a different,much more logical, meaning — the notion of shortcut in theevaluation.Finally, we also aim at representing functional computation,by considering a more general notion of observation that wouldallow for expressing the notion of output.R
EFERENCES[1] P. van Emde Boas, “Machine models and simulation,” in
Handbook ofTheoretical Computer Science. volume A: Algorithms and Complexity ,J. Van Leeuwen, Ed. Elsevier, 1990, pp. 1–66.[2] U. Dal Lago, “A short introduction to implicit computational complexity,”in
ESSLLI , ser. LNCS, N. Bezhanishvili and V. Goranko, Eds., vol. 7388.Springer, 2011, pp. 89–109.[3] S. J. Bellantoni and S. A. Cook, “A new recursion-theoretic characteriza-tion of the polytime functions,”
Comput. Complex. , vol. 2, pp. 97–110,1992.[4] D. Leivant, “Stratified functional programs and computational complexity,”in
POPL , M. S. Van Deusen and B. Lang, Eds. ACM Press, 1993, pp.325–333.[5] P. Neergaard, “A functional language for logarithmic space,” in
APLAS ,ser. LNCS, W.-N. Chin, Ed. Springer, 2004, vol. 3302, pp. 311–326.[6] J.-Y. Girard, “Linear logic,”
Theoret. Comput. Sci. , vol. 50, no. 1, pp.1–101, 1987.[7] ——, “Light linear logic,” in
LCC , ser. LNCS, D. Leivant, Ed. Springer,1995, vol. 960, pp. 145–176.[8] V. Danos and J.-B. Joinet, “Linear logic & elementary time,”
Inf. Comput. ,vol. 183, no. 1, pp. 123–137, 2003.[9] Y. Lafont, “Soft linear logic and polynomial time,”
Theoret. Comput.Sci. , vol. 318, no. 1, pp. 163–180, 2004.[10] P. Baillot and K. Terui, “Light types for polynomial time computation inlambda-calculus,” in
LICS . IEEE Computer Society, 2004, pp. 266–275.[11] U. Dal Lago and U. Schöpp, “Functional programming in sublinearspace,” in
ESOP , ser. LNCS, A. D. Gordon, Ed., vol. 6012. Springer,2010, pp. 205–225.[12] M. Gaboardi, J.-Y. Marion, and S. Ronchi Della Rocca, “An implicitcharacterization of pspace,”
ACM Trans. Comput. Log. , vol. 13, no. 2,pp. 18:1–18:36, 2012.[13] J.-Y. Girard, “Towards a geometry of interaction,” in
Proceedings of theAMS-IMS-SIAM Joint Summer Research Conference held June 14-20,1987 , ser. Categories in Computer Science and Logic, J. W. Gray andA. Šˇcedrov, Eds., vol. 92. AMS, 1989, pp. 69–108.[14] V. Danos, “La logique linéaire appliquée à l’étude de divers processusde normalisation (principalement du λ -calcul),” Ph.D. dissertation,Université Paris VII, 1990.[15] T. Seiller, “Logique dans le facteur hyperfini : géometrie de l’interactionet complexité,” Ph.D. dissertation, Université de la Méditerranée, 2012.[Online]. Available: http://tel.archives-ouvertes.fr/tel-00768403/ [16] ——, “Interaction graphs: Graphings,” Submitted , 2014. [Online].Available: http://arxiv.org/pdf/1405.6331[17] J.-Y. Girard, “Geometry of interaction 1: Interpretation of system F,”
Studies in Logic and the Foundations of Mathematics , vol. 127, pp.221–260, 1989.[18] ——, “Geometry of interaction V: logic in the hyperfinite factor,”
Theoret.Comput. Sci. , vol. 412, no. 20, pp. 1860–1883, Apr. 2011.[19] T. Seiller, “A correspondence between maximal abelian sub-algebrasand linear logic fragments,”
Submitted , 2014. [Online]. Available:http://arxiv.org/pdf/1408.2125[20] J.-Y. Girard, “Geometry of interaction III: accommodating the additives,”in
Advances in Linear Logic , ser. London Math. Soc. Lecture Note Ser.,J.-Y. Girard, Y. Lafont, and L. Regnier, Eds. CUP, Jun. 1995, no. 222,pp. 329–389.[21] M. Bagnol, “On the resolution semiring,” Ph.D. dissertation, Aix-Marseille Université – Institut de Mathématiques de Marseille, 2014.[22] J.-Y. Girard, “Normativity in logic,” in
Epistemology versus Ontology , ser.Logic, Epistemology, and the Unity of Science, P. Dybjer, S. Lindström,E. Palmgren, and G. Sundholm, Eds. Springer, 2012, vol. 27, pp.243–263.[23] C. Aubert and T. Seiller, “Characterizing co-nl by a group action,”
MSCS(FirstView) , pp. 1–33, 12 2014.[24] ——, “Logarithmic space and permutations,”
Inf. Comput. , 2015, toappear.[25] J. A. Robinson, “A machine-oriented logic based on the resolutionprinciple,”
J. ACM , vol. 12, no. 1, pp. 23–41, Jan. 1965.[26] E. Dantsin, T. Eiter, G. Gottlob, and A. Voronkov, “Complexity andexpressive power of logic programming,”
ACM Comput. Surv. , vol. 33,no. 3, pp. 374–425, 2001.[27] C. Aubert and M. Bagnol, “Unification and logarithmic space,” in
RTA-TLCA , ser. LNCS, G. Dowek, Ed., vol. 8650. Springer, 2014, pp.77–92.[28] C. Aubert, M. Bagnol, P. Pistone, and T. Seiller, “Logic programmingand logarithmic space,” in
APLAS , ser. LNCS, J. Garrigue, Ed., vol. 8858.Springer, 2014, pp. 39–57.[29] S. A. Cook, “Linear time simulation of deterministic two-way pushdownautomata,” in
IFIP Congress (1) . North-Holland, 1971, pp. 75–80.[30] C. Dwork, P. C. Kanellakis, and J. C. Mitchell, “On the sequential natureof unification,”
J. Log. Program. , vol. 1, no. 1, pp. 35–50, 1984.[31] F. Baader and T. Nipkow,
Term rewriting and all that.
CUP, 1998.[32] P. Baillot and M. Pedicini, “Elementary complexity and geometry ofinteraction,”
Fund. Inform. , vol. 45, no. 1–2, pp. 1–31, 2001.[33] M. Ladermann and H. Petersen, “Notes on looping deterministic two-waypushdown automata,”
Inf. Process. Lett. , vol. 49, no. 3, pp. 123–127,1994.[34] J. Hartmanis, “On non-determinancy in simple computing devices,”
ActaInform. , vol. 1, no. 4, pp. 336–344, 1972.[35] S. A. Cook, “Characterizations of pushdown machines in terms of time-bounded computers,”
J. ACM , vol. 18, no. 1, pp. 4–18, 1971.[36] K. W. Wagner and G. Wechsung,
Computational Complexity , ser.Mathematics and its Applications. Springer, 1986, vol. 21.[37] A. V. Aho, J. E. Hopcroft, and J. D. Ullman, “Time and tape complexityof pushdown automaton languages,”
Inform. Control , vol. 13, no. 3, pp.186–206, 1968.[38] D. Michie, ““Memo” functions and machine learning,”
Nature , vol. 218,pp. 19–22, Apr. 1968.[39] T. Amtoft and J. L. Träff, “Partial memoization for obtaining linear timebehavior of a 2dpda,”
Theoret. Comput. Sci. , vol. 98, no. 2, pp. 347–356,1992.[40] N. Andersen and N. D. Jones, “Generalizing cook’s transformationto imperative stack programs,” in
Results and Trends in TheoreticalComputer Science , ser. LNCS, J. Karhumäki, H. A. Maurer, andG. Rozenberg, Eds., vol. 812. Springer, 1994, pp. 1–18.[41] R. Glück, “Simulation of two-way pushdown automata revisited,” in
Festschrift for Dave Schmidt , ser. EPTCS, A. Banerjee, O. Danvy, K.-G.Doh, and J. Hatcliff, Eds., vol. 129, 2013, pp. 250–258.[42] R. E. Ladner, “The circuit value problem is log space complete for p,”
ACM SIGACT News , vol. 7, no. 1, pp. 18–20, 1975.[43] V. Danos and L. Regnier, “Reversible, irreversible and optimal lambda-machines,”