FibonacciNumbers
The Fibonacci numbers as a lazy indexed collection.
Wikipedia
Fibonacci sequenceWikidataQ23835349OEISA000045Wolfram LanguageFibonacciSageMathsage.combinat.combinat.fibonacci(n)mathlib4Nat.fibFibonacciNumbers, , , an infinite indexed collection.Details
- A lazy indexed collection: , and unranks the term via a memoised linear recurrence -- (
Atis 1-indexed; rank 0 is ). - The collection is indexed from 1, so : . The function is also defined at negative (negafibonacci, ; ), which the collection, starting at , does not reach.
- OEIS A000045, starting exactly at its offset-0 term: .
- Membership goes through Element: is true, is false. repeats, so the sequence is non-decreasing rather than strictly increasing.
Definition
Epsil, as the implementation runs it.
count()
PositiveInfinityunrank(_r)
Fold(
Function([wk_w[2], wk_w[1] + wk_w[2]], wk_w, wk_n),
[0, 1],
Range(0, _r - 1, 1),
)[1]rank(_x)
Fold(
Function(
wk_w if wk_n >= 0 && wk_w[1] > _x else [
wk_w[2],
wk_w[1] + wk_w[2],
wk_n if wk_w[3] < 0 &&
wk_w[1] == _x else wk_w[3],
],
wk_w,
wk_n,
),
[0, 1, -1],
Range(
0,
2 * (Apply(
(fl_r: list<integer>) => fl_r[2],
Fold(Function(
[
(fl_s[1] - fl_s[1] % 2 ^ fl_k) / 2 ^
fl_k,
fl_s[2] + fl_k,
] if fl_s[1] >= 2 ^ fl_k else fl_s,
fl_s,
fl_k,
), [_x + 2, 0], [
8_192,
4_096,
2_048,
1_024,
512,
256,
128,
64,
32,
16,
8,
4,
2,
1,
]),
) + 1) + 12,
1,
),
)[3] if _x >= 0 else -1valid(_x)
Fold(
Function(
wk_w if wk_n >= 0 && wk_w[1] > _x else [
wk_w[2],
wk_w[1] + wk_w[2],
wk_n if wk_w[3] < 0 &&
wk_w[1] == _x else wk_w[3],
],
wk_w,
wk_n,
),
[0, 1, -1],
Range(
0,
2 * (Apply(
(fl_r: list<integer>) => fl_r[2],
Fold(Function(
[
(fl_s[1] - fl_s[1] % 2 ^ fl_k) / 2 ^
fl_k,
fl_s[2] + fl_k,
] if fl_s[1] >= 2 ^ fl_k else fl_s,
fl_s,
fl_k,
), [_x + 2, 0], [
8_192,
4_096,
2_048,
1_024,
512,
256,
128,
64,
32,
16,
8,
4,
2,
1,
]),
) + 1) + 12,
1,
),
)[3] >= 0 if _x >= 0 else FalseEnumeration
Examples
1 more kept as data, checked against the oracles See also: Count, At, Element, LucasNumbers, PellNumbers, TribonacciNumbers