Feel Euler’s Number e with your programming sense — no equation

Arif
3 min readJun 29, 2021

--

Sometimes programmers understand concepts better from code than from technical talks, or even worse — painful analogies.

So, I will first give here the code to evaluate e, and then start the explanation (which might not be needed after you see the code):

STEP = 100
GROWTH = 1
GROWTH_RATE = GROWTH / STEP
e = 1
for i in range(STEP):
e = e + e * GROWTH_RATE
print(e)

That’s it!

If you plot a graph of e for all values of STEP between 1 to 100, it will be like this:

Here is the code to plot the graph if you wish to play with it:

What is Euler’s Number

If you could set infinite to the variable STEP in the code above, that would be the actual Euler’s number. It is a never-ending number like pi, and the value is 2.71828……

Okay, But What is Euler’s Number

Unlike π, you will have a hard time finding a complete formal definition of e on the internet — for one reason it is used in different ways in different places and its use is not necessarily the same everywhere. As a concrete example, e is also used in probability, but not as growth as such as we used in the code above.

This page very nicely combines a few definitions. The one relevant to our code above is:

https://betterexplained.com/articles/definitions-of-e-colorized/

If you relate this definition with our code part by part, it will start making sense.

unit quantity: We started with an initial value 1

unit interest: Our targeted GROWTH is 1 — although we are dividing it into STEPs

unit time: The time slices— 1/STEP

compounded: We are compounding the accumulated growths

as fast as possible: Making STEP as high as possible for the next time slice to come as fast as possible

Why Euler’s Number is important

It turns out that this constant has some properties which have enormous applications:

  1. Calculating compound interest: which we already got some idea
  2. Bernoulli trials (random experiment which has 2 possible outcomes)
  3. Standard normal distribution, with is normal distribution of 0 mean and unit standard deviation
  4. And many more …

For the sake of completeness

It will be misleading leaving you here giving an impression that e is only a quantity relating to compound interest. There are many other ways to look at it and you can use your programming ability to understand it from different perspectives and try to relate those views.

For example, two more ways (among many others) to derive e:

and

How about coding the equations!

Hope you will forgive me for these two equations since I promised there will be none. By the time you encountered them, I hope you got the core message I intended to share.

--

--