• Nenhum resultado encontrado

PERPETUAL PROCESSES

No documento Lloyd Foundations of Logic PrQgramming (páginas 93-104)

A perpetual process is a definite program which does not terminate and yet is doing useful computation, in some sense. With the advent of PROLOG systems for concurrent applications [18], [93], [106], especially operating systems, more and more programs will be of this type. Unfortunately, the semantics for definite programs developed in chapter 2 do not apply to perpetual processes, simply because they do not terminate. Inthis chapter, starting from the pioneering work of Andreka, van Emden, Nemeti and Tiuryn [2], we discuss the basic results of a semantics for perpetual processes.

§25. COMPLETE HERBRAND INTERPRETATIONS

In this section, we introduce complete Herbrand interpretations. We define the complete Herbrand universe and base and prove that they are compact metric spaces under a suitable metric. Some elementary notions from metric space topology, all of which can be found in [29], for example, will be required.

The complete Herbrand universe for a definite program is the collection of all (possibly infinite) terms which can be constructed from the constants and function symbols in the program. Thus our first task is to give a precise definition of a (possibly infinite) term, which extends the definition given in §2 of a (finite) term.

Let ro* denote the set of all finite lists of non-negative integers. Lists are denoted by [il'...,ik], where il'".,ikero. If m,nero*, then [m,n] denotes the list which is the concatenation of m and n. If nero* and iero, then [n,i] denotes the list [n,[i]]. We let IXI denote the cardinality of the set X. Similarly, if nero*, then Inl denotes the number of elements in n.

174 Chapter 6. Perpetual Processes §25. Complete Herbrand Interpretations 175 Definition We say T !:;ro* is a tree if the following conditions are satisfied:

(a) For all nero* and for all i,jero, if [n,i]eT and j<i, then neT and [nj]eT.

(b) I{i : [n,i]eT}1 is finite, for all neT.

Definition A tree T is finite if T is a finite subset of ro*. Otherwise, T is infinite.

Example The finite tree ([], [0], [1], [2], [1,0], [1,1], [2,0], [2,1], [2,2]) can be pictured as in Figure 7.

The infinite tree ([], [0], [1], [1,0], [1,1], [1,1,0], [1,1,1], [1,1,1,0], [l,l,l,l],... } can bepictured as in Figure 8.

[]

[0]

[1,0] [1,1] [2,0] [2,1] [2,2]

Fig. 7. A finite tree

[]

[1,1,1,0]

Fig. 8. An infinite tree

[1,1,1,1]

Intuitively, each neT is a node of the tree T. Condition (b) in the definition of tree states that each node has bounded degree.

We let S be a set of symbols and ar be a mapping from S into ro, which determines the arity of each symbol in S.

Definition A term (over S ) is a function t : dom(t) -7 S such that (a) The domain of t, dom(t), is a non-empty tree.

(b) For all nedom(t), ar(t(n)) = I{i : [n,i]edom(t)}1.

We say the tree dom(t) underlies t. We let TermS denote the set of all terms over S.

Intuitively, a term is a (possibly infinite) tree, whose nodes are labelled by symbols in such a way that the arity of the label of each node is equal to the degree of that node.

Definition The term t is finite if dom(t) is finite. Otherwise, t is infinite.

Definition Let tbea term. The depth, dp(t), of t is defined as follows:

(a)Ift is infinite, then dp(t) = 00.

(b) Ift is finite, then dp(t)= 1+max{lnl : nedom(t)}.

It will be convenient to have available the concept of the truncation at depth n (nero) of a term t, denoted by an(t). For this purpose, we introduce a new symbol Q of arity 0, which will be used to indicate that a branch of the term t has been cut off in the truncation. Thus anis a mapping from TermS into TermS u {Q}

defined as follows:

176 Chapter 6. Perpetual Processes §25. Complete Herorand Interpretations 177

Ultrametric spaces have topological properties rather similar to discrete metric spaces [5].

Definition (X,d) is a metric space, if d is a metric on X. If d IS an ultrametric, then (X,d) is an ultrametric space.

Clearly, o.n(t) is a finite tenu with dp(o.n(t» :=;; n+1.

TenuS can be made into a metric space in a natural way. First, we recall the definition of a metric space [29].

Now let s,~eTenuS' Ifs:¢:!:, then it is clear that o.n(s);t:o.n(t), for some n>O.

Consequently, If s;t:t, then {n : o.n(s);t:o.n(t)} is not empty. We define o.(s,t) = min{n: o.n(s);t:o.n(t)}. Thus o.(s,t) is the least depth at which s and t differ.

Proposition 25.1 (TenuS' d) is an ultrametric space, where d is defined by d(s,t) = 0, if s=t

= 2-<X.(s,t), otherwise.

A crucial fact about TenuS is given by the following proposition [72].

Proposition 25.2 (TenuS' d) is compact iff S is finite.

Proof Suppose first that S is infinite. Let {t

s : se S} be any collection of tenus with the property that ts(O)=s (that is, the root is labelled by s). Ifs1;t:s2' then d(t ,t ) =1/2. Thus TenuS is not compact.

s1 s2

Conversely, suppose that S is finite. Let {tk}keco be a sequence in TenuS' We consider two cases.

(a) There exists meco and peco such that, for all n"?p, we have dp(tn):=;;m.

Since S is finite, there are only a finite number of tenus over S of depth :=;; m.

Hence {tk}keco must have a constant and, hence, convergent subsequence.

(b) Given meco and peco, there exists n"?p such that dp(tn»m.

In this case, we can suppose without loss of generality that the sequence {tk}keco is such that dp(tk»k, for keco. Note that every subsequence of {tk}keco has the property that the depths of the tenus in the subsequence are unbounded.

We define by induction an infinite tenu teTenu

S such that, for each n"?1, there exists a subsequence {tkm}meco of {tk}keco with o.n(t

km) = o.n(t), for me co.

Suppose first that n=1. Since S is finite, a subsequence {~ }meco of m

{tk}keco must have the same symbol, say s, labelling their root nodes. We define t([]) = s.

Next suppose that t is defined up to depth n. Thus there exists a subsequence {tk } of {tk}k such that a. (tk ) = a. (t), for meco. Since S is finite,

m meco eco n m n

there exists a subsequence {~ }peco of {~ }meco such that the o.n+1(~ ) are

m m mp

all equal, for peco. Define the

n~es

at depth n+1 for t in the same way as each of the tk . This completes the inductive definition.m

Sin~e

it is clear that t is an accumulation point of {tk}ke co' we have shown that TermS is compact. I11III

Now we are in a position to define the complete Herbrand universe. Let P be a definite program and F be the finite set of constants and function symbols in P.

We regard constants as function symbols of arity O.

~. Thus tn~t

The closure of a (a) dom(o.n(t» = {medom(t) : Iml:=;;n}.

(b) o.n(t) : dom(o.n(t» ~ Sv

in}

is defined by o.n(t)(m) = t(m), if Iml <n

=

n,

if Iml = n.

Definition Let X be a set. A mapping d : X x X ~ non-negative reals is a metric for X if

(a) d(x,y) =0iff x=y, for all x,yeX.

(b) d(x,y) = d(y,x), for all x,yex.

(c) d(x,z) :=;; d(x,y) + d(y,z), for all x,y,zeX.

dis an ultrametric [5] if

(d) d(x,z) :=;; max{d(x,y), d(y,z)}, for all x,y,zex.

Proof Straightforward. (See problem 1.) I11III

Convergence in the topology induced by d is denoted by means that the sequence {t }n necoconverges to t in this topology. set A in this topology is denoted by

A.

Definition A metric space (X,d) is compact if every sequence in X has a subsequence which converges to a point in X.

Definition The complete Herbrand universe

Up

forP is TenuF. The elements of

Up

are called ground terms.

178 Chapter6. Perpetual Processes §25. Complete Herbrand Interpretations 179 Thus Upis the set of all ground (possibly infinite) terms which can be formed

out of the constants and function symbols appearing in P. It is straightforward to show that "ground term", as defined in §3, can be identified with "finite ground term", as just defined. (See problem 2.) This identification is taken for granted throughout this chapter. Thus we have Upk;;Up. As long as P contains at least one function symbol, it is clear thatUp is a proper subset ofUp.

We adopt the convention throughout this chapter that "term", without qualification, will always mean a possibly infinite term. If a term is finite, this will always be explicitly stated.

Despite the fact that we have given a rather formal definition of term, in the material which follows we will rarely make direct reference to this definition, relying instead on the reader's intuitive understanding of a term. All the arguments presented could easily be formalised, if desired. We will also find it convenient to use a more informal notation for terms. In particular, for finite terms we will continue to use the old notation.

Example fff... is the infinite term pictured in Figure 9.

f(a,f(a,f(a, ...

»)

is the infinite term pictured in Figure 10.

Proposition 25.3 Let P be a definite program. Then Up is a compact metric space, under the metric d introduced earlier.

Proof The result follows from proposition 25.2, since the set of constants and function symbols inPis finite. II1II

The proof of the next result is straightforward. (See problem3.)

Proposition 25.4 Let P be a definite program. ThenUpis dense inUp,under the topology induced by d.

Upis called "complete" because it is the completion [29] of the metric space Up' We will also require the concept of a (possibly infinite) atom. Let P be a definite program, F be the set of constants and function symbols in P, R be the set of predicate symbols in P and V be the set of variables in P (more precisely, the first order language underlying P). All variables have arity O.

Definition An atom A is an element of TermVuFuR such that A(n)eR iff n=[], for all nedom(A).

f

f

f

Fig. 9. The infinite term fff...

Thus an atom is a term with the root node (only) labelled by a predicate symbol. Just as we did for terms, we can identify "finite atom", as just defined, with "atom", as defined in §2. Whenever an atom is finite, this will always be explicitly stated in this chapter.

Definition The complete Herbrand base B

p

for a definite program P is the set of all terms A in TernL.. for which A(n)eR iff n=[], for all nedom(A). The

ruR

elements ofB

p

are calledground atoms.

Thus B' is the set of all ground (possibly infinite) atoms which can be formed

P l '

out of the finite set of constants, function symbols and predicate symbo s appeanng in P. Note that Bp k;;B

p.

Proposition 25.5 Let P be a definite program. Then B

p

is a compact metric space, under the metric d introduced earlier.

180 Chapter 6. Perpetual Processes §25. Complete Herbrand Interpretations 181

Fig. 10. The infinite term f(a,f(a,f(a, ...

»)

ProofTe~URis compact, by proposition 25.2. It is easy to show that B' is p a closed and, therefore, compact subspace ofTe~UR' l1li

Proposition 25.6 LetP be a definite program. Then Bp is dense in Bp, under the topology induced by d.

ProofStraightforward. l1li

The concept of a substitution applied to an atom in §4 can be easily generalised to the present more general definition of atom and term. We restrict attention to ground substitutions applied to finite atoms, which is all that is needed in this chapter.

Definition A ground substitution S is a finite set of the form {v It v. It }

. . 1 1"'" k' k '

where eachVI' IS a vanable, the variables are distinct and t.e U'1 p' Dor 1'=1,... , .k Definition Let A be a finite atom with variables {vl""'v

k} and S = {vI/tl'...,vI!tk}be a ground substitution. Then AS is the ground atom defined as

follows:

(a) dom(AS) = dom(A) u {[m,n] : medom(A), A(m)=Vi and nedom(ti), for some ie {I,...,k}}.

(b) AS : dom(AS) -+FuR is defined by

AS(m) A(m), if medom(A) and A(m)li {v1,...,v k} AS([m,n]) = ti(n), if medom(A), A(m)=v

i and nedom(t

i), for some ie {I,...,k}.

We say AS is a ground instance of A. The collection of all ground instances of the finite atom A is denoted by [[Al]. Note that [A] ~ [[All ~Bp'

Proposition 25.7 Let Pbe a definite program and C = {Al'...,Am} be a set of finite atoms with variables xl'''''xn, Consider the mapping

Sc : (Up)n -+(Bp)m defined by

SC(tI,···,tn) = (AIS,...,AmS),

where S = {xIltl'""xn/tn}' Then Sc is continuous, where (Up)n and (Bp)m are each given the product topology.

Proof Suppose that {(tI,k,...,tn,k) }kero converges to (tl'...,tn) in the product topology on (Up)n. Put Sk = {xI/tI,k"",xn/tn,k}' for kero. Clearly AiSk -+ AiS, for i=I,...,m, and hence Sc is continuous. l1li

Proposition25.8 Let Abe a finite atom. Then [[Al] is a closed subset of Bp.

Proof Put C = {A}. IfA has n variables, then [[A]] = Sc<(Up)n). Since Sc is continuous and Up is compact, SC«Up)n) is a compact and, therefore, closed subset of Bp. l1li

Proposition25.9 Let A bea finite atom. Then [A] = [[A]].

ProofSince [A] ~ [[All and [[Al] is closed, [A] ~ [[Al]. On the other hand, if C={A} and A has n variables, then [[Al] = SC<(Up)n) = SC«Up)n) ~ SC<(Up)n)

= [A], by propositions 25.4 and 25.7. l1li

We conclude this section with the definition of a complete Herbrand interpretation and the mapping Tp'

Definition Let P be a definite program. An interpretation for P is a complete Herbrand interpretationif the following conditions are satisfied:

182 Chapter 6. Perpetual Processes §26. Properties of T'p 183

(a) The domain of the interpretation is the complete Herbrand universe Up' (b) Constants in P are assigned themselves in Up'

(c) Iff is an n-ary function symbol in P, then the mapping from (Up)n into Up defined by (tl'...,tn) --?f(tl' ...,tn) is assigned to f.

We make no restrictions on the assignment to the predicate symbols in P, so that different complete Herbrand interpretations arise by taking different such assignments. In an analogous way to that in §3, we identify a complete Herbrand interpretation with a subset of Bp' The set of all complete Herbrand interpretations for P is a complete lattice under the partial order of set inclusion.

Definition Let P be a definite program. A complete Herbrand model for P is a complete Herbrand interpretation which is a model for P.

We also define a mapping Tp from the lattice of complete Herbrand interpretations to itself as follows. Let I be a complete Herbrand interpretation.

Then Tp(I) = {AeBp : A~Bl"...,Bn is a ground instance of a clause in P and {Bl'...,Bn}k I}.

Note that Tp is

Ti,

for the pre-interpretation J consisting of the domain Up and the above assignments to constants and function symbols. It turns out that because of the compactness of Up and Bp, Tp has an even richer set of properties than Tp' We explore these properties in the next section.

§26. PROPERTIES OF T

p

In this section we establish various important properties of Tp, notably that gfp(Tp) = Tp.J-ro.

We begin with four results, which are the analogues for Tp of propositions 6.1, 6.3 and 6.4 and theorem 6.5. The proofs of these results are essentially the same as the earlier ones.

Proposition26.1 (Model Intersection Property)

Let P be a definite program and {Mi}ieI be a non-empty set of complete Herbrand models for P. Then (\eIMi is a complete Herbrand model for P.

We let Mp denote the least complete Herbrand model for P. Thus Mp is the intersection of all complete Herbrand models for P.

Proposition 26.2 Let P be a definite program. Then the mapping Tp is continuous (in the lattice-theoretic sense of§5).

Proposition26.3 Let P be a definite program and I be a complete Herbrand interpretation for P. ThenIis a model for P iff Tp(I) k I.

Theorem 26.4 Let P be a definite program. Then Mp = Ifp(Tp) = Tp

i

roo The next result is due to Andreka, van Emden, Nemeti and Tiuryn [2].

Theorem26.5 (Closedness of Tp)

Let P be a definite program and I be a closed subset of Bp' Then Tp(I) is a closed subset of Bp. Furthermore, Tp(J) k Tp(J), for Jk Bp .

Proof Let I be a closed subset of Bp. We show Tp(I) is closed. It is sufficient to consider the case when P consists of a single clause, say, A~Al'...,Am·

Suppose the clause has n variables. Put C={A, Al'...,Am} and let Sc be the associated mapping defined in §25. Since Sc is continuous and Up is compact, we have that Sd(Up)n) is a closed subset of (Bp)m+1. Let 1t denote the

m+l Th T' (I)

projection from (Bp) onto its first component. en P 1t(Sd(Up)n) n(Bp x1m» and thus Tp(I) is closed.

For the last part, it is straightforward to show that T'p maps closed sets to closed sets iff Tp(J)k Tp(J), for J k Bp ' II1II

Corollary26.6 Tp.J-k is closed, for kero. Furthermore, Tp.J-ro is closed.

Note carefully that we do not necessarily have the opposite inclusion Tp(J);;;:1Tp(J), for J k Bp.

Example Let P be the program

q(a) ~p(f(x),f(x» _

Let J = {p(t,f(t» : te Up}. Then Tp(J)={ q(a)}, but Tp(J)=0.

Next we establish an important weak continuity result for Tp . For this we need the concept of the limit superior of a sequence of subsets of a metric space [5].

Definition Let (X,d) be a metric space and {Yn} ne ro be a sequence of subsets of X Then we define LS (Y ) = {xeX : for every neighbourhood V of x and

. nero n

for every me ro, there exists~msuch that V n Yk:;c0}.

184 Chapter 6. Perpetual Processes §26. Properties of T

p

185

Proof We have that Tp ( IlkeroIk)

= Tp(LSke ro(Ik))'

~LSkero(Tp(Ik))'

= 11 ke roTp(Ik)'

If {Yn}nero is a decreasing sequence of closed sets, it is easy to show that LSnero(Y)=11n ne ro n'Y

Theorem26.7 (Weak Continuity of Tp)

Let P be a definite program and (Ik}kero be a sequence of sets in Bp' Then LSkero(Tp(Ik)) ~Tp(LSkero(Ik))'

Proof Suppose Ae LSke ro(TP(Ik))' Then, for every neighbourhood V of A, there exist infinitely many k such that V 11 Tp(Ik);t0. Since P is finite, there exist' a clause AOf-Al'...,Am in P, a subsequence {Ikp}pero of {Ik}kero and a sequence {ep}pero of ground substitutions for the variables xl' ...,x

n of the clause such that AOep~Aand AjepeIk ' for j=l,...,m and pero.p

Suppose ep is {x1/tl,p,...,xr/tn,p}' Since Up is compact, we can assume without loss of generality that (tl p,...,t )~(tl,...,t), say. Put e =

, n,p n

{x1/tl' ,xr/tn}· By proposition 25.7, we have that

(AOep, ,Amep)~(AOe,...,Ame). Since AOep~A, we have that AOe=A.

Furthermore, since Ajep~Aje, we have that AjeeLSkero(Ik)' for j=l,...,m. Hence Ae Tp(LSkero(I

k)). I

Note that we do not generally have LSkero(Tp(Ik)) = Tp(LSkero(Ik))' ExampleConsider the program

q(a) f- p(f(x),f(x))

Pu k k+l

t Ik={p(f (a),f (a))}, for kero. Then LSkero(Ik)={p(fff...,fff...)}. Thus Tp(LSkero(Ik))={q(a)}, but LS

kero(Tp(I k))=0.

Corollary26.8 (Intersection Property for Tp)

Let P be a definite program and (Ik}kero be a decreasing sequence of closed setsinBp. Then Tp( Il keroIk) = IlkeroTp(Ik)'

since the Ik are closed and decreasing by theorem 26.7

since the Tp(Ik) are closed and decreasing.

We cannot drop the requirement that each I

k be closed in corollary 26.8.

Example Consider the program q(a) f- p(f(x))

Let Ik be (p(f\a)) : n~k}, for kero. Then (Ik}kero is a decreasing sequence.

Furthermore, IlkeroIk=0, so that Tp( Il keroIk)=0. However, Tp(Ik) = (q(a)}, for ke roo Thus 11 ke roTp(Ik)={ q(a) }.

Part (a) of the next theorem is due to Andreka, van Emden, Nemeti and Tiuryn [2]. Recall that it can happen that gfp(Tp);tTpJ.ro.

Theorem26.9 Let P be a definite program. Then we have (a) gfp(Tp) = TpJ.ro.

(b) Tp( Il keroTpJ.k);d Il keroTpJ.k.

Proof(a) It suffices to show that Tp(TpJ.ro)=TpJ.ro. Now we have Tp(TpJ.ro)

= Tp( Il keroTPJ.k)

= IlkeroTP(TpJ.k), by corollaries 26.6 and 26.8

= TpJ.ro.

(b) We have Tp( Il keroTpJ.k)

= 11 keroTp(fpJ.k), by corollary 26.8

;d 11 ke roTp(TpJ.k), by theorem 26.5

~ IlkeroTp J.k. I

It is apparent that the essential reason that gfp(Tp)=TpJ.ro is because Up is compact. We generally have gfp(Tp);tTpJ.ro precisely because limits of sequences of finite terms are missing from Up' In many respects, Tp, Up and Bp give a more appropriate setting for the foundations of logic programming than Tp, Up and Bp'

186 Chapter 6. Perpetual Processes §26. Properties of T

p

187

Note that (")keolpJ..k may not be a fixpoint of Tp.

Example Let P be the program q(a) f- p(x,f(x))

p(f(x),f(x)) f- p(x,x)

Then (")keolpJ..k = {p(fff...,fff...)}, but Tp( (")keclpJ..k) = {q(a), p(fff...,fff...)}.

Proposition 26.10 Let P be a definite program. Then we have (a) TpJ..k = TpJ..k, for k=O, 1.

(b) TpJ..k ~ TpJ..k, for l.e2.

Proof By corollary 26.6, TpJ..k is closed, for keco. Also it is easy to show by induction that TpJ..k~TpJ..k, for keco. Thus we have TpJ..k~TpJ..k, for keco.

Furthermore, TpJ..O =

B

p = Bp = TpJ..O. Finally, we leave the proof that TpJ..l = TpJ..l to problem 9. I

Note that TpJ..k may be a proper subset of TpJ..k, for l.e2. (See problem 10.) Proposition 26.11 Let P be a definite program. Then TpJ..co C (")k T J..k

- eco P

~ TpJ..co.

Proof We have TpJ..co

= (")kecoTpJ..k

~ (")kecoTpJ..k

~ (")kecoTpJ..k, by proposition 26.10

= TpJ..co. I

Note that both of the inclusions in proposition 26.11 may be proper. (See problem 11.)

Next, we prove a useful characterisation of (")keco p-.v .T 'k

Theorem 26.12 Let P be a definite program and Ae Bp. Then the following are equivalent:

(a) Ae (")kecoTpJ..k.

(b) There exists a sequence {Ak}keco such that AkeTpJ..k, for keco, and A k~A.

(c) There exists a finite atom B and a non-failed fair derivation f-B=GO' G1,...

with mgu's aI' a2,... such that Ae (")keco[[Ba

1...ak]]. (If the derivation is successful, then the intersection is over the finite set of non-negative integers which index the goals of the derivation).

Proof The equivalence of (a) and (b) is left to problem 12.

(c) implies (a). Suppose (c) holds. By proposition 25.9, we have that Ae (") co [Ba

1·..a ]. By proposition 13.5, given keco, there exists neco such that

ne n

----[Ba1...an]~TpJ..k. Hence Ae (")kecoTpJ..k.

(b) implies (c). For this proof, we ensure fairness in all derivations by always selecting atoms as follows. We select the leftmost atom to the right of the (possibly empty set of) atoms introduced at the previous derivation step, if there is such an atom; otherwise, we select the leftmost atom.

Let {Ak}keco be a sequence such that AkeTpJ..k, for keco, and Ak~A. Since AkeTpJ..k, proposition 13.4 shows that there is a derivation Dk beginning with f-Ak, which is either successful (that is, D

kis a refutation of Pv {f-A

k}) or has length> k. We consider two cases.

(1) Given meco and peco, there exists n~psuch that Dnhas length> m.

In this case, by passing to an appropriate subsequence, we can assume without loss of generality that the sequence {Ak}keco is such that AkeTpJ..k, for keco, Ak~A and D

k has length > k.

We now prove by induction that there exists a finite atom B and an infinite fair derivation f-B=GO' G1,... with input clauses Cl' C2,... such that, for each neco, there exists a subsequence {Akm}meco of (Ak}keco' where Cl'""Cn+1 are the same (up to variants) as the first n+1 input clauses of each of the Dk andm Gn+1is more general than the (n+l)th goal in D

km, for meco.

Suppose first that n=O. Since P contains only finitely many clauses, a subsequence {Ak } of {Ak}k co must use the same program clause, say E, in

m meco e

the first step of Dk . We let B be the head ofE and let C1be a suitable variant of m

E.

Next suppose the result holds for n-l. Thus there exists a finite atom B and a fair derivation f-B=GO' Gl'...,Gnvia R with input clauses Cl'""Cn such that there exists a subsequence {Ak } of {Ak}k co' where C1,...,C are the same (up to

m meco e n

variants) as the first n input clauses of each of the Dk and G is more generalm n than the nth goal in Dk ' for me co. Note that as the lengths of the Dk arem m unbounded, the nth goal in each Dk is not empty. Furthermore, the same atom ism

188 Chapter 6. Perpetual Processes §27. Semantics of Perpetual Processes 189

selected in the nth goal of each Ok SincePcontains only finitely many clauses,

m

a subsequence {Ak } co of {Ak } co must use the same program clause, say

m pe m me

F, as the (n+l)th inCut clause of the derivation Ok . It is clear that (a suitable

m

variant of) F can be used as Cn+l' This completes

th~

induction argument.

To finish off case (1), we have only to show that if 81,82,,,, are the mgu's of the derivation just constructed, then Ae [[B8 1...8n]]' for ne co. However, this follows from proposition 25.9, since, given neco, there exists a subsequence {Ak }m co such that Akm e m~A and Ak e[B81...8 ]. Thus A satisfies condition (c).m n

(2) There existsmecoandpeco such that, for alln~p, D

nhas length S; m.

In this case, since each Ok is either successful or has length > k, we may assume without loss of generality that there exists meco such that the sequence {Ak}keco has the properties that Ak~A and each Ok is successful with length S;

m. Because P is finite, there exists a subsequence {Ak } co such that all the

m me

Ok have exactly the same sequence of input clauses (up to variants). Suppose E m

is the program clause used first in each of the Ok . We let B be the head of E and construct a refutation of P U {f-B} of length S;mm using the same sequence of input clauses as each of the Ok . In a similar way to case (1), we can show that

m

A satisfies condition (c). I

§27. SEMANTICS OF PERPETUAL PROCESSES

As we stated above, a perpetual process is a definite program which does not terminate and yet is doing useful computation, in some sense. The problem is to find the appropriate sense of an infinite computation being "useful". We solve this problem by introducing the concept of an infinite atom in Bp being

"computable at infinity". The set of all such atoms plays the role for perpetual processes that the success set plays for programs which terminate. The major result of this section is that the set of all atoms computable at infinity is a subset of gfp(Tp)' Related results have been obtained by Nait Abdallah and van Emden [76], [77], [108].

We begin with the key definition.

Definition Let P be a definite program and AeBp\Bp' We say A is computable at infinity if there is a finite atom B and an infinite fair derivation f-B=G

O'G

1,... with mgu's 81' 82"" such that d(A,B81 ...8k)~0, ask~oo.

We put Cp = {AeBp\Bp : Ais computable at infinity}.

ExampleLetPbe the program p(f(x» f- p(x)

Since lfp(T )=0, this program does not compute anything in the sense of chapter 2.

Howev~r,

given the goal f-p(x),the atom p(fff...) can be "computed at infinity". In fact, it is clear that Cp={p(fff...)}.

Example LetPbe the program fib(x) f- fib 1(0. Lx)

fibl(x.y.z.w) f- plus(x,y,z), fibl(y.z.w) plus(O,x,x)

f-plus(f(x),y,f(z» f- plus(x,y,z)

(Recall the convention that n stands for f"(0». Clearly fib(L2.3.5.8. 13....)e Cp' where the argument of fib is the Fibonacci sequence. We simply let B be fib(x) and we obtain the approximating sequence fib(Lx 1), fib(L2.x2)' fib(L2.3.x3),..· .

Example We consider Hamming's problem, which is to construct the sorted sequence t of positive integers containing no prime factors other than 2, 3 or.5.

Thus the initial part of the sequence t is 2.3.4.5.6.8.9.10.12;15... The followmg programP to solve this problem appeared in [17] and [41].

hamming(x) f- seqprod(Lx,2,u), seqprod(Lx,3,v), seqprod(Lx,5,w), merge(u,v,z), merge(z,w,x)

merge(x.u,y.v,x.w) f- y>x, merge(u,y.v,w) merge(x.u,y.v,y.w) f- x>y, merge(x.u,v,w) merge(x.u,x.v,x.w) f- merge(u,v,w)

seqprod(x.u,y,z.v) f- prod(x,y,z), seqprod(u,y,v) f(x»f(y) f- x>y

f(x)>O prod(x,O,O)

f-prod(x,f(y),z) f- prod(x,y,w), plus(w,x,z) plus(O,x,x)

f-plus(f(x),y,f(z» f- plus(x,y,z) Then it is clear that hamming(t)e Cpo

No documento Lloyd Foundations of Logic PrQgramming (páginas 93-104)

Documentos relacionados