The connects Link

The Automated Tourist Guide might attempt to answer a tourist's question such as "What is near the Planetarium?" by a call on the query

?- near('the Planetarium', What).

which would, if the corresponding fact is in the database, return What = `Madame Tussauds'. The reverse query, "What is near Madame Tussauds?" would simply return no, however, unless the statement

near('Madame Tussauds', `the Planetarium').

was also explicitly given in the database. Simple Prolog queries, in other words, cannot imitate our human intuition that, if X is near to Y, then Y is also near to X. We therefore need to write a predicate that will make the correct inference, whichever way around the query is called. This can be done as follows:

near(From, To):-
link(From, To).
near(From, To):-
link(To, From).>
A call on the query

?- near('Madame Tussauds', `the Planetarium').

will then return the correct answer. [@to be completed]