1
$\begingroup$

Is it possible to solve for $i$ in the following equation?

EDIT- WolframAplha says it is possible but how do I do it?

$$\left \lfloor{\displaystyle \frac n{2^i}}\right \rfloor =1 $$

I am not sure on how to separate the floor to solve for $i$

$\endgroup$
1
  • $\begingroup$ If $\floor{x}=1$ then $1≤x<2$. Then just solve the inequality. $\endgroup$ – kadoodle May 30 '18 at 6:40
3
$\begingroup$

$\lfloor x \rfloor = 1$ if and only if $1 \le x < 2$. Thus you want $2^i \le n < 2^{i+1}$. Take base-$2$ logarithms of both sides, and you find $i = \lfloor \log_2(n) \rfloor$.

$\endgroup$
0
$\begingroup$

We can introduce a slack variable $\epsilon$: $$ 1 = \lfloor n / 2^i \rfloor = n/2^i - \epsilon \quad (\epsilon \in [0,1)) $$ Then $$ 1 + \epsilon = n / 2^i \iff \\ 2^i = n /(1+ \epsilon) \iff \\ i = \log_2(n/(1+\epsilon)) $$ This means $$ \log_2(n/2) < i \le \log_2(n) $$ You might want $i \in \mathbb{Z}$ as well (going by the name). Because we have $$ \log_2(n) - \log_2(n/2) = \log_2(n/(n/2)) = \log_2(2) = 1 $$ we can now go reverse and have $$ i = \log_2(n) - \epsilon' = \lfloor \log_2(n) \rfloor \quad (\epsilon' \in [0,1)) $$

$\endgroup$

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.