Search code examples
data-structuresgnufoldapl

Row Reduction with indexed parameters in GNU APL


I'm using the following data structure:

x1a ← 2 1 ⍴ 1 0
x1b ← ⍬

x2a ← 2 2 ⍴ 1 1 0 0
x2b ← 2 1 ⍴ 1 0

x3a ← 1 2 ⍴ 1 0
x3b ← 1

q ← (x3a x3b) (x2a x2b) (x1a x1b)

And attempting a row reduction equivalent to the following operations:

output ← x3b + x3a +.× x2b + x2a +.× x1a

I was thinking the result would be similar to the following, but I can't get the correct rank/operations working:

{⍵[2] + ⍺[1] +.× ⍵[1]}/q

Appreciate any advice or help!


Solution

  • There are three issues:

    1. You are using ⍵[1] which will give you an enclosed element of . Use "pick" instead.

    2. You have a typo: ⍵[2] should use instead, i.e. 2⊃⍺

    3. The function you reduce with, expects its right argument to be a two element vector, where it uses only the first element. It therefore needs to return such a structure for the next iteration.

    Also note that the result will both be enclosed due to / needing to reduce the rank from 1 to 0, and furthermore will have the inserted dummy element, so we need to pick the first element of the only element, that is, ⍬ 1⊃:

          x3b + x3a +.× x2b + x2a +.× x1a
    3
          ⍬ 1⊃{((2⊃⍺) + (1⊃⍺) +.× (1⊃⍵)) 'dummy'}/q
    3
    

    Try it online!