AI Heuristic Search Methods Explained
AI Heuristic Search Methods Explained
MODULE – 2
AI deals with solving complex problems that are too intricate to be handled using simple or direct techniques. Many AI
problems require exploring multiple possible solutions before reaching an optimal one. Therefore, AI systems often rely
on search-based problem-solving methods, which use algorithms to explore different paths or states in order to find the
best solution.
A search method is a structured process that defines how an AI system navigates through the problem space — that is,
how it moves from an initial state to a goal state. These search strategies are typically categorized as heuristic search
methods, which rely on rules of thumb or approximate knowledge to guide the search process efficiently. Search
methods can be described independently of the problem domain, making them general-purpose techniques. However,
when applied to specific problems, their success depends largely on how well they incorporate domain-specific
knowledge. Without this knowledge, AI systems can face the combinatorial explosion problem — an exponential
growth in the number of possible states to explore, making computation infeasible.
Because these search strategies operate based on limited knowledge and rely on general rules rather than detailed
information, they are often termed weak methods. Despite their limitations, such methods form the core of most AI
systems as they provide the foundation into which specialized, domain-specific intelligence can be integrated either
manually or through automatic learning.
● Depth-First Search (DFS): Explores as far as possible along one branch before backtracking.
● Breadth-First Search (BFS): Explores all nodes at one level before moving to the next level.
These methods form the foundation of search algorithms and are essential for understanding more advanced strategies.
Apart from DFS and BFS, the following search techniques are also commonly studied in AI:
● Generate-and-Test: Generates possible solutions and tests each for goal satisfaction.
● Hill Climbing: An iterative algorithm that moves towards a solution by selecting the best neighboring state.
Prepared by: Dr Roopashree S, Dr. Priyanka C H, Prof Anita H K, Prof. Vidushi Dwivedi 1
Introduction to AI and Applications (25CS1ETIAA)
● Means–Ends Analysis: Reduces the difference between the current state and the goal state by applying suitable
operators.
Each of these techniques is designed to handle specific problem scenarios efficiently and form the building blocks of
intelligent problem-solving systems.
2.2 Generate-and-Test
The Generate-and-Test strategy is one of the simplest and most fundamental problem-solving methods in Artificial
Intelligence. It is a trial-and-error approach where possible solutions are generated and tested until a satisfactory solution is
found. Despite its simplicity, it forms the foundation for more advanced AI techniques such as heuristic and evolutionary
algorithms.
The generate-and-test algorithm functions as a depth-first search process because complete solutions must be generated
before testing them. If solutions are generated systematically, the algorithm guarantees finding a solution — provided one
exists — though it may take a long time for large search spaces. In its most exhaustive form, the algorithm explores every
possible state, similar to the British Museum Algorithm, where one searches through an entire museum randomly to find an
object. However, this exhaustive approach is inefficient and time-consuming. Hence, heuristics are often applied to make
the process smarter and faster.
2.2.3. Advantages
Prepared by: Dr Roopashree S, Dr. Priyanka C H, Prof Anita H K, Prof. Vidushi Dwivedi 2
Introduction to AI and Applications (25CS1ETIAA)
2.2.4. Limitations
● May take a long time to find a solution, or may never find one if the space is infinite.
2.2.5. Applications
1. Puzzle Solving: Example – Arranging colored cubes in a row so that no two adjacent cubes share the same color.
o Randomly generate arrangements and test until one satisfies the condition.
2. Scientific Discovery:
o Example – The AI system DENDRAL used a plan-generate-test approach to identify molecular structures
based on chemical data (mass spectrometry and NMR).
● Heuristics guide the generation process by preferring solutions that are more likely to succeed.
● Example: Instead of trying all possible cube arrangements in the puzzle, a heuristic may prioritize placing blocks
with more matching faces first.
Variations
● Random Generate-and-Test: Randomly samples the solution space (less guaranteed but faster).
2.2.7. Example
Prepared by: Dr Roopashree S, Dr. Priyanka C H, Prof Anita H K, Prof. Vidushi Dwivedi 3
Introduction to AI and Applications (25CS1ETIAA)
This demonstrates how generate-and-test systematically searches through potential solutions until a goal is met.
Scenario:
We need to find a number between 1 and 100 that, when squared, gives 49.
Steps:
Explanation:
This example illustrates the basic essence of generate-and-test. The algorithm generates candidate solutions (numbers) and
tests each one until the goal condition (square = 49) is met. This process is simple but systematic — it guarantees a solution,
though it may not be efficient for larger problem spaces.
Scenario:
Imagine you forgot your 4-digit phone password but remember that it contains only numbers (0000–9999).
Steps:
Explanation:
This is a real-world example of a brute force search — a direct application of the generate-and-test method. It does not use
any shortcuts or heuristics; instead, it systematically tests all possible combinations until the correct one is found.
Prepared by: Dr Roopashree S, Dr. Priyanka C H, Prof Anita H K, Prof. Vidushi Dwivedi 4
Introduction to AI and Applications (25CS1ETIAA)
Note: Even though generate-and-test alone is limited, when used with other methods (like constraint satisfaction or
planning), it becomes a powerful part of AI systems. For instance, plan-generate-test combines planning and search — it
first plans a structure for solutions, generates possible ones, and tests them to identify feasible results.
Scenario:
A robot is placed inside a maze and must find the correct path to the exit.
Steps:
Explanation:
This is an example of a search-based problem-solving task. Early AI systems like the General Problem Solver (GPS)
used similar logic to explore problem spaces. The robot evaluates paths one by one until it finds the correct sequence of
moves leading to the goal.
Scenario:
A salesman must visit multiple cities exactly once and return to the starting city while minimizing the total travel distance
as shown in Fig. 2.1.
Steps:
Prepared by: Dr Roopashree S, Dr. Priyanka C H, Prof Anita H K, Prof. Vidushi Dwivedi 5
Introduction to AI and Applications (25CS1ETIAA)
Explanation:
This is a classic optimization problem where the goal is not just to find a solution, but the best solution (least cost or
shortest distance). Using generate-and-test, the algorithm systematically explores possible routes, evaluates each one, and
identifies the optimal path.
Minimum distance = 11
1. A → C → B → D → A
2. A → D → B → C → A
Final Answer
Hill Climbing is a variant of the Generate-and-Test strategy where feedback from the test procedure is used to decide
which direction to move in the search space. Unlike the pure Generate-and-Test approach—which only checks whether a
Prepared by: Dr Roopashree S, Dr. Priyanka C H, Prof Anita H K, Prof. Vidushi Dwivedi 6
Introduction to AI and Applications (25CS1ETIAA)
generated solution is correct or not—Hill Climbing improves the process by using a heuristic function. A heuristic
function (h) gives an estimate of how close a particular state is to the goal state. This allows the algorithm to “climb”
towards better states step-by-step. Essentially, instead of generating random solutions, the algorithm uses the heuristic to
guide its search toward more promising directions.
Hill Climbing is particularly efficient because the heuristic can often be computed at almost no extra cost during the process
of testing a solution. It is widely used when a good heuristic function is available to evaluate the quality of different states,
even when no other problem-specific knowledge is known. For example, imagine you are lost in an unfamiliar city without
a map, but you can see the tops of tall buildings in the distance. If your goal is to reach downtown, you might simply move
toward those buildings. Here, the heuristic function could be the distance between your current location and the tall
buildings—and your objective is to minimize this distance.
Hill Climbing continues moving toward states that appear to bring it closer to the goal (or maximize some objective). The
process stops when:
This method is particularly suitable for optimization problems, where we want to find the maximum or minimum of a
function, such as in the Travelling Salesman Problem. However, unlike some other algorithms, Hill Climbing does not
maintain a memory of previous states, so it can sometimes get “stuck” on local maxima or plateaus.
● Effective for problems where absolute solutions exist and can be recognized easily (e.g., reaching a specific goal).
● Used in relative optimization problems such as route finding, scheduling, and parameter tuning in AI models.
2.3.2. Example
If the objective is to minimize the cost (e.g., distance, time, or error), Hill Climbing repeatedly selects the next state that
has the lowest heuristic value. If the objective is to maximize a score (e.g., profit or efficiency), it selects the highest
heuristic value instead.
Prepared by: Dr Roopashree S, Dr. Priyanka C H, Prof Anita H K, Prof. Vidushi Dwivedi 7
Introduction to AI and Applications (25CS1ETIAA)
The Hill Climbing Search Graph as shown in Fig. 2.2 visually represents how the algorithm progresses through the search
space. The graph usually shows the evaluation function (or fitness) on the y-axis and the possible states or solutions on the
x-axis.
● Global Maximum: The highest peak on the graph. It represents the best possible solution among all states.
● Local Maximum: A smaller peak where the algorithm may get stuck because all nearby moves lead to lower
values, even though it’s not the best overall solution.
● Plateau: A flat region where many neighboring states have the same value, making it hard for the algorithm to
decide which direction to move.
● Shoulder: A flat region followed by an uphill climb, which might confuse the search process initially but
eventually leads to improvement.
● Ridge: It is another particular type of local maximum, that is located between a better maximum and a minimum
of the state space diagram.
In practice, Hill Climbing is simple but can face problems such as getting trapped in local maxima, wandering aimlessly
on plateaus, or oscillating between similar states. Variants like Stochastic Hill Climbing, Random-Restart Hill Climbing,
and Simulated Annealing are used to overcome these limitations.
2.3.3. Limitations
● May stop early at a plateau (flat region) where neighboring states have equal heuristic values.
Prepared by: Dr Roopashree S, Dr. Priyanka C H, Prof Anita H K, Prof. Vidushi Dwivedi 8
Introduction to AI and Applications (25CS1ETIAA)
Simple Hill Climbing is the most basic form of the hill-climbing algorithm used in Artificial Intelligence. It works on a
local and greedy search approach and does not use backtracking. It is a heuristic search method that continually moves in
the direction of increasing value (or decreasing cost) to find a better solution. The algorithm compares the current state with
its neighboring states and moves to the neighbor that improves the evaluation function. If no better neighbor exists, the
search stops.
3. If no operator can improve the current state further, terminate (failure or local optimum).
The main difference between Simple Hill Climbing and Generate-and-Test is the use of a heuristic function. The heuristic
function provides guidance on which direction to move in the search space by estimating how close a given state is to the
goal. The algorithm asks the question: “Is one state better than another?” and uses the heuristic function to decide. The
definition of “better” can vary: in some cases, a higher heuristic value is better, while in others (such as cost-based
problems), a lower value is preferred.
● A heuristic function can be defined as the number of different colors on each of the four sides.
● The goal is to make all sides the same color, so a perfect solution would have a heuristic value of 16.
● The rules of transformation involve choosing a block and changing its color until the heuristic value improves.
This example illustrates how the algorithm evaluates each state and chooses the next one that seems closer to the goal,
making decisions step by step based on heuristic feedback.
Example:
Prepared by: Dr Roopashree S, Dr. Priyanka C H, Prof Anita H K, Prof. Vidushi Dwivedi 9
Introduction to AI and Applications (25CS1ETIAA)
1. Blocks World Example: Consider the blocks world problem with the block arrangement with the initial state and
the desired goal state as shown in Fig 2.3.
Step 1. To move towards the goal state, we need to apply the move operator to rearrange the blocks as shown by applying
the rules. As a result, the block arrangement is as shown. in Fig. 2.4. where h(n) = 0 for initial state and after placing block
A on ground the h(n) = 2 (new state) which is closer to the goal. So h(n) = 2 becomes the next current state.
Prepared by: Dr Roopashree S, Dr. Priyanka C H, Prof Anita H K, Prof. Vidushi Dwivedi 10
Introduction to AI and Applications (25CS1ETIAA)
Fig 2.4. Rearranging the blocks h(n) = 0 and h(n) = 2- new state
Step 2. Continuing the algorithm, and rearranging the the blocks from the new current state h(n) = 2, we have 2 possible
new states
Fig 2.5. Rearranging the blocks h(n) = 2 and h(n) = 0- new possible states
In either case, h(n) evaluates to 0 ⇒ both the new states are not better than the current state with h(n) = 2 whereas the goal
state has h(n) = 4. The algorithm terminates here with a local optimum of h(n) = 2.
2: Global Heuristic Approach - uses global information i.e. considers all the blocks in the structure.
Prepared by: Dr Roopashree S, Dr. Priyanka C H, Prof Anita H K, Prof. Vidushi Dwivedi 11
Introduction to AI and Applications (25CS1ETIAA)
Applying the global heuristic rules as shown in Fig 2.5 h(n) = -6 and h(n) = +6 for initial and goal state is calculated. Fig
2.6 shows the sequence of move operators which after applied results in the goal state.
Fig 2.7 Sequence of move operators after applying the global heuristic rules results in reaching towards the goal state.
[Link]. Advantages:
● Simple to implement.
● Works well for problems where the evaluation function gives clear direction.
[Link]. Limitations:
● Can get stuck at local maxima, plateaus, or ridges where no improvement appears possible.
Constraint Satisfaction Problems (CSPs) form an important class of problems in Artificial Intelligence (AI), where the goal
is to find a solution that satisfies a given set of constraints. In such problems, a state is defined by assigning values to
variables while ensuring all constraints are met. Typical examples include cryptarithmetic puzzles, scheduling problems,
and design optimization tasks where constraints like time, cost, or materials are fixed.
A CSP can be visualized as a search problem that operates in a space of constraint sets. Initially, only the problem
constraints are known. As the solution progresses, additional constraints are discovered and propagated. The search
continues until either a consistent solution is found or an inconsistency is detected. For instance, in a cryptarithmetic puzzle
such as SEND + MORE = MONEY, each letter must represent a unique digit, and the sums of digits must match the
arithmetic rules.
Prepared by: Dr Roopashree S, Dr. Priyanka C H, Prof Anita H K, Prof. Vidushi Dwivedi 12
Introduction to AI and Applications (25CS1ETIAA)
● Map coloring (e.g., coloring countries so no two neighboring countries have the same color)
● Sudoku
CSPs are very important in AI because they represent a wide range of real-world problems that require reasoning,
planning, and optimization. Constraint satisfaction is preferred because it reduces unnecessary computation and allows
intelligent problem-solving. Instead of testing every possible combination, constraints narrow down the possible
solutions.
Prepared by: Dr Roopashree S, Dr. Priyanka C H, Prof Anita H K, Prof. Vidushi Dwivedi 13
Introduction to AI and Applications (25CS1ETIAA)
Goal:
Find a value for each variable from its domain such that all constraints are satisfied simultaneously.
Search in CSPs
To find a solution, a CSP search algorithm systematically explores combinations of variable assignments.
The process can be described as follows:
● All variables are assigned values that satisfy all constraints (success), or
● All combinations have been tried and none satisfy the constraints.
The Backtracking Search is the most fundamental and widely used algorithm for solving CSPs. It is a depth-first
search that assigns values to variables one by one.
Example:
In Sudoku, you start filling the grid cell by cell:
Prepared by: Dr Roopashree S, Dr. Priyanka C H, Prof Anita H K, Prof. Vidushi Dwivedi 14
Introduction to AI and Applications (25CS1ETIAA)
This algorithm generalizes the process of solving CSPs through constraint propagation and guessing:
Note:
The stronger the constraint propagation, the fewer guesses are required.
In Sudoku:
This is exactly how the CSP algorithm works — it combines logical deduction with trial and error.
CSP Summary
Concept Description
Variables Elements we must assign values to (e.g., letters, time slots, cells)
Domains Possible values for each variable (e.g., digits 0–9, colors)
Constraints Rules that limit valid assignments
Backtracking Systematically tries assignments, undoing invalid ones
Prepared by: Dr Roopashree S, Dr. Priyanka C H, Prof Anita H K, Prof. Vidushi Dwivedi 15
Introduction to AI and Applications (25CS1ETIAA)
Concept Description
Heuristics Smart strategies for variable/value selection
Inference Logical deduction to reduce possibilities
Goal Find an assignment that satisfies all constraints
● Flexible and applicable to many AI problems like Sudoku, map coloring, and logic puzzles.
Problem statement (brief): Each letter stands for a distinct decimal digit (0–9). Leading letters (S and M) cannot be 0.
Find digits for S,E,N,D,M,O,R,Y so that:
SEND
+MORE
-----------
MONEY
Key idea: model columns (right → left) with carry variables C1..C4 (each 0 or 1). Use arithmetic column constraints plus
the AllDifferent constraint to deduce values, propagate constraints, then finish by inference/backtracking if needed.
Step-by-step deduction
● Units: D + E = Y + 10·C1.
● Tens: N + R + C1 = E + 10·C2.
● Hundreds: E + O + C2 = N + 10·C3.
● Thousands: S + M + C3 = O + 10·C4.
Prepared by: Dr Roopashree S, Dr. Priyanka C H, Prof Anita H K, Prof. Vidushi Dwivedi 16
Introduction to AI and Applications (25CS1ETIAA)
● If C3 = 0 → O = S − 9 ⇒ only possible if S = 9 ⇒ O = 0.
Also N = E + 1, so possible (E,N) pairs from the remaining set are (2,3),(3,4),(4,5),(5,6),(6,7). Try each:
Prepared by: Dr Roopashree S, Dr. Priyanka C H, Prof Anita H K, Prof. Vidushi Dwivedi 17
Introduction to AI and Applications (25CS1ETIAA)
S = 9, E = 5, N = 6, D = 7,
M = 1, O = 0, R = 8, Y = 2
SEND = 9567
MORE = 1085
MONEY = 10652
Check: 9567 + 1085 = 10652 → correct. All letters distinct; leading digits nonzero.
1. Detect the differences between the current state and the goal state.
2. Identify an operator (action) that can reduce one or more of these differences.
3. If the operator cannot be applied immediately, a subgoal is created to satisfy its preconditions.
4. Continue this process until the current state matches the goal state.
This technique uses operator subgoaling, where subproblems are formed for each difference to make progress toward the
goal. Differences are prioritized — major differences are handled before smaller ones — making the search more efficient.
Example: Consider an example where we know the starting state and the desired state. In this issue, we must detect
differences between the beginning state and the goal state and apply operators to obtain the goal state.
To solve the problem, we will first identify the differences between starting and goal states, then construct a new state and
apply the operators to each difference. For this problem, we have the following operators:
Move
Delete
Prepared by: Dr Roopashree S, Dr. Priyanka C H, Prof Anita H K, Prof. Vidushi Dwivedi 18
Introduction to AI and Applications (25CS1ETIAA)
Expand
1. Evaluating the initial state: In the first step, evaluate the initial state and compare it to the Goal state to
see what are the differences.
2. Applying the Delete operator: As observed, the first difference is that there's no dot symbol in the Goal
state, whereas there is in the initial state, so we'll use the Delete operator to remove it.
3. Applying the Move Operator: After using the Delete operator, a new state appears, which we will
compare to the objective state again. After comparing these states, we notice that the square is outside the
circle, so we'll use the Move Operator to fix it.
4. Applying the Expand Operator: In the third phase, a new state is created, and we will compare it to the desired state.
There is still one difference between the states, which is the size of the square, so we will use the Expand operator to
construct the desired state.
Prepared by: Dr Roopashree S, Dr. Priyanka C H, Prof Anita H K, Prof. Vidushi Dwivedi 19
Introduction to AI and Applications (25CS1ETIAA)
To understand this concept practically, let us consider the Household Robot Problem, a classic example often used to
illustrate how MEA can be applied in a robotic domain. This example demonstrates how a robot can plan and execute a
series of actions to achieve a specific goal using logical reasoning.
Initial State:
Floor is dirty.
Goal State:
Floor clean.
Operators:
PickUp(Object)
PutDown(Object, Location)
Clean(Floor)
Prepared by: Dr Roopashree S, Dr. Priyanka C H, Prof Anita H K, Prof. Vidushi Dwivedi 20
Introduction to AI and Applications (25CS1ETIAA)
MEA Process:
Problem Statement
A robot is placed in a house and is given a set of tasks to perform. In this example, the robot’s task is to move a desk from
one room to another and place some objects on the desk. The robot must perform this task efficiently by reasoning about its
actions, understanding what prevents it from achieving the goal, and applying operators that can reduce these differences.
The goal state is that the desk should be placed at the desired location, and the required objects must be correctly positioned
on it. The current state is that the desk and objects are in their original locations, and the robot’s arm may or may not be
empty. The robot has a limited number of operators (actions) that it can perform, and each operator has certain preconditions
and results.
Goal:
Move a desk from one room to another.
Prepared by: Dr Roopashree S, Dr. Priyanka C H, Prof Anita H K, Prof. Vidushi Dwivedi 21
Introduction to AI and Applications (25CS1ETIAA)
In Means–Ends Analysis, the robot begins by comparing the current state and the goal state to identify differences.
In this problem:
● The goal is to have the desk at its destination location and the objects placed on the desk.
● The current state is that the desk and robot are in different rooms, and the objects are not yet on the desk.
The robot then chooses an operator that can reduce one of these differences.
The Difference Table is a vital component of the Means–Ends Analysis approach. It allows an intelligent system, such as
the household robot, to make informed decisions by linking specific differences in the problem state to relevant actions that
Prepared by: Dr Roopashree S, Dr. Priyanka C H, Prof Anita H K, Prof. Vidushi Dwivedi 22
Introduction to AI and Applications (25CS1ETIAA)
can resolve them. In the Household Robot Problem, this table enables the robot to plan its sequence of operations — from
walking to the desk, picking up objects, pushing the desk, and placing items — all while ensuring that each step
meaningfully reduces the difference toward achieving the goal state. Thus, the Difference Table is both a knowledge
representation tool and a decision-making aid, essential for efficient goal-directed problem solving in Artificial Intelligence.
When the robot encounters a difference, for example, “the object is not at the goal location”, it looks at the Difference
Table to identify which operators can handle that difference. The table indicates that both PUSH and CARRY can be used
to move an object. If the object is large, the robot applies the PUSH operator; if it is small, it uses CARRY. Similarly, when
the difference is “the robot is not near the object”, the table shows that WALK can resolve it by moving the robot to the
correct location. If the robot’s arm is not empty, PUTDOWN is the operator that reduces that difference. If the robot is not
holding an object that must be placed, PICKUP is selected.
Thus, the Difference Table provides a direct mapping between problems (differences) and solutions (operators). It
effectively guides the problem solver to select the most relevant and efficient action at each stage.
Difference Table
From this table, the robot can easily identify which operator to apply based on the current difference.
For example:
This organization of knowledge eliminates confusion and helps the system make decisions that are both goal-directed and
efficient.
Solution
Prepared by: Dr Roopashree S, Dr. Priyanka C H, Prof Anita H K, Prof. Vidushi Dwivedi 23
Introduction to AI and Applications (25CS1ETIAA)
Current State: Desk and objects are in their original positions. Robot’s arm may not be empty
Goal State: Desk is in the destination room. Objects are correctly placed on the desk
After applying WALK, the robot and desk are at the same location.
The robot pushes the desk to the target location, reducing the difference between the current and goal states.
However, the robot must be holding the object and be near the desk.
If it is not, PICKUP is used again to pick up the object, and WALK moves the robot to the desk’s new position.
The object is placed on the desk, and the robot’s arm becomes empty.
Prepared by: Dr Roopashree S, Dr. Priyanka C H, Prof Anita H K, Prof. Vidushi Dwivedi 24
Introduction to AI and Applications (25CS1ETIAA)
The Household Robot Problem effectively demonstrates how Means–Ends Analysis helps solve complex problems by
systematically reducing the differences between the current and goal states.
Instead of applying random actions, the robot uses a goal-directed reasoning process:
This method of problem solving mirrors how humans approach tasks — by first identifying obstacles and then planning
steps to remove them.
Prepared by: Dr Roopashree S, Dr. Priyanka C H, Prof Anita H K, Prof. Vidushi Dwivedi 25
Introduction to AI and Applications (25CS1ETIAA)
2.5.4. Limitations
● May become inefficient for very complex problems with many interrelated subgoals.
● Performance depends heavily on the quality of the difference table and operator definitions.
A heuristic function is adopted when a problem’s search space is very large and it becomes computationally expensive or
impractical to explore every possible solution. In Artificial Intelligence, many real-world problems such as route finding,
scheduling, and game playing involve an enormous number of possible states or paths. Searching through every state using
an exhaustive method would take excessive time and memory. To overcome this limitation, heuristics are used as intelligent
estimators or guiding functions that evaluate which paths or actions are likely to lead closer to the goal. The heuristic
function, usually denoted as h(n), estimates the “cost” or “distance” from a given state n to the goal state. It does not compute
the exact cost but provides an approximate measure to guide the search efficiently.
1. The problem space is large or complex, making it infeasible to explore all possible states.
2. There is some domain knowledge or prior experience available that can guide the search toward the goal.
3. The goal state is well-defined, and there exists a meaningful way to estimate “how far” a current state is from the
goal.
4. The problem demands a good (near-optimal) solution quickly, even if it is not guaranteed to be the absolute best.
For instance, in pathfinding problems like Google Maps navigation, heuristics such as the straight-line distance to the
destination help find efficient routes faster. In contrast, an exhaustive search approach—such as Breadth-First Search (BFS),
Depth-First Search (DFS), or Uniform Cost Search—explores every possible path or state systematically until it finds the
goal. While exhaustive methods guarantee an optimal solution, they are often computationally infeasible for large or
dynamic problems due to combinatorial explosion (the rapid growth of possibilities). Therefore, exhaustive search is best
used when:
Prepared by: Dr Roopashree S, Dr. Priyanka C H, Prof Anita H K, Prof. Vidushi Dwivedi 26
Introduction to AI and Applications (25CS1ETIAA)
Heuristic search, on the other hand, sacrifices completeness and optimality in favor of efficiency and practicality. It is
particularly useful when the environment is partially observable, complex, or when timely decisions are critical — such as
in robotics, game AI, and expert systems.
Thus, the decision to adopt a heuristic function depends on the trade-off between accuracy and efficiency. When the goal is
to achieve a good, near-optimal result quickly using limited computational resources, heuristic search is preferred. When
the goal demands the absolute best solution and the search space is small, exhaustive search may still be suitable.
Generate & Try all possible solutions Small, finite Simple; easy to Inefficient for large
Test and test each. problems. code. problems.
Constraint Assign values to satisfy all Scheduling, map Prunes invalid Complex with many
Satisfaction constraints. coloring, Sudoku. states early. interdependent constraints.
Reduce difference
Means–Ends Focused, goal- Needs defined operators
between current and goal Planning, robotics.
Analysis driven reasoning. and subgoals.
states.
Knowledge Representation (KR) is one of the fundamental areas of Artificial Intelligence concerned with how knowledge
about the world can be formally expressed, stored, and used by intelligent systems. It focuses on designing methods to
encode real-world information—facts, concepts, relationships, and processes—into a structured and symbolic format that
an AI system can interpret and reason with. Simply put, KR gives data meaning and context, allowing computers to
“understand” and manipulate information rather than just storing it.
The goal of KR is to move from raw, unorganized data to structured knowledge, much like converting a random string of
letters into a meaningful word. To achieve this, a formal representation language such as Propositional Logic (PL) or First-
Order Logic (FOL) is used to define facts, rules, and relationships about objects and events in the world. These languages
provide a clear syntax (structure) and semantics (meaning), enabling machines to represent knowledge in a precise, machine-
readable manner. Knowledge Representation, therefore, forms the foundation for reasoning and intelligent decision-making
in AI. Without a well-defined structure to represent what an AI “knows,” it cannot reason, plan, or act effectively.
Prepared by: Dr Roopashree S, Dr. Priyanka C H, Prof Anita H K, Prof. Vidushi Dwivedi 27
Introduction to AI and Applications (25CS1ETIAA)
Knowledge Representation is the cornerstone of intelligent behavior in AI systems. Just as human intelligence relies on
memory, logic, and understanding, an AI agent requires an explicit and organized representation of knowledge to simulate
human-like reasoning. The importance of KR can be summarized as follows:
Enables Reasoning and Inference: KR provides both the content (facts) and rules (logic) needed for automated
reasoning. Using logical inference methods such as deduction, an AI system can derive new facts from existing
ones. Example: If the system knows “All cats are mammals” and “Garfield is a cat,” it can logically infer “Garfield
is a mammal.” This demonstrates how knowledge representation supports intelligent reasoning.
Facilitates Problem Solving: Many AI applications—such as medical diagnosis, robotic navigation, and expert
systems—require the ability to relate objects, actions, and outcomes. KR structures this information, enabling the
system to analyze situations and choose appropriate actions. For instance, a robot that knows “if the floor is wet,
avoid moving fast” can apply this rule to prevent accidents.
Enhances Communication and Interpretation: In Natural Language Processing (NLP), AI systems must interpret
human language accurately. KR helps bridge the gap between ambiguous natural language and the precise internal
representations that computers require. It allows systems like chatbots and virtual assistants to map human questions
into logical structures and respond intelligently.
Supports Learning and Adaptation: A well-organized knowledge base allows AI systems to update and refine their
understanding as new information is received. This promotes incremental learning, where old knowledge is modified or
expanded instead of being replaced entirely. As a result, the AI becomes more adaptive and capable of handling dynamic
environments.
Humans possess intelligence not merely because they can react reflexively to stimuli, but because they have the ability to
store, represent, and reason with knowledge. What humans know helps them to understand situations, draw conclusions,
and make informed decisions. This concept forms the foundation of knowledge-based systems in AI. A knowledge-based
agent is an intelligent system that acts by reasoning over an internal representation of knowledge about the world. Instead
of responding blindly to inputs, such an agent uses stored information and logical inference to decide the most appropriate
action in a given situation.
A knowledge-based agent consists of two key components — a knowledge base (KB) and an inference mechanism. The
knowledge base is a collection of facts, rules, and representations about the world, stored in a structured form. The inference
mechanism is responsible for applying logical reasoning to the knowledge base to derive new information or to decide on
actions. These agents work in a cycle of perceive–infer–act: they perceive the environment, use inference to deduce what is
true or what should be done, and then act accordingly. Over time, they can also learn by updating their knowledge base with
new facts.
Prepared by: Dr Roopashree S, Dr. Priyanka C H, Prof Anita H K, Prof. Vidushi Dwivedi 28
Introduction to AI and Applications (25CS1ETIAA)
In the chapter, the concept of knowledge-based agents is introduced using a simple example called the Wumpus World.
This environment illustrates how an intelligent agent can survive by reasoning logically about what it perceives, even when
it lacks complete information. The Wumpus World helps to understand how an agent can use logical reasoning to infer
hidden aspects of the environment, such as the presence of danger or treasure, from indirect sensory evidence.
To formally describe and reason about such environments, AI uses logic as the mathematical foundation for knowledge
representation. Propositional logic, though less expressive than first-order logic, provides a clear and structured way to
illustrate the basic principles of logical reasoning. It allows agents to represent knowledge using propositions (statements
that can be true or false) and apply inference rules to deduce new information. More advanced agents use first-order logic,
which can represent relationships between objects and handle more complex forms of reasoning.
By integrating logical reasoning with knowledge representation, knowledge-based agents are capable of planning, learning,
and decision-making. They form the basis for intelligent systems in various domains, such as expert systems, natural
language understanding, and autonomous robotics. Understanding how these agents work provides a strong foundation for
students to explore advanced AI topics like reasoning under uncertainty, learning-based decision systems, and automated
[Link].
The knowledge base (KB) is the central component of a knowledge-based agent. It acts as the “brain” of the agent — a
structured repository of information about the world. A knowledge base consists of a set of sentences, each representing
some fact, rule, or relationship about the environment. These sentences are not in natural language (like English) but are
expressed in a Knowledge Representation Language (KRL), which allows precise and unambiguous reasoning. Each
sentence or statement in the KB is an assertion about the world, and when a sentence is assumed to be true without proof, it
is called an axiom.
A knowledge-based agent interacts with its environment by adding new knowledge and querying existing knowledge. Two
main operations are used to manage this process:
TELL: Adds new sentences (information) to the knowledge base. It represents the agent’s ability to learn or update
its understanding of the world based on its perceptions.
ASK: Queries the knowledge base to derive conclusions or make decisions. It enables the agent to reason about
what action should be taken next based on what it already knows.
Both TELL and ASK operations rely on inference, which is the process of deriving new sentences (knowledge) from existing
ones using logical rules. A valid inference ensures that whatever the system concludes must logically follow from what it
already knows; the agent must not “make things up.” This logical soundness is what distinguishes intelligent reasoning from
guesswork.
Prepared by: Dr Roopashree S, Dr. Priyanka C H, Prof Anita H K, Prof. Vidushi Dwivedi 29
Introduction to AI and Applications (25CS1ETIAA)
The agent perceives the environment through sensors and TELLs this information to the knowledge base.
It then ASKs the knowledge base to determine the best action based on the current state and accumulated
knowledge.
Finally, it TELLs the knowledge base which action was performed so that this new information becomes part of its
experience for future reasoning.
This continuous interaction allows the agent to function intelligently, making decisions not just from current perceptions
but also from previously acquired knowledge and logical deductions. Over time, the KB grows richer, enabling the agent to
handle more complex problems.
The overall design of a knowledge-based agent demonstrates the integration of knowledge representation and reasoning —
two key pillars of Artificial Intelligence. It serves as the foundation for intelligent systems such as expert systems, diagnostic
systems, and decision-making agents used in robotics and data-driven automation.
The Wumpus World is a classic example used in Artificial Intelligence to illustrate how a knowledge-based agent can make
intelligent decisions in a partially observable and uncertain environment as shown in Fig. 2.10. It is a grid-based environment
consisting of interconnected rooms or cells, representing a cave system. The world contains various elements—some
helpful, others dangerous—that the agent must detect, reason about, and act upon using its knowledge and percepts.
Fig. 2.10. A typical wumpus world. The agent is in the bottom left corner, facing right
The Wumpus World is designed as a 4×4 grid of rooms, each of which may contain one of the following:
The Wumpus – a deadly monster that eats any agent entering its room.
Bottomless pits – traps that cause instant death if the agent falls in.
Prepared by: Dr Roopashree S, Dr. Priyanka C H, Prof Anita H K, Prof. Vidushi Dwivedi 30
Introduction to AI and Applications (25CS1ETIAA)
Gold – the desirable goal that the agent must find and bring back to the starting point.
The agent starts in the lower-left corner, represented as [1,1], facing east (right). The goal of the agent is to find the gold
and return safely to the starting square while avoiding the Wumpus and pits. The agent has limited abilities and
information and must use reasoning to infer the safest actions.
In AI, environments are defined using the PEAS framework — Performance measure, Environment, Actuators, and
Sensors.
1. Performance Measure
–1000 for dying (by falling into a pit or being eaten by the Wumpus).
The game ends when the agent dies or climbs out of the cave.
2. Environment
A 4×4 grid of rooms. The Wumpus and gold are placed randomly in squares other than the starting square. Each
non-starting room can independently contain a pit with 20% probability (0.2).
The world is partially observable, as the agent can sense but not directly see hazards.
3. Actuators (Actions)
Turn Left / Turn Right – rotates the agent’s facing direction by 90°.
Prepared by: Dr Roopashree S, Dr. Priyanka C H, Prof Anita H K, Prof. Vidushi Dwivedi 31
Introduction to AI and Applications (25CS1ETIAA)
Shoot – fires an arrow straight in the current direction; it can kill the Wumpus if hit. The agent has only one
arrow.
Climb – exits the cave (only from the start position [1,1]).
If the agent enters a square with a pit or live Wumpus, it dies immediately. However, entering a square with a dead
Wumpus is safe, though smelly.
4. Sensors (Percepts)
The agent receives sensory information as a list of five percepts, each represented by a symbol:
Each percept provides one bit of information, helping the agent infer what might exist in nearby rooms.
Example: [Stench, Breeze, None, None, None] means the agent senses both a stench and a breeze, suggesting a nearby
Wumpus and pit.
The Wumpus World is a foundational problem in AI because it demonstrates how logical reasoning and knowledge
representation help agents make intelligent decisions under uncertainty. It helps to understand:
How knowledge-based reasoning (using propositional logic) can help deduce safe moves.
How intelligent behavior emerges through systematic inference rather than random guessing.
Prepared by: Dr Roopashree S, Dr. Priyanka C H, Prof Anita H K, Prof. Vidushi Dwivedi 32
Introduction to AI and Applications (25CS1ETIAA)
Propositional Logic, also known as Sentential Logic or Propositional Calculus, is one of the most fundamental and simplest
forms of logic used in Artificial Intelligence (AI). It provides a formal way to represent and reason about knowledge through
statements (propositions) that can be either true or false. Propositional logic is widely used in knowledge-based agents and
reasoning systems, particularly within environments like the Wumpus World, where agents must draw conclusions based
on limited and uncertain information.
Humans make intelligent decisions by reasoning about facts, and propositional logic captures this process through
propositions—statements that describe something about the world. For example, in the Wumpus World:
Each proposition can only have two possible truth values—True (T) or False (F).
Hence, propositional logic forms the foundation for representing knowledge in AI and performing logical inference
(deriving new truths from known facts).
The syntax of propositional logic defines how valid sentences are formed. These sentences are constructed using:
An atomic sentence consists of a single propositional symbol, such as: P, Q, R, W₁,₃, North, etc.
Each symbol represents a distinct fact or statement that can be either true or false.
For instance:
Here, W₁,₃ is treated as a single, indivisible symbol (not the combination of W, 1, and 3).
Prepared by: Dr Roopashree S, Dr. Priyanka C H, Prof Anita H K, Prof. Vidushi Dwivedi 33
Introduction to AI and Applications (25CS1ETIAA)
2. Logical Connectives
Complex sentences are formed by combining atomic sentences using logical connectives. There are five main logical
connectives in propositional logic:
¬ Negation (NOT) ¬W₁,₃ Represents “It is not the case that the Wumpus is in
[1,3].”
∧ Conjunction (AND) W₁,₃ ∧ P₃,₁ True if both W₁,₃ and P₃,₁ are true.
∨ Disjunction (OR) (W₁,₃ ∧ P₃,₁) ∨ W₂,₂ True if at least one of the disjuncts is true.
⇒ Implication (IF–THEN) (W₁,₃ ∧ P₃,₁) ⇒ Represents “If W₁,₃ and P₃,₁ are true, then W₂,₂ is
¬W₂,₂ false.”
⇔ Biconditional (IF AND ONLY W₁,₃ ⇔ ¬W₂,₂ True when both sides have the same truth value.
IF)
A literal is either an atomic sentence (positive literal) or a negated atomic sentence (negative literal). Example: W₁,₃ and
¬W₁,₃ are literals. A conjunction uses ∧ (AND) and joins multiple conditions. A disjunction uses ∨ (OR) and represents
alternative possibilities. An implication represents cause-and-effect relationships and is also known as a rule or if–then
statement. Example: “If there is a breeze, then there must be a pit nearby.” A biconditional (⇔) states that both sentences
are equivalent in truth value.
In the Wumpus World, propositional logic can represent rules that guide the agent’s reasoning:
Rule 1: If there is a breeze in [1,2], then there must be a pit in an adjacent square: B₁,₂ ⇒ (P₁,₁ ∨ P₂,₂ ∨ P₁,₃)
Rule 2: If there is no breeze in [1,1], then all adjacent squares are safe: ¬B₁,₁ ⇒ (¬P₁,₂ ∧ ¬P₂,₁)
These sentences illustrate how propositional logic allows the agent to reason about unseen dangers and plan safe moves.
Prepared by: Dr Roopashree S, Dr. Priyanka C H, Prof Anita H K, Prof. Vidushi Dwivedi 34
Introduction to AI and Applications (25CS1ETIAA)
After understanding the syntax of propositional logic—which defines how valid logical sentences are formed—the next
important concept is semantics. The semantics of propositional logic provides the rules that determine the truth or falsity of
logical sentences with respect to a particular model. In other words, semantics gives meaning to logical symbols by
specifying how their truth values are evaluated.
1. Meaning of Semantics
In propositional logic, a model represents a specific assignment of truth values (True or False) to each propositional symbol.
The truth value of a sentence is then computed based on these assignments.
Here, we have three proposition symbols, and each has been assigned a truth value. Since there are three propositions, there
can be 2³ = 8 possible models representing all possible combinations of truth assignments.
These models are mathematical structures that describe possible situations in the world. The meaning of symbols like P₁,₂
depends on how we interpret them. For example, P₁,₂ could mean “There is a pit in [1,2]” in the Wumpus World, or it could
mean “It will rain tomorrow” in another context. Hence, semantics provides a way to evaluate logical sentences
independently of their real-world meaning.
The truth value of a sentence in propositional logic is determined recursively. Since every logical sentence is built using
atomic propositions and logical connectives (¬, ∧, ∨, ⇒, ⇔), the semantics must define the truth conditions for:
Every other proposition symbol (e.g., P₁,₂) gets its truth value directly from the model.
For any two sentences P and Q, and any model m, the truth of compound statements is determined as follows:
Prepared by: Dr Roopashree S, Dr. Priyanka C H, Prof Anita H K, Prof. Vidushi Dwivedi 35
Introduction to AI and Applications (25CS1ETIAA)
P ⇔ Q (Biconditional) True iff both P and Q have the same truth value (both true or both false).
4. Truth Tables
Truth tables are a systematic way to represent the semantics of logical connectives. Each row of a truth table represents a
possible combination of truth values of propositions, and the resulting truth value of the compound sentence.
P Q ¬P P ∧ Q P ∨ Q P ⇒ Q P ⇔ Q
F F T F F T T
F T T F T T F
T F F F T F F
T T F T T T T
Example:
Step 1: ¬P₁,₂ → ¬F = T
Prepared by: Dr Roopashree S, Dr. Priyanka C H, Prof Anita H K, Prof. Vidushi Dwivedi 36
Introduction to AI and Applications (25CS1ETIAA)
Step 3: T ∧ T = T
The semantics of implication (⇒) can sometimes feel unintuitive. The statement P ⇒ Q means “If P is true, then Q must
also be true.”
It is false only when P is true and Q is false, and true in all other cases, even if P is false.
Example:
“If 5 is even, then Sam is smart.” (True in propositional logic, because the antecedent is false.)
Hence, implication does not require a causal relation between P and Q—it simply defines a logical dependency.
The biconditional (⇔) represents “if and only if,” meaning both statements must always share the same truth value.
Here, B₁,₁ means there is a breeze in room [1,1]. This biconditional statement captures both directions of logical
dependence—
6. Exclusive OR (XOR)
In addition to the standard connectives, there is also the exclusive OR (XOR), denoted as ⊕.
In exclusive OR, the result is True only when one of the two statements is true, but not both. This differs from the normal
disjunction (∨), which is true even if both are true.
Prepared by: Dr Roopashree S, Dr. Priyanka C H, Prof Anita H K, Prof. Vidushi Dwivedi 37
Introduction to AI and Applications (25CS1ETIAA)
Once the semantics of propositional logic are clearly defined, we can apply them to build a knowledge base (KB) for an
artificial intelligence agent operating in the Wumpus World. A knowledge base is a collection of logical sentences that
describe what the agent knows about its environment. Each sentence in the KB is expressed in propositional logic, using
symbols to represent facts and logical relationships between those facts.
In the Wumpus World, each room in the cave is represented by its coordinates [𝑥,𝑦], and a set of propositional symbols is
used to describe what might be true in each room. For every grid cell, we define the following symbols:
Each of these symbols represents an atomic proposition, and logical sentences involving these symbols describe the
relationships and constraints of the world.
The goal of the knowledge base is to help the agent reason logically about what it perceives (through sensors like breeze or
stench) and make safe decisions—for example, determining which adjacent rooms are safe to move into. The agent achieves
this by using inference, that is, deriving new knowledge (new sentences) from the existing knowledge base.
To illustrate this, we can construct a small knowledge base that captures the immutable rules of the Wumpus World — those
facts that always hold true regardless of the agent’s movements. These rules form the foundation for logical reasoning.
Each rule is represented as a propositional sentence, labeled R₁, R₂, R₃, etc., for easy reference.
The agent always begins in a safe position, so there cannot be a pit in cell [1,1].
Hence, the first rule is:
R₁: ¬P₁,₁
This means “There is no pit in [1,1].”
R₂: Relationship between breeze and neighboring pits (for square [1,1])
A square is breezy if and only if there is a pit in one of its adjacent squares. This relation is represented using the
biconditional (⇔) operator.
For the square [1,1]:
R₂: B₁,₁ ⇔ (P₁,₂ ∨ P₂,₁)
Prepared by: Dr Roopashree S, Dr. Priyanka C H, Prof Anita H K, Prof. Vidushi Dwivedi 38
Introduction to AI and Applications (25CS1ETIAA)
This means: “There will be a breeze in [1,1] if and only if there is a pit either in [1,2] or [2,1].”
The use of the biconditional ensures the relation works both ways — if a breeze exists, there must be a pit nearby, and if
there is a pit nearby, there will be a breeze in the current square.
Similarly, for square [2,1], the breeze depends on the existence of pits in any of its neighboring squares:
R₃: B₂,₁ ⇔ (P₁,₁ ∨ P₂,₂ ∨ P₃,₁)
This rule means: “There will be a breeze in [2,1] if and only if there is a pit in [1,1], [2,2], or [3,1].”
While R₁–R₃ represent general rules that hold for all possible Wumpus Worlds, the next two sentences represent the specific
percepts that the agent actually experiences during its exploration.
Using these rules, the agent can infer new information. For example:
2. From R₂ and R₄, since B₁,₁ is false, we conclude that both P₁,₂ and P₂,₁ must be false.
¬B₁,₁ ⇒ ¬(P₁,₂ ∨ P₂,₁)
Therefore:
¬P₁,₂ ∧ ¬P₂,₁
Meaning there are no pits in [1,2] and [2,1].
This simple inference shows how propositional logic helps an AI agent deduce safe squares to move into using logical
reasoning, rather than random exploration.
Prepared by: Dr Roopashree S, Dr. Priyanka C H, Prof Anita H K, Prof. Vidushi Dwivedi 39
Introduction to AI and Applications (25CS1ETIAA)
R₃ B₂,₁ ⇔ (P₁,₁ ∨ P₂,₂ ∨ P₃,₁) Breeze in [2,1] ↔ Pit in one of its neighboring squares
This example demonstrates how a knowledge-based agent builds and updates its knowledge base using logic.
In artificial intelligence, one of the most fundamental reasoning tasks for a knowledge-based agent is inference — the
process of determining whether a particular sentence (called a query) logically follows from a given Knowledge Base (KB).
This relationship is written as KB ⊨ α, which is read as “KB entails α”.
In simple terms, this means that the sentence α must be true in every situation (model) in which all the sentences of the KB
are true. The inference procedure helps an intelligent agent verify this logical relationship and make rational decisions based
on what it knows.
To test whether KB ⊨ α, a straightforward approach is to use a model-checking method. A model represents one possible
configuration of truth values (True or False) assigned to all the propositional symbols in the knowledge base.
If there are n symbols in total, there can be 2ⁿ possible models, because each symbol can independently take one of two
truth values.
1. Enumerate all possible models – For each model, assign truth values (True/False) to all propositional symbols.
Prepared by: Dr Roopashree S, Dr. Priyanka C H, Prof Anita H K, Prof. Vidushi Dwivedi 40
Introduction to AI and Applications (25CS1ETIAA)
In the Wumpus World, the agent’s knowledge base (KB) includes logical sentences such as:
R₄: ¬B₁,₁
R₅: B₂,₁
We now want to check whether the knowledge base entails the sentence:
α = ¬P₁,₂ (i.e., there is no pit in [1,2]).
To do this, we construct a truth table containing all possible combinations of truth values for the relevant symbols:
B₁,₁, B₂,₁, P₁,₁, P₁,₂, P₂,₁, P₂,₂, P₃,₁.
However, in these same 3 models, P₂,₂ is true in two models and false in one.
Thus, the agent cannot determine whether a pit exists in [2,2]; the available knowledge is insufficient for that conclusion.
Prepared by: Dr Roopashree S, Dr. Priyanka C H, Prof Anita H K, Prof. Vidushi Dwivedi 41
Introduction to AI and Applications (25CS1ETIAA)
This kind of reasoning demonstrates how a knowledge-based agent makes logical inferences by evaluating all possible
worlds that are consistent with its knowledge base.
In Artificial Intelligence, logic-based knowledge representation allows an intelligent agent to reason about the world and
make informed decisions. Learnt on how a knowledge-based agent uses Propositional Logic (PL) to represent facts and
deduce actions based on those facts. Propositional Logic served as a useful foundation to introduce the basic principles of
logical reasoning, inference, and knowledge-based systems. However, Propositional Logic is limited in its expressive
power—it can represent only specific, fixed facts about the world but cannot easily describe general relationships,
objects, or their properties. For instance, while PL can express “Socrates is mortal,” it cannot represent the general
rule “All humans are mortal” that applies to many individuals.
To overcome these limitations, Artificial Intelligence uses First-Order Logic (FOL), also known as Predicate Logic or First-
Order Predicate Calculus (FOPC). FOL extends Propositional Logic by introducing quantifiers and predicates, which
make it more expressive and capable of representing a large amount of commonsense and relational knowledge. In
FOL, objects, their relationships, and their properties can be described using variables and functions.
For example, the statement “All humans are mortal” can be represented as:
∀x (Human(x) → Mortal(x))
which means “For all x, if x is a human, then x is mortal.” This concise representation shows how FOL can generalize
statements that would require many individual propositions in Propositional Logic.
In Artificial Intelligence, First-Order Logic (FOL) provides a powerful framework to represent knowledge about the real
world using objects, their properties, and relationships. To understand how FOL works, let’s explore its syntax (the
structure and symbols used to form sentences) and semantics (the meaning and interpretation of those sentences in possible
worlds or models). A model in logic represents a possible world that defines what is true or false.
Prepared by: Dr Roopashree S, Dr. Priyanka C H, Prof Anita H K, Prof. Vidushi Dwivedi 42
Introduction to AI and Applications (25CS1ETIAA)
In Propositional Logic, models only map proposition symbols (like P or Q) to truth values (True or False). However, in
First-Order Logic, models are richer—they consist of objects, relations, and functions that describe how entities interact in
a particular world.
The domain of a model is the set of all objects or domain elements that exist in that world. Every model in FOL must have
at least one object (i.e., the domain is non-empty). For example, consider a simple world that contains the following five
objects as shown in Fig. 2.11.
A crown
Fig.2.11. A model containing five objects, two binary relations, three unary relations (indicated by labels on the objects),
and one unary function, left-leg.
These objects can have relations among them, which define how they are connected. For instance, the brother relation
connects Richard and John, represented as a set of tuples—ordered pairs of related objects. A tuple ⟨Richard, John⟩ means
“Richard is the brother of John,” while ⟨John, Richard⟩ means “John is the brother of Richard.” Similarly, the on-head
relation connects the crown with King John, indicating that the crown is on John’s head.
Unary relations (properties): True for one object (e.g., Person(Richard), King(John), Crown(crown)).
Prepared by: Dr Roopashree S, Dr. Priyanka C H, Prof Anita H K, Prof. Vidushi Dwivedi 43
Introduction to AI and Applications (25CS1ETIAA)
Binary relations: Involve two objects (e.g., Brother(Richard, John), OnHead(crown, John)).
3. Functions in FOL map objects to other objects in a consistent way. A function is a special kind of relationship
where each input has exactly one output. For example, the left_leg function may map:
Such a function is called a unary function because it takes one input. In formal terms, FOL requires total functions,
meaning every object must have a value for that function. However, in real scenarios, some objects (like a crown) may not
have a left leg. In such cases, an “invisible” or placeholder object can be assumed to satisfy the totality requirement.
These components together define the structure of the logical world. The meaning—or semantics—of any sentence in FOL
is determined by how its symbols correspond to the elements, relations, and functions of a model. Therefore, understanding
FOL models helps an intelligent agent interpret and reason about the real world systematically.
In First-Order Logic (FOL), the syntax defines the structure and symbols used to represent knowledge about objects,
their relationships, and the functions that connect them. While propositional logic could only describe entire facts as
true or false, FOL allows us to express statements about individual objects and relations between them, making it far
more expressive and suitable for real-world reasoning. The basic building blocks of FOL are symbols, which are divided
into three categories:
2. Predicate Symbols: These denote relations or properties among objects. They can take one or more arguments,
depending on their arity (number of arguments).
Example –
Prepared by: Dr Roopashree S, Dr. Priyanka C H, Prof Anita H K, Prof. Vidushi Dwivedi 44
Introduction to AI and Applications (25CS1ETIAA)
3. Function Symbols: These represent functional relationships that map objects to other objects. Each function also
has a fixed arity.
Example –
In First-Order Logic (FOL), the semantics defines how symbols and expressions correspond to the objects, relations,
and functions in the real or imagined world (model). Understanding semantics helps an AI system interpret logical
sentences in a meaningful way.
1. Terms
A term in FOL is a symbolic expression that refers to an object in the domain of a model. It serves as the basic unit of
reference for entities that exist in the world being represented. There are two main kinds of terms:
Constant Terms: These directly name specific objects. Each constant symbol refers to one fixed object in the
model.
Example: John, Richard, Crown
Complex Terms: These are expressions built using function symbols that relate objects to other objects. Function
symbols help describe relationships without naming every object separately.
Example: LeftLeg(John) refers to King John’s left leg.
In general, a complex term has the form: f(t₁, t₂, …, tₙ) where f is a function symbol, and t₁…tₙ are argument
terms.
It is important to note that a function term in FOL is not a subroutine or executable operation, as in programming. It
merely represents a symbolic reference, not a computed value. For instance, LeftLeg(John) does not “compute” anything
but simply refers to the object denoted as John’s left leg in the model.
2. Atomic Sentences
Once we can refer to objects using terms, we can express facts about these objects using atomic sentences. An atomic
sentence (or atom) is the simplest type of statement in FOL that can be either true or false. It is formed by
combining a predicate symbol with one or more terms as arguments.
Example:
Prepared by: Dr Roopashree S, Dr. Priyanka C H, Prof Anita H K, Prof. Vidushi Dwivedi 45
Introduction to AI and Applications (25CS1ETIAA)
3. Complex Sentences
Complex sentences are built by combining atomic sentences using logical connectives, following the same principles as
propositional logic. These include:
¬ (NOT), ∧ (AND), ∨ (OR), ⇒ (IMPLIES), and ⇔ (IF AND ONLY IF).
Summary:
Atomic Sentence States a fact using predicates and terms. Brother(Richard, John)
4. Quantifiers
In First-Order Logic (FOL), quantifiers are special symbols that allow us to express statements about sets or collections
of objects without naming each object individually. While propositional logic can only handle specific, fixed facts,
quantifiers give FOL the expressive power to describe general statements such as “All humans are mortal” or “There exists
a student who scored full marks.” FOL uses two standard quantifiers — the Universal Quantifier (∀) and the
Existential Quantifier (∃) — which together enable reasoning about all or some members of a domain.
Prepared by: Dr Roopashree S, Dr. Priyanka C H, Prof Anita H K, Prof. Vidushi Dwivedi 46
Introduction to AI and Applications (25CS1ETIAA)
The Universal Quantifier (∀) is used to express that a statement holds true for every object in the domain of
discourse. It is symbolized by the upside-down capital letter A (∀), which means “for all” or “for every.”
Syntax: ∀x P(x)
This reads as “For all x, P(x) is true.”
This means that for every object x, if x is a king, then x must also be a person.
Semantics (Meaning):
The universally quantified statement ∀x P(x) is true in a model if P(x) is true for every possible value of x in the domain.
The Existential Quantifier (∃) is used to express that there exists at least one object in the domain for which a given
property holds. The symbol (∃) is read as “there exists” or “for some.”
Syntax: ∃x P(x)
This reads as “There exists an x such that P(x) is true.”
This means there exists some object x such that x is a crown and x is on John’s head.
Semantics (Meaning):
The statement ∃x P(x) is true if there is at least one object in the model for which P(x) holds true.
Just as ⇒ works naturally with ∀, the and (∧) operator works naturally with ∃.
With ∀: Implication (⇒) ensures that the statement applies only to objects satisfying the condition.
With ∃: Conjunction (∧) connects the properties that must hold simultaneously for at least one object.
Summary
Prepared by: Dr Roopashree S, Dr. Priyanka C H, Prof Anita H K, Prof. Vidushi Dwivedi 47
Introduction to AI and Applications (25CS1ETIAA)
In addition to predicates, FOL allows us to express equality between two terms using the = symbol. Equality statements
are used to indicate that two different expressions refer to the same object in the domain.
Example:
The equality operator helps in defining relationships and comparisons between terms. Its negation, written as ¬(x = y) or
simply x ≠ y, states that the two terms refer to different objects.
Once the syntax and semantics of First-Order Logic (FOL) are understood, the next step is learning how to use this logic to
represent real-world knowledge. In Artificial Intelligence, FOL serves as a powerful representation language that allows us
to describe the structure of a world (called a domain) and express relationships, properties, and general rules about it in a
logical and systematic manner. A domain refers to a specific area or part of the real world about which we want to represent
and reason. It consists of the objects, entities, and relationships that are relevant to a given problem or environment. For
instance, if we are modeling a medical domain, the objects may include patients, doctors, diseases, and medicines, while
the relationships might describe which doctor treats which patient, or which medicine cures which disease. Similarly, in a
robotics domain, objects can be robots, locations, and objects to be moved; relationships can represent actions like “move,”
“pick,” and “place.”
Prepared by: Dr Roopashree S, Dr. Priyanka C H, Prof Anita H K, Prof. Vidushi Dwivedi 48
Introduction to AI and Applications (25CS1ETIAA)
By systematically defining these components, FOL allows an AI system to infer new knowledge automatically through
reasoning processes such as unification and inference.
The Wumpus World is a classic example used in Artificial Intelligence to demonstrate how agents can reason
logically in an uncertain environment. In this domain, a logical agent must represent knowledge about the world and
use reasoning to make intelligent decisions. First-Order Logic (FOL) offers a more expressive and compact representation
of the Wumpus World than Propositional Logic, enabling generalization across space and time.
In the Wumpus World, the agent receives a percept vector consisting of five elements: [Stench, Breeze, Glitter, Bump,
Scream]. Each percept occurs at a specific time step, represented as an integer.
For example:
Percept([Stench, Breeze, Glitter, None, None], 5) indicates that at time t = 5, the agent sensed a stench, a breeze, and
glitter.
Here, Percept is a binary predicate linking the percept list with the time step.
Percepts are converted into logical facts using quantified rules, for example:
These rules map percepts to logical facts in the KB, forming the basis of perception reasoning.
A simple reflex rule can then be added: ∀t Glitter(t) ⇒ BestAction(Grab, t)
→ If the agent perceives glitter at any time t, it should perform Grab.
Objects and relationships in the Wumpus World include squares, pits, and the Wumpus.
Instead of naming every square individually (like Square1,2), we represent locations as ordered pairs [x, y].
Prepared by: Dr Roopashree S, Dr. Priyanka C H, Prof Anita H K, Prof. Vidushi Dwivedi 49
Introduction to AI and Applications (25CS1ETIAA)
The agent can infer environmental properties from its percepts, for example:
∀s, t At(Agent, s, t) ∧ Breeze(t) ⇒ Breezy(s) → If the agent perceives a breeze while at square s, then that square is
breezy. The breezy property is time-independent since pits don’t move over time.
Instead of writing separate rules for each square as in propositional logic, FOL uses a single quantified axiom:
∀s Breezy(s) ⇔ ∃r Adjacent(r, s) ∧ Pit(r) → A square is breezy if and only if at least one of its adjacent squares has a
pit.
Prepared by: Dr Roopashree S, Dr. Priyanka C H, Prof Anita H K, Prof. Vidushi Dwivedi 50
Introduction to AI and Applications (25CS1ETIAA)
References
1. Stuart Russell and Peter Norvig, Artificial Intelligence: A Modern Approach (4th Edition), Pearson Education, 2023.
2. Elaine Rich, Kevin Knight, and Shivashankar B. Nair, Artificial Intelligence, McGraw Hill Education.
Summary
● In complex cases, it is combined with heuristics, constraint satisfaction, or optimization techniques to improve
efficiency.
● Constraint Satisfaction is an intelligent search technique that relies on constraints rather than blind search to
reach a solution. By systematically propagating and strengthening constraints, AI systems can solve complex
combinatorial problems efficiently.
● CSPs represent problems as variables + constraints, making them structured and efficient to solve.
● Backtracking search forms the foundation, and adding heuristics and inference dramatically improves
performance.
● Real-world problems such as Sudoku, scheduling, map coloring, and logic puzzles can be elegantly expressed and
solved as CSPs.
● The stronger the constraint propagation, the fewer guesses are needed — leading to faster, more accurate
solutions.
● Means–Ends Analysis is a heuristic problem-solving technique that detects differences between the current and
goal states, selects an operator to reduce the difference, and recursively applies the same method until the goal is
reached.
● Heuristic functions are adopted when the problem domain is large, real-time performance is required, and
approximate reasoning is acceptable. By integrating domain knowledge into the search process, heuristics enable
intelligent agents to solve problems more like humans — efficiently, adaptively, and purposefully. On the other
hand, exhaustive search remains valuable for smaller or critical systems where completeness and precision are
more important than speed.
● Heuristic methods are intelligent problem-solving techniques that use prior knowledge to guide the search process
efficiently.
Prepared by: Dr Roopashree S, Dr. Priyanka C H, Prof Anita H K, Prof. Vidushi Dwivedi 51
Introduction to AI and Applications (25CS1ETIAA)
● They are essential for real-world AI applications where optimal search is impractical due to time or resource
limits.
● Understanding the differences among heuristic strategies helps in selecting the right method for a given problem
type.
● Generate & Test: “Try and check if it works.”; Hill Climbing: “Keep improving until no better option remains.”;
Constraint Satisfaction: “Follow the rules and eliminate impossible cases.”; Means–Ends Analysis: “Plan actions
to reduce the gap between now and the goal.”
● Knowledge Representation serves as the backbone of Artificial Intelligence, enabling machines to store
knowledge in a meaningful way and apply logical reasoning to solve problems, learn from experience, and
communicate intelligently. Effective KR transforms static data into actionable knowledge, forming the bridge
between data processing and true understanding.
● Knowledge-Based Agent: An AI system that uses stored knowledge and reasoning to act intelligently.
● Logical Foundation: Based on Propositional Logic and First-Order Logic for knowledge representation and
inference.
● Knowledge Base (KB): Central store of facts and rules expressed in a Knowledge Representation Language.
● Sentence: A statement about the world; may also be an axiom if accepted as true without proof.
● Inference: Logical reasoning process to derive new knowledge from existing facts.
● Cycle of Operation: Perceive → TELL (add perception to KB); ASK (decide next action); TELL (record chosen
action)
Prepared by: Dr Roopashree S, Dr. Priyanka C H, Prof Anita H K, Prof. Vidushi Dwivedi 52
Introduction to AI and Applications (25CS1ETIAA)
● Agents must combine perceptual input and logical inference to act safely.
● The PEAS model is essential for designing and evaluating intelligent agents.
● It serves as a foundation for studying propositional logic, inference, and planning in AI.
● Propositional logic is the foundation of knowledge representation and reasoning in AI. It enables an agent to:
● Through propositional logic, AI systems can emulate human-like reasoning—deriving conclusions, detecting
contradictions, and deciding actions based on logical analysis.
● Entailment (⊨): Sentence α is true in every model where KB is true. Model: Assignment of truth values to all
proposition symbols.
● Quantifiers make First-Order Logic a powerful tool for knowledge representation and reasoning in Artificial
Intelligence. They enable: Compact representation of general rules (e.g., “All birds can fly”); Expression of specific
existence claims (e.g., “There exists a bird that cannot fly”); Logical inference over objects and relations, allowing
AI systems to deduce new knowledge efficiently.
● Understanding quantifiers and equality is fundamental in AI reasoning systems because: They allow generalization
over sets of objects instead of individual facts; Enable the representation of relationships and hierarchies (e.g., “All
humans are mortal”); Support logical inference, allowing AI to deduce new facts about entities in a knowledge base;
Form the foundation for semantic networks, ontologies, and logic programming languages like Prolog.
Prepared by: Dr Roopashree S, Dr. Priyanka C H, Prof Anita H K, Prof. Vidushi Dwivedi 53
Introduction to AI and Applications (25CS1ETIAA)
● The domain forms the backbone of any knowledge-based system in AI. By clearly defining the elements of the
domain and their interrelations, we enable logical reasoning that mimics human intelligence. The same approach
can be scaled to larger domains such as medicine, law, or natural language understanding. Thus, using FOL to
represent domains bridges human conceptual understanding with machine reasoning, making it possible to automate
complex problem-solving through formal logic.
Prepared by: Dr Roopashree S, Dr. Priyanka C H, Prof Anita H K, Prof. Vidushi Dwivedi 54
Propositional logic is limited in expressing general rules or relationships because it can only represent specific, fixed facts; more expressive systems like First-Order Logic are needed for complex AI systems .
The exclusive OR (XOR) returns true only when one of the two statements is true, but not both, whereas normal disjunction (∨) returns true if at least one statement is true, including when both are true .
Heuristic functions act as intelligent estimators that guide AI search strategies by evaluating paths likely to lead closer to the goal, thus enhancing efficiency by reducing the need to explore all possible states exhaustively .
A key limitation of the Hill Climbing algorithm is that it does not maintain a memory of previous states, which can cause it to get "stuck" on local maxima or plateaus without finding a global solution .
A well-organized knowledge base allows AI systems to update and refine their understanding incrementally as new information is received, promoting learning by modifying existing knowledge rather than replacing it entirely .
Exhaustive search methods are preferable when the search space is small and well-defined, computation time is not an issue, and an exact or optimal solution is required .
Propositional logic serves as a foundational basis by providing a structured way to represent and reason using propositions, which can be expanded into more expressive systems like First-Order Logic (FOL) that handle relationships and generalized inferences .
First-Order Logic (FOL) strengths include the ability to describe complex environments, reason about multiple entities, support generalized inference, and serve as a foundation for advanced knowledge representation techniques due to its expressive power and mathematical rigor .
Hill Climbing algorithms are suitable for optimization problems because they efficiently use heuristics to iteratively improve current states towards an optimal solution, especially when a good heuristic function is available to evaluate the quality of states .
The heuristic function in Simple Hill Climbing provides guidance by estimating how close a state is to the goal, allowing the algorithm to move towards more promising directions, whereas the Generate-and-Test method lacks this guiding function and merely tests generated solutions for correctness .