A14 · Lesson 32 · Metric spaces
Distance, abstracted, so the same theorems work for vectors, signals and codes
"Close" has meant small. But engineers measure closeness in many ways: the RMS difference between two signals, the largest deviation of a filter's response from a template, the number of bits by which a received word differs from a codeword. A metric space is any set with a distance function obeying three rules. Once those hold, convergence, Cauchy sequences, open sets and continuity all make sense, and theorems proved once apply to vectors, functions and codes alike. The next lesson's contraction mapping theorem is the payoff.
- The curve is the unit ball for the p-norm .
- p = 1 gives a diamond (the Manhattan, or taxicab, distance); p = 2 the ordinary circle; large p approaches the square of the max norm, .
- The readout measures the distance from (0, 0) to the point (0.6, 0.8) in the p-norm: 1.4 at p = 1, exactly 1 at p = 2, and approaching 0.8 as p grows.
Predict
In a code where every two codewords differ in at least 5 bits, how many bit errors can the decoder always correct?
- With Hamming distance as the metric, balls of radius 2 around the codewords don't overlap (2 + 2 < 5), so a received word with at most 2 errors is closer to the codeword it came from than to any other. In general a minimum distance d corrects errors.
Name it
The axioms
A metric on a set X is a function d(x, y) with, for all x, y, z:
- , and exactly when x = y;
- ;
- (the triangle inequality).
Examples
| Space | Distance |
|---|---|
| , Euclidean | |
| , Manhattan | |
| , max | |
| continuous functions on [a, b], sup | |
| integrable functions, | |
| bit strings of length n, Hamming | number of positions that differ |
On all the p-norms give the same convergent sequences: . On spaces of functions they don't: a sequence can converge in but not in the sup metric (a narrowing spike of fixed height).
The definitions carry over
Open balls , open and closed sets, convergence (), Cauchy sequences and continuity are all defined exactly as on ℝ, with d in place of . A metric space is complete if every Cauchy sequence converges in it (lesson 33).
Codes
With Hamming distance, a code with minimum distance d detects up to d − 1 errors and corrects up to .
Worked example
Find the Euclidean, Manhattan and max distances between (1, 4, −2) and (3, 1, 2).
Show the solution
- Differences. They are (2, −3, 4).
- Euclidean.
- Manhattan.
- Max. The largest difference in size is 4.
- Check. As always, max ≤ Euclidean ≤ Manhattan.
Answer Euclidean 5.385, Manhattan 9 and max 4.
Worked example
What's the sup distance between and x on [0, 1]?
Show the solution
- Where the gap is largest. is increasing on [0, 1] (its derivative ), so the sup is at x = 1:
- Compare the distance.
Answer the sup distance is , and the distance is 0.0403.
Worked example
What area do the unit balls of the 1-norm, 2-norm and max norm have in the plane?
Show the solution
- The 1-norm ball. is a diamond with diagonals of length 2: area 2.
- The 2-norm ball. is the unit disk: area π.
- The max-norm ball. is the square : area 4.
- They nest. Diamond inside disk inside square, matching
- What it means. In finite dimensions all norms are equivalent, so they agree about which sequences converge, but the constants matter for error bounds.
Answer the areas are 2 for the 1-norm, π for the 2-norm and 4 for the max norm.
Check
What's the Euclidean distance between (1, 3) and (4, 2)?
Check
And the max-norm distance between (1, 3) and (4, 2)?
Check
What's the p-norm of (0.6, 2) for p = 3?
Check
What's the Hamming distance between the bytes 01001011 and 10011110?
Check
A code's minimum Hamming distance is 5. How many bit errors can it always correct?
Check
What's the sup distance between and x on [0, 1]?
Check
Which of these is not a metric on ℝ?
Check
Distances between (1, 4) and (2, −3).
(a)
What is the 1-norm (Manhattan) distance?
(b)
What is the 3-norm distance?
Check
The sup distance between x and on [0, 1].
Step 1
Where is largest?
Type it the way you would write it, like 3sin(2πft) or 3*sin(2*pi*f*t). Angles can be in radians or carry a degree sign, like 45°.
Step 2
What is that largest value?
Explain why
Why is the triangle inequality the axiom that makes a distance useful for analysis?
Most convergence arguments chain approximations: if is close to x, and x is close to y, then is close to y. The triangle inequality is exactly the statement that distances add at most, so errors from several steps can be bounded by adding them up, as in the ε/2 + ε/2 arguments. Without it, two points could each be close to a third yet far from each other, and limits wouldn't be unique. The function fails it: 0 and 2 are at distance 4, though each is at distance 1 from 1, so it can't support those arguments.
Practice
Keep practicing
10 kinds of problem on this topic, dealt one at a time with new numbers every time, for as long as you like.