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

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

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 ipi, so when evaluating your expression it would replace ipi with ipi and wind up with "eipi". It might also have an internal rule saying eipi resolves into -1. And voila!

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

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

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]ipi[/sup], it computes e[sup]0[/sup](cos(pi) + i sin(pi)) = -1.

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 + ipi + -pi^2/2 - ipi^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 ]

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.

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

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.