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 / V01. The language of Mathlib

Mathlib.Basic.FunLike.Equiv

26 declarations. Mathlib docs · Source

Typeclass for a type F with an injective map to A ≃ B

This typeclass is primarily for use by isomorphisms like MonoidEquiv and LinearEquiv.

Basic usage of EquivLike

A typical type of isomorphisms should be declared as:

structure MyIso (A B : Type*) [MyClass A] [MyClass B] extends Equiv A B where
  (map_op' : ∀ (x y : A), toFun (MyClass.op x y) = MyClass.op (toFun x) (toFun y))

namespace MyIso

variable (A B : Type*) [MyClass A] [MyClass B]

@[macro_inline]
instance instEquivLike : EquivLike (MyIso A B) A B where
  coe f := f.toFun
  inv f := f.invFun
  left_inv f := f.left_inv
  right_inv f := f.right_inv
  coe_injective' f g h₁ h₂ := by cases f; cases g; congr; exact EquivLike.coe_injective' _ _ h₁ h₂

@[ext] theorem ext {f g : MyIso A B} (h : ∀ x, f x = g x) : f = g := DFunLike.ext f g h

/-- Copy of a `MyIso` with a new `toFun` equal to the old one. Useful to fix definitional
equalities. -/
protected def copy (f : MyIso A B) (f' : A → B) (f_inv : B → A)
    (h₁ : f' = f) (h₂ : f_inv = f.invFun) : MyIso A B where
  toFun := f'
  invFun := f_inv
  left_inv := h₁.symm ▸ h₂.symm ▸ f.left_inv
  right_inv := h₁.symm ▸ h₂.symm ▸ f.right_inv
  map_op' := h₁.symm ▸ f.map_op'

end MyIso

This file will then provide a CoeFun instance and various extensionality and simp lemmas.

Isomorphism classes extending EquivLike

The EquivLike design provides further benefits if you put in a bit more work. The first step is to extend EquivLike to create a class of those types satisfying the axioms of your new type of isomorphisms. Continuing the example above:

/-- `MyIsoClass F A B` states that `F` is a type of `MyClass.op`-preserving morphisms.
You should extend this class when you extend `MyIso`. -/
class MyIsoClass (F : Type*) (A B : outParam Type*) [MyClass A] [MyClass B]
    [EquivLike F A B]
    extends MyHomClass F A B

namespace MyIso

variable {A B : Type*} [MyClass A] [MyClass B]

-- This goes after `MyIsoClass.instEquivLike`:
instance : MyIsoClass (MyIso A B) A B where
  map_op := MyIso.map_op'

-- [Insert `ext` and `copy` here]

end MyIso

The second step is to add instances of your new MyIsoClass for all types extending MyIso. Typically, you can just declare a new class analogous to MyIsoClass:

structure CoolerIso (A B : Type*) [CoolClass A] [CoolClass B] extends MyIso A B where
  (map_cool' : toFun CoolClass.cool = CoolClass.cool)

class CoolerIsoClass (F : Type*) (A B : outParam Type*) [CoolClass A] [CoolClass B]
    [EquivLike F A B]
    extends MyIsoClass F A B where
  (map_cool : ∀ (f : F), f CoolClass.cool = CoolClass.cool)

@[simp] lemma map_cool {F A B : Type*} [CoolClass A] [CoolClass B]
    [EquivLike F A B] [CoolerIsoClass F A B] (f : F) :
    f CoolClass.cool = CoolClass.cool :=
  CoolerIsoClass.map_cool _

namespace CoolerIso

variable {A B : Type*} [CoolClass A] [CoolClass B]

@[macro_inline]
instance : EquivLike (CoolerIso A B) A B where
  coe f := f.toFun
  inv f := f.invFun
  left_inv f := f.left_inv
  right_inv f := f.right_inv
  coe_injective' f g h₁ h₂ := by cases f; cases g; congr; exact EquivLike.coe_injective' _ _ h₁ h₂

instance : CoolerIsoClass (CoolerIso A B) A B where
  map_op f := f.map_op'
  map_cool f := f.map_cool'

-- [Insert `ext` and `copy` here]

end CoolerIso

Then any declaration taking a specific type of morphisms as parameter can instead take the class you just defined:

-- Compare with: lemma do_something (f : MyIso A B) : sorry := sorry
lemma do_something {F : Type*} [EquivLike F A B] [MyIsoClass F A B] (f : F) : sorry := sorry

This means anything set up for MyIsos will automatically work for CoolerIsoClasses, and defining CoolerIsoClass only takes a constant amount of effort, instead of linearly increasing the work per MyIso-related declaration.

def EquivLike.ctorIdx E1 #

{E : Sort u_1} → {α : outParam (Sort u_2)} → {β : outParam (Sort u_3)} → EquivLike E α β → ℕ

class EquivLike E1 #

Sort u_1 → outParam (Sort u_2) → outParam (Sort u_3) → Sort (max (max (max 1 u_1) u_2) u_3)

The class EquivLike E α β expresses that terms of type E have an injective coercion to bijections between α and β.

Note that this does not directly extend FunLike, nor take FunLike as a parameter, so we can state coe_injective' in a nicer way.

This typeclass is used in the definition of the isomorphism (or equivalence) typeclasses, such as ZeroEquivClass, MulEquivClass, MonoidEquivClass, ....

ctor EquivLike.mk E0 #

{E : Sort u_1} →
  {α : outParam (Sort u_2)} →
    {β : outParam (Sort u_3)} →
      (coe : E → α → β) →
        (inv : E → β → α) →
          (∀ (e : E), Function.LeftInverse (inv e) (coe e)) →
            (∀ (e : E), Function.RightInverse (inv e) (coe e)) →
              (∀ (e g : E), coe e = coe g → inv e = inv g → e = g) → EquivLike E α β

abbrev EquivLike.coe E1 #

{E : Sort u_1} → {α : outParam (Sort u_2)} → {β : outParam (Sort u_3)} → [self : EquivLike E α β] → E → α → β

The coercion to a function in the forward direction.

abbrev EquivLike.inv E1 #

{E : Sort u_1} → {α : outParam (Sort u_2)} → {β : outParam (Sort u_3)} → [self : EquivLike E α β] → E → β → α

The coercion to a function in the backwards direction.

theorem EquivLike.left_inv E1 #

∀ {E : Sort u_1} {α : outParam (Sort u_2)} {β : outParam (Sort u_3)} [self : EquivLike E α β] (e : E),
  Function.LeftInverse (EquivLike.inv e) (EquivLike.coe e)

The coercions are left inverses.

theorem EquivLike.right_inv E1 #

∀ {E : Sort u_1} {α : outParam (Sort u_2)} {β : outParam (Sort u_3)} [self : EquivLike E α β] (e : E),
  Function.RightInverse (EquivLike.inv e) (EquivLike.coe e)

The coercions are right inverses.

theorem EquivLike.coe_injective' E0 #

∀ {E : Sort u_1} {α : outParam (Sort u_2)} {β : outParam (Sort u_3)} [self : EquivLike E α β] (e g : E),
  EquivLike.coe e = EquivLike.coe g → EquivLike.inv e = EquivLike.inv g → e = g

The two coercions to functions are jointly injective.

theorem EquivLike.inv_injective E1 #

∀ {E : Sort u_1} {α : Sort u_3} {β : Sort u_4} [inst : EquivLike E α β], Function.Injective EquivLike.inv

instance EquivLike.toFunLike E0 #

{E : Sort u_1} → {α : Sort u_3} → {β : Sort u_4} → [EquivLike E α β] → FunLike E α β

theorem EquivLike.coe_apply E0 #

∀ {E : Sort u_1} {α : Sort u_3} {β : Sort u_4} [inst : EquivLike E α β] {e : E} {a : α}, EquivLike.coe e a = e a

theorem EquivLike.inv_apply_eq E0 #

∀ {E : Sort u_1} {α : Sort u_3} {β : Sort u_4} [inst : EquivLike E α β] {e : E} {b : β} {a : α},
  EquivLike.inv e b = a ↔ b = e a

instance EquivLike.toEmbeddingLike E0 #

∀ {E : Sort u_1} {α : Sort u_3} {β : Sort u_4} [inst : EquivLike E α β], EmbeddingLike E α β

theorem EquivLike.injective E1 #

∀ {E : Sort u_1} {α : Sort u_3} {β : Sort u_4} [inst : EquivLike E α β] (e : E), Function.Injective ⇑e

theorem EquivLike.surjective E1 #

∀ {E : Sort u_1} {α : Sort u_3} {β : Sort u_4} [inst : EquivLike E α β] (e : E), Function.Surjective ⇑e

theorem EquivLike.bijective E1 #

∀ {E : Sort u_1} {α : Sort u_3} {β : Sort u_4} [inst : EquivLike E α β] (e : E), Function.Bijective ⇑e

theorem EquivLike.apply_eq_iff_eq E0 #

∀ {E : Sort u_1} {α : Sort u_3} {β : Sort u_4} [inst : EquivLike E α β] (f : E) {x y : α}, f x = f y ↔ x = y

theorem EquivLike.injective_comp E0 #

∀ {E : Sort u_1} {α : Sort u_3} {β : Sort u_4} {γ : Sort u_5} [inst : EquivLike E α β] (e : E) (f : β → γ),
  Function.Injective (f ∘ ⇑e) ↔ Function.Injective f

theorem EquivLike.surjective_comp E0 #

∀ {E : Sort u_1} {α : Sort u_3} {β : Sort u_4} {γ : Sort u_5} [inst : EquivLike E α β] (e : E) (f : β → γ),
  Function.Surjective (f ∘ ⇑e) ↔ Function.Surjective f

theorem EquivLike.bijective_comp E0 #

∀ {E : Sort u_1} {α : Sort u_3} {β : Sort u_4} {γ : Sort u_5} [inst : EquivLike E α β] (e : E) (f : β → γ),
  Function.Bijective (f ∘ ⇑e) ↔ Function.Bijective f

theorem EquivLike.inv_apply_apply E0 #

∀ {E : Sort u_1} {α : Sort u_3} {β : Sort u_4} [inst : EquivLike E α β] (e : E) (a : α), EquivLike.inv e (e a) = a

This lemma is only supposed to be used in the generic context, when working with instances of classes extending EquivLike. For concrete isomorphism types such as Equiv, you should use Equiv.symm_apply_apply or its equivalent.

TODO: define a generic form of Equiv.symm.

theorem EquivLike.apply_inv_apply E0 #

∀ {E : Sort u_1} {α : Sort u_3} {β : Sort u_4} [inst : EquivLike E α β] (e : E) (b : β), e (EquivLike.inv e b) = b

This lemma is only supposed to be used in the generic context, when working with instances of classes extending EquivLike. For concrete isomorphism types such as Equiv, you should use Equiv.apply_symm_apply or its equivalent.

TODO: define a generic form of Equiv.symm.

theorem EquivLike.comp_injective E1 #

∀ {F : Sort u_2} {α : Sort u_3} {β : Sort u_4} {γ : Sort u_5} [inst : EquivLike F β γ] (f : α → β) (e : F),
  Function.Injective (⇑e ∘ f) ↔ Function.Injective f

theorem EquivLike.comp_surjective E0 #

∀ {F : Sort u_2} {α : Sort u_3} {β : Sort u_4} {γ : Sort u_5} [inst : EquivLike F β γ] (f : α → β) (e : F),
  Function.Surjective (⇑e ∘ f) ↔ Function.Surjective f

theorem EquivLike.comp_bijective E0 #

∀ {F : Sort u_2} {α : Sort u_3} {β : Sort u_4} {γ : Sort u_5} [inst : EquivLike F β γ] (f : α → β) (e : F),
  Function.Bijective (⇑e ∘ f) ↔ Function.Bijective f

theorem EquivLike.subsingleton_dom E1 #

∀ {E : Sort u_1} {α : Sort u_3} {β : Sort u_4} [EquivLike E α β] [Subsingleton α], Subsingleton E

This is not an instance to avoid slowing down every single Subsingleton typeclass search.