2

Mathematics behind a calculator

I have tried googling around for a bit, but I lack the technical terms and mathematical knowledge to find results that gives me mathematical intuition about how a calculator work mathematically.

If you have time, please give me a short or long description on how a calculator works. If it is a long and thorough answer, I will start a bounty on 50 rep to award this answer with.

Otherwise, it will suffice with terms so that I may research further on what is "in" a calculator.

I sincerely hope that I have not misunderstood the concept behind a calculator, please leave me a comment if so.

PS I want to know how a calculator calculates more advanced expressions, not just division but, for example, $e$, $\sum$, $\int$, trigonometric functions and et cetera.

Andreas
  • 1,948
  • 2
  • 16
  • 45
  • 2
    This is an extremely broad question. https://en.wikipedia.org/wiki/Numerical_analysis could be a starting point. – Hans Lundmark Mar 01 '17 at 21:04
  • @HansLundmark Jag tänkte nästan det, men tack för ditt förslag av "starting point". +1 – Andreas Mar 01 '17 at 21:09
  • 1
    I have heard that many calculators use CORDIC for calculating e.g. the trig functions. Cordic is the only way on some devices - not 100% about modern calculators though. Lycka till :-) – Jyrki Lahtonen Mar 01 '17 at 21:09
  • Varsågod. Lycka till! :-) – Hans Lundmark Mar 01 '17 at 21:10
  • 1
    The answer on this question is simply taylor series. –  Mar 01 '17 at 22:14
  • 1
    @Math_QED Could you give an example of one? – Andreas Mar 01 '17 at 22:16
  • 5
    @Math_QED And also back it up with documentation. Conceivably you could use Taylor expansions to calculate e.g. trig functions in some smallish interval, and convert the rest in there. But relying on Taylor series alone for trig functions (or exponential) does not feel sensible at all. You need a lot of terms to get a tolerable cut-off error. – Jyrki Lahtonen Mar 01 '17 at 22:39
  • A calculator, whether implemented as a device or in software, typically offers basic arithmetic operations and some higher level functions. Please clarify whether your Question is about how to implement these separate operations (e.g. division vs. square root) or about how to combine/tie together the intermediate results into a final result. The latter topic involves "stack manipulation" (e.g. reverse polish notation promoted by HP calculators). – hardmath Mar 22 '17 at 01:57

3 Answers3

2
  • Many of these calculations are done using series. For example, the value of $e$ (if not saved in a hard-drive) can be calculated as: $$ e = \sum_{n=0}^{\infty} \frac{1}{n!} $$ Altough there are many other examples, for sine, cosine, and et cetera, that are calculated using series. Note that a calculator can't sum infinite terms, so they will sum a finite (however large) number of parcels to give you an decent approximation of the actual value.
  • For integrals and derivatives, there are a lot of algorithms who can do this, and to better understand them you can start studying a topic called numerical analysis, which is a "way" of evaluating integrals, derivatives and other operators, using computer algorithms. At the end of the day, all of those reduce to the simplest operations such as addition or multiplication. Lets think, for example, in a simple, intuitive algorithm to evaluate the derivative of $f(x) = x^2$ at $x=2$:

    1. Define an small $h$, such as $h = 0.000001$.
    2. Use of the derivative formula. Calculate $(2+0.000001)^2 - 2^2$
    3. Divide the result by $0.000001$.
    4. Return the value of the fraction.

You can do this calculation and you'll verify that approximates the value of the derivative. However, there are much more complex, efficient and exact algorithms out there to evaluate these calculations. Numerical Analysis is an very interesting topic.

embedded_dev
  • 1,261
0

$\newcommand{\bbx}[1]{\,\bbox[8px,border:1px groove navy]{\displaystyle{#1}}\,} \newcommand{\braces}[1]{\left\lbrace\,{#1}\,\right\rbrace} \newcommand{\bracks}[1]{\left\lbrack\,{#1}\,\right\rbrack} \newcommand{\dd}{\mathrm{d}} \newcommand{\ds}[1]{\displaystyle{#1}} \newcommand{\expo}[1]{\,\mathrm{e}^{#1}\,} \newcommand{\ic}{\mathrm{i}} \newcommand{\mc}[1]{\mathcal{#1}} \newcommand{\mrm}[1]{\mathrm{#1}} \newcommand{\pars}[1]{\left(\,{#1}\,\right)} \newcommand{\partiald}[3][]{\frac{\partial^{#1} #2}{\partial #3^{#1}}} \newcommand{\root}[2][]{\,\sqrt[#1]{\,{#2}\,}\,} \newcommand{\totald}[3][]{\frac{\mathrm{d}^{#1} #2}{\mathrm{d} #3^{#1}}} \newcommand{\verts}[1]{\left\vert\,{#1}\,\right\vert}$ $\ds{\large\bullet}$ Constants like $\ds{\expo{}}$, $\ds{\ln\pars{2}}$, $\ds{\pi}$, etc$\ldots$ can be kept, with some finite number of decimals, in a 'hard disk'.

$\ds{\large\bullet}$ Many functions are evaluated in 'small intervals'. For example, $\ds{\root{x}}$ just need to be evaluated in $\ds{\pars{0,1}}$ because $\ds{\root{x} = 1/\root{1/x}}$. Similarly, $\ds{\ln\pars{x} = -\ln\pars{1/x}}$. Newton-Rapson Method is helpful for evaluations in $\ds{\pars{0,1}}$.

Felix Marin
  • 89,464
0

The computational unit underlying computer mathematics is the Arithmetic Logic Unit (ALU), which is a combinatorial circuit that performs the basic functions of addition, subtraction, multiplication, division, negation (inversion), absolute value and a few other functions on binary numbers. Person-centuries have gone into optimizing these circuits for speed, accuracy, and functionality.

As @FelixMartin points out, it is very simple to store constants such as $e$, $\pi$, etc.

Beyond such a high-level "explanation," one would need to know precisely what you're seeking.