I was recently watching a video on Karatsuba's fast multiplication algorithm and the narrator stated something that intrigued me:
$2^{1.6} \approx 3 $
Specifically, I wondered what power $2$ would need to be raised to in order to be equal to $3$:
$2^p = 3$
Since my knowledge in the field of mathematics is rather lacking, I attempted to brute force the answer in the C# programming language:
double p = 1.5;
for (; Math.Pow(2, p) != 3;)
p += 0.00000000000000000000000000000000000000000000000000000000000001;
Console.WriteLine(p);
Note: This snippet is intended for creating a CodeGolf.SE challenge, so please disregard the abuse of the for
iterator here. It's abused for the sake of brevity.
However, as the incremental value increases in precision, the time it takes to reach an answer, also increases (likely by orders of magnitude), so this is a very inefficient way to determine the value needed for $p$.
What is the most effective way to determine the exponent needed in order for the following to be a true statement when $x$ and $z$ are known:
$$x^y = z$$
Math.pow(2,p)
and3
in your computer language... depending on precision and exactly where things lie... you might pass right over it and hit an infinite loop. Better to have used<
rather than!=
here... – JMoravitz Sep 01 '21 at 14:580.1+0.2
is not identically equal to0.3
in a computer language. https://0.30000000000000004.com/ – JMoravitz Sep 01 '21 at 15:00