0% found this document useful (0 votes)
21 views47 pages

CSE 381 Lecture 05 Logical Agents LastUpdate Mar 07 2021

Uploaded by

AL-HRBihfc
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views47 pages

CSE 381 Lecture 05 Logical Agents LastUpdate Mar 07 2021

Uploaded by

AL-HRBihfc
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 47

CSE 381: Principles of Artificial Intelligence

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!

• An agent that can reason similarly to humans!


• It reasons based on knowledge to draw a conclusion.

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

• If P is a sentence, P is a sentence (negation)


• If P and Q are sentences, P  Q is a sentence (and , conjunction)
• If P and Q are sentences, P  Q is a sentence (or , disjunction)
• If P and Q are sentences, P  Q is a sentence (if, implication)
• If P and Q are sentences, P  Q is a sentence (iff, biconditional)
Propositional Logic: Semantics
• 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


Truth tables for connectives

OR: P or Q is true or both are true. Implication is always true


XOR: P or Q is true but not both. when the premises are False!
Logical Equivalence
• To manipulate logical sentences, we need some rules.

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}.

• All possible models for N Propositional Symbols: 2N

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

• Model Checking is Sound Inference Algorithm:


• It derives only entailed sentences.
• Model Checking is Complete Inference Algorithm:
• it can derive ALL sentences that are entailed.

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., AA

• Validity is connected to entailment via the Deduction Theorem:


• KB ╞ α if and only if (KB  α) is valid
• Satisfiability is connected to entailment via the following:
• KB ╞ α if and only if (KB α) is unsatisfiable
• (there is no model for which KB=true and α is false)
Validity
• Validity can be proved using the Truth Table

24
Deductive Systems
• Prove entailment KB ⊨α using theorem proving techniques.
• Legitimate generation of new sentences from old.

• Typically require transformation of sentences into a normal form.


• Resolution: sentences are in Conjunctive Normal Form (CNF).
• Forward & Backward Chaining: sentences are Conjunction of Horn Clauses.

• Utilize Logical Equivalence and Inference Rules to derive a proof.

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)
(𝐷𝑜𝑢𝑏𝑙𝑒 𝑁𝑒𝑔𝑎𝑡𝑖𝑜𝑛 𝐸𝑙𝑖𝑚𝑖𝑛𝑎𝑡𝑖𝑜𝑛)
𝑃

PQ
(𝐼𝑚𝑝𝑙𝑖𝑐𝑎𝑡𝑖𝑜𝑛 𝐸𝑙𝑖𝑚𝑖𝑛𝑎𝑡𝑖𝑜𝑛)
𝑃 𝑄

33
Conjunctive Normal Form (CNF)
• Conjunctive Normal Form (CNF):
• Conjunction of Disjunctive Clauses Disjunctive Clause:
Disjunction of literals
Examples:
P𝑄 , 𝐴1𝐴2A3
• CNF Examples:

• (P𝑄)  (𝐴1𝐴2A3) . (P𝑄)  (PRS)  (QSW)


• (P𝑄)  R . (PS)  (QS)

Any KB can be converted into CNF

34
Example: Conversion to CNF
Converting B  (P  Q) to CNF:

1. Eliminate , replacing α  β with (α  β)(β  α).


(B  (P  Q))  ((P  Q)  B)

2. Eliminate , replacing α  β with α β.


(B  (P  Q))  ((P  Q)  B)

3. Move  inwards using de Morgan's rules and double-negation: ¬ 𝛼 ∨ 𝛽 ≡ ¬𝛼 ∧ ¬𝛽

(B  (P  Q))  ((P  Q)  B)

4. Apply distributive law ( over ) and flatten:


(B  P  Q)  (P  B)  (Q  B)
Resolution Sound: derives only entailed sentences.
Complete: derives ALL sentences that are entailed
• Resolution: inference rule for CNF: sound and complete! (see Slide #21)
(A  B  C )
( A ) “If A or B or C is true, but not A, then B or C must be true.”

 (B  C )

(A  B  C ) “If A is false then B or C must be true, or if A is true


(A  D  E ) then D or E must be true, hence since A is either true or
false, B or C or D or E must be true.”

 (B  C  D  E )

(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.

(A∨B) (¬B∨C) (¬C) (¬A) (¬B)

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..

(A∨B) (¬B∨C) (¬C) (¬A) (¬B) (A)

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, ().

(A∨B) (¬B∨C) (¬C) (¬A) (¬B) (A) ( )

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

• Resolution is Sound Inference Algorithm:


• It derives only entailed sentences.
• Resolution is Complete Inference Algorithm:
• it can derive ALL sentences that are entailed.

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

You might also like