Program m ing 3.1 Introduction
3.2 T he Calculus h H for First-O rder H ereditary Harrop Logic The classes of objects of the calculus hH are defined as follows; the class r of simple types,
the class t of first-order terms, the class S of signatures and the class A of atomic formulae are defined as in LJ^^; the classes of H and G-formulae~hoth subclasses of logical formulae— the class A of hH-contexts—a subclass of L J^^-contexts— and the class e of hH-proof-terms—a subclass of LJP* -proof-terms— are defined in Fig. 3.1. JT-formulae are often called hereditary
H A \ H A H \ G D H \ 'i ^ ,r H (H^-formulae)
G A | G A G | G V G | / / D G t 3^,rG | V,:TG (G-formulae)
A ::= {) I A ,x : (contexts)
e ::= pair(e,e) | inl{e) | inr{e) | lambda{x.e) | pairq{t,e)
I lambdaq{x.e) | x | splitl{x,x.e) | splitr{x,x.e)
I apply{x,e,x.e) \ applyq{x,t,x.e) (proof-terms)
X ranges over the set X of variables and r ranges over simple types. Figure 3.1: Classes of objects of hH .
Harrop formulae or program formulae and G-formulae are called goal formulae. As for
hH-contexts are sets and the notation (A, x : H) stands for A U {x : H}; x ^ A means that there is no Lf-formula H s.t. x : H is an element of A. The symbol identifying a class of objects, possibly indexed, is used as a meta-variable ranging over such a class, e.g. G, Gi, G ],... are used as meta-variables ranging over G-formulae.
The forms of judgement of the calculus hH are presented in Fig. 3.2. Judgements of the form E; A e : G are called {hH)-sequents. Sequents are the main judgements of hH;
any other form of judgement is called an auxiliary judgement of hH. The derivable auxiliary judgements of forms (i) and (ii) are the same as those of the calculus defined by the rules in Figs. 2.2 and 2,3. The derivable auxiliary judgements of forms (iii)-(vi) are defined by the rules in Fig. 3.3. The derivable sequents are defined by the rules in Fig. 3.4; essentially, the rules defining derivable sequents are obtained by constraining the rules of to AR-sequents, except for axioms that enforce a further constraint, i.e. hH only allows axioms whose main formula is atomic. Note that, in rules =>- V the eigenvariable condition is captured by the side conditions, since if h S; A basis is derivable and x ^ E then x has no free occurrences in
(i) h E signature (signatures)
(ii) E h i : r (terms of simple type)
(iii) 1- E; A basis (bases)
(iv) E h A a / (atomic formulae)
(V) E h / / / i / (hereditary Harrop formulae)
(vi) S h G y / (goal formulae)
(vii) E; A e : G (proof-terms of a goal formula) Figure 3.2: Judgement forms of hH .
formulae of A. The notions of left and right rules, and the notions of main and side formulae
of a left rule are as for LJ^*, see Sec. 2.3.2. In left rules, the rightmost sequent premiss is called the main premiss.
The principal part of a sequent derivation TT is the tree obtained from TT by deleting each subtree whose root is not a sequent. In a sequent E; A => e : G, e is called the proof-term of the sequent. If E; A ^ e : G has a derivation n then e is called the proof-term of w and e is called a proof-term for deriving G w.r.t. E; A. As for LJ^*, it may be easily shown that the proof-term and the context of a derivation’s endsequent determine uniquely, up to renaming of bound variables, the principal part of such derivation.
The calculus hH is used in Sec. 3.6 to define a semantics for the first-order pure logic pro gramming language FOPLP. In such a language a logic program is a basis of hH; a goal is a G-formula of hH; achieving a goal G w.r.t. a program E; A is a search for a proof-term e s.t. the sequent E; A => e : G is derivable in hH; any such proof-term e is called a witness for the achievement of G w.r.t. E; A.
In order fully to determine a semantics for FOPLP, it remains to define what counts as different means of goal-achievement. Given a basis E; A and a goal G there may be several proof-terms e s.t. the sequent E; A => e : G is derivable in hH. For example, let A be a context of the form (x : Ai D (A^ D A3), x% : Ai), where Ai, Ag and A3 are atomic formulae, and let E be a signature s.t. the judgement h E; A basis is derivable in hH . Let G be the formula Ai D (((Ag D A3) D Ag) D A3). The proof-terms in Fig. 3.5 are five possible witnesses for the achievement of G w.r.t. E; A. (See Appendix B for the h/f-derivation corresponding to witness (!).)
Should the five witnesses, for the achievement of G w.r.t. £; A, shown in Fig 3.5, be considered as different means of achieving G w.r.t. E; A in FOPLP? Or, should some of these witnesses be regarded as essentially the same means of goal-achievement?
Under traditional declarative semantics for logic programming, based on minimal models, as referred to in Sec. 1.3, all the five witnesses above for the achievement of G w.r.t. E; A are
h S signature h E ;A basis T,h H hf
h E; () basis h E; A, x : if basis *
Rules for well-formed bases.
Rules for well-formed atomic formulae.
E I- A a / E h Hi h / E h ifa A/ E h A A/ E h ifi A if2 A/ E h i f A / E l - G y / E , x : r h F A /
E h G D if A/ E h V*:rif A/ ® ^ Rules for well-formed program formulae,
E h A a / E h Gi y / E h Ga y / E h A y / E h G i A G a y / E h Gi y / S h G a y / E h G y / E h i f A/ E h G i V G a y / E h i f 3 G y / S, I : r h G g / E , i : 7 - h G g / E H 3 . „ Gs/ ^ E(-V ,;rO g/ ^
Rules for well-formed goal formulae.
h E; A , X : A basis
E ; A ,x : A = > x : A
E; A =» ei : G i E; A =» eg : Gg E; A =*- p a i r { e i, eg) : G i A Gg
E; A, X : ifi A if 2, xi : ifi = > e : G , E; A, X : ifi A ifg => sp/if/(x,xi.e) : G *
E; A, X : ifi A Ü2, xi : ifg =» e : G A ^ A
E; A ,x : ifi Aifg => sp/»fr(x,xi.e) : G
E ; A = » e : G i E h Gg y / E ; A ^ e : G z E h Gi y / ,
E; A=> m/(e) : Gi V Gg ' E;A=> inr(e) : Gi VGg
E; A, x: J Ï =î . e; G
E; A =*- lambda{x.e) : if 3 G
E; A, X : Gi 3 ifi =» e : Gi E; A, x : Gi 3 ifi, xi : ifi =» ei : G . . E; A, X : Gi 3 ifi => app/y(x,e, xi.ei) : G ’
E; A =>■ e : [t/x]G E h t : r E; A pairq(i,e) : 3i;;rG ^ ^ E, X : r; A =» e : G h E; A basis
E; A =>■ lambdaq{x.e) : Wa-.rG ^
E; A, xi : 'ix.rH, xg : [t/x]if =» e : G E h t : r ^ ^ ^ E; A,xi : Vr:rif => ctpp/yqCxi.t.xg.e) : G ’ ^
Figure 3.4: Rules for derivable sequents of hH.
regarded as the same means of achieving G w.r.t. S; A. (Note that the goal has no existen- tially quantified variables.) The language A Prolog is defined by means of a sequent calculus formalisation of a higher-order hereditary Harrop logic c/[NM88]. Such sequent calculus, when restricted to first-order logic, essentially corresponds to hH , without proof-term annotations. There, the different means of achieving a goal w.r.t. a program correspond to the different instantiations that may be given to the existentially quantified variables in the goal. So, the five witnesses above are regarded as the same means of achieving G. However, if the means of goal-achievement are considered to be the derivations which are uniform and use the admissible rule of backchaining^ for deriving atomic goals, then the witnesses (i)-(iv) are regarded as the
(i) apply{x, xi,X4.
Iambda{x2.lambda{x3.appîy{x4, apply{x3,lambda{x7.apply[x4,®7> Xs-Xs)), Xe-Xe), X5.X5))))
(ii) Iambda{x2.lambda{x3.appîy{x3,lambda{x‘r.apply{x, xi,XQ.apply{xg, xj,xg.xg))), xe.
apply{x, xi,X4.apply{x4, xe,X 5 X 5 ) ) ) ) )
(iii) Iambda{x2.lambda{x3-apply{x, xi, X4.
apply{x4, apply{x3,lambda{xj.apply{x4, xj,xg.xg)), xg-Xg), X5.X5))))
(iv) Iambda{x2.lambda{x3.apply{x, xi, X4.
apply{x4, apply{x3, lambda{x7.apply{x, xi, xg.apply{xg,X7,x g . x g ) ) ) , x g . x g ) , X 5 . X 5 ) ) ) )
(v) Iambda{x2.lambda{x3.apply{x, xg, X4.
apply{x4, apply {x3,lambda{x7.apply {x, x\,xg.apply{xg,x ? , x g . x g ) ) ) , x g . x g ) , X 5 . X 5 ) ) ) )
Figure 3.5: Witnesses for the achievement of G w.r.t. E; A.
same means of achieving G, but (v) constitutes a different means of achieving G. (Note that the proof-terms (i)-(iv) map under <f> to the same normal iVJP*-proof-term N and N is different from the image of the proof-term (v) under (f>.)
In functional programming the computation mechanism consists of evaluation of an expres sion to some kind of normal form, e.g. expressions of ground type (“printable values”) are usually evaluated to canonical forms of the type whereas expressions of non-ground type are only evaluated to some kind of weak normal form.
In logic programming, we take the view that the means of goal-achievement should corres pond to a class of derivations satisfying some normality constraint. The result of a computation, a witness for the achievement of a goal w.r.t. a program, does not need to satisfy such nor mality constraint, but a normal form should be easily computable from it, if desired. Natural deductions are usually seen as the archetypal forms of reasoning for intuitionistic logic. Given a formula and a set of assumptions there may be several deductions of the formula from the assumptions. Often, deductions having the same normal form are identified. We choose the dif ferent means of goal-achievement in FOPLP to be in 1-1 correspondence with expanded normal deductions of hereditary Harrop logic. Recall that from the expanded normal form of a deduc tion D one may easily compute all the /1-normal forms /l^y-equivalent to D and D ’s /?r;-normal form.
Section 3.5 shows that there is a class of AR-derivations, uniform linear focused derivations
that is in 1-1 correspondence to expanded normal deductions. Uniform linear focused derivations may be shown to correspond precisely to Miller’s uniform derivations with backchaining for
deriving atomic formulae.