child_of(mary, steve). child_of(mary, anne). child_of(alice, anne). child_of(alice, steve). child_of(jane, steve). child_of(leslie, steve). female(mary). female(alice). female(jane). sisters(Person1, Person2) :- child_of(Person1, Parent1), child_of(Person1, Parent2), child_of(Person2, Parent1), child_of(Person2, Parent2), not(Parent1 = Parent2), female(Person1), female(Person2), not(Person1 = Person2).
?- sisters(Sis1, Sis2).
Sis1 = mary, Sis2 = alice; Sis1 = mary, Sis2 = alice; Sis1 = alice, Sis2 = mary; Sis1 = alice, Sis2 = mary; false.
Comment:Essentially there are two persons here who are sisters,
alice, so we intuitively
expect a single answer, effectively verifying that
sisters(mary, alice). is true. However, Prolog also
sisters(alice, mary). which doubles the number
of solutions found. It also proves each of these two ways, binding
anne in one case, and vice-versa in the other case,
again doubling the number of solutions (to give 4 altogether).