# What is backward chaining?

by Stephen M. Walker II, Co-Founder / CEO

## What is backward chaining?

Backward chaining in AI is a goal-driven, top-down approach to reasoning, where the system starts with a goal or conclusion and works backward to find the necessary conditions and rules that lead to that goal. It is commonly used in expert systems, automated theorem provers, inference engines, proof assistants, and other AI applications that require logical reasoning. The process involves looking for rules that could have resulted in the conclusion and then recursively looking for facts that satisfy these rules until the initial conditions are met. This method typically employs a depth-first search strategy and is often contrasted with forward chaining, which is data-driven and works from the beginning to the end of a logic sequence.

In practice, backward chaining is implemented in logic programming languages like Prolog, where an inference engine searches through rules to find one that concludes with the goal and then attempts to satisfy the rule's premises with known facts or further rules. This process repeats until all necessary facts are proven true or the search fails to find supporting evidence for the goal.

Backward chaining is particularly useful in situations where there are many possible solutions, and the goal is to find the most appropriate one based on the given constraints or desired outcomes. It is also beneficial when the number of goals is small compared to the number of facts, as it can be more efficient than forward chaining in such cases.

## How does backward chaining differ from forward chaining?

Backward chaining and forward chaining are both strategies used in artificial intelligence (AI) for reasoning and problem-solving, but they differ in their approach, direction of reasoning, search strategy, and typical use cases.

1. Approach and Direction of Reasoning — Backward chaining starts with a goal and works backward to find known facts that support the goal. It is a goal-driven, top-down approach to reasoning. On the other hand, forward chaining starts with simple facts in the knowledge base and applies inference rules in the forward direction to extract more data until a goal is reached. It is a data-driven, bottom-up approach to reasoning.

2. Search Strategy — Backward chaining employs a depth-first search strategy, where it explores as far as possible along each branch before backtracking. In contrast, forward chaining uses a breadth-first search strategy, where it explores all the neighboring nodes at the present depth before moving on to nodes at the next depth level.

3. Use Cases — Backward chaining is typically used in automated inference engines, theorem proofs, proof assistants, and other AI applications that require logical reasoning. It is particularly useful for analyzing historical data and finding the most appropriate solution based on given constraints or desired outcomes. Forward chaining, on the other hand, is used for planning, monitoring, control, interpretation applications, and predicting future outcomes. It is beneficial when the number of facts is large compared to the number of goals.

4. Speed and Efficiency — Forward chaining can be slower because it checks all the rules, whereas backward chaining is faster because it only checks the rules that are required. However, the efficiency of either method can depend on the specific problem and the structure of the knowledge base.

## What are the benefits of backward chaining?

Backward chaining is a goal-driven approach used in artificial intelligence (AI) to solve complex problems. It offers several benefits:

1. Efficiency — Backward chaining is faster than forward chaining because it only checks the rules that are relevant to the goal, rather than all the rules in the system.
2. Goal-Oriented — It starts with the goal and works backward, making it suitable for problems where the endpoint is known.
3. Multiple Conclusions — It can be used to draw multiple conclusions, providing a good basis for arriving at solutions.
4. Use in Complex Problems — Backward chaining is often used in complex problem-solving scenarios, such as in game theory, automated theorem proving tools, inference engines, and proof assistants.

## What are the drawbacks of backward chaining?

Despite its benefits, backward chaining also has some limitations:

1. Single Answer — Backward chaining typically provides a single answer, which may limit its applicability in scenarios where multiple solutions are possible.
2. Less Flexibility — Compared to forward chaining, backward chaining is less flexible because it only infers information that is required.
3. Known Endpoint Required — It is suitable only if the endpoint or goal is known. If the goal is not clear, backward chaining may not be the best approach.
4. Execution Difficulty — It can be difficult to execute, especially in complex systems with numerous rules and facts.

## How does backward chaining work?

Backward chaining is a form of reasoning that starts with the goal and works backward, chaining through rules to find known facts that support the goal. It is often used in expert systems in AI, where it begins with a hypothesis and works backward through the data to find evidence to support or refute the hypothesis. This process continues until a conclusion is reached or all paths have been explored.

## What are some examples of backward chaining?

1. MYCIN — This is an early AI system developed at Stanford University in the 1970s. MYCIN used backward chaining to identify severe bacterial infections and recommend treatments.
2. Diagnosing Blood Cancer — Backward chaining can be used to diagnose diseases. For example, if the goal is to diagnose blood cancer, the system would start with this hypothesis and work backward through the patient's symptoms and test results to confirm or refute the diagnosis.
3. Game Theory — In game theory, backward chaining can be used to determine the optimal strategy by starting with a desired outcome and working backward to find the best moves to achieve that outcome.

## More terms

### Stephen Wolfram

Stephen Wolfram is a British-American computer scientist, physicist, and businessman. He is known for his work in theoretical particle physics, cellular automata, complexity theory, and computer algebra. He is the founder and CEO of the software company Wolfram Research where he worked as the lead developer of Mathematica and the Wolfram Alpha answer engine.

### What is first-order logic?

First-order logic (FOL), also known as first-order predicate calculus or quantificational logic, is a system of formal logic that provides a way to formalize natural languages into a computable format. It is an extension of propositional logic, which is less expressive as it can only represent information as either true or false. In contrast, FOL allows the use of sentences that contain variables, enabling more complex representations and assertions of relationships among certain elements.