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

Module 5 Notes

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views

Module 5 Notes

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 13

Backward Chaining is a popular inference technique used in logic programming and automated

theorem proving. It is commonly used in expert systems, such as Prolog, and is a form of goal-
driven reasoning where the search for a solution begins from the goal and works backwards through
the logic to determine what facts or conditions need to be true.

1. What is Backward Chaining?


Backward chaining is a goal-driven search strategy that begins with a goal (query) and tries to find
rules that can lead to the goal by recursively working backwards, until the base facts are reached.

• Goal-driven: Instead of starting from known facts and applying rules forward, backward
chaining starts with the goal and attempts to find the premises (facts) that will make the goal
true.
• Recursive: It works by recursively decomposing a goal into sub-goals (i.e., finding rules
whose conclusions match the goal and then trying to satisfy the preconditions of those
rules).

2. How Does Backward Chaining Work?


The backward chaining process follows these steps:
1. Start with the Goal:

• The goal (or query) is the target fact that we are trying to prove. The system tries to
prove the goal by searching for supporting facts or rules.
2. Find a Rule to Support the Goal:

• If the goal matches the conclusion of a rule, the system looks at the preconditions
(the body) of the rule.
• For example, if the goal is Criminal(West) and there is a rule
Criminal(x) :- Enemy(x, America), the system will attempt to prove
Enemy(West, America).
3. Break Down Sub-goals:

• Each precondition of the rule becomes a sub-goal. The system then recursively tries
to prove these sub-goals.
• For instance, to prove Enemy(West, America), the system will check for facts
or rules that support Enemy(x, y) for x = West and y = America.
4. Base Facts:

• If a sub-goal is a fact that is already known (i.e., a fact in the knowledge base), the
goal is satisfied.
• If not, the system continues searching for more rules that can help prove the sub-
goal.
5. Repeat Until Goal is Proven:

• This process continues until all the sub-goals are either known facts or can be
derived from the rules. If the goal can be proven through this process, backward
chaining succeeds. If no valid path is found, it fails.
3. Example of Backward Chaining
Consider a simple rule-based system with the following rules:
1. Criminal(x) :- Enemy(x, America) (If x is an enemy of America, then x is a
criminal.)
2. Enemy(West, America) (West is an enemy of America.)

Goal: Criminal(West)

• The goal is Criminal(West).


• Using the first rule, we see that Criminal(West) is true if Enemy(West, America)
is true.
• Now, we need to prove Enemy(West, America).
• The second rule tells us that Enemy(West, America) is already a fact, so we can
conclude that Criminal(West) is true.

4. Features of Backward Chaining


• Top-Down Approach: Starts with the goal and tries to prove it by working backwards.
• Recursive: Sub-goals are generated based on the rules that match the goal, and the process
continues until either a fact is found or the sub-goals cannot be proved.
• Goal-Directed: It’s efficient because it only focuses on proving what is necessary (the goal
and sub-goals), rather than exploring all possible facts in the system.

5. Advantages of Backward Chaining


• Efficiency: Because it is goal-directed, backward chaining only works on the specific facts
needed to prove the goal, avoiding unnecessary exploration of irrelevant information.
• Memory Efficient: Backward chaining does not need to store all states in memory (unlike
forward chaining). It only needs to keep track of the current goal and sub-goals.
• Useful for Query-Based Systems: It is well-suited for environments where queries are
made about specific facts (e.g., expert systems like Prolog).

6. Disadvantages of Backward Chaining


• Can Lead to Redundant Computations: If the same goal is derived multiple times (due to
recursive calls), the system may recompute it unnecessarily unless memoization is used to
cache results.
• Risk of Infinite Loops: If the knowledge base has cyclic dependencies, backward chaining
can get stuck in infinite loops. For example, if a rule's precondition depends on the
conclusion of another rule that, in turn, depends on the first rule.
• Non-Optimal in Large Knowledge Bases: In large knowledge bases with many rules and
facts, backward chaining can become inefficient unless combined with good strategies (such
as restricting the search space or using heuristics).
7. Memoization in Backward Chaining
• Memoization is a technique used to avoid redundant computations by storing the results of
sub-goals once they are computed. In backward chaining, this technique prevents the system
from recalculating the same sub-goals multiple times.

8. Backward Chaining vs. Forward Chaining


Aspect Backward Chaining Forward Chaining
Starts with the goal and works Starts with known facts and applies rules to
Start Point
backward to find facts. infer new facts.
Search
Goal-driven search. Data-driven search.
Type
More efficient when only specific Can be inefficient as it generates all possible
Efficiency
goals are needed. facts.
Used in query-based systems like Used in systems where the full set of
Use Case
Prolog. conclusions needs to be generated.

9. Use of Backward Chaining in Logic Programming


• Prolog: One of the most famous applications of backward chaining is in Prolog, a logic
programming language. Prolog uses backward chaining to search through a set of facts and
rules to answer queries.

10. Practical Applications


• Expert Systems: Backward chaining is widely used in expert systems, where an inference
engine needs to answer specific queries based on a set of rules and facts.
• Debugging: In software or hardware debugging, backward chaining can help trace the
causes of errors by working backwards from the point of failure to find the root cause.
• Natural Language Processing (NLP): In NLP, backward chaining can be used to derive the
meaning of sentences or to parse linguistic structures.

Resolution in First-Order Logic


Resolution is a key inference rule used in logic and artificial intelligence, particularly in automated
theorem proving. It is a powerful method for deducing conclusions from a set of logical clauses.
Resolution works by deriving a new clause from two clauses that contain complementary literals
(i.e., one literal and its negation).

1. What is Resolution?
Resolution is a refutation-based inference rule used to prove the unsatisfiability of a set of logical
sentences by deriving a contradiction. If a contradiction can be derived, the original set of sentences
is inconsistent, and the negation of the goal is unsatisfiable.
Resolution operates on conjunctive normal form (CNF), where sentences are expressed as a
conjunction of disjunctions (i.e., a conjunction of clauses, where each clause is a disjunction of
literals). The rule of resolution is applied to pairs of clauses that contain complementary literals.
2. Resolution Rule
Given two clauses:

• Clause 1: A∨B
• Clause 2: ¬A∨C
Where A is a literal and ¬A is its negation, the resolution of these two clauses results in a new
clause:

• Resolved Clause: B∨C


This works because A and ¬A "cancel out" (they are complementary), leaving the remaining literals
B and C.

3. General Resolution Process


1. Identify Complementary Literals: Find two clauses where one contains a literal L and the
other contains its negation ¬L.
2. Merge the Remaining Literals: After eliminating the complementary literals, combine the
remaining literals from the two clauses into a new clause.
3. Repeat: The process continues iteratively until either:
• A contradiction (empty clause) is derived, proving the set is unsatisfiable.
• No new clauses can be generated, indicating that the set is satisfiable.

4. Examples of Resolution
Consider the following clauses:

• Clause 1: P∨Q
• Clause 2: ¬P∨R
Resolution would work as follows:

• P and ¬P are complementary.


• The resolved clause would be: Q∨R.
If more clauses are involved, the resolution continues until no new clauses can be generated, or an
empty clause (indicating a contradiction) is produced.

5. Unification in Resolution
In First-Order Logic, resolution requires unification. Unification is the process of making two
terms identical by substituting variables with terms. For example, in the resolution of the clauses:

• Clause 1: P(x)∨Q(y)
• Clause 2: ¬P(a)∨R(b)
We would unify P(x) with ¬P(a) by substituting x=a, resulting in:

• Clause 1 becomes Q(y)


• Clause 2 becomes R(b)
After unification, the resolved clause is Q(y)∨R(b).
6. Completeness of Resolution
Resolution is complete for propositional logic and First-Order Logic under certain conditions,
meaning that if a set of clauses is unsatisfiable (i.e., no model satisfies all the clauses), then
resolution will eventually derive an empty clause. This makes it a powerful tool in automated
reasoning and theorem proving.

7. Resolution in First-Order Logic


In First-Order Logic (FOL), resolution extends to work with predicates and variables, not just
propositional symbols. This makes resolution more complex but also more powerful because it can
handle more expressive logical sentences.

• Unification becomes more complex in FOL due to the need to unify predicates and terms,
such as P(x) and P(a).
• The resolution process involves unifying predicates and applying the resolution rule to
produce new clauses, which is repeated until a contradiction is found or no further resolution
is possible.

8. Example of Resolution in First-Order Logic


Given the following set of clauses:

• ¬P(x)∨Q(x)
• P(a)
• ¬Q(a)
Resolution works as follows:
1. Resolve P(a) with ¬P(x)∨Q(x), resulting in Q(a).
2. Resolve Q(a) with ¬Q(a), resulting in the empty clause, indicating a contradiction.
Thus, the set of clauses is unsatisfiable.

9. Applications of Resolution
• Automated Theorem Proving: Resolution is a fundamental technique in many automated
theorem proving systems.
• Logic Programming: Languages like Prolog use resolution as their primary inference
mechanism.
• AI and Knowledge Representation: Resolution is used to derive new facts from existing
knowledge in expert systems and knowledge-based systems.

10. Limitations of Resolution


• Computational Complexity: Resolution can be computationally expensive, particularly in
First-Order Logic, due to the need for unification and the combinatorial explosion of
possible resolutions.
• Non-Intuitive: Finding a resolution path can sometimes be difficult, as it requires iterating
over many possible clauses and resolutions.
Classical Planning refers to the process of generating a sequence of actions (or a plan) that moves
an agent from an initial state to a goal state. It is a formalized problem-solving technique that
assumes a deterministic, fully observable environment where the effects of actions are known and
predictable.

Key Features of Classical Planning:


1. State-Space Representation:
• The world is modeled as a set of states, and the goal is to find a path from the initial
state to a goal state by applying actions.
2. Actions and Preconditions:
• Each action has preconditions (states that must be true before the action can be
executed) and effects (states that will be true after the action is executed).
3. Deterministic and Observable:
• The outcomes of actions are fully predictable (deterministic), and the agent has full
knowledge of the current state of the environment (fully observable).
4. Discrete Time:
• Time progresses in discrete steps, with each step corresponding to the execution of
an action that transitions the system from one state to another.
5. Goal-Oriented:
• The primary objective in classical planning is to reach a specified goal state, which is
a set of conditions the agent aims to satisfy.

Planning as a State-Space Search:


Classical planning can be viewed as a search problem:

• The state represents the current situation of the world.


• The actions are the possible transitions between states.
• The goal is a set of conditions that must be satisfied in the final state.
• The plan is the sequence of actions that takes the agent from the initial state to a state that
satisfies the goal.

Types of Algorithms:
• Forward Search: Starting from the initial state, explore the state space by applying actions
until a goal state is reached.
• Backward Search: Starting from the goal, work backward to find a sequence of actions that
lead to the initial state.
• Heuristic Search: Incorporates heuristics to guide the search process more efficiently by
evaluating the cost of reaching the goal from any given state.
Classical planning methods, while efficient for some domains, struggle in environments that are
non-deterministic, partially observable, or dynamic.

(Ref to the example problems solved in the class)


Algorithms for Planning as State-Space Search
In classical planning, problems are often formulated as state-space search problems, where the task
is to find a sequence of actions (a plan) that transforms the initial state into a goal state. Various
algorithms can be used to search this state space. These algorithms are crucial for solving planning
problems in AI, such as robotic control, automated scheduling, and other domains that require a
sequence of actions to achieve a goal.

1. State-Space Representation in Planning


• State: Represents a configuration of the world. The state contains all relevant information
that describes the situation at a particular point in time.

• Actions: Actions or operators are the transitions between states. Each action has:

• Preconditions: The conditions that must be true before an action can be applied.
• Effects: The changes that will occur to the world after applying the action.
• Goal: The set of conditions that need to be satisfied in the final state.

• Plan: A sequence of actions that transforms the initial state into a state that satisfies the goal.

2. Types of State-Space Search Algorithms ( A* is Imp)


Several algorithms can be used to search for a solution in the state space. These algorithms vary in
terms of efficiency, memory usage, and completeness. The following are common algorithms used
in planning as state-space search:

A. Breadth-First Search (BFS)


• Description: This is the simplest form of state-space search. BFS explores all states at the
current level before moving to the next level, ensuring that it explores all possible actions
systematically.

• Advantages:

• Completeness: If a solution exists, BFS will always find it.


• Optimality: BFS is optimal when all actions have the same cost.
• Disadvantages:

• Memory Usage: BFS can be memory-intensive as it stores all explored states in


memory.
• Efficiency: It may be inefficient in very large state spaces, especially when the
branching factor is high.

B. Depth-First Search (DFS)


• Description: DFS explores a single path in the state space as far as possible before
backtracking to explore other paths. It delves deep into one branch of the search tree before
considering alternatives.
• Advantages:

• Memory Efficiency: DFS only needs to store the current path, making it more
memory-efficient than BFS.
• Disadvantages:

• Non-Optimal: DFS is not guaranteed to find the shortest path to the goal, and it may
get stuck in deep or infinite branches.
• Completeness: DFS may fail to find a solution if the state space is infinitely deep or
contains loops.

C. Uniform Cost Search (UCS)


• Description: UCS is a variation of BFS where the search is guided by the cost of reaching
each state. It explores the least costly path first, rather than exploring level by level. UCS
ensures that the first solution found is the least costly.

• Advantages:

• Optimality: UCS is guaranteed to find the least costly solution, provided that the
costs are non-negative.
• Completeness: UCS is complete as long as the state space is finite and all actions
have non-negative costs.
• Disadvantages:

• Time and Space Complexity: UCS can be computationally expensive and memory-
intensive, as it needs to consider all paths in terms of their cost.

D. Best-First Search (Greedy Search)


• Description: In Best-First Search, the algorithm selects the most promising state based on a
heuristic evaluation function. This heuristic estimates the cost to reach the goal from the
current state. It does not necessarily guarantee an optimal solution, but it often finds a
solution faster by prioritizing states that are thought to be closer to the goal.

• Advantages:

• Speed: Best-First Search can be faster than BFS and UCS, especially when the
heuristic is good.
• Disadvantages:

• Non-Optimal: Since it does not take the cost of the path into account, it may not find
the least-cost solution.
• Completeness: Best-First Search is not always complete if the heuristic is poorly
designed.

E. A Search Algorithm*
• Description: A* search is an informed search algorithm that combines the advantages
of UCS and Best-First Search. It uses a heuristic function h(n) that estimates the cost to
the goal and an actual cost function g(n) that keeps track of the cost to reach the
current state. A* aims to minimize the total cost f(n)=g(n)+h(n).

• Advantages:

• Optimality: A* is guaranteed to find the optimal solution if the heuristic is


admissible (i.e., it never overestimates the cost to the goal).
• Completeness: A* is complete when the state space is finite.
• Disadvantages:

• Memory Usage: A* can be memory-intensive, as it needs to store both the open


and closed lists of states.
• Computation Time: If the heuristic is not well-designed, A* can take a long time
to find the solution.

3. Planning as a State-Space Search: The Process


In classical planning problems, the process typically follows these steps:
1. State Representation: Define the states of the world in a way that captures the essential
features required to solve the problem.
2. Action Representation: Specify actions and their effects, including preconditions (what
must be true before an action is applied) and effects (what changes after an action is
applied).
3. Initial State: Specify the initial state of the world.
4. Goal State: Specify the goal state(s) the agent is trying to achieve.
5. Search Algorithm: Choose and apply one of the state-space search algorithms (e.g., BFS,
UCS, A*) to explore the state space and find a sequence of actions (the plan) that transforms
the initial state into the goal state.

4. Heuristic Functions in State-Space Search


In some planning problems, heuristics are used to guide the search. A heuristic is a function that
estimates the cost to reach the goal from a given state. The heuristic function plays a crucial role in
improving the efficiency of the search process:

• A good heuristic can dramatically reduce the search space and speed up the process of
finding a solution.
• Heuristics are often domain-specific, meaning that they are tailored to particular types of
planning problems.

5. Conclusion
Algorithms for planning as state-space search are central to classical planning in AI. These
algorithms help generate plans by searching through all possible states and actions in the problem
domain. Depending on the characteristics of the problem and the computational resources available,
different search algorithms can be used. While algorithms like A* are optimal and complete, others
like DFS and Best-First Search may be more memory-efficient but less reliable in finding the
optimal solution.
Key considerations when choosing a planning algorithm include:

• Completeness: Whether the algorithm is guaranteed to find a solution.


• Optimality: Whether the algorithm finds the best (least costly) solution.
• Efficiency: The computational resources (time and memory) required to run the algorithm.

GRAPHPLAN Algorithm
Inconsistent effects: Remove(Spare , Trunk ) is mutex with LeaveOvernight because one has the
effect At(Spare , Ground ) and the other has its negation.
Interference: Remove(Flat , Axle) is mutex with LeaveOvernight because one has the precondition
At(Flat , Axle) and the other has its negation as an effect.
Competing needs: PutOn(Spare , Axle) is mutex with Remove(Flat , Axle) because one has At(Flat
, Axle) as a precondition and the other has its negation.
Inconsistent support: At(Spare , Axle) is mutex with At(Flat , Axle) in S2 because the only way of
achieving At(Spare , Axle) is by PutOn(Spare , Axle), and that is mutex with the persistence action
that is the only way of achieving At(Flat , Axle). Thus, the mutex relations detect the immediate
conflict that arises from trying to put two objects in the same place at the same time.
1. Components of the Planning Graph
• State Levels (S0, S1, S2...):

• Represent sets of literals (facts) that describe the possible states of the world at each
level.
• Example:
• In S0, we have At(Spare, Trunk) (the spare tire is in the trunk) and
¬At(Spare, Ground) (the spare tire is not on the ground).
• Action Levels (A0, A1...):

• Contain all possible actions that can be applied given the current state.
• Actions are determined based on their preconditions (must match the current state)
and produce effects (which are added to the next state level).
• Example:
• In A0, actions include Remove(Spare, Trunk) and Remove(Flat,
Axle).
• Mutex Links (Mutual Exclusion):

• Represent conflicts between states or actions. If two states or actions are mutually
exclusive, they cannot co-occur in the same plan.
• In the graph, these are shown as crossed lines or gray links.

2. Levels in the Graph


• S0 (Initial State):

• Represents the initial conditions of the problem, such as where the spare tire is
(At(Spare, Trunk)) or the flat tire's location.
• A0 (First Action Level):

• Contains actions available based on the state S0. For example:


• Remove(Spare, Trunk) removes the spare tire from the trunk.
• Remove(Flat, Axle) removes the flat tire from the axle.
• LeaveOvernight is also an action available.
• S1 (Resulting State After Actions in A0):

• Represents the new state after applying actions in A0.


• For example, if Remove(Spare, Trunk) is applied, the state ¬At(Spare,
Trunk) and At(Spare, Ground) are added.
• A1 and S2 (Subsequent Levels):

• These continue expanding possible actions and states:


• PutOn(Spare, Axle) is an action added in A1 if At(Spare,
Ground) exists in S1.

3. Mutex Relationships
• Mutex Between Actions:

• Actions in A0 or A1 can be mutually exclusive if:


• Their effects conflict.
• Their preconditions conflict (e.g., one requires At(Spare, Ground)
while the other requires ¬At(Spare, Ground)).
• Mutex Between States:

• Two states are mutually exclusive if no valid sequence of actions can lead to both
being true at the same time.

4. Key Concepts Illustrated


• Planning as Graph Expansion:

• The graph alternates between action and state levels, growing until a solution is
found or the graph "levels off" (no new states or actions can be added).
• A solution plan can be extracted when all goals are satisfied in a state level with no
mutual exclusions.
• Use of Preconditions and Effects:

• Actions are only added if their preconditions are satisfied in the preceding state level.
• Effects of actions are used to build the next state level.

Example: Flat Tire Problem


This graph is likely modeling a flat tire problem, where the goal is to replace a flat tire with a spare
tire. Steps might include:
1. Removing the spare tire from the trunk (Remove(Spare, Trunk)).
2. Removing the flat tire from the axle (Remove(Flat, Axle)).
3. Installing the spare tire on the axle (PutOn(Spare, Axle)).

Each action depends on the state of the world and produces new states, which are shown in the
subsequent levels.

Termination of GRAPHPLAN
The properties are as follows:
• Literals increase monotonically: Once a literal appears at a given level, it will appear
at all subsequent levels. This is because of the persistence actions; once a literal shows
up, persistence actions cause it to stay forever.
• Actions increase monotonically: Once an action appears at a given level, it will appear
at all subsequent levels. This is a consequence of the monotonic increase of literals; if
the preconditions of an action appear at one level, they will appear at subsequent levels,
and thus so will the action.
• Mutexes decrease monotonically: If two actions are mutex at a given level Ai , then they
will also be mutex for all previous levels at which they both appear. The same holds for
mutexes between literals. It might not always appear that way in the figures, because
the figures have a simplification: they display neither literals that cannot hold at level
Si nor actions that cannot be executed at level Ai . We can see that “mutexes decrease
monotonically” is true if you consider that these invisible literals and actions are mutex
with everything.

The proof can be handled by cases: if actions A and B are mutex at level Ai , it
must be because of one of the three types of mutex. The first two, inconsistent effects
and interference, are properties of the actions themselves, so if the actions are mutex
at Ai , they will be mutex at every level. The third case, competing needs, depends on
conditions at level Si : that level must contain a precondition of A that is mutex with
a precondition of B. Now, these two preconditions can be mutex if they are negations
of each other (in which case they would be mutex in every level) or if all actions for
achieving one are mutex with all actions for achieving the other. But we already know
that the available actions are increasing monotonically, so, by induction, the mutexes
must be decreasing.
• No-goods decrease monotonically: If a set of goals is not achievable at a given level,
then they are not achievable in any previous level. The proof is by contradiction: if they
were achievable at some previous level, then we could just add persistence actions to
make them achievable at a subsequent level.

You might also like