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

Simple rational terms

Lax149335.SimpleRationalTerms · concepts/Lax149335/SimpleRationalTerms.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 2.5 (Simple rational terms). Let BB be a finite alphabet. The simple rational terms with outputs in B∗B^* are the terms generated from the term []:1→B∗[] : 1 \to B^*, which produces the empty string, by the following combinators:

    • co-pairing: for f1:A1→B∗f_1 : A_1 \to B^* and f2:A2→B∗f_2 : A_2 \to B^*, the term ⟨f1,f2⟩:A1+A2→B∗\langle f_1, f_2 \rangle : A_1 + A_2 \to B^* that applies f1f_1 or f2f_2 depending on the summand;
    • concatenation: for f1:A1→B∗f_1 : A_1 \to B^* and f2:A2→B∗f_2 : A_2 \to B^*, the term f1⊙f2:A1×A2→B∗f_1 \odot f_2 : A_1 \times A_2 \to B^* that maps (a1,a2)(a_1, a_2) to f1(a1) f2(a2)f_1(a_1)\,f_2(a_2);
    • homomorphism: for f:A→B∗f : A \to B^*, the term hom f:A∗→B∗\mathrm{hom}\, f : A^* \to B^* that maps [a1,…,an][a_1, \ldots, a_n] to f(a1)⋯f(an)f(a_1) \cdots f(a_n);
    • constants: for f:A→B∗f : A \to B^* and a string w∈B∗w \in B^*, the terms w⋅fw \cdot f and f⋅wf \cdot w, which prepend or append ww to the output.

    A function is represented by a simple rational term if it is the function that the term defines.

    Concept map
    2 concepts; 4 descendants hidden
    100%
    Proven claimDefinitionThis conceptRelated conceptA → B: B builds on A

    Lean source view on GitHub

    1import Lax149335.Types
    2
    3/-!
    4---
    5title: Simple rational terms
    6type: definition
    7---
    8**Definition 2.5 (Simple rational terms).** Let BB be a finite alphabet. The *simple
    9rational terms* with outputs in B∗B^* are the terms generated from the term
    10[]:1→B∗[] : 1 \to B^*, which produces the empty string, by the following combinators:
    11
    12- *co-pairing*: for f1:A1→B∗f_1 : A_1 \to B^* and f2:A2→B∗f_2 : A_2 \to B^*, the term
    13 ⟨f1,f2⟩:A1+A2→B∗\langle f_1, f_2 \rangle : A_1 + A_2 \to B^* that applies f1f_1 or f2f_2 depending on
    14 the summand;
    15- *concatenation*: for f1:A1→B∗f_1 : A_1 \to B^* and f2:A2→B∗f_2 : A_2 \to B^*, the term
    16 f1⊙f2:A1×A2→B∗f_1 \odot f_2 : A_1 \times A_2 \to B^* that maps (a1,a2)(a_1, a_2) to f1(a1) f2(a2)f_1(a_1)\,f_2(a_2);
    17- *homomorphism*: for f:A→B∗f : A \to B^*, the term hom f:A∗→B∗\mathrm{hom}\, f : A^* \to B^* that maps
    18 [a1,…,an][a_1, \ldots, a_n] to f(a1)⋯f(an)f(a_1) \cdots f(a_n);
    19- *constants*: for f:A→B∗f : A \to B^* and a string w∈B∗w \in B^*, the terms w⋅fw \cdot f and
    20 f⋅wf \cdot w, which prepend or append ww to the output.
    21
    22A function is *represented* by a simple rational term if it is the function that the term
    23defines.
    24
    25# Formalization notes
    26
    27The output alphabet is an arbitrary Lean type `Bs`; the statements that need it to be
    28finite say so.
    29-/
    30
    31namespace Lax149335.SimpleRationalTerms
    32
    33open Lax149335.Types
    34
    35/-- Simple rational terms `A → Bs*`. -/
    36inductive 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
    50namespace SimpleTerm
    51
    52variable {Bs : Type}
    53
    54/-- The function defined by a simple rational term. -/
    55def 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
    65defines. -/
    66def IsSimpleFun {A : Ty} (f : ⟦A⟧ → List Bs) : Prop := ∃ t : SimpleTerm Bs A, t.den = f
    67
    68end SimpleTerm
    69
    70end Lax149335.SimpleRationalTerms
    71
    Formalization notes

    The output alphabet is an arbitrary Lean type BsBs; the statements that need it to be finite say so.

    Discussion

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

    Loading discussion…