e i π + 1 = 0However, in Python, this isn’t quite true:
If you note, the imaginary component is quite small: -1 x 10-16.>>> import math
>>> math.e**(math.pi*1j) + 1
1.2246063538223773e-16j
Python is Steve’s tool of choice, so it’s possible to misread his post and believe that python got the answer wrong. However, the error is fundamental. Witness:
As I said, it would be possible to misread Steve’s post as a complaint against Python. It is not. As he says:$ ghci
Prelude> :m + Data.Complex
Prelude Data.Complex> let e = exp 1 :+ 0
Prelude Data.Complex> let ipi = 0 :+ pi
Prelude Data.Complex> e
2.718281828459045 :+ 0.0
Prelude Data.Complex> ipi
0.0 :+ 3.141592653589793
Prelude Data.Complex> e ** ipi + 1
0.0 :+ 1.2246063538223773e-16
I believe the results would be just as disappointing in any other languageAnd indeed they are, thanks to irrational numbers like π and the limitations of IEEE doubles.
Updated: corrected uses of -iπ with the proper exponent, iπ.
6 comments:
It's very simple - floats are not reals, and expecting them to always behave like reals is wrong. Expecting them to behave "close enough" for many purposes seems alright to me, though.
You may also be interested in this video, if you haven't seen it:
http://video.google.com/videoplay?docid=-2285617608766742834
You seem to be using -i instead of i (in both examples) to multiply with pi, unless I'm misreading.
Philip,
Thanks for the correction. I don't play with imaginary numbers very often.
Updated.
Of course, you insult my friend pi by describing it as merely irrational when in fact it is also transcendental. ray clearly has no poetry in his soul, and would make a good applied mathematician (ray: don't be offended, I regard my own ineptness at applied math as a shortcoming, so I was only joking). chessguy: I am only a few minutes into the video, which I was previously unaware of, and I already know I am going to watch it to the end!
Steve: I've been called worse than "applied mathematician" before!
Post a Comment