CMPSC 442: Artificial Intelligence
Lecture 8. Propositional Logic
Rui Zhang
Spring 2024
1
AIMA Chapter 7
Outline
Logic and Logical Agents (AIMA 7.1, 7.2, 7.3)
Propositional Logic (AIMA 7.4 7.5 7.6)
2
3
4
https://www.lsac.org/lsat/taking-lsat/test-format/logical-reasoning/logical-reasoning-sample-questions
Can GPT answer this logical question (GPT-3.5)?
5
Can GPT answer this logical question (GPT-4)?
6
Can GPT answer this logical question (GPT-4)?
7
8
9
'Deduction' vs. 'Induction' vs. 'Abduction'
10
https://www.merriam-webster.com/grammar/deduction-vs-induction-vs-abduction
Wumpus World
Environment
Actuators
Sensors
11
Wumpus World
Performance measure
12
Wumpus World
13
Agents with Explicit Knowledge Representation
Knowledge Base (KB) = A set of sentences (declarations) in a formal language
Adding to the KB
Using the KB
14
Exploring Wumpus World: an Initial Action
Figure (a):
Figure (b):
15
Exploring Wumpus World:
Figure (a):
Figure (b):
16
Generic Knowledge-Based (KB) Agent
17
Formalizing the KB
The Wumpus world illustrates a logical agent: the agent takes an action, which results in a new percept, leading to new facts to add to the KB
How could such an agent be implemented?
18
General Properties of a Logical Formalism
Logic: a way to formulate statements, interpret them, and derive conclusions
19
Semantics
Grounding: The connection between logical reasoning processes and the real environment in which the agent exists.
20
Models
We use the term model in place of “possible world”.
A logical model m is a formally structured world with respect to which truth can be evaluated.
Satisfaction
Entailment
21
Entailment in Wumpus World
22
Entailment in Wumpus World
KB
23
Entailment in Wumpus World
KB
24
KB
Model Checking and Wumpus World
Statement to check: α1 ([1,2] is safe])
KB ⊨ α1
25
Model Checking and Wumpus World
Statement to check: α2 ([2,2] is safe])
KB ⊭ α2
26
Propositional Logic
The syntax of propositional logic defines the allowable sentences. Sentences are true or false.
The atomic sentences consist of a single proposition symbol. Each such symbol stands for a proposition that can be true or false.
Logical operators (connectives) combine simple sentences into complex sentences
27
Syntax of Propositional Logic
The proposition symbols S, S1, S2 etc are sentences. If S, S1, S2 are sentences
28
Translating between Propositions and English
29
Truth Table for Connectives
For 3 statements (P1, P2, P3), 23 combinations of truth values = 8 models
Recursive evaluation of arbitrary sentences. If P1,2 = false, P2,2 = true, P1,2 = false:
30
Backus-Naur Form (BNF) Grammar of Propositional Logic
31
Operator Precedence
The BNF grammar by itself is ambiguous; a sentence with several operators can be parsed by the grammar in multiple ways.
To eliminate the ambiguity we define a precedence for each operator.
32
Wumpus World Sentences
Let Pi,j be true if there is a pit in [i, j]
Let Bi,j be true if there is a breeze in [i, j]
¬ P1,1
¬ B1,1
Pits cause breezes in adjacent squares
B1,1 ⇔ (P1,2 ∨ P2,1)
B2,1 ⇔ (P1,1 ∨ P2,2 ∨ P3,1)
33
Limitations of Propositional Logic
Can only state specific truths
Cannot state generic truths
34
Logic Inference
Determine Entailment: Given a KB, how can the agent know if a sentence is true of false? In other others, how can we know if KB entails the sentence?
1. Model Checking
2. Theorem Proving
35
An example in the Wumpus World
KB:
Given the KB, we want to prove that there is no pit in [1,2], i.e,
36
Model Checking
37
Model Checking
38
Soundness and Completeness
Soundness
An inference algorithm that derives only entailed sentences is called sound or truth-preserving
Completeness
An inference algorithm is complete if it can derive any sentence that is entailed
For example, Model Checking is sound and complete.
39
Validity, Tautologies, and Deduction Theorem
A sentence is valid if it is true in all models, e.g., the following are valid sentences
Valid sentences are also known as tautologies—they are necessarily true.
Validity is connected to inference via the Deduction Theorem:
40
Satisfiability
A sentence is satisfiable if it is true in some model
Determining satisfiability (the SAT problem) is NP-complete
A sentence is unsatisfiable if it is true in no models
Validity and satisfiability are connected
Satisfiability is connected to inference via reductio ad absurdum (literally, “reduction to an absurd thing”)
41
Inference Rules
42
Logical Equivalence: Rewrite rules
43
Query a Wumpus KB: Prove ¬P1,2
44
Uninformed Search to Derive Proofs
We found this proof by hand, but we can apply any of the search algorithms in Chapter 3 to find a sequence of steps that constitutes a proof. We just need to define a proof problem as follows:
Sound, but not necessarily complete with inference rules presented so far
45
Monotonicity
46
Proof by Resolution
Inference rules covered in previous slides (Modus Ponens, And-Elimination, Logical Equivalence) are sound, but not necessarily complete
So, let us introduce a single inference rule, resolution, that yields a complete inference algorithm when coupled with any complete search algorithm.
47
Unit Resolution: A First Step towards Completeness
where each is a literal, and and are complementary literals (i.e., one is the negation of the other.
For examples, we can do unit resolution over P2,2 in these two clauses:
to get the following resolvent:
In English: if there’s a pit in one of [1,1], [2,2], and [3,1], and it’s not in [2,2], then it’s in [1,1] or [3,1].
48
Resolution
Generalization of unit resolution
Two clauses can be combined to produce a new clause as follows
49
Conjunctive Normal Form (CNF)
Every sentence of propositional logic is logically equivalent to a conjunction of clauses.
A sentence expressed as a conjunction of clauses is said to be in conjunctive normal form or CNF.
50
Converting to Conjunctive Normal Form (CNF)
Resolution Requires Conjunctive Normal Form (CNF): the input to resolution consists of two clauses (implicit conjunction) that are each disjunctions of literals
A procedure for converting all propositions to conjunctive normal form (CNF)
51
CNF Example
converting the sentence into CNF
52
Resolution-based Theorem Prover
For any sentences A and B in propositional logic, the following algorithm based on resolution can decide whether A ⊨ B
53
A quick example
Suppose our KB is
Now consider the following five queries over this KB:
54
Query | True or False judge by you | Resolution Result | How to interpret Resolution Result |
a | True | empty clause | KB entails a |
¬a | False | no empty clause | KB does not entails ¬a (we cannot interpret it as KB entails a) |
b | True | empty clause | KB entails b |
c | Unknown / False | no empty clause | KB does not entails c (we cannot interpret it as KB entails ¬c) |
¬c | Unknown / False | no empty clause | KB does not entails ¬c (we cannot interpret it as KB entails c) |
Example Proof
KB = (B1,1 ⇔ (P1,2 ∨ P2,1 )) ∧ ¬ B1,1
Prove: ¬ P1,2
CNF: (¬P1,2∨B1,1)∧(¬ B1,1 ∨ P1,2 ∨ P2,1)∧(¬P2,1 ∨ B1,1) ∧ ¬B1,1
55
We got an empty clause, so KB entails ¬ P1,2
Resolution Algorithm
56
Resolution is Complete
Resolution gives a complete inference algorithm when coupled with any complete search algorithm (See AIMA 7.5 for proof).
57
Horn Clauses
In many practical situations, however, the full power of resolution is not needed. Some real-world knowledge bases satisfy certain restrictions on the form of sentences they contain, which enables them to use a more restricted and efficient inference algorithm. On such restricted form is Horn Clause.
Horn Clause, a disjunction of literals of which at most one is positive.
58
Horn Clauses
Every definite clause can be written as an implication whose premise is a conjunction of positive literals and whose conclusion is a single positive literal.
Similar for Goal Clause. Therefore, we can rewrite Horn Clauses into literal, or, (conjunction of literals) ⇒literal.
59
Inference with Horn Clauses
The Inference with Horn clauses can be done efficiently through the forward-chaining and backward-chaining algorithms.
Deciding entailment with Horn clauses can be done in time that is linear in the size of the knowledge base.
60
Forward or Backward Chaining
Require Horn Form
Modus Ponens (for Horn Form): complete for Horn KBs
Forward chaining is sound, and complete for horn clauses
Forward chaining, linear time
Backward chaining potentially much less than linear time
61
CNF, Horn Clauses, Definite Clauses
62
Efficient Model Checking Algorithms for PL
Backward chaining (Horn Clauses)
Forward chaining (Horn Clauses)
There are two more:
DPLL Algorithm (Davis, Putnam, Logemann, Loveland)
WalkSAT
63
Summary
Logical agents apply inference to a KB to derive new facts and make decisions
Propositional Logic
Efficient search algorithms with inference procedures
64