AI Inference: Backward Chaining & Resolution
AI Inference: Backward Chaining & Resolution
AI_Module5
Syllabus :
Inference in First Order Logic: Backward Chaining, Resolution
Classical Planning: Definition of Classical Planning, Algorithms for Planning as
State-Space Search, Planning Graphs
Chapter 9-9.4, 9.5
Chapter 10- 10.1,10.2,10.3
Topics:
1. Inference in First Order Logic
1. Backward Chaining,
2. Resolution
2. Classical Planning
1. Definition of Classical Planning
2. Algorithms for Planning as State Space Search
3. Planning Graphs
4. Logic Programming
Source Book: Artificial Intelligence by Stuart Russel and Peter Norvig. Notes Compiled by: Dr. Thyagaraju G S, Professor, HOD-CSE, SDMIT.
Backward chaining is useful when there is a specific goal to be achieved, and the
system can efficiently backtrack through the inference rules to determine
whether the goal can be satisfied.
Source Book: Artificial Intelligence by Stuart Russel and Peter Norvig. Notes Compiled by: Dr. Thyagaraju G S, Professor, HOD-CSE, SDMIT.
Source Book: Stuart J. Russell and Peter Norvig, Artificial Intelligence, 3rd Edition, Pearson,2015
Fetch all rules from the KB that could produce the goal.
For each rule:
1. Standardize Variables: Make rule variables unique to avoid
conflicts.
2. Unify rhs and goal: Match the conclusion of the rule (rhs)
with the current goal using Unify. This updates θ.
3. Call FOL-BC-AND: Recursively evaluate the conditions (lhs) of
the rule with the updated θ.
Yield θ′: Each substitution that satisfies the rule is yielded back to the
caller.
Knowledge Base:
Execution Steps
Step 1: FOL-BC-ASK
Step 2: FOL-BC-OR
Step 3: FOL-BC-AND
Step 4: FOL-BC-OR
Source Book: Artificial Intelligence by Stuart Russel and Peter Norvig. Notes Compiled by: Dr. Thyagaraju G S, Professor, HOD-CSE, SDMIT.
Step 5: FOL-BC-AND
Step 6: FOL-BC-AND
Final Result
Source Book: Stuart J. Russell and Peter Norvig, Artificial Intelligence, 3rd Edition, Pearson,2015
Source Book: Artificial Intelligence by Stuart Russel and Peter Norvig. Notes Compiled by: Dr. Thyagaraju G S, Professor, HOD-CSE, SDMIT.
5.1.2 Resolution
Resolution is a fundamental inference rule used in automated theorem proving
and logic programming. It is based on the principle of proof by contradiction.
Resolution combines logical sentences in the form of clauses to derive new
sentences.
The resolution rule states that if there are two clauses that contain
complementary literals (one positive, one negative) then these literals can be
resolved, leading to a new clause that is inferred from the original clauses.
Example1:
Consider two logical statements:
1. P∨Q
2. ¬P∨R
Applying resolution: Resolve the statements by eliminating P:
• P∨Q
• ¬P∨R
Resolving P and ¬P: Q∨R
The resulting statement Q∨R is a new clause inferred from the original two.
Example2:
Clause 1: (P∨Q∨R)
Clause 2:(¬P∨¬Q∨S)
To resolve these clauses, we look for complementary literals. In this case, P and
¬P are complementary.
So, we can resolve these two clauses by removing the complementary literals
and combining the remaining literals:
Resolving P and ¬P gives: (Q∨R)∨(¬Q∨S)
Resolving Q and ¬Q gives (RVS)
6. Iterative Application:
o Apply the resolution rule repeatedly to derive new clauses.
o If the empty clause □is derived, it indicates a contradiction,
proving the original statement.
1. P(a)∨Q(b)
2. ¬Q(b)∨R(c)
3. ¬R(c)
Steps:
Since the empty clause □ is derived, the original statement ¬P(a) is valid.
Example 1:
Let's consider a simplified example of a knowledge base for the Wumpus World
scenario and demonstrate proof by resolution to establish the unsatisfiability of
a certain statement.
In Wumpus World, an agent explores a grid containing a Wumpus (a monster),
pits, and gold. Apply the resolution to prove P[1,2].
Negated Conclusion:
Let's say we want to prove the negation of the statement: ¬PitIn[1,2]
Apply Resolution:
1. W[1,1] ∨ P[1,2] , ¬P[1,2] resolves into W[1,1]
2. ¬W[1,1]∨¬P[1,2], W[1,1] resolves into ¬P[1,2]
3. ¬B[1,2] ∨ P[1,2] , ¬P[1,2] resolves into ¬B[1,2]
4. B[1,2] ∨¬P[1,2], ¬B[1,2] resolves into ¬P[1,2]
Applying resolution, we end up with: ¬P[1,2] , Which is not empty and also
there is not further any clauses to continue. This gives conclusion that our
negation conclusion is True and P[1,2] is False for the given knowledge base.
Source Book: Artificial Intelligence by Stuart Russel and Peter Norvig. Notes Compiled by: Dr. Thyagaraju G S, Professor, HOD-CSE, SDMIT.
Example 2:
Steps
• Eliminate implications: ∀ x [¬∀ y ¬Animal(y) ∨ Loves(x, y)] ∨ [∃ y
Loves(y, x)] .
• Move ¬ inwards: In addition to the usual rules for negated connectives,
we need rules for negated quantifiers. Thus, we have
• ¬∀ x p becomes ∃ x ¬p
• ¬∃ x p becomes ∀ x ¬p .
• Our sentence goes through the following transformations:
• ∀ x [∃ y ¬(¬Animal(y) ∨ Loves(x, y))] ∨ [∃ y Loves(y, x)] .
• ∀ x [∃ y ¬¬Animal(y) ∧ ¬Loves(x, y)] ∨ [∃ y Loves(y, x)] .
• ∀ x [∃ y Animal(y) ∧ ¬Loves(x, y)] ∨ [∃ y Loves(y, x)] .
• Standardize variables: For sentences like (∃ x P(x))∨(∃ x Q(x)) which use
the same variable name twice, change the name of one of the variables.
This avoids confusion later when we drop the quantifiers. Thus, we have
• ∀ x [∃ y Animal(y) ∧ ¬Loves(x, y)] ∨ [∃ z Loves(z, x)] .
Source Book: Artificial Intelligence by Stuart Russel and Peter Norvig. Notes Compiled by: Dr. Thyagaraju G S, Professor, HOD-CSE, SDMIT.
Example:
Source Book: Artificial Intelligence by Stuart Russel and Peter Norvig. Notes Compiled by: Dr. Thyagaraju G S, Professor, HOD-CSE, SDMIT.
Another Example :
Suppose Curiosity did not kill Tuna. We know that either Jack or
Curiosity did; thus Jack must have. Now, Tuna is a cat and cats are
animals, so Tuna is an animal. Because anyone who kills an animal is
loved by no one, we know that no one loves Jack. On the other hand,
Jack loves all animals, so someone loves him; so we have a
contradiction. Therefore, Curiosity killed the cat.
Source Book: Artificial Intelligence by Stuart Russel and Peter Norvig. Notes Compiled by: Dr. Thyagaraju G S, Professor, HOD-CSE, SDMIT.
Summary
1. Forward chaining starts with known facts and moves forward to reach
conclusions,
2. Backward chaining starts with the goal and moves backward to verify if
the goal can be satisfied, and
3. Resolution is an inference rule used to derive new clauses by combining
existing ones.
These techniques are essential for reasoning and inference in First-Order Logic
systems.
Completeness of resolution
Resolution is a method in logic that can prove whether a set of statements is
unsatisfiable. If the statements are unsatisfiable (i.e., there’s no way they can all
be true at once), resolution will eventually find a contradiction.
Key Idea
Herbrand's theorem ensures we only need to check a finite subset of these terms
to find a contradiction.
The lifting lemma connects proofs for ground terms to proofs for first-order logic. It "lifts"
results from simpler cases (propositional logic) to more general cases (with variables). This
step is essential to show resolution's power in first-order logic.
The Conclusion
The lifting lemma is a principle that allows us to "lift" a resolution proof from
specific ground instances (statements without variables) to general first-order
logic (statements with variables). Here's how it works:
Example
This lemma is crucial because it ensures that resolution proofs for specific cases
(ground terms) can be generalized to more complex first-order logic, making the
method powerful and versatile.
1. Axiomatizing Equality
We write rules (axioms) in the knowledge base that define how equality works.
These rules must express:
Reflexivity: x=x
Symmetry: x=y⇒y=x
Transitivity: x=y∧y=z⇒x=z
Using these axioms, standard inference methods like resolution can handle
equality reasoning (e.g., solving equations). However, this approach can
generate many unnecessary conclusions, making it inefficient.
How it works:
Example:
Given:
Father(Father(x))=PaternalGrandfather(x)
Birthdate(Father(Father(Bella)), 1926)
Birthdate(PaternalGrandfather(Bella), 1926)
3. Paramodulation
How it works:
Formal Rule:
Summary
Resolution Strategies
Resolution inference is guaranteed to find a proof if one exists, but some
strategies can make the process more efficient. Below are key strategies and their
applications.
Unit Preference
Set of Support
Input Resolution
Subsumption
Resolution theorem provers are widely used in the synthesis and verification of
both hardware and software systems.
Summary
Resolution strategies like unit preference, set of support, input resolution, and
subsumption improve proof efficiency by focusing on relevance, reducing
redundancy, and constraining the search space. Applications in hardware and
software demonstrate their importance in real-world problem-solving.
Source Book: Artificial Intelligence by Stuart Russel and Peter Norvig. Notes Compiled by: Dr. Thyagaraju G S, Professor, HOD-CSE, SDMIT.
For example, executing Fly(P1, SFO, JFK) in a state would remove At(P1,
SFO) and add At(P1, JFK).
The state Plane(Plane1) ∧ At(Plane1, SFO) satisfies the goal At(p, SFO) ∧
Plane(p).
The air cargo transport problem, illustrated in Figure 10.1, involves transporting
cargo between airports by loading, unloading, and flying planes. This problem
uses three main actions: Load, Unload, and Fly, which operate on two primary
predicates:
also move with it. While first-order logic can easily quantify over all objects
within the plane, basic PDDL lacks universal quantifiers. Therefore, a different
solution is adopted:
Handling Spurious Actions : The problem can also involve spurious actions,
such as Fly(P1, JFK, JFK), which would be a no-op but can produce
contradictory effects (e.g., both At(P1, JFK) and ¬At(P1, JFK)). While
such issues are often ignored in practice because they rarely lead to incorrect
plans, the proper way to prevent them is by adding inequality preconditions,
ensuring that the departure (from) and arrival (to) airports are different.
In the context of the air cargo transport problem, SFO and JFK refer to airport
codes:
These are commonly used IATA airport codes to represent specific locations in
transportation and logistics scenarios. In this problem, they are used as example
locations for cargo and planes.
Key Concepts:
1. Setup:
o Blocks can be placed on the table or stacked on top of one
another.
o Only one block can fit directly on top of another block.
Source Book: Artificial Intelligence by Stuart Russel and Peter Norvig. Notes Compiled by: Dr. Thyagaraju G S, Professor, HOD-CSE, SDMIT.
Reinterpret Clear(x):
"There is space on x to hold a block."
(Under this interpretation, Clear(Table) is always true.)
6. Optional Optimization:
o To prevent redundant use of Move(b, x, Table) instead of
MoveToTable(b, x):
Add the predicate Block(y) to the Move action's
precondition.
This ensures Move is only used for moving blocks between
other blocks, not the table.
By making these adjustments, the blocks world planner becomes more accurate
and efficient, avoiding unnecessary computational overhead.
Source Book: Artificial Intelligence by Stuart Russel and Peter Norvig. Notes Compiled by: Dr. Thyagaraju G S, Professor, HOD-CSE, SDMIT.
1. PlanSAT: Determines whether there exists any plan that solves a given planning
problem.
2. Bounded PlanSAT: Asks if there is a solution of length kkk or less, which can help
find an optimal plan.
Decidability
Both problems are decidable for classical planning due to the finiteness of states. However,
introducing function symbols to the language makes the number of states infinite. In this
case:
Complexity Class
Both PlanSAT and Bounded PlanSAT belong to the complexity class PSPACE, which
includes problems solvable by a deterministic Turing machine using polynomial space.
PSPACE is broader and more challenging than NP. Even with severe restrictions, these
problems remain complex:
Practical Implications
These theoretical results might seem daunting, but practical planning rarely involves worst-
case scenarios. For instance:
To handle such cases effectively, good search heuristics are essential. Classical planning has
advanced significantly by enabling highly accurate domain-independent heuristics. In
contrast, systems relying on successor state axioms in first-order logic have struggled to
develop strong heuristics.
Source Book: Artificial Intelligence by Stuart Russel and Peter Norvig. Notes Compiled by: Dr. Thyagaraju G S, Professor, HOD-CSE, SDMIT.
Description: Starts from the initial state and applies actions to reach the
goal.
o It explores all possible actions from the current state, leading to a
large branching factor and potential inefficiency without heuristics.
Challenges:
1. Explores irrelevant actions.
2. Handles large state spaces with numerous possible states and
actions.
Example:
In an air cargo problem with 10 airports, 5 planes, and 20 cargo items:
o At each step, the search needs to evaluate thousands of possible
actions like flying planes, loading cargo, or unloading it.
o Without a heuristic, this leads to a massive search space.
Example:
If the goal is At(C2, SFO), the algorithm considers the action
Unload(C2, p, SFO):
o Precondition: In(C2, p) ∧ At(p, SFO).
o Effect: At(C2, SFO).
It regresses to find the predecessor state where these
preconditions are true.
Purpose: Estimate the cost of reaching the goal from the current state to
guide search algorithms like A*.
Types of Heuristics:
1. Ignore Preconditions:
Drops preconditions, making every action applicable.
Example: Simplifies the 8-puzzle by ignoring adjacency
requirements for moves.
2. Ignore Delete Lists:
Assumes actions cannot undo progress, making the problem
monotonic.
Example: In a transportation problem, unloading an item is
never undone.
3. State Abstraction:
Groups states by ignoring irrelevant fluents to reduce the
state space.
Example: In air cargo, consider only packages and
destinations while abstracting plane details.
Figure 10.6 diagrams part of the state space for two planning problems using
the ignore-delete-lists heuristic. The dots represent states and the edges
actions, and the height of each dot above the bottom plane represents the
Source Book: Artificial Intelligence by Stuart Russel and Peter Norvig. Notes Compiled by: Dr. Thyagaraju G S, Professor, HOD-CSE, SDMIT.
heuristic value. States on the bottom plane are solutions. In both these
problems, there is a wide path to the goal. There are no dead ends, so no need
for backtracking; a simple hill climbing search will easily find a solution to these
problems (although it may not be an optimal solution).
The image illustrates two state spaces derived from planning problems where the ignore-
delete-lists heuristic is applied. Here’s a breakdown of the key details:
o
It creates a state space without local minima, meaning there are no dead ends
or misleading paths that can trap the search. This makes the search for the goal
straightforward.
5. Two Examples:
o The two diagrams represent different problem instances:
The left diagram shows a relatively "steep" and orderly descent to the
goal, indicating a direct and simple path.
The right diagram has a more "twisted" state space, with complex
paths leading to the goal, but still without any local minima.
These visualizations help explain why the ignore-delete-lists heuristic is effective: the
absence of local minima ensures the search algorithm does not get stuck, and the heuristic
guides the planner efficiently toward the goal.
Source Book: Artificial Intelligence by Stuart Russel and Peter Norvig. Notes Compiled by: Dr. Thyagaraju G S, Professor, HOD-CSE, SDMIT.
A planning graph is a directed, leveled graph that represents actions and literals
in alternating layers, capturing all possible states and actions up to a certain time
step.
1. Levels:
o S₀: Represents the initial state.
o A₀: Represents actions applicable in S₀.
o Alternates between states (S₁, S₂, ...) and actions (A₁, A₂, ...).
2. Termination:
o Stops when two consecutive levels are identical (levelled off).
Example: For the problem "Have Cake and Eat Cake Too":
o S₀: {Have(Cake)}
o A₀: {Eat(Cake), Bake(Cake)}
o S₁: {Have(Cake), Eaten(Cake)}
o Mutex Links: Highlight conflicts, e.g., eating and having the cake.
Figure 10.8 shows the planning graph for the “have cake and eat cake too”
problem up to level S2. Rectangles indicate actions (small squares indicate
persistence actions), and straight lines indicate preconditions and effects. Mutex
links are shown as curved gray lines. Not all mutex links are shown, because the
graph would be too cluttered. In general, if two literals are mutex at Si, then the
Source Book: Artificial Intelligence by Stuart Russel and Peter Norvig. Notes Compiled by: Dr. Thyagaraju G S, Professor, HOD-CSE, SDMIT.
persistence actions for those literals will be mutex at Ai and we need not draw
that mutex link.
1. Unsolvability Check:
If a goal literal does not appear in the final level of the graph, the problem
is unsolvable.
2. Estimating Goal Costs:
The cost of achieving a goal literal gi from an initial state s is estimated
as the level at which gi first appears in the planning graph constructed
from s. This is termed the level cost of gi. For example, in Figure 10.8,
Have(Cake) has a level cost of 0, and Eaten(Cake) has a level cost
of 1.
3. Accuracy and Serial Graphs:
The level cost may not always align with reality because planning graphs
allow multiple actions per level, while the heuristic only considers levels,
not actions. To improve accuracy, serial planning graphs are often used.
These enforce only one action per time step by adding mutual exclusion
(mutex) links between non-persistence actions. Costs derived from serial
graphs are more realistic.
4. Estimating Conjunction Costs:
Estimating costs for a conjunction of goals involves three approaches:
Source Book: Artificial Intelligence by Stuart Russel and Peter Norvig. Notes Compiled by: Dr. Thyagaraju G S, Professor, HOD-CSE, SDMIT.
This section demonstrates how the GRAPHPLAN algorithm operates using the
spare tire problem , with its planning graph depicted in Figure 10.10.
1. Initialization:
GRAPHPLAN begins by initializing the planning graph with a single level
(S0) that represents the initial state. The positive and negative fluents from
the initial state are included, while unchanging positive literals (e.g.,
Tire(Spare)) and irrelevant negative literals are omitted.
Since the goal At(Spare, Axle) does not appear in S0, EXTRACT-
SOLUTION is not called. Instead, EXPAND-GRAPH adds actions to A0
whose preconditions are met in S0 (all actions except PutOn(Spare,
Source Book: Artificial Intelligence by Stuart Russel and Peter Norvig. Notes Compiled by: Dr. Thyagaraju G S, Professor, HOD-CSE, SDMIT.
Axle)), along with persistence actions for S0's literals. The effects of these
actions form S1, and mutex relations are identified and added.
2. Expanding the Graph:
In S1, the goal At(Spare, Axle) is still absent, so EXPAND-GRAPH is
called again to produce A1 and S2, resulting in the full planning graph
(Figure 10.10). The process highlights examples of mutex relationships:
o Inconsistent Effects: Remove(Spare, Trunk) is mutex with
LeaveOvernight due to conflicting effects (At(Spare,
Ground) vs. its negation).
o Interference: Remove(Flat, Axle) is mutex with
LeaveOvernight because one requires At(Flat, Axle) as a
precondition, while the other negates it.
o Competing Needs: PutOn(Spare, Axle) is mutex with
Remove(Flat, Axle) as they depend on conflicting
preconditions (At(Flat, Axle) vs. its negation).
o Inconsistent Support: At(Spare, Axle) and At(Flat,
Axle) in S2 are mutex because achieving At(Spare, Axle)
requires PutOn(Spare, Axle), which conflicts with the
persistence of At(Flat, Axle).
3. Solution Extraction:
When all goal literals appear in S2 without mutex, EXTRACT-SOLUTION
is invoked. This process is framed as a Boolean constraint satisfaction
problem (CSP), with variables representing actions, values being inclusion
in or exclusion from the plan, and constraints being mutexes and
goal/precondition requirements. Alternatively, it can be defined as a
backward search problem, where:
o The initial state includes the last graph level (Sn) and the unsatisfied
goals.
o Actions at Si are conflict-free subsets of Ai−1 that satisfy the current
goals.
o The goal is to reach S0 with all goals satisfied, with each action
incurring a cost of 1.
4. Example Execution:
Starting at S2 with the goal At(Spare, Axle), the only relevant action
is PutOn(Spare, Axle), leading to S1 with goals At(Spare,
Ground) and ¬At(Flat, Axle).
o At(Spare, Ground) is achieved by Remove(Spare,
Trunk).
o ¬At(Flat, Axle) is achieved by either Remove(Flat,
Axle) or LeaveOvernight, but the latter is mutex with
Remove(Spare, Trunk).
Source Book: Artificial Intelligence by Stuart Russel and Peter Norvig. Notes Compiled by: Dr. Thyagaraju G S, Professor, HOD-CSE, SDMIT.
This strategy balances efficiency with practicality for solving complex planning
problems.
Source Book: Artificial Intelligence by Stuart Russel and Peter Norvig. Notes Compiled by: Dr. Thyagaraju G S, Professor, HOD-CSE, SDMIT.
The graph levels off when no new literals, actions, or mutex relations are added.
However, this does not guarantee a solution. Consider an air cargo problem
where one plane must transport nnn pieces of cargo from airport A to airport B,
but only one piece fits in the plane at a time.
The graph levels off at level 4, reflecting the steps required to load, fly,
and unload a single piece of cargo.
However, solving the problem requires 4n−1 steps, including return trips
for additional cargo. Thus, leveling off does not necessarily mean a
solution exists at that point.
When to Terminate?
The algorithm continues expanding the graph as long as new possibilities arise:
Proof of Leveling-Off
The key to proving that the graph and no-goods stabilize lies in the monotonic
properties of planning graphs:
Since actions and literals increase monotonically and are finite in number, the
graph eventually stabilizes at a level where no new actions or literals are
introduced. Similarly, mutexes and no-goods, which decrease monotonically and
cannot fall below zero, also stabilize.
Termination Condition
1. A goal is missing, or
2. Any goal is mutex with another,
the algorithm terminates, returning failure. This guarantees that further expansion
would not yield a solution.
PROLOG
Prolog is the most popular logic programming language. It’s used for quick
prototyping and tasks like:
Writing compilers
Parsing natural language
Creating expert systems in fields like law, medicine, and finance
Prolog Programs
Prolog programs consist of rules and facts (called definite clauses) written in a
special syntax. Here’s what makes Prolog different:
3. Lists: [E|L] represents a list where E is the first item, and L is the rest.
append([],Y,Y).
append([A|X],Y,[A|Z]) :- append(X,Y,Z).
Source Book: Artificial Intelligence by Stuart Russel and Peter Norvig. Notes Compiled by: Dr. Thyagaraju G S, Professor, HOD-CSE, SDMIT.
This means:
append(X,Y,[1,2]).
This query finds pairs of lists X and Y that combine to [1,2]. The answers are:
Interpreted Mode
In this mode, Prolog functions like the FOL-BC-ASK algorithm (Figure 9.6),
treating the program as a knowledge base. However, Prolog interpreters include
optimizations for better efficiency. Two key improvements are:
1. Global Stack of Choice Points:
o Instead of explicitly managing iterations over possible results,
Prolog uses a global stack of choice points to track alternatives
considered in the FOL-BC-OR step.
o This approach is not only more efficient but also simplifies
debugging, as the debugger can traverse up and down the stack to
inspect states.
2. Logic Variables and Trails:
o Prolog uses logic variables that dynamically remember their
current bindings. At any time, a variable is either unbound or
bound to a specific value. These bindings implicitly define the
substitution for the current proof branch.
o New variable bindings extend the path, but attempts to rebind an
already bound variable fail due to unification constraints.
o When backtracking occurs after a goal fails, variables are unbound
in reverse order using a trail stack. Each variable bound by
UNIFY-VAR is pushed onto the trail, and during backtracking,
variables are unbound as they are popped from the trail.
Despite these optimizations, Prolog interpreters still require thousands of
machine instructions per inference step due to the overhead of operations like
index lookups, unification, and recursive call stack management. In essence, the
interpreter processes each query as if encountering the program for the first
time, repeatedly finding clauses to match the goal.
Compiled Mode
Compiled Prolog programs offer significant performance improvements by
tailoring inference procedures to specific sets of clauses. This eliminates much
of the interpretation overhead:
1. Optimized Clause Matching:
o Unlike interpreters, compiled Prolog "remembers" which clauses
match a given goal, streamlining the process.
Source Book: Artificial Intelligence by Stuart Russel and Peter Norvig. Notes Compiled by: Dr. Thyagaraju G S, Professor, HOD-CSE, SDMIT.
The append predicate in Prolog can be compiled into an optimized form, such
as the example shown in Figure 9.8. Several noteworthy points highlight how
this compilation enhances efficiency:
Source Book: Artificial Intelligence by Stuart Russel and Peter Norvig. Notes Compiled by: Dr. Thyagaraju G S, Professor, HOD-CSE, SDMIT.
Before the advancements by Warren and others, Prolog's performance was too
slow for practical use. However, compilers like the Warren Abstract Machine
Source Book: Artificial Intelligence by Stuart Russel and Peter Norvig. Notes Compiled by: Dr. Thyagaraju G S, Professor, HOD-CSE, SDMIT.
Parallelism in Prolog :
1. OR-Parallelism:
o Occurs when a goal can unify with multiple clauses in the
knowledge base.
o Each unification forms an independent branch of the search
space, which can be solved in parallel.
2. AND-Parallelism:
o Arises from solving multiple conjuncts in the body of a rule
simultaneously.
o Unlike OR-parallelism, AND-parallelism is more challenging, as it
requires consistent bindings across all conjunctive branches.
Communication between branches ensures a globally valid
solution.
Consider the following Prolog program, which checks if a path exists between
two points in a directed graph:
This happens because Prolog's DFS prioritizes depth over breadth and fails to
detect cyclic dependencies. Consequently, Prolog is incomplete as a theorem
prover for definite clauses—even for simple Datalog programs like this one.
Source Book: Artificial Intelligence by Stuart Russel and Peter Norvig. Notes Compiled by: Dr. Thyagaraju G S, Professor, HOD-CSE, SDMIT.
Redundant Computations
For example:
Source Book: Stuart J. Russell and Peter Norvig, Artificial Intelligence, 3rd Edition, Pearson,2015
Under the unique names assumption, CS and EE are distinct, as are the course
numbers 101, 102, and 106. This means that there are exactly four distinct
courses. According to the closed-world assumption, there are no other courses,
so the total number of courses is exactly four.
Source Book: Artificial Intelligence by Stuart Russel and Peter Norvig. Notes Compiled by: Dr. Thyagaraju G S, Professor, HOD-CSE, SDMIT.
In contrast, if these were assertions in FOL, they would only imply that there are
at least one and at most infinity courses. This is because FOL does not deny the
existence of other unmentioned courses, nor does it specify that the mentioned
courses are distinct. In FOL, the assertions would be expressed as:
This is the completion of the Prolog assertions, which expresses the idea that
there are at most four courses in FOL. To express that there are at least four
courses in FOL, we would need to expand the equality predicate as follows:
is the most specific set of constraints that can be derived from the knowledge base
for the query variables.
For example, the solution to the query triangle(3, 4, Z) would be the
constraint 7 >= Z >= 1, which means that Z must be between 1 and 7. In
contrast, standard logic programs are a special case of CLP, where the solution
constraints are always equality constraints (bindings).
CLP systems include various constraint-solving algorithms tailored to the types
of constraints allowed in the system. For example, a CLP system that supports
linear inequalities on real-valued variables might employ a linear
programming algorithm to solve such constraints.
Several CLP systems allow programmers to control the order in which inferences
are made. For example, the MRS language (Genesereth and Smith, 1981;
Russell, 1985) lets the programmer define metarules to determine the order of
conjunct evaluations. A programmer could write a rule to prioritize goals with
fewer variables or define domain-specific rules for particular predicates.
In summary, CLP systems enhance traditional logic programming by
incorporating constraint-solving techniques, providing greater flexibility and
efficiency for handling a wide range of problems, from finite-domain CSPs to
complex real-valued constraints.
Source Book: Artificial Intelligence by Stuart Russel and Peter Norvig. Notes Compiled by: Dr. Thyagaraju G S, Professor, HOD-CSE, SDMIT.
% Example Query:
% ?- sum(5, 3, Result).
% Result = 8.
% Example Query:
% ?- swap(5, 3, A, B).
% A = 3,
% B = 5.
% Example Query:
% ?- add_lists([1, 2, 3], [4, 5, 6], Result).
% Result = [5, 7, 9].
factorial(N, Result) :-
N > 0,
N1 is N - 1,
factorial(N1, SubResult),
Result is N * SubResult.
% Example Query:
% ?- factorial(5, Result).
% Result = 120.
Example Usage
1. Sum of Two Numbers
?- swap(7, 9, A, B).
A = 9,
B = 7.
4. Find Factorial
?- factorial(4, Result).
Result = 24.
[Link] G S (9480123526)
The use of function symbols in classical planning with PDDL provides a modular, variable-based representation that reduces redundancy in action definitions by allowing multiple actions to be represented through schemas. This makes the planning process more concise and maintainable . However, while function symbols enable more expressive planning tasks, they can complicate the task of ensuring decidability. Planning problems with functions belong to PSPACE, thus requiring polynomial space on a deterministic Turing machine and making them more computationally intense than NP problems . Therefore, while function symbols provide flexibility, they also add complexity that could affect the tractability of planning tasks.
Prolog executes rules using depth-first backward chaining, trying rules sequentially and stopping as soon as a solution is found . Each query attempts to unify rules from top to bottom in the database, dynamically binding variables . Challenges arise with this strategy, including infinite loops due to Prolog's priority for depth. When clauses are ordered unfavorably, it can recursively call itself without termination, especially with cyclic dependencies . Moreover, the depth-first strategy incurs redundant computations, particularly in graph search scenarios, where negligible paths repetitively explored inflate the computation time and resources used . These inefficiencies necessitate techniques like memoization or logic programming systems to enhance handling of redundant computations and prevent infinite loops.
Forward chaining offers a strategic advantage over Prolog's depth-first search (DFS) by systematically generating all relevant facts, leading to an efficient handling of graph problems without the repeated-state issue inherent in DFS . While DFS recursively explores all possibilities, potentially falling into infinite loops or redundancy with repeated states, forward chaining incrementally builds on discovered facts, reducing unnecessary calculations and directly addressing redundancy concerns . Limits of forward chaining include lower efficiency in processes that require extensive exploratory search, as it can become cumbersome without intelligent design to restrict state generation. Meanwhile, DFS is more suited to environments where exploratory depth and trial can yield straightforward paths without severe redundancies, though it requires careful management of cyclic dependencies and state repeat to avoid inefficiencies . Overall, forward chaining's dynamic programming approach minimizes unnecessary computations and enhances task efficiency, whereas DFS in Prolog benefits from systematic search procedures when implemented with awareness of its constraints.
In PDDL, the closed-world assumption implies that any fluent not explicitly mentioned in a state is considered false, which simplifies the state representation by allowing the planner to ignore unspecified facts . This assumption promotes efficiency by reducing the amount of information that needs to be processed and stored, as planners only deal with explicitly stated facts rather than considering all possible true/false combinations. However, this assumption also imposes limitations, as it requires complete knowledge of the state space and cannot handle scenarios where previously unknown information becomes relevant . Consequently, it limits the flexibility of the planning system to adapt to new information dynamically.
Planning graphs systematically expand states with levels that encapsulate the possible actions and outcomes, using mutual exclusions (mutex) to identify incompatible actions and states within each level . The GRAPHPLAN algorithm leverages these planning graphs by verifying whether all goal literals appear without mutex conditions. It searches for a valid plan directly from the graph via the EXTRACT-SOLUTION phase, adding more levels if a solution is initially unsuccessful . Despite their systematic approach, planning graphs are prone to missing subtle unsolvable problems, such as those involving complex mutual dependencies or circular goals, as they cannot detect issues involving three or more actions without deeper analysis . This limitation means GRAPHPLAN might require iterative expansion without yielding a solution, especially in very complex problem spaces.
Prolog's employment of database semantics under the unique names assumption ensures that each constant and ground term refers to a distinct object. Combined with the closed-world assumption, this results in only the explicitly defined sentences being considered true, enhancing efficiency as it limits the scope of facts the system must consider . However, this also constrains expressiveness, as Prolog cannot represent unknown or negative information inherently in its language construct, reducing its potential to express queries that require knowledge beyond what's explicitly specified . This trade-off allows Prolog to be concise and computationally efficient, though at the expense of flexibility found in first-order logic.
Heuristics in AI planning, such as the max-level heuristic, estimate the cost of reaching a set of goals by considering the maximum cost needed for any single goal, which ensures admissibility but may lack precision due to its simplified nature . The level-sum heuristic assumes subgoal independence and sums the individual goal levels, performing well for decomposable problems, but is inadmissible due to ignoring interaction effects between goals, potentially underestimating the needed steps . The set-level heuristic addresses these shortcomings by recognizing levels at which all goals coexist without mutual exclusivity, providing an admissible solution that outperforms max-level heuristics and excels in problems with interacting subplans . However, these heuristics, while effective in providing goal proximity, can fail with non-separable or complex interacting goals without further computational efforts.
Dynamic programming enhances Prolog's backward chaining by implementing reusable solutions for subproblems, reducing redundant computations. Tabled logic programming capitalizes on this by caching solutions to known subgoals and reusing these cached results instead of recomputing each time the subgoal is encountered, integrating a memory component into backward chaining that mirrors forward chaining's efficiency . This combination permits the goal-directed nature of backward chaining to benefit from dynamic programming, allowing for expanded problem-solving capabilities while avoiding inefficiencies typical of repeated computations and infinite loops in Prolog's depth-first search. As a result, such a structured integration enables a balance between procedural searching and the optimized efficiency of dynamic programming, offering completeness for Datalog-based systems while effectively mitigating Prolog’s traditional limitations .
Prolog's parallelism capabilities significantly enhance computational efficiency in logic programming by exploiting independent paths in the search space. OR-parallelism allows for simultaneous resolution of multiple branches when a goal unifies with several clauses, offering speed improvements due to solving these branches concurrently . On the other hand, AND-parallelism solves multiple conjuncts within a rule together, although it demands careful synchronization to maintain consistent variable bindings across all concurrently solved conjunctive branches . While OR-parallelism generally offers more straightforward parallel execution, AND-parallelism's successful implementation can lead to substantial computation time reductions on suitable tasks, though it is more complex to coordinate . Together, these parallelism techniques enable Prolog to perform complex logic programming tasks appreciably faster, enhancing the practicality of Prolog in AI and computation-heavy tasks.
Forward (progression) search starts from the initial state and explores all possible actions, leading to a potentially large branching factor. It often ends up exploring irrelevant actions, making it inefficient for complex planning problems without heuristics . In contrast, backward (regression) search begins from the goal state, focusing only on relevant actions necessary to reach the goal, which typically reduces complexity and avoids irrelevant branches. This approach can be more efficient as it inherently restricts the search space, focusing only on actions directly affecting the goals . Thus, backward search tends to be more efficient in planning domains where goal states are well-formulated, while forward search can be cumbersome without effective heuristics.