def test_fibonacci(): assert [fibonacci(n) for n in range(-3, 5)] == [2, -1, 1, 0, 1, 1, 2, 3] assert fibonacci(100) == 354224848179261915075 assert [lucas(n) for n in range(-3, 5)] == [-4, 3, -1, 2, 1, 3, 4, 7] assert lucas(100) == 792070839848372253127 assert fibonacci(1, x) == 1 assert fibonacci(2, x) == x assert fibonacci(3, x) == x**2 + 1 assert fibonacci(4, x) == x**3 + 2*x
def test_fibonacci(): assert [fibonacci(n) for n in range(-3, 5)] == [2, -1, 1, 0, 1, 1, 2, 3] assert fibonacci(100) == 354224848179261915075 assert [lucas(n) for n in range(-3, 5)] == [-4, 3, -1, 2, 1, 3, 4, 7] assert lucas(100) == 792070839848372253127 assert fibonacci(1, x) == 1 assert fibonacci(2, x) == x assert fibonacci(3, x) == x**2 + 1 assert fibonacci(4, x) == x**3 + 2 * x
def test_approximants(): x, t = symbols("x,t") g = [lucas(k) for k in range(16)] assert [e for e in approximants(g)] == ( [2, -4/(x - 2), (5*x - 2)/(3*x - 1), (x - 2)/(x**2 + x - 1)] ) g = [lucas(k)+fibonacci(k+2) for k in range(16)] assert [e for e in approximants(g)] == ( [3, -3/(x - 1), (3*x - 3)/(2*x - 1), -3/(x**2 + x - 1)] ) g = [lucas(k)**2 for k in range(16)] assert [e for e in approximants(g)] == ( [4, -16/(x - 4), (35*x - 4)/(9*x - 1), (37*x - 28)/(13*x**2 + 11*x - 7), (50*x**2 + 63*x - 52)/(37*x**2 + 19*x - 13), (-x**2 - 7*x + 4)/(x**3 - 2*x**2 - 2*x + 1)] ) p = [sum(binomial(k,i)*x**i for i in range(k+1)) for k in range(16)] y = approximants(p, t, simplify=True) assert next(y) == 1 assert next(y) == -1/(t*(x + 1) - 1)
def a(n): return (sp.fibonacci(n + 1) + sp.lucas(n)) / (sp.fibonacci(n + 2) + sp.lucas(n + 1))
import numpy as np import sympy as sp import math from sympy import symbols x = symbols("x", positive=True) # Fibonacci Golden Nuggets -> Indexes A_F(x) whereby A_F(x) = integer and x = p/q rational number. # # Mathematical Solution: A_F(x) = Generating Function of Fibonacci polynomials = x / (1-x-x*x) # We want A_F(x) = x / (1-x-x*x) = k for some integer k # We solve the equation: x = k - k*x - k*x**2 # Trial Code to solve the equation cnt = 0 for k in range(1, 10**6): solns = sp.solve(k * x**2 + (k + 1) * x - k) if solns[0].is_rational: print(k, solns[0]) # OEIS: A081018 # 2, 15, 104, 714, 4895, 33552, 229970, 1576239, 10803704, 74049690, 507544127, 3478759200, 23843770274, # 163427632719, 1120149658760, 7677619978602, 52623190191455, 360684711361584, 2472169789339634, 16944503814015855, 116139356908771352, 796030994547383610 # Formula to get this sequence: (Lucas Numbers of (4*n+1) - 1)/5 or Fibonacci(2*n)*Fibonacci(2*n+1) # Solution Code to get the answer for n in range(1, 20): print(n, (sp.lucas(4 * n + 1) - 1) / 5)
def test_random(): from sympy import posify, lucas assert posify(x)[0]._random() is not None assert lucas(n)._random(2, -2, 0, -1, 1) is None