TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Fast Fibonacci Algorithms (2015)

102 点作者 old_sound超过 8 年前

12 条评论

OskarS超过 8 年前
It&#x27;s interesting to note that if you add a modulus to the calculation (i.e. if you calculate F(n) mod M), you can calculate ridiculously large values using the matrix&#x2F;doubling method. You can, for instance, calculate the last 10 digits of the Googolth Fibonacci number instantly (since you only need O(log n) multiplications, it&#x27;s just a few hundred for 10^100 ). Doing it the &quot;naive&quot; dynamic programming way, it would take you far longer than the age of the universe.<p>It&#x27;s a neat illustration of asymptotic running times.
评论 #12873452 未加载
rawnlq超过 8 年前
The fast exponentiation algorithm actually generalizes:<p><a href="http:&#x2F;&#x2F;kukuruku.co&#x2F;hub&#x2F;algorithms&#x2F;automatic-algorithms-optimization-via-fast-matrix-exponentiation.html" rel="nofollow">http:&#x2F;&#x2F;kukuruku.co&#x2F;hub&#x2F;algorithms&#x2F;automatic-algorithms-optim...</a>
评论 #12873873 未加载
adilparvez超过 8 年前
There is a log time way to do this, use Binet&#x27;s formula (<a href="https:&#x2F;&#x2F;en.m.wikipedia.org&#x2F;wiki&#x2F;Fibonacci_number#Closed-form_expression" rel="nofollow">https:&#x2F;&#x2F;en.m.wikipedia.org&#x2F;wiki&#x2F;Fibonacci_number#Closed-form...</a>), but do the arithmetic in the field Q[√5].<p>Edit: Someone&#x27;s implementation: <a href="http:&#x2F;&#x2F;ideone.com&#x2F;NWQe38" rel="nofollow">http:&#x2F;&#x2F;ideone.com&#x2F;NWQe38</a><p>Edit: constant time -&gt; log time
评论 #12872227 未加载
jheriko超过 8 年前
for really big numbers there are the generalisations of karatsuba and toom-cook for higher numbers of splits, and beyond that there are the FFT multiplication methods which i believe are the fastest general case methods for very large numbers.<p>also the laddering scheme used for the &#x27;exponentiation&#x27; can be in different forms, the left-to-right or right-to-left form or even a Montgomery ladder...<p>i seemed to recall there is a &#x27;fastest known&#x27; method for generating fibonacci or lucas numbers... but google is not helping me.<p>pretty sure i had seen it in this book: <a href="https:&#x2F;&#x2F;www.amazon.co.uk&#x2F;Prime-Numbers-Computational-Carl-Pomerance&#x2F;dp&#x2F;0387252827" rel="nofollow">https:&#x2F;&#x2F;www.amazon.co.uk&#x2F;Prime-Numbers-Computational-Carl-Po...</a> i&#x27;ll have to check when i have access to it next. :)
jerven超过 8 年前
The BigInteger implementation in java uses better multiplication algorithms in Java 1.8 then in the version of 1.6 tested [1], switching to toom-cook[2] for even larger numbers. So that in practice Fibonacci in java becomes an benchmark of allocation rate.<p>[1]: <a href="http:&#x2F;&#x2F;grepcode.com&#x2F;file&#x2F;repository.grepcode.com&#x2F;java&#x2F;root&#x2F;jdk&#x2F;openjdk&#x2F;8-b132&#x2F;java&#x2F;math&#x2F;BigInteger.java?av=f#1464" rel="nofollow">http:&#x2F;&#x2F;grepcode.com&#x2F;file&#x2F;repository.grepcode.com&#x2F;java&#x2F;root&#x2F;j...</a><p>[2]:<a href="https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Toom%E2%80%93Cook_multiplication" rel="nofollow">https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Toom%E2%80%93Cook_multiplicati...</a>
brudgers超过 8 年前
For anyone interested in Fibonacci numbers: <i>Fibonacci Quarterly</i> has been published for more than fifty years.<p><a href="http:&#x2F;&#x2F;www.fq.math.ca&#x2F;" rel="nofollow">http:&#x2F;&#x2F;www.fq.math.ca&#x2F;</a>
kitanata超过 8 年前
Isn&#x27;t there a constant time implementation using the Golden Mean? What is the advantage of these algorithms over the constant time one? (i.e. Binet&#x27;s formula)
评论 #12872396 未加载
评论 #12872468 未加载
评论 #12872223 未加载
评论 #12872661 未加载
评论 #12872301 未加载
jmstfv超过 8 年前
So, seems like matrix exponentiation is faster than computing eigenvalues &#x2F; eigenvectors in practice? Take a look: <a href="http:&#x2F;&#x2F;mathoverflow.net&#x2F;questions&#x2F;62904&#x2F;complexity-of-eigenvalue-decomposition" rel="nofollow">http:&#x2F;&#x2F;mathoverflow.net&#x2F;questions&#x2F;62904&#x2F;complexity-of-eigenv...</a>
chaitanyav超过 8 年前
Product of Lucas Numbers Algorithm - &quot;A fast algorithm for computing large Fibonacci numbers&quot; -<a href="https:&#x2F;&#x2F;pdfs.semanticscholar.org&#x2F;9652&#x2F;9e1fedb0a372b825215c7b471a99088f4515.pdf" rel="nofollow">https:&#x2F;&#x2F;pdfs.semanticscholar.org&#x2F;9652&#x2F;9e1fedb0a372b825215c7b...</a>
评论 #12875922 未加载
评论 #12876704 未加载
gandolfinmyhead超过 8 年前
fast doubling for fibonacci is mentioned in sicp. Cheers for sicp
nayuki超过 8 年前
Previous discussion: <a href="https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=9315346" rel="nofollow">https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=9315346</a>
mrcactu5超过 8 年前
the continued fraction of (1+√5)&#x2F;2 is [1;1,1,1,1,1,1,...] it goes on forever.<p>there are more advanced formulas in this article of Curtis McMullen <a href="http:&#x2F;&#x2F;www.math.harvard.edu&#x2F;~ctm&#x2F;papers&#x2F;home&#x2F;text&#x2F;papers&#x2F;cf&#x2F;cf.pdf" rel="nofollow">http:&#x2F;&#x2F;www.math.harvard.edu&#x2F;~ctm&#x2F;papers&#x2F;home&#x2F;text&#x2F;papers&#x2F;cf&#x2F;...</a>