Conceptually, a rule is very simple:
if A B C then D E
Meaning, "if A, B and C are true, then D and E are also true". These are often called if-then rules.
And what are A, B, C, D and E?
Premises and Conclusions
Rules have two parts to them: an if part (containing a list of statements called the premises), and a then part (containing a list of statements called the conclusions).
Pyke doesn't use the words if and then, as you'll see shortly.
Processing the Premises Within the If Clause
Because each premise with the if clause is a generalized statement, the premise is pattern matched to known facts. This means that it may match more than one fact.
Pyke tries all combinations of matching facts through a process called backtracking. This will cause the same rule to potentially succeed multiple times, once for each unique combination of matching facts.
Note that while processing the list of premises within a rule's if clause:
- If Pyke succeeds at proving a premise:
- Pyke will proceed down to the next premise in the list.
- Trying to proceed down from the last premise in the list (when it succeeds) causes the rule to succeed.
- If Pyke fails at proving a premise:
- Pyke will back up to the prior premise in the list and try to find another solution for it. The process starts over at the prior premise, going back down or further up the list depending on whether another solution can be found to the prior premise or not.
- Trying to back up from the first premise in the list (when it fails) causes the rule to fail.
Thus, execution within each rule's if clause proceeds both backwards and forwards, up and down the list of premises, depending on whether each premise succeeds or fails. The process of backing up within the if clause to try alternate solutions is called backtracking.
Rules are specified individually within a rule base. They are not nested or explicitly linked to each other. So Pyke must automatically figure out how to combine these rules to accomplish some larger task. This is called inferencing and there are two different approaches that Pyke uses:
- All forward-chaining rules are processed when a rule base is activated.
- Backward-chaining rules are processed when your program asks Pyke to
prove a specific goal (i.e., asks Pyke a question).
- These rules are designed to answer a question rather than assert new facts or activate more specific rule bases.
- They also have the ability to assemble Python functions into a customized call graph or program, called a plan, to meet a specific need.