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$

  • $\begingroup$ i is integer, a is not integer $\endgroup$ Apr 9, 2018 at 9:41
  • $\begingroup$ Not correct, function argument must be integer and $a$ is real. $\endgroup$
    – Oldboy
    Apr 9, 2018 at 9:44
  • 1
    $\begingroup$ 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. $\endgroup$
    – lulu
    Apr 9, 2018 at 9:57

1 Answer 1


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)$$


$$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$:

enter image description here

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

  • $\begingroup$ 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$ $\endgroup$ Apr 9, 2018 at 10:29
  • $\begingroup$ My second point is not necessarily true. But please, make a plot, where you plot the minimum, and 1/(2a) as a dashed line $\endgroup$ Apr 9, 2018 at 10:34
  • $\begingroup$ Which zeroes are at the wrong location? $f_{min}=0$ if $a$ is integer. The plot clearly confirms that. $\endgroup$
    – Oldboy
    Apr 9, 2018 at 12:12
  • $\begingroup$ Now its fine. I think yesterday the zeros were for the even numbers only $\endgroup$ Apr 10, 2018 at 13:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.