Post Reply 
(49G) Permutation List 2 Permutation Matrix
05-30-2015, 07:04 AM (This post was last modified: 06-15-2017 01:44 PM by Gene.)
Post: #1
(49G) Permutation List 2 Permutation Matrix
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 ]].

Code:
::
  CK1
  FPTR 7 17B
  DUPLENCOMP
  DUP'
  FPTR2 ^COERCE2Z
  4ROLL
  2Ob>Seco
  '
  ::
    ROT
    NTHCOMPDROP
    FPTR2 ^Z2BIN
    #=ITE
    Z1_
    Z0_
  ;
  &COMP
  FPTR2 ^MAKE2DMATRIX
 ;
Find all posts by this user
Quote this message in a reply
Post Reply 




User(s) browsing this thread: 1 Guest(s)