When we have only a few facts and many possible inference rules, it is often more efficient to consider each fact in turn and find what it matches in the rules. That gives the following algorithm:


Hybrid backward-forward chaining algorithm:
1. Apply subroutine "one-cycle" to the list of all rules without negations
2. Apply "one-cycle" to the list of all rules.
Subroutine "one-cycle":
1. Take the rules in order (one "cycle"):
(i) Find every way to get the rule to succeed by matching to the current set of facts (taking facts in order). Backtrack to ensure you try all possible bindings. Execute arithmetic and list-processing expressions as subroutine calls.
(ii) Add each new fact you prove at the bottom of the set of facts.
2. If no new facts were proved from any rule, stop. Else go to step 1.
As an example, click through the following demonstration of hybrid chaining. Step 0