changes
[chr.git] / Examples / family.chr
blobc15b2c394e95f9b6ce350966e60b539e29110b33
1 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2 %%
3 %% 000401 Slim Abdennadher and Henning Christiansen 
4 %%
5 %% ported to hProlog by Tom Schrijvers
7 :- module(family,[]).
9 :- use_module(library(chr)).
11 :- constraints
12   % extensional predicates:
13      person/2, father/2, mother/2,
14      orphan/1, 
15   % intensional predicates:
16      parent/2, sibling/2,
17   % predefined:
18      diff/2,
19   % a little helper:
20      start/0.
22 % Representing the test for failed state, i.e.,
23 % that the 'predefined' are satisfiable
25 diff(X,X) ==> false.
29 % Definition rules:
31 parent_def @
32 parent(P,C) <=> (true | (father(P,C) ; mother(P,C))).
34 sibling_def @
35 sibling(C1,C2) <=>
36          diff(C1,C2),
37          parent(P,C1), parent(P,C2).
39 ext_intro @
40 start <=> father(john,mary),   father(john,peter),
41           mother(jane,mary),
42           person(john,male),   person(peter,male),
43           person(jane,female), person(mary,female),
44           person(paul,male).
48 % Closing rules
49 father_close @
50 father(X,Y) ==> ( true | ((X=john, Y=mary) ; (X=john, Y=peter))).
52 % mother close @
53 mother(X,Y) ==> X=jane, Y=mary.
55 % person_close @
56 person(X,Y) ==> ( true | ( (X=john, Y=male)   ; 
57                            (X=peter, Y=male)  ;
58                            (X=jane, Y=female) ; 
59                            (X=mary, Y=female) ;
60                            (X=paul, Y=male)
61                          )
62                 ).
66 % ICs
68 ic_father_unique @
69 father(F1,C),father(F2,C) ==> F1=F2.
72 ic_mother_unique @
73 mother(M1,C),mother(M2,C) ==> M1=M2.
75 ic_gender_unique @
76 person(P,G1), person(P,G2) ==> G1=G2.
78 ic_father_persons @
79 father(F,C) ==> person(F,male), person(C,S).
81 ic_mother_persons @
82 mother(M,C) ==> person(M,female), person(C,G).
84 % Indirect def.
86 orphan1 @
87 orphan(C) ==>  person(C,G).
89 orphan2 @
90 orphan(C), /* person(F,male),*/ father(F,C) ==> false.
92 orphan3 @
93 orphan(C), /* person(M,female),*/ mother(M,C) ==> false.
97 %%%% The following just to simplify output;
100 father(F,C) \ father(F,C)<=> true.
101 mother(M,C) \ mother(M,C)<=> true.
102 person(M,C) \ person(M,C)<=> true.
103 orphan(C) \ orphan(C)<=> true.
106 /*************************************************
107 Sample goals
108   
109   :- start, sibling(peter,mary).
111   :- start, sibling(paul,mary). 
113   :- father(X,Y), mother(X,Y).
115 **************************************************/
116