controlling reasoning
DESCRIPTION
Controlling Reasoning. Logical view on rules: CNF Inference: TD, BU, Resolution Control in PLANNER, MBASE, PRESS Conclusions Notations in slides for logical connectors: &, |, ¬, , A, E. Rules as logical implications. A person admires a philosopher if he beats him in a race - PowerPoint PPT PresentationTRANSCRIPT
Controlling Reasoning
1. Logical view on rules: CNF2. Inference: TD, BU, Resolution3. Control in PLANNER, MBASE, PRESS4. Conclusions
Notations in slides for logical connectors: &, |, ¬, , A, E.
Expert Systemen 5 2
Rules as logical implications
• A person admires a philosopher if he beats him in a race• Rule: IF x is Philosopher
AND x beats y in raceTHEN y admires x
• Logic: A x,y: Ph(x) & Be(x,y) Ad(y,x)
• PROLOG: Ad(y,x) :- Ph(x), Be(x,y).• CLIPS: (defrule (Ph x) (Be x y) => (assert (Ad y x)))
CLIPS and PROLOG: Program is list of implications.
Each is valid individually: conjunction of implications.
Implication is disjunction: p q is the same as ¬p | q
Expert Systemen 5 3
Conjunctive Normal Form
• Atom: Relation symbol Be(x,y)• Literal: Atom or negated atom Be(x,y) ¬Be(x,y)• Clause: Disjunction of Literals ¬Be(x,y) | ¬Ph(x) |
Ad(y,x)
• Conjunctive Normal Form: Conjunction of clauses.CNF is Universal: Every statement is equivalent to a CNF.
• Special case: Horn clause has ONE positive literal.Our programs have Horn clauses but…
• Horn clauses are NOT universal!Influences expressibility and efficiency of programs.
Expert Systemen 5 4
CNF is Universal
Statement: Every student uses some computer and some computer is used by every student.
Formalize in logic:(A x: St(x) (E y: Co(y) & Use(x,y)) ) &(E z: Co(z) & (A t: St(t) Use(t,z)) )
Eliminate implications:(A x: ¬St(x) | (E y: Co(y) & Use(x,y)) ) &(E z: Co(z) & (A t: ¬St(t) | Use(t,z)) )
Replace existentials by Skolem functions:(A x: ¬St(x) | (Co(Y(x)) & Use(x,Y(x))) ) &(Co(Z) & (A t: ¬St(t) | Use(t,Z)) )
Expert Systemen 5 5
Transformation to CNF, continued
Replace existentials by Skolem functions:(A x: ¬St(x) | (Co(Y(x)) & Use(x,Y(x))) ) &(Co(Z) & (A t: ¬St(t) | Use(t,Z)) )
Move universal quantifiers up front:A x, A t: ¬St(x) | (Co(Y(x)) & Use(x,Y(x))) & (Co(Z) & (¬St(t) | Use(t,Z)) )
Distribute | over & and drop quantifiers:(¬St(x) | Co(Y(x)) & // St(x) Co(Y(x))(¬St(x) | Use(x,Y(x))) & // St(x) Use(x,Y(x))Co(Z) & // Co(Z)(¬St(t) | Use(t,Z)) // St(t) Use(t,Z)
Expert Systemen 5 6
Clause notation and meaning
• { } means False• {p} means p• {¬p} means ¬p• {¬p, q} means p q• {¬p, ¬q, r} means p & q r• {p} {q} means p & q
• {¬p, q, r} means p (q | r) or (p & ¬q) r
This is a non-Horn clause!
Expert Systemen 5 7
I have a problem with my TV . . .
Experts tell me that• IF powerfailure
THEN blackscreen• IF unitfailure
THEN blackscreenDeclarative (causal)
domain knowledge
I want to express this knowledge as• IF blackscreen
THEN powerfailure OR unitfailureProcedural domain knowledge
1. Why do I want that?2. Is the conclusion justified?3. How can I do it?
(assert (fact1 | fact2)) ??
• IF blackscreen & ¬unitfailureTHEN powerfailure
1. Symmetry between failures lost2. Mixes symptom with cause3. Negated conditions are costly
Expert Systemen 5 8
Conjunctions and Disjunctions in Implications
• p | q rConditions p and q each imply r by themselves:(p r) & (q r)Horn clause: {¬p,r} {¬q,r}
• p & q rHorn clause: {¬p,¬q,r}
• p q & rCondition p implies both q and r separately:(p q) & (p r)Horn clause: {¬p,q} {¬p,r}
Disjunction in the conclusion is the only problematic case
Expert Systemen 5 9
Inference: Bottom-Up
• Facts in the database express positive literals
• MP and MMP express how to extend the fact set.
• Modus Ponens:
p p s
s
• Multi Modus Ponens:
p q r p&q&r s
s
Initial Facts
Goal
Bottom-Up inference produces many irrelevant facts.
Expert Systemen 5 10
Inference: Top-Down
• Focus on goal avoids irrelevant facts
• Goal expansion:
Goal s p s
Goal p
• Goal expansion:
Goal s p & q & r s
Goals p, q, r
• Achieve empty goal list
Initial Facts
Goal
Top-Down inference persues many unreachable goals.
Expert Systemen 5 11
Resolution generalizes BU and TD inference
• Proving G is deriving a contradiction from ¬G.
• Goal list: negated statements
Goal expansion:
Goal s p s
Goal p
becomes ¬s p s
¬p
or: Modus Tollens
Achieve contradiction:prove False.
Initial Facts ¬G
False
Resolution may still derive too many facts.
Expert Systemen 5 12
The Resolution Principle
Horn clauses generalizefacts and rules
Resolution generalizes Modus Ponens and Modus Tollens:
From { p, s1, s2, …}and {¬p, t1, t2, …},conclude {s1, s2, …, t1, t2, …}Clauses clash on literal p
Justification:In both clauses a literal is TRUE.The p literal is TRUE in one.In at least one clause, another
literal is TRUE
Examples of Resolution:• Modus Ponens:
{¬p, q} {p} give {q}• Modus Tollens:
{¬p, q} {¬q} give {¬p}• Multi Modus Ponens:
{¬p, ¬q, ¬r, s} {p} {q} {r}give in three steps
• {¬q, ¬r, s}
• {¬r, s}
• {s}
• Contradiction:{¬p} {p} give {}
Expert Systemen 5 13
More proof rules subsumed by Resolution
Chaining:• p q and q r
imply p r
• If p is known, r is derived with 2x Modus Ponens
• Natural deduction:assume and then eliminate p
• Resolution:{¬p, q} and {¬q, r}clash on q and give{¬p, r}
Case distinction:• p q and ¬p q
imply q
• Resolution:{¬p, q} and {p, q}clash on p and give{q}
Expert Systemen 5 14
Resolution Conflict strategy
• Backward (Set-of-support):Use ¬G (or clause derived from it) in every step.
• Forward reasoning:Ignore ¬G until you can resolve it with G.
• Input Resolution:In each step use an IF or ¬G
• Unit preference:Prefer clauses with one literal
• Recency, Specificity, …
Initial Facts ¬G
False
TD-side
BU-side
Can we model and use Human Problem Solving
Knowledge here?
Expert Systemen 5 15
PLANNER (Hewitt, 1971)
Distinguish antecedent andconsequent theorems• A block is on the table
(ante (block x) (assert (on x table)))is triggered by antecedent(Bottom-Up theorem)
• Men are mortal(conse (mortal x) (goal (man x)))is triggered by consequent(Top-Down theorem)
Pros:• Employs some HE insights• Some efficiency gain
Cons:• Sacrifice completeness:
All true statements can be derived.Counterexample: (ante p (assert q)) (ante t (assert G)) (conse t (goal q)) p ¬G // Goal: G
• Efficiency gain is small
Expert Systemen 5 16
MECHO System Architecture
MECHO: Solver for highschool mechanics problemsImplemented in PROLOG, but with extended inference
control: MBASE
languageinterpreter
MECHO:physics
PRESS:mathematics
MBASE
PROLOG
Expert Systemen 5 17
MBASE: A Prolog extension
PROLOG inference control:rule ordering, clause ordering, !
First order conflict resolution:try rules in order in program.Put grandpa (abraham, jacob).before grandpa (x, y) :- fath(x, z), fath(z, y).
Second order conflict resolution:try clauses in listed order:Better write grandpa (x, y) :- fath(z, y), fath(x, z).
In both cases the two programs are logically equivalent.
Expert Systemen 5 18
The Use of ! (cut)
If x is found to be a woman, he cannot be anybodies grandpa: grandpa(x, y) :- female(x), fail.
Not enough; PROLOG will still try alternative clauses: grandpa(x, y) :- female(x), !, fail.
To prevent the penguin from flying: flies(X) :- penguin(X), !, fail. flies(X) :- bird(X).
Makes the program logically inconsistent.
This clause is not successful
Don’t try anything else
Expert Systemen 5 19
MBASE additional control: DBC
Knowledge that brothers share grandpa may find grandpa more efficiently: grandpa(x, y) :- brother (y, z), grandpa (x, z).
Want to use known facts only: grandpa(x, y) :- brother (y, z), DBC (grandpa (x, z) ).
DBC: Use fact if in database, but do not derive.
Knowledge that anybody has just one grandpa may stop superfluous search for another: grandpa(x, y) :- DBC (grandpa (z, y) ), different(z, x), !, fail.
Expert Systemen 5 20
MECHO additional control: Frames
• Hierarchical grouping of concepts:• a1 isa centrifugal
• centrifugal isa acceleration
• acceleration isa quantity
• Knowledge is associated to concepts.
Frame concept is NOT supported by MECHO/PROLOG,but implemented within MECHO
Expert Systemen 5 21
How PRESS solves an equation
Human problem solving strategy• Equation deduced from text (by MECHO):
log(x+1) = c – log(x - 1)• Rewrite to bring x on one side:
log(x+1) + log(x-1) = c• Rewrite to collect (reduce no. of occurrences of x):
log(x2 – 1) = c• Rewrite to isolate the value x:
x = √(ec +1)
Insufficient: algebraic rewriting rules, domain knowledge. (x+1)(x-1) = x2 - 1
We must supply them together with an application context.
Expert Systemen 5 22
PRESS solution strategies:
/* Isolate a single occurrence of x */solution( Lhs=Rhs, SolvedEquation ) :- occur( x, Lhs, 1 ), occur( x, Rhs, 0 ), isolate( Lhs=Rhs, SolvedEquation ), !.
/* Try to combine two occurrences */solution( Equation, SolvedEquation ) :- occur( x, Equation, N ), N > 1, collect( Equation, Equation1 ), solution( Equation1, SolvedEquation ), !.
/* Try two move two occurrences closer together */solution( Equation, SolvedEquation ) :- occur( x, Equation, N ), N > 1, attract( Equation, Equation1 ), solution( Equation1, SolvedEquation ), !.
Expert Systemen 5 23
Guide attraction by occurrences of x
/* Attraction can be done in subexpressions */attract( Equation, Equation1 ) :- subexpr( E, Equation ), attract_rewrite( E, E1 ), replace_sub( E, Equation, E1, Equation1 ).
/* Combine sum of logs, both containing x */attract_rewrite( log(U)+log(V), log(U*V) ) :- occur( x, U, NU ), NU > 0, occur( x, V, NV ), NV > 0.
Expert Systemen 5 24
Collection is the ultimate attraction:
/* Allow collection on subexpressions */collect( Equation, Equation1 ) :- sub_expr( E, Equation ), collect_rewrite( E, E1 ), replace_sub( E, Equation, E1, Equation1 ).
/* Formula’s that vanish one x */collect_rewrite( (x+N)*(x-N), (x^2-Nsq) ) :- Nsq is N^2.
collect_rewrite( A*x + B*x , C * x ) :- C is A + B.
Familiar product rule, but now has a direction and a goal
context
Expert Systemen 5 25
Isolation: Peel the Onion to the kernel
/* isolate brings an equation of the form LHS=RHS, with a single x in LHS, in the form x=Rhs */
/* What does that kernel look like */isolate( x=Rhs, x=Rhs ) :- !.
/* Otherwise, apply recursion */isolate( Equation, SolvedEquation ) :- isolate_rewrite( Equation, Equation1 ), isolate( Equation1, SolvedEquation ).
/* A is the subexpr of LHS that contains x */isolate_rewrite( sin(A)=B, A=arcsin(B) ).isolate_rewrite( log(A)=B, A=exp(B) ).isolate_rewrite( A^N=B, A=B^(1/N) ).
Expert Systemen 5 26
Conclusion about Mbase/Press
• MECHO was successful because it workedwhich is what we want
• Rules are not just laws of algebra,but solution strategies of Human Expertwhich is what we want
• Solution strategies are coded together with algebra,which is not what we want
• Many are represented implicitly (eg., by clause order)which is not what we want
MECHO was influential as1. a demonstration of what was possible in AI / PROLOG2. a guide for later research in strategic knowledge
representation
Expert Systemen 5 27
I still have a problem with my TV . . .
Experts tell me that• IF powerfailure
THEN blackscreen• IF unitfailure
THEN blackscreen
I want to express this knowledge as• IF blackscreen
THEN powerfailure OR unitfailure
1. Why do I want that?2. Is the conclusion justified?
Both TD and BU inference only draw logically valid conclusions
Closed World Assumption:If a statement is true, it can be proved
CWA in PROLOG: as long as blackscreen cannot be derived, your TV is fine.
CWA: The expert knowledge is complete wrt. possible causes