and the thesis easily follows. The program @’can be built up as follows: Step 1. Compute P( 1) by Q,with input 1. Time: t at most. Step 2. Compute P(P( 1)) by a’ with input P(1). Time: t at most. Step 3. Compute Pk( 1) and Pk+’ (1). The computation can be carried out by using the recurrence: for k even,
r$* Pk(l) = rk = P(1) rk-1 l
fork odd, fork=&
i 1
Time: at most 2 log2 k + 1 4 2 log2 n + 1 < 2t + 1 by Lemma 1. step 4. Compute pk by l
l
pk = (P(P(l))/Pk(I)) - P(1) (P(P(l))IPk+’ (1))
“*Xjm
4. Applications to concrete problems (a) Counting stringsof lengthn in a regularlanguage Let G be a regular grammar; we associate with G the enumeration system (w, 9 ), where S, E J is the set of words of length n generated by G. Now, it is well known [8] that the enumeration function can be described by a matrix A and vectors anand q such that #S, = nA”r)~ for every n. So, we have the poly nomial:
l
Theorem 2. Let 0 bc a program that evaluates in at most t s?eps. Then there is a proP(Xl, l**9 x,) gram a’ that computes the coefficilent pjr ._.j,,,, for a given m-uple (jr , .... j.&, in at most (3m + 1) t + Sm steps. Proof. Theproof is easily obtained by iterating the procedure followed for the case m = 1. The main steps are: Step 1. Compute P(&, .... jzn), where ji, = P(I ¶ l*-, 1) and
n
n
P(x) = c nAkqTxk = 7~c k=O
=
A similartheorem can be stated for a multivariate polynomial Pj,,..j,Xjl
Note that, for m = 1, we have the result of Theorem 1 as a particular case.
l
Time: 4 operations. Totaltime: 4t t 5 operations at most.
P(x 1, l**,X,)=x
13 June 1981
INFORMATION PROCESSING LETTERS
Volume 12, number 3
k=O
(Ax)~Q~
r((Ax)*+’ - I) (Ax - I)-’ VT,
where I is the identity matrix. A program that evaluates P(x) in time t = O(log n) can be easily given. So, by Theorem 1, there is a program which corib3utes##Sk(k fmed, 0
%c+1 =
P(kr
, .... &, 1, .,., 1).
P(x) =
PA = ml, Pjl
ljkjk+l
such that, if we set: .
Q,(x) = P”(x) =
l==9%I),
= @jl
...jk I&!>
-
@jl
. ..jk&+‘)
Time: 4m operations. Totaltime: 3mt + t t 5m at most. 144
c pkXk,
k=O
Time: mt + t at most. Step 2. Compute @ and g*s for 1< s < m. Time: 2m t + m at most. Step 3. Compute pj 1 . . . jm as fOllOWSI
l
&
;$ GkXk =
and l
h Rh(X,
y) = c Qk(X) k=O *
yk = c i,k
rhik Xiyk,
Volume 12, number 3 we
have:
%
=i
l
But Rh(x,
INFORMATION PROCESSING LETTERS
qn,n-1 = i ’ rh,n-1,n
for
tation of a permanent, we can conclude that every #P problem can be solved in polynomial time on a W with the usual arithmetic operations. A careful analysis, carried out in [6], gives the :;harper bound of a polynomial number of sum/product operations and two division operations for solving any #P problem. Furthermore, in [4] it is proved the stronger result that every P-SPACEproblem can be solved in polynomial time on a RAM with arithmetic operations.
h> n.
y) can be u iitten in the form: h
k =
Rh(x> Y) = c pk(x)y k=O
(,@(x))h+’ - 1 ypo 3 - I
and a program which evaluates Rn(x, y) in time 2 s log n can be easily written. But #Sn is the coefficient of the term xn-rvn in R,(X, y), divided by n; thus, by Theorem 2, wk can compute #/Sn in time 14s log n t 10, that is, with respect to n, O(log n). (c) Computing the permanent of a matrix. Let A be an n X n matrix, and let us consider the polynomial l
13June1981
l
References
l
n P(X*,
*-,
l
Xn)
=
;
n
(2 aikxk)*
P(x) can be evaluated in time t = 2n2 + n, the coefficient pkr k2+,, of the term x1kl x2k2 . . . Xnkn can be computed, by Theorem 2, in at most (3n + 1) (2n2 + n) + Sn =,6n3 (for n + +-) operations. Very interesting is the case kr = k2 = **= k, = 1; in this case: Since
l
l
Pl,l,...,l
= c
a1k l a2k2 **aankn =
Per A,
where the sum is extended over all the permutations (k 1, . . .. kn) of the nu:t,bers 1, .. .. IL This means that the permanent of A can be computed using only 0(n3) arithmetic operations. An independent proof that the permanent can be computed by a RAM with operations of sum, product and division in polynomial time can be found in Simon [lo]. As an interesting consequence, combining such a result with the result of Valiant [ 1l] that every #P problem can be polynomially reduced to the compu-
[l] A.V. Aho, J.E. Ullman and J.D. Hopcroft, The Designl and Analysis of Compu ter Algorithms (Addison-Wesley, Reading, MA, 1974). [ 21 A. Bertoni, G. Mauri and M. Torelli, An algebraic approach to problem solution and problem semantics, in: J. Gruska, Ed., Pro<:. Symposium MFCS 77, Lecture Notes in Comput. Sci. 53 (Springer, Berlin, 197’1) 252262. [ 31 A. Bertoni, 6. Mauri and M. Torelli, Three efficient algorithrns for counting problems, Information Processing Lett. 8 (l/2) (1979) 50-53. [4] A. Bertoni, G. Mauri and N. Sabadini, A sharacterization of the class of functions computable in polynomial time on random access machines, Proc. 15fh ACM STOC (1981). [5] A. Borodin and I. Munro, The Computational Complexity of Algebraic and Numeric Problems (American Elsevier, New York, 1!)75). [6] G. Mauri and N. Sabadlini, A #P-Complete problem over arithmetical trees, Prolc. gfh CAAP (Springer, Berlin, 1981). [ 71 J.K. PerclIs, Combinatorial Methods (Springer, Berlin, 197 1). [ 81 A. Salomaa, M. Soittola, Automata Theoretic Aspects of Formal Power Series (Springer, New York, 1978). [9] A. Shamir, Factoring numbers in O(log n) steps, MIT Report LCS/TM-91, Cambridge, MA (1977). [ 10) J. Simon, Division is good, Tech. Rep., Comp. Sci. Dept., Pennsylvania State University (1979). [ 1 l] L.G. Valiant, The complexity of computing the permanent, Theoret. Compu t. Sci. 8 (1979) 189-202.
145
Volume
12, number 3
INFORMATION PROCESSING LETTERS
B3June1981
ON THE TIME AND TAPE COMPLEXITYOF WEAKUNIFICATION W. ERNI and R. LAPSPEN . Institit fiirAngewandte Mathematik,UniversititHeidelberg, D-6900 Heidelberg, Fed. Rep. Germany Received 17 April 1980; revised version received 14 January 1981
Analysis of algorithms, automata theory, computational complexity, formal languages, theorem proving, theory of computation
P.
1.
Introduction
In this paper ‘,yehave as a basic notion an expression E, i.e. a linear representation of a finite tree, whose nodes are labeled either by functions or variables (which are labels only for tips of the tree). A further basic notion is a substitution 8 which can bc performed on such an expression E whereby (1) each occurrence of a variable in E is replaced ‘r) by an expression, (2) all occurrtinces of the same variable are replaced by occurrences of the same term. Many of the centrally important predicates, which occur within theorem-proving programs, e.g. ‘set A of atoms is unifiable’, involve in their computation a subcalcuiation aiming at determining whether or not a substitution exists satisfying certain constraints. Some of the principal difficulties in achieving efficient theorem-proving programs are traceable to the amount of computation required by this ‘substitution-existence’. Thus Stillman [ 141 has considered the case where condition (2) is dropped, i.e. he introduced so called weak substitutions where it is permitted that separate occurrences of the same variable (within the same expression) are replaced by occurrences of different terms. Acy notion (e.g. unification) in which substitutions play a part generalize correspondingiy. For example, we say that expressions E, F are weakly unifiable iff there are weak substitutions 8 1, O2 such that E 0 Bi = F 0 &. Stillman mentioned [ 141 that the amount of computation /2] needed to evaluate the weak predicate namely, the predicate obtained when one seeks weak 146
0 020-O190181/OOOO-0000/%02SO 0
substitutions rather than proper substitutions to satisfy the given constraints - is significantly less than that required to evaluate the original predicate. The advantage gained in moving from unification to weak unification is: in any case, the absence of unifying weak substitutions, which can be ‘rapidly’ detected, is a sufficient condition for the absence of a unifying substitution. In this paper we want to make precise that intuitive notion of ‘rapid’ detection by showing that (1) weak unification can be detected by a random access machine within linear time [5], (2) weak unification can be detected by a deterministic Turing machine within O(log n) space [6]. Our Section 2 presents some basic notions, which are used in Section 3 and 4. In Section 3 result (1) will be obtained by results of [l] and by describing a deterministic two-way pushdown automaton with a single input head which decides the weak unification. Finally in Section 4 result (2) will be obtained by results of [ 121 and by constructing a deterministic two-way finite automaton with three input heads which decides weak unification.
2. Preliminaries All terms used and not explicitly defined in the sequel may be found in [ 14,1,8]. Proposition 2.1. In the following we will use the usual left linear representation [ 151 for string labeled trees.
INFORMATION PROCESSING LETTERS
Volume 12, number 3
It will also be useful so have an s-grammar G in Greibach normal form [ 131 which generates the set of left linear representat:Jns of finite string labeled trees. Let G = (N, T, P, Mj with N = IA, B, C, E, F, I, M}, T = i(;j, > 9f, x, L21. The set of productions P consists of: ( ljM+fA ( 2)M+xB (3jA+lA
( S)A+(F ( 6jB+ 1B ( 7jB+2B
(4jA+2A
( @B+(C
( w
(13)E 9
+)
(10) F + fAE (lljF+xBE (12) F -))
(14) E 3, I (15jI +fAE (16) I + xEIE
G assigns ‘( )’ even to the tips oi finite string labeled trees, because it turns out to be useful for the proof of Theorem 3.1 but differs from customary logical notation [9,10]. However, it is easy to see that this assignment can be omitted without changing Theorem 3.1. The grammar G generates only labels of one of the following types: Ex) {1,2Y tf) 0,2j*
for variables, for nonvariables.
This may be our label convention for the whole paper. Lemma 2.2. The expressions E and F are weakly unifiable iff for all pairs.p, q of corresponding occurrences (p in E, q in Fj one of the following conditions is satisfied: (1) the label of p is a variable, (2) the label of q is a variable, (3) the labels of p and q coincide and moreover p has the same number of immediate successors in E that q has in F. Proposition 2.3. (1) If the language L is acceptable to
a deterministic two-way pushdown automaton with K heads, then L is acceptable to a random access machine program of time complexity O(nK) [I ,3]. (2) If L is acceptable to a random access machine program of polynomial time complexity, then L is acceptable to some deterministic (or not) two-way multihead pushdown automaton [5,12].
13June 1981
Remark 2.4. Consider DSPACE(lognj, the family of lqwges decidable to deterministic off-line Turing machines which cannot modify their input tape but which have a finite numbler of extra storage tapes, each of length < log n, where n is the length of the input. This family can be described - instead of Turing machines - by other types of automata, e.g. markingautomata [ 121 and deterministic two-way (nonprinting) automata [ 71.
3. Weak unification and linear time Using Lemma 2.2 it is possible to construct a deterministic two-way pushdown automaton with one input head which decides the weak unification. Theorem 3.1. There exists a deterministic two-way
pushdown automaton with only one input head which accepts a given string u of input symbols only iff it satisfies the following conditions: (1) u = v # w with v, w are expressions and ‘#’ is a separation symbol, (2) v and w are weakly unifiable. Proof. Before starting the proof, we want to give a
remark about the ability of a deterministic two-way pushdown automaton (short 2DPDA(1)) to identify corresponding ‘(,- and ‘j’-:symbols.Searching for a ‘), which corresponds to a special ‘(, the input head moves to the right starting with the ‘(‘-symbol.While doing this ‘(‘-and ‘j’-symbols are counted by storing and deleting special counting symbols on the pushdown tape. The right ‘j’ is reached when the input head reads a ‘)’ and there is no counting symbol left. The part of the pushdown tape used to.store the counting symbols is called parenthesis counting region. Naturally the 2DPDA(lj is able to find the ‘(’ corresponding to a certain ‘j’-symbol in an analogous way. The check whether an input string u satisfies the conditions of the theorem is subdivided into two main parts: (I) Check the correctness of the input string u. (a) Is u = &v# w$ with v, w strings of input symbols not containing ‘#? (bj Are v, w expressions? (II) Check whether each pair of corresponding labels of v and w satisfies at least one of the condotions of Lemma 2.2. 147
Volume 12, number
3
INFORMATION PROCESSING LETTERS
Point (Ia) and (Ib) are not very difficult to check. (la) is done by a sin@e move of the input head from the left end of the input tape to the right end. (Ib) can be checked easily for each of the expressions v, w by using the grammar G defmed in Proposition 2 D1 (II) is checked by executing the following sequence of operations for each label s1 of v. (1) Store the number of immediate successors of sp on the pushdown tape. (2) Store the label. (3) Check whether there exists a label s2 in w which corresponds to ~1, (4) Check whether one of the labels sr, s2 is a variable. (5) Compare the labels sl and ~2. (6) Compare the number of immediate successors of s1 and s2. Point (I) is done by sequentially identifying immediate successors of s1 and pushing a successor counting symbol for each of it. Successors of s1 which are not immediate successors are filtered out by using a parenthesis counting region. Point (2) is done by simply copying the label symbol by symbol, where the last symbol is copied first. Point (3) is the most difficult operation. Therefore we want to show it in more detail. The execution starts with pushmg a separation symbol ‘T’ and moving the input head to the left to ‘4’.While doing this he stores on the pushdown tape a representation of the path history of s1 (note: an expression is a treestrusitire). This path history can be identified by the ‘(‘: ‘)‘, ‘,‘-symbols.In detail: the automaton pushes a counting symbol ‘zr’ for every relevant ‘(’ and a ‘z2’ for every relevant ‘,‘. If he reads ‘)‘, he builds up a parenthesis counting region. A ‘(’ or ‘,‘-symbolis regarded as relevant only if, actually, there is no parenthesis counting region. When the input head reaches ‘d’,he moves to the right to ‘##‘.Here he starts to check whether a label s2 exists in w which has the same path history as stored on the pushdlown tape. Moving to the right he sequentially checks whether the symbols stored on the pushdown tape coincide with the ‘(‘: ‘)‘, ‘, -symbols read by the input head. If they coincide, the symbol on the top is popped. As before the automaton has to exclude irrelevant “(‘, ‘)‘, ‘,‘-symbols.He does this by building up a parenthesis counting region if he reads ‘(, having a ‘,’ on the top of the pushdown tape. He goes on comparing the l
13 June 1981
symbols when the parenthesis counting region is finished. During this process of comparison the automaton must be able to distinguish the following two cases: (i) There is no s2 which corresponds to sr. He recognizes this by reading ‘,’ having ‘(, on the top or *byreading ‘), having any symbol on the top which does not belong to a parenthesis counting region. In this case, the input head again moves to the left reconstructing the representation of the path history of s1 on the pushdown tape. After this he can find back to s1 by using this representation. (ii) There is a s2 which corresponds to sl. The automaton recognizes this by reading ‘x’ or ‘f’ while ‘T’ stands on the top. In this case ‘T’ is popped, whereby the label region on the pushdown tape becomes accessible. The remaining points (4)-(6) of the sequence of operations are as easy to check as points (l)-(2). Point (4) is checked by reading the first symbol of each label (that of s1 is available on the pushdown tape). If the result is positive, points (5) and (6) can be skipped. Otherwise, (5) is done by simply comparing the symbols read on the input tape with those stored on the pushdown tape and (6) is done in a similar way as (1) was done. That means, immediate successors of s2 are sequentially detected and for each of them one of the stored successor counting symbols is deleted. If either (4) or both (5) and (6) hold true, the input head returns to s1 (using the described path storing method) and the same process is repeated with the next label of v. If the input head reads ‘# searching for the next label of v, then the automaton has checked all labels of v with positive result. Therefore v and w are weakly unifiable expressions and the input string can be accepted. After we have shown that there exists a 2DPDA(l) that accepts the language L of all words v # w where v and w are weakly unifiable expressions, Propositon 2.3 (1) guarantees that there is a random access machine program accepting L in O(n) time. 4. Weak unification and logarithmic space Here we prove that weak unification can be decided by a deterministic off-line Turing machine within O(log n) space.
’