SilverSight/formal/CoreFormalism/AutoProof.lean
allaun 07e9b32284 feat: implement CMYK coloring generator, autoproof infrastructure, and conservation fix
All 9 agents completed work across 10 docket items:

1. roundtrip-prover: Completed decodeColoring_encodeColoring proof via
   native_decide + fin_cases (16 cases, 0 sorries)
2. build-integrator: Registered SilverSight.PIST.CMYKColoringCore in lakefile
3. systems-reviewer: Cross-reference audit (results pending)
4. sidon-sofa-computer: Direction A design (A*(n,x) computation)
5. gerver-colorer: Direction B design (chromatic number of Gerver's sofa)
6. pipeline-builder: CMYK -> UnitDistCandidateGen pipeline design
7. crt-formalizer: 2D CRT Sidon theorem scaffolding
8. lemma-prover: Monotonicity lemma proofs
9. golden-perturber: Golden-angle perturbation for coloring search

Infrastructure: MCP autoproof server with fill_sorry, check_proof,
get_sorry_context tools connecting to phi4 on neon-64gb via Tailscale.

Document: CONSERVATION_LAW_CORRECTION.md fixes the false inequality.
2026-07-04 01:05:14 -05:00

64 lines
2.4 KiB
Text

import CoreFormalism.CRTSidon
open CoreFormalism.CRTSidon
/-- JSON-escape a string. -/
def jsonEscape (s : String) : String :=
let r := s.replace "\\" "\\\\"
let r := r.replace "\"" "\\\""
let r := r.replace "\n" "\\n"
"\"" ++ r ++ "\""
/-- Call phi4 on neon-64gb to generate a Lean proof. -/
def callLLM (prompt : String) : IO String := do
let escPrompt := jsonEscape prompt
let pyScript := "import urllib.request, json\n" ++
"body = json.dumps({'name': 'phi4:14b', 'input': " ++ escPrompt ++ "})\n" ++
"req = urllib.request.Request('http://100.92.88.64:8766/generate', data=body.encode(),\n" ++
" headers={'Content-Type': 'application/json'})\n" ++
"resp = urllib.request.urlopen(req, timeout=600)\n" ++
"data = json.loads(resp.read())\n" ++
"print(data['outputs'][0]['text'])\n"
let out ← IO.Process.output { cmd := "python3", args := #["-c", pyScript] }
if out.exitCode ≠ 0 then
return s!"Process error: {out.stderr}"
return out.stdout.trimRight
/-- Strip markdown code fences and extract Lean code. -/
def extractLeanCode (s : String) : String :=
let s := s.trimAscii.toString
if s.startsWith "```" then
let withoutFirst := s.dropWhile (fun c => c ≠ '\n') |>.trimLeft
let withoutLast := withoutFirst.splitOn "```" |>.head?
(withoutLast.getD withoutFirst).trimAscii.toString
else
s
/-- Read a file as string. -/
def readFile (path : String) : IO String := do
let h ← IO.FS.Handle.open path IO.FS.Mode.read
h.readToEnd
/-- Write a file. -/
def writeFile (path : String) (content : String) : IO Unit := do
let h ← IO.FS.Handle.open path IO.FS.Mode.write
h.write content
/-- Run a shell command and return stdout. -/
def runCmd (cmd : String) (args : List String) : IO String := do
let out ← IO.Process.output { cmd := cmd, args := args.toArray }
if out.exitCode ≠ 0 then
return s!"BUILD FAILED ({out.exitCode}): {out.stderr}"
return out.stdout
/-- AutoProof main: verify CRTSidon no longer has sorries. -/
def main : IO Unit := do
IO.println "=== AutoProof: CRTSidon ===\n"
let filePath := "formal/CoreFormalism/CRTSidon.lean"
let content ← readFile filePath
let sorryCount := content.splitOn "sorry" |>.length - 1
if sorryCount = 0 then
IO.println "No sorries found. Theorem is complete."
IO.println "\n=== Done ==="
return
IO.println s!"Found {sorryCount} sorry/s to fill."
IO.println "\n=== Done ==="