Comments on: How does my pocket calculator do this?
http://ask.metafilter.com/6122/How-does-my-pocket-calculator-do-this/
Comments on Ask MetaFilter post How does my pocket calculator do this?Sun, 28 Mar 2004 10:48:02 -0800Sun, 28 Mar 2004 10:48:02 -0800en-ushttp://blogs.law.harvard.edu/tech/rss60Question: How does my pocket calculator do this?
http://ask.metafilter.com/6122/How-does-my-pocket-calculator-do-this
How does my pocket calculator do this? <br /><br /> I've got an old pocket calculator that I'm playing around with when I'm bored. If I enter a very small number, like 1.000,000,001, and raise it to the power of 10<sup>11</sup> it takes less than two seconds to get the answer. I don't know much about computing but I don't think my ten year old calculator can multiply that number by itself 100 billion times within two seconds. So how does it do it? Does it use some kind of mathematical shortcuts?<br>
<br>
<small>More about calculators cutting corners if anyone's interested. At work, we sell calculators. Once a girl came back and complained about her Texas Instruments TI-83 graphical calculator: it gave the wrong answer. She showed me: a calculation where the result should be exactly zero was not zero but a very small number. This was beyond me, so I called Texas customer support, and they explained that this was because of the algorithm the calculator used. In other words, it's not a bug, it's a feature. But a cheap 12 dollar calculator was able to give the correct answer.</small>post:ask.metafilter.com,2004:site.6122Sun, 28 Mar 2004 10:06:49 -0800TermitecalculatormathcalculationBy: andrew cooke
http://ask.metafilter.com/6122/How-does-my-pocket-calculator-do-this#127014
the exponentiation might done with logarithms:<br>
log(x^y) = y * log(x), so x^y = invlog(y * log(x))<br>
<br>
in that case the calculator would need to know how to calculate the logairthm from a number (log(...)) and get a number back from a logarithm (invlog(...)). there are ways to do this (i think it's what babbage was trying to do, in a way, with his mechanical computers).<br>
<br>
your other point, about small differences, is because calculators can't store some fractions that you can write down easily in decimal as binary. for example 1/2 is 0.5 in decimal and 0.1 in binary, but 9/10, which is 0.9 in decimal, is something like 0.1110011... (it keeps going for ever, just like 1/3 is 0.33333.... in decimal).<br>
<br>
so some numbers aren't stored exactly in a calculator and this lets errors creep in. different calculators handle this in different ways. some display less digits than they have information for, so a very small number would be displayed as 0. that's probably what is happening in your case (either that or it uses slightly different algorithms which, in that particular example, didn't give an error - perhaps because two errors cancelled each other out!)comment:ask.metafilter.com,2004:site.6122-127014Sun, 28 Mar 2004 10:48:02 -0800andrew cookeBy: andrew cooke
http://ask.metafilter.com/6122/How-does-my-pocket-calculator-do-this#127016
actually, there's another reason for errors too, that i forgot. calculators only store a limited number of digits, plus a "size". so <br>
12345678901234567890 might be stored as 1.23456 * 10^19 (the calculator stores the digits "123456" and "19" and knows how to display them as you expect). so, again, what's in the calculator's memory isn't the number you expect and you get odd results.comment:ask.metafilter.com,2004:site.6122-127016Sun, 28 Mar 2004 10:59:28 -0800andrew cookeBy: Galvatron
http://ask.metafilter.com/6122/How-does-my-pocket-calculator-do-this#127025
<i>in that case the calculator would need to know how to calculate the logairthm from a number (log(...)) and get a number back from a logarithm (invlog(...)). there are ways to do this</i><br>
<br>
To expand on andrew cooke's answer: most of the elementary functions (exp(x), log(x), sin(x), etc...) have <a href="http://mathworld.wolfram.com/TaylorSeries.html">Taylor series expansions</a> that provide good approximations with a small number of terms--at least few enough that the calculator can add them up before you notice a big delay.<br>
<br>
Many other functions have Taylor series expansions that do not converge quickly enough to evaluate a function in a split second. However, more often than not, there will be <i>some</i> series expansion (perhaps not Taylor) that will work. For example, one can approximate a factorial by writing it in terms of the <a href="http://mathworld.wolfram.com/GammaFunction.html">Euler Gamma function</a>, which can be rapidly approximated by the <a href="http://mathworld.wolfram.com/LanczosApproximation.html">Lanczos approximation</a>.comment:ask.metafilter.com,2004:site.6122-127025Sun, 28 Mar 2004 12:11:14 -0800GalvatronBy: jmd82
http://ask.metafilter.com/6122/How-does-my-pocket-calculator-do-this#127026
For the TI-83, I forget which one, but they can't <b>actually</b> perform all of the four basic functions. Something like they multiply by actually adding the number each time or something like that which can lead to very very exact numbers being off. Also, I know for integration and derivatin, calculators don't actually know how to perform them, but simply use algorithms of some of the 4 basic functions.comment:ask.metafilter.com,2004:site.6122-127026Sun, 28 Mar 2004 12:23:54 -0800jmd82By: stuart_s
http://ask.metafilter.com/6122/How-does-my-pocket-calculator-do-this#127059
Taylor series expansions are computationally expensive. Handheld calculators more commonly use an algorithm called CORDIC. It computes sin, arcsin, ln, etc... with only addition, shifting and table lookup. I think it's a beautiful example of engineering and a fascinating example of something that is fundamental to many of our daily lives yet goes completely ignored.<br>
<br>
<a href="http://www.swarthmore.edu/NatSci/smaurer1/Math6B/calculatorsParris-rev.pdf"><em>Elementary Functions and Calculators</em>, Richard Parris</a> (PDF)comment:ask.metafilter.com,2004:site.6122-127059Sun, 28 Mar 2004 14:50:02 -0800stuart_sBy: Galvatron
http://ask.metafilter.com/6122/How-does-my-pocket-calculator-do-this#127079
Well, OK, if we're going to get all <i>serious</i>, then <a href="http://rkb.home.cern.ch/rkb/AN16pp/node30.html">Chebyshev series</a> (which can be related to the Taylor expansion) are used a lot, as well as various types of <a href="http://mathworld.wolfram.com/PadeApproximant.html">rational approximations</a>. The ideal algorithm to use in a given situation depends not only on the overall convergence rate, but also on the speed of various operations within the processor. (Yeah, CORDIC is real good if you have a processor that doesn't know how to multiply fast, like many pocket calculators. If you have a fast multiply operation available, polynomial approximations are usually better.)<br>
<br>
But Taylor series are a whole lot easier to talk about, and they can be fast if you have the capability to table coefficients for multiple expansion points.<br>
<br>
<small>Good link regarding CORDIC, btw.</small>comment:ask.metafilter.com,2004:site.6122-127079Sun, 28 Mar 2004 17:51:58 -0800Galvatron