-1

For example if I have this ancestors, how can I say who is the bastard son or daughter?

ancestor(frank,mary).
ancestor(frank,andrew).
ancestor(frank,jake).
ancestor(joanne,mary).
ancestor(joanne,andrew).

married(frank,joanne).

laws (there are some more code that I am not posting because it is no relevant)

mother(X,Y) :- ancester(X,Y),gender(X,female).
father(X,Y) :- ancester(X,Y),gender(X,male).

son(X,Y) :- father(Y,X).

sister(X,Y) :- ancester(Z,X),ancester(Z,Y),X\==Y,gender(Y,female).
brother(X,Y) :- ancester(Z,Y),ancester(Z,X), X\==Y,gender(Y,male).

grandfahter(X,Y) :- ancester(X,Z),ancester(Z,Y),gender(X,male).
grandmother(X,Y) :- ancester(X,Z),ancester(Z,Y),gender(X,female).
user229044
  • 232,980
  • 40
  • 330
  • 338
  • 3
    By the definition of "bastard," I would think you'd need some facts indicating who is married to whom. You really can't tell who the "bastards" are just by sireship which is all your facts show. – lurker Mar 07 '17 at 19:11
  • @lurker I have edited, and said: married(frank,joanne). – Afonso Pinto Mar 07 '17 at 19:39
  • Good, so now you can tell if someone is a bastard (their parents aren't married). For example, `bastard(X) :- father(F, X), mother(M, X), \+ married(F, M).` – lurker Mar 07 '17 at 20:18
  • @lurker thanks, appreciate your help! – Afonso Pinto Mar 07 '17 at 21:27
  • does it exists another way instead probably of "\+" beacause it is giving me this error: `bastard(X) :- father(F, X), mother(M, X), \+ married(F, M). syntax error in parser ` @lurker – Afonso Pinto Mar 07 '17 at 21:33
  • @AlfonsoPinto what Prolog are you using? The `\+` is ISO, so it should work in any ISO compliant Prolog. Are you sure the error is pointing to that code? It works in GNU Prolog and in SWI Prolog. Check for typing errors. – lurker Mar 07 '17 at 21:35
  • SWI-Prolog also supports `not` but indeed, the newer code should use `\+`. – Alexander Serebrenik Mar 08 '17 at 20:15
  • indeed, I used `not` and it worked! @AlexanderSerebrenik – Afonso Pinto Mar 09 '17 at 19:14

1 Answers1

0

Just to summarise the answer to this question based on the comments.

Assuming that the person is a bastard if their parents aren't married, one can write

bastard(X) :- father(F, X), mother(M, X), \+ married(F, M).

If your Prolog dialect does not support \+ (despite of it being in the ISO standard), you should use not:

bastard(X) :- father(F, X), mother(M, X), not(married(F, M)).

Alexander Serebrenik
  • 3,567
  • 2
  • 16
  • 32