:- use_module(library(lists)).(can be autoloaded)
If both Xs and Ys are provided and both lists
have equal length the order is
Simply testing whether Xs is a permutation of Ys
can be achieved in order log(
using msort/2 as
illustrated below with the
semidet predicate is_permutation/2:
is_permutation(Xs, Ys) :- msort(Xs, Sorted), msort(Ys, Sorted).
The example below illustrates that Xs and Ys being proper lists is not a sufficient condition to use the above replacement.
?- permutation([1,2], [X,Y]). X = 1, Y = 2 ; X = 2, Y = 1 ; false.