Unit-3 AI Propositional Logic

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

Unit-3

Propositional Logic
Propositional Theorem Proving
Contents:
• 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
• An intelligent agent needs
– knowledge about the real world for taking decisions and
– reasoning to act efficiently.
• 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.
• Knowledge-based agents are composed of 2 main parts:
– Knowledge-base(Domain Specific) and
– Inference system(Domain Independent Algorithm)
A knowledge-based agent(KBA) must able to do the
following:

• An agent should be able to represent states, actions, etc.


• An agent should be able to incorporate new percepts
• An agent can update the internal representation of the
world
• An agent can deduce the internal representation of the
world
• An agent can deduce appropriate actions.
The architecture of knowledge-based agent(KBA):

• 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(KB):
• Knowledge-base is a central component of a
KBA.
• 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 2 rules:
– Forward chaining
– Backward chaining
• Forward chaining starts from known facts and
applies inference rule to extract more data unit
it reaches to the goal.
– Data-driven inference technique
– Forward chaining is suitable for the planning,
monitoring, control, and interpretation application.
• Backward chaining starts from the goal and
works backward through inference rules to find
the required facts that support the goal.
– Goal-driven technique
– Backward chaining is suitable for diagnostic,
prescription, and debugging application.
Operations Performed by KBA which are
performed by KBA in order to show the intelligent
behavior:
• TELL: This operation tells the knowledge base
what it perceives from the environment.
• ASK: This operation asks the knowledge base
what action it should perform.
• Perform: It performs the selected action.
Various Levels of Knowledge-Based Agent
Knowledge-based agents can be classified into 3 levels:

• Knowledge Level

• Logical Level

• Implementation Level
1. Knowledge Level
• The knowledge level is the highest level of abstraction in a
knowledge-based agent.
• It describes what the agent knows and how it uses it to
perform tasks.
• The knowledge level, concerns the representation and
organization of knowledge rather than the implementation
details.

2. Logical Level
• The logical level is the intermediate level of abstraction in a
knowledge-based agent.
• It describes how the knowledge is represented and
manipulated by the inference engine.
• The logical story concerns the formal logic used to represent
knowledge and make inferences.
3. Implementation Level
• The implementation level is the lowest level of
abstraction in a knowledge-based agent.
• It describes how the knowledge and inference
engine is implemented using a programming
language.
• The implementation level is concerned with the
details of the programming language and the
algorithms used to implement the knowledge
and inference engine.
Approaches to Designing a Knowledge-Based Agent

There are 2 main approaches to designing a


knowledge-based agent:

Declarative Approach

Procedural Approach
Declarative Approach
• The declarative approach to designing a
knowledge-based agent focuses on
representing knowledge in a declarative
form, such as rules or facts.
• The knowledge is represented independently
of the algorithms used to manipulate it.
Procedural Approach
• The procedural approach to designing a
knowledge-based agent focuses on
representing knowledge in a procedural form,
such as a sequence of instructions.
• The knowledge is represented in terms of the
algorithms used to manipulate it.
• The inference engine uses these algorithms to
make inferences from the knowledge.
Knowledge Representation
• Humans are best at understanding, reasoning,
and interpreting knowledge.
• Human knows things, which is knowledge and
as per their knowledge they perform various
actions in the real world.
• But how machines do all these things comes
under knowledge representation and
reasoning.
• Knowledge representation provides a
framework for
– representing, organizing, and manipulating
knowledge
that can be used
– to solve complex problems,
– make decisions, and
– learn from data.
• For example, when you see a hot tea cup, a
signal immediately comes from your brain
cautioning you against picking it up.
What to Represent:
Following are the kind of knowledge which needs to be
represented in AI systems:
• Object: All the facts about objects in our world domain.
E.g., Guitars contains strings, trumpets are brass
instruments.
• Facts: Facts are the truths about the real world and what
we represent.
• Events: Events are the actions which occur in our world.
• Performance: It describe behavior which involves
knowledge about how to do things.
• Meta-knowledge: It is knowledge about what we know.
Knowledge-Base: The central component of the
knowledge-based agents is the knowledge base.
• Knowledge: Knowledge is awareness or familiarity
gained by experiences of facts, data, and situations.
• Following are the types of knowledge in artificial
intelligence:

Types of
knowledge
1. Declarative Knowledge:
• Declarative knowledge is to know about
something.

It includes concepts, facts, and objects.

• It is also called descriptive knowledge and


expressed in declarative sentences.
2. Procedural Knowledge
• It is also known as imperative knowledge.
• Procedural knowledge is a type of knowledge
which is responsible for knowing how to do
something.
• It can be directly applied to any task.

It includes rules, strategies, procedures, agendas, etc.

• Procedural knowledge depends on the task on


which it can be applied.
3. Meta-knowledge:
• Knowledge about the other types of
knowledge is called Meta-knowledge.
4. Heuristic knowledge:
• Heuristic knowledge is representing
knowledge of some experts in a field or
subject.
• Heuristic knowledge is rules of thumb based
on previous experiences, awareness of
approaches, and which are good to work but
not guaranteed.
5. Structural knowledge:
• Structural knowledge is basic knowledge to
problem-solving.
• It describes relationships between various
concepts such as kind of, part of, and grouping
of something.
It describes the relationship that exists
between concepts or objects.
Techniques of knowledge representation
There are mainly 4 ways of knowledge
representation which are given as
follows:
• Logical Representation
• Semantic Network
Representation
• Frame Representation
• Production Rules
1. Logical Representation
• In AI, we communicate using formal logic, much like following a rulebook.
• Imagine AI as a student following a strict set of rules in a school.
• These rules ensure that information is shared with minimal mistakes and
that AI’s conclusions are either true or false.
• Though it can be tricky, logical representation is like the foundation of
many programming languages, helping AI think logically.
• Logical representation is a language with some concrete rules
which deals with propositions and has no ambiguity in
representation.
• Logical representation means drawing a conclusion based on
various conditions.
• It consists of precisely defined syntax and semantics which
supports the sound inference.
• Each sentence can be translated into logics using syntax and
semantics.
Syntax:
• Syntaxes are the rules which decide how we can
construct legal sentences in the logic.
• It determines which symbol we can use in
knowledge representation.
• How to write those symbols.
Semantics:
• Semantics are the rules by which we can
interpret the sentence in the logic.
• Semantic also involves assigning a meaning to
each sentence.
Logical representation can be categorized into mainly two logics:
• Propositional Logics
• Predicate logics
Advantages of logical representation:
• Logical representation enables us to do logical reasoning.
• Logical representation is the basis for the programming
languages.
Disadvantages of logical Representation:
• Logical representations have some restrictions and are
challenging to work with.
• Logical representation technique may not be very natural, and
inference may not be so efficient.
• Logical representation and logical reasoning as logical representation
is a representation language and reasoning is a process of thinking
logically.
2. Semantic Network Representation
• Semantic networks are alternative of predicate logic for
knowledge representation.
• In Semantic networks, we can represent our knowledge in
the form of graphical networks.
• This network consists of nodes representing objects and
arcs which describe the relationship between those
objects.
• Semantic networks can categorize the object in different
forms and can also link those objects.
• Semantic networks are easy to understand and can be
easily extended.
• This representation consist of mainly 2 types of relations:
– IS-A relation (Inheritance)
– Kind-of-relation
Example: Following are some statements which we need to represent in the form of nodes
and arcs.
Statements:
• Jerry is a cat.
• Jerry is a mammal
• Jerry is owned by Priya.
• Jerry is white colored.
• All Mammals are animal.

• In the above diagram, we have represented the different type of knowledge in the form
of nodes and arcs.
• Each object is connected with another object by some relation.
3. Frame Representation
• A frame is a record like structure which consists of a
collection of attributes and its values to describe an
entity in the world.
• It consists of a collection of slots and slot values.
• These slots may be of any type and sizes.
• Slots have names and values which are called
facets.
Facets: The various aspects of a slot is known
as Facets.
A frame is also known as slot-filter knowledge
representation in artificial intelligence.
Slots Filters
Let's take an example of a frame for a book
Title Artificial Intelligence
Genre Computer Science
Author Peter Norvig
Edition Third Edition
Year 1996
Page 1152

Example 2:
Let's suppose we are taking an entity, Peter. Peter is an engineer as a profession, and his age
is 25, he lives in city London, and the country is England. So following is the frame
representation for this:
Slots Filter

Name Peter
Profession Doctor
Age 25
Marital status Single
Weight 78
4. Production Rules
• Production rules system consist of (condition,
action) pairs which mean,
– "If condition then action".

• It has mainly 3 parts:


– The set of production rules
– Working Memory
– The recognize-act-cycle
• In production rules, agent checks for the
condition and if the condition exists then
production rule fires and corresponding action is
carried out.
– The condition part of the rule determines which rule
may be applied to a problem.
– And the action part carries out the associated
problem-solving steps.
• This complete process is called a recognize-act
cycle.
• The working memory contains the description
of the current state of problems-solving and
rule can write knowledge to the working
memory.
– This knowledge match and may fire other rules.
• If there is a new situation (state) generates,
then multiple production rules will be fired
together, this is called conflict set.
– In this situation, the agent needs to select a rule
from these sets, and it is called a conflict resolution.
Example:
• IF (at bus stop AND bus arrives) THEN action
(get into the bus)
• IF (on the bus AND paid AND empty seat)
THEN action (sit down).
• IF (on bus AND unpaid) THEN action (pay
charges).
• IF (bus arrives at destination) THEN action (get
down from the bus).
Propositional logic
Logical representation can be categorized into mainly two logics:
– Propositional Logics
– Predicate logics
1. 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.
2. Predicate Logic :
Predicates are properties, additional information
to better express the subject of the sentence.
A quantified predicate is a proposition , that is,
when you assign values to a predicate with
variables it can be made a proposition.
Difference between Propositional Logic and Predicate Logic

Propositional Logic Predicate Logic


Predicate logic is an expression consisting of
Propositional logic is the logic that deals with variables with a specified domain. It consists
a collection of declarative statements which of objects, relations and functions between
have a truth value, true or false. the objects.

Also known as Boolean logic. It is an extension of propositional logic


covering predicates and quantification.
A proposition has a specific truth value, either A predicate’s truth value depends on the
true or false. variables’ value.
Propositions are combined with Logical
Operators or Logical Connectives like
Negation(¬), Disjunction(∨), Conjunction(∧), Predicate Logic adds by introducing
Exclusive OR(⊕), Implication(⇒), Bi- quantifiers to the existing proposition.
Conditional or Double Implication(⇔).
It is a more generalized representation. It is a more specialized representation.
Following are some basic facts about propositional
logic:
• Propositional logic is also called Boolean logic as it works
on 0 and 1.
• In propositional logic, we use symbolic variables to
represent the logic, such as A, B, C, P, Q, R, etc.
• Propositions can be either true or false, but it cannot be
both.
• Propositional logic consists of an object, relations or
function, and logical connectives.
• These connectives are also called logical operators.
• The propositions and connectives are the basic
elements of the propositional logic.
• Connectives can be said as a logical operator which
connects two sentences.

• A proposition formula which is always true is


called tautology, and it is also called a valid sentence.

• A proposition formula which is always false is


called Contradiction.

• 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:
– Atomic Propositions
– Compound propositions
• Atomic Proposition:
– Atomic propositions are the simple, 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.


• Compound proposition:
– Compound propositions are constructed by combining
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 5 connectives:
• Negation:
– A sentence such as ¬ P is called negation of P.
– A literal can be either Positive literal or negative
literal.
• 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
• 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 Engineer,
– so we can write it as P∨Q
• 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
• 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.

Note: Implication is one-way, whereas the


biconditional is two-way.
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.
Truth table for all logical connectives
Truth table with 3 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
3 proposition symbols.
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.

Precedence Operators
First Precedence Parenthesis- ()
Second Precedence Negation- ~
Third Precedence Conjunction(AND) - ^
Fourth Precedence Disjunction(OR) - v
Fifth Precedence Implication - ->
Six Precedence Biconditional - 

Note:
For better understanding use parenthesis to make sure of the correct
interpretations.
Such as ¬R∨ Q, It can be interpreted as (¬R) ∨ Q
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
Properties of Operators:
Commutativity:
P∧ Q= Q ∧ P, or
P ∨ Q = Q ∨ P.
Associativity:
(P ∧ Q) ∧ R= P ∧ (Q ∧ R),
(P ∨ Q) ∨ R= P ∨ (Q ∨ R)
Identity element:
P ∧ True = P,
P ∨ True= True.
Distributive:
P∧ (Q ∨ R) = (P ∧ Q) ∨ (P ∧ R).
P ∨ (Q ∧ R) = (P ∨ Q) ∧ (P ∨ R).
DE Morgan's Law:
¬ (P ∧ Q) = (¬P) ∨ (¬Q)
¬ (P ∨ Q) = (¬ P) ∧ (¬Q).
Double-negation elimination:
¬ (¬P) = P.
Limitations of Propositional logic:
• We cannot represent relations like ALL, some, or none
with propositional logic.
• Example:
All the girls are intelligent.
Some apples are sweet.

• Propositional logic has limited expressive power.

• In propositional logic, we cannot describe statements in


terms of their properties or logical relationships.
Rules of Inference in AI
Inference:
• In AI, 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.
Inference rules:
• Inference rules are the templates for generating valid
arguments.
• Inference rules are applied to derive proofs in AI, 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.
Some terminologies related to inference rules:
• Implication:
– It is one of the logical connectives which can be
represented as P→Q
– It is a Boolean expression.
• 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
• Contrapositive:
– The negation of converse is termed as
contrapositive.
– It can be represented as
¬Q→¬P
• 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 states that if P and P → Q is true, then we can
infer that Q will be true.
• It can be represented as:

Example:
Statement-1: "If I am sleepy then I go to bed" ==> P→ Q
Statement-2: "I am sleepy" ==> P
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:
Statement-1: "If I am sleepy then I go to bed" ==> P→ Q
Statement-2: "I do not go to the bed."==> ~Q
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:
Statement-1: If you have my home key then you can unlock my home. P→Q
Statement-2: If you can unlock my home then you can take my money. Q→R
Conclusion: If you have my home key then you can take my money. P→R

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:
Statement-1: Today is Sunday or Monday. ==>P∨Q
Statement-2: Today is not Sunday. ==> ¬P
Conclusion: Today is Monday. ==> Q

Proof by Truth table


5. Addition:
• The Addition rule states that If P is true, then P∨Q will be true.

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

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


The Wumpus World
The Wumpus World
• The Wumpus World’s agent is an example of a
KBA that represents Knowledge
representation, reasoning and planning.
• KBA links general knowledge with current
percepts to infer hidden characters of current
state before selecting actions.
• Its necessity is vital in partially observable
environments.
• It was inspired by a video game Hunt the
Wumpus by Gregory Yob in 1973.
Problem Statement:
• The Wumpus world is a cave with 16 rooms (4×4).
• Each room is connected to others through walkways (no rooms
are connected diagonally).
• The knowledge-based agent starts from Room[1, 1].
• The cave has – some pits, a treasure and a beast
named Wumpus.
• The Wumpus can not move but eats the one who enters its
room.
• If the agent enters the pit, it gets stuck there.
• The goal of the agent is to take the treasure and come out of the
cave.
• The agent is rewarded, when the goal conditions are met.
• The agent is penalized, when it falls into a pit or being eaten by
the Wumpus.
• Some elements support the agent to explore
the cave, like
– The wumpus’s adjacent rooms are stenchy.
– The agent is given one arrow which it can use to
kill the wumpus when facing it (Wumpus screams
when it is killed).
– The adjacent rooms of the room with pits are filled
with breeze.
– The treasure room is always glittery.
• PEAS represents “Performance Measures,
Environment, Actuators, and Sensors”, helps in
grouping the agents.
PEAS Description for the Wumpus World problem:
• Performance measures:
– Agent gets the gold and return back safe = +1000
points
– Agent dies = -1000 points
– Each move of the agent = -1 point
– Agent uses the arrow = -10 points
• Environment:
– A cave with 16(4×4) rooms
– Rooms adjacent (not diagonally) to the Wumpus are
stinking
– Rooms adjacent (not diagonally) to the pit are breezy
– The room with the gold glitters
– Agent’s initial position – Room[1, 1] and facing right
side
– Location of Wumpus, gold and 3 pits can be
anywhere, except in Room[1, 1].
• Actuators: Devices that allow the agent to perform the
following actions in the environment.
– Move forward
– Turn right
– Turn left
– Shoot
– Grab
– Release
• Sensors: Devices which helps the agent in sensing the
following from the environment.
– Breeze
– Stench
– Glitter
– Scream (When the Wumpus is killed)
– Bump (when the agent hits a wall
Wumpus World Characterization:
• Partially Observable: knows only the local
perceptions
• Deterministic: outcome is precisely specified
• Sequential: subsequent level of actions
performed
• Static: Wumpus, pits are immobile
• Discrete: discrete environment
• Single-agent: The knowledge-based agent is the
only agent whereas the wumpus is considered as
the environment’s feature.
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.
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

• Lets create a knowledge base for the wumpus


world, and will derive some proves for the
Wumpus-world using propositional logic.
• 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:
• Let Pi,j be true if there is a Pit in the room [i, j].
• Let Bi,j be true if agent perceives breeze in [i, j], (dead or
alive).
• Let Wi,j be true if there is wumpus in the square[i, j].
• Let Si,j be true if agent perceives stench in the square [i,
j].
• Let Vi,j be true if that square[i, j] is visited.
• Let Gi,j be true if there is gold (and glitter) in the square
[i, j].
• Let OKi,j be true if the room is safe.
• Some Propositional Rules for the wumpus world:
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(¬ W 11),
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.
Apply Modus Ponens to ¬S21, and R2:
• 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
•Resolution is a fundamental inference rule used in automated
theorem proving.
•It involves resolving or simplifying logical expressions by eliminating
contradictory clauses.
•Example: Given two clauses "P OR Q" and "NOT Q OR R,"
resolution allows us to infer "P OR R."
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:
1. Forward chaining
2. 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.
First-Order logic:
• First-order logic is another way of knowledge representation in artificial
intelligence. It is an extension to propositional logic.
• FOL is sufficiently expressive to represent the natural language statements in
a concise way.
• First-order logic is also known as Predicate logic or First-order predicate
logic. First-order logic is a powerful language that develops information about
the objects in a more easy way and can also express the relationship between
those objects.
• First-order logic (like natural language) does not only assume that the world
contains facts like propositional logic but also assumes the following things in
the world:
– Objects: A, B, people, numbers, colors, wars, theories, squares, pits, wumpus, ......
– Relations: It can be unary relation such as: red, round, is adjacent, or n-any relation
such as: the sister of, brother of, has color, comes between
– Function: Father of, best friend, third inning of, end of, ......
• As a natural language, first-order logic also has two main parts:
– Syntax
– Semantics
Horn Clauses and Definite Clauses:
• Horn clauses are a special form of logical
expressions where at most one positive literal
is present.
• Example of Horn clause: "P OR Q OR NOT
R"
• Definite clauses are Horn clauses with exactly
one positive literal.
• Example of definite clause: "P OR Q"
• Horn Clauses:
1.likes(X,Y)←friend(X,Y)
1.This Horn clause states that if X is a friend of Y,
then X likes Y.
2.eats(X,Y)←hungry(X),food(Y)
1.Here, if X is hungry and Y is food, then X eats Y.
Definite Clauses:
1.parent(X,Y)←mother(X,Y)
1.This definite clause specifies that if X is the mother
of Y, then X is the parent of Y.
2.married(X,Y)←husband(X,Y),wife(Y,X)
1.If X is the husband of Y and Y is the wife of X, then
X and Y are married.
Forward and Backward Chaining:
• Forward chaining starts with known facts and uses
inference rules to derive new conclusions until the goal is
reached.
• Backward chaining begins with the goal and works
backward to find what facts need to be true to achieve the
goal.
• Forward chaining is data-driven, while backward chaining
is goal-driven.
• Example:
• In a medical diagnosis system, forward chaining might start with
symptoms and deduce potential diseases.
• Backward chaining might start with a disease and backtrack to
find symptoms.
A. 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:
• It is a down-up approach, as it moves from bottom
to top.
• 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.
• Forward-chaining approach is also called as data-
driven as we reach to the goal using available data.
• Forward -chaining approach is commonly used in
the expert system, such as business, and
production rule systems.
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:
• 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)
• 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)
• All of the missiles were sold to country A by Robert.
• ?p Missiles(p) ∧ Owns (A, p) → Sells (Robert, p, A) ......(4)
• Missiles are weapons.
• Missile(p) → Weapons (p) .......(5)
• Enemy of America is known as hostile.
• Enemy(p, America) →Hostile(p) ........(6)
• Country A is an enemy of America.
• Enemy (A, America) .........(7)
• 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).
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.
B. 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:
• It is known as a top-down approach.
• Backward-chaining is based on modus ponens inference
rule.
• In backward chaining, the goal is broken into sub-goal
or sub-goals to prove the facts true.
• It is called a goal-driven approach, as a list of goals
decides which rules are selected and used.
• Backward -chaining algorithm is used in game theory,
automated theorem proving tools, inference engines,
proof assistants, and various AI applications.
• The backward-chaining method mostly used a depth-
first search strategy for proof.
In backward-chaining, we will use the same above
example, and will rewrite all the rules:
• American (p) ∧ weapon(q) ∧ sells (p, q, r) ∧
hostile(r) → Criminal(p) ...(1)
• Owns(A, T1) ........(2)
• Missile(T1)
• ?p Missiles(p) ∧ Owns (A, p) → Sells (Robert, p,
A) ......(4)
• Missile(p) → Weapons (p) .......(5)
• Enemy(p, America) →Hostile(p) ........(6)
• Enemy (A, America) .........(7)
• 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:t 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.
• 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.
S.
No. Forward Chaining Backward Chaining
1. Forward chaining starts from known facts and Backward chaining starts from the goal
applies inference rule to extract more data unit and works backward through inference
it reaches to the goal. rules to find 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-
inference technique as we reach to the goal driven technique as we start from the goal
using the available data. and divide into sub-goal to extract the
facts.
4. Forward chaining reasoning applies a breadth- Backward chaining reasoning applies a
first search strategy. depth-first search strategy.
5. Forward chaining tests for all the available Backward chaining only tests for few
rules required rules.
6. Forward chaining is suitable for the planning, Backward chaining is suitable for
monitoring, control, and interpretation diagnostic, prescription, and debugging
application. application.
7. Forward chaining can generate an infinite Backward chaining generates a finite
number of possible conclusions. number of possible conclusions.
8. It operates in the forward direction. It operates in the backward direction.
9. Forward chaining is aimed for any conclusion. Backward chaining is only aimed for the
required data.
Effective Propositional Model Checking:
• Propositional model checking is a technique to
verify whether a given logical formula holds in a
given model.
• It involves constructing a model of the system and
checking if the formula holds in all possible states
of the model.
• Effective model checking techniques aim to
efficiently handle large-scale systems.
• Ex: Verifying whether a given circuit design
meets certain specifications by checking if
specific properties hold in all possible states of the
circuit.
Agents Based on Propositional Logic:
• In AI, agents are entities that perceive their
environment and take actions to achieve goals.
• Propositional logic can be used to represent the
knowledge and reasoning capabilities of these
agents.
• Agents can use propositional logic to make
decisions, infer consequences of actions, and plan
future actions.
• Ex: A simple intelligent agent controlling a vacuum
cleaner might use propositional logic to represent
facts about dirt locations, clean actions, and its
internal state to decide the next move.
• Propositional theorem proving forms the basis of
many AI applications, providing a systematic way
to represent, infer, and reason about knowledge.
• Understanding these concepts is crucial for
building intelligent systems capable of making
informed decisions and solving complex
problems.
• Through techniques like resolution, chaining, and
model checking, AI systems can effectively
manipulate propositional logic to achieve their
goals.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy