Saying that something exists, without knowing what it is, and without mixing it up with anything else.
existential-rules.js · output · proof · check · try it in the playground
The question
Some rules conclude that something exists without saying what it is:
- every person has a parent, even when nobody knows who;
- every customer who ordered something has an invoice, not yet numbered;
- two colleagues meet, at some meeting.
How can a reasoner keep track of such unknowns without confusing one with another, or with anything it already knows?
Historical background
The chase grew out of work on database dependencies. Maier, Mendelzon and Sagiv used it to test what follows when dependencies constrain the rows a database may contain. Rules that require another object have a similar constructive reading: applying the rule supplies a witness, as with the parents and invoices here. Maier, Mendelzon and Sagiv, Testing Implications of Data Dependencies
What we tell eyemind
fact(person('ann'), person('bob')) // clauses 1, 2
implies(person(X), has_parent(X, P)) // clause 3
fact(has_parent('dan', 'eve'), has_parent('fay', 'eve')) // clauses 4, 5
implies([has_parent(X, P), has_parent(Y, P), not_identical(X, Y)], sibling(X, Y)) // clause 6
fact(ordered('carl', 'lamp'), ordered('carl', 'desk'), ordered('dora', 'chair')) // clauses 7, 8, 9
implies(ordered(C, Item), invoice_for(C, I)) // clause 10
implies(invoice_for(C, I), sent(I)) // clause 11
fact(colleagues('ann', 'dora')) // clause 12
implies(colleagues(X, Y), [meeting(M), attends(M, X), attends(M, Y)]) // clause 13
fact(...)states things true outright; onefactline with several items gives one numbered clause per item.implies(premise, conclusion)is a forward rule: whenever the premise holds, eyemind adds the conclusion. A premise or conclusion in square brackets is a list of parts that go together.- Capitalized names are variables: they stand for whatever value makes the rule fit.
not_identical(X, Y)is a built-in test: eyemind decides it itself (are X and Y different?) instead of looking it up in facts.
A variable that appears in a rule’s conclusion but not in its premise is an
unknown: an existential. In rule 3, P is some parent of X; in rule
10, I is some invoice for C; in rule 13, M is some meeting of X
and Y. In rule 11, by contrast, I comes from the premise, so it is not
an unknown.
What eyemind concludes
// Conclusions: the facts the program derives, in the order derived.
has_parent('ann', skolem(3, 'P', ['ann']))
has_parent('bob', skolem(3, 'P', ['bob']))
sibling('dan', 'fay')
sibling('fay', 'dan')
invoice_for('carl', skolem(10, 'I', ['carl']))
invoice_for('dora', skolem(10, 'I', ['dora']))
sent(skolem(10, 'I', ['carl']))
sent(skolem(10, 'I', ['dora']))
meeting(skolem(13, 'M', ['ann', 'dora']))
attends(skolem(13, 'M', ['ann', 'dora']), 'ann')
attends(skolem(13, 'M', ['ann', 'dora']), 'dora')
Each unknown became a Skolem term, a made-up name for “the one that
exists here”, written skolem(Rule, Variable, Values).
skolem(3, 'P', ['ann']) reads the P of rule 3, for Ann. The values
are those of the conclusion’s other variables when the rule fired: for rule
10 only C (Carl), not the item he ordered; for rule 13 both X and Y.
Such an invented name is also called a witness: it stands witness for the
thing that exists.
One witness per firing
Each time a rule applies to particular values is called a firing.
- Ann and Bob each get a parent of their own, the
Pof rule 3 for Ann and for Bob. Had they shared one, the sibling rule would have made them siblings by accident. Only Dan and Fay, whose parent the data names, are siblings. - Carl ordered twice, and gets one invoice. The invoice depends on Carl alone, not on what he ordered, so both orders give the same term.
- The meeting is one meeting. The three conclusions of one firing
share their witness, the
Mof rule 13 for Ann and Dora. - Invented values are values. The
sentrule uses the invoices like any other value. Whenever a rule meets the same values again, it gives back the same term, so reasoning comes to an end.
Never a clash
A Skolem term names the rule and the unknown it stands for, and the values it depends on, so it cannot be mistaken for anything else:
- not for a name in your data, which says nothing of rule 3’s
P; - not for another unknown, which belongs to another rule, another variable or other values.
And it is the same in every run: run the program twice, or read one run’s output into another, and the same unknown has the same name.
The proof, line by line
eyemind --proof writes down how it reached each conclusion. This is the
complete proof:
// Conclusions: the facts the program derives, in the order derived.
has_parent('ann', skolem(3, 'P', ['ann']))
has_parent('bob', skolem(3, 'P', ['bob']))
sibling('dan', 'fay')
sibling('fay', 'dan')
invoice_for('carl', skolem(10, 'I', ['carl']))
invoice_for('dora', skolem(10, 'I', ['dora']))
sent(skolem(10, 'I', ['carl']))
sent(skolem(10, 'I', ['dora']))
meeting(skolem(13, 'M', ['ann', 'dora']))
attends(skolem(13, 'M', ['ann', 'dora']), 'ann')
attends(skolem(13, 'M', ['ann', 'dora']), 'dora')
// Steps: each derived fact and what it rests on: the clause or control that
// justifies it, the bindings and the goals it uses.
step(has_parent('ann', skolem(3, 'P', ['ann'])), clause(3), {X: 'ann', P: skolem(3, 'P', ['ann'])}, [person('ann')])
step(has_parent('bob', skolem(3, 'P', ['bob'])), clause(3), {X: 'bob', P: skolem(3, 'P', ['bob'])}, [person('bob')])
step(sibling('dan', 'fay'), clause(6), {X: 'dan', P: 'eve', Y: 'fay'}, [has_parent('dan', 'eve'), has_parent('fay', 'eve'), not_identical('dan', 'fay')])
step(has_parent('dan', 'eve'), clause(4), {}, [])
step(has_parent('fay', 'eve'), clause(5), {}, [])
step(sibling('fay', 'dan'), clause(6), {X: 'fay', P: 'eve', Y: 'dan'}, [has_parent('fay', 'eve'), has_parent('dan', 'eve'), not_identical('fay', 'dan')])
step(invoice_for('carl', skolem(10, 'I', ['carl'])), clause(10), {C: 'carl', Item: 'lamp', I: skolem(10, 'I', ['carl'])}, [ordered('carl', 'lamp')])
step(invoice_for('dora', skolem(10, 'I', ['dora'])), clause(10), {C: 'dora', Item: 'chair', I: skolem(10, 'I', ['dora'])}, [ordered('dora', 'chair')])
step(sent(skolem(10, 'I', ['carl'])), clause(11), {C: 'carl', I: skolem(10, 'I', ['carl'])}, [invoice_for('carl', skolem(10, 'I', ['carl']))])
step(sent(skolem(10, 'I', ['dora'])), clause(11), {C: 'dora', I: skolem(10, 'I', ['dora'])}, [invoice_for('dora', skolem(10, 'I', ['dora']))])
step(meeting(skolem(13, 'M', ['ann', 'dora'])), clause(13), {X: 'ann', Y: 'dora', M: skolem(13, 'M', ['ann', 'dora'])}, [colleagues('ann', 'dora')])
step(attends(skolem(13, 'M', ['ann', 'dora']), 'ann'), clause(13), {X: 'ann', Y: 'dora', M: skolem(13, 'M', ['ann', 'dora'])}, [colleagues('ann', 'dora')])
step(attends(skolem(13, 'M', ['ann', 'dora']), 'dora'), clause(13), {X: 'ann', Y: 'dora', M: skolem(13, 'M', ['ann', 'dora'])}, [colleagues('ann', 'dora')])
// Certificate: the derived facts and every answer of each call the questions make.
derived(has_parent(A, B), [has_parent('ann', skolem(3, 'P', ['ann'])), has_parent('bob', skolem(3, 'P', ['bob']))])
derived(sibling(A, B), [sibling('dan', 'fay'), sibling('fay', 'dan')])
derived(invoice_for(A, B), [invoice_for('carl', skolem(10, 'I', ['carl'])), invoice_for('dora', skolem(10, 'I', ['dora']))])
derived(sent(A), [sent(skolem(10, 'I', ['carl'])), sent(skolem(10, 'I', ['dora']))])
derived(meeting(A), [meeting(skolem(13, 'M', ['ann', 'dora']))])
derived(attends(A, B), [attends(skolem(13, 'M', ['ann', 'dora']), 'ann'), attends(skolem(13, 'M', ['ann', 'dora']), 'dora')])
called(has_parent(A, B), [has_parent('ann', skolem(3, 'P', ['ann'])), has_parent('bob', skolem(3, 'P', ['bob'])), has_parent('dan', 'eve'), has_parent('fay', 'eve')])
called(sibling(C, D), [sibling('dan', 'fay'), sibling('fay', 'dan')])
called(has_parent(E, skolem(3, 'P', ['ann'])), [has_parent('ann', skolem(3, 'P', ['ann']))])
called(has_parent(E, skolem(3, 'P', ['bob'])), [has_parent('bob', skolem(3, 'P', ['bob']))])
called(has_parent(E, 'eve'), [has_parent('dan', 'eve'), has_parent('fay', 'eve')])
called(invoice_for(F, G), [invoice_for('carl', skolem(10, 'I', ['carl'])), invoice_for('dora', skolem(10, 'I', ['dora']))])
called(sent(H), [sent(skolem(10, 'I', ['carl'])), sent(skolem(10, 'I', ['dora']))])
called(meeting(I), [meeting(skolem(13, 'M', ['ann', 'dora']))])
called(attends(J, K), [attends(skolem(13, 'M', ['ann', 'dora']), 'ann'), attends(skolem(13, 'M', ['ann', 'dora']), 'dora')])
It has three parts:
- The claims: the 11 conclusions the proof is about.
- The steps: the firing behind each derived fact. A step reads
step(what, by which clause, with which values, using what), citing clauses by their place in the program. In the values, an invented thing is an ordinary value:P: skolem(3, 'P', ['ann']). Clause 8, Carl’s desk order, is cited nowhere: it would only give Carl the same invoice again (eyemind --unusedreports it). - The certificate: the listings
derived(Pattern, Facts)hold every fact the forward rules derived for each relation, and the call tablescalled(Call, Answers)every answer of each call made while answering the questions, here the heads of the forward rules.
Read the steps as sentences:
- Ann has the parent
skolem(3, 'P', ['ann']): by rule 3, withX= Ann andPthat invented name, because Ann is a person. - Bob has the parent
skolem(3, 'P', ['bob']): by rule 3, because Bob is a person. - Dan and Fay are siblings: by rule 6, with
P= Eve, because both have Eve as parent and Dan and Fay are different. - Dan’s parent is Eve: fact 4.
- Fay’s parent is Eve: fact 5.
- Fay and Dan are siblings: by rule 6 the other way round, reusing steps 5 and 4.
- Carl has the invoice
skolem(10, 'I', ['carl']): by rule 10, withItem= lamp, because Carl ordered a lamp. - Dora has the invoice
skolem(10, 'I', ['dora']): by rule 10, because Dora ordered a chair. - Carl’s invoice is sent: by rule 11, because of step 7.
- Dora’s invoice is sent: by rule 11, because of step 8.
- There is the meeting
skolem(13, 'M', ['ann', 'dora']): by rule 13, because Ann and Dora are colleagues. - Ann attends that meeting: by rule 13, the same firing.
- Dora attends that meeting: by rule 13, the same firing.
Steps 4 and 5 cite facts: has_parent is also a relation rule 3 concludes,
so the sibling rule’s calls on it rest on derived facts, and the proof shows
which clause gave each parent. The persons, orders and colleagues are stated
facts the checker reads from the program, and not_identical is a test it
decides itself.
Checked: what the report says
A proof is only worth something if someone else can check it. eyemind -c
generates the proof and checks it against the program; --check-proof checks
a saved proof. The checker never reasons by itself. It checks each call table
by applying the program one level, requires each listing to be closed under
the forward rules, and replays each listed fact’s step from its rule. On
replay, each invented name is recomputed: the checker builds the Skolem
term from the rule, the variable and the values it depends on, and requires
the step to use exactly that name. A proof cannot slip in a real name, or
another firing’s witness, where an unknown belongs. Finally the claims must
be exactly the answers of the questions, and a step, table or listing the
check does not use fails it. This is the complete report:
// Checked answers: these follow from the input program and are every answer of its questions.
has_parent('ann', skolem(3, 'P', ['ann']))
has_parent('bob', skolem(3, 'P', ['bob']))
sibling('dan', 'fay')
sibling('fay', 'dan')
invoice_for('carl', skolem(10, 'I', ['carl']))
invoice_for('dora', skolem(10, 'I', ['dora']))
sent(skolem(10, 'I', ['carl']))
sent(skolem(10, 'I', ['dora']))
meeting(skolem(13, 'M', ['ann', 'dora']))
attends(skolem(13, 'M', ['ann', 'dora']), 'ann')
attends(skolem(13, 'M', ['ann', 'dora']), 'dora')
verdict('checked')
The verdict is checked: all 11 conclusions follow from the program, and they are every answer of the original questions.
Try it
eyemind examples/existential-rules.js # the conclusions
eyemind --proof examples/existential-rules.js # with the proof
Or open it in the playground.
Add person('dan') to the first fact line and run again: Dan gets a
parent witness of his own as well, beside Eve, because the rule says only
that some parent exists. Every later clause moves up one number, so the
names change too: Dan’s parent is skolem(4, 'P', ['dan']), and Carl’s
invoice becomes skolem(11, 'I', ['carl']).
Takeaway
An existential rule says that something exists. eyemind names each such something by a Skolem function of what the rule knew: the same activation always gives the same name, and the name can never be mistaken for anything else.
