0% found this document useful (0 votes)
73 views66 pages

SMAI-Deduction-as-Search-full

This document discusses search methods in artificial intelligence. It covers how an autonomous agent operating in a dynamic world needs to represent knowledge about its environment and make inferences to achieve its goals. Different types of logical reasoning are discussed, including deduction using rules of inference like modus ponens and modus tollens in classical logic. The document provides examples of knowledge representation using a symbolic logic approach.

Uploaded by

mathspix416
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)
73 views66 pages

SMAI-Deduction-as-Search-full

This document discusses search methods in artificial intelligence. It covers how an autonomous agent operating in a dynamic world needs to represent knowledge about its environment and make inferences to achieve its goals. Different types of logical reasoning are discussed, including deduction using rules of inference like modus ponens and modus tollens in classical logic. The document provides examples of knowledge representation using a symbolic logic approach.

Uploaded by

mathspix416
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/ 66

Search Methods in Artificial Intelligence

Deduction as Search
First Order Logic
A First Course in Artificial Intelligence: Chapter 11

Deepak Khemani
Plaksha University

Search Methods in Artificial Intelligence Deepak Khemani, Plaksha University


What do you know?

An autonomous agent

operating in a dynamic world

creates a representation of the world

senses the world around it

makes plans to achieve its goals

monitors the execution of those plans

and constantly updates what it knows

Search Methods in Artificial Intelligence Deepak Khemani, Plaksha University


What else do you know?
An autonomous agent
operating in a dynamic world

...needs to make inferences about its world

This week,
Representation and Reasoning in Logic

Another string in the bow of a problem solving agent

Search Methods in Artificial Intelligence Deepak Khemani, Plaksha University


Knowledge and Reasoning – necessary for intelligence

What does the agent know


and
what else does the agent know as
a consequence of what it knows?

A preview of the course


Knowledge Representation & Reasoning

Search Methods in Artificial Intelligence Deepak Khemani, Plaksha University


The Greek Syllogism

Given
All men are mortal
and
Socrates is a man
conclude
Socrates is mortal

The Socratic Argument

Search Methods in Artificial Intelligence Deepak Khemani, Plaksha University


What else do you know? Possibly true
Sneha loves Snigdha
True / Given Necessarily true Snigdha loves Sneha
Snigdha loves idli-sambhar
Snigdha’s mother is Sneha Snigdha is Sneha’s daughter
Snigdha goes to school
Snigdha’s father is Salil Snigdha is Sameer’s sister
Arushi is older than Salil
Sameer’s mother is Sneha Snigdha is Arushi’s niece
Snigdha is a Arnav’s friend
Sameer’s father is Salil •
Arnav has Covid
Salil’s sister is Arushi •

Arnav’s mother is Arushi Salil is not Arushi’s sister

Arnav tested positive for Covid Salil is not Sneha’s sister
Arushi is not Sneha’s daughter
+ •
Knowledge of gender •
and relationships There exists a woman who is
Snigdha and Arnav’s grandma

Search Methods in Artificial Intelligence Deepak Khemani, Plaksha University


Deduction: The Goal
Goal α

KB

Given a knowledge base (KB)


which is set of sentences assumed to be true,

is a given (query) sentence α necessarily true?


Search Methods in Artificial Intelligence Deepak Khemani, Plaksha University
Representation

Semiotics: A symbol is something that stands for something else


Examples:
• The “number” seven can be represented in many different ways.
• Road signs – curves, pedestrians, schools, U-turns, eating places…

All languages are semiotic systems

Biosemiotics: How complex behaviour


emerges when simple systems
interact with each other through signs

Search Methods in Artificial Intelligence Deepak Khemani, Plaksha University


Reasoning
The manipulation of symbols in a meaningful manner.
- we can only manipulate symbols
- the meaning or truth value is in only our minds

Maths is replete with algorithms we use –


• Addition and multiplication of multi-digit numbers
• Long division
• Solving systems of linear equations
• Fourier transforms, convolution…

Search Methods in Artificial Intelligence Deepak Khemani, Plaksha University


The Syllogism
The Greek syllogism embodies the notion of formal logic
An argument is valid if it conforms to a valid form

All men are mortal All cities are congested All politicians are honest
Socrates is a man Chennai is a city Sambit is a politician
Socrates is mortal Chennai is congested Sambit is honest

All Xs are Y
If premises are true
C is X
Then conclusion is true
C is Y

Search Methods in Artificial Intelligence Deepak Khemani, Plaksha University


Formal Logic

Logic is a formal system


Logical reasoning is only concerned ONLY with the FORM
of the argument, and not with CONTENT.
If the form is valid AND If the antecedents are true
THEN the conclusion is true.
Thus, the conclusion holds only if the antecedents are true.
Logic does not concern itself with the truth of antecedents
OR
what the sentences are talking about (content).

Search Methods in Artificial Intelligence Deepak Khemani, Plaksha University


Logics Event Calculus /
Situation Calculus
Epistemic Logics
Classical two valued logics Default Logics
Temporal Logics
Second Order Logic Probabilistic reasoning
Modal Logics
First Order Logic
Propositional Logic Horn Clauses

Description Logics
Fuzzy logics Constraint logic programming

Rough sets Qualitative reasoning

Search Methods in Artificial Intelligence Deepak Khemani, Plaksha University


Classical Logics
• Mathematical Logic
• Once a statement is true it remains true
– for example the Pythagoras Theorem
– no notion of time, events, or statements becoming false
• The RHS of a rule has only ADD actions

• Non-monotonic logics
– Fluents: sentences which can flip their truth value
– Knowledge and Belief
– Default Reasoning
– Inheritance

Knowledge Representation and Reasoning


Search Methods in Artificial Intelligence Deepak Khemani, Plaksha University
Rules of Inference p rule
pattern 1
Rules of inference in logic are similar to the rules in pattern 2
production systems .
.
In classical logic the RHS of a rule has only one action à
- add a new sentence actions...
- to the knowledge base (KB)

In logic the rules are viewed as


Premises à Conclusion
or Antecedents à Consequent

Rules do have names


but the names are not used directly
Search Methods in Artificial Intelligence Deepak Khemani, Plaksha University
Some common rules of inference
From α⊃β From α⊃β From α From (α ⊃ β) ∧ (γ ⊃ δ)

and α . and ∼β . and β . and α∨γ .

Infer β Infer ∼α Infer α∧β Infer β∨ δ

Modus Ponens (MP) Modus Tollens (MT) Conjunction (C) Constructive Dilemma (CD)

From α . From α∧β. From (α ⊃ β) ∧ (γ ⊃ δ)


Infer α∨ β Infer α and ∼β ∨ ∼δ .
Addition (A) Simplification (S) Infer ∼α ∨ ∼γ
Destructive Dilemma (DD)
From α⊃β From α∨β
and β⊃γ and ∼α .
Infer α⊃γ Infer β
Hypothetical Disjuncuntive
Syllogism (HS) Syllogism (DS)

Search Methods in Artificial Intelligence Deepak Khemani, Plaksha University


MoveGen in Logical Reasoning KB: A set of sentences in
some language

Pattern: A subset of the


sentences

Augmenting the KB in a
piecewise fashion

Move: Pattern à Inference


Premises à Consequent

Search Methods in Artificial Intelligence Deepak Khemani, Plaksha University


Rules of Substitution
A rule of substitution allows one to replace one sentence with another. This
is possible when one sentence is logically equivalent to another. For
example
((α⊃β) ≡ (¬α∨β))

If the above equivalence is a tautology, then the sentence (α⊃β) will always
take the same truth value as the sentence (¬α∨β). We can verify that the
equivalence is a tautology by constructing a truth table.

α β (α ⊃ β) ¬α (¬α∨β) ((α⊃β) ≡ (¬α∨β))


true true true false true true
false true true true true true
true false false false false true
false false true true true true

Search Methods in Artificial Intelligence Deepak Khemani, Plaksha University


Common rules of substitution
α ≡ (α ∨ α) idempotence of ∨ (α ∨ true) ≡ true
α ≡ (α ∧ α) idempotence of ∧ (α ∨ false) ≡ α
(α ∨ β) ≡ (β ∨ α) commutativity of ∨ (α ∧ true) ≡ α
(α ∧ β) ≡ (β ∧ α) commutativity of ∧ (α ∧ false) ≡ false
((α ∨ β) ∨ γ) ≡ (α ∨ (β ∨ γ)) associativity of ∨ (α ∧ ¬α) ≡ false
((α ∧ β) ∧ γ) ≡ (α ∧ (β ∧ γ)) associativity of ∧ (α ∨ ¬α) ≡ true
¬(α ∨ β) ≡ (¬α ∧ ¬β) DeMorgan’s Law α ≡ ¬(¬α)
¬(α ∧ β) ≡ (¬α ∨¬β) DeMorgan’s Law
(α ∧ (β ∨ γ)) ≡ ((α ∧ β) ∨ (α ∧ γ)) distributivity of ∧ over ∨
(α ∨ (β ∧ γ)) ≡ ((α ∨ β) ∧ (α ∨ γ)) distributivity of ∨ over ∧
(α ⊃ β) ≡ (¬β ⊃ ¬α) contrapositive
(α ⊃ β) ≡ (¬α ∨ β) implication
(α ≡ β) ≡ ((α ⊃ β) ∧ (β ⊃ α)) equivalence
((α ∧ β) ⊃ γ) ≡ (α ⊃ (β ⊃ γ)) exportation
((α ⊃ β) ∧ (α ⊃ ¬β)) ≡ ¬α absurdity

Search Methods in Artificial Intelligence Deepak Khemani, Plaksha University


Deduction: Proof
Goal α

KB

Applications of rules of inference

Provability: KB ⊢ α
Search Methods in Artificial Intelligence Deepak Khemani, Plaksha University
Finding Proofs
The proof is the end product,
that is a justification of the sentence α being true

It represents a chain of inferences linking


the given facts
to the desired goal

Proofs are found by a process of search


Remember the 4-colour theorem?

The irrelevant inferences are discarded


and only the final proof remains

Search Methods in Artificial Intelligence Deepak Khemani, Plaksha University


Forward Reasoning
A data driven chain of inferences
From facts to goals

Forward Chaining
Pick a rule with matching facts
Add the consequent to the KB
Till the goal is added to the KB

The key question is


which rule and what facts?

Search Methods in Artificial Intelligence Deepak Khemani, Plaksha University


Logic: Semantics Denotation: What does a sentence stand for?
Truth Functional: Is the sentence true?

Axioms / Premises (KB): Assumed to be true.


KB is true iff every sentence in the KB is true.

Entailment: A sentence α is said to be entailed by a set of sentences


S/KB if the sentence is necessarily true whenever S/KB is true

KB ⊨ α
We also say that α is true (given the KB)

Search Methods in Artificial Intelligence Deepak Khemani, Plaksha University


The set of true statements

KB

The set of sentences


entailed by the KB

Search Methods in Artificial Intelligence Deepak Khemani, Plaksha University


Soundness and Completeness
Given a knowledge base and a reasoning algorithm –

Entailment: which other sentences in the language are necessarily true?

Proof: which other sentences in the language can one produce by the
reasoning algorithm?

Soundness (of the reasoning algorithm):


A logic is sound
if only true statements in the language can be proved

Completeness (of the reasoning algorithm):


A logic is complete
if all true statements in the language can be proved

Search Methods in Artificial Intelligence Deepak Khemani, Plaksha University


Soundness and Completeness
The provable statements
….
The set of sentences
entailed by the KB

Search Methods in Artificial Intelligence Deepak Khemani, Plaksha University


First Order Logic (FOL): Syntax
The logical part of the vocabulary
• Symbols that stand for connectives or operators
– “∧”, “∨”, “~” (or “¬”), “⊃” (or “⟶” or “⟹”)…
• Brackets “(“, “)”, “{“, “}”…
• The constant symbols “⊥” and “⊤”.
• A set of variable symbols V = {v1, v2, v3, … }
– commonly used {x, y, z, x1, y1, z1, …}
•Quantifiers: “"” read as “for all”, and “$” read as “there exists”.
The former is the universal quantifier
and the latter the existential quantifier.
• The symbol “=” read as “equals”.

Search Methods in Artificial Intelligence Deepak Khemani, Plaksha University


FOL Syntax (contd)
The non-logical part of FOL vocabulary constitutes of three sets.

• A set of predicate symbols P = {P1, P2, P3, …}. We also use the symbols
{P, Q, R, …}. More commonly we use words like “Man”, “Mortal”,
“GreaterThan”. Each symbol has an arity associated with it.
• A set of function symbols F = {f1, f2, f3, …}. We commonly used the
symbols {f, g, h…} or words like “Successor” and “Sum”. Each function
symbol has an arity that denotes the number of argument it takes.
• A set of constant symbols C = {c1, c2, c3, …}. We often used symbols like
“0”, or “Socrates”, or “Darjeeling” that are meaningful to us.

The three sets define a specific language L(P,F,C).

Search Methods in Artificial Intelligence Deepak Khemani, Plaksha University


Terms of L(P,F,C)
The basic constituents of FOL expressions are terms. The set of terms ℑ of
L(P,F,C) is defined as follows. The constants and the variables are terms by
definition. More terms are defined using the function symbols.

If t ∈ V then t ∈ ℑ
If t ∈ C then t ∈ ℑ
If t1, t2, …, tn ∈ ℑ and f ∈ F is an n-place function symbol
then f(t1,t2, …,tn) ∈ ℑ

Search Methods in Artificial Intelligence Deepak Khemani, Plaksha University


Atomic Formulas of L(P,F,C)
The set of formulas is defined using terms and predicate symbols. By default
the logical symbols “⊥” and “⊤” are also formulas. The set of well formed
formulas F of L(P,F,C) is defined as follows.
Atomic formulas A
⊥∈A
⊤∈A
If t1, t2 ∈ ℑ then (t1=t2) ∈ A
If t1, t2, …, tn∈ ℑ and
P ∈ P is an n-place predicate symbol
then P(t1,t2,…,tn) ∈ A
Search Methods in Artificial Intelligence Deepak Khemani, Plaksha University
Formulas of L(P,F,C)

The set of formulas of L(P,F,C) ℱ is defined as follows


If α ∈ A then α ∈ ℱ
If α ∈ ℱ then ~α ∈ ℱ
If α, β ∈ ℱ then (α∧β) ∈ ℱ
If α, β ∈ ℱ then (α∨β) ∈ ℱ
If α, β ∈ ℱ then (α⊃β) ∈ ℱ

Search Methods in Artificial Intelligence Deepak Khemani, Plaksha University


Universal and Existential Quantifiers
If α ∈ ℱ and x ∈ V then "x (α) ∈ ℱ
"x (α) is read as “for all x (α)”
If α ∈ ℱ and x ∈ V then $x (α) ∈ ℱ
$x (α) is read as “there exists x (α)”

We will also use the notation (forall (x) (α)) and (exists (x) (α)) as given in
the book Artificial Intelligence by Eugene Charniak and Drew McDermott.
Makes representation for use in programs simpler.

Search Methods in Artificial Intelligence Deepak Khemani, Plaksha University


List notation
Standard mathematical notation
1. "x (Man(x) É Human(x)) : all men are human beings
2. Happy(suresh) Ú Rich(suresh) : Suresh is rich or happy
3. "x (CitrusFruit(x) É ¬Human(x)) : all citrus fruits are non-human
4. $x (Man(x) Ù Bright(x)) : some men are bright

List notation (a la Charniak & McDermott, “Artificial Intelligence”)


1.(forall (x) (if (man x) (human x)))
2.(or (happy suresh) (rich suresh))
3.(forall (x) (if (citrusFruit x) (not (human x))))
4.(exists (x) (and (man x) (bright x)))

Search Methods in Artificial Intelligence Deepak Khemani, Plaksha University


FOL: Rules of Inference
The propositional logic rules we saw earlier are valid in FOL as well. In addition we need
new rules to handle quantified statements. The two commonly used rules of inference are,
"x P(x) where a ∈ C Universal Instantiation (UI)
P(a)

P(a) where a ∈ C Generalization


$x P(x)
Examples:
"x (Man(x) ⊃ Mortal(x))
(Man(Socrates) ⊃ Mortal(Socrates))

(Man(Socrates) ⊃ Mortal(Socrates))
$x (Man(x) ⊃ Mortal(x))

Search Methods in Artificial Intelligence Deepak Khemani, Plaksha University


Semantics (Propositional Logic)
Atomic sentences in Propositional Logic can stand for anything. Consider,
Alice likes mathematics and she likes stories. If she likes mathematics she likes algebra. If
she likes algebra and likes physics she will go to college. She does not like stories or she
likes physics. She does not like chemistry and history.
Encoding: P = Alice likes mathematics. Q = Alice likes stories. R = Alice likes algebra. S =
Alice likes physics. T = Alice will go to college. U = Alice likes chemistry. V = Alice likes
history.
Then the given facts are, (P ∧ Q)
(P ⊃ R)
((R∧ S) ⊃ T)
If the above sentences are
true is it necessarily true that (~Q ∨ S)
“Alice will go to college”? (~U ∧ ~V)
That is “ Is T true?”

Search Methods in Artificial Intelligence Deepak Khemani, Plaksha University


Proofs in Propositional Logic
1. (P ∧ Q) premise Alice likes mathematics and she likes stories.
2. (P ⊃ R) premise If she likes mathematics she likes algebra.
3. ((R∧ S) ⊃ T) premise If she likes algebra and likes physics she will go to college.
4. (¬Q ∨ S) premise She does not like stories or she likes physics.
5. P 1, simplification
6. Q 1, simplification
7. R 2, 5, modus ponens
8. S 4, 6, disjunctive syllogism
9. (R∧ S) 7, 8, conjunction
10. T 3, 9, modus ponens

Search Methods in Artificial Intelligence Deepak Khemani, Plaksha University


The First Order version
Let us rephrase our example (Alice) problem in first order terminology.
• Alice likes mathematics and she likes stories.
• If someone likes mathematics she likes algebra[1].
• If someone likes algebra and likes physics she will go to college.
• Alice does not like stories or she likes physics.
• Alice does not like chemistry and history.”

We can formalize the statements in FOL as follows.


1. likes(Alice, Math) ∧ likes(Alice, stories)
2. ∀x(likes(x, Math) ⊃ likes(x, Algebra))
3. ∀x((likes(x, Algebra) ∧ likes(x, Physics)) ⊃ goesTo(x, College))
4. ¬likes(Alice, stories) ∨ likes(Alice, Physics)
5. ¬likes(Alice, Chemistry) ∧ ¬likes(Alice, History)
[1] Here we must emphasize that she stands for both she and he.

Search Methods in Artificial Intelligence Deepak Khemani, Plaksha University


The FOL Proof
1. likes(Alice, Math) ∧ likes(Alice, stories)
2. ∀x(likes(x, Math) ⊃ likes(x, Algebra))
3. ∀x((likes(x, Algebra) ∧ likes(x, Physics)) ⊃ goesTo(x, College))
4. ¬likes(Alice, stories) ∨ likes(Alice, Physics)
5. ¬likes(Alice, Chemistry) ∧ ¬likes(Alice, History)
We can now generate a proof that is analogous to the proof in propositional logic.
6. likes(Alice, Math) 1, simplification
7. likes(Alice, stories) 1, simplification
8. (likes(Alice, Math) ⊃ likes(Alice, Algebra)) 2, UI
9. likes(Alice, Algebra)) 6, 8, modus ponens
10. likes(Alice, Physics) 4, 7, disjunctive syllogism
11. ((likes(Alice, Algebra) ∧ likes(Alice,Physics)) 9, 10, conjunction
12. ((likes(Alice, Algebra) ∧ likes(Alice,Physics))
⊃ goesTo(Alice,College)) 3, UI
6. goesTo(Alice, College) 12, 11, modus ponens

Search Methods in Artificial Intelligence Deepak Khemani, Plaksha University


Forward Chaining in FOL

"x (P(x) ⊃ Q(x))


UI

P(a) ⊃ Q(a)

MP
P(a) Q(a)

Forward chaining in FOL is a two step process.


The use of Implicit Quantifier Notation
collapses this two step inference into one.

Search Methods in Artificial Intelligence Deepak Khemani, Plaksha University


The Greek Syllogism Forward Chaining
in First Order Logic
Given
All men are mortal ∀x(Man(x) ⊃ Mortal(x))
and
Socrates is a man Man(Socrates)

conclude
Socrates is mortal Mortal(Socrates)

The Socratic Argument


Search Methods in Artificial Intelligence Deepak Khemani, Plaksha University
Implicit Quantifier notation
Prefix universally quantified variables with a “?”. Replace existentially quantified
variables not in the scope of a universal quantified with a Skolem constant (named
after the mathematician Thoralf Skolem)
1. Man(?x) É Human(?x) : all men are human beings
2. Happy(suresh) Ú Rich(suresh) : Suresh is rich or happy
3. CitrusFruit(?x) É ¬Human(?x) : all citrus fruits are non-human
4. Man(sk-11) Ù Bright(sk-11)) : some men are bright

List notation
1. (if (man ?x) (human ?x))
2. (or (happy suresh) (rich suresh))
3. (if (citrusFruit ?x) (not (human ?x)))
4. (and (man sk-11) (bright sk-11))

Search Methods in Artificial Intelligence Deepak Khemani, Plaksha University


Unifier: Substitution

A substitution q is a set of <variable value> pairs each


denoting the value to be substituted for the variable.
A unifier for two formulas α and β is a substitution that makes
the two formulas identical. We say that α unifies with β. A
unifier q unifies a set of formulas {α1, α2, …, αN} if,
α1q = α2q = … = αNq = φ

Search Methods in Artificial Intelligence Deepak Khemani, Plaksha University


Modified Modus Ponens (MMP)
MPP: From (a É g) and b infer gq where q is a unifier* for a and b and gq is
the formula obtained by applying the substitution q to g.
For example,

MMP P(?x) ⊃ Q(?x)

q = {<?x, a>}
P(a) Q(a)

*A substitution q is a unifier for two (or more)


formulas a and b if when applied it makes the
two formulas identical. That is, aq =bq

Search Methods in Artificial Intelligence Deepak Khemani, Plaksha University


MPP: an example

Thus if
α = (Sport(tennis) ∧ Likes(Alice, tennis))
β⊃δ = (Sport(?y) ∧ Likes(?x, ?y)) ⊃ Watches(?x, ?y)

then α unifies with β


with the substitution θ = {<?x, Alice>, <?y, tennis>}
and one can infer
δθ = Watches(?x, ?y)θ = Watches(Alice, tennis)

Search Methods in Artificial Intelligence Deepak Khemani, Plaksha University


Modified Modus Ponens (MMP) From α
and β .
(P(?x,?y) ∧ R(?y)) ⊃ Q(?x)
Q(a) Infer α∧β
P(a,?z) ∧ R(?z) Conjunction (C)

q = {<?x, a>, <?y,?z>}


P(a,?z) R(?z)

Bypassing Conjunction
P(?x,?y) ∧ R(?y)

(P(?x,?y) ∧ R(?y)) ⊃ Q(?x)


P(a,?z) Q(a)

R(?z) q = {<?x, a>, <?y,?z>}


Search Methods in Artificial Intelligence Deepak Khemani, Plaksha University
A shorter proof with Modified Modus Ponens

1. likes(Alice, Math) ∧ likes(Alice, stories)


2. likes(?x, Math) ⊃ likes(?x, Algebra)
3. (likes(?x, Algebra) ∧ likes(?x, Physics)) ⊃ goesTo(?x, College)
4. ¬likes(Alice, stories) ∨ likes(Alice, Physics)
5. ¬likes(Alice, Chemistry) ∧ ¬likes(Alice, History)

6. likes(Alice, Math) 1, simplification


7. likes(Alice, stories) 1, simplification
8. likes(Alice, Algebra) 6, 2, MPP
9. likes(Alice, Physics) 4, 7, disjunctive syllogism
10. goesTo(Alice, College) 3, 8, 9, MPP

Search Methods in Artificial Intelligence Deepak Khemani, Plaksha University


Backward Chaining
We move from the goal to be proved towards facts.
From (a É g) and Goal:b infer Goal:aq where q is a unifier for g and b and
aq is the formula obtained by applying the substitution q to a.

For example,
P(?x) ⊃ Q(?x)

q = {<?x, a>}
P(a) Goal: P(a) Goal: Q(a)

A goal is said to be solved if it matches a fact in the KB.

Search Methods in Artificial Intelligence Deepak Khemani, Plaksha University


Backward Chaining and Modus Tollens
P(?x) ⊃ Q(?x)

q = {<?x, a>}
P(a) Goal: P(a) Goal: Q(a)
Backward Chaining

⊥ Proof by Contradiction Assume ¬Q(a)

Forward Chaining
¬P(a) ¬Q(a)

Modus Ponens Modus Tollens

¬Q(?x) ⊃ ¬P(?x) ≡ P(?x) ⊃ Q(?x)

Search Methods in Artificial Intelligence Deepak Khemani, Plaksha University


Backward Reasoning

• Backward reasoning is goal directed


• We only look for rules for which the
consequent matches the goal.
• This results in low branching factor in the
search tree
– which rule to apply from the matching set of rules?
• Foundations of Logic Programming
– the programming language Prolog

Search Methods in Artificial Intelligence Deepak Khemani, Plaksha University


Deductive Retrieval
The goal need not be a specific proposition
It can be have variables as well
Formulas with variables can match facts.
For example
Goal: Mortal(?z)
can be interpreted as an existential statement

Is (there a z such that) $z Mortal(z) true?


The answer, in addition to yes or no,
can also return a value for the variable
for which it is true.

Search Methods in Artificial Intelligence Deepak Khemani, Plaksha University


Deductive Retrieval: Multiple Answers
q = {<?z, Plato>} Substitute variable Z with Plato
Man(Plato) Man(?x) ⊃ Mortal(?x)

q = {<?z, Socrates>}
q = {<?x, ?z>}
Man(Socrates) Goal: Man(?z) Goal: Mortal(?z)

Substitute variable X with variable Z

Man(Aristotle)
q = {<?z, Aristotle>}

Search Methods in Artificial Intelligence Deepak Khemani, Plaksha University


Backward Chaining (Propositional Logic)
Alice likes mathematics (P) and she likes stories (Q). If she likes mathematics (P) she likes algebra (R). If
she likes algebra (R) and likes physics (S) she will go to college (T). She does not like stories (Q) or she
likes physics (S). She does not like chemistry (U) and history (V).

Then the given facts are, (P ∧ Q), (P ⊃ R), ((R ∧ S) ⊃ T), (~Q ∨ S), (~U ∧ ~V)

Equivalently Goal Set “Is T true?”


1.P We answer this by
2.Q {T} Given goal backward chaining.
3.(P ⊃ R) {R, S} from 4
4.((R ∧ S) ⊃ T) {P, S} from 3
5.(Q ⊃ S) {S} matches 1
6.~U {Q} from 5
7.~V {} matches 2, success
Search Methods in Artificial Intelligence Deepak Khemani, Plaksha University
Backward Chaining with Conjunctive Antecedents
A goal (R ?x) and a rule (if (and (P ?x) (Q ?x)) (R ?x))

A goal which matches the consequent of a rule reduces


to the antecedents in the rule.
An AND node
To solve R (R ?x)
{(R ?x)} solve both P & Q

{(P ?x), (Q ?x)}

(P ?x) (Q ?x)

Search Methods in Artificial Intelligence Deepak Khemani, Plaksha University


Goal Trees
Consider the following KB in skolemized list notation, and the goal (niceToy ?z)

Rule1: (if (and (green ?x) (circle ?x)) (niceToy ?x))


Rule2: (if (and (red ?x) (square ?x)) (niceToy ?x))
(green A) Properties of named objects
(green B)
(circle C) Is there a Z that is a nice toy?
(red C)
(red D)
(square D)
(circle E)
Search Methods in Artificial Intelligence Deepak Khemani, Plaksha University
Goal tree = AND/OR tree
(niceToy ?x)

Rule2
Rule1

(square ?x)

(circle ?x) (red ?x) (square D)


(green ?x)

(circle C) (circle E)

(green A) (green B) (red C) (red D)

Search Methods in Artificial Intelligence Deepak Khemani, Plaksha University


Depth First Search Goal Set
After having “solved”
(green ?x) by ?x=A {(niceToy ?x)}
{(green ?x), (circle ?x)} Rule1
(niceToy ?x) {(circle A)} ?x=A FAIL
{(circle B)} ?x=B FAIL
OR {(red ?x), (square ?x)} Rule2
{(square C)} ?x=C FAIL
Rule1 Rule2
{(square D)} ?x=D
AND AND {} Success

(green ?x) (circle ?x) (red ?x) (square ?x)

OR OR OR

(green A) (green B) (circle C) (circle E) (red C) (red D) (square D)

Search Methods in Artificial Intelligence Deepak Khemani, Plaksha University


AND/OR tree: Solution = subtree
(niceToy ?x)

Rule2
Rule1

(square ?x)

(circle ?x) (red ?x) (square D)


(green ?x)

(circle C) (circle E)

(green A) (green B) (red C) (red D)

Search Methods in Artificial Intelligence Deepak Khemani, Plaksha University


A Prolog KB (program)
outingPlan(X,Y,Z) :- eveningPlan(X), moviePlan(Y), dinnerPlan(Z).
eveningPlan(X) :- outing(X), likes(friend, X).
moviePlan(X) :- movie(X), likes(friend,X).
dinnerPlan(X) :- restaurant(X), likes(friend,X).
outing(mall).
outing(beach).
movie(theMatrix).
movie(artificialIntelligence). (if (and (restaurant ?x) (likes friend ?x)) (dinnerPlan ?x))
movie(bhuvanShome).
movie(sevenSamurai).
restaurant(pizzaHut).
restaurant(saravanaBhavan).
likes(friend, beach).
likes(friend, theMatrix).
likes(friend, bhuvanShome).
likes(friend, sarvanaBhavan).

Search Methods in Artificial Intelligence Deepak Khemani, Plaksha University


The Goal Tree outingPlan(X,Y,Z)

Dinner
eveningPlan(X)
Movie

outing(X) likes(friend,X)

movie(Y) likes(friend,Y) restaurant(Z) likes(friend,Z)

outing(mall)
likes(friend, bhuvanShome) likes(friend,saravanaBhavan)

likes(friend, theMatrix)
outing(beach)
restaurant(pizzaHut)
movie(theMatrix)
movie(sevenSamurai)

movie(artificialIIntelligence)
restaurant(saravanaBhavan)
likes(friend, beach) movie(bhuvanShome)

Search Methods in Artificial Intelligence Deepak Khemani, Plaksha University


Backward Chaining: Depth First Search
{outingPlan(X,Y,Z)} theta = { }
{eveningPlan(X), moviePlan(Y), dinnerPlan(Z)} theta = { }
{outing(X), likes(friend, X), moviePlan(Y), dinnerPlan(Z)} theta = { }
{likes(friend, mall), moviePlan(Y), dinnerPlan(Z)} theta = {X=mall}
{“fail”, moviePlan(Y), dinnerPlan(Z)} theta = {X=mall}
{outing(X), likes(friend, X), moviePlan(Y), dinnerPlan(Z)} theta = { }backtrack
{likes(friend, beach), moviePlan(Y), dinnerPlan(Z)} theta = {X=beach}
{moviePlan(Y), dinnerPlan(Z)} theta = {X=beach}
{movie(Y), likes(friend,Y), dinnerPlan(Z)} theta = {X=beach}
{likes(friend, theMatrix), dinnerPlan(Z)} theta = {X=beach, Y=theMatrix}
{dinnerPlan(Z)} theta = {X=beach, Y=theMatrix}
{restaurant(Z), likes(friend,Z)} theta = {X=beach, Y=theMatrix}
{likes(friend,pizzaHut)} theta = {X=beach, Y=theMatrix, Z=pizzaHut}
{“fail”} theta = {X=beach, Y=theMatrix, Z=pizzaHut}
{restaurant(Z), likes(friend,Z)} theta = {X=beach, Y=theMatrix} backtrack
{likes(friend, saravanaBhavan)} theta = {X=beach, Y=theMatrix, Z= saravanaBhavan }
{} theta = {X=beach, Y=theMatrix, Z= saravanaBhavan }

Search Methods in Artificial Intelligence Deepak Khemani, Plaksha University


The Solution outingPlan(X,Y,Z)

Dinner
eveningPlan(X)
Movie

outing(X) likes(friend,X)

movie(Y) likes(friend,Y) restaurant(Z) likes(friend,Z)

outing(mall)
likes(friend, bhuvanShome) likes(friend,saravanaBhavan)

likes(friend, theMatrix)
outing(beach)
restaurant(pizzaHut)
movie(theMatrix)
movie(sevenSamurai)

movie(artificialIIntelligence)
restaurant(saravanaBhavan)
likes(friend, beach) movie(bhuvanShome)

Search Methods in Artificial Intelligence Deepak Khemani, Plaksha University


A not so easy problem
Given the following knowledge base (in list notation)

{(O A B), (O B C), (not (M A)), (M C)}

What is the KB talking about?


What is the semantics?

Depends upon the interpretation ϑ = <D, I> !

Two sample interpretations….

Search Methods in Artificial Intelligence Deepak Khemani, Plaksha University


Interpretation 1 {(O A B), (O B C), (not (M A)), (M C)}
Domain: Blocks World

Predicate symbols A is not maroon


A is on B
O à On B ?
M à Maroon B is on C
C is maroon
Constant Symbols
A, B, C à blocks

Search Methods in Artificial Intelligence Deepak Khemani, Plaksha University


Interpretation 2 {(O A B), (O B C), (not (M A)), (M C)}
Domain: People Anne is looking at John
Jack is looking at Anne
Predicate symbols
O à LookingAt
M à Married
John Anne Jack
Constant Symbols is not married
is married
A à Jack
?
B à Anne
C à John
Search Methods in Artificial Intelligence Deepak Khemani, Plaksha University
The Goal {(O A B), (O B C), (not (M A)), (M C)}
Given the KB is the following goal entailed?
(exists (x y) (and (O x y) (not (M x)) (M y)))
or equivalently (and (O ?x ?y) (not (M ?x)) (M ?y))

Blocks World:
Is there a not-maroon block on a maroon block?

People:
Is a not-married person looking at a married one?

Is it provable?

Search Methods in Artificial Intelligence Deepak Khemani, Plaksha University


Incompleteness of Backward and Forward Chaining
Given the KB,
{(O A B), (O B C), (not (M A)), (M C)}
And the Goal,
(and (O ?x ?y) (not (M ?x)) (M ?y))
Neither Forward Chaining nor Backward Chaining
is able to generate a proof.
Both are Incomplete!

A complete procedure…
in AI: Knowledge Representation & Reasoning
Search Methods in Artificial Intelligence Deepak Khemani, Plaksha University
End : Deduction as Search

Search Methods in Artificial Intelligence Deepak Khemani, Plaksha University

You might also like