eyedia

Alternatives

Two ways out of Paris, and three ways of asking about them.

alternatives.pl · output · proof · check · try it in the playground


The question

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.


What we tell Eyedia

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”.


The three questions

true :+ route(paris, To).
true :+ (train(paris, brussels); bus(paris, lille)).
true :+ once(route(paris, To)).

A line of the form true :+ Question. tells Eyedia to answer that question.


What Eyedia concludes

route(paris, brussels).
route(paris, lille).
;(train(paris, brussels), bus(paris, lille)).
once(route(paris, brussels)).

Why: the proof in plain words

  1. Paris to Brussels by train — fact 1.
  2. So there is a route Paris to Brussels — rule 3, the train alternative.
  3. Paris to Lille by bus — fact 2.
  4. So there is a route Paris to Lille — rule 4, the bus alternative.
  5. “Train to Brussels or bus to Lille” holds — because the first half does (step 1). One true side is enough for an “or”.
  6. “Once, a route” gives Brussels — because of step 2.

Checked, not just claimed

A separate checker reads the proof against the program. The report says:

Verdict: checked.


Try it

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.


Takeaway

“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.