# W types #

Given α : Type and β : α → Type, the W type determined by this data, WType β, is the inductively defined type of trees where the nodes are labeled by elements of α and the children of a node labeled a are indexed by elements of β a.

This file is currently a stub, awaiting a full development of the theory. Currently, the main result is that if α is an encodable fintype and β a is encodable for every a : α, then WType β is encodable. This can be used to show the encodability of other inductive types, such as those that are commonly used to formalize syntax, e.g. terms and expressions in a given language. The strategy is illustrated in the example found in the file prop_encodable in the archive/examples folder of mathlib.

## Implementation details #

While the name WType is somewhat verbose, it is preferable to putting a single character identifier W in the root namespace.

inductive WType {α : Type u_1} (β : αType u_2) :
Type (max u_1 u_2)

Given β : α → Type*, WType β is the type of finitely branching trees where nodes are labeled by elements of α and the children of a node labeled a are indexed by elements of β a.

• mk: {α : Type u_1} → {β : αType u_2} → (a : α) → (β a → )
Instances For
Equations
def WType.toSigma {α : Type u_1} {β : αType u_2} :
(a : α) × (β a)

The canonical map to the corresponding sigma type, returning the label of a node as an element a of α, and the children of the node as a function β a → WType β.

Equations
• x.toSigma = match x with | WType.mk a f => a, f
Instances For
def WType.ofSigma {α : Type u_1} {β : αType u_2} :
(a : α) × (β a)

The canonical map from the sigma type into a WType. Given a node a : α, and its children as a function β a → WType β, return the corresponding tree.

Equations
Instances For
@[simp]
theorem WType.ofSigma_toSigma {α : Type u_1} {β : αType u_2} (w : ) :
WType.ofSigma w.toSigma = w
@[simp]
theorem WType.toSigma_ofSigma {α : Type u_1} {β : αType u_2} (s : (a : α) × (β a)) :
.toSigma = s
@[simp]
theorem WType.equivSigma_symm_apply {α : Type u_1} (β : αType u_2) :
∀ (a : (a : α) × (β a)), .symm a =
@[simp]
theorem WType.equivSigma_apply {α : Type u_1} (β : αType u_2) :
∀ (a : ), a = a.toSigma
def WType.equivSigma {α : Type u_1} (β : αType u_2) :
(a : α) × (β a)

The canonical bijection with the sigma type, showing that WType is a fixed point of the polynomial functor X ↦ Σ a : α, β a → X.

Equations
• = { toFun := WType.toSigma, invFun := WType.ofSigma, left_inv := , right_inv := }
Instances For
def WType.elim {α : Type u_1} {β : αType u_2} (γ : Type u_3) (fγ : (a : α) × (β aγ)γ) :
γ

The canonical map from WType β into any type γ given a map (Σ a : α, β a → γ) → γ.

Equations
Instances For
theorem WType.elim_injective {α : Type u_1} {β : αType u_2} (γ : Type u_3) (fγ : (a : α) × (β aγ)γ) (fγ_injective : ) :
instance WType.instIsEmpty {α : Type u_1} {β : αType u_2} [hα : ] :
Equations
• =
theorem WType.infinite_of_nonempty_of_isEmpty {α : Type u_1} {β : αType u_2} (a : α) (b : α) [ha : Nonempty (β a)] [he : IsEmpty (β b)] :
def WType.depth {α : Type u_1} {β : αType u_2} [(a : α) → Fintype (β a)] :

The depth of a finitely branching tree.

Equations
• (WType.mk a f).depth = (Finset.univ.sup fun (n : β a) => (f n).depth) + 1
Instances For
theorem WType.depth_pos {α : Type u_1} {β : αType u_2} [(a : α) → Fintype (β a)] (t : ) :
0 < t.depth
theorem WType.depth_lt_depth_mk {α : Type u_1} {β : αType u_2} [(a : α) → Fintype (β a)] (a : α) (f : β a) (i : β a) :
(f i).depth < (WType.mk a f).depth
instance WType.instEncodable {α : Type u_1} {β : αType u_2} [(a : α) → Fintype (β a)] [(a : α) → Encodable (β a)] [] :

WType is encodable when α is an encodable fintype and for every a : α, β a is encodable.

Equations
• WType.instEncodable = let f := fun (t : ) => t.depth, t, ; let finv := fun (p : (n : ) × ) => p.snd; let_fun this := ; Encodable.ofLeftInverse f finv this