fibonacci series what Iam is missing ?

Chris Angelico rosuav at gmail.com
Mon Mar 23 23:03:05 EDT 2015


On Tue, Mar 24, 2015 at 12:52 PM, Steven D'Aprano
<steve+comp.lang.python at pearwood.info> 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



More information about the Python-list mailing list