Watch the video on Spirals, Fibonacci, and Being a Plant.
Is Ms. Vihart doing Mathematics?
What is the 100th Fibonacci number . . . the 1,000th . . . the 1,000,000 . . . the $10^{100}$?
Can we use the computer to calculate these numbers?
Can a computer count to $10^{100}$?
Are Ms. Vihart's rectangles related to the Golden Rectangle that was so prized by the ancient Greek architects?
If so, how?
What about drawing those spirals, can we get the computer to draw them?
Understanding how to effectively use a computer as a tool in doing mathematics is the subject of Computational Mathematics.
The first step is to learn how to program, and for this class we will use today's most powerful "platform" for programming in mathematics.
Hello World! Cruel World!! Hello World! Cruel World!! |
Sage is a platform that brings together many powerful open source software packages for doing computational mathematics, and we talk to these packages using the Python programming language.
Python is a high-level scripting language that is particularly well suited for supporting the exploratory nature of Computational Mathematics.
|
|
75 75 75 75 |
|
Note the slightly different spelling here: explore why it is spelled that way.
300000000000000000000000000000000000000000000000000000000000000000000000\ 00000000000000000000000000000 30000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 |
100000000000000000000000000000000000000000000000000000000000000000000000\ 00000000000000000000000000000 10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 |
|
200000000000000000000000000000000000000000000000000000000000000000000000\ 00000000000000000000000000001 20000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001 |
933262154439441526816992388562667004907159682643816214685929638952175999\ 932299156089414639761565182862536979208272237582511852109168640000000000\ 00000000000000 93326215443944152681699238856266700490715968264381621468592963895217599993229915608941463976156518286253697920827223758251185210916864000000000000000000000000 |
|
563 * 102299 * 305687981 * 1271181968890993 * 61409798072746003 * 31015876512649230749968872235979 563 * 102299 * 305687981 * 1271181968890993 * 61409798072746003 * 31015876512649230749968872235979 |
79.6296875989841 79.6296875989841 |
80 80 |
(x^2 + x + 1)*(x^2 - x + 1)*(x + 1)*(x - 1) (x^2 + x + 1)*(x^2 - x + 1)*(x + 1)*(x - 1) |
<type 'sage.rings.integer.Integer'> <type 'sage.rings.integer.Integer'> |
<type 'sage.symbolic.expression.Expression'> <type 'sage.symbolic.expression.Expression'> |
To see what methods can be applied to an object
type the name of the object, followed by a period and hit the tab key.
100000000000000000000000000000000000000000000000000000000000000000000000\ 000000000000000000000000000000000000000000000000000000000000000000000000\ 000000000000000000000000000000000000000000000000000000000000000000000000\ 000000000000000000000000000000000000000000000000000000000000000000000000\ 000000000000000000000000000000000000000000000000000000000000000000000000\ 000000000000000000000000000000000000000000000000000000000000000000000000\ 000000000000000000000000000000000000000000000000000000000000000000000000\ 000000000000000000000000000000000000000000000000000000000000000000000000\ 000000000000000000000000000000000000000000000000000000000000000000000000\ 000000000000000000000000000000000000000000000000000000000000000000000000\ 000000000000000000000000000000000000000000000000000000000000000000000000\ 000000000000000000000000000000000000000000000000000000000000000000000000\ 000000000000000000000000000000000000000000000000000000000000000000000000\ 00000000000000000000000000000000000000000000000000000000000000453 10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000453 |
|
<type 'sage.rings.integer.Integer'> <type 'sage.rings.integer.Integer'> |
10/3 <type 'sage.rings.rational.Rational'> 10/3 <type 'sage.rings.rational.Rational'> |
10 Traceback (click to the left of this block for traceback) ... TypeError: no conversion of this rational to integer 10 Traceback (most recent call last): File "<stdin>", line 1, in <module> File "_sage_input_40.py", line 10, in <module> exec compile(u'open("___code___.py","w").write("# -*- coding: utf-8 -*-\\n" + _support_.preparse_worksheet_cell(base64.b64decode("Yj1hKjMKcHJpbnQoYikKdHlwZShiKQpjPUludGVnZXIoYSoyKQpwcmludChjKQp0eXBlKGMp"),globals())+"\\n"); execfile(os.path.abspath("___code___.py")) File "", line 1, in <module> File "/tmp/tmpxPUmIO/___code___.py", line 6, in <module> c=Integer(a*_sage_const_2 ) File "sage/rings/integer.pyx", line 662, in sage.rings.integer.Integer.__init__ (/usr/local/sage-6.10/src/build/cythonized/sage/rings/integer.c:5806) File "sage/rings/rational.pyx", line 2670, in sage.rings.rational.Rational._integer_ (/usr/local/sage-6.10/src/build/cythonized/sage/rings/rational.c:23379) TypeError: no conversion of this rational to integer |
<type 'sage.symbolic.expression.Expression'> <type 'sage.symbolic.expression.Expression'> |
<type 'sage.symbolic.expression.Expression'> x^5 - 1 <type 'sage.symbolic.expression.Expression'> x^5 - 1 |
(x^5 - 1)^3 (x^5 - 1)^4 (x^5 - 1)^3 (x^5 - 1)^4 |
![]() |
![]() |
(x^4 + x^3 + x^2 + x + 1)^3*(x - 1)^3 (x^4 + x^3 + x^2 + x + 1)^3*(x - 1)^3 |
x/(x^2 - 1) x/(x^2 - 1) |
![]() |
![]() |
Traceback (click to the left of this block for traceback) ... SyntaxError: invalid syntax Traceback (most recent call last): File "<stdin>", line 1, in <module> File "_sage_input_51.py", line 10, in <module> exec compile(u'open("___code___.py","w").write("# -*- coding: utf-8 -*-\\n" + _support_.preparse_worksheet_cell(base64.b64decode("cGxvdCg="),globals())+"\\n"); execfile(os.path.abspath("___code___.py")) File "", line 1, in <module> File "/tmp/tmpubsbt1/___code___.py", line 3 ^ SyntaxError: invalid syntax |
<type 'sage.rings.integer.Integer'> <type 'sage.symbolic.expression.Expression'> <type 'sage.symbolic.expression.Expression'> <type 'sage.symbolic.expression.Expression'> <type 'sage.rings.integer.Integer'> <type 'sage.symbolic.expression.Expression'> <type 'sage.symbolic.expression.Expression'> <type 'sage.symbolic.expression.Expression'> |
|
|
Traceback (click to the left of this block for traceback) ... NameError: name 'y' is not defined Traceback (most recent call last): File "<stdin>", line 1, in <module> File "_sage_input_3.py", line 10, in <module> exec compile(u'open("___code___.py","w").write("# -*- coding: utf-8 -*-\\n" + _support_.preparse_worksheet_cell(base64.b64decode("cmYyPXkvKHleMi0xKQ=="),globals())+"\\n"); execfile(os.path.abspath("___code___.py")) File "", line 1, in <module> File "/tmp/tmpHpNQCa/___code___.py", line 3, in <module> exec compile(u'rf2=y/(y**_sage_const_2 -_sage_const_1 ) File "", line 1, in <module> NameError: name 'y' is not defined |
|
|
|
|
x^3 - 2 == x x^3 - 2 == x |
|
x - 1 == y + z + 1 x + 1 == 2*y + z - 2 x - 1 == y + z + 1 x + 1 == 2*y + z - 2 |
[ [x == r1 + 7, y == 5, z == r1] ] [ [x == r1 + 7, y == 5, z == r1] ] |
|
1 + 1 = 2
1 + 2 = 3
2 + 3 = 5
3 + 5 = 8
5 + 8 = 13
and so on . . .
1 + 1 = 2 1 + 1 = 2 |
1 + 2 = 3 2 + 3 = 5 3 + 5 = 8 5 + 8 = 13 8 + 13 = 21 13 + 21 = 34 21 + 34 = 55 34 + 55 = 89 55 + 89 = 144 89 + 144 = 233 144 + 233 = 377 233 + 377 = 610 377 + 610 = 987 610 + 987 = 1597 987 + 1597 = 2584 1597 + 2584 = 4181 1 + 2 = 3 2 + 3 = 5 3 + 5 = 8 5 + 8 = 13 8 + 13 = 21 13 + 21 = 34 21 + 34 = 55 34 + 55 = 89 55 + 89 = 144 89 + 144 = 233 144 + 233 = 377 233 + 377 = 610 377 + 610 = 987 610 + 987 = 1597 987 + 1597 = 2584 1597 + 2584 = 4181 |
1 + 1 = 2 1 + 2 = 3 2 + 3 = 5 3 + 5 = 8 5 + 8 = 13 8 + 13 = 21 13 + 21 = 34 21 + 34 = 55 34 + 55 = 89 55 + 89 = 144 89 + 144 = 233 144 + 233 = 377 233 + 377 = 610 377 + 610 = 987 610 + 987 = 1597 987 + 1597 = 2584 1597 + 2584 = 4181 2584 + 4181 = 6765 4181 + 6765 = 10946 6765 + 10946 = 17711 10946 + 17711 = 28657 17711 + 28657 = 46368 28657 + 46368 = 75025 46368 + 75025 = 121393 75025 + 121393 = 196418 121393 + 196418 = 317811 196418 + 317811 = 514229 317811 + 514229 = 832040 514229 + 832040 = 1346269 832040 + 1346269 = 2178309 1346269 + 2178309 = 3524578 2178309 + 3524578 = 5702887 3524578 + 5702887 = 9227465 5702887 + 9227465 = 14930352 1 + 1 = 2 1 + 2 = 3 2 + 3 = 5 3 + 5 = 8 5 + 8 = 13 8 + 13 = 21 13 + 21 = 34 21 + 34 = 55 34 + 55 = 89 55 + 89 = 144 89 + 144 = 233 144 + 233 = 377 233 + 377 = 610 377 + 610 = 987 610 + 987 = 1597 987 + 1597 = 2584 1597 + 2584 = 4181 2584 + 4181 = 6765 4181 + 6765 = 10946 6765 + 10946 = 17711 10946 + 17711 = 28657 17711 + 28657 = 46368 28657 + 46368 = 75025 46368 + 75025 = 121393 75025 + 121393 = 196418 121393 + 196418 = 317811 196418 + 317811 = 514229 317811 + 514229 = 832040 514229 + 832040 = 1346269 832040 + 1346269 = 2178309 1346269 + 2178309 = 3524578 2178309 + 3524578 = 5702887 3524578 + 5702887 = 9227465 5702887 + 9227465 = 14930352 |
For more information on almost any sequence of integers, check the
573147844013817084101 573147844013817084101 |
1 + 1 = 2 1 + 2 = 3 2 + 3 = 5 3 + 5 = 8 5 + 8 = 13 8 + 13 = 21 13 + 21 = 34 21 + 34 = 55 34 + 55 = 89 55 + 89 = 144 89 + 144 = 233 144 + 233 = 377 233 + 377 = 610 377 + 610 = 987 610 + 987 = 1597 987 + 1597 = 2584 1597 + 2584 = 4181 2584 + 4181 = 6765 4181 + 6765 = 10946 6765 + 10946 = 17711 10946 + 17711 = 28657 17711 + 28657 = 46368 28657 + 46368 = 75025 1 + 1 = 2 1 + 2 = 3 2 + 3 = 5 3 + 5 = 8 5 + 8 = 13 8 + 13 = 21 13 + 21 = 34 21 + 34 = 55 34 + 55 = 89 55 + 89 = 144 89 + 144 = 233 144 + 233 = 377 233 + 377 = 610 377 + 610 = 987 610 + 987 = 1597 987 + 1597 = 2584 1597 + 2584 = 4181 2584 + 4181 = 6765 4181 + 6765 = 10946 6765 + 10946 = 17711 10946 + 17711 = 28657 17711 + 28657 = 46368 28657 + 46368 = 75025 |
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9] [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] |
|
[2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24] [2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24] |
<type 'int'> <type 'sage.rings.integer.Integer'> <type 'int'> <type 'sage.rings.integer.Integer'> |
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9] [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] True [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] True |
1 + 1 = 2 1 + 2 = 3 2 + 3 = 5 3 + 5 = 8 5 + 8 = 13 8 + 13 = 21 13 + 21 = 34 21 + 34 = 55 34 + 55 = 89 55 + 89 = 144 89 + 144 = 233 144 + 233 = 377 233 + 377 = 610 377 + 610 = 987 610 + 987 = 1597 987 + 1597 = 2584 1597 + 2584 = 4181 2584 + 4181 = 6765 4181 + 6765 = 10946 6765 + 10946 = 17711 10946 + 17711 = 28657 17711 + 28657 = 46368 28657 + 46368 = 75025 1 + 1 = 2 1 + 2 = 3 2 + 3 = 5 3 + 5 = 8 5 + 8 = 13 8 + 13 = 21 13 + 21 = 34 21 + 34 = 55 34 + 55 = 89 55 + 89 = 144 89 + 144 = 233 144 + 233 = 377 233 + 377 = 610 377 + 610 = 987 610 + 987 = 1597 987 + 1597 = 2584 1597 + 2584 = 4181 2584 + 4181 = 6765 4181 + 6765 = 10946 6765 + 10946 = 17711 10946 + 17711 = 28657 17711 + 28657 = 46368 28657 + 46368 = 75025 |
Print the 1,000th Fibonacci number, but not all the others.
268638100244853593861467272021429239676166093189869523401231759976179817\ 002478816893383696544833565641918278561614433563129766736422103503246348\ 50410377680367334151172899169723197082763985615764450078474174626 + 434665576869374564356885276750406258025646605173717804024817290895365554\ 179490518904038798400792551692959225930803226347752096896232398733224711\ 61642996440906533187938298969649928516003704476137795166849228875 = 434665576869374564356885276750406258025646605173717804024817290895365554\ 179490518904038798400792551692959225930803226347752096896232398733224711\ 61642996440906533187938298969649928516003704476137795166849228875 26863810024485359386146727202142923967616609318986952340123175997617981700247881689338369654483356564191827856161443356312976673642210350324634850410377680367334151172899169723197082763985615764450078474174626 + 43466557686937456435688527675040625802564660517371780402481729089536555417949051890403879840079255169295922593080322634775209689623239873322471161642996440906533187938298969649928516003704476137795166849228875 = 43466557686937456435688527675040625802564660517371780402481729089536555417949051890403879840079255169295922593080322634775209689623239873322471161642996440906533187938298969649928516003704476137795166849228875 |
How long do you think it would take to compute the 1,000,000th Fibonacci number?
Give it a shot!
How long do you think it would take to compute the $10^{100}$th Fibonacci number?
3.17460317460317e82 3.17460317460317e82 |
A fast computer --- 10 GHz has $10^{10}$ cycles per second. Computing the $10^{100}$th Fibonacci number
takes $10^{100}$ additions. Suppose each addition mod 20 takes one cycle. That means we take $10^{90}$ seconds.
That's about $3\times 10^{80}$ centuries.
|
An array is an ordered homogeneous collection. A list is an ordered inhomogeneous collection. In low level languages like C when an array is set up it has a fixed size. In higher level languages like Matlab, arrays are dynamic. That is, they can grow as needed. In Python lists are both inhomogeneous and dynamic. They generalize dynamic arrays.
We will start by considering some array operations that are common in most languages, and then explore the additional features provided in Python.
|
<type 'list'> <type 'list'> |
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14] [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14] |
15 15 |
[0, 1, 2, 3, 4, 5, 6, 7, 14, 21, 10, 11, 12, 13, 14] [0, 1, 2, 3, 4, 5, 6, 7, 14, 21, 10, 11, 12, 13, 14] |
[0, 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, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181, 6765, 10946, 17711, 28657, 46368, 75025] [0, 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, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181, 6765, 10946, 17711, 28657, 46368, 75025] |
<type 'list'> <type 'list'> |
[1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181, 6765, 10946, 17711, 28657, 46368, 75025] [1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181, 6765, 10946, 17711, 28657, 46368, 75025] |
[0, -15, sqrt(2), 3/5, 'John Doe', [1, 2, 3]] [0, -15, sqrt(2), 3/5, 'John Doe', [1, 2, 3]] |
0 <type 'sage.rings.integer.Integer'> -15 <type 'sage.rings.integer.Integer'> sqrt(2) <type 'sage.symbolic.expression.Expression'> 3/5 <type 'sage.rings.rational.Rational'> John Doe <type 'str'> [1, 2, 3] <type 'list'> 0 <type 'sage.rings.integer.Integer'> -15 <type 'sage.rings.integer.Integer'> sqrt(2) <type 'sage.symbolic.expression.Expression'> 3/5 <type 'sage.rings.rational.Rational'> John Doe <type 'str'> [1, 2, 3] <type 'list'> |
|
|
[1, 2, 3, 5, 6, 'Philadelphia'] [1, 2, 3, 5, 6, 'Philadelphia'] |
[5, 6, 'Philadelphia', 1, 2, 3] [5, 6, 'Philadelphia', 1, 2, 3] |
[1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181, 6765, 10946, 17711, 28657, 46368, 75025] [1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181, 6765, 10946, 17711, 28657, 46368, 75025] |
|
|
|
|
121393 121393 |
|
131709051675194962952276308712531641206660696499250714188774693672753087\ 040503842576450313012318640774657086218587192595276683635211911952815631\ 558263246079038383460565488061265771846563256883924597824847305817942207\ 073555312471638545088664055239227385677067223979716426435692766130834967\ 194167364320573334359270171671578825517067957550027918605331636558325918\ 692735935102338729837168622286082741537144355375995365951412088276380814\ 259336640247225134836000891558521529150498437169752387119955393571405695\ 9634778700594751875 1317090516751949629522763087125316412066606964992507141887746936727530870405038425764503130123186407746570862185871925952766836352119119528156315582632460790383834605654880612657718465632568839245978248473058179422070735553124716385450886640552392273856770672239797164264356927661308349671941673643205733343592701716715788255170679575500279186053316365583259186927359351023387298371686222860827415371443553759953659514120882763808142593366402472251348360008915585215291504984371697523871199553935714056959634778700594751875 |