CS 230 Programming Languages in class work NOTE WELL: The operator for NOT EQUALS is: \== Other comparison operators are as usual: <, >, <= >= Suggestions on how to use bprolog on the linux machines: Open a terminal and type gedit &, then hit enter (for writing your prolog code) To run B-Prolog, I recommend running it from the same directory that you are storing your prolog code to (use cd to change directories) At the command line: Type bp, then hit enter Inside the B-Prolog environment the following commands are useful: cl('myprog.pro') %compile and load a prolog program consult('myprog.pro') % use if want to trace the code trace % put bp in trace mode, need to consult first notrace % take bp out of trace mode halt % exits help % prints help ; % use to get next result Note: feel free to ignore most warnings when doing compiling/loading. ============================================================================== 1. Write a prolog procedure sisterof which takes two arguments and succeeds if the first argument is a sister of the second argument (that is, the first argument is female and has the same parents as those of the second argument). Examples: female(joy). male(mark). female(alice). female(sue). male(jim). parents(joy, barbara, dale). parents(mark, alicia, tyrone). parents(alice, barbara, dale). parents(sue, alicia, tyrone). parents(jim, barbara, dale). sisterof(joy,mark)? fails. sisterof(joy,alice)? succeeds. sisterof(alice,jim)? succeeds. sisterof(jim,alice)? fails. sisterof(joy,joy)? fails. 2. Imagine that you are involved with maintaining the records of the presidency of your Stocks Club. Given a database of all past presidents, you want to be able to ask questions like: "Was Mary ever re-elected as president?", "Did Dave ever serve at least 2 terms?", "Didn't Bob's term immediately follow Rachael's?", and "Did Violet serve as president at ANY time after Suzanna's term?" Suppose you are given information about each administration in the form of facts describing the president, starting year and ending year. The format is Prolog facts of the form pres(rachael,1995,1996). pres(rachael,1996,1997). pres(violet,1997,1998). pres(bob,1998,1999). pres(violet,1999,2000). pres(miguel,2000,2001). You can assume that each pres fact has a different beginning year and the beginning and ending year of each administration is different and that each presidency has no gaps. Define the following procedures: a) reElected(X) -- X is a president who successfully won the presidency two times in a row (consecutively); e.g., X=rachael b) twoTerm(X) -- X was president in two different administrations; e.g., X=rachael and X=violet c) follows(X,Y) -- Y was the president immediately after X, at least on one occasion; e.g., follows(violet,Y) should generate Y=bob and Y=miguel d) after(X,Y) -- Y was president sometime after X; e.g., after(bob,X) should generate X=violet and X=miguel.