Download Definitional Programming in GCLA Techniques, Functions, and

Transcript
Definitional Programming in GCLA: Techniques, Functions, and Predicates
in terms of the symptoms they cause:
disease(plague)
<= temp(high),symp(black_spots).
disease(pneumonia) <= temp(high),symp(chill).
disease(cold)
<= temp(normal),symp(cough).
Note that this definition does not contain any atomic facts, it just describes the
relation between diseases and the symptoms they cause. Facts about a special
case is instead given as assumptions in the query. To get the intended procedural
behavior we can use the standard rules but rewrite d right and d left so that
they cannot be applied to the atoms symp and temp. One such coding of d right
using guards to restrict its applicability is shown below:
d_right(C,PT)#{C \= symp(_), C \= temp(_)} <=
atom(C),
clause(C,B),
(PT -> (A \- B))
-> (A \- C).
Assume now that we have observed the symptoms black spots and high temperature, what diseases follow?
symp(black_spots),temp(high) \- disease(D).
A query that gives the single answer D = plague. We could also ask the dual
query, that is, assuming a case of plague what are the typical symptoms:
disease(plague) \- symp(X).
A derivation of the first query is given below:
axiom
axiom
symp(bs), temp(h) ` symp(bs)
symp(bs), temp(h) ` temp(h)
v-right
symp(bs), temp(h) ` symp(bs), temp(h)
D-right
symp(bs), temp(h) ` disease(D)
2.4.4
Yet Another Procedural Part
We conclude by giving a possible rule definition giving the intended procedural
behavior for the function size defined in Section 2.2. What we wish to do is to
evaluate size as a function, for instance the query
sizeS \\- size([a,b,c]) \- C.
should bind C to s(s(s(0))) and give no more answers. We use the standard
rules d left, d right, a left, a right, true right, and false left plus the
new rule if left given in Section 2.3.4.
We start by writing a strategy, sizeS for the query above assuming that we
have a strategy that handles member correctly. Since size is used to the left, the
first step is to apply the rule d left. After that either the axiom rule or if left
should be used. This gives us the skeleton strategy:
12