Survey of Mathematics

5.5 Higher partial derivatives and the equality of mixed partials

Differentiate a field twice and there are n² second partials, but for any field you will meet they come in equal pairs, f_xy = f_yx. This chapter proves that (Schwarz, Clairaut) with the mean value theorem on a rectangle, shows the function where it fails, and records what the pairing buys. It also sharpens the test of 5.3 for differentiability.

Taught in 375/376Apostol, not taughtBeyond the courseApostol Vol. 2, 8.23 (Theorems 8.12 and 8.13), 8.9 #10 to #12, 8.24 #1 to #3 and the end of 8.13Spagnolie, Lecture 24 ('F_xy = F_yx if they are continuous') and the Practice Final 2013, extra creditSchwarz (1873), Peano (1890): history only

Differentiate f(x,y)f(x, y) in xx and the result is again a function of (x,y)(x, y), so you may differentiate it again, in xx or in yy. With two variables there are four second derivatives fxxf_{xx}, fxyf_{xy}, fyxf_{yx}, fyyf_{yy}, and with nn variables n2n^2. Every example so far had fxy=fyxf_{xy} = f_{yx}. This chapter asks whether that is a law, finds that it is nearly one, and proves exactly how nearly. It also uses the same mean value argument as 5.3 to sharpen the test for differentiability.

Before you start

1.4: the mean value theorem. 5.2: partial derivatives and the mixed partial computations of homework 11. 5.3: continuous partial derivatives imply differentiable, and the chain rule of 5.4, which makes second derivatives of composites work.

Quick checkThe mean value theorem says that for gg continuous on [a,b][a, b] and differentiable on (a,b)(a, b):
Quick checkWhich condition on the partial derivatives of ff near aa guarantees that ff is differentiable at aa?
Quick checkIn this book fxyf_{xy} means (fx)y(f_x)_y. For f(x,y)=x2y3f(x, y) = x^2y^3, what is fxyf_{xy}?

The picture: one rectangle, two ways to cut it

Take a rectangle with corners at the origin, (h,0)(h, 0), (0,k)(0, k) and (h,k)(h, k), and form the signed sum of ff at the four corners, Δ(h,k)=f(h,k)−f(h,0)−f(0,k)+f(0,0)\Delta(h, k) = f(h, k) - f(h, 0) - f(0, k) + f(0, 0). Divide by the area hkhk. The colour in the picture is that number. A mixed second derivative is exactly a limit of it: shrink kk first and you get fy(h,0)−fy(0,0)h\frac{f_y(h, 0) - f_y(0, 0)}{h}, then shrink hh and you reach fyx(0,0)f_{yx}(0, 0); shrink them in the other order and you reach fxy(0,0)f_{xy}(0, 0). For the smooth function the colours merge into one value as you zoom in, so the two orders give the same limit. For the other one, the colour depends only on the direction, and the two orders give +1+1 and −1-1. Everything in the chapter is a proof of what the picture shows.

The idea, in words

The corner sum Δ\Delta can be read in two ways. Subtract along vertical edges first: it is the change in the quantity f(x,b+k)−f(x,b)f(x, b + k) - f(x, b) as xx moves from aa to a+ha + h. By the mean value theorem that change is hh times the xx-derivative at some point. The xx-derivative of f(x,b+k)−f(x,b)f(x, b + k) - f(x, b) is fx(x,b+k)−fx(x,b)f_x(x, b + k) - f_x(x, b), again a difference over a vertical edge, and the mean value theorem in yy turns it into k fxyk\,f_{xy} at a point. So Δ=hk fxy\Delta = hk\,f_{xy} at some point inside the rectangle. Subtract along horizontal edges first and the same steps give Δ=hk fyx\Delta = hk\,f_{yx} at some other point inside. Two points of the same small rectangle, both values equal to Δ/(hk)\Delta/(hk). If the second partials are continuous, the values at the two points get close to each other as the rectangle shrinks, and both tend to the value at the corner.

Definitions

Definition T

Higher-order partial derivative

Let ff be a scalar field on an open set. Its partial derivatives D1f,…,DnfD_1f, \dots, D_nf are again scalar fields, and may have partial derivatives. The second-order partials are DjDifD_jD_if for i,j=1,…,ni, j = 1, \dots, n (differentiate in xix_i first, then in xjx_j), and in general a partial derivative of order kk is Djk⋯Dj2Dj1fD_{j_k}\cdots D_{j_2}D_{j_1}f. In the plane, with x1=xx_1 = x, x2=yx_2 = y: this book’s fxyf_{xy} is D2D1fD_2D_1f (”xx first, then yy”), Apostol’s D2,1f=D2(D1f)D_{2,1}f = D_2(D_1f) and Leibniz’s ∂2f∂y ∂x\dfrac{\partial^2f}{\partial y\,\partial x}. Notation conventions differ between books (and Spagnolie’s boards are not consistent), so read the definition each time. We will always say which order a statement uses; for a C2C^2 field it never matters.

In one lineA partial derivative of a partial derivative: differentiate ff with respect to one variable, then the result with respect to a variable, and so on kk times; the result is a partial derivative of order kk.

Why it existsSecond derivatives measure how a field bends, and higher ones are what Taylor's formula needs; they are partial derivatives of the fields that the first partials already are.

Definition T

Mixed partial derivative

A partial derivative of order k≥2k \ge 2 is mixed if the variables it differentiates in are not all the same. In two variables, fxyf_{xy} and fyxf_{yx} are the two mixed second-order partials.

In one lineA higher-order partial derivative in which at least two different variables occur, such as fxyf_{xy} and fyxf_{yx} in two variables.

Why it existsPure second partials like fxxf_{xx} are one-variable derivatives, while mixed ones record how the slope in one direction changes as you move in another, and that is where the order question comes from.

Definition A

Class C^k

Let S⊆RnS \subseteq \mathbb R^n be open. A scalar field f:S→Rf: S \to \mathbb R is of class CkC^k if every partial derivative of order 0,1,…,k0, 1, \dots, k exists and is continuous on SS. Class C0C^0 is “continuous”; class C1C^1 is the “continuously differentiable” of 5.3; C∞C^\infty means all orders. Polynomials, exp⁡\exp, sin⁡\sin, and sums, products, quotients and compositions of them are C∞C^\infty where defined (the partials are again such expressions, by the chain rule of 5.4). A vector field is CkC^k if each component is. The classes get smaller as kk grows: x∣x∣x|x| on R\mathbb R is C1C^1 (its derivative is 2∣x∣2|x|) and not C2C^2.

In one lineA field is of class CkC^k on an open set if all its partial derivatives of order at most kk exist and are continuous there; C∞C^\infty means CkC^k for every kk.

Why it existsIt is the one hypothesis that makes every theorem in this chapter and the next one true, and it extends 'continuously differentiable' (C1C^1) of 5.3 to higher orders.

By the theorem of 5.3, a C1C^1 field is differentiable. If ff is C2C^2 then each DifD_if is C1C^1, hence differentiable, so the gradient field ∇f\nabla f has a Jacobian matrix, whose (i,j)(i, j) entry is DjDifD_jD_if. This matrix of second partials is what 5.6 calls the Hessian. Its symmetry, proved below, is why the spectral theorem (3.1) applies to it.

Partial derivatives and differentiability, sharpened

5.3 proved: if all the partials exist near aa and are continuous at aa, then ff is differentiable at aa. The proof used the mean value theorem on one coordinate at a time. If you look at where each hypothesis was used, one of the coordinates did not need it.

Theorem B the argument of Apostol 8.13, one step sharper

Differentiability from n minus one continuous partials

Suppose the partials D1f,…,DnfD_1f, \dots, D_nf exist on a ball B(a)B(a) and D2f,…,DnfD_2f, \dots, D_nf are continuous at aa. Then ff is differentiable at aa and f(a+v)=f(a)+∇f(a)⋅v+∥v∥ E(a,v)f(a + v) = f(a) + \nabla f(a)\cdot v + \lVert v \rVert\,E(a, v) with E(a,v)→0E(a, v) \to 0 as v→Ov \to O. (Which coordinate is the exceptional one does not matter; relabel.)

In one lineIf D1f,…,DnfD_1f, \dots, D_nf exist in a ball around aa, and D2f,…,DnfD_2f, \dots, D_nf are continuous at aa (while D1fD_1f merely exists at aa), then ff is differentiable at aa with total derivative v↦∇f(a)⋅vv \mapsto \nabla f(a)\cdot v.

Why it is trueIt shows how little is needed: one partial derivative of any single coordinate need not even be continuous, so a field can be differentiable at a point where it is not C1C^1 in the sense of 5.3.

ProofApostol 8.13, adapted
The idea: Walk from a to a + v one coordinate at a time, as in 5.3. The first leg changes only the first coordinate: there the definition of the partial derivative at a gives the estimate. Every other leg uses the mean value theorem and continuity of that coordinate's partial at a.
f(a+v)−f(a)=∑k=1n[f(pk)−f(pk−1)]f(a + v) - f(a) = \sum_{k=1}^n\big[f(p_k) - f(p_{k-1})\big].
Same path as in 5.3: p0=ap_0 = a, pk=a+(v1,…,vk,0,…,0)p_k = a + (v_1, \dots, v_k, 0, \dots, 0), so pn=a+vp_n = a + v. Telescoping sum.
First leg: f(p1)−f(a)=v1D1f(a)+r1f(p_1) - f(a) = v_1D_1f(a) + r_1 with ∣r1∣≤ε∣v1∣|r_1| \le \varepsilon|v_1|.
The first leg is the function t↦f(a+te1)t \mapsto f(a + te_1) at t=v1t = v_1; its derivative at t=0t = 0 is D1f(a)D_1f(a), which exists. Definition of the derivative, with an ε\varepsilon: there is δ1>0\delta_1 > 0 with ∣f(a+v1e1)−f(a)−v1D1f(a)∣≤ε∣v1∣|f(a + v_1e_1) - f(a) - v_1D_1f(a)| \le \varepsilon|v_1| for ∣v1∣<δ1|v_1| < \delta_1.
Other legs: f(pk)−f(pk−1)=vkDkf(ck)f(p_k) - f(p_{k-1}) = v_kD_kf(c_k) with ckc_k on the segment from pk−1p_{k-1} to pkp_k.
For k≥2k \ge 2 the legs pk−1→pkp_{k-1} \to p_k differ in coordinate kk only, and t↦f(pk−1+tek)t \mapsto f(p_{k-1} + te_k) is differentiable (the partial exists in the ball). The mean value theorem of 1.4.
For ∥v∥<δ\lVert v \rVert < \delta: ∣Dkf(ck)−Dkf(a)∣<ε|D_kf(c_k) - D_kf(a)| < \varepsilon.
DkfD_kf is continuous at aa for k≥2k \ge 2, and ∥ck−a∥≤∥v∥\lVert c_k - a \rVert \le \lVert v \rVert. Choose δ≤δ1\delta \le \delta_1 so small that ∣Dkf(x)−Dkf(a)∣<ε|D_kf(x) - D_kf(a)| < \varepsilon for ∥x−a∥<δ\lVert x - a \rVert < \delta and k=2,…,nk = 2, \dots, n.
∣f(a+v)−f(a)−∇f(a)⋅v∣≤ε∣v1∣+∑k≥2∣vk∣ ε≤nε∥v∥\big|f(a + v) - f(a) - \nabla f(a)\cdot v\big| \le \varepsilon|v_1| + \sum_{k \ge 2}|v_k|\,\varepsilon \le n\varepsilon\lVert v \rVert. Since ε\varepsilon was arbitrary, ff is differentiable at aa. ■\blacksquare
Add the legs and subtract ∇f(a)⋅v=∑vkDkf(a)\nabla f(a)\cdot v = \sum v_kD_kf(a). Use ∣vk∣≤∥v∥|v_k| \le \lVert v \rVert.Each leg contributes at most ε times |v_k|; that is a factor ε times a length, as the definition of differentiable demands.
Proof workshopGive the reason for each line of the sharper differentiability proofApostol 8.13, adapted

Each line of the proof is shown in order. Choose the reason that justifies it, then press Check.

  1. f(a+v)−f(a)=∑k=1n[f(pk)−f(pk−1)]f(a + v) - f(a) = \sum_{k=1}^n [f(p_k) - f(p_{k-1})], where pkp_k changes the first kk coordinates.
  2. f(p1)−f(a)=v1D1f(a)+r1f(p_1) - f(a) = v_1 D_1 f(a) + r_1 with ∣r1∣≤ε∣v1∣|r_1| \le \varepsilon |v_1|.
  3. For k≥2k \ge 2, f(pk)−f(pk−1)=vkDkf(ck)f(p_k) - f(p_{k-1}) = v_k D_k f(c_k).
  4. ∣Dkf(ck)−Dkf(a)∣<ε|D_k f(c_k) - D_k f(a)| < \varepsilon for ∥v∥\lVert v \rVert small.
  5. ∣f(a+v)−f(a)−∇f(a)⋅v∣≤nε∥v∥|f(a + v) - f(a) - \nabla f(a) \cdot v| \le n \varepsilon \lVert v \rVert.
Worked example new (the sharper theorem at work; compare 5.3, the field $(x^2 + y^2)\sin\frac1{x^2 + y^2}$)
Show that f(x,y)=(1+y2) x2sin⁡(1/x)f(x, y) = (1 + y^2)\,x^2\sin(1/x) for x≠0x \ne 0, f(0,y)=0f(0, y) = 0, is differentiable at the origin although it is not continuously differentiable there.

Solution.

  1. The partials. For x≠0x \ne 0: fx=(1+y2)(2xsin⁡1x−cos⁡1x)f_x = (1 + y^2)\big(2x\sin\frac1x - \cos\frac1x\big), fy=2y x2sin⁡1xf_y = 2y\,x^2\sin\frac1x. On the line x=0x = 0: fx(0,y)=lim⁡h→0(1+y2)h2sin⁡(1/h)h=0f_x(0, y) = \lim_{h \to 0}\frac{(1 + y^2)h^2\sin(1/h)}{h} = 0, and fy(0,y)=0f_y(0, y) = 0. Both partials exist at every point of the plane.
  2. fxf_x is not continuous at the origin. Along y=0y = 0 and x=12πnx = \frac1{2\pi n}, fx=−cos⁡(2πn)=−1f_x = -\cos(2\pi n) = -1, but fx(0,0)=0f_x(0, 0) = 0. So ff is not C1C^1 and the theorem of 5.3 does not apply.
  3. fyf_y is continuous at the origin. ∣fy(x,y)∣≤2∣y∣x2→0=fy(0,0)|f_y(x, y)| \le 2|y|x^2 \to 0 = f_y(0, 0). The sharper theorem needs D2f=fyD_2f = f_y continuous at the point, and D1f=fxD_1f = f_x only to exist.
  4. Apply the theorem. fxf_x exists in a ball around (0,0)(0, 0), fyf_y exists near it and is continuous at it, so ff is differentiable at (0,0)(0, 0) with total derivative v↦0v \mapsto 0. Direct check: ∣f(v)∣≤(1+y2)x2≤2∥v∥2|f(v)| \le (1 + y^2)x^2 \le 2\lVert v \rVert^2 for ∥v∥≤1\lVert v \rVert \le 1, so f(v)=∥v∥Ef(v) = \lVert v \rVert E with E→0E \to 0.

Answer. Differentiable at the origin, with ∇f=O\nabla f = O, while D1fD_1f is discontinuous there. The 5.3 test is sufficient and not necessary, and this example shows it can be sharpened but not reversed.

Worked example Apostol 8.24 #1
Apostol 8.24 #1. Find a scalar field ff with D1f(0,0)=D2f(0,0)=0D_1f(0, 0) = D_2f(0, 0) = 0 whose derivative at the origin in the direction of i+j\mathbf i + \mathbf j exists and equals 33. Explain why ff cannot be differentiable at the origin.

Solution.

  1. Try a homogeneous field of degree 1 vanishing on the axes. f(x,y)=3xy(x+y)x2+y2f(x, y) = \dfrac{3xy(x + y)}{x^2 + y^2}, f(0,0)=0f(0, 0) = 0. On the axes xy=0xy = 0, so f=0f = 0 there and both partials at the origin are 00.
  2. Direction (1,1)(1, 1). f(h,h)=3h⋅h⋅2h2h2=3hf(h, h) = \dfrac{3h\cdot h\cdot2h}{2h^2} = 3h, so f(h,h)−f(0)h=3\dfrac{f(h, h) - f(0)}{h} = 3 for every h≠0h \ne 0, and f′(0;(1,1))=3f'(0; (1, 1)) = 3. The limit is the constant 33.
  3. Why not differentiable. If ff were differentiable at OO, then by 5.3 f′(O;y)=∇f(O)⋅yf'(O; y) = \nabla f(O)\cdot y for every yy, which for y=(1,1)y = (1, 1) is 0+0=0≠30 + 0 = 0 \ne 3. The formula of 5.3 requires differentiability, and here it gives the wrong value.

Answer. f=3xy(x+y)x2+y2f = \dfrac{3xy(x + y)}{x^2 + y^2}. In a general direction (a,b)(a, b) the derivative is 3ab(a+b)a2+b2\dfrac{3ab(a + b)}{a^2 + b^2}, which exists but is not linear in (a,b)(a, b): the same warning as in 5.2.

Worked example Apostol 8.24 #3
Apostol 8.24 #3. Let f(x,y)=xy3x2+y6f(x, y) = \dfrac{xy^3}{x^2 + y^6} for (x,y)≠(0,0)(x, y) \ne (0, 0) and f(0,0)=0f(0, 0) = 0. Show that f′(0;a)f'(0; a) exists for every vector aa and find it, and decide whether ff is continuous at the origin.

Solution.

  1. Directions. For a=(a1,a2)a = (a_1, a_2): f(ha)=h4a1a23h2a12+h6a26f(ha) = \dfrac{h^4a_1a_2^3}{h^2a_1^2 + h^6a_2^6}, so f(ha)−f(0)h=h a1a23a12+h4a26\dfrac{f(ha) - f(0)}{h} = \dfrac{h\,a_1a_2^3}{a_1^2 + h^4a_2^6}. If a1≠0a_1 \ne 0 this tends to 00 as h→0h \to 0. If a1=0a_1 = 0, then f(ha)=0f(ha) = 0 for all hh. Divide numerator and denominator by h2h^2.
  2. Conclusion for directions. f′(0;a)=0f'(0; a) = 0 for every aa. Unlike the example of 5.2, this directional derivative is a linear function of aa (the zero function): the gradient is OO and f′(0;a)=∇f(0)⋅af'(0; a) = \nabla f(0)\cdot a for all aa.
  3. Continuity. Along the curve x=y3x = y^3: f(y3,y)=y3⋅y3y6+y6=12f(y^3, y) = \dfrac{y^3\cdot y^3}{y^6 + y^6} = \tfrac12, but f(0,0)=0f(0, 0) = 0. Points with f=12f = \frac12 come arbitrarily close to the origin.

Answer. f′(0;a)=0f'(0; a) = 0 for all aa, yet ff is not continuous at the origin, hence not differentiable. So even “all directional derivatives exist and equal ∇f⋅a\nabla f\cdot a” does not give differentiability: the approximation must be good along curves too, not only along lines.

How many partial derivatives are there?

In two variables a function has 2k2^k ordered ways to differentiate kk times. For a function of nn variables there are nkn^k ordered strings. We will prove that for CkC^k fields only the number of times each variable occurs matters. That is a choice of a multiset of size kk from nn variables, and the number of those is (n+k−1k)\binom{n + k - 1}{k} (put kk identical balls into nn boxes: kk balls and n−1n - 1 dividers in a row). For n=3n = 3, k=3k = 3 it is (53)=10\binom53 = 10 instead of 2727; for n=2n = 2, k=4k = 4 it is 55 instead of 1616.

Your answerHow many different third-order partial derivatives does a C3C^3 function of three variables have, once the order of differentiation does not matter?

A function whose mixed partials disagree

Before the theorem, the example it has to survive.

Worked example Apostol 8.23, 8.24 #2; Lecture 24 (the remark on continuity)
Let f(x,y)=xy(x2−y2)x2+y2f(x, y) = \dfrac{xy(x^2 - y^2)}{x^2 + y^2} for (x,y)≠(0,0)(x, y) \ne (0, 0) and f(0,0)=0f(0, 0) = 0. Compute fx(0,y)f_x(0, y) and fy(x,0)f_y(x, 0), and deduce fxy(0,0)f_{xy}(0, 0) and fyx(0,0)f_{yx}(0, 0).

Solution.

  1. fxf_x on the yy-axis, from the definition. For y≠0y \ne 0: f(h,y)−f(0,y)h=h y (h2−y2)(h2+y2) h=y(h2−y2)h2+y2→−y\dfrac{f(h, y) - f(0, y)}{h} = \dfrac{h\,y\,(h^2 - y^2)}{(h^2 + y^2)\,h} = \dfrac{y(h^2 - y^2)}{h^2 + y^2} \to -y as h→0h \to 0. At y=0y = 0, f(h,0)=0f(h, 0) = 0 so fx(0,0)=0=−0f_x(0, 0) = 0 = -0. f(0,y)=0f(0, y) = 0 for all yy, so the numerator is f(h,y)f(h, y) alone; cancel the hh. So fx(0,y)=−yf_x(0, y) = -y for every yy.
  2. fyf_y on the xx-axis. For x≠0x \ne 0: f(x,k)−f(x,0)k=x(x2−k2)x2+k2→x\dfrac{f(x, k) - f(x, 0)}{k} = \dfrac{x(x^2 - k^2)}{x^2 + k^2} \to x as k→0k \to 0, and fy(0,0)=0f_y(0, 0) = 0. Same computation with the roles swapped. So fy(x,0)=xf_y(x, 0) = x for every xx.
  3. Differentiate once more. fxy(0,0)=ddyfx(0,y)∣y=0=ddy(−y)=−1f_{xy}(0, 0) = \dfrac{d}{dy}f_x(0, y)\Big|_{y = 0} = \dfrac{d}{dy}(-y) = -1 and fyx(0,0)=ddxfy(x,0)∣x=0=ddx(x)=+1f_{yx}(0, 0) = \dfrac{d}{dx}f_y(x, 0)\Big|_{x = 0} = \dfrac{d}{dx}(x) = +1. fxyf_{xy} means (fx)y(f_x)_y: take fxf_x along the yy-axis, where we know it, and differentiate in yy. Likewise for fyxf_{yx}.
  4. Cross-check with the rectangle. Since f=0f = 0 on both axes, Δ(h,k)=f(h,k)\Delta(h, k) = f(h, k) and Δ/(hk)=h2−k2h2+k2\Delta/(hk) = \dfrac{h^2 - k^2}{h^2 + k^2}. Letting k→0k \to 0 first gives 11 (then h→0h \to 0: fyx(0,0)=1f_{yx}(0, 0) = 1), letting h→0h \to 0 first gives −1-1. Same two limits as in the picture.

Answer. fxy(0,0)=−1≠+1=fyx(0,0)f_{xy}(0, 0) = -1 \ne +1 = f_{yx}(0, 0) (Apostol: D2,1f(0,0)=−1D_{2,1}f(0, 0) = -1, D1,2f(0,0)=1D_{1,2}f(0, 0) = 1). The mixed partials exist at the origin and differ.

Your answerFor the function above, compute Δ(h,k)/(hk)\Delta(h, k)/(hk) at (h,k)=(3t,t)(h, k) = (3t, t) for any t≠0t \ne 0. (Give a decimal.)

What goes wrong? The second partials exist everywhere, but not as continuous functions.

Worked example Apostol 8.23 (the mixed partials 'are not both continuous at the origin')
For the same ff, find fxy(x,y)f_{xy}(x, y) at points (x,y)≠(0,0)(x, y) \ne (0, 0) and show it is not continuous at the origin; show also that ff is of class C1C^1.

Solution.

  1. Partials away from the origin. fx=y(x4+4x2y2−y4)(x2+y2)2f_x = \dfrac{y(x^4 + 4x^2y^2 - y^4)}{(x^2 + y^2)^2} and fy=x(x4−4x2y2−y4)(x2+y2)2f_y = \dfrac{x(x^4 - 4x^2y^2 - y^4)}{(x^2 + y^2)^2}. Quotient rule; verified symbolically.
  2. They are continuous at the origin. ∣x4+4x2y2−y4∣≤x4+4x2y2+y4=(x2+y2)2+2x2y2≤32(x2+y2)2|x^4 + 4x^2y^2 - y^4| \le x^4 + 4x^2y^2 + y^4 = (x^2 + y^2)^2 + 2x^2y^2 \le \tfrac32(x^2 + y^2)^2, so ∣fx∣≤32∣y∣→0=fx(0,0)|f_x| \le \tfrac32|y| \to 0 = f_x(0, 0), and likewise ∣fy∣≤32∣x∣|f_y| \le \tfrac32|x|. 2x2y2≤12(x2+y2)22x^2y^2 \le \frac12(x^2 + y^2)^2. So ff is C1C^1 on the plane.
  3. The mixed partial away from the origin. Differentiating fxf_x in yy gives fxy=(x2−y2)(x4+10x2y2+y4)(x2+y2)3f_{xy} = \dfrac{(x^2 - y^2)(x^4 + 10x^2y^2 + y^4)}{(x^2 + y^2)^3}, and differentiating fyf_y in xx gives the same expression, so fyx=fxyf_{yx} = f_{xy} there. Verified by computer algebra; the numerators agree.
  4. Along the axes. On the xx-axis (y=0y = 0): fxy=x2⋅x4x6=1f_{xy} = \dfrac{x^2\cdot x^4}{x^6} = 1. On the yy-axis (x=0x = 0): fxy=(−y2) y4y6=−1f_{xy} = \dfrac{(-y^2)\,y^4}{y^6} = -1. The limit of fxyf_{xy} at the origin depends on the direction: it does not exist.

Answer. fxyf_{xy} is not continuous at (0,0)(0, 0) (nor is fyxf_{yx}, which is the same function off the origin), and ff is C1C^1 but not C2C^2 there. In the next section’s theorem it is exactly this continuity that is missing.

Your answerFor the same ff, what is the limit of fxy(0,y)f_{xy}(0, y) as y→0y \to 0?
Quick checkBoth mixed partials of f=xy(x2−y2)x2+y2f = \frac{xy(x^2 - y^2)}{x^2 + y^2} exist at the origin and are different. What does this tell us?

Schwarz’s theorem

Everything in the picture comes from one identity about the rectangle.

Lemma A the argument of Apostol 8.23

The rectangle lemma

Let SS be open, fxf_x and fxy=(fx)yf_{xy} = (f_x)_y exist on SS, and the closed rectangle RR with opposite corners (a,b)(a, b) and (a+h,b+k)(a + h, b + k) (h,k≠0h, k \ne 0) lie in SS. Put Δ=f(a+h,b+k)−f(a+h,b)−f(a,b+k)+f(a,b)\Delta = f(a + h, b + k) - f(a + h, b) - f(a, b + k) + f(a, b). Then there is (ξ,η)(\xi, \eta) in the interior of RR with Δ=hk fxy(ξ,η)\Delta = hk\,f_{xy}(\xi, \eta). By the same argument with the roles of xx and yy swapped, if fyf_y and fyxf_{yx} exist on SS, then Δ=hk fyx(ξ′,η′)\Delta = hk\,f_{yx}(\xi', \eta') for some (ξ′,η′)(\xi', \eta') in the interior of RR.

In one lineIf fxf_x and fxyf_{xy} exist on an open set containing the rectangle with corners (a,b)(a, b) and (a+h,b+k)(a + h, b + k), then Δ(h,k)=hk fxy(ξ,η)\Delta(h, k) = hk\,f_{xy}(\xi, \eta) for some point (ξ,η)(\xi, \eta) strictly inside the rectangle.

Why it is trueIt converts a combination of four values of ff into a second derivative at an unknown interior point, which is how a limit of rectangles becomes a mixed partial.

ProofApostol 8.23
The idea: Group the four corners in pairs along vertical edges to get a one-variable function G with Delta equal to G(a + h) minus G(a). Mean value theorem in x, then mean value theorem in y.
Put G(x)=f(x,b+k)−f(x,b)G(x) = f(x, b + k) - f(x, b). Then Δ=G(a+h)−G(a)\Delta = G(a + h) - G(a) and G′(x)=fx(x,b+k)−fx(x,b)G'(x) = f_x(x, b + k) - f_x(x, b).
Pair the corners with the same xx-coordinate. GG is differentiable on the closed interval between aa and a+ha + h since fxf_x exists, so it is continuous there.
Δ=h G′(ξ)=h[fx(ξ,b+k)−fx(ξ,b)]\Delta = h\,G'(\xi) = h\big[f_x(\xi, b + k) - f_x(\xi, b)\big] for some ξ\xi strictly between aa and a+ha + h.
The mean value theorem for GG on the interval between aa and a+ha + h (1.4).
The bracket equals k fxy(ξ,η)k\,f_{xy}(\xi, \eta) for some η\eta strictly between bb and b+kb + k.
The function y↦fx(ξ,y)y \mapsto f_x(\xi, y) is differentiable between bb and b+kb + k with derivative fxy(ξ,y)f_{xy}(\xi, y) (this is what fxyf_{xy} means). Mean value theorem again.
Δ=hk fxy(ξ,η)\Delta = hk\,f_{xy}(\xi, \eta).
Combine the last two steps. For the second statement, swap xx and yy: use H(y)=f(a+h,y)−f(a,y)H(y) = f(a + h, y) - f(a, y), for which Δ=H(b+k)−H(b)\Delta = H(b + k) - H(b). ■\blacksquare
Theorem A Apostol Thm 8.12; Spagnolie Lecture 24

Equality of mixed partials (Schwarz, Clairaut)

Let S⊆R2S \subseteq \mathbb R^2 be open with (a,b)∈S(a, b) \in S, and suppose the partial derivatives fx,fy,fxy,fyxf_x, f_y, f_{xy}, f_{yx} exist on SS. If fxyf_{xy} and fyxf_{yx} are both continuous at the point (a,b)(a, b), then fxy(a,b)=fyx(a,b)f_{xy}(a, b) = f_{yx}(a, b).

In one lineIf fxf_x, fyf_y, fxyf_{xy}, fyxf_{yx} exist on an open set containing (a,b)(a, b) and fxyf_{xy} and fyxf_{yx} are both continuous at (a,b)(a, b), then fxy(a,b)=fyx(a,b)f_{xy}(a, b) = f_{yx}(a, b).

Why it is trueIt says that when the second derivatives behave (continuously), the order of differentiation does not matter, which makes the matrix of second derivatives symmetric and lets the spectral theorem decide the shape of a critical point.

ProofApostol 8.12; this is the picture above
The idea: Compute the same rectangle sum two ways with the rectangle lemma. Equate. Shrink the rectangle to the point and use continuity of both mixed partials.
Fix small h,k≠0h, k \ne 0 and let Δ=f(a+h,b+k)−f(a+h,b)−f(a,b+k)+f(a,b)\Delta = f(a + h, b + k) - f(a + h, b) - f(a, b + k) + f(a, b).
Choose a ball around (a,b)(a, b) inside SS, and take ∣h∣,∣k∣|h|, |k| small enough that the closed rectangle with corners (a,b)(a, b), (a+h,b+k)(a + h, b + k) lies in the ball. Then the rectangle lemma applies.
Δ=hk fxy(ξ,η)\Delta = hk\,f_{xy}(\xi, \eta) for some (ξ,η)(\xi, \eta) in the open rectangle.
Rectangle lemma, first form (needs fxf_x, fxyf_{xy}).
Δ=hk fyx(ξ′,η′)\Delta = hk\,f_{yx}(\xi', \eta') for some other point (ξ′,η′)(\xi', \eta') in the same open rectangle.
Rectangle lemma, second form (needs fyf_y, fyxf_{yx}).
So fxy(ξ,η)=fyx(ξ′,η′)f_{xy}(\xi, \eta) = f_{yx}(\xi', \eta').
Divide by hk≠0hk \ne 0.
Let (h,k)→(0,0)(h, k) \to (0, 0): fxy(a,b)=fyx(a,b)f_{xy}(a, b) = f_{yx}(a, b). ■\blacksquare
Both points lie within ∣h∣|h| and ∣k∣|k| of (a,b)(a, b), so they tend to (a,b)(a, b) as (h,k)→(0,0)(h, k) \to (0, 0); the left side tends to fxy(a,b)f_{xy}(a, b) and the right side to fyx(a,b)f_{yx}(a, b), by continuity at (a,b)(a, b) of each. A limit is unique.Only continuity at the single point (a, b) is used, not in a neighbourhood, and the proof needs both mixed partials.
Proof workshopRebuild the proof of Schwarz's theoremApostol 8.12

Tap the lines in the order a proof would write them. Each line can only use what is already above it.

    Theorem A Apostol Thm 8.13; Peano (1890)

    Peano's refinement of Schwarz's theorem

    Let fxf_x, fyf_y and fxyf_{xy} exist on an open set containing (a,b)(a, b), with fxyf_{xy} continuous at (a,b)(a, b). Then fyx(a,b)f_{yx}(a, b) exists and fyx(a,b)=fxy(a,b)f_{yx}(a, b) = f_{xy}(a, b).

    In one lineIf fxf_x, fyf_y and fxyf_{xy} exist on an open set containing (a,b)(a, b) and fxyf_{xy} is continuous at (a,b)(a, b), then fyx(a,b)f_{yx}(a, b) exists and equals fxy(a,b)f_{xy}(a, b).

    Why it is trueIt says only one of the two mixed partials needs to be continuous: the other is then forced to exist and to agree.

    ProofApostol 8.13 (the proof there is longer)
    The idea: The rectangle lemma gives the quotient Δ/(hk) as a value of the continuous function f_xy near the corner, so it is close to f_xy(a, b). Letting k go to zero turns the quotient into a difference quotient of f_y, which is the definition of f_yx.
    Choose δ\delta so that fxyf_{xy} is within ε\varepsilon of fxy(a,b)f_{xy}(a, b) on the δ\delta-ball.
    Let ε>0\varepsilon > 0. Continuity of fxyf_{xy} at (a,b)(a, b) gives δ>0\delta > 0 with ∣fxy(p)−fxy(a,b)∣<ε|f_{xy}(p) - f_{xy}(a, b)| < \varepsilon whenever ∥p−(a,b)∥<δ\lVert p - (a, b) \rVert < \delta.
    For 0<∣h∣,∣k∣<δ/20 < |h|, |k| < \delta/2: ∣Δ(h,k)hk−fxy(a,b)∣<ε\Big|\dfrac{\Delta(h, k)}{hk} - f_{xy}(a, b)\Big| < \varepsilon.
    Rectangle lemma: Δ(h,k)/(hk)=fxy(ξ,η)\Delta(h, k)/(hk) = f_{xy}(\xi, \eta) with (ξ,η)(\xi, \eta) inside the rectangle, which lies in the δ\delta-ball when ∣h∣,∣k∣<δ/2|h|, |k| < \delta/2.
    Fix hh and let k→0k \to 0: ∣fy(a+h,b)−fy(a,b)h−fxy(a,b)∣≤ε\Big|\dfrac{f_y(a + h, b) - f_y(a, b)}{h} - f_{xy}(a, b)\Big| \le \varepsilon for 0<∣h∣<δ/20 < |h| < \delta/2.
    fyf_y exists at (a+h,b)(a + h, b) and at (a,b)(a, b), so lim⁡k→0Δ(h,k)/k=fy(a+h,b)−fy(a,b)\lim_{k \to 0}\Delta(h, k)/k = f_y(a + h, b) - f_y(a, b) (definition of fyf_y applied to each of the two columns of Δ\Delta).
    So fyx(a,b)=lim⁡h→0fy(a+h,b)−fy(a,b)hf_{yx}(a, b) = \lim_{h \to 0}\dfrac{f_y(a + h, b) - f_y(a, b)}{h} exists and equals fxy(a,b)f_{xy}(a, b).
    Definition of the limit: the difference quotient of fyf_y at (a,b)(a, b) in the xx-direction is within ε\varepsilon of fxy(a,b)f_{xy}(a, b) for all small hh, for every ε\varepsilon. ■\blacksquare
    Corollary A Apostol 8.23 and Lecture 24

    Order does not matter for C^k fields

    Let ff be CkC^k on an open set SS. If two strings of kk differentiations (i1,…,ik)(i_1, \dots, i_k) and (j1,…,jk)(j_1, \dots, j_k) use each variable the same number of times, then Di1⋯Dikf=Dj1⋯DjkfD_{i_1}\cdots D_{i_k}f = D_{j_1}\cdots D_{j_k}f on SS. In particular for k=2k = 2 the matrix [DjDif][D_jD_if] of a C2C^2 field is symmetric.

    In one lineIf ff is of class CkC^k on an open set, then any two partial derivatives of order at most kk that differentiate the same number of times in each variable are equal; in particular the matrix of second partials of a C2C^2 field is symmetric.

    Why it is trueIt lets you write ∂3f∂x2∂y\dfrac{\partial^3f}{\partial x^2\partial y} without saying in what order, and it is the reason the third-order Taylor term has the coefficient 3 in 3Fxxyx2y3F_{xxy}x^2y.

    Proofstandard
    The idea: Any rearrangement of a string is a sequence of swaps of two neighbours. A swap of two neighbouring differentiations is Schwarz's theorem applied to the partial derivative that has already been taken, which still has two continuous derivatives.
    For two differentiations, DjDif=DiDjfD_jD_if = D_iD_jf by Schwarz’s theorem.
    k=2k = 2: every second partial of a C2C^2 field is continuous, so the hypotheses of Schwarz's theorem hold at every point (the first and second partials exist by C2C^2).
    For general kk, it suffices to show that swapping two adjacent differentiations does not change the result.
    Rearranging a list into another with the same entries is a product of swaps of adjacent entries.
    Let φ\varphi be the partial derivative applied before the two neighbours; it is of class C2C^2.
    Write the string as Di1⋯Dis−1 (DisDis+1) φD_{i_1}\cdots D_{i_{s-1}}\,(D_{i_s}D_{i_{s+1}})\,\varphi where φ=Dis+2⋯Dikf\varphi = D_{i_{s+2}}\cdots D_{i_k}f is the part applied first. This φ\varphi is a partial derivative of order k−s−1≤k−2k - s - 1 \le k - 2 of a CkC^k field, so it is C2C^2.
    So the two orders agree.
    Schwarz's theorem for φ\varphi: DisDis+1φ=Dis+1DisφD_{i_s}D_{i_{s+1}}\varphi = D_{i_{s+1}}D_{i_s}\varphi. The remaining outer differentiations are then applied to equal fields. ■\blacksquare
    Quick checkWhich hypothesis at (a,b)(a, b) guarantees fxy(a,b)=fyx(a,b)f_{xy}(a, b) = f_{yx}(a, b)?
    Quick checkHow many different fourth-order partial derivatives does a C4C^4 function of two variables have, once order does not matter?
    Worked example Apostol 8.9 #10 to #12 style
    Verify fxy=fyxf_{xy} = f_{yx} for f(x,y)=cos⁡(x2)/yf(x, y) = \cos(x^2)/y (with y≠0y \ne 0), and find fxyyf_{xyy}.

    Solution.

    1. xx first. fx=−2xsin⁡(x2)yf_x = -\dfrac{2x\sin(x^2)}{y}, then fxy=2xsin⁡(x2)y2f_{xy} = \dfrac{2x\sin(x^2)}{y^2}. Chain rule on cos⁡(x2)\cos(x^2); then differentiate y−1y^{-1}.
    2. yy first. fy=−cos⁡(x2)y2f_y = -\dfrac{\cos(x^2)}{y^2}, then fyx=2xsin⁡(x2)y2f_{yx} = \dfrac{2x\sin(x^2)}{y^2}. The xx-derivative of cos⁡(x2)\cos(x^2) is −2xsin⁡(x2)-2x\sin(x^2), and there is an extra minus sign from −cos⁡-\cos.
    3. Third order. fxyy=∂y(2xsin⁡(x2)y2)=−4xsin⁡(x2)y3f_{xyy} = \partial_y\Big(\dfrac{2x\sin(x^2)}{y^2}\Big) = -\dfrac{4x\sin(x^2)}{y^3}. The other orders fyxyf_{yxy} and fyyxf_{yyx} give the same by the corollary; for instance fyy=2cos⁡(x2)y3f_{yy} = \frac{2\cos(x^2)}{y^3} and ∂x\partial_x of it is −4xsin⁡(x2)y3-\frac{4x\sin(x^2)}{y^3}.

    Answer. fxy=fyx=2xsin⁡(x2)y2f_{xy} = f_{yx} = \dfrac{2x\sin(x^2)}{y^2} and fxyy=fyyx=−4xsin⁡(x2)y3f_{xyy} = f_{yyx} = -\dfrac{4x\sin(x^2)}{y^3}. The function is C∞C^\infty for y≠0y \ne 0, so the theorem applies at every point.

    Your answerFor f(x,y)=x2y3f(x, y) = x^2y^3, what is fxy(1,2)f_{xy}(1, 2)?

    Gradient fields and the necessary condition

    Suppose a vector field g=(g1,g2)g = (g_1, g_2) is the gradient of some C2C^2 function ff: g1=fxg_1 = f_x, g2=fyg_2 = f_y. Then D2g1=fxyD_2g_1 = f_{xy} and D1g2=fyxD_1g_2 = f_{yx}, which are equal by Schwarz’s theorem. So D2g1=D1g2D_2g_1 = D_1g_2 is a necessary condition for gg to be a gradient. (Clairaut used exactly this equality in 1740, to find a condition that P dx+Q dyP\,dx + Q\,dy must satisfy to be the differential of a function.)

    Worked example Practice Final 2013, problem 11; Apostol 8.12 and 9.1
    Practice Final 2013, extra credit. Suppose g:R2→R2g: \mathbb R^2 \to \mathbb R^2 is C1C^1. Is gg necessarily the gradient of some scalar field? Test g=(2xy+3, x2−1)g = (2xy + 3,\ x^2 - 1) and g=(−y,x)g = (-y, x).

    Solution.

    1. Necessary condition. If g=∇fg = \nabla f with ff of class C2C^2, then D2g1=D1g2D_2g_1 = D_1g_2. Both are fxy=fyxf_{xy} = f_{yx}.
    2. Test g=(−y,x)g = (-y, x). D2g1=−1D_2g_1 = -1 and D1g2=+1D_1g_2 = +1. They differ, so gg is not a gradient. It is the swirl field of 5.1; going once around the origin with it never returns to the same height.
    3. Test g=(2xy+3,x2−1)g = (2xy + 3, x^2 - 1). D2g1=2x=D1g2D_2g_1 = 2x = D_1g_2. The condition holds. It is necessary, not yet sufficient.
    4. Find the potential. Integrate fx=2xy+3f_x = 2xy + 3 in xx: f=x2y+3x+c(y)f = x^2y + 3x + c(y). Then fy=x2+c′(y)f_y = x^2 + c'(y) must equal x2−1x^2 - 1, so c′=−1c' = -1, c=−yc = -y (plus a constant). So f=x2y+3x−yf = x^2y + 3x - y. The condition made the xx-dependence of c′c' cancel, which is exactly what the integration needed.

    Answer. No: a C1C^1 field need not be a gradient, since D2g1=D1g2D_2g_1 = D_1g_2 can fail. For g=(2xy+3,x2−1)g = (2xy + 3, x^2 - 1) the answer is yes, f=x2y+3x−yf = x^2y + 3x - y.

    Your answerThe field g=(2xy+3, x2−1)g = (2xy + 3,\ x^2 - 1) is the gradient of a function ff with f(0,0)=0f(0, 0) = 0. What is f(1,2)f(1, 2)?
    Beyond the course: for understanding· The condition is sufficient on a rectangle, and not on a punctured plane

    For a C1C^1 field on a rectangle or a disc centred at the origin (a region where the path from (0,0)(0, 0) along the xx-axis and then straight up stays inside), D2g1=D1g2D_2g_1 = D_1g_2 is also sufficient: f(x,y)=∫0xg1(t,0) dt+∫0yg2(x,s) dsf(x, y) = \int_0^xg_1(t, 0)\,dt + \int_0^yg_2(x, s)\,ds has fy=g2f_y = g_2 and, differentiating under the integral and using the condition, fx=g1(x,0)+∫0yD2g1(x,s) ds=g1(x,y)f_x = g_1(x, 0) + \int_0^yD_2g_1(x, s)\,ds = g_1(x, y). On the punctured plane it fails. The field g=(−y,x)x2+y2g = \dfrac{(-y, x)}{x^2 + y^2} satisfies D2g1=D1g2=y2−x2(x2+y2)2D_2g_1 = D_1g_2 = \dfrac{y^2 - x^2}{(x^2 + y^2)^2} everywhere defined, but it is the gradient of the angle θ\theta, which cannot be defined as a single-valued function on the whole punctured plane (the angle grows by 2π2\pi as you walk once around the origin). Whether the necessary condition is sufficient depends on the shape of the domain: that is the beginning of de Rham cohomology (MATH 551 and beyond).

    Where this came from· From Euler and Clairaut to Schwarz

    In 1740 both Euler and Clairaut published a proposed proof that the order of differentiation does not matter. Clairaut’s use for it was the question of when an expression P dx+Q dyP\,dx + Q\,dy comes from a function: he showed that Py=QxP_y = Q_x is then needed. Those arguments were not rigorous. Lagrange gave a proof in 1797, which Cauchy improved in 1823, though it still assumed that the pure second partials fxxf_{xx} and fyyf_{yy} exist and are continuous; further proofs in the 1840s to 1860s were incomplete, and in 1867 Lindelöf gave an explicit example in which the two mixed partials are unequal. Hermann Schwarz gave the first rigorous proof in 1873. Giuseppe Peano’s short note of 1890 improved the theorem to the form of this chapter (Apostol’s 8.13: one mixed partial continuous forces the other to exist and agree). The function xy(x2−y2)x2+y2\frac{xy(x^2 - y^2)}{x^2 + y^2} is the standard example, usually called Peano’s. The problem all of them were solving was how to recognise a gradient, and the answer, equality of mixed partials, turned out to need a hypothesis that nobody had thought to state.

    Where it is used

    Used inside maths· Inside maths: a symmetric Hessian, and the shape of the next chapter

    For a C2C^2 field the matrix H=[DjDif]H = [D_jD_if] of second partials is symmetric, so the spectral theorem (3.1) gives it real eigenvalues and orthogonal eigenvectors, and its quadratic form vTHvv^{\mathsf T}Hv can be put in the form ∑λiwi2\sum\lambda_iw_i^2 by a rotation (3.2). That is the entire plan of 5.6: the second-order Taylor formula uses vTHvv^{\mathsf T}Hv, and the sign of that form, read off from the eigenvalues, decides whether a critical point is a maximum, a minimum or a saddle. The Taylor coefficients of order kk in nn variables are the (n+k−1k)\binom{n + k - 1}{k} distinct partials of order kk, each counted with the number of orderings that give it (the factor 33 in 3Fxxyx2y3F_{xxy}x^2y of Lecture 24 is 33 orderings of x,x,yx, x, y). And equality of mixed partials is what let 5.4 collect fxy+fyxf_{xy} + f_{yx} into 2fxy2f_{xy} in the wave-equation and Laplace computations.

    Used in the real world· Physics and AI: Maxwell's relations, and the cost of a Hessian

    In thermodynamics the Helmholtz free energy F(T,V)F(T, V) of a gas has dF=−S dT−p dVdF = -S\,dT - p\,dV, which says S=−FTS = -F_T and p=−FVp = -F_V. Equality of the mixed partials of FF gives the Maxwell relation (∂S∂V)T=(∂p∂T)V\big(\frac{\partial S}{\partial V}\big)_T = \big(\frac{\partial p}{\partial T}\big)_V. Entropy cannot be measured with an instrument, but pressure against temperature at fixed volume can. For one mole of an ideal gas, p=RT/Vp = RT/V, so (∂p∂T)V=R/V\big(\frac{\partial p}{\partial T}\big)_V = R/V; the relation then gives (∂S∂V)T=R/V\big(\frac{\partial S}{\partial V}\big)_T = R/V, and doubling the volume at constant temperature raises the entropy by Rln⁡2=8.314×0.693≈5.76 J/KR\ln2 = 8.314\times0.693 \approx 5.76\ \text{J/K}. At V=0.025 m3V = 0.025\ \text{m}^3 the slope is R/V=332.6 Pa/KR/V = 332.6\ \text{Pa/K}. In machine learning, the loss of a model with n=106n = 10^6 weights has n2=1012n^2 = 10^{12} second partials, but only n(n+1)/2≈5×1011n(n + 1)/2 \approx 5\times10^{11} distinct ones because of this chapter’s theorem, which at 8 bytes each is still about 4 terabytes. That is why second-order methods never form the Hessian. They compute only the product HvHv of the Hessian with a vector. It is the derivative in tt of ∇f(x+tv)\nabla f(x + tv), which two gradient evaluations approximate and automatic differentiation computes exactly for a small multiple of the cost of one gradient. Reading it as the gradient of the scalar ∇f⋅v\nabla f\cdot v uses the symmetry of HH: that gradient is HTvH^{\mathsf T}v, which equals HvHv by this chapter’s theorem.

    Python labTwo limits that do not commute
    import numpy as np
    
    def peano(x, y):
        d = x**2 + y**2
        return 0.0 if d == 0 else x * y * (x**2 - y**2) / d
    
    def smooth(x, y):
        return x**2 * y + np.sin(x * y)
    
    def Q(f, h, k):                       # the rectangle quotient Delta(h, k) / (h k)
        return (f(h, k) - f(h, 0) - f(0, k) + f(0, 0)) / (h * k)
    
    for name, f in [("smooth", smooth), ("Peano ", peano)]:
        print(name)
        print("  k -> 0 first (k = h/10^4), then h:", [round(Q(f, h, h * 1e-4), 4) for h in (1e-1, 1e-2, 1e-3)])
        print("  h -> 0 first (h = k/10^4), then k:", [round(Q(f, k * 1e-4, k), 4) for k in (1e-1, 1e-2, 1e-3)])
        print("  along the diagonal h = k:         ", [round(Q(f, t, t), 4) for t in (1e-1, 1e-2, 1e-3)])
        print("  along the direction (3, 1):       ", [round(Q(f, 3 * t, t), 4) for t in (1e-1, 1e-2, 1e-3)])
    
    # the mixed partials at the origin: finite differences of finite differences
    h = 1e-5
    fx = lambda f, x, y: (f(x + h, y) - f(x - h, y)) / (2 * h)
    fy = lambda f, x, y: (f(x, y + h) - f(x, y - h)) / (2 * h)
    for name, f in [("smooth", smooth), ("Peano ", peano)]:
        s = 1e-3
        fxy = (fx(f, 0, s) - fx(f, 0, -s)) / (2 * s)      # x first, then y
        fyx = (fy(f, s, 0) - fy(f, -s, 0)) / (2 * s)      # y first, then x
        print(name, "f_xy(0,0) ~", round(fxy, 4), "  f_yx(0,0) ~", round(fyx, 4))

    Try this. Run it. For the smooth function all four ways of shrinking the rectangle approach 1 (the direction (3, 1) gives 1.3, 1.03, 1.003): 1.1, 1.01, 1.001 along the first row, 1.0 along the second, and so on. For Peano's function the answers are +1, -1, 0 and 0.8, one for each way, and they do not move as the rectangle shrinks. The last two lines compute the mixed partials at the origin by finite differences of finite differences: for the smooth function f_xy and f_yx both come out 1; for Peano's function about -1 for f_xy and about +1 for f_yx. Change the direction (3, 1) to (1, 0.1) and check Q = (1 - 0.01)/(1 + 0.01) = 0.9802.

    Traps

    Watch out· Which order does the notation mean?

    ∂2f∂x ∂y\dfrac{\partial^2f}{\partial x\,\partial y} means differentiate in yy first, then in xx (the operator closest to ff acts first). The subscript fxyf_{xy} means xx first, then yy (this book, reading left to right). Apostol’s D1,2f=D1(D2f)D_{1,2}f = D_1(D_2f) is yy first. The same symbol reads in opposite orders in different books. For a C2C^2 function the difference is invisible, which is why the confusion survives; at Peano’s origin it flips the sign.

    Watch out· Both mixed partials existing does not make them equal

    At the origin, Peano’s function has fxy=−1f_{xy} = -1 and fyx=+1f_{yx} = +1, both existing. Schwarz’s theorem needs continuity of the second partials at the point (both, or one by Peano’s refinement). “Exist” is not enough.

    Watch out· Equal mixed partials do not mean continuous

    The converse of Schwarz’s theorem is false too: a function can have fxy=fyxf_{xy} = f_{yx} at a point without the second partials being continuous there. Equality is a consequence of a hypothesis, not a test for it.

    Watch out· C^1 does not give second derivatives

    A C1C^1 field has first partials that are continuous; they need not be differentiable. The function x∣x∣x|x| is C1C^1 and has no second derivative at 00. All the theorems of this chapter about second partials assume C2C^2, or at least the existence of the second partials.

    Watch out· Count distinct partials with the right formula

    For a CkC^k field of nn variables there are (n+k−1k)\binom{n + k - 1}{k} distinct partials of order kk, not nkn^k and not (nk)\binom nk. Three variables, third order: 1010, not 2727 and not 11.

    Problems

    checkApostol 8.9 #10 (MATH 375 HW 11)

    Compute fxyf_{xy} and fyxf_{yx} for f(x,y)=x4+y4−4x2y2f(x, y) = x^4 + y^4 - 4x^2y^2.

    Solution

    fx=4x3−8xy2f_x = 4x^3 - 8xy^2, so fxy=−16xyf_{xy} = -16xy. fy=4y3−8x2yf_y = 4y^3 - 8x^2y, so fyx=−16xyf_{yx} = -16xy. Equal, as a polynomial is C∞C^\infty.

    check

    How many distinct second-order partials does a C2C^2 function of 4 variables have? How many distinct fifth-order partials does a C5C^5 function of 2 variables have?

    Solution

    Second order, 4 variables: (4+2−12)=(52)=10\binom{4 + 2 - 1}{2} = \binom52 = 10 (that is n(n+1)/2n(n + 1)/2 with n=4n = 4). Fifth order, 2 variables: (2+5−15)=(65)=6\binom{2 + 5 - 1}{5} = \binom65 = 6: fx5,fx4y,…,fy5f_{x^5}, f_{x^4y}, \dots, f_{y^5}.

    checkPractice Final 2013, extra credit (the necessary condition)

    Is g(x,y)=(y2, x2)g(x, y) = (y^2,\ x^2) the gradient of a C2C^2 function? Is g(x,y)=(x2, y2)g(x, y) = (x^2,\ y^2)?

    Solution

    For (y2,x2)(y^2, x^2): D2g1=2yD_2g_1 = 2y and D1g2=2xD_1g_2 = 2x, which differ (for example at (1,0)(1, 0): 00 against 22), so it is not a gradient. For (x2,y2)(x^2, y^2): D2g1=0=D1g2D_2g_1 = 0 = D_1g_2, and indeed it is ∇(x3+y33)\nabla\big(\frac{x^3 + y^3}{3}\big).

    checkApostol 8.24 #2 (the same function)

    For Peano’s function, state fx(0,0)f_x(0, 0), fy(0,0)f_y(0, 0), fxy(0,0)f_{xy}(0, 0) and fyx(0,0)f_{yx}(0, 0) and say which hypothesis of Schwarz’s theorem fails.

    Solution

    fx(0,0)=fy(0,0)=0f_x(0, 0) = f_y(0, 0) = 0 (since ff vanishes on both axes), fxy(0,0)=−1f_{xy}(0, 0) = -1 and fyx(0,0)=+1f_{yx}(0, 0) = +1. The second partials exist but are not continuous at (0,0)(0, 0): fxyf_{xy} tends to 11 along the xx-axis and to −1-1 along the yy-axis. Both continuity hypotheses fail (and by Peano’s refinement, so does the hypothesis on fxyf_{xy} alone).

    useApostol 8.14 #10 style, with 5.4

    Let ff be C2C^2 and let g(t)=f(t,t2)g(t) = f(t, t^2). Find g′′(t)g''(t) in terms of the partials of ff, and evaluate at t=1t = 1 for f=x2y+xy3f = x^2y + xy^3.

    Solution

    By the second-derivative rule of 5.4 with r=(t,t2)r = (t, t^2), r′=(1,2t)r' = (1, 2t), r′′=(0,2)r'' = (0, 2): g′′=fxx+4t fxy+4t2fyy+2fyg'' = f_{xx} + 4t\,f_{xy} + 4t^2f_{yy} + 2f_y (using fxy=fyxf_{xy} = f_{yx}). For f=x2y+xy3f = x^2y + xy^3: fxx=2yf_{xx} = 2y, fxy=2x+3y2f_{xy} = 2x + 3y^2, fyy=6xyf_{yy} = 6xy, fy=x2+3xy2f_y = x^2 + 3xy^2. At (1,1)(1, 1): g′′(1)=2+4⋅5+4⋅6+2⋅4=54g''(1) = 2 + 4\cdot5 + 4\cdot6 + 2\cdot4 = 54. Check: g=t2⋅t2+t⋅t6=t4+t7g = t^2\cdot t^2 + t\cdot t^6 = t^4 + t^7, g′′=12t2+42t5g'' = 12t^2 + 42t^5, which at t=1t = 1 is 5454. ✓

    use

    Find a function ff with fx=2xy2+cos⁡xf_x = 2xy^2 + \cos x and fy=2x2y+1f_y = 2x^2y + 1, or show there is none.

    Solution

    Test: D2(2xy2+cos⁡x)=4xyD_2(2xy^2 + \cos x) = 4xy and D1(2x2y+1)=4xyD_1(2x^2y + 1) = 4xy. Equal, so a potential may exist. Integrate fxf_x in xx: f=x2y2+sin⁡x+c(y)f = x^2y^2 + \sin x + c(y). Then fy=2x2y+c′(y)f_y = 2x^2y + c'(y) must equal 2x2y+12x^2y + 1, so c=yc = y. Hence f=x2y2+sin⁡x+yf = x^2y^2 + \sin x + y (plus a constant).

    use

    Show that f(x,y)=x3yx2+y2f(x, y) = \dfrac{x^3y}{x^2 + y^2}, f(0,0)=0f(0, 0) = 0, is differentiable at the origin, find its gradient there, and find fxy(0,0)f_{xy}(0, 0) and fyx(0,0)f_{yx}(0, 0). Is ff of class C2C^2?

    Solution

    ∣f∣≤∣x∣⋅x2∣y∣x2+y2≤∣x∣∣y∣≤12∥v∥2|f| \le \dfrac{|x|\cdot x^2|y|}{x^2 + y^2} \le |x||y| \le \frac12\lVert v \rVert^2, so f(v)=∥v∥E(v)f(v) = \lVert v \rVert E(v) with E→0E \to 0: differentiable at OO with ∇f(O)=O\nabla f(O) = O. Away from the origin fx=y(3x2(x2+y2)−2x4)(x2+y2)2=y x2(x2+3y2)(x2+y2)2f_x = \dfrac{y(3x^2(x^2 + y^2) - 2x^4)}{(x^2 + y^2)^2} = \dfrac{y\,x^2(x^2 + 3y^2)}{(x^2 + y^2)^2} and fy=x3(x2−y2)(x2+y2)2f_y = \dfrac{x^3(x^2 - y^2)}{(x^2 + y^2)^2}. On the yy-axis fx(0,y)=0f_x(0, y) = 0, so fxy(0,0)=0f_{xy}(0, 0) = 0. On the xx-axis fy(x,0)=xf_y(x, 0) = x, so fyx(0,0)=1f_{yx}(0, 0) = 1. They differ, so ff is not C2C^2 at the origin.

    provenew (uses 5.4)

    Prove that if ff is C2C^2 on R2\mathbb R^2 and fxy≡0f_{xy} \equiv 0, then f(x,y)=φ(x)+ψ(y)f(x, y) = \varphi(x) + \psi(y) for some functions φ,ψ\varphi, \psi.

    Solution

    Plan. fxf_x has zero yy-derivative, so fxf_x depends on xx alone; integrate in xx.

    ∂y(fx)=fxy=0\partial_y(f_x) = f_{xy} = 0 on all of R2\mathbb R^2, so for each fixed xx the function y↦fx(x,y)y \mapsto f_x(x, y) has derivative 00 on R\mathbb R and is constant (1.4): fx(x,y)=α(x)f_x(x, y) = \alpha(x), where α(x)=fx(x,0)\alpha(x) = f_x(x, 0). Let φ\varphi be an antiderivative of α\alpha (it exists since α\alpha is continuous). Then ∂x(f−φ(x))=0\partial_x\big(f - \varphi(x)\big) = 0, so for each fixed yy the function x↦f(x,y)−φ(x)x \mapsto f(x, y) - \varphi(x) is constant: f(x,y)=φ(x)+ψ(y)f(x, y) = \varphi(x) + \psi(y) with ψ(y)=f(0,y)−φ(0)\psi(y) = f(0, y) - \varphi(0). ■\blacksquare

    proveApostol 8.9 #20 and #21(b)

    Let SS be an open convex set (the segment between any two of its points lies in SS). Prove that if f′(x;y)=0f'(x; y) = 0 for every x∈Sx \in S and every yy, then ff is constant on SS. (Hint: the mean value theorem for scalar fields from 5.2.)

    Solution

    Plan. Join two points by a segment and apply the mean value theorem of 5.2 on it.

    Let p,q∈Sp, q \in S and y=q−py = q - p. The segment {p+ty:0≤t≤1}\{p + ty : 0 \le t \le 1\} lies in SS by convexity. By the mean value theorem for scalar fields (5.2, Apostol 8.4), f(q)−f(p)=f′(z;y)f(q) - f(p) = f'(z; y) for some zz on the segment. By hypothesis f′(z;y)=0f'(z; y) = 0, so f(q)=f(p)f(q) = f(p). Since p,qp, q were arbitrary, ff is constant. ■\blacksquare (Every ball is convex, because ∥tp+(1−t)q−a∥≤t∥p−a∥+(1−t)∥q−a∥<r\lVert tp + (1 - t)q - a \rVert \le t\lVert p - a \rVert + (1 - t)\lVert q - a \rVert < r, which recovers the ball case of 5.2.)

    prove

    Prove that if ff is C3C^3 then fxyx=fxxy=fyxxf_{xyx} = f_{xxy} = f_{yxx} (in the book’s order: the first letter is the first differentiation).

    Solution

    Plan. Swap neighbours one at a time, each swap being Schwarz’s theorem for a C2C^2 field.

    In operator form fxyx=DxDyDxff_{xyx} = D_xD_yD_xf, fxxy=DyDxDxff_{xxy} = D_yD_xD_xf and fyxx=DxDxDyff_{yxx} = D_xD_xD_yf. Put φ=Dxf\varphi = D_xf, which is C2C^2. Schwarz’s theorem for φ\varphi gives DxDyφ=DyDxφD_xD_y\varphi = D_yD_x\varphi, that is, fxyx=fxxyf_{xyx} = f_{xxy}. Schwarz’s theorem for ff gives DxDyf=DyDxfD_xD_yf = D_yD_xf everywhere; apply DxD_x to both sides: DxDxDyf=DxDyDxfD_xD_xD_yf = D_xD_yD_xf, that is, fyxx=fxyxf_{yxx} = f_{xyx}. ■\blacksquare (In general, any two orders with the same counts agree: this is the corollary.)

    provenew (a necessary condition)

    Prove that if g=(g1,…,gn)g = (g_1, \dots, g_n) is the gradient of a C2C^2 scalar field, then Djgi=DigjD_jg_i = D_ig_j for all i,ji, j; equivalently, the Jacobian matrix of gg is symmetric.

    Solution

    Plan. Write the entries as second partials of ff and apply Schwarz’s theorem.

    If g=∇fg = \nabla f, then gi=Difg_i = D_if, so Djgi=DjDifD_jg_i = D_jD_if and Digj=DiDjfD_ig_j = D_iD_jf. These are second partials of a C2C^2 field, and equal by Schwarz’s theorem. The (i,j)(i, j) entry of the Jacobian is DjgiD_jg_i and the (j,i)(j, i) entry is DigjD_ig_j, so the Jacobian is symmetric. ■\blacksquare

    stretchnew (the picture of this chapter as a theorem)

    Let fxf_x and fxyf_{xy} exist near (a,b)(a, b) with fxyf_{xy} continuous at (a,b)(a, b). Prove that the double limit lim⁡(h,k)→(0,0)Δ(h,k)hk\displaystyle\lim_{(h, k) \to (0, 0)}\frac{\Delta(h, k)}{hk} exists and equals fxy(a,b)f_{xy}(a, b). Deduce that for Peano’s function fxyf_{xy} cannot be continuous at the origin.

    Solution

    Plan. The rectangle lemma writes the quotient as a value of fxyf_{xy} at a point of the rectangle.

    For small h,k≠0h, k \ne 0 the lemma gives Δ(h,k)/(hk)=fxy(ξ,η)\Delta(h, k)/(hk) = f_{xy}(\xi, \eta) with (ξ,η)(\xi, \eta) within ∣h∣|h| and ∣k∣|k| of (a,b)(a, b). Given ε>0\varepsilon > 0, continuity of fxyf_{xy} at (a,b)(a, b) gives δ\delta with ∣fxy(p)−fxy(a,b)∣<ε|f_{xy}(p) - f_{xy}(a, b)| < \varepsilon for ∥p−(a,b)∥<δ\lVert p - (a, b) \rVert < \delta, so ∣Δ/(hk)−fxy(a,b)∣<ε|\Delta/(hk) - f_{xy}(a, b)| < \varepsilon whenever h2+k2<δ/2\sqrt{h^2 + k^2} < \delta/2. ■\blacksquare For Peano’s function Δ/(hk)=h2−k2h2+k2\Delta/(hk) = \frac{h^2 - k^2}{h^2 + k^2} is 00 along h=kh = k and 0.80.8 along (3t,t)(3t, t), so the double limit does not exist; by the theorem fxyf_{xy} is therefore not continuous at the origin, which we also saw directly.

    stretch

    Let ff be C2C^2 on a disc. Show that the second derivative of ff in the direction of a unit vector u=(cos⁡θ,sin⁡θ)u = (\cos\theta, \sin\theta), defined as d2dt2f(a+tu)∣t=0\dfrac{d^2}{dt^2}f(a + tu)\big|_{t = 0}, equals fxxcos⁡2θ+2fxysin⁡θcos⁡θ+fyysin⁡2θf_{xx}\cos^2\theta + 2f_{xy}\sin\theta\cos\theta + f_{yy}\sin^2\theta. For which θ\theta is it largest, and what is that largest value in terms of the matrix [fxxfxyfxyfyy]\begin{bmatrix}f_{xx} & f_{xy}\\ f_{xy} & f_{yy}\end{bmatrix}?

    Solution

    By the second-derivative rule along a path (5.4) with r(t)=a+tur(t) = a + tu, r′=ur' = u, r′′=Or'' = O: d2dt2f(a+tu)=uTHu\frac{d^2}{dt^2}f(a + tu) = u^{\mathsf T}Hu with HH the matrix of second partials, which is the displayed formula (using fxy=fyxf_{xy} = f_{yx}). By the spectral theorem (HH is symmetric), the maximum of uTHuu^{\mathsf T}Hu over unit vectors is the largest eigenvalue of HH, attained at the corresponding eigenvector (3.2). So the direction of greatest curvature is an eigenvector of the largest eigenvalue, and the greatest curvature is that eigenvalue. This is the idea of 5.6.

    Summary

    • A higher-order partial derivative is a partial derivative of a partial derivative; a mixed one differentiates in at least two different variables. A field is of class CkC^k if all partials of order at most kk exist and are continuous. C1C^1 implies differentiable (5.3), and C2C^2 makes the gradient differentiable with the matrix of second partials as its Jacobian.
    • Sharpening 5.3. Existence of all partials near aa with n−1n - 1 of them continuous at aa already gives differentiability at aa (proved with the mean value theorem on one coordinate at a time). It is still sufficient and not necessary.
    • Schwarz’s theorem. If fx,fy,fxy,fyxf_x, f_y, f_{xy}, f_{yx} exist near (a,b)(a, b) and fxy,fyxf_{xy}, f_{yx} are continuous at (a,b)(a, b), then fxy(a,b)=fyx(a,b)f_{xy}(a, b) = f_{yx}(a, b). Proof: the rectangle sum Δ\Delta equals hk fxyhk\,f_{xy} at one interior point and hk fyxhk\,f_{yx} at another (mean value theorem twice, in two orders), so the two values get close as the rectangle shrinks. Peano’s refinement: continuity of one mixed partial forces the other to exist and agree.
    • The counterexample. f=xy(x2−y2)x2+y2f = \frac{xy(x^2 - y^2)}{x^2 + y^2} has fx(0,y)=−yf_x(0, y) = -y and fy(x,0)=xf_y(x, 0) = x, hence fxy(0,0)=−1≠+1=fyx(0,0)f_{xy}(0, 0) = -1 \ne +1 = f_{yx}(0, 0). It is C1C^1 and not C2C^2: fxyf_{xy} tends to 11 along the xx-axis and to −1-1 along the yy-axis. The rectangle quotient Δhk=h2−k2h2+k2\frac{\Delta}{hk} = \frac{h^2 - k^2}{h^2 + k^2} depends on direction only.
    • Order does not matter for CkC^k fields; the number of distinct partials of order kk in nn variables is (n+k−1k)\binom{n + k - 1}{k}. The matrix of second partials of a C2C^2 field is symmetric, so the spectral theorem applies to it (5.6).
    • Gradient fields. Djgi=DigjD_jg_i = D_ig_j is necessary for gg to be a gradient (Practice Final extra credit: (−y,x)(-y, x) is not one) and sufficient on a rectangle or disc, though not on the punctured plane.

    Watch and read

    The same ideas explained by someone else. Use these when an explanation here does not land.

    Where this sits

    Comes from
    1.4 The derivative as best linear approximation
    5.2 Directional derivatives, partial derivatives and the gradient
    5.3 The total derivative, the Jacobian matrix and tangent planes
    5.4 The chain rule for fields
    Leads to
    5.6 Taylor's formula, the Hessian and extrema
    Same idea elsewhere
    MATH 375: Lecture 24 writes 'F_xy = F_yx if they are continuous (so H = H^T)' and uses it to make the Hessian symmetric; Apostol proves it in 8.23 and the 2013 practice final used it in the extra-credit problem about gradient fields. Homework 11 (8.9 #10 to #12) checked it on examples. Apostol's Theorems 8.12 and 8.13 and his counterexample are proved in full here, as is the sufficiency theorem 8.13 of 5.3 in its sharper form.
    MATH 521: 521 proves Schwarz's theorem for functions of two variables with the same rectangle argument, then Fubini-type theorems (interchanging two limits or two integrals), which need the same kind of hypothesis. The Peano example is the standard example of two limits that do not commute.
    MATH 340 / CS 532: A loss function with continuous second derivatives has a symmetric Hessian, so Newton and quasi-Newton methods store n(n+1)/2 numbers and use the spectral theorem. The Hessian-vector product, computed without forming the Hessian, relies on this symmetry.
    Physics: Thermodynamics' Maxwell relations are the equality of mixed partials of an energy function; they turn quantities that are hard to measure (entropy changes) into ones that are easy (pressure against temperature).