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 / V03. Sets, finite structures and big operators

Mathlib.Data.FinEnum.Option

6 declarations. Mathlib docs · Source

FinEnum instance for Option

Provides a recursor for FinEnum types like Fintype.truncRecEmptyOption, but capable of producing non-truncated data.

TODO

  • recreate rest of Mathlib/Data/Fintype/Option.lean

def FinEnum.insertNone E1 #

(α : Type u) → [inst : FinEnum α] → Fin (FinEnum.card α + 1) → FinEnum (Option α)

Inserting an Option.none anywhere in an enumeration yields another enumeration.

instance FinEnum.instFinEnumOptionLast E0 #

(α : Type u) → [FinEnum α] → FinEnum (Option α)

This is an arbitrary choice of insertion rank for a default instance. It keeps the mapping of the existing α-inhabitants intact, modulo Fin.castSucc.

def FinEnum.recEmptyOption E1 #

{P : Type u → Sort v} →
  ((n : ℕ) → Fin (n + 1)) →
    ({α β : Type u} → (x : FinEnum α) → (x_1 : FinEnum β) → FinEnum.card β = FinEnum.card α → P α → P β) →
      P PEmpty.{u + 1} → ({α : Type u} → FinEnum α → P α → P (Option α)) → (α : Type u) → [FinEnum α] → P α

A recursor principle for finite-and-enumerable types, analogous to Nat.rec. It effectively says that every FinEnum is either Empty or Option α, up to an Equiv mediated by Fins of equal cardinality. In contrast to the Fintype case, data can be transported along such an Equiv. Also, since order matters, the choice of element that gets replaced by Option.none has to be provided for every step.

Since every FinEnum instance implies a Fintype instance and Prop is squashed already, Fintype.induction_empty_option can be used if a Prop needs to be constructed. Cf. Data.Fintype.Option

theorem FinEnum.recEmptyOption_of_card_eq_zero E1 #

∀ {P : Type u → Sort v} (finChoice : (n : ℕ) → Fin (n + 1))
  (congr : {α β : Type u} → (x : FinEnum α) → (x_1 : FinEnum β) → FinEnum.card β = FinEnum.card α → P α → P β)
  (empty : P PEmpty.{u + 1}) (option : {α : Type u} → FinEnum α → P α → P (Option α)) (α : Type u) [inst : FinEnum α]
  (h : FinEnum.card α = 0) (x : FinEnum PEmpty.{u + 1}),
  FinEnum.recEmptyOption finChoice (fun {α β} ↦ congr) empty (fun {α} ↦ option) α = congr x inst ⋯ empty

For an empty type, the recursion principle evaluates to whatever congr makes of the base case.

theorem FinEnum.recEmptyOption_of_card_pos E1 #

∀ {P : Type u → Sort v} (finChoice : (n : ℕ) → Fin (n + 1))
  (congr : {α β : Type u} → (x : FinEnum α) → (x_1 : FinEnum β) → FinEnum.card β = FinEnum.card α → P α → P β)
  (empty : P PEmpty.{u + 1}) (option : {α : Type u} → FinEnum α → P α → P (Option α)) (α : Type u) [inst : FinEnum α]
  (h : 0 < FinEnum.card α),
  FinEnum.recEmptyOption finChoice (fun {α β} ↦ congr) empty (fun {α} ↦ option) α =
    congr (FinEnum.insertNone (ULift.{u, 0} (Fin (FinEnum.card α - 1))) ↑↑(finChoice (FinEnum.card α - 1))) inst ⋯
      (option ULift.instFinEnum
        (FinEnum.recEmptyOption finChoice (fun {α β} ↦ congr) empty (fun {α} ↦ option)
          (ULift.{u, 0} (Fin (FinEnum.card α - 1)))))

For a type with positive card, the recursion principle evaluates to whatever congr makes of the step result, where Option.none has been inserted into the (finChoice (card α - 1))th rank of the enumeration.

abbrev FinEnum.recOnEmptyOption E1 #

{P : Type u → Sort v} →
  {α : Type u} →
    FinEnum α →
      ((n : ℕ) → Fin (n + 1)) →
        ({α β : Type u} → (x : FinEnum α) → (x_1 : FinEnum β) → FinEnum.card β = FinEnum.card α → P α → P β) →
          P PEmpty.{u + 1} → ({α : Type u} → FinEnum α → P α → P (Option α)) → P α

A recursor principle for finite-and-enumerable types, analogous to Nat.recOn. It effectively says that every FinEnum is either Empty or Option α, up to an Equiv mediated by Fins of equal cardinality. In contrast to the Fintype case, data can be transported along such an Equiv. Also, since order matters, the choice of element that gets replaced by Option.none has to be provided for every step.