Skip to content

Commit ca190eb

Browse files
committed
feat: An initial version of Buchi and Muller automata
1 parent 1d0fe7e commit ca190eb

File tree

5 files changed

+113
-0
lines changed

5 files changed

+113
-0
lines changed

Cslib.lean

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1+
import Cslib.Computability.Automata.BuchiNA
12
import Cslib.Computability.Automata.DA
23
import Cslib.Computability.Automata.DFA
34
import Cslib.Computability.Automata.DFAToNFA
45
import Cslib.Computability.Automata.EpsilonNFA
56
import Cslib.Computability.Automata.EpsilonNFAToNFA
7+
import Cslib.Computability.Automata.MullerDA
68
import Cslib.Computability.Automata.NA
79
import Cslib.Computability.Automata.NFA
810
import Cslib.Computability.Automata.NFAToDFA
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/-
2+
Copyright (c) 2025-present Ching-Tsun Chou All rights reserved.
3+
Released under Apache 2.0 license as described in the file LICENSE.
4+
Authors: Ching-Tsun Chou
5+
-/
6+
7+
import Cslib.Computability.Automata.NA
8+
import Mathlib.Order.Filter.AtTopBot.Defs
9+
10+
open Filter
11+
12+
/-- Nondeterministic Büchi automaton is a nondeterministic automaton over
13+
finite sets of states and symbols together with a finite set of accepting states. -/
14+
structure BuchiNA (State : Type _) (Symbol : Type _) extends NA State Symbol where
15+
/-- The set of accepting states of the automaton. -/
16+
accept : Set State
17+
/-- The automaton is finite-state. -/
18+
finite_state : Finite State
19+
/-- The type of symbols (also called 'alphabet') is finite. -/
20+
finite_symbol : Finite Symbol
21+
22+
namespace BuchiNA
23+
24+
variable {State : Type _} {Symbol : Type _}
25+
26+
/-- A nondeterministic Büchi automaton accepts an ω-word `xs` iff it has an infinite run
27+
on `xs` which passes through accepting states infinitely often.
28+
-/
29+
@[scoped grind]
30+
def Accepts (nba : BuchiNA State Symbol) (xs : ωList Symbol) :=
31+
∃ ss, nba.InfRun xs ss ∧ ∃ᶠ k in atTop, ss k ∈ nba.accept
32+
33+
/-- The language of a nondeterministic Büchi automaton is the set of ω-words that it accepts. -/
34+
@[scoped grind]
35+
def language (nba : BuchiNA State Symbol) : Set (ωList Symbol) :=
36+
{ xs | nba.Accepts xs }
37+
38+
/-- A string is accepted by a a nondeterministic Büchi automaton iff it is in its language. -/
39+
@[scoped grind]
40+
theorem accepts_mem_language (nba : BuchiNA State Symbol) (xs : ωList Symbol) :
41+
nba.Accepts xs ↔ xs ∈ nba.language := by rfl
42+
43+
end BuchiNA

Cslib/Computability/Automata/DA.lean

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ Authors: Fabrizio Montesi
55
-/
66

77
import Cslib.Computability.Automata.NA
8+
import Cslib.Foundations.Data.OmegaList.Init
89

910
/-! # Deterministic Automaton
1011
@@ -15,3 +16,11 @@ structure DA (State : Type _) (Symbol : Type _) where
1516
start : State
1617
/-- The transition function of the automaton. -/
1718
tr : State → Symbol → State
19+
20+
variable {State : Type _} {Symbol : Type _}
21+
22+
/-- The (unique) infinite run of a DA on an infinite input `xs`.
23+
-/
24+
def DA.infRun (da : DA State Symbol) (xs : ωList Symbol) : ωList State
25+
| 0 => da.start
26+
| k + 1 => da.tr (da.infRun xs k) (xs k)
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/-
2+
Copyright (c) 2025-present Ching-Tsun Chou All rights reserved.
3+
Released under Apache 2.0 license as described in the file LICENSE.
4+
Authors: Ching-Tsun Chou
5+
-/
6+
7+
import Cslib.Computability.Automata.DA
8+
import Mathlib.Order.Filter.AtTopBot.Defs
9+
10+
open Filter
11+
12+
/-! # Deterministic Muller Automata
13+
-/
14+
15+
/-- `xs.infOcc` is the set of elements that occurs infinitely many times in `xs`.
16+
TODO: This definition should be be moved to a different file.
17+
-/
18+
def ωList.infOcc {X : Type*} (xs : ωList X) : Set X :=
19+
{ x | ∃ᶠ k in atTop, xs k = x }
20+
21+
/-- A deterministic Muller automaton consists of a labelled transition function
22+
`tr` over finite sets of states and labels (called symbols), a starting state `start`,
23+
and a finite set of finite accepting sets `accept`. -/
24+
structure MullerDA (State : Type _) (Symbol : Type _) extends DA State Symbol where
25+
/-- The set of accepting sets of the automaton. -/
26+
accept : Set (Set State)
27+
/-- The automaton is finite-state. -/
28+
finite_state : Finite State
29+
/-- The type of symbols (also called 'alphabet') is finite. -/
30+
finite_symbol : Finite Symbol
31+
32+
namespace MullerDA
33+
34+
variable {State : Type _} {Symbol : Type _}
35+
36+
/-- A deterministic Muller automaton `mda` accepts an ω-word `xs` iff the set of states that
37+
occurs infinite often when running `mda` on `xs` is one of the accepting sets.
38+
-/
39+
@[scoped grind →]
40+
def Accepts (mda : MullerDA State Symbol) (xs : ωList Symbol) :=
41+
(mda.infRun xs).infOcc ∈ mda.accept
42+
43+
/-- The ω-language of a deterministic Muller automaton is the set of ω-words that it accepts. -/
44+
@[scoped grind =]
45+
def language (mda : MullerDA State Symbol) : Set (ωList Symbol) :=
46+
{ xs | mda.Accepts xs }
47+
48+
/-- An ω-word is accepted by a deterministic Muller automaton iff it is in its ω-language. -/
49+
@[scoped grind _=_]
50+
theorem accepts_mem_language (mda : MullerDA State Symbol) (xs : ωList Symbol) :
51+
mda.Accepts xs ↔ xs ∈ mda.language := by rfl
52+
53+
end MullerDA

Cslib/Computability/Automata/NA.lean

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ Released under Apache 2.0 license as described in the file LICENSE.
44
Authors: Fabrizio Montesi
55
-/
66

7+
import Cslib.Foundations.Data.OmegaList.Init
78
import Cslib.Foundations.Semantics.LTS.Basic
89

910
/-! # Nondeterministic Automaton
@@ -17,3 +18,8 @@ type `State → Symbol → Set State`; it gets automatically expanded to the for
1718
structure NA (State : Type _) (Symbol : Type _) extends LTS State Symbol where
1819
/-- The set of initial states of the automaton. -/
1920
start : Set State
21+
22+
variable {State : Type _} {Symbol : Type _}
23+
24+
def NA.InfRun (na : NA State Symbol) (xs : ωList Symbol) (ss : ωList State) :=
25+
ss 0 ∈ na.start ∧ ∀ k, na.Tr (ss k) (xs k) (ss (k + 1))

0 commit comments

Comments
 (0)