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