</> APL Run Loading interactive WebAssembly workspace…

🎓 Chapter 5: Outer Products & Grid Generators

One of APL's most famous and expressive capabilities is the Outer Product Operator (∘.f).

---

1. What is an Outer Product?

If you have a vector A of length M and a vector B of length N, the Outer Product A ∘.f B applies function f to all possible pairs of elements (a in A, b in B) to produce an M × N matrix!

Formula:

M[i, j] = A[i] f B[j]

Applications:

  • Multiplication / Addition tables
  • Distance matrices in 2D physics
  • Coordinate grids for complex fractals and computer graphics.
⍝ Generate a 10x10 multiplication table using (⍳10) ∘.× (⍳10)
MultTable ← (⍳10) ∘.× (⍳10)
MultTable

---

2. Distance Matrix Calculation

We can calculate 1D distances between every point in vector A and vector B using absolute difference | ⍺ - ⍵:

⍝ Absolute difference distance matrix
A ← 1 3 7 10
B ← 2 5 8
| A ∘.- B

---

3. Complex Coordinate Grids for Fractals & Graphics

By using addition ∘.+ with imaginary numbers 0J1 × R, we can construct a 2D grid of complex numbers C = Y + iX:

R ← ¯2 + ⍳ 5
I ← ¯1 + ⍳ 4
Grid ← I ∘.+ (0J1 × R)
Grid

← Chapter 4: Reductions (/) & Prefix Scans (\) Chapter 6: Dfns ({⍺ ⍵}), Guards & Recursion →