RIS.closed_automaton: computing an automaton for the ฮฑ-closure of an expression.

Set Implicit Arguments.

Require Import tools algebra language regexp automata systems.
Require Import aeq_facts alpha_regexp closed_languages binding_finite.

Section s.
  Context {atom : Set}{๐€ : Atom atom}.
  Context {X : Set} {๐— : Alphabet ๐€ X}.

  Notation Regexp := (@regexp letter).

  Definition bounded_stack A B n : list stack :=
    flat_map (lists_of_length (pairs A B)) (seq 0 (S n)).

  Definition state_space e A :=
    pairs (bounded_stack โŒŠeโŒ‹ A (2ร—sizeExpr e)) (stateSpace e).

  Definition transitions_from A (state : stack ร— Regexp) l :=
    match (state,l) with
    | (s,e,open a) โ‡’ flat_map (fun f โ‡’ map (fun b โ‡’ ((s,e),open b,((a,b)::s,f))) A) (ฮดA (open a) e)
    | (s,e,close a) โ‡’ if (pairedb s a (image s a)) && (inb (image s a) A) then
                        map (fun f โ‡’ ((s,e),close (image s a),(sโŠ–(a,image s a),f))) (ฮดA (close a) e)
                      else []
    | (s,e,var x) โ‡’
      match var_perm' โŒŠxโŒ‹ s with
      | None โ‡’ []
      | Some p โ‡’
        if inclb โŒŠpโˆ™xโŒ‹ A
        then map (fun f โ‡’ ((s,e),var (pโˆ™x),(s,f))) (ฮดA (var x) e)
        else []
      end
    end.

  Lemma transitions_from_spec A f s e l s1 s2 e1 e2 l' :
    (s,e)โˆˆ state_space f A โ†’
    ((s1,e1),l',(s2,e2)) โˆˆ transitions_from A (s,e) l โ†”
    (s1 = s โˆง e1 = e โˆง โŒŠl'โŒ‹ โŠ† A โˆง e2 โˆˆ ฮดA l e โˆง s โŠฃ l | l' โ†ฆ s2) .

  Definition closed_automaton (e : Regexp) (A : list atom) : NFA (stackร—Regexp) letter :=
    (filter (fun st โ‡’ (prj1 (fst st) =?= prj2 (fst st)) && ฯต (snd st) =?= e_un)(state_space e A),

     flat_map (fun st โ‡’ flat_map (transitions_from A st) (Var e)) (state_space e A)).

  Lemma path_support u v s1 s2 : s1 โŠฃ u | v โค… s2 โ†’ prj1 s2 โŠ† prj1 s1 ++ โŒŠuโŒ‹
                                                   โˆง prj2 s2 โŠ† prj2 s1 ++ โŒŠvโŒ‹.

We have built an automaton whose language is the set of words u such that โŒŠuโŒ‹ โŠ† A and there is a word v โˆˆ โŸฆeโŸง such that vโ‰กu.