Download data/lean/OAI/Combinatorics/Automata/Model.lean from introvoyz045/math: direct link, hf CLI and curl.
- Browser
- Download file 4.65 kB
-
https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Combinatorics/Automata/Model.lean
- Command line
-
hf download hf://datasets/introvoyz045/math/data/lean/OAI/Combinatorics/Automata/Model.lean
-
curl -L -o Model.lean https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Combinatorics/Automata/Model.lean
4.65 kB
| import Mathlib | |
| namespace OAI | |
| namespace OneWayLiveness | |
| @[ext] structure BRel (H : Type*) where | |
| holds : H β H β Prop | |
| namespace BRel | |
| variable {H : Type*} | |
| instance : One (BRel H) := β¨β¨Eqβ©β© | |
| instance : Mul (BRel H) := β¨fun a b => β¨fun x z => β y, a.holds x y β§ b.holds y zβ©β© | |
| instance : Zero (BRel H) := β¨β¨fun _ _ => Falseβ©β© | |
| @[simp] theorem one_holds (x y : H) : (1 : BRel H).holds x y β x = y := Iff.rfl | |
| @[simp] theorem mul_holds (a b : BRel H) (x z : H) : | |
| (a * b).holds x z β β y, a.holds x y β§ b.holds y z := Iff.rfl | |
| @[simp] theorem zero_holds (x y : H) : Β¬ (0 : BRel H).holds x y := id | |
| instance : Monoid (BRel H) where | |
| mul_assoc a b c := by | |
| ext x z | |
| change (β y, (β w, a.holds x w β§ b.holds w y) β§ c.holds y z) β | |
| β w, a.holds x w β§ β y, b.holds w y β§ c.holds y z | |
| aesop | |
| one_mul a := by ext x z; change (β y, x = y β§ a.holds y z) β a.holds x z; simp | |
| mul_one a := by ext x z; change (β y, a.holds x y β§ y = z) β a.holds x z; simp | |
| def restrictedId (F : Set H) : BRel H := β¨fun x y => x = y β§ x β Fβ© | |
| def live (w : List (BRel H)) : Prop := β x y, w.prod.holds x y | |
| instance [Finite H] : Finite (BRel H) := Finite.of_injective BRel.holds (fun _ _ h => BRel.ext h) | |
| end BRel | |
| abbrev Alphabet (h : β) := BRel (Fin h) | |
| def OWL (h : β) : Set (List (Alphabet h)) := {w | BRel.live w} | |
| inductive Symbol (Alpha : Type*) where | |
| | left : Symbol Alpha | |
| | letter : Alpha β Symbol Alpha | |
| | right : Symbol Alpha | |
| inductive Move where | |
| | left | stay | right | |
| deriving DecidableEq | |
| def Move.Rel : Move β β β β β Prop | |
| | .left, i, j => j + 1 = i | |
| | .stay, i, j => j = i | |
| | .right, i, j => j = i + 1 | |
| /-- The finite word including both endmarkers. -/ | |
| def scanned {Alpha : Type*} (w : List Alpha) (i : Fin (w.length + 2)) : Symbol Alpha := | |
| if h0 : i.val = 0 then .left | |
| else if hi : i.val < w.length + 1 then .letter (w[i.val - 1]'(by omega)) | |
| else .right | |
| abbrev Configuration {Alpha : Type*} (w : List Alpha) (n : β) := Fin (w.length + 2) Γ Fin n | |
| structure DMachine (Alpha : Type*) (s : β) where | |
| initial : Fin s | |
| accepting : Set (Fin s) | |
| transition : Fin s β Symbol Alpha β Option (Fin s Γ Move) | |
| left_boundary : β q q', transition q .left β some (q', .left) | |
| right_boundary : β q q', transition q .right β some (q', .right) | |
| structure NMachine (Alpha : Type*) (n : β) where | |
| initial : Fin n | |
| accepting : Set (Fin n) | |
| transition : Fin n β Symbol Alpha β Set (Fin n Γ Move) | |
| left_boundary : β q q', (q', .left) β transition q .left | |
| right_boundary : β q q', (q', .right) β transition q .right | |
| def DMachine.Step {Alpha : Type*} {s : β} (M : DMachine Alpha s) (w : List Alpha) | |
| (c c' : Configuration w s) : Prop := | |
| β d, M.transition c.2 (scanned w c.1) = some (c'.2, d) β§ d.Rel c.1.val c'.1.val | |
| def NMachine.Step {Alpha : Type*} {n : β} (M : NMachine Alpha n) (w : List Alpha) | |
| (c c' : Configuration w n) : Prop := | |
| β d, (c'.2, d) β M.transition c.2 (scanned w c.1) β§ d.Rel c.1.val c'.1.val | |
| /-- The positive convention explicitly excludes a length-zero computation. -/ | |
| def FiniteRun {C : Type*} (positive : Bool) (step : C β C β Prop) (c c' : C) : Prop := | |
| if positive then Relation.TransGen step c c' else Relation.ReflTransGen step c c' | |
| def DMachine.Accepts {Alpha : Type*} {s : β} (M : DMachine Alpha s) | |
| (positive : Bool) (w : List Alpha) : Prop := | |
| β c, FiniteRun positive (M.Step w) (β¨0, by omegaβ©, M.initial) c β§ c.2 β M.accepting | |
| def NMachine.Accepts {Alpha : Type*} {n : β} (M : NMachine Alpha n) | |
| (positive : Bool) (w : List Alpha) : Prop := | |
| β c, FiniteRun positive (M.Step w) (β¨0, by omegaβ©, M.initial) c β§ c.2 β M.accepting | |
| def NMachine.NoLeft {Alpha : Type*} {n : β} (M : NMachine Alpha n) : Prop := | |
| β q a q', (q', Move.left) β M.transition q a | |
| def NMachine.Recognizes {Alpha : Type*} {n : β} (M : NMachine Alpha n) | |
| (positive : Bool) (L : Set (List Alpha)) : Prop := β w, M.Accepts positive w β w β L | |
| def DMachine.Recognizes {Alpha : Type*} {s : β} (M : DMachine Alpha s) | |
| (positive : Bool) (L : Set (List Alpha)) : Prop := β w, M.Accepts positive w β w β L | |
| /-- An alphabet-independent polynomial bound for deterministic simulation. -/ | |
| def PolynomialSimulation (positive : Bool) : Prop := | |
| β C c : β, 0 < C β§ 0 < c β§ | |
| β (Alpha : Type) (_ : Fintype Alpha) (n : β) (N : NMachine Alpha n), | |
| β (s : β) (D : DMachine Alpha s), | |
| (s : β) β€ C * (n : β) ^ c β§ | |
| β w, D.Accepts positive w β N.Accepts positive w | |
| end OneWayLiveness | |
| end OAI | |