Equivalences involving List
-like types #
This file defines some additional constructive equivalences using Encodable
and the pairing
function on ℕ
.
Explicit encoding function for List α
Equations
- Encodable.encodeList [] = 0
- Encodable.encodeList (a :: l) = (Nat.pair (Encodable.encode a) (Encodable.encodeList l)).succ
Instances For
Explicit encoding function for Multiset α
Equations
- Encodable.encodeMultiset s = Encodable.encode (Multiset.sort Encodable.enle s)
Instances For
Explicit decoding function for Multiset α
Equations
- Encodable.decodeMultiset n = Multiset.ofList <$> Encodable.decode n
Instances For
A listable type with decidable equality is encodable.
Equations
- Encodable.encodableOfList l H = { encode := fun (a : α) => List.indexOf a l, decode := l.get?, encodek := ⋯ }
Instances For
A finite type is encodable. Because the encoding is not unique, we wrap it in Trunc
to
preserve computability.
Equations
- One or more equations did not get rendered due to their size.
Instances For
A noncomputable way to arbitrarily choose an ordering on a finite type.
It is not made into a global instance, since it involves an arbitrary choice.
This can be locally made into an instance with attribute [local instance] Fintype.toEncodable
.
Equations
- Fintype.toEncodable α = (Fintype.truncEncodable α).out
Instances For
If α
is encodable, then so is Vector α n
.
Equations
- Vector.encodable = Subtype.encodable
If α
is countable, then so is Vector α n
.
Equations
- ⋯ = ⋯
If α
is encodable, then so is Fin n → α
.
Equations
- Encodable.finArrow = Encodable.ofEquiv (Mathlib.Vector α n) (Equiv.vectorEquivFin α n).symm
Equations
- Encodable.finPi n π = Encodable.ofEquiv { f : Fin n → (i : Fin n) × π i // ∀ (i : Fin n), (f i).fst = i } (Equiv.piEquivSubtypeSigma (Fin n) π)
When α
is finite and β
is encodable, α → β
is encodable too. Because the encoding is not
unique, we wrap it in Trunc
to preserve computability.
Equations
- Encodable.fintypeArrow α β = Trunc.map (fun (f : α ≃ Fin (Fintype.card α)) => Encodable.ofEquiv (Fin (Fintype.card α) → β) (f.arrowCongr (Equiv.refl β))) (Fintype.truncEquivFin α)
Instances For
When α
is finite and all π a
are encodable, Π a, π a
is encodable too. Because the
encoding is not unique, we wrap it in Trunc
to preserve computability.
Equations
- One or more equations did not get rendered due to their size.
Instances For
The elements of a Fintype
as a sorted list.
Equations
- Encodable.sortedUniv α = Finset.sort (⇑(Encodable.encode' α) ⁻¹'o fun (x1 x2 : ℕ) => x1 ≤ x2) Finset.univ
Instances For
An encodable Fintype
is equivalent to the same size Fin
.
Equations
- Encodable.fintypeEquivFin = (List.Nodup.getEquivOfForallMemList (Encodable.sortedUniv α) ⋯ ⋯).symm.trans (Equiv.cast ⋯)
Instances For
If α
and β
are encodable and α
is a fintype, then α → β
is encodable as well.
Equations
- Encodable.fintypeArrowOfEncodable = Encodable.ofEquiv (Fin (Fintype.card α) → β) (Encodable.fintypeEquivFin.arrowCongr (Equiv.refl β))
If α
is denumerable, then so is List α
.
Equations
- Denumerable.denumerableList = Denumerable.mk ⋯
Outputs the list of differences of the input list, that is
lower [a₁, a₂, ...] n = [a₁ - n, a₂ - a₁, ...]
Equations
- Denumerable.lower [] x = []
- Denumerable.lower (m :: l) x = (m - x) :: Denumerable.lower l m
Instances For
Outputs the list of partial sums of the input list, that is
raise [a₁, a₂, ...] n = [n + a₁, n + a₁ + a₂, ...]
Equations
- Denumerable.raise [] x = []
- Denumerable.raise (m :: l) x = (m + x) :: Denumerable.raise l (m + x)
Instances For
raise l n
is a non-decreasing sequence.
If α
is denumerable, then so is Multiset α
. Warning: this is not the same encoding as used
in Multiset.encodable
.
Equations
- One or more equations did not get rendered due to their size.
Outputs the list of differences minus one of the input list, that is
lower' [a₁, a₂, a₃, ...] n = [a₁ - n, a₂ - a₁ - 1, a₃ - a₂ - 1, ...]
.
Equations
- Denumerable.lower' [] x = []
- Denumerable.lower' (m :: l) x = (m - x) :: Denumerable.lower' l (m + 1)
Instances For
Outputs the list of partial sums plus one of the input list, that is
raise [a₁, a₂, a₃, ...] n = [n + a₁, n + a₁ + a₂ + 1, n + a₁ + a₂ + a₃ + 2, ...]
. Adding one each
time ensures the elements are distinct.
Equations
- Denumerable.raise' [] x = []
- Denumerable.raise' (m :: l) x = (m + x) :: Denumerable.raise' l (m + x + 1)
Instances For
raise' l n
is a strictly increasing sequence.
Makes raise' l n
into a finset. Elements are distinct thanks to raise'_sorted
.
Equations
- Denumerable.raise'Finset l n = { val := ↑(Denumerable.raise' l n), nodup := ⋯ }
Instances For
If α
is denumerable, then so is Finset α
. Warning: this is not the same encoding as used
in Finset.encodable
.
Equations
- One or more equations did not get rendered due to their size.
The type lists on unit is canonically equivalent to the natural numbers.
Equations
- Equiv.listUnitEquiv = { toFun := List.length, invFun := fun (n : ℕ) => List.replicate n (), left_inv := Equiv.listUnitEquiv.proof_1, right_inv := ⋯ }
Instances For
If α
is equivalent to ℕ
, then List α
is equivalent to α
.
Equations
- e.listEquivSelfOfEquivNat = Trans.trans (Trans.trans e.listEquivOfEquiv Equiv.listNatEquivNat) e.symm