Rational terms
Lax149335.Terms · concepts/Lax149335/Terms.lean · lax-149335
No public endorsements yet.
Loading review…
Sign in with ORCIDNatural Language Statement
Definition
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.
Concept map
Lean source view on GitHub
| 1 | import Lax149335.Types |
| 2 | import Mathlib.Algebra.Group.Defs |
| 3 | |
| 4 | /-! |
| 5 | --- |
| 6 | title: Rational terms |
| 7 | type: definition |
| 8 | --- |
| 9 | **Definition 3.1 (Rational terms).** A *rational term* between types is an |
| 10 | expression built from the following atomic functions (Figure 1) using composition |
| 11 | and the functoriality combinators , and of |
| 12 | products, co-products and lists: |
| 13 | |
| 14 | 1. the identity ; |
| 15 | 2. the co-projections and ; |
| 16 | 3. the co-diagonal ; |
| 17 | 4. the projections and ; |
| 18 | 5. the units and , and associativity of products in |
| 19 | both directions; |
| 20 | 6. distributivity and |
| 21 | ; |
| 22 | 7. the list constructors and destructors , |
| 23 | , and ; |
| 24 | 8. list concatenation ; |
| 25 | 9. , which cuts a list before |
| 26 | every element of ; |
| 27 | 10. bracket shifting |
| 28 | and its inverse ; |
| 29 | 11. prefix multiplication for a finite |
| 30 | group , which replaces the -th group element by the product of the first ones. |
| 31 | |
| 32 | The *denotation* of a rational term is the function it defines. A rational |
| 33 | term is *aperiodic* if it does not use prefix multiplication. |
| 34 | |
| 35 | # Formalization notes |
| 36 | |
| 37 | A finite group is given by a group structure on a finite alphabet , which is |
| 38 | no loss of generality since every finite group is isomorphic to one of these. |
| 39 | -/ |
| 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 `split`: 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 splitDen {α β : Type} : List (α ⊕ β) → List α × List (β × List α) |
| 55 | | [] => ([], []) |
| 56 | | .inl a :: t => let p := splitDen t; (a :: p.1, p.2) |
| 57 | | .inr b :: t => let p := splitDen 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: splitting a list over a co-product. -/ |
| 127 | | split (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 | | _, _, .split _ _, l => splitDen 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 |
Formalization notes
A finite group is given by a group structure on a finite alphabet , which is no loss of generality since every finite group is isomorphic to one of these.
Builds on
From Mathlib
Discussion
Ask a question or add context. Endorsements and structured flags are kept in the review panel above.
0 comments