an annotated predicate calculus inference system …translator as described in [3]' there are...
TRANSCRIPT
l
An Annotated Predicate Calculus Inference System
(APCIS)
Kah-Eng Pua
Department of Computer Science University of Illinois at Urbana-Champaign
Urbana Illinois 61801
November 1984
ISG 84-8
File No UIUCDCS-F-84-928
This research was supported in part by the National Science Foundation under Grant No nCR 84-06081 and in part by the Office or Naval Research under Grant No NOO014-82-K-0186
Acknowledgement
I would 6rst like to thank Professor Ryszard Michalski ror his continued support and
guidance which made this work possible I would also like to express my appreciation to
Proressor Robert Stepp for his comments and suggestions to improve the quality or this report
Jeff Becker Tom Channic and Tony Nowicki helped me review this report Thanks to all or them
Finally a sepcial thank should go to Lai-Choi Cor her encouragements
Contents
1 Introduction bullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbull 1
2 Overview of APCIS bullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbull 2
21 Assertion-Translation Mode 2
22 Query-Translation Mode bullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbull 2
23 Assertion Mode bullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbull 4
24 Query ~1ode bullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbull 4
3 ~~c Translator 4
31~ Translation of Queries bullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbull 4
32 Translation of Iegated Term and Disjunction of Negated Terms bullbullbullbullbullbullbullbull t
33 Translation of Disjunction of Non-negated T~rms bullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbull 8
3A Further Transformation of Exceptions and Equivalences 9
4 Inference ~1echanism bullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbull 10
41 goo bullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbull 10
42 sol bullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbull 11
43 bull bullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbull bullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbulls02 12
44 dis and con bullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbull 12
45 countl and count2 bullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbull 14
46 equlv bullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbull 14
47 impli bullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbull 15
5 More on the Inference Mechanism bullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbull 15
(2)
51 Dum and cnum bullbullbullbullbullbullbull 15
52 sel and csel bullbullbullbullbullbullbullbullbullbullbull 17
6 Printing Result HJ
7 Summary bullbull 19
ReCerences bullbull 21
Appendix A APCIS Users Manual bullbullbullbullbull 22
Appendix B APCIS Program Listings 25
1 introduction
This report describes a deductive inrerence system called APCIS (Annotated Predicate
Calculus Inrerence System) wbich accepts expressions in Annotated Predicated Calculus (APC)
and carries out inrerence rrom them Annotated Predicate Calculus is an invention of Professor R
S Michalski It is built on the basis of First Order Predicate Calculus (FOPC) with some
additional features such as numerical quantifications compound terms selectors compound
selectors etc These reatures not only provide APC with more expressive power tban FOPC but
also make APC much closer to human language than does FOPC Details of APC and its
applications can be round in the paper A Theory and Methodology or Inductive Learning [2]
The process or translating APC to Prolog and a program implementing this process has
been discussed in [3] This report summarizes my continuing effort in developing an APC
inference system and can be considered as a folIowup of [3]
APCIS is capable or performing the following types of operations
1 Carrying out inferences from input assertions expressed in FOPC
2 Carrying out inrerences rrom input assertions expressed in APC
3 Dealing with disjunction or nonnegated terms or the (orm Al v A2 v v Am
4 Dealing with a negated term or a disjunction of negated terms or the rorms -(A) and
-(Al) v -(A2) v v -(An) respectively
5 Dealing with equivalence relations or the form A lt=gt B and exceptions or the
forms A - B or A lt=gt -(B) or -(A) lt=gt B
6 Counting the numbers or occurrence of given predicates in the database
In this report we present an overview of APCIS and a detailed description of its
translation mechanism and inrerence mechanism
2
2 Overview ot APCIS
Figure 1 shows the general structure of APCIS There are four modes by which we can
invoke APCIS Each of them will be discussed in the following sections
21 Assertion-Translation Mode
Figure 1(30) shows schematically the phases that APCIS will go through when assertionshy
translation mode is invoked To translate APC assertion into Prolog we type to Prolog system
ta(X)
where ta stands for ~translation of assertion and X is any APC expression to be translated The
input assertion will then go through an APC translator (discussed in [3]) and its result will be
printed out on the terminal Note that the translated result is not loaded back to Prolog system
22 Query-Translation Mode
Figure l(b) is the schematic diagram showing the execution process of query-translation
mode To translate APC query we type to Prolog system
tq(X)
where tq stands for ~translation of query and X is any APC expression The input query will go
through the same APC translator mentioned above but the output will be in the form of ~Prolog
question (see Slction 31) As in the assertion-translation mode the output will only be printed
out on the terminal and will not be loaded back to Prolog
The above two modes provide only translation purposes The following two modes
perform the actual infNence
3
1-------------1 1 ta (X) I 1-------------1
1 1-------------1
APe 1 I Translator 1
1-------------1 I
1-------------11 Terminal I 1-------------1
(a) Assertion-translation mode
1------------ a(X) I
1------------1 1
1 1------------1 I APe I 1 Translator 1
1------------1
i-----------I 1----------1 I temp_file 1 1 Terminal 1 1-----------1 I----------i
1
1 1-------------1 I Prolog 1 1 system 1 1------------ -I
(c) Assertion mode
Figure 1 Four modes of APCIS
1---------------1 1 tq(X) 1 1---------------1
1 1---------------1 1 A P C 1 I Translator 1
1---------------1 I
1---------------1 I Terminal 1 1---------------1
(b) Query-translation mode
1--------------1 q(X) I 1--------------1
1 1------------------1 1 asserta(inpt(Xraquo 1 1------------------1
1 1---------------1 1 A P C 1 1 Translator 1 1---------------1
I 1---------------1 i temt__file 1 1---------------1 1---------------1 1 Prolog 1 1 system 1 1---------------1
I 1---------------1 1 Terminal 1 1---------------1
I 1-------------------1 1 retract(inpt(Xraquo I I-----------------~-I
Cd) Q-uery mode
23 Assertion Mode
Figure l(c) is a schematic diagram showing how assertion mode works In this mode the
input assertion will first go through the APC translator as in assertionmiddot translation mode After
which the translated result will be printed both on the terminal and to a temporary file called
tempfile which will subsequently be loaded back to Prolog system As a result the newly
translated input assertion will become Prolog term(s or clause(s) in the database
24 Query Mode
Figure l(d) shows schematically the stages that will go through when query mode is
invoked The input query crowned by the (unctor inpt will first be stored in the database It will
then be passed to the APC translator as in query-translation mode The output of the translator
will be printed on the temporary file tempfile which will subsequently be loaded to Prolog
system Upon loading tempfiie to Prolog system (recall that tempJile contains essentially a
Prolog question) the question is executed immediately and its result will be prin ted out on the
terminal In the last stage the original input query crowned by the functor inpt will be
retracted from the database
3 APe Translator
As described in [3] there are ten steps in the APC translator and each step undertakes a
unique transformation Assertion-translation mode and assertion mode go through these steps
which have been covered in [3] and will not be discussed here
31 Translation of Queries
We will now examine the different transrormations that query-translation mode and
query mode will go through They differ Crom assertion-translation mode and assertion mode only
5
in the last step of translation
In the last step of the APe translator all input queries (ie expressions entered via
query-translation mode or query mode) are dealt with by the following six predicates prques pi
plett peont pehar and pout The task of prques pi plett and peont is to arrange each
input query in desired order whereas pehar and pout will print out each atomic formula
character by character For illustration purposes consider the following five APe expressions
1 all( X man(X) ==gt mortal(X)
2 exists( X horse(X) v dog(X) )
3 - ( exists( X horse(X) amp dog(X))
4 all( X be_shouted_at(X) amp no_response(X) == gt deaf(X) v dead(X) )
5 exists( 2 X box(X) )
H the above five APe expressions are typed to Prolog via assertion mode or assertionshy
translation mode they will be translated to the corresponding Prolog expressions
la
mortal(XI) shy
man(Xl)
2a
horse(skml) v dog(skml)
3a
contradiction(( horse(XI) dog(Xl) )) shy
horse(Xl)
dog(XI)
4a
deaf(Xl) v dead(Xl) shy
be_shouted_at(X I)
no_response(X1)
Sa
box(sknl)
number(sknl2)
The above live translated expressions ( ie la through Sa ) will be printed on the
terminal and loaded to Prolog if assertion mode is used they will be printed on the terminal but
not loaded to Prolog if assertion-translation mode is invoked
Now if the original APC expressions ( ie 1 through 5 ) are typed to Prolog via query
mode or query-translation mode the corresponding questions will be translated into the following
queries
lb
goo(( condi(( mortal(Xl) man(Xl))) ))
b
goo(( soil horse(Xl) v dog(XI)) ))
3b
goo(( c1ause( contradiction(( horse(XI) dog(Xl) )) _) ))
4b
goo(( conditt deaf(Xl) v dead(Xl) (be_shouted_at(XI) no_response(Xl)) )) ))
5b
amp00(( so2( box(XI) ) s02( num(XI 2 )) ))
The above five translated queries ( ie Ib through 5b ) will be printed on the terminal
and loaded to Prolog if query mode is used they will be printed on the terminal but not loaded to
Prolog if query-translation mode is invoked
In the above queries goo 801 and 802 each forms a part of the inference mechanism of
APCIS goo occupies the top level of the inference mechanism whereas 801 and 802 are at the
1
next level 102 will take care of the searching of simple terms and 101 will deal with the
disjunctions of non-negated terms in the database We will come back to them in Section 4
At the first glance one may feel that the above translated Queries are Quite complicated
However a closer examination will reveal that they are not so Queries lb 3b and 4b can each be
categorized as a conditional query which is a distinct feature of APCIS wherels queries 2b and
5b lre asking simple facts in the database
To handle conditional queries we consider two cases First if the queries involve a
special clause contradition we invoke the built-in function el3ule(X Y) which will look for the
desired contradiction clause in the database Second if the queries do not involve the clause
contradiction we activate a defined Prolog predicate condi to take care of the necessary
searching (To avoid confusion the reader is urged to compare expressions started with the same
number in the above three sets of example)
To handle a query which asks a simple fact we surround each disjunction of terms with
the functor sol as in the example 2b or crown each simple term with the functor 802 as in the
example 5b
32 TranslatIon of Negated Term And Disjunction of Negated Terms
One feature of APCIS is its ability to handle input expressions consisting of only negated
term or a disjunction of negated terms in the forms
or
2 -(AI) v ~(A2) v v ~(An)
To handle the above two forms a special clause with clause head contradiction is
created This special clause head has only one argument which is either a term or a set of terms
grouped together in the form
8
(AI A2 An)
The right-hand side of the clause contradiction is exactly same as the argument in the clause
head For example the above two forms involving negated terms will be translated into the
corresponding forms as follows
1 contradiction( A ) shy
A
2 contradiction(( AI A2 An )) shy
AI A2 An
The design of the clause with clause head contradiction will greatly enhance the inference power
of APCIS (see the example in Section 44)
33 Translation ot Disjunction ot Non-negated Terms
Another feature of APCIS is its ability to handle input expressions involving a
disjunction of non-negated terms in the forms
1 Al v A2 v v An
or
2 Bl amp 32 amp amp Bm ==gt Al v A2 v v An
Unlike Prolog which accepts only Horn clauses APCJS will accept Horn clauses as well
as non-Horn clauses which take the above two forms The inference from non-Horn clauses is
made possible by the two defined predicates sol lnd s02 discussed in Section 42 and Section 43
respectively (see also the example in Section 44) In the APC translator the above two forms are
transbted into the corresponding forms as follows
1 Al v A2 v v An
2 Al v A2 v v An shy
g
Bl B2 Bm
34 Futher Transformation of Exceptions and Equivalences
To provide some backgrounds for the discussion of the further transformation of
exception and equivalence relations we will lirst reproduce the three goals in the Step 2 of the
APe translator discussed in Section 32 of [31
First expressions involving implication or the form A ==gt B will be transformed to
Second expressions with exception symbol or the form A - B will be changed to the
form ( A lt=gt -(B) ) amp ( -(A) lt=gt B)
Tbird expressions with equivalence symbol of the form -(A) lt=gt B or of the form
A lt=gt -(B) will also be converted to ( A lt=gt -(B) ) amp ( -(A) lt=gt B ) since tbere are
logically identical to exception relations Also expressions with equivalence symbol of the form
A lt=gt B or -(A) lt=gt -(B) will remain the same
After the Step] of the APe translator both sides of any transformed expression with
lt = gt symbol will be treated separately as if they are two independent expressions In the
Step 10 of the APe translator each side of lt=gt will again be treated separately and
transformed into a form similar to an transformed input query (see Section 31) Two examples
are given below
1 state(on) lt=gt -( state(olJ) )
2 all( 1 bot(l) amp humid(l) - winter(I) )
They will be transformed in the Step 2 or the APe translator into
1
(state(on) lt=gt -( state(off) ) ) amp ( -( state(on) ) lt=gt state(olJ) )
2
10
( hot(l) amp humid(l lt=gt -(winter(l)) ) amp
( -( hot(l) amp humid(l)) lt=gt winter(I)
In Step la they will again be transformed to
1
so2( state(on) ) lt=gt so2( contradiction( state(oH) ) )
so2( contradiction( state(on) ) ) lt=gt so2( state(oH) )
2
( s02(hot(XI)) so2(humid(XI))) lt=gt so2( contradiction( winter(Xl ))
so2( contradiction(( bot(Xl) humid(Xl) )) ) lt= gt so2( winter(XI) )
There are two advantages in the treatment of exception and equivalence symbols in this
way First it will prevent Prolog program from going into an infinite loop which is difficult to
avoid if equivalent relation such as A lt=gt B is transformed into the logically equivalent form
( A ==gt B) amp ( B ==gt A) Second by maintaining both sides of lt=gt symbol in
query form the searching on either side caD be done more easily and efficiently since the form
is already processed and does not need any further transformation
Inference Mechanism
As mentioned at the end of Section 31 goo sol and s02 each forms a part of the
inference mechanism of APCIS with goo occupying the top level and 80) and 802 the second
level In addition to these countl count2 equlv and impll are also at the second level of the
inference mechanism We will go over all of them in the following sections
I goo
goo is essentially the starting point of the inference Whenever a translated query is
loaded to Prolog system from temp-fie goo will go through one or more of the following steps in
11
sequence
G 1 Check if the query asks for the numbers of occurrence of certain term(s) It so then
pass It to eountl and eount2 else go to G2
G2 The query will be passed down to sol or s02 (or both) to check i( any assertion in the
database can satisfy the query It the answer is positive then the query succeeds else
go to G3
G3 The query will be passed to equlv to carry out further searching It the searching is a
success then the query will be closed with a success else go to G4
G4 It the query is in the form A ==gt B then it will be passed to Impli It Impll
succeeds then done else the query will be closed with a (ailure
42 sol
801 and 802 together with dis and eon form the most complicated part of the APCIS
iorerence mechanism In this and the next section we will look at sol and s02 dis and eon will
be discussed in Section 44 We will close Section 44 with an example that illustrates the
materials presented in Section 42 through Section 44
sol is at the second level of the inference mechanism It will deal with any disjunction of
non-negated terms For any disjunction passed to it it will go through one or more of the
following steps in sequence
S1 Check if any term In the disjunction can be satisfied by any term or clause in the
database without contradiction It so then done else go to S2
S2 Pass the disjunction together with another disjunction (and its tlil) picked up from
the database to dis It dis succeeds then done else go to S3
S3 Pass the disjunction down to equlval which will check if any term in the disjunction
matches either side of any equivalence relation in the database It such a match is
found then check if the other side of the equivalence C3n be satisfied It so then done
else the goal fails
43 s02
s02 is also at the second level of the inference mechanism It will take care of all the
simple terms in the transl1ted query The following is the sequence that s02 wiII follow in
searching
S1 Check if the term passed to it caD be s3tisfied by any term or clause in the d3tabase
without contradiction It so then done else go to S2
S2 Pass the term together with a disjunction of terms (and its tail) picked up from the
database to dis If dis succeeds then done else the goal fails
44 dis and con
dis has three arguments In the first two clauses of dIs the first argument P v Q is
found in the database using the builtmiddotin functiol clause and the third argument R is the tair of
the term or the clause P v Q If P v Q is not a clause but a term R will be instantiated to trUE
The second 3rgument comes from either lIol or 802 and thus takes the form of either X v Y (a
disjunction of terms) or T (3 simple term)
All the clauses of dis together with con will perform the searching as exemplified in the
following algorithm (we will keep the notationsin this section)
01 Check if every term in P v Q is in X v Y It so then go to 03 else go to D2
02 For any term (in P v Q) which is not in X v Y or does not match T perform the
following tests
a Check if the term (in P v Q) has already been negated in the datab3Se (ie check if
the contradiction of the term exists in the d3tabase) If so then repeat D2 for other
terms not found in X v Y or not matching T else go to b
13
b Check if the contradiction of the term matches either side of any equivalence
relation in the database If such a match is found then check if the other side of the
equivalence can be satisfied If so then repeat O~ for other terms not found in X v Y
or not matching T else the goal fails
It all the terms (in P v Q) which are not in X v Y or do not match T survive either one
of the above two tests then go to 03
03 This step is essentially done by eon whose goal is to satisfy the tail R of P v Q It
con succeeds then done else the search fails
To close this section we will give an example to illustrate what we have covered In
Section 42 through Section 44
Example Assume that we already haye the following expressions in the database
horse(skml) v dog(skmI)
contradiction(( dog(XI) ))shy
dog(XI)
query goo(( soZ horse(X)) ))
This query will be passed to 802 which will check it the term horse() can be satisfied iu Step S 1
of Section 43 It is a failure So we now go to Step S2 In this step we pick up the disjunction
horse(~kml) v dog(skml) (and its tail true) in the datab3Se and pass it together with the term
horse(X) to dis We are now in Step 01 of Section 44 In this step we find that dog(skml) does
not match horse(X) So we have to go to Step 02 In Step 023 We find that the term dog(skml)
has already been negated (the second expression in the database) So we go to next step 03 Since
the tail of the disjuDction horse(skml) v dog(skml) is the atom true con is satisfied and the
query succeeds
45 countl and count2
countl and count2 are responsible for the counting of tbe numbers of occurrence of a
given simple term or a conjunction of terms They are activated by input queries in the form
q( exists( X whatnum amp P) )
where whatnum is the l~bel for activating the counting of the numbers of occurrence of P which
can either be a term or a conjunction of terms
countl will count the number of term(s) which will satisfy P and associate(s) with
numerical quantification(s Two counters are set to update the lower and upper boundary or the
scope or the numfrical quantifications encountered
The contents of the two counters are then passed to count2 which is responsible for the
counting or the following three types of term First term(s) which will satisfy P and associate(s)
with existential quantification(s Second term(s) which will satisfy P and has(have) Prolog atom
as its(thfir) argument(s) Third term(s) that will satisfy P and itself(themselves) is(are) Prolog
atom(s )
46 equiv
equlv will be activated only after sol and B02 have failed The first two goals of equlv
are similar to that of Step S3 in Section 42 and Step D2b in Section 44 The third goal or equiv
makes possible the inference on either side of any equivalent relation For example if we type the
following three expressions to Prolog in assertion mode
l all( X hot(X) amp humidX) - winter(X)
2 all( X hot(X) amp bumid(X) ==gt unpresent(X))
3 - ( exists( X winter(X) ) )
and then ask APCIS in query mode
q( cxists( X unpresent(X) ) )
15
APCIS with the aid of equlv will be able to answer yes to this query
41 lmpll
lmpll can be considered as the last attempt that APCIS would make to satisfy a
query It is activated only after equlv has failed It will first check if the query is conditional If
so it will convert the implication symbol to equivalence symbol and search if such an equivalent
relation can be found in the database If so a success Otherwise a failure
5 More on the Inference Mechanism
Having looked at all the subparts at the top two levels of the inference mechanism we
are ready to look at other subparts at lower levels
51 num and cnum
One distinct fe3ture or APCIS is its ability to deal with numerical quantifications As
mentioned in Section 31 input queries and assertions will undergo different transformations in
the last step (Step 10) of translation This also holds true for expressions involving numerical
quantifications Consider the following expression
exists( 6 X horse(X) )
If it is entered to Prolog via assertion mode we will after going through all the steps of
translation have the rollowing entered to the database
horse(sk n I
number(sknl6)
Now if we want to ask Are there more than five horses 7 and type in
q( exists( gt5 X horse(X) ) )
1amp
APCIS will translate the question and enter to Prolog the following query
goo(( s02( horse(X) ) s02( num( X gt5 )) ))
Note that the term number(slml 6) in the database and the term num(X gt S) in the query are
different predicates and this difference is exactly where the power of the clause num(X N)
defined in APCIS comes from When the clause num(X N) in APCIS is activated it will search
through the database to see if there is any term of the form number(X I) whose first argument
matches the first argument of num(X Y) in the query It a match is found the second arguments
of both num(X Y) in the query and number(ltI) in the database will be passed to cnum in
APCIS
The job of cnum is to compare the numerical messages carried by the second
argument or the term rlum(X Y) in the query and the second argument of the term rlumber(X I)
in the database to see if they match with each other according to the rules defined in cnum
While there are 25 rules for such matching purposes the idea is simple
Imagine that the second argument Y of the term num(X Y) in the query
and the second argument I of the term num()( I) in the database each occupies a
place in an integer line (Le the integer line in mathematics) To have a match
the domain covered by Y should contain the domain covered by L
As an example the answer to the above query is positive since the domain of gt5
contains the domain or 6
Before closing this section we will bring out a speciaJ translation aspect of expressions
involving numbers by an example We first type to APCIS the Collowing expressions in assertion
mode
1 aU(X all(Y father(X Y) amp number(Y gt6) ==gt has_manY3hildren(X) ))
2 exists(X exists( 12 Y Cather(X Y) ) )
11
After going tbrougb all tbe translation steps tbe Collowing two expressions will be entered to tbe
database
I
bas_many_cbildren( Xl ) shy
Cather( Xl X2 )
num( X2 gt6 )
2
Catber( sk m1 sk n2 )
number( skn2 12 )
lotice that whenev(gtr a term with Cunctor number appears at the rigbt-band side oC a Prolog
clause its Cunctor will be cbanged to num automatically This treatment will greatly cnbance tbe
inference power of the clause sbown in l above For instance iC we now ask tbe question
q( exists( X bas_many_children(X) ) )
The right hand side oC the clause l will match the two terms in 2 and tbe query succeeds
52 Bel and cael
A special feature of APe is tbat all predicates tbat express relations = = gt
gt= lt and lt= can be expressed explicitly using infix notations as relational statements
called selectors To handle selectors we defined Bel in APCIS
Every expression involving selectors will undergo different translations in assertion mode
and query mode For example the assertion
a( exists( [X Y] box (X) amp box(Y) amp (weigh t(X) gt weight(Y) ) ) )
will be translated into the following three terms and entered to tbe database
box( skml )
box( skm2 )
18
weight( skm 1 ) gt weight( skm2 )
Now it we want to ask Is it true that there exists two boxes of different weights and type in
q( exists( [X Yl box(X) amp box(Y) amp ( weight(X) = weight(Y) ) ) )
The question will be transformed to the following query and entered to Prolog
goo(( so( box(XI) ) s02( box(X2) ) so2( sel( weightXI) = weight(X2) )) ))
Note that the selector in the above query is surrounded by the functor set When any clause or
8el in APCIS is activated it will search through the database to see it there is any selector whose
two arguments (left and right side or any selector symbol) match the two arguments of the
selector in the query At the same time 8el will check iC the selector symbols (may be different) or
the two different selectors (one in the query and one in the database) satisfy the rules defined in
sel There are 12 matching rules defined in sel All oC them ~re straightforward and will not be
discussed here An example will be enough to explain how 8el works
Consider the execution of the above transformed query The first two terms in the query
are satisfied by the first two terms in the database and Xl and X2 are instantiated to skml and
skm2 respectively The third term of the query will be passed to eel (of APCIS) which finds a
match on each side of the two selectors (one in the query and one in the database) At the same
time the two different selector symbols gt and = are found to satisfy one of the rules in
8el As a result the query succeeds
To enhance the inference power of clauses involving selectors all the selectors appearing
on the rightmiddothand side oC any clause will be surrounded by a functor set The idea is similar to
that in the last part of the previous section
c8el is exactly the same as 8el functionally It provides a convenient way to compare
selectors when dis is being executed
19
8 Printing Result
Whenever a goal is successfully executed APCIS will not only response with a yes but
also print out the matched terms or clauses in the database This is made possible by the built-in
function bagor and the two predicates wout and prt defined in APCIS
7 Summary
In this paper a description of a deductive inference system called APCIS (Annotated
Predicate Calculus Inference System) has been provided APCIS is able to carry out inferences
from expressions involving numerical quantifiers selectors disjunctions of non-negated terms
negated terms disjunctions of negated terms equivalences and exceptions It is also able to count
the numbers of occurrence of a given simple term or a conjunction of terms
The main idea of APCIS is that each input APC expression is first passed to a
preprocessor ( ie APC translator ) which dissolves and transforms each APC expression into
Prolog expression(s) which will then be loaded to Prolog system The user bas to specify whether
each input expression is to be entered as an assertion or as a query by invoking either assertion
mode or query mode respectively Each assertion or query will undergo different transformations in
the preprocessor The different treatment of assertion or query not only allows a full uS1ge of the
Prolog inference mechanism but also makes possible a higher level of inexact pattern matching
exemplified by the examples in Section 51 and Section 52 where the four predicates num
cnum sel and csel are discussed This higher level of pattern matching increases the inference
power of APCIS greatly
The design of contradiction and the treatment of the disjunction of non-negated terms
allow APCIS to accept non-Horn clauses and to carry out inference from them This feature
makes APCIS more general than Prolog
20
While APCIS performs very well in many sets of arguments provided by the author it is
still too early to jump to conclusion that it can perform equally well in all types of problems In
any event the expressiveness of APC has greatly been retained in the present version of APCIS
and moreover some design ideas or APCIS mentioned in this paper are not restricted to APCIS
- they may be carried over to learning programs with narrower scopes
21
References
[1] W F Clocksin and C S Mellish Programming In Prolog Springermiddot Verlag Berlin Hpoundidelberg 1981
[2] R S Michalski A Theory and Methodology of Inductive Learning Chpt 4 Machine L earning Tioga Publishing Co Palo Alto CaliJornia 1989
[3] K-E Pua Translating Annotated Predicate Calculu8 to Prolog ISG Report 84middot1 UlUCDCSmiddotFmiddot918 University oj Illinois Urbana IL June 1984
22
Appendix A
APCIS Users Manual
1 Get Started
Users are urged to follow the steps depicted below
1 Get the PROLOG interpreter by typing
alias prolog mntb2sammutsammutprologprolog (Vax A)
or
alias prolog mntb2sammutsammutbinprolog (Vax B)
2 Load apc and infer by typing
prolog apc infer
When large APC expressions are expected we can increase the stlck by typingI
prolog -snnnn ape infer
where ns denote the number of stacks in decimal
3 When the wording LSW - PROLOG appears on the terminal we are reldy to interact
with APCIS The four modes by which we can invoke APCIS are summarized below
a Assert ion-Translation Mode
ta(X)
b Query-Translation Mode
tq(X)
c Assertion Mode
a(X
d Query Mode
q(X)
23
where Xs are APC expressions
2 Notations Used in APCIS
Below is a summary or notations used in APCIS
a Logical operators
amp
v
==gt
lt=gt
-
negation
conjunction
disjunction
implication
equivalence
exception
b Binary relation symbols in selectors
-
=
gt=
lt=
gt
lt
equal
not equal
greater or equal
smaller or equ al
greater
smaller
c Relational operators in numerical quantifiers
lt less than
lt= less than or equal
gt greater than
gt= greater than or equal
d BinlTY operator in numerical quantifier
range
e Universal quantifier
all(X p(X))
f Existential quantifier
exists(X p(X))
g Numerical quantifier
exists(I X p(X))
where p(X) is a formula
where X is a variable or a Jist of variables or the
form [HI~rj and p(X) a formula
where I repersents expression involving integer(s)
and operator(s) in c or d above and p(X) a formula
25
Appendix B
APCIS Program Listings
------------------------------- Program Name APCIS - Part 1 APC Translator
-------------------------------
op(3OO fx -)1
op(500 xfy amp)
oPt 500 xfy v)
op(600 xfx )
op(700 fx [gt= lt= gt lt ]) op(400 xfy [= gt= lt= gt lt ])1 op(900 xfy gt lt=gt -])1
steps(X Xg) shy
numbervars(X 1 J Step 1 change variables to iis
rmimp(X X) Step 2 conv(X X3) Step 3
rewrite(X3 X4) Step 4
negin(X4 X5) Step 5
dropexist(X5 X6 1]) Step 6
dropall(X6 X7) Step 7
distrib(X7 X8) Step 8 clausiCy(X8 X9 [J) Step 9
ta(X) shysteps(X Xg)
(( Xg = II nl
print( yes it is always true) )
( nl nl printcl(X9))) Step 10a
tq(X) shy
steps(X Xg)
prques(Xg)
28
Step 2 Removing implic3tions amp Transforming exceptions and equiv3lences
rmimpl( P - Q (PI lt=gt (QI) ) amp ((PI) lt=gt QI) ) -
rmimpl(P PI) rmimpl(Q QI)
rmimplnp) lt=gt Q (PI lt=gt -(QI)) amp nPI) lt=gt QI) ) - 1
rmimpl(P PI) rmimpJ(Q QI)
rmimpJ(P lt-gt -(Q) (PI lt=gt -(QI)) amp nPI) lt=gt QI) ) -
rmimpl(P PI) rmimpl(Q QI)
rmimpl( P lt=gt Q PI lt=gt QI ) - I
rmimpl(P PI) rmimpl(Q QI)
rmimpl( P ==gt Q -(PI) v QI ) - I
rmimpl(P PI) rmimpl(Q QI)
rmimpl( all(X P) aI(X PI) ) - 1
rmimpl(P PI)
rmimpl( exists(X P) exists(X PI) ) -
rmimpl(P PI)
rmimpl( exists(I X P) exists(I X PI) ) -
rmimpl(P PI)
rmimpl( P amp Q PI amp Ql ) -
rmimpl(P PI) rmimpl(Q Ql)
rmimpl( P v Q PI v QI ) -
rmimpl(P PI) rmimpl(Q QI)
rmimpl( -(p) -(PI) ) - I
rmimpl(p PI)
rmimpl( P P )
St~p 3 Converting numerical amp distinctive quantifiers
L Numerical quantifiers
examples of input forms
1 exists(gt= i X pIX)) where i is an integer
2 exists(i X pIX)) where i is an integer
3 exists(i j X pIX)) where i j are integers and iltj
4 exists(il v i2 X pIX)) where is are integers
examples of output forms of this step
1 exists(X pIX) amp number(X gt= i) )
2 exists(X pIX) amp number(X i) ) 3 exists(X pIX) amp number(X ij) ) 4 exists(X pIX) amp number(X il v i2) )
II Distinctive quantifiers
27
example or input Corm
exists([XYL p(X Y))
example or output Corm or this step
exists(X exists(Y p(XY)) )
conv(P lt=gt Q PI lt=gt QI) - 1
conv(P PI) conv(Q QI)
conv(al1(X P) all(X PI)) -
conv(P PI)
conv(exists(HIT] P) R ) - conv(P PI) convert distinctive quantifier
convtdis(exists([HIT]PI) R)
conv( exists(I X P) exists(X PIamp number(X I) )) -
conv(P PI) convert numerical quantifier
conv(exists(X P) exists(X PI)) - 1
conv(P Pl)
conv(P amp Q PI amp QI) - 1
conv(P PI) conv(Q QI)
conv(P v Q PI v QI) - t conv(P PI) conv(Q QI)
convC(P) -(PI)) -
conv(P PI)
conv(P Pl
convtdis(existsl[XL P) exists(X P)) - atomic(X) convtdis(exists[XIYj Pl exists(X R)) shy
convtdis(exists(Y P) R)
Step 4 Rewriting compound predicates andor compound selectors
Outputs are smiple predicates andor simple selectors
rewrite(P lt=gt Q PI lt=gt QI) - t rewrite(P PI) rewrite(Q QI)
rewrite(all(X Pl all(X PI)) - 1 rewrite(P PI)
rewriteexists(X P) exists(X PI)) - I rewriteP PI)
rewrite(P amp Q PI amp QI) - rewrite(P P 1) rewrite( Q Q 1
rewrite(P v Q PI v QI) - 1
rewrite(P PI) rewrite(Q QI)
rewriteC(P) -(PI)) - I
28
rewrite(P PI) rewrite(F(A B) R) -
rewrite(A AI) rewrite(B BI) re(F(AI BI) R)
rewrite(F(A) R) -
rewrite(A AI) re(F(AI) H)
rewrite(F(A B C) R) -
rewrite(A AI) rewrite(B BI) rewrite(C CI) re(F(AI BI CI) R)
rewrite(F(A B C D) R) -
rewrite(A AI) rewrite(B Btl rewrite(C CI) rewrite(D DI) rc(F(AI BI CI Dl) H)
rewrite(PP)
re(F(A B v el (RI v R2) -
re(F(A Bl RIl re(F(A C) R2) reF(A B amp cl (RI amp R2)) -
re(F(A B) RI) re(F(A e) R2) re(F(A amp B C) (Rl amp R2)) -
re(F(A e) R 1) re(F(B C) R 2) re(F( v B el (R I v R2)) -
re(F(A el R I) reFB el R2) re(F(A amp Bl (R I amp R2)) -
re(F(A RI) re(F(BJH2) re(F(A v B) (R 1 v R2)) -
re(F(A) RI) re(F(B) R2)
re(F(A vB c Dl (RI v R2) -
re(F(A C D) RI) re(F(B C D) R2) re(F(A amp B C D) (RI amp R2)) -
re(F(A C D) Rll re(F(B C D) R2) re(F(A B v C D) (HI v R2)) -
re(F(A B D) RI) re(F(A C D) R2) re(F(A B amp C D) (HI amp R2)) -
re(F(A B D) RI) re(F(A C D) R2) re(F(A B C v D) (RI v R2)) -
re(F(A B C) R I) reF(A B D) R2) re(F(A B C amp D) (RI amp R2)) -
29
re(F(A B C) RI) re(F(A B D) RZ)
re(F(A v B e D E) (R I v R2)) -
re(F(A e D E) R I) re(F(B e D El R2) re(F(A amp B e D E) (RI amp RZ)) -
re(F(A e D El R 1) re(F(B e D E) R2) re(F(A B v e D E) (R I v R2)) -
re(F(A B D E) RI) re(F(A e D E) R2)
re(F(A B amp e D E) (RI amp R2)) -
re(F(A B D El RI) re(F(A e D E) RZ) re(F(A B e v D E) (R I v R2)) -
re(F(A B e El R 1) re(F(A B D E) RZ) re(F(A B e amp D E) (RI amp RZ)) -
re(F(A B e E) R I) re(F(A B D E) RZ)
re(F(A B e D vEl (RI v RZ)) - l
rc(F(A B C D) RI) re(F(A n e El RZ) re(F(A B e D amp El (RI amp RZ)) - ~
re(F(A B e D) RI) re(F(A B e El RZ)
re((A = B) (A = B)l-
re((A = Bl (A = 8)) -
retIA gt= BI (A gt= B)) -
re((A lt= B) (A lt= B)) -
re((A gt B) (A gt B))-
re((A lt Bl (A lt Bl)- re(A A)
Step) Bringing n(gation inwards
Degin(-(P) PI) - neg(P Pl)
negin(P lt=gt Q PI lt=gt Ql) - ~
negin(P PI) negiD(Q QI)
Degin(aU(X P) all(X PI)) - Degin(P PI) negin(exists(X P) exists(X PI))- negin(P PI) negin(P amp Q PI amp Ql) - Degin(P PI) negin(Q Ql)
Degin(P v Q PI v QI) - Degin(P PI) negin(Q QI) negin(P Pl
neg(-(P) PI) - negin(P PI)
neg(all(X P) exists(X PI)) - neg(P PI)
30
neg(exists(X P) all(X PI)) - neg(P PI)
neg(P amp Q PI v QI) - neg(P PI) neg(Q Ql)
neg(P v Q PI amp QI) - neg(P PI) neg(Q QI)
neg(P -(PH
Step 6 Dropping existnetial quanti6ers
dropexist(P lt=gt Q PI lt=gt QI Elerns) - dropexist(P PI Elerns) dropexist(Q QI Elerns)
dropexist(alJ(X P) all(XPI) Elerns)
dropexist(P PI [XIElernsJ)
dropexist(exists(X P amp nurnber(X Yraquo P2 Elerns) -
genfun(skn Newg) Fun = [NewgIElerns]
subst(FuD X P amp Dumber(X Y) PI)
dropexist(Pl P2 Elerns)
dropexist(exists(X P) PZ Elerns) -
genfun(skrn Newf) Fun = [NewfIElernsJ
subst(Fun X p PI)
dropex ist(P 1 P~ Elerns)
dropexist(P v Q PI v QI Elerns) - ~
dropexist(P PI Elerns) dropexist(Q Ql Elerns)
dropexist(P amp Q PI amp QI Elerns) - 1
dropexist(P Pl Elerns) dropexist(Q QI Elerns)
dropexist(P P _)
gen fun(R oot Newn arne) shy
getnurn(Root Nurn)
narne(Root Rootlist)
append(Rootlist[Nurnj Narnelist)
concat(Narnelist Newnarne)
getnurn(Root Nurn) shy
retract(currentnurn(Root Nurn 1 raquo
Nurn is Nurni + 1
asserta(currentnurn(Root Nurn))
getnurn(Root 1) - asserta(currentnurn(Root 1))
subst(New Old Val Val) - var(Val)
subst(New Old Old New) - 1 substNew Old Val Val) - atornic(Val)
31
subst(New Old Val Newval) shy
runctor(Val F N)
CUDctor(Newval F N)
subst_args(N New Old Val Newval)
subst_args(O J J - J J
subst_args(N New Old Val NewVal) shy
arg(N Val OldArg)
arg(N NewVal NewArg)
subst(New Old OldArg NewArg)
NI is N - I
subst_args(Nl New Old Val NewVal)
append([J L L) -
append([XILl] L2 [XIL3]) - append(Ll L2 L3)
Step - Dropping universal quantifiers
dropall(P lt=gt Q PI lt=gt QI)-
dropall(P PI) dropall(Q QI)
dropall(all(X P) PI) - ~ dropall(P PI)
dropall(P amp Q PI amp QI) -
dropall(P PI) dropall(Q QI)
dropall(P v Q PI v QI) -
dropall(P PI) dropall(Q QI)
dropall(P P)
Step 8 Distributing conjunctions over disjunctions
distrib(P lt=gt Q PI lt=gt Ql) - t distrib(P PI) distrib(Q QI)
distrib(P v Q R) -
distrib(P PI) distrib(Q QI)
distributing(PI v QI R)
distrib(P it Q PI it QI) -
distrib(P PI) distrib( Q QI)
distrib(P P)
distributing((P amp Q) v R PI amp QI) -
distrib(P v R PI) distrib(Q v R Ql)
32
distributing(P v (Q amp R) PI amp Ql) -
distrib(P v Q PI) distrib(P v R Ql)
distributing(P P)
Step 9 Packing each conjunction into clauses
c1ausify(P amp Q CI C2) -
clausiCy(P CI C3) c1ausify(Q C3 C2)
cbusiCy(P [d(A B)ICs] Cs) shy
inclause(P A [j B [I) 1
c1ausiry( C C)
inclause(P v Q A AI B B1) -
inc1ause(P A2 AI B2 Bl)
inclause(Q A A2 B B2)
inclausenp) A A B1 B) -
notin(P A) putin(P B B1)
inclause(P AI A B B) shy
notin(P Bl putin(P A AI)
notin(X [XU) - fail
notin(X [JLj) - notin(X L)
notin(X 1])
putin(X II [X]) - 1
putin(X [XILJ L) -
putin(X [YILJ [YILl]) - putin(X L Ll)
Step 1Oa Printing clauses
printcl([]) - nl nl
printcl(c1(AB)ICsj) - printcl(A Bl nl printcl(Cs)
printcl(L II) - printdis(IL) prinr)middot
printclHl L) - prin(contradiction(() printconl(rL)
print()) - ) printconj(rL) prinr )
printcl(Ll L2) shy
printdis(ILl) print( - ) printconj(rL2) prin()
printdis(S[Lj) - printcbar(SL)
33
printdis(S[LILs]) - printchu(SL) prin( v) printdis(SLs)
printconl(S[LI) - printchar(SL)
printconl(S[LILs]) - printchar(SL) prin( ) printconl(SLs)
printconj(S[L]) - tab(3) printchar(SL)
prin tconj( S [L IL sl) shy
tab(3) printchar(SL) print( ) printconj(SLs)
printchar(SP) shy
atomic(P)
name(P L)
L = [IT]
concat([XIT NewP)
prin(~ewP)
printchar(SP) shy
atomic(P)
prin(P)
printchar(SA lt= gt B) -
prin((l clausify(A AI [j) pl(eAl) prin())
print lt=gt )
prin(() cbusify(B Bl [I) pJ(eBl) prine))middot
printchar(rnumber(X N)) shy
prin(num() printchar(rx) prin( )
printchar(rN) prinC))
printchar(rF(A B)) shy
seJec(F(A B))
prinCsel() printchar(rA)
prin( F ) printchar(rB) prinC))
printchar(SF(A B)) shy
( selec(F(A B)) F = infix )
printchar(SA) prin( F ) printchar(SB)
printchar(SF(A)) shy
(F= prefix gt= F= prefix lt= F= prefixgt F= prefix lt )
prin(F ) printcbar(SA)
printchar(SP) shy
functor(P F MaxN)
prin(F ()
Nl is MaxN - 1
putout(S N 1 P MaxN)
34
prin())
putout(S 0 P MaxN) -
arg(~laxN P Argu)
prin tchar(SArgu)
putout(S N p MaxN) shy
Nt is MaxN - N arg(NI P Argu)
printcbar(SArgu )
prin( )
N2 is N - 1
putout(S N2 P MaxN)
selec(FA B)) shy
( F= infix = F= infix f= F= infix gt=
F= infix gt F= infix lt= F= infix lt )
35
----------------------------------Program Name APClS - Part 2 Inference Mechanism ---------------------------------- a(X) shy
steps(X X9)
(( X9 =[] nl
print( yes it is always true) )
( X9 =[cI(IJ[])] nl
print( no it is always false) )
( nl nl printel(X9) Step 1Oa
tell(temp_file) printel(X9) e1ose(temp_file) consult(temp_6Ie) ))
q(X) shy
asserta( in pt(X))
steps(X X9)
(( X9 = [] print(middot~H~~middot~t~)
print(THE AiSWER IS YES)
print( ilgIQlQl(~) )
( X9 = [e1([j [j)] Pr1nt ( OJ fi(i I~ iii Ij)middot(i)(i) fiyenQ)riiio(i)(ij)(i)fj)fiyen1li1il1li1il)__ gtw~ __~_~ _~~_ ~_-=~
print(THE ANSWER IS NO ) print() )
( teI1(temp_6Ie)
prques(X9) Step 1Ob
close(temp_file)
nl print(Let me think about it) nl
consult(temp_6Ie) ))
retrac t( in pt(X))
Step lOb Printing question
prques(lcl(A 8)1) - prin(goo(() pl(qA 8) print()))
prques([c1(A 8HCs]) - prin(goo(() pl(qA 8) print() pl(q Cs)
pl(e [c1(A 8)]) - pl(eA 8)
pl(q [c1(A 8)]) - pl(qA 8) print()))
pl(S [e1(A B)ICs]) - pl(SA B) prin( ) pl(S Cs)
38
pl(q [j L) - prin(c1ause(contradiction(() pcont(qL) prin())_))
pl(S [I L)- prin(so2(contradidion(() pcont(SL) print))))middot
pl(S [L] []) - prin(so2() pcbar(SL) prin())
pl(S L [J)- prinsol() plett(SL) print))
pl(S [L] LI) - prin(condi(() pchar(cL)
prin(() pcont(S Ll) prine))))
pl(S L Ll)- prin(c1ause() plert(cL)
prin(() pcont(S Ll) prine)))
plert(S[LJ) - pchar(SL)
plert(SjLILsj) - pcbar(SL) print v) pleCt(SLs)
pcont(S[L]) - pchar(SL)
pcont(S[LILsj) - pcbar(SL) prinr ) pcont(SLs)
pcbar(SP) shy
atomic(P)
name(PL)
( L = [IT] L = [5 k miT] L = [5 k niT] )
concat[XITj NewP)
prin(0JewP)
pchar(SP) shy
atomic(P)
prin(P) pchar(SA lt=gt B) -
prin(() dausify(A AI []) pl(eAI) prin())
prinr lt=gt ) prin(() dausify(B BI ]) pl(eB) print))
pchar(Snumber(X N)) shy
prin(num() pchar(SX) prin()
pchar(SN) prinr))
pcbar(SM N) - prin(M N)
pcbar(cF(A B)) shy
selec(F(A Braquo
pcbar(cA)
prine F ) pchar(cB) pchar(SF(A B)) shy
selec(F(A B))
prin(sel() pchar(SA)
print F ) pchar(SB) print)) I
31
pc har(SF(A)) shy
( F= prefix gt= F= prefix lt= F= prefixgt F= prefix lt )
prin(F ) pchar(SA)
pchar(SP)shy
runctor(P F MaxN)
prin(F ()
011 is MaxN - 1 pout(SNl P MaxN)
print) )
pout(S 0 P M3xN) - 1
arg(~bxN P Argu)
pchlr(SArgu )
pout(S N P MaxN shy
Nl is MaxN - N
arg(Nl P Argu)
pchar(SArgu
prin( )
N2 is N - 1
pout(S N2 P ~13xN)
Comparing numbers in numerical quantifiers
num(XN) shy
number(X I)
cnum(N 1) ~
cnumlaquo=01 lt=I- N gt=I
cnumlaquo=J lt I) - N gt=1-1
cnumlaquo=NIJ) - N gt=J 1
cnumlaquo=N J)- integer(I) N gt=I~
cnum(gt=N gt=1) - N lt=1
cnum(gt=N gt I) - N lt=1+ 1 cnum(gt=NIJ) - N lt=1
cnum(gt=N lt=1)- N lt=1
cnum(gt=N lt I) - N lt=1 L cnum(gt=N 1)- integer(I) N lt=1
cnum( lt N lt 1)- N gt=1 L
38
cnum( lt N lt=1) - N gt I cnum( lt NLJ) - N gt J
cnum( lt N 1)- integer(I) N gt 1
cnum(gt N gt I) - N lt=1 cnumlgt i gt=1) - N lt I
cnum(gt N lt=1) - N lt=0
cnum(gt N lt I) - N lt=0
cnum(gt iIJ) - N lt I cnum(gt N 1)- integer(I) N lt I
cnum(~LN lt=1) - M=I N gt= I l
cnum(~LN lt I) - M=l N gt= I-I
cnum(~LNLJ) - M lt =1 N gt = J
cnum(~1N 1)- integer(I) M lt= I N gt= I
cnum(- N) - integer(N)
Comparing selectors
sel(X = Y) shyX= Y
sel(X I=Y) shy(X I=Y X lt Y Xgt Y)
sel(X gt Y) shyXgt Y
sel(X lt Y) shyXlt Y
selX gt=Y) shy(X gt=Y X= Y Xgt Y)
se(X lt=Y) shy
(X lt=Y
X= Y
X lt Y)
csel(infix = infix =)
39
csel(infix = infix = csel(infix = infix gt)
csel(infix = infix lt) csel(infix gt infix gt) cseJ(infix lt infix lt) csel(infix gt= infix gt=) csel(infix gt= infix gt csel(infix gt= infix =)
csellinfix lt= infix lt=) csel(infix lt= infix lt) csel(infix lt= infix =)
Finding solutions
sol(X v Y) -
(( notetra(X) eon(X) ( sol(Y) )
( c1ause(P v Q R) not(cketra(P v Q))
dis(P v Q X v Y R) ~ )
( A lt=gt B equival(A lt=gt B X v Y) ~ I) sol(X) - ~ notetra(X) eon(X)
so~(X) - notetra(X)
( con (X)
( clause(P v Q R) not(ekctra(P v Q)) dis(P v Q X R) I)
cketra(P v Q) -
eketra(P) eketra(Q) eketra(F(I J)) shy
selec(F(I J))
c1ause(contradiction(sel(F(IJ))) _I
eketra(number(W I)) -
clause(cootradietion(num(Wl)) - eketr(P) shy
clause(contradiction(P) - 1
notctra(P) shy
not( e lause( con tradiction(P) _))
40
Searching (or disjunctions
dis(P v Q X v Y R) - dis(P X v Y R)
dis(Q X v Y R) con(R)
dis(P v Q X R) -
dis(P X R) dis(Q X R) con(R
dis(P X v Y R) - clause(contradicton(Pl J 1
dis(F(I J) sel(G(I J)) v Y R) - csel(G Fl dis(number(WI) num(W N v Y R) - cnum(N I)
dis(P P v Y R) -
dis(P X v Y R) - dis(P Y R)
dis(F(I J) seJ(G(IJ)) R) - csel(G F)
dis(number(WI) num(WN) R) - cnum(N I) dis(P P R) - 1
dis(FJ J X R) shy
( ckctra(F(IJ) cbeckeq(seJ(F(IJ))) )
dis(number(W Il X R) - ( ckctra(number(WI)) cbeckeq(num(WI)) )
dis(P X R) shy( ckctra(P) cbeckeq(P) ) 1
cbeckeq(P) shy
(( A lt=gt so2(contradiction(P))
bagof(A A [jj) ) ( so2(contradiction(P)) lt=gt B
bagof(B B Uj) ))
ckeq(A) shy
( so2(A) lt=gt B B lt=gt so2(A) ) bagof(B B UJ)
con((P Q)) -
clause(P R) con(R) con(Q) con(true) -
con(contradiction(P)) - clause(contradiction(P) J
con(cause(X Y)) - cause(X Y)
con(sel(X)) - sel(X)
con(num(X Y)) - num(X Y) con(P)- (( dause(P R) (con(R) ckeq(R)))
colJectin(P) )
collectin(P) shy
bagof(S (c1ause(P S) S = true) [L LIJ )
mkcon(L Ll L)
bagor(l (L2 ) UJ) L
mkcon((A AI) (B B1) (sol(A v B) e D)) -
mkcon(A B1 e) mkcon(A1 (B Bl) D)
mkcon(A (B B1) (sol(A v B) e)) -
mkcon(A Bl e)
mkcon((A AI) B (sol(A v B) e)) middot1
mkcon(Al B e)
mkcon(A B sol(A vB))
Searching ror equivalences
equival(A lt=gt B X v Y) - 1 ( equival(A lt=gt B X) equival(A lt=gt B Y) )
equival(s02(A) lt=gt 502(B) A) - clause(B _I equival(s02(B) lt=gt 502(A) A) c1ause(B _I
Top level or inrerence mechanism
goo((s02(whatnum) P)) -
getatm(P Xl
bagor(number(X Y) ( P so2(number(X Y)) ) A )
count1(A 00 L R) nl
bagor(X P B )
count2(B L R Ll Rl) nJ print()
(( LI = 0 Rl = 0 print(THE ANSWER IS ) nl
(( Ll = Rl prin(-Jumber or ) prn(P) print(is Ll) )
( Rlgt20000 prin(Number or I prn(P) print(is LI or more) )
42
( prin(Number of ) pfn(P) print( is from Ll to Rl) )) )
( print(THE ANSWER IS NO I )) print()
goo(X) shy
(( bagof(X X L) L = [I nl print()
print(THE ANSWER IS YES) nl wout(L) print() )
( equiv(X L) nl print()
print(THE ANSWER IS YES) nl wout(L) print(-) )
( c1ause(inpt(A ==gt B) _I ( impli(A B Z) impli(B A Z) ) print(l~Hl)
printTHE ANSWER IS YES) nl print(Z) print(Hj~(fH~) ))
goo(X) print( Hg)
print(THE ANSWER IS NO ) print( lH~lH~gg9l9lmiddotmiddot~Q(gmiddot)
00 Semhing for implications in equiV3lent relations
impli( B Z) shyt-ell( z1) prin(templ() pchn(S A lt=gt B) print()) close ( zl) consult(zl) templ(Z)
unload zl Z
Searching for equivalence
equiv (X L)
(( X lt=gt Y
equ(Y YI)t bagof(Y Yl L) L = [j )
(Y lt=gt X equ(Y YI) bagof(Y Yl L) L = [J )
( X = F(New)
clause(~ew T) makeup(T Tl)
(( Tl lt=gt B
equ(B Bl) bagof(Bl Bl M) M = [j L=[Newl )
(A lt=gt TI
equ(A AI) bagof(Al AI M) M = 1] L=INewj )) ))
makeup((A B) (AI Bl)) -
makeup(A A1) makeup(B BI)
makeup(A so2(A))
equ((A B) (AI BI)) -
equ(A AI) equ(B Bl)
equ(sol(X v Y) sol(XI v Yl)) -
equ(X XI) equ(Y YI)
equ(so2(X) so2(XI)) -
equ(X XI)
equ(contradiction(X) clJuse(contradiction(X) X) ) -
equ(X X)
Counting numbers
getatm((A B) X) -
( getatm(A X) getatm(B X) )
getatm(so2(F(X)) X) -
getatm(so2(X) X) - atom(X)
countl([J L R L R) -
countl([number(X Y)IT] L R L2 R2) shy
(( Y = (gt=~) LI is L + N Rl is R + 20001 l )
( Y = (gt N) LI is L+ N+ 1 RI is R + 20002 )
(Y == laquo=~) LI is L + 1 Rl is R + N )
(Y = laquo N) LI is L + 1 RI is R+N-I)
(Y == IJ LI is L + I Rl is R + J ) ( Y == N L1 is L + N RI is R + N ))
count1(T LI R 1 L2 R2)
count2(fJ L R L R) - 1
count2([XITJ L R L2 R2) shy
name(X Xl)
(( Xl = sknj LI is L Rl is R )
44
( Xl = Iskmj L1 is L + 1 RI is R + ZOOO1) ( LI is L + I RI is R + I ))
count2(T LI RI L2 R2)
pfn((A B)) - pfn(A) prn(B)
pCn(so2(F(X))) - prin(F )
prn(so2(X)) - atom(X) prin(X ) prn (so2(X))
Printing result
wout([XlJ - prt(X) nl woutf[xIY]) - prt(X) nl nl wout(Y)
prt(e(A B)) -
prt(A) prinr 8 ) prt(ltE) prt(eA) - prt(A)
prt(c(A EJ) - prin() prt(A) prine ) prt(B) prin(T)
prt(c A) - prt(A) prt((A E)) - ~
prt(A) nl prt(E) prt(sol(X v Y)) - ~
prt(X) prinC v) prt(Y) prt(A lt=gt B) -
prt(e A) prinC lt=gt ) prt(e B) prt(sol(X)) - prt(X)
prt(so2(X)) - prt(X
prt(c1ause(X Y)) - prt(X)
prt(contradiction(X)) - prin(contradiction() prt(cX) prinr))middot prt(num(XY)) - prin(number(X Y)) prt(sel(X)) - prin(X) prt(X v Y) - prt(X) prin( v) prt(Y) prt(X) prin(X)
Handling conditional queries
condi((Y Xl) shy
assertcon(X) Y
45
retractcon(X)
condi((B A))
retractcon(A) fail
assertcon((A B)) 1
assertcon(A) assertcon(B)
assertcon(A) asserta(A)
retrac teon ((A B)) 1
retracteon(A) retractcon (B)
retraetcon(A) - retract(A)
BIBLIOGRAPHIC DATA SHEET
Report No UIUCDS-F-84-928
3 Recipients Accession No
4 T ide and Subt ltle
An Annotated Predicate Calculus Inference System (APCIS)
S Report Date
November 1984 6
7 Author(s)
Kah-Eng Pua 8 Performing Organization Rept
No
9 Performing Organization Name and Address
Department of Computer Science University of Illinois Urbana IL
10 ProjectTaskWork Unit No
11 Contract Grant No NSF DCR 84-06081 ONR N00014-82-K-0186
12 Sponsoring Organization Name and Address
National Science Foundation Washington DC
13 Type of Report amp Period Covered
14
15 Supplementary Notes
16 Abstracts
This paper describes a deductive inference system called APCIS (Annotated Predicate Calculus Inference System) APCIS is able to carry out inferences from expressions involving numerical quantifiers selectors disjunctions of non-negated terms negated terms disjunctions of negated terms equivalences and exceptions It is also able to count the numbers of occurrence of a given simple term or a conjunction of terms The design of contradiction and the treatment of the disjunction of non-negated terms allow APCIS to accept Horn clauses as well as non-Horn clauses and to carry out inferences from them This feature makes APCIS more general than Prolog
17 Key lords and Document Analysis 170 Descriptors
APC (Annotated Predicate Calculus) APCIS (Annotated Predicate Calculus Inference System) Horn Clause Numerical Quantifier Prolog Selector
17b IdentifiersOpen-Ended Terms
17c COSATI FieldGroup
18 Availability Statement 19 Security Class (This
Re~f~~IA~SIF IFf)
21 ~o of Pages
49 211 ecurity Class (This
PageUNCLASSIFIED
22 Price
FOA NTIS n (10middot70 usco-oc 40329-
Acknowledgement
I would 6rst like to thank Professor Ryszard Michalski ror his continued support and
guidance which made this work possible I would also like to express my appreciation to
Proressor Robert Stepp for his comments and suggestions to improve the quality or this report
Jeff Becker Tom Channic and Tony Nowicki helped me review this report Thanks to all or them
Finally a sepcial thank should go to Lai-Choi Cor her encouragements
Contents
1 Introduction bullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbull 1
2 Overview of APCIS bullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbull 2
21 Assertion-Translation Mode 2
22 Query-Translation Mode bullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbull 2
23 Assertion Mode bullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbull 4
24 Query ~1ode bullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbull 4
3 ~~c Translator 4
31~ Translation of Queries bullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbull 4
32 Translation of Iegated Term and Disjunction of Negated Terms bullbullbullbullbullbullbullbull t
33 Translation of Disjunction of Non-negated T~rms bullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbull 8
3A Further Transformation of Exceptions and Equivalences 9
4 Inference ~1echanism bullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbull 10
41 goo bullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbull 10
42 sol bullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbull 11
43 bull bullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbull bullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbulls02 12
44 dis and con bullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbull 12
45 countl and count2 bullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbull 14
46 equlv bullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbull 14
47 impli bullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbull 15
5 More on the Inference Mechanism bullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbull 15
(2)
51 Dum and cnum bullbullbullbullbullbullbull 15
52 sel and csel bullbullbullbullbullbullbullbullbullbullbull 17
6 Printing Result HJ
7 Summary bullbull 19
ReCerences bullbull 21
Appendix A APCIS Users Manual bullbullbullbullbull 22
Appendix B APCIS Program Listings 25
1 introduction
This report describes a deductive inrerence system called APCIS (Annotated Predicate
Calculus Inrerence System) wbich accepts expressions in Annotated Predicated Calculus (APC)
and carries out inrerence rrom them Annotated Predicate Calculus is an invention of Professor R
S Michalski It is built on the basis of First Order Predicate Calculus (FOPC) with some
additional features such as numerical quantifications compound terms selectors compound
selectors etc These reatures not only provide APC with more expressive power tban FOPC but
also make APC much closer to human language than does FOPC Details of APC and its
applications can be round in the paper A Theory and Methodology or Inductive Learning [2]
The process or translating APC to Prolog and a program implementing this process has
been discussed in [3] This report summarizes my continuing effort in developing an APC
inference system and can be considered as a folIowup of [3]
APCIS is capable or performing the following types of operations
1 Carrying out inferences from input assertions expressed in FOPC
2 Carrying out inrerences rrom input assertions expressed in APC
3 Dealing with disjunction or nonnegated terms or the (orm Al v A2 v v Am
4 Dealing with a negated term or a disjunction of negated terms or the rorms -(A) and
-(Al) v -(A2) v v -(An) respectively
5 Dealing with equivalence relations or the form A lt=gt B and exceptions or the
forms A - B or A lt=gt -(B) or -(A) lt=gt B
6 Counting the numbers or occurrence of given predicates in the database
In this report we present an overview of APCIS and a detailed description of its
translation mechanism and inrerence mechanism
2
2 Overview ot APCIS
Figure 1 shows the general structure of APCIS There are four modes by which we can
invoke APCIS Each of them will be discussed in the following sections
21 Assertion-Translation Mode
Figure 1(30) shows schematically the phases that APCIS will go through when assertionshy
translation mode is invoked To translate APC assertion into Prolog we type to Prolog system
ta(X)
where ta stands for ~translation of assertion and X is any APC expression to be translated The
input assertion will then go through an APC translator (discussed in [3]) and its result will be
printed out on the terminal Note that the translated result is not loaded back to Prolog system
22 Query-Translation Mode
Figure l(b) is the schematic diagram showing the execution process of query-translation
mode To translate APC query we type to Prolog system
tq(X)
where tq stands for ~translation of query and X is any APC expression The input query will go
through the same APC translator mentioned above but the output will be in the form of ~Prolog
question (see Slction 31) As in the assertion-translation mode the output will only be printed
out on the terminal and will not be loaded back to Prolog
The above two modes provide only translation purposes The following two modes
perform the actual infNence
3
1-------------1 1 ta (X) I 1-------------1
1 1-------------1
APe 1 I Translator 1
1-------------1 I
1-------------11 Terminal I 1-------------1
(a) Assertion-translation mode
1------------ a(X) I
1------------1 1
1 1------------1 I APe I 1 Translator 1
1------------1
i-----------I 1----------1 I temp_file 1 1 Terminal 1 1-----------1 I----------i
1
1 1-------------1 I Prolog 1 1 system 1 1------------ -I
(c) Assertion mode
Figure 1 Four modes of APCIS
1---------------1 1 tq(X) 1 1---------------1
1 1---------------1 1 A P C 1 I Translator 1
1---------------1 I
1---------------1 I Terminal 1 1---------------1
(b) Query-translation mode
1--------------1 q(X) I 1--------------1
1 1------------------1 1 asserta(inpt(Xraquo 1 1------------------1
1 1---------------1 1 A P C 1 1 Translator 1 1---------------1
I 1---------------1 i temt__file 1 1---------------1 1---------------1 1 Prolog 1 1 system 1 1---------------1
I 1---------------1 1 Terminal 1 1---------------1
I 1-------------------1 1 retract(inpt(Xraquo I I-----------------~-I
Cd) Q-uery mode
23 Assertion Mode
Figure l(c) is a schematic diagram showing how assertion mode works In this mode the
input assertion will first go through the APC translator as in assertionmiddot translation mode After
which the translated result will be printed both on the terminal and to a temporary file called
tempfile which will subsequently be loaded back to Prolog system As a result the newly
translated input assertion will become Prolog term(s or clause(s) in the database
24 Query Mode
Figure l(d) shows schematically the stages that will go through when query mode is
invoked The input query crowned by the (unctor inpt will first be stored in the database It will
then be passed to the APC translator as in query-translation mode The output of the translator
will be printed on the temporary file tempfile which will subsequently be loaded to Prolog
system Upon loading tempfiie to Prolog system (recall that tempJile contains essentially a
Prolog question) the question is executed immediately and its result will be prin ted out on the
terminal In the last stage the original input query crowned by the functor inpt will be
retracted from the database
3 APe Translator
As described in [3] there are ten steps in the APC translator and each step undertakes a
unique transformation Assertion-translation mode and assertion mode go through these steps
which have been covered in [3] and will not be discussed here
31 Translation of Queries
We will now examine the different transrormations that query-translation mode and
query mode will go through They differ Crom assertion-translation mode and assertion mode only
5
in the last step of translation
In the last step of the APe translator all input queries (ie expressions entered via
query-translation mode or query mode) are dealt with by the following six predicates prques pi
plett peont pehar and pout The task of prques pi plett and peont is to arrange each
input query in desired order whereas pehar and pout will print out each atomic formula
character by character For illustration purposes consider the following five APe expressions
1 all( X man(X) ==gt mortal(X)
2 exists( X horse(X) v dog(X) )
3 - ( exists( X horse(X) amp dog(X))
4 all( X be_shouted_at(X) amp no_response(X) == gt deaf(X) v dead(X) )
5 exists( 2 X box(X) )
H the above five APe expressions are typed to Prolog via assertion mode or assertionshy
translation mode they will be translated to the corresponding Prolog expressions
la
mortal(XI) shy
man(Xl)
2a
horse(skml) v dog(skml)
3a
contradiction(( horse(XI) dog(Xl) )) shy
horse(Xl)
dog(XI)
4a
deaf(Xl) v dead(Xl) shy
be_shouted_at(X I)
no_response(X1)
Sa
box(sknl)
number(sknl2)
The above live translated expressions ( ie la through Sa ) will be printed on the
terminal and loaded to Prolog if assertion mode is used they will be printed on the terminal but
not loaded to Prolog if assertion-translation mode is invoked
Now if the original APC expressions ( ie 1 through 5 ) are typed to Prolog via query
mode or query-translation mode the corresponding questions will be translated into the following
queries
lb
goo(( condi(( mortal(Xl) man(Xl))) ))
b
goo(( soil horse(Xl) v dog(XI)) ))
3b
goo(( c1ause( contradiction(( horse(XI) dog(Xl) )) _) ))
4b
goo(( conditt deaf(Xl) v dead(Xl) (be_shouted_at(XI) no_response(Xl)) )) ))
5b
amp00(( so2( box(XI) ) s02( num(XI 2 )) ))
The above five translated queries ( ie Ib through 5b ) will be printed on the terminal
and loaded to Prolog if query mode is used they will be printed on the terminal but not loaded to
Prolog if query-translation mode is invoked
In the above queries goo 801 and 802 each forms a part of the inference mechanism of
APCIS goo occupies the top level of the inference mechanism whereas 801 and 802 are at the
1
next level 102 will take care of the searching of simple terms and 101 will deal with the
disjunctions of non-negated terms in the database We will come back to them in Section 4
At the first glance one may feel that the above translated Queries are Quite complicated
However a closer examination will reveal that they are not so Queries lb 3b and 4b can each be
categorized as a conditional query which is a distinct feature of APCIS wherels queries 2b and
5b lre asking simple facts in the database
To handle conditional queries we consider two cases First if the queries involve a
special clause contradition we invoke the built-in function el3ule(X Y) which will look for the
desired contradiction clause in the database Second if the queries do not involve the clause
contradiction we activate a defined Prolog predicate condi to take care of the necessary
searching (To avoid confusion the reader is urged to compare expressions started with the same
number in the above three sets of example)
To handle a query which asks a simple fact we surround each disjunction of terms with
the functor sol as in the example 2b or crown each simple term with the functor 802 as in the
example 5b
32 TranslatIon of Negated Term And Disjunction of Negated Terms
One feature of APCIS is its ability to handle input expressions consisting of only negated
term or a disjunction of negated terms in the forms
or
2 -(AI) v ~(A2) v v ~(An)
To handle the above two forms a special clause with clause head contradiction is
created This special clause head has only one argument which is either a term or a set of terms
grouped together in the form
8
(AI A2 An)
The right-hand side of the clause contradiction is exactly same as the argument in the clause
head For example the above two forms involving negated terms will be translated into the
corresponding forms as follows
1 contradiction( A ) shy
A
2 contradiction(( AI A2 An )) shy
AI A2 An
The design of the clause with clause head contradiction will greatly enhance the inference power
of APCIS (see the example in Section 44)
33 Translation ot Disjunction ot Non-negated Terms
Another feature of APCIS is its ability to handle input expressions involving a
disjunction of non-negated terms in the forms
1 Al v A2 v v An
or
2 Bl amp 32 amp amp Bm ==gt Al v A2 v v An
Unlike Prolog which accepts only Horn clauses APCJS will accept Horn clauses as well
as non-Horn clauses which take the above two forms The inference from non-Horn clauses is
made possible by the two defined predicates sol lnd s02 discussed in Section 42 and Section 43
respectively (see also the example in Section 44) In the APC translator the above two forms are
transbted into the corresponding forms as follows
1 Al v A2 v v An
2 Al v A2 v v An shy
g
Bl B2 Bm
34 Futher Transformation of Exceptions and Equivalences
To provide some backgrounds for the discussion of the further transformation of
exception and equivalence relations we will lirst reproduce the three goals in the Step 2 of the
APe translator discussed in Section 32 of [31
First expressions involving implication or the form A ==gt B will be transformed to
Second expressions with exception symbol or the form A - B will be changed to the
form ( A lt=gt -(B) ) amp ( -(A) lt=gt B)
Tbird expressions with equivalence symbol of the form -(A) lt=gt B or of the form
A lt=gt -(B) will also be converted to ( A lt=gt -(B) ) amp ( -(A) lt=gt B ) since tbere are
logically identical to exception relations Also expressions with equivalence symbol of the form
A lt=gt B or -(A) lt=gt -(B) will remain the same
After the Step] of the APe translator both sides of any transformed expression with
lt = gt symbol will be treated separately as if they are two independent expressions In the
Step 10 of the APe translator each side of lt=gt will again be treated separately and
transformed into a form similar to an transformed input query (see Section 31) Two examples
are given below
1 state(on) lt=gt -( state(olJ) )
2 all( 1 bot(l) amp humid(l) - winter(I) )
They will be transformed in the Step 2 or the APe translator into
1
(state(on) lt=gt -( state(off) ) ) amp ( -( state(on) ) lt=gt state(olJ) )
2
10
( hot(l) amp humid(l lt=gt -(winter(l)) ) amp
( -( hot(l) amp humid(l)) lt=gt winter(I)
In Step la they will again be transformed to
1
so2( state(on) ) lt=gt so2( contradiction( state(oH) ) )
so2( contradiction( state(on) ) ) lt=gt so2( state(oH) )
2
( s02(hot(XI)) so2(humid(XI))) lt=gt so2( contradiction( winter(Xl ))
so2( contradiction(( bot(Xl) humid(Xl) )) ) lt= gt so2( winter(XI) )
There are two advantages in the treatment of exception and equivalence symbols in this
way First it will prevent Prolog program from going into an infinite loop which is difficult to
avoid if equivalent relation such as A lt=gt B is transformed into the logically equivalent form
( A ==gt B) amp ( B ==gt A) Second by maintaining both sides of lt=gt symbol in
query form the searching on either side caD be done more easily and efficiently since the form
is already processed and does not need any further transformation
Inference Mechanism
As mentioned at the end of Section 31 goo sol and s02 each forms a part of the
inference mechanism of APCIS with goo occupying the top level and 80) and 802 the second
level In addition to these countl count2 equlv and impll are also at the second level of the
inference mechanism We will go over all of them in the following sections
I goo
goo is essentially the starting point of the inference Whenever a translated query is
loaded to Prolog system from temp-fie goo will go through one or more of the following steps in
11
sequence
G 1 Check if the query asks for the numbers of occurrence of certain term(s) It so then
pass It to eountl and eount2 else go to G2
G2 The query will be passed down to sol or s02 (or both) to check i( any assertion in the
database can satisfy the query It the answer is positive then the query succeeds else
go to G3
G3 The query will be passed to equlv to carry out further searching It the searching is a
success then the query will be closed with a success else go to G4
G4 It the query is in the form A ==gt B then it will be passed to Impli It Impll
succeeds then done else the query will be closed with a (ailure
42 sol
801 and 802 together with dis and eon form the most complicated part of the APCIS
iorerence mechanism In this and the next section we will look at sol and s02 dis and eon will
be discussed in Section 44 We will close Section 44 with an example that illustrates the
materials presented in Section 42 through Section 44
sol is at the second level of the inference mechanism It will deal with any disjunction of
non-negated terms For any disjunction passed to it it will go through one or more of the
following steps in sequence
S1 Check if any term In the disjunction can be satisfied by any term or clause in the
database without contradiction It so then done else go to S2
S2 Pass the disjunction together with another disjunction (and its tlil) picked up from
the database to dis It dis succeeds then done else go to S3
S3 Pass the disjunction down to equlval which will check if any term in the disjunction
matches either side of any equivalence relation in the database It such a match is
found then check if the other side of the equivalence C3n be satisfied It so then done
else the goal fails
43 s02
s02 is also at the second level of the inference mechanism It will take care of all the
simple terms in the transl1ted query The following is the sequence that s02 wiII follow in
searching
S1 Check if the term passed to it caD be s3tisfied by any term or clause in the d3tabase
without contradiction It so then done else go to S2
S2 Pass the term together with a disjunction of terms (and its tail) picked up from the
database to dis If dis succeeds then done else the goal fails
44 dis and con
dis has three arguments In the first two clauses of dIs the first argument P v Q is
found in the database using the builtmiddotin functiol clause and the third argument R is the tair of
the term or the clause P v Q If P v Q is not a clause but a term R will be instantiated to trUE
The second 3rgument comes from either lIol or 802 and thus takes the form of either X v Y (a
disjunction of terms) or T (3 simple term)
All the clauses of dis together with con will perform the searching as exemplified in the
following algorithm (we will keep the notationsin this section)
01 Check if every term in P v Q is in X v Y It so then go to 03 else go to D2
02 For any term (in P v Q) which is not in X v Y or does not match T perform the
following tests
a Check if the term (in P v Q) has already been negated in the datab3Se (ie check if
the contradiction of the term exists in the d3tabase) If so then repeat D2 for other
terms not found in X v Y or not matching T else go to b
13
b Check if the contradiction of the term matches either side of any equivalence
relation in the database If such a match is found then check if the other side of the
equivalence can be satisfied If so then repeat O~ for other terms not found in X v Y
or not matching T else the goal fails
It all the terms (in P v Q) which are not in X v Y or do not match T survive either one
of the above two tests then go to 03
03 This step is essentially done by eon whose goal is to satisfy the tail R of P v Q It
con succeeds then done else the search fails
To close this section we will give an example to illustrate what we have covered In
Section 42 through Section 44
Example Assume that we already haye the following expressions in the database
horse(skml) v dog(skmI)
contradiction(( dog(XI) ))shy
dog(XI)
query goo(( soZ horse(X)) ))
This query will be passed to 802 which will check it the term horse() can be satisfied iu Step S 1
of Section 43 It is a failure So we now go to Step S2 In this step we pick up the disjunction
horse(~kml) v dog(skml) (and its tail true) in the datab3Se and pass it together with the term
horse(X) to dis We are now in Step 01 of Section 44 In this step we find that dog(skml) does
not match horse(X) So we have to go to Step 02 In Step 023 We find that the term dog(skml)
has already been negated (the second expression in the database) So we go to next step 03 Since
the tail of the disjuDction horse(skml) v dog(skml) is the atom true con is satisfied and the
query succeeds
45 countl and count2
countl and count2 are responsible for the counting of tbe numbers of occurrence of a
given simple term or a conjunction of terms They are activated by input queries in the form
q( exists( X whatnum amp P) )
where whatnum is the l~bel for activating the counting of the numbers of occurrence of P which
can either be a term or a conjunction of terms
countl will count the number of term(s) which will satisfy P and associate(s) with
numerical quantification(s Two counters are set to update the lower and upper boundary or the
scope or the numfrical quantifications encountered
The contents of the two counters are then passed to count2 which is responsible for the
counting or the following three types of term First term(s) which will satisfy P and associate(s)
with existential quantification(s Second term(s) which will satisfy P and has(have) Prolog atom
as its(thfir) argument(s) Third term(s) that will satisfy P and itself(themselves) is(are) Prolog
atom(s )
46 equiv
equlv will be activated only after sol and B02 have failed The first two goals of equlv
are similar to that of Step S3 in Section 42 and Step D2b in Section 44 The third goal or equiv
makes possible the inference on either side of any equivalent relation For example if we type the
following three expressions to Prolog in assertion mode
l all( X hot(X) amp humidX) - winter(X)
2 all( X hot(X) amp bumid(X) ==gt unpresent(X))
3 - ( exists( X winter(X) ) )
and then ask APCIS in query mode
q( cxists( X unpresent(X) ) )
15
APCIS with the aid of equlv will be able to answer yes to this query
41 lmpll
lmpll can be considered as the last attempt that APCIS would make to satisfy a
query It is activated only after equlv has failed It will first check if the query is conditional If
so it will convert the implication symbol to equivalence symbol and search if such an equivalent
relation can be found in the database If so a success Otherwise a failure
5 More on the Inference Mechanism
Having looked at all the subparts at the top two levels of the inference mechanism we
are ready to look at other subparts at lower levels
51 num and cnum
One distinct fe3ture or APCIS is its ability to deal with numerical quantifications As
mentioned in Section 31 input queries and assertions will undergo different transformations in
the last step (Step 10) of translation This also holds true for expressions involving numerical
quantifications Consider the following expression
exists( 6 X horse(X) )
If it is entered to Prolog via assertion mode we will after going through all the steps of
translation have the rollowing entered to the database
horse(sk n I
number(sknl6)
Now if we want to ask Are there more than five horses 7 and type in
q( exists( gt5 X horse(X) ) )
1amp
APCIS will translate the question and enter to Prolog the following query
goo(( s02( horse(X) ) s02( num( X gt5 )) ))
Note that the term number(slml 6) in the database and the term num(X gt S) in the query are
different predicates and this difference is exactly where the power of the clause num(X N)
defined in APCIS comes from When the clause num(X N) in APCIS is activated it will search
through the database to see if there is any term of the form number(X I) whose first argument
matches the first argument of num(X Y) in the query It a match is found the second arguments
of both num(X Y) in the query and number(ltI) in the database will be passed to cnum in
APCIS
The job of cnum is to compare the numerical messages carried by the second
argument or the term rlum(X Y) in the query and the second argument of the term rlumber(X I)
in the database to see if they match with each other according to the rules defined in cnum
While there are 25 rules for such matching purposes the idea is simple
Imagine that the second argument Y of the term num(X Y) in the query
and the second argument I of the term num()( I) in the database each occupies a
place in an integer line (Le the integer line in mathematics) To have a match
the domain covered by Y should contain the domain covered by L
As an example the answer to the above query is positive since the domain of gt5
contains the domain or 6
Before closing this section we will bring out a speciaJ translation aspect of expressions
involving numbers by an example We first type to APCIS the Collowing expressions in assertion
mode
1 aU(X all(Y father(X Y) amp number(Y gt6) ==gt has_manY3hildren(X) ))
2 exists(X exists( 12 Y Cather(X Y) ) )
11
After going tbrougb all tbe translation steps tbe Collowing two expressions will be entered to tbe
database
I
bas_many_cbildren( Xl ) shy
Cather( Xl X2 )
num( X2 gt6 )
2
Catber( sk m1 sk n2 )
number( skn2 12 )
lotice that whenev(gtr a term with Cunctor number appears at the rigbt-band side oC a Prolog
clause its Cunctor will be cbanged to num automatically This treatment will greatly cnbance tbe
inference power of the clause sbown in l above For instance iC we now ask tbe question
q( exists( X bas_many_children(X) ) )
The right hand side oC the clause l will match the two terms in 2 and tbe query succeeds
52 Bel and cael
A special feature of APe is tbat all predicates tbat express relations = = gt
gt= lt and lt= can be expressed explicitly using infix notations as relational statements
called selectors To handle selectors we defined Bel in APCIS
Every expression involving selectors will undergo different translations in assertion mode
and query mode For example the assertion
a( exists( [X Y] box (X) amp box(Y) amp (weigh t(X) gt weight(Y) ) ) )
will be translated into the following three terms and entered to tbe database
box( skml )
box( skm2 )
18
weight( skm 1 ) gt weight( skm2 )
Now it we want to ask Is it true that there exists two boxes of different weights and type in
q( exists( [X Yl box(X) amp box(Y) amp ( weight(X) = weight(Y) ) ) )
The question will be transformed to the following query and entered to Prolog
goo(( so( box(XI) ) s02( box(X2) ) so2( sel( weightXI) = weight(X2) )) ))
Note that the selector in the above query is surrounded by the functor set When any clause or
8el in APCIS is activated it will search through the database to see it there is any selector whose
two arguments (left and right side or any selector symbol) match the two arguments of the
selector in the query At the same time 8el will check iC the selector symbols (may be different) or
the two different selectors (one in the query and one in the database) satisfy the rules defined in
sel There are 12 matching rules defined in sel All oC them ~re straightforward and will not be
discussed here An example will be enough to explain how 8el works
Consider the execution of the above transformed query The first two terms in the query
are satisfied by the first two terms in the database and Xl and X2 are instantiated to skml and
skm2 respectively The third term of the query will be passed to eel (of APCIS) which finds a
match on each side of the two selectors (one in the query and one in the database) At the same
time the two different selector symbols gt and = are found to satisfy one of the rules in
8el As a result the query succeeds
To enhance the inference power of clauses involving selectors all the selectors appearing
on the rightmiddothand side oC any clause will be surrounded by a functor set The idea is similar to
that in the last part of the previous section
c8el is exactly the same as 8el functionally It provides a convenient way to compare
selectors when dis is being executed
19
8 Printing Result
Whenever a goal is successfully executed APCIS will not only response with a yes but
also print out the matched terms or clauses in the database This is made possible by the built-in
function bagor and the two predicates wout and prt defined in APCIS
7 Summary
In this paper a description of a deductive inference system called APCIS (Annotated
Predicate Calculus Inference System) has been provided APCIS is able to carry out inferences
from expressions involving numerical quantifiers selectors disjunctions of non-negated terms
negated terms disjunctions of negated terms equivalences and exceptions It is also able to count
the numbers of occurrence of a given simple term or a conjunction of terms
The main idea of APCIS is that each input APC expression is first passed to a
preprocessor ( ie APC translator ) which dissolves and transforms each APC expression into
Prolog expression(s) which will then be loaded to Prolog system The user bas to specify whether
each input expression is to be entered as an assertion or as a query by invoking either assertion
mode or query mode respectively Each assertion or query will undergo different transformations in
the preprocessor The different treatment of assertion or query not only allows a full uS1ge of the
Prolog inference mechanism but also makes possible a higher level of inexact pattern matching
exemplified by the examples in Section 51 and Section 52 where the four predicates num
cnum sel and csel are discussed This higher level of pattern matching increases the inference
power of APCIS greatly
The design of contradiction and the treatment of the disjunction of non-negated terms
allow APCIS to accept non-Horn clauses and to carry out inference from them This feature
makes APCIS more general than Prolog
20
While APCIS performs very well in many sets of arguments provided by the author it is
still too early to jump to conclusion that it can perform equally well in all types of problems In
any event the expressiveness of APC has greatly been retained in the present version of APCIS
and moreover some design ideas or APCIS mentioned in this paper are not restricted to APCIS
- they may be carried over to learning programs with narrower scopes
21
References
[1] W F Clocksin and C S Mellish Programming In Prolog Springermiddot Verlag Berlin Hpoundidelberg 1981
[2] R S Michalski A Theory and Methodology of Inductive Learning Chpt 4 Machine L earning Tioga Publishing Co Palo Alto CaliJornia 1989
[3] K-E Pua Translating Annotated Predicate Calculu8 to Prolog ISG Report 84middot1 UlUCDCSmiddotFmiddot918 University oj Illinois Urbana IL June 1984
22
Appendix A
APCIS Users Manual
1 Get Started
Users are urged to follow the steps depicted below
1 Get the PROLOG interpreter by typing
alias prolog mntb2sammutsammutprologprolog (Vax A)
or
alias prolog mntb2sammutsammutbinprolog (Vax B)
2 Load apc and infer by typing
prolog apc infer
When large APC expressions are expected we can increase the stlck by typingI
prolog -snnnn ape infer
where ns denote the number of stacks in decimal
3 When the wording LSW - PROLOG appears on the terminal we are reldy to interact
with APCIS The four modes by which we can invoke APCIS are summarized below
a Assert ion-Translation Mode
ta(X)
b Query-Translation Mode
tq(X)
c Assertion Mode
a(X
d Query Mode
q(X)
23
where Xs are APC expressions
2 Notations Used in APCIS
Below is a summary or notations used in APCIS
a Logical operators
amp
v
==gt
lt=gt
-
negation
conjunction
disjunction
implication
equivalence
exception
b Binary relation symbols in selectors
-
=
gt=
lt=
gt
lt
equal
not equal
greater or equal
smaller or equ al
greater
smaller
c Relational operators in numerical quantifiers
lt less than
lt= less than or equal
gt greater than
gt= greater than or equal
d BinlTY operator in numerical quantifier
range
e Universal quantifier
all(X p(X))
f Existential quantifier
exists(X p(X))
g Numerical quantifier
exists(I X p(X))
where p(X) is a formula
where X is a variable or a Jist of variables or the
form [HI~rj and p(X) a formula
where I repersents expression involving integer(s)
and operator(s) in c or d above and p(X) a formula
25
Appendix B
APCIS Program Listings
------------------------------- Program Name APCIS - Part 1 APC Translator
-------------------------------
op(3OO fx -)1
op(500 xfy amp)
oPt 500 xfy v)
op(600 xfx )
op(700 fx [gt= lt= gt lt ]) op(400 xfy [= gt= lt= gt lt ])1 op(900 xfy gt lt=gt -])1
steps(X Xg) shy
numbervars(X 1 J Step 1 change variables to iis
rmimp(X X) Step 2 conv(X X3) Step 3
rewrite(X3 X4) Step 4
negin(X4 X5) Step 5
dropexist(X5 X6 1]) Step 6
dropall(X6 X7) Step 7
distrib(X7 X8) Step 8 clausiCy(X8 X9 [J) Step 9
ta(X) shysteps(X Xg)
(( Xg = II nl
print( yes it is always true) )
( nl nl printcl(X9))) Step 10a
tq(X) shy
steps(X Xg)
prques(Xg)
28
Step 2 Removing implic3tions amp Transforming exceptions and equiv3lences
rmimpl( P - Q (PI lt=gt (QI) ) amp ((PI) lt=gt QI) ) -
rmimpl(P PI) rmimpl(Q QI)
rmimplnp) lt=gt Q (PI lt=gt -(QI)) amp nPI) lt=gt QI) ) - 1
rmimpl(P PI) rmimpJ(Q QI)
rmimpJ(P lt-gt -(Q) (PI lt=gt -(QI)) amp nPI) lt=gt QI) ) -
rmimpl(P PI) rmimpl(Q QI)
rmimpl( P lt=gt Q PI lt=gt QI ) - I
rmimpl(P PI) rmimpl(Q QI)
rmimpl( P ==gt Q -(PI) v QI ) - I
rmimpl(P PI) rmimpl(Q QI)
rmimpl( all(X P) aI(X PI) ) - 1
rmimpl(P PI)
rmimpl( exists(X P) exists(X PI) ) -
rmimpl(P PI)
rmimpl( exists(I X P) exists(I X PI) ) -
rmimpl(P PI)
rmimpl( P amp Q PI amp Ql ) -
rmimpl(P PI) rmimpl(Q Ql)
rmimpl( P v Q PI v QI ) -
rmimpl(P PI) rmimpl(Q QI)
rmimpl( -(p) -(PI) ) - I
rmimpl(p PI)
rmimpl( P P )
St~p 3 Converting numerical amp distinctive quantifiers
L Numerical quantifiers
examples of input forms
1 exists(gt= i X pIX)) where i is an integer
2 exists(i X pIX)) where i is an integer
3 exists(i j X pIX)) where i j are integers and iltj
4 exists(il v i2 X pIX)) where is are integers
examples of output forms of this step
1 exists(X pIX) amp number(X gt= i) )
2 exists(X pIX) amp number(X i) ) 3 exists(X pIX) amp number(X ij) ) 4 exists(X pIX) amp number(X il v i2) )
II Distinctive quantifiers
27
example or input Corm
exists([XYL p(X Y))
example or output Corm or this step
exists(X exists(Y p(XY)) )
conv(P lt=gt Q PI lt=gt QI) - 1
conv(P PI) conv(Q QI)
conv(al1(X P) all(X PI)) -
conv(P PI)
conv(exists(HIT] P) R ) - conv(P PI) convert distinctive quantifier
convtdis(exists([HIT]PI) R)
conv( exists(I X P) exists(X PIamp number(X I) )) -
conv(P PI) convert numerical quantifier
conv(exists(X P) exists(X PI)) - 1
conv(P Pl)
conv(P amp Q PI amp QI) - 1
conv(P PI) conv(Q QI)
conv(P v Q PI v QI) - t conv(P PI) conv(Q QI)
convC(P) -(PI)) -
conv(P PI)
conv(P Pl
convtdis(existsl[XL P) exists(X P)) - atomic(X) convtdis(exists[XIYj Pl exists(X R)) shy
convtdis(exists(Y P) R)
Step 4 Rewriting compound predicates andor compound selectors
Outputs are smiple predicates andor simple selectors
rewrite(P lt=gt Q PI lt=gt QI) - t rewrite(P PI) rewrite(Q QI)
rewrite(all(X Pl all(X PI)) - 1 rewrite(P PI)
rewriteexists(X P) exists(X PI)) - I rewriteP PI)
rewrite(P amp Q PI amp QI) - rewrite(P P 1) rewrite( Q Q 1
rewrite(P v Q PI v QI) - 1
rewrite(P PI) rewrite(Q QI)
rewriteC(P) -(PI)) - I
28
rewrite(P PI) rewrite(F(A B) R) -
rewrite(A AI) rewrite(B BI) re(F(AI BI) R)
rewrite(F(A) R) -
rewrite(A AI) re(F(AI) H)
rewrite(F(A B C) R) -
rewrite(A AI) rewrite(B BI) rewrite(C CI) re(F(AI BI CI) R)
rewrite(F(A B C D) R) -
rewrite(A AI) rewrite(B Btl rewrite(C CI) rewrite(D DI) rc(F(AI BI CI Dl) H)
rewrite(PP)
re(F(A B v el (RI v R2) -
re(F(A Bl RIl re(F(A C) R2) reF(A B amp cl (RI amp R2)) -
re(F(A B) RI) re(F(A e) R2) re(F(A amp B C) (Rl amp R2)) -
re(F(A e) R 1) re(F(B C) R 2) re(F( v B el (R I v R2)) -
re(F(A el R I) reFB el R2) re(F(A amp Bl (R I amp R2)) -
re(F(A RI) re(F(BJH2) re(F(A v B) (R 1 v R2)) -
re(F(A) RI) re(F(B) R2)
re(F(A vB c Dl (RI v R2) -
re(F(A C D) RI) re(F(B C D) R2) re(F(A amp B C D) (RI amp R2)) -
re(F(A C D) Rll re(F(B C D) R2) re(F(A B v C D) (HI v R2)) -
re(F(A B D) RI) re(F(A C D) R2) re(F(A B amp C D) (HI amp R2)) -
re(F(A B D) RI) re(F(A C D) R2) re(F(A B C v D) (RI v R2)) -
re(F(A B C) R I) reF(A B D) R2) re(F(A B C amp D) (RI amp R2)) -
29
re(F(A B C) RI) re(F(A B D) RZ)
re(F(A v B e D E) (R I v R2)) -
re(F(A e D E) R I) re(F(B e D El R2) re(F(A amp B e D E) (RI amp RZ)) -
re(F(A e D El R 1) re(F(B e D E) R2) re(F(A B v e D E) (R I v R2)) -
re(F(A B D E) RI) re(F(A e D E) R2)
re(F(A B amp e D E) (RI amp R2)) -
re(F(A B D El RI) re(F(A e D E) RZ) re(F(A B e v D E) (R I v R2)) -
re(F(A B e El R 1) re(F(A B D E) RZ) re(F(A B e amp D E) (RI amp RZ)) -
re(F(A B e E) R I) re(F(A B D E) RZ)
re(F(A B e D vEl (RI v RZ)) - l
rc(F(A B C D) RI) re(F(A n e El RZ) re(F(A B e D amp El (RI amp RZ)) - ~
re(F(A B e D) RI) re(F(A B e El RZ)
re((A = B) (A = B)l-
re((A = Bl (A = 8)) -
retIA gt= BI (A gt= B)) -
re((A lt= B) (A lt= B)) -
re((A gt B) (A gt B))-
re((A lt Bl (A lt Bl)- re(A A)
Step) Bringing n(gation inwards
Degin(-(P) PI) - neg(P Pl)
negin(P lt=gt Q PI lt=gt Ql) - ~
negin(P PI) negiD(Q QI)
Degin(aU(X P) all(X PI)) - Degin(P PI) negin(exists(X P) exists(X PI))- negin(P PI) negin(P amp Q PI amp Ql) - Degin(P PI) negin(Q Ql)
Degin(P v Q PI v QI) - Degin(P PI) negin(Q QI) negin(P Pl
neg(-(P) PI) - negin(P PI)
neg(all(X P) exists(X PI)) - neg(P PI)
30
neg(exists(X P) all(X PI)) - neg(P PI)
neg(P amp Q PI v QI) - neg(P PI) neg(Q Ql)
neg(P v Q PI amp QI) - neg(P PI) neg(Q QI)
neg(P -(PH
Step 6 Dropping existnetial quanti6ers
dropexist(P lt=gt Q PI lt=gt QI Elerns) - dropexist(P PI Elerns) dropexist(Q QI Elerns)
dropexist(alJ(X P) all(XPI) Elerns)
dropexist(P PI [XIElernsJ)
dropexist(exists(X P amp nurnber(X Yraquo P2 Elerns) -
genfun(skn Newg) Fun = [NewgIElerns]
subst(FuD X P amp Dumber(X Y) PI)
dropexist(Pl P2 Elerns)
dropexist(exists(X P) PZ Elerns) -
genfun(skrn Newf) Fun = [NewfIElernsJ
subst(Fun X p PI)
dropex ist(P 1 P~ Elerns)
dropexist(P v Q PI v QI Elerns) - ~
dropexist(P PI Elerns) dropexist(Q Ql Elerns)
dropexist(P amp Q PI amp QI Elerns) - 1
dropexist(P Pl Elerns) dropexist(Q QI Elerns)
dropexist(P P _)
gen fun(R oot Newn arne) shy
getnurn(Root Nurn)
narne(Root Rootlist)
append(Rootlist[Nurnj Narnelist)
concat(Narnelist Newnarne)
getnurn(Root Nurn) shy
retract(currentnurn(Root Nurn 1 raquo
Nurn is Nurni + 1
asserta(currentnurn(Root Nurn))
getnurn(Root 1) - asserta(currentnurn(Root 1))
subst(New Old Val Val) - var(Val)
subst(New Old Old New) - 1 substNew Old Val Val) - atornic(Val)
31
subst(New Old Val Newval) shy
runctor(Val F N)
CUDctor(Newval F N)
subst_args(N New Old Val Newval)
subst_args(O J J - J J
subst_args(N New Old Val NewVal) shy
arg(N Val OldArg)
arg(N NewVal NewArg)
subst(New Old OldArg NewArg)
NI is N - I
subst_args(Nl New Old Val NewVal)
append([J L L) -
append([XILl] L2 [XIL3]) - append(Ll L2 L3)
Step - Dropping universal quantifiers
dropall(P lt=gt Q PI lt=gt QI)-
dropall(P PI) dropall(Q QI)
dropall(all(X P) PI) - ~ dropall(P PI)
dropall(P amp Q PI amp QI) -
dropall(P PI) dropall(Q QI)
dropall(P v Q PI v QI) -
dropall(P PI) dropall(Q QI)
dropall(P P)
Step 8 Distributing conjunctions over disjunctions
distrib(P lt=gt Q PI lt=gt Ql) - t distrib(P PI) distrib(Q QI)
distrib(P v Q R) -
distrib(P PI) distrib(Q QI)
distributing(PI v QI R)
distrib(P it Q PI it QI) -
distrib(P PI) distrib( Q QI)
distrib(P P)
distributing((P amp Q) v R PI amp QI) -
distrib(P v R PI) distrib(Q v R Ql)
32
distributing(P v (Q amp R) PI amp Ql) -
distrib(P v Q PI) distrib(P v R Ql)
distributing(P P)
Step 9 Packing each conjunction into clauses
c1ausify(P amp Q CI C2) -
clausiCy(P CI C3) c1ausify(Q C3 C2)
cbusiCy(P [d(A B)ICs] Cs) shy
inclause(P A [j B [I) 1
c1ausiry( C C)
inclause(P v Q A AI B B1) -
inc1ause(P A2 AI B2 Bl)
inclause(Q A A2 B B2)
inclausenp) A A B1 B) -
notin(P A) putin(P B B1)
inclause(P AI A B B) shy
notin(P Bl putin(P A AI)
notin(X [XU) - fail
notin(X [JLj) - notin(X L)
notin(X 1])
putin(X II [X]) - 1
putin(X [XILJ L) -
putin(X [YILJ [YILl]) - putin(X L Ll)
Step 1Oa Printing clauses
printcl([]) - nl nl
printcl(c1(AB)ICsj) - printcl(A Bl nl printcl(Cs)
printcl(L II) - printdis(IL) prinr)middot
printclHl L) - prin(contradiction(() printconl(rL)
print()) - ) printconj(rL) prinr )
printcl(Ll L2) shy
printdis(ILl) print( - ) printconj(rL2) prin()
printdis(S[Lj) - printcbar(SL)
33
printdis(S[LILs]) - printchu(SL) prin( v) printdis(SLs)
printconl(S[LI) - printchar(SL)
printconl(S[LILs]) - printchar(SL) prin( ) printconl(SLs)
printconj(S[L]) - tab(3) printchar(SL)
prin tconj( S [L IL sl) shy
tab(3) printchar(SL) print( ) printconj(SLs)
printchar(SP) shy
atomic(P)
name(P L)
L = [IT]
concat([XIT NewP)
prin(~ewP)
printchar(SP) shy
atomic(P)
prin(P)
printchar(SA lt= gt B) -
prin((l clausify(A AI [j) pl(eAl) prin())
print lt=gt )
prin(() cbusify(B Bl [I) pJ(eBl) prine))middot
printchar(rnumber(X N)) shy
prin(num() printchar(rx) prin( )
printchar(rN) prinC))
printchar(rF(A B)) shy
seJec(F(A B))
prinCsel() printchar(rA)
prin( F ) printchar(rB) prinC))
printchar(SF(A B)) shy
( selec(F(A B)) F = infix )
printchar(SA) prin( F ) printchar(SB)
printchar(SF(A)) shy
(F= prefix gt= F= prefix lt= F= prefixgt F= prefix lt )
prin(F ) printcbar(SA)
printchar(SP) shy
functor(P F MaxN)
prin(F ()
Nl is MaxN - 1
putout(S N 1 P MaxN)
34
prin())
putout(S 0 P MaxN) -
arg(~laxN P Argu)
prin tchar(SArgu)
putout(S N p MaxN) shy
Nt is MaxN - N arg(NI P Argu)
printcbar(SArgu )
prin( )
N2 is N - 1
putout(S N2 P MaxN)
selec(FA B)) shy
( F= infix = F= infix f= F= infix gt=
F= infix gt F= infix lt= F= infix lt )
35
----------------------------------Program Name APClS - Part 2 Inference Mechanism ---------------------------------- a(X) shy
steps(X X9)
(( X9 =[] nl
print( yes it is always true) )
( X9 =[cI(IJ[])] nl
print( no it is always false) )
( nl nl printel(X9) Step 1Oa
tell(temp_file) printel(X9) e1ose(temp_file) consult(temp_6Ie) ))
q(X) shy
asserta( in pt(X))
steps(X X9)
(( X9 = [] print(middot~H~~middot~t~)
print(THE AiSWER IS YES)
print( ilgIQlQl(~) )
( X9 = [e1([j [j)] Pr1nt ( OJ fi(i I~ iii Ij)middot(i)(i) fiyenQ)riiio(i)(ij)(i)fj)fiyen1li1il1li1il)__ gtw~ __~_~ _~~_ ~_-=~
print(THE ANSWER IS NO ) print() )
( teI1(temp_6Ie)
prques(X9) Step 1Ob
close(temp_file)
nl print(Let me think about it) nl
consult(temp_6Ie) ))
retrac t( in pt(X))
Step lOb Printing question
prques(lcl(A 8)1) - prin(goo(() pl(qA 8) print()))
prques([c1(A 8HCs]) - prin(goo(() pl(qA 8) print() pl(q Cs)
pl(e [c1(A 8)]) - pl(eA 8)
pl(q [c1(A 8)]) - pl(qA 8) print()))
pl(S [e1(A B)ICs]) - pl(SA B) prin( ) pl(S Cs)
38
pl(q [j L) - prin(c1ause(contradiction(() pcont(qL) prin())_))
pl(S [I L)- prin(so2(contradidion(() pcont(SL) print))))middot
pl(S [L] []) - prin(so2() pcbar(SL) prin())
pl(S L [J)- prinsol() plett(SL) print))
pl(S [L] LI) - prin(condi(() pchar(cL)
prin(() pcont(S Ll) prine))))
pl(S L Ll)- prin(c1ause() plert(cL)
prin(() pcont(S Ll) prine)))
plert(S[LJ) - pchar(SL)
plert(SjLILsj) - pcbar(SL) print v) pleCt(SLs)
pcont(S[L]) - pchar(SL)
pcont(S[LILsj) - pcbar(SL) prinr ) pcont(SLs)
pcbar(SP) shy
atomic(P)
name(PL)
( L = [IT] L = [5 k miT] L = [5 k niT] )
concat[XITj NewP)
prin(0JewP)
pchar(SP) shy
atomic(P)
prin(P) pchar(SA lt=gt B) -
prin(() dausify(A AI []) pl(eAI) prin())
prinr lt=gt ) prin(() dausify(B BI ]) pl(eB) print))
pchar(Snumber(X N)) shy
prin(num() pchar(SX) prin()
pchar(SN) prinr))
pcbar(SM N) - prin(M N)
pcbar(cF(A B)) shy
selec(F(A Braquo
pcbar(cA)
prine F ) pchar(cB) pchar(SF(A B)) shy
selec(F(A B))
prin(sel() pchar(SA)
print F ) pchar(SB) print)) I
31
pc har(SF(A)) shy
( F= prefix gt= F= prefix lt= F= prefixgt F= prefix lt )
prin(F ) pchar(SA)
pchar(SP)shy
runctor(P F MaxN)
prin(F ()
011 is MaxN - 1 pout(SNl P MaxN)
print) )
pout(S 0 P M3xN) - 1
arg(~bxN P Argu)
pchlr(SArgu )
pout(S N P MaxN shy
Nl is MaxN - N
arg(Nl P Argu)
pchar(SArgu
prin( )
N2 is N - 1
pout(S N2 P ~13xN)
Comparing numbers in numerical quantifiers
num(XN) shy
number(X I)
cnum(N 1) ~
cnumlaquo=01 lt=I- N gt=I
cnumlaquo=J lt I) - N gt=1-1
cnumlaquo=NIJ) - N gt=J 1
cnumlaquo=N J)- integer(I) N gt=I~
cnum(gt=N gt=1) - N lt=1
cnum(gt=N gt I) - N lt=1+ 1 cnum(gt=NIJ) - N lt=1
cnum(gt=N lt=1)- N lt=1
cnum(gt=N lt I) - N lt=1 L cnum(gt=N 1)- integer(I) N lt=1
cnum( lt N lt 1)- N gt=1 L
38
cnum( lt N lt=1) - N gt I cnum( lt NLJ) - N gt J
cnum( lt N 1)- integer(I) N gt 1
cnum(gt N gt I) - N lt=1 cnumlgt i gt=1) - N lt I
cnum(gt N lt=1) - N lt=0
cnum(gt N lt I) - N lt=0
cnum(gt iIJ) - N lt I cnum(gt N 1)- integer(I) N lt I
cnum(~LN lt=1) - M=I N gt= I l
cnum(~LN lt I) - M=l N gt= I-I
cnum(~LNLJ) - M lt =1 N gt = J
cnum(~1N 1)- integer(I) M lt= I N gt= I
cnum(- N) - integer(N)
Comparing selectors
sel(X = Y) shyX= Y
sel(X I=Y) shy(X I=Y X lt Y Xgt Y)
sel(X gt Y) shyXgt Y
sel(X lt Y) shyXlt Y
selX gt=Y) shy(X gt=Y X= Y Xgt Y)
se(X lt=Y) shy
(X lt=Y
X= Y
X lt Y)
csel(infix = infix =)
39
csel(infix = infix = csel(infix = infix gt)
csel(infix = infix lt) csel(infix gt infix gt) cseJ(infix lt infix lt) csel(infix gt= infix gt=) csel(infix gt= infix gt csel(infix gt= infix =)
csellinfix lt= infix lt=) csel(infix lt= infix lt) csel(infix lt= infix =)
Finding solutions
sol(X v Y) -
(( notetra(X) eon(X) ( sol(Y) )
( c1ause(P v Q R) not(cketra(P v Q))
dis(P v Q X v Y R) ~ )
( A lt=gt B equival(A lt=gt B X v Y) ~ I) sol(X) - ~ notetra(X) eon(X)
so~(X) - notetra(X)
( con (X)
( clause(P v Q R) not(ekctra(P v Q)) dis(P v Q X R) I)
cketra(P v Q) -
eketra(P) eketra(Q) eketra(F(I J)) shy
selec(F(I J))
c1ause(contradiction(sel(F(IJ))) _I
eketra(number(W I)) -
clause(cootradietion(num(Wl)) - eketr(P) shy
clause(contradiction(P) - 1
notctra(P) shy
not( e lause( con tradiction(P) _))
40
Searching (or disjunctions
dis(P v Q X v Y R) - dis(P X v Y R)
dis(Q X v Y R) con(R)
dis(P v Q X R) -
dis(P X R) dis(Q X R) con(R
dis(P X v Y R) - clause(contradicton(Pl J 1
dis(F(I J) sel(G(I J)) v Y R) - csel(G Fl dis(number(WI) num(W N v Y R) - cnum(N I)
dis(P P v Y R) -
dis(P X v Y R) - dis(P Y R)
dis(F(I J) seJ(G(IJ)) R) - csel(G F)
dis(number(WI) num(WN) R) - cnum(N I) dis(P P R) - 1
dis(FJ J X R) shy
( ckctra(F(IJ) cbeckeq(seJ(F(IJ))) )
dis(number(W Il X R) - ( ckctra(number(WI)) cbeckeq(num(WI)) )
dis(P X R) shy( ckctra(P) cbeckeq(P) ) 1
cbeckeq(P) shy
(( A lt=gt so2(contradiction(P))
bagof(A A [jj) ) ( so2(contradiction(P)) lt=gt B
bagof(B B Uj) ))
ckeq(A) shy
( so2(A) lt=gt B B lt=gt so2(A) ) bagof(B B UJ)
con((P Q)) -
clause(P R) con(R) con(Q) con(true) -
con(contradiction(P)) - clause(contradiction(P) J
con(cause(X Y)) - cause(X Y)
con(sel(X)) - sel(X)
con(num(X Y)) - num(X Y) con(P)- (( dause(P R) (con(R) ckeq(R)))
colJectin(P) )
collectin(P) shy
bagof(S (c1ause(P S) S = true) [L LIJ )
mkcon(L Ll L)
bagor(l (L2 ) UJ) L
mkcon((A AI) (B B1) (sol(A v B) e D)) -
mkcon(A B1 e) mkcon(A1 (B Bl) D)
mkcon(A (B B1) (sol(A v B) e)) -
mkcon(A Bl e)
mkcon((A AI) B (sol(A v B) e)) middot1
mkcon(Al B e)
mkcon(A B sol(A vB))
Searching ror equivalences
equival(A lt=gt B X v Y) - 1 ( equival(A lt=gt B X) equival(A lt=gt B Y) )
equival(s02(A) lt=gt 502(B) A) - clause(B _I equival(s02(B) lt=gt 502(A) A) c1ause(B _I
Top level or inrerence mechanism
goo((s02(whatnum) P)) -
getatm(P Xl
bagor(number(X Y) ( P so2(number(X Y)) ) A )
count1(A 00 L R) nl
bagor(X P B )
count2(B L R Ll Rl) nJ print()
(( LI = 0 Rl = 0 print(THE ANSWER IS ) nl
(( Ll = Rl prin(-Jumber or ) prn(P) print(is Ll) )
( Rlgt20000 prin(Number or I prn(P) print(is LI or more) )
42
( prin(Number of ) pfn(P) print( is from Ll to Rl) )) )
( print(THE ANSWER IS NO I )) print()
goo(X) shy
(( bagof(X X L) L = [I nl print()
print(THE ANSWER IS YES) nl wout(L) print() )
( equiv(X L) nl print()
print(THE ANSWER IS YES) nl wout(L) print(-) )
( c1ause(inpt(A ==gt B) _I ( impli(A B Z) impli(B A Z) ) print(l~Hl)
printTHE ANSWER IS YES) nl print(Z) print(Hj~(fH~) ))
goo(X) print( Hg)
print(THE ANSWER IS NO ) print( lH~lH~gg9l9lmiddotmiddot~Q(gmiddot)
00 Semhing for implications in equiV3lent relations
impli( B Z) shyt-ell( z1) prin(templ() pchn(S A lt=gt B) print()) close ( zl) consult(zl) templ(Z)
unload zl Z
Searching for equivalence
equiv (X L)
(( X lt=gt Y
equ(Y YI)t bagof(Y Yl L) L = [j )
(Y lt=gt X equ(Y YI) bagof(Y Yl L) L = [J )
( X = F(New)
clause(~ew T) makeup(T Tl)
(( Tl lt=gt B
equ(B Bl) bagof(Bl Bl M) M = [j L=[Newl )
(A lt=gt TI
equ(A AI) bagof(Al AI M) M = 1] L=INewj )) ))
makeup((A B) (AI Bl)) -
makeup(A A1) makeup(B BI)
makeup(A so2(A))
equ((A B) (AI BI)) -
equ(A AI) equ(B Bl)
equ(sol(X v Y) sol(XI v Yl)) -
equ(X XI) equ(Y YI)
equ(so2(X) so2(XI)) -
equ(X XI)
equ(contradiction(X) clJuse(contradiction(X) X) ) -
equ(X X)
Counting numbers
getatm((A B) X) -
( getatm(A X) getatm(B X) )
getatm(so2(F(X)) X) -
getatm(so2(X) X) - atom(X)
countl([J L R L R) -
countl([number(X Y)IT] L R L2 R2) shy
(( Y = (gt=~) LI is L + N Rl is R + 20001 l )
( Y = (gt N) LI is L+ N+ 1 RI is R + 20002 )
(Y == laquo=~) LI is L + 1 Rl is R + N )
(Y = laquo N) LI is L + 1 RI is R+N-I)
(Y == IJ LI is L + I Rl is R + J ) ( Y == N L1 is L + N RI is R + N ))
count1(T LI R 1 L2 R2)
count2(fJ L R L R) - 1
count2([XITJ L R L2 R2) shy
name(X Xl)
(( Xl = sknj LI is L Rl is R )
44
( Xl = Iskmj L1 is L + 1 RI is R + ZOOO1) ( LI is L + I RI is R + I ))
count2(T LI RI L2 R2)
pfn((A B)) - pfn(A) prn(B)
pCn(so2(F(X))) - prin(F )
prn(so2(X)) - atom(X) prin(X ) prn (so2(X))
Printing result
wout([XlJ - prt(X) nl woutf[xIY]) - prt(X) nl nl wout(Y)
prt(e(A B)) -
prt(A) prinr 8 ) prt(ltE) prt(eA) - prt(A)
prt(c(A EJ) - prin() prt(A) prine ) prt(B) prin(T)
prt(c A) - prt(A) prt((A E)) - ~
prt(A) nl prt(E) prt(sol(X v Y)) - ~
prt(X) prinC v) prt(Y) prt(A lt=gt B) -
prt(e A) prinC lt=gt ) prt(e B) prt(sol(X)) - prt(X)
prt(so2(X)) - prt(X
prt(c1ause(X Y)) - prt(X)
prt(contradiction(X)) - prin(contradiction() prt(cX) prinr))middot prt(num(XY)) - prin(number(X Y)) prt(sel(X)) - prin(X) prt(X v Y) - prt(X) prin( v) prt(Y) prt(X) prin(X)
Handling conditional queries
condi((Y Xl) shy
assertcon(X) Y
45
retractcon(X)
condi((B A))
retractcon(A) fail
assertcon((A B)) 1
assertcon(A) assertcon(B)
assertcon(A) asserta(A)
retrac teon ((A B)) 1
retracteon(A) retractcon (B)
retraetcon(A) - retract(A)
BIBLIOGRAPHIC DATA SHEET
Report No UIUCDS-F-84-928
3 Recipients Accession No
4 T ide and Subt ltle
An Annotated Predicate Calculus Inference System (APCIS)
S Report Date
November 1984 6
7 Author(s)
Kah-Eng Pua 8 Performing Organization Rept
No
9 Performing Organization Name and Address
Department of Computer Science University of Illinois Urbana IL
10 ProjectTaskWork Unit No
11 Contract Grant No NSF DCR 84-06081 ONR N00014-82-K-0186
12 Sponsoring Organization Name and Address
National Science Foundation Washington DC
13 Type of Report amp Period Covered
14
15 Supplementary Notes
16 Abstracts
This paper describes a deductive inference system called APCIS (Annotated Predicate Calculus Inference System) APCIS is able to carry out inferences from expressions involving numerical quantifiers selectors disjunctions of non-negated terms negated terms disjunctions of negated terms equivalences and exceptions It is also able to count the numbers of occurrence of a given simple term or a conjunction of terms The design of contradiction and the treatment of the disjunction of non-negated terms allow APCIS to accept Horn clauses as well as non-Horn clauses and to carry out inferences from them This feature makes APCIS more general than Prolog
17 Key lords and Document Analysis 170 Descriptors
APC (Annotated Predicate Calculus) APCIS (Annotated Predicate Calculus Inference System) Horn Clause Numerical Quantifier Prolog Selector
17b IdentifiersOpen-Ended Terms
17c COSATI FieldGroup
18 Availability Statement 19 Security Class (This
Re~f~~IA~SIF IFf)
21 ~o of Pages
49 211 ecurity Class (This
PageUNCLASSIFIED
22 Price
FOA NTIS n (10middot70 usco-oc 40329-
Contents
1 Introduction bullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbull 1
2 Overview of APCIS bullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbull 2
21 Assertion-Translation Mode 2
22 Query-Translation Mode bullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbull 2
23 Assertion Mode bullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbull 4
24 Query ~1ode bullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbull 4
3 ~~c Translator 4
31~ Translation of Queries bullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbull 4
32 Translation of Iegated Term and Disjunction of Negated Terms bullbullbullbullbullbullbullbull t
33 Translation of Disjunction of Non-negated T~rms bullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbull 8
3A Further Transformation of Exceptions and Equivalences 9
4 Inference ~1echanism bullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbull 10
41 goo bullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbull 10
42 sol bullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbull 11
43 bull bullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbull bullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbulls02 12
44 dis and con bullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbull 12
45 countl and count2 bullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbull 14
46 equlv bullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbull 14
47 impli bullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbull 15
5 More on the Inference Mechanism bullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbullbull 15
(2)
51 Dum and cnum bullbullbullbullbullbullbull 15
52 sel and csel bullbullbullbullbullbullbullbullbullbullbull 17
6 Printing Result HJ
7 Summary bullbull 19
ReCerences bullbull 21
Appendix A APCIS Users Manual bullbullbullbullbull 22
Appendix B APCIS Program Listings 25
1 introduction
This report describes a deductive inrerence system called APCIS (Annotated Predicate
Calculus Inrerence System) wbich accepts expressions in Annotated Predicated Calculus (APC)
and carries out inrerence rrom them Annotated Predicate Calculus is an invention of Professor R
S Michalski It is built on the basis of First Order Predicate Calculus (FOPC) with some
additional features such as numerical quantifications compound terms selectors compound
selectors etc These reatures not only provide APC with more expressive power tban FOPC but
also make APC much closer to human language than does FOPC Details of APC and its
applications can be round in the paper A Theory and Methodology or Inductive Learning [2]
The process or translating APC to Prolog and a program implementing this process has
been discussed in [3] This report summarizes my continuing effort in developing an APC
inference system and can be considered as a folIowup of [3]
APCIS is capable or performing the following types of operations
1 Carrying out inferences from input assertions expressed in FOPC
2 Carrying out inrerences rrom input assertions expressed in APC
3 Dealing with disjunction or nonnegated terms or the (orm Al v A2 v v Am
4 Dealing with a negated term or a disjunction of negated terms or the rorms -(A) and
-(Al) v -(A2) v v -(An) respectively
5 Dealing with equivalence relations or the form A lt=gt B and exceptions or the
forms A - B or A lt=gt -(B) or -(A) lt=gt B
6 Counting the numbers or occurrence of given predicates in the database
In this report we present an overview of APCIS and a detailed description of its
translation mechanism and inrerence mechanism
2
2 Overview ot APCIS
Figure 1 shows the general structure of APCIS There are four modes by which we can
invoke APCIS Each of them will be discussed in the following sections
21 Assertion-Translation Mode
Figure 1(30) shows schematically the phases that APCIS will go through when assertionshy
translation mode is invoked To translate APC assertion into Prolog we type to Prolog system
ta(X)
where ta stands for ~translation of assertion and X is any APC expression to be translated The
input assertion will then go through an APC translator (discussed in [3]) and its result will be
printed out on the terminal Note that the translated result is not loaded back to Prolog system
22 Query-Translation Mode
Figure l(b) is the schematic diagram showing the execution process of query-translation
mode To translate APC query we type to Prolog system
tq(X)
where tq stands for ~translation of query and X is any APC expression The input query will go
through the same APC translator mentioned above but the output will be in the form of ~Prolog
question (see Slction 31) As in the assertion-translation mode the output will only be printed
out on the terminal and will not be loaded back to Prolog
The above two modes provide only translation purposes The following two modes
perform the actual infNence
3
1-------------1 1 ta (X) I 1-------------1
1 1-------------1
APe 1 I Translator 1
1-------------1 I
1-------------11 Terminal I 1-------------1
(a) Assertion-translation mode
1------------ a(X) I
1------------1 1
1 1------------1 I APe I 1 Translator 1
1------------1
i-----------I 1----------1 I temp_file 1 1 Terminal 1 1-----------1 I----------i
1
1 1-------------1 I Prolog 1 1 system 1 1------------ -I
(c) Assertion mode
Figure 1 Four modes of APCIS
1---------------1 1 tq(X) 1 1---------------1
1 1---------------1 1 A P C 1 I Translator 1
1---------------1 I
1---------------1 I Terminal 1 1---------------1
(b) Query-translation mode
1--------------1 q(X) I 1--------------1
1 1------------------1 1 asserta(inpt(Xraquo 1 1------------------1
1 1---------------1 1 A P C 1 1 Translator 1 1---------------1
I 1---------------1 i temt__file 1 1---------------1 1---------------1 1 Prolog 1 1 system 1 1---------------1
I 1---------------1 1 Terminal 1 1---------------1
I 1-------------------1 1 retract(inpt(Xraquo I I-----------------~-I
Cd) Q-uery mode
23 Assertion Mode
Figure l(c) is a schematic diagram showing how assertion mode works In this mode the
input assertion will first go through the APC translator as in assertionmiddot translation mode After
which the translated result will be printed both on the terminal and to a temporary file called
tempfile which will subsequently be loaded back to Prolog system As a result the newly
translated input assertion will become Prolog term(s or clause(s) in the database
24 Query Mode
Figure l(d) shows schematically the stages that will go through when query mode is
invoked The input query crowned by the (unctor inpt will first be stored in the database It will
then be passed to the APC translator as in query-translation mode The output of the translator
will be printed on the temporary file tempfile which will subsequently be loaded to Prolog
system Upon loading tempfiie to Prolog system (recall that tempJile contains essentially a
Prolog question) the question is executed immediately and its result will be prin ted out on the
terminal In the last stage the original input query crowned by the functor inpt will be
retracted from the database
3 APe Translator
As described in [3] there are ten steps in the APC translator and each step undertakes a
unique transformation Assertion-translation mode and assertion mode go through these steps
which have been covered in [3] and will not be discussed here
31 Translation of Queries
We will now examine the different transrormations that query-translation mode and
query mode will go through They differ Crom assertion-translation mode and assertion mode only
5
in the last step of translation
In the last step of the APe translator all input queries (ie expressions entered via
query-translation mode or query mode) are dealt with by the following six predicates prques pi
plett peont pehar and pout The task of prques pi plett and peont is to arrange each
input query in desired order whereas pehar and pout will print out each atomic formula
character by character For illustration purposes consider the following five APe expressions
1 all( X man(X) ==gt mortal(X)
2 exists( X horse(X) v dog(X) )
3 - ( exists( X horse(X) amp dog(X))
4 all( X be_shouted_at(X) amp no_response(X) == gt deaf(X) v dead(X) )
5 exists( 2 X box(X) )
H the above five APe expressions are typed to Prolog via assertion mode or assertionshy
translation mode they will be translated to the corresponding Prolog expressions
la
mortal(XI) shy
man(Xl)
2a
horse(skml) v dog(skml)
3a
contradiction(( horse(XI) dog(Xl) )) shy
horse(Xl)
dog(XI)
4a
deaf(Xl) v dead(Xl) shy
be_shouted_at(X I)
no_response(X1)
Sa
box(sknl)
number(sknl2)
The above live translated expressions ( ie la through Sa ) will be printed on the
terminal and loaded to Prolog if assertion mode is used they will be printed on the terminal but
not loaded to Prolog if assertion-translation mode is invoked
Now if the original APC expressions ( ie 1 through 5 ) are typed to Prolog via query
mode or query-translation mode the corresponding questions will be translated into the following
queries
lb
goo(( condi(( mortal(Xl) man(Xl))) ))
b
goo(( soil horse(Xl) v dog(XI)) ))
3b
goo(( c1ause( contradiction(( horse(XI) dog(Xl) )) _) ))
4b
goo(( conditt deaf(Xl) v dead(Xl) (be_shouted_at(XI) no_response(Xl)) )) ))
5b
amp00(( so2( box(XI) ) s02( num(XI 2 )) ))
The above five translated queries ( ie Ib through 5b ) will be printed on the terminal
and loaded to Prolog if query mode is used they will be printed on the terminal but not loaded to
Prolog if query-translation mode is invoked
In the above queries goo 801 and 802 each forms a part of the inference mechanism of
APCIS goo occupies the top level of the inference mechanism whereas 801 and 802 are at the
1
next level 102 will take care of the searching of simple terms and 101 will deal with the
disjunctions of non-negated terms in the database We will come back to them in Section 4
At the first glance one may feel that the above translated Queries are Quite complicated
However a closer examination will reveal that they are not so Queries lb 3b and 4b can each be
categorized as a conditional query which is a distinct feature of APCIS wherels queries 2b and
5b lre asking simple facts in the database
To handle conditional queries we consider two cases First if the queries involve a
special clause contradition we invoke the built-in function el3ule(X Y) which will look for the
desired contradiction clause in the database Second if the queries do not involve the clause
contradiction we activate a defined Prolog predicate condi to take care of the necessary
searching (To avoid confusion the reader is urged to compare expressions started with the same
number in the above three sets of example)
To handle a query which asks a simple fact we surround each disjunction of terms with
the functor sol as in the example 2b or crown each simple term with the functor 802 as in the
example 5b
32 TranslatIon of Negated Term And Disjunction of Negated Terms
One feature of APCIS is its ability to handle input expressions consisting of only negated
term or a disjunction of negated terms in the forms
or
2 -(AI) v ~(A2) v v ~(An)
To handle the above two forms a special clause with clause head contradiction is
created This special clause head has only one argument which is either a term or a set of terms
grouped together in the form
8
(AI A2 An)
The right-hand side of the clause contradiction is exactly same as the argument in the clause
head For example the above two forms involving negated terms will be translated into the
corresponding forms as follows
1 contradiction( A ) shy
A
2 contradiction(( AI A2 An )) shy
AI A2 An
The design of the clause with clause head contradiction will greatly enhance the inference power
of APCIS (see the example in Section 44)
33 Translation ot Disjunction ot Non-negated Terms
Another feature of APCIS is its ability to handle input expressions involving a
disjunction of non-negated terms in the forms
1 Al v A2 v v An
or
2 Bl amp 32 amp amp Bm ==gt Al v A2 v v An
Unlike Prolog which accepts only Horn clauses APCJS will accept Horn clauses as well
as non-Horn clauses which take the above two forms The inference from non-Horn clauses is
made possible by the two defined predicates sol lnd s02 discussed in Section 42 and Section 43
respectively (see also the example in Section 44) In the APC translator the above two forms are
transbted into the corresponding forms as follows
1 Al v A2 v v An
2 Al v A2 v v An shy
g
Bl B2 Bm
34 Futher Transformation of Exceptions and Equivalences
To provide some backgrounds for the discussion of the further transformation of
exception and equivalence relations we will lirst reproduce the three goals in the Step 2 of the
APe translator discussed in Section 32 of [31
First expressions involving implication or the form A ==gt B will be transformed to
Second expressions with exception symbol or the form A - B will be changed to the
form ( A lt=gt -(B) ) amp ( -(A) lt=gt B)
Tbird expressions with equivalence symbol of the form -(A) lt=gt B or of the form
A lt=gt -(B) will also be converted to ( A lt=gt -(B) ) amp ( -(A) lt=gt B ) since tbere are
logically identical to exception relations Also expressions with equivalence symbol of the form
A lt=gt B or -(A) lt=gt -(B) will remain the same
After the Step] of the APe translator both sides of any transformed expression with
lt = gt symbol will be treated separately as if they are two independent expressions In the
Step 10 of the APe translator each side of lt=gt will again be treated separately and
transformed into a form similar to an transformed input query (see Section 31) Two examples
are given below
1 state(on) lt=gt -( state(olJ) )
2 all( 1 bot(l) amp humid(l) - winter(I) )
They will be transformed in the Step 2 or the APe translator into
1
(state(on) lt=gt -( state(off) ) ) amp ( -( state(on) ) lt=gt state(olJ) )
2
10
( hot(l) amp humid(l lt=gt -(winter(l)) ) amp
( -( hot(l) amp humid(l)) lt=gt winter(I)
In Step la they will again be transformed to
1
so2( state(on) ) lt=gt so2( contradiction( state(oH) ) )
so2( contradiction( state(on) ) ) lt=gt so2( state(oH) )
2
( s02(hot(XI)) so2(humid(XI))) lt=gt so2( contradiction( winter(Xl ))
so2( contradiction(( bot(Xl) humid(Xl) )) ) lt= gt so2( winter(XI) )
There are two advantages in the treatment of exception and equivalence symbols in this
way First it will prevent Prolog program from going into an infinite loop which is difficult to
avoid if equivalent relation such as A lt=gt B is transformed into the logically equivalent form
( A ==gt B) amp ( B ==gt A) Second by maintaining both sides of lt=gt symbol in
query form the searching on either side caD be done more easily and efficiently since the form
is already processed and does not need any further transformation
Inference Mechanism
As mentioned at the end of Section 31 goo sol and s02 each forms a part of the
inference mechanism of APCIS with goo occupying the top level and 80) and 802 the second
level In addition to these countl count2 equlv and impll are also at the second level of the
inference mechanism We will go over all of them in the following sections
I goo
goo is essentially the starting point of the inference Whenever a translated query is
loaded to Prolog system from temp-fie goo will go through one or more of the following steps in
11
sequence
G 1 Check if the query asks for the numbers of occurrence of certain term(s) It so then
pass It to eountl and eount2 else go to G2
G2 The query will be passed down to sol or s02 (or both) to check i( any assertion in the
database can satisfy the query It the answer is positive then the query succeeds else
go to G3
G3 The query will be passed to equlv to carry out further searching It the searching is a
success then the query will be closed with a success else go to G4
G4 It the query is in the form A ==gt B then it will be passed to Impli It Impll
succeeds then done else the query will be closed with a (ailure
42 sol
801 and 802 together with dis and eon form the most complicated part of the APCIS
iorerence mechanism In this and the next section we will look at sol and s02 dis and eon will
be discussed in Section 44 We will close Section 44 with an example that illustrates the
materials presented in Section 42 through Section 44
sol is at the second level of the inference mechanism It will deal with any disjunction of
non-negated terms For any disjunction passed to it it will go through one or more of the
following steps in sequence
S1 Check if any term In the disjunction can be satisfied by any term or clause in the
database without contradiction It so then done else go to S2
S2 Pass the disjunction together with another disjunction (and its tlil) picked up from
the database to dis It dis succeeds then done else go to S3
S3 Pass the disjunction down to equlval which will check if any term in the disjunction
matches either side of any equivalence relation in the database It such a match is
found then check if the other side of the equivalence C3n be satisfied It so then done
else the goal fails
43 s02
s02 is also at the second level of the inference mechanism It will take care of all the
simple terms in the transl1ted query The following is the sequence that s02 wiII follow in
searching
S1 Check if the term passed to it caD be s3tisfied by any term or clause in the d3tabase
without contradiction It so then done else go to S2
S2 Pass the term together with a disjunction of terms (and its tail) picked up from the
database to dis If dis succeeds then done else the goal fails
44 dis and con
dis has three arguments In the first two clauses of dIs the first argument P v Q is
found in the database using the builtmiddotin functiol clause and the third argument R is the tair of
the term or the clause P v Q If P v Q is not a clause but a term R will be instantiated to trUE
The second 3rgument comes from either lIol or 802 and thus takes the form of either X v Y (a
disjunction of terms) or T (3 simple term)
All the clauses of dis together with con will perform the searching as exemplified in the
following algorithm (we will keep the notationsin this section)
01 Check if every term in P v Q is in X v Y It so then go to 03 else go to D2
02 For any term (in P v Q) which is not in X v Y or does not match T perform the
following tests
a Check if the term (in P v Q) has already been negated in the datab3Se (ie check if
the contradiction of the term exists in the d3tabase) If so then repeat D2 for other
terms not found in X v Y or not matching T else go to b
13
b Check if the contradiction of the term matches either side of any equivalence
relation in the database If such a match is found then check if the other side of the
equivalence can be satisfied If so then repeat O~ for other terms not found in X v Y
or not matching T else the goal fails
It all the terms (in P v Q) which are not in X v Y or do not match T survive either one
of the above two tests then go to 03
03 This step is essentially done by eon whose goal is to satisfy the tail R of P v Q It
con succeeds then done else the search fails
To close this section we will give an example to illustrate what we have covered In
Section 42 through Section 44
Example Assume that we already haye the following expressions in the database
horse(skml) v dog(skmI)
contradiction(( dog(XI) ))shy
dog(XI)
query goo(( soZ horse(X)) ))
This query will be passed to 802 which will check it the term horse() can be satisfied iu Step S 1
of Section 43 It is a failure So we now go to Step S2 In this step we pick up the disjunction
horse(~kml) v dog(skml) (and its tail true) in the datab3Se and pass it together with the term
horse(X) to dis We are now in Step 01 of Section 44 In this step we find that dog(skml) does
not match horse(X) So we have to go to Step 02 In Step 023 We find that the term dog(skml)
has already been negated (the second expression in the database) So we go to next step 03 Since
the tail of the disjuDction horse(skml) v dog(skml) is the atom true con is satisfied and the
query succeeds
45 countl and count2
countl and count2 are responsible for the counting of tbe numbers of occurrence of a
given simple term or a conjunction of terms They are activated by input queries in the form
q( exists( X whatnum amp P) )
where whatnum is the l~bel for activating the counting of the numbers of occurrence of P which
can either be a term or a conjunction of terms
countl will count the number of term(s) which will satisfy P and associate(s) with
numerical quantification(s Two counters are set to update the lower and upper boundary or the
scope or the numfrical quantifications encountered
The contents of the two counters are then passed to count2 which is responsible for the
counting or the following three types of term First term(s) which will satisfy P and associate(s)
with existential quantification(s Second term(s) which will satisfy P and has(have) Prolog atom
as its(thfir) argument(s) Third term(s) that will satisfy P and itself(themselves) is(are) Prolog
atom(s )
46 equiv
equlv will be activated only after sol and B02 have failed The first two goals of equlv
are similar to that of Step S3 in Section 42 and Step D2b in Section 44 The third goal or equiv
makes possible the inference on either side of any equivalent relation For example if we type the
following three expressions to Prolog in assertion mode
l all( X hot(X) amp humidX) - winter(X)
2 all( X hot(X) amp bumid(X) ==gt unpresent(X))
3 - ( exists( X winter(X) ) )
and then ask APCIS in query mode
q( cxists( X unpresent(X) ) )
15
APCIS with the aid of equlv will be able to answer yes to this query
41 lmpll
lmpll can be considered as the last attempt that APCIS would make to satisfy a
query It is activated only after equlv has failed It will first check if the query is conditional If
so it will convert the implication symbol to equivalence symbol and search if such an equivalent
relation can be found in the database If so a success Otherwise a failure
5 More on the Inference Mechanism
Having looked at all the subparts at the top two levels of the inference mechanism we
are ready to look at other subparts at lower levels
51 num and cnum
One distinct fe3ture or APCIS is its ability to deal with numerical quantifications As
mentioned in Section 31 input queries and assertions will undergo different transformations in
the last step (Step 10) of translation This also holds true for expressions involving numerical
quantifications Consider the following expression
exists( 6 X horse(X) )
If it is entered to Prolog via assertion mode we will after going through all the steps of
translation have the rollowing entered to the database
horse(sk n I
number(sknl6)
Now if we want to ask Are there more than five horses 7 and type in
q( exists( gt5 X horse(X) ) )
1amp
APCIS will translate the question and enter to Prolog the following query
goo(( s02( horse(X) ) s02( num( X gt5 )) ))
Note that the term number(slml 6) in the database and the term num(X gt S) in the query are
different predicates and this difference is exactly where the power of the clause num(X N)
defined in APCIS comes from When the clause num(X N) in APCIS is activated it will search
through the database to see if there is any term of the form number(X I) whose first argument
matches the first argument of num(X Y) in the query It a match is found the second arguments
of both num(X Y) in the query and number(ltI) in the database will be passed to cnum in
APCIS
The job of cnum is to compare the numerical messages carried by the second
argument or the term rlum(X Y) in the query and the second argument of the term rlumber(X I)
in the database to see if they match with each other according to the rules defined in cnum
While there are 25 rules for such matching purposes the idea is simple
Imagine that the second argument Y of the term num(X Y) in the query
and the second argument I of the term num()( I) in the database each occupies a
place in an integer line (Le the integer line in mathematics) To have a match
the domain covered by Y should contain the domain covered by L
As an example the answer to the above query is positive since the domain of gt5
contains the domain or 6
Before closing this section we will bring out a speciaJ translation aspect of expressions
involving numbers by an example We first type to APCIS the Collowing expressions in assertion
mode
1 aU(X all(Y father(X Y) amp number(Y gt6) ==gt has_manY3hildren(X) ))
2 exists(X exists( 12 Y Cather(X Y) ) )
11
After going tbrougb all tbe translation steps tbe Collowing two expressions will be entered to tbe
database
I
bas_many_cbildren( Xl ) shy
Cather( Xl X2 )
num( X2 gt6 )
2
Catber( sk m1 sk n2 )
number( skn2 12 )
lotice that whenev(gtr a term with Cunctor number appears at the rigbt-band side oC a Prolog
clause its Cunctor will be cbanged to num automatically This treatment will greatly cnbance tbe
inference power of the clause sbown in l above For instance iC we now ask tbe question
q( exists( X bas_many_children(X) ) )
The right hand side oC the clause l will match the two terms in 2 and tbe query succeeds
52 Bel and cael
A special feature of APe is tbat all predicates tbat express relations = = gt
gt= lt and lt= can be expressed explicitly using infix notations as relational statements
called selectors To handle selectors we defined Bel in APCIS
Every expression involving selectors will undergo different translations in assertion mode
and query mode For example the assertion
a( exists( [X Y] box (X) amp box(Y) amp (weigh t(X) gt weight(Y) ) ) )
will be translated into the following three terms and entered to tbe database
box( skml )
box( skm2 )
18
weight( skm 1 ) gt weight( skm2 )
Now it we want to ask Is it true that there exists two boxes of different weights and type in
q( exists( [X Yl box(X) amp box(Y) amp ( weight(X) = weight(Y) ) ) )
The question will be transformed to the following query and entered to Prolog
goo(( so( box(XI) ) s02( box(X2) ) so2( sel( weightXI) = weight(X2) )) ))
Note that the selector in the above query is surrounded by the functor set When any clause or
8el in APCIS is activated it will search through the database to see it there is any selector whose
two arguments (left and right side or any selector symbol) match the two arguments of the
selector in the query At the same time 8el will check iC the selector symbols (may be different) or
the two different selectors (one in the query and one in the database) satisfy the rules defined in
sel There are 12 matching rules defined in sel All oC them ~re straightforward and will not be
discussed here An example will be enough to explain how 8el works
Consider the execution of the above transformed query The first two terms in the query
are satisfied by the first two terms in the database and Xl and X2 are instantiated to skml and
skm2 respectively The third term of the query will be passed to eel (of APCIS) which finds a
match on each side of the two selectors (one in the query and one in the database) At the same
time the two different selector symbols gt and = are found to satisfy one of the rules in
8el As a result the query succeeds
To enhance the inference power of clauses involving selectors all the selectors appearing
on the rightmiddothand side oC any clause will be surrounded by a functor set The idea is similar to
that in the last part of the previous section
c8el is exactly the same as 8el functionally It provides a convenient way to compare
selectors when dis is being executed
19
8 Printing Result
Whenever a goal is successfully executed APCIS will not only response with a yes but
also print out the matched terms or clauses in the database This is made possible by the built-in
function bagor and the two predicates wout and prt defined in APCIS
7 Summary
In this paper a description of a deductive inference system called APCIS (Annotated
Predicate Calculus Inference System) has been provided APCIS is able to carry out inferences
from expressions involving numerical quantifiers selectors disjunctions of non-negated terms
negated terms disjunctions of negated terms equivalences and exceptions It is also able to count
the numbers of occurrence of a given simple term or a conjunction of terms
The main idea of APCIS is that each input APC expression is first passed to a
preprocessor ( ie APC translator ) which dissolves and transforms each APC expression into
Prolog expression(s) which will then be loaded to Prolog system The user bas to specify whether
each input expression is to be entered as an assertion or as a query by invoking either assertion
mode or query mode respectively Each assertion or query will undergo different transformations in
the preprocessor The different treatment of assertion or query not only allows a full uS1ge of the
Prolog inference mechanism but also makes possible a higher level of inexact pattern matching
exemplified by the examples in Section 51 and Section 52 where the four predicates num
cnum sel and csel are discussed This higher level of pattern matching increases the inference
power of APCIS greatly
The design of contradiction and the treatment of the disjunction of non-negated terms
allow APCIS to accept non-Horn clauses and to carry out inference from them This feature
makes APCIS more general than Prolog
20
While APCIS performs very well in many sets of arguments provided by the author it is
still too early to jump to conclusion that it can perform equally well in all types of problems In
any event the expressiveness of APC has greatly been retained in the present version of APCIS
and moreover some design ideas or APCIS mentioned in this paper are not restricted to APCIS
- they may be carried over to learning programs with narrower scopes
21
References
[1] W F Clocksin and C S Mellish Programming In Prolog Springermiddot Verlag Berlin Hpoundidelberg 1981
[2] R S Michalski A Theory and Methodology of Inductive Learning Chpt 4 Machine L earning Tioga Publishing Co Palo Alto CaliJornia 1989
[3] K-E Pua Translating Annotated Predicate Calculu8 to Prolog ISG Report 84middot1 UlUCDCSmiddotFmiddot918 University oj Illinois Urbana IL June 1984
22
Appendix A
APCIS Users Manual
1 Get Started
Users are urged to follow the steps depicted below
1 Get the PROLOG interpreter by typing
alias prolog mntb2sammutsammutprologprolog (Vax A)
or
alias prolog mntb2sammutsammutbinprolog (Vax B)
2 Load apc and infer by typing
prolog apc infer
When large APC expressions are expected we can increase the stlck by typingI
prolog -snnnn ape infer
where ns denote the number of stacks in decimal
3 When the wording LSW - PROLOG appears on the terminal we are reldy to interact
with APCIS The four modes by which we can invoke APCIS are summarized below
a Assert ion-Translation Mode
ta(X)
b Query-Translation Mode
tq(X)
c Assertion Mode
a(X
d Query Mode
q(X)
23
where Xs are APC expressions
2 Notations Used in APCIS
Below is a summary or notations used in APCIS
a Logical operators
amp
v
==gt
lt=gt
-
negation
conjunction
disjunction
implication
equivalence
exception
b Binary relation symbols in selectors
-
=
gt=
lt=
gt
lt
equal
not equal
greater or equal
smaller or equ al
greater
smaller
c Relational operators in numerical quantifiers
lt less than
lt= less than or equal
gt greater than
gt= greater than or equal
d BinlTY operator in numerical quantifier
range
e Universal quantifier
all(X p(X))
f Existential quantifier
exists(X p(X))
g Numerical quantifier
exists(I X p(X))
where p(X) is a formula
where X is a variable or a Jist of variables or the
form [HI~rj and p(X) a formula
where I repersents expression involving integer(s)
and operator(s) in c or d above and p(X) a formula
25
Appendix B
APCIS Program Listings
------------------------------- Program Name APCIS - Part 1 APC Translator
-------------------------------
op(3OO fx -)1
op(500 xfy amp)
oPt 500 xfy v)
op(600 xfx )
op(700 fx [gt= lt= gt lt ]) op(400 xfy [= gt= lt= gt lt ])1 op(900 xfy gt lt=gt -])1
steps(X Xg) shy
numbervars(X 1 J Step 1 change variables to iis
rmimp(X X) Step 2 conv(X X3) Step 3
rewrite(X3 X4) Step 4
negin(X4 X5) Step 5
dropexist(X5 X6 1]) Step 6
dropall(X6 X7) Step 7
distrib(X7 X8) Step 8 clausiCy(X8 X9 [J) Step 9
ta(X) shysteps(X Xg)
(( Xg = II nl
print( yes it is always true) )
( nl nl printcl(X9))) Step 10a
tq(X) shy
steps(X Xg)
prques(Xg)
28
Step 2 Removing implic3tions amp Transforming exceptions and equiv3lences
rmimpl( P - Q (PI lt=gt (QI) ) amp ((PI) lt=gt QI) ) -
rmimpl(P PI) rmimpl(Q QI)
rmimplnp) lt=gt Q (PI lt=gt -(QI)) amp nPI) lt=gt QI) ) - 1
rmimpl(P PI) rmimpJ(Q QI)
rmimpJ(P lt-gt -(Q) (PI lt=gt -(QI)) amp nPI) lt=gt QI) ) -
rmimpl(P PI) rmimpl(Q QI)
rmimpl( P lt=gt Q PI lt=gt QI ) - I
rmimpl(P PI) rmimpl(Q QI)
rmimpl( P ==gt Q -(PI) v QI ) - I
rmimpl(P PI) rmimpl(Q QI)
rmimpl( all(X P) aI(X PI) ) - 1
rmimpl(P PI)
rmimpl( exists(X P) exists(X PI) ) -
rmimpl(P PI)
rmimpl( exists(I X P) exists(I X PI) ) -
rmimpl(P PI)
rmimpl( P amp Q PI amp Ql ) -
rmimpl(P PI) rmimpl(Q Ql)
rmimpl( P v Q PI v QI ) -
rmimpl(P PI) rmimpl(Q QI)
rmimpl( -(p) -(PI) ) - I
rmimpl(p PI)
rmimpl( P P )
St~p 3 Converting numerical amp distinctive quantifiers
L Numerical quantifiers
examples of input forms
1 exists(gt= i X pIX)) where i is an integer
2 exists(i X pIX)) where i is an integer
3 exists(i j X pIX)) where i j are integers and iltj
4 exists(il v i2 X pIX)) where is are integers
examples of output forms of this step
1 exists(X pIX) amp number(X gt= i) )
2 exists(X pIX) amp number(X i) ) 3 exists(X pIX) amp number(X ij) ) 4 exists(X pIX) amp number(X il v i2) )
II Distinctive quantifiers
27
example or input Corm
exists([XYL p(X Y))
example or output Corm or this step
exists(X exists(Y p(XY)) )
conv(P lt=gt Q PI lt=gt QI) - 1
conv(P PI) conv(Q QI)
conv(al1(X P) all(X PI)) -
conv(P PI)
conv(exists(HIT] P) R ) - conv(P PI) convert distinctive quantifier
convtdis(exists([HIT]PI) R)
conv( exists(I X P) exists(X PIamp number(X I) )) -
conv(P PI) convert numerical quantifier
conv(exists(X P) exists(X PI)) - 1
conv(P Pl)
conv(P amp Q PI amp QI) - 1
conv(P PI) conv(Q QI)
conv(P v Q PI v QI) - t conv(P PI) conv(Q QI)
convC(P) -(PI)) -
conv(P PI)
conv(P Pl
convtdis(existsl[XL P) exists(X P)) - atomic(X) convtdis(exists[XIYj Pl exists(X R)) shy
convtdis(exists(Y P) R)
Step 4 Rewriting compound predicates andor compound selectors
Outputs are smiple predicates andor simple selectors
rewrite(P lt=gt Q PI lt=gt QI) - t rewrite(P PI) rewrite(Q QI)
rewrite(all(X Pl all(X PI)) - 1 rewrite(P PI)
rewriteexists(X P) exists(X PI)) - I rewriteP PI)
rewrite(P amp Q PI amp QI) - rewrite(P P 1) rewrite( Q Q 1
rewrite(P v Q PI v QI) - 1
rewrite(P PI) rewrite(Q QI)
rewriteC(P) -(PI)) - I
28
rewrite(P PI) rewrite(F(A B) R) -
rewrite(A AI) rewrite(B BI) re(F(AI BI) R)
rewrite(F(A) R) -
rewrite(A AI) re(F(AI) H)
rewrite(F(A B C) R) -
rewrite(A AI) rewrite(B BI) rewrite(C CI) re(F(AI BI CI) R)
rewrite(F(A B C D) R) -
rewrite(A AI) rewrite(B Btl rewrite(C CI) rewrite(D DI) rc(F(AI BI CI Dl) H)
rewrite(PP)
re(F(A B v el (RI v R2) -
re(F(A Bl RIl re(F(A C) R2) reF(A B amp cl (RI amp R2)) -
re(F(A B) RI) re(F(A e) R2) re(F(A amp B C) (Rl amp R2)) -
re(F(A e) R 1) re(F(B C) R 2) re(F( v B el (R I v R2)) -
re(F(A el R I) reFB el R2) re(F(A amp Bl (R I amp R2)) -
re(F(A RI) re(F(BJH2) re(F(A v B) (R 1 v R2)) -
re(F(A) RI) re(F(B) R2)
re(F(A vB c Dl (RI v R2) -
re(F(A C D) RI) re(F(B C D) R2) re(F(A amp B C D) (RI amp R2)) -
re(F(A C D) Rll re(F(B C D) R2) re(F(A B v C D) (HI v R2)) -
re(F(A B D) RI) re(F(A C D) R2) re(F(A B amp C D) (HI amp R2)) -
re(F(A B D) RI) re(F(A C D) R2) re(F(A B C v D) (RI v R2)) -
re(F(A B C) R I) reF(A B D) R2) re(F(A B C amp D) (RI amp R2)) -
29
re(F(A B C) RI) re(F(A B D) RZ)
re(F(A v B e D E) (R I v R2)) -
re(F(A e D E) R I) re(F(B e D El R2) re(F(A amp B e D E) (RI amp RZ)) -
re(F(A e D El R 1) re(F(B e D E) R2) re(F(A B v e D E) (R I v R2)) -
re(F(A B D E) RI) re(F(A e D E) R2)
re(F(A B amp e D E) (RI amp R2)) -
re(F(A B D El RI) re(F(A e D E) RZ) re(F(A B e v D E) (R I v R2)) -
re(F(A B e El R 1) re(F(A B D E) RZ) re(F(A B e amp D E) (RI amp RZ)) -
re(F(A B e E) R I) re(F(A B D E) RZ)
re(F(A B e D vEl (RI v RZ)) - l
rc(F(A B C D) RI) re(F(A n e El RZ) re(F(A B e D amp El (RI amp RZ)) - ~
re(F(A B e D) RI) re(F(A B e El RZ)
re((A = B) (A = B)l-
re((A = Bl (A = 8)) -
retIA gt= BI (A gt= B)) -
re((A lt= B) (A lt= B)) -
re((A gt B) (A gt B))-
re((A lt Bl (A lt Bl)- re(A A)
Step) Bringing n(gation inwards
Degin(-(P) PI) - neg(P Pl)
negin(P lt=gt Q PI lt=gt Ql) - ~
negin(P PI) negiD(Q QI)
Degin(aU(X P) all(X PI)) - Degin(P PI) negin(exists(X P) exists(X PI))- negin(P PI) negin(P amp Q PI amp Ql) - Degin(P PI) negin(Q Ql)
Degin(P v Q PI v QI) - Degin(P PI) negin(Q QI) negin(P Pl
neg(-(P) PI) - negin(P PI)
neg(all(X P) exists(X PI)) - neg(P PI)
30
neg(exists(X P) all(X PI)) - neg(P PI)
neg(P amp Q PI v QI) - neg(P PI) neg(Q Ql)
neg(P v Q PI amp QI) - neg(P PI) neg(Q QI)
neg(P -(PH
Step 6 Dropping existnetial quanti6ers
dropexist(P lt=gt Q PI lt=gt QI Elerns) - dropexist(P PI Elerns) dropexist(Q QI Elerns)
dropexist(alJ(X P) all(XPI) Elerns)
dropexist(P PI [XIElernsJ)
dropexist(exists(X P amp nurnber(X Yraquo P2 Elerns) -
genfun(skn Newg) Fun = [NewgIElerns]
subst(FuD X P amp Dumber(X Y) PI)
dropexist(Pl P2 Elerns)
dropexist(exists(X P) PZ Elerns) -
genfun(skrn Newf) Fun = [NewfIElernsJ
subst(Fun X p PI)
dropex ist(P 1 P~ Elerns)
dropexist(P v Q PI v QI Elerns) - ~
dropexist(P PI Elerns) dropexist(Q Ql Elerns)
dropexist(P amp Q PI amp QI Elerns) - 1
dropexist(P Pl Elerns) dropexist(Q QI Elerns)
dropexist(P P _)
gen fun(R oot Newn arne) shy
getnurn(Root Nurn)
narne(Root Rootlist)
append(Rootlist[Nurnj Narnelist)
concat(Narnelist Newnarne)
getnurn(Root Nurn) shy
retract(currentnurn(Root Nurn 1 raquo
Nurn is Nurni + 1
asserta(currentnurn(Root Nurn))
getnurn(Root 1) - asserta(currentnurn(Root 1))
subst(New Old Val Val) - var(Val)
subst(New Old Old New) - 1 substNew Old Val Val) - atornic(Val)
31
subst(New Old Val Newval) shy
runctor(Val F N)
CUDctor(Newval F N)
subst_args(N New Old Val Newval)
subst_args(O J J - J J
subst_args(N New Old Val NewVal) shy
arg(N Val OldArg)
arg(N NewVal NewArg)
subst(New Old OldArg NewArg)
NI is N - I
subst_args(Nl New Old Val NewVal)
append([J L L) -
append([XILl] L2 [XIL3]) - append(Ll L2 L3)
Step - Dropping universal quantifiers
dropall(P lt=gt Q PI lt=gt QI)-
dropall(P PI) dropall(Q QI)
dropall(all(X P) PI) - ~ dropall(P PI)
dropall(P amp Q PI amp QI) -
dropall(P PI) dropall(Q QI)
dropall(P v Q PI v QI) -
dropall(P PI) dropall(Q QI)
dropall(P P)
Step 8 Distributing conjunctions over disjunctions
distrib(P lt=gt Q PI lt=gt Ql) - t distrib(P PI) distrib(Q QI)
distrib(P v Q R) -
distrib(P PI) distrib(Q QI)
distributing(PI v QI R)
distrib(P it Q PI it QI) -
distrib(P PI) distrib( Q QI)
distrib(P P)
distributing((P amp Q) v R PI amp QI) -
distrib(P v R PI) distrib(Q v R Ql)
32
distributing(P v (Q amp R) PI amp Ql) -
distrib(P v Q PI) distrib(P v R Ql)
distributing(P P)
Step 9 Packing each conjunction into clauses
c1ausify(P amp Q CI C2) -
clausiCy(P CI C3) c1ausify(Q C3 C2)
cbusiCy(P [d(A B)ICs] Cs) shy
inclause(P A [j B [I) 1
c1ausiry( C C)
inclause(P v Q A AI B B1) -
inc1ause(P A2 AI B2 Bl)
inclause(Q A A2 B B2)
inclausenp) A A B1 B) -
notin(P A) putin(P B B1)
inclause(P AI A B B) shy
notin(P Bl putin(P A AI)
notin(X [XU) - fail
notin(X [JLj) - notin(X L)
notin(X 1])
putin(X II [X]) - 1
putin(X [XILJ L) -
putin(X [YILJ [YILl]) - putin(X L Ll)
Step 1Oa Printing clauses
printcl([]) - nl nl
printcl(c1(AB)ICsj) - printcl(A Bl nl printcl(Cs)
printcl(L II) - printdis(IL) prinr)middot
printclHl L) - prin(contradiction(() printconl(rL)
print()) - ) printconj(rL) prinr )
printcl(Ll L2) shy
printdis(ILl) print( - ) printconj(rL2) prin()
printdis(S[Lj) - printcbar(SL)
33
printdis(S[LILs]) - printchu(SL) prin( v) printdis(SLs)
printconl(S[LI) - printchar(SL)
printconl(S[LILs]) - printchar(SL) prin( ) printconl(SLs)
printconj(S[L]) - tab(3) printchar(SL)
prin tconj( S [L IL sl) shy
tab(3) printchar(SL) print( ) printconj(SLs)
printchar(SP) shy
atomic(P)
name(P L)
L = [IT]
concat([XIT NewP)
prin(~ewP)
printchar(SP) shy
atomic(P)
prin(P)
printchar(SA lt= gt B) -
prin((l clausify(A AI [j) pl(eAl) prin())
print lt=gt )
prin(() cbusify(B Bl [I) pJ(eBl) prine))middot
printchar(rnumber(X N)) shy
prin(num() printchar(rx) prin( )
printchar(rN) prinC))
printchar(rF(A B)) shy
seJec(F(A B))
prinCsel() printchar(rA)
prin( F ) printchar(rB) prinC))
printchar(SF(A B)) shy
( selec(F(A B)) F = infix )
printchar(SA) prin( F ) printchar(SB)
printchar(SF(A)) shy
(F= prefix gt= F= prefix lt= F= prefixgt F= prefix lt )
prin(F ) printcbar(SA)
printchar(SP) shy
functor(P F MaxN)
prin(F ()
Nl is MaxN - 1
putout(S N 1 P MaxN)
34
prin())
putout(S 0 P MaxN) -
arg(~laxN P Argu)
prin tchar(SArgu)
putout(S N p MaxN) shy
Nt is MaxN - N arg(NI P Argu)
printcbar(SArgu )
prin( )
N2 is N - 1
putout(S N2 P MaxN)
selec(FA B)) shy
( F= infix = F= infix f= F= infix gt=
F= infix gt F= infix lt= F= infix lt )
35
----------------------------------Program Name APClS - Part 2 Inference Mechanism ---------------------------------- a(X) shy
steps(X X9)
(( X9 =[] nl
print( yes it is always true) )
( X9 =[cI(IJ[])] nl
print( no it is always false) )
( nl nl printel(X9) Step 1Oa
tell(temp_file) printel(X9) e1ose(temp_file) consult(temp_6Ie) ))
q(X) shy
asserta( in pt(X))
steps(X X9)
(( X9 = [] print(middot~H~~middot~t~)
print(THE AiSWER IS YES)
print( ilgIQlQl(~) )
( X9 = [e1([j [j)] Pr1nt ( OJ fi(i I~ iii Ij)middot(i)(i) fiyenQ)riiio(i)(ij)(i)fj)fiyen1li1il1li1il)__ gtw~ __~_~ _~~_ ~_-=~
print(THE ANSWER IS NO ) print() )
( teI1(temp_6Ie)
prques(X9) Step 1Ob
close(temp_file)
nl print(Let me think about it) nl
consult(temp_6Ie) ))
retrac t( in pt(X))
Step lOb Printing question
prques(lcl(A 8)1) - prin(goo(() pl(qA 8) print()))
prques([c1(A 8HCs]) - prin(goo(() pl(qA 8) print() pl(q Cs)
pl(e [c1(A 8)]) - pl(eA 8)
pl(q [c1(A 8)]) - pl(qA 8) print()))
pl(S [e1(A B)ICs]) - pl(SA B) prin( ) pl(S Cs)
38
pl(q [j L) - prin(c1ause(contradiction(() pcont(qL) prin())_))
pl(S [I L)- prin(so2(contradidion(() pcont(SL) print))))middot
pl(S [L] []) - prin(so2() pcbar(SL) prin())
pl(S L [J)- prinsol() plett(SL) print))
pl(S [L] LI) - prin(condi(() pchar(cL)
prin(() pcont(S Ll) prine))))
pl(S L Ll)- prin(c1ause() plert(cL)
prin(() pcont(S Ll) prine)))
plert(S[LJ) - pchar(SL)
plert(SjLILsj) - pcbar(SL) print v) pleCt(SLs)
pcont(S[L]) - pchar(SL)
pcont(S[LILsj) - pcbar(SL) prinr ) pcont(SLs)
pcbar(SP) shy
atomic(P)
name(PL)
( L = [IT] L = [5 k miT] L = [5 k niT] )
concat[XITj NewP)
prin(0JewP)
pchar(SP) shy
atomic(P)
prin(P) pchar(SA lt=gt B) -
prin(() dausify(A AI []) pl(eAI) prin())
prinr lt=gt ) prin(() dausify(B BI ]) pl(eB) print))
pchar(Snumber(X N)) shy
prin(num() pchar(SX) prin()
pchar(SN) prinr))
pcbar(SM N) - prin(M N)
pcbar(cF(A B)) shy
selec(F(A Braquo
pcbar(cA)
prine F ) pchar(cB) pchar(SF(A B)) shy
selec(F(A B))
prin(sel() pchar(SA)
print F ) pchar(SB) print)) I
31
pc har(SF(A)) shy
( F= prefix gt= F= prefix lt= F= prefixgt F= prefix lt )
prin(F ) pchar(SA)
pchar(SP)shy
runctor(P F MaxN)
prin(F ()
011 is MaxN - 1 pout(SNl P MaxN)
print) )
pout(S 0 P M3xN) - 1
arg(~bxN P Argu)
pchlr(SArgu )
pout(S N P MaxN shy
Nl is MaxN - N
arg(Nl P Argu)
pchar(SArgu
prin( )
N2 is N - 1
pout(S N2 P ~13xN)
Comparing numbers in numerical quantifiers
num(XN) shy
number(X I)
cnum(N 1) ~
cnumlaquo=01 lt=I- N gt=I
cnumlaquo=J lt I) - N gt=1-1
cnumlaquo=NIJ) - N gt=J 1
cnumlaquo=N J)- integer(I) N gt=I~
cnum(gt=N gt=1) - N lt=1
cnum(gt=N gt I) - N lt=1+ 1 cnum(gt=NIJ) - N lt=1
cnum(gt=N lt=1)- N lt=1
cnum(gt=N lt I) - N lt=1 L cnum(gt=N 1)- integer(I) N lt=1
cnum( lt N lt 1)- N gt=1 L
38
cnum( lt N lt=1) - N gt I cnum( lt NLJ) - N gt J
cnum( lt N 1)- integer(I) N gt 1
cnum(gt N gt I) - N lt=1 cnumlgt i gt=1) - N lt I
cnum(gt N lt=1) - N lt=0
cnum(gt N lt I) - N lt=0
cnum(gt iIJ) - N lt I cnum(gt N 1)- integer(I) N lt I
cnum(~LN lt=1) - M=I N gt= I l
cnum(~LN lt I) - M=l N gt= I-I
cnum(~LNLJ) - M lt =1 N gt = J
cnum(~1N 1)- integer(I) M lt= I N gt= I
cnum(- N) - integer(N)
Comparing selectors
sel(X = Y) shyX= Y
sel(X I=Y) shy(X I=Y X lt Y Xgt Y)
sel(X gt Y) shyXgt Y
sel(X lt Y) shyXlt Y
selX gt=Y) shy(X gt=Y X= Y Xgt Y)
se(X lt=Y) shy
(X lt=Y
X= Y
X lt Y)
csel(infix = infix =)
39
csel(infix = infix = csel(infix = infix gt)
csel(infix = infix lt) csel(infix gt infix gt) cseJ(infix lt infix lt) csel(infix gt= infix gt=) csel(infix gt= infix gt csel(infix gt= infix =)
csellinfix lt= infix lt=) csel(infix lt= infix lt) csel(infix lt= infix =)
Finding solutions
sol(X v Y) -
(( notetra(X) eon(X) ( sol(Y) )
( c1ause(P v Q R) not(cketra(P v Q))
dis(P v Q X v Y R) ~ )
( A lt=gt B equival(A lt=gt B X v Y) ~ I) sol(X) - ~ notetra(X) eon(X)
so~(X) - notetra(X)
( con (X)
( clause(P v Q R) not(ekctra(P v Q)) dis(P v Q X R) I)
cketra(P v Q) -
eketra(P) eketra(Q) eketra(F(I J)) shy
selec(F(I J))
c1ause(contradiction(sel(F(IJ))) _I
eketra(number(W I)) -
clause(cootradietion(num(Wl)) - eketr(P) shy
clause(contradiction(P) - 1
notctra(P) shy
not( e lause( con tradiction(P) _))
40
Searching (or disjunctions
dis(P v Q X v Y R) - dis(P X v Y R)
dis(Q X v Y R) con(R)
dis(P v Q X R) -
dis(P X R) dis(Q X R) con(R
dis(P X v Y R) - clause(contradicton(Pl J 1
dis(F(I J) sel(G(I J)) v Y R) - csel(G Fl dis(number(WI) num(W N v Y R) - cnum(N I)
dis(P P v Y R) -
dis(P X v Y R) - dis(P Y R)
dis(F(I J) seJ(G(IJ)) R) - csel(G F)
dis(number(WI) num(WN) R) - cnum(N I) dis(P P R) - 1
dis(FJ J X R) shy
( ckctra(F(IJ) cbeckeq(seJ(F(IJ))) )
dis(number(W Il X R) - ( ckctra(number(WI)) cbeckeq(num(WI)) )
dis(P X R) shy( ckctra(P) cbeckeq(P) ) 1
cbeckeq(P) shy
(( A lt=gt so2(contradiction(P))
bagof(A A [jj) ) ( so2(contradiction(P)) lt=gt B
bagof(B B Uj) ))
ckeq(A) shy
( so2(A) lt=gt B B lt=gt so2(A) ) bagof(B B UJ)
con((P Q)) -
clause(P R) con(R) con(Q) con(true) -
con(contradiction(P)) - clause(contradiction(P) J
con(cause(X Y)) - cause(X Y)
con(sel(X)) - sel(X)
con(num(X Y)) - num(X Y) con(P)- (( dause(P R) (con(R) ckeq(R)))
colJectin(P) )
collectin(P) shy
bagof(S (c1ause(P S) S = true) [L LIJ )
mkcon(L Ll L)
bagor(l (L2 ) UJ) L
mkcon((A AI) (B B1) (sol(A v B) e D)) -
mkcon(A B1 e) mkcon(A1 (B Bl) D)
mkcon(A (B B1) (sol(A v B) e)) -
mkcon(A Bl e)
mkcon((A AI) B (sol(A v B) e)) middot1
mkcon(Al B e)
mkcon(A B sol(A vB))
Searching ror equivalences
equival(A lt=gt B X v Y) - 1 ( equival(A lt=gt B X) equival(A lt=gt B Y) )
equival(s02(A) lt=gt 502(B) A) - clause(B _I equival(s02(B) lt=gt 502(A) A) c1ause(B _I
Top level or inrerence mechanism
goo((s02(whatnum) P)) -
getatm(P Xl
bagor(number(X Y) ( P so2(number(X Y)) ) A )
count1(A 00 L R) nl
bagor(X P B )
count2(B L R Ll Rl) nJ print()
(( LI = 0 Rl = 0 print(THE ANSWER IS ) nl
(( Ll = Rl prin(-Jumber or ) prn(P) print(is Ll) )
( Rlgt20000 prin(Number or I prn(P) print(is LI or more) )
42
( prin(Number of ) pfn(P) print( is from Ll to Rl) )) )
( print(THE ANSWER IS NO I )) print()
goo(X) shy
(( bagof(X X L) L = [I nl print()
print(THE ANSWER IS YES) nl wout(L) print() )
( equiv(X L) nl print()
print(THE ANSWER IS YES) nl wout(L) print(-) )
( c1ause(inpt(A ==gt B) _I ( impli(A B Z) impli(B A Z) ) print(l~Hl)
printTHE ANSWER IS YES) nl print(Z) print(Hj~(fH~) ))
goo(X) print( Hg)
print(THE ANSWER IS NO ) print( lH~lH~gg9l9lmiddotmiddot~Q(gmiddot)
00 Semhing for implications in equiV3lent relations
impli( B Z) shyt-ell( z1) prin(templ() pchn(S A lt=gt B) print()) close ( zl) consult(zl) templ(Z)
unload zl Z
Searching for equivalence
equiv (X L)
(( X lt=gt Y
equ(Y YI)t bagof(Y Yl L) L = [j )
(Y lt=gt X equ(Y YI) bagof(Y Yl L) L = [J )
( X = F(New)
clause(~ew T) makeup(T Tl)
(( Tl lt=gt B
equ(B Bl) bagof(Bl Bl M) M = [j L=[Newl )
(A lt=gt TI
equ(A AI) bagof(Al AI M) M = 1] L=INewj )) ))
makeup((A B) (AI Bl)) -
makeup(A A1) makeup(B BI)
makeup(A so2(A))
equ((A B) (AI BI)) -
equ(A AI) equ(B Bl)
equ(sol(X v Y) sol(XI v Yl)) -
equ(X XI) equ(Y YI)
equ(so2(X) so2(XI)) -
equ(X XI)
equ(contradiction(X) clJuse(contradiction(X) X) ) -
equ(X X)
Counting numbers
getatm((A B) X) -
( getatm(A X) getatm(B X) )
getatm(so2(F(X)) X) -
getatm(so2(X) X) - atom(X)
countl([J L R L R) -
countl([number(X Y)IT] L R L2 R2) shy
(( Y = (gt=~) LI is L + N Rl is R + 20001 l )
( Y = (gt N) LI is L+ N+ 1 RI is R + 20002 )
(Y == laquo=~) LI is L + 1 Rl is R + N )
(Y = laquo N) LI is L + 1 RI is R+N-I)
(Y == IJ LI is L + I Rl is R + J ) ( Y == N L1 is L + N RI is R + N ))
count1(T LI R 1 L2 R2)
count2(fJ L R L R) - 1
count2([XITJ L R L2 R2) shy
name(X Xl)
(( Xl = sknj LI is L Rl is R )
44
( Xl = Iskmj L1 is L + 1 RI is R + ZOOO1) ( LI is L + I RI is R + I ))
count2(T LI RI L2 R2)
pfn((A B)) - pfn(A) prn(B)
pCn(so2(F(X))) - prin(F )
prn(so2(X)) - atom(X) prin(X ) prn (so2(X))
Printing result
wout([XlJ - prt(X) nl woutf[xIY]) - prt(X) nl nl wout(Y)
prt(e(A B)) -
prt(A) prinr 8 ) prt(ltE) prt(eA) - prt(A)
prt(c(A EJ) - prin() prt(A) prine ) prt(B) prin(T)
prt(c A) - prt(A) prt((A E)) - ~
prt(A) nl prt(E) prt(sol(X v Y)) - ~
prt(X) prinC v) prt(Y) prt(A lt=gt B) -
prt(e A) prinC lt=gt ) prt(e B) prt(sol(X)) - prt(X)
prt(so2(X)) - prt(X
prt(c1ause(X Y)) - prt(X)
prt(contradiction(X)) - prin(contradiction() prt(cX) prinr))middot prt(num(XY)) - prin(number(X Y)) prt(sel(X)) - prin(X) prt(X v Y) - prt(X) prin( v) prt(Y) prt(X) prin(X)
Handling conditional queries
condi((Y Xl) shy
assertcon(X) Y
45
retractcon(X)
condi((B A))
retractcon(A) fail
assertcon((A B)) 1
assertcon(A) assertcon(B)
assertcon(A) asserta(A)
retrac teon ((A B)) 1
retracteon(A) retractcon (B)
retraetcon(A) - retract(A)
BIBLIOGRAPHIC DATA SHEET
Report No UIUCDS-F-84-928
3 Recipients Accession No
4 T ide and Subt ltle
An Annotated Predicate Calculus Inference System (APCIS)
S Report Date
November 1984 6
7 Author(s)
Kah-Eng Pua 8 Performing Organization Rept
No
9 Performing Organization Name and Address
Department of Computer Science University of Illinois Urbana IL
10 ProjectTaskWork Unit No
11 Contract Grant No NSF DCR 84-06081 ONR N00014-82-K-0186
12 Sponsoring Organization Name and Address
National Science Foundation Washington DC
13 Type of Report amp Period Covered
14
15 Supplementary Notes
16 Abstracts
This paper describes a deductive inference system called APCIS (Annotated Predicate Calculus Inference System) APCIS is able to carry out inferences from expressions involving numerical quantifiers selectors disjunctions of non-negated terms negated terms disjunctions of negated terms equivalences and exceptions It is also able to count the numbers of occurrence of a given simple term or a conjunction of terms The design of contradiction and the treatment of the disjunction of non-negated terms allow APCIS to accept Horn clauses as well as non-Horn clauses and to carry out inferences from them This feature makes APCIS more general than Prolog
17 Key lords and Document Analysis 170 Descriptors
APC (Annotated Predicate Calculus) APCIS (Annotated Predicate Calculus Inference System) Horn Clause Numerical Quantifier Prolog Selector
17b IdentifiersOpen-Ended Terms
17c COSATI FieldGroup
18 Availability Statement 19 Security Class (This
Re~f~~IA~SIF IFf)
21 ~o of Pages
49 211 ecurity Class (This
PageUNCLASSIFIED
22 Price
FOA NTIS n (10middot70 usco-oc 40329-
(2)
51 Dum and cnum bullbullbullbullbullbullbull 15
52 sel and csel bullbullbullbullbullbullbullbullbullbullbull 17
6 Printing Result HJ
7 Summary bullbull 19
ReCerences bullbull 21
Appendix A APCIS Users Manual bullbullbullbullbull 22
Appendix B APCIS Program Listings 25
1 introduction
This report describes a deductive inrerence system called APCIS (Annotated Predicate
Calculus Inrerence System) wbich accepts expressions in Annotated Predicated Calculus (APC)
and carries out inrerence rrom them Annotated Predicate Calculus is an invention of Professor R
S Michalski It is built on the basis of First Order Predicate Calculus (FOPC) with some
additional features such as numerical quantifications compound terms selectors compound
selectors etc These reatures not only provide APC with more expressive power tban FOPC but
also make APC much closer to human language than does FOPC Details of APC and its
applications can be round in the paper A Theory and Methodology or Inductive Learning [2]
The process or translating APC to Prolog and a program implementing this process has
been discussed in [3] This report summarizes my continuing effort in developing an APC
inference system and can be considered as a folIowup of [3]
APCIS is capable or performing the following types of operations
1 Carrying out inferences from input assertions expressed in FOPC
2 Carrying out inrerences rrom input assertions expressed in APC
3 Dealing with disjunction or nonnegated terms or the (orm Al v A2 v v Am
4 Dealing with a negated term or a disjunction of negated terms or the rorms -(A) and
-(Al) v -(A2) v v -(An) respectively
5 Dealing with equivalence relations or the form A lt=gt B and exceptions or the
forms A - B or A lt=gt -(B) or -(A) lt=gt B
6 Counting the numbers or occurrence of given predicates in the database
In this report we present an overview of APCIS and a detailed description of its
translation mechanism and inrerence mechanism
2
2 Overview ot APCIS
Figure 1 shows the general structure of APCIS There are four modes by which we can
invoke APCIS Each of them will be discussed in the following sections
21 Assertion-Translation Mode
Figure 1(30) shows schematically the phases that APCIS will go through when assertionshy
translation mode is invoked To translate APC assertion into Prolog we type to Prolog system
ta(X)
where ta stands for ~translation of assertion and X is any APC expression to be translated The
input assertion will then go through an APC translator (discussed in [3]) and its result will be
printed out on the terminal Note that the translated result is not loaded back to Prolog system
22 Query-Translation Mode
Figure l(b) is the schematic diagram showing the execution process of query-translation
mode To translate APC query we type to Prolog system
tq(X)
where tq stands for ~translation of query and X is any APC expression The input query will go
through the same APC translator mentioned above but the output will be in the form of ~Prolog
question (see Slction 31) As in the assertion-translation mode the output will only be printed
out on the terminal and will not be loaded back to Prolog
The above two modes provide only translation purposes The following two modes
perform the actual infNence
3
1-------------1 1 ta (X) I 1-------------1
1 1-------------1
APe 1 I Translator 1
1-------------1 I
1-------------11 Terminal I 1-------------1
(a) Assertion-translation mode
1------------ a(X) I
1------------1 1
1 1------------1 I APe I 1 Translator 1
1------------1
i-----------I 1----------1 I temp_file 1 1 Terminal 1 1-----------1 I----------i
1
1 1-------------1 I Prolog 1 1 system 1 1------------ -I
(c) Assertion mode
Figure 1 Four modes of APCIS
1---------------1 1 tq(X) 1 1---------------1
1 1---------------1 1 A P C 1 I Translator 1
1---------------1 I
1---------------1 I Terminal 1 1---------------1
(b) Query-translation mode
1--------------1 q(X) I 1--------------1
1 1------------------1 1 asserta(inpt(Xraquo 1 1------------------1
1 1---------------1 1 A P C 1 1 Translator 1 1---------------1
I 1---------------1 i temt__file 1 1---------------1 1---------------1 1 Prolog 1 1 system 1 1---------------1
I 1---------------1 1 Terminal 1 1---------------1
I 1-------------------1 1 retract(inpt(Xraquo I I-----------------~-I
Cd) Q-uery mode
23 Assertion Mode
Figure l(c) is a schematic diagram showing how assertion mode works In this mode the
input assertion will first go through the APC translator as in assertionmiddot translation mode After
which the translated result will be printed both on the terminal and to a temporary file called
tempfile which will subsequently be loaded back to Prolog system As a result the newly
translated input assertion will become Prolog term(s or clause(s) in the database
24 Query Mode
Figure l(d) shows schematically the stages that will go through when query mode is
invoked The input query crowned by the (unctor inpt will first be stored in the database It will
then be passed to the APC translator as in query-translation mode The output of the translator
will be printed on the temporary file tempfile which will subsequently be loaded to Prolog
system Upon loading tempfiie to Prolog system (recall that tempJile contains essentially a
Prolog question) the question is executed immediately and its result will be prin ted out on the
terminal In the last stage the original input query crowned by the functor inpt will be
retracted from the database
3 APe Translator
As described in [3] there are ten steps in the APC translator and each step undertakes a
unique transformation Assertion-translation mode and assertion mode go through these steps
which have been covered in [3] and will not be discussed here
31 Translation of Queries
We will now examine the different transrormations that query-translation mode and
query mode will go through They differ Crom assertion-translation mode and assertion mode only
5
in the last step of translation
In the last step of the APe translator all input queries (ie expressions entered via
query-translation mode or query mode) are dealt with by the following six predicates prques pi
plett peont pehar and pout The task of prques pi plett and peont is to arrange each
input query in desired order whereas pehar and pout will print out each atomic formula
character by character For illustration purposes consider the following five APe expressions
1 all( X man(X) ==gt mortal(X)
2 exists( X horse(X) v dog(X) )
3 - ( exists( X horse(X) amp dog(X))
4 all( X be_shouted_at(X) amp no_response(X) == gt deaf(X) v dead(X) )
5 exists( 2 X box(X) )
H the above five APe expressions are typed to Prolog via assertion mode or assertionshy
translation mode they will be translated to the corresponding Prolog expressions
la
mortal(XI) shy
man(Xl)
2a
horse(skml) v dog(skml)
3a
contradiction(( horse(XI) dog(Xl) )) shy
horse(Xl)
dog(XI)
4a
deaf(Xl) v dead(Xl) shy
be_shouted_at(X I)
no_response(X1)
Sa
box(sknl)
number(sknl2)
The above live translated expressions ( ie la through Sa ) will be printed on the
terminal and loaded to Prolog if assertion mode is used they will be printed on the terminal but
not loaded to Prolog if assertion-translation mode is invoked
Now if the original APC expressions ( ie 1 through 5 ) are typed to Prolog via query
mode or query-translation mode the corresponding questions will be translated into the following
queries
lb
goo(( condi(( mortal(Xl) man(Xl))) ))
b
goo(( soil horse(Xl) v dog(XI)) ))
3b
goo(( c1ause( contradiction(( horse(XI) dog(Xl) )) _) ))
4b
goo(( conditt deaf(Xl) v dead(Xl) (be_shouted_at(XI) no_response(Xl)) )) ))
5b
amp00(( so2( box(XI) ) s02( num(XI 2 )) ))
The above five translated queries ( ie Ib through 5b ) will be printed on the terminal
and loaded to Prolog if query mode is used they will be printed on the terminal but not loaded to
Prolog if query-translation mode is invoked
In the above queries goo 801 and 802 each forms a part of the inference mechanism of
APCIS goo occupies the top level of the inference mechanism whereas 801 and 802 are at the
1
next level 102 will take care of the searching of simple terms and 101 will deal with the
disjunctions of non-negated terms in the database We will come back to them in Section 4
At the first glance one may feel that the above translated Queries are Quite complicated
However a closer examination will reveal that they are not so Queries lb 3b and 4b can each be
categorized as a conditional query which is a distinct feature of APCIS wherels queries 2b and
5b lre asking simple facts in the database
To handle conditional queries we consider two cases First if the queries involve a
special clause contradition we invoke the built-in function el3ule(X Y) which will look for the
desired contradiction clause in the database Second if the queries do not involve the clause
contradiction we activate a defined Prolog predicate condi to take care of the necessary
searching (To avoid confusion the reader is urged to compare expressions started with the same
number in the above three sets of example)
To handle a query which asks a simple fact we surround each disjunction of terms with
the functor sol as in the example 2b or crown each simple term with the functor 802 as in the
example 5b
32 TranslatIon of Negated Term And Disjunction of Negated Terms
One feature of APCIS is its ability to handle input expressions consisting of only negated
term or a disjunction of negated terms in the forms
or
2 -(AI) v ~(A2) v v ~(An)
To handle the above two forms a special clause with clause head contradiction is
created This special clause head has only one argument which is either a term or a set of terms
grouped together in the form
8
(AI A2 An)
The right-hand side of the clause contradiction is exactly same as the argument in the clause
head For example the above two forms involving negated terms will be translated into the
corresponding forms as follows
1 contradiction( A ) shy
A
2 contradiction(( AI A2 An )) shy
AI A2 An
The design of the clause with clause head contradiction will greatly enhance the inference power
of APCIS (see the example in Section 44)
33 Translation ot Disjunction ot Non-negated Terms
Another feature of APCIS is its ability to handle input expressions involving a
disjunction of non-negated terms in the forms
1 Al v A2 v v An
or
2 Bl amp 32 amp amp Bm ==gt Al v A2 v v An
Unlike Prolog which accepts only Horn clauses APCJS will accept Horn clauses as well
as non-Horn clauses which take the above two forms The inference from non-Horn clauses is
made possible by the two defined predicates sol lnd s02 discussed in Section 42 and Section 43
respectively (see also the example in Section 44) In the APC translator the above two forms are
transbted into the corresponding forms as follows
1 Al v A2 v v An
2 Al v A2 v v An shy
g
Bl B2 Bm
34 Futher Transformation of Exceptions and Equivalences
To provide some backgrounds for the discussion of the further transformation of
exception and equivalence relations we will lirst reproduce the three goals in the Step 2 of the
APe translator discussed in Section 32 of [31
First expressions involving implication or the form A ==gt B will be transformed to
Second expressions with exception symbol or the form A - B will be changed to the
form ( A lt=gt -(B) ) amp ( -(A) lt=gt B)
Tbird expressions with equivalence symbol of the form -(A) lt=gt B or of the form
A lt=gt -(B) will also be converted to ( A lt=gt -(B) ) amp ( -(A) lt=gt B ) since tbere are
logically identical to exception relations Also expressions with equivalence symbol of the form
A lt=gt B or -(A) lt=gt -(B) will remain the same
After the Step] of the APe translator both sides of any transformed expression with
lt = gt symbol will be treated separately as if they are two independent expressions In the
Step 10 of the APe translator each side of lt=gt will again be treated separately and
transformed into a form similar to an transformed input query (see Section 31) Two examples
are given below
1 state(on) lt=gt -( state(olJ) )
2 all( 1 bot(l) amp humid(l) - winter(I) )
They will be transformed in the Step 2 or the APe translator into
1
(state(on) lt=gt -( state(off) ) ) amp ( -( state(on) ) lt=gt state(olJ) )
2
10
( hot(l) amp humid(l lt=gt -(winter(l)) ) amp
( -( hot(l) amp humid(l)) lt=gt winter(I)
In Step la they will again be transformed to
1
so2( state(on) ) lt=gt so2( contradiction( state(oH) ) )
so2( contradiction( state(on) ) ) lt=gt so2( state(oH) )
2
( s02(hot(XI)) so2(humid(XI))) lt=gt so2( contradiction( winter(Xl ))
so2( contradiction(( bot(Xl) humid(Xl) )) ) lt= gt so2( winter(XI) )
There are two advantages in the treatment of exception and equivalence symbols in this
way First it will prevent Prolog program from going into an infinite loop which is difficult to
avoid if equivalent relation such as A lt=gt B is transformed into the logically equivalent form
( A ==gt B) amp ( B ==gt A) Second by maintaining both sides of lt=gt symbol in
query form the searching on either side caD be done more easily and efficiently since the form
is already processed and does not need any further transformation
Inference Mechanism
As mentioned at the end of Section 31 goo sol and s02 each forms a part of the
inference mechanism of APCIS with goo occupying the top level and 80) and 802 the second
level In addition to these countl count2 equlv and impll are also at the second level of the
inference mechanism We will go over all of them in the following sections
I goo
goo is essentially the starting point of the inference Whenever a translated query is
loaded to Prolog system from temp-fie goo will go through one or more of the following steps in
11
sequence
G 1 Check if the query asks for the numbers of occurrence of certain term(s) It so then
pass It to eountl and eount2 else go to G2
G2 The query will be passed down to sol or s02 (or both) to check i( any assertion in the
database can satisfy the query It the answer is positive then the query succeeds else
go to G3
G3 The query will be passed to equlv to carry out further searching It the searching is a
success then the query will be closed with a success else go to G4
G4 It the query is in the form A ==gt B then it will be passed to Impli It Impll
succeeds then done else the query will be closed with a (ailure
42 sol
801 and 802 together with dis and eon form the most complicated part of the APCIS
iorerence mechanism In this and the next section we will look at sol and s02 dis and eon will
be discussed in Section 44 We will close Section 44 with an example that illustrates the
materials presented in Section 42 through Section 44
sol is at the second level of the inference mechanism It will deal with any disjunction of
non-negated terms For any disjunction passed to it it will go through one or more of the
following steps in sequence
S1 Check if any term In the disjunction can be satisfied by any term or clause in the
database without contradiction It so then done else go to S2
S2 Pass the disjunction together with another disjunction (and its tlil) picked up from
the database to dis It dis succeeds then done else go to S3
S3 Pass the disjunction down to equlval which will check if any term in the disjunction
matches either side of any equivalence relation in the database It such a match is
found then check if the other side of the equivalence C3n be satisfied It so then done
else the goal fails
43 s02
s02 is also at the second level of the inference mechanism It will take care of all the
simple terms in the transl1ted query The following is the sequence that s02 wiII follow in
searching
S1 Check if the term passed to it caD be s3tisfied by any term or clause in the d3tabase
without contradiction It so then done else go to S2
S2 Pass the term together with a disjunction of terms (and its tail) picked up from the
database to dis If dis succeeds then done else the goal fails
44 dis and con
dis has three arguments In the first two clauses of dIs the first argument P v Q is
found in the database using the builtmiddotin functiol clause and the third argument R is the tair of
the term or the clause P v Q If P v Q is not a clause but a term R will be instantiated to trUE
The second 3rgument comes from either lIol or 802 and thus takes the form of either X v Y (a
disjunction of terms) or T (3 simple term)
All the clauses of dis together with con will perform the searching as exemplified in the
following algorithm (we will keep the notationsin this section)
01 Check if every term in P v Q is in X v Y It so then go to 03 else go to D2
02 For any term (in P v Q) which is not in X v Y or does not match T perform the
following tests
a Check if the term (in P v Q) has already been negated in the datab3Se (ie check if
the contradiction of the term exists in the d3tabase) If so then repeat D2 for other
terms not found in X v Y or not matching T else go to b
13
b Check if the contradiction of the term matches either side of any equivalence
relation in the database If such a match is found then check if the other side of the
equivalence can be satisfied If so then repeat O~ for other terms not found in X v Y
or not matching T else the goal fails
It all the terms (in P v Q) which are not in X v Y or do not match T survive either one
of the above two tests then go to 03
03 This step is essentially done by eon whose goal is to satisfy the tail R of P v Q It
con succeeds then done else the search fails
To close this section we will give an example to illustrate what we have covered In
Section 42 through Section 44
Example Assume that we already haye the following expressions in the database
horse(skml) v dog(skmI)
contradiction(( dog(XI) ))shy
dog(XI)
query goo(( soZ horse(X)) ))
This query will be passed to 802 which will check it the term horse() can be satisfied iu Step S 1
of Section 43 It is a failure So we now go to Step S2 In this step we pick up the disjunction
horse(~kml) v dog(skml) (and its tail true) in the datab3Se and pass it together with the term
horse(X) to dis We are now in Step 01 of Section 44 In this step we find that dog(skml) does
not match horse(X) So we have to go to Step 02 In Step 023 We find that the term dog(skml)
has already been negated (the second expression in the database) So we go to next step 03 Since
the tail of the disjuDction horse(skml) v dog(skml) is the atom true con is satisfied and the
query succeeds
45 countl and count2
countl and count2 are responsible for the counting of tbe numbers of occurrence of a
given simple term or a conjunction of terms They are activated by input queries in the form
q( exists( X whatnum amp P) )
where whatnum is the l~bel for activating the counting of the numbers of occurrence of P which
can either be a term or a conjunction of terms
countl will count the number of term(s) which will satisfy P and associate(s) with
numerical quantification(s Two counters are set to update the lower and upper boundary or the
scope or the numfrical quantifications encountered
The contents of the two counters are then passed to count2 which is responsible for the
counting or the following three types of term First term(s) which will satisfy P and associate(s)
with existential quantification(s Second term(s) which will satisfy P and has(have) Prolog atom
as its(thfir) argument(s) Third term(s) that will satisfy P and itself(themselves) is(are) Prolog
atom(s )
46 equiv
equlv will be activated only after sol and B02 have failed The first two goals of equlv
are similar to that of Step S3 in Section 42 and Step D2b in Section 44 The third goal or equiv
makes possible the inference on either side of any equivalent relation For example if we type the
following three expressions to Prolog in assertion mode
l all( X hot(X) amp humidX) - winter(X)
2 all( X hot(X) amp bumid(X) ==gt unpresent(X))
3 - ( exists( X winter(X) ) )
and then ask APCIS in query mode
q( cxists( X unpresent(X) ) )
15
APCIS with the aid of equlv will be able to answer yes to this query
41 lmpll
lmpll can be considered as the last attempt that APCIS would make to satisfy a
query It is activated only after equlv has failed It will first check if the query is conditional If
so it will convert the implication symbol to equivalence symbol and search if such an equivalent
relation can be found in the database If so a success Otherwise a failure
5 More on the Inference Mechanism
Having looked at all the subparts at the top two levels of the inference mechanism we
are ready to look at other subparts at lower levels
51 num and cnum
One distinct fe3ture or APCIS is its ability to deal with numerical quantifications As
mentioned in Section 31 input queries and assertions will undergo different transformations in
the last step (Step 10) of translation This also holds true for expressions involving numerical
quantifications Consider the following expression
exists( 6 X horse(X) )
If it is entered to Prolog via assertion mode we will after going through all the steps of
translation have the rollowing entered to the database
horse(sk n I
number(sknl6)
Now if we want to ask Are there more than five horses 7 and type in
q( exists( gt5 X horse(X) ) )
1amp
APCIS will translate the question and enter to Prolog the following query
goo(( s02( horse(X) ) s02( num( X gt5 )) ))
Note that the term number(slml 6) in the database and the term num(X gt S) in the query are
different predicates and this difference is exactly where the power of the clause num(X N)
defined in APCIS comes from When the clause num(X N) in APCIS is activated it will search
through the database to see if there is any term of the form number(X I) whose first argument
matches the first argument of num(X Y) in the query It a match is found the second arguments
of both num(X Y) in the query and number(ltI) in the database will be passed to cnum in
APCIS
The job of cnum is to compare the numerical messages carried by the second
argument or the term rlum(X Y) in the query and the second argument of the term rlumber(X I)
in the database to see if they match with each other according to the rules defined in cnum
While there are 25 rules for such matching purposes the idea is simple
Imagine that the second argument Y of the term num(X Y) in the query
and the second argument I of the term num()( I) in the database each occupies a
place in an integer line (Le the integer line in mathematics) To have a match
the domain covered by Y should contain the domain covered by L
As an example the answer to the above query is positive since the domain of gt5
contains the domain or 6
Before closing this section we will bring out a speciaJ translation aspect of expressions
involving numbers by an example We first type to APCIS the Collowing expressions in assertion
mode
1 aU(X all(Y father(X Y) amp number(Y gt6) ==gt has_manY3hildren(X) ))
2 exists(X exists( 12 Y Cather(X Y) ) )
11
After going tbrougb all tbe translation steps tbe Collowing two expressions will be entered to tbe
database
I
bas_many_cbildren( Xl ) shy
Cather( Xl X2 )
num( X2 gt6 )
2
Catber( sk m1 sk n2 )
number( skn2 12 )
lotice that whenev(gtr a term with Cunctor number appears at the rigbt-band side oC a Prolog
clause its Cunctor will be cbanged to num automatically This treatment will greatly cnbance tbe
inference power of the clause sbown in l above For instance iC we now ask tbe question
q( exists( X bas_many_children(X) ) )
The right hand side oC the clause l will match the two terms in 2 and tbe query succeeds
52 Bel and cael
A special feature of APe is tbat all predicates tbat express relations = = gt
gt= lt and lt= can be expressed explicitly using infix notations as relational statements
called selectors To handle selectors we defined Bel in APCIS
Every expression involving selectors will undergo different translations in assertion mode
and query mode For example the assertion
a( exists( [X Y] box (X) amp box(Y) amp (weigh t(X) gt weight(Y) ) ) )
will be translated into the following three terms and entered to tbe database
box( skml )
box( skm2 )
18
weight( skm 1 ) gt weight( skm2 )
Now it we want to ask Is it true that there exists two boxes of different weights and type in
q( exists( [X Yl box(X) amp box(Y) amp ( weight(X) = weight(Y) ) ) )
The question will be transformed to the following query and entered to Prolog
goo(( so( box(XI) ) s02( box(X2) ) so2( sel( weightXI) = weight(X2) )) ))
Note that the selector in the above query is surrounded by the functor set When any clause or
8el in APCIS is activated it will search through the database to see it there is any selector whose
two arguments (left and right side or any selector symbol) match the two arguments of the
selector in the query At the same time 8el will check iC the selector symbols (may be different) or
the two different selectors (one in the query and one in the database) satisfy the rules defined in
sel There are 12 matching rules defined in sel All oC them ~re straightforward and will not be
discussed here An example will be enough to explain how 8el works
Consider the execution of the above transformed query The first two terms in the query
are satisfied by the first two terms in the database and Xl and X2 are instantiated to skml and
skm2 respectively The third term of the query will be passed to eel (of APCIS) which finds a
match on each side of the two selectors (one in the query and one in the database) At the same
time the two different selector symbols gt and = are found to satisfy one of the rules in
8el As a result the query succeeds
To enhance the inference power of clauses involving selectors all the selectors appearing
on the rightmiddothand side oC any clause will be surrounded by a functor set The idea is similar to
that in the last part of the previous section
c8el is exactly the same as 8el functionally It provides a convenient way to compare
selectors when dis is being executed
19
8 Printing Result
Whenever a goal is successfully executed APCIS will not only response with a yes but
also print out the matched terms or clauses in the database This is made possible by the built-in
function bagor and the two predicates wout and prt defined in APCIS
7 Summary
In this paper a description of a deductive inference system called APCIS (Annotated
Predicate Calculus Inference System) has been provided APCIS is able to carry out inferences
from expressions involving numerical quantifiers selectors disjunctions of non-negated terms
negated terms disjunctions of negated terms equivalences and exceptions It is also able to count
the numbers of occurrence of a given simple term or a conjunction of terms
The main idea of APCIS is that each input APC expression is first passed to a
preprocessor ( ie APC translator ) which dissolves and transforms each APC expression into
Prolog expression(s) which will then be loaded to Prolog system The user bas to specify whether
each input expression is to be entered as an assertion or as a query by invoking either assertion
mode or query mode respectively Each assertion or query will undergo different transformations in
the preprocessor The different treatment of assertion or query not only allows a full uS1ge of the
Prolog inference mechanism but also makes possible a higher level of inexact pattern matching
exemplified by the examples in Section 51 and Section 52 where the four predicates num
cnum sel and csel are discussed This higher level of pattern matching increases the inference
power of APCIS greatly
The design of contradiction and the treatment of the disjunction of non-negated terms
allow APCIS to accept non-Horn clauses and to carry out inference from them This feature
makes APCIS more general than Prolog
20
While APCIS performs very well in many sets of arguments provided by the author it is
still too early to jump to conclusion that it can perform equally well in all types of problems In
any event the expressiveness of APC has greatly been retained in the present version of APCIS
and moreover some design ideas or APCIS mentioned in this paper are not restricted to APCIS
- they may be carried over to learning programs with narrower scopes
21
References
[1] W F Clocksin and C S Mellish Programming In Prolog Springermiddot Verlag Berlin Hpoundidelberg 1981
[2] R S Michalski A Theory and Methodology of Inductive Learning Chpt 4 Machine L earning Tioga Publishing Co Palo Alto CaliJornia 1989
[3] K-E Pua Translating Annotated Predicate Calculu8 to Prolog ISG Report 84middot1 UlUCDCSmiddotFmiddot918 University oj Illinois Urbana IL June 1984
22
Appendix A
APCIS Users Manual
1 Get Started
Users are urged to follow the steps depicted below
1 Get the PROLOG interpreter by typing
alias prolog mntb2sammutsammutprologprolog (Vax A)
or
alias prolog mntb2sammutsammutbinprolog (Vax B)
2 Load apc and infer by typing
prolog apc infer
When large APC expressions are expected we can increase the stlck by typingI
prolog -snnnn ape infer
where ns denote the number of stacks in decimal
3 When the wording LSW - PROLOG appears on the terminal we are reldy to interact
with APCIS The four modes by which we can invoke APCIS are summarized below
a Assert ion-Translation Mode
ta(X)
b Query-Translation Mode
tq(X)
c Assertion Mode
a(X
d Query Mode
q(X)
23
where Xs are APC expressions
2 Notations Used in APCIS
Below is a summary or notations used in APCIS
a Logical operators
amp
v
==gt
lt=gt
-
negation
conjunction
disjunction
implication
equivalence
exception
b Binary relation symbols in selectors
-
=
gt=
lt=
gt
lt
equal
not equal
greater or equal
smaller or equ al
greater
smaller
c Relational operators in numerical quantifiers
lt less than
lt= less than or equal
gt greater than
gt= greater than or equal
d BinlTY operator in numerical quantifier
range
e Universal quantifier
all(X p(X))
f Existential quantifier
exists(X p(X))
g Numerical quantifier
exists(I X p(X))
where p(X) is a formula
where X is a variable or a Jist of variables or the
form [HI~rj and p(X) a formula
where I repersents expression involving integer(s)
and operator(s) in c or d above and p(X) a formula
25
Appendix B
APCIS Program Listings
------------------------------- Program Name APCIS - Part 1 APC Translator
-------------------------------
op(3OO fx -)1
op(500 xfy amp)
oPt 500 xfy v)
op(600 xfx )
op(700 fx [gt= lt= gt lt ]) op(400 xfy [= gt= lt= gt lt ])1 op(900 xfy gt lt=gt -])1
steps(X Xg) shy
numbervars(X 1 J Step 1 change variables to iis
rmimp(X X) Step 2 conv(X X3) Step 3
rewrite(X3 X4) Step 4
negin(X4 X5) Step 5
dropexist(X5 X6 1]) Step 6
dropall(X6 X7) Step 7
distrib(X7 X8) Step 8 clausiCy(X8 X9 [J) Step 9
ta(X) shysteps(X Xg)
(( Xg = II nl
print( yes it is always true) )
( nl nl printcl(X9))) Step 10a
tq(X) shy
steps(X Xg)
prques(Xg)
28
Step 2 Removing implic3tions amp Transforming exceptions and equiv3lences
rmimpl( P - Q (PI lt=gt (QI) ) amp ((PI) lt=gt QI) ) -
rmimpl(P PI) rmimpl(Q QI)
rmimplnp) lt=gt Q (PI lt=gt -(QI)) amp nPI) lt=gt QI) ) - 1
rmimpl(P PI) rmimpJ(Q QI)
rmimpJ(P lt-gt -(Q) (PI lt=gt -(QI)) amp nPI) lt=gt QI) ) -
rmimpl(P PI) rmimpl(Q QI)
rmimpl( P lt=gt Q PI lt=gt QI ) - I
rmimpl(P PI) rmimpl(Q QI)
rmimpl( P ==gt Q -(PI) v QI ) - I
rmimpl(P PI) rmimpl(Q QI)
rmimpl( all(X P) aI(X PI) ) - 1
rmimpl(P PI)
rmimpl( exists(X P) exists(X PI) ) -
rmimpl(P PI)
rmimpl( exists(I X P) exists(I X PI) ) -
rmimpl(P PI)
rmimpl( P amp Q PI amp Ql ) -
rmimpl(P PI) rmimpl(Q Ql)
rmimpl( P v Q PI v QI ) -
rmimpl(P PI) rmimpl(Q QI)
rmimpl( -(p) -(PI) ) - I
rmimpl(p PI)
rmimpl( P P )
St~p 3 Converting numerical amp distinctive quantifiers
L Numerical quantifiers
examples of input forms
1 exists(gt= i X pIX)) where i is an integer
2 exists(i X pIX)) where i is an integer
3 exists(i j X pIX)) where i j are integers and iltj
4 exists(il v i2 X pIX)) where is are integers
examples of output forms of this step
1 exists(X pIX) amp number(X gt= i) )
2 exists(X pIX) amp number(X i) ) 3 exists(X pIX) amp number(X ij) ) 4 exists(X pIX) amp number(X il v i2) )
II Distinctive quantifiers
27
example or input Corm
exists([XYL p(X Y))
example or output Corm or this step
exists(X exists(Y p(XY)) )
conv(P lt=gt Q PI lt=gt QI) - 1
conv(P PI) conv(Q QI)
conv(al1(X P) all(X PI)) -
conv(P PI)
conv(exists(HIT] P) R ) - conv(P PI) convert distinctive quantifier
convtdis(exists([HIT]PI) R)
conv( exists(I X P) exists(X PIamp number(X I) )) -
conv(P PI) convert numerical quantifier
conv(exists(X P) exists(X PI)) - 1
conv(P Pl)
conv(P amp Q PI amp QI) - 1
conv(P PI) conv(Q QI)
conv(P v Q PI v QI) - t conv(P PI) conv(Q QI)
convC(P) -(PI)) -
conv(P PI)
conv(P Pl
convtdis(existsl[XL P) exists(X P)) - atomic(X) convtdis(exists[XIYj Pl exists(X R)) shy
convtdis(exists(Y P) R)
Step 4 Rewriting compound predicates andor compound selectors
Outputs are smiple predicates andor simple selectors
rewrite(P lt=gt Q PI lt=gt QI) - t rewrite(P PI) rewrite(Q QI)
rewrite(all(X Pl all(X PI)) - 1 rewrite(P PI)
rewriteexists(X P) exists(X PI)) - I rewriteP PI)
rewrite(P amp Q PI amp QI) - rewrite(P P 1) rewrite( Q Q 1
rewrite(P v Q PI v QI) - 1
rewrite(P PI) rewrite(Q QI)
rewriteC(P) -(PI)) - I
28
rewrite(P PI) rewrite(F(A B) R) -
rewrite(A AI) rewrite(B BI) re(F(AI BI) R)
rewrite(F(A) R) -
rewrite(A AI) re(F(AI) H)
rewrite(F(A B C) R) -
rewrite(A AI) rewrite(B BI) rewrite(C CI) re(F(AI BI CI) R)
rewrite(F(A B C D) R) -
rewrite(A AI) rewrite(B Btl rewrite(C CI) rewrite(D DI) rc(F(AI BI CI Dl) H)
rewrite(PP)
re(F(A B v el (RI v R2) -
re(F(A Bl RIl re(F(A C) R2) reF(A B amp cl (RI amp R2)) -
re(F(A B) RI) re(F(A e) R2) re(F(A amp B C) (Rl amp R2)) -
re(F(A e) R 1) re(F(B C) R 2) re(F( v B el (R I v R2)) -
re(F(A el R I) reFB el R2) re(F(A amp Bl (R I amp R2)) -
re(F(A RI) re(F(BJH2) re(F(A v B) (R 1 v R2)) -
re(F(A) RI) re(F(B) R2)
re(F(A vB c Dl (RI v R2) -
re(F(A C D) RI) re(F(B C D) R2) re(F(A amp B C D) (RI amp R2)) -
re(F(A C D) Rll re(F(B C D) R2) re(F(A B v C D) (HI v R2)) -
re(F(A B D) RI) re(F(A C D) R2) re(F(A B amp C D) (HI amp R2)) -
re(F(A B D) RI) re(F(A C D) R2) re(F(A B C v D) (RI v R2)) -
re(F(A B C) R I) reF(A B D) R2) re(F(A B C amp D) (RI amp R2)) -
29
re(F(A B C) RI) re(F(A B D) RZ)
re(F(A v B e D E) (R I v R2)) -
re(F(A e D E) R I) re(F(B e D El R2) re(F(A amp B e D E) (RI amp RZ)) -
re(F(A e D El R 1) re(F(B e D E) R2) re(F(A B v e D E) (R I v R2)) -
re(F(A B D E) RI) re(F(A e D E) R2)
re(F(A B amp e D E) (RI amp R2)) -
re(F(A B D El RI) re(F(A e D E) RZ) re(F(A B e v D E) (R I v R2)) -
re(F(A B e El R 1) re(F(A B D E) RZ) re(F(A B e amp D E) (RI amp RZ)) -
re(F(A B e E) R I) re(F(A B D E) RZ)
re(F(A B e D vEl (RI v RZ)) - l
rc(F(A B C D) RI) re(F(A n e El RZ) re(F(A B e D amp El (RI amp RZ)) - ~
re(F(A B e D) RI) re(F(A B e El RZ)
re((A = B) (A = B)l-
re((A = Bl (A = 8)) -
retIA gt= BI (A gt= B)) -
re((A lt= B) (A lt= B)) -
re((A gt B) (A gt B))-
re((A lt Bl (A lt Bl)- re(A A)
Step) Bringing n(gation inwards
Degin(-(P) PI) - neg(P Pl)
negin(P lt=gt Q PI lt=gt Ql) - ~
negin(P PI) negiD(Q QI)
Degin(aU(X P) all(X PI)) - Degin(P PI) negin(exists(X P) exists(X PI))- negin(P PI) negin(P amp Q PI amp Ql) - Degin(P PI) negin(Q Ql)
Degin(P v Q PI v QI) - Degin(P PI) negin(Q QI) negin(P Pl
neg(-(P) PI) - negin(P PI)
neg(all(X P) exists(X PI)) - neg(P PI)
30
neg(exists(X P) all(X PI)) - neg(P PI)
neg(P amp Q PI v QI) - neg(P PI) neg(Q Ql)
neg(P v Q PI amp QI) - neg(P PI) neg(Q QI)
neg(P -(PH
Step 6 Dropping existnetial quanti6ers
dropexist(P lt=gt Q PI lt=gt QI Elerns) - dropexist(P PI Elerns) dropexist(Q QI Elerns)
dropexist(alJ(X P) all(XPI) Elerns)
dropexist(P PI [XIElernsJ)
dropexist(exists(X P amp nurnber(X Yraquo P2 Elerns) -
genfun(skn Newg) Fun = [NewgIElerns]
subst(FuD X P amp Dumber(X Y) PI)
dropexist(Pl P2 Elerns)
dropexist(exists(X P) PZ Elerns) -
genfun(skrn Newf) Fun = [NewfIElernsJ
subst(Fun X p PI)
dropex ist(P 1 P~ Elerns)
dropexist(P v Q PI v QI Elerns) - ~
dropexist(P PI Elerns) dropexist(Q Ql Elerns)
dropexist(P amp Q PI amp QI Elerns) - 1
dropexist(P Pl Elerns) dropexist(Q QI Elerns)
dropexist(P P _)
gen fun(R oot Newn arne) shy
getnurn(Root Nurn)
narne(Root Rootlist)
append(Rootlist[Nurnj Narnelist)
concat(Narnelist Newnarne)
getnurn(Root Nurn) shy
retract(currentnurn(Root Nurn 1 raquo
Nurn is Nurni + 1
asserta(currentnurn(Root Nurn))
getnurn(Root 1) - asserta(currentnurn(Root 1))
subst(New Old Val Val) - var(Val)
subst(New Old Old New) - 1 substNew Old Val Val) - atornic(Val)
31
subst(New Old Val Newval) shy
runctor(Val F N)
CUDctor(Newval F N)
subst_args(N New Old Val Newval)
subst_args(O J J - J J
subst_args(N New Old Val NewVal) shy
arg(N Val OldArg)
arg(N NewVal NewArg)
subst(New Old OldArg NewArg)
NI is N - I
subst_args(Nl New Old Val NewVal)
append([J L L) -
append([XILl] L2 [XIL3]) - append(Ll L2 L3)
Step - Dropping universal quantifiers
dropall(P lt=gt Q PI lt=gt QI)-
dropall(P PI) dropall(Q QI)
dropall(all(X P) PI) - ~ dropall(P PI)
dropall(P amp Q PI amp QI) -
dropall(P PI) dropall(Q QI)
dropall(P v Q PI v QI) -
dropall(P PI) dropall(Q QI)
dropall(P P)
Step 8 Distributing conjunctions over disjunctions
distrib(P lt=gt Q PI lt=gt Ql) - t distrib(P PI) distrib(Q QI)
distrib(P v Q R) -
distrib(P PI) distrib(Q QI)
distributing(PI v QI R)
distrib(P it Q PI it QI) -
distrib(P PI) distrib( Q QI)
distrib(P P)
distributing((P amp Q) v R PI amp QI) -
distrib(P v R PI) distrib(Q v R Ql)
32
distributing(P v (Q amp R) PI amp Ql) -
distrib(P v Q PI) distrib(P v R Ql)
distributing(P P)
Step 9 Packing each conjunction into clauses
c1ausify(P amp Q CI C2) -
clausiCy(P CI C3) c1ausify(Q C3 C2)
cbusiCy(P [d(A B)ICs] Cs) shy
inclause(P A [j B [I) 1
c1ausiry( C C)
inclause(P v Q A AI B B1) -
inc1ause(P A2 AI B2 Bl)
inclause(Q A A2 B B2)
inclausenp) A A B1 B) -
notin(P A) putin(P B B1)
inclause(P AI A B B) shy
notin(P Bl putin(P A AI)
notin(X [XU) - fail
notin(X [JLj) - notin(X L)
notin(X 1])
putin(X II [X]) - 1
putin(X [XILJ L) -
putin(X [YILJ [YILl]) - putin(X L Ll)
Step 1Oa Printing clauses
printcl([]) - nl nl
printcl(c1(AB)ICsj) - printcl(A Bl nl printcl(Cs)
printcl(L II) - printdis(IL) prinr)middot
printclHl L) - prin(contradiction(() printconl(rL)
print()) - ) printconj(rL) prinr )
printcl(Ll L2) shy
printdis(ILl) print( - ) printconj(rL2) prin()
printdis(S[Lj) - printcbar(SL)
33
printdis(S[LILs]) - printchu(SL) prin( v) printdis(SLs)
printconl(S[LI) - printchar(SL)
printconl(S[LILs]) - printchar(SL) prin( ) printconl(SLs)
printconj(S[L]) - tab(3) printchar(SL)
prin tconj( S [L IL sl) shy
tab(3) printchar(SL) print( ) printconj(SLs)
printchar(SP) shy
atomic(P)
name(P L)
L = [IT]
concat([XIT NewP)
prin(~ewP)
printchar(SP) shy
atomic(P)
prin(P)
printchar(SA lt= gt B) -
prin((l clausify(A AI [j) pl(eAl) prin())
print lt=gt )
prin(() cbusify(B Bl [I) pJ(eBl) prine))middot
printchar(rnumber(X N)) shy
prin(num() printchar(rx) prin( )
printchar(rN) prinC))
printchar(rF(A B)) shy
seJec(F(A B))
prinCsel() printchar(rA)
prin( F ) printchar(rB) prinC))
printchar(SF(A B)) shy
( selec(F(A B)) F = infix )
printchar(SA) prin( F ) printchar(SB)
printchar(SF(A)) shy
(F= prefix gt= F= prefix lt= F= prefixgt F= prefix lt )
prin(F ) printcbar(SA)
printchar(SP) shy
functor(P F MaxN)
prin(F ()
Nl is MaxN - 1
putout(S N 1 P MaxN)
34
prin())
putout(S 0 P MaxN) -
arg(~laxN P Argu)
prin tchar(SArgu)
putout(S N p MaxN) shy
Nt is MaxN - N arg(NI P Argu)
printcbar(SArgu )
prin( )
N2 is N - 1
putout(S N2 P MaxN)
selec(FA B)) shy
( F= infix = F= infix f= F= infix gt=
F= infix gt F= infix lt= F= infix lt )
35
----------------------------------Program Name APClS - Part 2 Inference Mechanism ---------------------------------- a(X) shy
steps(X X9)
(( X9 =[] nl
print( yes it is always true) )
( X9 =[cI(IJ[])] nl
print( no it is always false) )
( nl nl printel(X9) Step 1Oa
tell(temp_file) printel(X9) e1ose(temp_file) consult(temp_6Ie) ))
q(X) shy
asserta( in pt(X))
steps(X X9)
(( X9 = [] print(middot~H~~middot~t~)
print(THE AiSWER IS YES)
print( ilgIQlQl(~) )
( X9 = [e1([j [j)] Pr1nt ( OJ fi(i I~ iii Ij)middot(i)(i) fiyenQ)riiio(i)(ij)(i)fj)fiyen1li1il1li1il)__ gtw~ __~_~ _~~_ ~_-=~
print(THE ANSWER IS NO ) print() )
( teI1(temp_6Ie)
prques(X9) Step 1Ob
close(temp_file)
nl print(Let me think about it) nl
consult(temp_6Ie) ))
retrac t( in pt(X))
Step lOb Printing question
prques(lcl(A 8)1) - prin(goo(() pl(qA 8) print()))
prques([c1(A 8HCs]) - prin(goo(() pl(qA 8) print() pl(q Cs)
pl(e [c1(A 8)]) - pl(eA 8)
pl(q [c1(A 8)]) - pl(qA 8) print()))
pl(S [e1(A B)ICs]) - pl(SA B) prin( ) pl(S Cs)
38
pl(q [j L) - prin(c1ause(contradiction(() pcont(qL) prin())_))
pl(S [I L)- prin(so2(contradidion(() pcont(SL) print))))middot
pl(S [L] []) - prin(so2() pcbar(SL) prin())
pl(S L [J)- prinsol() plett(SL) print))
pl(S [L] LI) - prin(condi(() pchar(cL)
prin(() pcont(S Ll) prine))))
pl(S L Ll)- prin(c1ause() plert(cL)
prin(() pcont(S Ll) prine)))
plert(S[LJ) - pchar(SL)
plert(SjLILsj) - pcbar(SL) print v) pleCt(SLs)
pcont(S[L]) - pchar(SL)
pcont(S[LILsj) - pcbar(SL) prinr ) pcont(SLs)
pcbar(SP) shy
atomic(P)
name(PL)
( L = [IT] L = [5 k miT] L = [5 k niT] )
concat[XITj NewP)
prin(0JewP)
pchar(SP) shy
atomic(P)
prin(P) pchar(SA lt=gt B) -
prin(() dausify(A AI []) pl(eAI) prin())
prinr lt=gt ) prin(() dausify(B BI ]) pl(eB) print))
pchar(Snumber(X N)) shy
prin(num() pchar(SX) prin()
pchar(SN) prinr))
pcbar(SM N) - prin(M N)
pcbar(cF(A B)) shy
selec(F(A Braquo
pcbar(cA)
prine F ) pchar(cB) pchar(SF(A B)) shy
selec(F(A B))
prin(sel() pchar(SA)
print F ) pchar(SB) print)) I
31
pc har(SF(A)) shy
( F= prefix gt= F= prefix lt= F= prefixgt F= prefix lt )
prin(F ) pchar(SA)
pchar(SP)shy
runctor(P F MaxN)
prin(F ()
011 is MaxN - 1 pout(SNl P MaxN)
print) )
pout(S 0 P M3xN) - 1
arg(~bxN P Argu)
pchlr(SArgu )
pout(S N P MaxN shy
Nl is MaxN - N
arg(Nl P Argu)
pchar(SArgu
prin( )
N2 is N - 1
pout(S N2 P ~13xN)
Comparing numbers in numerical quantifiers
num(XN) shy
number(X I)
cnum(N 1) ~
cnumlaquo=01 lt=I- N gt=I
cnumlaquo=J lt I) - N gt=1-1
cnumlaquo=NIJ) - N gt=J 1
cnumlaquo=N J)- integer(I) N gt=I~
cnum(gt=N gt=1) - N lt=1
cnum(gt=N gt I) - N lt=1+ 1 cnum(gt=NIJ) - N lt=1
cnum(gt=N lt=1)- N lt=1
cnum(gt=N lt I) - N lt=1 L cnum(gt=N 1)- integer(I) N lt=1
cnum( lt N lt 1)- N gt=1 L
38
cnum( lt N lt=1) - N gt I cnum( lt NLJ) - N gt J
cnum( lt N 1)- integer(I) N gt 1
cnum(gt N gt I) - N lt=1 cnumlgt i gt=1) - N lt I
cnum(gt N lt=1) - N lt=0
cnum(gt N lt I) - N lt=0
cnum(gt iIJ) - N lt I cnum(gt N 1)- integer(I) N lt I
cnum(~LN lt=1) - M=I N gt= I l
cnum(~LN lt I) - M=l N gt= I-I
cnum(~LNLJ) - M lt =1 N gt = J
cnum(~1N 1)- integer(I) M lt= I N gt= I
cnum(- N) - integer(N)
Comparing selectors
sel(X = Y) shyX= Y
sel(X I=Y) shy(X I=Y X lt Y Xgt Y)
sel(X gt Y) shyXgt Y
sel(X lt Y) shyXlt Y
selX gt=Y) shy(X gt=Y X= Y Xgt Y)
se(X lt=Y) shy
(X lt=Y
X= Y
X lt Y)
csel(infix = infix =)
39
csel(infix = infix = csel(infix = infix gt)
csel(infix = infix lt) csel(infix gt infix gt) cseJ(infix lt infix lt) csel(infix gt= infix gt=) csel(infix gt= infix gt csel(infix gt= infix =)
csellinfix lt= infix lt=) csel(infix lt= infix lt) csel(infix lt= infix =)
Finding solutions
sol(X v Y) -
(( notetra(X) eon(X) ( sol(Y) )
( c1ause(P v Q R) not(cketra(P v Q))
dis(P v Q X v Y R) ~ )
( A lt=gt B equival(A lt=gt B X v Y) ~ I) sol(X) - ~ notetra(X) eon(X)
so~(X) - notetra(X)
( con (X)
( clause(P v Q R) not(ekctra(P v Q)) dis(P v Q X R) I)
cketra(P v Q) -
eketra(P) eketra(Q) eketra(F(I J)) shy
selec(F(I J))
c1ause(contradiction(sel(F(IJ))) _I
eketra(number(W I)) -
clause(cootradietion(num(Wl)) - eketr(P) shy
clause(contradiction(P) - 1
notctra(P) shy
not( e lause( con tradiction(P) _))
40
Searching (or disjunctions
dis(P v Q X v Y R) - dis(P X v Y R)
dis(Q X v Y R) con(R)
dis(P v Q X R) -
dis(P X R) dis(Q X R) con(R
dis(P X v Y R) - clause(contradicton(Pl J 1
dis(F(I J) sel(G(I J)) v Y R) - csel(G Fl dis(number(WI) num(W N v Y R) - cnum(N I)
dis(P P v Y R) -
dis(P X v Y R) - dis(P Y R)
dis(F(I J) seJ(G(IJ)) R) - csel(G F)
dis(number(WI) num(WN) R) - cnum(N I) dis(P P R) - 1
dis(FJ J X R) shy
( ckctra(F(IJ) cbeckeq(seJ(F(IJ))) )
dis(number(W Il X R) - ( ckctra(number(WI)) cbeckeq(num(WI)) )
dis(P X R) shy( ckctra(P) cbeckeq(P) ) 1
cbeckeq(P) shy
(( A lt=gt so2(contradiction(P))
bagof(A A [jj) ) ( so2(contradiction(P)) lt=gt B
bagof(B B Uj) ))
ckeq(A) shy
( so2(A) lt=gt B B lt=gt so2(A) ) bagof(B B UJ)
con((P Q)) -
clause(P R) con(R) con(Q) con(true) -
con(contradiction(P)) - clause(contradiction(P) J
con(cause(X Y)) - cause(X Y)
con(sel(X)) - sel(X)
con(num(X Y)) - num(X Y) con(P)- (( dause(P R) (con(R) ckeq(R)))
colJectin(P) )
collectin(P) shy
bagof(S (c1ause(P S) S = true) [L LIJ )
mkcon(L Ll L)
bagor(l (L2 ) UJ) L
mkcon((A AI) (B B1) (sol(A v B) e D)) -
mkcon(A B1 e) mkcon(A1 (B Bl) D)
mkcon(A (B B1) (sol(A v B) e)) -
mkcon(A Bl e)
mkcon((A AI) B (sol(A v B) e)) middot1
mkcon(Al B e)
mkcon(A B sol(A vB))
Searching ror equivalences
equival(A lt=gt B X v Y) - 1 ( equival(A lt=gt B X) equival(A lt=gt B Y) )
equival(s02(A) lt=gt 502(B) A) - clause(B _I equival(s02(B) lt=gt 502(A) A) c1ause(B _I
Top level or inrerence mechanism
goo((s02(whatnum) P)) -
getatm(P Xl
bagor(number(X Y) ( P so2(number(X Y)) ) A )
count1(A 00 L R) nl
bagor(X P B )
count2(B L R Ll Rl) nJ print()
(( LI = 0 Rl = 0 print(THE ANSWER IS ) nl
(( Ll = Rl prin(-Jumber or ) prn(P) print(is Ll) )
( Rlgt20000 prin(Number or I prn(P) print(is LI or more) )
42
( prin(Number of ) pfn(P) print( is from Ll to Rl) )) )
( print(THE ANSWER IS NO I )) print()
goo(X) shy
(( bagof(X X L) L = [I nl print()
print(THE ANSWER IS YES) nl wout(L) print() )
( equiv(X L) nl print()
print(THE ANSWER IS YES) nl wout(L) print(-) )
( c1ause(inpt(A ==gt B) _I ( impli(A B Z) impli(B A Z) ) print(l~Hl)
printTHE ANSWER IS YES) nl print(Z) print(Hj~(fH~) ))
goo(X) print( Hg)
print(THE ANSWER IS NO ) print( lH~lH~gg9l9lmiddotmiddot~Q(gmiddot)
00 Semhing for implications in equiV3lent relations
impli( B Z) shyt-ell( z1) prin(templ() pchn(S A lt=gt B) print()) close ( zl) consult(zl) templ(Z)
unload zl Z
Searching for equivalence
equiv (X L)
(( X lt=gt Y
equ(Y YI)t bagof(Y Yl L) L = [j )
(Y lt=gt X equ(Y YI) bagof(Y Yl L) L = [J )
( X = F(New)
clause(~ew T) makeup(T Tl)
(( Tl lt=gt B
equ(B Bl) bagof(Bl Bl M) M = [j L=[Newl )
(A lt=gt TI
equ(A AI) bagof(Al AI M) M = 1] L=INewj )) ))
makeup((A B) (AI Bl)) -
makeup(A A1) makeup(B BI)
makeup(A so2(A))
equ((A B) (AI BI)) -
equ(A AI) equ(B Bl)
equ(sol(X v Y) sol(XI v Yl)) -
equ(X XI) equ(Y YI)
equ(so2(X) so2(XI)) -
equ(X XI)
equ(contradiction(X) clJuse(contradiction(X) X) ) -
equ(X X)
Counting numbers
getatm((A B) X) -
( getatm(A X) getatm(B X) )
getatm(so2(F(X)) X) -
getatm(so2(X) X) - atom(X)
countl([J L R L R) -
countl([number(X Y)IT] L R L2 R2) shy
(( Y = (gt=~) LI is L + N Rl is R + 20001 l )
( Y = (gt N) LI is L+ N+ 1 RI is R + 20002 )
(Y == laquo=~) LI is L + 1 Rl is R + N )
(Y = laquo N) LI is L + 1 RI is R+N-I)
(Y == IJ LI is L + I Rl is R + J ) ( Y == N L1 is L + N RI is R + N ))
count1(T LI R 1 L2 R2)
count2(fJ L R L R) - 1
count2([XITJ L R L2 R2) shy
name(X Xl)
(( Xl = sknj LI is L Rl is R )
44
( Xl = Iskmj L1 is L + 1 RI is R + ZOOO1) ( LI is L + I RI is R + I ))
count2(T LI RI L2 R2)
pfn((A B)) - pfn(A) prn(B)
pCn(so2(F(X))) - prin(F )
prn(so2(X)) - atom(X) prin(X ) prn (so2(X))
Printing result
wout([XlJ - prt(X) nl woutf[xIY]) - prt(X) nl nl wout(Y)
prt(e(A B)) -
prt(A) prinr 8 ) prt(ltE) prt(eA) - prt(A)
prt(c(A EJ) - prin() prt(A) prine ) prt(B) prin(T)
prt(c A) - prt(A) prt((A E)) - ~
prt(A) nl prt(E) prt(sol(X v Y)) - ~
prt(X) prinC v) prt(Y) prt(A lt=gt B) -
prt(e A) prinC lt=gt ) prt(e B) prt(sol(X)) - prt(X)
prt(so2(X)) - prt(X
prt(c1ause(X Y)) - prt(X)
prt(contradiction(X)) - prin(contradiction() prt(cX) prinr))middot prt(num(XY)) - prin(number(X Y)) prt(sel(X)) - prin(X) prt(X v Y) - prt(X) prin( v) prt(Y) prt(X) prin(X)
Handling conditional queries
condi((Y Xl) shy
assertcon(X) Y
45
retractcon(X)
condi((B A))
retractcon(A) fail
assertcon((A B)) 1
assertcon(A) assertcon(B)
assertcon(A) asserta(A)
retrac teon ((A B)) 1
retracteon(A) retractcon (B)
retraetcon(A) - retract(A)
BIBLIOGRAPHIC DATA SHEET
Report No UIUCDS-F-84-928
3 Recipients Accession No
4 T ide and Subt ltle
An Annotated Predicate Calculus Inference System (APCIS)
S Report Date
November 1984 6
7 Author(s)
Kah-Eng Pua 8 Performing Organization Rept
No
9 Performing Organization Name and Address
Department of Computer Science University of Illinois Urbana IL
10 ProjectTaskWork Unit No
11 Contract Grant No NSF DCR 84-06081 ONR N00014-82-K-0186
12 Sponsoring Organization Name and Address
National Science Foundation Washington DC
13 Type of Report amp Period Covered
14
15 Supplementary Notes
16 Abstracts
This paper describes a deductive inference system called APCIS (Annotated Predicate Calculus Inference System) APCIS is able to carry out inferences from expressions involving numerical quantifiers selectors disjunctions of non-negated terms negated terms disjunctions of negated terms equivalences and exceptions It is also able to count the numbers of occurrence of a given simple term or a conjunction of terms The design of contradiction and the treatment of the disjunction of non-negated terms allow APCIS to accept Horn clauses as well as non-Horn clauses and to carry out inferences from them This feature makes APCIS more general than Prolog
17 Key lords and Document Analysis 170 Descriptors
APC (Annotated Predicate Calculus) APCIS (Annotated Predicate Calculus Inference System) Horn Clause Numerical Quantifier Prolog Selector
17b IdentifiersOpen-Ended Terms
17c COSATI FieldGroup
18 Availability Statement 19 Security Class (This
Re~f~~IA~SIF IFf)
21 ~o of Pages
49 211 ecurity Class (This
PageUNCLASSIFIED
22 Price
FOA NTIS n (10middot70 usco-oc 40329-
1 introduction
This report describes a deductive inrerence system called APCIS (Annotated Predicate
Calculus Inrerence System) wbich accepts expressions in Annotated Predicated Calculus (APC)
and carries out inrerence rrom them Annotated Predicate Calculus is an invention of Professor R
S Michalski It is built on the basis of First Order Predicate Calculus (FOPC) with some
additional features such as numerical quantifications compound terms selectors compound
selectors etc These reatures not only provide APC with more expressive power tban FOPC but
also make APC much closer to human language than does FOPC Details of APC and its
applications can be round in the paper A Theory and Methodology or Inductive Learning [2]
The process or translating APC to Prolog and a program implementing this process has
been discussed in [3] This report summarizes my continuing effort in developing an APC
inference system and can be considered as a folIowup of [3]
APCIS is capable or performing the following types of operations
1 Carrying out inferences from input assertions expressed in FOPC
2 Carrying out inrerences rrom input assertions expressed in APC
3 Dealing with disjunction or nonnegated terms or the (orm Al v A2 v v Am
4 Dealing with a negated term or a disjunction of negated terms or the rorms -(A) and
-(Al) v -(A2) v v -(An) respectively
5 Dealing with equivalence relations or the form A lt=gt B and exceptions or the
forms A - B or A lt=gt -(B) or -(A) lt=gt B
6 Counting the numbers or occurrence of given predicates in the database
In this report we present an overview of APCIS and a detailed description of its
translation mechanism and inrerence mechanism
2
2 Overview ot APCIS
Figure 1 shows the general structure of APCIS There are four modes by which we can
invoke APCIS Each of them will be discussed in the following sections
21 Assertion-Translation Mode
Figure 1(30) shows schematically the phases that APCIS will go through when assertionshy
translation mode is invoked To translate APC assertion into Prolog we type to Prolog system
ta(X)
where ta stands for ~translation of assertion and X is any APC expression to be translated The
input assertion will then go through an APC translator (discussed in [3]) and its result will be
printed out on the terminal Note that the translated result is not loaded back to Prolog system
22 Query-Translation Mode
Figure l(b) is the schematic diagram showing the execution process of query-translation
mode To translate APC query we type to Prolog system
tq(X)
where tq stands for ~translation of query and X is any APC expression The input query will go
through the same APC translator mentioned above but the output will be in the form of ~Prolog
question (see Slction 31) As in the assertion-translation mode the output will only be printed
out on the terminal and will not be loaded back to Prolog
The above two modes provide only translation purposes The following two modes
perform the actual infNence
3
1-------------1 1 ta (X) I 1-------------1
1 1-------------1
APe 1 I Translator 1
1-------------1 I
1-------------11 Terminal I 1-------------1
(a) Assertion-translation mode
1------------ a(X) I
1------------1 1
1 1------------1 I APe I 1 Translator 1
1------------1
i-----------I 1----------1 I temp_file 1 1 Terminal 1 1-----------1 I----------i
1
1 1-------------1 I Prolog 1 1 system 1 1------------ -I
(c) Assertion mode
Figure 1 Four modes of APCIS
1---------------1 1 tq(X) 1 1---------------1
1 1---------------1 1 A P C 1 I Translator 1
1---------------1 I
1---------------1 I Terminal 1 1---------------1
(b) Query-translation mode
1--------------1 q(X) I 1--------------1
1 1------------------1 1 asserta(inpt(Xraquo 1 1------------------1
1 1---------------1 1 A P C 1 1 Translator 1 1---------------1
I 1---------------1 i temt__file 1 1---------------1 1---------------1 1 Prolog 1 1 system 1 1---------------1
I 1---------------1 1 Terminal 1 1---------------1
I 1-------------------1 1 retract(inpt(Xraquo I I-----------------~-I
Cd) Q-uery mode
23 Assertion Mode
Figure l(c) is a schematic diagram showing how assertion mode works In this mode the
input assertion will first go through the APC translator as in assertionmiddot translation mode After
which the translated result will be printed both on the terminal and to a temporary file called
tempfile which will subsequently be loaded back to Prolog system As a result the newly
translated input assertion will become Prolog term(s or clause(s) in the database
24 Query Mode
Figure l(d) shows schematically the stages that will go through when query mode is
invoked The input query crowned by the (unctor inpt will first be stored in the database It will
then be passed to the APC translator as in query-translation mode The output of the translator
will be printed on the temporary file tempfile which will subsequently be loaded to Prolog
system Upon loading tempfiie to Prolog system (recall that tempJile contains essentially a
Prolog question) the question is executed immediately and its result will be prin ted out on the
terminal In the last stage the original input query crowned by the functor inpt will be
retracted from the database
3 APe Translator
As described in [3] there are ten steps in the APC translator and each step undertakes a
unique transformation Assertion-translation mode and assertion mode go through these steps
which have been covered in [3] and will not be discussed here
31 Translation of Queries
We will now examine the different transrormations that query-translation mode and
query mode will go through They differ Crom assertion-translation mode and assertion mode only
5
in the last step of translation
In the last step of the APe translator all input queries (ie expressions entered via
query-translation mode or query mode) are dealt with by the following six predicates prques pi
plett peont pehar and pout The task of prques pi plett and peont is to arrange each
input query in desired order whereas pehar and pout will print out each atomic formula
character by character For illustration purposes consider the following five APe expressions
1 all( X man(X) ==gt mortal(X)
2 exists( X horse(X) v dog(X) )
3 - ( exists( X horse(X) amp dog(X))
4 all( X be_shouted_at(X) amp no_response(X) == gt deaf(X) v dead(X) )
5 exists( 2 X box(X) )
H the above five APe expressions are typed to Prolog via assertion mode or assertionshy
translation mode they will be translated to the corresponding Prolog expressions
la
mortal(XI) shy
man(Xl)
2a
horse(skml) v dog(skml)
3a
contradiction(( horse(XI) dog(Xl) )) shy
horse(Xl)
dog(XI)
4a
deaf(Xl) v dead(Xl) shy
be_shouted_at(X I)
no_response(X1)
Sa
box(sknl)
number(sknl2)
The above live translated expressions ( ie la through Sa ) will be printed on the
terminal and loaded to Prolog if assertion mode is used they will be printed on the terminal but
not loaded to Prolog if assertion-translation mode is invoked
Now if the original APC expressions ( ie 1 through 5 ) are typed to Prolog via query
mode or query-translation mode the corresponding questions will be translated into the following
queries
lb
goo(( condi(( mortal(Xl) man(Xl))) ))
b
goo(( soil horse(Xl) v dog(XI)) ))
3b
goo(( c1ause( contradiction(( horse(XI) dog(Xl) )) _) ))
4b
goo(( conditt deaf(Xl) v dead(Xl) (be_shouted_at(XI) no_response(Xl)) )) ))
5b
amp00(( so2( box(XI) ) s02( num(XI 2 )) ))
The above five translated queries ( ie Ib through 5b ) will be printed on the terminal
and loaded to Prolog if query mode is used they will be printed on the terminal but not loaded to
Prolog if query-translation mode is invoked
In the above queries goo 801 and 802 each forms a part of the inference mechanism of
APCIS goo occupies the top level of the inference mechanism whereas 801 and 802 are at the
1
next level 102 will take care of the searching of simple terms and 101 will deal with the
disjunctions of non-negated terms in the database We will come back to them in Section 4
At the first glance one may feel that the above translated Queries are Quite complicated
However a closer examination will reveal that they are not so Queries lb 3b and 4b can each be
categorized as a conditional query which is a distinct feature of APCIS wherels queries 2b and
5b lre asking simple facts in the database
To handle conditional queries we consider two cases First if the queries involve a
special clause contradition we invoke the built-in function el3ule(X Y) which will look for the
desired contradiction clause in the database Second if the queries do not involve the clause
contradiction we activate a defined Prolog predicate condi to take care of the necessary
searching (To avoid confusion the reader is urged to compare expressions started with the same
number in the above three sets of example)
To handle a query which asks a simple fact we surround each disjunction of terms with
the functor sol as in the example 2b or crown each simple term with the functor 802 as in the
example 5b
32 TranslatIon of Negated Term And Disjunction of Negated Terms
One feature of APCIS is its ability to handle input expressions consisting of only negated
term or a disjunction of negated terms in the forms
or
2 -(AI) v ~(A2) v v ~(An)
To handle the above two forms a special clause with clause head contradiction is
created This special clause head has only one argument which is either a term or a set of terms
grouped together in the form
8
(AI A2 An)
The right-hand side of the clause contradiction is exactly same as the argument in the clause
head For example the above two forms involving negated terms will be translated into the
corresponding forms as follows
1 contradiction( A ) shy
A
2 contradiction(( AI A2 An )) shy
AI A2 An
The design of the clause with clause head contradiction will greatly enhance the inference power
of APCIS (see the example in Section 44)
33 Translation ot Disjunction ot Non-negated Terms
Another feature of APCIS is its ability to handle input expressions involving a
disjunction of non-negated terms in the forms
1 Al v A2 v v An
or
2 Bl amp 32 amp amp Bm ==gt Al v A2 v v An
Unlike Prolog which accepts only Horn clauses APCJS will accept Horn clauses as well
as non-Horn clauses which take the above two forms The inference from non-Horn clauses is
made possible by the two defined predicates sol lnd s02 discussed in Section 42 and Section 43
respectively (see also the example in Section 44) In the APC translator the above two forms are
transbted into the corresponding forms as follows
1 Al v A2 v v An
2 Al v A2 v v An shy
g
Bl B2 Bm
34 Futher Transformation of Exceptions and Equivalences
To provide some backgrounds for the discussion of the further transformation of
exception and equivalence relations we will lirst reproduce the three goals in the Step 2 of the
APe translator discussed in Section 32 of [31
First expressions involving implication or the form A ==gt B will be transformed to
Second expressions with exception symbol or the form A - B will be changed to the
form ( A lt=gt -(B) ) amp ( -(A) lt=gt B)
Tbird expressions with equivalence symbol of the form -(A) lt=gt B or of the form
A lt=gt -(B) will also be converted to ( A lt=gt -(B) ) amp ( -(A) lt=gt B ) since tbere are
logically identical to exception relations Also expressions with equivalence symbol of the form
A lt=gt B or -(A) lt=gt -(B) will remain the same
After the Step] of the APe translator both sides of any transformed expression with
lt = gt symbol will be treated separately as if they are two independent expressions In the
Step 10 of the APe translator each side of lt=gt will again be treated separately and
transformed into a form similar to an transformed input query (see Section 31) Two examples
are given below
1 state(on) lt=gt -( state(olJ) )
2 all( 1 bot(l) amp humid(l) - winter(I) )
They will be transformed in the Step 2 or the APe translator into
1
(state(on) lt=gt -( state(off) ) ) amp ( -( state(on) ) lt=gt state(olJ) )
2
10
( hot(l) amp humid(l lt=gt -(winter(l)) ) amp
( -( hot(l) amp humid(l)) lt=gt winter(I)
In Step la they will again be transformed to
1
so2( state(on) ) lt=gt so2( contradiction( state(oH) ) )
so2( contradiction( state(on) ) ) lt=gt so2( state(oH) )
2
( s02(hot(XI)) so2(humid(XI))) lt=gt so2( contradiction( winter(Xl ))
so2( contradiction(( bot(Xl) humid(Xl) )) ) lt= gt so2( winter(XI) )
There are two advantages in the treatment of exception and equivalence symbols in this
way First it will prevent Prolog program from going into an infinite loop which is difficult to
avoid if equivalent relation such as A lt=gt B is transformed into the logically equivalent form
( A ==gt B) amp ( B ==gt A) Second by maintaining both sides of lt=gt symbol in
query form the searching on either side caD be done more easily and efficiently since the form
is already processed and does not need any further transformation
Inference Mechanism
As mentioned at the end of Section 31 goo sol and s02 each forms a part of the
inference mechanism of APCIS with goo occupying the top level and 80) and 802 the second
level In addition to these countl count2 equlv and impll are also at the second level of the
inference mechanism We will go over all of them in the following sections
I goo
goo is essentially the starting point of the inference Whenever a translated query is
loaded to Prolog system from temp-fie goo will go through one or more of the following steps in
11
sequence
G 1 Check if the query asks for the numbers of occurrence of certain term(s) It so then
pass It to eountl and eount2 else go to G2
G2 The query will be passed down to sol or s02 (or both) to check i( any assertion in the
database can satisfy the query It the answer is positive then the query succeeds else
go to G3
G3 The query will be passed to equlv to carry out further searching It the searching is a
success then the query will be closed with a success else go to G4
G4 It the query is in the form A ==gt B then it will be passed to Impli It Impll
succeeds then done else the query will be closed with a (ailure
42 sol
801 and 802 together with dis and eon form the most complicated part of the APCIS
iorerence mechanism In this and the next section we will look at sol and s02 dis and eon will
be discussed in Section 44 We will close Section 44 with an example that illustrates the
materials presented in Section 42 through Section 44
sol is at the second level of the inference mechanism It will deal with any disjunction of
non-negated terms For any disjunction passed to it it will go through one or more of the
following steps in sequence
S1 Check if any term In the disjunction can be satisfied by any term or clause in the
database without contradiction It so then done else go to S2
S2 Pass the disjunction together with another disjunction (and its tlil) picked up from
the database to dis It dis succeeds then done else go to S3
S3 Pass the disjunction down to equlval which will check if any term in the disjunction
matches either side of any equivalence relation in the database It such a match is
found then check if the other side of the equivalence C3n be satisfied It so then done
else the goal fails
43 s02
s02 is also at the second level of the inference mechanism It will take care of all the
simple terms in the transl1ted query The following is the sequence that s02 wiII follow in
searching
S1 Check if the term passed to it caD be s3tisfied by any term or clause in the d3tabase
without contradiction It so then done else go to S2
S2 Pass the term together with a disjunction of terms (and its tail) picked up from the
database to dis If dis succeeds then done else the goal fails
44 dis and con
dis has three arguments In the first two clauses of dIs the first argument P v Q is
found in the database using the builtmiddotin functiol clause and the third argument R is the tair of
the term or the clause P v Q If P v Q is not a clause but a term R will be instantiated to trUE
The second 3rgument comes from either lIol or 802 and thus takes the form of either X v Y (a
disjunction of terms) or T (3 simple term)
All the clauses of dis together with con will perform the searching as exemplified in the
following algorithm (we will keep the notationsin this section)
01 Check if every term in P v Q is in X v Y It so then go to 03 else go to D2
02 For any term (in P v Q) which is not in X v Y or does not match T perform the
following tests
a Check if the term (in P v Q) has already been negated in the datab3Se (ie check if
the contradiction of the term exists in the d3tabase) If so then repeat D2 for other
terms not found in X v Y or not matching T else go to b
13
b Check if the contradiction of the term matches either side of any equivalence
relation in the database If such a match is found then check if the other side of the
equivalence can be satisfied If so then repeat O~ for other terms not found in X v Y
or not matching T else the goal fails
It all the terms (in P v Q) which are not in X v Y or do not match T survive either one
of the above two tests then go to 03
03 This step is essentially done by eon whose goal is to satisfy the tail R of P v Q It
con succeeds then done else the search fails
To close this section we will give an example to illustrate what we have covered In
Section 42 through Section 44
Example Assume that we already haye the following expressions in the database
horse(skml) v dog(skmI)
contradiction(( dog(XI) ))shy
dog(XI)
query goo(( soZ horse(X)) ))
This query will be passed to 802 which will check it the term horse() can be satisfied iu Step S 1
of Section 43 It is a failure So we now go to Step S2 In this step we pick up the disjunction
horse(~kml) v dog(skml) (and its tail true) in the datab3Se and pass it together with the term
horse(X) to dis We are now in Step 01 of Section 44 In this step we find that dog(skml) does
not match horse(X) So we have to go to Step 02 In Step 023 We find that the term dog(skml)
has already been negated (the second expression in the database) So we go to next step 03 Since
the tail of the disjuDction horse(skml) v dog(skml) is the atom true con is satisfied and the
query succeeds
45 countl and count2
countl and count2 are responsible for the counting of tbe numbers of occurrence of a
given simple term or a conjunction of terms They are activated by input queries in the form
q( exists( X whatnum amp P) )
where whatnum is the l~bel for activating the counting of the numbers of occurrence of P which
can either be a term or a conjunction of terms
countl will count the number of term(s) which will satisfy P and associate(s) with
numerical quantification(s Two counters are set to update the lower and upper boundary or the
scope or the numfrical quantifications encountered
The contents of the two counters are then passed to count2 which is responsible for the
counting or the following three types of term First term(s) which will satisfy P and associate(s)
with existential quantification(s Second term(s) which will satisfy P and has(have) Prolog atom
as its(thfir) argument(s) Third term(s) that will satisfy P and itself(themselves) is(are) Prolog
atom(s )
46 equiv
equlv will be activated only after sol and B02 have failed The first two goals of equlv
are similar to that of Step S3 in Section 42 and Step D2b in Section 44 The third goal or equiv
makes possible the inference on either side of any equivalent relation For example if we type the
following three expressions to Prolog in assertion mode
l all( X hot(X) amp humidX) - winter(X)
2 all( X hot(X) amp bumid(X) ==gt unpresent(X))
3 - ( exists( X winter(X) ) )
and then ask APCIS in query mode
q( cxists( X unpresent(X) ) )
15
APCIS with the aid of equlv will be able to answer yes to this query
41 lmpll
lmpll can be considered as the last attempt that APCIS would make to satisfy a
query It is activated only after equlv has failed It will first check if the query is conditional If
so it will convert the implication symbol to equivalence symbol and search if such an equivalent
relation can be found in the database If so a success Otherwise a failure
5 More on the Inference Mechanism
Having looked at all the subparts at the top two levels of the inference mechanism we
are ready to look at other subparts at lower levels
51 num and cnum
One distinct fe3ture or APCIS is its ability to deal with numerical quantifications As
mentioned in Section 31 input queries and assertions will undergo different transformations in
the last step (Step 10) of translation This also holds true for expressions involving numerical
quantifications Consider the following expression
exists( 6 X horse(X) )
If it is entered to Prolog via assertion mode we will after going through all the steps of
translation have the rollowing entered to the database
horse(sk n I
number(sknl6)
Now if we want to ask Are there more than five horses 7 and type in
q( exists( gt5 X horse(X) ) )
1amp
APCIS will translate the question and enter to Prolog the following query
goo(( s02( horse(X) ) s02( num( X gt5 )) ))
Note that the term number(slml 6) in the database and the term num(X gt S) in the query are
different predicates and this difference is exactly where the power of the clause num(X N)
defined in APCIS comes from When the clause num(X N) in APCIS is activated it will search
through the database to see if there is any term of the form number(X I) whose first argument
matches the first argument of num(X Y) in the query It a match is found the second arguments
of both num(X Y) in the query and number(ltI) in the database will be passed to cnum in
APCIS
The job of cnum is to compare the numerical messages carried by the second
argument or the term rlum(X Y) in the query and the second argument of the term rlumber(X I)
in the database to see if they match with each other according to the rules defined in cnum
While there are 25 rules for such matching purposes the idea is simple
Imagine that the second argument Y of the term num(X Y) in the query
and the second argument I of the term num()( I) in the database each occupies a
place in an integer line (Le the integer line in mathematics) To have a match
the domain covered by Y should contain the domain covered by L
As an example the answer to the above query is positive since the domain of gt5
contains the domain or 6
Before closing this section we will bring out a speciaJ translation aspect of expressions
involving numbers by an example We first type to APCIS the Collowing expressions in assertion
mode
1 aU(X all(Y father(X Y) amp number(Y gt6) ==gt has_manY3hildren(X) ))
2 exists(X exists( 12 Y Cather(X Y) ) )
11
After going tbrougb all tbe translation steps tbe Collowing two expressions will be entered to tbe
database
I
bas_many_cbildren( Xl ) shy
Cather( Xl X2 )
num( X2 gt6 )
2
Catber( sk m1 sk n2 )
number( skn2 12 )
lotice that whenev(gtr a term with Cunctor number appears at the rigbt-band side oC a Prolog
clause its Cunctor will be cbanged to num automatically This treatment will greatly cnbance tbe
inference power of the clause sbown in l above For instance iC we now ask tbe question
q( exists( X bas_many_children(X) ) )
The right hand side oC the clause l will match the two terms in 2 and tbe query succeeds
52 Bel and cael
A special feature of APe is tbat all predicates tbat express relations = = gt
gt= lt and lt= can be expressed explicitly using infix notations as relational statements
called selectors To handle selectors we defined Bel in APCIS
Every expression involving selectors will undergo different translations in assertion mode
and query mode For example the assertion
a( exists( [X Y] box (X) amp box(Y) amp (weigh t(X) gt weight(Y) ) ) )
will be translated into the following three terms and entered to tbe database
box( skml )
box( skm2 )
18
weight( skm 1 ) gt weight( skm2 )
Now it we want to ask Is it true that there exists two boxes of different weights and type in
q( exists( [X Yl box(X) amp box(Y) amp ( weight(X) = weight(Y) ) ) )
The question will be transformed to the following query and entered to Prolog
goo(( so( box(XI) ) s02( box(X2) ) so2( sel( weightXI) = weight(X2) )) ))
Note that the selector in the above query is surrounded by the functor set When any clause or
8el in APCIS is activated it will search through the database to see it there is any selector whose
two arguments (left and right side or any selector symbol) match the two arguments of the
selector in the query At the same time 8el will check iC the selector symbols (may be different) or
the two different selectors (one in the query and one in the database) satisfy the rules defined in
sel There are 12 matching rules defined in sel All oC them ~re straightforward and will not be
discussed here An example will be enough to explain how 8el works
Consider the execution of the above transformed query The first two terms in the query
are satisfied by the first two terms in the database and Xl and X2 are instantiated to skml and
skm2 respectively The third term of the query will be passed to eel (of APCIS) which finds a
match on each side of the two selectors (one in the query and one in the database) At the same
time the two different selector symbols gt and = are found to satisfy one of the rules in
8el As a result the query succeeds
To enhance the inference power of clauses involving selectors all the selectors appearing
on the rightmiddothand side oC any clause will be surrounded by a functor set The idea is similar to
that in the last part of the previous section
c8el is exactly the same as 8el functionally It provides a convenient way to compare
selectors when dis is being executed
19
8 Printing Result
Whenever a goal is successfully executed APCIS will not only response with a yes but
also print out the matched terms or clauses in the database This is made possible by the built-in
function bagor and the two predicates wout and prt defined in APCIS
7 Summary
In this paper a description of a deductive inference system called APCIS (Annotated
Predicate Calculus Inference System) has been provided APCIS is able to carry out inferences
from expressions involving numerical quantifiers selectors disjunctions of non-negated terms
negated terms disjunctions of negated terms equivalences and exceptions It is also able to count
the numbers of occurrence of a given simple term or a conjunction of terms
The main idea of APCIS is that each input APC expression is first passed to a
preprocessor ( ie APC translator ) which dissolves and transforms each APC expression into
Prolog expression(s) which will then be loaded to Prolog system The user bas to specify whether
each input expression is to be entered as an assertion or as a query by invoking either assertion
mode or query mode respectively Each assertion or query will undergo different transformations in
the preprocessor The different treatment of assertion or query not only allows a full uS1ge of the
Prolog inference mechanism but also makes possible a higher level of inexact pattern matching
exemplified by the examples in Section 51 and Section 52 where the four predicates num
cnum sel and csel are discussed This higher level of pattern matching increases the inference
power of APCIS greatly
The design of contradiction and the treatment of the disjunction of non-negated terms
allow APCIS to accept non-Horn clauses and to carry out inference from them This feature
makes APCIS more general than Prolog
20
While APCIS performs very well in many sets of arguments provided by the author it is
still too early to jump to conclusion that it can perform equally well in all types of problems In
any event the expressiveness of APC has greatly been retained in the present version of APCIS
and moreover some design ideas or APCIS mentioned in this paper are not restricted to APCIS
- they may be carried over to learning programs with narrower scopes
21
References
[1] W F Clocksin and C S Mellish Programming In Prolog Springermiddot Verlag Berlin Hpoundidelberg 1981
[2] R S Michalski A Theory and Methodology of Inductive Learning Chpt 4 Machine L earning Tioga Publishing Co Palo Alto CaliJornia 1989
[3] K-E Pua Translating Annotated Predicate Calculu8 to Prolog ISG Report 84middot1 UlUCDCSmiddotFmiddot918 University oj Illinois Urbana IL June 1984
22
Appendix A
APCIS Users Manual
1 Get Started
Users are urged to follow the steps depicted below
1 Get the PROLOG interpreter by typing
alias prolog mntb2sammutsammutprologprolog (Vax A)
or
alias prolog mntb2sammutsammutbinprolog (Vax B)
2 Load apc and infer by typing
prolog apc infer
When large APC expressions are expected we can increase the stlck by typingI
prolog -snnnn ape infer
where ns denote the number of stacks in decimal
3 When the wording LSW - PROLOG appears on the terminal we are reldy to interact
with APCIS The four modes by which we can invoke APCIS are summarized below
a Assert ion-Translation Mode
ta(X)
b Query-Translation Mode
tq(X)
c Assertion Mode
a(X
d Query Mode
q(X)
23
where Xs are APC expressions
2 Notations Used in APCIS
Below is a summary or notations used in APCIS
a Logical operators
amp
v
==gt
lt=gt
-
negation
conjunction
disjunction
implication
equivalence
exception
b Binary relation symbols in selectors
-
=
gt=
lt=
gt
lt
equal
not equal
greater or equal
smaller or equ al
greater
smaller
c Relational operators in numerical quantifiers
lt less than
lt= less than or equal
gt greater than
gt= greater than or equal
d BinlTY operator in numerical quantifier
range
e Universal quantifier
all(X p(X))
f Existential quantifier
exists(X p(X))
g Numerical quantifier
exists(I X p(X))
where p(X) is a formula
where X is a variable or a Jist of variables or the
form [HI~rj and p(X) a formula
where I repersents expression involving integer(s)
and operator(s) in c or d above and p(X) a formula
25
Appendix B
APCIS Program Listings
------------------------------- Program Name APCIS - Part 1 APC Translator
-------------------------------
op(3OO fx -)1
op(500 xfy amp)
oPt 500 xfy v)
op(600 xfx )
op(700 fx [gt= lt= gt lt ]) op(400 xfy [= gt= lt= gt lt ])1 op(900 xfy gt lt=gt -])1
steps(X Xg) shy
numbervars(X 1 J Step 1 change variables to iis
rmimp(X X) Step 2 conv(X X3) Step 3
rewrite(X3 X4) Step 4
negin(X4 X5) Step 5
dropexist(X5 X6 1]) Step 6
dropall(X6 X7) Step 7
distrib(X7 X8) Step 8 clausiCy(X8 X9 [J) Step 9
ta(X) shysteps(X Xg)
(( Xg = II nl
print( yes it is always true) )
( nl nl printcl(X9))) Step 10a
tq(X) shy
steps(X Xg)
prques(Xg)
28
Step 2 Removing implic3tions amp Transforming exceptions and equiv3lences
rmimpl( P - Q (PI lt=gt (QI) ) amp ((PI) lt=gt QI) ) -
rmimpl(P PI) rmimpl(Q QI)
rmimplnp) lt=gt Q (PI lt=gt -(QI)) amp nPI) lt=gt QI) ) - 1
rmimpl(P PI) rmimpJ(Q QI)
rmimpJ(P lt-gt -(Q) (PI lt=gt -(QI)) amp nPI) lt=gt QI) ) -
rmimpl(P PI) rmimpl(Q QI)
rmimpl( P lt=gt Q PI lt=gt QI ) - I
rmimpl(P PI) rmimpl(Q QI)
rmimpl( P ==gt Q -(PI) v QI ) - I
rmimpl(P PI) rmimpl(Q QI)
rmimpl( all(X P) aI(X PI) ) - 1
rmimpl(P PI)
rmimpl( exists(X P) exists(X PI) ) -
rmimpl(P PI)
rmimpl( exists(I X P) exists(I X PI) ) -
rmimpl(P PI)
rmimpl( P amp Q PI amp Ql ) -
rmimpl(P PI) rmimpl(Q Ql)
rmimpl( P v Q PI v QI ) -
rmimpl(P PI) rmimpl(Q QI)
rmimpl( -(p) -(PI) ) - I
rmimpl(p PI)
rmimpl( P P )
St~p 3 Converting numerical amp distinctive quantifiers
L Numerical quantifiers
examples of input forms
1 exists(gt= i X pIX)) where i is an integer
2 exists(i X pIX)) where i is an integer
3 exists(i j X pIX)) where i j are integers and iltj
4 exists(il v i2 X pIX)) where is are integers
examples of output forms of this step
1 exists(X pIX) amp number(X gt= i) )
2 exists(X pIX) amp number(X i) ) 3 exists(X pIX) amp number(X ij) ) 4 exists(X pIX) amp number(X il v i2) )
II Distinctive quantifiers
27
example or input Corm
exists([XYL p(X Y))
example or output Corm or this step
exists(X exists(Y p(XY)) )
conv(P lt=gt Q PI lt=gt QI) - 1
conv(P PI) conv(Q QI)
conv(al1(X P) all(X PI)) -
conv(P PI)
conv(exists(HIT] P) R ) - conv(P PI) convert distinctive quantifier
convtdis(exists([HIT]PI) R)
conv( exists(I X P) exists(X PIamp number(X I) )) -
conv(P PI) convert numerical quantifier
conv(exists(X P) exists(X PI)) - 1
conv(P Pl)
conv(P amp Q PI amp QI) - 1
conv(P PI) conv(Q QI)
conv(P v Q PI v QI) - t conv(P PI) conv(Q QI)
convC(P) -(PI)) -
conv(P PI)
conv(P Pl
convtdis(existsl[XL P) exists(X P)) - atomic(X) convtdis(exists[XIYj Pl exists(X R)) shy
convtdis(exists(Y P) R)
Step 4 Rewriting compound predicates andor compound selectors
Outputs are smiple predicates andor simple selectors
rewrite(P lt=gt Q PI lt=gt QI) - t rewrite(P PI) rewrite(Q QI)
rewrite(all(X Pl all(X PI)) - 1 rewrite(P PI)
rewriteexists(X P) exists(X PI)) - I rewriteP PI)
rewrite(P amp Q PI amp QI) - rewrite(P P 1) rewrite( Q Q 1
rewrite(P v Q PI v QI) - 1
rewrite(P PI) rewrite(Q QI)
rewriteC(P) -(PI)) - I
28
rewrite(P PI) rewrite(F(A B) R) -
rewrite(A AI) rewrite(B BI) re(F(AI BI) R)
rewrite(F(A) R) -
rewrite(A AI) re(F(AI) H)
rewrite(F(A B C) R) -
rewrite(A AI) rewrite(B BI) rewrite(C CI) re(F(AI BI CI) R)
rewrite(F(A B C D) R) -
rewrite(A AI) rewrite(B Btl rewrite(C CI) rewrite(D DI) rc(F(AI BI CI Dl) H)
rewrite(PP)
re(F(A B v el (RI v R2) -
re(F(A Bl RIl re(F(A C) R2) reF(A B amp cl (RI amp R2)) -
re(F(A B) RI) re(F(A e) R2) re(F(A amp B C) (Rl amp R2)) -
re(F(A e) R 1) re(F(B C) R 2) re(F( v B el (R I v R2)) -
re(F(A el R I) reFB el R2) re(F(A amp Bl (R I amp R2)) -
re(F(A RI) re(F(BJH2) re(F(A v B) (R 1 v R2)) -
re(F(A) RI) re(F(B) R2)
re(F(A vB c Dl (RI v R2) -
re(F(A C D) RI) re(F(B C D) R2) re(F(A amp B C D) (RI amp R2)) -
re(F(A C D) Rll re(F(B C D) R2) re(F(A B v C D) (HI v R2)) -
re(F(A B D) RI) re(F(A C D) R2) re(F(A B amp C D) (HI amp R2)) -
re(F(A B D) RI) re(F(A C D) R2) re(F(A B C v D) (RI v R2)) -
re(F(A B C) R I) reF(A B D) R2) re(F(A B C amp D) (RI amp R2)) -
29
re(F(A B C) RI) re(F(A B D) RZ)
re(F(A v B e D E) (R I v R2)) -
re(F(A e D E) R I) re(F(B e D El R2) re(F(A amp B e D E) (RI amp RZ)) -
re(F(A e D El R 1) re(F(B e D E) R2) re(F(A B v e D E) (R I v R2)) -
re(F(A B D E) RI) re(F(A e D E) R2)
re(F(A B amp e D E) (RI amp R2)) -
re(F(A B D El RI) re(F(A e D E) RZ) re(F(A B e v D E) (R I v R2)) -
re(F(A B e El R 1) re(F(A B D E) RZ) re(F(A B e amp D E) (RI amp RZ)) -
re(F(A B e E) R I) re(F(A B D E) RZ)
re(F(A B e D vEl (RI v RZ)) - l
rc(F(A B C D) RI) re(F(A n e El RZ) re(F(A B e D amp El (RI amp RZ)) - ~
re(F(A B e D) RI) re(F(A B e El RZ)
re((A = B) (A = B)l-
re((A = Bl (A = 8)) -
retIA gt= BI (A gt= B)) -
re((A lt= B) (A lt= B)) -
re((A gt B) (A gt B))-
re((A lt Bl (A lt Bl)- re(A A)
Step) Bringing n(gation inwards
Degin(-(P) PI) - neg(P Pl)
negin(P lt=gt Q PI lt=gt Ql) - ~
negin(P PI) negiD(Q QI)
Degin(aU(X P) all(X PI)) - Degin(P PI) negin(exists(X P) exists(X PI))- negin(P PI) negin(P amp Q PI amp Ql) - Degin(P PI) negin(Q Ql)
Degin(P v Q PI v QI) - Degin(P PI) negin(Q QI) negin(P Pl
neg(-(P) PI) - negin(P PI)
neg(all(X P) exists(X PI)) - neg(P PI)
30
neg(exists(X P) all(X PI)) - neg(P PI)
neg(P amp Q PI v QI) - neg(P PI) neg(Q Ql)
neg(P v Q PI amp QI) - neg(P PI) neg(Q QI)
neg(P -(PH
Step 6 Dropping existnetial quanti6ers
dropexist(P lt=gt Q PI lt=gt QI Elerns) - dropexist(P PI Elerns) dropexist(Q QI Elerns)
dropexist(alJ(X P) all(XPI) Elerns)
dropexist(P PI [XIElernsJ)
dropexist(exists(X P amp nurnber(X Yraquo P2 Elerns) -
genfun(skn Newg) Fun = [NewgIElerns]
subst(FuD X P amp Dumber(X Y) PI)
dropexist(Pl P2 Elerns)
dropexist(exists(X P) PZ Elerns) -
genfun(skrn Newf) Fun = [NewfIElernsJ
subst(Fun X p PI)
dropex ist(P 1 P~ Elerns)
dropexist(P v Q PI v QI Elerns) - ~
dropexist(P PI Elerns) dropexist(Q Ql Elerns)
dropexist(P amp Q PI amp QI Elerns) - 1
dropexist(P Pl Elerns) dropexist(Q QI Elerns)
dropexist(P P _)
gen fun(R oot Newn arne) shy
getnurn(Root Nurn)
narne(Root Rootlist)
append(Rootlist[Nurnj Narnelist)
concat(Narnelist Newnarne)
getnurn(Root Nurn) shy
retract(currentnurn(Root Nurn 1 raquo
Nurn is Nurni + 1
asserta(currentnurn(Root Nurn))
getnurn(Root 1) - asserta(currentnurn(Root 1))
subst(New Old Val Val) - var(Val)
subst(New Old Old New) - 1 substNew Old Val Val) - atornic(Val)
31
subst(New Old Val Newval) shy
runctor(Val F N)
CUDctor(Newval F N)
subst_args(N New Old Val Newval)
subst_args(O J J - J J
subst_args(N New Old Val NewVal) shy
arg(N Val OldArg)
arg(N NewVal NewArg)
subst(New Old OldArg NewArg)
NI is N - I
subst_args(Nl New Old Val NewVal)
append([J L L) -
append([XILl] L2 [XIL3]) - append(Ll L2 L3)
Step - Dropping universal quantifiers
dropall(P lt=gt Q PI lt=gt QI)-
dropall(P PI) dropall(Q QI)
dropall(all(X P) PI) - ~ dropall(P PI)
dropall(P amp Q PI amp QI) -
dropall(P PI) dropall(Q QI)
dropall(P v Q PI v QI) -
dropall(P PI) dropall(Q QI)
dropall(P P)
Step 8 Distributing conjunctions over disjunctions
distrib(P lt=gt Q PI lt=gt Ql) - t distrib(P PI) distrib(Q QI)
distrib(P v Q R) -
distrib(P PI) distrib(Q QI)
distributing(PI v QI R)
distrib(P it Q PI it QI) -
distrib(P PI) distrib( Q QI)
distrib(P P)
distributing((P amp Q) v R PI amp QI) -
distrib(P v R PI) distrib(Q v R Ql)
32
distributing(P v (Q amp R) PI amp Ql) -
distrib(P v Q PI) distrib(P v R Ql)
distributing(P P)
Step 9 Packing each conjunction into clauses
c1ausify(P amp Q CI C2) -
clausiCy(P CI C3) c1ausify(Q C3 C2)
cbusiCy(P [d(A B)ICs] Cs) shy
inclause(P A [j B [I) 1
c1ausiry( C C)
inclause(P v Q A AI B B1) -
inc1ause(P A2 AI B2 Bl)
inclause(Q A A2 B B2)
inclausenp) A A B1 B) -
notin(P A) putin(P B B1)
inclause(P AI A B B) shy
notin(P Bl putin(P A AI)
notin(X [XU) - fail
notin(X [JLj) - notin(X L)
notin(X 1])
putin(X II [X]) - 1
putin(X [XILJ L) -
putin(X [YILJ [YILl]) - putin(X L Ll)
Step 1Oa Printing clauses
printcl([]) - nl nl
printcl(c1(AB)ICsj) - printcl(A Bl nl printcl(Cs)
printcl(L II) - printdis(IL) prinr)middot
printclHl L) - prin(contradiction(() printconl(rL)
print()) - ) printconj(rL) prinr )
printcl(Ll L2) shy
printdis(ILl) print( - ) printconj(rL2) prin()
printdis(S[Lj) - printcbar(SL)
33
printdis(S[LILs]) - printchu(SL) prin( v) printdis(SLs)
printconl(S[LI) - printchar(SL)
printconl(S[LILs]) - printchar(SL) prin( ) printconl(SLs)
printconj(S[L]) - tab(3) printchar(SL)
prin tconj( S [L IL sl) shy
tab(3) printchar(SL) print( ) printconj(SLs)
printchar(SP) shy
atomic(P)
name(P L)
L = [IT]
concat([XIT NewP)
prin(~ewP)
printchar(SP) shy
atomic(P)
prin(P)
printchar(SA lt= gt B) -
prin((l clausify(A AI [j) pl(eAl) prin())
print lt=gt )
prin(() cbusify(B Bl [I) pJ(eBl) prine))middot
printchar(rnumber(X N)) shy
prin(num() printchar(rx) prin( )
printchar(rN) prinC))
printchar(rF(A B)) shy
seJec(F(A B))
prinCsel() printchar(rA)
prin( F ) printchar(rB) prinC))
printchar(SF(A B)) shy
( selec(F(A B)) F = infix )
printchar(SA) prin( F ) printchar(SB)
printchar(SF(A)) shy
(F= prefix gt= F= prefix lt= F= prefixgt F= prefix lt )
prin(F ) printcbar(SA)
printchar(SP) shy
functor(P F MaxN)
prin(F ()
Nl is MaxN - 1
putout(S N 1 P MaxN)
34
prin())
putout(S 0 P MaxN) -
arg(~laxN P Argu)
prin tchar(SArgu)
putout(S N p MaxN) shy
Nt is MaxN - N arg(NI P Argu)
printcbar(SArgu )
prin( )
N2 is N - 1
putout(S N2 P MaxN)
selec(FA B)) shy
( F= infix = F= infix f= F= infix gt=
F= infix gt F= infix lt= F= infix lt )
35
----------------------------------Program Name APClS - Part 2 Inference Mechanism ---------------------------------- a(X) shy
steps(X X9)
(( X9 =[] nl
print( yes it is always true) )
( X9 =[cI(IJ[])] nl
print( no it is always false) )
( nl nl printel(X9) Step 1Oa
tell(temp_file) printel(X9) e1ose(temp_file) consult(temp_6Ie) ))
q(X) shy
asserta( in pt(X))
steps(X X9)
(( X9 = [] print(middot~H~~middot~t~)
print(THE AiSWER IS YES)
print( ilgIQlQl(~) )
( X9 = [e1([j [j)] Pr1nt ( OJ fi(i I~ iii Ij)middot(i)(i) fiyenQ)riiio(i)(ij)(i)fj)fiyen1li1il1li1il)__ gtw~ __~_~ _~~_ ~_-=~
print(THE ANSWER IS NO ) print() )
( teI1(temp_6Ie)
prques(X9) Step 1Ob
close(temp_file)
nl print(Let me think about it) nl
consult(temp_6Ie) ))
retrac t( in pt(X))
Step lOb Printing question
prques(lcl(A 8)1) - prin(goo(() pl(qA 8) print()))
prques([c1(A 8HCs]) - prin(goo(() pl(qA 8) print() pl(q Cs)
pl(e [c1(A 8)]) - pl(eA 8)
pl(q [c1(A 8)]) - pl(qA 8) print()))
pl(S [e1(A B)ICs]) - pl(SA B) prin( ) pl(S Cs)
38
pl(q [j L) - prin(c1ause(contradiction(() pcont(qL) prin())_))
pl(S [I L)- prin(so2(contradidion(() pcont(SL) print))))middot
pl(S [L] []) - prin(so2() pcbar(SL) prin())
pl(S L [J)- prinsol() plett(SL) print))
pl(S [L] LI) - prin(condi(() pchar(cL)
prin(() pcont(S Ll) prine))))
pl(S L Ll)- prin(c1ause() plert(cL)
prin(() pcont(S Ll) prine)))
plert(S[LJ) - pchar(SL)
plert(SjLILsj) - pcbar(SL) print v) pleCt(SLs)
pcont(S[L]) - pchar(SL)
pcont(S[LILsj) - pcbar(SL) prinr ) pcont(SLs)
pcbar(SP) shy
atomic(P)
name(PL)
( L = [IT] L = [5 k miT] L = [5 k niT] )
concat[XITj NewP)
prin(0JewP)
pchar(SP) shy
atomic(P)
prin(P) pchar(SA lt=gt B) -
prin(() dausify(A AI []) pl(eAI) prin())
prinr lt=gt ) prin(() dausify(B BI ]) pl(eB) print))
pchar(Snumber(X N)) shy
prin(num() pchar(SX) prin()
pchar(SN) prinr))
pcbar(SM N) - prin(M N)
pcbar(cF(A B)) shy
selec(F(A Braquo
pcbar(cA)
prine F ) pchar(cB) pchar(SF(A B)) shy
selec(F(A B))
prin(sel() pchar(SA)
print F ) pchar(SB) print)) I
31
pc har(SF(A)) shy
( F= prefix gt= F= prefix lt= F= prefixgt F= prefix lt )
prin(F ) pchar(SA)
pchar(SP)shy
runctor(P F MaxN)
prin(F ()
011 is MaxN - 1 pout(SNl P MaxN)
print) )
pout(S 0 P M3xN) - 1
arg(~bxN P Argu)
pchlr(SArgu )
pout(S N P MaxN shy
Nl is MaxN - N
arg(Nl P Argu)
pchar(SArgu
prin( )
N2 is N - 1
pout(S N2 P ~13xN)
Comparing numbers in numerical quantifiers
num(XN) shy
number(X I)
cnum(N 1) ~
cnumlaquo=01 lt=I- N gt=I
cnumlaquo=J lt I) - N gt=1-1
cnumlaquo=NIJ) - N gt=J 1
cnumlaquo=N J)- integer(I) N gt=I~
cnum(gt=N gt=1) - N lt=1
cnum(gt=N gt I) - N lt=1+ 1 cnum(gt=NIJ) - N lt=1
cnum(gt=N lt=1)- N lt=1
cnum(gt=N lt I) - N lt=1 L cnum(gt=N 1)- integer(I) N lt=1
cnum( lt N lt 1)- N gt=1 L
38
cnum( lt N lt=1) - N gt I cnum( lt NLJ) - N gt J
cnum( lt N 1)- integer(I) N gt 1
cnum(gt N gt I) - N lt=1 cnumlgt i gt=1) - N lt I
cnum(gt N lt=1) - N lt=0
cnum(gt N lt I) - N lt=0
cnum(gt iIJ) - N lt I cnum(gt N 1)- integer(I) N lt I
cnum(~LN lt=1) - M=I N gt= I l
cnum(~LN lt I) - M=l N gt= I-I
cnum(~LNLJ) - M lt =1 N gt = J
cnum(~1N 1)- integer(I) M lt= I N gt= I
cnum(- N) - integer(N)
Comparing selectors
sel(X = Y) shyX= Y
sel(X I=Y) shy(X I=Y X lt Y Xgt Y)
sel(X gt Y) shyXgt Y
sel(X lt Y) shyXlt Y
selX gt=Y) shy(X gt=Y X= Y Xgt Y)
se(X lt=Y) shy
(X lt=Y
X= Y
X lt Y)
csel(infix = infix =)
39
csel(infix = infix = csel(infix = infix gt)
csel(infix = infix lt) csel(infix gt infix gt) cseJ(infix lt infix lt) csel(infix gt= infix gt=) csel(infix gt= infix gt csel(infix gt= infix =)
csellinfix lt= infix lt=) csel(infix lt= infix lt) csel(infix lt= infix =)
Finding solutions
sol(X v Y) -
(( notetra(X) eon(X) ( sol(Y) )
( c1ause(P v Q R) not(cketra(P v Q))
dis(P v Q X v Y R) ~ )
( A lt=gt B equival(A lt=gt B X v Y) ~ I) sol(X) - ~ notetra(X) eon(X)
so~(X) - notetra(X)
( con (X)
( clause(P v Q R) not(ekctra(P v Q)) dis(P v Q X R) I)
cketra(P v Q) -
eketra(P) eketra(Q) eketra(F(I J)) shy
selec(F(I J))
c1ause(contradiction(sel(F(IJ))) _I
eketra(number(W I)) -
clause(cootradietion(num(Wl)) - eketr(P) shy
clause(contradiction(P) - 1
notctra(P) shy
not( e lause( con tradiction(P) _))
40
Searching (or disjunctions
dis(P v Q X v Y R) - dis(P X v Y R)
dis(Q X v Y R) con(R)
dis(P v Q X R) -
dis(P X R) dis(Q X R) con(R
dis(P X v Y R) - clause(contradicton(Pl J 1
dis(F(I J) sel(G(I J)) v Y R) - csel(G Fl dis(number(WI) num(W N v Y R) - cnum(N I)
dis(P P v Y R) -
dis(P X v Y R) - dis(P Y R)
dis(F(I J) seJ(G(IJ)) R) - csel(G F)
dis(number(WI) num(WN) R) - cnum(N I) dis(P P R) - 1
dis(FJ J X R) shy
( ckctra(F(IJ) cbeckeq(seJ(F(IJ))) )
dis(number(W Il X R) - ( ckctra(number(WI)) cbeckeq(num(WI)) )
dis(P X R) shy( ckctra(P) cbeckeq(P) ) 1
cbeckeq(P) shy
(( A lt=gt so2(contradiction(P))
bagof(A A [jj) ) ( so2(contradiction(P)) lt=gt B
bagof(B B Uj) ))
ckeq(A) shy
( so2(A) lt=gt B B lt=gt so2(A) ) bagof(B B UJ)
con((P Q)) -
clause(P R) con(R) con(Q) con(true) -
con(contradiction(P)) - clause(contradiction(P) J
con(cause(X Y)) - cause(X Y)
con(sel(X)) - sel(X)
con(num(X Y)) - num(X Y) con(P)- (( dause(P R) (con(R) ckeq(R)))
colJectin(P) )
collectin(P) shy
bagof(S (c1ause(P S) S = true) [L LIJ )
mkcon(L Ll L)
bagor(l (L2 ) UJ) L
mkcon((A AI) (B B1) (sol(A v B) e D)) -
mkcon(A B1 e) mkcon(A1 (B Bl) D)
mkcon(A (B B1) (sol(A v B) e)) -
mkcon(A Bl e)
mkcon((A AI) B (sol(A v B) e)) middot1
mkcon(Al B e)
mkcon(A B sol(A vB))
Searching ror equivalences
equival(A lt=gt B X v Y) - 1 ( equival(A lt=gt B X) equival(A lt=gt B Y) )
equival(s02(A) lt=gt 502(B) A) - clause(B _I equival(s02(B) lt=gt 502(A) A) c1ause(B _I
Top level or inrerence mechanism
goo((s02(whatnum) P)) -
getatm(P Xl
bagor(number(X Y) ( P so2(number(X Y)) ) A )
count1(A 00 L R) nl
bagor(X P B )
count2(B L R Ll Rl) nJ print()
(( LI = 0 Rl = 0 print(THE ANSWER IS ) nl
(( Ll = Rl prin(-Jumber or ) prn(P) print(is Ll) )
( Rlgt20000 prin(Number or I prn(P) print(is LI or more) )
42
( prin(Number of ) pfn(P) print( is from Ll to Rl) )) )
( print(THE ANSWER IS NO I )) print()
goo(X) shy
(( bagof(X X L) L = [I nl print()
print(THE ANSWER IS YES) nl wout(L) print() )
( equiv(X L) nl print()
print(THE ANSWER IS YES) nl wout(L) print(-) )
( c1ause(inpt(A ==gt B) _I ( impli(A B Z) impli(B A Z) ) print(l~Hl)
printTHE ANSWER IS YES) nl print(Z) print(Hj~(fH~) ))
goo(X) print( Hg)
print(THE ANSWER IS NO ) print( lH~lH~gg9l9lmiddotmiddot~Q(gmiddot)
00 Semhing for implications in equiV3lent relations
impli( B Z) shyt-ell( z1) prin(templ() pchn(S A lt=gt B) print()) close ( zl) consult(zl) templ(Z)
unload zl Z
Searching for equivalence
equiv (X L)
(( X lt=gt Y
equ(Y YI)t bagof(Y Yl L) L = [j )
(Y lt=gt X equ(Y YI) bagof(Y Yl L) L = [J )
( X = F(New)
clause(~ew T) makeup(T Tl)
(( Tl lt=gt B
equ(B Bl) bagof(Bl Bl M) M = [j L=[Newl )
(A lt=gt TI
equ(A AI) bagof(Al AI M) M = 1] L=INewj )) ))
makeup((A B) (AI Bl)) -
makeup(A A1) makeup(B BI)
makeup(A so2(A))
equ((A B) (AI BI)) -
equ(A AI) equ(B Bl)
equ(sol(X v Y) sol(XI v Yl)) -
equ(X XI) equ(Y YI)
equ(so2(X) so2(XI)) -
equ(X XI)
equ(contradiction(X) clJuse(contradiction(X) X) ) -
equ(X X)
Counting numbers
getatm((A B) X) -
( getatm(A X) getatm(B X) )
getatm(so2(F(X)) X) -
getatm(so2(X) X) - atom(X)
countl([J L R L R) -
countl([number(X Y)IT] L R L2 R2) shy
(( Y = (gt=~) LI is L + N Rl is R + 20001 l )
( Y = (gt N) LI is L+ N+ 1 RI is R + 20002 )
(Y == laquo=~) LI is L + 1 Rl is R + N )
(Y = laquo N) LI is L + 1 RI is R+N-I)
(Y == IJ LI is L + I Rl is R + J ) ( Y == N L1 is L + N RI is R + N ))
count1(T LI R 1 L2 R2)
count2(fJ L R L R) - 1
count2([XITJ L R L2 R2) shy
name(X Xl)
(( Xl = sknj LI is L Rl is R )
44
( Xl = Iskmj L1 is L + 1 RI is R + ZOOO1) ( LI is L + I RI is R + I ))
count2(T LI RI L2 R2)
pfn((A B)) - pfn(A) prn(B)
pCn(so2(F(X))) - prin(F )
prn(so2(X)) - atom(X) prin(X ) prn (so2(X))
Printing result
wout([XlJ - prt(X) nl woutf[xIY]) - prt(X) nl nl wout(Y)
prt(e(A B)) -
prt(A) prinr 8 ) prt(ltE) prt(eA) - prt(A)
prt(c(A EJ) - prin() prt(A) prine ) prt(B) prin(T)
prt(c A) - prt(A) prt((A E)) - ~
prt(A) nl prt(E) prt(sol(X v Y)) - ~
prt(X) prinC v) prt(Y) prt(A lt=gt B) -
prt(e A) prinC lt=gt ) prt(e B) prt(sol(X)) - prt(X)
prt(so2(X)) - prt(X
prt(c1ause(X Y)) - prt(X)
prt(contradiction(X)) - prin(contradiction() prt(cX) prinr))middot prt(num(XY)) - prin(number(X Y)) prt(sel(X)) - prin(X) prt(X v Y) - prt(X) prin( v) prt(Y) prt(X) prin(X)
Handling conditional queries
condi((Y Xl) shy
assertcon(X) Y
45
retractcon(X)
condi((B A))
retractcon(A) fail
assertcon((A B)) 1
assertcon(A) assertcon(B)
assertcon(A) asserta(A)
retrac teon ((A B)) 1
retracteon(A) retractcon (B)
retraetcon(A) - retract(A)
BIBLIOGRAPHIC DATA SHEET
Report No UIUCDS-F-84-928
3 Recipients Accession No
4 T ide and Subt ltle
An Annotated Predicate Calculus Inference System (APCIS)
S Report Date
November 1984 6
7 Author(s)
Kah-Eng Pua 8 Performing Organization Rept
No
9 Performing Organization Name and Address
Department of Computer Science University of Illinois Urbana IL
10 ProjectTaskWork Unit No
11 Contract Grant No NSF DCR 84-06081 ONR N00014-82-K-0186
12 Sponsoring Organization Name and Address
National Science Foundation Washington DC
13 Type of Report amp Period Covered
14
15 Supplementary Notes
16 Abstracts
This paper describes a deductive inference system called APCIS (Annotated Predicate Calculus Inference System) APCIS is able to carry out inferences from expressions involving numerical quantifiers selectors disjunctions of non-negated terms negated terms disjunctions of negated terms equivalences and exceptions It is also able to count the numbers of occurrence of a given simple term or a conjunction of terms The design of contradiction and the treatment of the disjunction of non-negated terms allow APCIS to accept Horn clauses as well as non-Horn clauses and to carry out inferences from them This feature makes APCIS more general than Prolog
17 Key lords and Document Analysis 170 Descriptors
APC (Annotated Predicate Calculus) APCIS (Annotated Predicate Calculus Inference System) Horn Clause Numerical Quantifier Prolog Selector
17b IdentifiersOpen-Ended Terms
17c COSATI FieldGroup
18 Availability Statement 19 Security Class (This
Re~f~~IA~SIF IFf)
21 ~o of Pages
49 211 ecurity Class (This
PageUNCLASSIFIED
22 Price
FOA NTIS n (10middot70 usco-oc 40329-
2
2 Overview ot APCIS
Figure 1 shows the general structure of APCIS There are four modes by which we can
invoke APCIS Each of them will be discussed in the following sections
21 Assertion-Translation Mode
Figure 1(30) shows schematically the phases that APCIS will go through when assertionshy
translation mode is invoked To translate APC assertion into Prolog we type to Prolog system
ta(X)
where ta stands for ~translation of assertion and X is any APC expression to be translated The
input assertion will then go through an APC translator (discussed in [3]) and its result will be
printed out on the terminal Note that the translated result is not loaded back to Prolog system
22 Query-Translation Mode
Figure l(b) is the schematic diagram showing the execution process of query-translation
mode To translate APC query we type to Prolog system
tq(X)
where tq stands for ~translation of query and X is any APC expression The input query will go
through the same APC translator mentioned above but the output will be in the form of ~Prolog
question (see Slction 31) As in the assertion-translation mode the output will only be printed
out on the terminal and will not be loaded back to Prolog
The above two modes provide only translation purposes The following two modes
perform the actual infNence
3
1-------------1 1 ta (X) I 1-------------1
1 1-------------1
APe 1 I Translator 1
1-------------1 I
1-------------11 Terminal I 1-------------1
(a) Assertion-translation mode
1------------ a(X) I
1------------1 1
1 1------------1 I APe I 1 Translator 1
1------------1
i-----------I 1----------1 I temp_file 1 1 Terminal 1 1-----------1 I----------i
1
1 1-------------1 I Prolog 1 1 system 1 1------------ -I
(c) Assertion mode
Figure 1 Four modes of APCIS
1---------------1 1 tq(X) 1 1---------------1
1 1---------------1 1 A P C 1 I Translator 1
1---------------1 I
1---------------1 I Terminal 1 1---------------1
(b) Query-translation mode
1--------------1 q(X) I 1--------------1
1 1------------------1 1 asserta(inpt(Xraquo 1 1------------------1
1 1---------------1 1 A P C 1 1 Translator 1 1---------------1
I 1---------------1 i temt__file 1 1---------------1 1---------------1 1 Prolog 1 1 system 1 1---------------1
I 1---------------1 1 Terminal 1 1---------------1
I 1-------------------1 1 retract(inpt(Xraquo I I-----------------~-I
Cd) Q-uery mode
23 Assertion Mode
Figure l(c) is a schematic diagram showing how assertion mode works In this mode the
input assertion will first go through the APC translator as in assertionmiddot translation mode After
which the translated result will be printed both on the terminal and to a temporary file called
tempfile which will subsequently be loaded back to Prolog system As a result the newly
translated input assertion will become Prolog term(s or clause(s) in the database
24 Query Mode
Figure l(d) shows schematically the stages that will go through when query mode is
invoked The input query crowned by the (unctor inpt will first be stored in the database It will
then be passed to the APC translator as in query-translation mode The output of the translator
will be printed on the temporary file tempfile which will subsequently be loaded to Prolog
system Upon loading tempfiie to Prolog system (recall that tempJile contains essentially a
Prolog question) the question is executed immediately and its result will be prin ted out on the
terminal In the last stage the original input query crowned by the functor inpt will be
retracted from the database
3 APe Translator
As described in [3] there are ten steps in the APC translator and each step undertakes a
unique transformation Assertion-translation mode and assertion mode go through these steps
which have been covered in [3] and will not be discussed here
31 Translation of Queries
We will now examine the different transrormations that query-translation mode and
query mode will go through They differ Crom assertion-translation mode and assertion mode only
5
in the last step of translation
In the last step of the APe translator all input queries (ie expressions entered via
query-translation mode or query mode) are dealt with by the following six predicates prques pi
plett peont pehar and pout The task of prques pi plett and peont is to arrange each
input query in desired order whereas pehar and pout will print out each atomic formula
character by character For illustration purposes consider the following five APe expressions
1 all( X man(X) ==gt mortal(X)
2 exists( X horse(X) v dog(X) )
3 - ( exists( X horse(X) amp dog(X))
4 all( X be_shouted_at(X) amp no_response(X) == gt deaf(X) v dead(X) )
5 exists( 2 X box(X) )
H the above five APe expressions are typed to Prolog via assertion mode or assertionshy
translation mode they will be translated to the corresponding Prolog expressions
la
mortal(XI) shy
man(Xl)
2a
horse(skml) v dog(skml)
3a
contradiction(( horse(XI) dog(Xl) )) shy
horse(Xl)
dog(XI)
4a
deaf(Xl) v dead(Xl) shy
be_shouted_at(X I)
no_response(X1)
Sa
box(sknl)
number(sknl2)
The above live translated expressions ( ie la through Sa ) will be printed on the
terminal and loaded to Prolog if assertion mode is used they will be printed on the terminal but
not loaded to Prolog if assertion-translation mode is invoked
Now if the original APC expressions ( ie 1 through 5 ) are typed to Prolog via query
mode or query-translation mode the corresponding questions will be translated into the following
queries
lb
goo(( condi(( mortal(Xl) man(Xl))) ))
b
goo(( soil horse(Xl) v dog(XI)) ))
3b
goo(( c1ause( contradiction(( horse(XI) dog(Xl) )) _) ))
4b
goo(( conditt deaf(Xl) v dead(Xl) (be_shouted_at(XI) no_response(Xl)) )) ))
5b
amp00(( so2( box(XI) ) s02( num(XI 2 )) ))
The above five translated queries ( ie Ib through 5b ) will be printed on the terminal
and loaded to Prolog if query mode is used they will be printed on the terminal but not loaded to
Prolog if query-translation mode is invoked
In the above queries goo 801 and 802 each forms a part of the inference mechanism of
APCIS goo occupies the top level of the inference mechanism whereas 801 and 802 are at the
1
next level 102 will take care of the searching of simple terms and 101 will deal with the
disjunctions of non-negated terms in the database We will come back to them in Section 4
At the first glance one may feel that the above translated Queries are Quite complicated
However a closer examination will reveal that they are not so Queries lb 3b and 4b can each be
categorized as a conditional query which is a distinct feature of APCIS wherels queries 2b and
5b lre asking simple facts in the database
To handle conditional queries we consider two cases First if the queries involve a
special clause contradition we invoke the built-in function el3ule(X Y) which will look for the
desired contradiction clause in the database Second if the queries do not involve the clause
contradiction we activate a defined Prolog predicate condi to take care of the necessary
searching (To avoid confusion the reader is urged to compare expressions started with the same
number in the above three sets of example)
To handle a query which asks a simple fact we surround each disjunction of terms with
the functor sol as in the example 2b or crown each simple term with the functor 802 as in the
example 5b
32 TranslatIon of Negated Term And Disjunction of Negated Terms
One feature of APCIS is its ability to handle input expressions consisting of only negated
term or a disjunction of negated terms in the forms
or
2 -(AI) v ~(A2) v v ~(An)
To handle the above two forms a special clause with clause head contradiction is
created This special clause head has only one argument which is either a term or a set of terms
grouped together in the form
8
(AI A2 An)
The right-hand side of the clause contradiction is exactly same as the argument in the clause
head For example the above two forms involving negated terms will be translated into the
corresponding forms as follows
1 contradiction( A ) shy
A
2 contradiction(( AI A2 An )) shy
AI A2 An
The design of the clause with clause head contradiction will greatly enhance the inference power
of APCIS (see the example in Section 44)
33 Translation ot Disjunction ot Non-negated Terms
Another feature of APCIS is its ability to handle input expressions involving a
disjunction of non-negated terms in the forms
1 Al v A2 v v An
or
2 Bl amp 32 amp amp Bm ==gt Al v A2 v v An
Unlike Prolog which accepts only Horn clauses APCJS will accept Horn clauses as well
as non-Horn clauses which take the above two forms The inference from non-Horn clauses is
made possible by the two defined predicates sol lnd s02 discussed in Section 42 and Section 43
respectively (see also the example in Section 44) In the APC translator the above two forms are
transbted into the corresponding forms as follows
1 Al v A2 v v An
2 Al v A2 v v An shy
g
Bl B2 Bm
34 Futher Transformation of Exceptions and Equivalences
To provide some backgrounds for the discussion of the further transformation of
exception and equivalence relations we will lirst reproduce the three goals in the Step 2 of the
APe translator discussed in Section 32 of [31
First expressions involving implication or the form A ==gt B will be transformed to
Second expressions with exception symbol or the form A - B will be changed to the
form ( A lt=gt -(B) ) amp ( -(A) lt=gt B)
Tbird expressions with equivalence symbol of the form -(A) lt=gt B or of the form
A lt=gt -(B) will also be converted to ( A lt=gt -(B) ) amp ( -(A) lt=gt B ) since tbere are
logically identical to exception relations Also expressions with equivalence symbol of the form
A lt=gt B or -(A) lt=gt -(B) will remain the same
After the Step] of the APe translator both sides of any transformed expression with
lt = gt symbol will be treated separately as if they are two independent expressions In the
Step 10 of the APe translator each side of lt=gt will again be treated separately and
transformed into a form similar to an transformed input query (see Section 31) Two examples
are given below
1 state(on) lt=gt -( state(olJ) )
2 all( 1 bot(l) amp humid(l) - winter(I) )
They will be transformed in the Step 2 or the APe translator into
1
(state(on) lt=gt -( state(off) ) ) amp ( -( state(on) ) lt=gt state(olJ) )
2
10
( hot(l) amp humid(l lt=gt -(winter(l)) ) amp
( -( hot(l) amp humid(l)) lt=gt winter(I)
In Step la they will again be transformed to
1
so2( state(on) ) lt=gt so2( contradiction( state(oH) ) )
so2( contradiction( state(on) ) ) lt=gt so2( state(oH) )
2
( s02(hot(XI)) so2(humid(XI))) lt=gt so2( contradiction( winter(Xl ))
so2( contradiction(( bot(Xl) humid(Xl) )) ) lt= gt so2( winter(XI) )
There are two advantages in the treatment of exception and equivalence symbols in this
way First it will prevent Prolog program from going into an infinite loop which is difficult to
avoid if equivalent relation such as A lt=gt B is transformed into the logically equivalent form
( A ==gt B) amp ( B ==gt A) Second by maintaining both sides of lt=gt symbol in
query form the searching on either side caD be done more easily and efficiently since the form
is already processed and does not need any further transformation
Inference Mechanism
As mentioned at the end of Section 31 goo sol and s02 each forms a part of the
inference mechanism of APCIS with goo occupying the top level and 80) and 802 the second
level In addition to these countl count2 equlv and impll are also at the second level of the
inference mechanism We will go over all of them in the following sections
I goo
goo is essentially the starting point of the inference Whenever a translated query is
loaded to Prolog system from temp-fie goo will go through one or more of the following steps in
11
sequence
G 1 Check if the query asks for the numbers of occurrence of certain term(s) It so then
pass It to eountl and eount2 else go to G2
G2 The query will be passed down to sol or s02 (or both) to check i( any assertion in the
database can satisfy the query It the answer is positive then the query succeeds else
go to G3
G3 The query will be passed to equlv to carry out further searching It the searching is a
success then the query will be closed with a success else go to G4
G4 It the query is in the form A ==gt B then it will be passed to Impli It Impll
succeeds then done else the query will be closed with a (ailure
42 sol
801 and 802 together with dis and eon form the most complicated part of the APCIS
iorerence mechanism In this and the next section we will look at sol and s02 dis and eon will
be discussed in Section 44 We will close Section 44 with an example that illustrates the
materials presented in Section 42 through Section 44
sol is at the second level of the inference mechanism It will deal with any disjunction of
non-negated terms For any disjunction passed to it it will go through one or more of the
following steps in sequence
S1 Check if any term In the disjunction can be satisfied by any term or clause in the
database without contradiction It so then done else go to S2
S2 Pass the disjunction together with another disjunction (and its tlil) picked up from
the database to dis It dis succeeds then done else go to S3
S3 Pass the disjunction down to equlval which will check if any term in the disjunction
matches either side of any equivalence relation in the database It such a match is
found then check if the other side of the equivalence C3n be satisfied It so then done
else the goal fails
43 s02
s02 is also at the second level of the inference mechanism It will take care of all the
simple terms in the transl1ted query The following is the sequence that s02 wiII follow in
searching
S1 Check if the term passed to it caD be s3tisfied by any term or clause in the d3tabase
without contradiction It so then done else go to S2
S2 Pass the term together with a disjunction of terms (and its tail) picked up from the
database to dis If dis succeeds then done else the goal fails
44 dis and con
dis has three arguments In the first two clauses of dIs the first argument P v Q is
found in the database using the builtmiddotin functiol clause and the third argument R is the tair of
the term or the clause P v Q If P v Q is not a clause but a term R will be instantiated to trUE
The second 3rgument comes from either lIol or 802 and thus takes the form of either X v Y (a
disjunction of terms) or T (3 simple term)
All the clauses of dis together with con will perform the searching as exemplified in the
following algorithm (we will keep the notationsin this section)
01 Check if every term in P v Q is in X v Y It so then go to 03 else go to D2
02 For any term (in P v Q) which is not in X v Y or does not match T perform the
following tests
a Check if the term (in P v Q) has already been negated in the datab3Se (ie check if
the contradiction of the term exists in the d3tabase) If so then repeat D2 for other
terms not found in X v Y or not matching T else go to b
13
b Check if the contradiction of the term matches either side of any equivalence
relation in the database If such a match is found then check if the other side of the
equivalence can be satisfied If so then repeat O~ for other terms not found in X v Y
or not matching T else the goal fails
It all the terms (in P v Q) which are not in X v Y or do not match T survive either one
of the above two tests then go to 03
03 This step is essentially done by eon whose goal is to satisfy the tail R of P v Q It
con succeeds then done else the search fails
To close this section we will give an example to illustrate what we have covered In
Section 42 through Section 44
Example Assume that we already haye the following expressions in the database
horse(skml) v dog(skmI)
contradiction(( dog(XI) ))shy
dog(XI)
query goo(( soZ horse(X)) ))
This query will be passed to 802 which will check it the term horse() can be satisfied iu Step S 1
of Section 43 It is a failure So we now go to Step S2 In this step we pick up the disjunction
horse(~kml) v dog(skml) (and its tail true) in the datab3Se and pass it together with the term
horse(X) to dis We are now in Step 01 of Section 44 In this step we find that dog(skml) does
not match horse(X) So we have to go to Step 02 In Step 023 We find that the term dog(skml)
has already been negated (the second expression in the database) So we go to next step 03 Since
the tail of the disjuDction horse(skml) v dog(skml) is the atom true con is satisfied and the
query succeeds
45 countl and count2
countl and count2 are responsible for the counting of tbe numbers of occurrence of a
given simple term or a conjunction of terms They are activated by input queries in the form
q( exists( X whatnum amp P) )
where whatnum is the l~bel for activating the counting of the numbers of occurrence of P which
can either be a term or a conjunction of terms
countl will count the number of term(s) which will satisfy P and associate(s) with
numerical quantification(s Two counters are set to update the lower and upper boundary or the
scope or the numfrical quantifications encountered
The contents of the two counters are then passed to count2 which is responsible for the
counting or the following three types of term First term(s) which will satisfy P and associate(s)
with existential quantification(s Second term(s) which will satisfy P and has(have) Prolog atom
as its(thfir) argument(s) Third term(s) that will satisfy P and itself(themselves) is(are) Prolog
atom(s )
46 equiv
equlv will be activated only after sol and B02 have failed The first two goals of equlv
are similar to that of Step S3 in Section 42 and Step D2b in Section 44 The third goal or equiv
makes possible the inference on either side of any equivalent relation For example if we type the
following three expressions to Prolog in assertion mode
l all( X hot(X) amp humidX) - winter(X)
2 all( X hot(X) amp bumid(X) ==gt unpresent(X))
3 - ( exists( X winter(X) ) )
and then ask APCIS in query mode
q( cxists( X unpresent(X) ) )
15
APCIS with the aid of equlv will be able to answer yes to this query
41 lmpll
lmpll can be considered as the last attempt that APCIS would make to satisfy a
query It is activated only after equlv has failed It will first check if the query is conditional If
so it will convert the implication symbol to equivalence symbol and search if such an equivalent
relation can be found in the database If so a success Otherwise a failure
5 More on the Inference Mechanism
Having looked at all the subparts at the top two levels of the inference mechanism we
are ready to look at other subparts at lower levels
51 num and cnum
One distinct fe3ture or APCIS is its ability to deal with numerical quantifications As
mentioned in Section 31 input queries and assertions will undergo different transformations in
the last step (Step 10) of translation This also holds true for expressions involving numerical
quantifications Consider the following expression
exists( 6 X horse(X) )
If it is entered to Prolog via assertion mode we will after going through all the steps of
translation have the rollowing entered to the database
horse(sk n I
number(sknl6)
Now if we want to ask Are there more than five horses 7 and type in
q( exists( gt5 X horse(X) ) )
1amp
APCIS will translate the question and enter to Prolog the following query
goo(( s02( horse(X) ) s02( num( X gt5 )) ))
Note that the term number(slml 6) in the database and the term num(X gt S) in the query are
different predicates and this difference is exactly where the power of the clause num(X N)
defined in APCIS comes from When the clause num(X N) in APCIS is activated it will search
through the database to see if there is any term of the form number(X I) whose first argument
matches the first argument of num(X Y) in the query It a match is found the second arguments
of both num(X Y) in the query and number(ltI) in the database will be passed to cnum in
APCIS
The job of cnum is to compare the numerical messages carried by the second
argument or the term rlum(X Y) in the query and the second argument of the term rlumber(X I)
in the database to see if they match with each other according to the rules defined in cnum
While there are 25 rules for such matching purposes the idea is simple
Imagine that the second argument Y of the term num(X Y) in the query
and the second argument I of the term num()( I) in the database each occupies a
place in an integer line (Le the integer line in mathematics) To have a match
the domain covered by Y should contain the domain covered by L
As an example the answer to the above query is positive since the domain of gt5
contains the domain or 6
Before closing this section we will bring out a speciaJ translation aspect of expressions
involving numbers by an example We first type to APCIS the Collowing expressions in assertion
mode
1 aU(X all(Y father(X Y) amp number(Y gt6) ==gt has_manY3hildren(X) ))
2 exists(X exists( 12 Y Cather(X Y) ) )
11
After going tbrougb all tbe translation steps tbe Collowing two expressions will be entered to tbe
database
I
bas_many_cbildren( Xl ) shy
Cather( Xl X2 )
num( X2 gt6 )
2
Catber( sk m1 sk n2 )
number( skn2 12 )
lotice that whenev(gtr a term with Cunctor number appears at the rigbt-band side oC a Prolog
clause its Cunctor will be cbanged to num automatically This treatment will greatly cnbance tbe
inference power of the clause sbown in l above For instance iC we now ask tbe question
q( exists( X bas_many_children(X) ) )
The right hand side oC the clause l will match the two terms in 2 and tbe query succeeds
52 Bel and cael
A special feature of APe is tbat all predicates tbat express relations = = gt
gt= lt and lt= can be expressed explicitly using infix notations as relational statements
called selectors To handle selectors we defined Bel in APCIS
Every expression involving selectors will undergo different translations in assertion mode
and query mode For example the assertion
a( exists( [X Y] box (X) amp box(Y) amp (weigh t(X) gt weight(Y) ) ) )
will be translated into the following three terms and entered to tbe database
box( skml )
box( skm2 )
18
weight( skm 1 ) gt weight( skm2 )
Now it we want to ask Is it true that there exists two boxes of different weights and type in
q( exists( [X Yl box(X) amp box(Y) amp ( weight(X) = weight(Y) ) ) )
The question will be transformed to the following query and entered to Prolog
goo(( so( box(XI) ) s02( box(X2) ) so2( sel( weightXI) = weight(X2) )) ))
Note that the selector in the above query is surrounded by the functor set When any clause or
8el in APCIS is activated it will search through the database to see it there is any selector whose
two arguments (left and right side or any selector symbol) match the two arguments of the
selector in the query At the same time 8el will check iC the selector symbols (may be different) or
the two different selectors (one in the query and one in the database) satisfy the rules defined in
sel There are 12 matching rules defined in sel All oC them ~re straightforward and will not be
discussed here An example will be enough to explain how 8el works
Consider the execution of the above transformed query The first two terms in the query
are satisfied by the first two terms in the database and Xl and X2 are instantiated to skml and
skm2 respectively The third term of the query will be passed to eel (of APCIS) which finds a
match on each side of the two selectors (one in the query and one in the database) At the same
time the two different selector symbols gt and = are found to satisfy one of the rules in
8el As a result the query succeeds
To enhance the inference power of clauses involving selectors all the selectors appearing
on the rightmiddothand side oC any clause will be surrounded by a functor set The idea is similar to
that in the last part of the previous section
c8el is exactly the same as 8el functionally It provides a convenient way to compare
selectors when dis is being executed
19
8 Printing Result
Whenever a goal is successfully executed APCIS will not only response with a yes but
also print out the matched terms or clauses in the database This is made possible by the built-in
function bagor and the two predicates wout and prt defined in APCIS
7 Summary
In this paper a description of a deductive inference system called APCIS (Annotated
Predicate Calculus Inference System) has been provided APCIS is able to carry out inferences
from expressions involving numerical quantifiers selectors disjunctions of non-negated terms
negated terms disjunctions of negated terms equivalences and exceptions It is also able to count
the numbers of occurrence of a given simple term or a conjunction of terms
The main idea of APCIS is that each input APC expression is first passed to a
preprocessor ( ie APC translator ) which dissolves and transforms each APC expression into
Prolog expression(s) which will then be loaded to Prolog system The user bas to specify whether
each input expression is to be entered as an assertion or as a query by invoking either assertion
mode or query mode respectively Each assertion or query will undergo different transformations in
the preprocessor The different treatment of assertion or query not only allows a full uS1ge of the
Prolog inference mechanism but also makes possible a higher level of inexact pattern matching
exemplified by the examples in Section 51 and Section 52 where the four predicates num
cnum sel and csel are discussed This higher level of pattern matching increases the inference
power of APCIS greatly
The design of contradiction and the treatment of the disjunction of non-negated terms
allow APCIS to accept non-Horn clauses and to carry out inference from them This feature
makes APCIS more general than Prolog
20
While APCIS performs very well in many sets of arguments provided by the author it is
still too early to jump to conclusion that it can perform equally well in all types of problems In
any event the expressiveness of APC has greatly been retained in the present version of APCIS
and moreover some design ideas or APCIS mentioned in this paper are not restricted to APCIS
- they may be carried over to learning programs with narrower scopes
21
References
[1] W F Clocksin and C S Mellish Programming In Prolog Springermiddot Verlag Berlin Hpoundidelberg 1981
[2] R S Michalski A Theory and Methodology of Inductive Learning Chpt 4 Machine L earning Tioga Publishing Co Palo Alto CaliJornia 1989
[3] K-E Pua Translating Annotated Predicate Calculu8 to Prolog ISG Report 84middot1 UlUCDCSmiddotFmiddot918 University oj Illinois Urbana IL June 1984
22
Appendix A
APCIS Users Manual
1 Get Started
Users are urged to follow the steps depicted below
1 Get the PROLOG interpreter by typing
alias prolog mntb2sammutsammutprologprolog (Vax A)
or
alias prolog mntb2sammutsammutbinprolog (Vax B)
2 Load apc and infer by typing
prolog apc infer
When large APC expressions are expected we can increase the stlck by typingI
prolog -snnnn ape infer
where ns denote the number of stacks in decimal
3 When the wording LSW - PROLOG appears on the terminal we are reldy to interact
with APCIS The four modes by which we can invoke APCIS are summarized below
a Assert ion-Translation Mode
ta(X)
b Query-Translation Mode
tq(X)
c Assertion Mode
a(X
d Query Mode
q(X)
23
where Xs are APC expressions
2 Notations Used in APCIS
Below is a summary or notations used in APCIS
a Logical operators
amp
v
==gt
lt=gt
-
negation
conjunction
disjunction
implication
equivalence
exception
b Binary relation symbols in selectors
-
=
gt=
lt=
gt
lt
equal
not equal
greater or equal
smaller or equ al
greater
smaller
c Relational operators in numerical quantifiers
lt less than
lt= less than or equal
gt greater than
gt= greater than or equal
d BinlTY operator in numerical quantifier
range
e Universal quantifier
all(X p(X))
f Existential quantifier
exists(X p(X))
g Numerical quantifier
exists(I X p(X))
where p(X) is a formula
where X is a variable or a Jist of variables or the
form [HI~rj and p(X) a formula
where I repersents expression involving integer(s)
and operator(s) in c or d above and p(X) a formula
25
Appendix B
APCIS Program Listings
------------------------------- Program Name APCIS - Part 1 APC Translator
-------------------------------
op(3OO fx -)1
op(500 xfy amp)
oPt 500 xfy v)
op(600 xfx )
op(700 fx [gt= lt= gt lt ]) op(400 xfy [= gt= lt= gt lt ])1 op(900 xfy gt lt=gt -])1
steps(X Xg) shy
numbervars(X 1 J Step 1 change variables to iis
rmimp(X X) Step 2 conv(X X3) Step 3
rewrite(X3 X4) Step 4
negin(X4 X5) Step 5
dropexist(X5 X6 1]) Step 6
dropall(X6 X7) Step 7
distrib(X7 X8) Step 8 clausiCy(X8 X9 [J) Step 9
ta(X) shysteps(X Xg)
(( Xg = II nl
print( yes it is always true) )
( nl nl printcl(X9))) Step 10a
tq(X) shy
steps(X Xg)
prques(Xg)
28
Step 2 Removing implic3tions amp Transforming exceptions and equiv3lences
rmimpl( P - Q (PI lt=gt (QI) ) amp ((PI) lt=gt QI) ) -
rmimpl(P PI) rmimpl(Q QI)
rmimplnp) lt=gt Q (PI lt=gt -(QI)) amp nPI) lt=gt QI) ) - 1
rmimpl(P PI) rmimpJ(Q QI)
rmimpJ(P lt-gt -(Q) (PI lt=gt -(QI)) amp nPI) lt=gt QI) ) -
rmimpl(P PI) rmimpl(Q QI)
rmimpl( P lt=gt Q PI lt=gt QI ) - I
rmimpl(P PI) rmimpl(Q QI)
rmimpl( P ==gt Q -(PI) v QI ) - I
rmimpl(P PI) rmimpl(Q QI)
rmimpl( all(X P) aI(X PI) ) - 1
rmimpl(P PI)
rmimpl( exists(X P) exists(X PI) ) -
rmimpl(P PI)
rmimpl( exists(I X P) exists(I X PI) ) -
rmimpl(P PI)
rmimpl( P amp Q PI amp Ql ) -
rmimpl(P PI) rmimpl(Q Ql)
rmimpl( P v Q PI v QI ) -
rmimpl(P PI) rmimpl(Q QI)
rmimpl( -(p) -(PI) ) - I
rmimpl(p PI)
rmimpl( P P )
St~p 3 Converting numerical amp distinctive quantifiers
L Numerical quantifiers
examples of input forms
1 exists(gt= i X pIX)) where i is an integer
2 exists(i X pIX)) where i is an integer
3 exists(i j X pIX)) where i j are integers and iltj
4 exists(il v i2 X pIX)) where is are integers
examples of output forms of this step
1 exists(X pIX) amp number(X gt= i) )
2 exists(X pIX) amp number(X i) ) 3 exists(X pIX) amp number(X ij) ) 4 exists(X pIX) amp number(X il v i2) )
II Distinctive quantifiers
27
example or input Corm
exists([XYL p(X Y))
example or output Corm or this step
exists(X exists(Y p(XY)) )
conv(P lt=gt Q PI lt=gt QI) - 1
conv(P PI) conv(Q QI)
conv(al1(X P) all(X PI)) -
conv(P PI)
conv(exists(HIT] P) R ) - conv(P PI) convert distinctive quantifier
convtdis(exists([HIT]PI) R)
conv( exists(I X P) exists(X PIamp number(X I) )) -
conv(P PI) convert numerical quantifier
conv(exists(X P) exists(X PI)) - 1
conv(P Pl)
conv(P amp Q PI amp QI) - 1
conv(P PI) conv(Q QI)
conv(P v Q PI v QI) - t conv(P PI) conv(Q QI)
convC(P) -(PI)) -
conv(P PI)
conv(P Pl
convtdis(existsl[XL P) exists(X P)) - atomic(X) convtdis(exists[XIYj Pl exists(X R)) shy
convtdis(exists(Y P) R)
Step 4 Rewriting compound predicates andor compound selectors
Outputs are smiple predicates andor simple selectors
rewrite(P lt=gt Q PI lt=gt QI) - t rewrite(P PI) rewrite(Q QI)
rewrite(all(X Pl all(X PI)) - 1 rewrite(P PI)
rewriteexists(X P) exists(X PI)) - I rewriteP PI)
rewrite(P amp Q PI amp QI) - rewrite(P P 1) rewrite( Q Q 1
rewrite(P v Q PI v QI) - 1
rewrite(P PI) rewrite(Q QI)
rewriteC(P) -(PI)) - I
28
rewrite(P PI) rewrite(F(A B) R) -
rewrite(A AI) rewrite(B BI) re(F(AI BI) R)
rewrite(F(A) R) -
rewrite(A AI) re(F(AI) H)
rewrite(F(A B C) R) -
rewrite(A AI) rewrite(B BI) rewrite(C CI) re(F(AI BI CI) R)
rewrite(F(A B C D) R) -
rewrite(A AI) rewrite(B Btl rewrite(C CI) rewrite(D DI) rc(F(AI BI CI Dl) H)
rewrite(PP)
re(F(A B v el (RI v R2) -
re(F(A Bl RIl re(F(A C) R2) reF(A B amp cl (RI amp R2)) -
re(F(A B) RI) re(F(A e) R2) re(F(A amp B C) (Rl amp R2)) -
re(F(A e) R 1) re(F(B C) R 2) re(F( v B el (R I v R2)) -
re(F(A el R I) reFB el R2) re(F(A amp Bl (R I amp R2)) -
re(F(A RI) re(F(BJH2) re(F(A v B) (R 1 v R2)) -
re(F(A) RI) re(F(B) R2)
re(F(A vB c Dl (RI v R2) -
re(F(A C D) RI) re(F(B C D) R2) re(F(A amp B C D) (RI amp R2)) -
re(F(A C D) Rll re(F(B C D) R2) re(F(A B v C D) (HI v R2)) -
re(F(A B D) RI) re(F(A C D) R2) re(F(A B amp C D) (HI amp R2)) -
re(F(A B D) RI) re(F(A C D) R2) re(F(A B C v D) (RI v R2)) -
re(F(A B C) R I) reF(A B D) R2) re(F(A B C amp D) (RI amp R2)) -
29
re(F(A B C) RI) re(F(A B D) RZ)
re(F(A v B e D E) (R I v R2)) -
re(F(A e D E) R I) re(F(B e D El R2) re(F(A amp B e D E) (RI amp RZ)) -
re(F(A e D El R 1) re(F(B e D E) R2) re(F(A B v e D E) (R I v R2)) -
re(F(A B D E) RI) re(F(A e D E) R2)
re(F(A B amp e D E) (RI amp R2)) -
re(F(A B D El RI) re(F(A e D E) RZ) re(F(A B e v D E) (R I v R2)) -
re(F(A B e El R 1) re(F(A B D E) RZ) re(F(A B e amp D E) (RI amp RZ)) -
re(F(A B e E) R I) re(F(A B D E) RZ)
re(F(A B e D vEl (RI v RZ)) - l
rc(F(A B C D) RI) re(F(A n e El RZ) re(F(A B e D amp El (RI amp RZ)) - ~
re(F(A B e D) RI) re(F(A B e El RZ)
re((A = B) (A = B)l-
re((A = Bl (A = 8)) -
retIA gt= BI (A gt= B)) -
re((A lt= B) (A lt= B)) -
re((A gt B) (A gt B))-
re((A lt Bl (A lt Bl)- re(A A)
Step) Bringing n(gation inwards
Degin(-(P) PI) - neg(P Pl)
negin(P lt=gt Q PI lt=gt Ql) - ~
negin(P PI) negiD(Q QI)
Degin(aU(X P) all(X PI)) - Degin(P PI) negin(exists(X P) exists(X PI))- negin(P PI) negin(P amp Q PI amp Ql) - Degin(P PI) negin(Q Ql)
Degin(P v Q PI v QI) - Degin(P PI) negin(Q QI) negin(P Pl
neg(-(P) PI) - negin(P PI)
neg(all(X P) exists(X PI)) - neg(P PI)
30
neg(exists(X P) all(X PI)) - neg(P PI)
neg(P amp Q PI v QI) - neg(P PI) neg(Q Ql)
neg(P v Q PI amp QI) - neg(P PI) neg(Q QI)
neg(P -(PH
Step 6 Dropping existnetial quanti6ers
dropexist(P lt=gt Q PI lt=gt QI Elerns) - dropexist(P PI Elerns) dropexist(Q QI Elerns)
dropexist(alJ(X P) all(XPI) Elerns)
dropexist(P PI [XIElernsJ)
dropexist(exists(X P amp nurnber(X Yraquo P2 Elerns) -
genfun(skn Newg) Fun = [NewgIElerns]
subst(FuD X P amp Dumber(X Y) PI)
dropexist(Pl P2 Elerns)
dropexist(exists(X P) PZ Elerns) -
genfun(skrn Newf) Fun = [NewfIElernsJ
subst(Fun X p PI)
dropex ist(P 1 P~ Elerns)
dropexist(P v Q PI v QI Elerns) - ~
dropexist(P PI Elerns) dropexist(Q Ql Elerns)
dropexist(P amp Q PI amp QI Elerns) - 1
dropexist(P Pl Elerns) dropexist(Q QI Elerns)
dropexist(P P _)
gen fun(R oot Newn arne) shy
getnurn(Root Nurn)
narne(Root Rootlist)
append(Rootlist[Nurnj Narnelist)
concat(Narnelist Newnarne)
getnurn(Root Nurn) shy
retract(currentnurn(Root Nurn 1 raquo
Nurn is Nurni + 1
asserta(currentnurn(Root Nurn))
getnurn(Root 1) - asserta(currentnurn(Root 1))
subst(New Old Val Val) - var(Val)
subst(New Old Old New) - 1 substNew Old Val Val) - atornic(Val)
31
subst(New Old Val Newval) shy
runctor(Val F N)
CUDctor(Newval F N)
subst_args(N New Old Val Newval)
subst_args(O J J - J J
subst_args(N New Old Val NewVal) shy
arg(N Val OldArg)
arg(N NewVal NewArg)
subst(New Old OldArg NewArg)
NI is N - I
subst_args(Nl New Old Val NewVal)
append([J L L) -
append([XILl] L2 [XIL3]) - append(Ll L2 L3)
Step - Dropping universal quantifiers
dropall(P lt=gt Q PI lt=gt QI)-
dropall(P PI) dropall(Q QI)
dropall(all(X P) PI) - ~ dropall(P PI)
dropall(P amp Q PI amp QI) -
dropall(P PI) dropall(Q QI)
dropall(P v Q PI v QI) -
dropall(P PI) dropall(Q QI)
dropall(P P)
Step 8 Distributing conjunctions over disjunctions
distrib(P lt=gt Q PI lt=gt Ql) - t distrib(P PI) distrib(Q QI)
distrib(P v Q R) -
distrib(P PI) distrib(Q QI)
distributing(PI v QI R)
distrib(P it Q PI it QI) -
distrib(P PI) distrib( Q QI)
distrib(P P)
distributing((P amp Q) v R PI amp QI) -
distrib(P v R PI) distrib(Q v R Ql)
32
distributing(P v (Q amp R) PI amp Ql) -
distrib(P v Q PI) distrib(P v R Ql)
distributing(P P)
Step 9 Packing each conjunction into clauses
c1ausify(P amp Q CI C2) -
clausiCy(P CI C3) c1ausify(Q C3 C2)
cbusiCy(P [d(A B)ICs] Cs) shy
inclause(P A [j B [I) 1
c1ausiry( C C)
inclause(P v Q A AI B B1) -
inc1ause(P A2 AI B2 Bl)
inclause(Q A A2 B B2)
inclausenp) A A B1 B) -
notin(P A) putin(P B B1)
inclause(P AI A B B) shy
notin(P Bl putin(P A AI)
notin(X [XU) - fail
notin(X [JLj) - notin(X L)
notin(X 1])
putin(X II [X]) - 1
putin(X [XILJ L) -
putin(X [YILJ [YILl]) - putin(X L Ll)
Step 1Oa Printing clauses
printcl([]) - nl nl
printcl(c1(AB)ICsj) - printcl(A Bl nl printcl(Cs)
printcl(L II) - printdis(IL) prinr)middot
printclHl L) - prin(contradiction(() printconl(rL)
print()) - ) printconj(rL) prinr )
printcl(Ll L2) shy
printdis(ILl) print( - ) printconj(rL2) prin()
printdis(S[Lj) - printcbar(SL)
33
printdis(S[LILs]) - printchu(SL) prin( v) printdis(SLs)
printconl(S[LI) - printchar(SL)
printconl(S[LILs]) - printchar(SL) prin( ) printconl(SLs)
printconj(S[L]) - tab(3) printchar(SL)
prin tconj( S [L IL sl) shy
tab(3) printchar(SL) print( ) printconj(SLs)
printchar(SP) shy
atomic(P)
name(P L)
L = [IT]
concat([XIT NewP)
prin(~ewP)
printchar(SP) shy
atomic(P)
prin(P)
printchar(SA lt= gt B) -
prin((l clausify(A AI [j) pl(eAl) prin())
print lt=gt )
prin(() cbusify(B Bl [I) pJ(eBl) prine))middot
printchar(rnumber(X N)) shy
prin(num() printchar(rx) prin( )
printchar(rN) prinC))
printchar(rF(A B)) shy
seJec(F(A B))
prinCsel() printchar(rA)
prin( F ) printchar(rB) prinC))
printchar(SF(A B)) shy
( selec(F(A B)) F = infix )
printchar(SA) prin( F ) printchar(SB)
printchar(SF(A)) shy
(F= prefix gt= F= prefix lt= F= prefixgt F= prefix lt )
prin(F ) printcbar(SA)
printchar(SP) shy
functor(P F MaxN)
prin(F ()
Nl is MaxN - 1
putout(S N 1 P MaxN)
34
prin())
putout(S 0 P MaxN) -
arg(~laxN P Argu)
prin tchar(SArgu)
putout(S N p MaxN) shy
Nt is MaxN - N arg(NI P Argu)
printcbar(SArgu )
prin( )
N2 is N - 1
putout(S N2 P MaxN)
selec(FA B)) shy
( F= infix = F= infix f= F= infix gt=
F= infix gt F= infix lt= F= infix lt )
35
----------------------------------Program Name APClS - Part 2 Inference Mechanism ---------------------------------- a(X) shy
steps(X X9)
(( X9 =[] nl
print( yes it is always true) )
( X9 =[cI(IJ[])] nl
print( no it is always false) )
( nl nl printel(X9) Step 1Oa
tell(temp_file) printel(X9) e1ose(temp_file) consult(temp_6Ie) ))
q(X) shy
asserta( in pt(X))
steps(X X9)
(( X9 = [] print(middot~H~~middot~t~)
print(THE AiSWER IS YES)
print( ilgIQlQl(~) )
( X9 = [e1([j [j)] Pr1nt ( OJ fi(i I~ iii Ij)middot(i)(i) fiyenQ)riiio(i)(ij)(i)fj)fiyen1li1il1li1il)__ gtw~ __~_~ _~~_ ~_-=~
print(THE ANSWER IS NO ) print() )
( teI1(temp_6Ie)
prques(X9) Step 1Ob
close(temp_file)
nl print(Let me think about it) nl
consult(temp_6Ie) ))
retrac t( in pt(X))
Step lOb Printing question
prques(lcl(A 8)1) - prin(goo(() pl(qA 8) print()))
prques([c1(A 8HCs]) - prin(goo(() pl(qA 8) print() pl(q Cs)
pl(e [c1(A 8)]) - pl(eA 8)
pl(q [c1(A 8)]) - pl(qA 8) print()))
pl(S [e1(A B)ICs]) - pl(SA B) prin( ) pl(S Cs)
38
pl(q [j L) - prin(c1ause(contradiction(() pcont(qL) prin())_))
pl(S [I L)- prin(so2(contradidion(() pcont(SL) print))))middot
pl(S [L] []) - prin(so2() pcbar(SL) prin())
pl(S L [J)- prinsol() plett(SL) print))
pl(S [L] LI) - prin(condi(() pchar(cL)
prin(() pcont(S Ll) prine))))
pl(S L Ll)- prin(c1ause() plert(cL)
prin(() pcont(S Ll) prine)))
plert(S[LJ) - pchar(SL)
plert(SjLILsj) - pcbar(SL) print v) pleCt(SLs)
pcont(S[L]) - pchar(SL)
pcont(S[LILsj) - pcbar(SL) prinr ) pcont(SLs)
pcbar(SP) shy
atomic(P)
name(PL)
( L = [IT] L = [5 k miT] L = [5 k niT] )
concat[XITj NewP)
prin(0JewP)
pchar(SP) shy
atomic(P)
prin(P) pchar(SA lt=gt B) -
prin(() dausify(A AI []) pl(eAI) prin())
prinr lt=gt ) prin(() dausify(B BI ]) pl(eB) print))
pchar(Snumber(X N)) shy
prin(num() pchar(SX) prin()
pchar(SN) prinr))
pcbar(SM N) - prin(M N)
pcbar(cF(A B)) shy
selec(F(A Braquo
pcbar(cA)
prine F ) pchar(cB) pchar(SF(A B)) shy
selec(F(A B))
prin(sel() pchar(SA)
print F ) pchar(SB) print)) I
31
pc har(SF(A)) shy
( F= prefix gt= F= prefix lt= F= prefixgt F= prefix lt )
prin(F ) pchar(SA)
pchar(SP)shy
runctor(P F MaxN)
prin(F ()
011 is MaxN - 1 pout(SNl P MaxN)
print) )
pout(S 0 P M3xN) - 1
arg(~bxN P Argu)
pchlr(SArgu )
pout(S N P MaxN shy
Nl is MaxN - N
arg(Nl P Argu)
pchar(SArgu
prin( )
N2 is N - 1
pout(S N2 P ~13xN)
Comparing numbers in numerical quantifiers
num(XN) shy
number(X I)
cnum(N 1) ~
cnumlaquo=01 lt=I- N gt=I
cnumlaquo=J lt I) - N gt=1-1
cnumlaquo=NIJ) - N gt=J 1
cnumlaquo=N J)- integer(I) N gt=I~
cnum(gt=N gt=1) - N lt=1
cnum(gt=N gt I) - N lt=1+ 1 cnum(gt=NIJ) - N lt=1
cnum(gt=N lt=1)- N lt=1
cnum(gt=N lt I) - N lt=1 L cnum(gt=N 1)- integer(I) N lt=1
cnum( lt N lt 1)- N gt=1 L
38
cnum( lt N lt=1) - N gt I cnum( lt NLJ) - N gt J
cnum( lt N 1)- integer(I) N gt 1
cnum(gt N gt I) - N lt=1 cnumlgt i gt=1) - N lt I
cnum(gt N lt=1) - N lt=0
cnum(gt N lt I) - N lt=0
cnum(gt iIJ) - N lt I cnum(gt N 1)- integer(I) N lt I
cnum(~LN lt=1) - M=I N gt= I l
cnum(~LN lt I) - M=l N gt= I-I
cnum(~LNLJ) - M lt =1 N gt = J
cnum(~1N 1)- integer(I) M lt= I N gt= I
cnum(- N) - integer(N)
Comparing selectors
sel(X = Y) shyX= Y
sel(X I=Y) shy(X I=Y X lt Y Xgt Y)
sel(X gt Y) shyXgt Y
sel(X lt Y) shyXlt Y
selX gt=Y) shy(X gt=Y X= Y Xgt Y)
se(X lt=Y) shy
(X lt=Y
X= Y
X lt Y)
csel(infix = infix =)
39
csel(infix = infix = csel(infix = infix gt)
csel(infix = infix lt) csel(infix gt infix gt) cseJ(infix lt infix lt) csel(infix gt= infix gt=) csel(infix gt= infix gt csel(infix gt= infix =)
csellinfix lt= infix lt=) csel(infix lt= infix lt) csel(infix lt= infix =)
Finding solutions
sol(X v Y) -
(( notetra(X) eon(X) ( sol(Y) )
( c1ause(P v Q R) not(cketra(P v Q))
dis(P v Q X v Y R) ~ )
( A lt=gt B equival(A lt=gt B X v Y) ~ I) sol(X) - ~ notetra(X) eon(X)
so~(X) - notetra(X)
( con (X)
( clause(P v Q R) not(ekctra(P v Q)) dis(P v Q X R) I)
cketra(P v Q) -
eketra(P) eketra(Q) eketra(F(I J)) shy
selec(F(I J))
c1ause(contradiction(sel(F(IJ))) _I
eketra(number(W I)) -
clause(cootradietion(num(Wl)) - eketr(P) shy
clause(contradiction(P) - 1
notctra(P) shy
not( e lause( con tradiction(P) _))
40
Searching (or disjunctions
dis(P v Q X v Y R) - dis(P X v Y R)
dis(Q X v Y R) con(R)
dis(P v Q X R) -
dis(P X R) dis(Q X R) con(R
dis(P X v Y R) - clause(contradicton(Pl J 1
dis(F(I J) sel(G(I J)) v Y R) - csel(G Fl dis(number(WI) num(W N v Y R) - cnum(N I)
dis(P P v Y R) -
dis(P X v Y R) - dis(P Y R)
dis(F(I J) seJ(G(IJ)) R) - csel(G F)
dis(number(WI) num(WN) R) - cnum(N I) dis(P P R) - 1
dis(FJ J X R) shy
( ckctra(F(IJ) cbeckeq(seJ(F(IJ))) )
dis(number(W Il X R) - ( ckctra(number(WI)) cbeckeq(num(WI)) )
dis(P X R) shy( ckctra(P) cbeckeq(P) ) 1
cbeckeq(P) shy
(( A lt=gt so2(contradiction(P))
bagof(A A [jj) ) ( so2(contradiction(P)) lt=gt B
bagof(B B Uj) ))
ckeq(A) shy
( so2(A) lt=gt B B lt=gt so2(A) ) bagof(B B UJ)
con((P Q)) -
clause(P R) con(R) con(Q) con(true) -
con(contradiction(P)) - clause(contradiction(P) J
con(cause(X Y)) - cause(X Y)
con(sel(X)) - sel(X)
con(num(X Y)) - num(X Y) con(P)- (( dause(P R) (con(R) ckeq(R)))
colJectin(P) )
collectin(P) shy
bagof(S (c1ause(P S) S = true) [L LIJ )
mkcon(L Ll L)
bagor(l (L2 ) UJ) L
mkcon((A AI) (B B1) (sol(A v B) e D)) -
mkcon(A B1 e) mkcon(A1 (B Bl) D)
mkcon(A (B B1) (sol(A v B) e)) -
mkcon(A Bl e)
mkcon((A AI) B (sol(A v B) e)) middot1
mkcon(Al B e)
mkcon(A B sol(A vB))
Searching ror equivalences
equival(A lt=gt B X v Y) - 1 ( equival(A lt=gt B X) equival(A lt=gt B Y) )
equival(s02(A) lt=gt 502(B) A) - clause(B _I equival(s02(B) lt=gt 502(A) A) c1ause(B _I
Top level or inrerence mechanism
goo((s02(whatnum) P)) -
getatm(P Xl
bagor(number(X Y) ( P so2(number(X Y)) ) A )
count1(A 00 L R) nl
bagor(X P B )
count2(B L R Ll Rl) nJ print()
(( LI = 0 Rl = 0 print(THE ANSWER IS ) nl
(( Ll = Rl prin(-Jumber or ) prn(P) print(is Ll) )
( Rlgt20000 prin(Number or I prn(P) print(is LI or more) )
42
( prin(Number of ) pfn(P) print( is from Ll to Rl) )) )
( print(THE ANSWER IS NO I )) print()
goo(X) shy
(( bagof(X X L) L = [I nl print()
print(THE ANSWER IS YES) nl wout(L) print() )
( equiv(X L) nl print()
print(THE ANSWER IS YES) nl wout(L) print(-) )
( c1ause(inpt(A ==gt B) _I ( impli(A B Z) impli(B A Z) ) print(l~Hl)
printTHE ANSWER IS YES) nl print(Z) print(Hj~(fH~) ))
goo(X) print( Hg)
print(THE ANSWER IS NO ) print( lH~lH~gg9l9lmiddotmiddot~Q(gmiddot)
00 Semhing for implications in equiV3lent relations
impli( B Z) shyt-ell( z1) prin(templ() pchn(S A lt=gt B) print()) close ( zl) consult(zl) templ(Z)
unload zl Z
Searching for equivalence
equiv (X L)
(( X lt=gt Y
equ(Y YI)t bagof(Y Yl L) L = [j )
(Y lt=gt X equ(Y YI) bagof(Y Yl L) L = [J )
( X = F(New)
clause(~ew T) makeup(T Tl)
(( Tl lt=gt B
equ(B Bl) bagof(Bl Bl M) M = [j L=[Newl )
(A lt=gt TI
equ(A AI) bagof(Al AI M) M = 1] L=INewj )) ))
makeup((A B) (AI Bl)) -
makeup(A A1) makeup(B BI)
makeup(A so2(A))
equ((A B) (AI BI)) -
equ(A AI) equ(B Bl)
equ(sol(X v Y) sol(XI v Yl)) -
equ(X XI) equ(Y YI)
equ(so2(X) so2(XI)) -
equ(X XI)
equ(contradiction(X) clJuse(contradiction(X) X) ) -
equ(X X)
Counting numbers
getatm((A B) X) -
( getatm(A X) getatm(B X) )
getatm(so2(F(X)) X) -
getatm(so2(X) X) - atom(X)
countl([J L R L R) -
countl([number(X Y)IT] L R L2 R2) shy
(( Y = (gt=~) LI is L + N Rl is R + 20001 l )
( Y = (gt N) LI is L+ N+ 1 RI is R + 20002 )
(Y == laquo=~) LI is L + 1 Rl is R + N )
(Y = laquo N) LI is L + 1 RI is R+N-I)
(Y == IJ LI is L + I Rl is R + J ) ( Y == N L1 is L + N RI is R + N ))
count1(T LI R 1 L2 R2)
count2(fJ L R L R) - 1
count2([XITJ L R L2 R2) shy
name(X Xl)
(( Xl = sknj LI is L Rl is R )
44
( Xl = Iskmj L1 is L + 1 RI is R + ZOOO1) ( LI is L + I RI is R + I ))
count2(T LI RI L2 R2)
pfn((A B)) - pfn(A) prn(B)
pCn(so2(F(X))) - prin(F )
prn(so2(X)) - atom(X) prin(X ) prn (so2(X))
Printing result
wout([XlJ - prt(X) nl woutf[xIY]) - prt(X) nl nl wout(Y)
prt(e(A B)) -
prt(A) prinr 8 ) prt(ltE) prt(eA) - prt(A)
prt(c(A EJ) - prin() prt(A) prine ) prt(B) prin(T)
prt(c A) - prt(A) prt((A E)) - ~
prt(A) nl prt(E) prt(sol(X v Y)) - ~
prt(X) prinC v) prt(Y) prt(A lt=gt B) -
prt(e A) prinC lt=gt ) prt(e B) prt(sol(X)) - prt(X)
prt(so2(X)) - prt(X
prt(c1ause(X Y)) - prt(X)
prt(contradiction(X)) - prin(contradiction() prt(cX) prinr))middot prt(num(XY)) - prin(number(X Y)) prt(sel(X)) - prin(X) prt(X v Y) - prt(X) prin( v) prt(Y) prt(X) prin(X)
Handling conditional queries
condi((Y Xl) shy
assertcon(X) Y
45
retractcon(X)
condi((B A))
retractcon(A) fail
assertcon((A B)) 1
assertcon(A) assertcon(B)
assertcon(A) asserta(A)
retrac teon ((A B)) 1
retracteon(A) retractcon (B)
retraetcon(A) - retract(A)
BIBLIOGRAPHIC DATA SHEET
Report No UIUCDS-F-84-928
3 Recipients Accession No
4 T ide and Subt ltle
An Annotated Predicate Calculus Inference System (APCIS)
S Report Date
November 1984 6
7 Author(s)
Kah-Eng Pua 8 Performing Organization Rept
No
9 Performing Organization Name and Address
Department of Computer Science University of Illinois Urbana IL
10 ProjectTaskWork Unit No
11 Contract Grant No NSF DCR 84-06081 ONR N00014-82-K-0186
12 Sponsoring Organization Name and Address
National Science Foundation Washington DC
13 Type of Report amp Period Covered
14
15 Supplementary Notes
16 Abstracts
This paper describes a deductive inference system called APCIS (Annotated Predicate Calculus Inference System) APCIS is able to carry out inferences from expressions involving numerical quantifiers selectors disjunctions of non-negated terms negated terms disjunctions of negated terms equivalences and exceptions It is also able to count the numbers of occurrence of a given simple term or a conjunction of terms The design of contradiction and the treatment of the disjunction of non-negated terms allow APCIS to accept Horn clauses as well as non-Horn clauses and to carry out inferences from them This feature makes APCIS more general than Prolog
17 Key lords and Document Analysis 170 Descriptors
APC (Annotated Predicate Calculus) APCIS (Annotated Predicate Calculus Inference System) Horn Clause Numerical Quantifier Prolog Selector
17b IdentifiersOpen-Ended Terms
17c COSATI FieldGroup
18 Availability Statement 19 Security Class (This
Re~f~~IA~SIF IFf)
21 ~o of Pages
49 211 ecurity Class (This
PageUNCLASSIFIED
22 Price
FOA NTIS n (10middot70 usco-oc 40329-
3
1-------------1 1 ta (X) I 1-------------1
1 1-------------1
APe 1 I Translator 1
1-------------1 I
1-------------11 Terminal I 1-------------1
(a) Assertion-translation mode
1------------ a(X) I
1------------1 1
1 1------------1 I APe I 1 Translator 1
1------------1
i-----------I 1----------1 I temp_file 1 1 Terminal 1 1-----------1 I----------i
1
1 1-------------1 I Prolog 1 1 system 1 1------------ -I
(c) Assertion mode
Figure 1 Four modes of APCIS
1---------------1 1 tq(X) 1 1---------------1
1 1---------------1 1 A P C 1 I Translator 1
1---------------1 I
1---------------1 I Terminal 1 1---------------1
(b) Query-translation mode
1--------------1 q(X) I 1--------------1
1 1------------------1 1 asserta(inpt(Xraquo 1 1------------------1
1 1---------------1 1 A P C 1 1 Translator 1 1---------------1
I 1---------------1 i temt__file 1 1---------------1 1---------------1 1 Prolog 1 1 system 1 1---------------1
I 1---------------1 1 Terminal 1 1---------------1
I 1-------------------1 1 retract(inpt(Xraquo I I-----------------~-I
Cd) Q-uery mode
23 Assertion Mode
Figure l(c) is a schematic diagram showing how assertion mode works In this mode the
input assertion will first go through the APC translator as in assertionmiddot translation mode After
which the translated result will be printed both on the terminal and to a temporary file called
tempfile which will subsequently be loaded back to Prolog system As a result the newly
translated input assertion will become Prolog term(s or clause(s) in the database
24 Query Mode
Figure l(d) shows schematically the stages that will go through when query mode is
invoked The input query crowned by the (unctor inpt will first be stored in the database It will
then be passed to the APC translator as in query-translation mode The output of the translator
will be printed on the temporary file tempfile which will subsequently be loaded to Prolog
system Upon loading tempfiie to Prolog system (recall that tempJile contains essentially a
Prolog question) the question is executed immediately and its result will be prin ted out on the
terminal In the last stage the original input query crowned by the functor inpt will be
retracted from the database
3 APe Translator
As described in [3] there are ten steps in the APC translator and each step undertakes a
unique transformation Assertion-translation mode and assertion mode go through these steps
which have been covered in [3] and will not be discussed here
31 Translation of Queries
We will now examine the different transrormations that query-translation mode and
query mode will go through They differ Crom assertion-translation mode and assertion mode only
5
in the last step of translation
In the last step of the APe translator all input queries (ie expressions entered via
query-translation mode or query mode) are dealt with by the following six predicates prques pi
plett peont pehar and pout The task of prques pi plett and peont is to arrange each
input query in desired order whereas pehar and pout will print out each atomic formula
character by character For illustration purposes consider the following five APe expressions
1 all( X man(X) ==gt mortal(X)
2 exists( X horse(X) v dog(X) )
3 - ( exists( X horse(X) amp dog(X))
4 all( X be_shouted_at(X) amp no_response(X) == gt deaf(X) v dead(X) )
5 exists( 2 X box(X) )
H the above five APe expressions are typed to Prolog via assertion mode or assertionshy
translation mode they will be translated to the corresponding Prolog expressions
la
mortal(XI) shy
man(Xl)
2a
horse(skml) v dog(skml)
3a
contradiction(( horse(XI) dog(Xl) )) shy
horse(Xl)
dog(XI)
4a
deaf(Xl) v dead(Xl) shy
be_shouted_at(X I)
no_response(X1)
Sa
box(sknl)
number(sknl2)
The above live translated expressions ( ie la through Sa ) will be printed on the
terminal and loaded to Prolog if assertion mode is used they will be printed on the terminal but
not loaded to Prolog if assertion-translation mode is invoked
Now if the original APC expressions ( ie 1 through 5 ) are typed to Prolog via query
mode or query-translation mode the corresponding questions will be translated into the following
queries
lb
goo(( condi(( mortal(Xl) man(Xl))) ))
b
goo(( soil horse(Xl) v dog(XI)) ))
3b
goo(( c1ause( contradiction(( horse(XI) dog(Xl) )) _) ))
4b
goo(( conditt deaf(Xl) v dead(Xl) (be_shouted_at(XI) no_response(Xl)) )) ))
5b
amp00(( so2( box(XI) ) s02( num(XI 2 )) ))
The above five translated queries ( ie Ib through 5b ) will be printed on the terminal
and loaded to Prolog if query mode is used they will be printed on the terminal but not loaded to
Prolog if query-translation mode is invoked
In the above queries goo 801 and 802 each forms a part of the inference mechanism of
APCIS goo occupies the top level of the inference mechanism whereas 801 and 802 are at the
1
next level 102 will take care of the searching of simple terms and 101 will deal with the
disjunctions of non-negated terms in the database We will come back to them in Section 4
At the first glance one may feel that the above translated Queries are Quite complicated
However a closer examination will reveal that they are not so Queries lb 3b and 4b can each be
categorized as a conditional query which is a distinct feature of APCIS wherels queries 2b and
5b lre asking simple facts in the database
To handle conditional queries we consider two cases First if the queries involve a
special clause contradition we invoke the built-in function el3ule(X Y) which will look for the
desired contradiction clause in the database Second if the queries do not involve the clause
contradiction we activate a defined Prolog predicate condi to take care of the necessary
searching (To avoid confusion the reader is urged to compare expressions started with the same
number in the above three sets of example)
To handle a query which asks a simple fact we surround each disjunction of terms with
the functor sol as in the example 2b or crown each simple term with the functor 802 as in the
example 5b
32 TranslatIon of Negated Term And Disjunction of Negated Terms
One feature of APCIS is its ability to handle input expressions consisting of only negated
term or a disjunction of negated terms in the forms
or
2 -(AI) v ~(A2) v v ~(An)
To handle the above two forms a special clause with clause head contradiction is
created This special clause head has only one argument which is either a term or a set of terms
grouped together in the form
8
(AI A2 An)
The right-hand side of the clause contradiction is exactly same as the argument in the clause
head For example the above two forms involving negated terms will be translated into the
corresponding forms as follows
1 contradiction( A ) shy
A
2 contradiction(( AI A2 An )) shy
AI A2 An
The design of the clause with clause head contradiction will greatly enhance the inference power
of APCIS (see the example in Section 44)
33 Translation ot Disjunction ot Non-negated Terms
Another feature of APCIS is its ability to handle input expressions involving a
disjunction of non-negated terms in the forms
1 Al v A2 v v An
or
2 Bl amp 32 amp amp Bm ==gt Al v A2 v v An
Unlike Prolog which accepts only Horn clauses APCJS will accept Horn clauses as well
as non-Horn clauses which take the above two forms The inference from non-Horn clauses is
made possible by the two defined predicates sol lnd s02 discussed in Section 42 and Section 43
respectively (see also the example in Section 44) In the APC translator the above two forms are
transbted into the corresponding forms as follows
1 Al v A2 v v An
2 Al v A2 v v An shy
g
Bl B2 Bm
34 Futher Transformation of Exceptions and Equivalences
To provide some backgrounds for the discussion of the further transformation of
exception and equivalence relations we will lirst reproduce the three goals in the Step 2 of the
APe translator discussed in Section 32 of [31
First expressions involving implication or the form A ==gt B will be transformed to
Second expressions with exception symbol or the form A - B will be changed to the
form ( A lt=gt -(B) ) amp ( -(A) lt=gt B)
Tbird expressions with equivalence symbol of the form -(A) lt=gt B or of the form
A lt=gt -(B) will also be converted to ( A lt=gt -(B) ) amp ( -(A) lt=gt B ) since tbere are
logically identical to exception relations Also expressions with equivalence symbol of the form
A lt=gt B or -(A) lt=gt -(B) will remain the same
After the Step] of the APe translator both sides of any transformed expression with
lt = gt symbol will be treated separately as if they are two independent expressions In the
Step 10 of the APe translator each side of lt=gt will again be treated separately and
transformed into a form similar to an transformed input query (see Section 31) Two examples
are given below
1 state(on) lt=gt -( state(olJ) )
2 all( 1 bot(l) amp humid(l) - winter(I) )
They will be transformed in the Step 2 or the APe translator into
1
(state(on) lt=gt -( state(off) ) ) amp ( -( state(on) ) lt=gt state(olJ) )
2
10
( hot(l) amp humid(l lt=gt -(winter(l)) ) amp
( -( hot(l) amp humid(l)) lt=gt winter(I)
In Step la they will again be transformed to
1
so2( state(on) ) lt=gt so2( contradiction( state(oH) ) )
so2( contradiction( state(on) ) ) lt=gt so2( state(oH) )
2
( s02(hot(XI)) so2(humid(XI))) lt=gt so2( contradiction( winter(Xl ))
so2( contradiction(( bot(Xl) humid(Xl) )) ) lt= gt so2( winter(XI) )
There are two advantages in the treatment of exception and equivalence symbols in this
way First it will prevent Prolog program from going into an infinite loop which is difficult to
avoid if equivalent relation such as A lt=gt B is transformed into the logically equivalent form
( A ==gt B) amp ( B ==gt A) Second by maintaining both sides of lt=gt symbol in
query form the searching on either side caD be done more easily and efficiently since the form
is already processed and does not need any further transformation
Inference Mechanism
As mentioned at the end of Section 31 goo sol and s02 each forms a part of the
inference mechanism of APCIS with goo occupying the top level and 80) and 802 the second
level In addition to these countl count2 equlv and impll are also at the second level of the
inference mechanism We will go over all of them in the following sections
I goo
goo is essentially the starting point of the inference Whenever a translated query is
loaded to Prolog system from temp-fie goo will go through one or more of the following steps in
11
sequence
G 1 Check if the query asks for the numbers of occurrence of certain term(s) It so then
pass It to eountl and eount2 else go to G2
G2 The query will be passed down to sol or s02 (or both) to check i( any assertion in the
database can satisfy the query It the answer is positive then the query succeeds else
go to G3
G3 The query will be passed to equlv to carry out further searching It the searching is a
success then the query will be closed with a success else go to G4
G4 It the query is in the form A ==gt B then it will be passed to Impli It Impll
succeeds then done else the query will be closed with a (ailure
42 sol
801 and 802 together with dis and eon form the most complicated part of the APCIS
iorerence mechanism In this and the next section we will look at sol and s02 dis and eon will
be discussed in Section 44 We will close Section 44 with an example that illustrates the
materials presented in Section 42 through Section 44
sol is at the second level of the inference mechanism It will deal with any disjunction of
non-negated terms For any disjunction passed to it it will go through one or more of the
following steps in sequence
S1 Check if any term In the disjunction can be satisfied by any term or clause in the
database without contradiction It so then done else go to S2
S2 Pass the disjunction together with another disjunction (and its tlil) picked up from
the database to dis It dis succeeds then done else go to S3
S3 Pass the disjunction down to equlval which will check if any term in the disjunction
matches either side of any equivalence relation in the database It such a match is
found then check if the other side of the equivalence C3n be satisfied It so then done
else the goal fails
43 s02
s02 is also at the second level of the inference mechanism It will take care of all the
simple terms in the transl1ted query The following is the sequence that s02 wiII follow in
searching
S1 Check if the term passed to it caD be s3tisfied by any term or clause in the d3tabase
without contradiction It so then done else go to S2
S2 Pass the term together with a disjunction of terms (and its tail) picked up from the
database to dis If dis succeeds then done else the goal fails
44 dis and con
dis has three arguments In the first two clauses of dIs the first argument P v Q is
found in the database using the builtmiddotin functiol clause and the third argument R is the tair of
the term or the clause P v Q If P v Q is not a clause but a term R will be instantiated to trUE
The second 3rgument comes from either lIol or 802 and thus takes the form of either X v Y (a
disjunction of terms) or T (3 simple term)
All the clauses of dis together with con will perform the searching as exemplified in the
following algorithm (we will keep the notationsin this section)
01 Check if every term in P v Q is in X v Y It so then go to 03 else go to D2
02 For any term (in P v Q) which is not in X v Y or does not match T perform the
following tests
a Check if the term (in P v Q) has already been negated in the datab3Se (ie check if
the contradiction of the term exists in the d3tabase) If so then repeat D2 for other
terms not found in X v Y or not matching T else go to b
13
b Check if the contradiction of the term matches either side of any equivalence
relation in the database If such a match is found then check if the other side of the
equivalence can be satisfied If so then repeat O~ for other terms not found in X v Y
or not matching T else the goal fails
It all the terms (in P v Q) which are not in X v Y or do not match T survive either one
of the above two tests then go to 03
03 This step is essentially done by eon whose goal is to satisfy the tail R of P v Q It
con succeeds then done else the search fails
To close this section we will give an example to illustrate what we have covered In
Section 42 through Section 44
Example Assume that we already haye the following expressions in the database
horse(skml) v dog(skmI)
contradiction(( dog(XI) ))shy
dog(XI)
query goo(( soZ horse(X)) ))
This query will be passed to 802 which will check it the term horse() can be satisfied iu Step S 1
of Section 43 It is a failure So we now go to Step S2 In this step we pick up the disjunction
horse(~kml) v dog(skml) (and its tail true) in the datab3Se and pass it together with the term
horse(X) to dis We are now in Step 01 of Section 44 In this step we find that dog(skml) does
not match horse(X) So we have to go to Step 02 In Step 023 We find that the term dog(skml)
has already been negated (the second expression in the database) So we go to next step 03 Since
the tail of the disjuDction horse(skml) v dog(skml) is the atom true con is satisfied and the
query succeeds
45 countl and count2
countl and count2 are responsible for the counting of tbe numbers of occurrence of a
given simple term or a conjunction of terms They are activated by input queries in the form
q( exists( X whatnum amp P) )
where whatnum is the l~bel for activating the counting of the numbers of occurrence of P which
can either be a term or a conjunction of terms
countl will count the number of term(s) which will satisfy P and associate(s) with
numerical quantification(s Two counters are set to update the lower and upper boundary or the
scope or the numfrical quantifications encountered
The contents of the two counters are then passed to count2 which is responsible for the
counting or the following three types of term First term(s) which will satisfy P and associate(s)
with existential quantification(s Second term(s) which will satisfy P and has(have) Prolog atom
as its(thfir) argument(s) Third term(s) that will satisfy P and itself(themselves) is(are) Prolog
atom(s )
46 equiv
equlv will be activated only after sol and B02 have failed The first two goals of equlv
are similar to that of Step S3 in Section 42 and Step D2b in Section 44 The third goal or equiv
makes possible the inference on either side of any equivalent relation For example if we type the
following three expressions to Prolog in assertion mode
l all( X hot(X) amp humidX) - winter(X)
2 all( X hot(X) amp bumid(X) ==gt unpresent(X))
3 - ( exists( X winter(X) ) )
and then ask APCIS in query mode
q( cxists( X unpresent(X) ) )
15
APCIS with the aid of equlv will be able to answer yes to this query
41 lmpll
lmpll can be considered as the last attempt that APCIS would make to satisfy a
query It is activated only after equlv has failed It will first check if the query is conditional If
so it will convert the implication symbol to equivalence symbol and search if such an equivalent
relation can be found in the database If so a success Otherwise a failure
5 More on the Inference Mechanism
Having looked at all the subparts at the top two levels of the inference mechanism we
are ready to look at other subparts at lower levels
51 num and cnum
One distinct fe3ture or APCIS is its ability to deal with numerical quantifications As
mentioned in Section 31 input queries and assertions will undergo different transformations in
the last step (Step 10) of translation This also holds true for expressions involving numerical
quantifications Consider the following expression
exists( 6 X horse(X) )
If it is entered to Prolog via assertion mode we will after going through all the steps of
translation have the rollowing entered to the database
horse(sk n I
number(sknl6)
Now if we want to ask Are there more than five horses 7 and type in
q( exists( gt5 X horse(X) ) )
1amp
APCIS will translate the question and enter to Prolog the following query
goo(( s02( horse(X) ) s02( num( X gt5 )) ))
Note that the term number(slml 6) in the database and the term num(X gt S) in the query are
different predicates and this difference is exactly where the power of the clause num(X N)
defined in APCIS comes from When the clause num(X N) in APCIS is activated it will search
through the database to see if there is any term of the form number(X I) whose first argument
matches the first argument of num(X Y) in the query It a match is found the second arguments
of both num(X Y) in the query and number(ltI) in the database will be passed to cnum in
APCIS
The job of cnum is to compare the numerical messages carried by the second
argument or the term rlum(X Y) in the query and the second argument of the term rlumber(X I)
in the database to see if they match with each other according to the rules defined in cnum
While there are 25 rules for such matching purposes the idea is simple
Imagine that the second argument Y of the term num(X Y) in the query
and the second argument I of the term num()( I) in the database each occupies a
place in an integer line (Le the integer line in mathematics) To have a match
the domain covered by Y should contain the domain covered by L
As an example the answer to the above query is positive since the domain of gt5
contains the domain or 6
Before closing this section we will bring out a speciaJ translation aspect of expressions
involving numbers by an example We first type to APCIS the Collowing expressions in assertion
mode
1 aU(X all(Y father(X Y) amp number(Y gt6) ==gt has_manY3hildren(X) ))
2 exists(X exists( 12 Y Cather(X Y) ) )
11
After going tbrougb all tbe translation steps tbe Collowing two expressions will be entered to tbe
database
I
bas_many_cbildren( Xl ) shy
Cather( Xl X2 )
num( X2 gt6 )
2
Catber( sk m1 sk n2 )
number( skn2 12 )
lotice that whenev(gtr a term with Cunctor number appears at the rigbt-band side oC a Prolog
clause its Cunctor will be cbanged to num automatically This treatment will greatly cnbance tbe
inference power of the clause sbown in l above For instance iC we now ask tbe question
q( exists( X bas_many_children(X) ) )
The right hand side oC the clause l will match the two terms in 2 and tbe query succeeds
52 Bel and cael
A special feature of APe is tbat all predicates tbat express relations = = gt
gt= lt and lt= can be expressed explicitly using infix notations as relational statements
called selectors To handle selectors we defined Bel in APCIS
Every expression involving selectors will undergo different translations in assertion mode
and query mode For example the assertion
a( exists( [X Y] box (X) amp box(Y) amp (weigh t(X) gt weight(Y) ) ) )
will be translated into the following three terms and entered to tbe database
box( skml )
box( skm2 )
18
weight( skm 1 ) gt weight( skm2 )
Now it we want to ask Is it true that there exists two boxes of different weights and type in
q( exists( [X Yl box(X) amp box(Y) amp ( weight(X) = weight(Y) ) ) )
The question will be transformed to the following query and entered to Prolog
goo(( so( box(XI) ) s02( box(X2) ) so2( sel( weightXI) = weight(X2) )) ))
Note that the selector in the above query is surrounded by the functor set When any clause or
8el in APCIS is activated it will search through the database to see it there is any selector whose
two arguments (left and right side or any selector symbol) match the two arguments of the
selector in the query At the same time 8el will check iC the selector symbols (may be different) or
the two different selectors (one in the query and one in the database) satisfy the rules defined in
sel There are 12 matching rules defined in sel All oC them ~re straightforward and will not be
discussed here An example will be enough to explain how 8el works
Consider the execution of the above transformed query The first two terms in the query
are satisfied by the first two terms in the database and Xl and X2 are instantiated to skml and
skm2 respectively The third term of the query will be passed to eel (of APCIS) which finds a
match on each side of the two selectors (one in the query and one in the database) At the same
time the two different selector symbols gt and = are found to satisfy one of the rules in
8el As a result the query succeeds
To enhance the inference power of clauses involving selectors all the selectors appearing
on the rightmiddothand side oC any clause will be surrounded by a functor set The idea is similar to
that in the last part of the previous section
c8el is exactly the same as 8el functionally It provides a convenient way to compare
selectors when dis is being executed
19
8 Printing Result
Whenever a goal is successfully executed APCIS will not only response with a yes but
also print out the matched terms or clauses in the database This is made possible by the built-in
function bagor and the two predicates wout and prt defined in APCIS
7 Summary
In this paper a description of a deductive inference system called APCIS (Annotated
Predicate Calculus Inference System) has been provided APCIS is able to carry out inferences
from expressions involving numerical quantifiers selectors disjunctions of non-negated terms
negated terms disjunctions of negated terms equivalences and exceptions It is also able to count
the numbers of occurrence of a given simple term or a conjunction of terms
The main idea of APCIS is that each input APC expression is first passed to a
preprocessor ( ie APC translator ) which dissolves and transforms each APC expression into
Prolog expression(s) which will then be loaded to Prolog system The user bas to specify whether
each input expression is to be entered as an assertion or as a query by invoking either assertion
mode or query mode respectively Each assertion or query will undergo different transformations in
the preprocessor The different treatment of assertion or query not only allows a full uS1ge of the
Prolog inference mechanism but also makes possible a higher level of inexact pattern matching
exemplified by the examples in Section 51 and Section 52 where the four predicates num
cnum sel and csel are discussed This higher level of pattern matching increases the inference
power of APCIS greatly
The design of contradiction and the treatment of the disjunction of non-negated terms
allow APCIS to accept non-Horn clauses and to carry out inference from them This feature
makes APCIS more general than Prolog
20
While APCIS performs very well in many sets of arguments provided by the author it is
still too early to jump to conclusion that it can perform equally well in all types of problems In
any event the expressiveness of APC has greatly been retained in the present version of APCIS
and moreover some design ideas or APCIS mentioned in this paper are not restricted to APCIS
- they may be carried over to learning programs with narrower scopes
21
References
[1] W F Clocksin and C S Mellish Programming In Prolog Springermiddot Verlag Berlin Hpoundidelberg 1981
[2] R S Michalski A Theory and Methodology of Inductive Learning Chpt 4 Machine L earning Tioga Publishing Co Palo Alto CaliJornia 1989
[3] K-E Pua Translating Annotated Predicate Calculu8 to Prolog ISG Report 84middot1 UlUCDCSmiddotFmiddot918 University oj Illinois Urbana IL June 1984
22
Appendix A
APCIS Users Manual
1 Get Started
Users are urged to follow the steps depicted below
1 Get the PROLOG interpreter by typing
alias prolog mntb2sammutsammutprologprolog (Vax A)
or
alias prolog mntb2sammutsammutbinprolog (Vax B)
2 Load apc and infer by typing
prolog apc infer
When large APC expressions are expected we can increase the stlck by typingI
prolog -snnnn ape infer
where ns denote the number of stacks in decimal
3 When the wording LSW - PROLOG appears on the terminal we are reldy to interact
with APCIS The four modes by which we can invoke APCIS are summarized below
a Assert ion-Translation Mode
ta(X)
b Query-Translation Mode
tq(X)
c Assertion Mode
a(X
d Query Mode
q(X)
23
where Xs are APC expressions
2 Notations Used in APCIS
Below is a summary or notations used in APCIS
a Logical operators
amp
v
==gt
lt=gt
-
negation
conjunction
disjunction
implication
equivalence
exception
b Binary relation symbols in selectors
-
=
gt=
lt=
gt
lt
equal
not equal
greater or equal
smaller or equ al
greater
smaller
c Relational operators in numerical quantifiers
lt less than
lt= less than or equal
gt greater than
gt= greater than or equal
d BinlTY operator in numerical quantifier
range
e Universal quantifier
all(X p(X))
f Existential quantifier
exists(X p(X))
g Numerical quantifier
exists(I X p(X))
where p(X) is a formula
where X is a variable or a Jist of variables or the
form [HI~rj and p(X) a formula
where I repersents expression involving integer(s)
and operator(s) in c or d above and p(X) a formula
25
Appendix B
APCIS Program Listings
------------------------------- Program Name APCIS - Part 1 APC Translator
-------------------------------
op(3OO fx -)1
op(500 xfy amp)
oPt 500 xfy v)
op(600 xfx )
op(700 fx [gt= lt= gt lt ]) op(400 xfy [= gt= lt= gt lt ])1 op(900 xfy gt lt=gt -])1
steps(X Xg) shy
numbervars(X 1 J Step 1 change variables to iis
rmimp(X X) Step 2 conv(X X3) Step 3
rewrite(X3 X4) Step 4
negin(X4 X5) Step 5
dropexist(X5 X6 1]) Step 6
dropall(X6 X7) Step 7
distrib(X7 X8) Step 8 clausiCy(X8 X9 [J) Step 9
ta(X) shysteps(X Xg)
(( Xg = II nl
print( yes it is always true) )
( nl nl printcl(X9))) Step 10a
tq(X) shy
steps(X Xg)
prques(Xg)
28
Step 2 Removing implic3tions amp Transforming exceptions and equiv3lences
rmimpl( P - Q (PI lt=gt (QI) ) amp ((PI) lt=gt QI) ) -
rmimpl(P PI) rmimpl(Q QI)
rmimplnp) lt=gt Q (PI lt=gt -(QI)) amp nPI) lt=gt QI) ) - 1
rmimpl(P PI) rmimpJ(Q QI)
rmimpJ(P lt-gt -(Q) (PI lt=gt -(QI)) amp nPI) lt=gt QI) ) -
rmimpl(P PI) rmimpl(Q QI)
rmimpl( P lt=gt Q PI lt=gt QI ) - I
rmimpl(P PI) rmimpl(Q QI)
rmimpl( P ==gt Q -(PI) v QI ) - I
rmimpl(P PI) rmimpl(Q QI)
rmimpl( all(X P) aI(X PI) ) - 1
rmimpl(P PI)
rmimpl( exists(X P) exists(X PI) ) -
rmimpl(P PI)
rmimpl( exists(I X P) exists(I X PI) ) -
rmimpl(P PI)
rmimpl( P amp Q PI amp Ql ) -
rmimpl(P PI) rmimpl(Q Ql)
rmimpl( P v Q PI v QI ) -
rmimpl(P PI) rmimpl(Q QI)
rmimpl( -(p) -(PI) ) - I
rmimpl(p PI)
rmimpl( P P )
St~p 3 Converting numerical amp distinctive quantifiers
L Numerical quantifiers
examples of input forms
1 exists(gt= i X pIX)) where i is an integer
2 exists(i X pIX)) where i is an integer
3 exists(i j X pIX)) where i j are integers and iltj
4 exists(il v i2 X pIX)) where is are integers
examples of output forms of this step
1 exists(X pIX) amp number(X gt= i) )
2 exists(X pIX) amp number(X i) ) 3 exists(X pIX) amp number(X ij) ) 4 exists(X pIX) amp number(X il v i2) )
II Distinctive quantifiers
27
example or input Corm
exists([XYL p(X Y))
example or output Corm or this step
exists(X exists(Y p(XY)) )
conv(P lt=gt Q PI lt=gt QI) - 1
conv(P PI) conv(Q QI)
conv(al1(X P) all(X PI)) -
conv(P PI)
conv(exists(HIT] P) R ) - conv(P PI) convert distinctive quantifier
convtdis(exists([HIT]PI) R)
conv( exists(I X P) exists(X PIamp number(X I) )) -
conv(P PI) convert numerical quantifier
conv(exists(X P) exists(X PI)) - 1
conv(P Pl)
conv(P amp Q PI amp QI) - 1
conv(P PI) conv(Q QI)
conv(P v Q PI v QI) - t conv(P PI) conv(Q QI)
convC(P) -(PI)) -
conv(P PI)
conv(P Pl
convtdis(existsl[XL P) exists(X P)) - atomic(X) convtdis(exists[XIYj Pl exists(X R)) shy
convtdis(exists(Y P) R)
Step 4 Rewriting compound predicates andor compound selectors
Outputs are smiple predicates andor simple selectors
rewrite(P lt=gt Q PI lt=gt QI) - t rewrite(P PI) rewrite(Q QI)
rewrite(all(X Pl all(X PI)) - 1 rewrite(P PI)
rewriteexists(X P) exists(X PI)) - I rewriteP PI)
rewrite(P amp Q PI amp QI) - rewrite(P P 1) rewrite( Q Q 1
rewrite(P v Q PI v QI) - 1
rewrite(P PI) rewrite(Q QI)
rewriteC(P) -(PI)) - I
28
rewrite(P PI) rewrite(F(A B) R) -
rewrite(A AI) rewrite(B BI) re(F(AI BI) R)
rewrite(F(A) R) -
rewrite(A AI) re(F(AI) H)
rewrite(F(A B C) R) -
rewrite(A AI) rewrite(B BI) rewrite(C CI) re(F(AI BI CI) R)
rewrite(F(A B C D) R) -
rewrite(A AI) rewrite(B Btl rewrite(C CI) rewrite(D DI) rc(F(AI BI CI Dl) H)
rewrite(PP)
re(F(A B v el (RI v R2) -
re(F(A Bl RIl re(F(A C) R2) reF(A B amp cl (RI amp R2)) -
re(F(A B) RI) re(F(A e) R2) re(F(A amp B C) (Rl amp R2)) -
re(F(A e) R 1) re(F(B C) R 2) re(F( v B el (R I v R2)) -
re(F(A el R I) reFB el R2) re(F(A amp Bl (R I amp R2)) -
re(F(A RI) re(F(BJH2) re(F(A v B) (R 1 v R2)) -
re(F(A) RI) re(F(B) R2)
re(F(A vB c Dl (RI v R2) -
re(F(A C D) RI) re(F(B C D) R2) re(F(A amp B C D) (RI amp R2)) -
re(F(A C D) Rll re(F(B C D) R2) re(F(A B v C D) (HI v R2)) -
re(F(A B D) RI) re(F(A C D) R2) re(F(A B amp C D) (HI amp R2)) -
re(F(A B D) RI) re(F(A C D) R2) re(F(A B C v D) (RI v R2)) -
re(F(A B C) R I) reF(A B D) R2) re(F(A B C amp D) (RI amp R2)) -
29
re(F(A B C) RI) re(F(A B D) RZ)
re(F(A v B e D E) (R I v R2)) -
re(F(A e D E) R I) re(F(B e D El R2) re(F(A amp B e D E) (RI amp RZ)) -
re(F(A e D El R 1) re(F(B e D E) R2) re(F(A B v e D E) (R I v R2)) -
re(F(A B D E) RI) re(F(A e D E) R2)
re(F(A B amp e D E) (RI amp R2)) -
re(F(A B D El RI) re(F(A e D E) RZ) re(F(A B e v D E) (R I v R2)) -
re(F(A B e El R 1) re(F(A B D E) RZ) re(F(A B e amp D E) (RI amp RZ)) -
re(F(A B e E) R I) re(F(A B D E) RZ)
re(F(A B e D vEl (RI v RZ)) - l
rc(F(A B C D) RI) re(F(A n e El RZ) re(F(A B e D amp El (RI amp RZ)) - ~
re(F(A B e D) RI) re(F(A B e El RZ)
re((A = B) (A = B)l-
re((A = Bl (A = 8)) -
retIA gt= BI (A gt= B)) -
re((A lt= B) (A lt= B)) -
re((A gt B) (A gt B))-
re((A lt Bl (A lt Bl)- re(A A)
Step) Bringing n(gation inwards
Degin(-(P) PI) - neg(P Pl)
negin(P lt=gt Q PI lt=gt Ql) - ~
negin(P PI) negiD(Q QI)
Degin(aU(X P) all(X PI)) - Degin(P PI) negin(exists(X P) exists(X PI))- negin(P PI) negin(P amp Q PI amp Ql) - Degin(P PI) negin(Q Ql)
Degin(P v Q PI v QI) - Degin(P PI) negin(Q QI) negin(P Pl
neg(-(P) PI) - negin(P PI)
neg(all(X P) exists(X PI)) - neg(P PI)
30
neg(exists(X P) all(X PI)) - neg(P PI)
neg(P amp Q PI v QI) - neg(P PI) neg(Q Ql)
neg(P v Q PI amp QI) - neg(P PI) neg(Q QI)
neg(P -(PH
Step 6 Dropping existnetial quanti6ers
dropexist(P lt=gt Q PI lt=gt QI Elerns) - dropexist(P PI Elerns) dropexist(Q QI Elerns)
dropexist(alJ(X P) all(XPI) Elerns)
dropexist(P PI [XIElernsJ)
dropexist(exists(X P amp nurnber(X Yraquo P2 Elerns) -
genfun(skn Newg) Fun = [NewgIElerns]
subst(FuD X P amp Dumber(X Y) PI)
dropexist(Pl P2 Elerns)
dropexist(exists(X P) PZ Elerns) -
genfun(skrn Newf) Fun = [NewfIElernsJ
subst(Fun X p PI)
dropex ist(P 1 P~ Elerns)
dropexist(P v Q PI v QI Elerns) - ~
dropexist(P PI Elerns) dropexist(Q Ql Elerns)
dropexist(P amp Q PI amp QI Elerns) - 1
dropexist(P Pl Elerns) dropexist(Q QI Elerns)
dropexist(P P _)
gen fun(R oot Newn arne) shy
getnurn(Root Nurn)
narne(Root Rootlist)
append(Rootlist[Nurnj Narnelist)
concat(Narnelist Newnarne)
getnurn(Root Nurn) shy
retract(currentnurn(Root Nurn 1 raquo
Nurn is Nurni + 1
asserta(currentnurn(Root Nurn))
getnurn(Root 1) - asserta(currentnurn(Root 1))
subst(New Old Val Val) - var(Val)
subst(New Old Old New) - 1 substNew Old Val Val) - atornic(Val)
31
subst(New Old Val Newval) shy
runctor(Val F N)
CUDctor(Newval F N)
subst_args(N New Old Val Newval)
subst_args(O J J - J J
subst_args(N New Old Val NewVal) shy
arg(N Val OldArg)
arg(N NewVal NewArg)
subst(New Old OldArg NewArg)
NI is N - I
subst_args(Nl New Old Val NewVal)
append([J L L) -
append([XILl] L2 [XIL3]) - append(Ll L2 L3)
Step - Dropping universal quantifiers
dropall(P lt=gt Q PI lt=gt QI)-
dropall(P PI) dropall(Q QI)
dropall(all(X P) PI) - ~ dropall(P PI)
dropall(P amp Q PI amp QI) -
dropall(P PI) dropall(Q QI)
dropall(P v Q PI v QI) -
dropall(P PI) dropall(Q QI)
dropall(P P)
Step 8 Distributing conjunctions over disjunctions
distrib(P lt=gt Q PI lt=gt Ql) - t distrib(P PI) distrib(Q QI)
distrib(P v Q R) -
distrib(P PI) distrib(Q QI)
distributing(PI v QI R)
distrib(P it Q PI it QI) -
distrib(P PI) distrib( Q QI)
distrib(P P)
distributing((P amp Q) v R PI amp QI) -
distrib(P v R PI) distrib(Q v R Ql)
32
distributing(P v (Q amp R) PI amp Ql) -
distrib(P v Q PI) distrib(P v R Ql)
distributing(P P)
Step 9 Packing each conjunction into clauses
c1ausify(P amp Q CI C2) -
clausiCy(P CI C3) c1ausify(Q C3 C2)
cbusiCy(P [d(A B)ICs] Cs) shy
inclause(P A [j B [I) 1
c1ausiry( C C)
inclause(P v Q A AI B B1) -
inc1ause(P A2 AI B2 Bl)
inclause(Q A A2 B B2)
inclausenp) A A B1 B) -
notin(P A) putin(P B B1)
inclause(P AI A B B) shy
notin(P Bl putin(P A AI)
notin(X [XU) - fail
notin(X [JLj) - notin(X L)
notin(X 1])
putin(X II [X]) - 1
putin(X [XILJ L) -
putin(X [YILJ [YILl]) - putin(X L Ll)
Step 1Oa Printing clauses
printcl([]) - nl nl
printcl(c1(AB)ICsj) - printcl(A Bl nl printcl(Cs)
printcl(L II) - printdis(IL) prinr)middot
printclHl L) - prin(contradiction(() printconl(rL)
print()) - ) printconj(rL) prinr )
printcl(Ll L2) shy
printdis(ILl) print( - ) printconj(rL2) prin()
printdis(S[Lj) - printcbar(SL)
33
printdis(S[LILs]) - printchu(SL) prin( v) printdis(SLs)
printconl(S[LI) - printchar(SL)
printconl(S[LILs]) - printchar(SL) prin( ) printconl(SLs)
printconj(S[L]) - tab(3) printchar(SL)
prin tconj( S [L IL sl) shy
tab(3) printchar(SL) print( ) printconj(SLs)
printchar(SP) shy
atomic(P)
name(P L)
L = [IT]
concat([XIT NewP)
prin(~ewP)
printchar(SP) shy
atomic(P)
prin(P)
printchar(SA lt= gt B) -
prin((l clausify(A AI [j) pl(eAl) prin())
print lt=gt )
prin(() cbusify(B Bl [I) pJ(eBl) prine))middot
printchar(rnumber(X N)) shy
prin(num() printchar(rx) prin( )
printchar(rN) prinC))
printchar(rF(A B)) shy
seJec(F(A B))
prinCsel() printchar(rA)
prin( F ) printchar(rB) prinC))
printchar(SF(A B)) shy
( selec(F(A B)) F = infix )
printchar(SA) prin( F ) printchar(SB)
printchar(SF(A)) shy
(F= prefix gt= F= prefix lt= F= prefixgt F= prefix lt )
prin(F ) printcbar(SA)
printchar(SP) shy
functor(P F MaxN)
prin(F ()
Nl is MaxN - 1
putout(S N 1 P MaxN)
34
prin())
putout(S 0 P MaxN) -
arg(~laxN P Argu)
prin tchar(SArgu)
putout(S N p MaxN) shy
Nt is MaxN - N arg(NI P Argu)
printcbar(SArgu )
prin( )
N2 is N - 1
putout(S N2 P MaxN)
selec(FA B)) shy
( F= infix = F= infix f= F= infix gt=
F= infix gt F= infix lt= F= infix lt )
35
----------------------------------Program Name APClS - Part 2 Inference Mechanism ---------------------------------- a(X) shy
steps(X X9)
(( X9 =[] nl
print( yes it is always true) )
( X9 =[cI(IJ[])] nl
print( no it is always false) )
( nl nl printel(X9) Step 1Oa
tell(temp_file) printel(X9) e1ose(temp_file) consult(temp_6Ie) ))
q(X) shy
asserta( in pt(X))
steps(X X9)
(( X9 = [] print(middot~H~~middot~t~)
print(THE AiSWER IS YES)
print( ilgIQlQl(~) )
( X9 = [e1([j [j)] Pr1nt ( OJ fi(i I~ iii Ij)middot(i)(i) fiyenQ)riiio(i)(ij)(i)fj)fiyen1li1il1li1il)__ gtw~ __~_~ _~~_ ~_-=~
print(THE ANSWER IS NO ) print() )
( teI1(temp_6Ie)
prques(X9) Step 1Ob
close(temp_file)
nl print(Let me think about it) nl
consult(temp_6Ie) ))
retrac t( in pt(X))
Step lOb Printing question
prques(lcl(A 8)1) - prin(goo(() pl(qA 8) print()))
prques([c1(A 8HCs]) - prin(goo(() pl(qA 8) print() pl(q Cs)
pl(e [c1(A 8)]) - pl(eA 8)
pl(q [c1(A 8)]) - pl(qA 8) print()))
pl(S [e1(A B)ICs]) - pl(SA B) prin( ) pl(S Cs)
38
pl(q [j L) - prin(c1ause(contradiction(() pcont(qL) prin())_))
pl(S [I L)- prin(so2(contradidion(() pcont(SL) print))))middot
pl(S [L] []) - prin(so2() pcbar(SL) prin())
pl(S L [J)- prinsol() plett(SL) print))
pl(S [L] LI) - prin(condi(() pchar(cL)
prin(() pcont(S Ll) prine))))
pl(S L Ll)- prin(c1ause() plert(cL)
prin(() pcont(S Ll) prine)))
plert(S[LJ) - pchar(SL)
plert(SjLILsj) - pcbar(SL) print v) pleCt(SLs)
pcont(S[L]) - pchar(SL)
pcont(S[LILsj) - pcbar(SL) prinr ) pcont(SLs)
pcbar(SP) shy
atomic(P)
name(PL)
( L = [IT] L = [5 k miT] L = [5 k niT] )
concat[XITj NewP)
prin(0JewP)
pchar(SP) shy
atomic(P)
prin(P) pchar(SA lt=gt B) -
prin(() dausify(A AI []) pl(eAI) prin())
prinr lt=gt ) prin(() dausify(B BI ]) pl(eB) print))
pchar(Snumber(X N)) shy
prin(num() pchar(SX) prin()
pchar(SN) prinr))
pcbar(SM N) - prin(M N)
pcbar(cF(A B)) shy
selec(F(A Braquo
pcbar(cA)
prine F ) pchar(cB) pchar(SF(A B)) shy
selec(F(A B))
prin(sel() pchar(SA)
print F ) pchar(SB) print)) I
31
pc har(SF(A)) shy
( F= prefix gt= F= prefix lt= F= prefixgt F= prefix lt )
prin(F ) pchar(SA)
pchar(SP)shy
runctor(P F MaxN)
prin(F ()
011 is MaxN - 1 pout(SNl P MaxN)
print) )
pout(S 0 P M3xN) - 1
arg(~bxN P Argu)
pchlr(SArgu )
pout(S N P MaxN shy
Nl is MaxN - N
arg(Nl P Argu)
pchar(SArgu
prin( )
N2 is N - 1
pout(S N2 P ~13xN)
Comparing numbers in numerical quantifiers
num(XN) shy
number(X I)
cnum(N 1) ~
cnumlaquo=01 lt=I- N gt=I
cnumlaquo=J lt I) - N gt=1-1
cnumlaquo=NIJ) - N gt=J 1
cnumlaquo=N J)- integer(I) N gt=I~
cnum(gt=N gt=1) - N lt=1
cnum(gt=N gt I) - N lt=1+ 1 cnum(gt=NIJ) - N lt=1
cnum(gt=N lt=1)- N lt=1
cnum(gt=N lt I) - N lt=1 L cnum(gt=N 1)- integer(I) N lt=1
cnum( lt N lt 1)- N gt=1 L
38
cnum( lt N lt=1) - N gt I cnum( lt NLJ) - N gt J
cnum( lt N 1)- integer(I) N gt 1
cnum(gt N gt I) - N lt=1 cnumlgt i gt=1) - N lt I
cnum(gt N lt=1) - N lt=0
cnum(gt N lt I) - N lt=0
cnum(gt iIJ) - N lt I cnum(gt N 1)- integer(I) N lt I
cnum(~LN lt=1) - M=I N gt= I l
cnum(~LN lt I) - M=l N gt= I-I
cnum(~LNLJ) - M lt =1 N gt = J
cnum(~1N 1)- integer(I) M lt= I N gt= I
cnum(- N) - integer(N)
Comparing selectors
sel(X = Y) shyX= Y
sel(X I=Y) shy(X I=Y X lt Y Xgt Y)
sel(X gt Y) shyXgt Y
sel(X lt Y) shyXlt Y
selX gt=Y) shy(X gt=Y X= Y Xgt Y)
se(X lt=Y) shy
(X lt=Y
X= Y
X lt Y)
csel(infix = infix =)
39
csel(infix = infix = csel(infix = infix gt)
csel(infix = infix lt) csel(infix gt infix gt) cseJ(infix lt infix lt) csel(infix gt= infix gt=) csel(infix gt= infix gt csel(infix gt= infix =)
csellinfix lt= infix lt=) csel(infix lt= infix lt) csel(infix lt= infix =)
Finding solutions
sol(X v Y) -
(( notetra(X) eon(X) ( sol(Y) )
( c1ause(P v Q R) not(cketra(P v Q))
dis(P v Q X v Y R) ~ )
( A lt=gt B equival(A lt=gt B X v Y) ~ I) sol(X) - ~ notetra(X) eon(X)
so~(X) - notetra(X)
( con (X)
( clause(P v Q R) not(ekctra(P v Q)) dis(P v Q X R) I)
cketra(P v Q) -
eketra(P) eketra(Q) eketra(F(I J)) shy
selec(F(I J))
c1ause(contradiction(sel(F(IJ))) _I
eketra(number(W I)) -
clause(cootradietion(num(Wl)) - eketr(P) shy
clause(contradiction(P) - 1
notctra(P) shy
not( e lause( con tradiction(P) _))
40
Searching (or disjunctions
dis(P v Q X v Y R) - dis(P X v Y R)
dis(Q X v Y R) con(R)
dis(P v Q X R) -
dis(P X R) dis(Q X R) con(R
dis(P X v Y R) - clause(contradicton(Pl J 1
dis(F(I J) sel(G(I J)) v Y R) - csel(G Fl dis(number(WI) num(W N v Y R) - cnum(N I)
dis(P P v Y R) -
dis(P X v Y R) - dis(P Y R)
dis(F(I J) seJ(G(IJ)) R) - csel(G F)
dis(number(WI) num(WN) R) - cnum(N I) dis(P P R) - 1
dis(FJ J X R) shy
( ckctra(F(IJ) cbeckeq(seJ(F(IJ))) )
dis(number(W Il X R) - ( ckctra(number(WI)) cbeckeq(num(WI)) )
dis(P X R) shy( ckctra(P) cbeckeq(P) ) 1
cbeckeq(P) shy
(( A lt=gt so2(contradiction(P))
bagof(A A [jj) ) ( so2(contradiction(P)) lt=gt B
bagof(B B Uj) ))
ckeq(A) shy
( so2(A) lt=gt B B lt=gt so2(A) ) bagof(B B UJ)
con((P Q)) -
clause(P R) con(R) con(Q) con(true) -
con(contradiction(P)) - clause(contradiction(P) J
con(cause(X Y)) - cause(X Y)
con(sel(X)) - sel(X)
con(num(X Y)) - num(X Y) con(P)- (( dause(P R) (con(R) ckeq(R)))
colJectin(P) )
collectin(P) shy
bagof(S (c1ause(P S) S = true) [L LIJ )
mkcon(L Ll L)
bagor(l (L2 ) UJ) L
mkcon((A AI) (B B1) (sol(A v B) e D)) -
mkcon(A B1 e) mkcon(A1 (B Bl) D)
mkcon(A (B B1) (sol(A v B) e)) -
mkcon(A Bl e)
mkcon((A AI) B (sol(A v B) e)) middot1
mkcon(Al B e)
mkcon(A B sol(A vB))
Searching ror equivalences
equival(A lt=gt B X v Y) - 1 ( equival(A lt=gt B X) equival(A lt=gt B Y) )
equival(s02(A) lt=gt 502(B) A) - clause(B _I equival(s02(B) lt=gt 502(A) A) c1ause(B _I
Top level or inrerence mechanism
goo((s02(whatnum) P)) -
getatm(P Xl
bagor(number(X Y) ( P so2(number(X Y)) ) A )
count1(A 00 L R) nl
bagor(X P B )
count2(B L R Ll Rl) nJ print()
(( LI = 0 Rl = 0 print(THE ANSWER IS ) nl
(( Ll = Rl prin(-Jumber or ) prn(P) print(is Ll) )
( Rlgt20000 prin(Number or I prn(P) print(is LI or more) )
42
( prin(Number of ) pfn(P) print( is from Ll to Rl) )) )
( print(THE ANSWER IS NO I )) print()
goo(X) shy
(( bagof(X X L) L = [I nl print()
print(THE ANSWER IS YES) nl wout(L) print() )
( equiv(X L) nl print()
print(THE ANSWER IS YES) nl wout(L) print(-) )
( c1ause(inpt(A ==gt B) _I ( impli(A B Z) impli(B A Z) ) print(l~Hl)
printTHE ANSWER IS YES) nl print(Z) print(Hj~(fH~) ))
goo(X) print( Hg)
print(THE ANSWER IS NO ) print( lH~lH~gg9l9lmiddotmiddot~Q(gmiddot)
00 Semhing for implications in equiV3lent relations
impli( B Z) shyt-ell( z1) prin(templ() pchn(S A lt=gt B) print()) close ( zl) consult(zl) templ(Z)
unload zl Z
Searching for equivalence
equiv (X L)
(( X lt=gt Y
equ(Y YI)t bagof(Y Yl L) L = [j )
(Y lt=gt X equ(Y YI) bagof(Y Yl L) L = [J )
( X = F(New)
clause(~ew T) makeup(T Tl)
(( Tl lt=gt B
equ(B Bl) bagof(Bl Bl M) M = [j L=[Newl )
(A lt=gt TI
equ(A AI) bagof(Al AI M) M = 1] L=INewj )) ))
makeup((A B) (AI Bl)) -
makeup(A A1) makeup(B BI)
makeup(A so2(A))
equ((A B) (AI BI)) -
equ(A AI) equ(B Bl)
equ(sol(X v Y) sol(XI v Yl)) -
equ(X XI) equ(Y YI)
equ(so2(X) so2(XI)) -
equ(X XI)
equ(contradiction(X) clJuse(contradiction(X) X) ) -
equ(X X)
Counting numbers
getatm((A B) X) -
( getatm(A X) getatm(B X) )
getatm(so2(F(X)) X) -
getatm(so2(X) X) - atom(X)
countl([J L R L R) -
countl([number(X Y)IT] L R L2 R2) shy
(( Y = (gt=~) LI is L + N Rl is R + 20001 l )
( Y = (gt N) LI is L+ N+ 1 RI is R + 20002 )
(Y == laquo=~) LI is L + 1 Rl is R + N )
(Y = laquo N) LI is L + 1 RI is R+N-I)
(Y == IJ LI is L + I Rl is R + J ) ( Y == N L1 is L + N RI is R + N ))
count1(T LI R 1 L2 R2)
count2(fJ L R L R) - 1
count2([XITJ L R L2 R2) shy
name(X Xl)
(( Xl = sknj LI is L Rl is R )
44
( Xl = Iskmj L1 is L + 1 RI is R + ZOOO1) ( LI is L + I RI is R + I ))
count2(T LI RI L2 R2)
pfn((A B)) - pfn(A) prn(B)
pCn(so2(F(X))) - prin(F )
prn(so2(X)) - atom(X) prin(X ) prn (so2(X))
Printing result
wout([XlJ - prt(X) nl woutf[xIY]) - prt(X) nl nl wout(Y)
prt(e(A B)) -
prt(A) prinr 8 ) prt(ltE) prt(eA) - prt(A)
prt(c(A EJ) - prin() prt(A) prine ) prt(B) prin(T)
prt(c A) - prt(A) prt((A E)) - ~
prt(A) nl prt(E) prt(sol(X v Y)) - ~
prt(X) prinC v) prt(Y) prt(A lt=gt B) -
prt(e A) prinC lt=gt ) prt(e B) prt(sol(X)) - prt(X)
prt(so2(X)) - prt(X
prt(c1ause(X Y)) - prt(X)
prt(contradiction(X)) - prin(contradiction() prt(cX) prinr))middot prt(num(XY)) - prin(number(X Y)) prt(sel(X)) - prin(X) prt(X v Y) - prt(X) prin( v) prt(Y) prt(X) prin(X)
Handling conditional queries
condi((Y Xl) shy
assertcon(X) Y
45
retractcon(X)
condi((B A))
retractcon(A) fail
assertcon((A B)) 1
assertcon(A) assertcon(B)
assertcon(A) asserta(A)
retrac teon ((A B)) 1
retracteon(A) retractcon (B)
retraetcon(A) - retract(A)
BIBLIOGRAPHIC DATA SHEET
Report No UIUCDS-F-84-928
3 Recipients Accession No
4 T ide and Subt ltle
An Annotated Predicate Calculus Inference System (APCIS)
S Report Date
November 1984 6
7 Author(s)
Kah-Eng Pua 8 Performing Organization Rept
No
9 Performing Organization Name and Address
Department of Computer Science University of Illinois Urbana IL
10 ProjectTaskWork Unit No
11 Contract Grant No NSF DCR 84-06081 ONR N00014-82-K-0186
12 Sponsoring Organization Name and Address
National Science Foundation Washington DC
13 Type of Report amp Period Covered
14
15 Supplementary Notes
16 Abstracts
This paper describes a deductive inference system called APCIS (Annotated Predicate Calculus Inference System) APCIS is able to carry out inferences from expressions involving numerical quantifiers selectors disjunctions of non-negated terms negated terms disjunctions of negated terms equivalences and exceptions It is also able to count the numbers of occurrence of a given simple term or a conjunction of terms The design of contradiction and the treatment of the disjunction of non-negated terms allow APCIS to accept Horn clauses as well as non-Horn clauses and to carry out inferences from them This feature makes APCIS more general than Prolog
17 Key lords and Document Analysis 170 Descriptors
APC (Annotated Predicate Calculus) APCIS (Annotated Predicate Calculus Inference System) Horn Clause Numerical Quantifier Prolog Selector
17b IdentifiersOpen-Ended Terms
17c COSATI FieldGroup
18 Availability Statement 19 Security Class (This
Re~f~~IA~SIF IFf)
21 ~o of Pages
49 211 ecurity Class (This
PageUNCLASSIFIED
22 Price
FOA NTIS n (10middot70 usco-oc 40329-
23 Assertion Mode
Figure l(c) is a schematic diagram showing how assertion mode works In this mode the
input assertion will first go through the APC translator as in assertionmiddot translation mode After
which the translated result will be printed both on the terminal and to a temporary file called
tempfile which will subsequently be loaded back to Prolog system As a result the newly
translated input assertion will become Prolog term(s or clause(s) in the database
24 Query Mode
Figure l(d) shows schematically the stages that will go through when query mode is
invoked The input query crowned by the (unctor inpt will first be stored in the database It will
then be passed to the APC translator as in query-translation mode The output of the translator
will be printed on the temporary file tempfile which will subsequently be loaded to Prolog
system Upon loading tempfiie to Prolog system (recall that tempJile contains essentially a
Prolog question) the question is executed immediately and its result will be prin ted out on the
terminal In the last stage the original input query crowned by the functor inpt will be
retracted from the database
3 APe Translator
As described in [3] there are ten steps in the APC translator and each step undertakes a
unique transformation Assertion-translation mode and assertion mode go through these steps
which have been covered in [3] and will not be discussed here
31 Translation of Queries
We will now examine the different transrormations that query-translation mode and
query mode will go through They differ Crom assertion-translation mode and assertion mode only
5
in the last step of translation
In the last step of the APe translator all input queries (ie expressions entered via
query-translation mode or query mode) are dealt with by the following six predicates prques pi
plett peont pehar and pout The task of prques pi plett and peont is to arrange each
input query in desired order whereas pehar and pout will print out each atomic formula
character by character For illustration purposes consider the following five APe expressions
1 all( X man(X) ==gt mortal(X)
2 exists( X horse(X) v dog(X) )
3 - ( exists( X horse(X) amp dog(X))
4 all( X be_shouted_at(X) amp no_response(X) == gt deaf(X) v dead(X) )
5 exists( 2 X box(X) )
H the above five APe expressions are typed to Prolog via assertion mode or assertionshy
translation mode they will be translated to the corresponding Prolog expressions
la
mortal(XI) shy
man(Xl)
2a
horse(skml) v dog(skml)
3a
contradiction(( horse(XI) dog(Xl) )) shy
horse(Xl)
dog(XI)
4a
deaf(Xl) v dead(Xl) shy
be_shouted_at(X I)
no_response(X1)
Sa
box(sknl)
number(sknl2)
The above live translated expressions ( ie la through Sa ) will be printed on the
terminal and loaded to Prolog if assertion mode is used they will be printed on the terminal but
not loaded to Prolog if assertion-translation mode is invoked
Now if the original APC expressions ( ie 1 through 5 ) are typed to Prolog via query
mode or query-translation mode the corresponding questions will be translated into the following
queries
lb
goo(( condi(( mortal(Xl) man(Xl))) ))
b
goo(( soil horse(Xl) v dog(XI)) ))
3b
goo(( c1ause( contradiction(( horse(XI) dog(Xl) )) _) ))
4b
goo(( conditt deaf(Xl) v dead(Xl) (be_shouted_at(XI) no_response(Xl)) )) ))
5b
amp00(( so2( box(XI) ) s02( num(XI 2 )) ))
The above five translated queries ( ie Ib through 5b ) will be printed on the terminal
and loaded to Prolog if query mode is used they will be printed on the terminal but not loaded to
Prolog if query-translation mode is invoked
In the above queries goo 801 and 802 each forms a part of the inference mechanism of
APCIS goo occupies the top level of the inference mechanism whereas 801 and 802 are at the
1
next level 102 will take care of the searching of simple terms and 101 will deal with the
disjunctions of non-negated terms in the database We will come back to them in Section 4
At the first glance one may feel that the above translated Queries are Quite complicated
However a closer examination will reveal that they are not so Queries lb 3b and 4b can each be
categorized as a conditional query which is a distinct feature of APCIS wherels queries 2b and
5b lre asking simple facts in the database
To handle conditional queries we consider two cases First if the queries involve a
special clause contradition we invoke the built-in function el3ule(X Y) which will look for the
desired contradiction clause in the database Second if the queries do not involve the clause
contradiction we activate a defined Prolog predicate condi to take care of the necessary
searching (To avoid confusion the reader is urged to compare expressions started with the same
number in the above three sets of example)
To handle a query which asks a simple fact we surround each disjunction of terms with
the functor sol as in the example 2b or crown each simple term with the functor 802 as in the
example 5b
32 TranslatIon of Negated Term And Disjunction of Negated Terms
One feature of APCIS is its ability to handle input expressions consisting of only negated
term or a disjunction of negated terms in the forms
or
2 -(AI) v ~(A2) v v ~(An)
To handle the above two forms a special clause with clause head contradiction is
created This special clause head has only one argument which is either a term or a set of terms
grouped together in the form
8
(AI A2 An)
The right-hand side of the clause contradiction is exactly same as the argument in the clause
head For example the above two forms involving negated terms will be translated into the
corresponding forms as follows
1 contradiction( A ) shy
A
2 contradiction(( AI A2 An )) shy
AI A2 An
The design of the clause with clause head contradiction will greatly enhance the inference power
of APCIS (see the example in Section 44)
33 Translation ot Disjunction ot Non-negated Terms
Another feature of APCIS is its ability to handle input expressions involving a
disjunction of non-negated terms in the forms
1 Al v A2 v v An
or
2 Bl amp 32 amp amp Bm ==gt Al v A2 v v An
Unlike Prolog which accepts only Horn clauses APCJS will accept Horn clauses as well
as non-Horn clauses which take the above two forms The inference from non-Horn clauses is
made possible by the two defined predicates sol lnd s02 discussed in Section 42 and Section 43
respectively (see also the example in Section 44) In the APC translator the above two forms are
transbted into the corresponding forms as follows
1 Al v A2 v v An
2 Al v A2 v v An shy
g
Bl B2 Bm
34 Futher Transformation of Exceptions and Equivalences
To provide some backgrounds for the discussion of the further transformation of
exception and equivalence relations we will lirst reproduce the three goals in the Step 2 of the
APe translator discussed in Section 32 of [31
First expressions involving implication or the form A ==gt B will be transformed to
Second expressions with exception symbol or the form A - B will be changed to the
form ( A lt=gt -(B) ) amp ( -(A) lt=gt B)
Tbird expressions with equivalence symbol of the form -(A) lt=gt B or of the form
A lt=gt -(B) will also be converted to ( A lt=gt -(B) ) amp ( -(A) lt=gt B ) since tbere are
logically identical to exception relations Also expressions with equivalence symbol of the form
A lt=gt B or -(A) lt=gt -(B) will remain the same
After the Step] of the APe translator both sides of any transformed expression with
lt = gt symbol will be treated separately as if they are two independent expressions In the
Step 10 of the APe translator each side of lt=gt will again be treated separately and
transformed into a form similar to an transformed input query (see Section 31) Two examples
are given below
1 state(on) lt=gt -( state(olJ) )
2 all( 1 bot(l) amp humid(l) - winter(I) )
They will be transformed in the Step 2 or the APe translator into
1
(state(on) lt=gt -( state(off) ) ) amp ( -( state(on) ) lt=gt state(olJ) )
2
10
( hot(l) amp humid(l lt=gt -(winter(l)) ) amp
( -( hot(l) amp humid(l)) lt=gt winter(I)
In Step la they will again be transformed to
1
so2( state(on) ) lt=gt so2( contradiction( state(oH) ) )
so2( contradiction( state(on) ) ) lt=gt so2( state(oH) )
2
( s02(hot(XI)) so2(humid(XI))) lt=gt so2( contradiction( winter(Xl ))
so2( contradiction(( bot(Xl) humid(Xl) )) ) lt= gt so2( winter(XI) )
There are two advantages in the treatment of exception and equivalence symbols in this
way First it will prevent Prolog program from going into an infinite loop which is difficult to
avoid if equivalent relation such as A lt=gt B is transformed into the logically equivalent form
( A ==gt B) amp ( B ==gt A) Second by maintaining both sides of lt=gt symbol in
query form the searching on either side caD be done more easily and efficiently since the form
is already processed and does not need any further transformation
Inference Mechanism
As mentioned at the end of Section 31 goo sol and s02 each forms a part of the
inference mechanism of APCIS with goo occupying the top level and 80) and 802 the second
level In addition to these countl count2 equlv and impll are also at the second level of the
inference mechanism We will go over all of them in the following sections
I goo
goo is essentially the starting point of the inference Whenever a translated query is
loaded to Prolog system from temp-fie goo will go through one or more of the following steps in
11
sequence
G 1 Check if the query asks for the numbers of occurrence of certain term(s) It so then
pass It to eountl and eount2 else go to G2
G2 The query will be passed down to sol or s02 (or both) to check i( any assertion in the
database can satisfy the query It the answer is positive then the query succeeds else
go to G3
G3 The query will be passed to equlv to carry out further searching It the searching is a
success then the query will be closed with a success else go to G4
G4 It the query is in the form A ==gt B then it will be passed to Impli It Impll
succeeds then done else the query will be closed with a (ailure
42 sol
801 and 802 together with dis and eon form the most complicated part of the APCIS
iorerence mechanism In this and the next section we will look at sol and s02 dis and eon will
be discussed in Section 44 We will close Section 44 with an example that illustrates the
materials presented in Section 42 through Section 44
sol is at the second level of the inference mechanism It will deal with any disjunction of
non-negated terms For any disjunction passed to it it will go through one or more of the
following steps in sequence
S1 Check if any term In the disjunction can be satisfied by any term or clause in the
database without contradiction It so then done else go to S2
S2 Pass the disjunction together with another disjunction (and its tlil) picked up from
the database to dis It dis succeeds then done else go to S3
S3 Pass the disjunction down to equlval which will check if any term in the disjunction
matches either side of any equivalence relation in the database It such a match is
found then check if the other side of the equivalence C3n be satisfied It so then done
else the goal fails
43 s02
s02 is also at the second level of the inference mechanism It will take care of all the
simple terms in the transl1ted query The following is the sequence that s02 wiII follow in
searching
S1 Check if the term passed to it caD be s3tisfied by any term or clause in the d3tabase
without contradiction It so then done else go to S2
S2 Pass the term together with a disjunction of terms (and its tail) picked up from the
database to dis If dis succeeds then done else the goal fails
44 dis and con
dis has three arguments In the first two clauses of dIs the first argument P v Q is
found in the database using the builtmiddotin functiol clause and the third argument R is the tair of
the term or the clause P v Q If P v Q is not a clause but a term R will be instantiated to trUE
The second 3rgument comes from either lIol or 802 and thus takes the form of either X v Y (a
disjunction of terms) or T (3 simple term)
All the clauses of dis together with con will perform the searching as exemplified in the
following algorithm (we will keep the notationsin this section)
01 Check if every term in P v Q is in X v Y It so then go to 03 else go to D2
02 For any term (in P v Q) which is not in X v Y or does not match T perform the
following tests
a Check if the term (in P v Q) has already been negated in the datab3Se (ie check if
the contradiction of the term exists in the d3tabase) If so then repeat D2 for other
terms not found in X v Y or not matching T else go to b
13
b Check if the contradiction of the term matches either side of any equivalence
relation in the database If such a match is found then check if the other side of the
equivalence can be satisfied If so then repeat O~ for other terms not found in X v Y
or not matching T else the goal fails
It all the terms (in P v Q) which are not in X v Y or do not match T survive either one
of the above two tests then go to 03
03 This step is essentially done by eon whose goal is to satisfy the tail R of P v Q It
con succeeds then done else the search fails
To close this section we will give an example to illustrate what we have covered In
Section 42 through Section 44
Example Assume that we already haye the following expressions in the database
horse(skml) v dog(skmI)
contradiction(( dog(XI) ))shy
dog(XI)
query goo(( soZ horse(X)) ))
This query will be passed to 802 which will check it the term horse() can be satisfied iu Step S 1
of Section 43 It is a failure So we now go to Step S2 In this step we pick up the disjunction
horse(~kml) v dog(skml) (and its tail true) in the datab3Se and pass it together with the term
horse(X) to dis We are now in Step 01 of Section 44 In this step we find that dog(skml) does
not match horse(X) So we have to go to Step 02 In Step 023 We find that the term dog(skml)
has already been negated (the second expression in the database) So we go to next step 03 Since
the tail of the disjuDction horse(skml) v dog(skml) is the atom true con is satisfied and the
query succeeds
45 countl and count2
countl and count2 are responsible for the counting of tbe numbers of occurrence of a
given simple term or a conjunction of terms They are activated by input queries in the form
q( exists( X whatnum amp P) )
where whatnum is the l~bel for activating the counting of the numbers of occurrence of P which
can either be a term or a conjunction of terms
countl will count the number of term(s) which will satisfy P and associate(s) with
numerical quantification(s Two counters are set to update the lower and upper boundary or the
scope or the numfrical quantifications encountered
The contents of the two counters are then passed to count2 which is responsible for the
counting or the following three types of term First term(s) which will satisfy P and associate(s)
with existential quantification(s Second term(s) which will satisfy P and has(have) Prolog atom
as its(thfir) argument(s) Third term(s) that will satisfy P and itself(themselves) is(are) Prolog
atom(s )
46 equiv
equlv will be activated only after sol and B02 have failed The first two goals of equlv
are similar to that of Step S3 in Section 42 and Step D2b in Section 44 The third goal or equiv
makes possible the inference on either side of any equivalent relation For example if we type the
following three expressions to Prolog in assertion mode
l all( X hot(X) amp humidX) - winter(X)
2 all( X hot(X) amp bumid(X) ==gt unpresent(X))
3 - ( exists( X winter(X) ) )
and then ask APCIS in query mode
q( cxists( X unpresent(X) ) )
15
APCIS with the aid of equlv will be able to answer yes to this query
41 lmpll
lmpll can be considered as the last attempt that APCIS would make to satisfy a
query It is activated only after equlv has failed It will first check if the query is conditional If
so it will convert the implication symbol to equivalence symbol and search if such an equivalent
relation can be found in the database If so a success Otherwise a failure
5 More on the Inference Mechanism
Having looked at all the subparts at the top two levels of the inference mechanism we
are ready to look at other subparts at lower levels
51 num and cnum
One distinct fe3ture or APCIS is its ability to deal with numerical quantifications As
mentioned in Section 31 input queries and assertions will undergo different transformations in
the last step (Step 10) of translation This also holds true for expressions involving numerical
quantifications Consider the following expression
exists( 6 X horse(X) )
If it is entered to Prolog via assertion mode we will after going through all the steps of
translation have the rollowing entered to the database
horse(sk n I
number(sknl6)
Now if we want to ask Are there more than five horses 7 and type in
q( exists( gt5 X horse(X) ) )
1amp
APCIS will translate the question and enter to Prolog the following query
goo(( s02( horse(X) ) s02( num( X gt5 )) ))
Note that the term number(slml 6) in the database and the term num(X gt S) in the query are
different predicates and this difference is exactly where the power of the clause num(X N)
defined in APCIS comes from When the clause num(X N) in APCIS is activated it will search
through the database to see if there is any term of the form number(X I) whose first argument
matches the first argument of num(X Y) in the query It a match is found the second arguments
of both num(X Y) in the query and number(ltI) in the database will be passed to cnum in
APCIS
The job of cnum is to compare the numerical messages carried by the second
argument or the term rlum(X Y) in the query and the second argument of the term rlumber(X I)
in the database to see if they match with each other according to the rules defined in cnum
While there are 25 rules for such matching purposes the idea is simple
Imagine that the second argument Y of the term num(X Y) in the query
and the second argument I of the term num()( I) in the database each occupies a
place in an integer line (Le the integer line in mathematics) To have a match
the domain covered by Y should contain the domain covered by L
As an example the answer to the above query is positive since the domain of gt5
contains the domain or 6
Before closing this section we will bring out a speciaJ translation aspect of expressions
involving numbers by an example We first type to APCIS the Collowing expressions in assertion
mode
1 aU(X all(Y father(X Y) amp number(Y gt6) ==gt has_manY3hildren(X) ))
2 exists(X exists( 12 Y Cather(X Y) ) )
11
After going tbrougb all tbe translation steps tbe Collowing two expressions will be entered to tbe
database
I
bas_many_cbildren( Xl ) shy
Cather( Xl X2 )
num( X2 gt6 )
2
Catber( sk m1 sk n2 )
number( skn2 12 )
lotice that whenev(gtr a term with Cunctor number appears at the rigbt-band side oC a Prolog
clause its Cunctor will be cbanged to num automatically This treatment will greatly cnbance tbe
inference power of the clause sbown in l above For instance iC we now ask tbe question
q( exists( X bas_many_children(X) ) )
The right hand side oC the clause l will match the two terms in 2 and tbe query succeeds
52 Bel and cael
A special feature of APe is tbat all predicates tbat express relations = = gt
gt= lt and lt= can be expressed explicitly using infix notations as relational statements
called selectors To handle selectors we defined Bel in APCIS
Every expression involving selectors will undergo different translations in assertion mode
and query mode For example the assertion
a( exists( [X Y] box (X) amp box(Y) amp (weigh t(X) gt weight(Y) ) ) )
will be translated into the following three terms and entered to tbe database
box( skml )
box( skm2 )
18
weight( skm 1 ) gt weight( skm2 )
Now it we want to ask Is it true that there exists two boxes of different weights and type in
q( exists( [X Yl box(X) amp box(Y) amp ( weight(X) = weight(Y) ) ) )
The question will be transformed to the following query and entered to Prolog
goo(( so( box(XI) ) s02( box(X2) ) so2( sel( weightXI) = weight(X2) )) ))
Note that the selector in the above query is surrounded by the functor set When any clause or
8el in APCIS is activated it will search through the database to see it there is any selector whose
two arguments (left and right side or any selector symbol) match the two arguments of the
selector in the query At the same time 8el will check iC the selector symbols (may be different) or
the two different selectors (one in the query and one in the database) satisfy the rules defined in
sel There are 12 matching rules defined in sel All oC them ~re straightforward and will not be
discussed here An example will be enough to explain how 8el works
Consider the execution of the above transformed query The first two terms in the query
are satisfied by the first two terms in the database and Xl and X2 are instantiated to skml and
skm2 respectively The third term of the query will be passed to eel (of APCIS) which finds a
match on each side of the two selectors (one in the query and one in the database) At the same
time the two different selector symbols gt and = are found to satisfy one of the rules in
8el As a result the query succeeds
To enhance the inference power of clauses involving selectors all the selectors appearing
on the rightmiddothand side oC any clause will be surrounded by a functor set The idea is similar to
that in the last part of the previous section
c8el is exactly the same as 8el functionally It provides a convenient way to compare
selectors when dis is being executed
19
8 Printing Result
Whenever a goal is successfully executed APCIS will not only response with a yes but
also print out the matched terms or clauses in the database This is made possible by the built-in
function bagor and the two predicates wout and prt defined in APCIS
7 Summary
In this paper a description of a deductive inference system called APCIS (Annotated
Predicate Calculus Inference System) has been provided APCIS is able to carry out inferences
from expressions involving numerical quantifiers selectors disjunctions of non-negated terms
negated terms disjunctions of negated terms equivalences and exceptions It is also able to count
the numbers of occurrence of a given simple term or a conjunction of terms
The main idea of APCIS is that each input APC expression is first passed to a
preprocessor ( ie APC translator ) which dissolves and transforms each APC expression into
Prolog expression(s) which will then be loaded to Prolog system The user bas to specify whether
each input expression is to be entered as an assertion or as a query by invoking either assertion
mode or query mode respectively Each assertion or query will undergo different transformations in
the preprocessor The different treatment of assertion or query not only allows a full uS1ge of the
Prolog inference mechanism but also makes possible a higher level of inexact pattern matching
exemplified by the examples in Section 51 and Section 52 where the four predicates num
cnum sel and csel are discussed This higher level of pattern matching increases the inference
power of APCIS greatly
The design of contradiction and the treatment of the disjunction of non-negated terms
allow APCIS to accept non-Horn clauses and to carry out inference from them This feature
makes APCIS more general than Prolog
20
While APCIS performs very well in many sets of arguments provided by the author it is
still too early to jump to conclusion that it can perform equally well in all types of problems In
any event the expressiveness of APC has greatly been retained in the present version of APCIS
and moreover some design ideas or APCIS mentioned in this paper are not restricted to APCIS
- they may be carried over to learning programs with narrower scopes
21
References
[1] W F Clocksin and C S Mellish Programming In Prolog Springermiddot Verlag Berlin Hpoundidelberg 1981
[2] R S Michalski A Theory and Methodology of Inductive Learning Chpt 4 Machine L earning Tioga Publishing Co Palo Alto CaliJornia 1989
[3] K-E Pua Translating Annotated Predicate Calculu8 to Prolog ISG Report 84middot1 UlUCDCSmiddotFmiddot918 University oj Illinois Urbana IL June 1984
22
Appendix A
APCIS Users Manual
1 Get Started
Users are urged to follow the steps depicted below
1 Get the PROLOG interpreter by typing
alias prolog mntb2sammutsammutprologprolog (Vax A)
or
alias prolog mntb2sammutsammutbinprolog (Vax B)
2 Load apc and infer by typing
prolog apc infer
When large APC expressions are expected we can increase the stlck by typingI
prolog -snnnn ape infer
where ns denote the number of stacks in decimal
3 When the wording LSW - PROLOG appears on the terminal we are reldy to interact
with APCIS The four modes by which we can invoke APCIS are summarized below
a Assert ion-Translation Mode
ta(X)
b Query-Translation Mode
tq(X)
c Assertion Mode
a(X
d Query Mode
q(X)
23
where Xs are APC expressions
2 Notations Used in APCIS
Below is a summary or notations used in APCIS
a Logical operators
amp
v
==gt
lt=gt
-
negation
conjunction
disjunction
implication
equivalence
exception
b Binary relation symbols in selectors
-
=
gt=
lt=
gt
lt
equal
not equal
greater or equal
smaller or equ al
greater
smaller
c Relational operators in numerical quantifiers
lt less than
lt= less than or equal
gt greater than
gt= greater than or equal
d BinlTY operator in numerical quantifier
range
e Universal quantifier
all(X p(X))
f Existential quantifier
exists(X p(X))
g Numerical quantifier
exists(I X p(X))
where p(X) is a formula
where X is a variable or a Jist of variables or the
form [HI~rj and p(X) a formula
where I repersents expression involving integer(s)
and operator(s) in c or d above and p(X) a formula
25
Appendix B
APCIS Program Listings
------------------------------- Program Name APCIS - Part 1 APC Translator
-------------------------------
op(3OO fx -)1
op(500 xfy amp)
oPt 500 xfy v)
op(600 xfx )
op(700 fx [gt= lt= gt lt ]) op(400 xfy [= gt= lt= gt lt ])1 op(900 xfy gt lt=gt -])1
steps(X Xg) shy
numbervars(X 1 J Step 1 change variables to iis
rmimp(X X) Step 2 conv(X X3) Step 3
rewrite(X3 X4) Step 4
negin(X4 X5) Step 5
dropexist(X5 X6 1]) Step 6
dropall(X6 X7) Step 7
distrib(X7 X8) Step 8 clausiCy(X8 X9 [J) Step 9
ta(X) shysteps(X Xg)
(( Xg = II nl
print( yes it is always true) )
( nl nl printcl(X9))) Step 10a
tq(X) shy
steps(X Xg)
prques(Xg)
28
Step 2 Removing implic3tions amp Transforming exceptions and equiv3lences
rmimpl( P - Q (PI lt=gt (QI) ) amp ((PI) lt=gt QI) ) -
rmimpl(P PI) rmimpl(Q QI)
rmimplnp) lt=gt Q (PI lt=gt -(QI)) amp nPI) lt=gt QI) ) - 1
rmimpl(P PI) rmimpJ(Q QI)
rmimpJ(P lt-gt -(Q) (PI lt=gt -(QI)) amp nPI) lt=gt QI) ) -
rmimpl(P PI) rmimpl(Q QI)
rmimpl( P lt=gt Q PI lt=gt QI ) - I
rmimpl(P PI) rmimpl(Q QI)
rmimpl( P ==gt Q -(PI) v QI ) - I
rmimpl(P PI) rmimpl(Q QI)
rmimpl( all(X P) aI(X PI) ) - 1
rmimpl(P PI)
rmimpl( exists(X P) exists(X PI) ) -
rmimpl(P PI)
rmimpl( exists(I X P) exists(I X PI) ) -
rmimpl(P PI)
rmimpl( P amp Q PI amp Ql ) -
rmimpl(P PI) rmimpl(Q Ql)
rmimpl( P v Q PI v QI ) -
rmimpl(P PI) rmimpl(Q QI)
rmimpl( -(p) -(PI) ) - I
rmimpl(p PI)
rmimpl( P P )
St~p 3 Converting numerical amp distinctive quantifiers
L Numerical quantifiers
examples of input forms
1 exists(gt= i X pIX)) where i is an integer
2 exists(i X pIX)) where i is an integer
3 exists(i j X pIX)) where i j are integers and iltj
4 exists(il v i2 X pIX)) where is are integers
examples of output forms of this step
1 exists(X pIX) amp number(X gt= i) )
2 exists(X pIX) amp number(X i) ) 3 exists(X pIX) amp number(X ij) ) 4 exists(X pIX) amp number(X il v i2) )
II Distinctive quantifiers
27
example or input Corm
exists([XYL p(X Y))
example or output Corm or this step
exists(X exists(Y p(XY)) )
conv(P lt=gt Q PI lt=gt QI) - 1
conv(P PI) conv(Q QI)
conv(al1(X P) all(X PI)) -
conv(P PI)
conv(exists(HIT] P) R ) - conv(P PI) convert distinctive quantifier
convtdis(exists([HIT]PI) R)
conv( exists(I X P) exists(X PIamp number(X I) )) -
conv(P PI) convert numerical quantifier
conv(exists(X P) exists(X PI)) - 1
conv(P Pl)
conv(P amp Q PI amp QI) - 1
conv(P PI) conv(Q QI)
conv(P v Q PI v QI) - t conv(P PI) conv(Q QI)
convC(P) -(PI)) -
conv(P PI)
conv(P Pl
convtdis(existsl[XL P) exists(X P)) - atomic(X) convtdis(exists[XIYj Pl exists(X R)) shy
convtdis(exists(Y P) R)
Step 4 Rewriting compound predicates andor compound selectors
Outputs are smiple predicates andor simple selectors
rewrite(P lt=gt Q PI lt=gt QI) - t rewrite(P PI) rewrite(Q QI)
rewrite(all(X Pl all(X PI)) - 1 rewrite(P PI)
rewriteexists(X P) exists(X PI)) - I rewriteP PI)
rewrite(P amp Q PI amp QI) - rewrite(P P 1) rewrite( Q Q 1
rewrite(P v Q PI v QI) - 1
rewrite(P PI) rewrite(Q QI)
rewriteC(P) -(PI)) - I
28
rewrite(P PI) rewrite(F(A B) R) -
rewrite(A AI) rewrite(B BI) re(F(AI BI) R)
rewrite(F(A) R) -
rewrite(A AI) re(F(AI) H)
rewrite(F(A B C) R) -
rewrite(A AI) rewrite(B BI) rewrite(C CI) re(F(AI BI CI) R)
rewrite(F(A B C D) R) -
rewrite(A AI) rewrite(B Btl rewrite(C CI) rewrite(D DI) rc(F(AI BI CI Dl) H)
rewrite(PP)
re(F(A B v el (RI v R2) -
re(F(A Bl RIl re(F(A C) R2) reF(A B amp cl (RI amp R2)) -
re(F(A B) RI) re(F(A e) R2) re(F(A amp B C) (Rl amp R2)) -
re(F(A e) R 1) re(F(B C) R 2) re(F( v B el (R I v R2)) -
re(F(A el R I) reFB el R2) re(F(A amp Bl (R I amp R2)) -
re(F(A RI) re(F(BJH2) re(F(A v B) (R 1 v R2)) -
re(F(A) RI) re(F(B) R2)
re(F(A vB c Dl (RI v R2) -
re(F(A C D) RI) re(F(B C D) R2) re(F(A amp B C D) (RI amp R2)) -
re(F(A C D) Rll re(F(B C D) R2) re(F(A B v C D) (HI v R2)) -
re(F(A B D) RI) re(F(A C D) R2) re(F(A B amp C D) (HI amp R2)) -
re(F(A B D) RI) re(F(A C D) R2) re(F(A B C v D) (RI v R2)) -
re(F(A B C) R I) reF(A B D) R2) re(F(A B C amp D) (RI amp R2)) -
29
re(F(A B C) RI) re(F(A B D) RZ)
re(F(A v B e D E) (R I v R2)) -
re(F(A e D E) R I) re(F(B e D El R2) re(F(A amp B e D E) (RI amp RZ)) -
re(F(A e D El R 1) re(F(B e D E) R2) re(F(A B v e D E) (R I v R2)) -
re(F(A B D E) RI) re(F(A e D E) R2)
re(F(A B amp e D E) (RI amp R2)) -
re(F(A B D El RI) re(F(A e D E) RZ) re(F(A B e v D E) (R I v R2)) -
re(F(A B e El R 1) re(F(A B D E) RZ) re(F(A B e amp D E) (RI amp RZ)) -
re(F(A B e E) R I) re(F(A B D E) RZ)
re(F(A B e D vEl (RI v RZ)) - l
rc(F(A B C D) RI) re(F(A n e El RZ) re(F(A B e D amp El (RI amp RZ)) - ~
re(F(A B e D) RI) re(F(A B e El RZ)
re((A = B) (A = B)l-
re((A = Bl (A = 8)) -
retIA gt= BI (A gt= B)) -
re((A lt= B) (A lt= B)) -
re((A gt B) (A gt B))-
re((A lt Bl (A lt Bl)- re(A A)
Step) Bringing n(gation inwards
Degin(-(P) PI) - neg(P Pl)
negin(P lt=gt Q PI lt=gt Ql) - ~
negin(P PI) negiD(Q QI)
Degin(aU(X P) all(X PI)) - Degin(P PI) negin(exists(X P) exists(X PI))- negin(P PI) negin(P amp Q PI amp Ql) - Degin(P PI) negin(Q Ql)
Degin(P v Q PI v QI) - Degin(P PI) negin(Q QI) negin(P Pl
neg(-(P) PI) - negin(P PI)
neg(all(X P) exists(X PI)) - neg(P PI)
30
neg(exists(X P) all(X PI)) - neg(P PI)
neg(P amp Q PI v QI) - neg(P PI) neg(Q Ql)
neg(P v Q PI amp QI) - neg(P PI) neg(Q QI)
neg(P -(PH
Step 6 Dropping existnetial quanti6ers
dropexist(P lt=gt Q PI lt=gt QI Elerns) - dropexist(P PI Elerns) dropexist(Q QI Elerns)
dropexist(alJ(X P) all(XPI) Elerns)
dropexist(P PI [XIElernsJ)
dropexist(exists(X P amp nurnber(X Yraquo P2 Elerns) -
genfun(skn Newg) Fun = [NewgIElerns]
subst(FuD X P amp Dumber(X Y) PI)
dropexist(Pl P2 Elerns)
dropexist(exists(X P) PZ Elerns) -
genfun(skrn Newf) Fun = [NewfIElernsJ
subst(Fun X p PI)
dropex ist(P 1 P~ Elerns)
dropexist(P v Q PI v QI Elerns) - ~
dropexist(P PI Elerns) dropexist(Q Ql Elerns)
dropexist(P amp Q PI amp QI Elerns) - 1
dropexist(P Pl Elerns) dropexist(Q QI Elerns)
dropexist(P P _)
gen fun(R oot Newn arne) shy
getnurn(Root Nurn)
narne(Root Rootlist)
append(Rootlist[Nurnj Narnelist)
concat(Narnelist Newnarne)
getnurn(Root Nurn) shy
retract(currentnurn(Root Nurn 1 raquo
Nurn is Nurni + 1
asserta(currentnurn(Root Nurn))
getnurn(Root 1) - asserta(currentnurn(Root 1))
subst(New Old Val Val) - var(Val)
subst(New Old Old New) - 1 substNew Old Val Val) - atornic(Val)
31
subst(New Old Val Newval) shy
runctor(Val F N)
CUDctor(Newval F N)
subst_args(N New Old Val Newval)
subst_args(O J J - J J
subst_args(N New Old Val NewVal) shy
arg(N Val OldArg)
arg(N NewVal NewArg)
subst(New Old OldArg NewArg)
NI is N - I
subst_args(Nl New Old Val NewVal)
append([J L L) -
append([XILl] L2 [XIL3]) - append(Ll L2 L3)
Step - Dropping universal quantifiers
dropall(P lt=gt Q PI lt=gt QI)-
dropall(P PI) dropall(Q QI)
dropall(all(X P) PI) - ~ dropall(P PI)
dropall(P amp Q PI amp QI) -
dropall(P PI) dropall(Q QI)
dropall(P v Q PI v QI) -
dropall(P PI) dropall(Q QI)
dropall(P P)
Step 8 Distributing conjunctions over disjunctions
distrib(P lt=gt Q PI lt=gt Ql) - t distrib(P PI) distrib(Q QI)
distrib(P v Q R) -
distrib(P PI) distrib(Q QI)
distributing(PI v QI R)
distrib(P it Q PI it QI) -
distrib(P PI) distrib( Q QI)
distrib(P P)
distributing((P amp Q) v R PI amp QI) -
distrib(P v R PI) distrib(Q v R Ql)
32
distributing(P v (Q amp R) PI amp Ql) -
distrib(P v Q PI) distrib(P v R Ql)
distributing(P P)
Step 9 Packing each conjunction into clauses
c1ausify(P amp Q CI C2) -
clausiCy(P CI C3) c1ausify(Q C3 C2)
cbusiCy(P [d(A B)ICs] Cs) shy
inclause(P A [j B [I) 1
c1ausiry( C C)
inclause(P v Q A AI B B1) -
inc1ause(P A2 AI B2 Bl)
inclause(Q A A2 B B2)
inclausenp) A A B1 B) -
notin(P A) putin(P B B1)
inclause(P AI A B B) shy
notin(P Bl putin(P A AI)
notin(X [XU) - fail
notin(X [JLj) - notin(X L)
notin(X 1])
putin(X II [X]) - 1
putin(X [XILJ L) -
putin(X [YILJ [YILl]) - putin(X L Ll)
Step 1Oa Printing clauses
printcl([]) - nl nl
printcl(c1(AB)ICsj) - printcl(A Bl nl printcl(Cs)
printcl(L II) - printdis(IL) prinr)middot
printclHl L) - prin(contradiction(() printconl(rL)
print()) - ) printconj(rL) prinr )
printcl(Ll L2) shy
printdis(ILl) print( - ) printconj(rL2) prin()
printdis(S[Lj) - printcbar(SL)
33
printdis(S[LILs]) - printchu(SL) prin( v) printdis(SLs)
printconl(S[LI) - printchar(SL)
printconl(S[LILs]) - printchar(SL) prin( ) printconl(SLs)
printconj(S[L]) - tab(3) printchar(SL)
prin tconj( S [L IL sl) shy
tab(3) printchar(SL) print( ) printconj(SLs)
printchar(SP) shy
atomic(P)
name(P L)
L = [IT]
concat([XIT NewP)
prin(~ewP)
printchar(SP) shy
atomic(P)
prin(P)
printchar(SA lt= gt B) -
prin((l clausify(A AI [j) pl(eAl) prin())
print lt=gt )
prin(() cbusify(B Bl [I) pJ(eBl) prine))middot
printchar(rnumber(X N)) shy
prin(num() printchar(rx) prin( )
printchar(rN) prinC))
printchar(rF(A B)) shy
seJec(F(A B))
prinCsel() printchar(rA)
prin( F ) printchar(rB) prinC))
printchar(SF(A B)) shy
( selec(F(A B)) F = infix )
printchar(SA) prin( F ) printchar(SB)
printchar(SF(A)) shy
(F= prefix gt= F= prefix lt= F= prefixgt F= prefix lt )
prin(F ) printcbar(SA)
printchar(SP) shy
functor(P F MaxN)
prin(F ()
Nl is MaxN - 1
putout(S N 1 P MaxN)
34
prin())
putout(S 0 P MaxN) -
arg(~laxN P Argu)
prin tchar(SArgu)
putout(S N p MaxN) shy
Nt is MaxN - N arg(NI P Argu)
printcbar(SArgu )
prin( )
N2 is N - 1
putout(S N2 P MaxN)
selec(FA B)) shy
( F= infix = F= infix f= F= infix gt=
F= infix gt F= infix lt= F= infix lt )
35
----------------------------------Program Name APClS - Part 2 Inference Mechanism ---------------------------------- a(X) shy
steps(X X9)
(( X9 =[] nl
print( yes it is always true) )
( X9 =[cI(IJ[])] nl
print( no it is always false) )
( nl nl printel(X9) Step 1Oa
tell(temp_file) printel(X9) e1ose(temp_file) consult(temp_6Ie) ))
q(X) shy
asserta( in pt(X))
steps(X X9)
(( X9 = [] print(middot~H~~middot~t~)
print(THE AiSWER IS YES)
print( ilgIQlQl(~) )
( X9 = [e1([j [j)] Pr1nt ( OJ fi(i I~ iii Ij)middot(i)(i) fiyenQ)riiio(i)(ij)(i)fj)fiyen1li1il1li1il)__ gtw~ __~_~ _~~_ ~_-=~
print(THE ANSWER IS NO ) print() )
( teI1(temp_6Ie)
prques(X9) Step 1Ob
close(temp_file)
nl print(Let me think about it) nl
consult(temp_6Ie) ))
retrac t( in pt(X))
Step lOb Printing question
prques(lcl(A 8)1) - prin(goo(() pl(qA 8) print()))
prques([c1(A 8HCs]) - prin(goo(() pl(qA 8) print() pl(q Cs)
pl(e [c1(A 8)]) - pl(eA 8)
pl(q [c1(A 8)]) - pl(qA 8) print()))
pl(S [e1(A B)ICs]) - pl(SA B) prin( ) pl(S Cs)
38
pl(q [j L) - prin(c1ause(contradiction(() pcont(qL) prin())_))
pl(S [I L)- prin(so2(contradidion(() pcont(SL) print))))middot
pl(S [L] []) - prin(so2() pcbar(SL) prin())
pl(S L [J)- prinsol() plett(SL) print))
pl(S [L] LI) - prin(condi(() pchar(cL)
prin(() pcont(S Ll) prine))))
pl(S L Ll)- prin(c1ause() plert(cL)
prin(() pcont(S Ll) prine)))
plert(S[LJ) - pchar(SL)
plert(SjLILsj) - pcbar(SL) print v) pleCt(SLs)
pcont(S[L]) - pchar(SL)
pcont(S[LILsj) - pcbar(SL) prinr ) pcont(SLs)
pcbar(SP) shy
atomic(P)
name(PL)
( L = [IT] L = [5 k miT] L = [5 k niT] )
concat[XITj NewP)
prin(0JewP)
pchar(SP) shy
atomic(P)
prin(P) pchar(SA lt=gt B) -
prin(() dausify(A AI []) pl(eAI) prin())
prinr lt=gt ) prin(() dausify(B BI ]) pl(eB) print))
pchar(Snumber(X N)) shy
prin(num() pchar(SX) prin()
pchar(SN) prinr))
pcbar(SM N) - prin(M N)
pcbar(cF(A B)) shy
selec(F(A Braquo
pcbar(cA)
prine F ) pchar(cB) pchar(SF(A B)) shy
selec(F(A B))
prin(sel() pchar(SA)
print F ) pchar(SB) print)) I
31
pc har(SF(A)) shy
( F= prefix gt= F= prefix lt= F= prefixgt F= prefix lt )
prin(F ) pchar(SA)
pchar(SP)shy
runctor(P F MaxN)
prin(F ()
011 is MaxN - 1 pout(SNl P MaxN)
print) )
pout(S 0 P M3xN) - 1
arg(~bxN P Argu)
pchlr(SArgu )
pout(S N P MaxN shy
Nl is MaxN - N
arg(Nl P Argu)
pchar(SArgu
prin( )
N2 is N - 1
pout(S N2 P ~13xN)
Comparing numbers in numerical quantifiers
num(XN) shy
number(X I)
cnum(N 1) ~
cnumlaquo=01 lt=I- N gt=I
cnumlaquo=J lt I) - N gt=1-1
cnumlaquo=NIJ) - N gt=J 1
cnumlaquo=N J)- integer(I) N gt=I~
cnum(gt=N gt=1) - N lt=1
cnum(gt=N gt I) - N lt=1+ 1 cnum(gt=NIJ) - N lt=1
cnum(gt=N lt=1)- N lt=1
cnum(gt=N lt I) - N lt=1 L cnum(gt=N 1)- integer(I) N lt=1
cnum( lt N lt 1)- N gt=1 L
38
cnum( lt N lt=1) - N gt I cnum( lt NLJ) - N gt J
cnum( lt N 1)- integer(I) N gt 1
cnum(gt N gt I) - N lt=1 cnumlgt i gt=1) - N lt I
cnum(gt N lt=1) - N lt=0
cnum(gt N lt I) - N lt=0
cnum(gt iIJ) - N lt I cnum(gt N 1)- integer(I) N lt I
cnum(~LN lt=1) - M=I N gt= I l
cnum(~LN lt I) - M=l N gt= I-I
cnum(~LNLJ) - M lt =1 N gt = J
cnum(~1N 1)- integer(I) M lt= I N gt= I
cnum(- N) - integer(N)
Comparing selectors
sel(X = Y) shyX= Y
sel(X I=Y) shy(X I=Y X lt Y Xgt Y)
sel(X gt Y) shyXgt Y
sel(X lt Y) shyXlt Y
selX gt=Y) shy(X gt=Y X= Y Xgt Y)
se(X lt=Y) shy
(X lt=Y
X= Y
X lt Y)
csel(infix = infix =)
39
csel(infix = infix = csel(infix = infix gt)
csel(infix = infix lt) csel(infix gt infix gt) cseJ(infix lt infix lt) csel(infix gt= infix gt=) csel(infix gt= infix gt csel(infix gt= infix =)
csellinfix lt= infix lt=) csel(infix lt= infix lt) csel(infix lt= infix =)
Finding solutions
sol(X v Y) -
(( notetra(X) eon(X) ( sol(Y) )
( c1ause(P v Q R) not(cketra(P v Q))
dis(P v Q X v Y R) ~ )
( A lt=gt B equival(A lt=gt B X v Y) ~ I) sol(X) - ~ notetra(X) eon(X)
so~(X) - notetra(X)
( con (X)
( clause(P v Q R) not(ekctra(P v Q)) dis(P v Q X R) I)
cketra(P v Q) -
eketra(P) eketra(Q) eketra(F(I J)) shy
selec(F(I J))
c1ause(contradiction(sel(F(IJ))) _I
eketra(number(W I)) -
clause(cootradietion(num(Wl)) - eketr(P) shy
clause(contradiction(P) - 1
notctra(P) shy
not( e lause( con tradiction(P) _))
40
Searching (or disjunctions
dis(P v Q X v Y R) - dis(P X v Y R)
dis(Q X v Y R) con(R)
dis(P v Q X R) -
dis(P X R) dis(Q X R) con(R
dis(P X v Y R) - clause(contradicton(Pl J 1
dis(F(I J) sel(G(I J)) v Y R) - csel(G Fl dis(number(WI) num(W N v Y R) - cnum(N I)
dis(P P v Y R) -
dis(P X v Y R) - dis(P Y R)
dis(F(I J) seJ(G(IJ)) R) - csel(G F)
dis(number(WI) num(WN) R) - cnum(N I) dis(P P R) - 1
dis(FJ J X R) shy
( ckctra(F(IJ) cbeckeq(seJ(F(IJ))) )
dis(number(W Il X R) - ( ckctra(number(WI)) cbeckeq(num(WI)) )
dis(P X R) shy( ckctra(P) cbeckeq(P) ) 1
cbeckeq(P) shy
(( A lt=gt so2(contradiction(P))
bagof(A A [jj) ) ( so2(contradiction(P)) lt=gt B
bagof(B B Uj) ))
ckeq(A) shy
( so2(A) lt=gt B B lt=gt so2(A) ) bagof(B B UJ)
con((P Q)) -
clause(P R) con(R) con(Q) con(true) -
con(contradiction(P)) - clause(contradiction(P) J
con(cause(X Y)) - cause(X Y)
con(sel(X)) - sel(X)
con(num(X Y)) - num(X Y) con(P)- (( dause(P R) (con(R) ckeq(R)))
colJectin(P) )
collectin(P) shy
bagof(S (c1ause(P S) S = true) [L LIJ )
mkcon(L Ll L)
bagor(l (L2 ) UJ) L
mkcon((A AI) (B B1) (sol(A v B) e D)) -
mkcon(A B1 e) mkcon(A1 (B Bl) D)
mkcon(A (B B1) (sol(A v B) e)) -
mkcon(A Bl e)
mkcon((A AI) B (sol(A v B) e)) middot1
mkcon(Al B e)
mkcon(A B sol(A vB))
Searching ror equivalences
equival(A lt=gt B X v Y) - 1 ( equival(A lt=gt B X) equival(A lt=gt B Y) )
equival(s02(A) lt=gt 502(B) A) - clause(B _I equival(s02(B) lt=gt 502(A) A) c1ause(B _I
Top level or inrerence mechanism
goo((s02(whatnum) P)) -
getatm(P Xl
bagor(number(X Y) ( P so2(number(X Y)) ) A )
count1(A 00 L R) nl
bagor(X P B )
count2(B L R Ll Rl) nJ print()
(( LI = 0 Rl = 0 print(THE ANSWER IS ) nl
(( Ll = Rl prin(-Jumber or ) prn(P) print(is Ll) )
( Rlgt20000 prin(Number or I prn(P) print(is LI or more) )
42
( prin(Number of ) pfn(P) print( is from Ll to Rl) )) )
( print(THE ANSWER IS NO I )) print()
goo(X) shy
(( bagof(X X L) L = [I nl print()
print(THE ANSWER IS YES) nl wout(L) print() )
( equiv(X L) nl print()
print(THE ANSWER IS YES) nl wout(L) print(-) )
( c1ause(inpt(A ==gt B) _I ( impli(A B Z) impli(B A Z) ) print(l~Hl)
printTHE ANSWER IS YES) nl print(Z) print(Hj~(fH~) ))
goo(X) print( Hg)
print(THE ANSWER IS NO ) print( lH~lH~gg9l9lmiddotmiddot~Q(gmiddot)
00 Semhing for implications in equiV3lent relations
impli( B Z) shyt-ell( z1) prin(templ() pchn(S A lt=gt B) print()) close ( zl) consult(zl) templ(Z)
unload zl Z
Searching for equivalence
equiv (X L)
(( X lt=gt Y
equ(Y YI)t bagof(Y Yl L) L = [j )
(Y lt=gt X equ(Y YI) bagof(Y Yl L) L = [J )
( X = F(New)
clause(~ew T) makeup(T Tl)
(( Tl lt=gt B
equ(B Bl) bagof(Bl Bl M) M = [j L=[Newl )
(A lt=gt TI
equ(A AI) bagof(Al AI M) M = 1] L=INewj )) ))
makeup((A B) (AI Bl)) -
makeup(A A1) makeup(B BI)
makeup(A so2(A))
equ((A B) (AI BI)) -
equ(A AI) equ(B Bl)
equ(sol(X v Y) sol(XI v Yl)) -
equ(X XI) equ(Y YI)
equ(so2(X) so2(XI)) -
equ(X XI)
equ(contradiction(X) clJuse(contradiction(X) X) ) -
equ(X X)
Counting numbers
getatm((A B) X) -
( getatm(A X) getatm(B X) )
getatm(so2(F(X)) X) -
getatm(so2(X) X) - atom(X)
countl([J L R L R) -
countl([number(X Y)IT] L R L2 R2) shy
(( Y = (gt=~) LI is L + N Rl is R + 20001 l )
( Y = (gt N) LI is L+ N+ 1 RI is R + 20002 )
(Y == laquo=~) LI is L + 1 Rl is R + N )
(Y = laquo N) LI is L + 1 RI is R+N-I)
(Y == IJ LI is L + I Rl is R + J ) ( Y == N L1 is L + N RI is R + N ))
count1(T LI R 1 L2 R2)
count2(fJ L R L R) - 1
count2([XITJ L R L2 R2) shy
name(X Xl)
(( Xl = sknj LI is L Rl is R )
44
( Xl = Iskmj L1 is L + 1 RI is R + ZOOO1) ( LI is L + I RI is R + I ))
count2(T LI RI L2 R2)
pfn((A B)) - pfn(A) prn(B)
pCn(so2(F(X))) - prin(F )
prn(so2(X)) - atom(X) prin(X ) prn (so2(X))
Printing result
wout([XlJ - prt(X) nl woutf[xIY]) - prt(X) nl nl wout(Y)
prt(e(A B)) -
prt(A) prinr 8 ) prt(ltE) prt(eA) - prt(A)
prt(c(A EJ) - prin() prt(A) prine ) prt(B) prin(T)
prt(c A) - prt(A) prt((A E)) - ~
prt(A) nl prt(E) prt(sol(X v Y)) - ~
prt(X) prinC v) prt(Y) prt(A lt=gt B) -
prt(e A) prinC lt=gt ) prt(e B) prt(sol(X)) - prt(X)
prt(so2(X)) - prt(X
prt(c1ause(X Y)) - prt(X)
prt(contradiction(X)) - prin(contradiction() prt(cX) prinr))middot prt(num(XY)) - prin(number(X Y)) prt(sel(X)) - prin(X) prt(X v Y) - prt(X) prin( v) prt(Y) prt(X) prin(X)
Handling conditional queries
condi((Y Xl) shy
assertcon(X) Y
45
retractcon(X)
condi((B A))
retractcon(A) fail
assertcon((A B)) 1
assertcon(A) assertcon(B)
assertcon(A) asserta(A)
retrac teon ((A B)) 1
retracteon(A) retractcon (B)
retraetcon(A) - retract(A)
BIBLIOGRAPHIC DATA SHEET
Report No UIUCDS-F-84-928
3 Recipients Accession No
4 T ide and Subt ltle
An Annotated Predicate Calculus Inference System (APCIS)
S Report Date
November 1984 6
7 Author(s)
Kah-Eng Pua 8 Performing Organization Rept
No
9 Performing Organization Name and Address
Department of Computer Science University of Illinois Urbana IL
10 ProjectTaskWork Unit No
11 Contract Grant No NSF DCR 84-06081 ONR N00014-82-K-0186
12 Sponsoring Organization Name and Address
National Science Foundation Washington DC
13 Type of Report amp Period Covered
14
15 Supplementary Notes
16 Abstracts
This paper describes a deductive inference system called APCIS (Annotated Predicate Calculus Inference System) APCIS is able to carry out inferences from expressions involving numerical quantifiers selectors disjunctions of non-negated terms negated terms disjunctions of negated terms equivalences and exceptions It is also able to count the numbers of occurrence of a given simple term or a conjunction of terms The design of contradiction and the treatment of the disjunction of non-negated terms allow APCIS to accept Horn clauses as well as non-Horn clauses and to carry out inferences from them This feature makes APCIS more general than Prolog
17 Key lords and Document Analysis 170 Descriptors
APC (Annotated Predicate Calculus) APCIS (Annotated Predicate Calculus Inference System) Horn Clause Numerical Quantifier Prolog Selector
17b IdentifiersOpen-Ended Terms
17c COSATI FieldGroup
18 Availability Statement 19 Security Class (This
Re~f~~IA~SIF IFf)
21 ~o of Pages
49 211 ecurity Class (This
PageUNCLASSIFIED
22 Price
FOA NTIS n (10middot70 usco-oc 40329-
5
in the last step of translation
In the last step of the APe translator all input queries (ie expressions entered via
query-translation mode or query mode) are dealt with by the following six predicates prques pi
plett peont pehar and pout The task of prques pi plett and peont is to arrange each
input query in desired order whereas pehar and pout will print out each atomic formula
character by character For illustration purposes consider the following five APe expressions
1 all( X man(X) ==gt mortal(X)
2 exists( X horse(X) v dog(X) )
3 - ( exists( X horse(X) amp dog(X))
4 all( X be_shouted_at(X) amp no_response(X) == gt deaf(X) v dead(X) )
5 exists( 2 X box(X) )
H the above five APe expressions are typed to Prolog via assertion mode or assertionshy
translation mode they will be translated to the corresponding Prolog expressions
la
mortal(XI) shy
man(Xl)
2a
horse(skml) v dog(skml)
3a
contradiction(( horse(XI) dog(Xl) )) shy
horse(Xl)
dog(XI)
4a
deaf(Xl) v dead(Xl) shy
be_shouted_at(X I)
no_response(X1)
Sa
box(sknl)
number(sknl2)
The above live translated expressions ( ie la through Sa ) will be printed on the
terminal and loaded to Prolog if assertion mode is used they will be printed on the terminal but
not loaded to Prolog if assertion-translation mode is invoked
Now if the original APC expressions ( ie 1 through 5 ) are typed to Prolog via query
mode or query-translation mode the corresponding questions will be translated into the following
queries
lb
goo(( condi(( mortal(Xl) man(Xl))) ))
b
goo(( soil horse(Xl) v dog(XI)) ))
3b
goo(( c1ause( contradiction(( horse(XI) dog(Xl) )) _) ))
4b
goo(( conditt deaf(Xl) v dead(Xl) (be_shouted_at(XI) no_response(Xl)) )) ))
5b
amp00(( so2( box(XI) ) s02( num(XI 2 )) ))
The above five translated queries ( ie Ib through 5b ) will be printed on the terminal
and loaded to Prolog if query mode is used they will be printed on the terminal but not loaded to
Prolog if query-translation mode is invoked
In the above queries goo 801 and 802 each forms a part of the inference mechanism of
APCIS goo occupies the top level of the inference mechanism whereas 801 and 802 are at the
1
next level 102 will take care of the searching of simple terms and 101 will deal with the
disjunctions of non-negated terms in the database We will come back to them in Section 4
At the first glance one may feel that the above translated Queries are Quite complicated
However a closer examination will reveal that they are not so Queries lb 3b and 4b can each be
categorized as a conditional query which is a distinct feature of APCIS wherels queries 2b and
5b lre asking simple facts in the database
To handle conditional queries we consider two cases First if the queries involve a
special clause contradition we invoke the built-in function el3ule(X Y) which will look for the
desired contradiction clause in the database Second if the queries do not involve the clause
contradiction we activate a defined Prolog predicate condi to take care of the necessary
searching (To avoid confusion the reader is urged to compare expressions started with the same
number in the above three sets of example)
To handle a query which asks a simple fact we surround each disjunction of terms with
the functor sol as in the example 2b or crown each simple term with the functor 802 as in the
example 5b
32 TranslatIon of Negated Term And Disjunction of Negated Terms
One feature of APCIS is its ability to handle input expressions consisting of only negated
term or a disjunction of negated terms in the forms
or
2 -(AI) v ~(A2) v v ~(An)
To handle the above two forms a special clause with clause head contradiction is
created This special clause head has only one argument which is either a term or a set of terms
grouped together in the form
8
(AI A2 An)
The right-hand side of the clause contradiction is exactly same as the argument in the clause
head For example the above two forms involving negated terms will be translated into the
corresponding forms as follows
1 contradiction( A ) shy
A
2 contradiction(( AI A2 An )) shy
AI A2 An
The design of the clause with clause head contradiction will greatly enhance the inference power
of APCIS (see the example in Section 44)
33 Translation ot Disjunction ot Non-negated Terms
Another feature of APCIS is its ability to handle input expressions involving a
disjunction of non-negated terms in the forms
1 Al v A2 v v An
or
2 Bl amp 32 amp amp Bm ==gt Al v A2 v v An
Unlike Prolog which accepts only Horn clauses APCJS will accept Horn clauses as well
as non-Horn clauses which take the above two forms The inference from non-Horn clauses is
made possible by the two defined predicates sol lnd s02 discussed in Section 42 and Section 43
respectively (see also the example in Section 44) In the APC translator the above two forms are
transbted into the corresponding forms as follows
1 Al v A2 v v An
2 Al v A2 v v An shy
g
Bl B2 Bm
34 Futher Transformation of Exceptions and Equivalences
To provide some backgrounds for the discussion of the further transformation of
exception and equivalence relations we will lirst reproduce the three goals in the Step 2 of the
APe translator discussed in Section 32 of [31
First expressions involving implication or the form A ==gt B will be transformed to
Second expressions with exception symbol or the form A - B will be changed to the
form ( A lt=gt -(B) ) amp ( -(A) lt=gt B)
Tbird expressions with equivalence symbol of the form -(A) lt=gt B or of the form
A lt=gt -(B) will also be converted to ( A lt=gt -(B) ) amp ( -(A) lt=gt B ) since tbere are
logically identical to exception relations Also expressions with equivalence symbol of the form
A lt=gt B or -(A) lt=gt -(B) will remain the same
After the Step] of the APe translator both sides of any transformed expression with
lt = gt symbol will be treated separately as if they are two independent expressions In the
Step 10 of the APe translator each side of lt=gt will again be treated separately and
transformed into a form similar to an transformed input query (see Section 31) Two examples
are given below
1 state(on) lt=gt -( state(olJ) )
2 all( 1 bot(l) amp humid(l) - winter(I) )
They will be transformed in the Step 2 or the APe translator into
1
(state(on) lt=gt -( state(off) ) ) amp ( -( state(on) ) lt=gt state(olJ) )
2
10
( hot(l) amp humid(l lt=gt -(winter(l)) ) amp
( -( hot(l) amp humid(l)) lt=gt winter(I)
In Step la they will again be transformed to
1
so2( state(on) ) lt=gt so2( contradiction( state(oH) ) )
so2( contradiction( state(on) ) ) lt=gt so2( state(oH) )
2
( s02(hot(XI)) so2(humid(XI))) lt=gt so2( contradiction( winter(Xl ))
so2( contradiction(( bot(Xl) humid(Xl) )) ) lt= gt so2( winter(XI) )
There are two advantages in the treatment of exception and equivalence symbols in this
way First it will prevent Prolog program from going into an infinite loop which is difficult to
avoid if equivalent relation such as A lt=gt B is transformed into the logically equivalent form
( A ==gt B) amp ( B ==gt A) Second by maintaining both sides of lt=gt symbol in
query form the searching on either side caD be done more easily and efficiently since the form
is already processed and does not need any further transformation
Inference Mechanism
As mentioned at the end of Section 31 goo sol and s02 each forms a part of the
inference mechanism of APCIS with goo occupying the top level and 80) and 802 the second
level In addition to these countl count2 equlv and impll are also at the second level of the
inference mechanism We will go over all of them in the following sections
I goo
goo is essentially the starting point of the inference Whenever a translated query is
loaded to Prolog system from temp-fie goo will go through one or more of the following steps in
11
sequence
G 1 Check if the query asks for the numbers of occurrence of certain term(s) It so then
pass It to eountl and eount2 else go to G2
G2 The query will be passed down to sol or s02 (or both) to check i( any assertion in the
database can satisfy the query It the answer is positive then the query succeeds else
go to G3
G3 The query will be passed to equlv to carry out further searching It the searching is a
success then the query will be closed with a success else go to G4
G4 It the query is in the form A ==gt B then it will be passed to Impli It Impll
succeeds then done else the query will be closed with a (ailure
42 sol
801 and 802 together with dis and eon form the most complicated part of the APCIS
iorerence mechanism In this and the next section we will look at sol and s02 dis and eon will
be discussed in Section 44 We will close Section 44 with an example that illustrates the
materials presented in Section 42 through Section 44
sol is at the second level of the inference mechanism It will deal with any disjunction of
non-negated terms For any disjunction passed to it it will go through one or more of the
following steps in sequence
S1 Check if any term In the disjunction can be satisfied by any term or clause in the
database without contradiction It so then done else go to S2
S2 Pass the disjunction together with another disjunction (and its tlil) picked up from
the database to dis It dis succeeds then done else go to S3
S3 Pass the disjunction down to equlval which will check if any term in the disjunction
matches either side of any equivalence relation in the database It such a match is
found then check if the other side of the equivalence C3n be satisfied It so then done
else the goal fails
43 s02
s02 is also at the second level of the inference mechanism It will take care of all the
simple terms in the transl1ted query The following is the sequence that s02 wiII follow in
searching
S1 Check if the term passed to it caD be s3tisfied by any term or clause in the d3tabase
without contradiction It so then done else go to S2
S2 Pass the term together with a disjunction of terms (and its tail) picked up from the
database to dis If dis succeeds then done else the goal fails
44 dis and con
dis has three arguments In the first two clauses of dIs the first argument P v Q is
found in the database using the builtmiddotin functiol clause and the third argument R is the tair of
the term or the clause P v Q If P v Q is not a clause but a term R will be instantiated to trUE
The second 3rgument comes from either lIol or 802 and thus takes the form of either X v Y (a
disjunction of terms) or T (3 simple term)
All the clauses of dis together with con will perform the searching as exemplified in the
following algorithm (we will keep the notationsin this section)
01 Check if every term in P v Q is in X v Y It so then go to 03 else go to D2
02 For any term (in P v Q) which is not in X v Y or does not match T perform the
following tests
a Check if the term (in P v Q) has already been negated in the datab3Se (ie check if
the contradiction of the term exists in the d3tabase) If so then repeat D2 for other
terms not found in X v Y or not matching T else go to b
13
b Check if the contradiction of the term matches either side of any equivalence
relation in the database If such a match is found then check if the other side of the
equivalence can be satisfied If so then repeat O~ for other terms not found in X v Y
or not matching T else the goal fails
It all the terms (in P v Q) which are not in X v Y or do not match T survive either one
of the above two tests then go to 03
03 This step is essentially done by eon whose goal is to satisfy the tail R of P v Q It
con succeeds then done else the search fails
To close this section we will give an example to illustrate what we have covered In
Section 42 through Section 44
Example Assume that we already haye the following expressions in the database
horse(skml) v dog(skmI)
contradiction(( dog(XI) ))shy
dog(XI)
query goo(( soZ horse(X)) ))
This query will be passed to 802 which will check it the term horse() can be satisfied iu Step S 1
of Section 43 It is a failure So we now go to Step S2 In this step we pick up the disjunction
horse(~kml) v dog(skml) (and its tail true) in the datab3Se and pass it together with the term
horse(X) to dis We are now in Step 01 of Section 44 In this step we find that dog(skml) does
not match horse(X) So we have to go to Step 02 In Step 023 We find that the term dog(skml)
has already been negated (the second expression in the database) So we go to next step 03 Since
the tail of the disjuDction horse(skml) v dog(skml) is the atom true con is satisfied and the
query succeeds
45 countl and count2
countl and count2 are responsible for the counting of tbe numbers of occurrence of a
given simple term or a conjunction of terms They are activated by input queries in the form
q( exists( X whatnum amp P) )
where whatnum is the l~bel for activating the counting of the numbers of occurrence of P which
can either be a term or a conjunction of terms
countl will count the number of term(s) which will satisfy P and associate(s) with
numerical quantification(s Two counters are set to update the lower and upper boundary or the
scope or the numfrical quantifications encountered
The contents of the two counters are then passed to count2 which is responsible for the
counting or the following three types of term First term(s) which will satisfy P and associate(s)
with existential quantification(s Second term(s) which will satisfy P and has(have) Prolog atom
as its(thfir) argument(s) Third term(s) that will satisfy P and itself(themselves) is(are) Prolog
atom(s )
46 equiv
equlv will be activated only after sol and B02 have failed The first two goals of equlv
are similar to that of Step S3 in Section 42 and Step D2b in Section 44 The third goal or equiv
makes possible the inference on either side of any equivalent relation For example if we type the
following three expressions to Prolog in assertion mode
l all( X hot(X) amp humidX) - winter(X)
2 all( X hot(X) amp bumid(X) ==gt unpresent(X))
3 - ( exists( X winter(X) ) )
and then ask APCIS in query mode
q( cxists( X unpresent(X) ) )
15
APCIS with the aid of equlv will be able to answer yes to this query
41 lmpll
lmpll can be considered as the last attempt that APCIS would make to satisfy a
query It is activated only after equlv has failed It will first check if the query is conditional If
so it will convert the implication symbol to equivalence symbol and search if such an equivalent
relation can be found in the database If so a success Otherwise a failure
5 More on the Inference Mechanism
Having looked at all the subparts at the top two levels of the inference mechanism we
are ready to look at other subparts at lower levels
51 num and cnum
One distinct fe3ture or APCIS is its ability to deal with numerical quantifications As
mentioned in Section 31 input queries and assertions will undergo different transformations in
the last step (Step 10) of translation This also holds true for expressions involving numerical
quantifications Consider the following expression
exists( 6 X horse(X) )
If it is entered to Prolog via assertion mode we will after going through all the steps of
translation have the rollowing entered to the database
horse(sk n I
number(sknl6)
Now if we want to ask Are there more than five horses 7 and type in
q( exists( gt5 X horse(X) ) )
1amp
APCIS will translate the question and enter to Prolog the following query
goo(( s02( horse(X) ) s02( num( X gt5 )) ))
Note that the term number(slml 6) in the database and the term num(X gt S) in the query are
different predicates and this difference is exactly where the power of the clause num(X N)
defined in APCIS comes from When the clause num(X N) in APCIS is activated it will search
through the database to see if there is any term of the form number(X I) whose first argument
matches the first argument of num(X Y) in the query It a match is found the second arguments
of both num(X Y) in the query and number(ltI) in the database will be passed to cnum in
APCIS
The job of cnum is to compare the numerical messages carried by the second
argument or the term rlum(X Y) in the query and the second argument of the term rlumber(X I)
in the database to see if they match with each other according to the rules defined in cnum
While there are 25 rules for such matching purposes the idea is simple
Imagine that the second argument Y of the term num(X Y) in the query
and the second argument I of the term num()( I) in the database each occupies a
place in an integer line (Le the integer line in mathematics) To have a match
the domain covered by Y should contain the domain covered by L
As an example the answer to the above query is positive since the domain of gt5
contains the domain or 6
Before closing this section we will bring out a speciaJ translation aspect of expressions
involving numbers by an example We first type to APCIS the Collowing expressions in assertion
mode
1 aU(X all(Y father(X Y) amp number(Y gt6) ==gt has_manY3hildren(X) ))
2 exists(X exists( 12 Y Cather(X Y) ) )
11
After going tbrougb all tbe translation steps tbe Collowing two expressions will be entered to tbe
database
I
bas_many_cbildren( Xl ) shy
Cather( Xl X2 )
num( X2 gt6 )
2
Catber( sk m1 sk n2 )
number( skn2 12 )
lotice that whenev(gtr a term with Cunctor number appears at the rigbt-band side oC a Prolog
clause its Cunctor will be cbanged to num automatically This treatment will greatly cnbance tbe
inference power of the clause sbown in l above For instance iC we now ask tbe question
q( exists( X bas_many_children(X) ) )
The right hand side oC the clause l will match the two terms in 2 and tbe query succeeds
52 Bel and cael
A special feature of APe is tbat all predicates tbat express relations = = gt
gt= lt and lt= can be expressed explicitly using infix notations as relational statements
called selectors To handle selectors we defined Bel in APCIS
Every expression involving selectors will undergo different translations in assertion mode
and query mode For example the assertion
a( exists( [X Y] box (X) amp box(Y) amp (weigh t(X) gt weight(Y) ) ) )
will be translated into the following three terms and entered to tbe database
box( skml )
box( skm2 )
18
weight( skm 1 ) gt weight( skm2 )
Now it we want to ask Is it true that there exists two boxes of different weights and type in
q( exists( [X Yl box(X) amp box(Y) amp ( weight(X) = weight(Y) ) ) )
The question will be transformed to the following query and entered to Prolog
goo(( so( box(XI) ) s02( box(X2) ) so2( sel( weightXI) = weight(X2) )) ))
Note that the selector in the above query is surrounded by the functor set When any clause or
8el in APCIS is activated it will search through the database to see it there is any selector whose
two arguments (left and right side or any selector symbol) match the two arguments of the
selector in the query At the same time 8el will check iC the selector symbols (may be different) or
the two different selectors (one in the query and one in the database) satisfy the rules defined in
sel There are 12 matching rules defined in sel All oC them ~re straightforward and will not be
discussed here An example will be enough to explain how 8el works
Consider the execution of the above transformed query The first two terms in the query
are satisfied by the first two terms in the database and Xl and X2 are instantiated to skml and
skm2 respectively The third term of the query will be passed to eel (of APCIS) which finds a
match on each side of the two selectors (one in the query and one in the database) At the same
time the two different selector symbols gt and = are found to satisfy one of the rules in
8el As a result the query succeeds
To enhance the inference power of clauses involving selectors all the selectors appearing
on the rightmiddothand side oC any clause will be surrounded by a functor set The idea is similar to
that in the last part of the previous section
c8el is exactly the same as 8el functionally It provides a convenient way to compare
selectors when dis is being executed
19
8 Printing Result
Whenever a goal is successfully executed APCIS will not only response with a yes but
also print out the matched terms or clauses in the database This is made possible by the built-in
function bagor and the two predicates wout and prt defined in APCIS
7 Summary
In this paper a description of a deductive inference system called APCIS (Annotated
Predicate Calculus Inference System) has been provided APCIS is able to carry out inferences
from expressions involving numerical quantifiers selectors disjunctions of non-negated terms
negated terms disjunctions of negated terms equivalences and exceptions It is also able to count
the numbers of occurrence of a given simple term or a conjunction of terms
The main idea of APCIS is that each input APC expression is first passed to a
preprocessor ( ie APC translator ) which dissolves and transforms each APC expression into
Prolog expression(s) which will then be loaded to Prolog system The user bas to specify whether
each input expression is to be entered as an assertion or as a query by invoking either assertion
mode or query mode respectively Each assertion or query will undergo different transformations in
the preprocessor The different treatment of assertion or query not only allows a full uS1ge of the
Prolog inference mechanism but also makes possible a higher level of inexact pattern matching
exemplified by the examples in Section 51 and Section 52 where the four predicates num
cnum sel and csel are discussed This higher level of pattern matching increases the inference
power of APCIS greatly
The design of contradiction and the treatment of the disjunction of non-negated terms
allow APCIS to accept non-Horn clauses and to carry out inference from them This feature
makes APCIS more general than Prolog
20
While APCIS performs very well in many sets of arguments provided by the author it is
still too early to jump to conclusion that it can perform equally well in all types of problems In
any event the expressiveness of APC has greatly been retained in the present version of APCIS
and moreover some design ideas or APCIS mentioned in this paper are not restricted to APCIS
- they may be carried over to learning programs with narrower scopes
21
References
[1] W F Clocksin and C S Mellish Programming In Prolog Springermiddot Verlag Berlin Hpoundidelberg 1981
[2] R S Michalski A Theory and Methodology of Inductive Learning Chpt 4 Machine L earning Tioga Publishing Co Palo Alto CaliJornia 1989
[3] K-E Pua Translating Annotated Predicate Calculu8 to Prolog ISG Report 84middot1 UlUCDCSmiddotFmiddot918 University oj Illinois Urbana IL June 1984
22
Appendix A
APCIS Users Manual
1 Get Started
Users are urged to follow the steps depicted below
1 Get the PROLOG interpreter by typing
alias prolog mntb2sammutsammutprologprolog (Vax A)
or
alias prolog mntb2sammutsammutbinprolog (Vax B)
2 Load apc and infer by typing
prolog apc infer
When large APC expressions are expected we can increase the stlck by typingI
prolog -snnnn ape infer
where ns denote the number of stacks in decimal
3 When the wording LSW - PROLOG appears on the terminal we are reldy to interact
with APCIS The four modes by which we can invoke APCIS are summarized below
a Assert ion-Translation Mode
ta(X)
b Query-Translation Mode
tq(X)
c Assertion Mode
a(X
d Query Mode
q(X)
23
where Xs are APC expressions
2 Notations Used in APCIS
Below is a summary or notations used in APCIS
a Logical operators
amp
v
==gt
lt=gt
-
negation
conjunction
disjunction
implication
equivalence
exception
b Binary relation symbols in selectors
-
=
gt=
lt=
gt
lt
equal
not equal
greater or equal
smaller or equ al
greater
smaller
c Relational operators in numerical quantifiers
lt less than
lt= less than or equal
gt greater than
gt= greater than or equal
d BinlTY operator in numerical quantifier
range
e Universal quantifier
all(X p(X))
f Existential quantifier
exists(X p(X))
g Numerical quantifier
exists(I X p(X))
where p(X) is a formula
where X is a variable or a Jist of variables or the
form [HI~rj and p(X) a formula
where I repersents expression involving integer(s)
and operator(s) in c or d above and p(X) a formula
25
Appendix B
APCIS Program Listings
------------------------------- Program Name APCIS - Part 1 APC Translator
-------------------------------
op(3OO fx -)1
op(500 xfy amp)
oPt 500 xfy v)
op(600 xfx )
op(700 fx [gt= lt= gt lt ]) op(400 xfy [= gt= lt= gt lt ])1 op(900 xfy gt lt=gt -])1
steps(X Xg) shy
numbervars(X 1 J Step 1 change variables to iis
rmimp(X X) Step 2 conv(X X3) Step 3
rewrite(X3 X4) Step 4
negin(X4 X5) Step 5
dropexist(X5 X6 1]) Step 6
dropall(X6 X7) Step 7
distrib(X7 X8) Step 8 clausiCy(X8 X9 [J) Step 9
ta(X) shysteps(X Xg)
(( Xg = II nl
print( yes it is always true) )
( nl nl printcl(X9))) Step 10a
tq(X) shy
steps(X Xg)
prques(Xg)
28
Step 2 Removing implic3tions amp Transforming exceptions and equiv3lences
rmimpl( P - Q (PI lt=gt (QI) ) amp ((PI) lt=gt QI) ) -
rmimpl(P PI) rmimpl(Q QI)
rmimplnp) lt=gt Q (PI lt=gt -(QI)) amp nPI) lt=gt QI) ) - 1
rmimpl(P PI) rmimpJ(Q QI)
rmimpJ(P lt-gt -(Q) (PI lt=gt -(QI)) amp nPI) lt=gt QI) ) -
rmimpl(P PI) rmimpl(Q QI)
rmimpl( P lt=gt Q PI lt=gt QI ) - I
rmimpl(P PI) rmimpl(Q QI)
rmimpl( P ==gt Q -(PI) v QI ) - I
rmimpl(P PI) rmimpl(Q QI)
rmimpl( all(X P) aI(X PI) ) - 1
rmimpl(P PI)
rmimpl( exists(X P) exists(X PI) ) -
rmimpl(P PI)
rmimpl( exists(I X P) exists(I X PI) ) -
rmimpl(P PI)
rmimpl( P amp Q PI amp Ql ) -
rmimpl(P PI) rmimpl(Q Ql)
rmimpl( P v Q PI v QI ) -
rmimpl(P PI) rmimpl(Q QI)
rmimpl( -(p) -(PI) ) - I
rmimpl(p PI)
rmimpl( P P )
St~p 3 Converting numerical amp distinctive quantifiers
L Numerical quantifiers
examples of input forms
1 exists(gt= i X pIX)) where i is an integer
2 exists(i X pIX)) where i is an integer
3 exists(i j X pIX)) where i j are integers and iltj
4 exists(il v i2 X pIX)) where is are integers
examples of output forms of this step
1 exists(X pIX) amp number(X gt= i) )
2 exists(X pIX) amp number(X i) ) 3 exists(X pIX) amp number(X ij) ) 4 exists(X pIX) amp number(X il v i2) )
II Distinctive quantifiers
27
example or input Corm
exists([XYL p(X Y))
example or output Corm or this step
exists(X exists(Y p(XY)) )
conv(P lt=gt Q PI lt=gt QI) - 1
conv(P PI) conv(Q QI)
conv(al1(X P) all(X PI)) -
conv(P PI)
conv(exists(HIT] P) R ) - conv(P PI) convert distinctive quantifier
convtdis(exists([HIT]PI) R)
conv( exists(I X P) exists(X PIamp number(X I) )) -
conv(P PI) convert numerical quantifier
conv(exists(X P) exists(X PI)) - 1
conv(P Pl)
conv(P amp Q PI amp QI) - 1
conv(P PI) conv(Q QI)
conv(P v Q PI v QI) - t conv(P PI) conv(Q QI)
convC(P) -(PI)) -
conv(P PI)
conv(P Pl
convtdis(existsl[XL P) exists(X P)) - atomic(X) convtdis(exists[XIYj Pl exists(X R)) shy
convtdis(exists(Y P) R)
Step 4 Rewriting compound predicates andor compound selectors
Outputs are smiple predicates andor simple selectors
rewrite(P lt=gt Q PI lt=gt QI) - t rewrite(P PI) rewrite(Q QI)
rewrite(all(X Pl all(X PI)) - 1 rewrite(P PI)
rewriteexists(X P) exists(X PI)) - I rewriteP PI)
rewrite(P amp Q PI amp QI) - rewrite(P P 1) rewrite( Q Q 1
rewrite(P v Q PI v QI) - 1
rewrite(P PI) rewrite(Q QI)
rewriteC(P) -(PI)) - I
28
rewrite(P PI) rewrite(F(A B) R) -
rewrite(A AI) rewrite(B BI) re(F(AI BI) R)
rewrite(F(A) R) -
rewrite(A AI) re(F(AI) H)
rewrite(F(A B C) R) -
rewrite(A AI) rewrite(B BI) rewrite(C CI) re(F(AI BI CI) R)
rewrite(F(A B C D) R) -
rewrite(A AI) rewrite(B Btl rewrite(C CI) rewrite(D DI) rc(F(AI BI CI Dl) H)
rewrite(PP)
re(F(A B v el (RI v R2) -
re(F(A Bl RIl re(F(A C) R2) reF(A B amp cl (RI amp R2)) -
re(F(A B) RI) re(F(A e) R2) re(F(A amp B C) (Rl amp R2)) -
re(F(A e) R 1) re(F(B C) R 2) re(F( v B el (R I v R2)) -
re(F(A el R I) reFB el R2) re(F(A amp Bl (R I amp R2)) -
re(F(A RI) re(F(BJH2) re(F(A v B) (R 1 v R2)) -
re(F(A) RI) re(F(B) R2)
re(F(A vB c Dl (RI v R2) -
re(F(A C D) RI) re(F(B C D) R2) re(F(A amp B C D) (RI amp R2)) -
re(F(A C D) Rll re(F(B C D) R2) re(F(A B v C D) (HI v R2)) -
re(F(A B D) RI) re(F(A C D) R2) re(F(A B amp C D) (HI amp R2)) -
re(F(A B D) RI) re(F(A C D) R2) re(F(A B C v D) (RI v R2)) -
re(F(A B C) R I) reF(A B D) R2) re(F(A B C amp D) (RI amp R2)) -
29
re(F(A B C) RI) re(F(A B D) RZ)
re(F(A v B e D E) (R I v R2)) -
re(F(A e D E) R I) re(F(B e D El R2) re(F(A amp B e D E) (RI amp RZ)) -
re(F(A e D El R 1) re(F(B e D E) R2) re(F(A B v e D E) (R I v R2)) -
re(F(A B D E) RI) re(F(A e D E) R2)
re(F(A B amp e D E) (RI amp R2)) -
re(F(A B D El RI) re(F(A e D E) RZ) re(F(A B e v D E) (R I v R2)) -
re(F(A B e El R 1) re(F(A B D E) RZ) re(F(A B e amp D E) (RI amp RZ)) -
re(F(A B e E) R I) re(F(A B D E) RZ)
re(F(A B e D vEl (RI v RZ)) - l
rc(F(A B C D) RI) re(F(A n e El RZ) re(F(A B e D amp El (RI amp RZ)) - ~
re(F(A B e D) RI) re(F(A B e El RZ)
re((A = B) (A = B)l-
re((A = Bl (A = 8)) -
retIA gt= BI (A gt= B)) -
re((A lt= B) (A lt= B)) -
re((A gt B) (A gt B))-
re((A lt Bl (A lt Bl)- re(A A)
Step) Bringing n(gation inwards
Degin(-(P) PI) - neg(P Pl)
negin(P lt=gt Q PI lt=gt Ql) - ~
negin(P PI) negiD(Q QI)
Degin(aU(X P) all(X PI)) - Degin(P PI) negin(exists(X P) exists(X PI))- negin(P PI) negin(P amp Q PI amp Ql) - Degin(P PI) negin(Q Ql)
Degin(P v Q PI v QI) - Degin(P PI) negin(Q QI) negin(P Pl
neg(-(P) PI) - negin(P PI)
neg(all(X P) exists(X PI)) - neg(P PI)
30
neg(exists(X P) all(X PI)) - neg(P PI)
neg(P amp Q PI v QI) - neg(P PI) neg(Q Ql)
neg(P v Q PI amp QI) - neg(P PI) neg(Q QI)
neg(P -(PH
Step 6 Dropping existnetial quanti6ers
dropexist(P lt=gt Q PI lt=gt QI Elerns) - dropexist(P PI Elerns) dropexist(Q QI Elerns)
dropexist(alJ(X P) all(XPI) Elerns)
dropexist(P PI [XIElernsJ)
dropexist(exists(X P amp nurnber(X Yraquo P2 Elerns) -
genfun(skn Newg) Fun = [NewgIElerns]
subst(FuD X P amp Dumber(X Y) PI)
dropexist(Pl P2 Elerns)
dropexist(exists(X P) PZ Elerns) -
genfun(skrn Newf) Fun = [NewfIElernsJ
subst(Fun X p PI)
dropex ist(P 1 P~ Elerns)
dropexist(P v Q PI v QI Elerns) - ~
dropexist(P PI Elerns) dropexist(Q Ql Elerns)
dropexist(P amp Q PI amp QI Elerns) - 1
dropexist(P Pl Elerns) dropexist(Q QI Elerns)
dropexist(P P _)
gen fun(R oot Newn arne) shy
getnurn(Root Nurn)
narne(Root Rootlist)
append(Rootlist[Nurnj Narnelist)
concat(Narnelist Newnarne)
getnurn(Root Nurn) shy
retract(currentnurn(Root Nurn 1 raquo
Nurn is Nurni + 1
asserta(currentnurn(Root Nurn))
getnurn(Root 1) - asserta(currentnurn(Root 1))
subst(New Old Val Val) - var(Val)
subst(New Old Old New) - 1 substNew Old Val Val) - atornic(Val)
31
subst(New Old Val Newval) shy
runctor(Val F N)
CUDctor(Newval F N)
subst_args(N New Old Val Newval)
subst_args(O J J - J J
subst_args(N New Old Val NewVal) shy
arg(N Val OldArg)
arg(N NewVal NewArg)
subst(New Old OldArg NewArg)
NI is N - I
subst_args(Nl New Old Val NewVal)
append([J L L) -
append([XILl] L2 [XIL3]) - append(Ll L2 L3)
Step - Dropping universal quantifiers
dropall(P lt=gt Q PI lt=gt QI)-
dropall(P PI) dropall(Q QI)
dropall(all(X P) PI) - ~ dropall(P PI)
dropall(P amp Q PI amp QI) -
dropall(P PI) dropall(Q QI)
dropall(P v Q PI v QI) -
dropall(P PI) dropall(Q QI)
dropall(P P)
Step 8 Distributing conjunctions over disjunctions
distrib(P lt=gt Q PI lt=gt Ql) - t distrib(P PI) distrib(Q QI)
distrib(P v Q R) -
distrib(P PI) distrib(Q QI)
distributing(PI v QI R)
distrib(P it Q PI it QI) -
distrib(P PI) distrib( Q QI)
distrib(P P)
distributing((P amp Q) v R PI amp QI) -
distrib(P v R PI) distrib(Q v R Ql)
32
distributing(P v (Q amp R) PI amp Ql) -
distrib(P v Q PI) distrib(P v R Ql)
distributing(P P)
Step 9 Packing each conjunction into clauses
c1ausify(P amp Q CI C2) -
clausiCy(P CI C3) c1ausify(Q C3 C2)
cbusiCy(P [d(A B)ICs] Cs) shy
inclause(P A [j B [I) 1
c1ausiry( C C)
inclause(P v Q A AI B B1) -
inc1ause(P A2 AI B2 Bl)
inclause(Q A A2 B B2)
inclausenp) A A B1 B) -
notin(P A) putin(P B B1)
inclause(P AI A B B) shy
notin(P Bl putin(P A AI)
notin(X [XU) - fail
notin(X [JLj) - notin(X L)
notin(X 1])
putin(X II [X]) - 1
putin(X [XILJ L) -
putin(X [YILJ [YILl]) - putin(X L Ll)
Step 1Oa Printing clauses
printcl([]) - nl nl
printcl(c1(AB)ICsj) - printcl(A Bl nl printcl(Cs)
printcl(L II) - printdis(IL) prinr)middot
printclHl L) - prin(contradiction(() printconl(rL)
print()) - ) printconj(rL) prinr )
printcl(Ll L2) shy
printdis(ILl) print( - ) printconj(rL2) prin()
printdis(S[Lj) - printcbar(SL)
33
printdis(S[LILs]) - printchu(SL) prin( v) printdis(SLs)
printconl(S[LI) - printchar(SL)
printconl(S[LILs]) - printchar(SL) prin( ) printconl(SLs)
printconj(S[L]) - tab(3) printchar(SL)
prin tconj( S [L IL sl) shy
tab(3) printchar(SL) print( ) printconj(SLs)
printchar(SP) shy
atomic(P)
name(P L)
L = [IT]
concat([XIT NewP)
prin(~ewP)
printchar(SP) shy
atomic(P)
prin(P)
printchar(SA lt= gt B) -
prin((l clausify(A AI [j) pl(eAl) prin())
print lt=gt )
prin(() cbusify(B Bl [I) pJ(eBl) prine))middot
printchar(rnumber(X N)) shy
prin(num() printchar(rx) prin( )
printchar(rN) prinC))
printchar(rF(A B)) shy
seJec(F(A B))
prinCsel() printchar(rA)
prin( F ) printchar(rB) prinC))
printchar(SF(A B)) shy
( selec(F(A B)) F = infix )
printchar(SA) prin( F ) printchar(SB)
printchar(SF(A)) shy
(F= prefix gt= F= prefix lt= F= prefixgt F= prefix lt )
prin(F ) printcbar(SA)
printchar(SP) shy
functor(P F MaxN)
prin(F ()
Nl is MaxN - 1
putout(S N 1 P MaxN)
34
prin())
putout(S 0 P MaxN) -
arg(~laxN P Argu)
prin tchar(SArgu)
putout(S N p MaxN) shy
Nt is MaxN - N arg(NI P Argu)
printcbar(SArgu )
prin( )
N2 is N - 1
putout(S N2 P MaxN)
selec(FA B)) shy
( F= infix = F= infix f= F= infix gt=
F= infix gt F= infix lt= F= infix lt )
35
----------------------------------Program Name APClS - Part 2 Inference Mechanism ---------------------------------- a(X) shy
steps(X X9)
(( X9 =[] nl
print( yes it is always true) )
( X9 =[cI(IJ[])] nl
print( no it is always false) )
( nl nl printel(X9) Step 1Oa
tell(temp_file) printel(X9) e1ose(temp_file) consult(temp_6Ie) ))
q(X) shy
asserta( in pt(X))
steps(X X9)
(( X9 = [] print(middot~H~~middot~t~)
print(THE AiSWER IS YES)
print( ilgIQlQl(~) )
( X9 = [e1([j [j)] Pr1nt ( OJ fi(i I~ iii Ij)middot(i)(i) fiyenQ)riiio(i)(ij)(i)fj)fiyen1li1il1li1il)__ gtw~ __~_~ _~~_ ~_-=~
print(THE ANSWER IS NO ) print() )
( teI1(temp_6Ie)
prques(X9) Step 1Ob
close(temp_file)
nl print(Let me think about it) nl
consult(temp_6Ie) ))
retrac t( in pt(X))
Step lOb Printing question
prques(lcl(A 8)1) - prin(goo(() pl(qA 8) print()))
prques([c1(A 8HCs]) - prin(goo(() pl(qA 8) print() pl(q Cs)
pl(e [c1(A 8)]) - pl(eA 8)
pl(q [c1(A 8)]) - pl(qA 8) print()))
pl(S [e1(A B)ICs]) - pl(SA B) prin( ) pl(S Cs)
38
pl(q [j L) - prin(c1ause(contradiction(() pcont(qL) prin())_))
pl(S [I L)- prin(so2(contradidion(() pcont(SL) print))))middot
pl(S [L] []) - prin(so2() pcbar(SL) prin())
pl(S L [J)- prinsol() plett(SL) print))
pl(S [L] LI) - prin(condi(() pchar(cL)
prin(() pcont(S Ll) prine))))
pl(S L Ll)- prin(c1ause() plert(cL)
prin(() pcont(S Ll) prine)))
plert(S[LJ) - pchar(SL)
plert(SjLILsj) - pcbar(SL) print v) pleCt(SLs)
pcont(S[L]) - pchar(SL)
pcont(S[LILsj) - pcbar(SL) prinr ) pcont(SLs)
pcbar(SP) shy
atomic(P)
name(PL)
( L = [IT] L = [5 k miT] L = [5 k niT] )
concat[XITj NewP)
prin(0JewP)
pchar(SP) shy
atomic(P)
prin(P) pchar(SA lt=gt B) -
prin(() dausify(A AI []) pl(eAI) prin())
prinr lt=gt ) prin(() dausify(B BI ]) pl(eB) print))
pchar(Snumber(X N)) shy
prin(num() pchar(SX) prin()
pchar(SN) prinr))
pcbar(SM N) - prin(M N)
pcbar(cF(A B)) shy
selec(F(A Braquo
pcbar(cA)
prine F ) pchar(cB) pchar(SF(A B)) shy
selec(F(A B))
prin(sel() pchar(SA)
print F ) pchar(SB) print)) I
31
pc har(SF(A)) shy
( F= prefix gt= F= prefix lt= F= prefixgt F= prefix lt )
prin(F ) pchar(SA)
pchar(SP)shy
runctor(P F MaxN)
prin(F ()
011 is MaxN - 1 pout(SNl P MaxN)
print) )
pout(S 0 P M3xN) - 1
arg(~bxN P Argu)
pchlr(SArgu )
pout(S N P MaxN shy
Nl is MaxN - N
arg(Nl P Argu)
pchar(SArgu
prin( )
N2 is N - 1
pout(S N2 P ~13xN)
Comparing numbers in numerical quantifiers
num(XN) shy
number(X I)
cnum(N 1) ~
cnumlaquo=01 lt=I- N gt=I
cnumlaquo=J lt I) - N gt=1-1
cnumlaquo=NIJ) - N gt=J 1
cnumlaquo=N J)- integer(I) N gt=I~
cnum(gt=N gt=1) - N lt=1
cnum(gt=N gt I) - N lt=1+ 1 cnum(gt=NIJ) - N lt=1
cnum(gt=N lt=1)- N lt=1
cnum(gt=N lt I) - N lt=1 L cnum(gt=N 1)- integer(I) N lt=1
cnum( lt N lt 1)- N gt=1 L
38
cnum( lt N lt=1) - N gt I cnum( lt NLJ) - N gt J
cnum( lt N 1)- integer(I) N gt 1
cnum(gt N gt I) - N lt=1 cnumlgt i gt=1) - N lt I
cnum(gt N lt=1) - N lt=0
cnum(gt N lt I) - N lt=0
cnum(gt iIJ) - N lt I cnum(gt N 1)- integer(I) N lt I
cnum(~LN lt=1) - M=I N gt= I l
cnum(~LN lt I) - M=l N gt= I-I
cnum(~LNLJ) - M lt =1 N gt = J
cnum(~1N 1)- integer(I) M lt= I N gt= I
cnum(- N) - integer(N)
Comparing selectors
sel(X = Y) shyX= Y
sel(X I=Y) shy(X I=Y X lt Y Xgt Y)
sel(X gt Y) shyXgt Y
sel(X lt Y) shyXlt Y
selX gt=Y) shy(X gt=Y X= Y Xgt Y)
se(X lt=Y) shy
(X lt=Y
X= Y
X lt Y)
csel(infix = infix =)
39
csel(infix = infix = csel(infix = infix gt)
csel(infix = infix lt) csel(infix gt infix gt) cseJ(infix lt infix lt) csel(infix gt= infix gt=) csel(infix gt= infix gt csel(infix gt= infix =)
csellinfix lt= infix lt=) csel(infix lt= infix lt) csel(infix lt= infix =)
Finding solutions
sol(X v Y) -
(( notetra(X) eon(X) ( sol(Y) )
( c1ause(P v Q R) not(cketra(P v Q))
dis(P v Q X v Y R) ~ )
( A lt=gt B equival(A lt=gt B X v Y) ~ I) sol(X) - ~ notetra(X) eon(X)
so~(X) - notetra(X)
( con (X)
( clause(P v Q R) not(ekctra(P v Q)) dis(P v Q X R) I)
cketra(P v Q) -
eketra(P) eketra(Q) eketra(F(I J)) shy
selec(F(I J))
c1ause(contradiction(sel(F(IJ))) _I
eketra(number(W I)) -
clause(cootradietion(num(Wl)) - eketr(P) shy
clause(contradiction(P) - 1
notctra(P) shy
not( e lause( con tradiction(P) _))
40
Searching (or disjunctions
dis(P v Q X v Y R) - dis(P X v Y R)
dis(Q X v Y R) con(R)
dis(P v Q X R) -
dis(P X R) dis(Q X R) con(R
dis(P X v Y R) - clause(contradicton(Pl J 1
dis(F(I J) sel(G(I J)) v Y R) - csel(G Fl dis(number(WI) num(W N v Y R) - cnum(N I)
dis(P P v Y R) -
dis(P X v Y R) - dis(P Y R)
dis(F(I J) seJ(G(IJ)) R) - csel(G F)
dis(number(WI) num(WN) R) - cnum(N I) dis(P P R) - 1
dis(FJ J X R) shy
( ckctra(F(IJ) cbeckeq(seJ(F(IJ))) )
dis(number(W Il X R) - ( ckctra(number(WI)) cbeckeq(num(WI)) )
dis(P X R) shy( ckctra(P) cbeckeq(P) ) 1
cbeckeq(P) shy
(( A lt=gt so2(contradiction(P))
bagof(A A [jj) ) ( so2(contradiction(P)) lt=gt B
bagof(B B Uj) ))
ckeq(A) shy
( so2(A) lt=gt B B lt=gt so2(A) ) bagof(B B UJ)
con((P Q)) -
clause(P R) con(R) con(Q) con(true) -
con(contradiction(P)) - clause(contradiction(P) J
con(cause(X Y)) - cause(X Y)
con(sel(X)) - sel(X)
con(num(X Y)) - num(X Y) con(P)- (( dause(P R) (con(R) ckeq(R)))
colJectin(P) )
collectin(P) shy
bagof(S (c1ause(P S) S = true) [L LIJ )
mkcon(L Ll L)
bagor(l (L2 ) UJ) L
mkcon((A AI) (B B1) (sol(A v B) e D)) -
mkcon(A B1 e) mkcon(A1 (B Bl) D)
mkcon(A (B B1) (sol(A v B) e)) -
mkcon(A Bl e)
mkcon((A AI) B (sol(A v B) e)) middot1
mkcon(Al B e)
mkcon(A B sol(A vB))
Searching ror equivalences
equival(A lt=gt B X v Y) - 1 ( equival(A lt=gt B X) equival(A lt=gt B Y) )
equival(s02(A) lt=gt 502(B) A) - clause(B _I equival(s02(B) lt=gt 502(A) A) c1ause(B _I
Top level or inrerence mechanism
goo((s02(whatnum) P)) -
getatm(P Xl
bagor(number(X Y) ( P so2(number(X Y)) ) A )
count1(A 00 L R) nl
bagor(X P B )
count2(B L R Ll Rl) nJ print()
(( LI = 0 Rl = 0 print(THE ANSWER IS ) nl
(( Ll = Rl prin(-Jumber or ) prn(P) print(is Ll) )
( Rlgt20000 prin(Number or I prn(P) print(is LI or more) )
42
( prin(Number of ) pfn(P) print( is from Ll to Rl) )) )
( print(THE ANSWER IS NO I )) print()
goo(X) shy
(( bagof(X X L) L = [I nl print()
print(THE ANSWER IS YES) nl wout(L) print() )
( equiv(X L) nl print()
print(THE ANSWER IS YES) nl wout(L) print(-) )
( c1ause(inpt(A ==gt B) _I ( impli(A B Z) impli(B A Z) ) print(l~Hl)
printTHE ANSWER IS YES) nl print(Z) print(Hj~(fH~) ))
goo(X) print( Hg)
print(THE ANSWER IS NO ) print( lH~lH~gg9l9lmiddotmiddot~Q(gmiddot)
00 Semhing for implications in equiV3lent relations
impli( B Z) shyt-ell( z1) prin(templ() pchn(S A lt=gt B) print()) close ( zl) consult(zl) templ(Z)
unload zl Z
Searching for equivalence
equiv (X L)
(( X lt=gt Y
equ(Y YI)t bagof(Y Yl L) L = [j )
(Y lt=gt X equ(Y YI) bagof(Y Yl L) L = [J )
( X = F(New)
clause(~ew T) makeup(T Tl)
(( Tl lt=gt B
equ(B Bl) bagof(Bl Bl M) M = [j L=[Newl )
(A lt=gt TI
equ(A AI) bagof(Al AI M) M = 1] L=INewj )) ))
makeup((A B) (AI Bl)) -
makeup(A A1) makeup(B BI)
makeup(A so2(A))
equ((A B) (AI BI)) -
equ(A AI) equ(B Bl)
equ(sol(X v Y) sol(XI v Yl)) -
equ(X XI) equ(Y YI)
equ(so2(X) so2(XI)) -
equ(X XI)
equ(contradiction(X) clJuse(contradiction(X) X) ) -
equ(X X)
Counting numbers
getatm((A B) X) -
( getatm(A X) getatm(B X) )
getatm(so2(F(X)) X) -
getatm(so2(X) X) - atom(X)
countl([J L R L R) -
countl([number(X Y)IT] L R L2 R2) shy
(( Y = (gt=~) LI is L + N Rl is R + 20001 l )
( Y = (gt N) LI is L+ N+ 1 RI is R + 20002 )
(Y == laquo=~) LI is L + 1 Rl is R + N )
(Y = laquo N) LI is L + 1 RI is R+N-I)
(Y == IJ LI is L + I Rl is R + J ) ( Y == N L1 is L + N RI is R + N ))
count1(T LI R 1 L2 R2)
count2(fJ L R L R) - 1
count2([XITJ L R L2 R2) shy
name(X Xl)
(( Xl = sknj LI is L Rl is R )
44
( Xl = Iskmj L1 is L + 1 RI is R + ZOOO1) ( LI is L + I RI is R + I ))
count2(T LI RI L2 R2)
pfn((A B)) - pfn(A) prn(B)
pCn(so2(F(X))) - prin(F )
prn(so2(X)) - atom(X) prin(X ) prn (so2(X))
Printing result
wout([XlJ - prt(X) nl woutf[xIY]) - prt(X) nl nl wout(Y)
prt(e(A B)) -
prt(A) prinr 8 ) prt(ltE) prt(eA) - prt(A)
prt(c(A EJ) - prin() prt(A) prine ) prt(B) prin(T)
prt(c A) - prt(A) prt((A E)) - ~
prt(A) nl prt(E) prt(sol(X v Y)) - ~
prt(X) prinC v) prt(Y) prt(A lt=gt B) -
prt(e A) prinC lt=gt ) prt(e B) prt(sol(X)) - prt(X)
prt(so2(X)) - prt(X
prt(c1ause(X Y)) - prt(X)
prt(contradiction(X)) - prin(contradiction() prt(cX) prinr))middot prt(num(XY)) - prin(number(X Y)) prt(sel(X)) - prin(X) prt(X v Y) - prt(X) prin( v) prt(Y) prt(X) prin(X)
Handling conditional queries
condi((Y Xl) shy
assertcon(X) Y
45
retractcon(X)
condi((B A))
retractcon(A) fail
assertcon((A B)) 1
assertcon(A) assertcon(B)
assertcon(A) asserta(A)
retrac teon ((A B)) 1
retracteon(A) retractcon (B)
retraetcon(A) - retract(A)
BIBLIOGRAPHIC DATA SHEET
Report No UIUCDS-F-84-928
3 Recipients Accession No
4 T ide and Subt ltle
An Annotated Predicate Calculus Inference System (APCIS)
S Report Date
November 1984 6
7 Author(s)
Kah-Eng Pua 8 Performing Organization Rept
No
9 Performing Organization Name and Address
Department of Computer Science University of Illinois Urbana IL
10 ProjectTaskWork Unit No
11 Contract Grant No NSF DCR 84-06081 ONR N00014-82-K-0186
12 Sponsoring Organization Name and Address
National Science Foundation Washington DC
13 Type of Report amp Period Covered
14
15 Supplementary Notes
16 Abstracts
This paper describes a deductive inference system called APCIS (Annotated Predicate Calculus Inference System) APCIS is able to carry out inferences from expressions involving numerical quantifiers selectors disjunctions of non-negated terms negated terms disjunctions of negated terms equivalences and exceptions It is also able to count the numbers of occurrence of a given simple term or a conjunction of terms The design of contradiction and the treatment of the disjunction of non-negated terms allow APCIS to accept Horn clauses as well as non-Horn clauses and to carry out inferences from them This feature makes APCIS more general than Prolog
17 Key lords and Document Analysis 170 Descriptors
APC (Annotated Predicate Calculus) APCIS (Annotated Predicate Calculus Inference System) Horn Clause Numerical Quantifier Prolog Selector
17b IdentifiersOpen-Ended Terms
17c COSATI FieldGroup
18 Availability Statement 19 Security Class (This
Re~f~~IA~SIF IFf)
21 ~o of Pages
49 211 ecurity Class (This
PageUNCLASSIFIED
22 Price
FOA NTIS n (10middot70 usco-oc 40329-
no_response(X1)
Sa
box(sknl)
number(sknl2)
The above live translated expressions ( ie la through Sa ) will be printed on the
terminal and loaded to Prolog if assertion mode is used they will be printed on the terminal but
not loaded to Prolog if assertion-translation mode is invoked
Now if the original APC expressions ( ie 1 through 5 ) are typed to Prolog via query
mode or query-translation mode the corresponding questions will be translated into the following
queries
lb
goo(( condi(( mortal(Xl) man(Xl))) ))
b
goo(( soil horse(Xl) v dog(XI)) ))
3b
goo(( c1ause( contradiction(( horse(XI) dog(Xl) )) _) ))
4b
goo(( conditt deaf(Xl) v dead(Xl) (be_shouted_at(XI) no_response(Xl)) )) ))
5b
amp00(( so2( box(XI) ) s02( num(XI 2 )) ))
The above five translated queries ( ie Ib through 5b ) will be printed on the terminal
and loaded to Prolog if query mode is used they will be printed on the terminal but not loaded to
Prolog if query-translation mode is invoked
In the above queries goo 801 and 802 each forms a part of the inference mechanism of
APCIS goo occupies the top level of the inference mechanism whereas 801 and 802 are at the
1
next level 102 will take care of the searching of simple terms and 101 will deal with the
disjunctions of non-negated terms in the database We will come back to them in Section 4
At the first glance one may feel that the above translated Queries are Quite complicated
However a closer examination will reveal that they are not so Queries lb 3b and 4b can each be
categorized as a conditional query which is a distinct feature of APCIS wherels queries 2b and
5b lre asking simple facts in the database
To handle conditional queries we consider two cases First if the queries involve a
special clause contradition we invoke the built-in function el3ule(X Y) which will look for the
desired contradiction clause in the database Second if the queries do not involve the clause
contradiction we activate a defined Prolog predicate condi to take care of the necessary
searching (To avoid confusion the reader is urged to compare expressions started with the same
number in the above three sets of example)
To handle a query which asks a simple fact we surround each disjunction of terms with
the functor sol as in the example 2b or crown each simple term with the functor 802 as in the
example 5b
32 TranslatIon of Negated Term And Disjunction of Negated Terms
One feature of APCIS is its ability to handle input expressions consisting of only negated
term or a disjunction of negated terms in the forms
or
2 -(AI) v ~(A2) v v ~(An)
To handle the above two forms a special clause with clause head contradiction is
created This special clause head has only one argument which is either a term or a set of terms
grouped together in the form
8
(AI A2 An)
The right-hand side of the clause contradiction is exactly same as the argument in the clause
head For example the above two forms involving negated terms will be translated into the
corresponding forms as follows
1 contradiction( A ) shy
A
2 contradiction(( AI A2 An )) shy
AI A2 An
The design of the clause with clause head contradiction will greatly enhance the inference power
of APCIS (see the example in Section 44)
33 Translation ot Disjunction ot Non-negated Terms
Another feature of APCIS is its ability to handle input expressions involving a
disjunction of non-negated terms in the forms
1 Al v A2 v v An
or
2 Bl amp 32 amp amp Bm ==gt Al v A2 v v An
Unlike Prolog which accepts only Horn clauses APCJS will accept Horn clauses as well
as non-Horn clauses which take the above two forms The inference from non-Horn clauses is
made possible by the two defined predicates sol lnd s02 discussed in Section 42 and Section 43
respectively (see also the example in Section 44) In the APC translator the above two forms are
transbted into the corresponding forms as follows
1 Al v A2 v v An
2 Al v A2 v v An shy
g
Bl B2 Bm
34 Futher Transformation of Exceptions and Equivalences
To provide some backgrounds for the discussion of the further transformation of
exception and equivalence relations we will lirst reproduce the three goals in the Step 2 of the
APe translator discussed in Section 32 of [31
First expressions involving implication or the form A ==gt B will be transformed to
Second expressions with exception symbol or the form A - B will be changed to the
form ( A lt=gt -(B) ) amp ( -(A) lt=gt B)
Tbird expressions with equivalence symbol of the form -(A) lt=gt B or of the form
A lt=gt -(B) will also be converted to ( A lt=gt -(B) ) amp ( -(A) lt=gt B ) since tbere are
logically identical to exception relations Also expressions with equivalence symbol of the form
A lt=gt B or -(A) lt=gt -(B) will remain the same
After the Step] of the APe translator both sides of any transformed expression with
lt = gt symbol will be treated separately as if they are two independent expressions In the
Step 10 of the APe translator each side of lt=gt will again be treated separately and
transformed into a form similar to an transformed input query (see Section 31) Two examples
are given below
1 state(on) lt=gt -( state(olJ) )
2 all( 1 bot(l) amp humid(l) - winter(I) )
They will be transformed in the Step 2 or the APe translator into
1
(state(on) lt=gt -( state(off) ) ) amp ( -( state(on) ) lt=gt state(olJ) )
2
10
( hot(l) amp humid(l lt=gt -(winter(l)) ) amp
( -( hot(l) amp humid(l)) lt=gt winter(I)
In Step la they will again be transformed to
1
so2( state(on) ) lt=gt so2( contradiction( state(oH) ) )
so2( contradiction( state(on) ) ) lt=gt so2( state(oH) )
2
( s02(hot(XI)) so2(humid(XI))) lt=gt so2( contradiction( winter(Xl ))
so2( contradiction(( bot(Xl) humid(Xl) )) ) lt= gt so2( winter(XI) )
There are two advantages in the treatment of exception and equivalence symbols in this
way First it will prevent Prolog program from going into an infinite loop which is difficult to
avoid if equivalent relation such as A lt=gt B is transformed into the logically equivalent form
( A ==gt B) amp ( B ==gt A) Second by maintaining both sides of lt=gt symbol in
query form the searching on either side caD be done more easily and efficiently since the form
is already processed and does not need any further transformation
Inference Mechanism
As mentioned at the end of Section 31 goo sol and s02 each forms a part of the
inference mechanism of APCIS with goo occupying the top level and 80) and 802 the second
level In addition to these countl count2 equlv and impll are also at the second level of the
inference mechanism We will go over all of them in the following sections
I goo
goo is essentially the starting point of the inference Whenever a translated query is
loaded to Prolog system from temp-fie goo will go through one or more of the following steps in
11
sequence
G 1 Check if the query asks for the numbers of occurrence of certain term(s) It so then
pass It to eountl and eount2 else go to G2
G2 The query will be passed down to sol or s02 (or both) to check i( any assertion in the
database can satisfy the query It the answer is positive then the query succeeds else
go to G3
G3 The query will be passed to equlv to carry out further searching It the searching is a
success then the query will be closed with a success else go to G4
G4 It the query is in the form A ==gt B then it will be passed to Impli It Impll
succeeds then done else the query will be closed with a (ailure
42 sol
801 and 802 together with dis and eon form the most complicated part of the APCIS
iorerence mechanism In this and the next section we will look at sol and s02 dis and eon will
be discussed in Section 44 We will close Section 44 with an example that illustrates the
materials presented in Section 42 through Section 44
sol is at the second level of the inference mechanism It will deal with any disjunction of
non-negated terms For any disjunction passed to it it will go through one or more of the
following steps in sequence
S1 Check if any term In the disjunction can be satisfied by any term or clause in the
database without contradiction It so then done else go to S2
S2 Pass the disjunction together with another disjunction (and its tlil) picked up from
the database to dis It dis succeeds then done else go to S3
S3 Pass the disjunction down to equlval which will check if any term in the disjunction
matches either side of any equivalence relation in the database It such a match is
found then check if the other side of the equivalence C3n be satisfied It so then done
else the goal fails
43 s02
s02 is also at the second level of the inference mechanism It will take care of all the
simple terms in the transl1ted query The following is the sequence that s02 wiII follow in
searching
S1 Check if the term passed to it caD be s3tisfied by any term or clause in the d3tabase
without contradiction It so then done else go to S2
S2 Pass the term together with a disjunction of terms (and its tail) picked up from the
database to dis If dis succeeds then done else the goal fails
44 dis and con
dis has three arguments In the first two clauses of dIs the first argument P v Q is
found in the database using the builtmiddotin functiol clause and the third argument R is the tair of
the term or the clause P v Q If P v Q is not a clause but a term R will be instantiated to trUE
The second 3rgument comes from either lIol or 802 and thus takes the form of either X v Y (a
disjunction of terms) or T (3 simple term)
All the clauses of dis together with con will perform the searching as exemplified in the
following algorithm (we will keep the notationsin this section)
01 Check if every term in P v Q is in X v Y It so then go to 03 else go to D2
02 For any term (in P v Q) which is not in X v Y or does not match T perform the
following tests
a Check if the term (in P v Q) has already been negated in the datab3Se (ie check if
the contradiction of the term exists in the d3tabase) If so then repeat D2 for other
terms not found in X v Y or not matching T else go to b
13
b Check if the contradiction of the term matches either side of any equivalence
relation in the database If such a match is found then check if the other side of the
equivalence can be satisfied If so then repeat O~ for other terms not found in X v Y
or not matching T else the goal fails
It all the terms (in P v Q) which are not in X v Y or do not match T survive either one
of the above two tests then go to 03
03 This step is essentially done by eon whose goal is to satisfy the tail R of P v Q It
con succeeds then done else the search fails
To close this section we will give an example to illustrate what we have covered In
Section 42 through Section 44
Example Assume that we already haye the following expressions in the database
horse(skml) v dog(skmI)
contradiction(( dog(XI) ))shy
dog(XI)
query goo(( soZ horse(X)) ))
This query will be passed to 802 which will check it the term horse() can be satisfied iu Step S 1
of Section 43 It is a failure So we now go to Step S2 In this step we pick up the disjunction
horse(~kml) v dog(skml) (and its tail true) in the datab3Se and pass it together with the term
horse(X) to dis We are now in Step 01 of Section 44 In this step we find that dog(skml) does
not match horse(X) So we have to go to Step 02 In Step 023 We find that the term dog(skml)
has already been negated (the second expression in the database) So we go to next step 03 Since
the tail of the disjuDction horse(skml) v dog(skml) is the atom true con is satisfied and the
query succeeds
45 countl and count2
countl and count2 are responsible for the counting of tbe numbers of occurrence of a
given simple term or a conjunction of terms They are activated by input queries in the form
q( exists( X whatnum amp P) )
where whatnum is the l~bel for activating the counting of the numbers of occurrence of P which
can either be a term or a conjunction of terms
countl will count the number of term(s) which will satisfy P and associate(s) with
numerical quantification(s Two counters are set to update the lower and upper boundary or the
scope or the numfrical quantifications encountered
The contents of the two counters are then passed to count2 which is responsible for the
counting or the following three types of term First term(s) which will satisfy P and associate(s)
with existential quantification(s Second term(s) which will satisfy P and has(have) Prolog atom
as its(thfir) argument(s) Third term(s) that will satisfy P and itself(themselves) is(are) Prolog
atom(s )
46 equiv
equlv will be activated only after sol and B02 have failed The first two goals of equlv
are similar to that of Step S3 in Section 42 and Step D2b in Section 44 The third goal or equiv
makes possible the inference on either side of any equivalent relation For example if we type the
following three expressions to Prolog in assertion mode
l all( X hot(X) amp humidX) - winter(X)
2 all( X hot(X) amp bumid(X) ==gt unpresent(X))
3 - ( exists( X winter(X) ) )
and then ask APCIS in query mode
q( cxists( X unpresent(X) ) )
15
APCIS with the aid of equlv will be able to answer yes to this query
41 lmpll
lmpll can be considered as the last attempt that APCIS would make to satisfy a
query It is activated only after equlv has failed It will first check if the query is conditional If
so it will convert the implication symbol to equivalence symbol and search if such an equivalent
relation can be found in the database If so a success Otherwise a failure
5 More on the Inference Mechanism
Having looked at all the subparts at the top two levels of the inference mechanism we
are ready to look at other subparts at lower levels
51 num and cnum
One distinct fe3ture or APCIS is its ability to deal with numerical quantifications As
mentioned in Section 31 input queries and assertions will undergo different transformations in
the last step (Step 10) of translation This also holds true for expressions involving numerical
quantifications Consider the following expression
exists( 6 X horse(X) )
If it is entered to Prolog via assertion mode we will after going through all the steps of
translation have the rollowing entered to the database
horse(sk n I
number(sknl6)
Now if we want to ask Are there more than five horses 7 and type in
q( exists( gt5 X horse(X) ) )
1amp
APCIS will translate the question and enter to Prolog the following query
goo(( s02( horse(X) ) s02( num( X gt5 )) ))
Note that the term number(slml 6) in the database and the term num(X gt S) in the query are
different predicates and this difference is exactly where the power of the clause num(X N)
defined in APCIS comes from When the clause num(X N) in APCIS is activated it will search
through the database to see if there is any term of the form number(X I) whose first argument
matches the first argument of num(X Y) in the query It a match is found the second arguments
of both num(X Y) in the query and number(ltI) in the database will be passed to cnum in
APCIS
The job of cnum is to compare the numerical messages carried by the second
argument or the term rlum(X Y) in the query and the second argument of the term rlumber(X I)
in the database to see if they match with each other according to the rules defined in cnum
While there are 25 rules for such matching purposes the idea is simple
Imagine that the second argument Y of the term num(X Y) in the query
and the second argument I of the term num()( I) in the database each occupies a
place in an integer line (Le the integer line in mathematics) To have a match
the domain covered by Y should contain the domain covered by L
As an example the answer to the above query is positive since the domain of gt5
contains the domain or 6
Before closing this section we will bring out a speciaJ translation aspect of expressions
involving numbers by an example We first type to APCIS the Collowing expressions in assertion
mode
1 aU(X all(Y father(X Y) amp number(Y gt6) ==gt has_manY3hildren(X) ))
2 exists(X exists( 12 Y Cather(X Y) ) )
11
After going tbrougb all tbe translation steps tbe Collowing two expressions will be entered to tbe
database
I
bas_many_cbildren( Xl ) shy
Cather( Xl X2 )
num( X2 gt6 )
2
Catber( sk m1 sk n2 )
number( skn2 12 )
lotice that whenev(gtr a term with Cunctor number appears at the rigbt-band side oC a Prolog
clause its Cunctor will be cbanged to num automatically This treatment will greatly cnbance tbe
inference power of the clause sbown in l above For instance iC we now ask tbe question
q( exists( X bas_many_children(X) ) )
The right hand side oC the clause l will match the two terms in 2 and tbe query succeeds
52 Bel and cael
A special feature of APe is tbat all predicates tbat express relations = = gt
gt= lt and lt= can be expressed explicitly using infix notations as relational statements
called selectors To handle selectors we defined Bel in APCIS
Every expression involving selectors will undergo different translations in assertion mode
and query mode For example the assertion
a( exists( [X Y] box (X) amp box(Y) amp (weigh t(X) gt weight(Y) ) ) )
will be translated into the following three terms and entered to tbe database
box( skml )
box( skm2 )
18
weight( skm 1 ) gt weight( skm2 )
Now it we want to ask Is it true that there exists two boxes of different weights and type in
q( exists( [X Yl box(X) amp box(Y) amp ( weight(X) = weight(Y) ) ) )
The question will be transformed to the following query and entered to Prolog
goo(( so( box(XI) ) s02( box(X2) ) so2( sel( weightXI) = weight(X2) )) ))
Note that the selector in the above query is surrounded by the functor set When any clause or
8el in APCIS is activated it will search through the database to see it there is any selector whose
two arguments (left and right side or any selector symbol) match the two arguments of the
selector in the query At the same time 8el will check iC the selector symbols (may be different) or
the two different selectors (one in the query and one in the database) satisfy the rules defined in
sel There are 12 matching rules defined in sel All oC them ~re straightforward and will not be
discussed here An example will be enough to explain how 8el works
Consider the execution of the above transformed query The first two terms in the query
are satisfied by the first two terms in the database and Xl and X2 are instantiated to skml and
skm2 respectively The third term of the query will be passed to eel (of APCIS) which finds a
match on each side of the two selectors (one in the query and one in the database) At the same
time the two different selector symbols gt and = are found to satisfy one of the rules in
8el As a result the query succeeds
To enhance the inference power of clauses involving selectors all the selectors appearing
on the rightmiddothand side oC any clause will be surrounded by a functor set The idea is similar to
that in the last part of the previous section
c8el is exactly the same as 8el functionally It provides a convenient way to compare
selectors when dis is being executed
19
8 Printing Result
Whenever a goal is successfully executed APCIS will not only response with a yes but
also print out the matched terms or clauses in the database This is made possible by the built-in
function bagor and the two predicates wout and prt defined in APCIS
7 Summary
In this paper a description of a deductive inference system called APCIS (Annotated
Predicate Calculus Inference System) has been provided APCIS is able to carry out inferences
from expressions involving numerical quantifiers selectors disjunctions of non-negated terms
negated terms disjunctions of negated terms equivalences and exceptions It is also able to count
the numbers of occurrence of a given simple term or a conjunction of terms
The main idea of APCIS is that each input APC expression is first passed to a
preprocessor ( ie APC translator ) which dissolves and transforms each APC expression into
Prolog expression(s) which will then be loaded to Prolog system The user bas to specify whether
each input expression is to be entered as an assertion or as a query by invoking either assertion
mode or query mode respectively Each assertion or query will undergo different transformations in
the preprocessor The different treatment of assertion or query not only allows a full uS1ge of the
Prolog inference mechanism but also makes possible a higher level of inexact pattern matching
exemplified by the examples in Section 51 and Section 52 where the four predicates num
cnum sel and csel are discussed This higher level of pattern matching increases the inference
power of APCIS greatly
The design of contradiction and the treatment of the disjunction of non-negated terms
allow APCIS to accept non-Horn clauses and to carry out inference from them This feature
makes APCIS more general than Prolog
20
While APCIS performs very well in many sets of arguments provided by the author it is
still too early to jump to conclusion that it can perform equally well in all types of problems In
any event the expressiveness of APC has greatly been retained in the present version of APCIS
and moreover some design ideas or APCIS mentioned in this paper are not restricted to APCIS
- they may be carried over to learning programs with narrower scopes
21
References
[1] W F Clocksin and C S Mellish Programming In Prolog Springermiddot Verlag Berlin Hpoundidelberg 1981
[2] R S Michalski A Theory and Methodology of Inductive Learning Chpt 4 Machine L earning Tioga Publishing Co Palo Alto CaliJornia 1989
[3] K-E Pua Translating Annotated Predicate Calculu8 to Prolog ISG Report 84middot1 UlUCDCSmiddotFmiddot918 University oj Illinois Urbana IL June 1984
22
Appendix A
APCIS Users Manual
1 Get Started
Users are urged to follow the steps depicted below
1 Get the PROLOG interpreter by typing
alias prolog mntb2sammutsammutprologprolog (Vax A)
or
alias prolog mntb2sammutsammutbinprolog (Vax B)
2 Load apc and infer by typing
prolog apc infer
When large APC expressions are expected we can increase the stlck by typingI
prolog -snnnn ape infer
where ns denote the number of stacks in decimal
3 When the wording LSW - PROLOG appears on the terminal we are reldy to interact
with APCIS The four modes by which we can invoke APCIS are summarized below
a Assert ion-Translation Mode
ta(X)
b Query-Translation Mode
tq(X)
c Assertion Mode
a(X
d Query Mode
q(X)
23
where Xs are APC expressions
2 Notations Used in APCIS
Below is a summary or notations used in APCIS
a Logical operators
amp
v
==gt
lt=gt
-
negation
conjunction
disjunction
implication
equivalence
exception
b Binary relation symbols in selectors
-
=
gt=
lt=
gt
lt
equal
not equal
greater or equal
smaller or equ al
greater
smaller
c Relational operators in numerical quantifiers
lt less than
lt= less than or equal
gt greater than
gt= greater than or equal
d BinlTY operator in numerical quantifier
range
e Universal quantifier
all(X p(X))
f Existential quantifier
exists(X p(X))
g Numerical quantifier
exists(I X p(X))
where p(X) is a formula
where X is a variable or a Jist of variables or the
form [HI~rj and p(X) a formula
where I repersents expression involving integer(s)
and operator(s) in c or d above and p(X) a formula
25
Appendix B
APCIS Program Listings
------------------------------- Program Name APCIS - Part 1 APC Translator
-------------------------------
op(3OO fx -)1
op(500 xfy amp)
oPt 500 xfy v)
op(600 xfx )
op(700 fx [gt= lt= gt lt ]) op(400 xfy [= gt= lt= gt lt ])1 op(900 xfy gt lt=gt -])1
steps(X Xg) shy
numbervars(X 1 J Step 1 change variables to iis
rmimp(X X) Step 2 conv(X X3) Step 3
rewrite(X3 X4) Step 4
negin(X4 X5) Step 5
dropexist(X5 X6 1]) Step 6
dropall(X6 X7) Step 7
distrib(X7 X8) Step 8 clausiCy(X8 X9 [J) Step 9
ta(X) shysteps(X Xg)
(( Xg = II nl
print( yes it is always true) )
( nl nl printcl(X9))) Step 10a
tq(X) shy
steps(X Xg)
prques(Xg)
28
Step 2 Removing implic3tions amp Transforming exceptions and equiv3lences
rmimpl( P - Q (PI lt=gt (QI) ) amp ((PI) lt=gt QI) ) -
rmimpl(P PI) rmimpl(Q QI)
rmimplnp) lt=gt Q (PI lt=gt -(QI)) amp nPI) lt=gt QI) ) - 1
rmimpl(P PI) rmimpJ(Q QI)
rmimpJ(P lt-gt -(Q) (PI lt=gt -(QI)) amp nPI) lt=gt QI) ) -
rmimpl(P PI) rmimpl(Q QI)
rmimpl( P lt=gt Q PI lt=gt QI ) - I
rmimpl(P PI) rmimpl(Q QI)
rmimpl( P ==gt Q -(PI) v QI ) - I
rmimpl(P PI) rmimpl(Q QI)
rmimpl( all(X P) aI(X PI) ) - 1
rmimpl(P PI)
rmimpl( exists(X P) exists(X PI) ) -
rmimpl(P PI)
rmimpl( exists(I X P) exists(I X PI) ) -
rmimpl(P PI)
rmimpl( P amp Q PI amp Ql ) -
rmimpl(P PI) rmimpl(Q Ql)
rmimpl( P v Q PI v QI ) -
rmimpl(P PI) rmimpl(Q QI)
rmimpl( -(p) -(PI) ) - I
rmimpl(p PI)
rmimpl( P P )
St~p 3 Converting numerical amp distinctive quantifiers
L Numerical quantifiers
examples of input forms
1 exists(gt= i X pIX)) where i is an integer
2 exists(i X pIX)) where i is an integer
3 exists(i j X pIX)) where i j are integers and iltj
4 exists(il v i2 X pIX)) where is are integers
examples of output forms of this step
1 exists(X pIX) amp number(X gt= i) )
2 exists(X pIX) amp number(X i) ) 3 exists(X pIX) amp number(X ij) ) 4 exists(X pIX) amp number(X il v i2) )
II Distinctive quantifiers
27
example or input Corm
exists([XYL p(X Y))
example or output Corm or this step
exists(X exists(Y p(XY)) )
conv(P lt=gt Q PI lt=gt QI) - 1
conv(P PI) conv(Q QI)
conv(al1(X P) all(X PI)) -
conv(P PI)
conv(exists(HIT] P) R ) - conv(P PI) convert distinctive quantifier
convtdis(exists([HIT]PI) R)
conv( exists(I X P) exists(X PIamp number(X I) )) -
conv(P PI) convert numerical quantifier
conv(exists(X P) exists(X PI)) - 1
conv(P Pl)
conv(P amp Q PI amp QI) - 1
conv(P PI) conv(Q QI)
conv(P v Q PI v QI) - t conv(P PI) conv(Q QI)
convC(P) -(PI)) -
conv(P PI)
conv(P Pl
convtdis(existsl[XL P) exists(X P)) - atomic(X) convtdis(exists[XIYj Pl exists(X R)) shy
convtdis(exists(Y P) R)
Step 4 Rewriting compound predicates andor compound selectors
Outputs are smiple predicates andor simple selectors
rewrite(P lt=gt Q PI lt=gt QI) - t rewrite(P PI) rewrite(Q QI)
rewrite(all(X Pl all(X PI)) - 1 rewrite(P PI)
rewriteexists(X P) exists(X PI)) - I rewriteP PI)
rewrite(P amp Q PI amp QI) - rewrite(P P 1) rewrite( Q Q 1
rewrite(P v Q PI v QI) - 1
rewrite(P PI) rewrite(Q QI)
rewriteC(P) -(PI)) - I
28
rewrite(P PI) rewrite(F(A B) R) -
rewrite(A AI) rewrite(B BI) re(F(AI BI) R)
rewrite(F(A) R) -
rewrite(A AI) re(F(AI) H)
rewrite(F(A B C) R) -
rewrite(A AI) rewrite(B BI) rewrite(C CI) re(F(AI BI CI) R)
rewrite(F(A B C D) R) -
rewrite(A AI) rewrite(B Btl rewrite(C CI) rewrite(D DI) rc(F(AI BI CI Dl) H)
rewrite(PP)
re(F(A B v el (RI v R2) -
re(F(A Bl RIl re(F(A C) R2) reF(A B amp cl (RI amp R2)) -
re(F(A B) RI) re(F(A e) R2) re(F(A amp B C) (Rl amp R2)) -
re(F(A e) R 1) re(F(B C) R 2) re(F( v B el (R I v R2)) -
re(F(A el R I) reFB el R2) re(F(A amp Bl (R I amp R2)) -
re(F(A RI) re(F(BJH2) re(F(A v B) (R 1 v R2)) -
re(F(A) RI) re(F(B) R2)
re(F(A vB c Dl (RI v R2) -
re(F(A C D) RI) re(F(B C D) R2) re(F(A amp B C D) (RI amp R2)) -
re(F(A C D) Rll re(F(B C D) R2) re(F(A B v C D) (HI v R2)) -
re(F(A B D) RI) re(F(A C D) R2) re(F(A B amp C D) (HI amp R2)) -
re(F(A B D) RI) re(F(A C D) R2) re(F(A B C v D) (RI v R2)) -
re(F(A B C) R I) reF(A B D) R2) re(F(A B C amp D) (RI amp R2)) -
29
re(F(A B C) RI) re(F(A B D) RZ)
re(F(A v B e D E) (R I v R2)) -
re(F(A e D E) R I) re(F(B e D El R2) re(F(A amp B e D E) (RI amp RZ)) -
re(F(A e D El R 1) re(F(B e D E) R2) re(F(A B v e D E) (R I v R2)) -
re(F(A B D E) RI) re(F(A e D E) R2)
re(F(A B amp e D E) (RI amp R2)) -
re(F(A B D El RI) re(F(A e D E) RZ) re(F(A B e v D E) (R I v R2)) -
re(F(A B e El R 1) re(F(A B D E) RZ) re(F(A B e amp D E) (RI amp RZ)) -
re(F(A B e E) R I) re(F(A B D E) RZ)
re(F(A B e D vEl (RI v RZ)) - l
rc(F(A B C D) RI) re(F(A n e El RZ) re(F(A B e D amp El (RI amp RZ)) - ~
re(F(A B e D) RI) re(F(A B e El RZ)
re((A = B) (A = B)l-
re((A = Bl (A = 8)) -
retIA gt= BI (A gt= B)) -
re((A lt= B) (A lt= B)) -
re((A gt B) (A gt B))-
re((A lt Bl (A lt Bl)- re(A A)
Step) Bringing n(gation inwards
Degin(-(P) PI) - neg(P Pl)
negin(P lt=gt Q PI lt=gt Ql) - ~
negin(P PI) negiD(Q QI)
Degin(aU(X P) all(X PI)) - Degin(P PI) negin(exists(X P) exists(X PI))- negin(P PI) negin(P amp Q PI amp Ql) - Degin(P PI) negin(Q Ql)
Degin(P v Q PI v QI) - Degin(P PI) negin(Q QI) negin(P Pl
neg(-(P) PI) - negin(P PI)
neg(all(X P) exists(X PI)) - neg(P PI)
30
neg(exists(X P) all(X PI)) - neg(P PI)
neg(P amp Q PI v QI) - neg(P PI) neg(Q Ql)
neg(P v Q PI amp QI) - neg(P PI) neg(Q QI)
neg(P -(PH
Step 6 Dropping existnetial quanti6ers
dropexist(P lt=gt Q PI lt=gt QI Elerns) - dropexist(P PI Elerns) dropexist(Q QI Elerns)
dropexist(alJ(X P) all(XPI) Elerns)
dropexist(P PI [XIElernsJ)
dropexist(exists(X P amp nurnber(X Yraquo P2 Elerns) -
genfun(skn Newg) Fun = [NewgIElerns]
subst(FuD X P amp Dumber(X Y) PI)
dropexist(Pl P2 Elerns)
dropexist(exists(X P) PZ Elerns) -
genfun(skrn Newf) Fun = [NewfIElernsJ
subst(Fun X p PI)
dropex ist(P 1 P~ Elerns)
dropexist(P v Q PI v QI Elerns) - ~
dropexist(P PI Elerns) dropexist(Q Ql Elerns)
dropexist(P amp Q PI amp QI Elerns) - 1
dropexist(P Pl Elerns) dropexist(Q QI Elerns)
dropexist(P P _)
gen fun(R oot Newn arne) shy
getnurn(Root Nurn)
narne(Root Rootlist)
append(Rootlist[Nurnj Narnelist)
concat(Narnelist Newnarne)
getnurn(Root Nurn) shy
retract(currentnurn(Root Nurn 1 raquo
Nurn is Nurni + 1
asserta(currentnurn(Root Nurn))
getnurn(Root 1) - asserta(currentnurn(Root 1))
subst(New Old Val Val) - var(Val)
subst(New Old Old New) - 1 substNew Old Val Val) - atornic(Val)
31
subst(New Old Val Newval) shy
runctor(Val F N)
CUDctor(Newval F N)
subst_args(N New Old Val Newval)
subst_args(O J J - J J
subst_args(N New Old Val NewVal) shy
arg(N Val OldArg)
arg(N NewVal NewArg)
subst(New Old OldArg NewArg)
NI is N - I
subst_args(Nl New Old Val NewVal)
append([J L L) -
append([XILl] L2 [XIL3]) - append(Ll L2 L3)
Step - Dropping universal quantifiers
dropall(P lt=gt Q PI lt=gt QI)-
dropall(P PI) dropall(Q QI)
dropall(all(X P) PI) - ~ dropall(P PI)
dropall(P amp Q PI amp QI) -
dropall(P PI) dropall(Q QI)
dropall(P v Q PI v QI) -
dropall(P PI) dropall(Q QI)
dropall(P P)
Step 8 Distributing conjunctions over disjunctions
distrib(P lt=gt Q PI lt=gt Ql) - t distrib(P PI) distrib(Q QI)
distrib(P v Q R) -
distrib(P PI) distrib(Q QI)
distributing(PI v QI R)
distrib(P it Q PI it QI) -
distrib(P PI) distrib( Q QI)
distrib(P P)
distributing((P amp Q) v R PI amp QI) -
distrib(P v R PI) distrib(Q v R Ql)
32
distributing(P v (Q amp R) PI amp Ql) -
distrib(P v Q PI) distrib(P v R Ql)
distributing(P P)
Step 9 Packing each conjunction into clauses
c1ausify(P amp Q CI C2) -
clausiCy(P CI C3) c1ausify(Q C3 C2)
cbusiCy(P [d(A B)ICs] Cs) shy
inclause(P A [j B [I) 1
c1ausiry( C C)
inclause(P v Q A AI B B1) -
inc1ause(P A2 AI B2 Bl)
inclause(Q A A2 B B2)
inclausenp) A A B1 B) -
notin(P A) putin(P B B1)
inclause(P AI A B B) shy
notin(P Bl putin(P A AI)
notin(X [XU) - fail
notin(X [JLj) - notin(X L)
notin(X 1])
putin(X II [X]) - 1
putin(X [XILJ L) -
putin(X [YILJ [YILl]) - putin(X L Ll)
Step 1Oa Printing clauses
printcl([]) - nl nl
printcl(c1(AB)ICsj) - printcl(A Bl nl printcl(Cs)
printcl(L II) - printdis(IL) prinr)middot
printclHl L) - prin(contradiction(() printconl(rL)
print()) - ) printconj(rL) prinr )
printcl(Ll L2) shy
printdis(ILl) print( - ) printconj(rL2) prin()
printdis(S[Lj) - printcbar(SL)
33
printdis(S[LILs]) - printchu(SL) prin( v) printdis(SLs)
printconl(S[LI) - printchar(SL)
printconl(S[LILs]) - printchar(SL) prin( ) printconl(SLs)
printconj(S[L]) - tab(3) printchar(SL)
prin tconj( S [L IL sl) shy
tab(3) printchar(SL) print( ) printconj(SLs)
printchar(SP) shy
atomic(P)
name(P L)
L = [IT]
concat([XIT NewP)
prin(~ewP)
printchar(SP) shy
atomic(P)
prin(P)
printchar(SA lt= gt B) -
prin((l clausify(A AI [j) pl(eAl) prin())
print lt=gt )
prin(() cbusify(B Bl [I) pJ(eBl) prine))middot
printchar(rnumber(X N)) shy
prin(num() printchar(rx) prin( )
printchar(rN) prinC))
printchar(rF(A B)) shy
seJec(F(A B))
prinCsel() printchar(rA)
prin( F ) printchar(rB) prinC))
printchar(SF(A B)) shy
( selec(F(A B)) F = infix )
printchar(SA) prin( F ) printchar(SB)
printchar(SF(A)) shy
(F= prefix gt= F= prefix lt= F= prefixgt F= prefix lt )
prin(F ) printcbar(SA)
printchar(SP) shy
functor(P F MaxN)
prin(F ()
Nl is MaxN - 1
putout(S N 1 P MaxN)
34
prin())
putout(S 0 P MaxN) -
arg(~laxN P Argu)
prin tchar(SArgu)
putout(S N p MaxN) shy
Nt is MaxN - N arg(NI P Argu)
printcbar(SArgu )
prin( )
N2 is N - 1
putout(S N2 P MaxN)
selec(FA B)) shy
( F= infix = F= infix f= F= infix gt=
F= infix gt F= infix lt= F= infix lt )
35
----------------------------------Program Name APClS - Part 2 Inference Mechanism ---------------------------------- a(X) shy
steps(X X9)
(( X9 =[] nl
print( yes it is always true) )
( X9 =[cI(IJ[])] nl
print( no it is always false) )
( nl nl printel(X9) Step 1Oa
tell(temp_file) printel(X9) e1ose(temp_file) consult(temp_6Ie) ))
q(X) shy
asserta( in pt(X))
steps(X X9)
(( X9 = [] print(middot~H~~middot~t~)
print(THE AiSWER IS YES)
print( ilgIQlQl(~) )
( X9 = [e1([j [j)] Pr1nt ( OJ fi(i I~ iii Ij)middot(i)(i) fiyenQ)riiio(i)(ij)(i)fj)fiyen1li1il1li1il)__ gtw~ __~_~ _~~_ ~_-=~
print(THE ANSWER IS NO ) print() )
( teI1(temp_6Ie)
prques(X9) Step 1Ob
close(temp_file)
nl print(Let me think about it) nl
consult(temp_6Ie) ))
retrac t( in pt(X))
Step lOb Printing question
prques(lcl(A 8)1) - prin(goo(() pl(qA 8) print()))
prques([c1(A 8HCs]) - prin(goo(() pl(qA 8) print() pl(q Cs)
pl(e [c1(A 8)]) - pl(eA 8)
pl(q [c1(A 8)]) - pl(qA 8) print()))
pl(S [e1(A B)ICs]) - pl(SA B) prin( ) pl(S Cs)
38
pl(q [j L) - prin(c1ause(contradiction(() pcont(qL) prin())_))
pl(S [I L)- prin(so2(contradidion(() pcont(SL) print))))middot
pl(S [L] []) - prin(so2() pcbar(SL) prin())
pl(S L [J)- prinsol() plett(SL) print))
pl(S [L] LI) - prin(condi(() pchar(cL)
prin(() pcont(S Ll) prine))))
pl(S L Ll)- prin(c1ause() plert(cL)
prin(() pcont(S Ll) prine)))
plert(S[LJ) - pchar(SL)
plert(SjLILsj) - pcbar(SL) print v) pleCt(SLs)
pcont(S[L]) - pchar(SL)
pcont(S[LILsj) - pcbar(SL) prinr ) pcont(SLs)
pcbar(SP) shy
atomic(P)
name(PL)
( L = [IT] L = [5 k miT] L = [5 k niT] )
concat[XITj NewP)
prin(0JewP)
pchar(SP) shy
atomic(P)
prin(P) pchar(SA lt=gt B) -
prin(() dausify(A AI []) pl(eAI) prin())
prinr lt=gt ) prin(() dausify(B BI ]) pl(eB) print))
pchar(Snumber(X N)) shy
prin(num() pchar(SX) prin()
pchar(SN) prinr))
pcbar(SM N) - prin(M N)
pcbar(cF(A B)) shy
selec(F(A Braquo
pcbar(cA)
prine F ) pchar(cB) pchar(SF(A B)) shy
selec(F(A B))
prin(sel() pchar(SA)
print F ) pchar(SB) print)) I
31
pc har(SF(A)) shy
( F= prefix gt= F= prefix lt= F= prefixgt F= prefix lt )
prin(F ) pchar(SA)
pchar(SP)shy
runctor(P F MaxN)
prin(F ()
011 is MaxN - 1 pout(SNl P MaxN)
print) )
pout(S 0 P M3xN) - 1
arg(~bxN P Argu)
pchlr(SArgu )
pout(S N P MaxN shy
Nl is MaxN - N
arg(Nl P Argu)
pchar(SArgu
prin( )
N2 is N - 1
pout(S N2 P ~13xN)
Comparing numbers in numerical quantifiers
num(XN) shy
number(X I)
cnum(N 1) ~
cnumlaquo=01 lt=I- N gt=I
cnumlaquo=J lt I) - N gt=1-1
cnumlaquo=NIJ) - N gt=J 1
cnumlaquo=N J)- integer(I) N gt=I~
cnum(gt=N gt=1) - N lt=1
cnum(gt=N gt I) - N lt=1+ 1 cnum(gt=NIJ) - N lt=1
cnum(gt=N lt=1)- N lt=1
cnum(gt=N lt I) - N lt=1 L cnum(gt=N 1)- integer(I) N lt=1
cnum( lt N lt 1)- N gt=1 L
38
cnum( lt N lt=1) - N gt I cnum( lt NLJ) - N gt J
cnum( lt N 1)- integer(I) N gt 1
cnum(gt N gt I) - N lt=1 cnumlgt i gt=1) - N lt I
cnum(gt N lt=1) - N lt=0
cnum(gt N lt I) - N lt=0
cnum(gt iIJ) - N lt I cnum(gt N 1)- integer(I) N lt I
cnum(~LN lt=1) - M=I N gt= I l
cnum(~LN lt I) - M=l N gt= I-I
cnum(~LNLJ) - M lt =1 N gt = J
cnum(~1N 1)- integer(I) M lt= I N gt= I
cnum(- N) - integer(N)
Comparing selectors
sel(X = Y) shyX= Y
sel(X I=Y) shy(X I=Y X lt Y Xgt Y)
sel(X gt Y) shyXgt Y
sel(X lt Y) shyXlt Y
selX gt=Y) shy(X gt=Y X= Y Xgt Y)
se(X lt=Y) shy
(X lt=Y
X= Y
X lt Y)
csel(infix = infix =)
39
csel(infix = infix = csel(infix = infix gt)
csel(infix = infix lt) csel(infix gt infix gt) cseJ(infix lt infix lt) csel(infix gt= infix gt=) csel(infix gt= infix gt csel(infix gt= infix =)
csellinfix lt= infix lt=) csel(infix lt= infix lt) csel(infix lt= infix =)
Finding solutions
sol(X v Y) -
(( notetra(X) eon(X) ( sol(Y) )
( c1ause(P v Q R) not(cketra(P v Q))
dis(P v Q X v Y R) ~ )
( A lt=gt B equival(A lt=gt B X v Y) ~ I) sol(X) - ~ notetra(X) eon(X)
so~(X) - notetra(X)
( con (X)
( clause(P v Q R) not(ekctra(P v Q)) dis(P v Q X R) I)
cketra(P v Q) -
eketra(P) eketra(Q) eketra(F(I J)) shy
selec(F(I J))
c1ause(contradiction(sel(F(IJ))) _I
eketra(number(W I)) -
clause(cootradietion(num(Wl)) - eketr(P) shy
clause(contradiction(P) - 1
notctra(P) shy
not( e lause( con tradiction(P) _))
40
Searching (or disjunctions
dis(P v Q X v Y R) - dis(P X v Y R)
dis(Q X v Y R) con(R)
dis(P v Q X R) -
dis(P X R) dis(Q X R) con(R
dis(P X v Y R) - clause(contradicton(Pl J 1
dis(F(I J) sel(G(I J)) v Y R) - csel(G Fl dis(number(WI) num(W N v Y R) - cnum(N I)
dis(P P v Y R) -
dis(P X v Y R) - dis(P Y R)
dis(F(I J) seJ(G(IJ)) R) - csel(G F)
dis(number(WI) num(WN) R) - cnum(N I) dis(P P R) - 1
dis(FJ J X R) shy
( ckctra(F(IJ) cbeckeq(seJ(F(IJ))) )
dis(number(W Il X R) - ( ckctra(number(WI)) cbeckeq(num(WI)) )
dis(P X R) shy( ckctra(P) cbeckeq(P) ) 1
cbeckeq(P) shy
(( A lt=gt so2(contradiction(P))
bagof(A A [jj) ) ( so2(contradiction(P)) lt=gt B
bagof(B B Uj) ))
ckeq(A) shy
( so2(A) lt=gt B B lt=gt so2(A) ) bagof(B B UJ)
con((P Q)) -
clause(P R) con(R) con(Q) con(true) -
con(contradiction(P)) - clause(contradiction(P) J
con(cause(X Y)) - cause(X Y)
con(sel(X)) - sel(X)
con(num(X Y)) - num(X Y) con(P)- (( dause(P R) (con(R) ckeq(R)))
colJectin(P) )
collectin(P) shy
bagof(S (c1ause(P S) S = true) [L LIJ )
mkcon(L Ll L)
bagor(l (L2 ) UJ) L
mkcon((A AI) (B B1) (sol(A v B) e D)) -
mkcon(A B1 e) mkcon(A1 (B Bl) D)
mkcon(A (B B1) (sol(A v B) e)) -
mkcon(A Bl e)
mkcon((A AI) B (sol(A v B) e)) middot1
mkcon(Al B e)
mkcon(A B sol(A vB))
Searching ror equivalences
equival(A lt=gt B X v Y) - 1 ( equival(A lt=gt B X) equival(A lt=gt B Y) )
equival(s02(A) lt=gt 502(B) A) - clause(B _I equival(s02(B) lt=gt 502(A) A) c1ause(B _I
Top level or inrerence mechanism
goo((s02(whatnum) P)) -
getatm(P Xl
bagor(number(X Y) ( P so2(number(X Y)) ) A )
count1(A 00 L R) nl
bagor(X P B )
count2(B L R Ll Rl) nJ print()
(( LI = 0 Rl = 0 print(THE ANSWER IS ) nl
(( Ll = Rl prin(-Jumber or ) prn(P) print(is Ll) )
( Rlgt20000 prin(Number or I prn(P) print(is LI or more) )
42
( prin(Number of ) pfn(P) print( is from Ll to Rl) )) )
( print(THE ANSWER IS NO I )) print()
goo(X) shy
(( bagof(X X L) L = [I nl print()
print(THE ANSWER IS YES) nl wout(L) print() )
( equiv(X L) nl print()
print(THE ANSWER IS YES) nl wout(L) print(-) )
( c1ause(inpt(A ==gt B) _I ( impli(A B Z) impli(B A Z) ) print(l~Hl)
printTHE ANSWER IS YES) nl print(Z) print(Hj~(fH~) ))
goo(X) print( Hg)
print(THE ANSWER IS NO ) print( lH~lH~gg9l9lmiddotmiddot~Q(gmiddot)
00 Semhing for implications in equiV3lent relations
impli( B Z) shyt-ell( z1) prin(templ() pchn(S A lt=gt B) print()) close ( zl) consult(zl) templ(Z)
unload zl Z
Searching for equivalence
equiv (X L)
(( X lt=gt Y
equ(Y YI)t bagof(Y Yl L) L = [j )
(Y lt=gt X equ(Y YI) bagof(Y Yl L) L = [J )
( X = F(New)
clause(~ew T) makeup(T Tl)
(( Tl lt=gt B
equ(B Bl) bagof(Bl Bl M) M = [j L=[Newl )
(A lt=gt TI
equ(A AI) bagof(Al AI M) M = 1] L=INewj )) ))
makeup((A B) (AI Bl)) -
makeup(A A1) makeup(B BI)
makeup(A so2(A))
equ((A B) (AI BI)) -
equ(A AI) equ(B Bl)
equ(sol(X v Y) sol(XI v Yl)) -
equ(X XI) equ(Y YI)
equ(so2(X) so2(XI)) -
equ(X XI)
equ(contradiction(X) clJuse(contradiction(X) X) ) -
equ(X X)
Counting numbers
getatm((A B) X) -
( getatm(A X) getatm(B X) )
getatm(so2(F(X)) X) -
getatm(so2(X) X) - atom(X)
countl([J L R L R) -
countl([number(X Y)IT] L R L2 R2) shy
(( Y = (gt=~) LI is L + N Rl is R + 20001 l )
( Y = (gt N) LI is L+ N+ 1 RI is R + 20002 )
(Y == laquo=~) LI is L + 1 Rl is R + N )
(Y = laquo N) LI is L + 1 RI is R+N-I)
(Y == IJ LI is L + I Rl is R + J ) ( Y == N L1 is L + N RI is R + N ))
count1(T LI R 1 L2 R2)
count2(fJ L R L R) - 1
count2([XITJ L R L2 R2) shy
name(X Xl)
(( Xl = sknj LI is L Rl is R )
44
( Xl = Iskmj L1 is L + 1 RI is R + ZOOO1) ( LI is L + I RI is R + I ))
count2(T LI RI L2 R2)
pfn((A B)) - pfn(A) prn(B)
pCn(so2(F(X))) - prin(F )
prn(so2(X)) - atom(X) prin(X ) prn (so2(X))
Printing result
wout([XlJ - prt(X) nl woutf[xIY]) - prt(X) nl nl wout(Y)
prt(e(A B)) -
prt(A) prinr 8 ) prt(ltE) prt(eA) - prt(A)
prt(c(A EJ) - prin() prt(A) prine ) prt(B) prin(T)
prt(c A) - prt(A) prt((A E)) - ~
prt(A) nl prt(E) prt(sol(X v Y)) - ~
prt(X) prinC v) prt(Y) prt(A lt=gt B) -
prt(e A) prinC lt=gt ) prt(e B) prt(sol(X)) - prt(X)
prt(so2(X)) - prt(X
prt(c1ause(X Y)) - prt(X)
prt(contradiction(X)) - prin(contradiction() prt(cX) prinr))middot prt(num(XY)) - prin(number(X Y)) prt(sel(X)) - prin(X) prt(X v Y) - prt(X) prin( v) prt(Y) prt(X) prin(X)
Handling conditional queries
condi((Y Xl) shy
assertcon(X) Y
45
retractcon(X)
condi((B A))
retractcon(A) fail
assertcon((A B)) 1
assertcon(A) assertcon(B)
assertcon(A) asserta(A)
retrac teon ((A B)) 1
retracteon(A) retractcon (B)
retraetcon(A) - retract(A)
BIBLIOGRAPHIC DATA SHEET
Report No UIUCDS-F-84-928
3 Recipients Accession No
4 T ide and Subt ltle
An Annotated Predicate Calculus Inference System (APCIS)
S Report Date
November 1984 6
7 Author(s)
Kah-Eng Pua 8 Performing Organization Rept
No
9 Performing Organization Name and Address
Department of Computer Science University of Illinois Urbana IL
10 ProjectTaskWork Unit No
11 Contract Grant No NSF DCR 84-06081 ONR N00014-82-K-0186
12 Sponsoring Organization Name and Address
National Science Foundation Washington DC
13 Type of Report amp Period Covered
14
15 Supplementary Notes
16 Abstracts
This paper describes a deductive inference system called APCIS (Annotated Predicate Calculus Inference System) APCIS is able to carry out inferences from expressions involving numerical quantifiers selectors disjunctions of non-negated terms negated terms disjunctions of negated terms equivalences and exceptions It is also able to count the numbers of occurrence of a given simple term or a conjunction of terms The design of contradiction and the treatment of the disjunction of non-negated terms allow APCIS to accept Horn clauses as well as non-Horn clauses and to carry out inferences from them This feature makes APCIS more general than Prolog
17 Key lords and Document Analysis 170 Descriptors
APC (Annotated Predicate Calculus) APCIS (Annotated Predicate Calculus Inference System) Horn Clause Numerical Quantifier Prolog Selector
17b IdentifiersOpen-Ended Terms
17c COSATI FieldGroup
18 Availability Statement 19 Security Class (This
Re~f~~IA~SIF IFf)
21 ~o of Pages
49 211 ecurity Class (This
PageUNCLASSIFIED
22 Price
FOA NTIS n (10middot70 usco-oc 40329-
1
next level 102 will take care of the searching of simple terms and 101 will deal with the
disjunctions of non-negated terms in the database We will come back to them in Section 4
At the first glance one may feel that the above translated Queries are Quite complicated
However a closer examination will reveal that they are not so Queries lb 3b and 4b can each be
categorized as a conditional query which is a distinct feature of APCIS wherels queries 2b and
5b lre asking simple facts in the database
To handle conditional queries we consider two cases First if the queries involve a
special clause contradition we invoke the built-in function el3ule(X Y) which will look for the
desired contradiction clause in the database Second if the queries do not involve the clause
contradiction we activate a defined Prolog predicate condi to take care of the necessary
searching (To avoid confusion the reader is urged to compare expressions started with the same
number in the above three sets of example)
To handle a query which asks a simple fact we surround each disjunction of terms with
the functor sol as in the example 2b or crown each simple term with the functor 802 as in the
example 5b
32 TranslatIon of Negated Term And Disjunction of Negated Terms
One feature of APCIS is its ability to handle input expressions consisting of only negated
term or a disjunction of negated terms in the forms
or
2 -(AI) v ~(A2) v v ~(An)
To handle the above two forms a special clause with clause head contradiction is
created This special clause head has only one argument which is either a term or a set of terms
grouped together in the form
8
(AI A2 An)
The right-hand side of the clause contradiction is exactly same as the argument in the clause
head For example the above two forms involving negated terms will be translated into the
corresponding forms as follows
1 contradiction( A ) shy
A
2 contradiction(( AI A2 An )) shy
AI A2 An
The design of the clause with clause head contradiction will greatly enhance the inference power
of APCIS (see the example in Section 44)
33 Translation ot Disjunction ot Non-negated Terms
Another feature of APCIS is its ability to handle input expressions involving a
disjunction of non-negated terms in the forms
1 Al v A2 v v An
or
2 Bl amp 32 amp amp Bm ==gt Al v A2 v v An
Unlike Prolog which accepts only Horn clauses APCJS will accept Horn clauses as well
as non-Horn clauses which take the above two forms The inference from non-Horn clauses is
made possible by the two defined predicates sol lnd s02 discussed in Section 42 and Section 43
respectively (see also the example in Section 44) In the APC translator the above two forms are
transbted into the corresponding forms as follows
1 Al v A2 v v An
2 Al v A2 v v An shy
g
Bl B2 Bm
34 Futher Transformation of Exceptions and Equivalences
To provide some backgrounds for the discussion of the further transformation of
exception and equivalence relations we will lirst reproduce the three goals in the Step 2 of the
APe translator discussed in Section 32 of [31
First expressions involving implication or the form A ==gt B will be transformed to
Second expressions with exception symbol or the form A - B will be changed to the
form ( A lt=gt -(B) ) amp ( -(A) lt=gt B)
Tbird expressions with equivalence symbol of the form -(A) lt=gt B or of the form
A lt=gt -(B) will also be converted to ( A lt=gt -(B) ) amp ( -(A) lt=gt B ) since tbere are
logically identical to exception relations Also expressions with equivalence symbol of the form
A lt=gt B or -(A) lt=gt -(B) will remain the same
After the Step] of the APe translator both sides of any transformed expression with
lt = gt symbol will be treated separately as if they are two independent expressions In the
Step 10 of the APe translator each side of lt=gt will again be treated separately and
transformed into a form similar to an transformed input query (see Section 31) Two examples
are given below
1 state(on) lt=gt -( state(olJ) )
2 all( 1 bot(l) amp humid(l) - winter(I) )
They will be transformed in the Step 2 or the APe translator into
1
(state(on) lt=gt -( state(off) ) ) amp ( -( state(on) ) lt=gt state(olJ) )
2
10
( hot(l) amp humid(l lt=gt -(winter(l)) ) amp
( -( hot(l) amp humid(l)) lt=gt winter(I)
In Step la they will again be transformed to
1
so2( state(on) ) lt=gt so2( contradiction( state(oH) ) )
so2( contradiction( state(on) ) ) lt=gt so2( state(oH) )
2
( s02(hot(XI)) so2(humid(XI))) lt=gt so2( contradiction( winter(Xl ))
so2( contradiction(( bot(Xl) humid(Xl) )) ) lt= gt so2( winter(XI) )
There are two advantages in the treatment of exception and equivalence symbols in this
way First it will prevent Prolog program from going into an infinite loop which is difficult to
avoid if equivalent relation such as A lt=gt B is transformed into the logically equivalent form
( A ==gt B) amp ( B ==gt A) Second by maintaining both sides of lt=gt symbol in
query form the searching on either side caD be done more easily and efficiently since the form
is already processed and does not need any further transformation
Inference Mechanism
As mentioned at the end of Section 31 goo sol and s02 each forms a part of the
inference mechanism of APCIS with goo occupying the top level and 80) and 802 the second
level In addition to these countl count2 equlv and impll are also at the second level of the
inference mechanism We will go over all of them in the following sections
I goo
goo is essentially the starting point of the inference Whenever a translated query is
loaded to Prolog system from temp-fie goo will go through one or more of the following steps in
11
sequence
G 1 Check if the query asks for the numbers of occurrence of certain term(s) It so then
pass It to eountl and eount2 else go to G2
G2 The query will be passed down to sol or s02 (or both) to check i( any assertion in the
database can satisfy the query It the answer is positive then the query succeeds else
go to G3
G3 The query will be passed to equlv to carry out further searching It the searching is a
success then the query will be closed with a success else go to G4
G4 It the query is in the form A ==gt B then it will be passed to Impli It Impll
succeeds then done else the query will be closed with a (ailure
42 sol
801 and 802 together with dis and eon form the most complicated part of the APCIS
iorerence mechanism In this and the next section we will look at sol and s02 dis and eon will
be discussed in Section 44 We will close Section 44 with an example that illustrates the
materials presented in Section 42 through Section 44
sol is at the second level of the inference mechanism It will deal with any disjunction of
non-negated terms For any disjunction passed to it it will go through one or more of the
following steps in sequence
S1 Check if any term In the disjunction can be satisfied by any term or clause in the
database without contradiction It so then done else go to S2
S2 Pass the disjunction together with another disjunction (and its tlil) picked up from
the database to dis It dis succeeds then done else go to S3
S3 Pass the disjunction down to equlval which will check if any term in the disjunction
matches either side of any equivalence relation in the database It such a match is
found then check if the other side of the equivalence C3n be satisfied It so then done
else the goal fails
43 s02
s02 is also at the second level of the inference mechanism It will take care of all the
simple terms in the transl1ted query The following is the sequence that s02 wiII follow in
searching
S1 Check if the term passed to it caD be s3tisfied by any term or clause in the d3tabase
without contradiction It so then done else go to S2
S2 Pass the term together with a disjunction of terms (and its tail) picked up from the
database to dis If dis succeeds then done else the goal fails
44 dis and con
dis has three arguments In the first two clauses of dIs the first argument P v Q is
found in the database using the builtmiddotin functiol clause and the third argument R is the tair of
the term or the clause P v Q If P v Q is not a clause but a term R will be instantiated to trUE
The second 3rgument comes from either lIol or 802 and thus takes the form of either X v Y (a
disjunction of terms) or T (3 simple term)
All the clauses of dis together with con will perform the searching as exemplified in the
following algorithm (we will keep the notationsin this section)
01 Check if every term in P v Q is in X v Y It so then go to 03 else go to D2
02 For any term (in P v Q) which is not in X v Y or does not match T perform the
following tests
a Check if the term (in P v Q) has already been negated in the datab3Se (ie check if
the contradiction of the term exists in the d3tabase) If so then repeat D2 for other
terms not found in X v Y or not matching T else go to b
13
b Check if the contradiction of the term matches either side of any equivalence
relation in the database If such a match is found then check if the other side of the
equivalence can be satisfied If so then repeat O~ for other terms not found in X v Y
or not matching T else the goal fails
It all the terms (in P v Q) which are not in X v Y or do not match T survive either one
of the above two tests then go to 03
03 This step is essentially done by eon whose goal is to satisfy the tail R of P v Q It
con succeeds then done else the search fails
To close this section we will give an example to illustrate what we have covered In
Section 42 through Section 44
Example Assume that we already haye the following expressions in the database
horse(skml) v dog(skmI)
contradiction(( dog(XI) ))shy
dog(XI)
query goo(( soZ horse(X)) ))
This query will be passed to 802 which will check it the term horse() can be satisfied iu Step S 1
of Section 43 It is a failure So we now go to Step S2 In this step we pick up the disjunction
horse(~kml) v dog(skml) (and its tail true) in the datab3Se and pass it together with the term
horse(X) to dis We are now in Step 01 of Section 44 In this step we find that dog(skml) does
not match horse(X) So we have to go to Step 02 In Step 023 We find that the term dog(skml)
has already been negated (the second expression in the database) So we go to next step 03 Since
the tail of the disjuDction horse(skml) v dog(skml) is the atom true con is satisfied and the
query succeeds
45 countl and count2
countl and count2 are responsible for the counting of tbe numbers of occurrence of a
given simple term or a conjunction of terms They are activated by input queries in the form
q( exists( X whatnum amp P) )
where whatnum is the l~bel for activating the counting of the numbers of occurrence of P which
can either be a term or a conjunction of terms
countl will count the number of term(s) which will satisfy P and associate(s) with
numerical quantification(s Two counters are set to update the lower and upper boundary or the
scope or the numfrical quantifications encountered
The contents of the two counters are then passed to count2 which is responsible for the
counting or the following three types of term First term(s) which will satisfy P and associate(s)
with existential quantification(s Second term(s) which will satisfy P and has(have) Prolog atom
as its(thfir) argument(s) Third term(s) that will satisfy P and itself(themselves) is(are) Prolog
atom(s )
46 equiv
equlv will be activated only after sol and B02 have failed The first two goals of equlv
are similar to that of Step S3 in Section 42 and Step D2b in Section 44 The third goal or equiv
makes possible the inference on either side of any equivalent relation For example if we type the
following three expressions to Prolog in assertion mode
l all( X hot(X) amp humidX) - winter(X)
2 all( X hot(X) amp bumid(X) ==gt unpresent(X))
3 - ( exists( X winter(X) ) )
and then ask APCIS in query mode
q( cxists( X unpresent(X) ) )
15
APCIS with the aid of equlv will be able to answer yes to this query
41 lmpll
lmpll can be considered as the last attempt that APCIS would make to satisfy a
query It is activated only after equlv has failed It will first check if the query is conditional If
so it will convert the implication symbol to equivalence symbol and search if such an equivalent
relation can be found in the database If so a success Otherwise a failure
5 More on the Inference Mechanism
Having looked at all the subparts at the top two levels of the inference mechanism we
are ready to look at other subparts at lower levels
51 num and cnum
One distinct fe3ture or APCIS is its ability to deal with numerical quantifications As
mentioned in Section 31 input queries and assertions will undergo different transformations in
the last step (Step 10) of translation This also holds true for expressions involving numerical
quantifications Consider the following expression
exists( 6 X horse(X) )
If it is entered to Prolog via assertion mode we will after going through all the steps of
translation have the rollowing entered to the database
horse(sk n I
number(sknl6)
Now if we want to ask Are there more than five horses 7 and type in
q( exists( gt5 X horse(X) ) )
1amp
APCIS will translate the question and enter to Prolog the following query
goo(( s02( horse(X) ) s02( num( X gt5 )) ))
Note that the term number(slml 6) in the database and the term num(X gt S) in the query are
different predicates and this difference is exactly where the power of the clause num(X N)
defined in APCIS comes from When the clause num(X N) in APCIS is activated it will search
through the database to see if there is any term of the form number(X I) whose first argument
matches the first argument of num(X Y) in the query It a match is found the second arguments
of both num(X Y) in the query and number(ltI) in the database will be passed to cnum in
APCIS
The job of cnum is to compare the numerical messages carried by the second
argument or the term rlum(X Y) in the query and the second argument of the term rlumber(X I)
in the database to see if they match with each other according to the rules defined in cnum
While there are 25 rules for such matching purposes the idea is simple
Imagine that the second argument Y of the term num(X Y) in the query
and the second argument I of the term num()( I) in the database each occupies a
place in an integer line (Le the integer line in mathematics) To have a match
the domain covered by Y should contain the domain covered by L
As an example the answer to the above query is positive since the domain of gt5
contains the domain or 6
Before closing this section we will bring out a speciaJ translation aspect of expressions
involving numbers by an example We first type to APCIS the Collowing expressions in assertion
mode
1 aU(X all(Y father(X Y) amp number(Y gt6) ==gt has_manY3hildren(X) ))
2 exists(X exists( 12 Y Cather(X Y) ) )
11
After going tbrougb all tbe translation steps tbe Collowing two expressions will be entered to tbe
database
I
bas_many_cbildren( Xl ) shy
Cather( Xl X2 )
num( X2 gt6 )
2
Catber( sk m1 sk n2 )
number( skn2 12 )
lotice that whenev(gtr a term with Cunctor number appears at the rigbt-band side oC a Prolog
clause its Cunctor will be cbanged to num automatically This treatment will greatly cnbance tbe
inference power of the clause sbown in l above For instance iC we now ask tbe question
q( exists( X bas_many_children(X) ) )
The right hand side oC the clause l will match the two terms in 2 and tbe query succeeds
52 Bel and cael
A special feature of APe is tbat all predicates tbat express relations = = gt
gt= lt and lt= can be expressed explicitly using infix notations as relational statements
called selectors To handle selectors we defined Bel in APCIS
Every expression involving selectors will undergo different translations in assertion mode
and query mode For example the assertion
a( exists( [X Y] box (X) amp box(Y) amp (weigh t(X) gt weight(Y) ) ) )
will be translated into the following three terms and entered to tbe database
box( skml )
box( skm2 )
18
weight( skm 1 ) gt weight( skm2 )
Now it we want to ask Is it true that there exists two boxes of different weights and type in
q( exists( [X Yl box(X) amp box(Y) amp ( weight(X) = weight(Y) ) ) )
The question will be transformed to the following query and entered to Prolog
goo(( so( box(XI) ) s02( box(X2) ) so2( sel( weightXI) = weight(X2) )) ))
Note that the selector in the above query is surrounded by the functor set When any clause or
8el in APCIS is activated it will search through the database to see it there is any selector whose
two arguments (left and right side or any selector symbol) match the two arguments of the
selector in the query At the same time 8el will check iC the selector symbols (may be different) or
the two different selectors (one in the query and one in the database) satisfy the rules defined in
sel There are 12 matching rules defined in sel All oC them ~re straightforward and will not be
discussed here An example will be enough to explain how 8el works
Consider the execution of the above transformed query The first two terms in the query
are satisfied by the first two terms in the database and Xl and X2 are instantiated to skml and
skm2 respectively The third term of the query will be passed to eel (of APCIS) which finds a
match on each side of the two selectors (one in the query and one in the database) At the same
time the two different selector symbols gt and = are found to satisfy one of the rules in
8el As a result the query succeeds
To enhance the inference power of clauses involving selectors all the selectors appearing
on the rightmiddothand side oC any clause will be surrounded by a functor set The idea is similar to
that in the last part of the previous section
c8el is exactly the same as 8el functionally It provides a convenient way to compare
selectors when dis is being executed
19
8 Printing Result
Whenever a goal is successfully executed APCIS will not only response with a yes but
also print out the matched terms or clauses in the database This is made possible by the built-in
function bagor and the two predicates wout and prt defined in APCIS
7 Summary
In this paper a description of a deductive inference system called APCIS (Annotated
Predicate Calculus Inference System) has been provided APCIS is able to carry out inferences
from expressions involving numerical quantifiers selectors disjunctions of non-negated terms
negated terms disjunctions of negated terms equivalences and exceptions It is also able to count
the numbers of occurrence of a given simple term or a conjunction of terms
The main idea of APCIS is that each input APC expression is first passed to a
preprocessor ( ie APC translator ) which dissolves and transforms each APC expression into
Prolog expression(s) which will then be loaded to Prolog system The user bas to specify whether
each input expression is to be entered as an assertion or as a query by invoking either assertion
mode or query mode respectively Each assertion or query will undergo different transformations in
the preprocessor The different treatment of assertion or query not only allows a full uS1ge of the
Prolog inference mechanism but also makes possible a higher level of inexact pattern matching
exemplified by the examples in Section 51 and Section 52 where the four predicates num
cnum sel and csel are discussed This higher level of pattern matching increases the inference
power of APCIS greatly
The design of contradiction and the treatment of the disjunction of non-negated terms
allow APCIS to accept non-Horn clauses and to carry out inference from them This feature
makes APCIS more general than Prolog
20
While APCIS performs very well in many sets of arguments provided by the author it is
still too early to jump to conclusion that it can perform equally well in all types of problems In
any event the expressiveness of APC has greatly been retained in the present version of APCIS
and moreover some design ideas or APCIS mentioned in this paper are not restricted to APCIS
- they may be carried over to learning programs with narrower scopes
21
References
[1] W F Clocksin and C S Mellish Programming In Prolog Springermiddot Verlag Berlin Hpoundidelberg 1981
[2] R S Michalski A Theory and Methodology of Inductive Learning Chpt 4 Machine L earning Tioga Publishing Co Palo Alto CaliJornia 1989
[3] K-E Pua Translating Annotated Predicate Calculu8 to Prolog ISG Report 84middot1 UlUCDCSmiddotFmiddot918 University oj Illinois Urbana IL June 1984
22
Appendix A
APCIS Users Manual
1 Get Started
Users are urged to follow the steps depicted below
1 Get the PROLOG interpreter by typing
alias prolog mntb2sammutsammutprologprolog (Vax A)
or
alias prolog mntb2sammutsammutbinprolog (Vax B)
2 Load apc and infer by typing
prolog apc infer
When large APC expressions are expected we can increase the stlck by typingI
prolog -snnnn ape infer
where ns denote the number of stacks in decimal
3 When the wording LSW - PROLOG appears on the terminal we are reldy to interact
with APCIS The four modes by which we can invoke APCIS are summarized below
a Assert ion-Translation Mode
ta(X)
b Query-Translation Mode
tq(X)
c Assertion Mode
a(X
d Query Mode
q(X)
23
where Xs are APC expressions
2 Notations Used in APCIS
Below is a summary or notations used in APCIS
a Logical operators
amp
v
==gt
lt=gt
-
negation
conjunction
disjunction
implication
equivalence
exception
b Binary relation symbols in selectors
-
=
gt=
lt=
gt
lt
equal
not equal
greater or equal
smaller or equ al
greater
smaller
c Relational operators in numerical quantifiers
lt less than
lt= less than or equal
gt greater than
gt= greater than or equal
d BinlTY operator in numerical quantifier
range
e Universal quantifier
all(X p(X))
f Existential quantifier
exists(X p(X))
g Numerical quantifier
exists(I X p(X))
where p(X) is a formula
where X is a variable or a Jist of variables or the
form [HI~rj and p(X) a formula
where I repersents expression involving integer(s)
and operator(s) in c or d above and p(X) a formula
25
Appendix B
APCIS Program Listings
------------------------------- Program Name APCIS - Part 1 APC Translator
-------------------------------
op(3OO fx -)1
op(500 xfy amp)
oPt 500 xfy v)
op(600 xfx )
op(700 fx [gt= lt= gt lt ]) op(400 xfy [= gt= lt= gt lt ])1 op(900 xfy gt lt=gt -])1
steps(X Xg) shy
numbervars(X 1 J Step 1 change variables to iis
rmimp(X X) Step 2 conv(X X3) Step 3
rewrite(X3 X4) Step 4
negin(X4 X5) Step 5
dropexist(X5 X6 1]) Step 6
dropall(X6 X7) Step 7
distrib(X7 X8) Step 8 clausiCy(X8 X9 [J) Step 9
ta(X) shysteps(X Xg)
(( Xg = II nl
print( yes it is always true) )
( nl nl printcl(X9))) Step 10a
tq(X) shy
steps(X Xg)
prques(Xg)
28
Step 2 Removing implic3tions amp Transforming exceptions and equiv3lences
rmimpl( P - Q (PI lt=gt (QI) ) amp ((PI) lt=gt QI) ) -
rmimpl(P PI) rmimpl(Q QI)
rmimplnp) lt=gt Q (PI lt=gt -(QI)) amp nPI) lt=gt QI) ) - 1
rmimpl(P PI) rmimpJ(Q QI)
rmimpJ(P lt-gt -(Q) (PI lt=gt -(QI)) amp nPI) lt=gt QI) ) -
rmimpl(P PI) rmimpl(Q QI)
rmimpl( P lt=gt Q PI lt=gt QI ) - I
rmimpl(P PI) rmimpl(Q QI)
rmimpl( P ==gt Q -(PI) v QI ) - I
rmimpl(P PI) rmimpl(Q QI)
rmimpl( all(X P) aI(X PI) ) - 1
rmimpl(P PI)
rmimpl( exists(X P) exists(X PI) ) -
rmimpl(P PI)
rmimpl( exists(I X P) exists(I X PI) ) -
rmimpl(P PI)
rmimpl( P amp Q PI amp Ql ) -
rmimpl(P PI) rmimpl(Q Ql)
rmimpl( P v Q PI v QI ) -
rmimpl(P PI) rmimpl(Q QI)
rmimpl( -(p) -(PI) ) - I
rmimpl(p PI)
rmimpl( P P )
St~p 3 Converting numerical amp distinctive quantifiers
L Numerical quantifiers
examples of input forms
1 exists(gt= i X pIX)) where i is an integer
2 exists(i X pIX)) where i is an integer
3 exists(i j X pIX)) where i j are integers and iltj
4 exists(il v i2 X pIX)) where is are integers
examples of output forms of this step
1 exists(X pIX) amp number(X gt= i) )
2 exists(X pIX) amp number(X i) ) 3 exists(X pIX) amp number(X ij) ) 4 exists(X pIX) amp number(X il v i2) )
II Distinctive quantifiers
27
example or input Corm
exists([XYL p(X Y))
example or output Corm or this step
exists(X exists(Y p(XY)) )
conv(P lt=gt Q PI lt=gt QI) - 1
conv(P PI) conv(Q QI)
conv(al1(X P) all(X PI)) -
conv(P PI)
conv(exists(HIT] P) R ) - conv(P PI) convert distinctive quantifier
convtdis(exists([HIT]PI) R)
conv( exists(I X P) exists(X PIamp number(X I) )) -
conv(P PI) convert numerical quantifier
conv(exists(X P) exists(X PI)) - 1
conv(P Pl)
conv(P amp Q PI amp QI) - 1
conv(P PI) conv(Q QI)
conv(P v Q PI v QI) - t conv(P PI) conv(Q QI)
convC(P) -(PI)) -
conv(P PI)
conv(P Pl
convtdis(existsl[XL P) exists(X P)) - atomic(X) convtdis(exists[XIYj Pl exists(X R)) shy
convtdis(exists(Y P) R)
Step 4 Rewriting compound predicates andor compound selectors
Outputs are smiple predicates andor simple selectors
rewrite(P lt=gt Q PI lt=gt QI) - t rewrite(P PI) rewrite(Q QI)
rewrite(all(X Pl all(X PI)) - 1 rewrite(P PI)
rewriteexists(X P) exists(X PI)) - I rewriteP PI)
rewrite(P amp Q PI amp QI) - rewrite(P P 1) rewrite( Q Q 1
rewrite(P v Q PI v QI) - 1
rewrite(P PI) rewrite(Q QI)
rewriteC(P) -(PI)) - I
28
rewrite(P PI) rewrite(F(A B) R) -
rewrite(A AI) rewrite(B BI) re(F(AI BI) R)
rewrite(F(A) R) -
rewrite(A AI) re(F(AI) H)
rewrite(F(A B C) R) -
rewrite(A AI) rewrite(B BI) rewrite(C CI) re(F(AI BI CI) R)
rewrite(F(A B C D) R) -
rewrite(A AI) rewrite(B Btl rewrite(C CI) rewrite(D DI) rc(F(AI BI CI Dl) H)
rewrite(PP)
re(F(A B v el (RI v R2) -
re(F(A Bl RIl re(F(A C) R2) reF(A B amp cl (RI amp R2)) -
re(F(A B) RI) re(F(A e) R2) re(F(A amp B C) (Rl amp R2)) -
re(F(A e) R 1) re(F(B C) R 2) re(F( v B el (R I v R2)) -
re(F(A el R I) reFB el R2) re(F(A amp Bl (R I amp R2)) -
re(F(A RI) re(F(BJH2) re(F(A v B) (R 1 v R2)) -
re(F(A) RI) re(F(B) R2)
re(F(A vB c Dl (RI v R2) -
re(F(A C D) RI) re(F(B C D) R2) re(F(A amp B C D) (RI amp R2)) -
re(F(A C D) Rll re(F(B C D) R2) re(F(A B v C D) (HI v R2)) -
re(F(A B D) RI) re(F(A C D) R2) re(F(A B amp C D) (HI amp R2)) -
re(F(A B D) RI) re(F(A C D) R2) re(F(A B C v D) (RI v R2)) -
re(F(A B C) R I) reF(A B D) R2) re(F(A B C amp D) (RI amp R2)) -
29
re(F(A B C) RI) re(F(A B D) RZ)
re(F(A v B e D E) (R I v R2)) -
re(F(A e D E) R I) re(F(B e D El R2) re(F(A amp B e D E) (RI amp RZ)) -
re(F(A e D El R 1) re(F(B e D E) R2) re(F(A B v e D E) (R I v R2)) -
re(F(A B D E) RI) re(F(A e D E) R2)
re(F(A B amp e D E) (RI amp R2)) -
re(F(A B D El RI) re(F(A e D E) RZ) re(F(A B e v D E) (R I v R2)) -
re(F(A B e El R 1) re(F(A B D E) RZ) re(F(A B e amp D E) (RI amp RZ)) -
re(F(A B e E) R I) re(F(A B D E) RZ)
re(F(A B e D vEl (RI v RZ)) - l
rc(F(A B C D) RI) re(F(A n e El RZ) re(F(A B e D amp El (RI amp RZ)) - ~
re(F(A B e D) RI) re(F(A B e El RZ)
re((A = B) (A = B)l-
re((A = Bl (A = 8)) -
retIA gt= BI (A gt= B)) -
re((A lt= B) (A lt= B)) -
re((A gt B) (A gt B))-
re((A lt Bl (A lt Bl)- re(A A)
Step) Bringing n(gation inwards
Degin(-(P) PI) - neg(P Pl)
negin(P lt=gt Q PI lt=gt Ql) - ~
negin(P PI) negiD(Q QI)
Degin(aU(X P) all(X PI)) - Degin(P PI) negin(exists(X P) exists(X PI))- negin(P PI) negin(P amp Q PI amp Ql) - Degin(P PI) negin(Q Ql)
Degin(P v Q PI v QI) - Degin(P PI) negin(Q QI) negin(P Pl
neg(-(P) PI) - negin(P PI)
neg(all(X P) exists(X PI)) - neg(P PI)
30
neg(exists(X P) all(X PI)) - neg(P PI)
neg(P amp Q PI v QI) - neg(P PI) neg(Q Ql)
neg(P v Q PI amp QI) - neg(P PI) neg(Q QI)
neg(P -(PH
Step 6 Dropping existnetial quanti6ers
dropexist(P lt=gt Q PI lt=gt QI Elerns) - dropexist(P PI Elerns) dropexist(Q QI Elerns)
dropexist(alJ(X P) all(XPI) Elerns)
dropexist(P PI [XIElernsJ)
dropexist(exists(X P amp nurnber(X Yraquo P2 Elerns) -
genfun(skn Newg) Fun = [NewgIElerns]
subst(FuD X P amp Dumber(X Y) PI)
dropexist(Pl P2 Elerns)
dropexist(exists(X P) PZ Elerns) -
genfun(skrn Newf) Fun = [NewfIElernsJ
subst(Fun X p PI)
dropex ist(P 1 P~ Elerns)
dropexist(P v Q PI v QI Elerns) - ~
dropexist(P PI Elerns) dropexist(Q Ql Elerns)
dropexist(P amp Q PI amp QI Elerns) - 1
dropexist(P Pl Elerns) dropexist(Q QI Elerns)
dropexist(P P _)
gen fun(R oot Newn arne) shy
getnurn(Root Nurn)
narne(Root Rootlist)
append(Rootlist[Nurnj Narnelist)
concat(Narnelist Newnarne)
getnurn(Root Nurn) shy
retract(currentnurn(Root Nurn 1 raquo
Nurn is Nurni + 1
asserta(currentnurn(Root Nurn))
getnurn(Root 1) - asserta(currentnurn(Root 1))
subst(New Old Val Val) - var(Val)
subst(New Old Old New) - 1 substNew Old Val Val) - atornic(Val)
31
subst(New Old Val Newval) shy
runctor(Val F N)
CUDctor(Newval F N)
subst_args(N New Old Val Newval)
subst_args(O J J - J J
subst_args(N New Old Val NewVal) shy
arg(N Val OldArg)
arg(N NewVal NewArg)
subst(New Old OldArg NewArg)
NI is N - I
subst_args(Nl New Old Val NewVal)
append([J L L) -
append([XILl] L2 [XIL3]) - append(Ll L2 L3)
Step - Dropping universal quantifiers
dropall(P lt=gt Q PI lt=gt QI)-
dropall(P PI) dropall(Q QI)
dropall(all(X P) PI) - ~ dropall(P PI)
dropall(P amp Q PI amp QI) -
dropall(P PI) dropall(Q QI)
dropall(P v Q PI v QI) -
dropall(P PI) dropall(Q QI)
dropall(P P)
Step 8 Distributing conjunctions over disjunctions
distrib(P lt=gt Q PI lt=gt Ql) - t distrib(P PI) distrib(Q QI)
distrib(P v Q R) -
distrib(P PI) distrib(Q QI)
distributing(PI v QI R)
distrib(P it Q PI it QI) -
distrib(P PI) distrib( Q QI)
distrib(P P)
distributing((P amp Q) v R PI amp QI) -
distrib(P v R PI) distrib(Q v R Ql)
32
distributing(P v (Q amp R) PI amp Ql) -
distrib(P v Q PI) distrib(P v R Ql)
distributing(P P)
Step 9 Packing each conjunction into clauses
c1ausify(P amp Q CI C2) -
clausiCy(P CI C3) c1ausify(Q C3 C2)
cbusiCy(P [d(A B)ICs] Cs) shy
inclause(P A [j B [I) 1
c1ausiry( C C)
inclause(P v Q A AI B B1) -
inc1ause(P A2 AI B2 Bl)
inclause(Q A A2 B B2)
inclausenp) A A B1 B) -
notin(P A) putin(P B B1)
inclause(P AI A B B) shy
notin(P Bl putin(P A AI)
notin(X [XU) - fail
notin(X [JLj) - notin(X L)
notin(X 1])
putin(X II [X]) - 1
putin(X [XILJ L) -
putin(X [YILJ [YILl]) - putin(X L Ll)
Step 1Oa Printing clauses
printcl([]) - nl nl
printcl(c1(AB)ICsj) - printcl(A Bl nl printcl(Cs)
printcl(L II) - printdis(IL) prinr)middot
printclHl L) - prin(contradiction(() printconl(rL)
print()) - ) printconj(rL) prinr )
printcl(Ll L2) shy
printdis(ILl) print( - ) printconj(rL2) prin()
printdis(S[Lj) - printcbar(SL)
33
printdis(S[LILs]) - printchu(SL) prin( v) printdis(SLs)
printconl(S[LI) - printchar(SL)
printconl(S[LILs]) - printchar(SL) prin( ) printconl(SLs)
printconj(S[L]) - tab(3) printchar(SL)
prin tconj( S [L IL sl) shy
tab(3) printchar(SL) print( ) printconj(SLs)
printchar(SP) shy
atomic(P)
name(P L)
L = [IT]
concat([XIT NewP)
prin(~ewP)
printchar(SP) shy
atomic(P)
prin(P)
printchar(SA lt= gt B) -
prin((l clausify(A AI [j) pl(eAl) prin())
print lt=gt )
prin(() cbusify(B Bl [I) pJ(eBl) prine))middot
printchar(rnumber(X N)) shy
prin(num() printchar(rx) prin( )
printchar(rN) prinC))
printchar(rF(A B)) shy
seJec(F(A B))
prinCsel() printchar(rA)
prin( F ) printchar(rB) prinC))
printchar(SF(A B)) shy
( selec(F(A B)) F = infix )
printchar(SA) prin( F ) printchar(SB)
printchar(SF(A)) shy
(F= prefix gt= F= prefix lt= F= prefixgt F= prefix lt )
prin(F ) printcbar(SA)
printchar(SP) shy
functor(P F MaxN)
prin(F ()
Nl is MaxN - 1
putout(S N 1 P MaxN)
34
prin())
putout(S 0 P MaxN) -
arg(~laxN P Argu)
prin tchar(SArgu)
putout(S N p MaxN) shy
Nt is MaxN - N arg(NI P Argu)
printcbar(SArgu )
prin( )
N2 is N - 1
putout(S N2 P MaxN)
selec(FA B)) shy
( F= infix = F= infix f= F= infix gt=
F= infix gt F= infix lt= F= infix lt )
35
----------------------------------Program Name APClS - Part 2 Inference Mechanism ---------------------------------- a(X) shy
steps(X X9)
(( X9 =[] nl
print( yes it is always true) )
( X9 =[cI(IJ[])] nl
print( no it is always false) )
( nl nl printel(X9) Step 1Oa
tell(temp_file) printel(X9) e1ose(temp_file) consult(temp_6Ie) ))
q(X) shy
asserta( in pt(X))
steps(X X9)
(( X9 = [] print(middot~H~~middot~t~)
print(THE AiSWER IS YES)
print( ilgIQlQl(~) )
( X9 = [e1([j [j)] Pr1nt ( OJ fi(i I~ iii Ij)middot(i)(i) fiyenQ)riiio(i)(ij)(i)fj)fiyen1li1il1li1il)__ gtw~ __~_~ _~~_ ~_-=~
print(THE ANSWER IS NO ) print() )
( teI1(temp_6Ie)
prques(X9) Step 1Ob
close(temp_file)
nl print(Let me think about it) nl
consult(temp_6Ie) ))
retrac t( in pt(X))
Step lOb Printing question
prques(lcl(A 8)1) - prin(goo(() pl(qA 8) print()))
prques([c1(A 8HCs]) - prin(goo(() pl(qA 8) print() pl(q Cs)
pl(e [c1(A 8)]) - pl(eA 8)
pl(q [c1(A 8)]) - pl(qA 8) print()))
pl(S [e1(A B)ICs]) - pl(SA B) prin( ) pl(S Cs)
38
pl(q [j L) - prin(c1ause(contradiction(() pcont(qL) prin())_))
pl(S [I L)- prin(so2(contradidion(() pcont(SL) print))))middot
pl(S [L] []) - prin(so2() pcbar(SL) prin())
pl(S L [J)- prinsol() plett(SL) print))
pl(S [L] LI) - prin(condi(() pchar(cL)
prin(() pcont(S Ll) prine))))
pl(S L Ll)- prin(c1ause() plert(cL)
prin(() pcont(S Ll) prine)))
plert(S[LJ) - pchar(SL)
plert(SjLILsj) - pcbar(SL) print v) pleCt(SLs)
pcont(S[L]) - pchar(SL)
pcont(S[LILsj) - pcbar(SL) prinr ) pcont(SLs)
pcbar(SP) shy
atomic(P)
name(PL)
( L = [IT] L = [5 k miT] L = [5 k niT] )
concat[XITj NewP)
prin(0JewP)
pchar(SP) shy
atomic(P)
prin(P) pchar(SA lt=gt B) -
prin(() dausify(A AI []) pl(eAI) prin())
prinr lt=gt ) prin(() dausify(B BI ]) pl(eB) print))
pchar(Snumber(X N)) shy
prin(num() pchar(SX) prin()
pchar(SN) prinr))
pcbar(SM N) - prin(M N)
pcbar(cF(A B)) shy
selec(F(A Braquo
pcbar(cA)
prine F ) pchar(cB) pchar(SF(A B)) shy
selec(F(A B))
prin(sel() pchar(SA)
print F ) pchar(SB) print)) I
31
pc har(SF(A)) shy
( F= prefix gt= F= prefix lt= F= prefixgt F= prefix lt )
prin(F ) pchar(SA)
pchar(SP)shy
runctor(P F MaxN)
prin(F ()
011 is MaxN - 1 pout(SNl P MaxN)
print) )
pout(S 0 P M3xN) - 1
arg(~bxN P Argu)
pchlr(SArgu )
pout(S N P MaxN shy
Nl is MaxN - N
arg(Nl P Argu)
pchar(SArgu
prin( )
N2 is N - 1
pout(S N2 P ~13xN)
Comparing numbers in numerical quantifiers
num(XN) shy
number(X I)
cnum(N 1) ~
cnumlaquo=01 lt=I- N gt=I
cnumlaquo=J lt I) - N gt=1-1
cnumlaquo=NIJ) - N gt=J 1
cnumlaquo=N J)- integer(I) N gt=I~
cnum(gt=N gt=1) - N lt=1
cnum(gt=N gt I) - N lt=1+ 1 cnum(gt=NIJ) - N lt=1
cnum(gt=N lt=1)- N lt=1
cnum(gt=N lt I) - N lt=1 L cnum(gt=N 1)- integer(I) N lt=1
cnum( lt N lt 1)- N gt=1 L
38
cnum( lt N lt=1) - N gt I cnum( lt NLJ) - N gt J
cnum( lt N 1)- integer(I) N gt 1
cnum(gt N gt I) - N lt=1 cnumlgt i gt=1) - N lt I
cnum(gt N lt=1) - N lt=0
cnum(gt N lt I) - N lt=0
cnum(gt iIJ) - N lt I cnum(gt N 1)- integer(I) N lt I
cnum(~LN lt=1) - M=I N gt= I l
cnum(~LN lt I) - M=l N gt= I-I
cnum(~LNLJ) - M lt =1 N gt = J
cnum(~1N 1)- integer(I) M lt= I N gt= I
cnum(- N) - integer(N)
Comparing selectors
sel(X = Y) shyX= Y
sel(X I=Y) shy(X I=Y X lt Y Xgt Y)
sel(X gt Y) shyXgt Y
sel(X lt Y) shyXlt Y
selX gt=Y) shy(X gt=Y X= Y Xgt Y)
se(X lt=Y) shy
(X lt=Y
X= Y
X lt Y)
csel(infix = infix =)
39
csel(infix = infix = csel(infix = infix gt)
csel(infix = infix lt) csel(infix gt infix gt) cseJ(infix lt infix lt) csel(infix gt= infix gt=) csel(infix gt= infix gt csel(infix gt= infix =)
csellinfix lt= infix lt=) csel(infix lt= infix lt) csel(infix lt= infix =)
Finding solutions
sol(X v Y) -
(( notetra(X) eon(X) ( sol(Y) )
( c1ause(P v Q R) not(cketra(P v Q))
dis(P v Q X v Y R) ~ )
( A lt=gt B equival(A lt=gt B X v Y) ~ I) sol(X) - ~ notetra(X) eon(X)
so~(X) - notetra(X)
( con (X)
( clause(P v Q R) not(ekctra(P v Q)) dis(P v Q X R) I)
cketra(P v Q) -
eketra(P) eketra(Q) eketra(F(I J)) shy
selec(F(I J))
c1ause(contradiction(sel(F(IJ))) _I
eketra(number(W I)) -
clause(cootradietion(num(Wl)) - eketr(P) shy
clause(contradiction(P) - 1
notctra(P) shy
not( e lause( con tradiction(P) _))
40
Searching (or disjunctions
dis(P v Q X v Y R) - dis(P X v Y R)
dis(Q X v Y R) con(R)
dis(P v Q X R) -
dis(P X R) dis(Q X R) con(R
dis(P X v Y R) - clause(contradicton(Pl J 1
dis(F(I J) sel(G(I J)) v Y R) - csel(G Fl dis(number(WI) num(W N v Y R) - cnum(N I)
dis(P P v Y R) -
dis(P X v Y R) - dis(P Y R)
dis(F(I J) seJ(G(IJ)) R) - csel(G F)
dis(number(WI) num(WN) R) - cnum(N I) dis(P P R) - 1
dis(FJ J X R) shy
( ckctra(F(IJ) cbeckeq(seJ(F(IJ))) )
dis(number(W Il X R) - ( ckctra(number(WI)) cbeckeq(num(WI)) )
dis(P X R) shy( ckctra(P) cbeckeq(P) ) 1
cbeckeq(P) shy
(( A lt=gt so2(contradiction(P))
bagof(A A [jj) ) ( so2(contradiction(P)) lt=gt B
bagof(B B Uj) ))
ckeq(A) shy
( so2(A) lt=gt B B lt=gt so2(A) ) bagof(B B UJ)
con((P Q)) -
clause(P R) con(R) con(Q) con(true) -
con(contradiction(P)) - clause(contradiction(P) J
con(cause(X Y)) - cause(X Y)
con(sel(X)) - sel(X)
con(num(X Y)) - num(X Y) con(P)- (( dause(P R) (con(R) ckeq(R)))
colJectin(P) )
collectin(P) shy
bagof(S (c1ause(P S) S = true) [L LIJ )
mkcon(L Ll L)
bagor(l (L2 ) UJ) L
mkcon((A AI) (B B1) (sol(A v B) e D)) -
mkcon(A B1 e) mkcon(A1 (B Bl) D)
mkcon(A (B B1) (sol(A v B) e)) -
mkcon(A Bl e)
mkcon((A AI) B (sol(A v B) e)) middot1
mkcon(Al B e)
mkcon(A B sol(A vB))
Searching ror equivalences
equival(A lt=gt B X v Y) - 1 ( equival(A lt=gt B X) equival(A lt=gt B Y) )
equival(s02(A) lt=gt 502(B) A) - clause(B _I equival(s02(B) lt=gt 502(A) A) c1ause(B _I
Top level or inrerence mechanism
goo((s02(whatnum) P)) -
getatm(P Xl
bagor(number(X Y) ( P so2(number(X Y)) ) A )
count1(A 00 L R) nl
bagor(X P B )
count2(B L R Ll Rl) nJ print()
(( LI = 0 Rl = 0 print(THE ANSWER IS ) nl
(( Ll = Rl prin(-Jumber or ) prn(P) print(is Ll) )
( Rlgt20000 prin(Number or I prn(P) print(is LI or more) )
42
( prin(Number of ) pfn(P) print( is from Ll to Rl) )) )
( print(THE ANSWER IS NO I )) print()
goo(X) shy
(( bagof(X X L) L = [I nl print()
print(THE ANSWER IS YES) nl wout(L) print() )
( equiv(X L) nl print()
print(THE ANSWER IS YES) nl wout(L) print(-) )
( c1ause(inpt(A ==gt B) _I ( impli(A B Z) impli(B A Z) ) print(l~Hl)
printTHE ANSWER IS YES) nl print(Z) print(Hj~(fH~) ))
goo(X) print( Hg)
print(THE ANSWER IS NO ) print( lH~lH~gg9l9lmiddotmiddot~Q(gmiddot)
00 Semhing for implications in equiV3lent relations
impli( B Z) shyt-ell( z1) prin(templ() pchn(S A lt=gt B) print()) close ( zl) consult(zl) templ(Z)
unload zl Z
Searching for equivalence
equiv (X L)
(( X lt=gt Y
equ(Y YI)t bagof(Y Yl L) L = [j )
(Y lt=gt X equ(Y YI) bagof(Y Yl L) L = [J )
( X = F(New)
clause(~ew T) makeup(T Tl)
(( Tl lt=gt B
equ(B Bl) bagof(Bl Bl M) M = [j L=[Newl )
(A lt=gt TI
equ(A AI) bagof(Al AI M) M = 1] L=INewj )) ))
makeup((A B) (AI Bl)) -
makeup(A A1) makeup(B BI)
makeup(A so2(A))
equ((A B) (AI BI)) -
equ(A AI) equ(B Bl)
equ(sol(X v Y) sol(XI v Yl)) -
equ(X XI) equ(Y YI)
equ(so2(X) so2(XI)) -
equ(X XI)
equ(contradiction(X) clJuse(contradiction(X) X) ) -
equ(X X)
Counting numbers
getatm((A B) X) -
( getatm(A X) getatm(B X) )
getatm(so2(F(X)) X) -
getatm(so2(X) X) - atom(X)
countl([J L R L R) -
countl([number(X Y)IT] L R L2 R2) shy
(( Y = (gt=~) LI is L + N Rl is R + 20001 l )
( Y = (gt N) LI is L+ N+ 1 RI is R + 20002 )
(Y == laquo=~) LI is L + 1 Rl is R + N )
(Y = laquo N) LI is L + 1 RI is R+N-I)
(Y == IJ LI is L + I Rl is R + J ) ( Y == N L1 is L + N RI is R + N ))
count1(T LI R 1 L2 R2)
count2(fJ L R L R) - 1
count2([XITJ L R L2 R2) shy
name(X Xl)
(( Xl = sknj LI is L Rl is R )
44
( Xl = Iskmj L1 is L + 1 RI is R + ZOOO1) ( LI is L + I RI is R + I ))
count2(T LI RI L2 R2)
pfn((A B)) - pfn(A) prn(B)
pCn(so2(F(X))) - prin(F )
prn(so2(X)) - atom(X) prin(X ) prn (so2(X))
Printing result
wout([XlJ - prt(X) nl woutf[xIY]) - prt(X) nl nl wout(Y)
prt(e(A B)) -
prt(A) prinr 8 ) prt(ltE) prt(eA) - prt(A)
prt(c(A EJ) - prin() prt(A) prine ) prt(B) prin(T)
prt(c A) - prt(A) prt((A E)) - ~
prt(A) nl prt(E) prt(sol(X v Y)) - ~
prt(X) prinC v) prt(Y) prt(A lt=gt B) -
prt(e A) prinC lt=gt ) prt(e B) prt(sol(X)) - prt(X)
prt(so2(X)) - prt(X
prt(c1ause(X Y)) - prt(X)
prt(contradiction(X)) - prin(contradiction() prt(cX) prinr))middot prt(num(XY)) - prin(number(X Y)) prt(sel(X)) - prin(X) prt(X v Y) - prt(X) prin( v) prt(Y) prt(X) prin(X)
Handling conditional queries
condi((Y Xl) shy
assertcon(X) Y
45
retractcon(X)
condi((B A))
retractcon(A) fail
assertcon((A B)) 1
assertcon(A) assertcon(B)
assertcon(A) asserta(A)
retrac teon ((A B)) 1
retracteon(A) retractcon (B)
retraetcon(A) - retract(A)
BIBLIOGRAPHIC DATA SHEET
Report No UIUCDS-F-84-928
3 Recipients Accession No
4 T ide and Subt ltle
An Annotated Predicate Calculus Inference System (APCIS)
S Report Date
November 1984 6
7 Author(s)
Kah-Eng Pua 8 Performing Organization Rept
No
9 Performing Organization Name and Address
Department of Computer Science University of Illinois Urbana IL
10 ProjectTaskWork Unit No
11 Contract Grant No NSF DCR 84-06081 ONR N00014-82-K-0186
12 Sponsoring Organization Name and Address
National Science Foundation Washington DC
13 Type of Report amp Period Covered
14
15 Supplementary Notes
16 Abstracts
This paper describes a deductive inference system called APCIS (Annotated Predicate Calculus Inference System) APCIS is able to carry out inferences from expressions involving numerical quantifiers selectors disjunctions of non-negated terms negated terms disjunctions of negated terms equivalences and exceptions It is also able to count the numbers of occurrence of a given simple term or a conjunction of terms The design of contradiction and the treatment of the disjunction of non-negated terms allow APCIS to accept Horn clauses as well as non-Horn clauses and to carry out inferences from them This feature makes APCIS more general than Prolog
17 Key lords and Document Analysis 170 Descriptors
APC (Annotated Predicate Calculus) APCIS (Annotated Predicate Calculus Inference System) Horn Clause Numerical Quantifier Prolog Selector
17b IdentifiersOpen-Ended Terms
17c COSATI FieldGroup
18 Availability Statement 19 Security Class (This
Re~f~~IA~SIF IFf)
21 ~o of Pages
49 211 ecurity Class (This
PageUNCLASSIFIED
22 Price
FOA NTIS n (10middot70 usco-oc 40329-
8
(AI A2 An)
The right-hand side of the clause contradiction is exactly same as the argument in the clause
head For example the above two forms involving negated terms will be translated into the
corresponding forms as follows
1 contradiction( A ) shy
A
2 contradiction(( AI A2 An )) shy
AI A2 An
The design of the clause with clause head contradiction will greatly enhance the inference power
of APCIS (see the example in Section 44)
33 Translation ot Disjunction ot Non-negated Terms
Another feature of APCIS is its ability to handle input expressions involving a
disjunction of non-negated terms in the forms
1 Al v A2 v v An
or
2 Bl amp 32 amp amp Bm ==gt Al v A2 v v An
Unlike Prolog which accepts only Horn clauses APCJS will accept Horn clauses as well
as non-Horn clauses which take the above two forms The inference from non-Horn clauses is
made possible by the two defined predicates sol lnd s02 discussed in Section 42 and Section 43
respectively (see also the example in Section 44) In the APC translator the above two forms are
transbted into the corresponding forms as follows
1 Al v A2 v v An
2 Al v A2 v v An shy
g
Bl B2 Bm
34 Futher Transformation of Exceptions and Equivalences
To provide some backgrounds for the discussion of the further transformation of
exception and equivalence relations we will lirst reproduce the three goals in the Step 2 of the
APe translator discussed in Section 32 of [31
First expressions involving implication or the form A ==gt B will be transformed to
Second expressions with exception symbol or the form A - B will be changed to the
form ( A lt=gt -(B) ) amp ( -(A) lt=gt B)
Tbird expressions with equivalence symbol of the form -(A) lt=gt B or of the form
A lt=gt -(B) will also be converted to ( A lt=gt -(B) ) amp ( -(A) lt=gt B ) since tbere are
logically identical to exception relations Also expressions with equivalence symbol of the form
A lt=gt B or -(A) lt=gt -(B) will remain the same
After the Step] of the APe translator both sides of any transformed expression with
lt = gt symbol will be treated separately as if they are two independent expressions In the
Step 10 of the APe translator each side of lt=gt will again be treated separately and
transformed into a form similar to an transformed input query (see Section 31) Two examples
are given below
1 state(on) lt=gt -( state(olJ) )
2 all( 1 bot(l) amp humid(l) - winter(I) )
They will be transformed in the Step 2 or the APe translator into
1
(state(on) lt=gt -( state(off) ) ) amp ( -( state(on) ) lt=gt state(olJ) )
2
10
( hot(l) amp humid(l lt=gt -(winter(l)) ) amp
( -( hot(l) amp humid(l)) lt=gt winter(I)
In Step la they will again be transformed to
1
so2( state(on) ) lt=gt so2( contradiction( state(oH) ) )
so2( contradiction( state(on) ) ) lt=gt so2( state(oH) )
2
( s02(hot(XI)) so2(humid(XI))) lt=gt so2( contradiction( winter(Xl ))
so2( contradiction(( bot(Xl) humid(Xl) )) ) lt= gt so2( winter(XI) )
There are two advantages in the treatment of exception and equivalence symbols in this
way First it will prevent Prolog program from going into an infinite loop which is difficult to
avoid if equivalent relation such as A lt=gt B is transformed into the logically equivalent form
( A ==gt B) amp ( B ==gt A) Second by maintaining both sides of lt=gt symbol in
query form the searching on either side caD be done more easily and efficiently since the form
is already processed and does not need any further transformation
Inference Mechanism
As mentioned at the end of Section 31 goo sol and s02 each forms a part of the
inference mechanism of APCIS with goo occupying the top level and 80) and 802 the second
level In addition to these countl count2 equlv and impll are also at the second level of the
inference mechanism We will go over all of them in the following sections
I goo
goo is essentially the starting point of the inference Whenever a translated query is
loaded to Prolog system from temp-fie goo will go through one or more of the following steps in
11
sequence
G 1 Check if the query asks for the numbers of occurrence of certain term(s) It so then
pass It to eountl and eount2 else go to G2
G2 The query will be passed down to sol or s02 (or both) to check i( any assertion in the
database can satisfy the query It the answer is positive then the query succeeds else
go to G3
G3 The query will be passed to equlv to carry out further searching It the searching is a
success then the query will be closed with a success else go to G4
G4 It the query is in the form A ==gt B then it will be passed to Impli It Impll
succeeds then done else the query will be closed with a (ailure
42 sol
801 and 802 together with dis and eon form the most complicated part of the APCIS
iorerence mechanism In this and the next section we will look at sol and s02 dis and eon will
be discussed in Section 44 We will close Section 44 with an example that illustrates the
materials presented in Section 42 through Section 44
sol is at the second level of the inference mechanism It will deal with any disjunction of
non-negated terms For any disjunction passed to it it will go through one or more of the
following steps in sequence
S1 Check if any term In the disjunction can be satisfied by any term or clause in the
database without contradiction It so then done else go to S2
S2 Pass the disjunction together with another disjunction (and its tlil) picked up from
the database to dis It dis succeeds then done else go to S3
S3 Pass the disjunction down to equlval which will check if any term in the disjunction
matches either side of any equivalence relation in the database It such a match is
found then check if the other side of the equivalence C3n be satisfied It so then done
else the goal fails
43 s02
s02 is also at the second level of the inference mechanism It will take care of all the
simple terms in the transl1ted query The following is the sequence that s02 wiII follow in
searching
S1 Check if the term passed to it caD be s3tisfied by any term or clause in the d3tabase
without contradiction It so then done else go to S2
S2 Pass the term together with a disjunction of terms (and its tail) picked up from the
database to dis If dis succeeds then done else the goal fails
44 dis and con
dis has three arguments In the first two clauses of dIs the first argument P v Q is
found in the database using the builtmiddotin functiol clause and the third argument R is the tair of
the term or the clause P v Q If P v Q is not a clause but a term R will be instantiated to trUE
The second 3rgument comes from either lIol or 802 and thus takes the form of either X v Y (a
disjunction of terms) or T (3 simple term)
All the clauses of dis together with con will perform the searching as exemplified in the
following algorithm (we will keep the notationsin this section)
01 Check if every term in P v Q is in X v Y It so then go to 03 else go to D2
02 For any term (in P v Q) which is not in X v Y or does not match T perform the
following tests
a Check if the term (in P v Q) has already been negated in the datab3Se (ie check if
the contradiction of the term exists in the d3tabase) If so then repeat D2 for other
terms not found in X v Y or not matching T else go to b
13
b Check if the contradiction of the term matches either side of any equivalence
relation in the database If such a match is found then check if the other side of the
equivalence can be satisfied If so then repeat O~ for other terms not found in X v Y
or not matching T else the goal fails
It all the terms (in P v Q) which are not in X v Y or do not match T survive either one
of the above two tests then go to 03
03 This step is essentially done by eon whose goal is to satisfy the tail R of P v Q It
con succeeds then done else the search fails
To close this section we will give an example to illustrate what we have covered In
Section 42 through Section 44
Example Assume that we already haye the following expressions in the database
horse(skml) v dog(skmI)
contradiction(( dog(XI) ))shy
dog(XI)
query goo(( soZ horse(X)) ))
This query will be passed to 802 which will check it the term horse() can be satisfied iu Step S 1
of Section 43 It is a failure So we now go to Step S2 In this step we pick up the disjunction
horse(~kml) v dog(skml) (and its tail true) in the datab3Se and pass it together with the term
horse(X) to dis We are now in Step 01 of Section 44 In this step we find that dog(skml) does
not match horse(X) So we have to go to Step 02 In Step 023 We find that the term dog(skml)
has already been negated (the second expression in the database) So we go to next step 03 Since
the tail of the disjuDction horse(skml) v dog(skml) is the atom true con is satisfied and the
query succeeds
45 countl and count2
countl and count2 are responsible for the counting of tbe numbers of occurrence of a
given simple term or a conjunction of terms They are activated by input queries in the form
q( exists( X whatnum amp P) )
where whatnum is the l~bel for activating the counting of the numbers of occurrence of P which
can either be a term or a conjunction of terms
countl will count the number of term(s) which will satisfy P and associate(s) with
numerical quantification(s Two counters are set to update the lower and upper boundary or the
scope or the numfrical quantifications encountered
The contents of the two counters are then passed to count2 which is responsible for the
counting or the following three types of term First term(s) which will satisfy P and associate(s)
with existential quantification(s Second term(s) which will satisfy P and has(have) Prolog atom
as its(thfir) argument(s) Third term(s) that will satisfy P and itself(themselves) is(are) Prolog
atom(s )
46 equiv
equlv will be activated only after sol and B02 have failed The first two goals of equlv
are similar to that of Step S3 in Section 42 and Step D2b in Section 44 The third goal or equiv
makes possible the inference on either side of any equivalent relation For example if we type the
following three expressions to Prolog in assertion mode
l all( X hot(X) amp humidX) - winter(X)
2 all( X hot(X) amp bumid(X) ==gt unpresent(X))
3 - ( exists( X winter(X) ) )
and then ask APCIS in query mode
q( cxists( X unpresent(X) ) )
15
APCIS with the aid of equlv will be able to answer yes to this query
41 lmpll
lmpll can be considered as the last attempt that APCIS would make to satisfy a
query It is activated only after equlv has failed It will first check if the query is conditional If
so it will convert the implication symbol to equivalence symbol and search if such an equivalent
relation can be found in the database If so a success Otherwise a failure
5 More on the Inference Mechanism
Having looked at all the subparts at the top two levels of the inference mechanism we
are ready to look at other subparts at lower levels
51 num and cnum
One distinct fe3ture or APCIS is its ability to deal with numerical quantifications As
mentioned in Section 31 input queries and assertions will undergo different transformations in
the last step (Step 10) of translation This also holds true for expressions involving numerical
quantifications Consider the following expression
exists( 6 X horse(X) )
If it is entered to Prolog via assertion mode we will after going through all the steps of
translation have the rollowing entered to the database
horse(sk n I
number(sknl6)
Now if we want to ask Are there more than five horses 7 and type in
q( exists( gt5 X horse(X) ) )
1amp
APCIS will translate the question and enter to Prolog the following query
goo(( s02( horse(X) ) s02( num( X gt5 )) ))
Note that the term number(slml 6) in the database and the term num(X gt S) in the query are
different predicates and this difference is exactly where the power of the clause num(X N)
defined in APCIS comes from When the clause num(X N) in APCIS is activated it will search
through the database to see if there is any term of the form number(X I) whose first argument
matches the first argument of num(X Y) in the query It a match is found the second arguments
of both num(X Y) in the query and number(ltI) in the database will be passed to cnum in
APCIS
The job of cnum is to compare the numerical messages carried by the second
argument or the term rlum(X Y) in the query and the second argument of the term rlumber(X I)
in the database to see if they match with each other according to the rules defined in cnum
While there are 25 rules for such matching purposes the idea is simple
Imagine that the second argument Y of the term num(X Y) in the query
and the second argument I of the term num()( I) in the database each occupies a
place in an integer line (Le the integer line in mathematics) To have a match
the domain covered by Y should contain the domain covered by L
As an example the answer to the above query is positive since the domain of gt5
contains the domain or 6
Before closing this section we will bring out a speciaJ translation aspect of expressions
involving numbers by an example We first type to APCIS the Collowing expressions in assertion
mode
1 aU(X all(Y father(X Y) amp number(Y gt6) ==gt has_manY3hildren(X) ))
2 exists(X exists( 12 Y Cather(X Y) ) )
11
After going tbrougb all tbe translation steps tbe Collowing two expressions will be entered to tbe
database
I
bas_many_cbildren( Xl ) shy
Cather( Xl X2 )
num( X2 gt6 )
2
Catber( sk m1 sk n2 )
number( skn2 12 )
lotice that whenev(gtr a term with Cunctor number appears at the rigbt-band side oC a Prolog
clause its Cunctor will be cbanged to num automatically This treatment will greatly cnbance tbe
inference power of the clause sbown in l above For instance iC we now ask tbe question
q( exists( X bas_many_children(X) ) )
The right hand side oC the clause l will match the two terms in 2 and tbe query succeeds
52 Bel and cael
A special feature of APe is tbat all predicates tbat express relations = = gt
gt= lt and lt= can be expressed explicitly using infix notations as relational statements
called selectors To handle selectors we defined Bel in APCIS
Every expression involving selectors will undergo different translations in assertion mode
and query mode For example the assertion
a( exists( [X Y] box (X) amp box(Y) amp (weigh t(X) gt weight(Y) ) ) )
will be translated into the following three terms and entered to tbe database
box( skml )
box( skm2 )
18
weight( skm 1 ) gt weight( skm2 )
Now it we want to ask Is it true that there exists two boxes of different weights and type in
q( exists( [X Yl box(X) amp box(Y) amp ( weight(X) = weight(Y) ) ) )
The question will be transformed to the following query and entered to Prolog
goo(( so( box(XI) ) s02( box(X2) ) so2( sel( weightXI) = weight(X2) )) ))
Note that the selector in the above query is surrounded by the functor set When any clause or
8el in APCIS is activated it will search through the database to see it there is any selector whose
two arguments (left and right side or any selector symbol) match the two arguments of the
selector in the query At the same time 8el will check iC the selector symbols (may be different) or
the two different selectors (one in the query and one in the database) satisfy the rules defined in
sel There are 12 matching rules defined in sel All oC them ~re straightforward and will not be
discussed here An example will be enough to explain how 8el works
Consider the execution of the above transformed query The first two terms in the query
are satisfied by the first two terms in the database and Xl and X2 are instantiated to skml and
skm2 respectively The third term of the query will be passed to eel (of APCIS) which finds a
match on each side of the two selectors (one in the query and one in the database) At the same
time the two different selector symbols gt and = are found to satisfy one of the rules in
8el As a result the query succeeds
To enhance the inference power of clauses involving selectors all the selectors appearing
on the rightmiddothand side oC any clause will be surrounded by a functor set The idea is similar to
that in the last part of the previous section
c8el is exactly the same as 8el functionally It provides a convenient way to compare
selectors when dis is being executed
19
8 Printing Result
Whenever a goal is successfully executed APCIS will not only response with a yes but
also print out the matched terms or clauses in the database This is made possible by the built-in
function bagor and the two predicates wout and prt defined in APCIS
7 Summary
In this paper a description of a deductive inference system called APCIS (Annotated
Predicate Calculus Inference System) has been provided APCIS is able to carry out inferences
from expressions involving numerical quantifiers selectors disjunctions of non-negated terms
negated terms disjunctions of negated terms equivalences and exceptions It is also able to count
the numbers of occurrence of a given simple term or a conjunction of terms
The main idea of APCIS is that each input APC expression is first passed to a
preprocessor ( ie APC translator ) which dissolves and transforms each APC expression into
Prolog expression(s) which will then be loaded to Prolog system The user bas to specify whether
each input expression is to be entered as an assertion or as a query by invoking either assertion
mode or query mode respectively Each assertion or query will undergo different transformations in
the preprocessor The different treatment of assertion or query not only allows a full uS1ge of the
Prolog inference mechanism but also makes possible a higher level of inexact pattern matching
exemplified by the examples in Section 51 and Section 52 where the four predicates num
cnum sel and csel are discussed This higher level of pattern matching increases the inference
power of APCIS greatly
The design of contradiction and the treatment of the disjunction of non-negated terms
allow APCIS to accept non-Horn clauses and to carry out inference from them This feature
makes APCIS more general than Prolog
20
While APCIS performs very well in many sets of arguments provided by the author it is
still too early to jump to conclusion that it can perform equally well in all types of problems In
any event the expressiveness of APC has greatly been retained in the present version of APCIS
and moreover some design ideas or APCIS mentioned in this paper are not restricted to APCIS
- they may be carried over to learning programs with narrower scopes
21
References
[1] W F Clocksin and C S Mellish Programming In Prolog Springermiddot Verlag Berlin Hpoundidelberg 1981
[2] R S Michalski A Theory and Methodology of Inductive Learning Chpt 4 Machine L earning Tioga Publishing Co Palo Alto CaliJornia 1989
[3] K-E Pua Translating Annotated Predicate Calculu8 to Prolog ISG Report 84middot1 UlUCDCSmiddotFmiddot918 University oj Illinois Urbana IL June 1984
22
Appendix A
APCIS Users Manual
1 Get Started
Users are urged to follow the steps depicted below
1 Get the PROLOG interpreter by typing
alias prolog mntb2sammutsammutprologprolog (Vax A)
or
alias prolog mntb2sammutsammutbinprolog (Vax B)
2 Load apc and infer by typing
prolog apc infer
When large APC expressions are expected we can increase the stlck by typingI
prolog -snnnn ape infer
where ns denote the number of stacks in decimal
3 When the wording LSW - PROLOG appears on the terminal we are reldy to interact
with APCIS The four modes by which we can invoke APCIS are summarized below
a Assert ion-Translation Mode
ta(X)
b Query-Translation Mode
tq(X)
c Assertion Mode
a(X
d Query Mode
q(X)
23
where Xs are APC expressions
2 Notations Used in APCIS
Below is a summary or notations used in APCIS
a Logical operators
amp
v
==gt
lt=gt
-
negation
conjunction
disjunction
implication
equivalence
exception
b Binary relation symbols in selectors
-
=
gt=
lt=
gt
lt
equal
not equal
greater or equal
smaller or equ al
greater
smaller
c Relational operators in numerical quantifiers
lt less than
lt= less than or equal
gt greater than
gt= greater than or equal
d BinlTY operator in numerical quantifier
range
e Universal quantifier
all(X p(X))
f Existential quantifier
exists(X p(X))
g Numerical quantifier
exists(I X p(X))
where p(X) is a formula
where X is a variable or a Jist of variables or the
form [HI~rj and p(X) a formula
where I repersents expression involving integer(s)
and operator(s) in c or d above and p(X) a formula
25
Appendix B
APCIS Program Listings
------------------------------- Program Name APCIS - Part 1 APC Translator
-------------------------------
op(3OO fx -)1
op(500 xfy amp)
oPt 500 xfy v)
op(600 xfx )
op(700 fx [gt= lt= gt lt ]) op(400 xfy [= gt= lt= gt lt ])1 op(900 xfy gt lt=gt -])1
steps(X Xg) shy
numbervars(X 1 J Step 1 change variables to iis
rmimp(X X) Step 2 conv(X X3) Step 3
rewrite(X3 X4) Step 4
negin(X4 X5) Step 5
dropexist(X5 X6 1]) Step 6
dropall(X6 X7) Step 7
distrib(X7 X8) Step 8 clausiCy(X8 X9 [J) Step 9
ta(X) shysteps(X Xg)
(( Xg = II nl
print( yes it is always true) )
( nl nl printcl(X9))) Step 10a
tq(X) shy
steps(X Xg)
prques(Xg)
28
Step 2 Removing implic3tions amp Transforming exceptions and equiv3lences
rmimpl( P - Q (PI lt=gt (QI) ) amp ((PI) lt=gt QI) ) -
rmimpl(P PI) rmimpl(Q QI)
rmimplnp) lt=gt Q (PI lt=gt -(QI)) amp nPI) lt=gt QI) ) - 1
rmimpl(P PI) rmimpJ(Q QI)
rmimpJ(P lt-gt -(Q) (PI lt=gt -(QI)) amp nPI) lt=gt QI) ) -
rmimpl(P PI) rmimpl(Q QI)
rmimpl( P lt=gt Q PI lt=gt QI ) - I
rmimpl(P PI) rmimpl(Q QI)
rmimpl( P ==gt Q -(PI) v QI ) - I
rmimpl(P PI) rmimpl(Q QI)
rmimpl( all(X P) aI(X PI) ) - 1
rmimpl(P PI)
rmimpl( exists(X P) exists(X PI) ) -
rmimpl(P PI)
rmimpl( exists(I X P) exists(I X PI) ) -
rmimpl(P PI)
rmimpl( P amp Q PI amp Ql ) -
rmimpl(P PI) rmimpl(Q Ql)
rmimpl( P v Q PI v QI ) -
rmimpl(P PI) rmimpl(Q QI)
rmimpl( -(p) -(PI) ) - I
rmimpl(p PI)
rmimpl( P P )
St~p 3 Converting numerical amp distinctive quantifiers
L Numerical quantifiers
examples of input forms
1 exists(gt= i X pIX)) where i is an integer
2 exists(i X pIX)) where i is an integer
3 exists(i j X pIX)) where i j are integers and iltj
4 exists(il v i2 X pIX)) where is are integers
examples of output forms of this step
1 exists(X pIX) amp number(X gt= i) )
2 exists(X pIX) amp number(X i) ) 3 exists(X pIX) amp number(X ij) ) 4 exists(X pIX) amp number(X il v i2) )
II Distinctive quantifiers
27
example or input Corm
exists([XYL p(X Y))
example or output Corm or this step
exists(X exists(Y p(XY)) )
conv(P lt=gt Q PI lt=gt QI) - 1
conv(P PI) conv(Q QI)
conv(al1(X P) all(X PI)) -
conv(P PI)
conv(exists(HIT] P) R ) - conv(P PI) convert distinctive quantifier
convtdis(exists([HIT]PI) R)
conv( exists(I X P) exists(X PIamp number(X I) )) -
conv(P PI) convert numerical quantifier
conv(exists(X P) exists(X PI)) - 1
conv(P Pl)
conv(P amp Q PI amp QI) - 1
conv(P PI) conv(Q QI)
conv(P v Q PI v QI) - t conv(P PI) conv(Q QI)
convC(P) -(PI)) -
conv(P PI)
conv(P Pl
convtdis(existsl[XL P) exists(X P)) - atomic(X) convtdis(exists[XIYj Pl exists(X R)) shy
convtdis(exists(Y P) R)
Step 4 Rewriting compound predicates andor compound selectors
Outputs are smiple predicates andor simple selectors
rewrite(P lt=gt Q PI lt=gt QI) - t rewrite(P PI) rewrite(Q QI)
rewrite(all(X Pl all(X PI)) - 1 rewrite(P PI)
rewriteexists(X P) exists(X PI)) - I rewriteP PI)
rewrite(P amp Q PI amp QI) - rewrite(P P 1) rewrite( Q Q 1
rewrite(P v Q PI v QI) - 1
rewrite(P PI) rewrite(Q QI)
rewriteC(P) -(PI)) - I
28
rewrite(P PI) rewrite(F(A B) R) -
rewrite(A AI) rewrite(B BI) re(F(AI BI) R)
rewrite(F(A) R) -
rewrite(A AI) re(F(AI) H)
rewrite(F(A B C) R) -
rewrite(A AI) rewrite(B BI) rewrite(C CI) re(F(AI BI CI) R)
rewrite(F(A B C D) R) -
rewrite(A AI) rewrite(B Btl rewrite(C CI) rewrite(D DI) rc(F(AI BI CI Dl) H)
rewrite(PP)
re(F(A B v el (RI v R2) -
re(F(A Bl RIl re(F(A C) R2) reF(A B amp cl (RI amp R2)) -
re(F(A B) RI) re(F(A e) R2) re(F(A amp B C) (Rl amp R2)) -
re(F(A e) R 1) re(F(B C) R 2) re(F( v B el (R I v R2)) -
re(F(A el R I) reFB el R2) re(F(A amp Bl (R I amp R2)) -
re(F(A RI) re(F(BJH2) re(F(A v B) (R 1 v R2)) -
re(F(A) RI) re(F(B) R2)
re(F(A vB c Dl (RI v R2) -
re(F(A C D) RI) re(F(B C D) R2) re(F(A amp B C D) (RI amp R2)) -
re(F(A C D) Rll re(F(B C D) R2) re(F(A B v C D) (HI v R2)) -
re(F(A B D) RI) re(F(A C D) R2) re(F(A B amp C D) (HI amp R2)) -
re(F(A B D) RI) re(F(A C D) R2) re(F(A B C v D) (RI v R2)) -
re(F(A B C) R I) reF(A B D) R2) re(F(A B C amp D) (RI amp R2)) -
29
re(F(A B C) RI) re(F(A B D) RZ)
re(F(A v B e D E) (R I v R2)) -
re(F(A e D E) R I) re(F(B e D El R2) re(F(A amp B e D E) (RI amp RZ)) -
re(F(A e D El R 1) re(F(B e D E) R2) re(F(A B v e D E) (R I v R2)) -
re(F(A B D E) RI) re(F(A e D E) R2)
re(F(A B amp e D E) (RI amp R2)) -
re(F(A B D El RI) re(F(A e D E) RZ) re(F(A B e v D E) (R I v R2)) -
re(F(A B e El R 1) re(F(A B D E) RZ) re(F(A B e amp D E) (RI amp RZ)) -
re(F(A B e E) R I) re(F(A B D E) RZ)
re(F(A B e D vEl (RI v RZ)) - l
rc(F(A B C D) RI) re(F(A n e El RZ) re(F(A B e D amp El (RI amp RZ)) - ~
re(F(A B e D) RI) re(F(A B e El RZ)
re((A = B) (A = B)l-
re((A = Bl (A = 8)) -
retIA gt= BI (A gt= B)) -
re((A lt= B) (A lt= B)) -
re((A gt B) (A gt B))-
re((A lt Bl (A lt Bl)- re(A A)
Step) Bringing n(gation inwards
Degin(-(P) PI) - neg(P Pl)
negin(P lt=gt Q PI lt=gt Ql) - ~
negin(P PI) negiD(Q QI)
Degin(aU(X P) all(X PI)) - Degin(P PI) negin(exists(X P) exists(X PI))- negin(P PI) negin(P amp Q PI amp Ql) - Degin(P PI) negin(Q Ql)
Degin(P v Q PI v QI) - Degin(P PI) negin(Q QI) negin(P Pl
neg(-(P) PI) - negin(P PI)
neg(all(X P) exists(X PI)) - neg(P PI)
30
neg(exists(X P) all(X PI)) - neg(P PI)
neg(P amp Q PI v QI) - neg(P PI) neg(Q Ql)
neg(P v Q PI amp QI) - neg(P PI) neg(Q QI)
neg(P -(PH
Step 6 Dropping existnetial quanti6ers
dropexist(P lt=gt Q PI lt=gt QI Elerns) - dropexist(P PI Elerns) dropexist(Q QI Elerns)
dropexist(alJ(X P) all(XPI) Elerns)
dropexist(P PI [XIElernsJ)
dropexist(exists(X P amp nurnber(X Yraquo P2 Elerns) -
genfun(skn Newg) Fun = [NewgIElerns]
subst(FuD X P amp Dumber(X Y) PI)
dropexist(Pl P2 Elerns)
dropexist(exists(X P) PZ Elerns) -
genfun(skrn Newf) Fun = [NewfIElernsJ
subst(Fun X p PI)
dropex ist(P 1 P~ Elerns)
dropexist(P v Q PI v QI Elerns) - ~
dropexist(P PI Elerns) dropexist(Q Ql Elerns)
dropexist(P amp Q PI amp QI Elerns) - 1
dropexist(P Pl Elerns) dropexist(Q QI Elerns)
dropexist(P P _)
gen fun(R oot Newn arne) shy
getnurn(Root Nurn)
narne(Root Rootlist)
append(Rootlist[Nurnj Narnelist)
concat(Narnelist Newnarne)
getnurn(Root Nurn) shy
retract(currentnurn(Root Nurn 1 raquo
Nurn is Nurni + 1
asserta(currentnurn(Root Nurn))
getnurn(Root 1) - asserta(currentnurn(Root 1))
subst(New Old Val Val) - var(Val)
subst(New Old Old New) - 1 substNew Old Val Val) - atornic(Val)
31
subst(New Old Val Newval) shy
runctor(Val F N)
CUDctor(Newval F N)
subst_args(N New Old Val Newval)
subst_args(O J J - J J
subst_args(N New Old Val NewVal) shy
arg(N Val OldArg)
arg(N NewVal NewArg)
subst(New Old OldArg NewArg)
NI is N - I
subst_args(Nl New Old Val NewVal)
append([J L L) -
append([XILl] L2 [XIL3]) - append(Ll L2 L3)
Step - Dropping universal quantifiers
dropall(P lt=gt Q PI lt=gt QI)-
dropall(P PI) dropall(Q QI)
dropall(all(X P) PI) - ~ dropall(P PI)
dropall(P amp Q PI amp QI) -
dropall(P PI) dropall(Q QI)
dropall(P v Q PI v QI) -
dropall(P PI) dropall(Q QI)
dropall(P P)
Step 8 Distributing conjunctions over disjunctions
distrib(P lt=gt Q PI lt=gt Ql) - t distrib(P PI) distrib(Q QI)
distrib(P v Q R) -
distrib(P PI) distrib(Q QI)
distributing(PI v QI R)
distrib(P it Q PI it QI) -
distrib(P PI) distrib( Q QI)
distrib(P P)
distributing((P amp Q) v R PI amp QI) -
distrib(P v R PI) distrib(Q v R Ql)
32
distributing(P v (Q amp R) PI amp Ql) -
distrib(P v Q PI) distrib(P v R Ql)
distributing(P P)
Step 9 Packing each conjunction into clauses
c1ausify(P amp Q CI C2) -
clausiCy(P CI C3) c1ausify(Q C3 C2)
cbusiCy(P [d(A B)ICs] Cs) shy
inclause(P A [j B [I) 1
c1ausiry( C C)
inclause(P v Q A AI B B1) -
inc1ause(P A2 AI B2 Bl)
inclause(Q A A2 B B2)
inclausenp) A A B1 B) -
notin(P A) putin(P B B1)
inclause(P AI A B B) shy
notin(P Bl putin(P A AI)
notin(X [XU) - fail
notin(X [JLj) - notin(X L)
notin(X 1])
putin(X II [X]) - 1
putin(X [XILJ L) -
putin(X [YILJ [YILl]) - putin(X L Ll)
Step 1Oa Printing clauses
printcl([]) - nl nl
printcl(c1(AB)ICsj) - printcl(A Bl nl printcl(Cs)
printcl(L II) - printdis(IL) prinr)middot
printclHl L) - prin(contradiction(() printconl(rL)
print()) - ) printconj(rL) prinr )
printcl(Ll L2) shy
printdis(ILl) print( - ) printconj(rL2) prin()
printdis(S[Lj) - printcbar(SL)
33
printdis(S[LILs]) - printchu(SL) prin( v) printdis(SLs)
printconl(S[LI) - printchar(SL)
printconl(S[LILs]) - printchar(SL) prin( ) printconl(SLs)
printconj(S[L]) - tab(3) printchar(SL)
prin tconj( S [L IL sl) shy
tab(3) printchar(SL) print( ) printconj(SLs)
printchar(SP) shy
atomic(P)
name(P L)
L = [IT]
concat([XIT NewP)
prin(~ewP)
printchar(SP) shy
atomic(P)
prin(P)
printchar(SA lt= gt B) -
prin((l clausify(A AI [j) pl(eAl) prin())
print lt=gt )
prin(() cbusify(B Bl [I) pJ(eBl) prine))middot
printchar(rnumber(X N)) shy
prin(num() printchar(rx) prin( )
printchar(rN) prinC))
printchar(rF(A B)) shy
seJec(F(A B))
prinCsel() printchar(rA)
prin( F ) printchar(rB) prinC))
printchar(SF(A B)) shy
( selec(F(A B)) F = infix )
printchar(SA) prin( F ) printchar(SB)
printchar(SF(A)) shy
(F= prefix gt= F= prefix lt= F= prefixgt F= prefix lt )
prin(F ) printcbar(SA)
printchar(SP) shy
functor(P F MaxN)
prin(F ()
Nl is MaxN - 1
putout(S N 1 P MaxN)
34
prin())
putout(S 0 P MaxN) -
arg(~laxN P Argu)
prin tchar(SArgu)
putout(S N p MaxN) shy
Nt is MaxN - N arg(NI P Argu)
printcbar(SArgu )
prin( )
N2 is N - 1
putout(S N2 P MaxN)
selec(FA B)) shy
( F= infix = F= infix f= F= infix gt=
F= infix gt F= infix lt= F= infix lt )
35
----------------------------------Program Name APClS - Part 2 Inference Mechanism ---------------------------------- a(X) shy
steps(X X9)
(( X9 =[] nl
print( yes it is always true) )
( X9 =[cI(IJ[])] nl
print( no it is always false) )
( nl nl printel(X9) Step 1Oa
tell(temp_file) printel(X9) e1ose(temp_file) consult(temp_6Ie) ))
q(X) shy
asserta( in pt(X))
steps(X X9)
(( X9 = [] print(middot~H~~middot~t~)
print(THE AiSWER IS YES)
print( ilgIQlQl(~) )
( X9 = [e1([j [j)] Pr1nt ( OJ fi(i I~ iii Ij)middot(i)(i) fiyenQ)riiio(i)(ij)(i)fj)fiyen1li1il1li1il)__ gtw~ __~_~ _~~_ ~_-=~
print(THE ANSWER IS NO ) print() )
( teI1(temp_6Ie)
prques(X9) Step 1Ob
close(temp_file)
nl print(Let me think about it) nl
consult(temp_6Ie) ))
retrac t( in pt(X))
Step lOb Printing question
prques(lcl(A 8)1) - prin(goo(() pl(qA 8) print()))
prques([c1(A 8HCs]) - prin(goo(() pl(qA 8) print() pl(q Cs)
pl(e [c1(A 8)]) - pl(eA 8)
pl(q [c1(A 8)]) - pl(qA 8) print()))
pl(S [e1(A B)ICs]) - pl(SA B) prin( ) pl(S Cs)
38
pl(q [j L) - prin(c1ause(contradiction(() pcont(qL) prin())_))
pl(S [I L)- prin(so2(contradidion(() pcont(SL) print))))middot
pl(S [L] []) - prin(so2() pcbar(SL) prin())
pl(S L [J)- prinsol() plett(SL) print))
pl(S [L] LI) - prin(condi(() pchar(cL)
prin(() pcont(S Ll) prine))))
pl(S L Ll)- prin(c1ause() plert(cL)
prin(() pcont(S Ll) prine)))
plert(S[LJ) - pchar(SL)
plert(SjLILsj) - pcbar(SL) print v) pleCt(SLs)
pcont(S[L]) - pchar(SL)
pcont(S[LILsj) - pcbar(SL) prinr ) pcont(SLs)
pcbar(SP) shy
atomic(P)
name(PL)
( L = [IT] L = [5 k miT] L = [5 k niT] )
concat[XITj NewP)
prin(0JewP)
pchar(SP) shy
atomic(P)
prin(P) pchar(SA lt=gt B) -
prin(() dausify(A AI []) pl(eAI) prin())
prinr lt=gt ) prin(() dausify(B BI ]) pl(eB) print))
pchar(Snumber(X N)) shy
prin(num() pchar(SX) prin()
pchar(SN) prinr))
pcbar(SM N) - prin(M N)
pcbar(cF(A B)) shy
selec(F(A Braquo
pcbar(cA)
prine F ) pchar(cB) pchar(SF(A B)) shy
selec(F(A B))
prin(sel() pchar(SA)
print F ) pchar(SB) print)) I
31
pc har(SF(A)) shy
( F= prefix gt= F= prefix lt= F= prefixgt F= prefix lt )
prin(F ) pchar(SA)
pchar(SP)shy
runctor(P F MaxN)
prin(F ()
011 is MaxN - 1 pout(SNl P MaxN)
print) )
pout(S 0 P M3xN) - 1
arg(~bxN P Argu)
pchlr(SArgu )
pout(S N P MaxN shy
Nl is MaxN - N
arg(Nl P Argu)
pchar(SArgu
prin( )
N2 is N - 1
pout(S N2 P ~13xN)
Comparing numbers in numerical quantifiers
num(XN) shy
number(X I)
cnum(N 1) ~
cnumlaquo=01 lt=I- N gt=I
cnumlaquo=J lt I) - N gt=1-1
cnumlaquo=NIJ) - N gt=J 1
cnumlaquo=N J)- integer(I) N gt=I~
cnum(gt=N gt=1) - N lt=1
cnum(gt=N gt I) - N lt=1+ 1 cnum(gt=NIJ) - N lt=1
cnum(gt=N lt=1)- N lt=1
cnum(gt=N lt I) - N lt=1 L cnum(gt=N 1)- integer(I) N lt=1
cnum( lt N lt 1)- N gt=1 L
38
cnum( lt N lt=1) - N gt I cnum( lt NLJ) - N gt J
cnum( lt N 1)- integer(I) N gt 1
cnum(gt N gt I) - N lt=1 cnumlgt i gt=1) - N lt I
cnum(gt N lt=1) - N lt=0
cnum(gt N lt I) - N lt=0
cnum(gt iIJ) - N lt I cnum(gt N 1)- integer(I) N lt I
cnum(~LN lt=1) - M=I N gt= I l
cnum(~LN lt I) - M=l N gt= I-I
cnum(~LNLJ) - M lt =1 N gt = J
cnum(~1N 1)- integer(I) M lt= I N gt= I
cnum(- N) - integer(N)
Comparing selectors
sel(X = Y) shyX= Y
sel(X I=Y) shy(X I=Y X lt Y Xgt Y)
sel(X gt Y) shyXgt Y
sel(X lt Y) shyXlt Y
selX gt=Y) shy(X gt=Y X= Y Xgt Y)
se(X lt=Y) shy
(X lt=Y
X= Y
X lt Y)
csel(infix = infix =)
39
csel(infix = infix = csel(infix = infix gt)
csel(infix = infix lt) csel(infix gt infix gt) cseJ(infix lt infix lt) csel(infix gt= infix gt=) csel(infix gt= infix gt csel(infix gt= infix =)
csellinfix lt= infix lt=) csel(infix lt= infix lt) csel(infix lt= infix =)
Finding solutions
sol(X v Y) -
(( notetra(X) eon(X) ( sol(Y) )
( c1ause(P v Q R) not(cketra(P v Q))
dis(P v Q X v Y R) ~ )
( A lt=gt B equival(A lt=gt B X v Y) ~ I) sol(X) - ~ notetra(X) eon(X)
so~(X) - notetra(X)
( con (X)
( clause(P v Q R) not(ekctra(P v Q)) dis(P v Q X R) I)
cketra(P v Q) -
eketra(P) eketra(Q) eketra(F(I J)) shy
selec(F(I J))
c1ause(contradiction(sel(F(IJ))) _I
eketra(number(W I)) -
clause(cootradietion(num(Wl)) - eketr(P) shy
clause(contradiction(P) - 1
notctra(P) shy
not( e lause( con tradiction(P) _))
40
Searching (or disjunctions
dis(P v Q X v Y R) - dis(P X v Y R)
dis(Q X v Y R) con(R)
dis(P v Q X R) -
dis(P X R) dis(Q X R) con(R
dis(P X v Y R) - clause(contradicton(Pl J 1
dis(F(I J) sel(G(I J)) v Y R) - csel(G Fl dis(number(WI) num(W N v Y R) - cnum(N I)
dis(P P v Y R) -
dis(P X v Y R) - dis(P Y R)
dis(F(I J) seJ(G(IJ)) R) - csel(G F)
dis(number(WI) num(WN) R) - cnum(N I) dis(P P R) - 1
dis(FJ J X R) shy
( ckctra(F(IJ) cbeckeq(seJ(F(IJ))) )
dis(number(W Il X R) - ( ckctra(number(WI)) cbeckeq(num(WI)) )
dis(P X R) shy( ckctra(P) cbeckeq(P) ) 1
cbeckeq(P) shy
(( A lt=gt so2(contradiction(P))
bagof(A A [jj) ) ( so2(contradiction(P)) lt=gt B
bagof(B B Uj) ))
ckeq(A) shy
( so2(A) lt=gt B B lt=gt so2(A) ) bagof(B B UJ)
con((P Q)) -
clause(P R) con(R) con(Q) con(true) -
con(contradiction(P)) - clause(contradiction(P) J
con(cause(X Y)) - cause(X Y)
con(sel(X)) - sel(X)
con(num(X Y)) - num(X Y) con(P)- (( dause(P R) (con(R) ckeq(R)))
colJectin(P) )
collectin(P) shy
bagof(S (c1ause(P S) S = true) [L LIJ )
mkcon(L Ll L)
bagor(l (L2 ) UJ) L
mkcon((A AI) (B B1) (sol(A v B) e D)) -
mkcon(A B1 e) mkcon(A1 (B Bl) D)
mkcon(A (B B1) (sol(A v B) e)) -
mkcon(A Bl e)
mkcon((A AI) B (sol(A v B) e)) middot1
mkcon(Al B e)
mkcon(A B sol(A vB))
Searching ror equivalences
equival(A lt=gt B X v Y) - 1 ( equival(A lt=gt B X) equival(A lt=gt B Y) )
equival(s02(A) lt=gt 502(B) A) - clause(B _I equival(s02(B) lt=gt 502(A) A) c1ause(B _I
Top level or inrerence mechanism
goo((s02(whatnum) P)) -
getatm(P Xl
bagor(number(X Y) ( P so2(number(X Y)) ) A )
count1(A 00 L R) nl
bagor(X P B )
count2(B L R Ll Rl) nJ print()
(( LI = 0 Rl = 0 print(THE ANSWER IS ) nl
(( Ll = Rl prin(-Jumber or ) prn(P) print(is Ll) )
( Rlgt20000 prin(Number or I prn(P) print(is LI or more) )
42
( prin(Number of ) pfn(P) print( is from Ll to Rl) )) )
( print(THE ANSWER IS NO I )) print()
goo(X) shy
(( bagof(X X L) L = [I nl print()
print(THE ANSWER IS YES) nl wout(L) print() )
( equiv(X L) nl print()
print(THE ANSWER IS YES) nl wout(L) print(-) )
( c1ause(inpt(A ==gt B) _I ( impli(A B Z) impli(B A Z) ) print(l~Hl)
printTHE ANSWER IS YES) nl print(Z) print(Hj~(fH~) ))
goo(X) print( Hg)
print(THE ANSWER IS NO ) print( lH~lH~gg9l9lmiddotmiddot~Q(gmiddot)
00 Semhing for implications in equiV3lent relations
impli( B Z) shyt-ell( z1) prin(templ() pchn(S A lt=gt B) print()) close ( zl) consult(zl) templ(Z)
unload zl Z
Searching for equivalence
equiv (X L)
(( X lt=gt Y
equ(Y YI)t bagof(Y Yl L) L = [j )
(Y lt=gt X equ(Y YI) bagof(Y Yl L) L = [J )
( X = F(New)
clause(~ew T) makeup(T Tl)
(( Tl lt=gt B
equ(B Bl) bagof(Bl Bl M) M = [j L=[Newl )
(A lt=gt TI
equ(A AI) bagof(Al AI M) M = 1] L=INewj )) ))
makeup((A B) (AI Bl)) -
makeup(A A1) makeup(B BI)
makeup(A so2(A))
equ((A B) (AI BI)) -
equ(A AI) equ(B Bl)
equ(sol(X v Y) sol(XI v Yl)) -
equ(X XI) equ(Y YI)
equ(so2(X) so2(XI)) -
equ(X XI)
equ(contradiction(X) clJuse(contradiction(X) X) ) -
equ(X X)
Counting numbers
getatm((A B) X) -
( getatm(A X) getatm(B X) )
getatm(so2(F(X)) X) -
getatm(so2(X) X) - atom(X)
countl([J L R L R) -
countl([number(X Y)IT] L R L2 R2) shy
(( Y = (gt=~) LI is L + N Rl is R + 20001 l )
( Y = (gt N) LI is L+ N+ 1 RI is R + 20002 )
(Y == laquo=~) LI is L + 1 Rl is R + N )
(Y = laquo N) LI is L + 1 RI is R+N-I)
(Y == IJ LI is L + I Rl is R + J ) ( Y == N L1 is L + N RI is R + N ))
count1(T LI R 1 L2 R2)
count2(fJ L R L R) - 1
count2([XITJ L R L2 R2) shy
name(X Xl)
(( Xl = sknj LI is L Rl is R )
44
( Xl = Iskmj L1 is L + 1 RI is R + ZOOO1) ( LI is L + I RI is R + I ))
count2(T LI RI L2 R2)
pfn((A B)) - pfn(A) prn(B)
pCn(so2(F(X))) - prin(F )
prn(so2(X)) - atom(X) prin(X ) prn (so2(X))
Printing result
wout([XlJ - prt(X) nl woutf[xIY]) - prt(X) nl nl wout(Y)
prt(e(A B)) -
prt(A) prinr 8 ) prt(ltE) prt(eA) - prt(A)
prt(c(A EJ) - prin() prt(A) prine ) prt(B) prin(T)
prt(c A) - prt(A) prt((A E)) - ~
prt(A) nl prt(E) prt(sol(X v Y)) - ~
prt(X) prinC v) prt(Y) prt(A lt=gt B) -
prt(e A) prinC lt=gt ) prt(e B) prt(sol(X)) - prt(X)
prt(so2(X)) - prt(X
prt(c1ause(X Y)) - prt(X)
prt(contradiction(X)) - prin(contradiction() prt(cX) prinr))middot prt(num(XY)) - prin(number(X Y)) prt(sel(X)) - prin(X) prt(X v Y) - prt(X) prin( v) prt(Y) prt(X) prin(X)
Handling conditional queries
condi((Y Xl) shy
assertcon(X) Y
45
retractcon(X)
condi((B A))
retractcon(A) fail
assertcon((A B)) 1
assertcon(A) assertcon(B)
assertcon(A) asserta(A)
retrac teon ((A B)) 1
retracteon(A) retractcon (B)
retraetcon(A) - retract(A)
BIBLIOGRAPHIC DATA SHEET
Report No UIUCDS-F-84-928
3 Recipients Accession No
4 T ide and Subt ltle
An Annotated Predicate Calculus Inference System (APCIS)
S Report Date
November 1984 6
7 Author(s)
Kah-Eng Pua 8 Performing Organization Rept
No
9 Performing Organization Name and Address
Department of Computer Science University of Illinois Urbana IL
10 ProjectTaskWork Unit No
11 Contract Grant No NSF DCR 84-06081 ONR N00014-82-K-0186
12 Sponsoring Organization Name and Address
National Science Foundation Washington DC
13 Type of Report amp Period Covered
14
15 Supplementary Notes
16 Abstracts
This paper describes a deductive inference system called APCIS (Annotated Predicate Calculus Inference System) APCIS is able to carry out inferences from expressions involving numerical quantifiers selectors disjunctions of non-negated terms negated terms disjunctions of negated terms equivalences and exceptions It is also able to count the numbers of occurrence of a given simple term or a conjunction of terms The design of contradiction and the treatment of the disjunction of non-negated terms allow APCIS to accept Horn clauses as well as non-Horn clauses and to carry out inferences from them This feature makes APCIS more general than Prolog
17 Key lords and Document Analysis 170 Descriptors
APC (Annotated Predicate Calculus) APCIS (Annotated Predicate Calculus Inference System) Horn Clause Numerical Quantifier Prolog Selector
17b IdentifiersOpen-Ended Terms
17c COSATI FieldGroup
18 Availability Statement 19 Security Class (This
Re~f~~IA~SIF IFf)
21 ~o of Pages
49 211 ecurity Class (This
PageUNCLASSIFIED
22 Price
FOA NTIS n (10middot70 usco-oc 40329-
g
Bl B2 Bm
34 Futher Transformation of Exceptions and Equivalences
To provide some backgrounds for the discussion of the further transformation of
exception and equivalence relations we will lirst reproduce the three goals in the Step 2 of the
APe translator discussed in Section 32 of [31
First expressions involving implication or the form A ==gt B will be transformed to
Second expressions with exception symbol or the form A - B will be changed to the
form ( A lt=gt -(B) ) amp ( -(A) lt=gt B)
Tbird expressions with equivalence symbol of the form -(A) lt=gt B or of the form
A lt=gt -(B) will also be converted to ( A lt=gt -(B) ) amp ( -(A) lt=gt B ) since tbere are
logically identical to exception relations Also expressions with equivalence symbol of the form
A lt=gt B or -(A) lt=gt -(B) will remain the same
After the Step] of the APe translator both sides of any transformed expression with
lt = gt symbol will be treated separately as if they are two independent expressions In the
Step 10 of the APe translator each side of lt=gt will again be treated separately and
transformed into a form similar to an transformed input query (see Section 31) Two examples
are given below
1 state(on) lt=gt -( state(olJ) )
2 all( 1 bot(l) amp humid(l) - winter(I) )
They will be transformed in the Step 2 or the APe translator into
1
(state(on) lt=gt -( state(off) ) ) amp ( -( state(on) ) lt=gt state(olJ) )
2
10
( hot(l) amp humid(l lt=gt -(winter(l)) ) amp
( -( hot(l) amp humid(l)) lt=gt winter(I)
In Step la they will again be transformed to
1
so2( state(on) ) lt=gt so2( contradiction( state(oH) ) )
so2( contradiction( state(on) ) ) lt=gt so2( state(oH) )
2
( s02(hot(XI)) so2(humid(XI))) lt=gt so2( contradiction( winter(Xl ))
so2( contradiction(( bot(Xl) humid(Xl) )) ) lt= gt so2( winter(XI) )
There are two advantages in the treatment of exception and equivalence symbols in this
way First it will prevent Prolog program from going into an infinite loop which is difficult to
avoid if equivalent relation such as A lt=gt B is transformed into the logically equivalent form
( A ==gt B) amp ( B ==gt A) Second by maintaining both sides of lt=gt symbol in
query form the searching on either side caD be done more easily and efficiently since the form
is already processed and does not need any further transformation
Inference Mechanism
As mentioned at the end of Section 31 goo sol and s02 each forms a part of the
inference mechanism of APCIS with goo occupying the top level and 80) and 802 the second
level In addition to these countl count2 equlv and impll are also at the second level of the
inference mechanism We will go over all of them in the following sections
I goo
goo is essentially the starting point of the inference Whenever a translated query is
loaded to Prolog system from temp-fie goo will go through one or more of the following steps in
11
sequence
G 1 Check if the query asks for the numbers of occurrence of certain term(s) It so then
pass It to eountl and eount2 else go to G2
G2 The query will be passed down to sol or s02 (or both) to check i( any assertion in the
database can satisfy the query It the answer is positive then the query succeeds else
go to G3
G3 The query will be passed to equlv to carry out further searching It the searching is a
success then the query will be closed with a success else go to G4
G4 It the query is in the form A ==gt B then it will be passed to Impli It Impll
succeeds then done else the query will be closed with a (ailure
42 sol
801 and 802 together with dis and eon form the most complicated part of the APCIS
iorerence mechanism In this and the next section we will look at sol and s02 dis and eon will
be discussed in Section 44 We will close Section 44 with an example that illustrates the
materials presented in Section 42 through Section 44
sol is at the second level of the inference mechanism It will deal with any disjunction of
non-negated terms For any disjunction passed to it it will go through one or more of the
following steps in sequence
S1 Check if any term In the disjunction can be satisfied by any term or clause in the
database without contradiction It so then done else go to S2
S2 Pass the disjunction together with another disjunction (and its tlil) picked up from
the database to dis It dis succeeds then done else go to S3
S3 Pass the disjunction down to equlval which will check if any term in the disjunction
matches either side of any equivalence relation in the database It such a match is
found then check if the other side of the equivalence C3n be satisfied It so then done
else the goal fails
43 s02
s02 is also at the second level of the inference mechanism It will take care of all the
simple terms in the transl1ted query The following is the sequence that s02 wiII follow in
searching
S1 Check if the term passed to it caD be s3tisfied by any term or clause in the d3tabase
without contradiction It so then done else go to S2
S2 Pass the term together with a disjunction of terms (and its tail) picked up from the
database to dis If dis succeeds then done else the goal fails
44 dis and con
dis has three arguments In the first two clauses of dIs the first argument P v Q is
found in the database using the builtmiddotin functiol clause and the third argument R is the tair of
the term or the clause P v Q If P v Q is not a clause but a term R will be instantiated to trUE
The second 3rgument comes from either lIol or 802 and thus takes the form of either X v Y (a
disjunction of terms) or T (3 simple term)
All the clauses of dis together with con will perform the searching as exemplified in the
following algorithm (we will keep the notationsin this section)
01 Check if every term in P v Q is in X v Y It so then go to 03 else go to D2
02 For any term (in P v Q) which is not in X v Y or does not match T perform the
following tests
a Check if the term (in P v Q) has already been negated in the datab3Se (ie check if
the contradiction of the term exists in the d3tabase) If so then repeat D2 for other
terms not found in X v Y or not matching T else go to b
13
b Check if the contradiction of the term matches either side of any equivalence
relation in the database If such a match is found then check if the other side of the
equivalence can be satisfied If so then repeat O~ for other terms not found in X v Y
or not matching T else the goal fails
It all the terms (in P v Q) which are not in X v Y or do not match T survive either one
of the above two tests then go to 03
03 This step is essentially done by eon whose goal is to satisfy the tail R of P v Q It
con succeeds then done else the search fails
To close this section we will give an example to illustrate what we have covered In
Section 42 through Section 44
Example Assume that we already haye the following expressions in the database
horse(skml) v dog(skmI)
contradiction(( dog(XI) ))shy
dog(XI)
query goo(( soZ horse(X)) ))
This query will be passed to 802 which will check it the term horse() can be satisfied iu Step S 1
of Section 43 It is a failure So we now go to Step S2 In this step we pick up the disjunction
horse(~kml) v dog(skml) (and its tail true) in the datab3Se and pass it together with the term
horse(X) to dis We are now in Step 01 of Section 44 In this step we find that dog(skml) does
not match horse(X) So we have to go to Step 02 In Step 023 We find that the term dog(skml)
has already been negated (the second expression in the database) So we go to next step 03 Since
the tail of the disjuDction horse(skml) v dog(skml) is the atom true con is satisfied and the
query succeeds
45 countl and count2
countl and count2 are responsible for the counting of tbe numbers of occurrence of a
given simple term or a conjunction of terms They are activated by input queries in the form
q( exists( X whatnum amp P) )
where whatnum is the l~bel for activating the counting of the numbers of occurrence of P which
can either be a term or a conjunction of terms
countl will count the number of term(s) which will satisfy P and associate(s) with
numerical quantification(s Two counters are set to update the lower and upper boundary or the
scope or the numfrical quantifications encountered
The contents of the two counters are then passed to count2 which is responsible for the
counting or the following three types of term First term(s) which will satisfy P and associate(s)
with existential quantification(s Second term(s) which will satisfy P and has(have) Prolog atom
as its(thfir) argument(s) Third term(s) that will satisfy P and itself(themselves) is(are) Prolog
atom(s )
46 equiv
equlv will be activated only after sol and B02 have failed The first two goals of equlv
are similar to that of Step S3 in Section 42 and Step D2b in Section 44 The third goal or equiv
makes possible the inference on either side of any equivalent relation For example if we type the
following three expressions to Prolog in assertion mode
l all( X hot(X) amp humidX) - winter(X)
2 all( X hot(X) amp bumid(X) ==gt unpresent(X))
3 - ( exists( X winter(X) ) )
and then ask APCIS in query mode
q( cxists( X unpresent(X) ) )
15
APCIS with the aid of equlv will be able to answer yes to this query
41 lmpll
lmpll can be considered as the last attempt that APCIS would make to satisfy a
query It is activated only after equlv has failed It will first check if the query is conditional If
so it will convert the implication symbol to equivalence symbol and search if such an equivalent
relation can be found in the database If so a success Otherwise a failure
5 More on the Inference Mechanism
Having looked at all the subparts at the top two levels of the inference mechanism we
are ready to look at other subparts at lower levels
51 num and cnum
One distinct fe3ture or APCIS is its ability to deal with numerical quantifications As
mentioned in Section 31 input queries and assertions will undergo different transformations in
the last step (Step 10) of translation This also holds true for expressions involving numerical
quantifications Consider the following expression
exists( 6 X horse(X) )
If it is entered to Prolog via assertion mode we will after going through all the steps of
translation have the rollowing entered to the database
horse(sk n I
number(sknl6)
Now if we want to ask Are there more than five horses 7 and type in
q( exists( gt5 X horse(X) ) )
1amp
APCIS will translate the question and enter to Prolog the following query
goo(( s02( horse(X) ) s02( num( X gt5 )) ))
Note that the term number(slml 6) in the database and the term num(X gt S) in the query are
different predicates and this difference is exactly where the power of the clause num(X N)
defined in APCIS comes from When the clause num(X N) in APCIS is activated it will search
through the database to see if there is any term of the form number(X I) whose first argument
matches the first argument of num(X Y) in the query It a match is found the second arguments
of both num(X Y) in the query and number(ltI) in the database will be passed to cnum in
APCIS
The job of cnum is to compare the numerical messages carried by the second
argument or the term rlum(X Y) in the query and the second argument of the term rlumber(X I)
in the database to see if they match with each other according to the rules defined in cnum
While there are 25 rules for such matching purposes the idea is simple
Imagine that the second argument Y of the term num(X Y) in the query
and the second argument I of the term num()( I) in the database each occupies a
place in an integer line (Le the integer line in mathematics) To have a match
the domain covered by Y should contain the domain covered by L
As an example the answer to the above query is positive since the domain of gt5
contains the domain or 6
Before closing this section we will bring out a speciaJ translation aspect of expressions
involving numbers by an example We first type to APCIS the Collowing expressions in assertion
mode
1 aU(X all(Y father(X Y) amp number(Y gt6) ==gt has_manY3hildren(X) ))
2 exists(X exists( 12 Y Cather(X Y) ) )
11
After going tbrougb all tbe translation steps tbe Collowing two expressions will be entered to tbe
database
I
bas_many_cbildren( Xl ) shy
Cather( Xl X2 )
num( X2 gt6 )
2
Catber( sk m1 sk n2 )
number( skn2 12 )
lotice that whenev(gtr a term with Cunctor number appears at the rigbt-band side oC a Prolog
clause its Cunctor will be cbanged to num automatically This treatment will greatly cnbance tbe
inference power of the clause sbown in l above For instance iC we now ask tbe question
q( exists( X bas_many_children(X) ) )
The right hand side oC the clause l will match the two terms in 2 and tbe query succeeds
52 Bel and cael
A special feature of APe is tbat all predicates tbat express relations = = gt
gt= lt and lt= can be expressed explicitly using infix notations as relational statements
called selectors To handle selectors we defined Bel in APCIS
Every expression involving selectors will undergo different translations in assertion mode
and query mode For example the assertion
a( exists( [X Y] box (X) amp box(Y) amp (weigh t(X) gt weight(Y) ) ) )
will be translated into the following three terms and entered to tbe database
box( skml )
box( skm2 )
18
weight( skm 1 ) gt weight( skm2 )
Now it we want to ask Is it true that there exists two boxes of different weights and type in
q( exists( [X Yl box(X) amp box(Y) amp ( weight(X) = weight(Y) ) ) )
The question will be transformed to the following query and entered to Prolog
goo(( so( box(XI) ) s02( box(X2) ) so2( sel( weightXI) = weight(X2) )) ))
Note that the selector in the above query is surrounded by the functor set When any clause or
8el in APCIS is activated it will search through the database to see it there is any selector whose
two arguments (left and right side or any selector symbol) match the two arguments of the
selector in the query At the same time 8el will check iC the selector symbols (may be different) or
the two different selectors (one in the query and one in the database) satisfy the rules defined in
sel There are 12 matching rules defined in sel All oC them ~re straightforward and will not be
discussed here An example will be enough to explain how 8el works
Consider the execution of the above transformed query The first two terms in the query
are satisfied by the first two terms in the database and Xl and X2 are instantiated to skml and
skm2 respectively The third term of the query will be passed to eel (of APCIS) which finds a
match on each side of the two selectors (one in the query and one in the database) At the same
time the two different selector symbols gt and = are found to satisfy one of the rules in
8el As a result the query succeeds
To enhance the inference power of clauses involving selectors all the selectors appearing
on the rightmiddothand side oC any clause will be surrounded by a functor set The idea is similar to
that in the last part of the previous section
c8el is exactly the same as 8el functionally It provides a convenient way to compare
selectors when dis is being executed
19
8 Printing Result
Whenever a goal is successfully executed APCIS will not only response with a yes but
also print out the matched terms or clauses in the database This is made possible by the built-in
function bagor and the two predicates wout and prt defined in APCIS
7 Summary
In this paper a description of a deductive inference system called APCIS (Annotated
Predicate Calculus Inference System) has been provided APCIS is able to carry out inferences
from expressions involving numerical quantifiers selectors disjunctions of non-negated terms
negated terms disjunctions of negated terms equivalences and exceptions It is also able to count
the numbers of occurrence of a given simple term or a conjunction of terms
The main idea of APCIS is that each input APC expression is first passed to a
preprocessor ( ie APC translator ) which dissolves and transforms each APC expression into
Prolog expression(s) which will then be loaded to Prolog system The user bas to specify whether
each input expression is to be entered as an assertion or as a query by invoking either assertion
mode or query mode respectively Each assertion or query will undergo different transformations in
the preprocessor The different treatment of assertion or query not only allows a full uS1ge of the
Prolog inference mechanism but also makes possible a higher level of inexact pattern matching
exemplified by the examples in Section 51 and Section 52 where the four predicates num
cnum sel and csel are discussed This higher level of pattern matching increases the inference
power of APCIS greatly
The design of contradiction and the treatment of the disjunction of non-negated terms
allow APCIS to accept non-Horn clauses and to carry out inference from them This feature
makes APCIS more general than Prolog
20
While APCIS performs very well in many sets of arguments provided by the author it is
still too early to jump to conclusion that it can perform equally well in all types of problems In
any event the expressiveness of APC has greatly been retained in the present version of APCIS
and moreover some design ideas or APCIS mentioned in this paper are not restricted to APCIS
- they may be carried over to learning programs with narrower scopes
21
References
[1] W F Clocksin and C S Mellish Programming In Prolog Springermiddot Verlag Berlin Hpoundidelberg 1981
[2] R S Michalski A Theory and Methodology of Inductive Learning Chpt 4 Machine L earning Tioga Publishing Co Palo Alto CaliJornia 1989
[3] K-E Pua Translating Annotated Predicate Calculu8 to Prolog ISG Report 84middot1 UlUCDCSmiddotFmiddot918 University oj Illinois Urbana IL June 1984
22
Appendix A
APCIS Users Manual
1 Get Started
Users are urged to follow the steps depicted below
1 Get the PROLOG interpreter by typing
alias prolog mntb2sammutsammutprologprolog (Vax A)
or
alias prolog mntb2sammutsammutbinprolog (Vax B)
2 Load apc and infer by typing
prolog apc infer
When large APC expressions are expected we can increase the stlck by typingI
prolog -snnnn ape infer
where ns denote the number of stacks in decimal
3 When the wording LSW - PROLOG appears on the terminal we are reldy to interact
with APCIS The four modes by which we can invoke APCIS are summarized below
a Assert ion-Translation Mode
ta(X)
b Query-Translation Mode
tq(X)
c Assertion Mode
a(X
d Query Mode
q(X)
23
where Xs are APC expressions
2 Notations Used in APCIS
Below is a summary or notations used in APCIS
a Logical operators
amp
v
==gt
lt=gt
-
negation
conjunction
disjunction
implication
equivalence
exception
b Binary relation symbols in selectors
-
=
gt=
lt=
gt
lt
equal
not equal
greater or equal
smaller or equ al
greater
smaller
c Relational operators in numerical quantifiers
lt less than
lt= less than or equal
gt greater than
gt= greater than or equal
d BinlTY operator in numerical quantifier
range
e Universal quantifier
all(X p(X))
f Existential quantifier
exists(X p(X))
g Numerical quantifier
exists(I X p(X))
where p(X) is a formula
where X is a variable or a Jist of variables or the
form [HI~rj and p(X) a formula
where I repersents expression involving integer(s)
and operator(s) in c or d above and p(X) a formula
25
Appendix B
APCIS Program Listings
------------------------------- Program Name APCIS - Part 1 APC Translator
-------------------------------
op(3OO fx -)1
op(500 xfy amp)
oPt 500 xfy v)
op(600 xfx )
op(700 fx [gt= lt= gt lt ]) op(400 xfy [= gt= lt= gt lt ])1 op(900 xfy gt lt=gt -])1
steps(X Xg) shy
numbervars(X 1 J Step 1 change variables to iis
rmimp(X X) Step 2 conv(X X3) Step 3
rewrite(X3 X4) Step 4
negin(X4 X5) Step 5
dropexist(X5 X6 1]) Step 6
dropall(X6 X7) Step 7
distrib(X7 X8) Step 8 clausiCy(X8 X9 [J) Step 9
ta(X) shysteps(X Xg)
(( Xg = II nl
print( yes it is always true) )
( nl nl printcl(X9))) Step 10a
tq(X) shy
steps(X Xg)
prques(Xg)
28
Step 2 Removing implic3tions amp Transforming exceptions and equiv3lences
rmimpl( P - Q (PI lt=gt (QI) ) amp ((PI) lt=gt QI) ) -
rmimpl(P PI) rmimpl(Q QI)
rmimplnp) lt=gt Q (PI lt=gt -(QI)) amp nPI) lt=gt QI) ) - 1
rmimpl(P PI) rmimpJ(Q QI)
rmimpJ(P lt-gt -(Q) (PI lt=gt -(QI)) amp nPI) lt=gt QI) ) -
rmimpl(P PI) rmimpl(Q QI)
rmimpl( P lt=gt Q PI lt=gt QI ) - I
rmimpl(P PI) rmimpl(Q QI)
rmimpl( P ==gt Q -(PI) v QI ) - I
rmimpl(P PI) rmimpl(Q QI)
rmimpl( all(X P) aI(X PI) ) - 1
rmimpl(P PI)
rmimpl( exists(X P) exists(X PI) ) -
rmimpl(P PI)
rmimpl( exists(I X P) exists(I X PI) ) -
rmimpl(P PI)
rmimpl( P amp Q PI amp Ql ) -
rmimpl(P PI) rmimpl(Q Ql)
rmimpl( P v Q PI v QI ) -
rmimpl(P PI) rmimpl(Q QI)
rmimpl( -(p) -(PI) ) - I
rmimpl(p PI)
rmimpl( P P )
St~p 3 Converting numerical amp distinctive quantifiers
L Numerical quantifiers
examples of input forms
1 exists(gt= i X pIX)) where i is an integer
2 exists(i X pIX)) where i is an integer
3 exists(i j X pIX)) where i j are integers and iltj
4 exists(il v i2 X pIX)) where is are integers
examples of output forms of this step
1 exists(X pIX) amp number(X gt= i) )
2 exists(X pIX) amp number(X i) ) 3 exists(X pIX) amp number(X ij) ) 4 exists(X pIX) amp number(X il v i2) )
II Distinctive quantifiers
27
example or input Corm
exists([XYL p(X Y))
example or output Corm or this step
exists(X exists(Y p(XY)) )
conv(P lt=gt Q PI lt=gt QI) - 1
conv(P PI) conv(Q QI)
conv(al1(X P) all(X PI)) -
conv(P PI)
conv(exists(HIT] P) R ) - conv(P PI) convert distinctive quantifier
convtdis(exists([HIT]PI) R)
conv( exists(I X P) exists(X PIamp number(X I) )) -
conv(P PI) convert numerical quantifier
conv(exists(X P) exists(X PI)) - 1
conv(P Pl)
conv(P amp Q PI amp QI) - 1
conv(P PI) conv(Q QI)
conv(P v Q PI v QI) - t conv(P PI) conv(Q QI)
convC(P) -(PI)) -
conv(P PI)
conv(P Pl
convtdis(existsl[XL P) exists(X P)) - atomic(X) convtdis(exists[XIYj Pl exists(X R)) shy
convtdis(exists(Y P) R)
Step 4 Rewriting compound predicates andor compound selectors
Outputs are smiple predicates andor simple selectors
rewrite(P lt=gt Q PI lt=gt QI) - t rewrite(P PI) rewrite(Q QI)
rewrite(all(X Pl all(X PI)) - 1 rewrite(P PI)
rewriteexists(X P) exists(X PI)) - I rewriteP PI)
rewrite(P amp Q PI amp QI) - rewrite(P P 1) rewrite( Q Q 1
rewrite(P v Q PI v QI) - 1
rewrite(P PI) rewrite(Q QI)
rewriteC(P) -(PI)) - I
28
rewrite(P PI) rewrite(F(A B) R) -
rewrite(A AI) rewrite(B BI) re(F(AI BI) R)
rewrite(F(A) R) -
rewrite(A AI) re(F(AI) H)
rewrite(F(A B C) R) -
rewrite(A AI) rewrite(B BI) rewrite(C CI) re(F(AI BI CI) R)
rewrite(F(A B C D) R) -
rewrite(A AI) rewrite(B Btl rewrite(C CI) rewrite(D DI) rc(F(AI BI CI Dl) H)
rewrite(PP)
re(F(A B v el (RI v R2) -
re(F(A Bl RIl re(F(A C) R2) reF(A B amp cl (RI amp R2)) -
re(F(A B) RI) re(F(A e) R2) re(F(A amp B C) (Rl amp R2)) -
re(F(A e) R 1) re(F(B C) R 2) re(F( v B el (R I v R2)) -
re(F(A el R I) reFB el R2) re(F(A amp Bl (R I amp R2)) -
re(F(A RI) re(F(BJH2) re(F(A v B) (R 1 v R2)) -
re(F(A) RI) re(F(B) R2)
re(F(A vB c Dl (RI v R2) -
re(F(A C D) RI) re(F(B C D) R2) re(F(A amp B C D) (RI amp R2)) -
re(F(A C D) Rll re(F(B C D) R2) re(F(A B v C D) (HI v R2)) -
re(F(A B D) RI) re(F(A C D) R2) re(F(A B amp C D) (HI amp R2)) -
re(F(A B D) RI) re(F(A C D) R2) re(F(A B C v D) (RI v R2)) -
re(F(A B C) R I) reF(A B D) R2) re(F(A B C amp D) (RI amp R2)) -
29
re(F(A B C) RI) re(F(A B D) RZ)
re(F(A v B e D E) (R I v R2)) -
re(F(A e D E) R I) re(F(B e D El R2) re(F(A amp B e D E) (RI amp RZ)) -
re(F(A e D El R 1) re(F(B e D E) R2) re(F(A B v e D E) (R I v R2)) -
re(F(A B D E) RI) re(F(A e D E) R2)
re(F(A B amp e D E) (RI amp R2)) -
re(F(A B D El RI) re(F(A e D E) RZ) re(F(A B e v D E) (R I v R2)) -
re(F(A B e El R 1) re(F(A B D E) RZ) re(F(A B e amp D E) (RI amp RZ)) -
re(F(A B e E) R I) re(F(A B D E) RZ)
re(F(A B e D vEl (RI v RZ)) - l
rc(F(A B C D) RI) re(F(A n e El RZ) re(F(A B e D amp El (RI amp RZ)) - ~
re(F(A B e D) RI) re(F(A B e El RZ)
re((A = B) (A = B)l-
re((A = Bl (A = 8)) -
retIA gt= BI (A gt= B)) -
re((A lt= B) (A lt= B)) -
re((A gt B) (A gt B))-
re((A lt Bl (A lt Bl)- re(A A)
Step) Bringing n(gation inwards
Degin(-(P) PI) - neg(P Pl)
negin(P lt=gt Q PI lt=gt Ql) - ~
negin(P PI) negiD(Q QI)
Degin(aU(X P) all(X PI)) - Degin(P PI) negin(exists(X P) exists(X PI))- negin(P PI) negin(P amp Q PI amp Ql) - Degin(P PI) negin(Q Ql)
Degin(P v Q PI v QI) - Degin(P PI) negin(Q QI) negin(P Pl
neg(-(P) PI) - negin(P PI)
neg(all(X P) exists(X PI)) - neg(P PI)
30
neg(exists(X P) all(X PI)) - neg(P PI)
neg(P amp Q PI v QI) - neg(P PI) neg(Q Ql)
neg(P v Q PI amp QI) - neg(P PI) neg(Q QI)
neg(P -(PH
Step 6 Dropping existnetial quanti6ers
dropexist(P lt=gt Q PI lt=gt QI Elerns) - dropexist(P PI Elerns) dropexist(Q QI Elerns)
dropexist(alJ(X P) all(XPI) Elerns)
dropexist(P PI [XIElernsJ)
dropexist(exists(X P amp nurnber(X Yraquo P2 Elerns) -
genfun(skn Newg) Fun = [NewgIElerns]
subst(FuD X P amp Dumber(X Y) PI)
dropexist(Pl P2 Elerns)
dropexist(exists(X P) PZ Elerns) -
genfun(skrn Newf) Fun = [NewfIElernsJ
subst(Fun X p PI)
dropex ist(P 1 P~ Elerns)
dropexist(P v Q PI v QI Elerns) - ~
dropexist(P PI Elerns) dropexist(Q Ql Elerns)
dropexist(P amp Q PI amp QI Elerns) - 1
dropexist(P Pl Elerns) dropexist(Q QI Elerns)
dropexist(P P _)
gen fun(R oot Newn arne) shy
getnurn(Root Nurn)
narne(Root Rootlist)
append(Rootlist[Nurnj Narnelist)
concat(Narnelist Newnarne)
getnurn(Root Nurn) shy
retract(currentnurn(Root Nurn 1 raquo
Nurn is Nurni + 1
asserta(currentnurn(Root Nurn))
getnurn(Root 1) - asserta(currentnurn(Root 1))
subst(New Old Val Val) - var(Val)
subst(New Old Old New) - 1 substNew Old Val Val) - atornic(Val)
31
subst(New Old Val Newval) shy
runctor(Val F N)
CUDctor(Newval F N)
subst_args(N New Old Val Newval)
subst_args(O J J - J J
subst_args(N New Old Val NewVal) shy
arg(N Val OldArg)
arg(N NewVal NewArg)
subst(New Old OldArg NewArg)
NI is N - I
subst_args(Nl New Old Val NewVal)
append([J L L) -
append([XILl] L2 [XIL3]) - append(Ll L2 L3)
Step - Dropping universal quantifiers
dropall(P lt=gt Q PI lt=gt QI)-
dropall(P PI) dropall(Q QI)
dropall(all(X P) PI) - ~ dropall(P PI)
dropall(P amp Q PI amp QI) -
dropall(P PI) dropall(Q QI)
dropall(P v Q PI v QI) -
dropall(P PI) dropall(Q QI)
dropall(P P)
Step 8 Distributing conjunctions over disjunctions
distrib(P lt=gt Q PI lt=gt Ql) - t distrib(P PI) distrib(Q QI)
distrib(P v Q R) -
distrib(P PI) distrib(Q QI)
distributing(PI v QI R)
distrib(P it Q PI it QI) -
distrib(P PI) distrib( Q QI)
distrib(P P)
distributing((P amp Q) v R PI amp QI) -
distrib(P v R PI) distrib(Q v R Ql)
32
distributing(P v (Q amp R) PI amp Ql) -
distrib(P v Q PI) distrib(P v R Ql)
distributing(P P)
Step 9 Packing each conjunction into clauses
c1ausify(P amp Q CI C2) -
clausiCy(P CI C3) c1ausify(Q C3 C2)
cbusiCy(P [d(A B)ICs] Cs) shy
inclause(P A [j B [I) 1
c1ausiry( C C)
inclause(P v Q A AI B B1) -
inc1ause(P A2 AI B2 Bl)
inclause(Q A A2 B B2)
inclausenp) A A B1 B) -
notin(P A) putin(P B B1)
inclause(P AI A B B) shy
notin(P Bl putin(P A AI)
notin(X [XU) - fail
notin(X [JLj) - notin(X L)
notin(X 1])
putin(X II [X]) - 1
putin(X [XILJ L) -
putin(X [YILJ [YILl]) - putin(X L Ll)
Step 1Oa Printing clauses
printcl([]) - nl nl
printcl(c1(AB)ICsj) - printcl(A Bl nl printcl(Cs)
printcl(L II) - printdis(IL) prinr)middot
printclHl L) - prin(contradiction(() printconl(rL)
print()) - ) printconj(rL) prinr )
printcl(Ll L2) shy
printdis(ILl) print( - ) printconj(rL2) prin()
printdis(S[Lj) - printcbar(SL)
33
printdis(S[LILs]) - printchu(SL) prin( v) printdis(SLs)
printconl(S[LI) - printchar(SL)
printconl(S[LILs]) - printchar(SL) prin( ) printconl(SLs)
printconj(S[L]) - tab(3) printchar(SL)
prin tconj( S [L IL sl) shy
tab(3) printchar(SL) print( ) printconj(SLs)
printchar(SP) shy
atomic(P)
name(P L)
L = [IT]
concat([XIT NewP)
prin(~ewP)
printchar(SP) shy
atomic(P)
prin(P)
printchar(SA lt= gt B) -
prin((l clausify(A AI [j) pl(eAl) prin())
print lt=gt )
prin(() cbusify(B Bl [I) pJ(eBl) prine))middot
printchar(rnumber(X N)) shy
prin(num() printchar(rx) prin( )
printchar(rN) prinC))
printchar(rF(A B)) shy
seJec(F(A B))
prinCsel() printchar(rA)
prin( F ) printchar(rB) prinC))
printchar(SF(A B)) shy
( selec(F(A B)) F = infix )
printchar(SA) prin( F ) printchar(SB)
printchar(SF(A)) shy
(F= prefix gt= F= prefix lt= F= prefixgt F= prefix lt )
prin(F ) printcbar(SA)
printchar(SP) shy
functor(P F MaxN)
prin(F ()
Nl is MaxN - 1
putout(S N 1 P MaxN)
34
prin())
putout(S 0 P MaxN) -
arg(~laxN P Argu)
prin tchar(SArgu)
putout(S N p MaxN) shy
Nt is MaxN - N arg(NI P Argu)
printcbar(SArgu )
prin( )
N2 is N - 1
putout(S N2 P MaxN)
selec(FA B)) shy
( F= infix = F= infix f= F= infix gt=
F= infix gt F= infix lt= F= infix lt )
35
----------------------------------Program Name APClS - Part 2 Inference Mechanism ---------------------------------- a(X) shy
steps(X X9)
(( X9 =[] nl
print( yes it is always true) )
( X9 =[cI(IJ[])] nl
print( no it is always false) )
( nl nl printel(X9) Step 1Oa
tell(temp_file) printel(X9) e1ose(temp_file) consult(temp_6Ie) ))
q(X) shy
asserta( in pt(X))
steps(X X9)
(( X9 = [] print(middot~H~~middot~t~)
print(THE AiSWER IS YES)
print( ilgIQlQl(~) )
( X9 = [e1([j [j)] Pr1nt ( OJ fi(i I~ iii Ij)middot(i)(i) fiyenQ)riiio(i)(ij)(i)fj)fiyen1li1il1li1il)__ gtw~ __~_~ _~~_ ~_-=~
print(THE ANSWER IS NO ) print() )
( teI1(temp_6Ie)
prques(X9) Step 1Ob
close(temp_file)
nl print(Let me think about it) nl
consult(temp_6Ie) ))
retrac t( in pt(X))
Step lOb Printing question
prques(lcl(A 8)1) - prin(goo(() pl(qA 8) print()))
prques([c1(A 8HCs]) - prin(goo(() pl(qA 8) print() pl(q Cs)
pl(e [c1(A 8)]) - pl(eA 8)
pl(q [c1(A 8)]) - pl(qA 8) print()))
pl(S [e1(A B)ICs]) - pl(SA B) prin( ) pl(S Cs)
38
pl(q [j L) - prin(c1ause(contradiction(() pcont(qL) prin())_))
pl(S [I L)- prin(so2(contradidion(() pcont(SL) print))))middot
pl(S [L] []) - prin(so2() pcbar(SL) prin())
pl(S L [J)- prinsol() plett(SL) print))
pl(S [L] LI) - prin(condi(() pchar(cL)
prin(() pcont(S Ll) prine))))
pl(S L Ll)- prin(c1ause() plert(cL)
prin(() pcont(S Ll) prine)))
plert(S[LJ) - pchar(SL)
plert(SjLILsj) - pcbar(SL) print v) pleCt(SLs)
pcont(S[L]) - pchar(SL)
pcont(S[LILsj) - pcbar(SL) prinr ) pcont(SLs)
pcbar(SP) shy
atomic(P)
name(PL)
( L = [IT] L = [5 k miT] L = [5 k niT] )
concat[XITj NewP)
prin(0JewP)
pchar(SP) shy
atomic(P)
prin(P) pchar(SA lt=gt B) -
prin(() dausify(A AI []) pl(eAI) prin())
prinr lt=gt ) prin(() dausify(B BI ]) pl(eB) print))
pchar(Snumber(X N)) shy
prin(num() pchar(SX) prin()
pchar(SN) prinr))
pcbar(SM N) - prin(M N)
pcbar(cF(A B)) shy
selec(F(A Braquo
pcbar(cA)
prine F ) pchar(cB) pchar(SF(A B)) shy
selec(F(A B))
prin(sel() pchar(SA)
print F ) pchar(SB) print)) I
31
pc har(SF(A)) shy
( F= prefix gt= F= prefix lt= F= prefixgt F= prefix lt )
prin(F ) pchar(SA)
pchar(SP)shy
runctor(P F MaxN)
prin(F ()
011 is MaxN - 1 pout(SNl P MaxN)
print) )
pout(S 0 P M3xN) - 1
arg(~bxN P Argu)
pchlr(SArgu )
pout(S N P MaxN shy
Nl is MaxN - N
arg(Nl P Argu)
pchar(SArgu
prin( )
N2 is N - 1
pout(S N2 P ~13xN)
Comparing numbers in numerical quantifiers
num(XN) shy
number(X I)
cnum(N 1) ~
cnumlaquo=01 lt=I- N gt=I
cnumlaquo=J lt I) - N gt=1-1
cnumlaquo=NIJ) - N gt=J 1
cnumlaquo=N J)- integer(I) N gt=I~
cnum(gt=N gt=1) - N lt=1
cnum(gt=N gt I) - N lt=1+ 1 cnum(gt=NIJ) - N lt=1
cnum(gt=N lt=1)- N lt=1
cnum(gt=N lt I) - N lt=1 L cnum(gt=N 1)- integer(I) N lt=1
cnum( lt N lt 1)- N gt=1 L
38
cnum( lt N lt=1) - N gt I cnum( lt NLJ) - N gt J
cnum( lt N 1)- integer(I) N gt 1
cnum(gt N gt I) - N lt=1 cnumlgt i gt=1) - N lt I
cnum(gt N lt=1) - N lt=0
cnum(gt N lt I) - N lt=0
cnum(gt iIJ) - N lt I cnum(gt N 1)- integer(I) N lt I
cnum(~LN lt=1) - M=I N gt= I l
cnum(~LN lt I) - M=l N gt= I-I
cnum(~LNLJ) - M lt =1 N gt = J
cnum(~1N 1)- integer(I) M lt= I N gt= I
cnum(- N) - integer(N)
Comparing selectors
sel(X = Y) shyX= Y
sel(X I=Y) shy(X I=Y X lt Y Xgt Y)
sel(X gt Y) shyXgt Y
sel(X lt Y) shyXlt Y
selX gt=Y) shy(X gt=Y X= Y Xgt Y)
se(X lt=Y) shy
(X lt=Y
X= Y
X lt Y)
csel(infix = infix =)
39
csel(infix = infix = csel(infix = infix gt)
csel(infix = infix lt) csel(infix gt infix gt) cseJ(infix lt infix lt) csel(infix gt= infix gt=) csel(infix gt= infix gt csel(infix gt= infix =)
csellinfix lt= infix lt=) csel(infix lt= infix lt) csel(infix lt= infix =)
Finding solutions
sol(X v Y) -
(( notetra(X) eon(X) ( sol(Y) )
( c1ause(P v Q R) not(cketra(P v Q))
dis(P v Q X v Y R) ~ )
( A lt=gt B equival(A lt=gt B X v Y) ~ I) sol(X) - ~ notetra(X) eon(X)
so~(X) - notetra(X)
( con (X)
( clause(P v Q R) not(ekctra(P v Q)) dis(P v Q X R) I)
cketra(P v Q) -
eketra(P) eketra(Q) eketra(F(I J)) shy
selec(F(I J))
c1ause(contradiction(sel(F(IJ))) _I
eketra(number(W I)) -
clause(cootradietion(num(Wl)) - eketr(P) shy
clause(contradiction(P) - 1
notctra(P) shy
not( e lause( con tradiction(P) _))
40
Searching (or disjunctions
dis(P v Q X v Y R) - dis(P X v Y R)
dis(Q X v Y R) con(R)
dis(P v Q X R) -
dis(P X R) dis(Q X R) con(R
dis(P X v Y R) - clause(contradicton(Pl J 1
dis(F(I J) sel(G(I J)) v Y R) - csel(G Fl dis(number(WI) num(W N v Y R) - cnum(N I)
dis(P P v Y R) -
dis(P X v Y R) - dis(P Y R)
dis(F(I J) seJ(G(IJ)) R) - csel(G F)
dis(number(WI) num(WN) R) - cnum(N I) dis(P P R) - 1
dis(FJ J X R) shy
( ckctra(F(IJ) cbeckeq(seJ(F(IJ))) )
dis(number(W Il X R) - ( ckctra(number(WI)) cbeckeq(num(WI)) )
dis(P X R) shy( ckctra(P) cbeckeq(P) ) 1
cbeckeq(P) shy
(( A lt=gt so2(contradiction(P))
bagof(A A [jj) ) ( so2(contradiction(P)) lt=gt B
bagof(B B Uj) ))
ckeq(A) shy
( so2(A) lt=gt B B lt=gt so2(A) ) bagof(B B UJ)
con((P Q)) -
clause(P R) con(R) con(Q) con(true) -
con(contradiction(P)) - clause(contradiction(P) J
con(cause(X Y)) - cause(X Y)
con(sel(X)) - sel(X)
con(num(X Y)) - num(X Y) con(P)- (( dause(P R) (con(R) ckeq(R)))
colJectin(P) )
collectin(P) shy
bagof(S (c1ause(P S) S = true) [L LIJ )
mkcon(L Ll L)
bagor(l (L2 ) UJ) L
mkcon((A AI) (B B1) (sol(A v B) e D)) -
mkcon(A B1 e) mkcon(A1 (B Bl) D)
mkcon(A (B B1) (sol(A v B) e)) -
mkcon(A Bl e)
mkcon((A AI) B (sol(A v B) e)) middot1
mkcon(Al B e)
mkcon(A B sol(A vB))
Searching ror equivalences
equival(A lt=gt B X v Y) - 1 ( equival(A lt=gt B X) equival(A lt=gt B Y) )
equival(s02(A) lt=gt 502(B) A) - clause(B _I equival(s02(B) lt=gt 502(A) A) c1ause(B _I
Top level or inrerence mechanism
goo((s02(whatnum) P)) -
getatm(P Xl
bagor(number(X Y) ( P so2(number(X Y)) ) A )
count1(A 00 L R) nl
bagor(X P B )
count2(B L R Ll Rl) nJ print()
(( LI = 0 Rl = 0 print(THE ANSWER IS ) nl
(( Ll = Rl prin(-Jumber or ) prn(P) print(is Ll) )
( Rlgt20000 prin(Number or I prn(P) print(is LI or more) )
42
( prin(Number of ) pfn(P) print( is from Ll to Rl) )) )
( print(THE ANSWER IS NO I )) print()
goo(X) shy
(( bagof(X X L) L = [I nl print()
print(THE ANSWER IS YES) nl wout(L) print() )
( equiv(X L) nl print()
print(THE ANSWER IS YES) nl wout(L) print(-) )
( c1ause(inpt(A ==gt B) _I ( impli(A B Z) impli(B A Z) ) print(l~Hl)
printTHE ANSWER IS YES) nl print(Z) print(Hj~(fH~) ))
goo(X) print( Hg)
print(THE ANSWER IS NO ) print( lH~lH~gg9l9lmiddotmiddot~Q(gmiddot)
00 Semhing for implications in equiV3lent relations
impli( B Z) shyt-ell( z1) prin(templ() pchn(S A lt=gt B) print()) close ( zl) consult(zl) templ(Z)
unload zl Z
Searching for equivalence
equiv (X L)
(( X lt=gt Y
equ(Y YI)t bagof(Y Yl L) L = [j )
(Y lt=gt X equ(Y YI) bagof(Y Yl L) L = [J )
( X = F(New)
clause(~ew T) makeup(T Tl)
(( Tl lt=gt B
equ(B Bl) bagof(Bl Bl M) M = [j L=[Newl )
(A lt=gt TI
equ(A AI) bagof(Al AI M) M = 1] L=INewj )) ))
makeup((A B) (AI Bl)) -
makeup(A A1) makeup(B BI)
makeup(A so2(A))
equ((A B) (AI BI)) -
equ(A AI) equ(B Bl)
equ(sol(X v Y) sol(XI v Yl)) -
equ(X XI) equ(Y YI)
equ(so2(X) so2(XI)) -
equ(X XI)
equ(contradiction(X) clJuse(contradiction(X) X) ) -
equ(X X)
Counting numbers
getatm((A B) X) -
( getatm(A X) getatm(B X) )
getatm(so2(F(X)) X) -
getatm(so2(X) X) - atom(X)
countl([J L R L R) -
countl([number(X Y)IT] L R L2 R2) shy
(( Y = (gt=~) LI is L + N Rl is R + 20001 l )
( Y = (gt N) LI is L+ N+ 1 RI is R + 20002 )
(Y == laquo=~) LI is L + 1 Rl is R + N )
(Y = laquo N) LI is L + 1 RI is R+N-I)
(Y == IJ LI is L + I Rl is R + J ) ( Y == N L1 is L + N RI is R + N ))
count1(T LI R 1 L2 R2)
count2(fJ L R L R) - 1
count2([XITJ L R L2 R2) shy
name(X Xl)
(( Xl = sknj LI is L Rl is R )
44
( Xl = Iskmj L1 is L + 1 RI is R + ZOOO1) ( LI is L + I RI is R + I ))
count2(T LI RI L2 R2)
pfn((A B)) - pfn(A) prn(B)
pCn(so2(F(X))) - prin(F )
prn(so2(X)) - atom(X) prin(X ) prn (so2(X))
Printing result
wout([XlJ - prt(X) nl woutf[xIY]) - prt(X) nl nl wout(Y)
prt(e(A B)) -
prt(A) prinr 8 ) prt(ltE) prt(eA) - prt(A)
prt(c(A EJ) - prin() prt(A) prine ) prt(B) prin(T)
prt(c A) - prt(A) prt((A E)) - ~
prt(A) nl prt(E) prt(sol(X v Y)) - ~
prt(X) prinC v) prt(Y) prt(A lt=gt B) -
prt(e A) prinC lt=gt ) prt(e B) prt(sol(X)) - prt(X)
prt(so2(X)) - prt(X
prt(c1ause(X Y)) - prt(X)
prt(contradiction(X)) - prin(contradiction() prt(cX) prinr))middot prt(num(XY)) - prin(number(X Y)) prt(sel(X)) - prin(X) prt(X v Y) - prt(X) prin( v) prt(Y) prt(X) prin(X)
Handling conditional queries
condi((Y Xl) shy
assertcon(X) Y
45
retractcon(X)
condi((B A))
retractcon(A) fail
assertcon((A B)) 1
assertcon(A) assertcon(B)
assertcon(A) asserta(A)
retrac teon ((A B)) 1
retracteon(A) retractcon (B)
retraetcon(A) - retract(A)
BIBLIOGRAPHIC DATA SHEET
Report No UIUCDS-F-84-928
3 Recipients Accession No
4 T ide and Subt ltle
An Annotated Predicate Calculus Inference System (APCIS)
S Report Date
November 1984 6
7 Author(s)
Kah-Eng Pua 8 Performing Organization Rept
No
9 Performing Organization Name and Address
Department of Computer Science University of Illinois Urbana IL
10 ProjectTaskWork Unit No
11 Contract Grant No NSF DCR 84-06081 ONR N00014-82-K-0186
12 Sponsoring Organization Name and Address
National Science Foundation Washington DC
13 Type of Report amp Period Covered
14
15 Supplementary Notes
16 Abstracts
This paper describes a deductive inference system called APCIS (Annotated Predicate Calculus Inference System) APCIS is able to carry out inferences from expressions involving numerical quantifiers selectors disjunctions of non-negated terms negated terms disjunctions of negated terms equivalences and exceptions It is also able to count the numbers of occurrence of a given simple term or a conjunction of terms The design of contradiction and the treatment of the disjunction of non-negated terms allow APCIS to accept Horn clauses as well as non-Horn clauses and to carry out inferences from them This feature makes APCIS more general than Prolog
17 Key lords and Document Analysis 170 Descriptors
APC (Annotated Predicate Calculus) APCIS (Annotated Predicate Calculus Inference System) Horn Clause Numerical Quantifier Prolog Selector
17b IdentifiersOpen-Ended Terms
17c COSATI FieldGroup
18 Availability Statement 19 Security Class (This
Re~f~~IA~SIF IFf)
21 ~o of Pages
49 211 ecurity Class (This
PageUNCLASSIFIED
22 Price
FOA NTIS n (10middot70 usco-oc 40329-
10
( hot(l) amp humid(l lt=gt -(winter(l)) ) amp
( -( hot(l) amp humid(l)) lt=gt winter(I)
In Step la they will again be transformed to
1
so2( state(on) ) lt=gt so2( contradiction( state(oH) ) )
so2( contradiction( state(on) ) ) lt=gt so2( state(oH) )
2
( s02(hot(XI)) so2(humid(XI))) lt=gt so2( contradiction( winter(Xl ))
so2( contradiction(( bot(Xl) humid(Xl) )) ) lt= gt so2( winter(XI) )
There are two advantages in the treatment of exception and equivalence symbols in this
way First it will prevent Prolog program from going into an infinite loop which is difficult to
avoid if equivalent relation such as A lt=gt B is transformed into the logically equivalent form
( A ==gt B) amp ( B ==gt A) Second by maintaining both sides of lt=gt symbol in
query form the searching on either side caD be done more easily and efficiently since the form
is already processed and does not need any further transformation
Inference Mechanism
As mentioned at the end of Section 31 goo sol and s02 each forms a part of the
inference mechanism of APCIS with goo occupying the top level and 80) and 802 the second
level In addition to these countl count2 equlv and impll are also at the second level of the
inference mechanism We will go over all of them in the following sections
I goo
goo is essentially the starting point of the inference Whenever a translated query is
loaded to Prolog system from temp-fie goo will go through one or more of the following steps in
11
sequence
G 1 Check if the query asks for the numbers of occurrence of certain term(s) It so then
pass It to eountl and eount2 else go to G2
G2 The query will be passed down to sol or s02 (or both) to check i( any assertion in the
database can satisfy the query It the answer is positive then the query succeeds else
go to G3
G3 The query will be passed to equlv to carry out further searching It the searching is a
success then the query will be closed with a success else go to G4
G4 It the query is in the form A ==gt B then it will be passed to Impli It Impll
succeeds then done else the query will be closed with a (ailure
42 sol
801 and 802 together with dis and eon form the most complicated part of the APCIS
iorerence mechanism In this and the next section we will look at sol and s02 dis and eon will
be discussed in Section 44 We will close Section 44 with an example that illustrates the
materials presented in Section 42 through Section 44
sol is at the second level of the inference mechanism It will deal with any disjunction of
non-negated terms For any disjunction passed to it it will go through one or more of the
following steps in sequence
S1 Check if any term In the disjunction can be satisfied by any term or clause in the
database without contradiction It so then done else go to S2
S2 Pass the disjunction together with another disjunction (and its tlil) picked up from
the database to dis It dis succeeds then done else go to S3
S3 Pass the disjunction down to equlval which will check if any term in the disjunction
matches either side of any equivalence relation in the database It such a match is
found then check if the other side of the equivalence C3n be satisfied It so then done
else the goal fails
43 s02
s02 is also at the second level of the inference mechanism It will take care of all the
simple terms in the transl1ted query The following is the sequence that s02 wiII follow in
searching
S1 Check if the term passed to it caD be s3tisfied by any term or clause in the d3tabase
without contradiction It so then done else go to S2
S2 Pass the term together with a disjunction of terms (and its tail) picked up from the
database to dis If dis succeeds then done else the goal fails
44 dis and con
dis has three arguments In the first two clauses of dIs the first argument P v Q is
found in the database using the builtmiddotin functiol clause and the third argument R is the tair of
the term or the clause P v Q If P v Q is not a clause but a term R will be instantiated to trUE
The second 3rgument comes from either lIol or 802 and thus takes the form of either X v Y (a
disjunction of terms) or T (3 simple term)
All the clauses of dis together with con will perform the searching as exemplified in the
following algorithm (we will keep the notationsin this section)
01 Check if every term in P v Q is in X v Y It so then go to 03 else go to D2
02 For any term (in P v Q) which is not in X v Y or does not match T perform the
following tests
a Check if the term (in P v Q) has already been negated in the datab3Se (ie check if
the contradiction of the term exists in the d3tabase) If so then repeat D2 for other
terms not found in X v Y or not matching T else go to b
13
b Check if the contradiction of the term matches either side of any equivalence
relation in the database If such a match is found then check if the other side of the
equivalence can be satisfied If so then repeat O~ for other terms not found in X v Y
or not matching T else the goal fails
It all the terms (in P v Q) which are not in X v Y or do not match T survive either one
of the above two tests then go to 03
03 This step is essentially done by eon whose goal is to satisfy the tail R of P v Q It
con succeeds then done else the search fails
To close this section we will give an example to illustrate what we have covered In
Section 42 through Section 44
Example Assume that we already haye the following expressions in the database
horse(skml) v dog(skmI)
contradiction(( dog(XI) ))shy
dog(XI)
query goo(( soZ horse(X)) ))
This query will be passed to 802 which will check it the term horse() can be satisfied iu Step S 1
of Section 43 It is a failure So we now go to Step S2 In this step we pick up the disjunction
horse(~kml) v dog(skml) (and its tail true) in the datab3Se and pass it together with the term
horse(X) to dis We are now in Step 01 of Section 44 In this step we find that dog(skml) does
not match horse(X) So we have to go to Step 02 In Step 023 We find that the term dog(skml)
has already been negated (the second expression in the database) So we go to next step 03 Since
the tail of the disjuDction horse(skml) v dog(skml) is the atom true con is satisfied and the
query succeeds
45 countl and count2
countl and count2 are responsible for the counting of tbe numbers of occurrence of a
given simple term or a conjunction of terms They are activated by input queries in the form
q( exists( X whatnum amp P) )
where whatnum is the l~bel for activating the counting of the numbers of occurrence of P which
can either be a term or a conjunction of terms
countl will count the number of term(s) which will satisfy P and associate(s) with
numerical quantification(s Two counters are set to update the lower and upper boundary or the
scope or the numfrical quantifications encountered
The contents of the two counters are then passed to count2 which is responsible for the
counting or the following three types of term First term(s) which will satisfy P and associate(s)
with existential quantification(s Second term(s) which will satisfy P and has(have) Prolog atom
as its(thfir) argument(s) Third term(s) that will satisfy P and itself(themselves) is(are) Prolog
atom(s )
46 equiv
equlv will be activated only after sol and B02 have failed The first two goals of equlv
are similar to that of Step S3 in Section 42 and Step D2b in Section 44 The third goal or equiv
makes possible the inference on either side of any equivalent relation For example if we type the
following three expressions to Prolog in assertion mode
l all( X hot(X) amp humidX) - winter(X)
2 all( X hot(X) amp bumid(X) ==gt unpresent(X))
3 - ( exists( X winter(X) ) )
and then ask APCIS in query mode
q( cxists( X unpresent(X) ) )
15
APCIS with the aid of equlv will be able to answer yes to this query
41 lmpll
lmpll can be considered as the last attempt that APCIS would make to satisfy a
query It is activated only after equlv has failed It will first check if the query is conditional If
so it will convert the implication symbol to equivalence symbol and search if such an equivalent
relation can be found in the database If so a success Otherwise a failure
5 More on the Inference Mechanism
Having looked at all the subparts at the top two levels of the inference mechanism we
are ready to look at other subparts at lower levels
51 num and cnum
One distinct fe3ture or APCIS is its ability to deal with numerical quantifications As
mentioned in Section 31 input queries and assertions will undergo different transformations in
the last step (Step 10) of translation This also holds true for expressions involving numerical
quantifications Consider the following expression
exists( 6 X horse(X) )
If it is entered to Prolog via assertion mode we will after going through all the steps of
translation have the rollowing entered to the database
horse(sk n I
number(sknl6)
Now if we want to ask Are there more than five horses 7 and type in
q( exists( gt5 X horse(X) ) )
1amp
APCIS will translate the question and enter to Prolog the following query
goo(( s02( horse(X) ) s02( num( X gt5 )) ))
Note that the term number(slml 6) in the database and the term num(X gt S) in the query are
different predicates and this difference is exactly where the power of the clause num(X N)
defined in APCIS comes from When the clause num(X N) in APCIS is activated it will search
through the database to see if there is any term of the form number(X I) whose first argument
matches the first argument of num(X Y) in the query It a match is found the second arguments
of both num(X Y) in the query and number(ltI) in the database will be passed to cnum in
APCIS
The job of cnum is to compare the numerical messages carried by the second
argument or the term rlum(X Y) in the query and the second argument of the term rlumber(X I)
in the database to see if they match with each other according to the rules defined in cnum
While there are 25 rules for such matching purposes the idea is simple
Imagine that the second argument Y of the term num(X Y) in the query
and the second argument I of the term num()( I) in the database each occupies a
place in an integer line (Le the integer line in mathematics) To have a match
the domain covered by Y should contain the domain covered by L
As an example the answer to the above query is positive since the domain of gt5
contains the domain or 6
Before closing this section we will bring out a speciaJ translation aspect of expressions
involving numbers by an example We first type to APCIS the Collowing expressions in assertion
mode
1 aU(X all(Y father(X Y) amp number(Y gt6) ==gt has_manY3hildren(X) ))
2 exists(X exists( 12 Y Cather(X Y) ) )
11
After going tbrougb all tbe translation steps tbe Collowing two expressions will be entered to tbe
database
I
bas_many_cbildren( Xl ) shy
Cather( Xl X2 )
num( X2 gt6 )
2
Catber( sk m1 sk n2 )
number( skn2 12 )
lotice that whenev(gtr a term with Cunctor number appears at the rigbt-band side oC a Prolog
clause its Cunctor will be cbanged to num automatically This treatment will greatly cnbance tbe
inference power of the clause sbown in l above For instance iC we now ask tbe question
q( exists( X bas_many_children(X) ) )
The right hand side oC the clause l will match the two terms in 2 and tbe query succeeds
52 Bel and cael
A special feature of APe is tbat all predicates tbat express relations = = gt
gt= lt and lt= can be expressed explicitly using infix notations as relational statements
called selectors To handle selectors we defined Bel in APCIS
Every expression involving selectors will undergo different translations in assertion mode
and query mode For example the assertion
a( exists( [X Y] box (X) amp box(Y) amp (weigh t(X) gt weight(Y) ) ) )
will be translated into the following three terms and entered to tbe database
box( skml )
box( skm2 )
18
weight( skm 1 ) gt weight( skm2 )
Now it we want to ask Is it true that there exists two boxes of different weights and type in
q( exists( [X Yl box(X) amp box(Y) amp ( weight(X) = weight(Y) ) ) )
The question will be transformed to the following query and entered to Prolog
goo(( so( box(XI) ) s02( box(X2) ) so2( sel( weightXI) = weight(X2) )) ))
Note that the selector in the above query is surrounded by the functor set When any clause or
8el in APCIS is activated it will search through the database to see it there is any selector whose
two arguments (left and right side or any selector symbol) match the two arguments of the
selector in the query At the same time 8el will check iC the selector symbols (may be different) or
the two different selectors (one in the query and one in the database) satisfy the rules defined in
sel There are 12 matching rules defined in sel All oC them ~re straightforward and will not be
discussed here An example will be enough to explain how 8el works
Consider the execution of the above transformed query The first two terms in the query
are satisfied by the first two terms in the database and Xl and X2 are instantiated to skml and
skm2 respectively The third term of the query will be passed to eel (of APCIS) which finds a
match on each side of the two selectors (one in the query and one in the database) At the same
time the two different selector symbols gt and = are found to satisfy one of the rules in
8el As a result the query succeeds
To enhance the inference power of clauses involving selectors all the selectors appearing
on the rightmiddothand side oC any clause will be surrounded by a functor set The idea is similar to
that in the last part of the previous section
c8el is exactly the same as 8el functionally It provides a convenient way to compare
selectors when dis is being executed
19
8 Printing Result
Whenever a goal is successfully executed APCIS will not only response with a yes but
also print out the matched terms or clauses in the database This is made possible by the built-in
function bagor and the two predicates wout and prt defined in APCIS
7 Summary
In this paper a description of a deductive inference system called APCIS (Annotated
Predicate Calculus Inference System) has been provided APCIS is able to carry out inferences
from expressions involving numerical quantifiers selectors disjunctions of non-negated terms
negated terms disjunctions of negated terms equivalences and exceptions It is also able to count
the numbers of occurrence of a given simple term or a conjunction of terms
The main idea of APCIS is that each input APC expression is first passed to a
preprocessor ( ie APC translator ) which dissolves and transforms each APC expression into
Prolog expression(s) which will then be loaded to Prolog system The user bas to specify whether
each input expression is to be entered as an assertion or as a query by invoking either assertion
mode or query mode respectively Each assertion or query will undergo different transformations in
the preprocessor The different treatment of assertion or query not only allows a full uS1ge of the
Prolog inference mechanism but also makes possible a higher level of inexact pattern matching
exemplified by the examples in Section 51 and Section 52 where the four predicates num
cnum sel and csel are discussed This higher level of pattern matching increases the inference
power of APCIS greatly
The design of contradiction and the treatment of the disjunction of non-negated terms
allow APCIS to accept non-Horn clauses and to carry out inference from them This feature
makes APCIS more general than Prolog
20
While APCIS performs very well in many sets of arguments provided by the author it is
still too early to jump to conclusion that it can perform equally well in all types of problems In
any event the expressiveness of APC has greatly been retained in the present version of APCIS
and moreover some design ideas or APCIS mentioned in this paper are not restricted to APCIS
- they may be carried over to learning programs with narrower scopes
21
References
[1] W F Clocksin and C S Mellish Programming In Prolog Springermiddot Verlag Berlin Hpoundidelberg 1981
[2] R S Michalski A Theory and Methodology of Inductive Learning Chpt 4 Machine L earning Tioga Publishing Co Palo Alto CaliJornia 1989
[3] K-E Pua Translating Annotated Predicate Calculu8 to Prolog ISG Report 84middot1 UlUCDCSmiddotFmiddot918 University oj Illinois Urbana IL June 1984
22
Appendix A
APCIS Users Manual
1 Get Started
Users are urged to follow the steps depicted below
1 Get the PROLOG interpreter by typing
alias prolog mntb2sammutsammutprologprolog (Vax A)
or
alias prolog mntb2sammutsammutbinprolog (Vax B)
2 Load apc and infer by typing
prolog apc infer
When large APC expressions are expected we can increase the stlck by typingI
prolog -snnnn ape infer
where ns denote the number of stacks in decimal
3 When the wording LSW - PROLOG appears on the terminal we are reldy to interact
with APCIS The four modes by which we can invoke APCIS are summarized below
a Assert ion-Translation Mode
ta(X)
b Query-Translation Mode
tq(X)
c Assertion Mode
a(X
d Query Mode
q(X)
23
where Xs are APC expressions
2 Notations Used in APCIS
Below is a summary or notations used in APCIS
a Logical operators
amp
v
==gt
lt=gt
-
negation
conjunction
disjunction
implication
equivalence
exception
b Binary relation symbols in selectors
-
=
gt=
lt=
gt
lt
equal
not equal
greater or equal
smaller or equ al
greater
smaller
c Relational operators in numerical quantifiers
lt less than
lt= less than or equal
gt greater than
gt= greater than or equal
d BinlTY operator in numerical quantifier
range
e Universal quantifier
all(X p(X))
f Existential quantifier
exists(X p(X))
g Numerical quantifier
exists(I X p(X))
where p(X) is a formula
where X is a variable or a Jist of variables or the
form [HI~rj and p(X) a formula
where I repersents expression involving integer(s)
and operator(s) in c or d above and p(X) a formula
25
Appendix B
APCIS Program Listings
------------------------------- Program Name APCIS - Part 1 APC Translator
-------------------------------
op(3OO fx -)1
op(500 xfy amp)
oPt 500 xfy v)
op(600 xfx )
op(700 fx [gt= lt= gt lt ]) op(400 xfy [= gt= lt= gt lt ])1 op(900 xfy gt lt=gt -])1
steps(X Xg) shy
numbervars(X 1 J Step 1 change variables to iis
rmimp(X X) Step 2 conv(X X3) Step 3
rewrite(X3 X4) Step 4
negin(X4 X5) Step 5
dropexist(X5 X6 1]) Step 6
dropall(X6 X7) Step 7
distrib(X7 X8) Step 8 clausiCy(X8 X9 [J) Step 9
ta(X) shysteps(X Xg)
(( Xg = II nl
print( yes it is always true) )
( nl nl printcl(X9))) Step 10a
tq(X) shy
steps(X Xg)
prques(Xg)
28
Step 2 Removing implic3tions amp Transforming exceptions and equiv3lences
rmimpl( P - Q (PI lt=gt (QI) ) amp ((PI) lt=gt QI) ) -
rmimpl(P PI) rmimpl(Q QI)
rmimplnp) lt=gt Q (PI lt=gt -(QI)) amp nPI) lt=gt QI) ) - 1
rmimpl(P PI) rmimpJ(Q QI)
rmimpJ(P lt-gt -(Q) (PI lt=gt -(QI)) amp nPI) lt=gt QI) ) -
rmimpl(P PI) rmimpl(Q QI)
rmimpl( P lt=gt Q PI lt=gt QI ) - I
rmimpl(P PI) rmimpl(Q QI)
rmimpl( P ==gt Q -(PI) v QI ) - I
rmimpl(P PI) rmimpl(Q QI)
rmimpl( all(X P) aI(X PI) ) - 1
rmimpl(P PI)
rmimpl( exists(X P) exists(X PI) ) -
rmimpl(P PI)
rmimpl( exists(I X P) exists(I X PI) ) -
rmimpl(P PI)
rmimpl( P amp Q PI amp Ql ) -
rmimpl(P PI) rmimpl(Q Ql)
rmimpl( P v Q PI v QI ) -
rmimpl(P PI) rmimpl(Q QI)
rmimpl( -(p) -(PI) ) - I
rmimpl(p PI)
rmimpl( P P )
St~p 3 Converting numerical amp distinctive quantifiers
L Numerical quantifiers
examples of input forms
1 exists(gt= i X pIX)) where i is an integer
2 exists(i X pIX)) where i is an integer
3 exists(i j X pIX)) where i j are integers and iltj
4 exists(il v i2 X pIX)) where is are integers
examples of output forms of this step
1 exists(X pIX) amp number(X gt= i) )
2 exists(X pIX) amp number(X i) ) 3 exists(X pIX) amp number(X ij) ) 4 exists(X pIX) amp number(X il v i2) )
II Distinctive quantifiers
27
example or input Corm
exists([XYL p(X Y))
example or output Corm or this step
exists(X exists(Y p(XY)) )
conv(P lt=gt Q PI lt=gt QI) - 1
conv(P PI) conv(Q QI)
conv(al1(X P) all(X PI)) -
conv(P PI)
conv(exists(HIT] P) R ) - conv(P PI) convert distinctive quantifier
convtdis(exists([HIT]PI) R)
conv( exists(I X P) exists(X PIamp number(X I) )) -
conv(P PI) convert numerical quantifier
conv(exists(X P) exists(X PI)) - 1
conv(P Pl)
conv(P amp Q PI amp QI) - 1
conv(P PI) conv(Q QI)
conv(P v Q PI v QI) - t conv(P PI) conv(Q QI)
convC(P) -(PI)) -
conv(P PI)
conv(P Pl
convtdis(existsl[XL P) exists(X P)) - atomic(X) convtdis(exists[XIYj Pl exists(X R)) shy
convtdis(exists(Y P) R)
Step 4 Rewriting compound predicates andor compound selectors
Outputs are smiple predicates andor simple selectors
rewrite(P lt=gt Q PI lt=gt QI) - t rewrite(P PI) rewrite(Q QI)
rewrite(all(X Pl all(X PI)) - 1 rewrite(P PI)
rewriteexists(X P) exists(X PI)) - I rewriteP PI)
rewrite(P amp Q PI amp QI) - rewrite(P P 1) rewrite( Q Q 1
rewrite(P v Q PI v QI) - 1
rewrite(P PI) rewrite(Q QI)
rewriteC(P) -(PI)) - I
28
rewrite(P PI) rewrite(F(A B) R) -
rewrite(A AI) rewrite(B BI) re(F(AI BI) R)
rewrite(F(A) R) -
rewrite(A AI) re(F(AI) H)
rewrite(F(A B C) R) -
rewrite(A AI) rewrite(B BI) rewrite(C CI) re(F(AI BI CI) R)
rewrite(F(A B C D) R) -
rewrite(A AI) rewrite(B Btl rewrite(C CI) rewrite(D DI) rc(F(AI BI CI Dl) H)
rewrite(PP)
re(F(A B v el (RI v R2) -
re(F(A Bl RIl re(F(A C) R2) reF(A B amp cl (RI amp R2)) -
re(F(A B) RI) re(F(A e) R2) re(F(A amp B C) (Rl amp R2)) -
re(F(A e) R 1) re(F(B C) R 2) re(F( v B el (R I v R2)) -
re(F(A el R I) reFB el R2) re(F(A amp Bl (R I amp R2)) -
re(F(A RI) re(F(BJH2) re(F(A v B) (R 1 v R2)) -
re(F(A) RI) re(F(B) R2)
re(F(A vB c Dl (RI v R2) -
re(F(A C D) RI) re(F(B C D) R2) re(F(A amp B C D) (RI amp R2)) -
re(F(A C D) Rll re(F(B C D) R2) re(F(A B v C D) (HI v R2)) -
re(F(A B D) RI) re(F(A C D) R2) re(F(A B amp C D) (HI amp R2)) -
re(F(A B D) RI) re(F(A C D) R2) re(F(A B C v D) (RI v R2)) -
re(F(A B C) R I) reF(A B D) R2) re(F(A B C amp D) (RI amp R2)) -
29
re(F(A B C) RI) re(F(A B D) RZ)
re(F(A v B e D E) (R I v R2)) -
re(F(A e D E) R I) re(F(B e D El R2) re(F(A amp B e D E) (RI amp RZ)) -
re(F(A e D El R 1) re(F(B e D E) R2) re(F(A B v e D E) (R I v R2)) -
re(F(A B D E) RI) re(F(A e D E) R2)
re(F(A B amp e D E) (RI amp R2)) -
re(F(A B D El RI) re(F(A e D E) RZ) re(F(A B e v D E) (R I v R2)) -
re(F(A B e El R 1) re(F(A B D E) RZ) re(F(A B e amp D E) (RI amp RZ)) -
re(F(A B e E) R I) re(F(A B D E) RZ)
re(F(A B e D vEl (RI v RZ)) - l
rc(F(A B C D) RI) re(F(A n e El RZ) re(F(A B e D amp El (RI amp RZ)) - ~
re(F(A B e D) RI) re(F(A B e El RZ)
re((A = B) (A = B)l-
re((A = Bl (A = 8)) -
retIA gt= BI (A gt= B)) -
re((A lt= B) (A lt= B)) -
re((A gt B) (A gt B))-
re((A lt Bl (A lt Bl)- re(A A)
Step) Bringing n(gation inwards
Degin(-(P) PI) - neg(P Pl)
negin(P lt=gt Q PI lt=gt Ql) - ~
negin(P PI) negiD(Q QI)
Degin(aU(X P) all(X PI)) - Degin(P PI) negin(exists(X P) exists(X PI))- negin(P PI) negin(P amp Q PI amp Ql) - Degin(P PI) negin(Q Ql)
Degin(P v Q PI v QI) - Degin(P PI) negin(Q QI) negin(P Pl
neg(-(P) PI) - negin(P PI)
neg(all(X P) exists(X PI)) - neg(P PI)
30
neg(exists(X P) all(X PI)) - neg(P PI)
neg(P amp Q PI v QI) - neg(P PI) neg(Q Ql)
neg(P v Q PI amp QI) - neg(P PI) neg(Q QI)
neg(P -(PH
Step 6 Dropping existnetial quanti6ers
dropexist(P lt=gt Q PI lt=gt QI Elerns) - dropexist(P PI Elerns) dropexist(Q QI Elerns)
dropexist(alJ(X P) all(XPI) Elerns)
dropexist(P PI [XIElernsJ)
dropexist(exists(X P amp nurnber(X Yraquo P2 Elerns) -
genfun(skn Newg) Fun = [NewgIElerns]
subst(FuD X P amp Dumber(X Y) PI)
dropexist(Pl P2 Elerns)
dropexist(exists(X P) PZ Elerns) -
genfun(skrn Newf) Fun = [NewfIElernsJ
subst(Fun X p PI)
dropex ist(P 1 P~ Elerns)
dropexist(P v Q PI v QI Elerns) - ~
dropexist(P PI Elerns) dropexist(Q Ql Elerns)
dropexist(P amp Q PI amp QI Elerns) - 1
dropexist(P Pl Elerns) dropexist(Q QI Elerns)
dropexist(P P _)
gen fun(R oot Newn arne) shy
getnurn(Root Nurn)
narne(Root Rootlist)
append(Rootlist[Nurnj Narnelist)
concat(Narnelist Newnarne)
getnurn(Root Nurn) shy
retract(currentnurn(Root Nurn 1 raquo
Nurn is Nurni + 1
asserta(currentnurn(Root Nurn))
getnurn(Root 1) - asserta(currentnurn(Root 1))
subst(New Old Val Val) - var(Val)
subst(New Old Old New) - 1 substNew Old Val Val) - atornic(Val)
31
subst(New Old Val Newval) shy
runctor(Val F N)
CUDctor(Newval F N)
subst_args(N New Old Val Newval)
subst_args(O J J - J J
subst_args(N New Old Val NewVal) shy
arg(N Val OldArg)
arg(N NewVal NewArg)
subst(New Old OldArg NewArg)
NI is N - I
subst_args(Nl New Old Val NewVal)
append([J L L) -
append([XILl] L2 [XIL3]) - append(Ll L2 L3)
Step - Dropping universal quantifiers
dropall(P lt=gt Q PI lt=gt QI)-
dropall(P PI) dropall(Q QI)
dropall(all(X P) PI) - ~ dropall(P PI)
dropall(P amp Q PI amp QI) -
dropall(P PI) dropall(Q QI)
dropall(P v Q PI v QI) -
dropall(P PI) dropall(Q QI)
dropall(P P)
Step 8 Distributing conjunctions over disjunctions
distrib(P lt=gt Q PI lt=gt Ql) - t distrib(P PI) distrib(Q QI)
distrib(P v Q R) -
distrib(P PI) distrib(Q QI)
distributing(PI v QI R)
distrib(P it Q PI it QI) -
distrib(P PI) distrib( Q QI)
distrib(P P)
distributing((P amp Q) v R PI amp QI) -
distrib(P v R PI) distrib(Q v R Ql)
32
distributing(P v (Q amp R) PI amp Ql) -
distrib(P v Q PI) distrib(P v R Ql)
distributing(P P)
Step 9 Packing each conjunction into clauses
c1ausify(P amp Q CI C2) -
clausiCy(P CI C3) c1ausify(Q C3 C2)
cbusiCy(P [d(A B)ICs] Cs) shy
inclause(P A [j B [I) 1
c1ausiry( C C)
inclause(P v Q A AI B B1) -
inc1ause(P A2 AI B2 Bl)
inclause(Q A A2 B B2)
inclausenp) A A B1 B) -
notin(P A) putin(P B B1)
inclause(P AI A B B) shy
notin(P Bl putin(P A AI)
notin(X [XU) - fail
notin(X [JLj) - notin(X L)
notin(X 1])
putin(X II [X]) - 1
putin(X [XILJ L) -
putin(X [YILJ [YILl]) - putin(X L Ll)
Step 1Oa Printing clauses
printcl([]) - nl nl
printcl(c1(AB)ICsj) - printcl(A Bl nl printcl(Cs)
printcl(L II) - printdis(IL) prinr)middot
printclHl L) - prin(contradiction(() printconl(rL)
print()) - ) printconj(rL) prinr )
printcl(Ll L2) shy
printdis(ILl) print( - ) printconj(rL2) prin()
printdis(S[Lj) - printcbar(SL)
33
printdis(S[LILs]) - printchu(SL) prin( v) printdis(SLs)
printconl(S[LI) - printchar(SL)
printconl(S[LILs]) - printchar(SL) prin( ) printconl(SLs)
printconj(S[L]) - tab(3) printchar(SL)
prin tconj( S [L IL sl) shy
tab(3) printchar(SL) print( ) printconj(SLs)
printchar(SP) shy
atomic(P)
name(P L)
L = [IT]
concat([XIT NewP)
prin(~ewP)
printchar(SP) shy
atomic(P)
prin(P)
printchar(SA lt= gt B) -
prin((l clausify(A AI [j) pl(eAl) prin())
print lt=gt )
prin(() cbusify(B Bl [I) pJ(eBl) prine))middot
printchar(rnumber(X N)) shy
prin(num() printchar(rx) prin( )
printchar(rN) prinC))
printchar(rF(A B)) shy
seJec(F(A B))
prinCsel() printchar(rA)
prin( F ) printchar(rB) prinC))
printchar(SF(A B)) shy
( selec(F(A B)) F = infix )
printchar(SA) prin( F ) printchar(SB)
printchar(SF(A)) shy
(F= prefix gt= F= prefix lt= F= prefixgt F= prefix lt )
prin(F ) printcbar(SA)
printchar(SP) shy
functor(P F MaxN)
prin(F ()
Nl is MaxN - 1
putout(S N 1 P MaxN)
34
prin())
putout(S 0 P MaxN) -
arg(~laxN P Argu)
prin tchar(SArgu)
putout(S N p MaxN) shy
Nt is MaxN - N arg(NI P Argu)
printcbar(SArgu )
prin( )
N2 is N - 1
putout(S N2 P MaxN)
selec(FA B)) shy
( F= infix = F= infix f= F= infix gt=
F= infix gt F= infix lt= F= infix lt )
35
----------------------------------Program Name APClS - Part 2 Inference Mechanism ---------------------------------- a(X) shy
steps(X X9)
(( X9 =[] nl
print( yes it is always true) )
( X9 =[cI(IJ[])] nl
print( no it is always false) )
( nl nl printel(X9) Step 1Oa
tell(temp_file) printel(X9) e1ose(temp_file) consult(temp_6Ie) ))
q(X) shy
asserta( in pt(X))
steps(X X9)
(( X9 = [] print(middot~H~~middot~t~)
print(THE AiSWER IS YES)
print( ilgIQlQl(~) )
( X9 = [e1([j [j)] Pr1nt ( OJ fi(i I~ iii Ij)middot(i)(i) fiyenQ)riiio(i)(ij)(i)fj)fiyen1li1il1li1il)__ gtw~ __~_~ _~~_ ~_-=~
print(THE ANSWER IS NO ) print() )
( teI1(temp_6Ie)
prques(X9) Step 1Ob
close(temp_file)
nl print(Let me think about it) nl
consult(temp_6Ie) ))
retrac t( in pt(X))
Step lOb Printing question
prques(lcl(A 8)1) - prin(goo(() pl(qA 8) print()))
prques([c1(A 8HCs]) - prin(goo(() pl(qA 8) print() pl(q Cs)
pl(e [c1(A 8)]) - pl(eA 8)
pl(q [c1(A 8)]) - pl(qA 8) print()))
pl(S [e1(A B)ICs]) - pl(SA B) prin( ) pl(S Cs)
38
pl(q [j L) - prin(c1ause(contradiction(() pcont(qL) prin())_))
pl(S [I L)- prin(so2(contradidion(() pcont(SL) print))))middot
pl(S [L] []) - prin(so2() pcbar(SL) prin())
pl(S L [J)- prinsol() plett(SL) print))
pl(S [L] LI) - prin(condi(() pchar(cL)
prin(() pcont(S Ll) prine))))
pl(S L Ll)- prin(c1ause() plert(cL)
prin(() pcont(S Ll) prine)))
plert(S[LJ) - pchar(SL)
plert(SjLILsj) - pcbar(SL) print v) pleCt(SLs)
pcont(S[L]) - pchar(SL)
pcont(S[LILsj) - pcbar(SL) prinr ) pcont(SLs)
pcbar(SP) shy
atomic(P)
name(PL)
( L = [IT] L = [5 k miT] L = [5 k niT] )
concat[XITj NewP)
prin(0JewP)
pchar(SP) shy
atomic(P)
prin(P) pchar(SA lt=gt B) -
prin(() dausify(A AI []) pl(eAI) prin())
prinr lt=gt ) prin(() dausify(B BI ]) pl(eB) print))
pchar(Snumber(X N)) shy
prin(num() pchar(SX) prin()
pchar(SN) prinr))
pcbar(SM N) - prin(M N)
pcbar(cF(A B)) shy
selec(F(A Braquo
pcbar(cA)
prine F ) pchar(cB) pchar(SF(A B)) shy
selec(F(A B))
prin(sel() pchar(SA)
print F ) pchar(SB) print)) I
31
pc har(SF(A)) shy
( F= prefix gt= F= prefix lt= F= prefixgt F= prefix lt )
prin(F ) pchar(SA)
pchar(SP)shy
runctor(P F MaxN)
prin(F ()
011 is MaxN - 1 pout(SNl P MaxN)
print) )
pout(S 0 P M3xN) - 1
arg(~bxN P Argu)
pchlr(SArgu )
pout(S N P MaxN shy
Nl is MaxN - N
arg(Nl P Argu)
pchar(SArgu
prin( )
N2 is N - 1
pout(S N2 P ~13xN)
Comparing numbers in numerical quantifiers
num(XN) shy
number(X I)
cnum(N 1) ~
cnumlaquo=01 lt=I- N gt=I
cnumlaquo=J lt I) - N gt=1-1
cnumlaquo=NIJ) - N gt=J 1
cnumlaquo=N J)- integer(I) N gt=I~
cnum(gt=N gt=1) - N lt=1
cnum(gt=N gt I) - N lt=1+ 1 cnum(gt=NIJ) - N lt=1
cnum(gt=N lt=1)- N lt=1
cnum(gt=N lt I) - N lt=1 L cnum(gt=N 1)- integer(I) N lt=1
cnum( lt N lt 1)- N gt=1 L
38
cnum( lt N lt=1) - N gt I cnum( lt NLJ) - N gt J
cnum( lt N 1)- integer(I) N gt 1
cnum(gt N gt I) - N lt=1 cnumlgt i gt=1) - N lt I
cnum(gt N lt=1) - N lt=0
cnum(gt N lt I) - N lt=0
cnum(gt iIJ) - N lt I cnum(gt N 1)- integer(I) N lt I
cnum(~LN lt=1) - M=I N gt= I l
cnum(~LN lt I) - M=l N gt= I-I
cnum(~LNLJ) - M lt =1 N gt = J
cnum(~1N 1)- integer(I) M lt= I N gt= I
cnum(- N) - integer(N)
Comparing selectors
sel(X = Y) shyX= Y
sel(X I=Y) shy(X I=Y X lt Y Xgt Y)
sel(X gt Y) shyXgt Y
sel(X lt Y) shyXlt Y
selX gt=Y) shy(X gt=Y X= Y Xgt Y)
se(X lt=Y) shy
(X lt=Y
X= Y
X lt Y)
csel(infix = infix =)
39
csel(infix = infix = csel(infix = infix gt)
csel(infix = infix lt) csel(infix gt infix gt) cseJ(infix lt infix lt) csel(infix gt= infix gt=) csel(infix gt= infix gt csel(infix gt= infix =)
csellinfix lt= infix lt=) csel(infix lt= infix lt) csel(infix lt= infix =)
Finding solutions
sol(X v Y) -
(( notetra(X) eon(X) ( sol(Y) )
( c1ause(P v Q R) not(cketra(P v Q))
dis(P v Q X v Y R) ~ )
( A lt=gt B equival(A lt=gt B X v Y) ~ I) sol(X) - ~ notetra(X) eon(X)
so~(X) - notetra(X)
( con (X)
( clause(P v Q R) not(ekctra(P v Q)) dis(P v Q X R) I)
cketra(P v Q) -
eketra(P) eketra(Q) eketra(F(I J)) shy
selec(F(I J))
c1ause(contradiction(sel(F(IJ))) _I
eketra(number(W I)) -
clause(cootradietion(num(Wl)) - eketr(P) shy
clause(contradiction(P) - 1
notctra(P) shy
not( e lause( con tradiction(P) _))
40
Searching (or disjunctions
dis(P v Q X v Y R) - dis(P X v Y R)
dis(Q X v Y R) con(R)
dis(P v Q X R) -
dis(P X R) dis(Q X R) con(R
dis(P X v Y R) - clause(contradicton(Pl J 1
dis(F(I J) sel(G(I J)) v Y R) - csel(G Fl dis(number(WI) num(W N v Y R) - cnum(N I)
dis(P P v Y R) -
dis(P X v Y R) - dis(P Y R)
dis(F(I J) seJ(G(IJ)) R) - csel(G F)
dis(number(WI) num(WN) R) - cnum(N I) dis(P P R) - 1
dis(FJ J X R) shy
( ckctra(F(IJ) cbeckeq(seJ(F(IJ))) )
dis(number(W Il X R) - ( ckctra(number(WI)) cbeckeq(num(WI)) )
dis(P X R) shy( ckctra(P) cbeckeq(P) ) 1
cbeckeq(P) shy
(( A lt=gt so2(contradiction(P))
bagof(A A [jj) ) ( so2(contradiction(P)) lt=gt B
bagof(B B Uj) ))
ckeq(A) shy
( so2(A) lt=gt B B lt=gt so2(A) ) bagof(B B UJ)
con((P Q)) -
clause(P R) con(R) con(Q) con(true) -
con(contradiction(P)) - clause(contradiction(P) J
con(cause(X Y)) - cause(X Y)
con(sel(X)) - sel(X)
con(num(X Y)) - num(X Y) con(P)- (( dause(P R) (con(R) ckeq(R)))
colJectin(P) )
collectin(P) shy
bagof(S (c1ause(P S) S = true) [L LIJ )
mkcon(L Ll L)
bagor(l (L2 ) UJ) L
mkcon((A AI) (B B1) (sol(A v B) e D)) -
mkcon(A B1 e) mkcon(A1 (B Bl) D)
mkcon(A (B B1) (sol(A v B) e)) -
mkcon(A Bl e)
mkcon((A AI) B (sol(A v B) e)) middot1
mkcon(Al B e)
mkcon(A B sol(A vB))
Searching ror equivalences
equival(A lt=gt B X v Y) - 1 ( equival(A lt=gt B X) equival(A lt=gt B Y) )
equival(s02(A) lt=gt 502(B) A) - clause(B _I equival(s02(B) lt=gt 502(A) A) c1ause(B _I
Top level or inrerence mechanism
goo((s02(whatnum) P)) -
getatm(P Xl
bagor(number(X Y) ( P so2(number(X Y)) ) A )
count1(A 00 L R) nl
bagor(X P B )
count2(B L R Ll Rl) nJ print()
(( LI = 0 Rl = 0 print(THE ANSWER IS ) nl
(( Ll = Rl prin(-Jumber or ) prn(P) print(is Ll) )
( Rlgt20000 prin(Number or I prn(P) print(is LI or more) )
42
( prin(Number of ) pfn(P) print( is from Ll to Rl) )) )
( print(THE ANSWER IS NO I )) print()
goo(X) shy
(( bagof(X X L) L = [I nl print()
print(THE ANSWER IS YES) nl wout(L) print() )
( equiv(X L) nl print()
print(THE ANSWER IS YES) nl wout(L) print(-) )
( c1ause(inpt(A ==gt B) _I ( impli(A B Z) impli(B A Z) ) print(l~Hl)
printTHE ANSWER IS YES) nl print(Z) print(Hj~(fH~) ))
goo(X) print( Hg)
print(THE ANSWER IS NO ) print( lH~lH~gg9l9lmiddotmiddot~Q(gmiddot)
00 Semhing for implications in equiV3lent relations
impli( B Z) shyt-ell( z1) prin(templ() pchn(S A lt=gt B) print()) close ( zl) consult(zl) templ(Z)
unload zl Z
Searching for equivalence
equiv (X L)
(( X lt=gt Y
equ(Y YI)t bagof(Y Yl L) L = [j )
(Y lt=gt X equ(Y YI) bagof(Y Yl L) L = [J )
( X = F(New)
clause(~ew T) makeup(T Tl)
(( Tl lt=gt B
equ(B Bl) bagof(Bl Bl M) M = [j L=[Newl )
(A lt=gt TI
equ(A AI) bagof(Al AI M) M = 1] L=INewj )) ))
makeup((A B) (AI Bl)) -
makeup(A A1) makeup(B BI)
makeup(A so2(A))
equ((A B) (AI BI)) -
equ(A AI) equ(B Bl)
equ(sol(X v Y) sol(XI v Yl)) -
equ(X XI) equ(Y YI)
equ(so2(X) so2(XI)) -
equ(X XI)
equ(contradiction(X) clJuse(contradiction(X) X) ) -
equ(X X)
Counting numbers
getatm((A B) X) -
( getatm(A X) getatm(B X) )
getatm(so2(F(X)) X) -
getatm(so2(X) X) - atom(X)
countl([J L R L R) -
countl([number(X Y)IT] L R L2 R2) shy
(( Y = (gt=~) LI is L + N Rl is R + 20001 l )
( Y = (gt N) LI is L+ N+ 1 RI is R + 20002 )
(Y == laquo=~) LI is L + 1 Rl is R + N )
(Y = laquo N) LI is L + 1 RI is R+N-I)
(Y == IJ LI is L + I Rl is R + J ) ( Y == N L1 is L + N RI is R + N ))
count1(T LI R 1 L2 R2)
count2(fJ L R L R) - 1
count2([XITJ L R L2 R2) shy
name(X Xl)
(( Xl = sknj LI is L Rl is R )
44
( Xl = Iskmj L1 is L + 1 RI is R + ZOOO1) ( LI is L + I RI is R + I ))
count2(T LI RI L2 R2)
pfn((A B)) - pfn(A) prn(B)
pCn(so2(F(X))) - prin(F )
prn(so2(X)) - atom(X) prin(X ) prn (so2(X))
Printing result
wout([XlJ - prt(X) nl woutf[xIY]) - prt(X) nl nl wout(Y)
prt(e(A B)) -
prt(A) prinr 8 ) prt(ltE) prt(eA) - prt(A)
prt(c(A EJ) - prin() prt(A) prine ) prt(B) prin(T)
prt(c A) - prt(A) prt((A E)) - ~
prt(A) nl prt(E) prt(sol(X v Y)) - ~
prt(X) prinC v) prt(Y) prt(A lt=gt B) -
prt(e A) prinC lt=gt ) prt(e B) prt(sol(X)) - prt(X)
prt(so2(X)) - prt(X
prt(c1ause(X Y)) - prt(X)
prt(contradiction(X)) - prin(contradiction() prt(cX) prinr))middot prt(num(XY)) - prin(number(X Y)) prt(sel(X)) - prin(X) prt(X v Y) - prt(X) prin( v) prt(Y) prt(X) prin(X)
Handling conditional queries
condi((Y Xl) shy
assertcon(X) Y
45
retractcon(X)
condi((B A))
retractcon(A) fail
assertcon((A B)) 1
assertcon(A) assertcon(B)
assertcon(A) asserta(A)
retrac teon ((A B)) 1
retracteon(A) retractcon (B)
retraetcon(A) - retract(A)
BIBLIOGRAPHIC DATA SHEET
Report No UIUCDS-F-84-928
3 Recipients Accession No
4 T ide and Subt ltle
An Annotated Predicate Calculus Inference System (APCIS)
S Report Date
November 1984 6
7 Author(s)
Kah-Eng Pua 8 Performing Organization Rept
No
9 Performing Organization Name and Address
Department of Computer Science University of Illinois Urbana IL
10 ProjectTaskWork Unit No
11 Contract Grant No NSF DCR 84-06081 ONR N00014-82-K-0186
12 Sponsoring Organization Name and Address
National Science Foundation Washington DC
13 Type of Report amp Period Covered
14
15 Supplementary Notes
16 Abstracts
This paper describes a deductive inference system called APCIS (Annotated Predicate Calculus Inference System) APCIS is able to carry out inferences from expressions involving numerical quantifiers selectors disjunctions of non-negated terms negated terms disjunctions of negated terms equivalences and exceptions It is also able to count the numbers of occurrence of a given simple term or a conjunction of terms The design of contradiction and the treatment of the disjunction of non-negated terms allow APCIS to accept Horn clauses as well as non-Horn clauses and to carry out inferences from them This feature makes APCIS more general than Prolog
17 Key lords and Document Analysis 170 Descriptors
APC (Annotated Predicate Calculus) APCIS (Annotated Predicate Calculus Inference System) Horn Clause Numerical Quantifier Prolog Selector
17b IdentifiersOpen-Ended Terms
17c COSATI FieldGroup
18 Availability Statement 19 Security Class (This
Re~f~~IA~SIF IFf)
21 ~o of Pages
49 211 ecurity Class (This
PageUNCLASSIFIED
22 Price
FOA NTIS n (10middot70 usco-oc 40329-
11
sequence
G 1 Check if the query asks for the numbers of occurrence of certain term(s) It so then
pass It to eountl and eount2 else go to G2
G2 The query will be passed down to sol or s02 (or both) to check i( any assertion in the
database can satisfy the query It the answer is positive then the query succeeds else
go to G3
G3 The query will be passed to equlv to carry out further searching It the searching is a
success then the query will be closed with a success else go to G4
G4 It the query is in the form A ==gt B then it will be passed to Impli It Impll
succeeds then done else the query will be closed with a (ailure
42 sol
801 and 802 together with dis and eon form the most complicated part of the APCIS
iorerence mechanism In this and the next section we will look at sol and s02 dis and eon will
be discussed in Section 44 We will close Section 44 with an example that illustrates the
materials presented in Section 42 through Section 44
sol is at the second level of the inference mechanism It will deal with any disjunction of
non-negated terms For any disjunction passed to it it will go through one or more of the
following steps in sequence
S1 Check if any term In the disjunction can be satisfied by any term or clause in the
database without contradiction It so then done else go to S2
S2 Pass the disjunction together with another disjunction (and its tlil) picked up from
the database to dis It dis succeeds then done else go to S3
S3 Pass the disjunction down to equlval which will check if any term in the disjunction
matches either side of any equivalence relation in the database It such a match is
found then check if the other side of the equivalence C3n be satisfied It so then done
else the goal fails
43 s02
s02 is also at the second level of the inference mechanism It will take care of all the
simple terms in the transl1ted query The following is the sequence that s02 wiII follow in
searching
S1 Check if the term passed to it caD be s3tisfied by any term or clause in the d3tabase
without contradiction It so then done else go to S2
S2 Pass the term together with a disjunction of terms (and its tail) picked up from the
database to dis If dis succeeds then done else the goal fails
44 dis and con
dis has three arguments In the first two clauses of dIs the first argument P v Q is
found in the database using the builtmiddotin functiol clause and the third argument R is the tair of
the term or the clause P v Q If P v Q is not a clause but a term R will be instantiated to trUE
The second 3rgument comes from either lIol or 802 and thus takes the form of either X v Y (a
disjunction of terms) or T (3 simple term)
All the clauses of dis together with con will perform the searching as exemplified in the
following algorithm (we will keep the notationsin this section)
01 Check if every term in P v Q is in X v Y It so then go to 03 else go to D2
02 For any term (in P v Q) which is not in X v Y or does not match T perform the
following tests
a Check if the term (in P v Q) has already been negated in the datab3Se (ie check if
the contradiction of the term exists in the d3tabase) If so then repeat D2 for other
terms not found in X v Y or not matching T else go to b
13
b Check if the contradiction of the term matches either side of any equivalence
relation in the database If such a match is found then check if the other side of the
equivalence can be satisfied If so then repeat O~ for other terms not found in X v Y
or not matching T else the goal fails
It all the terms (in P v Q) which are not in X v Y or do not match T survive either one
of the above two tests then go to 03
03 This step is essentially done by eon whose goal is to satisfy the tail R of P v Q It
con succeeds then done else the search fails
To close this section we will give an example to illustrate what we have covered In
Section 42 through Section 44
Example Assume that we already haye the following expressions in the database
horse(skml) v dog(skmI)
contradiction(( dog(XI) ))shy
dog(XI)
query goo(( soZ horse(X)) ))
This query will be passed to 802 which will check it the term horse() can be satisfied iu Step S 1
of Section 43 It is a failure So we now go to Step S2 In this step we pick up the disjunction
horse(~kml) v dog(skml) (and its tail true) in the datab3Se and pass it together with the term
horse(X) to dis We are now in Step 01 of Section 44 In this step we find that dog(skml) does
not match horse(X) So we have to go to Step 02 In Step 023 We find that the term dog(skml)
has already been negated (the second expression in the database) So we go to next step 03 Since
the tail of the disjuDction horse(skml) v dog(skml) is the atom true con is satisfied and the
query succeeds
45 countl and count2
countl and count2 are responsible for the counting of tbe numbers of occurrence of a
given simple term or a conjunction of terms They are activated by input queries in the form
q( exists( X whatnum amp P) )
where whatnum is the l~bel for activating the counting of the numbers of occurrence of P which
can either be a term or a conjunction of terms
countl will count the number of term(s) which will satisfy P and associate(s) with
numerical quantification(s Two counters are set to update the lower and upper boundary or the
scope or the numfrical quantifications encountered
The contents of the two counters are then passed to count2 which is responsible for the
counting or the following three types of term First term(s) which will satisfy P and associate(s)
with existential quantification(s Second term(s) which will satisfy P and has(have) Prolog atom
as its(thfir) argument(s) Third term(s) that will satisfy P and itself(themselves) is(are) Prolog
atom(s )
46 equiv
equlv will be activated only after sol and B02 have failed The first two goals of equlv
are similar to that of Step S3 in Section 42 and Step D2b in Section 44 The third goal or equiv
makes possible the inference on either side of any equivalent relation For example if we type the
following three expressions to Prolog in assertion mode
l all( X hot(X) amp humidX) - winter(X)
2 all( X hot(X) amp bumid(X) ==gt unpresent(X))
3 - ( exists( X winter(X) ) )
and then ask APCIS in query mode
q( cxists( X unpresent(X) ) )
15
APCIS with the aid of equlv will be able to answer yes to this query
41 lmpll
lmpll can be considered as the last attempt that APCIS would make to satisfy a
query It is activated only after equlv has failed It will first check if the query is conditional If
so it will convert the implication symbol to equivalence symbol and search if such an equivalent
relation can be found in the database If so a success Otherwise a failure
5 More on the Inference Mechanism
Having looked at all the subparts at the top two levels of the inference mechanism we
are ready to look at other subparts at lower levels
51 num and cnum
One distinct fe3ture or APCIS is its ability to deal with numerical quantifications As
mentioned in Section 31 input queries and assertions will undergo different transformations in
the last step (Step 10) of translation This also holds true for expressions involving numerical
quantifications Consider the following expression
exists( 6 X horse(X) )
If it is entered to Prolog via assertion mode we will after going through all the steps of
translation have the rollowing entered to the database
horse(sk n I
number(sknl6)
Now if we want to ask Are there more than five horses 7 and type in
q( exists( gt5 X horse(X) ) )
1amp
APCIS will translate the question and enter to Prolog the following query
goo(( s02( horse(X) ) s02( num( X gt5 )) ))
Note that the term number(slml 6) in the database and the term num(X gt S) in the query are
different predicates and this difference is exactly where the power of the clause num(X N)
defined in APCIS comes from When the clause num(X N) in APCIS is activated it will search
through the database to see if there is any term of the form number(X I) whose first argument
matches the first argument of num(X Y) in the query It a match is found the second arguments
of both num(X Y) in the query and number(ltI) in the database will be passed to cnum in
APCIS
The job of cnum is to compare the numerical messages carried by the second
argument or the term rlum(X Y) in the query and the second argument of the term rlumber(X I)
in the database to see if they match with each other according to the rules defined in cnum
While there are 25 rules for such matching purposes the idea is simple
Imagine that the second argument Y of the term num(X Y) in the query
and the second argument I of the term num()( I) in the database each occupies a
place in an integer line (Le the integer line in mathematics) To have a match
the domain covered by Y should contain the domain covered by L
As an example the answer to the above query is positive since the domain of gt5
contains the domain or 6
Before closing this section we will bring out a speciaJ translation aspect of expressions
involving numbers by an example We first type to APCIS the Collowing expressions in assertion
mode
1 aU(X all(Y father(X Y) amp number(Y gt6) ==gt has_manY3hildren(X) ))
2 exists(X exists( 12 Y Cather(X Y) ) )
11
After going tbrougb all tbe translation steps tbe Collowing two expressions will be entered to tbe
database
I
bas_many_cbildren( Xl ) shy
Cather( Xl X2 )
num( X2 gt6 )
2
Catber( sk m1 sk n2 )
number( skn2 12 )
lotice that whenev(gtr a term with Cunctor number appears at the rigbt-band side oC a Prolog
clause its Cunctor will be cbanged to num automatically This treatment will greatly cnbance tbe
inference power of the clause sbown in l above For instance iC we now ask tbe question
q( exists( X bas_many_children(X) ) )
The right hand side oC the clause l will match the two terms in 2 and tbe query succeeds
52 Bel and cael
A special feature of APe is tbat all predicates tbat express relations = = gt
gt= lt and lt= can be expressed explicitly using infix notations as relational statements
called selectors To handle selectors we defined Bel in APCIS
Every expression involving selectors will undergo different translations in assertion mode
and query mode For example the assertion
a( exists( [X Y] box (X) amp box(Y) amp (weigh t(X) gt weight(Y) ) ) )
will be translated into the following three terms and entered to tbe database
box( skml )
box( skm2 )
18
weight( skm 1 ) gt weight( skm2 )
Now it we want to ask Is it true that there exists two boxes of different weights and type in
q( exists( [X Yl box(X) amp box(Y) amp ( weight(X) = weight(Y) ) ) )
The question will be transformed to the following query and entered to Prolog
goo(( so( box(XI) ) s02( box(X2) ) so2( sel( weightXI) = weight(X2) )) ))
Note that the selector in the above query is surrounded by the functor set When any clause or
8el in APCIS is activated it will search through the database to see it there is any selector whose
two arguments (left and right side or any selector symbol) match the two arguments of the
selector in the query At the same time 8el will check iC the selector symbols (may be different) or
the two different selectors (one in the query and one in the database) satisfy the rules defined in
sel There are 12 matching rules defined in sel All oC them ~re straightforward and will not be
discussed here An example will be enough to explain how 8el works
Consider the execution of the above transformed query The first two terms in the query
are satisfied by the first two terms in the database and Xl and X2 are instantiated to skml and
skm2 respectively The third term of the query will be passed to eel (of APCIS) which finds a
match on each side of the two selectors (one in the query and one in the database) At the same
time the two different selector symbols gt and = are found to satisfy one of the rules in
8el As a result the query succeeds
To enhance the inference power of clauses involving selectors all the selectors appearing
on the rightmiddothand side oC any clause will be surrounded by a functor set The idea is similar to
that in the last part of the previous section
c8el is exactly the same as 8el functionally It provides a convenient way to compare
selectors when dis is being executed
19
8 Printing Result
Whenever a goal is successfully executed APCIS will not only response with a yes but
also print out the matched terms or clauses in the database This is made possible by the built-in
function bagor and the two predicates wout and prt defined in APCIS
7 Summary
In this paper a description of a deductive inference system called APCIS (Annotated
Predicate Calculus Inference System) has been provided APCIS is able to carry out inferences
from expressions involving numerical quantifiers selectors disjunctions of non-negated terms
negated terms disjunctions of negated terms equivalences and exceptions It is also able to count
the numbers of occurrence of a given simple term or a conjunction of terms
The main idea of APCIS is that each input APC expression is first passed to a
preprocessor ( ie APC translator ) which dissolves and transforms each APC expression into
Prolog expression(s) which will then be loaded to Prolog system The user bas to specify whether
each input expression is to be entered as an assertion or as a query by invoking either assertion
mode or query mode respectively Each assertion or query will undergo different transformations in
the preprocessor The different treatment of assertion or query not only allows a full uS1ge of the
Prolog inference mechanism but also makes possible a higher level of inexact pattern matching
exemplified by the examples in Section 51 and Section 52 where the four predicates num
cnum sel and csel are discussed This higher level of pattern matching increases the inference
power of APCIS greatly
The design of contradiction and the treatment of the disjunction of non-negated terms
allow APCIS to accept non-Horn clauses and to carry out inference from them This feature
makes APCIS more general than Prolog
20
While APCIS performs very well in many sets of arguments provided by the author it is
still too early to jump to conclusion that it can perform equally well in all types of problems In
any event the expressiveness of APC has greatly been retained in the present version of APCIS
and moreover some design ideas or APCIS mentioned in this paper are not restricted to APCIS
- they may be carried over to learning programs with narrower scopes
21
References
[1] W F Clocksin and C S Mellish Programming In Prolog Springermiddot Verlag Berlin Hpoundidelberg 1981
[2] R S Michalski A Theory and Methodology of Inductive Learning Chpt 4 Machine L earning Tioga Publishing Co Palo Alto CaliJornia 1989
[3] K-E Pua Translating Annotated Predicate Calculu8 to Prolog ISG Report 84middot1 UlUCDCSmiddotFmiddot918 University oj Illinois Urbana IL June 1984
22
Appendix A
APCIS Users Manual
1 Get Started
Users are urged to follow the steps depicted below
1 Get the PROLOG interpreter by typing
alias prolog mntb2sammutsammutprologprolog (Vax A)
or
alias prolog mntb2sammutsammutbinprolog (Vax B)
2 Load apc and infer by typing
prolog apc infer
When large APC expressions are expected we can increase the stlck by typingI
prolog -snnnn ape infer
where ns denote the number of stacks in decimal
3 When the wording LSW - PROLOG appears on the terminal we are reldy to interact
with APCIS The four modes by which we can invoke APCIS are summarized below
a Assert ion-Translation Mode
ta(X)
b Query-Translation Mode
tq(X)
c Assertion Mode
a(X
d Query Mode
q(X)
23
where Xs are APC expressions
2 Notations Used in APCIS
Below is a summary or notations used in APCIS
a Logical operators
amp
v
==gt
lt=gt
-
negation
conjunction
disjunction
implication
equivalence
exception
b Binary relation symbols in selectors
-
=
gt=
lt=
gt
lt
equal
not equal
greater or equal
smaller or equ al
greater
smaller
c Relational operators in numerical quantifiers
lt less than
lt= less than or equal
gt greater than
gt= greater than or equal
d BinlTY operator in numerical quantifier
range
e Universal quantifier
all(X p(X))
f Existential quantifier
exists(X p(X))
g Numerical quantifier
exists(I X p(X))
where p(X) is a formula
where X is a variable or a Jist of variables or the
form [HI~rj and p(X) a formula
where I repersents expression involving integer(s)
and operator(s) in c or d above and p(X) a formula
25
Appendix B
APCIS Program Listings
------------------------------- Program Name APCIS - Part 1 APC Translator
-------------------------------
op(3OO fx -)1
op(500 xfy amp)
oPt 500 xfy v)
op(600 xfx )
op(700 fx [gt= lt= gt lt ]) op(400 xfy [= gt= lt= gt lt ])1 op(900 xfy gt lt=gt -])1
steps(X Xg) shy
numbervars(X 1 J Step 1 change variables to iis
rmimp(X X) Step 2 conv(X X3) Step 3
rewrite(X3 X4) Step 4
negin(X4 X5) Step 5
dropexist(X5 X6 1]) Step 6
dropall(X6 X7) Step 7
distrib(X7 X8) Step 8 clausiCy(X8 X9 [J) Step 9
ta(X) shysteps(X Xg)
(( Xg = II nl
print( yes it is always true) )
( nl nl printcl(X9))) Step 10a
tq(X) shy
steps(X Xg)
prques(Xg)
28
Step 2 Removing implic3tions amp Transforming exceptions and equiv3lences
rmimpl( P - Q (PI lt=gt (QI) ) amp ((PI) lt=gt QI) ) -
rmimpl(P PI) rmimpl(Q QI)
rmimplnp) lt=gt Q (PI lt=gt -(QI)) amp nPI) lt=gt QI) ) - 1
rmimpl(P PI) rmimpJ(Q QI)
rmimpJ(P lt-gt -(Q) (PI lt=gt -(QI)) amp nPI) lt=gt QI) ) -
rmimpl(P PI) rmimpl(Q QI)
rmimpl( P lt=gt Q PI lt=gt QI ) - I
rmimpl(P PI) rmimpl(Q QI)
rmimpl( P ==gt Q -(PI) v QI ) - I
rmimpl(P PI) rmimpl(Q QI)
rmimpl( all(X P) aI(X PI) ) - 1
rmimpl(P PI)
rmimpl( exists(X P) exists(X PI) ) -
rmimpl(P PI)
rmimpl( exists(I X P) exists(I X PI) ) -
rmimpl(P PI)
rmimpl( P amp Q PI amp Ql ) -
rmimpl(P PI) rmimpl(Q Ql)
rmimpl( P v Q PI v QI ) -
rmimpl(P PI) rmimpl(Q QI)
rmimpl( -(p) -(PI) ) - I
rmimpl(p PI)
rmimpl( P P )
St~p 3 Converting numerical amp distinctive quantifiers
L Numerical quantifiers
examples of input forms
1 exists(gt= i X pIX)) where i is an integer
2 exists(i X pIX)) where i is an integer
3 exists(i j X pIX)) where i j are integers and iltj
4 exists(il v i2 X pIX)) where is are integers
examples of output forms of this step
1 exists(X pIX) amp number(X gt= i) )
2 exists(X pIX) amp number(X i) ) 3 exists(X pIX) amp number(X ij) ) 4 exists(X pIX) amp number(X il v i2) )
II Distinctive quantifiers
27
example or input Corm
exists([XYL p(X Y))
example or output Corm or this step
exists(X exists(Y p(XY)) )
conv(P lt=gt Q PI lt=gt QI) - 1
conv(P PI) conv(Q QI)
conv(al1(X P) all(X PI)) -
conv(P PI)
conv(exists(HIT] P) R ) - conv(P PI) convert distinctive quantifier
convtdis(exists([HIT]PI) R)
conv( exists(I X P) exists(X PIamp number(X I) )) -
conv(P PI) convert numerical quantifier
conv(exists(X P) exists(X PI)) - 1
conv(P Pl)
conv(P amp Q PI amp QI) - 1
conv(P PI) conv(Q QI)
conv(P v Q PI v QI) - t conv(P PI) conv(Q QI)
convC(P) -(PI)) -
conv(P PI)
conv(P Pl
convtdis(existsl[XL P) exists(X P)) - atomic(X) convtdis(exists[XIYj Pl exists(X R)) shy
convtdis(exists(Y P) R)
Step 4 Rewriting compound predicates andor compound selectors
Outputs are smiple predicates andor simple selectors
rewrite(P lt=gt Q PI lt=gt QI) - t rewrite(P PI) rewrite(Q QI)
rewrite(all(X Pl all(X PI)) - 1 rewrite(P PI)
rewriteexists(X P) exists(X PI)) - I rewriteP PI)
rewrite(P amp Q PI amp QI) - rewrite(P P 1) rewrite( Q Q 1
rewrite(P v Q PI v QI) - 1
rewrite(P PI) rewrite(Q QI)
rewriteC(P) -(PI)) - I
28
rewrite(P PI) rewrite(F(A B) R) -
rewrite(A AI) rewrite(B BI) re(F(AI BI) R)
rewrite(F(A) R) -
rewrite(A AI) re(F(AI) H)
rewrite(F(A B C) R) -
rewrite(A AI) rewrite(B BI) rewrite(C CI) re(F(AI BI CI) R)
rewrite(F(A B C D) R) -
rewrite(A AI) rewrite(B Btl rewrite(C CI) rewrite(D DI) rc(F(AI BI CI Dl) H)
rewrite(PP)
re(F(A B v el (RI v R2) -
re(F(A Bl RIl re(F(A C) R2) reF(A B amp cl (RI amp R2)) -
re(F(A B) RI) re(F(A e) R2) re(F(A amp B C) (Rl amp R2)) -
re(F(A e) R 1) re(F(B C) R 2) re(F( v B el (R I v R2)) -
re(F(A el R I) reFB el R2) re(F(A amp Bl (R I amp R2)) -
re(F(A RI) re(F(BJH2) re(F(A v B) (R 1 v R2)) -
re(F(A) RI) re(F(B) R2)
re(F(A vB c Dl (RI v R2) -
re(F(A C D) RI) re(F(B C D) R2) re(F(A amp B C D) (RI amp R2)) -
re(F(A C D) Rll re(F(B C D) R2) re(F(A B v C D) (HI v R2)) -
re(F(A B D) RI) re(F(A C D) R2) re(F(A B amp C D) (HI amp R2)) -
re(F(A B D) RI) re(F(A C D) R2) re(F(A B C v D) (RI v R2)) -
re(F(A B C) R I) reF(A B D) R2) re(F(A B C amp D) (RI amp R2)) -
29
re(F(A B C) RI) re(F(A B D) RZ)
re(F(A v B e D E) (R I v R2)) -
re(F(A e D E) R I) re(F(B e D El R2) re(F(A amp B e D E) (RI amp RZ)) -
re(F(A e D El R 1) re(F(B e D E) R2) re(F(A B v e D E) (R I v R2)) -
re(F(A B D E) RI) re(F(A e D E) R2)
re(F(A B amp e D E) (RI amp R2)) -
re(F(A B D El RI) re(F(A e D E) RZ) re(F(A B e v D E) (R I v R2)) -
re(F(A B e El R 1) re(F(A B D E) RZ) re(F(A B e amp D E) (RI amp RZ)) -
re(F(A B e E) R I) re(F(A B D E) RZ)
re(F(A B e D vEl (RI v RZ)) - l
rc(F(A B C D) RI) re(F(A n e El RZ) re(F(A B e D amp El (RI amp RZ)) - ~
re(F(A B e D) RI) re(F(A B e El RZ)
re((A = B) (A = B)l-
re((A = Bl (A = 8)) -
retIA gt= BI (A gt= B)) -
re((A lt= B) (A lt= B)) -
re((A gt B) (A gt B))-
re((A lt Bl (A lt Bl)- re(A A)
Step) Bringing n(gation inwards
Degin(-(P) PI) - neg(P Pl)
negin(P lt=gt Q PI lt=gt Ql) - ~
negin(P PI) negiD(Q QI)
Degin(aU(X P) all(X PI)) - Degin(P PI) negin(exists(X P) exists(X PI))- negin(P PI) negin(P amp Q PI amp Ql) - Degin(P PI) negin(Q Ql)
Degin(P v Q PI v QI) - Degin(P PI) negin(Q QI) negin(P Pl
neg(-(P) PI) - negin(P PI)
neg(all(X P) exists(X PI)) - neg(P PI)
30
neg(exists(X P) all(X PI)) - neg(P PI)
neg(P amp Q PI v QI) - neg(P PI) neg(Q Ql)
neg(P v Q PI amp QI) - neg(P PI) neg(Q QI)
neg(P -(PH
Step 6 Dropping existnetial quanti6ers
dropexist(P lt=gt Q PI lt=gt QI Elerns) - dropexist(P PI Elerns) dropexist(Q QI Elerns)
dropexist(alJ(X P) all(XPI) Elerns)
dropexist(P PI [XIElernsJ)
dropexist(exists(X P amp nurnber(X Yraquo P2 Elerns) -
genfun(skn Newg) Fun = [NewgIElerns]
subst(FuD X P amp Dumber(X Y) PI)
dropexist(Pl P2 Elerns)
dropexist(exists(X P) PZ Elerns) -
genfun(skrn Newf) Fun = [NewfIElernsJ
subst(Fun X p PI)
dropex ist(P 1 P~ Elerns)
dropexist(P v Q PI v QI Elerns) - ~
dropexist(P PI Elerns) dropexist(Q Ql Elerns)
dropexist(P amp Q PI amp QI Elerns) - 1
dropexist(P Pl Elerns) dropexist(Q QI Elerns)
dropexist(P P _)
gen fun(R oot Newn arne) shy
getnurn(Root Nurn)
narne(Root Rootlist)
append(Rootlist[Nurnj Narnelist)
concat(Narnelist Newnarne)
getnurn(Root Nurn) shy
retract(currentnurn(Root Nurn 1 raquo
Nurn is Nurni + 1
asserta(currentnurn(Root Nurn))
getnurn(Root 1) - asserta(currentnurn(Root 1))
subst(New Old Val Val) - var(Val)
subst(New Old Old New) - 1 substNew Old Val Val) - atornic(Val)
31
subst(New Old Val Newval) shy
runctor(Val F N)
CUDctor(Newval F N)
subst_args(N New Old Val Newval)
subst_args(O J J - J J
subst_args(N New Old Val NewVal) shy
arg(N Val OldArg)
arg(N NewVal NewArg)
subst(New Old OldArg NewArg)
NI is N - I
subst_args(Nl New Old Val NewVal)
append([J L L) -
append([XILl] L2 [XIL3]) - append(Ll L2 L3)
Step - Dropping universal quantifiers
dropall(P lt=gt Q PI lt=gt QI)-
dropall(P PI) dropall(Q QI)
dropall(all(X P) PI) - ~ dropall(P PI)
dropall(P amp Q PI amp QI) -
dropall(P PI) dropall(Q QI)
dropall(P v Q PI v QI) -
dropall(P PI) dropall(Q QI)
dropall(P P)
Step 8 Distributing conjunctions over disjunctions
distrib(P lt=gt Q PI lt=gt Ql) - t distrib(P PI) distrib(Q QI)
distrib(P v Q R) -
distrib(P PI) distrib(Q QI)
distributing(PI v QI R)
distrib(P it Q PI it QI) -
distrib(P PI) distrib( Q QI)
distrib(P P)
distributing((P amp Q) v R PI amp QI) -
distrib(P v R PI) distrib(Q v R Ql)
32
distributing(P v (Q amp R) PI amp Ql) -
distrib(P v Q PI) distrib(P v R Ql)
distributing(P P)
Step 9 Packing each conjunction into clauses
c1ausify(P amp Q CI C2) -
clausiCy(P CI C3) c1ausify(Q C3 C2)
cbusiCy(P [d(A B)ICs] Cs) shy
inclause(P A [j B [I) 1
c1ausiry( C C)
inclause(P v Q A AI B B1) -
inc1ause(P A2 AI B2 Bl)
inclause(Q A A2 B B2)
inclausenp) A A B1 B) -
notin(P A) putin(P B B1)
inclause(P AI A B B) shy
notin(P Bl putin(P A AI)
notin(X [XU) - fail
notin(X [JLj) - notin(X L)
notin(X 1])
putin(X II [X]) - 1
putin(X [XILJ L) -
putin(X [YILJ [YILl]) - putin(X L Ll)
Step 1Oa Printing clauses
printcl([]) - nl nl
printcl(c1(AB)ICsj) - printcl(A Bl nl printcl(Cs)
printcl(L II) - printdis(IL) prinr)middot
printclHl L) - prin(contradiction(() printconl(rL)
print()) - ) printconj(rL) prinr )
printcl(Ll L2) shy
printdis(ILl) print( - ) printconj(rL2) prin()
printdis(S[Lj) - printcbar(SL)
33
printdis(S[LILs]) - printchu(SL) prin( v) printdis(SLs)
printconl(S[LI) - printchar(SL)
printconl(S[LILs]) - printchar(SL) prin( ) printconl(SLs)
printconj(S[L]) - tab(3) printchar(SL)
prin tconj( S [L IL sl) shy
tab(3) printchar(SL) print( ) printconj(SLs)
printchar(SP) shy
atomic(P)
name(P L)
L = [IT]
concat([XIT NewP)
prin(~ewP)
printchar(SP) shy
atomic(P)
prin(P)
printchar(SA lt= gt B) -
prin((l clausify(A AI [j) pl(eAl) prin())
print lt=gt )
prin(() cbusify(B Bl [I) pJ(eBl) prine))middot
printchar(rnumber(X N)) shy
prin(num() printchar(rx) prin( )
printchar(rN) prinC))
printchar(rF(A B)) shy
seJec(F(A B))
prinCsel() printchar(rA)
prin( F ) printchar(rB) prinC))
printchar(SF(A B)) shy
( selec(F(A B)) F = infix )
printchar(SA) prin( F ) printchar(SB)
printchar(SF(A)) shy
(F= prefix gt= F= prefix lt= F= prefixgt F= prefix lt )
prin(F ) printcbar(SA)
printchar(SP) shy
functor(P F MaxN)
prin(F ()
Nl is MaxN - 1
putout(S N 1 P MaxN)
34
prin())
putout(S 0 P MaxN) -
arg(~laxN P Argu)
prin tchar(SArgu)
putout(S N p MaxN) shy
Nt is MaxN - N arg(NI P Argu)
printcbar(SArgu )
prin( )
N2 is N - 1
putout(S N2 P MaxN)
selec(FA B)) shy
( F= infix = F= infix f= F= infix gt=
F= infix gt F= infix lt= F= infix lt )
35
----------------------------------Program Name APClS - Part 2 Inference Mechanism ---------------------------------- a(X) shy
steps(X X9)
(( X9 =[] nl
print( yes it is always true) )
( X9 =[cI(IJ[])] nl
print( no it is always false) )
( nl nl printel(X9) Step 1Oa
tell(temp_file) printel(X9) e1ose(temp_file) consult(temp_6Ie) ))
q(X) shy
asserta( in pt(X))
steps(X X9)
(( X9 = [] print(middot~H~~middot~t~)
print(THE AiSWER IS YES)
print( ilgIQlQl(~) )
( X9 = [e1([j [j)] Pr1nt ( OJ fi(i I~ iii Ij)middot(i)(i) fiyenQ)riiio(i)(ij)(i)fj)fiyen1li1il1li1il)__ gtw~ __~_~ _~~_ ~_-=~
print(THE ANSWER IS NO ) print() )
( teI1(temp_6Ie)
prques(X9) Step 1Ob
close(temp_file)
nl print(Let me think about it) nl
consult(temp_6Ie) ))
retrac t( in pt(X))
Step lOb Printing question
prques(lcl(A 8)1) - prin(goo(() pl(qA 8) print()))
prques([c1(A 8HCs]) - prin(goo(() pl(qA 8) print() pl(q Cs)
pl(e [c1(A 8)]) - pl(eA 8)
pl(q [c1(A 8)]) - pl(qA 8) print()))
pl(S [e1(A B)ICs]) - pl(SA B) prin( ) pl(S Cs)
38
pl(q [j L) - prin(c1ause(contradiction(() pcont(qL) prin())_))
pl(S [I L)- prin(so2(contradidion(() pcont(SL) print))))middot
pl(S [L] []) - prin(so2() pcbar(SL) prin())
pl(S L [J)- prinsol() plett(SL) print))
pl(S [L] LI) - prin(condi(() pchar(cL)
prin(() pcont(S Ll) prine))))
pl(S L Ll)- prin(c1ause() plert(cL)
prin(() pcont(S Ll) prine)))
plert(S[LJ) - pchar(SL)
plert(SjLILsj) - pcbar(SL) print v) pleCt(SLs)
pcont(S[L]) - pchar(SL)
pcont(S[LILsj) - pcbar(SL) prinr ) pcont(SLs)
pcbar(SP) shy
atomic(P)
name(PL)
( L = [IT] L = [5 k miT] L = [5 k niT] )
concat[XITj NewP)
prin(0JewP)
pchar(SP) shy
atomic(P)
prin(P) pchar(SA lt=gt B) -
prin(() dausify(A AI []) pl(eAI) prin())
prinr lt=gt ) prin(() dausify(B BI ]) pl(eB) print))
pchar(Snumber(X N)) shy
prin(num() pchar(SX) prin()
pchar(SN) prinr))
pcbar(SM N) - prin(M N)
pcbar(cF(A B)) shy
selec(F(A Braquo
pcbar(cA)
prine F ) pchar(cB) pchar(SF(A B)) shy
selec(F(A B))
prin(sel() pchar(SA)
print F ) pchar(SB) print)) I
31
pc har(SF(A)) shy
( F= prefix gt= F= prefix lt= F= prefixgt F= prefix lt )
prin(F ) pchar(SA)
pchar(SP)shy
runctor(P F MaxN)
prin(F ()
011 is MaxN - 1 pout(SNl P MaxN)
print) )
pout(S 0 P M3xN) - 1
arg(~bxN P Argu)
pchlr(SArgu )
pout(S N P MaxN shy
Nl is MaxN - N
arg(Nl P Argu)
pchar(SArgu
prin( )
N2 is N - 1
pout(S N2 P ~13xN)
Comparing numbers in numerical quantifiers
num(XN) shy
number(X I)
cnum(N 1) ~
cnumlaquo=01 lt=I- N gt=I
cnumlaquo=J lt I) - N gt=1-1
cnumlaquo=NIJ) - N gt=J 1
cnumlaquo=N J)- integer(I) N gt=I~
cnum(gt=N gt=1) - N lt=1
cnum(gt=N gt I) - N lt=1+ 1 cnum(gt=NIJ) - N lt=1
cnum(gt=N lt=1)- N lt=1
cnum(gt=N lt I) - N lt=1 L cnum(gt=N 1)- integer(I) N lt=1
cnum( lt N lt 1)- N gt=1 L
38
cnum( lt N lt=1) - N gt I cnum( lt NLJ) - N gt J
cnum( lt N 1)- integer(I) N gt 1
cnum(gt N gt I) - N lt=1 cnumlgt i gt=1) - N lt I
cnum(gt N lt=1) - N lt=0
cnum(gt N lt I) - N lt=0
cnum(gt iIJ) - N lt I cnum(gt N 1)- integer(I) N lt I
cnum(~LN lt=1) - M=I N gt= I l
cnum(~LN lt I) - M=l N gt= I-I
cnum(~LNLJ) - M lt =1 N gt = J
cnum(~1N 1)- integer(I) M lt= I N gt= I
cnum(- N) - integer(N)
Comparing selectors
sel(X = Y) shyX= Y
sel(X I=Y) shy(X I=Y X lt Y Xgt Y)
sel(X gt Y) shyXgt Y
sel(X lt Y) shyXlt Y
selX gt=Y) shy(X gt=Y X= Y Xgt Y)
se(X lt=Y) shy
(X lt=Y
X= Y
X lt Y)
csel(infix = infix =)
39
csel(infix = infix = csel(infix = infix gt)
csel(infix = infix lt) csel(infix gt infix gt) cseJ(infix lt infix lt) csel(infix gt= infix gt=) csel(infix gt= infix gt csel(infix gt= infix =)
csellinfix lt= infix lt=) csel(infix lt= infix lt) csel(infix lt= infix =)
Finding solutions
sol(X v Y) -
(( notetra(X) eon(X) ( sol(Y) )
( c1ause(P v Q R) not(cketra(P v Q))
dis(P v Q X v Y R) ~ )
( A lt=gt B equival(A lt=gt B X v Y) ~ I) sol(X) - ~ notetra(X) eon(X)
so~(X) - notetra(X)
( con (X)
( clause(P v Q R) not(ekctra(P v Q)) dis(P v Q X R) I)
cketra(P v Q) -
eketra(P) eketra(Q) eketra(F(I J)) shy
selec(F(I J))
c1ause(contradiction(sel(F(IJ))) _I
eketra(number(W I)) -
clause(cootradietion(num(Wl)) - eketr(P) shy
clause(contradiction(P) - 1
notctra(P) shy
not( e lause( con tradiction(P) _))
40
Searching (or disjunctions
dis(P v Q X v Y R) - dis(P X v Y R)
dis(Q X v Y R) con(R)
dis(P v Q X R) -
dis(P X R) dis(Q X R) con(R
dis(P X v Y R) - clause(contradicton(Pl J 1
dis(F(I J) sel(G(I J)) v Y R) - csel(G Fl dis(number(WI) num(W N v Y R) - cnum(N I)
dis(P P v Y R) -
dis(P X v Y R) - dis(P Y R)
dis(F(I J) seJ(G(IJ)) R) - csel(G F)
dis(number(WI) num(WN) R) - cnum(N I) dis(P P R) - 1
dis(FJ J X R) shy
( ckctra(F(IJ) cbeckeq(seJ(F(IJ))) )
dis(number(W Il X R) - ( ckctra(number(WI)) cbeckeq(num(WI)) )
dis(P X R) shy( ckctra(P) cbeckeq(P) ) 1
cbeckeq(P) shy
(( A lt=gt so2(contradiction(P))
bagof(A A [jj) ) ( so2(contradiction(P)) lt=gt B
bagof(B B Uj) ))
ckeq(A) shy
( so2(A) lt=gt B B lt=gt so2(A) ) bagof(B B UJ)
con((P Q)) -
clause(P R) con(R) con(Q) con(true) -
con(contradiction(P)) - clause(contradiction(P) J
con(cause(X Y)) - cause(X Y)
con(sel(X)) - sel(X)
con(num(X Y)) - num(X Y) con(P)- (( dause(P R) (con(R) ckeq(R)))
colJectin(P) )
collectin(P) shy
bagof(S (c1ause(P S) S = true) [L LIJ )
mkcon(L Ll L)
bagor(l (L2 ) UJ) L
mkcon((A AI) (B B1) (sol(A v B) e D)) -
mkcon(A B1 e) mkcon(A1 (B Bl) D)
mkcon(A (B B1) (sol(A v B) e)) -
mkcon(A Bl e)
mkcon((A AI) B (sol(A v B) e)) middot1
mkcon(Al B e)
mkcon(A B sol(A vB))
Searching ror equivalences
equival(A lt=gt B X v Y) - 1 ( equival(A lt=gt B X) equival(A lt=gt B Y) )
equival(s02(A) lt=gt 502(B) A) - clause(B _I equival(s02(B) lt=gt 502(A) A) c1ause(B _I
Top level or inrerence mechanism
goo((s02(whatnum) P)) -
getatm(P Xl
bagor(number(X Y) ( P so2(number(X Y)) ) A )
count1(A 00 L R) nl
bagor(X P B )
count2(B L R Ll Rl) nJ print()
(( LI = 0 Rl = 0 print(THE ANSWER IS ) nl
(( Ll = Rl prin(-Jumber or ) prn(P) print(is Ll) )
( Rlgt20000 prin(Number or I prn(P) print(is LI or more) )
42
( prin(Number of ) pfn(P) print( is from Ll to Rl) )) )
( print(THE ANSWER IS NO I )) print()
goo(X) shy
(( bagof(X X L) L = [I nl print()
print(THE ANSWER IS YES) nl wout(L) print() )
( equiv(X L) nl print()
print(THE ANSWER IS YES) nl wout(L) print(-) )
( c1ause(inpt(A ==gt B) _I ( impli(A B Z) impli(B A Z) ) print(l~Hl)
printTHE ANSWER IS YES) nl print(Z) print(Hj~(fH~) ))
goo(X) print( Hg)
print(THE ANSWER IS NO ) print( lH~lH~gg9l9lmiddotmiddot~Q(gmiddot)
00 Semhing for implications in equiV3lent relations
impli( B Z) shyt-ell( z1) prin(templ() pchn(S A lt=gt B) print()) close ( zl) consult(zl) templ(Z)
unload zl Z
Searching for equivalence
equiv (X L)
(( X lt=gt Y
equ(Y YI)t bagof(Y Yl L) L = [j )
(Y lt=gt X equ(Y YI) bagof(Y Yl L) L = [J )
( X = F(New)
clause(~ew T) makeup(T Tl)
(( Tl lt=gt B
equ(B Bl) bagof(Bl Bl M) M = [j L=[Newl )
(A lt=gt TI
equ(A AI) bagof(Al AI M) M = 1] L=INewj )) ))
makeup((A B) (AI Bl)) -
makeup(A A1) makeup(B BI)
makeup(A so2(A))
equ((A B) (AI BI)) -
equ(A AI) equ(B Bl)
equ(sol(X v Y) sol(XI v Yl)) -
equ(X XI) equ(Y YI)
equ(so2(X) so2(XI)) -
equ(X XI)
equ(contradiction(X) clJuse(contradiction(X) X) ) -
equ(X X)
Counting numbers
getatm((A B) X) -
( getatm(A X) getatm(B X) )
getatm(so2(F(X)) X) -
getatm(so2(X) X) - atom(X)
countl([J L R L R) -
countl([number(X Y)IT] L R L2 R2) shy
(( Y = (gt=~) LI is L + N Rl is R + 20001 l )
( Y = (gt N) LI is L+ N+ 1 RI is R + 20002 )
(Y == laquo=~) LI is L + 1 Rl is R + N )
(Y = laquo N) LI is L + 1 RI is R+N-I)
(Y == IJ LI is L + I Rl is R + J ) ( Y == N L1 is L + N RI is R + N ))
count1(T LI R 1 L2 R2)
count2(fJ L R L R) - 1
count2([XITJ L R L2 R2) shy
name(X Xl)
(( Xl = sknj LI is L Rl is R )
44
( Xl = Iskmj L1 is L + 1 RI is R + ZOOO1) ( LI is L + I RI is R + I ))
count2(T LI RI L2 R2)
pfn((A B)) - pfn(A) prn(B)
pCn(so2(F(X))) - prin(F )
prn(so2(X)) - atom(X) prin(X ) prn (so2(X))
Printing result
wout([XlJ - prt(X) nl woutf[xIY]) - prt(X) nl nl wout(Y)
prt(e(A B)) -
prt(A) prinr 8 ) prt(ltE) prt(eA) - prt(A)
prt(c(A EJ) - prin() prt(A) prine ) prt(B) prin(T)
prt(c A) - prt(A) prt((A E)) - ~
prt(A) nl prt(E) prt(sol(X v Y)) - ~
prt(X) prinC v) prt(Y) prt(A lt=gt B) -
prt(e A) prinC lt=gt ) prt(e B) prt(sol(X)) - prt(X)
prt(so2(X)) - prt(X
prt(c1ause(X Y)) - prt(X)
prt(contradiction(X)) - prin(contradiction() prt(cX) prinr))middot prt(num(XY)) - prin(number(X Y)) prt(sel(X)) - prin(X) prt(X v Y) - prt(X) prin( v) prt(Y) prt(X) prin(X)
Handling conditional queries
condi((Y Xl) shy
assertcon(X) Y
45
retractcon(X)
condi((B A))
retractcon(A) fail
assertcon((A B)) 1
assertcon(A) assertcon(B)
assertcon(A) asserta(A)
retrac teon ((A B)) 1
retracteon(A) retractcon (B)
retraetcon(A) - retract(A)
BIBLIOGRAPHIC DATA SHEET
Report No UIUCDS-F-84-928
3 Recipients Accession No
4 T ide and Subt ltle
An Annotated Predicate Calculus Inference System (APCIS)
S Report Date
November 1984 6
7 Author(s)
Kah-Eng Pua 8 Performing Organization Rept
No
9 Performing Organization Name and Address
Department of Computer Science University of Illinois Urbana IL
10 ProjectTaskWork Unit No
11 Contract Grant No NSF DCR 84-06081 ONR N00014-82-K-0186
12 Sponsoring Organization Name and Address
National Science Foundation Washington DC
13 Type of Report amp Period Covered
14
15 Supplementary Notes
16 Abstracts
This paper describes a deductive inference system called APCIS (Annotated Predicate Calculus Inference System) APCIS is able to carry out inferences from expressions involving numerical quantifiers selectors disjunctions of non-negated terms negated terms disjunctions of negated terms equivalences and exceptions It is also able to count the numbers of occurrence of a given simple term or a conjunction of terms The design of contradiction and the treatment of the disjunction of non-negated terms allow APCIS to accept Horn clauses as well as non-Horn clauses and to carry out inferences from them This feature makes APCIS more general than Prolog
17 Key lords and Document Analysis 170 Descriptors
APC (Annotated Predicate Calculus) APCIS (Annotated Predicate Calculus Inference System) Horn Clause Numerical Quantifier Prolog Selector
17b IdentifiersOpen-Ended Terms
17c COSATI FieldGroup
18 Availability Statement 19 Security Class (This
Re~f~~IA~SIF IFf)
21 ~o of Pages
49 211 ecurity Class (This
PageUNCLASSIFIED
22 Price
FOA NTIS n (10middot70 usco-oc 40329-
found then check if the other side of the equivalence C3n be satisfied It so then done
else the goal fails
43 s02
s02 is also at the second level of the inference mechanism It will take care of all the
simple terms in the transl1ted query The following is the sequence that s02 wiII follow in
searching
S1 Check if the term passed to it caD be s3tisfied by any term or clause in the d3tabase
without contradiction It so then done else go to S2
S2 Pass the term together with a disjunction of terms (and its tail) picked up from the
database to dis If dis succeeds then done else the goal fails
44 dis and con
dis has three arguments In the first two clauses of dIs the first argument P v Q is
found in the database using the builtmiddotin functiol clause and the third argument R is the tair of
the term or the clause P v Q If P v Q is not a clause but a term R will be instantiated to trUE
The second 3rgument comes from either lIol or 802 and thus takes the form of either X v Y (a
disjunction of terms) or T (3 simple term)
All the clauses of dis together with con will perform the searching as exemplified in the
following algorithm (we will keep the notationsin this section)
01 Check if every term in P v Q is in X v Y It so then go to 03 else go to D2
02 For any term (in P v Q) which is not in X v Y or does not match T perform the
following tests
a Check if the term (in P v Q) has already been negated in the datab3Se (ie check if
the contradiction of the term exists in the d3tabase) If so then repeat D2 for other
terms not found in X v Y or not matching T else go to b
13
b Check if the contradiction of the term matches either side of any equivalence
relation in the database If such a match is found then check if the other side of the
equivalence can be satisfied If so then repeat O~ for other terms not found in X v Y
or not matching T else the goal fails
It all the terms (in P v Q) which are not in X v Y or do not match T survive either one
of the above two tests then go to 03
03 This step is essentially done by eon whose goal is to satisfy the tail R of P v Q It
con succeeds then done else the search fails
To close this section we will give an example to illustrate what we have covered In
Section 42 through Section 44
Example Assume that we already haye the following expressions in the database
horse(skml) v dog(skmI)
contradiction(( dog(XI) ))shy
dog(XI)
query goo(( soZ horse(X)) ))
This query will be passed to 802 which will check it the term horse() can be satisfied iu Step S 1
of Section 43 It is a failure So we now go to Step S2 In this step we pick up the disjunction
horse(~kml) v dog(skml) (and its tail true) in the datab3Se and pass it together with the term
horse(X) to dis We are now in Step 01 of Section 44 In this step we find that dog(skml) does
not match horse(X) So we have to go to Step 02 In Step 023 We find that the term dog(skml)
has already been negated (the second expression in the database) So we go to next step 03 Since
the tail of the disjuDction horse(skml) v dog(skml) is the atom true con is satisfied and the
query succeeds
45 countl and count2
countl and count2 are responsible for the counting of tbe numbers of occurrence of a
given simple term or a conjunction of terms They are activated by input queries in the form
q( exists( X whatnum amp P) )
where whatnum is the l~bel for activating the counting of the numbers of occurrence of P which
can either be a term or a conjunction of terms
countl will count the number of term(s) which will satisfy P and associate(s) with
numerical quantification(s Two counters are set to update the lower and upper boundary or the
scope or the numfrical quantifications encountered
The contents of the two counters are then passed to count2 which is responsible for the
counting or the following three types of term First term(s) which will satisfy P and associate(s)
with existential quantification(s Second term(s) which will satisfy P and has(have) Prolog atom
as its(thfir) argument(s) Third term(s) that will satisfy P and itself(themselves) is(are) Prolog
atom(s )
46 equiv
equlv will be activated only after sol and B02 have failed The first two goals of equlv
are similar to that of Step S3 in Section 42 and Step D2b in Section 44 The third goal or equiv
makes possible the inference on either side of any equivalent relation For example if we type the
following three expressions to Prolog in assertion mode
l all( X hot(X) amp humidX) - winter(X)
2 all( X hot(X) amp bumid(X) ==gt unpresent(X))
3 - ( exists( X winter(X) ) )
and then ask APCIS in query mode
q( cxists( X unpresent(X) ) )
15
APCIS with the aid of equlv will be able to answer yes to this query
41 lmpll
lmpll can be considered as the last attempt that APCIS would make to satisfy a
query It is activated only after equlv has failed It will first check if the query is conditional If
so it will convert the implication symbol to equivalence symbol and search if such an equivalent
relation can be found in the database If so a success Otherwise a failure
5 More on the Inference Mechanism
Having looked at all the subparts at the top two levels of the inference mechanism we
are ready to look at other subparts at lower levels
51 num and cnum
One distinct fe3ture or APCIS is its ability to deal with numerical quantifications As
mentioned in Section 31 input queries and assertions will undergo different transformations in
the last step (Step 10) of translation This also holds true for expressions involving numerical
quantifications Consider the following expression
exists( 6 X horse(X) )
If it is entered to Prolog via assertion mode we will after going through all the steps of
translation have the rollowing entered to the database
horse(sk n I
number(sknl6)
Now if we want to ask Are there more than five horses 7 and type in
q( exists( gt5 X horse(X) ) )
1amp
APCIS will translate the question and enter to Prolog the following query
goo(( s02( horse(X) ) s02( num( X gt5 )) ))
Note that the term number(slml 6) in the database and the term num(X gt S) in the query are
different predicates and this difference is exactly where the power of the clause num(X N)
defined in APCIS comes from When the clause num(X N) in APCIS is activated it will search
through the database to see if there is any term of the form number(X I) whose first argument
matches the first argument of num(X Y) in the query It a match is found the second arguments
of both num(X Y) in the query and number(ltI) in the database will be passed to cnum in
APCIS
The job of cnum is to compare the numerical messages carried by the second
argument or the term rlum(X Y) in the query and the second argument of the term rlumber(X I)
in the database to see if they match with each other according to the rules defined in cnum
While there are 25 rules for such matching purposes the idea is simple
Imagine that the second argument Y of the term num(X Y) in the query
and the second argument I of the term num()( I) in the database each occupies a
place in an integer line (Le the integer line in mathematics) To have a match
the domain covered by Y should contain the domain covered by L
As an example the answer to the above query is positive since the domain of gt5
contains the domain or 6
Before closing this section we will bring out a speciaJ translation aspect of expressions
involving numbers by an example We first type to APCIS the Collowing expressions in assertion
mode
1 aU(X all(Y father(X Y) amp number(Y gt6) ==gt has_manY3hildren(X) ))
2 exists(X exists( 12 Y Cather(X Y) ) )
11
After going tbrougb all tbe translation steps tbe Collowing two expressions will be entered to tbe
database
I
bas_many_cbildren( Xl ) shy
Cather( Xl X2 )
num( X2 gt6 )
2
Catber( sk m1 sk n2 )
number( skn2 12 )
lotice that whenev(gtr a term with Cunctor number appears at the rigbt-band side oC a Prolog
clause its Cunctor will be cbanged to num automatically This treatment will greatly cnbance tbe
inference power of the clause sbown in l above For instance iC we now ask tbe question
q( exists( X bas_many_children(X) ) )
The right hand side oC the clause l will match the two terms in 2 and tbe query succeeds
52 Bel and cael
A special feature of APe is tbat all predicates tbat express relations = = gt
gt= lt and lt= can be expressed explicitly using infix notations as relational statements
called selectors To handle selectors we defined Bel in APCIS
Every expression involving selectors will undergo different translations in assertion mode
and query mode For example the assertion
a( exists( [X Y] box (X) amp box(Y) amp (weigh t(X) gt weight(Y) ) ) )
will be translated into the following three terms and entered to tbe database
box( skml )
box( skm2 )
18
weight( skm 1 ) gt weight( skm2 )
Now it we want to ask Is it true that there exists two boxes of different weights and type in
q( exists( [X Yl box(X) amp box(Y) amp ( weight(X) = weight(Y) ) ) )
The question will be transformed to the following query and entered to Prolog
goo(( so( box(XI) ) s02( box(X2) ) so2( sel( weightXI) = weight(X2) )) ))
Note that the selector in the above query is surrounded by the functor set When any clause or
8el in APCIS is activated it will search through the database to see it there is any selector whose
two arguments (left and right side or any selector symbol) match the two arguments of the
selector in the query At the same time 8el will check iC the selector symbols (may be different) or
the two different selectors (one in the query and one in the database) satisfy the rules defined in
sel There are 12 matching rules defined in sel All oC them ~re straightforward and will not be
discussed here An example will be enough to explain how 8el works
Consider the execution of the above transformed query The first two terms in the query
are satisfied by the first two terms in the database and Xl and X2 are instantiated to skml and
skm2 respectively The third term of the query will be passed to eel (of APCIS) which finds a
match on each side of the two selectors (one in the query and one in the database) At the same
time the two different selector symbols gt and = are found to satisfy one of the rules in
8el As a result the query succeeds
To enhance the inference power of clauses involving selectors all the selectors appearing
on the rightmiddothand side oC any clause will be surrounded by a functor set The idea is similar to
that in the last part of the previous section
c8el is exactly the same as 8el functionally It provides a convenient way to compare
selectors when dis is being executed
19
8 Printing Result
Whenever a goal is successfully executed APCIS will not only response with a yes but
also print out the matched terms or clauses in the database This is made possible by the built-in
function bagor and the two predicates wout and prt defined in APCIS
7 Summary
In this paper a description of a deductive inference system called APCIS (Annotated
Predicate Calculus Inference System) has been provided APCIS is able to carry out inferences
from expressions involving numerical quantifiers selectors disjunctions of non-negated terms
negated terms disjunctions of negated terms equivalences and exceptions It is also able to count
the numbers of occurrence of a given simple term or a conjunction of terms
The main idea of APCIS is that each input APC expression is first passed to a
preprocessor ( ie APC translator ) which dissolves and transforms each APC expression into
Prolog expression(s) which will then be loaded to Prolog system The user bas to specify whether
each input expression is to be entered as an assertion or as a query by invoking either assertion
mode or query mode respectively Each assertion or query will undergo different transformations in
the preprocessor The different treatment of assertion or query not only allows a full uS1ge of the
Prolog inference mechanism but also makes possible a higher level of inexact pattern matching
exemplified by the examples in Section 51 and Section 52 where the four predicates num
cnum sel and csel are discussed This higher level of pattern matching increases the inference
power of APCIS greatly
The design of contradiction and the treatment of the disjunction of non-negated terms
allow APCIS to accept non-Horn clauses and to carry out inference from them This feature
makes APCIS more general than Prolog
20
While APCIS performs very well in many sets of arguments provided by the author it is
still too early to jump to conclusion that it can perform equally well in all types of problems In
any event the expressiveness of APC has greatly been retained in the present version of APCIS
and moreover some design ideas or APCIS mentioned in this paper are not restricted to APCIS
- they may be carried over to learning programs with narrower scopes
21
References
[1] W F Clocksin and C S Mellish Programming In Prolog Springermiddot Verlag Berlin Hpoundidelberg 1981
[2] R S Michalski A Theory and Methodology of Inductive Learning Chpt 4 Machine L earning Tioga Publishing Co Palo Alto CaliJornia 1989
[3] K-E Pua Translating Annotated Predicate Calculu8 to Prolog ISG Report 84middot1 UlUCDCSmiddotFmiddot918 University oj Illinois Urbana IL June 1984
22
Appendix A
APCIS Users Manual
1 Get Started
Users are urged to follow the steps depicted below
1 Get the PROLOG interpreter by typing
alias prolog mntb2sammutsammutprologprolog (Vax A)
or
alias prolog mntb2sammutsammutbinprolog (Vax B)
2 Load apc and infer by typing
prolog apc infer
When large APC expressions are expected we can increase the stlck by typingI
prolog -snnnn ape infer
where ns denote the number of stacks in decimal
3 When the wording LSW - PROLOG appears on the terminal we are reldy to interact
with APCIS The four modes by which we can invoke APCIS are summarized below
a Assert ion-Translation Mode
ta(X)
b Query-Translation Mode
tq(X)
c Assertion Mode
a(X
d Query Mode
q(X)
23
where Xs are APC expressions
2 Notations Used in APCIS
Below is a summary or notations used in APCIS
a Logical operators
amp
v
==gt
lt=gt
-
negation
conjunction
disjunction
implication
equivalence
exception
b Binary relation symbols in selectors
-
=
gt=
lt=
gt
lt
equal
not equal
greater or equal
smaller or equ al
greater
smaller
c Relational operators in numerical quantifiers
lt less than
lt= less than or equal
gt greater than
gt= greater than or equal
d BinlTY operator in numerical quantifier
range
e Universal quantifier
all(X p(X))
f Existential quantifier
exists(X p(X))
g Numerical quantifier
exists(I X p(X))
where p(X) is a formula
where X is a variable or a Jist of variables or the
form [HI~rj and p(X) a formula
where I repersents expression involving integer(s)
and operator(s) in c or d above and p(X) a formula
25
Appendix B
APCIS Program Listings
------------------------------- Program Name APCIS - Part 1 APC Translator
-------------------------------
op(3OO fx -)1
op(500 xfy amp)
oPt 500 xfy v)
op(600 xfx )
op(700 fx [gt= lt= gt lt ]) op(400 xfy [= gt= lt= gt lt ])1 op(900 xfy gt lt=gt -])1
steps(X Xg) shy
numbervars(X 1 J Step 1 change variables to iis
rmimp(X X) Step 2 conv(X X3) Step 3
rewrite(X3 X4) Step 4
negin(X4 X5) Step 5
dropexist(X5 X6 1]) Step 6
dropall(X6 X7) Step 7
distrib(X7 X8) Step 8 clausiCy(X8 X9 [J) Step 9
ta(X) shysteps(X Xg)
(( Xg = II nl
print( yes it is always true) )
( nl nl printcl(X9))) Step 10a
tq(X) shy
steps(X Xg)
prques(Xg)
28
Step 2 Removing implic3tions amp Transforming exceptions and equiv3lences
rmimpl( P - Q (PI lt=gt (QI) ) amp ((PI) lt=gt QI) ) -
rmimpl(P PI) rmimpl(Q QI)
rmimplnp) lt=gt Q (PI lt=gt -(QI)) amp nPI) lt=gt QI) ) - 1
rmimpl(P PI) rmimpJ(Q QI)
rmimpJ(P lt-gt -(Q) (PI lt=gt -(QI)) amp nPI) lt=gt QI) ) -
rmimpl(P PI) rmimpl(Q QI)
rmimpl( P lt=gt Q PI lt=gt QI ) - I
rmimpl(P PI) rmimpl(Q QI)
rmimpl( P ==gt Q -(PI) v QI ) - I
rmimpl(P PI) rmimpl(Q QI)
rmimpl( all(X P) aI(X PI) ) - 1
rmimpl(P PI)
rmimpl( exists(X P) exists(X PI) ) -
rmimpl(P PI)
rmimpl( exists(I X P) exists(I X PI) ) -
rmimpl(P PI)
rmimpl( P amp Q PI amp Ql ) -
rmimpl(P PI) rmimpl(Q Ql)
rmimpl( P v Q PI v QI ) -
rmimpl(P PI) rmimpl(Q QI)
rmimpl( -(p) -(PI) ) - I
rmimpl(p PI)
rmimpl( P P )
St~p 3 Converting numerical amp distinctive quantifiers
L Numerical quantifiers
examples of input forms
1 exists(gt= i X pIX)) where i is an integer
2 exists(i X pIX)) where i is an integer
3 exists(i j X pIX)) where i j are integers and iltj
4 exists(il v i2 X pIX)) where is are integers
examples of output forms of this step
1 exists(X pIX) amp number(X gt= i) )
2 exists(X pIX) amp number(X i) ) 3 exists(X pIX) amp number(X ij) ) 4 exists(X pIX) amp number(X il v i2) )
II Distinctive quantifiers
27
example or input Corm
exists([XYL p(X Y))
example or output Corm or this step
exists(X exists(Y p(XY)) )
conv(P lt=gt Q PI lt=gt QI) - 1
conv(P PI) conv(Q QI)
conv(al1(X P) all(X PI)) -
conv(P PI)
conv(exists(HIT] P) R ) - conv(P PI) convert distinctive quantifier
convtdis(exists([HIT]PI) R)
conv( exists(I X P) exists(X PIamp number(X I) )) -
conv(P PI) convert numerical quantifier
conv(exists(X P) exists(X PI)) - 1
conv(P Pl)
conv(P amp Q PI amp QI) - 1
conv(P PI) conv(Q QI)
conv(P v Q PI v QI) - t conv(P PI) conv(Q QI)
convC(P) -(PI)) -
conv(P PI)
conv(P Pl
convtdis(existsl[XL P) exists(X P)) - atomic(X) convtdis(exists[XIYj Pl exists(X R)) shy
convtdis(exists(Y P) R)
Step 4 Rewriting compound predicates andor compound selectors
Outputs are smiple predicates andor simple selectors
rewrite(P lt=gt Q PI lt=gt QI) - t rewrite(P PI) rewrite(Q QI)
rewrite(all(X Pl all(X PI)) - 1 rewrite(P PI)
rewriteexists(X P) exists(X PI)) - I rewriteP PI)
rewrite(P amp Q PI amp QI) - rewrite(P P 1) rewrite( Q Q 1
rewrite(P v Q PI v QI) - 1
rewrite(P PI) rewrite(Q QI)
rewriteC(P) -(PI)) - I
28
rewrite(P PI) rewrite(F(A B) R) -
rewrite(A AI) rewrite(B BI) re(F(AI BI) R)
rewrite(F(A) R) -
rewrite(A AI) re(F(AI) H)
rewrite(F(A B C) R) -
rewrite(A AI) rewrite(B BI) rewrite(C CI) re(F(AI BI CI) R)
rewrite(F(A B C D) R) -
rewrite(A AI) rewrite(B Btl rewrite(C CI) rewrite(D DI) rc(F(AI BI CI Dl) H)
rewrite(PP)
re(F(A B v el (RI v R2) -
re(F(A Bl RIl re(F(A C) R2) reF(A B amp cl (RI amp R2)) -
re(F(A B) RI) re(F(A e) R2) re(F(A amp B C) (Rl amp R2)) -
re(F(A e) R 1) re(F(B C) R 2) re(F( v B el (R I v R2)) -
re(F(A el R I) reFB el R2) re(F(A amp Bl (R I amp R2)) -
re(F(A RI) re(F(BJH2) re(F(A v B) (R 1 v R2)) -
re(F(A) RI) re(F(B) R2)
re(F(A vB c Dl (RI v R2) -
re(F(A C D) RI) re(F(B C D) R2) re(F(A amp B C D) (RI amp R2)) -
re(F(A C D) Rll re(F(B C D) R2) re(F(A B v C D) (HI v R2)) -
re(F(A B D) RI) re(F(A C D) R2) re(F(A B amp C D) (HI amp R2)) -
re(F(A B D) RI) re(F(A C D) R2) re(F(A B C v D) (RI v R2)) -
re(F(A B C) R I) reF(A B D) R2) re(F(A B C amp D) (RI amp R2)) -
29
re(F(A B C) RI) re(F(A B D) RZ)
re(F(A v B e D E) (R I v R2)) -
re(F(A e D E) R I) re(F(B e D El R2) re(F(A amp B e D E) (RI amp RZ)) -
re(F(A e D El R 1) re(F(B e D E) R2) re(F(A B v e D E) (R I v R2)) -
re(F(A B D E) RI) re(F(A e D E) R2)
re(F(A B amp e D E) (RI amp R2)) -
re(F(A B D El RI) re(F(A e D E) RZ) re(F(A B e v D E) (R I v R2)) -
re(F(A B e El R 1) re(F(A B D E) RZ) re(F(A B e amp D E) (RI amp RZ)) -
re(F(A B e E) R I) re(F(A B D E) RZ)
re(F(A B e D vEl (RI v RZ)) - l
rc(F(A B C D) RI) re(F(A n e El RZ) re(F(A B e D amp El (RI amp RZ)) - ~
re(F(A B e D) RI) re(F(A B e El RZ)
re((A = B) (A = B)l-
re((A = Bl (A = 8)) -
retIA gt= BI (A gt= B)) -
re((A lt= B) (A lt= B)) -
re((A gt B) (A gt B))-
re((A lt Bl (A lt Bl)- re(A A)
Step) Bringing n(gation inwards
Degin(-(P) PI) - neg(P Pl)
negin(P lt=gt Q PI lt=gt Ql) - ~
negin(P PI) negiD(Q QI)
Degin(aU(X P) all(X PI)) - Degin(P PI) negin(exists(X P) exists(X PI))- negin(P PI) negin(P amp Q PI amp Ql) - Degin(P PI) negin(Q Ql)
Degin(P v Q PI v QI) - Degin(P PI) negin(Q QI) negin(P Pl
neg(-(P) PI) - negin(P PI)
neg(all(X P) exists(X PI)) - neg(P PI)
30
neg(exists(X P) all(X PI)) - neg(P PI)
neg(P amp Q PI v QI) - neg(P PI) neg(Q Ql)
neg(P v Q PI amp QI) - neg(P PI) neg(Q QI)
neg(P -(PH
Step 6 Dropping existnetial quanti6ers
dropexist(P lt=gt Q PI lt=gt QI Elerns) - dropexist(P PI Elerns) dropexist(Q QI Elerns)
dropexist(alJ(X P) all(XPI) Elerns)
dropexist(P PI [XIElernsJ)
dropexist(exists(X P amp nurnber(X Yraquo P2 Elerns) -
genfun(skn Newg) Fun = [NewgIElerns]
subst(FuD X P amp Dumber(X Y) PI)
dropexist(Pl P2 Elerns)
dropexist(exists(X P) PZ Elerns) -
genfun(skrn Newf) Fun = [NewfIElernsJ
subst(Fun X p PI)
dropex ist(P 1 P~ Elerns)
dropexist(P v Q PI v QI Elerns) - ~
dropexist(P PI Elerns) dropexist(Q Ql Elerns)
dropexist(P amp Q PI amp QI Elerns) - 1
dropexist(P Pl Elerns) dropexist(Q QI Elerns)
dropexist(P P _)
gen fun(R oot Newn arne) shy
getnurn(Root Nurn)
narne(Root Rootlist)
append(Rootlist[Nurnj Narnelist)
concat(Narnelist Newnarne)
getnurn(Root Nurn) shy
retract(currentnurn(Root Nurn 1 raquo
Nurn is Nurni + 1
asserta(currentnurn(Root Nurn))
getnurn(Root 1) - asserta(currentnurn(Root 1))
subst(New Old Val Val) - var(Val)
subst(New Old Old New) - 1 substNew Old Val Val) - atornic(Val)
31
subst(New Old Val Newval) shy
runctor(Val F N)
CUDctor(Newval F N)
subst_args(N New Old Val Newval)
subst_args(O J J - J J
subst_args(N New Old Val NewVal) shy
arg(N Val OldArg)
arg(N NewVal NewArg)
subst(New Old OldArg NewArg)
NI is N - I
subst_args(Nl New Old Val NewVal)
append([J L L) -
append([XILl] L2 [XIL3]) - append(Ll L2 L3)
Step - Dropping universal quantifiers
dropall(P lt=gt Q PI lt=gt QI)-
dropall(P PI) dropall(Q QI)
dropall(all(X P) PI) - ~ dropall(P PI)
dropall(P amp Q PI amp QI) -
dropall(P PI) dropall(Q QI)
dropall(P v Q PI v QI) -
dropall(P PI) dropall(Q QI)
dropall(P P)
Step 8 Distributing conjunctions over disjunctions
distrib(P lt=gt Q PI lt=gt Ql) - t distrib(P PI) distrib(Q QI)
distrib(P v Q R) -
distrib(P PI) distrib(Q QI)
distributing(PI v QI R)
distrib(P it Q PI it QI) -
distrib(P PI) distrib( Q QI)
distrib(P P)
distributing((P amp Q) v R PI amp QI) -
distrib(P v R PI) distrib(Q v R Ql)
32
distributing(P v (Q amp R) PI amp Ql) -
distrib(P v Q PI) distrib(P v R Ql)
distributing(P P)
Step 9 Packing each conjunction into clauses
c1ausify(P amp Q CI C2) -
clausiCy(P CI C3) c1ausify(Q C3 C2)
cbusiCy(P [d(A B)ICs] Cs) shy
inclause(P A [j B [I) 1
c1ausiry( C C)
inclause(P v Q A AI B B1) -
inc1ause(P A2 AI B2 Bl)
inclause(Q A A2 B B2)
inclausenp) A A B1 B) -
notin(P A) putin(P B B1)
inclause(P AI A B B) shy
notin(P Bl putin(P A AI)
notin(X [XU) - fail
notin(X [JLj) - notin(X L)
notin(X 1])
putin(X II [X]) - 1
putin(X [XILJ L) -
putin(X [YILJ [YILl]) - putin(X L Ll)
Step 1Oa Printing clauses
printcl([]) - nl nl
printcl(c1(AB)ICsj) - printcl(A Bl nl printcl(Cs)
printcl(L II) - printdis(IL) prinr)middot
printclHl L) - prin(contradiction(() printconl(rL)
print()) - ) printconj(rL) prinr )
printcl(Ll L2) shy
printdis(ILl) print( - ) printconj(rL2) prin()
printdis(S[Lj) - printcbar(SL)
33
printdis(S[LILs]) - printchu(SL) prin( v) printdis(SLs)
printconl(S[LI) - printchar(SL)
printconl(S[LILs]) - printchar(SL) prin( ) printconl(SLs)
printconj(S[L]) - tab(3) printchar(SL)
prin tconj( S [L IL sl) shy
tab(3) printchar(SL) print( ) printconj(SLs)
printchar(SP) shy
atomic(P)
name(P L)
L = [IT]
concat([XIT NewP)
prin(~ewP)
printchar(SP) shy
atomic(P)
prin(P)
printchar(SA lt= gt B) -
prin((l clausify(A AI [j) pl(eAl) prin())
print lt=gt )
prin(() cbusify(B Bl [I) pJ(eBl) prine))middot
printchar(rnumber(X N)) shy
prin(num() printchar(rx) prin( )
printchar(rN) prinC))
printchar(rF(A B)) shy
seJec(F(A B))
prinCsel() printchar(rA)
prin( F ) printchar(rB) prinC))
printchar(SF(A B)) shy
( selec(F(A B)) F = infix )
printchar(SA) prin( F ) printchar(SB)
printchar(SF(A)) shy
(F= prefix gt= F= prefix lt= F= prefixgt F= prefix lt )
prin(F ) printcbar(SA)
printchar(SP) shy
functor(P F MaxN)
prin(F ()
Nl is MaxN - 1
putout(S N 1 P MaxN)
34
prin())
putout(S 0 P MaxN) -
arg(~laxN P Argu)
prin tchar(SArgu)
putout(S N p MaxN) shy
Nt is MaxN - N arg(NI P Argu)
printcbar(SArgu )
prin( )
N2 is N - 1
putout(S N2 P MaxN)
selec(FA B)) shy
( F= infix = F= infix f= F= infix gt=
F= infix gt F= infix lt= F= infix lt )
35
----------------------------------Program Name APClS - Part 2 Inference Mechanism ---------------------------------- a(X) shy
steps(X X9)
(( X9 =[] nl
print( yes it is always true) )
( X9 =[cI(IJ[])] nl
print( no it is always false) )
( nl nl printel(X9) Step 1Oa
tell(temp_file) printel(X9) e1ose(temp_file) consult(temp_6Ie) ))
q(X) shy
asserta( in pt(X))
steps(X X9)
(( X9 = [] print(middot~H~~middot~t~)
print(THE AiSWER IS YES)
print( ilgIQlQl(~) )
( X9 = [e1([j [j)] Pr1nt ( OJ fi(i I~ iii Ij)middot(i)(i) fiyenQ)riiio(i)(ij)(i)fj)fiyen1li1il1li1il)__ gtw~ __~_~ _~~_ ~_-=~
print(THE ANSWER IS NO ) print() )
( teI1(temp_6Ie)
prques(X9) Step 1Ob
close(temp_file)
nl print(Let me think about it) nl
consult(temp_6Ie) ))
retrac t( in pt(X))
Step lOb Printing question
prques(lcl(A 8)1) - prin(goo(() pl(qA 8) print()))
prques([c1(A 8HCs]) - prin(goo(() pl(qA 8) print() pl(q Cs)
pl(e [c1(A 8)]) - pl(eA 8)
pl(q [c1(A 8)]) - pl(qA 8) print()))
pl(S [e1(A B)ICs]) - pl(SA B) prin( ) pl(S Cs)
38
pl(q [j L) - prin(c1ause(contradiction(() pcont(qL) prin())_))
pl(S [I L)- prin(so2(contradidion(() pcont(SL) print))))middot
pl(S [L] []) - prin(so2() pcbar(SL) prin())
pl(S L [J)- prinsol() plett(SL) print))
pl(S [L] LI) - prin(condi(() pchar(cL)
prin(() pcont(S Ll) prine))))
pl(S L Ll)- prin(c1ause() plert(cL)
prin(() pcont(S Ll) prine)))
plert(S[LJ) - pchar(SL)
plert(SjLILsj) - pcbar(SL) print v) pleCt(SLs)
pcont(S[L]) - pchar(SL)
pcont(S[LILsj) - pcbar(SL) prinr ) pcont(SLs)
pcbar(SP) shy
atomic(P)
name(PL)
( L = [IT] L = [5 k miT] L = [5 k niT] )
concat[XITj NewP)
prin(0JewP)
pchar(SP) shy
atomic(P)
prin(P) pchar(SA lt=gt B) -
prin(() dausify(A AI []) pl(eAI) prin())
prinr lt=gt ) prin(() dausify(B BI ]) pl(eB) print))
pchar(Snumber(X N)) shy
prin(num() pchar(SX) prin()
pchar(SN) prinr))
pcbar(SM N) - prin(M N)
pcbar(cF(A B)) shy
selec(F(A Braquo
pcbar(cA)
prine F ) pchar(cB) pchar(SF(A B)) shy
selec(F(A B))
prin(sel() pchar(SA)
print F ) pchar(SB) print)) I
31
pc har(SF(A)) shy
( F= prefix gt= F= prefix lt= F= prefixgt F= prefix lt )
prin(F ) pchar(SA)
pchar(SP)shy
runctor(P F MaxN)
prin(F ()
011 is MaxN - 1 pout(SNl P MaxN)
print) )
pout(S 0 P M3xN) - 1
arg(~bxN P Argu)
pchlr(SArgu )
pout(S N P MaxN shy
Nl is MaxN - N
arg(Nl P Argu)
pchar(SArgu
prin( )
N2 is N - 1
pout(S N2 P ~13xN)
Comparing numbers in numerical quantifiers
num(XN) shy
number(X I)
cnum(N 1) ~
cnumlaquo=01 lt=I- N gt=I
cnumlaquo=J lt I) - N gt=1-1
cnumlaquo=NIJ) - N gt=J 1
cnumlaquo=N J)- integer(I) N gt=I~
cnum(gt=N gt=1) - N lt=1
cnum(gt=N gt I) - N lt=1+ 1 cnum(gt=NIJ) - N lt=1
cnum(gt=N lt=1)- N lt=1
cnum(gt=N lt I) - N lt=1 L cnum(gt=N 1)- integer(I) N lt=1
cnum( lt N lt 1)- N gt=1 L
38
cnum( lt N lt=1) - N gt I cnum( lt NLJ) - N gt J
cnum( lt N 1)- integer(I) N gt 1
cnum(gt N gt I) - N lt=1 cnumlgt i gt=1) - N lt I
cnum(gt N lt=1) - N lt=0
cnum(gt N lt I) - N lt=0
cnum(gt iIJ) - N lt I cnum(gt N 1)- integer(I) N lt I
cnum(~LN lt=1) - M=I N gt= I l
cnum(~LN lt I) - M=l N gt= I-I
cnum(~LNLJ) - M lt =1 N gt = J
cnum(~1N 1)- integer(I) M lt= I N gt= I
cnum(- N) - integer(N)
Comparing selectors
sel(X = Y) shyX= Y
sel(X I=Y) shy(X I=Y X lt Y Xgt Y)
sel(X gt Y) shyXgt Y
sel(X lt Y) shyXlt Y
selX gt=Y) shy(X gt=Y X= Y Xgt Y)
se(X lt=Y) shy
(X lt=Y
X= Y
X lt Y)
csel(infix = infix =)
39
csel(infix = infix = csel(infix = infix gt)
csel(infix = infix lt) csel(infix gt infix gt) cseJ(infix lt infix lt) csel(infix gt= infix gt=) csel(infix gt= infix gt csel(infix gt= infix =)
csellinfix lt= infix lt=) csel(infix lt= infix lt) csel(infix lt= infix =)
Finding solutions
sol(X v Y) -
(( notetra(X) eon(X) ( sol(Y) )
( c1ause(P v Q R) not(cketra(P v Q))
dis(P v Q X v Y R) ~ )
( A lt=gt B equival(A lt=gt B X v Y) ~ I) sol(X) - ~ notetra(X) eon(X)
so~(X) - notetra(X)
( con (X)
( clause(P v Q R) not(ekctra(P v Q)) dis(P v Q X R) I)
cketra(P v Q) -
eketra(P) eketra(Q) eketra(F(I J)) shy
selec(F(I J))
c1ause(contradiction(sel(F(IJ))) _I
eketra(number(W I)) -
clause(cootradietion(num(Wl)) - eketr(P) shy
clause(contradiction(P) - 1
notctra(P) shy
not( e lause( con tradiction(P) _))
40
Searching (or disjunctions
dis(P v Q X v Y R) - dis(P X v Y R)
dis(Q X v Y R) con(R)
dis(P v Q X R) -
dis(P X R) dis(Q X R) con(R
dis(P X v Y R) - clause(contradicton(Pl J 1
dis(F(I J) sel(G(I J)) v Y R) - csel(G Fl dis(number(WI) num(W N v Y R) - cnum(N I)
dis(P P v Y R) -
dis(P X v Y R) - dis(P Y R)
dis(F(I J) seJ(G(IJ)) R) - csel(G F)
dis(number(WI) num(WN) R) - cnum(N I) dis(P P R) - 1
dis(FJ J X R) shy
( ckctra(F(IJ) cbeckeq(seJ(F(IJ))) )
dis(number(W Il X R) - ( ckctra(number(WI)) cbeckeq(num(WI)) )
dis(P X R) shy( ckctra(P) cbeckeq(P) ) 1
cbeckeq(P) shy
(( A lt=gt so2(contradiction(P))
bagof(A A [jj) ) ( so2(contradiction(P)) lt=gt B
bagof(B B Uj) ))
ckeq(A) shy
( so2(A) lt=gt B B lt=gt so2(A) ) bagof(B B UJ)
con((P Q)) -
clause(P R) con(R) con(Q) con(true) -
con(contradiction(P)) - clause(contradiction(P) J
con(cause(X Y)) - cause(X Y)
con(sel(X)) - sel(X)
con(num(X Y)) - num(X Y) con(P)- (( dause(P R) (con(R) ckeq(R)))
colJectin(P) )
collectin(P) shy
bagof(S (c1ause(P S) S = true) [L LIJ )
mkcon(L Ll L)
bagor(l (L2 ) UJ) L
mkcon((A AI) (B B1) (sol(A v B) e D)) -
mkcon(A B1 e) mkcon(A1 (B Bl) D)
mkcon(A (B B1) (sol(A v B) e)) -
mkcon(A Bl e)
mkcon((A AI) B (sol(A v B) e)) middot1
mkcon(Al B e)
mkcon(A B sol(A vB))
Searching ror equivalences
equival(A lt=gt B X v Y) - 1 ( equival(A lt=gt B X) equival(A lt=gt B Y) )
equival(s02(A) lt=gt 502(B) A) - clause(B _I equival(s02(B) lt=gt 502(A) A) c1ause(B _I
Top level or inrerence mechanism
goo((s02(whatnum) P)) -
getatm(P Xl
bagor(number(X Y) ( P so2(number(X Y)) ) A )
count1(A 00 L R) nl
bagor(X P B )
count2(B L R Ll Rl) nJ print()
(( LI = 0 Rl = 0 print(THE ANSWER IS ) nl
(( Ll = Rl prin(-Jumber or ) prn(P) print(is Ll) )
( Rlgt20000 prin(Number or I prn(P) print(is LI or more) )
42
( prin(Number of ) pfn(P) print( is from Ll to Rl) )) )
( print(THE ANSWER IS NO I )) print()
goo(X) shy
(( bagof(X X L) L = [I nl print()
print(THE ANSWER IS YES) nl wout(L) print() )
( equiv(X L) nl print()
print(THE ANSWER IS YES) nl wout(L) print(-) )
( c1ause(inpt(A ==gt B) _I ( impli(A B Z) impli(B A Z) ) print(l~Hl)
printTHE ANSWER IS YES) nl print(Z) print(Hj~(fH~) ))
goo(X) print( Hg)
print(THE ANSWER IS NO ) print( lH~lH~gg9l9lmiddotmiddot~Q(gmiddot)
00 Semhing for implications in equiV3lent relations
impli( B Z) shyt-ell( z1) prin(templ() pchn(S A lt=gt B) print()) close ( zl) consult(zl) templ(Z)
unload zl Z
Searching for equivalence
equiv (X L)
(( X lt=gt Y
equ(Y YI)t bagof(Y Yl L) L = [j )
(Y lt=gt X equ(Y YI) bagof(Y Yl L) L = [J )
( X = F(New)
clause(~ew T) makeup(T Tl)
(( Tl lt=gt B
equ(B Bl) bagof(Bl Bl M) M = [j L=[Newl )
(A lt=gt TI
equ(A AI) bagof(Al AI M) M = 1] L=INewj )) ))
makeup((A B) (AI Bl)) -
makeup(A A1) makeup(B BI)
makeup(A so2(A))
equ((A B) (AI BI)) -
equ(A AI) equ(B Bl)
equ(sol(X v Y) sol(XI v Yl)) -
equ(X XI) equ(Y YI)
equ(so2(X) so2(XI)) -
equ(X XI)
equ(contradiction(X) clJuse(contradiction(X) X) ) -
equ(X X)
Counting numbers
getatm((A B) X) -
( getatm(A X) getatm(B X) )
getatm(so2(F(X)) X) -
getatm(so2(X) X) - atom(X)
countl([J L R L R) -
countl([number(X Y)IT] L R L2 R2) shy
(( Y = (gt=~) LI is L + N Rl is R + 20001 l )
( Y = (gt N) LI is L+ N+ 1 RI is R + 20002 )
(Y == laquo=~) LI is L + 1 Rl is R + N )
(Y = laquo N) LI is L + 1 RI is R+N-I)
(Y == IJ LI is L + I Rl is R + J ) ( Y == N L1 is L + N RI is R + N ))
count1(T LI R 1 L2 R2)
count2(fJ L R L R) - 1
count2([XITJ L R L2 R2) shy
name(X Xl)
(( Xl = sknj LI is L Rl is R )
44
( Xl = Iskmj L1 is L + 1 RI is R + ZOOO1) ( LI is L + I RI is R + I ))
count2(T LI RI L2 R2)
pfn((A B)) - pfn(A) prn(B)
pCn(so2(F(X))) - prin(F )
prn(so2(X)) - atom(X) prin(X ) prn (so2(X))
Printing result
wout([XlJ - prt(X) nl woutf[xIY]) - prt(X) nl nl wout(Y)
prt(e(A B)) -
prt(A) prinr 8 ) prt(ltE) prt(eA) - prt(A)
prt(c(A EJ) - prin() prt(A) prine ) prt(B) prin(T)
prt(c A) - prt(A) prt((A E)) - ~
prt(A) nl prt(E) prt(sol(X v Y)) - ~
prt(X) prinC v) prt(Y) prt(A lt=gt B) -
prt(e A) prinC lt=gt ) prt(e B) prt(sol(X)) - prt(X)
prt(so2(X)) - prt(X
prt(c1ause(X Y)) - prt(X)
prt(contradiction(X)) - prin(contradiction() prt(cX) prinr))middot prt(num(XY)) - prin(number(X Y)) prt(sel(X)) - prin(X) prt(X v Y) - prt(X) prin( v) prt(Y) prt(X) prin(X)
Handling conditional queries
condi((Y Xl) shy
assertcon(X) Y
45
retractcon(X)
condi((B A))
retractcon(A) fail
assertcon((A B)) 1
assertcon(A) assertcon(B)
assertcon(A) asserta(A)
retrac teon ((A B)) 1
retracteon(A) retractcon (B)
retraetcon(A) - retract(A)
BIBLIOGRAPHIC DATA SHEET
Report No UIUCDS-F-84-928
3 Recipients Accession No
4 T ide and Subt ltle
An Annotated Predicate Calculus Inference System (APCIS)
S Report Date
November 1984 6
7 Author(s)
Kah-Eng Pua 8 Performing Organization Rept
No
9 Performing Organization Name and Address
Department of Computer Science University of Illinois Urbana IL
10 ProjectTaskWork Unit No
11 Contract Grant No NSF DCR 84-06081 ONR N00014-82-K-0186
12 Sponsoring Organization Name and Address
National Science Foundation Washington DC
13 Type of Report amp Period Covered
14
15 Supplementary Notes
16 Abstracts
This paper describes a deductive inference system called APCIS (Annotated Predicate Calculus Inference System) APCIS is able to carry out inferences from expressions involving numerical quantifiers selectors disjunctions of non-negated terms negated terms disjunctions of negated terms equivalences and exceptions It is also able to count the numbers of occurrence of a given simple term or a conjunction of terms The design of contradiction and the treatment of the disjunction of non-negated terms allow APCIS to accept Horn clauses as well as non-Horn clauses and to carry out inferences from them This feature makes APCIS more general than Prolog
17 Key lords and Document Analysis 170 Descriptors
APC (Annotated Predicate Calculus) APCIS (Annotated Predicate Calculus Inference System) Horn Clause Numerical Quantifier Prolog Selector
17b IdentifiersOpen-Ended Terms
17c COSATI FieldGroup
18 Availability Statement 19 Security Class (This
Re~f~~IA~SIF IFf)
21 ~o of Pages
49 211 ecurity Class (This
PageUNCLASSIFIED
22 Price
FOA NTIS n (10middot70 usco-oc 40329-
13
b Check if the contradiction of the term matches either side of any equivalence
relation in the database If such a match is found then check if the other side of the
equivalence can be satisfied If so then repeat O~ for other terms not found in X v Y
or not matching T else the goal fails
It all the terms (in P v Q) which are not in X v Y or do not match T survive either one
of the above two tests then go to 03
03 This step is essentially done by eon whose goal is to satisfy the tail R of P v Q It
con succeeds then done else the search fails
To close this section we will give an example to illustrate what we have covered In
Section 42 through Section 44
Example Assume that we already haye the following expressions in the database
horse(skml) v dog(skmI)
contradiction(( dog(XI) ))shy
dog(XI)
query goo(( soZ horse(X)) ))
This query will be passed to 802 which will check it the term horse() can be satisfied iu Step S 1
of Section 43 It is a failure So we now go to Step S2 In this step we pick up the disjunction
horse(~kml) v dog(skml) (and its tail true) in the datab3Se and pass it together with the term
horse(X) to dis We are now in Step 01 of Section 44 In this step we find that dog(skml) does
not match horse(X) So we have to go to Step 02 In Step 023 We find that the term dog(skml)
has already been negated (the second expression in the database) So we go to next step 03 Since
the tail of the disjuDction horse(skml) v dog(skml) is the atom true con is satisfied and the
query succeeds
45 countl and count2
countl and count2 are responsible for the counting of tbe numbers of occurrence of a
given simple term or a conjunction of terms They are activated by input queries in the form
q( exists( X whatnum amp P) )
where whatnum is the l~bel for activating the counting of the numbers of occurrence of P which
can either be a term or a conjunction of terms
countl will count the number of term(s) which will satisfy P and associate(s) with
numerical quantification(s Two counters are set to update the lower and upper boundary or the
scope or the numfrical quantifications encountered
The contents of the two counters are then passed to count2 which is responsible for the
counting or the following three types of term First term(s) which will satisfy P and associate(s)
with existential quantification(s Second term(s) which will satisfy P and has(have) Prolog atom
as its(thfir) argument(s) Third term(s) that will satisfy P and itself(themselves) is(are) Prolog
atom(s )
46 equiv
equlv will be activated only after sol and B02 have failed The first two goals of equlv
are similar to that of Step S3 in Section 42 and Step D2b in Section 44 The third goal or equiv
makes possible the inference on either side of any equivalent relation For example if we type the
following three expressions to Prolog in assertion mode
l all( X hot(X) amp humidX) - winter(X)
2 all( X hot(X) amp bumid(X) ==gt unpresent(X))
3 - ( exists( X winter(X) ) )
and then ask APCIS in query mode
q( cxists( X unpresent(X) ) )
15
APCIS with the aid of equlv will be able to answer yes to this query
41 lmpll
lmpll can be considered as the last attempt that APCIS would make to satisfy a
query It is activated only after equlv has failed It will first check if the query is conditional If
so it will convert the implication symbol to equivalence symbol and search if such an equivalent
relation can be found in the database If so a success Otherwise a failure
5 More on the Inference Mechanism
Having looked at all the subparts at the top two levels of the inference mechanism we
are ready to look at other subparts at lower levels
51 num and cnum
One distinct fe3ture or APCIS is its ability to deal with numerical quantifications As
mentioned in Section 31 input queries and assertions will undergo different transformations in
the last step (Step 10) of translation This also holds true for expressions involving numerical
quantifications Consider the following expression
exists( 6 X horse(X) )
If it is entered to Prolog via assertion mode we will after going through all the steps of
translation have the rollowing entered to the database
horse(sk n I
number(sknl6)
Now if we want to ask Are there more than five horses 7 and type in
q( exists( gt5 X horse(X) ) )
1amp
APCIS will translate the question and enter to Prolog the following query
goo(( s02( horse(X) ) s02( num( X gt5 )) ))
Note that the term number(slml 6) in the database and the term num(X gt S) in the query are
different predicates and this difference is exactly where the power of the clause num(X N)
defined in APCIS comes from When the clause num(X N) in APCIS is activated it will search
through the database to see if there is any term of the form number(X I) whose first argument
matches the first argument of num(X Y) in the query It a match is found the second arguments
of both num(X Y) in the query and number(ltI) in the database will be passed to cnum in
APCIS
The job of cnum is to compare the numerical messages carried by the second
argument or the term rlum(X Y) in the query and the second argument of the term rlumber(X I)
in the database to see if they match with each other according to the rules defined in cnum
While there are 25 rules for such matching purposes the idea is simple
Imagine that the second argument Y of the term num(X Y) in the query
and the second argument I of the term num()( I) in the database each occupies a
place in an integer line (Le the integer line in mathematics) To have a match
the domain covered by Y should contain the domain covered by L
As an example the answer to the above query is positive since the domain of gt5
contains the domain or 6
Before closing this section we will bring out a speciaJ translation aspect of expressions
involving numbers by an example We first type to APCIS the Collowing expressions in assertion
mode
1 aU(X all(Y father(X Y) amp number(Y gt6) ==gt has_manY3hildren(X) ))
2 exists(X exists( 12 Y Cather(X Y) ) )
11
After going tbrougb all tbe translation steps tbe Collowing two expressions will be entered to tbe
database
I
bas_many_cbildren( Xl ) shy
Cather( Xl X2 )
num( X2 gt6 )
2
Catber( sk m1 sk n2 )
number( skn2 12 )
lotice that whenev(gtr a term with Cunctor number appears at the rigbt-band side oC a Prolog
clause its Cunctor will be cbanged to num automatically This treatment will greatly cnbance tbe
inference power of the clause sbown in l above For instance iC we now ask tbe question
q( exists( X bas_many_children(X) ) )
The right hand side oC the clause l will match the two terms in 2 and tbe query succeeds
52 Bel and cael
A special feature of APe is tbat all predicates tbat express relations = = gt
gt= lt and lt= can be expressed explicitly using infix notations as relational statements
called selectors To handle selectors we defined Bel in APCIS
Every expression involving selectors will undergo different translations in assertion mode
and query mode For example the assertion
a( exists( [X Y] box (X) amp box(Y) amp (weigh t(X) gt weight(Y) ) ) )
will be translated into the following three terms and entered to tbe database
box( skml )
box( skm2 )
18
weight( skm 1 ) gt weight( skm2 )
Now it we want to ask Is it true that there exists two boxes of different weights and type in
q( exists( [X Yl box(X) amp box(Y) amp ( weight(X) = weight(Y) ) ) )
The question will be transformed to the following query and entered to Prolog
goo(( so( box(XI) ) s02( box(X2) ) so2( sel( weightXI) = weight(X2) )) ))
Note that the selector in the above query is surrounded by the functor set When any clause or
8el in APCIS is activated it will search through the database to see it there is any selector whose
two arguments (left and right side or any selector symbol) match the two arguments of the
selector in the query At the same time 8el will check iC the selector symbols (may be different) or
the two different selectors (one in the query and one in the database) satisfy the rules defined in
sel There are 12 matching rules defined in sel All oC them ~re straightforward and will not be
discussed here An example will be enough to explain how 8el works
Consider the execution of the above transformed query The first two terms in the query
are satisfied by the first two terms in the database and Xl and X2 are instantiated to skml and
skm2 respectively The third term of the query will be passed to eel (of APCIS) which finds a
match on each side of the two selectors (one in the query and one in the database) At the same
time the two different selector symbols gt and = are found to satisfy one of the rules in
8el As a result the query succeeds
To enhance the inference power of clauses involving selectors all the selectors appearing
on the rightmiddothand side oC any clause will be surrounded by a functor set The idea is similar to
that in the last part of the previous section
c8el is exactly the same as 8el functionally It provides a convenient way to compare
selectors when dis is being executed
19
8 Printing Result
Whenever a goal is successfully executed APCIS will not only response with a yes but
also print out the matched terms or clauses in the database This is made possible by the built-in
function bagor and the two predicates wout and prt defined in APCIS
7 Summary
In this paper a description of a deductive inference system called APCIS (Annotated
Predicate Calculus Inference System) has been provided APCIS is able to carry out inferences
from expressions involving numerical quantifiers selectors disjunctions of non-negated terms
negated terms disjunctions of negated terms equivalences and exceptions It is also able to count
the numbers of occurrence of a given simple term or a conjunction of terms
The main idea of APCIS is that each input APC expression is first passed to a
preprocessor ( ie APC translator ) which dissolves and transforms each APC expression into
Prolog expression(s) which will then be loaded to Prolog system The user bas to specify whether
each input expression is to be entered as an assertion or as a query by invoking either assertion
mode or query mode respectively Each assertion or query will undergo different transformations in
the preprocessor The different treatment of assertion or query not only allows a full uS1ge of the
Prolog inference mechanism but also makes possible a higher level of inexact pattern matching
exemplified by the examples in Section 51 and Section 52 where the four predicates num
cnum sel and csel are discussed This higher level of pattern matching increases the inference
power of APCIS greatly
The design of contradiction and the treatment of the disjunction of non-negated terms
allow APCIS to accept non-Horn clauses and to carry out inference from them This feature
makes APCIS more general than Prolog
20
While APCIS performs very well in many sets of arguments provided by the author it is
still too early to jump to conclusion that it can perform equally well in all types of problems In
any event the expressiveness of APC has greatly been retained in the present version of APCIS
and moreover some design ideas or APCIS mentioned in this paper are not restricted to APCIS
- they may be carried over to learning programs with narrower scopes
21
References
[1] W F Clocksin and C S Mellish Programming In Prolog Springermiddot Verlag Berlin Hpoundidelberg 1981
[2] R S Michalski A Theory and Methodology of Inductive Learning Chpt 4 Machine L earning Tioga Publishing Co Palo Alto CaliJornia 1989
[3] K-E Pua Translating Annotated Predicate Calculu8 to Prolog ISG Report 84middot1 UlUCDCSmiddotFmiddot918 University oj Illinois Urbana IL June 1984
22
Appendix A
APCIS Users Manual
1 Get Started
Users are urged to follow the steps depicted below
1 Get the PROLOG interpreter by typing
alias prolog mntb2sammutsammutprologprolog (Vax A)
or
alias prolog mntb2sammutsammutbinprolog (Vax B)
2 Load apc and infer by typing
prolog apc infer
When large APC expressions are expected we can increase the stlck by typingI
prolog -snnnn ape infer
where ns denote the number of stacks in decimal
3 When the wording LSW - PROLOG appears on the terminal we are reldy to interact
with APCIS The four modes by which we can invoke APCIS are summarized below
a Assert ion-Translation Mode
ta(X)
b Query-Translation Mode
tq(X)
c Assertion Mode
a(X
d Query Mode
q(X)
23
where Xs are APC expressions
2 Notations Used in APCIS
Below is a summary or notations used in APCIS
a Logical operators
amp
v
==gt
lt=gt
-
negation
conjunction
disjunction
implication
equivalence
exception
b Binary relation symbols in selectors
-
=
gt=
lt=
gt
lt
equal
not equal
greater or equal
smaller or equ al
greater
smaller
c Relational operators in numerical quantifiers
lt less than
lt= less than or equal
gt greater than
gt= greater than or equal
d BinlTY operator in numerical quantifier
range
e Universal quantifier
all(X p(X))
f Existential quantifier
exists(X p(X))
g Numerical quantifier
exists(I X p(X))
where p(X) is a formula
where X is a variable or a Jist of variables or the
form [HI~rj and p(X) a formula
where I repersents expression involving integer(s)
and operator(s) in c or d above and p(X) a formula
25
Appendix B
APCIS Program Listings
------------------------------- Program Name APCIS - Part 1 APC Translator
-------------------------------
op(3OO fx -)1
op(500 xfy amp)
oPt 500 xfy v)
op(600 xfx )
op(700 fx [gt= lt= gt lt ]) op(400 xfy [= gt= lt= gt lt ])1 op(900 xfy gt lt=gt -])1
steps(X Xg) shy
numbervars(X 1 J Step 1 change variables to iis
rmimp(X X) Step 2 conv(X X3) Step 3
rewrite(X3 X4) Step 4
negin(X4 X5) Step 5
dropexist(X5 X6 1]) Step 6
dropall(X6 X7) Step 7
distrib(X7 X8) Step 8 clausiCy(X8 X9 [J) Step 9
ta(X) shysteps(X Xg)
(( Xg = II nl
print( yes it is always true) )
( nl nl printcl(X9))) Step 10a
tq(X) shy
steps(X Xg)
prques(Xg)
28
Step 2 Removing implic3tions amp Transforming exceptions and equiv3lences
rmimpl( P - Q (PI lt=gt (QI) ) amp ((PI) lt=gt QI) ) -
rmimpl(P PI) rmimpl(Q QI)
rmimplnp) lt=gt Q (PI lt=gt -(QI)) amp nPI) lt=gt QI) ) - 1
rmimpl(P PI) rmimpJ(Q QI)
rmimpJ(P lt-gt -(Q) (PI lt=gt -(QI)) amp nPI) lt=gt QI) ) -
rmimpl(P PI) rmimpl(Q QI)
rmimpl( P lt=gt Q PI lt=gt QI ) - I
rmimpl(P PI) rmimpl(Q QI)
rmimpl( P ==gt Q -(PI) v QI ) - I
rmimpl(P PI) rmimpl(Q QI)
rmimpl( all(X P) aI(X PI) ) - 1
rmimpl(P PI)
rmimpl( exists(X P) exists(X PI) ) -
rmimpl(P PI)
rmimpl( exists(I X P) exists(I X PI) ) -
rmimpl(P PI)
rmimpl( P amp Q PI amp Ql ) -
rmimpl(P PI) rmimpl(Q Ql)
rmimpl( P v Q PI v QI ) -
rmimpl(P PI) rmimpl(Q QI)
rmimpl( -(p) -(PI) ) - I
rmimpl(p PI)
rmimpl( P P )
St~p 3 Converting numerical amp distinctive quantifiers
L Numerical quantifiers
examples of input forms
1 exists(gt= i X pIX)) where i is an integer
2 exists(i X pIX)) where i is an integer
3 exists(i j X pIX)) where i j are integers and iltj
4 exists(il v i2 X pIX)) where is are integers
examples of output forms of this step
1 exists(X pIX) amp number(X gt= i) )
2 exists(X pIX) amp number(X i) ) 3 exists(X pIX) amp number(X ij) ) 4 exists(X pIX) amp number(X il v i2) )
II Distinctive quantifiers
27
example or input Corm
exists([XYL p(X Y))
example or output Corm or this step
exists(X exists(Y p(XY)) )
conv(P lt=gt Q PI lt=gt QI) - 1
conv(P PI) conv(Q QI)
conv(al1(X P) all(X PI)) -
conv(P PI)
conv(exists(HIT] P) R ) - conv(P PI) convert distinctive quantifier
convtdis(exists([HIT]PI) R)
conv( exists(I X P) exists(X PIamp number(X I) )) -
conv(P PI) convert numerical quantifier
conv(exists(X P) exists(X PI)) - 1
conv(P Pl)
conv(P amp Q PI amp QI) - 1
conv(P PI) conv(Q QI)
conv(P v Q PI v QI) - t conv(P PI) conv(Q QI)
convC(P) -(PI)) -
conv(P PI)
conv(P Pl
convtdis(existsl[XL P) exists(X P)) - atomic(X) convtdis(exists[XIYj Pl exists(X R)) shy
convtdis(exists(Y P) R)
Step 4 Rewriting compound predicates andor compound selectors
Outputs are smiple predicates andor simple selectors
rewrite(P lt=gt Q PI lt=gt QI) - t rewrite(P PI) rewrite(Q QI)
rewrite(all(X Pl all(X PI)) - 1 rewrite(P PI)
rewriteexists(X P) exists(X PI)) - I rewriteP PI)
rewrite(P amp Q PI amp QI) - rewrite(P P 1) rewrite( Q Q 1
rewrite(P v Q PI v QI) - 1
rewrite(P PI) rewrite(Q QI)
rewriteC(P) -(PI)) - I
28
rewrite(P PI) rewrite(F(A B) R) -
rewrite(A AI) rewrite(B BI) re(F(AI BI) R)
rewrite(F(A) R) -
rewrite(A AI) re(F(AI) H)
rewrite(F(A B C) R) -
rewrite(A AI) rewrite(B BI) rewrite(C CI) re(F(AI BI CI) R)
rewrite(F(A B C D) R) -
rewrite(A AI) rewrite(B Btl rewrite(C CI) rewrite(D DI) rc(F(AI BI CI Dl) H)
rewrite(PP)
re(F(A B v el (RI v R2) -
re(F(A Bl RIl re(F(A C) R2) reF(A B amp cl (RI amp R2)) -
re(F(A B) RI) re(F(A e) R2) re(F(A amp B C) (Rl amp R2)) -
re(F(A e) R 1) re(F(B C) R 2) re(F( v B el (R I v R2)) -
re(F(A el R I) reFB el R2) re(F(A amp Bl (R I amp R2)) -
re(F(A RI) re(F(BJH2) re(F(A v B) (R 1 v R2)) -
re(F(A) RI) re(F(B) R2)
re(F(A vB c Dl (RI v R2) -
re(F(A C D) RI) re(F(B C D) R2) re(F(A amp B C D) (RI amp R2)) -
re(F(A C D) Rll re(F(B C D) R2) re(F(A B v C D) (HI v R2)) -
re(F(A B D) RI) re(F(A C D) R2) re(F(A B amp C D) (HI amp R2)) -
re(F(A B D) RI) re(F(A C D) R2) re(F(A B C v D) (RI v R2)) -
re(F(A B C) R I) reF(A B D) R2) re(F(A B C amp D) (RI amp R2)) -
29
re(F(A B C) RI) re(F(A B D) RZ)
re(F(A v B e D E) (R I v R2)) -
re(F(A e D E) R I) re(F(B e D El R2) re(F(A amp B e D E) (RI amp RZ)) -
re(F(A e D El R 1) re(F(B e D E) R2) re(F(A B v e D E) (R I v R2)) -
re(F(A B D E) RI) re(F(A e D E) R2)
re(F(A B amp e D E) (RI amp R2)) -
re(F(A B D El RI) re(F(A e D E) RZ) re(F(A B e v D E) (R I v R2)) -
re(F(A B e El R 1) re(F(A B D E) RZ) re(F(A B e amp D E) (RI amp RZ)) -
re(F(A B e E) R I) re(F(A B D E) RZ)
re(F(A B e D vEl (RI v RZ)) - l
rc(F(A B C D) RI) re(F(A n e El RZ) re(F(A B e D amp El (RI amp RZ)) - ~
re(F(A B e D) RI) re(F(A B e El RZ)
re((A = B) (A = B)l-
re((A = Bl (A = 8)) -
retIA gt= BI (A gt= B)) -
re((A lt= B) (A lt= B)) -
re((A gt B) (A gt B))-
re((A lt Bl (A lt Bl)- re(A A)
Step) Bringing n(gation inwards
Degin(-(P) PI) - neg(P Pl)
negin(P lt=gt Q PI lt=gt Ql) - ~
negin(P PI) negiD(Q QI)
Degin(aU(X P) all(X PI)) - Degin(P PI) negin(exists(X P) exists(X PI))- negin(P PI) negin(P amp Q PI amp Ql) - Degin(P PI) negin(Q Ql)
Degin(P v Q PI v QI) - Degin(P PI) negin(Q QI) negin(P Pl
neg(-(P) PI) - negin(P PI)
neg(all(X P) exists(X PI)) - neg(P PI)
30
neg(exists(X P) all(X PI)) - neg(P PI)
neg(P amp Q PI v QI) - neg(P PI) neg(Q Ql)
neg(P v Q PI amp QI) - neg(P PI) neg(Q QI)
neg(P -(PH
Step 6 Dropping existnetial quanti6ers
dropexist(P lt=gt Q PI lt=gt QI Elerns) - dropexist(P PI Elerns) dropexist(Q QI Elerns)
dropexist(alJ(X P) all(XPI) Elerns)
dropexist(P PI [XIElernsJ)
dropexist(exists(X P amp nurnber(X Yraquo P2 Elerns) -
genfun(skn Newg) Fun = [NewgIElerns]
subst(FuD X P amp Dumber(X Y) PI)
dropexist(Pl P2 Elerns)
dropexist(exists(X P) PZ Elerns) -
genfun(skrn Newf) Fun = [NewfIElernsJ
subst(Fun X p PI)
dropex ist(P 1 P~ Elerns)
dropexist(P v Q PI v QI Elerns) - ~
dropexist(P PI Elerns) dropexist(Q Ql Elerns)
dropexist(P amp Q PI amp QI Elerns) - 1
dropexist(P Pl Elerns) dropexist(Q QI Elerns)
dropexist(P P _)
gen fun(R oot Newn arne) shy
getnurn(Root Nurn)
narne(Root Rootlist)
append(Rootlist[Nurnj Narnelist)
concat(Narnelist Newnarne)
getnurn(Root Nurn) shy
retract(currentnurn(Root Nurn 1 raquo
Nurn is Nurni + 1
asserta(currentnurn(Root Nurn))
getnurn(Root 1) - asserta(currentnurn(Root 1))
subst(New Old Val Val) - var(Val)
subst(New Old Old New) - 1 substNew Old Val Val) - atornic(Val)
31
subst(New Old Val Newval) shy
runctor(Val F N)
CUDctor(Newval F N)
subst_args(N New Old Val Newval)
subst_args(O J J - J J
subst_args(N New Old Val NewVal) shy
arg(N Val OldArg)
arg(N NewVal NewArg)
subst(New Old OldArg NewArg)
NI is N - I
subst_args(Nl New Old Val NewVal)
append([J L L) -
append([XILl] L2 [XIL3]) - append(Ll L2 L3)
Step - Dropping universal quantifiers
dropall(P lt=gt Q PI lt=gt QI)-
dropall(P PI) dropall(Q QI)
dropall(all(X P) PI) - ~ dropall(P PI)
dropall(P amp Q PI amp QI) -
dropall(P PI) dropall(Q QI)
dropall(P v Q PI v QI) -
dropall(P PI) dropall(Q QI)
dropall(P P)
Step 8 Distributing conjunctions over disjunctions
distrib(P lt=gt Q PI lt=gt Ql) - t distrib(P PI) distrib(Q QI)
distrib(P v Q R) -
distrib(P PI) distrib(Q QI)
distributing(PI v QI R)
distrib(P it Q PI it QI) -
distrib(P PI) distrib( Q QI)
distrib(P P)
distributing((P amp Q) v R PI amp QI) -
distrib(P v R PI) distrib(Q v R Ql)
32
distributing(P v (Q amp R) PI amp Ql) -
distrib(P v Q PI) distrib(P v R Ql)
distributing(P P)
Step 9 Packing each conjunction into clauses
c1ausify(P amp Q CI C2) -
clausiCy(P CI C3) c1ausify(Q C3 C2)
cbusiCy(P [d(A B)ICs] Cs) shy
inclause(P A [j B [I) 1
c1ausiry( C C)
inclause(P v Q A AI B B1) -
inc1ause(P A2 AI B2 Bl)
inclause(Q A A2 B B2)
inclausenp) A A B1 B) -
notin(P A) putin(P B B1)
inclause(P AI A B B) shy
notin(P Bl putin(P A AI)
notin(X [XU) - fail
notin(X [JLj) - notin(X L)
notin(X 1])
putin(X II [X]) - 1
putin(X [XILJ L) -
putin(X [YILJ [YILl]) - putin(X L Ll)
Step 1Oa Printing clauses
printcl([]) - nl nl
printcl(c1(AB)ICsj) - printcl(A Bl nl printcl(Cs)
printcl(L II) - printdis(IL) prinr)middot
printclHl L) - prin(contradiction(() printconl(rL)
print()) - ) printconj(rL) prinr )
printcl(Ll L2) shy
printdis(ILl) print( - ) printconj(rL2) prin()
printdis(S[Lj) - printcbar(SL)
33
printdis(S[LILs]) - printchu(SL) prin( v) printdis(SLs)
printconl(S[LI) - printchar(SL)
printconl(S[LILs]) - printchar(SL) prin( ) printconl(SLs)
printconj(S[L]) - tab(3) printchar(SL)
prin tconj( S [L IL sl) shy
tab(3) printchar(SL) print( ) printconj(SLs)
printchar(SP) shy
atomic(P)
name(P L)
L = [IT]
concat([XIT NewP)
prin(~ewP)
printchar(SP) shy
atomic(P)
prin(P)
printchar(SA lt= gt B) -
prin((l clausify(A AI [j) pl(eAl) prin())
print lt=gt )
prin(() cbusify(B Bl [I) pJ(eBl) prine))middot
printchar(rnumber(X N)) shy
prin(num() printchar(rx) prin( )
printchar(rN) prinC))
printchar(rF(A B)) shy
seJec(F(A B))
prinCsel() printchar(rA)
prin( F ) printchar(rB) prinC))
printchar(SF(A B)) shy
( selec(F(A B)) F = infix )
printchar(SA) prin( F ) printchar(SB)
printchar(SF(A)) shy
(F= prefix gt= F= prefix lt= F= prefixgt F= prefix lt )
prin(F ) printcbar(SA)
printchar(SP) shy
functor(P F MaxN)
prin(F ()
Nl is MaxN - 1
putout(S N 1 P MaxN)
34
prin())
putout(S 0 P MaxN) -
arg(~laxN P Argu)
prin tchar(SArgu)
putout(S N p MaxN) shy
Nt is MaxN - N arg(NI P Argu)
printcbar(SArgu )
prin( )
N2 is N - 1
putout(S N2 P MaxN)
selec(FA B)) shy
( F= infix = F= infix f= F= infix gt=
F= infix gt F= infix lt= F= infix lt )
35
----------------------------------Program Name APClS - Part 2 Inference Mechanism ---------------------------------- a(X) shy
steps(X X9)
(( X9 =[] nl
print( yes it is always true) )
( X9 =[cI(IJ[])] nl
print( no it is always false) )
( nl nl printel(X9) Step 1Oa
tell(temp_file) printel(X9) e1ose(temp_file) consult(temp_6Ie) ))
q(X) shy
asserta( in pt(X))
steps(X X9)
(( X9 = [] print(middot~H~~middot~t~)
print(THE AiSWER IS YES)
print( ilgIQlQl(~) )
( X9 = [e1([j [j)] Pr1nt ( OJ fi(i I~ iii Ij)middot(i)(i) fiyenQ)riiio(i)(ij)(i)fj)fiyen1li1il1li1il)__ gtw~ __~_~ _~~_ ~_-=~
print(THE ANSWER IS NO ) print() )
( teI1(temp_6Ie)
prques(X9) Step 1Ob
close(temp_file)
nl print(Let me think about it) nl
consult(temp_6Ie) ))
retrac t( in pt(X))
Step lOb Printing question
prques(lcl(A 8)1) - prin(goo(() pl(qA 8) print()))
prques([c1(A 8HCs]) - prin(goo(() pl(qA 8) print() pl(q Cs)
pl(e [c1(A 8)]) - pl(eA 8)
pl(q [c1(A 8)]) - pl(qA 8) print()))
pl(S [e1(A B)ICs]) - pl(SA B) prin( ) pl(S Cs)
38
pl(q [j L) - prin(c1ause(contradiction(() pcont(qL) prin())_))
pl(S [I L)- prin(so2(contradidion(() pcont(SL) print))))middot
pl(S [L] []) - prin(so2() pcbar(SL) prin())
pl(S L [J)- prinsol() plett(SL) print))
pl(S [L] LI) - prin(condi(() pchar(cL)
prin(() pcont(S Ll) prine))))
pl(S L Ll)- prin(c1ause() plert(cL)
prin(() pcont(S Ll) prine)))
plert(S[LJ) - pchar(SL)
plert(SjLILsj) - pcbar(SL) print v) pleCt(SLs)
pcont(S[L]) - pchar(SL)
pcont(S[LILsj) - pcbar(SL) prinr ) pcont(SLs)
pcbar(SP) shy
atomic(P)
name(PL)
( L = [IT] L = [5 k miT] L = [5 k niT] )
concat[XITj NewP)
prin(0JewP)
pchar(SP) shy
atomic(P)
prin(P) pchar(SA lt=gt B) -
prin(() dausify(A AI []) pl(eAI) prin())
prinr lt=gt ) prin(() dausify(B BI ]) pl(eB) print))
pchar(Snumber(X N)) shy
prin(num() pchar(SX) prin()
pchar(SN) prinr))
pcbar(SM N) - prin(M N)
pcbar(cF(A B)) shy
selec(F(A Braquo
pcbar(cA)
prine F ) pchar(cB) pchar(SF(A B)) shy
selec(F(A B))
prin(sel() pchar(SA)
print F ) pchar(SB) print)) I
31
pc har(SF(A)) shy
( F= prefix gt= F= prefix lt= F= prefixgt F= prefix lt )
prin(F ) pchar(SA)
pchar(SP)shy
runctor(P F MaxN)
prin(F ()
011 is MaxN - 1 pout(SNl P MaxN)
print) )
pout(S 0 P M3xN) - 1
arg(~bxN P Argu)
pchlr(SArgu )
pout(S N P MaxN shy
Nl is MaxN - N
arg(Nl P Argu)
pchar(SArgu
prin( )
N2 is N - 1
pout(S N2 P ~13xN)
Comparing numbers in numerical quantifiers
num(XN) shy
number(X I)
cnum(N 1) ~
cnumlaquo=01 lt=I- N gt=I
cnumlaquo=J lt I) - N gt=1-1
cnumlaquo=NIJ) - N gt=J 1
cnumlaquo=N J)- integer(I) N gt=I~
cnum(gt=N gt=1) - N lt=1
cnum(gt=N gt I) - N lt=1+ 1 cnum(gt=NIJ) - N lt=1
cnum(gt=N lt=1)- N lt=1
cnum(gt=N lt I) - N lt=1 L cnum(gt=N 1)- integer(I) N lt=1
cnum( lt N lt 1)- N gt=1 L
38
cnum( lt N lt=1) - N gt I cnum( lt NLJ) - N gt J
cnum( lt N 1)- integer(I) N gt 1
cnum(gt N gt I) - N lt=1 cnumlgt i gt=1) - N lt I
cnum(gt N lt=1) - N lt=0
cnum(gt N lt I) - N lt=0
cnum(gt iIJ) - N lt I cnum(gt N 1)- integer(I) N lt I
cnum(~LN lt=1) - M=I N gt= I l
cnum(~LN lt I) - M=l N gt= I-I
cnum(~LNLJ) - M lt =1 N gt = J
cnum(~1N 1)- integer(I) M lt= I N gt= I
cnum(- N) - integer(N)
Comparing selectors
sel(X = Y) shyX= Y
sel(X I=Y) shy(X I=Y X lt Y Xgt Y)
sel(X gt Y) shyXgt Y
sel(X lt Y) shyXlt Y
selX gt=Y) shy(X gt=Y X= Y Xgt Y)
se(X lt=Y) shy
(X lt=Y
X= Y
X lt Y)
csel(infix = infix =)
39
csel(infix = infix = csel(infix = infix gt)
csel(infix = infix lt) csel(infix gt infix gt) cseJ(infix lt infix lt) csel(infix gt= infix gt=) csel(infix gt= infix gt csel(infix gt= infix =)
csellinfix lt= infix lt=) csel(infix lt= infix lt) csel(infix lt= infix =)
Finding solutions
sol(X v Y) -
(( notetra(X) eon(X) ( sol(Y) )
( c1ause(P v Q R) not(cketra(P v Q))
dis(P v Q X v Y R) ~ )
( A lt=gt B equival(A lt=gt B X v Y) ~ I) sol(X) - ~ notetra(X) eon(X)
so~(X) - notetra(X)
( con (X)
( clause(P v Q R) not(ekctra(P v Q)) dis(P v Q X R) I)
cketra(P v Q) -
eketra(P) eketra(Q) eketra(F(I J)) shy
selec(F(I J))
c1ause(contradiction(sel(F(IJ))) _I
eketra(number(W I)) -
clause(cootradietion(num(Wl)) - eketr(P) shy
clause(contradiction(P) - 1
notctra(P) shy
not( e lause( con tradiction(P) _))
40
Searching (or disjunctions
dis(P v Q X v Y R) - dis(P X v Y R)
dis(Q X v Y R) con(R)
dis(P v Q X R) -
dis(P X R) dis(Q X R) con(R
dis(P X v Y R) - clause(contradicton(Pl J 1
dis(F(I J) sel(G(I J)) v Y R) - csel(G Fl dis(number(WI) num(W N v Y R) - cnum(N I)
dis(P P v Y R) -
dis(P X v Y R) - dis(P Y R)
dis(F(I J) seJ(G(IJ)) R) - csel(G F)
dis(number(WI) num(WN) R) - cnum(N I) dis(P P R) - 1
dis(FJ J X R) shy
( ckctra(F(IJ) cbeckeq(seJ(F(IJ))) )
dis(number(W Il X R) - ( ckctra(number(WI)) cbeckeq(num(WI)) )
dis(P X R) shy( ckctra(P) cbeckeq(P) ) 1
cbeckeq(P) shy
(( A lt=gt so2(contradiction(P))
bagof(A A [jj) ) ( so2(contradiction(P)) lt=gt B
bagof(B B Uj) ))
ckeq(A) shy
( so2(A) lt=gt B B lt=gt so2(A) ) bagof(B B UJ)
con((P Q)) -
clause(P R) con(R) con(Q) con(true) -
con(contradiction(P)) - clause(contradiction(P) J
con(cause(X Y)) - cause(X Y)
con(sel(X)) - sel(X)
con(num(X Y)) - num(X Y) con(P)- (( dause(P R) (con(R) ckeq(R)))
colJectin(P) )
collectin(P) shy
bagof(S (c1ause(P S) S = true) [L LIJ )
mkcon(L Ll L)
bagor(l (L2 ) UJ) L
mkcon((A AI) (B B1) (sol(A v B) e D)) -
mkcon(A B1 e) mkcon(A1 (B Bl) D)
mkcon(A (B B1) (sol(A v B) e)) -
mkcon(A Bl e)
mkcon((A AI) B (sol(A v B) e)) middot1
mkcon(Al B e)
mkcon(A B sol(A vB))
Searching ror equivalences
equival(A lt=gt B X v Y) - 1 ( equival(A lt=gt B X) equival(A lt=gt B Y) )
equival(s02(A) lt=gt 502(B) A) - clause(B _I equival(s02(B) lt=gt 502(A) A) c1ause(B _I
Top level or inrerence mechanism
goo((s02(whatnum) P)) -
getatm(P Xl
bagor(number(X Y) ( P so2(number(X Y)) ) A )
count1(A 00 L R) nl
bagor(X P B )
count2(B L R Ll Rl) nJ print()
(( LI = 0 Rl = 0 print(THE ANSWER IS ) nl
(( Ll = Rl prin(-Jumber or ) prn(P) print(is Ll) )
( Rlgt20000 prin(Number or I prn(P) print(is LI or more) )
42
( prin(Number of ) pfn(P) print( is from Ll to Rl) )) )
( print(THE ANSWER IS NO I )) print()
goo(X) shy
(( bagof(X X L) L = [I nl print()
print(THE ANSWER IS YES) nl wout(L) print() )
( equiv(X L) nl print()
print(THE ANSWER IS YES) nl wout(L) print(-) )
( c1ause(inpt(A ==gt B) _I ( impli(A B Z) impli(B A Z) ) print(l~Hl)
printTHE ANSWER IS YES) nl print(Z) print(Hj~(fH~) ))
goo(X) print( Hg)
print(THE ANSWER IS NO ) print( lH~lH~gg9l9lmiddotmiddot~Q(gmiddot)
00 Semhing for implications in equiV3lent relations
impli( B Z) shyt-ell( z1) prin(templ() pchn(S A lt=gt B) print()) close ( zl) consult(zl) templ(Z)
unload zl Z
Searching for equivalence
equiv (X L)
(( X lt=gt Y
equ(Y YI)t bagof(Y Yl L) L = [j )
(Y lt=gt X equ(Y YI) bagof(Y Yl L) L = [J )
( X = F(New)
clause(~ew T) makeup(T Tl)
(( Tl lt=gt B
equ(B Bl) bagof(Bl Bl M) M = [j L=[Newl )
(A lt=gt TI
equ(A AI) bagof(Al AI M) M = 1] L=INewj )) ))
makeup((A B) (AI Bl)) -
makeup(A A1) makeup(B BI)
makeup(A so2(A))
equ((A B) (AI BI)) -
equ(A AI) equ(B Bl)
equ(sol(X v Y) sol(XI v Yl)) -
equ(X XI) equ(Y YI)
equ(so2(X) so2(XI)) -
equ(X XI)
equ(contradiction(X) clJuse(contradiction(X) X) ) -
equ(X X)
Counting numbers
getatm((A B) X) -
( getatm(A X) getatm(B X) )
getatm(so2(F(X)) X) -
getatm(so2(X) X) - atom(X)
countl([J L R L R) -
countl([number(X Y)IT] L R L2 R2) shy
(( Y = (gt=~) LI is L + N Rl is R + 20001 l )
( Y = (gt N) LI is L+ N+ 1 RI is R + 20002 )
(Y == laquo=~) LI is L + 1 Rl is R + N )
(Y = laquo N) LI is L + 1 RI is R+N-I)
(Y == IJ LI is L + I Rl is R + J ) ( Y == N L1 is L + N RI is R + N ))
count1(T LI R 1 L2 R2)
count2(fJ L R L R) - 1
count2([XITJ L R L2 R2) shy
name(X Xl)
(( Xl = sknj LI is L Rl is R )
44
( Xl = Iskmj L1 is L + 1 RI is R + ZOOO1) ( LI is L + I RI is R + I ))
count2(T LI RI L2 R2)
pfn((A B)) - pfn(A) prn(B)
pCn(so2(F(X))) - prin(F )
prn(so2(X)) - atom(X) prin(X ) prn (so2(X))
Printing result
wout([XlJ - prt(X) nl woutf[xIY]) - prt(X) nl nl wout(Y)
prt(e(A B)) -
prt(A) prinr 8 ) prt(ltE) prt(eA) - prt(A)
prt(c(A EJ) - prin() prt(A) prine ) prt(B) prin(T)
prt(c A) - prt(A) prt((A E)) - ~
prt(A) nl prt(E) prt(sol(X v Y)) - ~
prt(X) prinC v) prt(Y) prt(A lt=gt B) -
prt(e A) prinC lt=gt ) prt(e B) prt(sol(X)) - prt(X)
prt(so2(X)) - prt(X
prt(c1ause(X Y)) - prt(X)
prt(contradiction(X)) - prin(contradiction() prt(cX) prinr))middot prt(num(XY)) - prin(number(X Y)) prt(sel(X)) - prin(X) prt(X v Y) - prt(X) prin( v) prt(Y) prt(X) prin(X)
Handling conditional queries
condi((Y Xl) shy
assertcon(X) Y
45
retractcon(X)
condi((B A))
retractcon(A) fail
assertcon((A B)) 1
assertcon(A) assertcon(B)
assertcon(A) asserta(A)
retrac teon ((A B)) 1
retracteon(A) retractcon (B)
retraetcon(A) - retract(A)
BIBLIOGRAPHIC DATA SHEET
Report No UIUCDS-F-84-928
3 Recipients Accession No
4 T ide and Subt ltle
An Annotated Predicate Calculus Inference System (APCIS)
S Report Date
November 1984 6
7 Author(s)
Kah-Eng Pua 8 Performing Organization Rept
No
9 Performing Organization Name and Address
Department of Computer Science University of Illinois Urbana IL
10 ProjectTaskWork Unit No
11 Contract Grant No NSF DCR 84-06081 ONR N00014-82-K-0186
12 Sponsoring Organization Name and Address
National Science Foundation Washington DC
13 Type of Report amp Period Covered
14
15 Supplementary Notes
16 Abstracts
This paper describes a deductive inference system called APCIS (Annotated Predicate Calculus Inference System) APCIS is able to carry out inferences from expressions involving numerical quantifiers selectors disjunctions of non-negated terms negated terms disjunctions of negated terms equivalences and exceptions It is also able to count the numbers of occurrence of a given simple term or a conjunction of terms The design of contradiction and the treatment of the disjunction of non-negated terms allow APCIS to accept Horn clauses as well as non-Horn clauses and to carry out inferences from them This feature makes APCIS more general than Prolog
17 Key lords and Document Analysis 170 Descriptors
APC (Annotated Predicate Calculus) APCIS (Annotated Predicate Calculus Inference System) Horn Clause Numerical Quantifier Prolog Selector
17b IdentifiersOpen-Ended Terms
17c COSATI FieldGroup
18 Availability Statement 19 Security Class (This
Re~f~~IA~SIF IFf)
21 ~o of Pages
49 211 ecurity Class (This
PageUNCLASSIFIED
22 Price
FOA NTIS n (10middot70 usco-oc 40329-
45 countl and count2
countl and count2 are responsible for the counting of tbe numbers of occurrence of a
given simple term or a conjunction of terms They are activated by input queries in the form
q( exists( X whatnum amp P) )
where whatnum is the l~bel for activating the counting of the numbers of occurrence of P which
can either be a term or a conjunction of terms
countl will count the number of term(s) which will satisfy P and associate(s) with
numerical quantification(s Two counters are set to update the lower and upper boundary or the
scope or the numfrical quantifications encountered
The contents of the two counters are then passed to count2 which is responsible for the
counting or the following three types of term First term(s) which will satisfy P and associate(s)
with existential quantification(s Second term(s) which will satisfy P and has(have) Prolog atom
as its(thfir) argument(s) Third term(s) that will satisfy P and itself(themselves) is(are) Prolog
atom(s )
46 equiv
equlv will be activated only after sol and B02 have failed The first two goals of equlv
are similar to that of Step S3 in Section 42 and Step D2b in Section 44 The third goal or equiv
makes possible the inference on either side of any equivalent relation For example if we type the
following three expressions to Prolog in assertion mode
l all( X hot(X) amp humidX) - winter(X)
2 all( X hot(X) amp bumid(X) ==gt unpresent(X))
3 - ( exists( X winter(X) ) )
and then ask APCIS in query mode
q( cxists( X unpresent(X) ) )
15
APCIS with the aid of equlv will be able to answer yes to this query
41 lmpll
lmpll can be considered as the last attempt that APCIS would make to satisfy a
query It is activated only after equlv has failed It will first check if the query is conditional If
so it will convert the implication symbol to equivalence symbol and search if such an equivalent
relation can be found in the database If so a success Otherwise a failure
5 More on the Inference Mechanism
Having looked at all the subparts at the top two levels of the inference mechanism we
are ready to look at other subparts at lower levels
51 num and cnum
One distinct fe3ture or APCIS is its ability to deal with numerical quantifications As
mentioned in Section 31 input queries and assertions will undergo different transformations in
the last step (Step 10) of translation This also holds true for expressions involving numerical
quantifications Consider the following expression
exists( 6 X horse(X) )
If it is entered to Prolog via assertion mode we will after going through all the steps of
translation have the rollowing entered to the database
horse(sk n I
number(sknl6)
Now if we want to ask Are there more than five horses 7 and type in
q( exists( gt5 X horse(X) ) )
1amp
APCIS will translate the question and enter to Prolog the following query
goo(( s02( horse(X) ) s02( num( X gt5 )) ))
Note that the term number(slml 6) in the database and the term num(X gt S) in the query are
different predicates and this difference is exactly where the power of the clause num(X N)
defined in APCIS comes from When the clause num(X N) in APCIS is activated it will search
through the database to see if there is any term of the form number(X I) whose first argument
matches the first argument of num(X Y) in the query It a match is found the second arguments
of both num(X Y) in the query and number(ltI) in the database will be passed to cnum in
APCIS
The job of cnum is to compare the numerical messages carried by the second
argument or the term rlum(X Y) in the query and the second argument of the term rlumber(X I)
in the database to see if they match with each other according to the rules defined in cnum
While there are 25 rules for such matching purposes the idea is simple
Imagine that the second argument Y of the term num(X Y) in the query
and the second argument I of the term num()( I) in the database each occupies a
place in an integer line (Le the integer line in mathematics) To have a match
the domain covered by Y should contain the domain covered by L
As an example the answer to the above query is positive since the domain of gt5
contains the domain or 6
Before closing this section we will bring out a speciaJ translation aspect of expressions
involving numbers by an example We first type to APCIS the Collowing expressions in assertion
mode
1 aU(X all(Y father(X Y) amp number(Y gt6) ==gt has_manY3hildren(X) ))
2 exists(X exists( 12 Y Cather(X Y) ) )
11
After going tbrougb all tbe translation steps tbe Collowing two expressions will be entered to tbe
database
I
bas_many_cbildren( Xl ) shy
Cather( Xl X2 )
num( X2 gt6 )
2
Catber( sk m1 sk n2 )
number( skn2 12 )
lotice that whenev(gtr a term with Cunctor number appears at the rigbt-band side oC a Prolog
clause its Cunctor will be cbanged to num automatically This treatment will greatly cnbance tbe
inference power of the clause sbown in l above For instance iC we now ask tbe question
q( exists( X bas_many_children(X) ) )
The right hand side oC the clause l will match the two terms in 2 and tbe query succeeds
52 Bel and cael
A special feature of APe is tbat all predicates tbat express relations = = gt
gt= lt and lt= can be expressed explicitly using infix notations as relational statements
called selectors To handle selectors we defined Bel in APCIS
Every expression involving selectors will undergo different translations in assertion mode
and query mode For example the assertion
a( exists( [X Y] box (X) amp box(Y) amp (weigh t(X) gt weight(Y) ) ) )
will be translated into the following three terms and entered to tbe database
box( skml )
box( skm2 )
18
weight( skm 1 ) gt weight( skm2 )
Now it we want to ask Is it true that there exists two boxes of different weights and type in
q( exists( [X Yl box(X) amp box(Y) amp ( weight(X) = weight(Y) ) ) )
The question will be transformed to the following query and entered to Prolog
goo(( so( box(XI) ) s02( box(X2) ) so2( sel( weightXI) = weight(X2) )) ))
Note that the selector in the above query is surrounded by the functor set When any clause or
8el in APCIS is activated it will search through the database to see it there is any selector whose
two arguments (left and right side or any selector symbol) match the two arguments of the
selector in the query At the same time 8el will check iC the selector symbols (may be different) or
the two different selectors (one in the query and one in the database) satisfy the rules defined in
sel There are 12 matching rules defined in sel All oC them ~re straightforward and will not be
discussed here An example will be enough to explain how 8el works
Consider the execution of the above transformed query The first two terms in the query
are satisfied by the first two terms in the database and Xl and X2 are instantiated to skml and
skm2 respectively The third term of the query will be passed to eel (of APCIS) which finds a
match on each side of the two selectors (one in the query and one in the database) At the same
time the two different selector symbols gt and = are found to satisfy one of the rules in
8el As a result the query succeeds
To enhance the inference power of clauses involving selectors all the selectors appearing
on the rightmiddothand side oC any clause will be surrounded by a functor set The idea is similar to
that in the last part of the previous section
c8el is exactly the same as 8el functionally It provides a convenient way to compare
selectors when dis is being executed
19
8 Printing Result
Whenever a goal is successfully executed APCIS will not only response with a yes but
also print out the matched terms or clauses in the database This is made possible by the built-in
function bagor and the two predicates wout and prt defined in APCIS
7 Summary
In this paper a description of a deductive inference system called APCIS (Annotated
Predicate Calculus Inference System) has been provided APCIS is able to carry out inferences
from expressions involving numerical quantifiers selectors disjunctions of non-negated terms
negated terms disjunctions of negated terms equivalences and exceptions It is also able to count
the numbers of occurrence of a given simple term or a conjunction of terms
The main idea of APCIS is that each input APC expression is first passed to a
preprocessor ( ie APC translator ) which dissolves and transforms each APC expression into
Prolog expression(s) which will then be loaded to Prolog system The user bas to specify whether
each input expression is to be entered as an assertion or as a query by invoking either assertion
mode or query mode respectively Each assertion or query will undergo different transformations in
the preprocessor The different treatment of assertion or query not only allows a full uS1ge of the
Prolog inference mechanism but also makes possible a higher level of inexact pattern matching
exemplified by the examples in Section 51 and Section 52 where the four predicates num
cnum sel and csel are discussed This higher level of pattern matching increases the inference
power of APCIS greatly
The design of contradiction and the treatment of the disjunction of non-negated terms
allow APCIS to accept non-Horn clauses and to carry out inference from them This feature
makes APCIS more general than Prolog
20
While APCIS performs very well in many sets of arguments provided by the author it is
still too early to jump to conclusion that it can perform equally well in all types of problems In
any event the expressiveness of APC has greatly been retained in the present version of APCIS
and moreover some design ideas or APCIS mentioned in this paper are not restricted to APCIS
- they may be carried over to learning programs with narrower scopes
21
References
[1] W F Clocksin and C S Mellish Programming In Prolog Springermiddot Verlag Berlin Hpoundidelberg 1981
[2] R S Michalski A Theory and Methodology of Inductive Learning Chpt 4 Machine L earning Tioga Publishing Co Palo Alto CaliJornia 1989
[3] K-E Pua Translating Annotated Predicate Calculu8 to Prolog ISG Report 84middot1 UlUCDCSmiddotFmiddot918 University oj Illinois Urbana IL June 1984
22
Appendix A
APCIS Users Manual
1 Get Started
Users are urged to follow the steps depicted below
1 Get the PROLOG interpreter by typing
alias prolog mntb2sammutsammutprologprolog (Vax A)
or
alias prolog mntb2sammutsammutbinprolog (Vax B)
2 Load apc and infer by typing
prolog apc infer
When large APC expressions are expected we can increase the stlck by typingI
prolog -snnnn ape infer
where ns denote the number of stacks in decimal
3 When the wording LSW - PROLOG appears on the terminal we are reldy to interact
with APCIS The four modes by which we can invoke APCIS are summarized below
a Assert ion-Translation Mode
ta(X)
b Query-Translation Mode
tq(X)
c Assertion Mode
a(X
d Query Mode
q(X)
23
where Xs are APC expressions
2 Notations Used in APCIS
Below is a summary or notations used in APCIS
a Logical operators
amp
v
==gt
lt=gt
-
negation
conjunction
disjunction
implication
equivalence
exception
b Binary relation symbols in selectors
-
=
gt=
lt=
gt
lt
equal
not equal
greater or equal
smaller or equ al
greater
smaller
c Relational operators in numerical quantifiers
lt less than
lt= less than or equal
gt greater than
gt= greater than or equal
d BinlTY operator in numerical quantifier
range
e Universal quantifier
all(X p(X))
f Existential quantifier
exists(X p(X))
g Numerical quantifier
exists(I X p(X))
where p(X) is a formula
where X is a variable or a Jist of variables or the
form [HI~rj and p(X) a formula
where I repersents expression involving integer(s)
and operator(s) in c or d above and p(X) a formula
25
Appendix B
APCIS Program Listings
------------------------------- Program Name APCIS - Part 1 APC Translator
-------------------------------
op(3OO fx -)1
op(500 xfy amp)
oPt 500 xfy v)
op(600 xfx )
op(700 fx [gt= lt= gt lt ]) op(400 xfy [= gt= lt= gt lt ])1 op(900 xfy gt lt=gt -])1
steps(X Xg) shy
numbervars(X 1 J Step 1 change variables to iis
rmimp(X X) Step 2 conv(X X3) Step 3
rewrite(X3 X4) Step 4
negin(X4 X5) Step 5
dropexist(X5 X6 1]) Step 6
dropall(X6 X7) Step 7
distrib(X7 X8) Step 8 clausiCy(X8 X9 [J) Step 9
ta(X) shysteps(X Xg)
(( Xg = II nl
print( yes it is always true) )
( nl nl printcl(X9))) Step 10a
tq(X) shy
steps(X Xg)
prques(Xg)
28
Step 2 Removing implic3tions amp Transforming exceptions and equiv3lences
rmimpl( P - Q (PI lt=gt (QI) ) amp ((PI) lt=gt QI) ) -
rmimpl(P PI) rmimpl(Q QI)
rmimplnp) lt=gt Q (PI lt=gt -(QI)) amp nPI) lt=gt QI) ) - 1
rmimpl(P PI) rmimpJ(Q QI)
rmimpJ(P lt-gt -(Q) (PI lt=gt -(QI)) amp nPI) lt=gt QI) ) -
rmimpl(P PI) rmimpl(Q QI)
rmimpl( P lt=gt Q PI lt=gt QI ) - I
rmimpl(P PI) rmimpl(Q QI)
rmimpl( P ==gt Q -(PI) v QI ) - I
rmimpl(P PI) rmimpl(Q QI)
rmimpl( all(X P) aI(X PI) ) - 1
rmimpl(P PI)
rmimpl( exists(X P) exists(X PI) ) -
rmimpl(P PI)
rmimpl( exists(I X P) exists(I X PI) ) -
rmimpl(P PI)
rmimpl( P amp Q PI amp Ql ) -
rmimpl(P PI) rmimpl(Q Ql)
rmimpl( P v Q PI v QI ) -
rmimpl(P PI) rmimpl(Q QI)
rmimpl( -(p) -(PI) ) - I
rmimpl(p PI)
rmimpl( P P )
St~p 3 Converting numerical amp distinctive quantifiers
L Numerical quantifiers
examples of input forms
1 exists(gt= i X pIX)) where i is an integer
2 exists(i X pIX)) where i is an integer
3 exists(i j X pIX)) where i j are integers and iltj
4 exists(il v i2 X pIX)) where is are integers
examples of output forms of this step
1 exists(X pIX) amp number(X gt= i) )
2 exists(X pIX) amp number(X i) ) 3 exists(X pIX) amp number(X ij) ) 4 exists(X pIX) amp number(X il v i2) )
II Distinctive quantifiers
27
example or input Corm
exists([XYL p(X Y))
example or output Corm or this step
exists(X exists(Y p(XY)) )
conv(P lt=gt Q PI lt=gt QI) - 1
conv(P PI) conv(Q QI)
conv(al1(X P) all(X PI)) -
conv(P PI)
conv(exists(HIT] P) R ) - conv(P PI) convert distinctive quantifier
convtdis(exists([HIT]PI) R)
conv( exists(I X P) exists(X PIamp number(X I) )) -
conv(P PI) convert numerical quantifier
conv(exists(X P) exists(X PI)) - 1
conv(P Pl)
conv(P amp Q PI amp QI) - 1
conv(P PI) conv(Q QI)
conv(P v Q PI v QI) - t conv(P PI) conv(Q QI)
convC(P) -(PI)) -
conv(P PI)
conv(P Pl
convtdis(existsl[XL P) exists(X P)) - atomic(X) convtdis(exists[XIYj Pl exists(X R)) shy
convtdis(exists(Y P) R)
Step 4 Rewriting compound predicates andor compound selectors
Outputs are smiple predicates andor simple selectors
rewrite(P lt=gt Q PI lt=gt QI) - t rewrite(P PI) rewrite(Q QI)
rewrite(all(X Pl all(X PI)) - 1 rewrite(P PI)
rewriteexists(X P) exists(X PI)) - I rewriteP PI)
rewrite(P amp Q PI amp QI) - rewrite(P P 1) rewrite( Q Q 1
rewrite(P v Q PI v QI) - 1
rewrite(P PI) rewrite(Q QI)
rewriteC(P) -(PI)) - I
28
rewrite(P PI) rewrite(F(A B) R) -
rewrite(A AI) rewrite(B BI) re(F(AI BI) R)
rewrite(F(A) R) -
rewrite(A AI) re(F(AI) H)
rewrite(F(A B C) R) -
rewrite(A AI) rewrite(B BI) rewrite(C CI) re(F(AI BI CI) R)
rewrite(F(A B C D) R) -
rewrite(A AI) rewrite(B Btl rewrite(C CI) rewrite(D DI) rc(F(AI BI CI Dl) H)
rewrite(PP)
re(F(A B v el (RI v R2) -
re(F(A Bl RIl re(F(A C) R2) reF(A B amp cl (RI amp R2)) -
re(F(A B) RI) re(F(A e) R2) re(F(A amp B C) (Rl amp R2)) -
re(F(A e) R 1) re(F(B C) R 2) re(F( v B el (R I v R2)) -
re(F(A el R I) reFB el R2) re(F(A amp Bl (R I amp R2)) -
re(F(A RI) re(F(BJH2) re(F(A v B) (R 1 v R2)) -
re(F(A) RI) re(F(B) R2)
re(F(A vB c Dl (RI v R2) -
re(F(A C D) RI) re(F(B C D) R2) re(F(A amp B C D) (RI amp R2)) -
re(F(A C D) Rll re(F(B C D) R2) re(F(A B v C D) (HI v R2)) -
re(F(A B D) RI) re(F(A C D) R2) re(F(A B amp C D) (HI amp R2)) -
re(F(A B D) RI) re(F(A C D) R2) re(F(A B C v D) (RI v R2)) -
re(F(A B C) R I) reF(A B D) R2) re(F(A B C amp D) (RI amp R2)) -
29
re(F(A B C) RI) re(F(A B D) RZ)
re(F(A v B e D E) (R I v R2)) -
re(F(A e D E) R I) re(F(B e D El R2) re(F(A amp B e D E) (RI amp RZ)) -
re(F(A e D El R 1) re(F(B e D E) R2) re(F(A B v e D E) (R I v R2)) -
re(F(A B D E) RI) re(F(A e D E) R2)
re(F(A B amp e D E) (RI amp R2)) -
re(F(A B D El RI) re(F(A e D E) RZ) re(F(A B e v D E) (R I v R2)) -
re(F(A B e El R 1) re(F(A B D E) RZ) re(F(A B e amp D E) (RI amp RZ)) -
re(F(A B e E) R I) re(F(A B D E) RZ)
re(F(A B e D vEl (RI v RZ)) - l
rc(F(A B C D) RI) re(F(A n e El RZ) re(F(A B e D amp El (RI amp RZ)) - ~
re(F(A B e D) RI) re(F(A B e El RZ)
re((A = B) (A = B)l-
re((A = Bl (A = 8)) -
retIA gt= BI (A gt= B)) -
re((A lt= B) (A lt= B)) -
re((A gt B) (A gt B))-
re((A lt Bl (A lt Bl)- re(A A)
Step) Bringing n(gation inwards
Degin(-(P) PI) - neg(P Pl)
negin(P lt=gt Q PI lt=gt Ql) - ~
negin(P PI) negiD(Q QI)
Degin(aU(X P) all(X PI)) - Degin(P PI) negin(exists(X P) exists(X PI))- negin(P PI) negin(P amp Q PI amp Ql) - Degin(P PI) negin(Q Ql)
Degin(P v Q PI v QI) - Degin(P PI) negin(Q QI) negin(P Pl
neg(-(P) PI) - negin(P PI)
neg(all(X P) exists(X PI)) - neg(P PI)
30
neg(exists(X P) all(X PI)) - neg(P PI)
neg(P amp Q PI v QI) - neg(P PI) neg(Q Ql)
neg(P v Q PI amp QI) - neg(P PI) neg(Q QI)
neg(P -(PH
Step 6 Dropping existnetial quanti6ers
dropexist(P lt=gt Q PI lt=gt QI Elerns) - dropexist(P PI Elerns) dropexist(Q QI Elerns)
dropexist(alJ(X P) all(XPI) Elerns)
dropexist(P PI [XIElernsJ)
dropexist(exists(X P amp nurnber(X Yraquo P2 Elerns) -
genfun(skn Newg) Fun = [NewgIElerns]
subst(FuD X P amp Dumber(X Y) PI)
dropexist(Pl P2 Elerns)
dropexist(exists(X P) PZ Elerns) -
genfun(skrn Newf) Fun = [NewfIElernsJ
subst(Fun X p PI)
dropex ist(P 1 P~ Elerns)
dropexist(P v Q PI v QI Elerns) - ~
dropexist(P PI Elerns) dropexist(Q Ql Elerns)
dropexist(P amp Q PI amp QI Elerns) - 1
dropexist(P Pl Elerns) dropexist(Q QI Elerns)
dropexist(P P _)
gen fun(R oot Newn arne) shy
getnurn(Root Nurn)
narne(Root Rootlist)
append(Rootlist[Nurnj Narnelist)
concat(Narnelist Newnarne)
getnurn(Root Nurn) shy
retract(currentnurn(Root Nurn 1 raquo
Nurn is Nurni + 1
asserta(currentnurn(Root Nurn))
getnurn(Root 1) - asserta(currentnurn(Root 1))
subst(New Old Val Val) - var(Val)
subst(New Old Old New) - 1 substNew Old Val Val) - atornic(Val)
31
subst(New Old Val Newval) shy
runctor(Val F N)
CUDctor(Newval F N)
subst_args(N New Old Val Newval)
subst_args(O J J - J J
subst_args(N New Old Val NewVal) shy
arg(N Val OldArg)
arg(N NewVal NewArg)
subst(New Old OldArg NewArg)
NI is N - I
subst_args(Nl New Old Val NewVal)
append([J L L) -
append([XILl] L2 [XIL3]) - append(Ll L2 L3)
Step - Dropping universal quantifiers
dropall(P lt=gt Q PI lt=gt QI)-
dropall(P PI) dropall(Q QI)
dropall(all(X P) PI) - ~ dropall(P PI)
dropall(P amp Q PI amp QI) -
dropall(P PI) dropall(Q QI)
dropall(P v Q PI v QI) -
dropall(P PI) dropall(Q QI)
dropall(P P)
Step 8 Distributing conjunctions over disjunctions
distrib(P lt=gt Q PI lt=gt Ql) - t distrib(P PI) distrib(Q QI)
distrib(P v Q R) -
distrib(P PI) distrib(Q QI)
distributing(PI v QI R)
distrib(P it Q PI it QI) -
distrib(P PI) distrib( Q QI)
distrib(P P)
distributing((P amp Q) v R PI amp QI) -
distrib(P v R PI) distrib(Q v R Ql)
32
distributing(P v (Q amp R) PI amp Ql) -
distrib(P v Q PI) distrib(P v R Ql)
distributing(P P)
Step 9 Packing each conjunction into clauses
c1ausify(P amp Q CI C2) -
clausiCy(P CI C3) c1ausify(Q C3 C2)
cbusiCy(P [d(A B)ICs] Cs) shy
inclause(P A [j B [I) 1
c1ausiry( C C)
inclause(P v Q A AI B B1) -
inc1ause(P A2 AI B2 Bl)
inclause(Q A A2 B B2)
inclausenp) A A B1 B) -
notin(P A) putin(P B B1)
inclause(P AI A B B) shy
notin(P Bl putin(P A AI)
notin(X [XU) - fail
notin(X [JLj) - notin(X L)
notin(X 1])
putin(X II [X]) - 1
putin(X [XILJ L) -
putin(X [YILJ [YILl]) - putin(X L Ll)
Step 1Oa Printing clauses
printcl([]) - nl nl
printcl(c1(AB)ICsj) - printcl(A Bl nl printcl(Cs)
printcl(L II) - printdis(IL) prinr)middot
printclHl L) - prin(contradiction(() printconl(rL)
print()) - ) printconj(rL) prinr )
printcl(Ll L2) shy
printdis(ILl) print( - ) printconj(rL2) prin()
printdis(S[Lj) - printcbar(SL)
33
printdis(S[LILs]) - printchu(SL) prin( v) printdis(SLs)
printconl(S[LI) - printchar(SL)
printconl(S[LILs]) - printchar(SL) prin( ) printconl(SLs)
printconj(S[L]) - tab(3) printchar(SL)
prin tconj( S [L IL sl) shy
tab(3) printchar(SL) print( ) printconj(SLs)
printchar(SP) shy
atomic(P)
name(P L)
L = [IT]
concat([XIT NewP)
prin(~ewP)
printchar(SP) shy
atomic(P)
prin(P)
printchar(SA lt= gt B) -
prin((l clausify(A AI [j) pl(eAl) prin())
print lt=gt )
prin(() cbusify(B Bl [I) pJ(eBl) prine))middot
printchar(rnumber(X N)) shy
prin(num() printchar(rx) prin( )
printchar(rN) prinC))
printchar(rF(A B)) shy
seJec(F(A B))
prinCsel() printchar(rA)
prin( F ) printchar(rB) prinC))
printchar(SF(A B)) shy
( selec(F(A B)) F = infix )
printchar(SA) prin( F ) printchar(SB)
printchar(SF(A)) shy
(F= prefix gt= F= prefix lt= F= prefixgt F= prefix lt )
prin(F ) printcbar(SA)
printchar(SP) shy
functor(P F MaxN)
prin(F ()
Nl is MaxN - 1
putout(S N 1 P MaxN)
34
prin())
putout(S 0 P MaxN) -
arg(~laxN P Argu)
prin tchar(SArgu)
putout(S N p MaxN) shy
Nt is MaxN - N arg(NI P Argu)
printcbar(SArgu )
prin( )
N2 is N - 1
putout(S N2 P MaxN)
selec(FA B)) shy
( F= infix = F= infix f= F= infix gt=
F= infix gt F= infix lt= F= infix lt )
35
----------------------------------Program Name APClS - Part 2 Inference Mechanism ---------------------------------- a(X) shy
steps(X X9)
(( X9 =[] nl
print( yes it is always true) )
( X9 =[cI(IJ[])] nl
print( no it is always false) )
( nl nl printel(X9) Step 1Oa
tell(temp_file) printel(X9) e1ose(temp_file) consult(temp_6Ie) ))
q(X) shy
asserta( in pt(X))
steps(X X9)
(( X9 = [] print(middot~H~~middot~t~)
print(THE AiSWER IS YES)
print( ilgIQlQl(~) )
( X9 = [e1([j [j)] Pr1nt ( OJ fi(i I~ iii Ij)middot(i)(i) fiyenQ)riiio(i)(ij)(i)fj)fiyen1li1il1li1il)__ gtw~ __~_~ _~~_ ~_-=~
print(THE ANSWER IS NO ) print() )
( teI1(temp_6Ie)
prques(X9) Step 1Ob
close(temp_file)
nl print(Let me think about it) nl
consult(temp_6Ie) ))
retrac t( in pt(X))
Step lOb Printing question
prques(lcl(A 8)1) - prin(goo(() pl(qA 8) print()))
prques([c1(A 8HCs]) - prin(goo(() pl(qA 8) print() pl(q Cs)
pl(e [c1(A 8)]) - pl(eA 8)
pl(q [c1(A 8)]) - pl(qA 8) print()))
pl(S [e1(A B)ICs]) - pl(SA B) prin( ) pl(S Cs)
38
pl(q [j L) - prin(c1ause(contradiction(() pcont(qL) prin())_))
pl(S [I L)- prin(so2(contradidion(() pcont(SL) print))))middot
pl(S [L] []) - prin(so2() pcbar(SL) prin())
pl(S L [J)- prinsol() plett(SL) print))
pl(S [L] LI) - prin(condi(() pchar(cL)
prin(() pcont(S Ll) prine))))
pl(S L Ll)- prin(c1ause() plert(cL)
prin(() pcont(S Ll) prine)))
plert(S[LJ) - pchar(SL)
plert(SjLILsj) - pcbar(SL) print v) pleCt(SLs)
pcont(S[L]) - pchar(SL)
pcont(S[LILsj) - pcbar(SL) prinr ) pcont(SLs)
pcbar(SP) shy
atomic(P)
name(PL)
( L = [IT] L = [5 k miT] L = [5 k niT] )
concat[XITj NewP)
prin(0JewP)
pchar(SP) shy
atomic(P)
prin(P) pchar(SA lt=gt B) -
prin(() dausify(A AI []) pl(eAI) prin())
prinr lt=gt ) prin(() dausify(B BI ]) pl(eB) print))
pchar(Snumber(X N)) shy
prin(num() pchar(SX) prin()
pchar(SN) prinr))
pcbar(SM N) - prin(M N)
pcbar(cF(A B)) shy
selec(F(A Braquo
pcbar(cA)
prine F ) pchar(cB) pchar(SF(A B)) shy
selec(F(A B))
prin(sel() pchar(SA)
print F ) pchar(SB) print)) I
31
pc har(SF(A)) shy
( F= prefix gt= F= prefix lt= F= prefixgt F= prefix lt )
prin(F ) pchar(SA)
pchar(SP)shy
runctor(P F MaxN)
prin(F ()
011 is MaxN - 1 pout(SNl P MaxN)
print) )
pout(S 0 P M3xN) - 1
arg(~bxN P Argu)
pchlr(SArgu )
pout(S N P MaxN shy
Nl is MaxN - N
arg(Nl P Argu)
pchar(SArgu
prin( )
N2 is N - 1
pout(S N2 P ~13xN)
Comparing numbers in numerical quantifiers
num(XN) shy
number(X I)
cnum(N 1) ~
cnumlaquo=01 lt=I- N gt=I
cnumlaquo=J lt I) - N gt=1-1
cnumlaquo=NIJ) - N gt=J 1
cnumlaquo=N J)- integer(I) N gt=I~
cnum(gt=N gt=1) - N lt=1
cnum(gt=N gt I) - N lt=1+ 1 cnum(gt=NIJ) - N lt=1
cnum(gt=N lt=1)- N lt=1
cnum(gt=N lt I) - N lt=1 L cnum(gt=N 1)- integer(I) N lt=1
cnum( lt N lt 1)- N gt=1 L
38
cnum( lt N lt=1) - N gt I cnum( lt NLJ) - N gt J
cnum( lt N 1)- integer(I) N gt 1
cnum(gt N gt I) - N lt=1 cnumlgt i gt=1) - N lt I
cnum(gt N lt=1) - N lt=0
cnum(gt N lt I) - N lt=0
cnum(gt iIJ) - N lt I cnum(gt N 1)- integer(I) N lt I
cnum(~LN lt=1) - M=I N gt= I l
cnum(~LN lt I) - M=l N gt= I-I
cnum(~LNLJ) - M lt =1 N gt = J
cnum(~1N 1)- integer(I) M lt= I N gt= I
cnum(- N) - integer(N)
Comparing selectors
sel(X = Y) shyX= Y
sel(X I=Y) shy(X I=Y X lt Y Xgt Y)
sel(X gt Y) shyXgt Y
sel(X lt Y) shyXlt Y
selX gt=Y) shy(X gt=Y X= Y Xgt Y)
se(X lt=Y) shy
(X lt=Y
X= Y
X lt Y)
csel(infix = infix =)
39
csel(infix = infix = csel(infix = infix gt)
csel(infix = infix lt) csel(infix gt infix gt) cseJ(infix lt infix lt) csel(infix gt= infix gt=) csel(infix gt= infix gt csel(infix gt= infix =)
csellinfix lt= infix lt=) csel(infix lt= infix lt) csel(infix lt= infix =)
Finding solutions
sol(X v Y) -
(( notetra(X) eon(X) ( sol(Y) )
( c1ause(P v Q R) not(cketra(P v Q))
dis(P v Q X v Y R) ~ )
( A lt=gt B equival(A lt=gt B X v Y) ~ I) sol(X) - ~ notetra(X) eon(X)
so~(X) - notetra(X)
( con (X)
( clause(P v Q R) not(ekctra(P v Q)) dis(P v Q X R) I)
cketra(P v Q) -
eketra(P) eketra(Q) eketra(F(I J)) shy
selec(F(I J))
c1ause(contradiction(sel(F(IJ))) _I
eketra(number(W I)) -
clause(cootradietion(num(Wl)) - eketr(P) shy
clause(contradiction(P) - 1
notctra(P) shy
not( e lause( con tradiction(P) _))
40
Searching (or disjunctions
dis(P v Q X v Y R) - dis(P X v Y R)
dis(Q X v Y R) con(R)
dis(P v Q X R) -
dis(P X R) dis(Q X R) con(R
dis(P X v Y R) - clause(contradicton(Pl J 1
dis(F(I J) sel(G(I J)) v Y R) - csel(G Fl dis(number(WI) num(W N v Y R) - cnum(N I)
dis(P P v Y R) -
dis(P X v Y R) - dis(P Y R)
dis(F(I J) seJ(G(IJ)) R) - csel(G F)
dis(number(WI) num(WN) R) - cnum(N I) dis(P P R) - 1
dis(FJ J X R) shy
( ckctra(F(IJ) cbeckeq(seJ(F(IJ))) )
dis(number(W Il X R) - ( ckctra(number(WI)) cbeckeq(num(WI)) )
dis(P X R) shy( ckctra(P) cbeckeq(P) ) 1
cbeckeq(P) shy
(( A lt=gt so2(contradiction(P))
bagof(A A [jj) ) ( so2(contradiction(P)) lt=gt B
bagof(B B Uj) ))
ckeq(A) shy
( so2(A) lt=gt B B lt=gt so2(A) ) bagof(B B UJ)
con((P Q)) -
clause(P R) con(R) con(Q) con(true) -
con(contradiction(P)) - clause(contradiction(P) J
con(cause(X Y)) - cause(X Y)
con(sel(X)) - sel(X)
con(num(X Y)) - num(X Y) con(P)- (( dause(P R) (con(R) ckeq(R)))
colJectin(P) )
collectin(P) shy
bagof(S (c1ause(P S) S = true) [L LIJ )
mkcon(L Ll L)
bagor(l (L2 ) UJ) L
mkcon((A AI) (B B1) (sol(A v B) e D)) -
mkcon(A B1 e) mkcon(A1 (B Bl) D)
mkcon(A (B B1) (sol(A v B) e)) -
mkcon(A Bl e)
mkcon((A AI) B (sol(A v B) e)) middot1
mkcon(Al B e)
mkcon(A B sol(A vB))
Searching ror equivalences
equival(A lt=gt B X v Y) - 1 ( equival(A lt=gt B X) equival(A lt=gt B Y) )
equival(s02(A) lt=gt 502(B) A) - clause(B _I equival(s02(B) lt=gt 502(A) A) c1ause(B _I
Top level or inrerence mechanism
goo((s02(whatnum) P)) -
getatm(P Xl
bagor(number(X Y) ( P so2(number(X Y)) ) A )
count1(A 00 L R) nl
bagor(X P B )
count2(B L R Ll Rl) nJ print()
(( LI = 0 Rl = 0 print(THE ANSWER IS ) nl
(( Ll = Rl prin(-Jumber or ) prn(P) print(is Ll) )
( Rlgt20000 prin(Number or I prn(P) print(is LI or more) )
42
( prin(Number of ) pfn(P) print( is from Ll to Rl) )) )
( print(THE ANSWER IS NO I )) print()
goo(X) shy
(( bagof(X X L) L = [I nl print()
print(THE ANSWER IS YES) nl wout(L) print() )
( equiv(X L) nl print()
print(THE ANSWER IS YES) nl wout(L) print(-) )
( c1ause(inpt(A ==gt B) _I ( impli(A B Z) impli(B A Z) ) print(l~Hl)
printTHE ANSWER IS YES) nl print(Z) print(Hj~(fH~) ))
goo(X) print( Hg)
print(THE ANSWER IS NO ) print( lH~lH~gg9l9lmiddotmiddot~Q(gmiddot)
00 Semhing for implications in equiV3lent relations
impli( B Z) shyt-ell( z1) prin(templ() pchn(S A lt=gt B) print()) close ( zl) consult(zl) templ(Z)
unload zl Z
Searching for equivalence
equiv (X L)
(( X lt=gt Y
equ(Y YI)t bagof(Y Yl L) L = [j )
(Y lt=gt X equ(Y YI) bagof(Y Yl L) L = [J )
( X = F(New)
clause(~ew T) makeup(T Tl)
(( Tl lt=gt B
equ(B Bl) bagof(Bl Bl M) M = [j L=[Newl )
(A lt=gt TI
equ(A AI) bagof(Al AI M) M = 1] L=INewj )) ))
makeup((A B) (AI Bl)) -
makeup(A A1) makeup(B BI)
makeup(A so2(A))
equ((A B) (AI BI)) -
equ(A AI) equ(B Bl)
equ(sol(X v Y) sol(XI v Yl)) -
equ(X XI) equ(Y YI)
equ(so2(X) so2(XI)) -
equ(X XI)
equ(contradiction(X) clJuse(contradiction(X) X) ) -
equ(X X)
Counting numbers
getatm((A B) X) -
( getatm(A X) getatm(B X) )
getatm(so2(F(X)) X) -
getatm(so2(X) X) - atom(X)
countl([J L R L R) -
countl([number(X Y)IT] L R L2 R2) shy
(( Y = (gt=~) LI is L + N Rl is R + 20001 l )
( Y = (gt N) LI is L+ N+ 1 RI is R + 20002 )
(Y == laquo=~) LI is L + 1 Rl is R + N )
(Y = laquo N) LI is L + 1 RI is R+N-I)
(Y == IJ LI is L + I Rl is R + J ) ( Y == N L1 is L + N RI is R + N ))
count1(T LI R 1 L2 R2)
count2(fJ L R L R) - 1
count2([XITJ L R L2 R2) shy
name(X Xl)
(( Xl = sknj LI is L Rl is R )
44
( Xl = Iskmj L1 is L + 1 RI is R + ZOOO1) ( LI is L + I RI is R + I ))
count2(T LI RI L2 R2)
pfn((A B)) - pfn(A) prn(B)
pCn(so2(F(X))) - prin(F )
prn(so2(X)) - atom(X) prin(X ) prn (so2(X))
Printing result
wout([XlJ - prt(X) nl woutf[xIY]) - prt(X) nl nl wout(Y)
prt(e(A B)) -
prt(A) prinr 8 ) prt(ltE) prt(eA) - prt(A)
prt(c(A EJ) - prin() prt(A) prine ) prt(B) prin(T)
prt(c A) - prt(A) prt((A E)) - ~
prt(A) nl prt(E) prt(sol(X v Y)) - ~
prt(X) prinC v) prt(Y) prt(A lt=gt B) -
prt(e A) prinC lt=gt ) prt(e B) prt(sol(X)) - prt(X)
prt(so2(X)) - prt(X
prt(c1ause(X Y)) - prt(X)
prt(contradiction(X)) - prin(contradiction() prt(cX) prinr))middot prt(num(XY)) - prin(number(X Y)) prt(sel(X)) - prin(X) prt(X v Y) - prt(X) prin( v) prt(Y) prt(X) prin(X)
Handling conditional queries
condi((Y Xl) shy
assertcon(X) Y
45
retractcon(X)
condi((B A))
retractcon(A) fail
assertcon((A B)) 1
assertcon(A) assertcon(B)
assertcon(A) asserta(A)
retrac teon ((A B)) 1
retracteon(A) retractcon (B)
retraetcon(A) - retract(A)
BIBLIOGRAPHIC DATA SHEET
Report No UIUCDS-F-84-928
3 Recipients Accession No
4 T ide and Subt ltle
An Annotated Predicate Calculus Inference System (APCIS)
S Report Date
November 1984 6
7 Author(s)
Kah-Eng Pua 8 Performing Organization Rept
No
9 Performing Organization Name and Address
Department of Computer Science University of Illinois Urbana IL
10 ProjectTaskWork Unit No
11 Contract Grant No NSF DCR 84-06081 ONR N00014-82-K-0186
12 Sponsoring Organization Name and Address
National Science Foundation Washington DC
13 Type of Report amp Period Covered
14
15 Supplementary Notes
16 Abstracts
This paper describes a deductive inference system called APCIS (Annotated Predicate Calculus Inference System) APCIS is able to carry out inferences from expressions involving numerical quantifiers selectors disjunctions of non-negated terms negated terms disjunctions of negated terms equivalences and exceptions It is also able to count the numbers of occurrence of a given simple term or a conjunction of terms The design of contradiction and the treatment of the disjunction of non-negated terms allow APCIS to accept Horn clauses as well as non-Horn clauses and to carry out inferences from them This feature makes APCIS more general than Prolog
17 Key lords and Document Analysis 170 Descriptors
APC (Annotated Predicate Calculus) APCIS (Annotated Predicate Calculus Inference System) Horn Clause Numerical Quantifier Prolog Selector
17b IdentifiersOpen-Ended Terms
17c COSATI FieldGroup
18 Availability Statement 19 Security Class (This
Re~f~~IA~SIF IFf)
21 ~o of Pages
49 211 ecurity Class (This
PageUNCLASSIFIED
22 Price
FOA NTIS n (10middot70 usco-oc 40329-
15
APCIS with the aid of equlv will be able to answer yes to this query
41 lmpll
lmpll can be considered as the last attempt that APCIS would make to satisfy a
query It is activated only after equlv has failed It will first check if the query is conditional If
so it will convert the implication symbol to equivalence symbol and search if such an equivalent
relation can be found in the database If so a success Otherwise a failure
5 More on the Inference Mechanism
Having looked at all the subparts at the top two levels of the inference mechanism we
are ready to look at other subparts at lower levels
51 num and cnum
One distinct fe3ture or APCIS is its ability to deal with numerical quantifications As
mentioned in Section 31 input queries and assertions will undergo different transformations in
the last step (Step 10) of translation This also holds true for expressions involving numerical
quantifications Consider the following expression
exists( 6 X horse(X) )
If it is entered to Prolog via assertion mode we will after going through all the steps of
translation have the rollowing entered to the database
horse(sk n I
number(sknl6)
Now if we want to ask Are there more than five horses 7 and type in
q( exists( gt5 X horse(X) ) )
1amp
APCIS will translate the question and enter to Prolog the following query
goo(( s02( horse(X) ) s02( num( X gt5 )) ))
Note that the term number(slml 6) in the database and the term num(X gt S) in the query are
different predicates and this difference is exactly where the power of the clause num(X N)
defined in APCIS comes from When the clause num(X N) in APCIS is activated it will search
through the database to see if there is any term of the form number(X I) whose first argument
matches the first argument of num(X Y) in the query It a match is found the second arguments
of both num(X Y) in the query and number(ltI) in the database will be passed to cnum in
APCIS
The job of cnum is to compare the numerical messages carried by the second
argument or the term rlum(X Y) in the query and the second argument of the term rlumber(X I)
in the database to see if they match with each other according to the rules defined in cnum
While there are 25 rules for such matching purposes the idea is simple
Imagine that the second argument Y of the term num(X Y) in the query
and the second argument I of the term num()( I) in the database each occupies a
place in an integer line (Le the integer line in mathematics) To have a match
the domain covered by Y should contain the domain covered by L
As an example the answer to the above query is positive since the domain of gt5
contains the domain or 6
Before closing this section we will bring out a speciaJ translation aspect of expressions
involving numbers by an example We first type to APCIS the Collowing expressions in assertion
mode
1 aU(X all(Y father(X Y) amp number(Y gt6) ==gt has_manY3hildren(X) ))
2 exists(X exists( 12 Y Cather(X Y) ) )
11
After going tbrougb all tbe translation steps tbe Collowing two expressions will be entered to tbe
database
I
bas_many_cbildren( Xl ) shy
Cather( Xl X2 )
num( X2 gt6 )
2
Catber( sk m1 sk n2 )
number( skn2 12 )
lotice that whenev(gtr a term with Cunctor number appears at the rigbt-band side oC a Prolog
clause its Cunctor will be cbanged to num automatically This treatment will greatly cnbance tbe
inference power of the clause sbown in l above For instance iC we now ask tbe question
q( exists( X bas_many_children(X) ) )
The right hand side oC the clause l will match the two terms in 2 and tbe query succeeds
52 Bel and cael
A special feature of APe is tbat all predicates tbat express relations = = gt
gt= lt and lt= can be expressed explicitly using infix notations as relational statements
called selectors To handle selectors we defined Bel in APCIS
Every expression involving selectors will undergo different translations in assertion mode
and query mode For example the assertion
a( exists( [X Y] box (X) amp box(Y) amp (weigh t(X) gt weight(Y) ) ) )
will be translated into the following three terms and entered to tbe database
box( skml )
box( skm2 )
18
weight( skm 1 ) gt weight( skm2 )
Now it we want to ask Is it true that there exists two boxes of different weights and type in
q( exists( [X Yl box(X) amp box(Y) amp ( weight(X) = weight(Y) ) ) )
The question will be transformed to the following query and entered to Prolog
goo(( so( box(XI) ) s02( box(X2) ) so2( sel( weightXI) = weight(X2) )) ))
Note that the selector in the above query is surrounded by the functor set When any clause or
8el in APCIS is activated it will search through the database to see it there is any selector whose
two arguments (left and right side or any selector symbol) match the two arguments of the
selector in the query At the same time 8el will check iC the selector symbols (may be different) or
the two different selectors (one in the query and one in the database) satisfy the rules defined in
sel There are 12 matching rules defined in sel All oC them ~re straightforward and will not be
discussed here An example will be enough to explain how 8el works
Consider the execution of the above transformed query The first two terms in the query
are satisfied by the first two terms in the database and Xl and X2 are instantiated to skml and
skm2 respectively The third term of the query will be passed to eel (of APCIS) which finds a
match on each side of the two selectors (one in the query and one in the database) At the same
time the two different selector symbols gt and = are found to satisfy one of the rules in
8el As a result the query succeeds
To enhance the inference power of clauses involving selectors all the selectors appearing
on the rightmiddothand side oC any clause will be surrounded by a functor set The idea is similar to
that in the last part of the previous section
c8el is exactly the same as 8el functionally It provides a convenient way to compare
selectors when dis is being executed
19
8 Printing Result
Whenever a goal is successfully executed APCIS will not only response with a yes but
also print out the matched terms or clauses in the database This is made possible by the built-in
function bagor and the two predicates wout and prt defined in APCIS
7 Summary
In this paper a description of a deductive inference system called APCIS (Annotated
Predicate Calculus Inference System) has been provided APCIS is able to carry out inferences
from expressions involving numerical quantifiers selectors disjunctions of non-negated terms
negated terms disjunctions of negated terms equivalences and exceptions It is also able to count
the numbers of occurrence of a given simple term or a conjunction of terms
The main idea of APCIS is that each input APC expression is first passed to a
preprocessor ( ie APC translator ) which dissolves and transforms each APC expression into
Prolog expression(s) which will then be loaded to Prolog system The user bas to specify whether
each input expression is to be entered as an assertion or as a query by invoking either assertion
mode or query mode respectively Each assertion or query will undergo different transformations in
the preprocessor The different treatment of assertion or query not only allows a full uS1ge of the
Prolog inference mechanism but also makes possible a higher level of inexact pattern matching
exemplified by the examples in Section 51 and Section 52 where the four predicates num
cnum sel and csel are discussed This higher level of pattern matching increases the inference
power of APCIS greatly
The design of contradiction and the treatment of the disjunction of non-negated terms
allow APCIS to accept non-Horn clauses and to carry out inference from them This feature
makes APCIS more general than Prolog
20
While APCIS performs very well in many sets of arguments provided by the author it is
still too early to jump to conclusion that it can perform equally well in all types of problems In
any event the expressiveness of APC has greatly been retained in the present version of APCIS
and moreover some design ideas or APCIS mentioned in this paper are not restricted to APCIS
- they may be carried over to learning programs with narrower scopes
21
References
[1] W F Clocksin and C S Mellish Programming In Prolog Springermiddot Verlag Berlin Hpoundidelberg 1981
[2] R S Michalski A Theory and Methodology of Inductive Learning Chpt 4 Machine L earning Tioga Publishing Co Palo Alto CaliJornia 1989
[3] K-E Pua Translating Annotated Predicate Calculu8 to Prolog ISG Report 84middot1 UlUCDCSmiddotFmiddot918 University oj Illinois Urbana IL June 1984
22
Appendix A
APCIS Users Manual
1 Get Started
Users are urged to follow the steps depicted below
1 Get the PROLOG interpreter by typing
alias prolog mntb2sammutsammutprologprolog (Vax A)
or
alias prolog mntb2sammutsammutbinprolog (Vax B)
2 Load apc and infer by typing
prolog apc infer
When large APC expressions are expected we can increase the stlck by typingI
prolog -snnnn ape infer
where ns denote the number of stacks in decimal
3 When the wording LSW - PROLOG appears on the terminal we are reldy to interact
with APCIS The four modes by which we can invoke APCIS are summarized below
a Assert ion-Translation Mode
ta(X)
b Query-Translation Mode
tq(X)
c Assertion Mode
a(X
d Query Mode
q(X)
23
where Xs are APC expressions
2 Notations Used in APCIS
Below is a summary or notations used in APCIS
a Logical operators
amp
v
==gt
lt=gt
-
negation
conjunction
disjunction
implication
equivalence
exception
b Binary relation symbols in selectors
-
=
gt=
lt=
gt
lt
equal
not equal
greater or equal
smaller or equ al
greater
smaller
c Relational operators in numerical quantifiers
lt less than
lt= less than or equal
gt greater than
gt= greater than or equal
d BinlTY operator in numerical quantifier
range
e Universal quantifier
all(X p(X))
f Existential quantifier
exists(X p(X))
g Numerical quantifier
exists(I X p(X))
where p(X) is a formula
where X is a variable or a Jist of variables or the
form [HI~rj and p(X) a formula
where I repersents expression involving integer(s)
and operator(s) in c or d above and p(X) a formula
25
Appendix B
APCIS Program Listings
------------------------------- Program Name APCIS - Part 1 APC Translator
-------------------------------
op(3OO fx -)1
op(500 xfy amp)
oPt 500 xfy v)
op(600 xfx )
op(700 fx [gt= lt= gt lt ]) op(400 xfy [= gt= lt= gt lt ])1 op(900 xfy gt lt=gt -])1
steps(X Xg) shy
numbervars(X 1 J Step 1 change variables to iis
rmimp(X X) Step 2 conv(X X3) Step 3
rewrite(X3 X4) Step 4
negin(X4 X5) Step 5
dropexist(X5 X6 1]) Step 6
dropall(X6 X7) Step 7
distrib(X7 X8) Step 8 clausiCy(X8 X9 [J) Step 9
ta(X) shysteps(X Xg)
(( Xg = II nl
print( yes it is always true) )
( nl nl printcl(X9))) Step 10a
tq(X) shy
steps(X Xg)
prques(Xg)
28
Step 2 Removing implic3tions amp Transforming exceptions and equiv3lences
rmimpl( P - Q (PI lt=gt (QI) ) amp ((PI) lt=gt QI) ) -
rmimpl(P PI) rmimpl(Q QI)
rmimplnp) lt=gt Q (PI lt=gt -(QI)) amp nPI) lt=gt QI) ) - 1
rmimpl(P PI) rmimpJ(Q QI)
rmimpJ(P lt-gt -(Q) (PI lt=gt -(QI)) amp nPI) lt=gt QI) ) -
rmimpl(P PI) rmimpl(Q QI)
rmimpl( P lt=gt Q PI lt=gt QI ) - I
rmimpl(P PI) rmimpl(Q QI)
rmimpl( P ==gt Q -(PI) v QI ) - I
rmimpl(P PI) rmimpl(Q QI)
rmimpl( all(X P) aI(X PI) ) - 1
rmimpl(P PI)
rmimpl( exists(X P) exists(X PI) ) -
rmimpl(P PI)
rmimpl( exists(I X P) exists(I X PI) ) -
rmimpl(P PI)
rmimpl( P amp Q PI amp Ql ) -
rmimpl(P PI) rmimpl(Q Ql)
rmimpl( P v Q PI v QI ) -
rmimpl(P PI) rmimpl(Q QI)
rmimpl( -(p) -(PI) ) - I
rmimpl(p PI)
rmimpl( P P )
St~p 3 Converting numerical amp distinctive quantifiers
L Numerical quantifiers
examples of input forms
1 exists(gt= i X pIX)) where i is an integer
2 exists(i X pIX)) where i is an integer
3 exists(i j X pIX)) where i j are integers and iltj
4 exists(il v i2 X pIX)) where is are integers
examples of output forms of this step
1 exists(X pIX) amp number(X gt= i) )
2 exists(X pIX) amp number(X i) ) 3 exists(X pIX) amp number(X ij) ) 4 exists(X pIX) amp number(X il v i2) )
II Distinctive quantifiers
27
example or input Corm
exists([XYL p(X Y))
example or output Corm or this step
exists(X exists(Y p(XY)) )
conv(P lt=gt Q PI lt=gt QI) - 1
conv(P PI) conv(Q QI)
conv(al1(X P) all(X PI)) -
conv(P PI)
conv(exists(HIT] P) R ) - conv(P PI) convert distinctive quantifier
convtdis(exists([HIT]PI) R)
conv( exists(I X P) exists(X PIamp number(X I) )) -
conv(P PI) convert numerical quantifier
conv(exists(X P) exists(X PI)) - 1
conv(P Pl)
conv(P amp Q PI amp QI) - 1
conv(P PI) conv(Q QI)
conv(P v Q PI v QI) - t conv(P PI) conv(Q QI)
convC(P) -(PI)) -
conv(P PI)
conv(P Pl
convtdis(existsl[XL P) exists(X P)) - atomic(X) convtdis(exists[XIYj Pl exists(X R)) shy
convtdis(exists(Y P) R)
Step 4 Rewriting compound predicates andor compound selectors
Outputs are smiple predicates andor simple selectors
rewrite(P lt=gt Q PI lt=gt QI) - t rewrite(P PI) rewrite(Q QI)
rewrite(all(X Pl all(X PI)) - 1 rewrite(P PI)
rewriteexists(X P) exists(X PI)) - I rewriteP PI)
rewrite(P amp Q PI amp QI) - rewrite(P P 1) rewrite( Q Q 1
rewrite(P v Q PI v QI) - 1
rewrite(P PI) rewrite(Q QI)
rewriteC(P) -(PI)) - I
28
rewrite(P PI) rewrite(F(A B) R) -
rewrite(A AI) rewrite(B BI) re(F(AI BI) R)
rewrite(F(A) R) -
rewrite(A AI) re(F(AI) H)
rewrite(F(A B C) R) -
rewrite(A AI) rewrite(B BI) rewrite(C CI) re(F(AI BI CI) R)
rewrite(F(A B C D) R) -
rewrite(A AI) rewrite(B Btl rewrite(C CI) rewrite(D DI) rc(F(AI BI CI Dl) H)
rewrite(PP)
re(F(A B v el (RI v R2) -
re(F(A Bl RIl re(F(A C) R2) reF(A B amp cl (RI amp R2)) -
re(F(A B) RI) re(F(A e) R2) re(F(A amp B C) (Rl amp R2)) -
re(F(A e) R 1) re(F(B C) R 2) re(F( v B el (R I v R2)) -
re(F(A el R I) reFB el R2) re(F(A amp Bl (R I amp R2)) -
re(F(A RI) re(F(BJH2) re(F(A v B) (R 1 v R2)) -
re(F(A) RI) re(F(B) R2)
re(F(A vB c Dl (RI v R2) -
re(F(A C D) RI) re(F(B C D) R2) re(F(A amp B C D) (RI amp R2)) -
re(F(A C D) Rll re(F(B C D) R2) re(F(A B v C D) (HI v R2)) -
re(F(A B D) RI) re(F(A C D) R2) re(F(A B amp C D) (HI amp R2)) -
re(F(A B D) RI) re(F(A C D) R2) re(F(A B C v D) (RI v R2)) -
re(F(A B C) R I) reF(A B D) R2) re(F(A B C amp D) (RI amp R2)) -
29
re(F(A B C) RI) re(F(A B D) RZ)
re(F(A v B e D E) (R I v R2)) -
re(F(A e D E) R I) re(F(B e D El R2) re(F(A amp B e D E) (RI amp RZ)) -
re(F(A e D El R 1) re(F(B e D E) R2) re(F(A B v e D E) (R I v R2)) -
re(F(A B D E) RI) re(F(A e D E) R2)
re(F(A B amp e D E) (RI amp R2)) -
re(F(A B D El RI) re(F(A e D E) RZ) re(F(A B e v D E) (R I v R2)) -
re(F(A B e El R 1) re(F(A B D E) RZ) re(F(A B e amp D E) (RI amp RZ)) -
re(F(A B e E) R I) re(F(A B D E) RZ)
re(F(A B e D vEl (RI v RZ)) - l
rc(F(A B C D) RI) re(F(A n e El RZ) re(F(A B e D amp El (RI amp RZ)) - ~
re(F(A B e D) RI) re(F(A B e El RZ)
re((A = B) (A = B)l-
re((A = Bl (A = 8)) -
retIA gt= BI (A gt= B)) -
re((A lt= B) (A lt= B)) -
re((A gt B) (A gt B))-
re((A lt Bl (A lt Bl)- re(A A)
Step) Bringing n(gation inwards
Degin(-(P) PI) - neg(P Pl)
negin(P lt=gt Q PI lt=gt Ql) - ~
negin(P PI) negiD(Q QI)
Degin(aU(X P) all(X PI)) - Degin(P PI) negin(exists(X P) exists(X PI))- negin(P PI) negin(P amp Q PI amp Ql) - Degin(P PI) negin(Q Ql)
Degin(P v Q PI v QI) - Degin(P PI) negin(Q QI) negin(P Pl
neg(-(P) PI) - negin(P PI)
neg(all(X P) exists(X PI)) - neg(P PI)
30
neg(exists(X P) all(X PI)) - neg(P PI)
neg(P amp Q PI v QI) - neg(P PI) neg(Q Ql)
neg(P v Q PI amp QI) - neg(P PI) neg(Q QI)
neg(P -(PH
Step 6 Dropping existnetial quanti6ers
dropexist(P lt=gt Q PI lt=gt QI Elerns) - dropexist(P PI Elerns) dropexist(Q QI Elerns)
dropexist(alJ(X P) all(XPI) Elerns)
dropexist(P PI [XIElernsJ)
dropexist(exists(X P amp nurnber(X Yraquo P2 Elerns) -
genfun(skn Newg) Fun = [NewgIElerns]
subst(FuD X P amp Dumber(X Y) PI)
dropexist(Pl P2 Elerns)
dropexist(exists(X P) PZ Elerns) -
genfun(skrn Newf) Fun = [NewfIElernsJ
subst(Fun X p PI)
dropex ist(P 1 P~ Elerns)
dropexist(P v Q PI v QI Elerns) - ~
dropexist(P PI Elerns) dropexist(Q Ql Elerns)
dropexist(P amp Q PI amp QI Elerns) - 1
dropexist(P Pl Elerns) dropexist(Q QI Elerns)
dropexist(P P _)
gen fun(R oot Newn arne) shy
getnurn(Root Nurn)
narne(Root Rootlist)
append(Rootlist[Nurnj Narnelist)
concat(Narnelist Newnarne)
getnurn(Root Nurn) shy
retract(currentnurn(Root Nurn 1 raquo
Nurn is Nurni + 1
asserta(currentnurn(Root Nurn))
getnurn(Root 1) - asserta(currentnurn(Root 1))
subst(New Old Val Val) - var(Val)
subst(New Old Old New) - 1 substNew Old Val Val) - atornic(Val)
31
subst(New Old Val Newval) shy
runctor(Val F N)
CUDctor(Newval F N)
subst_args(N New Old Val Newval)
subst_args(O J J - J J
subst_args(N New Old Val NewVal) shy
arg(N Val OldArg)
arg(N NewVal NewArg)
subst(New Old OldArg NewArg)
NI is N - I
subst_args(Nl New Old Val NewVal)
append([J L L) -
append([XILl] L2 [XIL3]) - append(Ll L2 L3)
Step - Dropping universal quantifiers
dropall(P lt=gt Q PI lt=gt QI)-
dropall(P PI) dropall(Q QI)
dropall(all(X P) PI) - ~ dropall(P PI)
dropall(P amp Q PI amp QI) -
dropall(P PI) dropall(Q QI)
dropall(P v Q PI v QI) -
dropall(P PI) dropall(Q QI)
dropall(P P)
Step 8 Distributing conjunctions over disjunctions
distrib(P lt=gt Q PI lt=gt Ql) - t distrib(P PI) distrib(Q QI)
distrib(P v Q R) -
distrib(P PI) distrib(Q QI)
distributing(PI v QI R)
distrib(P it Q PI it QI) -
distrib(P PI) distrib( Q QI)
distrib(P P)
distributing((P amp Q) v R PI amp QI) -
distrib(P v R PI) distrib(Q v R Ql)
32
distributing(P v (Q amp R) PI amp Ql) -
distrib(P v Q PI) distrib(P v R Ql)
distributing(P P)
Step 9 Packing each conjunction into clauses
c1ausify(P amp Q CI C2) -
clausiCy(P CI C3) c1ausify(Q C3 C2)
cbusiCy(P [d(A B)ICs] Cs) shy
inclause(P A [j B [I) 1
c1ausiry( C C)
inclause(P v Q A AI B B1) -
inc1ause(P A2 AI B2 Bl)
inclause(Q A A2 B B2)
inclausenp) A A B1 B) -
notin(P A) putin(P B B1)
inclause(P AI A B B) shy
notin(P Bl putin(P A AI)
notin(X [XU) - fail
notin(X [JLj) - notin(X L)
notin(X 1])
putin(X II [X]) - 1
putin(X [XILJ L) -
putin(X [YILJ [YILl]) - putin(X L Ll)
Step 1Oa Printing clauses
printcl([]) - nl nl
printcl(c1(AB)ICsj) - printcl(A Bl nl printcl(Cs)
printcl(L II) - printdis(IL) prinr)middot
printclHl L) - prin(contradiction(() printconl(rL)
print()) - ) printconj(rL) prinr )
printcl(Ll L2) shy
printdis(ILl) print( - ) printconj(rL2) prin()
printdis(S[Lj) - printcbar(SL)
33
printdis(S[LILs]) - printchu(SL) prin( v) printdis(SLs)
printconl(S[LI) - printchar(SL)
printconl(S[LILs]) - printchar(SL) prin( ) printconl(SLs)
printconj(S[L]) - tab(3) printchar(SL)
prin tconj( S [L IL sl) shy
tab(3) printchar(SL) print( ) printconj(SLs)
printchar(SP) shy
atomic(P)
name(P L)
L = [IT]
concat([XIT NewP)
prin(~ewP)
printchar(SP) shy
atomic(P)
prin(P)
printchar(SA lt= gt B) -
prin((l clausify(A AI [j) pl(eAl) prin())
print lt=gt )
prin(() cbusify(B Bl [I) pJ(eBl) prine))middot
printchar(rnumber(X N)) shy
prin(num() printchar(rx) prin( )
printchar(rN) prinC))
printchar(rF(A B)) shy
seJec(F(A B))
prinCsel() printchar(rA)
prin( F ) printchar(rB) prinC))
printchar(SF(A B)) shy
( selec(F(A B)) F = infix )
printchar(SA) prin( F ) printchar(SB)
printchar(SF(A)) shy
(F= prefix gt= F= prefix lt= F= prefixgt F= prefix lt )
prin(F ) printcbar(SA)
printchar(SP) shy
functor(P F MaxN)
prin(F ()
Nl is MaxN - 1
putout(S N 1 P MaxN)
34
prin())
putout(S 0 P MaxN) -
arg(~laxN P Argu)
prin tchar(SArgu)
putout(S N p MaxN) shy
Nt is MaxN - N arg(NI P Argu)
printcbar(SArgu )
prin( )
N2 is N - 1
putout(S N2 P MaxN)
selec(FA B)) shy
( F= infix = F= infix f= F= infix gt=
F= infix gt F= infix lt= F= infix lt )
35
----------------------------------Program Name APClS - Part 2 Inference Mechanism ---------------------------------- a(X) shy
steps(X X9)
(( X9 =[] nl
print( yes it is always true) )
( X9 =[cI(IJ[])] nl
print( no it is always false) )
( nl nl printel(X9) Step 1Oa
tell(temp_file) printel(X9) e1ose(temp_file) consult(temp_6Ie) ))
q(X) shy
asserta( in pt(X))
steps(X X9)
(( X9 = [] print(middot~H~~middot~t~)
print(THE AiSWER IS YES)
print( ilgIQlQl(~) )
( X9 = [e1([j [j)] Pr1nt ( OJ fi(i I~ iii Ij)middot(i)(i) fiyenQ)riiio(i)(ij)(i)fj)fiyen1li1il1li1il)__ gtw~ __~_~ _~~_ ~_-=~
print(THE ANSWER IS NO ) print() )
( teI1(temp_6Ie)
prques(X9) Step 1Ob
close(temp_file)
nl print(Let me think about it) nl
consult(temp_6Ie) ))
retrac t( in pt(X))
Step lOb Printing question
prques(lcl(A 8)1) - prin(goo(() pl(qA 8) print()))
prques([c1(A 8HCs]) - prin(goo(() pl(qA 8) print() pl(q Cs)
pl(e [c1(A 8)]) - pl(eA 8)
pl(q [c1(A 8)]) - pl(qA 8) print()))
pl(S [e1(A B)ICs]) - pl(SA B) prin( ) pl(S Cs)
38
pl(q [j L) - prin(c1ause(contradiction(() pcont(qL) prin())_))
pl(S [I L)- prin(so2(contradidion(() pcont(SL) print))))middot
pl(S [L] []) - prin(so2() pcbar(SL) prin())
pl(S L [J)- prinsol() plett(SL) print))
pl(S [L] LI) - prin(condi(() pchar(cL)
prin(() pcont(S Ll) prine))))
pl(S L Ll)- prin(c1ause() plert(cL)
prin(() pcont(S Ll) prine)))
plert(S[LJ) - pchar(SL)
plert(SjLILsj) - pcbar(SL) print v) pleCt(SLs)
pcont(S[L]) - pchar(SL)
pcont(S[LILsj) - pcbar(SL) prinr ) pcont(SLs)
pcbar(SP) shy
atomic(P)
name(PL)
( L = [IT] L = [5 k miT] L = [5 k niT] )
concat[XITj NewP)
prin(0JewP)
pchar(SP) shy
atomic(P)
prin(P) pchar(SA lt=gt B) -
prin(() dausify(A AI []) pl(eAI) prin())
prinr lt=gt ) prin(() dausify(B BI ]) pl(eB) print))
pchar(Snumber(X N)) shy
prin(num() pchar(SX) prin()
pchar(SN) prinr))
pcbar(SM N) - prin(M N)
pcbar(cF(A B)) shy
selec(F(A Braquo
pcbar(cA)
prine F ) pchar(cB) pchar(SF(A B)) shy
selec(F(A B))
prin(sel() pchar(SA)
print F ) pchar(SB) print)) I
31
pc har(SF(A)) shy
( F= prefix gt= F= prefix lt= F= prefixgt F= prefix lt )
prin(F ) pchar(SA)
pchar(SP)shy
runctor(P F MaxN)
prin(F ()
011 is MaxN - 1 pout(SNl P MaxN)
print) )
pout(S 0 P M3xN) - 1
arg(~bxN P Argu)
pchlr(SArgu )
pout(S N P MaxN shy
Nl is MaxN - N
arg(Nl P Argu)
pchar(SArgu
prin( )
N2 is N - 1
pout(S N2 P ~13xN)
Comparing numbers in numerical quantifiers
num(XN) shy
number(X I)
cnum(N 1) ~
cnumlaquo=01 lt=I- N gt=I
cnumlaquo=J lt I) - N gt=1-1
cnumlaquo=NIJ) - N gt=J 1
cnumlaquo=N J)- integer(I) N gt=I~
cnum(gt=N gt=1) - N lt=1
cnum(gt=N gt I) - N lt=1+ 1 cnum(gt=NIJ) - N lt=1
cnum(gt=N lt=1)- N lt=1
cnum(gt=N lt I) - N lt=1 L cnum(gt=N 1)- integer(I) N lt=1
cnum( lt N lt 1)- N gt=1 L
38
cnum( lt N lt=1) - N gt I cnum( lt NLJ) - N gt J
cnum( lt N 1)- integer(I) N gt 1
cnum(gt N gt I) - N lt=1 cnumlgt i gt=1) - N lt I
cnum(gt N lt=1) - N lt=0
cnum(gt N lt I) - N lt=0
cnum(gt iIJ) - N lt I cnum(gt N 1)- integer(I) N lt I
cnum(~LN lt=1) - M=I N gt= I l
cnum(~LN lt I) - M=l N gt= I-I
cnum(~LNLJ) - M lt =1 N gt = J
cnum(~1N 1)- integer(I) M lt= I N gt= I
cnum(- N) - integer(N)
Comparing selectors
sel(X = Y) shyX= Y
sel(X I=Y) shy(X I=Y X lt Y Xgt Y)
sel(X gt Y) shyXgt Y
sel(X lt Y) shyXlt Y
selX gt=Y) shy(X gt=Y X= Y Xgt Y)
se(X lt=Y) shy
(X lt=Y
X= Y
X lt Y)
csel(infix = infix =)
39
csel(infix = infix = csel(infix = infix gt)
csel(infix = infix lt) csel(infix gt infix gt) cseJ(infix lt infix lt) csel(infix gt= infix gt=) csel(infix gt= infix gt csel(infix gt= infix =)
csellinfix lt= infix lt=) csel(infix lt= infix lt) csel(infix lt= infix =)
Finding solutions
sol(X v Y) -
(( notetra(X) eon(X) ( sol(Y) )
( c1ause(P v Q R) not(cketra(P v Q))
dis(P v Q X v Y R) ~ )
( A lt=gt B equival(A lt=gt B X v Y) ~ I) sol(X) - ~ notetra(X) eon(X)
so~(X) - notetra(X)
( con (X)
( clause(P v Q R) not(ekctra(P v Q)) dis(P v Q X R) I)
cketra(P v Q) -
eketra(P) eketra(Q) eketra(F(I J)) shy
selec(F(I J))
c1ause(contradiction(sel(F(IJ))) _I
eketra(number(W I)) -
clause(cootradietion(num(Wl)) - eketr(P) shy
clause(contradiction(P) - 1
notctra(P) shy
not( e lause( con tradiction(P) _))
40
Searching (or disjunctions
dis(P v Q X v Y R) - dis(P X v Y R)
dis(Q X v Y R) con(R)
dis(P v Q X R) -
dis(P X R) dis(Q X R) con(R
dis(P X v Y R) - clause(contradicton(Pl J 1
dis(F(I J) sel(G(I J)) v Y R) - csel(G Fl dis(number(WI) num(W N v Y R) - cnum(N I)
dis(P P v Y R) -
dis(P X v Y R) - dis(P Y R)
dis(F(I J) seJ(G(IJ)) R) - csel(G F)
dis(number(WI) num(WN) R) - cnum(N I) dis(P P R) - 1
dis(FJ J X R) shy
( ckctra(F(IJ) cbeckeq(seJ(F(IJ))) )
dis(number(W Il X R) - ( ckctra(number(WI)) cbeckeq(num(WI)) )
dis(P X R) shy( ckctra(P) cbeckeq(P) ) 1
cbeckeq(P) shy
(( A lt=gt so2(contradiction(P))
bagof(A A [jj) ) ( so2(contradiction(P)) lt=gt B
bagof(B B Uj) ))
ckeq(A) shy
( so2(A) lt=gt B B lt=gt so2(A) ) bagof(B B UJ)
con((P Q)) -
clause(P R) con(R) con(Q) con(true) -
con(contradiction(P)) - clause(contradiction(P) J
con(cause(X Y)) - cause(X Y)
con(sel(X)) - sel(X)
con(num(X Y)) - num(X Y) con(P)- (( dause(P R) (con(R) ckeq(R)))
colJectin(P) )
collectin(P) shy
bagof(S (c1ause(P S) S = true) [L LIJ )
mkcon(L Ll L)
bagor(l (L2 ) UJ) L
mkcon((A AI) (B B1) (sol(A v B) e D)) -
mkcon(A B1 e) mkcon(A1 (B Bl) D)
mkcon(A (B B1) (sol(A v B) e)) -
mkcon(A Bl e)
mkcon((A AI) B (sol(A v B) e)) middot1
mkcon(Al B e)
mkcon(A B sol(A vB))
Searching ror equivalences
equival(A lt=gt B X v Y) - 1 ( equival(A lt=gt B X) equival(A lt=gt B Y) )
equival(s02(A) lt=gt 502(B) A) - clause(B _I equival(s02(B) lt=gt 502(A) A) c1ause(B _I
Top level or inrerence mechanism
goo((s02(whatnum) P)) -
getatm(P Xl
bagor(number(X Y) ( P so2(number(X Y)) ) A )
count1(A 00 L R) nl
bagor(X P B )
count2(B L R Ll Rl) nJ print()
(( LI = 0 Rl = 0 print(THE ANSWER IS ) nl
(( Ll = Rl prin(-Jumber or ) prn(P) print(is Ll) )
( Rlgt20000 prin(Number or I prn(P) print(is LI or more) )
42
( prin(Number of ) pfn(P) print( is from Ll to Rl) )) )
( print(THE ANSWER IS NO I )) print()
goo(X) shy
(( bagof(X X L) L = [I nl print()
print(THE ANSWER IS YES) nl wout(L) print() )
( equiv(X L) nl print()
print(THE ANSWER IS YES) nl wout(L) print(-) )
( c1ause(inpt(A ==gt B) _I ( impli(A B Z) impli(B A Z) ) print(l~Hl)
printTHE ANSWER IS YES) nl print(Z) print(Hj~(fH~) ))
goo(X) print( Hg)
print(THE ANSWER IS NO ) print( lH~lH~gg9l9lmiddotmiddot~Q(gmiddot)
00 Semhing for implications in equiV3lent relations
impli( B Z) shyt-ell( z1) prin(templ() pchn(S A lt=gt B) print()) close ( zl) consult(zl) templ(Z)
unload zl Z
Searching for equivalence
equiv (X L)
(( X lt=gt Y
equ(Y YI)t bagof(Y Yl L) L = [j )
(Y lt=gt X equ(Y YI) bagof(Y Yl L) L = [J )
( X = F(New)
clause(~ew T) makeup(T Tl)
(( Tl lt=gt B
equ(B Bl) bagof(Bl Bl M) M = [j L=[Newl )
(A lt=gt TI
equ(A AI) bagof(Al AI M) M = 1] L=INewj )) ))
makeup((A B) (AI Bl)) -
makeup(A A1) makeup(B BI)
makeup(A so2(A))
equ((A B) (AI BI)) -
equ(A AI) equ(B Bl)
equ(sol(X v Y) sol(XI v Yl)) -
equ(X XI) equ(Y YI)
equ(so2(X) so2(XI)) -
equ(X XI)
equ(contradiction(X) clJuse(contradiction(X) X) ) -
equ(X X)
Counting numbers
getatm((A B) X) -
( getatm(A X) getatm(B X) )
getatm(so2(F(X)) X) -
getatm(so2(X) X) - atom(X)
countl([J L R L R) -
countl([number(X Y)IT] L R L2 R2) shy
(( Y = (gt=~) LI is L + N Rl is R + 20001 l )
( Y = (gt N) LI is L+ N+ 1 RI is R + 20002 )
(Y == laquo=~) LI is L + 1 Rl is R + N )
(Y = laquo N) LI is L + 1 RI is R+N-I)
(Y == IJ LI is L + I Rl is R + J ) ( Y == N L1 is L + N RI is R + N ))
count1(T LI R 1 L2 R2)
count2(fJ L R L R) - 1
count2([XITJ L R L2 R2) shy
name(X Xl)
(( Xl = sknj LI is L Rl is R )
44
( Xl = Iskmj L1 is L + 1 RI is R + ZOOO1) ( LI is L + I RI is R + I ))
count2(T LI RI L2 R2)
pfn((A B)) - pfn(A) prn(B)
pCn(so2(F(X))) - prin(F )
prn(so2(X)) - atom(X) prin(X ) prn (so2(X))
Printing result
wout([XlJ - prt(X) nl woutf[xIY]) - prt(X) nl nl wout(Y)
prt(e(A B)) -
prt(A) prinr 8 ) prt(ltE) prt(eA) - prt(A)
prt(c(A EJ) - prin() prt(A) prine ) prt(B) prin(T)
prt(c A) - prt(A) prt((A E)) - ~
prt(A) nl prt(E) prt(sol(X v Y)) - ~
prt(X) prinC v) prt(Y) prt(A lt=gt B) -
prt(e A) prinC lt=gt ) prt(e B) prt(sol(X)) - prt(X)
prt(so2(X)) - prt(X
prt(c1ause(X Y)) - prt(X)
prt(contradiction(X)) - prin(contradiction() prt(cX) prinr))middot prt(num(XY)) - prin(number(X Y)) prt(sel(X)) - prin(X) prt(X v Y) - prt(X) prin( v) prt(Y) prt(X) prin(X)
Handling conditional queries
condi((Y Xl) shy
assertcon(X) Y
45
retractcon(X)
condi((B A))
retractcon(A) fail
assertcon((A B)) 1
assertcon(A) assertcon(B)
assertcon(A) asserta(A)
retrac teon ((A B)) 1
retracteon(A) retractcon (B)
retraetcon(A) - retract(A)
BIBLIOGRAPHIC DATA SHEET
Report No UIUCDS-F-84-928
3 Recipients Accession No
4 T ide and Subt ltle
An Annotated Predicate Calculus Inference System (APCIS)
S Report Date
November 1984 6
7 Author(s)
Kah-Eng Pua 8 Performing Organization Rept
No
9 Performing Organization Name and Address
Department of Computer Science University of Illinois Urbana IL
10 ProjectTaskWork Unit No
11 Contract Grant No NSF DCR 84-06081 ONR N00014-82-K-0186
12 Sponsoring Organization Name and Address
National Science Foundation Washington DC
13 Type of Report amp Period Covered
14
15 Supplementary Notes
16 Abstracts
This paper describes a deductive inference system called APCIS (Annotated Predicate Calculus Inference System) APCIS is able to carry out inferences from expressions involving numerical quantifiers selectors disjunctions of non-negated terms negated terms disjunctions of negated terms equivalences and exceptions It is also able to count the numbers of occurrence of a given simple term or a conjunction of terms The design of contradiction and the treatment of the disjunction of non-negated terms allow APCIS to accept Horn clauses as well as non-Horn clauses and to carry out inferences from them This feature makes APCIS more general than Prolog
17 Key lords and Document Analysis 170 Descriptors
APC (Annotated Predicate Calculus) APCIS (Annotated Predicate Calculus Inference System) Horn Clause Numerical Quantifier Prolog Selector
17b IdentifiersOpen-Ended Terms
17c COSATI FieldGroup
18 Availability Statement 19 Security Class (This
Re~f~~IA~SIF IFf)
21 ~o of Pages
49 211 ecurity Class (This
PageUNCLASSIFIED
22 Price
FOA NTIS n (10middot70 usco-oc 40329-
1amp
APCIS will translate the question and enter to Prolog the following query
goo(( s02( horse(X) ) s02( num( X gt5 )) ))
Note that the term number(slml 6) in the database and the term num(X gt S) in the query are
different predicates and this difference is exactly where the power of the clause num(X N)
defined in APCIS comes from When the clause num(X N) in APCIS is activated it will search
through the database to see if there is any term of the form number(X I) whose first argument
matches the first argument of num(X Y) in the query It a match is found the second arguments
of both num(X Y) in the query and number(ltI) in the database will be passed to cnum in
APCIS
The job of cnum is to compare the numerical messages carried by the second
argument or the term rlum(X Y) in the query and the second argument of the term rlumber(X I)
in the database to see if they match with each other according to the rules defined in cnum
While there are 25 rules for such matching purposes the idea is simple
Imagine that the second argument Y of the term num(X Y) in the query
and the second argument I of the term num()( I) in the database each occupies a
place in an integer line (Le the integer line in mathematics) To have a match
the domain covered by Y should contain the domain covered by L
As an example the answer to the above query is positive since the domain of gt5
contains the domain or 6
Before closing this section we will bring out a speciaJ translation aspect of expressions
involving numbers by an example We first type to APCIS the Collowing expressions in assertion
mode
1 aU(X all(Y father(X Y) amp number(Y gt6) ==gt has_manY3hildren(X) ))
2 exists(X exists( 12 Y Cather(X Y) ) )
11
After going tbrougb all tbe translation steps tbe Collowing two expressions will be entered to tbe
database
I
bas_many_cbildren( Xl ) shy
Cather( Xl X2 )
num( X2 gt6 )
2
Catber( sk m1 sk n2 )
number( skn2 12 )
lotice that whenev(gtr a term with Cunctor number appears at the rigbt-band side oC a Prolog
clause its Cunctor will be cbanged to num automatically This treatment will greatly cnbance tbe
inference power of the clause sbown in l above For instance iC we now ask tbe question
q( exists( X bas_many_children(X) ) )
The right hand side oC the clause l will match the two terms in 2 and tbe query succeeds
52 Bel and cael
A special feature of APe is tbat all predicates tbat express relations = = gt
gt= lt and lt= can be expressed explicitly using infix notations as relational statements
called selectors To handle selectors we defined Bel in APCIS
Every expression involving selectors will undergo different translations in assertion mode
and query mode For example the assertion
a( exists( [X Y] box (X) amp box(Y) amp (weigh t(X) gt weight(Y) ) ) )
will be translated into the following three terms and entered to tbe database
box( skml )
box( skm2 )
18
weight( skm 1 ) gt weight( skm2 )
Now it we want to ask Is it true that there exists two boxes of different weights and type in
q( exists( [X Yl box(X) amp box(Y) amp ( weight(X) = weight(Y) ) ) )
The question will be transformed to the following query and entered to Prolog
goo(( so( box(XI) ) s02( box(X2) ) so2( sel( weightXI) = weight(X2) )) ))
Note that the selector in the above query is surrounded by the functor set When any clause or
8el in APCIS is activated it will search through the database to see it there is any selector whose
two arguments (left and right side or any selector symbol) match the two arguments of the
selector in the query At the same time 8el will check iC the selector symbols (may be different) or
the two different selectors (one in the query and one in the database) satisfy the rules defined in
sel There are 12 matching rules defined in sel All oC them ~re straightforward and will not be
discussed here An example will be enough to explain how 8el works
Consider the execution of the above transformed query The first two terms in the query
are satisfied by the first two terms in the database and Xl and X2 are instantiated to skml and
skm2 respectively The third term of the query will be passed to eel (of APCIS) which finds a
match on each side of the two selectors (one in the query and one in the database) At the same
time the two different selector symbols gt and = are found to satisfy one of the rules in
8el As a result the query succeeds
To enhance the inference power of clauses involving selectors all the selectors appearing
on the rightmiddothand side oC any clause will be surrounded by a functor set The idea is similar to
that in the last part of the previous section
c8el is exactly the same as 8el functionally It provides a convenient way to compare
selectors when dis is being executed
19
8 Printing Result
Whenever a goal is successfully executed APCIS will not only response with a yes but
also print out the matched terms or clauses in the database This is made possible by the built-in
function bagor and the two predicates wout and prt defined in APCIS
7 Summary
In this paper a description of a deductive inference system called APCIS (Annotated
Predicate Calculus Inference System) has been provided APCIS is able to carry out inferences
from expressions involving numerical quantifiers selectors disjunctions of non-negated terms
negated terms disjunctions of negated terms equivalences and exceptions It is also able to count
the numbers of occurrence of a given simple term or a conjunction of terms
The main idea of APCIS is that each input APC expression is first passed to a
preprocessor ( ie APC translator ) which dissolves and transforms each APC expression into
Prolog expression(s) which will then be loaded to Prolog system The user bas to specify whether
each input expression is to be entered as an assertion or as a query by invoking either assertion
mode or query mode respectively Each assertion or query will undergo different transformations in
the preprocessor The different treatment of assertion or query not only allows a full uS1ge of the
Prolog inference mechanism but also makes possible a higher level of inexact pattern matching
exemplified by the examples in Section 51 and Section 52 where the four predicates num
cnum sel and csel are discussed This higher level of pattern matching increases the inference
power of APCIS greatly
The design of contradiction and the treatment of the disjunction of non-negated terms
allow APCIS to accept non-Horn clauses and to carry out inference from them This feature
makes APCIS more general than Prolog
20
While APCIS performs very well in many sets of arguments provided by the author it is
still too early to jump to conclusion that it can perform equally well in all types of problems In
any event the expressiveness of APC has greatly been retained in the present version of APCIS
and moreover some design ideas or APCIS mentioned in this paper are not restricted to APCIS
- they may be carried over to learning programs with narrower scopes
21
References
[1] W F Clocksin and C S Mellish Programming In Prolog Springermiddot Verlag Berlin Hpoundidelberg 1981
[2] R S Michalski A Theory and Methodology of Inductive Learning Chpt 4 Machine L earning Tioga Publishing Co Palo Alto CaliJornia 1989
[3] K-E Pua Translating Annotated Predicate Calculu8 to Prolog ISG Report 84middot1 UlUCDCSmiddotFmiddot918 University oj Illinois Urbana IL June 1984
22
Appendix A
APCIS Users Manual
1 Get Started
Users are urged to follow the steps depicted below
1 Get the PROLOG interpreter by typing
alias prolog mntb2sammutsammutprologprolog (Vax A)
or
alias prolog mntb2sammutsammutbinprolog (Vax B)
2 Load apc and infer by typing
prolog apc infer
When large APC expressions are expected we can increase the stlck by typingI
prolog -snnnn ape infer
where ns denote the number of stacks in decimal
3 When the wording LSW - PROLOG appears on the terminal we are reldy to interact
with APCIS The four modes by which we can invoke APCIS are summarized below
a Assert ion-Translation Mode
ta(X)
b Query-Translation Mode
tq(X)
c Assertion Mode
a(X
d Query Mode
q(X)
23
where Xs are APC expressions
2 Notations Used in APCIS
Below is a summary or notations used in APCIS
a Logical operators
amp
v
==gt
lt=gt
-
negation
conjunction
disjunction
implication
equivalence
exception
b Binary relation symbols in selectors
-
=
gt=
lt=
gt
lt
equal
not equal
greater or equal
smaller or equ al
greater
smaller
c Relational operators in numerical quantifiers
lt less than
lt= less than or equal
gt greater than
gt= greater than or equal
d BinlTY operator in numerical quantifier
range
e Universal quantifier
all(X p(X))
f Existential quantifier
exists(X p(X))
g Numerical quantifier
exists(I X p(X))
where p(X) is a formula
where X is a variable or a Jist of variables or the
form [HI~rj and p(X) a formula
where I repersents expression involving integer(s)
and operator(s) in c or d above and p(X) a formula
25
Appendix B
APCIS Program Listings
------------------------------- Program Name APCIS - Part 1 APC Translator
-------------------------------
op(3OO fx -)1
op(500 xfy amp)
oPt 500 xfy v)
op(600 xfx )
op(700 fx [gt= lt= gt lt ]) op(400 xfy [= gt= lt= gt lt ])1 op(900 xfy gt lt=gt -])1
steps(X Xg) shy
numbervars(X 1 J Step 1 change variables to iis
rmimp(X X) Step 2 conv(X X3) Step 3
rewrite(X3 X4) Step 4
negin(X4 X5) Step 5
dropexist(X5 X6 1]) Step 6
dropall(X6 X7) Step 7
distrib(X7 X8) Step 8 clausiCy(X8 X9 [J) Step 9
ta(X) shysteps(X Xg)
(( Xg = II nl
print( yes it is always true) )
( nl nl printcl(X9))) Step 10a
tq(X) shy
steps(X Xg)
prques(Xg)
28
Step 2 Removing implic3tions amp Transforming exceptions and equiv3lences
rmimpl( P - Q (PI lt=gt (QI) ) amp ((PI) lt=gt QI) ) -
rmimpl(P PI) rmimpl(Q QI)
rmimplnp) lt=gt Q (PI lt=gt -(QI)) amp nPI) lt=gt QI) ) - 1
rmimpl(P PI) rmimpJ(Q QI)
rmimpJ(P lt-gt -(Q) (PI lt=gt -(QI)) amp nPI) lt=gt QI) ) -
rmimpl(P PI) rmimpl(Q QI)
rmimpl( P lt=gt Q PI lt=gt QI ) - I
rmimpl(P PI) rmimpl(Q QI)
rmimpl( P ==gt Q -(PI) v QI ) - I
rmimpl(P PI) rmimpl(Q QI)
rmimpl( all(X P) aI(X PI) ) - 1
rmimpl(P PI)
rmimpl( exists(X P) exists(X PI) ) -
rmimpl(P PI)
rmimpl( exists(I X P) exists(I X PI) ) -
rmimpl(P PI)
rmimpl( P amp Q PI amp Ql ) -
rmimpl(P PI) rmimpl(Q Ql)
rmimpl( P v Q PI v QI ) -
rmimpl(P PI) rmimpl(Q QI)
rmimpl( -(p) -(PI) ) - I
rmimpl(p PI)
rmimpl( P P )
St~p 3 Converting numerical amp distinctive quantifiers
L Numerical quantifiers
examples of input forms
1 exists(gt= i X pIX)) where i is an integer
2 exists(i X pIX)) where i is an integer
3 exists(i j X pIX)) where i j are integers and iltj
4 exists(il v i2 X pIX)) where is are integers
examples of output forms of this step
1 exists(X pIX) amp number(X gt= i) )
2 exists(X pIX) amp number(X i) ) 3 exists(X pIX) amp number(X ij) ) 4 exists(X pIX) amp number(X il v i2) )
II Distinctive quantifiers
27
example or input Corm
exists([XYL p(X Y))
example or output Corm or this step
exists(X exists(Y p(XY)) )
conv(P lt=gt Q PI lt=gt QI) - 1
conv(P PI) conv(Q QI)
conv(al1(X P) all(X PI)) -
conv(P PI)
conv(exists(HIT] P) R ) - conv(P PI) convert distinctive quantifier
convtdis(exists([HIT]PI) R)
conv( exists(I X P) exists(X PIamp number(X I) )) -
conv(P PI) convert numerical quantifier
conv(exists(X P) exists(X PI)) - 1
conv(P Pl)
conv(P amp Q PI amp QI) - 1
conv(P PI) conv(Q QI)
conv(P v Q PI v QI) - t conv(P PI) conv(Q QI)
convC(P) -(PI)) -
conv(P PI)
conv(P Pl
convtdis(existsl[XL P) exists(X P)) - atomic(X) convtdis(exists[XIYj Pl exists(X R)) shy
convtdis(exists(Y P) R)
Step 4 Rewriting compound predicates andor compound selectors
Outputs are smiple predicates andor simple selectors
rewrite(P lt=gt Q PI lt=gt QI) - t rewrite(P PI) rewrite(Q QI)
rewrite(all(X Pl all(X PI)) - 1 rewrite(P PI)
rewriteexists(X P) exists(X PI)) - I rewriteP PI)
rewrite(P amp Q PI amp QI) - rewrite(P P 1) rewrite( Q Q 1
rewrite(P v Q PI v QI) - 1
rewrite(P PI) rewrite(Q QI)
rewriteC(P) -(PI)) - I
28
rewrite(P PI) rewrite(F(A B) R) -
rewrite(A AI) rewrite(B BI) re(F(AI BI) R)
rewrite(F(A) R) -
rewrite(A AI) re(F(AI) H)
rewrite(F(A B C) R) -
rewrite(A AI) rewrite(B BI) rewrite(C CI) re(F(AI BI CI) R)
rewrite(F(A B C D) R) -
rewrite(A AI) rewrite(B Btl rewrite(C CI) rewrite(D DI) rc(F(AI BI CI Dl) H)
rewrite(PP)
re(F(A B v el (RI v R2) -
re(F(A Bl RIl re(F(A C) R2) reF(A B amp cl (RI amp R2)) -
re(F(A B) RI) re(F(A e) R2) re(F(A amp B C) (Rl amp R2)) -
re(F(A e) R 1) re(F(B C) R 2) re(F( v B el (R I v R2)) -
re(F(A el R I) reFB el R2) re(F(A amp Bl (R I amp R2)) -
re(F(A RI) re(F(BJH2) re(F(A v B) (R 1 v R2)) -
re(F(A) RI) re(F(B) R2)
re(F(A vB c Dl (RI v R2) -
re(F(A C D) RI) re(F(B C D) R2) re(F(A amp B C D) (RI amp R2)) -
re(F(A C D) Rll re(F(B C D) R2) re(F(A B v C D) (HI v R2)) -
re(F(A B D) RI) re(F(A C D) R2) re(F(A B amp C D) (HI amp R2)) -
re(F(A B D) RI) re(F(A C D) R2) re(F(A B C v D) (RI v R2)) -
re(F(A B C) R I) reF(A B D) R2) re(F(A B C amp D) (RI amp R2)) -
29
re(F(A B C) RI) re(F(A B D) RZ)
re(F(A v B e D E) (R I v R2)) -
re(F(A e D E) R I) re(F(B e D El R2) re(F(A amp B e D E) (RI amp RZ)) -
re(F(A e D El R 1) re(F(B e D E) R2) re(F(A B v e D E) (R I v R2)) -
re(F(A B D E) RI) re(F(A e D E) R2)
re(F(A B amp e D E) (RI amp R2)) -
re(F(A B D El RI) re(F(A e D E) RZ) re(F(A B e v D E) (R I v R2)) -
re(F(A B e El R 1) re(F(A B D E) RZ) re(F(A B e amp D E) (RI amp RZ)) -
re(F(A B e E) R I) re(F(A B D E) RZ)
re(F(A B e D vEl (RI v RZ)) - l
rc(F(A B C D) RI) re(F(A n e El RZ) re(F(A B e D amp El (RI amp RZ)) - ~
re(F(A B e D) RI) re(F(A B e El RZ)
re((A = B) (A = B)l-
re((A = Bl (A = 8)) -
retIA gt= BI (A gt= B)) -
re((A lt= B) (A lt= B)) -
re((A gt B) (A gt B))-
re((A lt Bl (A lt Bl)- re(A A)
Step) Bringing n(gation inwards
Degin(-(P) PI) - neg(P Pl)
negin(P lt=gt Q PI lt=gt Ql) - ~
negin(P PI) negiD(Q QI)
Degin(aU(X P) all(X PI)) - Degin(P PI) negin(exists(X P) exists(X PI))- negin(P PI) negin(P amp Q PI amp Ql) - Degin(P PI) negin(Q Ql)
Degin(P v Q PI v QI) - Degin(P PI) negin(Q QI) negin(P Pl
neg(-(P) PI) - negin(P PI)
neg(all(X P) exists(X PI)) - neg(P PI)
30
neg(exists(X P) all(X PI)) - neg(P PI)
neg(P amp Q PI v QI) - neg(P PI) neg(Q Ql)
neg(P v Q PI amp QI) - neg(P PI) neg(Q QI)
neg(P -(PH
Step 6 Dropping existnetial quanti6ers
dropexist(P lt=gt Q PI lt=gt QI Elerns) - dropexist(P PI Elerns) dropexist(Q QI Elerns)
dropexist(alJ(X P) all(XPI) Elerns)
dropexist(P PI [XIElernsJ)
dropexist(exists(X P amp nurnber(X Yraquo P2 Elerns) -
genfun(skn Newg) Fun = [NewgIElerns]
subst(FuD X P amp Dumber(X Y) PI)
dropexist(Pl P2 Elerns)
dropexist(exists(X P) PZ Elerns) -
genfun(skrn Newf) Fun = [NewfIElernsJ
subst(Fun X p PI)
dropex ist(P 1 P~ Elerns)
dropexist(P v Q PI v QI Elerns) - ~
dropexist(P PI Elerns) dropexist(Q Ql Elerns)
dropexist(P amp Q PI amp QI Elerns) - 1
dropexist(P Pl Elerns) dropexist(Q QI Elerns)
dropexist(P P _)
gen fun(R oot Newn arne) shy
getnurn(Root Nurn)
narne(Root Rootlist)
append(Rootlist[Nurnj Narnelist)
concat(Narnelist Newnarne)
getnurn(Root Nurn) shy
retract(currentnurn(Root Nurn 1 raquo
Nurn is Nurni + 1
asserta(currentnurn(Root Nurn))
getnurn(Root 1) - asserta(currentnurn(Root 1))
subst(New Old Val Val) - var(Val)
subst(New Old Old New) - 1 substNew Old Val Val) - atornic(Val)
31
subst(New Old Val Newval) shy
runctor(Val F N)
CUDctor(Newval F N)
subst_args(N New Old Val Newval)
subst_args(O J J - J J
subst_args(N New Old Val NewVal) shy
arg(N Val OldArg)
arg(N NewVal NewArg)
subst(New Old OldArg NewArg)
NI is N - I
subst_args(Nl New Old Val NewVal)
append([J L L) -
append([XILl] L2 [XIL3]) - append(Ll L2 L3)
Step - Dropping universal quantifiers
dropall(P lt=gt Q PI lt=gt QI)-
dropall(P PI) dropall(Q QI)
dropall(all(X P) PI) - ~ dropall(P PI)
dropall(P amp Q PI amp QI) -
dropall(P PI) dropall(Q QI)
dropall(P v Q PI v QI) -
dropall(P PI) dropall(Q QI)
dropall(P P)
Step 8 Distributing conjunctions over disjunctions
distrib(P lt=gt Q PI lt=gt Ql) - t distrib(P PI) distrib(Q QI)
distrib(P v Q R) -
distrib(P PI) distrib(Q QI)
distributing(PI v QI R)
distrib(P it Q PI it QI) -
distrib(P PI) distrib( Q QI)
distrib(P P)
distributing((P amp Q) v R PI amp QI) -
distrib(P v R PI) distrib(Q v R Ql)
32
distributing(P v (Q amp R) PI amp Ql) -
distrib(P v Q PI) distrib(P v R Ql)
distributing(P P)
Step 9 Packing each conjunction into clauses
c1ausify(P amp Q CI C2) -
clausiCy(P CI C3) c1ausify(Q C3 C2)
cbusiCy(P [d(A B)ICs] Cs) shy
inclause(P A [j B [I) 1
c1ausiry( C C)
inclause(P v Q A AI B B1) -
inc1ause(P A2 AI B2 Bl)
inclause(Q A A2 B B2)
inclausenp) A A B1 B) -
notin(P A) putin(P B B1)
inclause(P AI A B B) shy
notin(P Bl putin(P A AI)
notin(X [XU) - fail
notin(X [JLj) - notin(X L)
notin(X 1])
putin(X II [X]) - 1
putin(X [XILJ L) -
putin(X [YILJ [YILl]) - putin(X L Ll)
Step 1Oa Printing clauses
printcl([]) - nl nl
printcl(c1(AB)ICsj) - printcl(A Bl nl printcl(Cs)
printcl(L II) - printdis(IL) prinr)middot
printclHl L) - prin(contradiction(() printconl(rL)
print()) - ) printconj(rL) prinr )
printcl(Ll L2) shy
printdis(ILl) print( - ) printconj(rL2) prin()
printdis(S[Lj) - printcbar(SL)
33
printdis(S[LILs]) - printchu(SL) prin( v) printdis(SLs)
printconl(S[LI) - printchar(SL)
printconl(S[LILs]) - printchar(SL) prin( ) printconl(SLs)
printconj(S[L]) - tab(3) printchar(SL)
prin tconj( S [L IL sl) shy
tab(3) printchar(SL) print( ) printconj(SLs)
printchar(SP) shy
atomic(P)
name(P L)
L = [IT]
concat([XIT NewP)
prin(~ewP)
printchar(SP) shy
atomic(P)
prin(P)
printchar(SA lt= gt B) -
prin((l clausify(A AI [j) pl(eAl) prin())
print lt=gt )
prin(() cbusify(B Bl [I) pJ(eBl) prine))middot
printchar(rnumber(X N)) shy
prin(num() printchar(rx) prin( )
printchar(rN) prinC))
printchar(rF(A B)) shy
seJec(F(A B))
prinCsel() printchar(rA)
prin( F ) printchar(rB) prinC))
printchar(SF(A B)) shy
( selec(F(A B)) F = infix )
printchar(SA) prin( F ) printchar(SB)
printchar(SF(A)) shy
(F= prefix gt= F= prefix lt= F= prefixgt F= prefix lt )
prin(F ) printcbar(SA)
printchar(SP) shy
functor(P F MaxN)
prin(F ()
Nl is MaxN - 1
putout(S N 1 P MaxN)
34
prin())
putout(S 0 P MaxN) -
arg(~laxN P Argu)
prin tchar(SArgu)
putout(S N p MaxN) shy
Nt is MaxN - N arg(NI P Argu)
printcbar(SArgu )
prin( )
N2 is N - 1
putout(S N2 P MaxN)
selec(FA B)) shy
( F= infix = F= infix f= F= infix gt=
F= infix gt F= infix lt= F= infix lt )
35
----------------------------------Program Name APClS - Part 2 Inference Mechanism ---------------------------------- a(X) shy
steps(X X9)
(( X9 =[] nl
print( yes it is always true) )
( X9 =[cI(IJ[])] nl
print( no it is always false) )
( nl nl printel(X9) Step 1Oa
tell(temp_file) printel(X9) e1ose(temp_file) consult(temp_6Ie) ))
q(X) shy
asserta( in pt(X))
steps(X X9)
(( X9 = [] print(middot~H~~middot~t~)
print(THE AiSWER IS YES)
print( ilgIQlQl(~) )
( X9 = [e1([j [j)] Pr1nt ( OJ fi(i I~ iii Ij)middot(i)(i) fiyenQ)riiio(i)(ij)(i)fj)fiyen1li1il1li1il)__ gtw~ __~_~ _~~_ ~_-=~
print(THE ANSWER IS NO ) print() )
( teI1(temp_6Ie)
prques(X9) Step 1Ob
close(temp_file)
nl print(Let me think about it) nl
consult(temp_6Ie) ))
retrac t( in pt(X))
Step lOb Printing question
prques(lcl(A 8)1) - prin(goo(() pl(qA 8) print()))
prques([c1(A 8HCs]) - prin(goo(() pl(qA 8) print() pl(q Cs)
pl(e [c1(A 8)]) - pl(eA 8)
pl(q [c1(A 8)]) - pl(qA 8) print()))
pl(S [e1(A B)ICs]) - pl(SA B) prin( ) pl(S Cs)
38
pl(q [j L) - prin(c1ause(contradiction(() pcont(qL) prin())_))
pl(S [I L)- prin(so2(contradidion(() pcont(SL) print))))middot
pl(S [L] []) - prin(so2() pcbar(SL) prin())
pl(S L [J)- prinsol() plett(SL) print))
pl(S [L] LI) - prin(condi(() pchar(cL)
prin(() pcont(S Ll) prine))))
pl(S L Ll)- prin(c1ause() plert(cL)
prin(() pcont(S Ll) prine)))
plert(S[LJ) - pchar(SL)
plert(SjLILsj) - pcbar(SL) print v) pleCt(SLs)
pcont(S[L]) - pchar(SL)
pcont(S[LILsj) - pcbar(SL) prinr ) pcont(SLs)
pcbar(SP) shy
atomic(P)
name(PL)
( L = [IT] L = [5 k miT] L = [5 k niT] )
concat[XITj NewP)
prin(0JewP)
pchar(SP) shy
atomic(P)
prin(P) pchar(SA lt=gt B) -
prin(() dausify(A AI []) pl(eAI) prin())
prinr lt=gt ) prin(() dausify(B BI ]) pl(eB) print))
pchar(Snumber(X N)) shy
prin(num() pchar(SX) prin()
pchar(SN) prinr))
pcbar(SM N) - prin(M N)
pcbar(cF(A B)) shy
selec(F(A Braquo
pcbar(cA)
prine F ) pchar(cB) pchar(SF(A B)) shy
selec(F(A B))
prin(sel() pchar(SA)
print F ) pchar(SB) print)) I
31
pc har(SF(A)) shy
( F= prefix gt= F= prefix lt= F= prefixgt F= prefix lt )
prin(F ) pchar(SA)
pchar(SP)shy
runctor(P F MaxN)
prin(F ()
011 is MaxN - 1 pout(SNl P MaxN)
print) )
pout(S 0 P M3xN) - 1
arg(~bxN P Argu)
pchlr(SArgu )
pout(S N P MaxN shy
Nl is MaxN - N
arg(Nl P Argu)
pchar(SArgu
prin( )
N2 is N - 1
pout(S N2 P ~13xN)
Comparing numbers in numerical quantifiers
num(XN) shy
number(X I)
cnum(N 1) ~
cnumlaquo=01 lt=I- N gt=I
cnumlaquo=J lt I) - N gt=1-1
cnumlaquo=NIJ) - N gt=J 1
cnumlaquo=N J)- integer(I) N gt=I~
cnum(gt=N gt=1) - N lt=1
cnum(gt=N gt I) - N lt=1+ 1 cnum(gt=NIJ) - N lt=1
cnum(gt=N lt=1)- N lt=1
cnum(gt=N lt I) - N lt=1 L cnum(gt=N 1)- integer(I) N lt=1
cnum( lt N lt 1)- N gt=1 L
38
cnum( lt N lt=1) - N gt I cnum( lt NLJ) - N gt J
cnum( lt N 1)- integer(I) N gt 1
cnum(gt N gt I) - N lt=1 cnumlgt i gt=1) - N lt I
cnum(gt N lt=1) - N lt=0
cnum(gt N lt I) - N lt=0
cnum(gt iIJ) - N lt I cnum(gt N 1)- integer(I) N lt I
cnum(~LN lt=1) - M=I N gt= I l
cnum(~LN lt I) - M=l N gt= I-I
cnum(~LNLJ) - M lt =1 N gt = J
cnum(~1N 1)- integer(I) M lt= I N gt= I
cnum(- N) - integer(N)
Comparing selectors
sel(X = Y) shyX= Y
sel(X I=Y) shy(X I=Y X lt Y Xgt Y)
sel(X gt Y) shyXgt Y
sel(X lt Y) shyXlt Y
selX gt=Y) shy(X gt=Y X= Y Xgt Y)
se(X lt=Y) shy
(X lt=Y
X= Y
X lt Y)
csel(infix = infix =)
39
csel(infix = infix = csel(infix = infix gt)
csel(infix = infix lt) csel(infix gt infix gt) cseJ(infix lt infix lt) csel(infix gt= infix gt=) csel(infix gt= infix gt csel(infix gt= infix =)
csellinfix lt= infix lt=) csel(infix lt= infix lt) csel(infix lt= infix =)
Finding solutions
sol(X v Y) -
(( notetra(X) eon(X) ( sol(Y) )
( c1ause(P v Q R) not(cketra(P v Q))
dis(P v Q X v Y R) ~ )
( A lt=gt B equival(A lt=gt B X v Y) ~ I) sol(X) - ~ notetra(X) eon(X)
so~(X) - notetra(X)
( con (X)
( clause(P v Q R) not(ekctra(P v Q)) dis(P v Q X R) I)
cketra(P v Q) -
eketra(P) eketra(Q) eketra(F(I J)) shy
selec(F(I J))
c1ause(contradiction(sel(F(IJ))) _I
eketra(number(W I)) -
clause(cootradietion(num(Wl)) - eketr(P) shy
clause(contradiction(P) - 1
notctra(P) shy
not( e lause( con tradiction(P) _))
40
Searching (or disjunctions
dis(P v Q X v Y R) - dis(P X v Y R)
dis(Q X v Y R) con(R)
dis(P v Q X R) -
dis(P X R) dis(Q X R) con(R
dis(P X v Y R) - clause(contradicton(Pl J 1
dis(F(I J) sel(G(I J)) v Y R) - csel(G Fl dis(number(WI) num(W N v Y R) - cnum(N I)
dis(P P v Y R) -
dis(P X v Y R) - dis(P Y R)
dis(F(I J) seJ(G(IJ)) R) - csel(G F)
dis(number(WI) num(WN) R) - cnum(N I) dis(P P R) - 1
dis(FJ J X R) shy
( ckctra(F(IJ) cbeckeq(seJ(F(IJ))) )
dis(number(W Il X R) - ( ckctra(number(WI)) cbeckeq(num(WI)) )
dis(P X R) shy( ckctra(P) cbeckeq(P) ) 1
cbeckeq(P) shy
(( A lt=gt so2(contradiction(P))
bagof(A A [jj) ) ( so2(contradiction(P)) lt=gt B
bagof(B B Uj) ))
ckeq(A) shy
( so2(A) lt=gt B B lt=gt so2(A) ) bagof(B B UJ)
con((P Q)) -
clause(P R) con(R) con(Q) con(true) -
con(contradiction(P)) - clause(contradiction(P) J
con(cause(X Y)) - cause(X Y)
con(sel(X)) - sel(X)
con(num(X Y)) - num(X Y) con(P)- (( dause(P R) (con(R) ckeq(R)))
colJectin(P) )
collectin(P) shy
bagof(S (c1ause(P S) S = true) [L LIJ )
mkcon(L Ll L)
bagor(l (L2 ) UJ) L
mkcon((A AI) (B B1) (sol(A v B) e D)) -
mkcon(A B1 e) mkcon(A1 (B Bl) D)
mkcon(A (B B1) (sol(A v B) e)) -
mkcon(A Bl e)
mkcon((A AI) B (sol(A v B) e)) middot1
mkcon(Al B e)
mkcon(A B sol(A vB))
Searching ror equivalences
equival(A lt=gt B X v Y) - 1 ( equival(A lt=gt B X) equival(A lt=gt B Y) )
equival(s02(A) lt=gt 502(B) A) - clause(B _I equival(s02(B) lt=gt 502(A) A) c1ause(B _I
Top level or inrerence mechanism
goo((s02(whatnum) P)) -
getatm(P Xl
bagor(number(X Y) ( P so2(number(X Y)) ) A )
count1(A 00 L R) nl
bagor(X P B )
count2(B L R Ll Rl) nJ print()
(( LI = 0 Rl = 0 print(THE ANSWER IS ) nl
(( Ll = Rl prin(-Jumber or ) prn(P) print(is Ll) )
( Rlgt20000 prin(Number or I prn(P) print(is LI or more) )
42
( prin(Number of ) pfn(P) print( is from Ll to Rl) )) )
( print(THE ANSWER IS NO I )) print()
goo(X) shy
(( bagof(X X L) L = [I nl print()
print(THE ANSWER IS YES) nl wout(L) print() )
( equiv(X L) nl print()
print(THE ANSWER IS YES) nl wout(L) print(-) )
( c1ause(inpt(A ==gt B) _I ( impli(A B Z) impli(B A Z) ) print(l~Hl)
printTHE ANSWER IS YES) nl print(Z) print(Hj~(fH~) ))
goo(X) print( Hg)
print(THE ANSWER IS NO ) print( lH~lH~gg9l9lmiddotmiddot~Q(gmiddot)
00 Semhing for implications in equiV3lent relations
impli( B Z) shyt-ell( z1) prin(templ() pchn(S A lt=gt B) print()) close ( zl) consult(zl) templ(Z)
unload zl Z
Searching for equivalence
equiv (X L)
(( X lt=gt Y
equ(Y YI)t bagof(Y Yl L) L = [j )
(Y lt=gt X equ(Y YI) bagof(Y Yl L) L = [J )
( X = F(New)
clause(~ew T) makeup(T Tl)
(( Tl lt=gt B
equ(B Bl) bagof(Bl Bl M) M = [j L=[Newl )
(A lt=gt TI
equ(A AI) bagof(Al AI M) M = 1] L=INewj )) ))
makeup((A B) (AI Bl)) -
makeup(A A1) makeup(B BI)
makeup(A so2(A))
equ((A B) (AI BI)) -
equ(A AI) equ(B Bl)
equ(sol(X v Y) sol(XI v Yl)) -
equ(X XI) equ(Y YI)
equ(so2(X) so2(XI)) -
equ(X XI)
equ(contradiction(X) clJuse(contradiction(X) X) ) -
equ(X X)
Counting numbers
getatm((A B) X) -
( getatm(A X) getatm(B X) )
getatm(so2(F(X)) X) -
getatm(so2(X) X) - atom(X)
countl([J L R L R) -
countl([number(X Y)IT] L R L2 R2) shy
(( Y = (gt=~) LI is L + N Rl is R + 20001 l )
( Y = (gt N) LI is L+ N+ 1 RI is R + 20002 )
(Y == laquo=~) LI is L + 1 Rl is R + N )
(Y = laquo N) LI is L + 1 RI is R+N-I)
(Y == IJ LI is L + I Rl is R + J ) ( Y == N L1 is L + N RI is R + N ))
count1(T LI R 1 L2 R2)
count2(fJ L R L R) - 1
count2([XITJ L R L2 R2) shy
name(X Xl)
(( Xl = sknj LI is L Rl is R )
44
( Xl = Iskmj L1 is L + 1 RI is R + ZOOO1) ( LI is L + I RI is R + I ))
count2(T LI RI L2 R2)
pfn((A B)) - pfn(A) prn(B)
pCn(so2(F(X))) - prin(F )
prn(so2(X)) - atom(X) prin(X ) prn (so2(X))
Printing result
wout([XlJ - prt(X) nl woutf[xIY]) - prt(X) nl nl wout(Y)
prt(e(A B)) -
prt(A) prinr 8 ) prt(ltE) prt(eA) - prt(A)
prt(c(A EJ) - prin() prt(A) prine ) prt(B) prin(T)
prt(c A) - prt(A) prt((A E)) - ~
prt(A) nl prt(E) prt(sol(X v Y)) - ~
prt(X) prinC v) prt(Y) prt(A lt=gt B) -
prt(e A) prinC lt=gt ) prt(e B) prt(sol(X)) - prt(X)
prt(so2(X)) - prt(X
prt(c1ause(X Y)) - prt(X)
prt(contradiction(X)) - prin(contradiction() prt(cX) prinr))middot prt(num(XY)) - prin(number(X Y)) prt(sel(X)) - prin(X) prt(X v Y) - prt(X) prin( v) prt(Y) prt(X) prin(X)
Handling conditional queries
condi((Y Xl) shy
assertcon(X) Y
45
retractcon(X)
condi((B A))
retractcon(A) fail
assertcon((A B)) 1
assertcon(A) assertcon(B)
assertcon(A) asserta(A)
retrac teon ((A B)) 1
retracteon(A) retractcon (B)
retraetcon(A) - retract(A)
BIBLIOGRAPHIC DATA SHEET
Report No UIUCDS-F-84-928
3 Recipients Accession No
4 T ide and Subt ltle
An Annotated Predicate Calculus Inference System (APCIS)
S Report Date
November 1984 6
7 Author(s)
Kah-Eng Pua 8 Performing Organization Rept
No
9 Performing Organization Name and Address
Department of Computer Science University of Illinois Urbana IL
10 ProjectTaskWork Unit No
11 Contract Grant No NSF DCR 84-06081 ONR N00014-82-K-0186
12 Sponsoring Organization Name and Address
National Science Foundation Washington DC
13 Type of Report amp Period Covered
14
15 Supplementary Notes
16 Abstracts
This paper describes a deductive inference system called APCIS (Annotated Predicate Calculus Inference System) APCIS is able to carry out inferences from expressions involving numerical quantifiers selectors disjunctions of non-negated terms negated terms disjunctions of negated terms equivalences and exceptions It is also able to count the numbers of occurrence of a given simple term or a conjunction of terms The design of contradiction and the treatment of the disjunction of non-negated terms allow APCIS to accept Horn clauses as well as non-Horn clauses and to carry out inferences from them This feature makes APCIS more general than Prolog
17 Key lords and Document Analysis 170 Descriptors
APC (Annotated Predicate Calculus) APCIS (Annotated Predicate Calculus Inference System) Horn Clause Numerical Quantifier Prolog Selector
17b IdentifiersOpen-Ended Terms
17c COSATI FieldGroup
18 Availability Statement 19 Security Class (This
Re~f~~IA~SIF IFf)
21 ~o of Pages
49 211 ecurity Class (This
PageUNCLASSIFIED
22 Price
FOA NTIS n (10middot70 usco-oc 40329-
11
After going tbrougb all tbe translation steps tbe Collowing two expressions will be entered to tbe
database
I
bas_many_cbildren( Xl ) shy
Cather( Xl X2 )
num( X2 gt6 )
2
Catber( sk m1 sk n2 )
number( skn2 12 )
lotice that whenev(gtr a term with Cunctor number appears at the rigbt-band side oC a Prolog
clause its Cunctor will be cbanged to num automatically This treatment will greatly cnbance tbe
inference power of the clause sbown in l above For instance iC we now ask tbe question
q( exists( X bas_many_children(X) ) )
The right hand side oC the clause l will match the two terms in 2 and tbe query succeeds
52 Bel and cael
A special feature of APe is tbat all predicates tbat express relations = = gt
gt= lt and lt= can be expressed explicitly using infix notations as relational statements
called selectors To handle selectors we defined Bel in APCIS
Every expression involving selectors will undergo different translations in assertion mode
and query mode For example the assertion
a( exists( [X Y] box (X) amp box(Y) amp (weigh t(X) gt weight(Y) ) ) )
will be translated into the following three terms and entered to tbe database
box( skml )
box( skm2 )
18
weight( skm 1 ) gt weight( skm2 )
Now it we want to ask Is it true that there exists two boxes of different weights and type in
q( exists( [X Yl box(X) amp box(Y) amp ( weight(X) = weight(Y) ) ) )
The question will be transformed to the following query and entered to Prolog
goo(( so( box(XI) ) s02( box(X2) ) so2( sel( weightXI) = weight(X2) )) ))
Note that the selector in the above query is surrounded by the functor set When any clause or
8el in APCIS is activated it will search through the database to see it there is any selector whose
two arguments (left and right side or any selector symbol) match the two arguments of the
selector in the query At the same time 8el will check iC the selector symbols (may be different) or
the two different selectors (one in the query and one in the database) satisfy the rules defined in
sel There are 12 matching rules defined in sel All oC them ~re straightforward and will not be
discussed here An example will be enough to explain how 8el works
Consider the execution of the above transformed query The first two terms in the query
are satisfied by the first two terms in the database and Xl and X2 are instantiated to skml and
skm2 respectively The third term of the query will be passed to eel (of APCIS) which finds a
match on each side of the two selectors (one in the query and one in the database) At the same
time the two different selector symbols gt and = are found to satisfy one of the rules in
8el As a result the query succeeds
To enhance the inference power of clauses involving selectors all the selectors appearing
on the rightmiddothand side oC any clause will be surrounded by a functor set The idea is similar to
that in the last part of the previous section
c8el is exactly the same as 8el functionally It provides a convenient way to compare
selectors when dis is being executed
19
8 Printing Result
Whenever a goal is successfully executed APCIS will not only response with a yes but
also print out the matched terms or clauses in the database This is made possible by the built-in
function bagor and the two predicates wout and prt defined in APCIS
7 Summary
In this paper a description of a deductive inference system called APCIS (Annotated
Predicate Calculus Inference System) has been provided APCIS is able to carry out inferences
from expressions involving numerical quantifiers selectors disjunctions of non-negated terms
negated terms disjunctions of negated terms equivalences and exceptions It is also able to count
the numbers of occurrence of a given simple term or a conjunction of terms
The main idea of APCIS is that each input APC expression is first passed to a
preprocessor ( ie APC translator ) which dissolves and transforms each APC expression into
Prolog expression(s) which will then be loaded to Prolog system The user bas to specify whether
each input expression is to be entered as an assertion or as a query by invoking either assertion
mode or query mode respectively Each assertion or query will undergo different transformations in
the preprocessor The different treatment of assertion or query not only allows a full uS1ge of the
Prolog inference mechanism but also makes possible a higher level of inexact pattern matching
exemplified by the examples in Section 51 and Section 52 where the four predicates num
cnum sel and csel are discussed This higher level of pattern matching increases the inference
power of APCIS greatly
The design of contradiction and the treatment of the disjunction of non-negated terms
allow APCIS to accept non-Horn clauses and to carry out inference from them This feature
makes APCIS more general than Prolog
20
While APCIS performs very well in many sets of arguments provided by the author it is
still too early to jump to conclusion that it can perform equally well in all types of problems In
any event the expressiveness of APC has greatly been retained in the present version of APCIS
and moreover some design ideas or APCIS mentioned in this paper are not restricted to APCIS
- they may be carried over to learning programs with narrower scopes
21
References
[1] W F Clocksin and C S Mellish Programming In Prolog Springermiddot Verlag Berlin Hpoundidelberg 1981
[2] R S Michalski A Theory and Methodology of Inductive Learning Chpt 4 Machine L earning Tioga Publishing Co Palo Alto CaliJornia 1989
[3] K-E Pua Translating Annotated Predicate Calculu8 to Prolog ISG Report 84middot1 UlUCDCSmiddotFmiddot918 University oj Illinois Urbana IL June 1984
22
Appendix A
APCIS Users Manual
1 Get Started
Users are urged to follow the steps depicted below
1 Get the PROLOG interpreter by typing
alias prolog mntb2sammutsammutprologprolog (Vax A)
or
alias prolog mntb2sammutsammutbinprolog (Vax B)
2 Load apc and infer by typing
prolog apc infer
When large APC expressions are expected we can increase the stlck by typingI
prolog -snnnn ape infer
where ns denote the number of stacks in decimal
3 When the wording LSW - PROLOG appears on the terminal we are reldy to interact
with APCIS The four modes by which we can invoke APCIS are summarized below
a Assert ion-Translation Mode
ta(X)
b Query-Translation Mode
tq(X)
c Assertion Mode
a(X
d Query Mode
q(X)
23
where Xs are APC expressions
2 Notations Used in APCIS
Below is a summary or notations used in APCIS
a Logical operators
amp
v
==gt
lt=gt
-
negation
conjunction
disjunction
implication
equivalence
exception
b Binary relation symbols in selectors
-
=
gt=
lt=
gt
lt
equal
not equal
greater or equal
smaller or equ al
greater
smaller
c Relational operators in numerical quantifiers
lt less than
lt= less than or equal
gt greater than
gt= greater than or equal
d BinlTY operator in numerical quantifier
range
e Universal quantifier
all(X p(X))
f Existential quantifier
exists(X p(X))
g Numerical quantifier
exists(I X p(X))
where p(X) is a formula
where X is a variable or a Jist of variables or the
form [HI~rj and p(X) a formula
where I repersents expression involving integer(s)
and operator(s) in c or d above and p(X) a formula
25
Appendix B
APCIS Program Listings
------------------------------- Program Name APCIS - Part 1 APC Translator
-------------------------------
op(3OO fx -)1
op(500 xfy amp)
oPt 500 xfy v)
op(600 xfx )
op(700 fx [gt= lt= gt lt ]) op(400 xfy [= gt= lt= gt lt ])1 op(900 xfy gt lt=gt -])1
steps(X Xg) shy
numbervars(X 1 J Step 1 change variables to iis
rmimp(X X) Step 2 conv(X X3) Step 3
rewrite(X3 X4) Step 4
negin(X4 X5) Step 5
dropexist(X5 X6 1]) Step 6
dropall(X6 X7) Step 7
distrib(X7 X8) Step 8 clausiCy(X8 X9 [J) Step 9
ta(X) shysteps(X Xg)
(( Xg = II nl
print( yes it is always true) )
( nl nl printcl(X9))) Step 10a
tq(X) shy
steps(X Xg)
prques(Xg)
28
Step 2 Removing implic3tions amp Transforming exceptions and equiv3lences
rmimpl( P - Q (PI lt=gt (QI) ) amp ((PI) lt=gt QI) ) -
rmimpl(P PI) rmimpl(Q QI)
rmimplnp) lt=gt Q (PI lt=gt -(QI)) amp nPI) lt=gt QI) ) - 1
rmimpl(P PI) rmimpJ(Q QI)
rmimpJ(P lt-gt -(Q) (PI lt=gt -(QI)) amp nPI) lt=gt QI) ) -
rmimpl(P PI) rmimpl(Q QI)
rmimpl( P lt=gt Q PI lt=gt QI ) - I
rmimpl(P PI) rmimpl(Q QI)
rmimpl( P ==gt Q -(PI) v QI ) - I
rmimpl(P PI) rmimpl(Q QI)
rmimpl( all(X P) aI(X PI) ) - 1
rmimpl(P PI)
rmimpl( exists(X P) exists(X PI) ) -
rmimpl(P PI)
rmimpl( exists(I X P) exists(I X PI) ) -
rmimpl(P PI)
rmimpl( P amp Q PI amp Ql ) -
rmimpl(P PI) rmimpl(Q Ql)
rmimpl( P v Q PI v QI ) -
rmimpl(P PI) rmimpl(Q QI)
rmimpl( -(p) -(PI) ) - I
rmimpl(p PI)
rmimpl( P P )
St~p 3 Converting numerical amp distinctive quantifiers
L Numerical quantifiers
examples of input forms
1 exists(gt= i X pIX)) where i is an integer
2 exists(i X pIX)) where i is an integer
3 exists(i j X pIX)) where i j are integers and iltj
4 exists(il v i2 X pIX)) where is are integers
examples of output forms of this step
1 exists(X pIX) amp number(X gt= i) )
2 exists(X pIX) amp number(X i) ) 3 exists(X pIX) amp number(X ij) ) 4 exists(X pIX) amp number(X il v i2) )
II Distinctive quantifiers
27
example or input Corm
exists([XYL p(X Y))
example or output Corm or this step
exists(X exists(Y p(XY)) )
conv(P lt=gt Q PI lt=gt QI) - 1
conv(P PI) conv(Q QI)
conv(al1(X P) all(X PI)) -
conv(P PI)
conv(exists(HIT] P) R ) - conv(P PI) convert distinctive quantifier
convtdis(exists([HIT]PI) R)
conv( exists(I X P) exists(X PIamp number(X I) )) -
conv(P PI) convert numerical quantifier
conv(exists(X P) exists(X PI)) - 1
conv(P Pl)
conv(P amp Q PI amp QI) - 1
conv(P PI) conv(Q QI)
conv(P v Q PI v QI) - t conv(P PI) conv(Q QI)
convC(P) -(PI)) -
conv(P PI)
conv(P Pl
convtdis(existsl[XL P) exists(X P)) - atomic(X) convtdis(exists[XIYj Pl exists(X R)) shy
convtdis(exists(Y P) R)
Step 4 Rewriting compound predicates andor compound selectors
Outputs are smiple predicates andor simple selectors
rewrite(P lt=gt Q PI lt=gt QI) - t rewrite(P PI) rewrite(Q QI)
rewrite(all(X Pl all(X PI)) - 1 rewrite(P PI)
rewriteexists(X P) exists(X PI)) - I rewriteP PI)
rewrite(P amp Q PI amp QI) - rewrite(P P 1) rewrite( Q Q 1
rewrite(P v Q PI v QI) - 1
rewrite(P PI) rewrite(Q QI)
rewriteC(P) -(PI)) - I
28
rewrite(P PI) rewrite(F(A B) R) -
rewrite(A AI) rewrite(B BI) re(F(AI BI) R)
rewrite(F(A) R) -
rewrite(A AI) re(F(AI) H)
rewrite(F(A B C) R) -
rewrite(A AI) rewrite(B BI) rewrite(C CI) re(F(AI BI CI) R)
rewrite(F(A B C D) R) -
rewrite(A AI) rewrite(B Btl rewrite(C CI) rewrite(D DI) rc(F(AI BI CI Dl) H)
rewrite(PP)
re(F(A B v el (RI v R2) -
re(F(A Bl RIl re(F(A C) R2) reF(A B amp cl (RI amp R2)) -
re(F(A B) RI) re(F(A e) R2) re(F(A amp B C) (Rl amp R2)) -
re(F(A e) R 1) re(F(B C) R 2) re(F( v B el (R I v R2)) -
re(F(A el R I) reFB el R2) re(F(A amp Bl (R I amp R2)) -
re(F(A RI) re(F(BJH2) re(F(A v B) (R 1 v R2)) -
re(F(A) RI) re(F(B) R2)
re(F(A vB c Dl (RI v R2) -
re(F(A C D) RI) re(F(B C D) R2) re(F(A amp B C D) (RI amp R2)) -
re(F(A C D) Rll re(F(B C D) R2) re(F(A B v C D) (HI v R2)) -
re(F(A B D) RI) re(F(A C D) R2) re(F(A B amp C D) (HI amp R2)) -
re(F(A B D) RI) re(F(A C D) R2) re(F(A B C v D) (RI v R2)) -
re(F(A B C) R I) reF(A B D) R2) re(F(A B C amp D) (RI amp R2)) -
29
re(F(A B C) RI) re(F(A B D) RZ)
re(F(A v B e D E) (R I v R2)) -
re(F(A e D E) R I) re(F(B e D El R2) re(F(A amp B e D E) (RI amp RZ)) -
re(F(A e D El R 1) re(F(B e D E) R2) re(F(A B v e D E) (R I v R2)) -
re(F(A B D E) RI) re(F(A e D E) R2)
re(F(A B amp e D E) (RI amp R2)) -
re(F(A B D El RI) re(F(A e D E) RZ) re(F(A B e v D E) (R I v R2)) -
re(F(A B e El R 1) re(F(A B D E) RZ) re(F(A B e amp D E) (RI amp RZ)) -
re(F(A B e E) R I) re(F(A B D E) RZ)
re(F(A B e D vEl (RI v RZ)) - l
rc(F(A B C D) RI) re(F(A n e El RZ) re(F(A B e D amp El (RI amp RZ)) - ~
re(F(A B e D) RI) re(F(A B e El RZ)
re((A = B) (A = B)l-
re((A = Bl (A = 8)) -
retIA gt= BI (A gt= B)) -
re((A lt= B) (A lt= B)) -
re((A gt B) (A gt B))-
re((A lt Bl (A lt Bl)- re(A A)
Step) Bringing n(gation inwards
Degin(-(P) PI) - neg(P Pl)
negin(P lt=gt Q PI lt=gt Ql) - ~
negin(P PI) negiD(Q QI)
Degin(aU(X P) all(X PI)) - Degin(P PI) negin(exists(X P) exists(X PI))- negin(P PI) negin(P amp Q PI amp Ql) - Degin(P PI) negin(Q Ql)
Degin(P v Q PI v QI) - Degin(P PI) negin(Q QI) negin(P Pl
neg(-(P) PI) - negin(P PI)
neg(all(X P) exists(X PI)) - neg(P PI)
30
neg(exists(X P) all(X PI)) - neg(P PI)
neg(P amp Q PI v QI) - neg(P PI) neg(Q Ql)
neg(P v Q PI amp QI) - neg(P PI) neg(Q QI)
neg(P -(PH
Step 6 Dropping existnetial quanti6ers
dropexist(P lt=gt Q PI lt=gt QI Elerns) - dropexist(P PI Elerns) dropexist(Q QI Elerns)
dropexist(alJ(X P) all(XPI) Elerns)
dropexist(P PI [XIElernsJ)
dropexist(exists(X P amp nurnber(X Yraquo P2 Elerns) -
genfun(skn Newg) Fun = [NewgIElerns]
subst(FuD X P amp Dumber(X Y) PI)
dropexist(Pl P2 Elerns)
dropexist(exists(X P) PZ Elerns) -
genfun(skrn Newf) Fun = [NewfIElernsJ
subst(Fun X p PI)
dropex ist(P 1 P~ Elerns)
dropexist(P v Q PI v QI Elerns) - ~
dropexist(P PI Elerns) dropexist(Q Ql Elerns)
dropexist(P amp Q PI amp QI Elerns) - 1
dropexist(P Pl Elerns) dropexist(Q QI Elerns)
dropexist(P P _)
gen fun(R oot Newn arne) shy
getnurn(Root Nurn)
narne(Root Rootlist)
append(Rootlist[Nurnj Narnelist)
concat(Narnelist Newnarne)
getnurn(Root Nurn) shy
retract(currentnurn(Root Nurn 1 raquo
Nurn is Nurni + 1
asserta(currentnurn(Root Nurn))
getnurn(Root 1) - asserta(currentnurn(Root 1))
subst(New Old Val Val) - var(Val)
subst(New Old Old New) - 1 substNew Old Val Val) - atornic(Val)
31
subst(New Old Val Newval) shy
runctor(Val F N)
CUDctor(Newval F N)
subst_args(N New Old Val Newval)
subst_args(O J J - J J
subst_args(N New Old Val NewVal) shy
arg(N Val OldArg)
arg(N NewVal NewArg)
subst(New Old OldArg NewArg)
NI is N - I
subst_args(Nl New Old Val NewVal)
append([J L L) -
append([XILl] L2 [XIL3]) - append(Ll L2 L3)
Step - Dropping universal quantifiers
dropall(P lt=gt Q PI lt=gt QI)-
dropall(P PI) dropall(Q QI)
dropall(all(X P) PI) - ~ dropall(P PI)
dropall(P amp Q PI amp QI) -
dropall(P PI) dropall(Q QI)
dropall(P v Q PI v QI) -
dropall(P PI) dropall(Q QI)
dropall(P P)
Step 8 Distributing conjunctions over disjunctions
distrib(P lt=gt Q PI lt=gt Ql) - t distrib(P PI) distrib(Q QI)
distrib(P v Q R) -
distrib(P PI) distrib(Q QI)
distributing(PI v QI R)
distrib(P it Q PI it QI) -
distrib(P PI) distrib( Q QI)
distrib(P P)
distributing((P amp Q) v R PI amp QI) -
distrib(P v R PI) distrib(Q v R Ql)
32
distributing(P v (Q amp R) PI amp Ql) -
distrib(P v Q PI) distrib(P v R Ql)
distributing(P P)
Step 9 Packing each conjunction into clauses
c1ausify(P amp Q CI C2) -
clausiCy(P CI C3) c1ausify(Q C3 C2)
cbusiCy(P [d(A B)ICs] Cs) shy
inclause(P A [j B [I) 1
c1ausiry( C C)
inclause(P v Q A AI B B1) -
inc1ause(P A2 AI B2 Bl)
inclause(Q A A2 B B2)
inclausenp) A A B1 B) -
notin(P A) putin(P B B1)
inclause(P AI A B B) shy
notin(P Bl putin(P A AI)
notin(X [XU) - fail
notin(X [JLj) - notin(X L)
notin(X 1])
putin(X II [X]) - 1
putin(X [XILJ L) -
putin(X [YILJ [YILl]) - putin(X L Ll)
Step 1Oa Printing clauses
printcl([]) - nl nl
printcl(c1(AB)ICsj) - printcl(A Bl nl printcl(Cs)
printcl(L II) - printdis(IL) prinr)middot
printclHl L) - prin(contradiction(() printconl(rL)
print()) - ) printconj(rL) prinr )
printcl(Ll L2) shy
printdis(ILl) print( - ) printconj(rL2) prin()
printdis(S[Lj) - printcbar(SL)
33
printdis(S[LILs]) - printchu(SL) prin( v) printdis(SLs)
printconl(S[LI) - printchar(SL)
printconl(S[LILs]) - printchar(SL) prin( ) printconl(SLs)
printconj(S[L]) - tab(3) printchar(SL)
prin tconj( S [L IL sl) shy
tab(3) printchar(SL) print( ) printconj(SLs)
printchar(SP) shy
atomic(P)
name(P L)
L = [IT]
concat([XIT NewP)
prin(~ewP)
printchar(SP) shy
atomic(P)
prin(P)
printchar(SA lt= gt B) -
prin((l clausify(A AI [j) pl(eAl) prin())
print lt=gt )
prin(() cbusify(B Bl [I) pJ(eBl) prine))middot
printchar(rnumber(X N)) shy
prin(num() printchar(rx) prin( )
printchar(rN) prinC))
printchar(rF(A B)) shy
seJec(F(A B))
prinCsel() printchar(rA)
prin( F ) printchar(rB) prinC))
printchar(SF(A B)) shy
( selec(F(A B)) F = infix )
printchar(SA) prin( F ) printchar(SB)
printchar(SF(A)) shy
(F= prefix gt= F= prefix lt= F= prefixgt F= prefix lt )
prin(F ) printcbar(SA)
printchar(SP) shy
functor(P F MaxN)
prin(F ()
Nl is MaxN - 1
putout(S N 1 P MaxN)
34
prin())
putout(S 0 P MaxN) -
arg(~laxN P Argu)
prin tchar(SArgu)
putout(S N p MaxN) shy
Nt is MaxN - N arg(NI P Argu)
printcbar(SArgu )
prin( )
N2 is N - 1
putout(S N2 P MaxN)
selec(FA B)) shy
( F= infix = F= infix f= F= infix gt=
F= infix gt F= infix lt= F= infix lt )
35
----------------------------------Program Name APClS - Part 2 Inference Mechanism ---------------------------------- a(X) shy
steps(X X9)
(( X9 =[] nl
print( yes it is always true) )
( X9 =[cI(IJ[])] nl
print( no it is always false) )
( nl nl printel(X9) Step 1Oa
tell(temp_file) printel(X9) e1ose(temp_file) consult(temp_6Ie) ))
q(X) shy
asserta( in pt(X))
steps(X X9)
(( X9 = [] print(middot~H~~middot~t~)
print(THE AiSWER IS YES)
print( ilgIQlQl(~) )
( X9 = [e1([j [j)] Pr1nt ( OJ fi(i I~ iii Ij)middot(i)(i) fiyenQ)riiio(i)(ij)(i)fj)fiyen1li1il1li1il)__ gtw~ __~_~ _~~_ ~_-=~
print(THE ANSWER IS NO ) print() )
( teI1(temp_6Ie)
prques(X9) Step 1Ob
close(temp_file)
nl print(Let me think about it) nl
consult(temp_6Ie) ))
retrac t( in pt(X))
Step lOb Printing question
prques(lcl(A 8)1) - prin(goo(() pl(qA 8) print()))
prques([c1(A 8HCs]) - prin(goo(() pl(qA 8) print() pl(q Cs)
pl(e [c1(A 8)]) - pl(eA 8)
pl(q [c1(A 8)]) - pl(qA 8) print()))
pl(S [e1(A B)ICs]) - pl(SA B) prin( ) pl(S Cs)
38
pl(q [j L) - prin(c1ause(contradiction(() pcont(qL) prin())_))
pl(S [I L)- prin(so2(contradidion(() pcont(SL) print))))middot
pl(S [L] []) - prin(so2() pcbar(SL) prin())
pl(S L [J)- prinsol() plett(SL) print))
pl(S [L] LI) - prin(condi(() pchar(cL)
prin(() pcont(S Ll) prine))))
pl(S L Ll)- prin(c1ause() plert(cL)
prin(() pcont(S Ll) prine)))
plert(S[LJ) - pchar(SL)
plert(SjLILsj) - pcbar(SL) print v) pleCt(SLs)
pcont(S[L]) - pchar(SL)
pcont(S[LILsj) - pcbar(SL) prinr ) pcont(SLs)
pcbar(SP) shy
atomic(P)
name(PL)
( L = [IT] L = [5 k miT] L = [5 k niT] )
concat[XITj NewP)
prin(0JewP)
pchar(SP) shy
atomic(P)
prin(P) pchar(SA lt=gt B) -
prin(() dausify(A AI []) pl(eAI) prin())
prinr lt=gt ) prin(() dausify(B BI ]) pl(eB) print))
pchar(Snumber(X N)) shy
prin(num() pchar(SX) prin()
pchar(SN) prinr))
pcbar(SM N) - prin(M N)
pcbar(cF(A B)) shy
selec(F(A Braquo
pcbar(cA)
prine F ) pchar(cB) pchar(SF(A B)) shy
selec(F(A B))
prin(sel() pchar(SA)
print F ) pchar(SB) print)) I
31
pc har(SF(A)) shy
( F= prefix gt= F= prefix lt= F= prefixgt F= prefix lt )
prin(F ) pchar(SA)
pchar(SP)shy
runctor(P F MaxN)
prin(F ()
011 is MaxN - 1 pout(SNl P MaxN)
print) )
pout(S 0 P M3xN) - 1
arg(~bxN P Argu)
pchlr(SArgu )
pout(S N P MaxN shy
Nl is MaxN - N
arg(Nl P Argu)
pchar(SArgu
prin( )
N2 is N - 1
pout(S N2 P ~13xN)
Comparing numbers in numerical quantifiers
num(XN) shy
number(X I)
cnum(N 1) ~
cnumlaquo=01 lt=I- N gt=I
cnumlaquo=J lt I) - N gt=1-1
cnumlaquo=NIJ) - N gt=J 1
cnumlaquo=N J)- integer(I) N gt=I~
cnum(gt=N gt=1) - N lt=1
cnum(gt=N gt I) - N lt=1+ 1 cnum(gt=NIJ) - N lt=1
cnum(gt=N lt=1)- N lt=1
cnum(gt=N lt I) - N lt=1 L cnum(gt=N 1)- integer(I) N lt=1
cnum( lt N lt 1)- N gt=1 L
38
cnum( lt N lt=1) - N gt I cnum( lt NLJ) - N gt J
cnum( lt N 1)- integer(I) N gt 1
cnum(gt N gt I) - N lt=1 cnumlgt i gt=1) - N lt I
cnum(gt N lt=1) - N lt=0
cnum(gt N lt I) - N lt=0
cnum(gt iIJ) - N lt I cnum(gt N 1)- integer(I) N lt I
cnum(~LN lt=1) - M=I N gt= I l
cnum(~LN lt I) - M=l N gt= I-I
cnum(~LNLJ) - M lt =1 N gt = J
cnum(~1N 1)- integer(I) M lt= I N gt= I
cnum(- N) - integer(N)
Comparing selectors
sel(X = Y) shyX= Y
sel(X I=Y) shy(X I=Y X lt Y Xgt Y)
sel(X gt Y) shyXgt Y
sel(X lt Y) shyXlt Y
selX gt=Y) shy(X gt=Y X= Y Xgt Y)
se(X lt=Y) shy
(X lt=Y
X= Y
X lt Y)
csel(infix = infix =)
39
csel(infix = infix = csel(infix = infix gt)
csel(infix = infix lt) csel(infix gt infix gt) cseJ(infix lt infix lt) csel(infix gt= infix gt=) csel(infix gt= infix gt csel(infix gt= infix =)
csellinfix lt= infix lt=) csel(infix lt= infix lt) csel(infix lt= infix =)
Finding solutions
sol(X v Y) -
(( notetra(X) eon(X) ( sol(Y) )
( c1ause(P v Q R) not(cketra(P v Q))
dis(P v Q X v Y R) ~ )
( A lt=gt B equival(A lt=gt B X v Y) ~ I) sol(X) - ~ notetra(X) eon(X)
so~(X) - notetra(X)
( con (X)
( clause(P v Q R) not(ekctra(P v Q)) dis(P v Q X R) I)
cketra(P v Q) -
eketra(P) eketra(Q) eketra(F(I J)) shy
selec(F(I J))
c1ause(contradiction(sel(F(IJ))) _I
eketra(number(W I)) -
clause(cootradietion(num(Wl)) - eketr(P) shy
clause(contradiction(P) - 1
notctra(P) shy
not( e lause( con tradiction(P) _))
40
Searching (or disjunctions
dis(P v Q X v Y R) - dis(P X v Y R)
dis(Q X v Y R) con(R)
dis(P v Q X R) -
dis(P X R) dis(Q X R) con(R
dis(P X v Y R) - clause(contradicton(Pl J 1
dis(F(I J) sel(G(I J)) v Y R) - csel(G Fl dis(number(WI) num(W N v Y R) - cnum(N I)
dis(P P v Y R) -
dis(P X v Y R) - dis(P Y R)
dis(F(I J) seJ(G(IJ)) R) - csel(G F)
dis(number(WI) num(WN) R) - cnum(N I) dis(P P R) - 1
dis(FJ J X R) shy
( ckctra(F(IJ) cbeckeq(seJ(F(IJ))) )
dis(number(W Il X R) - ( ckctra(number(WI)) cbeckeq(num(WI)) )
dis(P X R) shy( ckctra(P) cbeckeq(P) ) 1
cbeckeq(P) shy
(( A lt=gt so2(contradiction(P))
bagof(A A [jj) ) ( so2(contradiction(P)) lt=gt B
bagof(B B Uj) ))
ckeq(A) shy
( so2(A) lt=gt B B lt=gt so2(A) ) bagof(B B UJ)
con((P Q)) -
clause(P R) con(R) con(Q) con(true) -
con(contradiction(P)) - clause(contradiction(P) J
con(cause(X Y)) - cause(X Y)
con(sel(X)) - sel(X)
con(num(X Y)) - num(X Y) con(P)- (( dause(P R) (con(R) ckeq(R)))
colJectin(P) )
collectin(P) shy
bagof(S (c1ause(P S) S = true) [L LIJ )
mkcon(L Ll L)
bagor(l (L2 ) UJ) L
mkcon((A AI) (B B1) (sol(A v B) e D)) -
mkcon(A B1 e) mkcon(A1 (B Bl) D)
mkcon(A (B B1) (sol(A v B) e)) -
mkcon(A Bl e)
mkcon((A AI) B (sol(A v B) e)) middot1
mkcon(Al B e)
mkcon(A B sol(A vB))
Searching ror equivalences
equival(A lt=gt B X v Y) - 1 ( equival(A lt=gt B X) equival(A lt=gt B Y) )
equival(s02(A) lt=gt 502(B) A) - clause(B _I equival(s02(B) lt=gt 502(A) A) c1ause(B _I
Top level or inrerence mechanism
goo((s02(whatnum) P)) -
getatm(P Xl
bagor(number(X Y) ( P so2(number(X Y)) ) A )
count1(A 00 L R) nl
bagor(X P B )
count2(B L R Ll Rl) nJ print()
(( LI = 0 Rl = 0 print(THE ANSWER IS ) nl
(( Ll = Rl prin(-Jumber or ) prn(P) print(is Ll) )
( Rlgt20000 prin(Number or I prn(P) print(is LI or more) )
42
( prin(Number of ) pfn(P) print( is from Ll to Rl) )) )
( print(THE ANSWER IS NO I )) print()
goo(X) shy
(( bagof(X X L) L = [I nl print()
print(THE ANSWER IS YES) nl wout(L) print() )
( equiv(X L) nl print()
print(THE ANSWER IS YES) nl wout(L) print(-) )
( c1ause(inpt(A ==gt B) _I ( impli(A B Z) impli(B A Z) ) print(l~Hl)
printTHE ANSWER IS YES) nl print(Z) print(Hj~(fH~) ))
goo(X) print( Hg)
print(THE ANSWER IS NO ) print( lH~lH~gg9l9lmiddotmiddot~Q(gmiddot)
00 Semhing for implications in equiV3lent relations
impli( B Z) shyt-ell( z1) prin(templ() pchn(S A lt=gt B) print()) close ( zl) consult(zl) templ(Z)
unload zl Z
Searching for equivalence
equiv (X L)
(( X lt=gt Y
equ(Y YI)t bagof(Y Yl L) L = [j )
(Y lt=gt X equ(Y YI) bagof(Y Yl L) L = [J )
( X = F(New)
clause(~ew T) makeup(T Tl)
(( Tl lt=gt B
equ(B Bl) bagof(Bl Bl M) M = [j L=[Newl )
(A lt=gt TI
equ(A AI) bagof(Al AI M) M = 1] L=INewj )) ))
makeup((A B) (AI Bl)) -
makeup(A A1) makeup(B BI)
makeup(A so2(A))
equ((A B) (AI BI)) -
equ(A AI) equ(B Bl)
equ(sol(X v Y) sol(XI v Yl)) -
equ(X XI) equ(Y YI)
equ(so2(X) so2(XI)) -
equ(X XI)
equ(contradiction(X) clJuse(contradiction(X) X) ) -
equ(X X)
Counting numbers
getatm((A B) X) -
( getatm(A X) getatm(B X) )
getatm(so2(F(X)) X) -
getatm(so2(X) X) - atom(X)
countl([J L R L R) -
countl([number(X Y)IT] L R L2 R2) shy
(( Y = (gt=~) LI is L + N Rl is R + 20001 l )
( Y = (gt N) LI is L+ N+ 1 RI is R + 20002 )
(Y == laquo=~) LI is L + 1 Rl is R + N )
(Y = laquo N) LI is L + 1 RI is R+N-I)
(Y == IJ LI is L + I Rl is R + J ) ( Y == N L1 is L + N RI is R + N ))
count1(T LI R 1 L2 R2)
count2(fJ L R L R) - 1
count2([XITJ L R L2 R2) shy
name(X Xl)
(( Xl = sknj LI is L Rl is R )
44
( Xl = Iskmj L1 is L + 1 RI is R + ZOOO1) ( LI is L + I RI is R + I ))
count2(T LI RI L2 R2)
pfn((A B)) - pfn(A) prn(B)
pCn(so2(F(X))) - prin(F )
prn(so2(X)) - atom(X) prin(X ) prn (so2(X))
Printing result
wout([XlJ - prt(X) nl woutf[xIY]) - prt(X) nl nl wout(Y)
prt(e(A B)) -
prt(A) prinr 8 ) prt(ltE) prt(eA) - prt(A)
prt(c(A EJ) - prin() prt(A) prine ) prt(B) prin(T)
prt(c A) - prt(A) prt((A E)) - ~
prt(A) nl prt(E) prt(sol(X v Y)) - ~
prt(X) prinC v) prt(Y) prt(A lt=gt B) -
prt(e A) prinC lt=gt ) prt(e B) prt(sol(X)) - prt(X)
prt(so2(X)) - prt(X
prt(c1ause(X Y)) - prt(X)
prt(contradiction(X)) - prin(contradiction() prt(cX) prinr))middot prt(num(XY)) - prin(number(X Y)) prt(sel(X)) - prin(X) prt(X v Y) - prt(X) prin( v) prt(Y) prt(X) prin(X)
Handling conditional queries
condi((Y Xl) shy
assertcon(X) Y
45
retractcon(X)
condi((B A))
retractcon(A) fail
assertcon((A B)) 1
assertcon(A) assertcon(B)
assertcon(A) asserta(A)
retrac teon ((A B)) 1
retracteon(A) retractcon (B)
retraetcon(A) - retract(A)
BIBLIOGRAPHIC DATA SHEET
Report No UIUCDS-F-84-928
3 Recipients Accession No
4 T ide and Subt ltle
An Annotated Predicate Calculus Inference System (APCIS)
S Report Date
November 1984 6
7 Author(s)
Kah-Eng Pua 8 Performing Organization Rept
No
9 Performing Organization Name and Address
Department of Computer Science University of Illinois Urbana IL
10 ProjectTaskWork Unit No
11 Contract Grant No NSF DCR 84-06081 ONR N00014-82-K-0186
12 Sponsoring Organization Name and Address
National Science Foundation Washington DC
13 Type of Report amp Period Covered
14
15 Supplementary Notes
16 Abstracts
This paper describes a deductive inference system called APCIS (Annotated Predicate Calculus Inference System) APCIS is able to carry out inferences from expressions involving numerical quantifiers selectors disjunctions of non-negated terms negated terms disjunctions of negated terms equivalences and exceptions It is also able to count the numbers of occurrence of a given simple term or a conjunction of terms The design of contradiction and the treatment of the disjunction of non-negated terms allow APCIS to accept Horn clauses as well as non-Horn clauses and to carry out inferences from them This feature makes APCIS more general than Prolog
17 Key lords and Document Analysis 170 Descriptors
APC (Annotated Predicate Calculus) APCIS (Annotated Predicate Calculus Inference System) Horn Clause Numerical Quantifier Prolog Selector
17b IdentifiersOpen-Ended Terms
17c COSATI FieldGroup
18 Availability Statement 19 Security Class (This
Re~f~~IA~SIF IFf)
21 ~o of Pages
49 211 ecurity Class (This
PageUNCLASSIFIED
22 Price
FOA NTIS n (10middot70 usco-oc 40329-
18
weight( skm 1 ) gt weight( skm2 )
Now it we want to ask Is it true that there exists two boxes of different weights and type in
q( exists( [X Yl box(X) amp box(Y) amp ( weight(X) = weight(Y) ) ) )
The question will be transformed to the following query and entered to Prolog
goo(( so( box(XI) ) s02( box(X2) ) so2( sel( weightXI) = weight(X2) )) ))
Note that the selector in the above query is surrounded by the functor set When any clause or
8el in APCIS is activated it will search through the database to see it there is any selector whose
two arguments (left and right side or any selector symbol) match the two arguments of the
selector in the query At the same time 8el will check iC the selector symbols (may be different) or
the two different selectors (one in the query and one in the database) satisfy the rules defined in
sel There are 12 matching rules defined in sel All oC them ~re straightforward and will not be
discussed here An example will be enough to explain how 8el works
Consider the execution of the above transformed query The first two terms in the query
are satisfied by the first two terms in the database and Xl and X2 are instantiated to skml and
skm2 respectively The third term of the query will be passed to eel (of APCIS) which finds a
match on each side of the two selectors (one in the query and one in the database) At the same
time the two different selector symbols gt and = are found to satisfy one of the rules in
8el As a result the query succeeds
To enhance the inference power of clauses involving selectors all the selectors appearing
on the rightmiddothand side oC any clause will be surrounded by a functor set The idea is similar to
that in the last part of the previous section
c8el is exactly the same as 8el functionally It provides a convenient way to compare
selectors when dis is being executed
19
8 Printing Result
Whenever a goal is successfully executed APCIS will not only response with a yes but
also print out the matched terms or clauses in the database This is made possible by the built-in
function bagor and the two predicates wout and prt defined in APCIS
7 Summary
In this paper a description of a deductive inference system called APCIS (Annotated
Predicate Calculus Inference System) has been provided APCIS is able to carry out inferences
from expressions involving numerical quantifiers selectors disjunctions of non-negated terms
negated terms disjunctions of negated terms equivalences and exceptions It is also able to count
the numbers of occurrence of a given simple term or a conjunction of terms
The main idea of APCIS is that each input APC expression is first passed to a
preprocessor ( ie APC translator ) which dissolves and transforms each APC expression into
Prolog expression(s) which will then be loaded to Prolog system The user bas to specify whether
each input expression is to be entered as an assertion or as a query by invoking either assertion
mode or query mode respectively Each assertion or query will undergo different transformations in
the preprocessor The different treatment of assertion or query not only allows a full uS1ge of the
Prolog inference mechanism but also makes possible a higher level of inexact pattern matching
exemplified by the examples in Section 51 and Section 52 where the four predicates num
cnum sel and csel are discussed This higher level of pattern matching increases the inference
power of APCIS greatly
The design of contradiction and the treatment of the disjunction of non-negated terms
allow APCIS to accept non-Horn clauses and to carry out inference from them This feature
makes APCIS more general than Prolog
20
While APCIS performs very well in many sets of arguments provided by the author it is
still too early to jump to conclusion that it can perform equally well in all types of problems In
any event the expressiveness of APC has greatly been retained in the present version of APCIS
and moreover some design ideas or APCIS mentioned in this paper are not restricted to APCIS
- they may be carried over to learning programs with narrower scopes
21
References
[1] W F Clocksin and C S Mellish Programming In Prolog Springermiddot Verlag Berlin Hpoundidelberg 1981
[2] R S Michalski A Theory and Methodology of Inductive Learning Chpt 4 Machine L earning Tioga Publishing Co Palo Alto CaliJornia 1989
[3] K-E Pua Translating Annotated Predicate Calculu8 to Prolog ISG Report 84middot1 UlUCDCSmiddotFmiddot918 University oj Illinois Urbana IL June 1984
22
Appendix A
APCIS Users Manual
1 Get Started
Users are urged to follow the steps depicted below
1 Get the PROLOG interpreter by typing
alias prolog mntb2sammutsammutprologprolog (Vax A)
or
alias prolog mntb2sammutsammutbinprolog (Vax B)
2 Load apc and infer by typing
prolog apc infer
When large APC expressions are expected we can increase the stlck by typingI
prolog -snnnn ape infer
where ns denote the number of stacks in decimal
3 When the wording LSW - PROLOG appears on the terminal we are reldy to interact
with APCIS The four modes by which we can invoke APCIS are summarized below
a Assert ion-Translation Mode
ta(X)
b Query-Translation Mode
tq(X)
c Assertion Mode
a(X
d Query Mode
q(X)
23
where Xs are APC expressions
2 Notations Used in APCIS
Below is a summary or notations used in APCIS
a Logical operators
amp
v
==gt
lt=gt
-
negation
conjunction
disjunction
implication
equivalence
exception
b Binary relation symbols in selectors
-
=
gt=
lt=
gt
lt
equal
not equal
greater or equal
smaller or equ al
greater
smaller
c Relational operators in numerical quantifiers
lt less than
lt= less than or equal
gt greater than
gt= greater than or equal
d BinlTY operator in numerical quantifier
range
e Universal quantifier
all(X p(X))
f Existential quantifier
exists(X p(X))
g Numerical quantifier
exists(I X p(X))
where p(X) is a formula
where X is a variable or a Jist of variables or the
form [HI~rj and p(X) a formula
where I repersents expression involving integer(s)
and operator(s) in c or d above and p(X) a formula
25
Appendix B
APCIS Program Listings
------------------------------- Program Name APCIS - Part 1 APC Translator
-------------------------------
op(3OO fx -)1
op(500 xfy amp)
oPt 500 xfy v)
op(600 xfx )
op(700 fx [gt= lt= gt lt ]) op(400 xfy [= gt= lt= gt lt ])1 op(900 xfy gt lt=gt -])1
steps(X Xg) shy
numbervars(X 1 J Step 1 change variables to iis
rmimp(X X) Step 2 conv(X X3) Step 3
rewrite(X3 X4) Step 4
negin(X4 X5) Step 5
dropexist(X5 X6 1]) Step 6
dropall(X6 X7) Step 7
distrib(X7 X8) Step 8 clausiCy(X8 X9 [J) Step 9
ta(X) shysteps(X Xg)
(( Xg = II nl
print( yes it is always true) )
( nl nl printcl(X9))) Step 10a
tq(X) shy
steps(X Xg)
prques(Xg)
28
Step 2 Removing implic3tions amp Transforming exceptions and equiv3lences
rmimpl( P - Q (PI lt=gt (QI) ) amp ((PI) lt=gt QI) ) -
rmimpl(P PI) rmimpl(Q QI)
rmimplnp) lt=gt Q (PI lt=gt -(QI)) amp nPI) lt=gt QI) ) - 1
rmimpl(P PI) rmimpJ(Q QI)
rmimpJ(P lt-gt -(Q) (PI lt=gt -(QI)) amp nPI) lt=gt QI) ) -
rmimpl(P PI) rmimpl(Q QI)
rmimpl( P lt=gt Q PI lt=gt QI ) - I
rmimpl(P PI) rmimpl(Q QI)
rmimpl( P ==gt Q -(PI) v QI ) - I
rmimpl(P PI) rmimpl(Q QI)
rmimpl( all(X P) aI(X PI) ) - 1
rmimpl(P PI)
rmimpl( exists(X P) exists(X PI) ) -
rmimpl(P PI)
rmimpl( exists(I X P) exists(I X PI) ) -
rmimpl(P PI)
rmimpl( P amp Q PI amp Ql ) -
rmimpl(P PI) rmimpl(Q Ql)
rmimpl( P v Q PI v QI ) -
rmimpl(P PI) rmimpl(Q QI)
rmimpl( -(p) -(PI) ) - I
rmimpl(p PI)
rmimpl( P P )
St~p 3 Converting numerical amp distinctive quantifiers
L Numerical quantifiers
examples of input forms
1 exists(gt= i X pIX)) where i is an integer
2 exists(i X pIX)) where i is an integer
3 exists(i j X pIX)) where i j are integers and iltj
4 exists(il v i2 X pIX)) where is are integers
examples of output forms of this step
1 exists(X pIX) amp number(X gt= i) )
2 exists(X pIX) amp number(X i) ) 3 exists(X pIX) amp number(X ij) ) 4 exists(X pIX) amp number(X il v i2) )
II Distinctive quantifiers
27
example or input Corm
exists([XYL p(X Y))
example or output Corm or this step
exists(X exists(Y p(XY)) )
conv(P lt=gt Q PI lt=gt QI) - 1
conv(P PI) conv(Q QI)
conv(al1(X P) all(X PI)) -
conv(P PI)
conv(exists(HIT] P) R ) - conv(P PI) convert distinctive quantifier
convtdis(exists([HIT]PI) R)
conv( exists(I X P) exists(X PIamp number(X I) )) -
conv(P PI) convert numerical quantifier
conv(exists(X P) exists(X PI)) - 1
conv(P Pl)
conv(P amp Q PI amp QI) - 1
conv(P PI) conv(Q QI)
conv(P v Q PI v QI) - t conv(P PI) conv(Q QI)
convC(P) -(PI)) -
conv(P PI)
conv(P Pl
convtdis(existsl[XL P) exists(X P)) - atomic(X) convtdis(exists[XIYj Pl exists(X R)) shy
convtdis(exists(Y P) R)
Step 4 Rewriting compound predicates andor compound selectors
Outputs are smiple predicates andor simple selectors
rewrite(P lt=gt Q PI lt=gt QI) - t rewrite(P PI) rewrite(Q QI)
rewrite(all(X Pl all(X PI)) - 1 rewrite(P PI)
rewriteexists(X P) exists(X PI)) - I rewriteP PI)
rewrite(P amp Q PI amp QI) - rewrite(P P 1) rewrite( Q Q 1
rewrite(P v Q PI v QI) - 1
rewrite(P PI) rewrite(Q QI)
rewriteC(P) -(PI)) - I
28
rewrite(P PI) rewrite(F(A B) R) -
rewrite(A AI) rewrite(B BI) re(F(AI BI) R)
rewrite(F(A) R) -
rewrite(A AI) re(F(AI) H)
rewrite(F(A B C) R) -
rewrite(A AI) rewrite(B BI) rewrite(C CI) re(F(AI BI CI) R)
rewrite(F(A B C D) R) -
rewrite(A AI) rewrite(B Btl rewrite(C CI) rewrite(D DI) rc(F(AI BI CI Dl) H)
rewrite(PP)
re(F(A B v el (RI v R2) -
re(F(A Bl RIl re(F(A C) R2) reF(A B amp cl (RI amp R2)) -
re(F(A B) RI) re(F(A e) R2) re(F(A amp B C) (Rl amp R2)) -
re(F(A e) R 1) re(F(B C) R 2) re(F( v B el (R I v R2)) -
re(F(A el R I) reFB el R2) re(F(A amp Bl (R I amp R2)) -
re(F(A RI) re(F(BJH2) re(F(A v B) (R 1 v R2)) -
re(F(A) RI) re(F(B) R2)
re(F(A vB c Dl (RI v R2) -
re(F(A C D) RI) re(F(B C D) R2) re(F(A amp B C D) (RI amp R2)) -
re(F(A C D) Rll re(F(B C D) R2) re(F(A B v C D) (HI v R2)) -
re(F(A B D) RI) re(F(A C D) R2) re(F(A B amp C D) (HI amp R2)) -
re(F(A B D) RI) re(F(A C D) R2) re(F(A B C v D) (RI v R2)) -
re(F(A B C) R I) reF(A B D) R2) re(F(A B C amp D) (RI amp R2)) -
29
re(F(A B C) RI) re(F(A B D) RZ)
re(F(A v B e D E) (R I v R2)) -
re(F(A e D E) R I) re(F(B e D El R2) re(F(A amp B e D E) (RI amp RZ)) -
re(F(A e D El R 1) re(F(B e D E) R2) re(F(A B v e D E) (R I v R2)) -
re(F(A B D E) RI) re(F(A e D E) R2)
re(F(A B amp e D E) (RI amp R2)) -
re(F(A B D El RI) re(F(A e D E) RZ) re(F(A B e v D E) (R I v R2)) -
re(F(A B e El R 1) re(F(A B D E) RZ) re(F(A B e amp D E) (RI amp RZ)) -
re(F(A B e E) R I) re(F(A B D E) RZ)
re(F(A B e D vEl (RI v RZ)) - l
rc(F(A B C D) RI) re(F(A n e El RZ) re(F(A B e D amp El (RI amp RZ)) - ~
re(F(A B e D) RI) re(F(A B e El RZ)
re((A = B) (A = B)l-
re((A = Bl (A = 8)) -
retIA gt= BI (A gt= B)) -
re((A lt= B) (A lt= B)) -
re((A gt B) (A gt B))-
re((A lt Bl (A lt Bl)- re(A A)
Step) Bringing n(gation inwards
Degin(-(P) PI) - neg(P Pl)
negin(P lt=gt Q PI lt=gt Ql) - ~
negin(P PI) negiD(Q QI)
Degin(aU(X P) all(X PI)) - Degin(P PI) negin(exists(X P) exists(X PI))- negin(P PI) negin(P amp Q PI amp Ql) - Degin(P PI) negin(Q Ql)
Degin(P v Q PI v QI) - Degin(P PI) negin(Q QI) negin(P Pl
neg(-(P) PI) - negin(P PI)
neg(all(X P) exists(X PI)) - neg(P PI)
30
neg(exists(X P) all(X PI)) - neg(P PI)
neg(P amp Q PI v QI) - neg(P PI) neg(Q Ql)
neg(P v Q PI amp QI) - neg(P PI) neg(Q QI)
neg(P -(PH
Step 6 Dropping existnetial quanti6ers
dropexist(P lt=gt Q PI lt=gt QI Elerns) - dropexist(P PI Elerns) dropexist(Q QI Elerns)
dropexist(alJ(X P) all(XPI) Elerns)
dropexist(P PI [XIElernsJ)
dropexist(exists(X P amp nurnber(X Yraquo P2 Elerns) -
genfun(skn Newg) Fun = [NewgIElerns]
subst(FuD X P amp Dumber(X Y) PI)
dropexist(Pl P2 Elerns)
dropexist(exists(X P) PZ Elerns) -
genfun(skrn Newf) Fun = [NewfIElernsJ
subst(Fun X p PI)
dropex ist(P 1 P~ Elerns)
dropexist(P v Q PI v QI Elerns) - ~
dropexist(P PI Elerns) dropexist(Q Ql Elerns)
dropexist(P amp Q PI amp QI Elerns) - 1
dropexist(P Pl Elerns) dropexist(Q QI Elerns)
dropexist(P P _)
gen fun(R oot Newn arne) shy
getnurn(Root Nurn)
narne(Root Rootlist)
append(Rootlist[Nurnj Narnelist)
concat(Narnelist Newnarne)
getnurn(Root Nurn) shy
retract(currentnurn(Root Nurn 1 raquo
Nurn is Nurni + 1
asserta(currentnurn(Root Nurn))
getnurn(Root 1) - asserta(currentnurn(Root 1))
subst(New Old Val Val) - var(Val)
subst(New Old Old New) - 1 substNew Old Val Val) - atornic(Val)
31
subst(New Old Val Newval) shy
runctor(Val F N)
CUDctor(Newval F N)
subst_args(N New Old Val Newval)
subst_args(O J J - J J
subst_args(N New Old Val NewVal) shy
arg(N Val OldArg)
arg(N NewVal NewArg)
subst(New Old OldArg NewArg)
NI is N - I
subst_args(Nl New Old Val NewVal)
append([J L L) -
append([XILl] L2 [XIL3]) - append(Ll L2 L3)
Step - Dropping universal quantifiers
dropall(P lt=gt Q PI lt=gt QI)-
dropall(P PI) dropall(Q QI)
dropall(all(X P) PI) - ~ dropall(P PI)
dropall(P amp Q PI amp QI) -
dropall(P PI) dropall(Q QI)
dropall(P v Q PI v QI) -
dropall(P PI) dropall(Q QI)
dropall(P P)
Step 8 Distributing conjunctions over disjunctions
distrib(P lt=gt Q PI lt=gt Ql) - t distrib(P PI) distrib(Q QI)
distrib(P v Q R) -
distrib(P PI) distrib(Q QI)
distributing(PI v QI R)
distrib(P it Q PI it QI) -
distrib(P PI) distrib( Q QI)
distrib(P P)
distributing((P amp Q) v R PI amp QI) -
distrib(P v R PI) distrib(Q v R Ql)
32
distributing(P v (Q amp R) PI amp Ql) -
distrib(P v Q PI) distrib(P v R Ql)
distributing(P P)
Step 9 Packing each conjunction into clauses
c1ausify(P amp Q CI C2) -
clausiCy(P CI C3) c1ausify(Q C3 C2)
cbusiCy(P [d(A B)ICs] Cs) shy
inclause(P A [j B [I) 1
c1ausiry( C C)
inclause(P v Q A AI B B1) -
inc1ause(P A2 AI B2 Bl)
inclause(Q A A2 B B2)
inclausenp) A A B1 B) -
notin(P A) putin(P B B1)
inclause(P AI A B B) shy
notin(P Bl putin(P A AI)
notin(X [XU) - fail
notin(X [JLj) - notin(X L)
notin(X 1])
putin(X II [X]) - 1
putin(X [XILJ L) -
putin(X [YILJ [YILl]) - putin(X L Ll)
Step 1Oa Printing clauses
printcl([]) - nl nl
printcl(c1(AB)ICsj) - printcl(A Bl nl printcl(Cs)
printcl(L II) - printdis(IL) prinr)middot
printclHl L) - prin(contradiction(() printconl(rL)
print()) - ) printconj(rL) prinr )
printcl(Ll L2) shy
printdis(ILl) print( - ) printconj(rL2) prin()
printdis(S[Lj) - printcbar(SL)
33
printdis(S[LILs]) - printchu(SL) prin( v) printdis(SLs)
printconl(S[LI) - printchar(SL)
printconl(S[LILs]) - printchar(SL) prin( ) printconl(SLs)
printconj(S[L]) - tab(3) printchar(SL)
prin tconj( S [L IL sl) shy
tab(3) printchar(SL) print( ) printconj(SLs)
printchar(SP) shy
atomic(P)
name(P L)
L = [IT]
concat([XIT NewP)
prin(~ewP)
printchar(SP) shy
atomic(P)
prin(P)
printchar(SA lt= gt B) -
prin((l clausify(A AI [j) pl(eAl) prin())
print lt=gt )
prin(() cbusify(B Bl [I) pJ(eBl) prine))middot
printchar(rnumber(X N)) shy
prin(num() printchar(rx) prin( )
printchar(rN) prinC))
printchar(rF(A B)) shy
seJec(F(A B))
prinCsel() printchar(rA)
prin( F ) printchar(rB) prinC))
printchar(SF(A B)) shy
( selec(F(A B)) F = infix )
printchar(SA) prin( F ) printchar(SB)
printchar(SF(A)) shy
(F= prefix gt= F= prefix lt= F= prefixgt F= prefix lt )
prin(F ) printcbar(SA)
printchar(SP) shy
functor(P F MaxN)
prin(F ()
Nl is MaxN - 1
putout(S N 1 P MaxN)
34
prin())
putout(S 0 P MaxN) -
arg(~laxN P Argu)
prin tchar(SArgu)
putout(S N p MaxN) shy
Nt is MaxN - N arg(NI P Argu)
printcbar(SArgu )
prin( )
N2 is N - 1
putout(S N2 P MaxN)
selec(FA B)) shy
( F= infix = F= infix f= F= infix gt=
F= infix gt F= infix lt= F= infix lt )
35
----------------------------------Program Name APClS - Part 2 Inference Mechanism ---------------------------------- a(X) shy
steps(X X9)
(( X9 =[] nl
print( yes it is always true) )
( X9 =[cI(IJ[])] nl
print( no it is always false) )
( nl nl printel(X9) Step 1Oa
tell(temp_file) printel(X9) e1ose(temp_file) consult(temp_6Ie) ))
q(X) shy
asserta( in pt(X))
steps(X X9)
(( X9 = [] print(middot~H~~middot~t~)
print(THE AiSWER IS YES)
print( ilgIQlQl(~) )
( X9 = [e1([j [j)] Pr1nt ( OJ fi(i I~ iii Ij)middot(i)(i) fiyenQ)riiio(i)(ij)(i)fj)fiyen1li1il1li1il)__ gtw~ __~_~ _~~_ ~_-=~
print(THE ANSWER IS NO ) print() )
( teI1(temp_6Ie)
prques(X9) Step 1Ob
close(temp_file)
nl print(Let me think about it) nl
consult(temp_6Ie) ))
retrac t( in pt(X))
Step lOb Printing question
prques(lcl(A 8)1) - prin(goo(() pl(qA 8) print()))
prques([c1(A 8HCs]) - prin(goo(() pl(qA 8) print() pl(q Cs)
pl(e [c1(A 8)]) - pl(eA 8)
pl(q [c1(A 8)]) - pl(qA 8) print()))
pl(S [e1(A B)ICs]) - pl(SA B) prin( ) pl(S Cs)
38
pl(q [j L) - prin(c1ause(contradiction(() pcont(qL) prin())_))
pl(S [I L)- prin(so2(contradidion(() pcont(SL) print))))middot
pl(S [L] []) - prin(so2() pcbar(SL) prin())
pl(S L [J)- prinsol() plett(SL) print))
pl(S [L] LI) - prin(condi(() pchar(cL)
prin(() pcont(S Ll) prine))))
pl(S L Ll)- prin(c1ause() plert(cL)
prin(() pcont(S Ll) prine)))
plert(S[LJ) - pchar(SL)
plert(SjLILsj) - pcbar(SL) print v) pleCt(SLs)
pcont(S[L]) - pchar(SL)
pcont(S[LILsj) - pcbar(SL) prinr ) pcont(SLs)
pcbar(SP) shy
atomic(P)
name(PL)
( L = [IT] L = [5 k miT] L = [5 k niT] )
concat[XITj NewP)
prin(0JewP)
pchar(SP) shy
atomic(P)
prin(P) pchar(SA lt=gt B) -
prin(() dausify(A AI []) pl(eAI) prin())
prinr lt=gt ) prin(() dausify(B BI ]) pl(eB) print))
pchar(Snumber(X N)) shy
prin(num() pchar(SX) prin()
pchar(SN) prinr))
pcbar(SM N) - prin(M N)
pcbar(cF(A B)) shy
selec(F(A Braquo
pcbar(cA)
prine F ) pchar(cB) pchar(SF(A B)) shy
selec(F(A B))
prin(sel() pchar(SA)
print F ) pchar(SB) print)) I
31
pc har(SF(A)) shy
( F= prefix gt= F= prefix lt= F= prefixgt F= prefix lt )
prin(F ) pchar(SA)
pchar(SP)shy
runctor(P F MaxN)
prin(F ()
011 is MaxN - 1 pout(SNl P MaxN)
print) )
pout(S 0 P M3xN) - 1
arg(~bxN P Argu)
pchlr(SArgu )
pout(S N P MaxN shy
Nl is MaxN - N
arg(Nl P Argu)
pchar(SArgu
prin( )
N2 is N - 1
pout(S N2 P ~13xN)
Comparing numbers in numerical quantifiers
num(XN) shy
number(X I)
cnum(N 1) ~
cnumlaquo=01 lt=I- N gt=I
cnumlaquo=J lt I) - N gt=1-1
cnumlaquo=NIJ) - N gt=J 1
cnumlaquo=N J)- integer(I) N gt=I~
cnum(gt=N gt=1) - N lt=1
cnum(gt=N gt I) - N lt=1+ 1 cnum(gt=NIJ) - N lt=1
cnum(gt=N lt=1)- N lt=1
cnum(gt=N lt I) - N lt=1 L cnum(gt=N 1)- integer(I) N lt=1
cnum( lt N lt 1)- N gt=1 L
38
cnum( lt N lt=1) - N gt I cnum( lt NLJ) - N gt J
cnum( lt N 1)- integer(I) N gt 1
cnum(gt N gt I) - N lt=1 cnumlgt i gt=1) - N lt I
cnum(gt N lt=1) - N lt=0
cnum(gt N lt I) - N lt=0
cnum(gt iIJ) - N lt I cnum(gt N 1)- integer(I) N lt I
cnum(~LN lt=1) - M=I N gt= I l
cnum(~LN lt I) - M=l N gt= I-I
cnum(~LNLJ) - M lt =1 N gt = J
cnum(~1N 1)- integer(I) M lt= I N gt= I
cnum(- N) - integer(N)
Comparing selectors
sel(X = Y) shyX= Y
sel(X I=Y) shy(X I=Y X lt Y Xgt Y)
sel(X gt Y) shyXgt Y
sel(X lt Y) shyXlt Y
selX gt=Y) shy(X gt=Y X= Y Xgt Y)
se(X lt=Y) shy
(X lt=Y
X= Y
X lt Y)
csel(infix = infix =)
39
csel(infix = infix = csel(infix = infix gt)
csel(infix = infix lt) csel(infix gt infix gt) cseJ(infix lt infix lt) csel(infix gt= infix gt=) csel(infix gt= infix gt csel(infix gt= infix =)
csellinfix lt= infix lt=) csel(infix lt= infix lt) csel(infix lt= infix =)
Finding solutions
sol(X v Y) -
(( notetra(X) eon(X) ( sol(Y) )
( c1ause(P v Q R) not(cketra(P v Q))
dis(P v Q X v Y R) ~ )
( A lt=gt B equival(A lt=gt B X v Y) ~ I) sol(X) - ~ notetra(X) eon(X)
so~(X) - notetra(X)
( con (X)
( clause(P v Q R) not(ekctra(P v Q)) dis(P v Q X R) I)
cketra(P v Q) -
eketra(P) eketra(Q) eketra(F(I J)) shy
selec(F(I J))
c1ause(contradiction(sel(F(IJ))) _I
eketra(number(W I)) -
clause(cootradietion(num(Wl)) - eketr(P) shy
clause(contradiction(P) - 1
notctra(P) shy
not( e lause( con tradiction(P) _))
40
Searching (or disjunctions
dis(P v Q X v Y R) - dis(P X v Y R)
dis(Q X v Y R) con(R)
dis(P v Q X R) -
dis(P X R) dis(Q X R) con(R
dis(P X v Y R) - clause(contradicton(Pl J 1
dis(F(I J) sel(G(I J)) v Y R) - csel(G Fl dis(number(WI) num(W N v Y R) - cnum(N I)
dis(P P v Y R) -
dis(P X v Y R) - dis(P Y R)
dis(F(I J) seJ(G(IJ)) R) - csel(G F)
dis(number(WI) num(WN) R) - cnum(N I) dis(P P R) - 1
dis(FJ J X R) shy
( ckctra(F(IJ) cbeckeq(seJ(F(IJ))) )
dis(number(W Il X R) - ( ckctra(number(WI)) cbeckeq(num(WI)) )
dis(P X R) shy( ckctra(P) cbeckeq(P) ) 1
cbeckeq(P) shy
(( A lt=gt so2(contradiction(P))
bagof(A A [jj) ) ( so2(contradiction(P)) lt=gt B
bagof(B B Uj) ))
ckeq(A) shy
( so2(A) lt=gt B B lt=gt so2(A) ) bagof(B B UJ)
con((P Q)) -
clause(P R) con(R) con(Q) con(true) -
con(contradiction(P)) - clause(contradiction(P) J
con(cause(X Y)) - cause(X Y)
con(sel(X)) - sel(X)
con(num(X Y)) - num(X Y) con(P)- (( dause(P R) (con(R) ckeq(R)))
colJectin(P) )
collectin(P) shy
bagof(S (c1ause(P S) S = true) [L LIJ )
mkcon(L Ll L)
bagor(l (L2 ) UJ) L
mkcon((A AI) (B B1) (sol(A v B) e D)) -
mkcon(A B1 e) mkcon(A1 (B Bl) D)
mkcon(A (B B1) (sol(A v B) e)) -
mkcon(A Bl e)
mkcon((A AI) B (sol(A v B) e)) middot1
mkcon(Al B e)
mkcon(A B sol(A vB))
Searching ror equivalences
equival(A lt=gt B X v Y) - 1 ( equival(A lt=gt B X) equival(A lt=gt B Y) )
equival(s02(A) lt=gt 502(B) A) - clause(B _I equival(s02(B) lt=gt 502(A) A) c1ause(B _I
Top level or inrerence mechanism
goo((s02(whatnum) P)) -
getatm(P Xl
bagor(number(X Y) ( P so2(number(X Y)) ) A )
count1(A 00 L R) nl
bagor(X P B )
count2(B L R Ll Rl) nJ print()
(( LI = 0 Rl = 0 print(THE ANSWER IS ) nl
(( Ll = Rl prin(-Jumber or ) prn(P) print(is Ll) )
( Rlgt20000 prin(Number or I prn(P) print(is LI or more) )
42
( prin(Number of ) pfn(P) print( is from Ll to Rl) )) )
( print(THE ANSWER IS NO I )) print()
goo(X) shy
(( bagof(X X L) L = [I nl print()
print(THE ANSWER IS YES) nl wout(L) print() )
( equiv(X L) nl print()
print(THE ANSWER IS YES) nl wout(L) print(-) )
( c1ause(inpt(A ==gt B) _I ( impli(A B Z) impli(B A Z) ) print(l~Hl)
printTHE ANSWER IS YES) nl print(Z) print(Hj~(fH~) ))
goo(X) print( Hg)
print(THE ANSWER IS NO ) print( lH~lH~gg9l9lmiddotmiddot~Q(gmiddot)
00 Semhing for implications in equiV3lent relations
impli( B Z) shyt-ell( z1) prin(templ() pchn(S A lt=gt B) print()) close ( zl) consult(zl) templ(Z)
unload zl Z
Searching for equivalence
equiv (X L)
(( X lt=gt Y
equ(Y YI)t bagof(Y Yl L) L = [j )
(Y lt=gt X equ(Y YI) bagof(Y Yl L) L = [J )
( X = F(New)
clause(~ew T) makeup(T Tl)
(( Tl lt=gt B
equ(B Bl) bagof(Bl Bl M) M = [j L=[Newl )
(A lt=gt TI
equ(A AI) bagof(Al AI M) M = 1] L=INewj )) ))
makeup((A B) (AI Bl)) -
makeup(A A1) makeup(B BI)
makeup(A so2(A))
equ((A B) (AI BI)) -
equ(A AI) equ(B Bl)
equ(sol(X v Y) sol(XI v Yl)) -
equ(X XI) equ(Y YI)
equ(so2(X) so2(XI)) -
equ(X XI)
equ(contradiction(X) clJuse(contradiction(X) X) ) -
equ(X X)
Counting numbers
getatm((A B) X) -
( getatm(A X) getatm(B X) )
getatm(so2(F(X)) X) -
getatm(so2(X) X) - atom(X)
countl([J L R L R) -
countl([number(X Y)IT] L R L2 R2) shy
(( Y = (gt=~) LI is L + N Rl is R + 20001 l )
( Y = (gt N) LI is L+ N+ 1 RI is R + 20002 )
(Y == laquo=~) LI is L + 1 Rl is R + N )
(Y = laquo N) LI is L + 1 RI is R+N-I)
(Y == IJ LI is L + I Rl is R + J ) ( Y == N L1 is L + N RI is R + N ))
count1(T LI R 1 L2 R2)
count2(fJ L R L R) - 1
count2([XITJ L R L2 R2) shy
name(X Xl)
(( Xl = sknj LI is L Rl is R )
44
( Xl = Iskmj L1 is L + 1 RI is R + ZOOO1) ( LI is L + I RI is R + I ))
count2(T LI RI L2 R2)
pfn((A B)) - pfn(A) prn(B)
pCn(so2(F(X))) - prin(F )
prn(so2(X)) - atom(X) prin(X ) prn (so2(X))
Printing result
wout([XlJ - prt(X) nl woutf[xIY]) - prt(X) nl nl wout(Y)
prt(e(A B)) -
prt(A) prinr 8 ) prt(ltE) prt(eA) - prt(A)
prt(c(A EJ) - prin() prt(A) prine ) prt(B) prin(T)
prt(c A) - prt(A) prt((A E)) - ~
prt(A) nl prt(E) prt(sol(X v Y)) - ~
prt(X) prinC v) prt(Y) prt(A lt=gt B) -
prt(e A) prinC lt=gt ) prt(e B) prt(sol(X)) - prt(X)
prt(so2(X)) - prt(X
prt(c1ause(X Y)) - prt(X)
prt(contradiction(X)) - prin(contradiction() prt(cX) prinr))middot prt(num(XY)) - prin(number(X Y)) prt(sel(X)) - prin(X) prt(X v Y) - prt(X) prin( v) prt(Y) prt(X) prin(X)
Handling conditional queries
condi((Y Xl) shy
assertcon(X) Y
45
retractcon(X)
condi((B A))
retractcon(A) fail
assertcon((A B)) 1
assertcon(A) assertcon(B)
assertcon(A) asserta(A)
retrac teon ((A B)) 1
retracteon(A) retractcon (B)
retraetcon(A) - retract(A)
BIBLIOGRAPHIC DATA SHEET
Report No UIUCDS-F-84-928
3 Recipients Accession No
4 T ide and Subt ltle
An Annotated Predicate Calculus Inference System (APCIS)
S Report Date
November 1984 6
7 Author(s)
Kah-Eng Pua 8 Performing Organization Rept
No
9 Performing Organization Name and Address
Department of Computer Science University of Illinois Urbana IL
10 ProjectTaskWork Unit No
11 Contract Grant No NSF DCR 84-06081 ONR N00014-82-K-0186
12 Sponsoring Organization Name and Address
National Science Foundation Washington DC
13 Type of Report amp Period Covered
14
15 Supplementary Notes
16 Abstracts
This paper describes a deductive inference system called APCIS (Annotated Predicate Calculus Inference System) APCIS is able to carry out inferences from expressions involving numerical quantifiers selectors disjunctions of non-negated terms negated terms disjunctions of negated terms equivalences and exceptions It is also able to count the numbers of occurrence of a given simple term or a conjunction of terms The design of contradiction and the treatment of the disjunction of non-negated terms allow APCIS to accept Horn clauses as well as non-Horn clauses and to carry out inferences from them This feature makes APCIS more general than Prolog
17 Key lords and Document Analysis 170 Descriptors
APC (Annotated Predicate Calculus) APCIS (Annotated Predicate Calculus Inference System) Horn Clause Numerical Quantifier Prolog Selector
17b IdentifiersOpen-Ended Terms
17c COSATI FieldGroup
18 Availability Statement 19 Security Class (This
Re~f~~IA~SIF IFf)
21 ~o of Pages
49 211 ecurity Class (This
PageUNCLASSIFIED
22 Price
FOA NTIS n (10middot70 usco-oc 40329-
19
8 Printing Result
Whenever a goal is successfully executed APCIS will not only response with a yes but
also print out the matched terms or clauses in the database This is made possible by the built-in
function bagor and the two predicates wout and prt defined in APCIS
7 Summary
In this paper a description of a deductive inference system called APCIS (Annotated
Predicate Calculus Inference System) has been provided APCIS is able to carry out inferences
from expressions involving numerical quantifiers selectors disjunctions of non-negated terms
negated terms disjunctions of negated terms equivalences and exceptions It is also able to count
the numbers of occurrence of a given simple term or a conjunction of terms
The main idea of APCIS is that each input APC expression is first passed to a
preprocessor ( ie APC translator ) which dissolves and transforms each APC expression into
Prolog expression(s) which will then be loaded to Prolog system The user bas to specify whether
each input expression is to be entered as an assertion or as a query by invoking either assertion
mode or query mode respectively Each assertion or query will undergo different transformations in
the preprocessor The different treatment of assertion or query not only allows a full uS1ge of the
Prolog inference mechanism but also makes possible a higher level of inexact pattern matching
exemplified by the examples in Section 51 and Section 52 where the four predicates num
cnum sel and csel are discussed This higher level of pattern matching increases the inference
power of APCIS greatly
The design of contradiction and the treatment of the disjunction of non-negated terms
allow APCIS to accept non-Horn clauses and to carry out inference from them This feature
makes APCIS more general than Prolog
20
While APCIS performs very well in many sets of arguments provided by the author it is
still too early to jump to conclusion that it can perform equally well in all types of problems In
any event the expressiveness of APC has greatly been retained in the present version of APCIS
and moreover some design ideas or APCIS mentioned in this paper are not restricted to APCIS
- they may be carried over to learning programs with narrower scopes
21
References
[1] W F Clocksin and C S Mellish Programming In Prolog Springermiddot Verlag Berlin Hpoundidelberg 1981
[2] R S Michalski A Theory and Methodology of Inductive Learning Chpt 4 Machine L earning Tioga Publishing Co Palo Alto CaliJornia 1989
[3] K-E Pua Translating Annotated Predicate Calculu8 to Prolog ISG Report 84middot1 UlUCDCSmiddotFmiddot918 University oj Illinois Urbana IL June 1984
22
Appendix A
APCIS Users Manual
1 Get Started
Users are urged to follow the steps depicted below
1 Get the PROLOG interpreter by typing
alias prolog mntb2sammutsammutprologprolog (Vax A)
or
alias prolog mntb2sammutsammutbinprolog (Vax B)
2 Load apc and infer by typing
prolog apc infer
When large APC expressions are expected we can increase the stlck by typingI
prolog -snnnn ape infer
where ns denote the number of stacks in decimal
3 When the wording LSW - PROLOG appears on the terminal we are reldy to interact
with APCIS The four modes by which we can invoke APCIS are summarized below
a Assert ion-Translation Mode
ta(X)
b Query-Translation Mode
tq(X)
c Assertion Mode
a(X
d Query Mode
q(X)
23
where Xs are APC expressions
2 Notations Used in APCIS
Below is a summary or notations used in APCIS
a Logical operators
amp
v
==gt
lt=gt
-
negation
conjunction
disjunction
implication
equivalence
exception
b Binary relation symbols in selectors
-
=
gt=
lt=
gt
lt
equal
not equal
greater or equal
smaller or equ al
greater
smaller
c Relational operators in numerical quantifiers
lt less than
lt= less than or equal
gt greater than
gt= greater than or equal
d BinlTY operator in numerical quantifier
range
e Universal quantifier
all(X p(X))
f Existential quantifier
exists(X p(X))
g Numerical quantifier
exists(I X p(X))
where p(X) is a formula
where X is a variable or a Jist of variables or the
form [HI~rj and p(X) a formula
where I repersents expression involving integer(s)
and operator(s) in c or d above and p(X) a formula
25
Appendix B
APCIS Program Listings
------------------------------- Program Name APCIS - Part 1 APC Translator
-------------------------------
op(3OO fx -)1
op(500 xfy amp)
oPt 500 xfy v)
op(600 xfx )
op(700 fx [gt= lt= gt lt ]) op(400 xfy [= gt= lt= gt lt ])1 op(900 xfy gt lt=gt -])1
steps(X Xg) shy
numbervars(X 1 J Step 1 change variables to iis
rmimp(X X) Step 2 conv(X X3) Step 3
rewrite(X3 X4) Step 4
negin(X4 X5) Step 5
dropexist(X5 X6 1]) Step 6
dropall(X6 X7) Step 7
distrib(X7 X8) Step 8 clausiCy(X8 X9 [J) Step 9
ta(X) shysteps(X Xg)
(( Xg = II nl
print( yes it is always true) )
( nl nl printcl(X9))) Step 10a
tq(X) shy
steps(X Xg)
prques(Xg)
28
Step 2 Removing implic3tions amp Transforming exceptions and equiv3lences
rmimpl( P - Q (PI lt=gt (QI) ) amp ((PI) lt=gt QI) ) -
rmimpl(P PI) rmimpl(Q QI)
rmimplnp) lt=gt Q (PI lt=gt -(QI)) amp nPI) lt=gt QI) ) - 1
rmimpl(P PI) rmimpJ(Q QI)
rmimpJ(P lt-gt -(Q) (PI lt=gt -(QI)) amp nPI) lt=gt QI) ) -
rmimpl(P PI) rmimpl(Q QI)
rmimpl( P lt=gt Q PI lt=gt QI ) - I
rmimpl(P PI) rmimpl(Q QI)
rmimpl( P ==gt Q -(PI) v QI ) - I
rmimpl(P PI) rmimpl(Q QI)
rmimpl( all(X P) aI(X PI) ) - 1
rmimpl(P PI)
rmimpl( exists(X P) exists(X PI) ) -
rmimpl(P PI)
rmimpl( exists(I X P) exists(I X PI) ) -
rmimpl(P PI)
rmimpl( P amp Q PI amp Ql ) -
rmimpl(P PI) rmimpl(Q Ql)
rmimpl( P v Q PI v QI ) -
rmimpl(P PI) rmimpl(Q QI)
rmimpl( -(p) -(PI) ) - I
rmimpl(p PI)
rmimpl( P P )
St~p 3 Converting numerical amp distinctive quantifiers
L Numerical quantifiers
examples of input forms
1 exists(gt= i X pIX)) where i is an integer
2 exists(i X pIX)) where i is an integer
3 exists(i j X pIX)) where i j are integers and iltj
4 exists(il v i2 X pIX)) where is are integers
examples of output forms of this step
1 exists(X pIX) amp number(X gt= i) )
2 exists(X pIX) amp number(X i) ) 3 exists(X pIX) amp number(X ij) ) 4 exists(X pIX) amp number(X il v i2) )
II Distinctive quantifiers
27
example or input Corm
exists([XYL p(X Y))
example or output Corm or this step
exists(X exists(Y p(XY)) )
conv(P lt=gt Q PI lt=gt QI) - 1
conv(P PI) conv(Q QI)
conv(al1(X P) all(X PI)) -
conv(P PI)
conv(exists(HIT] P) R ) - conv(P PI) convert distinctive quantifier
convtdis(exists([HIT]PI) R)
conv( exists(I X P) exists(X PIamp number(X I) )) -
conv(P PI) convert numerical quantifier
conv(exists(X P) exists(X PI)) - 1
conv(P Pl)
conv(P amp Q PI amp QI) - 1
conv(P PI) conv(Q QI)
conv(P v Q PI v QI) - t conv(P PI) conv(Q QI)
convC(P) -(PI)) -
conv(P PI)
conv(P Pl
convtdis(existsl[XL P) exists(X P)) - atomic(X) convtdis(exists[XIYj Pl exists(X R)) shy
convtdis(exists(Y P) R)
Step 4 Rewriting compound predicates andor compound selectors
Outputs are smiple predicates andor simple selectors
rewrite(P lt=gt Q PI lt=gt QI) - t rewrite(P PI) rewrite(Q QI)
rewrite(all(X Pl all(X PI)) - 1 rewrite(P PI)
rewriteexists(X P) exists(X PI)) - I rewriteP PI)
rewrite(P amp Q PI amp QI) - rewrite(P P 1) rewrite( Q Q 1
rewrite(P v Q PI v QI) - 1
rewrite(P PI) rewrite(Q QI)
rewriteC(P) -(PI)) - I
28
rewrite(P PI) rewrite(F(A B) R) -
rewrite(A AI) rewrite(B BI) re(F(AI BI) R)
rewrite(F(A) R) -
rewrite(A AI) re(F(AI) H)
rewrite(F(A B C) R) -
rewrite(A AI) rewrite(B BI) rewrite(C CI) re(F(AI BI CI) R)
rewrite(F(A B C D) R) -
rewrite(A AI) rewrite(B Btl rewrite(C CI) rewrite(D DI) rc(F(AI BI CI Dl) H)
rewrite(PP)
re(F(A B v el (RI v R2) -
re(F(A Bl RIl re(F(A C) R2) reF(A B amp cl (RI amp R2)) -
re(F(A B) RI) re(F(A e) R2) re(F(A amp B C) (Rl amp R2)) -
re(F(A e) R 1) re(F(B C) R 2) re(F( v B el (R I v R2)) -
re(F(A el R I) reFB el R2) re(F(A amp Bl (R I amp R2)) -
re(F(A RI) re(F(BJH2) re(F(A v B) (R 1 v R2)) -
re(F(A) RI) re(F(B) R2)
re(F(A vB c Dl (RI v R2) -
re(F(A C D) RI) re(F(B C D) R2) re(F(A amp B C D) (RI amp R2)) -
re(F(A C D) Rll re(F(B C D) R2) re(F(A B v C D) (HI v R2)) -
re(F(A B D) RI) re(F(A C D) R2) re(F(A B amp C D) (HI amp R2)) -
re(F(A B D) RI) re(F(A C D) R2) re(F(A B C v D) (RI v R2)) -
re(F(A B C) R I) reF(A B D) R2) re(F(A B C amp D) (RI amp R2)) -
29
re(F(A B C) RI) re(F(A B D) RZ)
re(F(A v B e D E) (R I v R2)) -
re(F(A e D E) R I) re(F(B e D El R2) re(F(A amp B e D E) (RI amp RZ)) -
re(F(A e D El R 1) re(F(B e D E) R2) re(F(A B v e D E) (R I v R2)) -
re(F(A B D E) RI) re(F(A e D E) R2)
re(F(A B amp e D E) (RI amp R2)) -
re(F(A B D El RI) re(F(A e D E) RZ) re(F(A B e v D E) (R I v R2)) -
re(F(A B e El R 1) re(F(A B D E) RZ) re(F(A B e amp D E) (RI amp RZ)) -
re(F(A B e E) R I) re(F(A B D E) RZ)
re(F(A B e D vEl (RI v RZ)) - l
rc(F(A B C D) RI) re(F(A n e El RZ) re(F(A B e D amp El (RI amp RZ)) - ~
re(F(A B e D) RI) re(F(A B e El RZ)
re((A = B) (A = B)l-
re((A = Bl (A = 8)) -
retIA gt= BI (A gt= B)) -
re((A lt= B) (A lt= B)) -
re((A gt B) (A gt B))-
re((A lt Bl (A lt Bl)- re(A A)
Step) Bringing n(gation inwards
Degin(-(P) PI) - neg(P Pl)
negin(P lt=gt Q PI lt=gt Ql) - ~
negin(P PI) negiD(Q QI)
Degin(aU(X P) all(X PI)) - Degin(P PI) negin(exists(X P) exists(X PI))- negin(P PI) negin(P amp Q PI amp Ql) - Degin(P PI) negin(Q Ql)
Degin(P v Q PI v QI) - Degin(P PI) negin(Q QI) negin(P Pl
neg(-(P) PI) - negin(P PI)
neg(all(X P) exists(X PI)) - neg(P PI)
30
neg(exists(X P) all(X PI)) - neg(P PI)
neg(P amp Q PI v QI) - neg(P PI) neg(Q Ql)
neg(P v Q PI amp QI) - neg(P PI) neg(Q QI)
neg(P -(PH
Step 6 Dropping existnetial quanti6ers
dropexist(P lt=gt Q PI lt=gt QI Elerns) - dropexist(P PI Elerns) dropexist(Q QI Elerns)
dropexist(alJ(X P) all(XPI) Elerns)
dropexist(P PI [XIElernsJ)
dropexist(exists(X P amp nurnber(X Yraquo P2 Elerns) -
genfun(skn Newg) Fun = [NewgIElerns]
subst(FuD X P amp Dumber(X Y) PI)
dropexist(Pl P2 Elerns)
dropexist(exists(X P) PZ Elerns) -
genfun(skrn Newf) Fun = [NewfIElernsJ
subst(Fun X p PI)
dropex ist(P 1 P~ Elerns)
dropexist(P v Q PI v QI Elerns) - ~
dropexist(P PI Elerns) dropexist(Q Ql Elerns)
dropexist(P amp Q PI amp QI Elerns) - 1
dropexist(P Pl Elerns) dropexist(Q QI Elerns)
dropexist(P P _)
gen fun(R oot Newn arne) shy
getnurn(Root Nurn)
narne(Root Rootlist)
append(Rootlist[Nurnj Narnelist)
concat(Narnelist Newnarne)
getnurn(Root Nurn) shy
retract(currentnurn(Root Nurn 1 raquo
Nurn is Nurni + 1
asserta(currentnurn(Root Nurn))
getnurn(Root 1) - asserta(currentnurn(Root 1))
subst(New Old Val Val) - var(Val)
subst(New Old Old New) - 1 substNew Old Val Val) - atornic(Val)
31
subst(New Old Val Newval) shy
runctor(Val F N)
CUDctor(Newval F N)
subst_args(N New Old Val Newval)
subst_args(O J J - J J
subst_args(N New Old Val NewVal) shy
arg(N Val OldArg)
arg(N NewVal NewArg)
subst(New Old OldArg NewArg)
NI is N - I
subst_args(Nl New Old Val NewVal)
append([J L L) -
append([XILl] L2 [XIL3]) - append(Ll L2 L3)
Step - Dropping universal quantifiers
dropall(P lt=gt Q PI lt=gt QI)-
dropall(P PI) dropall(Q QI)
dropall(all(X P) PI) - ~ dropall(P PI)
dropall(P amp Q PI amp QI) -
dropall(P PI) dropall(Q QI)
dropall(P v Q PI v QI) -
dropall(P PI) dropall(Q QI)
dropall(P P)
Step 8 Distributing conjunctions over disjunctions
distrib(P lt=gt Q PI lt=gt Ql) - t distrib(P PI) distrib(Q QI)
distrib(P v Q R) -
distrib(P PI) distrib(Q QI)
distributing(PI v QI R)
distrib(P it Q PI it QI) -
distrib(P PI) distrib( Q QI)
distrib(P P)
distributing((P amp Q) v R PI amp QI) -
distrib(P v R PI) distrib(Q v R Ql)
32
distributing(P v (Q amp R) PI amp Ql) -
distrib(P v Q PI) distrib(P v R Ql)
distributing(P P)
Step 9 Packing each conjunction into clauses
c1ausify(P amp Q CI C2) -
clausiCy(P CI C3) c1ausify(Q C3 C2)
cbusiCy(P [d(A B)ICs] Cs) shy
inclause(P A [j B [I) 1
c1ausiry( C C)
inclause(P v Q A AI B B1) -
inc1ause(P A2 AI B2 Bl)
inclause(Q A A2 B B2)
inclausenp) A A B1 B) -
notin(P A) putin(P B B1)
inclause(P AI A B B) shy
notin(P Bl putin(P A AI)
notin(X [XU) - fail
notin(X [JLj) - notin(X L)
notin(X 1])
putin(X II [X]) - 1
putin(X [XILJ L) -
putin(X [YILJ [YILl]) - putin(X L Ll)
Step 1Oa Printing clauses
printcl([]) - nl nl
printcl(c1(AB)ICsj) - printcl(A Bl nl printcl(Cs)
printcl(L II) - printdis(IL) prinr)middot
printclHl L) - prin(contradiction(() printconl(rL)
print()) - ) printconj(rL) prinr )
printcl(Ll L2) shy
printdis(ILl) print( - ) printconj(rL2) prin()
printdis(S[Lj) - printcbar(SL)
33
printdis(S[LILs]) - printchu(SL) prin( v) printdis(SLs)
printconl(S[LI) - printchar(SL)
printconl(S[LILs]) - printchar(SL) prin( ) printconl(SLs)
printconj(S[L]) - tab(3) printchar(SL)
prin tconj( S [L IL sl) shy
tab(3) printchar(SL) print( ) printconj(SLs)
printchar(SP) shy
atomic(P)
name(P L)
L = [IT]
concat([XIT NewP)
prin(~ewP)
printchar(SP) shy
atomic(P)
prin(P)
printchar(SA lt= gt B) -
prin((l clausify(A AI [j) pl(eAl) prin())
print lt=gt )
prin(() cbusify(B Bl [I) pJ(eBl) prine))middot
printchar(rnumber(X N)) shy
prin(num() printchar(rx) prin( )
printchar(rN) prinC))
printchar(rF(A B)) shy
seJec(F(A B))
prinCsel() printchar(rA)
prin( F ) printchar(rB) prinC))
printchar(SF(A B)) shy
( selec(F(A B)) F = infix )
printchar(SA) prin( F ) printchar(SB)
printchar(SF(A)) shy
(F= prefix gt= F= prefix lt= F= prefixgt F= prefix lt )
prin(F ) printcbar(SA)
printchar(SP) shy
functor(P F MaxN)
prin(F ()
Nl is MaxN - 1
putout(S N 1 P MaxN)
34
prin())
putout(S 0 P MaxN) -
arg(~laxN P Argu)
prin tchar(SArgu)
putout(S N p MaxN) shy
Nt is MaxN - N arg(NI P Argu)
printcbar(SArgu )
prin( )
N2 is N - 1
putout(S N2 P MaxN)
selec(FA B)) shy
( F= infix = F= infix f= F= infix gt=
F= infix gt F= infix lt= F= infix lt )
35
----------------------------------Program Name APClS - Part 2 Inference Mechanism ---------------------------------- a(X) shy
steps(X X9)
(( X9 =[] nl
print( yes it is always true) )
( X9 =[cI(IJ[])] nl
print( no it is always false) )
( nl nl printel(X9) Step 1Oa
tell(temp_file) printel(X9) e1ose(temp_file) consult(temp_6Ie) ))
q(X) shy
asserta( in pt(X))
steps(X X9)
(( X9 = [] print(middot~H~~middot~t~)
print(THE AiSWER IS YES)
print( ilgIQlQl(~) )
( X9 = [e1([j [j)] Pr1nt ( OJ fi(i I~ iii Ij)middot(i)(i) fiyenQ)riiio(i)(ij)(i)fj)fiyen1li1il1li1il)__ gtw~ __~_~ _~~_ ~_-=~
print(THE ANSWER IS NO ) print() )
( teI1(temp_6Ie)
prques(X9) Step 1Ob
close(temp_file)
nl print(Let me think about it) nl
consult(temp_6Ie) ))
retrac t( in pt(X))
Step lOb Printing question
prques(lcl(A 8)1) - prin(goo(() pl(qA 8) print()))
prques([c1(A 8HCs]) - prin(goo(() pl(qA 8) print() pl(q Cs)
pl(e [c1(A 8)]) - pl(eA 8)
pl(q [c1(A 8)]) - pl(qA 8) print()))
pl(S [e1(A B)ICs]) - pl(SA B) prin( ) pl(S Cs)
38
pl(q [j L) - prin(c1ause(contradiction(() pcont(qL) prin())_))
pl(S [I L)- prin(so2(contradidion(() pcont(SL) print))))middot
pl(S [L] []) - prin(so2() pcbar(SL) prin())
pl(S L [J)- prinsol() plett(SL) print))
pl(S [L] LI) - prin(condi(() pchar(cL)
prin(() pcont(S Ll) prine))))
pl(S L Ll)- prin(c1ause() plert(cL)
prin(() pcont(S Ll) prine)))
plert(S[LJ) - pchar(SL)
plert(SjLILsj) - pcbar(SL) print v) pleCt(SLs)
pcont(S[L]) - pchar(SL)
pcont(S[LILsj) - pcbar(SL) prinr ) pcont(SLs)
pcbar(SP) shy
atomic(P)
name(PL)
( L = [IT] L = [5 k miT] L = [5 k niT] )
concat[XITj NewP)
prin(0JewP)
pchar(SP) shy
atomic(P)
prin(P) pchar(SA lt=gt B) -
prin(() dausify(A AI []) pl(eAI) prin())
prinr lt=gt ) prin(() dausify(B BI ]) pl(eB) print))
pchar(Snumber(X N)) shy
prin(num() pchar(SX) prin()
pchar(SN) prinr))
pcbar(SM N) - prin(M N)
pcbar(cF(A B)) shy
selec(F(A Braquo
pcbar(cA)
prine F ) pchar(cB) pchar(SF(A B)) shy
selec(F(A B))
prin(sel() pchar(SA)
print F ) pchar(SB) print)) I
31
pc har(SF(A)) shy
( F= prefix gt= F= prefix lt= F= prefixgt F= prefix lt )
prin(F ) pchar(SA)
pchar(SP)shy
runctor(P F MaxN)
prin(F ()
011 is MaxN - 1 pout(SNl P MaxN)
print) )
pout(S 0 P M3xN) - 1
arg(~bxN P Argu)
pchlr(SArgu )
pout(S N P MaxN shy
Nl is MaxN - N
arg(Nl P Argu)
pchar(SArgu
prin( )
N2 is N - 1
pout(S N2 P ~13xN)
Comparing numbers in numerical quantifiers
num(XN) shy
number(X I)
cnum(N 1) ~
cnumlaquo=01 lt=I- N gt=I
cnumlaquo=J lt I) - N gt=1-1
cnumlaquo=NIJ) - N gt=J 1
cnumlaquo=N J)- integer(I) N gt=I~
cnum(gt=N gt=1) - N lt=1
cnum(gt=N gt I) - N lt=1+ 1 cnum(gt=NIJ) - N lt=1
cnum(gt=N lt=1)- N lt=1
cnum(gt=N lt I) - N lt=1 L cnum(gt=N 1)- integer(I) N lt=1
cnum( lt N lt 1)- N gt=1 L
38
cnum( lt N lt=1) - N gt I cnum( lt NLJ) - N gt J
cnum( lt N 1)- integer(I) N gt 1
cnum(gt N gt I) - N lt=1 cnumlgt i gt=1) - N lt I
cnum(gt N lt=1) - N lt=0
cnum(gt N lt I) - N lt=0
cnum(gt iIJ) - N lt I cnum(gt N 1)- integer(I) N lt I
cnum(~LN lt=1) - M=I N gt= I l
cnum(~LN lt I) - M=l N gt= I-I
cnum(~LNLJ) - M lt =1 N gt = J
cnum(~1N 1)- integer(I) M lt= I N gt= I
cnum(- N) - integer(N)
Comparing selectors
sel(X = Y) shyX= Y
sel(X I=Y) shy(X I=Y X lt Y Xgt Y)
sel(X gt Y) shyXgt Y
sel(X lt Y) shyXlt Y
selX gt=Y) shy(X gt=Y X= Y Xgt Y)
se(X lt=Y) shy
(X lt=Y
X= Y
X lt Y)
csel(infix = infix =)
39
csel(infix = infix = csel(infix = infix gt)
csel(infix = infix lt) csel(infix gt infix gt) cseJ(infix lt infix lt) csel(infix gt= infix gt=) csel(infix gt= infix gt csel(infix gt= infix =)
csellinfix lt= infix lt=) csel(infix lt= infix lt) csel(infix lt= infix =)
Finding solutions
sol(X v Y) -
(( notetra(X) eon(X) ( sol(Y) )
( c1ause(P v Q R) not(cketra(P v Q))
dis(P v Q X v Y R) ~ )
( A lt=gt B equival(A lt=gt B X v Y) ~ I) sol(X) - ~ notetra(X) eon(X)
so~(X) - notetra(X)
( con (X)
( clause(P v Q R) not(ekctra(P v Q)) dis(P v Q X R) I)
cketra(P v Q) -
eketra(P) eketra(Q) eketra(F(I J)) shy
selec(F(I J))
c1ause(contradiction(sel(F(IJ))) _I
eketra(number(W I)) -
clause(cootradietion(num(Wl)) - eketr(P) shy
clause(contradiction(P) - 1
notctra(P) shy
not( e lause( con tradiction(P) _))
40
Searching (or disjunctions
dis(P v Q X v Y R) - dis(P X v Y R)
dis(Q X v Y R) con(R)
dis(P v Q X R) -
dis(P X R) dis(Q X R) con(R
dis(P X v Y R) - clause(contradicton(Pl J 1
dis(F(I J) sel(G(I J)) v Y R) - csel(G Fl dis(number(WI) num(W N v Y R) - cnum(N I)
dis(P P v Y R) -
dis(P X v Y R) - dis(P Y R)
dis(F(I J) seJ(G(IJ)) R) - csel(G F)
dis(number(WI) num(WN) R) - cnum(N I) dis(P P R) - 1
dis(FJ J X R) shy
( ckctra(F(IJ) cbeckeq(seJ(F(IJ))) )
dis(number(W Il X R) - ( ckctra(number(WI)) cbeckeq(num(WI)) )
dis(P X R) shy( ckctra(P) cbeckeq(P) ) 1
cbeckeq(P) shy
(( A lt=gt so2(contradiction(P))
bagof(A A [jj) ) ( so2(contradiction(P)) lt=gt B
bagof(B B Uj) ))
ckeq(A) shy
( so2(A) lt=gt B B lt=gt so2(A) ) bagof(B B UJ)
con((P Q)) -
clause(P R) con(R) con(Q) con(true) -
con(contradiction(P)) - clause(contradiction(P) J
con(cause(X Y)) - cause(X Y)
con(sel(X)) - sel(X)
con(num(X Y)) - num(X Y) con(P)- (( dause(P R) (con(R) ckeq(R)))
colJectin(P) )
collectin(P) shy
bagof(S (c1ause(P S) S = true) [L LIJ )
mkcon(L Ll L)
bagor(l (L2 ) UJ) L
mkcon((A AI) (B B1) (sol(A v B) e D)) -
mkcon(A B1 e) mkcon(A1 (B Bl) D)
mkcon(A (B B1) (sol(A v B) e)) -
mkcon(A Bl e)
mkcon((A AI) B (sol(A v B) e)) middot1
mkcon(Al B e)
mkcon(A B sol(A vB))
Searching ror equivalences
equival(A lt=gt B X v Y) - 1 ( equival(A lt=gt B X) equival(A lt=gt B Y) )
equival(s02(A) lt=gt 502(B) A) - clause(B _I equival(s02(B) lt=gt 502(A) A) c1ause(B _I
Top level or inrerence mechanism
goo((s02(whatnum) P)) -
getatm(P Xl
bagor(number(X Y) ( P so2(number(X Y)) ) A )
count1(A 00 L R) nl
bagor(X P B )
count2(B L R Ll Rl) nJ print()
(( LI = 0 Rl = 0 print(THE ANSWER IS ) nl
(( Ll = Rl prin(-Jumber or ) prn(P) print(is Ll) )
( Rlgt20000 prin(Number or I prn(P) print(is LI or more) )
42
( prin(Number of ) pfn(P) print( is from Ll to Rl) )) )
( print(THE ANSWER IS NO I )) print()
goo(X) shy
(( bagof(X X L) L = [I nl print()
print(THE ANSWER IS YES) nl wout(L) print() )
( equiv(X L) nl print()
print(THE ANSWER IS YES) nl wout(L) print(-) )
( c1ause(inpt(A ==gt B) _I ( impli(A B Z) impli(B A Z) ) print(l~Hl)
printTHE ANSWER IS YES) nl print(Z) print(Hj~(fH~) ))
goo(X) print( Hg)
print(THE ANSWER IS NO ) print( lH~lH~gg9l9lmiddotmiddot~Q(gmiddot)
00 Semhing for implications in equiV3lent relations
impli( B Z) shyt-ell( z1) prin(templ() pchn(S A lt=gt B) print()) close ( zl) consult(zl) templ(Z)
unload zl Z
Searching for equivalence
equiv (X L)
(( X lt=gt Y
equ(Y YI)t bagof(Y Yl L) L = [j )
(Y lt=gt X equ(Y YI) bagof(Y Yl L) L = [J )
( X = F(New)
clause(~ew T) makeup(T Tl)
(( Tl lt=gt B
equ(B Bl) bagof(Bl Bl M) M = [j L=[Newl )
(A lt=gt TI
equ(A AI) bagof(Al AI M) M = 1] L=INewj )) ))
makeup((A B) (AI Bl)) -
makeup(A A1) makeup(B BI)
makeup(A so2(A))
equ((A B) (AI BI)) -
equ(A AI) equ(B Bl)
equ(sol(X v Y) sol(XI v Yl)) -
equ(X XI) equ(Y YI)
equ(so2(X) so2(XI)) -
equ(X XI)
equ(contradiction(X) clJuse(contradiction(X) X) ) -
equ(X X)
Counting numbers
getatm((A B) X) -
( getatm(A X) getatm(B X) )
getatm(so2(F(X)) X) -
getatm(so2(X) X) - atom(X)
countl([J L R L R) -
countl([number(X Y)IT] L R L2 R2) shy
(( Y = (gt=~) LI is L + N Rl is R + 20001 l )
( Y = (gt N) LI is L+ N+ 1 RI is R + 20002 )
(Y == laquo=~) LI is L + 1 Rl is R + N )
(Y = laquo N) LI is L + 1 RI is R+N-I)
(Y == IJ LI is L + I Rl is R + J ) ( Y == N L1 is L + N RI is R + N ))
count1(T LI R 1 L2 R2)
count2(fJ L R L R) - 1
count2([XITJ L R L2 R2) shy
name(X Xl)
(( Xl = sknj LI is L Rl is R )
44
( Xl = Iskmj L1 is L + 1 RI is R + ZOOO1) ( LI is L + I RI is R + I ))
count2(T LI RI L2 R2)
pfn((A B)) - pfn(A) prn(B)
pCn(so2(F(X))) - prin(F )
prn(so2(X)) - atom(X) prin(X ) prn (so2(X))
Printing result
wout([XlJ - prt(X) nl woutf[xIY]) - prt(X) nl nl wout(Y)
prt(e(A B)) -
prt(A) prinr 8 ) prt(ltE) prt(eA) - prt(A)
prt(c(A EJ) - prin() prt(A) prine ) prt(B) prin(T)
prt(c A) - prt(A) prt((A E)) - ~
prt(A) nl prt(E) prt(sol(X v Y)) - ~
prt(X) prinC v) prt(Y) prt(A lt=gt B) -
prt(e A) prinC lt=gt ) prt(e B) prt(sol(X)) - prt(X)
prt(so2(X)) - prt(X
prt(c1ause(X Y)) - prt(X)
prt(contradiction(X)) - prin(contradiction() prt(cX) prinr))middot prt(num(XY)) - prin(number(X Y)) prt(sel(X)) - prin(X) prt(X v Y) - prt(X) prin( v) prt(Y) prt(X) prin(X)
Handling conditional queries
condi((Y Xl) shy
assertcon(X) Y
45
retractcon(X)
condi((B A))
retractcon(A) fail
assertcon((A B)) 1
assertcon(A) assertcon(B)
assertcon(A) asserta(A)
retrac teon ((A B)) 1
retracteon(A) retractcon (B)
retraetcon(A) - retract(A)
BIBLIOGRAPHIC DATA SHEET
Report No UIUCDS-F-84-928
3 Recipients Accession No
4 T ide and Subt ltle
An Annotated Predicate Calculus Inference System (APCIS)
S Report Date
November 1984 6
7 Author(s)
Kah-Eng Pua 8 Performing Organization Rept
No
9 Performing Organization Name and Address
Department of Computer Science University of Illinois Urbana IL
10 ProjectTaskWork Unit No
11 Contract Grant No NSF DCR 84-06081 ONR N00014-82-K-0186
12 Sponsoring Organization Name and Address
National Science Foundation Washington DC
13 Type of Report amp Period Covered
14
15 Supplementary Notes
16 Abstracts
This paper describes a deductive inference system called APCIS (Annotated Predicate Calculus Inference System) APCIS is able to carry out inferences from expressions involving numerical quantifiers selectors disjunctions of non-negated terms negated terms disjunctions of negated terms equivalences and exceptions It is also able to count the numbers of occurrence of a given simple term or a conjunction of terms The design of contradiction and the treatment of the disjunction of non-negated terms allow APCIS to accept Horn clauses as well as non-Horn clauses and to carry out inferences from them This feature makes APCIS more general than Prolog
17 Key lords and Document Analysis 170 Descriptors
APC (Annotated Predicate Calculus) APCIS (Annotated Predicate Calculus Inference System) Horn Clause Numerical Quantifier Prolog Selector
17b IdentifiersOpen-Ended Terms
17c COSATI FieldGroup
18 Availability Statement 19 Security Class (This
Re~f~~IA~SIF IFf)
21 ~o of Pages
49 211 ecurity Class (This
PageUNCLASSIFIED
22 Price
FOA NTIS n (10middot70 usco-oc 40329-
20
While APCIS performs very well in many sets of arguments provided by the author it is
still too early to jump to conclusion that it can perform equally well in all types of problems In
any event the expressiveness of APC has greatly been retained in the present version of APCIS
and moreover some design ideas or APCIS mentioned in this paper are not restricted to APCIS
- they may be carried over to learning programs with narrower scopes
21
References
[1] W F Clocksin and C S Mellish Programming In Prolog Springermiddot Verlag Berlin Hpoundidelberg 1981
[2] R S Michalski A Theory and Methodology of Inductive Learning Chpt 4 Machine L earning Tioga Publishing Co Palo Alto CaliJornia 1989
[3] K-E Pua Translating Annotated Predicate Calculu8 to Prolog ISG Report 84middot1 UlUCDCSmiddotFmiddot918 University oj Illinois Urbana IL June 1984
22
Appendix A
APCIS Users Manual
1 Get Started
Users are urged to follow the steps depicted below
1 Get the PROLOG interpreter by typing
alias prolog mntb2sammutsammutprologprolog (Vax A)
or
alias prolog mntb2sammutsammutbinprolog (Vax B)
2 Load apc and infer by typing
prolog apc infer
When large APC expressions are expected we can increase the stlck by typingI
prolog -snnnn ape infer
where ns denote the number of stacks in decimal
3 When the wording LSW - PROLOG appears on the terminal we are reldy to interact
with APCIS The four modes by which we can invoke APCIS are summarized below
a Assert ion-Translation Mode
ta(X)
b Query-Translation Mode
tq(X)
c Assertion Mode
a(X
d Query Mode
q(X)
23
where Xs are APC expressions
2 Notations Used in APCIS
Below is a summary or notations used in APCIS
a Logical operators
amp
v
==gt
lt=gt
-
negation
conjunction
disjunction
implication
equivalence
exception
b Binary relation symbols in selectors
-
=
gt=
lt=
gt
lt
equal
not equal
greater or equal
smaller or equ al
greater
smaller
c Relational operators in numerical quantifiers
lt less than
lt= less than or equal
gt greater than
gt= greater than or equal
d BinlTY operator in numerical quantifier
range
e Universal quantifier
all(X p(X))
f Existential quantifier
exists(X p(X))
g Numerical quantifier
exists(I X p(X))
where p(X) is a formula
where X is a variable or a Jist of variables or the
form [HI~rj and p(X) a formula
where I repersents expression involving integer(s)
and operator(s) in c or d above and p(X) a formula
25
Appendix B
APCIS Program Listings
------------------------------- Program Name APCIS - Part 1 APC Translator
-------------------------------
op(3OO fx -)1
op(500 xfy amp)
oPt 500 xfy v)
op(600 xfx )
op(700 fx [gt= lt= gt lt ]) op(400 xfy [= gt= lt= gt lt ])1 op(900 xfy gt lt=gt -])1
steps(X Xg) shy
numbervars(X 1 J Step 1 change variables to iis
rmimp(X X) Step 2 conv(X X3) Step 3
rewrite(X3 X4) Step 4
negin(X4 X5) Step 5
dropexist(X5 X6 1]) Step 6
dropall(X6 X7) Step 7
distrib(X7 X8) Step 8 clausiCy(X8 X9 [J) Step 9
ta(X) shysteps(X Xg)
(( Xg = II nl
print( yes it is always true) )
( nl nl printcl(X9))) Step 10a
tq(X) shy
steps(X Xg)
prques(Xg)
28
Step 2 Removing implic3tions amp Transforming exceptions and equiv3lences
rmimpl( P - Q (PI lt=gt (QI) ) amp ((PI) lt=gt QI) ) -
rmimpl(P PI) rmimpl(Q QI)
rmimplnp) lt=gt Q (PI lt=gt -(QI)) amp nPI) lt=gt QI) ) - 1
rmimpl(P PI) rmimpJ(Q QI)
rmimpJ(P lt-gt -(Q) (PI lt=gt -(QI)) amp nPI) lt=gt QI) ) -
rmimpl(P PI) rmimpl(Q QI)
rmimpl( P lt=gt Q PI lt=gt QI ) - I
rmimpl(P PI) rmimpl(Q QI)
rmimpl( P ==gt Q -(PI) v QI ) - I
rmimpl(P PI) rmimpl(Q QI)
rmimpl( all(X P) aI(X PI) ) - 1
rmimpl(P PI)
rmimpl( exists(X P) exists(X PI) ) -
rmimpl(P PI)
rmimpl( exists(I X P) exists(I X PI) ) -
rmimpl(P PI)
rmimpl( P amp Q PI amp Ql ) -
rmimpl(P PI) rmimpl(Q Ql)
rmimpl( P v Q PI v QI ) -
rmimpl(P PI) rmimpl(Q QI)
rmimpl( -(p) -(PI) ) - I
rmimpl(p PI)
rmimpl( P P )
St~p 3 Converting numerical amp distinctive quantifiers
L Numerical quantifiers
examples of input forms
1 exists(gt= i X pIX)) where i is an integer
2 exists(i X pIX)) where i is an integer
3 exists(i j X pIX)) where i j are integers and iltj
4 exists(il v i2 X pIX)) where is are integers
examples of output forms of this step
1 exists(X pIX) amp number(X gt= i) )
2 exists(X pIX) amp number(X i) ) 3 exists(X pIX) amp number(X ij) ) 4 exists(X pIX) amp number(X il v i2) )
II Distinctive quantifiers
27
example or input Corm
exists([XYL p(X Y))
example or output Corm or this step
exists(X exists(Y p(XY)) )
conv(P lt=gt Q PI lt=gt QI) - 1
conv(P PI) conv(Q QI)
conv(al1(X P) all(X PI)) -
conv(P PI)
conv(exists(HIT] P) R ) - conv(P PI) convert distinctive quantifier
convtdis(exists([HIT]PI) R)
conv( exists(I X P) exists(X PIamp number(X I) )) -
conv(P PI) convert numerical quantifier
conv(exists(X P) exists(X PI)) - 1
conv(P Pl)
conv(P amp Q PI amp QI) - 1
conv(P PI) conv(Q QI)
conv(P v Q PI v QI) - t conv(P PI) conv(Q QI)
convC(P) -(PI)) -
conv(P PI)
conv(P Pl
convtdis(existsl[XL P) exists(X P)) - atomic(X) convtdis(exists[XIYj Pl exists(X R)) shy
convtdis(exists(Y P) R)
Step 4 Rewriting compound predicates andor compound selectors
Outputs are smiple predicates andor simple selectors
rewrite(P lt=gt Q PI lt=gt QI) - t rewrite(P PI) rewrite(Q QI)
rewrite(all(X Pl all(X PI)) - 1 rewrite(P PI)
rewriteexists(X P) exists(X PI)) - I rewriteP PI)
rewrite(P amp Q PI amp QI) - rewrite(P P 1) rewrite( Q Q 1
rewrite(P v Q PI v QI) - 1
rewrite(P PI) rewrite(Q QI)
rewriteC(P) -(PI)) - I
28
rewrite(P PI) rewrite(F(A B) R) -
rewrite(A AI) rewrite(B BI) re(F(AI BI) R)
rewrite(F(A) R) -
rewrite(A AI) re(F(AI) H)
rewrite(F(A B C) R) -
rewrite(A AI) rewrite(B BI) rewrite(C CI) re(F(AI BI CI) R)
rewrite(F(A B C D) R) -
rewrite(A AI) rewrite(B Btl rewrite(C CI) rewrite(D DI) rc(F(AI BI CI Dl) H)
rewrite(PP)
re(F(A B v el (RI v R2) -
re(F(A Bl RIl re(F(A C) R2) reF(A B amp cl (RI amp R2)) -
re(F(A B) RI) re(F(A e) R2) re(F(A amp B C) (Rl amp R2)) -
re(F(A e) R 1) re(F(B C) R 2) re(F( v B el (R I v R2)) -
re(F(A el R I) reFB el R2) re(F(A amp Bl (R I amp R2)) -
re(F(A RI) re(F(BJH2) re(F(A v B) (R 1 v R2)) -
re(F(A) RI) re(F(B) R2)
re(F(A vB c Dl (RI v R2) -
re(F(A C D) RI) re(F(B C D) R2) re(F(A amp B C D) (RI amp R2)) -
re(F(A C D) Rll re(F(B C D) R2) re(F(A B v C D) (HI v R2)) -
re(F(A B D) RI) re(F(A C D) R2) re(F(A B amp C D) (HI amp R2)) -
re(F(A B D) RI) re(F(A C D) R2) re(F(A B C v D) (RI v R2)) -
re(F(A B C) R I) reF(A B D) R2) re(F(A B C amp D) (RI amp R2)) -
29
re(F(A B C) RI) re(F(A B D) RZ)
re(F(A v B e D E) (R I v R2)) -
re(F(A e D E) R I) re(F(B e D El R2) re(F(A amp B e D E) (RI amp RZ)) -
re(F(A e D El R 1) re(F(B e D E) R2) re(F(A B v e D E) (R I v R2)) -
re(F(A B D E) RI) re(F(A e D E) R2)
re(F(A B amp e D E) (RI amp R2)) -
re(F(A B D El RI) re(F(A e D E) RZ) re(F(A B e v D E) (R I v R2)) -
re(F(A B e El R 1) re(F(A B D E) RZ) re(F(A B e amp D E) (RI amp RZ)) -
re(F(A B e E) R I) re(F(A B D E) RZ)
re(F(A B e D vEl (RI v RZ)) - l
rc(F(A B C D) RI) re(F(A n e El RZ) re(F(A B e D amp El (RI amp RZ)) - ~
re(F(A B e D) RI) re(F(A B e El RZ)
re((A = B) (A = B)l-
re((A = Bl (A = 8)) -
retIA gt= BI (A gt= B)) -
re((A lt= B) (A lt= B)) -
re((A gt B) (A gt B))-
re((A lt Bl (A lt Bl)- re(A A)
Step) Bringing n(gation inwards
Degin(-(P) PI) - neg(P Pl)
negin(P lt=gt Q PI lt=gt Ql) - ~
negin(P PI) negiD(Q QI)
Degin(aU(X P) all(X PI)) - Degin(P PI) negin(exists(X P) exists(X PI))- negin(P PI) negin(P amp Q PI amp Ql) - Degin(P PI) negin(Q Ql)
Degin(P v Q PI v QI) - Degin(P PI) negin(Q QI) negin(P Pl
neg(-(P) PI) - negin(P PI)
neg(all(X P) exists(X PI)) - neg(P PI)
30
neg(exists(X P) all(X PI)) - neg(P PI)
neg(P amp Q PI v QI) - neg(P PI) neg(Q Ql)
neg(P v Q PI amp QI) - neg(P PI) neg(Q QI)
neg(P -(PH
Step 6 Dropping existnetial quanti6ers
dropexist(P lt=gt Q PI lt=gt QI Elerns) - dropexist(P PI Elerns) dropexist(Q QI Elerns)
dropexist(alJ(X P) all(XPI) Elerns)
dropexist(P PI [XIElernsJ)
dropexist(exists(X P amp nurnber(X Yraquo P2 Elerns) -
genfun(skn Newg) Fun = [NewgIElerns]
subst(FuD X P amp Dumber(X Y) PI)
dropexist(Pl P2 Elerns)
dropexist(exists(X P) PZ Elerns) -
genfun(skrn Newf) Fun = [NewfIElernsJ
subst(Fun X p PI)
dropex ist(P 1 P~ Elerns)
dropexist(P v Q PI v QI Elerns) - ~
dropexist(P PI Elerns) dropexist(Q Ql Elerns)
dropexist(P amp Q PI amp QI Elerns) - 1
dropexist(P Pl Elerns) dropexist(Q QI Elerns)
dropexist(P P _)
gen fun(R oot Newn arne) shy
getnurn(Root Nurn)
narne(Root Rootlist)
append(Rootlist[Nurnj Narnelist)
concat(Narnelist Newnarne)
getnurn(Root Nurn) shy
retract(currentnurn(Root Nurn 1 raquo
Nurn is Nurni + 1
asserta(currentnurn(Root Nurn))
getnurn(Root 1) - asserta(currentnurn(Root 1))
subst(New Old Val Val) - var(Val)
subst(New Old Old New) - 1 substNew Old Val Val) - atornic(Val)
31
subst(New Old Val Newval) shy
runctor(Val F N)
CUDctor(Newval F N)
subst_args(N New Old Val Newval)
subst_args(O J J - J J
subst_args(N New Old Val NewVal) shy
arg(N Val OldArg)
arg(N NewVal NewArg)
subst(New Old OldArg NewArg)
NI is N - I
subst_args(Nl New Old Val NewVal)
append([J L L) -
append([XILl] L2 [XIL3]) - append(Ll L2 L3)
Step - Dropping universal quantifiers
dropall(P lt=gt Q PI lt=gt QI)-
dropall(P PI) dropall(Q QI)
dropall(all(X P) PI) - ~ dropall(P PI)
dropall(P amp Q PI amp QI) -
dropall(P PI) dropall(Q QI)
dropall(P v Q PI v QI) -
dropall(P PI) dropall(Q QI)
dropall(P P)
Step 8 Distributing conjunctions over disjunctions
distrib(P lt=gt Q PI lt=gt Ql) - t distrib(P PI) distrib(Q QI)
distrib(P v Q R) -
distrib(P PI) distrib(Q QI)
distributing(PI v QI R)
distrib(P it Q PI it QI) -
distrib(P PI) distrib( Q QI)
distrib(P P)
distributing((P amp Q) v R PI amp QI) -
distrib(P v R PI) distrib(Q v R Ql)
32
distributing(P v (Q amp R) PI amp Ql) -
distrib(P v Q PI) distrib(P v R Ql)
distributing(P P)
Step 9 Packing each conjunction into clauses
c1ausify(P amp Q CI C2) -
clausiCy(P CI C3) c1ausify(Q C3 C2)
cbusiCy(P [d(A B)ICs] Cs) shy
inclause(P A [j B [I) 1
c1ausiry( C C)
inclause(P v Q A AI B B1) -
inc1ause(P A2 AI B2 Bl)
inclause(Q A A2 B B2)
inclausenp) A A B1 B) -
notin(P A) putin(P B B1)
inclause(P AI A B B) shy
notin(P Bl putin(P A AI)
notin(X [XU) - fail
notin(X [JLj) - notin(X L)
notin(X 1])
putin(X II [X]) - 1
putin(X [XILJ L) -
putin(X [YILJ [YILl]) - putin(X L Ll)
Step 1Oa Printing clauses
printcl([]) - nl nl
printcl(c1(AB)ICsj) - printcl(A Bl nl printcl(Cs)
printcl(L II) - printdis(IL) prinr)middot
printclHl L) - prin(contradiction(() printconl(rL)
print()) - ) printconj(rL) prinr )
printcl(Ll L2) shy
printdis(ILl) print( - ) printconj(rL2) prin()
printdis(S[Lj) - printcbar(SL)
33
printdis(S[LILs]) - printchu(SL) prin( v) printdis(SLs)
printconl(S[LI) - printchar(SL)
printconl(S[LILs]) - printchar(SL) prin( ) printconl(SLs)
printconj(S[L]) - tab(3) printchar(SL)
prin tconj( S [L IL sl) shy
tab(3) printchar(SL) print( ) printconj(SLs)
printchar(SP) shy
atomic(P)
name(P L)
L = [IT]
concat([XIT NewP)
prin(~ewP)
printchar(SP) shy
atomic(P)
prin(P)
printchar(SA lt= gt B) -
prin((l clausify(A AI [j) pl(eAl) prin())
print lt=gt )
prin(() cbusify(B Bl [I) pJ(eBl) prine))middot
printchar(rnumber(X N)) shy
prin(num() printchar(rx) prin( )
printchar(rN) prinC))
printchar(rF(A B)) shy
seJec(F(A B))
prinCsel() printchar(rA)
prin( F ) printchar(rB) prinC))
printchar(SF(A B)) shy
( selec(F(A B)) F = infix )
printchar(SA) prin( F ) printchar(SB)
printchar(SF(A)) shy
(F= prefix gt= F= prefix lt= F= prefixgt F= prefix lt )
prin(F ) printcbar(SA)
printchar(SP) shy
functor(P F MaxN)
prin(F ()
Nl is MaxN - 1
putout(S N 1 P MaxN)
34
prin())
putout(S 0 P MaxN) -
arg(~laxN P Argu)
prin tchar(SArgu)
putout(S N p MaxN) shy
Nt is MaxN - N arg(NI P Argu)
printcbar(SArgu )
prin( )
N2 is N - 1
putout(S N2 P MaxN)
selec(FA B)) shy
( F= infix = F= infix f= F= infix gt=
F= infix gt F= infix lt= F= infix lt )
35
----------------------------------Program Name APClS - Part 2 Inference Mechanism ---------------------------------- a(X) shy
steps(X X9)
(( X9 =[] nl
print( yes it is always true) )
( X9 =[cI(IJ[])] nl
print( no it is always false) )
( nl nl printel(X9) Step 1Oa
tell(temp_file) printel(X9) e1ose(temp_file) consult(temp_6Ie) ))
q(X) shy
asserta( in pt(X))
steps(X X9)
(( X9 = [] print(middot~H~~middot~t~)
print(THE AiSWER IS YES)
print( ilgIQlQl(~) )
( X9 = [e1([j [j)] Pr1nt ( OJ fi(i I~ iii Ij)middot(i)(i) fiyenQ)riiio(i)(ij)(i)fj)fiyen1li1il1li1il)__ gtw~ __~_~ _~~_ ~_-=~
print(THE ANSWER IS NO ) print() )
( teI1(temp_6Ie)
prques(X9) Step 1Ob
close(temp_file)
nl print(Let me think about it) nl
consult(temp_6Ie) ))
retrac t( in pt(X))
Step lOb Printing question
prques(lcl(A 8)1) - prin(goo(() pl(qA 8) print()))
prques([c1(A 8HCs]) - prin(goo(() pl(qA 8) print() pl(q Cs)
pl(e [c1(A 8)]) - pl(eA 8)
pl(q [c1(A 8)]) - pl(qA 8) print()))
pl(S [e1(A B)ICs]) - pl(SA B) prin( ) pl(S Cs)
38
pl(q [j L) - prin(c1ause(contradiction(() pcont(qL) prin())_))
pl(S [I L)- prin(so2(contradidion(() pcont(SL) print))))middot
pl(S [L] []) - prin(so2() pcbar(SL) prin())
pl(S L [J)- prinsol() plett(SL) print))
pl(S [L] LI) - prin(condi(() pchar(cL)
prin(() pcont(S Ll) prine))))
pl(S L Ll)- prin(c1ause() plert(cL)
prin(() pcont(S Ll) prine)))
plert(S[LJ) - pchar(SL)
plert(SjLILsj) - pcbar(SL) print v) pleCt(SLs)
pcont(S[L]) - pchar(SL)
pcont(S[LILsj) - pcbar(SL) prinr ) pcont(SLs)
pcbar(SP) shy
atomic(P)
name(PL)
( L = [IT] L = [5 k miT] L = [5 k niT] )
concat[XITj NewP)
prin(0JewP)
pchar(SP) shy
atomic(P)
prin(P) pchar(SA lt=gt B) -
prin(() dausify(A AI []) pl(eAI) prin())
prinr lt=gt ) prin(() dausify(B BI ]) pl(eB) print))
pchar(Snumber(X N)) shy
prin(num() pchar(SX) prin()
pchar(SN) prinr))
pcbar(SM N) - prin(M N)
pcbar(cF(A B)) shy
selec(F(A Braquo
pcbar(cA)
prine F ) pchar(cB) pchar(SF(A B)) shy
selec(F(A B))
prin(sel() pchar(SA)
print F ) pchar(SB) print)) I
31
pc har(SF(A)) shy
( F= prefix gt= F= prefix lt= F= prefixgt F= prefix lt )
prin(F ) pchar(SA)
pchar(SP)shy
runctor(P F MaxN)
prin(F ()
011 is MaxN - 1 pout(SNl P MaxN)
print) )
pout(S 0 P M3xN) - 1
arg(~bxN P Argu)
pchlr(SArgu )
pout(S N P MaxN shy
Nl is MaxN - N
arg(Nl P Argu)
pchar(SArgu
prin( )
N2 is N - 1
pout(S N2 P ~13xN)
Comparing numbers in numerical quantifiers
num(XN) shy
number(X I)
cnum(N 1) ~
cnumlaquo=01 lt=I- N gt=I
cnumlaquo=J lt I) - N gt=1-1
cnumlaquo=NIJ) - N gt=J 1
cnumlaquo=N J)- integer(I) N gt=I~
cnum(gt=N gt=1) - N lt=1
cnum(gt=N gt I) - N lt=1+ 1 cnum(gt=NIJ) - N lt=1
cnum(gt=N lt=1)- N lt=1
cnum(gt=N lt I) - N lt=1 L cnum(gt=N 1)- integer(I) N lt=1
cnum( lt N lt 1)- N gt=1 L
38
cnum( lt N lt=1) - N gt I cnum( lt NLJ) - N gt J
cnum( lt N 1)- integer(I) N gt 1
cnum(gt N gt I) - N lt=1 cnumlgt i gt=1) - N lt I
cnum(gt N lt=1) - N lt=0
cnum(gt N lt I) - N lt=0
cnum(gt iIJ) - N lt I cnum(gt N 1)- integer(I) N lt I
cnum(~LN lt=1) - M=I N gt= I l
cnum(~LN lt I) - M=l N gt= I-I
cnum(~LNLJ) - M lt =1 N gt = J
cnum(~1N 1)- integer(I) M lt= I N gt= I
cnum(- N) - integer(N)
Comparing selectors
sel(X = Y) shyX= Y
sel(X I=Y) shy(X I=Y X lt Y Xgt Y)
sel(X gt Y) shyXgt Y
sel(X lt Y) shyXlt Y
selX gt=Y) shy(X gt=Y X= Y Xgt Y)
se(X lt=Y) shy
(X lt=Y
X= Y
X lt Y)
csel(infix = infix =)
39
csel(infix = infix = csel(infix = infix gt)
csel(infix = infix lt) csel(infix gt infix gt) cseJ(infix lt infix lt) csel(infix gt= infix gt=) csel(infix gt= infix gt csel(infix gt= infix =)
csellinfix lt= infix lt=) csel(infix lt= infix lt) csel(infix lt= infix =)
Finding solutions
sol(X v Y) -
(( notetra(X) eon(X) ( sol(Y) )
( c1ause(P v Q R) not(cketra(P v Q))
dis(P v Q X v Y R) ~ )
( A lt=gt B equival(A lt=gt B X v Y) ~ I) sol(X) - ~ notetra(X) eon(X)
so~(X) - notetra(X)
( con (X)
( clause(P v Q R) not(ekctra(P v Q)) dis(P v Q X R) I)
cketra(P v Q) -
eketra(P) eketra(Q) eketra(F(I J)) shy
selec(F(I J))
c1ause(contradiction(sel(F(IJ))) _I
eketra(number(W I)) -
clause(cootradietion(num(Wl)) - eketr(P) shy
clause(contradiction(P) - 1
notctra(P) shy
not( e lause( con tradiction(P) _))
40
Searching (or disjunctions
dis(P v Q X v Y R) - dis(P X v Y R)
dis(Q X v Y R) con(R)
dis(P v Q X R) -
dis(P X R) dis(Q X R) con(R
dis(P X v Y R) - clause(contradicton(Pl J 1
dis(F(I J) sel(G(I J)) v Y R) - csel(G Fl dis(number(WI) num(W N v Y R) - cnum(N I)
dis(P P v Y R) -
dis(P X v Y R) - dis(P Y R)
dis(F(I J) seJ(G(IJ)) R) - csel(G F)
dis(number(WI) num(WN) R) - cnum(N I) dis(P P R) - 1
dis(FJ J X R) shy
( ckctra(F(IJ) cbeckeq(seJ(F(IJ))) )
dis(number(W Il X R) - ( ckctra(number(WI)) cbeckeq(num(WI)) )
dis(P X R) shy( ckctra(P) cbeckeq(P) ) 1
cbeckeq(P) shy
(( A lt=gt so2(contradiction(P))
bagof(A A [jj) ) ( so2(contradiction(P)) lt=gt B
bagof(B B Uj) ))
ckeq(A) shy
( so2(A) lt=gt B B lt=gt so2(A) ) bagof(B B UJ)
con((P Q)) -
clause(P R) con(R) con(Q) con(true) -
con(contradiction(P)) - clause(contradiction(P) J
con(cause(X Y)) - cause(X Y)
con(sel(X)) - sel(X)
con(num(X Y)) - num(X Y) con(P)- (( dause(P R) (con(R) ckeq(R)))
colJectin(P) )
collectin(P) shy
bagof(S (c1ause(P S) S = true) [L LIJ )
mkcon(L Ll L)
bagor(l (L2 ) UJ) L
mkcon((A AI) (B B1) (sol(A v B) e D)) -
mkcon(A B1 e) mkcon(A1 (B Bl) D)
mkcon(A (B B1) (sol(A v B) e)) -
mkcon(A Bl e)
mkcon((A AI) B (sol(A v B) e)) middot1
mkcon(Al B e)
mkcon(A B sol(A vB))
Searching ror equivalences
equival(A lt=gt B X v Y) - 1 ( equival(A lt=gt B X) equival(A lt=gt B Y) )
equival(s02(A) lt=gt 502(B) A) - clause(B _I equival(s02(B) lt=gt 502(A) A) c1ause(B _I
Top level or inrerence mechanism
goo((s02(whatnum) P)) -
getatm(P Xl
bagor(number(X Y) ( P so2(number(X Y)) ) A )
count1(A 00 L R) nl
bagor(X P B )
count2(B L R Ll Rl) nJ print()
(( LI = 0 Rl = 0 print(THE ANSWER IS ) nl
(( Ll = Rl prin(-Jumber or ) prn(P) print(is Ll) )
( Rlgt20000 prin(Number or I prn(P) print(is LI or more) )
42
( prin(Number of ) pfn(P) print( is from Ll to Rl) )) )
( print(THE ANSWER IS NO I )) print()
goo(X) shy
(( bagof(X X L) L = [I nl print()
print(THE ANSWER IS YES) nl wout(L) print() )
( equiv(X L) nl print()
print(THE ANSWER IS YES) nl wout(L) print(-) )
( c1ause(inpt(A ==gt B) _I ( impli(A B Z) impli(B A Z) ) print(l~Hl)
printTHE ANSWER IS YES) nl print(Z) print(Hj~(fH~) ))
goo(X) print( Hg)
print(THE ANSWER IS NO ) print( lH~lH~gg9l9lmiddotmiddot~Q(gmiddot)
00 Semhing for implications in equiV3lent relations
impli( B Z) shyt-ell( z1) prin(templ() pchn(S A lt=gt B) print()) close ( zl) consult(zl) templ(Z)
unload zl Z
Searching for equivalence
equiv (X L)
(( X lt=gt Y
equ(Y YI)t bagof(Y Yl L) L = [j )
(Y lt=gt X equ(Y YI) bagof(Y Yl L) L = [J )
( X = F(New)
clause(~ew T) makeup(T Tl)
(( Tl lt=gt B
equ(B Bl) bagof(Bl Bl M) M = [j L=[Newl )
(A lt=gt TI
equ(A AI) bagof(Al AI M) M = 1] L=INewj )) ))
makeup((A B) (AI Bl)) -
makeup(A A1) makeup(B BI)
makeup(A so2(A))
equ((A B) (AI BI)) -
equ(A AI) equ(B Bl)
equ(sol(X v Y) sol(XI v Yl)) -
equ(X XI) equ(Y YI)
equ(so2(X) so2(XI)) -
equ(X XI)
equ(contradiction(X) clJuse(contradiction(X) X) ) -
equ(X X)
Counting numbers
getatm((A B) X) -
( getatm(A X) getatm(B X) )
getatm(so2(F(X)) X) -
getatm(so2(X) X) - atom(X)
countl([J L R L R) -
countl([number(X Y)IT] L R L2 R2) shy
(( Y = (gt=~) LI is L + N Rl is R + 20001 l )
( Y = (gt N) LI is L+ N+ 1 RI is R + 20002 )
(Y == laquo=~) LI is L + 1 Rl is R + N )
(Y = laquo N) LI is L + 1 RI is R+N-I)
(Y == IJ LI is L + I Rl is R + J ) ( Y == N L1 is L + N RI is R + N ))
count1(T LI R 1 L2 R2)
count2(fJ L R L R) - 1
count2([XITJ L R L2 R2) shy
name(X Xl)
(( Xl = sknj LI is L Rl is R )
44
( Xl = Iskmj L1 is L + 1 RI is R + ZOOO1) ( LI is L + I RI is R + I ))
count2(T LI RI L2 R2)
pfn((A B)) - pfn(A) prn(B)
pCn(so2(F(X))) - prin(F )
prn(so2(X)) - atom(X) prin(X ) prn (so2(X))
Printing result
wout([XlJ - prt(X) nl woutf[xIY]) - prt(X) nl nl wout(Y)
prt(e(A B)) -
prt(A) prinr 8 ) prt(ltE) prt(eA) - prt(A)
prt(c(A EJ) - prin() prt(A) prine ) prt(B) prin(T)
prt(c A) - prt(A) prt((A E)) - ~
prt(A) nl prt(E) prt(sol(X v Y)) - ~
prt(X) prinC v) prt(Y) prt(A lt=gt B) -
prt(e A) prinC lt=gt ) prt(e B) prt(sol(X)) - prt(X)
prt(so2(X)) - prt(X
prt(c1ause(X Y)) - prt(X)
prt(contradiction(X)) - prin(contradiction() prt(cX) prinr))middot prt(num(XY)) - prin(number(X Y)) prt(sel(X)) - prin(X) prt(X v Y) - prt(X) prin( v) prt(Y) prt(X) prin(X)
Handling conditional queries
condi((Y Xl) shy
assertcon(X) Y
45
retractcon(X)
condi((B A))
retractcon(A) fail
assertcon((A B)) 1
assertcon(A) assertcon(B)
assertcon(A) asserta(A)
retrac teon ((A B)) 1
retracteon(A) retractcon (B)
retraetcon(A) - retract(A)
BIBLIOGRAPHIC DATA SHEET
Report No UIUCDS-F-84-928
3 Recipients Accession No
4 T ide and Subt ltle
An Annotated Predicate Calculus Inference System (APCIS)
S Report Date
November 1984 6
7 Author(s)
Kah-Eng Pua 8 Performing Organization Rept
No
9 Performing Organization Name and Address
Department of Computer Science University of Illinois Urbana IL
10 ProjectTaskWork Unit No
11 Contract Grant No NSF DCR 84-06081 ONR N00014-82-K-0186
12 Sponsoring Organization Name and Address
National Science Foundation Washington DC
13 Type of Report amp Period Covered
14
15 Supplementary Notes
16 Abstracts
This paper describes a deductive inference system called APCIS (Annotated Predicate Calculus Inference System) APCIS is able to carry out inferences from expressions involving numerical quantifiers selectors disjunctions of non-negated terms negated terms disjunctions of negated terms equivalences and exceptions It is also able to count the numbers of occurrence of a given simple term or a conjunction of terms The design of contradiction and the treatment of the disjunction of non-negated terms allow APCIS to accept Horn clauses as well as non-Horn clauses and to carry out inferences from them This feature makes APCIS more general than Prolog
17 Key lords and Document Analysis 170 Descriptors
APC (Annotated Predicate Calculus) APCIS (Annotated Predicate Calculus Inference System) Horn Clause Numerical Quantifier Prolog Selector
17b IdentifiersOpen-Ended Terms
17c COSATI FieldGroup
18 Availability Statement 19 Security Class (This
Re~f~~IA~SIF IFf)
21 ~o of Pages
49 211 ecurity Class (This
PageUNCLASSIFIED
22 Price
FOA NTIS n (10middot70 usco-oc 40329-
21
References
[1] W F Clocksin and C S Mellish Programming In Prolog Springermiddot Verlag Berlin Hpoundidelberg 1981
[2] R S Michalski A Theory and Methodology of Inductive Learning Chpt 4 Machine L earning Tioga Publishing Co Palo Alto CaliJornia 1989
[3] K-E Pua Translating Annotated Predicate Calculu8 to Prolog ISG Report 84middot1 UlUCDCSmiddotFmiddot918 University oj Illinois Urbana IL June 1984
22
Appendix A
APCIS Users Manual
1 Get Started
Users are urged to follow the steps depicted below
1 Get the PROLOG interpreter by typing
alias prolog mntb2sammutsammutprologprolog (Vax A)
or
alias prolog mntb2sammutsammutbinprolog (Vax B)
2 Load apc and infer by typing
prolog apc infer
When large APC expressions are expected we can increase the stlck by typingI
prolog -snnnn ape infer
where ns denote the number of stacks in decimal
3 When the wording LSW - PROLOG appears on the terminal we are reldy to interact
with APCIS The four modes by which we can invoke APCIS are summarized below
a Assert ion-Translation Mode
ta(X)
b Query-Translation Mode
tq(X)
c Assertion Mode
a(X
d Query Mode
q(X)
23
where Xs are APC expressions
2 Notations Used in APCIS
Below is a summary or notations used in APCIS
a Logical operators
amp
v
==gt
lt=gt
-
negation
conjunction
disjunction
implication
equivalence
exception
b Binary relation symbols in selectors
-
=
gt=
lt=
gt
lt
equal
not equal
greater or equal
smaller or equ al
greater
smaller
c Relational operators in numerical quantifiers
lt less than
lt= less than or equal
gt greater than
gt= greater than or equal
d BinlTY operator in numerical quantifier
range
e Universal quantifier
all(X p(X))
f Existential quantifier
exists(X p(X))
g Numerical quantifier
exists(I X p(X))
where p(X) is a formula
where X is a variable or a Jist of variables or the
form [HI~rj and p(X) a formula
where I repersents expression involving integer(s)
and operator(s) in c or d above and p(X) a formula
25
Appendix B
APCIS Program Listings
------------------------------- Program Name APCIS - Part 1 APC Translator
-------------------------------
op(3OO fx -)1
op(500 xfy amp)
oPt 500 xfy v)
op(600 xfx )
op(700 fx [gt= lt= gt lt ]) op(400 xfy [= gt= lt= gt lt ])1 op(900 xfy gt lt=gt -])1
steps(X Xg) shy
numbervars(X 1 J Step 1 change variables to iis
rmimp(X X) Step 2 conv(X X3) Step 3
rewrite(X3 X4) Step 4
negin(X4 X5) Step 5
dropexist(X5 X6 1]) Step 6
dropall(X6 X7) Step 7
distrib(X7 X8) Step 8 clausiCy(X8 X9 [J) Step 9
ta(X) shysteps(X Xg)
(( Xg = II nl
print( yes it is always true) )
( nl nl printcl(X9))) Step 10a
tq(X) shy
steps(X Xg)
prques(Xg)
28
Step 2 Removing implic3tions amp Transforming exceptions and equiv3lences
rmimpl( P - Q (PI lt=gt (QI) ) amp ((PI) lt=gt QI) ) -
rmimpl(P PI) rmimpl(Q QI)
rmimplnp) lt=gt Q (PI lt=gt -(QI)) amp nPI) lt=gt QI) ) - 1
rmimpl(P PI) rmimpJ(Q QI)
rmimpJ(P lt-gt -(Q) (PI lt=gt -(QI)) amp nPI) lt=gt QI) ) -
rmimpl(P PI) rmimpl(Q QI)
rmimpl( P lt=gt Q PI lt=gt QI ) - I
rmimpl(P PI) rmimpl(Q QI)
rmimpl( P ==gt Q -(PI) v QI ) - I
rmimpl(P PI) rmimpl(Q QI)
rmimpl( all(X P) aI(X PI) ) - 1
rmimpl(P PI)
rmimpl( exists(X P) exists(X PI) ) -
rmimpl(P PI)
rmimpl( exists(I X P) exists(I X PI) ) -
rmimpl(P PI)
rmimpl( P amp Q PI amp Ql ) -
rmimpl(P PI) rmimpl(Q Ql)
rmimpl( P v Q PI v QI ) -
rmimpl(P PI) rmimpl(Q QI)
rmimpl( -(p) -(PI) ) - I
rmimpl(p PI)
rmimpl( P P )
St~p 3 Converting numerical amp distinctive quantifiers
L Numerical quantifiers
examples of input forms
1 exists(gt= i X pIX)) where i is an integer
2 exists(i X pIX)) where i is an integer
3 exists(i j X pIX)) where i j are integers and iltj
4 exists(il v i2 X pIX)) where is are integers
examples of output forms of this step
1 exists(X pIX) amp number(X gt= i) )
2 exists(X pIX) amp number(X i) ) 3 exists(X pIX) amp number(X ij) ) 4 exists(X pIX) amp number(X il v i2) )
II Distinctive quantifiers
27
example or input Corm
exists([XYL p(X Y))
example or output Corm or this step
exists(X exists(Y p(XY)) )
conv(P lt=gt Q PI lt=gt QI) - 1
conv(P PI) conv(Q QI)
conv(al1(X P) all(X PI)) -
conv(P PI)
conv(exists(HIT] P) R ) - conv(P PI) convert distinctive quantifier
convtdis(exists([HIT]PI) R)
conv( exists(I X P) exists(X PIamp number(X I) )) -
conv(P PI) convert numerical quantifier
conv(exists(X P) exists(X PI)) - 1
conv(P Pl)
conv(P amp Q PI amp QI) - 1
conv(P PI) conv(Q QI)
conv(P v Q PI v QI) - t conv(P PI) conv(Q QI)
convC(P) -(PI)) -
conv(P PI)
conv(P Pl
convtdis(existsl[XL P) exists(X P)) - atomic(X) convtdis(exists[XIYj Pl exists(X R)) shy
convtdis(exists(Y P) R)
Step 4 Rewriting compound predicates andor compound selectors
Outputs are smiple predicates andor simple selectors
rewrite(P lt=gt Q PI lt=gt QI) - t rewrite(P PI) rewrite(Q QI)
rewrite(all(X Pl all(X PI)) - 1 rewrite(P PI)
rewriteexists(X P) exists(X PI)) - I rewriteP PI)
rewrite(P amp Q PI amp QI) - rewrite(P P 1) rewrite( Q Q 1
rewrite(P v Q PI v QI) - 1
rewrite(P PI) rewrite(Q QI)
rewriteC(P) -(PI)) - I
28
rewrite(P PI) rewrite(F(A B) R) -
rewrite(A AI) rewrite(B BI) re(F(AI BI) R)
rewrite(F(A) R) -
rewrite(A AI) re(F(AI) H)
rewrite(F(A B C) R) -
rewrite(A AI) rewrite(B BI) rewrite(C CI) re(F(AI BI CI) R)
rewrite(F(A B C D) R) -
rewrite(A AI) rewrite(B Btl rewrite(C CI) rewrite(D DI) rc(F(AI BI CI Dl) H)
rewrite(PP)
re(F(A B v el (RI v R2) -
re(F(A Bl RIl re(F(A C) R2) reF(A B amp cl (RI amp R2)) -
re(F(A B) RI) re(F(A e) R2) re(F(A amp B C) (Rl amp R2)) -
re(F(A e) R 1) re(F(B C) R 2) re(F( v B el (R I v R2)) -
re(F(A el R I) reFB el R2) re(F(A amp Bl (R I amp R2)) -
re(F(A RI) re(F(BJH2) re(F(A v B) (R 1 v R2)) -
re(F(A) RI) re(F(B) R2)
re(F(A vB c Dl (RI v R2) -
re(F(A C D) RI) re(F(B C D) R2) re(F(A amp B C D) (RI amp R2)) -
re(F(A C D) Rll re(F(B C D) R2) re(F(A B v C D) (HI v R2)) -
re(F(A B D) RI) re(F(A C D) R2) re(F(A B amp C D) (HI amp R2)) -
re(F(A B D) RI) re(F(A C D) R2) re(F(A B C v D) (RI v R2)) -
re(F(A B C) R I) reF(A B D) R2) re(F(A B C amp D) (RI amp R2)) -
29
re(F(A B C) RI) re(F(A B D) RZ)
re(F(A v B e D E) (R I v R2)) -
re(F(A e D E) R I) re(F(B e D El R2) re(F(A amp B e D E) (RI amp RZ)) -
re(F(A e D El R 1) re(F(B e D E) R2) re(F(A B v e D E) (R I v R2)) -
re(F(A B D E) RI) re(F(A e D E) R2)
re(F(A B amp e D E) (RI amp R2)) -
re(F(A B D El RI) re(F(A e D E) RZ) re(F(A B e v D E) (R I v R2)) -
re(F(A B e El R 1) re(F(A B D E) RZ) re(F(A B e amp D E) (RI amp RZ)) -
re(F(A B e E) R I) re(F(A B D E) RZ)
re(F(A B e D vEl (RI v RZ)) - l
rc(F(A B C D) RI) re(F(A n e El RZ) re(F(A B e D amp El (RI amp RZ)) - ~
re(F(A B e D) RI) re(F(A B e El RZ)
re((A = B) (A = B)l-
re((A = Bl (A = 8)) -
retIA gt= BI (A gt= B)) -
re((A lt= B) (A lt= B)) -
re((A gt B) (A gt B))-
re((A lt Bl (A lt Bl)- re(A A)
Step) Bringing n(gation inwards
Degin(-(P) PI) - neg(P Pl)
negin(P lt=gt Q PI lt=gt Ql) - ~
negin(P PI) negiD(Q QI)
Degin(aU(X P) all(X PI)) - Degin(P PI) negin(exists(X P) exists(X PI))- negin(P PI) negin(P amp Q PI amp Ql) - Degin(P PI) negin(Q Ql)
Degin(P v Q PI v QI) - Degin(P PI) negin(Q QI) negin(P Pl
neg(-(P) PI) - negin(P PI)
neg(all(X P) exists(X PI)) - neg(P PI)
30
neg(exists(X P) all(X PI)) - neg(P PI)
neg(P amp Q PI v QI) - neg(P PI) neg(Q Ql)
neg(P v Q PI amp QI) - neg(P PI) neg(Q QI)
neg(P -(PH
Step 6 Dropping existnetial quanti6ers
dropexist(P lt=gt Q PI lt=gt QI Elerns) - dropexist(P PI Elerns) dropexist(Q QI Elerns)
dropexist(alJ(X P) all(XPI) Elerns)
dropexist(P PI [XIElernsJ)
dropexist(exists(X P amp nurnber(X Yraquo P2 Elerns) -
genfun(skn Newg) Fun = [NewgIElerns]
subst(FuD X P amp Dumber(X Y) PI)
dropexist(Pl P2 Elerns)
dropexist(exists(X P) PZ Elerns) -
genfun(skrn Newf) Fun = [NewfIElernsJ
subst(Fun X p PI)
dropex ist(P 1 P~ Elerns)
dropexist(P v Q PI v QI Elerns) - ~
dropexist(P PI Elerns) dropexist(Q Ql Elerns)
dropexist(P amp Q PI amp QI Elerns) - 1
dropexist(P Pl Elerns) dropexist(Q QI Elerns)
dropexist(P P _)
gen fun(R oot Newn arne) shy
getnurn(Root Nurn)
narne(Root Rootlist)
append(Rootlist[Nurnj Narnelist)
concat(Narnelist Newnarne)
getnurn(Root Nurn) shy
retract(currentnurn(Root Nurn 1 raquo
Nurn is Nurni + 1
asserta(currentnurn(Root Nurn))
getnurn(Root 1) - asserta(currentnurn(Root 1))
subst(New Old Val Val) - var(Val)
subst(New Old Old New) - 1 substNew Old Val Val) - atornic(Val)
31
subst(New Old Val Newval) shy
runctor(Val F N)
CUDctor(Newval F N)
subst_args(N New Old Val Newval)
subst_args(O J J - J J
subst_args(N New Old Val NewVal) shy
arg(N Val OldArg)
arg(N NewVal NewArg)
subst(New Old OldArg NewArg)
NI is N - I
subst_args(Nl New Old Val NewVal)
append([J L L) -
append([XILl] L2 [XIL3]) - append(Ll L2 L3)
Step - Dropping universal quantifiers
dropall(P lt=gt Q PI lt=gt QI)-
dropall(P PI) dropall(Q QI)
dropall(all(X P) PI) - ~ dropall(P PI)
dropall(P amp Q PI amp QI) -
dropall(P PI) dropall(Q QI)
dropall(P v Q PI v QI) -
dropall(P PI) dropall(Q QI)
dropall(P P)
Step 8 Distributing conjunctions over disjunctions
distrib(P lt=gt Q PI lt=gt Ql) - t distrib(P PI) distrib(Q QI)
distrib(P v Q R) -
distrib(P PI) distrib(Q QI)
distributing(PI v QI R)
distrib(P it Q PI it QI) -
distrib(P PI) distrib( Q QI)
distrib(P P)
distributing((P amp Q) v R PI amp QI) -
distrib(P v R PI) distrib(Q v R Ql)
32
distributing(P v (Q amp R) PI amp Ql) -
distrib(P v Q PI) distrib(P v R Ql)
distributing(P P)
Step 9 Packing each conjunction into clauses
c1ausify(P amp Q CI C2) -
clausiCy(P CI C3) c1ausify(Q C3 C2)
cbusiCy(P [d(A B)ICs] Cs) shy
inclause(P A [j B [I) 1
c1ausiry( C C)
inclause(P v Q A AI B B1) -
inc1ause(P A2 AI B2 Bl)
inclause(Q A A2 B B2)
inclausenp) A A B1 B) -
notin(P A) putin(P B B1)
inclause(P AI A B B) shy
notin(P Bl putin(P A AI)
notin(X [XU) - fail
notin(X [JLj) - notin(X L)
notin(X 1])
putin(X II [X]) - 1
putin(X [XILJ L) -
putin(X [YILJ [YILl]) - putin(X L Ll)
Step 1Oa Printing clauses
printcl([]) - nl nl
printcl(c1(AB)ICsj) - printcl(A Bl nl printcl(Cs)
printcl(L II) - printdis(IL) prinr)middot
printclHl L) - prin(contradiction(() printconl(rL)
print()) - ) printconj(rL) prinr )
printcl(Ll L2) shy
printdis(ILl) print( - ) printconj(rL2) prin()
printdis(S[Lj) - printcbar(SL)
33
printdis(S[LILs]) - printchu(SL) prin( v) printdis(SLs)
printconl(S[LI) - printchar(SL)
printconl(S[LILs]) - printchar(SL) prin( ) printconl(SLs)
printconj(S[L]) - tab(3) printchar(SL)
prin tconj( S [L IL sl) shy
tab(3) printchar(SL) print( ) printconj(SLs)
printchar(SP) shy
atomic(P)
name(P L)
L = [IT]
concat([XIT NewP)
prin(~ewP)
printchar(SP) shy
atomic(P)
prin(P)
printchar(SA lt= gt B) -
prin((l clausify(A AI [j) pl(eAl) prin())
print lt=gt )
prin(() cbusify(B Bl [I) pJ(eBl) prine))middot
printchar(rnumber(X N)) shy
prin(num() printchar(rx) prin( )
printchar(rN) prinC))
printchar(rF(A B)) shy
seJec(F(A B))
prinCsel() printchar(rA)
prin( F ) printchar(rB) prinC))
printchar(SF(A B)) shy
( selec(F(A B)) F = infix )
printchar(SA) prin( F ) printchar(SB)
printchar(SF(A)) shy
(F= prefix gt= F= prefix lt= F= prefixgt F= prefix lt )
prin(F ) printcbar(SA)
printchar(SP) shy
functor(P F MaxN)
prin(F ()
Nl is MaxN - 1
putout(S N 1 P MaxN)
34
prin())
putout(S 0 P MaxN) -
arg(~laxN P Argu)
prin tchar(SArgu)
putout(S N p MaxN) shy
Nt is MaxN - N arg(NI P Argu)
printcbar(SArgu )
prin( )
N2 is N - 1
putout(S N2 P MaxN)
selec(FA B)) shy
( F= infix = F= infix f= F= infix gt=
F= infix gt F= infix lt= F= infix lt )
35
----------------------------------Program Name APClS - Part 2 Inference Mechanism ---------------------------------- a(X) shy
steps(X X9)
(( X9 =[] nl
print( yes it is always true) )
( X9 =[cI(IJ[])] nl
print( no it is always false) )
( nl nl printel(X9) Step 1Oa
tell(temp_file) printel(X9) e1ose(temp_file) consult(temp_6Ie) ))
q(X) shy
asserta( in pt(X))
steps(X X9)
(( X9 = [] print(middot~H~~middot~t~)
print(THE AiSWER IS YES)
print( ilgIQlQl(~) )
( X9 = [e1([j [j)] Pr1nt ( OJ fi(i I~ iii Ij)middot(i)(i) fiyenQ)riiio(i)(ij)(i)fj)fiyen1li1il1li1il)__ gtw~ __~_~ _~~_ ~_-=~
print(THE ANSWER IS NO ) print() )
( teI1(temp_6Ie)
prques(X9) Step 1Ob
close(temp_file)
nl print(Let me think about it) nl
consult(temp_6Ie) ))
retrac t( in pt(X))
Step lOb Printing question
prques(lcl(A 8)1) - prin(goo(() pl(qA 8) print()))
prques([c1(A 8HCs]) - prin(goo(() pl(qA 8) print() pl(q Cs)
pl(e [c1(A 8)]) - pl(eA 8)
pl(q [c1(A 8)]) - pl(qA 8) print()))
pl(S [e1(A B)ICs]) - pl(SA B) prin( ) pl(S Cs)
38
pl(q [j L) - prin(c1ause(contradiction(() pcont(qL) prin())_))
pl(S [I L)- prin(so2(contradidion(() pcont(SL) print))))middot
pl(S [L] []) - prin(so2() pcbar(SL) prin())
pl(S L [J)- prinsol() plett(SL) print))
pl(S [L] LI) - prin(condi(() pchar(cL)
prin(() pcont(S Ll) prine))))
pl(S L Ll)- prin(c1ause() plert(cL)
prin(() pcont(S Ll) prine)))
plert(S[LJ) - pchar(SL)
plert(SjLILsj) - pcbar(SL) print v) pleCt(SLs)
pcont(S[L]) - pchar(SL)
pcont(S[LILsj) - pcbar(SL) prinr ) pcont(SLs)
pcbar(SP) shy
atomic(P)
name(PL)
( L = [IT] L = [5 k miT] L = [5 k niT] )
concat[XITj NewP)
prin(0JewP)
pchar(SP) shy
atomic(P)
prin(P) pchar(SA lt=gt B) -
prin(() dausify(A AI []) pl(eAI) prin())
prinr lt=gt ) prin(() dausify(B BI ]) pl(eB) print))
pchar(Snumber(X N)) shy
prin(num() pchar(SX) prin()
pchar(SN) prinr))
pcbar(SM N) - prin(M N)
pcbar(cF(A B)) shy
selec(F(A Braquo
pcbar(cA)
prine F ) pchar(cB) pchar(SF(A B)) shy
selec(F(A B))
prin(sel() pchar(SA)
print F ) pchar(SB) print)) I
31
pc har(SF(A)) shy
( F= prefix gt= F= prefix lt= F= prefixgt F= prefix lt )
prin(F ) pchar(SA)
pchar(SP)shy
runctor(P F MaxN)
prin(F ()
011 is MaxN - 1 pout(SNl P MaxN)
print) )
pout(S 0 P M3xN) - 1
arg(~bxN P Argu)
pchlr(SArgu )
pout(S N P MaxN shy
Nl is MaxN - N
arg(Nl P Argu)
pchar(SArgu
prin( )
N2 is N - 1
pout(S N2 P ~13xN)
Comparing numbers in numerical quantifiers
num(XN) shy
number(X I)
cnum(N 1) ~
cnumlaquo=01 lt=I- N gt=I
cnumlaquo=J lt I) - N gt=1-1
cnumlaquo=NIJ) - N gt=J 1
cnumlaquo=N J)- integer(I) N gt=I~
cnum(gt=N gt=1) - N lt=1
cnum(gt=N gt I) - N lt=1+ 1 cnum(gt=NIJ) - N lt=1
cnum(gt=N lt=1)- N lt=1
cnum(gt=N lt I) - N lt=1 L cnum(gt=N 1)- integer(I) N lt=1
cnum( lt N lt 1)- N gt=1 L
38
cnum( lt N lt=1) - N gt I cnum( lt NLJ) - N gt J
cnum( lt N 1)- integer(I) N gt 1
cnum(gt N gt I) - N lt=1 cnumlgt i gt=1) - N lt I
cnum(gt N lt=1) - N lt=0
cnum(gt N lt I) - N lt=0
cnum(gt iIJ) - N lt I cnum(gt N 1)- integer(I) N lt I
cnum(~LN lt=1) - M=I N gt= I l
cnum(~LN lt I) - M=l N gt= I-I
cnum(~LNLJ) - M lt =1 N gt = J
cnum(~1N 1)- integer(I) M lt= I N gt= I
cnum(- N) - integer(N)
Comparing selectors
sel(X = Y) shyX= Y
sel(X I=Y) shy(X I=Y X lt Y Xgt Y)
sel(X gt Y) shyXgt Y
sel(X lt Y) shyXlt Y
selX gt=Y) shy(X gt=Y X= Y Xgt Y)
se(X lt=Y) shy
(X lt=Y
X= Y
X lt Y)
csel(infix = infix =)
39
csel(infix = infix = csel(infix = infix gt)
csel(infix = infix lt) csel(infix gt infix gt) cseJ(infix lt infix lt) csel(infix gt= infix gt=) csel(infix gt= infix gt csel(infix gt= infix =)
csellinfix lt= infix lt=) csel(infix lt= infix lt) csel(infix lt= infix =)
Finding solutions
sol(X v Y) -
(( notetra(X) eon(X) ( sol(Y) )
( c1ause(P v Q R) not(cketra(P v Q))
dis(P v Q X v Y R) ~ )
( A lt=gt B equival(A lt=gt B X v Y) ~ I) sol(X) - ~ notetra(X) eon(X)
so~(X) - notetra(X)
( con (X)
( clause(P v Q R) not(ekctra(P v Q)) dis(P v Q X R) I)
cketra(P v Q) -
eketra(P) eketra(Q) eketra(F(I J)) shy
selec(F(I J))
c1ause(contradiction(sel(F(IJ))) _I
eketra(number(W I)) -
clause(cootradietion(num(Wl)) - eketr(P) shy
clause(contradiction(P) - 1
notctra(P) shy
not( e lause( con tradiction(P) _))
40
Searching (or disjunctions
dis(P v Q X v Y R) - dis(P X v Y R)
dis(Q X v Y R) con(R)
dis(P v Q X R) -
dis(P X R) dis(Q X R) con(R
dis(P X v Y R) - clause(contradicton(Pl J 1
dis(F(I J) sel(G(I J)) v Y R) - csel(G Fl dis(number(WI) num(W N v Y R) - cnum(N I)
dis(P P v Y R) -
dis(P X v Y R) - dis(P Y R)
dis(F(I J) seJ(G(IJ)) R) - csel(G F)
dis(number(WI) num(WN) R) - cnum(N I) dis(P P R) - 1
dis(FJ J X R) shy
( ckctra(F(IJ) cbeckeq(seJ(F(IJ))) )
dis(number(W Il X R) - ( ckctra(number(WI)) cbeckeq(num(WI)) )
dis(P X R) shy( ckctra(P) cbeckeq(P) ) 1
cbeckeq(P) shy
(( A lt=gt so2(contradiction(P))
bagof(A A [jj) ) ( so2(contradiction(P)) lt=gt B
bagof(B B Uj) ))
ckeq(A) shy
( so2(A) lt=gt B B lt=gt so2(A) ) bagof(B B UJ)
con((P Q)) -
clause(P R) con(R) con(Q) con(true) -
con(contradiction(P)) - clause(contradiction(P) J
con(cause(X Y)) - cause(X Y)
con(sel(X)) - sel(X)
con(num(X Y)) - num(X Y) con(P)- (( dause(P R) (con(R) ckeq(R)))
colJectin(P) )
collectin(P) shy
bagof(S (c1ause(P S) S = true) [L LIJ )
mkcon(L Ll L)
bagor(l (L2 ) UJ) L
mkcon((A AI) (B B1) (sol(A v B) e D)) -
mkcon(A B1 e) mkcon(A1 (B Bl) D)
mkcon(A (B B1) (sol(A v B) e)) -
mkcon(A Bl e)
mkcon((A AI) B (sol(A v B) e)) middot1
mkcon(Al B e)
mkcon(A B sol(A vB))
Searching ror equivalences
equival(A lt=gt B X v Y) - 1 ( equival(A lt=gt B X) equival(A lt=gt B Y) )
equival(s02(A) lt=gt 502(B) A) - clause(B _I equival(s02(B) lt=gt 502(A) A) c1ause(B _I
Top level or inrerence mechanism
goo((s02(whatnum) P)) -
getatm(P Xl
bagor(number(X Y) ( P so2(number(X Y)) ) A )
count1(A 00 L R) nl
bagor(X P B )
count2(B L R Ll Rl) nJ print()
(( LI = 0 Rl = 0 print(THE ANSWER IS ) nl
(( Ll = Rl prin(-Jumber or ) prn(P) print(is Ll) )
( Rlgt20000 prin(Number or I prn(P) print(is LI or more) )
42
( prin(Number of ) pfn(P) print( is from Ll to Rl) )) )
( print(THE ANSWER IS NO I )) print()
goo(X) shy
(( bagof(X X L) L = [I nl print()
print(THE ANSWER IS YES) nl wout(L) print() )
( equiv(X L) nl print()
print(THE ANSWER IS YES) nl wout(L) print(-) )
( c1ause(inpt(A ==gt B) _I ( impli(A B Z) impli(B A Z) ) print(l~Hl)
printTHE ANSWER IS YES) nl print(Z) print(Hj~(fH~) ))
goo(X) print( Hg)
print(THE ANSWER IS NO ) print( lH~lH~gg9l9lmiddotmiddot~Q(gmiddot)
00 Semhing for implications in equiV3lent relations
impli( B Z) shyt-ell( z1) prin(templ() pchn(S A lt=gt B) print()) close ( zl) consult(zl) templ(Z)
unload zl Z
Searching for equivalence
equiv (X L)
(( X lt=gt Y
equ(Y YI)t bagof(Y Yl L) L = [j )
(Y lt=gt X equ(Y YI) bagof(Y Yl L) L = [J )
( X = F(New)
clause(~ew T) makeup(T Tl)
(( Tl lt=gt B
equ(B Bl) bagof(Bl Bl M) M = [j L=[Newl )
(A lt=gt TI
equ(A AI) bagof(Al AI M) M = 1] L=INewj )) ))
makeup((A B) (AI Bl)) -
makeup(A A1) makeup(B BI)
makeup(A so2(A))
equ((A B) (AI BI)) -
equ(A AI) equ(B Bl)
equ(sol(X v Y) sol(XI v Yl)) -
equ(X XI) equ(Y YI)
equ(so2(X) so2(XI)) -
equ(X XI)
equ(contradiction(X) clJuse(contradiction(X) X) ) -
equ(X X)
Counting numbers
getatm((A B) X) -
( getatm(A X) getatm(B X) )
getatm(so2(F(X)) X) -
getatm(so2(X) X) - atom(X)
countl([J L R L R) -
countl([number(X Y)IT] L R L2 R2) shy
(( Y = (gt=~) LI is L + N Rl is R + 20001 l )
( Y = (gt N) LI is L+ N+ 1 RI is R + 20002 )
(Y == laquo=~) LI is L + 1 Rl is R + N )
(Y = laquo N) LI is L + 1 RI is R+N-I)
(Y == IJ LI is L + I Rl is R + J ) ( Y == N L1 is L + N RI is R + N ))
count1(T LI R 1 L2 R2)
count2(fJ L R L R) - 1
count2([XITJ L R L2 R2) shy
name(X Xl)
(( Xl = sknj LI is L Rl is R )
44
( Xl = Iskmj L1 is L + 1 RI is R + ZOOO1) ( LI is L + I RI is R + I ))
count2(T LI RI L2 R2)
pfn((A B)) - pfn(A) prn(B)
pCn(so2(F(X))) - prin(F )
prn(so2(X)) - atom(X) prin(X ) prn (so2(X))
Printing result
wout([XlJ - prt(X) nl woutf[xIY]) - prt(X) nl nl wout(Y)
prt(e(A B)) -
prt(A) prinr 8 ) prt(ltE) prt(eA) - prt(A)
prt(c(A EJ) - prin() prt(A) prine ) prt(B) prin(T)
prt(c A) - prt(A) prt((A E)) - ~
prt(A) nl prt(E) prt(sol(X v Y)) - ~
prt(X) prinC v) prt(Y) prt(A lt=gt B) -
prt(e A) prinC lt=gt ) prt(e B) prt(sol(X)) - prt(X)
prt(so2(X)) - prt(X
prt(c1ause(X Y)) - prt(X)
prt(contradiction(X)) - prin(contradiction() prt(cX) prinr))middot prt(num(XY)) - prin(number(X Y)) prt(sel(X)) - prin(X) prt(X v Y) - prt(X) prin( v) prt(Y) prt(X) prin(X)
Handling conditional queries
condi((Y Xl) shy
assertcon(X) Y
45
retractcon(X)
condi((B A))
retractcon(A) fail
assertcon((A B)) 1
assertcon(A) assertcon(B)
assertcon(A) asserta(A)
retrac teon ((A B)) 1
retracteon(A) retractcon (B)
retraetcon(A) - retract(A)
BIBLIOGRAPHIC DATA SHEET
Report No UIUCDS-F-84-928
3 Recipients Accession No
4 T ide and Subt ltle
An Annotated Predicate Calculus Inference System (APCIS)
S Report Date
November 1984 6
7 Author(s)
Kah-Eng Pua 8 Performing Organization Rept
No
9 Performing Organization Name and Address
Department of Computer Science University of Illinois Urbana IL
10 ProjectTaskWork Unit No
11 Contract Grant No NSF DCR 84-06081 ONR N00014-82-K-0186
12 Sponsoring Organization Name and Address
National Science Foundation Washington DC
13 Type of Report amp Period Covered
14
15 Supplementary Notes
16 Abstracts
This paper describes a deductive inference system called APCIS (Annotated Predicate Calculus Inference System) APCIS is able to carry out inferences from expressions involving numerical quantifiers selectors disjunctions of non-negated terms negated terms disjunctions of negated terms equivalences and exceptions It is also able to count the numbers of occurrence of a given simple term or a conjunction of terms The design of contradiction and the treatment of the disjunction of non-negated terms allow APCIS to accept Horn clauses as well as non-Horn clauses and to carry out inferences from them This feature makes APCIS more general than Prolog
17 Key lords and Document Analysis 170 Descriptors
APC (Annotated Predicate Calculus) APCIS (Annotated Predicate Calculus Inference System) Horn Clause Numerical Quantifier Prolog Selector
17b IdentifiersOpen-Ended Terms
17c COSATI FieldGroup
18 Availability Statement 19 Security Class (This
Re~f~~IA~SIF IFf)
21 ~o of Pages
49 211 ecurity Class (This
PageUNCLASSIFIED
22 Price
FOA NTIS n (10middot70 usco-oc 40329-
22
Appendix A
APCIS Users Manual
1 Get Started
Users are urged to follow the steps depicted below
1 Get the PROLOG interpreter by typing
alias prolog mntb2sammutsammutprologprolog (Vax A)
or
alias prolog mntb2sammutsammutbinprolog (Vax B)
2 Load apc and infer by typing
prolog apc infer
When large APC expressions are expected we can increase the stlck by typingI
prolog -snnnn ape infer
where ns denote the number of stacks in decimal
3 When the wording LSW - PROLOG appears on the terminal we are reldy to interact
with APCIS The four modes by which we can invoke APCIS are summarized below
a Assert ion-Translation Mode
ta(X)
b Query-Translation Mode
tq(X)
c Assertion Mode
a(X
d Query Mode
q(X)
23
where Xs are APC expressions
2 Notations Used in APCIS
Below is a summary or notations used in APCIS
a Logical operators
amp
v
==gt
lt=gt
-
negation
conjunction
disjunction
implication
equivalence
exception
b Binary relation symbols in selectors
-
=
gt=
lt=
gt
lt
equal
not equal
greater or equal
smaller or equ al
greater
smaller
c Relational operators in numerical quantifiers
lt less than
lt= less than or equal
gt greater than
gt= greater than or equal
d BinlTY operator in numerical quantifier
range
e Universal quantifier
all(X p(X))
f Existential quantifier
exists(X p(X))
g Numerical quantifier
exists(I X p(X))
where p(X) is a formula
where X is a variable or a Jist of variables or the
form [HI~rj and p(X) a formula
where I repersents expression involving integer(s)
and operator(s) in c or d above and p(X) a formula
25
Appendix B
APCIS Program Listings
------------------------------- Program Name APCIS - Part 1 APC Translator
-------------------------------
op(3OO fx -)1
op(500 xfy amp)
oPt 500 xfy v)
op(600 xfx )
op(700 fx [gt= lt= gt lt ]) op(400 xfy [= gt= lt= gt lt ])1 op(900 xfy gt lt=gt -])1
steps(X Xg) shy
numbervars(X 1 J Step 1 change variables to iis
rmimp(X X) Step 2 conv(X X3) Step 3
rewrite(X3 X4) Step 4
negin(X4 X5) Step 5
dropexist(X5 X6 1]) Step 6
dropall(X6 X7) Step 7
distrib(X7 X8) Step 8 clausiCy(X8 X9 [J) Step 9
ta(X) shysteps(X Xg)
(( Xg = II nl
print( yes it is always true) )
( nl nl printcl(X9))) Step 10a
tq(X) shy
steps(X Xg)
prques(Xg)
28
Step 2 Removing implic3tions amp Transforming exceptions and equiv3lences
rmimpl( P - Q (PI lt=gt (QI) ) amp ((PI) lt=gt QI) ) -
rmimpl(P PI) rmimpl(Q QI)
rmimplnp) lt=gt Q (PI lt=gt -(QI)) amp nPI) lt=gt QI) ) - 1
rmimpl(P PI) rmimpJ(Q QI)
rmimpJ(P lt-gt -(Q) (PI lt=gt -(QI)) amp nPI) lt=gt QI) ) -
rmimpl(P PI) rmimpl(Q QI)
rmimpl( P lt=gt Q PI lt=gt QI ) - I
rmimpl(P PI) rmimpl(Q QI)
rmimpl( P ==gt Q -(PI) v QI ) - I
rmimpl(P PI) rmimpl(Q QI)
rmimpl( all(X P) aI(X PI) ) - 1
rmimpl(P PI)
rmimpl( exists(X P) exists(X PI) ) -
rmimpl(P PI)
rmimpl( exists(I X P) exists(I X PI) ) -
rmimpl(P PI)
rmimpl( P amp Q PI amp Ql ) -
rmimpl(P PI) rmimpl(Q Ql)
rmimpl( P v Q PI v QI ) -
rmimpl(P PI) rmimpl(Q QI)
rmimpl( -(p) -(PI) ) - I
rmimpl(p PI)
rmimpl( P P )
St~p 3 Converting numerical amp distinctive quantifiers
L Numerical quantifiers
examples of input forms
1 exists(gt= i X pIX)) where i is an integer
2 exists(i X pIX)) where i is an integer
3 exists(i j X pIX)) where i j are integers and iltj
4 exists(il v i2 X pIX)) where is are integers
examples of output forms of this step
1 exists(X pIX) amp number(X gt= i) )
2 exists(X pIX) amp number(X i) ) 3 exists(X pIX) amp number(X ij) ) 4 exists(X pIX) amp number(X il v i2) )
II Distinctive quantifiers
27
example or input Corm
exists([XYL p(X Y))
example or output Corm or this step
exists(X exists(Y p(XY)) )
conv(P lt=gt Q PI lt=gt QI) - 1
conv(P PI) conv(Q QI)
conv(al1(X P) all(X PI)) -
conv(P PI)
conv(exists(HIT] P) R ) - conv(P PI) convert distinctive quantifier
convtdis(exists([HIT]PI) R)
conv( exists(I X P) exists(X PIamp number(X I) )) -
conv(P PI) convert numerical quantifier
conv(exists(X P) exists(X PI)) - 1
conv(P Pl)
conv(P amp Q PI amp QI) - 1
conv(P PI) conv(Q QI)
conv(P v Q PI v QI) - t conv(P PI) conv(Q QI)
convC(P) -(PI)) -
conv(P PI)
conv(P Pl
convtdis(existsl[XL P) exists(X P)) - atomic(X) convtdis(exists[XIYj Pl exists(X R)) shy
convtdis(exists(Y P) R)
Step 4 Rewriting compound predicates andor compound selectors
Outputs are smiple predicates andor simple selectors
rewrite(P lt=gt Q PI lt=gt QI) - t rewrite(P PI) rewrite(Q QI)
rewrite(all(X Pl all(X PI)) - 1 rewrite(P PI)
rewriteexists(X P) exists(X PI)) - I rewriteP PI)
rewrite(P amp Q PI amp QI) - rewrite(P P 1) rewrite( Q Q 1
rewrite(P v Q PI v QI) - 1
rewrite(P PI) rewrite(Q QI)
rewriteC(P) -(PI)) - I
28
rewrite(P PI) rewrite(F(A B) R) -
rewrite(A AI) rewrite(B BI) re(F(AI BI) R)
rewrite(F(A) R) -
rewrite(A AI) re(F(AI) H)
rewrite(F(A B C) R) -
rewrite(A AI) rewrite(B BI) rewrite(C CI) re(F(AI BI CI) R)
rewrite(F(A B C D) R) -
rewrite(A AI) rewrite(B Btl rewrite(C CI) rewrite(D DI) rc(F(AI BI CI Dl) H)
rewrite(PP)
re(F(A B v el (RI v R2) -
re(F(A Bl RIl re(F(A C) R2) reF(A B amp cl (RI amp R2)) -
re(F(A B) RI) re(F(A e) R2) re(F(A amp B C) (Rl amp R2)) -
re(F(A e) R 1) re(F(B C) R 2) re(F( v B el (R I v R2)) -
re(F(A el R I) reFB el R2) re(F(A amp Bl (R I amp R2)) -
re(F(A RI) re(F(BJH2) re(F(A v B) (R 1 v R2)) -
re(F(A) RI) re(F(B) R2)
re(F(A vB c Dl (RI v R2) -
re(F(A C D) RI) re(F(B C D) R2) re(F(A amp B C D) (RI amp R2)) -
re(F(A C D) Rll re(F(B C D) R2) re(F(A B v C D) (HI v R2)) -
re(F(A B D) RI) re(F(A C D) R2) re(F(A B amp C D) (HI amp R2)) -
re(F(A B D) RI) re(F(A C D) R2) re(F(A B C v D) (RI v R2)) -
re(F(A B C) R I) reF(A B D) R2) re(F(A B C amp D) (RI amp R2)) -
29
re(F(A B C) RI) re(F(A B D) RZ)
re(F(A v B e D E) (R I v R2)) -
re(F(A e D E) R I) re(F(B e D El R2) re(F(A amp B e D E) (RI amp RZ)) -
re(F(A e D El R 1) re(F(B e D E) R2) re(F(A B v e D E) (R I v R2)) -
re(F(A B D E) RI) re(F(A e D E) R2)
re(F(A B amp e D E) (RI amp R2)) -
re(F(A B D El RI) re(F(A e D E) RZ) re(F(A B e v D E) (R I v R2)) -
re(F(A B e El R 1) re(F(A B D E) RZ) re(F(A B e amp D E) (RI amp RZ)) -
re(F(A B e E) R I) re(F(A B D E) RZ)
re(F(A B e D vEl (RI v RZ)) - l
rc(F(A B C D) RI) re(F(A n e El RZ) re(F(A B e D amp El (RI amp RZ)) - ~
re(F(A B e D) RI) re(F(A B e El RZ)
re((A = B) (A = B)l-
re((A = Bl (A = 8)) -
retIA gt= BI (A gt= B)) -
re((A lt= B) (A lt= B)) -
re((A gt B) (A gt B))-
re((A lt Bl (A lt Bl)- re(A A)
Step) Bringing n(gation inwards
Degin(-(P) PI) - neg(P Pl)
negin(P lt=gt Q PI lt=gt Ql) - ~
negin(P PI) negiD(Q QI)
Degin(aU(X P) all(X PI)) - Degin(P PI) negin(exists(X P) exists(X PI))- negin(P PI) negin(P amp Q PI amp Ql) - Degin(P PI) negin(Q Ql)
Degin(P v Q PI v QI) - Degin(P PI) negin(Q QI) negin(P Pl
neg(-(P) PI) - negin(P PI)
neg(all(X P) exists(X PI)) - neg(P PI)
30
neg(exists(X P) all(X PI)) - neg(P PI)
neg(P amp Q PI v QI) - neg(P PI) neg(Q Ql)
neg(P v Q PI amp QI) - neg(P PI) neg(Q QI)
neg(P -(PH
Step 6 Dropping existnetial quanti6ers
dropexist(P lt=gt Q PI lt=gt QI Elerns) - dropexist(P PI Elerns) dropexist(Q QI Elerns)
dropexist(alJ(X P) all(XPI) Elerns)
dropexist(P PI [XIElernsJ)
dropexist(exists(X P amp nurnber(X Yraquo P2 Elerns) -
genfun(skn Newg) Fun = [NewgIElerns]
subst(FuD X P amp Dumber(X Y) PI)
dropexist(Pl P2 Elerns)
dropexist(exists(X P) PZ Elerns) -
genfun(skrn Newf) Fun = [NewfIElernsJ
subst(Fun X p PI)
dropex ist(P 1 P~ Elerns)
dropexist(P v Q PI v QI Elerns) - ~
dropexist(P PI Elerns) dropexist(Q Ql Elerns)
dropexist(P amp Q PI amp QI Elerns) - 1
dropexist(P Pl Elerns) dropexist(Q QI Elerns)
dropexist(P P _)
gen fun(R oot Newn arne) shy
getnurn(Root Nurn)
narne(Root Rootlist)
append(Rootlist[Nurnj Narnelist)
concat(Narnelist Newnarne)
getnurn(Root Nurn) shy
retract(currentnurn(Root Nurn 1 raquo
Nurn is Nurni + 1
asserta(currentnurn(Root Nurn))
getnurn(Root 1) - asserta(currentnurn(Root 1))
subst(New Old Val Val) - var(Val)
subst(New Old Old New) - 1 substNew Old Val Val) - atornic(Val)
31
subst(New Old Val Newval) shy
runctor(Val F N)
CUDctor(Newval F N)
subst_args(N New Old Val Newval)
subst_args(O J J - J J
subst_args(N New Old Val NewVal) shy
arg(N Val OldArg)
arg(N NewVal NewArg)
subst(New Old OldArg NewArg)
NI is N - I
subst_args(Nl New Old Val NewVal)
append([J L L) -
append([XILl] L2 [XIL3]) - append(Ll L2 L3)
Step - Dropping universal quantifiers
dropall(P lt=gt Q PI lt=gt QI)-
dropall(P PI) dropall(Q QI)
dropall(all(X P) PI) - ~ dropall(P PI)
dropall(P amp Q PI amp QI) -
dropall(P PI) dropall(Q QI)
dropall(P v Q PI v QI) -
dropall(P PI) dropall(Q QI)
dropall(P P)
Step 8 Distributing conjunctions over disjunctions
distrib(P lt=gt Q PI lt=gt Ql) - t distrib(P PI) distrib(Q QI)
distrib(P v Q R) -
distrib(P PI) distrib(Q QI)
distributing(PI v QI R)
distrib(P it Q PI it QI) -
distrib(P PI) distrib( Q QI)
distrib(P P)
distributing((P amp Q) v R PI amp QI) -
distrib(P v R PI) distrib(Q v R Ql)
32
distributing(P v (Q amp R) PI amp Ql) -
distrib(P v Q PI) distrib(P v R Ql)
distributing(P P)
Step 9 Packing each conjunction into clauses
c1ausify(P amp Q CI C2) -
clausiCy(P CI C3) c1ausify(Q C3 C2)
cbusiCy(P [d(A B)ICs] Cs) shy
inclause(P A [j B [I) 1
c1ausiry( C C)
inclause(P v Q A AI B B1) -
inc1ause(P A2 AI B2 Bl)
inclause(Q A A2 B B2)
inclausenp) A A B1 B) -
notin(P A) putin(P B B1)
inclause(P AI A B B) shy
notin(P Bl putin(P A AI)
notin(X [XU) - fail
notin(X [JLj) - notin(X L)
notin(X 1])
putin(X II [X]) - 1
putin(X [XILJ L) -
putin(X [YILJ [YILl]) - putin(X L Ll)
Step 1Oa Printing clauses
printcl([]) - nl nl
printcl(c1(AB)ICsj) - printcl(A Bl nl printcl(Cs)
printcl(L II) - printdis(IL) prinr)middot
printclHl L) - prin(contradiction(() printconl(rL)
print()) - ) printconj(rL) prinr )
printcl(Ll L2) shy
printdis(ILl) print( - ) printconj(rL2) prin()
printdis(S[Lj) - printcbar(SL)
33
printdis(S[LILs]) - printchu(SL) prin( v) printdis(SLs)
printconl(S[LI) - printchar(SL)
printconl(S[LILs]) - printchar(SL) prin( ) printconl(SLs)
printconj(S[L]) - tab(3) printchar(SL)
prin tconj( S [L IL sl) shy
tab(3) printchar(SL) print( ) printconj(SLs)
printchar(SP) shy
atomic(P)
name(P L)
L = [IT]
concat([XIT NewP)
prin(~ewP)
printchar(SP) shy
atomic(P)
prin(P)
printchar(SA lt= gt B) -
prin((l clausify(A AI [j) pl(eAl) prin())
print lt=gt )
prin(() cbusify(B Bl [I) pJ(eBl) prine))middot
printchar(rnumber(X N)) shy
prin(num() printchar(rx) prin( )
printchar(rN) prinC))
printchar(rF(A B)) shy
seJec(F(A B))
prinCsel() printchar(rA)
prin( F ) printchar(rB) prinC))
printchar(SF(A B)) shy
( selec(F(A B)) F = infix )
printchar(SA) prin( F ) printchar(SB)
printchar(SF(A)) shy
(F= prefix gt= F= prefix lt= F= prefixgt F= prefix lt )
prin(F ) printcbar(SA)
printchar(SP) shy
functor(P F MaxN)
prin(F ()
Nl is MaxN - 1
putout(S N 1 P MaxN)
34
prin())
putout(S 0 P MaxN) -
arg(~laxN P Argu)
prin tchar(SArgu)
putout(S N p MaxN) shy
Nt is MaxN - N arg(NI P Argu)
printcbar(SArgu )
prin( )
N2 is N - 1
putout(S N2 P MaxN)
selec(FA B)) shy
( F= infix = F= infix f= F= infix gt=
F= infix gt F= infix lt= F= infix lt )
35
----------------------------------Program Name APClS - Part 2 Inference Mechanism ---------------------------------- a(X) shy
steps(X X9)
(( X9 =[] nl
print( yes it is always true) )
( X9 =[cI(IJ[])] nl
print( no it is always false) )
( nl nl printel(X9) Step 1Oa
tell(temp_file) printel(X9) e1ose(temp_file) consult(temp_6Ie) ))
q(X) shy
asserta( in pt(X))
steps(X X9)
(( X9 = [] print(middot~H~~middot~t~)
print(THE AiSWER IS YES)
print( ilgIQlQl(~) )
( X9 = [e1([j [j)] Pr1nt ( OJ fi(i I~ iii Ij)middot(i)(i) fiyenQ)riiio(i)(ij)(i)fj)fiyen1li1il1li1il)__ gtw~ __~_~ _~~_ ~_-=~
print(THE ANSWER IS NO ) print() )
( teI1(temp_6Ie)
prques(X9) Step 1Ob
close(temp_file)
nl print(Let me think about it) nl
consult(temp_6Ie) ))
retrac t( in pt(X))
Step lOb Printing question
prques(lcl(A 8)1) - prin(goo(() pl(qA 8) print()))
prques([c1(A 8HCs]) - prin(goo(() pl(qA 8) print() pl(q Cs)
pl(e [c1(A 8)]) - pl(eA 8)
pl(q [c1(A 8)]) - pl(qA 8) print()))
pl(S [e1(A B)ICs]) - pl(SA B) prin( ) pl(S Cs)
38
pl(q [j L) - prin(c1ause(contradiction(() pcont(qL) prin())_))
pl(S [I L)- prin(so2(contradidion(() pcont(SL) print))))middot
pl(S [L] []) - prin(so2() pcbar(SL) prin())
pl(S L [J)- prinsol() plett(SL) print))
pl(S [L] LI) - prin(condi(() pchar(cL)
prin(() pcont(S Ll) prine))))
pl(S L Ll)- prin(c1ause() plert(cL)
prin(() pcont(S Ll) prine)))
plert(S[LJ) - pchar(SL)
plert(SjLILsj) - pcbar(SL) print v) pleCt(SLs)
pcont(S[L]) - pchar(SL)
pcont(S[LILsj) - pcbar(SL) prinr ) pcont(SLs)
pcbar(SP) shy
atomic(P)
name(PL)
( L = [IT] L = [5 k miT] L = [5 k niT] )
concat[XITj NewP)
prin(0JewP)
pchar(SP) shy
atomic(P)
prin(P) pchar(SA lt=gt B) -
prin(() dausify(A AI []) pl(eAI) prin())
prinr lt=gt ) prin(() dausify(B BI ]) pl(eB) print))
pchar(Snumber(X N)) shy
prin(num() pchar(SX) prin()
pchar(SN) prinr))
pcbar(SM N) - prin(M N)
pcbar(cF(A B)) shy
selec(F(A Braquo
pcbar(cA)
prine F ) pchar(cB) pchar(SF(A B)) shy
selec(F(A B))
prin(sel() pchar(SA)
print F ) pchar(SB) print)) I
31
pc har(SF(A)) shy
( F= prefix gt= F= prefix lt= F= prefixgt F= prefix lt )
prin(F ) pchar(SA)
pchar(SP)shy
runctor(P F MaxN)
prin(F ()
011 is MaxN - 1 pout(SNl P MaxN)
print) )
pout(S 0 P M3xN) - 1
arg(~bxN P Argu)
pchlr(SArgu )
pout(S N P MaxN shy
Nl is MaxN - N
arg(Nl P Argu)
pchar(SArgu
prin( )
N2 is N - 1
pout(S N2 P ~13xN)
Comparing numbers in numerical quantifiers
num(XN) shy
number(X I)
cnum(N 1) ~
cnumlaquo=01 lt=I- N gt=I
cnumlaquo=J lt I) - N gt=1-1
cnumlaquo=NIJ) - N gt=J 1
cnumlaquo=N J)- integer(I) N gt=I~
cnum(gt=N gt=1) - N lt=1
cnum(gt=N gt I) - N lt=1+ 1 cnum(gt=NIJ) - N lt=1
cnum(gt=N lt=1)- N lt=1
cnum(gt=N lt I) - N lt=1 L cnum(gt=N 1)- integer(I) N lt=1
cnum( lt N lt 1)- N gt=1 L
38
cnum( lt N lt=1) - N gt I cnum( lt NLJ) - N gt J
cnum( lt N 1)- integer(I) N gt 1
cnum(gt N gt I) - N lt=1 cnumlgt i gt=1) - N lt I
cnum(gt N lt=1) - N lt=0
cnum(gt N lt I) - N lt=0
cnum(gt iIJ) - N lt I cnum(gt N 1)- integer(I) N lt I
cnum(~LN lt=1) - M=I N gt= I l
cnum(~LN lt I) - M=l N gt= I-I
cnum(~LNLJ) - M lt =1 N gt = J
cnum(~1N 1)- integer(I) M lt= I N gt= I
cnum(- N) - integer(N)
Comparing selectors
sel(X = Y) shyX= Y
sel(X I=Y) shy(X I=Y X lt Y Xgt Y)
sel(X gt Y) shyXgt Y
sel(X lt Y) shyXlt Y
selX gt=Y) shy(X gt=Y X= Y Xgt Y)
se(X lt=Y) shy
(X lt=Y
X= Y
X lt Y)
csel(infix = infix =)
39
csel(infix = infix = csel(infix = infix gt)
csel(infix = infix lt) csel(infix gt infix gt) cseJ(infix lt infix lt) csel(infix gt= infix gt=) csel(infix gt= infix gt csel(infix gt= infix =)
csellinfix lt= infix lt=) csel(infix lt= infix lt) csel(infix lt= infix =)
Finding solutions
sol(X v Y) -
(( notetra(X) eon(X) ( sol(Y) )
( c1ause(P v Q R) not(cketra(P v Q))
dis(P v Q X v Y R) ~ )
( A lt=gt B equival(A lt=gt B X v Y) ~ I) sol(X) - ~ notetra(X) eon(X)
so~(X) - notetra(X)
( con (X)
( clause(P v Q R) not(ekctra(P v Q)) dis(P v Q X R) I)
cketra(P v Q) -
eketra(P) eketra(Q) eketra(F(I J)) shy
selec(F(I J))
c1ause(contradiction(sel(F(IJ))) _I
eketra(number(W I)) -
clause(cootradietion(num(Wl)) - eketr(P) shy
clause(contradiction(P) - 1
notctra(P) shy
not( e lause( con tradiction(P) _))
40
Searching (or disjunctions
dis(P v Q X v Y R) - dis(P X v Y R)
dis(Q X v Y R) con(R)
dis(P v Q X R) -
dis(P X R) dis(Q X R) con(R
dis(P X v Y R) - clause(contradicton(Pl J 1
dis(F(I J) sel(G(I J)) v Y R) - csel(G Fl dis(number(WI) num(W N v Y R) - cnum(N I)
dis(P P v Y R) -
dis(P X v Y R) - dis(P Y R)
dis(F(I J) seJ(G(IJ)) R) - csel(G F)
dis(number(WI) num(WN) R) - cnum(N I) dis(P P R) - 1
dis(FJ J X R) shy
( ckctra(F(IJ) cbeckeq(seJ(F(IJ))) )
dis(number(W Il X R) - ( ckctra(number(WI)) cbeckeq(num(WI)) )
dis(P X R) shy( ckctra(P) cbeckeq(P) ) 1
cbeckeq(P) shy
(( A lt=gt so2(contradiction(P))
bagof(A A [jj) ) ( so2(contradiction(P)) lt=gt B
bagof(B B Uj) ))
ckeq(A) shy
( so2(A) lt=gt B B lt=gt so2(A) ) bagof(B B UJ)
con((P Q)) -
clause(P R) con(R) con(Q) con(true) -
con(contradiction(P)) - clause(contradiction(P) J
con(cause(X Y)) - cause(X Y)
con(sel(X)) - sel(X)
con(num(X Y)) - num(X Y) con(P)- (( dause(P R) (con(R) ckeq(R)))
colJectin(P) )
collectin(P) shy
bagof(S (c1ause(P S) S = true) [L LIJ )
mkcon(L Ll L)
bagor(l (L2 ) UJ) L
mkcon((A AI) (B B1) (sol(A v B) e D)) -
mkcon(A B1 e) mkcon(A1 (B Bl) D)
mkcon(A (B B1) (sol(A v B) e)) -
mkcon(A Bl e)
mkcon((A AI) B (sol(A v B) e)) middot1
mkcon(Al B e)
mkcon(A B sol(A vB))
Searching ror equivalences
equival(A lt=gt B X v Y) - 1 ( equival(A lt=gt B X) equival(A lt=gt B Y) )
equival(s02(A) lt=gt 502(B) A) - clause(B _I equival(s02(B) lt=gt 502(A) A) c1ause(B _I
Top level or inrerence mechanism
goo((s02(whatnum) P)) -
getatm(P Xl
bagor(number(X Y) ( P so2(number(X Y)) ) A )
count1(A 00 L R) nl
bagor(X P B )
count2(B L R Ll Rl) nJ print()
(( LI = 0 Rl = 0 print(THE ANSWER IS ) nl
(( Ll = Rl prin(-Jumber or ) prn(P) print(is Ll) )
( Rlgt20000 prin(Number or I prn(P) print(is LI or more) )
42
( prin(Number of ) pfn(P) print( is from Ll to Rl) )) )
( print(THE ANSWER IS NO I )) print()
goo(X) shy
(( bagof(X X L) L = [I nl print()
print(THE ANSWER IS YES) nl wout(L) print() )
( equiv(X L) nl print()
print(THE ANSWER IS YES) nl wout(L) print(-) )
( c1ause(inpt(A ==gt B) _I ( impli(A B Z) impli(B A Z) ) print(l~Hl)
printTHE ANSWER IS YES) nl print(Z) print(Hj~(fH~) ))
goo(X) print( Hg)
print(THE ANSWER IS NO ) print( lH~lH~gg9l9lmiddotmiddot~Q(gmiddot)
00 Semhing for implications in equiV3lent relations
impli( B Z) shyt-ell( z1) prin(templ() pchn(S A lt=gt B) print()) close ( zl) consult(zl) templ(Z)
unload zl Z
Searching for equivalence
equiv (X L)
(( X lt=gt Y
equ(Y YI)t bagof(Y Yl L) L = [j )
(Y lt=gt X equ(Y YI) bagof(Y Yl L) L = [J )
( X = F(New)
clause(~ew T) makeup(T Tl)
(( Tl lt=gt B
equ(B Bl) bagof(Bl Bl M) M = [j L=[Newl )
(A lt=gt TI
equ(A AI) bagof(Al AI M) M = 1] L=INewj )) ))
makeup((A B) (AI Bl)) -
makeup(A A1) makeup(B BI)
makeup(A so2(A))
equ((A B) (AI BI)) -
equ(A AI) equ(B Bl)
equ(sol(X v Y) sol(XI v Yl)) -
equ(X XI) equ(Y YI)
equ(so2(X) so2(XI)) -
equ(X XI)
equ(contradiction(X) clJuse(contradiction(X) X) ) -
equ(X X)
Counting numbers
getatm((A B) X) -
( getatm(A X) getatm(B X) )
getatm(so2(F(X)) X) -
getatm(so2(X) X) - atom(X)
countl([J L R L R) -
countl([number(X Y)IT] L R L2 R2) shy
(( Y = (gt=~) LI is L + N Rl is R + 20001 l )
( Y = (gt N) LI is L+ N+ 1 RI is R + 20002 )
(Y == laquo=~) LI is L + 1 Rl is R + N )
(Y = laquo N) LI is L + 1 RI is R+N-I)
(Y == IJ LI is L + I Rl is R + J ) ( Y == N L1 is L + N RI is R + N ))
count1(T LI R 1 L2 R2)
count2(fJ L R L R) - 1
count2([XITJ L R L2 R2) shy
name(X Xl)
(( Xl = sknj LI is L Rl is R )
44
( Xl = Iskmj L1 is L + 1 RI is R + ZOOO1) ( LI is L + I RI is R + I ))
count2(T LI RI L2 R2)
pfn((A B)) - pfn(A) prn(B)
pCn(so2(F(X))) - prin(F )
prn(so2(X)) - atom(X) prin(X ) prn (so2(X))
Printing result
wout([XlJ - prt(X) nl woutf[xIY]) - prt(X) nl nl wout(Y)
prt(e(A B)) -
prt(A) prinr 8 ) prt(ltE) prt(eA) - prt(A)
prt(c(A EJ) - prin() prt(A) prine ) prt(B) prin(T)
prt(c A) - prt(A) prt((A E)) - ~
prt(A) nl prt(E) prt(sol(X v Y)) - ~
prt(X) prinC v) prt(Y) prt(A lt=gt B) -
prt(e A) prinC lt=gt ) prt(e B) prt(sol(X)) - prt(X)
prt(so2(X)) - prt(X
prt(c1ause(X Y)) - prt(X)
prt(contradiction(X)) - prin(contradiction() prt(cX) prinr))middot prt(num(XY)) - prin(number(X Y)) prt(sel(X)) - prin(X) prt(X v Y) - prt(X) prin( v) prt(Y) prt(X) prin(X)
Handling conditional queries
condi((Y Xl) shy
assertcon(X) Y
45
retractcon(X)
condi((B A))
retractcon(A) fail
assertcon((A B)) 1
assertcon(A) assertcon(B)
assertcon(A) asserta(A)
retrac teon ((A B)) 1
retracteon(A) retractcon (B)
retraetcon(A) - retract(A)
BIBLIOGRAPHIC DATA SHEET
Report No UIUCDS-F-84-928
3 Recipients Accession No
4 T ide and Subt ltle
An Annotated Predicate Calculus Inference System (APCIS)
S Report Date
November 1984 6
7 Author(s)
Kah-Eng Pua 8 Performing Organization Rept
No
9 Performing Organization Name and Address
Department of Computer Science University of Illinois Urbana IL
10 ProjectTaskWork Unit No
11 Contract Grant No NSF DCR 84-06081 ONR N00014-82-K-0186
12 Sponsoring Organization Name and Address
National Science Foundation Washington DC
13 Type of Report amp Period Covered
14
15 Supplementary Notes
16 Abstracts
This paper describes a deductive inference system called APCIS (Annotated Predicate Calculus Inference System) APCIS is able to carry out inferences from expressions involving numerical quantifiers selectors disjunctions of non-negated terms negated terms disjunctions of negated terms equivalences and exceptions It is also able to count the numbers of occurrence of a given simple term or a conjunction of terms The design of contradiction and the treatment of the disjunction of non-negated terms allow APCIS to accept Horn clauses as well as non-Horn clauses and to carry out inferences from them This feature makes APCIS more general than Prolog
17 Key lords and Document Analysis 170 Descriptors
APC (Annotated Predicate Calculus) APCIS (Annotated Predicate Calculus Inference System) Horn Clause Numerical Quantifier Prolog Selector
17b IdentifiersOpen-Ended Terms
17c COSATI FieldGroup
18 Availability Statement 19 Security Class (This
Re~f~~IA~SIF IFf)
21 ~o of Pages
49 211 ecurity Class (This
PageUNCLASSIFIED
22 Price
FOA NTIS n (10middot70 usco-oc 40329-
23
where Xs are APC expressions
2 Notations Used in APCIS
Below is a summary or notations used in APCIS
a Logical operators
amp
v
==gt
lt=gt
-
negation
conjunction
disjunction
implication
equivalence
exception
b Binary relation symbols in selectors
-
=
gt=
lt=
gt
lt
equal
not equal
greater or equal
smaller or equ al
greater
smaller
c Relational operators in numerical quantifiers
lt less than
lt= less than or equal
gt greater than
gt= greater than or equal
d BinlTY operator in numerical quantifier
range
e Universal quantifier
all(X p(X))
f Existential quantifier
exists(X p(X))
g Numerical quantifier
exists(I X p(X))
where p(X) is a formula
where X is a variable or a Jist of variables or the
form [HI~rj and p(X) a formula
where I repersents expression involving integer(s)
and operator(s) in c or d above and p(X) a formula
25
Appendix B
APCIS Program Listings
------------------------------- Program Name APCIS - Part 1 APC Translator
-------------------------------
op(3OO fx -)1
op(500 xfy amp)
oPt 500 xfy v)
op(600 xfx )
op(700 fx [gt= lt= gt lt ]) op(400 xfy [= gt= lt= gt lt ])1 op(900 xfy gt lt=gt -])1
steps(X Xg) shy
numbervars(X 1 J Step 1 change variables to iis
rmimp(X X) Step 2 conv(X X3) Step 3
rewrite(X3 X4) Step 4
negin(X4 X5) Step 5
dropexist(X5 X6 1]) Step 6
dropall(X6 X7) Step 7
distrib(X7 X8) Step 8 clausiCy(X8 X9 [J) Step 9
ta(X) shysteps(X Xg)
(( Xg = II nl
print( yes it is always true) )
( nl nl printcl(X9))) Step 10a
tq(X) shy
steps(X Xg)
prques(Xg)
28
Step 2 Removing implic3tions amp Transforming exceptions and equiv3lences
rmimpl( P - Q (PI lt=gt (QI) ) amp ((PI) lt=gt QI) ) -
rmimpl(P PI) rmimpl(Q QI)
rmimplnp) lt=gt Q (PI lt=gt -(QI)) amp nPI) lt=gt QI) ) - 1
rmimpl(P PI) rmimpJ(Q QI)
rmimpJ(P lt-gt -(Q) (PI lt=gt -(QI)) amp nPI) lt=gt QI) ) -
rmimpl(P PI) rmimpl(Q QI)
rmimpl( P lt=gt Q PI lt=gt QI ) - I
rmimpl(P PI) rmimpl(Q QI)
rmimpl( P ==gt Q -(PI) v QI ) - I
rmimpl(P PI) rmimpl(Q QI)
rmimpl( all(X P) aI(X PI) ) - 1
rmimpl(P PI)
rmimpl( exists(X P) exists(X PI) ) -
rmimpl(P PI)
rmimpl( exists(I X P) exists(I X PI) ) -
rmimpl(P PI)
rmimpl( P amp Q PI amp Ql ) -
rmimpl(P PI) rmimpl(Q Ql)
rmimpl( P v Q PI v QI ) -
rmimpl(P PI) rmimpl(Q QI)
rmimpl( -(p) -(PI) ) - I
rmimpl(p PI)
rmimpl( P P )
St~p 3 Converting numerical amp distinctive quantifiers
L Numerical quantifiers
examples of input forms
1 exists(gt= i X pIX)) where i is an integer
2 exists(i X pIX)) where i is an integer
3 exists(i j X pIX)) where i j are integers and iltj
4 exists(il v i2 X pIX)) where is are integers
examples of output forms of this step
1 exists(X pIX) amp number(X gt= i) )
2 exists(X pIX) amp number(X i) ) 3 exists(X pIX) amp number(X ij) ) 4 exists(X pIX) amp number(X il v i2) )
II Distinctive quantifiers
27
example or input Corm
exists([XYL p(X Y))
example or output Corm or this step
exists(X exists(Y p(XY)) )
conv(P lt=gt Q PI lt=gt QI) - 1
conv(P PI) conv(Q QI)
conv(al1(X P) all(X PI)) -
conv(P PI)
conv(exists(HIT] P) R ) - conv(P PI) convert distinctive quantifier
convtdis(exists([HIT]PI) R)
conv( exists(I X P) exists(X PIamp number(X I) )) -
conv(P PI) convert numerical quantifier
conv(exists(X P) exists(X PI)) - 1
conv(P Pl)
conv(P amp Q PI amp QI) - 1
conv(P PI) conv(Q QI)
conv(P v Q PI v QI) - t conv(P PI) conv(Q QI)
convC(P) -(PI)) -
conv(P PI)
conv(P Pl
convtdis(existsl[XL P) exists(X P)) - atomic(X) convtdis(exists[XIYj Pl exists(X R)) shy
convtdis(exists(Y P) R)
Step 4 Rewriting compound predicates andor compound selectors
Outputs are smiple predicates andor simple selectors
rewrite(P lt=gt Q PI lt=gt QI) - t rewrite(P PI) rewrite(Q QI)
rewrite(all(X Pl all(X PI)) - 1 rewrite(P PI)
rewriteexists(X P) exists(X PI)) - I rewriteP PI)
rewrite(P amp Q PI amp QI) - rewrite(P P 1) rewrite( Q Q 1
rewrite(P v Q PI v QI) - 1
rewrite(P PI) rewrite(Q QI)
rewriteC(P) -(PI)) - I
28
rewrite(P PI) rewrite(F(A B) R) -
rewrite(A AI) rewrite(B BI) re(F(AI BI) R)
rewrite(F(A) R) -
rewrite(A AI) re(F(AI) H)
rewrite(F(A B C) R) -
rewrite(A AI) rewrite(B BI) rewrite(C CI) re(F(AI BI CI) R)
rewrite(F(A B C D) R) -
rewrite(A AI) rewrite(B Btl rewrite(C CI) rewrite(D DI) rc(F(AI BI CI Dl) H)
rewrite(PP)
re(F(A B v el (RI v R2) -
re(F(A Bl RIl re(F(A C) R2) reF(A B amp cl (RI amp R2)) -
re(F(A B) RI) re(F(A e) R2) re(F(A amp B C) (Rl amp R2)) -
re(F(A e) R 1) re(F(B C) R 2) re(F( v B el (R I v R2)) -
re(F(A el R I) reFB el R2) re(F(A amp Bl (R I amp R2)) -
re(F(A RI) re(F(BJH2) re(F(A v B) (R 1 v R2)) -
re(F(A) RI) re(F(B) R2)
re(F(A vB c Dl (RI v R2) -
re(F(A C D) RI) re(F(B C D) R2) re(F(A amp B C D) (RI amp R2)) -
re(F(A C D) Rll re(F(B C D) R2) re(F(A B v C D) (HI v R2)) -
re(F(A B D) RI) re(F(A C D) R2) re(F(A B amp C D) (HI amp R2)) -
re(F(A B D) RI) re(F(A C D) R2) re(F(A B C v D) (RI v R2)) -
re(F(A B C) R I) reF(A B D) R2) re(F(A B C amp D) (RI amp R2)) -
29
re(F(A B C) RI) re(F(A B D) RZ)
re(F(A v B e D E) (R I v R2)) -
re(F(A e D E) R I) re(F(B e D El R2) re(F(A amp B e D E) (RI amp RZ)) -
re(F(A e D El R 1) re(F(B e D E) R2) re(F(A B v e D E) (R I v R2)) -
re(F(A B D E) RI) re(F(A e D E) R2)
re(F(A B amp e D E) (RI amp R2)) -
re(F(A B D El RI) re(F(A e D E) RZ) re(F(A B e v D E) (R I v R2)) -
re(F(A B e El R 1) re(F(A B D E) RZ) re(F(A B e amp D E) (RI amp RZ)) -
re(F(A B e E) R I) re(F(A B D E) RZ)
re(F(A B e D vEl (RI v RZ)) - l
rc(F(A B C D) RI) re(F(A n e El RZ) re(F(A B e D amp El (RI amp RZ)) - ~
re(F(A B e D) RI) re(F(A B e El RZ)
re((A = B) (A = B)l-
re((A = Bl (A = 8)) -
retIA gt= BI (A gt= B)) -
re((A lt= B) (A lt= B)) -
re((A gt B) (A gt B))-
re((A lt Bl (A lt Bl)- re(A A)
Step) Bringing n(gation inwards
Degin(-(P) PI) - neg(P Pl)
negin(P lt=gt Q PI lt=gt Ql) - ~
negin(P PI) negiD(Q QI)
Degin(aU(X P) all(X PI)) - Degin(P PI) negin(exists(X P) exists(X PI))- negin(P PI) negin(P amp Q PI amp Ql) - Degin(P PI) negin(Q Ql)
Degin(P v Q PI v QI) - Degin(P PI) negin(Q QI) negin(P Pl
neg(-(P) PI) - negin(P PI)
neg(all(X P) exists(X PI)) - neg(P PI)
30
neg(exists(X P) all(X PI)) - neg(P PI)
neg(P amp Q PI v QI) - neg(P PI) neg(Q Ql)
neg(P v Q PI amp QI) - neg(P PI) neg(Q QI)
neg(P -(PH
Step 6 Dropping existnetial quanti6ers
dropexist(P lt=gt Q PI lt=gt QI Elerns) - dropexist(P PI Elerns) dropexist(Q QI Elerns)
dropexist(alJ(X P) all(XPI) Elerns)
dropexist(P PI [XIElernsJ)
dropexist(exists(X P amp nurnber(X Yraquo P2 Elerns) -
genfun(skn Newg) Fun = [NewgIElerns]
subst(FuD X P amp Dumber(X Y) PI)
dropexist(Pl P2 Elerns)
dropexist(exists(X P) PZ Elerns) -
genfun(skrn Newf) Fun = [NewfIElernsJ
subst(Fun X p PI)
dropex ist(P 1 P~ Elerns)
dropexist(P v Q PI v QI Elerns) - ~
dropexist(P PI Elerns) dropexist(Q Ql Elerns)
dropexist(P amp Q PI amp QI Elerns) - 1
dropexist(P Pl Elerns) dropexist(Q QI Elerns)
dropexist(P P _)
gen fun(R oot Newn arne) shy
getnurn(Root Nurn)
narne(Root Rootlist)
append(Rootlist[Nurnj Narnelist)
concat(Narnelist Newnarne)
getnurn(Root Nurn) shy
retract(currentnurn(Root Nurn 1 raquo
Nurn is Nurni + 1
asserta(currentnurn(Root Nurn))
getnurn(Root 1) - asserta(currentnurn(Root 1))
subst(New Old Val Val) - var(Val)
subst(New Old Old New) - 1 substNew Old Val Val) - atornic(Val)
31
subst(New Old Val Newval) shy
runctor(Val F N)
CUDctor(Newval F N)
subst_args(N New Old Val Newval)
subst_args(O J J - J J
subst_args(N New Old Val NewVal) shy
arg(N Val OldArg)
arg(N NewVal NewArg)
subst(New Old OldArg NewArg)
NI is N - I
subst_args(Nl New Old Val NewVal)
append([J L L) -
append([XILl] L2 [XIL3]) - append(Ll L2 L3)
Step - Dropping universal quantifiers
dropall(P lt=gt Q PI lt=gt QI)-
dropall(P PI) dropall(Q QI)
dropall(all(X P) PI) - ~ dropall(P PI)
dropall(P amp Q PI amp QI) -
dropall(P PI) dropall(Q QI)
dropall(P v Q PI v QI) -
dropall(P PI) dropall(Q QI)
dropall(P P)
Step 8 Distributing conjunctions over disjunctions
distrib(P lt=gt Q PI lt=gt Ql) - t distrib(P PI) distrib(Q QI)
distrib(P v Q R) -
distrib(P PI) distrib(Q QI)
distributing(PI v QI R)
distrib(P it Q PI it QI) -
distrib(P PI) distrib( Q QI)
distrib(P P)
distributing((P amp Q) v R PI amp QI) -
distrib(P v R PI) distrib(Q v R Ql)
32
distributing(P v (Q amp R) PI amp Ql) -
distrib(P v Q PI) distrib(P v R Ql)
distributing(P P)
Step 9 Packing each conjunction into clauses
c1ausify(P amp Q CI C2) -
clausiCy(P CI C3) c1ausify(Q C3 C2)
cbusiCy(P [d(A B)ICs] Cs) shy
inclause(P A [j B [I) 1
c1ausiry( C C)
inclause(P v Q A AI B B1) -
inc1ause(P A2 AI B2 Bl)
inclause(Q A A2 B B2)
inclausenp) A A B1 B) -
notin(P A) putin(P B B1)
inclause(P AI A B B) shy
notin(P Bl putin(P A AI)
notin(X [XU) - fail
notin(X [JLj) - notin(X L)
notin(X 1])
putin(X II [X]) - 1
putin(X [XILJ L) -
putin(X [YILJ [YILl]) - putin(X L Ll)
Step 1Oa Printing clauses
printcl([]) - nl nl
printcl(c1(AB)ICsj) - printcl(A Bl nl printcl(Cs)
printcl(L II) - printdis(IL) prinr)middot
printclHl L) - prin(contradiction(() printconl(rL)
print()) - ) printconj(rL) prinr )
printcl(Ll L2) shy
printdis(ILl) print( - ) printconj(rL2) prin()
printdis(S[Lj) - printcbar(SL)
33
printdis(S[LILs]) - printchu(SL) prin( v) printdis(SLs)
printconl(S[LI) - printchar(SL)
printconl(S[LILs]) - printchar(SL) prin( ) printconl(SLs)
printconj(S[L]) - tab(3) printchar(SL)
prin tconj( S [L IL sl) shy
tab(3) printchar(SL) print( ) printconj(SLs)
printchar(SP) shy
atomic(P)
name(P L)
L = [IT]
concat([XIT NewP)
prin(~ewP)
printchar(SP) shy
atomic(P)
prin(P)
printchar(SA lt= gt B) -
prin((l clausify(A AI [j) pl(eAl) prin())
print lt=gt )
prin(() cbusify(B Bl [I) pJ(eBl) prine))middot
printchar(rnumber(X N)) shy
prin(num() printchar(rx) prin( )
printchar(rN) prinC))
printchar(rF(A B)) shy
seJec(F(A B))
prinCsel() printchar(rA)
prin( F ) printchar(rB) prinC))
printchar(SF(A B)) shy
( selec(F(A B)) F = infix )
printchar(SA) prin( F ) printchar(SB)
printchar(SF(A)) shy
(F= prefix gt= F= prefix lt= F= prefixgt F= prefix lt )
prin(F ) printcbar(SA)
printchar(SP) shy
functor(P F MaxN)
prin(F ()
Nl is MaxN - 1
putout(S N 1 P MaxN)
34
prin())
putout(S 0 P MaxN) -
arg(~laxN P Argu)
prin tchar(SArgu)
putout(S N p MaxN) shy
Nt is MaxN - N arg(NI P Argu)
printcbar(SArgu )
prin( )
N2 is N - 1
putout(S N2 P MaxN)
selec(FA B)) shy
( F= infix = F= infix f= F= infix gt=
F= infix gt F= infix lt= F= infix lt )
35
----------------------------------Program Name APClS - Part 2 Inference Mechanism ---------------------------------- a(X) shy
steps(X X9)
(( X9 =[] nl
print( yes it is always true) )
( X9 =[cI(IJ[])] nl
print( no it is always false) )
( nl nl printel(X9) Step 1Oa
tell(temp_file) printel(X9) e1ose(temp_file) consult(temp_6Ie) ))
q(X) shy
asserta( in pt(X))
steps(X X9)
(( X9 = [] print(middot~H~~middot~t~)
print(THE AiSWER IS YES)
print( ilgIQlQl(~) )
( X9 = [e1([j [j)] Pr1nt ( OJ fi(i I~ iii Ij)middot(i)(i) fiyenQ)riiio(i)(ij)(i)fj)fiyen1li1il1li1il)__ gtw~ __~_~ _~~_ ~_-=~
print(THE ANSWER IS NO ) print() )
( teI1(temp_6Ie)
prques(X9) Step 1Ob
close(temp_file)
nl print(Let me think about it) nl
consult(temp_6Ie) ))
retrac t( in pt(X))
Step lOb Printing question
prques(lcl(A 8)1) - prin(goo(() pl(qA 8) print()))
prques([c1(A 8HCs]) - prin(goo(() pl(qA 8) print() pl(q Cs)
pl(e [c1(A 8)]) - pl(eA 8)
pl(q [c1(A 8)]) - pl(qA 8) print()))
pl(S [e1(A B)ICs]) - pl(SA B) prin( ) pl(S Cs)
38
pl(q [j L) - prin(c1ause(contradiction(() pcont(qL) prin())_))
pl(S [I L)- prin(so2(contradidion(() pcont(SL) print))))middot
pl(S [L] []) - prin(so2() pcbar(SL) prin())
pl(S L [J)- prinsol() plett(SL) print))
pl(S [L] LI) - prin(condi(() pchar(cL)
prin(() pcont(S Ll) prine))))
pl(S L Ll)- prin(c1ause() plert(cL)
prin(() pcont(S Ll) prine)))
plert(S[LJ) - pchar(SL)
plert(SjLILsj) - pcbar(SL) print v) pleCt(SLs)
pcont(S[L]) - pchar(SL)
pcont(S[LILsj) - pcbar(SL) prinr ) pcont(SLs)
pcbar(SP) shy
atomic(P)
name(PL)
( L = [IT] L = [5 k miT] L = [5 k niT] )
concat[XITj NewP)
prin(0JewP)
pchar(SP) shy
atomic(P)
prin(P) pchar(SA lt=gt B) -
prin(() dausify(A AI []) pl(eAI) prin())
prinr lt=gt ) prin(() dausify(B BI ]) pl(eB) print))
pchar(Snumber(X N)) shy
prin(num() pchar(SX) prin()
pchar(SN) prinr))
pcbar(SM N) - prin(M N)
pcbar(cF(A B)) shy
selec(F(A Braquo
pcbar(cA)
prine F ) pchar(cB) pchar(SF(A B)) shy
selec(F(A B))
prin(sel() pchar(SA)
print F ) pchar(SB) print)) I
31
pc har(SF(A)) shy
( F= prefix gt= F= prefix lt= F= prefixgt F= prefix lt )
prin(F ) pchar(SA)
pchar(SP)shy
runctor(P F MaxN)
prin(F ()
011 is MaxN - 1 pout(SNl P MaxN)
print) )
pout(S 0 P M3xN) - 1
arg(~bxN P Argu)
pchlr(SArgu )
pout(S N P MaxN shy
Nl is MaxN - N
arg(Nl P Argu)
pchar(SArgu
prin( )
N2 is N - 1
pout(S N2 P ~13xN)
Comparing numbers in numerical quantifiers
num(XN) shy
number(X I)
cnum(N 1) ~
cnumlaquo=01 lt=I- N gt=I
cnumlaquo=J lt I) - N gt=1-1
cnumlaquo=NIJ) - N gt=J 1
cnumlaquo=N J)- integer(I) N gt=I~
cnum(gt=N gt=1) - N lt=1
cnum(gt=N gt I) - N lt=1+ 1 cnum(gt=NIJ) - N lt=1
cnum(gt=N lt=1)- N lt=1
cnum(gt=N lt I) - N lt=1 L cnum(gt=N 1)- integer(I) N lt=1
cnum( lt N lt 1)- N gt=1 L
38
cnum( lt N lt=1) - N gt I cnum( lt NLJ) - N gt J
cnum( lt N 1)- integer(I) N gt 1
cnum(gt N gt I) - N lt=1 cnumlgt i gt=1) - N lt I
cnum(gt N lt=1) - N lt=0
cnum(gt N lt I) - N lt=0
cnum(gt iIJ) - N lt I cnum(gt N 1)- integer(I) N lt I
cnum(~LN lt=1) - M=I N gt= I l
cnum(~LN lt I) - M=l N gt= I-I
cnum(~LNLJ) - M lt =1 N gt = J
cnum(~1N 1)- integer(I) M lt= I N gt= I
cnum(- N) - integer(N)
Comparing selectors
sel(X = Y) shyX= Y
sel(X I=Y) shy(X I=Y X lt Y Xgt Y)
sel(X gt Y) shyXgt Y
sel(X lt Y) shyXlt Y
selX gt=Y) shy(X gt=Y X= Y Xgt Y)
se(X lt=Y) shy
(X lt=Y
X= Y
X lt Y)
csel(infix = infix =)
39
csel(infix = infix = csel(infix = infix gt)
csel(infix = infix lt) csel(infix gt infix gt) cseJ(infix lt infix lt) csel(infix gt= infix gt=) csel(infix gt= infix gt csel(infix gt= infix =)
csellinfix lt= infix lt=) csel(infix lt= infix lt) csel(infix lt= infix =)
Finding solutions
sol(X v Y) -
(( notetra(X) eon(X) ( sol(Y) )
( c1ause(P v Q R) not(cketra(P v Q))
dis(P v Q X v Y R) ~ )
( A lt=gt B equival(A lt=gt B X v Y) ~ I) sol(X) - ~ notetra(X) eon(X)
so~(X) - notetra(X)
( con (X)
( clause(P v Q R) not(ekctra(P v Q)) dis(P v Q X R) I)
cketra(P v Q) -
eketra(P) eketra(Q) eketra(F(I J)) shy
selec(F(I J))
c1ause(contradiction(sel(F(IJ))) _I
eketra(number(W I)) -
clause(cootradietion(num(Wl)) - eketr(P) shy
clause(contradiction(P) - 1
notctra(P) shy
not( e lause( con tradiction(P) _))
40
Searching (or disjunctions
dis(P v Q X v Y R) - dis(P X v Y R)
dis(Q X v Y R) con(R)
dis(P v Q X R) -
dis(P X R) dis(Q X R) con(R
dis(P X v Y R) - clause(contradicton(Pl J 1
dis(F(I J) sel(G(I J)) v Y R) - csel(G Fl dis(number(WI) num(W N v Y R) - cnum(N I)
dis(P P v Y R) -
dis(P X v Y R) - dis(P Y R)
dis(F(I J) seJ(G(IJ)) R) - csel(G F)
dis(number(WI) num(WN) R) - cnum(N I) dis(P P R) - 1
dis(FJ J X R) shy
( ckctra(F(IJ) cbeckeq(seJ(F(IJ))) )
dis(number(W Il X R) - ( ckctra(number(WI)) cbeckeq(num(WI)) )
dis(P X R) shy( ckctra(P) cbeckeq(P) ) 1
cbeckeq(P) shy
(( A lt=gt so2(contradiction(P))
bagof(A A [jj) ) ( so2(contradiction(P)) lt=gt B
bagof(B B Uj) ))
ckeq(A) shy
( so2(A) lt=gt B B lt=gt so2(A) ) bagof(B B UJ)
con((P Q)) -
clause(P R) con(R) con(Q) con(true) -
con(contradiction(P)) - clause(contradiction(P) J
con(cause(X Y)) - cause(X Y)
con(sel(X)) - sel(X)
con(num(X Y)) - num(X Y) con(P)- (( dause(P R) (con(R) ckeq(R)))
colJectin(P) )
collectin(P) shy
bagof(S (c1ause(P S) S = true) [L LIJ )
mkcon(L Ll L)
bagor(l (L2 ) UJ) L
mkcon((A AI) (B B1) (sol(A v B) e D)) -
mkcon(A B1 e) mkcon(A1 (B Bl) D)
mkcon(A (B B1) (sol(A v B) e)) -
mkcon(A Bl e)
mkcon((A AI) B (sol(A v B) e)) middot1
mkcon(Al B e)
mkcon(A B sol(A vB))
Searching ror equivalences
equival(A lt=gt B X v Y) - 1 ( equival(A lt=gt B X) equival(A lt=gt B Y) )
equival(s02(A) lt=gt 502(B) A) - clause(B _I equival(s02(B) lt=gt 502(A) A) c1ause(B _I
Top level or inrerence mechanism
goo((s02(whatnum) P)) -
getatm(P Xl
bagor(number(X Y) ( P so2(number(X Y)) ) A )
count1(A 00 L R) nl
bagor(X P B )
count2(B L R Ll Rl) nJ print()
(( LI = 0 Rl = 0 print(THE ANSWER IS ) nl
(( Ll = Rl prin(-Jumber or ) prn(P) print(is Ll) )
( Rlgt20000 prin(Number or I prn(P) print(is LI or more) )
42
( prin(Number of ) pfn(P) print( is from Ll to Rl) )) )
( print(THE ANSWER IS NO I )) print()
goo(X) shy
(( bagof(X X L) L = [I nl print()
print(THE ANSWER IS YES) nl wout(L) print() )
( equiv(X L) nl print()
print(THE ANSWER IS YES) nl wout(L) print(-) )
( c1ause(inpt(A ==gt B) _I ( impli(A B Z) impli(B A Z) ) print(l~Hl)
printTHE ANSWER IS YES) nl print(Z) print(Hj~(fH~) ))
goo(X) print( Hg)
print(THE ANSWER IS NO ) print( lH~lH~gg9l9lmiddotmiddot~Q(gmiddot)
00 Semhing for implications in equiV3lent relations
impli( B Z) shyt-ell( z1) prin(templ() pchn(S A lt=gt B) print()) close ( zl) consult(zl) templ(Z)
unload zl Z
Searching for equivalence
equiv (X L)
(( X lt=gt Y
equ(Y YI)t bagof(Y Yl L) L = [j )
(Y lt=gt X equ(Y YI) bagof(Y Yl L) L = [J )
( X = F(New)
clause(~ew T) makeup(T Tl)
(( Tl lt=gt B
equ(B Bl) bagof(Bl Bl M) M = [j L=[Newl )
(A lt=gt TI
equ(A AI) bagof(Al AI M) M = 1] L=INewj )) ))
makeup((A B) (AI Bl)) -
makeup(A A1) makeup(B BI)
makeup(A so2(A))
equ((A B) (AI BI)) -
equ(A AI) equ(B Bl)
equ(sol(X v Y) sol(XI v Yl)) -
equ(X XI) equ(Y YI)
equ(so2(X) so2(XI)) -
equ(X XI)
equ(contradiction(X) clJuse(contradiction(X) X) ) -
equ(X X)
Counting numbers
getatm((A B) X) -
( getatm(A X) getatm(B X) )
getatm(so2(F(X)) X) -
getatm(so2(X) X) - atom(X)
countl([J L R L R) -
countl([number(X Y)IT] L R L2 R2) shy
(( Y = (gt=~) LI is L + N Rl is R + 20001 l )
( Y = (gt N) LI is L+ N+ 1 RI is R + 20002 )
(Y == laquo=~) LI is L + 1 Rl is R + N )
(Y = laquo N) LI is L + 1 RI is R+N-I)
(Y == IJ LI is L + I Rl is R + J ) ( Y == N L1 is L + N RI is R + N ))
count1(T LI R 1 L2 R2)
count2(fJ L R L R) - 1
count2([XITJ L R L2 R2) shy
name(X Xl)
(( Xl = sknj LI is L Rl is R )
44
( Xl = Iskmj L1 is L + 1 RI is R + ZOOO1) ( LI is L + I RI is R + I ))
count2(T LI RI L2 R2)
pfn((A B)) - pfn(A) prn(B)
pCn(so2(F(X))) - prin(F )
prn(so2(X)) - atom(X) prin(X ) prn (so2(X))
Printing result
wout([XlJ - prt(X) nl woutf[xIY]) - prt(X) nl nl wout(Y)
prt(e(A B)) -
prt(A) prinr 8 ) prt(ltE) prt(eA) - prt(A)
prt(c(A EJ) - prin() prt(A) prine ) prt(B) prin(T)
prt(c A) - prt(A) prt((A E)) - ~
prt(A) nl prt(E) prt(sol(X v Y)) - ~
prt(X) prinC v) prt(Y) prt(A lt=gt B) -
prt(e A) prinC lt=gt ) prt(e B) prt(sol(X)) - prt(X)
prt(so2(X)) - prt(X
prt(c1ause(X Y)) - prt(X)
prt(contradiction(X)) - prin(contradiction() prt(cX) prinr))middot prt(num(XY)) - prin(number(X Y)) prt(sel(X)) - prin(X) prt(X v Y) - prt(X) prin( v) prt(Y) prt(X) prin(X)
Handling conditional queries
condi((Y Xl) shy
assertcon(X) Y
45
retractcon(X)
condi((B A))
retractcon(A) fail
assertcon((A B)) 1
assertcon(A) assertcon(B)
assertcon(A) asserta(A)
retrac teon ((A B)) 1
retracteon(A) retractcon (B)
retraetcon(A) - retract(A)
BIBLIOGRAPHIC DATA SHEET
Report No UIUCDS-F-84-928
3 Recipients Accession No
4 T ide and Subt ltle
An Annotated Predicate Calculus Inference System (APCIS)
S Report Date
November 1984 6
7 Author(s)
Kah-Eng Pua 8 Performing Organization Rept
No
9 Performing Organization Name and Address
Department of Computer Science University of Illinois Urbana IL
10 ProjectTaskWork Unit No
11 Contract Grant No NSF DCR 84-06081 ONR N00014-82-K-0186
12 Sponsoring Organization Name and Address
National Science Foundation Washington DC
13 Type of Report amp Period Covered
14
15 Supplementary Notes
16 Abstracts
This paper describes a deductive inference system called APCIS (Annotated Predicate Calculus Inference System) APCIS is able to carry out inferences from expressions involving numerical quantifiers selectors disjunctions of non-negated terms negated terms disjunctions of negated terms equivalences and exceptions It is also able to count the numbers of occurrence of a given simple term or a conjunction of terms The design of contradiction and the treatment of the disjunction of non-negated terms allow APCIS to accept Horn clauses as well as non-Horn clauses and to carry out inferences from them This feature makes APCIS more general than Prolog
17 Key lords and Document Analysis 170 Descriptors
APC (Annotated Predicate Calculus) APCIS (Annotated Predicate Calculus Inference System) Horn Clause Numerical Quantifier Prolog Selector
17b IdentifiersOpen-Ended Terms
17c COSATI FieldGroup
18 Availability Statement 19 Security Class (This
Re~f~~IA~SIF IFf)
21 ~o of Pages
49 211 ecurity Class (This
PageUNCLASSIFIED
22 Price
FOA NTIS n (10middot70 usco-oc 40329-
e Universal quantifier
all(X p(X))
f Existential quantifier
exists(X p(X))
g Numerical quantifier
exists(I X p(X))
where p(X) is a formula
where X is a variable or a Jist of variables or the
form [HI~rj and p(X) a formula
where I repersents expression involving integer(s)
and operator(s) in c or d above and p(X) a formula
25
Appendix B
APCIS Program Listings
------------------------------- Program Name APCIS - Part 1 APC Translator
-------------------------------
op(3OO fx -)1
op(500 xfy amp)
oPt 500 xfy v)
op(600 xfx )
op(700 fx [gt= lt= gt lt ]) op(400 xfy [= gt= lt= gt lt ])1 op(900 xfy gt lt=gt -])1
steps(X Xg) shy
numbervars(X 1 J Step 1 change variables to iis
rmimp(X X) Step 2 conv(X X3) Step 3
rewrite(X3 X4) Step 4
negin(X4 X5) Step 5
dropexist(X5 X6 1]) Step 6
dropall(X6 X7) Step 7
distrib(X7 X8) Step 8 clausiCy(X8 X9 [J) Step 9
ta(X) shysteps(X Xg)
(( Xg = II nl
print( yes it is always true) )
( nl nl printcl(X9))) Step 10a
tq(X) shy
steps(X Xg)
prques(Xg)
28
Step 2 Removing implic3tions amp Transforming exceptions and equiv3lences
rmimpl( P - Q (PI lt=gt (QI) ) amp ((PI) lt=gt QI) ) -
rmimpl(P PI) rmimpl(Q QI)
rmimplnp) lt=gt Q (PI lt=gt -(QI)) amp nPI) lt=gt QI) ) - 1
rmimpl(P PI) rmimpJ(Q QI)
rmimpJ(P lt-gt -(Q) (PI lt=gt -(QI)) amp nPI) lt=gt QI) ) -
rmimpl(P PI) rmimpl(Q QI)
rmimpl( P lt=gt Q PI lt=gt QI ) - I
rmimpl(P PI) rmimpl(Q QI)
rmimpl( P ==gt Q -(PI) v QI ) - I
rmimpl(P PI) rmimpl(Q QI)
rmimpl( all(X P) aI(X PI) ) - 1
rmimpl(P PI)
rmimpl( exists(X P) exists(X PI) ) -
rmimpl(P PI)
rmimpl( exists(I X P) exists(I X PI) ) -
rmimpl(P PI)
rmimpl( P amp Q PI amp Ql ) -
rmimpl(P PI) rmimpl(Q Ql)
rmimpl( P v Q PI v QI ) -
rmimpl(P PI) rmimpl(Q QI)
rmimpl( -(p) -(PI) ) - I
rmimpl(p PI)
rmimpl( P P )
St~p 3 Converting numerical amp distinctive quantifiers
L Numerical quantifiers
examples of input forms
1 exists(gt= i X pIX)) where i is an integer
2 exists(i X pIX)) where i is an integer
3 exists(i j X pIX)) where i j are integers and iltj
4 exists(il v i2 X pIX)) where is are integers
examples of output forms of this step
1 exists(X pIX) amp number(X gt= i) )
2 exists(X pIX) amp number(X i) ) 3 exists(X pIX) amp number(X ij) ) 4 exists(X pIX) amp number(X il v i2) )
II Distinctive quantifiers
27
example or input Corm
exists([XYL p(X Y))
example or output Corm or this step
exists(X exists(Y p(XY)) )
conv(P lt=gt Q PI lt=gt QI) - 1
conv(P PI) conv(Q QI)
conv(al1(X P) all(X PI)) -
conv(P PI)
conv(exists(HIT] P) R ) - conv(P PI) convert distinctive quantifier
convtdis(exists([HIT]PI) R)
conv( exists(I X P) exists(X PIamp number(X I) )) -
conv(P PI) convert numerical quantifier
conv(exists(X P) exists(X PI)) - 1
conv(P Pl)
conv(P amp Q PI amp QI) - 1
conv(P PI) conv(Q QI)
conv(P v Q PI v QI) - t conv(P PI) conv(Q QI)
convC(P) -(PI)) -
conv(P PI)
conv(P Pl
convtdis(existsl[XL P) exists(X P)) - atomic(X) convtdis(exists[XIYj Pl exists(X R)) shy
convtdis(exists(Y P) R)
Step 4 Rewriting compound predicates andor compound selectors
Outputs are smiple predicates andor simple selectors
rewrite(P lt=gt Q PI lt=gt QI) - t rewrite(P PI) rewrite(Q QI)
rewrite(all(X Pl all(X PI)) - 1 rewrite(P PI)
rewriteexists(X P) exists(X PI)) - I rewriteP PI)
rewrite(P amp Q PI amp QI) - rewrite(P P 1) rewrite( Q Q 1
rewrite(P v Q PI v QI) - 1
rewrite(P PI) rewrite(Q QI)
rewriteC(P) -(PI)) - I
28
rewrite(P PI) rewrite(F(A B) R) -
rewrite(A AI) rewrite(B BI) re(F(AI BI) R)
rewrite(F(A) R) -
rewrite(A AI) re(F(AI) H)
rewrite(F(A B C) R) -
rewrite(A AI) rewrite(B BI) rewrite(C CI) re(F(AI BI CI) R)
rewrite(F(A B C D) R) -
rewrite(A AI) rewrite(B Btl rewrite(C CI) rewrite(D DI) rc(F(AI BI CI Dl) H)
rewrite(PP)
re(F(A B v el (RI v R2) -
re(F(A Bl RIl re(F(A C) R2) reF(A B amp cl (RI amp R2)) -
re(F(A B) RI) re(F(A e) R2) re(F(A amp B C) (Rl amp R2)) -
re(F(A e) R 1) re(F(B C) R 2) re(F( v B el (R I v R2)) -
re(F(A el R I) reFB el R2) re(F(A amp Bl (R I amp R2)) -
re(F(A RI) re(F(BJH2) re(F(A v B) (R 1 v R2)) -
re(F(A) RI) re(F(B) R2)
re(F(A vB c Dl (RI v R2) -
re(F(A C D) RI) re(F(B C D) R2) re(F(A amp B C D) (RI amp R2)) -
re(F(A C D) Rll re(F(B C D) R2) re(F(A B v C D) (HI v R2)) -
re(F(A B D) RI) re(F(A C D) R2) re(F(A B amp C D) (HI amp R2)) -
re(F(A B D) RI) re(F(A C D) R2) re(F(A B C v D) (RI v R2)) -
re(F(A B C) R I) reF(A B D) R2) re(F(A B C amp D) (RI amp R2)) -
29
re(F(A B C) RI) re(F(A B D) RZ)
re(F(A v B e D E) (R I v R2)) -
re(F(A e D E) R I) re(F(B e D El R2) re(F(A amp B e D E) (RI amp RZ)) -
re(F(A e D El R 1) re(F(B e D E) R2) re(F(A B v e D E) (R I v R2)) -
re(F(A B D E) RI) re(F(A e D E) R2)
re(F(A B amp e D E) (RI amp R2)) -
re(F(A B D El RI) re(F(A e D E) RZ) re(F(A B e v D E) (R I v R2)) -
re(F(A B e El R 1) re(F(A B D E) RZ) re(F(A B e amp D E) (RI amp RZ)) -
re(F(A B e E) R I) re(F(A B D E) RZ)
re(F(A B e D vEl (RI v RZ)) - l
rc(F(A B C D) RI) re(F(A n e El RZ) re(F(A B e D amp El (RI amp RZ)) - ~
re(F(A B e D) RI) re(F(A B e El RZ)
re((A = B) (A = B)l-
re((A = Bl (A = 8)) -
retIA gt= BI (A gt= B)) -
re((A lt= B) (A lt= B)) -
re((A gt B) (A gt B))-
re((A lt Bl (A lt Bl)- re(A A)
Step) Bringing n(gation inwards
Degin(-(P) PI) - neg(P Pl)
negin(P lt=gt Q PI lt=gt Ql) - ~
negin(P PI) negiD(Q QI)
Degin(aU(X P) all(X PI)) - Degin(P PI) negin(exists(X P) exists(X PI))- negin(P PI) negin(P amp Q PI amp Ql) - Degin(P PI) negin(Q Ql)
Degin(P v Q PI v QI) - Degin(P PI) negin(Q QI) negin(P Pl
neg(-(P) PI) - negin(P PI)
neg(all(X P) exists(X PI)) - neg(P PI)
30
neg(exists(X P) all(X PI)) - neg(P PI)
neg(P amp Q PI v QI) - neg(P PI) neg(Q Ql)
neg(P v Q PI amp QI) - neg(P PI) neg(Q QI)
neg(P -(PH
Step 6 Dropping existnetial quanti6ers
dropexist(P lt=gt Q PI lt=gt QI Elerns) - dropexist(P PI Elerns) dropexist(Q QI Elerns)
dropexist(alJ(X P) all(XPI) Elerns)
dropexist(P PI [XIElernsJ)
dropexist(exists(X P amp nurnber(X Yraquo P2 Elerns) -
genfun(skn Newg) Fun = [NewgIElerns]
subst(FuD X P amp Dumber(X Y) PI)
dropexist(Pl P2 Elerns)
dropexist(exists(X P) PZ Elerns) -
genfun(skrn Newf) Fun = [NewfIElernsJ
subst(Fun X p PI)
dropex ist(P 1 P~ Elerns)
dropexist(P v Q PI v QI Elerns) - ~
dropexist(P PI Elerns) dropexist(Q Ql Elerns)
dropexist(P amp Q PI amp QI Elerns) - 1
dropexist(P Pl Elerns) dropexist(Q QI Elerns)
dropexist(P P _)
gen fun(R oot Newn arne) shy
getnurn(Root Nurn)
narne(Root Rootlist)
append(Rootlist[Nurnj Narnelist)
concat(Narnelist Newnarne)
getnurn(Root Nurn) shy
retract(currentnurn(Root Nurn 1 raquo
Nurn is Nurni + 1
asserta(currentnurn(Root Nurn))
getnurn(Root 1) - asserta(currentnurn(Root 1))
subst(New Old Val Val) - var(Val)
subst(New Old Old New) - 1 substNew Old Val Val) - atornic(Val)
31
subst(New Old Val Newval) shy
runctor(Val F N)
CUDctor(Newval F N)
subst_args(N New Old Val Newval)
subst_args(O J J - J J
subst_args(N New Old Val NewVal) shy
arg(N Val OldArg)
arg(N NewVal NewArg)
subst(New Old OldArg NewArg)
NI is N - I
subst_args(Nl New Old Val NewVal)
append([J L L) -
append([XILl] L2 [XIL3]) - append(Ll L2 L3)
Step - Dropping universal quantifiers
dropall(P lt=gt Q PI lt=gt QI)-
dropall(P PI) dropall(Q QI)
dropall(all(X P) PI) - ~ dropall(P PI)
dropall(P amp Q PI amp QI) -
dropall(P PI) dropall(Q QI)
dropall(P v Q PI v QI) -
dropall(P PI) dropall(Q QI)
dropall(P P)
Step 8 Distributing conjunctions over disjunctions
distrib(P lt=gt Q PI lt=gt Ql) - t distrib(P PI) distrib(Q QI)
distrib(P v Q R) -
distrib(P PI) distrib(Q QI)
distributing(PI v QI R)
distrib(P it Q PI it QI) -
distrib(P PI) distrib( Q QI)
distrib(P P)
distributing((P amp Q) v R PI amp QI) -
distrib(P v R PI) distrib(Q v R Ql)
32
distributing(P v (Q amp R) PI amp Ql) -
distrib(P v Q PI) distrib(P v R Ql)
distributing(P P)
Step 9 Packing each conjunction into clauses
c1ausify(P amp Q CI C2) -
clausiCy(P CI C3) c1ausify(Q C3 C2)
cbusiCy(P [d(A B)ICs] Cs) shy
inclause(P A [j B [I) 1
c1ausiry( C C)
inclause(P v Q A AI B B1) -
inc1ause(P A2 AI B2 Bl)
inclause(Q A A2 B B2)
inclausenp) A A B1 B) -
notin(P A) putin(P B B1)
inclause(P AI A B B) shy
notin(P Bl putin(P A AI)
notin(X [XU) - fail
notin(X [JLj) - notin(X L)
notin(X 1])
putin(X II [X]) - 1
putin(X [XILJ L) -
putin(X [YILJ [YILl]) - putin(X L Ll)
Step 1Oa Printing clauses
printcl([]) - nl nl
printcl(c1(AB)ICsj) - printcl(A Bl nl printcl(Cs)
printcl(L II) - printdis(IL) prinr)middot
printclHl L) - prin(contradiction(() printconl(rL)
print()) - ) printconj(rL) prinr )
printcl(Ll L2) shy
printdis(ILl) print( - ) printconj(rL2) prin()
printdis(S[Lj) - printcbar(SL)
33
printdis(S[LILs]) - printchu(SL) prin( v) printdis(SLs)
printconl(S[LI) - printchar(SL)
printconl(S[LILs]) - printchar(SL) prin( ) printconl(SLs)
printconj(S[L]) - tab(3) printchar(SL)
prin tconj( S [L IL sl) shy
tab(3) printchar(SL) print( ) printconj(SLs)
printchar(SP) shy
atomic(P)
name(P L)
L = [IT]
concat([XIT NewP)
prin(~ewP)
printchar(SP) shy
atomic(P)
prin(P)
printchar(SA lt= gt B) -
prin((l clausify(A AI [j) pl(eAl) prin())
print lt=gt )
prin(() cbusify(B Bl [I) pJ(eBl) prine))middot
printchar(rnumber(X N)) shy
prin(num() printchar(rx) prin( )
printchar(rN) prinC))
printchar(rF(A B)) shy
seJec(F(A B))
prinCsel() printchar(rA)
prin( F ) printchar(rB) prinC))
printchar(SF(A B)) shy
( selec(F(A B)) F = infix )
printchar(SA) prin( F ) printchar(SB)
printchar(SF(A)) shy
(F= prefix gt= F= prefix lt= F= prefixgt F= prefix lt )
prin(F ) printcbar(SA)
printchar(SP) shy
functor(P F MaxN)
prin(F ()
Nl is MaxN - 1
putout(S N 1 P MaxN)
34
prin())
putout(S 0 P MaxN) -
arg(~laxN P Argu)
prin tchar(SArgu)
putout(S N p MaxN) shy
Nt is MaxN - N arg(NI P Argu)
printcbar(SArgu )
prin( )
N2 is N - 1
putout(S N2 P MaxN)
selec(FA B)) shy
( F= infix = F= infix f= F= infix gt=
F= infix gt F= infix lt= F= infix lt )
35
----------------------------------Program Name APClS - Part 2 Inference Mechanism ---------------------------------- a(X) shy
steps(X X9)
(( X9 =[] nl
print( yes it is always true) )
( X9 =[cI(IJ[])] nl
print( no it is always false) )
( nl nl printel(X9) Step 1Oa
tell(temp_file) printel(X9) e1ose(temp_file) consult(temp_6Ie) ))
q(X) shy
asserta( in pt(X))
steps(X X9)
(( X9 = [] print(middot~H~~middot~t~)
print(THE AiSWER IS YES)
print( ilgIQlQl(~) )
( X9 = [e1([j [j)] Pr1nt ( OJ fi(i I~ iii Ij)middot(i)(i) fiyenQ)riiio(i)(ij)(i)fj)fiyen1li1il1li1il)__ gtw~ __~_~ _~~_ ~_-=~
print(THE ANSWER IS NO ) print() )
( teI1(temp_6Ie)
prques(X9) Step 1Ob
close(temp_file)
nl print(Let me think about it) nl
consult(temp_6Ie) ))
retrac t( in pt(X))
Step lOb Printing question
prques(lcl(A 8)1) - prin(goo(() pl(qA 8) print()))
prques([c1(A 8HCs]) - prin(goo(() pl(qA 8) print() pl(q Cs)
pl(e [c1(A 8)]) - pl(eA 8)
pl(q [c1(A 8)]) - pl(qA 8) print()))
pl(S [e1(A B)ICs]) - pl(SA B) prin( ) pl(S Cs)
38
pl(q [j L) - prin(c1ause(contradiction(() pcont(qL) prin())_))
pl(S [I L)- prin(so2(contradidion(() pcont(SL) print))))middot
pl(S [L] []) - prin(so2() pcbar(SL) prin())
pl(S L [J)- prinsol() plett(SL) print))
pl(S [L] LI) - prin(condi(() pchar(cL)
prin(() pcont(S Ll) prine))))
pl(S L Ll)- prin(c1ause() plert(cL)
prin(() pcont(S Ll) prine)))
plert(S[LJ) - pchar(SL)
plert(SjLILsj) - pcbar(SL) print v) pleCt(SLs)
pcont(S[L]) - pchar(SL)
pcont(S[LILsj) - pcbar(SL) prinr ) pcont(SLs)
pcbar(SP) shy
atomic(P)
name(PL)
( L = [IT] L = [5 k miT] L = [5 k niT] )
concat[XITj NewP)
prin(0JewP)
pchar(SP) shy
atomic(P)
prin(P) pchar(SA lt=gt B) -
prin(() dausify(A AI []) pl(eAI) prin())
prinr lt=gt ) prin(() dausify(B BI ]) pl(eB) print))
pchar(Snumber(X N)) shy
prin(num() pchar(SX) prin()
pchar(SN) prinr))
pcbar(SM N) - prin(M N)
pcbar(cF(A B)) shy
selec(F(A Braquo
pcbar(cA)
prine F ) pchar(cB) pchar(SF(A B)) shy
selec(F(A B))
prin(sel() pchar(SA)
print F ) pchar(SB) print)) I
31
pc har(SF(A)) shy
( F= prefix gt= F= prefix lt= F= prefixgt F= prefix lt )
prin(F ) pchar(SA)
pchar(SP)shy
runctor(P F MaxN)
prin(F ()
011 is MaxN - 1 pout(SNl P MaxN)
print) )
pout(S 0 P M3xN) - 1
arg(~bxN P Argu)
pchlr(SArgu )
pout(S N P MaxN shy
Nl is MaxN - N
arg(Nl P Argu)
pchar(SArgu
prin( )
N2 is N - 1
pout(S N2 P ~13xN)
Comparing numbers in numerical quantifiers
num(XN) shy
number(X I)
cnum(N 1) ~
cnumlaquo=01 lt=I- N gt=I
cnumlaquo=J lt I) - N gt=1-1
cnumlaquo=NIJ) - N gt=J 1
cnumlaquo=N J)- integer(I) N gt=I~
cnum(gt=N gt=1) - N lt=1
cnum(gt=N gt I) - N lt=1+ 1 cnum(gt=NIJ) - N lt=1
cnum(gt=N lt=1)- N lt=1
cnum(gt=N lt I) - N lt=1 L cnum(gt=N 1)- integer(I) N lt=1
cnum( lt N lt 1)- N gt=1 L
38
cnum( lt N lt=1) - N gt I cnum( lt NLJ) - N gt J
cnum( lt N 1)- integer(I) N gt 1
cnum(gt N gt I) - N lt=1 cnumlgt i gt=1) - N lt I
cnum(gt N lt=1) - N lt=0
cnum(gt N lt I) - N lt=0
cnum(gt iIJ) - N lt I cnum(gt N 1)- integer(I) N lt I
cnum(~LN lt=1) - M=I N gt= I l
cnum(~LN lt I) - M=l N gt= I-I
cnum(~LNLJ) - M lt =1 N gt = J
cnum(~1N 1)- integer(I) M lt= I N gt= I
cnum(- N) - integer(N)
Comparing selectors
sel(X = Y) shyX= Y
sel(X I=Y) shy(X I=Y X lt Y Xgt Y)
sel(X gt Y) shyXgt Y
sel(X lt Y) shyXlt Y
selX gt=Y) shy(X gt=Y X= Y Xgt Y)
se(X lt=Y) shy
(X lt=Y
X= Y
X lt Y)
csel(infix = infix =)
39
csel(infix = infix = csel(infix = infix gt)
csel(infix = infix lt) csel(infix gt infix gt) cseJ(infix lt infix lt) csel(infix gt= infix gt=) csel(infix gt= infix gt csel(infix gt= infix =)
csellinfix lt= infix lt=) csel(infix lt= infix lt) csel(infix lt= infix =)
Finding solutions
sol(X v Y) -
(( notetra(X) eon(X) ( sol(Y) )
( c1ause(P v Q R) not(cketra(P v Q))
dis(P v Q X v Y R) ~ )
( A lt=gt B equival(A lt=gt B X v Y) ~ I) sol(X) - ~ notetra(X) eon(X)
so~(X) - notetra(X)
( con (X)
( clause(P v Q R) not(ekctra(P v Q)) dis(P v Q X R) I)
cketra(P v Q) -
eketra(P) eketra(Q) eketra(F(I J)) shy
selec(F(I J))
c1ause(contradiction(sel(F(IJ))) _I
eketra(number(W I)) -
clause(cootradietion(num(Wl)) - eketr(P) shy
clause(contradiction(P) - 1
notctra(P) shy
not( e lause( con tradiction(P) _))
40
Searching (or disjunctions
dis(P v Q X v Y R) - dis(P X v Y R)
dis(Q X v Y R) con(R)
dis(P v Q X R) -
dis(P X R) dis(Q X R) con(R
dis(P X v Y R) - clause(contradicton(Pl J 1
dis(F(I J) sel(G(I J)) v Y R) - csel(G Fl dis(number(WI) num(W N v Y R) - cnum(N I)
dis(P P v Y R) -
dis(P X v Y R) - dis(P Y R)
dis(F(I J) seJ(G(IJ)) R) - csel(G F)
dis(number(WI) num(WN) R) - cnum(N I) dis(P P R) - 1
dis(FJ J X R) shy
( ckctra(F(IJ) cbeckeq(seJ(F(IJ))) )
dis(number(W Il X R) - ( ckctra(number(WI)) cbeckeq(num(WI)) )
dis(P X R) shy( ckctra(P) cbeckeq(P) ) 1
cbeckeq(P) shy
(( A lt=gt so2(contradiction(P))
bagof(A A [jj) ) ( so2(contradiction(P)) lt=gt B
bagof(B B Uj) ))
ckeq(A) shy
( so2(A) lt=gt B B lt=gt so2(A) ) bagof(B B UJ)
con((P Q)) -
clause(P R) con(R) con(Q) con(true) -
con(contradiction(P)) - clause(contradiction(P) J
con(cause(X Y)) - cause(X Y)
con(sel(X)) - sel(X)
con(num(X Y)) - num(X Y) con(P)- (( dause(P R) (con(R) ckeq(R)))
colJectin(P) )
collectin(P) shy
bagof(S (c1ause(P S) S = true) [L LIJ )
mkcon(L Ll L)
bagor(l (L2 ) UJ) L
mkcon((A AI) (B B1) (sol(A v B) e D)) -
mkcon(A B1 e) mkcon(A1 (B Bl) D)
mkcon(A (B B1) (sol(A v B) e)) -
mkcon(A Bl e)
mkcon((A AI) B (sol(A v B) e)) middot1
mkcon(Al B e)
mkcon(A B sol(A vB))
Searching ror equivalences
equival(A lt=gt B X v Y) - 1 ( equival(A lt=gt B X) equival(A lt=gt B Y) )
equival(s02(A) lt=gt 502(B) A) - clause(B _I equival(s02(B) lt=gt 502(A) A) c1ause(B _I
Top level or inrerence mechanism
goo((s02(whatnum) P)) -
getatm(P Xl
bagor(number(X Y) ( P so2(number(X Y)) ) A )
count1(A 00 L R) nl
bagor(X P B )
count2(B L R Ll Rl) nJ print()
(( LI = 0 Rl = 0 print(THE ANSWER IS ) nl
(( Ll = Rl prin(-Jumber or ) prn(P) print(is Ll) )
( Rlgt20000 prin(Number or I prn(P) print(is LI or more) )
42
( prin(Number of ) pfn(P) print( is from Ll to Rl) )) )
( print(THE ANSWER IS NO I )) print()
goo(X) shy
(( bagof(X X L) L = [I nl print()
print(THE ANSWER IS YES) nl wout(L) print() )
( equiv(X L) nl print()
print(THE ANSWER IS YES) nl wout(L) print(-) )
( c1ause(inpt(A ==gt B) _I ( impli(A B Z) impli(B A Z) ) print(l~Hl)
printTHE ANSWER IS YES) nl print(Z) print(Hj~(fH~) ))
goo(X) print( Hg)
print(THE ANSWER IS NO ) print( lH~lH~gg9l9lmiddotmiddot~Q(gmiddot)
00 Semhing for implications in equiV3lent relations
impli( B Z) shyt-ell( z1) prin(templ() pchn(S A lt=gt B) print()) close ( zl) consult(zl) templ(Z)
unload zl Z
Searching for equivalence
equiv (X L)
(( X lt=gt Y
equ(Y YI)t bagof(Y Yl L) L = [j )
(Y lt=gt X equ(Y YI) bagof(Y Yl L) L = [J )
( X = F(New)
clause(~ew T) makeup(T Tl)
(( Tl lt=gt B
equ(B Bl) bagof(Bl Bl M) M = [j L=[Newl )
(A lt=gt TI
equ(A AI) bagof(Al AI M) M = 1] L=INewj )) ))
makeup((A B) (AI Bl)) -
makeup(A A1) makeup(B BI)
makeup(A so2(A))
equ((A B) (AI BI)) -
equ(A AI) equ(B Bl)
equ(sol(X v Y) sol(XI v Yl)) -
equ(X XI) equ(Y YI)
equ(so2(X) so2(XI)) -
equ(X XI)
equ(contradiction(X) clJuse(contradiction(X) X) ) -
equ(X X)
Counting numbers
getatm((A B) X) -
( getatm(A X) getatm(B X) )
getatm(so2(F(X)) X) -
getatm(so2(X) X) - atom(X)
countl([J L R L R) -
countl([number(X Y)IT] L R L2 R2) shy
(( Y = (gt=~) LI is L + N Rl is R + 20001 l )
( Y = (gt N) LI is L+ N+ 1 RI is R + 20002 )
(Y == laquo=~) LI is L + 1 Rl is R + N )
(Y = laquo N) LI is L + 1 RI is R+N-I)
(Y == IJ LI is L + I Rl is R + J ) ( Y == N L1 is L + N RI is R + N ))
count1(T LI R 1 L2 R2)
count2(fJ L R L R) - 1
count2([XITJ L R L2 R2) shy
name(X Xl)
(( Xl = sknj LI is L Rl is R )
44
( Xl = Iskmj L1 is L + 1 RI is R + ZOOO1) ( LI is L + I RI is R + I ))
count2(T LI RI L2 R2)
pfn((A B)) - pfn(A) prn(B)
pCn(so2(F(X))) - prin(F )
prn(so2(X)) - atom(X) prin(X ) prn (so2(X))
Printing result
wout([XlJ - prt(X) nl woutf[xIY]) - prt(X) nl nl wout(Y)
prt(e(A B)) -
prt(A) prinr 8 ) prt(ltE) prt(eA) - prt(A)
prt(c(A EJ) - prin() prt(A) prine ) prt(B) prin(T)
prt(c A) - prt(A) prt((A E)) - ~
prt(A) nl prt(E) prt(sol(X v Y)) - ~
prt(X) prinC v) prt(Y) prt(A lt=gt B) -
prt(e A) prinC lt=gt ) prt(e B) prt(sol(X)) - prt(X)
prt(so2(X)) - prt(X
prt(c1ause(X Y)) - prt(X)
prt(contradiction(X)) - prin(contradiction() prt(cX) prinr))middot prt(num(XY)) - prin(number(X Y)) prt(sel(X)) - prin(X) prt(X v Y) - prt(X) prin( v) prt(Y) prt(X) prin(X)
Handling conditional queries
condi((Y Xl) shy
assertcon(X) Y
45
retractcon(X)
condi((B A))
retractcon(A) fail
assertcon((A B)) 1
assertcon(A) assertcon(B)
assertcon(A) asserta(A)
retrac teon ((A B)) 1
retracteon(A) retractcon (B)
retraetcon(A) - retract(A)
BIBLIOGRAPHIC DATA SHEET
Report No UIUCDS-F-84-928
3 Recipients Accession No
4 T ide and Subt ltle
An Annotated Predicate Calculus Inference System (APCIS)
S Report Date
November 1984 6
7 Author(s)
Kah-Eng Pua 8 Performing Organization Rept
No
9 Performing Organization Name and Address
Department of Computer Science University of Illinois Urbana IL
10 ProjectTaskWork Unit No
11 Contract Grant No NSF DCR 84-06081 ONR N00014-82-K-0186
12 Sponsoring Organization Name and Address
National Science Foundation Washington DC
13 Type of Report amp Period Covered
14
15 Supplementary Notes
16 Abstracts
This paper describes a deductive inference system called APCIS (Annotated Predicate Calculus Inference System) APCIS is able to carry out inferences from expressions involving numerical quantifiers selectors disjunctions of non-negated terms negated terms disjunctions of negated terms equivalences and exceptions It is also able to count the numbers of occurrence of a given simple term or a conjunction of terms The design of contradiction and the treatment of the disjunction of non-negated terms allow APCIS to accept Horn clauses as well as non-Horn clauses and to carry out inferences from them This feature makes APCIS more general than Prolog
17 Key lords and Document Analysis 170 Descriptors
APC (Annotated Predicate Calculus) APCIS (Annotated Predicate Calculus Inference System) Horn Clause Numerical Quantifier Prolog Selector
17b IdentifiersOpen-Ended Terms
17c COSATI FieldGroup
18 Availability Statement 19 Security Class (This
Re~f~~IA~SIF IFf)
21 ~o of Pages
49 211 ecurity Class (This
PageUNCLASSIFIED
22 Price
FOA NTIS n (10middot70 usco-oc 40329-
25
Appendix B
APCIS Program Listings
------------------------------- Program Name APCIS - Part 1 APC Translator
-------------------------------
op(3OO fx -)1
op(500 xfy amp)
oPt 500 xfy v)
op(600 xfx )
op(700 fx [gt= lt= gt lt ]) op(400 xfy [= gt= lt= gt lt ])1 op(900 xfy gt lt=gt -])1
steps(X Xg) shy
numbervars(X 1 J Step 1 change variables to iis
rmimp(X X) Step 2 conv(X X3) Step 3
rewrite(X3 X4) Step 4
negin(X4 X5) Step 5
dropexist(X5 X6 1]) Step 6
dropall(X6 X7) Step 7
distrib(X7 X8) Step 8 clausiCy(X8 X9 [J) Step 9
ta(X) shysteps(X Xg)
(( Xg = II nl
print( yes it is always true) )
( nl nl printcl(X9))) Step 10a
tq(X) shy
steps(X Xg)
prques(Xg)
28
Step 2 Removing implic3tions amp Transforming exceptions and equiv3lences
rmimpl( P - Q (PI lt=gt (QI) ) amp ((PI) lt=gt QI) ) -
rmimpl(P PI) rmimpl(Q QI)
rmimplnp) lt=gt Q (PI lt=gt -(QI)) amp nPI) lt=gt QI) ) - 1
rmimpl(P PI) rmimpJ(Q QI)
rmimpJ(P lt-gt -(Q) (PI lt=gt -(QI)) amp nPI) lt=gt QI) ) -
rmimpl(P PI) rmimpl(Q QI)
rmimpl( P lt=gt Q PI lt=gt QI ) - I
rmimpl(P PI) rmimpl(Q QI)
rmimpl( P ==gt Q -(PI) v QI ) - I
rmimpl(P PI) rmimpl(Q QI)
rmimpl( all(X P) aI(X PI) ) - 1
rmimpl(P PI)
rmimpl( exists(X P) exists(X PI) ) -
rmimpl(P PI)
rmimpl( exists(I X P) exists(I X PI) ) -
rmimpl(P PI)
rmimpl( P amp Q PI amp Ql ) -
rmimpl(P PI) rmimpl(Q Ql)
rmimpl( P v Q PI v QI ) -
rmimpl(P PI) rmimpl(Q QI)
rmimpl( -(p) -(PI) ) - I
rmimpl(p PI)
rmimpl( P P )
St~p 3 Converting numerical amp distinctive quantifiers
L Numerical quantifiers
examples of input forms
1 exists(gt= i X pIX)) where i is an integer
2 exists(i X pIX)) where i is an integer
3 exists(i j X pIX)) where i j are integers and iltj
4 exists(il v i2 X pIX)) where is are integers
examples of output forms of this step
1 exists(X pIX) amp number(X gt= i) )
2 exists(X pIX) amp number(X i) ) 3 exists(X pIX) amp number(X ij) ) 4 exists(X pIX) amp number(X il v i2) )
II Distinctive quantifiers
27
example or input Corm
exists([XYL p(X Y))
example or output Corm or this step
exists(X exists(Y p(XY)) )
conv(P lt=gt Q PI lt=gt QI) - 1
conv(P PI) conv(Q QI)
conv(al1(X P) all(X PI)) -
conv(P PI)
conv(exists(HIT] P) R ) - conv(P PI) convert distinctive quantifier
convtdis(exists([HIT]PI) R)
conv( exists(I X P) exists(X PIamp number(X I) )) -
conv(P PI) convert numerical quantifier
conv(exists(X P) exists(X PI)) - 1
conv(P Pl)
conv(P amp Q PI amp QI) - 1
conv(P PI) conv(Q QI)
conv(P v Q PI v QI) - t conv(P PI) conv(Q QI)
convC(P) -(PI)) -
conv(P PI)
conv(P Pl
convtdis(existsl[XL P) exists(X P)) - atomic(X) convtdis(exists[XIYj Pl exists(X R)) shy
convtdis(exists(Y P) R)
Step 4 Rewriting compound predicates andor compound selectors
Outputs are smiple predicates andor simple selectors
rewrite(P lt=gt Q PI lt=gt QI) - t rewrite(P PI) rewrite(Q QI)
rewrite(all(X Pl all(X PI)) - 1 rewrite(P PI)
rewriteexists(X P) exists(X PI)) - I rewriteP PI)
rewrite(P amp Q PI amp QI) - rewrite(P P 1) rewrite( Q Q 1
rewrite(P v Q PI v QI) - 1
rewrite(P PI) rewrite(Q QI)
rewriteC(P) -(PI)) - I
28
rewrite(P PI) rewrite(F(A B) R) -
rewrite(A AI) rewrite(B BI) re(F(AI BI) R)
rewrite(F(A) R) -
rewrite(A AI) re(F(AI) H)
rewrite(F(A B C) R) -
rewrite(A AI) rewrite(B BI) rewrite(C CI) re(F(AI BI CI) R)
rewrite(F(A B C D) R) -
rewrite(A AI) rewrite(B Btl rewrite(C CI) rewrite(D DI) rc(F(AI BI CI Dl) H)
rewrite(PP)
re(F(A B v el (RI v R2) -
re(F(A Bl RIl re(F(A C) R2) reF(A B amp cl (RI amp R2)) -
re(F(A B) RI) re(F(A e) R2) re(F(A amp B C) (Rl amp R2)) -
re(F(A e) R 1) re(F(B C) R 2) re(F( v B el (R I v R2)) -
re(F(A el R I) reFB el R2) re(F(A amp Bl (R I amp R2)) -
re(F(A RI) re(F(BJH2) re(F(A v B) (R 1 v R2)) -
re(F(A) RI) re(F(B) R2)
re(F(A vB c Dl (RI v R2) -
re(F(A C D) RI) re(F(B C D) R2) re(F(A amp B C D) (RI amp R2)) -
re(F(A C D) Rll re(F(B C D) R2) re(F(A B v C D) (HI v R2)) -
re(F(A B D) RI) re(F(A C D) R2) re(F(A B amp C D) (HI amp R2)) -
re(F(A B D) RI) re(F(A C D) R2) re(F(A B C v D) (RI v R2)) -
re(F(A B C) R I) reF(A B D) R2) re(F(A B C amp D) (RI amp R2)) -
29
re(F(A B C) RI) re(F(A B D) RZ)
re(F(A v B e D E) (R I v R2)) -
re(F(A e D E) R I) re(F(B e D El R2) re(F(A amp B e D E) (RI amp RZ)) -
re(F(A e D El R 1) re(F(B e D E) R2) re(F(A B v e D E) (R I v R2)) -
re(F(A B D E) RI) re(F(A e D E) R2)
re(F(A B amp e D E) (RI amp R2)) -
re(F(A B D El RI) re(F(A e D E) RZ) re(F(A B e v D E) (R I v R2)) -
re(F(A B e El R 1) re(F(A B D E) RZ) re(F(A B e amp D E) (RI amp RZ)) -
re(F(A B e E) R I) re(F(A B D E) RZ)
re(F(A B e D vEl (RI v RZ)) - l
rc(F(A B C D) RI) re(F(A n e El RZ) re(F(A B e D amp El (RI amp RZ)) - ~
re(F(A B e D) RI) re(F(A B e El RZ)
re((A = B) (A = B)l-
re((A = Bl (A = 8)) -
retIA gt= BI (A gt= B)) -
re((A lt= B) (A lt= B)) -
re((A gt B) (A gt B))-
re((A lt Bl (A lt Bl)- re(A A)
Step) Bringing n(gation inwards
Degin(-(P) PI) - neg(P Pl)
negin(P lt=gt Q PI lt=gt Ql) - ~
negin(P PI) negiD(Q QI)
Degin(aU(X P) all(X PI)) - Degin(P PI) negin(exists(X P) exists(X PI))- negin(P PI) negin(P amp Q PI amp Ql) - Degin(P PI) negin(Q Ql)
Degin(P v Q PI v QI) - Degin(P PI) negin(Q QI) negin(P Pl
neg(-(P) PI) - negin(P PI)
neg(all(X P) exists(X PI)) - neg(P PI)
30
neg(exists(X P) all(X PI)) - neg(P PI)
neg(P amp Q PI v QI) - neg(P PI) neg(Q Ql)
neg(P v Q PI amp QI) - neg(P PI) neg(Q QI)
neg(P -(PH
Step 6 Dropping existnetial quanti6ers
dropexist(P lt=gt Q PI lt=gt QI Elerns) - dropexist(P PI Elerns) dropexist(Q QI Elerns)
dropexist(alJ(X P) all(XPI) Elerns)
dropexist(P PI [XIElernsJ)
dropexist(exists(X P amp nurnber(X Yraquo P2 Elerns) -
genfun(skn Newg) Fun = [NewgIElerns]
subst(FuD X P amp Dumber(X Y) PI)
dropexist(Pl P2 Elerns)
dropexist(exists(X P) PZ Elerns) -
genfun(skrn Newf) Fun = [NewfIElernsJ
subst(Fun X p PI)
dropex ist(P 1 P~ Elerns)
dropexist(P v Q PI v QI Elerns) - ~
dropexist(P PI Elerns) dropexist(Q Ql Elerns)
dropexist(P amp Q PI amp QI Elerns) - 1
dropexist(P Pl Elerns) dropexist(Q QI Elerns)
dropexist(P P _)
gen fun(R oot Newn arne) shy
getnurn(Root Nurn)
narne(Root Rootlist)
append(Rootlist[Nurnj Narnelist)
concat(Narnelist Newnarne)
getnurn(Root Nurn) shy
retract(currentnurn(Root Nurn 1 raquo
Nurn is Nurni + 1
asserta(currentnurn(Root Nurn))
getnurn(Root 1) - asserta(currentnurn(Root 1))
subst(New Old Val Val) - var(Val)
subst(New Old Old New) - 1 substNew Old Val Val) - atornic(Val)
31
subst(New Old Val Newval) shy
runctor(Val F N)
CUDctor(Newval F N)
subst_args(N New Old Val Newval)
subst_args(O J J - J J
subst_args(N New Old Val NewVal) shy
arg(N Val OldArg)
arg(N NewVal NewArg)
subst(New Old OldArg NewArg)
NI is N - I
subst_args(Nl New Old Val NewVal)
append([J L L) -
append([XILl] L2 [XIL3]) - append(Ll L2 L3)
Step - Dropping universal quantifiers
dropall(P lt=gt Q PI lt=gt QI)-
dropall(P PI) dropall(Q QI)
dropall(all(X P) PI) - ~ dropall(P PI)
dropall(P amp Q PI amp QI) -
dropall(P PI) dropall(Q QI)
dropall(P v Q PI v QI) -
dropall(P PI) dropall(Q QI)
dropall(P P)
Step 8 Distributing conjunctions over disjunctions
distrib(P lt=gt Q PI lt=gt Ql) - t distrib(P PI) distrib(Q QI)
distrib(P v Q R) -
distrib(P PI) distrib(Q QI)
distributing(PI v QI R)
distrib(P it Q PI it QI) -
distrib(P PI) distrib( Q QI)
distrib(P P)
distributing((P amp Q) v R PI amp QI) -
distrib(P v R PI) distrib(Q v R Ql)
32
distributing(P v (Q amp R) PI amp Ql) -
distrib(P v Q PI) distrib(P v R Ql)
distributing(P P)
Step 9 Packing each conjunction into clauses
c1ausify(P amp Q CI C2) -
clausiCy(P CI C3) c1ausify(Q C3 C2)
cbusiCy(P [d(A B)ICs] Cs) shy
inclause(P A [j B [I) 1
c1ausiry( C C)
inclause(P v Q A AI B B1) -
inc1ause(P A2 AI B2 Bl)
inclause(Q A A2 B B2)
inclausenp) A A B1 B) -
notin(P A) putin(P B B1)
inclause(P AI A B B) shy
notin(P Bl putin(P A AI)
notin(X [XU) - fail
notin(X [JLj) - notin(X L)
notin(X 1])
putin(X II [X]) - 1
putin(X [XILJ L) -
putin(X [YILJ [YILl]) - putin(X L Ll)
Step 1Oa Printing clauses
printcl([]) - nl nl
printcl(c1(AB)ICsj) - printcl(A Bl nl printcl(Cs)
printcl(L II) - printdis(IL) prinr)middot
printclHl L) - prin(contradiction(() printconl(rL)
print()) - ) printconj(rL) prinr )
printcl(Ll L2) shy
printdis(ILl) print( - ) printconj(rL2) prin()
printdis(S[Lj) - printcbar(SL)
33
printdis(S[LILs]) - printchu(SL) prin( v) printdis(SLs)
printconl(S[LI) - printchar(SL)
printconl(S[LILs]) - printchar(SL) prin( ) printconl(SLs)
printconj(S[L]) - tab(3) printchar(SL)
prin tconj( S [L IL sl) shy
tab(3) printchar(SL) print( ) printconj(SLs)
printchar(SP) shy
atomic(P)
name(P L)
L = [IT]
concat([XIT NewP)
prin(~ewP)
printchar(SP) shy
atomic(P)
prin(P)
printchar(SA lt= gt B) -
prin((l clausify(A AI [j) pl(eAl) prin())
print lt=gt )
prin(() cbusify(B Bl [I) pJ(eBl) prine))middot
printchar(rnumber(X N)) shy
prin(num() printchar(rx) prin( )
printchar(rN) prinC))
printchar(rF(A B)) shy
seJec(F(A B))
prinCsel() printchar(rA)
prin( F ) printchar(rB) prinC))
printchar(SF(A B)) shy
( selec(F(A B)) F = infix )
printchar(SA) prin( F ) printchar(SB)
printchar(SF(A)) shy
(F= prefix gt= F= prefix lt= F= prefixgt F= prefix lt )
prin(F ) printcbar(SA)
printchar(SP) shy
functor(P F MaxN)
prin(F ()
Nl is MaxN - 1
putout(S N 1 P MaxN)
34
prin())
putout(S 0 P MaxN) -
arg(~laxN P Argu)
prin tchar(SArgu)
putout(S N p MaxN) shy
Nt is MaxN - N arg(NI P Argu)
printcbar(SArgu )
prin( )
N2 is N - 1
putout(S N2 P MaxN)
selec(FA B)) shy
( F= infix = F= infix f= F= infix gt=
F= infix gt F= infix lt= F= infix lt )
35
----------------------------------Program Name APClS - Part 2 Inference Mechanism ---------------------------------- a(X) shy
steps(X X9)
(( X9 =[] nl
print( yes it is always true) )
( X9 =[cI(IJ[])] nl
print( no it is always false) )
( nl nl printel(X9) Step 1Oa
tell(temp_file) printel(X9) e1ose(temp_file) consult(temp_6Ie) ))
q(X) shy
asserta( in pt(X))
steps(X X9)
(( X9 = [] print(middot~H~~middot~t~)
print(THE AiSWER IS YES)
print( ilgIQlQl(~) )
( X9 = [e1([j [j)] Pr1nt ( OJ fi(i I~ iii Ij)middot(i)(i) fiyenQ)riiio(i)(ij)(i)fj)fiyen1li1il1li1il)__ gtw~ __~_~ _~~_ ~_-=~
print(THE ANSWER IS NO ) print() )
( teI1(temp_6Ie)
prques(X9) Step 1Ob
close(temp_file)
nl print(Let me think about it) nl
consult(temp_6Ie) ))
retrac t( in pt(X))
Step lOb Printing question
prques(lcl(A 8)1) - prin(goo(() pl(qA 8) print()))
prques([c1(A 8HCs]) - prin(goo(() pl(qA 8) print() pl(q Cs)
pl(e [c1(A 8)]) - pl(eA 8)
pl(q [c1(A 8)]) - pl(qA 8) print()))
pl(S [e1(A B)ICs]) - pl(SA B) prin( ) pl(S Cs)
38
pl(q [j L) - prin(c1ause(contradiction(() pcont(qL) prin())_))
pl(S [I L)- prin(so2(contradidion(() pcont(SL) print))))middot
pl(S [L] []) - prin(so2() pcbar(SL) prin())
pl(S L [J)- prinsol() plett(SL) print))
pl(S [L] LI) - prin(condi(() pchar(cL)
prin(() pcont(S Ll) prine))))
pl(S L Ll)- prin(c1ause() plert(cL)
prin(() pcont(S Ll) prine)))
plert(S[LJ) - pchar(SL)
plert(SjLILsj) - pcbar(SL) print v) pleCt(SLs)
pcont(S[L]) - pchar(SL)
pcont(S[LILsj) - pcbar(SL) prinr ) pcont(SLs)
pcbar(SP) shy
atomic(P)
name(PL)
( L = [IT] L = [5 k miT] L = [5 k niT] )
concat[XITj NewP)
prin(0JewP)
pchar(SP) shy
atomic(P)
prin(P) pchar(SA lt=gt B) -
prin(() dausify(A AI []) pl(eAI) prin())
prinr lt=gt ) prin(() dausify(B BI ]) pl(eB) print))
pchar(Snumber(X N)) shy
prin(num() pchar(SX) prin()
pchar(SN) prinr))
pcbar(SM N) - prin(M N)
pcbar(cF(A B)) shy
selec(F(A Braquo
pcbar(cA)
prine F ) pchar(cB) pchar(SF(A B)) shy
selec(F(A B))
prin(sel() pchar(SA)
print F ) pchar(SB) print)) I
31
pc har(SF(A)) shy
( F= prefix gt= F= prefix lt= F= prefixgt F= prefix lt )
prin(F ) pchar(SA)
pchar(SP)shy
runctor(P F MaxN)
prin(F ()
011 is MaxN - 1 pout(SNl P MaxN)
print) )
pout(S 0 P M3xN) - 1
arg(~bxN P Argu)
pchlr(SArgu )
pout(S N P MaxN shy
Nl is MaxN - N
arg(Nl P Argu)
pchar(SArgu
prin( )
N2 is N - 1
pout(S N2 P ~13xN)
Comparing numbers in numerical quantifiers
num(XN) shy
number(X I)
cnum(N 1) ~
cnumlaquo=01 lt=I- N gt=I
cnumlaquo=J lt I) - N gt=1-1
cnumlaquo=NIJ) - N gt=J 1
cnumlaquo=N J)- integer(I) N gt=I~
cnum(gt=N gt=1) - N lt=1
cnum(gt=N gt I) - N lt=1+ 1 cnum(gt=NIJ) - N lt=1
cnum(gt=N lt=1)- N lt=1
cnum(gt=N lt I) - N lt=1 L cnum(gt=N 1)- integer(I) N lt=1
cnum( lt N lt 1)- N gt=1 L
38
cnum( lt N lt=1) - N gt I cnum( lt NLJ) - N gt J
cnum( lt N 1)- integer(I) N gt 1
cnum(gt N gt I) - N lt=1 cnumlgt i gt=1) - N lt I
cnum(gt N lt=1) - N lt=0
cnum(gt N lt I) - N lt=0
cnum(gt iIJ) - N lt I cnum(gt N 1)- integer(I) N lt I
cnum(~LN lt=1) - M=I N gt= I l
cnum(~LN lt I) - M=l N gt= I-I
cnum(~LNLJ) - M lt =1 N gt = J
cnum(~1N 1)- integer(I) M lt= I N gt= I
cnum(- N) - integer(N)
Comparing selectors
sel(X = Y) shyX= Y
sel(X I=Y) shy(X I=Y X lt Y Xgt Y)
sel(X gt Y) shyXgt Y
sel(X lt Y) shyXlt Y
selX gt=Y) shy(X gt=Y X= Y Xgt Y)
se(X lt=Y) shy
(X lt=Y
X= Y
X lt Y)
csel(infix = infix =)
39
csel(infix = infix = csel(infix = infix gt)
csel(infix = infix lt) csel(infix gt infix gt) cseJ(infix lt infix lt) csel(infix gt= infix gt=) csel(infix gt= infix gt csel(infix gt= infix =)
csellinfix lt= infix lt=) csel(infix lt= infix lt) csel(infix lt= infix =)
Finding solutions
sol(X v Y) -
(( notetra(X) eon(X) ( sol(Y) )
( c1ause(P v Q R) not(cketra(P v Q))
dis(P v Q X v Y R) ~ )
( A lt=gt B equival(A lt=gt B X v Y) ~ I) sol(X) - ~ notetra(X) eon(X)
so~(X) - notetra(X)
( con (X)
( clause(P v Q R) not(ekctra(P v Q)) dis(P v Q X R) I)
cketra(P v Q) -
eketra(P) eketra(Q) eketra(F(I J)) shy
selec(F(I J))
c1ause(contradiction(sel(F(IJ))) _I
eketra(number(W I)) -
clause(cootradietion(num(Wl)) - eketr(P) shy
clause(contradiction(P) - 1
notctra(P) shy
not( e lause( con tradiction(P) _))
40
Searching (or disjunctions
dis(P v Q X v Y R) - dis(P X v Y R)
dis(Q X v Y R) con(R)
dis(P v Q X R) -
dis(P X R) dis(Q X R) con(R
dis(P X v Y R) - clause(contradicton(Pl J 1
dis(F(I J) sel(G(I J)) v Y R) - csel(G Fl dis(number(WI) num(W N v Y R) - cnum(N I)
dis(P P v Y R) -
dis(P X v Y R) - dis(P Y R)
dis(F(I J) seJ(G(IJ)) R) - csel(G F)
dis(number(WI) num(WN) R) - cnum(N I) dis(P P R) - 1
dis(FJ J X R) shy
( ckctra(F(IJ) cbeckeq(seJ(F(IJ))) )
dis(number(W Il X R) - ( ckctra(number(WI)) cbeckeq(num(WI)) )
dis(P X R) shy( ckctra(P) cbeckeq(P) ) 1
cbeckeq(P) shy
(( A lt=gt so2(contradiction(P))
bagof(A A [jj) ) ( so2(contradiction(P)) lt=gt B
bagof(B B Uj) ))
ckeq(A) shy
( so2(A) lt=gt B B lt=gt so2(A) ) bagof(B B UJ)
con((P Q)) -
clause(P R) con(R) con(Q) con(true) -
con(contradiction(P)) - clause(contradiction(P) J
con(cause(X Y)) - cause(X Y)
con(sel(X)) - sel(X)
con(num(X Y)) - num(X Y) con(P)- (( dause(P R) (con(R) ckeq(R)))
colJectin(P) )
collectin(P) shy
bagof(S (c1ause(P S) S = true) [L LIJ )
mkcon(L Ll L)
bagor(l (L2 ) UJ) L
mkcon((A AI) (B B1) (sol(A v B) e D)) -
mkcon(A B1 e) mkcon(A1 (B Bl) D)
mkcon(A (B B1) (sol(A v B) e)) -
mkcon(A Bl e)
mkcon((A AI) B (sol(A v B) e)) middot1
mkcon(Al B e)
mkcon(A B sol(A vB))
Searching ror equivalences
equival(A lt=gt B X v Y) - 1 ( equival(A lt=gt B X) equival(A lt=gt B Y) )
equival(s02(A) lt=gt 502(B) A) - clause(B _I equival(s02(B) lt=gt 502(A) A) c1ause(B _I
Top level or inrerence mechanism
goo((s02(whatnum) P)) -
getatm(P Xl
bagor(number(X Y) ( P so2(number(X Y)) ) A )
count1(A 00 L R) nl
bagor(X P B )
count2(B L R Ll Rl) nJ print()
(( LI = 0 Rl = 0 print(THE ANSWER IS ) nl
(( Ll = Rl prin(-Jumber or ) prn(P) print(is Ll) )
( Rlgt20000 prin(Number or I prn(P) print(is LI or more) )
42
( prin(Number of ) pfn(P) print( is from Ll to Rl) )) )
( print(THE ANSWER IS NO I )) print()
goo(X) shy
(( bagof(X X L) L = [I nl print()
print(THE ANSWER IS YES) nl wout(L) print() )
( equiv(X L) nl print()
print(THE ANSWER IS YES) nl wout(L) print(-) )
( c1ause(inpt(A ==gt B) _I ( impli(A B Z) impli(B A Z) ) print(l~Hl)
printTHE ANSWER IS YES) nl print(Z) print(Hj~(fH~) ))
goo(X) print( Hg)
print(THE ANSWER IS NO ) print( lH~lH~gg9l9lmiddotmiddot~Q(gmiddot)
00 Semhing for implications in equiV3lent relations
impli( B Z) shyt-ell( z1) prin(templ() pchn(S A lt=gt B) print()) close ( zl) consult(zl) templ(Z)
unload zl Z
Searching for equivalence
equiv (X L)
(( X lt=gt Y
equ(Y YI)t bagof(Y Yl L) L = [j )
(Y lt=gt X equ(Y YI) bagof(Y Yl L) L = [J )
( X = F(New)
clause(~ew T) makeup(T Tl)
(( Tl lt=gt B
equ(B Bl) bagof(Bl Bl M) M = [j L=[Newl )
(A lt=gt TI
equ(A AI) bagof(Al AI M) M = 1] L=INewj )) ))
makeup((A B) (AI Bl)) -
makeup(A A1) makeup(B BI)
makeup(A so2(A))
equ((A B) (AI BI)) -
equ(A AI) equ(B Bl)
equ(sol(X v Y) sol(XI v Yl)) -
equ(X XI) equ(Y YI)
equ(so2(X) so2(XI)) -
equ(X XI)
equ(contradiction(X) clJuse(contradiction(X) X) ) -
equ(X X)
Counting numbers
getatm((A B) X) -
( getatm(A X) getatm(B X) )
getatm(so2(F(X)) X) -
getatm(so2(X) X) - atom(X)
countl([J L R L R) -
countl([number(X Y)IT] L R L2 R2) shy
(( Y = (gt=~) LI is L + N Rl is R + 20001 l )
( Y = (gt N) LI is L+ N+ 1 RI is R + 20002 )
(Y == laquo=~) LI is L + 1 Rl is R + N )
(Y = laquo N) LI is L + 1 RI is R+N-I)
(Y == IJ LI is L + I Rl is R + J ) ( Y == N L1 is L + N RI is R + N ))
count1(T LI R 1 L2 R2)
count2(fJ L R L R) - 1
count2([XITJ L R L2 R2) shy
name(X Xl)
(( Xl = sknj LI is L Rl is R )
44
( Xl = Iskmj L1 is L + 1 RI is R + ZOOO1) ( LI is L + I RI is R + I ))
count2(T LI RI L2 R2)
pfn((A B)) - pfn(A) prn(B)
pCn(so2(F(X))) - prin(F )
prn(so2(X)) - atom(X) prin(X ) prn (so2(X))
Printing result
wout([XlJ - prt(X) nl woutf[xIY]) - prt(X) nl nl wout(Y)
prt(e(A B)) -
prt(A) prinr 8 ) prt(ltE) prt(eA) - prt(A)
prt(c(A EJ) - prin() prt(A) prine ) prt(B) prin(T)
prt(c A) - prt(A) prt((A E)) - ~
prt(A) nl prt(E) prt(sol(X v Y)) - ~
prt(X) prinC v) prt(Y) prt(A lt=gt B) -
prt(e A) prinC lt=gt ) prt(e B) prt(sol(X)) - prt(X)
prt(so2(X)) - prt(X
prt(c1ause(X Y)) - prt(X)
prt(contradiction(X)) - prin(contradiction() prt(cX) prinr))middot prt(num(XY)) - prin(number(X Y)) prt(sel(X)) - prin(X) prt(X v Y) - prt(X) prin( v) prt(Y) prt(X) prin(X)
Handling conditional queries
condi((Y Xl) shy
assertcon(X) Y
45
retractcon(X)
condi((B A))
retractcon(A) fail
assertcon((A B)) 1
assertcon(A) assertcon(B)
assertcon(A) asserta(A)
retrac teon ((A B)) 1
retracteon(A) retractcon (B)
retraetcon(A) - retract(A)
BIBLIOGRAPHIC DATA SHEET
Report No UIUCDS-F-84-928
3 Recipients Accession No
4 T ide and Subt ltle
An Annotated Predicate Calculus Inference System (APCIS)
S Report Date
November 1984 6
7 Author(s)
Kah-Eng Pua 8 Performing Organization Rept
No
9 Performing Organization Name and Address
Department of Computer Science University of Illinois Urbana IL
10 ProjectTaskWork Unit No
11 Contract Grant No NSF DCR 84-06081 ONR N00014-82-K-0186
12 Sponsoring Organization Name and Address
National Science Foundation Washington DC
13 Type of Report amp Period Covered
14
15 Supplementary Notes
16 Abstracts
This paper describes a deductive inference system called APCIS (Annotated Predicate Calculus Inference System) APCIS is able to carry out inferences from expressions involving numerical quantifiers selectors disjunctions of non-negated terms negated terms disjunctions of negated terms equivalences and exceptions It is also able to count the numbers of occurrence of a given simple term or a conjunction of terms The design of contradiction and the treatment of the disjunction of non-negated terms allow APCIS to accept Horn clauses as well as non-Horn clauses and to carry out inferences from them This feature makes APCIS more general than Prolog
17 Key lords and Document Analysis 170 Descriptors
APC (Annotated Predicate Calculus) APCIS (Annotated Predicate Calculus Inference System) Horn Clause Numerical Quantifier Prolog Selector
17b IdentifiersOpen-Ended Terms
17c COSATI FieldGroup
18 Availability Statement 19 Security Class (This
Re~f~~IA~SIF IFf)
21 ~o of Pages
49 211 ecurity Class (This
PageUNCLASSIFIED
22 Price
FOA NTIS n (10middot70 usco-oc 40329-
28
Step 2 Removing implic3tions amp Transforming exceptions and equiv3lences
rmimpl( P - Q (PI lt=gt (QI) ) amp ((PI) lt=gt QI) ) -
rmimpl(P PI) rmimpl(Q QI)
rmimplnp) lt=gt Q (PI lt=gt -(QI)) amp nPI) lt=gt QI) ) - 1
rmimpl(P PI) rmimpJ(Q QI)
rmimpJ(P lt-gt -(Q) (PI lt=gt -(QI)) amp nPI) lt=gt QI) ) -
rmimpl(P PI) rmimpl(Q QI)
rmimpl( P lt=gt Q PI lt=gt QI ) - I
rmimpl(P PI) rmimpl(Q QI)
rmimpl( P ==gt Q -(PI) v QI ) - I
rmimpl(P PI) rmimpl(Q QI)
rmimpl( all(X P) aI(X PI) ) - 1
rmimpl(P PI)
rmimpl( exists(X P) exists(X PI) ) -
rmimpl(P PI)
rmimpl( exists(I X P) exists(I X PI) ) -
rmimpl(P PI)
rmimpl( P amp Q PI amp Ql ) -
rmimpl(P PI) rmimpl(Q Ql)
rmimpl( P v Q PI v QI ) -
rmimpl(P PI) rmimpl(Q QI)
rmimpl( -(p) -(PI) ) - I
rmimpl(p PI)
rmimpl( P P )
St~p 3 Converting numerical amp distinctive quantifiers
L Numerical quantifiers
examples of input forms
1 exists(gt= i X pIX)) where i is an integer
2 exists(i X pIX)) where i is an integer
3 exists(i j X pIX)) where i j are integers and iltj
4 exists(il v i2 X pIX)) where is are integers
examples of output forms of this step
1 exists(X pIX) amp number(X gt= i) )
2 exists(X pIX) amp number(X i) ) 3 exists(X pIX) amp number(X ij) ) 4 exists(X pIX) amp number(X il v i2) )
II Distinctive quantifiers
27
example or input Corm
exists([XYL p(X Y))
example or output Corm or this step
exists(X exists(Y p(XY)) )
conv(P lt=gt Q PI lt=gt QI) - 1
conv(P PI) conv(Q QI)
conv(al1(X P) all(X PI)) -
conv(P PI)
conv(exists(HIT] P) R ) - conv(P PI) convert distinctive quantifier
convtdis(exists([HIT]PI) R)
conv( exists(I X P) exists(X PIamp number(X I) )) -
conv(P PI) convert numerical quantifier
conv(exists(X P) exists(X PI)) - 1
conv(P Pl)
conv(P amp Q PI amp QI) - 1
conv(P PI) conv(Q QI)
conv(P v Q PI v QI) - t conv(P PI) conv(Q QI)
convC(P) -(PI)) -
conv(P PI)
conv(P Pl
convtdis(existsl[XL P) exists(X P)) - atomic(X) convtdis(exists[XIYj Pl exists(X R)) shy
convtdis(exists(Y P) R)
Step 4 Rewriting compound predicates andor compound selectors
Outputs are smiple predicates andor simple selectors
rewrite(P lt=gt Q PI lt=gt QI) - t rewrite(P PI) rewrite(Q QI)
rewrite(all(X Pl all(X PI)) - 1 rewrite(P PI)
rewriteexists(X P) exists(X PI)) - I rewriteP PI)
rewrite(P amp Q PI amp QI) - rewrite(P P 1) rewrite( Q Q 1
rewrite(P v Q PI v QI) - 1
rewrite(P PI) rewrite(Q QI)
rewriteC(P) -(PI)) - I
28
rewrite(P PI) rewrite(F(A B) R) -
rewrite(A AI) rewrite(B BI) re(F(AI BI) R)
rewrite(F(A) R) -
rewrite(A AI) re(F(AI) H)
rewrite(F(A B C) R) -
rewrite(A AI) rewrite(B BI) rewrite(C CI) re(F(AI BI CI) R)
rewrite(F(A B C D) R) -
rewrite(A AI) rewrite(B Btl rewrite(C CI) rewrite(D DI) rc(F(AI BI CI Dl) H)
rewrite(PP)
re(F(A B v el (RI v R2) -
re(F(A Bl RIl re(F(A C) R2) reF(A B amp cl (RI amp R2)) -
re(F(A B) RI) re(F(A e) R2) re(F(A amp B C) (Rl amp R2)) -
re(F(A e) R 1) re(F(B C) R 2) re(F( v B el (R I v R2)) -
re(F(A el R I) reFB el R2) re(F(A amp Bl (R I amp R2)) -
re(F(A RI) re(F(BJH2) re(F(A v B) (R 1 v R2)) -
re(F(A) RI) re(F(B) R2)
re(F(A vB c Dl (RI v R2) -
re(F(A C D) RI) re(F(B C D) R2) re(F(A amp B C D) (RI amp R2)) -
re(F(A C D) Rll re(F(B C D) R2) re(F(A B v C D) (HI v R2)) -
re(F(A B D) RI) re(F(A C D) R2) re(F(A B amp C D) (HI amp R2)) -
re(F(A B D) RI) re(F(A C D) R2) re(F(A B C v D) (RI v R2)) -
re(F(A B C) R I) reF(A B D) R2) re(F(A B C amp D) (RI amp R2)) -
29
re(F(A B C) RI) re(F(A B D) RZ)
re(F(A v B e D E) (R I v R2)) -
re(F(A e D E) R I) re(F(B e D El R2) re(F(A amp B e D E) (RI amp RZ)) -
re(F(A e D El R 1) re(F(B e D E) R2) re(F(A B v e D E) (R I v R2)) -
re(F(A B D E) RI) re(F(A e D E) R2)
re(F(A B amp e D E) (RI amp R2)) -
re(F(A B D El RI) re(F(A e D E) RZ) re(F(A B e v D E) (R I v R2)) -
re(F(A B e El R 1) re(F(A B D E) RZ) re(F(A B e amp D E) (RI amp RZ)) -
re(F(A B e E) R I) re(F(A B D E) RZ)
re(F(A B e D vEl (RI v RZ)) - l
rc(F(A B C D) RI) re(F(A n e El RZ) re(F(A B e D amp El (RI amp RZ)) - ~
re(F(A B e D) RI) re(F(A B e El RZ)
re((A = B) (A = B)l-
re((A = Bl (A = 8)) -
retIA gt= BI (A gt= B)) -
re((A lt= B) (A lt= B)) -
re((A gt B) (A gt B))-
re((A lt Bl (A lt Bl)- re(A A)
Step) Bringing n(gation inwards
Degin(-(P) PI) - neg(P Pl)
negin(P lt=gt Q PI lt=gt Ql) - ~
negin(P PI) negiD(Q QI)
Degin(aU(X P) all(X PI)) - Degin(P PI) negin(exists(X P) exists(X PI))- negin(P PI) negin(P amp Q PI amp Ql) - Degin(P PI) negin(Q Ql)
Degin(P v Q PI v QI) - Degin(P PI) negin(Q QI) negin(P Pl
neg(-(P) PI) - negin(P PI)
neg(all(X P) exists(X PI)) - neg(P PI)
30
neg(exists(X P) all(X PI)) - neg(P PI)
neg(P amp Q PI v QI) - neg(P PI) neg(Q Ql)
neg(P v Q PI amp QI) - neg(P PI) neg(Q QI)
neg(P -(PH
Step 6 Dropping existnetial quanti6ers
dropexist(P lt=gt Q PI lt=gt QI Elerns) - dropexist(P PI Elerns) dropexist(Q QI Elerns)
dropexist(alJ(X P) all(XPI) Elerns)
dropexist(P PI [XIElernsJ)
dropexist(exists(X P amp nurnber(X Yraquo P2 Elerns) -
genfun(skn Newg) Fun = [NewgIElerns]
subst(FuD X P amp Dumber(X Y) PI)
dropexist(Pl P2 Elerns)
dropexist(exists(X P) PZ Elerns) -
genfun(skrn Newf) Fun = [NewfIElernsJ
subst(Fun X p PI)
dropex ist(P 1 P~ Elerns)
dropexist(P v Q PI v QI Elerns) - ~
dropexist(P PI Elerns) dropexist(Q Ql Elerns)
dropexist(P amp Q PI amp QI Elerns) - 1
dropexist(P Pl Elerns) dropexist(Q QI Elerns)
dropexist(P P _)
gen fun(R oot Newn arne) shy
getnurn(Root Nurn)
narne(Root Rootlist)
append(Rootlist[Nurnj Narnelist)
concat(Narnelist Newnarne)
getnurn(Root Nurn) shy
retract(currentnurn(Root Nurn 1 raquo
Nurn is Nurni + 1
asserta(currentnurn(Root Nurn))
getnurn(Root 1) - asserta(currentnurn(Root 1))
subst(New Old Val Val) - var(Val)
subst(New Old Old New) - 1 substNew Old Val Val) - atornic(Val)
31
subst(New Old Val Newval) shy
runctor(Val F N)
CUDctor(Newval F N)
subst_args(N New Old Val Newval)
subst_args(O J J - J J
subst_args(N New Old Val NewVal) shy
arg(N Val OldArg)
arg(N NewVal NewArg)
subst(New Old OldArg NewArg)
NI is N - I
subst_args(Nl New Old Val NewVal)
append([J L L) -
append([XILl] L2 [XIL3]) - append(Ll L2 L3)
Step - Dropping universal quantifiers
dropall(P lt=gt Q PI lt=gt QI)-
dropall(P PI) dropall(Q QI)
dropall(all(X P) PI) - ~ dropall(P PI)
dropall(P amp Q PI amp QI) -
dropall(P PI) dropall(Q QI)
dropall(P v Q PI v QI) -
dropall(P PI) dropall(Q QI)
dropall(P P)
Step 8 Distributing conjunctions over disjunctions
distrib(P lt=gt Q PI lt=gt Ql) - t distrib(P PI) distrib(Q QI)
distrib(P v Q R) -
distrib(P PI) distrib(Q QI)
distributing(PI v QI R)
distrib(P it Q PI it QI) -
distrib(P PI) distrib( Q QI)
distrib(P P)
distributing((P amp Q) v R PI amp QI) -
distrib(P v R PI) distrib(Q v R Ql)
32
distributing(P v (Q amp R) PI amp Ql) -
distrib(P v Q PI) distrib(P v R Ql)
distributing(P P)
Step 9 Packing each conjunction into clauses
c1ausify(P amp Q CI C2) -
clausiCy(P CI C3) c1ausify(Q C3 C2)
cbusiCy(P [d(A B)ICs] Cs) shy
inclause(P A [j B [I) 1
c1ausiry( C C)
inclause(P v Q A AI B B1) -
inc1ause(P A2 AI B2 Bl)
inclause(Q A A2 B B2)
inclausenp) A A B1 B) -
notin(P A) putin(P B B1)
inclause(P AI A B B) shy
notin(P Bl putin(P A AI)
notin(X [XU) - fail
notin(X [JLj) - notin(X L)
notin(X 1])
putin(X II [X]) - 1
putin(X [XILJ L) -
putin(X [YILJ [YILl]) - putin(X L Ll)
Step 1Oa Printing clauses
printcl([]) - nl nl
printcl(c1(AB)ICsj) - printcl(A Bl nl printcl(Cs)
printcl(L II) - printdis(IL) prinr)middot
printclHl L) - prin(contradiction(() printconl(rL)
print()) - ) printconj(rL) prinr )
printcl(Ll L2) shy
printdis(ILl) print( - ) printconj(rL2) prin()
printdis(S[Lj) - printcbar(SL)
33
printdis(S[LILs]) - printchu(SL) prin( v) printdis(SLs)
printconl(S[LI) - printchar(SL)
printconl(S[LILs]) - printchar(SL) prin( ) printconl(SLs)
printconj(S[L]) - tab(3) printchar(SL)
prin tconj( S [L IL sl) shy
tab(3) printchar(SL) print( ) printconj(SLs)
printchar(SP) shy
atomic(P)
name(P L)
L = [IT]
concat([XIT NewP)
prin(~ewP)
printchar(SP) shy
atomic(P)
prin(P)
printchar(SA lt= gt B) -
prin((l clausify(A AI [j) pl(eAl) prin())
print lt=gt )
prin(() cbusify(B Bl [I) pJ(eBl) prine))middot
printchar(rnumber(X N)) shy
prin(num() printchar(rx) prin( )
printchar(rN) prinC))
printchar(rF(A B)) shy
seJec(F(A B))
prinCsel() printchar(rA)
prin( F ) printchar(rB) prinC))
printchar(SF(A B)) shy
( selec(F(A B)) F = infix )
printchar(SA) prin( F ) printchar(SB)
printchar(SF(A)) shy
(F= prefix gt= F= prefix lt= F= prefixgt F= prefix lt )
prin(F ) printcbar(SA)
printchar(SP) shy
functor(P F MaxN)
prin(F ()
Nl is MaxN - 1
putout(S N 1 P MaxN)
34
prin())
putout(S 0 P MaxN) -
arg(~laxN P Argu)
prin tchar(SArgu)
putout(S N p MaxN) shy
Nt is MaxN - N arg(NI P Argu)
printcbar(SArgu )
prin( )
N2 is N - 1
putout(S N2 P MaxN)
selec(FA B)) shy
( F= infix = F= infix f= F= infix gt=
F= infix gt F= infix lt= F= infix lt )
35
----------------------------------Program Name APClS - Part 2 Inference Mechanism ---------------------------------- a(X) shy
steps(X X9)
(( X9 =[] nl
print( yes it is always true) )
( X9 =[cI(IJ[])] nl
print( no it is always false) )
( nl nl printel(X9) Step 1Oa
tell(temp_file) printel(X9) e1ose(temp_file) consult(temp_6Ie) ))
q(X) shy
asserta( in pt(X))
steps(X X9)
(( X9 = [] print(middot~H~~middot~t~)
print(THE AiSWER IS YES)
print( ilgIQlQl(~) )
( X9 = [e1([j [j)] Pr1nt ( OJ fi(i I~ iii Ij)middot(i)(i) fiyenQ)riiio(i)(ij)(i)fj)fiyen1li1il1li1il)__ gtw~ __~_~ _~~_ ~_-=~
print(THE ANSWER IS NO ) print() )
( teI1(temp_6Ie)
prques(X9) Step 1Ob
close(temp_file)
nl print(Let me think about it) nl
consult(temp_6Ie) ))
retrac t( in pt(X))
Step lOb Printing question
prques(lcl(A 8)1) - prin(goo(() pl(qA 8) print()))
prques([c1(A 8HCs]) - prin(goo(() pl(qA 8) print() pl(q Cs)
pl(e [c1(A 8)]) - pl(eA 8)
pl(q [c1(A 8)]) - pl(qA 8) print()))
pl(S [e1(A B)ICs]) - pl(SA B) prin( ) pl(S Cs)
38
pl(q [j L) - prin(c1ause(contradiction(() pcont(qL) prin())_))
pl(S [I L)- prin(so2(contradidion(() pcont(SL) print))))middot
pl(S [L] []) - prin(so2() pcbar(SL) prin())
pl(S L [J)- prinsol() plett(SL) print))
pl(S [L] LI) - prin(condi(() pchar(cL)
prin(() pcont(S Ll) prine))))
pl(S L Ll)- prin(c1ause() plert(cL)
prin(() pcont(S Ll) prine)))
plert(S[LJ) - pchar(SL)
plert(SjLILsj) - pcbar(SL) print v) pleCt(SLs)
pcont(S[L]) - pchar(SL)
pcont(S[LILsj) - pcbar(SL) prinr ) pcont(SLs)
pcbar(SP) shy
atomic(P)
name(PL)
( L = [IT] L = [5 k miT] L = [5 k niT] )
concat[XITj NewP)
prin(0JewP)
pchar(SP) shy
atomic(P)
prin(P) pchar(SA lt=gt B) -
prin(() dausify(A AI []) pl(eAI) prin())
prinr lt=gt ) prin(() dausify(B BI ]) pl(eB) print))
pchar(Snumber(X N)) shy
prin(num() pchar(SX) prin()
pchar(SN) prinr))
pcbar(SM N) - prin(M N)
pcbar(cF(A B)) shy
selec(F(A Braquo
pcbar(cA)
prine F ) pchar(cB) pchar(SF(A B)) shy
selec(F(A B))
prin(sel() pchar(SA)
print F ) pchar(SB) print)) I
31
pc har(SF(A)) shy
( F= prefix gt= F= prefix lt= F= prefixgt F= prefix lt )
prin(F ) pchar(SA)
pchar(SP)shy
runctor(P F MaxN)
prin(F ()
011 is MaxN - 1 pout(SNl P MaxN)
print) )
pout(S 0 P M3xN) - 1
arg(~bxN P Argu)
pchlr(SArgu )
pout(S N P MaxN shy
Nl is MaxN - N
arg(Nl P Argu)
pchar(SArgu
prin( )
N2 is N - 1
pout(S N2 P ~13xN)
Comparing numbers in numerical quantifiers
num(XN) shy
number(X I)
cnum(N 1) ~
cnumlaquo=01 lt=I- N gt=I
cnumlaquo=J lt I) - N gt=1-1
cnumlaquo=NIJ) - N gt=J 1
cnumlaquo=N J)- integer(I) N gt=I~
cnum(gt=N gt=1) - N lt=1
cnum(gt=N gt I) - N lt=1+ 1 cnum(gt=NIJ) - N lt=1
cnum(gt=N lt=1)- N lt=1
cnum(gt=N lt I) - N lt=1 L cnum(gt=N 1)- integer(I) N lt=1
cnum( lt N lt 1)- N gt=1 L
38
cnum( lt N lt=1) - N gt I cnum( lt NLJ) - N gt J
cnum( lt N 1)- integer(I) N gt 1
cnum(gt N gt I) - N lt=1 cnumlgt i gt=1) - N lt I
cnum(gt N lt=1) - N lt=0
cnum(gt N lt I) - N lt=0
cnum(gt iIJ) - N lt I cnum(gt N 1)- integer(I) N lt I
cnum(~LN lt=1) - M=I N gt= I l
cnum(~LN lt I) - M=l N gt= I-I
cnum(~LNLJ) - M lt =1 N gt = J
cnum(~1N 1)- integer(I) M lt= I N gt= I
cnum(- N) - integer(N)
Comparing selectors
sel(X = Y) shyX= Y
sel(X I=Y) shy(X I=Y X lt Y Xgt Y)
sel(X gt Y) shyXgt Y
sel(X lt Y) shyXlt Y
selX gt=Y) shy(X gt=Y X= Y Xgt Y)
se(X lt=Y) shy
(X lt=Y
X= Y
X lt Y)
csel(infix = infix =)
39
csel(infix = infix = csel(infix = infix gt)
csel(infix = infix lt) csel(infix gt infix gt) cseJ(infix lt infix lt) csel(infix gt= infix gt=) csel(infix gt= infix gt csel(infix gt= infix =)
csellinfix lt= infix lt=) csel(infix lt= infix lt) csel(infix lt= infix =)
Finding solutions
sol(X v Y) -
(( notetra(X) eon(X) ( sol(Y) )
( c1ause(P v Q R) not(cketra(P v Q))
dis(P v Q X v Y R) ~ )
( A lt=gt B equival(A lt=gt B X v Y) ~ I) sol(X) - ~ notetra(X) eon(X)
so~(X) - notetra(X)
( con (X)
( clause(P v Q R) not(ekctra(P v Q)) dis(P v Q X R) I)
cketra(P v Q) -
eketra(P) eketra(Q) eketra(F(I J)) shy
selec(F(I J))
c1ause(contradiction(sel(F(IJ))) _I
eketra(number(W I)) -
clause(cootradietion(num(Wl)) - eketr(P) shy
clause(contradiction(P) - 1
notctra(P) shy
not( e lause( con tradiction(P) _))
40
Searching (or disjunctions
dis(P v Q X v Y R) - dis(P X v Y R)
dis(Q X v Y R) con(R)
dis(P v Q X R) -
dis(P X R) dis(Q X R) con(R
dis(P X v Y R) - clause(contradicton(Pl J 1
dis(F(I J) sel(G(I J)) v Y R) - csel(G Fl dis(number(WI) num(W N v Y R) - cnum(N I)
dis(P P v Y R) -
dis(P X v Y R) - dis(P Y R)
dis(F(I J) seJ(G(IJ)) R) - csel(G F)
dis(number(WI) num(WN) R) - cnum(N I) dis(P P R) - 1
dis(FJ J X R) shy
( ckctra(F(IJ) cbeckeq(seJ(F(IJ))) )
dis(number(W Il X R) - ( ckctra(number(WI)) cbeckeq(num(WI)) )
dis(P X R) shy( ckctra(P) cbeckeq(P) ) 1
cbeckeq(P) shy
(( A lt=gt so2(contradiction(P))
bagof(A A [jj) ) ( so2(contradiction(P)) lt=gt B
bagof(B B Uj) ))
ckeq(A) shy
( so2(A) lt=gt B B lt=gt so2(A) ) bagof(B B UJ)
con((P Q)) -
clause(P R) con(R) con(Q) con(true) -
con(contradiction(P)) - clause(contradiction(P) J
con(cause(X Y)) - cause(X Y)
con(sel(X)) - sel(X)
con(num(X Y)) - num(X Y) con(P)- (( dause(P R) (con(R) ckeq(R)))
colJectin(P) )
collectin(P) shy
bagof(S (c1ause(P S) S = true) [L LIJ )
mkcon(L Ll L)
bagor(l (L2 ) UJ) L
mkcon((A AI) (B B1) (sol(A v B) e D)) -
mkcon(A B1 e) mkcon(A1 (B Bl) D)
mkcon(A (B B1) (sol(A v B) e)) -
mkcon(A Bl e)
mkcon((A AI) B (sol(A v B) e)) middot1
mkcon(Al B e)
mkcon(A B sol(A vB))
Searching ror equivalences
equival(A lt=gt B X v Y) - 1 ( equival(A lt=gt B X) equival(A lt=gt B Y) )
equival(s02(A) lt=gt 502(B) A) - clause(B _I equival(s02(B) lt=gt 502(A) A) c1ause(B _I
Top level or inrerence mechanism
goo((s02(whatnum) P)) -
getatm(P Xl
bagor(number(X Y) ( P so2(number(X Y)) ) A )
count1(A 00 L R) nl
bagor(X P B )
count2(B L R Ll Rl) nJ print()
(( LI = 0 Rl = 0 print(THE ANSWER IS ) nl
(( Ll = Rl prin(-Jumber or ) prn(P) print(is Ll) )
( Rlgt20000 prin(Number or I prn(P) print(is LI or more) )
42
( prin(Number of ) pfn(P) print( is from Ll to Rl) )) )
( print(THE ANSWER IS NO I )) print()
goo(X) shy
(( bagof(X X L) L = [I nl print()
print(THE ANSWER IS YES) nl wout(L) print() )
( equiv(X L) nl print()
print(THE ANSWER IS YES) nl wout(L) print(-) )
( c1ause(inpt(A ==gt B) _I ( impli(A B Z) impli(B A Z) ) print(l~Hl)
printTHE ANSWER IS YES) nl print(Z) print(Hj~(fH~) ))
goo(X) print( Hg)
print(THE ANSWER IS NO ) print( lH~lH~gg9l9lmiddotmiddot~Q(gmiddot)
00 Semhing for implications in equiV3lent relations
impli( B Z) shyt-ell( z1) prin(templ() pchn(S A lt=gt B) print()) close ( zl) consult(zl) templ(Z)
unload zl Z
Searching for equivalence
equiv (X L)
(( X lt=gt Y
equ(Y YI)t bagof(Y Yl L) L = [j )
(Y lt=gt X equ(Y YI) bagof(Y Yl L) L = [J )
( X = F(New)
clause(~ew T) makeup(T Tl)
(( Tl lt=gt B
equ(B Bl) bagof(Bl Bl M) M = [j L=[Newl )
(A lt=gt TI
equ(A AI) bagof(Al AI M) M = 1] L=INewj )) ))
makeup((A B) (AI Bl)) -
makeup(A A1) makeup(B BI)
makeup(A so2(A))
equ((A B) (AI BI)) -
equ(A AI) equ(B Bl)
equ(sol(X v Y) sol(XI v Yl)) -
equ(X XI) equ(Y YI)
equ(so2(X) so2(XI)) -
equ(X XI)
equ(contradiction(X) clJuse(contradiction(X) X) ) -
equ(X X)
Counting numbers
getatm((A B) X) -
( getatm(A X) getatm(B X) )
getatm(so2(F(X)) X) -
getatm(so2(X) X) - atom(X)
countl([J L R L R) -
countl([number(X Y)IT] L R L2 R2) shy
(( Y = (gt=~) LI is L + N Rl is R + 20001 l )
( Y = (gt N) LI is L+ N+ 1 RI is R + 20002 )
(Y == laquo=~) LI is L + 1 Rl is R + N )
(Y = laquo N) LI is L + 1 RI is R+N-I)
(Y == IJ LI is L + I Rl is R + J ) ( Y == N L1 is L + N RI is R + N ))
count1(T LI R 1 L2 R2)
count2(fJ L R L R) - 1
count2([XITJ L R L2 R2) shy
name(X Xl)
(( Xl = sknj LI is L Rl is R )
44
( Xl = Iskmj L1 is L + 1 RI is R + ZOOO1) ( LI is L + I RI is R + I ))
count2(T LI RI L2 R2)
pfn((A B)) - pfn(A) prn(B)
pCn(so2(F(X))) - prin(F )
prn(so2(X)) - atom(X) prin(X ) prn (so2(X))
Printing result
wout([XlJ - prt(X) nl woutf[xIY]) - prt(X) nl nl wout(Y)
prt(e(A B)) -
prt(A) prinr 8 ) prt(ltE) prt(eA) - prt(A)
prt(c(A EJ) - prin() prt(A) prine ) prt(B) prin(T)
prt(c A) - prt(A) prt((A E)) - ~
prt(A) nl prt(E) prt(sol(X v Y)) - ~
prt(X) prinC v) prt(Y) prt(A lt=gt B) -
prt(e A) prinC lt=gt ) prt(e B) prt(sol(X)) - prt(X)
prt(so2(X)) - prt(X
prt(c1ause(X Y)) - prt(X)
prt(contradiction(X)) - prin(contradiction() prt(cX) prinr))middot prt(num(XY)) - prin(number(X Y)) prt(sel(X)) - prin(X) prt(X v Y) - prt(X) prin( v) prt(Y) prt(X) prin(X)
Handling conditional queries
condi((Y Xl) shy
assertcon(X) Y
45
retractcon(X)
condi((B A))
retractcon(A) fail
assertcon((A B)) 1
assertcon(A) assertcon(B)
assertcon(A) asserta(A)
retrac teon ((A B)) 1
retracteon(A) retractcon (B)
retraetcon(A) - retract(A)
BIBLIOGRAPHIC DATA SHEET
Report No UIUCDS-F-84-928
3 Recipients Accession No
4 T ide and Subt ltle
An Annotated Predicate Calculus Inference System (APCIS)
S Report Date
November 1984 6
7 Author(s)
Kah-Eng Pua 8 Performing Organization Rept
No
9 Performing Organization Name and Address
Department of Computer Science University of Illinois Urbana IL
10 ProjectTaskWork Unit No
11 Contract Grant No NSF DCR 84-06081 ONR N00014-82-K-0186
12 Sponsoring Organization Name and Address
National Science Foundation Washington DC
13 Type of Report amp Period Covered
14
15 Supplementary Notes
16 Abstracts
This paper describes a deductive inference system called APCIS (Annotated Predicate Calculus Inference System) APCIS is able to carry out inferences from expressions involving numerical quantifiers selectors disjunctions of non-negated terms negated terms disjunctions of negated terms equivalences and exceptions It is also able to count the numbers of occurrence of a given simple term or a conjunction of terms The design of contradiction and the treatment of the disjunction of non-negated terms allow APCIS to accept Horn clauses as well as non-Horn clauses and to carry out inferences from them This feature makes APCIS more general than Prolog
17 Key lords and Document Analysis 170 Descriptors
APC (Annotated Predicate Calculus) APCIS (Annotated Predicate Calculus Inference System) Horn Clause Numerical Quantifier Prolog Selector
17b IdentifiersOpen-Ended Terms
17c COSATI FieldGroup
18 Availability Statement 19 Security Class (This
Re~f~~IA~SIF IFf)
21 ~o of Pages
49 211 ecurity Class (This
PageUNCLASSIFIED
22 Price
FOA NTIS n (10middot70 usco-oc 40329-
27
example or input Corm
exists([XYL p(X Y))
example or output Corm or this step
exists(X exists(Y p(XY)) )
conv(P lt=gt Q PI lt=gt QI) - 1
conv(P PI) conv(Q QI)
conv(al1(X P) all(X PI)) -
conv(P PI)
conv(exists(HIT] P) R ) - conv(P PI) convert distinctive quantifier
convtdis(exists([HIT]PI) R)
conv( exists(I X P) exists(X PIamp number(X I) )) -
conv(P PI) convert numerical quantifier
conv(exists(X P) exists(X PI)) - 1
conv(P Pl)
conv(P amp Q PI amp QI) - 1
conv(P PI) conv(Q QI)
conv(P v Q PI v QI) - t conv(P PI) conv(Q QI)
convC(P) -(PI)) -
conv(P PI)
conv(P Pl
convtdis(existsl[XL P) exists(X P)) - atomic(X) convtdis(exists[XIYj Pl exists(X R)) shy
convtdis(exists(Y P) R)
Step 4 Rewriting compound predicates andor compound selectors
Outputs are smiple predicates andor simple selectors
rewrite(P lt=gt Q PI lt=gt QI) - t rewrite(P PI) rewrite(Q QI)
rewrite(all(X Pl all(X PI)) - 1 rewrite(P PI)
rewriteexists(X P) exists(X PI)) - I rewriteP PI)
rewrite(P amp Q PI amp QI) - rewrite(P P 1) rewrite( Q Q 1
rewrite(P v Q PI v QI) - 1
rewrite(P PI) rewrite(Q QI)
rewriteC(P) -(PI)) - I
28
rewrite(P PI) rewrite(F(A B) R) -
rewrite(A AI) rewrite(B BI) re(F(AI BI) R)
rewrite(F(A) R) -
rewrite(A AI) re(F(AI) H)
rewrite(F(A B C) R) -
rewrite(A AI) rewrite(B BI) rewrite(C CI) re(F(AI BI CI) R)
rewrite(F(A B C D) R) -
rewrite(A AI) rewrite(B Btl rewrite(C CI) rewrite(D DI) rc(F(AI BI CI Dl) H)
rewrite(PP)
re(F(A B v el (RI v R2) -
re(F(A Bl RIl re(F(A C) R2) reF(A B amp cl (RI amp R2)) -
re(F(A B) RI) re(F(A e) R2) re(F(A amp B C) (Rl amp R2)) -
re(F(A e) R 1) re(F(B C) R 2) re(F( v B el (R I v R2)) -
re(F(A el R I) reFB el R2) re(F(A amp Bl (R I amp R2)) -
re(F(A RI) re(F(BJH2) re(F(A v B) (R 1 v R2)) -
re(F(A) RI) re(F(B) R2)
re(F(A vB c Dl (RI v R2) -
re(F(A C D) RI) re(F(B C D) R2) re(F(A amp B C D) (RI amp R2)) -
re(F(A C D) Rll re(F(B C D) R2) re(F(A B v C D) (HI v R2)) -
re(F(A B D) RI) re(F(A C D) R2) re(F(A B amp C D) (HI amp R2)) -
re(F(A B D) RI) re(F(A C D) R2) re(F(A B C v D) (RI v R2)) -
re(F(A B C) R I) reF(A B D) R2) re(F(A B C amp D) (RI amp R2)) -
29
re(F(A B C) RI) re(F(A B D) RZ)
re(F(A v B e D E) (R I v R2)) -
re(F(A e D E) R I) re(F(B e D El R2) re(F(A amp B e D E) (RI amp RZ)) -
re(F(A e D El R 1) re(F(B e D E) R2) re(F(A B v e D E) (R I v R2)) -
re(F(A B D E) RI) re(F(A e D E) R2)
re(F(A B amp e D E) (RI amp R2)) -
re(F(A B D El RI) re(F(A e D E) RZ) re(F(A B e v D E) (R I v R2)) -
re(F(A B e El R 1) re(F(A B D E) RZ) re(F(A B e amp D E) (RI amp RZ)) -
re(F(A B e E) R I) re(F(A B D E) RZ)
re(F(A B e D vEl (RI v RZ)) - l
rc(F(A B C D) RI) re(F(A n e El RZ) re(F(A B e D amp El (RI amp RZ)) - ~
re(F(A B e D) RI) re(F(A B e El RZ)
re((A = B) (A = B)l-
re((A = Bl (A = 8)) -
retIA gt= BI (A gt= B)) -
re((A lt= B) (A lt= B)) -
re((A gt B) (A gt B))-
re((A lt Bl (A lt Bl)- re(A A)
Step) Bringing n(gation inwards
Degin(-(P) PI) - neg(P Pl)
negin(P lt=gt Q PI lt=gt Ql) - ~
negin(P PI) negiD(Q QI)
Degin(aU(X P) all(X PI)) - Degin(P PI) negin(exists(X P) exists(X PI))- negin(P PI) negin(P amp Q PI amp Ql) - Degin(P PI) negin(Q Ql)
Degin(P v Q PI v QI) - Degin(P PI) negin(Q QI) negin(P Pl
neg(-(P) PI) - negin(P PI)
neg(all(X P) exists(X PI)) - neg(P PI)
30
neg(exists(X P) all(X PI)) - neg(P PI)
neg(P amp Q PI v QI) - neg(P PI) neg(Q Ql)
neg(P v Q PI amp QI) - neg(P PI) neg(Q QI)
neg(P -(PH
Step 6 Dropping existnetial quanti6ers
dropexist(P lt=gt Q PI lt=gt QI Elerns) - dropexist(P PI Elerns) dropexist(Q QI Elerns)
dropexist(alJ(X P) all(XPI) Elerns)
dropexist(P PI [XIElernsJ)
dropexist(exists(X P amp nurnber(X Yraquo P2 Elerns) -
genfun(skn Newg) Fun = [NewgIElerns]
subst(FuD X P amp Dumber(X Y) PI)
dropexist(Pl P2 Elerns)
dropexist(exists(X P) PZ Elerns) -
genfun(skrn Newf) Fun = [NewfIElernsJ
subst(Fun X p PI)
dropex ist(P 1 P~ Elerns)
dropexist(P v Q PI v QI Elerns) - ~
dropexist(P PI Elerns) dropexist(Q Ql Elerns)
dropexist(P amp Q PI amp QI Elerns) - 1
dropexist(P Pl Elerns) dropexist(Q QI Elerns)
dropexist(P P _)
gen fun(R oot Newn arne) shy
getnurn(Root Nurn)
narne(Root Rootlist)
append(Rootlist[Nurnj Narnelist)
concat(Narnelist Newnarne)
getnurn(Root Nurn) shy
retract(currentnurn(Root Nurn 1 raquo
Nurn is Nurni + 1
asserta(currentnurn(Root Nurn))
getnurn(Root 1) - asserta(currentnurn(Root 1))
subst(New Old Val Val) - var(Val)
subst(New Old Old New) - 1 substNew Old Val Val) - atornic(Val)
31
subst(New Old Val Newval) shy
runctor(Val F N)
CUDctor(Newval F N)
subst_args(N New Old Val Newval)
subst_args(O J J - J J
subst_args(N New Old Val NewVal) shy
arg(N Val OldArg)
arg(N NewVal NewArg)
subst(New Old OldArg NewArg)
NI is N - I
subst_args(Nl New Old Val NewVal)
append([J L L) -
append([XILl] L2 [XIL3]) - append(Ll L2 L3)
Step - Dropping universal quantifiers
dropall(P lt=gt Q PI lt=gt QI)-
dropall(P PI) dropall(Q QI)
dropall(all(X P) PI) - ~ dropall(P PI)
dropall(P amp Q PI amp QI) -
dropall(P PI) dropall(Q QI)
dropall(P v Q PI v QI) -
dropall(P PI) dropall(Q QI)
dropall(P P)
Step 8 Distributing conjunctions over disjunctions
distrib(P lt=gt Q PI lt=gt Ql) - t distrib(P PI) distrib(Q QI)
distrib(P v Q R) -
distrib(P PI) distrib(Q QI)
distributing(PI v QI R)
distrib(P it Q PI it QI) -
distrib(P PI) distrib( Q QI)
distrib(P P)
distributing((P amp Q) v R PI amp QI) -
distrib(P v R PI) distrib(Q v R Ql)
32
distributing(P v (Q amp R) PI amp Ql) -
distrib(P v Q PI) distrib(P v R Ql)
distributing(P P)
Step 9 Packing each conjunction into clauses
c1ausify(P amp Q CI C2) -
clausiCy(P CI C3) c1ausify(Q C3 C2)
cbusiCy(P [d(A B)ICs] Cs) shy
inclause(P A [j B [I) 1
c1ausiry( C C)
inclause(P v Q A AI B B1) -
inc1ause(P A2 AI B2 Bl)
inclause(Q A A2 B B2)
inclausenp) A A B1 B) -
notin(P A) putin(P B B1)
inclause(P AI A B B) shy
notin(P Bl putin(P A AI)
notin(X [XU) - fail
notin(X [JLj) - notin(X L)
notin(X 1])
putin(X II [X]) - 1
putin(X [XILJ L) -
putin(X [YILJ [YILl]) - putin(X L Ll)
Step 1Oa Printing clauses
printcl([]) - nl nl
printcl(c1(AB)ICsj) - printcl(A Bl nl printcl(Cs)
printcl(L II) - printdis(IL) prinr)middot
printclHl L) - prin(contradiction(() printconl(rL)
print()) - ) printconj(rL) prinr )
printcl(Ll L2) shy
printdis(ILl) print( - ) printconj(rL2) prin()
printdis(S[Lj) - printcbar(SL)
33
printdis(S[LILs]) - printchu(SL) prin( v) printdis(SLs)
printconl(S[LI) - printchar(SL)
printconl(S[LILs]) - printchar(SL) prin( ) printconl(SLs)
printconj(S[L]) - tab(3) printchar(SL)
prin tconj( S [L IL sl) shy
tab(3) printchar(SL) print( ) printconj(SLs)
printchar(SP) shy
atomic(P)
name(P L)
L = [IT]
concat([XIT NewP)
prin(~ewP)
printchar(SP) shy
atomic(P)
prin(P)
printchar(SA lt= gt B) -
prin((l clausify(A AI [j) pl(eAl) prin())
print lt=gt )
prin(() cbusify(B Bl [I) pJ(eBl) prine))middot
printchar(rnumber(X N)) shy
prin(num() printchar(rx) prin( )
printchar(rN) prinC))
printchar(rF(A B)) shy
seJec(F(A B))
prinCsel() printchar(rA)
prin( F ) printchar(rB) prinC))
printchar(SF(A B)) shy
( selec(F(A B)) F = infix )
printchar(SA) prin( F ) printchar(SB)
printchar(SF(A)) shy
(F= prefix gt= F= prefix lt= F= prefixgt F= prefix lt )
prin(F ) printcbar(SA)
printchar(SP) shy
functor(P F MaxN)
prin(F ()
Nl is MaxN - 1
putout(S N 1 P MaxN)
34
prin())
putout(S 0 P MaxN) -
arg(~laxN P Argu)
prin tchar(SArgu)
putout(S N p MaxN) shy
Nt is MaxN - N arg(NI P Argu)
printcbar(SArgu )
prin( )
N2 is N - 1
putout(S N2 P MaxN)
selec(FA B)) shy
( F= infix = F= infix f= F= infix gt=
F= infix gt F= infix lt= F= infix lt )
35
----------------------------------Program Name APClS - Part 2 Inference Mechanism ---------------------------------- a(X) shy
steps(X X9)
(( X9 =[] nl
print( yes it is always true) )
( X9 =[cI(IJ[])] nl
print( no it is always false) )
( nl nl printel(X9) Step 1Oa
tell(temp_file) printel(X9) e1ose(temp_file) consult(temp_6Ie) ))
q(X) shy
asserta( in pt(X))
steps(X X9)
(( X9 = [] print(middot~H~~middot~t~)
print(THE AiSWER IS YES)
print( ilgIQlQl(~) )
( X9 = [e1([j [j)] Pr1nt ( OJ fi(i I~ iii Ij)middot(i)(i) fiyenQ)riiio(i)(ij)(i)fj)fiyen1li1il1li1il)__ gtw~ __~_~ _~~_ ~_-=~
print(THE ANSWER IS NO ) print() )
( teI1(temp_6Ie)
prques(X9) Step 1Ob
close(temp_file)
nl print(Let me think about it) nl
consult(temp_6Ie) ))
retrac t( in pt(X))
Step lOb Printing question
prques(lcl(A 8)1) - prin(goo(() pl(qA 8) print()))
prques([c1(A 8HCs]) - prin(goo(() pl(qA 8) print() pl(q Cs)
pl(e [c1(A 8)]) - pl(eA 8)
pl(q [c1(A 8)]) - pl(qA 8) print()))
pl(S [e1(A B)ICs]) - pl(SA B) prin( ) pl(S Cs)
38
pl(q [j L) - prin(c1ause(contradiction(() pcont(qL) prin())_))
pl(S [I L)- prin(so2(contradidion(() pcont(SL) print))))middot
pl(S [L] []) - prin(so2() pcbar(SL) prin())
pl(S L [J)- prinsol() plett(SL) print))
pl(S [L] LI) - prin(condi(() pchar(cL)
prin(() pcont(S Ll) prine))))
pl(S L Ll)- prin(c1ause() plert(cL)
prin(() pcont(S Ll) prine)))
plert(S[LJ) - pchar(SL)
plert(SjLILsj) - pcbar(SL) print v) pleCt(SLs)
pcont(S[L]) - pchar(SL)
pcont(S[LILsj) - pcbar(SL) prinr ) pcont(SLs)
pcbar(SP) shy
atomic(P)
name(PL)
( L = [IT] L = [5 k miT] L = [5 k niT] )
concat[XITj NewP)
prin(0JewP)
pchar(SP) shy
atomic(P)
prin(P) pchar(SA lt=gt B) -
prin(() dausify(A AI []) pl(eAI) prin())
prinr lt=gt ) prin(() dausify(B BI ]) pl(eB) print))
pchar(Snumber(X N)) shy
prin(num() pchar(SX) prin()
pchar(SN) prinr))
pcbar(SM N) - prin(M N)
pcbar(cF(A B)) shy
selec(F(A Braquo
pcbar(cA)
prine F ) pchar(cB) pchar(SF(A B)) shy
selec(F(A B))
prin(sel() pchar(SA)
print F ) pchar(SB) print)) I
31
pc har(SF(A)) shy
( F= prefix gt= F= prefix lt= F= prefixgt F= prefix lt )
prin(F ) pchar(SA)
pchar(SP)shy
runctor(P F MaxN)
prin(F ()
011 is MaxN - 1 pout(SNl P MaxN)
print) )
pout(S 0 P M3xN) - 1
arg(~bxN P Argu)
pchlr(SArgu )
pout(S N P MaxN shy
Nl is MaxN - N
arg(Nl P Argu)
pchar(SArgu
prin( )
N2 is N - 1
pout(S N2 P ~13xN)
Comparing numbers in numerical quantifiers
num(XN) shy
number(X I)
cnum(N 1) ~
cnumlaquo=01 lt=I- N gt=I
cnumlaquo=J lt I) - N gt=1-1
cnumlaquo=NIJ) - N gt=J 1
cnumlaquo=N J)- integer(I) N gt=I~
cnum(gt=N gt=1) - N lt=1
cnum(gt=N gt I) - N lt=1+ 1 cnum(gt=NIJ) - N lt=1
cnum(gt=N lt=1)- N lt=1
cnum(gt=N lt I) - N lt=1 L cnum(gt=N 1)- integer(I) N lt=1
cnum( lt N lt 1)- N gt=1 L
38
cnum( lt N lt=1) - N gt I cnum( lt NLJ) - N gt J
cnum( lt N 1)- integer(I) N gt 1
cnum(gt N gt I) - N lt=1 cnumlgt i gt=1) - N lt I
cnum(gt N lt=1) - N lt=0
cnum(gt N lt I) - N lt=0
cnum(gt iIJ) - N lt I cnum(gt N 1)- integer(I) N lt I
cnum(~LN lt=1) - M=I N gt= I l
cnum(~LN lt I) - M=l N gt= I-I
cnum(~LNLJ) - M lt =1 N gt = J
cnum(~1N 1)- integer(I) M lt= I N gt= I
cnum(- N) - integer(N)
Comparing selectors
sel(X = Y) shyX= Y
sel(X I=Y) shy(X I=Y X lt Y Xgt Y)
sel(X gt Y) shyXgt Y
sel(X lt Y) shyXlt Y
selX gt=Y) shy(X gt=Y X= Y Xgt Y)
se(X lt=Y) shy
(X lt=Y
X= Y
X lt Y)
csel(infix = infix =)
39
csel(infix = infix = csel(infix = infix gt)
csel(infix = infix lt) csel(infix gt infix gt) cseJ(infix lt infix lt) csel(infix gt= infix gt=) csel(infix gt= infix gt csel(infix gt= infix =)
csellinfix lt= infix lt=) csel(infix lt= infix lt) csel(infix lt= infix =)
Finding solutions
sol(X v Y) -
(( notetra(X) eon(X) ( sol(Y) )
( c1ause(P v Q R) not(cketra(P v Q))
dis(P v Q X v Y R) ~ )
( A lt=gt B equival(A lt=gt B X v Y) ~ I) sol(X) - ~ notetra(X) eon(X)
so~(X) - notetra(X)
( con (X)
( clause(P v Q R) not(ekctra(P v Q)) dis(P v Q X R) I)
cketra(P v Q) -
eketra(P) eketra(Q) eketra(F(I J)) shy
selec(F(I J))
c1ause(contradiction(sel(F(IJ))) _I
eketra(number(W I)) -
clause(cootradietion(num(Wl)) - eketr(P) shy
clause(contradiction(P) - 1
notctra(P) shy
not( e lause( con tradiction(P) _))
40
Searching (or disjunctions
dis(P v Q X v Y R) - dis(P X v Y R)
dis(Q X v Y R) con(R)
dis(P v Q X R) -
dis(P X R) dis(Q X R) con(R
dis(P X v Y R) - clause(contradicton(Pl J 1
dis(F(I J) sel(G(I J)) v Y R) - csel(G Fl dis(number(WI) num(W N v Y R) - cnum(N I)
dis(P P v Y R) -
dis(P X v Y R) - dis(P Y R)
dis(F(I J) seJ(G(IJ)) R) - csel(G F)
dis(number(WI) num(WN) R) - cnum(N I) dis(P P R) - 1
dis(FJ J X R) shy
( ckctra(F(IJ) cbeckeq(seJ(F(IJ))) )
dis(number(W Il X R) - ( ckctra(number(WI)) cbeckeq(num(WI)) )
dis(P X R) shy( ckctra(P) cbeckeq(P) ) 1
cbeckeq(P) shy
(( A lt=gt so2(contradiction(P))
bagof(A A [jj) ) ( so2(contradiction(P)) lt=gt B
bagof(B B Uj) ))
ckeq(A) shy
( so2(A) lt=gt B B lt=gt so2(A) ) bagof(B B UJ)
con((P Q)) -
clause(P R) con(R) con(Q) con(true) -
con(contradiction(P)) - clause(contradiction(P) J
con(cause(X Y)) - cause(X Y)
con(sel(X)) - sel(X)
con(num(X Y)) - num(X Y) con(P)- (( dause(P R) (con(R) ckeq(R)))
colJectin(P) )
collectin(P) shy
bagof(S (c1ause(P S) S = true) [L LIJ )
mkcon(L Ll L)
bagor(l (L2 ) UJ) L
mkcon((A AI) (B B1) (sol(A v B) e D)) -
mkcon(A B1 e) mkcon(A1 (B Bl) D)
mkcon(A (B B1) (sol(A v B) e)) -
mkcon(A Bl e)
mkcon((A AI) B (sol(A v B) e)) middot1
mkcon(Al B e)
mkcon(A B sol(A vB))
Searching ror equivalences
equival(A lt=gt B X v Y) - 1 ( equival(A lt=gt B X) equival(A lt=gt B Y) )
equival(s02(A) lt=gt 502(B) A) - clause(B _I equival(s02(B) lt=gt 502(A) A) c1ause(B _I
Top level or inrerence mechanism
goo((s02(whatnum) P)) -
getatm(P Xl
bagor(number(X Y) ( P so2(number(X Y)) ) A )
count1(A 00 L R) nl
bagor(X P B )
count2(B L R Ll Rl) nJ print()
(( LI = 0 Rl = 0 print(THE ANSWER IS ) nl
(( Ll = Rl prin(-Jumber or ) prn(P) print(is Ll) )
( Rlgt20000 prin(Number or I prn(P) print(is LI or more) )
42
( prin(Number of ) pfn(P) print( is from Ll to Rl) )) )
( print(THE ANSWER IS NO I )) print()
goo(X) shy
(( bagof(X X L) L = [I nl print()
print(THE ANSWER IS YES) nl wout(L) print() )
( equiv(X L) nl print()
print(THE ANSWER IS YES) nl wout(L) print(-) )
( c1ause(inpt(A ==gt B) _I ( impli(A B Z) impli(B A Z) ) print(l~Hl)
printTHE ANSWER IS YES) nl print(Z) print(Hj~(fH~) ))
goo(X) print( Hg)
print(THE ANSWER IS NO ) print( lH~lH~gg9l9lmiddotmiddot~Q(gmiddot)
00 Semhing for implications in equiV3lent relations
impli( B Z) shyt-ell( z1) prin(templ() pchn(S A lt=gt B) print()) close ( zl) consult(zl) templ(Z)
unload zl Z
Searching for equivalence
equiv (X L)
(( X lt=gt Y
equ(Y YI)t bagof(Y Yl L) L = [j )
(Y lt=gt X equ(Y YI) bagof(Y Yl L) L = [J )
( X = F(New)
clause(~ew T) makeup(T Tl)
(( Tl lt=gt B
equ(B Bl) bagof(Bl Bl M) M = [j L=[Newl )
(A lt=gt TI
equ(A AI) bagof(Al AI M) M = 1] L=INewj )) ))
makeup((A B) (AI Bl)) -
makeup(A A1) makeup(B BI)
makeup(A so2(A))
equ((A B) (AI BI)) -
equ(A AI) equ(B Bl)
equ(sol(X v Y) sol(XI v Yl)) -
equ(X XI) equ(Y YI)
equ(so2(X) so2(XI)) -
equ(X XI)
equ(contradiction(X) clJuse(contradiction(X) X) ) -
equ(X X)
Counting numbers
getatm((A B) X) -
( getatm(A X) getatm(B X) )
getatm(so2(F(X)) X) -
getatm(so2(X) X) - atom(X)
countl([J L R L R) -
countl([number(X Y)IT] L R L2 R2) shy
(( Y = (gt=~) LI is L + N Rl is R + 20001 l )
( Y = (gt N) LI is L+ N+ 1 RI is R + 20002 )
(Y == laquo=~) LI is L + 1 Rl is R + N )
(Y = laquo N) LI is L + 1 RI is R+N-I)
(Y == IJ LI is L + I Rl is R + J ) ( Y == N L1 is L + N RI is R + N ))
count1(T LI R 1 L2 R2)
count2(fJ L R L R) - 1
count2([XITJ L R L2 R2) shy
name(X Xl)
(( Xl = sknj LI is L Rl is R )
44
( Xl = Iskmj L1 is L + 1 RI is R + ZOOO1) ( LI is L + I RI is R + I ))
count2(T LI RI L2 R2)
pfn((A B)) - pfn(A) prn(B)
pCn(so2(F(X))) - prin(F )
prn(so2(X)) - atom(X) prin(X ) prn (so2(X))
Printing result
wout([XlJ - prt(X) nl woutf[xIY]) - prt(X) nl nl wout(Y)
prt(e(A B)) -
prt(A) prinr 8 ) prt(ltE) prt(eA) - prt(A)
prt(c(A EJ) - prin() prt(A) prine ) prt(B) prin(T)
prt(c A) - prt(A) prt((A E)) - ~
prt(A) nl prt(E) prt(sol(X v Y)) - ~
prt(X) prinC v) prt(Y) prt(A lt=gt B) -
prt(e A) prinC lt=gt ) prt(e B) prt(sol(X)) - prt(X)
prt(so2(X)) - prt(X
prt(c1ause(X Y)) - prt(X)
prt(contradiction(X)) - prin(contradiction() prt(cX) prinr))middot prt(num(XY)) - prin(number(X Y)) prt(sel(X)) - prin(X) prt(X v Y) - prt(X) prin( v) prt(Y) prt(X) prin(X)
Handling conditional queries
condi((Y Xl) shy
assertcon(X) Y
45
retractcon(X)
condi((B A))
retractcon(A) fail
assertcon((A B)) 1
assertcon(A) assertcon(B)
assertcon(A) asserta(A)
retrac teon ((A B)) 1
retracteon(A) retractcon (B)
retraetcon(A) - retract(A)
BIBLIOGRAPHIC DATA SHEET
Report No UIUCDS-F-84-928
3 Recipients Accession No
4 T ide and Subt ltle
An Annotated Predicate Calculus Inference System (APCIS)
S Report Date
November 1984 6
7 Author(s)
Kah-Eng Pua 8 Performing Organization Rept
No
9 Performing Organization Name and Address
Department of Computer Science University of Illinois Urbana IL
10 ProjectTaskWork Unit No
11 Contract Grant No NSF DCR 84-06081 ONR N00014-82-K-0186
12 Sponsoring Organization Name and Address
National Science Foundation Washington DC
13 Type of Report amp Period Covered
14
15 Supplementary Notes
16 Abstracts
This paper describes a deductive inference system called APCIS (Annotated Predicate Calculus Inference System) APCIS is able to carry out inferences from expressions involving numerical quantifiers selectors disjunctions of non-negated terms negated terms disjunctions of negated terms equivalences and exceptions It is also able to count the numbers of occurrence of a given simple term or a conjunction of terms The design of contradiction and the treatment of the disjunction of non-negated terms allow APCIS to accept Horn clauses as well as non-Horn clauses and to carry out inferences from them This feature makes APCIS more general than Prolog
17 Key lords and Document Analysis 170 Descriptors
APC (Annotated Predicate Calculus) APCIS (Annotated Predicate Calculus Inference System) Horn Clause Numerical Quantifier Prolog Selector
17b IdentifiersOpen-Ended Terms
17c COSATI FieldGroup
18 Availability Statement 19 Security Class (This
Re~f~~IA~SIF IFf)
21 ~o of Pages
49 211 ecurity Class (This
PageUNCLASSIFIED
22 Price
FOA NTIS n (10middot70 usco-oc 40329-
28
rewrite(P PI) rewrite(F(A B) R) -
rewrite(A AI) rewrite(B BI) re(F(AI BI) R)
rewrite(F(A) R) -
rewrite(A AI) re(F(AI) H)
rewrite(F(A B C) R) -
rewrite(A AI) rewrite(B BI) rewrite(C CI) re(F(AI BI CI) R)
rewrite(F(A B C D) R) -
rewrite(A AI) rewrite(B Btl rewrite(C CI) rewrite(D DI) rc(F(AI BI CI Dl) H)
rewrite(PP)
re(F(A B v el (RI v R2) -
re(F(A Bl RIl re(F(A C) R2) reF(A B amp cl (RI amp R2)) -
re(F(A B) RI) re(F(A e) R2) re(F(A amp B C) (Rl amp R2)) -
re(F(A e) R 1) re(F(B C) R 2) re(F( v B el (R I v R2)) -
re(F(A el R I) reFB el R2) re(F(A amp Bl (R I amp R2)) -
re(F(A RI) re(F(BJH2) re(F(A v B) (R 1 v R2)) -
re(F(A) RI) re(F(B) R2)
re(F(A vB c Dl (RI v R2) -
re(F(A C D) RI) re(F(B C D) R2) re(F(A amp B C D) (RI amp R2)) -
re(F(A C D) Rll re(F(B C D) R2) re(F(A B v C D) (HI v R2)) -
re(F(A B D) RI) re(F(A C D) R2) re(F(A B amp C D) (HI amp R2)) -
re(F(A B D) RI) re(F(A C D) R2) re(F(A B C v D) (RI v R2)) -
re(F(A B C) R I) reF(A B D) R2) re(F(A B C amp D) (RI amp R2)) -
29
re(F(A B C) RI) re(F(A B D) RZ)
re(F(A v B e D E) (R I v R2)) -
re(F(A e D E) R I) re(F(B e D El R2) re(F(A amp B e D E) (RI amp RZ)) -
re(F(A e D El R 1) re(F(B e D E) R2) re(F(A B v e D E) (R I v R2)) -
re(F(A B D E) RI) re(F(A e D E) R2)
re(F(A B amp e D E) (RI amp R2)) -
re(F(A B D El RI) re(F(A e D E) RZ) re(F(A B e v D E) (R I v R2)) -
re(F(A B e El R 1) re(F(A B D E) RZ) re(F(A B e amp D E) (RI amp RZ)) -
re(F(A B e E) R I) re(F(A B D E) RZ)
re(F(A B e D vEl (RI v RZ)) - l
rc(F(A B C D) RI) re(F(A n e El RZ) re(F(A B e D amp El (RI amp RZ)) - ~
re(F(A B e D) RI) re(F(A B e El RZ)
re((A = B) (A = B)l-
re((A = Bl (A = 8)) -
retIA gt= BI (A gt= B)) -
re((A lt= B) (A lt= B)) -
re((A gt B) (A gt B))-
re((A lt Bl (A lt Bl)- re(A A)
Step) Bringing n(gation inwards
Degin(-(P) PI) - neg(P Pl)
negin(P lt=gt Q PI lt=gt Ql) - ~
negin(P PI) negiD(Q QI)
Degin(aU(X P) all(X PI)) - Degin(P PI) negin(exists(X P) exists(X PI))- negin(P PI) negin(P amp Q PI amp Ql) - Degin(P PI) negin(Q Ql)
Degin(P v Q PI v QI) - Degin(P PI) negin(Q QI) negin(P Pl
neg(-(P) PI) - negin(P PI)
neg(all(X P) exists(X PI)) - neg(P PI)
30
neg(exists(X P) all(X PI)) - neg(P PI)
neg(P amp Q PI v QI) - neg(P PI) neg(Q Ql)
neg(P v Q PI amp QI) - neg(P PI) neg(Q QI)
neg(P -(PH
Step 6 Dropping existnetial quanti6ers
dropexist(P lt=gt Q PI lt=gt QI Elerns) - dropexist(P PI Elerns) dropexist(Q QI Elerns)
dropexist(alJ(X P) all(XPI) Elerns)
dropexist(P PI [XIElernsJ)
dropexist(exists(X P amp nurnber(X Yraquo P2 Elerns) -
genfun(skn Newg) Fun = [NewgIElerns]
subst(FuD X P amp Dumber(X Y) PI)
dropexist(Pl P2 Elerns)
dropexist(exists(X P) PZ Elerns) -
genfun(skrn Newf) Fun = [NewfIElernsJ
subst(Fun X p PI)
dropex ist(P 1 P~ Elerns)
dropexist(P v Q PI v QI Elerns) - ~
dropexist(P PI Elerns) dropexist(Q Ql Elerns)
dropexist(P amp Q PI amp QI Elerns) - 1
dropexist(P Pl Elerns) dropexist(Q QI Elerns)
dropexist(P P _)
gen fun(R oot Newn arne) shy
getnurn(Root Nurn)
narne(Root Rootlist)
append(Rootlist[Nurnj Narnelist)
concat(Narnelist Newnarne)
getnurn(Root Nurn) shy
retract(currentnurn(Root Nurn 1 raquo
Nurn is Nurni + 1
asserta(currentnurn(Root Nurn))
getnurn(Root 1) - asserta(currentnurn(Root 1))
subst(New Old Val Val) - var(Val)
subst(New Old Old New) - 1 substNew Old Val Val) - atornic(Val)
31
subst(New Old Val Newval) shy
runctor(Val F N)
CUDctor(Newval F N)
subst_args(N New Old Val Newval)
subst_args(O J J - J J
subst_args(N New Old Val NewVal) shy
arg(N Val OldArg)
arg(N NewVal NewArg)
subst(New Old OldArg NewArg)
NI is N - I
subst_args(Nl New Old Val NewVal)
append([J L L) -
append([XILl] L2 [XIL3]) - append(Ll L2 L3)
Step - Dropping universal quantifiers
dropall(P lt=gt Q PI lt=gt QI)-
dropall(P PI) dropall(Q QI)
dropall(all(X P) PI) - ~ dropall(P PI)
dropall(P amp Q PI amp QI) -
dropall(P PI) dropall(Q QI)
dropall(P v Q PI v QI) -
dropall(P PI) dropall(Q QI)
dropall(P P)
Step 8 Distributing conjunctions over disjunctions
distrib(P lt=gt Q PI lt=gt Ql) - t distrib(P PI) distrib(Q QI)
distrib(P v Q R) -
distrib(P PI) distrib(Q QI)
distributing(PI v QI R)
distrib(P it Q PI it QI) -
distrib(P PI) distrib( Q QI)
distrib(P P)
distributing((P amp Q) v R PI amp QI) -
distrib(P v R PI) distrib(Q v R Ql)
32
distributing(P v (Q amp R) PI amp Ql) -
distrib(P v Q PI) distrib(P v R Ql)
distributing(P P)
Step 9 Packing each conjunction into clauses
c1ausify(P amp Q CI C2) -
clausiCy(P CI C3) c1ausify(Q C3 C2)
cbusiCy(P [d(A B)ICs] Cs) shy
inclause(P A [j B [I) 1
c1ausiry( C C)
inclause(P v Q A AI B B1) -
inc1ause(P A2 AI B2 Bl)
inclause(Q A A2 B B2)
inclausenp) A A B1 B) -
notin(P A) putin(P B B1)
inclause(P AI A B B) shy
notin(P Bl putin(P A AI)
notin(X [XU) - fail
notin(X [JLj) - notin(X L)
notin(X 1])
putin(X II [X]) - 1
putin(X [XILJ L) -
putin(X [YILJ [YILl]) - putin(X L Ll)
Step 1Oa Printing clauses
printcl([]) - nl nl
printcl(c1(AB)ICsj) - printcl(A Bl nl printcl(Cs)
printcl(L II) - printdis(IL) prinr)middot
printclHl L) - prin(contradiction(() printconl(rL)
print()) - ) printconj(rL) prinr )
printcl(Ll L2) shy
printdis(ILl) print( - ) printconj(rL2) prin()
printdis(S[Lj) - printcbar(SL)
33
printdis(S[LILs]) - printchu(SL) prin( v) printdis(SLs)
printconl(S[LI) - printchar(SL)
printconl(S[LILs]) - printchar(SL) prin( ) printconl(SLs)
printconj(S[L]) - tab(3) printchar(SL)
prin tconj( S [L IL sl) shy
tab(3) printchar(SL) print( ) printconj(SLs)
printchar(SP) shy
atomic(P)
name(P L)
L = [IT]
concat([XIT NewP)
prin(~ewP)
printchar(SP) shy
atomic(P)
prin(P)
printchar(SA lt= gt B) -
prin((l clausify(A AI [j) pl(eAl) prin())
print lt=gt )
prin(() cbusify(B Bl [I) pJ(eBl) prine))middot
printchar(rnumber(X N)) shy
prin(num() printchar(rx) prin( )
printchar(rN) prinC))
printchar(rF(A B)) shy
seJec(F(A B))
prinCsel() printchar(rA)
prin( F ) printchar(rB) prinC))
printchar(SF(A B)) shy
( selec(F(A B)) F = infix )
printchar(SA) prin( F ) printchar(SB)
printchar(SF(A)) shy
(F= prefix gt= F= prefix lt= F= prefixgt F= prefix lt )
prin(F ) printcbar(SA)
printchar(SP) shy
functor(P F MaxN)
prin(F ()
Nl is MaxN - 1
putout(S N 1 P MaxN)
34
prin())
putout(S 0 P MaxN) -
arg(~laxN P Argu)
prin tchar(SArgu)
putout(S N p MaxN) shy
Nt is MaxN - N arg(NI P Argu)
printcbar(SArgu )
prin( )
N2 is N - 1
putout(S N2 P MaxN)
selec(FA B)) shy
( F= infix = F= infix f= F= infix gt=
F= infix gt F= infix lt= F= infix lt )
35
----------------------------------Program Name APClS - Part 2 Inference Mechanism ---------------------------------- a(X) shy
steps(X X9)
(( X9 =[] nl
print( yes it is always true) )
( X9 =[cI(IJ[])] nl
print( no it is always false) )
( nl nl printel(X9) Step 1Oa
tell(temp_file) printel(X9) e1ose(temp_file) consult(temp_6Ie) ))
q(X) shy
asserta( in pt(X))
steps(X X9)
(( X9 = [] print(middot~H~~middot~t~)
print(THE AiSWER IS YES)
print( ilgIQlQl(~) )
( X9 = [e1([j [j)] Pr1nt ( OJ fi(i I~ iii Ij)middot(i)(i) fiyenQ)riiio(i)(ij)(i)fj)fiyen1li1il1li1il)__ gtw~ __~_~ _~~_ ~_-=~
print(THE ANSWER IS NO ) print() )
( teI1(temp_6Ie)
prques(X9) Step 1Ob
close(temp_file)
nl print(Let me think about it) nl
consult(temp_6Ie) ))
retrac t( in pt(X))
Step lOb Printing question
prques(lcl(A 8)1) - prin(goo(() pl(qA 8) print()))
prques([c1(A 8HCs]) - prin(goo(() pl(qA 8) print() pl(q Cs)
pl(e [c1(A 8)]) - pl(eA 8)
pl(q [c1(A 8)]) - pl(qA 8) print()))
pl(S [e1(A B)ICs]) - pl(SA B) prin( ) pl(S Cs)
38
pl(q [j L) - prin(c1ause(contradiction(() pcont(qL) prin())_))
pl(S [I L)- prin(so2(contradidion(() pcont(SL) print))))middot
pl(S [L] []) - prin(so2() pcbar(SL) prin())
pl(S L [J)- prinsol() plett(SL) print))
pl(S [L] LI) - prin(condi(() pchar(cL)
prin(() pcont(S Ll) prine))))
pl(S L Ll)- prin(c1ause() plert(cL)
prin(() pcont(S Ll) prine)))
plert(S[LJ) - pchar(SL)
plert(SjLILsj) - pcbar(SL) print v) pleCt(SLs)
pcont(S[L]) - pchar(SL)
pcont(S[LILsj) - pcbar(SL) prinr ) pcont(SLs)
pcbar(SP) shy
atomic(P)
name(PL)
( L = [IT] L = [5 k miT] L = [5 k niT] )
concat[XITj NewP)
prin(0JewP)
pchar(SP) shy
atomic(P)
prin(P) pchar(SA lt=gt B) -
prin(() dausify(A AI []) pl(eAI) prin())
prinr lt=gt ) prin(() dausify(B BI ]) pl(eB) print))
pchar(Snumber(X N)) shy
prin(num() pchar(SX) prin()
pchar(SN) prinr))
pcbar(SM N) - prin(M N)
pcbar(cF(A B)) shy
selec(F(A Braquo
pcbar(cA)
prine F ) pchar(cB) pchar(SF(A B)) shy
selec(F(A B))
prin(sel() pchar(SA)
print F ) pchar(SB) print)) I
31
pc har(SF(A)) shy
( F= prefix gt= F= prefix lt= F= prefixgt F= prefix lt )
prin(F ) pchar(SA)
pchar(SP)shy
runctor(P F MaxN)
prin(F ()
011 is MaxN - 1 pout(SNl P MaxN)
print) )
pout(S 0 P M3xN) - 1
arg(~bxN P Argu)
pchlr(SArgu )
pout(S N P MaxN shy
Nl is MaxN - N
arg(Nl P Argu)
pchar(SArgu
prin( )
N2 is N - 1
pout(S N2 P ~13xN)
Comparing numbers in numerical quantifiers
num(XN) shy
number(X I)
cnum(N 1) ~
cnumlaquo=01 lt=I- N gt=I
cnumlaquo=J lt I) - N gt=1-1
cnumlaquo=NIJ) - N gt=J 1
cnumlaquo=N J)- integer(I) N gt=I~
cnum(gt=N gt=1) - N lt=1
cnum(gt=N gt I) - N lt=1+ 1 cnum(gt=NIJ) - N lt=1
cnum(gt=N lt=1)- N lt=1
cnum(gt=N lt I) - N lt=1 L cnum(gt=N 1)- integer(I) N lt=1
cnum( lt N lt 1)- N gt=1 L
38
cnum( lt N lt=1) - N gt I cnum( lt NLJ) - N gt J
cnum( lt N 1)- integer(I) N gt 1
cnum(gt N gt I) - N lt=1 cnumlgt i gt=1) - N lt I
cnum(gt N lt=1) - N lt=0
cnum(gt N lt I) - N lt=0
cnum(gt iIJ) - N lt I cnum(gt N 1)- integer(I) N lt I
cnum(~LN lt=1) - M=I N gt= I l
cnum(~LN lt I) - M=l N gt= I-I
cnum(~LNLJ) - M lt =1 N gt = J
cnum(~1N 1)- integer(I) M lt= I N gt= I
cnum(- N) - integer(N)
Comparing selectors
sel(X = Y) shyX= Y
sel(X I=Y) shy(X I=Y X lt Y Xgt Y)
sel(X gt Y) shyXgt Y
sel(X lt Y) shyXlt Y
selX gt=Y) shy(X gt=Y X= Y Xgt Y)
se(X lt=Y) shy
(X lt=Y
X= Y
X lt Y)
csel(infix = infix =)
39
csel(infix = infix = csel(infix = infix gt)
csel(infix = infix lt) csel(infix gt infix gt) cseJ(infix lt infix lt) csel(infix gt= infix gt=) csel(infix gt= infix gt csel(infix gt= infix =)
csellinfix lt= infix lt=) csel(infix lt= infix lt) csel(infix lt= infix =)
Finding solutions
sol(X v Y) -
(( notetra(X) eon(X) ( sol(Y) )
( c1ause(P v Q R) not(cketra(P v Q))
dis(P v Q X v Y R) ~ )
( A lt=gt B equival(A lt=gt B X v Y) ~ I) sol(X) - ~ notetra(X) eon(X)
so~(X) - notetra(X)
( con (X)
( clause(P v Q R) not(ekctra(P v Q)) dis(P v Q X R) I)
cketra(P v Q) -
eketra(P) eketra(Q) eketra(F(I J)) shy
selec(F(I J))
c1ause(contradiction(sel(F(IJ))) _I
eketra(number(W I)) -
clause(cootradietion(num(Wl)) - eketr(P) shy
clause(contradiction(P) - 1
notctra(P) shy
not( e lause( con tradiction(P) _))
40
Searching (or disjunctions
dis(P v Q X v Y R) - dis(P X v Y R)
dis(Q X v Y R) con(R)
dis(P v Q X R) -
dis(P X R) dis(Q X R) con(R
dis(P X v Y R) - clause(contradicton(Pl J 1
dis(F(I J) sel(G(I J)) v Y R) - csel(G Fl dis(number(WI) num(W N v Y R) - cnum(N I)
dis(P P v Y R) -
dis(P X v Y R) - dis(P Y R)
dis(F(I J) seJ(G(IJ)) R) - csel(G F)
dis(number(WI) num(WN) R) - cnum(N I) dis(P P R) - 1
dis(FJ J X R) shy
( ckctra(F(IJ) cbeckeq(seJ(F(IJ))) )
dis(number(W Il X R) - ( ckctra(number(WI)) cbeckeq(num(WI)) )
dis(P X R) shy( ckctra(P) cbeckeq(P) ) 1
cbeckeq(P) shy
(( A lt=gt so2(contradiction(P))
bagof(A A [jj) ) ( so2(contradiction(P)) lt=gt B
bagof(B B Uj) ))
ckeq(A) shy
( so2(A) lt=gt B B lt=gt so2(A) ) bagof(B B UJ)
con((P Q)) -
clause(P R) con(R) con(Q) con(true) -
con(contradiction(P)) - clause(contradiction(P) J
con(cause(X Y)) - cause(X Y)
con(sel(X)) - sel(X)
con(num(X Y)) - num(X Y) con(P)- (( dause(P R) (con(R) ckeq(R)))
colJectin(P) )
collectin(P) shy
bagof(S (c1ause(P S) S = true) [L LIJ )
mkcon(L Ll L)
bagor(l (L2 ) UJ) L
mkcon((A AI) (B B1) (sol(A v B) e D)) -
mkcon(A B1 e) mkcon(A1 (B Bl) D)
mkcon(A (B B1) (sol(A v B) e)) -
mkcon(A Bl e)
mkcon((A AI) B (sol(A v B) e)) middot1
mkcon(Al B e)
mkcon(A B sol(A vB))
Searching ror equivalences
equival(A lt=gt B X v Y) - 1 ( equival(A lt=gt B X) equival(A lt=gt B Y) )
equival(s02(A) lt=gt 502(B) A) - clause(B _I equival(s02(B) lt=gt 502(A) A) c1ause(B _I
Top level or inrerence mechanism
goo((s02(whatnum) P)) -
getatm(P Xl
bagor(number(X Y) ( P so2(number(X Y)) ) A )
count1(A 00 L R) nl
bagor(X P B )
count2(B L R Ll Rl) nJ print()
(( LI = 0 Rl = 0 print(THE ANSWER IS ) nl
(( Ll = Rl prin(-Jumber or ) prn(P) print(is Ll) )
( Rlgt20000 prin(Number or I prn(P) print(is LI or more) )
42
( prin(Number of ) pfn(P) print( is from Ll to Rl) )) )
( print(THE ANSWER IS NO I )) print()
goo(X) shy
(( bagof(X X L) L = [I nl print()
print(THE ANSWER IS YES) nl wout(L) print() )
( equiv(X L) nl print()
print(THE ANSWER IS YES) nl wout(L) print(-) )
( c1ause(inpt(A ==gt B) _I ( impli(A B Z) impli(B A Z) ) print(l~Hl)
printTHE ANSWER IS YES) nl print(Z) print(Hj~(fH~) ))
goo(X) print( Hg)
print(THE ANSWER IS NO ) print( lH~lH~gg9l9lmiddotmiddot~Q(gmiddot)
00 Semhing for implications in equiV3lent relations
impli( B Z) shyt-ell( z1) prin(templ() pchn(S A lt=gt B) print()) close ( zl) consult(zl) templ(Z)
unload zl Z
Searching for equivalence
equiv (X L)
(( X lt=gt Y
equ(Y YI)t bagof(Y Yl L) L = [j )
(Y lt=gt X equ(Y YI) bagof(Y Yl L) L = [J )
( X = F(New)
clause(~ew T) makeup(T Tl)
(( Tl lt=gt B
equ(B Bl) bagof(Bl Bl M) M = [j L=[Newl )
(A lt=gt TI
equ(A AI) bagof(Al AI M) M = 1] L=INewj )) ))
makeup((A B) (AI Bl)) -
makeup(A A1) makeup(B BI)
makeup(A so2(A))
equ((A B) (AI BI)) -
equ(A AI) equ(B Bl)
equ(sol(X v Y) sol(XI v Yl)) -
equ(X XI) equ(Y YI)
equ(so2(X) so2(XI)) -
equ(X XI)
equ(contradiction(X) clJuse(contradiction(X) X) ) -
equ(X X)
Counting numbers
getatm((A B) X) -
( getatm(A X) getatm(B X) )
getatm(so2(F(X)) X) -
getatm(so2(X) X) - atom(X)
countl([J L R L R) -
countl([number(X Y)IT] L R L2 R2) shy
(( Y = (gt=~) LI is L + N Rl is R + 20001 l )
( Y = (gt N) LI is L+ N+ 1 RI is R + 20002 )
(Y == laquo=~) LI is L + 1 Rl is R + N )
(Y = laquo N) LI is L + 1 RI is R+N-I)
(Y == IJ LI is L + I Rl is R + J ) ( Y == N L1 is L + N RI is R + N ))
count1(T LI R 1 L2 R2)
count2(fJ L R L R) - 1
count2([XITJ L R L2 R2) shy
name(X Xl)
(( Xl = sknj LI is L Rl is R )
44
( Xl = Iskmj L1 is L + 1 RI is R + ZOOO1) ( LI is L + I RI is R + I ))
count2(T LI RI L2 R2)
pfn((A B)) - pfn(A) prn(B)
pCn(so2(F(X))) - prin(F )
prn(so2(X)) - atom(X) prin(X ) prn (so2(X))
Printing result
wout([XlJ - prt(X) nl woutf[xIY]) - prt(X) nl nl wout(Y)
prt(e(A B)) -
prt(A) prinr 8 ) prt(ltE) prt(eA) - prt(A)
prt(c(A EJ) - prin() prt(A) prine ) prt(B) prin(T)
prt(c A) - prt(A) prt((A E)) - ~
prt(A) nl prt(E) prt(sol(X v Y)) - ~
prt(X) prinC v) prt(Y) prt(A lt=gt B) -
prt(e A) prinC lt=gt ) prt(e B) prt(sol(X)) - prt(X)
prt(so2(X)) - prt(X
prt(c1ause(X Y)) - prt(X)
prt(contradiction(X)) - prin(contradiction() prt(cX) prinr))middot prt(num(XY)) - prin(number(X Y)) prt(sel(X)) - prin(X) prt(X v Y) - prt(X) prin( v) prt(Y) prt(X) prin(X)
Handling conditional queries
condi((Y Xl) shy
assertcon(X) Y
45
retractcon(X)
condi((B A))
retractcon(A) fail
assertcon((A B)) 1
assertcon(A) assertcon(B)
assertcon(A) asserta(A)
retrac teon ((A B)) 1
retracteon(A) retractcon (B)
retraetcon(A) - retract(A)
BIBLIOGRAPHIC DATA SHEET
Report No UIUCDS-F-84-928
3 Recipients Accession No
4 T ide and Subt ltle
An Annotated Predicate Calculus Inference System (APCIS)
S Report Date
November 1984 6
7 Author(s)
Kah-Eng Pua 8 Performing Organization Rept
No
9 Performing Organization Name and Address
Department of Computer Science University of Illinois Urbana IL
10 ProjectTaskWork Unit No
11 Contract Grant No NSF DCR 84-06081 ONR N00014-82-K-0186
12 Sponsoring Organization Name and Address
National Science Foundation Washington DC
13 Type of Report amp Period Covered
14
15 Supplementary Notes
16 Abstracts
This paper describes a deductive inference system called APCIS (Annotated Predicate Calculus Inference System) APCIS is able to carry out inferences from expressions involving numerical quantifiers selectors disjunctions of non-negated terms negated terms disjunctions of negated terms equivalences and exceptions It is also able to count the numbers of occurrence of a given simple term or a conjunction of terms The design of contradiction and the treatment of the disjunction of non-negated terms allow APCIS to accept Horn clauses as well as non-Horn clauses and to carry out inferences from them This feature makes APCIS more general than Prolog
17 Key lords and Document Analysis 170 Descriptors
APC (Annotated Predicate Calculus) APCIS (Annotated Predicate Calculus Inference System) Horn Clause Numerical Quantifier Prolog Selector
17b IdentifiersOpen-Ended Terms
17c COSATI FieldGroup
18 Availability Statement 19 Security Class (This
Re~f~~IA~SIF IFf)
21 ~o of Pages
49 211 ecurity Class (This
PageUNCLASSIFIED
22 Price
FOA NTIS n (10middot70 usco-oc 40329-
29
re(F(A B C) RI) re(F(A B D) RZ)
re(F(A v B e D E) (R I v R2)) -
re(F(A e D E) R I) re(F(B e D El R2) re(F(A amp B e D E) (RI amp RZ)) -
re(F(A e D El R 1) re(F(B e D E) R2) re(F(A B v e D E) (R I v R2)) -
re(F(A B D E) RI) re(F(A e D E) R2)
re(F(A B amp e D E) (RI amp R2)) -
re(F(A B D El RI) re(F(A e D E) RZ) re(F(A B e v D E) (R I v R2)) -
re(F(A B e El R 1) re(F(A B D E) RZ) re(F(A B e amp D E) (RI amp RZ)) -
re(F(A B e E) R I) re(F(A B D E) RZ)
re(F(A B e D vEl (RI v RZ)) - l
rc(F(A B C D) RI) re(F(A n e El RZ) re(F(A B e D amp El (RI amp RZ)) - ~
re(F(A B e D) RI) re(F(A B e El RZ)
re((A = B) (A = B)l-
re((A = Bl (A = 8)) -
retIA gt= BI (A gt= B)) -
re((A lt= B) (A lt= B)) -
re((A gt B) (A gt B))-
re((A lt Bl (A lt Bl)- re(A A)
Step) Bringing n(gation inwards
Degin(-(P) PI) - neg(P Pl)
negin(P lt=gt Q PI lt=gt Ql) - ~
negin(P PI) negiD(Q QI)
Degin(aU(X P) all(X PI)) - Degin(P PI) negin(exists(X P) exists(X PI))- negin(P PI) negin(P amp Q PI amp Ql) - Degin(P PI) negin(Q Ql)
Degin(P v Q PI v QI) - Degin(P PI) negin(Q QI) negin(P Pl
neg(-(P) PI) - negin(P PI)
neg(all(X P) exists(X PI)) - neg(P PI)
30
neg(exists(X P) all(X PI)) - neg(P PI)
neg(P amp Q PI v QI) - neg(P PI) neg(Q Ql)
neg(P v Q PI amp QI) - neg(P PI) neg(Q QI)
neg(P -(PH
Step 6 Dropping existnetial quanti6ers
dropexist(P lt=gt Q PI lt=gt QI Elerns) - dropexist(P PI Elerns) dropexist(Q QI Elerns)
dropexist(alJ(X P) all(XPI) Elerns)
dropexist(P PI [XIElernsJ)
dropexist(exists(X P amp nurnber(X Yraquo P2 Elerns) -
genfun(skn Newg) Fun = [NewgIElerns]
subst(FuD X P amp Dumber(X Y) PI)
dropexist(Pl P2 Elerns)
dropexist(exists(X P) PZ Elerns) -
genfun(skrn Newf) Fun = [NewfIElernsJ
subst(Fun X p PI)
dropex ist(P 1 P~ Elerns)
dropexist(P v Q PI v QI Elerns) - ~
dropexist(P PI Elerns) dropexist(Q Ql Elerns)
dropexist(P amp Q PI amp QI Elerns) - 1
dropexist(P Pl Elerns) dropexist(Q QI Elerns)
dropexist(P P _)
gen fun(R oot Newn arne) shy
getnurn(Root Nurn)
narne(Root Rootlist)
append(Rootlist[Nurnj Narnelist)
concat(Narnelist Newnarne)
getnurn(Root Nurn) shy
retract(currentnurn(Root Nurn 1 raquo
Nurn is Nurni + 1
asserta(currentnurn(Root Nurn))
getnurn(Root 1) - asserta(currentnurn(Root 1))
subst(New Old Val Val) - var(Val)
subst(New Old Old New) - 1 substNew Old Val Val) - atornic(Val)
31
subst(New Old Val Newval) shy
runctor(Val F N)
CUDctor(Newval F N)
subst_args(N New Old Val Newval)
subst_args(O J J - J J
subst_args(N New Old Val NewVal) shy
arg(N Val OldArg)
arg(N NewVal NewArg)
subst(New Old OldArg NewArg)
NI is N - I
subst_args(Nl New Old Val NewVal)
append([J L L) -
append([XILl] L2 [XIL3]) - append(Ll L2 L3)
Step - Dropping universal quantifiers
dropall(P lt=gt Q PI lt=gt QI)-
dropall(P PI) dropall(Q QI)
dropall(all(X P) PI) - ~ dropall(P PI)
dropall(P amp Q PI amp QI) -
dropall(P PI) dropall(Q QI)
dropall(P v Q PI v QI) -
dropall(P PI) dropall(Q QI)
dropall(P P)
Step 8 Distributing conjunctions over disjunctions
distrib(P lt=gt Q PI lt=gt Ql) - t distrib(P PI) distrib(Q QI)
distrib(P v Q R) -
distrib(P PI) distrib(Q QI)
distributing(PI v QI R)
distrib(P it Q PI it QI) -
distrib(P PI) distrib( Q QI)
distrib(P P)
distributing((P amp Q) v R PI amp QI) -
distrib(P v R PI) distrib(Q v R Ql)
32
distributing(P v (Q amp R) PI amp Ql) -
distrib(P v Q PI) distrib(P v R Ql)
distributing(P P)
Step 9 Packing each conjunction into clauses
c1ausify(P amp Q CI C2) -
clausiCy(P CI C3) c1ausify(Q C3 C2)
cbusiCy(P [d(A B)ICs] Cs) shy
inclause(P A [j B [I) 1
c1ausiry( C C)
inclause(P v Q A AI B B1) -
inc1ause(P A2 AI B2 Bl)
inclause(Q A A2 B B2)
inclausenp) A A B1 B) -
notin(P A) putin(P B B1)
inclause(P AI A B B) shy
notin(P Bl putin(P A AI)
notin(X [XU) - fail
notin(X [JLj) - notin(X L)
notin(X 1])
putin(X II [X]) - 1
putin(X [XILJ L) -
putin(X [YILJ [YILl]) - putin(X L Ll)
Step 1Oa Printing clauses
printcl([]) - nl nl
printcl(c1(AB)ICsj) - printcl(A Bl nl printcl(Cs)
printcl(L II) - printdis(IL) prinr)middot
printclHl L) - prin(contradiction(() printconl(rL)
print()) - ) printconj(rL) prinr )
printcl(Ll L2) shy
printdis(ILl) print( - ) printconj(rL2) prin()
printdis(S[Lj) - printcbar(SL)
33
printdis(S[LILs]) - printchu(SL) prin( v) printdis(SLs)
printconl(S[LI) - printchar(SL)
printconl(S[LILs]) - printchar(SL) prin( ) printconl(SLs)
printconj(S[L]) - tab(3) printchar(SL)
prin tconj( S [L IL sl) shy
tab(3) printchar(SL) print( ) printconj(SLs)
printchar(SP) shy
atomic(P)
name(P L)
L = [IT]
concat([XIT NewP)
prin(~ewP)
printchar(SP) shy
atomic(P)
prin(P)
printchar(SA lt= gt B) -
prin((l clausify(A AI [j) pl(eAl) prin())
print lt=gt )
prin(() cbusify(B Bl [I) pJ(eBl) prine))middot
printchar(rnumber(X N)) shy
prin(num() printchar(rx) prin( )
printchar(rN) prinC))
printchar(rF(A B)) shy
seJec(F(A B))
prinCsel() printchar(rA)
prin( F ) printchar(rB) prinC))
printchar(SF(A B)) shy
( selec(F(A B)) F = infix )
printchar(SA) prin( F ) printchar(SB)
printchar(SF(A)) shy
(F= prefix gt= F= prefix lt= F= prefixgt F= prefix lt )
prin(F ) printcbar(SA)
printchar(SP) shy
functor(P F MaxN)
prin(F ()
Nl is MaxN - 1
putout(S N 1 P MaxN)
34
prin())
putout(S 0 P MaxN) -
arg(~laxN P Argu)
prin tchar(SArgu)
putout(S N p MaxN) shy
Nt is MaxN - N arg(NI P Argu)
printcbar(SArgu )
prin( )
N2 is N - 1
putout(S N2 P MaxN)
selec(FA B)) shy
( F= infix = F= infix f= F= infix gt=
F= infix gt F= infix lt= F= infix lt )
35
----------------------------------Program Name APClS - Part 2 Inference Mechanism ---------------------------------- a(X) shy
steps(X X9)
(( X9 =[] nl
print( yes it is always true) )
( X9 =[cI(IJ[])] nl
print( no it is always false) )
( nl nl printel(X9) Step 1Oa
tell(temp_file) printel(X9) e1ose(temp_file) consult(temp_6Ie) ))
q(X) shy
asserta( in pt(X))
steps(X X9)
(( X9 = [] print(middot~H~~middot~t~)
print(THE AiSWER IS YES)
print( ilgIQlQl(~) )
( X9 = [e1([j [j)] Pr1nt ( OJ fi(i I~ iii Ij)middot(i)(i) fiyenQ)riiio(i)(ij)(i)fj)fiyen1li1il1li1il)__ gtw~ __~_~ _~~_ ~_-=~
print(THE ANSWER IS NO ) print() )
( teI1(temp_6Ie)
prques(X9) Step 1Ob
close(temp_file)
nl print(Let me think about it) nl
consult(temp_6Ie) ))
retrac t( in pt(X))
Step lOb Printing question
prques(lcl(A 8)1) - prin(goo(() pl(qA 8) print()))
prques([c1(A 8HCs]) - prin(goo(() pl(qA 8) print() pl(q Cs)
pl(e [c1(A 8)]) - pl(eA 8)
pl(q [c1(A 8)]) - pl(qA 8) print()))
pl(S [e1(A B)ICs]) - pl(SA B) prin( ) pl(S Cs)
38
pl(q [j L) - prin(c1ause(contradiction(() pcont(qL) prin())_))
pl(S [I L)- prin(so2(contradidion(() pcont(SL) print))))middot
pl(S [L] []) - prin(so2() pcbar(SL) prin())
pl(S L [J)- prinsol() plett(SL) print))
pl(S [L] LI) - prin(condi(() pchar(cL)
prin(() pcont(S Ll) prine))))
pl(S L Ll)- prin(c1ause() plert(cL)
prin(() pcont(S Ll) prine)))
plert(S[LJ) - pchar(SL)
plert(SjLILsj) - pcbar(SL) print v) pleCt(SLs)
pcont(S[L]) - pchar(SL)
pcont(S[LILsj) - pcbar(SL) prinr ) pcont(SLs)
pcbar(SP) shy
atomic(P)
name(PL)
( L = [IT] L = [5 k miT] L = [5 k niT] )
concat[XITj NewP)
prin(0JewP)
pchar(SP) shy
atomic(P)
prin(P) pchar(SA lt=gt B) -
prin(() dausify(A AI []) pl(eAI) prin())
prinr lt=gt ) prin(() dausify(B BI ]) pl(eB) print))
pchar(Snumber(X N)) shy
prin(num() pchar(SX) prin()
pchar(SN) prinr))
pcbar(SM N) - prin(M N)
pcbar(cF(A B)) shy
selec(F(A Braquo
pcbar(cA)
prine F ) pchar(cB) pchar(SF(A B)) shy
selec(F(A B))
prin(sel() pchar(SA)
print F ) pchar(SB) print)) I
31
pc har(SF(A)) shy
( F= prefix gt= F= prefix lt= F= prefixgt F= prefix lt )
prin(F ) pchar(SA)
pchar(SP)shy
runctor(P F MaxN)
prin(F ()
011 is MaxN - 1 pout(SNl P MaxN)
print) )
pout(S 0 P M3xN) - 1
arg(~bxN P Argu)
pchlr(SArgu )
pout(S N P MaxN shy
Nl is MaxN - N
arg(Nl P Argu)
pchar(SArgu
prin( )
N2 is N - 1
pout(S N2 P ~13xN)
Comparing numbers in numerical quantifiers
num(XN) shy
number(X I)
cnum(N 1) ~
cnumlaquo=01 lt=I- N gt=I
cnumlaquo=J lt I) - N gt=1-1
cnumlaquo=NIJ) - N gt=J 1
cnumlaquo=N J)- integer(I) N gt=I~
cnum(gt=N gt=1) - N lt=1
cnum(gt=N gt I) - N lt=1+ 1 cnum(gt=NIJ) - N lt=1
cnum(gt=N lt=1)- N lt=1
cnum(gt=N lt I) - N lt=1 L cnum(gt=N 1)- integer(I) N lt=1
cnum( lt N lt 1)- N gt=1 L
38
cnum( lt N lt=1) - N gt I cnum( lt NLJ) - N gt J
cnum( lt N 1)- integer(I) N gt 1
cnum(gt N gt I) - N lt=1 cnumlgt i gt=1) - N lt I
cnum(gt N lt=1) - N lt=0
cnum(gt N lt I) - N lt=0
cnum(gt iIJ) - N lt I cnum(gt N 1)- integer(I) N lt I
cnum(~LN lt=1) - M=I N gt= I l
cnum(~LN lt I) - M=l N gt= I-I
cnum(~LNLJ) - M lt =1 N gt = J
cnum(~1N 1)- integer(I) M lt= I N gt= I
cnum(- N) - integer(N)
Comparing selectors
sel(X = Y) shyX= Y
sel(X I=Y) shy(X I=Y X lt Y Xgt Y)
sel(X gt Y) shyXgt Y
sel(X lt Y) shyXlt Y
selX gt=Y) shy(X gt=Y X= Y Xgt Y)
se(X lt=Y) shy
(X lt=Y
X= Y
X lt Y)
csel(infix = infix =)
39
csel(infix = infix = csel(infix = infix gt)
csel(infix = infix lt) csel(infix gt infix gt) cseJ(infix lt infix lt) csel(infix gt= infix gt=) csel(infix gt= infix gt csel(infix gt= infix =)
csellinfix lt= infix lt=) csel(infix lt= infix lt) csel(infix lt= infix =)
Finding solutions
sol(X v Y) -
(( notetra(X) eon(X) ( sol(Y) )
( c1ause(P v Q R) not(cketra(P v Q))
dis(P v Q X v Y R) ~ )
( A lt=gt B equival(A lt=gt B X v Y) ~ I) sol(X) - ~ notetra(X) eon(X)
so~(X) - notetra(X)
( con (X)
( clause(P v Q R) not(ekctra(P v Q)) dis(P v Q X R) I)
cketra(P v Q) -
eketra(P) eketra(Q) eketra(F(I J)) shy
selec(F(I J))
c1ause(contradiction(sel(F(IJ))) _I
eketra(number(W I)) -
clause(cootradietion(num(Wl)) - eketr(P) shy
clause(contradiction(P) - 1
notctra(P) shy
not( e lause( con tradiction(P) _))
40
Searching (or disjunctions
dis(P v Q X v Y R) - dis(P X v Y R)
dis(Q X v Y R) con(R)
dis(P v Q X R) -
dis(P X R) dis(Q X R) con(R
dis(P X v Y R) - clause(contradicton(Pl J 1
dis(F(I J) sel(G(I J)) v Y R) - csel(G Fl dis(number(WI) num(W N v Y R) - cnum(N I)
dis(P P v Y R) -
dis(P X v Y R) - dis(P Y R)
dis(F(I J) seJ(G(IJ)) R) - csel(G F)
dis(number(WI) num(WN) R) - cnum(N I) dis(P P R) - 1
dis(FJ J X R) shy
( ckctra(F(IJ) cbeckeq(seJ(F(IJ))) )
dis(number(W Il X R) - ( ckctra(number(WI)) cbeckeq(num(WI)) )
dis(P X R) shy( ckctra(P) cbeckeq(P) ) 1
cbeckeq(P) shy
(( A lt=gt so2(contradiction(P))
bagof(A A [jj) ) ( so2(contradiction(P)) lt=gt B
bagof(B B Uj) ))
ckeq(A) shy
( so2(A) lt=gt B B lt=gt so2(A) ) bagof(B B UJ)
con((P Q)) -
clause(P R) con(R) con(Q) con(true) -
con(contradiction(P)) - clause(contradiction(P) J
con(cause(X Y)) - cause(X Y)
con(sel(X)) - sel(X)
con(num(X Y)) - num(X Y) con(P)- (( dause(P R) (con(R) ckeq(R)))
colJectin(P) )
collectin(P) shy
bagof(S (c1ause(P S) S = true) [L LIJ )
mkcon(L Ll L)
bagor(l (L2 ) UJ) L
mkcon((A AI) (B B1) (sol(A v B) e D)) -
mkcon(A B1 e) mkcon(A1 (B Bl) D)
mkcon(A (B B1) (sol(A v B) e)) -
mkcon(A Bl e)
mkcon((A AI) B (sol(A v B) e)) middot1
mkcon(Al B e)
mkcon(A B sol(A vB))
Searching ror equivalences
equival(A lt=gt B X v Y) - 1 ( equival(A lt=gt B X) equival(A lt=gt B Y) )
equival(s02(A) lt=gt 502(B) A) - clause(B _I equival(s02(B) lt=gt 502(A) A) c1ause(B _I
Top level or inrerence mechanism
goo((s02(whatnum) P)) -
getatm(P Xl
bagor(number(X Y) ( P so2(number(X Y)) ) A )
count1(A 00 L R) nl
bagor(X P B )
count2(B L R Ll Rl) nJ print()
(( LI = 0 Rl = 0 print(THE ANSWER IS ) nl
(( Ll = Rl prin(-Jumber or ) prn(P) print(is Ll) )
( Rlgt20000 prin(Number or I prn(P) print(is LI or more) )
42
( prin(Number of ) pfn(P) print( is from Ll to Rl) )) )
( print(THE ANSWER IS NO I )) print()
goo(X) shy
(( bagof(X X L) L = [I nl print()
print(THE ANSWER IS YES) nl wout(L) print() )
( equiv(X L) nl print()
print(THE ANSWER IS YES) nl wout(L) print(-) )
( c1ause(inpt(A ==gt B) _I ( impli(A B Z) impli(B A Z) ) print(l~Hl)
printTHE ANSWER IS YES) nl print(Z) print(Hj~(fH~) ))
goo(X) print( Hg)
print(THE ANSWER IS NO ) print( lH~lH~gg9l9lmiddotmiddot~Q(gmiddot)
00 Semhing for implications in equiV3lent relations
impli( B Z) shyt-ell( z1) prin(templ() pchn(S A lt=gt B) print()) close ( zl) consult(zl) templ(Z)
unload zl Z
Searching for equivalence
equiv (X L)
(( X lt=gt Y
equ(Y YI)t bagof(Y Yl L) L = [j )
(Y lt=gt X equ(Y YI) bagof(Y Yl L) L = [J )
( X = F(New)
clause(~ew T) makeup(T Tl)
(( Tl lt=gt B
equ(B Bl) bagof(Bl Bl M) M = [j L=[Newl )
(A lt=gt TI
equ(A AI) bagof(Al AI M) M = 1] L=INewj )) ))
makeup((A B) (AI Bl)) -
makeup(A A1) makeup(B BI)
makeup(A so2(A))
equ((A B) (AI BI)) -
equ(A AI) equ(B Bl)
equ(sol(X v Y) sol(XI v Yl)) -
equ(X XI) equ(Y YI)
equ(so2(X) so2(XI)) -
equ(X XI)
equ(contradiction(X) clJuse(contradiction(X) X) ) -
equ(X X)
Counting numbers
getatm((A B) X) -
( getatm(A X) getatm(B X) )
getatm(so2(F(X)) X) -
getatm(so2(X) X) - atom(X)
countl([J L R L R) -
countl([number(X Y)IT] L R L2 R2) shy
(( Y = (gt=~) LI is L + N Rl is R + 20001 l )
( Y = (gt N) LI is L+ N+ 1 RI is R + 20002 )
(Y == laquo=~) LI is L + 1 Rl is R + N )
(Y = laquo N) LI is L + 1 RI is R+N-I)
(Y == IJ LI is L + I Rl is R + J ) ( Y == N L1 is L + N RI is R + N ))
count1(T LI R 1 L2 R2)
count2(fJ L R L R) - 1
count2([XITJ L R L2 R2) shy
name(X Xl)
(( Xl = sknj LI is L Rl is R )
44
( Xl = Iskmj L1 is L + 1 RI is R + ZOOO1) ( LI is L + I RI is R + I ))
count2(T LI RI L2 R2)
pfn((A B)) - pfn(A) prn(B)
pCn(so2(F(X))) - prin(F )
prn(so2(X)) - atom(X) prin(X ) prn (so2(X))
Printing result
wout([XlJ - prt(X) nl woutf[xIY]) - prt(X) nl nl wout(Y)
prt(e(A B)) -
prt(A) prinr 8 ) prt(ltE) prt(eA) - prt(A)
prt(c(A EJ) - prin() prt(A) prine ) prt(B) prin(T)
prt(c A) - prt(A) prt((A E)) - ~
prt(A) nl prt(E) prt(sol(X v Y)) - ~
prt(X) prinC v) prt(Y) prt(A lt=gt B) -
prt(e A) prinC lt=gt ) prt(e B) prt(sol(X)) - prt(X)
prt(so2(X)) - prt(X
prt(c1ause(X Y)) - prt(X)
prt(contradiction(X)) - prin(contradiction() prt(cX) prinr))middot prt(num(XY)) - prin(number(X Y)) prt(sel(X)) - prin(X) prt(X v Y) - prt(X) prin( v) prt(Y) prt(X) prin(X)
Handling conditional queries
condi((Y Xl) shy
assertcon(X) Y
45
retractcon(X)
condi((B A))
retractcon(A) fail
assertcon((A B)) 1
assertcon(A) assertcon(B)
assertcon(A) asserta(A)
retrac teon ((A B)) 1
retracteon(A) retractcon (B)
retraetcon(A) - retract(A)
BIBLIOGRAPHIC DATA SHEET
Report No UIUCDS-F-84-928
3 Recipients Accession No
4 T ide and Subt ltle
An Annotated Predicate Calculus Inference System (APCIS)
S Report Date
November 1984 6
7 Author(s)
Kah-Eng Pua 8 Performing Organization Rept
No
9 Performing Organization Name and Address
Department of Computer Science University of Illinois Urbana IL
10 ProjectTaskWork Unit No
11 Contract Grant No NSF DCR 84-06081 ONR N00014-82-K-0186
12 Sponsoring Organization Name and Address
National Science Foundation Washington DC
13 Type of Report amp Period Covered
14
15 Supplementary Notes
16 Abstracts
This paper describes a deductive inference system called APCIS (Annotated Predicate Calculus Inference System) APCIS is able to carry out inferences from expressions involving numerical quantifiers selectors disjunctions of non-negated terms negated terms disjunctions of negated terms equivalences and exceptions It is also able to count the numbers of occurrence of a given simple term or a conjunction of terms The design of contradiction and the treatment of the disjunction of non-negated terms allow APCIS to accept Horn clauses as well as non-Horn clauses and to carry out inferences from them This feature makes APCIS more general than Prolog
17 Key lords and Document Analysis 170 Descriptors
APC (Annotated Predicate Calculus) APCIS (Annotated Predicate Calculus Inference System) Horn Clause Numerical Quantifier Prolog Selector
17b IdentifiersOpen-Ended Terms
17c COSATI FieldGroup
18 Availability Statement 19 Security Class (This
Re~f~~IA~SIF IFf)
21 ~o of Pages
49 211 ecurity Class (This
PageUNCLASSIFIED
22 Price
FOA NTIS n (10middot70 usco-oc 40329-
30
neg(exists(X P) all(X PI)) - neg(P PI)
neg(P amp Q PI v QI) - neg(P PI) neg(Q Ql)
neg(P v Q PI amp QI) - neg(P PI) neg(Q QI)
neg(P -(PH
Step 6 Dropping existnetial quanti6ers
dropexist(P lt=gt Q PI lt=gt QI Elerns) - dropexist(P PI Elerns) dropexist(Q QI Elerns)
dropexist(alJ(X P) all(XPI) Elerns)
dropexist(P PI [XIElernsJ)
dropexist(exists(X P amp nurnber(X Yraquo P2 Elerns) -
genfun(skn Newg) Fun = [NewgIElerns]
subst(FuD X P amp Dumber(X Y) PI)
dropexist(Pl P2 Elerns)
dropexist(exists(X P) PZ Elerns) -
genfun(skrn Newf) Fun = [NewfIElernsJ
subst(Fun X p PI)
dropex ist(P 1 P~ Elerns)
dropexist(P v Q PI v QI Elerns) - ~
dropexist(P PI Elerns) dropexist(Q Ql Elerns)
dropexist(P amp Q PI amp QI Elerns) - 1
dropexist(P Pl Elerns) dropexist(Q QI Elerns)
dropexist(P P _)
gen fun(R oot Newn arne) shy
getnurn(Root Nurn)
narne(Root Rootlist)
append(Rootlist[Nurnj Narnelist)
concat(Narnelist Newnarne)
getnurn(Root Nurn) shy
retract(currentnurn(Root Nurn 1 raquo
Nurn is Nurni + 1
asserta(currentnurn(Root Nurn))
getnurn(Root 1) - asserta(currentnurn(Root 1))
subst(New Old Val Val) - var(Val)
subst(New Old Old New) - 1 substNew Old Val Val) - atornic(Val)
31
subst(New Old Val Newval) shy
runctor(Val F N)
CUDctor(Newval F N)
subst_args(N New Old Val Newval)
subst_args(O J J - J J
subst_args(N New Old Val NewVal) shy
arg(N Val OldArg)
arg(N NewVal NewArg)
subst(New Old OldArg NewArg)
NI is N - I
subst_args(Nl New Old Val NewVal)
append([J L L) -
append([XILl] L2 [XIL3]) - append(Ll L2 L3)
Step - Dropping universal quantifiers
dropall(P lt=gt Q PI lt=gt QI)-
dropall(P PI) dropall(Q QI)
dropall(all(X P) PI) - ~ dropall(P PI)
dropall(P amp Q PI amp QI) -
dropall(P PI) dropall(Q QI)
dropall(P v Q PI v QI) -
dropall(P PI) dropall(Q QI)
dropall(P P)
Step 8 Distributing conjunctions over disjunctions
distrib(P lt=gt Q PI lt=gt Ql) - t distrib(P PI) distrib(Q QI)
distrib(P v Q R) -
distrib(P PI) distrib(Q QI)
distributing(PI v QI R)
distrib(P it Q PI it QI) -
distrib(P PI) distrib( Q QI)
distrib(P P)
distributing((P amp Q) v R PI amp QI) -
distrib(P v R PI) distrib(Q v R Ql)
32
distributing(P v (Q amp R) PI amp Ql) -
distrib(P v Q PI) distrib(P v R Ql)
distributing(P P)
Step 9 Packing each conjunction into clauses
c1ausify(P amp Q CI C2) -
clausiCy(P CI C3) c1ausify(Q C3 C2)
cbusiCy(P [d(A B)ICs] Cs) shy
inclause(P A [j B [I) 1
c1ausiry( C C)
inclause(P v Q A AI B B1) -
inc1ause(P A2 AI B2 Bl)
inclause(Q A A2 B B2)
inclausenp) A A B1 B) -
notin(P A) putin(P B B1)
inclause(P AI A B B) shy
notin(P Bl putin(P A AI)
notin(X [XU) - fail
notin(X [JLj) - notin(X L)
notin(X 1])
putin(X II [X]) - 1
putin(X [XILJ L) -
putin(X [YILJ [YILl]) - putin(X L Ll)
Step 1Oa Printing clauses
printcl([]) - nl nl
printcl(c1(AB)ICsj) - printcl(A Bl nl printcl(Cs)
printcl(L II) - printdis(IL) prinr)middot
printclHl L) - prin(contradiction(() printconl(rL)
print()) - ) printconj(rL) prinr )
printcl(Ll L2) shy
printdis(ILl) print( - ) printconj(rL2) prin()
printdis(S[Lj) - printcbar(SL)
33
printdis(S[LILs]) - printchu(SL) prin( v) printdis(SLs)
printconl(S[LI) - printchar(SL)
printconl(S[LILs]) - printchar(SL) prin( ) printconl(SLs)
printconj(S[L]) - tab(3) printchar(SL)
prin tconj( S [L IL sl) shy
tab(3) printchar(SL) print( ) printconj(SLs)
printchar(SP) shy
atomic(P)
name(P L)
L = [IT]
concat([XIT NewP)
prin(~ewP)
printchar(SP) shy
atomic(P)
prin(P)
printchar(SA lt= gt B) -
prin((l clausify(A AI [j) pl(eAl) prin())
print lt=gt )
prin(() cbusify(B Bl [I) pJ(eBl) prine))middot
printchar(rnumber(X N)) shy
prin(num() printchar(rx) prin( )
printchar(rN) prinC))
printchar(rF(A B)) shy
seJec(F(A B))
prinCsel() printchar(rA)
prin( F ) printchar(rB) prinC))
printchar(SF(A B)) shy
( selec(F(A B)) F = infix )
printchar(SA) prin( F ) printchar(SB)
printchar(SF(A)) shy
(F= prefix gt= F= prefix lt= F= prefixgt F= prefix lt )
prin(F ) printcbar(SA)
printchar(SP) shy
functor(P F MaxN)
prin(F ()
Nl is MaxN - 1
putout(S N 1 P MaxN)
34
prin())
putout(S 0 P MaxN) -
arg(~laxN P Argu)
prin tchar(SArgu)
putout(S N p MaxN) shy
Nt is MaxN - N arg(NI P Argu)
printcbar(SArgu )
prin( )
N2 is N - 1
putout(S N2 P MaxN)
selec(FA B)) shy
( F= infix = F= infix f= F= infix gt=
F= infix gt F= infix lt= F= infix lt )
35
----------------------------------Program Name APClS - Part 2 Inference Mechanism ---------------------------------- a(X) shy
steps(X X9)
(( X9 =[] nl
print( yes it is always true) )
( X9 =[cI(IJ[])] nl
print( no it is always false) )
( nl nl printel(X9) Step 1Oa
tell(temp_file) printel(X9) e1ose(temp_file) consult(temp_6Ie) ))
q(X) shy
asserta( in pt(X))
steps(X X9)
(( X9 = [] print(middot~H~~middot~t~)
print(THE AiSWER IS YES)
print( ilgIQlQl(~) )
( X9 = [e1([j [j)] Pr1nt ( OJ fi(i I~ iii Ij)middot(i)(i) fiyenQ)riiio(i)(ij)(i)fj)fiyen1li1il1li1il)__ gtw~ __~_~ _~~_ ~_-=~
print(THE ANSWER IS NO ) print() )
( teI1(temp_6Ie)
prques(X9) Step 1Ob
close(temp_file)
nl print(Let me think about it) nl
consult(temp_6Ie) ))
retrac t( in pt(X))
Step lOb Printing question
prques(lcl(A 8)1) - prin(goo(() pl(qA 8) print()))
prques([c1(A 8HCs]) - prin(goo(() pl(qA 8) print() pl(q Cs)
pl(e [c1(A 8)]) - pl(eA 8)
pl(q [c1(A 8)]) - pl(qA 8) print()))
pl(S [e1(A B)ICs]) - pl(SA B) prin( ) pl(S Cs)
38
pl(q [j L) - prin(c1ause(contradiction(() pcont(qL) prin())_))
pl(S [I L)- prin(so2(contradidion(() pcont(SL) print))))middot
pl(S [L] []) - prin(so2() pcbar(SL) prin())
pl(S L [J)- prinsol() plett(SL) print))
pl(S [L] LI) - prin(condi(() pchar(cL)
prin(() pcont(S Ll) prine))))
pl(S L Ll)- prin(c1ause() plert(cL)
prin(() pcont(S Ll) prine)))
plert(S[LJ) - pchar(SL)
plert(SjLILsj) - pcbar(SL) print v) pleCt(SLs)
pcont(S[L]) - pchar(SL)
pcont(S[LILsj) - pcbar(SL) prinr ) pcont(SLs)
pcbar(SP) shy
atomic(P)
name(PL)
( L = [IT] L = [5 k miT] L = [5 k niT] )
concat[XITj NewP)
prin(0JewP)
pchar(SP) shy
atomic(P)
prin(P) pchar(SA lt=gt B) -
prin(() dausify(A AI []) pl(eAI) prin())
prinr lt=gt ) prin(() dausify(B BI ]) pl(eB) print))
pchar(Snumber(X N)) shy
prin(num() pchar(SX) prin()
pchar(SN) prinr))
pcbar(SM N) - prin(M N)
pcbar(cF(A B)) shy
selec(F(A Braquo
pcbar(cA)
prine F ) pchar(cB) pchar(SF(A B)) shy
selec(F(A B))
prin(sel() pchar(SA)
print F ) pchar(SB) print)) I
31
pc har(SF(A)) shy
( F= prefix gt= F= prefix lt= F= prefixgt F= prefix lt )
prin(F ) pchar(SA)
pchar(SP)shy
runctor(P F MaxN)
prin(F ()
011 is MaxN - 1 pout(SNl P MaxN)
print) )
pout(S 0 P M3xN) - 1
arg(~bxN P Argu)
pchlr(SArgu )
pout(S N P MaxN shy
Nl is MaxN - N
arg(Nl P Argu)
pchar(SArgu
prin( )
N2 is N - 1
pout(S N2 P ~13xN)
Comparing numbers in numerical quantifiers
num(XN) shy
number(X I)
cnum(N 1) ~
cnumlaquo=01 lt=I- N gt=I
cnumlaquo=J lt I) - N gt=1-1
cnumlaquo=NIJ) - N gt=J 1
cnumlaquo=N J)- integer(I) N gt=I~
cnum(gt=N gt=1) - N lt=1
cnum(gt=N gt I) - N lt=1+ 1 cnum(gt=NIJ) - N lt=1
cnum(gt=N lt=1)- N lt=1
cnum(gt=N lt I) - N lt=1 L cnum(gt=N 1)- integer(I) N lt=1
cnum( lt N lt 1)- N gt=1 L
38
cnum( lt N lt=1) - N gt I cnum( lt NLJ) - N gt J
cnum( lt N 1)- integer(I) N gt 1
cnum(gt N gt I) - N lt=1 cnumlgt i gt=1) - N lt I
cnum(gt N lt=1) - N lt=0
cnum(gt N lt I) - N lt=0
cnum(gt iIJ) - N lt I cnum(gt N 1)- integer(I) N lt I
cnum(~LN lt=1) - M=I N gt= I l
cnum(~LN lt I) - M=l N gt= I-I
cnum(~LNLJ) - M lt =1 N gt = J
cnum(~1N 1)- integer(I) M lt= I N gt= I
cnum(- N) - integer(N)
Comparing selectors
sel(X = Y) shyX= Y
sel(X I=Y) shy(X I=Y X lt Y Xgt Y)
sel(X gt Y) shyXgt Y
sel(X lt Y) shyXlt Y
selX gt=Y) shy(X gt=Y X= Y Xgt Y)
se(X lt=Y) shy
(X lt=Y
X= Y
X lt Y)
csel(infix = infix =)
39
csel(infix = infix = csel(infix = infix gt)
csel(infix = infix lt) csel(infix gt infix gt) cseJ(infix lt infix lt) csel(infix gt= infix gt=) csel(infix gt= infix gt csel(infix gt= infix =)
csellinfix lt= infix lt=) csel(infix lt= infix lt) csel(infix lt= infix =)
Finding solutions
sol(X v Y) -
(( notetra(X) eon(X) ( sol(Y) )
( c1ause(P v Q R) not(cketra(P v Q))
dis(P v Q X v Y R) ~ )
( A lt=gt B equival(A lt=gt B X v Y) ~ I) sol(X) - ~ notetra(X) eon(X)
so~(X) - notetra(X)
( con (X)
( clause(P v Q R) not(ekctra(P v Q)) dis(P v Q X R) I)
cketra(P v Q) -
eketra(P) eketra(Q) eketra(F(I J)) shy
selec(F(I J))
c1ause(contradiction(sel(F(IJ))) _I
eketra(number(W I)) -
clause(cootradietion(num(Wl)) - eketr(P) shy
clause(contradiction(P) - 1
notctra(P) shy
not( e lause( con tradiction(P) _))
40
Searching (or disjunctions
dis(P v Q X v Y R) - dis(P X v Y R)
dis(Q X v Y R) con(R)
dis(P v Q X R) -
dis(P X R) dis(Q X R) con(R
dis(P X v Y R) - clause(contradicton(Pl J 1
dis(F(I J) sel(G(I J)) v Y R) - csel(G Fl dis(number(WI) num(W N v Y R) - cnum(N I)
dis(P P v Y R) -
dis(P X v Y R) - dis(P Y R)
dis(F(I J) seJ(G(IJ)) R) - csel(G F)
dis(number(WI) num(WN) R) - cnum(N I) dis(P P R) - 1
dis(FJ J X R) shy
( ckctra(F(IJ) cbeckeq(seJ(F(IJ))) )
dis(number(W Il X R) - ( ckctra(number(WI)) cbeckeq(num(WI)) )
dis(P X R) shy( ckctra(P) cbeckeq(P) ) 1
cbeckeq(P) shy
(( A lt=gt so2(contradiction(P))
bagof(A A [jj) ) ( so2(contradiction(P)) lt=gt B
bagof(B B Uj) ))
ckeq(A) shy
( so2(A) lt=gt B B lt=gt so2(A) ) bagof(B B UJ)
con((P Q)) -
clause(P R) con(R) con(Q) con(true) -
con(contradiction(P)) - clause(contradiction(P) J
con(cause(X Y)) - cause(X Y)
con(sel(X)) - sel(X)
con(num(X Y)) - num(X Y) con(P)- (( dause(P R) (con(R) ckeq(R)))
colJectin(P) )
collectin(P) shy
bagof(S (c1ause(P S) S = true) [L LIJ )
mkcon(L Ll L)
bagor(l (L2 ) UJ) L
mkcon((A AI) (B B1) (sol(A v B) e D)) -
mkcon(A B1 e) mkcon(A1 (B Bl) D)
mkcon(A (B B1) (sol(A v B) e)) -
mkcon(A Bl e)
mkcon((A AI) B (sol(A v B) e)) middot1
mkcon(Al B e)
mkcon(A B sol(A vB))
Searching ror equivalences
equival(A lt=gt B X v Y) - 1 ( equival(A lt=gt B X) equival(A lt=gt B Y) )
equival(s02(A) lt=gt 502(B) A) - clause(B _I equival(s02(B) lt=gt 502(A) A) c1ause(B _I
Top level or inrerence mechanism
goo((s02(whatnum) P)) -
getatm(P Xl
bagor(number(X Y) ( P so2(number(X Y)) ) A )
count1(A 00 L R) nl
bagor(X P B )
count2(B L R Ll Rl) nJ print()
(( LI = 0 Rl = 0 print(THE ANSWER IS ) nl
(( Ll = Rl prin(-Jumber or ) prn(P) print(is Ll) )
( Rlgt20000 prin(Number or I prn(P) print(is LI or more) )
42
( prin(Number of ) pfn(P) print( is from Ll to Rl) )) )
( print(THE ANSWER IS NO I )) print()
goo(X) shy
(( bagof(X X L) L = [I nl print()
print(THE ANSWER IS YES) nl wout(L) print() )
( equiv(X L) nl print()
print(THE ANSWER IS YES) nl wout(L) print(-) )
( c1ause(inpt(A ==gt B) _I ( impli(A B Z) impli(B A Z) ) print(l~Hl)
printTHE ANSWER IS YES) nl print(Z) print(Hj~(fH~) ))
goo(X) print( Hg)
print(THE ANSWER IS NO ) print( lH~lH~gg9l9lmiddotmiddot~Q(gmiddot)
00 Semhing for implications in equiV3lent relations
impli( B Z) shyt-ell( z1) prin(templ() pchn(S A lt=gt B) print()) close ( zl) consult(zl) templ(Z)
unload zl Z
Searching for equivalence
equiv (X L)
(( X lt=gt Y
equ(Y YI)t bagof(Y Yl L) L = [j )
(Y lt=gt X equ(Y YI) bagof(Y Yl L) L = [J )
( X = F(New)
clause(~ew T) makeup(T Tl)
(( Tl lt=gt B
equ(B Bl) bagof(Bl Bl M) M = [j L=[Newl )
(A lt=gt TI
equ(A AI) bagof(Al AI M) M = 1] L=INewj )) ))
makeup((A B) (AI Bl)) -
makeup(A A1) makeup(B BI)
makeup(A so2(A))
equ((A B) (AI BI)) -
equ(A AI) equ(B Bl)
equ(sol(X v Y) sol(XI v Yl)) -
equ(X XI) equ(Y YI)
equ(so2(X) so2(XI)) -
equ(X XI)
equ(contradiction(X) clJuse(contradiction(X) X) ) -
equ(X X)
Counting numbers
getatm((A B) X) -
( getatm(A X) getatm(B X) )
getatm(so2(F(X)) X) -
getatm(so2(X) X) - atom(X)
countl([J L R L R) -
countl([number(X Y)IT] L R L2 R2) shy
(( Y = (gt=~) LI is L + N Rl is R + 20001 l )
( Y = (gt N) LI is L+ N+ 1 RI is R + 20002 )
(Y == laquo=~) LI is L + 1 Rl is R + N )
(Y = laquo N) LI is L + 1 RI is R+N-I)
(Y == IJ LI is L + I Rl is R + J ) ( Y == N L1 is L + N RI is R + N ))
count1(T LI R 1 L2 R2)
count2(fJ L R L R) - 1
count2([XITJ L R L2 R2) shy
name(X Xl)
(( Xl = sknj LI is L Rl is R )
44
( Xl = Iskmj L1 is L + 1 RI is R + ZOOO1) ( LI is L + I RI is R + I ))
count2(T LI RI L2 R2)
pfn((A B)) - pfn(A) prn(B)
pCn(so2(F(X))) - prin(F )
prn(so2(X)) - atom(X) prin(X ) prn (so2(X))
Printing result
wout([XlJ - prt(X) nl woutf[xIY]) - prt(X) nl nl wout(Y)
prt(e(A B)) -
prt(A) prinr 8 ) prt(ltE) prt(eA) - prt(A)
prt(c(A EJ) - prin() prt(A) prine ) prt(B) prin(T)
prt(c A) - prt(A) prt((A E)) - ~
prt(A) nl prt(E) prt(sol(X v Y)) - ~
prt(X) prinC v) prt(Y) prt(A lt=gt B) -
prt(e A) prinC lt=gt ) prt(e B) prt(sol(X)) - prt(X)
prt(so2(X)) - prt(X
prt(c1ause(X Y)) - prt(X)
prt(contradiction(X)) - prin(contradiction() prt(cX) prinr))middot prt(num(XY)) - prin(number(X Y)) prt(sel(X)) - prin(X) prt(X v Y) - prt(X) prin( v) prt(Y) prt(X) prin(X)
Handling conditional queries
condi((Y Xl) shy
assertcon(X) Y
45
retractcon(X)
condi((B A))
retractcon(A) fail
assertcon((A B)) 1
assertcon(A) assertcon(B)
assertcon(A) asserta(A)
retrac teon ((A B)) 1
retracteon(A) retractcon (B)
retraetcon(A) - retract(A)
BIBLIOGRAPHIC DATA SHEET
Report No UIUCDS-F-84-928
3 Recipients Accession No
4 T ide and Subt ltle
An Annotated Predicate Calculus Inference System (APCIS)
S Report Date
November 1984 6
7 Author(s)
Kah-Eng Pua 8 Performing Organization Rept
No
9 Performing Organization Name and Address
Department of Computer Science University of Illinois Urbana IL
10 ProjectTaskWork Unit No
11 Contract Grant No NSF DCR 84-06081 ONR N00014-82-K-0186
12 Sponsoring Organization Name and Address
National Science Foundation Washington DC
13 Type of Report amp Period Covered
14
15 Supplementary Notes
16 Abstracts
This paper describes a deductive inference system called APCIS (Annotated Predicate Calculus Inference System) APCIS is able to carry out inferences from expressions involving numerical quantifiers selectors disjunctions of non-negated terms negated terms disjunctions of negated terms equivalences and exceptions It is also able to count the numbers of occurrence of a given simple term or a conjunction of terms The design of contradiction and the treatment of the disjunction of non-negated terms allow APCIS to accept Horn clauses as well as non-Horn clauses and to carry out inferences from them This feature makes APCIS more general than Prolog
17 Key lords and Document Analysis 170 Descriptors
APC (Annotated Predicate Calculus) APCIS (Annotated Predicate Calculus Inference System) Horn Clause Numerical Quantifier Prolog Selector
17b IdentifiersOpen-Ended Terms
17c COSATI FieldGroup
18 Availability Statement 19 Security Class (This
Re~f~~IA~SIF IFf)
21 ~o of Pages
49 211 ecurity Class (This
PageUNCLASSIFIED
22 Price
FOA NTIS n (10middot70 usco-oc 40329-
31
subst(New Old Val Newval) shy
runctor(Val F N)
CUDctor(Newval F N)
subst_args(N New Old Val Newval)
subst_args(O J J - J J
subst_args(N New Old Val NewVal) shy
arg(N Val OldArg)
arg(N NewVal NewArg)
subst(New Old OldArg NewArg)
NI is N - I
subst_args(Nl New Old Val NewVal)
append([J L L) -
append([XILl] L2 [XIL3]) - append(Ll L2 L3)
Step - Dropping universal quantifiers
dropall(P lt=gt Q PI lt=gt QI)-
dropall(P PI) dropall(Q QI)
dropall(all(X P) PI) - ~ dropall(P PI)
dropall(P amp Q PI amp QI) -
dropall(P PI) dropall(Q QI)
dropall(P v Q PI v QI) -
dropall(P PI) dropall(Q QI)
dropall(P P)
Step 8 Distributing conjunctions over disjunctions
distrib(P lt=gt Q PI lt=gt Ql) - t distrib(P PI) distrib(Q QI)
distrib(P v Q R) -
distrib(P PI) distrib(Q QI)
distributing(PI v QI R)
distrib(P it Q PI it QI) -
distrib(P PI) distrib( Q QI)
distrib(P P)
distributing((P amp Q) v R PI amp QI) -
distrib(P v R PI) distrib(Q v R Ql)
32
distributing(P v (Q amp R) PI amp Ql) -
distrib(P v Q PI) distrib(P v R Ql)
distributing(P P)
Step 9 Packing each conjunction into clauses
c1ausify(P amp Q CI C2) -
clausiCy(P CI C3) c1ausify(Q C3 C2)
cbusiCy(P [d(A B)ICs] Cs) shy
inclause(P A [j B [I) 1
c1ausiry( C C)
inclause(P v Q A AI B B1) -
inc1ause(P A2 AI B2 Bl)
inclause(Q A A2 B B2)
inclausenp) A A B1 B) -
notin(P A) putin(P B B1)
inclause(P AI A B B) shy
notin(P Bl putin(P A AI)
notin(X [XU) - fail
notin(X [JLj) - notin(X L)
notin(X 1])
putin(X II [X]) - 1
putin(X [XILJ L) -
putin(X [YILJ [YILl]) - putin(X L Ll)
Step 1Oa Printing clauses
printcl([]) - nl nl
printcl(c1(AB)ICsj) - printcl(A Bl nl printcl(Cs)
printcl(L II) - printdis(IL) prinr)middot
printclHl L) - prin(contradiction(() printconl(rL)
print()) - ) printconj(rL) prinr )
printcl(Ll L2) shy
printdis(ILl) print( - ) printconj(rL2) prin()
printdis(S[Lj) - printcbar(SL)
33
printdis(S[LILs]) - printchu(SL) prin( v) printdis(SLs)
printconl(S[LI) - printchar(SL)
printconl(S[LILs]) - printchar(SL) prin( ) printconl(SLs)
printconj(S[L]) - tab(3) printchar(SL)
prin tconj( S [L IL sl) shy
tab(3) printchar(SL) print( ) printconj(SLs)
printchar(SP) shy
atomic(P)
name(P L)
L = [IT]
concat([XIT NewP)
prin(~ewP)
printchar(SP) shy
atomic(P)
prin(P)
printchar(SA lt= gt B) -
prin((l clausify(A AI [j) pl(eAl) prin())
print lt=gt )
prin(() cbusify(B Bl [I) pJ(eBl) prine))middot
printchar(rnumber(X N)) shy
prin(num() printchar(rx) prin( )
printchar(rN) prinC))
printchar(rF(A B)) shy
seJec(F(A B))
prinCsel() printchar(rA)
prin( F ) printchar(rB) prinC))
printchar(SF(A B)) shy
( selec(F(A B)) F = infix )
printchar(SA) prin( F ) printchar(SB)
printchar(SF(A)) shy
(F= prefix gt= F= prefix lt= F= prefixgt F= prefix lt )
prin(F ) printcbar(SA)
printchar(SP) shy
functor(P F MaxN)
prin(F ()
Nl is MaxN - 1
putout(S N 1 P MaxN)
34
prin())
putout(S 0 P MaxN) -
arg(~laxN P Argu)
prin tchar(SArgu)
putout(S N p MaxN) shy
Nt is MaxN - N arg(NI P Argu)
printcbar(SArgu )
prin( )
N2 is N - 1
putout(S N2 P MaxN)
selec(FA B)) shy
( F= infix = F= infix f= F= infix gt=
F= infix gt F= infix lt= F= infix lt )
35
----------------------------------Program Name APClS - Part 2 Inference Mechanism ---------------------------------- a(X) shy
steps(X X9)
(( X9 =[] nl
print( yes it is always true) )
( X9 =[cI(IJ[])] nl
print( no it is always false) )
( nl nl printel(X9) Step 1Oa
tell(temp_file) printel(X9) e1ose(temp_file) consult(temp_6Ie) ))
q(X) shy
asserta( in pt(X))
steps(X X9)
(( X9 = [] print(middot~H~~middot~t~)
print(THE AiSWER IS YES)
print( ilgIQlQl(~) )
( X9 = [e1([j [j)] Pr1nt ( OJ fi(i I~ iii Ij)middot(i)(i) fiyenQ)riiio(i)(ij)(i)fj)fiyen1li1il1li1il)__ gtw~ __~_~ _~~_ ~_-=~
print(THE ANSWER IS NO ) print() )
( teI1(temp_6Ie)
prques(X9) Step 1Ob
close(temp_file)
nl print(Let me think about it) nl
consult(temp_6Ie) ))
retrac t( in pt(X))
Step lOb Printing question
prques(lcl(A 8)1) - prin(goo(() pl(qA 8) print()))
prques([c1(A 8HCs]) - prin(goo(() pl(qA 8) print() pl(q Cs)
pl(e [c1(A 8)]) - pl(eA 8)
pl(q [c1(A 8)]) - pl(qA 8) print()))
pl(S [e1(A B)ICs]) - pl(SA B) prin( ) pl(S Cs)
38
pl(q [j L) - prin(c1ause(contradiction(() pcont(qL) prin())_))
pl(S [I L)- prin(so2(contradidion(() pcont(SL) print))))middot
pl(S [L] []) - prin(so2() pcbar(SL) prin())
pl(S L [J)- prinsol() plett(SL) print))
pl(S [L] LI) - prin(condi(() pchar(cL)
prin(() pcont(S Ll) prine))))
pl(S L Ll)- prin(c1ause() plert(cL)
prin(() pcont(S Ll) prine)))
plert(S[LJ) - pchar(SL)
plert(SjLILsj) - pcbar(SL) print v) pleCt(SLs)
pcont(S[L]) - pchar(SL)
pcont(S[LILsj) - pcbar(SL) prinr ) pcont(SLs)
pcbar(SP) shy
atomic(P)
name(PL)
( L = [IT] L = [5 k miT] L = [5 k niT] )
concat[XITj NewP)
prin(0JewP)
pchar(SP) shy
atomic(P)
prin(P) pchar(SA lt=gt B) -
prin(() dausify(A AI []) pl(eAI) prin())
prinr lt=gt ) prin(() dausify(B BI ]) pl(eB) print))
pchar(Snumber(X N)) shy
prin(num() pchar(SX) prin()
pchar(SN) prinr))
pcbar(SM N) - prin(M N)
pcbar(cF(A B)) shy
selec(F(A Braquo
pcbar(cA)
prine F ) pchar(cB) pchar(SF(A B)) shy
selec(F(A B))
prin(sel() pchar(SA)
print F ) pchar(SB) print)) I
31
pc har(SF(A)) shy
( F= prefix gt= F= prefix lt= F= prefixgt F= prefix lt )
prin(F ) pchar(SA)
pchar(SP)shy
runctor(P F MaxN)
prin(F ()
011 is MaxN - 1 pout(SNl P MaxN)
print) )
pout(S 0 P M3xN) - 1
arg(~bxN P Argu)
pchlr(SArgu )
pout(S N P MaxN shy
Nl is MaxN - N
arg(Nl P Argu)
pchar(SArgu
prin( )
N2 is N - 1
pout(S N2 P ~13xN)
Comparing numbers in numerical quantifiers
num(XN) shy
number(X I)
cnum(N 1) ~
cnumlaquo=01 lt=I- N gt=I
cnumlaquo=J lt I) - N gt=1-1
cnumlaquo=NIJ) - N gt=J 1
cnumlaquo=N J)- integer(I) N gt=I~
cnum(gt=N gt=1) - N lt=1
cnum(gt=N gt I) - N lt=1+ 1 cnum(gt=NIJ) - N lt=1
cnum(gt=N lt=1)- N lt=1
cnum(gt=N lt I) - N lt=1 L cnum(gt=N 1)- integer(I) N lt=1
cnum( lt N lt 1)- N gt=1 L
38
cnum( lt N lt=1) - N gt I cnum( lt NLJ) - N gt J
cnum( lt N 1)- integer(I) N gt 1
cnum(gt N gt I) - N lt=1 cnumlgt i gt=1) - N lt I
cnum(gt N lt=1) - N lt=0
cnum(gt N lt I) - N lt=0
cnum(gt iIJ) - N lt I cnum(gt N 1)- integer(I) N lt I
cnum(~LN lt=1) - M=I N gt= I l
cnum(~LN lt I) - M=l N gt= I-I
cnum(~LNLJ) - M lt =1 N gt = J
cnum(~1N 1)- integer(I) M lt= I N gt= I
cnum(- N) - integer(N)
Comparing selectors
sel(X = Y) shyX= Y
sel(X I=Y) shy(X I=Y X lt Y Xgt Y)
sel(X gt Y) shyXgt Y
sel(X lt Y) shyXlt Y
selX gt=Y) shy(X gt=Y X= Y Xgt Y)
se(X lt=Y) shy
(X lt=Y
X= Y
X lt Y)
csel(infix = infix =)
39
csel(infix = infix = csel(infix = infix gt)
csel(infix = infix lt) csel(infix gt infix gt) cseJ(infix lt infix lt) csel(infix gt= infix gt=) csel(infix gt= infix gt csel(infix gt= infix =)
csellinfix lt= infix lt=) csel(infix lt= infix lt) csel(infix lt= infix =)
Finding solutions
sol(X v Y) -
(( notetra(X) eon(X) ( sol(Y) )
( c1ause(P v Q R) not(cketra(P v Q))
dis(P v Q X v Y R) ~ )
( A lt=gt B equival(A lt=gt B X v Y) ~ I) sol(X) - ~ notetra(X) eon(X)
so~(X) - notetra(X)
( con (X)
( clause(P v Q R) not(ekctra(P v Q)) dis(P v Q X R) I)
cketra(P v Q) -
eketra(P) eketra(Q) eketra(F(I J)) shy
selec(F(I J))
c1ause(contradiction(sel(F(IJ))) _I
eketra(number(W I)) -
clause(cootradietion(num(Wl)) - eketr(P) shy
clause(contradiction(P) - 1
notctra(P) shy
not( e lause( con tradiction(P) _))
40
Searching (or disjunctions
dis(P v Q X v Y R) - dis(P X v Y R)
dis(Q X v Y R) con(R)
dis(P v Q X R) -
dis(P X R) dis(Q X R) con(R
dis(P X v Y R) - clause(contradicton(Pl J 1
dis(F(I J) sel(G(I J)) v Y R) - csel(G Fl dis(number(WI) num(W N v Y R) - cnum(N I)
dis(P P v Y R) -
dis(P X v Y R) - dis(P Y R)
dis(F(I J) seJ(G(IJ)) R) - csel(G F)
dis(number(WI) num(WN) R) - cnum(N I) dis(P P R) - 1
dis(FJ J X R) shy
( ckctra(F(IJ) cbeckeq(seJ(F(IJ))) )
dis(number(W Il X R) - ( ckctra(number(WI)) cbeckeq(num(WI)) )
dis(P X R) shy( ckctra(P) cbeckeq(P) ) 1
cbeckeq(P) shy
(( A lt=gt so2(contradiction(P))
bagof(A A [jj) ) ( so2(contradiction(P)) lt=gt B
bagof(B B Uj) ))
ckeq(A) shy
( so2(A) lt=gt B B lt=gt so2(A) ) bagof(B B UJ)
con((P Q)) -
clause(P R) con(R) con(Q) con(true) -
con(contradiction(P)) - clause(contradiction(P) J
con(cause(X Y)) - cause(X Y)
con(sel(X)) - sel(X)
con(num(X Y)) - num(X Y) con(P)- (( dause(P R) (con(R) ckeq(R)))
colJectin(P) )
collectin(P) shy
bagof(S (c1ause(P S) S = true) [L LIJ )
mkcon(L Ll L)
bagor(l (L2 ) UJ) L
mkcon((A AI) (B B1) (sol(A v B) e D)) -
mkcon(A B1 e) mkcon(A1 (B Bl) D)
mkcon(A (B B1) (sol(A v B) e)) -
mkcon(A Bl e)
mkcon((A AI) B (sol(A v B) e)) middot1
mkcon(Al B e)
mkcon(A B sol(A vB))
Searching ror equivalences
equival(A lt=gt B X v Y) - 1 ( equival(A lt=gt B X) equival(A lt=gt B Y) )
equival(s02(A) lt=gt 502(B) A) - clause(B _I equival(s02(B) lt=gt 502(A) A) c1ause(B _I
Top level or inrerence mechanism
goo((s02(whatnum) P)) -
getatm(P Xl
bagor(number(X Y) ( P so2(number(X Y)) ) A )
count1(A 00 L R) nl
bagor(X P B )
count2(B L R Ll Rl) nJ print()
(( LI = 0 Rl = 0 print(THE ANSWER IS ) nl
(( Ll = Rl prin(-Jumber or ) prn(P) print(is Ll) )
( Rlgt20000 prin(Number or I prn(P) print(is LI or more) )
42
( prin(Number of ) pfn(P) print( is from Ll to Rl) )) )
( print(THE ANSWER IS NO I )) print()
goo(X) shy
(( bagof(X X L) L = [I nl print()
print(THE ANSWER IS YES) nl wout(L) print() )
( equiv(X L) nl print()
print(THE ANSWER IS YES) nl wout(L) print(-) )
( c1ause(inpt(A ==gt B) _I ( impli(A B Z) impli(B A Z) ) print(l~Hl)
printTHE ANSWER IS YES) nl print(Z) print(Hj~(fH~) ))
goo(X) print( Hg)
print(THE ANSWER IS NO ) print( lH~lH~gg9l9lmiddotmiddot~Q(gmiddot)
00 Semhing for implications in equiV3lent relations
impli( B Z) shyt-ell( z1) prin(templ() pchn(S A lt=gt B) print()) close ( zl) consult(zl) templ(Z)
unload zl Z
Searching for equivalence
equiv (X L)
(( X lt=gt Y
equ(Y YI)t bagof(Y Yl L) L = [j )
(Y lt=gt X equ(Y YI) bagof(Y Yl L) L = [J )
( X = F(New)
clause(~ew T) makeup(T Tl)
(( Tl lt=gt B
equ(B Bl) bagof(Bl Bl M) M = [j L=[Newl )
(A lt=gt TI
equ(A AI) bagof(Al AI M) M = 1] L=INewj )) ))
makeup((A B) (AI Bl)) -
makeup(A A1) makeup(B BI)
makeup(A so2(A))
equ((A B) (AI BI)) -
equ(A AI) equ(B Bl)
equ(sol(X v Y) sol(XI v Yl)) -
equ(X XI) equ(Y YI)
equ(so2(X) so2(XI)) -
equ(X XI)
equ(contradiction(X) clJuse(contradiction(X) X) ) -
equ(X X)
Counting numbers
getatm((A B) X) -
( getatm(A X) getatm(B X) )
getatm(so2(F(X)) X) -
getatm(so2(X) X) - atom(X)
countl([J L R L R) -
countl([number(X Y)IT] L R L2 R2) shy
(( Y = (gt=~) LI is L + N Rl is R + 20001 l )
( Y = (gt N) LI is L+ N+ 1 RI is R + 20002 )
(Y == laquo=~) LI is L + 1 Rl is R + N )
(Y = laquo N) LI is L + 1 RI is R+N-I)
(Y == IJ LI is L + I Rl is R + J ) ( Y == N L1 is L + N RI is R + N ))
count1(T LI R 1 L2 R2)
count2(fJ L R L R) - 1
count2([XITJ L R L2 R2) shy
name(X Xl)
(( Xl = sknj LI is L Rl is R )
44
( Xl = Iskmj L1 is L + 1 RI is R + ZOOO1) ( LI is L + I RI is R + I ))
count2(T LI RI L2 R2)
pfn((A B)) - pfn(A) prn(B)
pCn(so2(F(X))) - prin(F )
prn(so2(X)) - atom(X) prin(X ) prn (so2(X))
Printing result
wout([XlJ - prt(X) nl woutf[xIY]) - prt(X) nl nl wout(Y)
prt(e(A B)) -
prt(A) prinr 8 ) prt(ltE) prt(eA) - prt(A)
prt(c(A EJ) - prin() prt(A) prine ) prt(B) prin(T)
prt(c A) - prt(A) prt((A E)) - ~
prt(A) nl prt(E) prt(sol(X v Y)) - ~
prt(X) prinC v) prt(Y) prt(A lt=gt B) -
prt(e A) prinC lt=gt ) prt(e B) prt(sol(X)) - prt(X)
prt(so2(X)) - prt(X
prt(c1ause(X Y)) - prt(X)
prt(contradiction(X)) - prin(contradiction() prt(cX) prinr))middot prt(num(XY)) - prin(number(X Y)) prt(sel(X)) - prin(X) prt(X v Y) - prt(X) prin( v) prt(Y) prt(X) prin(X)
Handling conditional queries
condi((Y Xl) shy
assertcon(X) Y
45
retractcon(X)
condi((B A))
retractcon(A) fail
assertcon((A B)) 1
assertcon(A) assertcon(B)
assertcon(A) asserta(A)
retrac teon ((A B)) 1
retracteon(A) retractcon (B)
retraetcon(A) - retract(A)
BIBLIOGRAPHIC DATA SHEET
Report No UIUCDS-F-84-928
3 Recipients Accession No
4 T ide and Subt ltle
An Annotated Predicate Calculus Inference System (APCIS)
S Report Date
November 1984 6
7 Author(s)
Kah-Eng Pua 8 Performing Organization Rept
No
9 Performing Organization Name and Address
Department of Computer Science University of Illinois Urbana IL
10 ProjectTaskWork Unit No
11 Contract Grant No NSF DCR 84-06081 ONR N00014-82-K-0186
12 Sponsoring Organization Name and Address
National Science Foundation Washington DC
13 Type of Report amp Period Covered
14
15 Supplementary Notes
16 Abstracts
This paper describes a deductive inference system called APCIS (Annotated Predicate Calculus Inference System) APCIS is able to carry out inferences from expressions involving numerical quantifiers selectors disjunctions of non-negated terms negated terms disjunctions of negated terms equivalences and exceptions It is also able to count the numbers of occurrence of a given simple term or a conjunction of terms The design of contradiction and the treatment of the disjunction of non-negated terms allow APCIS to accept Horn clauses as well as non-Horn clauses and to carry out inferences from them This feature makes APCIS more general than Prolog
17 Key lords and Document Analysis 170 Descriptors
APC (Annotated Predicate Calculus) APCIS (Annotated Predicate Calculus Inference System) Horn Clause Numerical Quantifier Prolog Selector
17b IdentifiersOpen-Ended Terms
17c COSATI FieldGroup
18 Availability Statement 19 Security Class (This
Re~f~~IA~SIF IFf)
21 ~o of Pages
49 211 ecurity Class (This
PageUNCLASSIFIED
22 Price
FOA NTIS n (10middot70 usco-oc 40329-
32
distributing(P v (Q amp R) PI amp Ql) -
distrib(P v Q PI) distrib(P v R Ql)
distributing(P P)
Step 9 Packing each conjunction into clauses
c1ausify(P amp Q CI C2) -
clausiCy(P CI C3) c1ausify(Q C3 C2)
cbusiCy(P [d(A B)ICs] Cs) shy
inclause(P A [j B [I) 1
c1ausiry( C C)
inclause(P v Q A AI B B1) -
inc1ause(P A2 AI B2 Bl)
inclause(Q A A2 B B2)
inclausenp) A A B1 B) -
notin(P A) putin(P B B1)
inclause(P AI A B B) shy
notin(P Bl putin(P A AI)
notin(X [XU) - fail
notin(X [JLj) - notin(X L)
notin(X 1])
putin(X II [X]) - 1
putin(X [XILJ L) -
putin(X [YILJ [YILl]) - putin(X L Ll)
Step 1Oa Printing clauses
printcl([]) - nl nl
printcl(c1(AB)ICsj) - printcl(A Bl nl printcl(Cs)
printcl(L II) - printdis(IL) prinr)middot
printclHl L) - prin(contradiction(() printconl(rL)
print()) - ) printconj(rL) prinr )
printcl(Ll L2) shy
printdis(ILl) print( - ) printconj(rL2) prin()
printdis(S[Lj) - printcbar(SL)
33
printdis(S[LILs]) - printchu(SL) prin( v) printdis(SLs)
printconl(S[LI) - printchar(SL)
printconl(S[LILs]) - printchar(SL) prin( ) printconl(SLs)
printconj(S[L]) - tab(3) printchar(SL)
prin tconj( S [L IL sl) shy
tab(3) printchar(SL) print( ) printconj(SLs)
printchar(SP) shy
atomic(P)
name(P L)
L = [IT]
concat([XIT NewP)
prin(~ewP)
printchar(SP) shy
atomic(P)
prin(P)
printchar(SA lt= gt B) -
prin((l clausify(A AI [j) pl(eAl) prin())
print lt=gt )
prin(() cbusify(B Bl [I) pJ(eBl) prine))middot
printchar(rnumber(X N)) shy
prin(num() printchar(rx) prin( )
printchar(rN) prinC))
printchar(rF(A B)) shy
seJec(F(A B))
prinCsel() printchar(rA)
prin( F ) printchar(rB) prinC))
printchar(SF(A B)) shy
( selec(F(A B)) F = infix )
printchar(SA) prin( F ) printchar(SB)
printchar(SF(A)) shy
(F= prefix gt= F= prefix lt= F= prefixgt F= prefix lt )
prin(F ) printcbar(SA)
printchar(SP) shy
functor(P F MaxN)
prin(F ()
Nl is MaxN - 1
putout(S N 1 P MaxN)
34
prin())
putout(S 0 P MaxN) -
arg(~laxN P Argu)
prin tchar(SArgu)
putout(S N p MaxN) shy
Nt is MaxN - N arg(NI P Argu)
printcbar(SArgu )
prin( )
N2 is N - 1
putout(S N2 P MaxN)
selec(FA B)) shy
( F= infix = F= infix f= F= infix gt=
F= infix gt F= infix lt= F= infix lt )
35
----------------------------------Program Name APClS - Part 2 Inference Mechanism ---------------------------------- a(X) shy
steps(X X9)
(( X9 =[] nl
print( yes it is always true) )
( X9 =[cI(IJ[])] nl
print( no it is always false) )
( nl nl printel(X9) Step 1Oa
tell(temp_file) printel(X9) e1ose(temp_file) consult(temp_6Ie) ))
q(X) shy
asserta( in pt(X))
steps(X X9)
(( X9 = [] print(middot~H~~middot~t~)
print(THE AiSWER IS YES)
print( ilgIQlQl(~) )
( X9 = [e1([j [j)] Pr1nt ( OJ fi(i I~ iii Ij)middot(i)(i) fiyenQ)riiio(i)(ij)(i)fj)fiyen1li1il1li1il)__ gtw~ __~_~ _~~_ ~_-=~
print(THE ANSWER IS NO ) print() )
( teI1(temp_6Ie)
prques(X9) Step 1Ob
close(temp_file)
nl print(Let me think about it) nl
consult(temp_6Ie) ))
retrac t( in pt(X))
Step lOb Printing question
prques(lcl(A 8)1) - prin(goo(() pl(qA 8) print()))
prques([c1(A 8HCs]) - prin(goo(() pl(qA 8) print() pl(q Cs)
pl(e [c1(A 8)]) - pl(eA 8)
pl(q [c1(A 8)]) - pl(qA 8) print()))
pl(S [e1(A B)ICs]) - pl(SA B) prin( ) pl(S Cs)
38
pl(q [j L) - prin(c1ause(contradiction(() pcont(qL) prin())_))
pl(S [I L)- prin(so2(contradidion(() pcont(SL) print))))middot
pl(S [L] []) - prin(so2() pcbar(SL) prin())
pl(S L [J)- prinsol() plett(SL) print))
pl(S [L] LI) - prin(condi(() pchar(cL)
prin(() pcont(S Ll) prine))))
pl(S L Ll)- prin(c1ause() plert(cL)
prin(() pcont(S Ll) prine)))
plert(S[LJ) - pchar(SL)
plert(SjLILsj) - pcbar(SL) print v) pleCt(SLs)
pcont(S[L]) - pchar(SL)
pcont(S[LILsj) - pcbar(SL) prinr ) pcont(SLs)
pcbar(SP) shy
atomic(P)
name(PL)
( L = [IT] L = [5 k miT] L = [5 k niT] )
concat[XITj NewP)
prin(0JewP)
pchar(SP) shy
atomic(P)
prin(P) pchar(SA lt=gt B) -
prin(() dausify(A AI []) pl(eAI) prin())
prinr lt=gt ) prin(() dausify(B BI ]) pl(eB) print))
pchar(Snumber(X N)) shy
prin(num() pchar(SX) prin()
pchar(SN) prinr))
pcbar(SM N) - prin(M N)
pcbar(cF(A B)) shy
selec(F(A Braquo
pcbar(cA)
prine F ) pchar(cB) pchar(SF(A B)) shy
selec(F(A B))
prin(sel() pchar(SA)
print F ) pchar(SB) print)) I
31
pc har(SF(A)) shy
( F= prefix gt= F= prefix lt= F= prefixgt F= prefix lt )
prin(F ) pchar(SA)
pchar(SP)shy
runctor(P F MaxN)
prin(F ()
011 is MaxN - 1 pout(SNl P MaxN)
print) )
pout(S 0 P M3xN) - 1
arg(~bxN P Argu)
pchlr(SArgu )
pout(S N P MaxN shy
Nl is MaxN - N
arg(Nl P Argu)
pchar(SArgu
prin( )
N2 is N - 1
pout(S N2 P ~13xN)
Comparing numbers in numerical quantifiers
num(XN) shy
number(X I)
cnum(N 1) ~
cnumlaquo=01 lt=I- N gt=I
cnumlaquo=J lt I) - N gt=1-1
cnumlaquo=NIJ) - N gt=J 1
cnumlaquo=N J)- integer(I) N gt=I~
cnum(gt=N gt=1) - N lt=1
cnum(gt=N gt I) - N lt=1+ 1 cnum(gt=NIJ) - N lt=1
cnum(gt=N lt=1)- N lt=1
cnum(gt=N lt I) - N lt=1 L cnum(gt=N 1)- integer(I) N lt=1
cnum( lt N lt 1)- N gt=1 L
38
cnum( lt N lt=1) - N gt I cnum( lt NLJ) - N gt J
cnum( lt N 1)- integer(I) N gt 1
cnum(gt N gt I) - N lt=1 cnumlgt i gt=1) - N lt I
cnum(gt N lt=1) - N lt=0
cnum(gt N lt I) - N lt=0
cnum(gt iIJ) - N lt I cnum(gt N 1)- integer(I) N lt I
cnum(~LN lt=1) - M=I N gt= I l
cnum(~LN lt I) - M=l N gt= I-I
cnum(~LNLJ) - M lt =1 N gt = J
cnum(~1N 1)- integer(I) M lt= I N gt= I
cnum(- N) - integer(N)
Comparing selectors
sel(X = Y) shyX= Y
sel(X I=Y) shy(X I=Y X lt Y Xgt Y)
sel(X gt Y) shyXgt Y
sel(X lt Y) shyXlt Y
selX gt=Y) shy(X gt=Y X= Y Xgt Y)
se(X lt=Y) shy
(X lt=Y
X= Y
X lt Y)
csel(infix = infix =)
39
csel(infix = infix = csel(infix = infix gt)
csel(infix = infix lt) csel(infix gt infix gt) cseJ(infix lt infix lt) csel(infix gt= infix gt=) csel(infix gt= infix gt csel(infix gt= infix =)
csellinfix lt= infix lt=) csel(infix lt= infix lt) csel(infix lt= infix =)
Finding solutions
sol(X v Y) -
(( notetra(X) eon(X) ( sol(Y) )
( c1ause(P v Q R) not(cketra(P v Q))
dis(P v Q X v Y R) ~ )
( A lt=gt B equival(A lt=gt B X v Y) ~ I) sol(X) - ~ notetra(X) eon(X)
so~(X) - notetra(X)
( con (X)
( clause(P v Q R) not(ekctra(P v Q)) dis(P v Q X R) I)
cketra(P v Q) -
eketra(P) eketra(Q) eketra(F(I J)) shy
selec(F(I J))
c1ause(contradiction(sel(F(IJ))) _I
eketra(number(W I)) -
clause(cootradietion(num(Wl)) - eketr(P) shy
clause(contradiction(P) - 1
notctra(P) shy
not( e lause( con tradiction(P) _))
40
Searching (or disjunctions
dis(P v Q X v Y R) - dis(P X v Y R)
dis(Q X v Y R) con(R)
dis(P v Q X R) -
dis(P X R) dis(Q X R) con(R
dis(P X v Y R) - clause(contradicton(Pl J 1
dis(F(I J) sel(G(I J)) v Y R) - csel(G Fl dis(number(WI) num(W N v Y R) - cnum(N I)
dis(P P v Y R) -
dis(P X v Y R) - dis(P Y R)
dis(F(I J) seJ(G(IJ)) R) - csel(G F)
dis(number(WI) num(WN) R) - cnum(N I) dis(P P R) - 1
dis(FJ J X R) shy
( ckctra(F(IJ) cbeckeq(seJ(F(IJ))) )
dis(number(W Il X R) - ( ckctra(number(WI)) cbeckeq(num(WI)) )
dis(P X R) shy( ckctra(P) cbeckeq(P) ) 1
cbeckeq(P) shy
(( A lt=gt so2(contradiction(P))
bagof(A A [jj) ) ( so2(contradiction(P)) lt=gt B
bagof(B B Uj) ))
ckeq(A) shy
( so2(A) lt=gt B B lt=gt so2(A) ) bagof(B B UJ)
con((P Q)) -
clause(P R) con(R) con(Q) con(true) -
con(contradiction(P)) - clause(contradiction(P) J
con(cause(X Y)) - cause(X Y)
con(sel(X)) - sel(X)
con(num(X Y)) - num(X Y) con(P)- (( dause(P R) (con(R) ckeq(R)))
colJectin(P) )
collectin(P) shy
bagof(S (c1ause(P S) S = true) [L LIJ )
mkcon(L Ll L)
bagor(l (L2 ) UJ) L
mkcon((A AI) (B B1) (sol(A v B) e D)) -
mkcon(A B1 e) mkcon(A1 (B Bl) D)
mkcon(A (B B1) (sol(A v B) e)) -
mkcon(A Bl e)
mkcon((A AI) B (sol(A v B) e)) middot1
mkcon(Al B e)
mkcon(A B sol(A vB))
Searching ror equivalences
equival(A lt=gt B X v Y) - 1 ( equival(A lt=gt B X) equival(A lt=gt B Y) )
equival(s02(A) lt=gt 502(B) A) - clause(B _I equival(s02(B) lt=gt 502(A) A) c1ause(B _I
Top level or inrerence mechanism
goo((s02(whatnum) P)) -
getatm(P Xl
bagor(number(X Y) ( P so2(number(X Y)) ) A )
count1(A 00 L R) nl
bagor(X P B )
count2(B L R Ll Rl) nJ print()
(( LI = 0 Rl = 0 print(THE ANSWER IS ) nl
(( Ll = Rl prin(-Jumber or ) prn(P) print(is Ll) )
( Rlgt20000 prin(Number or I prn(P) print(is LI or more) )
42
( prin(Number of ) pfn(P) print( is from Ll to Rl) )) )
( print(THE ANSWER IS NO I )) print()
goo(X) shy
(( bagof(X X L) L = [I nl print()
print(THE ANSWER IS YES) nl wout(L) print() )
( equiv(X L) nl print()
print(THE ANSWER IS YES) nl wout(L) print(-) )
( c1ause(inpt(A ==gt B) _I ( impli(A B Z) impli(B A Z) ) print(l~Hl)
printTHE ANSWER IS YES) nl print(Z) print(Hj~(fH~) ))
goo(X) print( Hg)
print(THE ANSWER IS NO ) print( lH~lH~gg9l9lmiddotmiddot~Q(gmiddot)
00 Semhing for implications in equiV3lent relations
impli( B Z) shyt-ell( z1) prin(templ() pchn(S A lt=gt B) print()) close ( zl) consult(zl) templ(Z)
unload zl Z
Searching for equivalence
equiv (X L)
(( X lt=gt Y
equ(Y YI)t bagof(Y Yl L) L = [j )
(Y lt=gt X equ(Y YI) bagof(Y Yl L) L = [J )
( X = F(New)
clause(~ew T) makeup(T Tl)
(( Tl lt=gt B
equ(B Bl) bagof(Bl Bl M) M = [j L=[Newl )
(A lt=gt TI
equ(A AI) bagof(Al AI M) M = 1] L=INewj )) ))
makeup((A B) (AI Bl)) -
makeup(A A1) makeup(B BI)
makeup(A so2(A))
equ((A B) (AI BI)) -
equ(A AI) equ(B Bl)
equ(sol(X v Y) sol(XI v Yl)) -
equ(X XI) equ(Y YI)
equ(so2(X) so2(XI)) -
equ(X XI)
equ(contradiction(X) clJuse(contradiction(X) X) ) -
equ(X X)
Counting numbers
getatm((A B) X) -
( getatm(A X) getatm(B X) )
getatm(so2(F(X)) X) -
getatm(so2(X) X) - atom(X)
countl([J L R L R) -
countl([number(X Y)IT] L R L2 R2) shy
(( Y = (gt=~) LI is L + N Rl is R + 20001 l )
( Y = (gt N) LI is L+ N+ 1 RI is R + 20002 )
(Y == laquo=~) LI is L + 1 Rl is R + N )
(Y = laquo N) LI is L + 1 RI is R+N-I)
(Y == IJ LI is L + I Rl is R + J ) ( Y == N L1 is L + N RI is R + N ))
count1(T LI R 1 L2 R2)
count2(fJ L R L R) - 1
count2([XITJ L R L2 R2) shy
name(X Xl)
(( Xl = sknj LI is L Rl is R )
44
( Xl = Iskmj L1 is L + 1 RI is R + ZOOO1) ( LI is L + I RI is R + I ))
count2(T LI RI L2 R2)
pfn((A B)) - pfn(A) prn(B)
pCn(so2(F(X))) - prin(F )
prn(so2(X)) - atom(X) prin(X ) prn (so2(X))
Printing result
wout([XlJ - prt(X) nl woutf[xIY]) - prt(X) nl nl wout(Y)
prt(e(A B)) -
prt(A) prinr 8 ) prt(ltE) prt(eA) - prt(A)
prt(c(A EJ) - prin() prt(A) prine ) prt(B) prin(T)
prt(c A) - prt(A) prt((A E)) - ~
prt(A) nl prt(E) prt(sol(X v Y)) - ~
prt(X) prinC v) prt(Y) prt(A lt=gt B) -
prt(e A) prinC lt=gt ) prt(e B) prt(sol(X)) - prt(X)
prt(so2(X)) - prt(X
prt(c1ause(X Y)) - prt(X)
prt(contradiction(X)) - prin(contradiction() prt(cX) prinr))middot prt(num(XY)) - prin(number(X Y)) prt(sel(X)) - prin(X) prt(X v Y) - prt(X) prin( v) prt(Y) prt(X) prin(X)
Handling conditional queries
condi((Y Xl) shy
assertcon(X) Y
45
retractcon(X)
condi((B A))
retractcon(A) fail
assertcon((A B)) 1
assertcon(A) assertcon(B)
assertcon(A) asserta(A)
retrac teon ((A B)) 1
retracteon(A) retractcon (B)
retraetcon(A) - retract(A)
BIBLIOGRAPHIC DATA SHEET
Report No UIUCDS-F-84-928
3 Recipients Accession No
4 T ide and Subt ltle
An Annotated Predicate Calculus Inference System (APCIS)
S Report Date
November 1984 6
7 Author(s)
Kah-Eng Pua 8 Performing Organization Rept
No
9 Performing Organization Name and Address
Department of Computer Science University of Illinois Urbana IL
10 ProjectTaskWork Unit No
11 Contract Grant No NSF DCR 84-06081 ONR N00014-82-K-0186
12 Sponsoring Organization Name and Address
National Science Foundation Washington DC
13 Type of Report amp Period Covered
14
15 Supplementary Notes
16 Abstracts
This paper describes a deductive inference system called APCIS (Annotated Predicate Calculus Inference System) APCIS is able to carry out inferences from expressions involving numerical quantifiers selectors disjunctions of non-negated terms negated terms disjunctions of negated terms equivalences and exceptions It is also able to count the numbers of occurrence of a given simple term or a conjunction of terms The design of contradiction and the treatment of the disjunction of non-negated terms allow APCIS to accept Horn clauses as well as non-Horn clauses and to carry out inferences from them This feature makes APCIS more general than Prolog
17 Key lords and Document Analysis 170 Descriptors
APC (Annotated Predicate Calculus) APCIS (Annotated Predicate Calculus Inference System) Horn Clause Numerical Quantifier Prolog Selector
17b IdentifiersOpen-Ended Terms
17c COSATI FieldGroup
18 Availability Statement 19 Security Class (This
Re~f~~IA~SIF IFf)
21 ~o of Pages
49 211 ecurity Class (This
PageUNCLASSIFIED
22 Price
FOA NTIS n (10middot70 usco-oc 40329-
33
printdis(S[LILs]) - printchu(SL) prin( v) printdis(SLs)
printconl(S[LI) - printchar(SL)
printconl(S[LILs]) - printchar(SL) prin( ) printconl(SLs)
printconj(S[L]) - tab(3) printchar(SL)
prin tconj( S [L IL sl) shy
tab(3) printchar(SL) print( ) printconj(SLs)
printchar(SP) shy
atomic(P)
name(P L)
L = [IT]
concat([XIT NewP)
prin(~ewP)
printchar(SP) shy
atomic(P)
prin(P)
printchar(SA lt= gt B) -
prin((l clausify(A AI [j) pl(eAl) prin())
print lt=gt )
prin(() cbusify(B Bl [I) pJ(eBl) prine))middot
printchar(rnumber(X N)) shy
prin(num() printchar(rx) prin( )
printchar(rN) prinC))
printchar(rF(A B)) shy
seJec(F(A B))
prinCsel() printchar(rA)
prin( F ) printchar(rB) prinC))
printchar(SF(A B)) shy
( selec(F(A B)) F = infix )
printchar(SA) prin( F ) printchar(SB)
printchar(SF(A)) shy
(F= prefix gt= F= prefix lt= F= prefixgt F= prefix lt )
prin(F ) printcbar(SA)
printchar(SP) shy
functor(P F MaxN)
prin(F ()
Nl is MaxN - 1
putout(S N 1 P MaxN)
34
prin())
putout(S 0 P MaxN) -
arg(~laxN P Argu)
prin tchar(SArgu)
putout(S N p MaxN) shy
Nt is MaxN - N arg(NI P Argu)
printcbar(SArgu )
prin( )
N2 is N - 1
putout(S N2 P MaxN)
selec(FA B)) shy
( F= infix = F= infix f= F= infix gt=
F= infix gt F= infix lt= F= infix lt )
35
----------------------------------Program Name APClS - Part 2 Inference Mechanism ---------------------------------- a(X) shy
steps(X X9)
(( X9 =[] nl
print( yes it is always true) )
( X9 =[cI(IJ[])] nl
print( no it is always false) )
( nl nl printel(X9) Step 1Oa
tell(temp_file) printel(X9) e1ose(temp_file) consult(temp_6Ie) ))
q(X) shy
asserta( in pt(X))
steps(X X9)
(( X9 = [] print(middot~H~~middot~t~)
print(THE AiSWER IS YES)
print( ilgIQlQl(~) )
( X9 = [e1([j [j)] Pr1nt ( OJ fi(i I~ iii Ij)middot(i)(i) fiyenQ)riiio(i)(ij)(i)fj)fiyen1li1il1li1il)__ gtw~ __~_~ _~~_ ~_-=~
print(THE ANSWER IS NO ) print() )
( teI1(temp_6Ie)
prques(X9) Step 1Ob
close(temp_file)
nl print(Let me think about it) nl
consult(temp_6Ie) ))
retrac t( in pt(X))
Step lOb Printing question
prques(lcl(A 8)1) - prin(goo(() pl(qA 8) print()))
prques([c1(A 8HCs]) - prin(goo(() pl(qA 8) print() pl(q Cs)
pl(e [c1(A 8)]) - pl(eA 8)
pl(q [c1(A 8)]) - pl(qA 8) print()))
pl(S [e1(A B)ICs]) - pl(SA B) prin( ) pl(S Cs)
38
pl(q [j L) - prin(c1ause(contradiction(() pcont(qL) prin())_))
pl(S [I L)- prin(so2(contradidion(() pcont(SL) print))))middot
pl(S [L] []) - prin(so2() pcbar(SL) prin())
pl(S L [J)- prinsol() plett(SL) print))
pl(S [L] LI) - prin(condi(() pchar(cL)
prin(() pcont(S Ll) prine))))
pl(S L Ll)- prin(c1ause() plert(cL)
prin(() pcont(S Ll) prine)))
plert(S[LJ) - pchar(SL)
plert(SjLILsj) - pcbar(SL) print v) pleCt(SLs)
pcont(S[L]) - pchar(SL)
pcont(S[LILsj) - pcbar(SL) prinr ) pcont(SLs)
pcbar(SP) shy
atomic(P)
name(PL)
( L = [IT] L = [5 k miT] L = [5 k niT] )
concat[XITj NewP)
prin(0JewP)
pchar(SP) shy
atomic(P)
prin(P) pchar(SA lt=gt B) -
prin(() dausify(A AI []) pl(eAI) prin())
prinr lt=gt ) prin(() dausify(B BI ]) pl(eB) print))
pchar(Snumber(X N)) shy
prin(num() pchar(SX) prin()
pchar(SN) prinr))
pcbar(SM N) - prin(M N)
pcbar(cF(A B)) shy
selec(F(A Braquo
pcbar(cA)
prine F ) pchar(cB) pchar(SF(A B)) shy
selec(F(A B))
prin(sel() pchar(SA)
print F ) pchar(SB) print)) I
31
pc har(SF(A)) shy
( F= prefix gt= F= prefix lt= F= prefixgt F= prefix lt )
prin(F ) pchar(SA)
pchar(SP)shy
runctor(P F MaxN)
prin(F ()
011 is MaxN - 1 pout(SNl P MaxN)
print) )
pout(S 0 P M3xN) - 1
arg(~bxN P Argu)
pchlr(SArgu )
pout(S N P MaxN shy
Nl is MaxN - N
arg(Nl P Argu)
pchar(SArgu
prin( )
N2 is N - 1
pout(S N2 P ~13xN)
Comparing numbers in numerical quantifiers
num(XN) shy
number(X I)
cnum(N 1) ~
cnumlaquo=01 lt=I- N gt=I
cnumlaquo=J lt I) - N gt=1-1
cnumlaquo=NIJ) - N gt=J 1
cnumlaquo=N J)- integer(I) N gt=I~
cnum(gt=N gt=1) - N lt=1
cnum(gt=N gt I) - N lt=1+ 1 cnum(gt=NIJ) - N lt=1
cnum(gt=N lt=1)- N lt=1
cnum(gt=N lt I) - N lt=1 L cnum(gt=N 1)- integer(I) N lt=1
cnum( lt N lt 1)- N gt=1 L
38
cnum( lt N lt=1) - N gt I cnum( lt NLJ) - N gt J
cnum( lt N 1)- integer(I) N gt 1
cnum(gt N gt I) - N lt=1 cnumlgt i gt=1) - N lt I
cnum(gt N lt=1) - N lt=0
cnum(gt N lt I) - N lt=0
cnum(gt iIJ) - N lt I cnum(gt N 1)- integer(I) N lt I
cnum(~LN lt=1) - M=I N gt= I l
cnum(~LN lt I) - M=l N gt= I-I
cnum(~LNLJ) - M lt =1 N gt = J
cnum(~1N 1)- integer(I) M lt= I N gt= I
cnum(- N) - integer(N)
Comparing selectors
sel(X = Y) shyX= Y
sel(X I=Y) shy(X I=Y X lt Y Xgt Y)
sel(X gt Y) shyXgt Y
sel(X lt Y) shyXlt Y
selX gt=Y) shy(X gt=Y X= Y Xgt Y)
se(X lt=Y) shy
(X lt=Y
X= Y
X lt Y)
csel(infix = infix =)
39
csel(infix = infix = csel(infix = infix gt)
csel(infix = infix lt) csel(infix gt infix gt) cseJ(infix lt infix lt) csel(infix gt= infix gt=) csel(infix gt= infix gt csel(infix gt= infix =)
csellinfix lt= infix lt=) csel(infix lt= infix lt) csel(infix lt= infix =)
Finding solutions
sol(X v Y) -
(( notetra(X) eon(X) ( sol(Y) )
( c1ause(P v Q R) not(cketra(P v Q))
dis(P v Q X v Y R) ~ )
( A lt=gt B equival(A lt=gt B X v Y) ~ I) sol(X) - ~ notetra(X) eon(X)
so~(X) - notetra(X)
( con (X)
( clause(P v Q R) not(ekctra(P v Q)) dis(P v Q X R) I)
cketra(P v Q) -
eketra(P) eketra(Q) eketra(F(I J)) shy
selec(F(I J))
c1ause(contradiction(sel(F(IJ))) _I
eketra(number(W I)) -
clause(cootradietion(num(Wl)) - eketr(P) shy
clause(contradiction(P) - 1
notctra(P) shy
not( e lause( con tradiction(P) _))
40
Searching (or disjunctions
dis(P v Q X v Y R) - dis(P X v Y R)
dis(Q X v Y R) con(R)
dis(P v Q X R) -
dis(P X R) dis(Q X R) con(R
dis(P X v Y R) - clause(contradicton(Pl J 1
dis(F(I J) sel(G(I J)) v Y R) - csel(G Fl dis(number(WI) num(W N v Y R) - cnum(N I)
dis(P P v Y R) -
dis(P X v Y R) - dis(P Y R)
dis(F(I J) seJ(G(IJ)) R) - csel(G F)
dis(number(WI) num(WN) R) - cnum(N I) dis(P P R) - 1
dis(FJ J X R) shy
( ckctra(F(IJ) cbeckeq(seJ(F(IJ))) )
dis(number(W Il X R) - ( ckctra(number(WI)) cbeckeq(num(WI)) )
dis(P X R) shy( ckctra(P) cbeckeq(P) ) 1
cbeckeq(P) shy
(( A lt=gt so2(contradiction(P))
bagof(A A [jj) ) ( so2(contradiction(P)) lt=gt B
bagof(B B Uj) ))
ckeq(A) shy
( so2(A) lt=gt B B lt=gt so2(A) ) bagof(B B UJ)
con((P Q)) -
clause(P R) con(R) con(Q) con(true) -
con(contradiction(P)) - clause(contradiction(P) J
con(cause(X Y)) - cause(X Y)
con(sel(X)) - sel(X)
con(num(X Y)) - num(X Y) con(P)- (( dause(P R) (con(R) ckeq(R)))
colJectin(P) )
collectin(P) shy
bagof(S (c1ause(P S) S = true) [L LIJ )
mkcon(L Ll L)
bagor(l (L2 ) UJ) L
mkcon((A AI) (B B1) (sol(A v B) e D)) -
mkcon(A B1 e) mkcon(A1 (B Bl) D)
mkcon(A (B B1) (sol(A v B) e)) -
mkcon(A Bl e)
mkcon((A AI) B (sol(A v B) e)) middot1
mkcon(Al B e)
mkcon(A B sol(A vB))
Searching ror equivalences
equival(A lt=gt B X v Y) - 1 ( equival(A lt=gt B X) equival(A lt=gt B Y) )
equival(s02(A) lt=gt 502(B) A) - clause(B _I equival(s02(B) lt=gt 502(A) A) c1ause(B _I
Top level or inrerence mechanism
goo((s02(whatnum) P)) -
getatm(P Xl
bagor(number(X Y) ( P so2(number(X Y)) ) A )
count1(A 00 L R) nl
bagor(X P B )
count2(B L R Ll Rl) nJ print()
(( LI = 0 Rl = 0 print(THE ANSWER IS ) nl
(( Ll = Rl prin(-Jumber or ) prn(P) print(is Ll) )
( Rlgt20000 prin(Number or I prn(P) print(is LI or more) )
42
( prin(Number of ) pfn(P) print( is from Ll to Rl) )) )
( print(THE ANSWER IS NO I )) print()
goo(X) shy
(( bagof(X X L) L = [I nl print()
print(THE ANSWER IS YES) nl wout(L) print() )
( equiv(X L) nl print()
print(THE ANSWER IS YES) nl wout(L) print(-) )
( c1ause(inpt(A ==gt B) _I ( impli(A B Z) impli(B A Z) ) print(l~Hl)
printTHE ANSWER IS YES) nl print(Z) print(Hj~(fH~) ))
goo(X) print( Hg)
print(THE ANSWER IS NO ) print( lH~lH~gg9l9lmiddotmiddot~Q(gmiddot)
00 Semhing for implications in equiV3lent relations
impli( B Z) shyt-ell( z1) prin(templ() pchn(S A lt=gt B) print()) close ( zl) consult(zl) templ(Z)
unload zl Z
Searching for equivalence
equiv (X L)
(( X lt=gt Y
equ(Y YI)t bagof(Y Yl L) L = [j )
(Y lt=gt X equ(Y YI) bagof(Y Yl L) L = [J )
( X = F(New)
clause(~ew T) makeup(T Tl)
(( Tl lt=gt B
equ(B Bl) bagof(Bl Bl M) M = [j L=[Newl )
(A lt=gt TI
equ(A AI) bagof(Al AI M) M = 1] L=INewj )) ))
makeup((A B) (AI Bl)) -
makeup(A A1) makeup(B BI)
makeup(A so2(A))
equ((A B) (AI BI)) -
equ(A AI) equ(B Bl)
equ(sol(X v Y) sol(XI v Yl)) -
equ(X XI) equ(Y YI)
equ(so2(X) so2(XI)) -
equ(X XI)
equ(contradiction(X) clJuse(contradiction(X) X) ) -
equ(X X)
Counting numbers
getatm((A B) X) -
( getatm(A X) getatm(B X) )
getatm(so2(F(X)) X) -
getatm(so2(X) X) - atom(X)
countl([J L R L R) -
countl([number(X Y)IT] L R L2 R2) shy
(( Y = (gt=~) LI is L + N Rl is R + 20001 l )
( Y = (gt N) LI is L+ N+ 1 RI is R + 20002 )
(Y == laquo=~) LI is L + 1 Rl is R + N )
(Y = laquo N) LI is L + 1 RI is R+N-I)
(Y == IJ LI is L + I Rl is R + J ) ( Y == N L1 is L + N RI is R + N ))
count1(T LI R 1 L2 R2)
count2(fJ L R L R) - 1
count2([XITJ L R L2 R2) shy
name(X Xl)
(( Xl = sknj LI is L Rl is R )
44
( Xl = Iskmj L1 is L + 1 RI is R + ZOOO1) ( LI is L + I RI is R + I ))
count2(T LI RI L2 R2)
pfn((A B)) - pfn(A) prn(B)
pCn(so2(F(X))) - prin(F )
prn(so2(X)) - atom(X) prin(X ) prn (so2(X))
Printing result
wout([XlJ - prt(X) nl woutf[xIY]) - prt(X) nl nl wout(Y)
prt(e(A B)) -
prt(A) prinr 8 ) prt(ltE) prt(eA) - prt(A)
prt(c(A EJ) - prin() prt(A) prine ) prt(B) prin(T)
prt(c A) - prt(A) prt((A E)) - ~
prt(A) nl prt(E) prt(sol(X v Y)) - ~
prt(X) prinC v) prt(Y) prt(A lt=gt B) -
prt(e A) prinC lt=gt ) prt(e B) prt(sol(X)) - prt(X)
prt(so2(X)) - prt(X
prt(c1ause(X Y)) - prt(X)
prt(contradiction(X)) - prin(contradiction() prt(cX) prinr))middot prt(num(XY)) - prin(number(X Y)) prt(sel(X)) - prin(X) prt(X v Y) - prt(X) prin( v) prt(Y) prt(X) prin(X)
Handling conditional queries
condi((Y Xl) shy
assertcon(X) Y
45
retractcon(X)
condi((B A))
retractcon(A) fail
assertcon((A B)) 1
assertcon(A) assertcon(B)
assertcon(A) asserta(A)
retrac teon ((A B)) 1
retracteon(A) retractcon (B)
retraetcon(A) - retract(A)
BIBLIOGRAPHIC DATA SHEET
Report No UIUCDS-F-84-928
3 Recipients Accession No
4 T ide and Subt ltle
An Annotated Predicate Calculus Inference System (APCIS)
S Report Date
November 1984 6
7 Author(s)
Kah-Eng Pua 8 Performing Organization Rept
No
9 Performing Organization Name and Address
Department of Computer Science University of Illinois Urbana IL
10 ProjectTaskWork Unit No
11 Contract Grant No NSF DCR 84-06081 ONR N00014-82-K-0186
12 Sponsoring Organization Name and Address
National Science Foundation Washington DC
13 Type of Report amp Period Covered
14
15 Supplementary Notes
16 Abstracts
This paper describes a deductive inference system called APCIS (Annotated Predicate Calculus Inference System) APCIS is able to carry out inferences from expressions involving numerical quantifiers selectors disjunctions of non-negated terms negated terms disjunctions of negated terms equivalences and exceptions It is also able to count the numbers of occurrence of a given simple term or a conjunction of terms The design of contradiction and the treatment of the disjunction of non-negated terms allow APCIS to accept Horn clauses as well as non-Horn clauses and to carry out inferences from them This feature makes APCIS more general than Prolog
17 Key lords and Document Analysis 170 Descriptors
APC (Annotated Predicate Calculus) APCIS (Annotated Predicate Calculus Inference System) Horn Clause Numerical Quantifier Prolog Selector
17b IdentifiersOpen-Ended Terms
17c COSATI FieldGroup
18 Availability Statement 19 Security Class (This
Re~f~~IA~SIF IFf)
21 ~o of Pages
49 211 ecurity Class (This
PageUNCLASSIFIED
22 Price
FOA NTIS n (10middot70 usco-oc 40329-
34
prin())
putout(S 0 P MaxN) -
arg(~laxN P Argu)
prin tchar(SArgu)
putout(S N p MaxN) shy
Nt is MaxN - N arg(NI P Argu)
printcbar(SArgu )
prin( )
N2 is N - 1
putout(S N2 P MaxN)
selec(FA B)) shy
( F= infix = F= infix f= F= infix gt=
F= infix gt F= infix lt= F= infix lt )
35
----------------------------------Program Name APClS - Part 2 Inference Mechanism ---------------------------------- a(X) shy
steps(X X9)
(( X9 =[] nl
print( yes it is always true) )
( X9 =[cI(IJ[])] nl
print( no it is always false) )
( nl nl printel(X9) Step 1Oa
tell(temp_file) printel(X9) e1ose(temp_file) consult(temp_6Ie) ))
q(X) shy
asserta( in pt(X))
steps(X X9)
(( X9 = [] print(middot~H~~middot~t~)
print(THE AiSWER IS YES)
print( ilgIQlQl(~) )
( X9 = [e1([j [j)] Pr1nt ( OJ fi(i I~ iii Ij)middot(i)(i) fiyenQ)riiio(i)(ij)(i)fj)fiyen1li1il1li1il)__ gtw~ __~_~ _~~_ ~_-=~
print(THE ANSWER IS NO ) print() )
( teI1(temp_6Ie)
prques(X9) Step 1Ob
close(temp_file)
nl print(Let me think about it) nl
consult(temp_6Ie) ))
retrac t( in pt(X))
Step lOb Printing question
prques(lcl(A 8)1) - prin(goo(() pl(qA 8) print()))
prques([c1(A 8HCs]) - prin(goo(() pl(qA 8) print() pl(q Cs)
pl(e [c1(A 8)]) - pl(eA 8)
pl(q [c1(A 8)]) - pl(qA 8) print()))
pl(S [e1(A B)ICs]) - pl(SA B) prin( ) pl(S Cs)
38
pl(q [j L) - prin(c1ause(contradiction(() pcont(qL) prin())_))
pl(S [I L)- prin(so2(contradidion(() pcont(SL) print))))middot
pl(S [L] []) - prin(so2() pcbar(SL) prin())
pl(S L [J)- prinsol() plett(SL) print))
pl(S [L] LI) - prin(condi(() pchar(cL)
prin(() pcont(S Ll) prine))))
pl(S L Ll)- prin(c1ause() plert(cL)
prin(() pcont(S Ll) prine)))
plert(S[LJ) - pchar(SL)
plert(SjLILsj) - pcbar(SL) print v) pleCt(SLs)
pcont(S[L]) - pchar(SL)
pcont(S[LILsj) - pcbar(SL) prinr ) pcont(SLs)
pcbar(SP) shy
atomic(P)
name(PL)
( L = [IT] L = [5 k miT] L = [5 k niT] )
concat[XITj NewP)
prin(0JewP)
pchar(SP) shy
atomic(P)
prin(P) pchar(SA lt=gt B) -
prin(() dausify(A AI []) pl(eAI) prin())
prinr lt=gt ) prin(() dausify(B BI ]) pl(eB) print))
pchar(Snumber(X N)) shy
prin(num() pchar(SX) prin()
pchar(SN) prinr))
pcbar(SM N) - prin(M N)
pcbar(cF(A B)) shy
selec(F(A Braquo
pcbar(cA)
prine F ) pchar(cB) pchar(SF(A B)) shy
selec(F(A B))
prin(sel() pchar(SA)
print F ) pchar(SB) print)) I
31
pc har(SF(A)) shy
( F= prefix gt= F= prefix lt= F= prefixgt F= prefix lt )
prin(F ) pchar(SA)
pchar(SP)shy
runctor(P F MaxN)
prin(F ()
011 is MaxN - 1 pout(SNl P MaxN)
print) )
pout(S 0 P M3xN) - 1
arg(~bxN P Argu)
pchlr(SArgu )
pout(S N P MaxN shy
Nl is MaxN - N
arg(Nl P Argu)
pchar(SArgu
prin( )
N2 is N - 1
pout(S N2 P ~13xN)
Comparing numbers in numerical quantifiers
num(XN) shy
number(X I)
cnum(N 1) ~
cnumlaquo=01 lt=I- N gt=I
cnumlaquo=J lt I) - N gt=1-1
cnumlaquo=NIJ) - N gt=J 1
cnumlaquo=N J)- integer(I) N gt=I~
cnum(gt=N gt=1) - N lt=1
cnum(gt=N gt I) - N lt=1+ 1 cnum(gt=NIJ) - N lt=1
cnum(gt=N lt=1)- N lt=1
cnum(gt=N lt I) - N lt=1 L cnum(gt=N 1)- integer(I) N lt=1
cnum( lt N lt 1)- N gt=1 L
38
cnum( lt N lt=1) - N gt I cnum( lt NLJ) - N gt J
cnum( lt N 1)- integer(I) N gt 1
cnum(gt N gt I) - N lt=1 cnumlgt i gt=1) - N lt I
cnum(gt N lt=1) - N lt=0
cnum(gt N lt I) - N lt=0
cnum(gt iIJ) - N lt I cnum(gt N 1)- integer(I) N lt I
cnum(~LN lt=1) - M=I N gt= I l
cnum(~LN lt I) - M=l N gt= I-I
cnum(~LNLJ) - M lt =1 N gt = J
cnum(~1N 1)- integer(I) M lt= I N gt= I
cnum(- N) - integer(N)
Comparing selectors
sel(X = Y) shyX= Y
sel(X I=Y) shy(X I=Y X lt Y Xgt Y)
sel(X gt Y) shyXgt Y
sel(X lt Y) shyXlt Y
selX gt=Y) shy(X gt=Y X= Y Xgt Y)
se(X lt=Y) shy
(X lt=Y
X= Y
X lt Y)
csel(infix = infix =)
39
csel(infix = infix = csel(infix = infix gt)
csel(infix = infix lt) csel(infix gt infix gt) cseJ(infix lt infix lt) csel(infix gt= infix gt=) csel(infix gt= infix gt csel(infix gt= infix =)
csellinfix lt= infix lt=) csel(infix lt= infix lt) csel(infix lt= infix =)
Finding solutions
sol(X v Y) -
(( notetra(X) eon(X) ( sol(Y) )
( c1ause(P v Q R) not(cketra(P v Q))
dis(P v Q X v Y R) ~ )
( A lt=gt B equival(A lt=gt B X v Y) ~ I) sol(X) - ~ notetra(X) eon(X)
so~(X) - notetra(X)
( con (X)
( clause(P v Q R) not(ekctra(P v Q)) dis(P v Q X R) I)
cketra(P v Q) -
eketra(P) eketra(Q) eketra(F(I J)) shy
selec(F(I J))
c1ause(contradiction(sel(F(IJ))) _I
eketra(number(W I)) -
clause(cootradietion(num(Wl)) - eketr(P) shy
clause(contradiction(P) - 1
notctra(P) shy
not( e lause( con tradiction(P) _))
40
Searching (or disjunctions
dis(P v Q X v Y R) - dis(P X v Y R)
dis(Q X v Y R) con(R)
dis(P v Q X R) -
dis(P X R) dis(Q X R) con(R
dis(P X v Y R) - clause(contradicton(Pl J 1
dis(F(I J) sel(G(I J)) v Y R) - csel(G Fl dis(number(WI) num(W N v Y R) - cnum(N I)
dis(P P v Y R) -
dis(P X v Y R) - dis(P Y R)
dis(F(I J) seJ(G(IJ)) R) - csel(G F)
dis(number(WI) num(WN) R) - cnum(N I) dis(P P R) - 1
dis(FJ J X R) shy
( ckctra(F(IJ) cbeckeq(seJ(F(IJ))) )
dis(number(W Il X R) - ( ckctra(number(WI)) cbeckeq(num(WI)) )
dis(P X R) shy( ckctra(P) cbeckeq(P) ) 1
cbeckeq(P) shy
(( A lt=gt so2(contradiction(P))
bagof(A A [jj) ) ( so2(contradiction(P)) lt=gt B
bagof(B B Uj) ))
ckeq(A) shy
( so2(A) lt=gt B B lt=gt so2(A) ) bagof(B B UJ)
con((P Q)) -
clause(P R) con(R) con(Q) con(true) -
con(contradiction(P)) - clause(contradiction(P) J
con(cause(X Y)) - cause(X Y)
con(sel(X)) - sel(X)
con(num(X Y)) - num(X Y) con(P)- (( dause(P R) (con(R) ckeq(R)))
colJectin(P) )
collectin(P) shy
bagof(S (c1ause(P S) S = true) [L LIJ )
mkcon(L Ll L)
bagor(l (L2 ) UJ) L
mkcon((A AI) (B B1) (sol(A v B) e D)) -
mkcon(A B1 e) mkcon(A1 (B Bl) D)
mkcon(A (B B1) (sol(A v B) e)) -
mkcon(A Bl e)
mkcon((A AI) B (sol(A v B) e)) middot1
mkcon(Al B e)
mkcon(A B sol(A vB))
Searching ror equivalences
equival(A lt=gt B X v Y) - 1 ( equival(A lt=gt B X) equival(A lt=gt B Y) )
equival(s02(A) lt=gt 502(B) A) - clause(B _I equival(s02(B) lt=gt 502(A) A) c1ause(B _I
Top level or inrerence mechanism
goo((s02(whatnum) P)) -
getatm(P Xl
bagor(number(X Y) ( P so2(number(X Y)) ) A )
count1(A 00 L R) nl
bagor(X P B )
count2(B L R Ll Rl) nJ print()
(( LI = 0 Rl = 0 print(THE ANSWER IS ) nl
(( Ll = Rl prin(-Jumber or ) prn(P) print(is Ll) )
( Rlgt20000 prin(Number or I prn(P) print(is LI or more) )
42
( prin(Number of ) pfn(P) print( is from Ll to Rl) )) )
( print(THE ANSWER IS NO I )) print()
goo(X) shy
(( bagof(X X L) L = [I nl print()
print(THE ANSWER IS YES) nl wout(L) print() )
( equiv(X L) nl print()
print(THE ANSWER IS YES) nl wout(L) print(-) )
( c1ause(inpt(A ==gt B) _I ( impli(A B Z) impli(B A Z) ) print(l~Hl)
printTHE ANSWER IS YES) nl print(Z) print(Hj~(fH~) ))
goo(X) print( Hg)
print(THE ANSWER IS NO ) print( lH~lH~gg9l9lmiddotmiddot~Q(gmiddot)
00 Semhing for implications in equiV3lent relations
impli( B Z) shyt-ell( z1) prin(templ() pchn(S A lt=gt B) print()) close ( zl) consult(zl) templ(Z)
unload zl Z
Searching for equivalence
equiv (X L)
(( X lt=gt Y
equ(Y YI)t bagof(Y Yl L) L = [j )
(Y lt=gt X equ(Y YI) bagof(Y Yl L) L = [J )
( X = F(New)
clause(~ew T) makeup(T Tl)
(( Tl lt=gt B
equ(B Bl) bagof(Bl Bl M) M = [j L=[Newl )
(A lt=gt TI
equ(A AI) bagof(Al AI M) M = 1] L=INewj )) ))
makeup((A B) (AI Bl)) -
makeup(A A1) makeup(B BI)
makeup(A so2(A))
equ((A B) (AI BI)) -
equ(A AI) equ(B Bl)
equ(sol(X v Y) sol(XI v Yl)) -
equ(X XI) equ(Y YI)
equ(so2(X) so2(XI)) -
equ(X XI)
equ(contradiction(X) clJuse(contradiction(X) X) ) -
equ(X X)
Counting numbers
getatm((A B) X) -
( getatm(A X) getatm(B X) )
getatm(so2(F(X)) X) -
getatm(so2(X) X) - atom(X)
countl([J L R L R) -
countl([number(X Y)IT] L R L2 R2) shy
(( Y = (gt=~) LI is L + N Rl is R + 20001 l )
( Y = (gt N) LI is L+ N+ 1 RI is R + 20002 )
(Y == laquo=~) LI is L + 1 Rl is R + N )
(Y = laquo N) LI is L + 1 RI is R+N-I)
(Y == IJ LI is L + I Rl is R + J ) ( Y == N L1 is L + N RI is R + N ))
count1(T LI R 1 L2 R2)
count2(fJ L R L R) - 1
count2([XITJ L R L2 R2) shy
name(X Xl)
(( Xl = sknj LI is L Rl is R )
44
( Xl = Iskmj L1 is L + 1 RI is R + ZOOO1) ( LI is L + I RI is R + I ))
count2(T LI RI L2 R2)
pfn((A B)) - pfn(A) prn(B)
pCn(so2(F(X))) - prin(F )
prn(so2(X)) - atom(X) prin(X ) prn (so2(X))
Printing result
wout([XlJ - prt(X) nl woutf[xIY]) - prt(X) nl nl wout(Y)
prt(e(A B)) -
prt(A) prinr 8 ) prt(ltE) prt(eA) - prt(A)
prt(c(A EJ) - prin() prt(A) prine ) prt(B) prin(T)
prt(c A) - prt(A) prt((A E)) - ~
prt(A) nl prt(E) prt(sol(X v Y)) - ~
prt(X) prinC v) prt(Y) prt(A lt=gt B) -
prt(e A) prinC lt=gt ) prt(e B) prt(sol(X)) - prt(X)
prt(so2(X)) - prt(X
prt(c1ause(X Y)) - prt(X)
prt(contradiction(X)) - prin(contradiction() prt(cX) prinr))middot prt(num(XY)) - prin(number(X Y)) prt(sel(X)) - prin(X) prt(X v Y) - prt(X) prin( v) prt(Y) prt(X) prin(X)
Handling conditional queries
condi((Y Xl) shy
assertcon(X) Y
45
retractcon(X)
condi((B A))
retractcon(A) fail
assertcon((A B)) 1
assertcon(A) assertcon(B)
assertcon(A) asserta(A)
retrac teon ((A B)) 1
retracteon(A) retractcon (B)
retraetcon(A) - retract(A)
BIBLIOGRAPHIC DATA SHEET
Report No UIUCDS-F-84-928
3 Recipients Accession No
4 T ide and Subt ltle
An Annotated Predicate Calculus Inference System (APCIS)
S Report Date
November 1984 6
7 Author(s)
Kah-Eng Pua 8 Performing Organization Rept
No
9 Performing Organization Name and Address
Department of Computer Science University of Illinois Urbana IL
10 ProjectTaskWork Unit No
11 Contract Grant No NSF DCR 84-06081 ONR N00014-82-K-0186
12 Sponsoring Organization Name and Address
National Science Foundation Washington DC
13 Type of Report amp Period Covered
14
15 Supplementary Notes
16 Abstracts
This paper describes a deductive inference system called APCIS (Annotated Predicate Calculus Inference System) APCIS is able to carry out inferences from expressions involving numerical quantifiers selectors disjunctions of non-negated terms negated terms disjunctions of negated terms equivalences and exceptions It is also able to count the numbers of occurrence of a given simple term or a conjunction of terms The design of contradiction and the treatment of the disjunction of non-negated terms allow APCIS to accept Horn clauses as well as non-Horn clauses and to carry out inferences from them This feature makes APCIS more general than Prolog
17 Key lords and Document Analysis 170 Descriptors
APC (Annotated Predicate Calculus) APCIS (Annotated Predicate Calculus Inference System) Horn Clause Numerical Quantifier Prolog Selector
17b IdentifiersOpen-Ended Terms
17c COSATI FieldGroup
18 Availability Statement 19 Security Class (This
Re~f~~IA~SIF IFf)
21 ~o of Pages
49 211 ecurity Class (This
PageUNCLASSIFIED
22 Price
FOA NTIS n (10middot70 usco-oc 40329-
35
----------------------------------Program Name APClS - Part 2 Inference Mechanism ---------------------------------- a(X) shy
steps(X X9)
(( X9 =[] nl
print( yes it is always true) )
( X9 =[cI(IJ[])] nl
print( no it is always false) )
( nl nl printel(X9) Step 1Oa
tell(temp_file) printel(X9) e1ose(temp_file) consult(temp_6Ie) ))
q(X) shy
asserta( in pt(X))
steps(X X9)
(( X9 = [] print(middot~H~~middot~t~)
print(THE AiSWER IS YES)
print( ilgIQlQl(~) )
( X9 = [e1([j [j)] Pr1nt ( OJ fi(i I~ iii Ij)middot(i)(i) fiyenQ)riiio(i)(ij)(i)fj)fiyen1li1il1li1il)__ gtw~ __~_~ _~~_ ~_-=~
print(THE ANSWER IS NO ) print() )
( teI1(temp_6Ie)
prques(X9) Step 1Ob
close(temp_file)
nl print(Let me think about it) nl
consult(temp_6Ie) ))
retrac t( in pt(X))
Step lOb Printing question
prques(lcl(A 8)1) - prin(goo(() pl(qA 8) print()))
prques([c1(A 8HCs]) - prin(goo(() pl(qA 8) print() pl(q Cs)
pl(e [c1(A 8)]) - pl(eA 8)
pl(q [c1(A 8)]) - pl(qA 8) print()))
pl(S [e1(A B)ICs]) - pl(SA B) prin( ) pl(S Cs)
38
pl(q [j L) - prin(c1ause(contradiction(() pcont(qL) prin())_))
pl(S [I L)- prin(so2(contradidion(() pcont(SL) print))))middot
pl(S [L] []) - prin(so2() pcbar(SL) prin())
pl(S L [J)- prinsol() plett(SL) print))
pl(S [L] LI) - prin(condi(() pchar(cL)
prin(() pcont(S Ll) prine))))
pl(S L Ll)- prin(c1ause() plert(cL)
prin(() pcont(S Ll) prine)))
plert(S[LJ) - pchar(SL)
plert(SjLILsj) - pcbar(SL) print v) pleCt(SLs)
pcont(S[L]) - pchar(SL)
pcont(S[LILsj) - pcbar(SL) prinr ) pcont(SLs)
pcbar(SP) shy
atomic(P)
name(PL)
( L = [IT] L = [5 k miT] L = [5 k niT] )
concat[XITj NewP)
prin(0JewP)
pchar(SP) shy
atomic(P)
prin(P) pchar(SA lt=gt B) -
prin(() dausify(A AI []) pl(eAI) prin())
prinr lt=gt ) prin(() dausify(B BI ]) pl(eB) print))
pchar(Snumber(X N)) shy
prin(num() pchar(SX) prin()
pchar(SN) prinr))
pcbar(SM N) - prin(M N)
pcbar(cF(A B)) shy
selec(F(A Braquo
pcbar(cA)
prine F ) pchar(cB) pchar(SF(A B)) shy
selec(F(A B))
prin(sel() pchar(SA)
print F ) pchar(SB) print)) I
31
pc har(SF(A)) shy
( F= prefix gt= F= prefix lt= F= prefixgt F= prefix lt )
prin(F ) pchar(SA)
pchar(SP)shy
runctor(P F MaxN)
prin(F ()
011 is MaxN - 1 pout(SNl P MaxN)
print) )
pout(S 0 P M3xN) - 1
arg(~bxN P Argu)
pchlr(SArgu )
pout(S N P MaxN shy
Nl is MaxN - N
arg(Nl P Argu)
pchar(SArgu
prin( )
N2 is N - 1
pout(S N2 P ~13xN)
Comparing numbers in numerical quantifiers
num(XN) shy
number(X I)
cnum(N 1) ~
cnumlaquo=01 lt=I- N gt=I
cnumlaquo=J lt I) - N gt=1-1
cnumlaquo=NIJ) - N gt=J 1
cnumlaquo=N J)- integer(I) N gt=I~
cnum(gt=N gt=1) - N lt=1
cnum(gt=N gt I) - N lt=1+ 1 cnum(gt=NIJ) - N lt=1
cnum(gt=N lt=1)- N lt=1
cnum(gt=N lt I) - N lt=1 L cnum(gt=N 1)- integer(I) N lt=1
cnum( lt N lt 1)- N gt=1 L
38
cnum( lt N lt=1) - N gt I cnum( lt NLJ) - N gt J
cnum( lt N 1)- integer(I) N gt 1
cnum(gt N gt I) - N lt=1 cnumlgt i gt=1) - N lt I
cnum(gt N lt=1) - N lt=0
cnum(gt N lt I) - N lt=0
cnum(gt iIJ) - N lt I cnum(gt N 1)- integer(I) N lt I
cnum(~LN lt=1) - M=I N gt= I l
cnum(~LN lt I) - M=l N gt= I-I
cnum(~LNLJ) - M lt =1 N gt = J
cnum(~1N 1)- integer(I) M lt= I N gt= I
cnum(- N) - integer(N)
Comparing selectors
sel(X = Y) shyX= Y
sel(X I=Y) shy(X I=Y X lt Y Xgt Y)
sel(X gt Y) shyXgt Y
sel(X lt Y) shyXlt Y
selX gt=Y) shy(X gt=Y X= Y Xgt Y)
se(X lt=Y) shy
(X lt=Y
X= Y
X lt Y)
csel(infix = infix =)
39
csel(infix = infix = csel(infix = infix gt)
csel(infix = infix lt) csel(infix gt infix gt) cseJ(infix lt infix lt) csel(infix gt= infix gt=) csel(infix gt= infix gt csel(infix gt= infix =)
csellinfix lt= infix lt=) csel(infix lt= infix lt) csel(infix lt= infix =)
Finding solutions
sol(X v Y) -
(( notetra(X) eon(X) ( sol(Y) )
( c1ause(P v Q R) not(cketra(P v Q))
dis(P v Q X v Y R) ~ )
( A lt=gt B equival(A lt=gt B X v Y) ~ I) sol(X) - ~ notetra(X) eon(X)
so~(X) - notetra(X)
( con (X)
( clause(P v Q R) not(ekctra(P v Q)) dis(P v Q X R) I)
cketra(P v Q) -
eketra(P) eketra(Q) eketra(F(I J)) shy
selec(F(I J))
c1ause(contradiction(sel(F(IJ))) _I
eketra(number(W I)) -
clause(cootradietion(num(Wl)) - eketr(P) shy
clause(contradiction(P) - 1
notctra(P) shy
not( e lause( con tradiction(P) _))
40
Searching (or disjunctions
dis(P v Q X v Y R) - dis(P X v Y R)
dis(Q X v Y R) con(R)
dis(P v Q X R) -
dis(P X R) dis(Q X R) con(R
dis(P X v Y R) - clause(contradicton(Pl J 1
dis(F(I J) sel(G(I J)) v Y R) - csel(G Fl dis(number(WI) num(W N v Y R) - cnum(N I)
dis(P P v Y R) -
dis(P X v Y R) - dis(P Y R)
dis(F(I J) seJ(G(IJ)) R) - csel(G F)
dis(number(WI) num(WN) R) - cnum(N I) dis(P P R) - 1
dis(FJ J X R) shy
( ckctra(F(IJ) cbeckeq(seJ(F(IJ))) )
dis(number(W Il X R) - ( ckctra(number(WI)) cbeckeq(num(WI)) )
dis(P X R) shy( ckctra(P) cbeckeq(P) ) 1
cbeckeq(P) shy
(( A lt=gt so2(contradiction(P))
bagof(A A [jj) ) ( so2(contradiction(P)) lt=gt B
bagof(B B Uj) ))
ckeq(A) shy
( so2(A) lt=gt B B lt=gt so2(A) ) bagof(B B UJ)
con((P Q)) -
clause(P R) con(R) con(Q) con(true) -
con(contradiction(P)) - clause(contradiction(P) J
con(cause(X Y)) - cause(X Y)
con(sel(X)) - sel(X)
con(num(X Y)) - num(X Y) con(P)- (( dause(P R) (con(R) ckeq(R)))
colJectin(P) )
collectin(P) shy
bagof(S (c1ause(P S) S = true) [L LIJ )
mkcon(L Ll L)
bagor(l (L2 ) UJ) L
mkcon((A AI) (B B1) (sol(A v B) e D)) -
mkcon(A B1 e) mkcon(A1 (B Bl) D)
mkcon(A (B B1) (sol(A v B) e)) -
mkcon(A Bl e)
mkcon((A AI) B (sol(A v B) e)) middot1
mkcon(Al B e)
mkcon(A B sol(A vB))
Searching ror equivalences
equival(A lt=gt B X v Y) - 1 ( equival(A lt=gt B X) equival(A lt=gt B Y) )
equival(s02(A) lt=gt 502(B) A) - clause(B _I equival(s02(B) lt=gt 502(A) A) c1ause(B _I
Top level or inrerence mechanism
goo((s02(whatnum) P)) -
getatm(P Xl
bagor(number(X Y) ( P so2(number(X Y)) ) A )
count1(A 00 L R) nl
bagor(X P B )
count2(B L R Ll Rl) nJ print()
(( LI = 0 Rl = 0 print(THE ANSWER IS ) nl
(( Ll = Rl prin(-Jumber or ) prn(P) print(is Ll) )
( Rlgt20000 prin(Number or I prn(P) print(is LI or more) )
42
( prin(Number of ) pfn(P) print( is from Ll to Rl) )) )
( print(THE ANSWER IS NO I )) print()
goo(X) shy
(( bagof(X X L) L = [I nl print()
print(THE ANSWER IS YES) nl wout(L) print() )
( equiv(X L) nl print()
print(THE ANSWER IS YES) nl wout(L) print(-) )
( c1ause(inpt(A ==gt B) _I ( impli(A B Z) impli(B A Z) ) print(l~Hl)
printTHE ANSWER IS YES) nl print(Z) print(Hj~(fH~) ))
goo(X) print( Hg)
print(THE ANSWER IS NO ) print( lH~lH~gg9l9lmiddotmiddot~Q(gmiddot)
00 Semhing for implications in equiV3lent relations
impli( B Z) shyt-ell( z1) prin(templ() pchn(S A lt=gt B) print()) close ( zl) consult(zl) templ(Z)
unload zl Z
Searching for equivalence
equiv (X L)
(( X lt=gt Y
equ(Y YI)t bagof(Y Yl L) L = [j )
(Y lt=gt X equ(Y YI) bagof(Y Yl L) L = [J )
( X = F(New)
clause(~ew T) makeup(T Tl)
(( Tl lt=gt B
equ(B Bl) bagof(Bl Bl M) M = [j L=[Newl )
(A lt=gt TI
equ(A AI) bagof(Al AI M) M = 1] L=INewj )) ))
makeup((A B) (AI Bl)) -
makeup(A A1) makeup(B BI)
makeup(A so2(A))
equ((A B) (AI BI)) -
equ(A AI) equ(B Bl)
equ(sol(X v Y) sol(XI v Yl)) -
equ(X XI) equ(Y YI)
equ(so2(X) so2(XI)) -
equ(X XI)
equ(contradiction(X) clJuse(contradiction(X) X) ) -
equ(X X)
Counting numbers
getatm((A B) X) -
( getatm(A X) getatm(B X) )
getatm(so2(F(X)) X) -
getatm(so2(X) X) - atom(X)
countl([J L R L R) -
countl([number(X Y)IT] L R L2 R2) shy
(( Y = (gt=~) LI is L + N Rl is R + 20001 l )
( Y = (gt N) LI is L+ N+ 1 RI is R + 20002 )
(Y == laquo=~) LI is L + 1 Rl is R + N )
(Y = laquo N) LI is L + 1 RI is R+N-I)
(Y == IJ LI is L + I Rl is R + J ) ( Y == N L1 is L + N RI is R + N ))
count1(T LI R 1 L2 R2)
count2(fJ L R L R) - 1
count2([XITJ L R L2 R2) shy
name(X Xl)
(( Xl = sknj LI is L Rl is R )
44
( Xl = Iskmj L1 is L + 1 RI is R + ZOOO1) ( LI is L + I RI is R + I ))
count2(T LI RI L2 R2)
pfn((A B)) - pfn(A) prn(B)
pCn(so2(F(X))) - prin(F )
prn(so2(X)) - atom(X) prin(X ) prn (so2(X))
Printing result
wout([XlJ - prt(X) nl woutf[xIY]) - prt(X) nl nl wout(Y)
prt(e(A B)) -
prt(A) prinr 8 ) prt(ltE) prt(eA) - prt(A)
prt(c(A EJ) - prin() prt(A) prine ) prt(B) prin(T)
prt(c A) - prt(A) prt((A E)) - ~
prt(A) nl prt(E) prt(sol(X v Y)) - ~
prt(X) prinC v) prt(Y) prt(A lt=gt B) -
prt(e A) prinC lt=gt ) prt(e B) prt(sol(X)) - prt(X)
prt(so2(X)) - prt(X
prt(c1ause(X Y)) - prt(X)
prt(contradiction(X)) - prin(contradiction() prt(cX) prinr))middot prt(num(XY)) - prin(number(X Y)) prt(sel(X)) - prin(X) prt(X v Y) - prt(X) prin( v) prt(Y) prt(X) prin(X)
Handling conditional queries
condi((Y Xl) shy
assertcon(X) Y
45
retractcon(X)
condi((B A))
retractcon(A) fail
assertcon((A B)) 1
assertcon(A) assertcon(B)
assertcon(A) asserta(A)
retrac teon ((A B)) 1
retracteon(A) retractcon (B)
retraetcon(A) - retract(A)
BIBLIOGRAPHIC DATA SHEET
Report No UIUCDS-F-84-928
3 Recipients Accession No
4 T ide and Subt ltle
An Annotated Predicate Calculus Inference System (APCIS)
S Report Date
November 1984 6
7 Author(s)
Kah-Eng Pua 8 Performing Organization Rept
No
9 Performing Organization Name and Address
Department of Computer Science University of Illinois Urbana IL
10 ProjectTaskWork Unit No
11 Contract Grant No NSF DCR 84-06081 ONR N00014-82-K-0186
12 Sponsoring Organization Name and Address
National Science Foundation Washington DC
13 Type of Report amp Period Covered
14
15 Supplementary Notes
16 Abstracts
This paper describes a deductive inference system called APCIS (Annotated Predicate Calculus Inference System) APCIS is able to carry out inferences from expressions involving numerical quantifiers selectors disjunctions of non-negated terms negated terms disjunctions of negated terms equivalences and exceptions It is also able to count the numbers of occurrence of a given simple term or a conjunction of terms The design of contradiction and the treatment of the disjunction of non-negated terms allow APCIS to accept Horn clauses as well as non-Horn clauses and to carry out inferences from them This feature makes APCIS more general than Prolog
17 Key lords and Document Analysis 170 Descriptors
APC (Annotated Predicate Calculus) APCIS (Annotated Predicate Calculus Inference System) Horn Clause Numerical Quantifier Prolog Selector
17b IdentifiersOpen-Ended Terms
17c COSATI FieldGroup
18 Availability Statement 19 Security Class (This
Re~f~~IA~SIF IFf)
21 ~o of Pages
49 211 ecurity Class (This
PageUNCLASSIFIED
22 Price
FOA NTIS n (10middot70 usco-oc 40329-
38
pl(q [j L) - prin(c1ause(contradiction(() pcont(qL) prin())_))
pl(S [I L)- prin(so2(contradidion(() pcont(SL) print))))middot
pl(S [L] []) - prin(so2() pcbar(SL) prin())
pl(S L [J)- prinsol() plett(SL) print))
pl(S [L] LI) - prin(condi(() pchar(cL)
prin(() pcont(S Ll) prine))))
pl(S L Ll)- prin(c1ause() plert(cL)
prin(() pcont(S Ll) prine)))
plert(S[LJ) - pchar(SL)
plert(SjLILsj) - pcbar(SL) print v) pleCt(SLs)
pcont(S[L]) - pchar(SL)
pcont(S[LILsj) - pcbar(SL) prinr ) pcont(SLs)
pcbar(SP) shy
atomic(P)
name(PL)
( L = [IT] L = [5 k miT] L = [5 k niT] )
concat[XITj NewP)
prin(0JewP)
pchar(SP) shy
atomic(P)
prin(P) pchar(SA lt=gt B) -
prin(() dausify(A AI []) pl(eAI) prin())
prinr lt=gt ) prin(() dausify(B BI ]) pl(eB) print))
pchar(Snumber(X N)) shy
prin(num() pchar(SX) prin()
pchar(SN) prinr))
pcbar(SM N) - prin(M N)
pcbar(cF(A B)) shy
selec(F(A Braquo
pcbar(cA)
prine F ) pchar(cB) pchar(SF(A B)) shy
selec(F(A B))
prin(sel() pchar(SA)
print F ) pchar(SB) print)) I
31
pc har(SF(A)) shy
( F= prefix gt= F= prefix lt= F= prefixgt F= prefix lt )
prin(F ) pchar(SA)
pchar(SP)shy
runctor(P F MaxN)
prin(F ()
011 is MaxN - 1 pout(SNl P MaxN)
print) )
pout(S 0 P M3xN) - 1
arg(~bxN P Argu)
pchlr(SArgu )
pout(S N P MaxN shy
Nl is MaxN - N
arg(Nl P Argu)
pchar(SArgu
prin( )
N2 is N - 1
pout(S N2 P ~13xN)
Comparing numbers in numerical quantifiers
num(XN) shy
number(X I)
cnum(N 1) ~
cnumlaquo=01 lt=I- N gt=I
cnumlaquo=J lt I) - N gt=1-1
cnumlaquo=NIJ) - N gt=J 1
cnumlaquo=N J)- integer(I) N gt=I~
cnum(gt=N gt=1) - N lt=1
cnum(gt=N gt I) - N lt=1+ 1 cnum(gt=NIJ) - N lt=1
cnum(gt=N lt=1)- N lt=1
cnum(gt=N lt I) - N lt=1 L cnum(gt=N 1)- integer(I) N lt=1
cnum( lt N lt 1)- N gt=1 L
38
cnum( lt N lt=1) - N gt I cnum( lt NLJ) - N gt J
cnum( lt N 1)- integer(I) N gt 1
cnum(gt N gt I) - N lt=1 cnumlgt i gt=1) - N lt I
cnum(gt N lt=1) - N lt=0
cnum(gt N lt I) - N lt=0
cnum(gt iIJ) - N lt I cnum(gt N 1)- integer(I) N lt I
cnum(~LN lt=1) - M=I N gt= I l
cnum(~LN lt I) - M=l N gt= I-I
cnum(~LNLJ) - M lt =1 N gt = J
cnum(~1N 1)- integer(I) M lt= I N gt= I
cnum(- N) - integer(N)
Comparing selectors
sel(X = Y) shyX= Y
sel(X I=Y) shy(X I=Y X lt Y Xgt Y)
sel(X gt Y) shyXgt Y
sel(X lt Y) shyXlt Y
selX gt=Y) shy(X gt=Y X= Y Xgt Y)
se(X lt=Y) shy
(X lt=Y
X= Y
X lt Y)
csel(infix = infix =)
39
csel(infix = infix = csel(infix = infix gt)
csel(infix = infix lt) csel(infix gt infix gt) cseJ(infix lt infix lt) csel(infix gt= infix gt=) csel(infix gt= infix gt csel(infix gt= infix =)
csellinfix lt= infix lt=) csel(infix lt= infix lt) csel(infix lt= infix =)
Finding solutions
sol(X v Y) -
(( notetra(X) eon(X) ( sol(Y) )
( c1ause(P v Q R) not(cketra(P v Q))
dis(P v Q X v Y R) ~ )
( A lt=gt B equival(A lt=gt B X v Y) ~ I) sol(X) - ~ notetra(X) eon(X)
so~(X) - notetra(X)
( con (X)
( clause(P v Q R) not(ekctra(P v Q)) dis(P v Q X R) I)
cketra(P v Q) -
eketra(P) eketra(Q) eketra(F(I J)) shy
selec(F(I J))
c1ause(contradiction(sel(F(IJ))) _I
eketra(number(W I)) -
clause(cootradietion(num(Wl)) - eketr(P) shy
clause(contradiction(P) - 1
notctra(P) shy
not( e lause( con tradiction(P) _))
40
Searching (or disjunctions
dis(P v Q X v Y R) - dis(P X v Y R)
dis(Q X v Y R) con(R)
dis(P v Q X R) -
dis(P X R) dis(Q X R) con(R
dis(P X v Y R) - clause(contradicton(Pl J 1
dis(F(I J) sel(G(I J)) v Y R) - csel(G Fl dis(number(WI) num(W N v Y R) - cnum(N I)
dis(P P v Y R) -
dis(P X v Y R) - dis(P Y R)
dis(F(I J) seJ(G(IJ)) R) - csel(G F)
dis(number(WI) num(WN) R) - cnum(N I) dis(P P R) - 1
dis(FJ J X R) shy
( ckctra(F(IJ) cbeckeq(seJ(F(IJ))) )
dis(number(W Il X R) - ( ckctra(number(WI)) cbeckeq(num(WI)) )
dis(P X R) shy( ckctra(P) cbeckeq(P) ) 1
cbeckeq(P) shy
(( A lt=gt so2(contradiction(P))
bagof(A A [jj) ) ( so2(contradiction(P)) lt=gt B
bagof(B B Uj) ))
ckeq(A) shy
( so2(A) lt=gt B B lt=gt so2(A) ) bagof(B B UJ)
con((P Q)) -
clause(P R) con(R) con(Q) con(true) -
con(contradiction(P)) - clause(contradiction(P) J
con(cause(X Y)) - cause(X Y)
con(sel(X)) - sel(X)
con(num(X Y)) - num(X Y) con(P)- (( dause(P R) (con(R) ckeq(R)))
colJectin(P) )
collectin(P) shy
bagof(S (c1ause(P S) S = true) [L LIJ )
mkcon(L Ll L)
bagor(l (L2 ) UJ) L
mkcon((A AI) (B B1) (sol(A v B) e D)) -
mkcon(A B1 e) mkcon(A1 (B Bl) D)
mkcon(A (B B1) (sol(A v B) e)) -
mkcon(A Bl e)
mkcon((A AI) B (sol(A v B) e)) middot1
mkcon(Al B e)
mkcon(A B sol(A vB))
Searching ror equivalences
equival(A lt=gt B X v Y) - 1 ( equival(A lt=gt B X) equival(A lt=gt B Y) )
equival(s02(A) lt=gt 502(B) A) - clause(B _I equival(s02(B) lt=gt 502(A) A) c1ause(B _I
Top level or inrerence mechanism
goo((s02(whatnum) P)) -
getatm(P Xl
bagor(number(X Y) ( P so2(number(X Y)) ) A )
count1(A 00 L R) nl
bagor(X P B )
count2(B L R Ll Rl) nJ print()
(( LI = 0 Rl = 0 print(THE ANSWER IS ) nl
(( Ll = Rl prin(-Jumber or ) prn(P) print(is Ll) )
( Rlgt20000 prin(Number or I prn(P) print(is LI or more) )
42
( prin(Number of ) pfn(P) print( is from Ll to Rl) )) )
( print(THE ANSWER IS NO I )) print()
goo(X) shy
(( bagof(X X L) L = [I nl print()
print(THE ANSWER IS YES) nl wout(L) print() )
( equiv(X L) nl print()
print(THE ANSWER IS YES) nl wout(L) print(-) )
( c1ause(inpt(A ==gt B) _I ( impli(A B Z) impli(B A Z) ) print(l~Hl)
printTHE ANSWER IS YES) nl print(Z) print(Hj~(fH~) ))
goo(X) print( Hg)
print(THE ANSWER IS NO ) print( lH~lH~gg9l9lmiddotmiddot~Q(gmiddot)
00 Semhing for implications in equiV3lent relations
impli( B Z) shyt-ell( z1) prin(templ() pchn(S A lt=gt B) print()) close ( zl) consult(zl) templ(Z)
unload zl Z
Searching for equivalence
equiv (X L)
(( X lt=gt Y
equ(Y YI)t bagof(Y Yl L) L = [j )
(Y lt=gt X equ(Y YI) bagof(Y Yl L) L = [J )
( X = F(New)
clause(~ew T) makeup(T Tl)
(( Tl lt=gt B
equ(B Bl) bagof(Bl Bl M) M = [j L=[Newl )
(A lt=gt TI
equ(A AI) bagof(Al AI M) M = 1] L=INewj )) ))
makeup((A B) (AI Bl)) -
makeup(A A1) makeup(B BI)
makeup(A so2(A))
equ((A B) (AI BI)) -
equ(A AI) equ(B Bl)
equ(sol(X v Y) sol(XI v Yl)) -
equ(X XI) equ(Y YI)
equ(so2(X) so2(XI)) -
equ(X XI)
equ(contradiction(X) clJuse(contradiction(X) X) ) -
equ(X X)
Counting numbers
getatm((A B) X) -
( getatm(A X) getatm(B X) )
getatm(so2(F(X)) X) -
getatm(so2(X) X) - atom(X)
countl([J L R L R) -
countl([number(X Y)IT] L R L2 R2) shy
(( Y = (gt=~) LI is L + N Rl is R + 20001 l )
( Y = (gt N) LI is L+ N+ 1 RI is R + 20002 )
(Y == laquo=~) LI is L + 1 Rl is R + N )
(Y = laquo N) LI is L + 1 RI is R+N-I)
(Y == IJ LI is L + I Rl is R + J ) ( Y == N L1 is L + N RI is R + N ))
count1(T LI R 1 L2 R2)
count2(fJ L R L R) - 1
count2([XITJ L R L2 R2) shy
name(X Xl)
(( Xl = sknj LI is L Rl is R )
44
( Xl = Iskmj L1 is L + 1 RI is R + ZOOO1) ( LI is L + I RI is R + I ))
count2(T LI RI L2 R2)
pfn((A B)) - pfn(A) prn(B)
pCn(so2(F(X))) - prin(F )
prn(so2(X)) - atom(X) prin(X ) prn (so2(X))
Printing result
wout([XlJ - prt(X) nl woutf[xIY]) - prt(X) nl nl wout(Y)
prt(e(A B)) -
prt(A) prinr 8 ) prt(ltE) prt(eA) - prt(A)
prt(c(A EJ) - prin() prt(A) prine ) prt(B) prin(T)
prt(c A) - prt(A) prt((A E)) - ~
prt(A) nl prt(E) prt(sol(X v Y)) - ~
prt(X) prinC v) prt(Y) prt(A lt=gt B) -
prt(e A) prinC lt=gt ) prt(e B) prt(sol(X)) - prt(X)
prt(so2(X)) - prt(X
prt(c1ause(X Y)) - prt(X)
prt(contradiction(X)) - prin(contradiction() prt(cX) prinr))middot prt(num(XY)) - prin(number(X Y)) prt(sel(X)) - prin(X) prt(X v Y) - prt(X) prin( v) prt(Y) prt(X) prin(X)
Handling conditional queries
condi((Y Xl) shy
assertcon(X) Y
45
retractcon(X)
condi((B A))
retractcon(A) fail
assertcon((A B)) 1
assertcon(A) assertcon(B)
assertcon(A) asserta(A)
retrac teon ((A B)) 1
retracteon(A) retractcon (B)
retraetcon(A) - retract(A)
BIBLIOGRAPHIC DATA SHEET
Report No UIUCDS-F-84-928
3 Recipients Accession No
4 T ide and Subt ltle
An Annotated Predicate Calculus Inference System (APCIS)
S Report Date
November 1984 6
7 Author(s)
Kah-Eng Pua 8 Performing Organization Rept
No
9 Performing Organization Name and Address
Department of Computer Science University of Illinois Urbana IL
10 ProjectTaskWork Unit No
11 Contract Grant No NSF DCR 84-06081 ONR N00014-82-K-0186
12 Sponsoring Organization Name and Address
National Science Foundation Washington DC
13 Type of Report amp Period Covered
14
15 Supplementary Notes
16 Abstracts
This paper describes a deductive inference system called APCIS (Annotated Predicate Calculus Inference System) APCIS is able to carry out inferences from expressions involving numerical quantifiers selectors disjunctions of non-negated terms negated terms disjunctions of negated terms equivalences and exceptions It is also able to count the numbers of occurrence of a given simple term or a conjunction of terms The design of contradiction and the treatment of the disjunction of non-negated terms allow APCIS to accept Horn clauses as well as non-Horn clauses and to carry out inferences from them This feature makes APCIS more general than Prolog
17 Key lords and Document Analysis 170 Descriptors
APC (Annotated Predicate Calculus) APCIS (Annotated Predicate Calculus Inference System) Horn Clause Numerical Quantifier Prolog Selector
17b IdentifiersOpen-Ended Terms
17c COSATI FieldGroup
18 Availability Statement 19 Security Class (This
Re~f~~IA~SIF IFf)
21 ~o of Pages
49 211 ecurity Class (This
PageUNCLASSIFIED
22 Price
FOA NTIS n (10middot70 usco-oc 40329-
31
pc har(SF(A)) shy
( F= prefix gt= F= prefix lt= F= prefixgt F= prefix lt )
prin(F ) pchar(SA)
pchar(SP)shy
runctor(P F MaxN)
prin(F ()
011 is MaxN - 1 pout(SNl P MaxN)
print) )
pout(S 0 P M3xN) - 1
arg(~bxN P Argu)
pchlr(SArgu )
pout(S N P MaxN shy
Nl is MaxN - N
arg(Nl P Argu)
pchar(SArgu
prin( )
N2 is N - 1
pout(S N2 P ~13xN)
Comparing numbers in numerical quantifiers
num(XN) shy
number(X I)
cnum(N 1) ~
cnumlaquo=01 lt=I- N gt=I
cnumlaquo=J lt I) - N gt=1-1
cnumlaquo=NIJ) - N gt=J 1
cnumlaquo=N J)- integer(I) N gt=I~
cnum(gt=N gt=1) - N lt=1
cnum(gt=N gt I) - N lt=1+ 1 cnum(gt=NIJ) - N lt=1
cnum(gt=N lt=1)- N lt=1
cnum(gt=N lt I) - N lt=1 L cnum(gt=N 1)- integer(I) N lt=1
cnum( lt N lt 1)- N gt=1 L
38
cnum( lt N lt=1) - N gt I cnum( lt NLJ) - N gt J
cnum( lt N 1)- integer(I) N gt 1
cnum(gt N gt I) - N lt=1 cnumlgt i gt=1) - N lt I
cnum(gt N lt=1) - N lt=0
cnum(gt N lt I) - N lt=0
cnum(gt iIJ) - N lt I cnum(gt N 1)- integer(I) N lt I
cnum(~LN lt=1) - M=I N gt= I l
cnum(~LN lt I) - M=l N gt= I-I
cnum(~LNLJ) - M lt =1 N gt = J
cnum(~1N 1)- integer(I) M lt= I N gt= I
cnum(- N) - integer(N)
Comparing selectors
sel(X = Y) shyX= Y
sel(X I=Y) shy(X I=Y X lt Y Xgt Y)
sel(X gt Y) shyXgt Y
sel(X lt Y) shyXlt Y
selX gt=Y) shy(X gt=Y X= Y Xgt Y)
se(X lt=Y) shy
(X lt=Y
X= Y
X lt Y)
csel(infix = infix =)
39
csel(infix = infix = csel(infix = infix gt)
csel(infix = infix lt) csel(infix gt infix gt) cseJ(infix lt infix lt) csel(infix gt= infix gt=) csel(infix gt= infix gt csel(infix gt= infix =)
csellinfix lt= infix lt=) csel(infix lt= infix lt) csel(infix lt= infix =)
Finding solutions
sol(X v Y) -
(( notetra(X) eon(X) ( sol(Y) )
( c1ause(P v Q R) not(cketra(P v Q))
dis(P v Q X v Y R) ~ )
( A lt=gt B equival(A lt=gt B X v Y) ~ I) sol(X) - ~ notetra(X) eon(X)
so~(X) - notetra(X)
( con (X)
( clause(P v Q R) not(ekctra(P v Q)) dis(P v Q X R) I)
cketra(P v Q) -
eketra(P) eketra(Q) eketra(F(I J)) shy
selec(F(I J))
c1ause(contradiction(sel(F(IJ))) _I
eketra(number(W I)) -
clause(cootradietion(num(Wl)) - eketr(P) shy
clause(contradiction(P) - 1
notctra(P) shy
not( e lause( con tradiction(P) _))
40
Searching (or disjunctions
dis(P v Q X v Y R) - dis(P X v Y R)
dis(Q X v Y R) con(R)
dis(P v Q X R) -
dis(P X R) dis(Q X R) con(R
dis(P X v Y R) - clause(contradicton(Pl J 1
dis(F(I J) sel(G(I J)) v Y R) - csel(G Fl dis(number(WI) num(W N v Y R) - cnum(N I)
dis(P P v Y R) -
dis(P X v Y R) - dis(P Y R)
dis(F(I J) seJ(G(IJ)) R) - csel(G F)
dis(number(WI) num(WN) R) - cnum(N I) dis(P P R) - 1
dis(FJ J X R) shy
( ckctra(F(IJ) cbeckeq(seJ(F(IJ))) )
dis(number(W Il X R) - ( ckctra(number(WI)) cbeckeq(num(WI)) )
dis(P X R) shy( ckctra(P) cbeckeq(P) ) 1
cbeckeq(P) shy
(( A lt=gt so2(contradiction(P))
bagof(A A [jj) ) ( so2(contradiction(P)) lt=gt B
bagof(B B Uj) ))
ckeq(A) shy
( so2(A) lt=gt B B lt=gt so2(A) ) bagof(B B UJ)
con((P Q)) -
clause(P R) con(R) con(Q) con(true) -
con(contradiction(P)) - clause(contradiction(P) J
con(cause(X Y)) - cause(X Y)
con(sel(X)) - sel(X)
con(num(X Y)) - num(X Y) con(P)- (( dause(P R) (con(R) ckeq(R)))
colJectin(P) )
collectin(P) shy
bagof(S (c1ause(P S) S = true) [L LIJ )
mkcon(L Ll L)
bagor(l (L2 ) UJ) L
mkcon((A AI) (B B1) (sol(A v B) e D)) -
mkcon(A B1 e) mkcon(A1 (B Bl) D)
mkcon(A (B B1) (sol(A v B) e)) -
mkcon(A Bl e)
mkcon((A AI) B (sol(A v B) e)) middot1
mkcon(Al B e)
mkcon(A B sol(A vB))
Searching ror equivalences
equival(A lt=gt B X v Y) - 1 ( equival(A lt=gt B X) equival(A lt=gt B Y) )
equival(s02(A) lt=gt 502(B) A) - clause(B _I equival(s02(B) lt=gt 502(A) A) c1ause(B _I
Top level or inrerence mechanism
goo((s02(whatnum) P)) -
getatm(P Xl
bagor(number(X Y) ( P so2(number(X Y)) ) A )
count1(A 00 L R) nl
bagor(X P B )
count2(B L R Ll Rl) nJ print()
(( LI = 0 Rl = 0 print(THE ANSWER IS ) nl
(( Ll = Rl prin(-Jumber or ) prn(P) print(is Ll) )
( Rlgt20000 prin(Number or I prn(P) print(is LI or more) )
42
( prin(Number of ) pfn(P) print( is from Ll to Rl) )) )
( print(THE ANSWER IS NO I )) print()
goo(X) shy
(( bagof(X X L) L = [I nl print()
print(THE ANSWER IS YES) nl wout(L) print() )
( equiv(X L) nl print()
print(THE ANSWER IS YES) nl wout(L) print(-) )
( c1ause(inpt(A ==gt B) _I ( impli(A B Z) impli(B A Z) ) print(l~Hl)
printTHE ANSWER IS YES) nl print(Z) print(Hj~(fH~) ))
goo(X) print( Hg)
print(THE ANSWER IS NO ) print( lH~lH~gg9l9lmiddotmiddot~Q(gmiddot)
00 Semhing for implications in equiV3lent relations
impli( B Z) shyt-ell( z1) prin(templ() pchn(S A lt=gt B) print()) close ( zl) consult(zl) templ(Z)
unload zl Z
Searching for equivalence
equiv (X L)
(( X lt=gt Y
equ(Y YI)t bagof(Y Yl L) L = [j )
(Y lt=gt X equ(Y YI) bagof(Y Yl L) L = [J )
( X = F(New)
clause(~ew T) makeup(T Tl)
(( Tl lt=gt B
equ(B Bl) bagof(Bl Bl M) M = [j L=[Newl )
(A lt=gt TI
equ(A AI) bagof(Al AI M) M = 1] L=INewj )) ))
makeup((A B) (AI Bl)) -
makeup(A A1) makeup(B BI)
makeup(A so2(A))
equ((A B) (AI BI)) -
equ(A AI) equ(B Bl)
equ(sol(X v Y) sol(XI v Yl)) -
equ(X XI) equ(Y YI)
equ(so2(X) so2(XI)) -
equ(X XI)
equ(contradiction(X) clJuse(contradiction(X) X) ) -
equ(X X)
Counting numbers
getatm((A B) X) -
( getatm(A X) getatm(B X) )
getatm(so2(F(X)) X) -
getatm(so2(X) X) - atom(X)
countl([J L R L R) -
countl([number(X Y)IT] L R L2 R2) shy
(( Y = (gt=~) LI is L + N Rl is R + 20001 l )
( Y = (gt N) LI is L+ N+ 1 RI is R + 20002 )
(Y == laquo=~) LI is L + 1 Rl is R + N )
(Y = laquo N) LI is L + 1 RI is R+N-I)
(Y == IJ LI is L + I Rl is R + J ) ( Y == N L1 is L + N RI is R + N ))
count1(T LI R 1 L2 R2)
count2(fJ L R L R) - 1
count2([XITJ L R L2 R2) shy
name(X Xl)
(( Xl = sknj LI is L Rl is R )
44
( Xl = Iskmj L1 is L + 1 RI is R + ZOOO1) ( LI is L + I RI is R + I ))
count2(T LI RI L2 R2)
pfn((A B)) - pfn(A) prn(B)
pCn(so2(F(X))) - prin(F )
prn(so2(X)) - atom(X) prin(X ) prn (so2(X))
Printing result
wout([XlJ - prt(X) nl woutf[xIY]) - prt(X) nl nl wout(Y)
prt(e(A B)) -
prt(A) prinr 8 ) prt(ltE) prt(eA) - prt(A)
prt(c(A EJ) - prin() prt(A) prine ) prt(B) prin(T)
prt(c A) - prt(A) prt((A E)) - ~
prt(A) nl prt(E) prt(sol(X v Y)) - ~
prt(X) prinC v) prt(Y) prt(A lt=gt B) -
prt(e A) prinC lt=gt ) prt(e B) prt(sol(X)) - prt(X)
prt(so2(X)) - prt(X
prt(c1ause(X Y)) - prt(X)
prt(contradiction(X)) - prin(contradiction() prt(cX) prinr))middot prt(num(XY)) - prin(number(X Y)) prt(sel(X)) - prin(X) prt(X v Y) - prt(X) prin( v) prt(Y) prt(X) prin(X)
Handling conditional queries
condi((Y Xl) shy
assertcon(X) Y
45
retractcon(X)
condi((B A))
retractcon(A) fail
assertcon((A B)) 1
assertcon(A) assertcon(B)
assertcon(A) asserta(A)
retrac teon ((A B)) 1
retracteon(A) retractcon (B)
retraetcon(A) - retract(A)
BIBLIOGRAPHIC DATA SHEET
Report No UIUCDS-F-84-928
3 Recipients Accession No
4 T ide and Subt ltle
An Annotated Predicate Calculus Inference System (APCIS)
S Report Date
November 1984 6
7 Author(s)
Kah-Eng Pua 8 Performing Organization Rept
No
9 Performing Organization Name and Address
Department of Computer Science University of Illinois Urbana IL
10 ProjectTaskWork Unit No
11 Contract Grant No NSF DCR 84-06081 ONR N00014-82-K-0186
12 Sponsoring Organization Name and Address
National Science Foundation Washington DC
13 Type of Report amp Period Covered
14
15 Supplementary Notes
16 Abstracts
This paper describes a deductive inference system called APCIS (Annotated Predicate Calculus Inference System) APCIS is able to carry out inferences from expressions involving numerical quantifiers selectors disjunctions of non-negated terms negated terms disjunctions of negated terms equivalences and exceptions It is also able to count the numbers of occurrence of a given simple term or a conjunction of terms The design of contradiction and the treatment of the disjunction of non-negated terms allow APCIS to accept Horn clauses as well as non-Horn clauses and to carry out inferences from them This feature makes APCIS more general than Prolog
17 Key lords and Document Analysis 170 Descriptors
APC (Annotated Predicate Calculus) APCIS (Annotated Predicate Calculus Inference System) Horn Clause Numerical Quantifier Prolog Selector
17b IdentifiersOpen-Ended Terms
17c COSATI FieldGroup
18 Availability Statement 19 Security Class (This
Re~f~~IA~SIF IFf)
21 ~o of Pages
49 211 ecurity Class (This
PageUNCLASSIFIED
22 Price
FOA NTIS n (10middot70 usco-oc 40329-
38
cnum( lt N lt=1) - N gt I cnum( lt NLJ) - N gt J
cnum( lt N 1)- integer(I) N gt 1
cnum(gt N gt I) - N lt=1 cnumlgt i gt=1) - N lt I
cnum(gt N lt=1) - N lt=0
cnum(gt N lt I) - N lt=0
cnum(gt iIJ) - N lt I cnum(gt N 1)- integer(I) N lt I
cnum(~LN lt=1) - M=I N gt= I l
cnum(~LN lt I) - M=l N gt= I-I
cnum(~LNLJ) - M lt =1 N gt = J
cnum(~1N 1)- integer(I) M lt= I N gt= I
cnum(- N) - integer(N)
Comparing selectors
sel(X = Y) shyX= Y
sel(X I=Y) shy(X I=Y X lt Y Xgt Y)
sel(X gt Y) shyXgt Y
sel(X lt Y) shyXlt Y
selX gt=Y) shy(X gt=Y X= Y Xgt Y)
se(X lt=Y) shy
(X lt=Y
X= Y
X lt Y)
csel(infix = infix =)
39
csel(infix = infix = csel(infix = infix gt)
csel(infix = infix lt) csel(infix gt infix gt) cseJ(infix lt infix lt) csel(infix gt= infix gt=) csel(infix gt= infix gt csel(infix gt= infix =)
csellinfix lt= infix lt=) csel(infix lt= infix lt) csel(infix lt= infix =)
Finding solutions
sol(X v Y) -
(( notetra(X) eon(X) ( sol(Y) )
( c1ause(P v Q R) not(cketra(P v Q))
dis(P v Q X v Y R) ~ )
( A lt=gt B equival(A lt=gt B X v Y) ~ I) sol(X) - ~ notetra(X) eon(X)
so~(X) - notetra(X)
( con (X)
( clause(P v Q R) not(ekctra(P v Q)) dis(P v Q X R) I)
cketra(P v Q) -
eketra(P) eketra(Q) eketra(F(I J)) shy
selec(F(I J))
c1ause(contradiction(sel(F(IJ))) _I
eketra(number(W I)) -
clause(cootradietion(num(Wl)) - eketr(P) shy
clause(contradiction(P) - 1
notctra(P) shy
not( e lause( con tradiction(P) _))
40
Searching (or disjunctions
dis(P v Q X v Y R) - dis(P X v Y R)
dis(Q X v Y R) con(R)
dis(P v Q X R) -
dis(P X R) dis(Q X R) con(R
dis(P X v Y R) - clause(contradicton(Pl J 1
dis(F(I J) sel(G(I J)) v Y R) - csel(G Fl dis(number(WI) num(W N v Y R) - cnum(N I)
dis(P P v Y R) -
dis(P X v Y R) - dis(P Y R)
dis(F(I J) seJ(G(IJ)) R) - csel(G F)
dis(number(WI) num(WN) R) - cnum(N I) dis(P P R) - 1
dis(FJ J X R) shy
( ckctra(F(IJ) cbeckeq(seJ(F(IJ))) )
dis(number(W Il X R) - ( ckctra(number(WI)) cbeckeq(num(WI)) )
dis(P X R) shy( ckctra(P) cbeckeq(P) ) 1
cbeckeq(P) shy
(( A lt=gt so2(contradiction(P))
bagof(A A [jj) ) ( so2(contradiction(P)) lt=gt B
bagof(B B Uj) ))
ckeq(A) shy
( so2(A) lt=gt B B lt=gt so2(A) ) bagof(B B UJ)
con((P Q)) -
clause(P R) con(R) con(Q) con(true) -
con(contradiction(P)) - clause(contradiction(P) J
con(cause(X Y)) - cause(X Y)
con(sel(X)) - sel(X)
con(num(X Y)) - num(X Y) con(P)- (( dause(P R) (con(R) ckeq(R)))
colJectin(P) )
collectin(P) shy
bagof(S (c1ause(P S) S = true) [L LIJ )
mkcon(L Ll L)
bagor(l (L2 ) UJ) L
mkcon((A AI) (B B1) (sol(A v B) e D)) -
mkcon(A B1 e) mkcon(A1 (B Bl) D)
mkcon(A (B B1) (sol(A v B) e)) -
mkcon(A Bl e)
mkcon((A AI) B (sol(A v B) e)) middot1
mkcon(Al B e)
mkcon(A B sol(A vB))
Searching ror equivalences
equival(A lt=gt B X v Y) - 1 ( equival(A lt=gt B X) equival(A lt=gt B Y) )
equival(s02(A) lt=gt 502(B) A) - clause(B _I equival(s02(B) lt=gt 502(A) A) c1ause(B _I
Top level or inrerence mechanism
goo((s02(whatnum) P)) -
getatm(P Xl
bagor(number(X Y) ( P so2(number(X Y)) ) A )
count1(A 00 L R) nl
bagor(X P B )
count2(B L R Ll Rl) nJ print()
(( LI = 0 Rl = 0 print(THE ANSWER IS ) nl
(( Ll = Rl prin(-Jumber or ) prn(P) print(is Ll) )
( Rlgt20000 prin(Number or I prn(P) print(is LI or more) )
42
( prin(Number of ) pfn(P) print( is from Ll to Rl) )) )
( print(THE ANSWER IS NO I )) print()
goo(X) shy
(( bagof(X X L) L = [I nl print()
print(THE ANSWER IS YES) nl wout(L) print() )
( equiv(X L) nl print()
print(THE ANSWER IS YES) nl wout(L) print(-) )
( c1ause(inpt(A ==gt B) _I ( impli(A B Z) impli(B A Z) ) print(l~Hl)
printTHE ANSWER IS YES) nl print(Z) print(Hj~(fH~) ))
goo(X) print( Hg)
print(THE ANSWER IS NO ) print( lH~lH~gg9l9lmiddotmiddot~Q(gmiddot)
00 Semhing for implications in equiV3lent relations
impli( B Z) shyt-ell( z1) prin(templ() pchn(S A lt=gt B) print()) close ( zl) consult(zl) templ(Z)
unload zl Z
Searching for equivalence
equiv (X L)
(( X lt=gt Y
equ(Y YI)t bagof(Y Yl L) L = [j )
(Y lt=gt X equ(Y YI) bagof(Y Yl L) L = [J )
( X = F(New)
clause(~ew T) makeup(T Tl)
(( Tl lt=gt B
equ(B Bl) bagof(Bl Bl M) M = [j L=[Newl )
(A lt=gt TI
equ(A AI) bagof(Al AI M) M = 1] L=INewj )) ))
makeup((A B) (AI Bl)) -
makeup(A A1) makeup(B BI)
makeup(A so2(A))
equ((A B) (AI BI)) -
equ(A AI) equ(B Bl)
equ(sol(X v Y) sol(XI v Yl)) -
equ(X XI) equ(Y YI)
equ(so2(X) so2(XI)) -
equ(X XI)
equ(contradiction(X) clJuse(contradiction(X) X) ) -
equ(X X)
Counting numbers
getatm((A B) X) -
( getatm(A X) getatm(B X) )
getatm(so2(F(X)) X) -
getatm(so2(X) X) - atom(X)
countl([J L R L R) -
countl([number(X Y)IT] L R L2 R2) shy
(( Y = (gt=~) LI is L + N Rl is R + 20001 l )
( Y = (gt N) LI is L+ N+ 1 RI is R + 20002 )
(Y == laquo=~) LI is L + 1 Rl is R + N )
(Y = laquo N) LI is L + 1 RI is R+N-I)
(Y == IJ LI is L + I Rl is R + J ) ( Y == N L1 is L + N RI is R + N ))
count1(T LI R 1 L2 R2)
count2(fJ L R L R) - 1
count2([XITJ L R L2 R2) shy
name(X Xl)
(( Xl = sknj LI is L Rl is R )
44
( Xl = Iskmj L1 is L + 1 RI is R + ZOOO1) ( LI is L + I RI is R + I ))
count2(T LI RI L2 R2)
pfn((A B)) - pfn(A) prn(B)
pCn(so2(F(X))) - prin(F )
prn(so2(X)) - atom(X) prin(X ) prn (so2(X))
Printing result
wout([XlJ - prt(X) nl woutf[xIY]) - prt(X) nl nl wout(Y)
prt(e(A B)) -
prt(A) prinr 8 ) prt(ltE) prt(eA) - prt(A)
prt(c(A EJ) - prin() prt(A) prine ) prt(B) prin(T)
prt(c A) - prt(A) prt((A E)) - ~
prt(A) nl prt(E) prt(sol(X v Y)) - ~
prt(X) prinC v) prt(Y) prt(A lt=gt B) -
prt(e A) prinC lt=gt ) prt(e B) prt(sol(X)) - prt(X)
prt(so2(X)) - prt(X
prt(c1ause(X Y)) - prt(X)
prt(contradiction(X)) - prin(contradiction() prt(cX) prinr))middot prt(num(XY)) - prin(number(X Y)) prt(sel(X)) - prin(X) prt(X v Y) - prt(X) prin( v) prt(Y) prt(X) prin(X)
Handling conditional queries
condi((Y Xl) shy
assertcon(X) Y
45
retractcon(X)
condi((B A))
retractcon(A) fail
assertcon((A B)) 1
assertcon(A) assertcon(B)
assertcon(A) asserta(A)
retrac teon ((A B)) 1
retracteon(A) retractcon (B)
retraetcon(A) - retract(A)
BIBLIOGRAPHIC DATA SHEET
Report No UIUCDS-F-84-928
3 Recipients Accession No
4 T ide and Subt ltle
An Annotated Predicate Calculus Inference System (APCIS)
S Report Date
November 1984 6
7 Author(s)
Kah-Eng Pua 8 Performing Organization Rept
No
9 Performing Organization Name and Address
Department of Computer Science University of Illinois Urbana IL
10 ProjectTaskWork Unit No
11 Contract Grant No NSF DCR 84-06081 ONR N00014-82-K-0186
12 Sponsoring Organization Name and Address
National Science Foundation Washington DC
13 Type of Report amp Period Covered
14
15 Supplementary Notes
16 Abstracts
This paper describes a deductive inference system called APCIS (Annotated Predicate Calculus Inference System) APCIS is able to carry out inferences from expressions involving numerical quantifiers selectors disjunctions of non-negated terms negated terms disjunctions of negated terms equivalences and exceptions It is also able to count the numbers of occurrence of a given simple term or a conjunction of terms The design of contradiction and the treatment of the disjunction of non-negated terms allow APCIS to accept Horn clauses as well as non-Horn clauses and to carry out inferences from them This feature makes APCIS more general than Prolog
17 Key lords and Document Analysis 170 Descriptors
APC (Annotated Predicate Calculus) APCIS (Annotated Predicate Calculus Inference System) Horn Clause Numerical Quantifier Prolog Selector
17b IdentifiersOpen-Ended Terms
17c COSATI FieldGroup
18 Availability Statement 19 Security Class (This
Re~f~~IA~SIF IFf)
21 ~o of Pages
49 211 ecurity Class (This
PageUNCLASSIFIED
22 Price
FOA NTIS n (10middot70 usco-oc 40329-
39
csel(infix = infix = csel(infix = infix gt)
csel(infix = infix lt) csel(infix gt infix gt) cseJ(infix lt infix lt) csel(infix gt= infix gt=) csel(infix gt= infix gt csel(infix gt= infix =)
csellinfix lt= infix lt=) csel(infix lt= infix lt) csel(infix lt= infix =)
Finding solutions
sol(X v Y) -
(( notetra(X) eon(X) ( sol(Y) )
( c1ause(P v Q R) not(cketra(P v Q))
dis(P v Q X v Y R) ~ )
( A lt=gt B equival(A lt=gt B X v Y) ~ I) sol(X) - ~ notetra(X) eon(X)
so~(X) - notetra(X)
( con (X)
( clause(P v Q R) not(ekctra(P v Q)) dis(P v Q X R) I)
cketra(P v Q) -
eketra(P) eketra(Q) eketra(F(I J)) shy
selec(F(I J))
c1ause(contradiction(sel(F(IJ))) _I
eketra(number(W I)) -
clause(cootradietion(num(Wl)) - eketr(P) shy
clause(contradiction(P) - 1
notctra(P) shy
not( e lause( con tradiction(P) _))
40
Searching (or disjunctions
dis(P v Q X v Y R) - dis(P X v Y R)
dis(Q X v Y R) con(R)
dis(P v Q X R) -
dis(P X R) dis(Q X R) con(R
dis(P X v Y R) - clause(contradicton(Pl J 1
dis(F(I J) sel(G(I J)) v Y R) - csel(G Fl dis(number(WI) num(W N v Y R) - cnum(N I)
dis(P P v Y R) -
dis(P X v Y R) - dis(P Y R)
dis(F(I J) seJ(G(IJ)) R) - csel(G F)
dis(number(WI) num(WN) R) - cnum(N I) dis(P P R) - 1
dis(FJ J X R) shy
( ckctra(F(IJ) cbeckeq(seJ(F(IJ))) )
dis(number(W Il X R) - ( ckctra(number(WI)) cbeckeq(num(WI)) )
dis(P X R) shy( ckctra(P) cbeckeq(P) ) 1
cbeckeq(P) shy
(( A lt=gt so2(contradiction(P))
bagof(A A [jj) ) ( so2(contradiction(P)) lt=gt B
bagof(B B Uj) ))
ckeq(A) shy
( so2(A) lt=gt B B lt=gt so2(A) ) bagof(B B UJ)
con((P Q)) -
clause(P R) con(R) con(Q) con(true) -
con(contradiction(P)) - clause(contradiction(P) J
con(cause(X Y)) - cause(X Y)
con(sel(X)) - sel(X)
con(num(X Y)) - num(X Y) con(P)- (( dause(P R) (con(R) ckeq(R)))
colJectin(P) )
collectin(P) shy
bagof(S (c1ause(P S) S = true) [L LIJ )
mkcon(L Ll L)
bagor(l (L2 ) UJ) L
mkcon((A AI) (B B1) (sol(A v B) e D)) -
mkcon(A B1 e) mkcon(A1 (B Bl) D)
mkcon(A (B B1) (sol(A v B) e)) -
mkcon(A Bl e)
mkcon((A AI) B (sol(A v B) e)) middot1
mkcon(Al B e)
mkcon(A B sol(A vB))
Searching ror equivalences
equival(A lt=gt B X v Y) - 1 ( equival(A lt=gt B X) equival(A lt=gt B Y) )
equival(s02(A) lt=gt 502(B) A) - clause(B _I equival(s02(B) lt=gt 502(A) A) c1ause(B _I
Top level or inrerence mechanism
goo((s02(whatnum) P)) -
getatm(P Xl
bagor(number(X Y) ( P so2(number(X Y)) ) A )
count1(A 00 L R) nl
bagor(X P B )
count2(B L R Ll Rl) nJ print()
(( LI = 0 Rl = 0 print(THE ANSWER IS ) nl
(( Ll = Rl prin(-Jumber or ) prn(P) print(is Ll) )
( Rlgt20000 prin(Number or I prn(P) print(is LI or more) )
42
( prin(Number of ) pfn(P) print( is from Ll to Rl) )) )
( print(THE ANSWER IS NO I )) print()
goo(X) shy
(( bagof(X X L) L = [I nl print()
print(THE ANSWER IS YES) nl wout(L) print() )
( equiv(X L) nl print()
print(THE ANSWER IS YES) nl wout(L) print(-) )
( c1ause(inpt(A ==gt B) _I ( impli(A B Z) impli(B A Z) ) print(l~Hl)
printTHE ANSWER IS YES) nl print(Z) print(Hj~(fH~) ))
goo(X) print( Hg)
print(THE ANSWER IS NO ) print( lH~lH~gg9l9lmiddotmiddot~Q(gmiddot)
00 Semhing for implications in equiV3lent relations
impli( B Z) shyt-ell( z1) prin(templ() pchn(S A lt=gt B) print()) close ( zl) consult(zl) templ(Z)
unload zl Z
Searching for equivalence
equiv (X L)
(( X lt=gt Y
equ(Y YI)t bagof(Y Yl L) L = [j )
(Y lt=gt X equ(Y YI) bagof(Y Yl L) L = [J )
( X = F(New)
clause(~ew T) makeup(T Tl)
(( Tl lt=gt B
equ(B Bl) bagof(Bl Bl M) M = [j L=[Newl )
(A lt=gt TI
equ(A AI) bagof(Al AI M) M = 1] L=INewj )) ))
makeup((A B) (AI Bl)) -
makeup(A A1) makeup(B BI)
makeup(A so2(A))
equ((A B) (AI BI)) -
equ(A AI) equ(B Bl)
equ(sol(X v Y) sol(XI v Yl)) -
equ(X XI) equ(Y YI)
equ(so2(X) so2(XI)) -
equ(X XI)
equ(contradiction(X) clJuse(contradiction(X) X) ) -
equ(X X)
Counting numbers
getatm((A B) X) -
( getatm(A X) getatm(B X) )
getatm(so2(F(X)) X) -
getatm(so2(X) X) - atom(X)
countl([J L R L R) -
countl([number(X Y)IT] L R L2 R2) shy
(( Y = (gt=~) LI is L + N Rl is R + 20001 l )
( Y = (gt N) LI is L+ N+ 1 RI is R + 20002 )
(Y == laquo=~) LI is L + 1 Rl is R + N )
(Y = laquo N) LI is L + 1 RI is R+N-I)
(Y == IJ LI is L + I Rl is R + J ) ( Y == N L1 is L + N RI is R + N ))
count1(T LI R 1 L2 R2)
count2(fJ L R L R) - 1
count2([XITJ L R L2 R2) shy
name(X Xl)
(( Xl = sknj LI is L Rl is R )
44
( Xl = Iskmj L1 is L + 1 RI is R + ZOOO1) ( LI is L + I RI is R + I ))
count2(T LI RI L2 R2)
pfn((A B)) - pfn(A) prn(B)
pCn(so2(F(X))) - prin(F )
prn(so2(X)) - atom(X) prin(X ) prn (so2(X))
Printing result
wout([XlJ - prt(X) nl woutf[xIY]) - prt(X) nl nl wout(Y)
prt(e(A B)) -
prt(A) prinr 8 ) prt(ltE) prt(eA) - prt(A)
prt(c(A EJ) - prin() prt(A) prine ) prt(B) prin(T)
prt(c A) - prt(A) prt((A E)) - ~
prt(A) nl prt(E) prt(sol(X v Y)) - ~
prt(X) prinC v) prt(Y) prt(A lt=gt B) -
prt(e A) prinC lt=gt ) prt(e B) prt(sol(X)) - prt(X)
prt(so2(X)) - prt(X
prt(c1ause(X Y)) - prt(X)
prt(contradiction(X)) - prin(contradiction() prt(cX) prinr))middot prt(num(XY)) - prin(number(X Y)) prt(sel(X)) - prin(X) prt(X v Y) - prt(X) prin( v) prt(Y) prt(X) prin(X)
Handling conditional queries
condi((Y Xl) shy
assertcon(X) Y
45
retractcon(X)
condi((B A))
retractcon(A) fail
assertcon((A B)) 1
assertcon(A) assertcon(B)
assertcon(A) asserta(A)
retrac teon ((A B)) 1
retracteon(A) retractcon (B)
retraetcon(A) - retract(A)
BIBLIOGRAPHIC DATA SHEET
Report No UIUCDS-F-84-928
3 Recipients Accession No
4 T ide and Subt ltle
An Annotated Predicate Calculus Inference System (APCIS)
S Report Date
November 1984 6
7 Author(s)
Kah-Eng Pua 8 Performing Organization Rept
No
9 Performing Organization Name and Address
Department of Computer Science University of Illinois Urbana IL
10 ProjectTaskWork Unit No
11 Contract Grant No NSF DCR 84-06081 ONR N00014-82-K-0186
12 Sponsoring Organization Name and Address
National Science Foundation Washington DC
13 Type of Report amp Period Covered
14
15 Supplementary Notes
16 Abstracts
This paper describes a deductive inference system called APCIS (Annotated Predicate Calculus Inference System) APCIS is able to carry out inferences from expressions involving numerical quantifiers selectors disjunctions of non-negated terms negated terms disjunctions of negated terms equivalences and exceptions It is also able to count the numbers of occurrence of a given simple term or a conjunction of terms The design of contradiction and the treatment of the disjunction of non-negated terms allow APCIS to accept Horn clauses as well as non-Horn clauses and to carry out inferences from them This feature makes APCIS more general than Prolog
17 Key lords and Document Analysis 170 Descriptors
APC (Annotated Predicate Calculus) APCIS (Annotated Predicate Calculus Inference System) Horn Clause Numerical Quantifier Prolog Selector
17b IdentifiersOpen-Ended Terms
17c COSATI FieldGroup
18 Availability Statement 19 Security Class (This
Re~f~~IA~SIF IFf)
21 ~o of Pages
49 211 ecurity Class (This
PageUNCLASSIFIED
22 Price
FOA NTIS n (10middot70 usco-oc 40329-
40
Searching (or disjunctions
dis(P v Q X v Y R) - dis(P X v Y R)
dis(Q X v Y R) con(R)
dis(P v Q X R) -
dis(P X R) dis(Q X R) con(R
dis(P X v Y R) - clause(contradicton(Pl J 1
dis(F(I J) sel(G(I J)) v Y R) - csel(G Fl dis(number(WI) num(W N v Y R) - cnum(N I)
dis(P P v Y R) -
dis(P X v Y R) - dis(P Y R)
dis(F(I J) seJ(G(IJ)) R) - csel(G F)
dis(number(WI) num(WN) R) - cnum(N I) dis(P P R) - 1
dis(FJ J X R) shy
( ckctra(F(IJ) cbeckeq(seJ(F(IJ))) )
dis(number(W Il X R) - ( ckctra(number(WI)) cbeckeq(num(WI)) )
dis(P X R) shy( ckctra(P) cbeckeq(P) ) 1
cbeckeq(P) shy
(( A lt=gt so2(contradiction(P))
bagof(A A [jj) ) ( so2(contradiction(P)) lt=gt B
bagof(B B Uj) ))
ckeq(A) shy
( so2(A) lt=gt B B lt=gt so2(A) ) bagof(B B UJ)
con((P Q)) -
clause(P R) con(R) con(Q) con(true) -
con(contradiction(P)) - clause(contradiction(P) J
con(cause(X Y)) - cause(X Y)
con(sel(X)) - sel(X)
con(num(X Y)) - num(X Y) con(P)- (( dause(P R) (con(R) ckeq(R)))
colJectin(P) )
collectin(P) shy
bagof(S (c1ause(P S) S = true) [L LIJ )
mkcon(L Ll L)
bagor(l (L2 ) UJ) L
mkcon((A AI) (B B1) (sol(A v B) e D)) -
mkcon(A B1 e) mkcon(A1 (B Bl) D)
mkcon(A (B B1) (sol(A v B) e)) -
mkcon(A Bl e)
mkcon((A AI) B (sol(A v B) e)) middot1
mkcon(Al B e)
mkcon(A B sol(A vB))
Searching ror equivalences
equival(A lt=gt B X v Y) - 1 ( equival(A lt=gt B X) equival(A lt=gt B Y) )
equival(s02(A) lt=gt 502(B) A) - clause(B _I equival(s02(B) lt=gt 502(A) A) c1ause(B _I
Top level or inrerence mechanism
goo((s02(whatnum) P)) -
getatm(P Xl
bagor(number(X Y) ( P so2(number(X Y)) ) A )
count1(A 00 L R) nl
bagor(X P B )
count2(B L R Ll Rl) nJ print()
(( LI = 0 Rl = 0 print(THE ANSWER IS ) nl
(( Ll = Rl prin(-Jumber or ) prn(P) print(is Ll) )
( Rlgt20000 prin(Number or I prn(P) print(is LI or more) )
42
( prin(Number of ) pfn(P) print( is from Ll to Rl) )) )
( print(THE ANSWER IS NO I )) print()
goo(X) shy
(( bagof(X X L) L = [I nl print()
print(THE ANSWER IS YES) nl wout(L) print() )
( equiv(X L) nl print()
print(THE ANSWER IS YES) nl wout(L) print(-) )
( c1ause(inpt(A ==gt B) _I ( impli(A B Z) impli(B A Z) ) print(l~Hl)
printTHE ANSWER IS YES) nl print(Z) print(Hj~(fH~) ))
goo(X) print( Hg)
print(THE ANSWER IS NO ) print( lH~lH~gg9l9lmiddotmiddot~Q(gmiddot)
00 Semhing for implications in equiV3lent relations
impli( B Z) shyt-ell( z1) prin(templ() pchn(S A lt=gt B) print()) close ( zl) consult(zl) templ(Z)
unload zl Z
Searching for equivalence
equiv (X L)
(( X lt=gt Y
equ(Y YI)t bagof(Y Yl L) L = [j )
(Y lt=gt X equ(Y YI) bagof(Y Yl L) L = [J )
( X = F(New)
clause(~ew T) makeup(T Tl)
(( Tl lt=gt B
equ(B Bl) bagof(Bl Bl M) M = [j L=[Newl )
(A lt=gt TI
equ(A AI) bagof(Al AI M) M = 1] L=INewj )) ))
makeup((A B) (AI Bl)) -
makeup(A A1) makeup(B BI)
makeup(A so2(A))
equ((A B) (AI BI)) -
equ(A AI) equ(B Bl)
equ(sol(X v Y) sol(XI v Yl)) -
equ(X XI) equ(Y YI)
equ(so2(X) so2(XI)) -
equ(X XI)
equ(contradiction(X) clJuse(contradiction(X) X) ) -
equ(X X)
Counting numbers
getatm((A B) X) -
( getatm(A X) getatm(B X) )
getatm(so2(F(X)) X) -
getatm(so2(X) X) - atom(X)
countl([J L R L R) -
countl([number(X Y)IT] L R L2 R2) shy
(( Y = (gt=~) LI is L + N Rl is R + 20001 l )
( Y = (gt N) LI is L+ N+ 1 RI is R + 20002 )
(Y == laquo=~) LI is L + 1 Rl is R + N )
(Y = laquo N) LI is L + 1 RI is R+N-I)
(Y == IJ LI is L + I Rl is R + J ) ( Y == N L1 is L + N RI is R + N ))
count1(T LI R 1 L2 R2)
count2(fJ L R L R) - 1
count2([XITJ L R L2 R2) shy
name(X Xl)
(( Xl = sknj LI is L Rl is R )
44
( Xl = Iskmj L1 is L + 1 RI is R + ZOOO1) ( LI is L + I RI is R + I ))
count2(T LI RI L2 R2)
pfn((A B)) - pfn(A) prn(B)
pCn(so2(F(X))) - prin(F )
prn(so2(X)) - atom(X) prin(X ) prn (so2(X))
Printing result
wout([XlJ - prt(X) nl woutf[xIY]) - prt(X) nl nl wout(Y)
prt(e(A B)) -
prt(A) prinr 8 ) prt(ltE) prt(eA) - prt(A)
prt(c(A EJ) - prin() prt(A) prine ) prt(B) prin(T)
prt(c A) - prt(A) prt((A E)) - ~
prt(A) nl prt(E) prt(sol(X v Y)) - ~
prt(X) prinC v) prt(Y) prt(A lt=gt B) -
prt(e A) prinC lt=gt ) prt(e B) prt(sol(X)) - prt(X)
prt(so2(X)) - prt(X
prt(c1ause(X Y)) - prt(X)
prt(contradiction(X)) - prin(contradiction() prt(cX) prinr))middot prt(num(XY)) - prin(number(X Y)) prt(sel(X)) - prin(X) prt(X v Y) - prt(X) prin( v) prt(Y) prt(X) prin(X)
Handling conditional queries
condi((Y Xl) shy
assertcon(X) Y
45
retractcon(X)
condi((B A))
retractcon(A) fail
assertcon((A B)) 1
assertcon(A) assertcon(B)
assertcon(A) asserta(A)
retrac teon ((A B)) 1
retracteon(A) retractcon (B)
retraetcon(A) - retract(A)
BIBLIOGRAPHIC DATA SHEET
Report No UIUCDS-F-84-928
3 Recipients Accession No
4 T ide and Subt ltle
An Annotated Predicate Calculus Inference System (APCIS)
S Report Date
November 1984 6
7 Author(s)
Kah-Eng Pua 8 Performing Organization Rept
No
9 Performing Organization Name and Address
Department of Computer Science University of Illinois Urbana IL
10 ProjectTaskWork Unit No
11 Contract Grant No NSF DCR 84-06081 ONR N00014-82-K-0186
12 Sponsoring Organization Name and Address
National Science Foundation Washington DC
13 Type of Report amp Period Covered
14
15 Supplementary Notes
16 Abstracts
This paper describes a deductive inference system called APCIS (Annotated Predicate Calculus Inference System) APCIS is able to carry out inferences from expressions involving numerical quantifiers selectors disjunctions of non-negated terms negated terms disjunctions of negated terms equivalences and exceptions It is also able to count the numbers of occurrence of a given simple term or a conjunction of terms The design of contradiction and the treatment of the disjunction of non-negated terms allow APCIS to accept Horn clauses as well as non-Horn clauses and to carry out inferences from them This feature makes APCIS more general than Prolog
17 Key lords and Document Analysis 170 Descriptors
APC (Annotated Predicate Calculus) APCIS (Annotated Predicate Calculus Inference System) Horn Clause Numerical Quantifier Prolog Selector
17b IdentifiersOpen-Ended Terms
17c COSATI FieldGroup
18 Availability Statement 19 Security Class (This
Re~f~~IA~SIF IFf)
21 ~o of Pages
49 211 ecurity Class (This
PageUNCLASSIFIED
22 Price
FOA NTIS n (10middot70 usco-oc 40329-
con(cause(X Y)) - cause(X Y)
con(sel(X)) - sel(X)
con(num(X Y)) - num(X Y) con(P)- (( dause(P R) (con(R) ckeq(R)))
colJectin(P) )
collectin(P) shy
bagof(S (c1ause(P S) S = true) [L LIJ )
mkcon(L Ll L)
bagor(l (L2 ) UJ) L
mkcon((A AI) (B B1) (sol(A v B) e D)) -
mkcon(A B1 e) mkcon(A1 (B Bl) D)
mkcon(A (B B1) (sol(A v B) e)) -
mkcon(A Bl e)
mkcon((A AI) B (sol(A v B) e)) middot1
mkcon(Al B e)
mkcon(A B sol(A vB))
Searching ror equivalences
equival(A lt=gt B X v Y) - 1 ( equival(A lt=gt B X) equival(A lt=gt B Y) )
equival(s02(A) lt=gt 502(B) A) - clause(B _I equival(s02(B) lt=gt 502(A) A) c1ause(B _I
Top level or inrerence mechanism
goo((s02(whatnum) P)) -
getatm(P Xl
bagor(number(X Y) ( P so2(number(X Y)) ) A )
count1(A 00 L R) nl
bagor(X P B )
count2(B L R Ll Rl) nJ print()
(( LI = 0 Rl = 0 print(THE ANSWER IS ) nl
(( Ll = Rl prin(-Jumber or ) prn(P) print(is Ll) )
( Rlgt20000 prin(Number or I prn(P) print(is LI or more) )
42
( prin(Number of ) pfn(P) print( is from Ll to Rl) )) )
( print(THE ANSWER IS NO I )) print()
goo(X) shy
(( bagof(X X L) L = [I nl print()
print(THE ANSWER IS YES) nl wout(L) print() )
( equiv(X L) nl print()
print(THE ANSWER IS YES) nl wout(L) print(-) )
( c1ause(inpt(A ==gt B) _I ( impli(A B Z) impli(B A Z) ) print(l~Hl)
printTHE ANSWER IS YES) nl print(Z) print(Hj~(fH~) ))
goo(X) print( Hg)
print(THE ANSWER IS NO ) print( lH~lH~gg9l9lmiddotmiddot~Q(gmiddot)
00 Semhing for implications in equiV3lent relations
impli( B Z) shyt-ell( z1) prin(templ() pchn(S A lt=gt B) print()) close ( zl) consult(zl) templ(Z)
unload zl Z
Searching for equivalence
equiv (X L)
(( X lt=gt Y
equ(Y YI)t bagof(Y Yl L) L = [j )
(Y lt=gt X equ(Y YI) bagof(Y Yl L) L = [J )
( X = F(New)
clause(~ew T) makeup(T Tl)
(( Tl lt=gt B
equ(B Bl) bagof(Bl Bl M) M = [j L=[Newl )
(A lt=gt TI
equ(A AI) bagof(Al AI M) M = 1] L=INewj )) ))
makeup((A B) (AI Bl)) -
makeup(A A1) makeup(B BI)
makeup(A so2(A))
equ((A B) (AI BI)) -
equ(A AI) equ(B Bl)
equ(sol(X v Y) sol(XI v Yl)) -
equ(X XI) equ(Y YI)
equ(so2(X) so2(XI)) -
equ(X XI)
equ(contradiction(X) clJuse(contradiction(X) X) ) -
equ(X X)
Counting numbers
getatm((A B) X) -
( getatm(A X) getatm(B X) )
getatm(so2(F(X)) X) -
getatm(so2(X) X) - atom(X)
countl([J L R L R) -
countl([number(X Y)IT] L R L2 R2) shy
(( Y = (gt=~) LI is L + N Rl is R + 20001 l )
( Y = (gt N) LI is L+ N+ 1 RI is R + 20002 )
(Y == laquo=~) LI is L + 1 Rl is R + N )
(Y = laquo N) LI is L + 1 RI is R+N-I)
(Y == IJ LI is L + I Rl is R + J ) ( Y == N L1 is L + N RI is R + N ))
count1(T LI R 1 L2 R2)
count2(fJ L R L R) - 1
count2([XITJ L R L2 R2) shy
name(X Xl)
(( Xl = sknj LI is L Rl is R )
44
( Xl = Iskmj L1 is L + 1 RI is R + ZOOO1) ( LI is L + I RI is R + I ))
count2(T LI RI L2 R2)
pfn((A B)) - pfn(A) prn(B)
pCn(so2(F(X))) - prin(F )
prn(so2(X)) - atom(X) prin(X ) prn (so2(X))
Printing result
wout([XlJ - prt(X) nl woutf[xIY]) - prt(X) nl nl wout(Y)
prt(e(A B)) -
prt(A) prinr 8 ) prt(ltE) prt(eA) - prt(A)
prt(c(A EJ) - prin() prt(A) prine ) prt(B) prin(T)
prt(c A) - prt(A) prt((A E)) - ~
prt(A) nl prt(E) prt(sol(X v Y)) - ~
prt(X) prinC v) prt(Y) prt(A lt=gt B) -
prt(e A) prinC lt=gt ) prt(e B) prt(sol(X)) - prt(X)
prt(so2(X)) - prt(X
prt(c1ause(X Y)) - prt(X)
prt(contradiction(X)) - prin(contradiction() prt(cX) prinr))middot prt(num(XY)) - prin(number(X Y)) prt(sel(X)) - prin(X) prt(X v Y) - prt(X) prin( v) prt(Y) prt(X) prin(X)
Handling conditional queries
condi((Y Xl) shy
assertcon(X) Y
45
retractcon(X)
condi((B A))
retractcon(A) fail
assertcon((A B)) 1
assertcon(A) assertcon(B)
assertcon(A) asserta(A)
retrac teon ((A B)) 1
retracteon(A) retractcon (B)
retraetcon(A) - retract(A)
BIBLIOGRAPHIC DATA SHEET
Report No UIUCDS-F-84-928
3 Recipients Accession No
4 T ide and Subt ltle
An Annotated Predicate Calculus Inference System (APCIS)
S Report Date
November 1984 6
7 Author(s)
Kah-Eng Pua 8 Performing Organization Rept
No
9 Performing Organization Name and Address
Department of Computer Science University of Illinois Urbana IL
10 ProjectTaskWork Unit No
11 Contract Grant No NSF DCR 84-06081 ONR N00014-82-K-0186
12 Sponsoring Organization Name and Address
National Science Foundation Washington DC
13 Type of Report amp Period Covered
14
15 Supplementary Notes
16 Abstracts
This paper describes a deductive inference system called APCIS (Annotated Predicate Calculus Inference System) APCIS is able to carry out inferences from expressions involving numerical quantifiers selectors disjunctions of non-negated terms negated terms disjunctions of negated terms equivalences and exceptions It is also able to count the numbers of occurrence of a given simple term or a conjunction of terms The design of contradiction and the treatment of the disjunction of non-negated terms allow APCIS to accept Horn clauses as well as non-Horn clauses and to carry out inferences from them This feature makes APCIS more general than Prolog
17 Key lords and Document Analysis 170 Descriptors
APC (Annotated Predicate Calculus) APCIS (Annotated Predicate Calculus Inference System) Horn Clause Numerical Quantifier Prolog Selector
17b IdentifiersOpen-Ended Terms
17c COSATI FieldGroup
18 Availability Statement 19 Security Class (This
Re~f~~IA~SIF IFf)
21 ~o of Pages
49 211 ecurity Class (This
PageUNCLASSIFIED
22 Price
FOA NTIS n (10middot70 usco-oc 40329-
42
( prin(Number of ) pfn(P) print( is from Ll to Rl) )) )
( print(THE ANSWER IS NO I )) print()
goo(X) shy
(( bagof(X X L) L = [I nl print()
print(THE ANSWER IS YES) nl wout(L) print() )
( equiv(X L) nl print()
print(THE ANSWER IS YES) nl wout(L) print(-) )
( c1ause(inpt(A ==gt B) _I ( impli(A B Z) impli(B A Z) ) print(l~Hl)
printTHE ANSWER IS YES) nl print(Z) print(Hj~(fH~) ))
goo(X) print( Hg)
print(THE ANSWER IS NO ) print( lH~lH~gg9l9lmiddotmiddot~Q(gmiddot)
00 Semhing for implications in equiV3lent relations
impli( B Z) shyt-ell( z1) prin(templ() pchn(S A lt=gt B) print()) close ( zl) consult(zl) templ(Z)
unload zl Z
Searching for equivalence
equiv (X L)
(( X lt=gt Y
equ(Y YI)t bagof(Y Yl L) L = [j )
(Y lt=gt X equ(Y YI) bagof(Y Yl L) L = [J )
( X = F(New)
clause(~ew T) makeup(T Tl)
(( Tl lt=gt B
equ(B Bl) bagof(Bl Bl M) M = [j L=[Newl )
(A lt=gt TI
equ(A AI) bagof(Al AI M) M = 1] L=INewj )) ))
makeup((A B) (AI Bl)) -
makeup(A A1) makeup(B BI)
makeup(A so2(A))
equ((A B) (AI BI)) -
equ(A AI) equ(B Bl)
equ(sol(X v Y) sol(XI v Yl)) -
equ(X XI) equ(Y YI)
equ(so2(X) so2(XI)) -
equ(X XI)
equ(contradiction(X) clJuse(contradiction(X) X) ) -
equ(X X)
Counting numbers
getatm((A B) X) -
( getatm(A X) getatm(B X) )
getatm(so2(F(X)) X) -
getatm(so2(X) X) - atom(X)
countl([J L R L R) -
countl([number(X Y)IT] L R L2 R2) shy
(( Y = (gt=~) LI is L + N Rl is R + 20001 l )
( Y = (gt N) LI is L+ N+ 1 RI is R + 20002 )
(Y == laquo=~) LI is L + 1 Rl is R + N )
(Y = laquo N) LI is L + 1 RI is R+N-I)
(Y == IJ LI is L + I Rl is R + J ) ( Y == N L1 is L + N RI is R + N ))
count1(T LI R 1 L2 R2)
count2(fJ L R L R) - 1
count2([XITJ L R L2 R2) shy
name(X Xl)
(( Xl = sknj LI is L Rl is R )
44
( Xl = Iskmj L1 is L + 1 RI is R + ZOOO1) ( LI is L + I RI is R + I ))
count2(T LI RI L2 R2)
pfn((A B)) - pfn(A) prn(B)
pCn(so2(F(X))) - prin(F )
prn(so2(X)) - atom(X) prin(X ) prn (so2(X))
Printing result
wout([XlJ - prt(X) nl woutf[xIY]) - prt(X) nl nl wout(Y)
prt(e(A B)) -
prt(A) prinr 8 ) prt(ltE) prt(eA) - prt(A)
prt(c(A EJ) - prin() prt(A) prine ) prt(B) prin(T)
prt(c A) - prt(A) prt((A E)) - ~
prt(A) nl prt(E) prt(sol(X v Y)) - ~
prt(X) prinC v) prt(Y) prt(A lt=gt B) -
prt(e A) prinC lt=gt ) prt(e B) prt(sol(X)) - prt(X)
prt(so2(X)) - prt(X
prt(c1ause(X Y)) - prt(X)
prt(contradiction(X)) - prin(contradiction() prt(cX) prinr))middot prt(num(XY)) - prin(number(X Y)) prt(sel(X)) - prin(X) prt(X v Y) - prt(X) prin( v) prt(Y) prt(X) prin(X)
Handling conditional queries
condi((Y Xl) shy
assertcon(X) Y
45
retractcon(X)
condi((B A))
retractcon(A) fail
assertcon((A B)) 1
assertcon(A) assertcon(B)
assertcon(A) asserta(A)
retrac teon ((A B)) 1
retracteon(A) retractcon (B)
retraetcon(A) - retract(A)
BIBLIOGRAPHIC DATA SHEET
Report No UIUCDS-F-84-928
3 Recipients Accession No
4 T ide and Subt ltle
An Annotated Predicate Calculus Inference System (APCIS)
S Report Date
November 1984 6
7 Author(s)
Kah-Eng Pua 8 Performing Organization Rept
No
9 Performing Organization Name and Address
Department of Computer Science University of Illinois Urbana IL
10 ProjectTaskWork Unit No
11 Contract Grant No NSF DCR 84-06081 ONR N00014-82-K-0186
12 Sponsoring Organization Name and Address
National Science Foundation Washington DC
13 Type of Report amp Period Covered
14
15 Supplementary Notes
16 Abstracts
This paper describes a deductive inference system called APCIS (Annotated Predicate Calculus Inference System) APCIS is able to carry out inferences from expressions involving numerical quantifiers selectors disjunctions of non-negated terms negated terms disjunctions of negated terms equivalences and exceptions It is also able to count the numbers of occurrence of a given simple term or a conjunction of terms The design of contradiction and the treatment of the disjunction of non-negated terms allow APCIS to accept Horn clauses as well as non-Horn clauses and to carry out inferences from them This feature makes APCIS more general than Prolog
17 Key lords and Document Analysis 170 Descriptors
APC (Annotated Predicate Calculus) APCIS (Annotated Predicate Calculus Inference System) Horn Clause Numerical Quantifier Prolog Selector
17b IdentifiersOpen-Ended Terms
17c COSATI FieldGroup
18 Availability Statement 19 Security Class (This
Re~f~~IA~SIF IFf)
21 ~o of Pages
49 211 ecurity Class (This
PageUNCLASSIFIED
22 Price
FOA NTIS n (10middot70 usco-oc 40329-
clause(~ew T) makeup(T Tl)
(( Tl lt=gt B
equ(B Bl) bagof(Bl Bl M) M = [j L=[Newl )
(A lt=gt TI
equ(A AI) bagof(Al AI M) M = 1] L=INewj )) ))
makeup((A B) (AI Bl)) -
makeup(A A1) makeup(B BI)
makeup(A so2(A))
equ((A B) (AI BI)) -
equ(A AI) equ(B Bl)
equ(sol(X v Y) sol(XI v Yl)) -
equ(X XI) equ(Y YI)
equ(so2(X) so2(XI)) -
equ(X XI)
equ(contradiction(X) clJuse(contradiction(X) X) ) -
equ(X X)
Counting numbers
getatm((A B) X) -
( getatm(A X) getatm(B X) )
getatm(so2(F(X)) X) -
getatm(so2(X) X) - atom(X)
countl([J L R L R) -
countl([number(X Y)IT] L R L2 R2) shy
(( Y = (gt=~) LI is L + N Rl is R + 20001 l )
( Y = (gt N) LI is L+ N+ 1 RI is R + 20002 )
(Y == laquo=~) LI is L + 1 Rl is R + N )
(Y = laquo N) LI is L + 1 RI is R+N-I)
(Y == IJ LI is L + I Rl is R + J ) ( Y == N L1 is L + N RI is R + N ))
count1(T LI R 1 L2 R2)
count2(fJ L R L R) - 1
count2([XITJ L R L2 R2) shy
name(X Xl)
(( Xl = sknj LI is L Rl is R )
44
( Xl = Iskmj L1 is L + 1 RI is R + ZOOO1) ( LI is L + I RI is R + I ))
count2(T LI RI L2 R2)
pfn((A B)) - pfn(A) prn(B)
pCn(so2(F(X))) - prin(F )
prn(so2(X)) - atom(X) prin(X ) prn (so2(X))
Printing result
wout([XlJ - prt(X) nl woutf[xIY]) - prt(X) nl nl wout(Y)
prt(e(A B)) -
prt(A) prinr 8 ) prt(ltE) prt(eA) - prt(A)
prt(c(A EJ) - prin() prt(A) prine ) prt(B) prin(T)
prt(c A) - prt(A) prt((A E)) - ~
prt(A) nl prt(E) prt(sol(X v Y)) - ~
prt(X) prinC v) prt(Y) prt(A lt=gt B) -
prt(e A) prinC lt=gt ) prt(e B) prt(sol(X)) - prt(X)
prt(so2(X)) - prt(X
prt(c1ause(X Y)) - prt(X)
prt(contradiction(X)) - prin(contradiction() prt(cX) prinr))middot prt(num(XY)) - prin(number(X Y)) prt(sel(X)) - prin(X) prt(X v Y) - prt(X) prin( v) prt(Y) prt(X) prin(X)
Handling conditional queries
condi((Y Xl) shy
assertcon(X) Y
45
retractcon(X)
condi((B A))
retractcon(A) fail
assertcon((A B)) 1
assertcon(A) assertcon(B)
assertcon(A) asserta(A)
retrac teon ((A B)) 1
retracteon(A) retractcon (B)
retraetcon(A) - retract(A)
BIBLIOGRAPHIC DATA SHEET
Report No UIUCDS-F-84-928
3 Recipients Accession No
4 T ide and Subt ltle
An Annotated Predicate Calculus Inference System (APCIS)
S Report Date
November 1984 6
7 Author(s)
Kah-Eng Pua 8 Performing Organization Rept
No
9 Performing Organization Name and Address
Department of Computer Science University of Illinois Urbana IL
10 ProjectTaskWork Unit No
11 Contract Grant No NSF DCR 84-06081 ONR N00014-82-K-0186
12 Sponsoring Organization Name and Address
National Science Foundation Washington DC
13 Type of Report amp Period Covered
14
15 Supplementary Notes
16 Abstracts
This paper describes a deductive inference system called APCIS (Annotated Predicate Calculus Inference System) APCIS is able to carry out inferences from expressions involving numerical quantifiers selectors disjunctions of non-negated terms negated terms disjunctions of negated terms equivalences and exceptions It is also able to count the numbers of occurrence of a given simple term or a conjunction of terms The design of contradiction and the treatment of the disjunction of non-negated terms allow APCIS to accept Horn clauses as well as non-Horn clauses and to carry out inferences from them This feature makes APCIS more general than Prolog
17 Key lords and Document Analysis 170 Descriptors
APC (Annotated Predicate Calculus) APCIS (Annotated Predicate Calculus Inference System) Horn Clause Numerical Quantifier Prolog Selector
17b IdentifiersOpen-Ended Terms
17c COSATI FieldGroup
18 Availability Statement 19 Security Class (This
Re~f~~IA~SIF IFf)
21 ~o of Pages
49 211 ecurity Class (This
PageUNCLASSIFIED
22 Price
FOA NTIS n (10middot70 usco-oc 40329-
44
( Xl = Iskmj L1 is L + 1 RI is R + ZOOO1) ( LI is L + I RI is R + I ))
count2(T LI RI L2 R2)
pfn((A B)) - pfn(A) prn(B)
pCn(so2(F(X))) - prin(F )
prn(so2(X)) - atom(X) prin(X ) prn (so2(X))
Printing result
wout([XlJ - prt(X) nl woutf[xIY]) - prt(X) nl nl wout(Y)
prt(e(A B)) -
prt(A) prinr 8 ) prt(ltE) prt(eA) - prt(A)
prt(c(A EJ) - prin() prt(A) prine ) prt(B) prin(T)
prt(c A) - prt(A) prt((A E)) - ~
prt(A) nl prt(E) prt(sol(X v Y)) - ~
prt(X) prinC v) prt(Y) prt(A lt=gt B) -
prt(e A) prinC lt=gt ) prt(e B) prt(sol(X)) - prt(X)
prt(so2(X)) - prt(X
prt(c1ause(X Y)) - prt(X)
prt(contradiction(X)) - prin(contradiction() prt(cX) prinr))middot prt(num(XY)) - prin(number(X Y)) prt(sel(X)) - prin(X) prt(X v Y) - prt(X) prin( v) prt(Y) prt(X) prin(X)
Handling conditional queries
condi((Y Xl) shy
assertcon(X) Y
45
retractcon(X)
condi((B A))
retractcon(A) fail
assertcon((A B)) 1
assertcon(A) assertcon(B)
assertcon(A) asserta(A)
retrac teon ((A B)) 1
retracteon(A) retractcon (B)
retraetcon(A) - retract(A)
BIBLIOGRAPHIC DATA SHEET
Report No UIUCDS-F-84-928
3 Recipients Accession No
4 T ide and Subt ltle
An Annotated Predicate Calculus Inference System (APCIS)
S Report Date
November 1984 6
7 Author(s)
Kah-Eng Pua 8 Performing Organization Rept
No
9 Performing Organization Name and Address
Department of Computer Science University of Illinois Urbana IL
10 ProjectTaskWork Unit No
11 Contract Grant No NSF DCR 84-06081 ONR N00014-82-K-0186
12 Sponsoring Organization Name and Address
National Science Foundation Washington DC
13 Type of Report amp Period Covered
14
15 Supplementary Notes
16 Abstracts
This paper describes a deductive inference system called APCIS (Annotated Predicate Calculus Inference System) APCIS is able to carry out inferences from expressions involving numerical quantifiers selectors disjunctions of non-negated terms negated terms disjunctions of negated terms equivalences and exceptions It is also able to count the numbers of occurrence of a given simple term or a conjunction of terms The design of contradiction and the treatment of the disjunction of non-negated terms allow APCIS to accept Horn clauses as well as non-Horn clauses and to carry out inferences from them This feature makes APCIS more general than Prolog
17 Key lords and Document Analysis 170 Descriptors
APC (Annotated Predicate Calculus) APCIS (Annotated Predicate Calculus Inference System) Horn Clause Numerical Quantifier Prolog Selector
17b IdentifiersOpen-Ended Terms
17c COSATI FieldGroup
18 Availability Statement 19 Security Class (This
Re~f~~IA~SIF IFf)
21 ~o of Pages
49 211 ecurity Class (This
PageUNCLASSIFIED
22 Price
FOA NTIS n (10middot70 usco-oc 40329-
45
retractcon(X)
condi((B A))
retractcon(A) fail
assertcon((A B)) 1
assertcon(A) assertcon(B)
assertcon(A) asserta(A)
retrac teon ((A B)) 1
retracteon(A) retractcon (B)
retraetcon(A) - retract(A)
BIBLIOGRAPHIC DATA SHEET
Report No UIUCDS-F-84-928
3 Recipients Accession No
4 T ide and Subt ltle
An Annotated Predicate Calculus Inference System (APCIS)
S Report Date
November 1984 6
7 Author(s)
Kah-Eng Pua 8 Performing Organization Rept
No
9 Performing Organization Name and Address
Department of Computer Science University of Illinois Urbana IL
10 ProjectTaskWork Unit No
11 Contract Grant No NSF DCR 84-06081 ONR N00014-82-K-0186
12 Sponsoring Organization Name and Address
National Science Foundation Washington DC
13 Type of Report amp Period Covered
14
15 Supplementary Notes
16 Abstracts
This paper describes a deductive inference system called APCIS (Annotated Predicate Calculus Inference System) APCIS is able to carry out inferences from expressions involving numerical quantifiers selectors disjunctions of non-negated terms negated terms disjunctions of negated terms equivalences and exceptions It is also able to count the numbers of occurrence of a given simple term or a conjunction of terms The design of contradiction and the treatment of the disjunction of non-negated terms allow APCIS to accept Horn clauses as well as non-Horn clauses and to carry out inferences from them This feature makes APCIS more general than Prolog
17 Key lords and Document Analysis 170 Descriptors
APC (Annotated Predicate Calculus) APCIS (Annotated Predicate Calculus Inference System) Horn Clause Numerical Quantifier Prolog Selector
17b IdentifiersOpen-Ended Terms
17c COSATI FieldGroup
18 Availability Statement 19 Security Class (This
Re~f~~IA~SIF IFf)
21 ~o of Pages
49 211 ecurity Class (This
PageUNCLASSIFIED
22 Price
FOA NTIS n (10middot70 usco-oc 40329-
BIBLIOGRAPHIC DATA SHEET
Report No UIUCDS-F-84-928
3 Recipients Accession No
4 T ide and Subt ltle
An Annotated Predicate Calculus Inference System (APCIS)
S Report Date
November 1984 6
7 Author(s)
Kah-Eng Pua 8 Performing Organization Rept
No
9 Performing Organization Name and Address
Department of Computer Science University of Illinois Urbana IL
10 ProjectTaskWork Unit No
11 Contract Grant No NSF DCR 84-06081 ONR N00014-82-K-0186
12 Sponsoring Organization Name and Address
National Science Foundation Washington DC
13 Type of Report amp Period Covered
14
15 Supplementary Notes
16 Abstracts
This paper describes a deductive inference system called APCIS (Annotated Predicate Calculus Inference System) APCIS is able to carry out inferences from expressions involving numerical quantifiers selectors disjunctions of non-negated terms negated terms disjunctions of negated terms equivalences and exceptions It is also able to count the numbers of occurrence of a given simple term or a conjunction of terms The design of contradiction and the treatment of the disjunction of non-negated terms allow APCIS to accept Horn clauses as well as non-Horn clauses and to carry out inferences from them This feature makes APCIS more general than Prolog
17 Key lords and Document Analysis 170 Descriptors
APC (Annotated Predicate Calculus) APCIS (Annotated Predicate Calculus Inference System) Horn Clause Numerical Quantifier Prolog Selector
17b IdentifiersOpen-Ended Terms
17c COSATI FieldGroup
18 Availability Statement 19 Security Class (This
Re~f~~IA~SIF IFf)
21 ~o of Pages
49 211 ecurity Class (This
PageUNCLASSIFIED
22 Price
FOA NTIS n (10middot70 usco-oc 40329-