Exercise 4.60. By giving the query (lives-near ?person (Hacker Alyssa P)) Alyssa P. Hacker is able to find people who live near her, with whom she can ride to work. On the other hand, when she tries to find all pairs of people who live near each other by querying (lives-near ?person-1 ?person-2) she notices that each pair of people who live near each other is listed twice; for example, (lives-near (Hacker Alyssa P) (Fect Cy D)) (lives-near (Fect Cy D) (Hacker Alyssa P)) Why does this happen? Is there a way to find a list of people who live near each other, in which each pair appears only once? Explain. ———————————————————————————————————————————————————————————————————————— These are distinct assignments of values to the variables person-1 and person-2, so displaying both is correct. To remove the duplicates we wish to remove half the assignments that would otherwise be considered, while still considering each pair. We can define a rule (sorts-before ?a ?b) which compares lists by lexicographic ordering, considering as many list elements as necessary, then Alyssa can rewrite her query as (and (lives-near ?person-1 ?person-2) (sorts-before ?person-1 ?person-2))