|
| 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 |
0 commit comments