The earlier publish required computing
After writing the publish, I thought of how you’d mentally approximate log2 5. Essentially the most crude approximation would spherical 5 all the way down to 4 and use log2 4 = 2 to approximate log2 5. That might be ok for an order of magnitude guess, however we will do a lot better with out an excessive amount of extra work.
Easy approximation
I’ve written earlier than in regards to the approximation
for x between 1/√2 and √2. We will write 5 as 4 (5/4) and so
How correct is that this? The precise worth of log2 5 is 2.3219…. Approximating this quantity by 7/3 is a lot better than approximating it by simply 2, lowering the relative error from 16% all the way down to 0.5%.
Origin story
The place did the approximation
come from?
I don’t bear in mind the place I discovered it. I wouldn’t be stunned if it was from one thing Ron Doerfler wrote. However how would possibly somebody have derived it?
You’d like an approximation that works on the interval from 1/√2 to √2 as a result of you possibly can at all times multiply or divide by an influence of two to scale back the issue to this interval. Rational approximations are the same old solution to approximate capabilities over an interval [1], and for psychological calculation you’d wish to use the bottom order doable, i.e. diploma 1 within the numerator and denominator.
Right here’s how we may ask Mathematica to discover a rational approximation for us [2].
Simplify[
    N[
        ResourceFunction["EconomizedRationalApproximation"][
            Log[2, x], { x, {1/Sqrt[2], Sqrt[2]}, 1, 1}]]]
This returns
(2.97035 x − 2.97155) / (1.04593 + x)
which we spherical off to
(3 x − 3) / (1 + x).
The N perform turns a symbolic consequence into one with floating level numbers. With out this name we get a sophisticated expression involving sq. roots and logs of rational numbers.
The Simplify perform returns an algebraically equal however less complicated expression for its argument. In our case the perform finishes the calculation by eradicating some parentheses.
Associated posts
[1] Energy sequence approximations are simpler to compute, however energy sequence approximations don’t give the very best accuracy over an interval. Energy sequence are wonderful on the level the place they’re centered, however degrade as you progress away from the middle. Rational approximations unfold the error extra uniformly.
[2] I first tried utilizing Mathematica’s MiniMaxApproximation perform, but it surely bumped into numerical issues, so I switched to EconomizedRationalApproximation.
