Rational functions
Lax149335.RationalFunctions · concepts/Lax149335/RationalFunctions.lean · lax-149335
No public endorsements yet.
Loading review…
Sign in with ORCIDNatural Language Statement
Definition
A rational relation between strings over alphabets and is a subset of the monoid defined by a regular expression: the atoms are pairs of strings, and the operations are union, concatenation (componentwise) and Kleene star.
Definition 2.1 (Rational function). A function is rational if its graph is a rational relation.
Definition 2.3 (Rational functions on types). A function between types is rational if there is a rational function that agrees with on the string representations of elements, i.e. the string representation of is applied to the string representation of .
Concept map
Lean source view on GitHub
| 1 | import Lax149335.Types |
| 2 | import Mathlib.Data.Set.Defs |
| 3 | |
| 4 | /-! |
| 5 | --- |
| 6 | title: Rational functions |
| 7 | type: definition |
| 8 | --- |
| 9 | A *rational relation* between strings over alphabets and |
| 10 | is a subset of the monoid defined by a regular expression: the atoms |
| 11 | are pairs of strings, and the operations are union, concatenation (componentwise) and Kleene |
| 12 | star. |
| 13 | |
| 14 | **Definition 2.1 (Rational function).** A function is *rational* if its |
| 15 | graph is a rational relation. |
| 16 | |
| 17 | **Definition 2.3 (Rational functions on types).** A function between types is |
| 18 | *rational* if there is a rational function that agrees |
| 19 | with on the string representations of elements, i.e. the string representation of |
| 20 | is applied to the string representation of . |
| 21 | -/ |
| 22 | |
| 23 | namespace Lax149335.RationalFunctions |
| 24 | |
| 25 | open Lax149335.Types |
| 26 | |
| 27 | variable {α β : Type} |
| 28 | |
| 29 | /-- Regular expressions over the product monoid `α* × β*`. -/ |
| 30 | inductive RatExp (α β : Type) : Type |
| 31 | | zero : RatExp α β |
| 32 | | atom : List α → List β → RatExp α β |
| 33 | | plus : RatExp α β → RatExp α β → RatExp α β |
| 34 | | cat : RatExp α β → RatExp α β → RatExp α β |
| 35 | | star : RatExp α β → RatExp α β |
| 36 | |
| 37 | /-- The submonoid of `α* × β*` generated by a set `S`: all finite products of elements of |
| 38 | `S`. -/ |
| 39 | inductive StarSet (S : Set (List α × List β)) : List α × List β → Prop |
| 40 | | nil : StarSet S ([], []) |
| 41 | | cons {x y : List α × List β} : x ∈ S → StarSet S y → StarSet S (x.1 ++ y.1, x.2 ++ y.2) |
| 42 | |
| 43 | /-- The relation defined by a regular expression. -/ |
| 44 | def RatExp.lang : RatExp α β → Set (List α × List β) |
| 45 | | .zero => ∅ |
| 46 | | .atom u v => {(u, v)} |
| 47 | | .plus e f => e.lang ∪ f.lang |
| 48 | | .cat e f => {p | ∃ x ∈ e.lang, ∃ y ∈ f.lang, p = (x.1 ++ y.1, x.2 ++ y.2)} |
| 49 | | .star e => {p | StarSet e.lang p} |
| 50 | |
| 51 | /-- A relation between strings is rational if it is defined by a regular expression. -/ |
| 52 | def IsRationalRel (R : Set (List α × List β)) : Prop := ∃ e : RatExp α β, e.lang = R |
| 53 | |
| 54 | /-- **Definition 2.1.** A function `f : α* → β*` is rational if its graph is a rational |
| 55 | relation. -/ |
| 56 | def IsRationalFun (f : List α → List β) : Prop := |
| 57 | IsRationalRel {p : List α × List β | p.2 = f p.1} |
| 58 | |
| 59 | /-- **Definition 2.3.** A function between types is rational if, on string representations, |
| 60 | it is computed by a rational function `𝟖* → 𝟖*`. -/ |
| 61 | def IsRationalTypeFun {A B : Ty} (f : ⟦A⟧ → ⟦B⟧) : Prop := |
| 62 | ∃ f' : List Ty.Sym → List Ty.Sym, |
| 63 | IsRationalFun f' ∧ ∀ a : ⟦A⟧, Ty.repr B (f a) = f' (Ty.repr A a) |
| 64 | |
| 65 | end Lax149335.RationalFunctions |
| 66 |
Discussion
Ask a question or add context. Endorsements and structured flags are kept in the review panel above.
0 comments