ScienceDirect® Home Skip Main Navigation Links
You have guest access to ScienceDirect. Find out more.
 
Home
Browse
My Settings
Alerts
Help
 Quick Search
 Search tips (Opens new window)
    Clear all fields    
advertisementadvertisement
Information and Computation
Volume 183, Issue 1, 25 May 2003, Pages 2-18
International Workshop on Implicit Computational Complexity (ICC'99)
 
Font Size: Decrease Font Size  Increase Font Size
 Article - selected
PDF (239 K)
Thumbnails - selected | Full-Size Images

 
 
 
Related Articles in ScienceDirect
View More Related Articles
 
View Record in Scopus
 
doi:10.1016/S0890-5401(03)00011-7    How to Cite or Link Using DOI (Opens New Window)
Copyright © 2003 Published by Elsevier Science (USA).

Analysing the implicit complexity of programs

J. Y. MarionE-mail The Corresponding Author, E-mail The Corresponding Author

Loria Calligramme Project B.P. 239, 54506, Vandoeuvre-lès-Nancy Cedex, France

Available online 25 February 2003.

Abstract

We study termination proofs in order to (i) determine computational complexity of programs and (ii) generate efficient programs from the complexity analysis. For this, we construct a termination ordering, called light multiset path ordering (LMPO), which is a restriction of the multiset path ordering. We establish that the class of first order functional programs on lists which is terminating by LMPO characterises exactly the functions computable in polynomial time.

Article Outline

1. Introduction
2. Programming with rewrite rules
2.1. Programs over many-sorted algebra
2.2. Semantics
2.3. Multiset path ordering
3. Light multiset path ordering
3.1. Valency and extension of orderings to n-uplets
3.2. Properties
4. Characterisation of ptime
4.1. LMPO programs
4.2. Examples
4.3. Simple constructor sets
4.4. Main result
5. Bounding normal form size
5.1. A polynomial interpretation of terms
5.2. Properties of Fk
5.3. Bounding theorem
5.4. Quasi-interpretation of derivations
6. LMPO programs are ptime computable
References

1. Introduction

What is the complexity of a function computed by a program? How can an efficient program which computes the same function be extracted? We shall attempt to answer to those questions. We consider first order functional programs whose data structure are lists. The result is a syntactic delineation of a significative class of programs which defines exactly all functions running in polynomial time. It is difficult to ascribe a precise meaning to “significative” because we are dealing with intentional properties of programming languages. So, we mean a class of programs containing algorithms which solve nontrivial problems naturally, as we shall try to illustrate in Example 4.2. The result is based on an analysis of program termination proofs to determine an approximation of the complexity of the computed function that we call the analysis of the implicit complexity of a program. We shall see that the programs considered calculate in exponential time, but denote polynomial time functions. For this, we combine termination orderings for term-rewriting systems (see the survey of Dershowitz [8]) and the ramification of recurrence schema arising from the work of Simmons [18], Bellantoni and Cook [2], and Leivant [15]. A similar approach, which replaces the above ramification principle by a semantic argument, has been suggested by Marion and Moyen [16]. Compared to the analysis of the complexity of a program like Benzinger’s prototype [3], this approach allows us to transform programs. The transformation is based on dynamic programming methods which were developed first by Cook [6] and generalised by Andersen and Jones [1 and 12].

This paper is organised as follows. Section 2 defines functions computed by rewrite systems and multiset path ordering. The construction of light multiset path orderings is given in Section 3. In Section 4, the main result is presented in Theorem 18. The proof is established by Theorems 19 and 20. The proof of Theorem 20 is first outlined and details are in 5 and 6.

2. Programming with rewrite rules

2.1. Programs over many-sorted algebra

A signature is a pair (Image ) where Image is a finite set of sorts (atomic types) and Σ is a vocabulary on Image . A vocabulary on Image consists in a finite set of symbols. Every symbol in Σ has some fixed arity n and a type. The type of a symbol of arity 0 is a sort Image of Image . The type of a symbol of arity n>0 is an (n+1)-uplet of sorts of Image that we write Image .

Throughout, for every sort Image there is a countably infinite set Image of variables of sort Image which is disjoint from vocabularies. Put Image .

The set Image is the set of freely generated terms of type Image . The set of terms is Image . The set of ground terms of type Image is denoted by Image . The set of ground terms is Image . The set of variables in a term t is Var(t)subset of or equal toχ. A ground substitution is a mapping σ from χ to Image , which respects type variables. The size, |t|, of a term Image is the number of symbols in t

Image


Definition 1.  A program is a quadruplet Image where
Image is a set of sorts.

Image

is a vocabulary on Image and symbols of Image are called constructors.

Image

is a vocabulary on Image , disjoint of Image , and symbols of Image are of arity >0 and are called function symbols.

Image

is a finite sequence of oriented equations. Every equation is of the form f(t1,…,tn)→t where Image is of type Image , each Image , Image such that FV(t)subset of or equal tounion or logical sumiless-than-or-equals, slantnVar(ti).

The main function symbol is the last symbol defined in Image .

2.2. Semantics

Actually, a program Image denotes a term rewriting system. The set of equations Image induces a rewriting rule → defined as follows: uv if the term v is obtained from u by applying an equation of Image . The relation Image (Image ) denotes the transitive (reflexive-transitive) closure of →. We write Image to mean that Image and t is in normal form. A program is confluent if the induced rewriting rule → is confluent. One might consult [9] about general references on rewrite systems.

We give an operational semantics based on term rewriting. The domain of computation of a program Image is the term algebra defined by the signature Image . The interpretation of the sort Image is the ground term algebra built on constructor terms; that is, Image .

Definition 2.  Let F be the main symbol of a confluent program Image of type Image . The function computed by Image is

which is defined as follows. For all Image iff Image and Image , otherwise left double bracket delimiterFright double bracket delimiter(u1,…,un) is undefined.

Throughout, we shall only consider the normal forms, which are in Image , as being meaningful.

Example 3.  The following equations define the function which returns the minimum value in a list of numbers. The sorts are Image and constructors are

.
Image

Image
Image

Image
Putting Image , we have Image . The program Image denotes .

2.3. Multiset path ordering

Multiset path ordering (MPO) was introduced by Plaisted [17] and Dershowitz [7]. MPO belongs to the family of syntactic term orderings whose well-foundness stems on Kruskal’s tree theorem [14].

We briefly describe MPO. A multiset M of terms of Image is a finite mapping Image which associates to each term t the number M(t) of terms t in M. Suppose that Image is ordered by precedes. This ordering precedes induces an ordering precedesm on term multisets.

Definition 4.  MprecedesmN iff MN and for all Image if M(s)>N(s), then there is Image such that sprecedest and M(t)<N(t).

Throughout, the subterm relation will be noted left triangle, open. For example, we see that {s(x),x,x} left triangle, openm {s(x),s(x),x}.

Let precedesΣ be an ordering on Σ and ≈Σ be an equivalence relation on Σ which respects symbol arities. Then, we say that the quasi-ordering not precedes, equalsΣ defined by precedesΣunion or logical sumΣ is a precedence on Σ. From ≈Σ, we define the permutative congruence ≈ as the smallest equivalence relation on terms which satisfied f(t1,…,tn)≈g(s1,…,sn) if fΣg and tiSπ(i) for some permutation π over {1,…,n}.

Definition 5.  Let not precedes, equalsΣ be a precedence on the signature Σ. The multiset path ordering precedesmpo is defined recursively by

1. sprecedesmpof(…,ti,…), if sprecedesmpoti

2. g(s1,…,sm)precedesmpof(t1,…,tn) if

either gprecedesΣf and siprecedesmpof(t1,…,tn) for all iless-than-or-equals, slantm,

or gΣf and {s1,…,sm}precedesmpom{t1,…,tn},

where not precedes, equalsmpo=precedesmpounion or logical sum≈.

A program Image is terminating by MPO if there is a precedence on Image such that for each equation lr of Image , we have rprecedesmpol. Notice that we do take into account the types of terms to prove termination.

Hofbauer has shown in [10] that the class of functions computed by a confluent program which is terminated by MPO is exactly the class of the primitive recursive functions.

Example 6.  The following program computes the exponential and terminates by MPO.



Image


Image

3. Light multiset path ordering

3.1. Valency and extension of orderings to n-uplets

The definition of a light multiset path ordering makes use of the notion of valency to restrict MPO.

Definition 7.  A valency of a function symbol f of arity n is a mapping v(f):{1,…,n} maps to {0,1}.

We shall write f(…,ti,…) to mean that the term ti occurs at position i in f, which is a position of valency v(f,i).

The valency of a function symbol f indicates how to compare arguments of f. More precisely, it indicates first how to compare n-uplets of arguments and second how to compare an argument with a term by giving the ability of combining several term orderings. Thus, valencies generalise the notion of status as proposed by Kamin and Levy [13] in the following way. The status of function symbols allow one to compare f(s1,…,sn) with f(t1,…,tn) by lifting the term ordering to an ordering on sequences of terms which depends on f. The notion of valency extends this idea to the case where root symbols are different Throughout, we shall assign valencies to the function symbols Image , but we shall never assign valencies to constructors of Image . Constructors of Image will be always treated separately.

Definition 8.  Let v be a valency function on Image . A permutation π over {1,…,n} respects the valency of f and g if the arity of f and g is n and v(g,i)=v(f,π(i)) for all iless-than-or-equals, slantn.

Definition 9.  Let precedes0 and precedes1 be two term orderings. These orderings are lifted to an ordering over n-uplets of terms which respects the valency function v on Image as follows. {s1,…,sn}precedesg,fv{t1,…,tn} iff there is a permutation π which respects the valency of f and g and which satisfies that there is jless-than-or-equals, slantn such that v(g,j)=1 and sjprecedes1tπ(j), and for all iless-than-or-equals, slantn, sinot precedes, equalsv(g,i)tπ(i).

The above ordering on n-uplets of terms is a restriction of the multiset ordering, as defined in Definition 4, induced by the transitive closure of precedes1union or logical sumprecedes0.

Definition 10.  Let Image be an equivalence relation on Image . The permutative congruencewhich respects the valency v is the smallest equivalence relation on terms of Image which satisfies:

1. c(s1,…,sn)≈c(t1,…,tn) if Image and siti for all iless-than-or-equals, slantn.

2. f(t1,…,tn)≈g(s1,…,sn) if Image for some permutation π which respects the valency of f and g.

Definition 11.  Let Image be a precedence on Image . The light multiset path ordering is a pair (precedesk)k=0,1 of orderings which is recursively defined on Image as follows:

1. sprecedeskc(…,ti,…) if snot precedes, equalskti and Image .

2. sprecedeskf(…,ti,…) if Image , and kless-than-or-equals, slantv(f,i).

3. c(s1,…,sn)precedeskf(t1,…,tm) if Image , and siprecedeskf(t1,…,tm), for each iless-than-or-equals, slantn. Note that c can be a 0-ary.

4. g(s1,…,sn)precedeskf(t1,…,tm) if (Image ) and if siprecedesmax(k,v(g,i))f(t1,…,tm) for each iless-than-or-equals, slantn.

5. g(s1,…,sn)precedes0f(t1,…,tn) if Image and {s1,…,sn}precedesvg,f{t1,…,tn},

where not precedes, equalsk = precedeskunion or logical sum≈.

3.2. Properties

 

Proposition 12.  

not precedes, equals0 is an extension of not precedes, equals1; that is, snot precedes, equals1t implies snot precedes, equals0t.

The multiset path ordering not precedes, equalsmpo is an extension of not precedes, equals0; that is, snot precedes, equals0t implies snot precedes, equalsmpot.
Proof.  Each rule of not precedes, equals1 is a rule of not precedes, equals0. By forgetting function symbol valencies, we also see that each rule of not precedes, equals0 is also a rule of not precedes, equalsmpo. □Lemma 13.  The relation (precedesi)i=0,1 is a partial ordering.Proof.  Since precedesmpo is an extension of precedesi, we immediately see that precedesi is irreflexive.  The transitivity of precedesi is tedious to demonstrate. So, we just outline the key steps of the proof. Assume that snot precedes, equalskt. We have the following:

1. If s=c(s1,…,sn) and Image , then for each iless-than-or-equals, slantn,siprecedeskt.

2. If s=g(s1,…,sn) and Image , then for each iless-than-or-equals, slantn,siprecedesmax(k,v,(g,i))t.

3. If Image , then sprecedeskc(…,t,…).

4. If v(f,i)=k, then sprecedeskf(…,t,…). where t is the ith argument of f.

  We prove these four assertions by a mutual induction on |s|+|t|. From then on, we can prove the transitivity of not precedes, equalsi again by induction on |s|+|t|. □

Neither not precedes, equals1 nor not precedes, equals0 is a total ordering. They are not simplification orderings because they are not monotonic. However, note that not precedes, equals0 is monotonic with respect to the argument of valency 1; i.e., sinot precedes, equals1ti implies f(…,si,…)not precedes, equals0f(…,ti,…) if v(f,i)=1. Also precedes0 possesses the subterm property; that is, tprecedes0f(…,t,…).

Proposition 14.  Let s and t be two terms of Image . We have snot precedes, equals1t iff snot precedes, equals0t iff s normal subgroup of or equal to t.

Proof.  (1) snot precedes, equals1t implies snot precedes, equals0t by Proposition 12. (2) To prove that snot precedes, equals0t implies s normal subgroup of or equal to t we proceed by induction on |t|. But first observe that st is equivalent to s=t by Definition 10. Otherwise sprecedes0t=c(t0,…,tn), necessarily snot precedes, equals0tj, and so s normal subgroup of or equal to tjleft triangle, opent. (3) s normal subgroup of or equal to t implies snot precedes, equals0t is proved by induction on |t|. □

4. Characterisation of ptime

4.1. LMPO programs

 

Definition 15.  A LMPO program is a sextuple Image , where Image is a confluent program, v is a valency function on Image , Image is a precedence on Image , and such that the induced ordering precedes0 satisfies for each rule lr,rprecedes0l.

Termination of LMPO programs is obtained by the fact that the term ordering precedes0 is a restriction of precedesmpo, and so the rewrite relation of a LMPO program is well founded.

4.2. Examples

We shall now give several examples. This example shows that the class of LMPO programs encapsulates a broad class of algorithmic patterns.

For the sake of readability, we write the termination proof in sequent style. On the right, we note the rule number which is applied, following Definition 11. Also, we write in subscript the valency of arguments of a function symbol in the declaration of its type. Last we use a notational convention similar to that of [2] and write f(x1,…,xn;y1,…,ym), with a semicolon separating two lists of arguments, to indicate that v(f,i)=1 for iset membership, variant{1,…,n} and v(f,n+j)=0 for jset membership, variant{1,…,m}.

1. The program displayed in Example 3 is a LMPO program where valencies are set as Image , Image , Image . The precedence is Image . The two first equations are ordered because precedes0 possesses the subterm properties. The termination proof of the third one is:


The fourth equation is a special case of (3). The termination proof of the last equation is carried out as follows.


The program Image computes the minimum of two integers n and m, written in unary, within O(min(n,m)) steps. So Image is the “good” algorithms for the function Image . Colson has demonstrated in [5] that if we consider the class of programs defined by means of strict primitive recursion, then the function Image is obviously definable but not with a “good” algorithm. In particular, this implies that the characterization of the polynomial time functions of Bellantoni and Cook [2] does not comprise a “good” algorithm for Image , due to the absence of simultaneous recursion is that class.

2. Given a list list of type Image , Image (list, Image (list);) returns the list sorted. The algorithm is the insertion sort. The sort Image , with (tt: Image , ff: Image ) as a constructor set, denotes the truth values.



Image
Image


0<suc(y)→tt
x<0ff
suc(x)<suc(y)→x<y
Image

Image


Image


Image

Put

Image