#SAV(L): inputs a list of complex numbers, and outputs the permutation of {1, ..., nops(L)} that #makes it weakly decreasing. Try: #SAV([4,-2,I+1]); SAV:=proc(L) local L1,T,i: L1:=[seq(evalf(abs(L[i])),i=1..nops(L))]: for i from 1 to nops(L1) do T[L1[i]]:=i: od: L1:=sort(L1, `>`): [seq(T[L1[i]],i=1..nops(L1))]: end: