SternDiatomicSequence
Stern's diatomic sequence (the fusc function) as a lazy indexed collection.
OEIS
A002487SternDiatomicSequence, , , , an infinite indexed collection.Details
- A lazy indexed collection: , and ; unranking is via the bit-doubling pair , not a growing cache.
- OEIS A002487, starting exactly at its offset-0 term: .
- Not monotone, so membership is not 'is this term some bound': every non-negative integer is a term ( appears exactly once, at ; every positive integer appears infinitely often). and are both true; only a negative or non-integer value is false.
Definition
Epsil, as the implementation runs it.
count()
PositiveInfinityunrank(_r)
Fold(Function(
[(st_p[1] - st_p[1] % 2) / 2, st_p[2] + st_p[3], st_p[3]] if st_p[1] %
2 ==
0 else [
(st_p[1] -
st_p[1] % 2) /
2,
st_p[2],
st_p[2] + st_p[3],
],
st_p,
st_b,
), [_r, 1, 0], Range(1, Floor(Log(_r + 1, 2)) + 2, 1))[3]rank(_x)
(-1 if _x < 0 else _x) if _x < 2 else Fold(
Function(Apply(
(st_e: list<integer>) => 2 ^ st_e[4] +
st_e[3] if GCD(_x, st_w) ==
1 &&
2 ^ st_e[4] +
st_e[3] <
st_best else st_best,
Fold(
Function(st_s if st_s[1] == st_s[2] else [
st_s[1] -
(st_s[1] - 1 -
(st_s[1] - 1) %
st_s[2]) /
st_s[2] *
st_s[2],
st_s[2],
st_s[3] +
(2 ^
((st_s[1] - 1 -
(st_s[1] - 1) %
st_s[2]) /
st_s[2]) -
1) *
2 ^ st_s[4],
st_s[4] +
(st_s[1] - 1 -
(st_s[1] - 1) %
st_s[2]) /
st_s[2],
] if st_s[1] > st_s[2] else [
st_s[1],
st_s[2] -
(st_s[2] - 1 -
(st_s[2] - 1) %
st_s[1]) /
st_s[1] *
st_s[1],
st_s[3],
st_s[4] +
(st_s[2] - 1 -
(st_s[2] - 1) %
st_s[1]) /
st_s[1],
], st_s, st_k),
[
_x,
st_w,
0,
0,
],
Range(
1,
2 *
Floor(Log(_x, 2)) + 4,
1,
),
),
), st_best, st_w),
PositiveInfinity,
Range(1, _x - 1, 1),
)valid(_x)
_x >= 0Enumeration
Examples
1 more kept as data, checked against the oraclesAbout
| Examples | 1 |
|---|---|
| Crosswalk | OEIS |
See also: Count, At, Element, ThueMorseNumbers