Published
Edited
Oct 25, 2021
Importers
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
function sequence_down(n) {
const result = [];
let nn = next(n);
result.push(nn);
while (nn > n) {
nn = next(nn);
result.push(nn);
}
return result;
}
Insert cell
sequence_down(15n)
Insert cell
Insert cell
function count_down(n) {
let i = 1n,
c = next(n);
while (c > n) {
i++;
c = next(c);
}
return i;
}
Insert cell
count_down(7n)
Insert cell
Insert cell
counts = bigrange(1n, 2n ** magnitude, 2n).map(count_down)
Insert cell
Insert cell
arrange_by_mod = (base) =>
_(counts).chunk(Number(base)).unzip().map(_.uniq).value()
Insert cell
arrange_by_mod(32n)
Insert cell
Insert cell
symbolic = (array) => array.map((it) => (it.length == 1 ? it[0] : `[${it[0]}]`))
Insert cell
symbolic(arrange_by_mod(32n))
Insert cell
Insert cell
magnitude = 21n
Insert cell
function mod_counts(base) {
const arranged = arrange_by_mod(base);
const lengths = _.countBy(arranged, "length");
const repr = symbolic(arranged);
const stable = lengths[1];
return {
base,
stable,
unstable: base - BigInt(stable),
ratio: stable / Number(base),
ratio_u: (Number(base) - stable) / Number(base),
min_unstable_len: _(lengths).omit(1).keys().map(_.toNumber).min(),
max_unstable_len: _(lengths).keys().map(_.toNumber).max(),
lengths,
repr: _.join(repr, " "),
repr_count: _.countBy(repr),
highest_in_stable: _.max(repr),
lowest_in_unstable: _(arranged)
.filter((it) => it.length > 1)
.map(_.min)
.min(),
raw: arranged
};
}
Insert cell
pattern = bigrange(2n, magnitude - 2n)
.map((x) => 2n ** x)
.map(mod_counts)
Insert cell
aq.from(pattern).view()
Insert cell
pattern.map((it) => it.repr)
Insert cell
Insert cell
bigrange(pattern.length - 1).map((i) => {
const a = pattern[i],
b = pattern[i + 1];
return `${a.base} to ${b.base}: ${b.ratio_u / a.ratio_u}`;
})
Insert cell
Insert cell
Insert cell
slice = {
const result = [];
const LIMIT = 200;
const ITERATIONS = 200n;
let exp = 1n;
const width = 2n ** exp;
let base = width;
let starters = bigrange(1n, width + 1n);
for (let i = 0; i < ITERATIONS; i++) {
const lengths = starters.map((parity) =>
bigrange(6n)
.map((x) => x * base + parity)
.map(count_down)
);

const reduced = lengths.map(_.uniq);
const stabilized_count = _(reduced)
.filter((it) => it.length == 1)
.size();
result.push({
base: `2^${exp}`,
exp,
starters,
//lengths,
stabilized_starters: _(reduced)
.map((it, id) => (it.length != 1 ? false : starters[id]))
.filter()
.value(),
stabilized_count,
stabilized_value:
stabilized_count == 0
? null
: Number(_.find(reduced, (it) => it.length == 1)[0])
//repr: symbolic(reduced).join(" ")
});
starters = _(reduced)
.map((it, id) => (it.length == 1 ? false : starters[id]))
.filter()
.value();
starters = [...starters, ...starters.map((it) => it + base)];
starters = _.take(starters, LIMIT);
exp++;
base *= 2n;
}
return result;
}
Insert cell
Insert cell
slice_table = aq.from(slice)

Insert cell
slice_table.view()
Insert cell
slice_table
.derive({
stabilized_value: (d) => op.fill_down(d.stabilized_value)
})
.derive({ x: (d) => op.lead(d.stabilized_value) - d.stabilized_value })
.array("x")
.slice(0, -1)
.join("")
.replace(/203/g, ".") // 3 rows
.replace(/\.\.03/g, ":") // 8 rows
.replace(/\.::/g, "!") // 19 rows
.replace(/!!!!:/g, "#") // 84 rows
Insert cell
Insert cell
Insert cell
function route(start) {
let n = start;
let res = "";
do {
if (n % 2n == 0n) {
n /= 2n;
res += "-";
} else {
n = n * 3n + 1n;
res += "+";
}
} while (n > start);
return res;
}
Insert cell
route(7n)
Insert cell
Insert cell
stable_patterns = slice.map((s) =>
s.stabilized_starters
.map((it) =>
bigrange(30n)
.map((i) => it + 2n ** s.exp * i)
.map(route)
)
)
Insert cell
_.every(stable_patterns, (base) =>
_.every(base, (starter) => _.uniq(starter).length == 1)
)
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
function bigrange(start, end, step) {
if (end !== 0 && end !== 0n && !end) {
end = start;
start = end - end;
}
if (!step) step = end / end; // TODO division by 0
const result = [];
while (start < end) {
result.push(start);
start += step;
}
return result;
}
Insert cell
Support BigInt serialization for Arquero tables
Insert cell
(BigInt.prototype.toJSON = function () {
return this.toString();
})
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more