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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started