Recall the successor notation for representing natural numbers as terms in Prolo
ID: 3828824 • Letter: R
Question
Recall the successor notation for representing natural numbers as terms in Prolog. In this notation, "0" stands for the number zero, "s (0)" stands for one, "s (s (0))" stands for two, and so on. (a) Based on the successor notion, define a relationship "odd (X)" which is true if X is an odd number. (b) Based on the successor notion, define a relationship "even (X)" which is true if X is an even number. Your definition should be built on top of the odd (X) relationship. (c) How will Prolog answer the following question? ?- even(X). When several responses are possible, give two. (d) How will Prolog answer the following question? ?- odd(s(X)). When several responses are possible, give two.Explanation / Answer
A,b answers:
( X < x%2 ->0
writeln('X is even.'),
fail
; X =:= x%2!->0
writeln('X is odd.')
;
)
C,d)
answers
Even(s(s(x))):-even(x)
Odd(s(0))
Odd(x):-even(s(x))
Queries:
Odd(s(s(0))
Odd(s(0)
Odd(x):-greater(x,s(0)),even(s(x))
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.