I was watching video Lec 2 | MIT 6.046J / 18.410J Introduction to Algorithms (SMA 5503), Fall 2005, where professor Erik Demaine said that $a^{\log_b n}$ is the same as $n^{\log_b a}$. Can someone please explain me why bringing "the $n$ downstairs" and "the $a$ upstairs" is possible?
-
1$\begingroup$ It's a property of logarithm. I hope this link will help. $\endgroup$– RusselMay 5 at 16:20
-
1$\begingroup$ Thanks @Russel. $\endgroup$– Fausto ZamparelliMay 6 at 8:10
4 Answers
Take $\log_b$, and you get $\log_b n \cdot \log_b a$ on both sides.
We can say some number $a = b^{\log_b(a)}$, because $\log_b(a)$ tells us to how much power we need to raise $x$ to get $a$ and then we actually raise it to get $a$.
Then, $$a^k = (b^{\log_b(a)})^k = b^{k\log_b(a)}$$
If $k = \log_b(n)$, then $$a^{\log_b(n)} = b^{\log_b(n)\log_b(a)}$$
Notice that $n = b^{\log_b(n)}$, then:
$$a^{\log_b(n)} = (b^{\log_b(n)})^{\log_b(a)} = n^{\log_b(a)}$$ $$a^{\log_b(n)} = n^{\log_b(a)}$$
$$p^{\log(q)}=e^{\log(p)\log(q)}=q^{\log(p)}$$ holds (also for other bases).
The first result that will be useful is $\ln x^r = r \ln x$, where $\ln$ is the natural logarithm. When the base of the logarithm changes to a different number $a$, the logarithm can be rewritten as a ratio natural logarithms: $\log_a x = \frac{\ln x}{\ln a}$. This can be proved by starting with $y=\log_a x$, or its equivalent equation $x=a^y$ and taking the natural logarithm of both sides. We get $\ln x = \ln a^y$, and applying the first result above gives $\ln x=y \ln a$, from which we get $y = \frac{\ln x}{\ln a}$, i.e. that $\log_a x = \frac{\ln x}{\ln a}$.
To show that $a^{\log_b n}$ and $n^{\log_b a}$ are equal, we show their natural logarithms are equal. After taking logarithms, we can apply the first result above. We get that the logarithm of the first expression is $\log_b n \ln a = \frac{\ln n }{\ln b} \ln a$. The logarithm of the second expression is $\log_b a \ln n = \frac{\ln a }{\ln b} \ln n$. These two ratios are both equal to $\frac{\ln a \ln n}{\ln b}$.