import { useMemo } from 'react'; import { ready, ink, role } from '../../lib/mrly.js'; import { mount, Page, Row, Pick, Check, Btn, Stats, Stat, Note, Group } from '../../lib/app.jsx'; import { Markup, Sketch } from '../../lib/draw.jsx'; import { useQuery } from '../../lib/query.js'; import { useSeeds, seeded, Picker } from '../../lib/select.jsx'; import { board, bars, line, axis, tag } from '../../lib/chart.js'; const m = await ready(); const TOP = 16; const CORNERS = [0, 1, 2, 3, 4, 5, 6, 7, 8]; const EIGHTHS = [[-4, '-1/2'], [-3, '-3/8'], [-2, '-1/4'], [-1, '-1/8'], [0, '0'], [1, '1/8'], [2, '1/4'], [3, '3/8'], [4, '1/2']]; const RULER = Array.from({ length: 9 }, (_, step) => step / 8); const LEVELS = ['level 0', 'level 1', 'level 2', 'level 3']; function App() { const s = useSeeds(); const [pick, set] = useQuery({ code: seeded(s, 3, 2, '23'), k: 8, mystery: false, mseed: 1, corners: 4, top: 0, shown: false }); const k = Math.min(TOP, Math.max(1, pick.k)); const sealed = pick.mystery && !pick.shown; const code = pick.mystery ? m.random_code(3, 2, pick.mseed) : pick.code.trim(); const built = useMemo(() => { try { return { read: JSON.parse(m.walsh_spectrum(code, TOP)), series: JSON.parse(m.slice_series(code, TOP)), name: m.name_of(code, 3, 2), error: null, }; } catch (error) { return { read: null, series: null, name: '', error }; } }, [code]); const read = built.read; const row = read?.law[k - 1]; const counted = built.series?.[k - 1].fills; const art = useMemo(() => (row ? m.hex_svg(code, row.n, 1, 2, 'cut', Math.max(1, Math.round(320 / row.n))) : ''), [code, row]); const law = (canvas) => { if (!read) return; const b = board(canvas, 260); const rows = read.law, count = rows.length; const at = (i) => (i + 0.5) / count; for (const step of RULER) line(b, [[0, step], [1, step]], ink.line, { width: 1 }); if (!sealed) line(b, [[0, read.background], [1, read.background]], ink.dim, { width: 1, dash: [5, 5] }); line(b, built.series.map((each, i) => [at(i), each.fills / rows[i].triangles]), ink.yellow, { width: 1, dash: [1, 5], dots: 3.5 }); line(b, rows.map((each, i) => [at(i), each.ink]), ink.blue, { width: 1.6, dots: 2 }); axis(b, rows.map((each, i) => [at(i), each.n])); const next = tag(b, 'closed form read off the spectrum', ink.blue); tag(b, 'ink counted on the mesh', ink.yellow, 'left', next + 16); }; const spectrum = (canvas) => { if (!read) return; const b = board(canvas, 200, { bottom: 96 }); const values = read.levels.map((level) => level.sigma); bars(b, values, { peak: Math.max(...values.map(Math.abs), 1e-12), color: (i) => role()[i], inset: 14 }); axis(b, values.map((value, i) => [(i + 0.5) / values.length, LEVELS[i]]), { wall: true }); }; const controls = ( <> set({ mystery: value, shown: false })} /> ); return ( A cube design is eight yes-or-no answers about corner parities. Cut its cube down the main diagonal and the hexagon comes back part inked, part blank, and that one fraction is an exact closed form in the design's Walsh spectrum, level by level: a steady background, a two-step blink, and two corrections that die as 1/n and 1/n^2. No fit, no error term. Turn the mystery on and the code is hidden - read the recipe off the curve, then reveal it.} foot={<>The spectrum is the crate's Walsh-Hadamard transform of the design's eight corners, the four bars are its level sums Sigma_0 to Sigma_3, and the blue curve is the ink law evaluated over the integers in Rust and handed here as an exact numerator over 96n^2. The yellow dots are the fills the crate counts triangle by triangle on the real mesh, over the 6n^2 triangles of the hexagon. The two never part: the law predicts the count itself, not an approximation to it. The same hexagon, its mesh census, its pieces and its holes are the slices page; the research note this grew from is slices, and the theorem, its proof and its checks are the shelf paper the Walsh spectrometer.}>

The slice {`side ${row?.n ?? ''}, ${row?.triangles ?? ''} triangles`}

The spectrum {sealed ? 'sealed' : 'level sums'}

{sealed ? 'sealed' : built.name} {row?.s} {row?.fills} {counted} {row ? (row.fills === counted ? 'exact' : 'broken') : ''} {row?.ink.toFixed(6)} {row ? `${row.numerator}/${row.denominator}` : ''} {!sealed && read && ( {read.levels.map((level) => {`${level.eighths}/8`})} {read.background.toFixed(4)} {read.blink.toFixed(4)} )} {pick.mystery && !sealed && read && ( {`${read.corners}, you said ${pick.corners}`} {pick.corners === read.corners ? 'right' : 'missed'} {`${read.levels[3].eighths}/8, you said ${pick.top}/8`} {pick.top === read.levels[3].eighths ? 'right' : 'missed'} )}
); } mount();