commit 64cad1c39333ddc688ffb2763ffaa9c04d9a41b8 Author: J. Fernando Sánchez Date: Fri Apr 17 17:48:48 2020 +0200 Conway presentation diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..8d98f9d --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.* diff --git a/Conway.ipynb b/Conway.ipynb new file mode 100644 index 0000000..bebc3c4 --- /dev/null +++ b/Conway.ipynb @@ -0,0 +1,75399 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": { + "slideshow": { + "slide_type": "slide" + } + }, + "source": [ + "# Conway's life and games\n", + "\n", + "![](data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wCEAAkGBwgHBgkIBwgKCgkLDRYPDQwMDRsUFRAWIB0iIiAdHx8kKDQsJCYxJx8fLT0tMTU3Ojo6Iys/RD84QzQ5OjcBCgoKDQwNGg8PGjclHyU3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3N//AABEIAKAAoAMBIgACEQEDEQH/xAAcAAACAgMBAQAAAAAAAAAAAAAEBQMGAAECBwj/xAA5EAACAQMCAwYDBwMEAwEAAAABAgMABBESIQUxQQYTIlFhcTKBkRQjobHB4fBCUtEHJGJyFTPxJf/EABgBAAMBAQAAAAAAAAAAAAAAAAECAwAE/8QAHREBAQEBAAIDAQAAAAAAAAAAAAECESExAxJBUf/aAAwDAQACEQMRAD8A8h55/OuxhRkbk8gK0o5E1gyN6AOm8t8nnWgMjO+3StquoZ6+1dkAdOdBkc2hl8IIJqE8xipGGOnTlW4Lae6lEdtG0jnkq1reDxFkb10mXOlRueXrTmPsxxBkDlUbroRwTQ9vZDv2ilDx6AS2V+dLdQfrQDRt4VAZmOdgOtdrZ3DY+4lz5aTT1IHmspJIEEYjTDMebeRPriorK3ieNnnl0WgOC7ZDSHkfeh9jfUoWzuZAe7t5XwcHCGoHR0YiSMqQN81bO4WWN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8047/pxxOwZ5bBvtkJOQpGmQfjhvlisCmFfDua4Vd/PHKpjsMGtKu9MDYTK8gD1qa1sLi6uI7e1heWaQ4REGSan4fZT8QuorSyjMs8raUQdT+g9fSvaOyXZS17O2zHUJ7yRcTT4wD6KOi/nQYo7H9g7fhHd3vFNFzfjBVeccJ9P7m/5fQVdicnPkefnWM25IHoK0u5CgUBD38zQWzvEoLLyz51TTaJEpVVJJJLN1YnmSepzV9eBZImRxkNsRSW+4BKf/AEyK69ATgik3m1T49Se1SW7NjkvnSTsCaN+3Wsocl8Id2DEHP6j6UTP2XupAe8izjkCwxVb4r2P4q8TRh440/u1EsPoKSWn1M30KWazDPKWjVQSW1bac42pPcdt4zmO1i1Lg4LH4vLYUE/ZNInBuZJJnXlk6QKIi4dHb4CRgH0FHpeSBBfX/ABGXvJIyOgaQdPICpoLEd73tzK88vm3IewphDZXEp0pGQPPGKe8L4AWbVJv6Dl9aIWl3DrCe5kHdocDrV04fYCCMA4LflRFlw8RKBjHpimKx6aeThLUSR6RnnUiJgV2V3VfnXenemBzGOYNREFSV6HoeVEIvizW+7DE5rM//2Q==)" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "slideshow": { + "slide_type": "slide" + } + }, + "source": [ + "## Conway's Life" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "slideshow": { + "slide_type": "slide" + } + }, + "source": [ + "Some of his achievements:\n", + " \n", + "* Game of Life\n", + "* Surreal numbers\n", + "* Free Will Theorem" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "slideshow": { + "slide_type": "slide" + } + }, + "source": [ + "## Game of Life\n", + "\n", + "\n", + "" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": { + "slideshow": { + "slide_type": "skip" + } + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Populating the interactive namespace from numpy and matplotlib\n" + ] + } + ], + "source": [ + "%pylab inline\n", + "from pylab import rc\n", + "\n", + "import numpy as np\n", + "import scipy\n", + "from IPython.display import HTML\n", + "from matplotlib import animation\n", + "\n", + "rc('animation', html='html5')" + ] + }, + { + "cell_type": "code", + "execution_count": 17, + "metadata": { + "slideshow": { + "slide_type": "slide" + } + }, + "outputs": [], + "source": [ + "def life_step(X):\n", + " \"\"\"Game of life step using scipy tools\"\"\"\n", + " from scipy.signal import convolve2d\n", + " nbrs_count = convolve2d(X, np.ones((3, 3)), mode='same', boundary='wrap') - X\n", + " return (nbrs_count == 3) | (X & (nbrs_count == 2))" + ] + }, + { + "cell_type": "code", + "execution_count": 175, + "metadata": { + "scrolled": false, + "slideshow": { + "slide_type": "skip" + } + }, + "outputs": [], + "source": [ + "def life_animation(X, dpi=120, fps=30, frames=10, interval=300, mode='loop', save=None):\n", + " \"\"\"Produce a Game of Life Animation\n", + " \n", + " Parameters\n", + " ----------\n", + " X : array_like\n", + " a two-dimensional numpy array showing the game board\n", + " dpi : integer\n", + " the number of dots per inch in the resulting animation.\n", + " This controls the size of the game board on the screen\n", + " frames : integer\n", + " The number of frames to compute for the animation\n", + " interval : float\n", + " The time interval (in milliseconds) between frames\n", + " mode : string\n", + " The default mode of the animation. Options are ['loop'|'once'|'reflect']\n", + " \"\"\"\n", + " X = np.asarray(X)\n", + " assert X.ndim == 2\n", + " X = X.astype(bool)\n", + " \n", + " X_blank = np.zeros_like(X)\n", + "# figsize = (X.shape[1] * 1. / dpi, X.shape[0] * 1. / dpi)\n", + "# print(figsize, dpi)\n", + "\n", + " fig = plt.figure(dpi=dpi);\n", + " plt.close()\n", + " ax = fig.add_axes([0, 0, 1, 1], xticks=[], yticks=[], frameon=False)\n", + " im = ax.imshow(X, cmap=plt.cm.binary, interpolation='nearest')\n", + " im.set_clim(-0.05, 1) # Make background gray\n", + " orig = X.copy()\n", + " # initialization function: plot the background of each frame\n", + " def init():\n", + " im.set_data(orig)\n", + " animate.X = orig\n", + " return (im,)\n", + "\n", + " # animation function. This is called sequentially\n", + " def animate(i):\n", + " im.set_data(animate.X)\n", + " animate.X = life_step(animate.X)\n", + " return (im,)\n", + "\n", + " anim = animation.FuncAnimation(fig, animate, init_func=init,\n", + " frames=frames, interval=interval,\n", + " blit=True)\n", + " \n", + " #print anim_to_html(anim)\n", + " htmlcode = anim.to_jshtml(default_mode=mode)\n", + " if save:\n", + " anim.save(save+'.gif', writer='imagemagick', fps=fps)\n", + " return HTML(htmlcode)\n", + "\n", + "\n", + "def pattern(*figs, height=50, width=70):\n", + " '''Concatenate different patterns into a single board'''\n", + " X = np.zeros((height, width)) \n", + " for patt, x0, y0 in figs:\n", + " X[y0:y0+len(patt), x0:x0+len(patt[0])] = patt\n", + " return X" + ] + }, + { + "cell_type": "code", + "execution_count": 110, + "metadata": { + "scrolled": false, + "slideshow": { + "slide_type": "slide" + } + }, + "outputs": [ + { + "data": { + "text/html": [ + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "
\n", + " \n", + "
\n", + " \n", + "
\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
\n", + "
\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
\n", + "
\n", + "
\n", + "\n", + "\n", + "\n" + ], + "text/plain": [ + "" + ] + }, + "execution_count": 110, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "np.random.seed(0)\n", + "X = np.zeros((30, 40), dtype=bool)\n", + "r = np.random.random((10, 20))\n", + "X[10:20, 10:30] = (r > 0.75)\n", + "life_animation(X, dpi=120, frames=40, mode='once')" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "slideshow": { + "slide_type": "slide" + } + }, + "source": [ + "### Static configurations" + ] + }, + { + "cell_type": "code", + "execution_count": 111, + "metadata": { + "slideshow": { + "slide_type": "-" + } + }, + "outputs": [ + { + "data": { + "text/html": [ + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "
\n", + " \n", + "
\n", + " \n", + "
\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
\n", + "
\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
\n", + "
\n", + "
\n", + "\n", + "\n", + "\n" + ], + "text/plain": [ + "" + ] + }, + "execution_count": 111, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "X = np.zeros((6, 21))\n", + "X[2:4, 1:3] = 1\n", + "X[1:4, 5:9] = [[0, 1, 1, 0],\n", + " [1, 0, 0, 1],\n", + " [0, 1, 1, 0]]\n", + "X[1:5, 11:15] = [[0, 1, 1, 0],\n", + " [1, 0, 0, 1],\n", + " [0, 1, 0, 1],\n", + " [0, 0, 1, 0]]\n", + "X[1:4, 17:20] = [[1, 1, 0],\n", + " [1, 0, 1],\n", + " [0, 1, 0]]\n", + "\n", + "life_animation(X, dpi=120, frames=3)" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "slideshow": { + "slide_type": "slide" + } + }, + "source": [ + "### The \"Blinker\" and the \"Toad\" (Period-2 oscillators)\n" + ] + }, + { + "cell_type": "code", + "execution_count": 112, + "metadata": { + "slideshow": { + "slide_type": "-" + } + }, + "outputs": [ + { + "data": { + "text/html": [ + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "
\n", + " \n", + "
\n", + " \n", + "
\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
\n", + "
\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
\n", + "
\n", + "
\n", + "\n", + "\n", + "\n" + ], + "text/plain": [ + "" + ] + }, + "execution_count": 112, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "blinker = [[1, 1, 1]]\n", + "toad = [[1, 1, 1, 0],\n", + " [0, 1, 1, 1]]\n", + "\n", + "\n", + "X = pattern((blinker, 1, 1),\n", + " (toad, 6, 1), width=10, height=4)\n", + "\n", + "life_animation(X, frames=4)" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "slideshow": { + "slide_type": "slide" + } + }, + "source": [ + "### The pulsar (period-3)" + ] + }, + { + "cell_type": "code", + "execution_count": 113, + "metadata": { + "slideshow": { + "slide_type": "fragment" + } + }, + "outputs": [ + { + "data": { + "text/html": [ + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "
\n", + " \n", + "
\n", + " \n", + "
\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
\n", + "
\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
\n", + "
\n", + "
\n", + "\n", + "\n", + "\n" + ], + "text/plain": [ + "" + ] + }, + "execution_count": 113, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "X = np.zeros((17, 17))\n", + "X[2, 4:7] = 1\n", + "X[4:7, 7] = 1\n", + "X += X.T\n", + "X += X[:, ::-1]\n", + "X += X[::-1, :]\n", + "pulsar = X.copy()\n", + "life_animation(X, frames=6)" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "slideshow": { + "slide_type": "slide" + } + }, + "source": [ + "### The glider (period-4 oscillator that moves)" + ] + }, + { + "cell_type": "code", + "execution_count": 176, + "metadata": { + "slideshow": { + "slide_type": "fragment" + } + }, + "outputs": [ + { + "data": { + "text/html": [ + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "
\n", + " \n", + "
\n", + " \n", + "
\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
\n", + "
\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
\n", + "
\n", + "
\n", + "\n", + "\n", + "\n" + ], + "text/plain": [ + "" + ] + }, + "execution_count": 176, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "glider = [[1, 0, 0],\n", + " [0, 1, 1],\n", + " [1, 1, 0]]\n", + "life_animation(pattern((glider, 0,0), width=8, height=8), frames=32, interval=100)" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "slideshow": { + "slide_type": "slide" + } + }, + "source": [ + "### The Glider Gun (Unbounded growth)" + ] + }, + { + "cell_type": "code", + "execution_count": 177, + "metadata": { + "slideshow": { + "slide_type": "-" + } + }, + "outputs": [ + { + "data": { + "text/html": [ + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "
\n", + " \n", + "
\n", + " \n", + "
\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
\n", + "
\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
\n", + "
\n", + "
\n", + "\n", + "\n", + "\n" + ], + "text/plain": [ + "" + ] + }, + "execution_count": 177, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "glider_gun =\\\n", + "[[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0],\n", + " [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0],\n", + " [0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,1,1],\n", + " [0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,1,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,1,1],\n", + " [1,1,0,0,0,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0],\n", + " [1,1,0,0,0,0,0,0,0,0,1,0,0,0,1,0,1,1,0,0,0,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0],\n", + " [0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0],\n", + " [0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],\n", + " [0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]]\n", + "\n", + "life_animation(pattern((glider_gun, 1, 1)), frames=180, interval=50, mode='once')" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "slideshow": { + "slide_type": "slide" + } + }, + "source": [ + "### Logic" + ] + }, + { + "cell_type": "code", + "execution_count": 164, + "metadata": { + "slideshow": { + "slide_type": "fragment" + } + }, + "outputs": [], + "source": [ + "reverse_gun = [i[::-1] for i in glider_gun]" + ] + }, + { + "cell_type": "code", + "execution_count": 165, + "metadata": { + "slideshow": { + "slide_type": "fragment" + } + }, + "outputs": [ + { + "data": { + "text/html": [ + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "
\n", + " \n", + "
\n", + " \n", + "
\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
\n", + "
\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
\n", + "
\n", + "
\n", + "\n", + "\n", + "\n" + ], + "text/plain": [ + "" + ] + }, + "execution_count": 165, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "life_animation(pattern((glider_gun, 1, 1), (reverse_gun, 46, 1), width=100, height=100), frames=180, interval=50, mode='once')" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "slideshow": { + "slide_type": "slide" + } + }, + "source": [ + "### Other patterns" + ] + }, + { + "cell_type": "code", + "execution_count": 52, + "metadata": {}, + "outputs": [], + "source": [ + "diehard = [[0, 0, 0, 0, 0, 0, 1, 0],\n", + " [1, 1, 0, 0, 0, 0, 0, 0],\n", + " [0, 1, 0, 0, 0, 1, 1, 1]]\n", + "\n", + "boat = [[1, 1, 0],\n", + " [1, 0, 1],\n", + " [0, 1, 0]]\n", + "\n", + "r_pentomino = [[0, 1, 1],\n", + " [1, 1, 0],\n", + " [0, 1, 0]]\n", + "\n", + "beacon = [[0, 0, 1, 1],\n", + " [0, 0, 1, 1],\n", + " [1, 1, 0, 0],\n", + " [1, 1, 0, 0]]\n", + "\n", + "acorn = [[0, 1, 0, 0, 0, 0, 0],\n", + " [0, 0, 0, 1, 0, 0, 0],\n", + " [1, 1, 0, 0, 1, 1, 1]]\n", + "\n", + "spaceship = [[0, 0, 1, 1, 0],\n", + " [1, 1, 0, 1, 1],\n", + " [1, 1, 1, 1, 0],\n", + " [0, 1, 1, 0, 0]]\n", + "\n", + "block_switch_engine = [[0, 0, 0, 0, 0, 0, 1, 0],\n", + " [0, 0, 0, 0, 1, 0, 1, 1],\n", + " [0, 0, 0, 0, 1, 0, 1, 0],\n", + " [0, 0, 0, 0, 1, 0, 0, 0],\n", + " [0, 0, 1, 0, 0, 0, 0, 0],\n", + " [1, 0, 1, 0, 0, 0, 0, 0]]" + ] + }, + { + "cell_type": "code", + "execution_count": 178, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "
\n", + " \n", + "
\n", + " \n", + "
\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
\n", + "
\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
\n", + "
\n", + "
\n", + "\n", + "\n", + "\n" + ], + "text/plain": [ + "" + ] + }, + "execution_count": 178, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "life_animation(pattern((block_switch_engine, 10, 10)), frames=100, interval=50, mode='once')" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "slideshow": { + "slide_type": "slide" + } + }, + "source": [ + "### Fun and art" + ] + }, + { + "cell_type": "code", + "execution_count": 179, + "metadata": {}, + "outputs": [], + "source": [ + "from PIL import Image\n", + "import numpy as np\n", + "\n", + "im = Image.open('conwaycabify.png')\n", + "a = 0+~np.array(im.convert('1'))" + ] + }, + { + "cell_type": "code", + "execution_count": 180, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "
\n", + " \n", + "
\n", + " \n", + "
\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
\n", + "
\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
\n", + "
\n", + "
\n", + "\n", + "\n", + "\n" + ], + "text/plain": [ + "" + ] + }, + "execution_count": 180, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "life_animation(a[::5,::5], dpi=120, fps=30,frames=500, mode='reflect')" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "slideshow": { + "slide_type": "slide" + } + }, + "source": [ + "# Surreal numbers\n", + "\n", + "The achievement for which Conway himself was most proud, according to Kochen, was his invention of a new system of numbers, the surreal numbers. This continuum of numbers includes not only real numbers such as integers, fractions and irrational numbers such as pi, but also the infinitesimal and infinite numbers. \n", + "\n", + "Mathematician John Horton Conway first invented surreal numbers, and Donald Knuth (TAOCP) introduced them to the public in 1974 in his mathematical novelette \"Surreal Numbers: How Two Ex-Students Turned on to Pure Mathematics and Found Total Happiness\".\n" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "slideshow": { + "slide_type": "slide" + } + }, + "source": [ + "![](https://www.researchgate.net/profile/Mickael_Matusinski/publication/306186762/figure/fig1/AS:395755064971265@1471366768199/The-tree-of-surreal-numbers.png)" + ] + }, + { + "cell_type": "code", + "execution_count": 181, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "\n", + " \n", + " " + ], + "text/plain": [ + "" + ] + }, + "execution_count": 181, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "from IPython.display import IFrame\n", + "IFrame('https://www.youtube.com/embed/mPn2AdMH7UQ', 560, 315)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "How can surreal numbers represent irrational numbers such as $\\pi$?\n", + "\n", + "\n", + "One intuitive way to go around this is that you start with the closest integer:\n", + "\n", + "$3 = \\{0,1,2 | 4\\} = \\{ L | R\\}$.\n", + "\n", + "And then continue getting closer to $\\pi$ by adding rationals to either $L$ or $R$.\n", + "A strategy to calculate each rational ($a_n$) could be:\n", + "\n", + "$a_(n) = a_{n-1} + 2^{-n} * sign(\\pi-a_{n-1})$\n", + "\n", + "\n", + "If $a_n < \\pi$, $a_n$ is added to $L$, otherwise it goes to $R$. \n", + "\n", + "$3 = \\{0,1,2, 3 | \\} $\n", + "\n", + "$3.5 = \\{0,1,2, 3 | 4\\} $ # Adding 4\n", + "\n", + "$3.25 = \\{0,1,2, 3 | 3.5 4\\}$ # Adding 3.5\n", + "...\n", + "\n", + "\n", + "$ \\pi = \\{ 3.14150... | 3.141509...\\}\n" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "slideshow": { + "slide_type": "slide" + } + }, + "source": [ + "## Free Will Theorem" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "if we have a free will in the sense that our choices are not a function of the past, then, subject to certain assumptions, so must some elementary particles." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# References" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "\n", + "* [Code for game of life](https://jakevdp.github.io/blog/2013/08/07/conways-game-of-life/)\n", + "* [A Turing machine made in Life](http://www.rendell-attic.org/gol/tm.htm)\n", + "* John Horton Conway, a ‘Magical Genius’ in Math, Dies at 82 [NY Times](https://www.nytimes.com/2020/04/15/technology/john-horton-conway-dead-coronavirus.html)\n", + "* [Implementation of logical functions in the Game of Life](https://www.rennard.org/alife/CollisionBasedRennard.pdf)\n", + "* [Surreal Numbers: How two ex-students turned on to pure mathematics and found total happiness ](https://www-cs-faculty.stanford.edu/~knuth/sn.html)" + ] + } + ], + "metadata": { + "celltoolbar": "Slideshow", + "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.8.2" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/cabify-conway.gif b/cabify-conway.gif new file mode 100644 index 0000000..7d093f1 Binary files /dev/null and b/cabify-conway.gif differ diff --git a/conwaycabify.png b/conwaycabify.png new file mode 100644 index 0000000..bc79110 Binary files /dev/null and b/conwaycabify.png differ