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.Unique

45 declarations. Mathlib docs · Source

Types with a unique term

In this file we define a typeclass Unique, which expresses that a type has a unique term. In other words, a type that is Inhabited and a Subsingleton.

Main declaration

  • Unique: a typeclass that expresses that a type has a unique term.

Main statements

  • Unique.mk': an inhabited subsingleton type is Unique. This cannot be an instance because it would lead to loops in typeclass inference.

  • Function.Surjective.unique: if the domain of a surjective function is Unique, then its codomain is Unique as well.

  • Function.Injective.subsingleton: if the codomain of an injective function is Subsingleton, then its domain is Subsingleton as well.

  • Function.Injective.unique: if the codomain of an injective function is Subsingleton and its domain is Inhabited, then its domain is Unique.

Implementation notes

The typeclass Unique α is implemented as a type, rather than a Prop-valued predicate, for good definitional properties of the default term.

def Unique.ctorIdx E1 #

{α : Sort u} → Unique α → ℕ

class Unique E3 #

Sort u → Sort (max 1 u)

Unique α expresses that α is a type with a unique term default.

This is implemented as a type, rather than a Prop-valued predicate, for good definitional properties of the default term.

ctor Unique.mk E0 #

{α : Sort u} → (toInhabited : Inhabited α) → (∀ (a : α), a = default) → Unique α

abbrev Unique.toInhabited E1 #

{α : Sort u} → Unique α → Inhabited α

theorem Unique.uniq E1 #

∀ {α : Sort u} (self : Unique α) (a : α), a = default

In a Unique type, every term is equal to the default element (from Inhabited).

theorem unique_iff_existsUnique E1 #

∀ (α : Sort u), Nonempty (Unique α) ↔ ∃! x, True

theorem unique_subtype_iff_existsUnique E1 #

∀ {α : Sort u_1} (p : α → Prop), Nonempty (Unique (Subtype p)) ↔ ∃! a, p a

abbrev uniqueOfSubsingleton E1 #

{α : Sort u_1} → [Subsingleton α] → α → Unique α

Given an explicit a : α with Subsingleton α, we can construct a Unique α instance. This is a def because the typeclass search cannot arbitrarily invent the a : α term. Nevertheless, these instances are all equivalent by Unique.Subsingleton.unique.

See note [reducible non-instances].

instance PUnit.instUnique E0 #

Unique PUnit.{u}

theorem PUnit.default_eq_unit E0 #

default = PUnit.unit

def uniqueProp E1 #

{p : Prop} → p → Unique p

Every provable proposition is unique, as all proofs are equal.

instance instUniqueTrue E0 #

Unique True

instance Unique.instInhabited E0 #

{α : Sort u_1} → [Unique α] → Inhabited α

theorem Unique.default_eq E0 #

∀ {α : Sort u_1} [inst : Unique α] (a : α), default = a

instance Unique.instSubsingleton E0 #

∀ {α : Sort u_1} [Unique α], Subsingleton α

theorem Unique.forall_iff E0 #

∀ {α : Sort u_1} [inst : Unique α] {p : α → Prop}, (∀ (a : α), p a) ↔ p default

theorem Unique.exists_iff E0 #

∀ {α : Sort u_1} [inst : Unique α] {p : α → Prop}, Exists p ↔ p default

theorem Unique.subsingleton_unique' E1 #

∀ {α : Sort u_1} (h₁ h₂ : Unique α), h₁ = h₂

theorem Unique.subsingleton_unique'_iff E0 #

∀ {α : Sort u_1} {h₁ h₂ : Unique α}, h₁ = h₂ ↔ True

instance Unique.subsingleton_unique E0 #

∀ {α : Sort u_1}, Subsingleton (Unique α)

abbrev Unique.mk' E3 #

(α : Sort u) → [h₁ : Inhabited α] → [Subsingleton α] → Unique α

Construct Unique from Inhabited and Subsingleton. Making this an instance would create a loop in the class inheritance graph.

theorem nonempty_unique E1 #

∀ (α : Sort u) [Subsingleton α] [Nonempty α], Nonempty (Unique α)

theorem unique_iff_subsingleton_and_nonempty E1 #

∀ (α : Sort u), Nonempty (Unique α) ↔ Subsingleton α ∧ Nonempty α

theorem subsingleton_iff_isEmpty_or_unique E1 #

∀ (α : Sort u), Subsingleton α ↔ IsEmpty α ∨ Nonempty (Unique α)

theorem Pi.default_def E0 #

∀ {α : Sort u_1} {β : α → Sort v} [inst : (a : α) → Inhabited (β a)], default = fun a ↦ default

theorem Pi.default_apply E0 #

∀ {α : Sort u_1} {β : α → Sort v} [inst : (a : α) → Inhabited (β a)] (a : α), default a = default

instance Pi.unique E0 #

{α : Sort u_1} → {β : α → Sort v} → [(a : α) → Unique (β a)] → Unique ((a : α) → β a)

instance Pi.uniqueOfIsEmpty E0 #

{α : Sort u_1} → [IsEmpty α] → (β : α → Sort v) → Unique ((a : α) → β a)

There is a unique function on an empty domain.

theorem heq_const_of_unique E1 #

∀ {α : Sort u_1} [inst : Unique α] {β : α → Sort v} (f : (a : α) → β a), f ≍ Function.const α (f default)

theorem Function.Injective.subsingleton E3 #

∀ {α : Sort u_1} {β : Sort u_2} {f : α → β}, Function.Injective f → ∀ [Subsingleton β], Subsingleton α

If the codomain of an injective function is a subsingleton, then the domain is a subsingleton as well.

theorem Function.Surjective.subsingleton E1 #

∀ {α : Sort u_1} {β : Sort u_2} {f : α → β} [Subsingleton α], Function.Surjective f → Subsingleton β

If the domain of a surjective function is a subsingleton, then the codomain is a subsingleton as well.

def Function.Surjective.unique E3 #

{β : Sort u_2} → {α : Sort u} → (f : α → β) → Function.Surjective f → [Unique α] → Unique β

If the domain of a surjective function is a singleton, then the codomain is a singleton as well.

def Function.Injective.unique E3 #

{α : Sort u_1} → {β : Sort u_2} → {f : α → β} → [Inhabited α] → [Subsingleton β] → Function.Injective f → Unique α

If α is inhabited and admits an injective map to a subsingleton type, then α is Unique.

def Function.Surjective.uniqueOfSurjectiveConst E1 #

(α : Type u_3) → {β : Type u_4} → (b : β) → Function.Surjective (Function.const α b) → Unique β

If a constant function is surjective, then the codomain is a singleton.

def uniqueElim E1 #

{ι : Sort u_2} → {α : ι → Sort u_3} → [inst : Unique ι] → α default → (i : ι) → α i

Given one value over a unique, we get a dependent function.

theorem uniqueElim_default E0 #

∀ {ι : Sort u_2} {α : ι → Sort u_3} {x : Unique ι} (x_1 : α default), uniqueElim x_1 default = x_1

theorem uniqueElim_const E0 #

∀ {ι : Sort u_2} {β : Sort u_4} {x : Unique ι} (x_1 : β) (i : ι), uniqueElim x_1 i = x_1

theorem Unique.bijective E1 #

∀ {A : Sort u_2} {B : Sort u_3} [Unique A] [Unique B] {f : A → B}, Function.Bijective f

theorem Option.subsingleton_iff_isEmpty E1 #

∀ {α : Type u}, Subsingleton (Option α) ↔ IsEmpty α

Option α is a Subsingleton if and only if α is empty.

instance Option.instUniqueOfIsEmpty E0 #

{α : Type u_2} → [IsEmpty α] → Unique (Option α)

instance Unique.subtypeEq E0 #

{α : Sort u_1} → (y : α) → Unique { x // x = y }

instance Unique.subtypeEq' E0 #

{α : Sort u_1} → (y : α) → Unique { x // y = x }

theorem Subtype.coe_default_eq E0 #

∀ {α : Sort u_1} (y : α), ↑default = y

theorem Subtype.coe_default_eq' E0 #

∀ {α : Sort u_1} (y : α), ↑default = y

instance Fin.instUnique E0 #

Unique (Fin 1)