Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!feeder.news-service.com!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.005 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'numeric': 0.07; 'received:209.85.160.174': 0.09; 'received:mail- gy0-f174.google.com': 0.09; 'scientists': 0.09; 'pm,': 0.10; 'def': 0.12; 'wrote:': 0.14; 'precision,': 0.16; 'subject:Fibonacci': 0.16; 'cc:addr:python-list': 0.17; 'tue,': 0.17; 'header:In-Reply-To:1': 0.21; 'thu,': 0.22; 'cc:2**0': 0.22; 'assume': 0.23; 'cc:no real name:2**0': 0.23; 'charset:iso-8859-7': 0.25; 'point,': 0.25; 'thanks.': 0.27; 'message-id:@mail.gmail.com': 0.28; 'be.': 0.29; 'received:209.85.160': 0.29; "won't": 0.30; 'cc:addr:python.org': 0.30; 'steven': 0.32; 'that,': 0.34; '-0700,': 0.35; "d'aprano": 0.35; 'received:google.com': 0.37; 'something': 0.37; 'received:209.85': 0.37; 'but': 0.38; 'data': 0.38; 'subject:: ': 0.38; 'should': 0.39; "i'd": 0.39; 'received:209': 0.39; 'unlimited': 0.67; 'attention': 0.67 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=70baFEOI+0Hmrd0qSMVtaDAqIMfVYJDCeFmmDtEr6Mw=; b=WxGrHSM2e62/EqOe4IuoM6xZlCkLy0FyXbMKpwrLOmjgxfGOR1/77LIgVDgI2oUMAB fNvTFq7dW9siY2TT8Tmr0TR9GT0Vq7vGJn0iLsZk0YU9CMFs97H64LPhR1Z8PBSmCwgJ QdnOsWsR2n1/MURIQVMCWSJs5ADiAlt/n3LjM= 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=IFrnwabzYNZKb2M7yBwq74MiAsyndPGT7CpOj92dGr7Qv8Zz/hX+u6pdBoN8ww7gUH E1IXeqzCtxcPKMXxAVgZP5hobYIkp+XGM6JRY1Pw/IswA+NwYwYit015Eur1cMOVEd1B C1nQyeYrKkDfuzXBS9WeZv3FR5QG+ad+UkFfM= MIME-Version: 1.0 In-Reply-To: <4dd59e1e$0$29996$c3e8da3$5496439d@news.astraweb.com> References: <108ce447-10fa-4cf7-84ef-440ee18dbfd4@22g2000prx.googlegroups.com> <9d9c163b-14fd-4131-81bb-105c3b97c432@h36g2000pro.googlegroups.com> <4dd59e1e$0$29996$c3e8da3$5496439d@news.astraweb.com> Date: Thu, 19 May 2011 17:03:45 -0700 Subject: Re: Faster Recursive Fibonacci Numbers From: geremy condra To: "Steven D'Aprano" Content-Type: text/plain; charset=ISO-8859-7 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 21 NNTP-Posting-Host: 82.94.164.166 X-Trace: 1305849828 news.xs4all.nl 49046 [::ffff:82.94.164.166]:43212 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:5798 On Thu, May 19, 2011 at 3:47 PM, Steven D'Aprano wrote: > On Tue, 17 May 2011 10:02:21 -0700, geremy condra wrote: > >> or O(1): >> >> =F6 =3D (1 + sqrt(5)) / 2 >> def fib(n): >> =A0 =A0 numerator =3D (=F6**n) - (1 - =F6)**n >> =A0 =A0 denominator =3D sqrt(5) >> =A0 =A0 return round(numerator/denominator) > > I'd just like to point out that, strictly speaking, it's only O(1) if you > assume that exponentiation is O(1). Computer scientists often like to > make this simplifying assumption, and it might even be true for floats, > but for long ints and any numeric data types with unlimited precision, it > won't be. Great point, and something I should have paid attention to. Thanks. Geremy Condra