Tutorials › Real Analysis › Distance on the Real Line

Topology of the Real Line · Tutorial 232 of 1000

Distance on the Real Line

Learn how absolute-value distance encodes order and position on the real line, and how to estimate distances between points and to intervals.

Intermediate 10 min read

What You'll Learn

  • Interpret absolute-value differences as distances and relate distance to order on the real line
  • Use translation, reflection, and scaling to calculate distances
  • Apply the reverse triangle inequality to compare distances from a fixed point
  • Identify exactly when equality holds in the triangle inequality
  • Calculate the distance from a point to a closed interval
  • Distinguish distance from a point to a set from whether that distance is attained

Reading Distance from Absolute Difference

In “The Real Line as a Metric Space,” the usual distance between two real numbers was defined by \(d(x,y)=|x-y|\). That formula is simple, but it carries several useful geometric facts. It does not depend on which point is written first, it is unchanged when both points are shifted by the same amount, and it records how far apart the points are without by itself specifying which one is larger.

This tutorial develops those facts and shows how to use them. We will also extend the idea from the distance between two points to the distance from a point to a nonempty set. On the real line, that extension gives a particularly direct formula for distance to a closed interval.

Definition: The usual distance between \(x,y\in\mathbb{R}\) is \(d(x,y)=|x-y|\). For a nonempty set \(E\subseteq\mathbb{R}\), the distance from \(x\in\mathbb{R}\) to \(E\) is \(d(x,E)=\inf\{|x-y|:y\in E\}\).

The first definition measures the separation of two specified points. The second considers all distances from \(x\) to points of \(E\), then takes their infimum. Since these distances form a nonempty set bounded below by \(0\), the infimum exists in \(\mathbb{R}\). It is the greatest lower bound, and it need not be the distance to any particular point of \(E\).

Distance, Order, and Change of Position

For real numbers, absolute value can be written using order: \(|x-y|=x-y\) if \(x\geq y\), and \(|x-y|=y-x\) if \(x<y\). Thus distance is always nonnegative, while the sign of \(x-y\) tells which point lies to the right. The distance alone does not distinguish the two directions: \(d(x,y)=d(y,x)\).

Adding the same real number \(c\) to both points does not change their distance. Multiplying both points by \(c\) changes the distance by the factor \(|c|\). These statements follow directly from the absolute-value formula:

$$ d(x+c,y+c)=|(x+c)-(y+c)|=|x-y|=d(x,y), $$
$$ d(cx,cy)=|cx-cy|=|c|\,|x-y|=|c|d(x,y). $$

The first identity says that shifting the entire real line preserves distances. The second includes reflection when \(c<0\), and collapse of all distances to zero when \(c=0\). These are calculations about this particular metric on \(\mathbb{R}\); they are not additional assumptions about an arbitrary metric space.

Worked Example: Shifting and Rescaling Two Points

Let \(x=-5\) and \(y=3\). Their distance is

$$ d(-5,3)=|-5-3|=|-8|=8. $$

Shift both points by \(4\). The resulting points are \(-1\) and \(7\), and their distance is

$$ d(-1,7)=|-1-7|=|-8|=8. $$

Now multiply the original points by \(-2\), which reflects and rescales them. They become \(10\) and \(-6\), so

$$ d(10,-6)=|10-(-6)|=|16|=16 =|-2|\cdot 8. $$

The calculations illustrate both rules: a common shift preserves the distance, while multiplication by \(-2\) doubles it.

A common source of error is to confuse distance with a signed difference. For example, \(x-y\) can be negative, but \(d(x,y)\) cannot. When order is known, the absolute value can be removed with the appropriate sign; without that order information, replacing \(|x-y|\) by \(x-y\) may give the wrong answer.

The Reverse Triangle Inequality

The triangle inequality bounds the distance between two points by a route through a third point. On the real line it also yields a useful estimate in the opposite direction: changing one endpoint by a small amount cannot change its distance to a fixed point by more than that amount.

Theorem (Reverse Triangle Inequality on \(\mathbb{R}\)): For all \(x,y,z\in\mathbb{R}\), \(\bigl|d(x,z)-d(y,z)\bigr|\leq d(x,y)\).

Proof. By the triangle inequality,

$$ d(x,z)\leq d(x,y)+d(y,z). $$

Subtracting \(d(y,z)\) gives \(d(x,z)-d(y,z)\leq d(x,y)\). Apply the triangle inequality instead to the route from \(y\) to \(z\) through \(x\):

$$ d(y,z)\leq d(y,x)+d(x,z)=d(x,y)+d(x,z). $$

Therefore \(d(y,z)-d(x,z)\leq d(x,y)\) as well. Together, the two inequalities say that the signed difference \(d(x,z)-d(y,z)\) lies between \(-d(x,y)\) and \(d(x,y)\). Taking its absolute value proves the result. \(\square\)

This estimate is called “reverse” because it bounds the difference between two distances by the distance between the points whose locations changed. In absolute-value notation, the same result is

$$ \bigl||x-z|-|y-z|\bigr|\leq |x-y|. $$

Worked Example: Bounding a Change in Distance

Suppose \(x=12\), \(y=9\), and the fixed point is \(z=-4\). The reverse triangle inequality gives

$$ \bigl|d(12,-4)-d(9,-4)\bigr|\leq d(12,9). $$

The distances on the two sides can be checked directly:

$$ d(12,-4)=|12-(-4)|=16,\qquad d(9,-4)=|9-(-4)|=13,\qquad d(12,9)=|12-9|=3. $$

Consequently, \(|16-13|=3\leq3\), so equality holds in this instance. The estimate is useful even when the distances to \(z\) are not known exactly: if \(x\) and \(y\) are within \(0.1\) of each other, their distances to any fixed \(z\) differ by at most \(0.1\).

When Does the Triangle Inequality Become Equality?

The triangle inequality permits equality, but equality has a precise meaning on the real line: the intermediate point must lie between the two endpoints, possibly coinciding with one of them. If the intermediate point lies outside that segment, travelling through it adds extra distance.

Theorem (Equality in the Triangle Inequality on \(\mathbb{R}\)): For \(x,y,z\in\mathbb{R}\), \(d(x,z)=d(x,y)+d(y,z)\) if and only if \(y\) lies between \(x\) and \(z\), inclusive. Equivalently, either \(x\leq y\leq z\) or \(z\leq y\leq x\).

Proof. First suppose \(x\leq z\). If \(x\leq y\leq z\), then \(y-x\geq0\) and \(z-y\geq0\), so

$$ d(x,y)+d(y,z)=|x-y|+|y-z| =(y-x)+(z-y)=z-x=|x-z|=d(x,z). $$

If instead \(y<x\), then \(y<x\leq z\), and

$$ d(x,y)+d(y,z)=(x-y)+(z-y)=z-x+2(x-y)>z-x=d(x,z). $$

If \(y>z\), then \(x\leq z<y\), and

$$ d(x,y)+d(y,z)=(y-x)+(y-z)=z-x+2(y-z)>z-x=d(x,z). $$

Thus, when \(x\leq z\), equality holds exactly when \(x\leq y\leq z\). If \(z\leq x\), interchange the endpoint names \(x\) and \(z\). The distance \(d(x,z)\) remains unchanged, and the same argument shows that equality holds exactly when \(z\leq y\leq x\). These cases include equality at either endpoint and also the case \(x=z=y\). This proves both directions. \(\square\)

Worked Example: Testing Whether a Point Lies Between Two Others

Take the endpoints \(x=-6\) and \(z=5\), and first choose \(y=2\). Since \(-6\leq2\leq5\), the theorem predicts equality. Indeed,

$$ d(-6,5)=|-6-5|=11,\qquad d(-6,2)+d(2,5)=|-8|+|-3|=8+3=11. $$

Now choose \(y=8\), which lies to the right of both endpoints. Then

$$ d(-6,8)+d(8,5)=|-14|+|3|=14+3=17>11=d(-6,5). $$

The intermediate point \(8\) makes the route longer than the direct distance. The strict inequality is not a failure of the metric triangle inequality; it is exactly the situation in which that inequality is not an equality.

Distance from a Point to an Interval

The distance from a point to a set is an infimum, so calculating it requires finding the smallest possible separation, or showing what the greatest lower bound of those separations is. For a closed interval, the answer is determined by whether the point is inside it or outside it.

Theorem (Distance to a Closed Interval): Let \(a,b\in\mathbb{R}\) with \(a\leq b\). For every \(x\in\mathbb{R}\), \(d(x,[a,b])=0\) if \(a\leq x\leq b\), \(d(x,[a,b])=a-x\) if \(x<a\), and \(d(x,[a,b])=x-b\) if \(x>b\).

Proof. If \(a\leq x\leq b\), then \(x\in[a,b]\), so \(|x-x|=0\) is one of the distances used to define \(d(x,[a,b])\). All distances are nonnegative, so their infimum is \(0\).

If \(x<a\), then every \(y\in[a,b]\) satisfies \(y\geq a>x\). Hence \(|x-y|=y-x\geq a-x\). The value \(y=a\) belongs to \([a,b]\) and gives \(|x-a|=a-x\). Therefore \(a-x\) is a lower bound attained among the distances, and \(d(x,[a,b])=a-x\).

If \(x>b\), every \(y\in[a,b]\) satisfies \(y\leq b<x\), so \(|x-y|=x-y\geq x-b\). The endpoint \(y=b\) belongs to the interval and gives \(|x-b|=x-b\). Thus the infimum is \(x-b\). These three cases exhaust the real line and prove the formula. \(\square\)

Worked Example: Finding Distance to a Closed Interval

Consider the interval \([2,7]\). For \(x=10\), we are in the case \(x>b\), so

$$ d(10,[2,7])=10-7=3. $$

This value is attained at the endpoint \(7\), since \(|10-7|=3\); every other point of the interval is farther from \(10\). For \(x=5\), we have \(5\in[2,7]\), and the distance is \(0\), attained at \(y=5\). For \(x=-1\), we are in the case \(x<a\), giving

$$ d(-1,[2,7])=2-(-1)=3. $$

Here the nearest point is the left endpoint \(2\), because \(|-1-2|=3\), while every \(y\in[2,7]\) satisfies \(y-(-1)\geq3\).

Infimum Does Not Always Mean a Nearest Point

For a closed interval, the nearest point exists in all three cases above: it is \(x\) itself when \(x\) is inside, and the nearer endpoint when \(x\) is outside. A general nonempty set need not contain a point that realizes its distance from \(x\). This is why the definition uses an infimum rather than assuming a minimum.

For example, let \(E=(3,8)\) and \(x=3\). Every \(y\in E\) satisfies \(y>3\), so the distances are \(|3-y|=y-3>0\). Given any \(\varepsilon>0\), the point \(y=3+\min\{\varepsilon/2,\,1\}/2\) belongs to \((3,8)\), and its distance from \(3\) is positive and less than \(\varepsilon\). Thus the distances can be made arbitrarily small, and their infimum is \(0\). But \(3\notin E\), and no point of \(E\) has distance \(0\) from \(3\). So \(d(3,E)=0\) even though there is no nearest point in \(E\).

The distinction matters whenever distance to a set is used: an infimum describes how close points of the set can get, not necessarily a point of the set that is closest. For closed intervals the endpoint argument supplies an actual nearest point; for other sets, that conclusion requires a separate justification.

Check Your Understanding

Use the distance formulas and results in this tutorial to answer the following questions.

  1. Why is the distance between \(x\) and \(y\) unchanged when the same real number is added to both?
  2. State the reverse triangle inequality for three real numbers and explain what it bounds.
  3. For which locations of \(y\) does \(d(x,z)=d(x,y)+d(y,z)\) hold?
  4. Find the distance from \(-3\) to the closed interval \([1,9]\), and identify a point of the interval that attains it.
  5. Can the distance from a point to a nonempty set be zero when the point is not in the set? Give the example from this tutorial or another one.