skip to content

Using the chord test, why is f(x) = x^2 convex but f(x) = x^3 not?

level: middleimportance: must knowfreq 70%

answer

  1. compare a straight line to the curve
  2. chord versus graph, which is higher
  3. test a pair on the negative side
  4. f(t*x+(1-t)*y) <= t*f(x)+(1-t)*f(y)

basics

~20 s

A function is convex when every chord lies on or above its graph: f(t*x + (1-t)y) <= tf(x) + (1-t)*f(y). Squaring passes everywhere. Cubing fails between x = -2 and 0, where f(-1) = -1 sits above the chord value -4.

solid answer

~40 s

The chord test is the definition: `f` is convex on a convex domain if for all `x, y` and all `t` in `[0, 1]`, `f(t*x + (1-t)*y) <= t*f(x) + (1-t)*f(y)`. Read geometrically, the straight chord joining any two points on the graph never dips below the graph between them. For `f(x) = x^2` the inequality holds for every pair, with equality only when `x = y`, so it is strictly convex. For `f(x) = x^3` take `x = -2`, `y = 0`, `t = 0.5`: the midpoint is `-1` with `f(-1) = -1`, while the chord value is `0.5*(-8) + 0.5*0 = -4`. Since `-1 > -4`, the graph pokes above its chord and convexity fails. Cubing is convex only on `x >= 0`, where the chord test does hold.

go deeper

for a junior

Be ready to write the chord inequality from memory and to say which side the chord sits on for a convex function, plus name x^2 as convex and x^3 as not convex on the whole line.

for a middle

Explain the mechanics: expand the chord minus the graph for x^2 to get t*(1-t)*(x-y)^2, and produce an explicit pair of points where x^3 breaks the inequality.

for a senior

Show judgment about domains — the same formula can be convex on one interval and not another — and know when the midpoint shortcut is safe to use because the function is continuous.

for a principal

Own the framing question: how much is it worth restricting a model or a domain so that the objective is provably convex, versus accepting a non-convex formulation with weaker guarantees.

## The chord (secant) definition Let `D` be a convex set. A function `f : D -> R` is **convex** if for all `x, y` in `D` and all `t` in `[0, 1]`, ``` f(t*x + (1 - t)*y) <= t*f(x) + (1 - t)*f(y) ``` The left side is the function evaluated at a point on the segment between `x` and `y`. The right side is the height of the straight **chord** joining `(x, f(x))` to `(y, f(y))`, evaluated at that same point. So the condition reads: **the chord lies on or above the graph**. A function is **concave** when the reverse inequality holds — its chords lie on or below the graph — and `f` is concave exactly when `-f` is convex. Note what the definition does *not* require: no derivative, no continuity assumption baked in, no particular shape. The chord test is the primitive; everything else is a consequence or a convenient sufficient condition. ## Strict convexity `f` is **strictly convex** if the inequality is strict whenever `x != y` and `t` is in the open interval `(0, 1)`. Then the chord touches the graph only at its two endpoints. `f(x) = x^2` is strictly convex. An affine function `f(x) = a*x + b` is convex *and* concave, since the chord coincides with the graph — it is convex but not strictly so. `f(x) = |x|` is convex but not strictly convex, because it is affine on each side of the origin, so a chord from `1` to `2` lies exactly on the graph. ## Working the two examples **Squaring.** For `f(x) = x^2`, expand the difference between the chord and the graph: ``` t*x^2 + (1-t)*y^2 - (t*x + (1-t)*y)^2 = t*(1-t)*(x - y)^2 ``` Since `t*(1-t) >= 0` on `[0, 1]` and `(x - y)^2 >= 0`, the chord minus the graph is non-negative for every pair, and strictly positive when `x != y` and `0 < t < 1`. That is a complete proof of strict convexity with no calculus at all. **Cubing.** For `f(x) = x^3` on the whole real line, one counterexample settles it. Take `x = -2`, `y = 0`, `t = 0.5`. The convex combination is the midpoint `-1`, and ``` f(-1) = -1 chord value at -1 = 0.5*f(-2) + 0.5*f(0) = 0.5*(-8) + 0 = -4 ``` Convexity demands `f(midpoint) <= chord value`, i.e. `-1 <= -4`, which is false. The graph rises above its own chord on the negative half-line — cubing is concave there. Restricted to `x >= 0`, `x^3` is convex, which is a reminder that convexity is a statement about a function **on a specified domain**, not an intrinsic label on a formula. A cautionary note about the midpoint you might be tempted to try first: with `x = -1`, `y = 1`, `t = 0.5`, the midpoint value `f(0) = 0` exactly equals the chord value `0`. That single pair does not violate anything, so a hasty check with a symmetric pair proves nothing. You need a witness that actually breaks the inequality. ## Midpoint convexity Checking only `t = 1/2` — `f((x + y)/2) <= (f(x) + f(y))/2` — is called **midpoint convexity**. It is weaker in general, but for a continuous function (indeed for any measurable one) midpoint convexity implies full convexity, because dyadic values of `t` are dense in `[0, 1]` and continuity fills in the rest. Pathological counterexamples exist only among non-measurable functions built with the axiom of choice, so in practice the midpoint check is a sound quick test — provided you actually verify continuity. ## Why the chord form is the one to memorise Second-derivative tests are more convenient when a function happens to be twice differentiable, but they say nothing about functions with corners, and they can only be applied pointwise. The chord inequality applies to every convex function, differentiable or not, and it is the form used to prove that convexity is preserved by non-negative weighted sums, by composition with an affine map, and by taking pointwise maxima. If you remember one thing about convexity, remember that the chord sits on top.

  • What separates strictly convex from merely convex, and where does an affine function sit?
    Strict convexity requires `f(t*x + (1-t)*y) < t*f(x) + (1-t)*f(y)` for `x != y` and `t` in `(0, 1)`, so the chord touches only at the endpoints. An affine function `a*x + b` makes the inequality an equality everywhere, so it is convex and concave but never strictly convex. `|x|` is convex without being strict. Strict convexity buys you at most one minimiser.
  • Is checking only the midpoint enough to conclude a function is convex?
    For a continuous function, yes: midpoint convexity, `f((x+y)/2) <= (f(x)+f(y))/2`, plus continuity implies the full inequality for every `t`, because dyadic `t` values are dense in `[0, 1]`. Without a regularity assumption it is not enough — counterexamples exist among non-measurable functions. So state the continuity assumption when you use the shortcut.
  • Does convexity require the function to be differentiable?
    No. The chord inequality never mentions derivatives, so functions with corners such as `|x|` or a piecewise-linear hinge are perfectly convex. Differentiability is a convenience that unlocks the second-derivative test, not a requirement. A convex function on an open interval is automatically continuous there, but it may still fail to be differentiable at isolated points.

Stretch a string between two points on the graph. If the string never touches the curve except at its ends, the curve is strictly convex; if the curve pushes up through the string anywhere, it is not convex there.

saying these in an interview costs you the question

  • Says convex just means U-shaped, with no test
  • Claims x^3 is convex because it is increasing
  • Puts the chord below the graph for a convex function
  • Swaps convex and concave in the inequality direction
  • Asserts convexity requires differentiability
  • Concludes from one symmetric pair that x^3 passes

context