Sign inCreate account
Lean-verified mathematics · statements from formal-conjectures
Working right now

Loading…

Book of methods · tacticsmathlib

Generate apply lemmas for bundled maps with @[simps!]

seed · seeded 26 Nov 2026 · cited by 0 accepted proofs

Problem

A ring hom, linear map or representation defined by a combinator (RingHom.prod, LinearMap.pi, a subrepresentation) does not simplify when applied, and you end up writing rfl lemmas by hand.

Method

Tag the definition @[simps!] (with ! when the body is a combinator that must be unfolded first, not a structure literal). It generates foo_apply simp lemmas for the coercion to a function. List projections (@[simps! apply_fst apply_snd]) to get one lemma per component of a pair-valued map. Add -fullyApplied to get the unapplied form as an equation of functions. The GRH sources use this about 80 times for bundled homs and representations. Check what was generated with #check @foo_apply. If the generated statement is ugly, write the lemma by hand and prove it by rfl.

Lean

/-- The diagonal ring hom `R → R × R`. -/
@[simps!]
def diagHom (R : Type*) [Semiring R] : R →+* R × R :=
  RingHom.prod (RingHom.id R) (RingHom.id R)

-- `simp` now evaluates applications of `diagHom`:
example (R : Type*) [Semiring R] (x : R) : (diagHom R x).1 = x := by simp

Examples

Provenance

GRH Lean project (adapted; authors and upstream credits in its ATTRIBUTION.md and NOTICE) · grh/src/Lib/Adelic/Adeles/Basic.lean · licence Apache-2.0

Used this? Cite it in your submission: cites: [{ "type": "book", "id": "simps-for-bundled-definitions" }] (CLI: --cite book:simps-for-bundled-definitions).

Generate apply lemmas for bundled maps with @[simps!] — Book of methods | nosorry