import { useEffect, useMemo, useRef, useState } from 'react'; import { ready, ink, fit } from '../../lib/mrly.js'; import { useQuery } from '../../lib/query.js'; import { mount, Page, Row, Btn, Stats, Stat, Note } from '../../lib/app.jsx'; import { Sketch } from '../../lib/draw.jsx'; import { useSeeds, roll } from '../../lib/select.jsx'; import { board, bars, axis, tag } from '../../lib/chart.js'; import { Terms, mix } from '../../lib/series.jsx'; const m = await ready(); const COLS = 40; const LINES = 25; const PAGE = 25; const BUDGET = 14; const WIN = JSON.parse(m.census_window()); const CEILING = Number(WIN.ceiling); const START = JSON.parse(m.census_walk(WIN.tiers[0].keys)); function shade(count, peak) { if (count === 0) return ink.orange; if (count === 1) return ink.dim; return mix(ink.blue, ink.yellow, Math.log(count) / peak); } function census() { return { counts: m.census_counts(), report: JSON.parse(m.census_report()) }; } function frame() { return new Promise((resolve) => requestAnimationFrame(resolve)); } function App() { const s = useSeeds(); const [pick, set] = useQuery({ value: 16 }); const value = Math.min(CEILING, Math.max(1, pick.value || 16)); const [typing, setTyping] = useState(String(value)); const [page, setPage] = useState(0); const [walking, setWalking] = useState(true); const [state, setState] = useState(START); const [look, setLook] = useState(census); const [error, setError] = useState(null); const live = useRef(state); live.current = state; const choose = (v, typed = false) => { const next = Math.min(CEILING, Math.max(1, v || 1)); setPage(0); if (!typed || next !== v) setTyping(String(next)); set({ value: next }); }; const pass = async () => { setWalking(true); setError(null); let span = 4; let ticks = 0; let broken = false; let now = live.current; do { await frame(); const opened = performance.now(); while (performance.now() - opened < BUDGET) { const clock = performance.now(); try { now = JSON.parse(m.census_walk(span)); } catch (error) { setError(error); broken = true; break; } const spent = Math.max(performance.now() - clock, 0.5); span = Math.max(1, Math.min(span * 2, 4000, Math.round((span * BUDGET) / spent))); if (now.done >= now.total || spent >= BUDGET) break; } live.current = now; setState(now); if (++ticks % 8 === 0) setLook(census()); } while (!broken && now.done < now.total); setWalking(false); setLook(census()); }; useEffect(() => { pass(); }, []); const found = useMemo(() => JSON.parse(m.census_writers(value, page, PAGE)), [value, page, look]); const champs = useMemo(() => JSON.parse(m.census_champions(20)), [look]); const misses = useMemo(() => JSON.parse(m.census_misses(30)), [look]); const field = (canvas) => { const side = canvas.clientWidth / COLS; const [ctx, w, h] = fit(canvas, Math.round(side * LINES)); ctx.clearRect(0, 0, w, h); const peak = Math.log(Math.max(2, ...look.counts)); for (let i = 0; i < look.counts.length; i++) { ctx.fillStyle = shade(look.counts[i], peak); ctx.fillRect((i % COLS) * side, Math.floor(i / COLS) * side, Math.max(1, side - 1), Math.max(1, side - 1)); } const at = value - 1; ctx.strokeStyle = ink.fg; ctx.lineWidth = 2; ctx.strokeRect((at % COLS) * side - 1.5, Math.floor(at / COLS) * side - 1.5, side + 2, side + 2); }; const split = (canvas) => { const b = board(canvas, 62, { top: 20, bottom: 24 }); const parts = [ ['missed', look.report.never, ink.orange], ['written once', look.report.once, ink.dim], ['written by many', look.report.multiple, ink.blue], ]; let at = 0; let label = b.x(0); for (const [name, count, color] of parts) { b.ctx.fillStyle = color; b.ctx.fillRect(b.x(at / CEILING), b.roof, Math.max(1, (b.wide * count) / CEILING - 1), b.floor - b.roof); label = tag(b, `${name} ${count}`, color, 'left', label, b.h - 8) + 14; at += count; } tag(b, `1 to ${CEILING} at ${state.depth} rendered terms`, ink.dim); }; const champions = (canvas) => { const b = board(canvas, 210); bars(b, champs.map((row) => row.rows), { color: (i) => (champs[i].value === value ? ink.yellow : ink.blue) }); axis(b, champs.map((row, i) => [(i + 0.5) / champs.length, row.value])); tag(b, 'rows writing the integer, the twenty heaviest', ink.dim); tag(b, `leader ${champs[0].value} at ${champs[0].rows} rows`, ink.fg, 'right'); }; const onField = (event) => { const box = event.currentTarget.getBoundingClientRect(); const side = box.width / COLS; const column = Math.floor((event.clientX - box.left) / side); const row = Math.floor((event.clientY - box.top) / side); if (column >= 0 && column < COLS && row >= 0 && row < LINES) choose(row * COLS + column + 1); }; const onChampions = (event) => { const box = event.currentTarget.getBoundingClientRect(); const at = Math.floor(((event.clientX - box.left - 14) / (box.width - 28)) * champs.length); if (champs[at]) choose(champs[at].value); }; const random = () => { const [at] = roll(s.next(), [[1, CEILING]]); choose(at); }; const miss = () => { const all = JSON.parse(m.census_misses(CEILING)); if (!all.length) return; const [at] = roll(s.next(), [[0, all.length - 1]]); choose(all[at]); }; const champion = () => { const rows = JSON.parse(m.census_champions(20)); const [at] = roll(s.next(), [[0, rows.length - 1]]); choose(rows[at].value); }; const tierOf = (name) => found.tiers.find((tier) => tier.tier === name)?.rows ?? ''; const controls = ( Randomize A miss A champion ); return ( The census is only as good as its window, so the window is pinned and printed rather than assumed. A row is one design, one measure and one axis, taken over the four cost tiers of the ledger. A row's rendered window is its first min(48, B) terms, B the leading terms whose footprint fits 100000 cells: one cell for a closed measure, number^dimension + level * span for a convolved one, number^(dimension * level) for a grid. A row whose rendered terms are strictly increasing stops at the first term above the ceiling, which on this page is 1000. A row writes n when n is a term inside that window and n is in range, and multiplicity counts rows and not places, so a row writing the same integer twice counts once. Terms at or below zero - the Euler characteristics, the voids of a solid - are counted apart and never folded in. The page opens at the ledger's own eight-term heads and deepens on request, because more than half of the written set arrives past the head; the last pass is the pinned 48-term window, and the depth table above is the honest measure of how much the window itself decides. That a missed integer is written by no row at any depth is a conjecture and not a result: the rows the cap still cuts have deeper terms nobody has rendered, and the counter says how many rows those are. The same census runs to a ceiling of 100000 in the research tree, where the miss density climbs decade by decade; whatever the ceiling, a fixed registry renders at most 48 terms a row, so the written set is finite and far enough out the census is almost all miss. Every number here is computed in Rust and walked live through wasm; the page only draws. The census behind it, misses and all, is the integers note.} controls={controls}>

The pinned window {walking ? `walking ${state.done} of ${state.total} rows at ${state.depth} terms` : state.complete ? `complete at the pinned ${WIN.cap}-term window` : `${state.pending} rows are cut by the ${state.depth}-term cap`}

registry {WIN.registry} rows read {`${state.rows} of ${WIN.registry} rows`} rendered terms {state.complete ? `${state.depth}, the pinned cap` : state.depth} ceiling {CEILING} cells a term {WIN.cells}

The field {`1 to ${CEILING}, one cell an integer, click to read one`}

missed {look.report.never} written once {look.report.once} written by many {look.report.multiple} share written {look.report.share.toFixed(4)}

The verdict {`${state.rows} rows read at ${state.depth} rendered terms`}

{found.rows ? `${value} is written by ${found.rows === 1 ? 'exactly one row' : `${found.rows} rows`}` : `${value} is missed: no row of the ${WIN.registry} writes it inside the window`}

{found.rows} {tierOf('closed')} {tierOf('convolved')} {tierOf('side')} {tierOf('level')} {found.rows ? `${page + 1} of ${Math.ceil(found.rows / PAGE)}` : '0'} {' '}
{found.shown.length ? found.shown.map((row, i) => ( )) : }
rowmeasureclosed formwrites it atfirst terms
{row.name} {row.measure} · {row.axis} {row.closed || 'none known'} term {row.index + 1}, {row.axis === 'level' ? `level ${row.term}` : `side ${row.side}`}
no row of the registry writes it

The champions the integers the most rows write

The first misses click one to read it

n === value)} onPick={(n) => choose(Number(n))} empty="no integer of the window is missed" tight />

The depth of the window {state.complete ? 'the last row is the pinned window' : `${state.pending} rows are still cut by the cap`}

{look.report.depths.length ? look.report.depths.map((row) => ( )) : }
rendered termswrittenmissedoncefirst missrows still cut
{row.depth} {row.written} {row.never} {row.once} {row.first_miss} {row.deepenable}
{`the ${WIN.depths[0]}-term pass is still walking`}

The miss density by decade

{look.report.bands.map((band) => ( ))}
decadewidthmissedmiss density
{band.first} to {band.last} {band.width} {band.missed} {band.density.toFixed(6)}

The tiers

{look.report.tiers.map((tier) => ( ))}
tierrowswrittenwritten by this tier alone
{tier.tier} {tier.rows} {tier.written} {tier.alone}
); } mount();