| | @@ -1,24 +1,47 @@ |
| 1 | 1 | import Lean |
| 2 | 2 | import ErdosSwarm |
| 3 | 3 | |
| 4 | | −/-! Fails unless every theorem under `ErdosSwarm` uses only Lean's three standard axioms. -/ |
| 4 | +/-! |
| 5 | +Fails unless |
| 6 | +* no constant under `ErdosSwarm` (theorem, definition, instance, auxiliary, ...) depends on `sorryAx`, |
| 7 | +* no axiom is declared under `ErdosSwarm`, and |
| 8 | +* every theorem under `ErdosSwarm` uses only Lean's three standard axioms |
| 9 | + (`propext`, `Classical.choice`, `Quot.sound`). |
| 10 | +-/ |
| 5 | 11 | |
| 6 | 12 | open Lean Elab Command |
| 7 | 13 | |
| 8 | 14 | elab "#check_swarm_axioms" : command => do |
| 9 | 15 | let env ← getEnv |
| 10 | 16 | let allowed : List Name := [``propext, ``Classical.choice, ``Quot.sound] |
| 11 | | − let mut checked : Nat := 0 |
| 17 | + let mut theorems : Nat := 0 |
| 18 | + let mut constants : Nat := 0 |
| 12 | 19 | let mut bad : Array (Name × Name) := #[] |
| 13 | | − for (c, info) in env.constants.map₁.toList do |
| 20 | + let mut sorried : Array Name := #[] |
| 21 | + let mut declaredAxioms : Array Name := #[] |
| 22 | + -- Both maps: imported constants and any declared in this file (so a scratch copy can demonstrate a failure). |
| 23 | + let all := env.constants.fold (fun acc c info => acc.push (c, info)) #[] |
| 24 | + for (c, info) in all do |
| 14 | 25 | if c.getRoot == `ErdosSwarm then |
| 26 | + constants := constants + 1 |
| 27 | + if let .axiomInfo _ := info then declaredAxioms := declaredAxioms.push c |
| 28 | + let axs ← liftCoreM (collectAxioms c) |
| 29 | + if axs.contains ``sorryAx then sorried := sorried.push c |
| 15 | 30 | if let .thmInfo _ := info then |
| 16 | | − checked := checked + 1 |
| 17 | | − for a in ← liftCoreM (collectAxioms c) do |
| 18 | | − unless allowed.contains a do bad := bad.push (c, a) |
| 19 | | − if bad.isEmpty then |
| 20 | | − logInfo m!"{checked} theorems use only propext, Classical.choice and Quot.sound" |
| 31 | + theorems := theorems + 1 |
| 32 | + for a in axs do |
| 33 | + unless allowed.contains a || a == ``sorryAx do bad := bad.push (c, a) |
| 34 | + let mut errors : Array MessageData := #[] |
| 35 | + unless sorried.isEmpty do |
| 36 | + errors := errors.push m!"uses sorry: {sorried.toList}" |
| 37 | + unless declaredAxioms.isEmpty do |
| 38 | + errors := errors.push m!"declares an axiom: {declaredAxioms.toList}" |
| 39 | + unless bad.isEmpty do |
| 40 | + errors := errors.push m!"not proved (disallowed axioms): {bad.toList}" |
| 41 | + if errors.isEmpty then |
| 42 | + logInfo m!"{theorems} theorems use only propext, Classical.choice and Quot.sound; \ |
| 43 | + none of the {constants} constants under ErdosSwarm uses sorry" |
| 21 | 44 | else |
| 22 | | − throwError m!"not proved (disallowed axioms): {bad.toList}" |
| 45 | + throwError MessageData.joinSep errors.toList "\n" |
| 23 | 46 | |
| 24 | 47 | #check_swarm_axioms |