Math: Why no log 2(x) function?

Many times, things keep doubling, so a LOG2(x) function on a calculator would sure be nice. Yet, there is no log base 2 function. Why not?

You can simulate it easily enough with log(x)/log(2) using log in any base. There are also many situations in which one would want logarithms using base 10 and base e, but there’s no need to clutter up the calculator with a different button for each base. I can’t speak to why they chose this or that in particular, but it’s no great loss; it’s on the same level as having a single SIN button when sometimes one wants to give input in radians and sometimes one wants to give it in degrees.

As a Computer Scientist, of course log base 2 is nearly the only base I ever use. Once in a while I need natural log. Log base 10? Who ever needs that? So if they’re doing 2 buttons on a calculator use bases 2 and e. Got that TI and Casio?

(I’ve also used the golden ratio as a log base, but that’s in my research and not something most computer folk ever need to deal with.)

I’m guessing that ln(x)/ln(2) is how the calculator would calculate it if there were a button for it, and that ln(x)/ln(10) is how it actually does calculate base 10 logs.

I should certainly hope not, given the more efficient and accurate methods of interpolation with Taylor series and similar we’ve had for decades now.

Numerical analysis is a complex and subtle field with one constant: The obvious algorithm is almost always wrong.

What would be more efficient or accurate than using the built-in algorithm for ln(x) and multiplying the result by the (stored) constant 1/ln(10)?

As an electrical engineer, I use log[sub]10[/sub] and natural logs, but rarely log[sub]2[/sub]. I guess we can tell who designs the calculators. :wink:

As for Taylor series: While it’s a lovely thing and is taught all over the place, it is rarely used in simple computer math applications. In particular, for things like logs it is horrid and then some. I assume your “and similar” refers to things like Chebyshev Polynomials which are great for the trig functions and other well behaved things.

For a cheap calculator, re-using existing functions (like log to a given base and multiplication) to compute a third is much, much more likely than putting in new code. The only reason to create new code is if you were losing too much accuracy by combining functions.

Keep in mind that the earliest pocket calculators did multiplication by repeated shift-and-add method. Horribly slow by hand. Even a 70s vintage calculator would finish by the time you lifted your finger off the ‘X’ button.

All of the texts that I’ve read on the implementation of math libraries use polynomial approximations. Many calculators and other constrained devices use CORDIC.

On the PC, the only native log function IS log2(x). The FPU also holds constants for multiplying this result to get the other base logs.

Chebyshev Polynomials are polynomial approximations. Less error with far fewer terms than Taylor’s. Looked up CORDIC on Wikipedia. Very nice, shift-and-add carried to an extreme.

More precisely, they have more uniform error. When you do a Taylor series approximation, you’re always expanding around some point (often 0). If you’re really close to that point, then you’ll have a really good approximation, but as you get further away, the approximation gets worse and worse. For most functions, there’s some distance from the central point, called the radius of convergence, past which the Taylor series just goes completely haywire, and you’ll never get a good approximation, no matter how many terms you use.

With a Chebyshev polynomial, by contrast, instead of optimizing the fit near a single point, you’re optimizing it across a region of finite size. The approximation is about equally good for any point within that region. At any given order, a Taylor series approximation will be better than a Chebyshev approximation near the center point, but it’ll be worse than the Cheb at points far from the center point. So if you have a requirement that the function always be good to within, say, one part in a million, and you need this accuracy everywhere in the domain of the function, the Chebyshev polynomial will do the job with fewer terms than the Taylor series will.

Just curious…what kinds of things do you use log[sub]10[/sub] for?

I seem to remember my high-school maths textbook said base-10 logarithms were common simply because slide rules and log tables were much easier to use in base-10.

But if you’re using a calculator, you don’t really need a slide rule or log table (unless there’s something they can do that calculators can’t). So what is the log[sub]10[/sub] button used for?

Electrical engineers use base 10 logs for calculations involving gain.

I’m also curious about Derleth’s remark.

:smack: Dammit, I knew that.

Well, I didn’t know about gain in particular, but I did know that there are several quantities that are commonly expressed as base-10 logarithms (sound intensity, seismic energy, acidity/alkalinity, etc.).

You think that’s crazy? In my field, we routinely work with logs to the base of the fifth root of 100. Well, we generally recast them in terms of base 10, but that’s what they really are.