# How does my calculator know that e^(i\*pi)=-1?

**URL:** <https://boards.straightdope.com/t/how-does-my-calculator-know-that-e-i-pi-1/334117>\
**Category:** Factual Questions\
**Created:** [December 5, 2005, 1:52am UTC](https://boards.straightdope.com/t/how-does-my-calculator-know-that-e-i-pi-1/334117 "2005-12-05T01:52:23Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![quelquechose](https://avatars.discourse-cdn.com/v4/letter/q/6f9a4e/32.png) [@quelquechose](https://boards.straightdope.com/u/quelquechose)\
**Post date:** [December 5, 2005, 1:52am UTC](https://boards.straightdope.com/t/how-does-my-calculator-know-that-e-i-pi-1/334117/1 "2005-12-05T01:52:23Z")

</div>

How does a computer algebra system (like that in my TI-89) simplify expressions like e^(i\*pi)? How does it simplify in general?

---

<div class="post-metadata">

**Author:** ![groman](https://avatars.discourse-cdn.com/v4/letter/g/73ab20/32.png) [@groman](https://boards.straightdope.com/u/groman)\
**Post date:** [December 5, 2005, 2:48am UTC](https://boards.straightdope.com/t/how-does-my-calculator-know-that-e-i-pi-1/334117/2 "2005-12-05T02:48:11Z")

</div>

It most likely builds what is called an “expression tree” of your expression, so e^(i\*pi) is expressed as a tree (let me attempt):

```
  ^

```

/   
e \*  
/   
i pi

It then probably has a lot of internal “terminals” that certain basic expressions can be resolved into. For example, it could have a terminal called ipi which only resolves to i_pi, so when evaluating your expression it would replace i_pi with ipi and wind up with "e_ipi". It might also have an internal rule saying e_ipi resolves into -1. And voila!

This is only an example of how that can be accomplished.

---

<div class="post-metadata">

**Author:** ![groman](https://avatars.discourse-cdn.com/v4/letter/g/73ab20/32.png) [@groman](https://boards.straightdope.com/u/groman)\
**Post date:** [December 5, 2005, 2:51am UTC](https://boards.straightdope.com/t/how-does-my-calculator-know-that-e-i-pi-1/334117/3 "2005-12-05T02:51:55Z")

</div>

Ugh, why didn’t I preview that tree, is there a way to add non-breaking spaces to a vBulletin post?

---

<div class="post-metadata">

**Author:** ![JustAnotherGeek](https://avatars.discourse-cdn.com/v4/letter/j/58f4c7/32.png) [@JustAnotherGeek](https://boards.straightdope.com/u/JustAnotherGeek)\
**Post date:** [December 5, 2005, 2:59am UTC](https://boards.straightdope.com/t/how-does-my-calculator-know-that-e-i-pi-1/334117/4 "2005-12-05T02:59:23Z")

</div>

> [@groman](#):
>
> Ugh, why didn’t I preview that tree, is there a way to add non-breaking spaces to a vBulletin post?

Use the [code] command.

Cheers  
-Geek

---

<div class="post-metadata">

**Author:** ![Topologist](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/topologist/32/3208_2.png) [@Topologist](https://boards.straightdope.com/u/Topologist)\
**Post date:** [December 5, 2005, 3:35am UTC](https://boards.straightdope.com/t/how-does-my-calculator-know-that-e-i-pi-1/334117/5 "2005-12-05T03:35:38Z")

</div>

To answer the more specific question: The calculator knows that, when evaluating _e_ raised to a complex power, _e[sup]a+bi[/sup] = e[sup]a[/sup]_(cos(_b_) + _i_ sin(_b_)). So, to evaluate _e_[sup]_i_pi[/sup], it computes _e_[sup]0[/sup](cos(pi) + _i_ sin(pi)) = -1.

---

<div class="post-metadata">

**Author:** ![Citizen\_Bob](https://avatars.discourse-cdn.com/v4/letter/c/f07891/32.png) [@Citizen\_Bob](https://boards.straightdope.com/u/Citizen_Bob)\
**Post date:** [December 5, 2005, 7:34am UTC](https://boards.straightdope.com/t/how-does-my-calculator-know-that-e-i-pi-1/334117/6 "2005-12-05T07:34:17Z")

</div>

> [@quelquechose](#):
>
> How does a computer algebra system (like that in my TI-89) simplify expressions like e^(i\*pi)? How does it simplify in general?

My guess is that, like with almost every other expression, the associated series is used. For e, the MacLaurin series is

f(x) = e^x = 1 + x/(1!) + (x^2)/(2!) + (x^3)/(3!) + … [for any x, Real, Imaginary or Complex]

If it can handle simple complex mult and add, then if x = i\*(pi), then

e^(i\*(pi)) = 1 + i_pi + -pi^2/2 - i_pi^3/6 + …

Separating the Real and Imag components:

Real:  
e^i\*pi = 1 - pi^2/2 + pi^4/24 + … = -1 [If you are up on your power series]

Imag:  
+ i\*( pi - pi^3/6 + …) = i\*0 = 0 [if you are up on your power series]

```
       = -1 + 0i [Grand Total]

```

* * *

It’s so much easier to store an associated series for a designated function than to store every single freakin’ value for every single function. Every calculator I’ve ever used just takes the series out far enough so that uncertain decimal places are off the end of the display. If you would like to know what they are, try this site:  
[[http://mathworld.wolfram.com/MaclaurinSeries.html](http://mathworld.wolfram.com/MaclaurinSeries.html) ]

---

<div class="post-metadata">

**Author:** ![Cabbage](https://avatars.discourse-cdn.com/v4/letter/c/f07891/32.png) [@Cabbage](https://boards.straightdope.com/u/Cabbage)\
**Post date:** [December 5, 2005, 8:11am UTC](https://boards.straightdope.com/t/how-does-my-calculator-know-that-e-i-pi-1/334117/7 "2005-12-05T08:11:46Z")

</div>

> [@Citizen Bob](#):
>
> It’s so much easier to store an associated series for a designated function than to store every single freakin’ value for every single function. Every calculator I’ve ever used just takes the series out far enough so that uncertain decimal places are off the end of the display. If you would like to know what they are, try this site:  
> [[http://mathworld.wolfram.com/MaclaurinSeries.html](http://mathworld.wolfram.com/MaclaurinSeries.html) ]

I’m certainly no expert on the algorithms calculators use, but it’s my impression that most calculators don’t actually use series for these sorts of computations.

I think trig functions, for example, are generally calculated by an algorithm which

1. Has certain (precalculted) values stored in memory, and
2. Interpolates to calculate the rest.

It might be easier to use series to calculate trig functions (it’s certainly the method I would use if I had to program a calculator to perform trig functions, simply because I’m not really familiar with other methods), but I expect the method of storing values and interpolating others is quicker.

---

<div class="post-metadata">

**Author:** ![mks57](https://avatars.discourse-cdn.com/v4/letter/m/b9bd4f/32.png) [@mks57](https://boards.straightdope.com/u/mks57)\
**Post date:** [December 5, 2005, 12:20pm UTC](https://boards.straightdope.com/t/how-does-my-calculator-know-that-e-i-pi-1/334117/8 "2005-12-05T12:20:25Z")

</div>

> [@Citizen Bob](#):
>
> It’s so much easier to store an associated series for a designated function than to store every single freakin’ value for every single function. Every calculator I’ve ever used just takes the series out far enough so that uncertain decimal places are off the end of the display.

I’ve never seen a calculator or computer math library that used the series approximation for a function. CORDIC is popular on calculators, while polynomial approximations are the norm for computers. There are a number of textbooks [1] that have tables of polynomial coefficients for implementing math libraries at varying degrees of precision.

[1] W. J. Cody, Jr. and W. Waite. Software Manual for the Elementary Functions. Prentice Hall, Englewood Cliffs, New Jersey, 1980.

---

<div class="post-metadata">

**Author:** ![Citizen\_Bob](https://avatars.discourse-cdn.com/v4/letter/c/f07891/32.png) [@Citizen\_Bob](https://boards.straightdope.com/u/Citizen_Bob)\
**Post date:** [December 5, 2005, 3:17pm UTC](https://boards.straightdope.com/t/how-does-my-calculator-know-that-e-i-pi-1/334117/9 "2005-12-05T15:17:49Z")

</div>

> [@mks57](#):
>
> I’ve never seen a calculator or computer math library that used the series approximation for a function. CORDIC is popular on calculators, while polynomial approximations are the norm for computers. There are a number of textbooks [1] that have tables of polynomial coefficients for implementing math libraries at varying degrees of precision.
> 
> [1] W. J. Cody, Jr. and W. Waite. Software Manual for the Elementary Functions. Prentice Hall, Englewood Cliffs, New Jersey, 1980.

Ugh, CORDIC interpolative algorithms - I don’t know how it slipped my mind! :smack: I’ve never tried these by hand 🙂

Let’s see if I can find another good CORDIC ref - so that I might contribute something better than my last post:  
[http://www.emesystems.com/BS2mathC.htm](http://www.emesystems.com/BS2mathC.htm)

Power series work, but can be haphazard near sigularities. CORDIC is even more compact and you can also do trans functions… I must be losing my mind.
