Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Consider these Prolog rules: edged (1, 2). edge(2, 3). edge(3, 4). edged (1, 3).

ID: 3837196 • Letter: C

Question

Consider these Prolog rules: edged (1, 2). edge(2, 3). edge(3, 4). edged (1, 3). path(X, Y):- edge(X, Y). path(X, Y):- edge(X, Z), path(Z, Y). Your job on this problem is to show your understanding of the unification mechanism by listing the answers, in order, to the query path(X, Y), assuming that the user keeps hitting the semi-colon. You will be scored based on whether you list all the solutions the unification mechanism will find, and whether the solutions are given in the correct order (make the order clear-list them one per line in a column, starting new columns as needed). If you think Prolog will reach stack overflow, or just never return, or will produce infinitely many solutions, say so.

Explanation / Answer

The solution to the query in prolog programming is to find the values to be substituted into the variables in the query such that query will be satisfied.In other words "for what values will this query be true".

For the given query path(x,y) there are two rules we need to check

path(x,y):-edge(x,y)

path(x,y):-edge(x,z),edge(z,y).

SOLUTION

for path(x,y):-edge(x,y).

x = 1 ,y=2;

x = 2, y=3;

x=3,y=4;

x=1,y=3;

no

for path(x,y) :- edge(x,z) , path(z,y).

x=1,y=3,z=2;

no

EXPLANATION FOR SOLUTION:

For the query path(x,y) : - edge(x,y)

path(x,y) is true if there is an edge between x and y. the following values of x & y match these criteria

x = 1 ,y=2;

x = 2, y=3;

x=3,y=4;

x=1,y=3;

no

and the last value is "no" because there are no further values that satisfy the query path(x,y):-edge(x,y)

For second rule path(x,y) :-edge(x,z),path(z,y).

i.e for path(x,y) to be true there must be edge between x and z AND there must be a path between z and y. if both these conditions are met then path(x,y) will be true.

the only values of x,y,z that matches the above critieria is x=1,y=3,z=2 . we can arrive these values by substituting all the possible values and checking whether they match the criteria above(edge between x and z AND there must be a path between z and y) as there is a edge between 1 and 2 (edge(1,2)) and path(2,3) is true because there is a edge(2,3) is true.

as said above "no" because there are further values that satisfy this condition.

FINAL SOLUTION:

As final solution will be combined of both the above solutions

x = 1 ,y=2;

x = 2, y=3;

x=3,y=4;

x=1,y=3;

x=1,y=3,z=2;

no