Goal
Make matrix-calculus notation behave like a type system: the input and output spaces determine the derivative’s job, and its shape exposes many mistakes before any algebra is finished.
The central rule is:
Decide what linear map the derivative must represent, write its shape, and only then choose notation for it.
A Short Bridge From Computation Graphs
Before adding new notation, separate three operations that looked similar in the previous lesson.
Evaluate Local Derivatives At Local Values
If:
then:
At , the stored intermediate value is , so:
The square belongs to , not to the original input .
Differentiate The Operation That Is Actually Present
If:
the final operation is addition. Its local derivatives are both , so the two paths contribute:
Factors such as and would appear if the final operation were multiplication. A graph prevents that accidental change of program.
Build Jacobians From Component Functions
For:
differentiate each output with respect to each input:
Do not infer the derivative from the visual presence of two variables. Read the actual addition, subtraction, multiplication, or other operation in each component.
These are the same habits matrix calculus needs: local values, actual operations, and explicit shapes.
Notation / Symbol Table
| Symbol | Shape | Meaning |
|---|---|---|
| Column-vector input. | ||
| Column-vector output. | ||
| Output-by-input Jacobian. | ||
| Column gradient of scalar with respect to . | ||
| Small input displacement. | ||
| scalar | First-order change in a scalar function. | |
| Matrix input. | ||
| Matrix gradient paired with . | ||
| scalar | Sum of diagonal entries of square . | |
| scalar | Frobenius inner product . |
Derivatives Are Linear Maps Before They Are Arrays
Let:
Near , the derivative consumes an input displacement and produces an output displacement:
The shapes must be:
That requirement is more fundamental than the notation . Any notation convention must still encode this same local linear map.
For a scalar function:
the differential is:
Again the shapes explain the transpose:
Two Layout Families
Different books arrange the same partial derivatives differently. Let .
Numerator Layout
Numerator layout places output coordinates in rows and input coordinates in columns:
This is the Jacobian convention used by this course because it acts directly in:
For scalar , the same layout produces a row derivative.
Denominator Layout
Denominator layout transposes that array:
For scalar , this produces an column—the same shape commonly assigned to .
The Course Convention
This course uses a practical hybrid that is common in machine learning:
- Vector-output derivatives use the output-by-input Jacobian .
- Scalar-output derivatives use the column gradient .
- They are related by .
The names “numerator” and “denominator” are less important than declaring the shape. When reading another source, ask:
- Are vectors columns or rows?
- What shape does it assign to a scalar-by-vector derivative?
- Does its chain rule multiply on the left or the right?
- Is its displayed object a Jacobian, a gradient, or a transpose of one?
Shape Checking As A Compiler
Suppose:
The derivative with respect to must map an -vector displacement to an -vector displacement, so:
Now let . The chain rule in column-gradient form is:
The shape check is:
This is exactly the vector form of a backward pass.
Differentials: A Convention-Resistant Method
Differentials let us derive gradients by matching a standard shape instead of recalling a formula.
For a vector input, arrange the result as:
Whatever multiplies as a row is .
Linear Form
Let:
Then:
Matching the standard form gives:
Quadratic Form
Let:
Apply the product rule:
The first scalar term can be transposed without changing its value:
Therefore:
so:
If is symmetric, this reduces to:
The familiar formula requires symmetry. Shape checking alone cannot supply that assumption; it must be stated.
A Core ML Identity: Squared Error
Let:
First differentiate the residual:
Then differentiate the loss:
Substitute the local differential:
Match :
The transpose is not a memorized decoration. It is forced when the row is converted into a column gradient.
Gradients With Respect To Matrices
Suppose a scalar function depends on a matrix:
We define to have the same shape as and pair it with using the Frobenius inner product:
This is the matrix analogue of .
Trace Linear Form
Let:
where and have the same shape. Then:
Matching the standard matrix differential gives:
The trace turns an entrywise sum into compact linear-algebra notation:
Derivative Identity Ledger
These identities should be reconstructible from differentials and shapes:
| Function | Gradient or Jacobian | Required assumptions |
|---|---|---|
| is constant. | ||
| is constant. | ||
| is constant. | ||
| is constant and symmetric. | ||
| and are constant. | ||
| is constant and has the same shape as . |
Use this table as a checksum, not as a substitute for the derivations.
Reading A Paper Without Inheriting Its Convention Blindly
Suppose a paper writes:
That line alone does not reveal whether is a row or column. Recover its meaning from use:
- If the paper writes , then acts like a row derivative.
- If it writes , then acts like a column gradient.
- If an update is , then must have the same shape as .
- If a chain rule seems reversed, check whether every derivative array has been transposed by the source’s layout convention.
The invariant is the linear map and the scalar pairing, not the typography.
Connection To Programming
A lightweight shape ledger makes the convention explicit in code review:
type Shape = readonly [rows: number, columns: number];
type TypedValue = Readonly<{
name: string;
shape: Shape;
}>;
const canMultiply = (
left: TypedValue,
right: TypedValue,
): boolean => left.shape[1] === right.shape[0];
const jacobian: TypedValue = { name: 'J_F', shape: [3, 2] };
const displacement: TypedValue = { name: 'dx', shape: [2, 1] };
console.assert(canMultiply(jacobian, displacement));
Real tensor libraries carry richer shape information, but the mathematical habit is the same: reject incompatible compositions early.
Common Mistakes
Calling Every Derivative A Gradient
A gradient is naturally associated with a scalar output. A vector-valued function has a Jacobian or another explicitly declared derivative map.
Copying A Formula Without Its Convention
Two sources may display transposed arrays while representing the same derivative. Record vector orientation and expected shape before comparing formulas.
Losing A Transpose In A Backward Pass
Forward displacements use . Backward column gradients use .
Using The Symmetric Quadratic Identity Without Symmetry
only when . The general result is .
Treating Shape Checking As A Complete Proof
Several wrong formulas can have the right shape. Shape checking rejects many errors, but component definitions, local values, and algebra still matter.
Exercises
-
Let . State the shape of its numerator-layout Jacobian and denominator-layout derivative. Which one acts directly on a displacement from the left?
-
Let . Write the shapes of , , and . Explain the transpose relation between the first two.
-
For with , write the forward differential and the reverse column-gradient rule. Annotate every factor with its shape.
-
Derive using differentials rather than componentwise partial derivatives.
-
Derive for a general constant . Then state the extra assumption needed to simplify the result to .
-
Let with . Derive the gradient and verify that its final shape matches .
-
For , expand the trace into an entrywise sum and use it to verify .
-
A source defines a scalar-by-vector derivative as a row but another writes the gradient as a column. Show how both encode the same differential .
-
Diagnose the error in the claim for every square . Give a nonsymmetric example and compare the claimed and correct gradients at a point of your choice.
-
Write a TypeScript function that accepts two matrix shapes and either returns the product shape or a descriptive incompatibility result. Use it to type-check for and .
Summary
- A derivative is a local linear map; its array shape is a representation of that map.
- This course uses output-by-input Jacobians and column gradients for scalar outputs.
- Numerator and denominator layouts transpose the same table of partial derivatives.
- describes forward displacement propagation.
- describes reverse column-gradient propagation.
- Differentials expose gradients by matching .
- Matrix gradients use .
- Shape checking catches many transpose and composition errors, but it does not replace differentiating the actual operation.
Next Lesson
Lesson 39 develops Taylor series and local approximation. It will connect the gradient to the best first-order model and the Hessian to the second-order correction.
Completed Exercises
Handwritten work submitted after completing this lesson.









