Quiz 6 - Prolog 1

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

[Prolog-12] What would it be the result of T for the following prolog query? ?- [a, b, c] = [X, Y, Z | T].

T=[ ].

[Prolog-12] For the following Prolog query, X will be ____. ?- X=[ 1 | X ].

a circular list Answers: a circular list a self-referenced list an infinite list X=[1, 1, 1, ...] all of the above

[Prolog-12] What is it called for the variable matching process in Prolog?

unification

[Prolog-12] Complete the second clause of a Prolog program (factorial/3 or factorial(N,A,F)) to compute a factorial F of an integer N, in tail-recursion with an accumulating variable A. factorial(0,F,F). factorial(N,A,F) :- ___________.

N>0, A1 is N*A, N1 is N-1, factorial(N1,A1,F).

[Prolog-12] Consider the following bachelor Prolog program. What would it be the "INCORRECT" result of the following query? bachelor(P) :- male(P), not married(P). male(henry). male(tom). married(tom).

?- male(P). no

[Prolog-12] Explain the behavior or goal of the following program (mystery/3). What would it be the result of the query below? mystery(A,B) :- mystery(A,[],B). mystery([X|Y],Z,W) :- mystery(Y,[X|Z],W). mystery([],X,X). ?- mystery([1,2,3], A).

A=[3,2,1]

[Prolog-12] Consider the following program xyz/3. Select the result of the query shown below. xyz(X,[X|R],R). xyz(X,[F|R],[F|S]) :- xyz(X,R,S). ?- xyz(X,[1,2,3],L).

It will take an element X out of a list [X|R], resulting in a list R.

[Prolog-12] Select the body of the second clause of the following Prolog program (factorial/2) to compute a factorial. factorial(0,1). factorial(N,F) :- _____________.

N>0, N1 is N-1, factorial(N1,F1), F is N*F1.

[Prolog-12] What would it be the result of the following prolog query? ?- [a, b, c] = [X | Y].

X=a, Y=[b, c]

[Prolog-12] What would it be the result of the following prolog query? ?- p(X, f(Y), a) = p(a, f(a), Y).

X=a, Y=a.

[Prolog-12] What would it be the result of the following prolog query? ?- [a, b, c] = [X, Y | Z].

X=a, Y=b, Z=[c].

[Prolog-12] What would it be the result of the following prolog query? ?- p(X, f(Y), a) = p(a, f(b), Y).

X=a, Y=f(a). X=f(a), Y=a. X=f(a), Y=f(a). X=a, Y=a. None of the above

[Prolog-12] Write a Prolog program (append/3) where two lists (A and B) are appended, resulting in the third list (C) in 'append(A, B, C)'.

append([X|Y],Z,[X|W]) :- append(Y,Z,W). append([],X,X).

[Prolog-12] Write a prolog program (factorial/2) to compute a factorial F of an integer N, where factorial of 0 is 1.

factorial(0,1). factorial(N,F) :- N>0, N1 is N-1, factorial(N1,F1), F is N * F1.

[Prolog-12] Negation in Prolog is negation by ____

failure

[Prolog-12] Complete the second clause of the following Prolog program for member/2 where member(X, Y) checks whether X is an element (a member) of a list Y. member(X,[X|R]). member(X,[Y|R]) :- ____________.

member(X,R).

[Prolog-12] Assume that you have member/2 where member(X, Y) checks whether X is an element of a list Y, complete the first clause of the following Prolog program subset/2 where subset(A, B) will establish a relationship of A being a subset of B. subset([X|R],S) :- subset([ ],_).

member(X,S), subset(R,S).

[Prolog-12] The definition of Prolog negation is ____.

not(P) :- call(P), !, fail. not(P).

[Prolog-12] Given member/2 where member(X, Y) checks whether X is an element of a list Y, Select a Prolog program (subset/2) where subset(A, B) will establish a relationship of A being a subset of B.

subset([X|R],S) :- member(X,S), subset(R,S). subset([ ],_).

[Prolog-12] Given member/2 where member(X, Y) checks whether X is an element of a list Y, Select a Prolog program union/3 where union(A, B, C) will establish a "union" relationship where a list C is a union of a list A and a list B.

union([X|Y],Z,W) :- member(X,Z), union(Y,Z,W). union([X|Y],Z,[X|W]) :- \+ member(X,Z), union(Y,Z,W). union([],Z,Z).


Kaugnay na mga set ng pag-aaral

Chapter 19 Blood Vessels and Circulation

View Set

Mental Health - Ch 4: Treatment Settings

View Set

Chapter 8; Eukaryotic cell Cycle

View Set

Layers of the atmosphere science study guide

View Set

GEOS 1113 last mastering questions

View Set