Solution - Exercises INF3110 week 44 31.10. - 4.11.2011 Exercise 1 ---------- Remember that constants are written in lowercase and variables start always with uppercase letters. 1. studies(ivar, informatics). 2. population(norway, 4.5). 3. rich_country(norway). 4. prime(2). 5. author(hamlet, someone). 6. mortal(X):- humans(X). 7. pays_taxes(X):- person(X), rich(X). 8. takes(ivar, umbrella):- raining. 9. man(X) :- fbEmp(X) . tallerTh6Ft(X) :- fbEmp(X) . tallerTh6Ft(X) :- height(X,Y) , moreTh(Y,6) . Exercise 2 ---------- biography(X,Y,2003). Exercise 3 ---------- indian(curry). indian(tandoori). indian(tikkaMasala). mild(tandoori). hot(curry). hot(tikkaMasala). italian(pizza). italian(spaghetti). likes(ola,Food) :- indian(Food), mild(Food). likes(ola,Food) :- italian(Food). Exercise 4 ---------- likes(Person,Food) :- indian(Food), mild(Food), nationality(nor,Person). likes(Person,Food) :- italian(Food), nationality(nor,Person). %likes(Person,Food) :- indian(Food), (hot(Food); mild(Food)), nationality(ind,Person). likes(Person,Food) :- indian(Food), nationality(ind,Person). nationality(nor,ola) nationality(ind,samir) Exercise 5 ---------- star(sun). star(sirius). star(vega). orbits(mercury, sun). orbits(venus, sun). orbits(earth, sun). orbits(mars, sun). orbits(moon, earth). orbits(deimos, mars). planet(B):- orbits(B, sun). satellite(B):- orbits(B,P), planet(P). solar(sun). solar(B):- planet(B); satellite(B). Exercise 6 ---------- 1. tel(hundre_meter_skogen, ole_brumm, N). 2. tel(C,P,123). 3. local(N1,N2):- tel(C,P1,N1),tel(C,P2,N2), N1 \== N2 . 4. notOK :- tel(C1,P1,N),tel(C2,P2,N), C1\==C2. notOK :- tel(C1,P1,N),tel(C2,P2,N), P1\==P2. 4. To get a listing of which numbers are not OK, define the rules: sameNo(C1,P1,C2,P2,N) :- tel(C1,P1,N),tel(C2,P2,N), C1\==C2. sameNo(C1,P1,C2,P2,N) :- tel(C1,P1,N),tel(C2,P2,N), P1\==P2. and use the query: sameNo(C1,P1,C2,P2,N) . Exercise 7 ---------- a) connection(X,Y):- reindeerLine(X,Y). connection(X,Y):- reindeerLine(X,Z),connection(Z,Y). b) For example: Question: reindeerLine(northpole,X), reindeerLine(X,moscow). Answer: X = stockholm Exercise 8 ---------- natural_number(0). natural_number(s(X)) :- natural_number(X). a) plus(0,X,X) :- natural_number(X). plus(s(X),Y,s(Z)) :- plus(X,Y,Z). Note: It would be also possible to write only "plus(0,X,X)." in the first part of the definition. b) mult(0,X,0) :- natural_number(0). mult(s(X),Y,Z) :- mult(X,Y,XY), plus(XY,Y,Z). Note: It would be also possible to write only "mult(0,X,0)." in the first part of the definition.