Upload
phungnhi
View
213
Download
0
Embed Size (px)
Citation preview
VIII. RECURSIVELY DEFINED FUNCTIONS
I. Recursive Equations Represented by Rule Schemata
Recursive equations provide a convenient language for defining com-
putable functions. Recent studies by Cadiou [Cad72], Vuillemin [Vu74],
Downey and Sexthi [DS?6] and Berry and L~vy [BL77] separate computation-
al steps involving recursively defined functions from those involving
given primitive functions, and are based on continuous interpretations
of primitive functions with fixpoint semantics for computed functions.
The SRS approach in this section does not depend on fixpoint semantics,
and follows Rosen [Ro73] in unifying the sequencing problems related to
defined and given functions.
The strong syntactic restrictions on the forms of recursive equa-
tions in [Ca72], [Vu74], [DS76] allow simpler proofs of confluence, ter-
mination and optimality properties than those in Chapters If, III and
IV, but the SRS approach has the virtue of demonstrating that some of
these restrictions are not essential. A short discussion of the fix-
point approach appears in Section 4. Section 5 relates the schemata and
continuous semantics versions of primitive functions.
Let C be a set of constants, V a set of variable symbols, ~n a set
of n-ary function constant symbols for each n~p, Fn a set of n-ary func-
tion symbols to be defined recursively. Assume that V n FnUG n = ~.
Let Z = u{g,Gn,Fnlnap~. For each f~F n, consider a single recursive
equation f(~l ..... X--n)=A where f~Fn' ~I .... ,Xn~V~ A~(zUV)# and A
contains no variables other than ~i' .... ~n"
[f(~l ..... X_n)=A] is a rule schema. Let
sf = { [ f ( ~ l . . . . . × ) = A ] } , S F = U{sft f~Fn,n~P}.
Suppose that, for each gSGn , n¢~, we also have a nonoverlapping
consistent set Sg of rule schemata of the form [g(al,...,an)=b] with
al,...,~,b~CuV. Sg must be valid in the sense that whenever <A=B> is
an instance of a~hema in Sg, the equation A=B is true for the intend'-
ed interpretation of g. In addition, it is desirable that Sg repre-
sent all available information about g. In Sections 3 and 5 we will
see several ways to generate such a set given a semantic interpretation
of g.
Let s G = U~Sg I g~Gn,n~P~ and S = S F U S~. Now let S generate
A and r. Using Lemma 23 (p. 70), we see that S is nonoverlapping,
consistent and outer, so the SRS Rec = <Z,Z#,+,A> is commutative with
respect to (innermost preserving) r, and has the outer property.
73
Consider any fsF n and Cl,...,Cn,da c. The singleton Z-tree dsZ#
is in normal form, and f(c I ..... Cn)+*d iff f(c I ..... Cn)=d follows from
the rule schemata S generating the equations A (see Th. 5, p.29). Also
f(c I ..... Cn)+*d iff f(c I ..... Cn)=dwhere f is the meaning of f given by fix-
point semantics [Ro73] (Th. 8.4, p. 184). Reduction sequences form a
rich class of computations of recursively defined functions, mimicking
as special cases the types of computations considered by Cadiou [Cad72]
(1.4.2, pp. 12-15), Vuillemin [Vu74] (1.3, 1.4, pp. 336-343) and Downey
and Sethi [DS76] (Section 3, pp. 382-384). So, all of the following re-
sults about reduction sequences may be interpreted as statements about
computations of recursively defined functions.
Theorem 19 (Recursive Equation Theorem).
Let Rec be a SRS constructed by the above methods to represent a set of
recursive equations with primitive functions. Then Rec has the follow-
ing properties:
(I) Normal Forms are unique (i.e., recursively defined functions are
single valued).
(2) Eventually outermost reduction-sequences terminate whenever possi-
ble.
(3) Strictly innermost sequences are infinite whenever possible.
(4) Some strictly outermost noncopying sequence is optimal.
(S) Strictly innermost noncopying sequences have maximal cost.
Proof:
(i) Theorem 6 (p. 38) and Theorem 17 (p. 70).
(2) Theorem i0 (p. 50) and Theorem 18 (p. 71).
(3) Theorem ii (p. 53) and Theorem 16 (p. 67).
(4) Theorem 13 (p. 63) and Theorem 17 (p. 70).
(5) Theorem 12 (p. 60) and Theorem 17 again. []
(I) is well known. Vuillemin's "delay-rule" is related to (4).
2. Rule Schemata for Primitive Functions
In some cases elegant nonoverlapping sets of rule schemata for a
function symbol will be suggested by popular sets of axioms for that
symbol. For instance, the functions v and if then else may be repre-
sented by
S v = { [ v ( T , X _ ) = T ] , [ v ( X , T ) = T ] , [ V ( F , F ) = F ] }
74
Sir then else = { [ i f then e l s e (T,A,B)=A],
[ i f t hen e l s e (F ,A,B)=B]} .
T,FEC represent truth and falsehood. In general, the construction of
S depends on what kind of knowledge we have about g. g
Consider an interpretation <D,v> of C u U{GnlnEP} (Def. 6, p.
8). Assume that every constant symbol is assigned a different value
by v. Given v, we may define
Sg = { [ g ( c 1 . . . . . Cn)=d]l c 1 . . . . . Cn,ds C and v ( g ( c 1 . . . . . Cn))=vd}.
R o s e n ' s r u l e schemata ~[g] [Ro73] (p. 178) may be g e n e r a t e d in t h i s
f a s h i o n . Each S i s n o n o v e r l a p p i n g and c o n s i s t e n t by Lemma 23 (p. 70 ) . g Note t h a t [ g ( c 1 . . . . . Cn)=d ] ~ Sg i f f <D,v> ~ g (c 1 . . . . . Cn)=d.
More p o w e r f u l s e t s o f r u l e schemata may be o b t a i n e d by u s i n g schema
v a r i a b l e s . Given <D,v> above , suppose t h a t
( v g ) ( v c 1 . . . . . a . . . . . VCn?=Vd f o r a l l a e D.
Then, t he e n t i r e s e t o f s chemata
{ [ g ( c 1 . . . . . b . . . . . Cn)=d] 1 bag} ~ Sg may be r e p l a c e d by the s i n g l e t o n
{ [ g ( c 1 . . . . . X , . . . , C n ) = d ] } . In g e n e r a l , f o r gsG n, d~C, l e t
s chemata ( g , d ) = { [ g ( a 1 . . . . an )=d] ! ai~gU{Xi}
and <D,v> ~ g (a 1 . . . . . an)=d
and a i / ~ i - > <D,v> ~ g (a 1 . . . . . ~ i . . . . . an)=d}
Then, an a l t e r n a t e s e t o f n o n o v e r l a p p i n g c o n s i s t e n t schemata f o r g
d e f i n e d by
S ' g = U{schemata ( g , d ) ] dEC}.
Note t h a t <D,v> ~ g (c 1 . . . . . Cn)=d i f f < g ( c l , . . . , C n ) = d >
o f a schema in S ' g
is
is an instance
3. Dominance Orderings for Recursive Equations
Given a SRS E generated by a set of rule schemata representing
recursive equations, we may characterize a large class of dominance
orderings d for which E is d-outer•
7B
Lemma 24
Let S = U{Sf,Sgl fsF n, gsG n, nsp}
be a set of rule schemata representing a set of recursive equations, let
A be generated by S, and let E = <Z,F,+,A> be a SRS constructed by
the methods of Section i.
Let d be a dominance ordering satisfying the following for all AsF
and x,y,a s domainA:
If Ax=gcG n and x.(i) anc y, x-(j) ant z, i~j, and y(dA)z,
then S contains no schema of the form [g( .... ~i ..... cj .... )=d]
(if i<j) or the form [g( .... cj .... ,Xi...)=d] (if j<i).
Then E is d-outer.
Proof: Straightforward from Definition 41 (p. 63). []
Definition 51
A set of rule schemata S representing recursive equations is sequen-
tial iff the following holds:
S does not contain two different schemata of the forms
[g( .... ~i ..... cj .... )=e]
[g( .... ci,...,x~ .... )~f].
Vuillemin's sequential functions [Vu74] (3.3, pp. 351-353) generate
sequential sets of rule schemata.
Theorem 20
Let S be a sequential set of rule schemata representing recursive
equations and let E = <Z,F,-÷~A > be the associated SRS.
Define d as follows:
Let x,y be in domainA.
If x anc y, then x(dA)y.
If y anc x, then y(dA)x.
If xiy, let z be the least common ancestor of x and y, that is
z.(i) anc x and z'(j) anc y where i~j.
If A z=gsG n and S contains [g( .... c i ..... Xj .... )=e], then x(dA)y.
If S contains [g( .... ~i ..... cj...)=f], then y(dA)x.
76
In case neither form of schema is in S,
is irrelevant, so let
x(dA)y if i<j, y(dA)x if j<i.
the relationship of x and y
Then E is d-outer and, for all AcF, dA is a total ordering.
Proof: By Lemma 24 (p. 75) and Definition 51 (p. 75 ) []
Note that, when d is preorder, Theorem 20 is a special case of clause
(2) of Theorem 18 (p. 71).
Theorem 20 (with Theorem IS, p. 6~ guarantees an easy way to find op-
timal noncopying reduction sequences for sequential recursive systems
by simply computing the unique strictly d-outermost sequence for some
total dominance ordering d. Vuillemin's "generalized delay rule" [Vu74]
(3.1, p. 352) is a variation on d-outermost sequences.
'4. Continuous Semantics for Recursive Equations
Given C, V, G n, F n, z as in Section i, assume that we have a
continuous interpretation <D,v> of Z, with (vf) (!l .... 'd-n) = ~
for fsF n, !l,-", -nd sD. v represents the initial information we have
about the primitive symbols in C and Gn' with no information at all
about defined symbols in F n. Consider the SRS <Z,Z#,+,A> where A
is a set of recursive equations.
Theorem 21
Let A be a set of recursive equations containing exactly one
equation of the form f(X 1 ..... Xn)=A for each fcFn, n~p.
Let <D,v> be a continuous interpretation of ~ =CuU{Fn,Gnl ncp},
with ( v f ) ( d l a . . . . d_n)=~ f o r a l l fsF n. Then va (Def . 14, p , 1 6 )
exists and v A = defA, for all A~X#.
Proof: Define a function
m : (Z÷ (D*÷D))+(Z+(D*÷D)) which maps valuations of ~ to valuations of Z as follows:
(Tw) c = vc for csC
(~w) g = vg for g~G n
( (Tw)f) (d 1 . . . . . d n ) = ~ (A( (A-1Xi )+d i l l<_i_<n))
for fsF n , d I ..... d_nSD.
77
~j~ = ~] {w] TW = W} exists by Lemma 4 (p. 14). FZ w It is straightforward to show that Tw = w iff <D,w> ~ A and v ,
S o , v a = lf___ET.
d e f A e x i s t s by T h e o r e m 7 (p . 3 8 ) .
def A SAA c lause el) of Theorem 2 (p. 17) . To show that v A ~ def A, consider the alternate form of IfpT :
v a = ~i~T = ~ {Tigl isN} (Lemma 4).
(~ is the valuation such that
(~a)(dl . . . . . d ) = ~ fo r a t l a~Z, ! l , . . . , d n ~ D ) .
First, show by induction on the structure of A that SAA =
{(Ti~)AI icN}. Then, show by induction on i that
(Ti~)A~vB for some B where A+*B. So~
SA A E ~ {~BI A *B) = ~vB I A~ A = B} = def A D
Corollary 4
(I) In <Z,Z#,÷A> described above, (Ai)~c~$AA0 = l~{$Ail i~N}.
(2) If, in addition, for each equation [f(~l ..... X_n)=A]~ , A is of
the form g(B 1 ..... Bm), then (Ai)~oe-~vAA 0 U~Ail i~}.
Proof:
(i) Direct from Theoroms 9 (p. 43) and 21.
(2) With such strong restrictions on the equations, it is straight-
forward to show that 0 e = C. []
A detailed comparison of this chapter with the work of Cadiou
[Cad72], Vuillemin [Vu74], Downey and Sethi [Ds76] and Berry and L~vy
[BL77] reveals multitudinous small, and sometimes subtle, differences,
too intricate to describe fully here. Roughly, the authors above treat ^A v A 0 as the "denotational" meaning of a term A 0. They (implicitly)
consider a SRS such as <Z,S#,+,A> of this section. Given a reduction
sequence (Ai) , the computed meaning of A@ is U {vAil i~S}" A
computation rule is correct ([Vu74] Section 2, p. 343; [DS76] Def. 3.1,
p. 385; [BL77] III. 2.5 Definition, P.223) when it produces sequences
78
^ AAo ' (Ai) such that ~j {vAil icN}= v that is, the denotational and
computed meanings agree. Cadiou (1.7.1, p. 20), and Vuillemin ((6),
p. 230; Prop. 4, Th. 3, p. 231) show that the special complete sequences
described in V.3 (p. 43) are correct, essentially a special case of
Corollary 4, clause (i). Vuillemin ((4), p. 230; Prop. 4, Th. 3,
p. 531) and Downey and Sethi (Th. 4.1, p. 386) go on to show that the
eventually outermost sequences described in V.5 are correct under strong
syntactic restrictions. Downey and Sethi use a notion of syntactic
dominance to essentially characterize 0 e and prove correctness of all
eventually outermost sequences. The syntactic restrictions correspond
to those in Corollary 4, clause (2), so 0 e = C in cases covered by
the above work. Vuillemin's result on the optimality of the delay rule
(3.1, p. 232) corresponds roughly to Theoroms 13 (p. 63) and 20 (p. 75).
Berry and L~vy generalize the approach of Cadiou, Vuillemin, Downey and
Sethi by relaxing the syntactic restrictions on recursive equations.
~5. Continuous Semantics for Primitive Functions
The relationship between rule schemata and continuous interpreta-
tions may become quite complex if the CPO domains involved are allowed
to be very rich. To illustrate the general nature of this relationship,
we consider the very simplest of domains, the flat or discrete domains.
Given the set of constant symbols C, let D = {~I aEG}u{~}. Let F-,-__
be the simplest partial ordering of D, that is a = b iff ~ = ~ or
a = b. Let v be the continuous interpretation defined by
va = a if asC
(va)(dl ..... d_n)=m in all other cases.
Now, given a nonoverlapping consistent set A of schemata for the
primitive functions G n, all of the form g(al,...,a n) = h with
a I .... ,an,bsguV, v A exists and satisfies
= b is an instance (vAg)(al ..... an ) = b if g(al'''''an) of a rule in A
otherwise
Conversely, given a continuous interpretation <D,w> with v~w,
schemata' (g,d)={[g(a I ..... an)=dl ai~gu{~ i}
and <D,w> ~g(a I ..... an)=d
and a. ~ X.=> I --i
<D,w>
let
g (al ..... ai_l,~,ai+ 1 ..... an)=d}
79
This definition is essentially the same as the definition of
schemata (g,d) Section 2.
A = U{schemata' (g,d) I d~ c} is a nonoverlapping consistent set
of equations such that v a = w. Berry and L~vy describe special domains,
richer than the flat domains, which correspond to the Herbrand domains
in classical logic [BL77] gII.l.2 Def., p. 222). As an exercise, the
interested reader may work out a similar relation between rule schemata
and interpretations using those richer domains.