×

Backward Chaining in AI: Artificial Intelligence

Backward Chaining is a backward approach which works in the backward direction. It begins its journey from the back of the goal.

Like, forward chaining, we have backward chaining for Propositional logic as well as Predicate logic followed by their respective algorithms.

Let’s discuss both types one by one:

Backward Chaining in Propositional Logic

In propositional logic, backward chaining begins from the goal and using the given propositions, it proves the asked goal. There is a backward chaining algorithm which is used to perform backward chaining for the given axioms. The first algorithm given is known as the Davis-Putnam algorithm. It was proposed by Martin Davis and Hilary Putnam in 1960. In 1962, Davis, Logemann and Loveland presented a new version of the Davis-Putnam algorithm. It was named under the initials of all four authors as DPLL. The versioned algorithm (DPLL) takes an input of a statement as CNF.

The DPLL algorithm is as follows:

function DPLL-SATISFIABLE?(s) returns true or false
inputs: s, a sentence in propositional logic
clauses ? clause set  in CNF representation of s
symbols?list of proposition symbols in s
return DPLL(clauses, symbols,{ })
function DPLL(clauses, symbols,model ) returns true or false
if every clause is true in model then return true
if some clause is false in model then return false
P, value?FIND-PURE-SYMBOL(symbols, clauses,model )
if the value of P is non-null then return DPLL(clauses, symbols – P,model ? {P=value})
P, value?FIND-UNIT-CLAUSE(clauses,model )
if the value ofP is non-null then return DPLL(clauses, symbols – P,model ? {P=value})
P ?FIRST(symbols); rest ?REST(symbols)
return DPLL(clauses, rest ,model ? {P=true}) or
DPLL(clauses, rest ,model ? {P=false}))                                                                                               

Note: The above backward chaining algorithm is used to check satisfiability of a sentence in propositional logic.

Why was DPLL introduced?

There are following improvements required in the Davis-Putnam algorithm, which led to the introduction of the DPLL algorithm:

  • Early Termination: The algorithm used to detect if the sentence must be true or false, even if it is a partially completed model.
  • Pure symbol heuristic: It is the symbol which always appears with the same sign in each clause.
  • Unit clause heuristic: It was defined earlier as a clause with just one literal. In DPLL, it also means clauses in which all literals excluding one is already assigned with a false value in the model.

The above algorithm is limited to small problems.

But for large problems, we have some specific  tricks described below:

  • Component analysis: DPLL assigns true values to variables, therefore set of clauses may become disjoint subsets. They are known as components which share no unassigned variables. Provided an efficient method to detect, the solver can solve each component separately.
  • Variable and value ordering:  in the above DPLL algorithm, we have used an arbitrary variable and always tried to make the value true first. Degree heuristic helps in doing so.
  • Intelligent Backtracking: The problem which cannot be solved in hours can easily be solved in few minutes by applying intelligent backtracking.
  • Random restarts: Restarting from the initial state, we can have random decisions regarding the direction to be chosen to reach the goal. Like, in hill-climbing, we can restart from the top to reach the goal  in a more efficient way.
  • Clever indexing: The fast indexing methods helps to process the backtracking fastly.

Example of Backward Chaining in Propositional Logic

Let’s consider the previous section  example:

Given that:

  1. If D barks and D eats bone, then D is a dog.
  2. If V is cold and V is sweet, then V is ice-cream.
  3. If D is a dog, then D is black.
  4. If V is ice-cream, then it is Vanilla.

Derive backward chaining using the given known facts to prove Tomy is black.

  • Tomy barks.
  • Tomy eats bone.

Solution:

  1. On replacing D with Tomy in (3), it becomes:

If Tomy is a dog, then Tomy is black.

           Thus, the goal is matched with the above axiom.

  • Now, we have to prove Tomy is a dog.                                  …(new goal)

     Replace D with Tomy in (1), it will become:

If Tomy barks and Tomy eats bone, then Tomy is a dog.        …(new goal)

Again, the goal is achieved.

  • Now, we have to prove that Tomy barks and Tomy eats bone.       …(new goal)

      As we can see, the goal is a combination of two sentences which can be further divided as:

Tomy barks.

Tomy eats bone.

From (1), it is clear that Tomy is a dog.

Hence, Tomy is black.

Note: Statement (2) and (4) are not used in proving the given axiom. So, it is clear that goal never matches the negated versions of the axioms. Always Modus Ponen is used, rather Modus Tollen.

Backward Chaining in FOPL

In FOPL, backward chaining works from the backward direction of the goal, apply the rules on the known facts which could support the proof. Backward Chaining is a type of AND/OR search because we can prove the goal by applying any rule in the knowledge base. A backward chaining algorithm is used to process the backward chaining.

The algorithm is given below:

function FOL_BACKWARD_ASK(KB, query) returns  generator of the substitutions
return FOL_BACKWARD_OR(KB, query,{ })
generator FOL_BACKWARD_OR(KB, goal , ?) yields the substitution
for each (lhs ? rhs) rule in FETCH-RULES-FOR-GOAL(KB, goal ) do
(lhs, rhs)?STANDARDIZE-VARIABLES((lhs, rhs))
for each ? in FOL_BACKWARD_AND(KB, lhs, UNIFY(rhs, goal , ?)) do
yield ?_
generator FOL_BACKWARD_AND(KB, goals, ?) yields a substitution
if ? = failure then return
else if LENGTH(goals) = 0 then yield ?
else do
first,rest ?FIRST(goals), REST(goals)
for each ? in FOL_BACKWARD_OR(KB, SUBST(?, first), ?) do
for each ? in FOL_BACKWARD_AND(KB, rest , ?_) do
yield 

Above illustrated is a simple backward chaining algorithm under FOPL.

Example of Backward Chaining in FOPL

Let’s solve the previous section example of Forward Chaining in FOPL using Backward Chaining.

Consider the below axioms:

1) Gita loves all types of clothes.

2) Suits are clothes.

3) Jackets are clothes.

4)Anything any wear and isn’t bad is clothes.

5) Sita wears skirt and is good.

6) Renu wears anything Sita wears.

Apply backward chaining and prove that Gita loves Kurtis.

Solution: Convert the given axioms into FOPL as:

  1. x: clothes(x)?loves(Gita, x).
  2. Suits(x)?Clothes(x).
  3. Jackets(x)?Clothes(x).
  4. wears(x,y)?? ¬bad(y)?Clothes(x)
  5. wears(Sita,skirt)? ¬good(Sita)
  6. wears(Sita,x)?wears(Renu,x)

To prove: Gita loves Kurtis.

FOPL: loves(Gita, Kurtis).

Apply backward chaining in the below graph: 

Backward Chaining in AI

It is clear from the above graph Gita wears Kurtis and does not look bad. Hence, Gita loves Kurtis.

Note: We have seen that the graph of forward and backward chaining is same. It means that forward chaining follows the bottom-up approach and backward chaining follows the top-down approach.


Related Topics

Utility Functions in Artificial Intelligence

The agents use the utility theory for making decisions. It is the mapping from lotteries to the real numbers. An agent is supposed to have various preferences and can choose the one...

3 minutes read.

Unsupervised Learning in AI

Unsupervised Learning in AI Unsupervised LearningIntroductionClusteringComparison between Supervised, Unsupervised, and Reinforcement Learning. Unsupervised Learning This is the third major category of Machine Learning. Unsupervised learning happens when we have data without additional feedback,...

2 minutes read.

Information Retrieval

Information Retrieval: In order to analyze and categorize the text, we'd like to be able to figure out information about the text, some meaning about the text as well. And,...

14 minutes read.

Probabilistic Reasoning

Probabilistic Reasoning Probabilistic Reasoning is the study of building network models which can reason under uncertainty, following the principles of probability theory. Bayesian Networks Bayesian network is a data structure which is used to represent the dependencies among variables....

7 minutes read.

Uninformed Search Strategies - Artificial Intelligence

Breadth-first search (BFS) It is a simple search strategy where the root node is expanded first, then covering all other successors of the root node, further move to expand the next...

8 minutes read.

Inference Rules in Proposition Logic

Inference rules are those rules which are used to describe certain conclusions. The inferred conclusions lead to the desired goal state. In propositional logic, there are various inference rules which can be applied to...

3 minutes read.

Intelligent Agents | Agents in AI

What is an Agent? An agent can be viewed as anything that perceives its environment through sensors and acts upon that environment through actuators. For example, human being perceives their surroundings through...

8 minutes read.

Integration of Blockchain and Artificial Intelligence

A Blockchain is a shared database or ledger where pieces of data are stored in data structures known as blocks. So, we can say that Blockchain is the distribution storage...

6 minutes read.

The Wumpus World

The Wumpus world is a game playing which provides an environment to the knowledge-based agent to showcase its stored knowledge. It was developed by Gregory Yob in 1973. About the game:  It...

3 minutes read.

Heuristic Functions in Artificial Intelligence

Heuristic Functions in AI: As we have already seen that an informed search make use of heuristic functions in order to reach the goal node in a more prominent way....

3 minutes read.

Hill Climbing Algorithm in AI

Hill Climbing Algorithm: Hill climbing search is a local search problem. The purpose of the hill climbing search is to climb a hill and reach the topmost peak/ point of...

4 minutes read.

Alpha-beta Pruning | Artificial Intelligence

Alpha-beta pruning is an advance version of MINIMAX algorithm. The drawback of minimax strategy is that it explores each node in the tree deeply to provide the best path among all the...

3 minutes read.

Backward Chaining in AI: Artificial Intelligence

Backward Chaining is a backward approach which works in the backward direction. It begins its journey from the back of the goal. Like, forward chaining, we have backward chaining for Propositional logic as...

6 minutes read.

Cryptarithmetic Problem in AI

Cryptarithmetic Problem Cryptarithmetic Problem is a type of constraint satisfaction problem where the game is about digits and its unique replacement either with alphabets or other symbols. In cryptarithmetic problem, the...

3 minutes read.

Top 10 Artificial Intelligence Technologies in 2024

Artificial Intelligence Technologies in 2020 1. Augmented Reality This is one of the most fascinating technology nowadays. Augmented Reality is the use of text, graphics, audio, etc. in real time. In Simple...

4 minutes read.

Natural Language Processing

Natural Language Processing in AI Topics Covered in Language Module Natural Language ProcessingSyntax and SemanticsContext-Free GrammarNLTKN-gramsTokenizationBag of WordsNaïve Bayes In language, we will cover how Artificial Intelligence is used to process human language...

13 minutes read.

Artificial Satellites

Many objects like stars, satellites and the moon are visible in the night sky. Satellites are objects revolving around the planet or a more significant object. Moon is the most...

6 minutes read.

Quantifying Uncertainty

The concept of quantifying uncertainty relies on how an agent can keep away uncertainty with a degree of belief. The term uncertainty refers to that situation or information which is either unknown or...

5 minutes read.

Hidden Markov Models

Hidden Markov Model is a partially observable model, where the agent partially observes the states. This model is based on the statistical Markov model, where a system being modeled follows the Markov process...

4 minutes read.

Problem-solving in Artificial Intelligence

The reflex agents are known as the simplest agents because they directly map states into actions. Unfortunately, these agents fail to operate in an environment where the mapping is too large to...

7 minutes read.