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