The Mathlib Handbook

The volumes of the handbook are not written yet. This site shows the map of Mathlib that they will follow, at Mathlib 4472534b60.

The areas / V34. The tactics of Mathlib

Mathlib.Tactic.CategoryTheory.Elementwise

5 declarations. Mathlib docs · Source

Tools to reformulate category-theoretic lemmas in concrete categories

The elementwise attribute

The elementwise attribute generates lemmas for concrete categories from lemmas that equate morphisms in a category.

A sort of inverse to this for the Type* category is the @[higher_order] attribute.

For more details, see the documentation attached to the syntax declaration.

Main definitions

  • The @[elementwise] attribute.

  • The elementwise_of% h term elaborator.

Implementation

This closely follows the implementation of the @[reassoc] attribute, due to Simon Hudon and reimplemented by Kim Morrison in Lean 4.

theorem Mathlib.Tactic.Elementwise.hom_elementwise E1 #

∀ {C : Type u_1} [inst : CategoryTheory.Category.{v_1, u_1} C] {FC : outParam (C → C → Type u_2)}
  {CC : outParam (C → Type u_3)} {x : outParam ((X Y : C) → FunLike (FC X Y) (CC X) (CC Y))}
  [inst_1 : CategoryTheory.ConcreteCategory C FC] {X Y : C} {f g : X ⟶ Y},
  f = g → ∀ (x_1 : CC X), (CategoryTheory.ConcreteCategory.hom f) x_1 = (CategoryTheory.ConcreteCategory.hom g) x_1

def Mathlib.Tactic.Elementwise.elementwiseThms E1 #

List Lean.Name

List of simp lemmas to apply to the elementwise theorem.

def Mathlib.Tactic.Elementwise.elementwiseExpr E1 #

Lean.Name → Lean.Expr → optParam Bool true → Lean.MetaM (Lean.Expr × Option (Lean.Level × Lean.Level))

Given an equation f = g between morphisms X ⟶ Y in a category C (possibly after a ∀ binder), produce the equation ∀ (x : X), f x = g x or ∀ FC CC _ [ConcreteCategory C FC] (x : X), f x = g x as needed (after the ∀ binder), but with compositions fully right associated and identities removed.

Returns the proof of the new theorem along with (optionally) a new level metavariable for the first universe parameter to ConcreteCategory.

The simpSides option controls whether to simplify both sides of the equality, for simpNF purposes.

def Mathlib.Tactic.Elementwise.elementwise E1 #

Lean.ParserDescr

The elementwise attribute can be added to a lemma proving an equation of morphisms, and it creates a new lemma for a ConcreteCategory giving an equation with those morphisms applied to some value.

Syntax examples:

  • @[elementwise]
  • @[elementwise nosimp] to not use simp on both sides of the generated lemma
  • @[elementwise (attr := simp)] to apply the simp attribute to both the generated lemma and the original lemma.

Example application of elementwise:

@[elementwise]
lemma some_lemma {C : Type*} [Category* C]
    {X Y Z : C} (f : X ⟶ Y) (g : Y ⟶ Z) (h : X ⟶ Z) (w : ...) : f ≫ g = h := ...

produces

lemma some_lemma_apply {C : Type*} [Category* C]
    {X Y Z : C} (f : X ⟶ Y) (g : Y ⟶ Z) (h : X ⟶ Z) (w : ...)
    {CC : ...} {FC : ...} [...] [ConcreteCategory C FC] (x : ToType X) : g (f x) = h x := ...

Here f, g, and h are being coerced to functions via CategoryTheory.ConcreteCategory.instCoeFunHomForallToType. Further, we simplify the type using CategoryTheory.coe_id : ((𝟙 X) : X → X) x = x and CategoryTheory.coe_comp : (f ≫ g) x = g (f x), replacing morphism composition with function composition.

The [ConcreteCategory C FC] and related arguments will be omitted if it is possible to synthesize an instance.

The name of the produced lemma can be specified with @[elementwise other_lemma_name]. If simp is added first, the generated lemma will also have the simp attribute.

def Mathlib.Tactic.Elementwise.«termElementwise_of%_» E1 #

Lean.ParserDescr

elementwise_of% h, where h is a proof of an equation f = g between morphisms X ⟶ Y in a concrete category (possibly after a ∀ binder), produces a proof of equation ∀ (x : X), f x = g x, but with compositions fully right associated and identities removed.

A typical example is using elementwise_of% to dynamically generate rewrite lemmas:

example (M N K : MonCat) (f : M ⟶ N) (g : N ⟶ K) (h : M ⟶ K) (w : f ≫ g = h) (m : M) :
    g (f m) = h m := by rw [elementwise_of% w]

In this case, elementwise_of% w generates the lemma ∀ (x : M), f (g x) = h x.

Like the @[elementwise] attribute, elementwise_of% inserts a ConcreteCategory instance argument if it can't synthesize a relevant ConcreteCategory instance. (Technical note: The forgetful functor's universe variable is instantiated with a fresh level metavariable in this case.)

One difference between elementwise_of% and @[elementwise] is that @[elementwise] by default applies simp to both sides of the generated lemma to get something that is in simp normal form. elementwise_of% does not do this.