Rules
Rules are the core mechanism for representing logical inference in DS. This page explains how rules work and how to use them.
Rule Structure
A rule consists of:
- Premises: Zero or more conditions (above the line)
- Conclusion: The result when all premises are satisfied (below the line)
Text Representation
Rules are written with premises and conclusion separated by dashes (at least four dashes):
| premise1
premise2
----------
conclusion
|
A fact is a rule with no premises:
Or explicitly:
| ----------
(parent john mary)
|
Rule Format Details
- Premises are separated by newlines
- The separator line must contain at least 4 dashes (
----) between premises and conclusion
- Whitespace around premises and conclusion is trimmed
- A rule without an premises is a fact
For rules with multiple premises, you can use space-separated terms on a single line:
This is equivalent to:
| (`P -> `Q)
`P
----------
`Q
|
The last term is the conclusion, and all preceding terms are premises.
Examples
Modus Ponens (if P implies Q and P is true, then Q is true):
| (`P -> `Q)
`P
----------
`Q
|
Family Relationship (if X is the father of Y, then X is a parent of Y):
| (father `X `Y)
----------
(parent `X `Y)
|
Creating Rules
Rule Operations
Grounding
Grounding substitutes variables in a rule with values from a dictionary.
Matching
Matching unifies the first premise of a rule with a fact, producing a new rule with one fewer premise.
Renaming
Renaming adds prefixes and/or suffixes to all variables in a rule.
Rule Comparison
Rules can be compared for equality. Two rules are equal if they have the same binary representation.
See Also