Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #5623
| Path | csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!feeder.news-service.com!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <debatem1@gmail.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.021 |
| X-Spam-Evidence | '*H*': 0.96; '*S*': 0.00; 'event,': 0.07; 'linear': 0.07; 'indicates': 0.09; 'pm,': 0.11; 'somewhere': 0.11; 'def': 0.13; ';-)': 0.14; 'am,': 0.14; 'wrote:': 0.14; 'ratio': 0.16; 'suggested.': 0.16; 'tue,': 0.20; 'writes:': 0.20; 'cc:no real name:2**0': 0.20; 'cc:2**0': 0.20; 'header:In-Reply-To:1': 0.22; 'cc:addr:python-list': 0.22; 'so.': 0.22; 'values': 0.23; 'message-id:@mail.gmail.com': 0.28; 'testing': 0.28; 'cc:addr:python.org': 0.31; '17,': 0.31; 'decimal': 0.31; 'does': 0.31; 'bit': 0.33; 'module': 0.33; 'using': 0.34; 'point': 0.35; 'received:209.85.216.46': 0.35; 'received:mail- qw0-f46.google.com': 0.35; 'quite': 0.36; 'think': 0.36; 'received:209.85': 0.37; 'faster': 0.38; 'received:google.com': 0.38; 'earlier': 0.39; 'larger': 0.39; 'ok,': 0.39; 'though,': 0.39; 'could': 0.39; 'received:209': 0.39; 'add': 0.39; 'would': 0.40; "it's": 0.40; 'header:Received:5': 0.40; 'bottom': 0.60; 'you.': 0.61; '2011': 0.62; 'golden': 0.68; 'tiny': 0.69; 'funny': 0.77; '10:19': 0.84; 'further,': 0.93 |
| DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:in-reply-to:references:date :message-id:subject:from:to:cc:content-type :content-transfer-encoding; bh=PZV70/y6ji/BwiXTG4XG1nS64K/YZDZWWUR7XwjiBrk=; b=LQ1E/AhEruBjp1KSc2ea6hg8Aqtc8tuDQdZ9arkLiPrD106GVnnVuf3hOojFlvqK5h 4W59Gs0ajhD7xB2jrv9ZI/3IOleug3GkKlx0jkTJRGMOMFBb9Lhnt80o1Mw6x8YzsMbt 3yxTTIbbAUoZWFJQ4ZTiKr8WJTTwJiTmYNV7Q= |
| DomainKey-Signature | a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:content-transfer-encoding; b=gETE+JDCMWHgut8Vx5KqwUGm9+bJaMD6VosgjfTcFRnwY8AMMxbqRanVoRefSm95uC DJL1pOPk1e9XjKmb9F9j74O/wJ58er8bCGyS4bi/o/Jl8o0DrSd/13RpCrF0FCcNY36N vcNYRGIENuCf6gWzUV2mq/WSm/GrGJ4a9Vcks= |
| MIME-Version | 1.0 |
| In-Reply-To | <80ba3b5e-34c1-420a-aade-9c1996d0239e@u26g2000vby.googlegroups.com> |
| References | <108ce447-10fa-4cf7-84ef-440ee18dbfd4@22g2000prx.googlegroups.com> <9d9c163b-14fd-4131-81bb-105c3b97c432@h36g2000pro.googlegroups.com> <mailman.1680.1305651743.9059.python-list@python.org> <qotmxilp7na.fsf@ruuvi.it.helsinki.fi> <mailman.1695.1305658596.9059.python-list@python.org> <80ba3b5e-34c1-420a-aade-9c1996d0239e@u26g2000vby.googlegroups.com> |
| Date | Tue, 17 May 2011 14:59:06 -0700 |
| Subject | Re: Faster Recursive Fibonacci Numbers |
| From | geremy condra <debatem1@gmail.com> |
| To | Wolfram Hinderer <wolfram.hinderer@googlemail.com> |
| Content-Type | text/plain; charset=ISO-8859-1 |
| Content-Transfer-Encoding | quoted-printable |
| Cc | python-list@python.org |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.12 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.1722.1305669549.9059.python-list@python.org> (permalink) |
| Lines | 39 |
| NNTP-Posting-Host | 82.94.164.166 |
| X-Trace | 1305669555 news.xs4all.nl 49179 [::ffff:82.94.164.166]:49623 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | x330-a1.tempe.blueboxinc.net comp.lang.python:5623 |
Show key headers only | View raw
On Tue, May 17, 2011 at 2:04 PM, Wolfram Hinderer <wolfram.hinderer@googlemail.com> wrote: > On 17 Mai, 20:56, geremy condra <debat...@gmail.com> wrote: >> On Tue, May 17, 2011 at 10:19 AM, Jussi Piitulainen >> >> <jpiit...@ling.helsinki.fi> wrote: >> > geremy condra writes: >> >> >> or O(1): >> >> >> ö = (1 + sqrt(5)) / 2 >> >> def fib(n): >> >> numerator = (ö**n) - (1 - ö)**n >> >> denominator = sqrt(5) >> >> return round(numerator/denominator) >> >> >> Testing indicates that it's faster somewhere around 7 or so. >> >> > And increasingly inaccurate from 71 on. >> >> Yup. That's floating point for you. For larger values you could just >> add a linear search at the bottom using the 5f**2 +/- 4 rule, which >> would still be quite fast out to about 10 times that. The decimal >> module gets you a tiny bit further, and after that it's time to just >> use Dijkstra's, like rusi suggested. In any event, I still think this >> formulation is the most fun ;). > > I think you can write it even more funny > > def fib(n): > return round(((.5 + .5 * 5 ** .5) ** n - (.5 - .5 * 5 ** .5) ** > n) * 5 ** -.5) > > ;-) Ok, that's amusing. It does hide the interaction with the golden ratio though, which is what I find so fascinating about the earlier one. Geremy Condra
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Faster Recursive Fibonacci Numbers RJB <rbotting@csusb.edu> - 2011-05-17 08:50 -0700
Re: Faster Recursive Fibonacci Numbers Ian Kelly <ian.g.kelly@gmail.com> - 2011-05-17 10:23 -0600
Re: Faster Recursive Fibonacci Numbers rusi <rustompmody@gmail.com> - 2011-05-17 09:25 -0700
Re: Faster Recursive Fibonacci Numbers rusi <rustompmody@gmail.com> - 2011-05-17 09:36 -0700
Re: Faster Recursive Fibonacci Numbers geremy condra <debatem1@gmail.com> - 2011-05-17 10:02 -0700
Re: Faster Recursive Fibonacci Numbers Jussi Piitulainen <jpiitula@ling.helsinki.fi> - 2011-05-17 20:19 +0300
Re: Faster Recursive Fibonacci Numbers geremy condra <debatem1@gmail.com> - 2011-05-17 11:56 -0700
Re: Faster Recursive Fibonacci Numbers Wolfram Hinderer <wolfram.hinderer@googlemail.com> - 2011-05-17 14:04 -0700
Re: Faster Recursive Fibonacci Numbers geremy condra <debatem1@gmail.com> - 2011-05-17 14:59 -0700
Re: Faster Recursive Fibonacci Numbers rusi <rustompmody@gmail.com> - 2011-05-17 21:43 -0700
Re: Faster Recursive Fibonacci Numbers Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-05-19 22:47 +0000
Re: Faster Recursive Fibonacci Numbers Chris Angelico <rosuav@gmail.com> - 2011-05-20 09:37 +1000
Re: Faster Recursive Fibonacci Numbers Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-05-20 05:58 +0000
Re: Faster Recursive Fibonacci Numbers Chris Angelico <rosuav@gmail.com> - 2011-05-20 16:06 +1000
Re: Faster Recursive Fibonacci Numbers harrismh777 <harrismh777@charter.net> - 2011-05-20 01:26 -0500
Re: Faster Recursive Fibonacci Numbers Chris Angelico <rosuav@gmail.com> - 2011-05-20 16:54 +1000
Re: Faster Recursive Fibonacci Numbers Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-05-20 17:07 +0000
Re: Faster Recursive Fibonacci Numbers geremy condra <debatem1@gmail.com> - 2011-05-20 11:43 -0700
Re: Faster Recursive Fibonacci Numbers Chris Angelico <rosuav@gmail.com> - 2011-05-21 10:44 +1000
Re: Faster Recursive Fibonacci Numbers Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2011-05-21 20:49 +1200
Re: Faster Recursive Fibonacci Numbers Ian Kelly <ian.g.kelly@gmail.com> - 2011-05-20 01:26 -0600
Re: Faster Recursive Fibonacci Numbers Ian Kelly <ian.g.kelly@gmail.com> - 2011-05-20 01:32 -0600
Re: Faster Recursive Fibonacci Numbers SigmundV <sigmundv@gmail.com> - 2011-05-20 03:53 -0700
Re: Faster Recursive Fibonacci Numbers geremy condra <debatem1@gmail.com> - 2011-05-19 17:03 -0700
Re: Faster Recursive Fibonacci Numbers Raymond Hettinger <python@rcn.com> - 2011-05-24 16:44 -0700
csiph-web