CSE 381 Lecture 05 Logical Agents LastUpdate Mar 07 2021
CSE 381 Lecture 05 Logical Agents LastUpdate Mar 07 2021
Lecture 5:
Logical Agents
*
Logical Agent
• An agent that reasons by operating on internal representations of
knowledge.
• to reason: to draw new conclusions based on existing facts.
• knowledge: facts that can be exploited to generate new facts!
2
Logical Agent
• Example:
• Facts
1. If it didn’t rain, Hani visited Riyadh today. S1 = P Q
2. Hani visited Riyadh or Jeddah today, but not both. S2 = Q XOR T
3. Hani visited Jeddah today. T
• Question:
• did it rain today?
• Inferred facts:
4. Hani did not visit Riyadh. (from fact 3 and 2) ~Q
5. It rained today. (from fact 4 and 1) ~P
3
Logic
• The natural language of reasoning.
• Several Forms, called logic representation languages.
• We introduce Two representation languages:
1. Propositional Logic
2. First-order Logic
• Sentence:
• An assertion about the world in a knowledge representation language.
4
Propositional Logic
• based on propositions: sentences about the world that can be either
true or false.
• the simplest logic – illustrates basic ideas
• A sentence is constructed from Symbols and Connectives.
• Propositional Symbols
• letters (P, Q, R, S1, S2 ,…. ) are used to represent a proposition.
• Logical connectives
• logical symbols (operators) connect propositional symbols
5
Propositional logic: Syntax
You need to
know these !
Model
• assignment of a truth value to every propositional symbol (a "possible
world")
• P: “It is raining.”
• Q: “It is Tuesday.”
• M1 = {P = True, Q = False}.
• M2 = {P = True, Q = True}.
10
Knowledge Base
• The knowledge base (KB) is a set of sentences known by a logical agent.
• i.e., the agent knows the truth values of these sentences
• Example:
• P: It is a Tuesday. Q: It is raining. R: Hani will go for a run.
• KB: S = (P ∧ ¬Q) → R , P , ¬Q
• means the agents knows that {S is True , P is True , ¬Q is True ( ==> Q is False) }
but it does NOT know the truth value of R is.
11
Inference
• Entailment: is the process of deriving new sentences from old ones
(i.e., from the sentences stored in KB).
• Entailment discovers the valid consequences of the KB.
• Entailment verifies that query sentence is consistent with KB.
• KB entails a (new) sentence α (written as KB⊨α) if and only if, in
every model in which KB is true, α is also true.
• Entailment means that one thing follows from another.
12
Entailment
• Example:
• P: It is a Tuesday. Q: It is raining. R: Hani is running.
• KB: S = (P ∧ ¬Q) → R , P , ¬Q
• Does KB⊨R?
• Solution:
• Since the implication S is True, and
• its premises (P ∧ ¬Q) is True (because P and ¬Q both are True)
• Therefore, the consequence R must be True (why?)
• Therefore, KB⊨R
13
Model Checking
• A simple inference algorithm.
• Enumerate all possible models to check that α is true in all models in
which KB is true.
• To determine if KB ⊨α:
1. Enumerate all possible models.
2. If in every model where KB is true, α is true, then KB entails α.
Otherwise, KB does not entail α.
14
Model Checking
• Example:
• P: It is a Tuesday. Q: It is raining. R: Hani is running.
• KB: S = (P ∧ ¬Q) → R , P , ¬Q
• Does KB⊨R?
• Solution: Model Checking
• All possible models = 23 = 8 (KB contains 3 preposition symbols (P, Q, R) )
• KB is true in any model where {P = True , ¬Q = True ( ==> Q = False) , S = True}
• KB is Ture iff (P ∧ ¬Q ∧ S) is True
15
KB is Ture iff P ∧ ¬Q ∧ S = True
P Q R KB?
FALSE FALSE FALSE
FALSE FALSE TRUE
FALSE TRUE FALSE
FALSE TRUE TRUE
TRUE FALSE FALSE
TRUE FALSE TRUE
TRUE TRUE FALSE
TRUE TRUE TRUE
16
KB is Ture iff P ∧ ¬Q ∧ S = True
P Q R KB?
FALSE FALSE FALSE FALSE because P = False in
these models
FALSE FALSE TRUE FALSE
FALSE TRUE FALSE FALSE
FALSE TRUE TRUE FALSE
TRUE FALSE FALSE
TRUE FALSE TRUE
TRUE TRUE FALSE
TRUE TRUE TRUE
17
KB is Ture iff P ∧ ¬Q ∧ S = True
P Q R KB?
FALSE FALSE FALSE FALSE
FALSE FALSE TRUE FALSE
FALSE TRUE FALSE FALSE
FALSE TRUE TRUE FALSE
TRUE FALSE FALSE
TRUE FALSE TRUE
TRUE TRUE FALSE FALSE because ¬Q = False in
TRUE TRUE TRUE FALSE these models
18
KB is Ture iff P ∧ ¬Q ∧ S = True
P Q R KB?
FALSE FALSE FALSE FALSE
FALSE FALSE TRUE FALSE
FALSE TRUE FALSE FALSE
FALSE TRUE TRUE FALSE
because S = False in
TRUE FALSE FALSE FALSE this model
TRUE FALSE TRUE
TRUE TRUE FALSE FALSE
TRUE TRUE TRUE FALSE
19
KB is Ture iff P ∧ ¬Q ∧ S = True
P Q R KB?
FALSE FALSE FALSE FALSE
FALSE FALSE TRUE FALSE
FALSE TRUE FALSE FALSE
FALSE TRUE TRUE FALSE
TRUE FALSE FALSE FALSE
TRUE FALSE TRUE True KB = True and R = True
TRUE TRUE FALSE FALSE
TRUE TRUE TRUE FALSE
Therefore, KB⊨R
20
Model Checking Properties
• Analysis
• For n symbols,
• time complexity is O(2n),
• space complexity is O(n)
• Performance improvement:
• Improved Backtracking: Davis--Putnam-Logemann-Loveland (DPLL)
• Heuristic search in model space: Walksat
21
Logical Agents - II
22
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
• A sentence is satisfiable if it is true in some model
• e.g., A B, C
• A sentence is unsatisfiable if it is false in all models
• e.g., AA
24
Deductive Systems
• Prove entailment KB ⊨α using theorem proving techniques.
• Legitimate generation of new sentences from old.
25
Logical Equivalence
Inference Rules: Modus Ponens
• Modus Ponens (Latin for “mode that affirms”):
P Q , P
𝑄
Means that: whenever any sentences of the form P Q and P are given (i.e.,
both are True), then the sentence Q can be inferred (i.e. Q must be True)
27
Inference Rules: And Elimination-v1
• And Elimination:
𝐴1 𝐴2 … … . 𝐴𝑛
𝐴𝑖
Form a conjunction, we can infer any of the conjuncts.
Whenever the sentence 𝐴1 𝐴2 … … . 𝐴𝑛 is given (i.e., it is True), all the
conjuncts can be inferred (i.e. all 𝐴𝑖 must be True).
28
Inference Rules: And Introduction
• And Introduction:
𝐴1 , 𝐴2 , … … . 𝐴𝑛
𝐴1 𝐴2 … … . 𝐴𝑛
From a list of sentences (it is given they are True), we can infer their conjunction
29
Inference Rules: OR Introduction
• OR Introduction:
𝐴𝑖
𝐴1𝐴2 … … . 𝐴𝑛
From a sentence, we can infer its disjunction with anything else
30
Inference Rules: Unit Resolution
• Unit Resolution:
P𝑄 , P
𝑄
If on of the disjuncts is False, the other must be True
31
Inference Rules: Resolution
• Resolution:
P 𝑄 , 𝑄 𝑅
𝑃𝑅
Because Q cannot be True and False (at the same time), one of the disjuncts
must be True (for the two
32
Inference Rules & Logical Equivalence
• All of the Logical Equivalences (Slide #7) can be used as inference
rules.
• Examples:
(P)
(𝐷𝑜𝑢𝑏𝑙𝑒 𝑁𝑒𝑔𝑎𝑡𝑖𝑜𝑛 𝐸𝑙𝑖𝑚𝑖𝑛𝑎𝑡𝑖𝑜𝑛)
𝑃
PQ
(𝐼𝑚𝑝𝑙𝑖𝑐𝑎𝑡𝑖𝑜𝑛 𝐸𝑙𝑖𝑚𝑖𝑛𝑎𝑡𝑖𝑜𝑛)
𝑃 𝑄
33
Conjunctive Normal Form (CNF)
• Conjunctive Normal Form (CNF):
• Conjunction of Disjunctive Clauses Disjunctive Clause:
Disjunction of literals
Examples:
P𝑄 , 𝐴1𝐴2A3
• CNF Examples:
34
Example: Conversion to CNF
Converting B (P Q) to CNF:
(A B )
𝑃
(A B )
Simplification
𝑃 Empty clause
(Contradiction)
(B B ) B ()
Resolution Algorithm
To determine if KB ⊨α:
• Check if (KB ∧ ¬α) is unsatisfiable?
• If so, then KB ⊨α.
• Otherwise, no entailment.
37
Resolution Algorithm
• To determine if KB ⊨α:
• Convert (KB ∧ ¬α) to Conjunctive Normal Form.
• Keep checking to see if we can use resolution to produce a new clause.
• If ever we produce the empty clause (equivalent to False), we have a contradiction, and
KB ⊨α.
• Otherwise, if we can't add new clauses, no entailment
38
Resolution Algorithm
Example
Does (A∨B) ∧ (¬B∨C) ∧ (¬C) entail A?
• Convert (KB ∧ ¬α) to CNF:
(A∨B) ∧ (¬B∨C) ∧ (¬C) ∧ (¬A)
• Keep checking to see if we can use resolution to produce a new clause:
39
Resolution Algorithm
Example
Does (A∨B) ∧ (¬B∨C) ∧ (¬C) entail A?
• Convert (KB ∧ ¬α) to CNF:
(A∨B) ∧ (¬B∨C) ∧ (¬C) ∧ (¬A)
• Keep checking to see if we can use resolution to produce a new clause:
1. Since we know that C is false (¬C), the only way (¬B ∨ C) can be true is if
¬B is true, too. Thus, we can add (¬B) to our KB.
40
Resolution Algorithm
Example
Does (A∨B) ∧ (¬B∨C) ∧ (¬C) entail A?
• Convert (KB ∧ ¬α) to CNF:
(A∨B) ∧ (¬B∨C) ∧ (¬C) ∧ (¬A)
• Keep checking to see if we can use resolution to produce a new clause:
2. since we know (¬B), the only way (A ∨ B) can be true is if A is true. Thus, we
can add (A) to our KB..
41
Resolution Algorithm
Example
Does (A∨B) ∧ (¬B∨C) ∧ (¬C) entail A?
• Convert (KB ∧ ¬α) to CNF:
(A∨B) ∧ (¬B∨C) ∧ (¬C) ∧ (¬A)
• Keep checking to see if we can use resolution to produce a new clause:
3. Now, KB has two complementary literals, (A) and (¬A). We resolve them,
arriving at the empty set, ().
42
Resolution Algorithm
Example
Does (A∨B) ∧ (¬B∨C) ∧ (¬C) entail A?
• Convert (KB ∧ ¬α) to CNF:
(A∨B) ∧ (¬B∨C) ∧ (¬C) ∧ (¬A)
• Keep checking to see if we can use resolution to produce a new clause:
(A∨B) (¬B∨C) (¬C) (¬A) (¬B) (A) ( )
• Since we produced the empty clause ( ), we have a contradiction
• Therefore, KB ⊨α
43
Resolution Algorithm Properties
• Analysis
• Resolution can be exponential in space and time (in worse case)
• Performance improvement:
• If we can reduce all clauses to “Horn clauses” resolution is linear in space and time.
• Using Forward & Backward Chaining algorithms
44
Summary
• Intelligent agents need knowledge about the world in order to reach good decisions.
• Knowledge is contained in agents in the form of sentences in a knowledge representation
language that are stored in a knowledge base.
• A knowledge-based agent is composed of:
• a knowledge base, and
• an inference mechanism.
• A knowledge-based agent operates by:
• storing sentences about the world in its knowledge base,
• using the inference mechanism to infer new sentences, and
• using these sentences to decide what action to take.
• A representation language is defined by:
• syntax, which specifies the structure of sentences, and
• semantics, which defines the truth of each sentence in each possible world or model.
45
Summary
• The relationship of entailment between sentences is crucial to our understanding of reasoning.
• A sentence S entails another sentence α if , α is true in all Models where S is true.
• Equivalent definitions of entailment include:
• the validity of the sentence S ==> α , and
• the unsatisfiability of the sentence S α .
• Inference is the process of deriving new sentences from old ones.
• Sound inference algorithms derive only sentences that are entailed.
• Complete algorithms derive all sentences that are entailed.
• Propositional logic is a very simple language consisting of proposition symbols and logical
connectives. It can handle propositions that are known true, known false, or completely unknown.
• The set of possible models, given a fixed propositional vocabulary, is finite, so entailment can be
checked by enumerating models. Efficient model-checking inference algorithms for propositional
logic include backtracking and local-search methods and can often solve large problems very
quickly.
46
Summary
• Inference rules are patterns of sound inference that can be used to find proofs.
• The resolution rule yields a complete inference algorithm for knowledge bases that are
expressed in conjunctive normal form.
• Forward chaining and backward chaining are very natural reasoning algorithms for
knowledge bases in Horn form.
47