cfahlgren1/math / lean /ComparatorChallenges /TwoWayDeterminization.lean
cfahlgren1's picture
download
raw
3.02 kB
import Mathlib
namespace OAI
namespace TwoWayComplementation
open scoped SetRel
/-- Reflexive transitive closure, including the empty path. -/
def relStar {α : Type*} (R : SetRel α α) : SetRel α α :=
{(x, y) | Relation.ReflTransGen (fun a b => (a, b) ∈ R) x y}
/-- A read-only 2NFA. The two endmarkers are `Sum.inl 0` and `Sum.inl 1`.
Move codes 0, 1, 2 mean left, stay, right. -/
structure TwoNFA (Sigma Q : Type*) where
/-- The state in which the machine starts on the left endmarker. -/
initial : Q
/-- States whose occurrence on a finite run constitutes acceptance. -/
accepting : Set Q
/-- Allowed next-state and move pairs, determined by the state and scanned symbol. -/
transition : Q → (Fin 2 ⊕ Sigma) → Set (Q × Fin 3)
/-- Tape lookup includes two distinct endmarkers, even on empty input. -/
def tapeSymbol {Sigma : Type*} (w : List Sigma) (p : Fin (w.length + 2)) : Fin 2 ⊕ Sigma :=
if hleft : p.val = 0 then .inl 0
else if hright : p.val = w.length + 1 then .inl 1
else .inr (w[p.val - 1]'(by omega))
namespace TwoNFA
/-- One legal step: both head positions stay within the marked input. -/
def step {Sigma Q : Type*} (A : TwoNFA Sigma Q) (w : List Sigma) :
SetRel (Q × Fin (w.length + 2)) (Q × Fin (w.length + 2)) :=
{(c, d) | ∃ move : Fin 3,
(d.1, move) ∈ A.transition c.1 (tapeSymbol w c.2) ∧
(d.2.val : ℤ) = (c.2.val : ℤ) + (move.val : ℤ) - 1}
/-- Existential finite-run acceptance, allowing a run of length zero. -/
def language {Sigma Q : Type*} (A : TwoNFA Sigma Q) : Set (List Sigma) :=
{w | ∃ c, c.1 ∈ A.accepting ∧
((A.initial, ⟨0, by omega⟩), c) ∈ relStar (A.step w)}
end TwoNFA
/-- At most one next-state/move pair at every state and scanned symbol. -/
def TwoNFA.Deterministic {Sigma Q : Type*} (A : TwoNFA Sigma Q) : Prop :=
∀ q symbol, (A.transition q symbol).Subsingleton
/-- Relation product for an input word; the empty product is the identity. -/
def relationProduct {H : Type*} (w : List (SetRel H H)) : SetRel H H :=
w.foldr SetRel.comp SetRel.id
/-- The source language consists of the words with nonempty relation product. -/
def sourceLanguage (H : Type*) : Set (List (SetRel H H)) :=
{w | (relationProduct w).Nonempty}
/-- Both lower bounds hold for the same n-state liveness witness. -/
theorem explicit_family_main (n : ℕ) (hn : 4 ≤ n) :
∃ A : TwoNFA (SetRel (Fin (n - 2)) (Fin (n - 2))) (Fin n),
A.language = sourceLanguage (Fin (n - 2)) ∧
(∀ (Q : Type*) [Fintype Q],
∀ B : TwoNFA (SetRel (Fin (n - 2)) (Fin (n - 2))) Q,
B.language = A.languageᶜ →
(1 / 2 : ℝ) * 2 ^ ((n - 4) / 127) - 1 ≤ (Fintype.card Q : ℝ)) ∧
(131 ≤ n → ∀ (Q : Type*) [Fintype Q],
∀ D : TwoNFA (SetRel (Fin (n - 2)) (Fin (n - 2))) Q,
D.Deterministic → D.language = A.language →
(1 / 2 : ℝ) * 2 ^ ((n - 4) / 127) ≤ (Fintype.card Q : ℝ)) := by
sorry
end TwoWayComplementation
end OAI

Xet Storage Details

Size:
3.02 kB
·
Xet hash:
c22f4ce96a4207f38df4e36934d1caebf2df4fb989f86d05b461c25c6097e761

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.