A1432 of 55
0 XP
  1. Hook
  2. Play
  3. Predict
  4. Name it
  5. Check
  6. Explain

A14 · Lesson 32 · Metric spaces

Distance, abstracted, so the same theorems work for vectors, signals and codes

"Close" has meant |x−y| 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 {(x,y):‖(x,y)‖p≤1} for the p-norm ‖(x,y)‖p=(|x|p+|y|p)1/p.
  • p = 1 gives a diamond (the Manhattan, or taxicab, distance); p = 2 the ordinary circle; large p approaches the square of the max norm, max⁡(|x|,|y|).
  • 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?

Name it

The axioms

A metric on a set X is a function d(x, y) with, for all x, y, z:

  1. d(x,y)≥0, and d(x,y)=0 exactly when x = y;
  2. d(x,y)=d(y,x);
  3. d(x,z)≤d(x,y)+d(y,z) (the triangle inequality).

Examples

SpaceDistance
ℝn, Euclidean∑(xi−yi)2
ℝn, Manhattan∑|xi−yi|
ℝn, maxmax⁡|xi−yi|
continuous functions on [a, b], supsup⁡|f(x)−g(x)|
integrable functions, L1∫|f−g|
bit strings of length n, Hammingnumber of positions that differ

On ℝn all the p-norms give the same convergent sequences: ‖v‖∞≤‖v‖2≤‖v‖1≤n‖v‖∞. On spaces of functions they don't: a sequence can converge in L1 but not in the sup metric (a narrowing spike of fixed height).

The definitions carry over

Open balls B(x,r)={y:d(x,y)<r}, open and closed sets, convergence (d(xn,x)→0), Cauchy sequences and continuity are all defined exactly as on ℝ, with d in place of |x−y|. 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 ⌊(d−1)/2⌋.

Worked example

Find the Euclidean, Manhattan and max distances between (1, 4, −2) and (3, 1, 2).

Show the solution
  1. Differences. They are (2, −3, 4).
  2. Euclidean. 4+9+16=5.385
  3. Manhattan. 2+3+4=9
  4. Max. The largest difference in size is 4.
  5. Check. As always, max ≤ Euclidean ≤ Manhattan.

Answer Euclidean 5.385, Manhattan 9 and max 4.

Worked example

What's the sup distance between sin⁡x and x on [0, 1]?

Show the solution
  1. Where the gap is largest. x−sin⁡x is increasing on [0, 1] (its derivative 1−cos⁡x≥0), so the sup is at x = 1: 1−sin⁡1=0.1585
  2. Compare the L1 distance. ∫01(x−sin⁡x)dx=12−(1−cos⁡1)=0.0403

Answer the sup distance is 1−sin⁡1=0.1585, and the L1 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
  1. The 1-norm ball. |x|+|y|≤1 is a diamond with diagonals of length 2: area 2.
  2. The 2-norm ball. x2+y2≤1 is the unit disk: area π.
  3. The max-norm ball. max⁡(|x|,|y|)≤1 is the square [−1,1]2: area 4.
  4. They nest. Diamond inside disk inside square, matching ‖v‖∞≤‖v‖2≤‖v‖1
  5. 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 sin⁡x 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 xn on [0, 1].

Step 1

Where is x−xn 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°.

Explain why

Why is the triangle inequality the axiom that makes a distance useful for analysis?

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.