Skip to main content

๐Ÿ“‹ Instruction Grids

Understanding Matricesโ€‹


๐ŸŽฏ The Simple Storyโ€‹

Imagine you have a bingo card - a grid of boxes with numbers or arrows in each one.

Instead of one arrow telling you where to go, you have a whole table of arrows!

Each box in the table tells you: "If you follow THIS rule, go HERE."

That table = that's a matrix!

Matrices let you do many vector operations at once!


๐Ÿง  Mental Modelโ€‹

Hold this picture in your head:

Matrix = Bingo card of instructions

Instructions for how to transform one vector into another:

Input: vโ‚€ vโ‚ vโ‚‚ vโ‚ƒ (4 input values)

Output:
wโ‚€ = [ aโ†ฆb aโ†ฆc aโ†ฆe aโ†ฆg ] โ† First output
wโ‚ = [ bโ†ฆc bโ†”d bโ†ฆe bโ†ฆh ] โ† Second output
wโ‚‚ = [ cโ†ฆe cโ†”d cโ†”f cโ†ฆe ] โ† Third output

Each position in matrix = "How much input vโฑผ contributes to output wแตข"

Think of it like this:

  • Bingo card: Each square = instruction
  • Recipe book: Each page = combining different ingredients
  • Playlist: Each song = different mood

Matrix = Table combining all inputs to create all outputs


๐Ÿ“Š See It Happenโ€‹

Let's see how a matrix transforms vectors:


๐ŸŽฎ Try It Yourselfโ€‹

Question 1: Given matrix M and vector v, what's the result?

Matrix M:

Row 1: [1, 2, 3]
Row 2: [0, 1, 4]

Vector v: (5, 2, 1)

Show Answer

Compute each output:

Output wโ‚€ (first row): 1ยท5 + 2ยท2 + 3ยท1 = 5 + 4 + 3 = 12

Output wโ‚ (second row): 0ยท5 + 1ยท2 + 4ยท1 = 0 + 2 + 4 = 6

Result vector: (12, 6)


Question 2: If matrix A = [[2, 0], [1, 3]] and vector x = (4, 5), what's Ax?

Show Answer

Matrix A:

  • Row 1: [2, 0]
  • Row 2: [1, 3]

Compute:

Output yโ‚€ = 2ยท4 + 0ยท5 = 8 + 0 = 8 Output yโ‚ = 1ยท4 + 3ยท5 = 4 + 15 = 19

Result: (8, 19)


Question 3: What's the matrix that sends (1, 0) โ†’ (2, 3) and (0, 1) โ†’ (5, 1)?

Show Answer

Matrix = [first column, second column]

Column 1 = image of (1, 0) = (2, 3) Column 2 = image of (0, 1) = (5, 1)

Matrix M:

[ 2  5 ]
[ 3 1 ]

Check:

  • Mยท(1, 0) = (2, 3) โœ“
  • Mยท(0, 1) = (5, 1) โœ“

๐Ÿ”ข The Mathโ€‹

Matrix Notationโ€‹

Mathematicians write matrices with rows and columns:

A=[a11a12a13a21a22a23a31a32a33]\mathbf{A} = \begin{bmatrix} a_{11} & a_{12} & a_{13} \\ a_{21} & a_{22} & a_{23} \\ a_{31} & a_{32} & a_{33} \end{bmatrix}

Where:

  • aija_{ij} = Entry at position (row i, column j)
  • Row i = Horizontal (left โ†’ right)
  • Column j = Vertical (top โ†’ bottom)

Example 2ร—2 matrix: A=[1234]\mathbf{A} = \begin{bmatrix} 1 & 2 \\ 3 & 4 \end{bmatrix}

Matrix-Vector Multiplicationโ€‹

To multiply matrix A\mathbf{A} by vector v\mathbf{v}:

Av=[a11a12โ€ฆa21a22โ€ฆโ‹ฎโ‹ฎโ‹ฑ][v0v1v2โ‹ฎ]=[a11v0+a12v1+โ€ฆa21v0+a22v1+โ€ฆโ‹ฎ]\mathbf{A}\mathbf{v} = \begin{bmatrix} a_{11} & a_{12} & \dots \\ a_{21} & a_{22} & \dots \\ \vdots & \vdots & \ddots \end{bmatrix} \begin{bmatrix} v_0 \\ v_1 \\ v_2 \\ \vdots \end{bmatrix} = \begin{bmatrix} a_{11}v_0 + a_{12}v_1 + \dots \\ a_{21}v_0 + a_{22}v_1 + \dots \\ \vdots \end{bmatrix}

In words: Each output = sum of (row entries) ร— (vector entries)

Simplified:

  • Output position 0 = dot product of row 0 and vector
  • Output position 1 = dot product of row 1 and vector
  • Output position i = dot product of row i and vector

Matrix Dimensionsโ€‹

If matrix A\mathbf{A} has rr rows and cc columns, and vector v\mathbf{v} has cc entries, then:

Av\mathbf{A}\mathbf{v} = vector with rr entries

Example:

  • 3ร—4 matrix ร— 4-entry vector = 3-entry output
  • 2ร—2 matrix ร— 2-entry vector = 2-entry output

ML-KEM uses 3ร—3 matrix = 3-entry output


๐Ÿ’ก Why We Careโ€‹

Problem: ML-KEM Has Many Parallel Operationsโ€‹

During key generation, ML-KEM computes:

t=As+e\mathbf{t} = \mathbf{A}\mathbf{s} + \mathbf{e}

Where:

  • A\mathbf{A} = 3ร—3 matrix (9 entries)
  • s\mathbf{s} = entry vector (3 entries)
  • e\mathbf{e} = error vector (3 entries)

Without matrices, you'd write:

tโ‚€ = Aโ‚€โ‚€ยทsโ‚€ + Aโ‚€โ‚ยทsโ‚ + Aโ‚€โ‚‚ยทsโ‚‚ + eโ‚€
tโ‚ = Aโ‚โ‚€ยทsโ‚€ + Aโ‚โ‚ยทsโ‚ + Aโ‚โ‚‚ยทsโ‚‚ + eโ‚
tโ‚‚ = Aโ‚‚โ‚€ยทsโ‚€ + Aโ‚‚โ‚ยทsโ‚ + Aโ‚‚โ‚‚ยทsโ‚‚ + eโ‚‚

That's 3 equations with 9 matrix entries!

With matrix notation: t=As+e\mathbf{t} = \mathbf{A}\mathbf{s} + \mathbf{e}

One equation! Much simpler!

Matrix = Compacted Parallel Operationsโ€‹

Matrix-vector multiplication = computing MANY dot products in parallel:

Output entry 0 = dot(row 0, vector)
Output entry 1 = dot(row 1, vector)
Output entry 2 = dot(row 2, vector)

All done at once when you write: ๐€๐ฏ

This is powerful for:

  • Cryptography (ML-KEM, etc.)
  • Machine learning (neural networks)
  • Graphics (3D transformations)
  • Linear algebra (solving equations)

ML-KEM's Matrix Formatโ€‹

In ML-KEM:

AโˆˆRqkร—k\mathbf{A} \in R_q^{k \times k}

Where:

  • k=3k = 3 for ML-KEM768
  • RqR_q = Polynomial ring (polynomials with coefficients modulo 3329)
  • Each entry AijA_{ij} = A polynomial

So actually: Matrix of polynomials!

A=[P11P12P13P21P22P23P31P32P33]\mathbf{A} = \begin{bmatrix} P_{11} & P_{12} & P_{13} \\ P_{21} & P_{22} & P_{23} \\ P_{31} & P_{32} & P_{33} \end{bmatrix}

Where each PijP_{ij} = Polynomial with 256 coefficients!

But we'll learn about polynomial matrices soon. For now, just know:

ML-KEM matrix = 3ร—3 = 9 polynomials ร— 256 coefficients = 2304 entries!


โœ… Quick Checkโ€‹

Can you explain matrices to a 5-year-old?

Try saying this out loud:

"A matrix is like a bingo card - a table where each box has a job. When you give the matrix some numbers, it looks at each row, multiplies the boxes by the numbers, and gives you back answers for each row. It's like doing many different math problems at once!"

Can you multiply a 2ร—2 matrix by a 2D vector?

Try this examples:

Matrix A = [[2, 1], [0, 3]] Vector v = (4, 2)

Compute Aยทv:

Output position 0 = 2ยท4 + 1ยท2 = 8 + 2 = 10 Output position 1 = 0ยท4 + 3ยท2 = 0 + 6 = 6

Result: (10, 6)


๐ŸŽ“ Key Takeawaysโ€‹

โœ… Matrix = Table of instructions (bingo card metaphor) โœ… Matrix-vector multiplication = Compute dot products for each row โœ… Output size = Number of rows in matrix โœ… Compacts many operations = Write one equation instead of many โœ… ML-KEM = Uses 3ร—3 polynomial matrices โœ… Polynomial matrices = 9 polynomials ร— 256 coefficients = 2304 entries


๐ŸŽ‰ What You'll Learn Nextโ€‹

Now you understand matrices! Next, we'll learn about the recipes that loop back:

๐Ÿ“œ Recipes That Loop โ†’ Polynomial Rings

How polynomials create the structure ML-KEM needs for fast operations!