August 17, 2007

Close Enough?

I have long admired the formula often known as Euler's identity. It was probably known before Euler's time, but it is associated inextricably with his name because it is a special case of a more general formula, with π as the value of the bound variable. The identity asserts that

To me this is a thing of beauty and a joy forever, but I have long since given up trying to explain to other people why or how I perceive beauty in mathematics. Anyway I thought I would see how close my trusty laptop could get to emulating this mystic identity (it's amazing what I get up to when procrastinating), and naturally chose Python (though I believe the results would be just as disappointing in any other language). Here's what I got:

>>> math.e**(math.pi*-1j)

Definitely not quite the same mystical properties there, even though numerically quite close. No wonder I never liked applied mathematics!


Dalius said...

>>> (e**(pi*-1j)).real
>>> (e**(pi*-1j)).imag
>>> '%1.16f' % (e**(pi*-1j)).imag

Maybe that's not good enough for spaceship but it is enough precise for many tasks.

Have I missed something?

Richard Jones said...

That computer-(im)precise result a little sad, isn't it.

Having said that, I was procrastinating at work today, and was also let down by computers when I discovered that the graphics hardware in my Powerbook couldn't handle a GL fragment shader with a nested for loop.

I guess it's just a day for being disappointed with computers.

Steve said...


You aren't missing amything at all. It might even be good enough for spaceships. I was merely struck by the incongruity of the result in the Python interpreter and the simple beauty of the formula.

Perhaps you are reading too much into my remarks ... note that the post was also tagged "humor".


Sometimes our expectations are artificially high ... how spoiled we are in our little techno-bubbles :-)

Anonymous said...

I don't know anyone who has any aptitude for math that doesn't have some degree of appreciation for that simple equation.

However, I personally prefer the equivalent form:

e(^pi*i) + 1 = 0

To me, that works five of the "fundamental constants of the universe" into one formula.

Steve said...

I see that, and I have seen other arguments to the same effect, and yet somehow I can't help regarding it as "less canonical" than the form I quoted - even though I realize that quadratics are always canonicalized to equality with zero, I can't help preferring

      x = -1


      x + 1 = 0

If this makes me somehow deficient as a mathematician then I guess I'll just have to live with that. I suppose if I wanted to be linguistically tricky I would say that your rewrite adds nothing to the original :-)

Anonymous said...

How clever a word play!

Delightfully subtle.

I fit this into the category of 'personal preference'. I see nothing 'wrong' with either form. (Of course, it's the longer version that I have posted on my cube wall, along with a printout of the first 10k digits of pi that I generated on my Apple ][ back in '81, and a few other artifacts I've gathered through the years.) But I certainly had no intent of casting dispersions on your skills as a mathematician, at least not in a public forum. (Now in private, over a beer, things might be different. ;)

If I'm rambling, it's because it's Monday morning and my brain is still trying to get into "work mode"...

... and it's all in good fun!

Anonymous said...

Note that there often is a specific function for computing e**x - 1. In C, it's expm1. This is useful when e**x is very close to one. I think scipy has it, but my scipy installation is busted right now.