Artificial Intelligence CSE3002: by Dr. Manomita Chakraborty Assistant Professor VIT-AP, Amaravati, AP, India
Artificial Intelligence CSE3002: by Dr. Manomita Chakraborty Assistant Professor VIT-AP, Amaravati, AP, India
CSE3002
By
By
Dr. Manomita Chakraborty
Assistant Professor
VIT-AP, Amaravati, AP, India
• Mathematics
• Programming concepts
Ability to perception.
Artificial Intelligence
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.
Main goals:
To create expert system: The systems
which exhibit intelligent behavior, learn,
demonstrate, and explain its user.
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.
Type-1 Type-2
Super AI:
Reactive machines are the most basic example of AI which cannot create memories or learn from past experiences.
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.
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
“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:
They are aware about who they are, understand their internal traits, states and conditions and can even perceive human
emotions.
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.
Specification of what are valid inputs and what are acceptable outputs for each valid input.
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.
1. Define the initial state, final state, acceptable solution(s) of the problem precisely.
4. Choose the best possible problem solving technique to solve the problem.
2. Problem Reduction.
• The game goes on until a player wins the game or it ended up in a draw by
***
• Based on the problem
solving technique or
algorithm , a player
will decide his move.
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:
***
• Based on the problem
solving technique or
algorithm , a player
will decide his move.
In this way you have to explore the state space for the problem until the goal is reached
• 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.
• 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.
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.
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
Speed Finding the solution is quicker. Finding the solution is much slower comparatively.
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.
Length of Implementation Implementation is shorter using AI. The implementation is lengthier using AI.
Iterative Deepening
Breadth First Depth First Uniform cost Depth Limited Depth First
Search(BFS) Search(DFS) search Search Search(IDDFS)
Informed
search
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.
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.
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
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.
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.
*** 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.
Admissibility: An algorithm is admissible if it is guaranteed to return an optimal solution whenever a solution exists.
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
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.
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).
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.
****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.
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.
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)
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.
********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.
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.
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
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.
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.
5 A 7
1 1
1
f(B-E) = 1 + 6 = 7
f(B-F) = 1 + 8 = 9
5 A 7
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
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)
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.
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.
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.
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
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.
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.
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
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.
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).
18.8
Steepest-Ascent hill-climbing
Algorithm CURRENT node
CLOSED
h(n)=6
A
h(n)=1.7 E h(n)= 1 H I
h(n)= 1.5
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.
Algorithm
Step 3: Else remove the CURRENT node and push to CLOSED . Call this NODE as k.
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.
4 6
A B
2 3 2 1
C D E F
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
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.
Using this information we have to use some operator to go from start to goal node
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
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.
Using this information we have to use some operator to go from start to goal node
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
h = -6 h=6
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
You have to replace each unique alphabet by a unique number between 0 to 9 such that the final answer is correct:
Constraints allowed:
? ? ? ?
+ ? ? ? ?
? ? ? ? ?
•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 ?
•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 ?
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
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
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.
• 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.
1. B A S E
+ B A L L
G A M E S
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
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
Q1
Q1 Q1
Q2 Q2
Q1 Q1
Q2 Q2
Q3 Q3
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
Q3 Q3
Q4=
3
Q1
Q2
Q3
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
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.
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.
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
………………………………………………………………………………………………………………..
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
• 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.
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.
X Y X
Production rules
S.No. Initial State Condition Final state Description of action taken
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
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
(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)
(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
(2,3)
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.
(3,3) (0,0)
(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-
• The game goes on until a player wins the game or it ended up in a draw by
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.
… … …
(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
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.
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?
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).
The Water Jug Problem, the path that leads to the goal must be
reported.
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.
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.
• These agents can represent the world with some formal representation and act intelligently.
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
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.
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.
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.
Approaches
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.
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
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
4. Example: Let's suppose there are two statements: 3. Various coding languages such as LISP language and Prolog language can be
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)
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
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.
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:
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.
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.
Statements:
1. Tom is a cat.
7. A cat is a mammal.
8. A bird is an animal.
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
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
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.
Frame Description
of a Hotel Room
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
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,
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,
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.
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."
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.
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
Precedence of connectives:
Precedence Operators
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.
¬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.
¬p ^ q
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 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:
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.
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.
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
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.
Valid Arguments
Valid Arguments
Let
p :=“I sleep a lot”
q :=“I don’t do any homework”
r :=“I will not do well in this class”
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
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.
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:
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.
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.”
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.”
Absorption:
(p -> q)
∴ p -> (p ^ q)
Example:
“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.”
Modus Tollens
Disjunctive Syllogism
Addition
Simplification
Resolution
Step2:Determine if the symbolic rules matches with any of the inference rules.
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.
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.
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.
Then the premises become ¬p ∧ q, r → p, ¬r →s, and s →t. The conclusion is simply t.
Then the premises become ¬p ∧ q, r → p, ¬r →s, and s →t. The conclusion is simply t.
(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
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.
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
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
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
Begin:
• 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.
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,
Functions: father of, best friend, third inning of, one more than, end of
collection of formal systems used in mathematics, philosophy, linguistics, and computer science.
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
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.
Example:
Ravi and Ajay are brothers: Brothers(Ravi, Ajay).
Chinky is a cat: cat (Chinky).
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.
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.
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:
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.
Quantifier with negation: ~ ∃x [P(x)] = ∀x[~ P(x)] and ~ ∀x[P(x)]= ∃x[~ P(x)].
(∃ 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
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
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.
Solution:
Let MAN(x), MORTAL(x) represent that x is a man and x is mortal respectively.
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
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.
Let’s let L(x) be “x is a lion,” F(x) be “x is fierce,” and C(x) be “x drinks coffee.”
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)
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))}
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 θ= {John/x}
S1 => { knows(Richard, John); knows(Richard, John)}, Successfully Unified.
Unifier: {John/x}..
• “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
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)
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.
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.
In First order logic resolution, it is required to convert the FOL into CNF as CNF form makes
easier for resolution proofs.
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).
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
In First order logic resolution, it is required to convert the FOL into CNF as CNF form makes easier for resolution proofs.
In First order logic resolution, it is required to convert the FOL into CNF as CNF form makes easier for resolution proofs.
¬ 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).
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
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
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
Second iteration :
Rule 2 fires : conclusion G is true, new
knowledge found.
Rule 4 fires : conclusion D is true
Goal found;
Proved.
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)
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.
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.
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.
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.
Second iteration :
Rule 3 fires : conclusion B is true (2nd input
found) both inputs A and B ascertained.
Proved
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)
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.
{q/p}
{T1/q}
Step 4: At step-4, we can infer facts Missile(T1) and Owns(A, T1) form Sells(Robert, T1, r) which satisfies the Rule- 4, with
the substitution of A in place of r. So these two statements are proved here.
Step 5: At step-5, we can infer the fact Enemy(A, America) from Hostile(A) which satisfies Rule- 6. And hence all the
statements are proved true using backward chaining.
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.
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.
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.
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].
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.
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.
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?
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].
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..
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
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
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
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.
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.
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
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