在斐波那契数列中,fib(0) 是 0 还是 1 ?
我正在一个主题中执行一项任务,其中 fib(0) 被定义为 = 1。但这不可能是正确的吗? fib(0) 是 0?
Program with fib(0) = 1; spits out fib(4) = 5
Program with fib(0) = 0; spits out fib(3) = 3
正确的定义是什么?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(10)
Fib(0) = 1 的定义称为组合定义,Fib(0) = 0 是经典定义。两者都在斐波那契季刊中使用,尽管使用组合定义的作者需要添加一句解释。本杰明和奎因在《真正计数的证明》中使用 f_n 表示第 n 个组合斐波那契数,使用 F_n 表示第 n 个经典斐波那契数。组合定义很好,对于计算诸如“一次走一步或两步,有多少种方法可以走上 n 级台阶?”之类的计数问题来说并不奇怪。当 n 为 0 时,只有一种方法,而不是零种方法。
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.
你是对的。 斐波那契数列使用种子值
fib(0) = 0 和
fib(1) = 1
。这是序列其余部分正确的要求(并且不被一个或任何东西抵消)。中,斐波那契数(通常表示为 Fn),形成一个序列,称为斐波那契序列,这样每个数字都是前两个数字的总和,从 0 和 1 开始。
编辑: 我必须承认还有另一个(不太常见, (通常是非正式的)通过用值 1 和 1 播种来定义序列的方法,但这无论如何都不是传统的方法。在我见过的所有正式数学定义中,它当然不是首选,例如整数序列在线百科全书 。
You're correct. The Fibonacci sequence is formally defined with seed values
fib(0) = 0
andfib(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 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.
来自维基百科上的斐波那契数条目:
From the Fibonacci number entry on Wikipedia:
http://en.wikipedia.org/wiki/Fibonacci_number
斐波那契本人以 1 开始数列,不是 0。重要的是要认识到一个人的观点并不是不可改变的事实,并且可能值得考虑的是您不一定比创建该序列的人更了解。我认为以 0 开始序列就可以了,只要你不表现得像那是唯一且唯一绝对正确的做事方式,因为“索引 0”处的数字从根本上来说是不明确的,应该始终明确地传达。
“指数”的问题只适用于我们,而不适用于斐波那契。因此,如果我们想使用他的起始编号并且我们使用基于 0 的索引,我们会将他的起始编号放在索引 0 处,或者如果我们使用基于 1 的索引,我们会将他的起始编号放在索引 1 处而且
由于确实可以向左继续序列,这也使得从 0 开始完全是任意的。为什么不从 -1 开始,然后转到 -1, 1, 0, 1, 1, 2...?
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...?
根据斐波那契数列的定义,您可以生成一个封闭形式来定义第 n 个元素:
对于 n = 0,它显然是 0:
Based on the definition of the Fibonacci sequence, you can generate a closed form for defining the nth element:
For n = 0 it is clearly 0:
你不可能拥有零只兔子,从而产生一对,而“一年内可以产生多少对兔子,从一对开始,从第二个月开始每月繁殖”是斐波那契最初的问题。
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.
他们都是正确的。如果您通过以下方式指定序列 G{n}
递归 G{1} = 3、G{2} = 5、G{n} = G{n - 1} + G{n - 2}
那么大多数人都会同意这是“斐波那契数列”。
唯一的区别是前面的一些术语,但是
主要术语大多与任何有趣的内容无关
关于顺序的问题。斐波那契数列的核心
序列是加法规则,任何使用的序列
该规则是斐波那契数列。这只是必要的
指定 0 是否在序列中,如果您
想询问有关特定指数的具体问题...
其他一切都只是索引上的翻译
几乎是无关紧要的。也就是说,如果问题是
'找到第 N 个值的封闭式解
序列',然后求解G即可解决问题
对于 F,只需对解进行简单的移动。这
对于两个序列来说,问题的难点是相同的。
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.
这就是种子值的定义。
That is the seed value definition.
我的解释是为了那些想要简单理解这个系列的程序员,关于零项,
从
逻辑上相信,负项和零项是斐波那契公式的结果,使用黄金比例
黄金比例(GR)值为1.618034,公式
f(n) = (GR^n - (1-GR)^n))/sqrt(5)
My explanation is for programmers who wants to have simple understanding of this series and about zero term
just start with
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)
斐波那契数列不是从 0 开始,而是从 1 开始。
当我们试图将数学概念表示为计算机程序时,我们会感到困惑。术语“Fib(0)”是保存第一个斐波那契数的数组索引,该数始终为 1。
我们问这个问题是因为当有人输入 0 作为输入时,我们必须从程序中返回一些内容。该输入的本质含义是生成 0 个斐波那契数。因此,您返回一条消息“未生成斐波那契数”
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"