Denumerable types #
This file defines denumerable (countably infinite) types as a typeclass extending Encodable
. This
is used to provide explicit encode/decode functions from and to ℕ
, with the information that those
functions are inverses of each other.
Implementation notes #
This property already has a name, namely α ≃ ℕ
, but here we are interested in using it as a
typeclass.
A denumerable type is (constructively) bijective with ℕ
. Typeclass equivalent of α ≃ ℕ
.
- encode : α → ℕ
- encodek : ∀ (a : α), Encodable.decode (Encodable.encode a) = some a
- decode_inv : ∀ (n : ℕ), ∃ a ∈ Encodable.decode n, Encodable.encode a = n
decode
andencode
are inverses.
Instances
Returns the n
-th element of α
indexed by the decoding.
Equations
- Denumerable.ofNat α n = Option.get (Encodable.decode n) ⋯
Instances For
A denumerable type is equivalent to ℕ
.
Equations
- Denumerable.eqv α = { toFun := Encodable.encode, invFun := Denumerable.ofNat α, left_inv := ⋯, right_inv := ⋯ }
Instances For
A type equivalent to ℕ
is denumerable.
Equations
Instances For
Denumerability is conserved by equivalences. This is transitivity of equivalence the denumerable way.
Equations
- Denumerable.ofEquiv α e = let __src := Encodable.ofEquiv α e; Denumerable.mk ⋯
Instances For
All denumerable types are equivalent.
Equations
- Denumerable.equiv₂ α β = (Denumerable.eqv α).trans (Denumerable.eqv β).symm
Instances For
If α
is denumerable, then so is Option α
.
Equations
- Denumerable.option = Denumerable.mk ⋯
If α
and β
are denumerable, then so is their sum.
Equations
- Denumerable.sum = Denumerable.mk ⋯
A denumerable collection of denumerable types is denumerable.
Equations
- Denumerable.sigma = Denumerable.mk ⋯
If α
and β
are denumerable, then so is their product.
Equations
- Denumerable.prod = Denumerable.ofEquiv ((_ : α) × β) (Equiv.sigmaEquivProd α β).symm
Equations
The lift of a denumerable type is denumerable.
Equations
- Denumerable.ulift = Denumerable.ofEquiv α Equiv.ulift
The lift of a denumerable type is denumerable.
Equations
- Denumerable.plift = Denumerable.ofEquiv α Equiv.plift
If α
is denumerable, then α × α
and α
are equivalent.
Equations
- Denumerable.pair = Denumerable.equiv₂ (α × α) α
Instances For
Subsets of ℕ
#
Returns the next natural in a set, according to the usual ordering of ℕ
.
Equations
- Nat.Subtype.succ x = let_fun h := ⋯; { val := ↑x + Nat.find h + 1, property := ⋯ }
Instances For
Returns the n
-th element of a set, according to the usual ordering of ℕ
.
Equations
- Nat.Subtype.ofNat s 0 = ⊥
- Nat.Subtype.ofNat s (Nat.succ n) = Nat.Subtype.succ (Nat.Subtype.ofNat s n)
Instances For
Any infinite set of naturals is denumerable.
Equations
- Nat.Subtype.denumerable s = Denumerable.ofEquiv ℕ { toFun := Nat.Subtype.toFunAux, invFun := Nat.Subtype.ofNat s, left_inv := ⋯, right_inv := ⋯ }
Instances For
An infinite encodable type is denumerable.
Equations
- Denumerable.ofEncodableOfInfinite α = Denumerable.ofEquiv (↑(Set.range Encodable.encode)) (Encodable.equivRangeEncode α)
Instances For
See also nonempty_encodable
, nonempty_fintype
.