?-consult soap.
Compiling
soap.
Yes.
?-listing.
jealous(A) :-
(loves(A,B)
, (loves(C,B) , not (A = C) )).
jealous(A) :-
(married(A,B)
, (loves(D,B) , not (A = D) )).
/* as is shown
below, ending rule with “not” results only in “yes” or “no” */
loves(phoebe,perry).
loves(jack,phoebe).
loves(lane,phoebe).
loves(jason,eulalie).
married(jason,phoebe).
married(phoebe,jason).
married(perry,stacey).
married(stacey,perry).
married(lane,eulalie).
married(eulalie,lane).
marriage_on_rocks(A,B) :-
(married(A,B) , (loves(A,D) ,
(not loves(A,B) , (loves(B,_) , (not
loves(B,A)
, (nl , (write(' The marriage
of ') , (write(A) , (write(' and ') , (write(B) ,
write(' is on the rocks '))))))))))).
marriage_on_rocks(C) :-
(married(C,E) , (loves(C,_) ,
(loves(E,_) , (not loves(C,E) , (not
loves(E,C)
, (write('
The marriage of ') , (write(C) , ' is on the rocks '))))))).
Yes.
?-jealous(Who).
Yes.
?-jealous (jason).
Yes.
?-jealous(phoebe).
No.
?-forget soap.
Yes.
?-consult soap5.
Compiling
soap5.
Yes.
?-listing.
jealous(A) :-
(loves(A,B) , (loves(C,B) , (A \= C))). /* red text is
changed from not A = C in soap.pro */
jealous(A) :-
(married(A,B)
, (loves(D,B) , (A \= D))). /* red text is
changed from not A = D in soap.pro */
/* this shows
behavioral difference between
\= and not */
loves(phoebe,perry).
loves(jack,phoebe).
loves(lane,phoebe).
loves(jason,eulalie).
married(jason,phoebe).
married(phoebe,jason).
married(perry,stacey).
married(stacey,perry).
married(lane,eulalie).
married(eulalie,lane).
marriage_on_rocks(A,B) :-
(married(A,B) , (loves(A,D) ,
(not loves(A,B) , (loves(B,_) , (not
loves(B,A)
, (nl , (write(' The marriage
of ') , (write(A) , (write(' and ') , (write(B) ,
write(' is on the rocks '))))))))))).
marriage_on_rocks(C) :-
(married(C,E) , (loves(C,_) ,
(loves(E,_) , (not loves(C,E) , (not
loves(E,C)
, (write('
The marriage of ') , (write(C) , write(' is on the rocks ')))))))).
Yes.
?-jealous(Who).
Who = jack
More? (Y/N):y
Who = lane
More? (Y/N):y
Who = jason
More? (Y/N):y
Who = jason
More? (Y/N):y
Who = stacey
More? (Y/N):y
Who = lane
More? (Y/N):y
No.
?-forget soap5.
Yes.
?-consult soap2.
Compiling
soap2.
Yes.
?-listing.
jealous(A) :-
(loves(A,B) , (loves(C,B) ,
(not (A = C) , (nl
, (write(A) , write(' is jealous first ')))))).
jealous(A) :-
(married(A,B) , (loves(D,B) ,
(not (A = D) , (nl
, (write(A) , write(' is jealous ')))))).
/* red text
added to soap.pro to force output other than “yes” or “no”.*/
/* alternative
to using \= to get output other than “yes” or “no”. */
loves(phoebe,perry).
loves(jack,phoebe).
loves(lane,phoebe).
loves(jason,eulalie).
married(jason,phoebe).
married(phoebe,jason).
married(perry,stacey).
married(stacey,perry).
married(lane,eulalie).
married(eulalie,lane).
marriage_on_rocks(A,B) :-
(married(A,B) , (loves(A,D) ,
(not loves(A,B) , (loves(B,_) , (not
loves(B,A)
, (nl , (write(' The marriage
of ') , (write(A) , (write(' and ') , (write(B) ,
write(' is on the rocks '))))))))))).
marriage_on_rocks(C) :-
(married(C,E) , (loves(C,_) ,
(loves(E,_) , (not loves(C,E) , (not
loves(E,C)
, (write('
The marriage of ') , (write(C) , write(' is on the rocks ')))))))).
Yes
?-jealous(Who).
jack' is jealous first '
Who = jack
More? (Y/N):y
lane' is jealous first '
Who = lane
More? (Y/N):y
jason' is jealous '
Who = jason
More? (Y/N):y
jason' is jealous '
Who = jason
More? (Y/N):y
stacey' is jealous '
Who = stacey
More? (Y/N):y
lane' is jealous '
Who = lane
More? (Y/N):y
No.
forget soap2.
?-consult soap4.
Compiling
soap4.
Yes.
?-listing.
jealous(A) :-
(loves(A,B) , (loves(C,B) ,
((A \= C) , (nl , (write(A) , write(' is jealous first ')))))).
jealous(A) :-
(married(A,B) , (loves(D,B) ,
((A \= D) , (nl , (write(A) , write(' is jealous second ')))))).
/* green text added to
soap2.pro to distinguish which results come from which jealous */
loves(phoebe,perry).
loves(jack,phoebe).
loves(lane,phoebe).
loves(jason,eulalie).
married(jason,phoebe).
married(phoebe,jason).
married(perry,stacey).
married(stacey,perry).
married(lane,eulalie).
married(eulalie,lane).
marriage_on_rocks(A,B) :-
(married(A,B) , (loves(A,D) ,
(not loves(A,B) , (loves(B,_) , (not
loves(B,A)
, (nl , (write(' The marriage
of ') , (write(A) , (write(' and ') , (write(B) ,
write(' is on the rocks '))))))))))).
marriage_on_rocks(C) :-
(married(C,E) , (loves(C,_) ,
(loves(E,_) , (not loves(C,E) , (not
loves(E,C)
, (write('
The marriage of ') , (write(C) , write(' is on the rocks ')))))))).
Yes.
?-jealous(Who).
jack' is jealous first '
Who = jack
More? (Y/N):y
lane' is jealous first '
Who = lane
More? (Y/N):y
jason' is jealous second '
Who = jason
More? (Y/N):y
jason' is jealous second '
Who = jason
More? (Y/N):y
stacey' is jealous second '
Who = stacey
More? (Y/N):y
lane' is jealous second '
Who = lane
More? (Y/N):y
No.
?-forget soap4.
Yes.
?-consult soap3.
Compiling
soap3.
Yes.
?-listing.
jealous(A) :-
(loves(A,B) , (loves(C,B) ,
(not (A = C) , (nl , (write(A) , write('
is jealous
first ')))))).
jealous(A) :-
(married(A,B) , (loves(D,B) ,
(nl , (write(A) , write(' is jealous second '))))).
/* removed not A= D from soap2.pro to see whether it was needed
*/
/* it wasn’t in
THIS database but might be necessary in another context */
loves(phoebe,perry).
loves(jack,phoebe).
loves(lane,phoebe).
loves(jason,eulalie).
married(jason,phoebe).
married(phoebe,jason).
married(perry,stacey).
married(stacey,perry).
married(lane,eulalie).
married(eulalie,lane).
marriage_on_rocks(A,B) :-
(married(A,B) , (loves(A,D) ,
(not loves(A,B) , (loves(B,_) , (not
loves(B,A)
, (nl , (write(' The marriage
of ') , (write(A) , (write(' and ') , (write(B) ,
write(' is on the rocks '))))))))))).
marriage_on_rocks(C) :-
(married(C,E) , (loves(C,_) ,
(loves(E,_) , (not loves(C,E) , (not
loves(E,C)
, (write('
The marriage of ') , (write(C) , write(' is on the rocks ')))))))).
Yes.
?-jealous(Who).
jack' is jealous first '
Who = jack
More? (Y/N):y
lane' is jealous first '
Who = lane
More? (Y/N):y
jason' is jealous second '
Who = jason
More? (Y/N):y
jason' is jealous second '
Who = jason
More? (Y/N):y
stacey' is jealous second '
Who = stacey
More? (Y/N):y
lane' is jealous second '
Who = lane
More? (Y/N):y
No.