|
| 1 | +/- |
| 2 | +Copyright (c) 2025 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 | +import Cslib.Computability.Automata.DFA |
| 8 | +import Cslib.Computability.Automata.NFA |
| 9 | +import Mathlib.Data.Fintype.Powerset |
| 10 | + |
| 11 | +/-! # Translation of NFA into DFA (subset construction) -/ |
| 12 | + |
| 13 | +namespace NFA |
| 14 | +section SubsetConstruction |
| 15 | + |
| 16 | +/-- Converts an `NFA` into a `DFA` using the subset construction. -/ |
| 17 | +@[scoped grind =] |
| 18 | +def toDFA (nfa : NFA State Symbol) : DFA (Set State) Symbol := { |
| 19 | + start := nfa.start |
| 20 | + accept := { S | ∃ s ∈ S, s ∈ nfa.accept } |
| 21 | + tr := nfa.setImage |
| 22 | + finite_state := by |
| 23 | + haveI := nfa.finite_state |
| 24 | + infer_instance |
| 25 | + finite_symbol := nfa.finite_symbol |
| 26 | +} |
| 27 | + |
| 28 | +/-- Characterisation of transitions in `NFA.toDFA` wrt transitions in the original NA. -/ |
| 29 | +@[scoped grind =] |
| 30 | +theorem toDFA_mem_tr {nfa : NFA State Symbol} : |
| 31 | + s' ∈ nfa.toDFA.tr S x ↔ ∃ s ∈ S, nfa.Tr s x s' := by |
| 32 | + simp only [NFA.toDFA, LTS.setImage, Set.mem_iUnion, exists_prop] |
| 33 | + grind |
| 34 | + |
| 35 | +/-- Characterisation of multistep transitions in `NFA.toDFA` wrt multistep transitions in the |
| 36 | +original NA. -/ |
| 37 | +@[scoped grind =] |
| 38 | +theorem toDFA_mem_mtr {nfa : NFA State Symbol} : |
| 39 | + s' ∈ nfa.toDFA.mtr S xs ↔ ∃ s ∈ S, nfa.MTr s xs s' := by |
| 40 | + simp only [NFA.toDFA, DFA.mtr] |
| 41 | + /- TODO: Grind does not catch a useful rewrite in the subset construction for automata |
| 42 | +
|
| 43 | + A very similar issue seems to occur in the proof of `NFA.toDFA_language_eq`. |
| 44 | +
|
| 45 | + labels: grind, lts, automata |
| 46 | + -/ |
| 47 | + rw [← LTS.setImageMultistep_foldl_setImage] |
| 48 | + grind |
| 49 | + |
| 50 | +/-- Characterisation of multistep transitions in `NFA.toDFA` as image transitions in `LTS`. -/ |
| 51 | +@[scoped grind =] |
| 52 | +theorem toDFA_mtr_setImageMultistep {nfa : NFA State Symbol} : |
| 53 | + nfa.toDFA.mtr = nfa.setImageMultistep := by grind |
| 54 | + |
| 55 | +/-- The `DFA` constructed from an `NFA` has the same language. -/ |
| 56 | +@[scoped grind =] |
| 57 | +theorem toDFA_language_eq {nfa : NFA State Symbol} : |
| 58 | + nfa.toDFA.language = nfa.language := by |
| 59 | + ext xs |
| 60 | + rw [← DFA.accepts_mem_language] |
| 61 | + open DFA in grind |
| 62 | + |
| 63 | +end SubsetConstruction |
| 64 | +end NFA |
0 commit comments