AI Knowledge Tree

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.

⏱ 28 minPrerequisites:Vector spaces & subspaces

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 VV is a function ∥⋅∥:V→R\lVert \cdot \rVert: V \to \mathbb{R} satisfying[1]:

  1. Positivity: ∥v∥≥0\lVert v\rVert \ge 0, with ∥v∥=0\lVert v\rVert = 0 only when v=0v = 0.
  2. Absolute homogeneity: ∥αv∥=∣α∣ ∥v∥\lVert \alpha v\rVert = |\alpha|\,\lVert v\rVert for all α∈R\alpha \in \mathbb{R}.
  3. Triangle inequality: ∥u+v∥≤∥u∥+∥v∥\lVert u + v\rVert \le \lVert u\rVert + \lVert v\rVert.

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 v∈Rnv \in \mathbb{R}^n and p≥1p \ge 1, the ℓp\ell^p norm is

∥v∥p=(∑i=1n∣vi∣p)1/p.\lVert v\rVert_p = \left(\sum_{i=1}^n |v_i|^p\right)^{1/p}.

The three cases that appear constantly in machine learning:

ℓ2\ell^2 (Euclidean norm, p=2p=2): ∥v∥2=v12+⋯+vn2\lVert v\rVert_2 = \sqrt{v_1^2 + \cdots + v_n^2}. This is the familiar length of an arrow in space. Its unit ball {v:∥v∥2≤1}\{v : \lVert v\rVert_2 \le 1\} is the round sphere. Minimizing ∥v∥2\lVert v\rVert_2 penalizes all coordinates uniformly and typically produces many small, nonzero entries.

ℓ1\ell^1 (Manhattan norm, p=1p=1): ∥v∥1=∣v1∣+⋯+∣vn∣\lVert v\rVert_1 = |v_1| + \cdots + |v_n|. The unit ball is a diamond (hyperoctahedron). Minimizing ∥v∥1\lVert v\rVert_1 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].

ℓ∞\ell^\infty (max norm, p→∞p \to \infty): ∥v∥∞=max⁡i∣vi∣\lVert v\rVert_\infty = \max_i |v_i|. The unit ball is a hypercube. It penalizes the single largest entry.

All ℓp\ell^p norms for p≥1p \ge 1 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 p=2p=2 case.

To see what each norm measures, compare two vectors with the same Euclidean length but opposite shapes. A spread-out v=(1,1,1,1)v = (1, 1, 1, 1) and a spiky w=(2,0,0,0)w = (2, 0, 0, 0) both have ∥⋅∥2=2\lVert \cdot \rVert_2 = 2, so ℓ2\ell^2 cannot tell them apart. The other two norms can:

  • Spread (1,1,1,1)(1, 1, 1, 1): ∥v∥1=4\lVert v\rVert_1 = 4, ∥v∥∞=1\lVert v\rVert_\infty = 1.
  • Spiky (2,0,0,0)(2, 0, 0, 0): ∥w∥1=2\lVert w\rVert_1 = 2, ∥w∥∞=2\lVert w\rVert_\infty = 2.

The same ℓ2=2\ell^2 = 2 splits into ℓ1=4\ell^1 = 4 for the spread vector and ℓ1=2\ell^1 = 2 for the spiky one: ℓ1\ell^1 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 ℓ∞\ell^\infty values invert the ranking (11 vs 22): it sees only the largest entry, so the spiky vector, with one big coordinate, costs more. Three norms, one ℓ2\ell^2, two different orderings of the same pair.

Equivalence of norms

On a finite-dimensional space all norms are equivalent: for any two norms ∥⋅∥a\lVert \cdot \rVert_a and ∥⋅∥b\lVert \cdot \rVert_b, there exist constants c,C>0c, C > 0 such that

c ∥v∥a  ≤  ∥v∥b  ≤  C ∥v∥a.c\,\lVert v\rVert_a \;\le\; \lVert v\rVert_b \;\le\; C\,\lVert v\rVert_a.

For Rn\mathbb{R}^n the explicit constants between ℓ1\ell^1, ℓ2\ell^2, ℓ∞\ell^\infty are:

∥v∥∞  ≤  ∥v∥2  ≤  ∥v∥1  ≤  n ∥v∥2  ≤  n ∥v∥∞.\lVert v\rVert_\infty \;\le\; \lVert v\rVert_2 \;\le\; \lVert v\rVert_1 \;\le\; \sqrt{n}\,\lVert v\rVert_2 \;\le\; n\,\lVert v\rVert_\infty.

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).

Different norms have different unit balls (L1 a diamond, L2 a circle, L∞ a square), so the same vector has a different length under each.
Different norms have different unit balls (L1 a diamond, L2 a circle, L∞ a square), so the same vector has a different length under each.

Check it on arrays

python · numpy
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 v=(3,−4,12)v = (3, -4, 12), compute ∥v∥1\lVert v\rVert_1, ∥v∥2\lVert v\rVert_2, and ∥v∥∞\lVert v\rVert_\infty by hand, and check that the chain ∥v∥∞≤∥v∥2≤∥v∥1\lVert v\rVert_\infty \le \lVert v\rVert_2 \le \lVert v\rVert_1 holds.

Solution

Step 1. Sum of absolute values: ∥v∥1=3+4+12=19\lVert v\rVert_1 = 3 + 4 + 12 = 19.

Step 2. Euclidean length: ∥v∥2=9+16+144=169=13\lVert v\rVert_2 = \sqrt{9 + 16 + 144} = \sqrt{169} = 13.

Step 3. Largest magnitude: ∥v∥∞=max⁡(3,4,12)=12\lVert v\rVert_\infty = \max(3, 4, 12) = 12.

The ordering 12≤13≤1912 \le 13 \le 19 holds, matching the general inequality ∥v∥∞≤∥v∥2≤∥v∥1\lVert v\rVert_\infty \le \lVert v\rVert_2 \le \lVert v\rVert_1.

Exercise 2. Prove the triangle inequality fails for the "norm" N(v)=(∑i∣vi∣1/2)2N(v) = \left(\sum_i |v_i|^{1/2}\right)^2 (the p=1/2p = 1/2 case), so ℓp\ell^p with pp below 1 is not a norm. Use u=(1,0)u = (1, 0) and v=(0,1)v = (0, 1).

Solution

Step 1. Compute the two pieces separately. For u=(1,0)u = (1, 0), N(u)=(∣1∣1/2)2=1N(u) = (|1|^{1/2})^2 = 1, and likewise N(v)=1N(v) = 1, so N(u)+N(v)=2N(u) + N(v) = 2.

Step 2. Compute the combined vector u+v=(1,1)u + v = (1, 1):

N(u+v)=(11/2+11/2)2=(1+1)2=4.N(u + v) = \left(1^{1/2} + 1^{1/2}\right)^2 = (1 + 1)^2 = 4.

Step 3. The triangle inequality demands N(u+v)≤N(u)+N(v)N(u + v) \le N(u) + N(v), that is 4≤24 \le 2, which is false. So NN violates axiom 3 and is not a norm; the exponent p≥1p \ge 1 in the lesson is what the triangle inequality (Minkowski) requires.

Exercise 3 (code). Generate 100000 random vectors in R10\mathbb{R}^{10} and confirm the equivalence chain ∥v∥∞≤∥v∥2≤∥v∥1≤n ∥v∥2\lVert v\rVert_\infty \le \lVert v\rVert_2 \le \lVert v\rVert_1 \le \sqrt{n}\,\lVert v\rVert_2 holds for every one of them.

Solution
python · numpy
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 11 and n\sqrt{n} being the explicit equivalence constants for these three norms on Rn\mathbb{R}^n.

With a norm in hand, the inner-products lesson adds the angle between two vectors.


References

  1. [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. [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.↩