Answer two of the three questions, labelled Q1, Q2 and Q3. If you answer all three
questions, your answer to question Q3 will be ignored (and left unmarked). Each
question is worth 50 marks; two questions together are 100 marks.
Please type your answers and upload a PDF or plaintext file in answer to Blackboard
Question 3. (PDF converters are available online.)
Tip: As partial credit will be awarded where possible, try not to leave any part of a
question you are answering blank. Write down some thoughts that show effort and
understanding (even if the understanding is that the effort falls short). But to avoid
penalties for overly long answers, please be concise.
(a) The English sentence \Pat is happy every day it is sunny” can be translated
many different ways in Prolog, including (among others)
(t1) ’Pat is happy every day it is sunny’.
(t4) happy(pat,X) :- sunnyDay(X).
(t5) pat(happy) :- day(sunny).
The choice of a translation depends on the queries we wish to answer (and the
additional information that may go into a program). Give five queries (q1), (q2),
(q3), (q4) and (q5) that suggest choosing (t1), (t2), (t3), (t4) and (t5),
respectively, so that the Prolog interpreter replies
(i) true (or yes) to (q1) if told (t1)
(ii) When = sunnyDay to (q2) if told (t2)
(iii) Who = pat, What = happy to (q3) if told (t3)
(iv) Who = pat, When = today to (q4) if told (t4) and
(v) What = happy to (q5) if told (t5) and day(sunny).
(b) Learn Prolog Now defines sublist(Sub,List) to be true when Sub is a prefix
of a suffix of List.
sublist(Sub,List) :- append(_,Suffix,List),
This makes [2,3] a sublist of [1,2,3,4].
On the other hand, [2,4] is not a sublist of [1,2,3,4].
Define a modification subl/2 of sublist so that subl(Sub,List) is true not
only when sublist(Sub,List) is true but more generally, whenever Sub can be
obtained from List by deleting any number of List’s members. For example,
L = [0,4]
(c) A list L is non-repeating if no member of L occurs more than once in L. For
example, [2,1] is non-repeating, whereas [2,1,2] is not. Define a predicate
nonRep/1 such that nonRep(L) is true exactly if L is a non-repeating list.
(d) SWI-Prolog and SWISH have a built-in predicate subset/2 such that
subset(+SubSet,+Set) is described to be
true if all elements of Subset belong to Set as well.
Moreover, in SWI-Prolog and SWISH, we have
P = [].
Why is the list  not included in the answer P = []? Explain.
(e) A convenient way to represent non-negative integers is via the predicate
numeral/1 defined in Chapter 3 of Learn Prolog Now
numeral(succ(X)) :- numeral(X).
(i) Explain how Prolog uses these two clauses to reply to the query
?- X = succ(X), numeral(X).
(ii) Modify numeral to a predicate nu/1 so that
?- X = succ(X), nu(X).
X = 0 ;
X = succ(0) ;
X = succ(succ(0)) ;
X = succ(succ(succ(0))) ;