Backward chaining is a goal-driven inference strategy that starts from a hypothesis or query and works backward through rules, looking for facts that would make the goal true. In Symbolic AI & reasoning, it is one of the two classic ways to apply if-then rules to a knowledge base, the other being forward chaining, and it is also known as goal-driven reasoning.
The method underlies Prolog execution, many diagnostic expert systems and modern rule engines that answer specific questions. Its key strength is focus: it only touches the rules and facts relevant to the current question, which makes it efficient when the space of possible conclusions is large but each query is narrow.
How backward chaining resolves a goal
Backward chaining resolves a goal by recursively replacing it with subgoals until every subgoal is either a known fact or impossible to prove. The engine looks for rules whose conclusion (head) matches the goal, then treats each condition in the rule body as a new goal to prove.
In first-order systems, matching is done by unification, which binds variables so that the goal and the rule head become identical. If a subgoal fails, the engine backtracks to the most recent choice point and tries the next matching rule or fact. The result is a depth-first search over an AND-OR tree: alternative rules form OR branches, and the conditions within one rule form AND branches that must all succeed.
The following table traces the main steps of a typical backward-chaining cycle and what each step produces.
| Step | What the engine does | Outcome |
|---|---|---|
| Select goal | Takes the leftmost pending goal | One goal to prove |
| Match | Finds facts or rule heads that unify with the goal | Candidate clauses and variable bindings |
| Expand | Replaces the goal with the body of the chosen rule | New subgoals added to the stack |
| Succeed | Goal matches a fact directly | Bindings returned to the caller |
| Backtrack | Undoes bindings after a failure | Next alternative is tried |
| Fail | No alternatives remain | Goal reported as unprovable |
Logical foundations and rule format
Backward chaining is complete and efficient for Horn clauses, which are rules with at most one positive literal, such as “grandparent(X, Z) if parent(X, Y) and parent(Y, Z)”. With Horn clauses, the procedure corresponds to SLD resolution, the proof method that gives logic programming its formal semantics.
Most practical engines adopt the closed-world assumption together with negation as failure: a goal that cannot be proven is treated as false. This is convenient for databases and configuration logic, but it differs from classical logic and from the open-world assumption used by ontology reasoners based on description logic.
The table below summarizes the logical ingredients and where each matters in practice.
| Concept | Role in backward chaining | Practical consequence |
|---|---|---|
| Horn clause | Standard rule format | Guarantees a simple, sound proof procedure |
| Unification | Matches goals with rule heads | Supports variables and structured terms |
| SLD resolution | Formal proof strategy | Defines the meaning of Prolog programs |
| Negation as failure | Treats unprovable goals as false | Requires a closed-world view of data |
| Tabling | Memoizes subgoal answers | Prevents infinite loops on recursive rules |
Backward chaining compared with forward chaining
Backward chaining differs from forward chaining mainly in direction and trigger: it starts from a question, whereas forward chaining starts from data and derives every conclusion that follows. Forward chaining suits monitoring and event processing, where new facts arrive continuously and the Rete algorithm can update conclusions incrementally.
Backward chaining suits diagnosis, eligibility checks and query answering, where the user asks a specific question. Many production systems are hybrid, using forward rules to maintain derived facts and backward rules to answer queries on demand.
| Criterion | Backward chaining | Forward chaining |
|---|---|---|
| Starting point | Goal or query | Known facts |
| Search direction | Conclusions to premises | Premises to conclusions |
| Work performed | Only goal-relevant rules | All rules whose conditions hold |
| Typical use | Diagnosis, queries, eligibility | Monitoring, alerting, configuration |
| Explanation style | Answers why a goal holds | Shows how facts led to results |
| Main risk | Infinite recursion on cyclic rules | Many irrelevant derived facts |
Where goal-driven reasoning is used
Goal-driven reasoning is used wherever a system must justify a specific conclusion rather than enumerate all of them. The classic medical expert system MYCIN used backward chaining to decide which bacterial infection hypotheses to pursue, asking the physician only for data needed by the current goal.
The same pattern appears in Prolog and Datalog query engines, business rule engines for insurance and lending, tax and benefit eligibility calculators, and the query side of semantic reasoners. Because the engine records which rules fired, it can produce a readable proof trace, which supports auditing and regulatory explanation.
| Application | Typical goal | Why it fits |
|---|---|---|
| Medical diagnosis | Is infection X present | Asks only relevant questions |
| Loan eligibility | Does the applicant qualify | Produces an auditable rule trace |
| Fault isolation | Which component failed | Tests hypotheses one at a time |
| Logic programming | Does the query succeed | Native Prolog execution model |
| Access control | Is this request permitted | Evaluates only the applicable policies |
Limitations and common mistakes
The most frequent failure is left recursion, where a rule calls itself before making progress and the depth-first engine loops forever. Rule order also matters: placing expensive or rarely true conditions first can cause exponential backtracking, and the same subgoal may be recomputed many times without tabling.
- Rewrite left-recursive rules or enable tabling when rules describe transitive relations such as ancestry or reachability.
- Order conditions by selectivity, so that cheap and restrictive tests run first.
- Remember that negation as failure gives wrong answers when the data is incomplete.
- Backward chaining alone is inefficient for deriving all consequences; use forward chaining or materialization for that task.
Put simply
Backward chaining is reasoning that starts with the question. Suppose you want to know if you can bake a cake. You do not list everything in your kitchen first. You ask what a cake needs. It needs flour, eggs and an oven. Then you check each item one by one.
If one item is missing, you look for another way to get it. If no way works, the answer is no. A computer does the same with rules. The key idea is to work backward from the goal and check only what matters for that goal.
In practice
A regional bank uses a rule engine to decide whether small business applicants qualify for a credit line of up to 50,000 dollars. The top goal is “applicant is eligible”. The engine finds the rule for that goal, which requires at least two years of trading, an acceptable debt-to-income ratio and no recent defaults. Each condition becomes a subgoal, and the engine queries the credit bureau only when the earlier subgoals succeed.
Because the engine stops at the first failing condition, an applicant with only one year of trading is rejected without any external credit check, which saves bureau fees and time. For every decision, the system stores the chain of rules that fired. When an applicant appeals, the loan officer can show the exact rule path behind the outcome, which satisfies the bank’s internal audit requirements.