本文整理汇总了Python中sympy.fibonacci函数的典型用法代码示例。如果您正苦于以下问题:Python fibonacci函数的具体用法?Python fibonacci怎么用?Python fibonacci使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了fibonacci函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_evalf_integer_parts
def test_evalf_integer_parts():
a = floor(log(8)/log(2) - exp(-1000), evaluate=False)
b = floor(log(8)/log(2), evaluate=False)
assert a.evalf() == 3
assert b.evalf() == 3
# equals, as a fallback, can still fail but it might succeed as here
assert ceiling(10*(sin(1)**2 + cos(1)**2)) == 10
assert int(floor(factorial(50)/E, evaluate=False).evalf(70)) == \
long(11188719610782480504630258070757734324011354208865721592720336800)
assert int(ceiling(factorial(50)/E, evaluate=False).evalf(70)) == \
long(11188719610782480504630258070757734324011354208865721592720336801)
assert int(floor((GoldenRatio**999 / sqrt(5) + Rational(1, 2)))
.evalf(1000)) == fibonacci(999)
assert int(floor((GoldenRatio**1000 / sqrt(5) + Rational(1, 2)))
.evalf(1000)) == fibonacci(1000)
assert ceiling(x).evalf(subs={x: 3}) == 3
assert ceiling(x).evalf(subs={x: 3*I}) == 3*I
assert ceiling(x).evalf(subs={x: 2 + 3*I}) == 2 + 3*I
assert ceiling(x).evalf(subs={x: 3.}) == 3
assert ceiling(x).evalf(subs={x: 3.*I}) == 3*I
assert ceiling(x).evalf(subs={x: 2. + 3*I}) == 2 + 3*I
assert float((floor(1.5, evaluate=False)+1/9).evalf()) == 1 + 1/9
assert float((floor(0.5, evaluate=False)+20).evalf()) == 20
开发者ID:cklb,项目名称:sympy,代码行数:26,代码来源:test_evalf.py
示例2: test_linrec
def test_linrec():
assert linrec(coeffs=[1, 1], init=[1, 1], n=20) == 10946
assert linrec(coeffs=[1, 2, 3, 4, 5], init=[1, 1, 0, 2], n=10) == 1040
assert linrec(coeffs=[0, 0, 11, 13], init=[23, 27], n=25) == 59628567384
assert linrec(coeffs=[0, 0, 1, 1, 2], init=[1, 5, 3], n=15) == 165
assert linrec(coeffs=[11, 13, 15, 17], init=[1, 2, 3, 4], n=70) == \
56889923441670659718376223533331214868804815612050381493741233489928913241
assert linrec(coeffs=[0]*55 + [1, 1, 2, 3], init=[0]*50 + [1, 2, 3], n=4000) == \
702633573874937994980598979769135096432444135301118916539
assert linrec(coeffs=[11, 13, 15, 17], init=[1, 2, 3, 4], n=10**4)
assert linrec(coeffs=[11, 13, 15, 17], init=[1, 2, 3, 4], n=10**5)
assert all(linrec(coeffs=[1, 1], init=[0, 1], n=n) == fibonacci(n)
for n in range(95, 115))
assert all(linrec(coeffs=[1, 1], init=[1, 1], n=n) == fibonacci(n + 1)
for n in range(595, 615))
a = [S(1)/2, S(3)/4, S(5)/6, 7, S(8)/9, S(3)/5]
b = [1, 2, 8, S(5)/7, S(3)/7, S(2)/9, 6]
x, y, z = symbols('x y z')
assert linrec(coeffs=a[:5], init=b[:4], n=80) == \
Rational(1726244235456268979436592226626304376013002142588105090705187189,
1960143456748895967474334873705475211264)
assert linrec(coeffs=a[:4], init=b[:4], n=50) == \
Rational(368949940033050147080268092104304441, 504857282956046106624)
assert linrec(coeffs=a[3:], init=b[:3], n=35) == \
Rational(97409272177295731943657945116791049305244422833125109,
814315512679031689453125)
assert linrec(coeffs=[0]*60 + [S(2)/3, S(4)/5], init=b, n=3000) == \
26777668739896791448594650497024/S(48084516708184142230517578125)
raises(TypeError, lambda: linrec(coeffs=[11, 13, 15, 17], init=[1, 2, 3, 4, 5], n=1))
raises(TypeError, lambda: linrec(coeffs=a[:4], init=b[:5], n=10000))
raises(ValueError, lambda: linrec(coeffs=a[:4], init=b[:4], n=-10000))
raises(TypeError, lambda: linrec(x, b, n=10000))
raises(TypeError, lambda: linrec(a, y, n=10000))
assert linrec(coeffs=[x, y, z], init=[1, 1, 1], n=4) == \
x**2 + x*y + x*z + y + z
assert linrec(coeffs=[1, 2, 1], init=[x, y, z], n=20) == \
269542*x + 664575*y + 578949*z
assert linrec(coeffs=[0, 3, 1, 2], init=[x, y], n=30) == \
58516436*x + 56372788*y
assert linrec(coeffs=[0]*50 + [1, 2, 3], init=[x, y, z], n=1000) == \
11477135884896*x + 25999077948732*y + 41975630244216*z
开发者ID:asmeurer,项目名称:sympy,代码行数:51,代码来源:test_recurrences.py
示例3: test_evalf_integer_parts
def test_evalf_integer_parts():
a = floor(log(8)/log(2) - exp(-1000), evaluate=False)
b = floor(log(8)/log(2), evaluate=False)
raises(PrecisionExhausted, "a.evalf()")
assert a.evalf(chop=True) == 3
assert a.evalf(maxprec=500) == 2
raises(PrecisionExhausted, "b.evalf()")
raises(PrecisionExhausted, "b.evalf(maxprec=500)")
assert b.evalf(chop=True) == 3
assert int(floor(factorial(50)/E,evaluate=False).evalf()) == \
11188719610782480504630258070757734324011354208865721592720336800L
assert int(ceiling(factorial(50)/E,evaluate=False).evalf()) == \
11188719610782480504630258070757734324011354208865721592720336801L
assert int(floor((GoldenRatio**999 / sqrt(5) + Rational(1,2))).evalf(1000)) == fibonacci(999)
assert int(floor((GoldenRatio**1000 / sqrt(5) + Rational(1,2))).evalf(1000)) == fibonacci(1000)
开发者ID:jcockayne,项目名称:sympy-rkern,代码行数:15,代码来源:test_evalf.py
示例4: test_evalf_integer_parts
def test_evalf_integer_parts():
a = floor(log(8)/log(2) - exp(-1000), evaluate=False)
b = floor(log(8)/log(2), evaluate=False)
raises(PrecisionExhausted, "a.evalf()")
assert a.evalf(chop=True) == 3
assert a.evalf(maxn=500) == 2
assert b.evalf() == 3
# equals, as a fallback, can still fail but it might succeed as here
assert ceiling(10*(sin(1)**2 + cos(1)**2)) == 10
assert int(floor(factorial(50)/E,evaluate=False).evalf()) == \
11188719610782480504630258070757734324011354208865721592720336800L
assert int(ceiling(factorial(50)/E,evaluate=False).evalf()) == \
11188719610782480504630258070757734324011354208865721592720336801L
assert int(floor((GoldenRatio**999 / sqrt(5) + Rational(1,2))).evalf(1000)) == fibonacci(999)
assert int(floor((GoldenRatio**1000 / sqrt(5) + Rational(1,2))).evalf(1000)) == fibonacci(1000)
开发者ID:vipulnsward,项目名称:sympy,代码行数:16,代码来源:test_evalf.py
示例5: test_evalf_near_integers
def test_evalf_near_integers():
# Binet's formula
f = lambda n: ((1 + sqrt(5))**n)/(2**n * sqrt(5))
assert NS(f(5000) - fibonacci(5000), 10, maxn=1500) == '5.156009964e-1046'
# Some near-integer identities from
# http://mathworld.wolfram.com/AlmostInteger.html
assert NS('sin(2017*2**(1/5))', 15) == '-1.00000000000000'
assert NS('sin(2017*2**(1/5))', 20) == '-0.99999999999999997857'
assert NS('1+sin(2017*2**(1/5))', 15) == '2.14322287389390e-17'
assert NS('45 - 613*E/37 + 35/991', 15) == '6.03764498766326e-11'
开发者ID:QuaBoo,项目名称:sympy,代码行数:10,代码来源:test_evalf.py
示例6: test_evalf_near_integers
def test_evalf_near_integers():
# Binet's formula
f = lambda n: ((1 + sqrt(5)) ** n) / (2 ** n * sqrt(5))
assert NS(f(5000) - fibonacci(5000), 10, maxprec=1500) == "5.156009964e-1046"
# Some near-integer identities from
# http://mathworld.wolfram.com/AlmostInteger.html
assert NS("sin(2017*2**(1/5))", 15) == "-1.00000000000000"
assert NS("sin(2017*2**(1/5))", 20) == "-0.99999999999999997857"
assert NS("1+sin(2017*2**(1/5))", 15) == "2.14322287389390e-17"
assert NS("45 - 613*E/37 + 35/991", 15) == "6.03764498766326e-11"
开发者ID:tovrstra,项目名称:sympy,代码行数:10,代码来源:test_evalf.py
示例7: test_guess_generating_function
def test_guess_generating_function():
x = Symbol('x')
assert guess_generating_function([fibonacci(k)
for k in range(5, 15)]) == ((3*x + 5)/(-x**2 - x + 1))
assert guess_generating_function(
[1, 2, 5, 14, 41, 124, 383, 1200, 3799, 12122, 38919]) == (
(1/(x**4 + 2*x**2 - 4*x + 1))**(sympify("1/2")))
assert guess_generating_function(sympify(
"[3/2, 11/2, 0, -121/2, -363/2, 121, 4719/2, 11495/2, -8712, -178717/2]")
) == (x + sympify("3/2"))/(11*x**2 - 3*x + 1)
开发者ID:NervenCid,项目名称:sympy,代码行数:10,代码来源:test_guess.py
示例8: test_find_simple_recurrence
def test_find_simple_recurrence():
a = Function('a')
n = Symbol('n')
assert find_simple_recurrence([fibonacci(k) for k in range(12)]) == (
-a(n) - a(n + 1) + a(n + 2))
f = Function('a')
i = Symbol('n')
a = [1, 1, 1]
for k in range(15): a.append(5*a[-1]-3*a[-2]+8*a[-3])
assert find_simple_recurrence(a, A=f, N=i) == (
-8*f(i) + 3*f(i + 1) - 5*f(i + 2) + f(i + 3))
assert find_simple_recurrence([0, 2, 15, 74, 12, 3, 0,
1, 2, 85, 4, 5, 63]) == 0
开发者ID:A-turing-machine,项目名称:sympy,代码行数:14,代码来源:test_guess.py
示例9: test_guess_generating_function
def test_guess_generating_function():
x = Symbol('x')
assert guess_generating_function([fibonacci(k)
for k in range(5, 15)])['ogf'] == ((3*x + 5)/(-x**2 - x + 1))
assert guess_generating_function(
[1, 2, 5, 14, 41, 124, 383, 1200, 3799, 12122, 38919])['ogf'] == (
(1/(x**4 + 2*x**2 - 4*x + 1))**Rational(1, 2))
assert guess_generating_function(sympify(
"[3/2, 11/2, 0, -121/2, -363/2, 121, 4719/2, 11495/2, -8712, -178717/2]")
)['ogf'] == (x + Rational(3, 2))/(11*x**2 - 3*x + 1)
assert guess_generating_function([factorial(k) for k in range(12)],
types=['egf'])['egf'] == 1/(-x + 1)
assert guess_generating_function([k+1 for k in range(12)],
types=['egf']) == {'egf': (x + 1)*exp(x), 'lgdegf': (x + 2)/(x + 1)}
开发者ID:A-turing-machine,项目名称:sympy,代码行数:14,代码来源:test_guess.py
示例10: test_fibonacci
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
开发者ID:B-Rich,项目名称:sympy,代码行数:10,代码来源:test_comb_numbers.py
示例11: test_approximants
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)
开发者ID:A-turing-machine,项目名称:sympy,代码行数:17,代码来源:test_approximants.py
示例12: main
def main():
fibo_var = 39
arr_fibo = []
for i in range(1,fibo_var):
arr_fibo.append(sp.fibonacci(i))
#base will be a number in arr_fibo
#ht will be a number which is +- 1 of base
#(L**2) = (ht**2) + ((base*0.5)**2)
#print arr_fibo
#Calculate the difference betweeen the squares of adjacent numbers
arr_base = []
for i in range(1,len(arr_fibo)):
temp = ((arr_fibo[i]**2) - (arr_fibo[i-1]**2))
arr_base.append(temp)
#Remove zeros from the array
for i in range(0,len(arr_base)-1):
if(arr_base[i] == 0):
arr_base.remove(0)
summa = 0
for i in range(0,len(arr_base)):
ht = arr_base[i] + 1
base = arr_base[i]
var = math.sqrt(((base*0.5)**2) + (ht**2))
if(var.is_integer()):
#print int(var)
summa += int(var)
####################
ht = arr_base[i] - 1
base = arr_base[i]
var = math.sqrt(((base*0.5)**2) + (ht**2))
if(var.is_integer()):
#print int(var)
summa += int(var)
print summa
开发者ID:KartikKannapur,项目名称:Programming_Challenges,代码行数:43,代码来源:138.py
示例13: test_find_linear_recurrence
def test_find_linear_recurrence():
assert sequence((0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55), \
(n, 0, 10)).find_linear_recurrence(11) == [1, 1]
assert sequence((1, 2, 4, 7, 28, 128, 582, 2745, 13021, 61699, 292521, \
1387138), (n, 0, 11)).find_linear_recurrence(12) == [5, -2, 6, -11]
assert sequence(x*n**3+y*n, (n, 0, oo)).find_linear_recurrence(10) \
== [4, -6, 4, -1]
assert sequence(x**n, (n,0,20)).find_linear_recurrence(21) == [x]
assert sequence((1,2,3)).find_linear_recurrence(10, 5) == [0, 0, 1]
assert sequence(((1 + sqrt(5))/2)**n + \
(-(1 + sqrt(5))/2)**(-n)).find_linear_recurrence(10) == [1, 1]
assert sequence(x*((1 + sqrt(5))/2)**n + y*(-(1 + sqrt(5))/2)**(-n), \
(n,0,oo)).find_linear_recurrence(10) == [1, 1]
assert sequence((1,2,3,4,6),(n, 0, 4)).find_linear_recurrence(5) == []
assert sequence((2,3,4,5,6,79),(n, 0, 5)).find_linear_recurrence(6,gfvar=x) \
== ([], None)
assert sequence((2,3,4,5,8,30),(n, 0, 5)).find_linear_recurrence(6,gfvar=x) \
== ([19/2, -20, 27/2], (-31*x**2 + 32*x - 4)/(27*x**3 - 40*x**2 + 19*x -2))
assert sequence(fibonacci(n)).find_linear_recurrence(30,gfvar=x) \
== ([1, 1], -x/(x**2 + x - 1))
开发者ID:KonstantinTogoi,项目名称:sympy,代码行数:20,代码来源:test_sequences.py
示例14: fibonacci_numbers
def fibonacci_numbers(start=0, limit=100, symbolic_keys=True):
f = IndexedBase('f')
return {(f[i] if symbolic_keys else i):fibonacci(i) for i in range(start, limit)}
开发者ID:massimo-nocentini,项目名称:recurrences-unfolding,代码行数:3,代码来源:knowledge.py
示例15: test_find_simple_recurrence_vector
def test_find_simple_recurrence_vector():
assert find_simple_recurrence_vector(
[fibonacci(k) for k in range(12)]) == [1, -1, -1]
开发者ID:A-turing-machine,项目名称:sympy,代码行数:3,代码来源:test_guess.py
示例16: test_issue_10382
def test_issue_10382():
n = Symbol('n', integer=True)
assert limit_seq(fibonacci(n+1)/fibonacci(n), n) == S.GoldenRatio
开发者ID:cklb,项目名称:sympy,代码行数:3,代码来源:test_limitseq.py
示例17: apply
def apply(self, n, evaluation):
'Fibonacci[n_Integer]'
return Integer(sympy.fibonacci(n.to_sympy()))
开发者ID:q423462798,项目名称:Mathics,代码行数:4,代码来源:combinatorial.py
示例18: xrange
"""
Created Nov 15, 2012
Author: Spencer Lyon
Project Euler Problem 25
"""
import sympy as sym
import numpy as np
fibs = [str(sym.fibonacci(n)) for n in xrange(5000)]
lens = np.array([len(fibs[i]) for i in xrange(5000)])
ans = np.where(lens == 1000)[0][0]
print 'The answer is: ', ans
开发者ID:spencerlyon2,项目名称:pryject_Euler,代码行数:16,代码来源:SL_Problem25.py
示例19: test_guess_generating_function_rational
def test_guess_generating_function_rational():
x = Symbol('x')
assert guess_generating_function_rational([fibonacci(k)
for k in range(5, 15)]) == ((3*x + 5)/(-x**2 - x + 1))
开发者ID:A-turing-machine,项目名称:sympy,代码行数:4,代码来源:test_guess.py
示例20: apply
def apply(self, n, evaluation):
'Fibonacci[n_Integer]'
return Integer(sympy.fibonacci(n.get_int_value()))
开发者ID:mathics,项目名称:Mathics,代码行数:4,代码来源:combinatorial.py
注:本文中的sympy.fibonacci函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论