src/ZF/UNITY/Constrains.thy
author wenzelm
Thu Jul 02 17:34:14 2009 +0200 (2009-07-02)
changeset 31902 862ae16a799d
parent 30549 d2d7874648bd
child 32149 ef59550a55d3
permissions -rw-r--r--
renamed NamedThmsFun to Named_Thms;
simplified/unified names of instances of Named_Thms;
paulson@15634
     1
(*  ID:         $Id$
paulson@11479
     2
    Author:     Sidi O Ehmety, Computer Laboratory
paulson@11479
     3
    Copyright   2001  University of Cambridge
paulson@11479
     4
*)
paulson@11479
     5
paulson@15634
     6
header{*Weak Safety Properties*}
paulson@15634
     7
paulson@15634
     8
theory Constrains
paulson@15634
     9
imports UNITY
wenzelm@24893
    10
begin
paulson@15634
    11
paulson@11479
    12
consts traces :: "[i, i] => i"
paulson@11479
    13
  (* Initial states and program => (final state, reversed trace to it)... 
ehmety@12195
    14
      the domain may also be state*list(state) *)
paulson@11479
    15
inductive 
paulson@11479
    16
  domains 
paulson@11479
    17
     "traces(init, acts)" <=
paulson@11479
    18
         "(init Un (UN act:acts. field(act)))*list(UN act:acts. field(act))"
paulson@15634
    19
  intros 
paulson@11479
    20
         (*Initial trace is empty*)
paulson@15634
    21
    Init: "s: init ==> <s,[]> : traces(init,acts)"
paulson@11479
    22
paulson@15634
    23
    Acts: "[| act:acts;  <s,evs> : traces(init,acts);  <s,s'>: act |]
paulson@11479
    24
           ==> <s', Cons(s,evs)> : traces(init, acts)"
paulson@11479
    25
  
paulson@15634
    26
  type_intros list.intros UnI1 UnI2 UN_I fieldI2 fieldI1
paulson@11479
    27
paulson@11479
    28
paulson@15634
    29
consts reachable :: "i=>i"
paulson@11479
    30
inductive
paulson@11479
    31
  domains
paulson@11479
    32
  "reachable(F)" <= "Init(F) Un (UN act:Acts(F). field(act))"
paulson@15634
    33
  intros 
paulson@15634
    34
    Init: "s:Init(F) ==> s:reachable(F)"
paulson@11479
    35
paulson@15634
    36
    Acts: "[| act: Acts(F);  s:reachable(F);  <s,s'>: act |]
paulson@11479
    37
           ==> s':reachable(F)"
paulson@11479
    38
paulson@15634
    39
  type_intros UnI1 UnI2 fieldI2 UN_I
paulson@11479
    40
paulson@11479
    41
  
wenzelm@24893
    42
definition
wenzelm@24893
    43
  Constrains :: "[i,i] => i"  (infixl "Co" 60)  where
wenzelm@24893
    44
  "A Co B == {F:program. F:(reachable(F) Int A) co B}"
paulson@11479
    45
wenzelm@24893
    46
definition
wenzelm@24893
    47
  op_Unless  :: "[i, i] => i"  (infixl "Unless" 60)  where
wenzelm@24893
    48
  "A Unless B == (A-B) Co (A Un B)"
paulson@11479
    49
wenzelm@24893
    50
definition
wenzelm@24893
    51
  Stable     :: "i => i"  where
wenzelm@24893
    52
  "Stable(A) == A Co A"
paulson@11479
    53
wenzelm@24893
    54
definition
paulson@11479
    55
  (*Always is the weak form of "invariant"*)
wenzelm@24893
    56
  Always :: "i => i"  where
wenzelm@24893
    57
  "Always(A) == initially(A) Int Stable(A)"
paulson@11479
    58
paulson@15634
    59
paulson@15634
    60
(*** traces and reachable ***)
paulson@15634
    61
paulson@15634
    62
lemma reachable_type: "reachable(F) <= state"
paulson@15634
    63
apply (cut_tac F = F in Init_type)
paulson@15634
    64
apply (cut_tac F = F in Acts_type)
paulson@15634
    65
apply (cut_tac F = F in reachable.dom_subset, blast)
paulson@15634
    66
done
paulson@15634
    67
paulson@15634
    68
lemma st_set_reachable: "st_set(reachable(F))"
paulson@15634
    69
apply (unfold st_set_def)
paulson@15634
    70
apply (rule reachable_type)
paulson@15634
    71
done
paulson@15634
    72
declare st_set_reachable [iff]
paulson@15634
    73
paulson@15634
    74
lemma reachable_Int_state: "reachable(F) Int state = reachable(F)"
paulson@15634
    75
by (cut_tac reachable_type, auto)
paulson@15634
    76
declare reachable_Int_state [iff]
paulson@15634
    77
paulson@15634
    78
lemma state_Int_reachable: "state Int reachable(F) = reachable(F)"
paulson@15634
    79
by (cut_tac reachable_type, auto)
paulson@15634
    80
declare state_Int_reachable [iff]
paulson@15634
    81
paulson@15634
    82
lemma reachable_equiv_traces: 
paulson@15634
    83
"F \<in> program ==> reachable(F)={s \<in> state. \<exists>evs. <s,evs>:traces(Init(F), Acts(F))}"
paulson@15634
    84
apply (rule equalityI, safe)
paulson@15634
    85
apply (blast dest: reachable_type [THEN subsetD])
paulson@15634
    86
apply (erule_tac [2] traces.induct)
paulson@15634
    87
apply (erule reachable.induct)
paulson@15634
    88
apply (blast intro: reachable.intros traces.intros)+
paulson@15634
    89
done
paulson@15634
    90
paulson@15634
    91
lemma Init_into_reachable: "Init(F) <= reachable(F)"
paulson@15634
    92
by (blast intro: reachable.intros)
paulson@15634
    93
paulson@15634
    94
lemma stable_reachable: "[| F \<in> program; G \<in> program;  
paulson@15634
    95
    Acts(G) <= Acts(F)  |] ==> G \<in> stable(reachable(F))"
paulson@15634
    96
apply (blast intro: stableI constrainsI st_setI
paulson@15634
    97
             reachable_type [THEN subsetD] reachable.intros)
paulson@15634
    98
done
paulson@15634
    99
paulson@15634
   100
declare stable_reachable [intro!]
paulson@15634
   101
declare stable_reachable [simp]
paulson@15634
   102
paulson@15634
   103
(*The set of all reachable states is an invariant...*)
paulson@15634
   104
lemma invariant_reachable: 
paulson@15634
   105
   "F \<in> program ==> F \<in> invariant(reachable(F))"
paulson@15634
   106
apply (unfold invariant_def initially_def)
paulson@15634
   107
apply (blast intro: reachable_type [THEN subsetD] reachable.intros)
paulson@15634
   108
done
paulson@15634
   109
paulson@15634
   110
(*...in fact the strongest invariant!*)
paulson@15634
   111
lemma invariant_includes_reachable: "F \<in> invariant(A) ==> reachable(F) <= A"
paulson@15634
   112
apply (cut_tac F = F in Acts_type)
paulson@15634
   113
apply (cut_tac F = F in Init_type)
paulson@15634
   114
apply (cut_tac F = F in reachable_type)
paulson@15634
   115
apply (simp (no_asm_use) add: stable_def constrains_def invariant_def initially_def)
paulson@15634
   116
apply (rule subsetI)
paulson@15634
   117
apply (erule reachable.induct)
paulson@15634
   118
apply (blast intro: reachable.intros)+
paulson@15634
   119
done
paulson@15634
   120
paulson@15634
   121
(*** Co ***)
paulson@15634
   122
paulson@15634
   123
lemma constrains_reachable_Int: "F \<in> B co B'==>F:(reachable(F) Int B) co (reachable(F) Int B')"
paulson@15634
   124
apply (frule constrains_type [THEN subsetD])
paulson@15634
   125
apply (frule stable_reachable [OF _ _ subset_refl])
paulson@15634
   126
apply (simp_all add: stable_def constrains_Int)
paulson@15634
   127
done
paulson@15634
   128
paulson@15634
   129
(*Resembles the previous definition of Constrains*)
paulson@15634
   130
lemma Constrains_eq_constrains: 
paulson@15634
   131
"A Co B = {F \<in> program. F:(reachable(F) Int A) co (reachable(F)  Int  B)}"
paulson@15634
   132
apply (unfold Constrains_def)
paulson@15634
   133
apply (blast dest: constrains_reachable_Int constrains_type [THEN subsetD]
paulson@15634
   134
             intro: constrains_weaken)
paulson@15634
   135
done
paulson@15634
   136
paulson@15634
   137
lemmas Constrains_def2 = Constrains_eq_constrains [THEN eq_reflection]
paulson@15634
   138
paulson@15634
   139
lemma constrains_imp_Constrains: "F \<in> A co A' ==> F \<in> A Co A'"
paulson@15634
   140
apply (unfold Constrains_def)
paulson@15634
   141
apply (blast intro: constrains_weaken_L dest: constrainsD2)
paulson@15634
   142
done
paulson@15634
   143
paulson@15634
   144
lemma ConstrainsI: 
paulson@15634
   145
    "[|!!act s s'. [| act \<in> Acts(F); <s,s'>:act; s \<in> A |] ==> s':A'; 
paulson@15634
   146
       F \<in> program|]
paulson@15634
   147
     ==> F \<in> A Co A'"
paulson@15634
   148
apply (auto simp add: Constrains_def constrains_def st_set_def)
paulson@15634
   149
apply (blast dest: reachable_type [THEN subsetD])
paulson@15634
   150
done
paulson@15634
   151
paulson@15634
   152
lemma Constrains_type: 
paulson@15634
   153
 "A Co B <= program"
paulson@15634
   154
apply (unfold Constrains_def, blast)
paulson@15634
   155
done
paulson@15634
   156
paulson@15634
   157
lemma Constrains_empty: "F \<in> 0 Co B <-> F \<in> program"
paulson@15634
   158
by (auto dest: Constrains_type [THEN subsetD]
paulson@15634
   159
            intro: constrains_imp_Constrains)
paulson@15634
   160
declare Constrains_empty [iff]
paulson@15634
   161
paulson@15634
   162
lemma Constrains_state: "F \<in> A Co state <-> F \<in> program"
paulson@15634
   163
apply (unfold Constrains_def)
paulson@15634
   164
apply (auto dest: Constrains_type [THEN subsetD] intro: constrains_imp_Constrains)
paulson@15634
   165
done
paulson@15634
   166
declare Constrains_state [iff]
paulson@15634
   167
paulson@15634
   168
lemma Constrains_weaken_R: 
paulson@15634
   169
        "[| F \<in> A Co A'; A'<=B' |] ==> F \<in> A Co B'"
paulson@15634
   170
apply (unfold Constrains_def2)
paulson@15634
   171
apply (blast intro: constrains_weaken_R)
paulson@15634
   172
done
paulson@15634
   173
paulson@15634
   174
lemma Constrains_weaken_L: 
paulson@15634
   175
    "[| F \<in> A Co A'; B<=A |] ==> F \<in> B Co A'"
paulson@15634
   176
apply (unfold Constrains_def2)
paulson@15634
   177
apply (blast intro: constrains_weaken_L st_set_subset)
paulson@15634
   178
done
paulson@15634
   179
paulson@15634
   180
lemma Constrains_weaken: 
paulson@15634
   181
   "[| F \<in> A Co A'; B<=A; A'<=B' |] ==> F \<in> B Co B'"
paulson@15634
   182
apply (unfold Constrains_def2)
paulson@15634
   183
apply (blast intro: constrains_weaken st_set_subset)
paulson@15634
   184
done
paulson@15634
   185
paulson@15634
   186
(** Union **)
paulson@15634
   187
lemma Constrains_Un: 
paulson@15634
   188
    "[| F \<in> A Co A'; F \<in> B Co B' |] ==> F \<in> (A Un B) Co (A' Un B')"
paulson@15634
   189
apply (unfold Constrains_def2, auto)
paulson@15634
   190
apply (simp add: Int_Un_distrib)
paulson@15634
   191
apply (blast intro: constrains_Un)
paulson@15634
   192
done
paulson@15634
   193
paulson@15634
   194
lemma Constrains_UN: 
paulson@15634
   195
    "[|(!!i. i \<in> I==>F \<in> A(i) Co A'(i)); F \<in> program|] 
paulson@15634
   196
     ==> F:(\<Union>i \<in> I. A(i)) Co (\<Union>i \<in> I. A'(i))"
paulson@15634
   197
by (auto intro: constrains_UN simp del: UN_simps 
paulson@15634
   198
         simp add: Constrains_def2 Int_UN_distrib)
paulson@15634
   199
paulson@15634
   200
paulson@15634
   201
(** Intersection **)
paulson@15634
   202
paulson@15634
   203
lemma Constrains_Int: 
paulson@15634
   204
    "[| F \<in> A Co A'; F \<in> B Co B'|]==> F:(A Int B) Co (A' Int B')"
paulson@15634
   205
apply (unfold Constrains_def)
paulson@15634
   206
apply (subgoal_tac "reachable (F) Int (A Int B) = (reachable (F) Int A) Int (reachable (F) Int B) ")
paulson@15634
   207
apply (auto intro: constrains_Int)
paulson@15634
   208
done
paulson@15634
   209
paulson@15634
   210
lemma Constrains_INT: 
paulson@15634
   211
    "[| (!!i. i \<in> I ==>F \<in> A(i) Co A'(i)); F \<in> program  |]  
paulson@15634
   212
     ==> F:(\<Inter>i \<in> I. A(i)) Co (\<Inter>i \<in> I. A'(i))"
paulson@15634
   213
apply (simp (no_asm_simp) del: INT_simps add: Constrains_def INT_extend_simps)
paulson@15634
   214
apply (rule constrains_INT)
paulson@15634
   215
apply (auto simp add: Constrains_def)
paulson@15634
   216
done
paulson@15634
   217
paulson@15634
   218
lemma Constrains_imp_subset: "F \<in> A Co A' ==> reachable(F) Int A <= A'"
paulson@15634
   219
apply (unfold Constrains_def)
paulson@15634
   220
apply (blast dest: constrains_imp_subset)
paulson@15634
   221
done
paulson@15634
   222
paulson@15634
   223
lemma Constrains_trans: 
paulson@15634
   224
 "[| F \<in> A Co B; F \<in> B Co C |] ==> F \<in> A Co C"
paulson@15634
   225
apply (unfold Constrains_def2)
paulson@15634
   226
apply (blast intro: constrains_trans constrains_weaken)
paulson@15634
   227
done
paulson@15634
   228
paulson@15634
   229
lemma Constrains_cancel: 
paulson@15634
   230
"[| F \<in> A Co (A' Un B); F \<in> B Co B' |] ==> F \<in> A Co (A' Un B')"
paulson@15634
   231
apply (unfold Constrains_def2)
paulson@15634
   232
apply (simp (no_asm_use) add: Int_Un_distrib)
paulson@15634
   233
apply (blast intro: constrains_cancel)
paulson@15634
   234
done
paulson@15634
   235
paulson@15634
   236
(*** Stable ***)
paulson@15634
   237
(* Useful because there's no Stable_weaken.  [Tanja Vos] *)
paulson@15634
   238
paulson@15634
   239
lemma stable_imp_Stable: 
paulson@15634
   240
"F \<in> stable(A) ==> F \<in> Stable(A)"
paulson@15634
   241
paulson@15634
   242
apply (unfold stable_def Stable_def)
paulson@15634
   243
apply (erule constrains_imp_Constrains)
paulson@15634
   244
done
paulson@15634
   245
paulson@15634
   246
lemma Stable_eq: "[| F \<in> Stable(A); A = B |] ==> F \<in> Stable(B)"
paulson@15634
   247
by blast
paulson@15634
   248
paulson@15634
   249
lemma Stable_eq_stable: 
paulson@15634
   250
"F \<in> Stable(A) <->  (F \<in> stable(reachable(F) Int A))"
paulson@15634
   251
apply (auto dest: constrainsD2 simp add: Stable_def stable_def Constrains_def2)
paulson@15634
   252
done
paulson@15634
   253
paulson@15634
   254
lemma StableI: "F \<in> A Co A ==> F \<in> Stable(A)"
paulson@15634
   255
by (unfold Stable_def, assumption)
paulson@15634
   256
paulson@15634
   257
lemma StableD: "F \<in> Stable(A) ==> F \<in> A Co A"
paulson@15634
   258
by (unfold Stable_def, assumption)
paulson@15634
   259
paulson@15634
   260
lemma Stable_Un: 
paulson@15634
   261
    "[| F \<in> Stable(A); F \<in> Stable(A') |] ==> F \<in> Stable(A Un A')"
paulson@15634
   262
apply (unfold Stable_def)
paulson@15634
   263
apply (blast intro: Constrains_Un)
paulson@15634
   264
done
paulson@15634
   265
paulson@15634
   266
lemma Stable_Int: 
paulson@15634
   267
    "[| F \<in> Stable(A); F \<in> Stable(A') |] ==> F \<in> Stable (A Int A')"
paulson@15634
   268
apply (unfold Stable_def)
paulson@15634
   269
apply (blast intro: Constrains_Int)
paulson@15634
   270
done
paulson@15634
   271
paulson@15634
   272
lemma Stable_Constrains_Un: 
paulson@15634
   273
    "[| F \<in> Stable(C); F \<in> A Co (C Un A') |]    
paulson@15634
   274
     ==> F \<in> (C Un A) Co (C Un A')"
paulson@15634
   275
apply (unfold Stable_def)
paulson@15634
   276
apply (blast intro: Constrains_Un [THEN Constrains_weaken_R])
paulson@15634
   277
done
paulson@15634
   278
paulson@15634
   279
lemma Stable_Constrains_Int: 
paulson@15634
   280
    "[| F \<in> Stable(C); F \<in> (C Int A) Co A' |]    
paulson@15634
   281
     ==> F \<in> (C Int A) Co (C Int A')"
paulson@15634
   282
apply (unfold Stable_def)
paulson@15634
   283
apply (blast intro: Constrains_Int [THEN Constrains_weaken])
paulson@15634
   284
done
paulson@15634
   285
paulson@15634
   286
lemma Stable_UN: 
paulson@15634
   287
    "[| (!!i. i \<in> I ==> F \<in> Stable(A(i))); F \<in> program |]
paulson@15634
   288
     ==> F \<in> Stable (\<Union>i \<in> I. A(i))"
paulson@15634
   289
apply (simp add: Stable_def)
paulson@15634
   290
apply (blast intro: Constrains_UN)
paulson@15634
   291
done
paulson@15634
   292
paulson@15634
   293
lemma Stable_INT: 
paulson@15634
   294
    "[|(!!i. i \<in> I ==> F \<in> Stable(A(i))); F \<in> program |]
paulson@15634
   295
     ==> F \<in> Stable (\<Inter>i \<in> I. A(i))"
paulson@15634
   296
apply (simp add: Stable_def)
paulson@15634
   297
apply (blast intro: Constrains_INT)
paulson@15634
   298
done
paulson@15634
   299
paulson@15634
   300
lemma Stable_reachable: "F \<in> program ==>F \<in> Stable (reachable(F))"
paulson@15634
   301
apply (simp (no_asm_simp) add: Stable_eq_stable Int_absorb)
paulson@15634
   302
done
paulson@15634
   303
paulson@15634
   304
lemma Stable_type: "Stable(A) <= program"
paulson@15634
   305
apply (unfold Stable_def)
paulson@15634
   306
apply (rule Constrains_type)
paulson@15634
   307
done
paulson@15634
   308
paulson@15634
   309
(*** The Elimination Theorem.  The "free" m has become universally quantified!
paulson@15634
   310
     Should the premise be !!m instead of \<forall>m ?  Would make it harder to use
paulson@15634
   311
     in forward proof. ***)
paulson@15634
   312
paulson@15634
   313
lemma Elimination: 
paulson@15634
   314
    "[| \<forall>m \<in> M. F \<in> ({s \<in> A. x(s) = m}) Co (B(m)); F \<in> program |]  
paulson@15634
   315
     ==> F \<in> ({s \<in> A. x(s):M}) Co (\<Union>m \<in> M. B(m))"
paulson@15634
   316
apply (unfold Constrains_def, auto)
paulson@15634
   317
apply (rule_tac A1 = "reachable (F) Int A" 
paulson@15634
   318
	in UNITY.elimination [THEN constrains_weaken_L])
paulson@15634
   319
apply (auto intro: constrains_weaken_L)
paulson@15634
   320
done
paulson@15634
   321
paulson@15634
   322
(* As above, but for the special case of A=state *)
paulson@15634
   323
lemma Elimination2: 
paulson@15634
   324
 "[| \<forall>m \<in> M. F \<in> {s \<in> state. x(s) = m} Co B(m); F \<in> program |]  
paulson@15634
   325
     ==> F \<in> {s \<in> state. x(s):M} Co (\<Union>m \<in> M. B(m))"
paulson@15634
   326
apply (blast intro: Elimination)
paulson@15634
   327
done
paulson@15634
   328
paulson@15634
   329
(** Unless **)
paulson@15634
   330
paulson@15634
   331
lemma Unless_type: "A Unless B <=program"
wenzelm@24893
   332
apply (unfold op_Unless_def)
paulson@15634
   333
apply (rule Constrains_type)
paulson@15634
   334
done
paulson@15634
   335
paulson@15634
   336
(*** Specialized laws for handling Always ***)
paulson@15634
   337
paulson@15634
   338
(** Natural deduction rules for "Always A" **)
paulson@15634
   339
paulson@15634
   340
lemma AlwaysI: 
paulson@15634
   341
"[| Init(F)<=A;  F \<in> Stable(A) |] ==> F \<in> Always(A)"
paulson@15634
   342
paulson@15634
   343
apply (unfold Always_def initially_def)
paulson@15634
   344
apply (frule Stable_type [THEN subsetD], auto)
paulson@15634
   345
done
paulson@15634
   346
paulson@15634
   347
lemma AlwaysD: "F \<in> Always(A) ==> Init(F)<=A & F \<in> Stable(A)"
paulson@15634
   348
by (simp add: Always_def initially_def)
paulson@15634
   349
paulson@15634
   350
lemmas AlwaysE = AlwaysD [THEN conjE, standard]
paulson@15634
   351
lemmas Always_imp_Stable = AlwaysD [THEN conjunct2, standard]
paulson@15634
   352
paulson@15634
   353
(*The set of all reachable states is Always*)
paulson@15634
   354
lemma Always_includes_reachable: "F \<in> Always(A) ==> reachable(F) <= A"
paulson@15634
   355
apply (simp (no_asm_use) add: Stable_def Constrains_def constrains_def Always_def initially_def)
paulson@15634
   356
apply (rule subsetI)
paulson@15634
   357
apply (erule reachable.induct)
paulson@15634
   358
apply (blast intro: reachable.intros)+
paulson@15634
   359
done
paulson@15634
   360
paulson@15634
   361
lemma invariant_imp_Always: 
paulson@15634
   362
     "F \<in> invariant(A) ==> F \<in> Always(A)"
paulson@15634
   363
apply (unfold Always_def invariant_def Stable_def stable_def)
paulson@15634
   364
apply (blast intro: constrains_imp_Constrains)
paulson@15634
   365
done
paulson@15634
   366
paulson@15634
   367
lemmas Always_reachable = invariant_reachable [THEN invariant_imp_Always, standard]
paulson@15634
   368
paulson@15634
   369
lemma Always_eq_invariant_reachable: "Always(A) = {F \<in> program. F \<in> invariant(reachable(F) Int A)}"
paulson@15634
   370
apply (simp (no_asm) add: Always_def invariant_def Stable_def Constrains_def2 stable_def initially_def)
paulson@15634
   371
apply (rule equalityI, auto) 
paulson@15634
   372
apply (blast intro: reachable.intros reachable_type)
paulson@15634
   373
done
paulson@15634
   374
paulson@15634
   375
(*the RHS is the traditional definition of the "always" operator*)
paulson@15634
   376
lemma Always_eq_includes_reachable: "Always(A) = {F \<in> program. reachable(F) <= A}"
paulson@15634
   377
apply (rule equalityI, safe)
paulson@15634
   378
apply (auto dest: invariant_includes_reachable 
paulson@15634
   379
   simp add: subset_Int_iff invariant_reachable Always_eq_invariant_reachable)
paulson@15634
   380
done
paulson@15634
   381
paulson@15634
   382
lemma Always_type: "Always(A) <= program"
paulson@15634
   383
by (unfold Always_def initially_def, auto)
paulson@15634
   384
paulson@15634
   385
lemma Always_state_eq: "Always(state) = program"
paulson@15634
   386
apply (rule equalityI)
paulson@15634
   387
apply (auto dest: Always_type [THEN subsetD] reachable_type [THEN subsetD]
paulson@15634
   388
            simp add: Always_eq_includes_reachable)
paulson@15634
   389
done
paulson@15634
   390
declare Always_state_eq [simp]
paulson@15634
   391
paulson@15634
   392
lemma state_AlwaysI: "F \<in> program ==> F \<in> Always(state)"
paulson@15634
   393
by (auto dest: reachable_type [THEN subsetD]
paulson@15634
   394
            simp add: Always_eq_includes_reachable)
paulson@15634
   395
paulson@15634
   396
lemma Always_eq_UN_invariant: "st_set(A) ==> Always(A) = (\<Union>I \<in> Pow(A). invariant(I))"
paulson@15634
   397
apply (simp (no_asm) add: Always_eq_includes_reachable)
paulson@15634
   398
apply (rule equalityI, auto) 
paulson@15634
   399
apply (blast intro: invariantI rev_subsetD [OF _ Init_into_reachable] 
paulson@15634
   400
		    rev_subsetD [OF _ invariant_includes_reachable]  
paulson@15634
   401
             dest: invariant_type [THEN subsetD])+
paulson@15634
   402
done
paulson@15634
   403
paulson@15634
   404
lemma Always_weaken: "[| F \<in> Always(A); A <= B |] ==> F \<in> Always(B)"
paulson@15634
   405
by (auto simp add: Always_eq_includes_reachable)
paulson@15634
   406
paulson@15634
   407
paulson@15634
   408
(*** "Co" rules involving Always ***)
paulson@15634
   409
lemmas Int_absorb2 = subset_Int_iff [unfolded iff_def, THEN conjunct1, THEN mp]
paulson@15634
   410
paulson@15634
   411
lemma Always_Constrains_pre: "F \<in> Always(I) ==> (F:(I Int A) Co A') <-> (F \<in> A Co A')"
paulson@15634
   412
apply (simp (no_asm_simp) add: Always_includes_reachable [THEN Int_absorb2] Constrains_def Int_assoc [symmetric])
paulson@15634
   413
done
paulson@15634
   414
paulson@15634
   415
lemma Always_Constrains_post: "F \<in> Always(I) ==> (F \<in> A Co (I Int A')) <->(F \<in> A Co A')"
paulson@15634
   416
apply (simp (no_asm_simp) add: Always_includes_reachable [THEN Int_absorb2] Constrains_eq_constrains Int_assoc [symmetric])
paulson@15634
   417
done
paulson@15634
   418
paulson@15634
   419
lemma Always_ConstrainsI: "[| F \<in> Always(I);  F \<in> (I Int A) Co A' |] ==> F \<in> A Co A'"
paulson@15634
   420
by (blast intro: Always_Constrains_pre [THEN iffD1])
paulson@15634
   421
paulson@15634
   422
(* [| F \<in> Always(I);  F \<in> A Co A' |] ==> F \<in> A Co (I Int A') *)
paulson@15634
   423
lemmas Always_ConstrainsD = Always_Constrains_post [THEN iffD2, standard]
paulson@15634
   424
paulson@15634
   425
(*The analogous proof of Always_LeadsTo_weaken doesn't terminate*)
paulson@15634
   426
lemma Always_Constrains_weaken: 
paulson@15634
   427
"[|F \<in> Always(C); F \<in> A Co A'; C Int B<=A; C Int A'<=B'|]==>F \<in> B Co B'"
paulson@15634
   428
apply (rule Always_ConstrainsI)
paulson@15634
   429
apply (drule_tac [2] Always_ConstrainsD, simp_all) 
paulson@15634
   430
apply (blast intro: Constrains_weaken)
paulson@15634
   431
done
paulson@15634
   432
paulson@15634
   433
(** Conjoining Always properties **)
paulson@15634
   434
lemma Always_Int_distrib: "Always(A Int B) = Always(A) Int Always(B)"
paulson@15634
   435
by (auto simp add: Always_eq_includes_reachable)
paulson@15634
   436
paulson@15634
   437
(* the premise i \<in> I is need since \<Inter>is formally not defined for I=0 *)
paulson@15634
   438
lemma Always_INT_distrib: "i \<in> I==>Always(\<Inter>i \<in> I. A(i)) = (\<Inter>i \<in> I. Always(A(i)))"
paulson@15634
   439
apply (rule equalityI)
paulson@15634
   440
apply (auto simp add: Inter_iff Always_eq_includes_reachable)
paulson@15634
   441
done
paulson@15634
   442
paulson@15634
   443
paulson@15634
   444
lemma Always_Int_I: "[| F \<in> Always(A);  F \<in> Always(B) |] ==> F \<in> Always(A Int B)"
paulson@15634
   445
apply (simp (no_asm_simp) add: Always_Int_distrib)
paulson@15634
   446
done
paulson@15634
   447
paulson@15634
   448
(*Allows a kind of "implication introduction"*)
paulson@15634
   449
lemma Always_Diff_Un_eq: "[| F \<in> Always(A) |] ==> (F \<in> Always(C-A Un B)) <-> (F \<in> Always(B))"
paulson@15634
   450
by (auto simp add: Always_eq_includes_reachable)
paulson@15634
   451
paulson@15634
   452
(*Delete the nearest invariance assumption (which will be the second one
paulson@15634
   453
  used by Always_Int_I) *)
paulson@15634
   454
lemmas Always_thin = thin_rl [of "F \<in> Always(A)", standard]
paulson@15634
   455
paulson@15634
   456
ML
paulson@15634
   457
{*
paulson@15634
   458
(*Combines two invariance ASSUMPTIONS into one.  USEFUL??*)
wenzelm@24893
   459
val Always_Int_tac = dtac @{thm Always_Int_I} THEN' assume_tac THEN' etac @{thm Always_thin};
paulson@15634
   460
paulson@15634
   461
(*Combines a list of invariance THEOREMS into one.*)
wenzelm@24893
   462
val Always_Int_rule = foldr1 (fn (th1,th2) => [th1,th2] MRS @{thm Always_Int_I});
paulson@15634
   463
paulson@15634
   464
(*To allow expansion of the program's definition when appropriate*)
wenzelm@31902
   465
structure Program_Defs = Named_Thms
wenzelm@31902
   466
(
wenzelm@31902
   467
  val name = "program"
wenzelm@31902
   468
  val description = "program definitions"
wenzelm@31902
   469
);
paulson@15634
   470
paulson@15634
   471
(*proves "co" properties when the program is specified*)
paulson@15634
   472
wenzelm@23894
   473
fun constrains_tac ctxt =
wenzelm@23894
   474
  let val css as (cs, ss) = local_clasimpset_of ctxt in
paulson@15634
   475
   SELECT_GOAL
paulson@15634
   476
      (EVERY [REPEAT (Always_Int_tac 1),
wenzelm@24893
   477
              REPEAT (etac @{thm Always_ConstrainsI} 1
paulson@15634
   478
                      ORELSE
wenzelm@24893
   479
                      resolve_tac [@{thm StableI}, @{thm stableI},
wenzelm@24893
   480
                                   @{thm constrains_imp_Constrains}] 1),
wenzelm@24893
   481
              rtac @{thm constrainsI} 1,
paulson@15634
   482
              (* Three subgoals *)
wenzelm@24893
   483
              rewrite_goal_tac [@{thm st_set_def}] 3,
wenzelm@23894
   484
              REPEAT (force_tac css 2),
wenzelm@31902
   485
              full_simp_tac (ss addsimps (Program_Defs.get ctxt)) 1,
paulson@15634
   486
              ALLGOALS (clarify_tac cs),
paulson@15634
   487
              REPEAT (FIRSTGOAL (etac disjE)),
wenzelm@23894
   488
              ALLGOALS (clarify_tac cs),
paulson@15634
   489
              REPEAT (FIRSTGOAL (etac disjE)),
paulson@15634
   490
              ALLGOALS (clarify_tac cs),
paulson@15634
   491
              ALLGOALS (asm_full_simp_tac ss),
wenzelm@23894
   492
              ALLGOALS (clarify_tac cs)])
wenzelm@23894
   493
  end;
paulson@15634
   494
paulson@15634
   495
(*For proving invariants*)
wenzelm@23894
   496
fun always_tac ctxt i = 
wenzelm@24893
   497
    rtac @{thm AlwaysI} i THEN force_tac (local_clasimpset_of ctxt) i THEN constrains_tac ctxt i;
paulson@15634
   498
*}
paulson@15634
   499
wenzelm@31902
   500
setup Program_Defs.setup
wenzelm@24051
   501
paulson@16183
   502
method_setup safety = {*
wenzelm@30549
   503
  Scan.succeed (SIMPLE_METHOD' o constrains_tac) *}
wenzelm@21588
   504
  "for proving safety properties"
paulson@15634
   505
wenzelm@23894
   506
method_setup always = {*
wenzelm@30549
   507
  Scan.succeed (SIMPLE_METHOD' o always_tac) *}
wenzelm@23894
   508
  "for proving invariants"
paulson@15634
   509
paulson@11479
   510
end