NEW
Font size
WorksheetsCSCI0823 UnitTest_Finals
Total questions: 35
Worksheet time: 18mins
Determine the result of predicate append
?- append([1, 2, 3], [d, e, f, g], X).
X = [1, 2, 3]
X = [1, 2, 3, d, e, f, g]
X = [d, e, f, g,1, 2, 3]
Assess the result of the given query
?- [1,2,3,4,5].
Head = 1,
Tail = [2, 3, 4, 5].
ERROR
[1,2,3,4,5].
What does the given fact mean
list([_|_]).
number of argument in list predicate
head and tail in list predicate
empty list in list predicate
list_to_set([1,2,a,q,@], X).
X = [1, 2, a, q, @].
X = [a, q, 1, 2, @].
Below are valid examples of ___
[ ]
[0, 1, 2, 3, 4, 5]
[‘a’, ‘b’, ‘c’]
[‘mon’, ‘tue’, ‘wed’]
Set elements
Sets
Head and Tail
member(1,2, [1,2,5,4]).
True
False
ERROR: Unknown procedure: member/3
ERROR: However, there are definitions for:
ERROR: lists:member/2
false.
?- sumlist([1,2,3,1,1], Sum).
Sum = 8.
ERROR: Arithmetic: `a/0' is not a function
?- is_ordset([1,3,5]).
True
False
?- subtract([1,2,3], [1,2,3,4], Answer).
Answer = ( ).
Answer = [1,2,3].
Answer = [ ].
?- is_set([[H]|T]).
True
False
?- intersection([1,2,3,4], [1,2,3,4,5], Answer).
Answer = [1, 2, 3, 4].
Answer = [5].
?- union([1,2,3,4,4], [1,2,3,4,5], Answer).
Answer = [4, 4].
Answer = [1, 2, 3, 4, 5].
?- ord_empty([1,2,3 ]).
True
False
?- ord_seteq([[ ]], [[ ]]).
True
False
?- list_to_ord_set([b,a,+,4,*,3], Set).
Set = [3, 4, *, +, a, b].
Set = [3, 4, a, b, *, +, ].
Let A = [29,30,41],B = [1,2,3], C = [30,41] find
A U B ∩ C
[30,41]
[1,2,3,29,30,41]
[29,30,41]
sample.pl
list([]).
list([_|_]).
lt(X,Y):-var(X);var(Y).
lt(X,Y):-nonvar(X),nonvar(Y),X<Y.
Using the database sample.pl, project the result of evaluation
?-list([5435,63,868]).
True
False
sample.pl
list([]).
list([_|_]).
lt(X,Y):-var(X);var(Y).
lt(X,Y):-nonvar(X),nonvar(Y),X<Y.
Using the database sample.pl, project the result of evaluation
?- list([5435,63|868]).
True
False
reverse.pl
reverse([ ], [ ]).
reverse([H|Tail],Result) :- reverse(Tail,Tailreversed), append(Tailreversed,[H],Result).
Using reverse.pl database, evaluate
?-reverse([ 4,5| [6] ],X).
X=[4,5,6]
X=[6,5,4]
Error
Succeeds if Set3 unifies with the
intersection of Set1 and Set2
intersection(-Set1, -Set2, +Set3)
intersection(+Set1, +Set2, -Set3)
subtract(+Set, +Delete, -Result)
The predicate subtract means ___
Delete all elements of set ‘Delete’ from ‘Set’
Delete all elements of Set ‘Delete’ from ‘set’
The first element and the last element in a set
[ H | T ]
[ _ ]
Identify the result of the query
?- [342, 899, 190, 3788, 5134] = [_, X | _].
X = 899.
X = [899, 190, 3788, 5134].
The arity of append( ).
append/3
append/2
append/1
append(FL,BL,[c,d,e,1,2,3]).
is categorized as ___
Finding Back List
Finding Front List
Indeterministic List Decomposition
?- append(FL,BL,[c,d,e,1,2,3]).
will return__
FL = [],
BL = [c, d, e, 1, 2, 3] ;
FL = [c],
BL = [d, e, 1, 2, 3] ;
BL = [e, 1, 2, 3] ;
FL = [c, d, e],
BL = [1, 2, 3] ;
FL = [c, d, e, 1],
BL = [2, 3] ;
FL = [c, d, e, 1, 2],
BL = [3] ;
FL = [c, d, e, 1, 2, 3],
BL = [] ;
false.
FL = [],
BL = [c, d, e, 1, 2, 3] ;
FL = [c],
BL = [d, e, 1, 2, 3] ;
FL = [c, d],
BL = [e, 1, 2, 3] ;
FL = [c, d, e],
BL = [1, 2, 3] ;
FL = [c, d, e, 1],
BL = [2, 3] ;
FL = [c, d, e, 1, 2],
BL = [3] ;
FL = [c, d, e, 1, 2, 3],
BL = [] ;
false.
FL = [],
BL = [c, d, e, 1, 2, 3] ;
FL = [c],
BL = [d, e, 1, 2, 3] ;
FL = [c, d],
FL = [c, d, e],
BL = [1, 2, 3] ;
FL = [c, d, e, 1],
BL = [2, 3] ;
FL = [c, d, e, 1, 2],
BL = [3] ;
FL = [c, d, e, 1, 2, 3],
BL = [] ;
false.
FL = [],
BL = [c, d, e, 1, 2, 3] ;
FL = [c],
BL = [d, e, 1, 2, 3] ;
FL = [c, d],
BL = [e, 1, 2, 3] ;
FL = [c, d, e],
BL = [1, 2, 3] ;
FL = [c, d, e, 1],
BL = [2, 3] ;
FL = [c, d, e, 1, 2],
BL = [3] ;
BL = [] ;
false.
Arity of last( ).
last/2
last/1
Arity of select( ).
select/3
select/2
Arity of member( ).
member/3
member/2
?- append([1, 2, 3], [ ], [a, f, t, p, w], X).
ERROR: Unknown procedure: ______
append/4
append/3
?- is_ordset([*, +, -, /]).
True
False
?- is_ordset([#,1,3,5]).
False
True
?- subset([1,2,4], [1,2,3]).
False
True
Below is the database finals.pl
b(f).
b(i).
b(n).
b(a).
c(l).
c(g).
c(r).
c(a).
c(d).
c(e).
d(1).
d(0).
d(0).
a(X):- b(X), c(X), d(X).
a(X):- c(X), d(X).
a(X):- d(X).
Determine the result of a(X)
X = 1 .
X = 1 ;
X = 0 ;
X = 0.
X = 0.
?- sumlist([ ], Sum).
Sum = [ ].
Sum = 0.
