Join rules are rules with multiple atoms in the body. They define facts of the head predicate, given facts of the body.
project(Z,X) <- employee(X), department(Y,X).
For each employee X in a department Y, there exists a project Z in which they participate.If the atoms in the body do not have variables in common, the Cartesian product is assumed.
employee("Jack").employee("Ruth").department("science").department("finance").canWork(X, Y, Z) <- employee(X), department(Y).@output("canWork").
Any employee X can work in any department Y on some unknown project Z. The expected result:
Constants can appear in the atoms of the rules.When they appear in the head, they denote specific constant values to be generated in the head facts.When they appear in the body, they denote specific filters, or selection criteria, to be applied to the facts considered in the rule.
Any junior employee X will have a “basic” contract with stipend 20. Any senior employee X will have an “advanced” contract with stipend 40. The constants filter the facts to which the rules apply, so the basic contract rule applies only to Mark, and the advanced contract rule applies only to Ruth.The expected result: