Homework VII

 

 

1. [30 points]

For this problem, you should use only predicates defined in the files 'kennedy' and 'familial' in our class directory (and pre-defined predicates). Formulate queries and test them using the two indicated files, and show that multiple solutions may be obtained.

(a) each response to this query should be a pair of individuals from the database who share a common birthday (i.e., month and day).

(b) each response to this query should be a pair of twins from the database

(c) each response to this query should be a parent and one of their children who were born in the same month as that parent

 

2. [30 points]

This problem uses the Prolog definitions in the file/group/class/c111/Prolog/familial. Add definitions of the following predicates and use the definitions in the file /group/class/c111/Prolog/kennedy to perform tests showing the correctness of your definitions. Illustrate the generation of multiple results, and the responses of queries where both arguments are known, one or the other is unknown, or both are unknown.

(a) motherInLawOf(Person, MomInLaw); the dictionary definition of mother-in-law is the mother of a spouse.

(b) ancestorOf(Person, Ancestor) -- succeeds when one of Person's ancestors (i.e., a person from whom he/she is descended, a forebear) is Ancestor.

 

3. [40 points]

Virtually all programming languages provide parenthesized expressions as a central feature, and a basic property of such strings is that parentheses are "balanced". This problem is to write a Prolog predicate definition 'balanced(String)' that succeeds when String is a Prolog string in which the parentheses are balanced. Thus, for instance, query balanced("a(b(c))d(()e)") should succeed, and queries balanced("a(b(c)d(e)") and balanced("a(bc)d)((e)") should fail. Note that in Prolog a string is a list of ASCII character codes (i.e., integers) rather than the characters themselves. If you wish to convert between the ASCII and printable representations (in either direction), use the pre-defined predicate 'name(Atom,String)'.

 

Program submission instructions

Program  solutions must include documentation that makes it clear both what general method you used in constructing the program, and how the details of the program accomplish that method. You need to run test cases that exercise every component of your code, and include documentation that justifies that your test data meets this condition. It is not the grader’s responsibility to figure out how you wrote the program and whether it is correct — it is your responsibility to explain your program and convince the grader it is completely tested and correct. Full credit will not be awarded, even for (apparently) correct programs, without completing these requirements.

 

To receive a score you must turn-in a printout of your source programs and test outcomes (paper copy). In addition, you should use the 'submit' command to provide an electronic copy of your source code only for problem 2 and 3 -- send it to the directory Hwk7 for course c111.