Question: Consider the following Prolog program: edge(a, b). edge(c, d). edge(a, c). edge(c, b). edge(X, Y) :- edge(Y, X). path(X, X). path(X, Y) :- edge(Z, Y),
Consider the following Prolog program:
edge(a, b).
edge(c, d).
edge(a, c).
edge(c, b).
edge(X, Y) :- edge(Y, X).
path(X, X).
path(X, Y) :- edge(Z, Y),
path(X, Z).
Note that this program is nearly identical to one presented in lecture except for the inclusion of the extra rule: edge(X, Y) :- edge(Y, X).
The intent is that, with this additional rule, the program should model an undirected (as opposed to directed) graph.
(a) Execute the query: ?- edge(a,b). What response do you get?
(b) Execute the query ?- edge(b,a). What response do you get?
(c) Execute the query ?- edge(a, d). What response do you get? And why?
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
