Closest points on two line segments 2026-10-14
For line segments and , , the squared Euclidean distance is a convex quadratic function on a square. Its minimum is either an admissible stationary point or a minimum on one of the four edges. Each edge minimum is a point-to-segment orthogonal projection, restricted to the interval. Testing these five candidates gives a complete algorithm; when the directions are parallel, the edge candidates suffice. Independently restricting both coordinates of the unconstrained stationary point is generally incorrect because the variables are coupled by .
Convex conjugate Created 2026-09-28 Updated 2026-10-14
The convex conjugate records a function using slopes rather than input positions. Let be a proper extended-real function: it is finite somewhere and never takes . Its convex conjugate iswhere is the dot product and is the effective domain. An infinite value of excludes that input from the supremum. The value can be , but cannot be because an input with finite supplies a finite lower bound.
The convex conjugate is automatically a convex function, even when is not convex: each fixed input gives an affine function , and their supremum is convex. It is also lower semicontinuous. It need not be proper: for on , is unbounded above for every . The definition and the automatic convexity are discussed in Boyd and Vandenberghe, Convex Optimization (2004), §3.3.1.
The best lower bound with a prescribed slope. Whenever is finite, the affine functionis an affine minorant of . Indeed, an affine function lies below everywhere exactly when . Thus is the largest possible intercept at slope . The convex conjugate trades positions for slopes: specifies where to inspect , whereas specifies which global affine minorant to use. Taking the supremum over all these affine minorants produces the biconjugate; the Fenchel-Moreau theorem says this recovers a proper convex function when it is lower semicontinuous.
A quadratic, computed by completing the square. For the convex quadratic function ,Consequently , and the unique maximizing input is . The affine minorant is the tangent line at : its slope is and its intercept is . For example, gives and the tangent line , touching at . This is the same curve described either by its point values or by the intercepts of its tangent lines.
A corner turns into a constraint on slopes. For the absolute value , if then , with value zero at . If , taking makes ; if , taking does the same. Therefore its convex conjugate is zero on and outside: it is the indicator functional of a constraint set for this interval. For the unique maximizing input is zero; for every maximizes, and for every maximizes. The corner's many supporting slopes are exactly the subdifferential .
A supremum need not be attained. For a differentiable convex function finite on all of , an input maximizes exactly when . If is strictly convex, there is at most one such input; existence is a separate issue. For the exponential function , the derivative is positive. At , solving gives and . At , the supremum of is zero as , with no maximizing input. At , as . Thus a strictly convex differentiable function can have both unattained finite conjugate values and infinite conjugate values.
Convex quadratic function 2026-10-14
A convex quadratic function on has the form with a symmetric positive semidefinite matrix . Its Hessian is , and , proving convexity directly. A stationary point is a global minimum. On a compact polytope, a minimum either is stationary in the interior or minimizes a restriction to a boundary face.
Fenchel–Young gap Created 2026-10-05 Updated 2026-10-14
The Fenchel–Young gap is the nonnegative discrepancyfor a proper convex function and its convex conjugate. It can be . When is finite, it is the vertical distance between and its affine minorant . The Fenchel–Young gap vanishes exactly when , so it measures whether an input and a slope satisfy the subgradient relation.
For the convex quadratic function , completing the square givesAt and , the function value is and the tangent line has value , giving a Fenchel–Young gap of . In , the same calculation for gives and , half the squared Euclidean norm of the mismatch.
An exact optimization error certificate. Fix a slope with and minimize the linearly tilted objective function . By the definition of the convex conjugate, , soThis identity holds even when the infimum is not attained. Thus a computed finite Fenchel–Young gap is exactly the error in objective value for this minimization problem. For the convex quadratic function, implies . A general proper convex function need not convert a small gap into a small distance: the absolute value has zero gap at for every .
The Fenchel–Young gap also connects convex analysis to optimal transport. For a proper convex function , define Kantorovich potentials and . The half-squared Euclidean distance cost satisfies . For a transport plan with finite integrated cost and integrable Kantorovich potentials, integrating this identity gives the difference between transport cost and the potentials' bound. This is the same local subgradient mismatch summed over transported pairs.
Fenchel–Young inequality Created 2026-09-28 Updated 2026-10-14
The Fenchel–Young inequality says that every input and every slope obeywhere is any proper extended-real function and is its convex conjugate. No convexity assumption on is needed for this inequality: the defining supremum is at least the particular value . If either term on the left is , the inequality still holds, but cannot be an equality because the dot product on the right is finite.
For a proper convex function, equality is equivalent to the subgradient conditionTo see this, with finite, equality says that attains the supremum defining , so for every . Rearranging gives the subgradient inequality . Geometrically, the affine minorant touches at .
If the proper convex function is also closed, meaning its epigraph is a closed set, or equivalently it is lower semicontinuous, thenThe forward implication holds without closedness; the reverse one requires the additional hypothesis in general. Applying the equality criterion to relates to , and the Fenchel-Moreau theorem supplies when is closed. See Bertsekas, Convex Optimization Theory: A Summary, §5.4.1, Proposition 5.4.3 for precisely this distinction.
A concrete failure of the reverse implication occurs for the indicator functional of a constraint set of the open interval . Its convex conjugate is : the endpoint gives the supremum, even though it is excluded from the interval. At , , but , so equality fails and is empty. Closing the interval changes the endpoint value and restores equality there.
For the convex quadratic function , the Fenchel–Young inequality is , and equality holds exactly when . For the absolute value , finite equality requires at , where is the sign function; at every gives equality. These are exactly the subgradients of the absolute value, including its entire interval of slopes at the corner.
Infimal convolution Created 2026-10-05 Updated 2026-10-14
An infimal convolution is the cheapest way to split a prescribed total between two costs. Suppose two activities contribute and to a required total , costing and . Their combined cost is optimized over all splits , rather than charging both activities for the entire total.
For proper extended-real functions on a real vector space , defineThe definition does not require convexity. An infinite cost forbids that contribution, as with an indicator functional of a constraint set. If no split has two finite costs, set ; if the costs of admissible splits are unbounded below, . Thus proper inputs need not produce a proper extended-real function. The notation denotes the same operation. See Parikh and Boyd, Proximal Algorithms, §3.1 for the standard convex analysis definition and its connection to the Moreau envelope.
An infimum is a best lower bound, whereas a minimum is a value realized by some split. Writing in place of requires an attaining pair . For convex functions, mixing two nearly optimal splits and applying convexity to each cost proves that their infimal convolution is convex whenever it is proper; one must use nearly optimal splits because exact minimizers need not exist. Its convex conjugate is whenever the extended real number arithmetic is well defined; see conjugate of an infimal convolution for the precise identity. This turns the optimization over splits into addition in the conjugate variables.
Two quadratic costs: share the load according to its price. Let and let the convex quadratic functions beFor fixed , eliminate . The derivative of the total cost is , so equal marginal costs giveThe cheaper activity receives more of a positive total: when and , . Completing the square gives an exact certificate for every competing split:Consequently the infimum is a unique minimum, andThe effective quadratic coefficient is , with . It is smaller than either or : allowing both activities reduces the cost compared with assigning everything to either one. If , each receives half the total and . This is a simple quadratic optimization problem whose answer preserves the form of the original costs.
Optimizing the split of two quadratic costs gives a cheaper quadratic total cost
. An exact illustrative calculation, not measured data: , and give and cost , compared with cost for an equal split. The right panel compares the optimized cost with assigning the whole total to either activity. Details.Smoothing a corner by splitting its cost. Take the absolute value function and the convex quadratic function , with . This infimal convolution is the Moreau envelope of the absolute value function:Here is the sign function, with . The optimal is soft thresholding. In the central region, the quadratic function carries the whole total; outside it, stays at and the absolute value function carries the excess. At the result is the Huber loss in the normalization near zero and outside. Its derivative is for and outside, so the corner becomes a continuous change of slope. Parikh and Boyd's [ref]
https://web.stanford.edu/~boyd/papers/pdf/prox_algs.pdf#page=18. §3.1 discussion of Moreau smoothing
uses twice this normalization for the Huber loss; the explicit formula here fixes the convention. This is also the one-dimensional case of the existing Moreau envelope of the Euclidean norm. Past exam of the mathematics course of the University of Cambridge 2003 iii Paper 68 1 Solution Created 2026-10-03 Updated 2026-10-14
Parameterize the two line segments byPut and abbreviate , , , , and . Minimizing the Euclidean distance is equivalent to minimizing the convex quadratic functionover a closed square. For nonzero nonparallel segment directions, . An interior minimum must satisfywhose unique solution isKeep it as a candidate only if both parameters lie in .
Every remaining minimum lies on the boundary. Define . The four edge minima are the point-to-segment orthogonal projectionsEvaluate at those four pairs and at the admissible interior pair, and return a pair with the smallest value. This solves closest points on two line segments completely: continuity guarantees a minimum, and every interior or boundary location has been tested. Do not independently clamp and : the mixed term couples them. For example, , , and give the line minimizer . Its independently clamped pair has squared distance , whereas the correct edge minimizer has squared distance .
Without general position, explicitly handle these configurations:
- If either segment has zero length, solve a point-to-segment projection; if both do, return the two points. This avoids division by or .
- If the directions are parallel, and the interior linear system is singular. The four edge projections still contain a minimum. Overlapping projected parameter intervals can yield a whole family of closest pairs.
- Collinear segments may overlap, touch, or be disjoint. Overlap gives zero distance with many choices; disjoint intervals give their nearest endpoints.
- Coplanar nonparallel segments can intersect, including endpoint contacts. The same candidate tests return zero distance if the line-intersection parameters lie in the square. Coincident endpoints and equal candidate distances need no arbitrary division or uniqueness assumption.
In floating-point arithmetic, almost-parallel directions require a condition-aware or higher-precision solve; they must not be declared exactly parallel solely because the computed determinant is small. The returned distance is , and the returned points are obtained by substitution into .



