Skip to content

Instantly share code, notes, and snippets.

@rpalo
Created October 28, 2017 20:36
Show Gist options
  • Save rpalo/28bb52b08faea245f49efc3e4638225b to your computer and use it in GitHub Desktop.
Save rpalo/28bb52b08faea245f49efc3e4638225b to your computer and use it in GitHub Desktop.
E for Everywhere
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# E for Everywhere\n",
"\n",
"I just learned something new and it prompted me to want to share it (and a whole bunch of other things). Let's talk about the letter `e`. This post will have a little bit of math in it, but I'll try to make those parts painless enough to keep you with me.\n",
"\n",
"## e\n",
"\n",
"`e` is a mathmatical constant (like `pi`) that crops up a lot of places.\n",
"\n",
"$$e = 2.71828182845904523536028747135266249775724709369995$$\n",
"\n",
"Like `pi`, it's a number that is *irrational*, meaning that its decimal places never end and never repeat (go into an infinite loop).\n",
"\n",
"\"Blah blah blah blah,\" you say -- eloquently, I might add. \"All I hear is blah blah math letters-that-are-really-numbers blah. Why are you bothering me about this `e`?\"\n",
"\n",
"I want to tell you about it, because, even though it doesn't get the kind of press that `pi` does (not to mention `phi` -- the golden ratio), it shows up everywhere you look and helps us with all kinds of statistics, finance, and more! I'm writing this post to show off a couple of the ways that `e` works behind the scenes.\n",
"\n",
"## Something Interesting and Practical\n",
"\n",
"Let's talk about **interest**. Like bank interest! Like investment stocks interest. You ever wonder how that was calculated? Here's the interest equation:\n",
"\n",
"$$A = P(1 + \\frac{r}{n})^n$$\n",
"\n",
"Where:\n",
" A is the future value of your money.\n",
" P is the present value of your money.\n",
" r is the interest rate over the time period you care about (usually a year, in practice).\n",
" n is the number of times you compound your interest over the time period.\n",
" \n",
"For example, if you put $100 into a bank for a year, and the bank provided a 7% (or .07) interest rate over that time, *and* the bank only compounded your interest one time (which they sometimes do), after one year, you'd end up with:\n",
"\n",
"$$100(1 + \\frac{.07}{1})^{1} = 107$$\n",
"\n",
"This is as expected, because we already said you're getting 7% yearly interest (also known as APR), and 7% of 100 is 7, so getting $107 at the end of the year should hopefully seem reasonable.\n",
"\n",
"But some banks compound your interest every month! Check your bank statement -- yours probably does! What does that look like?\n",
"\n",
"$$100(1 + \\frac{.07}{12})^{12} = 107.23$$\n",
"\n",
"WHAAAAAAT? You just got an extra $0.25, simply by doing some math 12 times a year instead of once at the end. You squint at me skeptically, and ask, \"Does that pattern continue like that?\" Let's try it! Let's compound once a day.\n",
"\n",
"$$100(1 + \\frac{.07}{365})^{365} = 107.25$$\n",
"\n",
"Yep! Kind of. Definitely not as much increase, and we're compounding waaaay more. Let's really amp up the compounding and see what happens.\n",
"\n",
"Actually, let's simplify our life a little bit first to make the math easy:\n",
"\n",
"1. Let's assume we're starting with just $1.\n",
"2. Let's assume our interest rate is 100% (i.e. 1). Thus compounding yearly, we would double our money.\n",
"\n",
"Now let's see what our pattern looks like."
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"r = 1.0\n",
"p = 1.0\n",
"\n",
"def compound(p, r, n):\n",
" \"\"\"Calculates interest after one time period (e.g. a year).\n",
" p: float - initial money amount\n",
" r: float - interest rate over the time period\n",
" n: int - number of times we compound\n",
" returns float - amount of money after one time period\n",
" \"\"\"\n",
" return p*((1 + r/n)**n)\n",
"\n",
"result_data = [compound(p, r, n) for n in range(1, 100)]\n"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAXcAAAD8CAYAAACMwORRAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAHQRJREFUeJzt3Xt0nPWd3/H3d26627ItgcG2LGMILCRhDQJCzG5u2w3k\nUpKTnBM2KdndsOs2zXZhD5smJZuc09N22zQNm+uGdcM2ScMJbWPncnJrvCwN8SYYZMexsQQEYxsw\nMpZ8032u3/4xz9iyrNGMrJHG88zndc6ceeaZ38x8h0d8/NNPv+f5mbsjIiLhEql2ASIiUnkKdxG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78Q97PAfuAT1a5nAb/nLeR/PdsD\n7A5ubyM//vwI8BvgH4Dl1a51Af8bvBH4QbB9GfAE+UXY/w/QUO36FuD7/jbQGxzz7wLL6uF4A/8e\neBp4CvifQENYjzfwLfJ/W0iT/23trmLHmPza1V8Osm4v+RlFZX+WzlAVEQmhWhuWERGRMijcRURC\nSOEuIhJCCncRkRBSuIuIhJDCXUQkhBTuIiIhpHAXEQmh/w8QTbKS3mfiggAAAABJRU5ErkJggg==\n",
"text/plain": [
"<matplotlib.figure.Figure at 0x10c8f8f60>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"from matplotlib import pyplot as plt\n",
"plt.plot(result_data)\n",
"plt.show()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"You can see that with 1 compound, we get 100% return, just like we planned. Start with $1, end up with $2. And as we compound more and more, we see it go up by quite a bit and then the gains start to level off. But wait. What number are the gains leveling off at?"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAXcAAAD8CAYAAACMwORRAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAGjpJREFUeJzt3X10XPV95/H3V0+2Jdn4QcKAbFkQTAikAYMWQ51NSMhJ\nSNpAaNKTB2Jomhyn3Ta1e7wPXZqT3Z5te04OOWySpsXrhS1N10vSxoY6D03iUDcpEBskxbGxBDYP\nwTbItuRnybKlkb77x71jj+UZzUia0dW983mdM+feufPTzHd84aOffvOb+zN3R0REkqUi6gJERKT4\nFO4iIgmkcBcRSSCFu4hIAincRUQSSOEuIpJACncRkQRSuIuIJJDCXUQkgaqieuGGhgZvaWmJ6uVF\nRGKpvb29190b87WLLNxbWlpoa2uL6uVFRGLJzF4vpJ2GZUREEkjhLiKSQAp3EZEEUriLiCSQwl1E\nJIEU7iIiCaRwFxFJoMjmuU/Un313N51vnoy6DBGRCbvuijn8tw9fX9LXUM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Ed4+xDBOPRTwF7gJ8D8qGstwXu/HfheuH8V\n8BzBwuv/CMyIur4iv9cbgbbwPD8JzEv6OQb+DHgReAH4e2BG0s4z8DjBZwpDBH+hfTbXeSVYn/qv\nwzzbRTCTqCh16BuqIiIJFLdhGRERKYDCXUQkgRTuIiIJpHAXEUkghbuISAIp3EVEEkjhLiKSQAp3\nEZEE+v/MqZAtVAhOrgAAAABJRU5ErkJggg==\n",
"text/plain": [
"<matplotlib.figure.Figure at 0x10ce8eef0>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"from math import e\n",
"plt.plot((0, 100), (e, e)) # Plot horizontal line at 2.71828...\n",
"plt.plot(result_data)\n",
"plt.show()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"OH SNAP, IT'S E. As we approach higher and higher frequency of compounding, we approach a return amount of E. This is where the concept of **continuously compounding interest** comes from.\n",
"\n",
"So we've found `e` once. Let's do another.\n",
"\n",
"## Factorials and e\n",
"\n",
"If you've read any of my other blog posts, you're probably sick and tired of factorials. Well, that's too bad. Let's combine them with fractions and see what we can come up with.\n",
"\n",
"$$\\frac{1}{0!} = \\frac{1}{1} = 1$$\n",
"\n",
"$$\\frac{1}{1!} = \\frac{1}{1} = 1$$\n",
"\n",
"$$\\frac{1}{2!} = \\frac{1}{2 * 1} = .5$$\n",
"\n",
"$$\\frac{1}{3!} = \\frac{1}{3 * 2 * 1} = 0.16666$$\n",
"\n",
"Where am I going with this? Let's add them up and see."
]
},
{
"cell_type": "code",
"execution_count": 15,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAX4AAAD8CAYAAABw1c+bAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAHVFJREFUeJzt3Xt4VfWd7/H3lyRcEm6SBEQgBApyqRWxKWqhcrGlWLWO\nc3pO5Vjr9HI40+nNHqdzrDNHZ3Rqp9OOTy+2dagynnbUnuep2KLihZJ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TCzIYCDwM3untD2PWEwcyuBOLuvj7sWtJELnAh8At3nw0cBSL7nljQEvZqEn8Q\nzwEKzOxz4VbV97Il+JNu6h4VZpZHIvQfcPeVYdcTornAp81sB4klwEVm9p/hlhSqPcAed2/7F+Bv\nSfwhiKqPA9vdvdbdTwIrgY+GXFOfy5bgfxWYamaTzGwgiTdnVoVcU2jMzEis4Va5+11h1xMmd/+O\nu49391IS/1+Uu3vWH9F1xd3fBnab2bRg6DKgMsSSwrYLuNjM8oPfm8uIwJvdSfXcTXfu3mxmXwOe\nIvGu/Ap33xRyWWGaC1wPvGFmG4OxW9x9dYg1Sfr4OvBAcJC0DfhCyPWExt1fNrPfAhtInA33GhG4\nildX7oqIREy2LPWIiEiSFPwiIhGj4BcRiRgFv4hIxCj4RUQiRsEvIhIxCn4RkYhR8IuIRMz/B3Q8\nMuI/IjxbAAAAAElFTkSuQmCC\n",
"text/plain": [
"<matplotlib.figure.Figure at 0x10d26c2e8>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"The last result: 2.7182815255731922\n"
]
}
],
"source": [
"from math import factorial\n",
"\n",
"def sum_of_factorial_fractions(n):\n",
" \"\"\"Calculates the sum of 1/0! + 1/1! + 1/2! ... 1/n!\"\"\"\n",
" return sum(1/factorial(x) for x in range(0, n + 1))\n",
" \n",
"results2 = [sum_of_factorial_fractions(n) for n in range(10)]\n",
"plt.plot(results2)\n",
"plt.show()\n",
"print(\"The last result:\", results2[-1])"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"A;LSDKJF;ALKJSDFJSDLKFJEIVLENNVOIEJ.\n",
"\n",
"### E\n",
"\n",
"(approximately).\n",
"\n",
"Let's do one more: my favorite one.\n",
"\n",
"## Random E\n",
"\n",
"This one comes courtesy of [Fermat's Library on Twitter](https://twitter.com/fermatslibrary). Pick a random number between 0 and 1. Keep picking numbers and adding them until the sum is greater than 1. For example:"
]
},
{
"cell_type": "code",
"execution_count": 16,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"0.185263666584764\n"
]
}
],
"source": [
"from random import random\n",
"x = random()\n",
"print(x)"
]
},
{
"cell_type": "code",
"execution_count": 17,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"0.5797470876977189\n"
]
}
],
"source": [
"x += random()\n",
"print(x)"
]
},
{
"cell_type": "code",
"execution_count": 18,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"1.2821236982804123\n"
]
}
],
"source": [
"x += random()\n",
"print(x)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Alright! We're now greater than 1, and it took us 3 rolls to get there. Let's do that a ton of times and see what the average number of rolls is."
]
},
{
"cell_type": "code",
"execution_count": 25,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAXcAAAD8CAYAAACMwORRAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAIABJREFUeJzt3Xl8VOW9x/HPjyxAIOwBISxxQQERBKOCuCBuLK16q9fq\ntWhdahdfvbhcb0GtdalbF221typXe7W216XKVdS6IGCVKmBA9n1TdsK+JyT53T/mZMgyw0xCwmSG\n7/v1ysuZc56Z+Z0c/M7Jc57zHHN3REQktTRKdAEiIlL3FO4iIilI4S4ikoIU7iIiKUjhLiKSghTu\nIiIpSOEuIpKCFO4iIilI4S4ikoLSE/XB7dq187y8vER9vIhIUpoxY8Zmd8+J1S5h4Z6Xl0dBQUGi\nPl5EJCmZ2dfxtFO3jIhIClK4i4ikIIW7iEgKUriLiKQghbuISApSuIuIpCCFu4hICkq6cC8uKeNv\nBavR7QFFRKJL2EVMtfXUxKX8YfIysjLTGdGnY6LLERFpkJLuyH3z7iIAdu4/kOBKREQarqQLdxER\niU3hLiKSghTuIiIpSOEuIpKCkjbcNRJSRCS6pAt3s0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fd0>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"The last result was 2.712271227122712\n"
]
}
],
"source": [
"def rolls_to_greater_than_n(n):\n",
" \"\"\"Rolls a random number between 0 and 1 and adds them up\n",
" until the sum is greater than n. Returns the number of rolls it took.\n",
" \"\"\"\n",
" total = 0\n",
" rolls = 0\n",
" while total < n:\n",
" total += random()\n",
" rolls += 1\n",
" return rolls\n",
"\n",
"def roll_experiment_avg(n, times):\n",
" \"\"\"Performs the rolls_to_greater_than_n 'times' times.\n",
" Returs the average number of rolls it took.\"\"\"\n",
" return sum(rolls_to_greater_than_n(n) for _ in range(times))/times\n",
"\n",
"results3 = [roll_experiment_avg(1, x) for x in range(1, 10000)]\n",
"plt.plot(results3)\n",
"plt.plot((0, 10000), (e, e)) # Line representing e for reference.\n",
"plt.show()\n",
"print(\"The last result was\", results3[-1])"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"This one definitely is converging a lot slower, [but it does. Math says so.](https://twitter.com/fermatslibrary/status/924263998589145090)\n",
"\n",
"Anyways, this was kind of a long post about nothing, but I though that the way that `e` seems to pop up all over the place, even amidst factorials and random numbers, was pretty cool. Let me know if you can think of any other cool ways to come up with `e`!"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.2"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment