Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1. sublist/2 Write a Prolog predicate sublist(X,Y) that is true if list X is a s

ID: 3830963 • Letter: 1

Question

1. sublist/2
Write a Prolog predicate sublist(X,Y) that is true if list X is a sublist of list Y. A
sublist is defined as the original list, in the same order, but in which some elements
may have been removed. For instance (user input is in bold):


?- sublist([a,b],[a,e,b,d,s,e]).
Yes

?- sublist([a,b],[a,e,e,f]).
No

?- sublist([a,b],[b,a]).
No

?- sublist([],[a,e,e,f]).
Yes

?- sublist([a],[]).
No

?- sublist(X,[a,b,c]).
X = [] ;
X = [a] ;
X = [a, b] ;
X = [a, b, c] ;
X = [a, c] ;
X = [b] ;
X = [b, c] ;
X = [c] ;
No

Explanation / Answer

CODE:

This code works for both subsequences and non subsequences in the list.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Chat Now And Get Quote