'use strict'; // Run the real small kernel with observable survivors, then compare with gcd. // Full-period cardinality can hide a wrong forbidden phase, so compare sets. const fs = require('node:fs'); const path = require('node:path'); const os = require('node:os'); const crypto = require('node:crypto'); const assert = require('node:assert/strict'); const sha = text => crypto.createHash('sha256').update(text).digest('hex'); const raw = fs.readFileSync(path.join(__dirname, 'census-break747-inputs.json')); assert.equal(sha(raw), 'f673667c7c1d26f9ca7b65a77a2b55872ccd21dcb5ba84564cde5ba154433c7a'); const data = JSON.parse(raw); for (const record of Object.values(data.notes)) assert.equal(sha(record.content), record.sha256); const source = data.notes['research/verify-ladder-big.js'].content; const kernel = source.slice(0, source.indexOf('const expected =')); assert(kernel.includes('function census(upto)')); function makeKernel(segment, wrongPhase = false, missingStrike = false) { let code = kernel.replace('300_000_000', String(segment)); // Retention and return adapters expose the exact survivors. Strike/index // code stays unchanged; smaller segment sizes exercise seams cheaply. assert(code.includes('if (!arr[i]) count++;')); code = code.replace('let count = 0;', 'const kept = []; let count = 0;'); code = code.replace('if (!arr[i]) count++;', 'if (!arr[i]) { count++; kept.push(j); }'); code = code.replace('return count;', 'return {count, kept};'); if (wrongPhase) code = code.replace('[0, p - 2]', '[0, p - 1]'); // Keep the fixed three-class loop valid. Removing a strike changes the // census without introducing an unrelated undefined-class infinite loop. if (missingStrike) code = code.replace('[0, p - 2]', '[0]'); return new Function('console', code + '\nreturn census;')({log() {}, error() {}}); } function primesTo(limit) { return Array.from({length: limit - 1}, (_, i) => i + 2) .filter(p => { for (let d = 2; d * d <= p; d++) if (p % d === 0) return false; return true; }); } function gcd(a, b) { while (b) [a, b] = [b, a % b]; return a; } function literalSlots(p) { const width = primesTo(p).reduce((a, b) => a * b, 1); const slots = []; for (let r = 0; r < width; r++) if (gcd(r, width) === 1 && gcd(r + 2, width) === 1) slots.push(r); return slots; } const small = []; for (const p of [5, 7, 11, 13, 17]) { console.error('small tile', p); const wanted = literalSlots(p); for (const segment of [30, 60, 210, 300, 300000000]) { const got = makeKernel(segment)(p); assert.equal(got.count, wanted.length); assert.deepEqual(got.kept.sort((a, b) => a - b), wanted); small.push({p, segment, survivors: got.count}); } } const wanted7 = literalSlots(7); console.error('negative controls'); const wrongPhase7 = makeKernel(60, true)(7); assert.equal(wrongPhase7.count, wanted7.length); assert.notDeepEqual(wrongPhase7.kept.sort((a, b) => a - b), wanted7); const missingStrike7 = makeKernel(60, false, true)(7); assert.notEqual(missingStrike7.count, wanted7.length); function exactCeil(n, d) { return n >= 0n ? (n + d - 1n) / d : n / d; } const segment = 300000000; let firstLastChecks = 0, allSegmentCount = 0, quotientRemainderChecks = 0; const arithmetic = []; for (const upto of [29, 31, 37]) { console.error('arithmetic seams', upto); const ps = primesTo(upto).filter(p => p >= 7); const width = primesTo(upto).reduce((a, b) => a * b, 1); let local = 0, segments = 0; for (let base = 0; base < width; base += segment) { const end = Math.min(base + segment, width); assert.equal(base % 30, 0); assert.equal(end % 30, 0); segments++; for (const p of ps) for (const kill of [0, p - 2]) for (const res of [11, 17, 29]) { let x0 = res; while (x0 % p !== kill) x0 += 30; const d = 30 * p; let first = x0 + Math.ceil((base - x0) / d) * d; if (first < base) first += d; const exactFirst = BigInt(x0) + exactCeil(BigInt(base - x0), BigInt(d)) * BigInt(d); assert.equal(BigInt(first), exactFirst); assert(first >= base && first < base + d); if (first < end) { const last = first + Math.floor((end - 1 - first) / d) * d; const exactLast = exactFirst + ((BigInt(end - 1) - exactFirst) / BigInt(d)) * BigInt(d); assert.equal(BigInt(last), exactLast); for (const j of [first, last]) { const index = (j - base - (res - (base % 30) + 30) % 30) / 30 | 0; assert.equal(BigInt(index), (BigInt(j) - BigInt(base) - BigInt(res)) / 30n); assert(index >= 0 && index < Math.ceil((end - base) / 30)); assert(index <= 9999999); assert.equal(j % p, kill); assert.equal(j % 30, res); } } local++; } } arithmetic.push({upto, width, segments, first_last_progression_checks: local}); firstLastChecks += local; allSegmentCount += segments; } // Exercise every fractional remainder at the largest supported scale, not // just the specific CRT numerators occurring at fixed segment boundaries. for (const p of primesTo(37).filter(p => p >= 7)) { const d = 30 * p, maximum = Math.floor(7420738134810 / d); for (const q of [1, 1024, 1000000, maximum - 1, maximum]) for (let r = 0; r < d; r++) { const n = q * d + r; assert.equal(BigInt(Math.ceil(n / d)), exactCeil(BigInt(n), BigInt(d))); quotientRemainderChecks++; } } const scratch = fs.mkdtempSync(path.join(os.tmpdir(), 'sah747-')); console.error('static binding'); let binding; try { const filename = path.join(scratch, 'tailfmt.js'); fs.writeFileSync(filename, data.notes['research/qc/tailfmt.js'].content); const T = require(filename), fp = T.fingerprint(source); assert.equal(T.sha(T.headText(source)), fp['code-sha256']); assert.equal(T.bodyMatchesRecorded(source, fp).ok, true); const blocks = [...data.return162.report_md.matchAll(/```\n([\s\S]*?)\n```/g)].map(m => m[1]); const stdout = blocks.find(b => b.startsWith('T29: width=') && b.includes('77.1 min')) + '\n'; assert.equal(sha(stdout), data.return162.hashes['out-big.txt']); assert.equal(sha(stdout.replace('77.1 min', '77.0 min')), data.return162.hashes['out-big.txt (detached run)']); let stderr = ''; const progressCounts = []; for (const p of [29, 31, 37]) { const width = primesTo(p).reduce((a, b) => a * b, 1); let count = 0; for (let base = 0; base < width; base += 400 * segment) { stderr += `T${p}: ${(100 * base / width).toFixed(1)}% (0.0 min)\n`; count++; } progressCounts.push(count); } const marker = '───── stderr ─────'; assert(data.notes['research/qc/embed.js'].content.includes("const STDERR_MARK = '" + marker + "'")); const combined = stdout.replace(/\n*$/, '\n') + marker + '\n' + stderr; const combinedHash = sha(T.normalize(combined)); assert.equal(combinedHash, fp['out-sha256']); assert.notEqual(sha(T.normalize(combined.replace('census=214708725', 'census=214708726'))), combinedHash); assert.notEqual(sha(T.normalize(stdout + '\n' + marker + '\n' + stderr)), combinedHash); binding = {source_head: fp['code-sha256'], normalized_combined: combinedHash, raw_stdout_reconstructed: true, detached_stdout_reconstructed: true, progress_counts: progressCounts, count_mutation_rejected: true, wrong_newline_rejected: true, raw_stderr_hash_reconstructed: false}; } finally { fs.rmSync(scratch, {recursive: true, force: true}); } process.stdout.write(JSON.stringify({job_id: 747, input_sha256: sha(raw), small_actual_kernel_cases: small, wrong_phase_control: {same_count: true, different_survivor_set: true}, missing_strike_control_rejected: true, arithmetic, all_segments: allSegmentCount, first_last_progression_checks: firstLastChecks, quotient_remainder_checks: quotientRemainderChecks, static_binding: binding, scope: 'Accepted counts stand under this focused check; no full big census or missing raw stderr custody claim.'}, null, 2) + '\n');