src/HOL/IOA/IOA.ML
author paulson
Tue Jun 28 15:27:45 2005 +0200 (2005-06-28)
changeset 16587 b34c8aa657a5
parent 12886 75ca1bf5ae12
child 17288 aa3833fb7bee
permissions -rw-r--r--
Constant "If" is now local
     1 (*  Title:      HOL/IOA/IOA.ML
     2     ID:         $Id$
     3     Author:     Tobias Nipkow & Konrad Slind
     4     Copyright   1994  TU Muenchen
     5 
     6 The I/O automata of Lynch and Tuttle.
     7 *)
     8 
     9 Addsimps [Let_def];
    10 
    11 val ioa_projections = [asig_of_def, starts_of_def, trans_of_def];
    12 
    13 val exec_rws = [executions_def,is_execution_fragment_def];
    14 
    15 Goal
    16 "asig_of(x,y,z) = x & starts_of(x,y,z) = y & trans_of(x,y,z) = z";
    17   by (simp_tac (simpset() addsimps ioa_projections) 1);
    18   qed "ioa_triple_proj";
    19 
    20 Goalw [ioa_def,state_trans_def,actions_def, is_asig_def]
    21   "[| IOA(A); (s1,a,s2):trans_of(A) |] ==> a:actions(asig_of(A))";
    22   by (REPEAT(etac conjE 1));
    23   by (EVERY1[etac allE, etac impE, atac]);
    24   by (Asm_full_simp_tac 1);
    25 qed "trans_in_actions";
    26 
    27 
    28 Goal "filter_oseq p (filter_oseq p s) = filter_oseq p s";
    29   by (simp_tac (simpset() addsimps [filter_oseq_def]) 1);
    30   by (rtac ext 1);
    31   by (case_tac "s(i)" 1);
    32   by (Asm_simp_tac 1);
    33   by (Asm_simp_tac 1);
    34 qed "filter_oseq_idemp";
    35 
    36 Goalw [mk_trace_def,filter_oseq_def]
    37 "(mk_trace A s n = None) =                                        \
    38 \  (s(n)=None | (? a. s(n)=Some(a) & a ~: externals(asig_of(A)))) \
    39 \  &                                                              \
    40 \  (mk_trace A s n = Some(a)) =                                   \
    41 \   (s(n)=Some(a) & a : externals(asig_of(A)))";
    42   by (case_tac "s(n)" 1);
    43   by (ALLGOALS Asm_simp_tac);
    44   by (Fast_tac 1);
    45 qed "mk_trace_thm";
    46 
    47 Goalw [reachable_def] "s:starts_of(A) ==> reachable A s";
    48   by (res_inst_tac [("x","(%i. None,%i. s)")] bexI 1);
    49   by (Simp_tac 1);
    50   by (asm_simp_tac (simpset() addsimps exec_rws) 1);
    51 qed "reachable_0";
    52 
    53 Goalw (reachable_def::exec_rws)
    54 "!!A. [| reachable A s; (s,a,t) : trans_of(A) |] ==> reachable A t";
    55   by (asm_full_simp_tac (simpset() delsimps bex_simps) 1);
    56   by (split_all_tac 1);
    57   by Safe_tac;
    58   by (rename_tac "ex1 ex2 n" 1);
    59   by (res_inst_tac [("x","(%i. if i<n then ex1 i                    \
    60 \                            else (if i=n then Some a else None),    \
    61 \                         %i. if i<Suc n then ex2 i else t)")] bexI 1);
    62    by (res_inst_tac [("x","Suc n")] exI 1);
    63    by (Simp_tac 1);
    64   by (Asm_full_simp_tac 1);
    65   by (rtac allI 1);
    66   by (cut_inst_tac [("m","na"),("n","n")] less_linear 1);
    67   by Auto_tac;
    68 qed "reachable_n";
    69 
    70 val [p1,p2] = goalw IOA.thy [invariant_def]
    71   "[| !!s. s:starts_of(A) ==> P(s);                                          \
    72 \     !!s t a. [|reachable A s; P(s)|] ==> (s,a,t): trans_of(A) --> P(t) |] \
    73 \  ==> invariant A P";
    74   by (rewrite_goals_tac(reachable_def::Let_def::exec_rws));
    75   by Safe_tac;
    76   by (rename_tac "ex1 ex2 n" 1);
    77   by (res_inst_tac [("Q","reachable A (ex2 n)")] conjunct1 1);
    78   by (Asm_full_simp_tac 1);
    79   by (induct_tac "n" 1);
    80    by (fast_tac (claset() addIs [p1,reachable_0]) 1);
    81   by (eres_inst_tac[("x","na")] allE 1);
    82   by (case_tac "ex1 na" 1 THEN ALLGOALS Asm_full_simp_tac);
    83   by Safe_tac;
    84    by (etac (p2 RS mp) 1);
    85     by (ALLGOALS(fast_tac(claset() addDs [reachable_n])));
    86 qed "invariantI";
    87 
    88 val [p1,p2] = goal IOA.thy
    89  "[| !!s. s : starts_of(A) ==> P(s); \
    90 \    !!s t a. reachable A s ==> P(s) --> (s,a,t):trans_of(A) --> P(t) \
    91 \ |] ==> invariant A P";
    92   by (fast_tac (claset() addSIs [invariantI] addSDs [p1,p2]) 1);
    93 qed "invariantI1";
    94 
    95 val [p1,p2] = goalw IOA.thy [invariant_def]
    96 "[| invariant A P; reachable A s |] ==> P(s)";
    97    by (rtac (p2 RS (p1 RS spec RS mp)) 1);
    98 qed "invariantE";
    99 
   100 Goal 
   101 "actions(asig_comp a b) = actions(a) Un actions(b)";
   102   by (simp_tac (simpset() addsimps
   103                ([actions_def,asig_comp_def]@asig_projections)) 1);
   104   by (Fast_tac 1);
   105 qed "actions_asig_comp";
   106 
   107 Goal
   108 "starts_of(A || B) = {p. fst(p):starts_of(A) & snd(p):starts_of(B)}";
   109   by (simp_tac (simpset() addsimps (par_def::ioa_projections)) 1);
   110 qed "starts_of_par";
   111 
   112 (* Every state in an execution is reachable *)
   113 Goalw [reachable_def] 
   114 "ex:executions(A) ==> !n. reachable A (snd ex n)";
   115   by (Fast_tac 1);
   116 qed "states_of_exec_reachable";
   117 
   118 
   119 Goal 
   120 "(s,a,t) : trans_of(A || B || C || D) =                                      \
   121 \ ((a:actions(asig_of(A)) | a:actions(asig_of(B)) | a:actions(asig_of(C)) |  \
   122 \   a:actions(asig_of(D))) &                                                 \
   123 \  (if a:actions(asig_of(A)) then (fst(s),a,fst(t)):trans_of(A)              \
   124 \   else fst t=fst s) &                                                      \
   125 \  (if a:actions(asig_of(B)) then (fst(snd(s)),a,fst(snd(t))):trans_of(B)    \
   126 \   else fst(snd(t))=fst(snd(s))) &                                          \
   127 \  (if a:actions(asig_of(C)) then                                            \
   128 \     (fst(snd(snd(s))),a,fst(snd(snd(t)))):trans_of(C)                      \
   129 \   else fst(snd(snd(t)))=fst(snd(snd(s)))) &                                \
   130 \  (if a:actions(asig_of(D)) then                                            \
   131 \     (snd(snd(snd(s))),a,snd(snd(snd(t)))):trans_of(D)                      \
   132 \   else snd(snd(snd(t)))=snd(snd(snd(s)))))";
   133   (*SLOW*)
   134   by (simp_tac (simpset() addsimps ([par_def,actions_asig_comp,Pair_fst_snd_eq]
   135                                     @ ioa_projections)) 1);
   136 qed "trans_of_par4";
   137 
   138 Goal "starts_of(restrict ioa acts) = starts_of(ioa) &     \
   139 \             trans_of(restrict ioa acts) = trans_of(ioa) &       \
   140 \             reachable (restrict ioa acts) s = reachable ioa s";
   141 by (simp_tac (simpset() addsimps ([is_execution_fragment_def,executions_def,
   142                            reachable_def,restrict_def]@ioa_projections)) 1);
   143 qed "cancel_restrict";
   144 
   145 Goal "asig_of(A || B) = asig_comp (asig_of A) (asig_of B)";
   146   by (simp_tac (simpset() addsimps (par_def::ioa_projections)) 1);
   147 qed "asig_of_par";
   148 
   149 
   150 Goal "externals(asig_of(A1||A2)) =    \
   151 \  (externals(asig_of(A1)) Un externals(asig_of(A2)))";
   152 by (asm_full_simp_tac (simpset() addsimps [externals_def,asig_of_par,asig_comp_def,asig_inputs_def,asig_outputs_def,Un_def,set_diff_def]) 1);
   153 by (rtac set_ext 1); 
   154 by (Fast_tac 1);
   155 qed"externals_of_par"; 
   156 
   157 Goalw [externals_def,actions_def,compat_ioas_def,compat_asigs_def]
   158  "[| compat_ioas A1 A2; a:externals(asig_of(A1))|] ==> a~:internals(asig_of(A2))";
   159 by (Asm_full_simp_tac 1);
   160 by (Best_tac 1);
   161 qed"ext1_is_not_int2";
   162 
   163 Goalw [externals_def,actions_def,compat_ioas_def,compat_asigs_def]
   164  "[| compat_ioas A2 A1 ; a:externals(asig_of(A1))|] ==> a~:internals(asig_of(A2))";
   165 by (Asm_full_simp_tac 1);
   166 by (Best_tac 1);
   167 qed"ext2_is_not_int1";
   168 
   169 val ext1_ext2_is_not_act2 = ext1_is_not_int2 RS int_and_ext_is_act;
   170 val ext1_ext2_is_not_act1 = ext2_is_not_int1 RS int_and_ext_is_act;
   171