>>>>> "sen1" == sen1 <sen1 at math.msu.edu> writes:
sen1> Hello,
sen1> Is there an easy function to find the permutation used in
sen1> sorting a list?
sen1> For instance, take the list
sen1> xx: [2,3,1,5]
sen1> Sorting it in increasing order gives
sen1> yy: [1,2,3,5]
sen1> So, the permutation s() which produced the sort is
sen1> s(1) = 2, s(2)=3, s(3) = 1, s(4) = 4
sen1> Thanks for any information.
Isn't the typical way of producing this from a sort function that
doesn't return the permutation is to add it yourself? Something like:
xx : [2,3,1,5]$
xy : map(lambda([x,y],[x,y]), xx, makelist(i,i,1,4));
=> [[2, 1], [3, 2], [1, 3], [5, 4]]
sort(xy, lambda([x,y],orderlessp(x[1],y[1])));
=> [[1, 3], [2, 1], [3, 2], [5, 4]]
map(second, %);
=> [3, 1, 2, 4]
Not exactly what you wanted for s, but basically the same info.
Ray