Examples of W-types #
THIS FILE IS SYNCHRONIZED WITH MATHLIB4. Any changes to this file require a corresponding PR to mathlib4.
We take the view of W types as inductive types.
Given α : Type
and β : α → Type
, the W type determined by this data, W_type β
, is the
inductively with constructors from α
and arities of each constructor a : α
given by β a
.
This file contains nat
and list
as examples of W types.
Main results #
W_type.equiv_nat
: the construction of the naturals as a W-type is equivalent tonat
W_type.equiv_list
: the construction of lists on a typeγ
as a W-type is equivalent tolist γ
- zero : W_type.nat_α
- succ : W_type.nat_α
The constructors for the naturals
Instances for W_type.nat_α
- W_type.nat_α.has_sizeof_inst
- W_type.nat_α.inhabited
Equations
The arity of the constructors for the naturals, zero
takes no arguments, succ
takes one
Instances for W_type.nat_β
Equations
The isomorphism from the W_type
of the naturals to the naturals
Equations
- (W_type.mk W_type.nat_α.succ f).to_nat = (f unit.star()).to_nat.succ
- (W_type.mk W_type.nat_α.zero f).to_nat = 0
The naturals are equivalent to their associated W_type
Equations
W_type.nat_α
is equivalent to punit ⊕ punit
.
This is useful when considering the associated polynomial endofunctor.
Equations
- W_type.nat_α_equiv_punit_sum_punit = {to_fun := λ (c : W_type.nat_α), W_type.nat_α_equiv_punit_sum_punit._match_1 c, inv_fun := λ (b : punit ⊕ punit), W_type.nat_α_equiv_punit_sum_punit._match_2 b, left_inv := W_type.nat_α_equiv_punit_sum_punit._proof_1, right_inv := W_type.nat_α_equiv_punit_sum_punit._proof_2}
- W_type.nat_α_equiv_punit_sum_punit._match_1 W_type.nat_α.succ = sum.inr punit.star
- W_type.nat_α_equiv_punit_sum_punit._match_1 W_type.nat_α.zero = sum.inl punit.star
- W_type.nat_α_equiv_punit_sum_punit._match_2 (sum.inr x) = W_type.nat_α.succ
- W_type.nat_α_equiv_punit_sum_punit._match_2 (sum.inl x) = W_type.nat_α.zero
- nil : Π {γ : Type u}, W_type.list_α γ
- cons : Π {γ : Type u}, γ → W_type.list_α γ
The constructors for lists.
There is "one constructor cons x
for each x : γ
",
since we view list γ
as
Instances for W_type.list_α
- W_type.list_α.has_sizeof_inst
- W_type.list_α.inhabited
Equations
The arities of each constructor for lists, nil
takes no arguments, cons hd
takes one
Equations
Instances for W_type.list_β
Equations
- W_type.list_β.inhabited γ hd = {default := punit.star}
The isomorphism from lists to the W_type
construction of lists
Equations
- W_type.of_list γ (hd :: tl) = W_type.mk (W_type.list_α.cons hd) (λ (_x : W_type.list_β γ (W_type.list_α.cons hd)), W_type.of_list γ tl)
- W_type.of_list γ list.nil = W_type.mk W_type.list_α.nil pempty.elim
The isomorphism from the W_type
construction of lists to lists
Equations
- W_type.to_list γ (W_type.mk (W_type.list_α.cons hd) f) = hd :: W_type.to_list γ (f punit.star)
- W_type.to_list γ (W_type.mk W_type.list_α.nil f) = list.nil
Lists are equivalent to their associated W_type
Equations
- W_type.equiv_list γ = {to_fun := W_type.to_list γ, inv_fun := W_type.of_list γ, left_inv := _, right_inv := _}
W_type.list_α
is equivalent to γ
with an extra point.
This is useful when considering the associated polynomial endofunctor
Equations
- W_type.list_α_equiv_punit_sum γ = {to_fun := λ (c : W_type.list_α γ), W_type.list_α_equiv_punit_sum._match_1 γ c, inv_fun := sum.elim (λ (_x : punit), W_type.list_α.nil) (λ (x : γ), W_type.list_α.cons x), left_inv := _, right_inv := _}
- W_type.list_α_equiv_punit_sum._match_1 γ (W_type.list_α.cons x) = sum.inr x
- W_type.list_α_equiv_punit_sum._match_1 γ W_type.list_α.nil = sum.inl punit.star