Backward chaining

Also known as: goal-driven reasoning

On this page 7

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.

StepWhat the engine doesOutcome
Select goalTakes the leftmost pending goalOne goal to prove
MatchFinds facts or rule heads that unify with the goalCandidate clauses and variable bindings
ExpandReplaces the goal with the body of the chosen ruleNew subgoals added to the stack
SucceedGoal matches a fact directlyBindings returned to the caller
BacktrackUndoes bindings after a failureNext alternative is tried
FailNo alternatives remainGoal reported as unprovable
Steps in a backward-chaining cycle

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.

ConceptRole in backward chainingPractical consequence
Horn clauseStandard rule formatGuarantees a simple, sound proof procedure
UnificationMatches goals with rule headsSupports variables and structured terms
SLD resolutionFormal proof strategyDefines the meaning of Prolog programs
Negation as failureTreats unprovable goals as falseRequires a closed-world view of data
TablingMemoizes subgoal answersPrevents infinite loops on recursive rules
Logical building blocks of backward chaining

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.

CriterionBackward chainingForward chaining
Starting pointGoal or queryKnown facts
Search directionConclusions to premisesPremises to conclusions
Work performedOnly goal-relevant rulesAll rules whose conditions hold
Typical useDiagnosis, queries, eligibilityMonitoring, alerting, configuration
Explanation styleAnswers why a goal holdsShows how facts led to results
Main riskInfinite recursion on cyclic rulesMany irrelevant derived facts
Backward and forward chaining side by side

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.

ApplicationTypical goalWhy it fits
Medical diagnosisIs infection X presentAsks only relevant questions
Loan eligibilityDoes the applicant qualifyProduces an auditable rule trace
Fault isolationWhich component failedTests hypotheses one at a time
Logic programmingDoes the query succeedNative Prolog execution model
Access controlIs this request permittedEvaluates only the applicable policies
Typical applications and why backward chaining fits

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.