46.1k views
5 votes
Given the following Prolog clauses:

ancestor(X, Y):- ancestor(2, Y), parent(X, Z).
ancestor(x,x).
parent(amy, bob).

Explain, using a search tree of subgoals, why Prolog fails to answer when the given the goal ancestor(x, bob).

1 Answer

5 votes

Final answer:

Prolog fails to resolve the goal 'ancestor(x, bob)' because it cannot find a rule to match 'ancestor' with '2' as the first argument, and 'x' is treated as a specific individual rather than a variable.

Step-by-step explanation:

The question pertains to understanding how the Prolog programming language resolves a given goal through its backward chaining mechanism. When provided with the goal ancestor(x, bob), Prolog constructs a search tree of subgoals to try and find a match. This entails looking at possible resolutions for the predicate 'ancestor' based on the clauses provided.

From the clauses given:

  • ancestor(X, Y):- ancestor(2, Y), parent(X, Z).
  • ancestor(x,x).
  • parent(amy, bob).

Prolog starts at the first clause. However, the literal 'ancestor(2, Y)' is problematic because there's no matching rule that defines 'ancestor' with '2' as the first argument, causing the search to fail at this point. The second clause 'ancestor(x,x)' doesn't help either because 'x' does not unify with 'bob'. The symbol 'x' in the clause 'ancestor(x,x)' is interpreted as a specific individual named 'x', not as a variable, due to the lowercase starting letter which is another reason Prolog fails to answer the goal ancestor(x, bob).

User Walid Bousseta
by
8.9k points