- encode : α → ℕ
- decode : ℕ → option α
- encodek : ∀ (a : α), encodable.decode α (encodable.encode a) = option.some a
An encodable type is a "constructively countable" type. This is where
we have an explicit injection encode : α → nat
and a partial inverse
decode : nat → option α
. This makes the range of encode
decidable,
although it is not decidable if α
is finite or not.
Instances
- denumerable.to_encodable
- primcodable.to_encodable
- encodable.nat
- encodable.empty
- encodable.unit
- encodable.option
- encodable.sum
- encodable.bool
- encodable.sigma
- encodable.prod
- encodable.subtype
- encodable.fin
- encodable.int
- encodable.ulift
- encodable.plift
- ulower.encodable
- rat.encodable
- encodable.list
- encodable.multiset
- encodable.vector
- encodable.fin_arrow
- encodable.fin_pi
- encodable.array
- encodable.finset
- encodable.fintype_arrow_of_encodable
- encodable.encodable
Equations
Equations
- encodable.of_left_injection f finv linv = {encode := λ (b : β), encodable.encode (f b), decode := λ (n : ℕ), (encodable.decode α n).bind finv, encodek := _}
Equations
- encodable.of_left_inverse f finv linv = encodable.of_left_injection f (option.some ∘ finv) _
If α
is encodable and β ≃ α
, then so is β
Equations
- encodable.of_equiv α e = encodable.of_left_inverse ⇑e ⇑(e.symm) _
Equations
- encodable.nat = {encode := id ℕ, decode := option.some ℕ, encodek := encodable.nat._proof_1}
Equations
- encodable.unit = {encode := λ (_x : punit), 0, decode := λ (n : ℕ), n.cases_on (option.some punit.star) (λ (_x : ℕ), option.none), encodek := encodable.unit._proof_1}
Equations
- encodable.option = {encode := λ (o : option α), o.cases_on 0 (λ (a : α), (encodable.encode a).succ), decode := λ (n : ℕ), n.cases_on (option.some option.none) (λ (m : ℕ), option.map option.some (encodable.decode α m)), encodek := _}
Equations
- encodable.decode2 α n = (encodable.decode α n).bind (option.guard (λ (a : α), encodable.encode a = n))
Equations
- encodable.decidable_range_encode α = λ (x : ℕ), decidable_of_iff ↥((encodable.decode2 α x).is_some) _
Equations
- encodable.equiv_range_encode α = {to_fun := λ (a : α), ⟨encodable.encode a, _⟩, inv_fun := λ (n : ↥(set.range encodable.encode)), option.get _, left_inv := _, right_inv := _}
Equations
- encodable.encode_sum (sum.inr b) = bit1 (encodable.encode b)
- encodable.encode_sum (sum.inl a) = bit0 (encodable.encode a)
Equations
- encodable.decode_sum n = encodable.decode_sum._match_1 n.bodd_div2
- encodable.decode_sum._match_1 (bool.tt, m) = option.map sum.inr (encodable.decode β m)
- encodable.decode_sum._match_1 (bool.ff, m) = option.map sum.inl (encodable.decode α m)
Equations
- encodable.sum = {encode := encodable.encode_sum _inst_2, decode := encodable.decode_sum _inst_2, encodek := _}
Equations
- encodable.encode_sigma ⟨a, b⟩ = (encodable.encode a).mkpair (encodable.encode b)
Equations
- encodable.decode_sigma n = encodable.decode_sigma._match_1 n.unpair
- encodable.decode_sigma._match_1 (n₁, n₂) = (encodable.decode α n₁).bind (λ (a : α), option.map (sigma.mk a) (encodable.decode (γ a) n₂))
Equations
- encodable.sigma = {encode := encodable.encode_sigma (λ (a : α), _inst_2 a), decode := encodable.decode_sigma (λ (a : α), _inst_2 a), encodek := _}
Equations
- encodable.prod = encodable.of_equiv (Σ (_x : α), β) (equiv.sigma_equiv_prod α β).symm
Equations
Equations
- encodable.decode_subtype v = (encodable.decode α v).bind (λ (a : α), dite (P a) (λ (h : P a), option.some ⟨a, h⟩) (λ (h : ¬P a), option.none))
Equations
- encodable.subtype = {encode := encodable.encode_subtype encA, decode := encodable.decode_subtype (λ (a : α), decP a), encodek := _}
Equations
- encodable.fin n = encodable.of_equiv {m // m < n} (equiv.fin_equiv_subtype n)
Equations
Equations
Equations
Equations
- encodable.of_inj f hf = encodable.of_left_injection f (function.partial_inv f) _
The equivalence between the encodable type α
and ulower α : Type 0
.
Equations
Lowers an a : α
into ulower α
.
Equations
- ulower.down a = ⇑(ulower.equiv α) a
Equations
Equations
- encodable.choose_x h = have this : ∃ (n : ℕ), good p (encodable.decode α n), from _, encodable.choose_x._match_4 (encodable.decode α (nat.find this)) _
- encodable.choose_x._match_4 (option.some a) h = ⟨a, h⟩
- _ = _
Equations
The encode
function, viewed as an embedding.
Equations
- encodable.encode' α = {to_fun := encodable.encode _inst_1, inj' := _}
Equations
Equations
Equations
Given a directed r
function f : α → β
defined on an encodable inhabited type,
construct a noncomputable sequence such that r (f (x n)) (f (x (n + 1)))
and r (f a) (f (x (encode a + 1))
.
Equations
- directed.sequence f hf (n + 1) = let p : α := directed.sequence f hf n in directed.sequence._match_1 f hf p (encodable.decode α n)
- directed.sequence f hf 0 = inhabited.default α
- directed.sequence._match_1 f hf p (option.some a) = classical.some _
- directed.sequence._match_1 f hf p option.none = classical.some _
Representative of an equivalence class. This is a computable version of quot.out
for a setoid
on an encodable type.
Equations
- q.rep = encodable.choose _
The quotient of an encodable space by a decidable equivalence relation is encodable.
Equations
- encodable_quotient = {encode := λ (q : quotient s), encodable.encode q.rep, decode := λ (n : ℕ), quotient.mk <$> encodable.decode α n, encodek := _}