Weekly exercises for INF3110/4110 week 46 10.11. - 14.11.2008 Exercise 1 ---------- Represent the following statements in Prolog: 1. Ivar studies Informatics 2. The population of Norway is 4,5 million 3. Norway is a rich country 4. 2 is a prime number 5. Someone wrote Hamlet 6. All humans are mortal 7. All rich people pay taxes 8. Ivar takes his umbrella if it rains 9. Firebrigade employees are men over six feet tall. Exercise 2 ---------- Given the following facts: biography(bashir,saddams_fortrolige,2004). biography(moen,jensStoltenberg,2002). biography(halvorsen,rett_fra_hjertet,2004). biography(isaksen, dronningen_vi_ikke_fikk,2003). biography(hasted,eminem,2003). biography(n?ss,munch,2004). biography(willoch,utfordringer,2004). biography(n?ss,munch,2004). Make a question where the answer is the author and title of biographies published in 2003. Exercise 3 ---------- Define a relation "likes", so that ola likes both Italian and mild Indian food. These are Italian dishes: pizza, spaghetti. These are Indian dishes: tandoori, curry, tikkaMasala. Of these, curry and tikkaMasala are hot, while tandoori is mild. Exercise 4 ---------- Extend the above with nationality, so that Norwegians (as ola) like Italian food and mild Indian food, while Indians like both mild and hot Indian dishes, but not Italian food. Exercise 5 ---------- Define the fact that each of sun, sirius and vega is a star. Define the fact "orbits", so that each of mercury, venus, earth, and mars orbits the sun, while moon orbits earth and deimos orbits mars. orbits(mercury, sun). orbits(venus, sun). orbits(earth, sun). orbits(mars, sun). orbits(moon, earth). orbits(deimos, mars). Given this, define the relation "planet(B)" as those Bs that are orbiting the sun. Define the relation "satellite(B)" giving those that orbits a planet. Define the solar system "solar" to be either the sun, a planet or a satellite. Exercise 6 ---------- The relation tel(county,person,number) expresses that a "person" (represented by name) in a given "county" has a certain telephone "number". 1. Make a question that ask for the telephone number of ole_brumm in hundre_meter_skogen 2. Make a question that gives all counties and all persons with the number 123 3. Make rules so that local(N1,N2) expresses that N1 and N2 are numbers within the same county 4. Make a question (with rules) to test that there is not two different persons (either in different counties or with different names) with the same number. Exercise 7 ---------- Santa has outsourced the reindeer traveling. Reindeer Line Inc. has decided not to travel from the North Pole to any major city, but has set up some pre-scheduled lines. Here are some of them. reindeerLine(northpole,oslo). reindeerLine(oslo,london). reindeerLine(oslo,copenhagen). reindeerLine(copehagen,berlin). reindeerLine(northpole,stockholm). reindeerLine(stockholm,moscow). a) As part of the deal, Santa has got a SWI-prolog and a two-hours introduction to Prolog. So, instead of calling Reindeer Line Inc. in order to find out if there is a connection between north pole and a given city, Santa just has to make a Prolog rule that tells if this is the case. Can you help him? b) If Santa wants to know if there is just one stop between the north pole and a city, what kind of question should be ask? Exercise 8 ---------- Natural numbers may be defined as follows in Prolog: natural_number(0). natural_number(s(X)) :- natural_number(X). The first fact asserts that "0" is a natural number while the second one says that if X is a natural number, then the s(X) is also a natural number. a) Define an operation "plus(X,Y,Z)" where the first two arguments are two natural numbers to be added and the result is given in the third argument. b) Define an operation "mult(X,Y,Z)" which makes the product of the first two arguments giving the result in the third.