Title: Reasoning with Logic Programming
1Reasoning with Logic Programming
- Luís Moniz Pereira
- José Júlio Alferes
2Aim
- To provide a logic programming integrated
framework and working system, for representing
knowledge and reason about classical AI topics
and applications, such as - taxonomies
- hypothetical reasoning
- abduction
- paraconsistent reasoning
- revision
- diagnosis
3Topics
- Overview of Logic Programs semantics
- Explicit negation semantics
- Paraconsistency
- Methodology for KR in LP
- Proof procedures
- Belief revision and abduction
4LP forKnowledge Representation
- Due to its declarative nature, LP has become a
prime candidate for Knowledge Representation and
Reasoning - This has been more noticeable since its relations
to other NMR formalisms were established - For this usage of LP, a precise declarative
semantics was in order
5Language
- A Normal Logic Programs P is a set of rules
- H ??A1, , An, not B1, not Bm (n,m ? 0)
- where H, Ai and Bj are atoms
- Literal not Bj are called default literals
- When no rule in P has default literal, P is
called definite - The Herbrand base HP is the set of all
instantiated atoms from program P. - We will consider programs as possibly infinite
sets of instantiated rules.
6Declarative Programming
- A logic program can be an executable
specification of a problem
member(X,XY). member(X,YL) ? member(X,L).
- Easier to program, compact code
- Adequate for building prototypes
- Given efficient implementations, why not use it
to program directly?
7LP and Deductive Databases
- In a database, tables are viewed as sets of
facts - Flight(lisbon,adam)
- Flight(lisbon,london)
- Flight(lisbon, munich)
- Flight(munich,dresden)
- Other relations are represented with rules
- Connection(A,B) if flight(A,B).
- Connection(A,B) if flight(A,C), connection(C,B).
- chooseAnother(A,B) if not connection(A,B).
8Default Rules
- The representation of default rules, such as
- All birds fly
- can be done via the non-monotonic operator not
- Flies(A) if bird(A), not abnormal(A).
- Bird(P) if penguin(P)
- Abnormal(P) if penguin(P)
- Bird(a)
- Penguin(p).
9The need for a semantics
- In all the previous examples, classical logic is
not an appropriate semantics - In the 1st, it does not derive not
member(3,1,2) - In the 2nd, it never concludes choosing another
company - In the 3rd, all abnormalities must be expressed
- The precise definition of a declarative semantics
for LPs is recognized as an important issue for
its use in KRR.
102-valued Interpretations
- A 2-valued interpretation I of P is a subset of
HP - A is true in I (ie. I(A) 1) iff A ? I
- Otherwise, A is false in I (ie. I(A) 0)
113-valued Interpretations
- A 3-valued interpretation I of P is a set
- I T U not F
- where T and F are disjoint subsets of HP
- A is true in I iff A ? T
- A is false in I iff A ? F
- Otherwise, A is undefined (I(A) 1/2)
- 2-valued interpretations are a special case,
where - HP T U F
12Models
- Models can be defined via an evaluation function
Î - For an atom A, Î(A) I(A)
- For a formula F, Î(not F) 1 - Î(F)
- For formulas F and G
- Î((F,G)) min(Î(F), Î(G))
- Î(F ? G) 1 if Î(G) ? Î(F), and 0 otherwise
13Minimal Models Semantics
- The idea of this semantics is to minimize
positive information. What is implied as true by
the program is true everything else is
false. ableMathematician(X) if
physicist(X) physicist(einstein) president(sam
paio)
- pr(s),pr(e),ph(s),ph(e),aM(s),aM(e) is a model
- Lack of information that sampaio is a physicist,
should indicate that he isnt - The minimal model is pr(s),ph(e),aM(e)
14Minimal Models Semantics
- Truth ordering For interpretations I and J, I ?
J iff for all atom A, I(A) ? J(A), i.e. - TI ? TJ and FI ? FJ
15TP operator
- The minimal models of a definite P can be
computed (bottom-up) via operator TP
16On Minimal Models
- SLD can be used as a proof procedure for the
minimal models semantics - If the is a SLD-derivation for A, then A is true
- Otherwise, A is false
- The semantics does not apply to normal programs
- p ? not q has two minimal models
- p and q
- There is no least model !
17Stable Models definition
18Cumulativity
19Relevance
20Problems with SMs
- Dont provide a meaning to every program
- P a ? not a has no stable models
- Its non-cumulative and non-relevant
- The only SM is not a, c, b
a ? not b c ? not a b ? not a c ? not c
- However b is not true in P U c (non-cumulative)
- P U c has 2 SMs not a, b, c and a, not b,
c - b is not true in Relb(P) (non-relevance)
- The rules in Relb(P) are the 2 on the left
- Relb(P) has 2 SMs not a, b and a, not b
21Problems with SMs (cont)
- Its computation is NP-Complete
- The intersection of SMs is non-supported
a ? not b c ? a b ? not a c ? b
22Well Founded Semantics
- Defined in GRS90, generalizes SMs to 3-valued
models. - Note that
- there are programs with no fixpoints of ?
- but all have fixpoints of ?2
P a ? not a
- ?(a) and ?() a
- There are no stable models
23Partial Stable Models
P a ? not a, has a single PSM
This program has 3 PSMs , a, not b and c,
b, not a The 3rd corresponds to the single SM
a ? not b c ? not a b ? not a c ? not c
24WFS definition
25Well Founded Semantics
- Let M be the well founded model of P
- A is true in P iff A ? M
- A is false in P iff not A ? M
- Otherwise (i.e. A ? M and not A ? M) A is
undefined in P
26WFS Properties
- Every program is assigned a meaning
- Every PSM extends one SM
- If WFM is total it coincides with the single SM
- It is sound wrt to the SMs semantics
- If P has stable models and A is true (resp.
false) in the WFM, it is also true (resp. false)
in the intersection of SMs
27More WFS Properties
- The WFM is supported
- WFS is cumulative and relevant
- Its computation is polynomial (on the number of
instantiated rules of P) - There are top-down proof-procedures, and sound
implementations - these are mentioned in the sequel
28Extended LPs
- In Normal LPs all the negative information is
implicit. Though thats desired in some cases
(e.g. the database with flight connections),
sometimes an explicit form of negation is needed
for Knowledge Representation - Penguins dont fly could be noFly(X) ?
penguin(X) - This does not relate fly(X) and noFly(X) in
- fly(X) ? bird(X)
- noFly(X) ? penguin(X)
29Extended LP motivation
- is also needed in bodies
- Someone is guilty if is not innocent
- cannot be represented by guilty(X) ? not
innocent(X) - This would imply guilty in the absence of
information about innocent - Instead, guilty(X) ? innocent(X) only implies
guilty(X) if X is proven not to be innocent - The difference between not p and p is essential
whenever the information about p cannot be
assumed to be complete
30ELP motivation (cont)
- allows for greater expressivity
- If youre not sure that someone is not innocent,
then further investigation is needed - Can be represented by
- investigate(X) ? not innocent(X)
- extends the relation of LP to other NMR
formalisms. E.g - it can represent default rules with negative
conclusions and pre-requisites, and positive
justifications - it can represent normal default rules
31Explicit versus Classical
- Classical complies with the excluded middle
principle (i.e. F v F is tautological) - This makes sense in mathematics
- What about in common sense knowledge?
- A is the the opposite of A.
- The excluded middle leaves no room for
undefinedness
The excluded middle implies that every X is
either hired or rejected It leaves no room for
those about whom further information is need to
determine if they are qualified
hire(X) ? qualified(X) reject(X) ? qualified(X)
32ELP Language
- An Extended Logic Program P is a set of rules
- L0 ??L1, , Lm, not Lm1, not Bn (n,m ? 0)
- where the Li are objective literals
- An objective literal is an atoms A or its
explicit negation A - Literals not Lj are called default literals
- The Extended Herbrand base HP is the set of all
instantiated objective literals from program P - We will consider programs as possibly infinite
sets of instantiated rules.
33ELP Interpretations
- An interpretation I of P is a set
- I T U not F
- where T and F are disjoint subsets of HP and
- L ? T ? L ? F (Coherence Principle)
- i.e. if L is explicitly false, it must be
assumed false by default - I is total iff HP T U F
- I is consistent iff ? L L, L ? T
- In total consistent interpretations the Coherence
Principle is trivially satisfied
34The coherence principle
- Generalizing WFS in the same way yields
unintuitive results
pacifist(X) ? not hawk(X) hawk(X) ? not
pacifist(X) pacifist(a)
- Using the same method the WFS is pacifist(a)
- Though it is explicitly stated that a is
non-pacifist, not pacifist(a) is not assumed, and
so hawk(a) cannot be concluded. - Coherence is not satisfied...
- Coherence must be imposed
35Imposing Coherence
- Coherence is L ? T ? L ? F, for objective L
- According to the WFS definition, everything is
false that doesnt belong to ?(T) - To impose coherence, when applying ?(T) simply
delete all rules for the objective complement of
literals in T
If L is explicitly true then when computing
undefined literals forget all rules with head L
36WFSX definition
37WFSX example
Ps pacifist(X) ? not hawk(X), not
pacifist(X) hawk(X) ? not pacifist(X ), not
hawk(X) pacifist(a) ? not pacifist(a)
pacifist(b) ? not pacifist(b)
T0 ?s(T0) p(a),p(a),h(a),p(b),h(b) T1
p(a) ?s(T1) p(a),h(a),p(b),h(b) T2
p(a),h(a) T3 T2
P pacifist(X) ? not hawk(X) hawk(X) ? not
pacifist(X) pacifist(a) pacifist(b)
38Properties of WFSX
- Complies with the coherence principle
- Coincides with WFS in normal programs
- It is supported, cumulative, and relevant
- Its computation is polynomial
- It has sound implementations (cf. below)
39Inconsistent programs
- Some ELPs have no WFM. E.g. a ???a ?
- What to do in these cases?
- Explosive approach everything follows from
contradiction - taken by answer-sets
- gives no information in the presence of
contradiction - Belief revision approach remove contradiction by
revising P - computationally expensive
- Paraconsistent approach isolate contradiction
- efficient
- allows to reason about the non-contradictory part
40WFSXp definition
- The paraconsistent version of WFSX is obtained by
dropping the requirement that T and F are
disjoint, i.e. dropping T ? ?Ps(T)
41SLXProof procedure for WFSXp
- SLX (SL with eXplicit negation) is a top-down
procedure for WFSXp - Here we only present an AND-trees
characterization - The proof procedure details are in AP96
- Is similar to SLDNF
- Nodes are either successful or failed
- Resolution with program rules and resolution of
default literals by failure of their complements
are as in SLDNF - In SLX, failure doesnt mean falsity. It simply
means non-verity (i.e. false or undefined)
42Success and failure
- A finite tree is successful if its root is
successful, and failed if its root is failed - The status of a node is determined by
- A leaf labeled with an objective literal is
failed - A leaf with true is successful
- An intermediate node is successful if all its
children are successful, and failed otherwise
(i.e. at least one of its children is failed)
43Negation as Failure?
- As in SLS, to solve infinite positive recursion,
infinite trees are (by definition) failed - Can a NAF rule be used?
YES
- This is the basis of SLX. It defines
- T-Trees for proving truth
- TU-Trees for proving truth or undefinedness
44T and TU-trees
- They differ in that literals involved in
recursion through negation, and so undefined in
WFSXp, are failed in T-Trees and successful in
TU-Trees
a ? not b b ? not a
45Explicit negation in SLX
- -literals are treated as atoms
- To impose coherence, the semi-normal program is
used in TU-trees
?
?
a ? not b b ? not a a
?
?
?
46Explicit negation in SLX (2)
- In TU-trees L also fails if L succeeds true
- I.e. if not L fails as true-or-undefined
a
not a
?
?
?
c ? not c b ? not c b a ? b
?
?
?
?
?
?
?
47Paraconsistent example
b ? not a a a
48T and TU-trees definition
49Success and Failure
50Properties of SLX
- SLX is sound and (theoretically) complete wrt
WFSXp. - Even ignoring rules concerning explicit negation,
SLX is sound and (theoretically) complete wrt
WFS. - See AP96 for the definition of a refutation
procedure based on the AND-trees
characterization, and for all proofs and details
51Infinite trees example
?
?
?
52Negative recursion example
53Guaranteeing termination
- The method is not effective, because of loops
- To guarantee termination in ground programs
- Local ancestors of node n are literals in the
path from n to the root, exclusive of n - Global ancestors are assigned to trees
- the root tree has no global ancestors
- the global ancestors of T, a subsidiary tree of
leaf n of T, are the global ancestors of T plus
the local ancestors of n - global ancestors are divided into those occurring
in T-trees and those occurring in TU-trees
54Pruning rules
- For cyclic positive recursion
55Pruning rules (2)
56Other sound rules
57Pruning examples
a ? not b b ? not a a
?
?
b
a
c ? not c b ? not c b a ? b
not a
?
?
?
?
?
58Simple diagnosis example
inv(G,I,0) ? node(I,1), not ab(G). inv(G,I,1) ?
node(I,0), not ab(G). node(b,V) ?
inv(g1,a,V). node(a,1). node(b,0). Fault
model inv(G,I,0) ? node(I,0), ab(G). inv(G,I,1) ?
node(I,1), ab(G).
The only revision is P U ab(g1) ? u It does
not conclude node(b,1).
592-valued Revision
- In diagnosis one often wants the IC
- ab(X) v not ab(X) ?
- With these ICs (that are not denials), 3-valued
revision is not enough. - A two valued revision is obtained by adding facts
for revisables, in order to remove contradiction. - For 2-valued revision the algorithm no longer
works
60Example
? ? p. ? ? a. ? ? b, not c. p ? not a, not b.
The only support is not a, not b. Removals are
not a and not b.
- In 2-valued revision
- some removals must be deleted
- the process must be iterated.
61Algorithm for 2-valued revision
- Let Revs
- For every element R of Revs
- Add it to the program and compute removal sets.
- Remove R from Revs
- For each removal set RS
- Add R U not RS to Revs
- Remove non-minimal sets from Revs
- Repeat 2 and 3 until reaching a fixed point of
Revs. - The revisions are the elements of the final Revs.
62Example of 2-valued revision
? ? p. ? ? a. ? ? b, not c. p ? not a, not b.
Rev0
Rev1 a, b
Rev2 b
Rev3 b,c
Rev4
- Choose . Removal sets of P U are not a
and not b. Add them to Rev.
- Choose a. P U a has no removal sets.
- Choose b. The removal set of P U b is not
c. Add b, c to Rev.
- Choose b,c. The removal set of P U b,c is
. Add b, c to Rev.
- The fixed point had been reached. P U b,c is
the only revision.
63REVISE
- The algorithm with various optimizations had been
implemented - REVISE system. - Revise also has
- The possibility of defining a partial ordering of
preferences among revisables. - Associate probabilities to revisables.
- Also computes revisions with minimal cardinality.
- Optimizations include
- Pruning of the search space.
- Making use of preferences and probabilities.
64Revision and Diagnosis
- In model based diagnosis one has
- a program P with the model of a system (the
correct and, possibly, incorrect behaviors) - a set of observations O inconsistent with P (or
not explained by P). - The diagnoses of the system are the revisions of
P U O. - Weve shown how to perform mixed consistency and
abduction based diagnosis.
65Diagnosis Example
66Diagnosis Program
Observables obs(out(inpt0, c1),
0). obs(out(inpt0, c2), 0). obs(out(inpt0, c3),
0). obs(out(inpt0, c6), 0). obs(out(inpt0, c7),
0). obs(out(nand, g22), 0). obs(out(nand, g23),
1).
Connections conn(in(nand, g10, 1), out(inpt0,
c1)). conn(in(nand, g10, 2), out(inpt0,
c3)). conn(in(nand, g23, 1), out(nand,
g16)). conn(in(nand, g23, 2), out(nand, g19)).
Predicted and observed values cannot be
different ?? obs(out(G, N), V1), val(out(G, N),
V2), V1 ? V2.
Value propagation val( in(T,N,Nr), V ) ? conn(
in(T,N,Nr), out(T2,N2) ), val( out(T2,N2), V
). val( out(inpt0, N), V ) ? obs( out(inpt0, N),
V ).
Normal behavior val( out(nand,N), V ) ? not
ab(N), val( in(nand,N,1), W1), val( in(nand,N,2),
W2), nand_table(W1,W2,V).
Abnormal behavior val( out(nand,N), V ) ?
ab(N), val( in(nand,N,1), W1), val( in(nand,N,2),
W2), and_table(W1,W2,V).
67Diagnosis Example
, and ab(g16),ab(g22)
Revision are
ab(g23)
, ab(g19)
68Abduction as Revision
- For abductive queries
- Declare as revisable all the abducibles
- If the abductive query is Q, add the IC
- ? ? not Q
- The revision of the program are the abductive
solutions of Q.
69Bibliography (1)
- Most of the work covered by this course is
detailed in - AP96 J.J. Alferes and L.M. Pereira. Reasoning
with Logic Programming. Springer LNAI 1111, 1996 - See references there for the original definitions
- For more on semantics of normal LPs see
- PP90 H. Przymusinska and T. Przymusinski.
Semantic issues in deductive databases and logic
programs. In R. Banerji ed, Formal Techniques in
AI, a Sourcebook. North Holland, 1990 - For more on derivation procedures
- AB94 K. Apt and R. Bol. Logic Programming and
Negation A survey. In Journal of L.P., 1994
70Bibliography (2)
- For more on LP for KRR
- BG94 C. Baral and M. Gelfond. Logic Programming
and Knowledge Representation. In Journal of L.P.,
1994 - For relation with NMR e structural properties
- BDK97 G. Brewka, J. Dix and K. Konolige.
Nonmonotonic Reasoning an overview. CSLI
Publications, 1997 - More on our LP belief revision approach in
- ADP95 J. J. Alferes and C. V. Damásio and L. M.
Pereira, A Logic Programming System for
Non-monotonic Reasoning, Journal of Automated
Reasoning (14), 1995
71Bibliography (3)
- For more on LP update
- MT96 V. Marek and M. Truszczynski. Revision
specifications by means of programs. In JELIA94,
Springer LNAI 838, 1994 - ALPPP98 J.J. Alferes, J. Leite, L.M. Pereira,
H. Przymusinska and T. Przymusinski. Dynamic
Logic Programming. In KR98, Morgan Kaufmann,
1998 - Another good entry point for these questions is
- DPP97 J. Dix, L.M. Pereira, T. Przymusinski.
Prolegomena to Logic Programming and
Non-Monotonic Reasoning. In Non-Monotonic
Extensions of Logic Programming. Springer LNAI
1216, 1997