Actual timed Mathomatic output from the fibonacci script
Mathomatic version 16.0.1
Copyright © 1987-2012 George Gesslein II.
200 equation spaces available in RAM; 2 megabytes per equation space.
HTML color mode enabled; manage by typing "help color".
Reading in files specified on the command line...
1−>
1−> ; This Mathomatic input file contains the mathematical formula to
1−> ; directly calculate the "n"th Fibonacci number.
1−> ; The formula presented here is called Binet's formula, found at
1−> ; http://en.wikipedia.org/wiki/Fibonacci_number
1−> ;
1−> ; The Fibonacci sequence is the endless integer sequence:
1−> ; 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 ...
1−> ; Any Fibonacci number is always the sum of the previous two Fibonacci numbers.
1−> ;
1−> ; Easy to understand info on the golden ratio can be found here:
1−> ; http://www.mathsisfun.com/numbers/golden-ratio.html
1−>
1−> -1/phi=1-phi ; Derive the golden ratio (phi) from this quadratic polynomial.
-1
#1: ––– = 1 − phi
phi
1−> 0 ; show it is quadratic
Solve successful:
#1: 0 = ((1 − phi)·phi) + 1
1−> unfactor
#1: 0 = phi − phi^2 + 1
1−> solve verifiable for phi ; The golden ratio will help us directly compute Fibonacci numbers.
Solving equation #1 for phi with required verification...
Equation is a degree 2 polynomial equation in phi.
Equation was solved with the quadratic formula.
Solve and "simplify quick" successful:
1
(1 − ((5^–)·sign))
2
#1: phi = ––––––––––––––––––
2
All solutions verified.
1−> replace sign with -1 ; the golden ratio constant:
1
(1 + (5^–))
2
#1: phi = –––––––––––
2
1−> fibonacci = ((phi^n) - ((1 - phi)^n))/(phi - (1 - phi)) ; Binet's Fibonacci formula.
(phi^n − ((1 − phi)^n))
#2: fibonacci = –––––––––––––––––––––––
(phi − 1 + phi)
2−> eliminate phi ; Completed direct Fibonacci formula:
Eliminating variable phi using solved equation #1...
1 1
(1 + (5^–)) (1 + (5^–))
2 2
((–––––––––––^n) − ((1 − –––––––––––)^n))
2 2
#2: fibonacci = –––––––––––––––––––––––––––––––––––––––––
1
(5^–)
2
2−> simplify ; Note that Mathomatic rationalizes the denominator here.
1 1 1
(5^–)·(((1 + (5^–))^n) − ((1 − (5^–))^n))
2 2 2
#2: fibonacci = –––––––––––––––––––––––––––––––––––––––––
(5·2^n)
2−> for n 1 20 ; Display the first 20 Fibonacci numbers by plugging in values 1-20:
n = 1: 1
n = 2: 1
n = 3: 2
n = 4: 3
n = 5: 5
n = 6: 8
n = 7: 13
n = 8: 21
n = 9: 34
n = 10: 55
n = 11: 89
n = 12: 144
n = 13: 233
n = 14: 377
n = 15: 610
n = 16: 987
n = 17: 1597
n = 18: 2584
n = 19: 4181
n = 20: 6765
2−> ; Note that this formula should work for any positive integer value of n.
Successfully finished reading script file "fibonacci.in".
2−>
End of input.
real 0.00 user 0.00 sys 0.00 seconds total execution time of this script.
More examples www.mathomatic.org