Procedural Control of Reasoning - PowerPoint PPT Presentation

1 / 36
About This Presentation
Title:

Procedural Control of Reasoning

Description:

This is because each application of the rule calls Fibo twice. Most of this effort is redundant. ... Fibo(n,v) F(n,1,0,v) F(0,y,z,y) F(s(n),y,z,v) Plus(y,z,s) F ... – PowerPoint PPT presentation

Number of Views:90
Avg rating:3.0/5.0
Slides: 37
Provided by: sergeini
Category:

less

Transcript and Presenter's Notes

Title: Procedural Control of Reasoning


1
Procedural Control of Reasoning
Sometimes it is not computationally feasible to
try all logically possible ways of using the KB.
When we have additional knowledge about the
structure of a problem, we want to communicate to
the theorem-proving procedure hints about how to
conduct the reasoning process.
2
If ? is the symbol for one-way implication
(meaning that the consequent does not necessarily
also imply the antecedent), then Battleship(x) ?
Gray(x) would allow the system to conclude that
if something is a battleship it is gray but would
prevent it from trying to prove that if
something is gray then it is a battleship.
3
We can separate clauses in the KB into a set of
facts and a set of rules. The facts cover the
basic truths in the domain and are usually
ground atoms. The rules are used to allow
expressing new facts in terms of basic
facts. They are usually universally quantified
conditionals. Both facts and rules can be
manipulated by the unification matching algorithms
that we have learned.
4
Mother(jane, billy) Parent(x,y) ?
Mother(x,y) Father(john, billy) Parent(x,y) ?
Father(x,y) Father(sam, john) Child(x,y) ?
Parent(y,x) The answer to the question whether
John is the father of Billy is found by matching
the base fact directly. The question if John is
a parent of Billy is answered through
backward chaining and asking whether John is
Billys mother or Billys father. For the
question Is Billy a child of John we would have
to check whether John is a parent of Billy and
then do the father/mother checks. What is the
most effective use of rules in a knowledge base?
5
  • Rule Formation and Search Strategy
  • Lets define Ancestor in terms of Parent. There
    are at least three ways
  • Ancestor(x,y) ? Parent(x,y)Ancestor(x,y) ?
    Parent(x,z) ? Ancestor(z,y)
  • Ancestor(x,y) ? Parent(x,y)Ancestor(x,y) ?
    Parent(z,y) ? Ancestor(x,z)
  • Ancestor(x,y) ? Parent(x,y)Ancestor(x,y) ?
    Ancestor(x,z) ? Ancestor(z,y)

6
  • Ancestor(x,y) ? Parent(x,y)Ancestor(x,y) ?
    Parent(x,z) ? Ancestor(z,y)
  • Ancestor(x,y) ? Parent(x,y)Ancestor(x,y) ?
    Parent(z,y) ? Ancestor(x,z)
  • Ancestor(x,y) ? Parent(x,y)Ancestor(x,y) ?
    Ancestor(x,z) ? Ancestor(z,y)

In the first case, if Sam is the father of Bill
and Bill is a great-grandfather (an ancestor) of
Sue then Sam is an ancestor of Sue. In the
second case, if Sam is the great-grandfather of
Fred who is a parent of Sue and therefore Sam is
an ancestor of Sue. In the third case, we
observe that if Sam is a great-grandfather of
George who in turn is a grandfather of Sue, then
again Sam is an ancestor of Sue. All three
formulations yield the same result. In
reasoning, in any of the three cases we would use
backward chaining from the initial Ancestor
goal, reduce it to a set of the Parent
goals. However, the amount of computation will
be different in each of the cases.
7
  • Ancestor(x,y) ? Parent(x,y)Ancestor(x,y) ?
    Parent(x,z) ? Ancestor(z,y)
  • Ancestor(x,y) ? Parent(x,y)Ancestor(x,y) ?
    Parent(z,y) ? Ancestor(x,z)
  • Ancestor(x,y) ? Parent(x,y)Ancestor(x,y) ?
    Ancestor(x,z) ? Ancestor(z,y)

The first version suggests that we start from Sam
(the putative ancestor) and look downward in
the family tree looking for a descendant of
Sam who might be a parent of Sue. The second
version suggest that we start with the putative
descendant and go up in the family tree toward
the ancestor, looking for the parent of the
descendant (Sue). The third option suggests
looking in both directions at the same time.
8
Suppose that people have just one child. Using
Method 1, we start from Sam (the ancestor) and
search the tree downward and make d comparisons,
where d is the depth of the search. If we fan
out from Sue (the descendant) and search upward,
then we traverse 2d nodes. So, in big trees
the first option becomes increasingly more
attractive. But think of families with many
children
9
Consider the Fibonacci sequence
1,1,2,3,5,8,13,21,34,55, Here are two facts
and a rule that characterize it Fibo(0,1) Fibo(1
,1) Fibo(succ(succ(n), v) ? Fibo(n,y) ?
Fibo(s(n), z) ? Plus(y,z,v) Plus(y,z,v) means v
y z. If we unleash the unguided
backward-chaining theorem prover on the above
direct formulation (that is, ask the query, What
is the nth member of the Fibonacci sequencegt) it
will lead to a disaster Why?
10
Because it generates an exponential number of
Plus subgoals. This is because each application
of the rule calls Fibo twice. Most of this
effort is redundant. Indeed, say, for Fibo(12,
-) we invoke Fibo(11, -) and Fibo(10, -). But we
will have to invoke Fibo(10, -) again when
computing Fibo(11, -).
11
An alternative (but still recursive) way of
representing the Fibonacci sequence uses a
four-place intermediate predicate, F Fibo(n,v)
? F(n,1,0,v) F(0,y,z,y) F(s(n),y,z,v) ?
Plus(y,z,s) ? F(n,s,y,v) Here, F(n,s,y,v) will
count down from n using y to keep track of the
current Fibonacci number and z to keep track of
the one before it. Each time we reduce n by 1,
we get a new current number (the sum of
the current and the previous Fibonacci numbers)
and we also get a new previous number (which was
the current one). At the end, when n is 0, the
final result v is the current Fibonacci number
y. This formulation requires only a linear
number of Plus subgoals. This work is similar to
algorithm design in software engineering.
12
Goal Order AmericanCousin(x,y) ? American(x) ?
Cousin(x,y). Suppose the query is
AmericanCousin(fred,sally). Then we can solve the
subgoals - American(fred) and Cousin(fred,sally)
- in any order. However, if we are asking
whether Sally has an American cousin AmericanCous
in(x,sally), then we have a choice of first
finding an American and then checking that he or
she is Sallys cousin or first find a cousin of
Sally and then check whether he or she is an
American. Which of these generate and test
methods is better? In Prolog, a language that
stems from theorem proving but is a
general- purpose language, the order of goals
(and generally clauses and literals in
expression) is strict. And this allows the
programmer to formulate the most efficient
algorithm.
13
In Prolog, the above problem is formulated as
follows americanCousin(X,Y) - cousin(X,Y),
american(X,Y). We need to consider goal
backtracking because subgoals have to be tried
for different values of the variables. We may
have to generate many cousin candidates before we
find one who is American. In a clause of the
form G - T, S the goal T is often needed only
as a test for the applicability of goal S and
not as a generator of possibilities for subgoal
S to test further. In other words, if T succeeds,
then we want to commit to S as the
appropriate way of achieving G. Then, if S
fails, we would consider G to fail too. This
means that we are committed to not looking for
other ways of solving T or other clauses with G
as their head.
14
This type of control is carried out in Prolog
using the cut symbol, ! So, there may be a
Prolog clause G - T1, T2,, Tm, !, G1,
G2,,Gn. which would tell the interpreter to try
each of the goals in this order but if all of the
Ti succeed, to commit to the sequence Gi as the
only way of solving G.
15
The cut is a relative of the if-then-else
construct in traditional programming languages. S
uppose the predicate Expt(a,n,v) means that v
an. A simple algorithm for calculating an (or
reasoning about Expt goals) involves n - 1
multiplications. There is a recursive algorithm
that requires log2(n) multiplications. If n is
even, we continue recursively replacing a and n
with a2 and n/2 respectively. If n is odd, we
continue replacing a and n with a2 and (n-1)/2
respectively and multiplying the result by a if
n is even then even-procedure else
odd-procedure
16
In logical terms, Expt(a,0,1) Expt(a,n,v) ? n gt
0 ? Even(n) ? Expt(a2, n/2,v) Expt(a,n,v) ? n gt 0
? ?Even(n) ? Expt(a2, (n-1)/2,v) ? v av
What we want to be able to do is to test whether
n is even only once! We should solve the goal
Even(n) once, and if it succeeds do one thing and
if it does not, do another. The goal ?Even(n)
should not be even considered. Similarly, if n0,
we should not touch the second and third clauses
in the above problem formulation. The cut
operator handles this.
17
expt(A,0,V) - !, V1. expt(A,N,V) - even(N), !,
lteven-proceduregt. expt(A,N,V) -
ltodd-proceduregt. We commit to the first clause
unconditionally but that clause succeeds
only when V1. expt(A,N,V) - N0, !, V1. is
equivalent to the first clause above, expt(A,0,1)
- !. would be incorrect. In general, G - P,
!, R. G - S. is logically equivalent to If P
holds then R implies G, and if ?P holds, then S
implie G. However, this procedure checks P only
once.
18
NumberOf Parents(adam, V) - !, V 0. NumberOf
Parents(eve, V) - !, V 0. NumberOf
Parents(P,2). In this example, due to the order
of clauses, we do not need to ascertain that the
person in the third clause is not Adam or Eve.
19
Backtracking. The cut operator also controls
backtracking on failure of search. Suppose, we
are trying to prove that Jane is an American
cousin of Billy. Two individuals can be
considered to be first cousins if they share
a grandparent but are not siblings Cousin(x,y)
? (x ? y) ? ?Sibling(x,y) ? Gparent(z,x) ?
Gparent(z,y). Suppose, we have found that Henry
is a grandfather of both Jane and Billy but that
Jane is not an American. What do we do now? If
it turns out that Billy and Jane have another
common grandparent, this second z will be found
on backtracking and we will have to test whether
Jane is an American another time. And we will
fail for the second time.
20
The example shows that on failure we need to
avoid trying to redo a goal that was not part of
the reason we are failing. It was not the choice
of grandparent that caused the trouble here, so
there is no point in reconsidering it. But
Prolog would do precisely this. So, we would need
to represent our goal as cousin(jane,billy), !,
american(jane) In other words, once we have
found a way to show that Jane is a cousin of
Billy (whatever the method), we should commit to
whatever result comes out of checking that she is
American.
21
Another example membership in a
list Member(x,l) ? FirstElement(x,l) Member(x,l)
? RemainingElements(l,l) ? Member(x,l) Now
lets try to establish that some object a is an
element of some list c and has a property Q
Member(a,c) ? Q(a). If the Member(a,c) subgoal
succeeds but Q(a) fails, it would be wasteful
to reconsider Member(a,c) to see whether a also
occurs later in the list. In Prolog, this is
controlled by member(a,C), !, q(a).
22
If we know that the Member predicate will only be
used to test for membership in a list (and not
to generate new elements for the list), we can
use a Prolog definition as follows member(X,L)
- firstElement(X,L), !. member(X,L) -
remainingElements(L,L1), member(X,L1). This
guarantees that once a membership goal succeeds
(in the first clause) by finding a sublist whose
first element is the item in question, the second
clause will never be reconsidered on failure of a
later goal. So, if we wanted to check that
George is both a friend and rich, we would write
member(george,Friends), rich(george) and not
worry about including a cut. The definition of
Member assures us that once an element is found
in the list, if a subsequent test, like
rich, fails, we will not go back to see if that
element occurs somewhere later in the list and
try the failed test again.
23
  • Negation as Failure
  • There is a distinction between two types of
    failure to solve a goal G
  • being able to solve the goal ?G and
  • being unable to solve the goal G.
  • In the latter case, we may not be able to find a
    fact or rule asserting that
  • G is false, but we may have run out of ideas
    about how to solve G. The
  • reasoner must be told what to do if it fails to
    solve a goal.

24
We introduce a new type of goal, not(G) that
succeeds when G fails and fails when G succeeds
(independently of the status of ?G). This is the
behavior of the Prolog not operator not(G) -
G, !, fail fail if G succeeds not(G)
otherwise, succeed. This type of negation as
failure is only useful when failure is finite.
If attempts to prove G result in an infinite
branch of the search tree or infinite set of
resolvents to process in resolution, we cannot
expect the goal of not(G) to terminate. But if
there are no more resolvents to try in a proof,
not(G) will succeed.
25
Negation as failure is especially useful in
closed world KBs, where the facts and the rules
express complete knowledge about some
predicate. If, for example, we have an entire
family represented in a KB, we could define in
Prolog noChildren(X) - not(parent(X,Y)). The
system will conclude that someone has no children
if it cannot find any in the KB. With incomplete
knowledge, we could fail to find children simply
because they are not in the KB.
26
Negation as failure is also useful when we have a
complete method of computing the complement of a
predicate. For example, if we have a rule for
determining that a number is prime, we would not
need to constructanother rule that shows that a
numebr is not prime. Instead composinte(N) - N
gt 1, not(primeNumber(N)). In this case, failure
to prove that a number greater than 1 is prime
is sufficient to conclude that the number is
composite.
27
not differs from conventional negation when new
variables appear in the goal. For example, the
Prolog clause for Composite can be read as for
every number n, if n gt 1 and n is not a prime
number, then n is composite. However, the
clause for NoChildren does not read as for
every x and y, if x is not a parent of y, then x
has no children. Instead, it should read for
every x, if for every y, x is not a parent of y,
then x has no children. The quantifier for the
new variable y in the goal has moved inside
the scope of if.
28
  • Dynamic databases
  • Realistic KBs undergo change over time --
    insertions and deletions, as
  • old facts may not be any longer true and new
    facts appear. Now, a rule like
  • Parent(x,y) ? Mother(x,y), there can be different
    procedural interpretations
  • if-needed Whenever there is a goal Parent(x,) we
    can solve it bysolving Mother(x,y). This is
    ordinary backward chaining. Procedurally,we do
    not make a connection between parents and mothers
    beforewe need to prove something involving
    parents.
  • if-added, whenever a fact of the type Mother(x,y)
    is added to the KB,we also add Parent(x,y) to
    the KB. This is forward chaining. A proofof a
    parent relation will become more immediate at the
    cost of thespace used for storing new facts that
    may never be used.
  • if-removed Whenever something matching
    Parent(x,y) is removedfrom the KB, we should
    also remove Mother(x,y). It is also
    forwardchaining, but with a twist. If the only
    reason we have a parent relationin the KB is
    because of the mother relation, then if we remove
    thatmother relation, we should remove the parent
    as well. That is, weshould consider removing
    descendants and single parents.

29
The if-needed control underlies Prolog. The
other two control options suggest the use of
demons, procedures that actively monitor the KB
and trigger (fire) when certain conditions
aremet. There can be more than one such demon
matching a change in the KB, and the results of
the operation of a demon may cause
further changes in the KB, causing more demons to
fire. This is called spreading activation. This
type of processing underlies the operation of
production systems.
30
  • Planner
  • To give the user more control over the reasoning
    process has led to
  • the development of programming languages attuned
    to these needs.
  • Planner was designed (Hewitt, Sussman, Winograd)
    specifically to give
  • the user fine-grained control of theorem proving.
  • The main ideas of Planner are as follows
  • the knowledge base of a planner application is a
    database of factsexpressed in a notation like
    (Mother susan john) and (Person john)(this is
    the Cambridge-Polish notation underlying Lisp)
  • the rules of the system are formulated as a
    collection of if-needed,if-added and if-removed
    procedures, each consisting of a patternfor
    invocation (e.g., (Mother x y)) and a body, which
    is a programstatement to execute once the
    invocation pattern is matched

31
  • each program statement can succeed or fail
  • - (goal p), (assert p) and (erase p) specify
    that a goal should be established (proven or
    made true), that a new fact should be added to
    the KB and that an old fact should be removed
  • - (and s1 sn), where the si are program
    statements, succeeds if all si succeed,
    allowing for backtracking among them
  • - (not s) is negation as failure
  • - (for p s) says to perform program
    segment s for every way goal p succeeds
  • - (finalize s) is similar to the Prolog
    cut operator
  • - all of Lisp.

32
Here is a simple Planner program (proc
if-needed(clearTable) (for (on x table) (and
(erase (on x table))(goal (putaway x))))) (proc
if-removed(on x y) (print x is no longer on
y)) The first procedure is invoked whenever the
goal clearTable needs to be satisfied, that is,
when, in the blocks world of this example,
the table should be clear of objects. To solve
this problem, for each item found on the table we
remove the statement in the database that
reflects its being on the table and solve the
goal of putting that item away somewhere. The
second procedure alerts the user to a change in
the KB by printing a statement for each object
removed.
33
The Planner type of program suggests a shift in
perspective on knowledge representation and
reasoning. Instead of thinking of solving a goal
as proving that a condition is logically entailed
by a collection of facts and rules, we think of
it as making conditions hold, using some
combination of forward and backward
chaining. This is the first hint at how to
support the execution of plans. We also shift
away from rules with a clear logical
interpretation (as universally quantified
conditionals) toward arbitrary procedures over a
knowledge base of facts. These operations can
correspond to deductive reasoning but they need
not! This dynamic use of rules persists in the
area of production systems.
34
(No Transcript)
35
(No Transcript)
36
(No Transcript)
Write a Comment
User Comments (0)
About PowerShow.com