src/HOL/UNITY/Union.thy
author haftmann
Sat Mar 22 08:37:43 2014 +0100 (2014-03-22)
changeset 56248 67dc9549fa15
parent 46577 e5438c5797ae
child 58889 5b7a9633cfa8
permissions -rw-r--r--
generalized and strengthened cong rules on compound operators, similar to 1ed737a98198
paulson@5252
     1
(*  Title:      HOL/UNITY/Union.thy
paulson@5252
     2
    Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
paulson@5252
     3
    Copyright   1998  University of Cambridge
paulson@5252
     4
wenzelm@32960
     5
Partly from Misra's Chapter 5: Asynchronous Compositions of Programs.
paulson@5252
     6
*)
paulson@5252
     7
paulson@13798
     8
header{*Unions of Programs*}
paulson@13798
     9
haftmann@16417
    10
theory Union imports SubstAx FP begin
paulson@5252
    11
paulson@13805
    12
  (*FIXME: conjoin Init F \<inter> Init G \<noteq> {} *) 
wenzelm@36866
    13
definition
paulson@13792
    14
  ok :: "['a program, 'a program] => bool"      (infixl "ok" 65)
wenzelm@36866
    15
  where "F ok G == Acts F \<subseteq> AllowedActs G &
paulson@13805
    16
               Acts G \<subseteq> AllowedActs F"
paulson@10064
    17
paulson@13805
    18
  (*FIXME: conjoin (\<Inter>i \<in> I. Init (F i)) \<noteq> {} *) 
wenzelm@36866
    19
definition
paulson@13792
    20
  OK  :: "['a set, 'a => 'b program] => bool"
wenzelm@36866
    21
  where "OK I F = (\<forall>i \<in> I. \<forall>j \<in> I-{i}. Acts (F i) \<subseteq> AllowedActs (F j))"
paulson@10064
    22
wenzelm@36866
    23
definition
paulson@13792
    24
  JOIN  :: "['a set, 'a => 'b program] => 'b program"
wenzelm@36866
    25
  where "JOIN I F = mk_program (\<Inter>i \<in> I. Init (F i), \<Union>i \<in> I. Acts (F i),
wenzelm@32960
    26
                             \<Inter>i \<in> I. AllowedActs (F i))"
paulson@5252
    27
wenzelm@36866
    28
definition
paulson@13792
    29
  Join :: "['a program, 'a program] => 'a program"      (infixl "Join" 65)
wenzelm@36866
    30
  where "F Join G = mk_program (Init F \<inter> Init G, Acts F \<union> Acts G,
wenzelm@32960
    31
                             AllowedActs F \<inter> AllowedActs G)"
paulson@5252
    32
wenzelm@36866
    33
definition
paulson@13792
    34
  SKIP :: "'a program"
wenzelm@36866
    35
  where "SKIP = mk_program (UNIV, {}, UNIV)"
paulson@10064
    36
paulson@13812
    37
  (*Characterizes safety properties.  Used with specifying Allowed*)
wenzelm@36866
    38
definition
paulson@10064
    39
  safety_prop :: "'a program set => bool"
wenzelm@36866
    40
  where "safety_prop X <-> SKIP: X & (\<forall>G. Acts G \<subseteq> UNION X Acts --> G \<in> X)"
paulson@5259
    41
wenzelm@35434
    42
notation (xsymbols)
wenzelm@35427
    43
  SKIP  ("\<bottom>") and
wenzelm@35427
    44
  Join  (infixl "\<squnion>" 65)
wenzelm@35427
    45
paulson@5313
    46
syntax
wenzelm@35054
    47
  "_JOIN1"     :: "[pttrns, 'b set] => 'b set"         ("(3JN _./ _)" 10)
wenzelm@35054
    48
  "_JOIN"      :: "[pttrn, 'a set, 'b set] => 'b set"  ("(3JN _:_./ _)" 10)
wenzelm@35427
    49
syntax (xsymbols)
wenzelm@35427
    50
  "_JOIN1" :: "[pttrns, 'b set] => 'b set"              ("(3\<Squnion> _./ _)" 10)
wenzelm@35427
    51
  "_JOIN"  :: "[pttrn, 'a set, 'b set] => 'b set"       ("(3\<Squnion> _\<in>_./ _)" 10)
paulson@5313
    52
paulson@5313
    53
translations
wenzelm@35054
    54
  "JN x: A. B" == "CONST JOIN A (%x. B)"
wenzelm@35054
    55
  "JN x y. B" == "JN x. JN y. B"
wenzelm@35068
    56
  "JN x. B" == "CONST JOIN (CONST UNIV) (%x. B)"
paulson@5313
    57
paulson@13792
    58
paulson@13798
    59
subsection{*SKIP*}
paulson@13792
    60
paulson@13792
    61
lemma Init_SKIP [simp]: "Init SKIP = UNIV"
paulson@13792
    62
by (simp add: SKIP_def)
paulson@13792
    63
paulson@13792
    64
lemma Acts_SKIP [simp]: "Acts SKIP = {Id}"
paulson@13792
    65
by (simp add: SKIP_def)
paulson@13792
    66
paulson@13792
    67
lemma AllowedActs_SKIP [simp]: "AllowedActs SKIP = UNIV"
paulson@13792
    68
by (auto simp add: SKIP_def)
paulson@13792
    69
paulson@13792
    70
lemma reachable_SKIP [simp]: "reachable SKIP = UNIV"
paulson@13792
    71
by (force elim: reachable.induct intro: reachable.intros)
paulson@13792
    72
paulson@13798
    73
subsection{*SKIP and safety properties*}
paulson@13792
    74
paulson@13805
    75
lemma SKIP_in_constrains_iff [iff]: "(SKIP \<in> A co B) = (A \<subseteq> B)"
paulson@13792
    76
by (unfold constrains_def, auto)
paulson@13792
    77
paulson@13805
    78
lemma SKIP_in_Constrains_iff [iff]: "(SKIP \<in> A Co B) = (A \<subseteq> B)"
paulson@13792
    79
by (unfold Constrains_def, auto)
paulson@13792
    80
paulson@13805
    81
lemma SKIP_in_stable [iff]: "SKIP \<in> stable A"
paulson@13792
    82
by (unfold stable_def, auto)
paulson@13792
    83
paulson@13792
    84
declare SKIP_in_stable [THEN stable_imp_Stable, iff]
paulson@13792
    85
paulson@13792
    86
paulson@13798
    87
subsection{*Join*}
paulson@13792
    88
paulson@13819
    89
lemma Init_Join [simp]: "Init (F\<squnion>G) = Init F \<inter> Init G"
paulson@13792
    90
by (simp add: Join_def)
paulson@13792
    91
paulson@13819
    92
lemma Acts_Join [simp]: "Acts (F\<squnion>G) = Acts F \<union> Acts G"
paulson@13792
    93
by (auto simp add: Join_def)
paulson@13792
    94
paulson@13792
    95
lemma AllowedActs_Join [simp]:
paulson@13819
    96
     "AllowedActs (F\<squnion>G) = AllowedActs F \<inter> AllowedActs G"
paulson@13792
    97
by (auto simp add: Join_def)
paulson@13792
    98
paulson@13792
    99
paulson@13798
   100
subsection{*JN*}
paulson@13792
   101
paulson@13805
   102
lemma JN_empty [simp]: "(\<Squnion>i\<in>{}. F i) = SKIP"
paulson@13792
   103
by (unfold JOIN_def SKIP_def, auto)
paulson@13792
   104
paulson@13819
   105
lemma JN_insert [simp]: "(\<Squnion>i \<in> insert a I. F i) = (F a)\<squnion>(\<Squnion>i \<in> I. F i)"
paulson@13792
   106
apply (rule program_equalityI)
paulson@13792
   107
apply (auto simp add: JOIN_def Join_def)
paulson@13792
   108
done
paulson@13792
   109
paulson@13805
   110
lemma Init_JN [simp]: "Init (\<Squnion>i \<in> I. F i) = (\<Inter>i \<in> I. Init (F i))"
paulson@13792
   111
by (simp add: JOIN_def)
paulson@13792
   112
paulson@13805
   113
lemma Acts_JN [simp]: "Acts (\<Squnion>i \<in> I. F i) = insert Id (\<Union>i \<in> I. Acts (F i))"
paulson@13792
   114
by (auto simp add: JOIN_def)
paulson@13792
   115
paulson@13792
   116
lemma AllowedActs_JN [simp]:
paulson@13805
   117
     "AllowedActs (\<Squnion>i \<in> I. F i) = (\<Inter>i \<in> I. AllowedActs (F i))"
paulson@13792
   118
by (auto simp add: JOIN_def)
paulson@13792
   119
paulson@13792
   120
paulson@13792
   121
lemma JN_cong [cong]: 
paulson@13805
   122
    "[| I=J;  !!i. i \<in> J ==> F i = G i |] ==> (\<Squnion>i \<in> I. F i) = (\<Squnion>i \<in> J. G i)"
paulson@13792
   123
by (simp add: JOIN_def)
paulson@13792
   124
paulson@13792
   125
paulson@13798
   126
subsection{*Algebraic laws*}
paulson@13792
   127
paulson@13819
   128
lemma Join_commute: "F\<squnion>G = G\<squnion>F"
paulson@13792
   129
by (simp add: Join_def Un_commute Int_commute)
paulson@13792
   130
paulson@13819
   131
lemma Join_assoc: "(F\<squnion>G)\<squnion>H = F\<squnion>(G\<squnion>H)"
paulson@13792
   132
by (simp add: Un_ac Join_def Int_assoc insert_absorb)
paulson@13792
   133
 
paulson@13819
   134
lemma Join_left_commute: "A\<squnion>(B\<squnion>C) = B\<squnion>(A\<squnion>C)"
paulson@13792
   135
by (simp add: Un_ac Int_ac Join_def insert_absorb)
paulson@13792
   136
paulson@13819
   137
lemma Join_SKIP_left [simp]: "SKIP\<squnion>F = F"
paulson@13792
   138
apply (unfold Join_def SKIP_def)
paulson@13792
   139
apply (rule program_equalityI)
paulson@13792
   140
apply (simp_all (no_asm) add: insert_absorb)
paulson@13792
   141
done
paulson@13792
   142
paulson@13819
   143
lemma Join_SKIP_right [simp]: "F\<squnion>SKIP = F"
paulson@13792
   144
apply (unfold Join_def SKIP_def)
paulson@13792
   145
apply (rule program_equalityI)
paulson@13792
   146
apply (simp_all (no_asm) add: insert_absorb)
paulson@13792
   147
done
paulson@13792
   148
paulson@13819
   149
lemma Join_absorb [simp]: "F\<squnion>F = F"
paulson@13792
   150
apply (unfold Join_def)
paulson@13792
   151
apply (rule program_equalityI, auto)
paulson@13792
   152
done
paulson@13792
   153
paulson@13819
   154
lemma Join_left_absorb: "F\<squnion>(F\<squnion>G) = F\<squnion>G"
paulson@13792
   155
apply (unfold Join_def)
paulson@13792
   156
apply (rule program_equalityI, auto)
paulson@13792
   157
done
paulson@13792
   158
paulson@13792
   159
(*Join is an AC-operator*)
paulson@13792
   160
lemmas Join_ac = Join_assoc Join_left_absorb Join_commute Join_left_commute
paulson@13792
   161
paulson@13792
   162
paulson@14150
   163
subsection{*Laws Governing @{text "\<Squnion>"}*}
paulson@13792
   164
paulson@13792
   165
(*Also follows by JN_insert and insert_absorb, but the proof is longer*)
paulson@13819
   166
lemma JN_absorb: "k \<in> I ==> F k\<squnion>(\<Squnion>i \<in> I. F i) = (\<Squnion>i \<in> I. F i)"
paulson@13792
   167
by (auto intro!: program_equalityI)
paulson@13792
   168
paulson@13819
   169
lemma JN_Un: "(\<Squnion>i \<in> I \<union> J. F i) = ((\<Squnion>i \<in> I. F i)\<squnion>(\<Squnion>i \<in> J. F i))"
paulson@13792
   170
by (auto intro!: program_equalityI)
paulson@13792
   171
paulson@13805
   172
lemma JN_constant: "(\<Squnion>i \<in> I. c) = (if I={} then SKIP else c)"
paulson@13792
   173
by (rule program_equalityI, auto)
paulson@13792
   174
paulson@13792
   175
lemma JN_Join_distrib:
paulson@13819
   176
     "(\<Squnion>i \<in> I. F i\<squnion>G i) = (\<Squnion>i \<in> I. F i) \<squnion> (\<Squnion>i \<in> I. G i)"
paulson@13792
   177
by (auto intro!: program_equalityI)
paulson@13792
   178
paulson@13792
   179
lemma JN_Join_miniscope:
paulson@13819
   180
     "i \<in> I ==> (\<Squnion>i \<in> I. F i\<squnion>G) = ((\<Squnion>i \<in> I. F i)\<squnion>G)"
paulson@13792
   181
by (auto simp add: JN_Join_distrib JN_constant)
paulson@13792
   182
paulson@13792
   183
(*Used to prove guarantees_JN_I*)
paulson@13819
   184
lemma JN_Join_diff: "i \<in> I ==> F i\<squnion>JOIN (I - {i}) F = JOIN I F"
paulson@13792
   185
apply (unfold JOIN_def Join_def)
paulson@13792
   186
apply (rule program_equalityI, auto)
paulson@13792
   187
done
paulson@13792
   188
paulson@13792
   189
paulson@13798
   190
subsection{*Safety: co, stable, FP*}
paulson@13792
   191
paulson@13805
   192
(*Fails if I={} because it collapses to SKIP \<in> A co B, i.e. to A \<subseteq> B.  So an
paulson@13805
   193
  alternative precondition is A \<subseteq> B, but most proofs using this rule require
paulson@13792
   194
  I to be nonempty for other reasons anyway.*)
paulson@13792
   195
lemma JN_constrains: 
paulson@13805
   196
    "i \<in> I ==> (\<Squnion>i \<in> I. F i) \<in> A co B = (\<forall>i \<in> I. F i \<in> A co B)"
paulson@13792
   197
by (simp add: constrains_def JOIN_def, blast)
paulson@13792
   198
paulson@13792
   199
lemma Join_constrains [simp]:
paulson@13819
   200
     "(F\<squnion>G \<in> A co B) = (F \<in> A co B & G \<in> A co B)"
paulson@13792
   201
by (auto simp add: constrains_def Join_def)
paulson@13792
   202
paulson@13792
   203
lemma Join_unless [simp]:
paulson@13819
   204
     "(F\<squnion>G \<in> A unless B) = (F \<in> A unless B & G \<in> A unless B)"
wenzelm@46577
   205
by (simp add: unless_def)
paulson@13792
   206
paulson@13792
   207
(*Analogous weak versions FAIL; see Misra [1994] 5.4.1, Substitution Axiom.
paulson@13819
   208
  reachable (F\<squnion>G) could be much bigger than reachable F, reachable G
paulson@13792
   209
*)
paulson@13792
   210
paulson@13792
   211
paulson@13792
   212
lemma Join_constrains_weaken:
paulson@13805
   213
     "[| F \<in> A co A';  G \<in> B co B' |]  
paulson@13819
   214
      ==> F\<squnion>G \<in> (A \<inter> B) co (A' \<union> B')"
paulson@13792
   215
by (simp, blast intro: constrains_weaken)
paulson@13792
   216
paulson@13805
   217
(*If I={}, it degenerates to SKIP \<in> UNIV co {}, which is false.*)
paulson@13792
   218
lemma JN_constrains_weaken:
paulson@13805
   219
     "[| \<forall>i \<in> I. F i \<in> A i co A' i;  i \<in> I |]  
paulson@13805
   220
      ==> (\<Squnion>i \<in> I. F i) \<in> (\<Inter>i \<in> I. A i) co (\<Union>i \<in> I. A' i)"
paulson@13792
   221
apply (simp (no_asm_simp) add: JN_constrains)
paulson@13792
   222
apply (blast intro: constrains_weaken)
paulson@13792
   223
done
paulson@13792
   224
paulson@13805
   225
lemma JN_stable: "(\<Squnion>i \<in> I. F i) \<in> stable A = (\<forall>i \<in> I. F i \<in> stable A)"
paulson@13792
   226
by (simp add: stable_def constrains_def JOIN_def)
paulson@13792
   227
paulson@13792
   228
lemma invariant_JN_I:
paulson@13805
   229
     "[| !!i. i \<in> I ==> F i \<in> invariant A;  i \<in> I |]   
paulson@13805
   230
       ==> (\<Squnion>i \<in> I. F i) \<in> invariant A"
paulson@13792
   231
by (simp add: invariant_def JN_stable, blast)
paulson@13792
   232
paulson@13792
   233
lemma Join_stable [simp]:
paulson@13819
   234
     "(F\<squnion>G \<in> stable A) =  
paulson@13805
   235
      (F \<in> stable A & G \<in> stable A)"
paulson@13792
   236
by (simp add: stable_def)
paulson@13792
   237
paulson@13792
   238
lemma Join_increasing [simp]:
paulson@13819
   239
     "(F\<squnion>G \<in> increasing f) =  
paulson@13805
   240
      (F \<in> increasing f & G \<in> increasing f)"
wenzelm@46577
   241
by (auto simp add: increasing_def)
paulson@13792
   242
paulson@13792
   243
lemma invariant_JoinI:
paulson@13805
   244
     "[| F \<in> invariant A; G \<in> invariant A |]   
paulson@13819
   245
      ==> F\<squnion>G \<in> invariant A"
wenzelm@46577
   246
by (auto simp add: invariant_def)
paulson@13792
   247
paulson@13805
   248
lemma FP_JN: "FP (\<Squnion>i \<in> I. F i) = (\<Inter>i \<in> I. FP (F i))"
hoelzl@44928
   249
by (simp add: FP_def JN_stable INTER_eq)
paulson@13792
   250
paulson@13792
   251
paulson@13798
   252
subsection{*Progress: transient, ensures*}
paulson@13792
   253
paulson@13792
   254
lemma JN_transient:
paulson@13805
   255
     "i \<in> I ==>  
paulson@13805
   256
    (\<Squnion>i \<in> I. F i) \<in> transient A = (\<exists>i \<in> I. F i \<in> transient A)"
paulson@13792
   257
by (auto simp add: transient_def JOIN_def)
paulson@13792
   258
paulson@13792
   259
lemma Join_transient [simp]:
paulson@13819
   260
     "F\<squnion>G \<in> transient A =  
paulson@13805
   261
      (F \<in> transient A | G \<in> transient A)"
paulson@13792
   262
by (auto simp add: bex_Un transient_def Join_def)
paulson@13792
   263
paulson@13819
   264
lemma Join_transient_I1: "F \<in> transient A ==> F\<squnion>G \<in> transient A"
wenzelm@46577
   265
by simp
paulson@13792
   266
paulson@13819
   267
lemma Join_transient_I2: "G \<in> transient A ==> F\<squnion>G \<in> transient A"
wenzelm@46577
   268
by simp
paulson@13792
   269
paulson@13805
   270
(*If I={} it degenerates to (SKIP \<in> A ensures B) = False, i.e. to ~(A \<subseteq> B) *)
paulson@13792
   271
lemma JN_ensures:
paulson@13805
   272
     "i \<in> I ==>  
paulson@13805
   273
      (\<Squnion>i \<in> I. F i) \<in> A ensures B =  
paulson@13805
   274
      ((\<forall>i \<in> I. F i \<in> (A-B) co (A \<union> B)) & (\<exists>i \<in> I. F i \<in> A ensures B))"
paulson@13792
   275
by (auto simp add: ensures_def JN_constrains JN_transient)
paulson@13792
   276
paulson@13792
   277
lemma Join_ensures: 
paulson@13819
   278
     "F\<squnion>G \<in> A ensures B =      
paulson@13805
   279
      (F \<in> (A-B) co (A \<union> B) & G \<in> (A-B) co (A \<union> B) &  
paulson@13805
   280
       (F \<in> transient (A-B) | G \<in> transient (A-B)))"
wenzelm@46577
   281
by (auto simp add: ensures_def)
paulson@13792
   282
paulson@13792
   283
lemma stable_Join_constrains: 
paulson@13805
   284
    "[| F \<in> stable A;  G \<in> A co A' |]  
paulson@13819
   285
     ==> F\<squnion>G \<in> A co A'"
paulson@13792
   286
apply (unfold stable_def constrains_def Join_def)
paulson@13792
   287
apply (simp add: ball_Un, blast)
paulson@13792
   288
done
paulson@13792
   289
paulson@13805
   290
(*Premise for G cannot use Always because  F \<in> Stable A  is weaker than
paulson@13805
   291
  G \<in> stable A *)
paulson@13792
   292
lemma stable_Join_Always1:
paulson@13819
   293
     "[| F \<in> stable A;  G \<in> invariant A |] ==> F\<squnion>G \<in> Always A"
paulson@13792
   294
apply (simp (no_asm_use) add: Always_def invariant_def Stable_eq_stable)
paulson@13792
   295
apply (force intro: stable_Int)
paulson@13792
   296
done
paulson@13792
   297
paulson@13792
   298
(*As above, but exchanging the roles of F and G*)
paulson@13792
   299
lemma stable_Join_Always2:
paulson@13819
   300
     "[| F \<in> invariant A;  G \<in> stable A |] ==> F\<squnion>G \<in> Always A"
paulson@13792
   301
apply (subst Join_commute)
paulson@13792
   302
apply (blast intro: stable_Join_Always1)
paulson@13792
   303
done
paulson@13792
   304
paulson@13792
   305
lemma stable_Join_ensures1:
paulson@13819
   306
     "[| F \<in> stable A;  G \<in> A ensures B |] ==> F\<squnion>G \<in> A ensures B"
paulson@13792
   307
apply (simp (no_asm_simp) add: Join_ensures)
paulson@13792
   308
apply (simp add: stable_def ensures_def)
paulson@13792
   309
apply (erule constrains_weaken, auto)
paulson@13792
   310
done
paulson@13792
   311
paulson@13792
   312
(*As above, but exchanging the roles of F and G*)
paulson@13792
   313
lemma stable_Join_ensures2:
paulson@13819
   314
     "[| F \<in> A ensures B;  G \<in> stable A |] ==> F\<squnion>G \<in> A ensures B"
paulson@13792
   315
apply (subst Join_commute)
paulson@13792
   316
apply (blast intro: stable_Join_ensures1)
paulson@13792
   317
done
paulson@13792
   318
paulson@13792
   319
paulson@13798
   320
subsection{*the ok and OK relations*}
paulson@13792
   321
paulson@13792
   322
lemma ok_SKIP1 [iff]: "SKIP ok F"
paulson@13812
   323
by (simp add: ok_def)
paulson@13792
   324
paulson@13792
   325
lemma ok_SKIP2 [iff]: "F ok SKIP"
paulson@13812
   326
by (simp add: ok_def)
paulson@13792
   327
paulson@13792
   328
lemma ok_Join_commute:
paulson@13819
   329
     "(F ok G & (F\<squnion>G) ok H) = (G ok H & F ok (G\<squnion>H))"
paulson@13792
   330
by (auto simp add: ok_def)
paulson@13792
   331
paulson@13792
   332
lemma ok_commute: "(F ok G) = (G ok F)"
paulson@13792
   333
by (auto simp add: ok_def)
paulson@13792
   334
wenzelm@45605
   335
lemmas ok_sym = ok_commute [THEN iffD1]
paulson@13792
   336
paulson@13792
   337
lemma ok_iff_OK:
paulson@13819
   338
     "OK {(0::int,F),(1,G),(2,H)} snd = (F ok G & (F\<squnion>G) ok H)"
wenzelm@16977
   339
apply (simp add: Ball_def conj_disj_distribR ok_def Join_def OK_def insert_absorb
wenzelm@16977
   340
              all_conj_distrib)
wenzelm@16977
   341
apply blast
wenzelm@16977
   342
done
paulson@13792
   343
paulson@13819
   344
lemma ok_Join_iff1 [iff]: "F ok (G\<squnion>H) = (F ok G & F ok H)"
paulson@13792
   345
by (auto simp add: ok_def)
paulson@13792
   346
paulson@13819
   347
lemma ok_Join_iff2 [iff]: "(G\<squnion>H) ok F = (G ok F & H ok F)"
paulson@13792
   348
by (auto simp add: ok_def)
paulson@13792
   349
paulson@13792
   350
(*useful?  Not with the previous two around*)
paulson@13819
   351
lemma ok_Join_commute_I: "[| F ok G; (F\<squnion>G) ok H |] ==> F ok (G\<squnion>H)"
paulson@13792
   352
by (auto simp add: ok_def)
paulson@13792
   353
paulson@13805
   354
lemma ok_JN_iff1 [iff]: "F ok (JOIN I G) = (\<forall>i \<in> I. F ok G i)"
paulson@13792
   355
by (auto simp add: ok_def)
paulson@13792
   356
paulson@13805
   357
lemma ok_JN_iff2 [iff]: "(JOIN I G) ok F =  (\<forall>i \<in> I. G i ok F)"
paulson@13792
   358
by (auto simp add: ok_def)
paulson@13792
   359
paulson@13805
   360
lemma OK_iff_ok: "OK I F = (\<forall>i \<in> I. \<forall>j \<in> I-{i}. (F i) ok (F j))"
paulson@13792
   361
by (auto simp add: ok_def OK_def)
paulson@13792
   362
paulson@13805
   363
lemma OK_imp_ok: "[| OK I F; i \<in> I; j \<in> I; i \<noteq> j|] ==> (F i) ok (F j)"
paulson@13792
   364
by (auto simp add: OK_iff_ok)
paulson@13792
   365
paulson@13792
   366
paulson@13798
   367
subsection{*Allowed*}
paulson@13792
   368
paulson@13792
   369
lemma Allowed_SKIP [simp]: "Allowed SKIP = UNIV"
paulson@13792
   370
by (auto simp add: Allowed_def)
paulson@13792
   371
paulson@13819
   372
lemma Allowed_Join [simp]: "Allowed (F\<squnion>G) = Allowed F \<inter> Allowed G"
paulson@13792
   373
by (auto simp add: Allowed_def)
paulson@13792
   374
paulson@13805
   375
lemma Allowed_JN [simp]: "Allowed (JOIN I F) = (\<Inter>i \<in> I. Allowed (F i))"
paulson@13792
   376
by (auto simp add: Allowed_def)
paulson@13792
   377
paulson@13805
   378
lemma ok_iff_Allowed: "F ok G = (F \<in> Allowed G & G \<in> Allowed F)"
paulson@13792
   379
by (simp add: ok_def Allowed_def)
paulson@13792
   380
paulson@13805
   381
lemma OK_iff_Allowed: "OK I F = (\<forall>i \<in> I. \<forall>j \<in> I-{i}. F i \<in> Allowed(F j))"
paulson@13792
   382
by (auto simp add: OK_iff_ok ok_iff_Allowed)
paulson@13792
   383
paulson@13812
   384
subsection{*@{term safety_prop}, for reasoning about
paulson@13798
   385
 given instances of "ok"*}
paulson@13792
   386
paulson@13792
   387
lemma safety_prop_Acts_iff:
paulson@13805
   388
     "safety_prop X ==> (Acts G \<subseteq> insert Id (UNION X Acts)) = (G \<in> X)"
paulson@13792
   389
by (auto simp add: safety_prop_def)
paulson@13792
   390
paulson@13792
   391
lemma safety_prop_AllowedActs_iff_Allowed:
paulson@13805
   392
     "safety_prop X ==> (UNION X Acts \<subseteq> AllowedActs F) = (X \<subseteq> Allowed F)"
paulson@13792
   393
by (auto simp add: Allowed_def safety_prop_Acts_iff [symmetric])
paulson@13792
   394
paulson@13792
   395
lemma Allowed_eq:
paulson@13792
   396
     "safety_prop X ==> Allowed (mk_program (init, acts, UNION X Acts)) = X"
paulson@13792
   397
by (simp add: Allowed_def safety_prop_Acts_iff)
paulson@13792
   398
paulson@13792
   399
(*For safety_prop to hold, the property must be satisfiable!*)
paulson@13805
   400
lemma safety_prop_constrains [iff]: "safety_prop (A co B) = (A \<subseteq> B)"
paulson@13792
   401
by (simp add: safety_prop_def constrains_def, blast)
paulson@13792
   402
paulson@13792
   403
lemma safety_prop_stable [iff]: "safety_prop (stable A)"
paulson@13792
   404
by (simp add: stable_def)
paulson@13792
   405
paulson@13792
   406
lemma safety_prop_Int [simp]:
haftmann@56248
   407
  "safety_prop X \<Longrightarrow> safety_prop Y \<Longrightarrow> safety_prop (X \<inter> Y)"
haftmann@56248
   408
  by (simp add: safety_prop_def) blast
haftmann@56248
   409
haftmann@56248
   410
lemma safety_prop_INTER [simp]:
haftmann@56248
   411
  "(\<And>i. i \<in> I \<Longrightarrow> safety_prop (X i)) \<Longrightarrow> safety_prop (\<Inter>i\<in>I. X i)"
haftmann@56248
   412
  by (simp add: safety_prop_def) blast
paulson@13792
   413
paulson@13792
   414
lemma safety_prop_INTER1 [simp]:
haftmann@56248
   415
  "(\<And>i. safety_prop (X i)) \<Longrightarrow> safety_prop (\<Inter>i. X i)"
haftmann@56248
   416
  by (rule safety_prop_INTER) simp
paulson@13792
   417
paulson@13812
   418
lemma def_prg_Allowed:
paulson@13812
   419
     "[| F == mk_program (init, acts, UNION X Acts) ; safety_prop X |]  
paulson@13812
   420
      ==> Allowed F = X"
paulson@13812
   421
by (simp add: Allowed_eq)
paulson@13812
   422
paulson@13812
   423
lemma Allowed_totalize [simp]: "Allowed (totalize F) = Allowed F"
paulson@13812
   424
by (simp add: Allowed_def) 
paulson@13812
   425
paulson@13812
   426
lemma def_total_prg_Allowed:
wenzelm@36866
   427
     "[| F = mk_total_program (init, acts, UNION X Acts) ; safety_prop X |]  
paulson@13812
   428
      ==> Allowed F = X"
paulson@13812
   429
by (simp add: mk_total_program_def def_prg_Allowed) 
paulson@13812
   430
paulson@13792
   431
lemma def_UNION_ok_iff:
wenzelm@36866
   432
     "[| F = mk_program(init,acts,UNION X Acts); safety_prop X |]  
paulson@13805
   433
      ==> F ok G = (G \<in> X & acts \<subseteq> AllowedActs G)"
paulson@13792
   434
by (auto simp add: ok_def safety_prop_Acts_iff)
paulson@9685
   435
paulson@13812
   436
text{*The union of two total programs is total.*}
paulson@13819
   437
lemma totalize_Join: "totalize F\<squnion>totalize G = totalize (F\<squnion>G)"
paulson@13812
   438
by (simp add: program_equalityI totalize_def Join_def image_Un)
paulson@13812
   439
paulson@13819
   440
lemma all_total_Join: "[|all_total F; all_total G|] ==> all_total (F\<squnion>G)"
paulson@13812
   441
by (simp add: all_total_def, blast)
paulson@13812
   442
paulson@13812
   443
lemma totalize_JN: "(\<Squnion>i \<in> I. totalize (F i)) = totalize(\<Squnion>i \<in> I. F i)"
paulson@13812
   444
by (simp add: program_equalityI totalize_def JOIN_def image_UN)
paulson@13812
   445
paulson@13812
   446
lemma all_total_JN: "(!!i. i\<in>I ==> all_total (F i)) ==> all_total(\<Squnion>i\<in>I. F i)"
paulson@13812
   447
by (simp add: all_total_iff_totalize totalize_JN [symmetric])
paulson@13812
   448
paulson@5252
   449
end