AI - Module IV - Propositionallogic

You might also like

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 49

Artificial

Intelligence
Knowledge Representation and
Reasoning

MODULE 4

20/02/2024 KNOWLEDGE REPRESENTATION - AI 1


Contents
 Logical Agents
 Knowledge-based agents
 Logic in general - models and entailment
 Propositional (Boolean) logic
 Propositional Theorem proving
 Agents based on Propositional Logic.
 First Order Predicate Logic – Syntax and Semantics of First Order Logic,
Using First Order Logic, Knowledge representation in First Order Logic.
Inference in First Order Logic – Propositional Vs First Order inference,
 Unification and Lifting,
 Forward chaining,
 Backward chaining,
 Resolution.
20/02/2024 KNOWLEDGE REPRESENTATION - AI 2
Logical Agents

Logical agents tries to implement the reasoning capabilities of human brain


Humans can know “things” and “reason”
To implement logical agents ,two issues are to be handled;
knowledge Representation: How are things stored?
Reasoning: How is the knowledge used?

20/02/2024 KNOWLEDGE REPRESENTATION - AI 3


Knowledge-Based Agents
 Knowledge based agents use logical agent approach to solve a
problem
 Central component of a Knowledge-Based Agent is a Knowledge-
Base ,which contains a set of sentences representing the current
knowledge
 Sentences are expressed using a knowledge representation
language
 Two generic functions:
– TELL - add new sentences (facts) to the KB
– ASK - query what is known from the KB

20/02/2024 KNOWLEDGE REPRESENTATION - AI 4


A simple knowledge-based agent

20/02/2024 KNOWLEDGE REPRESENTATION - AI 5


Contd..
Like all our agents, it takes a percept as input and returns an action.
The agent maintains a knowledge base, KB, which may initially contain some
background knowledge.
Each time the agent program is called, it does three things.
1. It TELLs the knowledgebase what it perceives. MAKE-PERCEPT-
SENTENCE constructs a sentence asserting that the agent perceived the
given percept at the given time
2. It ASKs the knowledge base what action it should perform. MAKE-
ACTION-QUERY constructs a sentence that asks what action should be
done at the current time. In the process of answering this query, extensive
reasoning may be done about the current state of the world, about the
outcomes of possible action sequences, and so on.

20/02/2024 KNOWLEDGE REPRESENTATION - AI 6


Contd..
3.The agent program TELLs the knowledge base which action was
chosen, and the agent executes the action. MAKE-ACTION-SENTENCE
constructs a sentence asserting that the chosen action was executed.

20/02/2024 KNOWLEDGE REPRESENTATION - AI 7


Logic as a KB language

Multi-valued Modal Temporal Non-monotonic


Logic Logic

Higher Order
Probabilistic
Logic First Order

Fuzzy Propositional Logic


Logic

20/02/2024 KNOWLEDGE REPRESENTATION - AI 8


Logics
Logics are formal languages for representing information in knowledge base
Syntax defines the sentences in the language
Semantics define the "meaning" of sentences; defines truth of a sentence with respect
to possible world.
In standard logics, every sentence must be either true or false in each possible world—
there is no “in between.
Entailment and inference are the concepts used to make conclusions from the given
knowledgebase(logical reasoning)

20/02/2024 KNOWLEDGE REPRESENTATION - AI 9


Entailment
Entailment is a logical relationship between two statements where the truth of one statement
necessarily implies the truth of another.
If statement A entails statement B, it means that whenever A is true, B must also be true.It is
represented as
A╞B
 Knowledge base KB entails sentence α if and only if α is true in all worlds where KB is true. It
is represented as
KB ╞ α
 Eg. the KB containing “the Phillies won” and “the Reds won” entails “Either the Phillies won or
the Reds won”
 There fore when KB ╞ α , we can say that αcan be concluded from given KB

20/02/2024 KNOWLEDGE REPRESENTATION - AI 10


Inference and Entailment

 Inference is a procedure that allows new sentences to be derived from a


knowledge base.

 Understanding inference and entailment: think of

Set of all consequences of a KB as a haystack


α as the needle

Entailment is like the needle being in the haystack Inference is like finding it

20/02/2024 KNOWLEDGE REPRESENTATION - AI 11


20/02/2024 KNOWLEDGE REPRESENTATION - AI 12
Desirable properties of inference
algorithms

20/02/2024 KNOWLEDGE REPRESENTATION - AI 13


Propositional Logic simplest logic
 Syntax of PL
 Semantics of PL
 Inference procedure
 By model checking
 By theorem proving

20/02/2024 KNOWLEDGE REPRESENTATION - AI 14


Syntax of Propositional Logic
 Defines the allowable sentences or propositions.

 Definition (Proposition): A proposition is a declarative statement (True or False).


A fact, like “the Sun is hot.” The Sun cannot be both hot and not hot at the
same time. This declarative statement could also be referred to as a proposition.

 “How are you?” or “Hello!” are not propositions. In general,


statement that are questions, commands, or opinions are not
propositions

20/02/2024 KNOWLEDGE REPRESENTATION - AI 15


Contd..
 Atomic proposition:
 Single proposition symbol. Each symbol is a proposition.
 Notation: We use symbols that start with an uppercase letter and may
contain other letters or subscripts, for example: P, Q, R, W1,3 and North .
 There are two proposition symbols with fixed meanings: True is the
always-true proposition and False is the always-false proposition
 Compound proposition: constructed from atomic propositions using
parentheses and logical connectives. There are five connectives in
common use. Negation, conjuction, disjunction, implication
biconditional

20/02/2024 KNOWLEDGE REPRESENTATION - AI 16


Examples of compound/complex propositions
Let p1, and p2 be propositions

• Negation ¬p1 is also a proposition. A literal is either an atomic proposition or its


negation.
E.g., W1,3 is a positive literal, and ¬W1,3 is a negative literal.

• Conjunction p1 ∧ p2. E.g., W1,3 ∧ P3,1

• Disjunction p1 ∨ p2 E.g., W1,3 ∨ P3,1

• Implication(if then) p1 → p2. E.g., W1,3 ∧ P3,1 → ¬W2,2


(⇒)

• Biconditional(if and only if) p1 ↔ p2. E.g., W1,3 ↔ ¬W2,2 ( ⇔)


20/02/2024 KNOWLEDGE REPRESENTATION - AI 17
20/02/2024 KNOWLEDGE REPRESENTATION - AI 18
Semantics of Propositional Logic

 The semantics define the rules to determine the truth of a sentence.


 This is done recursively. All sentences are constructed from atomic sentences and the
five connectives; therefore, we need to specify how to compute the truth of atomic
sentences and how to compute the truth of sentences formed with each of the five
connectives.
 Atomic sentences are easy:
• True is true in every model and False is false in every model.
• The truth value of every other proposition symbol must be specified directly in
the model.

20/02/2024 KNOWLEDGE REPRESENTATION - AI 19


Contd..
 For complex sentences, we have five rules, which hold for any subsentences P
and Q in any model m (here “iff” means “if and only if”):
 ¬ P is true iff P is false in m.
 P ∧ Q is true iff both P and Q are true in m.
 P ∨ Q is true iff either P or Q is true in m.
 P ⇒ Q is true unless P is true and Q is false in m.
 P ⇔ Q is true iff P and Q are both true or both false in m.

20/02/2024 KNOWLEDGE REPRESENTATION - AI 20


Inference procedure: by model checking
In this , We make all possible combinations of proposition symbols in knowledge base . And
find the truth value of all sentences in Knowledge base
A knowledge base is true , when all its sentences have true value.
To check whether a sentence α can be inferred from a given knowledge base, we check the
value of α when KB is true. If value of α is true in all cases ,we can say that α can be inferred
from KB
Suppose we have a KB containing five sentences

20/02/2024 KNOWLEDGE REPRESENTATION - AI 21


To check whether ¬ P1,2 can be inferred from the KB

20/02/2024 KNOWLEDGE REPRESENTATION - AI 22


Contd..
This method is sound and complete
If KB and α contain n symbols in all, then there are 2n models. Thus, the time
complexity of the algorithm is O(2n)

20/02/2024 KNOWLEDGE REPRESENTATION - AI 23


Inference by PROPOSITIONAL THEOREM PROVING

How entailment can be done by theorem proving—applying rules of inference


directly to the sentences in our knowledge base to construct a proof of the
desired sentence without consulting models.
ie, starting from knowledge base , we derive the conclusion using inference
rules.
Four concepts
Logical equivalence
Validity
Satisfiability
Monotonicity

20/02/2024 KNOWLEDGE REPRESENTATION - AI 24


Logical Equivalence
Two propositions p and q are logically equivalent if and only if the columns in
the truth table giving their truth values agree.

• We write this as p ≡ q.

An alternative definition of equivalence is as follows: any two sentences α


and β are equivalent
only if each of them entails the other:
α ≡ β if and only if α |= β and β |= α .
 NOTE: To prove that a statement α |= β , we can use this concept.ie,if the statements are logically equivalent
we can say that α |= β
20/02/2024 KNOWLEDGE REPRESENTATION - AI 25
Validity
A sentence is valid if it is true in all models.
For example, the sentence P ∨ ¬ P is valid. Valid sentences are
also known as tautologies—they are necessarily true.
From our definition of entailment, we can derive the deduction
theorem, which was known to the ancient Greeks:
For any sentences α and β, α |= β if and only if the sentence
(α ⇒ β) is valid(or tautology).In other words, if (α ⇒ β) is valid(or
tautology), then we can say that α |= β

20/02/2024 KNOWLEDGE REPRESENTATION - AI 26


Satisfiability
A sentence is satisfiable if it is true in, or satisfied by, some model
Validity and satisfiability are of course connected: α is valid iff ¬ α
is unsatisfiable; contrapositively, α is satisfiable iff ¬ α is not valid.
We also have the following useful result:
α |= β if and only if the sentence (α ∧ ¬ β) is unsatisfiable. In
other words if (α ∧ ¬ β) is unsatisfiable ,then we can say that α |

20/02/2024 KNOWLEDGE REPRESENTATION - AI 27


Monotonicity
Monotonicity, says that the set of entailed sentences can only increase as
information is added to the knowledge base. ie, For any sentences α and β,
if KB |= α then KB ∧ β |= α

20/02/2024 KNOWLEDGE REPRESENTATION - AI 28


University question
Decide whether each of the following sentences is valid, unsatisfiable, or neither. Verify your
decisions using truth tables or the equivalence rules
i)Smoke ∨ Fire ∨ ¬Fire
ii)((Smoke ∧ Heat) ⇒ Fire) ⇔ ((Smoke ⇒ Fire) ∨ (Heat ⇒ Fire))
iii)(Smoke ⇒ Fire) ⇒ ((Smoke ∧ Heat) ⇒ Fire)
SMOKE FIRE ¬Fire Smoke
TRUTH TABLE METHOD
∨ Fire ∨
¬Fire
(i)Since the result is a tautology, we can say that it s valid.
It is also satisfiable because at least one of them is true T T F T
T F T T
F T F T
F F T T

20/02/2024 KNOWLEDGE REPRESENTATION - AI 29


(ii) Valid
satisfiable
Contd..
Smoke Heat fire Smoke ∧ Heat Smoke ∧ Heat) ⇒ Smoke ⇒ Fire Heat ⇒ Fire ((Smoke ⇒ Fire) ∨ )((Smoke ∧ Heat) ⇒ Fire) ⇔
Fire (Heat ⇒ Fire)) ((Smoke ⇒ Fire) ∨ (Heat ⇒
Fire))
T T T T T T T T T
T T F T F F F F T
T F T F T T T T T
T F F F T F T T T
F T T F T T T T T
F T F F T T F T T
F F T F T T T T T
F F F F T T T T T

20/02/2024 KNOWLEDGE REPRESENTATION - AI 30


General Inference rules
1. Modus Ponens
2. And Elimination
3. Logical equivalences

20/02/2024 KNOWLEDGE REPRESENTATION - AI 31


Inference (Modus Ponens)

20/02/2024 KNOWLEDGE REPRESENTATION - AI 32


And Elimination

ie, if is true , we can infer that each statement is true

20/02/2024 KNOWLEDGE REPRESENTATION - AI 33


Logical equivalences

20/02/2024 KNOWLEDGE REPRESENTATION - AI 34


Example : Propositional theorem proving
The basic strategy use to prove a given statement can be inferred from
the KB is that
First we assume that all statements in KB is true, the by using
the rules , we try to prove that the given statement is also true
Consider that the knowledgebase contains

Prove that ¬ P1,2 can be inferred from the KB


Step1 :We apply biconditional elimination to R2 to obtain

R6: (B1,1 ⇒ (P1,2 ∨ P2,1)) ∧ ((P1,2 ∨ P2,1) ⇒


B1,1) .
20/02/2024 KNOWLEDGE REPRESENTATION - AI 35
Contd..
Step 2: we apply And-Elimination to R6 to obtain
R7: ((P1,2 ∨ P2,1) ⇒ B1,1) .
Step 3: Logical equivalence for contrapositives gives
R8: (¬B1,1 ⇒ ¬(P1,2 ∨ P2,1)) .
Step 4:we can apply Modus Ponens with R8 and the percept R4 (i.e.,
¬B1,1), to obtain
R9 : ¬(P1,2 ∨ P2,1) .
Step 5:we apply De Morgan’s rule, giving the conclusion
R10 : ¬P1,2 ∧ ¬P2,1 .
Step 6:we apply AND elimination we can prove that ¬P1,2 is true
20/02/2024 KNOWLEDGE REPRESENTATION - AI 36
Concept of Unit Resolution

 The unit resolution rule can be generalized to the full resolution rules

 This says that resolution takes two clauses and produces a new clause
containing all the literals of the two original clauses except the two
complementary literals.

20/02/2024 KNOWLEDGE REPRESENTATION - AI 37


DNF and CNF
A normal form is a canonical way to write a logical sentence. It
turns out that any sentence can be written in either of
the universal forms:
DNF: Disjunctive Normal Form Every sentence of propositional logic
◦ OR of ANDs (terms) is logically equivalent to a conjunction
of clauses
e.g. (p∧¬q) ∨ (¬p∧¬r)

CNF: Conjunctive Normal Form


◦ AND of ORs (clauses)
e.g. (p∨¬q) ∧ (¬p∨¬r)

20/02/2024 KNOWLEDGE REPRESENTATION - AI 38


20/02/2024 KNOWLEDGE REPRESENTATION - AI 39
20/02/2024 KNOWLEDGE REPRESENTATION - AI 40
20/02/2024 KNOWLEDGE REPRESENTATION - AI 41
20/02/2024 KNOWLEDGE REPRESENTATION - AI 42
Inference procedure based on Resolution
Inference procedures based on resolution work by using the principle of proof by
contradiction . That is, to show that KB |= α, we show that (KB ∧ ¬ α) is
unsatisfiable. We do this by proving a contradiction.
STEP 1: (KB ∧ ¬ α) is converted into CNF.
STEP2 :Then, 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. The process continues until one of two things happens:
• There are no new clauses that can be added, in which case KB does not entail α; or,
• 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
This algorithm is described in the next slide
20/02/2024 KNOWLEDGE REPRESENTATION - AI 43
20/02/2024 KNOWLEDGE REPRESENTATION - AI 44
Example :proof using resolution
algorithm
Suppose KB contains (B1,1 ⇔ (P1,2 ∨ P2,1)) and ¬ B1,1 and we want to prove that ¬ P1,2 can be inferred from the
KB.
we take the knowledgebase as
(B1,1 ⇔ (P1,2 ∨ P2,1)) ∧ ¬ B1,1

To prove the inference we want to (B1,1 ⇔ (P1,2 ∨ P2,1)) ∧ ¬ B1,1 ∧ ¬ ( ¬ P1,2) is unsatisfiable(ie, all false)
For that , first we have to convert it to CNF .
Then we get
( ¬ B1,1 ∨ P1,2 ∨ P2,1) ∧ ( ¬ P1,2 ∨ B1,1) ∧ ( ¬ P2,1 ∨ B1,1) ∧ ¬ B1,1 ∧ P1,2

20/02/2024 KNOWLEDGE REPRESENTATION - AI 45


1 ( ¬ B1,1 ∨ P1,2 ∨ P2,1) Given

2 ( ¬ P1,2 ∨ B1,1) Given


Contd… 3 ( ¬ P2,1 ∨ B1,1) Given

4 ¬ B1,1 Given

5 P1,2 Given

6 B1,1 Combining 2,5

7 Empty set(ie,false) Combining 4,6

20/02/2024 KNOWLEDGE REPRESENTATION - AI 46


University questions
Consider the following sentence:
[(Food ⇒ Party) ∨ (Drinks ⇒ Party)] ⇒ [(Food ∧ Drinks) ⇒ Party].
Convert this to CNF

20/02/2024 KNOWLEDGE REPRESENTATION - AI 47


Contd..
Question : Suppose my knowledge base contains the fact

And need to prove P is entailed. Use rules of inference to do this.

20/02/2024 KNOWLEDGE REPRESENTATION - AI 48


20/02/2024 KNOWLEDGE REPRESENTATION - AI 49

You might also like