把黎曼猜想的 Lean 证明,写成人能读懂的证明
把黎曼猜想的 Lean 证明写成数学家能读的证明文章,以及人人能看懂的证明思路
| 1 | import Lean |
| 2 | open Lean |
| 3 | |
| 4 | def atlasKind : ConstantInfo → String |
| 5 | | .axiomInfo _ => "axiom" |
| 6 | | .defnInfo _ => "definition" |
| 7 | | .thmInfo _ => "theorem" |
| 8 | | .opaqueInfo _ => "opaque" |
| 9 | | .quotInfo _ => "quotient" |
| 10 | | .inductInfo _ => "inductive" |
| 11 | | .ctorInfo _ => "constructor" |
| 12 | | .recInfo _ => "recursor" |
| 13 | |
| 14 | unsafe def main (args : List String) : IO UInt32 := do |
| 15 | let [entry, modulesFile, outputFile] := args |
| 16 | | throw <| IO.userError "usage: ExtractAtlas.lean ENTRY MODULES.txt OUTPUT.jsonl" |
| 17 | initSearchPath (← findSysroot) |
| 18 | let modulesText ← IO.FS.readFile modulesFile |
| 19 | let modulesText := modulesText.replace "\r" "" |
| 20 | let modules : Std.HashSet String := Std.HashSet.ofList (modulesText.splitOn "\n" |>.filter (· != "")) |
| 21 | enableInitializersExecution |
| 22 | let env ← importModules #[{module := entry.toName}] {} (loadExts := true) |
| 23 | let ctx : PPContext := { env := env } |
| 24 | let output ← IO.FS.Handle.mk outputFile .write |
| 25 | let mut count := 0 |
| 26 | let mut missingRanges := 0 |
| 27 | for (name, info) in env.constants.toList do |
| 28 | let some idx := env.getModuleIdxFor? name | continue |
| 29 | let moduleName := env.header.moduleNames[idx]!.toString |
| 30 | unless modules.contains moduleName do continue |
| 31 | let typeText := (← ctx.runMetaM (Meta.ppExpr info.type)).pretty 120 |
| 32 | let ranges ← ctx.runCoreM (findDeclarationRanges? name) |
| 33 | let lines := match ranges with |
| 34 | | some ranges => ranges.range.endPos.line - ranges.range.pos.line + 1 |
| 35 | | none => 0 |
| 36 | if ranges.isNone then missingRanges := missingRanges + 1 |
| 37 | -- Use Lean's own helper: references in types and values, including opaque |
| 38 | -- theorem values, plus its inductive/constructor/recursor metadata policy. |
| 39 | let dependencies := info.getUsedConstantsAsSet.toList.map Name.toString |>.mergeSort (· < ·) |
| 40 | let row := Json.mkObj [ |
| 41 | ("name", toJson name.toString), ("module", toJson moduleName), |
| 42 | ("kind", toJson (atlasKind info)), ("type", toJson typeText), |
| 43 | ("dependencies", toJson dependencies), ("source_lines", toJson lines)] |
| 44 | output.putStrLn row.compress |
| 45 | count := count + 1 |
| 46 | output.flush |
| 47 | IO.eprintln s!"Extracted {count} declarations; {missingRanges} have no recorded declaration range (source_lines = 0)." |
| 48 | return 0 |