General forward chaining Pseudo code :
- For all rules and assertions, find all matches i.e. Rule + Assertion combinations
- Check if any of the matches are defunct i.e. where consequent of the match is already in DB
- Run the first non defunct match
- Repeat until no match left to run
In forward chaining rule, please take special care for delete because it may lead to infinite loop.
General Backwards Chaining Pseudo Code:
- Check hypothesis against DB. If satisfied, exit
- Find all matching rule: any rule with a consequent that matches hypothesis
- For each rule
- Binding <-- Unify rule , consequent and hypothesis
- Subtree <-- Antecedents_goal_tree(rule,rules,binding,DB)
- Optimization <-- If subtree evaluation returns true we can short circuit subtree
return OR(rule subtree)
Function Antecedents_goal_tree(rule,rules,binding,DB):
For each antecedent:
- new_hypothesis <-- antecedent + Binding
- Check new_hypothesis against DB , if matched update Binding. If multiple matches found OR them to create new subtree.
- subtree <-- Run above function
- Optimization <-- Short circuit for AND & OR
Related