0
votes

Here's the relevant code:

married(X,Y) :- wife(X,Y);husband(X,Y).

parent(X,Y) :- father(X,Y) ;mother(X,Y).

brother(X,Y) :-
man(X),
parent(Z,X),
parent(Z,Y),
X \= Y.

brother_in_law(X,Y) :-
brother(X,Z),married(Z,Y).

I've googled and it seems other have been using the exact code for the brother in law predicate so it should be fine? I checked the other predicates and they seem good too.. not sure what is happening.

Also, by not working I mean that it's not acknowledging the relevant relation when I check.

1
Where are your facts and what is your actual query that isn't working? - Daniel Lyons
pastebin.com/UcEcNmqx brother_in_law(prins-daniel, Y). - Rattletrap
This database is rather large, it might not even contain the situation you are looking for. Could you add a small number of facts (this should be doable in about 5) where you expect the program to work? It's much easier to debug then. - lambda.xy.x

1 Answers

2
votes

Look at the trace and you will see the problem:

?- trace,  brother_in_law(prins-daniel, Y).
   Call: (9) brother_in_law(prins-daniel, _11346) ? creep
   Call: (10) brother(prins-daniel, _11680) ? creep
   Call: (11) man(prins-daniel) ? creep
   Exit: (11) man(prins-daniel) ? creep
   Call: (11) parent(_11678, prins-daniel) ? creep
   Call: (12) father(_11678, prins-daniel) ? creep
   Fail: (12) father(_11678, prins-daniel) ? creep
   Redo: (11) parent(_11678, prins-daniel) ? creep
   Call: (12) mother(_11678, prins-daniel) ? creep
   Fail: (12) mother(_11678, prins-daniel) ? creep
   Fail: (11) parent(_11678, prins-daniel) ? creep
   Redo: (11) man(prins-daniel) ? creep
   Fail: (11) man(prins-daniel) ? creep
   Fail: (10) brother(prins-daniel, _11680) ? creep
   Fail: (9) brother_in_law(prins-daniel, _11346) ? creep
false.

Who is prins-daniel's father? You don't have a fact for that. Who is prins-daniel's mother? You don't have a fact for that either. As a result, you can't find any brothers, so the query fails.

Does this mean you are missing facts or missing code? The code says X and Y are brothers-in-law if X has a brother Z who is married to Y. Is this the only way to have a brother-in-law?

Side note: prins-daniel is not an atom in Prolog as it would be in Lisp. This is a term:

?- write_canonical(prins-daniel).
-(prins,daniel)

The situation is compounded by longer terms:

?- write_canonical(johann-georg-av-hohenzollern).
-(-(-(johann,georg),av),hohenzollern)

Just something to be aware of.