Search

Search papers and lessons

Functional Derivative

Level 3 · 11 min read

A functional derivative is how much a total quantity, such as an integral of a function, changes when the whole function is nudged; it is the directional derivative in function space.

On this page

  • Colour = topic mix
  • Calculus
  • Discrete math
  • Linear algebra
  • Optimization
  • ReadReady to readNot yet

TL;DR

A functional derivative tells you how a total quantity changes when you nudge the whole function it depends on, not a single number. Take a functional J[f]J[f], such as the integral of f(x)2f(x)^2 over [0,1][0,1]. Its functional derivative is a function g(x)g(x) with one property: the first-order change in JJ equals ∫g(x) η(x) dx\int g(x)\,\eta(x)\,dx for any small wiggle η\eta added to ff. It is the directional derivative idea carried into a space where a direction is a whole function and the dot product is an integral.

Builds on: Calculus of Variations, Directional Derivative · Leads to: Density Functional Theory

Where it's used

Electrons in molecules. The energy of a molecule can be written as a functional (see Calculus of Variations) of the electron density ρ(r)\rho(\mathbf{r}), a function of position in space. Density functional theory says the true density is the one that makes this energy smallest. The functional derivative of the energy with respect to the density gives the potential that the electrons feel, and chemistry codes solve that condition for molecules with many atoms.

Learning a whole function. Some learning methods choose a function, not a parameter vector. Gradient boosting can be read as gradient descent in function space: at each step the model adds a new function that points downhill on the loss, and that downhill direction is a functional gradient.

Sag of a string under load. The stored energy of a stretched string is an integral over its deflection u(x)u(x). Setting its functional derivative to zero gives the shape the string settles into. Example 3 below does this calculation.

How it works

Use the simplest functional we can: J[f]=∫01f(x)2 dxJ[f] = \int_0^1 f(x)^2\,dx, which gives one number for each function ff on [0,1][0,1]. Take f(x)=xf(x) = x and the wiggle η(x)=1\eta(x) = 1, a constant. This toy has no endpoint conditions. We want the rate at which JJ changes as ff moves in the direction η\eta.

  1. Start with the value. J[f]=∫01x2 dx=13J[f] = \int_0^1 x^2\,dx = \tfrac13. Check: ∫01x2 dx=[x3/3]01=13\int_0^1 x^2\,dx = \big[x^3/3\big]_0^1 = \tfrac13.
  2. Nudge the function by εη\varepsilon\eta. The new function is f+εη=x+εf + \varepsilon\eta = x + \varepsilon, and J[f+εη]=∫01(x+ε)2 dx=∫01(x2+2εx+ε2) dx=13+ε+ε2J[f+\varepsilon\eta] = \int_0^1 (x+\varepsilon)^2\,dx = \int_0^1 (x^2 + 2\varepsilon x + \varepsilon^2)\,dx = \tfrac13 + \varepsilon + \varepsilon^2. Check: at ε=0\varepsilon = 0 this gives 13\tfrac13, the value from step 1.
  3. Take the change and divide by ε\varepsilon. The change is ε+ε2\varepsilon + \varepsilon^2, so the quotient is 1+ε1 + \varepsilon. Check: with ε=0.1\varepsilon = 0.1 the change is 0.110.11 and the quotient is 1.11.1.
  4. Let ε\varepsilon go to zero. The quotient goes to 11. That limit is the directional derivative of JJ at ff in the direction η\eta.
  5. Find the function that produces this number. Guess g(x)=2f(x)=2xg(x) = 2f(x) = 2x and test it: ∫01g(x) η(x) dx=∫012x dx=1\int_0^1 g(x)\,\eta(x)\,dx = \int_0^1 2x\,dx = 1. The two agree. The math section shows where the guess comes from. Check: both sides equal 1.
  6. Name it. g(x)=2f(x)g(x) = 2f(x) is the functional derivative δJδf(x)\dfrac{\delta J}{\delta f(x)}, and the whole idea is that the directional derivative equals ∫g η dx\int g\,\eta\,dx.
flowchart LR
  A[Function f] --> B[Nudge f by eps times eta]
  B --> C[Change in J, divided by eps]
  C --> D[Let eps go to zero]
  D --> E[Write the limit as the integral of g times eta]
  E --> F[g is the functional derivative]
00.20.40.60.8100.20.40.60.811.2xfunction value
  • f(x) = x
  • f + 0.1 eta
Adding 0.1 times eta(x) = 1 lifts the curve by 0.1 everywhere. The first-order change in J is 0.1 times 1, which is the step-3 quotient at the start.

The math

Definition: Functional derivative

Let J[f]J[f] be a functional, a rule that gives a number for each function ff in some class. The functional derivative of JJ at ff is the function g(x)=δJδf(x)g(x) = \dfrac{\delta J}{\delta f(x)} such that, for every smooth wiggle η(x)\eta(x) that respects the problem's boundary conditions,

ddεJ[f+εη]∣ε=0=∫g(x) η(x) dx.\frac{d}{d\varepsilon} J[f + \varepsilon\eta]\Big|_{\varepsilon = 0} = \int g(x)\,\eta(x)\,dx.

The left side is the directional derivative of JJ in the direction η\eta. The right side is the integral of the product of two functions, the function-space version of a dot product.

Step 1 in symbols: the nudge

The function f+εηf + \varepsilon\eta is the original plus a small multiple of the wiggle. In the example, f(x)=xf(x) = x and η(x)=1\eta(x) = 1, so f+εη=x+εf + \varepsilon\eta = x + \varepsilon.

Step 2 in symbols: the change

Let Φ(ε)=J[f+εη]\Phi(\varepsilon) = J[f + \varepsilon\eta]. The walkthrough found Φ(ε)=13+ε+ε2\Phi(\varepsilon) = \tfrac13 + \varepsilon + \varepsilon^2. A Taylor expansion of Φ\Phi at 00 gives this form. The first-order part is the term linear in ε\varepsilon, here Φ′(0)=1\Phi'(0) = 1. The directional derivative is exactly this coefficient, because Φ(ε)=Φ(0)+ε Φ′(0)+O(ε2)\Phi(\varepsilon) = \Phi(0) + \varepsilon\,\Phi'(0) + O(\varepsilon^2), where O(ε2)O(\varepsilon^2) stands for terms that shrink faster than ε\varepsilon.

Step 3 in symbols: the guess is forced

For J[f]=∫01f2 dxJ[f] = \int_0^1 f^2\,dx, differentiating under the integral sign gives

ddε∫01(f+εη)2 dx∣ε=0=∫012f η dx,\frac{d}{d\varepsilon}\int_0^1 (f + \varepsilon\eta)^2\,dx\bigg|_{\varepsilon=0} = \int_0^1 2f\,\eta\,dx,

so g=2fg = 2f. The function gg is unique. Suppose two functions g1g_1 and g2g_2 both work, and let h=g1−g2h = g_1 - g_2. Then ∫h η dx=0\int h\,\eta\,dx = 0 for every admissible η\eta. Choose η=h\eta = h, which is allowed when hh is smooth: then ∫h2 dx=0\int h^2\,dx = 0, so h=0h = 0.

Step 4 in symbols: the general integrand

For J[y]=∫abF(x,y,y′) dxJ[y] = \int_a^b F(x, y, y')\,dx with fixed endpoints, the derivation in Calculus of Variations gives Φ′(0)=∫ab(Fy η+Fy′ η′) dx\Phi'(0) = \int_a^b \big(F_y\,\eta + F_{y'}\,\eta'\big)\,dx. Integrate the second term by parts, as in Integration by Parts, with η(a)=η(b)=0\eta(a) = \eta(b) = 0 so the boundary term vanishes:

δJδy(x)=∂F∂y−ddx(∂F∂y′).\frac{\delta J}{\delta y(x)} = \frac{\partial F}{\partial y} - \frac{d}{dx}\left(\frac{\partial F}{\partial y'}\right).

Setting this to zero is the Euler–Lagrange equation. The functional derivative is the general object; the Euler–Lagrange equation is the statement that it vanishes.

Worked examples

Example
1. A constant function and a linear wiggle

Let J[f]=∫01f(x)2 dxJ[f] = \int_0^1 f(x)^2\,dx, with f(x)=2f(x) = 2 and wiggle η(x)=x\eta(x) = x.

  1. Nudge: f+εη=2+εxf + \varepsilon\eta = 2 + \varepsilon x.
  2. Square: (2+εx)2=4+4εx+ε2x2(2 + \varepsilon x)^2 = 4 + 4\varepsilon x + \varepsilon^2 x^2.
  3. Integrate: J=4+4ε⋅12+ε2⋅13=4+2ε+13ε2J = 4 + 4\varepsilon\cdot\tfrac12 + \varepsilon^2\cdot\tfrac13 = 4 + 2\varepsilon + \tfrac13\varepsilon^2. Check: ∫01x dx=12\int_0^1 x\,dx = \tfrac12 and ∫01x2 dx=13\int_0^1 x^2\,dx = \tfrac13.
  4. Divide the change by ε\varepsilon: (2ε+13ε2)/ε=2+13ε(2\varepsilon + \tfrac13\varepsilon^2)/\varepsilon = 2 + \tfrac13\varepsilon, which goes to 22 as ε\varepsilon goes to zero.
  5. Compare with the formula: g=2f=4g = 2f = 4, and ∫014x dx=2\int_0^1 4x\,dx = 2. The values match.

Interpretation: moving ff toward larger values where xx is large raises JJ at rate 2 per unit of ε\varepsilon.

Example
2. A functional with a derivative inside

Let J[y]=∫01(y′2+y2) dxJ[y] = \int_0^1 (y'^2 + y^2)\,dx, with y(x)=xy(x) = x and wiggle η(x)=x(1−x)\eta(x) = x(1-x). The wiggle is zero at both ends.

  1. The formula from the math section gives δJδy=2y−2y′′\dfrac{\delta J}{\delta y} = 2y - 2y''. For y=xy = x we have y′′=0y'' = 0, so g(x)=2xg(x) = 2x.
  2. Compute the first-order change directly: Φ′(0)=∫01(2y′η′+2yη) dx\Phi'(0) = \int_0^1 (2y'\eta' + 2y\eta)\,dx.
  3. With y′=1y' = 1 and η′=1−2x\eta' = 1 - 2x, the first term is ∫012(1−2x) dx=2−2=0\int_0^1 2(1-2x)\,dx = 2 - 2 = 0. Check: ∫01(1−2x) dx=1−1=0\int_0^1 (1-2x)\,dx = 1 - 1 = 0.
  4. The second term is ∫012x⋅x(1−x) dx=2∫01(x2−x3) dx=2(13−14)=16\int_0^1 2x \cdot x(1-x)\,dx = 2\int_0^1 (x^2 - x^3)\,dx = 2\big(\tfrac13 - \tfrac14\big) = \tfrac16.
  5. The total is 0+16=160 + \tfrac16 = \tfrac16.
  6. The formula gives ∫01g η dx=∫012x⋅x(1−x) dx=16\int_0^1 g\,\eta\,dx = \int_0^1 2x \cdot x(1-x)\,dx = \tfrac16. Same answer.

Interpretation: the term 2y′η′2y'\eta' was moved onto y′′y'' by integration by parts. That is where the −2y′′-2y'' in the formula comes from. Here y′′=0y'' = 0, so it adds nothing.

Example
3. The sag of a string under a uniform load

A string on [0,1][0,1] is fixed at both ends. Let u(x)≥0u(x) \ge 0 be its downward deflection, and let a uniform load f>0f > 0 pull on it. The energy is

E[u]=∫01(12u′2−f u) dx,E[u] = \int_0^1 \Big(\tfrac12 u'^2 - f\,u\Big)\,dx,

where the first term is the stretching energy and the second is the energy released as the load drops.

  1. Write the integrand as F(x,u,p)=12p2−fuF(x, u, p) = \tfrac12 p^2 - f u, so Fu=−fF_u = -f and Fp=pF_p = p.
  2. The functional derivative is δEδu=Fu−ddxFp=−f−u′′\dfrac{\delta E}{\delta u} = F_u - \dfrac{d}{dx}F_p = -f - u''.
  3. Set it to zero: u′′=−fu'' = -f. This is the stationary condition.
  4. Integrate twice: u(x)=−f2x2+c1x+c2u(x) = -\tfrac{f}{2}x^2 + c_1 x + c_2.
  5. Apply the endpoints. u(0)=0u(0) = 0 gives c2=0c_2 = 0. u(1)=0u(1) = 0 gives −f2+c1=0-\tfrac f2 + c_1 = 0, so c1=f2c_1 = \tfrac f2. Therefore u(x)=f2 (x−x2)u(x) = \tfrac f2\,(x - x^2).
  6. The peak is at x=12x = \tfrac12: u=f2⋅14=f8u = \tfrac f2 \cdot \tfrac14 = \tfrac f8. With f=1f = 1 the peak is 0.1250.125. Check: u(12)=12(12−14)=18=0.125u(\tfrac12) = \tfrac12(\tfrac12 - \tfrac14) = \tfrac18 = 0.125.

Interpretation: the sag is a parabola, and it grows in proportion to the load.

Try it: the same string carries a load f=2f = 2. What is the peak sag?

Answer: f/8=2/8=0.25f/8 = 2/8 = 0.25. Doubling the load doubles the sag, as the formula u=f2(x−x2)u = \tfrac f2(x - x^2) says.

Common mistakes and tradeoffs

It is tempting to think a functional derivative is a single number, like an ordinary partial derivative. In fact it is a function of xx. For J[f]=∫f2 dxJ[f] = \int f^2\,dx it is 2f(x)2f(x), which changes from point to point along the interval.

It is tempting to drop the derivative term. In fact for ∫(y′2+y2) dx\int (y'^2 + y^2)\,dx the answer is 2y−2y′′2y - 2y'', not 2y2y. For y=x2y = x^2, 2y−2y′′=2x2−42y - 2y'' = 2x^2 - 4, while 2y2y alone gives 2x22x^2.

It is tempting to think the wiggle η\eta must have length 1. In fact the definition takes a limit in ε\varepsilon, so any η\eta works, and scaling η\eta scales the answer. The unit-length condition in the Directional Derivative exists so that the answer is a rate per unit distance. A function space has many possible notions of distance, so the definition does not pick one.

It is tempting to forget the endpoint conditions. Integration by parts needs η\eta to vanish at the ends, which is why the wiggles must respect the boundary conditions. If it does not, boundary terms appear and the simple Euler–Lagrange form needs extra conditions.

When to use it. Use it when the unknown is a whole function and the objective is an integral, as in energy minimisation and in the physics and chemistry examples above. When not to use it. If the functional is not differentiable, the directional-derivative limit may not exist. Alternative. Replace the function by its values on a grid of NN points. The functional becomes an ordinary function of NN variables, and its partial derivatives approximate the functional derivative times the grid spacing. This is how many numerical solvers work.

History

The functional derivative grew out of the calculus of variations, which asks how a total changes under a small change of a whole curve. The problem that started that field was the brachistochrone, the curve of fastest descent, as described in Calculus of Variations. The notation δJ/δf\delta J / \delta f is the one used in physics and chemistry, where energies and actions are integrals of functions. It became central when those fields needed the stationary condition for such energies. Density functional theory is the best-known case: the energy is a functional of the electron density, and its functional derivative gives the potential the electrons feel. The idea caught on because it turns a family of problems into one condition: the functional derivative is zero.

Recap

  • A functional J[f]J[f] takes a whole function and returns a number.
  • Nudging ff by εη\varepsilon\eta gives a first-order change; its rate is the Directional Derivative of JJ in the direction η\eta.
  • The functional derivative g=δJ/δfg = \delta J/\delta f is the function for which that rate equals ∫g η dx\int g\,\eta\,dx for every admissible η\eta.
  • For ∫F(x,y,y′) dx\int F(x, y, y')\,dx, g=Fy−ddxFy′g = F_y - \dfrac{d}{dx}F_{y'}. Setting g=0g = 0 gives the Euler–Lagrange equation of Calculus of Variations.

Read next: Density Functional Theory, where the functional derivative of the energy gives the potential that electrons feel.

Check yourself

QuestionWrite the defining equation of the functional derivative of J at f, in words and in symbols.Show answer

In words: the rate of change of JJ as ff moves by εη\varepsilon\eta, evaluated at ε=0\varepsilon = 0, equals the integral of the functional derivative times η\eta, for every admissible η\eta. In symbols, ddεJ[f+εη]∣ε=0=∫g(x) η(x) dx\dfrac{d}{d\varepsilon} J[f + \varepsilon\eta]\big|_{\varepsilon=0} = \int g(x)\,\eta(x)\,dx, where g=δJδf(x)g = \dfrac{\delta J}{\delta f(x)}.

QuestionLet J[f]=∫01f(x)2 dxJ[f] = \int_0^1 f(x)^2\,dx. What is δJδf(x)\dfrac{\delta J}{\delta f(x)} at x=0.5x = 0.5 when f(x)=xf(x) = x?Show answer

The functional derivative is 2f(x)2f(x), so it is 2x2x. At x=0.5x = 0.5 the value is 2×0.5=12 \times 0.5 = 1.

QuestionWhy is the functional derivative a function of x rather than a single number, and why is it unique?Show answer

A functional can respond differently to a wiggle at each point, so the sensitivity is a function of position. It is unique because if two functions gave the same integral against every admissible η\eta, their difference hh would satisfy ∫h η dx=0\int h\,\eta\,dx = 0 for all η\eta. Choosing η=h\eta = h gives ∫h2 dx=0\int h^2\,dx = 0, so h=0h = 0.

QuestionA load of f=3f = 3 pulls on the string of Example 3. What is the peak sag?Show answer

The shape is u=f2(x−x2)u = \tfrac f2(x - x^2), and the peak is f/8f/8. With f=3f = 3 the peak is 3/8=0.3753/8 = 0.375.

Sources