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