10.3 Calculus 3 problem set: vectors, gradients, the chain rule, Hessians, multiple integrals, Lagrange
A model has many parameters, and training moves all of them at once along the gradient. The two sections before this one built the numerical machinery for that: Partial derivatives, gradients, and gradcheck compares analytic gradients with central differences coordinate by coordinate, and Jacobians, the multivariable chain rule, and numeric JVP/VJP computes Jacobians and the vector-Jacobian products that reverse-mode autodiff (Scalar reverse mode: the Value graph, and Tensor, broadcasting backward, and no_grad in AI Engineering) chains together. Later, gradient descent descends along gradients at a rate set by the Hessian’s condition number, Variance propagation and initialization sizes initial weights with Gaussian integrals in several variables, and the second information theory problem set reads the softmax as the solution of a constrained maximization. This set works the hand computations behind all of them.
Concepts from other sections (21)
This section uses these ideas. Each has a short definition and a link to the section that explains it in full. Tap a dotted term in the text to preview it.
- central differences: the numerical derivative , used as an oracle for analytic gradients. Read more: 6.3 The op library and gradcheck_all in AI Engineering
- Change of variables (multiple integrals): for a substitution , , where is the Jacobian determinant of ; it measures how stretches area, and it gives the in polar and the in spherical coordinates. Read more: Chapter 10: Calculus 3
- Chain rule: . Read more: 10.2 Jacobians, the multivariable chain rule, and numeric JVP/VJP
- Cross product: for vectors in 3D, is perpendicular to both, with magnitude , the area of the parallelogram they span; it gives normals to planes. Read more: Chapter 10: Calculus 3
- Partial derivative: the ordinary derivative of along one coordinate with every other coordinate frozen. Read more: 10.1 Partial derivatives, gradients, and gradcheck
- Log-sum-exp (LSE): , computed stably as . Read more: 15.2 Stable numerics: logsumexp, softmax, and compensated sums
- critical point: a point where , a candidate for an interior optimum. Read more: 7.5 Calculus 1 Problem Set
- Dot product: ; it measures how much two vectors point the same way, and it is zero exactly when they are perpendicular. Read more: Chapter 10: Calculus 3
- Backpropagation: reverse-mode automatic differentiation that computes all parameter gradients in one backward pass. Read more: Chapter 2: Deep Learning in AI Engineering
- Rate of change: how much the output changes per unit change in the input; for it is 4 per person. Read more: Chapter 2: Change and growth
- Eigenvector / eigenvalue: a non-zero and scalar with . Read more: 9.4 Eigenvalues, power iteration, and the spectral radius
- Determinant: a single number for a square matrix: the factor by which scales signed volume. It is zero exactly when squashes space flat and so cannot be inverted, and . Read more: Chapter 9: Linear Algebra
- Polar coordinates: describing a point by its distance from the origin and angle , with and ; a polar curve sweeps area . Read more: Chapter 8: Calculus 2
- Cross-entropy: , the average surprise when data from are predicted with . Read more: 17.1 Entropy, cross-entropy, KL, JS, and the k3 estimator
- Power rule: , the derivative of a power, and with linearity the derivative of any polynomial. Read more: Chapter 7: Calculus 1
- sigmoid: , mapping the real line into , with . Read more: 7.3 Activation Functions and Their Derivatives
- JVP (Jacobian-vector product): , the rate of change of the output along ; what forward mode computes. Read more: 10.2 Jacobians, the multivariable chain rule, and numeric JVP/VJP
- Standard normal: the distribution with density . Read more: 13.1 Random variables, expectation, variance, and normal draws by Box-Muller
- Entropy: , the average surprise of a distribution. Read more: 17.1 Entropy, cross-entropy, KL, JS, and the k3 estimator
- Gradcheck: a comparison of a hand-written gradient against central differences of . Read more: 3.3 Oracles, golden and differential tests, gradcheck as a test in Software Engineering
- Reverse mode: automatic differentiation that records the computation and walks it backward once from the output, pushing adjoints into inputs. Read more: 14.2 Scalar reverse mode: the Value graph
The set is also the book’s only treatment of three topics that have no code of their own: the Hessian and the second-derivative test, multiple integrals and change of variables, and Lagrange multipliers. It assumes one-variable derivatives, the chain rule, and integrals, as practiced in the Calculus 1 problem set, and the overview in the chapter opening. Work it after the two sections above.
The set has 58 problems: 56 with exact answers and 2 proofs (q34 and q58), whose model proofs are also in course/solutions/solve/S-M04/. Every problem is followed by a collapsed worked answer with the final result, the derivation, and the common wrong answers and why they are wrong. Try each problem before opening its answer.
Learning objectives
- Compute dot and cross products, angles, planes, and distances in .
- Compute partial derivatives and gradients, including the least-squares and log-sum-exp gradients, and directional derivatives.
- Apply the multivariable chain rule as a product of Jacobians and evaluate a backward pass as a chain of vector-Jacobian products.
- Classify critical points with the Hessian and relate its condition number to the speed of gradient descent.
- Evaluate multiple integrals with a change of variables, and solve constrained optimization problems with Lagrange multipliers.
The ideas you will use
Section titled “The ideas you will use”Before the problems, here is a compact review of the definitions and results they rely on. The notation is collected in one table first:
| Symbol | Meaning | Type / shape |
|---|---|---|
| , | dot product; cross product (in ) | scalar; vector |
| Euclidean length, | real | |
| partial derivative: vary , hold the others fixed | function | |
| gradient, the vector of partials | vector | |
| directional derivative along a unit vector , | real | |
| Jacobian of , | ||
| Hessian, | , symmetric | |
| condition number of a positive definite , | real | |
| double integral over a region | real | |
| a Lagrange multiplier | real |
Vectors and geometry
Section titled “Vectors and geometry”, so exactly when . The cross product is perpendicular to both, with length the area of the parallelogram they span. A plane is with normal (a cross product of two edge vectors), and the distance from a point to it is .
Partial derivatives and the gradient
Section titled “Partial derivatives and the gradient”A partial derivative differentiates in one variable with the rest held fixed, by the one-variable rules. Mixed second partials agree for smooth functions: . Two gradients recur in machine learning: , and the gradient of log-sum-exp, , is the softmax of .
The multivariable chain rule
Section titled “The multivariable chain rule”If , then : one term per path from to . In general the Jacobian of a composite is the product of Jacobians, . A loss is a scalar at the end of a long chain, and reverse mode evaluates the product from the left: start with and multiply by one Jacobian at a time, . Each step is a vector-Jacobian product (VJP), and backpropagation is nothing more.
Directional derivatives
Section titled “Directional derivatives”The rate of change of at along a unit vector is , by the chain rule. By Cauchy-Schwarz it is at most , reached at . So the gradient is the direction of steepest ascent, the direction of steepest descent, and directions perpendicular to follow a level curve.
The Hessian and the second-derivative test
Section titled “The Hessian and the second-derivative test”At a critical point (), the second-order Taylor expansion is . If every eigenvalue of is positive (positive definite), the point is a local minimum; all negative, a maximum; mixed signs, a saddle. For two variables: and is a minimum, is a saddle. For the quadratic , gradient descent’s error shrinks by about per step with , as Convexity, smoothness, gradient descent, and Armijo line search shows.
Multiple integrals and change of variables
Section titled “Multiple integrals and change of variables”A double integral over a rectangle is an iterated integral in either order; over other regions, the limits of the inner integral depend on the outer variable. Changing variables multiplies the area element by the absolute Jacobian determinant: . Polar coordinates have , so .
Lagrange multipliers
Section titled “Lagrange multipliers”To optimize subject to , look for points where and . At a constrained optimum, moving along the constraint surface cannot change to first order, so has no component along the surface. With several constraints, . Solve the system, then compare the candidates’ values.
Two examples worked by hand
Section titled “Two examples worked by hand”These two examples are siblings of q27 and q52, not problems of the set, and they show the level of detail the answers use.
A backward pass by hand. Let , , (the cross-entropy of one positive example). At , the forward pass gives , , . The backward pass takes one factor at a time: ; ; . So . The middle two factors combine to , the familiar “prediction minus label” of a logistic output.
A constrained minimum. Minimize subject to . Lagrange gives , so , , and gives , , value . Check by substitution: , at .
The problems
Section titled “The problems”The problems follow the same seven topics as the review above, in the same order. Answers are exact (for example , not ). Vectors are written as tuples and matrices row by row. The tag after each problem says what kind of answer is expected. For q33 either sign of the direction is correct.
Vectors and geometry
Section titled “Vectors and geometry”q1. . [number]
Answer
. Multiply entry by entry and add: . A common mistake is 32, which drops the sign of .
q2. . [vector]
Answer
. . Check: , so it is perpendicular to . Answering computes : the cross product is antisymmetric, so the order matters.
q3. Give the angle between and , in radians. [number]
Answer
. , so . A common mistake is to stop at , which is the cosine, not the angle.
q4. . [number]
Answer
. . Answering 49 forgets the square root: that is .
q5. Give the equation of the plane through , , and . [equation in x, y, z]
Answer
. Two edge vectors from are and ; their cross product is the normal . Then . Any nonzero multiple, such as , is the same plane. is the parallel plane through the origin, which contains none of the three points.
q6. Give the distance from the point to the plane . [number]
Answer
. . A common mistake is 6, which forgets to divide by the normal’s length: measures distance in units of .
q7. Give the area of the triangle with vertices , , . [number]
Answer
. With the edges of q5, is the area of the parallelogram; the triangle is half of it. Answering reports the parallelogram.
q8. Are and orthogonal? [bool]
Answer
True. , and a zero dot product means orthogonal.
Partial derivatives and the gradient
Section titled “Partial derivatives and the gradient”q9. . Give . [expr in x, y]
Answer
. Hold fixed. ; for the chain rule gives times the inner derivative . A common mistake is , which drops the inner factor .
q10. Give for the of q9. [expr in x, y]
Answer
. Hold fixed: , and . Dropping the inner gives the wrong .
q11. . Give . [vector]
Answer
. ; at that is . The order matters: swaps the components.
q12. . Give . [vector]
Answer
. Each partial differentiates one square: , and the other terms are constants in . Answering forgets the factor 2 from the power rule.
q13. . Give . [vector]
Answer
. A linear function has a constant gradient, its coefficient vector; the constant 7 has derivative 0 and is not a component. The gradient of a function of two variables has two entries, so is wrong.
q14. . [expr in x, y]
Answer
. , then (the other order gives the same, as it must for a smooth function). A common mistake is , which takes only the derivative.
q15. (log-sum-exp). Give . [vector]
Answer
. by the chain rule, and the same for . This is the softmax of , and it is why the backward pass of cross-entropy (Losses with a fused backward in AI Engineering) starts from the softmax. Two common mistakes: drops the outer , and drops the inner derivative.
q16. with and . Give . [vector]
Answer
. ; at , and . This is the direction gradient descent follows. A common mistake is , which forgets : the chain rule through contributes the transpose. has the sign of flipped.
q17. . Give at . [number]
Answer
. , and at that is . Answering 1 evaluates and forgets the factor .
q18. The squared error of a one-weight model is . Give . [expr in w, x, y]
Answer
. The outer square gives , and the inner derivative multiplies it. Dropping gives , the gradient with respect to the prediction, not the weight.
The multivariable chain rule
Section titled “The multivariable chain rule”q19. with , . Give . [number]
Answer
. One term per path: . Directly, is constant.
q20. with , . Give . [expr in t]
Answer
. ; directly, . A common mistake is , which multiplies the two inner derivatives instead of summing one term per path.
q21. with , . Give . [expr in x, y]
Answer
. . Check: .
q22. Give for the of q21. [expr in x, y]
Answer
. . The sign comes from ; dropping it gives .
q23. with the sigmoid . Give at , . [number]
Answer
. With : at , and . Three factors: , , . Product: . Common mistakes: drops the factor , and drops the sigmoid’s slope .
q24. with , . Give . [expr in r]
Answer
. ; directly, . is not a derivative of anything here.
q25. Give the Jacobian matrix of at . [matrix]
Answer
. Row is the gradient of output : and at . The transpose puts inputs in rows, against the convention .
q26. Give the determinant of the Jacobian of . [expr in r]
Answer
. , so . This is the extra factor in (q45, q46). Answering 1 treats polar coordinates as if they preserved area.
q27. , , . Give at (backpropagate one factor at a time). [number]
Answer
. Forward at : , , . Backward, one factor at a time: ; , so ; , so . Common mistakes: is , which stops before the last factor , and loses the sign of .
q28. with . Give the vector-Jacobian product for , as a column. [vector]
Answer
. , and : the column sums of weighted by . This is the product that vjp_numeric from Jacobians, the multivariable chain rule, and numeric JVP/VJP and every reverse-mode backward compute. A common mistake is , the row sums: that is a JVP, and for a non-symmetric it is a different vector.
Directional derivatives
Section titled “Directional derivatives”q29. . Give the directional derivative at in the direction . [number]
Answer
. , and . A common mistake is 4, which dots the gradient with , a vector of length that is not the given direction.
q30. . Give the largest directional derivative at over all unit directions. [number]
Answer
. The largest directional derivative is (q34). , with length . Answering 5 adds the components instead of taking the norm.
q31. . Give the unit direction of steepest descent at . [vector]
Answer
. at , with length . Steepest descent is . Common mistakes: is steepest ascent, and is the right direction but not a unit vector.
q32. . Give the directional derivative at in the direction . [number]
Answer
. at , and .
q33. . Give a unit direction at along which the directional derivative is 0 (either sign). [vector]
Answer
(or its negative). ; a direction with zero derivative is perpendicular to it, and is. Along it you follow the level curve. A common mistake is , which points along the gradient, where the derivative is largest.
q34. Prove that at a point where , the unit direction that maximizes the directional derivative is , and that the maximum is . [proof]
Answer
Claim. Let be differentiable at with . Over unit vectors , the directional derivative is largest at , and its maximum value is .
Proof (direct). By the chain rule applied to , . For every unit vector , the Cauchy-Schwarz inequality gives . Since , is defined and , and , so the bound is attained. Hence the maximizing direction is and the maximum is .
A complete proof derives from the chain rule, bounds it with Cauchy-Schwarz, shows is a unit vector that attains the bound (this is where is used), and states both the direction and the value. Model proof also in q34.md.
The Hessian and the second-derivative test
Section titled “The Hessian and the second-derivative test”q35. Give the Hessian of . [matrix]
Answer
. , , and . A common mistake is off the diagonal: in the cross term is split as , so each off-diagonal entry is the full 3, not half of it. reads the coefficients off without differentiating.
q36. Give the Hessian of at . [matrix]
Answer
. , , ; at the diagonal is 6. Answering 3 on the diagonal takes only the first derivative’s coefficient.
q37. Classify the critical point of : minimum, maximum, or saddle. [choice]
Answer
Saddle. has one positive and one negative eigenvalue: rises along and falls along . .
q38. Classify the critical point of : minimum, maximum, or saddle. [choice]
Answer
Minimum. , with and (eigenvalues 1 and 3). A cross term alone does not make a saddle; only does.
q39. Give the critical point of . [vector]
Answer
. gives , . Completing the square, , confirms it. has both signs flipped.
q40. Classify the critical point of : minimum, maximum, or saddle. [choice]
Answer
Minimum. vanishes at , and there, positive definite. (The other critical point, , is a saddle.)
q41. Is the Hessian of q35 positive definite? [bool]
Answer
False. , so the eigenvalues have opposite signs: the matrix is indefinite and its critical point is a saddle, even though both diagonal entries are positive.
q42. with . Give the condition number of its Hessian. [number]
Answer
. The Hessian of is itself, with eigenvalues 1 and 100. Gradient descent shrinks the error by about per step, so means slow convergence along the flat direction (gradient descent). Common mistakes: inverts the ratio, and 10 is the ratio of the axes’ lengths (the square root), not of the eigenvalues.
Multiple integrals and change of variables
Section titled “Multiple integrals and change of variables”q43. . [number]
Answer
. Inner: . Outer: . Answering 2 keeps the inner result and forgets the outer integral over .
q44. Give the area of the triangle as a double integral. [number]
Answer
. . The inner limit depends on ; integrating over the whole unit square gives 1.
q45. . [number]
Answer
. In polar coordinates, , the area of the unit disk. A common mistake is , which integrates without the Jacobian .
q46. . [number]
Answer
. ; substitute , : the inner integral is , so the total is . It is also , which is how is proved. is the one-variable value.
q47. . [number]
Answer
. Inner: . Outer: . Answering uses the wrong inner limit.
q48. Give the volume under and above the unit disk . [number]
Answer
. . Answering forgets the term (that is the volume of the cylinder of height 1).
q49. , the total mass of a 2-D standard normal. [number]
Answer
. , since by . A density integrates to 1, which is what makes the right constant (Random variables, expectation, variance, and normal draws by Box-Muller). forgets the normalizer.
q50. With , , give the area of the region , . [number]
Answer
. In the region is the square , of area 4. The map has , so and the area in is . (The region is a square with diagonals of length 2.) A common mistake is 4, which forgets the Jacobian factor; 8 multiplies by it instead of dividing.
Lagrange multipliers
Section titled “Lagrange multipliers”q51. Give the maximum of subject to . [number]
Answer
. gives , and gives , so the maximum is (the minimum is at the opposite point). 1 is the value at , not an optimum; 2 ignores the constraint.
q52. Give the minimum of subject to . [number]
Answer
. gives , and . A common mistake is , which is the distance from the origin to the line, not its square.
q53. Give the maximum of subject to . [number]
Answer
. gives , and . Answering 5 reports the optimizer instead of the optimum value.
q54. Maximize the entropy subject to . Give the optimal . [number]
Answer
. , so every has the same value, and the constraint makes it . With only the normalization constraint, maximum entropy is uniform; adding an energy constraint (q58) turns it into a softmax (the second information theory problem set).
q55. Give the maximum of subject to with . [number]
Answer
. forces (all positive), so each is 1 and ; AM-GM confirms . A common mistake is 27, which is .
q56. Give the minimum of subject to with . [number]
Answer
. gives , , and gives : , , value . A common mistake is 13 from , , which pairs the multiplier equations the wrong way round.
q57. Give the point of the plane closest to the origin. [vector]
Answer
. Minimize : , so the point is , on the normal through the origin. The constraint gives , . The distance is 3. is the unit normal, a direction, not the point.
q58. With Lagrange multipliers, show that the distribution over states with energies that maximizes the entropy subject to and has the form (a softmax of ). [proof]
Answer
Claim. Among distributions with , , and , a stationary point of the entropy has for a constant .
Proof (Lagrange multipliers). Introduce multipliers for the normalization and for the energy constraint, and form At a constrained stationary point, for each : , so . The factor is the same for every . The normalization gives , so . Therefore the softmax of , with the value for which . (Since is strictly concave and the constraints are linear, this stationary point is the maximum.)
A complete proof names both multipliers in the Lagrangian, sets each partial in to zero, uses the normalization to fix the common constant, and concludes the softmax form with fixed by the energy constraint. Model proof also in q58.md.
What can go wrong
Section titled “What can go wrong”The wrong answers discussed under each problem fall into a handful of recurring patterns. Each one has a symptom you would see in code and a habit that prevents it:
| Pitfall | Symptom | How to avoid it |
|---|---|---|
| Dropping an inner derivative in a partial | given as ; gradcheck fails on every product inside a nonlinearity | apply the chain rule to every inner function and write its derivative as a separate factor (q9, q10, q18) |
| Forgetting the in a least-squares gradient | descent along the wrong direction for any non-identity | differentiate through with the chain rule, which brings in (q16) |
| Multiplying the derivatives of the parts instead of summing over paths | for given as | write one term per path from to and add them (q20) |
| Skipping a factor in a chain of local derivatives | a backward pass off by the sigmoid’s slope or a weight | backpropagate one named local derivative at a time and multiply them all (q23, q27) |
| Computing when the backward pass needs | the gradient of a non-symmetric layer comes out transposed | compute the row vector , a weighted sum of rows of (q28) |
| Using an unnormalized direction | a directional derivative scaled by the direction’s length | use the given unit vector, or divide by the norm first (q29, q31) |
| Halving the mixed term of a Hessian | a saddle misread as a minimum | take directly, which is the full coefficient of (q35) |
| Forgetting the Jacobian factor in a change of variables | polar integrals off by the missing | write before setting limits (q45, q50) |
| Reporting the optimizer instead of the optimum | the argmax given as the max | substitute the optimizer back into and report that value (q52, q53) |
Where this leads
Section titled “Where this leads”This set rests on the one-variable derivatives, chain rule, and integrals of the Calculus 1 problem set. Its results are used throughout the rest of the book. gradcheck in Partial derivatives, gradients, and gradcheck compares analytic partials like those of q9 to q18 with central differences. jacobian, vjp_numeric, and jvp_numeric in Jacobians, the multivariable chain rule, and numeric JVP/VJP compute the products of q25 and q28. Reverse-mode autodiff in Scalar reverse mode: the Value graph is the chain of VJPs of q27. Convexity, smoothness, gradient descent, and Armijo line search uses the condition number of q42. Variance propagation and initialization rests on the Gaussian integrals in two variables of q46 and q49. And the second information theory problem set treats softmax as maximum entropy under an energy constraint, the result of q58.
Further reading
Section titled “Further reading”- OpenStax, Calculus Volume 3 (free), chapters 2, 4, and 5.
- Boyd and Vandenberghe, Convex Optimization, section 5.1, for Lagrange duality.
Key terms
Section titled “Key terms”- Gradient: the vector of partial derivatives of a scalar function; it points in the direction of steepest ascent.
- Directional derivative: , the rate of change of along a unit vector .
- Jacobian: the matrix of partial derivatives of a vector-valued function, .
- Vector-Jacobian product (VJP): , one step of reverse-mode differentiation.
- Hessian: the symmetric matrix of second partial derivatives, whose eigenvalues classify a critical point.
- Condition number: of a positive definite matrix, which sets how slowly gradient descent converges.
- Lagrange multiplier: the scalar in at a constrained optimum.
Summary
Section titled “Summary”- The gradient collects the partial derivatives; it points uphill fastest, and its length is the steepest slope (q11, q30, q34).
- The multivariable chain rule multiplies Jacobians, and reverse mode multiplies them from the loss backward, one vector-Jacobian product at a time (q23, q27, q28).
- At a critical point the Hessian’s eigenvalues decide minimum, maximum, or saddle, and their ratio is the condition number that slows gradient descent (q37, q42).
- A change of variables multiplies the area element by : the in polar coordinates is why (q26, q46, q50).
- At a constrained optimum the gradient is parallel to the constraint’s gradient; maximum entropy under an energy constraint is a softmax (q51 to q58).