Theory NBA_Refine

section ‹Relations on Nondeterministic Büchi Automata›

theory NBA_Refine
imports
  "NBA"
  "../../Transition_Systems/Transition_System_Refine"
begin

  definition nba_rel :: "('label1 × 'label2) set  ('state1 × 'state2) set 
    (('label1, 'state1) nba × ('label2, 'state2) nba) set" where
    [to_relAPP]: "nba_rel L S  {(A1, A2).
      (alphabet A1, alphabet A2)  L set_rel 
      (initial A1, initial A2)  S set_rel 
      (transition A1, transition A2)  L  S  S set_rel 
      (accepting A1, accepting A2)  S  bool_rel}"

  lemma nba_param[param]:
    "(nba, nba)  L set_rel  S set_rel  (L  S  S set_rel)  (S  bool_rel) 
      L, S nba_rel"
    "(alphabet, alphabet)  L, S nba_rel  L set_rel"
    "(initial, initial)  L, S nba_rel  S set_rel"
    "(transition, transition)  L, S nba_rel  L  S  S set_rel"
    "(accepting, accepting)  L, S nba_rel  S  bool_rel"
    unfolding nba_rel_def fun_rel_def by auto

  lemma nba_rel_id[simp]: "Id, Id nba_rel = Id" unfolding nba_rel_def using nba.expand by auto
  lemma nba_rel_comp[trans]:
    assumes [param]: "(A, B)  L1, S1 nba_rel" "(B, C)  L2, S2 nba_rel"
    shows "(A, C)  L1 O L2, S1 O S2 nba_rel"
  proof -
    have "(accepting A, accepting B)  S1  bool_rel" by parametricity
    also have "(accepting B, accepting C)  S2  bool_rel" by parametricity
    finally have 1: "(accepting A, accepting C)  S1 O S2  bool_rel" by simp
    have "(transition A, transition B)  L1  S1  S1 set_rel" by parametricity
    also have "(transition B, transition C)  L2  S2  S2 set_rel" by parametricity
    finally have 2: "(transition A, transition C)  L1 O L2  S1 O S2  S1 set_rel O S2 set_rel" by simp
    show ?thesis
      unfolding nba_rel_def mem_Collect_eq prod.case set_rel_compp
      using 1 2
      using nba_param(2 - 5)[THEN fun_relD, OF assms(1)]
      using nba_param(2 - 5)[THEN fun_relD, OF assms(2)]
      by auto
  qed
  lemma nba_rel_converse[simp]: "(L, S nba_rel)¯ = L¯, S¯ nba_rel"
  proof -
    have 1: "L set_rel = (L¯ set_rel)¯" by simp
    have 2: "S set_rel = (S¯ set_rel)¯" by simp
    have 3: "L  S  S set_rel = (L¯  S¯  S¯ set_rel)¯" by simp
    have 4: "S  bool_rel = (S¯  bool_rel)¯" by simp
    show ?thesis unfolding nba_rel_def unfolding 3 unfolding 1 2 4 by fastforce
  qed

  lemma nba_rel_eq: "(A, A)  Id_on (alphabet A), Id_on (nodes A) nba_rel"
    unfolding nba_rel_def by auto

  lemma enableds_param[param]: "(nba.enableds, nba.enableds)  L, S nba_rel  S  L ×r S set_rel"
    using nba_param(2, 4) unfolding nba.enableds_def fun_rel_def set_rel_def by fastforce
  lemma paths_param[param]: "(nba.paths, nba.paths)  L, S nba_rel  S  L ×r S list_rel set_rel"
    using enableds_param[param_fo] by parametricity
  lemma runs_param[param]: "(nba.runs, nba.runs)  L, S nba_rel  S  L ×r S stream_rel set_rel"
    using enableds_param[param_fo] by parametricity

  lemma reachable_param[param]: "(reachable, reachable)  L, S nba_rel  S  S set_rel"
  proof -
    have 1: "reachable A p = (λ wr. target wr p) ` nba.paths A p" for A :: "('label, 'state) nba" and p
      unfolding nba.reachable_alt_def nba.paths_def by auto
    show ?thesis unfolding 1 using enableds_param[param_fo] by parametricity
  qed
  lemma nodes_param[param]: "(nodes, nodes)  L, S nba_rel  S set_rel"
    unfolding nba.nodes_alt_def Collect_mem_eq by parametricity

  lemma language_param[param]: "(language, language)  L, S nba_rel  L stream_rel set_rel"
  proof -
    have 1: "language A = ( p  initial A.  wr  nba.runs A p.
      if infs (accepting A) (p ## smap snd wr) then {smap fst wr} else {})"
      for A :: "('label, 'state) nba"
      unfolding nba.language_def nba.runs_def image_def
      by (auto iff: split_szip_ex simp del: alw_smap)
    show ?thesis unfolding 1 using enableds_param[param_fo] by parametricity
  qed

end