Paper
The equational theory of rational string-to-string functions
98 pages · 41 marked passages · pdflatex · download PDF · lax-149335
-
Rational functions
A rational relation between strings over alphabets and is a subset of the monoid defined by a regular expression: the atoms are pairs of strings, and the operations are union, concatenation (componentwise) and Kleene star.
Definition 2.1 (Rational function). A function is rational if its graph is a rational relation.
Definition 2.3 (Rational functions on types). A function between types is rational if there is a rational function that agrees with on the string representations of elements, i.e. the string representation of is applied to the string representation of .
1 import Lax149335.Types 2 import Mathlib.Data.Set.Defs 3 … module docstring, 18 lines 22 23 namespace Lax149335.RationalFunctions 24 25 open Lax149335.Types 26 27 variable {α β : Type} 28 29 /-- Regular expressions over the product monoid `α* × β*`. -/ 30 inductive RatExp (α β : Type) : Type 31 | zero : RatExp α β 32 | atom : List α → List β → RatExp α β 33 | plus : RatExp α β → RatExp α β → RatExp α β 34 | cat : RatExp α β → RatExp α β → RatExp α β 35 | star : RatExp α β → RatExp α β 36 37 /-- The submonoid of `α* × β*` generated by a set `S`: all finite products of elements of 38 `S`. -/ 39 inductive StarSet (S : Set (List α × List β)) : List α × List β → Prop 40 | nil : StarSet S ([], []) 41 | cons {x y : List α × List β} : x ∈ S → StarSet S y → StarSet S (x.1 ++ y.1, x.2 ++ y.2) 42 43 /-- The relation defined by a regular expression. -/ 44 def RatExp.lang : RatExp α β → Set (List α × List β) 45 | .zero => ∅ 46 | .atom u v => {(u, v)} 47 | .plus e f => e.lang ∪ f.lang 48 | .cat e f => {p | ∃ x ∈ e.lang, ∃ y ∈ f.lang, p = (x.1 ++ y.1, x.2 ++ y.2)} 49 | .star e => {p | StarSet e.lang p} 50 51 /-- A relation between strings is rational if it is defined by a regular expression. -/ 52 def IsRationalRel (R : Set (List α × List β)) : Prop := ∃ e : RatExp α β, e.lang = R 53 54 /-- **Definition 2.1.** A function `f : α* → β*` is rational if its graph is a rational 55 relation. -/ 56 def IsRationalFun (f : List α → List β) : Prop := 57 IsRationalRel {p : List α × List β | p.2 = f p.1} 58 59 /-- **Definition 2.3.** A function between types is rational if, on string representations, 60 it is computed by a rational function `𝟖* → 𝟖*`. -/ 61 def IsRationalTypeFun {A B : Ty} (f : ⟦A⟧ → ⟦B⟧) : Prop := 62 ∃ f' : List Ty.Sym → List Ty.Sym, 63 IsRationalFun f' ∧ ∀ a : ⟦A⟧, Ty.repr B (f a) = f' (Ty.repr A a) 64 65 end Lax149335.RationalFunctions 66 -
Types
Types are the expressions generated by the grammar
A type denotes a set: is a one-element set, is the Cartesian product, is the disjoint union, and is the set of finite lists over .
Elements of types are represented as strings over the eight-letter alphabet
the element of is written , an element of is written or , a pair is written and a list is written .
A type is a finite alphabet if it has the form . We write for the finite alphabet with letters, bracketed to the right.
1 import Mathlib.Data.Nat.Notation 2 … module docstring, 32 lines 35 36 namespace Lax149335.Types 37 38 /-- Types: the unit type `1`, products `A × B`, co-products `A + B` and lists `A*`. -/ 39 inductive Ty : Type 40 | unit : Ty 41 | prod : Ty → Ty → Ty 42 | sum : Ty → Ty → Ty 43 | list : Ty → Ty 44 deriving DecidableEq, Repr 45 46 namespace Ty 47 48 /-- Notation `A ⊗ B` for the product type. -/ 49 infixl:70 " ⊗ " => Ty.prod 50 /-- Notation `A ⊕' B` for the co-product type. -/ 51 infixl:65 " ⊕' " => Ty.sum 52 /-- Notation `A⋆` for the list type. -/ 53 postfix:max "⋆" => Ty.list 54 55 /-- The set denoted by a type. -/ 56 def den : Ty → Type 57 | .unit => Unit 58 | .prod A B => den A × den B 59 | .sum A B => den A ⊕ den B 60 | .list A => List (den A) 61 62 /-- Notation `⟦A⟧` for the set denoted by a type. -/ 63 notation "⟦" A "⟧" => Ty.den A 64 65 /-- The eight-letter alphabet used to represent elements of types as strings. -/ 66 inductive Sym : Type 67 | lpar | rpar | lbrack | rbrack | comma | one | left | right 68 deriving DecidableEq, Repr 69 70 /-- The string representing an element of a type: `1`, `Left a`, `Right b`, `(a,b)` and 71 `[a₁,…,aₙ]`. -/ 72 def repr : (A : Ty) → ⟦A⟧ → List Sym 73 | .unit, _ => [Sym.one] 74 | .prod A B, (a, b) => Sym.lpar :: (repr A a ++ Sym.comma :: repr B b ++ [Sym.rpar]) 75 | .sum A _, .inl a => Sym.left :: repr A a 76 | .sum _ B, .inr b => Sym.right :: repr B b 77 | .list A, l => 78 Sym.lbrack :: ((l.map (repr A)).intersperse [Sym.comma]).flatten ++ [Sym.rbrack] 79 80 /-- A canonical element of every type. -/ 81 def someElem : (A : Ty) → ⟦A⟧ 82 | .unit => () 83 | .prod A B => (someElem A, someElem B) 84 | .sum A _ => .inl (someElem A) 85 | .list _ => [] 86 87 /-- The finite alphabet `1 + (1 + ⋯ + 1)` with `n + 1` letters. -/ 88 def finAlph : ℕ → Ty 89 | 0 => Ty.unit 90 | (n + 1) => Ty.sum Ty.unit (finAlph n) 91 92 /-- A type is a finite alphabet if it has the form `1 + ⋯ + 1`. -/ 93 def IsFinAlph (A : Ty) : Prop := ∃ n : ℕ, A = finAlph n 94 95 end Ty 96 97 end Lax149335.Types 98 -
Rational functions
A rational relation between strings over alphabets and is a subset of the monoid defined by a regular expression: the atoms are pairs of strings, and the operations are union, concatenation (componentwise) and Kleene star.
Definition 2.1 (Rational function). A function is rational if its graph is a rational relation.
Definition 2.3 (Rational functions on types). A function between types is rational if there is a rational function that agrees with on the string representations of elements, i.e. the string representation of is applied to the string representation of .
1 import Lax149335.Types 2 import Mathlib.Data.Set.Defs 3 … module docstring, 18 lines 22 23 namespace Lax149335.RationalFunctions 24 25 open Lax149335.Types 26 27 variable {α β : Type} 28 29 /-- Regular expressions over the product monoid `α* × β*`. -/ 30 inductive RatExp (α β : Type) : Type 31 | zero : RatExp α β 32 | atom : List α → List β → RatExp α β 33 | plus : RatExp α β → RatExp α β → RatExp α β 34 | cat : RatExp α β → RatExp α β → RatExp α β 35 | star : RatExp α β → RatExp α β 36 37 /-- The submonoid of `α* × β*` generated by a set `S`: all finite products of elements of 38 `S`. -/ 39 inductive StarSet (S : Set (List α × List β)) : List α × List β → Prop 40 | nil : StarSet S ([], []) 41 | cons {x y : List α × List β} : x ∈ S → StarSet S y → StarSet S (x.1 ++ y.1, x.2 ++ y.2) 42 43 /-- The relation defined by a regular expression. -/ 44 def RatExp.lang : RatExp α β → Set (List α × List β) 45 | .zero => ∅ 46 | .atom u v => {(u, v)} 47 | .plus e f => e.lang ∪ f.lang 48 | .cat e f => {p | ∃ x ∈ e.lang, ∃ y ∈ f.lang, p = (x.1 ++ y.1, x.2 ++ y.2)} 49 | .star e => {p | StarSet e.lang p} 50 51 /-- A relation between strings is rational if it is defined by a regular expression. -/ 52 def IsRationalRel (R : Set (List α × List β)) : Prop := ∃ e : RatExp α β, e.lang = R 53 54 /-- **Definition 2.1.** A function `f : α* → β*` is rational if its graph is a rational 55 relation. -/ 56 def IsRationalFun (f : List α → List β) : Prop := 57 IsRationalRel {p : List α × List β | p.2 = f p.1} 58 59 /-- **Definition 2.3.** A function between types is rational if, on string representations, 60 it is computed by a rational function `𝟖* → 𝟖*`. -/ 61 def IsRationalTypeFun {A B : Ty} (f : ⟦A⟧ → ⟦B⟧) : Prop := 62 ∃ f' : List Ty.Sym → List Ty.Sym, 63 IsRationalFun f' ∧ ∀ a : ⟦A⟧, Ty.repr B (f a) = f' (Ty.repr A a) 64 65 end Lax149335.RationalFunctions 66 -
Types
Types are the expressions generated by the grammar
A type denotes a set: is a one-element set, is the Cartesian product, is the disjoint union, and is the set of finite lists over .
Elements of types are represented as strings over the eight-letter alphabet
the element of is written , an element of is written or , a pair is written and a list is written .
A type is a finite alphabet if it has the form . We write for the finite alphabet with letters, bracketed to the right.
1 import Mathlib.Data.Nat.Notation 2 … module docstring, 32 lines 35 36 namespace Lax149335.Types 37 38 /-- Types: the unit type `1`, products `A × B`, co-products `A + B` and lists `A*`. -/ 39 inductive Ty : Type 40 | unit : Ty 41 | prod : Ty → Ty → Ty 42 | sum : Ty → Ty → Ty 43 | list : Ty → Ty 44 deriving DecidableEq, Repr 45 46 namespace Ty 47 48 /-- Notation `A ⊗ B` for the product type. -/ 49 infixl:70 " ⊗ " => Ty.prod 50 /-- Notation `A ⊕' B` for the co-product type. -/ 51 infixl:65 " ⊕' " => Ty.sum 52 /-- Notation `A⋆` for the list type. -/ 53 postfix:max "⋆" => Ty.list 54 55 /-- The set denoted by a type. -/ 56 def den : Ty → Type 57 | .unit => Unit 58 | .prod A B => den A × den B 59 | .sum A B => den A ⊕ den B 60 | .list A => List (den A) 61 62 /-- Notation `⟦A⟧` for the set denoted by a type. -/ 63 notation "⟦" A "⟧" => Ty.den A 64 65 /-- The eight-letter alphabet used to represent elements of types as strings. -/ 66 inductive Sym : Type 67 | lpar | rpar | lbrack | rbrack | comma | one | left | right 68 deriving DecidableEq, Repr 69 70 /-- The string representing an element of a type: `1`, `Left a`, `Right b`, `(a,b)` and 71 `[a₁,…,aₙ]`. -/ 72 def repr : (A : Ty) → ⟦A⟧ → List Sym 73 | .unit, _ => [Sym.one] 74 | .prod A B, (a, b) => Sym.lpar :: (repr A a ++ Sym.comma :: repr B b ++ [Sym.rpar]) 75 | .sum A _, .inl a => Sym.left :: repr A a 76 | .sum _ B, .inr b => Sym.right :: repr B b 77 | .list A, l => 78 Sym.lbrack :: ((l.map (repr A)).intersperse [Sym.comma]).flatten ++ [Sym.rbrack] 79 80 /-- A canonical element of every type. -/ 81 def someElem : (A : Ty) → ⟦A⟧ 82 | .unit => () 83 | .prod A B => (someElem A, someElem B) 84 | .sum A _ => .inl (someElem A) 85 | .list _ => [] 86 87 /-- The finite alphabet `1 + (1 + ⋯ + 1)` with `n + 1` letters. -/ 88 def finAlph : ℕ → Ty 89 | 0 => Ty.unit 90 | (n + 1) => Ty.sum Ty.unit (finAlph n) 91 92 /-- A type is a finite alphabet if it has the form `1 + ⋯ + 1`. -/ 93 def IsFinAlph (A : Ty) : Prop := ∃ n : ℕ, A = finAlph n 94 95 end Ty 96 97 end Lax149335.Types 98 -
Simple rational terms
Definition 2.5 (Simple rational terms). Let be a finite alphabet. The simple rational terms with outputs in are the terms generated from the term , which produces the empty string, by the following combinators:
- co-pairing: for and , the term that applies or depending on the summand;
- concatenation: for and , the term that maps to ;
- homomorphism: for , the term that maps to ;
- constants: for and a string , the terms and , which prepend or append to the output.
A function is represented by a simple rational term if it is the function that the term defines.
1 import Lax149335.Types 2 … module docstring, 27 lines 30 31 namespace Lax149335.SimpleRationalTerms 32 33 open Lax149335.Types 34 35 /-- Simple rational terms `A → Bs*`. -/ 36 inductive SimpleTerm (Bs : Type) : Ty → Type 37 /-- The term `[] : 1 → Bs*` with empty output. -/ 38 | empty : SimpleTerm Bs Ty.unit 39 /-- Co-pairing `⟨f₁, f₂⟩ : A₁ + A₂ → Bs*`. -/ 40 | either {A₁ A₂ : Ty} : SimpleTerm Bs A₁ → SimpleTerm Bs A₂ → SimpleTerm Bs (A₁ ⊕' A₂) 41 /-- Concatenation `f₁ ⊙ f₂ : A₁ × A₂ → Bs*`. -/ 42 | conc {A₁ A₂ : Ty} : SimpleTerm Bs A₁ → SimpleTerm Bs A₂ → SimpleTerm Bs (A₁ ⊗ A₂) 43 /-- Homomorphism `hom f : A* → Bs*`. -/ 44 | hom {A : Ty} : SimpleTerm Bs A → SimpleTerm Bs A⋆ 45 /-- Prepending a string constant, `w · f`. -/ 46 | pre {A : Ty} : List Bs → SimpleTerm Bs A → SimpleTerm Bs A 47 /-- Appending a string constant, `f · w`. -/ 48 | post {A : Ty} : SimpleTerm Bs A → List Bs → SimpleTerm Bs A 49 50 namespace SimpleTerm 51 52 variable {Bs : Type} 53 54 /-- The function defined by a simple rational term. -/ 55 def den : {A : Ty} → SimpleTerm Bs A → ⟦A⟧ → List Bs 56 | _, .empty, _ => [] 57 | _, .either f _, .inl a => den f a 58 | _, .either _ g, .inr b => den g b 59 | _, .conc f g, (a, b) => den f a ++ den g b 60 | _, .hom f, l => (l.map (den f)).flatten 61 | _, .pre w f, a => w ++ den f a 62 | _, .post f w, a => den f a ++ w 63 64 /-- A function is represented by a simple rational term if it is the function that the term 65 defines. -/ 66 def IsSimpleFun {A : Ty} (f : ⟦A⟧ → List Bs) : Prop := ∃ t : SimpleTerm Bs A, t.den = f 67 68 end SimpleTerm 69 70 end Lax149335.SimpleRationalTerms 71 -
Conjugacy completeness
Theorem 2.6 (Conjugacy completeness). Two simple rational terms define the same function if and only if they are equivalent with respect to the least equivalence relation on simple rational terms that satisfies the following rules (where are simple rational terms, are strings and is the empty string):
- Congruence: is preserved by co-pairing, concatenation, homomorphism and adding constants.
- Concatenation monoidality: , , , , , , , and .
- Constants and co-pairing: and .
- Case splitting: if then , and symmetrically on the other side.
- Conjugacy: if then .
1 import Lax149335.SimpleRationalTerms 2 … module docstring, 29 lines 32 33 namespace Lax149335.ConjugacyCompleteness 34 35 open Lax149335.Types Lax149335.SimpleRationalTerms 36 37 namespace SimpleTerm 38 39 /-- The equivalence `≡` of simple rational terms from Theorem 2.6: the least relation closed 40 under (1) congruence, (2) concatenation monoidality, (3) constants and co-pairing, (4) case 41 splitting and (5) conjugacy. -/ 42 inductive SEq {Bs : Type} : {A : Ty} → SimpleTerm Bs A → SimpleTerm Bs A → Prop 43 -- (1) congruence, together with the equivalence relation rules 44 | refl {A : Ty} (f : SimpleTerm Bs A) : SEq f f 45 | symm {A : Ty} {f g : SimpleTerm Bs A} : SEq f g → SEq g f 46 | trans {A : Ty} {f g h : SimpleTerm Bs A} : SEq f g → SEq g h → SEq f h 47 | congr_either {A₁ A₂ : Ty} {f₁ g₁ : SimpleTerm Bs A₁} {f₂ g₂ : SimpleTerm Bs A₂} : 48 SEq f₁ g₁ → SEq f₂ g₂ → SEq (.either f₁ f₂) (.either g₁ g₂) 49 | congr_conc {A₁ A₂ : Ty} {f₁ g₁ : SimpleTerm Bs A₁} {f₂ g₂ : SimpleTerm Bs A₂} : 50 SEq f₁ g₁ → SEq f₂ g₂ → SEq (.conc f₁ f₂) (.conc g₁ g₂) 51 | congr_hom {A : Ty} {f g : SimpleTerm Bs A} : SEq f g → SEq (.hom f) (.hom g) 52 | congr_pre {A : Ty} {f g : SimpleTerm Bs A} (w : List Bs) : 53 SEq f g → SEq (.pre w f) (.pre w g) 54 | congr_post {A : Ty} {f g : SimpleTerm Bs A} (w : List Bs) : 55 SEq f g → SEq (.post f w) (.post g w) 56 -- (2) concatenation monoidality 57 | post_post {A : Ty} (f : SimpleTerm Bs A) (w v : List Bs) : 58 SEq (.post (.post f w) v) (.post f (w ++ v)) 59 | pre_pre {A : Ty} (f : SimpleTerm Bs A) (w v : List Bs) : 60 SEq (.pre w (.pre v f)) (.pre (w ++ v) f) 61 | post_nil {A : Ty} (f : SimpleTerm Bs A) : SEq (.post f []) f 62 | pre_nil {A : Ty} (f : SimpleTerm Bs A) : SEq (.pre [] f) f 63 | pre_post {A : Ty} (f : SimpleTerm Bs A) (w v : List Bs) : 64 SEq (.post (.pre w f) v) (.pre w (.post f v)) 65 | conc_shift {A₁ A₂ : Ty} (f : SimpleTerm Bs A₁) (g : SimpleTerm Bs A₂) (w : List Bs) : 66 SEq (.conc (.post f w) g) (.conc f (.pre w g)) 67 | pre_conc {A₁ A₂ : Ty} (w : List Bs) (f₁ : SimpleTerm Bs A₁) (f₂ : SimpleTerm Bs A₂) : 68 SEq (.pre w (.conc f₁ f₂)) (.conc (.pre w f₁) f₂) 69 | post_conc {A₁ A₂ : Ty} (w : List Bs) (f₁ : SimpleTerm Bs A₁) (f₂ : SimpleTerm Bs A₂) : 70 SEq (.post (.conc f₁ f₂) w) (.conc f₁ (.post f₂ w)) 71 | move_empty (w : List Bs) : 72 SEq (.post (.empty : SimpleTerm Bs Ty.unit) w) (.pre w .empty) 73 -- (3) constants and copairing 74 | pre_either {A₁ A₂ : Ty} (w : List Bs) (f₁ : SimpleTerm Bs A₁) (f₂ : SimpleTerm Bs A₂) : 75 SEq (.pre w (.either f₁ f₂)) (.either (.pre w f₁) (.pre w f₂)) 76 | post_either {A₁ A₂ : Ty} (w : List Bs) (f₁ : SimpleTerm Bs A₁) (f₂ : SimpleTerm Bs A₂) : 77 SEq (.post (.either f₁ f₂) w) (.either (.post f₁ w) (.post f₂ w)) 78 -- (4) case splitting 79 | case_left {A₁ A₂ A : Ty} {f₁ g₁ : SimpleTerm Bs A₁} {f₂ g₂ : SimpleTerm Bs A₂} 80 {h : SimpleTerm Bs A} : 81 SEq (.either (.conc f₁ h) (.conc f₂ h)) (.either (.conc g₁ h) (.conc g₂ h)) → 82 SEq (.conc (.either f₁ f₂) h) (.conc (.either g₁ g₂) h) 83 | case_right {A₁ A₂ A : Ty} {f₁ g₁ : SimpleTerm Bs A₁} {f₂ g₂ : SimpleTerm Bs A₂} 84 {h : SimpleTerm Bs A} : 85 SEq (.either (.conc h f₁) (.conc h f₂)) (.either (.conc h g₁) (.conc h g₂)) → 86 SEq (.conc h (.either f₁ f₂)) (.conc h (.either g₁ g₂)) 87 -- (5) conjugacy 88 | conjugacy {A : Ty} {f g : SimpleTerm Bs A} (w : List Bs) : 89 SEq (.post f w) (.pre w g) → SEq (.post (.hom f) w) (.pre w (.hom g)) 90 91 /-- Notation `f ≃ₛ g` for the equivalence of simple rational terms. -/ 92 infix:50 " ≃ₛ " => SEq 93 94 end SimpleTerm 95 96 /-- **Theorem 2.6.** Two simple rational terms define the same function if and only if they 97 are equivalent. -/ 98 axiom conjugacy_completeness {Bs : Type} {A : Ty} (f g : SimpleTerm Bs A) : 99 f.den = g.den ↔ f ≃ₛ g 100 101 end Lax149335.ConjugacyCompleteness 102 -
Synchronised output lengths
Claim 2.7. This claim arises in the induction step for products in the proof of Theorem 2.6. Consider two simple rational terms with input type of the form
that define the same function. Then for every and every , the strings and have the same length.
1 import Lax149335.SimpleRationalTerms 2 … module docstring, 21 lines 24 25 namespace Lax149335.SynchronisedLengths 26 27 open Lax149335.Types Lax149335.SimpleRationalTerms 28 29 namespace SimpleTerm 30 31 variable {Bs : Type} 32 33 /-- The type `A₁* × (A₂* × ⋯ × (Aₙ* × 1))`. -/ 34 def prodListTy : List Ty → Ty 35 | [] => Ty.unit 36 | A :: As => Ty.prod A⋆ (prodListTy As) 37 38 /-- A list of pairs `(fᵢ, wᵢ)` of a simple rational term `fᵢ : Aᵢ → Bs*` and a string `wᵢ`. -/ 39 inductive HomList (Bs : Type) : List Ty → Type 40 | nil : HomList Bs [] 41 | cons {A : Ty} {As : List Ty} : SimpleTerm Bs A → List Bs → HomList Bs As → 42 HomList Bs (A :: As) 43 44 /-- The term `(hom f₁ · w₁) ⊙ ⋯ ⊙ (hom fₙ · wₙ)` of a list of pairs. -/ 45 def HomList.term : {As : List Ty} → HomList Bs As → SimpleTerm Bs (prodListTy As) 46 | _, .nil => .empty 47 | _, .cons f w rest => .conc (.post (.hom f) w) rest.term 48 49 /-- Two lists of pairs whose terms `fᵢ` and `gᵢ` produce outputs of the same length on every 50 input. -/ 51 def HomList.SameLengths : {As : List Ty} → HomList Bs As → HomList Bs As → Prop 52 | _, .nil, .nil => True 53 | _, .cons f _ F, .cons g _ G => 54 (∀ a, (f.den a).length = (g.den a).length) ∧ HomList.SameLengths F G 55 56 end SimpleTerm 57 58 open SimpleTerm 59 60 /-- **Claim 2.7.** If `w₀ · (hom f₁ · w₁) ⊙ ⋯ ⊙ (hom fₙ · wₙ)` and 61 `v₀ · (hom g₁ · v₁) ⊙ ⋯ ⊙ (hom gₙ · vₙ)` define the same function, then `fᵢ` and `gᵢ` produce 62 outputs of the same length on every input. -/ 63 axiom claim_same_lengths {Bs : Type} {As : List Ty} (F G : HomList Bs As) (w₀ v₀ : List Bs) : 64 (SimpleRationalTerms.SimpleTerm.pre w₀ F.term).den = 65 (SimpleRationalTerms.SimpleTerm.pre v₀ G.term).den → 66 F.SameLengths G 67 68 end Lax149335.SynchronisedLengths 69 -
Equivalence of simple rational terms is decidable
Corollary 2.8. Equivalence for simple rational terms is decidable in polynomial time.
1 import Lax149335.SimpleRationalTerms 2 … module docstring, 25 lines 28 29 namespace Lax149335.DecidableEquivalence 30 31 open Lax149335.Types Lax149335.SimpleRationalTerms 32 33 /-- The test inputs `T(A)` of a type. -/ 34 def testInputs : (A : Ty) → List ⟦A⟧ 35 | .unit => [()] 36 | .sum A₁ A₂ => (testInputs A₁).map Sum.inl ++ (testInputs A₂).map Sum.inr 37 | .prod A₁ A₂ => 38 (testInputs A₁).map (fun a => (a, Ty.someElem A₂)) ++ 39 (testInputs A₂).map (fun b => (Ty.someElem A₁, b)) 40 | .list A => [] :: (testInputs A).map (fun a => [a]) 41 42 /-- **Corollary 2.8.** Two simple rational terms define the same function if and only if they 43 agree on all test inputs. -/ 44 axiom decidable_equivalence {Bs : Type} {A : Ty} (f g : SimpleTerm Bs A) : 45 f.den = g.den ↔ ∀ x ∈ testInputs A, f.den x = g.den x 46 47 end Lax149335.DecidableEquivalence 48 -
Simplification of rational terms
Theorem 2.9 (Simplification of rational terms). Consider rational terms where and are finite alphabets. There is a type and a rational term with surjective denotation, such that and are represented by simple rational terms.
1 import Lax149335.SimpleRationalTerms 2 import Lax149335.Terms 3 … module docstring, 16 lines 20 21 namespace Lax149335.Simplification 22 23 open Lax149335.Types Lax149335.Terms Lax149335.SimpleRationalTerms 24 25 /-- **Theorem 2.9.** After precomposing with a rational term with surjective denotation, two 26 rational terms `N* → M*` are represented by simple rational terms. -/ 27 axiom simplification_of_rational_terms {N M : Ty} (hN : Ty.IsFinAlph N) 28 (hM : Ty.IsFinAlph M) (f g : Term N⋆ M⋆) : 29 ∃ (C : Ty) (π : Term C N⋆), Function.Surjective π.den ∧ 30 SimpleTerm.IsSimpleFun (Bs := ⟦M⟧) (π ⨟ f).den ∧ 31 SimpleTerm.IsSimpleFun (Bs := ⟦M⟧) (π ⨟ g).den 32 33 end Lax149335.Simplification 34 -
Rational terms
Definition 3.1 (Rational terms). A rational term between types is an expression built from the following atomic functions (Figure 1) using composition and the functoriality combinators , and of products, co-products and lists:
- the identity ;
- the co-projections and ;
- the co-diagonal ;
- the projections and ;
- the units and , and associativity of products in both directions;
- distributivity and ;
- the list constructors and destructors , , and ;
- list concatenation ;
- , which cuts a list before every element of ;
- bracket shifting and its inverse ;
- prefix multiplication for a finite group , which replaces the -th group element by the product of the first ones.
The denotation of a rational term is the function it defines. A rational term is aperiodic if it does not use prefix multiplication.
1 import Lax149335.Types 2 import Mathlib.Algebra.Group.Defs 3 … module docstring, 36 lines 40 41 namespace Lax149335.Terms 42 43 open Lax149335.Types 44 45 /-- Auxiliary function used for the denotation of the group prefix multiplication: the `i`-th 46 group element of the output is the product of the first `i` group elements of the input. -/ 47 def prefixMul {α G : Type} [Mul G] : G → List (α × G) → List (α × G) 48 | _, [] => [] 49 | acc, (a, g) :: t => (a, acc * g) :: prefixMul (acc * g) t 50 51 /-- Auxiliary function used for the denotation of `block`: a list over `A + B` is split into a 52 maximal prefix of elements of `A`, followed by a list of blocks, each consisting of one 53 element of `B` and the following maximal run of elements of `A`. -/ 54 def blockDen {α β : Type} : List (α ⊕ β) → List α × List (β × List α) 55 | [] => ([], []) 56 | .inl a :: t => let p := blockDen t; (a :: p.1, p.2) 57 | .inr b :: t => let p := blockDen t; ([], (b, p.1) :: p.2) 58 59 /-- Auxiliary function used for the denotation of `snoc`. -/ 60 def snocDen {α : Type} : Unit ⊕ (List α × α) → List α 61 | .inl _ => [] 62 | .inr (l, a) => l ++ [a] 63 64 /-- Auxiliary function used for the denotation of `unsnoc`. -/ 65 def unsnocDen {α : Type} (l : List α) : Unit ⊕ (List α × α) := 66 match l.reverse with 67 | [] => .inl () 68 | a :: t => .inr (t.reverse, a) 69 70 /-- Auxiliary function used for the denotation of `shiftR`. -/ 71 def shiftRDen {α β : Type} : List (α × β) → α → α × List (β × α) 72 | [], a => (a, []) 73 | (a₁, b₁) :: t, a => let p := shiftRDen t a; (a₁, (b₁, p.1) :: p.2) 74 75 /-- Auxiliary function used for the denotation of `shiftL`. -/ 76 def shiftLDen {α β : Type} (a : α) : List (β × α) → List (α × β) × α 77 | [] => ([], a) 78 | (b₁, a₂) :: t => let p := shiftLDen a₂ t; ((a, b₁) :: p.1, p.2) 79 80 /-- **Definition 3.1 (Rational terms).** The expressions built from the atomic functions of 81 Figure 1 by composition and the functoriality combinators of products, co-products and 82 lists. -/ 83 inductive Term : Ty → Ty → Type 84 /-- Composition of functions. -/ 85 | comp {A B C : Ty} : Term A B → Term B C → Term A C 86 /-- Functoriality of the product type constructor. -/ 87 | prodF {A₁ A₂ B₁ B₂ : Ty} : Term A₁ B₁ → Term A₂ B₂ → Term (A₁ ⊗ A₂) (B₁ ⊗ B₂) 88 /-- Functoriality of the co-product type constructor. -/ 89 | sumF {A₁ A₂ B₁ B₂ : Ty} : Term A₁ B₁ → Term A₂ B₂ → Term (A₁ ⊕' A₂) (B₁ ⊕' B₂) 90 /-- Functoriality of the list type constructor. -/ 91 | listF {A B : Ty} : Term A B → Term A⋆ B⋆ 92 /-- Atomic function 1: the identity. -/ 93 | id (A : Ty) : Term A A 94 /-- Atomic function 2: the left co-projection. -/ 95 | inl (A B : Ty) : Term A (A ⊕' B) 96 /-- Atomic function 2: the right co-projection. -/ 97 | inr (A B : Ty) : Term B (A ⊕' B) 98 /-- Atomic function 3: the co-diagonal. -/ 99 | codiag (A : Ty) : Term (A ⊕' A) A 100 /-- Atomic function 4: the first projection. -/ 101 | fst (A B : Ty) : Term (A ⊗ B) A 102 /-- Atomic function 4: the second projection. -/ 103 | snd (A B : Ty) : Term (A ⊗ B) B 104 /-- Atomic function 5: the right unit `(id, 1)`. -/ 105 | unitR (A : Ty) : Term A (A ⊗ Ty.unit) 106 /-- Atomic function 5: the left unit `(1, id)`. -/ 107 | unitL (A : Ty) : Term A (Ty.unit ⊗ A) 108 /-- Atomic function 5: left associativity of products. -/ 109 | assocL (A B C : Ty) : Term (A ⊗ (B ⊗ C)) ((A ⊗ B) ⊗ C) 110 /-- Atomic function 5: right associativity of products. -/ 111 | assocR (A B C : Ty) : Term ((A ⊗ B) ⊗ C) (A ⊗ (B ⊗ C)) 112 /-- Atomic function 6: distributivity on the right. -/ 113 | distR (A B C : Ty) : Term (A ⊗ (B ⊕' C)) ((A ⊗ B) ⊕' (A ⊗ C)) 114 /-- Atomic function 6: distributivity on the left. -/ 115 | distL (A B C : Ty) : Term ((A ⊕' B) ⊗ C) ((A ⊗ C) ⊕' (B ⊗ C)) 116 /-- Atomic function 7: the list constructor `cons`. -/ 117 | cons (A : Ty) : Term (Ty.unit ⊕' (A ⊗ A⋆)) A⋆ 118 /-- Atomic function 7: the list destructor `uncons`. -/ 119 | uncons (A : Ty) : Term A⋆ (Ty.unit ⊕' (A ⊗ A⋆)) 120 /-- Atomic function 7: the list constructor `snoc`. -/ 121 | snoc (A : Ty) : Term (Ty.unit ⊕' (A⋆ ⊗ A)) A⋆ 122 /-- Atomic function 7: the list destructor `unsnoc`. -/ 123 | unsnoc (A : Ty) : Term A⋆ (Ty.unit ⊕' (A⋆ ⊗ A)) 124 /-- Atomic function 8: concatenation of a list of lists. -/ 125 | concat (A : Ty) : Term A⋆⋆ A⋆ 126 /-- Atomic function 9: cutting a list over a co-product into blocks. -/ 127 | block (A B : Ty) : Term (A ⊕' B)⋆ (A⋆ ⊗ (B ⊗ A⋆)⋆) 128 /-- Atomic function 10: shifting brackets to the right. -/ 129 | shiftR (A B : Ty) : Term ((A ⊗ B)⋆ ⊗ A) (A ⊗ (B ⊗ A)⋆) 130 /-- Atomic function 10: shifting brackets to the left. -/ 131 | shiftL (A B : Ty) : Term (A ⊗ (B ⊗ A)⋆) ((A ⊗ B)⋆ ⊗ A) 132 /-- Atomic function 11: prefix multiplication in a finite group whose underlying set is the 133 finite alphabet `1 + ⋯ + 1`. -/ 134 | pref (A : Ty) {n : ℕ} (G : Group ⟦Ty.finAlph n⟧) : 135 Term ((A ⊗ Ty.finAlph n)⋆) ((A ⊗ Ty.finAlph n)⋆) 136 137 namespace Term 138 139 /-- Notation `f ⨟ g` for the composition of rational terms: first `f`, then `g`. -/ 140 infixl:60 " ⨟ " => Term.comp 141 142 /-- The denotation `⟦f⟧` of a rational term: the function that it defines. -/ 143 def den : {A B : Ty} → Term A B → ⟦A⟧ → ⟦B⟧ 144 | _, _, .comp f g, x => den g (den f x) 145 | _, _, .prodF f g, x => (den f x.1, den g x.2) 146 | _, _, .sumF f g, x => 147 match x with 148 | .inl a => .inl (den f a) 149 | .inr b => .inr (den g b) 150 | _, _, .listF f, l => l.map (den f) 151 | _, _, .id _, x => x 152 | _, _, .inl _ _, x => .inl x 153 | _, _, .inr _ _, x => .inr x 154 | _, _, .codiag _, x => match x with | .inl a => a | .inr a => a 155 | _, _, .fst _ _, x => x.1 156 | _, _, .snd _ _, x => x.2 157 | _, _, .unitR _, x => (x, ()) 158 | _, _, .unitL _, x => ((), x) 159 | _, _, .assocL _ _ _, x => ((x.1, x.2.1), x.2.2) 160 | _, _, .assocR _ _ _, x => (x.1.1, (x.1.2, x.2)) 161 | _, _, .distR _ _ _, x => 162 match x with 163 | (a, .inl b) => .inl (a, b) 164 | (a, .inr c) => .inr (a, c) 165 | _, _, .distL _ _ _, x => 166 match x with 167 | (.inl a, c) => .inl (a, c) 168 | (.inr b, c) => .inr (b, c) 169 | _, _, .cons _, x => match x with | .inl _ => [] | .inr (a, l) => a :: l 170 | _, _, .uncons _, l => match l with | [] => .inl () | a :: t => .inr (a, t) 171 | _, _, .snoc _, x => snocDen x 172 | _, _, .unsnoc _, l => unsnocDen l 173 | _, _, .concat _, l => l.flatten 174 | _, _, .block _ _, l => blockDen l 175 | _, _, .shiftR _ _, x => match x with | (l, a) => shiftRDen l a 176 | _, _, .shiftL _ _, x => match x with | (a, l) => shiftLDen a l 177 | _, _, .pref _ G, l => letI := G; prefixMul (1 : ⟦Ty.finAlph _⟧) l 178 179 /-- Whether a rational term uses the atomic function `pref` for prefix multiplication in 180 groups. -/ 181 def usesPref : {A B : Ty} → Term A B → Bool 182 | _, _, .comp f g => usesPref f || usesPref g 183 | _, _, .prodF f g => usesPref f || usesPref g 184 | _, _, .sumF f g => usesPref f || usesPref g 185 | _, _, .listF f => usesPref f 186 | _, _, .pref _ _ => true 187 | _, _, _ => false 188 189 end Term 190 191 /-- A rational term is aperiodic if it does not use the group prefix multiplication `pref`. -/ 192 def IsAperiodic {A B : Ty} (f : Term A B) : Prop := Term.usesPref f = false 193 194 end Lax149335.Terms 195 -
Derived terms
The following terms are derived from the atomic functions and combinators of Definition 3.1. They are used to state the axioms of Section 4 and the results of the completeness proof.
- The unique term , co-pairing , commutativity and associativity of co-products.
- The list notation of Section 4.6: the empty list , , , , , the homomorphism combinator , and the concatenation of two terms with list outputs.
- The inverses of distributivity, and (Section 4.4).
- Definition 5.1 (Value). A value is a term of type . For a list value , the terms and prepend or append the output of to the output of (Section 5.2), and returns the first element of a list, or the output of for the empty list.
- Concatenation maps (Section 5.1). For a type constructor with one parameter, built from the parameter, , , and , the concatenation map lists all the elements of occurring in the input, from left to right. Similarly for type constructors with two parameters, with outputs in . In particular, is a concatenation map.
- The terms and of Table 1.
- The inverse of group prefix multiplication (Section 4.4), which maps to , where is the group identity.
1 import Lax149335.Terms 2 … module docstring, 39 lines 42 43 namespace Lax149335.DerivedTerms 44 45 open Lax149335.Types Lax149335.Terms 46 47 namespace Term 48 49 open Lax149335.Terms.Term 50 51 /-- The unique function into the unit type, `A → 1`. -/ 52 def toUnit (A : Ty) : Term A Ty.unit := unitL A ⨟ fst Ty.unit A 53 54 /-- Co-pairing, a derived combinator: `either f₁ f₂ = (f₁ + f₂); codiag`. -/ 55 def either {A₁ A₂ B : Ty} (f₁ : Term A₁ B) (f₂ : Term A₂ B) : Term (A₁ ⊕' A₂) B := 56 sumF f₁ f₂ ⨟ codiag B 57 58 /-- Commutativity of the co-product, a derived term. -/ 59 def comm (A B : Ty) : Term (A ⊕' B) (B ⊕' A) := either (inr B A) (inl B A) 60 61 /-- Associativity of the co-product, from left to right. -/ 62 def sumAssocR (A B C : Ty) : Term ((A ⊕' B) ⊕' C) (A ⊕' (B ⊕' C)) := 63 either (either (inl A (B ⊕' C)) (inl B C ⨟ inr A (B ⊕' C))) (inr B C ⨟ inr A (B ⊕' C)) 64 65 /-- Associativity of the co-product, from right to left. -/ 66 def sumAssocL (A B C : Ty) : Term (A ⊕' (B ⊕' C)) ((A ⊕' B) ⊕' C) := 67 either (inl A B ⨟ inl (A ⊕' B) C) 68 (either (inr A B ⨟ inl (A ⊕' B) C) (inr (A ⊕' B) C)) 69 70 /-- The empty list `[] : 1 → A*`, defined as `Left; cons`. -/ 71 def nilT (A : Ty) : Term Ty.unit A⋆ := inl Ty.unit (A ⊗ A⋆) ⨟ cons A 72 73 /-- `prepend : A × A* → A*`, defined as `Right; cons`. -/ 74 def prepend (A : Ty) : Term (A ⊗ A⋆) A⋆ := inr Ty.unit (A ⊗ A⋆) ⨟ cons A 75 76 /-- `append : A* × A → A*`, defined as `Right; snoc`. -/ 77 def append (A : Ty) : Term (A⋆ ⊗ A) A⋆ := inr Ty.unit (A⋆ ⊗ A) ⨟ snoc A 78 79 /-- `pure : A → A*`, defined as `(id,1); id × []; prepend`. -/ 80 def pureT (A : Ty) : Term A A⋆ := 81 unitR A ⨟ prodF (Term.id A) (nilT A) ⨟ prepend A 82 83 /-- `binconcat : A* × A* → A*`, defined as `(id × pure); prepend; concat`. -/ 84 def binconcat (A : Ty) : Term (A⋆ ⊗ A⋆) A⋆ := 85 prodF (Term.id A⋆) (pureT A⋆) ⨟ prepend A⋆ ⨟ concat A 86 87 /-- The homomorphism combinator `hom f = f*; concat`. -/ 88 def homT {A B : Ty} (f : Term A B⋆) : Term A⋆ B⋆ := listF f ⨟ concat B 89 90 /-- Concatenation of two functions with list outputs, `f ⊙ g = (f × g); binconcat`. -/ 91 def fdot {A₁ A₂ B : Ty} (f : Term A₁ B⋆) (g : Term A₂ B⋆) : Term (A₁ ⊗ A₂) B⋆ := 92 prodF f g ⨟ binconcat B 93 94 /-- Notation `f ⊙ g` for the concatenation of two terms with list outputs. -/ 95 infixl:65 " ⊙ " => Term.fdot 96 97 /-- The inverse of distributivity on the right, 98 `undistR = either (id × Left) (id × Right)`. -/ 99 def undistR (A B C : Ty) : Term ((A ⊗ B) ⊕' (A ⊗ C)) (A ⊗ (B ⊕' C)) := 100 either (prodF (Term.id A) (inl B C)) (prodF (Term.id A) (inr B C)) 101 102 /-- The inverse of distributivity on the left. -/ 103 def undistL (A B C : Ty) : Term ((A ⊗ C) ⊕' (B ⊗ C)) ((A ⊕' B) ⊗ C) := 104 either (prodF (inl A B) (Term.id C)) (prodF (inr A B) (Term.id C)) 105 106 -- Values and concatenation with values (Section 5.2) 107 108 /-- **Definition 5.1 (Value).** A value is a term of type `1 → A`. -/ 109 abbrev Value (A : Ty) : Type := Term Ty.unit A 110 111 /-- Pairing a value on the left with an arbitrary term: `(v,f) = (1,id); (v × f)`. -/ 112 def pairL {A B C : Ty} (v : Value C) (f : Term A B) : Term A (C ⊗ B) := 113 unitL A ⨟ prodF v f 114 115 /-- Pairing a value on the right with an arbitrary term: `(f,v) = (id,1); (f × v)`. -/ 116 def pairR {A B C : Ty} (f : Term A B) (v : Value C) : Term A (B ⊗ C) := 117 unitR A ⨟ prodF f v 118 119 /-- Concatenation of a list value on the left with a term with list outputs, `w · f`. -/ 120 def dotL {A B : Ty} (w : Value B⋆) (f : Term A B⋆) : Term A B⋆ := 121 pairL w f ⨟ binconcat B 122 123 /-- Concatenation of a term with list outputs with a list value on the right, `f · w`. -/ 124 def dotR {A B : Ty} (f : Term A B⋆) (w : Value B⋆) : Term A B⋆ := 125 pairR f w ⨟ binconcat B 126 127 /-- The singleton list value `[v] = v; pure`. -/ 128 def sing {A : Ty} (v : Value A) : Value A⋆ := v ⨟ pureT A 129 130 /-- The *head term for `w`*: the first element of a list, or the value `w` if the list is 131 empty. -/ 132 def headT {A : Ty} (w : Value A) : Term A⋆ A := 133 uncons A ⨟ either w (fst A A⋆) 134 135 -- Concatenation maps (Section 5.1) 136 137 /-- Type constructors with one parameter, used to define concatenation maps. -/ 138 inductive TyF : Type 139 /-- The parameter itself. -/ 140 | param : TyF 141 /-- The unit type. -/ 142 | unit : TyF 143 /-- Product of two type constructors. -/ 144 | prod : TyF → TyF → TyF 145 /-- Co-product of two type constructors. -/ 146 | sum : TyF → TyF → TyF 147 /-- List of a type constructor. -/ 148 | list : TyF → TyF 149 150 /-- The type `F(A)` obtained by substituting the type `A` for the parameter of `F`. -/ 151 def TyF.app : TyF → Ty → Ty 152 | .param, A => A 153 | .unit, _ => Ty.unit 154 | .prod F G, A => (F.app A) ⊗ (G.app A) 155 | .sum F G, A => (F.app A) ⊕' (G.app A) 156 | .list F, A => (F.app A)⋆ 157 158 /-- **Concatenation maps** (Section 5.1): the term `F(A) ↣ A*` that concatenates all the 159 elements of the input into a single list, defined by induction on `F`. -/ 160 def TyF.concatMap : (F : TyF) → (A : Ty) → Term (F.app A) A⋆ 161 | .param, A => pureT A 162 | .unit, A => nilT A 163 | .prod F G, A => (F.concatMap A) ⊙ (G.concatMap A) 164 | .sum F G, A => either (F.concatMap A) (G.concatMap A) 165 | .list F, A => homT (F.concatMap A) 166 167 /-- The type constructor `A ↦ Aᵏ`, the `k`-fold product of the parameter with itself. -/ 168 def TyF.pow : ℕ → TyF 169 | 0 => .unit 170 | (k + 1) => .prod .param (TyF.pow k) 171 172 /-- The type constructor `A ↦ A⁰ + A¹ + ⋯ + Aᵏ`, i.e. `A^{<k+1}` in the notation of the 173 paper. -/ 174 def TyF.lt : ℕ → TyF 175 | 0 => TyF.pow 0 176 | (k + 1) => .sum (TyF.lt k) (TyF.pow (k + 1)) 177 178 /-- Type constructors with two parameters, used for the concatenation maps with values in 179 `(A + B)*` that occur in Axiom 15 and in the definition of `unblock`. -/ 180 inductive TyF2 : Type 181 /-- The first parameter. -/ 182 | p1 : TyF2 183 /-- The second parameter. -/ 184 | p2 : TyF2 185 /-- The unit type. -/ 186 | unit : TyF2 187 /-- Product of two type constructors. -/ 188 | prod : TyF2 → TyF2 → TyF2 189 /-- Co-product of two type constructors. -/ 190 | sum : TyF2 → TyF2 → TyF2 191 /-- List of a type constructor. -/ 192 | list : TyF2 → TyF2 193 194 /-- The type `F(A,B)`. -/ 195 def TyF2.app : TyF2 → Ty → Ty → Ty 196 | .p1, A, _ => A 197 | .p2, _, B => B 198 | .unit, _, _ => Ty.unit 199 | .prod F G, A, B => (F.app A B) ⊗ (G.app A B) 200 | .sum F G, A, B => (F.app A B) ⊕' (G.app A B) 201 | .list F, A, B => (F.app A B)⋆ 202 203 /-- The concatenation map `F(A,B) ↣ (A+B)*`, which injects the elements of `A` and of `B` 204 into the co-product `A + B` and concatenates all of them. -/ 205 def TyF2.concatMap : (F : TyF2) → (A B : Ty) → Term (F.app A B) (A ⊕' B)⋆ 206 | .p1, A, B => inl A B ⨟ pureT (A ⊕' B) 207 | .p2, A, B => inr A B ⨟ pureT (A ⊕' B) 208 | .unit, A, B => nilT (A ⊕' B) 209 | .prod F G, A, B => (F.concatMap A B) ⊙ (G.concatMap A B) 210 | .sum F G, A, B => either (F.concatMap A B) (G.concatMap A B) 211 | .list F, A, B => homT (F.concatMap A B) 212 213 /-- The inverse of `block`: it injects `A` and `B` into the co-product `A + B` and then 214 concatenates all resulting lists. -/ 215 def unblock (A B : Ty) : Term (A⋆ ⊗ (B ⊗ A⋆)⋆) (A ⊕' B)⋆ := 216 TyF2.concatMap (.prod (.list .p1) (.list (.prod .p2 (.list .p1)))) A B 217 218 -- The terms `shift` and `unshift` of Table 1 219 220 /-- The lift `shift : (A × B)* ⊸ 1 + A × (B × A)* × B`, obtained by composing `uncons`, 221 `assocR` and `shiftL`. -/ 222 def shift (A B : Ty) : Term ((A ⊗ B)⋆) (Ty.unit ⊕' (A ⊗ ((B ⊗ A)⋆ ⊗ B))) := 223 uncons (A ⊗ B) ⨟ 224 sumF (Term.id Ty.unit) (assocR A B ((A ⊗ B)⋆) ⨟ prodF (Term.id A) (shiftL B A)) 225 226 /-- The drop `unshift : 1 + A × (B × A)* × B ⇒ (A × B)*`, the inverse of `shift`. -/ 227 def unshift (A B : Ty) : Term (Ty.unit ⊕' (A ⊗ ((B ⊗ A)⋆ ⊗ B))) ((A ⊗ B)⋆) := 228 sumF (Term.id Ty.unit) (prodF (Term.id A) (shiftR B A) ⨟ assocL A B ((A ⊗ B)⋆)) ⨟ cons (A ⊗ B) 229 230 -- Terms for finite alphabets and the inverse of the group prefix operation 231 232 /-- The value `1 → 1 + ⋯ + 1` that picks out a given letter of a finite alphabet. -/ 233 def constFin : {n : ℕ} → ⟦Ty.finAlph n⟧ → Value (Ty.finAlph n) 234 | 0, _ => Term.id Ty.unit 235 | (_ + 1), .inl _ => inl Ty.unit _ 236 | (_ + 1), .inr g => constFin g ⨟ inr Ty.unit _ 237 238 /-- Case analysis on a letter of a finite alphabet that appears as the right component of a 239 product; it is derived using distributivity and co-pairing. -/ 240 def caseR : {n : ℕ} → {A B : Ty} → (⟦Ty.finAlph n⟧ → Term A B) → Term (A ⊗ Ty.finAlph n) B 241 | 0, A, _, t => fst A Ty.unit ⨟ t () 242 | (n + 1), A, _, t => 243 distR A Ty.unit (Ty.finAlph n) ⨟ 244 either (fst A Ty.unit ⨟ t (.inl ())) (caseR (fun g => t (.inr g))) 245 246 /-- Case analysis on a letter of a finite alphabet that appears as the left component of a 247 product. -/ 248 def caseL : {n : ℕ} → {A B : Ty} → (⟦Ty.finAlph n⟧ → Term A B) → Term (Ty.finAlph n ⊗ A) B 249 | 0, A, _, t => snd Ty.unit A ⨟ t () 250 | (n + 1), A, _, t => 251 distL Ty.unit (Ty.finAlph n) A ⨟ 252 either (snd Ty.unit A ⨟ t (.inl ())) (caseL (fun g => t (.inr g))) 253 254 /-- The term `(a,g) ↦ (g,(a,g))`, admissible because the group is a finite alphabet. -/ 255 def grepeat (A : Ty) (n : ℕ) : Term (A ⊗ Ty.finAlph n) (Ty.finAlph n ⊗ (A ⊗ Ty.finAlph n)) := 256 caseR (fun g => pairL (constFin g) (pairR (Term.id A) (constFin g))) 257 258 /-- The term `(h,(g,a)) ↦ (a, h⁻¹ · g)`, admissible because the group is a finite 259 alphabet. -/ 260 def gdiv (A : Ty) {n : ℕ} (G : Group ⟦Ty.finAlph n⟧) : 261 Term (Ty.finAlph n ⊗ (Ty.finAlph n ⊗ A)) (A ⊗ Ty.finAlph n) := 262 caseL (fun h => caseL (fun g => pairR (Term.id A) (constFin (letI := G; h⁻¹ * g)))) 263 264 /-- The unprefixing operation, the inverse of the group prefix multiplication: 265 `[(a₁,g₁),…,(aₙ,gₙ)] ↦ [(a₁,g₀⁻¹g₁),(a₂,g₁⁻¹g₂),…,(aₙ,gₙ₋₁⁻¹gₙ)]`, where `g₀` is the group 266 identity. -/ 267 def unpref (A : Ty) {n : ℕ} (G : Group ⟦Ty.finAlph n⟧) : 268 Term ((A ⊗ Ty.finAlph n)⋆) ((A ⊗ Ty.finAlph n)⋆) := 269 listF (grepeat A n) ⨟ 270 listF (assocL (Ty.finAlph n) A (Ty.finAlph n)) ⨟ 271 pairL (constFin (letI := G; (1 : ⟦Ty.finAlph n⟧))) (Term.id _) ⨟ 272 shiftL (Ty.finAlph n) (Ty.finAlph n ⊗ A) ⨟ 273 fst _ _ ⨟ listF (gdiv A G) 274 275 end Term 276 277 end Lax149335.DerivedTerms 278 -
Rational terms
Definition 3.1 (Rational terms). A rational term between types is an expression built from the following atomic functions (Figure 1) using composition and the functoriality combinators , and of products, co-products and lists:
- the identity ;
- the co-projections and ;
- the co-diagonal ;
- the projections and ;
- the units and , and associativity of products in both directions;
- distributivity and ;
- the list constructors and destructors , , and ;
- list concatenation ;
- , which cuts a list before every element of ;
- bracket shifting and its inverse ;
- prefix multiplication for a finite group , which replaces the -th group element by the product of the first ones.
The denotation of a rational term is the function it defines. A rational term is aperiodic if it does not use prefix multiplication.
1 import Lax149335.Types 2 import Mathlib.Algebra.Group.Defs 3 … module docstring, 36 lines 40 41 namespace Lax149335.Terms 42 43 open Lax149335.Types 44 45 /-- Auxiliary function used for the denotation of the group prefix multiplication: the `i`-th 46 group element of the output is the product of the first `i` group elements of the input. -/ 47 def prefixMul {α G : Type} [Mul G] : G → List (α × G) → List (α × G) 48 | _, [] => [] 49 | acc, (a, g) :: t => (a, acc * g) :: prefixMul (acc * g) t 50 51 /-- Auxiliary function used for the denotation of `block`: a list over `A + B` is split into a 52 maximal prefix of elements of `A`, followed by a list of blocks, each consisting of one 53 element of `B` and the following maximal run of elements of `A`. -/ 54 def blockDen {α β : Type} : List (α ⊕ β) → List α × List (β × List α) 55 | [] => ([], []) 56 | .inl a :: t => let p := blockDen t; (a :: p.1, p.2) 57 | .inr b :: t => let p := blockDen t; ([], (b, p.1) :: p.2) 58 59 /-- Auxiliary function used for the denotation of `snoc`. -/ 60 def snocDen {α : Type} : Unit ⊕ (List α × α) → List α 61 | .inl _ => [] 62 | .inr (l, a) => l ++ [a] 63 64 /-- Auxiliary function used for the denotation of `unsnoc`. -/ 65 def unsnocDen {α : Type} (l : List α) : Unit ⊕ (List α × α) := 66 match l.reverse with 67 | [] => .inl () 68 | a :: t => .inr (t.reverse, a) 69 70 /-- Auxiliary function used for the denotation of `shiftR`. -/ 71 def shiftRDen {α β : Type} : List (α × β) → α → α × List (β × α) 72 | [], a => (a, []) 73 | (a₁, b₁) :: t, a => let p := shiftRDen t a; (a₁, (b₁, p.1) :: p.2) 74 75 /-- Auxiliary function used for the denotation of `shiftL`. -/ 76 def shiftLDen {α β : Type} (a : α) : List (β × α) → List (α × β) × α 77 | [] => ([], a) 78 | (b₁, a₂) :: t => let p := shiftLDen a₂ t; ((a, b₁) :: p.1, p.2) 79 80 /-- **Definition 3.1 (Rational terms).** The expressions built from the atomic functions of 81 Figure 1 by composition and the functoriality combinators of products, co-products and 82 lists. -/ 83 inductive Term : Ty → Ty → Type 84 /-- Composition of functions. -/ 85 | comp {A B C : Ty} : Term A B → Term B C → Term A C 86 /-- Functoriality of the product type constructor. -/ 87 | prodF {A₁ A₂ B₁ B₂ : Ty} : Term A₁ B₁ → Term A₂ B₂ → Term (A₁ ⊗ A₂) (B₁ ⊗ B₂) 88 /-- Functoriality of the co-product type constructor. -/ 89 | sumF {A₁ A₂ B₁ B₂ : Ty} : Term A₁ B₁ → Term A₂ B₂ → Term (A₁ ⊕' A₂) (B₁ ⊕' B₂) 90 /-- Functoriality of the list type constructor. -/ 91 | listF {A B : Ty} : Term A B → Term A⋆ B⋆ 92 /-- Atomic function 1: the identity. -/ 93 | id (A : Ty) : Term A A 94 /-- Atomic function 2: the left co-projection. -/ 95 | inl (A B : Ty) : Term A (A ⊕' B) 96 /-- Atomic function 2: the right co-projection. -/ 97 | inr (A B : Ty) : Term B (A ⊕' B) 98 /-- Atomic function 3: the co-diagonal. -/ 99 | codiag (A : Ty) : Term (A ⊕' A) A 100 /-- Atomic function 4: the first projection. -/ 101 | fst (A B : Ty) : Term (A ⊗ B) A 102 /-- Atomic function 4: the second projection. -/ 103 | snd (A B : Ty) : Term (A ⊗ B) B 104 /-- Atomic function 5: the right unit `(id, 1)`. -/ 105 | unitR (A : Ty) : Term A (A ⊗ Ty.unit) 106 /-- Atomic function 5: the left unit `(1, id)`. -/ 107 | unitL (A : Ty) : Term A (Ty.unit ⊗ A) 108 /-- Atomic function 5: left associativity of products. -/ 109 | assocL (A B C : Ty) : Term (A ⊗ (B ⊗ C)) ((A ⊗ B) ⊗ C) 110 /-- Atomic function 5: right associativity of products. -/ 111 | assocR (A B C : Ty) : Term ((A ⊗ B) ⊗ C) (A ⊗ (B ⊗ C)) 112 /-- Atomic function 6: distributivity on the right. -/ 113 | distR (A B C : Ty) : Term (A ⊗ (B ⊕' C)) ((A ⊗ B) ⊕' (A ⊗ C)) 114 /-- Atomic function 6: distributivity on the left. -/ 115 | distL (A B C : Ty) : Term ((A ⊕' B) ⊗ C) ((A ⊗ C) ⊕' (B ⊗ C)) 116 /-- Atomic function 7: the list constructor `cons`. -/ 117 | cons (A : Ty) : Term (Ty.unit ⊕' (A ⊗ A⋆)) A⋆ 118 /-- Atomic function 7: the list destructor `uncons`. -/ 119 | uncons (A : Ty) : Term A⋆ (Ty.unit ⊕' (A ⊗ A⋆)) 120 /-- Atomic function 7: the list constructor `snoc`. -/ 121 | snoc (A : Ty) : Term (Ty.unit ⊕' (A⋆ ⊗ A)) A⋆ 122 /-- Atomic function 7: the list destructor `unsnoc`. -/ 123 | unsnoc (A : Ty) : Term A⋆ (Ty.unit ⊕' (A⋆ ⊗ A)) 124 /-- Atomic function 8: concatenation of a list of lists. -/ 125 | concat (A : Ty) : Term A⋆⋆ A⋆ 126 /-- Atomic function 9: cutting a list over a co-product into blocks. -/ 127 | block (A B : Ty) : Term (A ⊕' B)⋆ (A⋆ ⊗ (B ⊗ A⋆)⋆) 128 /-- Atomic function 10: shifting brackets to the right. -/ 129 | shiftR (A B : Ty) : Term ((A ⊗ B)⋆ ⊗ A) (A ⊗ (B ⊗ A)⋆) 130 /-- Atomic function 10: shifting brackets to the left. -/ 131 | shiftL (A B : Ty) : Term (A ⊗ (B ⊗ A)⋆) ((A ⊗ B)⋆ ⊗ A) 132 /-- Atomic function 11: prefix multiplication in a finite group whose underlying set is the 133 finite alphabet `1 + ⋯ + 1`. -/ 134 | pref (A : Ty) {n : ℕ} (G : Group ⟦Ty.finAlph n⟧) : 135 Term ((A ⊗ Ty.finAlph n)⋆) ((A ⊗ Ty.finAlph n)⋆) 136 137 namespace Term 138 139 /-- Notation `f ⨟ g` for the composition of rational terms: first `f`, then `g`. -/ 140 infixl:60 " ⨟ " => Term.comp 141 142 /-- The denotation `⟦f⟧` of a rational term: the function that it defines. -/ 143 def den : {A B : Ty} → Term A B → ⟦A⟧ → ⟦B⟧ 144 | _, _, .comp f g, x => den g (den f x) 145 | _, _, .prodF f g, x => (den f x.1, den g x.2) 146 | _, _, .sumF f g, x => 147 match x with 148 | .inl a => .inl (den f a) 149 | .inr b => .inr (den g b) 150 | _, _, .listF f, l => l.map (den f) 151 | _, _, .id _, x => x 152 | _, _, .inl _ _, x => .inl x 153 | _, _, .inr _ _, x => .inr x 154 | _, _, .codiag _, x => match x with | .inl a => a | .inr a => a 155 | _, _, .fst _ _, x => x.1 156 | _, _, .snd _ _, x => x.2 157 | _, _, .unitR _, x => (x, ()) 158 | _, _, .unitL _, x => ((), x) 159 | _, _, .assocL _ _ _, x => ((x.1, x.2.1), x.2.2) 160 | _, _, .assocR _ _ _, x => (x.1.1, (x.1.2, x.2)) 161 | _, _, .distR _ _ _, x => 162 match x with 163 | (a, .inl b) => .inl (a, b) 164 | (a, .inr c) => .inr (a, c) 165 | _, _, .distL _ _ _, x => 166 match x with 167 | (.inl a, c) => .inl (a, c) 168 | (.inr b, c) => .inr (b, c) 169 | _, _, .cons _, x => match x with | .inl _ => [] | .inr (a, l) => a :: l 170 | _, _, .uncons _, l => match l with | [] => .inl () | a :: t => .inr (a, t) 171 | _, _, .snoc _, x => snocDen x 172 | _, _, .unsnoc _, l => unsnocDen l 173 | _, _, .concat _, l => l.flatten 174 | _, _, .block _ _, l => blockDen l 175 | _, _, .shiftR _ _, x => match x with | (l, a) => shiftRDen l a 176 | _, _, .shiftL _ _, x => match x with | (a, l) => shiftLDen a l 177 | _, _, .pref _ G, l => letI := G; prefixMul (1 : ⟦Ty.finAlph _⟧) l 178 179 /-- Whether a rational term uses the atomic function `pref` for prefix multiplication in 180 groups. -/ 181 def usesPref : {A B : Ty} → Term A B → Bool 182 | _, _, .comp f g => usesPref f || usesPref g 183 | _, _, .prodF f g => usesPref f || usesPref g 184 | _, _, .sumF f g => usesPref f || usesPref g 185 | _, _, .listF f => usesPref f 186 | _, _, .pref _ _ => true 187 | _, _, _ => false 188 189 end Term 190 191 /-- A rational term is aperiodic if it does not use the group prefix multiplication `pref`. -/ 192 def IsAperiodic {A B : Ty} (f : Term A B) : Prop := Term.usesPref f = false 193 194 end Lax149335.Terms 195 -
Expressive completeness
Theorem 3.2 (Expressive completeness). A function between types is rational if and only if it is the denotation of some rational term.
This theorem is not proved in this submission; it is recorded as an open statement. Nothing else in the submission depends on it.
1 import Lax149335.RationalFunctions 2 import Lax149335.Terms 3 … module docstring, 11 lines 15 16 namespace Lax149335.ExpressiveCompleteness 17 18 open Lax149335.Types Lax149335.RationalFunctions Lax149335.Terms 19 20 /-- **Theorem 3.2.** A function between types is rational if and only if it is the denotation 21 of some rational term. -/ 22 axiom expressive_completeness {A B : Ty} (f : ⟦A⟧ → ⟦B⟧) : 23 IsRationalTypeFun f ↔ ∃ t : Term A B, t.den = f 24 25 end Lax149335.ExpressiveCompleteness 26 -
Finite axiomatisation
Theorem 4.1 (Finite axiomatisation). Two rational terms have the same denotation if and only if can be proved using Axioms 1–16.
1 import Lax149335.EquationalTheory 2 … module docstring, 8 lines 11 12 namespace Lax149335.FiniteAxiomatisation 13 14 open Lax149335.Types Lax149335.Terms Lax149335.EquationalTheory 15 16 /-- **Theorem 4.1.** Two rational terms have the same denotation if and only if they are 17 provably equivalent. -/ 18 axiom finite_axiomatisation {A B : Ty} (f g : Term A B) : f.den = g.den ↔ f ≡ₜ g 19 20 end Lax149335.FiniteAxiomatisation 21 -
The equational theory
Section 4 introduces an equivalence relation on rational terms of the same type, called provable equivalence. It is the least equivalence relation on rational terms that contains the following sixteen axioms and is preserved by the four combinators of Definition 3.1 (composition and functoriality of products, co-products and lists).
- Category axioms: composition is associative and the identity is neutral.
- Functoriality: the combinators , and preserve identities and composition.
- Naturality: every atomic function except prefix multiplication is a natural transformation.
- Isomorphisms: ten pairs of mutually inverse terms — the units and , ; and ; and ; and ; and ; and ; and ; and ; and .
- The unit type is terminal: any two terms are equivalent.
- The co-diagonal: , and .
- Mac Lane's pentagon for .
- Mac Lane's triangle for and the unit.
- The notation based on agrees with the notation based on : for the empty list, for singleton lists, and for concatenation.
- is a monoid under with unit .
- is a monoid homomorphism.
- is a monad with unit and multiplication .
- and are expressed by .
- Concatenating a list of empty lists gives the empty list.
- does not change the content of a list: it commutes with the concatenation maps into .
- The window axiom: the bundle term , which splits a list into consecutive pairs followed by a remainder of at most one element, is undone by the concatenation map: . Here .
The bundle term (Definition H.5) is, for a type and a value , the composition
where is the cyclic group of order two on , with identity . The window axiom uses it for and .
1 import Lax149335.DerivedTerms 2 … module docstring, 60 lines 63 64 namespace Lax149335.EquationalTheory 65 66 open Lax149335.Types Lax149335.Terms Lax149335.DerivedTerms 67 68 namespace Term 69 70 open Lax149335.Terms.Term Lax149335.DerivedTerms.Term 71 72 /-- The cyclic group `ℤ₂` of order two, with the two letter alphabet `2 = 1 + 1` as its 73 underlying set: the group identity is the first letter `Left`, and the second letter `Right` 74 is the generator. -/ 75 def cyclicTwo : Group ⟦Ty.finAlph 1⟧ where 76 mul x y := match x, y with 77 | .inl _, y => y 78 | x, .inl _ => x 79 | .inr _, .inr _ => .inl () 80 one := .inl () 81 inv x := x 82 mul_assoc := by intro x y z; cases x <;> cases y <;> cases z <;> rfl 83 one_mul := by intro x; cases x <;> rfl 84 mul_one := by intro x; cases x <;> rfl 85 inv_mul_cancel := by intro x; cases x <;> rfl 86 87 /-- The generator `Right` of the cyclic group of order two. -/ 88 def cyclicTwoGen : ⟦Ty.finAlph 1⟧ := Sum.inr () 89 90 /-- **Step 3 of the bundle term**, for a single element: `distR ; either (fst ; Right) 91 (fst ; Left) : A × 2 → A + A`. An element annotated with the generator `Right` goes to the 92 left copy of `A`, and an element annotated with the identity `Left` goes to the right 93 copy. -/ 94 def bundleTag (A : Ty) : Term (A ⊗ Ty.finAlph 1) (A ⊕' A) := 95 distR A Ty.unit (Ty.finAlph 0) ⨟ either (fst A Ty.unit ⨟ inr A A) (fst A Ty.unit ⨟ inl A A) 96 97 /-- **Definition H.5 (the bundle term)** `A* → (A × A)* × (1 + A)`, for a type `A` and a value 98 `w : 1 → A`: 99 100 `((id,1) ; (id × Right))* ; pref_{ℤ₂} ; (distR ; either (fst ; Right) (fst ; Left))* ; 101 block ; shiftL ; ((head_w × id)* × (uncons ; (id + fst)))`. 102 103 The window axiom (Axiom 16) says that, for `A = 2*` and `w = []`, it is a one-sided inverse 104 of the concatenation map `(A × A)* × (1 + A) ↣ A*`. -/ 105 def bundle (A : Ty) (w : Value A) : Term A⋆ ((A ⊗ A)⋆ ⊗ (Ty.unit ⊕' A)) := 106 listF (unitR A ⨟ prodF (Term.id A) (inr Ty.unit (Ty.finAlph 0))) ⨟ 107 pref A cyclicTwo ⨟ 108 listF (bundleTag A) ⨟ 109 block A A ⨟ 110 shiftL A⋆ A ⨟ 111 prodF (listF (prodF (headT w) (Term.id A))) (uncons A ⨟ sumF (Term.id Ty.unit) (fst A A⋆)) 112 113 /-- The type constructor `A ↦ (A × A)* × (1 + A)` of the window axiom. -/ 114 def TyF.window : TyF := .prod (.list (.prod .param .param)) (.sum .unit .param) 115 116 end Term 117 118 open Lax149335.Terms.Term Lax149335.DerivedTerms.Term 119 120 /-- Provable equality of rational terms: the least equivalence relation containing 121 Axioms 1-16 of Section 4 and stable under the combinators of the system. -/ 122 inductive PEq : {A B : Ty} → Term A B → Term A B → Prop 123 -- rules of equational reasoning: `≡` is an equivalence relation, stable under the 124 -- four combinators of the system 125 | refl {A B : Ty} (f : Term A B) : PEq f f 126 | symm {A B : Ty} {f g : Term A B} : PEq f g → PEq g f 127 | trans {A B : Ty} {f g h : Term A B} : PEq f g → PEq g h → PEq f h 128 | congr_comp {A B C : Ty} {f f' : Term A B} {g g' : Term B C} : 129 PEq f f' → PEq g g' → PEq (f ⨟ g) (f' ⨟ g') 130 | congr_prodF {A₁ A₂ B₁ B₂ : Ty} {f f' : Term A₁ B₁} {g g' : Term A₂ B₂} : 131 PEq f f' → PEq g g' → PEq (prodF f g) (prodF f' g') 132 | congr_sumF {A₁ A₂ B₁ B₂ : Ty} {f f' : Term A₁ B₁} {g g' : Term A₂ B₂} : 133 PEq f f' → PEq g g' → PEq (sumF f g) (sumF f' g') 134 | congr_listF {A B : Ty} {f f' : Term A B} : PEq f f' → PEq (listF f) (listF f') 135 -- ## Axiom 1 (category axioms) 136 | comp_assoc {A B C D : Ty} (f : Term A B) (g : Term B C) (h : Term C D) : 137 PEq ((f ⨟ g) ⨟ h) (f ⨟ (g ⨟ h)) 138 | id_comp {A B : Ty} (f : Term A B) : PEq (Term.id A ⨟ f) f 139 | comp_id {A B : Ty} (f : Term A B) : PEq (f ⨟ Term.id B) f 140 -- ## Axiom 2 (functoriality), first part: the functors preserve the identity 141 | prod_id (A B : Ty) : PEq (prodF (Term.id A) (Term.id B)) (Term.id (A ⊗ B)) 142 | sum_id (A B : Ty) : PEq (sumF (Term.id A) (Term.id B)) (Term.id (A ⊕' B)) 143 | list_id (A : Ty) : PEq (listF (Term.id A)) (Term.id A⋆) 144 -- ## Axiom 2 (functoriality), second part: the functors preserve composition 145 | prod_comp {A₁ A₂ B₁ B₂ C₁ C₂ : Ty} (f₁ : Term A₁ B₁) (f₂ : Term A₂ B₂) 146 (g₁ : Term B₁ C₁) (g₂ : Term B₂ C₂) : 147 PEq (prodF f₁ f₂ ⨟ prodF g₁ g₂) (prodF (f₁ ⨟ g₁) (f₂ ⨟ g₂)) 148 | sum_comp {A₁ A₂ B₁ B₂ C₁ C₂ : Ty} (f₁ : Term A₁ B₁) (f₂ : Term A₂ B₂) 149 (g₁ : Term B₁ C₁) (g₂ : Term B₂ C₂) : 150 PEq (sumF f₁ f₂ ⨟ sumF g₁ g₂) (sumF (f₁ ⨟ g₁) (f₂ ⨟ g₂)) 151 | list_comp {A B C : Ty} (f : Term A B) (g : Term B C) : 152 PEq (listF f ⨟ listF g) (listF (f ⨟ g)) 153 -- ## Axiom 3 (each atomic function is a natural transformation) 154 | nat_inl {A A' B B' : Ty} (f : Term A A') (g : Term B B') : 155 PEq (inl A B ⨟ sumF f g) (f ⨟ inl A' B') 156 | nat_inr {A A' B B' : Ty} (f : Term A A') (g : Term B B') : 157 PEq (inr A B ⨟ sumF f g) (g ⨟ inr A' B') 158 | nat_codiag {A A' : Ty} (f : Term A A') : 159 PEq (sumF f f ⨟ codiag A') (codiag A ⨟ f) 160 | nat_fst {A A' B B' : Ty} (f : Term A A') (g : Term B B') : 161 PEq (prodF f g ⨟ fst A' B') (fst A B ⨟ f) 162 | nat_snd {A A' B B' : Ty} (f : Term A A') (g : Term B B') : 163 PEq (prodF f g ⨟ snd A' B') (snd A B ⨟ g) 164 | nat_unitR {A A' : Ty} (f : Term A A') : 165 PEq (f ⨟ unitR A') (unitR A ⨟ prodF f (Term.id Ty.unit)) 166 | nat_unitL {A A' : Ty} (f : Term A A') : 167 PEq (f ⨟ unitL A') (unitL A ⨟ prodF (Term.id Ty.unit) f) 168 | nat_assocL {A A' B B' C C' : Ty} (f₁ : Term A A') (f₂ : Term B B') (f₃ : Term C C') : 169 PEq (prodF f₁ (prodF f₂ f₃) ⨟ assocL A' B' C') (assocL A B C ⨟ prodF (prodF f₁ f₂) f₃) 170 | nat_assocR {A A' B B' C C' : Ty} (f₁ : Term A A') (f₂ : Term B B') (f₃ : Term C C') : 171 PEq (prodF (prodF f₁ f₂) f₃ ⨟ assocR A' B' C') (assocR A B C ⨟ prodF f₁ (prodF f₂ f₃)) 172 | nat_distR {A A' B B' C C' : Ty} (f : Term A A') (g : Term B B') (h : Term C C') : 173 PEq (prodF f (sumF g h) ⨟ distR A' B' C') (distR A B C ⨟ sumF (prodF f g) (prodF f h)) 174 | nat_distL {A A' B B' C C' : Ty} (f : Term A A') (g : Term B B') (h : Term C C') : 175 PEq (prodF (sumF f g) h ⨟ distL A' B' C') (distL A B C ⨟ sumF (prodF f h) (prodF g h)) 176 | nat_cons {A B : Ty} (f : Term A B) : 177 PEq (sumF (Term.id Ty.unit) (prodF f (listF f)) ⨟ cons B) (cons A ⨟ listF f) 178 | nat_uncons {A B : Ty} (f : Term A B) : 179 PEq (listF f ⨟ uncons B) (uncons A ⨟ sumF (Term.id Ty.unit) (prodF f (listF f))) 180 | nat_snoc {A B : Ty} (f : Term A B) : 181 PEq (sumF (Term.id Ty.unit) (prodF (listF f) f) ⨟ snoc B) (snoc A ⨟ listF f) 182 | nat_unsnoc {A B : Ty} (f : Term A B) : 183 PEq (listF f ⨟ unsnoc B) (unsnoc A ⨟ sumF (Term.id Ty.unit) (prodF (listF f) f)) 184 | nat_concat {A B : Ty} (f : Term A B) : 185 PEq (listF (listF f) ⨟ concat B) (concat A ⨟ listF f) 186 | nat_block {A A' B B' : Ty} (f : Term A A') (g : Term B B') : 187 PEq (listF (sumF f g) ⨟ block A' B') 188 (block A B ⨟ prodF (listF f) (listF (prodF g (listF f)))) 189 | nat_shiftR {A A' B B' : Ty} (f : Term A A') (g : Term B B') : 190 PEq (prodF (listF (prodF f g)) f ⨟ shiftR A' B') 191 (shiftR A B ⨟ prodF f (listF (prodF g f))) 192 | nat_shiftL {A A' B B' : Ty} (f : Term A A') (g : Term B B') : 193 PEq (prodF f (listF (prodF g f)) ⨟ shiftL A' B') 194 (shiftL A B ⨟ prodF (listF (prodF f g)) f) 195 -- (Naturality of the group prefix multiplication need not be postulated: it is derivable, 196 -- see footnote 5 of the paper.) 197 -- ## Axiom 4 (ten pairs of mutually inverse functions) 198 | unitR_fst (A : Ty) : PEq (unitR A ⨟ fst A Ty.unit) (Term.id A) 199 | fst_unitR (A : Ty) : PEq (fst A Ty.unit ⨟ unitR A) (Term.id (A ⊗ Ty.unit)) 200 | unitL_snd (A : Ty) : PEq (unitL A ⨟ snd Ty.unit A) (Term.id A) 201 | snd_unitL (A : Ty) : PEq (snd Ty.unit A ⨟ unitL A) (Term.id (Ty.unit ⊗ A)) 202 | assocL_assocR (A B C : Ty) : 203 PEq (assocL A B C ⨟ assocR A B C) (Term.id (A ⊗ (B ⊗ C))) 204 | assocR_assocL (A B C : Ty) : 205 PEq (assocR A B C ⨟ assocL A B C) (Term.id ((A ⊗ B) ⊗ C)) 206 | distL_undistL (A B C : Ty) : 207 PEq (distL A B C ⨟ undistL A B C) (Term.id ((A ⊕' B) ⊗ C)) 208 | undistL_distL (A B C : Ty) : 209 PEq (undistL A B C ⨟ distL A B C) (Term.id ((A ⊗ C) ⊕' (B ⊗ C))) 210 | distR_undistR (A B C : Ty) : 211 PEq (distR A B C ⨟ undistR A B C) (Term.id (A ⊗ (B ⊕' C))) 212 | undistR_distR (A B C : Ty) : 213 PEq (undistR A B C ⨟ distR A B C) (Term.id ((A ⊗ B) ⊕' (A ⊗ C))) 214 | cons_uncons (A : Ty) : PEq (cons A ⨟ uncons A) (Term.id (Ty.unit ⊕' (A ⊗ A⋆))) 215 | uncons_cons (A : Ty) : PEq (uncons A ⨟ cons A) (Term.id A⋆) 216 | snoc_unsnoc (A : Ty) : PEq (snoc A ⨟ unsnoc A) (Term.id (Ty.unit ⊕' (A⋆ ⊗ A))) 217 | unsnoc_snoc (A : Ty) : PEq (unsnoc A ⨟ snoc A) (Term.id A⋆) 218 | block_unblock (A B : Ty) : PEq (block A B ⨟ unblock A B) (Term.id (A ⊕' B)⋆) 219 | unblock_block (A B : Ty) : PEq (unblock A B ⨟ block A B) (Term.id (A⋆ ⊗ (B ⊗ A⋆)⋆)) 220 | pref_unpref (A : Ty) {n : ℕ} (G : Group ⟦Ty.finAlph n⟧) : 221 PEq (pref A G ⨟ unpref A G) (Term.id ((A ⊗ Ty.finAlph n)⋆)) 222 | unpref_pref (A : Ty) {n : ℕ} (G : Group ⟦Ty.finAlph n⟧) : 223 PEq (unpref A G ⨟ pref A G) (Term.id ((A ⊗ Ty.finAlph n)⋆)) 224 | shiftL_shiftR (A B : Ty) : PEq (shiftL A B ⨟ shiftR A B) (Term.id (A ⊗ (B ⊗ A)⋆)) 225 | shiftR_shiftL (A B : Ty) : PEq (shiftR A B ⨟ shiftL A B) (Term.id ((A ⊗ B)⋆ ⊗ A)) 226 -- ## Axiom 5 (the unit type is terminal) 227 | unit_unique {A : Ty} (f g : Term A Ty.unit) : PEq f g 228 -- ## Axiom 6 (the co-diagonal) 229 | inl_codiag (A : Ty) : PEq (inl A A ⨟ codiag A) (Term.id A) 230 | inr_codiag (A : Ty) : PEq (inr A A ⨟ codiag A) (Term.id A) 231 | sum_inl_inr_codiag (A B : Ty) : 232 PEq (sumF (inl A B) (inr A B) ⨟ codiag (A ⊕' B)) (Term.id (A ⊕' B)) 233 -- ## Axiom 7 (Mac Lane's pentagon) 234 | pentagon (A B C D : Ty) : 235 PEq (prodF (Term.id A) (assocL B C D) ⨟ assocL A (B ⊗ C) D ⨟ 236 prodF (assocL A B C) (Term.id D)) 237 (assocL A B (C ⊗ D) ⨟ assocL (A ⊗ B) C D) 238 -- ## Axiom 8 (Mac Lane's triangle) 239 | triangle (A C : Ty) : 240 PEq (assocL A Ty.unit C ⨟ prodF (fst A Ty.unit) (Term.id C)) 241 (prodF (Term.id A) (snd Ty.unit C)) 242 -- ## Axiom 9 (`snoc`-based notation agrees with `cons`-based notation) 243 | inl_snoc_cons (A : Ty) : 244 PEq (inl Ty.unit (A⋆ ⊗ A) ⨟ snoc A) (inl Ty.unit (A ⊗ A⋆) ⨟ cons A) 245 | append_nil_prepend_nil (A : Ty) : 246 PEq (unitL A ⨟ prodF (nilT A) (Term.id A) ⨟ append A) 247 (unitR A ⨟ prodF (Term.id A) (nilT A) ⨟ prepend A) 248 | append_concat_prepend_concat (A : Ty) : 249 PEq (prodF (pureT A⋆) (Term.id A⋆) ⨟ append A⋆ ⨟ concat A) 250 (prodF (Term.id A⋆) (pureT A⋆) ⨟ prepend A⋆ ⨟ concat A) 251 -- ## Axiom 10 (`A*` is a monoid) 252 | binconcat_assoc (A : Ty) : 253 PEq (prodF (binconcat A) (Term.id A⋆) ⨟ binconcat A) 254 (assocR A⋆ A⋆ A⋆ ⨟ prodF (Term.id A⋆) (binconcat A) ⨟ binconcat A) 255 | binconcat_unitR (A : Ty) : 256 PEq (unitR A⋆ ⨟ prodF (Term.id A⋆) (nilT A) ⨟ binconcat A) (Term.id A⋆) 257 | binconcat_unitL (A : Ty) : 258 PEq (unitL A⋆ ⨟ prodF (nilT A) (Term.id A⋆) ⨟ binconcat A) (Term.id A⋆) 259 -- ## Axiom 11 (`concat` is a monoid homomorphism) 260 | nil_concat (A : Ty) : PEq (nilT A⋆ ⨟ concat A) (nilT A) 261 | binconcat_concat (A : Ty) : 262 PEq (binconcat A⋆ ⨟ concat A) (prodF (concat A) (concat A) ⨟ binconcat A) 263 -- ## Axiom 12 (`A*` is a monad) 264 | concat_concat (A : Ty) : PEq (listF (concat A) ⨟ concat A) (concat A⋆ ⨟ concat A) 265 | pure_concat (A : Ty) : PEq (pureT A⋆ ⨟ concat A) (Term.id A⋆) 266 | listF_pure_concat (A : Ty) : PEq (listF (pureT A) ⨟ concat A) (Term.id A⋆) 267 -- ## Axiom 13 (the inductive structure in terms of the monoid structure) 268 | prepend_def (A : Ty) : 269 PEq (prepend A) (prodF (pureT A) (Term.id A⋆) ⨟ binconcat A) 270 | append_def (A : Ty) : 271 PEq (append A) (prodF (Term.id A⋆) (pureT A) ⨟ binconcat A) 272 -- ## Axiom 14 (concatenating a list of empty lists) 273 | nil_map_concat (A : Ty) : 274 PEq (listF (nilT A) ⨟ concat A) (toUnit Ty.unit⋆ ⨟ nilT A) 275 -- ## Axiom 15 (`shiftR` does not change the content of the list) 276 | shiftR_content (A B : Ty) : 277 PEq (shiftR A B ⨟ TyF2.concatMap (.prod .p1 (.list (.prod .p2 .p1))) A B) 278 (TyF2.concatMap (.prod (.list (.prod .p1 .p2)) .p1) A B) 279 -- ## Axiom 16 (the window axiom: the bundle term undoes the concatenation map of bundles 280 -- of size two over binary strings) 281 -- 282 -- The bundle term `bundle_{2*} : (2*)* → (2* × 2*)* × (1 + 2*)` of Definition H.5, 283 -- formalised as `Term.bundle` with the value `w = []`, splits a list into bundles 284 -- of two consecutive entries followed by a remainder of at most one entry. The axiom says 285 -- that this splitting is undone by the concatenation map 286 -- 287 -- `(2* × 2*)* × (1 + 2*) ↣ (2*)*`, 288 -- 289 -- i.e. that `bundle ; concat ≡ id`. 290 | window : 291 PEq (Term.bundle ((Ty.finAlph 1)⋆) (nilT (Ty.finAlph 1)) ⨟ 292 TyF.concatMap Term.TyF.window ((Ty.finAlph 1)⋆)) 293 (Term.id (((Ty.finAlph 1)⋆)⋆)) 294 295 /-- Notation `f ≡ₜ g` for provable equivalence of rational terms. -/ 296 infix:50 " ≡ₜ " => PEq 297 298 end Lax149335.EquationalTheory 299 -
Derived terms
The following terms are derived from the atomic functions and combinators of Definition 3.1. They are used to state the axioms of Section 4 and the results of the completeness proof.
- The unique term , co-pairing , commutativity and associativity of co-products.
- The list notation of Section 4.6: the empty list , , , , , the homomorphism combinator , and the concatenation of two terms with list outputs.
- The inverses of distributivity, and (Section 4.4).
- Definition 5.1 (Value). A value is a term of type . For a list value , the terms and prepend or append the output of to the output of (Section 5.2), and returns the first element of a list, or the output of for the empty list.
- Concatenation maps (Section 5.1). For a type constructor with one parameter, built from the parameter, , , and , the concatenation map lists all the elements of occurring in the input, from left to right. Similarly for type constructors with two parameters, with outputs in . In particular, is a concatenation map.
- The terms and of Table 1.
- The inverse of group prefix multiplication (Section 4.4), which maps to , where is the group identity.
1 import Lax149335.Terms 2 … module docstring, 39 lines 42 43 namespace Lax149335.DerivedTerms 44 45 open Lax149335.Types Lax149335.Terms 46 47 namespace Term 48 49 open Lax149335.Terms.Term 50 51 /-- The unique function into the unit type, `A → 1`. -/ 52 def toUnit (A : Ty) : Term A Ty.unit := unitL A ⨟ fst Ty.unit A 53 54 /-- Co-pairing, a derived combinator: `either f₁ f₂ = (f₁ + f₂); codiag`. -/ 55 def either {A₁ A₂ B : Ty} (f₁ : Term A₁ B) (f₂ : Term A₂ B) : Term (A₁ ⊕' A₂) B := 56 sumF f₁ f₂ ⨟ codiag B 57 58 /-- Commutativity of the co-product, a derived term. -/ 59 def comm (A B : Ty) : Term (A ⊕' B) (B ⊕' A) := either (inr B A) (inl B A) 60 61 /-- Associativity of the co-product, from left to right. -/ 62 def sumAssocR (A B C : Ty) : Term ((A ⊕' B) ⊕' C) (A ⊕' (B ⊕' C)) := 63 either (either (inl A (B ⊕' C)) (inl B C ⨟ inr A (B ⊕' C))) (inr B C ⨟ inr A (B ⊕' C)) 64 65 /-- Associativity of the co-product, from right to left. -/ 66 def sumAssocL (A B C : Ty) : Term (A ⊕' (B ⊕' C)) ((A ⊕' B) ⊕' C) := 67 either (inl A B ⨟ inl (A ⊕' B) C) 68 (either (inr A B ⨟ inl (A ⊕' B) C) (inr (A ⊕' B) C)) 69 70 /-- The empty list `[] : 1 → A*`, defined as `Left; cons`. -/ 71 def nilT (A : Ty) : Term Ty.unit A⋆ := inl Ty.unit (A ⊗ A⋆) ⨟ cons A 72 73 /-- `prepend : A × A* → A*`, defined as `Right; cons`. -/ 74 def prepend (A : Ty) : Term (A ⊗ A⋆) A⋆ := inr Ty.unit (A ⊗ A⋆) ⨟ cons A 75 76 /-- `append : A* × A → A*`, defined as `Right; snoc`. -/ 77 def append (A : Ty) : Term (A⋆ ⊗ A) A⋆ := inr Ty.unit (A⋆ ⊗ A) ⨟ snoc A 78 79 /-- `pure : A → A*`, defined as `(id,1); id × []; prepend`. -/ 80 def pureT (A : Ty) : Term A A⋆ := 81 unitR A ⨟ prodF (Term.id A) (nilT A) ⨟ prepend A 82 83 /-- `binconcat : A* × A* → A*`, defined as `(id × pure); prepend; concat`. -/ 84 def binconcat (A : Ty) : Term (A⋆ ⊗ A⋆) A⋆ := 85 prodF (Term.id A⋆) (pureT A⋆) ⨟ prepend A⋆ ⨟ concat A 86 87 /-- The homomorphism combinator `hom f = f*; concat`. -/ 88 def homT {A B : Ty} (f : Term A B⋆) : Term A⋆ B⋆ := listF f ⨟ concat B 89 90 /-- Concatenation of two functions with list outputs, `f ⊙ g = (f × g); binconcat`. -/ 91 def fdot {A₁ A₂ B : Ty} (f : Term A₁ B⋆) (g : Term A₂ B⋆) : Term (A₁ ⊗ A₂) B⋆ := 92 prodF f g ⨟ binconcat B 93 94 /-- Notation `f ⊙ g` for the concatenation of two terms with list outputs. -/ 95 infixl:65 " ⊙ " => Term.fdot 96 97 /-- The inverse of distributivity on the right, 98 `undistR = either (id × Left) (id × Right)`. -/ 99 def undistR (A B C : Ty) : Term ((A ⊗ B) ⊕' (A ⊗ C)) (A ⊗ (B ⊕' C)) := 100 either (prodF (Term.id A) (inl B C)) (prodF (Term.id A) (inr B C)) 101 102 /-- The inverse of distributivity on the left. -/ 103 def undistL (A B C : Ty) : Term ((A ⊗ C) ⊕' (B ⊗ C)) ((A ⊕' B) ⊗ C) := 104 either (prodF (inl A B) (Term.id C)) (prodF (inr A B) (Term.id C)) 105 106 -- Values and concatenation with values (Section 5.2) 107 108 /-- **Definition 5.1 (Value).** A value is a term of type `1 → A`. -/ 109 abbrev Value (A : Ty) : Type := Term Ty.unit A 110 111 /-- Pairing a value on the left with an arbitrary term: `(v,f) = (1,id); (v × f)`. -/ 112 def pairL {A B C : Ty} (v : Value C) (f : Term A B) : Term A (C ⊗ B) := 113 unitL A ⨟ prodF v f 114 115 /-- Pairing a value on the right with an arbitrary term: `(f,v) = (id,1); (f × v)`. -/ 116 def pairR {A B C : Ty} (f : Term A B) (v : Value C) : Term A (B ⊗ C) := 117 unitR A ⨟ prodF f v 118 119 /-- Concatenation of a list value on the left with a term with list outputs, `w · f`. -/ 120 def dotL {A B : Ty} (w : Value B⋆) (f : Term A B⋆) : Term A B⋆ := 121 pairL w f ⨟ binconcat B 122 123 /-- Concatenation of a term with list outputs with a list value on the right, `f · w`. -/ 124 def dotR {A B : Ty} (f : Term A B⋆) (w : Value B⋆) : Term A B⋆ := 125 pairR f w ⨟ binconcat B 126 127 /-- The singleton list value `[v] = v; pure`. -/ 128 def sing {A : Ty} (v : Value A) : Value A⋆ := v ⨟ pureT A 129 130 /-- The *head term for `w`*: the first element of a list, or the value `w` if the list is 131 empty. -/ 132 def headT {A : Ty} (w : Value A) : Term A⋆ A := 133 uncons A ⨟ either w (fst A A⋆) 134 135 -- Concatenation maps (Section 5.1) 136 137 /-- Type constructors with one parameter, used to define concatenation maps. -/ 138 inductive TyF : Type 139 /-- The parameter itself. -/ 140 | param : TyF 141 /-- The unit type. -/ 142 | unit : TyF 143 /-- Product of two type constructors. -/ 144 | prod : TyF → TyF → TyF 145 /-- Co-product of two type constructors. -/ 146 | sum : TyF → TyF → TyF 147 /-- List of a type constructor. -/ 148 | list : TyF → TyF 149 150 /-- The type `F(A)` obtained by substituting the type `A` for the parameter of `F`. -/ 151 def TyF.app : TyF → Ty → Ty 152 | .param, A => A 153 | .unit, _ => Ty.unit 154 | .prod F G, A => (F.app A) ⊗ (G.app A) 155 | .sum F G, A => (F.app A) ⊕' (G.app A) 156 | .list F, A => (F.app A)⋆ 157 158 /-- **Concatenation maps** (Section 5.1): the term `F(A) ↣ A*` that concatenates all the 159 elements of the input into a single list, defined by induction on `F`. -/ 160 def TyF.concatMap : (F : TyF) → (A : Ty) → Term (F.app A) A⋆ 161 | .param, A => pureT A 162 | .unit, A => nilT A 163 | .prod F G, A => (F.concatMap A) ⊙ (G.concatMap A) 164 | .sum F G, A => either (F.concatMap A) (G.concatMap A) 165 | .list F, A => homT (F.concatMap A) 166 167 /-- The type constructor `A ↦ Aᵏ`, the `k`-fold product of the parameter with itself. -/ 168 def TyF.pow : ℕ → TyF 169 | 0 => .unit 170 | (k + 1) => .prod .param (TyF.pow k) 171 172 /-- The type constructor `A ↦ A⁰ + A¹ + ⋯ + Aᵏ`, i.e. `A^{<k+1}` in the notation of the 173 paper. -/ 174 def TyF.lt : ℕ → TyF 175 | 0 => TyF.pow 0 176 | (k + 1) => .sum (TyF.lt k) (TyF.pow (k + 1)) 177 178 /-- Type constructors with two parameters, used for the concatenation maps with values in 179 `(A + B)*` that occur in Axiom 15 and in the definition of `unblock`. -/ 180 inductive TyF2 : Type 181 /-- The first parameter. -/ 182 | p1 : TyF2 183 /-- The second parameter. -/ 184 | p2 : TyF2 185 /-- The unit type. -/ 186 | unit : TyF2 187 /-- Product of two type constructors. -/ 188 | prod : TyF2 → TyF2 → TyF2 189 /-- Co-product of two type constructors. -/ 190 | sum : TyF2 → TyF2 → TyF2 191 /-- List of a type constructor. -/ 192 | list : TyF2 → TyF2 193 194 /-- The type `F(A,B)`. -/ 195 def TyF2.app : TyF2 → Ty → Ty → Ty 196 | .p1, A, _ => A 197 | .p2, _, B => B 198 | .unit, _, _ => Ty.unit 199 | .prod F G, A, B => (F.app A B) ⊗ (G.app A B) 200 | .sum F G, A, B => (F.app A B) ⊕' (G.app A B) 201 | .list F, A, B => (F.app A B)⋆ 202 203 /-- The concatenation map `F(A,B) ↣ (A+B)*`, which injects the elements of `A` and of `B` 204 into the co-product `A + B` and concatenates all of them. -/ 205 def TyF2.concatMap : (F : TyF2) → (A B : Ty) → Term (F.app A B) (A ⊕' B)⋆ 206 | .p1, A, B => inl A B ⨟ pureT (A ⊕' B) 207 | .p2, A, B => inr A B ⨟ pureT (A ⊕' B) 208 | .unit, A, B => nilT (A ⊕' B) 209 | .prod F G, A, B => (F.concatMap A B) ⊙ (G.concatMap A B) 210 | .sum F G, A, B => either (F.concatMap A B) (G.concatMap A B) 211 | .list F, A, B => homT (F.concatMap A B) 212 213 /-- The inverse of `block`: it injects `A` and `B` into the co-product `A + B` and then 214 concatenates all resulting lists. -/ 215 def unblock (A B : Ty) : Term (A⋆ ⊗ (B ⊗ A⋆)⋆) (A ⊕' B)⋆ := 216 TyF2.concatMap (.prod (.list .p1) (.list (.prod .p2 (.list .p1)))) A B 217 218 -- The terms `shift` and `unshift` of Table 1 219 220 /-- The lift `shift : (A × B)* ⊸ 1 + A × (B × A)* × B`, obtained by composing `uncons`, 221 `assocR` and `shiftL`. -/ 222 def shift (A B : Ty) : Term ((A ⊗ B)⋆) (Ty.unit ⊕' (A ⊗ ((B ⊗ A)⋆ ⊗ B))) := 223 uncons (A ⊗ B) ⨟ 224 sumF (Term.id Ty.unit) (assocR A B ((A ⊗ B)⋆) ⨟ prodF (Term.id A) (shiftL B A)) 225 226 /-- The drop `unshift : 1 + A × (B × A)* × B ⇒ (A × B)*`, the inverse of `shift`. -/ 227 def unshift (A B : Ty) : Term (Ty.unit ⊕' (A ⊗ ((B ⊗ A)⋆ ⊗ B))) ((A ⊗ B)⋆) := 228 sumF (Term.id Ty.unit) (prodF (Term.id A) (shiftR B A) ⨟ assocL A B ((A ⊗ B)⋆)) ⨟ cons (A ⊗ B) 229 230 -- Terms for finite alphabets and the inverse of the group prefix operation 231 232 /-- The value `1 → 1 + ⋯ + 1` that picks out a given letter of a finite alphabet. -/ 233 def constFin : {n : ℕ} → ⟦Ty.finAlph n⟧ → Value (Ty.finAlph n) 234 | 0, _ => Term.id Ty.unit 235 | (_ + 1), .inl _ => inl Ty.unit _ 236 | (_ + 1), .inr g => constFin g ⨟ inr Ty.unit _ 237 238 /-- Case analysis on a letter of a finite alphabet that appears as the right component of a 239 product; it is derived using distributivity and co-pairing. -/ 240 def caseR : {n : ℕ} → {A B : Ty} → (⟦Ty.finAlph n⟧ → Term A B) → Term (A ⊗ Ty.finAlph n) B 241 | 0, A, _, t => fst A Ty.unit ⨟ t () 242 | (n + 1), A, _, t => 243 distR A Ty.unit (Ty.finAlph n) ⨟ 244 either (fst A Ty.unit ⨟ t (.inl ())) (caseR (fun g => t (.inr g))) 245 246 /-- Case analysis on a letter of a finite alphabet that appears as the left component of a 247 product. -/ 248 def caseL : {n : ℕ} → {A B : Ty} → (⟦Ty.finAlph n⟧ → Term A B) → Term (Ty.finAlph n ⊗ A) B 249 | 0, A, _, t => snd Ty.unit A ⨟ t () 250 | (n + 1), A, _, t => 251 distL Ty.unit (Ty.finAlph n) A ⨟ 252 either (snd Ty.unit A ⨟ t (.inl ())) (caseL (fun g => t (.inr g))) 253 254 /-- The term `(a,g) ↦ (g,(a,g))`, admissible because the group is a finite alphabet. -/ 255 def grepeat (A : Ty) (n : ℕ) : Term (A ⊗ Ty.finAlph n) (Ty.finAlph n ⊗ (A ⊗ Ty.finAlph n)) := 256 caseR (fun g => pairL (constFin g) (pairR (Term.id A) (constFin g))) 257 258 /-- The term `(h,(g,a)) ↦ (a, h⁻¹ · g)`, admissible because the group is a finite 259 alphabet. -/ 260 def gdiv (A : Ty) {n : ℕ} (G : Group ⟦Ty.finAlph n⟧) : 261 Term (Ty.finAlph n ⊗ (Ty.finAlph n ⊗ A)) (A ⊗ Ty.finAlph n) := 262 caseL (fun h => caseL (fun g => pairR (Term.id A) (constFin (letI := G; h⁻¹ * g)))) 263 264 /-- The unprefixing operation, the inverse of the group prefix multiplication: 265 `[(a₁,g₁),…,(aₙ,gₙ)] ↦ [(a₁,g₀⁻¹g₁),(a₂,g₁⁻¹g₂),…,(aₙ,gₙ₋₁⁻¹gₙ)]`, where `g₀` is the group 266 identity. -/ 267 def unpref (A : Ty) {n : ℕ} (G : Group ⟦Ty.finAlph n⟧) : 268 Term ((A ⊗ Ty.finAlph n)⋆) ((A ⊗ Ty.finAlph n)⋆) := 269 listF (grepeat A n) ⨟ 270 listF (assocL (Ty.finAlph n) A (Ty.finAlph n)) ⨟ 271 pairL (constFin (letI := G; (1 : ⟦Ty.finAlph n⟧))) (Term.id _) ⨟ 272 shiftL (Ty.finAlph n) (Ty.finAlph n ⊗ A) ⨟ 273 fst _ _ ⨟ listF (gdiv A G) 274 275 end Term 276 277 end Lax149335.DerivedTerms 278 -
Derived terms
The following terms are derived from the atomic functions and combinators of Definition 3.1. They are used to state the axioms of Section 4 and the results of the completeness proof.
- The unique term , co-pairing , commutativity and associativity of co-products.
- The list notation of Section 4.6: the empty list , , , , , the homomorphism combinator , and the concatenation of two terms with list outputs.
- The inverses of distributivity, and (Section 4.4).
- Definition 5.1 (Value). A value is a term of type . For a list value , the terms and prepend or append the output of to the output of (Section 5.2), and returns the first element of a list, or the output of for the empty list.
- Concatenation maps (Section 5.1). For a type constructor with one parameter, built from the parameter, , , and , the concatenation map lists all the elements of occurring in the input, from left to right. Similarly for type constructors with two parameters, with outputs in . In particular, is a concatenation map.
- The terms and of Table 1.
- The inverse of group prefix multiplication (Section 4.4), which maps to , where is the group identity.
1 import Lax149335.Terms 2 … module docstring, 39 lines 42 43 namespace Lax149335.DerivedTerms 44 45 open Lax149335.Types Lax149335.Terms 46 47 namespace Term 48 49 open Lax149335.Terms.Term 50 51 /-- The unique function into the unit type, `A → 1`. -/ 52 def toUnit (A : Ty) : Term A Ty.unit := unitL A ⨟ fst Ty.unit A 53 54 /-- Co-pairing, a derived combinator: `either f₁ f₂ = (f₁ + f₂); codiag`. -/ 55 def either {A₁ A₂ B : Ty} (f₁ : Term A₁ B) (f₂ : Term A₂ B) : Term (A₁ ⊕' A₂) B := 56 sumF f₁ f₂ ⨟ codiag B 57 58 /-- Commutativity of the co-product, a derived term. -/ 59 def comm (A B : Ty) : Term (A ⊕' B) (B ⊕' A) := either (inr B A) (inl B A) 60 61 /-- Associativity of the co-product, from left to right. -/ 62 def sumAssocR (A B C : Ty) : Term ((A ⊕' B) ⊕' C) (A ⊕' (B ⊕' C)) := 63 either (either (inl A (B ⊕' C)) (inl B C ⨟ inr A (B ⊕' C))) (inr B C ⨟ inr A (B ⊕' C)) 64 65 /-- Associativity of the co-product, from right to left. -/ 66 def sumAssocL (A B C : Ty) : Term (A ⊕' (B ⊕' C)) ((A ⊕' B) ⊕' C) := 67 either (inl A B ⨟ inl (A ⊕' B) C) 68 (either (inr A B ⨟ inl (A ⊕' B) C) (inr (A ⊕' B) C)) 69 70 /-- The empty list `[] : 1 → A*`, defined as `Left; cons`. -/ 71 def nilT (A : Ty) : Term Ty.unit A⋆ := inl Ty.unit (A ⊗ A⋆) ⨟ cons A 72 73 /-- `prepend : A × A* → A*`, defined as `Right; cons`. -/ 74 def prepend (A : Ty) : Term (A ⊗ A⋆) A⋆ := inr Ty.unit (A ⊗ A⋆) ⨟ cons A 75 76 /-- `append : A* × A → A*`, defined as `Right; snoc`. -/ 77 def append (A : Ty) : Term (A⋆ ⊗ A) A⋆ := inr Ty.unit (A⋆ ⊗ A) ⨟ snoc A 78 79 /-- `pure : A → A*`, defined as `(id,1); id × []; prepend`. -/ 80 def pureT (A : Ty) : Term A A⋆ := 81 unitR A ⨟ prodF (Term.id A) (nilT A) ⨟ prepend A 82 83 /-- `binconcat : A* × A* → A*`, defined as `(id × pure); prepend; concat`. -/ 84 def binconcat (A : Ty) : Term (A⋆ ⊗ A⋆) A⋆ := 85 prodF (Term.id A⋆) (pureT A⋆) ⨟ prepend A⋆ ⨟ concat A 86 87 /-- The homomorphism combinator `hom f = f*; concat`. -/ 88 def homT {A B : Ty} (f : Term A B⋆) : Term A⋆ B⋆ := listF f ⨟ concat B 89 90 /-- Concatenation of two functions with list outputs, `f ⊙ g = (f × g); binconcat`. -/ 91 def fdot {A₁ A₂ B : Ty} (f : Term A₁ B⋆) (g : Term A₂ B⋆) : Term (A₁ ⊗ A₂) B⋆ := 92 prodF f g ⨟ binconcat B 93 94 /-- Notation `f ⊙ g` for the concatenation of two terms with list outputs. -/ 95 infixl:65 " ⊙ " => Term.fdot 96 97 /-- The inverse of distributivity on the right, 98 `undistR = either (id × Left) (id × Right)`. -/ 99 def undistR (A B C : Ty) : Term ((A ⊗ B) ⊕' (A ⊗ C)) (A ⊗ (B ⊕' C)) := 100 either (prodF (Term.id A) (inl B C)) (prodF (Term.id A) (inr B C)) 101 102 /-- The inverse of distributivity on the left. -/ 103 def undistL (A B C : Ty) : Term ((A ⊗ C) ⊕' (B ⊗ C)) ((A ⊕' B) ⊗ C) := 104 either (prodF (inl A B) (Term.id C)) (prodF (inr A B) (Term.id C)) 105 106 -- Values and concatenation with values (Section 5.2) 107 108 /-- **Definition 5.1 (Value).** A value is a term of type `1 → A`. -/ 109 abbrev Value (A : Ty) : Type := Term Ty.unit A 110 111 /-- Pairing a value on the left with an arbitrary term: `(v,f) = (1,id); (v × f)`. -/ 112 def pairL {A B C : Ty} (v : Value C) (f : Term A B) : Term A (C ⊗ B) := 113 unitL A ⨟ prodF v f 114 115 /-- Pairing a value on the right with an arbitrary term: `(f,v) = (id,1); (f × v)`. -/ 116 def pairR {A B C : Ty} (f : Term A B) (v : Value C) : Term A (B ⊗ C) := 117 unitR A ⨟ prodF f v 118 119 /-- Concatenation of a list value on the left with a term with list outputs, `w · f`. -/ 120 def dotL {A B : Ty} (w : Value B⋆) (f : Term A B⋆) : Term A B⋆ := 121 pairL w f ⨟ binconcat B 122 123 /-- Concatenation of a term with list outputs with a list value on the right, `f · w`. -/ 124 def dotR {A B : Ty} (f : Term A B⋆) (w : Value B⋆) : Term A B⋆ := 125 pairR f w ⨟ binconcat B 126 127 /-- The singleton list value `[v] = v; pure`. -/ 128 def sing {A : Ty} (v : Value A) : Value A⋆ := v ⨟ pureT A 129 130 /-- The *head term for `w`*: the first element of a list, or the value `w` if the list is 131 empty. -/ 132 def headT {A : Ty} (w : Value A) : Term A⋆ A := 133 uncons A ⨟ either w (fst A A⋆) 134 135 -- Concatenation maps (Section 5.1) 136 137 /-- Type constructors with one parameter, used to define concatenation maps. -/ 138 inductive TyF : Type 139 /-- The parameter itself. -/ 140 | param : TyF 141 /-- The unit type. -/ 142 | unit : TyF 143 /-- Product of two type constructors. -/ 144 | prod : TyF → TyF → TyF 145 /-- Co-product of two type constructors. -/ 146 | sum : TyF → TyF → TyF 147 /-- List of a type constructor. -/ 148 | list : TyF → TyF 149 150 /-- The type `F(A)` obtained by substituting the type `A` for the parameter of `F`. -/ 151 def TyF.app : TyF → Ty → Ty 152 | .param, A => A 153 | .unit, _ => Ty.unit 154 | .prod F G, A => (F.app A) ⊗ (G.app A) 155 | .sum F G, A => (F.app A) ⊕' (G.app A) 156 | .list F, A => (F.app A)⋆ 157 158 /-- **Concatenation maps** (Section 5.1): the term `F(A) ↣ A*` that concatenates all the 159 elements of the input into a single list, defined by induction on `F`. -/ 160 def TyF.concatMap : (F : TyF) → (A : Ty) → Term (F.app A) A⋆ 161 | .param, A => pureT A 162 | .unit, A => nilT A 163 | .prod F G, A => (F.concatMap A) ⊙ (G.concatMap A) 164 | .sum F G, A => either (F.concatMap A) (G.concatMap A) 165 | .list F, A => homT (F.concatMap A) 166 167 /-- The type constructor `A ↦ Aᵏ`, the `k`-fold product of the parameter with itself. -/ 168 def TyF.pow : ℕ → TyF 169 | 0 => .unit 170 | (k + 1) => .prod .param (TyF.pow k) 171 172 /-- The type constructor `A ↦ A⁰ + A¹ + ⋯ + Aᵏ`, i.e. `A^{<k+1}` in the notation of the 173 paper. -/ 174 def TyF.lt : ℕ → TyF 175 | 0 => TyF.pow 0 176 | (k + 1) => .sum (TyF.lt k) (TyF.pow (k + 1)) 177 178 /-- Type constructors with two parameters, used for the concatenation maps with values in 179 `(A + B)*` that occur in Axiom 15 and in the definition of `unblock`. -/ 180 inductive TyF2 : Type 181 /-- The first parameter. -/ 182 | p1 : TyF2 183 /-- The second parameter. -/ 184 | p2 : TyF2 185 /-- The unit type. -/ 186 | unit : TyF2 187 /-- Product of two type constructors. -/ 188 | prod : TyF2 → TyF2 → TyF2 189 /-- Co-product of two type constructors. -/ 190 | sum : TyF2 → TyF2 → TyF2 191 /-- List of a type constructor. -/ 192 | list : TyF2 → TyF2 193 194 /-- The type `F(A,B)`. -/ 195 def TyF2.app : TyF2 → Ty → Ty → Ty 196 | .p1, A, _ => A 197 | .p2, _, B => B 198 | .unit, _, _ => Ty.unit 199 | .prod F G, A, B => (F.app A B) ⊗ (G.app A B) 200 | .sum F G, A, B => (F.app A B) ⊕' (G.app A B) 201 | .list F, A, B => (F.app A B)⋆ 202 203 /-- The concatenation map `F(A,B) ↣ (A+B)*`, which injects the elements of `A` and of `B` 204 into the co-product `A + B` and concatenates all of them. -/ 205 def TyF2.concatMap : (F : TyF2) → (A B : Ty) → Term (F.app A B) (A ⊕' B)⋆ 206 | .p1, A, B => inl A B ⨟ pureT (A ⊕' B) 207 | .p2, A, B => inr A B ⨟ pureT (A ⊕' B) 208 | .unit, A, B => nilT (A ⊕' B) 209 | .prod F G, A, B => (F.concatMap A B) ⊙ (G.concatMap A B) 210 | .sum F G, A, B => either (F.concatMap A B) (G.concatMap A B) 211 | .list F, A, B => homT (F.concatMap A B) 212 213 /-- The inverse of `block`: it injects `A` and `B` into the co-product `A + B` and then 214 concatenates all resulting lists. -/ 215 def unblock (A B : Ty) : Term (A⋆ ⊗ (B ⊗ A⋆)⋆) (A ⊕' B)⋆ := 216 TyF2.concatMap (.prod (.list .p1) (.list (.prod .p2 (.list .p1)))) A B 217 218 -- The terms `shift` and `unshift` of Table 1 219 220 /-- The lift `shift : (A × B)* ⊸ 1 + A × (B × A)* × B`, obtained by composing `uncons`, 221 `assocR` and `shiftL`. -/ 222 def shift (A B : Ty) : Term ((A ⊗ B)⋆) (Ty.unit ⊕' (A ⊗ ((B ⊗ A)⋆ ⊗ B))) := 223 uncons (A ⊗ B) ⨟ 224 sumF (Term.id Ty.unit) (assocR A B ((A ⊗ B)⋆) ⨟ prodF (Term.id A) (shiftL B A)) 225 226 /-- The drop `unshift : 1 + A × (B × A)* × B ⇒ (A × B)*`, the inverse of `shift`. -/ 227 def unshift (A B : Ty) : Term (Ty.unit ⊕' (A ⊗ ((B ⊗ A)⋆ ⊗ B))) ((A ⊗ B)⋆) := 228 sumF (Term.id Ty.unit) (prodF (Term.id A) (shiftR B A) ⨟ assocL A B ((A ⊗ B)⋆)) ⨟ cons (A ⊗ B) 229 230 -- Terms for finite alphabets and the inverse of the group prefix operation 231 232 /-- The value `1 → 1 + ⋯ + 1` that picks out a given letter of a finite alphabet. -/ 233 def constFin : {n : ℕ} → ⟦Ty.finAlph n⟧ → Value (Ty.finAlph n) 234 | 0, _ => Term.id Ty.unit 235 | (_ + 1), .inl _ => inl Ty.unit _ 236 | (_ + 1), .inr g => constFin g ⨟ inr Ty.unit _ 237 238 /-- Case analysis on a letter of a finite alphabet that appears as the right component of a 239 product; it is derived using distributivity and co-pairing. -/ 240 def caseR : {n : ℕ} → {A B : Ty} → (⟦Ty.finAlph n⟧ → Term A B) → Term (A ⊗ Ty.finAlph n) B 241 | 0, A, _, t => fst A Ty.unit ⨟ t () 242 | (n + 1), A, _, t => 243 distR A Ty.unit (Ty.finAlph n) ⨟ 244 either (fst A Ty.unit ⨟ t (.inl ())) (caseR (fun g => t (.inr g))) 245 246 /-- Case analysis on a letter of a finite alphabet that appears as the left component of a 247 product. -/ 248 def caseL : {n : ℕ} → {A B : Ty} → (⟦Ty.finAlph n⟧ → Term A B) → Term (Ty.finAlph n ⊗ A) B 249 | 0, A, _, t => snd Ty.unit A ⨟ t () 250 | (n + 1), A, _, t => 251 distL Ty.unit (Ty.finAlph n) A ⨟ 252 either (snd Ty.unit A ⨟ t (.inl ())) (caseL (fun g => t (.inr g))) 253 254 /-- The term `(a,g) ↦ (g,(a,g))`, admissible because the group is a finite alphabet. -/ 255 def grepeat (A : Ty) (n : ℕ) : Term (A ⊗ Ty.finAlph n) (Ty.finAlph n ⊗ (A ⊗ Ty.finAlph n)) := 256 caseR (fun g => pairL (constFin g) (pairR (Term.id A) (constFin g))) 257 258 /-- The term `(h,(g,a)) ↦ (a, h⁻¹ · g)`, admissible because the group is a finite 259 alphabet. -/ 260 def gdiv (A : Ty) {n : ℕ} (G : Group ⟦Ty.finAlph n⟧) : 261 Term (Ty.finAlph n ⊗ (Ty.finAlph n ⊗ A)) (A ⊗ Ty.finAlph n) := 262 caseL (fun h => caseL (fun g => pairR (Term.id A) (constFin (letI := G; h⁻¹ * g)))) 263 264 /-- The unprefixing operation, the inverse of the group prefix multiplication: 265 `[(a₁,g₁),…,(aₙ,gₙ)] ↦ [(a₁,g₀⁻¹g₁),(a₂,g₁⁻¹g₂),…,(aₙ,gₙ₋₁⁻¹gₙ)]`, where `g₀` is the group 266 identity. -/ 267 def unpref (A : Ty) {n : ℕ} (G : Group ⟦Ty.finAlph n⟧) : 268 Term ((A ⊗ Ty.finAlph n)⋆) ((A ⊗ Ty.finAlph n)⋆) := 269 listF (grepeat A n) ⨟ 270 listF (assocL (Ty.finAlph n) A (Ty.finAlph n)) ⨟ 271 pairL (constFin (letI := G; (1 : ⟦Ty.finAlph n⟧))) (Term.id _) ⨟ 272 shiftL (Ty.finAlph n) (Ty.finAlph n ⊗ A) ⨟ 273 fst _ _ ⨟ listF (gdiv A G) 274 275 end Term 276 277 end Lax149335.DerivedTerms 278 -
Derived terms
The following terms are derived from the atomic functions and combinators of Definition 3.1. They are used to state the axioms of Section 4 and the results of the completeness proof.
- The unique term , co-pairing , commutativity and associativity of co-products.
- The list notation of Section 4.6: the empty list , , , , , the homomorphism combinator , and the concatenation of two terms with list outputs.
- The inverses of distributivity, and (Section 4.4).
- Definition 5.1 (Value). A value is a term of type . For a list value , the terms and prepend or append the output of to the output of (Section 5.2), and returns the first element of a list, or the output of for the empty list.
- Concatenation maps (Section 5.1). For a type constructor with one parameter, built from the parameter, , , and , the concatenation map lists all the elements of occurring in the input, from left to right. Similarly for type constructors with two parameters, with outputs in . In particular, is a concatenation map.
- The terms and of Table 1.
- The inverse of group prefix multiplication (Section 4.4), which maps to , where is the group identity.
1 import Lax149335.Terms 2 … module docstring, 39 lines 42 43 namespace Lax149335.DerivedTerms 44 45 open Lax149335.Types Lax149335.Terms 46 47 namespace Term 48 49 open Lax149335.Terms.Term 50 51 /-- The unique function into the unit type, `A → 1`. -/ 52 def toUnit (A : Ty) : Term A Ty.unit := unitL A ⨟ fst Ty.unit A 53 54 /-- Co-pairing, a derived combinator: `either f₁ f₂ = (f₁ + f₂); codiag`. -/ 55 def either {A₁ A₂ B : Ty} (f₁ : Term A₁ B) (f₂ : Term A₂ B) : Term (A₁ ⊕' A₂) B := 56 sumF f₁ f₂ ⨟ codiag B 57 58 /-- Commutativity of the co-product, a derived term. -/ 59 def comm (A B : Ty) : Term (A ⊕' B) (B ⊕' A) := either (inr B A) (inl B A) 60 61 /-- Associativity of the co-product, from left to right. -/ 62 def sumAssocR (A B C : Ty) : Term ((A ⊕' B) ⊕' C) (A ⊕' (B ⊕' C)) := 63 either (either (inl A (B ⊕' C)) (inl B C ⨟ inr A (B ⊕' C))) (inr B C ⨟ inr A (B ⊕' C)) 64 65 /-- Associativity of the co-product, from right to left. -/ 66 def sumAssocL (A B C : Ty) : Term (A ⊕' (B ⊕' C)) ((A ⊕' B) ⊕' C) := 67 either (inl A B ⨟ inl (A ⊕' B) C) 68 (either (inr A B ⨟ inl (A ⊕' B) C) (inr (A ⊕' B) C)) 69 70 /-- The empty list `[] : 1 → A*`, defined as `Left; cons`. -/ 71 def nilT (A : Ty) : Term Ty.unit A⋆ := inl Ty.unit (A ⊗ A⋆) ⨟ cons A 72 73 /-- `prepend : A × A* → A*`, defined as `Right; cons`. -/ 74 def prepend (A : Ty) : Term (A ⊗ A⋆) A⋆ := inr Ty.unit (A ⊗ A⋆) ⨟ cons A 75 76 /-- `append : A* × A → A*`, defined as `Right; snoc`. -/ 77 def append (A : Ty) : Term (A⋆ ⊗ A) A⋆ := inr Ty.unit (A⋆ ⊗ A) ⨟ snoc A 78 79 /-- `pure : A → A*`, defined as `(id,1); id × []; prepend`. -/ 80 def pureT (A : Ty) : Term A A⋆ := 81 unitR A ⨟ prodF (Term.id A) (nilT A) ⨟ prepend A 82 83 /-- `binconcat : A* × A* → A*`, defined as `(id × pure); prepend; concat`. -/ 84 def binconcat (A : Ty) : Term (A⋆ ⊗ A⋆) A⋆ := 85 prodF (Term.id A⋆) (pureT A⋆) ⨟ prepend A⋆ ⨟ concat A 86 87 /-- The homomorphism combinator `hom f = f*; concat`. -/ 88 def homT {A B : Ty} (f : Term A B⋆) : Term A⋆ B⋆ := listF f ⨟ concat B 89 90 /-- Concatenation of two functions with list outputs, `f ⊙ g = (f × g); binconcat`. -/ 91 def fdot {A₁ A₂ B : Ty} (f : Term A₁ B⋆) (g : Term A₂ B⋆) : Term (A₁ ⊗ A₂) B⋆ := 92 prodF f g ⨟ binconcat B 93 94 /-- Notation `f ⊙ g` for the concatenation of two terms with list outputs. -/ 95 infixl:65 " ⊙ " => Term.fdot 96 97 /-- The inverse of distributivity on the right, 98 `undistR = either (id × Left) (id × Right)`. -/ 99 def undistR (A B C : Ty) : Term ((A ⊗ B) ⊕' (A ⊗ C)) (A ⊗ (B ⊕' C)) := 100 either (prodF (Term.id A) (inl B C)) (prodF (Term.id A) (inr B C)) 101 102 /-- The inverse of distributivity on the left. -/ 103 def undistL (A B C : Ty) : Term ((A ⊗ C) ⊕' (B ⊗ C)) ((A ⊕' B) ⊗ C) := 104 either (prodF (inl A B) (Term.id C)) (prodF (inr A B) (Term.id C)) 105 106 -- Values and concatenation with values (Section 5.2) 107 108 /-- **Definition 5.1 (Value).** A value is a term of type `1 → A`. -/ 109 abbrev Value (A : Ty) : Type := Term Ty.unit A 110 111 /-- Pairing a value on the left with an arbitrary term: `(v,f) = (1,id); (v × f)`. -/ 112 def pairL {A B C : Ty} (v : Value C) (f : Term A B) : Term A (C ⊗ B) := 113 unitL A ⨟ prodF v f 114 115 /-- Pairing a value on the right with an arbitrary term: `(f,v) = (id,1); (f × v)`. -/ 116 def pairR {A B C : Ty} (f : Term A B) (v : Value C) : Term A (B ⊗ C) := 117 unitR A ⨟ prodF f v 118 119 /-- Concatenation of a list value on the left with a term with list outputs, `w · f`. -/ 120 def dotL {A B : Ty} (w : Value B⋆) (f : Term A B⋆) : Term A B⋆ := 121 pairL w f ⨟ binconcat B 122 123 /-- Concatenation of a term with list outputs with a list value on the right, `f · w`. -/ 124 def dotR {A B : Ty} (f : Term A B⋆) (w : Value B⋆) : Term A B⋆ := 125 pairR f w ⨟ binconcat B 126 127 /-- The singleton list value `[v] = v; pure`. -/ 128 def sing {A : Ty} (v : Value A) : Value A⋆ := v ⨟ pureT A 129 130 /-- The *head term for `w`*: the first element of a list, or the value `w` if the list is 131 empty. -/ 132 def headT {A : Ty} (w : Value A) : Term A⋆ A := 133 uncons A ⨟ either w (fst A A⋆) 134 135 -- Concatenation maps (Section 5.1) 136 137 /-- Type constructors with one parameter, used to define concatenation maps. -/ 138 inductive TyF : Type 139 /-- The parameter itself. -/ 140 | param : TyF 141 /-- The unit type. -/ 142 | unit : TyF 143 /-- Product of two type constructors. -/ 144 | prod : TyF → TyF → TyF 145 /-- Co-product of two type constructors. -/ 146 | sum : TyF → TyF → TyF 147 /-- List of a type constructor. -/ 148 | list : TyF → TyF 149 150 /-- The type `F(A)` obtained by substituting the type `A` for the parameter of `F`. -/ 151 def TyF.app : TyF → Ty → Ty 152 | .param, A => A 153 | .unit, _ => Ty.unit 154 | .prod F G, A => (F.app A) ⊗ (G.app A) 155 | .sum F G, A => (F.app A) ⊕' (G.app A) 156 | .list F, A => (F.app A)⋆ 157 158 /-- **Concatenation maps** (Section 5.1): the term `F(A) ↣ A*` that concatenates all the 159 elements of the input into a single list, defined by induction on `F`. -/ 160 def TyF.concatMap : (F : TyF) → (A : Ty) → Term (F.app A) A⋆ 161 | .param, A => pureT A 162 | .unit, A => nilT A 163 | .prod F G, A => (F.concatMap A) ⊙ (G.concatMap A) 164 | .sum F G, A => either (F.concatMap A) (G.concatMap A) 165 | .list F, A => homT (F.concatMap A) 166 167 /-- The type constructor `A ↦ Aᵏ`, the `k`-fold product of the parameter with itself. -/ 168 def TyF.pow : ℕ → TyF 169 | 0 => .unit 170 | (k + 1) => .prod .param (TyF.pow k) 171 172 /-- The type constructor `A ↦ A⁰ + A¹ + ⋯ + Aᵏ`, i.e. `A^{<k+1}` in the notation of the 173 paper. -/ 174 def TyF.lt : ℕ → TyF 175 | 0 => TyF.pow 0 176 | (k + 1) => .sum (TyF.lt k) (TyF.pow (k + 1)) 177 178 /-- Type constructors with two parameters, used for the concatenation maps with values in 179 `(A + B)*` that occur in Axiom 15 and in the definition of `unblock`. -/ 180 inductive TyF2 : Type 181 /-- The first parameter. -/ 182 | p1 : TyF2 183 /-- The second parameter. -/ 184 | p2 : TyF2 185 /-- The unit type. -/ 186 | unit : TyF2 187 /-- Product of two type constructors. -/ 188 | prod : TyF2 → TyF2 → TyF2 189 /-- Co-product of two type constructors. -/ 190 | sum : TyF2 → TyF2 → TyF2 191 /-- List of a type constructor. -/ 192 | list : TyF2 → TyF2 193 194 /-- The type `F(A,B)`. -/ 195 def TyF2.app : TyF2 → Ty → Ty → Ty 196 | .p1, A, _ => A 197 | .p2, _, B => B 198 | .unit, _, _ => Ty.unit 199 | .prod F G, A, B => (F.app A B) ⊗ (G.app A B) 200 | .sum F G, A, B => (F.app A B) ⊕' (G.app A B) 201 | .list F, A, B => (F.app A B)⋆ 202 203 /-- The concatenation map `F(A,B) ↣ (A+B)*`, which injects the elements of `A` and of `B` 204 into the co-product `A + B` and concatenates all of them. -/ 205 def TyF2.concatMap : (F : TyF2) → (A B : Ty) → Term (F.app A B) (A ⊕' B)⋆ 206 | .p1, A, B => inl A B ⨟ pureT (A ⊕' B) 207 | .p2, A, B => inr A B ⨟ pureT (A ⊕' B) 208 | .unit, A, B => nilT (A ⊕' B) 209 | .prod F G, A, B => (F.concatMap A B) ⊙ (G.concatMap A B) 210 | .sum F G, A, B => either (F.concatMap A B) (G.concatMap A B) 211 | .list F, A, B => homT (F.concatMap A B) 212 213 /-- The inverse of `block`: it injects `A` and `B` into the co-product `A + B` and then 214 concatenates all resulting lists. -/ 215 def unblock (A B : Ty) : Term (A⋆ ⊗ (B ⊗ A⋆)⋆) (A ⊕' B)⋆ := 216 TyF2.concatMap (.prod (.list .p1) (.list (.prod .p2 (.list .p1)))) A B 217 218 -- The terms `shift` and `unshift` of Table 1 219 220 /-- The lift `shift : (A × B)* ⊸ 1 + A × (B × A)* × B`, obtained by composing `uncons`, 221 `assocR` and `shiftL`. -/ 222 def shift (A B : Ty) : Term ((A ⊗ B)⋆) (Ty.unit ⊕' (A ⊗ ((B ⊗ A)⋆ ⊗ B))) := 223 uncons (A ⊗ B) ⨟ 224 sumF (Term.id Ty.unit) (assocR A B ((A ⊗ B)⋆) ⨟ prodF (Term.id A) (shiftL B A)) 225 226 /-- The drop `unshift : 1 + A × (B × A)* × B ⇒ (A × B)*`, the inverse of `shift`. -/ 227 def unshift (A B : Ty) : Term (Ty.unit ⊕' (A ⊗ ((B ⊗ A)⋆ ⊗ B))) ((A ⊗ B)⋆) := 228 sumF (Term.id Ty.unit) (prodF (Term.id A) (shiftR B A) ⨟ assocL A B ((A ⊗ B)⋆)) ⨟ cons (A ⊗ B) 229 230 -- Terms for finite alphabets and the inverse of the group prefix operation 231 232 /-- The value `1 → 1 + ⋯ + 1` that picks out a given letter of a finite alphabet. -/ 233 def constFin : {n : ℕ} → ⟦Ty.finAlph n⟧ → Value (Ty.finAlph n) 234 | 0, _ => Term.id Ty.unit 235 | (_ + 1), .inl _ => inl Ty.unit _ 236 | (_ + 1), .inr g => constFin g ⨟ inr Ty.unit _ 237 238 /-- Case analysis on a letter of a finite alphabet that appears as the right component of a 239 product; it is derived using distributivity and co-pairing. -/ 240 def caseR : {n : ℕ} → {A B : Ty} → (⟦Ty.finAlph n⟧ → Term A B) → Term (A ⊗ Ty.finAlph n) B 241 | 0, A, _, t => fst A Ty.unit ⨟ t () 242 | (n + 1), A, _, t => 243 distR A Ty.unit (Ty.finAlph n) ⨟ 244 either (fst A Ty.unit ⨟ t (.inl ())) (caseR (fun g => t (.inr g))) 245 246 /-- Case analysis on a letter of a finite alphabet that appears as the left component of a 247 product. -/ 248 def caseL : {n : ℕ} → {A B : Ty} → (⟦Ty.finAlph n⟧ → Term A B) → Term (Ty.finAlph n ⊗ A) B 249 | 0, A, _, t => snd Ty.unit A ⨟ t () 250 | (n + 1), A, _, t => 251 distL Ty.unit (Ty.finAlph n) A ⨟ 252 either (snd Ty.unit A ⨟ t (.inl ())) (caseL (fun g => t (.inr g))) 253 254 /-- The term `(a,g) ↦ (g,(a,g))`, admissible because the group is a finite alphabet. -/ 255 def grepeat (A : Ty) (n : ℕ) : Term (A ⊗ Ty.finAlph n) (Ty.finAlph n ⊗ (A ⊗ Ty.finAlph n)) := 256 caseR (fun g => pairL (constFin g) (pairR (Term.id A) (constFin g))) 257 258 /-- The term `(h,(g,a)) ↦ (a, h⁻¹ · g)`, admissible because the group is a finite 259 alphabet. -/ 260 def gdiv (A : Ty) {n : ℕ} (G : Group ⟦Ty.finAlph n⟧) : 261 Term (Ty.finAlph n ⊗ (Ty.finAlph n ⊗ A)) (A ⊗ Ty.finAlph n) := 262 caseL (fun h => caseL (fun g => pairR (Term.id A) (constFin (letI := G; h⁻¹ * g)))) 263 264 /-- The unprefixing operation, the inverse of the group prefix multiplication: 265 `[(a₁,g₁),…,(aₙ,gₙ)] ↦ [(a₁,g₀⁻¹g₁),(a₂,g₁⁻¹g₂),…,(aₙ,gₙ₋₁⁻¹gₙ)]`, where `g₀` is the group 266 identity. -/ 267 def unpref (A : Ty) {n : ℕ} (G : Group ⟦Ty.finAlph n⟧) : 268 Term ((A ⊗ Ty.finAlph n)⋆) ((A ⊗ Ty.finAlph n)⋆) := 269 listF (grepeat A n) ⨟ 270 listF (assocL (Ty.finAlph n) A (Ty.finAlph n)) ⨟ 271 pairL (constFin (letI := G; (1 : ⟦Ty.finAlph n⟧))) (Term.id _) ⨟ 272 shiftL (Ty.finAlph n) (Ty.finAlph n ⊗ A) ⨟ 273 fst _ _ ⨟ listF (gdiv A G) 274 275 end Term 276 277 end Lax149335.DerivedTerms 278 -
Derived terms
The following terms are derived from the atomic functions and combinators of Definition 3.1. They are used to state the axioms of Section 4 and the results of the completeness proof.
- The unique term , co-pairing , commutativity and associativity of co-products.
- The list notation of Section 4.6: the empty list , , , , , the homomorphism combinator , and the concatenation of two terms with list outputs.
- The inverses of distributivity, and (Section 4.4).
- Definition 5.1 (Value). A value is a term of type . For a list value , the terms and prepend or append the output of to the output of (Section 5.2), and returns the first element of a list, or the output of for the empty list.
- Concatenation maps (Section 5.1). For a type constructor with one parameter, built from the parameter, , , and , the concatenation map lists all the elements of occurring in the input, from left to right. Similarly for type constructors with two parameters, with outputs in . In particular, is a concatenation map.
- The terms and of Table 1.
- The inverse of group prefix multiplication (Section 4.4), which maps to , where is the group identity.
1 import Lax149335.Terms 2 … module docstring, 39 lines 42 43 namespace Lax149335.DerivedTerms 44 45 open Lax149335.Types Lax149335.Terms 46 47 namespace Term 48 49 open Lax149335.Terms.Term 50 51 /-- The unique function into the unit type, `A → 1`. -/ 52 def toUnit (A : Ty) : Term A Ty.unit := unitL A ⨟ fst Ty.unit A 53 54 /-- Co-pairing, a derived combinator: `either f₁ f₂ = (f₁ + f₂); codiag`. -/ 55 def either {A₁ A₂ B : Ty} (f₁ : Term A₁ B) (f₂ : Term A₂ B) : Term (A₁ ⊕' A₂) B := 56 sumF f₁ f₂ ⨟ codiag B 57 58 /-- Commutativity of the co-product, a derived term. -/ 59 def comm (A B : Ty) : Term (A ⊕' B) (B ⊕' A) := either (inr B A) (inl B A) 60 61 /-- Associativity of the co-product, from left to right. -/ 62 def sumAssocR (A B C : Ty) : Term ((A ⊕' B) ⊕' C) (A ⊕' (B ⊕' C)) := 63 either (either (inl A (B ⊕' C)) (inl B C ⨟ inr A (B ⊕' C))) (inr B C ⨟ inr A (B ⊕' C)) 64 65 /-- Associativity of the co-product, from right to left. -/ 66 def sumAssocL (A B C : Ty) : Term (A ⊕' (B ⊕' C)) ((A ⊕' B) ⊕' C) := 67 either (inl A B ⨟ inl (A ⊕' B) C) 68 (either (inr A B ⨟ inl (A ⊕' B) C) (inr (A ⊕' B) C)) 69 70 /-- The empty list `[] : 1 → A*`, defined as `Left; cons`. -/ 71 def nilT (A : Ty) : Term Ty.unit A⋆ := inl Ty.unit (A ⊗ A⋆) ⨟ cons A 72 73 /-- `prepend : A × A* → A*`, defined as `Right; cons`. -/ 74 def prepend (A : Ty) : Term (A ⊗ A⋆) A⋆ := inr Ty.unit (A ⊗ A⋆) ⨟ cons A 75 76 /-- `append : A* × A → A*`, defined as `Right; snoc`. -/ 77 def append (A : Ty) : Term (A⋆ ⊗ A) A⋆ := inr Ty.unit (A⋆ ⊗ A) ⨟ snoc A 78 79 /-- `pure : A → A*`, defined as `(id,1); id × []; prepend`. -/ 80 def pureT (A : Ty) : Term A A⋆ := 81 unitR A ⨟ prodF (Term.id A) (nilT A) ⨟ prepend A 82 83 /-- `binconcat : A* × A* → A*`, defined as `(id × pure); prepend; concat`. -/ 84 def binconcat (A : Ty) : Term (A⋆ ⊗ A⋆) A⋆ := 85 prodF (Term.id A⋆) (pureT A⋆) ⨟ prepend A⋆ ⨟ concat A 86 87 /-- The homomorphism combinator `hom f = f*; concat`. -/ 88 def homT {A B : Ty} (f : Term A B⋆) : Term A⋆ B⋆ := listF f ⨟ concat B 89 90 /-- Concatenation of two functions with list outputs, `f ⊙ g = (f × g); binconcat`. -/ 91 def fdot {A₁ A₂ B : Ty} (f : Term A₁ B⋆) (g : Term A₂ B⋆) : Term (A₁ ⊗ A₂) B⋆ := 92 prodF f g ⨟ binconcat B 93 94 /-- Notation `f ⊙ g` for the concatenation of two terms with list outputs. -/ 95 infixl:65 " ⊙ " => Term.fdot 96 97 /-- The inverse of distributivity on the right, 98 `undistR = either (id × Left) (id × Right)`. -/ 99 def undistR (A B C : Ty) : Term ((A ⊗ B) ⊕' (A ⊗ C)) (A ⊗ (B ⊕' C)) := 100 either (prodF (Term.id A) (inl B C)) (prodF (Term.id A) (inr B C)) 101 102 /-- The inverse of distributivity on the left. -/ 103 def undistL (A B C : Ty) : Term ((A ⊗ C) ⊕' (B ⊗ C)) ((A ⊕' B) ⊗ C) := 104 either (prodF (inl A B) (Term.id C)) (prodF (inr A B) (Term.id C)) 105 106 -- Values and concatenation with values (Section 5.2) 107 108 /-- **Definition 5.1 (Value).** A value is a term of type `1 → A`. -/ 109 abbrev Value (A : Ty) : Type := Term Ty.unit A 110 111 /-- Pairing a value on the left with an arbitrary term: `(v,f) = (1,id); (v × f)`. -/ 112 def pairL {A B C : Ty} (v : Value C) (f : Term A B) : Term A (C ⊗ B) := 113 unitL A ⨟ prodF v f 114 115 /-- Pairing a value on the right with an arbitrary term: `(f,v) = (id,1); (f × v)`. -/ 116 def pairR {A B C : Ty} (f : Term A B) (v : Value C) : Term A (B ⊗ C) := 117 unitR A ⨟ prodF f v 118 119 /-- Concatenation of a list value on the left with a term with list outputs, `w · f`. -/ 120 def dotL {A B : Ty} (w : Value B⋆) (f : Term A B⋆) : Term A B⋆ := 121 pairL w f ⨟ binconcat B 122 123 /-- Concatenation of a term with list outputs with a list value on the right, `f · w`. -/ 124 def dotR {A B : Ty} (f : Term A B⋆) (w : Value B⋆) : Term A B⋆ := 125 pairR f w ⨟ binconcat B 126 127 /-- The singleton list value `[v] = v; pure`. -/ 128 def sing {A : Ty} (v : Value A) : Value A⋆ := v ⨟ pureT A 129 130 /-- The *head term for `w`*: the first element of a list, or the value `w` if the list is 131 empty. -/ 132 def headT {A : Ty} (w : Value A) : Term A⋆ A := 133 uncons A ⨟ either w (fst A A⋆) 134 135 -- Concatenation maps (Section 5.1) 136 137 /-- Type constructors with one parameter, used to define concatenation maps. -/ 138 inductive TyF : Type 139 /-- The parameter itself. -/ 140 | param : TyF 141 /-- The unit type. -/ 142 | unit : TyF 143 /-- Product of two type constructors. -/ 144 | prod : TyF → TyF → TyF 145 /-- Co-product of two type constructors. -/ 146 | sum : TyF → TyF → TyF 147 /-- List of a type constructor. -/ 148 | list : TyF → TyF 149 150 /-- The type `F(A)` obtained by substituting the type `A` for the parameter of `F`. -/ 151 def TyF.app : TyF → Ty → Ty 152 | .param, A => A 153 | .unit, _ => Ty.unit 154 | .prod F G, A => (F.app A) ⊗ (G.app A) 155 | .sum F G, A => (F.app A) ⊕' (G.app A) 156 | .list F, A => (F.app A)⋆ 157 158 /-- **Concatenation maps** (Section 5.1): the term `F(A) ↣ A*` that concatenates all the 159 elements of the input into a single list, defined by induction on `F`. -/ 160 def TyF.concatMap : (F : TyF) → (A : Ty) → Term (F.app A) A⋆ 161 | .param, A => pureT A 162 | .unit, A => nilT A 163 | .prod F G, A => (F.concatMap A) ⊙ (G.concatMap A) 164 | .sum F G, A => either (F.concatMap A) (G.concatMap A) 165 | .list F, A => homT (F.concatMap A) 166 167 /-- The type constructor `A ↦ Aᵏ`, the `k`-fold product of the parameter with itself. -/ 168 def TyF.pow : ℕ → TyF 169 | 0 => .unit 170 | (k + 1) => .prod .param (TyF.pow k) 171 172 /-- The type constructor `A ↦ A⁰ + A¹ + ⋯ + Aᵏ`, i.e. `A^{<k+1}` in the notation of the 173 paper. -/ 174 def TyF.lt : ℕ → TyF 175 | 0 => TyF.pow 0 176 | (k + 1) => .sum (TyF.lt k) (TyF.pow (k + 1)) 177 178 /-- Type constructors with two parameters, used for the concatenation maps with values in 179 `(A + B)*` that occur in Axiom 15 and in the definition of `unblock`. -/ 180 inductive TyF2 : Type 181 /-- The first parameter. -/ 182 | p1 : TyF2 183 /-- The second parameter. -/ 184 | p2 : TyF2 185 /-- The unit type. -/ 186 | unit : TyF2 187 /-- Product of two type constructors. -/ 188 | prod : TyF2 → TyF2 → TyF2 189 /-- Co-product of two type constructors. -/ 190 | sum : TyF2 → TyF2 → TyF2 191 /-- List of a type constructor. -/ 192 | list : TyF2 → TyF2 193 194 /-- The type `F(A,B)`. -/ 195 def TyF2.app : TyF2 → Ty → Ty → Ty 196 | .p1, A, _ => A 197 | .p2, _, B => B 198 | .unit, _, _ => Ty.unit 199 | .prod F G, A, B => (F.app A B) ⊗ (G.app A B) 200 | .sum F G, A, B => (F.app A B) ⊕' (G.app A B) 201 | .list F, A, B => (F.app A B)⋆ 202 203 /-- The concatenation map `F(A,B) ↣ (A+B)*`, which injects the elements of `A` and of `B` 204 into the co-product `A + B` and concatenates all of them. -/ 205 def TyF2.concatMap : (F : TyF2) → (A B : Ty) → Term (F.app A B) (A ⊕' B)⋆ 206 | .p1, A, B => inl A B ⨟ pureT (A ⊕' B) 207 | .p2, A, B => inr A B ⨟ pureT (A ⊕' B) 208 | .unit, A, B => nilT (A ⊕' B) 209 | .prod F G, A, B => (F.concatMap A B) ⊙ (G.concatMap A B) 210 | .sum F G, A, B => either (F.concatMap A B) (G.concatMap A B) 211 | .list F, A, B => homT (F.concatMap A B) 212 213 /-- The inverse of `block`: it injects `A` and `B` into the co-product `A + B` and then 214 concatenates all resulting lists. -/ 215 def unblock (A B : Ty) : Term (A⋆ ⊗ (B ⊗ A⋆)⋆) (A ⊕' B)⋆ := 216 TyF2.concatMap (.prod (.list .p1) (.list (.prod .p2 (.list .p1)))) A B 217 218 -- The terms `shift` and `unshift` of Table 1 219 220 /-- The lift `shift : (A × B)* ⊸ 1 + A × (B × A)* × B`, obtained by composing `uncons`, 221 `assocR` and `shiftL`. -/ 222 def shift (A B : Ty) : Term ((A ⊗ B)⋆) (Ty.unit ⊕' (A ⊗ ((B ⊗ A)⋆ ⊗ B))) := 223 uncons (A ⊗ B) ⨟ 224 sumF (Term.id Ty.unit) (assocR A B ((A ⊗ B)⋆) ⨟ prodF (Term.id A) (shiftL B A)) 225 226 /-- The drop `unshift : 1 + A × (B × A)* × B ⇒ (A × B)*`, the inverse of `shift`. -/ 227 def unshift (A B : Ty) : Term (Ty.unit ⊕' (A ⊗ ((B ⊗ A)⋆ ⊗ B))) ((A ⊗ B)⋆) := 228 sumF (Term.id Ty.unit) (prodF (Term.id A) (shiftR B A) ⨟ assocL A B ((A ⊗ B)⋆)) ⨟ cons (A ⊗ B) 229 230 -- Terms for finite alphabets and the inverse of the group prefix operation 231 232 /-- The value `1 → 1 + ⋯ + 1` that picks out a given letter of a finite alphabet. -/ 233 def constFin : {n : ℕ} → ⟦Ty.finAlph n⟧ → Value (Ty.finAlph n) 234 | 0, _ => Term.id Ty.unit 235 | (_ + 1), .inl _ => inl Ty.unit _ 236 | (_ + 1), .inr g => constFin g ⨟ inr Ty.unit _ 237 238 /-- Case analysis on a letter of a finite alphabet that appears as the right component of a 239 product; it is derived using distributivity and co-pairing. -/ 240 def caseR : {n : ℕ} → {A B : Ty} → (⟦Ty.finAlph n⟧ → Term A B) → Term (A ⊗ Ty.finAlph n) B 241 | 0, A, _, t => fst A Ty.unit ⨟ t () 242 | (n + 1), A, _, t => 243 distR A Ty.unit (Ty.finAlph n) ⨟ 244 either (fst A Ty.unit ⨟ t (.inl ())) (caseR (fun g => t (.inr g))) 245 246 /-- Case analysis on a letter of a finite alphabet that appears as the left component of a 247 product. -/ 248 def caseL : {n : ℕ} → {A B : Ty} → (⟦Ty.finAlph n⟧ → Term A B) → Term (Ty.finAlph n ⊗ A) B 249 | 0, A, _, t => snd Ty.unit A ⨟ t () 250 | (n + 1), A, _, t => 251 distL Ty.unit (Ty.finAlph n) A ⨟ 252 either (snd Ty.unit A ⨟ t (.inl ())) (caseL (fun g => t (.inr g))) 253 254 /-- The term `(a,g) ↦ (g,(a,g))`, admissible because the group is a finite alphabet. -/ 255 def grepeat (A : Ty) (n : ℕ) : Term (A ⊗ Ty.finAlph n) (Ty.finAlph n ⊗ (A ⊗ Ty.finAlph n)) := 256 caseR (fun g => pairL (constFin g) (pairR (Term.id A) (constFin g))) 257 258 /-- The term `(h,(g,a)) ↦ (a, h⁻¹ · g)`, admissible because the group is a finite 259 alphabet. -/ 260 def gdiv (A : Ty) {n : ℕ} (G : Group ⟦Ty.finAlph n⟧) : 261 Term (Ty.finAlph n ⊗ (Ty.finAlph n ⊗ A)) (A ⊗ Ty.finAlph n) := 262 caseL (fun h => caseL (fun g => pairR (Term.id A) (constFin (letI := G; h⁻¹ * g)))) 263 264 /-- The unprefixing operation, the inverse of the group prefix multiplication: 265 `[(a₁,g₁),…,(aₙ,gₙ)] ↦ [(a₁,g₀⁻¹g₁),(a₂,g₁⁻¹g₂),…,(aₙ,gₙ₋₁⁻¹gₙ)]`, where `g₀` is the group 266 identity. -/ 267 def unpref (A : Ty) {n : ℕ} (G : Group ⟦Ty.finAlph n⟧) : 268 Term ((A ⊗ Ty.finAlph n)⋆) ((A ⊗ Ty.finAlph n)⋆) := 269 listF (grepeat A n) ⨟ 270 listF (assocL (Ty.finAlph n) A (Ty.finAlph n)) ⨟ 271 pairL (constFin (letI := G; (1 : ⟦Ty.finAlph n⟧))) (Term.id _) ⨟ 272 shiftL (Ty.finAlph n) (Ty.finAlph n ⊗ A) ⨟ 273 fst _ _ ⨟ listF (gdiv A G) 274 275 end Term 276 277 end Lax149335.DerivedTerms 278 -
Concatenation with values
Lemma 5.2 (Concatenation with values). For terms and and list values ,
1 import Lax149335.EquationalTheory 2 … module docstring, 17 lines 20 21 namespace Lax149335.ValueConcatenation 22 23 open Lax149335.Types Lax149335.Terms Lax149335.DerivedTerms Lax149335.DerivedTerms.Term 24 Lax149335.EquationalTheory 25 26 /-- **Lemma 5.2.** The associativity and unit laws for concatenation with values. -/ 27 axiom value_assoc {A A' B : Ty} (f : Term A B⋆) (g : Term A' B⋆) (w v : Value B⋆) : 28 (dotR (dotR f w) v ≡ₜ dotR f (dotL w v)) ∧ 29 (dotL w (dotL v f) ≡ₜ dotL (dotL w v) f) ∧ 30 (dotR f (nilT B) ≡ₜ f) ∧ 31 (dotL (nilT B) f ≡ₜ f) ∧ 32 (dotR (dotL w f) v ≡ₜ dotL w (dotR f v)) ∧ 33 (fdot (dotR f w) g ≡ₜ fdot f (dotL w g)) 34 35 end Lax149335.ValueConcatenation 36 -
Normalisation of values
Lemma 5.3 (Normalisation of values). Every value is provably equivalent to a value built from the identity on using the following constructors: and for values of co-products, for values of products, and , and for values of list types.
1 import Lax149335.EquationalTheory 2 … module docstring, 10 lines 13 14 namespace Lax149335.ValueNormalisation 15 16 open Lax149335.Types Lax149335.Terms Lax149335.Terms.Term Lax149335.DerivedTerms 17 Lax149335.DerivedTerms.Term Lax149335.EquationalTheory 18 19 /-- Values in normal form. -/ 20 inductive NormalValue : {A : Ty} → Value A → Prop 21 /-- The identity on the unit type. -/ 22 | id : NormalValue (Term.id Ty.unit) 23 /-- A co-product value `v; Left`. -/ 24 | inl {A B : Ty} {v : Value A} : NormalValue v → NormalValue (v ⨟ Term.inl A B) 25 /-- A co-product value `v; Right`. -/ 26 | inr {A B : Ty} {v : Value B} : NormalValue v → NormalValue (v ⨟ Term.inr A B) 27 /-- A product value `(v, w)`. -/ 28 | pair {A B : Ty} {v : Value A} {w : Value B} : 29 NormalValue v → NormalValue w → NormalValue (pairR v w) 30 /-- The concatenation `v · w` of two list values. -/ 31 | dot {A : Ty} {v w : Value A⋆} : NormalValue v → NormalValue w → NormalValue (dotL v w) 32 /-- A singleton list value `[v]`. -/ 33 | sing {A : Ty} {v : Value A} : NormalValue v → NormalValue (sing v) 34 /-- The empty list value `[]`. -/ 35 | nil {A : Ty} : NormalValue (nilT A) 36 37 /-- **Lemma 5.3.** Every value is provably equivalent to a value in normal form. -/ 38 axiom normalisation_of_values {A : Ty} (v : Value A) : ∃ u : Value A, NormalValue u ∧ v ≡ₜ u 39 40 end Lax149335.ValueNormalisation 41 -
Injective, surjective and isomorphic terms
Definition 5.4. A rational term is
- injective if for some term ;
- surjective if for some term ;
- an isomorphism if both hold for the same term .
In categorical terms, an injective term is a section and a surjective term is a retraction in the category of rational terms modulo .
1 import Lax149335.EquationalTheory 2 … module docstring, 20 lines 23 24 namespace Lax149335.InjectiveSurjectiveTerms 25 26 open Lax149335.Types Lax149335.Terms Lax149335.EquationalTheory 27 28 /-- `f : A → B` is injective if `f ; f' ≡ id` for some `f' : B → A`. -/ 29 def ProvablyInjective {A B : Ty} (f : Term A B) : Prop := 30 ∃ f' : Term B A, (f ⨟ f') ≡ₜ Term.id A 31 32 /-- `f : A → B` is surjective if `f' ; f ≡ id` for some `f' : B → A`. -/ 33 def ProvablySurjective {A B : Ty} (f : Term A B) : Prop := 34 ∃ f' : Term B A, (f' ⨟ f) ≡ₜ Term.id B 35 36 /-- `f : A → B` is an isomorphism if `f ; f' ≡ id` and `f' ; f ≡ id` for some 37 `f' : B → A`. -/ 38 def ProvableIso {A B : Ty} (f : Term A B) : Prop := 39 ∃ f' : Term B A, (f ⨟ f') ≡ₜ Term.id A ∧ (f' ⨟ f) ≡ₜ Term.id B 40 41 end Lax149335.InjectiveSurjectiveTerms 42 -
Cancelling injective and surjective terms
Lemma 5.5. For all terms ,
1 import Lax149335.InjectiveSurjectiveTerms 2 … module docstring, 15 lines 18 19 namespace Lax149335.Cancellation 20 21 open Lax149335.Types Lax149335.Terms Lax149335.EquationalTheory Lax149335.InjectiveSurjectiveTerms 22 23 /-- **Lemma 5.5.** Injective terms can be cancelled on the right and surjective terms on 24 the left. -/ 25 axiom cancel {A B : Ty} (g₁ g₂ : Term A B) : 26 (∀ (C : Ty) (f : Term B C), ProvablyInjective f → (g₁ ≡ₜ g₂ ↔ (g₁ ⨟ f) ≡ₜ (g₂ ⨟ f))) ∧ 27 (∀ (C : Ty) (f : Term C A), ProvablySurjective f → (g₁ ≡ₜ g₂ ↔ (f ⨟ g₁) ≡ₜ (f ⨟ g₂))) 28 29 end Lax149335.Cancellation 30 -
Injective string representations
Lemma 5.6. For every type there is an injective aperiodic term , where is the binary alphabet.
1 import Lax149335.InjectiveSurjectiveTerms 2 … module docstring, 8 lines 11 12 namespace Lax149335.StringRepresentations 13 14 open Lax149335.Types Lax149335.Terms Lax149335.InjectiveSurjectiveTerms 15 16 /-- **Lemma 5.6.** Every type has an injective aperiodic encoding into binary strings. -/ 17 axiom exists_injective_binary_encoding (A : Ty) : 18 ∃ enc : Term A (Ty.finAlph 1)⋆, IsAperiodic enc ∧ ProvablyInjective enc 19 20 end Lax149335.StringRepresentations 21 -
Simple rational terms within the compositional syntax
The definition of simple rational terms (Definition 2.5) is meaningful in the compositional syntax of Section 3: the simple rational terms with outputs in are the rational terms built from the empty list using co-pairing , concatenation , the homomorphism combinator , and prepending and appending a value, and , where .
For two rational terms and a value , Section 6 considers three conjugacy relations, in increasing order of strength:
- and are denotationally -conjugate if ;
- and are provably -conjugate if ;
- and are syntactically -conjugate if and for some term .
The length of a list value is the length of the list it produces.
1 import Lax149335.EquationalTheory 2 … module docstring, 22 lines 25 26 namespace Lax149335.SimpleRationalWithinSyntax 27 28 open Lax149335.Types Lax149335.Terms Lax149335.DerivedTerms Lax149335.DerivedTerms.Term 29 Lax149335.EquationalTheory 30 31 /-- Simple rational terms with outputs in `B*`, within the syntax of rational terms. -/ 32 inductive IsSimple (B : Ty) : {A : Ty} → Term A B⋆ → Prop 33 /-- The empty function `[] : 1 → B*`. -/ 34 | nil : IsSimple B (nilT B) 35 /-- Co-pairing. -/ 36 | either {A₁ A₂ : Ty} {f₁ : Term A₁ B⋆} {f₂ : Term A₂ B⋆} : 37 IsSimple B f₁ → IsSimple B f₂ → IsSimple B (Term.either f₁ f₂) 38 /-- Concatenation of two functions. -/ 39 | fdot {A₁ A₂ : Ty} {f₁ : Term A₁ B⋆} {f₂ : Term A₂ B⋆} : 40 IsSimple B f₁ → IsSimple B f₂ → IsSimple B (f₁ ⊙ f₂) 41 /-- The homomorphism combinator. -/ 42 | hom {A : Ty} {f : Term A B⋆} : IsSimple B f → IsSimple B (homT f) 43 /-- Prepending a value. -/ 44 | dotL {A : Ty} {f : Term A B⋆} (w : Value B⋆) : IsSimple B f → IsSimple B (Term.dotL w f) 45 /-- Appending a value. -/ 46 | dotR {A : Ty} {f : Term A B⋆} (w : Value B⋆) : IsSimple B f → IsSimple B (Term.dotR f w) 47 48 /-- The length of a list value. -/ 49 def valLength {B : Ty} (w : Value B⋆) : ℕ := List.length (w.den ()) 50 51 /-- `f` and `g` are denotationally `w`-conjugate: `⟦f · w⟧ = ⟦w · g⟧`. -/ 52 def DenConjugate {A B : Ty} (w : Value B⋆) (f g : Term A B⋆) : Prop := 53 (dotR f w).den = (dotL w g).den 54 55 /-- `f` and `g` are provably `w`-conjugate: `f · w ≡ w · g`. -/ 56 def ProvConjugate {A B : Ty} (w : Value B⋆) (f g : Term A B⋆) : Prop := 57 dotR f w ≡ₜ dotL w g 58 59 /-- `f` and `g` are syntactically `w`-conjugate: `f = w · h` and `g = h · w` for some `h`. -/ 60 def SynConjugate {A B : Ty} (w : Value B⋆) (f g : Term A B⋆) : Prop := 61 ∃ h : Term A B⋆, f = dotL w h ∧ g = dotR h w 62 63 end Lax149335.SimpleRationalWithinSyntax 64 -
Completeness for simple rational terms
Lemma 6.1 (Completeness for simple rational terms). For all simple rational terms , where is a finite alphabet, and every value ,
1 import Lax149335.SimpleRationalWithinSyntax 2 … module docstring, 15 lines 18 19 namespace Lax149335.SimpleCompleteness 20 21 open Lax149335.Types Lax149335.Terms Lax149335.DerivedTerms Lax149335.DerivedTerms.Term 22 Lax149335.EquationalTheory Lax149335.SimpleRationalWithinSyntax 23 24 /-- **Lemma 6.1.** The completeness rule and the conjugacy rule for simple rational terms. -/ 25 axiom completeness_simple {A B : Ty} (hB : Ty.IsFinAlph B) (f g : Term A B⋆) 26 (hf : IsSimple B f) (hg : IsSimple B g) (w : Value B⋆) : 27 (f.den = g.den → f ≡ₜ g) ∧ 28 (dotR f w ≡ₜ dotL w g → dotR (homT f) w ≡ₜ dotL w (homT g)) 29 30 end Lax149335.SimpleCompleteness 31 -
The conjugacy rule for syntactic conjugates
Lemma 6.2. For a simple rational term and a value ,
That is, the conjugacy rule holds when its assumption is strengthened from provable to syntactic conjugacy.
1 import Lax149335.SimpleRationalWithinSyntax 2 … module docstring, 18 lines 21 22 namespace Lax149335.ConjugacyRule 23 24 open Lax149335.Types Lax149335.Terms Lax149335.DerivedTerms Lax149335.DerivedTerms.Term 25 Lax149335.EquationalTheory 26 27 /-- **Lemma 6.2.** `hom(w · h) · w ≡ w · hom(h · w)`. -/ 28 axiom conjugacy_of_syntactic {A B : Ty} (h : Term A B⋆) (w : Value B⋆) : 29 dotR (homT (dotL w h)) w ≡ₜ dotL w (homT (dotR h w)) 30 31 end Lax149335.ConjugacyRule 32 -
Guarded terms
Definition 6.3. Let . A term is -guarded if it is either
- constant: the composition of the unique term with a value; or
- long: of the form for values of length and a simple rational term .
A term is nonempty if it never produces the empty list.
The reductions of Lemmas 6.4 and 6.5 are about -ary co-pairings of such terms, and about the nesting depth of the list constructor in a type, on which the proof of Lemma 6.1 is an induction.
1 import Lax149335.SimpleRationalWithinSyntax 2 … module docstring, 25 lines 28 29 namespace Lax149335.GuardedTerms 30 31 open Lax149335.Types Lax149335.Terms Lax149335.DerivedTerms Lax149335.DerivedTerms.Term 32 Lax149335.SimpleRationalWithinSyntax 33 34 /-- **Definition 6.3.** `f : A → B*` is `k`-guarded if it is constant, or of the form 35 `u · h · v` for values `u`, `v` of length `k` and a simple rational term `h`. -/ 36 def KGuarded (k : ℕ) (B : Ty) {A : Ty} (f : Term A B⋆) : Prop := 37 (∃ v : Value B⋆, f = toUnit A ⨟ v) ∨ 38 (∃ (u v : Value B⋆) (h : Term A B⋆), 39 IsSimple B h ∧ valLength u = k ∧ valLength v = k ∧ f = dotR (dotL u h) v) 40 41 /-- A term with list outputs is nonempty if it never produces the empty list. -/ 42 def NonemptyOutput {A B : Ty} (f : Term A B⋆) : Prop := ∀ a : ⟦A⟧, f.den a ≠ [] 43 44 /-- The co-product `A₀ + (A₁ + ⋯ + Aₙ)` of a nonempty list of types. -/ 45 def sumTyOf : Ty → List Ty → Ty 46 | A, [] => A 47 | A, (A' :: As) => A ⊕' sumTyOf A' As 48 49 /-- A list of terms `Aᵢ → B`, one for each type in a list of types. -/ 50 inductive Cases (B : Ty) : List Ty → Type 51 /-- The empty list of terms. -/ 52 | nil : Cases B [] 53 /-- One more term. -/ 54 | cons {A : Ty} {As : List Ty} : Term A B → Cases B As → Cases B (A :: As) 55 56 /-- The `n`-ary co-pairing `⟨f₀, f₁, …, fₙ⟩ : A₀ + (A₁ + ⋯ + Aₙ) → B`. -/ 57 def copair {B : Ty} : {A : Ty} → {As : List Ty} → Term A B → Cases B As → 58 Term (sumTyOf A As) B 59 | _, [], f, _ => f 60 | _, _ :: _, f, .cons g rest => Term.either f (copair g rest) 61 62 /-- A property holds for all terms in a list of terms. -/ 63 def Cases.All {B : Ty} (P : (A : Ty) → Term A B → Prop) : 64 {As : List Ty} → Cases B As → Prop 65 | [], _ => True 66 | _ :: _, .cons f rest => P _ f ∧ Cases.All P rest 67 68 /-- The nesting depth of the list constructor in a type. -/ 69 def Ty.listDepth : Ty → ℕ 70 | .unit => 0 71 | .prod A B => max (Ty.listDepth A) (Ty.listDepth B) 72 | .sum A B => max (Ty.listDepth A) (Ty.listDepth B) 73 | .list A => Ty.listDepth A + 1 74 75 end Lax149335.GuardedTerms 76 -
Reduction to co-pairings of guarded terms
Lemma 6.4. In the proof of the conjugacy rule of Lemma 6.1, let be the length of . Without loss of generality, and are co-pairings
1 import Lax149335.GuardedTerms 2 … module docstring, 22 lines 25 26 namespace Lax149335.GuardedReduction 27 28 open Lax149335.Types Lax149335.Terms Lax149335.DerivedTerms Lax149335.DerivedTerms.Term 29 Lax149335.EquationalTheory Lax149335.SimpleRationalWithinSyntax Lax149335.GuardedTerms 30 31 /-- **Lemma 6.4.** The conjugacy rule for simple rational terms follows from the conjugacy 32 rule for co-pairings of `k`-guarded terms, where `k > 0` is the length of `w`. -/ 33 axiom wlog_kguarded {B : Ty} (w : Value B⋆) (hw : 0 < valLength w) {A : Ty} 34 (H : ∀ (A₀ : Ty) (As : List Ty) (f₀ g₀ : Term A₀ B⋆) (fs gs : Cases B⋆ As), 35 Ty.listDepth (sumTyOf A₀ As) ≤ Ty.listDepth A → 36 KGuarded (valLength w) B f₀ → KGuarded (valLength w) B g₀ → 37 fs.All (fun _ f => KGuarded (valLength w) B f) → 38 gs.All (fun _ g => KGuarded (valLength w) B g) → 39 dotR (copair f₀ fs) w ≡ₜ dotL w (copair g₀ gs) → 40 dotR (homT (copair f₀ fs)) w ≡ₜ dotL w (homT (copair g₀ gs))) 41 (f g : Term A B⋆) (hf : IsSimple B f) (hg : IsSimple B g) 42 (hfg : dotR f w ≡ₜ dotL w g) : 43 dotR (homT f) w ≡ₜ dotL w (homT g) 44 45 end Lax149335.GuardedReduction 46 -
Reduction to nonempty summands
Lemma 6.5. In the situation of Lemma 6.4, one can further assume without loss of generality that all the terms and are nonempty.
1 import Lax149335.GuardedTerms 2 … module docstring, 15 lines 18 19 namespace Lax149335.NonemptyReduction 20 21 open Lax149335.Types Lax149335.Terms Lax149335.DerivedTerms Lax149335.DerivedTerms.Term 22 Lax149335.EquationalTheory Lax149335.SimpleRationalWithinSyntax Lax149335.GuardedTerms 23 24 /-- **Lemma 6.5.** The conjugacy rule for co-pairings of `k`-guarded terms follows from the 25 conjugacy rule for co-pairings of `k`-guarded nonempty terms. -/ 26 axiom wlog_nonempty {B : Ty} (w : Value B⋆) (hw : 0 < valLength w) (D : ℕ) 27 (H : ∀ (A₀ : Ty) (As : List Ty) (f₀ g₀ : Term A₀ B⋆) (fs gs : Cases B⋆ As), 28 Ty.listDepth (sumTyOf A₀ As) ≤ D → 29 KGuarded (valLength w) B f₀ → KGuarded (valLength w) B g₀ → 30 fs.All (fun _ f => KGuarded (valLength w) B f) → 31 gs.All (fun _ g => KGuarded (valLength w) B g) → 32 NonemptyOutput f₀ → NonemptyOutput g₀ → 33 fs.All (fun _ f => NonemptyOutput f) → gs.All (fun _ g => NonemptyOutput g) → 34 dotR (copair f₀ fs) w ≡ₜ dotL w (copair g₀ gs) → 35 dotR (homT (copair f₀ fs)) w ≡ₜ dotL w (homT (copair g₀ gs))) 36 (A₀ : Ty) (As : List Ty) (f₀ g₀ : Term A₀ B⋆) (fs gs : Cases B⋆ As) 37 (hD : Ty.listDepth (sumTyOf A₀ As) ≤ D) 38 (hf₀ : KGuarded (valLength w) B f₀) (hg₀ : KGuarded (valLength w) B g₀) 39 (hfs : fs.All (fun _ f => KGuarded (valLength w) B f)) 40 (hgs : gs.All (fun _ g => KGuarded (valLength w) B g)) 41 (hfg : dotR (copair f₀ fs) w ≡ₜ dotL w (copair g₀ gs)) : 42 dotR (homT (copair f₀ fs)) w ≡ₜ dotL w (homT (copair g₀ gs)) 43 44 end Lax149335.NonemptyReduction 45 -
Ignoring empty summands
Claim 6.6. Let , where is the empty constant, i.e. . Then is provably equivalent to the composition
1 import Lax149335.EquationalTheory 2 … module docstring, 14 lines 17 18 namespace Lax149335.EmptySummands 19 20 open Lax149335.Types Lax149335.Terms Lax149335.Terms.Term Lax149335.DerivedTerms 21 Lax149335.DerivedTerms.Term Lax149335.EquationalTheory 22 23 /-- **Claim 6.6.** If the case `f_E` of a co-pairing is the empty constant, then `hom f` 24 factors through `hom f_N`. -/ 25 axiom hom_factors {B E N : Ty} (fE : Term E B⋆) (fN : Term N B⋆) 26 (hfE : fE ≡ₜ toUnit E ⨟ nilT B) : 27 homT (Term.either fE fN) ≡ₜ 28 (block E N ⨟ snd E⋆ ((N ⊗ E⋆)⋆) ⨟ listF (fst N E⋆) ⨟ homT fN) 29 30 end Lax149335.EmptySummands 31 -
The bundle lemma
Lemma 6.7 (Bundles). For every type , there are arbitrarily large numbers such that the concatenation map
is an isomorphism. Here is the -fold product of with itself, with , and is the co-product of all with .
1 import Lax149335.InjectiveSurjectiveTerms 2 … module docstring, 19 lines 22 23 namespace Lax149335.BundleLemma 24 25 open Lax149335.Types Lax149335.Terms Lax149335.DerivedTerms Lax149335.DerivedTerms.Term 26 Lax149335.InjectiveSurjectiveTerms 27 28 /-- **Lemma 6.7.** For every `N` there is a `k ≥ N` such that, for every type `A`, the 29 concatenation map `(A^{k+1})* × A^{<k+1} ↣ A*` is an isomorphism. -/ 30 axiom concatMap_bundle_iso_arbitrarily_large' (N : ℕ) : 31 ∃ k : ℕ, N ≤ k ∧ ∀ A : Ty, 32 ProvableIso (TyF.concatMap (.prod (.list (TyF.pow (k + 1))) (TyF.lt k)) A) 33 34 end Lax149335.BundleLemma 35 -
Lifts and drops
Definition 7.1 (Lifts and drops). Lift terms (respectively, drop terms) are those which can be obtained from the atomic lift (respectively, atomic drop) terms in Table 1 by applying composition, as well as the functoriality combinators for co-products, products and lists.
Table 1. The atomic lift terms are
and the atomic drop terms are
where is the unique term followed by an arbitrary value .
1 import Lax149335.DerivedTerms 2 … module docstring, 39 lines 42 43 namespace Lax149335.LiftsAndDrops 44 45 open Lax149335.Types Lax149335.Terms Lax149335.DerivedTerms Lax149335.DerivedTerms.Term 46 47 /-- **Definition 7.1 (Lifts).** The terms obtained from the atomic lift terms of Table 1 by 48 composition and the functoriality combinators of products, co-products and lists. -/ 49 inductive IsLift : {A B : Ty} → Term A B → Prop 50 /-- Lifts are closed under composition. -/ 51 | comp {A B C : Ty} {f : Term A B} {g : Term B C} : IsLift f → IsLift g → IsLift (f ⨟ g) 52 /-- Lifts are closed under functoriality of products. -/ 53 | prodF {A₁ A₂ B₁ B₂ : Ty} {f : Term A₁ B₁} {g : Term A₂ B₂} : 54 IsLift f → IsLift g → IsLift (Term.prodF f g) 55 /-- Lifts are closed under functoriality of co-products. -/ 56 | sumF {A₁ A₂ B₁ B₂ : Ty} {f : Term A₁ B₁} {g : Term A₂ B₂} : 57 IsLift f → IsLift g → IsLift (Term.sumF f g) 58 /-- Lifts are closed under functoriality of lists. -/ 59 | listF {A B : Ty} {f : Term A B} : IsLift f → IsLift (Term.listF f) 60 /-- The identity is a prime lift. -/ 61 | id (A : Ty) : IsLift (Term.id A) 62 /-- `(id,1)` is a prime lift. -/ 63 | unitR (A : Ty) : IsLift (Term.unitR A) 64 /-- `(1,id)` is a prime lift. -/ 65 | unitL (A : Ty) : IsLift (Term.unitL A) 66 /-- `assocL` is a prime lift. -/ 67 | assocL (A B C : Ty) : IsLift (Term.assocL A B C) 68 /-- `assocR` is a prime lift. -/ 69 | assocR (A B C : Ty) : IsLift (Term.assocR A B C) 70 /-- Associativity of the co-product, from right to left, is a prime lift. -/ 71 | sumAssocL (A B C : Ty) : IsLift (Term.sumAssocL A B C) 72 /-- Associativity of the co-product, from left to right, is a prime lift. -/ 73 | sumAssocR (A B C : Ty) : IsLift (Term.sumAssocR A B C) 74 /-- Commutativity of the co-product is a prime lift. -/ 75 | comm (A B : Ty) : IsLift (Term.comm A B) 76 /-- `distL` is a prime lift. -/ 77 | distL (A B C : Ty) : IsLift (Term.distL A B C) 78 /-- `distR` is a prime lift. -/ 79 | distR (A B C : Ty) : IsLift (Term.distR A B C) 80 /-- `block` is a prime lift. -/ 81 | block (A B : Ty) : IsLift (Term.block A B) 82 /-- `shift` is a prime lift. -/ 83 | shift (A B : Ty) : IsLift (Term.shift A B) 84 85 /-- **Definition 7.1 (Drops).** The terms obtained from the atomic drop terms of Table 1 by 86 composition and the functoriality combinators of products, co-products and lists. -/ 87 inductive IsDrop : {A B : Ty} → Term A B → Prop 88 /-- Drops are closed under composition. -/ 89 | comp {A B C : Ty} {f : Term A B} {g : Term B C} : IsDrop f → IsDrop g → IsDrop (f ⨟ g) 90 /-- Drops are closed under functoriality of products. -/ 91 | prodF {A₁ A₂ B₁ B₂ : Ty} {f : Term A₁ B₁} {g : Term A₂ B₂} : 92 IsDrop f → IsDrop g → IsDrop (Term.prodF f g) 93 /-- Drops are closed under functoriality of co-products. -/ 94 | sumF {A₁ A₂ B₁ B₂ : Ty} {f : Term A₁ B₁} {g : Term A₂ B₂} : 95 IsDrop f → IsDrop g → IsDrop (Term.sumF f g) 96 /-- Drops are closed under functoriality of lists. -/ 97 | listF {A B : Ty} {f : Term A B} : IsDrop f → IsDrop (Term.listF f) 98 /-- The identity is a prime drop. -/ 99 | id (A : Ty) : IsDrop (Term.id A) 100 /-- A constant function `1 ; v`, for an arbitrary value `v`, is a prime drop. -/ 101 | bangV (A : Ty) {B : Ty} (v : Value B) : IsDrop (Term.toUnit A ⨟ v) 102 /-- `assocL` is a prime drop. -/ 103 | assocL (A B C : Ty) : IsDrop (Term.assocL A B C) 104 /-- `assocR` is a prime drop. -/ 105 | assocR (A B C : Ty) : IsDrop (Term.assocR A B C) 106 /-- `fst` is a prime drop. -/ 107 | fst (A B : Ty) : IsDrop (Term.fst A B) 108 /-- `snd` is a prime drop. -/ 109 | snd (A B : Ty) : IsDrop (Term.snd A B) 110 /-- `Left` is a prime drop. -/ 111 | inl (A B : Ty) : IsDrop (Term.inl A B) 112 /-- `Right` is a prime drop. -/ 113 | inr (A B : Ty) : IsDrop (Term.inr A B) 114 /-- The co-diagonal is a prime drop. -/ 115 | codiag (A : Ty) : IsDrop (Term.codiag A) 116 /-- `pure` is a prime drop. -/ 117 | pureT (A : Ty) : IsDrop (Term.pureT A) 118 /-- `binconcat` is a prime drop. -/ 119 | binconcat (A : Ty) : IsDrop (Term.binconcat A) 120 /-- `concat` is a prime drop. -/ 121 | concat (A : Ty) : IsDrop (Term.concat A) 122 /-- `unshift` is a prime drop. -/ 123 | unshift (A B : Ty) : IsDrop (Term.unshift A B) 124 125 end Lax149335.LiftsAndDrops 126 -
Lifts and drops
Definition 7.1 (Lifts and drops). Lift terms (respectively, drop terms) are those which can be obtained from the atomic lift (respectively, atomic drop) terms in Table 1 by applying composition, as well as the functoriality combinators for co-products, products and lists.
Table 1. The atomic lift terms are
and the atomic drop terms are
where is the unique term followed by an arbitrary value .
1 import Lax149335.DerivedTerms 2 … module docstring, 39 lines 42 43 namespace Lax149335.LiftsAndDrops 44 45 open Lax149335.Types Lax149335.Terms Lax149335.DerivedTerms Lax149335.DerivedTerms.Term 46 47 /-- **Definition 7.1 (Lifts).** The terms obtained from the atomic lift terms of Table 1 by 48 composition and the functoriality combinators of products, co-products and lists. -/ 49 inductive IsLift : {A B : Ty} → Term A B → Prop 50 /-- Lifts are closed under composition. -/ 51 | comp {A B C : Ty} {f : Term A B} {g : Term B C} : IsLift f → IsLift g → IsLift (f ⨟ g) 52 /-- Lifts are closed under functoriality of products. -/ 53 | prodF {A₁ A₂ B₁ B₂ : Ty} {f : Term A₁ B₁} {g : Term A₂ B₂} : 54 IsLift f → IsLift g → IsLift (Term.prodF f g) 55 /-- Lifts are closed under functoriality of co-products. -/ 56 | sumF {A₁ A₂ B₁ B₂ : Ty} {f : Term A₁ B₁} {g : Term A₂ B₂} : 57 IsLift f → IsLift g → IsLift (Term.sumF f g) 58 /-- Lifts are closed under functoriality of lists. -/ 59 | listF {A B : Ty} {f : Term A B} : IsLift f → IsLift (Term.listF f) 60 /-- The identity is a prime lift. -/ 61 | id (A : Ty) : IsLift (Term.id A) 62 /-- `(id,1)` is a prime lift. -/ 63 | unitR (A : Ty) : IsLift (Term.unitR A) 64 /-- `(1,id)` is a prime lift. -/ 65 | unitL (A : Ty) : IsLift (Term.unitL A) 66 /-- `assocL` is a prime lift. -/ 67 | assocL (A B C : Ty) : IsLift (Term.assocL A B C) 68 /-- `assocR` is a prime lift. -/ 69 | assocR (A B C : Ty) : IsLift (Term.assocR A B C) 70 /-- Associativity of the co-product, from right to left, is a prime lift. -/ 71 | sumAssocL (A B C : Ty) : IsLift (Term.sumAssocL A B C) 72 /-- Associativity of the co-product, from left to right, is a prime lift. -/ 73 | sumAssocR (A B C : Ty) : IsLift (Term.sumAssocR A B C) 74 /-- Commutativity of the co-product is a prime lift. -/ 75 | comm (A B : Ty) : IsLift (Term.comm A B) 76 /-- `distL` is a prime lift. -/ 77 | distL (A B C : Ty) : IsLift (Term.distL A B C) 78 /-- `distR` is a prime lift. -/ 79 | distR (A B C : Ty) : IsLift (Term.distR A B C) 80 /-- `block` is a prime lift. -/ 81 | block (A B : Ty) : IsLift (Term.block A B) 82 /-- `shift` is a prime lift. -/ 83 | shift (A B : Ty) : IsLift (Term.shift A B) 84 85 /-- **Definition 7.1 (Drops).** The terms obtained from the atomic drop terms of Table 1 by 86 composition and the functoriality combinators of products, co-products and lists. -/ 87 inductive IsDrop : {A B : Ty} → Term A B → Prop 88 /-- Drops are closed under composition. -/ 89 | comp {A B C : Ty} {f : Term A B} {g : Term B C} : IsDrop f → IsDrop g → IsDrop (f ⨟ g) 90 /-- Drops are closed under functoriality of products. -/ 91 | prodF {A₁ A₂ B₁ B₂ : Ty} {f : Term A₁ B₁} {g : Term A₂ B₂} : 92 IsDrop f → IsDrop g → IsDrop (Term.prodF f g) 93 /-- Drops are closed under functoriality of co-products. -/ 94 | sumF {A₁ A₂ B₁ B₂ : Ty} {f : Term A₁ B₁} {g : Term A₂ B₂} : 95 IsDrop f → IsDrop g → IsDrop (Term.sumF f g) 96 /-- Drops are closed under functoriality of lists. -/ 97 | listF {A B : Ty} {f : Term A B} : IsDrop f → IsDrop (Term.listF f) 98 /-- The identity is a prime drop. -/ 99 | id (A : Ty) : IsDrop (Term.id A) 100 /-- A constant function `1 ; v`, for an arbitrary value `v`, is a prime drop. -/ 101 | bangV (A : Ty) {B : Ty} (v : Value B) : IsDrop (Term.toUnit A ⨟ v) 102 /-- `assocL` is a prime drop. -/ 103 | assocL (A B C : Ty) : IsDrop (Term.assocL A B C) 104 /-- `assocR` is a prime drop. -/ 105 | assocR (A B C : Ty) : IsDrop (Term.assocR A B C) 106 /-- `fst` is a prime drop. -/ 107 | fst (A B : Ty) : IsDrop (Term.fst A B) 108 /-- `snd` is a prime drop. -/ 109 | snd (A B : Ty) : IsDrop (Term.snd A B) 110 /-- `Left` is a prime drop. -/ 111 | inl (A B : Ty) : IsDrop (Term.inl A B) 112 /-- `Right` is a prime drop. -/ 113 | inr (A B : Ty) : IsDrop (Term.inr A B) 114 /-- The co-diagonal is a prime drop. -/ 115 | codiag (A : Ty) : IsDrop (Term.codiag A) 116 /-- `pure` is a prime drop. -/ 117 | pureT (A : Ty) : IsDrop (Term.pureT A) 118 /-- `binconcat` is a prime drop. -/ 119 | binconcat (A : Ty) : IsDrop (Term.binconcat A) 120 /-- `concat` is a prime drop. -/ 121 | concat (A : Ty) : IsDrop (Term.concat A) 122 /-- `unshift` is a prime drop. -/ 123 | unshift (A B : Ty) : IsDrop (Term.unshift A B) 124 125 end Lax149335.LiftsAndDrops 126 -
Lifts are isomorphisms
Lemma 7.2. Every lift is an isomorphism, and its inverse is a drop.
1 import Lax149335.LiftsAndDrops 2 import Lax149335.EquationalTheory 3 … module docstring, 7 lines 11 12 namespace Lax149335.LiftInverses 13 14 open Lax149335.Types Lax149335.Terms Lax149335.EquationalTheory Lax149335.LiftsAndDrops 15 16 /-- **Lemma 7.2.** Every lift `f : A → B` has an inverse `g : B → A` that is a drop. -/ 17 axiom lift_iso {A B : Ty} (f : Term A B) (hf : IsLift f) : 18 ∃ g : Term B A, IsDrop g ∧ (f ⨟ g) ≡ₜ Term.id A ∧ (g ⨟ f) ≡ₜ Term.id B 19 20 end Lax149335.LiftInverses 21 -
Provable simplification of drops
Lemma 7.3 (Provable simplification of drops). Let be a finite alphabet, and let be drops. There is a lift and its inverse such that and are both equivalent to simple rational terms.
1 import Lax149335.LiftsAndDrops 2 import Lax149335.SimpleRationalWithinSyntax 3 … module docstring, 15 lines 19 20 namespace Lax149335.DropsJointSimplification 21 22 open Lax149335.Types Lax149335.Terms Lax149335.EquationalTheory Lax149335.LiftsAndDrops 23 Lax149335.SimpleRationalWithinSyntax 24 25 /-- **Lemma 7.3.** Two drops `A → N*` into the lists over a finite alphabet become provably 26 equivalent to simple rational terms after precomposing with the inverse of a common lift. -/ 27 axiom drops_to_simple {A B : Ty} (hB : Ty.IsFinAlph B) (f g : Term A B⋆) 28 (hf : IsDrop f) (hg : IsDrop g) : 29 ∃ (C : Ty) (l : Term A C) (π : Term C A), 30 IsLift l ∧ IsDrop π ∧ (l ⨟ π) ≡ₜ Term.id A ∧ (π ⨟ l) ≡ₜ Term.id C ∧ 31 (∃ f' : Term C B⋆, IsSimple B f' ∧ (π ⨟ f) ≡ₜ f') ∧ 32 (∃ g' : Term C B⋆, IsSimple B g' ∧ (π ⨟ g) ≡ₜ g') 33 34 end Lax149335.DropsJointSimplification 35 -
Lift-drop factorisation
Lemma 7.4 (Lift-drop factorisation). Every aperiodic rational term is provably equivalent to a composition of a lift followed by a drop.
1 import Lax149335.LiftsAndDrops 2 import Lax149335.EquationalTheory 3 … module docstring, 8 lines 12 13 namespace Lax149335.LiftDropFactorisation 14 15 open Lax149335.Types Lax149335.Terms Lax149335.EquationalTheory Lax149335.LiftsAndDrops 16 17 /-- **Lemma 7.4.** Every aperiodic term is provably equivalent to a lift followed by a 18 drop. -/ 19 axiom lift_drop_factorisation {A B : Ty} (f : Term A B) (hf : IsAperiodic f) : 20 ∃ (C : Ty) (l : Term A C) (d : Term C B), IsLift l ∧ IsDrop d ∧ f ≡ₜ (l ⨟ d) 21 22 end Lax149335.LiftDropFactorisation 23 -
Exchange
Lemma 7.5 (Exchange). Every composition of the form drop-lift is equivalent to a composition of the form lift-drop.
1 import Lax149335.LiftsAndDrops 2 import Lax149335.EquationalTheory 3 … module docstring, 8 lines 12 13 namespace Lax149335.Exchange 14 15 open Lax149335.Types Lax149335.Terms Lax149335.EquationalTheory Lax149335.LiftsAndDrops 16 17 /-- **Lemma 7.5.** A drop followed by a lift is provably equivalent to a lift followed by a 18 drop. -/ 19 axiom exchange {A B C : Ty} (d : Term A B) (l : Term B C) (hd : IsDrop d) (hl : IsLift l) : 20 ∃ (D : Ty) (l' : Term A D) (d' : Term D C), IsLift l' ∧ IsDrop d' ∧ (d ⨟ l) ≡ₜ (l' ⨟ d') 21 22 end Lax149335.Exchange 23 -
Aperiodic completeness
Corollary 7.6 (Aperiodic completeness). If aperiodic rational terms and have the same denotation, then .
1 import Lax149335.EquationalTheory 2 … module docstring, 8 lines 11 12 namespace Lax149335.AperiodicCompleteness 13 14 open Lax149335.Types Lax149335.Terms Lax149335.EquationalTheory 15 16 /-- **Corollary 7.6.** Aperiodic terms with the same denotation are provably equivalent. -/ 17 axiom completeness_aperiodic {A B : Ty} (f g : Term A B) 18 (hf : IsAperiodic f) (hg : IsAperiodic g) (h : f.den = g.den) : f ≡ₜ g 19 20 end Lax149335.AperiodicCompleteness 21 -
Provable simplification of rational terms
Theorem 7.7 (Provable simplification of rational terms). Consider rational terms , where is a finite alphabet. There is a type and a surjective rational term , such that and are equivalent to simple rational terms.
This is a strengthening of Theorem 2.9 in which the decomposition is carried out within the equational system: surjectivity of is the provable notion of Definition 5.4, and the equivalences are provable.
1 import Lax149335.InjectiveSurjectiveTerms 2 import Lax149335.SimpleRationalWithinSyntax 3 … module docstring, 14 lines 18 19 namespace Lax149335.ProvableSimplification 20 21 open Lax149335.Types Lax149335.Terms Lax149335.EquationalTheory Lax149335.InjectiveSurjectiveTerms 22 Lax149335.SimpleRationalWithinSyntax 23 24 /-- **Theorem 7.7.** Two terms `A → N*` into the 25 lists over a finite alphabet become provably equivalent to simple rational terms after 26 precomposing with a common surjective term `π : B → A`. -/ 27 axiom provable_simplification {A N : Ty} (hN : Ty.IsFinAlph N) (f g : Term A N⋆) : 28 ∃ (B : Ty) (π : Term B A), ProvablySurjective π ∧ 29 (∃ f' : Term B N⋆, IsSimple N f' ∧ (π ⨟ f) ≡ₜ f') ∧ 30 (∃ g' : Term B N⋆, IsSimple N g' ∧ (π ⨟ g) ≡ₜ g') 31 32 end Lax149335.ProvableSimplification 33 -
The equational theory
Section 4 introduces an equivalence relation on rational terms of the same type, called provable equivalence. It is the least equivalence relation on rational terms that contains the following sixteen axioms and is preserved by the four combinators of Definition 3.1 (composition and functoriality of products, co-products and lists).
- Category axioms: composition is associative and the identity is neutral.
- Functoriality: the combinators , and preserve identities and composition.
- Naturality: every atomic function except prefix multiplication is a natural transformation.
- Isomorphisms: ten pairs of mutually inverse terms — the units and , ; and ; and ; and ; and ; and ; and ; and ; and .
- The unit type is terminal: any two terms are equivalent.
- The co-diagonal: , and .
- Mac Lane's pentagon for .
- Mac Lane's triangle for and the unit.
- The notation based on agrees with the notation based on : for the empty list, for singleton lists, and for concatenation.
- is a monoid under with unit .
- is a monoid homomorphism.
- is a monad with unit and multiplication .
- and are expressed by .
- Concatenating a list of empty lists gives the empty list.
- does not change the content of a list: it commutes with the concatenation maps into .
- The window axiom: the bundle term , which splits a list into consecutive pairs followed by a remainder of at most one element, is undone by the concatenation map: . Here .
The bundle term (Definition H.5) is, for a type and a value , the composition
where is the cyclic group of order two on , with identity . The window axiom uses it for and .
1 import Lax149335.DerivedTerms 2 … module docstring, 60 lines 63 64 namespace Lax149335.EquationalTheory 65 66 open Lax149335.Types Lax149335.Terms Lax149335.DerivedTerms 67 68 namespace Term 69 70 open Lax149335.Terms.Term Lax149335.DerivedTerms.Term 71 72 /-- The cyclic group `ℤ₂` of order two, with the two letter alphabet `2 = 1 + 1` as its 73 underlying set: the group identity is the first letter `Left`, and the second letter `Right` 74 is the generator. -/ 75 def cyclicTwo : Group ⟦Ty.finAlph 1⟧ where 76 mul x y := match x, y with 77 | .inl _, y => y 78 | x, .inl _ => x 79 | .inr _, .inr _ => .inl () 80 one := .inl () 81 inv x := x 82 mul_assoc := by intro x y z; cases x <;> cases y <;> cases z <;> rfl 83 one_mul := by intro x; cases x <;> rfl 84 mul_one := by intro x; cases x <;> rfl 85 inv_mul_cancel := by intro x; cases x <;> rfl 86 87 /-- The generator `Right` of the cyclic group of order two. -/ 88 def cyclicTwoGen : ⟦Ty.finAlph 1⟧ := Sum.inr () 89 90 /-- **Step 3 of the bundle term**, for a single element: `distR ; either (fst ; Right) 91 (fst ; Left) : A × 2 → A + A`. An element annotated with the generator `Right` goes to the 92 left copy of `A`, and an element annotated with the identity `Left` goes to the right 93 copy. -/ 94 def bundleTag (A : Ty) : Term (A ⊗ Ty.finAlph 1) (A ⊕' A) := 95 distR A Ty.unit (Ty.finAlph 0) ⨟ either (fst A Ty.unit ⨟ inr A A) (fst A Ty.unit ⨟ inl A A) 96 97 /-- **Definition H.5 (the bundle term)** `A* → (A × A)* × (1 + A)`, for a type `A` and a value 98 `w : 1 → A`: 99 100 `((id,1) ; (id × Right))* ; pref_{ℤ₂} ; (distR ; either (fst ; Right) (fst ; Left))* ; 101 block ; shiftL ; ((head_w × id)* × (uncons ; (id + fst)))`. 102 103 The window axiom (Axiom 16) says that, for `A = 2*` and `w = []`, it is a one-sided inverse 104 of the concatenation map `(A × A)* × (1 + A) ↣ A*`. -/ 105 def bundle (A : Ty) (w : Value A) : Term A⋆ ((A ⊗ A)⋆ ⊗ (Ty.unit ⊕' A)) := 106 listF (unitR A ⨟ prodF (Term.id A) (inr Ty.unit (Ty.finAlph 0))) ⨟ 107 pref A cyclicTwo ⨟ 108 listF (bundleTag A) ⨟ 109 block A A ⨟ 110 shiftL A⋆ A ⨟ 111 prodF (listF (prodF (headT w) (Term.id A))) (uncons A ⨟ sumF (Term.id Ty.unit) (fst A A⋆)) 112 113 /-- The type constructor `A ↦ (A × A)* × (1 + A)` of the window axiom. -/ 114 def TyF.window : TyF := .prod (.list (.prod .param .param)) (.sum .unit .param) 115 116 end Term 117 118 open Lax149335.Terms.Term Lax149335.DerivedTerms.Term 119 120 /-- Provable equality of rational terms: the least equivalence relation containing 121 Axioms 1-16 of Section 4 and stable under the combinators of the system. -/ 122 inductive PEq : {A B : Ty} → Term A B → Term A B → Prop 123 -- rules of equational reasoning: `≡` is an equivalence relation, stable under the 124 -- four combinators of the system 125 | refl {A B : Ty} (f : Term A B) : PEq f f 126 | symm {A B : Ty} {f g : Term A B} : PEq f g → PEq g f 127 | trans {A B : Ty} {f g h : Term A B} : PEq f g → PEq g h → PEq f h 128 | congr_comp {A B C : Ty} {f f' : Term A B} {g g' : Term B C} : 129 PEq f f' → PEq g g' → PEq (f ⨟ g) (f' ⨟ g') 130 | congr_prodF {A₁ A₂ B₁ B₂ : Ty} {f f' : Term A₁ B₁} {g g' : Term A₂ B₂} : 131 PEq f f' → PEq g g' → PEq (prodF f g) (prodF f' g') 132 | congr_sumF {A₁ A₂ B₁ B₂ : Ty} {f f' : Term A₁ B₁} {g g' : Term A₂ B₂} : 133 PEq f f' → PEq g g' → PEq (sumF f g) (sumF f' g') 134 | congr_listF {A B : Ty} {f f' : Term A B} : PEq f f' → PEq (listF f) (listF f') 135 -- ## Axiom 1 (category axioms) 136 | comp_assoc {A B C D : Ty} (f : Term A B) (g : Term B C) (h : Term C D) : 137 PEq ((f ⨟ g) ⨟ h) (f ⨟ (g ⨟ h)) 138 | id_comp {A B : Ty} (f : Term A B) : PEq (Term.id A ⨟ f) f 139 | comp_id {A B : Ty} (f : Term A B) : PEq (f ⨟ Term.id B) f 140 -- ## Axiom 2 (functoriality), first part: the functors preserve the identity 141 | prod_id (A B : Ty) : PEq (prodF (Term.id A) (Term.id B)) (Term.id (A ⊗ B)) 142 | sum_id (A B : Ty) : PEq (sumF (Term.id A) (Term.id B)) (Term.id (A ⊕' B)) 143 | list_id (A : Ty) : PEq (listF (Term.id A)) (Term.id A⋆) 144 -- ## Axiom 2 (functoriality), second part: the functors preserve composition 145 | prod_comp {A₁ A₂ B₁ B₂ C₁ C₂ : Ty} (f₁ : Term A₁ B₁) (f₂ : Term A₂ B₂) 146 (g₁ : Term B₁ C₁) (g₂ : Term B₂ C₂) : 147 PEq (prodF f₁ f₂ ⨟ prodF g₁ g₂) (prodF (f₁ ⨟ g₁) (f₂ ⨟ g₂)) 148 | sum_comp {A₁ A₂ B₁ B₂ C₁ C₂ : Ty} (f₁ : Term A₁ B₁) (f₂ : Term A₂ B₂) 149 (g₁ : Term B₁ C₁) (g₂ : Term B₂ C₂) : 150 PEq (sumF f₁ f₂ ⨟ sumF g₁ g₂) (sumF (f₁ ⨟ g₁) (f₂ ⨟ g₂)) 151 | list_comp {A B C : Ty} (f : Term A B) (g : Term B C) : 152 PEq (listF f ⨟ listF g) (listF (f ⨟ g)) 153 -- ## Axiom 3 (each atomic function is a natural transformation) 154 | nat_inl {A A' B B' : Ty} (f : Term A A') (g : Term B B') : 155 PEq (inl A B ⨟ sumF f g) (f ⨟ inl A' B') 156 | nat_inr {A A' B B' : Ty} (f : Term A A') (g : Term B B') : 157 PEq (inr A B ⨟ sumF f g) (g ⨟ inr A' B') 158 | nat_codiag {A A' : Ty} (f : Term A A') : 159 PEq (sumF f f ⨟ codiag A') (codiag A ⨟ f) 160 | nat_fst {A A' B B' : Ty} (f : Term A A') (g : Term B B') : 161 PEq (prodF f g ⨟ fst A' B') (fst A B ⨟ f) 162 | nat_snd {A A' B B' : Ty} (f : Term A A') (g : Term B B') : 163 PEq (prodF f g ⨟ snd A' B') (snd A B ⨟ g) 164 | nat_unitR {A A' : Ty} (f : Term A A') : 165 PEq (f ⨟ unitR A') (unitR A ⨟ prodF f (Term.id Ty.unit)) 166 | nat_unitL {A A' : Ty} (f : Term A A') : 167 PEq (f ⨟ unitL A') (unitL A ⨟ prodF (Term.id Ty.unit) f) 168 | nat_assocL {A A' B B' C C' : Ty} (f₁ : Term A A') (f₂ : Term B B') (f₃ : Term C C') : 169 PEq (prodF f₁ (prodF f₂ f₃) ⨟ assocL A' B' C') (assocL A B C ⨟ prodF (prodF f₁ f₂) f₃) 170 | nat_assocR {A A' B B' C C' : Ty} (f₁ : Term A A') (f₂ : Term B B') (f₃ : Term C C') : 171 PEq (prodF (prodF f₁ f₂) f₃ ⨟ assocR A' B' C') (assocR A B C ⨟ prodF f₁ (prodF f₂ f₃)) 172 | nat_distR {A A' B B' C C' : Ty} (f : Term A A') (g : Term B B') (h : Term C C') : 173 PEq (prodF f (sumF g h) ⨟ distR A' B' C') (distR A B C ⨟ sumF (prodF f g) (prodF f h)) 174 | nat_distL {A A' B B' C C' : Ty} (f : Term A A') (g : Term B B') (h : Term C C') : 175 PEq (prodF (sumF f g) h ⨟ distL A' B' C') (distL A B C ⨟ sumF (prodF f h) (prodF g h)) 176 | nat_cons {A B : Ty} (f : Term A B) : 177 PEq (sumF (Term.id Ty.unit) (prodF f (listF f)) ⨟ cons B) (cons A ⨟ listF f) 178 | nat_uncons {A B : Ty} (f : Term A B) : 179 PEq (listF f ⨟ uncons B) (uncons A ⨟ sumF (Term.id Ty.unit) (prodF f (listF f))) 180 | nat_snoc {A B : Ty} (f : Term A B) : 181 PEq (sumF (Term.id Ty.unit) (prodF (listF f) f) ⨟ snoc B) (snoc A ⨟ listF f) 182 | nat_unsnoc {A B : Ty} (f : Term A B) : 183 PEq (listF f ⨟ unsnoc B) (unsnoc A ⨟ sumF (Term.id Ty.unit) (prodF (listF f) f)) 184 | nat_concat {A B : Ty} (f : Term A B) : 185 PEq (listF (listF f) ⨟ concat B) (concat A ⨟ listF f) 186 | nat_block {A A' B B' : Ty} (f : Term A A') (g : Term B B') : 187 PEq (listF (sumF f g) ⨟ block A' B') 188 (block A B ⨟ prodF (listF f) (listF (prodF g (listF f)))) 189 | nat_shiftR {A A' B B' : Ty} (f : Term A A') (g : Term B B') : 190 PEq (prodF (listF (prodF f g)) f ⨟ shiftR A' B') 191 (shiftR A B ⨟ prodF f (listF (prodF g f))) 192 | nat_shiftL {A A' B B' : Ty} (f : Term A A') (g : Term B B') : 193 PEq (prodF f (listF (prodF g f)) ⨟ shiftL A' B') 194 (shiftL A B ⨟ prodF (listF (prodF f g)) f) 195 -- (Naturality of the group prefix multiplication need not be postulated: it is derivable, 196 -- see footnote 5 of the paper.) 197 -- ## Axiom 4 (ten pairs of mutually inverse functions) 198 | unitR_fst (A : Ty) : PEq (unitR A ⨟ fst A Ty.unit) (Term.id A) 199 | fst_unitR (A : Ty) : PEq (fst A Ty.unit ⨟ unitR A) (Term.id (A ⊗ Ty.unit)) 200 | unitL_snd (A : Ty) : PEq (unitL A ⨟ snd Ty.unit A) (Term.id A) 201 | snd_unitL (A : Ty) : PEq (snd Ty.unit A ⨟ unitL A) (Term.id (Ty.unit ⊗ A)) 202 | assocL_assocR (A B C : Ty) : 203 PEq (assocL A B C ⨟ assocR A B C) (Term.id (A ⊗ (B ⊗ C))) 204 | assocR_assocL (A B C : Ty) : 205 PEq (assocR A B C ⨟ assocL A B C) (Term.id ((A ⊗ B) ⊗ C)) 206 | distL_undistL (A B C : Ty) : 207 PEq (distL A B C ⨟ undistL A B C) (Term.id ((A ⊕' B) ⊗ C)) 208 | undistL_distL (A B C : Ty) : 209 PEq (undistL A B C ⨟ distL A B C) (Term.id ((A ⊗ C) ⊕' (B ⊗ C))) 210 | distR_undistR (A B C : Ty) : 211 PEq (distR A B C ⨟ undistR A B C) (Term.id (A ⊗ (B ⊕' C))) 212 | undistR_distR (A B C : Ty) : 213 PEq (undistR A B C ⨟ distR A B C) (Term.id ((A ⊗ B) ⊕' (A ⊗ C))) 214 | cons_uncons (A : Ty) : PEq (cons A ⨟ uncons A) (Term.id (Ty.unit ⊕' (A ⊗ A⋆))) 215 | uncons_cons (A : Ty) : PEq (uncons A ⨟ cons A) (Term.id A⋆) 216 | snoc_unsnoc (A : Ty) : PEq (snoc A ⨟ unsnoc A) (Term.id (Ty.unit ⊕' (A⋆ ⊗ A))) 217 | unsnoc_snoc (A : Ty) : PEq (unsnoc A ⨟ snoc A) (Term.id A⋆) 218 | block_unblock (A B : Ty) : PEq (block A B ⨟ unblock A B) (Term.id (A ⊕' B)⋆) 219 | unblock_block (A B : Ty) : PEq (unblock A B ⨟ block A B) (Term.id (A⋆ ⊗ (B ⊗ A⋆)⋆)) 220 | pref_unpref (A : Ty) {n : ℕ} (G : Group ⟦Ty.finAlph n⟧) : 221 PEq (pref A G ⨟ unpref A G) (Term.id ((A ⊗ Ty.finAlph n)⋆)) 222 | unpref_pref (A : Ty) {n : ℕ} (G : Group ⟦Ty.finAlph n⟧) : 223 PEq (unpref A G ⨟ pref A G) (Term.id ((A ⊗ Ty.finAlph n)⋆)) 224 | shiftL_shiftR (A B : Ty) : PEq (shiftL A B ⨟ shiftR A B) (Term.id (A ⊗ (B ⊗ A)⋆)) 225 | shiftR_shiftL (A B : Ty) : PEq (shiftR A B ⨟ shiftL A B) (Term.id ((A ⊗ B)⋆ ⊗ A)) 226 -- ## Axiom 5 (the unit type is terminal) 227 | unit_unique {A : Ty} (f g : Term A Ty.unit) : PEq f g 228 -- ## Axiom 6 (the co-diagonal) 229 | inl_codiag (A : Ty) : PEq (inl A A ⨟ codiag A) (Term.id A) 230 | inr_codiag (A : Ty) : PEq (inr A A ⨟ codiag A) (Term.id A) 231 | sum_inl_inr_codiag (A B : Ty) : 232 PEq (sumF (inl A B) (inr A B) ⨟ codiag (A ⊕' B)) (Term.id (A ⊕' B)) 233 -- ## Axiom 7 (Mac Lane's pentagon) 234 | pentagon (A B C D : Ty) : 235 PEq (prodF (Term.id A) (assocL B C D) ⨟ assocL A (B ⊗ C) D ⨟ 236 prodF (assocL A B C) (Term.id D)) 237 (assocL A B (C ⊗ D) ⨟ assocL (A ⊗ B) C D) 238 -- ## Axiom 8 (Mac Lane's triangle) 239 | triangle (A C : Ty) : 240 PEq (assocL A Ty.unit C ⨟ prodF (fst A Ty.unit) (Term.id C)) 241 (prodF (Term.id A) (snd Ty.unit C)) 242 -- ## Axiom 9 (`snoc`-based notation agrees with `cons`-based notation) 243 | inl_snoc_cons (A : Ty) : 244 PEq (inl Ty.unit (A⋆ ⊗ A) ⨟ snoc A) (inl Ty.unit (A ⊗ A⋆) ⨟ cons A) 245 | append_nil_prepend_nil (A : Ty) : 246 PEq (unitL A ⨟ prodF (nilT A) (Term.id A) ⨟ append A) 247 (unitR A ⨟ prodF (Term.id A) (nilT A) ⨟ prepend A) 248 | append_concat_prepend_concat (A : Ty) : 249 PEq (prodF (pureT A⋆) (Term.id A⋆) ⨟ append A⋆ ⨟ concat A) 250 (prodF (Term.id A⋆) (pureT A⋆) ⨟ prepend A⋆ ⨟ concat A) 251 -- ## Axiom 10 (`A*` is a monoid) 252 | binconcat_assoc (A : Ty) : 253 PEq (prodF (binconcat A) (Term.id A⋆) ⨟ binconcat A) 254 (assocR A⋆ A⋆ A⋆ ⨟ prodF (Term.id A⋆) (binconcat A) ⨟ binconcat A) 255 | binconcat_unitR (A : Ty) : 256 PEq (unitR A⋆ ⨟ prodF (Term.id A⋆) (nilT A) ⨟ binconcat A) (Term.id A⋆) 257 | binconcat_unitL (A : Ty) : 258 PEq (unitL A⋆ ⨟ prodF (nilT A) (Term.id A⋆) ⨟ binconcat A) (Term.id A⋆) 259 -- ## Axiom 11 (`concat` is a monoid homomorphism) 260 | nil_concat (A : Ty) : PEq (nilT A⋆ ⨟ concat A) (nilT A) 261 | binconcat_concat (A : Ty) : 262 PEq (binconcat A⋆ ⨟ concat A) (prodF (concat A) (concat A) ⨟ binconcat A) 263 -- ## Axiom 12 (`A*` is a monad) 264 | concat_concat (A : Ty) : PEq (listF (concat A) ⨟ concat A) (concat A⋆ ⨟ concat A) 265 | pure_concat (A : Ty) : PEq (pureT A⋆ ⨟ concat A) (Term.id A⋆) 266 | listF_pure_concat (A : Ty) : PEq (listF (pureT A) ⨟ concat A) (Term.id A⋆) 267 -- ## Axiom 13 (the inductive structure in terms of the monoid structure) 268 | prepend_def (A : Ty) : 269 PEq (prepend A) (prodF (pureT A) (Term.id A⋆) ⨟ binconcat A) 270 | append_def (A : Ty) : 271 PEq (append A) (prodF (Term.id A⋆) (pureT A) ⨟ binconcat A) 272 -- ## Axiom 14 (concatenating a list of empty lists) 273 | nil_map_concat (A : Ty) : 274 PEq (listF (nilT A) ⨟ concat A) (toUnit Ty.unit⋆ ⨟ nilT A) 275 -- ## Axiom 15 (`shiftR` does not change the content of the list) 276 | shiftR_content (A B : Ty) : 277 PEq (shiftR A B ⨟ TyF2.concatMap (.prod .p1 (.list (.prod .p2 .p1))) A B) 278 (TyF2.concatMap (.prod (.list (.prod .p1 .p2)) .p1) A B) 279 -- ## Axiom 16 (the window axiom: the bundle term undoes the concatenation map of bundles 280 -- of size two over binary strings) 281 -- 282 -- The bundle term `bundle_{2*} : (2*)* → (2* × 2*)* × (1 + 2*)` of Definition H.5, 283 -- formalised as `Term.bundle` with the value `w = []`, splits a list into bundles 284 -- of two consecutive entries followed by a remainder of at most one entry. The axiom says 285 -- that this splitting is undone by the concatenation map 286 -- 287 -- `(2* × 2*)* × (1 + 2*) ↣ (2*)*`, 288 -- 289 -- i.e. that `bundle ; concat ≡ id`. 290 | window : 291 PEq (Term.bundle ((Ty.finAlph 1)⋆) (nilT (Ty.finAlph 1)) ⨟ 292 TyF.concatMap Term.TyF.window ((Ty.finAlph 1)⋆)) 293 (Term.id (((Ty.finAlph 1)⋆)⋆)) 294 295 /-- Notation `f ≡ₜ g` for provable equivalence of rational terms. -/ 296 infix:50 " ≡ₜ " => PEq 297 298 end Lax149335.EquationalTheory 299
Loading the paper…