While this submission is a draft, it cannot be used by other submissions.

Rational terms

Lax149335.Terms · concepts/Lax149335/Terms.lean · lax-149335

definition

Loading review…

Sign in with ORCID

Community review

Flags

Each flag is tied to a public ORCID identity and explains why this concept may be incorrect.

No flags have been submitted.

    Community review

    Flag this concept

    State precisely what appears incorrect. This explanation will be public under your ORCID name.

    No source line selected.

    Natural Language Statement

    Definition

    Definition 3.1 (Rational terms). A rational term f:A→Bf : A \to B between types is an expression built from the following atomic functions (Figure 1) using composition f;gf \mathbin{;} g and the functoriality combinators f×gf \times g, f+gf + g and f∗f^* of products, co-products and lists:

    1. the identity A→AA \to A;
    2. the co-projections Left:A→A+B\mathsf{Left} : A \to A + B and Right:B→A+B\mathsf{Right} : B \to A + B;
    3. the co-diagonal A+A→AA + A \to A;
    4. the projections fst:A×B→A\mathsf{fst} : A \times B \to A and snd:A×B→B\mathsf{snd} : A \times B \to B;
    5. the units A→A×1A \to A \times 1 and A→1×AA \to 1 \times A, and associativity of products in both directions;
    6. distributivity A×(B+C)→A×B+A×CA \times (B + C) \to A \times B + A \times C and (A+B)×C→A×C+B×C(A + B) \times C \to A \times C + B \times C;
    7. the list constructors and destructors cons:1+A×A∗→A∗\mathsf{cons} : 1 + A \times A^* \to A^*, uncons\mathsf{uncons}, snoc:1+A∗×A→A∗\mathsf{snoc} : 1 + A^* \times A \to A^* and unsnoc\mathsf{unsnoc};
    8. list concatenation concat:A∗∗→A∗\mathsf{concat} : A^{**} \to A^*;
    9. split:(A+B)∗→A∗×(B×A∗)∗\mathsf{split} : (A + B)^* \to A^* \times (B \times A^*)^*, which cuts a list before every element of BB;
    10. bracket shifting shiftR:(A×B)∗×A→A×(B×A)∗\mathsf{shiftR} : (A \times B)^* \times A \to A \times (B \times A)^* and its inverse shiftL\mathsf{shiftL};
    11. prefix multiplication pref:(A×G)∗→(A×G)∗\mathsf{pref} : (A \times G)^* \to (A \times G)^* for a finite group GG, which replaces the ii-th group element by the product of the first ii ones.

    The denotation [ ⁣[f] ⁣][\![ f ]\!] of a rational term is the function it defines. A rational term is aperiodic if it does not use prefix multiplication.

    Concept map
    2 concepts
    100%
    DefinitionThis conceptRelated conceptA → B: B builds on ADescendants are omitted for concepts with more than 10 descendants.

    Lean source view on GitHub

    1import Lax149335.Types
    2import Mathlib.Algebra.Group.Defs
    3
    4/-!
    5---
    6title: Rational terms
    7type: definition
    8---
    9**Definition 3.1 (Rational terms).** A *rational term* f:A→Bf : A \to B between types is an
    10expression built from the following atomic functions (Figure 1) using composition
    11f;gf \mathbin{;} g and the functoriality combinators f×gf \times g, f+gf + g and f∗f^* of
    12products, co-products and lists:
    13
    141. the identity A→AA \to A;
    152. the co-projections Left:A→A+B\mathsf{Left} : A \to A + B and Right:B→A+B\mathsf{Right} : B \to A + B;
    163. the co-diagonal A+A→AA + A \to A;
    174. the projections fst:A×B→A\mathsf{fst} : A \times B \to A and snd:A×B→B\mathsf{snd} : A \times B \to B;
    185. the units A→A×1A \to A \times 1 and A→1×AA \to 1 \times A, and associativity of products in
    19 both directions;
    206. distributivity A×(B+C)→A×B+A×CA \times (B + C) \to A \times B + A \times C and
    21 (A+B)×C→A×C+B×C(A + B) \times C \to A \times C + B \times C;
    227. the list constructors and destructors cons:1+A×A∗→A∗\mathsf{cons} : 1 + A \times A^* \to A^*,
    23 uncons\mathsf{uncons}, snoc:1+A∗×A→A∗\mathsf{snoc} : 1 + A^* \times A \to A^* and unsnoc\mathsf{unsnoc};
    248. list concatenation concat:A∗∗→A∗\mathsf{concat} : A^{**} \to A^*;
    259. split:(A+B)∗→A∗×(B×A∗)∗\mathsf{split} : (A + B)^* \to A^* \times (B \times A^*)^*, which cuts a list before
    26 every element of BB;
    2710. bracket shifting shiftR:(A×B)∗×A→A×(B×A)∗\mathsf{shiftR} : (A \times B)^* \times A \to A \times (B \times A)^*
    28 and its inverse shiftL\mathsf{shiftL};
    2911. prefix multiplication pref:(A×G)∗→(A×G)∗\mathsf{pref} : (A \times G)^* \to (A \times G)^* for a finite
    30 group GG, which replaces the ii-th group element by the product of the first ii ones.
    31
    32The *denotation* [ ⁣[f] ⁣][\![ f ]\!] of a rational term is the function it defines. A rational
    33term is *aperiodic* if it does not use prefix multiplication.
    34
    35# Formalization notes
    36
    37A finite group is given by a group structure on a finite alphabet n+1‾\overline{n+1}, which is
    38no loss of generality since every finite group is isomorphic to one of these.
    39-/
    40
    41namespace Lax149335.Terms
    42
    43open Lax149335.Types
    44
    45/-- Auxiliary function used for the denotation of the group prefix multiplication: the `i`-th
    46group element of the output is the product of the first `i` group elements of the input. -/
    47def 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
    52maximal prefix of elements of `A`, followed by a list of blocks, each consisting of one
    53element of `B` and the following maximal run of elements of `A`. -/
    54def 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`. -/
    60def snocDen {α : Type} : Unit ⊕ (List α × α) → List α
    61 | .inl _ => []
    62 | .inr (l, a) => l ++ [a]
    63
    64/-- Auxiliary function used for the denotation of `unsnoc`. -/
    65def 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`. -/
    71def 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`. -/
    76def 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
    81Figure 1 by composition and the functoriality combinators of products, co-products and
    82lists. -/
    83inductive 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
    137namespace Term
    138
    139/-- Notation `f ⨟ g` for the composition of rational terms: first `f`, then `g`. -/
    140infixl:60 " ⨟ " => Term.comp
    141
    142/-- The denotation `⟦f⟧` of a rational term: the function that it defines. -/
    143def 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
    180groups. -/
    181def 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
    189end Term
    190
    191/-- A rational term is aperiodic if it does not use the group prefix multiplication `pref`. -/
    192def IsAperiodic {A B : Ty} (f : Term A B) : Prop := Term.usesPref f = false
    193
    194end Lax149335.Terms
    195
    Formalization notes

    A finite group is given by a group structure on a finite alphabet n+1‾\overline{n+1}, which is no loss of generality since every finite group is isomorphic to one of these.

    Discussion

    Ask a question or add context. Endorsements and structured flags are kept in the review panel above.

    Loading discussion…