src/HOL/IOA/IOA.thy
author haftmann
Sun Oct 08 22:28:22 2017 +0200 (23 months ago)
changeset 66816 212a3334e7da
parent 63167 0909deb8059b
child 67613 ce654b0e6d69
permissions -rw-r--r--
more fundamental definition of div and mod on int
oheimb@4530
     1
(*  Title:      HOL/IOA/IOA.thy
mueller@3078
     2
    Author:     Tobias Nipkow & Konrad Slind
mueller@3078
     3
    Copyright   1994  TU Muenchen
mueller@3078
     4
*)
mueller@3078
     5
wenzelm@63167
     6
section \<open>The I/O automata of Lynch and Tuttle\<close>
wenzelm@17288
     7
wenzelm@17288
     8
theory IOA
wenzelm@17288
     9
imports Asig
wenzelm@17288
    10
begin
mueller@3078
    11
wenzelm@42174
    12
type_synonym 'a seq = "nat => 'a"
wenzelm@42174
    13
type_synonym 'a oseq = "nat => 'a option"
wenzelm@42174
    14
type_synonym ('a, 'b) execution = "'a oseq * 'b seq"
wenzelm@42174
    15
type_synonym ('a, 's) transition = "('s * 'a * 's)"
wenzelm@42174
    16
type_synonym ('a,'s) ioa = "'a signature * 's set * ('a, 's) transition set"
mueller@3078
    17
wenzelm@62145
    18
(* IO automata *)
wenzelm@62145
    19
wenzelm@62145
    20
definition state_trans :: "['action signature, ('action,'state)transition set] => bool"
wenzelm@62145
    21
  where "state_trans asig R ==
wenzelm@62145
    22
     (!triple. triple:R --> fst(snd(triple)):actions(asig)) &
wenzelm@62145
    23
     (!a. (a:inputs(asig)) --> (!s1. ? s2. (s1,a,s2):R))"
wenzelm@62145
    24
wenzelm@62145
    25
definition asig_of :: "('action,'state)ioa => 'action signature"
wenzelm@62145
    26
  where "asig_of == fst"
mueller@3078
    27
wenzelm@62145
    28
definition starts_of :: "('action,'state)ioa => 'state set"
wenzelm@62145
    29
  where "starts_of == (fst o snd)"
wenzelm@62145
    30
wenzelm@62145
    31
definition trans_of :: "('action,'state)ioa => ('action,'state)transition set"
wenzelm@62145
    32
  where "trans_of == (snd o snd)"
mueller@3078
    33
wenzelm@62145
    34
definition IOA :: "('action,'state)ioa => bool"
wenzelm@62145
    35
  where "IOA(ioa) == (is_asig(asig_of(ioa)) &
wenzelm@62145
    36
                (~ starts_of(ioa) = {}) &
wenzelm@62145
    37
                state_trans (asig_of ioa) (trans_of ioa))"
wenzelm@62145
    38
wenzelm@62145
    39
wenzelm@62145
    40
(* Executions, schedules, and traces *)
mueller@3078
    41
wenzelm@62145
    42
(* An execution fragment is modelled with a pair of sequences:
wenzelm@62145
    43
   the first is the action options, the second the state sequence.
wenzelm@62145
    44
   Finite executions have None actions from some point on. *)
wenzelm@62145
    45
definition is_execution_fragment :: "[('action,'state)ioa, ('action,'state)execution] => bool"
wenzelm@62145
    46
  where "is_execution_fragment A ex ==
wenzelm@62145
    47
     let act = fst(ex); state = snd(ex)
wenzelm@62145
    48
     in !n a. (act(n)=None --> state(Suc(n)) = state(n)) &
wenzelm@62145
    49
              (act(n)=Some(a) --> (state(n),a,state(Suc(n))):trans_of(A))"
wenzelm@62145
    50
wenzelm@62145
    51
definition executions :: "('action,'state)ioa => ('action,'state)execution set"
wenzelm@62145
    52
  where "executions(ioa) == {e. snd e 0:starts_of(ioa) & is_execution_fragment ioa e}"
mueller@3078
    53
wenzelm@62145
    54
wenzelm@62145
    55
definition reachable :: "[('action,'state)ioa, 'state] => bool"
wenzelm@62145
    56
  where "reachable ioa s == (? ex:executions(ioa). ? n. (snd ex n) = s)"
wenzelm@62145
    57
wenzelm@62145
    58
definition invariant :: "[('action,'state)ioa, 'state=>bool] => bool"
wenzelm@62145
    59
  where "invariant A P == (!s. reachable A s --> P(s))"
wenzelm@62145
    60
wenzelm@62145
    61
wenzelm@62145
    62
(* Composition of action signatures and automata *)
wenzelm@62145
    63
wenzelm@62145
    64
consts
mueller@3078
    65
  compatible_asigs ::"('a => 'action signature) => bool"
mueller@3078
    66
  asig_composition ::"('a => 'action signature) => 'action signature"
mueller@3078
    67
  compatible_ioas  ::"('a => ('action,'state)ioa) => bool"
mueller@3078
    68
  ioa_composition  ::"('a => ('action, 'state)ioa) =>('action,'a => 'state)ioa"
mueller@3078
    69
wenzelm@62145
    70
wenzelm@62145
    71
(* binary composition of action signatures and automata *)
mueller@3078
    72
wenzelm@62145
    73
definition compat_asigs ::"['action signature, 'action signature] => bool"
wenzelm@62145
    74
  where "compat_asigs a1 a2 ==
wenzelm@62145
    75
   (((outputs(a1) Int outputs(a2)) = {}) &
wenzelm@62145
    76
    ((internals(a1) Int actions(a2)) = {}) &
wenzelm@62145
    77
    ((internals(a2) Int actions(a1)) = {}))"
mueller@3078
    78
wenzelm@62145
    79
definition compat_ioas  ::"[('action,'s)ioa, ('action,'t)ioa] => bool"
wenzelm@62145
    80
  where "compat_ioas ioa1 ioa2 == compat_asigs (asig_of(ioa1)) (asig_of(ioa2))"
mueller@3078
    81
wenzelm@62145
    82
definition asig_comp :: "['action signature, 'action signature] => 'action signature"
wenzelm@62145
    83
  where "asig_comp a1 a2 ==
wenzelm@62145
    84
      (((inputs(a1) Un inputs(a2)) - (outputs(a1) Un outputs(a2)),
wenzelm@62145
    85
        (outputs(a1) Un outputs(a2)),
wenzelm@62145
    86
        (internals(a1) Un internals(a2))))"
mueller@3078
    87
wenzelm@62145
    88
definition par :: "[('a,'s)ioa, ('a,'t)ioa] => ('a,'s*'t)ioa"  (infixr "||" 10)
wenzelm@62145
    89
  where "(ioa1 || ioa2) ==
wenzelm@62145
    90
     (asig_comp (asig_of ioa1) (asig_of ioa2),
wenzelm@62145
    91
      {pr. fst(pr):starts_of(ioa1) & snd(pr):starts_of(ioa2)},
wenzelm@62145
    92
      {tr. let s = fst(tr); a = fst(snd(tr)); t = snd(snd(tr))
wenzelm@62145
    93
           in (a:actions(asig_of(ioa1)) | a:actions(asig_of(ioa2))) &
wenzelm@62145
    94
              (if a:actions(asig_of(ioa1)) then
wenzelm@62145
    95
                 (fst(s),a,fst(t)):trans_of(ioa1)
wenzelm@62145
    96
               else fst(t) = fst(s))
wenzelm@62145
    97
              &
wenzelm@62145
    98
              (if a:actions(asig_of(ioa2)) then
wenzelm@62145
    99
                 (snd(s),a,snd(t)):trans_of(ioa2)
wenzelm@62145
   100
               else snd(t) = snd(s))})"
mueller@3078
   101
mueller@3078
   102
wenzelm@62145
   103
(* Filtering and hiding *)
mueller@3078
   104
mueller@3078
   105
(* Restrict the trace to those members of the set s *)
wenzelm@62145
   106
definition filter_oseq :: "('a => bool) => 'a oseq => 'a oseq"
wenzelm@62145
   107
  where "filter_oseq p s ==
wenzelm@17288
   108
   (%i. case s(i)
wenzelm@17288
   109
         of None => None
mueller@3078
   110
          | Some(x) => if p x then Some x else None)"
mueller@3078
   111
wenzelm@62145
   112
definition mk_trace :: "[('action,'state)ioa, 'action oseq] => 'action oseq"
wenzelm@62145
   113
  where "mk_trace(ioa) == filter_oseq(%a. a:externals(asig_of(ioa)))"
mueller@3078
   114
mueller@3078
   115
(* Does an ioa have an execution with the given trace *)
wenzelm@62145
   116
definition has_trace :: "[('action,'state)ioa, 'action oseq] => bool"
wenzelm@62145
   117
  where "has_trace ioa b == (? ex:executions(ioa). b = mk_trace ioa (fst ex))"
mueller@3078
   118
wenzelm@62145
   119
definition NF :: "'a oseq => 'a oseq"
wenzelm@62145
   120
  where "NF(tr) == @nf. ? f. mono(f) & (!i. nf(i)=tr(f(i))) &
wenzelm@17288
   121
                    (!j. j ~: range(f) --> nf(j)= None) &
wenzelm@62145
   122
                    (!i. nf(i)=None --> (nf (Suc i)) = None)"
wenzelm@17288
   123
mueller@3078
   124
(* All the traces of an ioa *)
wenzelm@62145
   125
definition traces :: "('action,'state)ioa => 'action oseq set"
wenzelm@62145
   126
  where "traces(ioa) == {trace. ? tr. trace=NF(tr) & has_trace ioa tr}"
mueller@3078
   127
mueller@3078
   128
wenzelm@62145
   129
definition restrict_asig :: "['a signature, 'a set] => 'a signature"
wenzelm@62145
   130
  where "restrict_asig asig actns ==
wenzelm@17288
   131
    (inputs(asig) Int actns, outputs(asig) Int actns,
mueller@3078
   132
     internals(asig) Un (externals(asig) - actns))"
mueller@3078
   133
wenzelm@62145
   134
definition restrict :: "[('a,'s)ioa, 'a set] => ('a,'s)ioa"
wenzelm@62145
   135
  where "restrict ioa actns ==
mueller@3078
   136
    (restrict_asig (asig_of ioa) actns, starts_of(ioa), trans_of(ioa))"
mueller@3078
   137
mueller@3078
   138
wenzelm@62145
   139
wenzelm@62145
   140
(* Notions of correctness *)
wenzelm@62145
   141
wenzelm@62145
   142
definition ioa_implements :: "[('action,'state1)ioa, ('action,'state2)ioa] => bool"
wenzelm@62145
   143
  where "ioa_implements ioa1 ioa2 ==
wenzelm@17288
   144
  ((inputs(asig_of(ioa1)) = inputs(asig_of(ioa2))) &
wenzelm@17288
   145
     (outputs(asig_of(ioa1)) = outputs(asig_of(ioa2))) &
mueller@3078
   146
      traces(ioa1) <= traces(ioa2))"
wenzelm@17288
   147
wenzelm@62145
   148
wenzelm@62145
   149
(* Instantiation of abstract IOA by concrete actions *)
wenzelm@62145
   150
wenzelm@62145
   151
definition rename :: "('a, 'b)ioa => ('c => 'a option) => ('c,'b)ioa"
wenzelm@62145
   152
  where "rename ioa ren ==
wenzelm@62145
   153
    (({b. ? x. Some(x)= ren(b) & x : inputs(asig_of(ioa))},
wenzelm@62145
   154
      {b. ? x. Some(x)= ren(b) & x : outputs(asig_of(ioa))},
wenzelm@62145
   155
      {b. ? x. Some(x)= ren(b) & x : internals(asig_of(ioa))}),
wenzelm@62145
   156
                starts_of(ioa)   ,
wenzelm@62145
   157
     {tr. let s = fst(tr); a = fst(snd(tr));  t = snd(snd(tr))
wenzelm@62145
   158
          in
wenzelm@62145
   159
          ? x. Some(x) = ren(a) & (s,x,t):trans_of(ioa)})"
mueller@3078
   160
wenzelm@19801
   161
wenzelm@19801
   162
declare Let_def [simp]
wenzelm@19801
   163
wenzelm@19801
   164
lemmas ioa_projections = asig_of_def starts_of_def trans_of_def
wenzelm@19801
   165
  and exec_rws = executions_def is_execution_fragment_def
wenzelm@19801
   166
wenzelm@19801
   167
lemma ioa_triple_proj:
wenzelm@19801
   168
    "asig_of(x,y,z) = x & starts_of(x,y,z) = y & trans_of(x,y,z) = z"
wenzelm@19801
   169
  apply (simp add: ioa_projections)
wenzelm@19801
   170
  done
wenzelm@19801
   171
wenzelm@19801
   172
lemma trans_in_actions:
wenzelm@19801
   173
  "[| IOA(A); (s1,a,s2):trans_of(A) |] ==> a:actions(asig_of(A))"
wenzelm@62145
   174
  apply (unfold IOA_def state_trans_def actions_def is_asig_def)
wenzelm@19801
   175
  apply (erule conjE)+
wenzelm@19801
   176
  apply (erule allE, erule impE, assumption)
wenzelm@19801
   177
  apply simp
wenzelm@19801
   178
  done
wenzelm@19801
   179
wenzelm@19801
   180
wenzelm@19801
   181
lemma filter_oseq_idemp: "filter_oseq p (filter_oseq p s) = filter_oseq p s"
wenzelm@19801
   182
  apply (simp add: filter_oseq_def)
wenzelm@19801
   183
  apply (rule ext)
wenzelm@19801
   184
  apply (case_tac "s i")
wenzelm@19801
   185
  apply simp_all
wenzelm@19801
   186
  done
wenzelm@19801
   187
wenzelm@19801
   188
lemma mk_trace_thm:
wenzelm@19801
   189
"(mk_trace A s n = None) =
wenzelm@19801
   190
   (s(n)=None | (? a. s(n)=Some(a) & a ~: externals(asig_of(A))))
wenzelm@19801
   191
   &
wenzelm@19801
   192
   (mk_trace A s n = Some(a)) =
wenzelm@19801
   193
    (s(n)=Some(a) & a : externals(asig_of(A)))"
wenzelm@19801
   194
  apply (unfold mk_trace_def filter_oseq_def)
wenzelm@19801
   195
  apply (case_tac "s n")
wenzelm@19801
   196
  apply auto
wenzelm@19801
   197
  done
wenzelm@19801
   198
wenzelm@19801
   199
lemma reachable_0: "s:starts_of(A) ==> reachable A s"
wenzelm@19801
   200
  apply (unfold reachable_def)
wenzelm@19801
   201
  apply (rule_tac x = "(%i. None, %i. s)" in bexI)
wenzelm@19801
   202
  apply simp
wenzelm@19801
   203
  apply (simp add: exec_rws)
wenzelm@19801
   204
  done
wenzelm@19801
   205
wenzelm@19801
   206
lemma reachable_n:
wenzelm@19801
   207
  "!!A. [| reachable A s; (s,a,t) : trans_of(A) |] ==> reachable A t"
wenzelm@19801
   208
  apply (unfold reachable_def exec_rws)
wenzelm@19801
   209
  apply (simp del: bex_simps)
wenzelm@19801
   210
  apply (simp (no_asm_simp) only: split_tupled_all)
wenzelm@19801
   211
  apply safe
wenzelm@19801
   212
  apply (rename_tac ex1 ex2 n)
wenzelm@19801
   213
  apply (rule_tac x = "(%i. if i<n then ex1 i else (if i=n then Some a else None) , %i. if i<Suc n then ex2 i else t)" in bexI)
wenzelm@19801
   214
   apply (rule_tac x = "Suc n" in exI)
wenzelm@19801
   215
   apply (simp (no_asm))
wenzelm@19801
   216
  apply simp
paulson@24742
   217
  apply (metis ioa_triple_proj less_antisym)
wenzelm@19801
   218
  done
wenzelm@19801
   219
wenzelm@19801
   220
wenzelm@19801
   221
lemma invariantI:
wenzelm@19801
   222
  assumes p1: "!!s. s:starts_of(A) ==> P(s)"
wenzelm@19801
   223
    and p2: "!!s t a. [|reachable A s; P(s)|] ==> (s,a,t): trans_of(A) --> P(t)"
wenzelm@19801
   224
  shows "invariant A P"
wenzelm@19801
   225
  apply (unfold invariant_def reachable_def Let_def exec_rws)
wenzelm@19801
   226
  apply safe
wenzelm@19801
   227
  apply (rename_tac ex1 ex2 n)
wenzelm@19801
   228
  apply (rule_tac Q = "reachable A (ex2 n) " in conjunct1)
wenzelm@19801
   229
  apply simp
wenzelm@19801
   230
  apply (induct_tac n)
wenzelm@19801
   231
   apply (fast intro: p1 reachable_0)
wenzelm@19801
   232
  apply (erule_tac x = na in allE)
wenzelm@19801
   233
  apply (case_tac "ex1 na", simp_all)
wenzelm@19801
   234
  apply safe
wenzelm@19801
   235
   apply (erule p2 [THEN mp])
wenzelm@19801
   236
    apply (fast dest: reachable_n)+
wenzelm@19801
   237
  done
wenzelm@19801
   238
wenzelm@19801
   239
lemma invariantI1:
wenzelm@19801
   240
 "[| !!s. s : starts_of(A) ==> P(s);
wenzelm@19801
   241
     !!s t a. reachable A s ==> P(s) --> (s,a,t):trans_of(A) --> P(t)
wenzelm@19801
   242
  |] ==> invariant A P"
wenzelm@19801
   243
  apply (blast intro!: invariantI)
wenzelm@19801
   244
  done
wenzelm@19801
   245
wenzelm@19801
   246
lemma invariantE:
wenzelm@19801
   247
  "[| invariant A P; reachable A s |] ==> P(s)"
wenzelm@19801
   248
  apply (unfold invariant_def)
wenzelm@19801
   249
  apply blast
wenzelm@19801
   250
  done
wenzelm@19801
   251
wenzelm@19801
   252
lemma actions_asig_comp:
wenzelm@19801
   253
  "actions(asig_comp a b) = actions(a) Un actions(b)"
wenzelm@19801
   254
  apply (auto simp add: actions_def asig_comp_def asig_projections)
wenzelm@19801
   255
  done
wenzelm@19801
   256
wenzelm@19801
   257
lemma starts_of_par:
wenzelm@19801
   258
  "starts_of(A || B) = {p. fst(p):starts_of(A) & snd(p):starts_of(B)}"
wenzelm@19801
   259
  apply (simp add: par_def ioa_projections)
wenzelm@19801
   260
  done
wenzelm@19801
   261
wenzelm@19801
   262
(* Every state in an execution is reachable *)
wenzelm@19801
   263
lemma states_of_exec_reachable:
wenzelm@19801
   264
  "ex:executions(A) ==> !n. reachable A (snd ex n)"
wenzelm@19801
   265
  apply (unfold reachable_def)
wenzelm@19801
   266
  apply fast
wenzelm@19801
   267
  done
wenzelm@19801
   268
wenzelm@19801
   269
wenzelm@19801
   270
lemma trans_of_par4:
wenzelm@19801
   271
"(s,a,t) : trans_of(A || B || C || D) =
wenzelm@19801
   272
  ((a:actions(asig_of(A)) | a:actions(asig_of(B)) | a:actions(asig_of(C)) |
wenzelm@19801
   273
    a:actions(asig_of(D))) &
wenzelm@19801
   274
   (if a:actions(asig_of(A)) then (fst(s),a,fst(t)):trans_of(A)
wenzelm@19801
   275
    else fst t=fst s) &
wenzelm@19801
   276
   (if a:actions(asig_of(B)) then (fst(snd(s)),a,fst(snd(t))):trans_of(B)
wenzelm@19801
   277
    else fst(snd(t))=fst(snd(s))) &
wenzelm@19801
   278
   (if a:actions(asig_of(C)) then
wenzelm@19801
   279
      (fst(snd(snd(s))),a,fst(snd(snd(t)))):trans_of(C)
wenzelm@19801
   280
    else fst(snd(snd(t)))=fst(snd(snd(s)))) &
wenzelm@19801
   281
   (if a:actions(asig_of(D)) then
wenzelm@19801
   282
      (snd(snd(snd(s))),a,snd(snd(snd(t)))):trans_of(D)
wenzelm@19801
   283
    else snd(snd(snd(t)))=snd(snd(snd(s)))))"
wenzelm@19801
   284
  (*SLOW*)
huffman@44066
   285
  apply (simp (no_asm) add: par_def actions_asig_comp prod_eq_iff ioa_projections)
wenzelm@19801
   286
  done
wenzelm@19801
   287
wenzelm@19801
   288
lemma cancel_restrict: "starts_of(restrict ioa acts) = starts_of(ioa) &
wenzelm@19801
   289
              trans_of(restrict ioa acts) = trans_of(ioa) &
wenzelm@19801
   290
              reachable (restrict ioa acts) s = reachable ioa s"
wenzelm@19801
   291
  apply (simp add: is_execution_fragment_def executions_def
wenzelm@19801
   292
    reachable_def restrict_def ioa_projections)
wenzelm@19801
   293
  done
wenzelm@19801
   294
wenzelm@19801
   295
lemma asig_of_par: "asig_of(A || B) = asig_comp (asig_of A) (asig_of B)"
wenzelm@19801
   296
  apply (simp add: par_def ioa_projections)
wenzelm@19801
   297
  done
wenzelm@19801
   298
wenzelm@19801
   299
wenzelm@19801
   300
lemma externals_of_par: "externals(asig_of(A1||A2)) =
wenzelm@19801
   301
   (externals(asig_of(A1)) Un externals(asig_of(A2)))"
wenzelm@19801
   302
  apply (simp add: externals_def asig_of_par asig_comp_def
berghofe@26806
   303
    asig_inputs_def asig_outputs_def Un_def set_diff_eq)
wenzelm@19801
   304
  apply blast
wenzelm@19801
   305
  done
wenzelm@19801
   306
wenzelm@19801
   307
lemma ext1_is_not_int2:
wenzelm@19801
   308
  "[| compat_ioas A1 A2; a:externals(asig_of(A1))|] ==> a~:internals(asig_of(A2))"
wenzelm@19801
   309
  apply (unfold externals_def actions_def compat_ioas_def compat_asigs_def)
wenzelm@19801
   310
  apply auto
wenzelm@19801
   311
  done
wenzelm@19801
   312
wenzelm@19801
   313
lemma ext2_is_not_int1:
wenzelm@19801
   314
 "[| compat_ioas A2 A1 ; a:externals(asig_of(A1))|] ==> a~:internals(asig_of(A2))"
wenzelm@19801
   315
  apply (unfold externals_def actions_def compat_ioas_def compat_asigs_def)
wenzelm@19801
   316
  apply auto
wenzelm@19801
   317
  done
wenzelm@19801
   318
wenzelm@19801
   319
lemmas ext1_ext2_is_not_act2 = ext1_is_not_int2 [THEN int_and_ext_is_act]
wenzelm@19801
   320
  and ext1_ext2_is_not_act1 = ext2_is_not_int1 [THEN int_and_ext_is_act]
wenzelm@17288
   321
wenzelm@17288
   322
end