Sunteți pe pagina 1din 4

2marks

BACKWARD CHAINING:

Suppose that we have formulas:[Backward chaining only works for Horn clauses, which have at
most one positive literal.]
A
B
D
A∧B→C
C∧D→E

A conclusion E can be proved recursively:

1. First check whether the desired conclusion is in the database of facts. If so, return True.
2. Otherwise, for each rule that has the desired conclusion (right-hand side), call the
algorithm recursively for each item in the premise (left-hand side). If all of the premises
are true, return True.
3. Otherwise, return False.

In this example, we would know that E is true if we knew that C and D were true; we would
know that C is true if we knew A and B ; A and B are in the database, so C must be true; and D is
in the database, so E is true.

With careful implementation, backchaining can run in linear time.

Forward Chaining

Suppose that we have formulas such as the following:


A
B
D
A∧B→C
C∧D→E

From A and B , it is possible to derive C and save it as a new fact; then from C and D , E can be
derived.

The forward chaining algorithm is as follows:

When a new fact is presented to the database manager,

1. Add the new fact to the database.


2. For each rule that has the new fact as part of its premise, if the rest of the premise is true,
add the conclusion to the database.

This cycle is repeated until activity stops or until the desired fact is added to the database.

With careful implementation, forward chaining can run in linear tim

Unification Algorithm

The basic unification algorithm is simple. However, it must be implemented with care to ensure
that the results are correct.

We begin by making sure that the two expressions have no variables in common. If there are
common variables, substitute a new variable in one of the expressions. (Since variables are
universally quantified, another variable can be substituted without changing the meaning.)

Imagine moving a pointer left-to-right across both expressions until parts are encountered that
are not the same in both expressions. If one is a variable, and the other is a term not containing
that variable,

1. substitute the term for the variable in both expressions,


2. substitute the term for the variable in the existing substitution set [This is necessary so
that the substitution set will be simultaneous.]
3. add the substitution to the substitution set.

Unification Implementation

1. Initialize the substitution set to be empty. We do this with the set ((t . t)). A nil set
indicates failure.
2. Recursively unify expressions:
1. Identical items match.
2. If one item is a variable vi and the other is a term ti not containing that variable,
then:
1. Substitute ti / vi in the existing substitutions.
2. Add ti / vi to the substitution set.
3. If both items are functions, the function names must be identical and all
arguments must unify. Substitutions are made in the rest of the expression as
unification proceeds.
Predicate Logic
The first of these, predicate logic, involves using standard forms of logical symbolism which
have been familiar to philosophers and mathematicians for many decades. Most simple
sentences, for example, ``Peter is generous'' or ``Jane gives a painting to Sam,'' can be
represented in terms of logical formulae in which a predicate is applied to one or more
arguments (the term `argument' as used in predicate logic is similar to, but not identical with, its
use to refer to the inputs to a procedure in POP-11):

PREDICATE ARGUMENTS

generous (peter)

gives (jane, painting, sam)

Consider the following sentence: ``Every respectable villager worships a deity.'' A moment's
reflection will reveal that this is ambiguous. Is it saying that there is one single deity to which
each respectable villager offers worship? Or does each worshipper have his or her own deity, to
which a fellow respectable villager may or may not be also praying? With predicate logic it is
easy to reveal the nature of the ambiguity, by a device known as quantification. Quantification
allows one to talk in a general way about all things of a certain class or about some particular but
unspecified thing of a certain class. We can, for instance, express the proposition ``All of Jane's
friends are generous'' in terms of the following formula:

For any X: IF friend(X,jane) THEN generous(X)

while the sentence ``Jane has at least one friend who is generous'' can be expressed as follows:

For some X: friend(X,jane) AND generous(X)

The expressions `For any X' and `For some X' are known as quantifiers. We can now use
quantification to exhibit the ambiguity of the sentence about the respectable villagers. The first
reading of it can be represented as

For some X: for any Y: deity(X)


AND IF (villager(Y) AND respectable(Y)) THEN
worships(Y,X)

while the second can be represented as


For any Y: (IF villager(Y) AND respectable(Y) THEN
For some X: deity(X) AND worships(Y,X))

S-ar putea să vă placă și