XenonStack
Concave and Convex Functions Explained
J
K
N
O
R
X
Y
Z

XenonStack GlossaryConcave and Convex Functions Explained

Key takeaway

  • A convex function lies on or below its chords; a concave function is its mirror. See the definitions, the second derivative test and why convexity matters.

A convex function is one whose graph lies on or below the straight line between any two of its points, and a concave function is its mirror image, whose graph lies on or above those lines. Convexity is what makes many optimisation problems tractable.

This page is for students, analysts and machine learning engineers who need a clear working definition. It covers the formal definitions, the second derivative test, how convex and concave differ, why convexity matters for optimisation, how it relates to AI agents, and what to do first.

What is a convex function?

The UBC convexity notes define a function f as convex if it lies below its chords. For all points x0 and x1 and every α between 0 and 1, f((1 − α)x0 + αx1) ≤ (1 − α)f(x0) + αf(x1). Geometrically, as Wikipedia puts it, the line segment between two points on the graph lies above or on the graph.

If the inequality is strict for every pair of different points, the function is strictly convex. Older texts, including the earlier version of this page, call a convex function "convex downward" or "concave upward". Both phrases describe the same bowl shape.

What is a concave function?

Per Wikipedia, a function f is concave if its negative, minus f, is convex, and strictly concave if minus f is strictly convex. In plain terms, the graph lies on or above its chords, like a cap. Per the same article, x squared and the exponential function are convex. The older phrases "convex upward" and "concave downward" mean the same thing.

Two-column comparison of convex and concave functions across shape, second derivative, extremes and examples.

How do you test convexity with the second derivative?

For a twice differentiable function of one variable on an interval, Wikipedia says f is convex if and only if its second derivative is non-negative there. For several variables, the UBC convexity notes give the matching test: the Hessian must be positive semi-definite at every point.

A positive second derivative everywhere implies strict convexity, but the reverse does not hold. Wikipedia notes that x to the fourth power has a second derivative of zero at zero and is still strictly convex.

How do convex and concave functions differ?

PropertyConvex functionConcave function
Graph and chordsLies on or below the chord between two pointsLies on or above the chord
Second derivativeNon-negativeNon-positive
RelationshipThe negative of a concave functionThe negative of a convex function
Local and global extremesAny local minimum is a global minimumAny local maximum is a global maximum
Older namesConvex downward, concave upwardConvex upward, concave downward

Why does convexity matter for optimisation?

The UBC convexity notes state that any local minimum of a convex function is also a global minimum, and that a strictly convex function has only one global minimum. For anyone training a model, that means a search that finds a local minimum has found the best answer, with no risk of settling in a worse valley.

The notes also give Jensen's inequality: if f is convex and X is a random variable whose expectations exist, then f of the expected value of X is at most the expected value of f(X). The inequality underpins many results in probability and statistics.

How do convex functions relate to AI agents?

Training a model means minimising a loss function, and whether that loss is convex decides how much you can guarantee about the result. Agents built on trained models inherit those guarantees, or their absence. For the XenonStack AI agents computing platform, see ElixirClaw.

What should you do first?

  1. Write the function or loss you care about in one line.
  2. Check the second derivative, or the Hessian for several variables.
  3. Decide whether it is convex, concave or neither on your domain.
  4. If it is convex, use a method that exploits one global minimum.
  5. If it is not, plan for several local minima and test more than one start.

To map one decision your agents make, and the data and policy it depends on, book a Context Workshop. See what happens in the workshop.

Frequently asked questions

What is the difference between a convex and a concave function?

A convex function lies on or below the straight line between any two points on its graph. A concave function lies on or above it. A function is concave when its negative is convex.

How can you test convexity with the second derivative?

For a twice differentiable function of one variable, it is convex on an interval if and only if its second derivative is non-negative there. A positive second derivative everywhere implies strict convexity.

Why is a local minimum of a convex function a global minimum?

Any two local minima of a convex function can be connected by chords that lie on or above the graph, so no local minimum can be worse than another. A strictly convex function has only one global minimum.

What is a strictly convex function?

It is a convex function for which the defining inequality is strict for every pair of different points, so its graph never touches a chord between them.

What is Jensen's inequality?

If f is convex and X is a random variable whose expectations exist, then f of the expected value of X is at most the expected value of f(X).