src/HOL/IOA/IOA.thy
author mueller
Wed Apr 30 11:56:17 1997 +0200 (1997-04-30)
changeset 3078 984866a8f905
child 3842 b55686a7b22c
permissions -rw-r--r--
old IOA meta theory (see also new version in HOLCF/IOA/meta_theory);
mueller@3078
     1
(*  Title:      HOL/IOA/meta_theory/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
The I/O automata of Lynch and Tuttle.
mueller@3078
     7
*)
mueller@3078
     8
mueller@3078
     9
IOA = Asig + Option +
mueller@3078
    10
mueller@3078
    11
types
mueller@3078
    12
   'a seq            =   "nat => 'a"
mueller@3078
    13
   'a oseq           =   "nat => 'a option"
mueller@3078
    14
   ('a,'b)execution  =   "'a oseq * 'b seq"
mueller@3078
    15
   ('a,'s)transition =   "('s * 'a * 's)"
mueller@3078
    16
   ('a,'s)ioa        =   "'a signature * 's set * ('a,'s)transition set"
mueller@3078
    17
mueller@3078
    18
consts
mueller@3078
    19
mueller@3078
    20
  (* IO automata *)
mueller@3078
    21
  state_trans::"['action signature, ('action,'state)transition set] => bool"
mueller@3078
    22
  asig_of    ::"('action,'state)ioa => 'action signature"
mueller@3078
    23
  starts_of  ::"('action,'state)ioa => 'state set"
mueller@3078
    24
  trans_of   ::"('action,'state)ioa => ('action,'state)transition set"
mueller@3078
    25
  IOA        ::"('action,'state)ioa => bool"
mueller@3078
    26
mueller@3078
    27
  (* Executions, schedules, and traces *)
mueller@3078
    28
mueller@3078
    29
  is_execution_fragment,
mueller@3078
    30
  has_execution ::"[('action,'state)ioa, ('action,'state)execution] => bool"
mueller@3078
    31
  executions    :: "('action,'state)ioa => ('action,'state)execution set"
mueller@3078
    32
  mk_trace  :: "[('action,'state)ioa, 'action oseq] => 'action oseq"
mueller@3078
    33
  reachable     :: "[('action,'state)ioa, 'state] => bool"
mueller@3078
    34
  invariant     :: "[('action,'state)ioa, 'state=>bool] => bool"
mueller@3078
    35
  has_trace :: "[('action,'state)ioa, 'action oseq] => bool"
mueller@3078
    36
  traces    :: "('action,'state)ioa => 'action oseq set"
mueller@3078
    37
  NF            :: "'a oseq => 'a oseq"
mueller@3078
    38
mueller@3078
    39
  (* Composition of action signatures and automata *)
mueller@3078
    40
  compatible_asigs ::"('a => 'action signature) => bool"
mueller@3078
    41
  asig_composition ::"('a => 'action signature) => 'action signature"
mueller@3078
    42
  compatible_ioas  ::"('a => ('action,'state)ioa) => bool"
mueller@3078
    43
  ioa_composition  ::"('a => ('action, 'state)ioa) =>('action,'a => 'state)ioa"
mueller@3078
    44
mueller@3078
    45
  (* binary composition of action signatures and automata *)
mueller@3078
    46
  compat_asigs ::"['action signature, 'action signature] => bool"
mueller@3078
    47
  asig_comp    ::"['action signature, 'action signature] => 'action signature"
mueller@3078
    48
  compat_ioas  ::"[('action,'s)ioa, ('action,'t)ioa] => bool"
mueller@3078
    49
  "||"         ::"[('a,'s)ioa, ('a,'t)ioa] => ('a,'s*'t)ioa"  (infixr 10)
mueller@3078
    50
mueller@3078
    51
  (* Filtering and hiding *)
mueller@3078
    52
  filter_oseq  :: "('a => bool) => 'a oseq => 'a oseq"
mueller@3078
    53
mueller@3078
    54
  restrict_asig :: "['a signature, 'a set] => 'a signature"
mueller@3078
    55
  restrict      :: "[('a,'s)ioa, 'a set] => ('a,'s)ioa"
mueller@3078
    56
mueller@3078
    57
  (* Notions of correctness *)
mueller@3078
    58
  ioa_implements :: "[('action,'state1)ioa, ('action,'state2)ioa] => bool"
mueller@3078
    59
mueller@3078
    60
  (* Instantiation of abstract IOA by concrete actions *)
mueller@3078
    61
  rename:: "('a, 'b)ioa => ('c => 'a option) => ('c,'b)ioa"
mueller@3078
    62
mueller@3078
    63
defs
mueller@3078
    64
mueller@3078
    65
state_trans_def
mueller@3078
    66
  "state_trans asig R == 
mueller@3078
    67
     (!triple. triple:R --> fst(snd(triple)):actions(asig)) & 
mueller@3078
    68
     (!a. (a:inputs(asig)) --> (!s1. ? s2. (s1,a,s2):R))"
mueller@3078
    69
mueller@3078
    70
mueller@3078
    71
asig_of_def   "asig_of == fst"
mueller@3078
    72
starts_of_def "starts_of == (fst o snd)"
mueller@3078
    73
trans_of_def  "trans_of == (snd o snd)"
mueller@3078
    74
mueller@3078
    75
ioa_def
mueller@3078
    76
  "IOA(ioa) == (is_asig(asig_of(ioa))      &                            
mueller@3078
    77
                (~ starts_of(ioa) = {})    &                            
mueller@3078
    78
                state_trans (asig_of ioa) (trans_of ioa))"
mueller@3078
    79
mueller@3078
    80
mueller@3078
    81
(* An execution fragment is modelled with a pair of sequences:
mueller@3078
    82
 * the first is the action options, the second the state sequence.
mueller@3078
    83
 * Finite executions have None actions from some point on.
mueller@3078
    84
 *******)
mueller@3078
    85
is_execution_fragment_def
mueller@3078
    86
  "is_execution_fragment A ex ==                                        
mueller@3078
    87
     let act = fst(ex); state = snd(ex)                                 
mueller@3078
    88
     in !n a. (act(n)=None --> state(Suc(n)) = state(n)) &              
mueller@3078
    89
              (act(n)=Some(a) --> (state(n),a,state(Suc(n))):trans_of(A))"
mueller@3078
    90
mueller@3078
    91
mueller@3078
    92
executions_def
mueller@3078
    93
  "executions(ioa) == {e. snd e 0:starts_of(ioa) &                      
mueller@3078
    94
                        is_execution_fragment ioa e}"
mueller@3078
    95
mueller@3078
    96
  
mueller@3078
    97
reachable_def
mueller@3078
    98
  "reachable ioa s == (? ex:executions(ioa). ? n. (snd ex n) = s)"
mueller@3078
    99
mueller@3078
   100
mueller@3078
   101
invariant_def "invariant A P == (!s. reachable A s --> P(s))"
mueller@3078
   102
mueller@3078
   103
mueller@3078
   104
(* Restrict the trace to those members of the set s *)
mueller@3078
   105
filter_oseq_def
mueller@3078
   106
  "filter_oseq p s ==                                                   
mueller@3078
   107
   (%i.case s(i)                                                       
mueller@3078
   108
         of None => None                                               
mueller@3078
   109
          | Some(x) => if p x then Some x else None)"
mueller@3078
   110
mueller@3078
   111
mueller@3078
   112
mk_trace_def
mueller@3078
   113
  "mk_trace(ioa) == filter_oseq(%a.a:externals(asig_of(ioa)))"
mueller@3078
   114
mueller@3078
   115
mueller@3078
   116
(* Does an ioa have an execution with the given trace *)
mueller@3078
   117
has_trace_def
mueller@3078
   118
  "has_trace ioa b ==                                               
mueller@3078
   119
     (? ex:executions(ioa). b = mk_trace ioa (fst ex))"
mueller@3078
   120
mueller@3078
   121
normal_form_def
mueller@3078
   122
  "NF(tr) == @nf. ? f. mono(f) & (!i. nf(i)=tr(f(i))) &   
mueller@3078
   123
                    (!j. j ~: range(f) --> nf(j)= None) &   
mueller@3078
   124
                    (!i. nf(i)=None --> (nf (Suc i)) = None)   "
mueller@3078
   125
  
mueller@3078
   126
(* All the traces of an ioa *)
mueller@3078
   127
mueller@3078
   128
  traces_def
mueller@3078
   129
  "traces(ioa) == {trace. ? tr. trace=NF(tr) & has_trace ioa tr}"
mueller@3078
   130
mueller@3078
   131
(*
mueller@3078
   132
  traces_def
mueller@3078
   133
  "traces(ioa) == {tr. has_trace ioa tr}"
mueller@3078
   134
*)
mueller@3078
   135
  
mueller@3078
   136
compat_asigs_def
mueller@3078
   137
  "compat_asigs a1 a2 ==                                                
mueller@3078
   138
   (((outputs(a1) Int outputs(a2)) = {}) &                              
mueller@3078
   139
    ((internals(a1) Int actions(a2)) = {}) &                            
mueller@3078
   140
    ((internals(a2) Int actions(a1)) = {}))"
mueller@3078
   141
mueller@3078
   142
mueller@3078
   143
compat_ioas_def
mueller@3078
   144
  "compat_ioas ioa1 ioa2 == compat_asigs (asig_of(ioa1)) (asig_of(ioa2))"
mueller@3078
   145
mueller@3078
   146
mueller@3078
   147
asig_comp_def
mueller@3078
   148
  "asig_comp a1 a2 ==                                                   
mueller@3078
   149
      (((inputs(a1) Un inputs(a2)) - (outputs(a1) Un outputs(a2)),      
mueller@3078
   150
        (outputs(a1) Un outputs(a2)),                                   
mueller@3078
   151
        (internals(a1) Un internals(a2))))"
mueller@3078
   152
mueller@3078
   153
mueller@3078
   154
par_def
mueller@3078
   155
  "(ioa1 || ioa2) ==                                                    
mueller@3078
   156
       (asig_comp (asig_of ioa1) (asig_of ioa2),                        
mueller@3078
   157
        {pr. fst(pr):starts_of(ioa1) & snd(pr):starts_of(ioa2)},        
mueller@3078
   158
        {tr. let s = fst(tr); a = fst(snd(tr)); t = snd(snd(tr))        
mueller@3078
   159
             in (a:actions(asig_of(ioa1)) | a:actions(asig_of(ioa2))) & 
mueller@3078
   160
                (if a:actions(asig_of(ioa1)) then                       
mueller@3078
   161
                   (fst(s),a,fst(t)):trans_of(ioa1)                     
mueller@3078
   162
                 else fst(t) = fst(s))                                  
mueller@3078
   163
                &                                                       
mueller@3078
   164
                (if a:actions(asig_of(ioa2)) then                       
mueller@3078
   165
                   (snd(s),a,snd(t)):trans_of(ioa2)                     
mueller@3078
   166
                 else snd(t) = snd(s))})"
mueller@3078
   167
mueller@3078
   168
mueller@3078
   169
restrict_asig_def
mueller@3078
   170
  "restrict_asig asig actns ==                                          
mueller@3078
   171
    (inputs(asig) Int actns, outputs(asig) Int actns,                  
mueller@3078
   172
     internals(asig) Un (externals(asig) - actns))"
mueller@3078
   173
mueller@3078
   174
mueller@3078
   175
restrict_def
mueller@3078
   176
  "restrict ioa actns ==                                               
mueller@3078
   177
    (restrict_asig (asig_of ioa) actns, starts_of(ioa), trans_of(ioa))"
mueller@3078
   178
mueller@3078
   179
mueller@3078
   180
ioa_implements_def
mueller@3078
   181
  "ioa_implements ioa1 ioa2 ==   
mueller@3078
   182
  ((inputs(asig_of(ioa1)) = inputs(asig_of(ioa2))) &   
mueller@3078
   183
     (outputs(asig_of(ioa1)) = outputs(asig_of(ioa2))) &   
mueller@3078
   184
      traces(ioa1) <= traces(ioa2))"
mueller@3078
   185
 
mueller@3078
   186
rename_def 
mueller@3078
   187
"rename ioa ren ==  
mueller@3078
   188
  (({b. ? x. Some(x)= ren(b) & x : inputs(asig_of(ioa))},         
mueller@3078
   189
    {b. ? x. Some(x)= ren(b) & x : outputs(asig_of(ioa))},        
mueller@3078
   190
    {b. ? x. Some(x)= ren(b) & x : internals(asig_of(ioa))}),     
mueller@3078
   191
              starts_of(ioa)   ,                                            
mueller@3078
   192
   {tr. let s = fst(tr); a = fst(snd(tr));  t = snd(snd(tr))    
mueller@3078
   193
        in                                                      
mueller@3078
   194
        ? x. Some(x) = ren(a) & (s,x,t):trans_of(ioa)})"
mueller@3078
   195
mueller@3078
   196
end