0% found this document useful (0 votes)
39 views96 pages

Module-3 Knowledge Representation

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
39 views96 pages

Module-3 Knowledge Representation

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 96

Artificial Intelligence

Module-III:
Knowledge Representation using
Predicate Logic and Rules

Dr. Dwiti Krishna Bebarta

Text Book Referred:


1. Artificial Intelligence, Elaine Rich and Kevin Knight, Tata McGraw -Hill Publications
2. Introduction To Artificial Intelligence & Expert Systems, Patterson, PHI publications
Knowledge Representation using Predicate Logic and Rules
Topics to discuss:
• Propositional Logic
• First Order Predicate Logic:
– Representing Instance and is-a Relationships
– Computable Functions and Predicates
• Resolution in propositional logic
• Resolution in predicate logic with Clause form
• Unification & Resolution algorithm
• Question Answering
• Procedural Vs Declarative Knowledge
• Logic programming with Prolog
• Forward Vs Backward Reasoning and combining them
• Matching Techniques
• Matching with variables
• RETE Algorithm
• Conflict resolutions
Propositional Logic
• Propositional logic (PL) is the simplest form of logic where
all the statements are made by propositions. A proposition is
a declarative statement which is either true or false. It is a
technique of knowledge representation in logical and
mathematical form.
– It is Sunday.
– The Sun rises from West (False proposition)
– 3+3= 7(False proposition)
– 5 is a prime number.
• Propositional logic is also called Boolean logic as it works on 0 and 1.
• In propositional logic, we use symbolic variables to represent the logic,
and we can use any symbol for a representing a proposition, such A, B,
C, P, Q, R, etc.
• Propositions can be either true or false, but it cannot be both.
• Propositional logic consists of an object, relations or function, and logical
connectives.
• These connectives are also called logical operators.
• The propositions and connectives are the basic elements of the
propositional logic.
• Connectives can be said as a logical operator which connects two
sentences.
• A proposition formula which is always true is called tautology, and it is
also called a valid sentence.
• A proposition formula which is always false is called Contradiction.
• Statements which are questions, commands, or opinions are not
propositions such as "Where is Rohini", "How are you", "What is your
name", are not propositions.
Syntax of propositional logic:
• The syntax of propositional logic defines the allowable sentences for the
knowledge representation. There are two types of Propositions:
1. Atomic Propositions
2. Compound Propositions
Atomic Proposition: Atomic propositions are the simple propositions. It
consists of a single proposition symbol. These are the sentences which
must be either true or false.
Example:
• 2+2 is 4, it is an atomic proposition as it is a true fact.
• "The Sun is cold" is also a proposition as it is a false fact.
Compound proposition: Compound propositions are constructed by
combining simpler or atomic propositions, using parenthesis and logical
connectives.
Example:
• "It is raining today, and street is wet."
• "Ankit is a doctor, and his clinic is in Mumbai."
Logical or Sentence connectives
Symbols used to combine two sentences to form a compound
statement

Logic Name Rank Example


~ Negation 1 not A (~A)
˄ Conjunction 2 A and B (A ˄ B)
˅ Disjunction 3 A or B (A ˅ B)
→ Conditional/ 4
A implies B: (A → B)
Implication
↔ Bi-conditional 5 A if and only if B (A ↔ B)

A implies B: (A → B) (~A˅B)
A if and only if B (A ↔ B) (~A˅B) ˄ (~B˅A)
• The natural language words may have slightly different
meanings.
Example:
• A ^ B and B ^ A should always have the same meaning.
But the below sentences
• She became sick and she went to the doctor.

• She went to the doctor and she became sick.

• Have different meanings.


Precedence Operators
First Precedence Parenthesis
Second Precedence Negation
Third Precedence Conjunction(AND)
Fourth Precedence Disjunction(OR)
Fifth Precedence Conditional/Implication
Six Precedence Bi-conditional
• Proposition refers to a declarative statement i.e. either true
or false
• The propositional calculus is defined in the context of
Boolean constants, where two or more values are computed
against each other to produce an accurate description of a
concept. Each variable used in the calculus holds a value for
it, which is either true to the context or false
• Also defined as, A set of rules are used to combine simple
propositions to form compound propositions with help of
logical operators i.e. Logical or sentence connectives.
• The important properties of a well-formed formula in PC are:
Properties of Operators:
• Commutativity:
 P∧ Q= Q ∧ P, or
 P ∨ Q = Q ∨ P.
• Associativity:
 (P ∧ Q) ∧ R= P ∧ (Q ∧ R),
 (P ∨ Q) ∨ R= P ∨ (Q ∨ R)
• Identity element:
 P ∧ True = P,
 P ∨ True= True.
• Distributive:
 P∧ (Q ∨ R) = (P ∧ Q) ∨ (P ∧ R).
 P ∨ (Q ∧ R) = (P ∨ Q) ∧ (P ∨ R).
• DE Morgan's Law:
 ¬ (P ∧ Q) = (¬P) ∨ (¬Q)
 ¬ (P ∨ Q) = (¬ P) ∧ (¬Q).
• Double-negation elimination:
 ¬ (¬P) = P.
Using truth tables to prove that ¬A∨ B and A→B are logically
equivalent

Yes, it is ¬A∨ B ≡ A→B

Limitations of Propositional logic:


We cannot represent relations like ALL, some, or none with propositional
logic. Example:
All the girls are intelligent.
Some apples are sweet.
Propositional logic has limited expressive power.
In propositional logic, we cannot describe statements in terms of their
properties or logical relationships.
Solve the following problems
• (A↔B) ↔(A→B) ˄ (B→A)
• [(A ˄ ~ B) →C, ~(A ˄ ~ B ˄ ~ C)]
• Are they logical equivalent?
Propositional Logic (PL)

• Simple language for showing key ideas and definitions


• Deals with the validity, Satisfiability (consistency),
un-Satisfiability (inconsistency)
• User defines set of propositional symbols, like P and Q
• User defines semantics of each propositional symbol:
– P means “It is hot”, Q means “It is humid”, etc.
• A sentence (well formed formula) is defined as follows:
– A symbol is a sentence
– If S is a sentence, then S is a sentence
– If S and T are sentences, then (S  T), (S  T), (S  T), and
(S ↔ T) are sentences
– A sentence results from a finite number of applications of
the rules
• Each row of a truth table for a given formula α is called its
interpretation under which the value of a formula may be true
or false
• A formula α is said to be a tautology if the value of α is true
for all its interpretations
• A formula α is said to be satisfiable if there exists at least
one interpretation for which α is true
• A formula α is said to be unsatisfiable if the value of α is
false under all interpretations
A B ~A A→B i.e. ~A˅B [(A→B) ∧ A] ~[(A→B) ∧ A] ~[(A→B) ∧ A] ˅ B
T T F T T F T
T F F F F T T
F T T T F T T
F F T T F T T

This formula α is a tautology


For each of the following compound propositions determine if it
is a tautology, satisfiable or unsatisfiable:
• (p ∨ q) ∧ ¬p ∧ ¬q
• p ∨ q ∨ r ∨ (¬p ∧ ¬q ∧ ¬r)
• (p → q) ↔ (¬p ∨ q)
First Order Predicate Logic
• Predicate logic is an extension of propositional logic that
permits concisely reasoning about whole classes of entities.
E.g., “x>1”, “x+y=10”
• Such statements are neither true or false when the values of
the variables are not specified.
Applications of Predicate Logic
• It is the formal notation for writing perfectly clear, concise,
and unambiguous mathematical definitions, axioms, and
theorems for any branch of mathematics.
• Supported by some of the more sophisticated database
query engines.
• Basis for automatic theorem and many other Artificial
Intelligence systems.
Applications of First-Order Logic in AI
First-order logic is instrumental in various AI applications, enabling systems to reason
about complex knowledge structures and make informed decisions. Some of the key
applications of FOL in AI include:
• Knowledge Representation: FOL provides a robust framework for representing
complex relationships and properties of objects. For example, in a medical diagnosis
system, predicates can represent symptoms, diseases, and their relationships,
allowing the system to reason about potential diagnoses.
• Automated Theorem Proving: Automated theorem proving involves using algorithms
to prove mathematical theorems. FOL provides the foundational structure for many
theorem proving systems, enabling them to verify software and hardware correctness,
prove mathematical theorems, and more.
• Natural Language Processing (NLP): In NLP, FOL is used to parse and understand
natural language by representing the meaning of sentences in a formal, logical
manner. This allows AI systems to perform tasks such as question answering,
machine translation, and text summarization.
• Expert Systems: Expert systems encode expert knowledge using FOL and reason
about it to make decisions. For example, a legal expert system might use FOL to
represent legal rules and infer outcomes based on given facts, aiding in legal
decision-making processes.
• Semantic Web: The Semantic Web uses FOL to describe relationships between web
resources, enabling more intelligent information retrieval and processing. This
enhances the ability of AI systems to understand and interact with web content.
Subjects and Predicates
• The proposition
“The dog is sleeping”
has two parts:
– “the dog” denotes the subject - the object or entity that the
sentence is about.
– “is sleeping” denotes the predicate- a property that the subject
can have.
Propositional Functions
• A predicate is modeled as a function P(·) from objects to
propositions.
– P(x) = “x is sleeping” (where x is any object).
• Predicate logic includes propositional functions of any number of
arguments.
e.g. let P(x,y,z) = “x gave y the grade z”,
x=“Mike”, y=“Mary”, z=“A”,
P(x,y,z) = “Mike gave Mary the grade A.”
Universe of Discourse (UD)
• The collection of values that a variable x can take is called
x‟s universe of discourse.
e.g., let P(x)=“x+1>x”.
we could define the course of universe as the set of integers.
Quantifier Expressions
• Quantifiers allow us to quantify (count) how many objects in
the universe of discourse satisfy a given predicate:
Universal Quantifier (∀)
- “” is the FOR ALL or universal quantifier.
x P(x) means for all x in the UD, P holds.
• Let P(x) be the predicate “x is full.”
• Let the UD of x be parking spaces at GVP.
• The universal quantification of P(x),
x P(x), is the proposition:
– “All parking spaces at GVP are full.” or
– “Every parking space at GVP is full.” or
– “For each parking space at GVP, that space is full.”
• To prove that a statement of the form
x P(x) is false, it suffices to find a counter example (i.e.,
one value of x in the universe of discourse such that P(x) is
false)
Existential Quantifier  Example
• Let P(x) be the predicate “x is full.”
• Let the UD of x be parking spaces at GVP.
• The universal quantification of P(x),
x P(x), is the proposition:
– “Some parking space at GVP is full.” or
– “There is a parking space at GVP that is full.” or
– “At least one parking space at GVP is full.”
First Order Predicate Logic
• First-order logic is another way of knowledge representation
in artificial intelligence. It is an extension to propositional
logic.
• FOL is sufficiently expressive to represent the natural
language statements in a concise way.
• First-order logic is also known as Predicate logic or First-
order predicate logic. First-order logic is a powerful
language that develops information about the objects in a
more easy way and can also express the relationship
between those objects.
• First-order logic (like natural language) does not only
assume that the world contains facts like propositional logic
but also assumes the following things in the world:
– Objects: A, B, people, numbers, colors, wars, theories,
squares, pits, wumpus, ......
– Relations: It can be unary relation such as: red, round,
is adjacent, or n-any relation such as: the sister of,
brother of, has colour, comes between
– Function: Father of, best friend, third inning of, end of,
......
• As a natural language, first-order logic also has two main
parts:
– Syntax
– Semantics
Syntax of First-Order logic:
• Basic Elements of First-order logic:

Constant 1, 2, A, John, Mumbai, cat,....


Variables x, y, z, a, b,....
Predicates Brother, Father, >,....
Function sqrt, LeftLegOf, ....
Connectives ∧, ∨, ¬, ⇒, ⇔
Equality ==
Quantifier ∀, ∃
Atomic sentences:
• Atomic sentences are the most basic sentences of first-order
logic. These sentences are formed from a predicate symbol
followed by a parenthesis with a sequence of terms.
• We can represent atomic sentences as Predicate (term1,
term2, ......, term n).
• Example:
Ravi and Ajay are brothers: => Brothers(Ravi, Ajay).
Chinky is a cat: => cat (Chinky).
Complex Sentences:
• Complex sentences are made by combining atomic
sentences using connectives.
Quantifiers in First-order logic:
• A quantifier is a language element which generates quantification,
and quantification specifies the quantity of specimen in the
universe of discourse.
• These are the symbols that permit to determine or identify the
range and scope of the variable in the logical expression.
• There are two types of quantifier:
– Universal Quantifier, (for all, everyone, everything)
– Existential quantifier, (for some, at least one).
• If x is a variable, then ∀x is read as:
– For all x
– For each x
– For every x
• Example:
– All man drink coffee.
– Let a variable x which refers to a man and all x can be
represented in UD as explained in next slide:
All man drink coffee.
∀x man(x) → drink (x, coffee).
Existential Quantifier:
• Existential quantifiers are the type of quantifiers, which
express that the statement within its scope is true for at least
one instance of something.
• It is denoted by the logical operator ∃, which resembles as
inverted E. When it is used with a predicate variable then it is
called as an existential quantifier.
• If x is a variable, then existential quantifier will be ∃x or ∃(x).
• It will be read as:
– There exists a 'x.'
– For some 'x.'
– For at least one 'x.'
• Example:
• Some boys are intelligent.
Some boys are intelligent.

∃x: boys(x) ∧ intelligent(x)


Properties of Quantifiers:
• In universal quantifier, ∀x∀y is similar to ∀y∀x.
• In Existential quantifier, ∃x∃y is similar to ∃y∃x.
• ∃x∀y is not similar to ∀y∃x.

All birds fly.


Every man respects his parent.
Some boys play cricket.
Not all students like both Mathematics and Science.
Only one student failed in Mathematics.

1. ∀x bird(x) →fly(x).
2. ∀x man(x) → respects (x, parent).
3. ∃x boys(x) → play(x, cricket).
4. ¬∀ (x) [ student(x) → like(x, Mathematics) ∧ like(x, Science)].
5. ∃(x) [ student(x) → failed (x, Mathematics) ∧∀ (y) [¬(x==y) ∧
student(y) → ¬failed (y, Mathematics)]].
Consider the following example that shows the use of predicate
logic as a way of representing knowledge.
1. Marcus was a man.
2. Marcus was a Pompeian.
3. All Pompeians were Romans.
4. Caesar was a ruler.
5. All Pompeians were either loyal to Caesar or hated him.
6. Everyone is loyal to someone.
7. People only try to assassinate rulers they are not loyal to.
8. Marcus tried to assassinate Caesar.
The facts described by these sentences can be represented as
a set of well-formed formulas (wffs) as follows:
• Marcus was a man.
– man(Marcus)
• Marcus was a Pompeian.
– Pompeian(Marcus)
• All Pompeians were Romans.
– ∀x: Pompeian(x) → Roman(x)
• Caesar was a ruler.
– ruler(Caesar)
• All Pompeians were either loyal to Caesar or hated him.
 As inclusive-or
– ∀x: Roman(x) → loyalto(x, Caesar) ∨ hate(x, Caesar)
 As exclusive-or
– ∀x: Roman(x) → (loyalto(x, Caesar) ∧¬ hate(x, Caesar)) ∨
(¬loyalto(x, Caesar) ∧ hate(x, Caesar))
• Everyone is loyal to someone.
– ∀x: ∃y: loyalto(x, y)
• People only try to assassinate rulers they are not loyal to.
– ∀x: ∀y: person(x) ∧ ruler(y) ∧ tryassassinate(x, y) →¬loyalto(x, y)
• Marcus tried to assassinate Caesar.
– tryassassinate(Marcus, Caesar)
• Now suppose if we want to use these statements to answer
the question: Was Marcus loyal to Caesar?

1. NIL
2. man(Marcus)
3. ruler(Caesar)
4. tryassassinate(Marcus, Caesar)
5. ¬ loyalto(Marcus, Caesar)
An attempt to prove ¬loyalto(Marcus, Caesar)
• The problem is that, although we know that Marcus was a
man, we do not have any way to conclude from that that
Marcus was a person.
• So, We need to add the representation of another fact to our
system, namely: All men are person
– ∀ man(x) → person(x)
Representing Instance and ISA Relationships
• Specific attributes instance and isa play an important role
particularly in a useful form of reasoning called property
inheritance.
• The predicates instance and isa explicitly captured the
relationships they used to express, namely class membership and
class inclusion.
• The first part of the figure contains the representations we have
already discussed. In these representations, class membership
represented with unary predicates (such as Roman), each of which
corresponds to a class.
• Asserting that P(x) is true is equivalent to asserting that x is an
instance (or element) of P.
• The second part of the figure contains representations that use the
instance predicate explicitly.
Three ways of representing class membership: ISA Relationships
• The predicate instance is a binary one, whose first argument is an object
and whose second argument is a class to which the object belongs.
• But these representations do not use an explicit isa predicate.
• Instead, subclass relationships, such as that between Pompeians and
Romans, described as shown in sentence 3.
• The implication rule states that if an object is an instance of the subclass
Pompeian then it is an instance of the superclass Roman.
• Note that this rule is equivalent to the standard set-theoretic definition of
the subclass superclass relationship.
• The third part contains representations that use both the instance and isa
predicates explicitly.
• The use of the isa predicate simplifies the representation of sentence 3,
but it requires that one additional axiom (shown here as number 6) be
provided.
Computable Functions and Predicates
• To express simple facts, such as the following greater-than
and less-than relationships:
– gt(1,0) It(0,1) gt(2,1) It(1,2) gt(3,2) It( 2,3)
• It is often also useful to have computable functions as well as
computable predicates.
– Thus we might want to be able to evaluate the truth of
gt(2 + 3,1)
– To do so requires that we first compute the value of the
plus function given the arguments 2 and 3, and then send
the arguments 5 and 1 to gt.
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 1740
born(Marcus, 1740)
4. All men are mortal.
∀x: man(x) → mortal(x)
5. All Pompeians died when the volcano erupted in 1779.
erupted(volcano, 1779) ∧ ∀ x : [Pompeian(x) → died(x, 1779)]
6. No mortal lives longer than 150 years.
∀x: ∀t1: ∀t2: mortal(x) ∧ born(x, t1) ∧ gt(t2 – t1,150) → died(x, t2)
7. It is now 2024.
now = 2024
• Now 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.
• Also, As soon as we attempt to follow either of those paths
rigorously, however, we discover, just as we did in the last
example, that we need some additional knowledge. For example,
our statements talk about dying, but they say nothing that relates to
being alive, which is what the question is asking.
• Modus ponens: If there is an axiom E → F and an axiom E, then
F logically follows.
• Modus tolens: If there is an axiom E → F and an axiom ¬F, then
¬E follows logically
So we add the following facts:
• Alive means not dead.
– ∀x:∀t: [alive(x, t) → ¬ died(x, t)] ∧ [¬ died(x, t) → alive(x, t)]
– ∀x:∀t: [alive(x, t) ↔ ¬ died(x, t)]
• If someone dies, then he is dead at all later times.
– ∀x: ∀t1: ∀t2: died(x, t1) ∧ gt(t2, t1) → died(x, t2)

Now let‟s attempt to answer the question “Is Marcus alive now?”

by proving:
¬ alive(Marcus,now)
7
Prove: Is Marcus alive now? i.e. ¬ alive(Marcus,now)
1. NIL
2. man(Marcus) by rule-1
3. Pompeian(Marcus) by rule-2
4. gt(2024,1979) compute
5. gt(now,1979) substitute by rule-7
6. Pompeian(Marcus) ∧ gt(now,1979) combine 2 and sentence 5
7. died(Marcus, 1779) ∧ gt(now,1979) by rule 5 and x/marcus
8. died(x, t1) ∧ gt(t2,t1) substitution with variables
9. died(x,t2) by rule 9
10. ¬ alive(Marcus,now) by rule 8

1. man(Marcus)
2. Pompeian(Marcus)
3. born(Marcus, 1740)
4. ∀x: man(x) → mortal(x)
5. erupted(volcano, 1779) ∧ ∀ x : [Pompeian(x) → died(x, 1779)]
6. ∀x: ∀t1: ∀t2: mortal(x) ∧ born(x, t1) ∧ gt(t2 – t1,150) → died(x, t2)
7. now = 2024
8. ∀x:∀t: [alive(x, t) → ¬ died(x, t)] ∧ [¬ died(x, t) → alive(x, t)]
9. ∀x: ∀t1: ∀t2: died(x, t1) ∧ gt(t2, t1) → died(x, t2)
Prove: Is Marcus died because of volcano erupted in 1979 ? i.e. Died(Marcus,1979)
1. NIL
2. man(Marcus) by rule-1
3. Pompeian(Marcus) by rule-2
4. erupted(volcano, 1779) compute
5. erupted(volcano, 1779) ∧ Pompeian(Marcus) combine 3 & 4
7. Died(Marcus,1979) by rule 5

1. man(Marcus)
2. Pompeian(Marcus)
3. born(Marcus, 1740)
4. ∀x: man(x) → mortal(x)
5. erupted(volcano, 1779) ∧ ∀ x : [Pompeian(x) → died(x, 1779)]
6. ∀x: ∀t1: ∀t2: mortal(x) ∧ born(x, t1) ∧ gt(t2 – t1,150) → died(x, t2)
7. now = 2024
8. ∀x:∀t: [alive(x, t) → ¬ died(x, t)] ∧ [¬ died(x, t) → alive(x, t)]
9. ∀x: ∀t1: ∀t2: died(x, t1) ∧ gt(t2, t1) → died(x, t2)
Resolution in propositional logic
1. Convert all the propositions of F 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:
1. Select two clauses. Call these the parent clauses.
2. 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.
3. 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.
The Unification Algorithm
• In propositional logic, it is easy to determine that two literals
cannot both be true at the same time.
• Simply look for L and ¬L in predicate logic, this matching
process is more complicated since the arguments of the
predicates must be considered.
• For example, man(John) and ¬man(John) is a contradiction,
while the man(John) and ¬man(Spot) is not.
• Thus, in order to determine contradictions, we need a
matching procedure that compares two literals and discovers
whether there exists a set of substitutions that makes them
identical.
• There is a straightforward recursive procedure, called the
unification algorithm, that does it.
• Propositional Resolution
αvβ
¬β v γ
---------------
αvγ
• Resolution refutation:
– Convert all sentences to CNF
– Negate the desired conclusion (converted to Conjunctive Normal
Form (CNF)
– Apply resolution rule until either
» Derive false (a contradiction)
» Can‟t apply any more
• Resolution refutation is sound and complete
• If we derive a contradiction, then the conclusion follows from the
axioms
• If we can‟t apply any more, then the conclusion cannot be proved
from the axioms.
The Resolution proof procedure is as follows:
• Negate the theorem to be proved
• Turn the theorem and the axioms into clause form.
• Until the empty clause is produced or there are no
resolvable clauses, find pairs of resolvable clauses, resolve
them (including Unification), and add them to the list of
clauses.
• If the empty clause was produced, the negated theorem
contradicted the axioms, and the (unnegated) theorem is
TRUE, w.r.t. the axioms. If there were no more resolvable
clauses, the theorem is FALSE w.r.t. the axioms.
Propositional Resolution Example
1. P v Q
Sl. No. Formula Derivation
2. P → R
1 PvQ Given
3. Q → R
2 ~P v R Given
Prove R
3 ~Q v R Given
4 ~R Negated conclusion

Sl. No. Formula Derivation


5 QvR As per 1 & 2
6 ~P As per 2 & 4
7 ~Q As per 3 & 4
8 R As per 5 & 7
9 As per 4 & 8

And finally, resolving away R in lines 4 and 8, we get the empty clause,
which is false. We‟ll often draw this little black box to indicate that we‟ve
reached the desired contradiction.
What is Unification?
• Unification is a process of making two different logical atomic
expressions identical by finding a substitution. Unification depends on
the substitution process.
• It takes two literals as input and makes them identical using substitution.
• Let L1 and L2 be two atomic sentences and ? be a unifier such
that, L1? = L2?, then it can be expressed as UNIFY(L1, L2).
• Example: Find the Most General Unifier (MGU) for Unify{King(x),
King(John)}
• Let L1 = King(x), L2 = King(John)
• Substitution θ = {John/x} is a unifier for these atoms and applying this
substitution, and both expressions will be identical.
• Example: Let's say there are two different expressions,
P(x, y), and P(a, f(z)).
• Substitute x with a, and y with f(z) in the first expression, and it will be
represented as a/x and f(z)/y.
• With both the substitutions, the first expression will be identical to the
second expression and the substitution set will be: [a/x, f(z)/y].
Conditions for Unification:
Following are some basic conditions for unification:
• Predicate symbol must be same, atoms or expression with different
predicate symbol can never be unified.
• Number of Arguments in both expressions must be identical.
• Unification will fail if there are two similar variables present in the same
expression.
• Find the MGU of {p(f(a), g(Y)) and p(X, X)}

Sol:
S0 => Here, L1 = p(f(a), g(Y)), and L2 = p(X, X)
SUBST θ= {f(a) / X}
S1 => L1 = p(f(a), g(Y)), and L2 = p(f(a), f(a))
SUBST θ= {f(a) / g(y)}, Unification failed.
Find the MGU of {p(b, X, f(g(Z))) and p(Z, f(Y), f(Y))}
• Here, L1 = p(b, X, f(g(Z))) , and L2 = p(Z, f(Y), f(Y))
S0 => { p(b, X, f(g(Z))); p(Z, f(Y), f(Y))}
SUBST θ={b/Z}
• S1 => { p(b, X, f(g(b))); p(b, f(Y), f(Y))}
SUBST θ={f(Y) /X}
• S2 => { p(b, f(Y), f(g(b))); p(b, f(Y), f(Y))}
SUBST θ= {g(b) /Y}
• S2 => { p(b, f(g(b)), f(g(b)); p(b, f(g(b)), f(g(b))}
Unified Successfully and Unifier = { b/Z, f(Y) /X , g(b) /Y}.
Question: Find the MGU of {p (X, X), and p (Z, f(Z))}

Here, L1 = {p (X, X), and L2 = p (Z, f(Z))


S0 => {p (X, X), p (Z, f(Z))}
SUBST θ= {X/Z}
S1 => {p (Z, Z), p (Z, f(Z))}
SUBST θ= {f(Z) / Z}, Unification Failed.
Algorithm: Unify(L1, L2)
1. If L1 or L2 are both variables or constants, 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. Also, Else if L2 is a variable, then if L2 occurs in L1 then return {FAIL}, else
return (L1/L2). d. Else return {FAIL}.
2. If the initial predicate symbols in L1 and L2 are not identical, then return {FAIL}.
3. If LI and L2 have a different number of arguments, then return {FAIL}.
4. Set SUBST to NIL. (At the end of this procedure, SUBST will contain all the
substitutions used to unify L1 and L2.)
5. For I ← 1 to the number of arguments in L1 :
a. Call Unify with the ith argument of L1 and the ith argument of L2, putting the
result in S.
b. If S contains FAIL then return {FAIL}.
c. If S is not equal to NIL then:
I. Apply S to the remainder of both L1 and L2.
II. SUBST: = APPEND(S, SUBST).
6. Return SUBST.
Resolution Procedure
• Resolution is a procedure, which gains its efficiency from the
fact that it operates on statements that have been converted
to a very convenient standard form.
• Resolution produces proofs by refutation.
• 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 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. Suppose that
there are two clauses in the system:
winter V summer
• ¬ winter V cold
• Now we observe that precisely one of winter and ¬ winter will be true at
any point.
• If winter is true, then cold must be true to guarantee the truth of the
second clause. If ~winter is true, then summer must be true to guarantee
the truth of the first clause.
• Thus we see that from these two clauses we can deduce summer V cold
• This is the deduction that the resolution procedure will make.
• Resolution operates by taking two clauses that each contains the same
literal, in this example, winter.
• Moreover, The literal must occur in the positive form in one clause and in
negative form in the other. The resolvent 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.
• For example, the two clauses: winter V ~winter will produce the empty
clause.
Resolution in predicate logic with Clause form
Developing a proof procedure
• Deriving (or refuting) a goal from a collection of logic facts.
• A large number of rules of inference could be utilized.
• The selection of which rules to apply and when would itself
be non-trivial.

Resolution and CNF


• Resolution is a single rule of inference that can operate
efficiently on a special form of sentences.
• The special form is called conjunctive normal form (CNF) or
clausal form, and has these properties:
– Every sentence is a disjunction (OR) of literals (clauses)
– All sentences are implicitly conjuncted (ANDed).
Predicate Logic Resolution
• We have to worry about the arguments to predicates, so it is
harder to know when two literals match and can be used by
resolution.
– For example, does the literal Father(Bill, Chelsea) match
Father(x, y) ?

The answer depends on how we substitute values for


variables.
Suppose our database contains the above statements
convert to conjunctive normal form as given above
Now prove that “Marcus hates Caesar”.
1. man(Marcus)
2. Pompeian(Marcus)
3. ∀x: Pompeian(x) → Roman(x)
4. ruler(Caesar)
5. ∀x: Roman(x) → loyalto(x, Caesar) ∨ hate(x, Caesar)
6. ∀x: ∃y: loyalto(x, y)
7. ∀x: ∀y: person(x) ∧ ruler(y) ∧ tryassassinate(x, y) →¬loyalto(x, y)
8. tryassassinate(Marcus, Caesar)
9. ∀ man(x) → person(x)
Converting to CNF
1. man(Marcus)
2. Pompeian(Marcus)
3. ~Pompeian(x) ∨ Roman(x)
4. ruler(Caesar)
5. ~Roman(x) ∨ loyalto(x, Caesar) ∨ hate(x, Caesar)
6. loyalto(x, f(x)) where y=f(x) Skolem function
7. ~person(x) ∨ ~ruler(y) ∨ ~tryassassinate(x, y) ∨ ¬loyalto(x, y)
8. tryassassinate(Marcus, Caesar)
9. ~man(x) ∨ person(x)
~Roman(x) ∨ loyalto(x, Caesar) ∨ hate(x, Caesar) Marcus/x

~Pompeian(x) ∨ Roman(x) Marcus/x

Pompeian(Marcus)
~person(x) ∨ ~ruler(y) ∨ ~tryassassinate(x, y) ∨
¬loyalto(x, y)

Marcus/x & Casear/y


By rule 9
~man(x) ∨ ~person(Marcus)
person(x)

~man(x) ∨ ~ruler(y) ∨ ~tryassassinate(x, y) 4. ruler(Caesar)

~man(x) ∨ ~tryassassinate(x, y) 1. man(Marcus)

Marcus/x & Casear/y


8. tryassassinate(Marcus, Caesar)
~tryassassinate(x, y) Conflict
Question Answering
• Theorem proving technique could be applied to the problem
of answering questions.
• Deriving theorems from axioms and deriving new facts from
old facts employ the precess of deduction.
• For example, hate(Marcus, Casear), Is Marcus alive now?
• Used Resolution technique to solve these above problems.
• Now let us use resolution technique to solve fill in the blank
questions.
• For example: when did Marcus die? i.e. died (Marcus,----)
Question Answering
• For example: when did Marcus die? i.e. died (Marcus,----)
• Solution:
∃t: died(Marcus,t)
To prove this, by resolution we need to start with
~∃t: died(Marcus,t)
In CNF, ~died(Marcus,f(t)) = ~died(Marcus,1979)
Where f(t) Skolem function and it is “what happened in 1979?”
~∃x: event(x,1979) i.e. erupted(volcano, 1779)
erupted(volcano, 1779) ∧ died(Marcus,1979)

~died(Marcus,1979) 5. ~Pompeian(x) ∨ died(x, 1779)

Marcus/x,1979/t
~Pompeian(x)
2. Pompeian(Marcus)

1. man(Marcus)
2. Pompeian(Marcus)
3. born(Marcus, 1740)
4. ∀x: man(x) → mortal(x)
5. erupted(volcano, 1779) ∧ ∀ x : [Pompeian(x) → died(x, 1779)]
6. ∀x: ∀t1: ∀t2: mortal(x) ∧ born(x, t1) ∧ gt(t2 – t1,150) → died(x, t2)
7. now = 2024
8. ∀x:∀t: [alive(x, t) → ¬ died(x, t)] ∧ [¬ died(x, t) → alive(x, t)]
9. ∀x: ∀t1: ∀t2: died(x, t1) ∧ gt(t2, t1) → died(x, t2)
Procedural Vs Declarative Knowledge
We have discussed various search techniques in previous units.
Now we would consider a set of rules that represent,
• Knowledge about relationships in the world and
• Knowledge about how to solve the problem using the content
of the rules.

Procedural Knowledge
• A representation in which the control information that is
necessary to use the knowledge is embedded in the
knowledge itself for e.g. computer programs, directions, and
recipes; these indicate specific use or implementation;
• The real difference between declarative and procedural views
of knowledge lies in where control information reside.
For example, consider the following
• Man (Marcus)
• Man (Caesar)
• Person (Cleopatra)
• ∀x: Man(x) → Person(x)
Now, try to answer the question. ∃y: Person(y)
• The knowledge base justifies any of the following answers.
– y=Marcus
– y=Caesar
– y=Cleopatra
• We get more than one value that satisfies the predicate.
• If only one value needed, then the answer to the question will
depend on the order in
• which the assertions examined during the search for a response.
• If the assertions declarative then they do not themselves say
anything about how they will be examined. In case of procedural
representation, they say how they will examine.
Declarative Knowledge
• A statement in which knowledge specified, but the use to which
that knowledge is to be put is not given.
• For example, laws, people‟s name; these are the facts which can
stand alone, not dependent on other knowledge;
• So to use declarative representation, we must have a program that
explains what is to do with the knowledge and how.
• For example, a set of logical assertions can combine with a
resolution theorem prove to give a complete program for solving
problems but in some cases, the logical assertions can view as a
program rather than data to a program.
• Hence the implication statements define the legitimate reasoning
paths and automatic assertions provide the starting points of those
paths.
• These paths define the execution paths which is similar to the “if
then else” in traditional programming.
• So logical assertions can view as a procedural representation of
knowledge.
For example, consider the following
• Man (Marcus)
• Man (Caesar)
• Person (Cleopatra)
• ∀x: Man(x) → Person(x)
– Declare x=Cleopatra
• Person (Cleopatra)
Logic Programming with PROLOG
• Logic programming is a programming paradigm in which
logical assertions viewed as programs.
• There are several logic programming systems, PROLOG is
one of them.
• A PROLOG program consists of several logical
assertions where each is a horn clause i.e. a clause with
at most one positive literal.
• Example: P, P V Q, P → Q
• The facts are represented on Horn Clause for two reasons.
– Because of a uniform representation, a simple and efficient interpreter
can write.
– The logic of Horn Clause decidable.
• Also, The first two differences are the fact that PROLOG
programs are actually sets of Horn clause that have been
transformed as follows:-
– If the Horn Clause contains no negative literal then leave it
as it is.
– Also, Otherwise rewrite the Horn clauses as an
implication, combining all of the negative literals into the
antecedent of the implications and the single positive
literal into the consequent.
For example the PROLOG clause P(x) :– Q(x, y) is equal to
logical expression ∀x: ∃y: Q (x,y) → P(x).
∀x: ∀t1: ∀t2: died(x, t1) ∧ gt(t2, t1) → died(x, t2)
PROLOG clause:- died(x, t2) :- died(x, t1) ∧ gt(t2, t1)
• Given database in PROLOG
grandson(X,Y) :- son(X,Z), parent(Y,Z)
son(charles,elizabeth)
parent(george,elizabeth)
• In query mode we might ask
?- grandson(elizabeth,charles).
• Ans: no

• ?- grandson(W,george) with W = charles { W/X, george/Y }.


• Ans: yes
• dbase statement 3 does this with no unification. The system
returns the overall unification for W which is (W/X/charles), ie
(W/charles)
Consider the following example:
Logical representation
• ∀x : pet(x) ∧ small (x) → apartmentpet(x)
• ∀x : cat(x) ∨ dog(x) → pet(x)
• ∀x : poodle (x) → dog (x) ∧ small (x)
• poodle (fluffy)
PROLOG representation
• apartmentpet(x) : pet(x), small (x)
• pet (x): cat (x)
• pet (x): dog(x)
• dog(x): poodle (x)
• small (x): poodle(x)
• poodle (fluffy)
Forward Vs Backward Reasoning and combining them
• A search procedure must find a path between initial and goal states.
• There are two directions in which a search process could proceed.
• The two types of search are:
1. Forward search which starts from the start state
2. Backward search that starts from the goal state
• The production system views the forward and backward as symmetric
processes.
• Consider a game of playing 8 puzzles. The rules defined are
We can solve the problem following two ways:
1. Forward search which starts from the start state
Step 1. Begin building a tree of move sequences by starting with the initial
configuration at the root of the tree.
Step 2. Generate the next level of the tree by finding all rules whose left-
hand side matches the root node. The right-hand side is used to create new
configurations.
Step 3. Generate the next level by considering the nodes in the previous
level and applying it to all rules whose left-hand side match.
Given Knowledge Base
Knowledge base contains the combination of rules and facts about the user
profile.
• John‟s credit score is 780.
• A person with a credit score greater than 700 has never defaulted on
their loan.
• John has an annual income of $100,000.
• A person with a credit score greater than 750 is a low-risk borrower.
• A person with a credit score between 600 to 750 is a medium-risk
borrower.
• A person with a credit score less than 600 is a high-risk borrower.
• A low-risk borrower can be given a loan amount up to 4X of his annual
income at a 10 percent interest rate.
• A medium-risk borrower can be given a loan amount of up to 3X of his
annual income at a 12 percent interest rate.
• A high-risk borrower can be given a loan amount of up to 1X of his
annual income at a 16 percent interest rate.
• Based on that knowledge base, let‟s look at the questions we will want to
resolve using forward chaining.
Question
Next, we‟ll seek to find answers to two questions:
• What max loan amount can be sanctioned for John?
• What will the interest rate be?
John‟ CS = 780 AND CS > 750 are Low Risk Borrower → John is a
Low Risk Borrower

• Loan Amount for Low Risk Borrower is 4X annual income AND


John‟s annual income is $100k

• Max loan amount that can be sanctioned is $400k at a 10%


interest rate.
2. Reasoning backward from the goal states:
Step 1. Begin building a tree of move sequences by starting with the goal
node configuration at the root of the tree.
Step 2. Generate the next level of the tree by finding all rules whose right-
hand side matches the root node. The left-hand side used to create new
configurations.
Step 3. Generate the next level by considering the nodes in the previous
level and applying it to all rules whose right-hand side match.
So, The same rules can use in both cases.
Also, In forwarding reasoning, the left-hand sides of the rules matched
against the current state and right sides used to generate the new state.
Moreover, In backward reasoning, the right-hand sides of the rules matched
against the current state and left sides are used to generate the new state.
Knowledge Base
We have few facts and rules that constitute our knowledge base:
1. John is taller than Kim
2. John is a boy
3. Kim is a girl
4. John and Kim study in the same class
5. Everyone else other than John in the class is shorter than Kim

Question
We‟ll seek to answer the question:
• Is John the tallest boy in class?
Result
Now, to apply backward chaining, we start from the goal and assume that
John is the tallest boy in class. From there, we go backward through the
knowledge base comparing that assumption to each known fact to determine
whether it is true that John is the tallest boy in class or not.
Our goal:
• John is the tallest boy in the class
Which means:
Height (John) > Height (anyone in the class)
AND
John and Kim both are in the same class Rule-4
AND
Height (Kim) > Height (anyone in the class except John)
Rule-5: Everyone else other than John in the class is shorter than Kim
SO Height (John) > Hight(Kim)

Which aligns with the knowledge base fact.


Hence the goal is proved true.
There are four factors influencing the type of reasoning. They
are,
1. Are there more possible start or goal state?
We move from smaller set of sets to the length.
2. In what direction is the branching factor greater?
We proceed in the direction with the lower branching factor.
3. Will the program be asked to justify its reasoning process to
a user?
If, so then it is selected since it is very close to the way in
which the user thinks.
4. What kind of event is going to trigger a problem-solving
episode?
If it is the arrival of a new factor, the forward reasoning
makes sense. If it is a query to which a response is desired,
backward reasoning is more natural.
Forward versus Backward Reasoning
• It is easier to drive from an unfamiliar place from home, rather
than from home to an unfamiliar place. Also, If you consider a
home as starting place an unfamiliar place as a goal then we
have to backtrack from unfamiliar place to home.
Forward versus Backward Reasoning
• PROLOG is an example of backward chaining rule system. In
PROLOG rules restricted to Horn clauses. This allows for
rapid indexing because all the rules for deducing a given fact
share the same rule head. Rules matched with unification
procedure. Unification tries to find a set of bindings for
variables to equate a sub-goal with the head of some rule.
Rules in the PROLOG program matched in the order in which
they appear.
Matching Techniques
• Search techniques uses appropriate rules to solve problems
to individual problems.
• Clever search algorithms involves choosing from among the
rules that can be applied at a particular point, that most likely
to lead to a solution.
• How to extract one from the collection of rules?
• So, some kind matching techniques required to select a rule
based on the current state.
• Let us discuss few proposals:
• Indexing
• A simple search through all the rules
• Compare each one‟s preconditions to the current state and
extract the one that matches
• problems with this method
– Scanning through all the rules step by step of the search is
inefficient method.
• Use indexing technique to deal with problems
• Instead searching all the rules, use the current state as an
index into the rules and select the matching ones immediately
as mentioned in previous slide.
• Any good hashing function can be used to treat that number
as an index into the rules.
• In PROLOG, rules are indexed by the predicates they
contain.
• All the rules that could be applicable to prove a fact can be
accessed quickly.
• In chess, rules can be indexed by pieces and their positions.
• Matching with variables
son(X,Z) ∧ parent(Y,Z) → grandson(X,Y)
son(x,y) ∧ son(y,z) → grandparent(x,z)
son(charles,elizabeth)
parent(george,elizabeth)
son(marry,joy)
son(bill,bob)
RETE Algorithm
• The Rete algorithm is a pattern matching algorithm in artificial intelligence
(AI) that's used to efficiently compare a large number of patterns to a large
number of objects
• The Rete algorithm organizes data into a tree-like structure and tests it
against conditions until a terminal node is reached. It creates activation
records for true rules.
• The Rete algorithm is a key component of modern AI systems because it's
designed to handle large amounts of data and complex rule
combinations. It's used in AI applications that require pattern matching,
such as data mining, text classification, and image recognition.
Features
• Node sharing: Reduces or eliminates redundancy by sharing nodes
• Partial matches: Stores partial matches when joining different fact types
• Efficient removal of memory elements: Allows for efficient removal of
memory elements when facts are retracted from working memory
RETE
• Example node
If age>60 or age<5 or
income<36000, then price
will be charged 50%
Type-1 Type-2

income<3
age>60 age<5
6000

α1 α2 α3
age>60 or
age<5 α-β pruning

β1 age>60 or age<5
or income<36000
β2
price will be
charged 50%
Terminal Node
Conflict resolutions
• The result of the matching process is a list of rules whose
past history have matched the current state description along
with whatever variable bindings were generated by the
matching process
• it is the job of search method to decide on the order in which
rules will be applied.
• Sometimes matching process is incorporated along with the
decision making to decide a rule and that phase is called
conflict resolution.
• There are three approaches to the problem conflict resolution
in a production system
– Preference based on the rule that matched
– Preference based on the objects that matched
– Preference based on the action that matched
Preference based on the rule that matched
• Two common ways of assigning a preference based on the rules
• The first and simplest form is
– consider the rules specified in particular order they are presented.
– Priority is given to the rules in the order in which they appear.
– This scheme is used in PROLOG

• The second form is


– Give priority to special case rules over general rules
– Purpose is to allow experts to solve the problems directly, without
search.
– The addition of such rules will increase the size of the rule set.
– So need to build a matcher to reject such rules that are more general
– Process to reject general rules as follows
1. If the set of preconditions of one rule contains all the preconditions of
other, then second rule is more general and reject it
2. If the set of preconditions of one rule are the same as of those
another except that in the first case variables are specified i.e.
constants, then first rule is more general
Capacity of one jug is P
Production rules for the problem Capacity of second jug is Q
Rule No. Rule Result Description
1 X,Y – X<P (P, Y) Fill first jug
2 X,Y – X>0 (0, Y) Empty first jug
3 X,Y – Y<P (X, Q) Fill second jug
4 X,Y – Y>0 (X, 0) Empty second jug
Pour water from second jug into
5 X+Y <= P and Y > 0 (X+Y, 0)
first jug
Pour water from first jug into
6 X+Y <= Q and X > 0 (0, X+Y)
second jug
Pour water from second jug into
7 X<P and X+Y >= P and Y > 0 (P, Y-(P-X)
first jug until first jug is full
Pour water from first jug into
8 Y<Q and X+Y >= Q and X > 0 (X-(Q-Y), Q) second jug until second jug is
full
Pour water from 2L from second
9/5 (X,Y) where X=0,Y=2 (2,0) jug into first jug until second jug
is empty
Empty 2L water of first jug on
10/2 (X,Y) where X=2 (0, Y)
the ground
Preference based on the objects that matched
• This approach involves giving priority to the object (data,
entity, etc.) that the rule is applied to. Depending on the
characteristics or properties of the matched object, priority is
assigned.
• EXAMPLE
• Consider ELIZA, which matched patterns against a user‟s
sentence to find a rule to generate a reply.
• Patterns can be identified for specific combinations important
keywords.
• “I know everybody laughed at me” and “you say you know
everybody laughed at you”
• The keywords such as „I‟ and „everybody‟ ELIZ should know it
in more semantically significant and thus to which it should
respond.
Preference based on the action that matched
• This approach involves considering the action or operation
that each rule would perform. The rule with the action that is
deemed more critical or appropriate in the given context is
given higher priority.
• Trigger all rules waiting for.
• Examine the results of each state
• Use a heuristic function to evaluate each of the resulting
states.
• Compare the merits of the results and select the preferred
one and leave the others.
• This approach is like best-first search method and can be
categorized as conflict resolution strategy.

You might also like