Queries
A query is a nameless rule, so it translates the same way. Asking what is reachable from one station:
?- reach("Taipei Main Station", Y).
The constant in column #1 is a filter; the variable Y in column #2 is what we keep:
π#2( σ#1 = "Taipei Main Station"( reach ) )
Two goals that share all their variables intersect: the handout's
?- prime(N), even(N) is prime ∩ even.
Everything that held for rule bodies holds for queries.