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.succ (Nat.pair (Encodable.encode a) (Encodable.encodeList l))
Instances For
If α
is encodable, then so is List α
. This uses the pair
and unpair
functions from
Data.Nat.Pairing
.
Equations
- List.encodable = { encode := Encodable.encodeList, decode := Encodable.decodeList, encodek := (_ : ∀ (l : List α), Encodable.decodeList (Encodable.encodeList l) = some l) }
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 := List.get? l, encodek := (_ : ∀ (x : α), List.get? l (List.indexOf x l) = some x) }
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
Instances For
If α
is encodable, then so is Fin n → α
.
Equations
- Encodable.finArrow = Encodable.ofEquiv (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
- One or more equations did not get rendered due to their size.
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 (x x_1 : ℕ) => x ≤ x_1) Finset.univ
Instances For
If α
and β
are encodable and α
is a fintype, then α → β
is encodable as well.
Equations
- Encodable.fintypeArrowOfEncodable = Encodable.ofEquiv (Fin (Fintype.card α) → β) (Equiv.arrowCongr Encodable.fintypeEquivFin (Equiv.refl β))
If α
is denumerable, then so is List α
.
Equations
- Denumerable.denumerableList = Denumerable.mk (_ : ∀ (n : ℕ), ∃ a ∈ Encodable.decodeList n, Encodable.encodeList a = n)
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 := (_ : List.Pairwise (fun (a b : ℕ) => a ≠ b) (Denumerable.raise' l n)) }
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.