agentsclimarketplace

Lean math foundations

Skill r-irbe/proof-skills/skills/lean-math-foundations

APM-installable agent skills for Lean 4 and Mathlib4 — proof tactics, math domains, review and research workflows, generic tooling.

Install
npx -y skills add r-irbe/proof-skills --skill lean-math-foundations

Assembled from the repository path, not quoted from the project. Check it against their README if it does not work.

One thing to look at

  • 2 stars2 stars. Stars are a popularity signal and not a quality one, but at this level it is likely that nobody has read this closely except its author, and you would be relying on your own review.

What its author says it does

Copied from the file, not written here

USE FOR: foundational mathematics in Lean 4 — Lean's type system (Prop / Type / universes), classical vs constructive choices, Mathlib's algebraic typeclass hierarchy (Group / Ring / Order / Lattice / Module / Algebra), category theory basics, and any proof that needs foundational reasoning about types, propositions, or universes. DO NOT USE FOR: applied lattice instances such as severity / quality-gate lattices (use @lean-math-discrete); analysis-flavoured algebra such as normed-space structure (use @lean-math-analysis); writing a specific proof (use @lean-proof); reviewing a finished proof (use @lean-proof-review). TRIGGERS: type universe, Prop vs Type, classical reasoning, Classical.choice, algebraic typeclass, Mathlib hierarchy, category theory, propext, funext.

SKILL.md

8.1 KB, as published. Nobody here has run it

Lean 4 Mathematical Foundations

Guide to formalizing foundational mathematics in Lean 4, covering the structures and patterns that underpin all domain-specific formalization work.

Routing

  • USE FOR: foundational mathematics in Lean 4 — Lean's type system (Prop / Type / universes), classical vs constructive choices, Mathlib's algebraic typeclass hierarchy (Group / Ring / Order / Lattice / Module / Algebra), category theory basics, and any proof that needs foundational reasoning about types, propositions, or universes.
  • DO NOT USE FOR: applied lattice instances such as severity / quality-gate lattices (delegate to @lean-math-discrete); analysis-flavoured algebra such as normed-space structure (delegate to @lean-math-analysis); writing a specific proof (delegate to @lean-proof); reviewing a finished proof (delegate to @lean-proof-review).
  • TRIGGERS: type universe, Prop vs Type, classical reasoning, Classical.choice, algebraic typeclass, Mathlib hierarchy, category theory, propext, funext.

Workflow

  1. Identify whether the question is about Lean's logical foundation (Part 1), Mathlib's typeclass hierarchy (Parts 2–5), or a category-theoretic construction (later parts).
  2. Locate the relevant Part below and read the project-relevance callouts before applying any pattern.
  3. If the answer is a specific proof, handoff to @lean-proof; if it is a soundness-affecting choice (e.g., adding a new Classical import), handoff to @lean-proof-review and @lean-enforcement.

Recovery & STOP

  • STOP if a foundational choice silently introduces a new axiom — #print axioms must show only propext, Classical.choice, Quot.sound (and funext is a theorem, not an axiom). Escalate to @lean-review-council if uncertain.
  • STOP and handoff to @lean-research if the question is about a result not present in Mathlib at the current pin (e.g., a new universe-polymorphism API).

Handoffs

  • Predecessors: agent:gateway, skill:lean-proof (mid-proof typeclass synthesis failure), skill:lean-research (when a survey turns up a foundational construct).
  • Successors: skill:lean-proof (apply the foundational pattern in a concrete proof), skill:lean-proof-review (verify axiom impact), skill:lean-enforcement (run native-decide / #print axioms checks after the change).

Detailed reference

Full encyclopaedia content (Parts 1 through 6) lives in references/lean4-math-foundations.md. Load that file when authoring; the SKILL.md only carries the dispatch contract and the high-frequency pitfalls / recipes (kept inline below).

PartTopicCovers
Part 1Lean's Logical Foundationstype universes, classical vs constructive, Prop vs Decidable, equality variants
Part 2Set Theory in MathlibSet vs Finset, set operations, well-founded recursion, choice principles
Part 3Algebraic HierarchiesMonoid → Group → Ring → Field, Order typeclasses, instance discovery
Part 4Order TheoryPreorder, PartialOrder, LinearOrder, Lattice, Galois connections
Part 5Logic and Proof Techniquesclassical reasoning, decidability, choice, propositional extensionality
Part 6Category Theory BasicsMathlib's CategoryTheory namespace; when to use it (rarely)

Part 7 — Research Council Integration

Consolidated into the single canonical routing matrix: references/research-council-skill-map.md (see the "Foundations" section). When dispatching a question to a council member, cite that table rather than restating the rows here.


Part 8 — Common Pitfalls & Anti-Patterns

PitfallSymptomRecovery
Decidable-instance synthesis loopfailed to synthesize Decidable + stack-depth warningReplace infer_instance with Classical.dec _; mark the surrounding def noncomputable if needed
Universe-polymorphism mismatchtype mismatch involving .{u} arguments in elaborationAnnotate universes explicitly (@F.{u, v}); prefer Type _ over Type 0 in generic positions
simp set explosion via algebraic typeclassesTrivial goal hangs simpSwitch to simp only [...] with a hand-picked list; drop Algebra.* lemmas when working over Nat
Unintended Classical.choice leak#print axioms shows Classical.choice on a supposedly constructive proofSearch for Classical.byContradiction / decide-via-Decidable.decide coercions; localise the open Classical
PropBool confusionsimp won't reduce a decide-based goalDecidable.decide_eq_true_iff bridges them; or rewrite via Bool.decide lemmas
funext on dependent functionsfunext_iff doesn't firefunext_iff is non-dependent only; for Π x, ... unfold and apply funext directly

Anti-patterns

  • Do not redeclare a Group / Ring instance that already exists in Mathlib — it triggers diamond / overlap issues. Search Mathlib.Algebra.Group.Defs first.
  • Do not open Classical at file scope — it pollutes every decide downstream. Open it only inside the proof that needs it.
  • Do not reach for Mathlib.CategoryTheory.* if the same statement can be phrased in Mathlib.Order.* or Mathlib.Algebra.Order.*; the category-theoretic phrasing is correct but harder to automate against.

Part 9 — Recovery Recipes

SituationFirst-line recipe
Typeclass synthesis stuck on an instance you believe existsset_option synthInstance.maxHeartbeats 40000 temporarily, then exact? to confirm the instance Mathlib expects
simp loops on an algebraic rewritesimp only [list]; replace add_comm with Nat.add_comm etc. (qualified names cut through diamond confusion)
decide can't see a Decidable instanceclassical decide (uses Classical.dec); or rewrite the predicate to one with a Decidable instance you can locate via #check
Universe issue blocks elaborationAnnotate universes explicitly (@F.{u, v}) at the call site
Need a foundational lemma absent from Mathlib at the pinAuthor it locally in a host-repository Foundation/Helpers.lean (mirroring the Mathlib namespace) and open a Lean/Mathlib PR via @lean-pr
Want to suppress an instance for one sectionattribute [-instance] foo in section — preferable to deleting the instance entirely

See also

Keep looking

Skills are one crate of 328,083. Ordering is by how many stacks a row turns up in, so the top of any crate is what has actually been picked rather than what has the most stars.