Equivalence between types #
In this file we define two types:
-
equiv α β
a.k.a.α ≃ β
: a bijective mapα → β
bundled with its inverse map; we use this (and not equality!) to express that variousType
s orSort
s are equivalent. -
equiv.perm α
: the group of permutationsα ≃ α
. More lemmas aboutequiv.perm
can be found ingroup_theory/perm
.
Then we define
-
canonical isomorphisms between various types: e.g.,
-
equiv.refl α
is the identity map interpreted asα ≃ α
; -
equiv.sum_equiv_sigma_bool
is the canonical equivalence between the sum of two typesα ⊕ β
and the sigma-typeΣ b : bool, cond b α β
; -
equiv.prod_sum_distrib : α × (β ⊕ γ) ≃ (α × β) ⊕ (α × γ)
shows that type product and type sum satisfy the distributive law up to a canonical equivalence;
-
-
operations on equivalences: e.g.,
-
equiv.symm e : β ≃ α
is the inverse ofe : α ≃ β
; -
equiv.trans e₁ e₂ : α ≃ γ
is the composition ofe₁ : α ≃ β
ande₂ : β ≃ γ
(note the order of the arguments!); -
equiv.prod_congr ea eb : α₁ × β₁ ≃ α₂ × β₂
: combine two equivalencesea : α₁ ≃ α₂
andeb : β₁ ≃ β₂
usingprod.map
.
-
-
definitions that transfer some instances along an equivalence. By convention, we transfer instances from right to left.
equiv.inhabited
takese : α ≃ β
and[inhabited β]
and returnsinhabited α
;equiv.unique
takese : α ≃ β
and[unique β]
and returnsunique α
;equiv.decidable_eq
takese : α ≃ β
and[decidable_eq β]
and returnsdecidable_eq α
.
More definitions of this kind can be found in other files. E.g.,
data/equiv/transfer_instance
does it for many algebraic type classes likegroup
,module
, etc.
Tags #
equivalence, congruence, bijective map
- to_fun : α → β
- inv_fun : β → α
- left_inv : function.left_inverse self.inv_fun self.to_fun
- right_inv : function.right_inverse self.inv_fun self.to_fun
α ≃ β
is the type of functions from α → β
with a two-sided inverse.
perm α
is the type of bijections from α
to itself.
Equations
- equiv.perm α = (α ≃ α)
Equations
- equiv.equiv_like = {coe := equiv.to_fun β, inv := equiv.inv_fun β, left_inv := _, right_inv := _, coe_injective' := _}
Equations
The map coe_fn : (r ≃ s) → (r → s)
is injective.
Equations
- equiv.inhabited' = {default := equiv.refl α}
See Note [custom simps projection]
Equations
- equiv.simps.symm_apply e = ⇑(e.symm)
Equations
If α
is equivalent to β
and γ
is equivalent to δ
, then the type of equivalences α ≃ γ
is equivalent to the type of equivalences β ≃ δ
.
If α
is equivalent to β
, then perm α
is equivalent to perm β
.
Equations
- e.perm_congr = e.equiv_congr e
α
is equivalent to an empty type iff α
is empty.
Equations
- equiv.equiv_empty_equiv α = {to_fun := _, inv_fun := equiv.equiv_empty α, left_inv := _, right_inv := _}
Equations
If α
is an empty type, then it is equivalent to the pempty
type in any universe.
pempty
types from any two universes are equivalent.
Equations
Equations
ulift α
is equivalent to α
.
Equations
- equiv.ulift = {to_fun := ulift.down α, inv_fun := ulift.up α, left_inv := _, right_inv := _}
plift α
is equivalent to α
.
Equations
- equiv.plift = {to_fun := plift.down α, inv_fun := plift.up α, left_inv := _, right_inv := _}
If α₁
is equivalent to α₂
and β₁
is equivalent to β₂
, then the type of maps α₁ → β₁
is equivalent to the type of maps α₂ → β₂
.
A version of equiv.arrow_congr
in Type
, rather than Sort
.
The equiv_rw
tactic is not able to use the default Sort
level equiv.arrow_congr
,
because Lean's universe rules will not unify ?l_1
with imax (1 ?m_1)
.
Equations
- hα.arrow_congr' hβ = hα.arrow_congr hβ
Conjugate a map f : α → α
by an equivalence α ≃ β
.
Equations
- e.conj = e.arrow_congr e
punit
sorts in any two universes are equivalent.
Equations
- equiv.punit_equiv_punit = {to_fun := λ (_x : punit), punit.star, inv_fun := λ (_x : punit), punit.star, left_inv := equiv.punit_equiv_punit._proof_1, right_inv := equiv.punit_equiv_punit._proof_2}
The sort of maps to punit.{v}
is equivalent to punit.{w}
.
Equations
- equiv.arrow_punit_equiv_punit α = {to_fun := λ (f : α → punit), punit.star, inv_fun := λ (u : punit) (f : α), punit.star, left_inv := _, right_inv := _}
If α
is subsingleton
and a : α
, then the type of dependent functions Π (i : α), β i
is equivalent to β i
.
Equations
- equiv.Pi_subsingleton β a = {to_fun := function.eval a, inv_fun := λ (x : β a) (b : α), cast _ x, left_inv := _, right_inv := _}
If α
has a unique term, then the type of function α → β
is equivalent to β
.
Equations
- equiv.fun_unique α β = equiv.Pi_subsingleton (λ (ᾰ : α), β) default
The sort of maps from punit
is equivalent to the codomain.
Equations
The sort of maps from true
is equivalent to the codomain.
Equations
The sort of maps from a type that is_empty
is equivalent to punit
.
Equations
- equiv.arrow_punit_of_is_empty α β = {to_fun := λ (f : α → β), punit.star, inv_fun := λ (u : punit), is_empty_elim, left_inv := _, right_inv := _}
Product of two equivalences. If α₁ ≃ α₂
and β₁ ≃ β₂
, then α₁ × β₁ ≃ α₂ × β₂
.
Type product is associative up to an equivalence.
Functions on α × β
are equivalent to functions α → β → γ
.
Equations
- equiv.curry α β γ = {to_fun := function.curry γ, inv_fun := function.uncurry γ, left_inv := _, right_inv := _}
punit
is a left identity for type product up to an equivalence.
Equations
- equiv.punit_prod α = (equiv.prod_comm punit α).trans (equiv.prod_punit α)
empty
type is a right absorbing element for type product up to an equivalence.
Equations
- equiv.prod_empty α = equiv.equiv_empty (α × empty)
empty
type is a left absorbing element for type product up to an equivalence.
Equations
- equiv.empty_prod α = equiv.equiv_empty (empty × α)
pempty
type is a right absorbing element for type product up to an equivalence.
Equations
pempty
type is a left absorbing element for type product up to an equivalence.
Equations
If α ≃ α'
and β ≃ β'
, then α ⊕ β ≃ α' ⊕ β'
.
Combine a permutation of α
and of β
into a permutation of α ⊕ β
.
Equations
- ea.sum_congr eb = equiv.sum_congr ea eb
bool
is equivalent the sum of two punit
s.
Equations
- equiv.bool_equiv_punit_sum_punit = {to_fun := λ (b : bool), cond b (sum.inr punit.star) (sum.inl punit.star), inv_fun := λ (s : punit ⊕ punit), s.rec_on (λ (_x : punit), ff) (λ (_x : punit), tt), left_inv := equiv.bool_equiv_punit_sum_punit._proof_1, right_inv := equiv.bool_equiv_punit_sum_punit._proof_2}
Sum of types is associative up to an equivalence.
The sum of empty
with any Sort*
is equivalent to the right summand.
Equations
- equiv.empty_sum α β = (equiv.sum_comm α β).trans (equiv.sum_empty β α)
The set of x : option α
such that is_some x
is equivalent to α
.
The product over option α
of β a
is the binary product of the
product over α
of β (some α)
and β none
α ⊕ β
is equivalent to a sigma
-type over bool
. Note that this definition assumes α
and
β
to be types from the same universe, so it cannot by used directly to transfer theorems about
sigma types to theorems about sum types. In many cases one can use ulift
to work around this
difficulty.
Equations
- equiv.sum_equiv_sigma_bool α β = {to_fun := λ (s : α ⊕ β), sum.elim (λ (x : α), ⟨tt, x⟩) (λ (x : β), ⟨ff, x⟩) s, inv_fun := λ (s : Σ (b : bool), cond b α β), equiv.sum_equiv_sigma_bool._match_1 α β s, left_inv := _, right_inv := _}
- equiv.sum_equiv_sigma_bool._match_1 α β ⟨tt, a⟩ = sum.inl a
- equiv.sum_equiv_sigma_bool._match_1 α β ⟨ff, b⟩ = sum.inr b
sigma_preimage_equiv f
for f : α → β
is the natural equivalence between
the type of all fibres of f
and the total space α
.
For any predicate p
on α
,
the sum of the two subtypes {a // p a}
and its complement {a // ¬ p a}
is naturally equivalent to α
.
See subtype_or_equiv
for sum types over subtypes {x // p x}
and {x // q x}
that are not necessarily is_compl p q
.
Combines an equiv
between two subtypes with an equiv
between their complements to form a
permutation.
Equations
- e.subtype_congr f = (equiv.sum_compl p).symm.trans ((e.sum_congr f).trans (equiv.sum_compl q))
Combining permutations on ε
that permute only inside or outside the subtype
split induced by p : ε → Prop
constructs a permutation on ε
.
Equations
- ep.subtype_congr en = ⇑((equiv.sum_compl p).perm_congr) (equiv.sum_congr ep en)
For a fixed function x₀ : {a // p a} → β
defined on a subtype of α
,
the subtype of functions x : α → β
that agree with x₀
on the subtype {a // p a}
is naturally equivalent to the type of functions {a // ¬ p a} → β
.
A family of equivalences Π a, β₁ a ≃ β₂ a
generates an equivalence between Π a, β₁ a
and
Π a, β₂ a
.
Dependent curry
equivalence: the type of dependent functions on Σ i, β i
is equivalent
to the type of dependent functions of two arguments (i.e., functions to the space of functions).
This is sigma.curry
and sigma.uncurry
together as an equiv.
Equations
- equiv.Pi_curry γ = {to_fun := sigma.curry γ, inv_fun := sigma.uncurry (λ (a : α) (b : β a), γ a b), left_inv := _, right_inv := _}
A family of equivalences Π a, β₁ a ≃ β₂ a
generates an equivalence between Σ' a, β₁ a
and
Σ' a, β₂ a
.
A family of equivalences Π a, β₁ a ≃ β₂ a
generates an equivalence between Σ a, β₁ a
and
Σ a, β₂ a
.
A psigma
with Prop
fibers is equivalent to the subtype.
A sigma
with plift
fibers is equivalent to the subtype.
Equations
- equiv.sigma_plift_equiv_subtype P = ((equiv.psigma_equiv_sigma (λ (i : α), plift (P i))).symm.trans (equiv.psigma_congr_right (λ (a : α), equiv.plift))).trans (equiv.psigma_equiv_subtype P)
A sigma
with λ i, ulift (plift (P i))
fibers is equivalent to { x // P x }
.
Variant of sigma_plift_equiv_subtype
.
Equations
A family of permutations Π a, perm (β a)
generates a permuation perm (Σ a, β₁ a)
.
Equations
An equivalence f : α₁ ≃ α₂
generates an equivalence between Σ a, β (f a)
and Σ a, β a
.
Transporting a sigma type through an equivalence of the base
Equations
Transporting a sigma type through an equivalence of the base and a family of equivalences of matching fibers
Equations
- f.sigma_congr F = (equiv.sigma_congr_right F).trans f.sigma_congr_left
sigma
type with a constant fiber is equivalent to the product.
If each fiber of a sigma
type is equivalent to a fixed type, then the sigma type
is equivalent to the product.
Equations
Dependent product of types is associative up to an equivalence.
A family of equivalences Π (a : α₁), β₁ ≃ β₂
generates an equivalence
between β₁ × α₁
and β₂ × α₁
.
A family of equivalences Π (a : α₁), β₁ ≃ β₂
generates an equivalence
between α₁ × β₁
and α₁ × β₂
.
A variation on equiv.prod_congr
where the equivalence in the second component can depend
on the first component. A typical example is a shear mapping, explaining the name of this
declaration.
prod_extend_right a e
extends e : perm β
to perm (α × β)
by sending (a, b)
to
(a, e b)
and keeping the other (a', b)
fixed.
The type of functions to a product α × β
is equivalent to the type of pairs of functions
γ → α
and γ → β
.
The type of functions on a sum type α ⊕ β
is equivalent to the type of pairs of functions
on α
and on β
.
Type product is right distributive with respect to type sum up to an equivalence.
Equations
- equiv.sum_prod_distrib α β γ = {to_fun := λ (p : (α ⊕ β) × γ), equiv.sum_prod_distrib._match_1 α β γ p, inv_fun := λ (s : α × γ ⊕ β × γ), equiv.sum_prod_distrib._match_2 α β γ s, left_inv := _, right_inv := _}
- equiv.sum_prod_distrib._match_1 α β γ (sum.inr b, c) = sum.inr (b, c)
- equiv.sum_prod_distrib._match_1 α β γ (sum.inl a, c) = sum.inl (a, c)
- equiv.sum_prod_distrib._match_2 α β γ (sum.inr q) = (sum.inr q.fst, q.snd)
- equiv.sum_prod_distrib._match_2 α β γ (sum.inl q) = (sum.inl q.fst, q.snd)
Type product is left distributive with respect to type sum up to an equivalence.
Equations
- equiv.prod_sum_distrib α β γ = ((equiv.prod_comm α (β ⊕ γ)).trans (equiv.sum_prod_distrib β γ α)).trans ((equiv.prod_comm β α).sum_congr (equiv.prod_comm γ α))
The product of an indexed sum of types (formally, a sigma
-type Σ i, α i
) by a type β
is
equivalent to the sum of products Σ i, (α i × β)
.
The product bool × α
is equivalent to α ⊕ α
.
Equations
The set of natural numbers is equivalent to ℕ ⊕ punit
.
Equations
- equiv.nat_equiv_nat_sum_punit = {to_fun := λ (n : ℕ), equiv.nat_equiv_nat_sum_punit._match_1 n, inv_fun := λ (s : ℕ ⊕ punit), equiv.nat_equiv_nat_sum_punit._match_2 s, left_inv := equiv.nat_equiv_nat_sum_punit._proof_1, right_inv := equiv.nat_equiv_nat_sum_punit._proof_2}
- equiv.nat_equiv_nat_sum_punit._match_1 a.succ = sum.inl a
- equiv.nat_equiv_nat_sum_punit._match_1 0 = sum.inr punit.star
- equiv.nat_equiv_nat_sum_punit._match_2 (sum.inr punit.star) = 0
- equiv.nat_equiv_nat_sum_punit._match_2 (sum.inl n) = n.succ
ℕ ⊕ punit
is equivalent to ℕ
.
The type of integer numbers is equivalent to ℕ ⊕ ℕ
.
Equations
If α
is equivalent to β
and the predicates p : α → Prop
and q : β → Prop
are equivalent
at corresponding points, then {a // p a}
is equivalent to {b // q b}
.
For the statement where α = β
, that is, e : perm α
, see perm.subtype_perm
.
If two predicates p
and q
are pointwise equivalent, then {x // p x}
is equivalent to
{x // q x}
.
Equations
If α ≃ β
, then for any predicate p : β → Prop
the subtype {a // p (e a)}
is equivalent
to the subtype {b // p b}
.
Equations
If α ≃ β
, then for any predicate p : α → Prop
the subtype {a // p a}
is equivalent
to the subtype {b // p (e.symm b)}
. This version is used by equiv_rw
.
Equations
If two predicates are equal, then the corresponding subtypes are equivalent.
Equations
A subtype of a subtype is equivalent to the subtype of elements satisfying both predicates. This
version allows the “inner” predicate to depend on h : p a
.
Equations
- equiv.subtype_subtype_equiv_subtype_exists p q = {to_fun := λ (_x : subtype q), equiv.subtype_subtype_equiv_subtype_exists._match_1 p q _x, inv_fun := λ (_x : {a // ∃ (h : p a), q ⟨a, h⟩}), equiv.subtype_subtype_equiv_subtype_exists._match_2 p q _x, left_inv := _, right_inv := _}
- equiv.subtype_subtype_equiv_subtype_exists._match_1 p q ⟨⟨a, ha⟩, ha'⟩ = ⟨a, _⟩
- equiv.subtype_subtype_equiv_subtype_exists._match_2 p q ⟨a, ha⟩ = ⟨⟨a, _⟩, _⟩
A subtype of a subtype is equivalent to the subtype of elements satisfying both predicates.
Equations
- equiv.subtype_subtype_equiv_subtype_inter p q = (equiv.subtype_subtype_equiv_subtype_exists p (λ (x : subtype p), q x.val)).trans (equiv.subtype_equiv_right _)
If the outer subtype has more restrictive predicate than the inner one, then we can drop the latter.
If a proposition holds for all elements, then the subtype is equivalent to the original type.
A subtype of a sigma-type is a sigma-type over a subtype.
A sigma type over a subtype is equivalent to the sigma set over the original type, if the fiber is empty outside of the subset
Equations
If a predicate p : β → Prop
is true on the range of a map f : α → β
, then
Σ y : {y // p y}, {x // f x = y}
is equivalent to α
.
Equations
- equiv.sigma_subtype_preimage_equiv f p h = (equiv.sigma_subtype_equiv_of_subset (λ (y : β), {x // f x = y}) p _).trans (equiv.sigma_preimage_equiv f)
If for each x
we have p x ↔ q (f x)
, then Σ y : {y // q y}, f ⁻¹' {y}
is equivalent
to {x // p x}
.
Equations
- equiv.sigma_subtype_preimage_equiv_subtype f h = (equiv.sigma_congr_right (λ (y : subtype q), ((equiv.subtype_subtype_equiv_subtype_exists p (λ (x : subtype p), ⟨f ↑x, _⟩ = y)).trans (equiv.subtype_equiv_right _)).symm)).trans (equiv.sigma_preimage_equiv (λ (x : subtype p), ⟨f ↑x, _⟩))
A sigma type over an option
is equivalent to the sigma set over the original type,
if the fiber is empty at none.
Equations
- equiv.sigma_option_equiv_of_some p h = (equiv.sigma_subtype_equiv_of_subset (λ (x : option α), p x) (λ (x : option α), ↥(x.is_some)) _).symm.trans (equiv.option_is_some_equiv α).sigma_congr_left'
The pi
-type Π i, π i
is equivalent to the type of sections f : ι → Σ i, π i
of the
sigma
type such that for all i
we have (f i).fst = i
.
The set of functions f : Π a, β a
such that for all a
we have p a (f a)
is equivalent
to the set of functions Π a, {b : β a // p a b}
.
A subtype of a product defined by componentwise conditions is equivalent to a product of subtypes.
A subtype of a prod
is equivalent to a sigma type whose fibers are subtypes.
The type Π (i : α), β i
can be split as a product by separating the indices in α
depending on whether they satisfy a predicate p
or not.
Equations
- equiv.pi_equiv_pi_subtype_prod p β = {to_fun := λ (f : Π (i : α), β i), (λ (x : {x // p x}), f ↑x, λ (x : {x // ¬p x}), f ↑x), inv_fun := λ (f : (Π (i : {x // p x}), β ↑i) × Π (i : {x // ¬p x}), β ↑i) (x : α), dite (p x) (λ (h : p x), f.fst ⟨x, h⟩) (λ (h : ¬p x), f.snd ⟨x, h⟩), left_inv := _, right_inv := _}
The type of all functions X → Y
with prescribed values for all x' ≠ x
is equivalent to the codomain Y
.
Equations
- equiv.subtype_equiv_codomain f = (equiv.subtype_preimage (λ (x' : X), x' ≠ x) f).trans (equiv.fun_unique {x' // ¬x' ≠ x} Y)
If f
is a bijective function, then its domain is equivalent to its codomain.
Equations
- equiv.of_bijective f hf = {to_fun := f, inv_fun := function.surj_inv _, left_inv := _, right_inv := _}
Equations
- equiv.can_lift = {coe := coe_fn equiv.has_coe_to_fun, cond := function.bijective β, prf := _}
Extend the domain of e : equiv.perm α
to one that is over β
via f : α → subtype p
,
where p : β → Prop
, permuting only the b : β
that satisfy p b
.
This can be used to extend the domain across a function f : α → β
,
keeping everything outside of set.range f
fixed. For this use-case equiv
given by f
can
be constructed by equiv.of_left_inverse'
or equiv.of_left_inverse
when there is a known
inverse, or equiv.of_injective
in the general case.`.
Equations
- e.extend_domain f = (⇑(f.perm_congr) e).subtype_congr (equiv.refl {a // ¬p a})
Subtype of the quotient is equivalent to the quotient of the subtype. Let α
be a setoid with
equivalence relation ~
. Let p₂
be a predicate on the quotient type α/~
, and p₁
be the lift
of this predicate to α
: p₁ a ↔ p₂ ⟦a⟧
. Let ~₂
be the restriction of ~
to {x // p₁ x}
.
Then {x // p₂ x}
is equivalent to the quotient of {x // p₁ x}
by ~₂
.
A helper function for equiv.swap
.
swap a b
is the permutation that swaps a
and b
and
leaves other values as is.
Equations
- equiv.swap a b = {to_fun := equiv.swap_core a b, inv_fun := equiv.swap_core a b, left_inv := _, right_inv := _}
A function is invariant to a swap if it is equal at both elements
Augment an equivalence with a prescribed mapping f a = b
Equations
- f.set_value a b = equiv.trans (equiv.swap a (⇑(f.symm) b)) f
Convert an involutive function f
to a permutation with to_fun = inv_fun = f
.
Transport dependent functions through an equivalence of the base space.
Transporting dependent functions through an equivalence of the base, expressed as a "simplification".
Equations
- equiv.Pi_congr_left P e = (equiv.Pi_congr_left' P e.symm).symm
Transport dependent functions through an equivalence of the base spaces and a family of equivalences of the matching fibers.
Equations
- h₁.Pi_congr h₂ = (equiv.Pi_congr_right h₂).trans (equiv.Pi_congr_left Z h₁)
If α
is a singleton, then it is equivalent to any punit
.
Equations
If α
is a subsingleton, then it is equivalent to α × α
.
To give an equivalence between two subsingleton types, it is sufficient to give any two functions between them.
A nonempty subsingleton type is (noncomputably) equivalent to punit
.
Equations
- equiv.punit_of_nonempty_of_subsingleton = equiv_of_subsingleton_of_subsingleton (λ (_x : α), punit.star) (λ (_x : punit), h.some)
Quotients are congruent on equivalences under equality of their relation.
An alternative is just to use rewriting with eq
, but then computational proofs get stuck.
Equations
- quot.congr_right eq = quot.congr (equiv.refl α) eq
An equivalence e : α ≃ β
generates an equivalence between the quotient space of α
by a relation ra
and the quotient space of β
by the image of this relation under e
.
Equations
- quot.congr_left e = quot.congr e _
An equivalence e : α ≃ β
generates an equivalence between quotient spaces,
if `ra a₁ a₂ ↔ rb (e a₁) (e a₂).
Equations
- quotient.congr e eq = quot.congr e eq