Draft — mutable and not usable as a dependency; its citation marks the draft state.

Lax709149.Types

Types and their string representation

concepts/Lax709149/Types.lean · lax-709149

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.

    Concept map

    Proven claimDefinitionThis conceptRelated conceptA → B: B builds on A

    In the paper

    Definition

    The types of Section C.5 of Transducers (Definition C.5.1) are the expressions built from the unit type 1\mathbb{1}, which has the unique element 11, by the product A×BA \times B, the co-product A+BA + B and the list type AA^*. Every element of a type has a string representation over a fixed alphabet with eight letters

    ()[],1LR,( \quad ) \quad [ \quad ] \quad , \quad 1 \quad L \quad R,

    defined by induction on the type: the unique element of 1\mathbb{1} is 11, an element of A+BA + B is LaL\,a or RbR\,b, a pair is (a,b)(a, b), and a list is [a1,,an][a_1, \ldots, a_n]. Through this representation, type-to-type functions can be computed by string-to-string transducers (Definition C.5.2).

    Lean source view on GitHub

    1import Mathlib.Data.Fintype.Basic
    2import Mathlib.Tactic.DeriveFintype
    3
    4/-!
    5---
    6title: Types and their string representation
    7type: definition
    8---
    9The *types* of Section C.5 of *Transducers* (Definition C.5.1) are the
    10expressions built from the unit type 1\mathbb{1}, which has the unique element
    1111, by the product A×BA \times B, the co-product A+BA + B and the list type
    12AA^*. Every element of a type has a *string representation* over a fixed
    13alphabet with eight letters
    14()[],1LR,( \quad ) \quad [ \quad ] \quad , \quad 1 \quad L \quad R,
    15defined by induction on the type: the unique element of 1\mathbb{1} is 11, an
    16element of A+BA + B is LaL\,a or RbR\,b, a pair is (a,b)(a, b), and a list is
    17[a1,,an][a_1, \ldots, a_n]. Through this representation, type-to-type functions can
    18be computed by string-to-string transducers (Definition C.5.2).
    19
    20# Formalization notes
    21
    22`Ty.Elt` interprets a type as a Lean type — `Unit`, products, sums and lists —
    23and `Ty.repr` is the representation, a string over the eight-letter alphabet
    24`Sym8`, the same alphabet for all types. Lists are written with the separating
    25commas of the book and no trailing separator.
    26-/
    27
    28namespace Lax709149.Types
    29
    30/-- A type: built from the unit type by product, co-product and list. -/
    31inductive Ty : Type
    32 | one : Ty
    33 | prod : TyTyTy
    34 | sum : TyTyTy
    35 | list : TyTy
    36 deriving DecidableEq
    37
    38/-- The set of elements of a type. -/
    39def Ty.Elt : TyType
    40 | .one => Unit
    41 | .prod A B => A.Elt × B.Elt
    42 | .sum A B => A.Elt ⊕ B.Elt
    43 | .list A => List A.Elt
    44
    45/-- The alphabet with eight letters `(`, `)`, `[`, `]`, `,`, `1`, `L`, `R`. -/
    46inductive Sym8 : Type
    47 | lpar | rpar | lbrack | rbrack | comma | one | left | right
    48 deriving DecidableEq, Fintype
    49
    50/-- The entries of a list representation, separated by commas. -/
    51def joinSep : List (List Sym8) → List Sym8
    52 | [] => []
    53 | [x] => x
    54 | x :: xs => x ++ Sym8.comma :: joinSep xs
    55
    56/-- The string representation of an element: `1` for the unit, `L a` and `R b` for
    57the co-product, `(a,b)` for a pair, `[a₁,…,aₙ]` for a list. -/
    58def Ty.repr : (t : Ty) → t.Elt → List Sym8
    59 | .one, _ => [Sym8.one]
    60 | .prod A B, x => Sym8.lpar :: (A.repr x.1 ++ Sym8.comma :: (B.repr x.2 ++ [Sym8.rpar]))
    61 | .sum A B, x => Sum.elim (fun a => Sym8.left :: A.repr a) (fun b => Sym8.right :: B.repr b) x
    62 | .list A, l => Sym8.lbrack :: (joinSep (l.map A.repr) ++ [Sym8.rbrack])
    63
    64end Lax709149.Types
    65

    Formalization notes

    Ty.EltTy.Elt interprets a type as a Lean type — UnitUnit, products, sums and lists — and Ty.reprTy.repr is the representation, a string over the eight-letter alphabet Sym8Sym8, the same alphabet for all types. Lists are written with the separating commas of the book and no trailing separator.

    Community review

    Discussion

    Ask a question or add context. Endorsements and structured flags are kept in the review panel above; your ORCID profile must share a public name.

    0 comments

    Loading discussion…