Equality with floor function and logarithm

2.2k Views Asked by At

Prove that if n is odd then $\lfloor(\log_2(n))\rfloor=\lfloor(\log_2(n-1))\rfloor$. I tried to substitute $n=2k+1$ but it didn't help me in any way.

2

There are 2 best solutions below

0
On BEST ANSWER

One nice way to prove this is to use $$ \tag{0} n = m \;\equiv\; \langle \forall k :: k \le n \equiv k \le m \rangle \\ $$ and $$ \tag{1} k \le \left\lfloor x \right\rfloor \;\equiv\; k \le x \\ $$ where $\;n,m,k\;$ are integers and $\;x\;$ is real.

First use $(1)$ to prove that $\;k \le \left\lfloor \log_2 n \right\rfloor \;\equiv\; 2^k \le n\;$, and $\;k \le \left\lfloor \log_2 (n-1) \right\rfloor \;\equiv\; 2^k < n\;$. Then connect those two using the fact that $\;n\;$ is odd and $\;>1\;$, and finally use $(0)$ to wrap it all up.

0
On

Hint: The quantity $\log_2(n)$ takes integer values only when $n=2^k$ for some $k$. So, the only way for $\log_2(n)$ and $\log_2(n-1)$ to have different floors is...