๐ 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:
Where:
- = Entry at position (row i, column j)
- Row i = Horizontal (left โ right)
- Column j = Vertical (top โ bottom)
Example 2ร2 matrix:
Matrix-Vector Multiplicationโ
To multiply matrix by vector :
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 has rows and columns, and vector has entries, then:
= vector with 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:
Where:
- = 3ร3 matrix (9 entries)
- = entry vector (3 entries)
- = 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:
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:
Where:
- for ML-KEM768
- = Polynomial ring (polynomials with coefficients modulo 3329)
- Each entry = A polynomial
So actually: Matrix of polynomials!
Where each = 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!