Kirby,

I am sorry to spoil all the fun, but this is a not a gem but a mathematical trick, and I think the way to deal with mathematical tricks is to explain them, not to verify with code.

There are two Fibonacci sequences that are also geometric sequences 1, x, x^2, ..., x^n,...: when x = phi or x = -1/phi, because phi and -1/phi are the roots of the quadratic equation x^2 = x+1. Any Fibonacci sequence is a linear combination of these two: F[n] = a*phi^n + b*(-1/phi)^n. a and b can be determined from the first two terms of the sequence:

a + b = F[0]
a*phi - b/phi = F[1]

If you choose F[0] and F[1] (not necessarily integers) in a tricky way, so that b = 0, then F[n] = a*phi^n. In addition, if a = phi^e, then F[n] = phi^(e+n). Working in reverse, you can find F[0] and F[1] that satisfy these conditions and get the trick going. Here

F[0] = (13 + 5 - 8*sqrt(5))/2 = 9 - 4*sqrt(5)
F[1] =  (-8 - 3 + 5*sqrt(5))/2 = (-11+5sqrt(5))/2

Easy to verify that F0*phi = F1, so, indeed, b = 0 and F[n] is a geometric sequence. Also, phi^6 = 9 + 4*sqrt(5), so F[0]*phi^6 = 1 and a = F[0] = phi^(-6). You get F[n] = phi^(n-6).

Gary Litvin
www.skylit.com

At 10:04 PM 11/22/2013, you wrote:

Here's something mathematical from the Poly list [1], adapting
something by David Koski.

The code shows how one might use a program to express a
cool relationship, without offering a proof.

The unit-test shows use raising PHI from the -6 to the 29th
power and finding an equivalent expression built solely from
three consecutive Fibonacci numbers and the sqrt(5).

Something like:

LOOP:
   PHI ** E = (FIB[N] + FIB[N-2] + FIB[N-1]*RT5) / 2
   E += 1
   N += 1

Start with:

E = -6

FIB[N-2] = 13
FIB[N-1] = -8
FIB[N]    =  5

in . . . 13, -8, 5, -3, 2, -1,1, 0, 1, 2, 3, 5, 8,13 . . .

===


"""
Encapsulating a discovery -- not a proof.
By David Koski (Python by K. Urner)

Failure at around 37th power is due to floating point limitations.
"""

import unittest

def fibonacci(a=0, b=1):
    while True:
        yield a
        a, b = b, a + b


series1 = fibonacci(5, -3)  # 5, -3, 2, -1, 1, 0 , 1, 2, 3, 5, 8
series2 = fibonacci(-8, 5)  # -8, 5, -3, 2, -1, 1, 0 , 1, 2, 3, 5, 8
series3 = fibonacci(13,-8)  # 13, -8, 5, -3, 2, -1, 1, 0 , 1, 2, 3, 5, 8

RT5 = pow(5, .5)   # "square root" of five
PHI = (1 + RT5)/2  # golden proportion

def cool_formula():
    """
    Two fib numbers, two apart, plus the one in the middle * sqrt(5)
    all over 2, gives PHI to a power.  Advancing all three sequences
    gives successive powers.
    """
    while True:
        yield (next(series1) + next(series3) + next(series2) * RT5)/2.0

class TestPhi(unittest.TestCase):

    def test_loop(self):
        gem = cool_formula()
        for e in range(-6, 30):  # adjust range (fails about 37th power)
            answer = next( gem )
            self.assertAlmostEqual( PHI ** e, answer)

if __name__ == "__main__":
    unittest.main()

[1]  Polyhedron mailing list
Contributions to <mailto:polyhed...@lists.mathconsult.ch>mailto:polyhed...@lists.mathconsult.ch Admin: <http://lists.mathconsult.ch/mailman/listinfo/polyhedron>http://lists.mathconsult.ch/mailman/listinfo/polyhedron Archive: <http://lists.mathconsult.ch/mailman/private/polyhedron/>http://lists.mathconsult.ch/mailman/private/polyhedron/

_______________________________________________
Edu-sig mailing list
Edu-sig@python.org
https://mail.python.org/mailman/listinfo/edu-sig

At 10:04 PM 11/22/2013, kirby urner wrote:


Here's something mathematical from the Poly list [1], adapting
something by David Koski.

The code shows how one might use a program to express a
cool relationship, without offering a proof.

The unit-test shows use raising PHI from the -6 to the 29th
power and finding an equivalent expression built solely from
three consecutive Fibonacci numbers and the sqrt(5).

Something like:

LOOP:
   PHI ** E = (FIB[N] + FIB[N-2] + FIB[N-1]*RT5) / 2
   E += 1
   N += 1

Start with:

E = -6

FIB[N-2] = 13
FIB[N-1] = -8
FIB[N]    =  5

in . . . 13, -8, 5, -3, 2, -1,1, 0, 1, 2, 3, 5, 8,13 . . .

===


"""
Encapsulating a discovery -- not a proof.
By David Koski (Python by K. Urner)

Failure at around 37th power is due to floating point limitations.
"""

import unittest

def fibonacci(a=0, b=1):
    while True:
        yield a
        a, b = b, a + b


series1 = fibonacci(5, -3)  # 5, -3, 2, -1, 1, 0 , 1, 2, 3, 5, 8
series2 = fibonacci(-8, 5)  # -8, 5, -3, 2, -1, 1, 0 , 1, 2, 3, 5, 8
series3 = fibonacci(13,-8)  # 13, -8, 5, -3, 2, -1, 1, 0 , 1, 2, 3, 5, 8

RT5 = pow(5, .5)   # "square root" of five
PHI = (1 + RT5)/2  # golden proportion

def cool_formula():
    """
    Two fib numbers, two apart, plus the one in the middle * sqrt(5)
    all over 2, gives PHI to a power.  Advancing all three sequences
    gives successive powers.
    """
    while True:
        yield (next(series1) + next(series3) + next(series2) * RT5)/2.0

class TestPhi(unittest.TestCase):

    def test_loop(self):
        gem = cool_formula()
        for e in range(-6, 30):  # adjust range (fails about 37th power)
            answer = next( gem )
            self.assertAlmostEqual( PHI ** e, answer)

if __name__ == "__main__":
    unittest.main()

[1]  Polyhedron mailing list
Contributions to <mailto:polyhed...@lists.mathconsult.ch>mailto:polyhed...@lists.mathconsult.ch Admin: <http://lists.mathconsult.ch/mailman/listinfo/polyhedron>http://lists.mathconsult.ch/mailman/listinfo/polyhedron Archive: <http://lists.mathconsult.ch/mailman/private/polyhedron/>http://lists.mathconsult.ch/mailman/private/polyhedron/

_______________________________________________
Edu-sig mailing list
Edu-sig@python.org
https://mail.python.org/mailman/listinfo/edu-sig
_______________________________________________
Edu-sig mailing list
Edu-sig@python.org
https://mail.python.org/mailman/listinfo/edu-sig

Reply via email to