Mathematical Foundations

II.16 · Linear Algebra

Can a transformation recover the input it just changed?

Transform an input vector, then recover it with an inverse constructed from exact row operations on [A | I]. Singular maps show where information has been lost.

Construct the map that undoes A

Apply A, then undo with A⁻¹

Original x (2, 1), transformed Ax (5, 3), reconstructed (2, 1).

Original coefficient matrix
[2, 1; 1, 1]
Pivot count / image dimension
2
Independent null directions
0
Null-space basis
none: only the zero vector
Inverse from [A | I]
[1, −1; −1, 2]
Both multiplication checks
I and I, exactly
Reconstructed input
(2, 1)

Exact values use =; numerical companions use ≈. Rank and zero decisions are exact.

Rank 2: 2 independent image directions and 0 null directions. Full rank: the square map is invertible.

A=[2111]A=\begin{bmatrix}2&1\\1&1\end{bmatrix}
rank⁡A+dim⁡ker⁡A=2+0=2\operatorname{rank}A+\dim\ker A=2+0=2
A−1=[1−1−12]A^{-1}=\begin{bmatrix}1&-1\\-1&2\end{bmatrix}
A−1A=AA−1=IA^{-1}A=AA^{-1}=I

Begin with [A | I]

The original equations. Coefficients are left of the augmentation boundary. The same operation acts on all columns of [A | I].

Rows of the current mathematical state; ◆ marks a pivot
R12110
R21101
[21101101]\begin{bmatrix}2&1&1&0\\1&1&0&1\end{bmatrix}

from −4 to 4, up to 2 decimal places

from −4 to 4, up to 2 decimal places

from −4 to 4, up to 2 decimal places

from −4 to 4, up to 2 decimal places

from −4 to 4, up to 2 decimal places

from −4 to 4, up to 2 decimal places

Edit the exact mathematical input, then replay and inspect each immutable state.

Move the input vector and compare its original position with A−1(Ax)A^{-1}(Ax). Replay the construction on the identity block. Switch to Repeated columns and explain why no undoing map appears. The Small 3×3 preset keeps the derivation exact without inventing a planar picture of three-dimensional action.

Intuition: an undoing transformation

A rotation changes coordinates without losing information, so another rotation can recover the input. A collapse onto a line loses a direction: several inputs become the same output. No single-valued transformation can then recover which input was used.

An inverse therefore describes recoverability of the whole transformation. It is not an array of entrywise reciprocals.

Definition

For square A∈Rn×nA\in\R^{n\times n}, an inverse is a matrix A−1A^{-1} satisfying

A−1A=I,AA−1=I.A^{-1}A=I,\qquad AA^{-1}=I.

The identity sends every vector to itself. These identities imply A−1(Ax)=xA^{-1}(Ax)=x and A(A−1y)=yA(A^{-1}y)=y. An inverse exists exactly when AA has full rank. A rectangular map may have a one-sided inverse under suitable rank conditions, but the ordinary two-sided inverse taught here requires a square matrix.

Mechanics: one row operation, two blocks

The live trace starts with [A∣I][A\mid I]. Every swap, scaling and row addition acts on both blocks. If the left block reaches II, the right block is the inverse. If the coefficient rank is too small, the lesson reports that the inverse does not exist.

The plane shows xx, AxAx, and the exactly reconstructed A−1AxA^{-1}Ax at the input tip. The inspector calculates both multiplication identities rather than accepting rounded agreement as proof. Input-vector drag, keyboard movement and numeric entry all update the same state. Exact 2×2 and small 3×3 matrices are supported.

Derivation: why the identity block becomes the inverse

Each elementary row operation is left multiplication by an invertible elementary matrix. Let their composition be EE. Applying the trace to AA yields EA=IEA=I, while applying it to the identity yields EI=EEI=E. The final augmented state is therefore [I∣E][I\mid E], with E=A−1E=A^{-1}.

This works because the same reversible operations transform every column. Equivalently, each identity column is a right-hand side: solve Acj=ejAc_j=e_j and collect the resulting cjc_j as inverse columns. The derivation uses elimination already learned in II.14; it does not hide inverse construction behind a black box.

Worked examples

For A=[2111]A=\begin{bmatrix}2&1\\1&1\end{bmatrix}, reducing the augmented matrix gives

[A∣I]⟶[101−101−12].[A\mid I]\longrightarrow \left[\begin{array}{cc|cc}1&0&1&-1\\0&1&-1&2\end{array}\right].

Thus A−1=[1−1−12]A^{-1}=\begin{bmatrix}1&-1\\-1&2\end{bmatrix}. The opening vector (2,1)(2,1) becomes (5,3)(5,3); applying the inverse returns (5−3,−5+6)=(2,1)(5-3,-5+6)=(2,1). Replay the opening trace to see where each inverse entry came from. Multiplication in either order yields diagonal entries 11 and off-diagonal entries 00.

For A=[110011101]A=\begin{bmatrix}1&1&0\\0&1&1\\1&0&1\end{bmatrix}, the inverse is

12[1−1111−1−111].\frac12\begin{bmatrix}1&-1&1\\1&1&-1\\-1&1&1\end{bmatrix}.

Choose Small 3×3 and inspect the full six-column augmented trace. For repeated columns the left block cannot become II; a nonzero null direction makes unique recovery impossible.

Replay the worked derivation

Begin with [A | I]

The original equations. Coefficients are left of the augmentation boundary. The same operation acts on all columns of [A | I].

Rows of the current mathematical state; ◆ marks a pivot
R12110
R21101
[21101101]\begin{bmatrix}2&1&1&0\\1&1&0&1\end{bmatrix}
Replay the canonical worked example, inspecting each exact mathematical frame.

Executable reference code

The Fraction reference constructs the inverse from the identity block and checks both products. NumPy demonstrates an inverse when the map itself is needed, then uses a direct solve when only an input is required.

code/python/inverse.py
"""Construct [A | I] -> [I | inverse] through exact row operations."""
from fractions import Fraction as F

def inverse(a):
    n = len(a)
    rows = [[F(x) for x in row] + [F(i == j) for j in range(n)] for i, row in enumerate(a)]
    for j in range(n):
        pivot = next((i for i in range(j, n) if rows[i][j]), None)
        if pivot is None:
            return None
        rows[j], rows[pivot] = rows[pivot], rows[j]
        factor = rows[j][j]
        rows[j] = [x/factor for x in rows[j]]
        for i in range(n):
            if i != j:
                factor = rows[i][j]
                rows[i] = [x-factor*y for x, y in zip(rows[i], rows[j])]
    return [row[n:] for row in rows]

A = [[2, 1], [1, 1]]
B = inverse(A)
assert B == [[1, -1], [-1, 2]]
assert inverse([[1, 2], [2, 4]]) is None
for left, right in ((A, B), (B, A)):
    assert [[sum(left[i][k]*right[k][j] for k in range(2)) for j in range(2)] for i in range(2)] == [[1, 0], [0, 1]]
code/python/inverse_numpy.py
import numpy as np
A = np.array([[2., 1.], [1., 1.]])
x = np.array([2., 1.])
y = A @ x
B = np.linalg.inv(A)  # Display an undoing map when it is actually needed.
assert np.allclose(B @ y, x)
assert np.allclose(B @ A, np.eye(2)) and np.allclose(A @ B, np.eye(2))
assert np.allclose(np.linalg.solve(A, y), x)  # Preferred for solving one system.

Explore

Compare an independent map, a zero map and a rank-one collapse. In the close preset, inspect the large inverse coefficients; move between exact existence and numerical sensitivity without confusing them. Recover several input vectors. Check a 3×3 inverse by multiplying one row against each original column.

Common mistakes

The transpose is an inverse only for square orthogonal matrices. Entrywise reciprocals fail because matrix multiplication mixes entries. A singular map does not gain an inverse by ignoring zero rows. To undo BABA, undo BB first and AA second: (BA)−1=A−1B−1(BA)^{-1}=A^{-1}B^{-1}.

Numerical considerations

Although x=A−1bx=A^{-1}b is a valid identity for an invertible matrix, numerical software should generally solve Ax=bAx=b directly using an appropriate factorization. Explicit inverse formation usually costs more work and can introduce avoidable error. The exact identity checks here concern entered rationals; they do not remove coefficient uncertainty or conditioning problems. An extremely thin image can be exactly invertible while giving unstable recovered coordinates.

Engineering and ML connections

Inverse transforms recover coordinate systems and reversible maps. Solvers recover forces, states and parameters from constraints. Most ML least-squares problems are rectangular or noisy, so ordinary inverses are often absent; projection and pseudoinverses provide the relevant replacement in the next chapters.

Exercises

calculation

Construct the undoing map

For A = [[2, 1], [1, 1]], give A⁻¹ by rows.

calculation

Undo an output

The preceding A sends x to y = (5, 3). Recover x.

prediction

Two inputs, one output

A has a nonzero null vector. Can a two-sided inverse exist?

Choose one answer

prediction

Solve in numerical software

You only need x from Ax = b. What is the usual starting choice?

Choose one answer

prediction

Undo a composition

A acts first, then B. How do you undo BA when both are invertible?

Choose one answer

Summary and checkpoints

An inverse recovers every input and output through both identity products. Derive it from [A∣I][A\mid I], connect its existence to exact rank, and distinguish the algebraic inverse identity from the practical choice to solve directly.

The map of the book

97 of 97 chapters written · eight Parts

demo Foundation demo Try the live vector example Open as a page

Part I

Mathematical Language

The notation and mental objects everything else uses.

9 of 9 chapters written

  1. I.1 Scalars, quantities, units, powers and roots available
  2. I.2 Coordinates and points available
  3. I.3 Vectors: components, magnitude, and direction reference chapter available
  4. I.4 Algebraic expressions, equations and inequalities available
  5. I.5 Functions as input → transformation → output available
  6. I.6 Essential function families available
  7. I.7 Sets, intervals, and relations available
  8. I.8 Indexed quantities and summation available
  9. I.9 The notation map for ML available

Part II

Linear Algebra

Matrices as transformations: the strongest foundation in the book.

19 of 19 chapters written

  1. II.1 Vector addition and subtraction available
  2. II.2 Scalar multiplication and vector scaling available
  3. II.3 Norms, magnitude, and normalization available
  4. II.4 Dot product, angle, and orthogonality available
  5. II.5 Projection and distance to a direction available
  6. II.6 Linear combinations and span available
  7. II.7 Linear independence, basis, and coordinates available
  8. II.8 Matrices as linear transformations available
  9. II.9 Matrix × vector available
  10. II.10 Matrix × matrix as composition available
  11. II.11 Transpose and orthogonality available
  12. II.12 Determinant: orientation and area/volume scaling available
  13. II.13 Linear systems as intersecting constraints available
  14. II.14 Gaussian elimination and row operations available
  15. II.15 Rank and invertibility available
  16. II.16 Inverse matrices available
  17. II.17 Eigenvalues and eigenvectors available
  18. II.18 Orthogonal bases and least-squares geometry available
  19. II.19 Singular Value Decomposition available

Part III

Calculus

Change, local approximation, and sensitivity made visible.

15 of 15 chapters written

  1. III.1 Limits through approach available
  2. III.2 Continuity and local behavior available
  3. III.3 Derivative as secant → tangent available
  4. III.4 Derivative as rate of change and local linear model available
  5. III.5 Derivative rules available
  6. III.6 Chain rule available
  7. III.7 Multivariable functions and partial derivatives available
  8. III.8 Gradient and directional derivatives available
  9. III.9 Jacobian available
  10. III.10 Computational graphs and automatic differentiation available
  11. III.11 Hessian and curvature available
  12. III.12 Integrals as accumulation available
  13. III.13 Fundamental derivative/integral connection available
  14. III.14 Numerical differentiation available
  15. III.15 Numerical integration available

Part IV

Probability

Uncertainty through sample spaces, evidence, and repetition.

16 of 16 chapters written

  1. IV.1 Random experiments, outcomes, and sample spaces available
  2. IV.2 Events and probability mass available
  3. IV.3 Counting and finite probability where needed available
  4. IV.4 Conditional probability as restricted sample space available
  5. IV.5 Independence available
  6. IV.6 Bayes' theorem as probability-mass update available
  7. IV.7 Random variables available
  8. IV.8 PMF, PDF, and CDF available
  9. IV.9 Bernoulli and Binomial distributions available
  10. IV.10 Uniform and Gaussian distributions available
  11. IV.11 Expectation available
  12. IV.12 Variance and standard deviation available
  13. IV.13 Joint, marginal, and conditional distributions available
  14. IV.14 Covariance and correlation available
  15. IV.15 Law of Large Numbers available
  16. IV.16 Central Limit Theorem available

Part V

Statistics

From observed data to estimates, intervals, and likelihood.

10 of 10 chapters written

  1. V.1 Data summaries: mean, median, mode available
  2. V.2 Spread: variance, standard deviation, robust interpretation available
  3. V.3 Population, sample, and sampling variability available
  4. V.4 Estimators and estimation available
  5. V.5 Confidence intervals through repeated sampling available
  6. V.6 Covariance matrices and multivariate spread available
  7. V.7 Regression fundamentals available
  8. V.8 Likelihood available
  9. V.9 Maximum Likelihood Estimation available
  10. V.10 Maximum A Posteriori estimation available

Part VI

Optimization

Learning as repeated parameter updates governed by an objective.

10 of 10 chapters written

  1. VI.1 Objective functions and optimization landscapes available
  2. VI.2 Local vs global optima and stationary points available
  3. VI.3 Convexity available
  4. VI.4 Gradient descent flagship chapter available
  5. VI.5 Learning rate and convergence behavior available
  6. VI.6 Momentum available
  7. VI.7 Stochastic and mini-batch gradient descent available
  8. VI.8 Adam intuition available
  9. VI.9 Constraints and projected/penalized intuition available
  10. VI.10 Numerical stopping and optimization diagnostics available

Part VII

Information Theory

Logarithms, entropy, and the loss behind token prediction.

8 of 8 chapters written

  1. VII.1 Logarithms and log probabilities in computation available
  2. VII.2 Self-information available
  3. VII.3 Entropy available
  4. VII.4 Cross entropy and negative log-likelihood available
  5. VII.5 KL divergence available
  6. VII.6 Logits and softmax available
  7. VII.7 Numerical stability: log-sum-exp and stable softmax available
  8. VII.8 From token logits to language-model loss available

Part VIII

Numerical Computing

Why equivalent expressions behave differently on real machines.

10 of 10 chapters written

  1. VIII.1 Floating-point representation available
  2. VIII.2 Rounding and representation error available
  3. VIII.3 Error propagation and conditioning available
  4. VIII.4 Catastrophic cancellation available
  5. VIII.5 Overflow and underflow available
  6. VIII.6 Stable algorithms available
  7. VIII.7 Numerical linear algebra realities available
  8. VIII.8 Sparse matrices and sparse structure available
  9. VIII.9 Vectorized computation available
  10. VIII.10 Reproducibility, random seeds, and nondeterminism available