The reverse(X,Y)
goal succeeds if the elements of list X
are in reverse order of the elements in list Y
.
Examples
?- reverse([a],[a]).
yes
?- reverse([a,b,c],[c,b,a]).
yes
?- reverse([a,b,c],X).
X = [c,b,a]
yes
?- reverse(X,[a,b,c]).
X = [c,b,a]
yes
?- reverse([],[]).
yes
?- reverse([],X).
X = []
yes
?- reverse(X,[]).
X = []
yes
?- reverse([a,b,c],[]).
no
?- reverse([a,b,c],[a,b,c]).
no
?- reverse([a,b,c],[d,c,b,a]).
no
?- reverse([a,b,c,d],[c,b,a]).
no
?- reverse([a,b,c],'abc').
no
?- reverse('abc',X).
no
?- reverse([a,b|c],X).
no
?- reverse([a|X], Y).
X = []
Y = [a]
yes;
X = [_]
Y = [_,a]
yes;
X = [_,_]
Y = [_,_,a]
yes;
X = [_,_,_]
Y = [_,_,_,a]
yes
?- reverse([z,x,x,c,b|X],[a,b,c|Y]).
X = [a]
Y = [x,x,z]
yes;
X = [c,b,a]
Y = [b,c,x,x,z]
yes;
X = [_,c,b,a]
Y = [_,b,c,x,x,z]
yes;
X = [_,_,c,b,a]
Y = [_,_,b,c,x,x,z]
yes;
X = [_,_,_,c,b,a]
Y = [_,_,_,b,c,x,x,z]
yes
?- reverse([a,b,c|Y],[z,x,x,c,b|X]).
X = [a]
Y = [x,x,z]
yes;
X = [c,b,a]
Y = [b,c,x,x,z]
yes;
X = [_,c,b,a]
Y = [_,b,c,x,x,z]
yes;
X = [_,_,c,b,a]
Y = [_,_,b,c,x,x,z]
yes;
X = [_,_,_,c,b,a]
Y = [_,_,_,b,c,x,x,z]
yes
?- reverse([c,b,a|X],[c,b,a|Y]).
X = [b,c]
Y = [b,c]
yes;
X = [a,b,c]
Y = [a,b,c]
yes;
X = [_,a,b,c]
Y = [_,a,b,c]
yes;
X = [_,_,a,b,c]
Y = [_,_,a,b,c]
yes;
X = [_,_,_,a,b,c]
Y = [_,_,_,a,b,c]
yes
?- reverse([b,c|X],[a,b,c|Y]).
X = [b,a]
Y = [b]
yes;
X = [c,b,a]
Y = [c,b]
yes;
X = [_,c,b,a]
Y = [_,c,b]
yes;
X = [_,_,c,b,a]
Y = [_,_,c,b]
yes;
X = [_,_,_,c,b,a]
Y = [_,_,_,c,b]
yes
?- reverse([a,b,c|Y],[b,c|X]).
X = [b,a]
Y = [b]
yes;
X = [c,b,a]
Y = [c,b]
yes;
X = [_,c,b,a]
Y = [_,c,b]
yes;
X = [_,_,c,b,a]
Y = [_,_,c,b]
yes;
X = [_,_,_,c,b,a]
Y = [_,_,_,c,b]
yes
?- X=[d,c|Q],Y=[a,b,c|R],reverse(X,Y).
Q = [b,a]
R = [d]
X = [d,c,b,a]
Y = [a,b,c,d]
yes;
Q = [c,b,a]
R = [c,d]
X = [d,c,c,b,a]
Y = [a,b,c,c,d]
yes;
Q = [_,c,b,a]
R = [_,c,d]
X = [d,c,_,c,b,a]
Y = [a,b,c,_,c,d]
yes;
Q = [_,_,c,b,a]
R = [_,_,c,d]
X = [d,c,_,_,c,b,a]
Y = [a,b,c,_,_,c,d]
yes;
Q = [_,_,_,c,b,a]
R = [_,_,_,c,d]
X = [d,c,_,_,_,c,b,a]
Y = [a,b,c,_,_,_,c,d]
yes
?- X=[d,c|Q],Y=[a,b,c|R],reverse(Y,X).
Q = [b,a]
R = [d]
X = [d,c,b,a]
Y = [a,b,c,d]
yes;
Q = [c,b,a]
R = [c,d]
X = [d,c,c,b,a]
Y = [a,b,c,c,d]
yes;
Q = [_,c,b,a]
R = [_,c,d]
X = [d,c,_,c,b,a]
Y = [a,b,c,_,c,d]
yes;
Q = [_,_,c,b,a]
R = [_,_,c,d]
X = [d,c,_,_,c,b,a]
Y = [a,b,c,_,_,c,d]
yes;
Q = [_,_,_,c,b,a]
R = [_,_,_,c,d]
X = [d,c,_,_,_,c,b,a]
Y = [a,b,c,_,_,_,c,d]
yes
?- X=[e,d|Q],Y=[a,b,c|R],reverse(X,Y).
Q = [c,b,a]
R = [d,e]
X = [e,d,c,b,a]
Y = [a,b,c,d,e]
yes;
Q = [_,c,b,a]
R = [_,d,e]
X = [e,d,_,c,b,a]
Y = [a,b,c,_,d,e]
yes;
Q = [_,_,c,b,a]
R = [_,_,d,e]
X = [e,d,_,_,c,b,a]
Y = [a,b,c,_,_,d,e]
yes;
Q = [_,_,_,c,b,a]
R = [_,_,_,d,e]
X = [e,d,_,_,_,c,b,a]
Y = [a,b,c,_,_,_,d,e]
yes
?- X=[e,d|Q],Y=[a,b,c|R],reverse(Y,X).
Q = [c,b,a]
R = [d,e]
X = [e,d,c,b,a]
Y = [a,b,c,d,e]
yes;
Q = [_,c,b,a]
R = [_,d,e]
X = [e,d,_,c,b,a]
Y = [a,b,c,_,d,e]
yes;
Q = [_,_,c,b,a]
R = [_,_,d,e]
X = [e,d,_,_,c,b,a]
Y = [a,b,c,_,_,d,e]
yes;
Q = [_,_,_,c,b,a]
R = [_,_,_,d,e]
X = [e,d,_,_,_,c,b,a]
Y = [a,b,c,_,_,_,d,e]
yes
?- reverse([a,b,c|Y],[X|Z]).
X = c
Y = []
Z = [b,a]
yes;
X = UNINSTANTIATED VARIABLE
Y = [X]
Z = [c,b,a]
yes;
X = UNINSTANTIATED VARIABLE
Y = [_,X]
Z = [_,c,b,a]
yes;
X = UNINSTANTIATED VARIABLE
Y = [_,_,X]
Z = [_,_,c,b,a]
yes
?- reverse([a,b|X],[a,b|X]).
X = [a]
yes;
X = [b,a]
yes;
X = [X,b,a]
yes;
X = [X,X,b,a]
yes;
X = [X,X,X,b,a]
yes
?- reverse(X,X), numbervars(X).
X = []
yes;
X = [$VAR(0)]
yes;
X = [$VAR(0),$VAR(0)]
yes;
X = [$VAR(0),$VAR(1),$VAR(0)]
yes;
X = [$VAR(0),$VAR(1),$VAR(1),$VAR(0)]
yes;
X = [$VAR(0),$VAR(1),$VAR(2),$VAR(1),$VAR(0)]
yes;
X = [$VAR(0),$VAR(1),$VAR(2),$VAR(2),$VAR(1),$VAR(0)]
yes