Error of logic?

Asked

Viewed 141 times

5

I have the following code:

mãe(ana, eva).
mãe(eva, noé).
mãe(bia, raí).
mãe(bia, clô).
mãe(bia, ary).
mãe(lia, gal).
pai(ivo, eva).
pai(raí, noé).
pai(gil, raí).
pai(gil, clô).
pai(gil, ary).
pai(ary, gal).
avô(X, Y) :- pai(X, Z), pai(Z, Y); pai(X, Z), mãe(Z, Y).

When making the consultation:

avô(X, Y).

SWI-Prolog returns to me:

X = gil,
Y = noé ;
X = gil,
Y = gal ;
X = ivo,
Y = noé ;
false.

I thought it should return 'true', but I didn’t understand if I made a logic error because I can’t identify it, I would like to know the reason to return 'false' (I’m quite beginner). Thank you.

1 answer

5


There is no error in your code. Prolog is returning all pairs (X,Y) that satisfy the query avo(X,Y).

He would return true if Voce asked a question where both the "variables" X and Y "have some value":

avo(gil, noe)

for example.

  • Thank you for clarifying.

  • 1

    +1 just complementing: it returns false because you asked for "more results" (command ;) after all possible results had already been explored. That is, the false You mean, "More results? No."

Browser other questions tagged

You are not signed in. Login or sign up in order to post.