# How to mathematically express the minimum difference between a number and an interval of numbers?

Suppose $$x \in \mathbb{R}$$, and $$y \in [a, b]$$, where $$a, b \in \mathbb{R}$$. I want to minimize the difference between $$x$$ and $$y$$ but am not sure how to write it in mathematical notation.

For example, if $$x = 10$$, and $$y \in [11, 35]$$, then the minimum difference between $$x$$ and $$y$$ is 1.

The way that I came up with is: $$min\{|x - y|\}$$. Is this correct?

• Not quite sure what you are asking. If $a≤x≤b$ the answer is $0$, right? Otherwise if $x<a$ then the answer is $(a-x)$ and if $x>b$ the answer is $(x-b)$. Or have I misunderstood the question ?
– lulu
Apr 15, 2023 at 1:08
• See "distance from a point to a set" in metric topology: $d(x,[a,b]) := \inf\{d(x,y)\text{ }|\text{ }y\in [a,b]\}$. Apr 15, 2023 at 1:15
• Note that $\min \{\vert y-x\vert \} = \vert y-x \vert$ since it's a singleton. Apr 15, 2023 at 1:27
• $$\begin{cases} 0 &: x \in [a, b]\\ a - x &: x < a\\ x - b &: x > b \end{cases}$$ Apr 15, 2023 at 3:02

Add a specification to your set to identify the possible values of $$y$$:
$$\min\{ |x - y|\ |\ y \in [a, b]\}.$$
But as in Kevin's comment above, you may want to replace the minimum by the infimum. In the case you are describing, they are equivalent, but if you want to find the distance from a point to an open interval, say, the minimum distance may be undefined. For example, $$\min\{ |10 - y|\ |\ y \in (11, 35)\}$$ is undefined, while $$\inf\{ |10 - y|\ |\ y \in (11, 35)\} = 1$$.
For any interval which has a real midpoint $$m$$ and a non-negative length $$l$$, $$\left(\frac{2m\ -\ l\ -\ 2x}{2}\right)\ H\left(\frac{2m\ -\ l\ -\ 2x}{2}\right)\ +\ \left(\frac{2x\ -\ 2m\ -\ l}{2}\right)\ H\left(\frac{2x\ -\ 2m\ -\ l}{2}\right)$$ where $$H()$$ is the Heaviside function should return this distance as a function of $$x$$.