Skip to content

Commit a441db6

Browse files
authored
feat(Automata): Transducers (#650)
Adds a class for transducers and a first implementation based on `NA`.
1 parent f10c049 commit a441db6

4 files changed

Lines changed: 99 additions & 0 deletions

File tree

Cslib.lean

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,15 @@ public import Cslib.Computability.Automata.NA.Basic
1616
public import Cslib.Computability.Automata.NA.BuchiEquiv
1717
public import Cslib.Computability.Automata.NA.BuchiInter
1818
public import Cslib.Computability.Automata.NA.Concat
19+
public import Cslib.Computability.Automata.NA.EpsilonTransducer
1920
public import Cslib.Computability.Automata.NA.Hist
2021
public import Cslib.Computability.Automata.NA.Loop
2122
public import Cslib.Computability.Automata.NA.Pair
2223
public import Cslib.Computability.Automata.NA.Prod
2324
public import Cslib.Computability.Automata.NA.Sum
2425
public import Cslib.Computability.Automata.NA.ToDA
2526
public import Cslib.Computability.Automata.NA.Total
27+
public import Cslib.Computability.Automata.Transducers.Transducer
2628
public import Cslib.Computability.Distributed.FLP.Algorithm
2729
public import Cslib.Computability.Distributed.FLP.Consensus
2830
public import Cslib.Computability.Distributed.FLP.ZeroConsensus
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/-
2+
Copyright (c) 2026 Fabrizio Montesi. All rights reserved.
3+
Released under Apache 2.0 license as described in the file LICENSE.
4+
Authors: Fabrizio Montesi
5+
-/
6+
7+
module
8+
9+
public import Cslib.Computability.Automata.NA.Basic
10+
public import Cslib.Computability.Automata.Transducers.Transducer
11+
public import Cslib.Foundations.Semantics.LTS.HasTau
12+
13+
/-! # Nondeterministic finite ε-transducers
14+
15+
Transducers based on `NA` with an invisible symbol in their input and output alphabets.
16+
-/
17+
18+
@[expose] public section
19+
20+
namespace Cslib.Automata.NA
21+
22+
/-- A nondeterministic ε-transducer of finite strings where the input and output alphabets include
23+
an invisible symbol, modelled as `HasTau.τ` (typically called `ε`). -/
24+
structure εTransducer (State InSymbol OutSymbol : Type*)
25+
extends NA State (InSymbol × OutSymbol) where
26+
/-- The set of accepting states. -/
27+
accept : Set State
28+
29+
/-- Removes all `τ`s from a list. -/
30+
@[scoped grind =]
31+
def _root_.List.dropTaus [HasTau α] [DecidableEqTau α] (l : List α) : List α :=
32+
l.filter (· ≠ HasTau.τ)
33+
34+
variable [HasTau InSymbol] [HasTau OutSymbol]
35+
36+
namespace εTransducer
37+
38+
/-- An `εTransducer` translates `xs` into `ys` from state `s` to state `s'` if there is a
39+
multistep transition from `s` to `s'` whose visible projection is `(xs, ys)`.
40+
`MTransl` is short for Multistep Translation relation.
41+
-/
42+
def MTransl [DecidableEqTau InSymbol] [DecidableEqTau OutSymbol]
43+
(a : εTransducer State InSymbol OutSymbol) (s : State)
44+
(xs : List InSymbol) (ys : List OutSymbol) (s' : State) : Prop :=
45+
∃ μs, a.MTr s μs s' ∧ (μs.map Prod.fst |>.dropTaus) = xs ∧ (μs.map Prod.snd |>.dropTaus) = ys
46+
47+
/-- An `NA.εTransducer` translates a finite string `xs` into a finite string `ys` if it has
48+
a multistep transition whose visible projection is `(xs, ys)`.
49+
50+
This is the standard string translation performed by nondeterministic transducers, where
51+
`HasTau.τ` symbols (epsilon transitions) are ignored in the input and output. -/
52+
instance [DecidableEqTau InSymbol] [DecidableEqTau OutSymbol] :
53+
Transducer (εTransducer State InSymbol OutSymbol) InSymbol OutSymbol where
54+
Translates a xs ys := ∃ s ∈ a.start, ∃ s' ∈ a.accept, a.MTransl s xs ys s'
55+
56+
/-- Composition of multistep translations. -/
57+
theorem MTransl.comp [DecidableEqTau InSymbol] [DecidableEqTau OutSymbol]
58+
{a : εTransducer State InSymbol OutSymbol}
59+
{s₁ s₂ s₃ : State} {xs xs' : List InSymbol} {ys ys' : List OutSymbol} :
60+
a.MTransl s₁ xs ys s₂ → a.MTransl s₂ xs' ys' s₃ →
61+
a.MTransl s₁ (xs ++ xs') (ys ++ ys') s₃ := by
62+
intro ⟨μs₁, h₁, e₁⟩ ⟨μs₂, h₂, e₂⟩
63+
refine ⟨μs₁ ++ μs₂, LTS.MTr.comp a.toLTS h₁ h₂, ?_⟩
64+
grind
65+
66+
end εTransducer
67+
68+
end Cslib.Automata.NA
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/-
2+
Copyright (c) 2026 Fabrizio Montesi. All rights reserved.
3+
Released under Apache 2.0 license as described in the file LICENSE.
4+
Authors: Fabrizio Montesi
5+
-/
6+
7+
module
8+
9+
public import Cslib.Init
10+
11+
/-! # Transducers -/
12+
13+
@[expose] public section
14+
15+
namespace Cslib.Automata
16+
17+
/-- A `Transducer` is an automaton that translates strings (lists of symbols, from an input to an
18+
output alphabet). -/
19+
class Transducer (A : Type u) (InSymbol OutSymbol : outParam (Type v)) where
20+
/-- The string `xs` can be translated into `ys` by `a`. -/
21+
Translates (a : A) (xs : List InSymbol) (ys : List OutSymbol) : Prop
22+
23+
@[inherit_doc]
24+
scoped notation xs "[" a "]" ys => Transducer.Translates a xs ys
25+
26+
end Cslib.Automata

Cslib/Foundations/Semantics/LTS/HasTau.lean

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ class HasTau (Label : Type v) where
2323
/-- The internal transition label, also known as τ. -/
2424
τ : Label
2525

26+
/-- Checking whether an element is `τ` is decidable. -/
27+
abbrev DecidableEqTau (α : Type*) [HasTau α] := ∀ a : α, Decidable (a = HasTau.τ)
28+
2629
namespace LTS
2730

2831
/-- Saturated τ-transition relation. -/

0 commit comments

Comments
 (0)