Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
158 views36 pages

AI Unit-II Chapter-III Propositional Logic

AI Unit-II Chapter-III Propositional Logic

Uploaded by

Priya Mannem
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)
158 views36 pages

AI Unit-II Chapter-III Propositional Logic

AI Unit-II Chapter-III Propositional Logic

Uploaded by

Priya Mannem
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/ 36

ARTIFICIAL INTELLIGENCE

UNIT - II
Chapter-III: Propositional Logic: Knowledge-Based Agents, The Wumpus World, Logic,
Propositional Logic, Propositional Theorem Proving: Inference and proofs, Proof by resolution,
Horn clauses and definite clauses, Forward and backward chaining, Effective Propositional
Model Checking, Agents Based on Propositional Logic.

KNOWLEDGE-BASED AGENT IN ARTIFICIAL INTELLIGENCE


o An intelligent agent needs knowledge about the real world for taking decisions and reasoning to act
efficiently.
o Knowledge-based agents are those agents who have the capability of maintaining an internal state of
knowledge, reason over that knowledge, update their knowledge after observations and take actions.
These agents can represent the world with some formal representation and act intelligently.
o Knowledge-based agents are composed of two main parts:
o Knowledge-base and
o Inference system.

A knowledge-based agent must able to do the following:


o An agent should be able to represent states, actions, etc.
o An agent should be able to incorporate new percepts.
o An agent can update the internal representation of the world
o An agent can deduce the internal representation of the world
o An agent can deduce appropriate actions.

The architecture of knowledge-based agent:

Mr. Mohammed Afzal, Asst. Professor in AIML


Mob: +91-8179700193, Email: [email protected]
 The above diagram is representing a generalized architecture for a knowledge-based agent. The
knowledge-based agent (KBA) take input from the environment by perceiving the environment. The
input is taken by the inference engine of the agent and which also communicate with KB to decide as
per the knowledge store in KB. The learning element of KBA regularly updates the KB by learning
new knowledge.
 Knowledge base: Knowledge-base is a central component of a knowledge-based agent, it is also
known as KB. It is a collection of sentences (here 'sentence' is a technical term and it is not identical
to sentence in English). These sentences are expressed in a language which is called a knowledge
representation language. The Knowledge-base of KBA stores fact about the world.

Why use a knowledge base?


 Knowledge-base is required for updating knowledge for an agent to learn with experiences and take
action as per the knowledge.
Inference system
 Inference means deriving new sentences from old. Inference system allows us to add a new sentence
to the knowledge base. A sentence is a proposition about the world. Inference system applies logical
rules to the KB to deduce new information.
 Inference system generates new facts so that an agent can update the KB. An inference system works
mainly in two rules which are given as:
o Forward chaining
o Backward chaining
Operations Performed by KBA
Following are three operations which are performed by KBA in order to show the intelligent
behavior:

1. TELL: This operation tells the knowledge base what it perceives from the environment.
2. ASK: This operation asks the knowledge base what action it should perform.
3. Perform: It performs the selected action.

A generic knowledge-based agent:

 Following is the structure outline of a generic knowledge-based agents program:

function KB-AGENT(percept):

Mr. Mohammed Afzal, Asst. Professor in AIML


Mob: +91-8179700193, Email: [email protected]
persistent: KB, a knowledge base
t, a counter, initially 0, indicating time
TELL(KB, MAKE-PERCEPT-SENTENCE(percept, t))
Action = ASK(KB, MAKE-ACTION-QUERY(t))
TELL(KB, MAKE-ACTION-SENTENCE(action, t))
t=t+1
return action

 The knowledge-based agent takes percept as input and returns an action as output. The agent
maintains the knowledge base, KB, and it initially has some background knowledge of the real
world. It also has a counter to indicate the time for the whole process, and this counter is initialized
with zero.
 Each time when the function is called, it performs its three operations:
o Firstly, it TELLs the KB what it perceives.
o Secondly, it asks KB what action it should take
o Third agent program TELLS the KB that which action was chosen.
 The MAKE-PERCEPT-SENTENCE generates a sentence as setting that the agent perceived the
given percept at the given time.
 The MAKE-ACTION-QUERY generates a sentence to ask which action should be done at the
current time.
 MAKE-ACTION-SENTENCE generates a sentence which asserts that the chosen action was
executed.
Various levels of knowledge-based agent:
 A knowledge-based agent can be viewed at different levels which are given below:
1. Knowledge level
 Knowledge level is the first level of knowledge-based agent, and in this level, we need to
specify what the agent knows, and what the agent goals are.
 With these specifications, we can fix its behavior.
For example, suppose an automated taxi agent needs to go from a station A to station B, and
he knows the way from A to B, so this comes at the knowledge level.
2. Logical level:
 At this level, we understand that how the knowledge representation of knowledge is stored.
At this level, sentences are encoded into different logics.
Mr. Mohammed Afzal, Asst. Professor in AIML
Mob: +91-8179700193, Email: [email protected]
 At the logical level, an encoding of knowledge into logical sentences occurs. At the logical
level we can expect to the automated taxi agent to reach to the destination B.
3. Implementation level:
 This is the physical representation of logic and knowledge. At the implementation level agent
perform actions as per logical and knowledge level.
 At this level, an automated taxi agent actually implements his knowledge and logic so that he
can reach to the destination.
Approaches to designing a knowledge-based agent:
 There are mainly two approaches to build a knowledge-based agent:
1. Declarative approach: We can create a knowledge-based agent by initializing with an
empty knowledge base and telling the agent all the sentences with which we want to start
with. This approach is called Declarative approach.
2. Procedural approach: In the procedural approach, we directly encode desired behaviour as
a program code. Which means we just need to write a program that already encodes the
desired behaviour or agent.
 However, in the real world, a successful agent can be built by combining both declarative and
procedural approaches, and declarative knowledge can often be compiled into more efficient
procedural code.

PROPOSITIONAL LOGIC IN ARTIFICIAL INTELLIGENCE


 Propositional logic (PL) is the simplest form of logic where all the statements are made by
propositions.
 A proposition is a declarative statement which is either true or false. It is a technique of knowledge
representation in logical and mathematical form.
Example:
a) It is Sunday.
b) The Sun rises from West (False proposition)
c) 3+3= 7(False proposition)
d) 5 is a prime number.

Mr. Mohammed Afzal, Asst. Professor in AIML


Mob: +91-8179700193, Email: [email protected]
Following are some basic facts about propositional logic:
o Propositional logic is also called Boolean logic as it works on 0 and 1.
o In propositional logic, we use symbolic variables to represent the logic, and we can use any symbol
for a representing a proposition, such A, B, C, P, Q, R, etc.
o Propositions can be either true or false, but it cannot be both.
o Propositional logic consists of an object, relations or function, and logical connectives.
o These connectives are also called logical operators.
o The propositions and connectives are the basic elements of the propositional logic.
o Connectives can be said as a logical operator which connects two sentences.
o A proposition formula which is always true is called tautology, and it is also called a valid sentence.
o A proposition formula which is always false is called Contradiction.
o A proposition formula which has both true and false values is called
o Statements which are questions, commands, or opinions are not propositions such as "Where is
Rohini", "How are you", "What is your name", are not propositions.
Syntax of propositional logic:
 The syntax of propositional logic defines the allowable sentences for the knowledge representation.
There are two types of Propositions:
a) Atomic Proposition: Atomic propositions are the simple propositions. It consists of a single
proposition symbol. These are the sentences which must be either true or false.
Example:
a) 2+2 is 4, it is an atomic proposition as it is a true fact.
b) "The Sun is cold" is also a proposition as it is a false fact.

b) Compound proposition: Compound propositions are constructed by combining simpler or


atomic propositions, using parenthesis and logical connectives.

Example:
a) "It is raining today, and street is wet."
b) "Ankit is a doctor, and his clinic is in Mumbai."

Logical Connectives:
 Logical connectives are used to connect two simpler propositions or representing a sentence
logically. We can create compound propositions with the help of logical connectives.
 There are mainly five connectives, which are given as follows:
Mr. Mohammed Afzal, Asst. Professor in AIML
Mob: +91-8179700193, Email: [email protected]
1. Negation: A sentence such as ¬ P is called negation of P. A literal can be either Positive literal
or negative literal.
2. Conjunction: A sentence which has ∧ connective such as, P ∧ Q is called a conjunction.
Example: Rohan is intelligent and hardworking. It can be written as,
P= Rohan is intelligent,
Q= Rohan is hardworking. → P∧ Q.
3. Disjunction: A sentence which has ∨ connective, such as P ∨ Q. is called disjunction, where P
and Q are the propositions.
Example: "Ritika is a doctor or Engineer",
Here P= Ritika is Doctor. Q= Ritika is Doctor, so we can write it as P ∨ Q.
4. Implication: A sentence such as P → Q, is called an implication. Implications are also known as
if-then rules. It can be represented as
If it is raining, then the street is wet.
Let P= It is raining, and Q= Street is wet, so it is represented as P → Q
5. Biconditional: A sentence such as P⇔ Q is a Biconditional sentence, example If I am
breathing, then I am alive
P= I am breathing, Q= I am alive, it can be represented as P ⇔ Q.

Following is the summarized table for Propositional Logic Connectives:

Truth Table:
 In propositional logic, we need to know the truth values of propositions in all possible scenarios. We
can combine all the possible combination with logical connectives, and the representation of these
combinations in a tabular format is called Truth table.
 Following are the truth table for all logical connectives:

Mr. Mohammed Afzal, Asst. Professor in AIML


Mob: +91-8179700193, Email: [email protected]
Truth table with three propositions:
 We can build a proposition composing three propositions P, Q, and R. This truth table is made-up of
8n Tuples as we have taken three proposition symbols.

Mr. Mohammed Afzal, Asst. Professor in AIML


Mob: +91-8179700193, Email: [email protected]
Precedence of connectives:
 Just like arithmetic operators, there is a precedence order for propositional connectors or logical
operators. This order should be followed while evaluating a propositional problem.
 Following is the list of the precedence order for operators:

Precedence Operators

First Precedence Parenthesis

Second Precedence Negation

Third Precedence Conjunction(AND)

Fourth Precedence Disjunction(OR)

Fifth Precedence Implication

Six Precedence Biconditional

Logical equivalence:
 Logical equivalence is one of the features of propositional logic. Two propositions are said to be
logically equivalent if and only if the columns in the truth table are identical to each other.
 Let's take two propositions A and B, so for logical equivalence, we can write it as A⇔B. In below
truth table we can see that column for ¬A∨ B and A→B, are identical hence A is Equivalent to B.

Mr. Mohammed Afzal, Asst. Professor in AIML


Mob: +91-8179700193, Email: [email protected]
Properties of Operators:
o Commutativity:
o P∧ Q= Q ∧ P, or
o P ∨ Q = Q ∨ P.
o Associativity:
o (P ∧ Q) ∧ R= P ∧ (Q ∧ R),
o (P ∨ Q) ∨ R= P ∨ (Q ∨ R)
o Identity element:
o P ∧ True = P,
o P ∨ True= True.
o Distributive:
o P∧ (Q ∨ R) = (P ∧ Q) ∨ (P ∧ R).
o P ∨ (Q ∧ R) = (P ∨ Q) ∧ (P ∨ R).
o DE Morgan's Law:
o ¬ (P ∧ Q) = (¬P) ∨ (¬Q)
o ¬ (P ∨ Q) = (¬ P) ∧ (¬Q).
o Double-negation elimination:
o ¬ (¬P) = P.

Limitations of Propositional logic:

o We cannot represent relations like ALL, some, or none with propositional logic. Example:
1. All the girls are intelligent.
2. Some apples are sweet.
o Propositional logic has limited expressive power.
o In propositional logic, we cannot describe statements in terms of their properties or logical
relationships.

RULES OF INFERENCE IN ARTIFICIAL INTELLIGENCE

Inference:
 In artificial intelligence, we need intelligent computers which can create new logic from old logic or
by evidence, so generating the conclusions from evidence and facts is termed as Inference.

Mr. Mohammed Afzal, Asst. Professor in AIML


Mob: +91-8179700193, Email: [email protected]
Inference rules:
 Inference rules are the templates for generating valid arguments. Inference rules are applied to derive
proofs in artificial intelligence, and the proof is a sequence of the conclusion that leads to the desired
goal.
 In inference rules, the implication among all the connectives plays an important role. Following are
some terminologies related to inference rules:
o Implication: It is one of the logical connectives which can be represented as P → Q. It is a
Boolean expression.
o Converse: The converse of implication, which means the right-hand side proposition goes to
the left-hand side and vice-versa. It can be written as Q → P.
o Contrapositive: The negation of converse is termed as contrapositive, and it can be
represented as ¬ Q → ¬ P.
o Inverse: The negation of implication is called inverse. It can be represented as ¬ P → ¬ Q.
 From the above term some of the compound statements are equivalent to each other, which we can
prove using truth table:

 Hence from the above truth table, we can prove that P → Q is equivalent to ¬ Q → ¬ P, and Q→ P is
equivalent to ¬ P → ¬ Q.

Types of Inference rules:


1. Modus Ponens:
 The Modus Ponens rule is one of the most important rules of inference, and it states that if P and P
→ Q is true, then we can infer that Q will be true. It can be represented as:

Example:
o Statement-1: "If I am sleepy then I go to bed" ==> P→ Q
o Statement-2: "I am sleepy" ==> P

Mr. Mohammed Afzal, Asst. Professor in AIML


Mob: +91-8179700193, Email: [email protected]
o Conclusion: "I go to bed." ==> Q.
Hence, we can say that, if P→ Q is true and P is true then Q will be true.
Proof by Truth table:

2. Modus Tollens:
 The Modus Tollens rule state that if P→ Q is true and ¬ Q is true, then ¬ P will also true. It can be
represented as:

Example:
o Statement-1: "If I am sleepy then I go to bed" ==> P→ Q
o Statement-2: "I do not go to the bed."==> ~Q
o Statement-3: Which infers that "I am not sleepy" => ~P
Proof by Truth table:

3. Hypothetical Syllogism:
 The Hypothetical Syllogism rule state that if P→R is true whenever P→Q is true, and Q→R is true.
It can be represented as the following notation:
Example:
o Statement-1: If you have my home key then you can unlock my home. P→Q
o Statement-2: If you can unlock my home then you can take my money. Q→R
o Conclusion: If you have my home key then you can take my money. P→R

Mr. Mohammed Afzal, Asst. Professor in AIML


Mob: +91-8179700193, Email: [email protected]
Proof by truth table:

4. Disjunctive Syllogism:
 The Disjunctive syllogism rule state that if P∨Q is true, and ¬P is true, then Q will be true. It can be
represented as:

Example:
o Statement-1: Today is Sunday or Monday. ==>P∨Q
o Statement-2: Today is not Sunday. ==> ¬P
o Conclusion: Today is Monday. ==> Q
Proof by truth-table:

5. Addition:
 The Addition rule is one the common inference rule, and it states that If P is true, then P∨Q will be
true.

Example:
o Statement: I have a vanilla ice-cream. ==> P
o Statement-2: I have Chocolate ice-cream.
o Conclusion: I have vanilla or chocolate ice-cream. ==> (P∨Q)

Mr. Mohammed Afzal, Asst. Professor in AIML


Mob: +91-8179700193, Email: [email protected]
Proof by Truth-Table:

6. Simplification:
 The simplification rule state that if P∧ Q is true, then Q or P will also be true. It can be represented
as:

Proof by Truth-Table:

7. Resolution:
 The Resolution rule state that if P∨Q and ¬ P∧R is true, then Q∨R will also be true. It can be
represented as

Proof by Truth-Table:

Mr. Mohammed Afzal, Asst. Professor in AIML


Mob: +91-8179700193, Email: [email protected]
THE WUMPUS WORLD IN ARTIFICIAL INTELLIGENCE
Wumpus world:
 The Wumpus world is a simple world example to illustrate the worth of a knowledge-based agent
and to represent knowledge representation. It was inspired by a video game Hunt the Wumpus by
Gregory Yob in 1973.
 The Wumpus world is a cave which has 4/4 rooms connected with passageways. So there are total
16 rooms which are connected with each other.
 We have a knowledge-based agent who will go forward in this world. The cave has a room with a
beast which is called Wumpus, who eats anyone who enters the room. The Wumpus can be shot by
the agent, but the agent has a single arrow.
 In the Wumpus world, there are some Pits rooms which are bottomless, and if agent falls in Pits,
then he will be stuck there forever. The exciting thing with this cave is that in one room there is a
possibility of finding a heap of gold.
 So, the agent goal is to find the gold and climb out the cave without fallen into Pits or eaten by
Wumpus. The agent will get a reward if he comes out with gold, and he will get a penalty if eaten by
Wumpus or falls in the pit.
 Following is a sample diagram for representing the Wumpus world. It is showing some rooms with
Pits, one room with Wumpus and one agent at (1, 1) square location of the world.

There are also some components which can help the agent to navigate the cave. These components are
given as follows:

a) The rooms adjacent to the Wumpus room are smelly, so that it would have some stench.
Mr. Mohammed Afzal, Asst. Professor in AIML
Mob: +91-8179700193, Email: [email protected]
b) The room adjacent to PITs has a breeze, so if the agent reaches near to PIT, then he will perceive the
breeze.
c) There will be glitter in the room if and only if the room has gold.
d) The Wumpus can be killed by the agent if the agent is facing to it, and Wumpus will emit a horrible
scream which can be heard anywhere in the cave.

PEAS description of Wumpus world:


 To explain the Wumpus world we have given PEAS description as below:
Performance measure:
o +1000 reward points if the agent comes out of the cave with the gold.
o -1000 points penalty for being eaten by the Wumpus or falling into the pit.
o -1 for each action, and -10 for using an arrow.
o The game ends if either agent dies or came out of the cave.
Environment:
o A 4*4 grid of rooms.
o The agent initially in room square [1, 1], facing toward the right.
o Location of Wumpus and gold are chosen randomly except the first square [1,1].
o Each square of the cave can be a pit with probability 0.2 except the first square.
Actuators:
o Left turn,
o Right turn
o Move forward
o Grab
o Release
o Shoot.
Sensors:
o The agent will perceive the stench if he is in the room adjacent to the Wumpus. (Not
diagonally).
o The agent will perceive breeze if he is in the room directly adjacent to the Pit.
o The agent will perceive the glitter in the room where the gold is present.
o The agent will perceive the bump if he walks into a wall.
o When the Wumpus is shot, it emits a horrible scream which can be perceived anywhere in the
cave.

Mr. Mohammed Afzal, Asst. Professor in AIML


Mob: +91-8179700193, Email: [email protected]
o These percepts can be represented as five element list, in which we will have different indicators
for each sensor.
o Example if agent perceives stench, breeze, but no glitter, no bump, and no scream then it can be
represented as:
[Stench, Breeze, None, None, None].

The Wumpus world Properties:


o Partially observable: The Wumpus world is partially observable because the agent can only
perceive the close environment such as an adjacent room.
o Deterministic: It is deterministic, as the result and outcome of the world are already known.
o Sequential: The order is important, so it is sequential.
o Static: It is static as Wumpus and Pits are not moving.
o Discrete: The environment is discrete.
o One agent: The environment is a single agent as we have one agent only and Wumpus is not
considered as an agent.
Exploring the Wumpus world:
 Now we will explore the Wumpus world and will determine how the agent will find its goal by
applying logical reasoning.
Agent's First step:
 Initially, the agent is in the first room or on the square [1,1], and we already know that this room is
safe for the agent, so to represent on the below diagram (a) that room is safe we will add symbol OK.
 Symbol A is used to represent agent, symbol B for the breeze, G for Glitter or gold, V for the visited
room, P for pits, W for Wumpus.
 At Room [1,1] agent does not feel any breeze or any Stench which means the adjacent squares are
also OK.

Mr. Mohammed Afzal, Asst. Professor in AIML


Mob: +91-8179700193, Email: [email protected]
Agent's second Step:
 Now agent needs to move forward, so it will either move to [1, 2], or [2,1]. Let's suppose agent
moves to the room [2, 1], at this room agent perceives some breeze which means Pit is around this
room. The pit can be in [3, 1], or [2,2], so we will add symbol P? to say that, is this Pit room?
 Now agent will stop and think and will not make any harmful move. The agent will go back to the
[1, 1] room. The room [1,1], and [2,1] are visited by the agent, so we will use symbol V to represent
the visited squares.
Agent's third step:
 At the third step, now agent will move to the room [1,2] which is OK. In the room [1,2] agent
perceives a stench which means there must be a Wumpus nearby. But Wumpus cannot be in the
room [1,1] as by rules of the game, and also not in [2,2] (Agent had not detected any stench when he
was at [2,1]).
 Therefore, agent infers that Wumpus is in the room [1,3], and in current state, there is no breeze
which means in [2,2] there is no Pit and no Wumpus.
 So, it is safe, and we will mark it OK, and the agent moves further in [2,2].

Agent's fourth step:


 At room [2,2], here no stench and no breezes present so let's suppose agent decides to move to [2,3].
At room [2,3] agent perceives glitter, so it should grab the gold and climb out of the cave.

Knowledge-base for Wumpus world


 As in the previous topic we have learned about the wumpus world and how a knowledge-based agent
evolves the world. Now in this topic, we will create a knowledge base for the wumpus world, and
will derive some proves for the Wumpus-world using propositional logic.

Mr. Mohammed Afzal, Asst. Professor in AIML


Mob: +91-8179700193, Email: [email protected]
 The agent starts visiting from first square [1, 1], and we already know that this room is safe for the
agent. To build a knowledge base for wumpus world, we will use some rules and atomic
propositions. We need symbol [i, j] for each location in the wumpus world, where i is for the
location of rows, and j for column location.

Atomic proposition variable for Wumpus world:


o Let Pi,j be true if there is a Pit in the room [i, j].
o Let Bi,j be true if agent perceives breeze in [i, j], (dead or alive).
o Let Wi,j be true if there is wumpus in the square[i, j].
o Let Si,j be true if agent perceives stench in the square [i, j].
o Let Vi,j be true if that square[i, j] is visited.
o Let Gi,j be true if there is gold (and glitter) in the square [i, j].
o Let OKi,j be true if the room is safe.

Some Propositional Rules for the wumpus world:

Mr. Mohammed Afzal, Asst. Professor in AIML


Mob: +91-8179700193, Email: [email protected]
Representation of Knowledgebase for Wumpus world:
 Following is the Simple KB for wumpus world when an agent moves from room [1, 1], to room
[2,1]:

 Here in the first row, we have mentioned propositional variables for room[1,1], which is showing
that room does not have wumpus(¬ W11), no stench (¬S11), no Pit(¬P11), no breeze(¬B11), no gold
(¬G11), visited (V11), and the room is Safe(OK11).
 In the second row, we have mentioned propositional variables for room [1,2], which is showing that
there is no wumpus, stench and breeze are unknown as an agent has not visited room [1,2], no Pit,
not visited yet, and the room is safe.
 In the third row we have mentioned propositional variable for room[2,1], which is showing that there
is no wumpus(¬ W21), no stench (¬S21), no Pit (¬P21), Perceives breeze(B21), no glitter(¬G21),
visited (V21), and room is safe (OK21).

Prove that Wumpus is in the room (1, 3)


 We can prove that wumpus is in the room (1, 3) using propositional rules which we have derived for
the wumpus world and using inference rule.
o Apply Modus Ponens with ¬S11 and R1:
 We will firstly apply MP rule with R1 which is ¬S11 → ¬ W11 ^ ¬ W12 ^ ¬ W21,
and ¬S11 which will give the output ¬ W11 ^ W12 ^ W12.

o Apply And-Elimination Rule:


 After applying And-elimination rule to ¬ W11 ∧ ¬ W12 ∧ ¬ W21, we will get three statements:
¬ W11, ¬ W12, and ¬W21.
o Apply Modus Ponens to ¬S21, and R2:

Mr. Mohammed Afzal, Asst. Professor in AIML


Mob: +91-8179700193, Email: [email protected]
 Now we will apply Modus Ponens to ¬S21 and R2 which is ¬S21 → ¬ W21 ∧¬ W22 ∧ ¬ W31,
which will give the Output as ¬ W21 ∧ ¬ W22 ∧¬ W31

o Apply And -Elimination rule:


 Now again apply And-elimination rule to ¬ W21 ∧ ¬ W22 ∧¬ W31, We will get three
statements:
¬ W21, ¬ W22, and ¬ W31.
o Apply MP to S12 and R4:
 Apply Modus Ponens to S12 and R4 which is S12 → W13 ∨. W12 ∨. W22 ∨.W11, we will get
the output as W13∨ W12 ∨ W22 ∨.W11.

o Apply Unit resolution on W13 ∨ W12 ∨ W22 ∨W11 and ¬ W11 :


 After applying Unit resolution formula on W13 ∨ W12 ∨ W22 ∨W11 and ¬ W11 we will get
W13 ∨ W12 ∨ W22.

o Apply Unit resolution on W13 ∨ W12 ∨ W22 and ¬ W22 :


 After applying Unit resolution on W13 ∨ W12 ∨ W22, and ¬W22, we will get W13 ∨ W12 as
output.

Mr. Mohammed Afzal, Asst. Professor in AIML


Mob: +91-8179700193, Email: [email protected]
o Apply Unit Resolution on W13 ∨ W12 and ¬ W12 :
 After Applying Unit resolution on W13 ∨ W12 and ¬ W12, we will get W13 as an output,
hence it is proved that the Wumpus is in the room [1, 3].

FORWARD CHAINING AND BACKWARD CHAINING IN AI


 In artificial intelligence, forward and backward chaining is one of the important topics, but before
understanding forward and backward chaining lets first understand that from where these two terms
came.
Inference engine:
 The inference engine is the component of the intelligent system in artificial intelligence, which
applies logical rules to the knowledge base to infer new information from known facts.
 The first inference engine was part of the expert system. Inference engine commonly proceeds in
two modes, which are:
a) Forward chaining
b) Backward chaining
Horn Clause and Definite clause:
 Horn clause and definite clause are the forms of sentences, which enables knowledge base to use a
more restricted and efficient inference algorithm.
 Logical inference algorithms use forward and backward chaining approaches, which require KB in
the form of the first-order definite clause.
o Definite clause: A clause which is a disjunction of literals with exactly one positive literal is
known as a definite clause or strict horn clause.

Mr. Mohammed Afzal, Asst. Professor in AIML


Mob: +91-8179700193, Email: [email protected]
o Horn clause: A clause which is a disjunction of literals with at most one positive literal is
known as horn clause. Hence all the definite clauses are horn clauses.
o Example: (¬ p V ¬ q V k). It has only one positive literal k.
It is equivalent to p ∧ q → k.

FORWARD CHAINING
 Forward chaining is also known as a forward deduction or forward reasoning method when using an
inference engine. Forward chaining is a form of reasoning which start with atomic sentences in the
knowledge base and applies inference rules (Modus Ponens) in the forward direction to extract more
data until a goal is reached.
 The Forward-chaining algorithm starts from known facts, triggers all rules whose premises are
satisfied, and add their conclusion to the known facts. This process repeats until the problem is
solved.
Properties of Forward-Chaining:
o It is a down-up approach, as it moves from bottom to top.
o It is a process of making a conclusion based on known facts or data, by starting from the initial
state and reaches the goal state.
o Forward-chaining approach is also called as data-driven as we reach to the goal using available
data.
o Forward -chaining approach is commonly used in the expert system, such as CLIPS, business, and
production rule systems.
Consider the following famous example which we will use in both approaches:
Example:
 "As per the law, it is a crime for an American to sell weapons to hostile nations. Country A,
an enemy of America, has some missiles, and all the missiles were sold to it by Robert, who
is an American citizen."
 Prove that "Robert is criminal."
 To solve the above problem, first, we will convert all the above facts into first-order definite
clauses, and then we will use a forward-chaining algorithm to reach the goal.
Facts Conversion into FOL:
o It is a crime for an American to sell weapons to hostile nations. (Let's say p, q, and r are variables)
American (p) ∧ weapon(q) ∧ sells (p, q, r) ∧ hostile(r) → Criminal(p) ...(1)

Mr. Mohammed Afzal, Asst. Professor in AIML


Mob: +91-8179700193, Email: [email protected]
o Country A has some missiles. ?p Owns(A, p) ∧ Missile(p). It can be written in two definite clauses
by using Existential Instantiation, introducing new Constant T1.
Owns(A, T1) ......(2)
Missile(T1) .......(3)
o All of the missiles were sold to country A by Robert.
?p Missiles(p) ∧ Owns (A, p) → Sells (Robert, p, A) ......(4)
o Missiles are weapons.
Missile(p) → Weapons (p) .......(5)
o Enemy of America is known as hostile.
Enemy(p, America) →Hostile(p) ........(6)
o Country A is an enemy of America.
Enemy (A, America) .........(7)
o Robert is American
American(Robert). ..........(8)

Forward chaining proof:


Step-1:
 In the first step we will start with the known facts and will choose the sentences which do not have
implications, such as: American(Robert), Enemy(A, America), Owns(A, T1), and Missile(T1).
 All these facts will be represented as below.

Step-2:
 At the second step, we will see those facts which infer from available facts and with satisfied
premises.
 Rule-(1) does not satisfy premises, so it will not be added in the first iteration.
 Rule-(2) and (3) are already added.
 Rule-(4) satisfy with the substitution {p/T1}, so Sells (Robert, T1, A) is added, which infers from the
conjunction of Rule (2) and (3).
 Rule-(6) is satisfied with the substitution(p/A), so Hostile(A) is added and which infers from Rule-(7).

Mr. Mohammed Afzal, Asst. Professor in AIML


Mob: +91-8179700193, Email: [email protected]
Step-3:
 At step-3, as we can check Rule-(1) is satisfied with the substitution {p/Robert, q/T1, r/A}, so we
can add Criminal(Robert) which infers all the available facts.
 And hence we reached our goal statement.

 Hence it is proved that Robert is Criminal using forward chaining approach.

BACKWARD CHAINING:
 Backward-chaining is also known as a backward deduction or backward reasoning method when
using an inference engine.
 A backward chaining algorithm is a form of reasoning, which starts with the goal and works
backward, chaining through rules to find known facts that support the goal.
Properties of backward chaining:
o It is known as a top-down approach.
o Backward-chaining is based on modus ponens inference rule.
o In backward chaining, the goal is broken into sub-goal or sub-goals to prove the facts true.
o It is called a goal-driven approach, as a list of goals decides which rules are selected and used.
o Backward -chaining algorithm is used in game theory, automated theorem proving tools, inference
engines, proof assistants, and various AI applications.
o The backward-chaining method mostly used a depth-first search strategy for proof.
Example:
In backward-chaining, we will use the same above example, and will rewrite all the rules.
o American (p) ∧ weapon(q) ∧ sells (p, q, r) ∧ hostile(r) → Criminal(p) ...(1)
Owns(A, T1) ........(2)
o Missile(T1)
o ?p Missiles(p) ∧ Owns (A, p) → Sells (Robert, p, A) ......(4)
o Missile(p) → Weapons (p) .......(5)

Mr. Mohammed Afzal, Asst. Professor in AIML


Mob: +91-8179700193, Email: [email protected]
o Enemy(p, America) →Hostile(p) ........(6)
o Enemy (A, America) .........(7)
o American(Robert). ..........(8)

Backward-Chaining proof:
 In Backward chaining, we will start with our goal predicate, which is Criminal(Robert), and then
infer further rules.
Step-1:
 At the first step, we will take the goal fact. And from the goal fact, we will infer other facts, and at
last, we will prove those facts true.
 So, our goal fact is "Robert is Criminal," so following is the predicate of it.

Step-2:
 At the second step, we will infer other facts form goal fact which satisfies the rules. So, as we can
see in Rule-1, the goal predicate Criminal (Robert) is present with substitution {Robert/P}.
 So, we will add all the conjunctive facts below the first level and will replace p with Robert.
 Here we can see American (Robert) is a fact, so it is proved here.

Step-3:
 At step-3, we will extract further fact Missile(q) which infer from Weapon(q), as it satisfies Rule-(5).
Weapon (q) is also true with the substitution of a constant T1 at q.

Mr. Mohammed Afzal, Asst. Professor in AIML


Mob: +91-8179700193, Email: [email protected]
Step-4:
 At step-4, we can infer facts Missile(T1) and Owns(A, T1) form Sells(Robert, T1, r) which satisfies
the Rule- 4, with the substitution of A in place of r.
 So, these two statements are proved here.

Step-5:
 At step-5, we can infer the fact Enemy(A, America) from Hostile(A) which satisfies Rule- 6. And
hence all the statements are proved true using backward chaining.

Mr. Mohammed Afzal, Asst. Professor in AIML


Mob: +91-8179700193, Email: [email protected]
Difference between backward chaining and forward chaining
Following are the differences between the forward chaining and backward chaining:
 Forward chaining as the name suggests, start from the known facts and move forward by applying
inference rules to extract more data, and it continues until it reaches to the goal, whereas backward
chaining starts from the goal, move backward by using inference rules to determine the facts that satisfy
the goal.
 Forward chaining is called a data-driven inference technique, whereas backward chaining is called
a goal-driven inference technique.
 Forward chaining is known as the down-up approach, whereas backward chaining is known as a top-
down approach.
 Forward chaining uses breadth-first search strategy, whereas backward chaining uses depth-first
search strategy.
 Forward and backward chaining both applies Modus ponens inference rule.
 Forward chaining can be used for tasks such as planning, design process monitoring, diagnosis, and
classification, whereas backward chaining can be used for classification and diagnosis tasks.
 Forward chaining can be like an exhaustive search, whereas backward chaining tries to avoid the
unnecessary path of reasoning.
 In forward-chaining there can be various ASK questions from the knowledge base, whereas in
backward chaining there can be fewer ASK questions.
 Forward chaining is slow as it checks for all the rules, whereas backward chaining is fast as it checks
few required rules only.

Mr. Mohammed Afzal, Asst. Professor in AIML


Mob: +91-8179700193, Email: [email protected]
S. No. Forward Chaining Backward Chaining

1. Forward chaining starts from known facts Backward chaining starts from the goal and
and applies inference rule to extract more works backward through inference rules to find
data unit it reaches to the goal. the required facts that support the goal.

2. It is a bottom-up approach It is a top-down approach

3. Forward chaining is known as data-driven Backward chaining is known as goal-driven


inference technique as we reach to the goal technique as we start from the goal and divide
using the available data. into sub-goal to extract the facts.

4. Forward chaining reasoning applies a Backward chaining reasoning applies a depth-


breadth-first search strategy. first search strategy.

5. Forward chaining tests for all the available Backward chaining only tests for few required
rules rules.

6. Forward chaining is suitable fhghhghor the Backward chaining is suitable for diagnostic,
planning, monitoring, control, and prescription, and debugging application.
interpretation application.

7. Forward chaining can generate an infinite Backward chaining generates a finite number of
number of possible conclusions. possible conclusions.

8. It operates in the forward direction. It operates in the backward direction.

9. Forward chaining is aimed for any Backward chaining is only aimed for the
conclusion. required data.

EFFECTIVE PROPOSITIONAL MODEL CHECKING


 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 quickly.
 Two families of algorithms for the SAT problem based on model checking:
a) based on backtracking
b) based on local hill-climbing search

Mr. Mohammed Afzal, Asst. Professor in AIML


Mob: +91-8179700193, Email: [email protected]
1. A complete backtracking algorithm
David-Putnam algorithm (DPLL):

 DPLL embodies 3 improvements over the scheme of TT-ENTAILS?: Early termination, pure
symbol heuristic, unit clause heuristic.
 Tricks that enable SAT solvers to scale up to large problems: Component analysis, variable and
value ordering, intelligent backtracking, random restarts, clever indexing.

LOCAL SEARCH ALGORITHMS


 Local search algorithms can be applied directly to the SAT problem, provided that choose the right
evaluation function. (We can choose an evaluation function that counts the number of unsatisfied
clauses.)
 These algorithms take steps in the space of complete assignments, flipping the truth value of one
symbol at a time.
 The space usually contains many local minima, to escape from which various forms of randomness
are required.
 Local search methods such as WALKSAT can be used to find solutions. Such algorithm are sound
but not complete.
Mr. Mohammed Afzal, Asst. Professor in AIML
Mob: +91-8179700193, Email: [email protected]
 WALKSAT: one of the simplest and most effective algorithms.

 On every iteration, the algorithm picks an unsatisfied clause, and chooses randomly between two
ways to pick a symbol to flip:
Either
a) a “min-conflicts” step that minimizes the number of unsatisfied clauses in the new state;
b) a “random walk” step that picks the symbol randomly.

 When the algorithm returns a model, the input sentence is indeed satisfiable; When the algorithm
returns failure, there are two possible causes:
Either
a) The sentence is unsatisfiable;
b) We need to give the algorithm more time.
 If we set max_flips=∞, p>0, the algorithm will:
Either
a) eventually returns a model if one exists
b) never terminates if the sentence is unsatisfiable.
 Thus, WALKSAT is useful when we expect a solution to exist, but cannot always detect un-
satisfiability.

Mr. Mohammed Afzal, Asst. Professor in AIML


Mob: +91-8179700193, Email: [email protected]
The landscape of random SAT problems
 Under-constrained problem: When we look at satisfiability problems in CNF, an under-
constrained problem is one with relatively few clauses constraining the variables.
 An over-constrained problem has many clauses relative to the number of variables and is likely to
have no solutions.
 The notation CNFk(m, n) denotes a k-CNF sentence with m clauses and n symbols. (with n variables
and k literals per clause).
 Given a source of random sentences, where the clauses are chosen uniformly, independently and
without replacement from among all clauses with k different literals, which are positive or negative
at random.
 Hardness: problems right at the threshold > over-constrained problems > under-constrained
problems.

 Satifiability threshold conjecture: A theory says that for every k≥3, there is a threshold ratio rk,
such that as n goes to infinity, the probability that CNFk(n, rn) is satisfiable becomes 1 for all values
or r below the threshold, and 0 for all values above. (remains unproven)

Agent based on propositional logic


1. The current state of the world
 We can associate proposition with timestamp to avoid contradiction.
e.g. ¬Stench3, Stench4
Mr. Mohammed Afzal, Asst. Professor in AIML
Mob: +91-8179700193, Email: [email protected]
 fluent: refer an aspect of the world that changes. (E.g. Ltx,y)
 atemporal variables: Symbols associated with permanent aspects of the world do not need a time
superscript.
 Effect axioms: specify the outcome of an action at the next time step.
 Frame problem: some information lost because the effect axioms fail to state what remains
unchanged as the result of an action.
Solution: add frame axioms explicitly asserting all the propositions that remain the same.
 Representation frame problem: The proliferation of frame axioms is inefficient; the set of frame
axioms will be O(mn) in a world with m different actions and n fluents.
Solution: because the world exhibits locaility (for humans each action typically changes no more
than some number k of those fluents.) Define the transition model with a set of axioms of size O(mk)
rather than size O(mn).
 Inferential frame problem: The problem of projecting forward the results of a t step lan of action
in time O(kt) rather than O(nt).
Solution: change one’s focus from writing axioms about actions to writing axioms about fluents.
 For each fluent F, we will have an axiom that defines the truth value of Ft+1 in terms of fluents at
time t and the action that may have occurred at time t.
 The truth value of Ft+1 can be set in one of 2 ways:
 Either
a) The action at time t cause F to be true at t+1
b) F was already true at time t and the action at time t does not cause it to be false.
 An axiom of this form is called a successor-state axiom and has this schema:

 Qualification problem: specifying all unusual exceptions that could cause the action to fail.

2. A hybrid agent
 Hybrid agent: combines the ability to deduce various aspect of the state of the world with
condition-action rules, and with problem-solving algorithms.
 The agent maintains and update KB as a current plan.
 The initial KB contains the atemporal axioms. (don’t depend on t)
 At each time step, the new percept sentence is added along with all the axioms that depend on t (such
as the successor-state axioms).

Mr. Mohammed Afzal, Asst. Professor in AIML


Mob: +91-8179700193, Email: [email protected]
 Then the agent uses logical inference by ASKING questions of the KB (to work out which squares
are safe and which have yet to be visited).
 The main body of the agent program constructs a plan based on a decreasing priority of goals:
1. If there is a glitter, construct a plan to grab the gold, follow a route back to the initial location
and climb out of the cave;
2. Otherwise, if there is no current plan, plan a route (with A* search) to the closest safe square
unvisited yet, making sure the route goes through only safe squares;
3. If there are no safe squares to explore, if still has an arrow, try to make a safe square by shooting
at one of the possible Wumpus locations.
4. If this fails, look for a square to explore that is not provably unsafe.
5. If there is no such square, the mission is impossible, then retreat to the initial location and climb
out of the cave.

Mr. Mohammed Afzal, Asst. Professor in AIML


Mob: +91-8179700193, Email: [email protected]
 Weakness: The computational expense goes up as time goes by.

3. Logical state estimation


 To get a constant update time, we need to cache the result of inference.
 Belief state: Some representation of the set of all possible current state of the world. (used to replace
the past history of percepts and all their ramifications)
 Example:

 We use a logical sentence involving the proposition symbols associated with the current time step
and the temporal symbols.
 Logical state estimation involves maintaining a logical sentence that describes the set of possible
states consistent with the observation history. Each update step requires inference using the
transition model of the environment, which is built from successor-state axioms that specify how
each fluent changes.
 State estimation: The process of updating the belief state as new percepts arrive.
 Exact state estimation may require logical formulas whose size is exponential in the number of
symbols.
 One common scheme for approximate state estimation: to represent belief state as conjunctions of
literals (1-CNF formulas).
 The agent simply tries to prove Xt and ¬Xt for each symbol Xt, given the belief state at t-1.
 The conjunction of provable literals becomes the new belief state, and the previous belief state is
discarded. (This scheme may lose some information as time goes along.)

Mr. Mohammed Afzal, Asst. Professor in AIML


Mob: +91-8179700193, Email: [email protected]
 The set of possible states represented by the 1-CNF belief state includes all states that are in fact
possible given the full percept history. The 1-CNF belief state acts as a simple outer envelope,
or conservative approximation.

4. Making plans by propositional inference


 We can make plans by logical inference instead of A* search in the above figure.
Basic idea:
1. Construct a sentence that includes:
a. Init0: a collection of assertions about the initial state;
b. Transition1, …, Transitiont: The successor-state axioms for all possible actions at
each time up to some maximum time t;
c. HaveGoldt∧ClimbedOutt: The assertion that the goal is achieved at time t.
2. Present the whole sentence to a SAT solver. If the solver finds a satisfying model, the
goal is achievable; else the planning is impossible.
3. Assuming a model is found, extract from the model those variables that represent actions
and are assigned true.
 Together they represent a plan to achieve the goals.
 Decisions within a logical agent can be made by SAT solving: finding possible models specifying
future action sequences that reach the goal. This approach works only for fully observable or sensor-
less environment.
Mr. Mohammed Afzal, Asst. Professor in AIML
Mob: +91-8179700193, Email: [email protected]
 SATPLAN: A propositional planning. (Cannot be used in a partially observable environment).
 SATPLAN finds models for a sentence containing the initial sate, the goal, the successor-state
axioms, and the action exclusion axioms.
 (Because the agent does not know how many steps it will take to reach the goal, the algorithm tries
each possible number of steps t up to some maximum conceivable plan length Tmax.)

 Precondition axioms: stating that an action occurrence requires the preconditions to be satisfied,
added to avoid generating plans with illegal actions.
 Action exclusion axioms: added to avoid the creation of plans with multiple simultaneous actions
that interfere with each other.
 Propositional logic does not scale to environments of unbounded size because it lacks the expressive
power to deal concisely with time, space and universal patterns of relationships among objects.

Mr. Mohammed Afzal, Asst. Professor in AIML


Mob: +91-8179700193, Email: [email protected]

You might also like