Matrix Multiplication in APL

I’ve been working on linear algebra in APL and I decided to write an article on one of the fundamental operations of linear algebra (and neural networks), matrix multiplication! In this post I walk through how to multiply a 2x2 array by a 2x1 array.

And there’s no matrix multiplication glyph :scream:!

This post walks through:

  • What is matrix multiplication and manual calculation in this simple example
  • How to do matrix multiplication in APL step by step and how and why it works (including explaining the dot glyph)
  • Shows a first (relatively) simple example of how glyphs will combine in a really powerful and flexible ways. Matrix multiplication for example is +.x, rather than having a glyph specific to matrix multiplication.

Hope you enjoy!

Link to post

5 Likes

Great stuff. I’m a big fan of inner product in APL. So cool the way they generalised the idea beyond standard math notation

1 Like

Hey all - I got a question about how this works with a matrix times a matrix instead of a matrix times a vector, so I updated the post to include an example showing that it works the same way with 2 matrices!

@Ezno I believe that, because inner product in APL is an operator, not a function, the arguments to it are ⍺⍺ and ⍵⍵, not and .

1 Like

I did not know that. I’ve updated the post to use that convention. Thanks!

Really cool Isaac! :smile: (btw the bullet points in your introduction don’t seem to be parsing properly- I’m viewing on mobile)

I was wondering if someone could help me in understanding the following example:

    (2 2 ⍴ ⍳4) +.× (2 ⍴ 2)
6 14

and

    2 2 ⍴ ⍳4 +.× 2 ⍴ 2
1 2
3 4

I understand the first example, but I am unsure what is going on in the second. I assume it is something with precedence but I am not sure.

APL does right to left precedence. So 2 2 ⍴ ⍳4 +.× 2 ⍴ 2 would be equivalent to (2 2 ⍴ (⍳4 +.× (2 ⍴ 2)))

4 Likes

Nice write-up Explaining matrix multiplication step by step is super helpful, especially for people new to APL. And honestly, the fact that matrix multiplication is built from combining glyphs instead of needing its own dedicated symbol is part of what makes APL so elegant and powerfulT his idea also connects well with how structured systems are used how to read destiny matrix compatibility chart to interpret deeper patterns in different analytical models.