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