Types and their string representation

Lax709149.Types · 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.

    Natural Language Statement

    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 A∗A^*. 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 L aL\,a or R bR\,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).

    Concept map
    1 concept; 3 descendants hidden
    100%
    Proven claimDefinitionThis conceptRelated conceptA → B: B builds on A

    In the paper

    Lean source view on GitHub

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

    Discussion

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

    Loading discussion…