You are on page 1of 48

Artificial Intelligence

DSE 313

Knowledge Representation and Reasoning:


Logic in AI
Vaibhav
Assistant Professor, Data Science and Engineering
IISERB

Based on slides/lectures by Stuart Russell, Henry Kautz, Subbarao Kambhampati, Amit


Sethi, Avijit Maji, B Ravindran, and Mausam
A story
• You roommate comes home; he/she is completely
wet
• You know the following things:
• Your roommate is wet
• If your roommate is wet, it is because of rain, sprinklers, or both
• If your roommate is wet because of sprinklers, the sprinklers must be on
• If your roommate is wet because of rain, your roommate must not be
carrying the umbrella
• The umbrella is not in the umbrella holder
• If the umbrella is not in the umbrella holder, either you must be carrying the
umbrella, or your roommate must be carrying the umbrella
• You are not carrying the umbrella

• Can you conclude that the sprinklers are on?


• Can AI conclude that the sprinklers are on?
Knowledge base (KB) for the story
• RoommateWet
• RoommateWet => (RoommateWetBecauseOfRain OR
RoommateWetBecauseOfSprinklers)
• RoommateWetBecauseOfSprinklers => SprinklersOn
• RoommateWetBecauseOfRain =>
NOT(RoommateCarryingUmbrella)
• UmbrellaGone
• UmbrellaGone => (YouCarryingUmbrella OR
RoommateCarryingUmbrella)
• NOT(YouCarryingUmbrella)

KB = Set of sentences in a formal language


Language is a mechanism for expression.
Natural languages (informal):
English:Two divides even numbers.
German: Zwei dividieren geraden zahlen.
Programming languages (formal):
Python:
def even(x): return x % 2 == 0
C++:
bool even(int x) { return x % 2 == 0; }
Logical languages (formal):
First-order-logic:
Logic and AI
• Would like our AI to have knowledge about the
world, and logically draw conclusions from it
• Search algorithms generate successors and evaluate
them, but do not “understand” much about the setting
• Example question: is it possible for a chess player to have
8 pawns and 2 queens?
• Search algorithm could search through tons of states
to see if this ever happens, but…
Till Now Problem

Representation

Representations
• Constraint Satisfaction
• Propositional Logic Problem
Solving
• Bayesian Networks (Probabilistic PL)

Can you think of other representations??? Representation


Semantic Networks
Till Now Problem

Representation

Representations
• Constraint Satisfaction
• Propositional Logic Problem
Solving
• Bayesian Networks (Probabilistic PL)

Can you think of other representations??? Representation


Semantic Networks
Logic roadmap overview
• Propositional logic with only horn clauses
• Propositional logic
• First order logic with horn clauses
• First order logic
• Second order logic
.
.
.
Tradeoff: Balance expressivity with computational efficiency
Components of KR
• Syntax: Defines the sentences in the
language
• Semantics: Defines the “Meaning” to the
sentences
• Knowledge Base
• Inference Procedure
-Algorithms
Propositional logic
• Syntax: Atomic sentences P, Q ,...
Connectives:
 and [conjunction]
 or [disjunction]
 implies (if then) [implication / conditional]
 is equivalent (iff) [biconditional]
 not [negation]
• Semantics:
Logical constants (Truth values represented using truth
tables ): true, false
• Inference Algorithms:
• Modus Ponens
• Resolution
• DPLL
• GSTAT
Propositional logic (PL)
• Simple language for showing key ideas and definitions
• 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
Examples of PL sentences
• (P  Q) → R
“If it is hot and humid, then it is raining”
•Q→P
“If it is humid, then it is hot”
•Q
“It is humid.”
• We’re free to choose better symbols, btw:
Ho = “It is hot”
Hu = “It is humid”
R = “It is raining”
Semantics
• A model (w) specifies which of the proposition symbols are
true and which are false
• Given a model, I should be able to tell you whether a
sentence is true or false (interpretation function {I
(P/Q,w)= 0,1})
• Truth table defines semantics of operators:
I(P,w) I(Q,w) I(NOT(P), I(P AND I(P OR I(P =>
w) Q, w) Q,w) Q, w)
false false true false false true

false true true false true true

true false false false true false

true true false true true true


• Given a model, can compute truth of sentence
recursively with these
Knowledge base (KB) for the story
• A knowledge base is a set of formulas representing their
conjunction / intersection
• KB specifies constraints on the world. M (KB) is the set of
all worlds satisfying those constraints
Special Syntactic Forms
• General Form:
((q r) → s))   (s  t)
• Conjunction Normal Form (CNF)
( q  r  s )  ( s   t)
Set notation: { ( q, r, s ), ( s,  t) }
empty clause () = false
• Binary clauses: 1 or 2 literals per clause
( q  r) ( s   t)
• Horn clauses: at most 1 positive literal per
(seq   r  s ) ( s   t)
clau
(qr) → s (st) → false
18
Inference rules: Deducing Logical outcomes

Logical inference creates new sentences that


logically follow from a set of sentences (KB)
Inferencing: A mechanical process for computing
new sentences
1. Modes Ponens (Backward and forward chaining)
2. Resolution (Proof by Contradiction)
3. SAT
Reasoning Tasks
• Model finding
KB = background knowledge
S = description of problem
Show (KB  S) is satisfiable
A kind of constraint satisfaction
• Deduction
f = question
Prove that KB|= f
Two approaches:
• Rules to derive new formulas from old (inference)
• Show (KB   f) is unsatisfiable

20
More terms: Adding to the Knowledge
Base:
Entailment

P entails Q, written P |= Q, all models of P are also


models of Q.
Whenever P is True Q must also be True
Artificial Intelligence
DSE 313

Knowledge Representation and Reasoning:


Logic in AI
Vaibhav
Assistant Professor, Data Science and Engineering
IISERB

Based on slides/lectures by Stuart Russell, Henry Kautz, Subbarao Kambhampati, Amit


Sethi, Avijit Maji, B Ravindran, and Mausam
Satisfiability, Validity, & Entailment
• S is satisfiable if it is true in some world

• S is unsatisfiable if it is false in all worlds

• S is valid if it is true in all worlds

• S1 entails S2 if wherever S1 is true S2 is also true


Two major areas
• Inferencing
• Modus ponens
• Model finding
• SAT problem
• DPLL
• Local search
Contradiction

A sentence that is False under all interpretations.


e.g., It’s raining and it’s not raining

f contradicts what we know (KB)


Contingency

f adds non-trivial information to KB

Example: Rain and Snow


Tell Operation
Ask Operation
Inference Framework

Forward Inference
Deducing Logical Outcomes

If it rains, I will get wet p q


It’s raining
P
-
Therefore I will get wet Therefore q - Conclusion
Deducing Logical Outcomes
if you have a conditional proposition of the
form "if A then B", and you also know that A is
true, then you can infer that B is true.

If it rains, I will get wet p q


It’s raining
P
-
Therefore I will get wet Therefore q - Conclusion

Modus Ponens
Inference example: Modus Ponens through
forward Inference
Example

2 2

32
Example

1 1

33
Example

1 0

34
Example

1 0

35
Example

1 0

36
Example

1 0

37
Example

1 0

38
Example

0 0

39
Example

0 0

40
Soundness and Completeness of an algorithm

Soundness: Nothing but the truth


Completeness: Whole truth

Soundness means that you cannot prove anything that's


wrong.
Completeness means that you can prove anything that's
right.
An inference rule is sound if the set of derived formulas is a subset of the set of
entailed formulas

If you follow a sound inference rule, then any conclusions you derive (derived
formulas) will be guaranteed to be true given your starting statements (entailed
formulas).

An inference algorithm is sound if it guarantees that any conclusion it derives from


a set of true premises is also necessarily true.

It only produces valid inferences


You can live without
completeness, but if you are
unsound, that means you are just
going to generate erroneous
conclusions
Premise 1: All birds have wings.
Premise 2: X is a bird.

Sound: X has wings


Complete: X has wings, X is not a car

• An inference rule is complete if the set of derived formulas is


a superset of the set of true/entailed formulas.
• Inference rule can derive all logically valid conclusions from a
set of true premises.
• Algorithm explores every possible avenue of logical reasoning
allowed by the underlying logic system and identifies every
single conclusion that can be definitively proven true based
on the starting statements
Soundness of modus ponens

Is the intersection of the left is subset of Wet models

Is it sound? Yes
Is it complete? No {we are not able to derive all the models of wet}
SAT: Model Finding/Checking
Find assignments to variables that makes a formula true

Also known as satisfiability problem

S is satisfiable if it is true in some world

Popular Algorithms
• DPLL (backtracking search)
• WalkSat (randomized local search)
Satisfiability
A formula is satisfiable if there exists an interpretation (model) that
makes the formula true

A formula is valid if all interpretations make the formula true

for (m in truth assignments){


if (m makes  true)
then return “Sat!”
}
return “Unsat!”
Example: Model Finding/Checking

You might also like