Higher-Order Lazy Narrowing Calculus:
A Computation Model for a Higher-order Functional Logic Language Taro Suzuki, Koji Nakagawa and Tetsuo Ida Institute of Information Sciences and Electronics University of Tsukuba
taro, nakoji,
[email protected]
f
1
Introduction
Experiences with functional programming revealed that higher-order concept leads to powerful and succinct programming. Functional logic programming, an approach to integrate functional and logic programming, would naturally be expected to incorporate the notion of higher-order-ness. Little has been investigated how to incorporate higher-order-ness in functional logic programming. In this paper we present a computation model for a higher-order functional and logic programming. Although investigations of computation models for higherorder functional logic languages are under way[13, 9, 8, 20, 22], implemented functional logic languages like K-LEAF[6] and Babel[18] among others, are all based on rst-order models of computation. First-order narrowing has been used as basic computation mechanism. The lack of higher-order-ness is exempli ed by the following prototypical program map(F; [ ]) ! [] map(F; [X j Xs]) ! [F (X ) j map(F; Xs)] written in a language of term rewriting. The symbols that start with capital letters denote variables. Due to the higher-order term F (X ), a goal that requires the second rule cannot be solved by ordinary rst-order narrowing. This diculty can be overcome by the use of applicative rewrite systems. By writing a program in applicative systems we can partially realize higher-order programming. In an applicative rewrite system the above example can be written as map F [ ] ! [] map F [X j Xs] ! [F X j map F Xs] where term t1 t2 1 1 1 tn ((1 1 1 (t1 t2 ) 1 1 1) tn ) is an abbreviation of a rst-order term ap(ap(1 1 1 ap(t1 ; t2 ); 1 1 1); tn ). Then, with appropriate extension of rst-order rewriting, we can solve a goal like map F [0,(succ 0)] = Z , which is actually a rst-order equation ap(ap(map,F ),ap(ap(cons,0),ap(ap(cons,ap(succ,0)),[ ])))=Z
where map, succ, cons, 0 and [ ] are regarded as constants. Although the use of applicative systems is a step towards higher-order programming, an important feature pertaining to higher-order programming is missing. Namely, we cannot handle anonymous functions with bound variables, i:e: -terms. Higher-order narrowing with higher-order rewrite systems would be one direction for realizing a higher-order functional logic programming. However, as observed by Prehofer[22], simply-minded higher-order narrowing is highly nondeterministic. Prehofer's higher-order narrowing calculus LN successfully reduces some degree of non-determinism, but still a more ecient higher-order narrowing calculus is desired for a functional logic programming language. Hanus and Prehofer proposed a calculus for needed narrowing LNT, which deals with higherorder narrowing systematically[9]. Those works are based on higher-order rewriting, where -reduction is an implicit operation. On the other hand, rst-order narrowing has been studied extensively (see [7] for survey). Several narrowing methods have been proposed for reducing search space of narrowing [11, 2, 15, 5, 10]. So once we can relate (restricted class of) higher-order narrowing and rst-order narrowing, we can exploit the techniques of improving eciency of rst-order narrowing in order to improve the eciency of higher-order narrowing. In this paper we propose a higher-order lazy narrowing calculus, to be called HLNC, that is based on the rst-order lazy narrowing calculus LNC[17]for which strong completeness and deterministic version of the calculus have been developed. The organization of the rest of the paper is as follows. In Section 2 we introduce basic concepts of rewriting, notation and conventions to be used in the paper. In Section 3 we introduce a T RS , an abstract higher-order functional logic program. In Section 4 we give a rst-order narrowing calculus on which our higher-order narrowing calculus is based. In Section 5 we present HLNC together with the completeness theorem. In Section 6, we summarize our main results and their advantage, then discuss a future research theme. 2
Preliminary
We rst introduce typed terms. Let 0 be the set of all types. 0 is generated from a set of base types (denoted by ) using a function type constructor !. Let V be a set of typed variables, i.e. [ 20 V and F a set of typed constants, i.e. 0 [ 20 F , where V \ V 0 = ; and F \ F 0 = ; for 6= . The set V is divided into the set of free variables F V and the set of bound variables BV . The set F is divided into the set of de ned function symbols FD and the set of constructor symbols FC . Let T (F ; V ) be a set of simply-typed -terms over a typed signature F and V . Namely, T (F ; V ) is generated by the following grammar.
t ::= X jxjf jt1 t2 jx:t
where X 2 F V ; x 2 BV ; f 2 F and t1 ; t2 2 T (F ; V ). A term of the form (V sn ), where n 1 and V 2 F V , is called ex term. Here sn denotes s1 1 1 1 sn . A term that does not contain a ex term or a -redex is called -free term. A -free term is a term that will never be -reducible whatever substitutions are applied to it. A term t is linear if the same variable does not occur more than once in t. For a term t of the form at1 1 1 1 tn , where a 2 F , a is called root, and denoted by root(t). By V ar(t), we denote a set of free variables in a term t. We adopt the following convention for symbols. Bound variables are denoted by x; y and z and free variables by X; Y; F and H . F and H are reserved for higher-order variables. f denotes a de ned function symbol, g a function symbol (either de ned or constructor), and c a constructor symbol. Readers are referred to [17] for other notations, conventions and basic properties of rewriting that are used in this paper. 3
T RS: Rewrite system with -terms
We de ne a restricted higher-order rewrite system to be called T RS , with which we can avoid higher-order uni cation for the selection of rewrite rules.
De nition 1. (T RS ) A pair of terms l; r
2 T (F ; V ), denoted by l satis es the following conditions is called a rewrite rule:
!
r, that
{ l and r are of base type, { V ar(l) V ar(r ), { root(l) 2 FD A T RS is a set of rewrite rules l!r. A reduction relation !R induced by a T RS
R
is de ned as follows:
s!R t i there exists a position p, a substitution , and a rewrite rule l!r 2 R such that sjp = l and t = s[r]p , where syntactic equality is assumed in modulo -conversion. A T RS is called -free if 8l!r 2 R, l is -free. Note that abstractions are allowed in the proper subterms of the left-hand side of a rewrite rule of a T RS as well as in the right-hand side. When we treat rewriting by a T RS , we omit types and regard the T RS as an untyped rewrite system. The -reduction is given by the relation induced by the following (in nite) set of rewrite rules. R
= f (x:t) X !t[x := X ]
j
t 2 T (F ; V )g
(1)
where w.l.o.g. we assume that (x:t) X is linear. A meta notation s[x := t] denotes a term obtained by replacing all free occurrences of x in s by t. As in the lambda calculus, -conversion of terms are performed implicitly. Reduction
relation !R are de ned as in !R . The -normal form of t is denoted by t # . A term t is called outermost irreducible if root(t) 2 = FD or t is not a -redex. We are going to use a combined system R [ R as an abstract functional logic program. The combined system is not con uent in general even if R is con uent, as Klop's well-known counter example revealed [12]. Muller showed that a combined system of the -reduction and a left-linear con uent applicative term rewriting system, where every left-hand side of its rewrite rule contains no ex term, is con uent on a subset of terms that is closed under some operations including the -reduction[19]. Following Muller's observations in the proof of his theorem, we also can obtain the following con uence result for the combined system of R [ R over the set of terms T (F ; V ).
Theorem 2. Let
be a left-linear, -free and con uent T RS . con uent on T (F ; V ). R
!
is
R[R
u t
Note that with T RS we treat higher-order terms by applying -reduction explicitly. Pattern matching in the selection of a rewrite rule involves no implicit -reduction. Thus T RS is not a higher-order rewrite system such as HRS of Nipkow[21], for example. Furthermore, we can treat a T RS as a rst-order rewrite system by restricting terms to long -normal forms and by viewing abstraction x:s as a root-constructor term x(s), application (x:s)t as ap(x(s); t) and rst-order terms f t1 1 1 1 tn of long -normal form as f (t1 ; 1 1 1 ; tn ). Here, a long -normal form is de ned as follows.
De nition 3. Let T be a set of well-typed terms, generated by the following grammar. Let t; t1 ; 1 1 1 ; tn 2 T . t ::=
g t1 1 1 1 tn j x t1 1 1 1 t n j X t1 1 1 1 tn j x1 1 1 1 xn:t j (x1 1 1 1 xn :t) t1 1 1 1 tm
(n 0) (n 0) (n 0) (n 1) (n m 0; n 1)
subjected to the following conditions:
{ Terms g t1 1 1 1 tn ; x t1 1 1 1 tn and X t1 1 1 1 tn (n 1) are of base type. { The term t in x1 1 1 1 xn :t is of base type and is not of the form Xx1 1 1 1 xn . A term in T is called long -normal form. This de nition of long -normal form is dierent from usual long -normal form, in that we exclude abstractions that are -equivalent to a higher-order variable. An abstraction x1 1 1 1 xn :Xx1 1 1 1 xn is written only as X .
4
First-order Lazy Narrowing Calculus
Once we have de ned a T RS , we will use a rst-order narrowing calculus called LNC(Lazy Narrowing Calculus)[17] as our base calculus for a functional logic language. LNC is presented as an inference system that manipulates a sequence of equations called goal. Below an equation is written as s t. s ' t denotes either s t or t s.
De nition 4. (LNC) Let R be a TRS. The calculus LNC consists of the following ve inference rules: outermost narrowing [o]
f (s1 ; 1 1 1 ; sn ) ' t; E s1 l1 ; 1 1 1 ; sn ln ; r t; E
if there exists a fresh variant f (l1 ; 1 1 1 ; ln )!r of a rewrite rule in R. imitation [i] f (s1; 1 1 1 ; sn ) ' X; E
s1 X1; 1 1 1 ; sn Xn ; E if = fX 7! f (X1 ; 1 1 1 ; Xn )g with X1 ; 1 1 1 ; Xn fresh variables. decomposition [d] f (s1 ; 1 1 1 ; sn) ' f (t1; 1 1 1 ; tn ); E s1 t1; 1 1 1 ; sn tn ; E variable elimination [v ] s ' X; E E if X 2 = V ar(s) and = fX 7! sg. removal of trivial equations [t] X X; E E
A derivation by using the inference rules from an initial goal G to an empty goal 2 is written as G )3 2. The substitution is obtained by composing substitutions formed in each step of the derivation. V ar(G) is called LNCsolution of G.
Theorem 5. (Completeness of LNC) Let R be a con uent TRS and G a goal. For every normalized solution of G there exists an LNC-derivation G 3 ) 2 such that [V ar (G)]. u t There are two sources of non-determinism in LNC: the choice of the inference rule, and the choice of the rewrite rule in the case of the inference rule [o]. Nondeterminism in the choice of the inference rule except for parameter passing equations (see below for the de nition) is entirely resolved if we solve equations to obtain strict solutions, and take R to be a left-linear con uent system.
De nition 6. Let R be a TRS and G a goal. A substitution is called strict solution of G if for every equation s t in G there exists a closed constructor term u such that s!3R u and t !3R u. Based on the above observations a strictly solving LNC[16], written as LNCs , is given in De nition 7. There are two kinds of equations in LNCs : one that is a descendant of equations of an initial goal, and the other generated in the inference rule [o] by equating parameters. The former equations are called strict equations, and the latter equations parameter passing equations denoted by s t. The inference rules of LNCs are grouped into two: those that operate on strict equations and those that operate on parameter passing equations.
De nition 7. (LNCs ) Let
following inference rules:
R
be a TRS. The calculus LNCs consists of the
Inference rules on strict equations outermost narrowing [o] f (s1 ; 1 1 1 ; sn ) t; E t f (s1 ; 1 1 1 ; sn); E and root(t) 2 = FD s1 l1; : : : ; sn ln ; r t; E s1 l1 ; : : : ; sn ln ; r t; E
if there exists a fresh variant f (l1 ; 1 1 1 ; ln ) ! r of a rewrite rule in R. imitation [i] c(s1; 1 1 1 ; sm ) ' X; E (s1 X1 ; : : : ; sm Xm ; E )
if X 2 V ar(c(s1 ; 1 1 1 ; sm )) or c(s1 ; 1 1 1 ; sm ) 2 = T (F C ; V ) and = fX c(X1 ; 1 1 1 ; Xm )g with X1; 1 1 1 ; Xm fresh variables. decomposition [d] c(s1 ; 1 1 1 ; sn ) c(t1 ; 1 1 1 ; tn ); E s 1 t 1 ; : : : ; sn t n ; E variable elimination [v]
X s; E s X; E and s 2= V E E if X 2 = V ar (s), s 2 T (F C ; V ), and = fX 7! sg. removal of trivial equation [t]
X X; E E Inference rules on parameter passing equations outermost narrowing [o]
f (s1; 1 1 1 ; sn) t; E t 2= V s1 l1 ; : : : ; sn ln; r t; E if there exists a fresh variant f (l1 ; 1 1 1 ; ln ) ! r of a rewrite rule in R.
7!
decomposition [d]
f (s1 ; 1 1 1 ; sn) f (t1; 1 1 1 ; tn ); E s1 t1; : : : ; sn tn ; E
variable elimination [v ]
if = fX
7!
sg.
X s; E s X; E and s 2= V E E
Theorem 8. (Completeness of LNCs ) Let R be a left-linear con uent TRS and G a goal. For every normalized strict solution of G there exists an LNCs derivation G )3 2 such that [V ar(G)]. u t This theorem derives from Theorem 22 in [16] for an orthogonal constructorbased system. Extension to left-linear system is based on the result of Suzuki[24]. 5
Higher-order Lazy Narrowing Calculus
We are now ready to present a higher-order lazy narrowing calculus HLNC. For the investigation of its completeness, we present HLNC in two stages. In Subsection 5.1 we present basic HLNC and then in Subsection 5.2 we present HLNC.
5.1 BHLNC Since we use the results of the previous sections, we require that TRS is -free, left-linear, and con uent in order to ensure the completeness of HLNC. We often see these restrictions in the discussion of a computation model for functional logic languages. An orthogonal constructor-based system of which many functional logic programs fall into this category is an obvious example of a T RS. As for goals, we require that each side of an equation is a long -normal form of the same type. This requirement makes the inference rules simpler. With this requirement we will easily see that T is closed under the HLNC-derivation. In the sequel basic HLNC is abbreviated as BHLNC.
De nition 9. (BHLNC) The calculus BHLNC consists of the following inference rules:
Inference rules on strict equations outermost narrowing [o] t f (s1 ; 1 1 1 ; sn); E f (s1 ; 1 1 1 ; sn ) t; E and s1 l1 ; : : : ; sn ln ; r t; E s1 l1 ; : : : ; sn ln ; r t; E if t is outermost irreducible and there exists a fresh variant f (l1 ; 1 1 1 ; ln ) ! r of a rewrite rule in R.
outermost -reduction [o ]
t (xn :u) sn ; E (xn :u) sn t; E and t is outermost irreducible u[xn := sn ] t; E u[xn := sn] t; E
outermost narrowing on ex terms [ov ]
F sn t; E
(u[xn := sn ] t; E )
and
t F sn ; E
(u[xn := sn ] t; E )
t is not ex
if n 1, t is outermost irreducible, = fF 7! xn :ug, and xn :u is an appropriate closed long R -normal form1 . imitation [i] c(s1; 1 1 1 ; sm ) ' X; E (s1 X1 ; : : : ; sm Xm ; E ) if X 2 V ar(c(s1 ; 1 1 1 ; sm )) or c(s1 ; 1 1 1 ; sm ) 2 = T (F C ; V ) and = fX c(X1 ; 1 1 1 ; Xm )g with X1; 1 1 1 ; Xm fresh variables. decomposition [d]
c(s1; 1 1 1 ; sn ) c(t1 ; 1 1 1 ; tn ); E x sn x tn ; E and s1 t1 ; : : : ; sn tn; E s1 t1 ; : : : ; sn tn; E and
xn :s xn:t; E s t; E
variable elimination [v]
X s; E s X; E and s 2= V E E
if = fX 7! sg, X 2 = V ar(s), and s 2 T (FC ; V ). removal of trivial equation [t]
X X; E E Inference rules on parameter passing equations outermost narrowing [o] f (s1; 1 1 1 ; sn) t; E t 2= V s1 l1 ; : : : ; sn ln; r t; E
if there exists a fresh variant f (l1 ; 1 1 1 ; ln ) ! r of a rewrite rule in R. outermost -reduction [o ] (xn :u) sn t; E t 2= V u[xn := sn ] t; E
1
long - and
R [ R-normal form is abbreviated as long R -normal form.
7!
outermost narrowing on ex terms [ov]
F sn t; E
if n
t 2= V
(u[xn := sn ] t; E ) xn :ug and xn :u is an appropriate fresh closed long
1, = fF 7! R -normal form. decomposition [d] x sn x tn ; E f (s1 ; 1 1 1 ; sn ) f (t1 ; 1 1 1 ; tn ); E and s1 t1; : : : ; sn tn; E s1 t1 ; : : : ; sn tn; E x :s xn :t; E and n s t; E variable elimination [v ] X s; E s X; E and s 2= V E E if = fX 7! sg.
Remarks: { In [ov] and [ov] , how to choose u in xn:u is unspeci ed. The selection of an appropriate u is discussed separately in the following subsection. { In [v], occur check is not necessary, since the left-hand side of a parameter passing equation is a fresh variable.
{ There is no rule of removal of a trivial equation for parameter passing equations since R is left-linear and the right-hand side of a parameter passing equation contains only fresh variables.
It takes a considerable amount of work to formally discuss the correspondence between the inference rules of LNCs and of BHLNC. The most of the discussion, however, follows the line of the formulation of NCA[20]. The only dierences are the inference rules [o ] and [o ] . As space is limited, we brie y discuss the inference rules [o ] and [o ] for treating the -reduction. These inference rules are equal to so-called n step weak head -reductions of the one side of an equation, i.e. only the root positions are contracted in these -reductions. Such reduction derivations are always possible because every (R [ R )-rewrite derivation starting from a -redex can be simulated by a derivation such that (possibly zero) inner (R [ R )-rewrite steps follow a (possibly empty) head reduction derivation. It is formally given in Lemma 11. On the other hand, in the application of [o] of LNCs to the -redex in a goal we may choose the rewrite rule whose left-hand side is an instance of the -redex; this LNCs -step does not correspond to the BHLNC-step by [o ]. Such LNCs-steps can be replaced with another LNCs-steps that employ the rewrite rules whose left-hand side is more general than the original one. It is formally given in Lemma 10. From these observations we can easily see that the undesirable LNCs derivations are excluded. Hence we can relate desirable LNCs -derivations with BHLNCderivations with [o ]. The formal statement is given by Proposition 12. We will omit the full proofs of the lemmas and the proposition.
Lemma 10. Let
R be a left-linear con uent ( rst order) TRS and G a goal. Suppose we have an LNCs -derivation G )3 2 such that [o] is applied to G with a variant l ! r of a rewrite rule in R. For any LNCs-step G )[o] G0 with a rewrite rule l0 ! r0 such that a substitution satis es l0 = l and r0 = r, there exists an LNCs-derivation G0 )30 2 such that 0 [V ar(G)]. Proof. The proof is done by a so-called lifting lemma. u t
Lemma 11. For any rewrite derivation s !3R[R t starting from s of the form (x:M )N1 1 1 1 Nk (k > 0), there exists a derivation s !3R s0 !3R[R t, where only the root positions are contracted in the rst subderivation s !3R s0 . Proof.
Similar to the proof of Lemma 11.4.6 in [3].
u t
Proposition 12. Let R be a -free left-linear con uent TRS , S a goal of the form (xn :M )sn ' t; E (n > 0), and a (R [ R )-normalized solution of S . There exists a BHLNC-step S )[o ] S 0 and a (R [ R )-normalized solution of S 0 such that [V ar(S )]. Proof. By Lemmas 10 and 11. u t Theorem 13. (Completeness of BHLNC) Let R be a left-linear, -free and con uent T RS , and G a goal. For every long R -normalized strict solution of G there exists a BHLNC-derivation G )3 2 such that [V ar(G)]. u t 5.2 HLNC Although BHLNC enjoys the completeness it will not be useful as a calculus unless it is provided with an eective procedure to nd an appropriate term u in [ov ] and [ov ] . In general term u is not uniquely determined, and moreover search for u involves do-not-know non-determinism. We will next discuss how to reduce the search space of u. The search space for u is reduced by observing the structures of the right-hand side term t of the processed equation F sn ' t and of parameters of a rewrite rule to be used to rewrite the term F sn .
De nition 14. (HLNC) The calculus HLNC consists of the following inference rules and the inference rules of BHLNC excluding [ov ] and [ov ] :
outermost narrowing on ex terms with imitation binding [ovi]
F sn t; E
(g(H1 sn ; 1 1 1 ; Hm sn ) t; E )
and
t F sn ; E
(g(H1 sn ; 1 1 1 ; Hm sn ) t; E )
t is not ex
if 1 n, t is outermost irreducible, = fF 7! xn :g(H1 xn ; 1 1 1 ; Hm xn )g. outermost narrowing on ex terms with projection binding [ovp]
t F sn ; E F sn t; E and t is not ex (si (H1 sn ) 1 1 1 (Hm sn ) t; E ) (si (H1 sn ) 1 1 1 (Hm sn ) t; E ) if 1 n, 1 i n, t is outermost irreducible, = fF
7!
xn :xi (H1 xn ) 1 1 1 (Hm xn )g.
outermost narrowing on ex terms with imitation binding [ovi]
F sn t; E
(g(H1 sn ; 1 1 1 ; Hm sn ) t; E )
t 2= V
if 1 n, = fF 7! xn :g (H1 xn ; 1 1 1 ; Hm xn )g. outermost narrowing on ex terms with projection binding [ovp]
F sn t; E
(si (H1 sn ) 1 1 1 (Hm sn ) t; E ) if 1 n, 1 i n, = fF
7!
t 2= V
xn:xi (H1 xn) 1 1 1 (Hm xn)g.
The following theorem is crucial in order to justify our calculus HLNC, and is the main result of the paper. We sketch the proof because the description of its rigorous proof is beyond the scope of the present paper.
Theorem 15. (Completeness of HLNC) Let R be a left-linear, -free and con uent TRS, and G a goal. For every long R -normalized strict solution of G there exists an HLNC-derivation G )3 2 such that [V ar(G)]. 3 Proof Sketch. Given an non-empty BHLNC derivation 5 : G ) 2, we con0 0 3 struct a BHLNC derivation 5 : G )0 2, with an HLNC step G )[0 ];1 G0 .
Applications of this construction process repeatedly to the obtained BHLNC derivations eventually yield an HLNC derivation G )[0 ];1 G0 )32 2 provided there exists a complexity measure of BHLNC derivations monotonously decreasing during this process (see the Figure 1).
5: G
0 ];1
;1
)[ ]
G1 )32 2
+[
5 0 : G0 3 +
2
)
3
0
2
2
Fig.1. Transformation of BHLNC derivations 3 The complexity j5 j of a BHLNC derivation 5 8 : G ) 2 is de ned9 as the pair (M (5 ); #(5 )), where M (5 ) is the multiset jXj j X 2 V ar (G) and #(5 ) is the length of 5 . Here jtj is the size of long -normal forms de ned as follows:
xj = 1 x 2 BV f (s1; 1 1 1 ; sn )j = 1 + js1 j + 1 1 1 + jsn j n 0 jF (s1 ; 1 1 1 ; sn )j = 1 F 2 V; n 0 jx:sj = jsj j
j
We de ne a (strict) partial order on BHLNC derivations by 51 52 if 51j lex(>mul ; >) j52j. In the gure 1, we show 5 5 0 for any application of the inference rule [] in the rst step of 5 . In the case [] is one of the inference rules other j
than [ov ] and [ov] , we immediately obtain a BHLNC derivation 5 0 by taking [] = [0 ]. It is not dicult to show that M (5 ) M (5 0 ) and #(5 ) > #(5 0 ). Only the dicult cases are where [] is [ov ] or [ov] . Consider the following BHLNC derivation 5 :
F x d(0)
ov];1 =fF 7!x:d(0)g d(0) d(0)
)[
d 00
)[ ]
d
)[ ]
2:
Application of [ovi] to the initial goal yields
F x d(0)
ovi];1 =fF 7!x:d(H x)g d(H x) d(0):
)[
The BHLNC derivation 5 0 starting from the goal obtained by the application of [ovi] is obtained as follows: d(H x) d(0)
d
)[ ]
Hx0
ov];01 =fH 7!x:0g 0 0
)[
d
)[ ]
2:
The relationship between the subderivation of 5 starting from the second goal and 5 0 is very clear: the same inference rules are applied to the same equations as far as a head variable introduced by [ovi] does not appear in the root position of the one side of the equation. When the head variable occurs in the root position as H x 0, a substitution for H is provided by [ov] then the equation 0 0 is obtained, which corresponds to the equation in 5 . Furthermore, the term bound to H is the subterm 0, plus a binder x, of the term x:d(0) bound to F , thus M (5 ) > M (5 0). As the result of the considerable amount of formal arguments, we learn that it is always the case, thereby, the construction process of HLNC derivations works as desired. u t The following example illustrates how goals are solved by HLNC. This example shows that HLNC can solve a higher-order uni cation problem. Let G be a goal c(x:F x) c(x:d(0)). G is solved by HLNC as follows. c(x:F x) c(x:d(0)) )[d] x:F x x:d(0) ) [d] F x d(0) ) [ovi]; =fF 7!x:d(H x)g d(H x) d(0) 1 )[d] H x 0 )[ovi];2 =fH 7!x:0g 0 0 )[d] 2 A solution of G is (# )V ar(G) = ((1 2 )# )V ar(G) = fF fF 7! x:d(0)g. 6
7!
x:d((x:0) 0)g# =
Concluding Remarks
We have presented a higher-order lazy narrowing calculus HLNC as a computation model of a functional logic programming language. HLNC enjoys the completeness with respect to normalized solutions for a left-linear, -free and con uent T RS . HLNC is based on a rst-order lazy narrowing calculus LNC that incorporates a rewriting strategy usually called lazy evaluation in functional programming. HLNC automatically inherits those properties that eliminate certain non-determinism inherent in general narrowing. This is done by the establishment of relationship between higher-order narrowing calculi and rst-order
narrowing calculi. Now we can exploit the techniques of improving eciency of rst-order narrowing in order to improve the eciency of higher-order narrowing. It produces much advantages over higher-order narrowing based on higher-order rewriting because rst-order narrowing is studied more extensively. The relationship between rst-order narrowing and higher-order narrowing in our framework relies on the introduction of R , a rst-order TRS embodying reduction. Another expression of -reduction in the form of a rst-order rewrite system is explicit substitution[1, 4]. The most desirable one is [4] proposed by Benaissa et al. since the calculus of is presented by a simple orthogonal TRS. However, is not con uent on open terms, i.e. the terms not correspond to classical -terms. The con uent property of the combined system R [ on closed terms, the terms of classical -calculus, is still unclear, though we expect it would be dicult to show its con uence. HLNC applies -reductions to -redexes in the goals explicitly. Any HLNC step involves no implicit -reduction. This property is preferable from the computational aspect. Consider the following TRS. if(true; X; Y ) ! X if(false; X; Y ) ! Y Let 6 be a complicated -term whose normalization involves many -reduction steps. We have an HLNC step issuing from the equation if(false; 6; x:x) x: if(false; 6; x:x) x
)[o] false false; 6 X; x:x Y; Y x )[d] 6 X; x:x Y; Y x )[v] ;fX 7!6 g x:x Y; Y x )[v] ;fY 7!x:xg x:x x )[o ] x x )[d] 2 The discard of 6 is guaranteed by operational semantics of HLNC. Thus HLNC gives implementors a strict speci cation how and when -redexes should be reduced. As long as the system is implemented correctly, the -redexes are com-
puted only when they are necessary. By contrast, the higher-order narrowing applying -reductions implicitly does not specify when -redexes are reduced. It leaves implementors how and when -redexes should be reduced. Our development of higher-order narrowing calculus is still under way. For instance, the lack of higher-order patterns in the left-hand side of rewrite rules causes a problem in writing interesting programs demonstrated in [22]. We conjecture that we can relax the condition of -free for TRS, such that higherorder patterns are allowed in the left-hand side of rewrite rules. We expect that a technique developed by Qian et al. to treat higher-order pattern uni cation by modular rst-order uni cation can be exploited[23, 14]. References
1. M. Abadi, L. Cardelli, P.-L. Curien, and J.-J. Levy. Explicit Substitutions. Technical Report 54, Digital Systems Research Center, February 1990. 2. S. Antoy, R. Echahed, and M. Hanus. A Needed Narrowing Strategy. In Proc. of 21st ACM Symposium on Principles of Programming Languages, pages 268{279, Portland, 1994.
3. P.H. Barendregt. The Lambda Calculus (revised edition). North-Holland, 1984. 4. Z.-E.-A. Benaissa, D. Briaud, P. Lescanne, and J. Rouyer-Degli. , A Calculus of Explicit Substitutions Which Preserves Strong Normalization. Technical Report 2477, INRIA, Lorraine, January 1995. 5. A. Bockmayr, S. Krischer, and A. Werner. Narrowing Strategies for Arbitrary Canonical Systems. Fundamenta Informaticae, 24(1,2):125{155, 1995. 6. E. Giovannetti, G. Levi, C. Moiso, and C. Palamidessi. Kernel-LEAF: A logic plus functional language. Journal of Computer and System Sciences, 42(2):139{185, 1991. 7. M. Hanus. The Integration of Functions into Logic Programming: From Theory to Practice. Journal of Logic Programming, 19,20:583{628, 1994. 8. M. Hanus, H. Kuchen, and J. J. Moreno-Navarro. Curry: A Truly Functional Logic Language. In Proc. of ILPS'95 Workshop on Visions for the Future of Logic Programming, pages 95{107, 1995. 9. M. Hanus and C. Prehofer. Higher-order narrowing with de nitional trees. In Proceedings of Seventh International Conference on Rewrite Techniques and Ap-
plications, Lecture Notes in Computer Science 1103, pages 138{152, 1996. 10. T. Ida and K. Nakahara. Leftmost Outside-In Narrowing Calculi. Journal of Functional Programming, 7(2), 1997. To appear. 11. T. Ida and S. Okui. Outside-In Conditional Narrowing. IEICE Transactions on Information and Systems, E77-D(6):631{641, 1994. 12. J. W. Klop. Combinatory Reduction Systems. Mathematical Centre Tracts Nr. 127, CWI, Amsterdam, 1980. PhD Thesis. 13. H. Kuchen. Higher Order BABEL. In S. Breitinger, H. Kroger, and R. Loogen, editors, Proc. of 5th International Workshop on Functional and Logic Programming, page XII, 1996. 14. J. Liu and Z. Qian. Using First-Order Narrowing to Solve Goals of Higher-Order Patterns. In Proc. of Fuji International Workshop on Functional and Logic Programming, pages 92{105, July 1995. 15. A. Middeldorp and E. Hamoen. Completeness Results for Basic Narrowing . Applicable Algebra in Engineering, Communication and Computing, 5:213{253, 1994. 16. A. Middeldorp and S. Okui. A Deterministic Lazy Narrowing Calculus. In Fuji International Workshop on Functional and Logic Programming, pages 104{118. World Scienti c, 1995. 17. A. Middeldorp, S. Okui, and T. Ida. Lazy Narrowing: Strong Completeness and Eager Variable Elimination. Theoretical Computer Science, 167:95{130, 1996. 18. J. J. Moreno-Navarro and M. Rodrguez-Artalejo. Logic Programming with Functions and Predicates: The Language BABEL. Journal of Logic Programming, 12:191{223, 1992. 19. F. Muller. Con uence of the lambda calculus with left-linear algebraic rewriting. Information Processing Letters, 41:293{299, 1992. 20. K. Nakahara, A. Middeldorp, and T. Ida. A Complete Narrowing Calculus for Higher-Order Functional Logic Programming. In Proc. of the 7th Programming Languages Implementation and Logic Programming, Lecture Notes in Computer Sciences 982, pages 99{114, 1995. 21. T. Nipkow. Higher-order critical pairs. In Proc. Sixth Annual IEEE Symposium on Logic in Computer Science, pages 342{349, 1991. 22. C. Prehofer. Solving Higher-Order Equations: From Logic to Programming. PhD thesis, Technischen Universitat Munchen, 1995.
23. Z. Qian. Linear Uni cation of Higher-Order Patterns. In Proc. of Theory and Practice of Software Development, Lecture Notes in Computer Sciences 668, pages 391{405. Springer Verlag, 1993. 24. T. Suzuki. Standardization theorem revisited. In Proceedings of Fifth International Conference on Algebraic and Logic Programming, Lecture Notes in Computer Science 1139
, pages 122{134, 1996.
This article was processed using the LaTEX macro package with LLNCS style