Path: csiph.com!usenet.pasdenom.info!news.redatomik.org!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!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.009 X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; 'mathematics': 0.05; '*not*': 0.07; 'definitions': 0.07; 'odd': 0.07; 'practice,': 0.07; 'squares': 0.07; 'subject:missing': 0.07; 'counting': 0.09; 'sure,': 0.09; 'cc:addr:python-list': 0.11; '11:19': 0.16; '24,': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'happily': 0.16; 'implies': 0.16; 'progression': 0.16; 'sequence.': 0.16; 'set,': 0.16; 'subject: ?': 0.16; 'wrote:': 0.18; 'all,': 0.19; 'example': 0.22; 'cc:addr:python.org': 0.22; 'mathematical': 0.24; 'question': 0.24; 'cc:2**0': 0.24; "i've": 0.25; 'define': 0.26; 'somewhere': 0.26; 'defined': 0.27; 'header :In-Reply-To:1': 0.27; 'am,': 0.29; 'is?': 0.30; 'sets': 0.30; 'message-id:@mail.gmail.com': 0.30; "d'aprano": 0.31; 'steven': 0.31; 'subject:what': 0.31; 'quite': 0.32; 'trouble': 0.34; 'definition': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'add': 0.35; 'sequence': 0.36; 'next': 0.36; 'starting': 0.37; 'being': 0.38; 'problems': 0.38; 'previous': 0.38; 'anything': 0.39; 'how': 0.40; 'easy': 0.60; 'chain': 0.60; 'most': 0.60; 'numbers': 0.61; 'matter': 0.61; 'more': 0.64; 'series': 0.66; 'mar': 0.68; 'containing': 0.69; 'computers': 0.72; 'square': 0.74; '2015': 0.84; 'answer:': 0.84; 'progression.': 0.84; 'toy': 0.84; 'fibonacci': 0.91; 'inefficient': 0.91; 'states,': 0.91; 'to:none': 0.92 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc :content-type; bh=jnNQC4vfZtiGIG0Zu0b9VjeB+Fo2ZPy1yD+sAogGFlM=; b=kApB7R1G2FK/xC0H7sdiKp3VpB8UoiiYApHei+H9oPZMwQP5v7Z6KTlDW1KowCylgZ oxMgXlFlAe6DydOgkh9mGsi0LsclCUdOvCYlgeK5DVES4VCtnTEg6kkN5m13d5YahRDy pUnJZqa375X1WkFR0/ZYmDRGiPfIcdzVp9p0h9tcoOypdg8o35ljYy5fMetH6fsrhSS+ pD/zIoHbMWULV9RbLgpygo8O9qa1zVm/HiqPzKwtMbZluh+n598mFxhUy0dWqGcul71W GGnpmU5wQ2tNu4itJCnSXtddG2MGWQ7vfrAqdtolR3EDHLfONX+lywGIJOspFexg9O6F ZxWA== MIME-Version: 1.0 X-Received: by 10.50.131.196 with SMTP id oo4mr18650207igb.2.1427158786853; Mon, 23 Mar 2015 17:59:46 -0700 (PDT) In-Reply-To: <5510ad7a$0$12979$c3e8da3$5496439d@news.astraweb.com> References: <5510ad7a$0$12979$c3e8da3$5496439d@news.astraweb.com> Date: Tue, 24 Mar 2015 11:59:46 +1100 Subject: Re: fibonacci series what Iam is missing ? From: Chris Angelico Cc: "python-list@python.org" Content-Type: text/plain; charset=UTF-8 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.19 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: 37 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1427158790 news.xs4all.nl 2937 [2001:888:2000:d::a6]:33743 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:87859 On Tue, Mar 24, 2015 at 11:19 AM, Steven D'Aprano wrote: > It is pretty inefficient, but it is a good toy example of recursion. It's > also a good example of how *not* to write the Fibonacci series in practice, > what is mathematically straightforward is not always computationally > efficient. > > The question is, just how inefficient is is? How many calls to `fib` are > made in calling fib(n)? > > Answer to follow. Exact answer not particularly important (though fun to calculate). Practical answer: A *lot*. :) I've never thought of the mathematical definition as being inherently recursive; but as inherently sequential. Sure, you can define counting numbers based on sets (0 is the cardinality of the empty set, 1 is the cardinality of the set containing the empty set, et-set-era), but most people will define them by counting. The Fibonacci sequence is logically defined by starting somewhere and then adding to the sequence. Yes, you can define it recursively too, but it's just as easy to define it as a progression. (Conversely, the squares *can* be defined as a progression - you add the next odd number to the previous square - but they're more logically defined by their indices. Some work better one way, some the other way.) Of course, mathematics works quite happily with infinity. You can construct infinite sequences and do arithmetic on them, which computers have a lot of trouble with. You can define anything in terms of anything, no matter how long a chain of definitions it takes. And above all, you can reduce problems to previously-solved states, which implies that mathematics has a concept of caching. :) ChrisA