Post Reply 
(49g 50g) Triangular Matrix Utilities
03-07-2021, 09:48 PM
Post: #2
RE: (49g 50g) Triangular Matrix Utilities
Update with one change and one new program.

The program C->LT has been replaced by C->M which turns a list of columns into a lower triangular matrix. C->LT can simply be replaced by C->M M->LT.

The new program TRICOL extracts a column or diagonal from a triangle. With the triangle (a list of lists) on level 2 and an integer n on level 1, the program returns the nth column as a list.

If n is negative, the nth column from the right is returned. If n = 0, the central column is returned. Since the central column consists of the central term from odd rows only, the central column will have half as many terms as the triangle has rows.

TRICOL requires ListExt 1.3 but can be re-written using DOLIST at some cost in speed and program size.

I am posting as a directory object again for convenience but all of the other programs are unchanged.

Code:

DIR
  LT\->M
  \<< DUP SIZE \-> n
    \<< 1. n 1. -
      FOR j j DUP2 GET 0 n j - NDUPN \->LIST + PUT
      NEXT AXL
    \>>
  \>>
  M\->LT
  \<< AXL 1.
    \<< 1. NSUB SUB
    \>> DOSUBS
  \>>
  C\->M
  \<< DUP SIZE \-> n
    \<< 1. n
      FOR k DUP k GET 0 k 1. - NDUPN \->LIST SWAP + 1. n SUB AXL SWAP
      NEXT DROP n COL\->
    \>>
  \>>
  M\->AD
  \<< \->COL \->LIST 1.
    \<< AXL
    \>> DOLIST C\->M M\->LT
  \>>
  UNFLT
  \<< { } SWAP 1. \-> k
    \<<
      WHILE DUP SIZE k \>=
      REPEAT k SPLIT UNROT 1. \->LIST + SWAP 'k' INCR DROP
      END DROP
    \>>
  \>>
  TRICOL
  \<< I\->R \-> n
    \<<
      IF n 0 \=/
      THEN n ABS OVER SIZE SUB n 0. < { :: REV LMAP } IFT { n ABS GET } LMAP
      ELSE 1.
        \<< NSUB 2. MOD { NSUB 2. / GET } { DROP } IFTE
        \>> DOSUBS
      END
    \>>
  \>>
END
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: (49g 50g) Triangular Matrix Utilities - John Keith - 03-07-2021 09:48 PM



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