05-30-2015, 07:04 AM
Given a permutation list as input, eg
{ 4 3 1 2 6 5 }
the programme returns the corresponding permutation matrix, in this case
[[ 0 0 0 1 0 0 ]
[ 0 0 1 0 0 0 ]
[ 1 0 0 0 0 0 ]
[ 0 1 0 0 0 0 ]
[ 0 0 0 0 0 1 ]
[ 0 0 0 0 1 0 ]].
As a check, applying the matrix to
[[ 1 ]
[ 2 ]
[ 3 ]
[ 4 ]
[ 5 ]
[ 6 ]]
returns
[[ 4 ]
[ 3 ]
[ 1 ]
[ 2 ]
[ 6 ]
[ 5 ]].
{ 4 3 1 2 6 5 }
the programme returns the corresponding permutation matrix, in this case
[[ 0 0 0 1 0 0 ]
[ 0 0 1 0 0 0 ]
[ 1 0 0 0 0 0 ]
[ 0 1 0 0 0 0 ]
[ 0 0 0 0 0 1 ]
[ 0 0 0 0 1 0 ]].
As a check, applying the matrix to
[[ 1 ]
[ 2 ]
[ 3 ]
[ 4 ]
[ 5 ]
[ 6 ]]
returns
[[ 4 ]
[ 3 ]
[ 1 ]
[ 2 ]
[ 6 ]
[ 5 ]].
Code:
::
CK1
FPTR 7 17B
DUPLENCOMP
DUP'
FPTR2 ^COERCE2Z
4ROLL
2Ob>Seco
'
::
ROT
NTHCOMPDROP
FPTR2 ^Z2BIN
#=ITE
Z1_
Z0_
;
&COMP
FPTR2 ^MAKE2DMATRIX
;