# Forward and Backward Chaining Algorithm in Artificial Intelligence

## Forward Chaining:

The process of instantiating the left side of rules, executing them from left to right matching the left part of the sentence with the existing expression and if the match occurs then replacing it with the right part of the rule is called as Forward Chaining or Forward Reasoning.

In the next step, this right-hand side of the previous rule is considered as the left side of the present rule to find the applicability of a rule. So the finding of the rule becomes Subgoals to be fulfilled. These subgoals may, in turn, cause new subgoals to be established and so on until the facts are found to match the lowest subgoal conditions. Whenever the goal is achieved, the search process stops.

### Forward Chaining Algorithm:

Repeat: Collect the rule whose condition matches a fact in the database.
Do actions indicated by the rule – added facts to the database or delete facts from working memory.

Until: Problem is solved or no condition matches

Repeat: Collect the rules whose conditions match facts in the database.
If more than one rule matches
then use a conflict resolution strategy to eliminate all but one
else
do actions indicated by the rules

## Backward Chaining:

It is a process of reasoning in which within a rule, it matches the existing state with the right-hand part of the rule and if the match occurs, it is replaced by the left-hand side of the rule.

### Backward Chaining Algorithm:

Step-1: Prove goal G
Step-2: Find a rule which can be used to conclude G
Step-3: Try to prove each of that rules conditions