1. Artificial Intelligence Knowledge & Reasoning
Logic.
Reading: Sections 7.1, 7.3, 7.4 & 7.5 of Textbook R&N
Representation Language of Artificial
Intelligence.
By Bal Krishna Subedi 1
2. Artificial Intelligence Knowledge & Reasoning
Knowledge bases
Knowledge base = set of sentences in a formal language
Allows an agent to reason about the world, deduce hidden properties and
determine appropriate actions.
Example:
KB = {Mike comes to the party;
If Cathy comes to the party then Becky comes;
If Cathy doesn't come then Mike won't come to the party}
Agent should be able to deduce that Becky comes to the party.
By Bal Krishna Subedi 2
3. Artificial Intelligence Knowledge & Reasoning
Logic in general
Logics are formal languages for representing information such that
conclusions can be drawn
Components of logic:
Syntax defines how we can make sentences in the language.
Semantics defines how the sentences reflect meaning in the real world.
i.e define truth of sentence in real world
Inference Procedures specify how we can derive new sentences from our
existing sentences.
E.g., the language of arithmetic
x + 2 ≥ y is a sentence; x2 + y > is not a sentence.
x + 2 ≥ y is true iff the number x + 2 is no less than the number y
x + 2 ≥ y is true in a world where x = 7, y = 1.
x + 2 ≥ y is false in a world where x = 0, y = 6.
By Bal Krishna Subedi 3
4. Artificial Intelligence Knowledge & Reasoning
Types of logic
Logics are characterized by what they commit to as “primitives”
Ontological commitment: what exists -- facts? objects? time? beliefs?
Epistemological commitment: what states of knowledge?
We will look at propositional logic, first-order logic (also known as
predicate logic) and probability theory.
By Bal Krishna Subedi 4
5. Artificial Intelligence Knowledge & Reasoning
Propositional logic: Syntax
Propositional logic is the simplest logic --illustrates
basic ideas
• Symbols:
– Logical constants: True, False
– Propositional symbols: P, Q, R, ...
– Connectives: ^ (and), ∨ (or), ¬ (not), ⇒ (implies), ⇔
(equivalent)
– Parentheses: ( )
• Sentences
– constructed from atomic sentences and connectives.
By Bal Krishna Subedi 5
6. Artificial Intelligence Knowledge & Reasoning
Propositional logic: Syntax
Formal Grammar of Propositional Logic (in BNF form):
Sentence → AtomicSentence | ComplexSentence
AtomicSentence → True | False | P | Q | ...
ComplexSentence → (Sentence )
| Sentence Connective Sentence
| ¬ Sentence
Connective → ∧ | ∨ | ⇒ | ⇔
ambiguities are resolved through precedence ¬ ∧ ∨ ⇒ ⇔ or parentheses
By Bal Krishna Subedi 6
7. Artificial Intelligence Knowledge & Reasoning
Propositional logic: Syntax
The proposition symbols P, Q, R etc are sentences
If P is a sentence, ¬P is a sentence
If P and Q is a sentence, P ^ Q is a sentence
If P and Q is a sentence, P ∨ Q is a sentence
If P and Q is a sentence, P ⇒ Q is a sentence
If P and Q is a sentence, P ⇔ Q is a sentence
By Bal Krishna Subedi 7
8. Artificial Intelligence Knowledge & Reasoning
Propositional logic: Semantics
Each propositional statement is a fact which can be true or false.
Example:
P means “It is hot"
Q means “It is sunny"
R means “It is raining"
The user defines what the propositional symbols mean.
A model of the world species true/false for each propositional symbol.
E.g. P Q R the world
True True False It is sunny and hot but it is not raining
False False True It is raining and it is not sunny nor hot
By Bal Krishna Subedi 8
9. Artificial Intelligence Knowledge & Reasoning
Propositional logic: Semantics
Rules for evaluating truth:
¬ P is true iff P is false
P ^ Q is true iff P is true and Q is true
P ∨ Q is true iff P is true or Q is true
P ⇒ Q is true iff P is false or Q is true
i.e., is false iff P is true and Q is false
P ⇔ Q is true iff P ⇒ Q is true and Q ⇒ P is true
We can define the meaning of the logical connectives explicitly
with a truth table:
By Bal Krishna Subedi 9
10. Artificial Intelligence Knowledge & Reasoning
Semantics of Implication ⇒
What does P ⇒ Q mean?
If P is true, then I am claiming that Q is true. If P is
false then I make no claim.
Also known as if-then rules
Example:
if it rains then I will get wet R ⇒ W
Important: P ⇒ Q is equivalent to : ¬ P ∨ Q
By Bal Krishna Subedi 10
11. Representing Knowledge in
Propositional Logic
Artificial Intelligence Knowledge & Reasoning
Example:
KB = {Mike comes to the party;
If Cathy comes to the party then Becky comes;
If Cathy doesn't come then Mike won't come to the party}
Let
M represent Mike comes to the party.
C represent Cathy comes to the party.
B represent Becky comes to the party.
KB = {M, C ⇒ B, ¬C ⇒ ¬M}
By Bal Krishna Subedi 11
12. Artificial Intelligence Knowledge & Reasoning
Models and Entailment
In propositional logic models can be thought of as a truth
assignment to the literals that make the sentence true,
e.g. what are the models of a sentence C ⇒ B?
We say m is a model of a sentence α if α is true in m
M(α) is the set of all models of α
Then KB╞ α if and only if M(KB) is subset of M(α)
By Bal Krishna Subedi 12
13. Artificial Intelligence Knowledge & Reasoning
Inference
Inference – derive a conclusion from facts or premises
Inference rules allow the construction of new sentences
from existing sentences
An inference procedure generates new sentences on the
basis of inference rules.
That is, the procedure will answer any question whose
answer follows from what is known by the KB
By Bal Krishna Subedi 13
14. Artificial Intelligence Knowledge & Reasoning
Inference: Example
KB = {Mike comes to the party;
If Cathy comes to the party then Becky comes;
If Cathy doesn't come then Mike won't come to the party}
Let
M represent Mike comes to the party.
C represent Cathy comes to the party.
B represent Becky comes to the party.
Conclusion: Becky comes to the party.
Propositional Logic Representation
Premises: M, C ⇒ B, ¬C ⇒ ¬M
Conclusion: Therefore B.
By Bal Krishna Subedi 14
15. Artificial Intelligence Knowledge & Reasoning
Inference rules for propositional logic
Modus Ponens:
from an implication and its premise one
can infer the conclusion.
if α ⇒ β, α are given, then sentence β
can be inferred.
and-elimination
– from a conjunction, any of the conjuncts can
be inferred.
and-introduction
– from a list of sentences, one can infer their
conjunction
or-introduction
– from a sentence, one can infer its disjunction
with anything else
α ⇒ β, α
β
α1 ∧ α2 ∧... ∧ αn
αi
α1, α2, … , αn
α1 ∧ α2 ∧... ∧ αn
By Bal Krishna Subedi 15
αi
α1 ∨ α2 ∨... ∨ αn
16. Artificial Intelligence Knowledge & Reasoning
Inference rules for propositional logic
Resolution:
A complete inference mechanism for propositional logic
Intuition: cannot be both true and false, therefore one of the
other disjuncts must be true in one of the premises.
unit resolution
• if one of the disjuncts in a disjunction is false, then the
other one must be true
resolution
• β cannot be true and false, so one of the other disjuncts
must be true
• can also be restated as “implication is transitive”
α ∨ β, ¬ β
α
α ∨ β, ¬ β ∨ γ
α ∨ γ
¬ α ⇒ β, β ⇒ γ
¬ α ⇒ γ
By Bal Krishna Subedi 16
17. Artificial Intelligence Knowledge & Reasoning
Normal forms
The resolution rule use syntactic operations on sentences, often
expressed in standardized forms.
By Bal Krishna Subedi 17
19. Artificial Intelligence Knowledge & Reasoning
Example
KB = {Mike comes to the party;
If Cathy comes to the party then Becky comes;
If Cathy doesn't come then Mike won't come to the party}
Let
M represent Mike comes to the party.
C represent Cathy comes to the party.
B represent Becky comes to the party.
Propositional Logic Representation
KB = {M, C ⇒ B, ¬C ⇒ ¬M}
Convert to CNF:
1. M
2. ¬C ∨ B
3. C ∨ ¬M
By Bal Krishna Subedi 19
20. Artificial Intelligence Knowledge & Reasoning
Example
Use resolution to combine 3 and 2.
Add result to the KB
4. ¬ M ∨ B
Use unit resolution to combine 1 and 4.
Conclusion: Therefore, Becky comes to the party
By Bal Krishna Subedi 20
21. Artificial Intelligence Knowledge & Reasoning
Limitations of Propositional Logic
Propositional logic is extremely simple, hence it has limited
expressive power and thus it is difficult to represent statements
concerning objects and relations.
Example: How do we use propositional logic to represent
{All people are mortal}
To do so we would need to have a separate proposition for each
person living on Earth claiming that she or he is mortal.
{Mortal-Pete, Mortal-Jessica, Mortal-John, and so on}
This results in a huge number of propositions and thus causes
problems with inference.
We will look at a more expressive logic: predicate or first-order logic.
It allows us to reason about objects, their properties and their
relations.
By Bal Krishna Subedi 21