## Why does decode of a matrix work by column and not row

General APL language issues

### Why does decode of a matrix work by column and not row

I have matrix ← 4 3 ⍴ 0 0 0 1 1 0 0 1 1 1 1 1
Code: Select all
`0 0 01 1 00 1 11 1 1`

I wish to convert each row from binary to decimal with the ⊥ primitive. The result is
Code: Select all
`2⊥ matrix5 7 3`

I thought/expected to get 0 6 3 7. I had to transpose the matrix to get what I thought.

Code: Select all
`2⊥⍉matrix0 6 3 7`

Yet if I sum reduce the matrix, it operates by rows

Code: Select all
`+/matrix0 2 2 3`

So why does the ⊥ seem to function on rank 2, while the / functions on rank 1? There is a separate ⌿ function to operate on rank 2.
Code: Select all
`+⌿matrix2 3 2`

This seems inconsistent between the two primitives with one operating column-wise and the other row-wise.
+←--------------------------------------------------------------→
+ Jay Moskowitz
+←--------------------------------------------------------------→
+

jmosk

Posts: 69
Joined: Thu Jul 18, 2013 5:15 am

### Re: Why does decode of a matrix work by column and not row

In fact decode works not on rank 2 but on the first dimension. The fact that reduction works on the last dimension is a mistake or oversight made in the earliest impementations and only corrected by Ken and Roger when they implemented J.

So the why is history.

Phil Last

Posts: 628
Joined: Thu Jun 18, 2009 6:29 pm
Location: Wessex

### Re: Why does decode of a matrix work by column and not row

Hello,
Decode syntax is derived from internal product syntax which operates on last dimension of left argument and first dimension of right argument.
Regards.
--
Yves-Antoine Emmanuelli
--
Yves-Antoine Emmanuelli

yaemmanuelli

Posts: 16
Joined: Sat Aug 01, 2020 6:29 pm
Location: Recloses, France

### Re: Why does decode of a matrix work by column and not row

To summarise previous posts:

1. Regard ⌿ as the primary form and works along the leading axis, and / is convenient name for ⌿⍤1 which works along the trailing axis
2. ⊥ is a convenient wrapper on +.× namely {⍵+.×⍨⌽×\1,⍺⍴⍨¯1+≢⍵} making it work along the leading axis
1. As with ⌿ you can make ⊥ work along the trailing axis with ⍤1:
Code: Select all
`      2(⊥⍤1)matrix0 6 3 7`