Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1. Given the facts about Bible family relationship: parent(abraham,ismael). pare

ID: 3555788 • Letter: 1

Question

1. Given the facts about Bible family relationship: parent(abraham,ismael). parent(abraham,isaac). parent(isaac,esau). parent(isaac,iacob). Write the output for the following queries (if there are more than one output, write all of them):

a) ?- parent(abraham,X).

b) ?- parent(abraham,_).

c) ?- parent(Father,esau).

d) ?- parent(F,S).

e) ?- parent(abraham,X),parent(X,Grandson).

2. Write a Prolog rule, brother, which determines if two persons in the Bible family are brothers. For example, after your rule is created, you will have the following output: ?- brother(esau,iacob). yes

3. Write a Prolog rule that find the last element of a list. Example: ?- my_last(X,[a,b,c,d]). X = d

4. Write a Prolog rule that duplicate the elements of a list. Example: ?- dupli([a,b,c,c,d],X). X = [a,a,b,b,c,c,c,c,d,d] 5. The following is an example code that finds the area and perimeter of a rectangle: area:- write('Length '),read(L), area:- write(

Explanation / Answer

Question 1:-

a :- X=isaac

b:- true

c:- Father=isaac

d F=abraham

S=isaac

F=isaac

S=esau

F=isaac

S=iacob

d:-

false
2:-

brother(X,Y) :- parent(A,X),parent(A,Y),male(Y).

list every person in family tree as male or female.
3:-

my_last(X,[H]):-
X=H.
my_last(X,[H|T]):-
my_last(X,T).
4:-

dupli([ ],[ ]).
dupli([X,X|Ys],[X|Xs]) :- dupli(Ys,Xs).
5:-

area:- write('radius'),read(R),
write('Area is '),A is 3.14*R*R,write(A),nl,
write('Perimeter is '),P is 2*3.14*R,write(P),nl.
6
start:- write('input a= '),read(A),
write('input b= '),read(B),
write('input c= '),read(C),
A >= 0,B >= 0,C >= 0,
A < B+C,B < C+A,C < A+B,
write('These numbers are the edges of a triangle.').