Skip to content

Instantly share code, notes, and snippets.

@Paddy3118
Created October 4, 2018 20:54
Show Gist options
  • Save Paddy3118/ed3d9db0acda1a95fcc0821f44e9c233 to your computer and use it in GitHub Desktop.
Save Paddy3118/ed3d9db0acda1a95fcc0821f44e9c233 to your computer and use it in GitHub Desktop.
Tennenbaum-root-2-graphic
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "markdown",
"metadata": {
"toc": "true"
},
"source": [
"# Table of Contents\n",
" <p><div class=\"lev1 toc-item\"><a href=\"#Tennenbaum-root-2-graphic\" data-toc-modified-id=\"Tennenbaum-root-2-graphic-1\"><span class=\"toc-item-num\">1&nbsp;&nbsp;</span>Tennenbaum root-2 graphic</a></div><div class=\"lev1 toc-item\"><a href=\"#√2\" data-toc-modified-id=\"√2-2\"><span class=\"toc-item-num\">2&nbsp;&nbsp;</span>√<span style=\"text-decoration: overline\">2</span></a></div><div class=\"lev2 toc-item\"><a href=\"#Dancing-squares\" data-toc-modified-id=\"Dancing-squares-2.1\"><span class=\"toc-item-num\">2.1&nbsp;&nbsp;</span>Dancing squares</a></div><div class=\"lev2 toc-item\"><a href=\"#Nearest-miss-generators\" data-toc-modified-id=\"Nearest-miss-generators-2.2\"><span class=\"toc-item-num\">2.2&nbsp;&nbsp;</span>Nearest miss generators</a></div><div class=\"lev2 toc-item\"><a href=\"#Lets-generate-larger-near-misses\" data-toc-modified-id=\"Lets-generate-larger-near-misses-2.3\"><span class=\"toc-item-num\">2.3&nbsp;&nbsp;</span>Lets generate larger near misses</a></div><div class=\"lev1 toc-item\"><a href=\"#That-one-picture-to-capture-√2\" data-toc-modified-id=\"That-one-picture-to-capture-√2-3\"><span class=\"toc-item-num\">3&nbsp;&nbsp;</span>That one picture to capture √2</a></div><div class=\"lev2 toc-item\"><a href=\"#Turtle-initialisation\" data-toc-modified-id=\"Turtle-initialisation-3.1\"><span class=\"toc-item-num\">3.1&nbsp;&nbsp;</span>Turtle initialisation</a></div><div class=\"lev1 toc-item\"><a href=\"#Final-turtle-graphic\" data-toc-modified-id=\"Final-turtle-graphic-4\"><span class=\"toc-item-num\">4&nbsp;&nbsp;</span>Final turtle graphic</a></div>"
]
},
{
"cell_type": "markdown",
"metadata": {
"inputHidden": false,
"outputHidden": false
},
"source": [
"\n",
"\n",
"# Tennenbaum root-2 graphic"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"I watched a mathologer [video](https://www.youtube.com/watch?v=yk6wbvNPZW0&feature=youtu.be&t=8m39s) in which the presenter, Professor Burkard Polster, gives visual proofs of the irrationality of some square roots. \n",
"\n",
"Please watch the video at least once; I found it interesting.\n",
"\n",
"Burkard goes on to state many things about $$\\sqrt{3}$$ and the allied equation $$x^2 + x^2 + x^2 = y^2$$ having no integer solutions.\n",
"\n",
"I will do similar for &radic;<span style=\"text-decoration:overline;\">2</span>\n",
"\n"
]
},
{
"cell_type": "markdown",
"metadata": {
"inputHidden": false,
"outputHidden": false
},
"source": [
"[![IMAGE ALT TEXT](#file-root2_tennenbaum.jpg)](https://youtu.be/yk6wbvNPZW0?t=8m39s \"Visualising irrationality with triangular squares\")\n",
"\n",
"Click image to go to relevant part of the video."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# &radic;<span style=\"text-decoration:overline;\">2</span>\n",
"\n",
"He proves that the two brown squares, (with sides x), taken together, and the white square (of sides y), used in his illustrations cannot have the same number of mini squares: $$x^2 + x^2 \\not= y^2$$\n",
"He choses the sizes of the of these squares to be as close as possible - differing by just one.\n",
"\n",
"12 and 17 for the still from the video as shown above form a \"nearest miss\" solution and inthis case: $$12^2 + 12^2 = 17^2 - 1$$\n",
"\n",
"This also means that <math>17/12</math> is a good approximation for &radic;<span style=\"text-decoration:overline;\">2</span>."
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"inputHidden": false,
"outputHidden": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"1.4142135623730951\n",
"1.4166666666666667\n"
]
}
],
"source": [
"print(2**0.5)\n",
"print(17/12)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Dancing squares\n",
"After another stage of the square animation he would end up with the two white triangles and the single, central, darker brown overlap squares as his new, smaller, x and y of size 5 and 7.\n",
"\n",
"5 and 7 correspond to a new \"nearest miss\" solution as $$5^2 + 5^2 = 7^2 + 1$$\n",
"\n",
"Yet another stage of animation would produce an even smaller near miss solution of 2 and 3 where: $$2^2 + 2^2 = 3^2 - 1$$"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Nearest miss generators\n",
"If the big square is of side y then if one of the smaller squares slides in from the left then it will leave a white region of size (y - x) to the left of it. This forms the sides of one of the new x squares.\n",
"When the other x square is slid in from the right then the length of the dark brown central region has two times the new x chopped out of the original y, .e. new y is y minus twice (y - x) or simply 2x - y.\n",
"\n",
"Lets code:"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"inputHidden": false,
"outputHidden": false
},
"outputs": [],
"source": [
"def smaller(x, y):\n",
" return y-x, 2*x - y"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"inputHidden": false,
"outputHidden": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"x, y, delta = 12 17 -1\n"
]
}
],
"source": [
"x, y = 12, 17\n",
"print('x, y, delta =', x, y, 2*x**2 - y**2)"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {
"inputHidden": false,
"outputHidden": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"x, y, delta = 5 7 1\n"
]
}
],
"source": [
"x, y = smaller(x, y)\n",
"print('x, y, delta =', x, y, 2*x**2 - y**2)"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {
"inputHidden": false,
"outputHidden": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"x, y, delta = 2 3 -1\n"
]
}
],
"source": [
"x, y = smaller(x, y)\n",
"print('x, y, delta =', x, y, 2*x**2 - y**2)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Lets generate larger near misses\n",
"Running the choreography in reverse is catured by this code:"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {
"inputHidden": false,
"outputHidden": false
},
"outputs": [],
"source": [
"def bigger(x, y):\n",
" print(f'x, y; delta; approx. √2 = {x:3}, {y:3}; {2*x**2 - y**2:+2}; {y/x}')\n",
" return x + y, 2*x + y\n"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {
"inputHidden": false,
"outputHidden": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"x, y; delta; approx. √2 = 2, 3; -1; 1.5\n",
"x, y; delta; approx. √2 = 5, 7; +1; 1.4\n",
"x, y; delta; approx. √2 = 12, 17; -1; 1.4166666666666667\n",
"x, y; delta; approx. √2 = 29, 41; +1; 1.4137931034482758\n",
"x, y; delta; approx. √2 = 70, 99; -1; 1.4142857142857144\n",
"x, y; delta; approx. √2 = 169, 239; +1; 1.4142011834319526\n",
"x, y; delta; approx. √2 = 408, 577; -1; 1.4142156862745099\n"
]
}
],
"source": [
"x, y = 2, 3 # as above\n",
"for _ in range(7):\n",
" x, y = bigger(x, y)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# That one picture to capture √2 \n",
"<img src=\"root2_encapsulated.jpg\"></image>\n",
"\n",
"I liked the graphic so much that I decided to do some turtle graphics to show it\n",
"\n",
"(**Note!** The turtle module doesn't display under Jupyter, but does when run with [nteract](https://nteract.io/))"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {
"inputHidden": false,
"outputHidden": false
},
"outputs": [],
"source": [
"import turtle as t"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Turtle initialisation\n",
"\n",
"I decided to always reset the turtles heading between writing sections of the graphic.\n",
"\n",
"I couldn't find a turtle function to move delta x, delta y, from a current position so created one in the ``moveby`` function."
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {
"inputHidden": false,
"outputHidden": false
},
"outputs": [],
"source": [
"def init_turtle_graphics():\n",
" global t\n",
" \n",
" x, x2y = 70, 3/4 *9.7 / 8.9\n",
" y = x* x2y\n",
" t.reset()\n",
" t.screensize(400, 300)\n",
" t.setworldcoordinates(-x, -y, x, y)\n",
" t.setposition(0, 0)\n",
" t.setheading(0)\n",
" t.width(4) # pixels\n",
" t.delay(0)\n",
"\n",
"def moveby(delta_x, delta_y):\n",
" global t\n",
" \n",
" heading = t.heading()\n",
" t.setheading(0)\n",
" t.forward(delta_x)\n",
" t.left(90)\n",
" t.forward(delta_y)\n",
" t.setheading(heading) # Preserve heading"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {
"inputHidden": false,
"outputHidden": false
},
"outputs": [],
"source": [
"def square(side=1, colour=\"yellow\"):\n",
" global t\n",
" \n",
" t.pendown()\n",
" t.fillcolor(colour)\n",
" t.begin_fill()\n",
" for _ in range(4):\n",
" t.forward(side)\n",
" t.left(90)\n",
" t.end_fill()\n",
" t.penup()\n"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {
"inputHidden": false,
"outputHidden": false
},
"outputs": [],
"source": [
"\n",
"def _chev(x, y, start):\n",
" \"Draw a single chevron. Initial heading going into the function is important\"\n",
" global t\n",
"\n",
" t.begin_fill()\n",
" for s in (2*x - y, y - x, x, x, y - x, 2*x - y):\n",
" t.fd(s)\n",
" t.right(90)\n",
" t.end_fill()\n",
" t.penup()\n",
" t.goto(start)\n",
" t.setheading(0)\n"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {
"inputHidden": false,
"outputHidden": false
},
"outputs": [],
"source": [
"def bl_chevron(x=5, y=7, colour=\"orange\"):\n",
" \"Bottom left chevron\"\n",
" global t\n",
" \n",
" start = t.position()\n",
" t.pendown()\n",
" t.fillcolor(colour)\n",
" _chev(x, y, start)\n",
"\n",
"def ur_chevron(x=5, y=7, colour=\"orange\"):\n",
" \"Upper right chevron\"\n",
" global t\n",
" \n",
" start = t.position()\n",
" moveby(2*x - y, 2*x - y)\n",
" t.pendown()\n",
" t.fillcolor(colour)\n",
" t.left(180)\n",
" _chev(x, y, start)\n",
"\n",
"def br_chevron(x=5, y=7, colour=\"orange\"):\n",
" \"Bottom right chevron\"\n",
" global t\n",
" \n",
" start = t.position()\n",
" moveby(2*x - y, 0)\n",
" t.pendown()\n",
" t.fillcolor(colour)\n",
" t.left(90)\n",
" _chev(x, y, start)\n",
"\n",
"def ul_chevron(x=5, y=7, colour=\"orange\"):\n",
" \"Upper left chevron\"\n",
" global t\n",
" \n",
" start = t.position()\n",
" moveby(0, 2*x - y)\n",
" t.pendown()\n",
" t.fillcolor(colour)\n",
" t.left(-90)\n",
" _chev(x, y, start)\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {
"inputHidden": false,
"outputHidden": false
},
"outputs": [],
"source": [
"\n",
"def ur_square(x, y, colour=\"red\"):\n",
" global t\n",
" \n",
" start = t.position()\n",
" moveby(2*x - y, 2*x - y)\n",
" square(y - x, colour)\n",
" t.goto(start)\n",
"\n",
"def bl_square(x, y, colour=\"red\"):\n",
" global t\n",
" \n",
" start = t.position()\n",
" moveby(-(y - x), -(y - x))\n",
" square(y - x, colour)\n",
" t.goto(start)\n",
"\n",
"def ul_square(x, y, colour=\"red\"):\n",
" global t\n",
" \n",
" start = t.position()\n",
" moveby(-(y - x), 2*x - y)\n",
" square(y - x, colour)\n",
" t.goto(start)\n",
"\n",
"def br_square(x, y, colour=\"red\"):\n",
" global t\n",
" \n",
" start = t.position()\n",
" moveby(2*x - y, -(y - x))\n",
" square(y - x, colour)\n",
" t.goto(start)\n"
]
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {
"inputHidden": false,
"outputHidden": false
},
"outputs": [],
"source": [
"init_turtle_graphics()\n",
"colour_names = \"peru,lime green,dodger blue,slate blue\".split(',')\n",
"colour_names += colour_names[:1] # Controls the level of nesting\n",
"x, y = 1, 1# Smallest nearest miss\n",
"# Pattern of drawing alternates between levels so will swap the drawing functions\n",
"chev_squares = [(bl_chevron, ur_chevron, ul_square, br_square),\n",
" (ul_chevron, br_chevron, bl_square, ur_square)]\n",
"square(x, \"yellow\")\n",
"for colour in colour_names:\n",
" x, y = x + y, 2*x + y # Next bigger tenenbaum squares: 2*x**2 == y**2 +/- 1\n",
" chev1, chev2, sqr1, sqr2 = chev_squares[0]\n",
" chev_squares.insert(0, chev_squares.pop(-1))\n",
" chev1(x, y, colour)\n",
" chev2(x, y, colour)\n",
" sqr1(x, y)\n",
" sqr2(x, y)\n",
" moveby(-(y - x), -(y - x))\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Final turtle graphic\n",
"<img src=\"root2_turtle.jpg\"></img>"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernel_info": {
"name": "python3"
},
"kernelspec": {
"display_name": "Python [default]",
"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.6"
},
"nav_menu": {},
"nteract": {
"version": "0.11.6"
},
"toc": {
"navigate_menu": true,
"number_sections": true,
"sideBar": true,
"threshold": 6,
"toc_cell": true,
"toc_section_display": "block",
"toc_window_display": false
}
},
"nbformat": 4,
"nbformat_minor": 4
}
# -*- coding: utf-8 -*-
"""
Created on Wed Sep 26 07:33:53 2018
@author: Paddy3118
"""
import turtle as t
# ## Turtle initialisation
#
# I decided to always reset the turtles heading between writing sections of the graphic.
#
# I couldn't find a turtle function to move delta x, delta y, from a current position so created one in the ``moveby`` function.
# In[23]:
def init_turtle_graphics():
global t
x, x2y = 70, 3/4 *9.7 / 8.9
y = x* x2y
t.reset()
t.screensize(400, 300)
t.setworldcoordinates(-x, -y, x, y)
t.setposition(0, 0)
t.setheading(0)
t.width(4) # pixels
t.delay(1)
def moveby(delta_x, delta_y):
global t
heading = t.heading()
t.setheading(0)
t.forward(delta_x)
t.left(90)
t.forward(delta_y)
t.setheading(heading) # Preserve heading
# In[24]:
def square(side=1, colour="yellow"):
global t
t.pendown()
t.fillcolor(colour)
t.begin_fill()
for _ in range(4):
t.forward(side)
t.left(90)
t.end_fill()
t.penup()
# In[25]:
def _chev(x, y, start):
"Draw a single chevron. Initial heading going into the function is important"
global t
t.begin_fill()
for s in (2*x - y, y - x, x, x, y - x, 2*x - y):
t.fd(s)
t.right(90)
t.end_fill()
t.penup()
t.goto(start)
t.setheading(0)
# In[26]:
def bl_chevron(x=5, y=7, colour="orange"):
"Bottom left chevron"
global t
start = t.position()
t.pendown()
t.fillcolor(colour)
_chev(x, y, start)
def ur_chevron(x=5, y=7, colour="orange"):
"Upper right chevron"
global t
start = t.position()
moveby(2*x - y, 2*x - y)
t.pendown()
t.fillcolor(colour)
t.left(180)
_chev(x, y, start)
def br_chevron(x=5, y=7, colour="orange"):
"Bottom right chevron"
global t
start = t.position()
moveby(2*x - y, 0)
t.pendown()
t.fillcolor(colour)
t.left(90)
_chev(x, y, start)
def ul_chevron(x=5, y=7, colour="orange"):
"Upper left chevron"
global t
start = t.position()
moveby(0, 2*x - y)
t.pendown()
t.fillcolor(colour)
t.left(-90)
_chev(x, y, start)
# In[27]:
def ur_square(x, y, colour="red"):
global t
start = t.position()
moveby(2*x - y, 2*x - y)
square(y - x, colour)
t.goto(start)
def bl_square(x, y, colour="red"):
global t
start = t.position()
moveby(-(y - x), -(y - x))
square(y - x, colour)
t.goto(start)
def ul_square(x, y, colour="red"):
global t
start = t.position()
moveby(-(y - x), 2*x - y)
square(y - x, colour)
t.goto(start)
def br_square(x, y, colour="red"):
global t
start = t.position()
moveby(2*x - y, -(y - x))
square(y - x, colour)
t.goto(start)
# In[28]:
init_turtle_graphics()
colour_names = "peru,lime green,dodger blue,slate blue".split(',')
colour_names += colour_names[:1] # Controls the level of nesting
x, y = 1, 1# Smallest nearest miss
# Pattern of drawing alternates between levels so will swap the drawing functions
chev_squares = [(bl_chevron, ur_chevron, ul_square, br_square),
(ul_chevron, br_chevron, bl_square, ur_square)]
square(x, "yellow")
for colour in colour_names:
x, y = x + y, 2*x + y # Next bigger tenenbaum squares: 2*x**2 == y**2 +/- 1
chev1, chev2, sqr1, sqr2 = chev_squares[0]
chev_squares.insert(0, chev_squares.pop(-1))
chev1(x, y, colour)
chev2(x, y, colour)
sqr1(x, y)
sqr2(x, y)
moveby(-(y - x), -(y - x))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment