You are on page 1of 64

Techniques of Knowledge

Representation
Representing Simple Facts in Logic
• Knowledge is stored in a knowledge base using a particular representation scheme and
manipulated using Inference techniques or algorithms.
• Various representation schemes
– Logical representation – Propositional and Predicate logic
– Network representation – Semantic networks and Conceptual graphs
– Procedural representation – Expert systems
Logical Representation Scheme
2 Step process:
I. Converting facts to logical propositions (proposition or predicate)
Proposition- A statement putting forth an idea, suggestion or plan

I. Deducing additional information from these facts using backward


chaining or resolution
What is a proposition?
• A proposition is basically a declarative sentence that has a truth value.
• Truth value can either be true or false, but it needs to be assigned any of the two
values and not be ambiguous.
• The purpose of using propositional logic is to analyze a statement, individually or
compositely.
• The branch of logic that deals with proposition is propositional logic.
Propositions combined with Logical Operators:
Negation(¬),
Disjunction(∧),
Conjunction(∨),
Exclusive OR(⊕),
Implication(⇒),
Bi-Conditional or Double Implication(⇔).

Propositions have a specific truth value, true or false.


Predicate Logic
• Predicates are properties, additional information to better express the subject of the
sentence.
• A quantified predicate is a proposition , that is, when you assign values to a predicate
with variables it can be made a proposition.
• Predicate logic is an expression consisting of variables with a specified domain. It consists
of objects, relations and functions between the objects.
• A predicate’s truth value depends on the variables’ value

For example :
• In P(x) : x>5, x is the subject or the variable and ‘>5’ is the predicate.
• P(7) : 7>5 is a proposition where we are assigning values to the variable x, and it has a
truth value, i.e. True.
• The set of values that the variables of the predicate can assume is called the Universe or
Domain of Discourse or Domain of Predicate.
Predicate Logic
• Predicate Logic adds by introducing quantifiers to the existing
proposition
• It helps analyze the scope of the subject over the predicate. There are
three quantifiers :
Universal Quantifier (∀) depicts for all
Existential Quantifier (∃) depicting there exists some
Uniqueness Quantifier (∃!) depicting exactly one.
Logical Representation Scheme
1. Converting facts to logical propositions
• The first step is to convert facts in English sentence to logical
propositions(statements) called well-formed formulas (wffs).
• The wffs include the following symbols:
– Implies: →
– And: /\
– Or: \/
– Not: ~
– For all: ∀
– The exists: ∃
Examples
• Caesar was a ruler
ruler(Caeser)
• Rajiv likes cricket
Like( Rajiv, Cricket)
Example: Consider the following facts :
1. Marcus was a man.
2. Marcus was a Pompeian.
3. All Pompeians were Roman.
4. Caesar was a ruler.
5. All Romans were either loyal to Caesar or hated
him.
6. Everyone is loyal to someone.
7. People only try to assassinate rulers that they are
not loyal to.
8. Marcus tried to assassinate Caesar.
9. All men are people.
Ex: Consider the following facts
These facts can be represented in predicate logic as the following wffs:
1. Marcus was a man.
man(Marcus)
2. Marcus was a Pompeian.
Pompeian(Marcus)
3. All Pompeians were Romans.
∀x: Pompeian(x) → Roman(x)
4. Caesar was a ruler.
ruler(Caesar)
5. All Pompeians were either loyal to Caesar or hated him.
∀x: Roman(x) → loyalto(x, Caesar) ∨ hate(x, Caesar)
6. Everyone is loyal to someone.
∀x: ∃y: loyalto(x, y)

7. People only try to assassinate rulers they are not loyal to.
∀x: ∀y: person(x) ∧ ruler(y) ∧ tryassassinate(x, y) →¬loyalto(x, y)

8 Marcus tried to assassinate Caesar.


tryassassinate(Marcus, Caesar)

9.All men are people


∀x: man(x) → person(x)
Logical Representation Scheme
Step 2: Deducing additional information( backward chaining or resolution)
Backward Reasoning

Backward chaining matches a clause to the right-hand side of a rule (wff with an implies)
and then attempts to prove the clauses on the left-hand of the rule.

Backward chaining works from the backward direction of the goal, apply the rules on the known
facts which could support the proof.

Backward Chaining is a type of AND/OR search because we can prove the goal by applying any
rule in the knowledge base.

Backward chaining starts from the goal and works backward through inference rules to find the
required facts that support the goal.
Backward Reasoning
• Ex: Given the facts 1 to 9, answer the question ‘Was Marcus loyal to Caesar”?
• Soln : Since wff 7 has a ~loyalto on the right-hand side, we will attempt to prove ~loyalto(Marcus, Caesar):

Consider the following facts :


1. Marcus was a man.
2. Marcus was a Pompeian.
3. All Pompeians were Roman.
4. Caesar was a ruler.
5. All Romans were either loyal to Caesar or
hated him.
6. Everyone is loyal to someone.
7. People only try to assassinate rulers that they
are not loyal to.
8. Marcus tried to assassinate Caesar.
9. All men are people.
Exercise 1:
Consider the following facts:
1. John likes all kinds of food.
2. Apples are food.
3. Chicken is food
4. Anything anyone eats and is not killed by is food.
5. Bill eats peanuts and is still alive.
6. Sue eats everything Bill eats.
a) Convert these facts to wffs in predicate logic.
b) Using backward chaining prove the “John likes peanuts”.
Using backward chaining prove
the “John likes peanuts”.
Exercise 2:
Consider the following facts:
1. Steve only likes easy courses.
2. Science courses are hard.
3. All the courses in the basketweaving department are easy.
4. BK301 is a basketweaving course.
• a) Convert these facts to wffs in predicate logic.
• b) Use backward chaining to answer the question “What course
would Steve like?”.
• Consider the following axioms:
• Every child loves every candy.
• Anyone who loves some candy is not a nutrition fanatic.
• Anyone who eats any pumpkin is a nutrition fanatic.
• Anyone who buys any pumpkin either carves it or eats it.
• John buys a pumpkin.
• Lifesavers is a candy.
• (Conclusion) If John is a child, then John carves some pumpkin.
Solution
• Every child loves every candy.
∀ x ∀ y (CHILD(x) ∧ CANDY(y) → LOVES(x,y))
• Anyone who loves some candy is not a nutrition fanatic.
∀ x ( (∃ y (CANDY(y) ∧ LOVES(x,y))) → ¬ FANATIC(x))
• Anyone who eats any pumpkin is a nutrition fanatic.
∀ x ((∃ y (PUMPKIN(y) ∧ EAT(x,y))) → FANATIC(x))
• Anyone who buys any pumpkin either carves it or eats it.
∀ x ∀ y (PUMPKIN(y) ∧ BUY(x,y) → CARVE(x,y) ∨ EAT(x,y))
• John buys a pumpkin.
∃ x (PUMPKIN(x) ∧ BUY(John,x))
• Lifesavers is a candy.
CANDY(Lifesavers)
• (Conclusion) If John is a child, then John carves some pumpkin.
CHILD(John) → ∃ x (PUMPKIN(x) ∧ CARVE(John,x))
Consider the following set of facts, again involving Marcus:

• 1) Marcus was a man. man(Marcus)


• 2) Marcus was a Pompeian. Pompeian(Marcus)
• 3) Marcus was born in 40 A.D. born(Marcus, 40)
• 4) All men are mortal. ∀x : man(x) → mortal(x)
• 5) All Pompeians died when the volcano erupted in 79 A.D.
erupted(volcano, 79) ∧ ∀ x : [Pompeian(x) → died(x, 79)]
• 6) No mortal lives longer than 150 years.
∀x ∀t1 ∀t2: mortal(x) /\ born(x,t1) /\ gt(t2-t1,150) → dead(x,t2)
• 7) It is now 1991. now = 1991
• 8 Alive means not dead. ∀x ∀t: [alive(x,t) → ~dead(x,t)] /\ [~dead(x,t) →alive(x,t)]
• 9 If someone dies, then he is dead at all later times.
∀x ∀t1 ∀t2:died(x,t1) /\ gt(t2,t1) →dead(x,t2)
• Suppose we want to answer the question “Is Marcus alive now?”.
• The statements suggested here, there may be two ways of deducing an answer.
• Either we can show that Marcus is dead because he was killed by the volcano or we can show that he
must be dead because he would otherwise be more than 150 years old, which we know is not possible.
• We can do this by either proving alive(Marcus,now) or ~alive(Marcus,now).
• Let us try the latter:
Knowledge Representation-

Resolution
Logical Representation Scheme
2 Step process:
I. Facts are represented as logical propositions
and
II. Additional information is deduced from these
facts using backward chaining or resolution
1. Converting facts to logical propositions
• The first step is to convert facts in English sentence to logical
propositions(statements) called well-formed formulas (wffs).
• The wffs include the following symbols:
– Implies: →
– And: /\
– Or: \/
– Not: ~
– For all: ∀
– The exists: ∃
2. Deduce addition information using Resolution

• Resolution - Resolve something


• The process to prove a statement.
• Resolution produces proofs by refutation. It proves facts and answers
queries by refutation. This involves assuming the fact/query is untrue
and reaching a contradiction which indicates that the opposite must be
true.
• In other words, to prove a statement (i.e., to show that it is valid),
resolution attempts to show that the negation of the statement
produces a contradiction with the known statements (i.e., that it is
unsatisfiable).
• The wffs must firstly be converted to clause form before using resolution.
• Resolution is a proof technique that works this way
1.select two clauses that contain conflicting terms.
2. Combine those two clauses and cancel out the conflicting terms.
• The resolution procedure is a simple iterative process: at each step,
two clauses, called the parent clauses, are compared (resolved),
resulting in a new clause that has inferred from them.
• The new clause represents ways that the two parent clauses
interact with each other.
• Resolution operates by taking two clauses that each contain the
same literal (ex: Winter). The literal must occur in the positive
form in one clause and in negative form in the other.
• The resolvent is obtained by combining all of the literals of the
two parent clauses except the ones that cancel.
• If the clause that produced is the empty clause, then a
contradiction has found.
• Ex: Suppose that there are two clauses in the system:
winter V summer
¬ winter V cold
• The two clauses Winter and ¬ winter will produce the empty
clause.
Steps in Resolution :
• 1. Converts facts into FOL
• 2. Converts FOL into CNF ( Conjuctive Normal Form )
• 3. Negate the statement to be proved , and add the result to the
knowledge base.
• 4. Draw Resolution graph
* if empty clause (NIL) is produced , stop and report that original
theorem is true
Algorithm: Resolution
• 1. Convert the wffs to clause form.
• 2. Add the fact (or query) P to be proved to the set of clauses:
i. Negate P.
ii. Convert negated P to clause form.
iii. Add the result of ii to the set of clauses.
• 3. Repeat
i. Select two clauses.
ii. Resolve the clauses using unification.
iii. If the resolvent clause is the empty clause, then a contradiction
has been reached.
If not add the resolvent to the set of clauses until (a contradiction
is found OR no progress can be made)
Algorithm: Converting wffs to Clause Form

1. Remove all implies, i.e. → by applying the following:


a → b is equivalent to ~a \/ b.

2. Use the following rules to reduce the scope of each


negation operator to a single term:
~(~a) = a
~(a /\ b) = ~a \/ ~b
~(a \/ b) = ~a /\ ~b
~∀x: p(x) = ∃x: ~p(x)
~∃x: p(x) = ∀x: ~p(x)
3. Each quantifier must be linked to a unique variable. For example,
consider ∀x: p(x) \/ ∀x: q(x). In this both quantifiers are using the
same variable and one must changed to another variable: ∀x: p(x) \/
∀y: q(y).

4. Apply the associative property of disjunctions:


a \/ (b \/ c) = (a \/ b) \/ c
and remove brackets giving a \/ b \/ c.
Resolution refutation proofs involves the following
steps:
• 1. Put the premises or axioms into clause form.
• 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.
• 4. Produce a contradiction by generating the
empty clause.
• 5. The substitutions used to produce the empty
clause are those under which the opposite of the
negated goal is true.
Algorithm: Propositional Resolution
• 1. Convert all the propositions of F(set of axioms) to clause form.
• 2. Negate P and convert the result to clause form. Add it to the
set of clauses obtained in step 1.
• 3. Repeat until either a contradiction is found or no progress can
be made:
• a) Select two clauses. Call these the parent clauses.
• b) Resolve them together. The resulting clause, called the
resolvent, will be the disjunction of all of the literals of both of
the parent clauses with the following exception: If there are any
pairs of literals L and ¬ L such that one of the parent clauses
contains L and the other contains ¬L, then select one such pair
and eliminate both L and ¬ L from the resolvent.
• c) If the resolvent is the empty clause, then a contradiction has
been found. If it is not, then add it to the set of classes available
to the procedure.
a → b is equivalent to ~a \/ b.
Prove R ?
Resolution in Predicate Logic
• The resolution algorithm for predicate logic as
follows, assuming a set of given statements F and a
statement to be proved P:
• Algorithm:
• 1. Convert all the statements of F to clause form.
• 2. Negate P and convert the result to clause form.
Add it to the set of clauses obtained in 1.
• 3. Repeat until a contradiction found, no progress
can make, or a predetermined amount of effort has
expanded.
• (a) Select two clauses. Call these the parent clauses.
• (b) Resolve them together. The resolvent will the
disjunction of all the literals of both parent clauses
with appropriate substitutions performed and with
the following exception:
• If there is one pair of literals T1 and ¬T2 such that one of
the parent clauses contains T2 and the other contains T1
and if T1 and T2 are unifiable, then neither T1 nor T2
should appear in the resolvent. We call T1 and T2
Complementary literals. Use the substitution produced by
the unification to create the resolvent. If there is more than
one pair of complementary literals, only one pair should
omit from the resolvent.
• (c). If the resolvent is an empty clause, then a
contradiction has found. Moreover, If it is not, then
add it to the set of classes available to the procedure
Example 1:

Consider the given facts:


• 1. All dogs are animal.
• 2. Fido is a dog.
• 3. All animals will die.

• Prove ‘fido will die’ using resolution


Step 1 Convert stmt to FOL
• 1. All dogs are animal.
∀x: dog(x) → animal(x)
• 2. Fido is a dog.
Dog(Fido)
• 3. All animals will die.
∀y: animal(y) → die(y)
Step 2:Convert FOL to CNF
a → b is equivalent to ~a \/ b.
• 1. All dogs are animal.
∀x: dog(x) → animal(x)
¬ dog(x) \/ animal(x)
• 2. Fido is a dog.
dog(Fido)
• 3. All animals will die.
∀y: animal(y) → die(y)
¬ animal (y) \/ die (y)
Step 3: Negate the stmt to be proved

• Fido will die == die(Fido)


Negation: ¬ die(Fido)
STEP 4. DRAW RESOULTION GRAPH
(iii)
~die (fido) ~animal (y) V die (y)

ORing
fido/y

~animal (fido)
~dog(x) V animal (x) (i)

fido/x

~dog(fido) dog(fido) (ii)

Hence Proved
Example 2:
Consider the following facts:
1. John likes all kinds of food.
2. Apples are food.
3. Anything anyone eats and is not killed by is food.
4. Bill eats peanuts and is still alive.
5. Sue eats everything Bill eats.
a) Convert these facts to wffs in predicate logic.
b) Using resolution, prove that “John likes peanuts”.
Step 1:
Step 2:
a → b is equivalent to ~a \/ b.
• 1. ~ food(x) V likes(John,x)
• 2. food(apple)
• 3. ~ eats(x,y) V ~ alive (x) V food(y) #~killedby ==alive(x)

• 4.eats(ajay, peanut ) Ù alive(ajay)


• ~ food(x) V ~eats (ajay,x) V eats(Sue,x)
Step 3: Negate the stmt to be proved
• John likes peanuts == likes(John,peanuts) (predicate stmt)
• Neagation: ~likes(John, peanuts)
Step 2:
a → b is equivalent to ~a \/ b.
• 1. ~ food(x) V likes(John,x)
• 2. food(apple)
• 3. ~ eats(x,y) V ~ alive (x) V food(y) # ~killedby
==alive(x)
• 4.eats(ajay, peanut ) Ù alive(ajay)
• ~ food(x) V ~eats (ajay,x) V eats(Sue,x)
STEP 4. DRAW RESOULTION GRAPH
(i)
~likes (john, peanut) ~food(x) V likes (John, x)

ORing
x, peanut

~food (peanut) ~eats(x, y) V ~alive (x) V ~food (y)


(iii)

y, peanut

~eats(x, peanut) V ~alive (x) eats(ajay, peanut) Ù alive(ajay) (iv)

x, ajay Rule: V~ = Ù

Hence Proved
Example 3: Lucky Student
• 1. Anyone passing his AI exam and winning the
lottery is happy.
• 2. Anyone who studies or is lucky can pass all his
exams.
• 3. John did not study but he is lucky.
• 4. Anyone who is lucky wins the lottery.

• Prove that John is happy!


Example 5: Exciting life
• 1. All people that are not poor and are
smart are happy.
• 2. Those people that read are not stupid.
• 3. John can read and is wealthy.
• 4. Happy people have exiting lives.

Can anyone be found with an exciting life?

You might also like