P vs NP: the fewest gates
Easy to check, easy to find? Exact small circuits, proofs that none smaller exists, and the 2026 claims around P vs NP, rerun and read

| 1 | // docs/find-vs-check.svg: finding against checking, on Clay's own example (house a quarter of n students, no two on the |
| 2 | // list of pairs who may not share). For n = 20 to 140, fifteen random lists each (a planted dorm, each other pair listed |
| 3 | // with probability 20/n): the steps a plain search takes to find a dorm, median and middle half, and the pairs a checker |
| 4 | // reads to check one, k(k-1)/2. Log scale, so steady multiplication is a straight line. Its only words are numbers, so |
| 5 | // the README captions it. The search is the one the site's playground runs (the column’s first playground, pnp-dorm, replaced by pnp-circuit on 11-28), copied. |
| 6 | // node scripts/find-vs-check.mjs > docs/find-vs-check.svg (about 2.5 minutes) |
| 7 | // Clay's dorm problem (an independent set): n students, a list of pairs who may not share, house k with no such pair. |
| 8 | const Dorm = (function () { |
| 9 | function rng(seed) { var s = seed >>> 0; return function () { s = (s + 0x6d2b79f5) >>> 0; var t = s; t = Math.imul(t ^ (t >>> 15), t | 1); t ^= t + Math.imul(t ^ (t >>> 7), t | 61); return ((t ^ (t >>> 14)) >>> 0) / 4294967296 } } |
| 10 | // a hidden dorm of k students with no pair inside; every other pair is on the list with probability p |
| 11 | function planted(n, k, p, seed) { |
| 12 | var r = rng(seed), perm = [], i, j |
| 13 | for (i = 0; i < n; i++) perm.push(i) |
| 14 | for (i = n - 1; i > 0; i--) { j = Math.floor(r() * (i + 1)); var t = perm[i]; perm[i] = perm[j]; perm[j] = t } |
| 15 | var hid = new Uint8Array(n), edges = []; perm.slice(0, k).forEach(function (v) { hid[v] = 1 }) |
| 16 | for (var u = 0; u < n; u++) for (var v = u + 1; v < n; v++) if (!(hid[u] && hid[v]) && r() < p) edges.push([u, v]) |
| 17 | return { n: n, k: k, edges: edges } |
| 18 | } |
| 19 | // checking a proposed dorm: each pair of the chosen looked up in the list once |
| 20 | function check(inst, chosen) { |
| 21 | var bad = new Set(inst.edges.map(function (e) { return e[0] * inst.n + e[1] })), out = [], reads = 0 |
| 22 | for (var i = 0; i < chosen.length; i++) for (var j = i + 1; j < chosen.length; j++) { reads++; var u = Math.min(chosen[i], chosen[j]), v = Math.max(chosen[i], chosen[j]); if (bad.has(u * inst.n + v)) out.push([u, v]) } |
| 23 | return { ok: chosen.length >= inst.k && out.length === 0, conflicts: out, reads: reads } |
| 24 | } |
| 25 | // the plain search, as a generator a page can run a slice at a time: take the candidate with the most conflicts |
| 26 | // (then drop its conflicts) or leave it; give up a branch when the chosen and the candidates cannot reach k |
| 27 | function search(inst) { |
| 28 | var n = inst.n, k = inst.k, W = Math.ceil(n / 32), nb = [], i |
| 29 | for (i = 0; i < n; i++) nb.push(new Uint32Array(W)) |
| 30 | inst.edges.forEach(function (e) { nb[e[0]][e[1] >> 5] |= 1 << (e[1] & 31); nb[e[1]][e[0] >> 5] |= 1 << (e[0] & 31) }) |
| 31 | function pop(x) { x -= (x >>> 1) & 0x55555555; x = (x & 0x33333333) + ((x >>> 2) & 0x33333333); return (((x + (x >>> 4)) & 0x0f0f0f0f) * 0x01010101) >>> 24 } |
| 32 | function count(c) { var s = 0; for (var w = 0; w < W; w++) s += pop(c[w]); return s } |
| 33 | var res = { steps: 0, found: null }, chosen = [] |
| 34 | function* go(c, size) { |
| 35 | res.steps++ |
| 36 | if ((res.steps & 4095) === 0) yield res.steps |
| 37 | if (chosen.length >= k) { res.found = chosen.slice(); return } |
| 38 | if (chosen.length + size < k) return |
| 39 | var best = -1, bd = -1, w, q |
| 40 | for (w = 0; w < W; w++) { var x = c[w]; while (x) { var b = x & -x, v = (w << 5) + 31 - Math.clz32(b); x ^= b |
| 41 | var d = 0; for (q = 0; q < W; q++) d += pop(c[q] & nb[v][q]); if (d > bd) { bd = d; best = v } } } |
| 42 | if (bd === 0) { // no conflicts left among the candidates: take them all |
| 43 | var all = []; for (w = 0; w < W; w++) { var y = c[w]; while (y) { var bb = y & -y; y ^= bb; all.push((w << 5) + 31 - Math.clz32(bb)) } } |
| 44 | if (chosen.length + all.length >= k) res.found = chosen.concat(all).slice(0, k); return } |
| 45 | var take = new Uint32Array(W), leave = Uint32Array.from(c) |
| 46 | for (w = 0; w < W; w++) take[w] = c[w] & ~nb[best][w] |
| 47 | take[best >> 5] &= ~(1 << (best & 31)); leave[best >> 5] &= ~(1 << (best & 31)) |
| 48 | chosen.push(best); yield* go(take, count(take)); chosen.pop(); if (res.found) return |
| 49 | yield* go(leave, size - 1) |
| 50 | } |
| 51 | var all0 = new Uint32Array(W); for (i = 0; i < n; i++) all0[i >> 5] |= 1 << (i & 31) |
| 52 | var gen = go(all0, n) |
| 53 | return { res: res, step: function (until) { while (until()) { if (gen.next().done) return true } return false } } |
| 54 | } |
| 55 | function solve(inst) { var s = search(inst); s.step(function () { return true }); return s.res } |
| 56 | // the race's instances: k = n/4 as in Clay's example, conflicts with probability 20/n |
| 57 | function race(n, seed) { return planted(n, n / 4, Math.min(0.9, 20 / n), 1000 * n + seed) } |
| 58 | return { rng: rng, planted: planted, check: check, search: search, solve: solve, race: race } |
| 59 | })() |
| 60 | |
| 61 | const NS = [20, 28, 36, 44, 52, 60, 68, 76, 84, 92, 100, 108, 116, 124, 132, 140], RUNS = 15 |
| 62 | const rows = NS.map(n => { |
| 63 | const st = [] |
| 64 | for (let s = 1; s <= RUNS; s++) { const inst = Dorm.race(n, 100 + s), r = Dorm.solve(inst); if (!r.found || !Dorm.check(inst, r.found).ok) throw Error(`n=${n}`); st.push(r.steps) } |
| 65 | st.sort((a, b) => a - b) |
| 66 | const q = f => st[Math.round(f * (RUNS - 1))], k = n / 4 |
| 67 | console.error(`n ${n}: median ${q(0.5)} steps (middle half ${q(0.25)}..${q(0.75)}); check ${k * (k - 1) / 2} pairs`) |
| 68 | return { n, lo: q(0.25), mid: q(0.5), hi: q(0.75), check: k * (k - 1) / 2 } |
| 69 | }) |
| 70 | const W = 720, H = 340, L = 56, R = W - 96, T = 12, B = H - 28, NMAX = 144, EMAX = Math.ceil(Math.log10(rows.at(-1).hi)) |
| 71 | const X = n => L + n / NMAX * (R - L), Y = v => B - Math.log10(v) / EMAX * (B - T), num = v => (Math.round(v * 10) / 10).toString() |
| 72 | const sup = n => String(n).replace(/[0-9]/g, d => '⁰¹²³⁴⁵⁶⁷⁸⁹'[d]) |
| 73 | const out = [`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 ${W} ${H}" width="${W}" height="${H}" font-family="system-ui, -apple-system, 'Segoe UI', sans-serif" font-size="12">`, |
| 74 | '<title>Steps to find a dorm against pairs read to check one</title>', |
| 75 | '<style>.bg{fill:#fff}.grid{stroke:#ebedf0}.axis{stroke:#dadce0}.t{fill:#5f6368}.find{stroke:#03586f}.findf{fill:#03586f}.band{fill:#03586f;fill-opacity:.14}.check{stroke:#188038}.checkf{fill:#188038}' + |
| 76 | '@media (prefers-color-scheme: dark){.bg{fill:#1f2023}.grid{stroke:#2e3033}.axis{stroke:#3c4043}.t{fill:#9aa0a6}.find{stroke:#6fb9c9}.findf{fill:#6fb9c9}.band{fill:#6fb9c9;fill-opacity:.18}.check{stroke:#81c995}.checkf{fill:#81c995}}</style>', |
| 77 | `<rect class="bg" width="${W}" height="${H}"/>`] |
| 78 | for (let e = 0; e <= EMAX; e++) { const y = Math.round(Y(10 ** e)) + 0.5; out.push(`<path class="grid" d="M${L} ${y}H${R}"/><text class="t" x="${L - 8}" y="${y + 4}" text-anchor="end">${e === 0 ? '1' : e === 1 ? '10' : '10' + sup(e)}</text>`) } |
| 79 | for (const n of [0, 20, 40, 60, 80, 100, 120, 140]) out.push(`<text class="t" x="${num(X(n))}" y="${B + 18}" text-anchor="middle">${n}</text>`) |
| 80 | out.push(`<path class="axis" d="M${L} ${B + 0.5}H${R}"/>`) |
| 81 | out.push(`<path class="band" d="M${rows.map(r => `${num(X(r.n))} ${num(Y(r.hi))}`).join('L')}L${rows.slice().reverse().map(r => `${num(X(r.n))} ${num(Y(r.lo))}`).join('L')}Z"/>`) |
| 82 | out.push(`<path class="find" fill="none" stroke-width="2" d="M${rows.map(r => `${num(X(r.n))} ${num(Y(r.mid))}`).join('L')}"/>`) |
| 83 | out.push(...rows.map(r => `<circle class="findf" cx="${num(X(r.n))}" cy="${num(Y(r.mid))}" r="2.6"/>`)) |
| 84 | out.push(`<path class="check" fill="none" stroke-width="2" d="M${rows.map(r => `${num(X(r.n))} ${num(Y(r.check))}`).join('L')}"/>`) |
| 85 | const last = rows.at(-1) |
| 86 | out.push(`<text class="findf" x="${num(X(last.n) + 8)}" y="${num(Y(last.mid) + 4)}" font-weight="600">${last.mid.toLocaleString('en-US')}</text>`) |
| 87 | out.push(`<text class="checkf" x="${num(X(last.n) + 8)}" y="${num(Y(last.check) + 4)}" font-weight="600">${last.check}</text>`) |
| 88 | out.push('</svg>') |
| 89 | console.log(out.join('\n')) |