Question: I have an assignment in PROLOG that I am stuck with. Question 1 Consider the following database. mother(lisa, abe). father(tony, abe). mother(lisa, sarah). father(tony, sarah).
I have an assignment in PROLOG that I am stuck with.
Question 1
Consider the following database.
mother(lisa, abe). father(tony, abe).
mother(lisa, sarah). father(tony, sarah).
mother(hannah, john). father(abe, john).
mother(sarah, martha). father(bill, martha).
mother(sarah, linda). father(bill, linda).
mother(martha, mike). father(rob, mike).
mother(hannah, mary). father(rob, rick).
mother(martha, susan). father(rob, susan).
Define rules for the following relationships:
1. sister(X, Y): X and Y are sisters.
2. nephew(X, Y): X is a nephew of Y.
3. full siblings(X, Y): X and Y have the same mother and father.
4. grniece(X, Y): X is a great niece of Y.
Question 2 Using a predicate married_couple(Wife, Husband), define the relationships mother_in_law, brother_in_law, and son_in_law.
Question 3 Write a predicate called greater_than using the successor representation.
Question 4 Write a program for computing the quotient and remainder of two numbers using the successor representation.
Question 5 Define predicates even(X) and odd(X) for determining if a natural number is even or odd (using the successor representation).
Question 6 Write a predicate for computing the greatest common divisor (gcd) of two numbers
(using the successor representation). Your predicate should repeatedly subtract the smaller number from the larger number until the two numbers are equal. Do not use the remainder predicate of question 4.
Question 7 Solve exercises 3.2.1: (i), (ii), (iii).
3.2.1 Exercises for Section 3.2
(i) A variant of Program 3.14 for sublist is defined by the following three rules:
subsequence ([X | Xs] , [X | Ys]) subsequence (Xs, Ys).
subsequence(Xs,[Y | Ys]) subsequence(Xs,Ys).
subsequence([ ],Ys).
Explain why this program has a different meaning from Program
3.14.
(ii) Write recursive programs for adjacent and last that have the same meaning as the predicates defined in the text in terms of
append.
(iii) Write a program for double (List, ListList), where every element in List appears twice in ListList, e.g., double ( [1, 2, 3] , [1, 1, 2,
2,3,3]) is true.
Program 3.14 Determining sublists of list
append(Xs, Ys, XsYs)
XsYs is the result of concatenating the lists Xs and Ys.
append([],Ys,Ys).
append([X|Xs],Ys,[X|Zs]) append(Xs,Ys,Zs).
Question 8 Solve exercises 3.3.1: (i), (ii), (iii).
(i) Write a program for substitute (X, Y, L1, L2), where L2 is the result of substituting Y for all occurrences of X in L1, e.g.,
substitute(a,x, [a,b,a,c], [x,b,x,c]) is true, whereas substitute(a,x, [a,b,a,c], [a,b,x,c]) is false.
(ii) What is the meaning of the variant of select:
select(X,[X | Xs] ,Xs).
select(X, [Y | Ys], [Y | Zs]) X Y,
select(X,Ys,Zs).
(iii) Write a program for no_doubles (L1, L2), where L2 is the result of removing all duplicate elements from L1, e.g., no_doubles ([a, b, c, b] , [a, c, b] ) is true. (Hint: Use member.)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
