Euler’s identity is widely regarded as the prime example of mathematical beauty. In this post we’ll rediscover it using high school math and a bit of common sense.

Contents:

Euler’s formula and Euler’s identity

You’re here, so you probably know the identity is

\[e^{i\cdot\pi}+1=0.\]

It ties up all the mathematical constants we know from high school, namely \(0,1,e,\pi\) and \(i=\sqrt{-1}\) in one surprisingly neat formula. What’s even more surprising is that this identity is effectively a special case of Euler’s formula:

\[e^{i\cdot x}=\mathrm{cos}(x)+i\cdot\mathrm{sin}(x).\]

Don’t see it? Plug in \(x=\pi\) and remember that \(\mathrm{cos}(\pi)=-1, \mathrm{sin}(\pi)=0.\)

You could argue that this one is even more beautiful: the trig functions also make an appearance now. Richard Feynman went as far as to say that it’s “the most remarkable formula in mathematics”, but only after having shown experimentally that the formula is actually true. What I’m going to show you is heavily inspired by his take on the matter, but today you’ll help me do the experiment.

How do we calculate \(e^x\)?

Using Math.exp(x) would be cheating! But no worries, there’s a way to do it using only:

  1. An estimate of \(e\). \(2.718\) is good enough for me, but go ahead and use something better.
  2. Square roots (If the Babylonians could do it, so can we).
  3. The exponent rules:

    \[e^{a+b}=e^{a}\cdot e^{b},\] \[(e^{a})^{b}= e^{a \cdot b}.\]

Let’s calculate \(e^{3.626}\) as an example. Start by rewriting the exponent:

\[3.626 = 3 + 625/1000 + 1/1000.\]

Why are we even doing this? Give me a sec.

Make sure you notice that

\[625/1000 = 5/8,\]

which gives:

\[e^{3.626} = e^{3\ +\ 5/8 \ +\ 1/1000} = e^{3}\cdot e^{5/8}\cdot e^{1/1000}.\]

We can more or less easily calculate the three multiplicands on the right, but each requires his own treatment:

  1. \(e^{3}=e\cdot e \cdot e \approx 2.718 \cdot 2.718 \cdot 2.718 \approx 20.08.\)

    If you ever need a more accurate result, just plug in that fancier estimate of \(e\) you’ve got.

  2. For \(e^{5/8}\), we need to know \(e^{1/8}\) first, which we calculate by taking the square root three times in succession:

    \[e^{1/8} = \sqrt{e^{1/4}} = \sqrt{\sqrt{e^{1/2}}} = \sqrt{\sqrt{\sqrt{e}}} \approx\] \[\approx \sqrt{\sqrt{\sqrt{2.718}}} \approx 1.133.\]

    Now we just multiply this number by itself five times:

    \[e^{5/8}=(e^{1/8})^{5}\approx 1.133^{5} \approx 1.867.\]
  3. Finally, \(1/1000\) is so small that we can just say \(e^{1/1000}\approx e^{0} = 1.\)

    In case \(1/1000\) is not so small after all, can you think of a way to get an even better estimate here? Hint: \(1/1000 = 1/1024 + 3/128000\).

Putting everything together, we get

\[e^{3.626} \approx 20.08\cdot 1.867 \approx 37.49,\]

and as I hinted above, we can get as close as we want to the actual value with better approximations and more of the same work.

This example should make it clear that numbers like \(e^{5/8}=e^{5/2^{3}}\) play a big role here: they’re the only ones we can actually calculate! Let’s go about this methodically and find a bunch of these all at once. Specifically, I want the values of:

\[e^{0/16},\ e^{1/16},\ e^{2/16}, \ldots,\ e^{3}.\]

You can run the following code in the p5.js web editor, or, you know, just take my word for it.

const e = 2.718281828459045;
let kth_sq_root = e;
for (let k = 1; k <= 4; k++) {
  kth_sq_root = Math.sqrt(kth_sq_root);
  console.log(kth_sq_root);
}

In every iteration of the loop we calculate another square root of \(e\), till we get to \(e^{1/16}\):

1.6487212707001282
1.2840254166877414
1.1331484530668263
1.0644944589178595

Now we take that last number and calculate

\[e^{2/16}=e^{1/16}\cdot e^{1/16} \approx 1.064 \cdot 1.064.\]

Using this result we get the next one,

\[e^{3/16}=e^{2/16}\cdot e^{1/16} \approx 1.064 \cdot 1.064 \cdot 1.064,\]

and so on.

let x = [];
let ex = [];
let current = 1;
for (let k = 1; k <= 3 * 16; k++) {
  x.push(k / 16);
  ex.push(current);
  current = current * kth_sq_root;
}

plotting ex against x, we get:

You’re saying: “that’s just \(e^{x}\), I’ve seen it before, what’s the big deal?” You just did all the calculations here by “hand”, take it in.

This isn’t the end of it. We could fill in the blanks in the figure by taking \(e^{1/32}\) as kth_sq_root and we could run the loop a bit longer to go past \(x=3\). In short, we know how to find \(e^x\) for any \(x\ge0\), up to any desired accuracy.

What about \(e^{-x}\)? That one’s easy: \(e^{-x}=1/e^{x}.\)

If you feel like it, change the code above to calculate

\[e^{-1},\ldots,\ e^{-1/2^{10}},\ e^{0},\ e^{1/2^{10}},\ldots,\ e^{1}.\]

OK, we’re good with \(e^x\), but what does \(e^{ix}\) even mean?

Obviously you felt like it, so I’m assuming you’ve seen this:

\(k\) \(x=k/2^{10}\) \(e^{x}\)
1 0.000976 1.000977
2 0.001953 1.001955
3 0.002929 1.002933
4 0.003906 1.003913
50 0.048828 1.050040

Did you notice the pattern though? It looks like

\[e^x\approx1+x\]

is a really good approximation for small values of \(x\), but it gets worse very fast as \(x\) increases. This should come as no surprise to you if you’ve had some calculus. Otherwise, here’s a proof by graphics:

How does this apply to \(e^{ix}\)? Well, the thing is, if \(x \approx 0\), then by multiplying both sides by \(i\) we get

\[i \cdot x \approx i\cdot 0 = 0\] \[ix \approx 0.\]

Now, we just said \(e^x\approx1+x\) for small \(x\), and we just saw that \(ix\) is also small, so I’ll go out on a limb and guess that

\[e^{ix} \approx 1+ix\]

is good (when \(x\) is not too large). We still have no idea what \(e^{ix}\) means in general, but having written the rest of this post already, I can tell you that we don’t need anything more to see Euler’s formula materialize.

This is what you’ve come to see

The recipe is as follows:

  1. \(0.1\) is a small number, so say that

    \[e^{0.1i} \approx 1+0.1i.\]
  2. Use the exponent rule a lot:

    • \(e^{0.2i} = e^{0.1i}\cdot e^{0.1i} \approx (1+0.1i)\cdot (1+0.1i)\)
    • \(e^{0.3i} = e^{0.2i}\cdot e^{0.1i} \approx (1+0.1i)\cdot (1+0.1i)\cdot (1+0.1i)\)
    • \(e^{0.4i} = e^{0.3i}\cdot e^{0.1i} \approx (1+0.1i)\cdot (1+0.1i)\cdot (1+0.1i)\cdot (1+0.1i)\)

      \[\vdots\]

Doesn’t sound too complicated right? We just need to keep track of which number we’ve just calculated and keep on multiplying with \(1+0.1i\):

\[(a+ib)(1+0.1i) = a-0.1b +i(0.1a+b).\]

In code it should look like this:

// e^(0.1ni) = a_n + ib_n
const a_0 = 1;
const b_0 = 0;

iterate = function (a_n,b_n) {
  const a_n1 = a_n - 0.1*b_n;
  const b_n1 = 0.1*a_n + b_n;
  return [a_n1,b_n1]
}

The rest is just graphics.

Check out the code for this sketch here.

Cool spiral… But how does this relate to Euler’s formula? We just drew (what we believe to be) the left hand side of

\[e^{ix}=\mathrm{cos}(x)+i\cdot \mathrm{sin}(x),\ \ x = 0,0.1,0.2,..\]

Let’s compare it head to head with the RHS. We need to keep track of the iteration number, n, and calculate

cos_n = cos(n*0.1)
sin_n = sin(n*0.1)

I’ve colored these points red here:

Somewhat disappointing, no? Why do the black and red points diverge?

Do you remember I said \(0.1\) is small, so \(e^{0.1i} \approx 1+0.1i\) should be true? Maybe \(0.1\) is just not small enough! Maybe. You tell me:

Take the slider all the way to the left and it’s right on the money! That’s it, we’re done here.

What’s next?

  • We now have reasonable evidence that Euler’s formula is true, but how do we prove it? I particularly like Euler’s original proof. Also, definitely watch the video by 3Blue1Brown for another intuitive explanation, using a completely different approach.
  • Some would argue that Euler’s formula is even more beautiful with \(\tau\) instead of \(\pi\). Read all about it (and much more) here.

Finally, some challenges to think about:

  • Look closely at the last sketch. If you’re patient enough, you’ll see the black points diverge away from the origin, while the red ones stay on a circle. This always happens. Can you figure out why?

    Hint: calculate the distance from the origin of \(1+ix,(1+ix)^{2},\ldots\)

  • It looks as if the black and red points go around in phase: they always complete a full circle at the same time. Can you use this “fact” to make the black points better approximate \(e^{ix}\)?

    Check your idea by changing the function iterate and rerunning the sketch.