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: Write the output for the fol

ID: 3712498 • Letter: 1

Question

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

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:

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(‘Width '),read(W),

write('Area is '),A is L*W,write(A),nl,

write('Perimeter is '),P is 2*3.14*R,write(P),nl.

?- area.

Length |: 3.

Width |: 4

Area is 12

Perimeter is 14

Write similar code to find the area and circumference of a circle.

6. Write Prolog rules that verifies if 3 numbers can be the edges of a triangle. Note, in a triangle, the sum of any two edges must be grater than the third edge.

Explanation / Answer

Solution:

1)

a)

X=isaac

b)

true

c)

Father=isaac

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.').

I hope this helps if you find any problem. Please comment below. Don't forget to give a thumbs up if you liked it. :)