Post Reply 
(50g) Outer Product, Kronecker Product
02-23-2019, 03:14 PM
Post: #1
(50g) Outer Product, Kronecker Product
Inspired by this thread, I am posting two programs for the 50g.

The first program, which will also run on the 48G, computes the outer product of two vectors or the Kronecker product of two matrices.

Code:

\<< SWAP DUP2 SIZE SWAP SIZE +
  IF DUP SIZE 2. SAME
  THEN EVAL 4. ROLL SWAP 1. SWAP 2. \->LIST RDM UNROT 1. 2. \->LIST RDM SWAP *
  ELSE EVAL \-> a m n p q
    \<< DUP m p * n q * 2. \->LIST RDM 1. m
      FOR i 1. n
        FOR j OVER a i j 2. \->LIST GET * i 1. - p * 1. + j 1. - q * 1. + 2. \->LIST SWAP REPL
        NEXT
      NEXT NIP
    \>>
  END
\>>

The next program computes the "generalized outer product" of two vectors. Level 1 should have a program which takes two arguments. Levels 2 and 3 should have vectors, which need not be the same size. The output will be a matrix whose elements result from the function being applied to corresponding elements of the input vectors.

For example, if the function is \<< * \>> the result will be the outer product of the two vectors.

Code:

\<< SWAP AXL PICK3 SIZE EVAL OVER SIZE \-> c f r cs rs
  \<< 1. cs
    FOR j c j GET rs NDUPN \->LIST r 2. f DOLIST
    NEXT cs \->LIST AXL
  \>>
\>>
Find all posts by this user
Quote this message in a reply
Post Reply 




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