Two ways out of Paris, and three ways of asking about them.
alternatives.pl · output · proof · check · try it in the playground
From Paris you can take a train to Brussels, or a bus to Lille.
Everyday questions about choices come in different shapes:
This example asks all three, and shows the reasoning behind each answer.
Two facts, and two rules that both define a route:
train(paris, brussels).
bus(paris, lille).
route(From, To) :- train(From, To).
route(From, To) :- bus(From, To).
Two rules with the same name are alternatives: a route is a train
connection, or a bus connection. The :- means “work this out when someone
asks”.
true :+ route(paris, To).
true :+ (train(paris, brussels); bus(paris, lille)).
true :+ once(route(paris, To)).
To reachable from Paris.;, which means or: is either connection there?once: find the first route and commit to
it, without looking for more.A line of the form true :+ Question. tells Eyedia to answer that question.
route(paris, brussels).
route(paris, lille).
;(train(paris, brussels), bus(paris, lille)).
once(route(paris, brussels)).
A ; B in its standard spelling,
;(A, B).once picked Brussels, because the train rule comes first, and stopped there.A separate checker reads the proof against the program. The report says:
once) checked by confirming the step they rest on.Verdict: checked.
node bin/eyedia.js examples/alternatives.pl # the answers
node bin/eyedia.js --proof examples/alternatives.pl # answers with their proof
Or open it in the playground.
Add train(paris, amsterdam). after the bus line and run again: a third
route, route(paris, amsterdam), appears, but once still answers Brussels,
because that train fact still comes first.
“All of them”, “at least one” and “just the first” are different questions. Eyedia lets you say which one you mean, and its proof shows exactly which option answered.