Search

Search papers and lessons

Smooth Function

Level 3 · 10 min read

A smooth function has no corners or jumps in its slope, and in optimization 'smooth' means the slope cannot change faster than a fixed rate L, which makes gradient steps safe.

On this page

  • Colour = topic mix
  • Calculus
  • Discrete math
  • Linear algebra
  • Optimization
  • Sign in to see your progress

TL;DR

A function is smooth when its graph has no corners, kinks or jumps, so its slope changes gently. In optimization the word has a sharper meaning: a function is LL-smooth when its gradient can change no faster than a fixed rate LL. That single bound is what lets gradient descent take a step of size 1/L1/L and be sure the function goes down.

Where you'll see it: in the convergence proofs of Gradient Descent, in the choice of its step size, and in the analysis of training losses such as the squared error of Linear Regression.

Intuition

Picture a road. A smooth road has no sharp corners where you would have to stop and turn, and its steepness changes gradually. A road with a corner has a point where the steepness jumps in an instant.

Now think about walking downhill on a foggy hill. You can only see the slope under your feet. If the slope could change suddenly, a step that looked safe could land you on a steep wall. If the slope changes at most at some known rate, you can estimate how far you will go before the terrain changes under you, and choose a step that is safe.

That is the reason the optimization definition exists. Gradient descent moves a point against the Gradient, which is the vector of partial derivatives. It works well when the gradient at one point tells you something reliable about the gradient nearby. Smoothness is the promise that it does.

The plot below shows three shapes. x2x^2 is smooth everywhere. ∣x∣|x| has a corner at zero, where the slope jumps from −1-1 to +1+1. x ∣x∣x\,|x| has a flat, gentle bend at zero, and it is the kind of function that is smooth enough for optimization even though its curvature jumps.

−2−1.5−1−0.500.511.52−101234xf(x)
  • x^2 (smooth)
  • x|x| (slope is continuous)
  • |x| (corner at 0)
|x| has a corner at zero, so it is not differentiable there. The other two curves have a slope that changes continuously.

The math

Two different definitions go by the name smooth. Keep them apart.

Definition: Smooth (calculus)

A function ff is smooth, or C∞C^\infty, when it has derivatives of every order and each one is continuous. It is C1C^1 when ff has a continuous first derivative. Polynomials, exp⁡\exp and sin⁡\sin are smooth everywhere they are defined.

Definition: L-smooth (optimization)

Let f:Rn→Rf : \mathbb{R}^n \to \mathbb{R} be differentiable, and let L>0L > 0 be a number. Then ff is LL-smooth when its gradient is LL-Lipschitz:

∥∇f(x)−∇f(y)∥≤L ∥x−y∥for all x,y.\|\nabla f(\mathbf{x}) - \nabla f(\mathbf{y})\| \le L\,\|\mathbf{x} - \mathbf{y}\| \quad \text{for all } \mathbf{x}, \mathbf{y}.

Here ∥⋅∥\|\cdot\| is the Euclidean length, and LL is the smallest number that makes the inequality hold, called the smoothness constant.

The second definition asks about the gradient, not the function. The gradient may be continuous and bounded in slope change even when the function is not C2C^2. This matters below.

Two checks you can run by hand

For a one-variable function, the definition says that the derivative f′f' is LL-Lipschitz. If ff is twice differentiable, a simpler test works: ff is LL-smooth when ∣f′′(x)∣≤L|f''(x)| \le L for all xx. In several variables the same role is played by the Hessian ∇2f\nabla^2 f, the matrix of second partial derivatives. A twice-differentiable ff is LL-smooth when every eigenvalue of the Hessian, at every point, has absolute value at most LL.

The descent lemma

The key consequence is a bound on how much the function can curve above its linear approximation. For an LL-smooth ff, for all x,y\mathbf{x}, \mathbf{y},

f(y)≤f(x)+∇f(x)⊤(y−x)+L2 ∥y−x∥2.f(\mathbf{y}) \le f(\mathbf{x}) + \nabla f(\mathbf{x})^\top (\mathbf{y} - \mathbf{x}) + \frac{L}{2}\,\|\mathbf{y} - \mathbf{x}\|^2 .

Read it in words. The right side is the tangent-plane guess at f(y)f(\mathbf{y}), plus a quadratic penalty. The function is never higher than its tangent plane plus that penalty.

Why it holds. Write f(y)−f(x)f(\mathbf{y}) - f(\mathbf{x}) as the integral of the directional change along the segment from x\mathbf{x} to y\mathbf{y}, subtract the tangent term, and bound the leftover with the Lipschitz condition. The gap is ∫01(∇f(x+t(y−x))−∇f(x))⊤(y−x) dt\int_0^1 (\nabla f(\mathbf{x} + t(\mathbf{y}-\mathbf{x})) - \nabla f(\mathbf{x}))^\top(\mathbf{y}-\mathbf{x})\,dt. Each integrand is at most Lt ∥y−x∥2L t\,\|\mathbf{y}-\mathbf{x}\|^2, and ∫01Lt dt=L/2\int_0^1 L t\,dt = L/2.

Why this gives a safe step size

Take a gradient step x+=x−1L∇f(x)\mathbf{x}^+ = \mathbf{x} - \frac{1}{L}\nabla f(\mathbf{x}) and put y=x+\mathbf{y} = \mathbf{x}^+ into the descent lemma. Let g=∇f(x)\mathbf{g} = \nabla f(\mathbf{x}). Then ∇f(x)⊤(y−x)=−1L∥g∥2\nabla f(\mathbf{x})^\top(\mathbf{y}-\mathbf{x}) = -\frac{1}{L}\|\mathbf{g}\|^2 and ∥y−x∥2=1L2∥g∥2\|\mathbf{y}-\mathbf{x}\|^2 = \frac{1}{L^2}\|\mathbf{g}\|^2, so

f(x+)≤f(x)−1L∥g∥2+L2⋅1L2∥g∥2=f(x)−12L∥g∥2.f(\mathbf{x}^+) \le f(\mathbf{x}) - \frac{1}{L}\|\mathbf{g}\|^2 + \frac{L}{2}\cdot\frac{1}{L^2}\|\mathbf{g}\|^2 = f(\mathbf{x}) - \frac{1}{2L}\|\mathbf{g}\|^2 .

Every step lowers the function by at least 12L∥g∥2\frac{1}{2L}\|\mathbf{g}\|^2. The step size 1/L1/L is not a guess. It is the value the proof needs. This is the core reason Gradient Descent converges on smooth problems.

Smooth is not the same as C∞C^\infty with a bound

A C∞C^\infty function need not be LL-smooth on the whole line. The function f(x)=x4f(x) = x^4 is smooth in the calculus sense, but its derivative 4x34x^3 grows without bound, so no single LL works everywhere. It is LL-smooth on any bounded interval, which is often enough in practice.

The converse also fails. The function f(x)=x ∣x∣f(x) = x\,|x| is only C1C^1, but its derivative 2∣x∣2|x| has Lipschitz constant 22, so ff is 22-smooth in the optimization sense.

Worked examples

Example
1. A parabola, by hand

Take f(x)=x2f(x) = x^2. Its derivative is f′(x)=2xf'(x) = 2x.

  1. Find LL. ∣f′(x)−f′(y)∣=∣2x−2y∣=2∣x−y∣|f'(x) - f'(y)| = |2x - 2y| = 2|x - y|, so L=2L = 2.
  2. Start at x=3x = 3. Here f(3)=9f(3) = 9 and f′(3)=6f'(3) = 6.
  3. Take the step 1/L=1/21/L = 1/2: x+=3−12⋅6=0x^+ = 3 - \tfrac{1}{2}\cdot 6 = 0.
  4. The new value is f(0)=0f(0) = 0.
  5. Check the bound f(x+)≤f(x)−12L∥g∥2f(x^+) \le f(x) - \frac{1}{2L}\|\mathbf{g}\|^2. The right side is 9−14⋅36=09 - \frac{1}{4}\cdot 36 = 0.

The bound is exact here. One step reaches the minimum, which happens because the parabola is the simplest smooth curve.

Example
2. A two-variable quadratic

Take f(x,y)=12(x2+4y2)f(x, y) = \tfrac12\left(x^2 + 4y^2\right), written as f(x)=12x⊤Axf(\mathbf{x}) = \tfrac12 \mathbf{x}^\top A \mathbf{x} with A=diag(1,4)A = \mathrm{diag}(1, 4).

  1. The Hessian is AA, a constant matrix. Its eigenvalues are 11 and 44, so L=4L = 4.
  2. Start at x=(2,1)\mathbf{x} = (2, 1). The gradient is ∇f=Ax=(2,4)\nabla f = A\mathbf{x} = (2, 4), and ∥g∥2=4+16=20\|\mathbf{g}\|^2 = 4 + 16 = 20.
  3. Compute f(x)=12(4+4)=4f(\mathbf{x}) = \tfrac12(4 + 4) = 4.
  4. Take the step 1/L=1/41/L = 1/4: x+=(2,1)−14(2,4)=(1.5, 0)\mathbf{x}^+ = (2, 1) - \tfrac14(2, 4) = (1.5,\ 0).
  5. Compute f(x+)=12(2.25+0)=1.125f(\mathbf{x}^+) = \tfrac12(2.25 + 0) = 1.125.
  6. Check the bound: f(x)−12L∥g∥2=4−208=1.5f(\mathbf{x}) - \frac{1}{2L}\|\mathbf{g}\|^2 = 4 - \frac{20}{8} = 1.5.

Since 1.125≤1.51.125 \le 1.5, the bound holds. The step lowered the value by more than the guaranteed amount. Notice the step size 1/L1/L was set by the stiffest direction, yy, which is why the gentler xx direction converges slower.

Example
3. Least squares with two features

A linear regression loss is f(w)=12∥Xw−y∥2f(\mathbf{w}) = \tfrac12\|X\mathbf{w} - \mathbf{y}\|^2. Here ∇f(w)=X⊤(Xw−y)\nabla f(\mathbf{w}) = X^\top(X\mathbf{w} - \mathbf{y}) and ∇2f=X⊤X\nabla^2 f = X^\top X (with X⊤X^\top the transpose of XX), a constant matrix. So ff is LL-smooth with LL equal to the largest eigenvalue of X⊤XX^\top X.

Take XX with rows (1,0)(1, 0), (0,2)(0, 2), (1,1)(1, 1) and y=(1,2,3)\mathbf{y} = (1, 2, 3).

  1. Compute X⊤X=(2115)X^\top X = \begin{pmatrix} 2 & 1 \\ 1 & 5 \end{pmatrix}. Its trace is 77 and its Determinant is 99, so its eigenvalues are 7±132\tfrac{7 \pm \sqrt{13}}{2}.
  2. The largest is L=7+132≈5.303L = \tfrac{7 + \sqrt{13}}{2} \approx 5.303.
  3. Start at w=(0,0)\mathbf{w} = (0, 0). Then Xw−y=−yX\mathbf{w} - \mathbf{y} = -\mathbf{y}, and ∇f(0)=−X⊤y=(−4,−7)\nabla f(\mathbf{0}) = -X^\top \mathbf{y} = (-4, -7). So ∥g∥2=65\|\mathbf{g}\|^2 = 65.
  4. Compute f(0)=12(1+4+9)=7f(\mathbf{0}) = \tfrac12(1 + 4 + 9) = 7.
  5. Take the step 1/L≈0.18861/L \approx 0.1886: w+≈(0.754, 1.320)\mathbf{w}^+ \approx (0.754,\ 1.320).
  6. Compute the residual Xw+−y≈(−0.246, 0.640, −0.926)X\mathbf{w}^+ - \mathbf{y} \approx (-0.246,\ 0.640,\ -0.926), so f(w+)≈0.663f(\mathbf{w}^+) \approx 0.663.
  7. The bound says f(w+)≤7−652⋅5.303≈0.871f(\mathbf{w}^+) \le 7 - \frac{65}{2 \cdot 5.303} \approx 0.871.

The loss fell from 77 to about 0.660.66 in one step, and the guarantee of 0.870.87 holds. In practice the same argument tells a data scientist that a learning rate near 1/L1/L is safe, and that a much larger one can make the loss grow.

Tradeoffs and failure modes

SituationWhat goes wrongBetter choice
Gradient steps with a step size above 2/L2/LThe loss can grow from one step to the next, because the descent bound no longer holds.Use a step at most 1/L1/L, or line search.
LL is unknown or very largeThe safe step is tiny and training is slow.Estimate LL on the fly, or use adaptive methods such as Adam.
The function has corners, as with ∣x∣\lvert x\rvertNo LL exists, and the gradient step can oscillate around the kink.Use Subgradient or proximal methods.
The function is smooth only on a bounded regionThe bound holds locally but a large step can leave the region.Restrict steps, or use a line search.

Smoothness is a worst-case promise over the whole domain. A function can be smooth in most places and fail the bound at one extreme point, and that one point is enough to break the global guarantee.

History

The calculus idea of a smooth function, one with derivatives of every order, grew out of the nineteenth-century work that made derivatives and continuity precise. The optimization sense, a bound on how fast the gradient can change, became central to the analysis of gradient methods in the second half of the twentieth century. Yurii Nesterov's work on fast gradient methods in the 1980s used this bound to prove convergence rates, and his later book made the condition standard. Modern texts, including the one by Boyd and Vandenberghe, use it as the working definition for analyzing Gradient Descent in machine learning.

Recap

A smooth function changes its slope gently. In optimization, the useful version is an LL-smooth function, whose gradient is LL-Lipschitz. That gives the descent lemma, which in turn gives the step size 1/L1/L and a guaranteed decrease at every step. The same bound is the first step toward the convergence proofs of Gradient Descent.

Check yourself

QuestionWhat does the abbreviation L-smooth refer to, and what property of which object does it describe?Show answer

An LL-smooth function has a gradient that is LL-Lipschitz: the gradient changes by at most LL times the distance between the two input points. It describes the gradient, not the function's values directly, though it implies a bound on how far the function can rise above its tangent.

QuestionCompute the smoothness constant L of f(x) = 5x^2 and state the safe step size.Show answer

The derivative is f′(x)=10xf'(x) = 10x. Then ∣f′(x)−f′(y)∣=10∣x−y∣|f'(x) - f'(y)| = 10|x - y|, so L=10L = 10. The safe step size is 1/L=1/101/L = 1/10. Using a larger step, for example 1/51/5, makes the iteration overshoot on this parabola.

QuestionWhy does the descent lemma imply that the gradient step with size 1/L reduces the loss?Show answer

Substituting y=x−1Lg\mathbf{y} = \mathbf{x} - \frac{1}{L}\mathbf{g} into the descent lemma gives f(y)≤f(x)−1L∥g∥2+12L∥g∥2=f(x)−12L∥g∥2f(\mathbf{y}) \le f(\mathbf{x}) - \frac{1}{L}\|\mathbf{g}\|^2 + \frac{1}{2L}\|\mathbf{g}\|^2 = f(\mathbf{x}) - \frac{1}{2L}\|\mathbf{g}\|^2. The right side is strictly smaller than f(x)f(\mathbf{x}) whenever the gradient is nonzero, so the loss falls at every step.

QuestionA function is C-infinity on the whole real line, but its derivative 3x^2 has no finite Lipschitz constant. Is it L-smooth? Explain.Show answer

No, not globally. Take f(x)=x3f(x) = x^3. Its derivative 3x23x^2 grows without bound, so ∣3x2−3y2∣|3x^2 - 3y^2| can be made as large as desired with xx and yy far from zero. No single LL works on all of R\mathbb{R}. The function is still LL-smooth on any bounded interval, with LL set by the largest value of ∣6x∣|6x| there.

QuestionSuppose you train a linear model whose loss has Hessian X^T X, and the largest eigenvalue of X^T X is 8. Which step size should you use, and why?Show answer

The smoothness constant is L=8L = 8, so the safe step size is 1/L=1/81/L = 1/8. The Hessian is constant for a linear model, so the bound holds everywhere, and a step of 1/81/8 is guaranteed not to increase the loss. Steps larger than 2/8=1/42/8 = 1/4 can make the loss grow.

Sources