The areas / V32. Logic, model theory and computability
Mathlib.Computability.Encoding
55 declarations and 11 deprecated aliases. Mathlib docs · Source
Encodings
This file contains the definition of an encoding, a map from a type to strings in an alphabet, used in defining computability by Turing machines. It also contains several examples:
Examples
encodingNatBool: a binary encoding ofℕin a simple alphabet.encodingNatΓ': a binary encoding ofℕin the alphabet used for TM's.unaryEncodingNat: a unary encoding ofℕencodingBoolBool: an encoding ofBool.encodingList: an encoding ofList αin the alphabetα.encodingProd: an encoding ofα × βfrom encodings ofαandβ.
Deprecated aliases for FinEncoding and unbundled Γ
theorem Computability.Γ'.bit.inj E1 #
∀ {b b_1 : Bool}, Computability.Γ'.bit b = Computability.Γ'.bit b_1 → b = b_1
theorem Computability.decodePosNum.match_1.congr_eq_3 E1 #
∀ (motive : List Bool → Sort u_1) (x : List Bool) (h_1 : (l : List Bool) → motive (false :: l))
(h_2 : (l : List Bool) → motive (true :: l)) (h_3 : (x : List Bool) → motive x) (x_1 : List Bool),
x = x_1 →
(∀ (l : List Bool), x_1 = false :: l → False) →
(∀ (l : List Bool), x_1 = true :: l → False) →
(match x with
| false :: l => h_1 l
| true :: l => h_2 l
| x => h_3 x) ≍
h_3 x_1
theorem Computability.Encoding.mk.injEq E0 #
∀ {α : Type u} {Γ : Type v} (encode : α → List Γ) (decode : List Γ → Option α)
(decode_encode : ∀ (x : α), decode (encode x) = some x) (encode_1 : α → List Γ) (decode_1 : List Γ → Option α)
(decode_encode_1 : ∀ (x : α), decode_1 (encode_1 x) = some x),
({ encode := encode, decode := decode, decode_encode := decode_encode } =
{ encode := encode_1, decode := decode_1, decode_encode := decode_encode_1 }) =
(encode = encode_1 ∧ decode = decode_1)
def Computability.Γ'.ctorIdx E1 #
Computability.Γ' → ℕ
abbrev Computability.Γ'.ctorElimType E1 #
{motive : Computability.Γ' → Sort u} → ℕ → Sort (max 1 u)
theorem Computability.Encoding.mk.inj E1 #
∀ {α : Type u} {Γ : Type v} {encode : α → List Γ} {decode : List Γ → Option α}
{decode_encode : ∀ (x : α), decode (encode x) = some x} {encode_1 : α → List Γ} {decode_1 : List Γ → Option α}
{decode_encode_1 : ∀ (x : α), decode_1 (encode_1 x) = some x},
{ encode := encode, decode := decode, decode_encode := decode_encode } =
{ encode := encode_1, decode := decode_1, decode_encode := decode_encode_1 } →
encode = encode_1 ∧ decode = decode_1
theorem Computability.Γ'.bit.injEq E0 #
∀ (b b_1 : Bool), (Computability.Γ'.bit b = Computability.Γ'.bit b_1) = (b = b_1)
def Computability.Encoding.ctorIdx E1 #
{α : Type u} → {Γ : Type v} → Computability.Encoding α Γ → ℕ
abbrev Computability.Γ'.proxyTypeEquiv E1 #
Unit ⊕ Bool ⊕ Unit ⊕ Unit ⊕ Unit ≃ Computability.Γ'
An equivalence between the "proxy type" Computability.Γ'.proxyType and Computability.Γ'. The proxy type is a reducible definition that represents the inductive type using Unit, PLift, Sigma, Empty, and Sum (and whatever other inductive types appear within the inductive type), and the intended use is to define typeclass instances uses pre-existing instances on these. (Generated by the proxy_equiv% elaborator.)
abbrev Computability.Γ'.proxyType E1 #
Type
A "proxy type" equivalent to Computability.Γ' that is constructed from Unit, PLift, Sigma, Empty, and Sum. See Computability.Γ'.proxyTypeEquiv for the equivalence. (Generated by the proxy_equiv% elaborator.)
structure Computability.Encoding E1 #
Type u → Type v → Type (max u v)
An encoding of a type in a certain alphabet, together with a decoding.
ctor Computability.Encoding.mk E0 #
{α : Type u} →
{Γ : Type v} →
(encode : α → List Γ) →
(decode : List Γ → Option α) → (∀ (x : α), decode (encode x) = some x) → Computability.Encoding α Γ
abbrev Computability.Encoding.encode E1 #
{α : Type u} → {Γ : Type v} → Computability.Encoding α Γ → α → List Γ
The encoding function
abbrev Computability.Encoding.decode E1 #
{α : Type u} → {Γ : Type v} → Computability.Encoding α Γ → List Γ → Option α
The decoding function
theorem Computability.Encoding.decode_encode E0 #
∀ {α : Type u} {Γ : Type v} (self : Computability.Encoding α Γ) (x : α), self.decode (self.encode x) = some x
Decoding and encoding are inverses of each other.
theorem Computability.Encoding.encode_injective E1 #
∀ {α : Type u_1} {Γ : Type u_2} (e : Computability.Encoding α Γ), Function.Injective e.encode
inductive Computability.Γ' E1 #
Type
A standard Turing machine alphabet, consisting of blank,bit0,bit1,bra,ket,comma.
ctor Computability.Γ'.blank E0 #
Computability.Γ'
ctor Computability.Γ'.bit E0 #
Bool → Computability.Γ'
ctor Computability.Γ'.bra E0 #
Computability.Γ'
ctor Computability.Γ'.ket E0 #
Computability.Γ'
ctor Computability.Γ'.comma E0 #
Computability.Γ'
def Computability.instDecidableEqΓ'.decEq E1 #
(x x_1 : Computability.Γ') → Decidable (x = x_1)
instance Computability.instDecidableEqΓ' E0 #
DecidableEq Computability.Γ'
instance Computability.instFintypeΓ' E0 #
Fintype Computability.Γ'
instance Computability.inhabitedΓ' E0 #
Inhabited Computability.Γ'
def Computability.inclusionBoolΓ' E1 #
Bool → Computability.Γ'
The natural inclusion of Bool in Γ'.
def Computability.sectionΓ'Bool E1 #
Computability.Γ' → Bool
An arbitrary section of the natural inclusion of Bool in Γ'.
theorem Computability.sectionΓ'Bool_inclusionBoolΓ' E0 #
∀ {b : Bool}, Computability.sectionΓ'Bool (Computability.inclusionBoolΓ' b) = b
theorem Computability.inclusionBoolΓ'_injective E1 #
Function.Injective Computability.inclusionBoolΓ'
def Computability.encodePosNum E1 #
PosNum → List Bool
An encoding function of the positive binary numbers in Bool.
def Computability.encodeNum E1 #
Num → List Bool
An encoding function of the binary numbers in Bool.
def Computability.encodeNat E1 #
ℕ → List Bool
An encoding function of ℕ in Bool.
def Computability.decodePosNum E1 #
List Bool → PosNum
A decoding function from List Bool to the positive binary numbers.
def Computability.decodeNum E1 #
List Bool → Num
A decoding function from List Bool to the binary numbers.
def Computability.decodeNat E1 #
List Bool → ℕ
A decoding function from List Bool to ℕ.
theorem Computability.encodePosNum_nonempty E1 #
∀ (n : PosNum), Computability.encodePosNum n ≠ []
theorem Computability.decode_encodePosNum E0 #
∀ (n : PosNum), Computability.decodePosNum (Computability.encodePosNum n) = n
theorem Computability.decode_encodeNum E0 #
∀ (n : Num), Computability.decodeNum (Computability.encodeNum n) = n
theorem Computability.decode_encodeNat E0 #
∀ (n : ℕ), Computability.decodeNat (Computability.encodeNat n) = n
def Computability.encodingNatBool E1 #
Computability.Encoding ℕ Bool
A binary Encoding of ℕ in Bool.
def Computability.encodingNatΓ' E1 #
Computability.Encoding ℕ Computability.Γ'
A binary Encoding of ℕ in Γ'.
def Computability.unaryEncodeNat E1 #
ℕ → List Bool
A unary encoding function of ℕ in Bool.
def Computability.unaryDecodeNat E1 #
List Bool → ℕ
A unary decoding function from List Bool to ℕ.
theorem Computability.unary_decode_encode_nat E0 #
∀ (n : ℕ), Computability.unaryDecodeNat (Computability.unaryEncodeNat n) = n
def Computability.unaryEncodingNat E1 #
Computability.Encoding ℕ Bool
A unary Encoding of ℕ in Bool.
def Computability.encodeBool E1 #
Bool → List Bool
An encoding function of Bool in Bool.
def Computability.decodeBool E1 #
List Bool → Bool
A decoding function from List Bool to Bool.
theorem Computability.decode_encodeBool E0 #
∀ (b : Bool), Computability.decodeBool (Computability.encodeBool b) = b
def Computability.encodingBoolBool E1 #
Computability.Encoding Bool Bool
An Encoding of Bool in Bool.
instance Computability.inhabitedEncoding E0 #
Inhabited (Computability.Encoding Bool Bool)
theorem Computability.Encoding.card_le_card_list E1 #
∀ {α : Type u} {Γ : Type v} (e : Computability.Encoding α Γ),
Cardinal.lift.{v, u} (Cardinal.mk α) ≤ Cardinal.lift.{u, v} (Cardinal.mk (List Γ))
theorem Computability.Encoding.card_le_aleph0 E1 #
∀ {α : Type u_1} {Γ : Type u_2} (e : Computability.Encoding α Γ) [Countable Γ], Cardinal.mk α ≤ Cardinal.aleph0
def Computability.encodingList E1 #
(α : Type) → Computability.Encoding (List α) α
An Encoding of a List α in alphabet α, encoded directly.
def Computability.encodingProd E1 #
{α : Type u_1} →
{β : Type u_2} →
{Γ₁ : Type u_3} →
{Γ₂ : Type u_4} →
Computability.Encoding α Γ₁ → Computability.Encoding β Γ₂ → Computability.Encoding (α × β) (Γ₁ ⊕ Γ₂)
Given an Encoding of α and β,
constructs an Encoding of α × β by concatenating the encodings,
mapping the symbols from the first encoding with Sum.inl
and those from the second with Sum.inr.
Deprecated aliases
| Name | New name | Since |
|---|---|---|
Computability.Encoding.Γ | 2026-05-07 | |
Computability.FinEncoding | 2026-05-07 | |
Computability.FinEncoding.card_le_aleph0 | Computability.Encoding.card_le_aleph0 | 2026-05-07 |
Computability.FinEncoding.toEncoding | 2026-05-07 | |
Computability.FinEncoding.ΓFin | 2026-05-07 | |
Computability.finEncodingBoolBool | Computability.encodingBoolBool | 2026-05-07 |
Computability.finEncodingList | Computability.encodingList | 2026-05-07 |
Computability.finEncodingNatBool | Computability.encodingNatBool | 2026-05-07 |
Computability.finEncodingNatΓ' | Computability.encodingNatΓ' | 2026-05-07 |
Computability.finEncodingPair | Computability.encodingProd | 2026-05-07 |
Computability.unaryFinEncodingNat | Computability.unaryEncodingNat | 2026-05-07 |