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.
- encode : α → ℕ
- encodek : ∀ (a : α), Encodable.decode (Encodable.encode a) = some a
- decode_inv : ∀ (n : ℕ), ∃ a, a ∈ Encodable.decode n ∧ Encodable.encode a = n
decode
andencode
are inverses.
A denumerable type is (constructively) bijective with ℕ
. Typeclass equivalent of α ≃ ℕ
.
Instances
Returns the n
-th element of α
indexed by the decoding.
Equations
- Denumerable.ofNat α n = Option.get (Encodable.decode n) (_ : Option.isSome (Encodable.decode n) = true)
Instances For
A denumerable type is equivalent to ℕ
.
Equations
- One or more equations did not get rendered due to their size.
Instances For
A type equivalent to ℕ
is denumerable.
Equations
- Denumerable.mk' e = Denumerable.mk (_ : ∀ (x : ℕ), ∃ a, a ∈ Encodable.decode x ∧ Encodable.encode a = x)
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 (_ : ∀ (n : ℕ), ∃ a, a ∈ Encodable.decode n ∧ Encodable.encode a = n)
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 (_ : ∀ (n : ℕ), ∃ a, a ∈ Encodable.decode n ∧ Encodable.encode a = n)
If α
and β
are denumerable, then so is their sum.
Equations
- Denumerable.sum = Denumerable.mk (_ : ∀ (n : ℕ), ∃ a, a ∈ Encodable.decode n ∧ Encodable.encode a = n)
A denumerable collection of denumerable types is denumerable.
Equations
- One or more equations did not get rendered due to their size.
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
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
- One or more equations did not get rendered due to their size.
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
.