import assert from 'node:assert/strict'; import { createReadStream } from 'node:fs'; import { createInterface } from 'node:readline'; import { createGunzip } from 'node:zlib'; // Each input graph6 record is the complement of the all-odd graph to check. // The inputs are the even-degree graph catalogues of Brendan McKay's data page. function decodeComplement(record, n) { assert.equal(record.charCodeAt(0) - 63, n); assert.equal(record.length, 1 + Math.ceil(n * (n - 1) / 12)); const adjacency = new Uint16Array(n); let bit = 0; for (let v = 1; v < n; v++) { for (let u = 0; u < v; u++, bit++) { const code = record.charCodeAt(1 + Math.floor(bit / 6)) - 63; if ((code & (32 >> (bit % 6))) === 0) { adjacency[v] |= 1 << u; adjacency[u] |= 1 << v; } } } return adjacency; } function dataForOrder(n) { const m = n / 2; const half = 1 << m; const full = half * half - 1; const sizes = new Uint8Array(full + 1); for (let s = 1; s <= full; s++) sizes[s] = sizes[s >>> 1] + (s & 1); const patterns = Array.from({ length: half }, (_, mask) => { const unrestricted = (half - 1) ^ mask; const supermasks = []; for (let free = unrestricted; ; free = (free - 1) & unrestricted) { supermasks.push(free); if (!free) break; } return supermasks; }); const rightWords = new Uint32Array(2 * half * half); for (let mask = 0; mask < half; mask++) { for (let pattern = mask; ; pattern = (pattern - 1) & mask) { const address = 2 * (mask * half + pattern); for (const free of patterns[mask]) { const label = pattern | free; rightWords[address + (label >>> 5)] |= 1 << (label & 31); } if (!pattern) break; } } const allLow = half < 32 ? 2 ** half - 1 : 0xffffffff; const allHigh = half > 32 ? 0xffffffff : 0; return { m, half, full, sizes, patterns, rightWords, allLow, allHigh }; } function smallestUncovered(adjacency, data, threshold) { const { m, half, full, sizes, patterns, rightWords, allLow, allHigh } = data; const leftXor = new Uint16Array(half); const rightXor = new Uint16Array(half); for (let s = 1; s < half; s++) { const bit = s & -s; const v = 31 - Math.clz32(bit); leftXor[s] = leftXor[s ^ bit] ^ adjacency[v]; rightXor[s] = rightXor[s ^ bit] ^ adjacency[v + m]; } const coverage = new Uint32Array(2 * half); let completed = 0; // For a subset S, parity labels are fixed on S and arbitrary off S. // Accumulate all such labelings as bit sets, grouping by their left half. for (let s = 1; s <= full; s++) { if (sizes[s] < threshold) continue; const onLeft = s & (half - 1); const onRight = s >>> m; const parity = (leftXor[onLeft] ^ rightXor[onRight]) & s; const leftLabel = parity & (half - 1); const rightAddress = 2 * (onRight * half + (parity >>> m)); const low = rightWords[rightAddress]; const high = rightWords[rightAddress + 1]; for (const free of patterns[onLeft]) { const address = 2 * (free | leftLabel); if (coverage[address] === allLow && coverage[address + 1] === allHigh) continue; coverage[address] |= low; coverage[address + 1] |= high; if (coverage[address] === allLow && coverage[address + 1] === allHigh) { if (++completed === half) return -1; } } } for (let left = 0; left < half; left++) { for (let right = 0; right < half; right++) { if (((coverage[2 * left + (right >>> 5)] >>> (right & 31)) & 1) === 0) { return left | (right << m); } } } throw new Error('inconsistent coverage count'); } function directMaxima(adjacency, sizes) { const order = adjacency.length; const best = new Uint8Array(1 << order); for (let labels = 0; labels < best.length; labels++) { for (let s = 1; s < best.length; s++) { if (sizes[s] <= best[labels]) continue; const valid = adjacency.every((neighbors, v) => !(s & (1 << v)) || (sizes[neighbors & s] & 1) === ((labels >> v) & 1)); if (valid) best[labels] = sizes[s]; } } return best; } const n = Number(process.argv[2]); assert([2, 4, 6, 8, 10, 12].includes(n), 'usage: node check-degree-parity.mjs order graph6-file ...'); const files = process.argv.slice(3); assert(files.length > 0); const data = dataForOrder(n); let checked = 0; let tight = 0; let witness; for (const path of files) { const stream = createReadStream(path); const input = path.endsWith('.gz') ? stream.pipe(createGunzip()) : stream; const lines = createInterface({ input, crlfDelay: Infinity }); for await (const line of lines) { const record = line.trim(); if (!record || record === '>>graph6<<') continue; const adjacency = decodeComplement(record, n); assert(adjacency.every((a) => data.sizes[a] & 1)); const uncovered = smallestUncovered(adjacency, data, n / 2); if (uncovered >= 0) { const maximum = directMaxima(adjacency, data.sizes)[uncovered]; assert(maximum < n / 2); throw new Error(JSON.stringify({ counterexample: record, adjacency: [...adjacency], uncovered, maximum })); } if (n <= 8 && checked % 19 === 0) { assert(directMaxima(adjacency, data.sizes).every((maximum) => maximum >= n / 2)); } if (n <= 10) { const label = smallestUncovered(adjacency, data, n / 2 + 1); if (label >= 0) { witness ??= { record, label, adjacency: [...adjacency] }; tight++; } } checked++; if (n === 12 && checked % 1_000_000 === 0) console.error(`${path}: ${checked}`); } console.log(JSON.stringify({ order: n, checked, ...(n <= 10 ? { tight, witness } : {}) })); }