Question: Procedure for Sort "by proxy" (sort list using another list)

Hello

 

I need help creating a proceadure that does the following:

 

It takes two lists of the same length N   (0<N<inf), one is the numerical pivote list P and the other is a symbolic target list S.

 

Lets say for the simple case of N=3 that we input:

 

P=[22.5,14.3,78.2]

S=[x[1],x[2],x[3]]

 

First the proceadure will sort the Pivote list P, which will result in a local variable Ps=[14.3,22.5,78.2]

 

Next it will generate the rearanged indices of S when it was transformed into Ps, meaning the sort indices rearangment from [1,2,3] in S into [2,1,3] in Ps. This will result in another local variable PSI=[2,1,3]

 

Finally, the proceadure will use PSI to rearange (sort by proxy) the target list P, which in this case will result in the folowing output of [x[2],x[1],x[3]], where x[i] can be either symbolic variable or numeric.

 

So what I need is to use numeric list P to sort a non numeric list S of the same size.

 

I'd appreciate any tips or usefule commands that I can use in this proceadure. 

 

Thanks

 

 

Please Wait...