BRAGA

02 Writing02-02 Notes02-02-167

Chebyshev Distance (L∞ norm, p → ∞)

Published 16 Apr 20266 min read
Contents
  1. 01Deep Breakdown
  2. 02Flowchart
  3. 03Real-world use
  4. 04The formula, piece by piece
  5. 05The formula in words
  6. 06Critical Concepts
  7. 07Step-by-step calculation (tiny example)
  8. 08Code examples
D(x,y)=max⁡i∣xi−yi∣D(x,y) = \max_i |x_i - y_i|
(1)

Deep Breakdown

What it tells me (Situation Awareness): Chebyshev distance is the L∞L_\infty norm: the distance between two points equals the largest single-coordinate difference, ignoring all other dimensions. The name comes from chess: the Chebyshev distance between two squares is the minimum number of king moves needed (a king can move diagonally, so it takes max⁡(∣Δrow∣,∣Δcol∣)\max(|\Delta\text{row}|, |\Delta\text{col}|) moves). In DA/DS: Chebyshev distance is the right metric when the bottleneck or worst-case deviation drives the cost, not the total deviation. It is used in warehouse logistics (robot arm movement), anomaly detection (which feature deviates most?), game AI, and maximum-deviation tolerance checks.

Flowchart

Vectors x =(x1,...,xn), y =(y1,...,yn)Computeelement-wiseabsolutedifferences: |xi -yi|Find themaximum:max_i |xi - yi|D_inf(x,y) =ChebyshevdistanceLimit ofMinkowski as p -infCaptures theWORST-CASEdimensiondeviationChess king:max(|delta_row|,|delta_col|)moves

Real-world use

Where it is used

Warehouse robot routing (moving along two axes simultaneously, the time needed is the max of horizontal and vertical travel), maximum tolerance checks in manufacturing QC (is any feature out of spec?), outlier detection (which feature deviates most from expected?), chess-like grid game AI, and L∞L_\infty robustness analysis in adversarial ML (maximum perturbation budget per feature).

Problem it solves

When you care about the single worst deviation rather than the total or average deviation, Chebyshev is the correct metric. Summing all differences (Manhattan) or squaring them (Euclidean) dilutes the worst-case feature. Chebyshev isolates it.

How it solves the problem

max⁡i∣xi−yi∣\max_i |x_i - y_i| simply picks the largest element from the absolute difference vector. As a limit of LpL_p: lim⁡p→∞(∑i∣xi−yi∣p)1/p=max⁡i∣xi−yi∣\lim_{p \to \infty} \left(\sum_i |x_i - y_i|^p\right)^{1/p} = \max_i |x_i - y_i|, because raising to a very large power pp forces the maximum term to dominate the sum.

Example in a business

A DS at a logistics company models robot arm movement in a grid warehouse. The robot can move diagonally, so moving from bin (r1,c1)(r_1, c_1) to (r2,c2)(r_2, c_2) takes max⁡(∣r1−r2∣,∣c1−c2∣)\max(|r_1-r_2|, |c_1-c_2|) time steps. They use Chebyshev distance to optimize picking routes, minimizing time steps rather than path length.

The formula, piece by piece

  • D(x,y)D(x,y): Chebyshev distance between x,y∈Rnx, y \in \mathbb{R}^n; always ≥0\geq 0
  • ∣xi−yi∣|x_i - y_i|: absolute difference in dimension ii
  • max⁡i\max_i: take the maximum over all dimensions — the single largest absolute difference
  • =∥x−y∥∞= \|x - y\|_\infty: equivalent to the infinity norm (sup norm, L∞L_\infty norm)
  • Limit: D∞(x,y)=lim⁡p→∞Dp(x,y)D_\infty(x,y) = \lim_{p \to \infty} D_p(x,y)
  • For 2D: D∞=max⁡(∣x1−y1∣,∣x2−y2∣)D_\infty = \max(|x_1 - y_1|, |x_2 - y_2|) — the chess king distance
  • Relationship to other norms: ∥v∥∞≤∥v∥2≤∥v∥1\|v\|_\infty \leq \|v\|_2 \leq \|v\|_1 (for the same vector v=x−yv = x-y)

The formula in words

"Look at how much xx and yy differ in each coordinate. Ignore all but the worst one. The Chebyshev distance is that single biggest gap — the most extreme coordinate difference." Tiny example: x=(1,8,3)x = (1, 8, 3), y=(4,5,9)y = (4, 5, 9). Differences: ∣1−4∣=3|1-4| = 3, ∣8−5∣=3|8-5| = 3, ∣3−9∣=6|3-9| = 6. D∞=max⁡(3,3,6)=6D_\infty = \max(3, 3, 6) = 6 (the third dimension dominates). ✓\checkmark

Critical Concepts

  • Worst-case semantics: Chebyshev captures the maximum single-feature deviation. Useful whenever "the weakest link" (worst feature) is the bottleneck.
  • Unit ball is a hypercube: the set {v:∥v∥∞≤1}\{v : \|v\|_\infty \leq 1\} is a hypercube (square in 2D, cube in 3D). Compare to the diamond (L1L_1) and sphere (L2L_2).
  • Coordinate transformation: in 2D, rotating by 45° converts L∞L_\infty into L1L_1 and vice versa. Concretely: max⁡(∣a∣,∣b∣)=12(∣a+b∣+∣a−b∣)\max(|a|, |b|) = \frac{1}{2}(|a+b| + |a-b|).
  • L∞L_\infty adversarial robustness: in adversarial ML, the ϵ\epsilon-L∞L_\infty attack budget means no single pixel/feature can be perturbed by more than ϵ\epsilon. Chebyshev distance measures whether an adversarial example is within budget.
  • Bottleneck property: D∞(x,y)=0D_\infty(x,y) = 0 iff x=yx = y (as required for a metric). It is a proper metric (satisfies all four axioms).
  • Dimension sensitivity: dominated by the most variable feature.

Must standardize features before using.

Step-by-step calculation (tiny example)

Step 1: Compute element-wise absolute differences x=(3,1,9,4)x = (3, 1, 9, 4), y=(7,1,2,8)y = (7, 1, 2, 8). ∣3−7∣=4|3-7|=4, ∣1−1∣=0|1-1|=0, ∣9−2∣=7|9-2|=7, ∣4−8∣=4|4-8|=4.

Step 2: Find the maximum D∞=max⁡(4,0,7,4)=7D_\infty = \max(4, 0, 7, 4) = 7.

Step 3: Compare all three norms D1=4+0+7+4=15D_1 = 4+0+7+4 = 15. D2=16+0+49+16=81=9D_2 = \sqrt{16+0+49+16} = \sqrt{81} = 9. D∞=7D_\infty = 7. Holds: D∞≤D2≤D1D_\infty \leq D_2 \leq D_1. ✓\checkmark

Code examples

Beginner example (Python)

python
import numpy as np

def chebyshev_distance(x: np.ndarray, y: np.ndarray) -> float:
    """Compute Chebyshev (L-infinity) distance between x and y."""
    return float(np.max(np.abs(x - y)))
x = np.array([3.0, 1.0, 9.0, 4.0])
y = np.array([7.0, 1.0, 2.0, 8.0])
d_inf = chebyshev_distance(x, y)
d1 = float(np.linalg.norm(x - y, ord=1))
d2 = float(np.linalg.norm(x - y, ord=2))
print(f"Chebyshev (Linf): {d_inf:.4f}")
print(f"Manhattan (L1): {d1:.4f}")
print(f"Euclidean (L2): {d2:.4f}")
print(f"Holds Linf <= L2 <= L1: {d_inf <= d2 <= d1}")   # Chess king example: board positions as (row, col)
king_pos = np.array([3, 4])
target = np.array([7, 1])
print(f"\nChess king moves needed: {chebyshev_distance(king_pos, target):.0f}")   # Verify scipy
from scipy.spatial.distance import chebyshev
print(f"scipy chebyshev: {chebyshev(x, y):.4f}")

Beginner example (R)

r
# -- Chebyshev (L-infinity) distance ---
chebyshev_dist <- function(x, y) max(abs(x - y))
x <- c(3, 1, 9, 4)
y <- c(7, 1, 2, 8)
d_inf <- chebyshev_dist(x, y)
d1 <- sum(abs(x - y))
d2 <- sqrt(sum((x - y)^2))
cat(sprintf("Chebyshev (Linf): %.4f\n", d_inf))
cat(sprintf("Manhattan (L1): %.4f\n", d1))
cat(sprintf("Euclidean (L2): %.4f\n", d2))
cat(sprintf("Holds Linf <= L2 <= L1: %s\n", d_inf <= d2 && d2 <= d1))  # Which dimension dominates?
diffs <- abs(x - y)
cat(sprintf("\nDominant dimension: %d (diff = %.1f)\n", which.max(diffs), max(diffs)))

Professional example (Python)

python
import numpy as np
import pandas as pd
np.random.seed(42)   # -- Business scenario: adversarial robustness audit (L-inf budget check) ---
# For each test sample, check if any adversarial perturbation exceeds the
# L-inf budget epsilon. Flag samples that are near a class boundary.
N_CLEAN = 200
N_ADVER = 50
D = 20
EPSILON = 0.1   # L-inf perturbation budget per feature # Simulate clean test samples and adversarial perturbations
X_clean = np.random.randn(N_CLEAN, D)
X_adv = X_clean[:N_ADVER] + np.random.uniform(-0.15, 0.15, (N_ADVER, D))   # Compute per-sample Chebyshev distance (max feature perturbation)
chebyshev_dists = np.max(np.abs(X_adv - X_clean[:N_ADVER]), axis=1)   # Flag samples that exceed the L-inf budget
within_budget = chebyshev_dists <= EPSILON
worst_feature = np.argmax(np.abs(X_adv - X_clean[:N_ADVER]), axis=1)
results = pd.DataFrame({ "sample_id": range(N_ADVER), "max_perturbation": chebyshev_dists.round(4), "within_budget": within_budget, "dominant_feature": worst_feature,
})
print(f"L-inf adversarial audit (epsilon={EPSILON}):")
print(f" Samples within budget: {within_budget.sum()} / {N_ADVER}")
print(f" Max perturbation observed: {chebyshev_dists.max():.4f}")
print(f"\nSamples exceeding budget:")
print(results[~within_budget].head(10).to_string(index=False))

Source: domain knowledge

#linear-algebra#spatial-distance-norms-and-analytic-geometry#advanced-distance-and-similarity-metrics

Keyboard shortcuts

Single keys, ignored while typing in a field or with Cmd, Ctrl or Alt held.

0
Home
1 2 3 4
Work, Writing, Tools, About
j / k
Next / previous section on this page
n / p
Next / previous project or essay
u
Up one level
l
Deutsch
t
Light or dark theme
?
This list
Esc
Close