Propositional Logic

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 50

Artificial Intelligence

Lecture 4
Propositional Logic
3-11-2022
Outline
 Revision of propositional logic, models, entailment,
validity, and satisfiability.
 Inference rules and theorem proving
 Resolution inference rule
 Conjunctive Normal Form
 Resolution Algorithm
Propositional logic
 Propositional logic deals with individual propositions,
which are viewed as atoms which cannot be further
broken down into smaller constituents.
 Propositional symbols: P, Q, R, …
 Each of these symbols represents some fact or
symbols about the world.
 Connectors can be used to connect these symbols.
Syntax of propositional logic
BNF grammar of sentences in propositional logic:
Sentence → AtomicSentence | ComplexSentence
AtomicSentence → True | False | P | Q | R | …
ComplexSentence → (Sentence) | [Sentence]
What is the |  Sentence
terminals and | Sentence  Sentence
non-terminals of
this grammar? | Sentence  Sentence
| Sentence  Sentence
| Sentence  Sentence
Operator Precedence : , , , , 
Syntactic derivation
 To prove that a given sentence is syntactically correct, either a parse
tree or syntactic derivation (derivation) can be constructed.
 Example: a derivation of P ∧ Q ⇒ R

Sentence ::= ComplexSentence


::= Sentence ⇒ Sentence
::= Sentence ∧ Sentence ⇒ Sentence
::= AtomicSentence ∧ Sentence ⇒ Sentence
::= P ∧ Sentence ⇒ Sentence
::= P ∧ AtomicSentence ⇒ Sentence
::= P ∧ Q ⇒ Sentence
::= P ∧ Q ⇒ AtomicSentence
::= P∧ Q ⇒ R
Semantics of propositional logic
Each model specifies true/false for each proposition symbol

E.g. P Q R
False True False
With these symbols, 8 possible models, can be enumerated automatically.

Rules for evaluating truth with respect to a model M:

S is True iff S is False


S1  S2 is True iff S1 is True and S2 is True
S1  S2 is True iff S1is True or S2 is True
S1  S2 is True iff S1 is False or S2 is True
i.e., it is False iff S1 is true and S2 is False
S1  S2 is True iff S1S2 is True and S2S1 is True

If P is False, Q are True, and R is False, then:


P  (Q  R) = True  (True  False) = True  True = True
Truth tables for connectives
P ¬P
False True
True False

P Q P^Q PvQ P⟹Q P⇔Q


False False False False True True
False True False True True False
True False False True False False
True True True True True True
Knowledge Base (KB)
 A set of sentences known by a knowledge-based
agent to be true.
Entailment
 Entailment means that one thing follows from another α ╞ β

α entails β or β is a logical consequence from α

 Knowledge base KB entails sentence α if and only if α is true in all worlds where KB is
true

 Examples:

 the KB containing “All men are mortal” and “Socrates is a man” entails “Socrates is
mortal”

 x + y = 4 entails 4 = x + y

 Entailment is a relationship between sentences (i.e., syntax) that is based on semantics


Models
 Logicians typically think in terms of models, which are formally structured
worlds with respect to which truth can be evaluated.

 We say m is a model of a sentence α if α is true in m

 M(α) is the set of all models of α

 Then KB ╞ α iff M(KB)  M(α)


 E.g. KB = Adam won and Sally won

α = Adam won

 E.g., x = 0 entails xy = 0
Model checking proof method
 Enumeration of models (models are assignments of true
or false to every possible symbol)
 To determine if KB ╞ α:
◼ Enumerate all possible models.
◼ If in every model where KB is true, α is true, then KB entails α
◼ Otherwise, KB does not entail α
Inference (deduction)

 The process of deriving new sentences from old ones


using inference rules.
 KB ⊢ α: sentence α is derived from KB (KB deduces α)
 For example, ((P ⇒ Q) ∧ P) ⊢ Q;
 Q is derived from ((P ⇒ Q) ∧ P), or
 ((P ⇒ Q) ∧ P) deduces Q
Soundness and completeness
 An inference algorithm that derives only entailed
sentences is called sound or truth preserving:

 if whenever KB ⊢ α, it is also true that KB╞ α


 Model checking is a sound procedure.
 An inference algorithm is complete if it can derive
any sentence that is entailed.
 If whenever KB╞ α , it is also true that KB ⊢ α
Note

 The entailment procedure is sound because it


implements directly the definition of
entailment, and
 It is complete because it works for any KB
and any statement α and always terminates—
there are only finitely many models to
examine.
Inference rules
 Modus Ponens (latin for mode that affirms)

𝛼 ⟹ 𝛽, 𝛼
𝛽
Example,
α The light is on
α⇒β if the light is on then the switch is on
----------
β the switch is on
Inference rules
 Modus Tollens
𝛼⇒𝛽, ¬𝛽
¬𝛼
Example,
α⇒β if the light is on then the switch is on
¬𝛽 the switch is not on
----------
¬𝛼 the light is not on
Inference rules
 And elimination
𝛼𝛽
𝛼

 By considering the possible truth values of α and β, it


can easily be verified that Modus Ponens and And-
Elimination are sound once and for all.
 These rules can then be used in any particular instances
where they apply, generating sound inferences without
the need for enumerating models.
Inference rules
 All the logical equivalence can be used as an
inference rules, e.g.,

𝛼⇔𝛽
(𝛼⇒𝛽)(𝛽⇒𝛼)

(𝛼 ⇒ 𝛽)(𝛽 ⇒ 𝛼)
𝛼⇔𝛽
Inference rules
 Double negation elimination
¬(¬ 𝛼 )
α
Logical equivalence
 α ≡ ß iff α╞ β and β╞ α
Validity and satisfiability
 A sentence is valid if it is true in all models,
e.g., True, A A, A  A, (A  (A  B))  B
 Valid sentences are also known as tautology
 Validity is connected to inference via the Deduction Theorem:
KB ╞ α if and only if (KB  α) is valid

A sentence is satisfiable if it is true in some model


e.g., A B, C
A sentence is unsatisfiable if it is true in no models
e.g., AA
Satisfiability is connected to inference via the following:
KB ╞ α if and only if (KB α) is unsatisfiable. Proof by contradiction!
Enumeration of truth table Examples
Example 1

 Let α = A  B and KB = ( A  C)  (B  C)


 Is KB╞ α ?
 Check all models: α must be true whenever KB is true
A B C AC B  C KB α
False False False False True False False
False False True True False False False
False True False False True False True
False True True True True True True
True False False True True True True
True False True True False False True
True True False True True True True
True True True True True True True
Example 1

 Let α = A  B and KB = ( A  C)  (B  C)


 Is KB╞ α ?
 Check all models: α must be true whenever KB is true (i. e., KB ⇒𝞪 is valid)

A B C AC B  C KB α
False False False False True False False
False False True True False False False
False True False False True False True
False True True True True True True
True False False True True True True
KB╞ α
True False True True False False True
True True False True True True True
True True True True True True True
Example 1

 Let α = A  B and KB = ( A  C)  (B  C)


 Is KB╞ α ?
 Check all models: α must be true whenever KB is true (i. e., KB ⇒𝞪 is valid)

A B C AC B  C KB α KB⇒𝛼
False False False False True False False True
False False True True False False False True
False True False False True False True valid
True
False True True True True True True
True
True False False True True True True
True
True False True True False False True
True
True True False True True True True
True
True True True True True True True
Example 2
 Determine the logical consequence of
S = (P∨ R) ∧(Q ∨  R) from T= {P, Q}, (T ╞ S)
P Q R P R QR T S
False False False False True False False
False False True True True False True
False True False False True False False
T╞ S
False True True True False False False S is true in
True False False True True True True every
model in
True False True True True True True
which T is
True True False True True False True True
True True True True False False False
Inference Rules Examples
Example 1
 Show that
{A, B ⇒ C, ( A ∧B ) ⇒ (C ∨ D), B } ⊢ D
1. A hypothesis
2. B ⇒ C hypothesis
3. ( A ∧B ) ⇒ (C ∨ D) hypothesis
4. B hypothesis
B ⇒ C B
From 2, 4 Modus Ponens
C
5.
Example 1 (Cont.)
𝐴 𝐵
6. From 1, 4 ∧ introduction
𝐴∧𝐵

( A ∧B ) ⇒ (C ∨ D) 𝐴 ∧𝐵
7. From 3, 6 Modus Ponens
𝐶 ∨𝐷

C 𝐶 ∨𝐷
8. From 5, 7 ∨-elimination
𝐷
Note
 Finding a proof is a search problem.
 A state is a set of sentences.
 The initial state is the initial KB.
 The actions consists of all the inference rules
applied to all sentences in KB.
 The goal state is the sentence we are trying to
prove.
Monotonicity
 A property of logical systems.
 If KB ⊨ α then KB ∧ 𝛽 ⊨ α
Semantic tableau
 Checking for satisfiability of propositional logic sentence can be
performed by truth tables.
 Semantic tableau is another efficient method for deciding
satisfiability for sentences.
 The method (or algorithm) systematically searches for a model
for a formula. If it is found, the formula is satisfiable, else not
satisfiable.
 A literal is an atomic sentence or negation of it.
 For any atom P, the set {P,  P} is complementary pair of
literals.
 For any sentence S, {S,  S} is complementary pair of sentence.
Example 1 of analysis of the satisfiability
of a sentence
 For a sentence A = P ∧ ( Q ∨ P), has an arbitrary model (or
interpretation) M.
 M(A) = True iff M(P) = True and M( Q ∨  P) = True .
 Hence, M(A) = True iff either:
1. M(P) = True and M(¬Q) = True, or
2. M(P) = True and M(¬P) = True
 Therefore, A is satisfiable if either, model 1 holds or model 2 holds.
 Model 2 is not possible, then A is satisfiable when the model 1 holds true.
 The satisfiability of a formula is reduced to the satisfiability of literals.
 A set of literals is satisfied if and only if it does not contain complementary
pair of literals.
Example 1 of analysis of the satisfiability
of a sentence
 For a sentence A = P ∧ ( Q ∨ P), has an arbitrary
model (or interpretation) M.
 M(A) = True iff M(P) = True and M( Q ∨ SinceP)there
= True
is .
a model for
 Hence, M(A) = True iff either: the sentence
(P=True and
1. M(P) = True and M(¬Q) = True, or Q= False) it is
satisfiable

1. M(P) = True and M(¬P) = True


Semantic tableau (cont.)
 The method in the last slide can be represented by a semantic
tableau tree:

 The leaves in the tree represent a set of literals that must be


satisfied.
 A leaf containing complementary pair of literals is marked closed
by ×, while the satisfying leaf is marked as open by ⨀.
Semantic tableau (cont.)
 A semantic tableau whose construction is terminated is called
completed tableau.
 A completed tableau is closed if all the leaves are marked
closed. Otherwise, it is open i.e., some leaves are open.
 Any formula A is unsatisfiable if its completed tableau T is
closed x.
 A formula A is satisfied if its tableau T is open ⨀.
Example 2
 Find out whether A = (P ∨ Q) ∧ (P ∧Q) is satisfiable, using
semantic tableau method.
 A is satisfiable if M(A) = True for some model assignments.
 That is, M(P ∨ Q) = True and M(P ∧Q) = True.
 Thus, M(A) is True if either,
1. M(P) = True , M(P) = True, M(Q) = True, or
2. M(Q) = True, M( P) = True, M(Q) = True.
 The two sets of literals are (P, P, Q) and (Q, P, Q).
 Since both models contain complementary pairs, hence neither of the literals is
satisfiable.
 Therefore, it is impossible to find a model for A the A is unsatisfiable.
Example 2: semantic tableau tree

(P ∨ Q) ∧ (P ∧Q)

(P ∨ Q) , (P ,Q)

P, P ,Q Q, P ,Q
x x
Resolution inference rule
 PQ
P
Q

 Example,
Ramy is in the library  Hany is in the library
Ramy is NOT in the library
Hany is in the library
Resolution
 In general, for n proposition :
P  𝑄1  𝑄2 …  𝑄𝑛
P
𝑄1  𝑄2 …  𝑄𝑛
Resolution
Conjunctive Normal Form (CNF)
conjunction () of disjunctions of literals

clauses
E.g., (A  B)  (B  C  D)

 Resolution inference rule (for CNF):

l1 …  lk, m1  …  mn
l1  …  li-1  li+1  …  lk  m1  …  mj-1  mj+1 ...  mn

 li and mj are complementary literals (i.e., one is the negative of the


other)
Conversion to Conjunctive Normal Form
(CNF)
B1  (P1  P2)
1. Eliminate , replacing α  β with (α  β)(β  α)
(B1  (P1 P2))  ((P1  P2)  B1)
2. Eliminate , replacing α  β with α β
(B1  P1  P2)  ((P1  P2)  B1)

3. Move  inwards using de Morgan's rules and double-negation:

(B1  P1  P2)  ((P1  P2)  B1)


4. Apply distributivity law ( over ):

(B1  P1  P2)  (P1  B1)  (P2  B1)


Exercises
 Convert the following to CNF
A ⇔ (C ∧ D)
C ∧ D ⟹¬ B
Exercises
 Convert the following to CNF
A ⇔ (C ∧ D)
1. Eliminate ⇔: A ⇒ (C ∧ D) ∧ (C ∧ D) ⇒A
2. Eliminate ⇒: [A ∨ (C ∧ D)] ∧ [ (C ∧ D)∨ A]
3. Move  inwards using de Morgan's rules:
[A ∨ (C ∧ D)] ∧ [( C∨  D)∨ A]
4. Apply distributivity law ( over ):
[(A ∨C) ∧(A ∨ D)] ∧ [( C ∨  D∨ A)]
Notes
 The resulting clause should contain exactly one copy of
each literal
P𝑄
PQ
QQ
Q
 If there is only P and  P, we get the empty clause

P
 P
empty clause which is always false
Note

 Clauses are disjunction of literals, e.g., A  B


 The resolution rule applies only to conjunction of
clauses, e.g., (A  B)  (B  C  D),
which is known as Conjunctive Normal Form
(CNF).
Resolution Algorithm
 Inference procedures based on resolution work by
using the principle of proof by contradiction:
 To show that KB ⊨ α, we show that (KB ∧ ¬α) is
unsatisfiable.
 This is done by proving a contradiction.
Resolution Algorithm
1) (KB ∧ ¬α) is converted into CNF.
2) The resolution rule is applied to the resulting clauses. Each pair
that contains complementary literals is resolved to produce a new
clause, which is added to the set if it is not already present.
3) The process continues until one of two things happens:
1) there are no new clauses that can be added, in which case KB does
not entail α; or
2) two clauses resolve to yield the empty clause, in which case KB
entails α.
 The empty clause—a disjunction of no disjuncts—is equivalent to
False because a disjunction is true only if at least one of its disjuncts
is true. Another way to see that an empty clause represents a
contradiction is to observe that it arises only from resolving two
complementary unit clauses such as P and ¬P.
Resolution example
 KB = (B1,1  (P1,2 P2,1))  B1,1 α = P1,2
Questions
 Prove each of the following assertions:
1. 𝛼 is valid iff True ⊨𝛼
2. For any 𝛼, False ⊨𝛼

You might also like