52

I'm doing a task in a subject were fib(0) is defined to = 1. But that can't be right? fib(0) is 0?

Program with fib(0) = 1; spits out fib(4) = 5
Program with fib(0) = 0; spits out fib(3) = 3

What is the correct definition?

oɔɯǝɹ
  • 7,219
  • 7
  • 58
  • 69
Algific
  • 1,470
  • 2
  • 18
  • 33

10 Answers10

41

The definition with Fib(0) = 1 is known as the combinatorial definition, and Fib(0) = 0 is the classical definition. Both are used in the Fibonacci Quarterly, though authors that use the combinatorial definition need to add a sentence of explanation. Benjamin and Quinn in Proofs that Really Count use f_n for the nth combinatorial Fibonacci number and F_n for the nth classical Fibonacci number. The combinatorial definition is good, not surprisingly for counting questions like "How many ways are there to walk up a flight of n steps, taking either one or two steps at a time?" When n is 0, there's one way to do it, not zero ways.

ThomasW
  • 16,981
  • 4
  • 79
  • 106
Dale Gerdemann
  • 739
  • 5
  • 7
  • 13
    The `Fibonacci Quarterly`? i must get a subscription! :-) – oɔɯǝɹ Jan 23 '13 at 22:09
  • 1
    https://www.britannica.com/science/Fibonacci-number states that Fib(0) = 1 is the definition as specified by Fibonacci himself. The original sequence begins with 1, but I agree that this definition can be relaxed for convenience with problem solving. – Janac Meena Jun 07 '20 at 17:37
39

You're correct. The Fibonacci sequence is formally defined with seed values fib(0) = 0 and fib(1) = 1. This is a requirement for the rest of the sequence to be right (and not offset by one or anything).

In mathematics, the Fibonacci numbers, commonly denoted F_n, form a sequence, called the Fibonacci sequence, such that each number is the sum of the two preceding ones, starting from 0 and 1.

In mathematics, the Fibonacci numbers, commonly denoted Fn, form a sequence, called the Fibonacci sequence, such that each number is the sum of the two preceding ones, starting from 0 and 1.

Edit: I have to concede that there is another (much less common, and usually informal) way to define the sequence by seeding it with values 1 and 1, but this is not the conventional one by any means. It is certainly not preferred in all the formal mathematical definitions I’ve seen, like The On-Line Encyclopaedia of Integer Sequences.

Noldorin
  • 144,213
  • 56
  • 264
  • 302
  • 4
    In other words, his sequence is offset by one index. – Markus Sep 20 '09 at 14:56
  • @Markus: Yes, offset in a very strange way. It could just be that whoever assigned the task got it wrong, however (more likely?). – Noldorin Sep 20 '09 at 15:00
  • @Sjoerd: I've done enough mathematics to know it's simply non-standard. – Noldorin May 08 '11 at 13:13
  • 1
    The funny thing is that the project euler fibonacci puzzles work on the premise of `fib(0) = 1`. – oɔɯǝɹ Jan 23 '13 at 22:04
  • @KyleDelaney Not only have missed the point, but you've been very rude in doing so. The Fibonacci sequence is defined *by convention* to start with 0 and 1. Just read the Wikipedia page. – Noldorin Jun 18 '19 at 22:29
  • @Noldorin you are also incorrect in citing a user-changeable source like Wikipedia. I would recommend seeing https://www.britannica.com/science/Fibonacci-number – Janac Meena Jun 07 '20 at 17:35
  • “Incorrect”? You really have a way with words, don’t you? It’s an encyclopaedia, whether you like it or not. Just check the sources there. – Noldorin Jun 07 '20 at 19:22
  • Also see my updated answer, where I clarify things and provide a couple new sources. – Noldorin Jun 07 '20 at 19:44
17

From the Fibonacci number entry on Wikipedia:

In mathematics, the Fibonacci numbers are the following sequence of numbers:

alt text

By definition, the first two Fibonacci numbers are 0 and 1, and each remaining number is the sum of the previous two. Some sources omit the initial 0, instead beginning the sequence with two 1s.

In mathematical terms, the sequence Fn of Fibonacci numbers is defined by the recurrence relation

alt text

with seed values

alt text

Community
  • 1
  • 1
Pascal Thivent
  • 562,542
  • 136
  • 1,062
  • 1,124
  • 8
    With a nice little emphasis on: "Some sources omit the initial 0, instead beginning the sequence with two 1s" – NomeN Sep 20 '09 at 15:41
  • In programming, maybe f(0) comes in handy when doing bottom up generation of the fibonacci sequence since you need two to generate the third and so on. – Patrick Mutuku Aug 25 '20 at 21:02
8

http://en.wikipedia.org/wiki/Fibonacci_number

Fibonacci himself started the sequence with 1 and not 0. It's important to recognize that one's opinion is not unalterable fact, and it may be worthwhile to consider that you don't necessarily know better than the guy who created the sequence. I think it's fine to start the sequence with 0 just as long as you don't act like that is the one and only absolutely correct way of doing things, as the number at "index 0" is fundamentally ambiguous and should always be communicated explicitly.

The question of "index" only applies to us and not Fibonacci. So if we want to go with his starting number and we're using 0-based indexes we'd put his starting number at index 0, or if we're using 1-based indexes we'd put his starting number at index 1.

And since it is indeed possible to continue the sequence to the left, that also makes starting with 0 totally arbitrary. Why not start with -1 and go -1, 1, 0, 1, 1, 2...?

Kyle Delaney
  • 11,616
  • 6
  • 39
  • 66
  • Can you provide evidence of Fibonacci using terms like F(1)? – Kyle Delaney Jun 12 '15 at 15:14
  • 3
    My point is that if you can accept 1 as possibly the first number in the sequence, and you use 0 as the first index of a sequence, then it makes sense to say `F(0) = 1`. My point is also that there are multiple ways to do it, so it's better to be clear about which version you're using rather than insisting that there's only one way. – Kyle Delaney Jun 17 '15 at 22:06
  • but did he say the 1 was at index 0 or index 1? – codeshot Nov 12 '17 at 00:35
  • 1
    I doubt he used those terms. – Kyle Delaney Nov 13 '17 at 14:10
  • So I don't understand why his starting number is relevant if we don't know what index he started at - unless he said the preceding number is not decidable and we can be sure he didn't say that because there is exactly one number that continues his sequence to lower indexes and we can compute it easily. – codeshot Nov 19 '17 at 03:16
  • 1
    Here's the thing. The question of "index" only applies to us and not him. So if we want to go with his starting number and we're using 0-based indexes we'd put his starting number at index 0, or if we're using 1-based indexes we'd put his starting number at index 1. – Kyle Delaney Nov 19 '17 at 16:10
  • 1
    Since you brought up that it is indeed possible to continue the sequence to the left, that also makes starting with 0 totally arbitrary. Why not start with -1 and go -1, 1, 0, 1, 1, 2...? – Kyle Delaney Nov 19 '17 at 17:30
  • 1
    An excellent answer Kyle, you should add that to your answer above. – codeshot Nov 23 '17 at 21:18
7

Based on the definition of the Fibonacci sequence, you can generate a closed form for defining the nth element:

F(n) = ( f^n - (1-f)^n ) / sqrt(5),
where f = (1 + sqrt(5)) / 2 [the golden ratio]

For n = 0 it is clearly 0:

F(0) = (1 - 1) / sqrt(5) = 0.
Zed
  • 57,028
  • 9
  • 76
  • 100
  • 4
    That's an explanation, albeit a roundabout one. It's really the seed that defines it in the first place. – Noldorin Sep 20 '09 at 15:01
  • 1
    Anyway, there's certainly no debate on the closed form, so this gives an unquestionable answer to the question =) – Zed Sep 20 '09 at 15:12
  • 2
    @Noldorin Of course you could define the seed differently, but then a lot of nice theorems would become false, like this one. BTW, my favorite is gcd(F_m, F_n) = F_gcd(m,n). – starblue Sep 20 '09 at 16:05
7

You cannot have zero rabbits and thus produce a pair, and "how many pairs of rabbits can be produced in a year starting with one pair and reproducing monthly starting with the second month" was the original question to Fibonacci.

Woody Podgers
  • 79
  • 1
  • 1
  • Does that mean fib(0) is undefined? It would be nice to be clear about this. – codeshot Nov 12 '17 at 00:39
  • Good to know... Thanks Woody! – Bravo Feb 18 '19 at 09:54
  • I think a big part of this is how the question is formed. If you ask "what is the first Fibonacci number fib(1) then you get the value 1. What is the 2nd fib(2) you get the value 1. fib(0) is 0 but it is not the first Fibonacci number. This would be like asking what is the zeroth fibonacci number, which is mostly irrelevant. If you think of it this way then the combinatoric (recursive) algorithm works perfectly. C# example => int fib(int n){ if (n < 2){ return n; } return fib(n -1) + fib(n-2); } – raddevus Apr 18 '19 at 13:11
  • 1
    Downvote: I do agree that you can't "produce" (what an ugly term) rabbits from nothing. But we're talking about math here, which as a philosophical science is based on imagination and definitions, not reality. Some wikipedia article states: "Fibonacci considers the growth of an idealized (biologically unrealistic) rabbit population." Trying to link imaginary fibonacci numbers to natural animal populations was adventurous in the first place. I guess it was just an intellectual game Fibonacci did. Conclusion: Don't try to establish a link today, which was flawed 800 Years ago already. – ChristophK Apr 26 '20 at 08:06
3

They are both correct. If you specify a sequence G{n} by the recursion G{1} = 3, G{2} = 5, G{n} = G{ n - 1} + G{ n - 2} then most people would agree that is "a Fibonacci sequence". The only difference being a few terms at the front, but the leading terms are mostly irrelevant for any interesting questions about the sequence. The heart of a Fibonacci sequence is the addition rule, and any sequence that uses that rule is a Fibonacci sequence. It is only necessary to specify whether 0 is in the sequence if you want to ask specific questions about a particular index... every thing else is just a translation on the index and is pretty much irrelevant. That is, if the problem is 'find a closed form solution for the Nth value in the sequence', then solving it for G will solve the problem for F with just a trivial shift of the solution. The hard part of the problem is the same for both sequences.

William Pursell
  • 204,365
  • 48
  • 270
  • 300
  • 1
    No. This would not be called a Fibonacci sequence, at least not without an additional adjective. Some identities that hold for classical or combinatorial Fibonacci numbers do not hold for the general case. And some starting conditions (2 1 3 4 7.... Lucas Seqkem for example) are independently interesting – Dale Gerdemann Mar 12 '12 at 16:55
0
fib 0 = 0
fib 1 = 1

That is the seed value definition.

phsiao
  • 1,557
  • 10
  • 7
  • 6
    source? Or any other backup for your claim? Just stating that something is so, doesn't make it so. – Sjoerd May 08 '11 at 11:58
-1

My explanation is for programmers who wants to have simple understanding of this series and about zero term

just start with

first term as    f(1) = 1
second term as   f(2) = f(1)+nothing Available = f(1)+0 = 1+0 =1
third term as    f(3) = f(2)+f(1) = 1+1 = 2

it is logical to believe, negative and zero terms are results of the Fibonacci formula using golden ratio

Golden Ratio(GR) value is 1.618034 and formula f(n) = (GR^n - (1-GR)^n))/sqrt(5)

-3

Fibonacci series doesn't start with 0. It starts with 1.
We are getting confused trying to represent a mathematical concept as a computer program. The term "Fib(0)" is the array index that holds the first Fibonacci number which is always 1. We are asking this question because we have to return something from the program when someone enters 0 as input. What that input essentially means is to generate 0 Fibonacci numbers. So you return a message saying "No Fibonacci numbers generated"

cavalier
  • 43
  • 1
  • 9