Lean library · module TopologyByExample.Crosswalk.AssertDecl
assert_decl: checking the kind and home of a declaration
The generated crosswalk check TopologyByExample.Crosswalk.MathlibCheck records, for every
Mathlib declaration it relies on, what kind of declaration it is and which module defines it.
The command assert_decl makes that record machine-checked:
assert_decl T0Space "class" Mathlib.Topology.Separation.Basic
fails unless T0Space resolves to a declaration of the stated kind, defined in the stated
module. The kinds are
class: a structure or inductive registered as a type class;structure: a structure that is not a class;abbrev: a definition with@[reducible]reducibility;def: any other definition (not a class, not reducible, not an instance);theorem: a theorem that is not an instance (under the module system, a theorem imported from another module may appear as an axiom-like constant; any such constant whose type is a proposition counts as a theorem);instance: a declaration registered as an instance (definition or theorem).
The command assert_standard_axioms n fails unless the declaration n depends only on Lean's
standard axioms (propext, Classical.choice, Quot.sound; any subset of them). The generated
content check uses it for the content's general theorems, whose statements are given in prose.
This file was written by Claude (Anthropic's AI model) working under the direction of David R. MacIver, who reviews it and is responsible for it.
Imports
- Lean.Elab.Command
- Lean.Meta.Instances
- Lean.Util.CollectAxioms
definition declKind
TopologyByExample.Crosswalk.declKind
The kind of the constant n, in the vocabulary of assert_decl.
def declKind (n : Name) : MetaM String
Definition
:= do
let env ← getEnv
let some ci := env.find? n | throwError "unknown constant {n}"
if isClass env n then return "class"
if ← Meta.isInstance n then return "instance"
if isStructure env n then return "structure"
match ci with
| .thmInfo _ => return "theorem"
| .axiomInfo ai => if ← Meta.isProp ai.type then return "theorem" else return "axiom"
| .defnInfo _ =>
if (← getReducibilityStatus n) == .reducible then return "abbrev" else return "def"
| _ => return "other"
elab (name := assertDecl) "assert_decl " id:ident kind:str mod:ident : command => do
let n ← liftCoreM <| realizeGlobalConstNoOverloadWithInfo id
let actual ← liftTermElabM <| declKind n
let expected := kind.getString
unless actual == expected do
throwError "{n} is a(n) {actual}, not a(n) {expected}"
let env ← getEnv
let some idx := env.getModuleIdxFor? n
| throwError "{n} is defined in the current file, not in {mod.getId}"
let home := env.header.moduleNames[idx.toNat]!
unless home == mod.getId do
throwError "{n} is defined in {home}, not in {mod.getId}"
definition standardAxioms
TopologyByExample.Crosswalk.standardAxioms
The axioms a result of the project may depend on: Lean's standard three.
def standardAxioms : List Name
:= [``propext, ``Classical.choice, ``Quot.sound]
elab (name := assertStandardAxioms) "assert_standard_axioms " id:ident : command => do
let n ← liftCoreM <| realizeGlobalConstNoOverloadWithInfo id
let axioms ← liftCoreM <| Lean.collectAxioms n
let bad := axioms.filter (· ∉ standardAxioms)
unless bad.isEmpty do
throwError "{n} depends on non-standard axioms: {bad.toList}"