CPSC 203 PROLOG LAB 1 This lab introduces you to the programming language PROLOG (short for "Programming in Logic"). You will practice defining basic clauses and queries. You need to finish AT LEAST part 1 in lab. Parts 2 and 3 may be completed outside of class, and are due Wednesday 11/4. 1. Start Prolog. At the "?-" prompt, type in the following, observe and become intrigued at what happens. Whenever Prolog returns with something like "X = 3" instead of just "yes" or "no", type a ";" and see what happens. RECORD THE RESULTS on paper (or in another file) - you'll be required to hand this in. For each result, write down a short explanation as to why PROLOG responded the way it did. I've written the explanations for the first couple of cases: a. "true." "yes" means true, or proved. b. "false." "false" always fails, and "no" means failure. c. "true, false." d. "true; false." e. "X = 3, X >= 2." ("=<" is less than or equal to) f. "X = 3, X = 4." g. "X = 3; X = 4." h. "X = (3 + 4)." i. "X is (3 + 4)." is EVALUATES the expression before unification. j. "(X + 0) + Y = (Y + X) + 0." did prolog produce ALL possible solutions? k. "member(3,[4,3,6,2])." l. "member(Y,[4,3,X])." m. "not(member(3,[4,2,6]))." 2. Using your favorite editor, create a text file with the following clauses: flight(lax,bos). flight(lga,lax). flight(dul,bdl). flight(bos,dul). flight(phl,sfo). flight(sfo,lax). flight(phl,bos). These clauses reflect all the flights operated by Cheapskate Discount Air Travel, Inc. For example, "flight(lax,bos)" is intended to mean "there are flights from lax (LA) to bos (Boston)." A. Load the file into PROLOG with "compile('filename').", and try the following queries: ?- flight(bos,lax). ?- flight(X,lax). B. You are to axiomatize a predicate "route(A,B)" to indicate that there's a way to "Fly Cheap" from city A to city B via the various flights offered, with as many connections as necessary. The first clause should just be: route(A,B) :- flight(A,B). This means that it's possible to get from A to B if there's a direct flight from A to B. As a further hint, you should look at how we axiomatized the "above" predicate in the blocks world. Test your program with interesting examples. Try quries with variables such as "route(X,bos)". Record the results. 3. Modify the program to include two more parameters to the flight predicate indicating the time of the flights. For example, "flight(lax,bos,12,19)" should be intended to mean "there's a flight from lax to bos, departing at noon and arriving at 7pm. You then need to redefine the "route" predicate to also take four parameters, so that "route(A,B,DT,AT)" should hold if and only if there's a way to fly from city A to city B, DEPARTING NO EARLIER than time DT, and ARRIVING NO LATER than time AT, with AT LEAST one hour for all connections. For example, "route(phl,sfo,9,15)" would mean that there's a way to get from Philadelphia to San Francisco, departing no earlier than 9am, and arriving no later than 3pm. You can use the following test clauses, but you should also make up some of your own: flight(lax,bos,9,14). flight(lga,lax,7,13). flight(dul,bdl,19,22). flight(bos,dul,15,17). flight(phl,sfo,12,18). flight(sfo,lax,5,7). flight(phl,bos,13,16). flight(bos,lax,16,21). flight(lax,phl,12,18). flight(phl,bdl,20,23). Test your solution with sample queries including, BUT NOT LIMITED TO: ?- route(sfo,bdl,5,23). ?- route(sfo,bdl,7,23). ?- route(sfo,bdl,5,20). ?- route(phl,lax,12,22). IMPORTANT HINT: arithmetics is strange in PROLOG. Do not use clauses such as "p(T+1)" even when you know that T will be instantiated with a number. Instead, use the conjunction "T2 is (T + 1), p(T2)". In general, you'll find that unification (pattern matching) when arithemtics is involved will not work the way you hope it would; i.e., do not expect (X > 3, X < 5) to return X = 4. Prolog can only perform SYMBOLIC reasoning when pattern matching (that's why "is" is different from "=").