Applied PQC GitHub Home Playground Blog @AppliedPQC

Linear Algebra Foundations

Every code listing from this chapter of Applied Post-Quantum Cryptography — 7 in total, 7 runnable here. Edit any cell and press Run.

The book's snippets build on each other down the chapter, but a Sage Cell kernel runs one cell and keeps no state afterwards, so each cell replays the earlier listings with apqc_book. That call is the only thing added to the book's own code.

← the playground

Listing 1 — Sage experiment: creating a vector

Listing 2 — Vector addition and scalar multiplication

Listing 3 — Sage experiment: detecting dependence through rank

Dependence is detected numerically by rank, defined precisely below: stacking the vectors as rows, the rank counts how many are genuinely independent.

Listing 4 — Sage experiment: two bases for one space

Listing 5 — Matrices as linear maps

A matrix is best understood not as a grid of numbers but as the coordinate form of a linear map.

[Linear map] A map T: 𝔽^n → 𝔽^m is linear if it respects both operations:

Once bases are fixed, every linear map is given by an m× n matrix A via T(v)=Av, and every such matrix defines a linear map.

The product Av is itself a linear combination: it is the combination of the columns of A weighted by the entries of v. Concretely, entry i of the result is the inner product of row i of A with v, which is exactly the double loop of the algorithm in the book.

Listing 6 — Sage experiment: rank governs invertibility

Listing 7 — Experiments