0% found this document useful (0 votes)
20 views

Artificial Intelligence CSE3002: by Dr. Manomita Chakraborty Assistant Professor VIT-AP, Amaravati, AP, India

Uploaded by

trivenic606
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)
20 views

Artificial Intelligence CSE3002: by Dr. Manomita Chakraborty Assistant Professor VIT-AP, Amaravati, AP, India

Uploaded by

trivenic606
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/ 313

ARTIFICIAL INTELLIGENCE

CSE3002

By
By
Dr. Manomita Chakraborty
Assistant Professor
VIT-AP, Amaravati, AP, India

3/24/2023 By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 1


Prerequisite

• Data Structure and algorithm

• Mathematics

• Programming concepts

3/24/2023 By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 2


Course Objectives

 To have a thorough understanding of the classical and modern AI applications;


 To implement a wide range of AI concepts;
 To understand non-classical AI approaches ;
 To be able to assess the potential of AI in research and real-world environments;

3/24/2023 By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 3


Course Outcome

 Understand the basics of AI.


 Implement and debug core AI algorithms in a clean and structured manner.
 Describe AI algorithms and representations and explain their performance, in writing and orally.
 Analyze and design a real-world AI application.

3/24/2023 By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 4


Syllabus
Module No. 1 Introduction To Al And Production Systems
Introduction to AI-Problem formulation, Problem Definition -TIC-TAC-TOE Production systems, Control strategies, Search
strategies-(BFS, DFS, best First, A*, AO* ). Problem characteristics, Production system characteristics -Specialized production
system-Water Jug Problem, Missionaries and Cannibals Problem, 8-Puzzle, 8-queen
Module No. 2 Problem Solving methods
Problem graphs, Matching, Indexing and Heuristic functions -Hill Climbing-Depth first and Breadth first, Constraints satisfaction -
Related algorithms, simple mention
Module No. 3 Knowledge Representation
Types of Agents, Wumpus World Problem, Knowledge-based agents, Prepositional Logic- First Order logic- Inferences

Module No. 4 Knowledge Inference


Knowledge representation -Production-based system, Frame-based system. Inference - Backward chaining, Forward chaining, Rule
value approach, Bayesian Theory- Certainty factors, Bayesian Network, Dempster - Shafer theory
Module No. 5 Planning And Learning
Basic plan generation systems - Strips -Advanced plan generation systems – K strips -Strategic explanations – Explanation bases
Learning
Module No. 6 Expert Systems Architecture
Expert systems architecture- Fuzzy reasoning-systems, Genetic algorithms-basic

3/24/2023 By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 5


Books
Text Books
1. Stuart Russell and Peter Norvig, “Artificial Intelligence: A Modern Approach” Prentice Hall, Fourth Edition, 2020
References
1. Deepak Khemani, “A First Course in Artificial Intelligence”, McGraw Hill Education (India), 2017.
2. Nick Bostrom, “Superintelligence:Paths,Dangers,Strategies”, 1st edition, 2015.
3. David Poole,Alan Mackworth, “Artificial Intelligence:Foundations of Computational Agents”, 2nd edition, 2017.
4. Elaine Rich and Kevin Knight. “Artificial Intelligence”, Tata McGraw Hill, Third Edition,2019.

3/24/2023 By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 6


MODULE 1 & 2

3/24/2023 By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 7


Intelligence
 Ability to learn from experience.

 Ability to perception.

 Ability to solve real world problem.

 Ability to reasoning (capacity for logical, rational, and analytic thought)

3/24/2023 By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 8


Types of Intelligence

3/24/2023 By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 9


Measure of Intelligence
Intelligence quotient:
 IQ, which stands for Intelligence Quotient, is a score that is derived from a collection of tests designed to determine how mentally agile or intelligent a
person is.
 The term 'IQ' was coined in 1912 by the psychologist William Stern in relation to the German term Intelligenzquotient.
 IQ was represented as a ratio of mental age to chronological age x 100

3/24/2023 By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 10


Artificial Intelligence
Comprises of two terms:

Artificial Intelligence

Artificially incorporating intelligence in a machine

3/24/2023 By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 11


Artificial Intelligence
Definition from Rich and Knight, 1991:
Artificial Intelligence is the study of how to make computers do things which, at the moment , people do better.

Other definitions:
 Artificial Intelligence (AI) is an area of computer science that aims to create machines that work and act like humans.

 Artificial Intelligence (AI) is the study of ideas that enable computers to be intelligent.

3/24/2023 By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 12


Goals of Artificial Intelligence

Main goals:
 To create expert system: The systems
which exhibit intelligent behavior, learn,
demonstrate, and explain its user.

 To implement human intelligence in


machine: Creating machine that
understand, think, learn, and behave like
humans.

3/24/2023 By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 13


Contributors of Artificial Intelligence

3/24/2023 By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 14


Components of Artificial Intelligence

REASONING:
LEARNING: Like Ability to
human computer differentiate
programs also learn in
different manner

PROBLEM
COMPONENTS SOLVING: ability to
define problem and
propose solution
LANGUAGE
UNDERSTANDING:
interpreting text,
translating into a
computer language and PERCEPTION:
producing output in an Process of
language that humans interpreting vision,
can understand sound, smell, touch
3/24/2023 By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 15
Why Artificial Intelligence?
 Advancement in technology is leading to collection of massive amount of data.
 Hence, it is becoming very troublesome for humans to handle these massive data size.
 Through AI, computers have the ability to harness these massive amounts of data effectively and use their learned
intelligence to make optimal decisions and discoveries in fractions of the time that it would take humans.

 Few advantages of AI:

• Reduction in human error


• Allows Automating Repetitive Tasks 24x7 Availability
• Easily Handles Big Data
• Faster Decision-Making with Continuous Availability
• AI-powered Digital Assistants
• 24x7 Availability
• Perform Repetitive Jobs
• Daily Applications
• AI in Risky Situations
3/24/2023 By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 16
Applications of Artificial Intelligence

3/24/2023 By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 17


Few terms related to Artificial Intelligence

3/24/2023 By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 18


History of Artificial Intelligence
TURING TEST:
 Turing Test was introduced by Alan Turing in the 1950 in his paper, "Computing Machinery and Intelligence“.
 The test is to check whether a machine can think like a human or not.
 According to the test , the computer can be said to be an intelligent if it can mimic human response under specific conditions.

 The Turing test is based on a party game "Imitation


game," with some modifications.

 This game involves three players:


1. One player is Computer responder
2. Second player is human responder
3. Third player is a human Interrogator or
questioner (isolated from other two players)

 The job of the interrogator is to find that which player is


machine among two of them.

 If the interrogator cannot identify between human and


machine, in that case the machine is considered to be
intelligent.

3/24/2023 By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 19


History of Artificial Intelligence

3/24/2023 By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 20


Types of Artificial Intelligence
Artificial Intelligence

Type-1 Type-2

Reactive Limited Theory of Self


Narrow AI General AI Super AI
Machines Memory mind Awareness

3/24/2023 By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 21


Types of Artificial Intelligence
Narrow or weak AI:
 Also known as weak AI as the goal of such AI systems is limited or narrow.
 Narrow AI is a term used to describe artificial intelligence systems that are specified to handle a singular or limited task.
 Example: Siri by apple.

3/24/2023 By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 22


Types of Artificial Intelligence
General or strong AI:
 Artificial general intelligence (AGI) is the intelligence of
machines that allows them to comprehend, learn, and
perform intellectual tasks almost like humans.

Super AI:

 With this level of intelligence, machines could surpass human


intelligence, and can perform any task better than human with
cognitive properties. It is an outcome of general AI.

 Some key characteristics of super AI include capability include


the ability to think, to reason, solve the puzzle, make
judgments, plan, learn, and communicate by its own.

 Super AI is a hypothetical concept of Artificial Intelligence.


Development of such systems in real is still world changing
task.

3/24/2023 By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 23


Types of Artificial Intelligence
Reactive machines:

 Reactive machines are the most basic example of AI which cannot create memories or learn from past experiences.

 Reactive machines takes input and respond according to that input.

 Reactive machines does not store previous information or ‘memories’ to determine future information.

 An example of a reactive machine would be the IBM’s Deep Blue computer which was created in 1997 which was
specifically designed to play chess.

 IBM Deep Blue had won chess against Garry Kasparov.

3/24/2023 By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 24


Types of Artificial Intelligence
Limited memory:

 Limited memory is a step forward in technology which can learn from its past experiences unlike reactive machines.

 An example of Limited memory AI is the self-driving car which is capable of driving on its own once it has studied the
speed of other cars, has mapped the area (including lanes and curves) and has learned how to obey the traffic lights

3/24/2023 By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 25


Types of Artificial Intelligence
Theory of mind:

 “Theory of Mind" means that people have thoughts, feelings and emotions that affect their behavior.

 Future AI systems must learn to understand that everyone (both people and AI objects) have thoughts and feelings.

 This type of AI robot still does not exist, but it would be the closest AI to human if it did. The AI ‘robots’ that have been
recently created are able to sense emotions and human commands but still lack the ability to feel those emotions to and
change according to them. Luckily, now people are experimenting to create a theory of mind AI ‘robot’.

Self awareness:

 AI can form representation about themselves.

 They are aware about who they are, understand their internal traits, states and conditions and can even perceive human
emotions.

 They are considered to be future generation of AI with super intelligence.

3/24/2023 By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 26


Agent
An agent can be anything that perceive its environment through sensors and act upon that environment through actuators:

 Human-Agent: A human agent has eyes, ears, and other organs which work for sensors and hand, legs, vocal tract work for
actuators.

 Robotic Agent: A robotic agent can have cameras, infrared range finder, NLP for sensors and various motors for actuators.

 Software Agent: Software agent can have keystrokes, file contents as sensory input and act on those inputs and display output on
the screen.

********************************
Sensor: Sensor is a device which detects the change in the environment and sends the information to other electronic devices. An agent observes its environment through
sensors.
Actuators: Actuators are the component of machines that converts energy into motion. The actuators are only responsible for moving and controlling a system. An actuator
can be an electric motor, gears, rails, etc.
Effectors: Effectors are the devices which affect the environment. Effectors can be legs, wheels, arms, fingers, wings, fins, and display screen.
3/24/2023 By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 27
Intelligent Agent in AI
 An AI system is composed of an agent and its environment.

 Agent in artificial intelligence is autonomous entities that act upon an environment using sensors and actuators to achieve their
goals.

 An Agent is anything that takes actions according to the information that it gains from the environment.

 Examples of intelligent agents in AI include Siri, alexa, and driverless cars.

3/24/2023 By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 28


Intelligent Agent in AI

3/24/2023 By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 29


Intelligent Agent in AI

3/24/2023 By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 30


Intelligent Agent in AI
Types of intelligent agents:
Simple Reflex:
• Most simplest type.
• The Simple reflex agent works on Condition-action rule, which means it maps the current state to action, Such as a Room Cleaner
agent, it works only if there is dirt in the room.
• It has limited intelligence.
• Works in an environment where it’s fully observable.
• Not adaptive to changes in the environment.

3/24/2023 By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 31


Intelligent Agent in AI
Types of intelligent agents:
Model Based agents:
• A model-based agent has two important factors:
 Model: It is knowledge about "how things happen in the world," so it is called a Model-based agent.
 Internal State: It is a representation of the current state based on percept history.
• A model-based reflex agent is one that uses its percept history and its internal memory to make decisions about an internal ''model'' of the
world around it.
• The Model-based agent can work in a partially observable environment, and track the situation.
• Example: When a person walks in a lane, he maps the pathway in his mind.
• Updating the agent state requires information about:
 How the world evolves
 How the agent's action affects the world.

3/24/2023 By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 32


Intelligent Agent in AI
Types of intelligent agents:
Goal Based agents:
• The knowledge of the current state environment is not always sufficient to decide for an agent to what to do.
• The agent needs to know its goal which describes desirable situations.
• Goal-based agents expand the capabilities of the model-based agent by having the "goal" information.
• They choose an action, so that they can achieve the goal.
• These agents may have to consider a long sequence of possible actions before deciding whether the goal is achieved or not. Such considerations of different
scenario are called searching and planning, which makes an agent proactive.

3/24/2023 By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 33


Intelligent Agent in AI
Types of intelligent agents:
Utility Based agents:
• These agents are similar to the goal-based agent but provide an extra component of utility measurement which makes them different by providing a measure
of success at a given state.
• Utility-based agent act based not only goals but also the best way to achieve the goal.
• The Utility-based agent is useful when there are multiple possible alternatives, and an agent has to choose in order to perform the best action.
• The utility function maps each state to a real number to check how efficiently each action achieves the goals.

3/24/2023 By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 34


Intelligent Agent in AI
Types of intelligent agents:
Learning agents:
• A learning agent in AI is the type of agent which can learn from its past experiences, or it has learning capabilities.
• It starts to act with basic knowledge and then able to act and adapt automatically through learning.
• Example: Humans learn to speak only after taking birth.
• A learning agent has mainly four conceptual components, which are:
1. Learning element: It is responsible for making improvements by learning from environment
2. Critic: Learning element takes feedback from critic which describes that how well the agent is doing with respect to a fixed performance standard.
3. Performance element: It is responsible for selecting external action
4. Problem generator: This component is responsible for suggesting actions that will lead to new and informative experiences.

3/24/2023 By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 35


Problem

Specification of what are valid inputs and what are acceptable outputs for each valid input.

3/24/2023 By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 36


Problem

 A problem in AI can be defined by 5 components:

1. The initial state: The state from which agent will start.
2. The goal state: The state to be finally reached.
3. The current state: The state at which the agent is present after starting from the initial state.
4. Successor function: It is the description of possible actions and their outcomes.
5. Path cost: It is a function that assigns a numeric cost to each path.

 Once a problem is formulated and its goal is decided, it is the task of the agent to call a proper control
strategy to solve the problem.

3/24/2023 By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 37


Steps in problem representation in AI

1. Define the initial state, final state, acceptable solution(s) of the problem precisely.

2. Analyze the various problem solving techniques to solve the problem.

3. Represent the task knowledge that is necessary to solve the problem.

4. Choose the best possible problem solving technique to solve the problem.

3/24/2023 By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 38


Two ways of representing problem

1. State Space Representation.

2. Problem Reduction.

3/24/2023 By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 39


State Space Representation
• Before an AI problem can be solved it must be represented into some easy understandable form.

• State Space Representation is one such way.

• A state space essentially consists of


1. a set of nodes representing each state of the problem,
2. arcs between nodes representing the legal moves from one state to another,
3. an initial state
4. goal state.

• Let us take the example of Tic Tac Toe problem

3/24/2023 By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 40


State Space Representation of Tic Tac Toe problem
What is the Tic Tac Toe problem? Steps in playing the game:
• It is a two player game • First, one user will place their sign in one of the available empty boxes.
• Two signs represent each player. The general signs used in • Next, the second user will place their sign in one of the available empty
the game are X and O.
boxes.
• There will be a board with 9 boxes.
• The goal of the players is to place their respective signs completely row-

wise or column-wise, or diagonally.

• The game goes on until a player wins the game or it ended up in a draw by

filling all boxes without a winning match.

3/24/2023 By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 41


State Space Representation of Tic Tac Toe problem

***
• Based on the problem
solving technique or
algorithm , a player
will decide his move.

• There are many search


algorithms like bfs, dfs,
A*, etc. which can be
used by a player to
traverse the tree for
winning.

3/24/2023 By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 42


State Space Representation of 8 puzzle problem
8 puzzle problem?
Given a 3×3 board with 8 tiles (every tile has one number from 1 to 8) and one empty space. The objective is to place the numbers on tiles to
match the final configuration using the empty space. We can slide four adjacent (left, right, above, and below) tiles into the empty space.

Problem formulation:

States–It is a set of all possible states where the location of the blank tile and the numbers will differ in each specific state.
Initial State – The state from where the problem starts is its initial state.
Goal State – The state to be reached is the goal state.
Legal Moves – These are the rules which will be followed in order to reach the goal state. Here, the moves which are termed as legal are:

1. Blank square moves Left

2. Blank square moves Right

3. Blank square moves Up

4. Blank square moves Down

3/24/2023 By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 43


State Space Representation of 8 puzzle problem

***
• Based on the problem
solving technique or
algorithm , a player
will decide his move.

• There are many search


algorithms like bfs, dfs,
A*, etc for searching
the tree to reach the
goal node.

In this way you have to explore the state space for the problem until the goal is reached

3/24/2023 By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 44


Problem reduction method of representing problem
• It is not an easy task to find the search space for all problems.
• When the problems get complex in nature it becomes easy to solve the problem by breaking it into smaller problems which would be easier to solve
as compared to the problem as a whole.

• Problem reduction
 A solution to a problem can be obtained by decomposing it into smaller sub-problems.
 Each of this sub-problem can then be solved to get its sub-solution.
 These sub-solutions can then be recombined to get a solution as a whole.

 The structure used to represent such problems is known as an AND OR Graph / Tree.

3/24/2023 By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 45


Control strategies
• Control Strategy in Artificial Intelligence scenario is a technique or strategy that tells us about which rule has to be applied next while searching
for the solution of a problem within problem space.

• It helps us to decide which rule has to apply next without getting stuck at any point.

• These rules decide the way we approach the problem and how quickly it is solved and even whether a problem is finally solved.

• A good Control strategy has two main characteristics:


 Control Strategy should cause Motion: Each rule or strategy applied should cause the motion because if there will be no motion than such
control strategy will never lead to a solution.

 Control strategy should be Systematic: Though the strategy applied should create the motion but if do not follow some systematic strategy
than we are likely to reach the same state number of times before reaching the solution which increases the number of steps.

3/24/2023 By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 46


Types of Control strategies or searching algorithms
Input and output of a search algorithm : A search algorithm takes a problem as an input and returns the solution in the form of an action sequence.
Once the solution is found, the actions it recommends can be carried out. This phase is called as the execution phase.

Search algorithm *********Note*********


Search algorithms form the core of such Artificial Intelligence programs. And while we
may be inclined to think that this has limited applicability only in areas of gaming and
puzzle-solving, such algorithms are in fact used in many more AI areas like route and cost
optimizations, action planning, knowledge mining, robotics, autonomous driving,
computational biology, software and hardware verification, theorem proving etc. In a way,
many AI problems can be modelled as a search problem where the task is to reach the
goal from the initial state via state transformation rules

uninformed/ blind search Informed/heurestic search

3/24/2023 By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 47


Types of Control strategies or searching algorithms
Uninformed search
 Is a class of general-purpose search algorithms which operates in brute force-way.
 Do not have additional information about state or search space other than how to traverse the tree, so it is also called blind search.

Informed search
 Contains an array of knowledge such as how far we are from the goal, path cost, how to reach to goal node, etc.
 This knowledge help agents to explore less to the search space and find more efficiently the goal node.
 Uses the idea of heuristic, so it is also called Heuristic search.
Parameters Informed Search Uninformed Search

It does not require using any knowledge during the process of


Utilizing Knowledge It uses knowledge during the process of searching.
searching.

Speed Finding the solution is quicker. Finding the solution is much slower comparatively.

Completion It can be both complete and incomplete. It is always bound to be complete.

Consumption of Time Due to a quicker search, it consumes much less time. Due to slow searches, it consumes comparatively more time.

Cost Incurred The expenses are much lower. The expenses are comparatively higher.

The AI does not get any suggestions regarding what solution to find
Suggestion/ Direction The AI gets suggestions regarding how and where to find a solution to any problem. and where to find it. Whatever knowledge it gets is out of the
information provided.

It costs more and generates slower results. Thus, it is comparatively


Efficiency It costs less and generates quicker results. Thus, it is comparatively more efficient.
less efficient.

Length of Implementation Implementation is shorter using AI. The implementation is lengthier using AI.

3/24/2023 A few examples include Breadth-First Search or BFS and Depth- 48


Examples A few examples include GraphBySearch
Dr. Manomita Chakraborty,
and Greedy Search. SCOPE, VIT-AP UNIVERSITY
First Search or DFS.
Types of Control strategies or searching algorithms
uninformed/ blind
search

Iterative Deepening
Breadth First Depth First Uniform cost Depth Limited Depth First
Search(BFS) Search(DFS) search Search Search(IDDFS)

Informed
search

Best First Constraint


Hill Simulated Mini-max Alpha-beta Means end Branch and
Search A* AO* satisfaction
climbing annealing algorithm algorithm analysis bound
(BFS) search

These are the not the only informed search


techniques. There are many.

3/24/2023 By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 49


Depth First Search
 Depth first search (DFS) is used for traversing a finite graph or a tree.

 DFS traverses the depth of any particular path before exploring its breadth.

 It explores one subtree before returning to the current node and then exploring the other subtree.

 DFS uses stack instead of queue.

 It traverses a graph or a tree in a depth-ward motion and gets the next vertex to start a search when a dead end occurs

in any iteration.

3/24/2023 By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 50


DFS in tree
Depth First Search

3/24/2023 By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 51


DFS in Graph: Depth First Search

How is stack used here?


• Visit an random unvisited node or the start node
(if it is given) and push it in the stack
Push(1)
Pop(1)
Push(4)
Pop(4)
Push(5) 5 & 2 are equidistant form 4,both
Push(2) the sequences 52 and 25 are correct
Pop(2)
Pop(5)
Push(3)
Pop(3)

**The sequence of the pop operations will show you


the path of the traversal incase of graph

3/24/2023 By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 52


Depth First Search
H
Find the DFS traversal order for the following graphs starting with vertex A
D E
PUSH(A)
POP(A) A C C
Neighbors of A , all the equidistant (CD or DC both the PUSH(E)
PUSH(A) PUSH(C)
orderings correct) PUSH(H)
POP(A) PUSH(D)
PUSH(C) POP(H)
POP(D)
POP(E)
PUSH(D) POP(C)
POP(D)

Neighbors of D, all are equidistant (HE and EH both


orderings are correct)
PUSH(E)
PUSH(H)
**The sequence of the POP operations will show you POP(H)
the path of the traversal incase of graph G
Neighbor of H is already in the stack
POP(E) F F B
DFS ORDER FOR THE POP(C)
PUSH(F) POP(F)
PUSH(B)
PUSH(G) POP(B)
PROBLEM STARTING Neighbors of C. all the equidistant
PUSH(F)
POP(G)

WITH A: PUSH(G)
POP(G)
POP(F)
ADHECGFB Neighbor of F
PUSH(B)
POP(B)
3/24/2023 By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 53
Depth First Search
Find the DFS traversal order for the following graphs starting with vertex A

3/24/2023 By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 54


Depth First Search
Find the path from source to goal in a DFS manner. Source=1 and goal=10

3/24/2023 By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 55


Depth First Search
Complexity of Depth First Search for graph traversal

 The Time complexity of DFS is O(V + E) when Adjacency List is used and O(V^2) when Adjacency Matrix is used,
where V stands for vertices and E stands for edges.

 The space complexity of the algorithm is O(V).

Complexity of Depth First Search for tree traversal

 Time complexity: Equivalent to the number of nodes traversed in DFS.


T(n) = 1 + n^2 + n^3 + ... + n^d = O(n^d), where n = maximum branching factor, and d= maximum depth of the tree.

 Space complexity: DFS algorithm needs to store only single path from the root node, hence space complexity of DFS
is equivalent to the size of the fringe set, which is O(nd).

*** Adjacency list and Adjacency matrix are data structures used for storing graph. Based on the data structure used for storing an input, the
complexity will vary.

3/24/2023 By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 56


Depth First Search

Application of DFS Algorithm

 For finding the path


 To test if the graph is bipartite
 For finding the strongly connected components of a graph
 For detecting cycles in a graph

*** Adjacency list and Adjacency matrix are data structures used for storing graph. Based on the data structure used for storing an input, the
complexity will vary.

3/24/2023 By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 57


Depth First Search
Admissibility and completeness of a search algorithm

 Completeness: An algorithm is complete if it terminates with a solution when one exists.

 Admissibility: An algorithm is admissible if it is guaranteed to return an optimal solution whenever a solution exists.

Admissibility and completeness of DFS

Completeness: DFS is not always complete because Admissibility: DFS is not guaranteed to be admissible .
it can get stuck in infinite loop.  It may return a sub-optimal path to the goal,
and that happens if the goal is reachable in
more than one way, but DFS discovers a longer
path first

DFS is complete if the search space is finite.


3/24/2023 By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 58
TASK 1
Given an initial state of an 8-puzzle problem and final state to be reached. Traverse the state space tree for the
problem using DEPTH FIRST SEARCH algorithm and show the path from initial to final state.

3/24/2023 By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 59


Breadth First Search

 Breadth First Search (BFS) is an algorithm for traversing an unweighted Graph or a Tree.

 BFS starts with the root node and explores each adjacent node before exploring node(s) at the next level.

 BFS makes use of Queue for storing the visited nodes of the graph / tree.

3/24/2023 By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 60


Breadth First Search
BFS in tree

3/24/2023 By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 61


Breadth First Search
BFS in tree

3/24/2023 By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 62


Breadth First Search
BFS in tree

3/24/2023 By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 63


Breadth First Search
BFS in tree

3/24/2023 By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 64


Breadth First Search
BFS in graph

3/24/2023 By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 65


Breadth First Search
Find the BFS traversal order for the following graphs starting with vertex A

3/24/2023 By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 66


Breadth First Search
Find the path from source to goal in a BFS manner. Source=1 and goal=10

3/24/2023 By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 67


Breadth First Search
Admissibility and completeness of BFS

Completeness: BFS is complete.

Admissibility: BFS is admissible if all the edge cost are equivalent.

3/24/2023 By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 68


Breadth First Search

Complexity of BFS for graph traversal


The Time complexity of BFS is O(V + E) when Adjacency List is used and O(V^2) when Adjacency Matrix is used, where V
stands for vertices and E stands for edges.

Complexity of BFS for tree traversal

 Time complexity: Time Complexity of BFS algorithm can be obtained by the number of nodes traversed in BFS until
the shallowest Node. Where the d= depth of shallowest solution and b is a node at every state.
T (b) = 1+b2+b3+.......+ bd= O (bd)
 Space complexity: Space complexity of BFS algorithm is given by the Memory size of frontier which is O(bd).

Application of BFS Algorithm

 Shortest Path and Minimum Spanning Tree for unweighted graph


 Peer to Peer Networks
 Crawlers in Search Engines
 Social Networking Websites
 GPS Navigation systems
 Broadcasting in Network
3/24/2023 By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 69
Breadth First Search vs. Depth First Search

BFS DFS
BFS starts traversal from the root node and visits nodes in DFS starts the traversal from the root
Traversal a level by level manner (i.e., visiting the ones closest to the node and visits nodes as far as possible
root first). from the root node (i.e., depth wise).
Usually implemented using a stack data
Data Structure Usually implemented using a queue data structure.
structure.
Generally requires less memory than
Memory Generally requires more memory than DFS.
BFS.
Not optimal for finding the shortest
optimality Optimal for finding the shortest distance.
distance.
May find a sub-optimal solution (one
It can be slow since it expands all the nodes at each level
Disadvantage that is deeper or more costly than the
before moving on to the next level.
best solution)
Used for topological sorting, solving
Used for finding the shortest path between two nodes, problems that require graph
Application testing if a graph is bipartite, finding all connected backtracking, detecting cycles in a
components in a graph, etc. graph, finding paths between two nodes,
3/24/2023 By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY etc. 70
Best First Search
 It is an informed/heuristic search technique.

 It finds the shortest path from start node to goal node following specific rule.

 It combines the advantages of Depth First Search and Breadth First Search:
 DFS is good because it allows a solution to be found without expanding all the competing neighbors.
 BFS is good because it does not get trapped in dead end paths.

 BFS uses an evaluation function (heuristic cost) to decide which among the various available nodes is the most promising (or ‘BEST’)
before traversing to that node.

 There are two variants of BFS : greedy and A*

 BFS uses Priority Queue.

****A priority queue is a special type of queue in which each element is associated with a priority value. And, elements are served on the basis of their priority. That is, higher priority elements are served first.

3/24/2023 By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 71


Greedy Best First Search
• Evaluation function f (n) is defined in terms of a heuristic function h(n): f(n)= h(n)
h(n) = estimated cost of the cheapest path from the state at node n to a goal state. (for goal state: h(n)=0)
Example: Consider the network below. Find the route from S to F.
h(n)=10
S
Open list (priority Closed list (List of
1 1 queue is used) visited nodes)
h(n)=8 A B
h(n)=7 PQ: [] []
PQ: [S] []
3 2 2 1 PQ: [B,A] (B is put [S]
h(n)=4 h(n) = 5 h(n)=9 h(n)= 0
before A because B
C D E F has lesser cost)
PQ: [F, A, E] [S,B]
PQ: [A, E] [S,B, F]
Goal

 Goal node is found and the optimal path from S(initial node) to F(goal node) is S-B-F with a path cost of 2
3/24/2023 By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 72
Greedy Best First Search
• Consider the below network of 5 cities below. Find the route from city S to city G.

Open list (min


priority queue is Closed list (List of
used for this visited nodes)
problem)
PQ: [] []
PQ: [S] []
PQ: [A, B] [S]
PQ: [G, B] [S , A]
PQ: [B] [S , A, G]

 Goal node is found and the cheapest path is from S(initial node) to G(goal node) is S-A-G with a path cost of 6.
3/24/2023 By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 73
Greedy Best First Search
Best-First-Search(Graph g, Node start, Node goal)

1. Create an empty PriorityQueue


PriorityQueue pq;
2. Insert "start" in pq.
pq.insert(start)
3. Until PriorityQueue is empty
u = PriorityQueue.DeleteMin
If u is the goal
Exit
Else
For each neighbor v of u
If v "Unvisited"
Mark v "Visited"
pq.insert(v)
Mark u "Examined"
End procedure.

The worst-case time complexity for Best First Search is O(n * log n) where n is the number of nodes. In the worst case, we may have to visit all nodes
before we reach goal. Note that priority queue is implemented using Min(or Max) Heap, and insert and remove operations take O(log n) time.

3/24/2023 By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 74


Greedy Best First Search
Problems with BFS:
1. h(n) may overestimate the cost of going from node n to goal:
BFS is greedy in nature . In many cases it leads to a very quick solution but may not produce optimal solution if h(n)
overestimates the cost of going from node n to goal. For example, consider the network below. The red colored
values are heuristic costs.

 According to BFS, cheapest path: S-A-G with a cost of 6.


 Optimal solution: S-B-C-G with a cost of 5
 So, BFS is not admissible.
 BFS can guarantee to give optimal solution only if h(n) is
an admissible heuristic i.e., h(n) does not overestimates the
cost from node n to goal.

********important************
A key property of a heuristic function is that it has to be admissible. In other words, it always has to underestimate the remaining cost.
3/24/2023 By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 75
Greedy Best First Search
Problems with BFS:
2. BFS may not be complete:
The greedy BST algorithm is not complete, that is, there is always the risk to take a path that does not bring to the
goal.

3. BFS can get stuck in infinite loop.

3/24/2023 By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 76


A* algorithm

 The greedy BFS is a simplification of the A* algorithm. A* algorithm was proposed by Hart et al. in the year 1968.

 A* algorithm differs with Best-First Search algorithms only in terms of the heuristic function f(n).

 A* uses f(n) = g(n) + h(n) with h(n) being the estimated distance between any random vertex n and target vertex, g(n)

being the actual distance between the start point and any vertex n.

 If g(n)=0, the A* turns to be Best-First Search.

 If h(n)=0, then A* turns to be Uniform-Cost Search.

3/24/2023 By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 77


A* algorithm
Open list Closed list
(priority (List of
queue is visited
f(A) = g(A) + h(A)=0+10=10 used) nodes)
f(F) = g(F) + h(F)=3+6=9
f(B) = g(B) + h(B)=6+8=14 [A] []
f(G) = g(G) + h(G)=4+5=9 [F, B] [A]
f(H) = g(H) + h(H)=10+3=13 [G,H, B] [A,F]
f(I) = g(I) + h(I)=7+1=8
f(E) = g(E) + h(E)=12+3=15 [I,H,B] [A,F, G]
f(J) = g(J) + h(J)=10+0=10 [J,H,B,E] [A,F, G,I]
[H,B,E] [A,F, G,I,J]

 Goal node is found and the optimal path from A(initial node) to J(goal node) is A-F-G-I-J with a cost of 10

3/24/2023 By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 78


A* algorithm
Admissibility and completeness of A*
A* is complete and optimal on graphs that are locally finite where the heuristics are admissible and monotonic.

A* uses f(n) = g(n) + h(n) with h(n) being the estimated distance between any
random vertex n and target vertex, g(n) being the actual distance between the
start point and any vertex n.
Locally finite : A* must be locally finite, because if there exist an infinite amount of nodes where the estimated path cost, f(n), is less than the
actual goal path cost then the algorithm could continue to explore these nodes without end, and it will be neither complete nor optimal.

h(n) is admissible: A* can guarantee to provide the optimal solution if the heuristic h(n) never overestimates the cost from n to goal, h(n) is
admissible .

h(n) is monotonic: If estimate of h(n) is always less than or equal to the estimated distance from any neighboring vertex of n to the goal, plus the
cost of reaching that neighbor from n.

H(n) is consistent or monotonous is h(n)<=c(n,a,n’) + h(n’)

3/24/2023 By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 79


A* algorithm
Prove with an example that A* can provide optimal solution if h’ never overestimates h, i.e., the cost of going from a node to
the goal: (read from Rich and Knight , page number 61)

3/24/2023 By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 80


A* algorithm
Solve the 8 puzzle problem using A* algorithm.

Initial state Goal state

• h= number of misplaced tiles in each


state. (Example: for the initial state
only 4, 5, and 8 are misplaced, so, h for
start node=3)
• Each edge has a path cost of 1.

3/24/2023 By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 81


AO* algorithm

 AO* algorithm uses the concept of AND-OR graphs to decompose any complex problem given into smaller set of
problems which are further solved.
 The AO* algorithm works on the formula given below : f(n) = g(n) + h(n)
where,
g(n): The actual cost of traversal from initial state to the current state.
h(n): The estimated cost of traversal from the current state to the goal state.
f(n): The actual cost of traversal from the initial state to the goal state.

3/24/2023 By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 82


AO* algorithm
A
Consider the graph.
1 1
1
Objective:
You have to find the route from A to goal node. h(n)=4 B h(n)=2 C h(n)= 3 D
1
Solution: 1 1 1 1
Solve the problem by solving the starting node 1
A. E F G H I J
Node A is solved if either of the subproblems h(n)= 0 h(n)= 0
h(n)=6 h(n) = 8 h(n)=2 h(n)= 0
represented by the path AB or ACD is
solvable.
The problem cannot be solved, if neither of the f(A-B) = g(B) + h(B) = 1+4= 5 f(A-C-D) = g(C) + h(C) + g(D) + h(D) = 1+2+1+3 = 7
subproblems are solvable.

5 A 7
1 1
1

h(n)=4 B h(n)=2 C h(n)= 3 D


1
1 1 1 1
** 1
black color= edge cost I
Red color= heuristic cost
E F G H J
Blue color= new heuristic cost
h(n)=6 h(n)=2 h(n)= 0 h(n)= 0 h(n)= 0
h(n) = 8
3/24/2023 By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 83
AO* algorithm
5 A 7
1 1
1

h(n)=4 B h(n)=2 C h(n)= 3 D


1
1 1 1 1
1
E F G H I J
h(n)=6 h(n)=2 h(n)= 0 h(n)= 0 h(n)= 0
h(n) = 8
The minimum cost path is chosen i.e. A-B. Now we have to solve the sub problem represented by B. B is solvable if either BE or BF is solved

f(B-E) = 1 + 6 = 7
f(B-F) = 1 + 8 = 9

5 A 7
1 1
1

h(n)=4 B h(n)=2 C h(n)= 3 D


**
1 black color= edge cost
7 1 1 9 1 1
Red color= heuristic cost
1 Blue color= new heuristic cost

E F G H I J
h(n)=6 h(n)=2 h(n)= 0 h(n)= 0 h(n)= 0
h(n) = 8
3/24/2023 By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 84
AO* algorithm
5 A 7
1 1
1
h(n)=4 B h(n)=2 C h(n)= 3 D
1
7 1 1 9 1 1
1
E F G H I J
h(n)=6 h(n)=2 h(n)= 0 h(n)= 0 h(n)= 0
h(n) = 8
• The minimum cost path is BE but E is not a goal node . So it is not solvable.
Check whether the revised heuristic costs needs to be back propagated or not
• The heuristics for B have to be updated since there is a difference between actual and heuristic value of B (7 !=4).
 The minimum cost path BE is chosen and is updated as the heuristic for B , in our case the value is 7.
• And because of change in heuristic of B there is also change in heuristic of A which is to be calculated again.
 f(A-B) = g(B) + updated((h(B)) = 1+7=8

5 8 A 7
1 1
1
h(n)= 4
h(n) =7 B h(n)=2 C h(n)= 3 D
1
7 1 1 9 1 1
1 **
I black color= edge cost
E F G H J Red color= heuristic cost
h(n)= 0 Blue color= new heuristic cost
h(n)=6 h(n) = 8 h(n)=2 h(n)= 0 h(n)= 0
Violet color=revised heuristic

3/24/2023
unsolved By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 85
AO* algorithm **
black color= edge cost
Red color= heuristic cost
Blue color= new heuristic cost
Violet color=revised heuristic
5 8 A 7
1 1
1
h(n)= 7 B h(n)=2 C h(n)= 3 D Solved
1
7 1 1 9 1 1 5 8 A 7 5
1
1 1
E F G H I J 1 Solved
h(n)= 4
h(n)= 0 B D h(n)= 3
h(n)=6 h(n) = 8 h(n)=2 h(n)= 0 h(n)= 0 h(n) =7 h(n)=2 C Solved h(n)= 1
1
• Comparing path of f(A-B) and f(A-C-D) it is seen that f(A-C-D) is 7 1 1 9 1 1
smaller. Hence f(A-C-D) needs to be explored. 1
E F G H I J
1. Now the current node becomes C node and the cost of the path is h(n)=6 h(n)=2 h(n)= 0 h(n)= 0 h(n)= 0
h(n) = 8
calculated,
f(C-G) = 1+2 = 3
f(C-H-I) = 1+0+1+0 = 2 Solved Solved
2. f(C-H-I) is chosen as minimum cost path, also there is no change in
heuristic since it matches the actual cost.
3. Heuristic of path of H and I are 0 and hence they are solved.
The solved path is A-C-D with a cost
4. Path A-D also needs to be calculated , since it has an AND-arc.
f(D-J) = 1+0 = 1, there is change in the heuristic of D, so it needs of 5
to be updated to 1 from 3.
5. Heuristic of path of J is 0 and hence it is solved.

• And finally the f(A-C-D) needs to be updated. By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY
3/24/2023 f(A-C-D) = g(C) + h(C) + g(D) + updated((h(D)) = 1+2+1+1 =5. 86
AO* algorithm
(read the algorithm from Rich and Knight , page number 67)

**FUTILITY COST: FUTILITY IS A THRESHOLD FOR A SOLUTION. IF THE COST OF THE


SOLUTION GOES ABOVE FUTILITY, THEN THE SOLUTION IS TOO EXPENSIVE TO BE
PRACTICAL
(IN QUESTION FUTILITY COST MAY OR MAY NOT BE GIVEN)
By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY
3/24/2023 87
AO* algorithm
Advantages:
It is complete
Will not go in infinite loop
Less memory required
Can be applied to both OR and AND graphs.

Disadvantages:
Does not explore all the paths once solution is found, so it is not optimal.
Sometimes for unsolvable nodes , it cannot find a solution.

By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY


3/24/2023 88
AO* algorithm
Consider the graph below. Use AO*
algorithm to find the cheapest route from A to
goal node.

By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY


3/24/2023 89
AO* algorithm

By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY


3/24/2023 90
AO* algorithm

By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY


3/24/2023 91
AO* algorithm

By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY


3/24/2023 92
AO* algorithm
Consider the graph below. Use AO* algorithm to find the cheapest route from A to goal node.

By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY


3/24/2023 93
Generate and Test Search
1. Most simplest type of Informed search.

2. Generate and Test Search is a heuristic search technique based on Depth First Search with Backtracking which guarantees to
find a solution if done systematically and there exists a solution.

By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY


3/24/2023 94
Hill Climbing
1. It is a heuristic search widely used for mathematical optimization problems in the field of Artificial Intelligence.

2. The name of the algorithm is given after David Hill and is based on concept of climbing a hill.

3. The idea is to start with a sub-optimal solution to a problem (i.e., start at the base of a hill) and then repeatedly improve
the solution(walk up the hill) until some condition is maximized (the top of the hill is reached). (reverse case for
minimization problem.)

4. Hill climbing is used widely in artificial intelligence fields, for reaching a goal state from a starting node. Choice of next
node/starting node can be varied to give number of related algorithms.

5. In hill climbing, the basic idea is to always head towards a state which is better than the current one. So, if you are at town A
and you can get to town B and town C (and your target is town D), you should make a move if town B or C appear nearer to
town D than town A does.

6. Given a large set of inputs and a good heuristic function, it tries to find a sufficiently good solution to the problem.

7. The solution may not be the global optimal maximum.

8. One of the widely discussed examples of Hill climbing algorithm is Traveling-salesman Problem in which we need to
minimize the distance traveled by the salesman.
By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY
3/24/2023 95
Hill Climbing

1. Features of Hill Climbing Algorithm:

a) Generate and Test variant: Hill Climbing is the variant of Generate and Test method. The Generate and Test method

produce feedback which helps to decide which direction to move in the search space.

b) Greedy approach: Hill-climbing algorithm search moves in the direction which optimizes the cost.

c) No backtracking: It does not backtrack the search space, as it does not remember the previous states.

By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY


3/24/2023 96
Hill Climbing

The state-space landscape is a graphical representation of the hill-climbing algorithm which is showing a graph between
various states of algorithm and Objective function/Cost.

By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY


3/24/2023 97
Hill Climbing
Types of Hill Climbing:

1. Simple hill Climbing.


2. Steepest-Ascent hill-climbing.
3. Stochastic hill Climbing.

By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY


3/24/2023 98
Simple Hill Climbing
 Simple hill climbing is the simplest way to implement a hill climbing algorithm.

 It performs a local search and choses the best state that is better than the current state.

 It only evaluates the neighbor node state at a time and selects the first one which optimizes current cost(DOES NOT KEEP
TRACK OF OTHER NEIGHBORS) and set it (first one ) as a current state.

 It has information about local domain , does not have info about global domain. It does not remember those neighbors who are not
explored or not selected.

 No backtracking.
10
s

10 9 7
A B C

4 3
D E

By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY


3/24/2023 99
Simple Hill Climbing
CURRENT nodes
Algorithm CLOSED

Step 1: Put initial node in list CURRENT. A


Step 2: If (CURRENT==empty) or (CURRENT==goal) terminate search. B
A
Step 3: Remove the CURRENT node and push to CLOSED . Call this NODE as k. H A B
1. If (k==goal), terminate with success. G A B H
2. Else if node k has successor , find out the first successor node which optimizes the
heuristic cost and set it as the CURRENT node. Goto step 2
A B H G PATH

Consider the task to h(n)=6


find minimum route A
SHC almost looks like DFS….Then
what is the difference between SHC
h(n)=4 B h(n)=2 C h(n)= 3 D and DFS?

h(n)=5 E H I h(n)= 1.5


h(n)= 3

h(n)= 1
h(n)= 0 By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY
3/24/2023 G F 100
Simple Hill Climbing

SHC almost looks like DFS….Then what is the difference between SHC and DFS?

 DFS traverses the tree depth wise blindly. There is no heuristic involved.

 Whereas SHC also finds the solution depth wise but it uses a heuristic to decide which node to explore.
And it finds the solution greedily. And no backtracking is involved in SHC compared to DFS.

By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY


3/24/2023 101
Steepest-Ascent hill-climbing
 Steepest ascent hill climbing is a variation of the simple hill climbing algorithm.

 Instead of evaluating first best neighboring state, steepest ascent hill climbing evaluates all the neighboring states and
select the one that improves the objective function the most (steepest).

 Steepest means largest and Ascent means upward.

18.8
Steepest-Ascent hill-climbing
Algorithm CURRENT node
CLOSED

Step 1: Put initial node in list CURRENT. A


Step 2: If (CURRENT==empty) or (CURRENT==goal) terminate search. C
A
Step 3: Else remove the CURRENT node and push to CLOSED . Call this NODE as k. H A C
1. If (k==goal), terminate with success. G A C H
2. Else if node k has successor generate all of them. Sort them by remaining distance
from goal and set the node with best heuristic as the CURRENT node. Goto step 2. A C H G PATH

h(n)=6
A

h(n)=4 B h(n)=2 C h(n)= 3 D

h(n)=1.7 E h(n)= 1 H I
h(n)= 1.5

By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY


3/24/2023 h(n)= 0 G 103
Steepest-Ascent hill-climbing

Steepest-Ascent hill-climbing almost looks like Best First Search….Then what is the difference between them?

 The similarity is that both of them picks the best successor of a current node to explore (based on some heuristic) among all
the available successors.

 The difference is that best-first search considers all paths from the start node to the end node(i.e., it remembers all the
successors of a node , both explored and not explored), whereas steepest ascent hill climbing only remembers one path during
the search (i.e., it does not remember the successors that are not explored). So, in Steepest-Ascent backtracking is not
possible.

 BFS uses more memory , as it remembers all the successors of a node.

By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY


3/24/2023 104
Stochastic hill climbing
 It does not examine all the neighboring nodes before deciding which node to select. It just selects a neighboring node at
random and decides (based on the amount of improvement in that neighbor) whether to move to that neighbor or to examine
another.

Algorithm

Step 1: Put initial node in list CURRENT.

Step 2: If (CURRENT==empty) or (CURRENT==goal) terminate search.

Step 3: Else remove the CURRENT node and push to CLOSED . Call this NODE as k.

1. If (k==goal), terminate with success.

2. Else if node k has successor generate all of them. Generate all the successors of k and
among the generated neighbor states which are better than the current state choose a
state randomly (or based on some probability function). Set the selected state as
CURRENT STATE and Goto step 2.
Problems with Hill Climbing
Problems with hill climbing

• Local maximum
• Plateau
• Ridge
Problems with Hill Climbing
Local maximum:
At a local maximum all neighboring states have a value that is worse than the current state. Since hill-climbing uses a greedy
approach, it will not move to the worse state and terminate itself. The process will end even though a better solution may exist.
Example:
How SHC can get trap in local
maxima?
Let us take the 8 puzzle problem.
h=number of misplaced tiles. How
far a state is from goal node is
represented by h.

***backtracking can be used to deal with this problem


of local maximum
Problems with Hill Climbing
Local maximum:

4 6
A B

2 3 2 1
C D E F

SHC reaches here global maximum


which his local
maximum

***backtracking can be used to deal with this problem of local maxima


Problems with Hill Climbing
Plateau:
On the plateau, all neighbors have the same value. Hence, it is not possible to select the best direction. .

4 4
A B All the neighbours are having same value

3 2 2 1
C D E F

***To overcome plateaus: Make a big jump. Randomly select a state far away from the current state. Chances are that we
will land in a non-plateau region.
Problems with Hill Climbing
Ridge: A ridge is a special form of the local maximum. It has an area which is higher than its surrounding areas, but itself has a
slope, and cannot be reached in a single move . The hill-climbing algorithm may terminate itself when it reaches a ridge. This is
because the peak of the ridge is followed by downward movement rather than upward movement.

Solution: With the use of bidirectional search, or by moving in different directions, we can improve this problem.
Hill-climbing using local and global heuristic functions
Choosing an appropriate heuristic function in hill climbing is very important to avoid local maximum .
Let us take an example: Suppose you want go from initial to final state as shown in image below

Solution using local heuristic function

Let's define such function h:

h(x) = +1 for a block in the support structure if the block is correctly positioned.
h(x) = -1 for a block in the support structure if the block is wrongly positioned.

By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY


3/24/2023 111
Hill-climbing using local and global heuristic functions
Solution using local heuristic function

A is resting on wrong support , so -1


D is resting on correct support, so +1
C is resting on correct support, so +1
h for start state= -1+1+1-1= 0
B is resting on wrong support, so -1

D is resting on correct support , so +1


C is resting on correct support, so +1 h for goal state= 1+1+1+1= 4
B is resting on correct support, so +1
A is resting on correct support, so +1

Using this information we have to use some operator to go from start to goal node

By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY


3/24/2023 112
Hill-climbing using local and global heuristic functions
Solution using local heuristic function

C D
B A
D
h = -1+1+1 -1=0
C
C h=4
B A
B A D
h=0 h = -1+1+1 +1=2
h = -1+1+1 -1=0

A Local Maximum
D

C
B
h=0

By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY


3/24/2023 So we cannot proceed further 113
Hill-climbing using local and global heuristic functions
Let us take an example: Suppose you want go from initial to final state as shown in image below

Solution using global heuristic function

Let's define such function h:

h(x) =For a block, +1 for all the blocks in the support structure correctly positioned otherwise -1 for all the blocks in the
support structure.

By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY


3/24/2023 114
Hill-climbing using local and global heuristic functions
Solution using global heuristic function

A is resting on incorrect support, three blocks are incorrectly placed, so -3


D is resting on incorrect support, two blocks are incorrectly placed, so -2
h for start state= -3-2-1+0= -6
C is resting on B which is wrongly placed, so -1
B is resting on 0 blocks, so 0

D is resting on correct support (3 blocks below) , so +3


C is resting on correct support (2 blocks below) , so +2 h for goal state= 3+2+1+0= 6
B is resting on correct support(1 block below) , so +1
A is resting on ground(0 block below), so 0

Using this information we have to use some operator to go from start to goal node

By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY


3/24/2023 115
Hill-climbing using local and global heuristic functions
Solution using global heuristic function

C D
If SHC is used you will go with this
B A
D
h = 0-1+0-1=-2
C
C h=6
B A
B A D If steepest ascent hill climbing is used you will go with this
h = -6 h = 0-1-2+0=-3
h = 0-1+0+0=-1

C
B
h = -6

Let us go with the steepest ascent hill climbing


By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY
3/24/2023 116
Hill-climbing using local and global heuristic functions
Solution using global heuristic function

h = -6 h=6

By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY


3/24/2023 117
Hill-climbing
Solve the 8 puzzle problem using hill climbing method

Consider h(n) as the number of misplaced tiles

By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY


3/24/2023 118
Constraint Satisfaction
 One of the Problem-solving strategies.
 It is used for solving those problems where there are possibilities of finding multiple solutions and there are some constraints associated
for finding the solution.
 It is the process of finding a solution through a set of constraints that impose conditions that the variables must satisfy.
 It tries out all the possible solutions and chooses the feasible ones out of them.
 Backtracking is allowed here. If the current solution is not feasible, then eliminate that and backtrack (go back) and check for other
solutions.

State Chakraborty,
By Dr. Manomita space tree SCOPE, VIT-AP UNIVERSITY 119
Constraint Satisfaction
 Example:
 Suppose , you want to find all the possible ways of arranging 2 boys and 1 girl on 3 benches.
 Constraint: Girl should not be on the middle bench.
 Solution: There are a total of 3! = 6 possibilities. We will try all the possibilities and get the possible solutions. We recursively try all the
possibilities.

Start Start

B1 B2 G B1 B2 G

B2 G B1 G B1 B2 B2 G B1 G B1 B2

G B2 G B1 B2 B1 G G B2 B1

Sol Sol Sol Sol Sol Sol Sol Sol


Constraint satisfaction
Brute-force Method Method
By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 120
Constraint Satisfaction
 Syllabus for List of problems on Constraint Satisfaction:
1. Cryptarithmetic Problem
2. N queens problem
3. Graph coloring problem

By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 121


Cryptarithmetic Problem
 It is a type of constraint satisfaction problem where the game is about digits and its unique replacement either with alphabets or other
symbols.
 The digits (0-9) get substituted by some possible alphabets or symbols.
 The task is to substitute each digit with an alphabet to get the result arithmetically correct.
 For example : If you are given with the combination of alphabets as below:

 You have to replace each unique alphabet by a unique number between 0 to 9 such that the final answer is correct:

By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 122


Cryptarithmetic Problem
Question : Solve the following puzzle by replacing each unique alphabet with a unique digit between (0-9).

 Constraints allowed:

 There should be a unique digit to be replaced with a unique alphabet.


 The result should satisfy the predefined arithmetic rules, i.e., 2+2 =4, nothing else.
 Digits should be from 0-9 only.
 There should be only one carry forward, while performing the addition operation on a problem.
 The problem can be solved from both sides, i.e., left-hand side (L.H.S), or right-hand side (R.H.S)

By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 123


Cryptarithmetic Problem
Carry

? ? ? ?
+ ? ? ? ?
? ? ? ? ?

•Starting from the left hand side (L.H.S) , the terms are S and M. Assign a digit which could give a satisfactory result. (S+M) =MO. So,
definitinity, the summation should produce a two digit number. Left digit for (MO) CANNOT BE 1, BECAUSE FOR THAT ONE ALPHABET
AMONG S AND M HAVE TO GREATER THAN 9 WHICH IS VIOLATING THE RANGE OF DIGIT. SO, Let’s assign S->9 and M->1.

S 9

M 1

S 9 O 0

+M +1 E ?

MO 10 N ?

R ?

D ?

Y ?

By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 124


Cryptarithmetic Problem
Carry 0
9 ? ? ?
+ 1 0 ? ?
1 0 ? ? ?

•Now, move ahead to the next terms E and O to get N as its output.

S 9

M 1

O 0

Adding E and O, which means 5+0=0, which is not possible because according to cryptarithmetic constraints, we cannot E 5
assign the same digit to two letters. So, we need to think more and assign some other value. N 6
Carry 1

E ? 5 R ?

+O +0 +0 D ?

N ? 6 Y ?

By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 125


Cryptarithmetic Problem
Carry 0 1
9 5 6 ?
+ 1 0 ? 5
1 0 6 5 ?
•Further, adding the next two terms N and R we get.

S 9

M 1

O 0

But, we have already assigned E->5. Thus, the above result does not satisfy the values because we are getting a different E 5
value for E. So, we have to assign something else to R as N is already 6. N 6
Carry 1
N R 8
6 6
+R D ?
+? +8
E Y ?
15 15

By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 126


Cryptarithmetic Problem
Carry 0 1 1
9 5 6 ?
+ 1 0 8 5
1 0 6 5 ?
•Again, on adding the last two terms, i.e., the rightmost terms D and E, we get Y as its result..

S 9
D ? 7
M 1
+E +5 +5
O 0
Y 1? 12
E 5

N 6

R 8
9 5 6 7
D 7
+ 1 0 8 5
Y 2
1 0 6 5 2
SOLUTION
By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 127
Cryptarithmetic Problem
Question From the multiplication below, What is the value of N + A + M + E?

From the first row of multiplication, H =1 is clear, As HE x H = HE. Substitute H = 1 in all places.

1 E
X E 1
1 E
1 1 A
1 N M E

By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 128


Cryptarithmetic Problem
Question: From the multiplication below, What is the value of N + A + M + E?

1 E
X E 1
1 E
1 1 A
1 N M E
Now from the tenth's place, think about, the value of A. 1 + A = M. If M is a single digit number, then N = 1,
which is impossible (Already we have given H = 1). So A = 9, Then M = 0, and N = 2. Now 1E x E = 119. So
by trial and error E = 7.

1 7
X 7 1
1 7 NAME = 2907
1 1 9 N + A + M + E= 18

1 2 0 7
By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 129
Cryptarithmetic Problem
Question : Find the Sum of (A+B+C) if ABC = A!+B!+C!

• Let us try to find the largest number among (0-9) that can be assigned to A or B or C.

• 7 , 8, or 9 cannot be assigned to either of A or B or C, as factorial of 7 or 8 or 9 is greater than a three digit number.

• Let us take the largest number as 6: 6! = 720, is a 3 digit number. But, we cannot take 6 as the largest number as factorial of 6 is
having a digit 7 greater than 6.

• Let us take the largest number as 5 : 5!=120. All the digits in 120 are less than 5. So , we can add something with 5! to satisfy the
condition ABC = A!+B!+C!

• So, 5 can be assigned to the alphabets? can we assign 5 to all the alphabets? If no, find out which alphabet is assigned as 5 and
what are the values for the remaining alphabets.

By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 130


Cryptarithmetic Problem
Question : Solve the following puzzles by replacing each unique alphabet with a unique digit between (0-9).

1. B A S E
+ B A L L
G A M E S

2. If KANSAS + OHIO = OREGON Then find the value of G + R + O + S + S

3. HERE = COMES - SHE, (Assume S = 8) Find the value of R + H + O

Sample Questions:
https://www.faceprep.in/logical-reasoning/cryptarithmetic-problems/
By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 131
n- Queens problem
1) n- Queens problem: Placing n chess queens on an n * n chessboard such that no queens attack each other.
(Example: 4-Queen Problem, 8-Queen problem)

Solution requires:
No queens share the same row
No queens share the same column
No queens share the same diagonal

By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 132


n- Queens problem
n- Queens problem

8-Queens problem One Possible Solution

 Total number of possible configurations to be checked for finding a solution for the 8-Queens problem:
64C = 4426165368 -> very Expensive
8

 Total number of possible configurations , ensuring the constraints of rows and columns : 8!
 Among 8! Solutions we need to reject those solutions where queens share same diagonal.
 Solution:
1. Explore all the possibilities, find the required solution(Brute-force method)
2. Backtracking
By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 133
n- Queens problem
n- Queens problem
 Solution 1: Let us take the example of 4-Queens Problem

Complete state space tree for 4*4 chess board using brute force method

 Maximum Number of nodes generated ensuring the constraint of rows and column for the 4-Queens
problem using brute force method: 1 + 4 + (4*3) + (4*3*2 ) + (4*3*2*1) = 1 + 3𝑖=0 𝑖𝑗=0(4 − 𝑗) = 𝟔𝟓 𝑛𝑜𝑑𝑒𝑠

 Maximum Number of nodes generated ensuring the constraint of rows and column for the 8-Queens
problem using brute force method: = 1 + 7𝑖=0 𝑖𝑗=0(8 − 𝑗) = 𝟏𝟐𝟗𝟕𝟔𝟏 𝑛𝑜𝑑𝑒𝑠 −−−−→ 𝑣𝑒𝑟𝑦 𝑙𝑎𝑟𝑔𝑒
By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 134
n- Queens problem
n- Queens problem
 Solution 2: How to ignore exploring all the possible nodes -> Use Backtracking
4 Queens Problem:

Q1

Q1

Q2
Q2 cannot be placed
here as it falls in the
same diagonal to Q1

By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 135


n- Queens problem
n- Queens problem
 Solution 2: How to ignore exploring all the possible nodes -> Use Backtracking
4 Queens Problem:

Q1

Q1 Q1
Q2 Q2

Q1 Q1
Q2 Q2
Q3 Q3

By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 136


n- Queens problem
n- Queens problem
 Solution 2: How to ignore exploring all the possible nodes -> Use Backtracking
4 Queens Problem:

Q1

Q1
Q1 Q1
Q2
Q2 Q2

Q1 Q1
Q1 Q1
Q2 Q2
Q2 Q2
Q3 Q3
Q3 Q3

Q1
Q2
Q3
By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 137
Q4
n- Queens problem
n- Queens problem
4 Queens Problem:

Q1= Q1
1

Q2= Q2= Q2=


2 3 4 Q1 Q1 Q1
Q2 Q2 Q2

Q3= Q3= Q3= Q2=


2 4 2 3
Q1 Q1

Q2 Q2

Q3 Q3
Q4=
3
Q1
Q2
Q3

By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY Q4 138


Sol
n- Queens problem
n- Queens problem
4-Queens Problem:
 One solution for the 4-Queens problem : 2,4,1,3
 In this way if the whole tree is explored using backtracking, we will get another solution which is mirror of
2,4,1,3 -> 3,1,4,2

Q1 Q1 Q1
Q1
=1 =2 Q2 Q2

Q3 Q3

Q4 Q4
Q2 Q2 Q2 Q2 Q2 Q2
=2 =3 =4 =1 =3 =4

Q3 Q3 Q3 Q3
=2 =3 Q3 Q3
=2 =4
=1 =3

Q4
=3 Q4
=3

Sol
By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 139
n- Queens problem
n- Queens problem
4 Queens Problem: Solutions: 2,4,1,3 and 3,1,4,2

whole State Space Tree:

Q1 Q1 Q1 Q1
=1 =2 =3 =4

Q2 Q2 Q2 Q2 Q2 Q2 Q2 Q2 Q2
Q2 Q2 Q2
=2 =3 =4 =1 =2 =4 =1 =2 =3
=1 =3 =4

Q3 Q3 Q3 Q3 Q3 Q3 Q3 Q3
=2 =4 =2 =3 Q3 Q3 Q3 Q3 =2 =3 =1 =3
=1 =3 =2 =4
Q4
=3 Q4 Q4
=3 Q4
=2
=2
Sol Sol
By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 140
n- Queens problem
n- Queens problem
8-Queens Problem:
 Similarly for the 8-Queens problem we can find the solutions using backtracking.
 It will have 92 solutions.

By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 141


n- Queens problem
n- Queens problem
Time complexity:
 For finding a single solution where the first queen Q has been assigned the first column and can be put on
N positions, the second queen has been assigned the second column and would choose from N-1 possible
positions and so on; the time complexity is O ( N * ( N - 1 ) * ( N - 2 ) * … 1 ). i.e The worst-case time
complexity is O ( N! ).
 Thus, for finding all the solutions to the N Queens problem the time complexity runs in polynomial time..

By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 142


Graph Coloring problem
Graph Coloring problem

Given an undirected graph and a number m, determine if the graph can be colored with at most m colors such that no two adjacent
vertices of the graph are colored with same color.

By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 143


Graph Coloring problem
Graph Coloring problem

Two problems will be solved by solving the graph coloring problem:


1. M-coloring decision problem: In how many ways the graph can be colored with the given m colors such that no two adjacent vertices are having
same colors. Example : Consider the graph below . In how many ways the graph can colored with m={red, blue, green} such that no two vertices
are having same color.

1 2

3
Solution: 6 feasible decisions

1 2 1 2 1 2 1 2 1 2 1 2

3 3 3 3 3 3

2. M-coloring optimization problem: What is the minimum number of colors among the m colors with which the graph can be colored.
 Chromatic Number: The smallest number of colors needed to color a graph G is called its chromatic number. For example, the following can
be colored minimum 2 colors.
1 2
4 By Dr. Manomita
3 Chakraborty, SCOPE, VIT-AP UNIVERSITY 144
Graph Coloring problem
Graph Coloring problem
 First Let’s try to solve this problem using Brute-Force method.
Example: Suppose we want to color the  State Space Tree Using brute-force method: (without following any restrictions)
graph below with color R,B,G such that no
two adjacent vertices are having same
colors. How many solutions are possible
for this? What is the chromatic number for
solving this problem? 1 1 1

1 2

4 3

………………………………………………………………………………………………………………..

Time Complexity: O(𝒎𝒏 ) , n= number of vertices , m=number of colors


By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 145
Graph Coloring problem
Graph Coloring problem
 State Space Tree Using Backtracking
Example: Suppose we want to color the  Constraint: No two adjacent vertices should have the same color.
graph below with color R,B,G such that no
two adjacent vertices are having same
colors. How many solutions are possible
for this? What is the chromatic number for
solving this problem? 1 1 1

1 2 2 2 2 2
2 2

4 3
3 3 3 3 3 3 3 3 3 3 3 3

4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY
Number of Solutions=18 (Eg=RBRB, RBRG, etc.), Chromatic Number =2 (Eg= RBRB, etc.) 146
Graph Coloring problem
Graph Coloring problem

Complexity Analysis: For m colors and n vertices

• Time Complexity: O(𝒎𝒏 ).


There is a total O(𝒎𝒏 ) combination of colors. So, the time complexity is O(𝒎𝒏 ).
• Space Complexity: O(n).
Recursive Stack of graphColoring(…) function will require O(n) space.

By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 147


Algorithm for Constraint Satisfaction
Rich and Knight, page 69

By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 148


Production System
• A production system (popularly known as a production rule system) is a kind of cognitive architecture that is used to
 implement search algorithms and
 replicate human problem-solving skills.

• The knowledge for solving a problem is stored in the form of productions.

• Production consists of two components: rule and action.

 Rules recognize the condition,


 The actions part has the knowledge of how to deal with the condition.

• The rules in a production system are determined by LHS (left-hand side) and RHS (right-hand side) equations, where LHS
denotes the specific condition to be applied, and RHS shows the output of the applied condition.

***Cognitive architectures are computational models of the human mind. They aim to capture the essential components of cognition,
including perception, action, memory, and reasoning.

By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 149


Architecture of a Production System in AI
Knowledgebase (Production Rules)

 A set of production rules, which are of the form A->B.


 Each rule consists of left hand side constituent that represent
the current problem state and a right hand side that represent an
output state.
 A rule is applicable if its left hand side matches with the current
problem state.
 Production rules in AI are the set of rules that operates on the
data fetched from the global database.

Global database Control Structure


 A global database consists of the architecture used as a central data structure.
 A database contains all the necessary data and information required for the  The control system checks the applicability of a rule.
successful completion of a task.  It helps decide which rule should be applied and terminates the
 It can be divided into two parts as permanent and temporary. The permanent process when the system gives the correct output.
part of the database consists of fixed actions, whereas the temporary part alters  It also resolves the conflict of multiple conditions arriving at
according to circumstances. the same time.
 The strategy of the control system specifies the sequence of
rules that compares the condition from the global database to
reach the correct result..

By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 150


Characteristics of a Production System

Simplicity: The structure of each sentence in a production system is unique and uniform as they use “IF-THEN” structure. They are simple and
easy to understand.

Modularity: This means production rule code the knowledge available in discrete pieces. Information can be treated as a collection of independent
facts which may be added or deleted from the system with essentially no deleterious side effects.

Modifiability: This allows the development of production rules in a skeletal form first and then it is made accurate to suit a specific application.

Knowledge intensive: The knowledge base of production system stores pure knowledge. This part does not contain any type of control or
programming information. Each production rule is normally written as an English sentence; the problem of semantics is solved by the very structure
of the representation.

By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 151


Water Jug Problem
Suppose you have two jugs with capacity X litre and Y litre. And you want to get exactly m litre water into
the X litre jug . How will you solve this problem? You can do only three operations:
 Empty a Jug completely ,
 Fill a Jug completely,
 Pour water from one jug to the other until one of the jugs is either
empty or full,
(Consider X=4, Y=3, m=2).

X Y X

By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 152


Water Jug Problem
The state space for the problem can represented as a set of ordered pairs: (X, Y) such that X=0,1,2,3, or 4 and
Y= 0,1,2, or 3. Start state= (0,0) and the Goal state= (2,n)

Production rules
S.No. Initial State Condition Final state Description of action taken

1. (x,y) If x<4 (4,y) Fill the 4 gallon jug completely

2. (x,y) if y<3 (x,3) Fill the 3 gallon jug completely

3. (x,y) If x>0 (x-d,y) Pour some part from the 4 gallon jug

4. (x,y) If y>0 (x,y-d) Pour some part from the 3 gallon jug

5. (x,y) If x>0 (0,y) Empty the 4 gallon jug

6. (x,y) If y>0 (x,0) Empty the 3 gallon jug

7. (x,y) If (x+y)<7 (4, y-[4-x]) Pour some water from the 3 gallon jug to fill the four gallon jug
&& x<4

8. (x,y) If (x+y)<7 (x-[3-y],3) Pour some water from the 4 gallon jug to fill the 3 gallon jug.
&& y<3

9. (x,y) If (x+y)<=4 (x+y,0) Pour all water from 3 gallon jug to the 4 gallon jug

10. (x,y) if (x+y)<=3 (0, x+y) Pour all water from the 4 gallon jug to the 3 gallon jug

By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 153


Water Jug Problem
The state space for the problem can represented as a set of ordered pairs: (X, Y) such that X=0,1,2,3, or 4 and
Y= 0,1,2, or 3. Start state= (0,0) and the Goal state= (2,n) (0,0)
Rule 1
One possible solution Rule 2

(4,0) (0,3)
S.No. 4 gallon jug 3 gallon jug Rule followed Rule 9
contents contents
(3,0)
1. 0 gallon 0 gallon Initial state
Rule 2
2. 0 gallon 3 gallons Rule no.2
3. 3 gallons 0 gallon Rule no. 9 (3,3)
Rule 7
4. 3 gallons 3 gallons Rule no. 2
5. 4 gallons 2 gallons Rule no. 7
(4,2)
6. 0 gallon 2 gallons Rule no. 5
Rule 5
7. 2 gallons 0 gallon Rule no. 9
(0,2)
Rule 9

(2,0)

By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 154


Water Jug Problem
The state space for the problem can represented as a set of ordered pairs: (X, Y) such that X=0,1,2,3, or 4 and
Y= 0,1,2, or 3. Start state= (0,0) and the Goal state= (2,n) (0,0)
Rule 2
Another possible solution Rule 1

(0,3) (4,0)
S.No. 4 gallon jug 3 gallon jug Rule followed Rule 8
contents contents
(1,3)
1. 0 gallon 0 gallon Initial state
Rule 6
2. 4 gallon 0 gallons Rule no.1
3. 1 gallons 3 gallon Rule no. 8 (1,0)
Rule
4. 1 gallons 0 gallons Rule no. 6 10

5. 0 gallons 1 gallons Rule no. 10


(0,1)
6. 4 gallon 1 gallons Rule no. 1
Rule 1
7. 2 gallons 3 gallon Rule no. 8
(4,1)
Rule 8

(2,3)

By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 155


Missionaries and Cannibals Problem
In the missionaries and cannibals problem, three missionaries and three cannibals must cross a river
using a boat which can carry at most two people, under the constraint that,
 For both banks, if there are missionaries present on the bank, they cannot be outnumbered by
cannibals (if they were, the cannibals would eat the missionaries).
 The boat cannot cross the river by itself with no people on board.

By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 156


Missionaries and Cannibals Problem
The state for this problem can be defined as
{(M, C)/ M=0, 1, 2, 3, C=0, 1, 2, 3} where M represents the number missionaries in one side
of a river , C represents the number of cannibals in the same side of river.
 The initial state is (3,3), that is three missionaries and three cannibals one side of a river , (Bank 1) and ( 0,0) on another side of the river
(bank 2) .
 The goal state is to get (3,3) at bank 2 and (0,0) at bank 1.

RULE NO RULES

1 (2,0) : Two missionaries can cross in boat only when (M-2)>=C or M-2=0 in one bank and
(M+2)>C in the other bank.
2 (0,2) : Two cannibals can cross in boat only when (C-2)<=M or M=0 in one bank and (C+2)<=M
or M=0 in the other bank.
3 (1,1) : One missionary and one cannibal can cross in boat only when (C-1)<=(M-1) or M=0 in
one bank and (C+1)<=(M+1) or M=0 in the other bank.
4 (1,0) : One missionary can cross in boat only when C<=(M-1) or M=0 in one bank and C<M+1
or C=0 in the other bank.
5 (0,1) : One cannibal can cross in boat only when (C-1)<M or M=0 in one bank and (C+1)<=M
or M=0 in the other bank.

By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 157


Missionaries and Cannibals Problem
Bank 1 Bank1 -> bank2 Bank 2->bank 1 (Bank 2)

(3,3) (0,0)

(2,2) (1,1) (1,1)

(3,2) (1,0) (0,1)

(3,0) (0,2) (0,3)

(3,1) (0,1) (0,2)

(1,1) (2,0) (2,2)

(2,2) (1,1) (1,1)

(0,2) (2,0) (3,1)

(0,3) (0,1) (3,0)

(0,1) (0,2) (3,2)

(0,2) (0,1) (3,1)

(0,0) (0,2) By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY (3,3) 158
Tic Tac Toe
What is the Tic Tac Toe problem? Steps in playing the game:
• It is a two player game • First, one user will place their sign in one of the available empty boxes.
• Two signs represent each player. The general signs used in • Next, the second user will place their sign in one of the available empty
the game are X and O.
boxes.
• There will be a board with 9 boxes.
• The goal of the players is to place their respective signs completely row-

wise or column-wise, or diagonally.

• The game goes on until a player wins the game or it ended up in a draw by

filling all boxes without a winning match.

3/24/2023 By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 159


Solution to Tic Tac Toe: program1 or solution1
PROGRAM1 OR SOLUTION1:
Data Structures used : Board and Move table
Board: Move table:
 9 element vectors representing the board, with 1-9 for  It is a vector of 3^9 elements, each element of which is a nine-element
each square. vector representing board position.
 An element contains the value:  Total of 3^9=(19683) elements in move table
• 0 if it is blank  Sample Move Table looks like as shown below:
• 1 if it is filled by X
• 2 if it is filled with an O
Current Board
Index New Board position
position
000000000 000010000
1 2 3 1 000000001 020000001

4 5 6 2 000000002 000100002
1 2 3 4 5 6 7 8 9
3 000000010 002000010
7 8 9
… … …
2D array 1D array

*****
One of the player is a computer and one will be a human.

3/24/2023 By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 160


Solution to Tic Tac Toe: program1 or solution1
PROGRAM1 OR SOLUTION1:
Current Board Algorithm
Index New Board position To make a move, do the following:
position
0 000000000 000010000 1. View the vector (board) as a ternary number and convert it to its
corresponding decimal number.
1 000000001 020000001 2. Use the computed number as an index into the move table and access the
vector stored there.
2 000000002 000100002
3. The vector selected in step 2 represents the way the board will look after
3 000000010 002000010 the move that should be made. So set board equal to that vector.

… … …

How Move table is used by a computer?


(000000000)𝟑 0 0 0 0 0 0 (000010000)𝟑 = 0*𝟑𝟖 + 0*𝟑𝟕 + 0*𝟑𝟔 +0*𝟑𝟓 + 1*𝟑𝟒
0 0 0 = (000000000)𝟏𝟎 +0*𝟑𝟑 +0*𝟑𝟐 +0*𝟑𝟏 + 0*𝟑𝟎 = (000000081)𝟏𝟎
In this way the rules
0 1 0 0 1 0
0 0 0  Check move table for current
are applied
 Check move table for current
0 0 0 0 0 0 state = 000000081
0 0 0 state =000000000
 Apply the rule that matches the
 Apply the rule
New board position Current board position
Current board position current board position

(000000001)𝟑
0 0 0 = (000000001)𝟏𝟎
0 2 0 0 2 0 (000010000)𝟑 = 0*𝟑𝟖 + 2*𝟑𝟕 + 0*𝟑𝟔 +0*𝟑𝟓 + 0*𝟑𝟒
+0*𝟑𝟑 +0*𝟑𝟐 +0*𝟑𝟏 + 1*𝟑𝟎 = (000004375)𝟏𝟎
0 0 0 0 0 0 0 0 0 In this way the rules
 Check move table for current are applied
state =000000001  Check move table for current
0 0 1  Apply the rule that matches the 0 0 1 0 0 1 state = 000004375
current board position  Apply the rule
Current board position New board position Current board position

3/24/2023 By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 161


Solution to Tic Tac Toe: program1 or solution1
Solution to Tic Tac Toe: program2 or Magic Square
2 7 6 Computer
 Board positions are assigned to vector elements. 9 5 1 Human
 The Sum of all rows, columns, and diagonals must be 15.
4 3 8
2 7 6
******computer gives the first move******
9 5 1 Suppose the computer choses the box with 6 and 5
4 3 8 (15-(6+5)) = 4, box with 4 is empty, so computer can
win

Algorithm
1. First the computer will check, the chance of its win,
2 7 6
• It calculates the difference between 15 and the sum of the 9 5 1
two squares occupied by the computer,
• If this difference is not positive or if it is greater than 9, then 4 3 8
the original two squares were not collinear and so can be
ignored.

2. If chances of winning for the computer is 0, it will check the


chances of winning of the opponent and it will block the chances
of winning.
*****
One of the player is a computer and one will be a human.
3/24/2023 By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 163
Solution to Tic Tac Toe: program2 or Magic Square
2 7 6 Computer
 Board positions are assigned to vector elements. 9 5 1 Human
 The Sum of all rows, columns, and diagonals must be 15.
4 3 8
2 7 6
******computer gives the first move******
9 5 1
Suppose the computer choses the box with 6 and 3
4 3 8 (15-(7+8)) = 0, no box with 0, so the computer cannot
win.
It calculates the winning chances of the opponent: (15-
Algorithm
1. First the computer will check, the chance of its win, (2+9))=4. Box 4 is empty, the opponent can win. So, the
computer blocks the box with 4
• It calculates the difference between 15 and the sum of the
two squares occupied by the computer,
• If this difference is not positive or if it is greater than 9, then
the original two squares were not collinear and so can be
ignored.
2 7 6
2. If chances of winning for the computer is 0, it will check the 9 5 1
chances of winning of the opponent and it will block the chances
of winning. 4 3 8
*****
One of the player is a computer and one will be a human.
3/24/2023 By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 164
Solution to Tic Tac Toe: program2 or Magic Square
Example: Solve the following tic tac toe puzzle using magic square

Turn 5
Turn 1 Turn 3
1. Now, the computer will check its possibility of
winning the game.
• First, calculate the difference between the 15
and the sum of two positions.
 Diff = 15 – (5+4) = 6
 6 is not empty, hence Computer
can’t win the game.
Turn 2 Turn 4 2. Now, the computer checks the possibility of
opponents winning the match. If the opponent is
winning block it.
• Diff = 15 – (8+6) = 1
• 1 is empty, hence the human can win the game.
• Hence Computer Blocks it.
Computer – go to 1
Solution to Tic Tac Toe: program2 or Magic Square

Example: Solve the following tic tac toe puzzle using magic square
(continue)

Turn 5

Turn 7
1. Now, the computer will check its possibility of
winning the game.
• Diff = 15 – (5+4) = 6
• 6 is not empty, hence Computer can’t win the
game.
Turn 6
• Diff = 15 – (1+4) = 10
• 10 is greater than 9, hence Computer can’t
win the game.
• Diff = 15 – (1+5) = 9
• 9 is empty, hence Computer can win the
Turn 7
game. Computer – go to 9
Solution to Tic Tac Toe: program3
Characteristics of Problem

To choose an appropriate method for a particular problem first we need to categorize the problem based on the following
characteristics.

1. Is the problem decomposable into small sub-problems which are easy to solve?
2. Can solution steps be ignored or undone?
3. Is the universe of the problem is predictable?
4. Is a good solution to the problem is absolute or relative?
5. Is the solution to the problem a state or a path?
6. What is the role of knowledge in solving a problem using artificial intelligence?
7. Does the task of solving a problem require human interaction?

By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 168


Characteristics of Problem
1. Is the problem decomposable into small sub- 2. Can solution steps be ignored or undone?
problems which are easy to solve? Problem fall under three classes ignorable , recoverable and
irrecoverable.

Ignorable problems : Example- In the Theorem Proving problem, a


lemma that has been proved can be ignored for the next steps.
Recoverable problems: Example-In the 8-Puzzle, Moves can be
undone and backtracked.
Irrecoverable Problems: Consider the game of chess. If a wrong
move is made, it can neither be ignored nor be recovered. The thing to
do is to make the best use of current situation and proceed. This is an
example of an irrecoverable solution steps.

A knowledge of these will help in determining the control structure.

By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 169


Characteristics of Problem
3. Is the universe of the problem predictable?

 Problems can be classified into those with certain outcome (eight puzzle and water jug problems) and those with uncertain outcome (
playing cards) .

 In certain outcome problems, planning could be done to generate a sequence of operators that guarantees to a lead to a solution. Planning
helps to avoid unwanted solution steps.

 For uncertain outcome problems, planning can at best generate a sequence of operators that has a good probability of leading to a solution.
The uncertain outcome problems do not guarantee a solution and it is often very expensive since the number of solution and it is often very
expensive since the number of solution paths to be explored increases exponentially with the number of points at which the outcome can not
be predicted. Thus one of the hardest types of problems to solve is the irrecoverable, uncertain – outcome problems ( Ex:- Playing cards).

By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 170


Characteristics of Problem
4. Is a good solution to the problem absolute or 6. What is the role of knowledge in solving a problem using

relative? artificial intelligence?


 Though one could have unlimited computing power, the size of the knowledge base
available for solving the problem does matter in arriving at a good solution. Take for
 There are two categories of problems. In one, like the water jug
example the game of playing chess, just the rules for determining legal moves and
and 8 puzzle problems, we are satisfied with the solution,
some simple control mechanism is sufficient to arrive at a solution. But additional
unmindful of the solution path taken, whereas in the other category
knowledge about good strategy and tactics could help to constrain the search and
not just any solution is acceptable.
speed up the execution of the program. The solution would then be realistic.

5. Is the solution to the problem a state or a path?

 The Water Jug Problem, the path that leads to the goal must be
reported.

 A path-solution problem can be reformulated as a state-solution


problem by describing a state as a partial path to a solution. .

By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 171


Characteristics of Problem
7. Does the task of solving a problem require human interaction?

The problems can again be categorized under two heads:

1. Solitary in which the computer will be given a problem description and will produce an answer, with no intermediate communication and with the demand for an
explanation of the reasoning process. Simple theorem proving falls under this category . given the basic rules and laws, the theorem could be proved, if one exists.

Ex:- theorem proving (give basic rules & laws to computer)

2. Conversational, in which there will be intermediate communication between a person and the computer, whether to provide additional assistance to the computer or to
provide additional informed information to the user, or both problems such as medical diagnosis fall under this category, where people will be unwilling to accept the
verdict of the program, if they can not follow its reasoning.

Ex:- Problems such as medical diagnosis.

By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 172


MODULE 3 & 4:
Knowledge Representation & Inference

3/24/2023 By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 173


Knowledge-based agent (KBA)
• Knowledge-based agents are those agents who have the capability of
 maintaining an internal state of knowledge,
 reasoning over that knowledge,
 updating their knowledge after observations
 taking actions.

• These agents can represent the world with some formal representation and act intelligently.

• Knowledge-based agents are composed of two main parts:


1. Knowledge-base (KB):
 Central component of a knowledge-based agent which stores facts about the world.
 It is a collection of sentences. (A sentence is a proposition about the world.)
 These sentences are expressed in a language which is called a knowledge representation language.

2. Inference system:
 Generates new facts so that an agent can update the KB.
 Inference means deriving new sentences from old.
 Inference system allows us to add a new sentence to the knowledge base.
 Inference system applies logical rules to the KB to deduce new information.
 An inference system works mainly in two rules which are given as: Forward and Backward chaining.
3/24/2023 By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 174
Architecture of Knowledge-based agents

 The knowledge-based agent (KBA) takes 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.

3/24/2023 By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 175


Approaches of designing KBA

 Declarative approach: You can build a KBA simply by telling it what it needs to know.

 Procedural approach: In the procedural approach, we just need to write a program that already encodes the desired behavior or
agent.

3/24/2023 By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 176


Levels of KBA

Knowledge level
• Knowledge level is the first level of knowledge-based agent, and in E For example, suppose an automated taxi agent needs to go
this level, we need to specify what the agent knows, and what the from a station A to station B, and he knows the way from A
agent goals are. to B, so this comes at the knowledge level.
X

A
Logical level At the logical level we can expect to the automated taxi
• At this level, we understand that how the knowledge is represented. M
agent to reach to the destination B.
• At the level, knowledge is encoded into logical sentences.
P

L
Implementation level
• This is the physical representation of logic and knowledge. At the At this level, an automated taxi agent actually implement his
implementation level agent perform actions as per logical and
E knowledge and logic so that he can reach to the destination.
knowledge level.

3/24/2023 By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 177


Knowledge representation
 Knowledge representation is a part of AI which describes how we can represent knowledge in artificial intelligence.

What to represent?
1. Object: Facts about objects in real world: For example: Guitars contains strings, trumpets are
brass instruments.
2. Events: Actions that occur in real world: For example: ABC played guitar in XYZ concert
yesterday.

 A KR module is responsible for representing information about the real world so that a computer can understand and can utilize this
knowledge to solve the complex real world problems such as diagnosis a medical condition or communicating with humans in natural
language.

 Knowledge representation is not only about storing data into some database, but it also enables an intelligent machine to learn from that
knowledge and experiences so that it can behave intelligently like a human.

3/24/2023 By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 178


Approaches to Knowledge representation

Approaches

Inheritable Inferential Procedural


Simple relational
knowledge knowledge knowledge

3/24/2023 By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 179


Approaches to Knowledge representation
Simple relational knowledge:

1. It is the simplest way of storing facts which uses the relational method, and each fact about a set of the object is set out systematically in columns.

2. This approach of knowledge representation is famous in database systems where the relationship between different entities is represented.

3. This approach has little opportunity for inference.

Emp_SSN Emp_Number Emp_Name

123456789 226 Steve

999999321 227 Ajeet

888997212 228 Chaitanya

777778888 229 Ajeet

3/24/2023 By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 180


Approaches to Knowledge representation
Inheritable knowledge:

1. Data is stored in hierarchical classes.

2. Inheritance property is applied: Elements inherit values from other members of a class.

3. This approach contains inheritable knowledge which shows a relation between instance

and class, and it is called instance relation.

4. Objects and values are represented in Boxed nodes.

5. Arrows are used for pointing objects to their values.

3/24/2023 By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 181


Approaches to Knowledge representation
Inferential knowledge: Procedural knowledge:

1. Inferential knowledge approach represents knowledge in the form of formal logics. 1. Uses small programs and codes which describes how to do specific things, and

2. This approach can be used to derive more facts. how to proceed.

3. It guaranteed correctness. 2. One important rule is used is If-Then rule.

4. Example: Let's suppose there are two statements: 3. Various coding languages such as LISP language and Prolog language can be

Statement 1: Marcus is a man used.


We will be
Statement 2: All men are mortal 4. We can easily represent heuristic or domain-specific knowledge using this
knowing in
Then it can represent as; detail while approach.

Statement1: man(Marcus)
learning 5. But it is not necessary that we can represent all cases in this approach.
predicate logic
Statement2: ∀x : man (x) -> mortal (x)

3/24/2023 By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 182


Properties of a good Knowledge representation system

1. Representational Accuracy: Ability to represent all kind of required knowledge that are needed in the

domain.

2. Inferential Adequacy: Ability to manipulate the representational structures such that new knowledge can

be derived/inferred from the old.

3. Inferential Efficiency: Ability to incorporate additional information into an existing knowledge base that

can be used to focus the attention of inference mechanisms in the most promising direction.

4. Acquisitional efficiency: Ability to acquire the new information.

3/24/2023 By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 183


Techniques of Knowledge representation

3/24/2023 By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 184


Techniques of Knowledge representation
Logical Representation:

1. Language with some definite rules which deal with propositions and has no ambiguity in

representation.

2. It represents a conclusion based on various conditions and lays down some important

communication rules.
Logical representation can be categorized
3. Also, it consists of precisely defined syntax and semantics which supports the sound into mainly two logics:

inference. 1. Propositional Logics


2. Predicate logics
4. Each sentence can be translated into logics using syntax and semantics.

Syntax Semantics
•It decides how we can construct legal
sentences in logic. •Semantics are the rules by which we can
•It determines which symbol we can use in interpret the sentence in the logic.
knowledge representation. •It assigns a meaning to each sentence.
•Also, how to write those symbols.

3/24/2023 By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 185


Techniques of Knowledge representation
Semantic Network Representation:
Statements:
1. Semantic networks are alternative of predicate logic for knowledge representation. 1. Jerry is a cat.

2. In Semantic networks, we can represent our knowledge in the form of graphical networks. 2. Cat is a mammal

3. This network consists of nodes representing objects and arcs which describe the relationship 3. Jerry is owned by Priya.

between those objects. 4. Jerry is white colored.

5. All Mammals are animal.

This representation consist of mainly two types of relations:

1. IS-A relation (Inheritance)


2. Kind-of-relation

3/24/2023 By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 186


Techniques of Knowledge representation
Semantic Network Representation:

Statements:
1. Tom is a cat.

2. Tom caught a bird.

3. Tom is owned by John.

4. Tom is ginger in color.

5. Cats like cream.

6. The cat sat on the mat.

7. A cat is a mammal.

8. A bird is an animal.

9. All mammals are animals.

10. Mammals have fur.

3/24/2023 By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 187


Techniques of Knowledge representation
Frame Representation:

Let's suppose we are taking an entity, Peter. Peter is an


 Knowledge is stored in a record-like structure called frame that contains a set of engineer as a profession, he is unmarried and his age is 25,
he lives in city London, and the country is England. So
properties and their values to describe a physical thing. following is the frame representation for this:

 A frame consists of a collection of slots.

 Slots have names and values which are called facets: features of frames which enable us Slots Value
to put constraints on the frames. Name Peter
 Slots can be filled by values or pointers to other frames. Profession Engineer
Age 25
Marital status Single
City London
Country England

3/24/2023 By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 188


Techniques of Knowledge representation
Frame Representation:

 A frame may consist of any number of slots, and a slot may include any number of facets and facets may have any number of values. A frame is

also known as slot-filter knowledge representation in AI.

Example: Alex, an instance of a boy, inherits default values like "Sex" from the more general parent object Boy, but the boy may also have different instance
values in the form of exceptions such as the number of legs.

Slot Value Type


ALEX _ (This Frame)
NAME Alex (key value)
ISA Boy (parent frame)
SEX Male (inheritance value) Slot Value Type

IF-NEEDED: BOY _ (This Frame)


AGE Subtract(current,BIRTHD (procedural attachment) ISA Person (parent frame)
ATE);
SEX Male (instance value)
HOME 100 Main St. (instance value)
(procedural attachment - sets
BIRTHDATE 8/4/2000 (instance value) AGE Under 12 yrs.
constraint)
FAVORITE_FOOD Spaghetti (instance value)
HOME A Place (frame)
CLIMBS Trees (instance value)
(default, inherited from Person
NUM_LEGS Default = 2
BODY_TYPE Wiry (instance value) frame)
NUM_LEGS 1 (exception)

3/24/2023 By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 189


Techniques of Knowledge representation
Frame Representation:
• A single frame is of limited utility.
• A frames system is made up of a group of interconnected frames.
• Knowledge about an object or event can be kept in the knowledge base in the frame.
• The frame is a form of technology that can be used in a wide range of applications.

Frame Description
of a Hotel Room

3/24/2023 By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 190


Techniques of Knowledge representation
Frame Representation:
• Frames are derived from semantic networks and later evolved into our modern-day classes and objects.
• Frames are organized into hierarchies or networks of frames.
• Lower level frames can inherit information from upper level frames in the network.

3/24/2023 By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 191


Techniques of Knowledge representation
Recognize-act cycle:
Production Rules:
 Agent checks for the condition and if the condition exists then

production rule fires and corresponding action is carried out.


• Here knowledge is represented as rules.
 The condition part of the rule determines which rule may be applied
• Production rules system consist of (condition, action) pairs which mean, "If condition then
to a problem.
action". It has mainly three parts:
 The action part carries out the associated problem-solving steps.
1. The set of production rules

2. Working Memory
The working memory:
3. The recognize-act-cycle.
 Contains the description of the current state of problems-solving and

Production rules: rule can write knowledge to the working memory. This knowledge
IF (at bus stop AND bus arrives) THEN action (get into the bus)
match and may fire other rules.
IF (on the bus AND paid AND empty seat) THEN action (sit down).
 If there is a new situation (state) generates, then multiple production
IF (on bus AND unpaid) THEN action (pay charges).
IF (bus arrives at destination) THEN action (get down from the bus). 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.


3/24/2023 By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 192
Propositional Logic
 A proposition is the basic building block of logic.

 It is defined as a declarative sentence that can be either True or False. A proposition's Truth Value is True (denoted as T) if it is a true
statement, and False (denoted as F) if it is a false statement. For Example,

1. The sun rises in the East and sets in the West.


2. 1 + 1 = 2
3. 'b' is a vowel.

 All of the above sentences are propositions, where the first two are Valid(True) and the third one is Invalid(False).

 Sentences that do not have a truth value or may have more than one truth value are not propositions. For Example,

1. What time is it?


2. Go out and play.
3. x + 1 = 2.

 The above sentences are not propositions as the first two do not have a truth value, and the third one may be true or false.

 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.
3/24/2023 By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 193
Propositional Logic
 To represent propositions, propositional variables are used: these variables are represented by small alphabets such as p, q, r, s .

 The area of logic which deals with propositions is called propositional calculus or propositional logic.

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

 The syntax of propositional logic defines the allowable sentences for the knowledge representation. There are two types of proposition:

1. Atomic: 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:
 2+2 is 4, it is an atomic proposition as it is a true fact.
 "The Sun is cold" is also a proposition as it is a false fact.

2. Compound: Propositions constructed using one or more propositions are called compound propositions. The propositions are
combined together using Logical Connectives or Logical Operators. Example:
 "It is raining today, and street is wet."

3/24/2023 By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 194


Propositional Logic

TRUTH TABLE based approach of representing Propositional Logic:


 The truth values of compound propositions formed by combining different propositions linked by logical connectives must be known.

 It is a table that gives the output of the propositional logic against each input component. The result is binary, either True or False for each row of inputs.

 A truth table is a table that contains the combination of all possible scenarios in a tabular format. Most Common Logical Connectives- Negation, Conjunction,
Disjunction, Exclusive OR, Implication, Biconditional or Double Implication.

3/24/2023 By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 195


Propositional Logic
TRUTH TABLE based approach of representing Propositional Logic:

Negation:

If p is a proposition, then the negation of p is denoted by ¬ p. Example, The negation of “It is raining today”, is “It is
not raining today”.

p ¬p
T F
F T
Conjunction:

For any two propositions p and q , their conjunction is denoted by p ^ q , which means “p and q”.
Example:
p q p^q
p : “Today is Friday”
T T T q : “It is raining today”,
p ^ q : “Today is Friday and it is raining today”.
T F F
F T F This proposition p ^ q is true only IF both p and q are
true.
F F F
3/24/2023 By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 196
Propositional Logic
TRUTH TABLE based approach of representing Propositional Logic:
Disjunction:

For any two propositions p and q , their disjunction is denoted by p ˅ q , which means “p or q”.

p q p˅q Example:
T T T
p : “Today is Friday”
T F T q : “It is raining today”,
F T T p ˅ q : “Today is Friday or it is raining today”.
F F F
Exclusive OR:
For any two propositions p and q , their exclusive OR is denoted by p ⊕ q , which means “either p or q but not
both”.
p q p⊕q
Example:
T T F
T F T p : “Today is Friday”
q : “It is raining today”,
F T T p ⊕ q : “Either today is Friday or it is raining today, but
F F F not both”.
3/24/2023 By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 197
Propositional Logic
TRUTH TABLE based approach of representing Propositional Logic:
Implication:
For any two propositions p and q , the statement “if p then q ” is called an implication and it is denoted by p -> q .
p q p -> q Example1:
p : “Today is Friday”
**p -> q = ¬ p ˅ q T T T q : “It is raining today”,
T F F p -> q : “If it is Friday then it is raining today”
Example2:
F T T “(1 < 2) -> (5^2 < 0)" is false because the hypothesis is true and
the conclusion is false.
F F T
Biconditional:
For any two propositions p and q , the statement “if and only if (iff)” is called a biconditional and it is denoted by
p <-> q .
p q p <->q Example1:
p : “Today is Friday”
** p <-> q T T T q : “It is raining today”,
= (p -> q ) ^ (q -> p ) p <->q : “It is raining today if and only if it is Friday today”
= (¬ p ˅ q) ^ (¬ q ˅ p)
T F F
Example2:
F T F “(1 = 2) <=> (the number of primes is finite)" is true because both
F F T “(1 = 2)" and “(the number of primes is finite)" are false.

3/24/2023 198
Propositional Logic
TRUTH TABLE based approach of representing Propositional Logic:

Example: Truth table for three propositions using the basic logic connectives:

p q p -> q
p q r ¬r p˅q (p ˅ q) -> (¬ r) T T T
T F F
F T T
T T T
F F T
T T F
T F T
T F F
F T T
F T F
F F T
F F F

2^n combinations are possible where n= number of statements

3/24/2023 By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 199


Propositional Logic
TRUTH TABLE based approach of representing Propositional Logic:

Laws of logic or useful tautologies:


1. Commutativity:
• p ∧ q= q ∧ p.
• p ∨ q = q ∨ p.
2. Associativity:
• (p ∧ q) ∧ r = p ∧ (q ∧ r).
• (p ∨ q) ∨ r= p ∨ (q ∨ r).
3. Identity element:
• p ∧ true = p.
• p ∨ true= true.
4. Distributive:
• p ∧ (q ∨ r) = (p ∧ q) ∨ (p ∧ r).
• p ∨ (q ∧ r) = (p ∨ q) ∧ (p ∨ r).
5. DE Morgan's Law:
• ¬(p ∧ q) = (¬p) ∨ (¬q).
• ¬(p ∨ q) = (¬ p) ∧ (¬q).
6. Double-negation elimination:
• ¬(¬p) = p.

3/24/2023 By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 200


Propositional Logic
TRUTH TABLE based approach of representing Propositional Logic:

Precedence of connectives:

Precedence Operators

First Precedence Parenthesis


Second Precedence Negation
Third Precedence Conjunction(AND)
Fourth Precedence Disjunction(OR)
Fifth Precedence Implication
Six Precedence Biconditional

3/24/2023 By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 201


Propositional Logic
TRUTH TABLE based approach of representing Propositional Logic:

Example:

Represent the following sentence in the form of propositional logic and find the truth table: It is not sunny this
afternoon and it is colder than yesterday.

Step 1: Assign the atomic statements to variable:


 p = It is sunny this afternoon
 q = It is colder than yesterday
Step 2: Form the propositional logic
It is not sunny this afternoon and it is colder than yesterday.

¬p ^ q
It is not sunny this afternoon and it is colder than yesterday: ¬ p ^ q
Step 3: Truth table
p q ¬p ¬p^q
T T F F
T F F F
F T T T
3/24/2023
F F T F 202
Propositional Logic
TRUTH TABLE based approach of representing Propositional Logic:

Examples:
Represent the following sentence in the form of propositional logic and find the truth table:
1. It is not sunny this afternoon and it is colder than yesterday.
2. We will go swimming only if it is sunny.
3. If we do not go swimming then we will take a canoe trip.
4. If we take a canoe trip, then we will be home by sunset.

Step 1: Assign the atomic statements to variable:


 p = It is sunny this afternoon
 q = It is colder than yesterday
 r = We will go swimming
 s= We will take a canoe trip
 t= We will be home by sunset
Step 2: Form the propositional logic
Statement 1:
It is not sunny this afternoon and it is colder than yesterday.

¬p ^ q

1. It is not sunny this afternoon and it is colder than yesterday: ¬ p ^ q


3/24/2023 By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 203
Propositional Logic
TRUTH TABLE based approach of representing Propositional Logic:
Examples:

Represent the following sentence in the form of propositional logic and find the truth table:
1. It is not sunny this afternoon and it is colder than yesterday.
2. We will go swimming only if it is sunny.
3. If we do not go swimming then we will take a canoe trip.
4. If we take a canoe trip, then we will be home by sunset.

Step 1: Assign the atomic statements to variable:


 p = It is sunny this afternoon
 q = It is colder than yesterday
 r = We will go swimming
 s= We will take a canoe trip
 t= We will be home by sunset

Step 2: Form the propositional logic


1. It is not sunny this afternoon and it is colder than yesterday: ¬ p ^ q
2. We will go swimming only if it is sunny: r ->p
3. If we do not go swimming then we will take a canoe trip: ¬r -> s
4. If we take a canoe trip, then we will be home by sunset: s -> t

Step 3: Truth table for these propositions will contain: 2 ^5 entries = 32 entries
3/24/2023 By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 204
Propositional Logic
TRUTH TABLE based approach of representing Propositional Logic:
Examples:

Find if the given propositional logic is tautology or not:


(p → q) → [(p → q) → q]

p q p→q (p → q) → q (p → q) → [(p → q) → q]

T T T T T

T F F T T

F T T T T

F F T F F

Since there is a False entry in the truth table, it implies it is not a Tautology.

******Propositional logic is said to be a tautology if it is always true regardless of the true/false of the atomic
formulas.
3/24/2023 By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 205
Propositional Logic
TRUTH TABLE based approach of representing Propositional Logic:
Converse and Contrapositive
1. The converse of the implication p -> q is q -> p.

2. The contrapositive of the implication p -> q is ¬q -> ¬p.

For example for the proposition "If it rains, then I get wet",
Converse: If I get wet, then it rains.
Contrapositive: If I don't get wet, then it does not rain.

3/24/2023 By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 206


Propositional Logic
TRUTH TABLE based approach of representing Propositional Logic:

Valid Arguments

An argument (form) is a sequence of statements (forms).All statements (forms) in an argument (form) except for the final one, are called
premises (or assumptions, or hypothesis). The final statement (form) is called the conclusion.

Example

Premises ⇒ Conclusion p-> q and q -> r are the premises


p v q -> r is the conclusion

 An argument form in propositional logic is a sequence of compound propositions involving propositional variables.

 An argument is valid if the truth of all its premises implies that the conclusion is true.

 An argument form is valid if no matter which particular propositions are substituted for the propositional variables in its premises, the conclusion is
true if the premises are all true.

 If the premises are 𝑝1 , 𝑝2 , …, 𝑝𝑛 and the conclusion is q then (𝒑𝟏 ∧ 𝒑𝟐 ∧ … ∧ 𝒑𝒏 ) → q is a tautology.

3/24/2023 By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 207


Propositional Logic
TRUTH TABLE based approach of representing Propositional Logic:

Valid Arguments

To test whether or not an argument is valid, we do the following:

(i ) Identify the premises and the conclusion


(ii ) Construct a truth table showing the truth values of the premises and the conclusion
(iii ) Look for all the rows where the premises are all true - we call such rows critical rows. If the conclusion is false in a critical row, then the
argument is invalid. Otherwise, the argument is valid (since the conclusion is always true when the premises are true).

3/24/2023 By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 208


Propositional Logic
TRUTH TABLE based approach of representing Propositional Logic:

Valid Arguments

Determine whether the following arguments are valid.

Let
p :=“I sleep a lot”
q :=“I don’t do any homework”
r :=“I will not do well in this class”

Then this translates to:


p-> q : If I sleep a lot, then I don’t do any
homework.
q -> r : If I don’t do any homework, then I will not
do well in the class.

p v q -> r : Therefore, if I sleep a lot or don’t do any


homework, I will not do well in the class”.

3/24/2023 By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 209


Propositional Logic
TRUTH TABLE based approach of representing Propositional Logic:

Valid Arguments
Determine the validity of the following argument: “Robbery was the motive for the crime only if the victim had money
in his pockets. But robbery or vengeance was the motive for the crime. Therefore, vengeance must have been the motive for
the crime.”

Let p = “robbery was the motive for the crime”, q = the victim had money in his pockets, and r = “vengeance was the motive for
the crime”. Then the argument translates as follows:

p-> q

‫؞‬
pvr
r

The argument is not valid as suggested by the truth


table.

3/24/2023 By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 210


Propositional Logic
TRUTH TABLE based approach of representing Propositional Logic:
Examples: Convert the following to propositional logic, and use truth tables to determine whether or not the Conjecture is a logical consequence of
the Axioms.

If Mary loves Pat then Mary loves Quincy. If it is Monday then Mary loves Pat or Quincy. Prove that If it is Monday then Mary loves Quincy.

‫؞‬
1. If Mary loves Pat, then Mary loves Quincy. p ->q
2. If it is Monday, Mary loves Pat or Quincy. m -> (p ˅ q)
3. Therefore, if it is Monday, then Mary loves Quincy. m ->q

The Conjecture is a logical consequence of the Axioms as indicated by row 1, 3, 5, 7, 8. So, the argument is true.

3/24/2023 By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 211


Propositional Logic
Drawback of TRUTH TABLE based approach of representing Propositional Logic:

Let us take the argument : ( A ∨ C ) ∧ (B ∨ ¬C ) => ( A ∨ B )


Suppose KB = ( A ∨ C ) ∧ (B ∨ ¬C ) and α = ( A ∨ B )
1. Generate table for all possible interpretations
2. Check whether α evaluates to true, whenever KB evaluates to true.

So, α is true whenever KB is true, but to prove that 8 possible interpretations needs to be checked.

 The computational complexity of the truth table approach is exponential to the number of the proposition
symbols : 2 ^n
 2^n interpretations needs to be checked though the KB is true only for few rows
3/24/2023 By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 212
Propositional Logic
Solution to the limitation of TRUTH TABLE based approach of representing Propositional Logic:

 Check only entries for which KB is True.

 This is the idea behind the inference rules approach

3/24/2023 By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 213


Propositional Logic
Inference rules for natural deduction:
1. Testing whether a proposition is a tautology by testing every possible truth assignment is expensive—there are exponentially many.
We need a deductive system, which will allow us to construct proofs of tautologies in a step-by-step fashion.

2. The system we will use is known as natural deduction. The system consists of a set of rules of inference for deriving
consequences from premises.

3. An inference rule is a pattern establishing that if a set of antecedent statements (hypothesis) are true, then we can validly deduce that
a certain related consequent statement (conclusion) is true.

3/24/2023 By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 214


Propositional Logic
Inference rules for natural deduction:

Inference rules are


used to create new
sentences that logically
follows a given set of
premises

*** All these rules are


sound. A rule is sound if its
conclusion is true
whenever its premises are
true

***The final disjunction


in the resolution rule, q ∨ r
, is called the resolvent.
(very important rule)

3/24/2023 By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 215


Propositional Logic
Inference rules for natural deduction :
Few more rules:

Constructive Dilemma:

Example: Let p be “I will study discrete math.” Let q be “I will study computer science.” Let r be “I will study
protein structures.” Let s be “I will study biochemistry.”

“If I will study discrete math, then I will study computer science.” “If I will study protein structures, then I
will study biochemistry.”
“I will study discrete math or I will study protein structures.”

“Therefore, I will study computer science or biochemistry.

3/24/2023 By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 216


Propositional Logic
Inference rules for natural deduction :
Few more rules:

Destructive Dilemma:

(p -> q) ^ (r -> s)
(¬q ˅ ¬s )
∴ ¬ p ˅ ¬r

Example: Let p be “I will study discrete math.” Let q be “I will study computer science.” Let r be “I will study
protein structures.” Let s be “I will study biochemistry.”

“If I will study discrete math, then I will study computer science.”
“If I will study protein structures, then I will study biochemistry.”
“I will not study computer science or I will not study biochemistry.”
“Therefore, I will not study discrete math or I will not study protein structures.”

3/24/2023 By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 217


Propositional Logic
Inference rules for natural deduction :
Few more rules:

Absorption:

(p -> q)
∴ p -> (p ^ q)

q is absorbed by p in the conclusion!

Example:

Let p be “I will study discrete math.”


Let q be “I will study computer science.”

“If I will study discrete math, then I will study computer science.”
“Therefore, if I will study discrete math, then I will study discrete mathematics and I will study computer science.”

3/24/2023 By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 218


Propositional Logic
Inference rules for natural deduction:
Modus Ponens

Modus Tollens

3/24/2023 By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 219


Propositional Logic
Inference rules for natural deduction :
Hypothetical Syllogism

Disjunctive Syllogism

3/24/2023 By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 220


Propositional Logic
Inference rules for natural deduction :

Addition

Simplification

“I will study discrete math and English literature” p ∧q Simplification


“Therefore, I will study discrete math ∴p (p∧q) →p

3/24/2023 By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 221


Propositional Logic
Inference rules for natural deduction :

Resolution

3/24/2023 By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 222


Propositional Logic
Inference rules for natural deduction :
Prove the conclusion:

1. If it snows, Paul will miss class.


2. Paul did not miss class.
3. Therefore, it did not snow.

Step1: First, we will translate the argument into symbolic form

1. If it snows, Paul will miss class. p ->q


2. Paul did not miss class. ¬q
3. Therefore, it did not snow. ¬p

Step2:Determine if the symbolic rules matches with any of the inference rules.

3/24/2023 By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 223


Propositional Logic
Inference rules for natural deduction :
Prove the conclusion:

1. If it snows, Paul will miss class.


2. It did not snow.
3. Therefore, Paul did not miss class.

Step1: First, we will translate the argument into symbolic form

1. If it snows, Paul will miss class. p ->q


2. It did not snow. ¬p
3. Therefore, Paul did not miss class. ¬ q

Step2:Determine if the symbolic rules matches with any of the inference rules.

Because the argument does not match one of our known rules, we determine that the conclusion is invalid.

3/24/2023 By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 224


Propositional Logic
Inference rules for logic:
If Aakash goes to the temple, then Aakash is a religious person. Aakash is not a religious person. Prove that Aakash
doesn’t go to temple.

Step1: First, we will translate the argument into symbolic form

1. If Aakash goes to the temple, then Aakash is a religious person. p ->q


2. Aakash is not a religious person. ¬q
3. Therefore, Aakash doesn’t go to temple ¬p

Step2:Determine if the symbolic rules matches with any of the inference rules.

The argument matches with Modus tollens, we determine that the conclusion is valid.

3/24/2023 By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 225


Propositional Logic
Inference rules for natural deduction :
If Sheero is intelligent, then Sheero is smart. Sheero is intelligent. Prove that Sheero is smart.

Step1: First, we will translate the argument into symbolic form

1. If Sheero is intelligent, then Sheero is smart. p ->q


2. Sheero is intelligent. p
3. Therefore, Sheero is smart q

Step2:Determine if the symbolic rules matches with any of the inference rules.

The argument matches with Modus ponens, we determine that the conclusion is valid.

3/24/2023 By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 226


Propositional Logic
Inference rules for natural deduction :
Examples where the rules cannot be applied directly to prove the conclusion.
“It is not sunny this afternoon and it is colder than yesterday”, “We will go swimming only if it is sunny”, “If we do not go swimming,
then we will take a canoe trip”, and “If we take a canoe trip, then we will be home by sunset” lead to the conclusion “We will be home by
sunset”.
Let p be the proposition “It is sunny this afternoon,”
q be the proposition “It is colder than yesterday,”
r be the proposition “We will go swimming,”
s be the proposition “We will take a canoe trip,” and
t be the proposition “We will be home by sunset.”

Then the premises become ¬p ∧ q, r → p, ¬r →s, and s →t. The conclusion is simply t.

3/24/2023 By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 227


Propositional Logic
Inference rules for natural deduction :
Examples where the rules cannot be applied directly to prove the conclusion.

3/24/2023 By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 228


Propositional Logic
Inference rules for natural deduction :
*****Proof by RESOLUTION
“It is not sunny this afternoon and it is colder than yesterday”, “We will go swimming only if it is sunny”, “If we do not go swimming,
then we will take a canoe trip”, and “If we take a canoe trip, then we will be home by sunset” lead to the conclusion “We will be home by
sunset”.

Let p be the proposition “It is sunny this afternoon,”


q be the proposition “It is colder than yesterday,”
r be the proposition “We will go swimming,”
s be the proposition “We will take a canoe trip,” and
t be the proposition “We will be home by sunset.”

Then the premises become ¬p ∧ q, r → p, ¬r →s, and s →t. The conclusion is simply t.

3/24/2023 By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 229


Propositional Logic
Inference rules for natural deduction :
*****Proof by RESOLUTION

Given the following hypotheses:


If it rains, Joe brings his umbrella (r -> u)
If Joe has an umbrella, he doesn't get wet (u -> ¬ w)
If it doesn't rain, Joe doesn't get wet (¬ r -> ¬ w)

Prove that Joes doesn't get wet (¬ w)

(r -> u) = ¬ r ˅ u
1. ¬ r ˅ u Premise1 (u -> ¬ w) =¬ u ˅ ¬ w
2. ¬ u ˅ ¬ w Premise2 (¬ r -> ¬ w) = r ˅ ¬ w
3. r ˅ ¬ w Premise3
4. ¬ r ˅ ¬ w L1, L2, resolution
5. ¬ w ˅ ¬ w L3, L4, resolution
6. ¬ w L6, idempotence

So the conclusion is proved.

3/24/2023 By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 230


Propositional Logic
Inference rules for natural deduction :
***Proof By CONTRADICTION USING RESOLUTION

We can combine resolution with proof by contradiction (where we assert the negation of what
we wish to prove, and from that premise derive FALSE) to direct our search towards smaller
and smaller clauses, with the goal of producing FALSE.

3/24/2023 By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 231


Propositional Logic
Inference rules for natural deduction :
***Proof By CONTRADICTION USING RESOLUTION

Given the following hypotheses:


If it rains, Joe brings his umbrella (r -> u)
If Joe has an umbrella, he doesn't get wet (u -> ¬ w)
If it doesn't rain, Joe doesn't get wet (¬ r -> ¬ w)

Prove that Joes doesn't get wet (¬ w)

1. ¬ r ˅ u Premise1
2. ¬ u ˅ ¬ w Premise2
3. r ˅ ¬ w Premise3
4. w Negation of conclusion
5. ¬ r ˅ ¬ w L1, L2, resolution
6. ¬ w ˅ ¬ w L3, L5, resolution
7. ¬ w L6, idempotence
8. FALSE or null clause L4, L7, resolution

We got false, so the conclusion is valid.

3/24/2023 By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 232


Propositional Logic
Inference rules for natural deduction :
***Proof By CONTRADICTION USING RESOLUTION
Either Heather attended the meeting or Heather was not invited. If the boss wanted Heather at the meeting, then she was invited. Heather did not
attend the meeting. If the boss did not want Heather there, and the boss did not invite her there, then she is going to be fired. Prove Heather is
going to be fired.

1. A ˅ ¬ I Premise1
2. ¬ W ˅ I Premise2
3. ¬ A Premise3 (¬W ∧ ¬ I) -> F
4. W ˅ I ˅ F Premise4 = ¬ (¬W ∧ ¬ I) ˅ F
5. ¬ F Negation of conclusion =W˅I˅F
6. W ˅ I L4, L5, resolution
7. I L2, L6, resolution, Idempotence
8. A L1, L7, resolution
9. FALSE or null clause L3, L8, resolution

We got false, so the conclusion is valid.

3/24/2023 By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 233


Propositional Logic
Inference rules for natural deduction :
***Proof By CONTRADICTION USING RESOLUTION
Either taxes are increased or if expenditures rise then the debt ceiling is raised. If taxes are increased, then the cost of collecting taxes rises. If a
rise in expenditures implies that the government borrows more money, then if the debt ceiling is raised, then interest rates increase. If taxes are
not increased and the cost of collecting taxes does not increase then if the debt ceiling is raised, then the government borrows more money. The
cost of collecting taxes does not increase. Either interest rates do not increase or the government does not borrow more money.

Prove either the debt ceiling isn't raised or expenditures don't rise.
1. T ˅ ¬ E ˅ D Premise1 T ˅ (E->D) =T ˅ ¬ E ˅ D
2. ¬ T ˅ C Premise2 T->C = ¬ T ˅ C
3. (E ∧ ¬ G) ˅ ¬ D ˅ I Premise3 (E->G)->(D->I)= ¬(¬ E ˅ G) ˅ (¬ D ˅ I)
4. T ˅ C ˅ ¬ D ˅ G Premise 4 = (E ∧ ¬ G) ˅ ¬ D ˅ I
5. ¬ C Premise5 (¬ T ∧ ¬ C) -> (D -> G) = ¬ (¬ T ∧ ¬ C) ˅ (¬ D ˅ G )
6. ¬ I ˅ ¬ G Premise6 =T˅C˅¬D˅G
7. D ∧ E Negation of conclusion
8. (E ∧ ¬ G) ˅ I take simplication of L7, and resolve with L3
9. C ˅ ¬ D ˅ G L2, L4, resolution
10.C ˅ G take simplication of L7, and resolve with L9
11.G L5, L10, resolution
12.¬ I L6, L11, resolution
13.E ∧ ¬ G L8, L12, resolution
14.¬ G L13, tautology
15.FALSE or null clause L11, L14, contradiction

We got false, so the conclusion is valid.


3/24/2023 By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 234
Propositional Logic
Inference rules for natural deduction :
***RESOLUTION ALGORITHM
(b) Bring each modified clause into the following form and then drop AND
Given: operators connected between each square bracket. The clauses thus obtained
A set of clauses, called axioms and a goal. . are in conjunctive normal from (CNF). It may be noted that pij may be in
Aim: negated or non-negated form.
To test whether the goal is derivable from the axioms.

Begin:

1. Construct a set S of axioms plus the negated goal.

2. Represent each element of S into conjunctive normal 3. Repeat:


form (CNF) by the following steps: (a) Select any two clauses from S, such that one clause contains a negated literal
and the other clause contains its corresponding positive (non-negated) literal.
(a) Replace ‘if-then’ operator by NEGATION and OR
operation by: p -> q = ¬ p ˅ q (b) Resolve these two clauses and call the resulting clause the resolvent. Remove
the parent clauses from S.

Until a null clause is obtained or no further progress can be made.

4. If a null clause is obtained, then report: “goal is proved”

3/24/2023 By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 235


Propositional Logic
Drawback of propositional logic:
• If you want to represent complicated sentences or natural language statements, PL is not sufficient.

• Propositional logic has very limited expressive power (unlike natural language)

• Cannot represent relations like ALL, some, or none with propositional logic. Example:
 All the girls are intelligent.
 Some apples are sweet.

• Statements cannot describe statements in terms of their properties or logical relationships.

3/24/2023 By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 236


First Order Logic or Predicate Logic

Propositional logic assumes world contains facts that can either hold or do not hold, whereas first-order logic (like natural
language) assumes the world contains universe consists of multiple objects with certain relations among them that can either
hold or do not hold:

 Objects: people, houses, numbers, theories, Ronald McDonald, colors, baseball games, wars, centuries . . .

 Relations: red, round, bogus, prime, multistoried . . .,brother of, bigger than, inside, part of, has color, occurred after,

owns, comes between, . . .

 Functions: father of, best friend, third inning of, one more than, end of

3/24/2023 By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 237


First Order Logic or Predicate Logic
 First-order logic—also known as predicate logic, quantificational logic, and first-order predicate calculus—is a

collection of formal systems used in mathematics, philosophy, linguistics, and computer science.

 First-order logic statements can be divided into two parts:

 Subject: Subject is the main part of the statement.

 Predicate: A predicate can be defined as a relation, which binds two atoms together in a statement.

 Consider the statement: "x is an integer.", it consists of two parts, the first part x is the subject of the statement and

second part "is an integer," is known as a predicate.

3/24/2023 By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 238


First Order Logic or Predicate Logic
 First-order logic also has two main parts as a natural language: Syntax and Semantics

 In first-order logic, the syntax of FOL determines which set of symbols represents a logical expression.
Symbols are the core syntactic constituents of first-order logic.

The basic elements of FOL syntax are as follows


Constant 1, 2, A, John, Mumbai,
cat,....
Variables x, y, z, a, b,....
Predicates Brother, Father, >,....
Function sqrt, LeftLegOf, ....
Connectives ∧, ∨, ¬, ⇒, ⇔
Equality ==
Quantifier ∀, ∃
3/24/2023 By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 239
First Order Logic or Predicate Logic

Atomic sentences in FOL:


•Basic sentences of first-order logic. These sentences are formed from a predicate symbol followed by a parenthesis with a
sequence of terms. We can represent atomic sentences as Predicate (term1, term2, ......, term n).

Example:
Ravi and Ajay are brothers: Brothers(Ravi, Ajay).
Chinky is a cat: cat (Chinky).

Complex sentences in FOL:


Complex sentences are made by combining atomic sentences using connectives.

S, S1 ∧ S2, S1 ∨ S2, S1 ⇒ S2, S1 ⇔ S2

3/24/2023 By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 240


First Order Logic or Predicate Logic
To strengthen your understanding of Predicate Logic, let us Consider the sentences:

1. Aristotle is a man
2. Socrates is a man
3. Bob is a man

 These sentences express different propositions but they have the same syntactic form. Each of the propositions has a
subject (Aristotle, Socrates, and Bob) and a verb phrase (is a man). In Propositional logic we can use P, Q, R to represent
the three statements. Propositional logic can’t draw any conclusions about similarities between P, Q and R. So, it is
better to represent these facts as– MAN(a), MAN(s) and MAN(b), where a, s, and b means Aristotle, Socrates, and Bob.

 a, s, and b are called individual constants (or simply individuals). Each individual constant refers to the entity in the world
which bears that name.

 Now consider the sentences below, in which the subject is the same but the verb phrase changes.
4. Aristotle is a man
5. Aristotle is pompous
6. Aristotle jogs

 Verb phrases like is a man, is pompous, and jogs, express predicate constants (simply predicates), which are written using
uppercase letters like M, P, J; alternatively, MAN, POMPOUS, JOG.

3/24/2023 By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 241


First Order Logic or Predicate Logic

 Predicate constants are not propositions, much like verbs are not sentences. Like a verb, a predicate constant has to combine
with one or more elements to form a proposition.

 Predicate logic for the statements mentioned in the previous slide:

1. Aristotle is a man : MAN(a)


2. Socrates is a man : MAN(s)
3. Bob is a man : MAN(b)
4. Aristotle is pompous : POMPOUS(a)
5. Aristotle jogs : JOGS(a)

3/24/2023 By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 242


First Order Logic or Predicate Logic

Quantifiers in FOL:

These are the symbols that permit to determine or identify the range and scope of the variable in the logical expression.
There are two types of quantifier:

a. Universal Quantifier, (for all, everyone, everything)


b. Existential quantifier, (for some, at least one).

3/24/2023 By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 243


First Order Logic or Predicate Logic
Universal Quantifier in FOL:
 The Universal quantifier is represented by a symbol ∀, which resembles an inverted A.
 If p(x) is a proposition over the universe U. Then it is denoted as ∀x,p(x) and read as "For every x∈U,p(x) is true."
 If x is a variable, then ∀x is read as:
• For all x
• For each x
• For every x.

Example: All man drink coffee.

****In universal quantifier we use implication "→".

∀x man(x) → drink (x, coffee).

3/24/2023 By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 244


First Order Logic or Predicate Logic
Existential Quantifier in FOL:
 It is denoted by the logical operator ∃, which resembles as inverted E.
 Existential quantifiers are the type of quantifiers, which express that the statement within its scope is true for at least one
instance of something.

 If x is a variable, then existential quantifier will be ∃x or ∃(x). And it will be read as:
• There exists a 'x.'
• For some 'x.'
• For at least one 'x.'
Example: Some boys are intelligent.

****In Existential quantifier we always use AND or


Conjunction symbol (∧).

∃x: boys(x) ∧ intelligent(x)


3/24/2023 By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 245
First Order Logic or Predicate Logic
Properties of Quantifier:
 In universal quantifier, ∀x∀y is similar to ∀y∀x.

 In Existential quantifier, ∃x∃y is similar to ∃y∃x.

 ∃x∀y is not similar to ∀y∃x.

 Quantifier with negation: ~ ∃x [P(x)] = ∀x[~ P(x)] and ~ ∀x[P(x)]= ∃x[~ P(x)].

3/24/2023 By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 246


First Order Logic or Predicate Logic
Free and bound variable:
Consider a Predicate formula having a part in form of (∃ x) P(x) of (x)P(x), then such part is called x-bound part of the
formula. Any occurrence of x in x-bound part is termed as bound occurrence and any occurrence of x which is not x-bound
is termed as free occurrence. See the examples below –

(∃ x) (P(x) ∧ Q(x))
X occurs within the scope of the
quantifier. X is a bound variable here

(∃ x) P(x) ∧ Q(x)
X is a bound X is a free
variable here as variable here as
it occurs within it does not
the scope of the occurs within
quantifier the scope of the
quantifier

3/24/2023 By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 247


First Order Logic or Predicate Logic
Well Formed Formulas:
Well-formed formula in FOPC is defined recursively as follows:

a. Atomic formula P(t1, …, tn ) is a well-formed formula, where P is a predicate symbol and t1,...,tn are the terms. It is

also called atom.

b. If α and β are well-formed formulae, then ~ (α) , (α V β ), (α Λ β), (α → β) and (α ↔ β ) are well-formed formulae.

c. If α is a well-formed formula and x is a free variable in α, then (∀x)α and (∃x)α are well-formed formulae.

d. Well-formed formulae are generated by a finite number of applications of above rules.

Sentences and formulae


A sentence is a formula with no free variables.
****NOTE*****
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.
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.

3/24/2023 By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 248


First Order Logic or Predicate Logic
Example:
Translate the text "Every man is mortal. John is a man. Therefore, John is mortal" into a First Order
Predicate Calculus (FOPC) formula

Solution:
Let MAN(x), MORTAL(x) represent that x is a man and x is mortal respectively.

Every man is mortal : (∀x) (MAN(x) → MORTAL(x))


John is a man : MAN(john)
John is mortal : MORTAL(john)

The whole text can be represented by the following formula:


(∀x) ((MAN(x) → MORTAL(x)) Λ MAN(john)) → MORTAL(john)

3/24/2023 By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 249


First Order Logic or Predicate Logic
Nested Quantifier:
Example : Every sophomore owns a computer or has a friend in the junior class who owns a computer.

Domains S and J are the sophomores and the juniors. Predicates C(u) and F(v,w) mean that u owns a computer and that w is
a friend of v.

Nested

3/24/2023 By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 250


First Order Logic or Predicate Logic
EXAMPLES:
1. All birds fly.
In this question the predicate is "fly(bird)."
And since there are all birds who fly so it will be represented as follows.
∀x bird(x) →fly(x).
2. Every child respects his parent.
In this question, the predicate is "respect(x, y)," where x=child, and y= parent.
Since there is every child so will use ∀, and it will be represented as follows:
∀x child(x) → respects (x, parent).
3. Some boys play cricket.
In this question, the predicate is "play(x, y)," where x= boys, and y= game. Since there are some boys so we will use ∃, and it will be represented as:
∃x boys(x) ∧ play(x, cricket).
4. Not all students like both Mathematics and Science.
In this question, the predicate is "like(x, y)," where x= student, and y= subject.
Since there are not all students, so we will use ∀ with negation, so following representation for this:
¬∀ (x) [ student(x) →( like(x, Mathematics) ∧ like(x, Science))].
5. Only one student failed in Mathematics.
In this question, the predicate is "failed(x, y)," where x= student, and y= subject.
Since there is only one student who failed in Mathematics, so we will use following representation for this:
∃(x) [ student(x) ∧ failed (x, Mathematics) ∧∀ (y) [¬(x==y) ∧ student(y) → ¬failed (y, Mathematics)].
3/24/2023 By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 251
EXAMPLES:
First Order Logic or Predicate Logic
6. All purple mushrooms are poisonous.
∀X ((mushroom(X) Λ purple(X)) ⇒ poisonous(X))
7. No purple mushroom is poisonous.
∀X (mushroom(X) Λ purple(X) ⇒ ¬ poisonous(X)).
8. All mushrooms are either purple or poisonous.
∀X (mushroom(X) ⇒( purple(X) ν poisonous(X)))
9. All mushrooms are either purple or poisonous but not both.
∀X (mushroom(X) ⇒( purple(X) Λ ¬ poisonous(X)) ν (¬purple(X) Λ poisonous(X)))
10. All purple mushrooms except one are poisonous.
ƎX[ (purple(X) Λ mushroom(X) Λ ¬ poisonous(X)) Λ (∀Y(purple(Y) Λ mushroom(Y) Λ ¬equal(X,Y)) ⇒poisonous(Y))]
11. Everyone loves someone.
∀x(person(x) → ∃y(person(y) ∧ love (x, y))) (For every person x, there is some person y whom x loves.)
Or
∃y(person(y) ∧ ∀x(person(x) → love (x, y))) (There is some person y whom every person x loves.)

3/24/2023 By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 252


EXAMPLES:
First Order Logic or Predicate Logic
12. Someone walks and someone talks.
(∃x (person(x) ∧ walk (x)) ∧ ∃x(person(x) ∧ talk (x)))
Or
(∃x (person(x) ∧ walk (x)) ∧ ∃y (person(y) ∧ talk (y)))
Or
∃x∃y (person(x) ∧ walk (x) ∧ person(y) ∧ talk (y))
13. Someone walks and talks.
∃x(person(x) ∧ walk (x) ∧ talk (x))

14. Anyone who loves everyone loves himself.


∀x(∀y love (x,y)→ (love(x,x))
Wrong ans :∀x∀y (love (x,y)→ love(x,x)) (Anyone who loves anyone loves himself)
Wrong ans: ∃x∀y(love (x,y)→ love(x,x))
15. Every student except George smiles.
∀x ((student(x) ∧ x ≠ George) → smile( x))

3/24/2023 By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 253


First Order Logic or Predicate Logic
EXAMPLES:
16.

3/24/2023 By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 254


EXAMPLES: First Order Logic or Predicate Logic

3/24/2023 By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 255


EXAMPLES: First Order Logic or Predicate Logic

3/24/2023 By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 256


First Order Logic or Predicate Logic
INFERENCES IN FOL
Inference in First-Order Logic is used to deduce new facts or sentences from existing sentences.

 Inference rules for propositional logic can also be applied here. Other than these rules few more rules are
augmented in PL to be used with quantifiers.

3/24/2023 By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 257


First Order Logic or Predicate Logic
INFERENCES IN FOL

3/24/2023 By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 258


First Order Logic or Predicate Logic
INFERENCE rules IN FOL

3/24/2023 By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 259


First Order Logic or Predicate Logic
INFERENCE IN FOL
Example: Using inference rules to the prove the classical Lewis Carroll problem:

Premise1: “All lions are fierce.”


Premise2: “Some lions do not drink coffee.”
Conclusion: “Some fierce creatures do not drink coffee.”

Let’s let L(x) be “x is a lion,” F(x) be “x is fierce,” and C(x) be “x drinks coffee.”

3/24/2023 By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 260


First Order Logic or Predicate Logic
INFERENCE IN FOL

3/24/2023 By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 261


First Order Logic or Predicate Logic
Unification in FOL
 It is an algorithm for determining the substitutions needed to make two predicate logic expressions match. .
 It takes two literals as input and makes them identical using substitution.
 The act of unifying is called unification. The instantiation that unifies the formulas in question is called a unifier.
 Let Ψ1 and Ψ2 be two atomic sentences and 𝜎 be a unifier such that, Ψ1𝜎 = Ψ2𝜎, then it can be expressed as UNIFY(Ψ1, Ψ2).
 It returns fail if the expressions do not match with each other.
 The substitution variables are called Most General Unifier or MGU.

Example: Find the MGU of UNIFY(prime (11), prime(y))


****Notation [a/x] means replacing all occurrences of
Here, Ψ1 = prime(11) , and Ψ2 = prime(y) x with a in the formula
S0 => {prime(11) , prime(y)} substitution [5/x] in p(x) ∨ Q(x,y) results
in p(5) ∨ Q(5,y)
SUBST θ= {11/y}
S1 => {prime(11) , prime(11)} , Successfully unified.
Unifier: {11/y}.
3/24/2023 By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 262
First Order Logic or Predicate Logic
Conditions for Unification:
Following are some basic conditions for unification:

 Predicate symbol must be same, atoms or expression with different predicate symbol can never be unified.
 Number of Arguments in both expressions must be identical.
 A variable cannot be unified with a term containing that variable. The test for it is called the occurs check.
– Example: cannot substitute x for x + y in p(x + y)

3/24/2023 By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 263


First Order Logic or Predicate Logic
Unification:
Examples: Find the MGU of { p (b, X, f(g(Z))) and p (Z, f(Y), f(Y)) }

Here, Ψ1 = p(b, X, f(g(Z))) , and Ψ2 = p(Z, f(Y), f(Y))

 Predicates are same and number of arguments are also same. So, go for substitution
S0 => { p(b, X, f(g(Z))), p(Z, f(Y), f(Y))}

SUBST θ={b/Z}
S1 => { p(b, X, f(g(b))), p(b, f(Y), f(Y))}

SUBST θ={f(Y) /X}


S2 => { p(b, f(Y), f(g(b))), p(b, f(Y), f(Y))}

SUBST θ= {g(b) /Y}


S3 => { p(b, f(g(b)), f(g(b)), p(b, f(g(b)), f(g(b))} Unified Successfully.

3/24/2023 By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 264


First Order Logic or Predicate Logic
Unification:
Examples: Find the MGU of {p (X, X), and p (Z, f(Z))}

Here, Ψ1 = p (X, X), and Ψ2 = p (Z, f(Z))

 Predicates are same and number of arguments are also same. So, go for substitution
S0 => {p (X, X), p (Z, f(Z))}

SUBST θ={Z/X}
S1 => {p (Z, Z), p (Z, f(Z))}

SUBST θ={f(Z) /Z} : Unification failed. (condition 3 of unification)

3/24/2023 By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 265


First Order Logic or Predicate Logic
Unification:
Examples: UNIFY(knows(Richard, x), knows(Richard, John))

Here, Ψ1 = knows(Richard, x), and Ψ2 = knows(Richard, John)

S0 => { knows(Richard, x); knows(Richard, John)}

SUBST θ= {John/x}
S1 => { knows(Richard, John); knows(Richard, John)}, Successfully Unified.

Unifier: {John/x}..

3/24/2023 By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 266


First Order Logic or Predicate Logic
Conversion of FOL to CNF:
ALGORITHM
1.Eliminate biconditionals and implications:
• Eliminate ⇔, replacing α ⇔ β with (α ⇒ β) ∧ (β ⇒ α).
• Eliminate ⇒, replacing α ⇒ β with ¬α ∨ β.
2. Move ¬ inwards:
• ¬(∀ x p) ≡ ∃ x ¬p,
• ¬(∃ x p) ≡ ∀ x ¬p,
• ¬(α ∨ β) ≡ ¬α ∧ ¬β,
• ¬(α ∧ β) ≡ ¬α ∨ ¬β,
• ¬¬α ≡ α.
3. Standardize variables apart by renaming them: each quantifier should use a different variable.
4. Skolemize: each existential variable is replaced by a Skolem constant or Skolem function of the enclosing universally quantified variables.

• For instance, ∃x Rich(x) becomes Rich(G1) where G1 is a new Skolem constant.

• “Everyone has a heart” : ∀ x(Person(x) ⇒ (∃ y Heart(y) ∧ Has(x, y))) becomes ∀ x (Person(x) ⇒ Heart(H(x)) ∧ Has(x, H(x))), where H is a new

symbol (Skolem function).


5. Drop universal quantifiers
• For instance, ∀ x Person(x) becomes Person(x).
6. Distribute ∧ over ∨:
• (α ∧ β) ∨ γ ≡ (α ∨ γ) ∧ (β ∨ γ).
267
3/24/2023 By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY
First Order Logic or Predicate Logic
Conversion of FOL to CNF: 3. Standardize variables apart by renaming them: each quantifier
QUESTION1: CONVERT THE FOLLOWING STATEMENT TO CNF should use a different variable.
1. All Martians like to eat some kind of spiced food.
⇒ (∀X )(¬ martian(X ) V (∃Y)(∃Z)( food(Y) ∧ spice(Z) ∧ contains(Y, Z) ∧likes(X ,Y)))
SOLUTION: 4. Skolemize: each existential variable is replaced by a Skolem
PREDICATE LOGICS FOR THE STATEMENTS: constant or Skolem function of the enclosing universally
⇒ (∀X )(martian(X ) → (∃Y)(∃Z)( food(Y) ∧ spice(Z) ∧ quantified variables.
contains(Y, Z) ∧likes(X ,Y)))
⇒ (∀X )(¬ martian(X ) V ( food(f(X)) ∧ spice(s(X)) ∧ contains(f(X), s(X)) ∧likes(X
,f(X))))
1.Eliminate biconditionals and implications:
5. Drop universal quantifiers
⇒ (∀X )(¬ martian(X ) V (∃Y)(∃Z)( food(Y) ∧ spice(Z) ∧
contains(Y, Z) ∧likes(X ,Y))) ⇒ (¬ martian(X ) V ( food(f(X)) ∧ spice(s(X)) ∧ contains(f(X), s(X)) ∧likes(X ,f(X))))

6. Distribute ∧ over ∨:
2. Move ¬ inwards:
⇒ (¬ martian(X ) V food(f(X))) ∧ (¬ martian(X ) V spice(s(X))) ∧ (¬ martian(X ) V
contains(f(X), s(X))) ∧ (¬ martian(X ) V likes(X ,f(X)))
No change
⇒ (∀X )(¬ martian(X ) V (∃Y)(∃Z)( food(Y) ∧ spice(Z) ∧
CNF for the given sentence:
⇒(¬ martian(X ) V food(f(X))) ∧ (¬ martian(X ) V spice(s(X))) ∧ (¬ martian(X ) V
contains(Y, Z) ∧likes(X ,Y)))
contains(f(X), s(X))) ∧ (¬ martian(X ) V likes(X ,f(X)))

268
3/24/2023 By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY
First Order Logic or Predicate Logic
Conversion of FOL to CNF: 1.Eliminate biconditionals and implications:
QUESTION2: CONVERT THE FOLLOWING STATEMENTS TO CNF
1. Ravi likes all kind of food. 1. ∀x : ¬ food(x) V likes (Ravi, x)
2. Apples and chicken are food 2. food (Apple) ^ food (chicken)
3. Anything anyone eats and is not killed is food 3. ∀x∀y: ¬ (eats (x, y) ^ ¬ killed (x)) V food (y)
4. Ajay eats peanuts and is still alive 4. eats (Ajay, Peanuts) ^ alive (Ajay)
5. Rita eats everything that Ajay eats
5. ∀c : ¬ eats (Ajay, c) V eats (Rita, c)

SOLUTION:
2. Move ¬ inwards:
PREDICATE LOGICS FOR THE STATEMENTS:
1. ∀x : ¬ food(x) V likes (Ravi, x)

1. ∀x : food(x) → likes (Ravi, x) 2. food (Apple) ^ food (chicken)


2. food (Apple) ^ food (chicken) 3. ∀x∀y: ¬ eats (x, y) V killed (x) V food (y)
3. ∀x∀y: (eats (x, y) ^ ¬ killed (x)) → food (y)
4. eats (Ajay, Peanuts) ^ alive (Ajay) 4. eats (Ajay, Peanuts) ^ alive (Ajay)
5. ∀c : eats (Ajay, c) → eats (Rita, c) 5. ∀c : ¬ eats (Ajay, c) V eats (Rita, c)

269
3/24/2023 By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY
First Order Logic or Predicate Logic
Conversion of FOL to CNF:
SOLUTION: (CONTINUE)
3. Standardize variables apart by renaming them: each quantifier 6. Distribute ∧ over ∨:

should
1. ∀xuse a different
: ¬ food(x) V likesvariable.
(Ravi, x) **No change in the statements as the rule (α ∧ β) ∨ γ
2. food (Apple) ^ food (chicken) ≡ (α ∨ γ) ∧ (β ∨ γ) is not applicable in any of them.
3. ∀a∀b: ¬ eats (a, b) V killed (a) V food (b)
4. eats (Ajay, Peanuts) ^ alive (Ajay)
5. ∀c : ¬ eats (Ajay, c) V eats (Rita, c)
4. Skolemize: each existential variable is replaced by a Skolem constant CNF for the given sentences:
or Skolem function of the enclosing universally quantified variables.
1. ¬ food(x) V likes (Ravi, x)
**As there is no existential quantifier, there will be no change in the statements
2. food (Apple)
5. Drop universal quantifiers
3. food (chicken)
1. ¬ food(x) V likes (Ravi, x)
4. ¬ eats (a, b) V killed (a) V food (b)
2. food (Apple)
5. eats (Ajay, Peanuts)
3. food (chicken)
4. ¬ eats (a, b) V killed (a) V food (b) 6. alive (Ajay)
5. eats (Ajay, Peanuts) 7. ¬ eats (Ajay, c) V eats (Rita, c)
6. alive (Ajay)
7. ¬ eats (Ajay, c) V eats (Rita, c) 270
3/24/2023 By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY
First Order Logic or Predicate Logic
Resolution in FOL
Resolution is a theorem proving technique that proceeds by building refutation proofs, i.e., proofs by contradictions.

Steps for Resolution in FOL:

1.Conversion of facts into first-order logic.

2.Convert FOL statements into CNF

3.Negate the statement which needs to prove (proof by contradiction)

4.Draw resolution graph (unification).

3/24/2023 By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 271


First Order Logic or Predicate Logic
Resolution in FOL
Step-1: Conversion of Facts into FOL
Let us take an example in which we will apply resolution.
In the first step we will convert all the given statements into its first
order logic.

Example1:
John likes all kind of food.
Apple and vegetable are food
Anything anyone eats and not killed is food.
Anil eats peanuts and still alive
Harry eats everything that Anil eats.
Prove by resolution that: John likes peanuts.

3/24/2023 By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 272


First Order Logic or Predicate Logic
Resolution in FOL
Step-2: Conversion of FOL into CNF

In First order logic resolution, it is required to convert the FOL into CNF as CNF form makes
easier for resolution proofs.

Step 2a) Eliminate all implication (→) and rewrite


∀x ¬ food(x) V likes(John, x)
food(Apple) Λ food(vegetables)
∀x ∀y ¬ [eats(x, y) Λ ¬ killed(x)] V food(y)
eats (Anil, Peanuts) Λ alive(Anil)
∀x ¬ eats(Anil, x) V eats(Harry, x)
∀x¬ [¬ killed(x) ] V alive(x)
∀x ¬ alive(x) V ¬ killed(x)
likes(John, Peanuts).

3/24/2023 By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 273


First Order Logic or Predicate Logic
Resolution in FOL
Step-2: Conversion of FOL into CNF

In First order logic resolution, it is required to convert the FOL into CNF as CNF form makes easier for resolution proofs.

Step 2a) Eliminate all implication (→) and rewrite Step 2b) Move negation (¬)inwards and rewrite
∀x ¬ food(x) V likes(John, x) ∀x ¬ food(x) V likes(John, x)
food(Apple) Λ food(vegetables) food(Apple) Λ food(vegetables)
∀x ∀y ¬ [eats(x, y) Λ ¬ killed(x)] V food(y) ∀x ∀y ¬ eats(x, y) V killed(x) V food(y)
eats (Anil, Peanuts) Λ alive(Anil) eats (Anil, Peanuts) Λ alive(Anil)
∀x ¬ eats(Anil, x) V eats(Harry, x) ∀x ¬ eats(Anil, x) V eats(Harry, x)
∀x¬ [¬ killed(x) ] V alive(x) ∀x ¬killed(x) V alive(x)
∀x ¬ alive(x) V ¬ killed(x) ∀x ¬ alive(x) V ¬ killed(x)
likes(John, Peanuts). likes(John, Peanuts).

3/24/2023 By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 274


First Order Logic or Predicate Logic
Resolution in FOL
Step-2: Conversion of FOL into CNF

In First order logic resolution, it is required to convert the FOL into CNF as CNF form makes easier for resolution proofs.

Step 2b) Move negation (¬)inwards and rewrite Step 2c)Rename variables or standardize variables

∀x ¬ food(x) V likes(John, x) ∀x ¬ food(x) V likes(John, x)

food(Apple) Λ food(vegetables) food(Apple) Λ food(vegetables)

∀x ∀y ¬ eats(x, y) V killed(x) V food(y) ∀y ∀z ¬ eats(y, z) V killed(y) V food(z)

eats (Anil, Peanuts) Λ alive(Anil) eats (Anil, Peanuts) Λ alive(Anil)

∀x ¬ eats(Anil, x) V eats(Harry, x) ∀w¬ eats(Anil, w) V eats(Harry, w)

∀x ¬killed(x) V alive(x) ∀g ¬killed(g) ] V alive(g)

∀x ¬ alive(x) V ¬ killed(x) ∀k ¬ alive(k) V ¬ killed(k)

likes(John, Peanuts). likes(John, Peanuts).


.

3/24/2023 By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 275


First Order Logic or Predicate Logic
Resolution in FOL
Step-2: Conversion of FOL into CNF
In First order logic resolution, it is required to convert the FOL into CNF as CNF form makes easier for resolution proofs.

Step 2d) Eliminate existential instantiation quantifier by


Step 2c)Rename variables or standardize elimination.
variables In this step, we will eliminate existential quantifier ∃, and this process
∀x ¬ food(x) V likes(John, x) is known as Skolemization. But in this example problem since there is
food(Apple) Λ food(vegetables) no existential quantifier so all the statements will remain same in this
∀y ∀z ¬ eats(y, z) V killed(y) V food(z) step.
eats (Anil, Peanuts) Λ alive(Anil)
∀w¬ eats(Anil, w) V eats(Harry, w) ****Not a part of this question, just few
example of Skolemization:
∀g ¬killed(g) ] V alive(g)
∀k ¬ alive(k) V ¬ killed(k)
likes(John, Peanuts).
.

3/24/2023 By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 276


First Order Logic or Predicate Logic
Resolution in FOL
Step-2: Conversion of FOL into CNF

In First order logic resolution, it is required to convert the FOL into CNF as CNF form makes easier for resolution proofs.

Step 2e) Drop Universal quantifiers.


Results till step 2d): In this step we will drop all universal
∀x ¬ food(x) V likes(John, x)
food(Apple) Λ food(vegetables) ¬ food(x) V likes(John, x)
food(Apple)
∀y ∀z ¬ eats(y, z) V killed(y) V food(z) food(vegetables)
eats (Anil, Peanuts) Λ alive(Anil) ¬ eats(y, z) V killed(y) V food(z)
eats (Anil, Peanuts)
∀w¬ eats(Anil, w) V eats(Harry, w) alive(Anil)
∀g ¬killed(g) ] V alive(g) ¬ eats(Anil, w) V eats(Harry, w)
killed(g) V alive(g)
∀k ¬ alive(k) V ¬ killed(k) ¬ alive(k) V ¬ killed(k)
likes(John, Peanuts). likes(John, Peanuts).
. **Statements "food(Apple) Λ food(vegetables)" and "eats (Anil, Peanuts) Λ alive(Anil)"
can be written in two separate statements.

3/24/2023 By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 277


First Order Logic or Predicate Logic
Resolution in FOL
Step-2: Conversion of FOL into CNF

In First order logic resolution, it is required to convert the FOL into CNF as CNF form makes easier for resolution proofs.

Step 2e) Drop Universal quantifiers.


Step 2f) Distribute conjunction ∧ over disjunction ¬.
¬ food(x) V likes(John, x) This step will not make any change in this problem.
food(Apple)
food(vegetables)
¬ eats(y, z) V killed(y) V food(z)
eats (Anil, Peanuts)
alive(Anil)
¬ eats(Anil, w) V eats(Harry, w)
killed(g) V alive(g)
¬ alive(k) V ¬ killed(k)
likes(John, Peanuts).

3/24/2023 By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 278


First Order Logic or Predicate Logic
Resolution in FOL
Step-3: Negate the statement to be proved
In this statement, we will apply negation to the conclusion statements, which will be written as ¬likes(John, Peanuts)

Step-4: Draw Resolution graph:


Now in this step, we will solve the problem by resolution tree using substitution. For the above problem, it will be given as
follows:

¬ food(x) V likes(John, x)
food(Apple)
food(vegetables)
¬ eats(y, z) V killed(y) V food(z)
eats (Anil, Peanuts)
alive(Anil)
¬ eats(Anil, w) V eats(Harry, w)
killed(g) V alive(g)
¬ alive(k) V ¬ killed(k)
¬ likes(John, Peanuts).

3/24/2023 By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 279


First Order Logic or Predicate Logic
Resolution in FOL
Step-1: Conversion of Facts into FOL
Let us take an example in which we will apply resolution.
In the first step we will convert all the given statements into its first
order logic.

Example2:
i. ∀x : food(x) → likes (Ravi, x)
1. Ravi likes all kind of food. ii. food (Apple) ^ food (chicken)
2. Apples and chicken are food iii. ∀a : ∀b: eats (a, b) ^ ¬ killed (a) → food (b)
iv. eats (Ajay, Peanuts) ^ alive (Ajay)
3. Anything anyone eats and is not killed is food
v. ∀c : eats (Ajay, c) → eats (Rita, c)
4. Ajay eats peanuts and is still alive vi. ∀d : alive(d) → ~killed (d)
5. Rita eats everything that Ajay eats. vii. ∀e: ~killed(e) → alive(e) Added predicates

Prove by resolution that: Ravi likes peanuts.


Conclusion: likes (Ravi, Peanuts)

3/24/2023 By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 280


First Order Logic or Predicate Logic
Resolution in FOL
Step-2: Convert into CNF
Example2(continue..)
Step-1: Conversion of Facts into FOL
i. ~food(x) v likes (Ravi, x)
ii. Food (apple)
i. ∀x : food(x) → likes (Ravi, x)
iii. Food (chicken)
ii. food (Apple) ^ food (chicken)
iv. ~ eats (a, b) v killed (a) v food (b)
iii. ∀a : ∀b: eats (a, b) ^ ¬ killed (a) → food (b)
v. Eats (Ajay, Peanuts)
iv. eats (Ajay, Peanuts) ^ alive (Ajay)
vi. Alive (Ajay)
v. ∀c : eats (Ajay, c) → eats (Rita, c)
vii. ~eats (Ajay, c) V eats (Rita, c)
vi. ∀d : alive(d) → ~killed (d)
viii. ~alive (d) v ~ killed (d)
vii. ∀e: ~killed(e) → alive(e)
ix. Killed (e) v alive (e)
Conclusion: likes (Ravi, Peanuts)
Conclusion: likes (Ravi, Peanuts)

Step-3: Negate the conclusion

~ likes (Ravi, Peanuts)

3/24/2023 By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 281


First Order Logic or Predicate Logic
Resolution in FOL
Step-4: Resolve using a resolution tree
Example2(continue..)

i. ~food(x) v likes (Ravi, x)


ii. Food (apple)
iii. Food (chicken)
iv. ~ eats (a, b) v killed (a) v food (b)
v. Eats (Ajay, Peanuts)
vi. Alive (Ajay)
vii. ~eats (Ajay, c) V eats (Rita, c)
viii. ~alive (d) v ~ killed (d)
ix. Killed (e) v alive (e)

Negated Conclusion: ~ likes (Ravi, Peanuts)

Hence the negation of the conclusion is completely invalid or


false or the assertion is completely valid or true. Hence the
conclusion is Proved

3/24/2023 By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 282


Forward Chaining and backward chaining
Chaining:

1. Whenever we do a complete, multistep task, we complete the component parts in a specific order (though there can be some flexibility.)
2. We start at some point and complete each step, one step at a time.
3. Since these tasks are sequential we refer to teaching them step-by-step as "chaining."

Example:

1. When teaching life skills such as dressing, grooming or perhaps even cooking, a special educator often has to break down the task to be
taught in small discrete steps.
2. The first step for teaching a life skill is to complete a task analysis.
3. Once the task analysis is complete, the teacher needs to decide how it is to be taught: chaining forward, or chaining backward?

The inference engine of a knowledge based expert system uses the same concept:

The inference engine of knowledge based agents applies logical rules to the knowledge base to infer new information from known facts.
Inference engine commonly proceeds in two modes, which are:

1. Forward chaining
2. Backward chaining

3/24/2023 By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 283


Forward Chaining
 Known as a forward deduction or forward reasoning method.

 Starts with atomic sentences in the knowledge base and applies inference rules in the forward direction to extract more data until a goal is
reached. So, it is a bottom up approach.

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

 Forward-chaining approach is also called as data-driven as we reach to the goal using available data.

Simple Example:
A He exercises regularly
A-> B If he is exercising regularly, he is fit
B He is fit

3/24/2023 By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 284


Forward Chaining
Question: Solution :
 Start with input given A, B is true and then start
Given : A Rule base contains following Rule set at Rule 1 and go forward/down till a rule “fires'' is
Rule 1: If A and C Then F found.
Rule 2: If A and E Then G
Rule 3: If B Then E First iteration :
Rule 4: If G Then D  Rule 3 fires : conclusion E is true, new
knowledge found .
 No other rule fires;
Problem : Prove end of first iteration.
If A and B true Then D is true
Goal not found; new knowledge found for E; go for
second iteration

Second iteration :
 Rule 2 fires : conclusion G is true, new
knowledge found.
 Rule 4 fires : conclusion D is true
Goal found;
Proved.

3/24/2023 By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 285


Forward Chaining
Question:
Some Fact :
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."
Goal:
Prove that "Robert is criminal."

1. 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)
2. 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)
3. All of the missiles were sold to country A by Robert.
∀p Missiles(p) ∧ Owns (A, p) → Sells (Robert, p, A) ......(4)
4. Missiles are weapons.
Missile(p) → Weapons (p) .......(5)
5. Enemy of America is known as hostile.
Enemy(p, America) →Hostile(p) ........(6)
6. Country A is an enemy of America.
Enemy (A, America) .........(7)
7. Robert is American
American(Robert). ..........(8)

3/24/2023 By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 286


Forward Chaining
1. American (p) ∧ weapon(q) ∧ sells (p, q, r) ∧ hostile(r) → Criminal(p)
2. Owns(A, T1)
3. Missile(T1)
4. ∀p (Missiles(p) ∧ Owns (A, p) → Sells (Robert, p, A) )
5. (Missile(p) → Weapons (p))
6. (Enemy(p, America) →Hostile(p))
7. Enemy (A, America)
8. American(Robert).

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 {T1/p}, so Sells (Robert, T1, A) is added, which infers from the conjunction of Rule (2)
and (3).
Rule –(5) satisfy with substitution T1/p, so Weapons (T1) is added.
Rule-(6) is satisfied with the substitution(A/p), so Hostile(A) is added.

3/24/2023 By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 287


Forward Chaining
1. American (p) ∧ weapon(q) ∧ sells (p, q, r) ∧ hostile(r) → Criminal(p)
2. Owns(A, T1)
3. Missile(T1)
4. ∀p (Missiles(p) ∧ Owns (A, p) → Sells (Robert, p, A) )
5. (Missile(p) → Weapons (p))
6. (Enemy(p, America) →Hostile(p))
7. Enemy (A, America)
8. American(Robert).

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 {T1/p}, so Sells (Robert, T1, A) is added, which infers from the conjunction of Rule (2)
and (3).
Rule –(5) satisfy with substitution T1/p, so Weapons (T1) is added.
Rule-(6) is satisfied with the substitution(A/p), so Hostile(A) is added.

3/24/2023 By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 288


Forward Chaining
1. American (p) ∧ weapon(q) ∧ sells (p, q, r) ∧ hostile(r) → Criminal(p)
2. Owns(A, T1)
3. Missile(T1)
4. ∀p (Missiles(p) ∧ Owns (A, p) → Sells (Robert, p, A) )
5. (Missile(p) → Weapons (p))
6. (Enemy(p, America) →Hostile(p))
7. Enemy (A, America)
8. American(Robert).

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

3/24/2023 By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 289


Backward Chaining
 Known as a backward deduction or backward reasoning method.

 Starts with the goal and works backward, chaining through rules to find known facts that support the goal. So, it is a top down approach.

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

Simple Example:
B Tom is sweating (B).
A-> B If a person is running, he will sweat (A->B).
A Tom is running.

3/24/2023 By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 290


Backward Chaining
Question:
Solution :
Given : A Rule base contains following Rule set  Start with goal i.e., D is true go backward/up till a
Rule 1: If A and C Then F rule "fires'' is found.
Rule 2: If A and E Then G
Rule 3: If B Then E First iteration :
Rule 4: If G Then D  Rule 4 fires : new sub goal to prove G is true , go
backward
 Rule 2 "fires''; conclusion: A is true
 New sub goal to prove E is true go backward;
Problem : Prove  No other rule fires; end of first iteration.
If A and B true Then D is true
New sub goal found E, go for second iteration

Second iteration :
 Rule 3 fires : conclusion B is true (2nd input
found) both inputs A and B ascertained.
Proved

3/24/2023 By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 291


Backward Chaining
Question:
Some Fact :
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."
Goal:
Prove that "Robert isa criminal."

1. 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)
2. 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)
3. All of the missiles were sold to country A by Robert.
∀p Missiles(p) ∧ Owns (A, p) → Sells (Robert, p, A) ......(4)
4. Missiles are weapons.
Missile(p) → Weapons (p) .......(5)
5. Enemy of America is known as hostile.
Enemy(p, America) →Hostile(p) ........(6)
6. Country A is an enemy of America.
Enemy (A, America) .........(7)
7. Robert is American
American(Robert). ..........(8)

3/24/2023 By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 292


Backward Chaining
1. American (p) ∧ weapon(q) ∧ sells (p, q, r) ∧ hostile(r) → Criminal(p)
2. Owns(A, T1)
3. Missile(T1)
4. ∀p (Missiles(p) ∧ Owns (A, p) → Sells (Robert, p, A) )
5. (Missile(p) → Weapons (p))
6. (Enemy(p, America) →Hostile(p))
7. Enemy (A, America)
8. American(Robert).

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.

3/24/2023 By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 293


Backward Chaining
1. American (p) ∧ weapon(q) ∧ sells (p, q, r) ∧ hostile(r) → Criminal(p)
2. Owns(A, T1)
3. Missile(T1)
4. ∀p (Missiles(p) ∧ Owns (A, p) → Sells (Robert, p, A) )
5. (Missile(p) → Weapons (p))
6. (Enemy(p, America) →Hostile(p))
7. Enemy (A, America)
8. American(Robert).
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.

{q/p}

{T1/q}

3/24/2023 By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 294


Backward Chaining
1. American (p) ∧ weapon(q) ∧ sells (p, q, r) ∧ hostile(r) → Criminal(p)
2. Owns(A, T1)
3. Missile(T1)
4. ∀p (Missiles(p) ∧ Owns (A, p) → Sells (Robert, p, A) )
5. (Missile(p) → Weapons (p))
6. (Enemy(p, America) →Hostile(p))
7. Enemy (A, America)
8. American(Robert).

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.

{q/p} {T1/p} {A/r}

3/24/2023 By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 295


Backward Chaining
1. American (p) ∧ weapon(q) ∧ sells (p, q, r) ∧ hostile(r) → Criminal(p)
2. Owns(A, T1)
3. Missile(T1)
4. ∀p (Missiles(p) ∧ Owns (A, p) → Sells (Robert, p, A) )
5. (Missile(p) → Weapons (p))
6. (Enemy(p, America) →Hostile(p))
7. Enemy (A, America)
8. American(Robert).

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.

3/24/2023 By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 296


Backward Chaining

 Most useful production system databases will contain a large amount of information that is irrelevant to the given problem
being worked on, and this can make their use rather inefficient.

 Three traditional solutions to this problem are:

1. Use backward chaining rather than forward chaining.


2. Restrict forward chaining to a selected sub-set of rules.
3. Rewrite the rule set using information from the goal, so that only relevant variable bindings (those belonging to a magic
set) are considered during forward inference.

3/24/2023 By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 297


Forward Vs. Backward Chaining
Forward Chaining Backward Chaining
Forward chaining starts from known facts and applies inference Backward chaining starts from the goal and works backward
rule to extract more data unit it reaches to the goal. through inference rules to find the required facts that support
the goal.
It is a bottom-up approach It is a top-down approach
Forward chaining is known as data-driven inference technique Backward chaining is known as goal-driven technique as we
as we reach to the goal using the available data. start from the goal and divide into sub-goal to extract the facts.

Forward chaining reasoning applies a breadth-first search Backward chaining reasoning applies a depth-first search
strategy. strategy.
Forward chaining tests for all the available rules Backward chaining only tests for few required rules.
Forward chaining is suitable for the planning, monitoring, Backward chaining is suitable for diagnostic, prescription, and
control, and interpretation application. debugging application.
Forward chaining can generate an infinite number of possible Backward chaining generates a finite number of possible
conclusions. conclusions.
It operates in the forward direction. It operates in the backward direction.
Forward chaining is aimed for any conclusion. Backward chaining is only aimed for the required data.
Forward chaining can be used for tasks such as planning, Backward chaining can be used for tasks such as classification
design process monitoring, diagnosis, and classification. and diagnosis tasks.
3/24/2023 By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 298
Wumpus World Problem
The Wumpus world is a simple world example that shows the value of a knowledge-based agent and how knowledge
representation works.

Wumpus World Problem:


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.

3/24/2023 By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 299


Wumpus World Problem

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

 The rooms adjacent to the Wumpus room are smelly, so that it would have
some stench.
 The room adjacent to PITs has a breeze, so if the agent reaches near to
PIT, then he will perceive the breeze.
 There will be glitter in the room if and only if the room has gold.
 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.

3/24/2023 By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 300


Wumpus World Problem

PEAS description of Wumpus world:

Performance measure:
 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].

3/24/2023 By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 301


Wumpus World Problem
PEAS description of Wumpus world:

Sensors:
 Breeze
 Stench
 Glitter
 Scream (When the Wumpus is killed)
 Bump (when the agent hits a wall).
 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].

Actuators:
 Left turn,
 Right turn
 Move forward
 Grab
 Release
 Shoot.
3/24/2023 By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 302
Wumpus World Problem
The Wumpus world Properties:

1. Partially observable: The Wumpus world is partially observable because the agent can only
perceive the close environment such as an adjacent room.
2. Deterministic: It is deterministic, as the result and outcome of the world are already known.
3. Sequential: The order is important, so it is sequential.
4. Static: It is static as Wumpus and Pits are not moving.
5. Discrete: The environment is discrete.
6. One agent: The environment is a single agent as we have one agent only and Wumpus is not
considered as an agent.

3/24/2023 By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 303


Wumpus World Problem
How the agent searches for the treasure?

Step 1: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 that the room
is safe we will add symbol OK.

3/24/2023 By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 304


Wumpus World Problem
How the agent searches for the treasure?

Step 2: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?

3/24/2023 By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 305


Wumpus World Problem
How the agent searches for the treasure?

Step 3: 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].

1,4 2,4 3,4 4,4

1,3 2,3 3,3 4,3


W

1,2 2,2 3,2 4,2


vOK A OK
1,1 2,1 3,1 4,1
v OK B P

3/24/2023 By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 306


Wumpus World Problem
How the agent searches for the treasure?

Step 4: 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..

3/24/2023 By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 307


Wumpus World Problem
Knowledge Base of Wumpus world:

Propositional logic is used for building the knowledge base

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.

There are 7 variables for one room, So, there will be 7*4*4= 112 propositional
variables for a 4 * 4 square board

Some Propositional Rules for the wumpus world: 1,4 2,4 3,4 4,4

1,3 2,3 3,3 4,3

1,2 2,2 3,2 4,2

1,1 2,1 3,1 4,1

3/24/2023 308
Wumpus World Problem
Knowledge Base of Wumpus world:
Prove that Wumpus is in the room (1, 3)

1. Apply Modus Ponens with ¬S11 and R1: At first we will apply MP rule with R1
which is ¬S11 → ¬W11^ ¬W12 ^ ¬W21, and ¬S11 which will give this output ¬ W11 ^
W12 ^ W12

Rule premises conclusion

Modus ¬S11 → ¬W11^ ¬W12 ^ ¬W21 ¬ W11 ^ W12 ^ W12


Ponens ¬S11

3/24/2023 309
Wumpus World Problem
Knowledge Base of Wumpus world:
Prove that Wumpus is in the room (1, 3)

2. Apply And-Elimination Rule: After we apply And-elimination rule to ¬W11 ∧ ¬W12 ∧ ¬W21, we
will see three statements: ¬W11, ¬W12, and ¬W21.

3. Apply Modus Ponens to ¬S21, and R2: We will now apply Modus Ponens to ¬S21 and R2 which is
¬S21 → ¬W21 ∧¬ W22 ∧ ¬W31, which will give the Output as ¬W21 ∧ ¬W22 ∧ ¬W31

4. Apply And-Elimination Rule: Again we will now apply And-elimination rule to ¬ W21 ∧ ¬ W22 ∧¬ W31, We will see three statements: ¬W21,
¬W22, and ¬W31.
Rule premises Conclusion
Modus Ponens ¬S11 → ¬W11^ ¬W12 ^ ¬W21 ¬ W11 ^ W12 ^ W12
¬S11

And-Elimination ¬W11 ∧ ¬W12 ∧ ¬W21 ¬W11, ¬W12, and ¬W21

Modus Ponens ¬S21 → ¬W21 ∧¬ W22 ∧ ¬W31 ¬W21 ∧ ¬W22 ∧ ¬W31


¬S21
And-Elimination ¬ W21 ∧ ¬ W22 ∧¬ W31 W21, ¬W22, and ¬W31
3/24/2023 310
Wumpus World Problem
Knowledge Base of Wumpus world:

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

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

Rule premises Conclusion


Modus Ponens ¬S11 → ¬W11^ ¬W12 ^ ¬W21 ¬ W11 ^ W12 ^ W12
6. Apply Unit resolution on W13 ∨ W12 ∨ W22 ∨ W11 and ¬W11 : After applying Unit ¬S11

resolution formula on W13 ∨ W12 ∨ W22 ∨ W11 and ¬W11 we will see W13 ∨ W12 ∨ W22 And- ¬W11 ∧ ¬W12 ∧ ¬W21 ¬W11, ¬W12, and ¬W21
Elimination
Modus Ponens ¬S21 → ¬W21 ∧¬ W22 ∧ ¬W31 ¬W21 ∧ ¬W22 ∧ ¬W31
¬S21
And- ¬ W21 ∧ ¬ W22 ∧¬ W31 W21, ¬W22, and ¬W31
Elimination
Modus Ponens S12 → W13 ∨. W12 ∨. W22 ∨. W11 W13 ∨ W12 ∨ W22 ∨
S12 W11
Unit W13 ∨ W12 ∨ W22 ∨ W11 W13 ∨ W12 ∨ W22
resolution ¬W11

3/24/2023 311
Wumpus World Problem
Knowledge Base of Wumpus world:
Prove that Wumpus is in the room (1, 3)

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

Rule premises Conclusion

Modus Ponens ¬S11 → ¬W11^ ¬W12 ^ ¬W21 ¬ W11 ^ W12 ^ W12


¬S11

And-Elimination ¬W11 ∧ ¬W12 ∧ ¬W21 ¬W11, ¬W12, and ¬W21

8. Apply Unit Resolution on W13 ∨ W12 and ¬W12 : After Applying Unit Modus Ponens ¬S21 → ¬W21 ∧¬ W22 ∧ ¬W31
¬S21
¬W21 ∧ ¬W22 ∧ ¬W31

resolution on W13 ∨ W12 and ¬W12, we will see W13 as an output, therefore, it is
And-Elimination ¬ W21 ∧ ¬ W22 ∧¬ W31 W21, ¬W22, and ¬W31
proved that the Wumpus is in the room [1, 3].
Modus Ponens S12 → W13 ∨. W12 ∨. W22 ∨. W11 W13 ∨ W12 ∨ W22 ∨ W11
S12

Unit resolution W13 ∨ W12 ∨ W22 ∨ W11 W13 ∨ W12 ∨ W22


¬W11

Unit resolution W13 ∨ W12 ∨ W22 W13 ∨ W12


¬W22

Unit resolution W13 ∨ W12 W13 (proved)


¬W12

3/24/2023 312
Reasoning in AI
 The reasoning is the mental process of deriving logical conclusion and making predictions from available knowledge,
facts, and beliefs. Or we can say, "Reasoning is a way to infer facts from existing data"

 Reasoning is essential so that the machine can also think rationally as a human brain, and can perform like a human.

 Types of Reasoning:
 Deductive reasoning
 Inductive reasoning
 Abductive reasoning
 Common Sense Reasoning
 Monotonic Reasoning
 Non-monotonic Reasoning

3/24/2023 By Dr. Manomita Chakraborty, SCOPE, VIT-AP UNIVERSITY 313

You might also like