You've just been hired to keep track of the books for the local WeedEating Society. The Society hires people to do jobs, such as weeding, trimming, hedging, and seeding. You have decided on a really simple bookkeeping system, using the following predicates: hired(Job,Person,Amount) -- Person has agreed to do the Job for Amount dollars. paid(Job,Person,Amount) -- Person has been paid Amount dollars for the Job they are doing. Examples: hired(weeding, jin, 10). % jin has agreed to weed for $10. paid(weeding, jin, 4). % jin has been paid $4 for the weeding job. First, make up a database of several such facts. Now write the following predicates, some of which will need side effects: on_payroll(Person): True if Person is hired for any job. hire(Job,Person,Amount): Hires Person to do Job for Amount dollars if they haven't been hired to do that job already, and adds a clause that says they have been paid zero dollars. (You may need to use a cut.) pay(Job,Person,Amount): Pays Person Amount dollars for the Job they are doing. Note that the old paid() predicate should be updated to include the new amount; don't just add a new paid() clause. owed(Job,Person,Amount): True if Person is owed Amount dollars for Job. all_paid(X): True if X is the set of triples (Job,Person,Amount) where paid(Job,Person,Amount). is in the database. You will need to use the setof() predicate, which is described briefly below. all_hired(X): True if X is the set of all people who are hired for any job. You may need to use the existential quantification defined on slide 17 of the Programs = Data section of your notes. SETOF: setof(X,f(X),S). will place in S a list of all atoms X that satisfy the predicate f(). Examples: Given these facts: teaches(csc148,paul). teaches(csc324,paul). teaches(csc148,diane). teaches(csc228,diane). teaches(csc270,francois). This is a session from XSB: | ?- setof(X,teaches(X,paul),S). X = _119 S = [csc148,csc324]; Note that S has all the courses that paul teaches. You can get sets of tuples as well; the following asks for all pairs (X,Y) such that X is taught by Y: | ?- setof((X,Y),teaches(X,Y),S). X = _126 Y = _119 S = [(csc148 ',' diane),(csc148 ',' paul),(csc228 ',' diane),(csc270 ',' francois),(csc324 ] You can read more about setof() in the Programs = Data section of the course notes. SAMPLE SESSION Here is a sample session; jin and alex have already been hired to do some jobs. | ?- hire(weeding,fred,30). yes | ?- owed(A,B,C). A = weeding B = jin C = 6; A = weeding B = alex C = 17; A = weeding B = fred C = 30; no | ?- pay(weeding,fred,10). yes | ?- owed(A,B,C). A = weeding B = jin C = 6; A = weeding B = alex C = 17; A = weeding B = fred C = 20; no | ?- all_paid(X). X = [(weeding ',' alex ',' 3),(weeding ',' fred ',' 10),(weeding ',' jin ',' 4)]; no | ?- all_hired(X). X = [alex,fred,jin]; no | ?- hire(trimming,jin,15). yes | ?- all_hired(X). X = [alex,fred,jin]; no | ?- all_paid(X). X = [(trimming ',' jin ',' 0),(weeding ',' alex ',' 3),(weeding ',' fred ',' 10),(weeding ',' jin ',' 4)];