Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed2.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.023 X-Spam-Evidence: '*H*': 0.95; '*S*': 0.00; 'mathematics': 0.05; 'true,': 0.05; 'subject:missing': 0.07; 'counting': 0.09; 'sure,': 0.09; 'cc:addr:python-list': 0.11; 'posted': 0.15; '11:59': 0.16; '24,': 0.16; 'definition.': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'sequence,': 0.16; 'sequence.': 0.16; 'set,': 0.16; 'trivially': 0.16; 'subject: ?': 0.16; 'wrote:': 0.18; 'basically': 0.19; 'cc:addr:python.org': 0.22; 'mathematical': 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; 'function': 0.29; 'chris': 0.29; 'am,': 0.29; "doesn't": 0.30; 'converting': 0.30; 'sets': 0.30; 'message- id:@mail.gmail.com': 0.30; "i'm": 0.30; 'about.': 0.31; 'constant': 0.31; "d'aprano": 0.31; 'steven': 0.31; 'subject:what': 0.31; '"the': 0.34; 'problem': 0.35; 'except': 0.35; 'convert': 0.35; 'definition': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'sequence': 0.36; 'level': 0.37; 'starting': 0.37; 'being': 0.38; 'handle': 0.38; 'pm,': 0.38; 'previous': 0.38; 'functional': 0.39; 'easy': 0.60; 'expression': 0.60; 'most': 0.60; 'numbers': 0.61; 'simple': 0.61; "you're": 0.61; 'term': 0.63; 'talking': 0.65; 'mar': 0.68; 'containing': 0.69; '2015': 0.84; 'inherent': 0.84; 'progression.': 0.84; 'recursion,': 0.84; 'fibonacci': 0.91; 'to:none': 0.92; 'from.': 0.93 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=wUze8j/cKca1FnmNL4k5+1A9lImiVjb8TtxwdhcIn/Y=; b=rRTdsecVrtp2BDNhWgbtcuvadd+lPC4xKZK5HdZY+I02N3KG9fo+Si9ApFRQer8XYj eDi86HdY78RTI04mtNAO1wyDlZbtfNFnWJcUkFl/v1/bdigeh9al1XEzmliGdIhcfZkr s3jXiKnESGB9j1rxMSXdx6nkZ+ijPDea/3OaX6DOx03rAWZ3X2BadUSD0UdkNFU0yVgT i/RqGEYwMbXlRQg8sUYV+kZAzcrC2ACTvlakjxXauqW9biLTCBZbi3q2aN7UBNcKORoj BFAhooiWw4P3Rtm6GcZhLxl0JXryn8n84ILUEwJUfHB3R9aN5NF7JV6LngmsDKl0IRdR lruQ== MIME-Version: 1.0 X-Received: by 10.107.16.31 with SMTP id y31mr3074644ioi.53.1427166185557; Mon, 23 Mar 2015 20:03:05 -0700 (PDT) In-Reply-To: <5510c34c$0$12999$c3e8da3$5496439d@news.astraweb.com> References: <5510ad7a$0$12979$c3e8da3$5496439d@news.astraweb.com> <5510c34c$0$12999$c3e8da3$5496439d@news.astraweb.com> Date: Tue, 24 Mar 2015 14:03:05 +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: 35 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1427166194 news.xs4all.nl 2947 [2001:888:2000:d::a6]:40931 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:87863 On Tue, Mar 24, 2015 at 12:52 PM, Steven D'Aprano wrote: > On Tue, 24 Mar 2015 11:59 am, Chris Angelico wrote: > > >> 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. > > But what are you adding? You're not adding a constant or simple expression > each time, but a previous term of the series. That's recursion. That's true, if you are defining "the Nth Fibonacci number". But if you're defining "the Fibonacci sequence", then it's self-referential, but not double-recursive as it is in the naive functional definition. And that's where the problem comes from; it's pretty easy to handle a single level of recursion by converting it to tail recursion, then trivially converting that to iteration; double recursion is harder to handle. The cache-append solution that Terry posted is basically "evaluate the Fibonacci sequence up as far as we need it, then return that number", which is what I'm talking about. Mathematics doesn't like defining sequences, except by defining functions, and so it has to convert the concept of "defining the Fibonacci sequence" into "defining a function F(N) which returns the Nth Fibonacci number", and that's where the double recursion comes from. It's not an inherent part of the sequence, which is, uhh, sequential. ChrisA