lean-hit-development
Guides adding new Higher Inductive Types to the ComputationalPaths library. Use when creating new HITs, defining fundamental group (pi1) calculations, implementing encode-decode proofs, or adding new topological spaces.
When & Why to Use This Skill
This Claude skill acts as a specialized assistant for formal verification and mathematical modeling within the Lean 4 environment. It streamlines the implementation of Higher Inductive Types (HITs) for the ComputationalPaths library by providing structured templates for axiom declarations, recursion principles, and homotopy theory calculations. By automating boilerplate code for encode-decode proofs and fundamental group (π₁) equivalences, it ensures mathematical consistency and adherence to formal proof standards.
Use Cases
- 1. New HIT Implementation: Rapidly generating the necessary axiom blocks, point constructors, and path constructors for novel topological spaces in Lean 4.
- 2. Homotopy Theory Research: Facilitating the calculation of fundamental groups (π₁) and defining group presentations (words and relations) for complex mathematical structures.
- 3. Formal Verification Proofs: Guiding the implementation of encode-decode round-trip proofs to verify equivalences between paths and group elements.
- 4. Library Standardization: Ensuring all new contributions to the ComputationalPaths library follow the required module structure, import patterns, and naming conventions.
| name | lean-hit-development |
|---|---|
| description | Guides adding new Higher Inductive Types to the ComputationalPaths library. Use when creating new HITs, defining fundamental group (pi1) calculations, implementing encode-decode proofs, or adding new topological spaces. |
Higher Inductive Type Development
This skill guides the implementation of new Higher Inductive Types (HITs) in the ComputationalPaths Lean 4 library, following established patterns for axiom declarations, recursion principles, and fundamental group calculations.
File Location
New HITs go in ComputationalPaths/Path/HIT/YourHIT.lean
Required Module Structure
/-
# [HIT Name] Higher Inductive Type
Brief mathematical description of the space.
## Key Results
- `yourHITBase`: The base point constructor
- `yourHITLoop`: The path constructor(s)
- `piOneEquiv*`: π₁(YourHIT) ≃ [Group]
## Mathematical Background
[Explain the topology/homotopy theory]
## References
- [Cite relevant papers]
-/
import ComputationalPaths.Path.Homotopy.FundamentalGroup
import ComputationalPaths.Path.Rewrite.SimpleEquiv
-- other imports as needed
namespace ComputationalPaths
namespace Path.HIT
/-! ## Type and Constructor Axioms -/
axiom YourHIT : Type u
axiom yourHITBase : YourHIT
axiom yourHITLoop : Path yourHITBase yourHITBase -- or other path constructors
/-! ## Recursion Principle -/
axiom YourHIT.rec {β : Type v} (base : β) (loop : Path base base) : YourHIT → β
axiom YourHIT.rec_base : YourHIT.rec base loop yourHITBase = base
/-! ## Path Recursion (for encode) -/
axiom YourHIT.recPath {a : YourHIT} (P : YourHIT → Type)
(pbase : P yourHITBase)
(ploop : Path (transport P yourHITLoop pbase) pbase)
: (x : YourHIT) → P x
/-! ## Presentation Type -/
-- Define the group presentation
inductive YourGroupWord
| e : YourGroupWord -- identity
| gen : YourGroupWord -- generator(s)
| inv : YourGroupWord → YourGroupWord
| mul : YourGroupWord → YourGroupWord → YourGroupWord
inductive YourGroupRel : YourGroupWord → YourGroupWord → Prop
| inv_left : YourGroupRel (mul (inv w) w) e
| inv_right : YourGroupRel (mul w (inv w)) e
-- group-specific relations
def YourGroupPresentation := Quot YourGroupRel
/-! ## Encode-Decode -/
-- Decode: presentation → π₁
noncomputable def decode : YourGroupPresentation → π₁(YourHIT, yourHITBase) :=
Quot.lift
(fun w => wordToLoop w)
(fun _ _ h => Quot.sound (decode_respects_rel h))
-- Encode: π₁ → presentation (often needs axioms)
axiom encodePath : Path yourHITBase yourHITBase → YourGroupWord
axiom encodePath_respects_rweq : RwEq p q → YourGroupRel (encodePath p) (encodePath q)
noncomputable def encode : π₁(YourHIT, yourHITBase) → YourGroupPresentation :=
Quot.lift
(fun p => Quot.mk _ (encodePath p))
(fun _ _ h => Quot.sound (encodePath_respects_rweq h))
/-! ## Round-Trip Proofs -/
theorem decode_encode (α : π₁(YourHIT, yourHITBase)) : decode (encode α) = α := by
induction α using Quot.ind with
| _ p => exact Quot.sound (decode_encode_path p)
theorem encode_decode (x : YourGroupPresentation) : encode (decode x) = x := by
induction x using Quot.ind with
| _ w => exact Quot.sound (encode_decode_word w)
/-! ## Main Equivalence -/
noncomputable def piOneEquivYourGroup : SimpleEquiv (π₁(YourHIT, yourHITBase)) YourGroupPresentation where
toFun := encode
invFun := decode
left_inv := decode_encode
right_inv := encode_decode
/-! ## Summary -/
/-
This module establishes:
1. YourHIT as an axiomatized higher inductive type
2. π₁(YourHIT, yourHITBase) ≃ YourGroupPresentation
-/
end Path.HIT
end ComputationalPaths
Checklist for New HITs
- Define axioms for type and constructors
- Define recursion principle (non-dependent and dependent)
- Define computation rules (β-rules as axioms)
- Create group presentation type (words + relations)
- Implement decode (presentation → π₁)
- Implement encode (π₁ → presentation, may need axioms)
- Prove decode_respects_rel using RwEq lemmas
- Prove round-trip properties (decode_encode, encode_decode)
- Package as SimpleEquiv
- Add to imports in
ComputationalPaths/Path.lean - Update README with new result
Common HIT Patterns
Circle (S¹)
- One base point, one loop
- π₁(S¹) ≃ ℤ
Torus (T²)
- One base point, two loops (a, b) with
aba⁻¹b⁻¹ = refl - π₁(T²) ≃ ℤ × ℤ
Sphere (S²)
- One base point, one 2-cell (surface) filling a constant loop
- π₁(S²) ≃ 1 (trivial)
Wedge Sum (A ∨ B)
- Glue base points together
- π₁(A ∨ B) ≃ π₁(A) * π₁(B) (free product)
Orientable Surface (Σ_g)
- Genus g with 2g generators and surface relation
- π₁(Σ_g) ≃ ⟨a₁,b₁,...,a_g,b_g | [a₁,b₁]⋯[a_g,b_g] = 1⟩
Key Imports
import ComputationalPaths.Path.Basic.Core -- Path, refl, symm, trans
import ComputationalPaths.Path.Basic.Congruence -- congrArg, transport
import ComputationalPaths.Path.Rewrite.RwEq -- RwEq and lemmas
import ComputationalPaths.Path.Rewrite.SimpleEquiv -- SimpleEquiv structure
import ComputationalPaths.Path.Homotopy.FundamentalGroup -- π₁ notation
import ComputationalPaths.Path.Homotopy.Loops -- LoopSpace
Axiom Minimization
Only use axioms for:
- The HIT type itself
- Point constructors
- Path constructors
- Higher path constructors (2-cells, etc.)
- Recursion/elimination principles
- Computation rules (β-rules)
- Encode function (when not definable)
Everything else should be proved from these axioms.