/* Define the sorts needed. The obvious ones are sorts for representing each house, perons, drink, pet and cigarette type. In addition we define a sort containing the 5 possible locations for each house. */ SORT house = {redHouse,greenHouse,ivoryHouse,yellowHouse,blueHouse} SORT person = {japanese,englishman,ukranian,spaniard,norwegian} SORT drink = {coffee,tea,orangeJuice,water,milk} SORT pet = {zebra,dog,horse,fox,snails} SORT cigarette = {oldGold,parliament,kools,lucky,chesterfield} SORT location[5] /* Functions mapping locations <-> persons. The function location-of will indicate where each person will be located. */ FUNC locationOf(person) : location FUNC locatedAt(location) : person /* Functions mapping drinks <-> persons. The function drunk-by will indicated which drink each person drinks. */ FUNC drinks(drink) : person FUNC drunkBy(person) : drink /* Functions mapping pets <-> persons. The function owned-by tells what pet each person owns. */ FUNC hasPet(pet) : person FUNC ownedBy(person) : pet /* Functions mapping cigarettes <-> persons. The function smoked-by will tell which cigarette-type each person smokes. */ FUNC smokes(cigarette) : person FUNC smokedBy(person) : cigarette /* Functions mapping houses <-> persons. The function inhabited-by will show where each person lives. */ FUNC livesIn(house) : person FUNC inhabitedBy(person) : house /* This function is the number of each house on the street. House number 0 is furthest to the left. */ FUNC houseNumber(house) : location /* Equality predicates are needed for the locations and the persons. */ PRED samePerson(person,person) PRED sameLocation(location,location) %EqualityRelation(samePerson) %EqualityRelation(sameLocation) /* Various predicates to describe locations and relations between two locations. */ PRED immRight(location,location) PRED inMiddle(location) PRED leftMost(location) PRED nextTo(location,location) /* These axioms guarantee that the functions mapping person <-> X are all one-on-one, by making each be the inverse of another. */ A xa (samePerson(livesIn(inhabitedBy(xa)),xa)) A xb (samePerson(smokes(smokedBy(xb)),xb)) A xc (samePerson(drinks(drunkBy(xc)),xc)) A xd (samePerson(locatedAt(locationOf(xd)),xd)) A xe (samePerson(hasPet(ownedBy(xe)),xe)) /* Axiom to guarantee that if someone lives in a house, the house and that person are both at the same location (street number). */ A xf (sameLocation(locationOf(livesIn(xf)),houseNumber(xf))) /* Axioms for the predicate indicating whether one house is to the immediate right of another one. First we list the pairs for which this holds. */ immRight(1,0) immRight(2,1) immRight(3,2) immRight(4,3) /* Then we add an axiom so that no other pairs satisfy the condition. */ A xg A y (immRight(xg,y) -> ((sameLocation(xg,1) * sameLocation(y,0)) + (sameLocation(xg,2) * sameLocation(y,1)) + (sameLocation(xg,3) * sameLocation(y,2)) + (sameLocation(xg,4) * sameLocation(y,3)))) /* Location number 2 is in the middle. */ inMiddle(2) /* Location 0 is the left-most one. */ A xh (leftMost(xh) <-> sameLocation(xh,0)) /* A location is next to another one, if and only if one is immediately right of the other one. */ A xi A y (nextTo(xi,y) <-> (immRight(xi,y) + immRight(y,xi)))