# Find minimum of simple expression over integers

I'm interested in minimizing an expression

$F(i) = |1 - \frac{a}{i}|$

where $a > 1.0$ is a known positive real number, and $i$ is a positive integer.

EDIT: In particular, I am interested in how the minimum scales with $a$

EDIT 2: Ok, I found my answer. By noticing that reals and integers can only differ by 0.5, and doing a tiny bit of math, one arrives at

$F_{min} \in [0, \frac{1}{2a}]$ and thus the minimum scales inverse-linearly with $a$

• i is integer, a is not integer Apr 9, 2018 at 9:41
• Not correct, function argument must be integer and $a$ is real. Apr 9, 2018 at 9:44
• Not seeing a terribly elegant answer. Barring error (and excluding $a\in \mathbb N$), it is $\lfloor a \rfloor$ iff $2\{a\}<\frac {\lfloor a \rfloor}{\lfloor a \rfloor+1}$, and $\lfloor a \rfloor+1$ otherwise.
– lulu
Apr 9, 2018 at 9:57

## 1 Answer

Denote with $\lfloor a \rfloor$ the biggest integer no greather than $a$ and with $\lceil a \rceil$ the smallest integer no less than $a$. In other words $\lfloor 2.0 \rfloor = \lceil 2.0 \rceil = 2$, $\lfloor 2.2 \rfloor = 2$, $\lceil 2.2 \rceil = 3$

If $i\ge a$:

$$f(i) = \frac{|i-a|}{a}=\frac{i-a}{a} =1-\frac{a}{i}$$

This epxression reaches minimal value for x=$\lceil a \rceil$ and the minimal value is:

$$f_1 = 1 - \frac{a}{\lceil a \rceil}$$

If $i\lt a$:

$$f(i) = \frac{|i-a|}{a}=\frac{a-i}{a} =1-\frac{i}{a}$$

This epxression reaches minimal value for x=$\lfloor a \rfloor$ and the minimal value is:

$$f_2 = 1 - \frac{\lfloor a \rfloor}{a}$$

Minimum value of $f(i)$ for a given $a$ is:

$$f_{min}=min \left(1 - \frac{a}{\lceil a \rceil},1 - \frac{\lfloor a \rfloor}{a}\right)$$

or:

$$f_{min}=1 - max \left(\frac{a}{\lceil a \rceil},\frac{\lfloor a \rfloor}{a}\right)$$

Here is the graph of $f_{min}$ as a function of $a$:

Red line represents asymptotic boundary of $f_{min}$: $\frac1{2x}$

• Cool solution, but there is something wrong with your plot. x-axis does not have zeros at the right locations, and I would expect the maximum of the minimum errors to decay linearly with $a$ Apr 9, 2018 at 10:29
• My second point is not necessarily true. But please, make a plot, where you plot the minimum, and 1/(2a) as a dashed line Apr 9, 2018 at 10:34
• Which zeroes are at the wrong location? $f_{min}=0$ if $a$ is integer. The plot clearly confirms that. Apr 9, 2018 at 12:12
• Now its fine. I think yesterday the zeros were for the even numbers only Apr 10, 2018 at 13:25