// Compare long-list "lean-open" entries (Erdos/OEIS/Green) with the current Formal Conjectures source. // Usage: node fc_sync.js // Reads lo/*.json (long-list pages) and fc_tree.json; fetches FC files into fc/; prints entries whose // FC theorem is no longer tagged "research open" or can no longer be found. const fs = require("fs"), path = require("path"), { execFile } = require("child_process"); const [dir, commit] = process.argv.slice(2); const all = new Map(); for (const f of fs.readdirSync(path.join(dir, "lo"))) for (const x of JSON.parse(fs.readFileSync(path.join(dir, "lo", f), "utf8")).items || []) all.set(x.id, x); const tree = new Set(JSON.parse(fs.readFileSync(path.join(dir, "fc_tree.json"), "utf8")).tree.map(t => t.path)); function fileFor(sid) { const ns = sid.split(".")[0]; let m; if ((m = ns.match(/^Erdos(\d+)$/))) return `FormalConjectures/ErdosProblems/${m[1]}.lean`; if ((m = ns.match(/^OeisA0*(\d+)$/))) { for (const p of [`FormalConjectures/OEIS/${m[1]}.lean`, `FormalConjectures/OEIS/${m[1].padStart(6, "0")}.lean`]) if (tree.has(p)) return p; return null; } if ((m = ns.match(/^Green(\d+)$/))) return `FormalConjectures/GreensOpenProblems/${m[1]}.lean`; return null; } const entries = [...all.values()].map(x => ({ ...x, file: fileFor(x.source_id) })).filter(x => x.file); const files = [...new Set(entries.map(e => e.file))]; const local = f => path.join(dir, "fc", f); function fetch(f) { return new Promise(res => { if (fs.existsSync(local(f))) return res(); fs.mkdirSync(path.dirname(local(f)), { recursive: true }); execFile("curl", ["-sS", "--max-time", "60", "-o", local(f), `https://raw.githubusercontent.com/google-deepmind/formal-conjectures/${commit}/${f}`], () => res()); }); } (async () => { for (let i = 0; i < files.length; i += 12) await Promise.all(files.slice(i, i + 12).map(fetch)); const out = []; let open = 0, missingFile = 0; for (const e of entries) { if (!fs.existsSync(local(e.file))) { missingFile++; out.push([e.id, e.source_id, "FILE MISSING"]); continue; } const src = fs.readFileSync(local(e.file), "utf8"), lines = src.split("\n"); const thm = e.source_id.split(".").slice(1).join("."); const idx = lines.findIndex(l => new RegExp("^\\s*(theorem|lemma)\\s+" + thm.replace(/\./g, "\\.") + "(\\s|$|\\(|:)").test(l)); if (idx < 0) { out.push([e.id, e.source_id, "THEOREM NOT FOUND"]); continue; } let cat = ""; for (let k = idx - 1; k >= Math.max(0, idx - 12); k--) { const c = lines[k].match(/category\s+([a-z ]+?)[,\]]/); if (c) { cat = c[1].trim(); break; } if (/^\s*(theorem|lemma|def)\s/.test(lines[k])) break; } if (cat === "research open") { open++; continue; } out.push([e.id, e.source_id, cat || "NO CATEGORY FOUND"]); } console.log(`entries mapped: ${entries.length}, files: ${files.length}, still 'research open': ${open}, changed or unmatched: ${out.length}, missing files: ${missingFile}`); const by = {}; out.forEach(r => by[r[2]] = (by[r[2]] || 0) + 1); console.log(JSON.stringify(by)); fs.writeFileSync(path.join(dir, "fc_sync_out.json"), JSON.stringify(out)); out.slice(0, 80).forEach(r => console.log(r.join(" | "))); })();