Norms and the geometry of distance
Define norms via their three axioms, meet the p-norms, and connect L1 and L2 to sparsity and Euclidean length.
A vector space has no built-in notion of length. A norm adds one. The choice of norm shapes which solutions we prefer in an optimization problem: L2 favors small overall magnitude, L1 favors sparsity, and each choice comes with its own geometry.
The three axioms
A norm on a vector space is a function satisfying[1]:
- Positivity: , with only when .
- Absolute homogeneity: for all .
- Triangle inequality: .
Axiom 1 says the only zero-length vector is the origin. Axiom 2 says scaling a vector scales its length proportionally. Axiom 3 is the geometric fact that the direct path is never longer than a detour.
The p-norms
For and , the norm is
The three cases that appear constantly in machine learning:
(Euclidean norm, ): . This is the familiar length of an arrow in space. Its unit ball is the round sphere. Minimizing penalizes all coordinates uniformly and typically produces many small, nonzero entries.
(Manhattan norm, ): . The unit ball is a diamond (hyperoctahedron). Minimizing in an optimization problem tends to push most coordinates to exactly zero: the corners of the diamond are where the constraint boundary meets objective-level sets, and corners have many zero coordinates. This is the geometric root of the sparsity effect in LASSO[2].
(max norm, ): . The unit ball is a hypercube. It penalizes the single largest entry.
All norms for are genuine norms. The hard part is the triangle inequality (Minkowski's inequality); the proof uses Holder's inequality, which the inner-products lesson derives in the case.
To see what each norm measures, compare two vectors with the same Euclidean length but opposite shapes. A spread-out and a spiky both have , so cannot tell them apart. The other two norms can:
- Spread : , .
- Spiky : , .
The same splits into for the spread vector and for the spiky one: charges every coordinate its full magnitude, so it penalizes mass-spreading and rewards concentrating it on fewer entries, which is why minimizing it drives coordinates to zero. The values invert the ranking ( vs ): it sees only the largest entry, so the spiky vector, with one big coordinate, costs more. Three norms, one , two different orderings of the same pair.
Equivalence of norms
On a finite-dimensional space all norms are equivalent: for any two norms and , there exist constants such that
For the explicit constants between , , are:
Equivalence means that convergence and continuity are norm-independent in finite dimensions; the choice of norm matters for optimization (it shapes solutions) but not for analysis (it does not change which sequences converge).
Check it on arrays
import numpy as np
v = np.array([3.0, -4.0, 0.0, 1.0])
l1 = np.linalg.norm(v, ord=1)
l2 = np.linalg.norm(v, ord=2)
linf = np.linalg.norm(v, ord=np.inf)
print(f"L1 = {l1:.4f}") # 8.0
print(f"L2 = {l2:.4f}") # 5.0990...
print(f"Linf = {linf:.4f}") # 4.0
# Same L2, opposite shapes: L1 and Linf disagree on which is "bigger"
spread = np.array([1.0, 1.0, 1.0, 1.0])
spiky = np.array([2.0, 0.0, 0.0, 0.0])
for name, u in [("spread", spread), ("spiky", spiky)]:
print(f"{name}: L1={np.linalg.norm(u,1):.1f} "
f"L2={np.linalg.norm(u,2):.1f} Linf={np.linalg.norm(u,np.inf):.1f}")
# spread: L1=4.0 L2=2.0 Linf=1.0 ; spiky: L1=2.0 L2=2.0 Linf=2.0
# Verify the inequalities: linf <= l2 <= l1 <= sqrt(n)*l2
n = len(v)
print(f"linf <= l2: {linf <= l2 + 1e-12}") # True
print(f"l2 <= l1: {l2 <= l1 + 1e-12}") # True
print(f"l1 <= sqrt(n)*l2: {l1 <= np.sqrt(n)*l2 + 1e-12}") # True
# Sparsity intuition: L1-minimizing solution of min ||x||_1 s.t. x in an affine set
# is often sparse. Quick demo with a random underdetermined system:
rng = np.random.default_rng(42)
A = rng.normal(size=(3, 8)) # 3 equations, 8 unknowns -> many solutions
b = rng.normal(size=3)
# L2-minimum norm solution via pseudo-inverse:
x_l2 = np.linalg.lstsq(A, b, rcond=None)[0]
print(f"L2 solution nonzeros: {np.sum(np.abs(x_l2) > 1e-8)}") # likely 3 (full)The L2 solution typically uses all available coordinates; a proper L1 solve (requires a QP or LASSO solver not shown here) would produce a sparse vector.
Exercises
Exercise 1. For , compute , , and by hand, and check that the chain holds.
Solution
Step 1. Sum of absolute values: .
Step 2. Euclidean length: .
Step 3. Largest magnitude: .
The ordering holds, matching the general inequality .
Exercise 2. Prove the triangle inequality fails for the "norm" (the case), so with below 1 is not a norm. Use and .
Solution
Step 1. Compute the two pieces separately. For , , and likewise , so .
Step 2. Compute the combined vector :
Step 3. The triangle inequality demands , that is , which is false. So violates axiom 3 and is not a norm; the exponent in the lesson is what the triangle inequality (Minkowski) requires.
Exercise 3 (code). Generate 100000 random vectors in and confirm the equivalence chain holds for every one of them.
Solution
import numpy as np
rng = np.random.default_rng(0)
n = 10
V = rng.normal(size=(100_000, n))
l1 = np.linalg.norm(V, ord=1, axis=1)
l2 = np.linalg.norm(V, ord=2, axis=1)
linf = np.linalg.norm(V, ord=np.inf, axis=1)
tol = 1e-9
assert np.all(linf <= l2 + tol)
assert np.all(l2 <= l1 + tol)
assert np.all(l1 <= np.sqrt(n) * l2 + tol)
print("all", len(V), "vectors satisfy the equivalence chain")Each inequality holds across all samples: the norms differ by bounded factors, the constants and being the explicit equivalence constants for these three norms on .
With a norm in hand, the inner-products lesson adds the angle between two vectors.
References
- [1]Boyd, S., & Vandenberghe, L. (2018). Introduction to Applied Linear Algebra. Cambridge University Press. Norms, distances, and their use in least-squares and regularization.↩
- [2]Tibshirani, R. (1996). "Regression shrinkage and selection via the lasso". Journal of the Royal Statistical Society: Series B, 58, 267-288. doi:10.1111/j.2517-6161.1996.tb02080.x. The origin of L1-induced sparsity.↩