


Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!



All problems in this homework are programming problems. Please return actual listings. Provide explanations as comments in your programs.
%father(?Father,?Child) father(tearch,abraham). father(tearch,nachor). father(tearch,haran). father(abraham,isaac). father(haran,lot). father(haran,milcah). father(haran,yiscah).
%mother(?Mother,?Child) mother(sarah,isaac).
male(tearch). male(abraham). male(nachor). male(haran). male(isaac). male(lot).
female(sarah). female(milcah).
female(yiscah)
Specify the following Prolog predicates:
% is_mother(X) X is a mother % son(X,Y) X is the son of Y % sister(X,Y) X is the sister of Y % grandfather(X,Y) X is the grandfather of Y % ancestor(X,Y) X is the ancestor of Y
Show all results of posing the goals:
?- is_mother(X). ?- son(X,X). ?- ancestor(X,isaac).
for your implementation. Explain the meaning of the results obtained with these goals.
Write Prolog predicates for the following list operations:
(a) deleting and element from a list: delete(X,L,R)(delete all in- stances of element X from the list L and put the result into list R). Show all results of posing the goal
?- delete(X,[a,b,c],R).
for your implementation. (b) length of a list: length(List,Length). ( Hint: To compute the length of a list you have to use the is operator. For example A is B+1 will first add 1 to the numerical value of B and then assign it to A if it is unbound or compare it with value of A if bound. ) (c) smallest element of a list: smallestElem(X,List)
Each character corresponds to a digit. The same digit may not be assigned to two different characters. Show the goal posed to solve the puzzle with your implementation and the result obtained.
Bonus problems are intended to be fairly complicated and tricky. Obtain- ing a good solution might require a significant effort, thus first make sure you solve the regular homework problems before tackling the bonus problems. The following rules apply to the bonus problems: