TExcelTAD
Home › Linear Algebra & Matrix Theory › The Algebra of Linear Transformations

The Algebra of Linear Transformations

Linear maps can be added, scaled and composed, and the results are again linear. With these operations, linear maps behave like matrices: you can form polynomials in a map such as D2−3D+2D^2 - 3D + 2, factor them, and invert them. Order matters, though, because composition is not commutative.

Sum, scalar multiple and composition

Let S,T:V→WS, T: V \to W be linear and cc a scalar. Define

(S+T)(v)=S(v)+T(v)(c⋅T)(v)=c⋅T(v)(S + T)(\mathbf{v}) = S(\mathbf{v}) + T(\mathbf{v}) \qquad (c \cdot T)(\mathbf{v}) = c \cdot T(\mathbf{v})

Both are linear. With these operations the set of all linear maps V→WV \to W is itself a vector space, written L(V,W)L(V, W). Its zero vector is the zero map, and if dim⁡V=n\dim V = n and dim⁡W=m\dim W = m, then dim⁡L(V,W)=m⋅n\dim L(V, W) = m \cdot n, the same as for m×nm \times n matrices.

If T:U→VT: U \to V and S:V→WS: V \to W are linear, the composition S∘T:U→WS \circ T: U \to W, (S∘T)(u)=S(T(u))(S \circ T)(\mathbf{u}) = S(T(\mathbf{u})), is linear as well:

(S∘T)(au+bu′)=S(aT(u)+bT(u′))=aS(T(u))+bS(T(u′))(S \circ T)(a\mathbf{u} + b\mathbf{u}') = S(aT(\mathbf{u}) + bT(\mathbf{u}')) = aS(T(\mathbf{u})) + bS(T(\mathbf{u}'))

Composition matches matrix multiplication: if SS and TT have matrices AA and BB, then S∘TS \circ T has matrix ABAB (The Matrix of a Linear Transformation). So all the rules of Matrix Multiplication carry over: composition is associative, distributes over addition, and is not commutative.

Operators on polynomials

Two maps on the space PP of all polynomials will be our running example:

D(p)=p′(differentiate)X(p)=x⋅p(multiply by x)\begin{aligned} D(p) &= p' && \text{(differentiate)} \\ X(p) &= x \cdot p && \text{(multiply by } x\text{)} \end{aligned}

Composing them in the two orders gives different results. By the product rule, (D∘X)(p)=(xp)′=p+xp′(D \circ X)(p) = (xp)' = p + xp', while (X∘D)(p)=xp′(X \circ D)(p) = xp'. Their difference is

D∘X−X∘D=I(the identity map)D \circ X - X \circ D = I \qquad \text{(the identity map)}

This tiny identity is famous: in quantum mechanics, the position and momentum operators satisfy the same relation (up to a constant), and it is the origin of the uncertainty principle. It also shows that D∘X≠X∘DD \circ X \ne X \circ D, so operators must be composed in the right order.

python · try it yourself
from sympy import symbols, diff, expand, Function

x = symbols("x")
D = lambda p: diff(p, x)
X = lambda p: x * p
compose = lambda S, T: (lambda p: S(T(p)))

p = 4 - x + 7 * x**3
print("(D o X)(p) =", expand(compose(D, X)(p)))
print("(X o D)(p) =", expand(compose(X, D)(p)))
print("difference =", expand(compose(D, X)(p) - compose(X, D)(p)), " (= p)")
f = Function("f")(x)
print("for any f: ", expand(compose(D, X)(f) - compose(X, D)(f)))
(D o X)(p) = 28*x**3 - 2*x + 4
(X o D)(p) = 21*x**3 - x
difference = 7*x**3 - x + 4  (= p)
for any f:  f(x)

Polynomials in an operator

Since we can add, scale and compose, any polynomial in TT makes sense: T2=T∘TT^2 = T \circ T, and for q(t)=t2−3t+2q(t) = t^2 - 3t + 2 we get q(T)=T2−3T+2Iq(T) = T^2 - 3T + 2I. Products of polynomials in the same operator commute, so they factor like ordinary polynomials:

D2−3D+2I=(D−I)∘(D−2I)=(D−2I)∘(D−I)D^2 - 3D + 2I = (D - I) \circ (D - 2I) = (D - 2I) \circ (D - I)

This factorization solves differential equations. The kernel of D−aID - aI consists of the functions with y′=ayy' = ay, which is span⁡{eax}\operatorname{span}\{e^{ax}\}. So y′′−3y′+2y=0y'' - 3y' + 2y = 0 is solved by exe^x (killed by D−ID - I) and e2xe^{2x} (killed by D−2ID - 2I), and by every combination of them, exactly what the characteristic equation r2−3r+2=0r^2 - 3r + 2 = 0 gives in Second-Order Linear Equations.

Inverses and one-sided inverses

T:V→WT: V \to W is invertible (an isomorphism) if there is a linear T−1:W→VT^{-1}: W \to V with T−1∘T=IVT^{-1} \circ T = I_V and T∘T−1=IWT \circ T^{-1} = I_W. The inverse of a linear bijection is automatically linear. Isomorphic spaces are "the same space with different names": PnP_n and Rn+1\mathbb{R}^{n+1} are isomorphic via p↦its coefficient vectorp \mapsto \text{its coefficient vector}, which is why coordinates work.

The shift S(p)(x)=p(x+1)S(p)(x) = p(x + 1) has inverse S−1(p)(x)=p(x−1)S^{-1}(p)(x) = p(x - 1). The derivative DD on polynomials has no inverse (it kills constants), but the integral J(p)=∫0xp(t) dtJ(p) = \int_0^x p(t)\,dt is a right inverse: D∘J=ID \circ J = I, by the fundamental theorem of calculus. In the other order, J∘D(p)=p−p(0)J \circ D(p) = p - p(0), which is not the identity.

python · try it yourself
from sympy import symbols, diff, integrate, expand

x, t = symbols("x t")
D = lambda p: diff(p, x)
J = lambda p: integrate(p.subs(x, t), (t, 0, x))
S = lambda p: expand(p.subs(x, x + 1))
S_inv = lambda p: expand(p.subs(x, x - 1))

p = 5 + 2 * x - 3 * x**2
print("D(J(p))   =", expand(D(J(p))))
print("J(D(p))   =", expand(J(D(p))), "  (lost the constant 5)")
print("S_inv(S(p)) =", S_inv(S(p)))
D(J(p))   = -3*x**2 + 2*x + 5
J(D(p))   = -3*x**2 + 2*x   (lost the constant 5)
S_inv(S(p)) = -3*x**2 + 2*x + 5

In a finite-dimensional space this cannot happen for a map T:V→VT: V \to V. There, one-to-one, onto and invertible are all equivalent (by rank–nullity), so a one-sided inverse is automatically two-sided. The asymmetry of DD and JJ needs the infinite-dimensional space PP (or the different spaces PnP_n and Pn+1P_{n+1}).

In software

  • Pipelines: a graphics transform pipeline or a stack of linear layers is a composition; you can multiply the matrices once and apply the product, but the order must match the order of application (3D Graphics: Transform Pipelines).
  • Operator libraries: SciPy's LinearOperator and PyTorch's linear modules let you add, scale and compose maps without ever building their matrices (Sparse Linear Algebra).
  • Differential operators in code: finite-difference stencils are matrices that approximate DD, and numerical solvers build D2−3D+2ID^2 - 3D + 2I as a sparse matrix.
  • Undo: an invertible edit (a shift, a rotation, a scale) can be undone exactly by its inverse; a projection or a derivative cannot.

Exercises

Exercise 1: Apply an operator polynomial

Let L=D2−3D+2IL = D^2 - 3D + 2I. Compute L(ex)L(e^x), L(e3x)L(e^{3x}) and L(x)L(x).

Answer

L(ex)=0L(e^x) = 0, L(e3x)=2e3xL(e^{3x}) = 2e^{3x}, L(x)=2x−3L(x) = 2x - 3.

Solution
L(eax)=(a2−3a+2)⋅eaxa=1: 1−3+2=0;a=3: 9−9+2=2L(x)=0−3⋅1+2x=2x−3\begin{aligned} L(e^{ax}) &= (a^2 - 3a + 2) \cdot e^{ax} \\ &a = 1: \ 1 - 3 + 2 = 0; \qquad a = 3: \ 9 - 9 + 2 = 2 \\ L(x) &= 0 - 3 \cdot 1 + 2x = 2x - 3 \end{aligned}

Exercise 2: Do shift and derivative commute?

With S(p)(x)=p(x+1)S(p)(x) = p(x + 1), compute (S∘D)(x3)(S \circ D)(x^3) and (D∘S)(x3)(D \circ S)(x^3). Do SS and DD commute in general?

Answer

Both give 3(x+1)2=3x2+6x+33(x + 1)^2 = 3x^2 + 6x + 3. Yes: S∘D=D∘SS \circ D = D \circ S on all differentiable functions.

Solution
(S∘D)(x3)=S(3x2)=3(x+1)2(D∘S)(x3)=D((x+1)3)=3(x+1)2(chain rule)in general: (D∘S)(f)=ddxf(x+1)=f′(x+1)=(S∘D)(f)\begin{aligned} (S \circ D)(x^3) &= S(3x^2) = 3(x + 1)^2 \\ (D \circ S)(x^3) &= D((x + 1)^3) = 3(x + 1)^2 && \text{(chain rule)} \\ \text{in general: } (D \circ S)(f) &= \frac{d}{dx} f(x + 1) = f'(x + 1) = (S \circ D)(f) \end{aligned}

Unlike DD and XX, the shift and the derivative commute. That is why convolution filters (which are combinations of shifts) can be analysed with derivatives and frequencies.

Exercise 3: Invert I+DI + D on P2P_2

Let T(p)=p+p′T(p) = p + p' on P2P_2. Use D3=0D^3 = 0 on P2P_2 to find T−1T^{-1}, and compute T−1(x2)T^{-1}(x^2).

Answer

T−1=I−D+D2T^{-1} = I - D + D^2; T−1(x2)=x2−2x+2T^{-1}(x^2) = x^2 - 2x + 2.

Solution

Like the geometric series 11+t=1−t+t2−⋯\frac{1}{1 + t} = 1 - t + t^2 - \cdots, which stops because D3=0D^3 = 0:

(I+D)(I−D+D2)=I−D+D2+D−D2+D3=I+D3=IT−1(x2)=x2−2x+2check: T(x2−2x+2)=(x2−2x+2)+(2x−2)=x2✓\begin{aligned} (I + D)(I - D + D^2) &= I - D + D^2 + D - D^2 + D^3 = I + D^3 = I \\ T^{-1}(x^2) &= x^2 - 2x + 2 \\ \text{check: } T(x^2 - 2x + 2) &= (x^2 - 2x + 2) + (2x - 2) = x^2 \quad \checkmark \end{aligned}

Exercise 4: Check with matrices

In the basis 1,x,x21, x, x^2 of P2P_2, DD has matrix [010002000]\begin{bmatrix} 0 & 1 & 0 \\ 0 & 0 & 2 \\ 0 & 0 & 0 \end{bmatrix}. Verify in SymPy that (I+D)−1=I−D+D2(I + D)^{-1} = I - D + D^2 and apply it to x2x^2.

Answer

Both sides give [1−1201−2001]\begin{bmatrix} 1 & -1 & 2 \\ 0 & 1 & -2 \\ 0 & 0 & 1 \end{bmatrix}, and the image of x2x^2, coordinates (0,0,1)(0, 0, 1), is (2,−2,1)(2, -2, 1): the polynomial 2−2x+x22 - 2x + x^2.

Solution
python · try it yourself
from sympy import Matrix, eye

D = Matrix([[0, 1, 0], [0, 0, 2], [0, 0, 0]])
inv = (eye(3) + D).inv()
print("(I + D)^-1   =", inv.tolist())
print("I - D + D^2  =", (eye(3) - D + D**2).tolist())
print("applied to x^2:", list(inv * Matrix([0, 0, 1])))
(I + D)^-1   = [[1, -1, 2], [0, 1, -2], [0, 0, 1]]
I - D + D^2  = [[1, -1, 2], [0, 1, -2], [0, 0, 1]]
applied to x^2: [2, -2, 1]

Test yourself

If TT has matrix BB and SS has matrix AA, what is the matrix of S∘TS \circ T (first TT, then SS)?

  1. BABA
  2. ABAB
  3. A+BA + B
  4. BTATB^TA^T

With D=ddxD = \frac{d}{dx} and X=multiplication by xX = \text{multiplication by } x, what is D∘X−X∘DD \circ X - X \circ D?

  1. 0
  2. The identity II
  3. DD
  4. XX

On the space of all polynomials, D∘J=ID \circ J = I where J(p)=∫0xpJ(p) = \int_0^x p. What is J∘DJ \circ D?

  1. Also II
  2. The map p↦p−p(0)p \mapsto p - p(0)
  3. The zero map
  4. D2D^2