Skip to content

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 (f(x+ϵ)−f(x−ϵ))/2ϵ(f(x + \epsilon) - f(x - \epsilon))/2\epsilon, 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 (x,y)=T(u,v)(x, y) = T(u, v), dA=∣J∣ du dvdA = |J|\,du\,dv, where JJ is the Jacobian determinant of TT; it measures how TT stretches area, and it gives the rr in polar and the ρ2sin⁡ϕ\rho^2 \sin\phi in spherical coordinates. Read more: Chapter 10: Calculus 3
  • Chain rule: Jg∘f(x)=Jg(f(x)) Jf(x)J_{g \circ f}(x) = J_g(f(x))\,J_f(x). Read more: 10.2 Jacobians, the multivariable chain rule, and numeric JVP/VJP
  • Cross product: for vectors in 3D, u×vu \times v is perpendicular to both, with magnitude ∥u∥∥v∥sin⁡θ\lVert u \rVert \lVert v \rVert \sin\theta, the area of the parallelogram they span; it gives normals to planes. Read more: Chapter 10: Calculus 3
  • Partial derivative: the ordinary derivative of ff along one coordinate with every other coordinate frozen. Read more: 10.1 Partial derivatives, gradients, and gradcheck
  • Log-sum-exp (LSE): log⁡∑iexi\log\sum_i e^{x_i}, computed stably as m+log⁡∑iexi−mm + \log\sum_i e^{x_i - m}. Read more: 15.2 Stable numerics: logsumexp, softmax, and compensated sums
  • critical point: a point where f′(x)=0f'(x) = 0, a candidate for an interior optimum. Read more: 7.5 Calculus 1 Problem Set
  • Dot product: u⋅v=∑iuivi=∥u∥∥v∥cos⁡θu \cdot v = \sum_i u_i v_i = \lVert u \rVert \lVert v \rVert \cos\theta; 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 C(n)=60+4nC(n) = 60 + 4n it is 4 per person. Read more: Chapter 2: Change and growth
  • Eigenvector / eigenvalue: a non-zero vv and scalar λ\lambda with Av=λvAv = \lambda v. Read more: 9.4 Eigenvalues, power iteration, and the spectral radius
  • Determinant: a single number det⁡A\det A for a square matrix: the factor by which AA scales signed volume. It is zero exactly when AA squashes space flat and so cannot be inverted, and det⁡(AB)=det⁡Adet⁡B\det(AB) = \det A \det B. Read more: Chapter 9: Linear Algebra
  • Polar coordinates: describing a point by its distance rr from the origin and angle θ\theta, with x=rcos⁡θx = r\cos\theta and y=rsin⁡θy = r\sin\theta; a polar curve r(θ)r(\theta) sweeps area 12∫αβr(θ)2 dθ\frac12\int_\alpha^\beta r(\theta)^2\,d\theta. Read more: Chapter 8: Calculus 2
  • Cross-entropy: H(p,q)=−∑ipilog⁡qiH(p, q) = -\sum_i p_i \log q_i, the average surprise when data from pp are predicted with qq. Read more: 17.1 Entropy, cross-entropy, KL, JS, and the k3 estimator
  • Power rule: ddxxn=nxn−1\frac{d}{dx} x^n = n x^{n-1}, the derivative of a power, and with linearity the derivative of any polynomial. Read more: Chapter 7: Calculus 1
  • sigmoid: σ(x)=11+e−x\sigma(x) = \frac{1}{1 + e^{-x}}, mapping the real line into (0,1)(0, 1), with σ′=σ(x)σ(−x)\sigma' = \sigma(x)\sigma(-x). Read more: 7.3 Activation Functions and Their Derivatives
  • JVP (Jacobian-vector product): JvJv, the rate of change of the output along vv; what forward mode computes. Read more: 10.2 Jacobians, the multivariable chain rule, and numeric JVP/VJP
  • Standard normal: the distribution N(0,1)\mathcal{N}(0, 1) with density 12πe−z2/2\frac{1}{\sqrt{2\pi}} e^{-z^2/2}. Read more: 13.1 Random variables, expectation, variance, and normal draws by Box-Muller
  • Entropy: H(p)=−∑ipilog⁡piH(p) = -\sum_i p_i \log p_i, 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 ∑f(x)⊙g\sum f(x) \odot g. 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 R3\mathbb{R}^3.
  • 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.

Before the problems, here is a compact review of the definitions and results they rely on. The notation is collected in one table first:

SymbolMeaningType / shape
u⋅vu \cdot v, u×vu \times vdot product; cross product (in R3\mathbb{R}^3)scalar; vector
∥v∥\lVert v \rVertEuclidean length, v⋅v\sqrt{v \cdot v}real
∂f/∂xi\partial f / \partial x_ipartial derivative: vary xix_i, hold the others fixedfunction
∇f\nabla fgradient, the vector of partialsvector
DufD_u fdirectional derivative along a unit vector uu, ∇f⋅u\nabla f \cdot ureal
JgJ_gJacobian of g:Rn→Rmg: \mathbb{R}^n \to \mathbb{R}^m, (Jg)ij=∂gi/∂xj(J_g)_{ij} = \partial g_i / \partial x_jm×nm \times n
HfH_fHessian, (Hf)ij=∂2f/∂xi∂xj(H_f)_{ij} = \partial^2 f / \partial x_i \partial x_jn×nn \times n, symmetric
κ\kappacondition number of a positive definite HH, λmax⁡/λmin⁡\lambda_{\max}/\lambda_{\min}real
∬Df dA\iint_D f\,dAdouble integral over a region DDreal
λ\lambdaa Lagrange multiplierreal

u⋅v=∑iuivi=∥u∥∥v∥cos⁡θu \cdot v = \sum_i u_i v_i = \lVert u \rVert \lVert v \rVert \cos\theta, so u⊥vu \perp v exactly when u⋅v=0u \cdot v = 0. The cross product u×vu \times v is perpendicular to both, with length the area of the parallelogram they span. A plane is n⋅x=dn \cdot x = d with normal nn (a cross product of two edge vectors), and the distance from a point pp to it is ∣n⋅p−d∣/∥n∥|n \cdot p - d| / \lVert n \rVert.

A partial derivative differentiates in one variable with the rest held fixed, by the one-variable rules. Mixed second partials agree for smooth functions: ∂2f/∂x ∂y=∂2f/∂y ∂x\partial^2 f/\partial x\,\partial y = \partial^2 f/\partial y\,\partial x. Two gradients recur in machine learning: ∇x12∥Ax−b∥2=A⊤(Ax−b)\nabla_x \frac12 \lVert Ax - b \rVert^2 = A^\top(Ax - b), and the gradient of log-sum-exp, ∇ln⁡∑jexj\nabla \ln \sum_j e^{x_j}, is the softmax of xx.

If z=f(x(t),y(t))z = f(x(t), y(t)), then dzdt=∂f∂xdxdt+∂f∂ydydt\frac{dz}{dt} = \frac{\partial f}{\partial x}\frac{dx}{dt} + \frac{\partial f}{\partial y}\frac{dy}{dt}: one term per path from tt to zz. In general the Jacobian of a composite is the product of Jacobians, Jf∘g=Jf JgJ_{f \circ g} = J_f\, J_g. A loss is a scalar at the end of a long chain, and reverse mode evaluates the product from the left: start with u⊤=∂L/∂(output)u^\top = \partial L / \partial(\text{output}) and multiply by one Jacobian at a time, u⊤←u⊤Ju^\top \leftarrow u^\top J. Each step is a vector-Jacobian product (VJP), and backpropagation is nothing more.

The rate of change of ff at xx along a unit vector uu is Duf=ddsf(x+su)∣s=0=∇f⋅uD_u f = \frac{d}{ds} f(x + s u)\big|_{s=0} = \nabla f \cdot u, by the chain rule. By Cauchy-Schwarz it is at most ∥∇f∥\lVert \nabla f \rVert, reached at u=∇f/∥∇f∥u = \nabla f / \lVert \nabla f \rVert. So the gradient is the direction of steepest ascent, −∇f-\nabla f the direction of steepest descent, and directions perpendicular to ∇f\nabla f follow a level curve.

The Hessian and the second-derivative test

Section titled “The Hessian and the second-derivative test”

At a critical point (∇f=0\nabla f = 0), the second-order Taylor expansion is f(x+h)≈f(x)+12h⊤Hhf(x + h) \approx f(x) + \frac12 h^\top H h. If every eigenvalue of HH is positive (positive definite), the point is a local minimum; all negative, a maximum; mixed signs, a saddle. For two variables: det⁡H>0\det H > 0 and fxx>0f_{xx} > 0 is a minimum, det⁡H<0\det H < 0 is a saddle. For the quadratic 12x⊤Hx\frac12 x^\top H x, gradient descent’s error shrinks by about 1−1/κ1 - 1/\kappa per step with κ=λmax⁡/λmin⁡\kappa = \lambda_{\max}/\lambda_{\min}, 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 (u,v)↦(x,y)(u, v) \mapsto (x, y) multiplies the area element by the absolute Jacobian determinant: dx dy=∣det⁡J∣ du dvdx\,dy = |\det J|\,du\,dv. Polar coordinates have ∣det⁡J∣=r|\det J| = r, so dA=r dr dθdA = r\,dr\,d\theta.

To optimize ff subject to g=0g = 0, look for points where ∇f=λ∇g\nabla f = \lambda \nabla g and g=0g = 0. At a constrained optimum, moving along the constraint surface cannot change ff to first order, so ∇f\nabla f has no component along the surface. With several constraints, ∇f=∑kλk∇gk\nabla f = \sum_k \lambda_k \nabla g_k. Solve the system, then compare the candidates’ values.

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 h=2x−1h = 2x - 1, y=σ(h)y = \sigma(h), L=−ln⁡yL = -\ln y (the cross-entropy of one positive example). At x=1/2x = 1/2, the forward pass gives h=0h = 0, y=σ(0)=1/2y = \sigma(0) = 1/2, L=ln⁡2L = \ln 2. The backward pass takes one factor at a time: dLdy=−1y=−2\frac{dL}{dy} = -\frac{1}{y} = -2; dydh=σ(h)(1−σ(h))=14\frac{dy}{dh} = \sigma(h)(1 - \sigma(h)) = \frac14; dhdx=2\frac{dh}{dx} = 2. So dLdx=(−2)⋅14⋅2=−1\frac{dL}{dx} = (-2)\cdot\frac14\cdot 2 = -1. The middle two factors combine to dLdh=−(1−y)=y−1=−12\frac{dL}{dh} = -(1 - y) = y - 1 = -\frac12, the familiar “prediction minus label” of a logistic output.

A constrained minimum. Minimize x2+2y2x^2 + 2y^2 subject to x+y=3x + y = 3. Lagrange gives ∇f=(2x,4y)=λ(1,1)\nabla f = (2x, 4y) = \lambda (1, 1), so x=λ/2x = \lambda/2, y=λ/4y = \lambda/4, and x+y=3λ/4=3x + y = 3\lambda/4 = 3 gives λ=4\lambda = 4, (x,y)=(2,1)(x, y) = (2, 1), value 4+2=64 + 2 = 6. Check by substitution: f=x2+2(3−x)2f = x^2 + 2(3 - x)^2, f′=2x−4(3−x)=6x−12=0f' = 2x - 4(3 - x) = 6x - 12 = 0 at x=2x = 2.

The problems follow the same seven topics as the review above, in the same order. Answers are exact (for example −1/5-1/\sqrt5, not −0.447-0.447). 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.

q1. (1,2,3)⋅(4,−5,6)(1, 2, 3) \cdot (4, -5, 6). [number]

Answer

1212. Multiply entry by entry and add: 1⋅4+2⋅(−5)+3⋅6=4−10+18=121 \cdot 4 + 2 \cdot (-5) + 3 \cdot 6 = 4 - 10 + 18 = 12. A common mistake is 32, which drops the sign of −5-5.

q2. (1,2,3)×(4,5,6)(1, 2, 3) \times (4, 5, 6). [vector]

Answer

(−3,6,−3)(-3, 6, -3). u×v=(u2v3−u3v2, u3v1−u1v3, u1v2−u2v1)=(12−15, 12−6, 5−8)u \times v = (u_2 v_3 - u_3 v_2,\ u_3 v_1 - u_1 v_3,\ u_1 v_2 - u_2 v_1) = (12 - 15,\ 12 - 6,\ 5 - 8). Check: (−3,6,−3)⋅(1,2,3)=−3+12−9=0(-3, 6, -3) \cdot (1, 2, 3) = -3 + 12 - 9 = 0, so it is perpendicular to uu. Answering (3,−6,3)(3, -6, 3) computes v×uv \times u: the cross product is antisymmetric, so the order matters.

q3. Give the angle between (1,0)(1, 0) and (1,1)(1, 1), in radians. [number]

Answer

π/4\pi/4. cos⁡θ=u⋅v∥u∥∥v∥=11⋅2\cos\theta = \frac{u \cdot v}{\lVert u \rVert \lVert v \rVert} = \frac{1}{1 \cdot \sqrt2}, so θ=arccos⁡(1/2)=π/4\theta = \arccos(1/\sqrt2) = \pi/4. A common mistake is to stop at 1/21/\sqrt2, which is the cosine, not the angle.

q4. ∥(2,3,6)∥\lVert (2, 3, 6) \rVert. [number]

Answer

77. 4+9+36=49=7\sqrt{4 + 9 + 36} = \sqrt{49} = 7. Answering 49 forgets the square root: that is v⋅vv \cdot v.

q5. Give the equation of the plane through (1,0,0)(1, 0, 0), (0,1,0)(0, 1, 0), and (0,0,1)(0, 0, 1). [equation in x, y, z]

Answer

x+y+z=1x + y + z = 1. Two edge vectors from (1,0,0)(1, 0, 0) are (−1,1,0)(-1, 1, 0) and (−1,0,1)(-1, 0, 1); their cross product is the normal n=(1,1,1)n = (1, 1, 1). Then d=n⋅(1,0,0)=1d = n \cdot (1, 0, 0) = 1. Any nonzero multiple, such as 2x+2y+2z=22x + 2y + 2z = 2, is the same plane. x+y+z=0x + y + z = 0 is the parallel plane through the origin, which contains none of the three points.

q6. Give the distance from the point (1,2,3)(1, 2, 3) to the plane x+y+z=0x + y + z = 0. [number]

Answer

232\sqrt3. ∣n⋅p−d∣∥n∥=∣1+2+3−0∣3=63=23\frac{|n \cdot p - d|}{\lVert n \rVert} = \frac{|1 + 2 + 3 - 0|}{\sqrt3} = \frac{6}{\sqrt3} = 2\sqrt3. A common mistake is 6, which forgets to divide by the normal’s length: n⋅p−dn \cdot p - d measures distance in units of ∥n∥\lVert n \rVert.

q7. Give the area of the triangle with vertices (1,0,0)(1, 0, 0), (0,1,0)(0, 1, 0), (0,0,1)(0, 0, 1). [number]

Answer

3/2\sqrt3/2. With the edges of q5, ∥(−1,1,0)×(−1,0,1)∥=∥(1,1,1)∥=3\lVert (-1, 1, 0) \times (-1, 0, 1) \rVert = \lVert (1, 1, 1) \rVert = \sqrt3 is the area of the parallelogram; the triangle is half of it. Answering 3\sqrt3 reports the parallelogram.

q8. Are (1,2,−1)(1, 2, -1) and (3,−1,1)(3, -1, 1) orthogonal? [bool]

Answer

True. (1,2,−1)⋅(3,−1,1)=3−2−1=0(1, 2, -1) \cdot (3, -1, 1) = 3 - 2 - 1 = 0, and a zero dot product means orthogonal.

q9. f(x,y)=x2y+sin⁡(xy)f(x, y) = x^2 y + \sin(xy). Give ∂f/∂x\partial f / \partial x. [expr in x, y]

Answer

2xy+ycos⁡(xy)2xy + y\cos(xy). Hold yy fixed. ∂x(x2y)=2xy\partial_x(x^2 y) = 2xy; for sin⁡(xy)\sin(xy) the chain rule gives cos⁡(xy)\cos(xy) times the inner derivative ∂x(xy)=y\partial_x(xy) = y. A common mistake is 2xy+cos⁡(xy)2xy + \cos(xy), which drops the inner factor yy.

q10. Give ∂f/∂y\partial f / \partial y for the ff of q9. [expr in x, y]

Answer

x2+xcos⁡(xy)x^2 + x\cos(xy). Hold xx fixed: ∂y(x2y)=x2\partial_y(x^2 y) = x^2, and ∂ysin⁡(xy)=cos⁡(xy)⋅x\partial_y \sin(xy) = \cos(xy) \cdot x. Dropping the inner xx gives the wrong x2+cos⁡(xy)x^2 + \cos(xy).

q11. f(x,y)=x2+3xy+y2f(x, y) = x^2 + 3xy + y^2. Give ∇f(1,2)\nabla f(1, 2). [vector]

Answer

(8,7)(8, 7). ∇f=(2x+3y, 3x+2y)\nabla f = (2x + 3y,\ 3x + 2y); at (1,2)(1, 2) that is (2+6, 3+4)(2 + 6,\ 3 + 4). The order matters: (7,8)(7, 8) swaps the components.

q12. f(a,b,c)=a2+b2+c2f(a, b, c) = a^2 + b^2 + c^2. Give ∇f\nabla f. [vector]

Answer

(2a,2b,2c)(2a, 2b, 2c). Each partial differentiates one square: ∂aa2=2a\partial_a a^2 = 2a, and the other terms are constants in aa. Answering (a,b,c)(a, b, c) forgets the factor 2 from the power rule.

q13. f(x,y)=3x−2y+7f(x, y) = 3x - 2y + 7. Give ∇f\nabla f. [vector]

Answer

(3,−2)(3, -2). 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 (3,−2,7)(3, -2, 7) is wrong.

q14. ∂2∂x ∂y x3y2\dfrac{\partial^2}{\partial x\, \partial y}\, x^3 y^2. [expr in x, y]

Answer

6x2y6x^2 y. ∂y(x3y2)=2x3y\partial_y(x^3 y^2) = 2x^3 y, then ∂x(2x3y)=6x2y\partial_x(2x^3 y) = 6x^2 y (the other order gives the same, as it must for a smooth function). A common mistake is 3x2y23x^2 y^2, which takes only the xx derivative.

q15. f(x,y)=ln⁡(ex+ey)f(x, y) = \ln(e^x + e^y) (log-sum-exp). Give ∇f\nabla f. [vector]

Answer

(exex+ey, eyex+ey)\left(\frac{e^x}{e^x + e^y},\ \frac{e^y}{e^x + e^y}\right). ∂xln⁡(ex+ey)=1ex+ey⋅ex\partial_x \ln(e^x + e^y) = \frac{1}{e^x + e^y} \cdot e^x by the chain rule, and the same for yy. This is the softmax of (x,y)(x, y), 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: (ex,ey)(e^x, e^y) drops the outer 1/(⋅)1/(\cdot), and (1ex+ey,1ex+ey)\left(\frac{1}{e^x + e^y}, \frac{1}{e^x + e^y}\right) drops the inner derivative.

q16. f(x)=12∥Ax−b∥2f(x) = \frac{1}{2}\lVert A x - b \rVert^2 with A=(1002)A = \begin{pmatrix} 1 & 0 \\ 0 & 2 \end{pmatrix} and b=(1,1)b = (1, 1). Give ∇f(0,0)\nabla f(0, 0). [vector]

Answer

(−1,−2)(-1, -2). ∇f=A⊤(Ax−b)\nabla f = A^\top(Ax - b); at x=0x = 0, Ax−b=(−1,−1)Ax - b = (-1, -1) and A⊤(−1,−1)=(−1,−2)A^\top(-1, -1) = (-1, -2). This is the direction gradient descent follows. A common mistake is (−1,−1)(-1, -1), which forgets A⊤A^\top: the chain rule through AxAx contributes the transpose. (1,2)(1, 2) has the sign of Ax−bAx - b flipped.

q17. f(x,y)=xeyf(x, y) = x e^y. Give ∂f/∂y\partial f / \partial y at (2,0)(2, 0). [number]

Answer

22. ∂y(xey)=xey\partial_y(x e^y) = x e^y, and at (2,0)(2, 0) that is 2⋅12 \cdot 1. Answering 1 evaluates eye^y and forgets the factor xx.

q18. The squared error of a one-weight model is L(w)=(wx−y)2L(w) = (w x - y)^2. Give ∂L/∂w\partial L / \partial w. [expr in w, x, y]

Answer

2x(wx−y)2x(wx - y). The outer square gives 2(wx−y)2(wx - y), and the inner derivative ∂w(wx−y)=x\partial_w(wx - y) = x multiplies it. Dropping xx gives 2(wx−y)2(wx - y), the gradient with respect to the prediction, not the weight.

q19. z=x2+y2z = x^2 + y^2 with x=cos⁡tx = \cos t, y=sin⁡ty = \sin t. Give dz/dtdz/dt. [number]

Answer

00. One term per path: dzdt=2x⋅(−sin⁡t)+2y⋅cos⁡t=−2cos⁡tsin⁡t+2sin⁡tcos⁡t=0\frac{dz}{dt} = 2x \cdot (-\sin t) + 2y \cdot \cos t = -2\cos t \sin t + 2\sin t \cos t = 0. Directly, z=cos⁡2t+sin⁡2t=1z = \cos^2 t + \sin^2 t = 1 is constant.

q20. z=xyz = xy with x=t2x = t^2, y=t3y = t^3. Give dz/dtdz/dt. [expr in t]

Answer

5t45t^4. dzdt=y⋅x′(t)+x⋅y′(t)=t3⋅2t+t2⋅3t2=5t4\frac{dz}{dt} = y \cdot x'(t) + x \cdot y'(t) = t^3 \cdot 2t + t^2 \cdot 3t^2 = 5t^4; directly, z=t5z = t^5. A common mistake is 6t3=(2t)(3t2)6t^3 = (2t)(3t^2), which multiplies the two inner derivatives instead of summing one term per path.

q21. f(u,v)=uvf(u, v) = uv with u=x+yu = x + y, v=x−yv = x - y. Give ∂f/∂x\partial f / \partial x. [expr in x, y]

Answer

2x2x. ∂f∂x=v⋅∂u∂x+u⋅∂v∂x=(x−y)+(x+y)=2x\frac{\partial f}{\partial x} = v \cdot \frac{\partial u}{\partial x} + u \cdot \frac{\partial v}{\partial x} = (x - y) + (x + y) = 2x. Check: f=(x+y)(x−y)=x2−y2f = (x + y)(x - y) = x^2 - y^2.

q22. Give ∂f/∂y\partial f / \partial y for the ff of q21. [expr in x, y]

Answer

−2y-2y. ∂f∂y=v⋅1+u⋅(−1)=(x−y)−(x+y)=−2y\frac{\partial f}{\partial y} = v \cdot 1 + u \cdot (-1) = (x - y) - (x + y) = -2y. The sign comes from ∂v/∂y=−1\partial v / \partial y = -1; dropping it gives 2y2y.

q23. L(w)=(σ(wx)−1)2L(w) = (\sigma(w x) - 1)^2 with the sigmoid σ\sigma. Give dL/dwdL/dw at w=0w = 0, x=2x = 2. [number]

Answer

−1/2-1/2. With z=wxz = wx: at w=0w = 0, z=0z = 0 and σ(0)=1/2\sigma(0) = 1/2. Three factors: dLdσ=2(σ−1)=−1\frac{dL}{d\sigma} = 2(\sigma - 1) = -1, dσdz=σ(1−σ)=14\frac{d\sigma}{dz} = \sigma(1 - \sigma) = \frac14, dzdw=x=2\frac{dz}{dw} = x = 2. Product: −1⋅14⋅2=−12-1 \cdot \frac14 \cdot 2 = -\frac12. Common mistakes: −1/4-1/4 drops the factor xx, and −2-2 drops the sigmoid’s slope 1/41/4.

q24. f(x,y)=x2+y2f(x, y) = x^2 + y^2 with x=rcos⁡θx = r\cos\theta, y=rsin⁡θy = r\sin\theta. Give ∂f/∂r\partial f / \partial r. [expr in r]

Answer

2r2r. ∂f∂r=2xcos⁡θ+2ysin⁡θ=2rcos⁡2θ+2rsin⁡2θ=2r\frac{\partial f}{\partial r} = 2x\cos\theta + 2y\sin\theta = 2r\cos^2\theta + 2r\sin^2\theta = 2r; directly, f=r2f = r^2. 2r22r^2 is not a derivative of anything here.

q25. Give the Jacobian matrix of (x,y)↦(x+y, xy)(x, y) \mapsto (x + y,\ xy) at (1,2)(1, 2). [matrix]

Answer

(1121)\begin{pmatrix} 1 & 1 \\ 2 & 1 \end{pmatrix}. Row ii is the gradient of output ii: ∇(x+y)=(1,1)\nabla(x + y) = (1, 1) and ∇(xy)=(y,x)=(2,1)\nabla(xy) = (y, x) = (2, 1) at (1,2)(1, 2). The transpose (1211)\begin{pmatrix} 1 & 2 \\ 1 & 1 \end{pmatrix} puts inputs in rows, against the convention (J)ij=∂gi/∂xj(J)_{ij} = \partial g_i / \partial x_j.

q26. Give the determinant of the Jacobian of (r,θ)↦(rcos⁡θ, rsin⁡θ)(r, \theta) \mapsto (r\cos\theta,\ r\sin\theta). [expr in r]

Answer

rr. J=(cos⁡θ−rsin⁡θsin⁡θrcos⁡θ)J = \begin{pmatrix} \cos\theta & -r\sin\theta \\ \sin\theta & r\cos\theta \end{pmatrix}, so det⁡J=rcos⁡2θ+rsin⁡2θ=r\det J = r\cos^2\theta + r\sin^2\theta = r. This rr is the extra factor in dA=r dr dθdA = r\,dr\,d\theta (q45, q46). Answering 1 treats polar coordinates as if they preserved area.

q27. h=3x+1h = 3x + 1, y=h2y = h^2, L=(y−4)2L = (y - 4)^2. Give dL/dxdL/dx at x=0x = 0 (backpropagate one factor at a time). [number]

Answer

−36-36. Forward at x=0x = 0: h=1h = 1, y=1y = 1, L=9L = 9. Backward, one factor at a time: dLdy=2(y−4)=−6\frac{dL}{dy} = 2(y - 4) = -6; dydh=2h=2\frac{dy}{dh} = 2h = 2, so dLdh=−12\frac{dL}{dh} = -12; dhdx=3\frac{dh}{dx} = 3, so dLdx=−36\frac{dL}{dx} = -36. Common mistakes: −12-12 is dL/dhdL/dh, which stops before the last factor dh/dx=3dh/dx = 3, and 3636 loses the sign of y−4y - 4.

q28. f(x)=Axf(x) = A x with A=(1234)A = \begin{pmatrix} 1 & 2 \\ 3 & 4 \end{pmatrix}. Give the vector-Jacobian product u⊤Jfu^\top J_f for u=(1,1)u = (1, 1), as a column. [vector]

Answer

(4,6)(4, 6). Jf=AJ_f = A, and u⊤A=(1⋅1+1⋅3, 1⋅2+1⋅4)=(4,6)u^\top A = (1 \cdot 1 + 1 \cdot 3,\ 1 \cdot 2 + 1 \cdot 4) = (4, 6): the column sums of AA weighted by uu. 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 (3,7)=Au(3, 7) = Au, the row sums: that is a JVP, and for a non-symmetric AA it is a different vector.

q29. f(x,y)=x2+y2f(x, y) = x^2 + y^2. Give the directional derivative at (1,1)(1, 1) in the direction u=(3/5,4/5)u = (3/5, 4/5). [number]

Answer

14/514/5. ∇f(1,1)=(2,2)\nabla f(1, 1) = (2, 2), and (2,2)⋅(3/5,4/5)=6/5+8/5=14/5(2, 2) \cdot (3/5, 4/5) = 6/5 + 8/5 = 14/5. A common mistake is 4, which dots the gradient with (1,1)(1, 1), a vector of length 2\sqrt2 that is not the given direction.

q30. f(x,y)=xyf(x, y) = xy. Give the largest directional derivative at (2,3)(2, 3) over all unit directions. [number]

Answer

13\sqrt{13}. The largest directional derivative is ∥∇f∥\lVert \nabla f \rVert (q34). ∇f=(y,x)=(3,2)\nabla f = (y, x) = (3, 2), with length 9+4\sqrt{9 + 4}. Answering 5 adds the components instead of taking the norm.

q31. f(x,y)=x2+2y2f(x, y) = x^2 + 2y^2. Give the unit direction of steepest descent at (1,1)(1, 1). [vector]

Answer

(−1/5, −2/5)(-1/\sqrt5,\ -2/\sqrt5). ∇f=(2x,4y)=(2,4)\nabla f = (2x, 4y) = (2, 4) at (1,1)(1, 1), with length 252\sqrt5. Steepest descent is −∇f/∥∇f∥-\nabla f / \lVert \nabla f \rVert. Common mistakes: (1/5,2/5)(1/\sqrt5, 2/\sqrt5) is steepest ascent, and (−2,−4)(-2, -4) is the right direction but not a unit vector.

q32. f(x,y)=exsin⁡yf(x, y) = e^x \sin y. Give the directional derivative at (0,π/2)(0, \pi/2) in the direction (1,0)(1, 0). [number]

Answer

11. ∇f=(exsin⁡y, excos⁡y)=(1,0)\nabla f = (e^x \sin y,\ e^x \cos y) = (1, 0) at (0,π/2)(0, \pi/2), and (1,0)⋅(1,0)=1(1, 0) \cdot (1, 0) = 1.

q33. f(x,y)=x2−y2f(x, y) = x^2 - y^2. Give a unit direction at (1,1)(1, 1) along which the directional derivative is 0 (either sign). [vector]

Answer

(1/2, 1/2)(1/\sqrt2,\ 1/\sqrt2) (or its negative). ∇f=(2x,−2y)=(2,−2)\nabla f = (2x, -2y) = (2, -2); a direction with zero derivative is perpendicular to it, and (1,1)/2(1, 1)/\sqrt2 is. Along it you follow the level curve. A common mistake is (1,−1)/2(1, -1)/\sqrt2, which points along the gradient, where the derivative is largest.

q34. Prove that at a point where ∇f≠0\nabla f \ne 0, the unit direction uu that maximizes the directional derivative Duf=∇f⋅uD_u f = \nabla f \cdot u is u=∇f/∥∇f∥u = \nabla f / \lVert \nabla f \rVert, and that the maximum is ∥∇f∥\lVert \nabla f \rVert. [proof]

Answer

Claim. Let ff be differentiable at xx with ∇f(x)≠0\nabla f(x) \ne 0. Over unit vectors uu, the directional derivative Duf(x)=∇f(x)⋅uD_u f(x) = \nabla f(x) \cdot u is largest at u∗=∇f(x)/∥∇f(x)∥u^* = \nabla f(x) / \lVert \nabla f(x) \rVert, and its maximum value is ∥∇f(x)∥\lVert \nabla f(x) \rVert.

Proof (direct). By the chain rule applied to s↦f(x+su)s \mapsto f(x + su), Duf(x)=ddsf(x+su)∣s=0=∇f(x)⋅uD_u f(x) = \frac{d}{ds} f(x + su)\big|_{s=0} = \nabla f(x) \cdot u. For every unit vector uu, the Cauchy-Schwarz inequality gives ∇f(x)⋅u≤∥∇f(x)∥ ∥u∥=∥∇f(x)∥\nabla f(x) \cdot u \le \lVert \nabla f(x) \rVert\,\lVert u \rVert = \lVert \nabla f(x) \rVert. Since ∇f(x)≠0\nabla f(x) \ne 0, u∗u^* is defined and ∥u∗∥=1\lVert u^* \rVert = 1, and ∇f(x)⋅u∗=∥∇f(x)∥2/∥∇f(x)∥=∥∇f(x)∥\nabla f(x) \cdot u^* = \lVert \nabla f(x) \rVert^2 / \lVert \nabla f(x) \rVert = \lVert \nabla f(x) \rVert, so the bound is attained. Hence the maximizing direction is u∗u^* and the maximum is ∥∇f(x)∥\lVert \nabla f(x) \rVert.

A complete proof derives Duf=∇f⋅uD_u f = \nabla f \cdot u from the chain rule, bounds it with Cauchy-Schwarz, shows u∗u^* is a unit vector that attains the bound (this is where ∇f≠0\nabla f \ne 0 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 f(x,y)=x2+3xy+2y2f(x, y) = x^2 + 3xy + 2y^2. [matrix]

Answer

(2334)\begin{pmatrix} 2 & 3 \\ 3 & 4 \end{pmatrix}. fxx=2f_{xx} = 2, fyy=4f_{yy} = 4, and fxy=∂y(2x+3y)=3f_{xy} = \partial_y(2x + 3y) = 3. A common mistake is 3/23/2 off the diagonal: in 12x⊤Hx\frac12 x^\top H x the cross term 3xy3xy is split as 12(H12+H21)xy\frac12(H_{12} + H_{21})xy, so each off-diagonal entry is the full 3, not half of it. (1332)\begin{pmatrix} 1 & 3 \\ 3 & 2 \end{pmatrix} reads the coefficients off without differentiating.

q36. Give the Hessian of f(x,y)=x3+y3f(x, y) = x^3 + y^3 at (1,1)(1, 1). [matrix]

Answer

(6006)\begin{pmatrix} 6 & 0 \\ 0 & 6 \end{pmatrix}. fxx=6xf_{xx} = 6x, fyy=6yf_{yy} = 6y, fxy=0f_{xy} = 0; at (1,1)(1, 1) the diagonal is 6. Answering 3 on the diagonal takes only the first derivative’s coefficient.

q37. Classify the critical point (0,0)(0, 0) of f(x,y)=x2−y2f(x, y) = x^2 - y^2: minimum, maximum, or saddle. [choice]

Answer

Saddle. H=diag⁡(2,−2)H = \operatorname{diag}(2, -2) has one positive and one negative eigenvalue: ff rises along xx and falls along yy. det⁡H=−4<0\det H = -4 < 0.

q38. Classify the critical point (0,0)(0, 0) of f(x,y)=x2+xy+y2f(x, y) = x^2 + xy + y^2: minimum, maximum, or saddle. [choice]

Answer

Minimum. H=(2112)H = \begin{pmatrix} 2 & 1 \\ 1 & 2 \end{pmatrix}, with det⁡H=4−1=3>0\det H = 4 - 1 = 3 > 0 and fxx=2>0f_{xx} = 2 > 0 (eigenvalues 1 and 3). A cross term alone does not make a saddle; only det⁡H<0\det H < 0 does.

q39. Give the critical point of f(x,y)=x2+y2−2x+4yf(x, y) = x^2 + y^2 - 2x + 4y. [vector]

Answer

(1,−2)(1, -2). ∇f=(2x−2, 2y+4)=0\nabla f = (2x - 2,\ 2y + 4) = 0 gives x=1x = 1, y=−2y = -2. Completing the square, f=(x−1)2+(y+2)2−5f = (x - 1)^2 + (y + 2)^2 - 5, confirms it. (−1,2)(-1, 2) has both signs flipped.

q40. Classify the critical point (1,0)(1, 0) of f(x,y)=x3−3x+y2f(x, y) = x^3 - 3x + y^2: minimum, maximum, or saddle. [choice]

Answer

Minimum. ∇f=(3x2−3, 2y)\nabla f = (3x^2 - 3,\ 2y) vanishes at (1,0)(1, 0), and H=(6x002)=diag⁡(6,2)H = \begin{pmatrix} 6x & 0 \\ 0 & 2 \end{pmatrix} = \operatorname{diag}(6, 2) there, positive definite. (The other critical point, (−1,0)(-1, 0), is a saddle.)

q41. Is the Hessian of q35 positive definite? [bool]

Answer

False. det⁡(2334)=8−9=−1<0\det\begin{pmatrix} 2 & 3 \\ 3 & 4 \end{pmatrix} = 8 - 9 = -1 < 0, 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. f(x)=12x⊤Hxf(x) = \frac{1}{2} x^\top H x with H=diag⁡(1,100)H = \operatorname{diag}(1, 100). Give the condition number λmax⁡/λmin⁡\lambda_{\max} / \lambda_{\min} of its Hessian. [number]

Answer

100100. The Hessian of 12x⊤Hx\frac12 x^\top H x is HH itself, with eigenvalues 1 and 100. Gradient descent shrinks the error by about 1−1/1001 - 1/100 per step, so κ=100\kappa = 100 means slow convergence along the flat direction (gradient descent). Common mistakes: 1/1001/100 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. ∫01∫02xy dy dx\displaystyle\int_0^1 \int_0^2 x y\, dy\, dx. [number]

Answer

11. Inner: ∫02xy dy=x⋅y22∣02=2x\int_0^2 xy\,dy = x \cdot \frac{y^2}{2}\Big|_0^2 = 2x. Outer: ∫012x dx=1\int_0^1 2x\,dx = 1. Answering 2 keeps the inner result and forgets the outer integral over xx.

q44. Give the area of the triangle 0≤y≤x≤10 \le y \le x \le 1 as a double integral. [number]

Answer

1/21/2. ∫01∫0x1 dy dx=∫01x dx=12\int_0^1 \int_0^x 1\,dy\,dx = \int_0^1 x\,dx = \frac12. The inner limit depends on xx; integrating over the whole unit square gives 1.

q45. ∬x2+y2≤11 dA\displaystyle\iint_{x^2 + y^2 \le 1} 1\, dA. [number]

Answer

π\pi. In polar coordinates, ∫02π∫01r dr dθ=2π⋅12=π\int_0^{2\pi} \int_0^1 r\,dr\,d\theta = 2\pi \cdot \frac12 = \pi, the area of the unit disk. A common mistake is 2π2\pi, which integrates dr dθdr\,d\theta without the Jacobian rr.

q46. ∬R2e−(x2+y2) dA\displaystyle\iint_{\mathbb{R}^2} e^{-(x^2 + y^2)}\, dA. [number]

Answer

π\pi. ∫02π∫0∞e−r2r dr dθ\int_0^{2\pi} \int_0^\infty e^{-r^2} r\,dr\,d\theta; substitute s=r2s = r^2, ds=2r drds = 2r\,dr: the inner integral is 12∫0∞e−s ds=12\frac12 \int_0^\infty e^{-s}\,ds = \frac12, so the total is 2π⋅12=π2\pi \cdot \frac12 = \pi. It is also (∫e−x2dx)2\left(\int e^{-x^2}dx\right)^2, which is how ∫e−x2=π\int e^{-x^2} = \sqrt\pi is proved. π\sqrt\pi is the one-variable value.

q47. ∫01∫0x2y dy dx\displaystyle\int_0^1 \int_0^x 2y\, dy\, dx. [number]

Answer

1/31/3. Inner: ∫0x2y dy=x2\int_0^x 2y\,dy = x^2. Outer: ∫01x2 dx=13\int_0^1 x^2\,dx = \frac13. Answering 1/21/2 uses the wrong inner limit.

q48. Give the volume under z=1−x2−y2z = 1 - x^2 - y^2 and above the unit disk x2+y2≤1x^2 + y^2 \le 1. [number]

Answer

π/2\pi/2. ∫02π∫01(1−r2) r dr dθ=2π(12−14)=π2\int_0^{2\pi} \int_0^1 (1 - r^2)\, r\,dr\,d\theta = 2\pi\left(\frac12 - \frac14\right) = \frac{\pi}{2}. Answering π\pi forgets the r2r^2 term (that is the volume of the cylinder of height 1).

q49. ∬R212πe−(x2+y2)/2 dA\displaystyle\iint_{\mathbb{R}^2} \frac{1}{2\pi} e^{-(x^2 + y^2)/2}\, dA, the total mass of a 2-D standard normal. [number]

Answer

11. 12π∫02π∫0∞e−r2/2r dr dθ=12π⋅2π⋅1\frac{1}{2\pi}\int_0^{2\pi} \int_0^\infty e^{-r^2/2} r\,dr\,d\theta = \frac{1}{2\pi} \cdot 2\pi \cdot 1, since ∫0∞re−r2/2dr=1\int_0^\infty r e^{-r^2/2}dr = 1 by s=r2/2s = r^2/2. A density integrates to 1, which is what makes 12π\frac{1}{2\pi} the right constant (Random variables, expectation, variance, and normal draws by Box-Muller). 2π2\pi forgets the normalizer.

q50. With u=x+yu = x + y, v=x−yv = x - y, give the area of the region ∣x+y∣≤1|x + y| \le 1, ∣x−y∣≤1|x - y| \le 1. [number]

Answer

22. In (u,v)(u, v) the region is the square [−1,1]2[-1, 1]^2, of area 4. The map (x,y)↦(u,v)(x, y) \mapsto (u, v) has det⁡(111−1)=−2\det \begin{pmatrix} 1 & 1 \\ 1 & -1 \end{pmatrix} = -2, so du dv=2 dx dydu\,dv = 2\,dx\,dy and the area in (x,y)(x, y) is 4/2=24 / 2 = 2. (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.

q51. Give the maximum of x+yx + y subject to x2+y2=1x^2 + y^2 = 1. [number]

Answer

2\sqrt2. ∇(x+y)=(1,1)=λ(2x,2y)\nabla(x + y) = (1, 1) = \lambda(2x, 2y) gives x=yx = y, and x2+y2=1x^2 + y^2 = 1 gives x=y=1/2x = y = 1/\sqrt2, so the maximum is 2/2=22/\sqrt2 = \sqrt2 (the minimum −2-\sqrt2 is at the opposite point). 1 is the value at (1,0)(1, 0), not an optimum; 2 ignores the constraint.

q52. Give the minimum of x2+y2x^2 + y^2 subject to x+y=1x + y = 1. [number]

Answer

1/21/2. (2x,2y)=λ(1,1)(2x, 2y) = \lambda(1, 1) gives x=y=12x = y = \frac12, and f=14+14=12f = \frac14 + \frac14 = \frac12. A common mistake is 1/21/\sqrt2, which is the distance from the origin to the line, not its square.

q53. Give the maximum of xyxy subject to x+y=10x + y = 10. [number]

Answer

2525. (y,x)=λ(1,1)(y, x) = \lambda(1, 1) gives x=y=5x = y = 5, and xy=25xy = 25. Answering 5 reports the optimizer x=y=5x = y = 5 instead of the optimum value.

q54. Maximize the entropy −∑i=13piln⁡pi-\sum_{i=1}^{3} p_i \ln p_i subject to p1+p2+p3=1p_1 + p_2 + p_3 = 1. Give the optimal p1p_1. [number]

Answer

1/31/3. ∂pi(−∑pjln⁡pj−λ(∑pj−1))=−ln⁡pi−1−λ=0\partial_{p_i}\left(-\sum p_j \ln p_j - \lambda(\sum p_j - 1)\right) = -\ln p_i - 1 - \lambda = 0, so every pip_i has the same value, and the constraint makes it 1/31/3. 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 xyzxyz subject to x+y+z=3x + y + z = 3 with x,y,z>0x, y, z > 0. [number]

Answer

11. (yz,xz,xy)=λ(1,1,1)(yz, xz, xy) = \lambda(1, 1, 1) forces x=y=zx = y = z (all positive), so each is 1 and xyz=1xyz = 1; AM-GM confirms xyz≤((x+y+z)/3)3=1xyz \le ((x + y + z)/3)^3 = 1. A common mistake is 27, which is (x+y+z)3(x + y + z)^3.

q56. Give the minimum of 2x+3y2x + 3y subject to xy=6xy = 6 with x,y>0x, y > 0. [number]

Answer

1212. (2,3)=λ(y,x)(2, 3) = \lambda(y, x) gives y=2/λy = 2/\lambda, x=3/λx = 3/\lambda, and xy=6/λ2=6xy = 6/\lambda^2 = 6 gives λ=1\lambda = 1: x=3x = 3, y=2y = 2, value 6+6=126 + 6 = 12. A common mistake is 13 from x=2x = 2, y=3y = 3, which pairs the multiplier equations the wrong way round.

q57. Give the point of the plane x+2y+2z=9x + 2y + 2z = 9 closest to the origin. [vector]

Answer

(1,2,2)(1, 2, 2). Minimize x2+y2+z2x^2 + y^2 + z^2: (2x,2y,2z)=λ(1,2,2)(2x, 2y, 2z) = \lambda(1, 2, 2), so the point is t(1,2,2)t(1, 2, 2), on the normal through the origin. The constraint gives t+4t+4t=9t + 4t + 4t = 9, t=1t = 1. The distance is 3. (1/3,2/3,2/3)(1/3, 2/3, 2/3) is the unit normal, a direction, not the point.

q58. With Lagrange multipliers, show that the distribution pp over states 1,…,n1, \dots, n with energies EiE_i that maximizes the entropy −∑ipiln⁡pi-\sum_i p_i \ln p_i subject to ∑ipi=1\sum_i p_i = 1 and ∑ipiEi=U\sum_i p_i E_i = U has the form pi=e−βEi/∑je−βEjp_i = e^{-\beta E_i} / \sum_j e^{-\beta E_j} (a softmax of −βE-\beta E). [proof]

Answer

Claim. Among distributions p=(p1,…,pn)p = (p_1, \dots, p_n) with pi>0p_i > 0, ∑ipi=1\sum_i p_i = 1, and ∑ipiEi=U\sum_i p_i E_i = U, a stationary point of the entropy H(p)=−∑ipiln⁡piH(p) = -\sum_i p_i \ln p_i has pi=e−βEi/∑je−βEjp_i = e^{-\beta E_i} / \sum_j e^{-\beta E_j} for a constant β\beta.

Proof (Lagrange multipliers). Introduce multipliers α\alpha for the normalization and β\beta for the energy constraint, and form L(p,α,β)=−∑ipiln⁡pi−α(∑ipi−1)−β(∑ipiEi−U).\mathcal{L}(p, \alpha, \beta) = -\sum_i p_i \ln p_i - \alpha\Big(\sum_i p_i - 1\Big) - \beta\Big(\sum_i p_i E_i - U\Big). At a constrained stationary point, ∂L/∂pi=0\partial \mathcal{L} / \partial p_i = 0 for each ii: −ln⁡pi−1−α−βEi=0-\ln p_i - 1 - \alpha - \beta E_i = 0, so pi=e−1−α e−βEip_i = e^{-1 - \alpha}\, e^{-\beta E_i}. The factor e−1−αe^{-1-\alpha} is the same for every ii. The normalization ∑ipi=1\sum_i p_i = 1 gives e−1−α∑je−βEj=1e^{-1 - \alpha} \sum_j e^{-\beta E_j} = 1, so e−1−α=1/∑je−βEje^{-1-\alpha} = 1 / \sum_j e^{-\beta E_j}. Therefore pi=e−βEi∑je−βEj,p_i = \frac{e^{-\beta E_i}}{\sum_j e^{-\beta E_j}}, the softmax of −βE-\beta E, with β\beta the value for which ∑ipiEi=U\sum_i p_i E_i = U. (Since HH 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 pip_i to zero, uses the normalization to fix the common constant, and concludes the softmax form with β\beta fixed by the energy constraint. Model proof also in q58.md.

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:

PitfallSymptomHow to avoid it
Dropping an inner derivative in a partial∂xsin⁡(xy)\partial_x \sin(xy) given as cos⁡(xy)\cos(xy); gradcheck fails on every product inside a nonlinearityapply the chain rule to every inner function and write its derivative as a separate factor (q9, q10, q18)
Forgetting the A⊤A^\top in a least-squares gradientdescent along the wrong direction for any non-identity AAdifferentiate through AxAx with the chain rule, which brings in A⊤A^\top (q16)
Multiplying the derivatives of the parts instead of summing over pathsdz/dtdz/dt for z=xyz = xy given as x′(t) y′(t)x'(t)\,y'(t)write one term per path from tt to zz and add them (q20)
Skipping a factor in a chain of local derivativesa backward pass off by the sigmoid’s slope or a weightbackpropagate one named local derivative at a time and multiply them all (q23, q27)
Computing JuJ u when the backward pass needs u⊤Ju^\top Jthe gradient of a non-symmetric layer comes out transposedcompute the row vector u⊤Ju^\top J, a weighted sum of rows of JJ (q28)
Using an unnormalized directiona directional derivative scaled by the direction’s lengthuse the given unit vector, or divide by the norm first (q29, q31)
Halving the mixed term of a Hessiana saddle misread as a minimumtake H12=∂x∂yfH_{12} = \partial_x\partial_y f directly, which is the full coefficient of xyxy (q35)
Forgetting the Jacobian factor in a change of variablespolar integrals off by the missing rrwrite dA=∣det⁡J∣ du dvdA = \lvert\det J\rvert\,du\,dv before setting limits (q45, q50)
Reporting the optimizer instead of the optimumthe argmax given as the maxsubstitute the optimizer back into ff and report that value (q52, q53)

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.

  • OpenStax, Calculus Volume 3 (free), chapters 2, 4, and 5.
  • Boyd and Vandenberghe, Convex Optimization, section 5.1, for Lagrange duality.
  • Gradient: the vector of partial derivatives of a scalar function; it points in the direction of steepest ascent.
  • Directional derivative: Duf=∇f⋅uD_u f = \nabla f \cdot u, the rate of change of ff along a unit vector uu.
  • Jacobian: the matrix of partial derivatives of a vector-valued function, (Jg)ij=∂gi/∂xj(J_g)_{ij} = \partial g_i / \partial x_j.
  • Vector-Jacobian product (VJP): u⊤Ju^\top J, one step of reverse-mode differentiation.
  • Hessian: the symmetric matrix of second partial derivatives, whose eigenvalues classify a critical point.
  • Condition number: κ=λmax⁡/λmin⁡\kappa = \lambda_{\max}/\lambda_{\min} of a positive definite matrix, which sets how slowly gradient descent converges.
  • Lagrange multiplier: the scalar λ\lambda in ∇f=λ∇g\nabla f = \lambda \nabla g at a constrained optimum.
  • 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 ∣det⁡J∣|\det J|: the rr in polar coordinates is why ∬e−(x2+y2)=π\iint e^{-(x^2 + y^2)} = \pi (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).