Ai-Module Iii
Ai-Module Iii
Ai-Module Iii
Knowledge representation -Using Predicate logic- representing facts in logic, functions and
Predicates, Conversion to clause form, Resolution in propositional logic, Resolution in predicate
Logic, Unification, Question Answering, forward and backward chaining.
(Elaine rich & Kevin Knight)
KNOWLEDGE REPRESENTATION
In order to solve the complex problems encountered in AI, one needs both a large amount of
knowledge and some mechanisms for manipulating that knowledge to create solutions to new
problems. A variety of ways of representing knowledge (facts) have been exploited in AI
programs.
Facts: truth in some relevant world. These are things we want to represent.
Representations of facts in some chosen formalism. These are the things we will actually
be able to manipulate.
One representation of facts concerns with natural language (particularly English) sentences.
Regardless of the representation for facts that we use in a program, we may also need to be
concerned with an English representation of those facts that in order to facilitate getting
information into and out of the system.
Propositional calculus is a language. Using their words, phrases and sentences, we can represent
and reason about properties and relationships in the world. Propositional logic is simple to deal with. We
can easily represent real world facts as logical propositions written as well formed formulas (wff’s) in
propositional logic.
propositional symbols:
o P, Q, R, S…. (P: it is raining Q: Marcus is a man)
truth symbols:
o True, False
connectives:
o ∩, U, ⌐, →, ≡
Equivalence
Two expressions in propositional calculus are equivalent if they have the same value under all
truth value assignments.
⌐ (⌐P) ≡ P
P → Q ≡ ⌐P U Q
⌐ (P U Q) ≡ ⌐P ∩ ⌐Q DE-MORGAN’S
⌐ (P ∩ Q) ≡ ⌐P U ⌐Q
P ∩ Q ≡ Q ∩ P Commutative
PUQ≡QUP
(P ∩ Q) ∩ R ≡ P ∩ (Q ∩ R) Associative
(P U Q) U R ≡ P U (Q U R)
P U (Q ∩ R) ≡ (P U Q) ∩ (P U R) Distributive
P ∩ (Q U R) ≡ (P ∩ Q) U (P ∩ R)
These identities can be used to change propositional calculus expressions into a syntactically
different but logically equivalent form.
Prove that P → Q ≡ ⌐P U Q
P Q PQ ⌐P ⌐P U Q
T T T F T
T F F F F
F T T T T
F F T T T
Prove that P ↔Q ≡ (P → Q) ∩( Q → P)
P Q P ↔Q PQ Q→P (P → Q) ∩( Q → P)
T T T T T T
T F F F T F
F T F T F F
F F T T T T
In propositional calculus, each atomic symbol P, Q etc.. Denotes a proposition of some complexity. There
is no way to access the components of an individual assertion. Predicate calculus provides this ability. For
eg. Instead of letting a single propositional symbol, P, denote the entire sentence “Marcus is a man”, we
can create a predicate man that describes the relationship between man and Marcus.
Man (Marcus)
Predicate symbols allow functions on objects. Functions denote a mapping of one or more
elements in a set (domain) into a unique element of another set (range).
Function has an associated arity indicating number of elements in domain mapped onto each
element on range.
Predicate calculus terms
The following are some statements represented in predicate calculus.
f (X, Y)
father (david)
price (bananas)
likes (george, Susie)
friends (bill, george)
likes (X, george)
The predicate symbols in these expressions are f, father, price, likes, friends.
In the predicates above, david, bananas, george, Susie, bill are constant symbols.
Quantifiers
Predicate calculus includes 2 symbols, the . ( for all and there exists)
The universal quantifier, , indicates that the sentence is true for all values of the variable. The
existential quantifier, , indicates that the sentence is true for at least one value in the domain. Some
relationships between universal and existential quantifiers are given below.
Material implication: , and (^) , or (v) , not (⌐)
o Example we can use mathematical logic as the representation formalism. Consider the English
sentences below
Spot is a dog
x : dog ( x) hastail ( x)
o Using the deductive mechanisms of the logic, we may generate the new representation object
hastail (Spot )
o Using an appropriate backward mapping function we could then generate the English sentence:
Spot has a tail
o Or we could make use this representation of new fact to cause us to take some appropriate action
or to derive representation of additional facts.
The following represents some facts in the real world and corresponding predicate calculus
expressions.
1. Marcus was a man.
man (Marcus)
2. Marcus was a Pompeian.
pompeian (Marcus)
3. All Pompeians were Romans.
7. People only try to assassinate rulers they are not loyal to.
It seems that using 7 and 8, we should be able to prove that Marcus was not loyal to Caesar.
Though try to prove, reasoning backward from the desired goal.
The nil at the end of each prove indicates that the list of conditions remaining to be proved is
empty and so the proof has succeeded.
It also allows equal objects to be substituted for each other whenever it appears helpful to do so
during a proof.
This attempt fails, since there is no way to conclude from that Marcus was a person.
We need to consider another fact – 9. Now we can satisfy the last goal and produce a proof that
Marcus was not loyal to Caesar.
Modus ponens
Modus ponens is one of the most commonly used concepts in logic. It is one of the accepted
mechanisms for the construction of deductive proofs that includes the "rule of definition" and the "rule of
substitution". Modus ponens allows one to eliminate a conditional statement from a logical proof or
argument and there by not carry these antecedents forward in an ever-lengthening string of symbols; for
this reason modus ponens is sometimes called the rule of detachment. For example, observes that
"modus ponens can produce shorter formulas from longer ones".
If the sentences P and P→Q are known to be true, then modus ponens lets us infer Q.
Example
Assume the following observations.
1. “it is raining”.
2. “if it is raining, then the ground will be wet”.
Through the application of modus ponens we can infer Q. that is “ground is wet”.
Example 2
Since the variable X in the implication is universally quantified, we may substitute any value in
the domain for x. By substituting “socrates” for X in the implication, we infer the expression,
man(socrates) → mortal(socrates)
By considering the predicates
man(socrates) and
man(socrates) → mortal(socrates)
All the simple facts were expressed as the combination of individual predicate.
Eg. Tryassassinate (Marcus, Caesar)
Suppose we want to express very large number of facts, such as the following greater than and
less than relationships: gt(1,0) , gt(2,1), lt(0,1), lt(1,2) etc. we do not want to have to write out the
representation of each of these facts individually. It would be extremely insufficient to store
explicitly a large set of statements when we would, instead, so easily compute each one of it as
we need it. So it is useful to have computable functions as well as computable predicates. The
next example shows how these ideas of computable functions and predicates. It also allows equal
objects to be substituted for each other whenever it appears helpful to do so during a proof.
Consider the problem of answering questions based on a database of simple facts, such as the following.
From looking at the proofs we have just shown, two things should be clear
In the next section, we introduce a proof procedure called resolution that reduces some of the
complexity because it operates on statements that have first been converted to a single canonical
form.
To prove a statement, resolution attempts to show that the negation of the statement
produces a contradiction with the known statements. That is known as refutation.
It’s a simple iterative process: at each step, two clauses called, the parent clauses, are
compared, yielding a new clause that has been inferred from them. The new clause
represents the ways that the two parents interact with each other.
2. Add the negation of what is to be proved, in clause form, to the set of axioms.
3. Resolve these clauses together, producing new clauses that logically follow from them.
5. The substitutions used to produce the empty clause are those under which the opposite of
the negated goal is true.
The following is the algorithm for reducing any set of predicate calculus statements
(wff) to clause form (Conjunctive normal form)
If the existential quantifier lies in the scope of a universal quantifier, then the value that satisfies
the predicate may depend on the value of the universally quantified variables.
a b a c
Separate each conjunct as
.
a b and
a c
9. Standardize the variables apart again. By this we mean rename the variables so that no two
clauses make reference to the same variables.
( X ) a X b X (X ) a X (Y ) b Y
After performing these nine steps, we will get the expression in clause form.
Example
10 | A J C E C S E / 2 0 1 6 / A I - C S 0 1 0 8 0 2
( X) ( [a (X) ∩ b (X)] → [c (X, I) ∩ ( Y) (( Z) [c(Y, Z)] → d (X, Y))]) U ( X) (e(X))
11 | A J C E C S E / 2 0 1 6 / A I - C S 0 1 0 8 0 2
1 ⌐(a (X) U ⌐b (X)] U c (X, I) U (e(W)
This is the clause form generated. Since each clause is a separate conjunct and since all the variables are
universally quantified, there need be no relationship between the variables of two clauses, even if they
were generated from same wff.
After applying this entire procedure to a set of wff’s, we will have a set of clauses, each of which is a
disjunction of literals. These clauses can now be exploited by the resolution procedure to generate proofs.
In propositional logic, the procedure for producing the proof by resolution of proposition P with
respect to a set of axioms F is the following.
Let’s look at a simple example. We want to prove R. First we convert the axioms to clause form.
Then we negate R, producing ⌐R, which is already in clause form. We begin by resolving with the clause
⌐R since that is one of the clauses that must be involved in the contradiction we are trying to find.
12 | A J C E C S E / 2 0 1 6 / A I - C S 0 1 0 8 0 2
Although any pair of clauses can be resolved, only those pairs that contain complementary literals will
produce a resolvant that is likely to lead to the goal of producing the empty clause.
A contradiction occurs when a clause becomes so restricted that there is no way it can be true.
This is indicated by generating empty clause. In order for proposition 2 to be true, one of three thing must
be true: ⌐P,⌐Q, or R. But we are assuming that ⌐R is true. Given The only way for proposition 2 to be
true is for one of two things to be true: ⌐P and ⌐Q. that is what resolvant says. But preposition says P is
true. Which means ⌐P cannot be true. This leaves only ⌐Q to be true. Preposition 4 can be true if either
⌐T or ⌐Q is true. The only way for preposition 4 to be true is for ⌐T to be true. Preposition 5 says that T is
true. There is no way for all these clauses to be true in a single interpretation. This is indicated by the
empty clause.
UNIFICATION
To apply inference rules such as modus ponens, an inference system must be able to determine when 2
expressions are the same or match. In propositional logic it is easy to determine the complementary
literals by finding L and ⌐L. In predicate calculus, the process of matching 2 sentences is complicated by
the existence of variables in the expressions. Unification is an algorithm for determining the substitutions
needed to make 2 predicate calculus expressions match.
The basic idea of unification is very simple. First check if their initial predicates are same. If so we can
proceed, otherwise there is no way to proceed. For example two literals
Tryassassinate(Marcus, Caesar)
hate(Marcus, Caesar) cannot be unified. If the predicate symbols match, then we must check the
arguments, one pair at a time.
The only complication in this procedure is that we must find a single, consistent substitution for
the entire literal, not separate one for each piece of it. Eg:
13 | A J C E C S E / 2 0 1 6 / A I - C S 0 1 0 8 0 2
P(x,x)
P(y,z) Compare x,y and decide that to substitute y for x (y/x) and then z for y(z/y).
We write composition as (z/y) (y/x).
Algorithm: unify (L1, L2)
1. if L1 and L2 are both variable or constant, then
(a) if L1 and L2 are identical then return NIL
(b) else if L1 is a variable, then if L1 occurs in L2 then return FAIL; else return {L2 / L1};
(c ) else if L2 is a variable: if then L2 occurs in L1 then return FAIL; else return {L1 / L2};
(d) else return FAIL;
2. if the initial predicate symbol in L1 and L2 are not identical, then return {FAIL}
3. if L1 and L2 have different number of arguments then return {FAIL}
4. Set SUBSET to NIL.
5. for I I to number of arguments in L1
a. call unify with the ith argument of L1 and the ith arguments of L2, putting result in S
b. if S contains FAIL then return {FAIL}
c. if S is not equal to NIL then:
1. Apply S to the remainder of both L1 and L2
2. SUBST=append(S, SUBST)
6. return SUBST
14 | A J C E C S E / 2 0 1 6 / A I - C S 0 1 0 8 0 2
RESOLUTION IN PREDICATE LOGIC
Unification is an easy way of determining two literals are contradictory – they are if one of them
can be unified with the negation of the other. For example, man(x) and ⌐man(spot) are contradictory,
since man(x) and man(spot) can be unified.
15 | A J C E C S E / 2 0 1 6 / A I - C S 0 1 0 8 0 2
Algorithm Predicate resolution:
Figure (a) shows the result of clause form conversion and (b) shows the resolution proof the
statement.
16 | A J C E C S E / 2 0 1 6 / A I - C S 0 1 0 8 0 2
Question Answering
AI – theorem proving technique – can also be applied to problem of answering questions.
As we have already suggested , this seems natural since both deriving theorems from axioms and
deriving new facts ( answers) from old facts employ the process of reduction.
Resolution can be used to answer YES/NO questions, such as ” is Marcus alive? “ . Here we are
using resolution to answer fill-in-the-blank questions, such as “When did Marcus die?”
died(Marcus,??)
17 | A J C E C S E / 2 0 1 6 / A I - C S 0 1 0 8 0 2
Fill-in-the-blank questions, “When did Marcus die?”
18 | A J C E C S E / 2 0 1 6 / A I - C S 0 1 0 8 0 2
Whatever value of date we use in producing that contradiction is the answer we want.
Fig: (a) shows the resolution process to find the answer. The answer to the
question can then be derived from the chain of unifications that lead back to the
starting clause.
We can eliminate the backward lookup by simply adding the expresson that we
are trying to prove. Fig: (b)
We can tag it with a special marker so it will not interfere with the resolution
process.
It just gets carried along, but each time unification is done, the dummy expression
also will also change as they are part of the actual clause.
19 | A J C E C S E / 2 0 1 6 / A I - C S 0 1 0 8 0 2
FORWARD AND BACKWARD CHAINING (Ref: Russel)
Start with the atomic sentences in the knowledge base and apply modus
Ponens in the forward direction, adding new atomic sentences, until no
further inferences can be made.
20 | A J C E C S E / 2 0 1 6 / A I - C S 0 1 0 8 0 2
Problem: Does situation Z exists or not ?
The first rule that fires is A->D because A is already in the database. Next we infer D. Existence of C
and D causes second rule to fire and as a consequence F is inferred and placed in the database. This in
turn, causes the third rule F&B->Z to fire, placing Z in the database.
This technique is called forward chaining.
N RULES R1,R2,......Rn
repeat
for i 1 to n do
if one or more current facts match the antecedent of Ri then
1 ) add the new fact(s) define by the consequent
2 ) flag the rule that has been fired
3 ) increase m
until no new facts have been produced.
Backward chaining
These algorithms work backward from the goal, chaining through rules to find known
facts that support the proof. The list of goals can be thought of as a stack waiting to be worked
on: if all of them can be satisfied, then the current branch of the proof succeeds. The backward
chaining algorithm takes the first goal in the list and finds every clause in the knowledge base
whose positive literal or head, unifies with the goal. Each such clause creates a new recursive
call in which the premise, or body, of the clause is added to the goal stack.
Abductive inference rule: [Modus Tollens]
Backward Chaining: Conclude from "B" and "A implies B" to "A".
B
A -> B
A
-------- ------------- -------------
Example: The Street is wet. (B)
If it is raining, the street is wet. (AB)
It is raining. (A)
21 | A J C E C S E / 2 0 1 6 / A I - C S 0 1 0 8 0 2
With this inference method the system starts with what it wants to prove, e.g., that situation Z
exists, and only executes rules that are relevant to establishing it. Figure following shows how
backward chaining would work using the rules from the forward chaining example.
In step 1 the system is told to establish (if it can) that situation Z exists, It first checks the
data base for Z, and when that fails, searches for rules that conclude Z, i.e., have Z on the right
side of the arrow. It finds the rule F&B->Z, and decides that it must establish F and B in order to
conclude Z.
In step 2 the system tries to establish F, first checking the data base and then finding a rule
that concludes F. From this rule, C&D->F, the system decides it must establish C and D to
conclude F.
In steps 3 the system finds C in the data base but decides it must establish A before it can
conclude D. It then finds A in the data base.
In steps 4 through 6 the system executes the third rule to establish D, and then executes the
second rule to establish the original goal, Z. The inference chain created here is identical to the
one created by forward chaining. The difference in two approaches hinges on the method in
which data and rules are searched.
22 | A J C E C S E / 2 0 1 6 / A I - C S 0 1 0 8 0 2