Skip to content
Back to skills

Lean Proof

ASecurity

Use when asked to prove something in Lean. Covers one-step-at-a-time proving, error priority, working on the hardest case first, proof cleanup, skill discovery and loading, evolution pipeline skill registration, handling unknown skill failures, handling dependent type rewriting issues, and verification gates.

  • 3 stars
  • 0 votes
  • 0 copies
  • 2 views
  • Added November 24, 2026
developmentpythongobashexpressawstestingdebuggingdocumentation

Works with

  • cli

Security analysis

A100/100

Scanned November 24, 2026

npx -y skills add nickgou-nuke/info-geometry-lean --skill lean-proof --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Lean Proof?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Lean Proof
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/nickgou-nuke-lean-proof/badge)](https://www.skillsdirectory.com/skills/nickgou-nuke-lean-proof)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: lean-proof
description: Use when asked to prove something in Lean. Covers one-step-at-a-time proving, error priority, working on the hardest case first, proof cleanup, skill discovery and loading, evolution pipeline skill registration, handling unknown skill failures, handling dependent type rewriting issues, and verification gates.
---

<!-- repository-context-rule -->
## Repository context rule

For repository work, the current checked-out codebase is the context. Search
existing implementation and trace actual carriers, definitions, imports,
instances, theorem statements, and uses before claiming a structure is missing
or incorrect. A local absence is not a repository-wide absence. Names,
heuristics, summaries, and documentation guide discovery but do not override
source. Follow `docs/REPO_DEEP_SEARCH_PROTOCOL.md` before repo-wide gap claims.


## Constructive Closure Mandate

Replacing witness-gated and external-certificate leftovers with native Lean 4 proofs is the highest mandate. Treat witness packets, certificate fields, external certificates, assumption interfaces, literature owners, graph edges, and physics analogies as closure debt until discharged by kernel-checked Lean or imported mathlib theorems. Follow docs/CONSTRUCTIVE_CLOSURE_MANDATE.md; never promote anonymous or unformalized sockets as complete.

## Evolution Pipeline: Registering Generated Skill Variants

This skill participates in an evolution (self-evolver) pipeline. The pipeline mutates this SKILL.md, writes the result to `quarantine/hermes_skills/evolved/lean-proof/gen_NNN/SKILL.md`, and then tests the variant by loading it.

**The test step fails** when a variant is loaded by filesystem path instead of by registered name. To correctly test a generated variant:

### Correct Loading: Register Then View

```python
# Step 1: Register the generated skill by name
skill_manage(
    action="create",
    name="lean-proof-gen-NNN",  # or any unique name
    content=read_file("quarantine/hermes_skills/evolved/lean-proof/gen_NNN/SKILL.md")
)

# Step 2: Load the registered skill by name
skill_view(name="lean-proof-gen-NNN")
```

### INCORRECT (causes failure)

```python
# WRONG: Filesystem paths are NOT skill names
skill_view(name="quarantine/hermes_skills/evolved/lean-proof/gen_000")
# Error: Unknown skill(s): quarantine/hermes_skills/evolved/lean-proof/gen_000
```

### Cleanup After Testing

After testing, remove the temporary skill registration:

```python
skill_manage(action="delete", name="lean-proof-gen-NNN", absorbed_into="")
```

### Evolution Pipeline Integration Checklist

When this skill is being evolved or tested by a self-evolver pipeline:

1. Read the mutated SKILL.md from `quarantine/hermes_skills/evolved/lean-proof/gen_NNN/SKILL.md`
2. Register it: `skill_manage(action="create", name="lean-proof-gen-NNN", content=...)`
3. Load it: `skill_view(name="lean-proof-gen-NNN")`
4. Execute the proof task using the loaded skill
5. Clean up: `skill_manage(action="delete", name="lean-proof-gen-NNN", absorbed_into="")`
6. Collect the outcome and fitness score

Never pass a filesystem path as a `name` parameter to `skill_view()`. Only registered skill names work.

## Before Starting: Skill Discovery and Loading

Always search for and load relevant skills before beginning proof work. This prevents "unknown skill" failures and ensures you have the right tooling.

### Skill Discovery

Use `skills_list()` to discover available skills, then `skill_view(name)` to load full content:

```
skills_list()                              # see all skills
skills_list(category="lean4-skills")       # Lean-specific skills
skills_list(category="software-development") # repo workflow skills
```

### Loading Skills

Load relevant skills by **registered skill name only** — never by filesystem path:

```
skill_view(name="lean4")                      # Lean 4 tooling, LSP commands, mathlib search
skill_view(name="native-proof-closure-mandate")  # Hard closure-debt reduction policy
skill_view(name="proof-root-hole-repair")     # Lean proof repair for semantic holes
```

### NEVER Reference Skills by Filesystem Path

**Do not** reference skills by filesystem path like:
```
skill_view(name="/home/goutev/repos/info-geometry-lean/quarantine/hermes_skills/evolved/lean-proof/gen_000")
# ^^^ WRONG — this will fail with "Unknown skill(s)"
```

Always use the registered skill name (the `name:` field in the skill's YAML frontmatter). If you don't know the name, use `skills_list()` to find it.

### Error Recovery: Unknown Skill

If `skill_view(name=...)` returns an "Unknown skill(s)" error:

1. Check the name you passed — is it a filesystem path instead of a registered name?
2. Run `skills_list()` to find the correct name
3. If the skill genuinely doesn't exist, proceed without it rather than fabricating a path
4. Log the missing skill as a discovery gap — do not silently retry with a guessed path or filesystem path

## Which Lean Skill to Load

| Situation | Load this skill first |
|-----------|----------------------|
| Editing .lean files, debugging builds, mathlib search | `lean4` |
| Replacing hypothesis/witness/certificate scaffolding with native proofs | `native-proof-closure-mandate` |
| Repairing proof holes, fake bridges, or wrapper projections | `proof-root-hole-repair` |
| Writing a new theorem corridor from scratch | `lean4` + this skill |
| Triage of strict-check CI blockers | `strict-check-artifact-triage` |
| Reducing closure debt in a specific corridor | `graph-guided-closure-debt` |

# Lean Proof Methodology

These are non-negotiable constraints for writing Lean proofs correctly.

## One Step at a Time

Write one tactic, check diagnostics (use `done` to see unsolved goals), repeat. Never write multiple tactics before checking.

**`by sorry` is acceptable**: For placeholders you're not actively working on.
**`done` is required**: When you expect there to be next steps in an active proof.

## Error Priority

Fix errors in this order — higher-priority errors make lower-priority ones unreliable:

1. **Syntax errors** -> 2. **Type errors** -> 3. **Unsolved goals / tactic failures** -> 4. **Linter warnings**

"Unsolved goals" errors appear on `by` or `=>` lines, NOT where you add tactics. If there's an "unsolved goals" on line 59 but a tactic error on line 65 -- fix line 65 FIRST.

Stop writing tactics after any error.

## Work on the Hardest Case First

### Across Theorems

Go directly to the target theorem. Don't fill in `sorry`s in helper lemmas first -- Lean treats `sorry` as an axiom, so dependent theorems still work.

Move sorries earlier in the file by replacing a `sorry` proof with references to simpler lemmas:

```lean
-- Before:
theorem main_theorem : A = C := by sorry

-- After:
theorem lemma1 : A = B := by sorry
theorem lemma2 : B = C := by sorry
theorem main_theorem : A = C := by
  rw [lemma1, lemma2]
```

### Within a Proof

When a proof has multiple cases, `sorry` the easy cases and work on the hardest one first. If the hard case fails, effort on easy cases is wasted.

```lean
match n with
| 0 => sorry -- fill in later
| 1 => sorry -- fill in later
| n + 2 => -- WORK ON THIS FIRST
```

## Proof Cleanup

After getting a proof to work, clean it up immediately:
- Combine redundant steps (`rw [a]; rw [b]` -> `rw [a, b]`)
- Test if `simp` can handle more (remove earlier steps one by one)
- Find the truly minimal proof

## Comment And Docstring Discipline

In `info-geometry-lean`, explanatory comments may be part of the theorem
transport substrate. They often map between SymPy, Python, Lean 4, LaTeX,
natural language, and physics-of-information terminology.

Do not shorten comments by default while proving. Preserve bridge-bearing prose,
expand it when needed for semantic accuracy, and correct it when it misstates
the formal object. Delete prose only when it is stale, false, duplicative, or
not carrying a representation bridge.

## Repository-Specific Pitfalls (info-geometry-lean)

### Carrier Equivalence Bridge Pattern

When two modules define the same algebraic carrier differently (e.g., matrix
literal `!![...]` vs function match), prove definitional equality first:

```lean
theorem tilt_eq_tilt2 : tilt = tilt2 := by
  ext i j
  fin_cases i <;> fin_cases j <;> simp [tilt, tilt2]
```

Then transfer theorems via `rw [← tilt_eq_tilt2, ← switch_eq_switch2]`.
This avoids duplicating proof logic across carriers.

### No-Namespace Import Trap

Some owner files (e.g., `Canonical/KleinBottleSewing.lean`) declare NO
namespace — all definitions are at top level. `open InfoGeometry.Canonical.KleinBottleSewing`
will fail with "unknown namespace". Import the file but do NOT open it;
use the definitions directly (they're in the global namespace).

### `λ` Is a Lambda Keyword, Not an Identifier

The Greek letter `λ` is parsed as lambda abstraction in Lean 4. Using it as a variable or parameter name (e.g., `{λ μ : ℝ}` or `twoSidedHyperbolicLaplace λ μ ...`) causes "unexpected token 'λ'" parse errors. Use `lam`, `mu`, `ell`, etc. instead. Same caution applies to other Greek letters that double as keywords/operators (`Σ` in some contexts); prefer ASCII names in signatures.

### `rw` vs `simpa` for Squared Lemmas
`tilt ^ 2 = 1`, because `rw` does not unfold `^ 2` to `*`. Use:

```lean
simpa [sq] using tilt_sq
```

### Namespace-Qualified Lemma Access

Lemmas like `clifford_squares`, `polarization_velocity`, `pp`, `pq`, `qp`,
`qq`, `pd`, `pb`, `qd`, `qb`, `dp`, `dq`, `bp`, `bq` are methods of
`IsDualSeedPair`, not bare identifiers. Access them as `IsDualSeedPair.X h`
or open the namespace with `open InfoGeometry.Core.DualSeedPeirce.IsDualSeedPair`.

Theorems defined later in the same file cannot be referenced earlier.
Reorder definitions so dependencies come first.

### `ring` Does Not Work on Matrices or Non-Commutative Rings

`ring`, `ring_nf`, and `abel` fail on non-commutative rings (any `Ring A`
without `CommRing A`) and on matrix expressions. Use `rw` with explicit
distributivity lemmas (`add_mul`, `mul_add`, `sub_mul`, `mul_sub`) and
`abel` only when the ring is commutative. When `simp` does not unfold a
`def` (only `abbrev`s unfold automatically), use `change` or `unfold`
to expose the underlying expression first.

### Anticommutation Role Swap Type Mismatch

When a Cl(1,1) atom construction swaps which factor is `c` (square +1) and which is `d'` (square −1), the anticommutation lemma `h` may prove `a * b + b * a = 0` while the goal expects `b * a + a * b = 0`. The terms are equal by commutativity of addition, but Lean does not unify them automatically. Fix with `rw [add_comm]` before `exact h`, rather than rewriting the lemma.

### `ZornVectorMatrix.zero` Does Not Reduce in `ext_h3` Goals

When `ext_h3` splits an `H3Zorn` equality into 6 fields, the ZornVectorMatrix
components (fields `a`, `b`, `c`) may show an expanded constructor form
`{ a := 0, v := fun i => 0, w := fun i => 0, b := 0 }` instead of
`ZornVectorMatrix.zero`. `simp` with `ZornVectorMatrix.conj_zero`,
`ZornVectorMatrix.norm_zero`, etc. reduces the expression but leaves this
expanded form unmatched. Add `ZornVectorMatrix.zero` to the `simp` list so Lean
unfolds `zero` to its constructor form, making both sides syntactically equal:

```lean
simp [adjointQuad, cuntzToAlbert_e1, ZornVectorMatrix.conj_zero,
  ZornVectorMatrix.zero_mul, ..., ZornVectorMatrix.zero]
```

### `Matrix.trace` vs `Matrix.traceAddMonoidHom`

These are not definitionally equal for `rw`. Either use `convert ... using 2`
or avoid the mismatch by reusing existing theorems that already use `Matrix.trace`.

`H3Zorn R` defines `Add` and `SMul R` as anonymous instances (`noncomputable
instance : Add (H3Zorn R) where ...`). Consequently, `simp [cuntzToAlbert_e1]`
unfolds the definition but does **not** compute `e1 + e1` or `2 • e1` —
`norm_num` cannot reduce these because the operations are on `H3Zorn`, not on
`ℝ`. To prove equalities like `e1 + e1 = 2 • e1`, use `ext_h3` and handle
scalar components with `norm_num` and vector components with
`simp [ZornVectorMatrix.zero, ZornVectorMatrix.add, ZornVectorMatrix.smul]`.
Do not rely on `rfl` or `decide` for these equalities.

## Mathematical Design Validation

**Verify the mathematical claim before proving it.** User correction: "random single shot pathing does not fix design flaws." If a theorem statement is mathematically false, no tactic sequence can prove it.

### Procedure

1. **State the claim precisely** — write the theorem in plain language: "parent rank ≤ child rank" or "rank index is injective"
2. **Check edge cases manually** — for taxonomy ranks, test `kingdom ≤ domain` (false), `domain ≤ species` (true)
3. **Only then write tactics** — once the claim is verified, design the proof structure
4. **Fix the statement if wrong** — if the claim is false, correct it (e.g., change `≤` to `≥`, or replace with `≠`/`comparability`)

### Pitfall: Brute-Force Tactic Thrashing

Random tactic substitution (`omega` → `decide` → `contradiction` → `cases`) on a false claim wastes cycles. The error "omega could not prove the goal" or "unsolved goals" after `simp` often means the goal is impossible, not that the tactic is weak. Stop, re-examine the theorem statement, and verify the claim on paper before editing tactics again.

## Inductive Type Equality Proofs

**Use `cases a; cases b` instead of `match a, b with` for inductive equalities.**

`match a, b with` does not reduce `a` and `b` in the motive, so Lean cannot synthesize the equation motive for dependent elimination. The result is "Dependent elimination failed" or "don't know how to synthesize implicit argument".

### Correct Pattern

```lean
theorem rankIndex_injective (a b : TaxonRank) : rankIndex a = rankIndex b → a = b := by
  intro h
  cases a
  case domain =>
    cases b
    case domain => rfl
    case kingdom => simp [rankIndex] at h; cases h
    -- ...
```

### Incorrect Pattern

```lean
-- FAILS: "Dependent elimination failed"
theorem rankIndex_injective (a b : TaxonRank) : rankIndex a = rankIndex b → a = b := by
  match a, b with
  | domain, domain => intro h; rfl
  | _, _ => intro h; simp [rankIndex] at h; cases h
```

## Arithmetic Tactic Limitations

**`omega` fails on non-arithmetic goals.** After `simp [f] at h`, if `h` reduces to `0 = 1`, the goal is `False`, not an arithmetic inequality. `omega` cannot prove `False` from `0 = 1` because it only handles linear arithmetic goals.

### Pattern for Impossible Equalities

```lean
| _, _ => intro h; simp [rankIndex] at h; cases h
```

`cases h` closes the goal when `h` is reduced to `0 = 1` by `simp`. Do not use `omega` or `decide` for this pattern.

## Prop-Valued Contradiction Patterns

**`h : P ≠ Q` is a `Prop`, not an inductive type.** `cases h` fails with "Tactic `cases` failed: major premise type is not an inductive type".

### Pattern for `Prop`-Valued Negation

```lean
h_nonempty : a.modulePaths ≠ []
⊢ False

-- CORRECT:
exact h_nonempty rfl

-- INCORRECT:
cases h_nonempty  -- fails: ≠ is not inductive
apply h_nonempty   -- fails: type mismatch
```

Ensure the argument type matches: `rfl` has type `x = x`, so `h_nonempty rfl` requires `a.modulePaths = []`. If the goal is `False`, use `exact False.elim (h_nonempty rfl)`.

## Import Placement Rule

**`import` must come before doc comments.** Lean rejects `import` after `/-! ... -/` blocks with "invalid 'import' command, it must be used in the beginning of the file".

```lean
-- CORRECT:
import Mathlib.Tactic

/-!
# Module docstring
-/

namespace Foo

-- INCORRECT:
/-!
# Module docstring
-/
import Mathlib.Tactic  -- ERROR
```

## List Membership After Rewriting

When proving `path ∈ b.modulePaths` after `rw [← h_paths]`, the goal becomes `path ∈ a.modulePaths`. Use `List.Mem.head _ _` directly:

```lean
rw [h_paths]
exact List.Mem.head _ _ _
```

If `List.Mem.head` fails with "could not unify the conclusion", check that the goal is exactly `List.Mem ?a (?a :: ?as)` after rewriting.

### Preserve Original Form with `cases h : x`

When pattern matching would lose the original term, use `cases h : x with` to keep both the pattern-match result and the original equation:

```lean
cases h : a.modulePaths with
| nil => exact h_nonempty h
| cons p ps => ...
```

Here `h : a.modulePaths = []` in the `nil` branch, allowing `exact h_nonempty h` to close the goal.

## Dependent Type Rewriting Issues

**When you encounter "motive is not type correct" or similar errors during rewriting:**

### The Problem

Rewriting a term `b` that appears in dependent types (like `hab : a <= b`) fails because the motive cannot abstract over the dependencies.

```lean
have hb : b = f x
rw [hb]  -- Error: motive is not type correct
```

### The Solution: Generalize First, Instantiate Last

Prove a generalized statement for an arbitrary parameter, then instantiate:

```lean
suffices forall s, statement_about s by
  have h_specific := the_equality_you_have
  convert this ?_ <;> exact h_specific
intro s
-- Now prove the general statement for arbitrary s
```

This works because the generalized statement has no dependencies on the problematic term, and `convert` handles the dependent type coercions at the end.

### Alternative: `generalize` tactic

When the above pattern is awkward, use `generalize` to abstract the problematic term:

```lean
generalize hb : b = x
-- b is now replaced by x everywhere, with hb : b = x
-- Prove the goal for x, then subst hb
```

## Verification Gates

### File-Level Gate

After editing a `.lean` file, verify it compiles:

```bash
lake env lean path/to/File.lean
```

Run this from the project root. It catches syntax and type errors faster than a full build.

### Module-Level Gate

After a batch of edits, build the minimal module target:

```bash
~/.elan/bin/lake build Module.Name
```

Use the project's locked wrapper if available:

```bash
python3 tools/infra/run_locked_lake_build.py --wait-for-build-lock Module.Name
```

### Project Gate

Before committing, run the full project build:

```bash
lake build
```

### Completion Criteria

A proof is complete only when ALL of these hold:

1. `lake build` passes (or the locked module build passes) with zero errors
2. Zero `sorry` placeholders remain in the agreed scope
3. Only standard axioms are used: `propext`, `Classical.choice`, `Quot.sound`
4. No theorem/lemma statements were changed without explicit permission
5. No witness/certificate/wrapper fields remain as substitutes for real proof
6. No debt markers (explicit `sorry`, `admit`, `axiom`) remain in the touched modules

**Never declare a proof complete while `sorry` placeholders, debt markers, or uncompiled code remain.** The build gate is necessary but not sufficient -- green builds can still carry explicit closure debt. Separate "build-green" from "native-closed" when reporting status.

## Automation Tactics Cascade

When stuck on a goal, try these in order (stop on first success):

`rfl` -> `simp` -> `ring` -> `linarith` -> `nlinarith` -> `omega` -> `exact?` -> `apply?` -> `grind` -> `aesop`

Note: `exact?`/`apply?` query mathlib (slow). `grind` and `aesop` are powerful but may timeout. For detailed tactic guidance, load the `lean4` skill and use its LSP tools (`lean_goal`, `lean_multi_attempt`, `lean_hammer_premise`).

## Stuck or Error Recovery

When a tactic or approach fails repeatedly:

1. **Step back** -- read the full goal state with `lean_goal(file, line)`
2. **Search mathlib** -- use `lean_local_search("keyword")` or `lean_leanfinder("goal query")` for relevant lemmas
3. **Change course** -- if rewriting fails, try `calc` blocks. If `simp` loops, try explicit `rw`. If a direct approach stalls, try an indirect lemma.
4. **Cut scope** -- replace the stuck proof with a clearly marked `sorry`, rebuild the rest of the file to verify it's structurally sound, then return to the blocker in isolation
5. **Escalate** -- load the `lean4` skill and use `/lean4:prove` or `/lean4:autoprove` for guided multi-cycle proving

Do not repeat the same failing command more than twice without changing the proof shape.

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in development →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.