Advertisement
salmancreation

family tree

Feb 6th, 2018
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Prolog 3.74 KB | None | 0 0
  1. % parent(X,Y) means that person X is a parent (father or mother) of person Y
  2.  
  3. parent(alex,julia).
  4. parent(alex,rosa).
  5. parent(robi,alex).
  6. parent(robi,jon).
  7. parent(lina,julia).
  8. parent(lina,rosa).
  9. parent(romeo,peter).
  10. parent(julia,peter).
  11. parent(rosa,silvia).
  12. parent(oscar,ida).
  13. parent(eva,ida).
  14. parent(eva,bruno).
  15. parent(peter,bruno).
  16. parent(peter,georg).
  17. parent(peter,irma).
  18. parent(ruth,georg).
  19. parent(ruth,irma).
  20. parent(silvia,otto).
  21. parent(silvia,pascal).
  22. parent(irma,olga).
  23. parent(irma,jean).
  24. parent(otto,olga).
  25. parent(otto,jean).
  26. parent(jean,tina).
  27. parent(marie,tina).
  28.  
  29.  
  30. % male(X) means that X is a male person
  31.  
  32. male(alex).
  33. male(romeo).
  34. male(oscar).
  35. male(peter).
  36. male(bruno).
  37. male(georg).
  38. male(otto).
  39. male(pascal).
  40. male(jean).
  41. male(jon).
  42.  
  43.  
  44. % husband(X,Y) means that person X is the husband of person Y
  45.  
  46. husband(alex,lina).
  47. husband(romeo,julia).
  48. husband(oscar,eva).
  49. husband(peter,ruth).
  50. husband(otto,irma).
  51. husband(jean,marie).
  52.  
  53.  
  54. % female
  55. female(X) :- \+ male(X).
  56.  
  57. % father
  58. father(X,Y) :- parent(X,Y),male(X).
  59.  
  60. % mother
  61. mother(X,Y) :- parent(X,Y),female(X).
  62.  
  63. % son
  64. son(X,Y) :- male(X),parent(Y,X).
  65.  
  66. % daughter
  67. daughter(X,Y) :- female(X),parent(Y,X).
  68.  
  69. % sibling
  70. sibling(X,Y) :-
  71.     parent(Z, X),
  72.     parent(Z, Y),
  73.     X \= Y.
  74.  
  75.  
  76. % Brother
  77. brother(X,Y) :-
  78.     parent(Z, X),
  79.     parent(Z, Y),
  80.     X \= Y,
  81.     male(X).
  82.  
  83.  
  84. % sister
  85. sister(X,Y) :-
  86.     parent(Z, X),
  87.     parent(Z, Y),
  88.     X \= Y,
  89.     female(X).
  90.  
  91.  
  92.  
  93. % wife
  94. wife(X,Y) :-
  95.     female(X),
  96.     husband(Y,X).
  97.  
  98. %married
  99. married(X,Y) :-
  100.     husband(X,Y);
  101.     wife(X,Y).
  102.  
  103. % grandchild
  104. grandchild(X,Y) :-
  105.     parent(Z, X),
  106.     parent(Y, Z).
  107.  
  108.  
  109.  
  110. % grandparent
  111. grandparent(X,Y) :-
  112.     parent(X, Z),
  113.     parent(Z, Y).
  114.  
  115.  
  116. % grandfather
  117.  grandfather(X,Y) :-
  118.     male(X),
  119.     parent(X, Z),
  120.     parent(Z, Y).
  121.  
  122.  
  123. % grandmother
  124. grandmother(X,Y) :-
  125.     female(X),
  126.     parent(X, Z),
  127.     parent(Z, Y).
  128.  
  129.  
  130. % uncle
  131. uncle(X,Y) :-
  132.     male(X),
  133.     parent(Z, Y),
  134.     brother(X, Z).
  135.  
  136.  
  137.  
  138. % halfbrother
  139. commonmother(X,Y):-
  140.     mother(Z,X),
  141.     mother(Z,Y).
  142. commonfather(X,Y):-
  143.     father(Z,X),
  144.     father(Z,Y).
  145.  
  146. halfbrother(X,Y) :-
  147.     male(X),
  148.     commonmother(X,Y),
  149.     \+commonfather(X, Y);
  150.     male(X),
  151.     commonfather(X,Y),
  152.     \+commonmother(X, Y).
  153.  
  154.  
  155.  
  156.  
  157.  
  158.  
  159. % halfsister
  160. halfsister(X,Y) :-
  161.     female(X),
  162.     commonmother(X,Y),
  163.     \+commonfather(X, Y);
  164.     female(X),
  165.     commonfather(X,Y),
  166.     \+commonmother(X, Y).
  167.  
  168.  
  169. % stepbrother
  170. stepbrother(X,Y) :-
  171.     male(X),
  172.     father(Z,X),
  173.     mother(W,Y),
  174.     married(Z,W);
  175.     male(X),
  176.     mother(Z,X),
  177.     father(W,Y),
  178.     married(Z,W).
  179.  
  180.  
  181. % stepsister
  182. stepsister(X,Y) :-
  183.     female(X),
  184.     father(Z,X),
  185.     mother(W,Y),
  186.     married(Z,W);
  187.     female(X),
  188.     mother(Z,X),
  189.     father(W,Y),
  190.     married(Z,W).
  191.  
  192.  
  193.  
  194. % ancestor
  195. ancestor(X,Y) :- parent(X,Y).
  196. ancestor(X,Y) :- parent(X,Z),ancestor(Z,Y).
  197.  
  198.  
  199. % descendant
  200.  
  201. descendant(X,Y) :- parent(Y,X).
  202. descendant(X,Y) :- parent(Z,X),ancestor(Y,Z).
  203.  
  204.  
  205.  
  206. % Father-in-law
  207.  fatherinlaw(X,Y) :-
  208.     father(X,Z),
  209.     husband(Z,Y);
  210.     father(X,Z),
  211.     wife(Z,Y).
  212.  
  213.  
  214.  
  215. % mother-in-law
  216. motherinlaw(X,Y)  :-
  217.     mother(X,Z),
  218.     married(Z,Y).
  219.  
  220.  
  221.  
  222.  
  223. % familycomn
  224. familycommon(X,Y):-
  225.     father(X,Y);
  226.     mother(X,Y);
  227.     sister(X,Y);
  228.     brother(X,Y);
  229.     son(X,Y);
  230.     daughter(X,Y);
  231.     sibling(X,Y);
  232.     married(X,Y);
  233.     grandchild(X,Y);
  234.     grandparent(X,Y);
  235.     grandfather(X,Y);
  236.     grandmother(X,Y);
  237.     uncle(X,Y) ;
  238.     halfbrother(X,Y);
  239.     halfsister(X,Y);
  240.     stepbrother(X,Y);
  241.     stepsister(X,Y);
  242.     ancestor(X,Y) ;
  243.     fatherinlaw(X,Y);
  244.     motherinlaw(X,Y);
  245.     motherinlaw(Z,X),
  246.     motherinlaw(Z,Y);
  247.     fatherinlaw(Z,X),
  248.     fatherinlaw(Z,Y).
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement