CS代考 Implement the following predicate:

Implement the following predicate:
replace(E1, L1, E2, L2)
this holds when list L1 is the same as L2, except that in one place
where L1 has the value E1, L2 has E2. Note that only one

Copyright By PowCoder代写 加微信 powcoder

occurrence of E1 is replaced. This must work in any mode in whict
at least one of L1 or L2 is a proper list (that is, either I or a list
whose tail is a proper list). For example:
replace(2,[1,2,3,41,5,X) should have only the solution X = [1,5,3,4]
replace(2,[1,2,3,2,11,5X) should backtrack over the solutions X
[1,53,2,11 and X = [1,2,3,5,1].
replace(2X,5,[1,5,3,5,1]) should backtrack over the solutions X=
[1,2,3,5,1] and X = [1,5,3,2,1].
replace(×,[a,b,c,d], Y,la, e, c,d]) should have only the solution X = b, Y =
replace(X,[1,2,3,2,1],Y,[1,5,3,5,11) should have no solutions (it should

Implement the following predicate:
zip(As, Bs, ABs)
this holds when As, Bs, and ABs are lists of the same length, and
each element of ABs is a term of the form A-B where A is the
corresponding element of As and B is the corresponding element o
Bs. This should work whenever at least one of the arguments is a
proper list. Note that – is an infix operator here, but aside from
syntax, A-B is an ordinary term whose functor is – and whose two
arguments are A and B. For example:
zip (11,2,3,4],[a,b,c,d],L) should have only the solution L=[1-a,2-b,3-c,4-
zip(X,Y, [1-a,2-b,3-c,4-d]) should have only the solution X=[1,2,3,4], Y=
zip([1,2,3,4], Y, [1-a,2-b,3-c,4-d]) should have only the solution Y=
la,b,c.d].
zip(XIa,b,c,d][1-P,2-Q,3-R,4-S]) should have only the solution X=
[1,2,3,4], P=a, Q=b, R=c, S=d.
zip([1,2,3] [a,b,c,d], L) should fail.

Implement the following predicate:
sublist(Xs, Ys)
this holds when Xs is a list containing some of the elements of Ys,
in the same order they appear in the list Ys. This should work
whenever Ys is a proper list. For example:
sublist(la,c,e],[a,b,c,d,e]) should succeed.
sublist(la,e,c],la,b,c,d,e]) should fail.
sublist(la,X,d],a,b,c,d,e]) should have the two solutions X=b and
sublist(X,la,b,cl) should have the eight solutións X=]; X=[cl; X=[bl;
X=[b,c); X=[a]; X=[a,c]; X=[a,b]; and X=[a,b,c].

程序代写 CS代考 加微信: powcoder QQ: 1823890830 Email: powcoder@163.com