src/HOL/UNITY/Constrains.thy
author paulson
Fri Jan 31 20:12:44 2003 +0100 (2003-01-31)
changeset 13798 4c1a53627500
parent 13797 baefae13ad37
child 13805 3786b2fd6808
permissions -rw-r--r--
conversion to new-style theories and tidying
     1 (*  Title:      HOL/UNITY/Constrains
     2     ID:         $Id$
     3     Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
     4     Copyright   1998  University of Cambridge
     5 
     6 Weak safety relations: restricted to the set of reachable states.
     7 *)
     8 
     9 header{*Weak Safety*}
    10 
    11 theory Constrains = UNITY:
    12 
    13 consts traces :: "['a set, ('a * 'a)set set] => ('a * 'a list) set"
    14 
    15   (*Initial states and program => (final state, reversed trace to it)...
    16     Arguments MUST be curried in an inductive definition*)
    17 
    18 inductive "traces init acts"  
    19   intros 
    20          (*Initial trace is empty*)
    21     Init:  "s: init ==> (s,[]) : traces init acts"
    22 
    23     Acts:  "[| act: acts;  (s,evs) : traces init acts;  (s,s'): act |]
    24 	    ==> (s', s#evs) : traces init acts"
    25 
    26 
    27 consts reachable :: "'a program => 'a set"
    28 
    29 inductive "reachable F"
    30   intros 
    31     Init:  "s: Init F ==> s : reachable F"
    32 
    33     Acts:  "[| act: Acts F;  s : reachable F;  (s,s'): act |]
    34 	    ==> s' : reachable F"
    35 
    36 constdefs
    37   Constrains :: "['a set, 'a set] => 'a program set"  (infixl "Co" 60)
    38     "A Co B == {F. F : (reachable F Int A)  co  B}"
    39 
    40   Unless  :: "['a set, 'a set] => 'a program set"     (infixl "Unless" 60)
    41     "A Unless B == (A-B) Co (A Un B)"
    42 
    43   Stable     :: "'a set => 'a program set"
    44     "Stable A == A Co A"
    45 
    46   (*Always is the weak form of "invariant"*)
    47   Always :: "'a set => 'a program set"
    48     "Always A == {F. Init F <= A} Int Stable A"
    49 
    50   (*Polymorphic in both states and the meaning of <= *)
    51   Increasing :: "['a => 'b::{order}] => 'a program set"
    52     "Increasing f == INT z. Stable {s. z <= f s}"
    53 
    54 
    55 subsection{*traces and reachable*}
    56 
    57 lemma reachable_equiv_traces:
    58      "reachable F = {s. EX evs. (s,evs): traces (Init F) (Acts F)}"
    59 apply safe
    60 apply (erule_tac [2] traces.induct)
    61 apply (erule reachable.induct)
    62 apply (blast intro: reachable.intros traces.intros)+
    63 done
    64 
    65 lemma Init_subset_reachable: "Init F <= reachable F"
    66 by (blast intro: reachable.intros)
    67 
    68 lemma stable_reachable [intro!,simp]:
    69      "Acts G <= Acts F ==> G : stable (reachable F)"
    70 by (blast intro: stableI constrainsI reachable.intros)
    71 
    72 (*The set of all reachable states is an invariant...*)
    73 lemma invariant_reachable: "F : invariant (reachable F)"
    74 apply (simp add: invariant_def)
    75 apply (blast intro: reachable.intros)
    76 done
    77 
    78 (*...in fact the strongest invariant!*)
    79 lemma invariant_includes_reachable: "F : invariant A ==> reachable F <= A"
    80 apply (simp add: stable_def constrains_def invariant_def)
    81 apply (rule subsetI)
    82 apply (erule reachable.induct)
    83 apply (blast intro: reachable.intros)+
    84 done
    85 
    86 
    87 subsection{*Co*}
    88 
    89 (*F : B co B' ==> F : (reachable F Int B) co (reachable F Int B')*)
    90 lemmas constrains_reachable_Int =  
    91     subset_refl [THEN stable_reachable [unfolded stable_def], 
    92                  THEN constrains_Int, standard]
    93 
    94 (*Resembles the previous definition of Constrains*)
    95 lemma Constrains_eq_constrains: 
    96      "A Co B = {F. F : (reachable F  Int  A) co (reachable F  Int  B)}"
    97 apply (unfold Constrains_def)
    98 apply (blast dest: constrains_reachable_Int intro: constrains_weaken)
    99 done
   100 
   101 lemma constrains_imp_Constrains: "F : A co A' ==> F : A Co A'"
   102 apply (unfold Constrains_def)
   103 apply (blast intro: constrains_weaken_L)
   104 done
   105 
   106 lemma stable_imp_Stable: "F : stable A ==> F : Stable A"
   107 apply (unfold stable_def Stable_def)
   108 apply (erule constrains_imp_Constrains)
   109 done
   110 
   111 lemma ConstrainsI: 
   112     "(!!act s s'. [| act: Acts F;  (s,s') : act;  s: A |] ==> s': A')  
   113      ==> F : A Co A'"
   114 apply (rule constrains_imp_Constrains)
   115 apply (blast intro: constrainsI)
   116 done
   117 
   118 lemma Constrains_empty [iff]: "F : {} Co B"
   119 by (unfold Constrains_def constrains_def, blast)
   120 
   121 lemma Constrains_UNIV [iff]: "F : A Co UNIV"
   122 by (blast intro: ConstrainsI)
   123 
   124 lemma Constrains_weaken_R: 
   125     "[| F : A Co A'; A'<=B' |] ==> F : A Co B'"
   126 apply (unfold Constrains_def)
   127 apply (blast intro: constrains_weaken_R)
   128 done
   129 
   130 lemma Constrains_weaken_L: 
   131     "[| F : A Co A'; B<=A |] ==> F : B Co A'"
   132 apply (unfold Constrains_def)
   133 apply (blast intro: constrains_weaken_L)
   134 done
   135 
   136 lemma Constrains_weaken: 
   137    "[| F : A Co A'; B<=A; A'<=B' |] ==> F : B Co B'"
   138 apply (unfold Constrains_def)
   139 apply (blast intro: constrains_weaken)
   140 done
   141 
   142 (** Union **)
   143 
   144 lemma Constrains_Un: 
   145     "[| F : A Co A'; F : B Co B' |] ==> F : (A Un B) Co (A' Un B')"
   146 apply (unfold Constrains_def)
   147 apply (blast intro: constrains_Un [THEN constrains_weaken])
   148 done
   149 
   150 lemma Constrains_UN: 
   151   assumes Co: "!!i. i:I ==> F : (A i) Co (A' i)"
   152   shows "F : (UN i:I. A i) Co (UN i:I. A' i)"
   153 apply (unfold Constrains_def)
   154 apply (rule CollectI)
   155 apply (rule Co [unfolded Constrains_def, THEN CollectD, THEN constrains_UN, 
   156                 THEN constrains_weaken],   auto)
   157 done
   158 
   159 (** Intersection **)
   160 
   161 lemma Constrains_Int: 
   162     "[| F : A Co A'; F : B Co B' |] ==> F : (A Int B) Co (A' Int B')"
   163 apply (unfold Constrains_def)
   164 apply (blast intro: constrains_Int [THEN constrains_weaken])
   165 done
   166 
   167 lemma Constrains_INT: 
   168   assumes Co: "!!i. i:I ==> F : (A i) Co (A' i)"
   169   shows "F : (INT i:I. A i) Co (INT i:I. A' i)"
   170 apply (unfold Constrains_def)
   171 apply (rule CollectI)
   172 apply (rule Co [unfolded Constrains_def, THEN CollectD, THEN constrains_INT, 
   173                 THEN constrains_weaken],   auto)
   174 done
   175 
   176 lemma Constrains_imp_subset: "F : A Co A' ==> reachable F Int A <= A'"
   177 by (simp add: constrains_imp_subset Constrains_def)
   178 
   179 lemma Constrains_trans: "[| F : A Co B; F : B Co C |] ==> F : A Co C"
   180 apply (simp add: Constrains_eq_constrains)
   181 apply (blast intro: constrains_trans constrains_weaken)
   182 done
   183 
   184 lemma Constrains_cancel:
   185      "[| F : A Co (A' Un B); F : B Co B' |] ==> F : A Co (A' Un B')"
   186 by (simp add: Constrains_eq_constrains constrains_def, blast)
   187 
   188 
   189 subsection{*Stable*}
   190 
   191 (*Useful because there's no Stable_weaken.  [Tanja Vos]*)
   192 lemma Stable_eq: "[| F: Stable A; A = B |] ==> F : Stable B"
   193 by blast
   194 
   195 lemma Stable_eq_stable: "(F : Stable A) = (F : stable (reachable F Int A))"
   196 by (simp add: Stable_def Constrains_eq_constrains stable_def)
   197 
   198 lemma StableI: "F : A Co A ==> F : Stable A"
   199 by (unfold Stable_def, assumption)
   200 
   201 lemma StableD: "F : Stable A ==> F : A Co A"
   202 by (unfold Stable_def, assumption)
   203 
   204 lemma Stable_Un: 
   205     "[| F : Stable A; F : Stable A' |] ==> F : Stable (A Un A')"
   206 apply (unfold Stable_def)
   207 apply (blast intro: Constrains_Un)
   208 done
   209 
   210 lemma Stable_Int: 
   211     "[| F : Stable A; F : Stable A' |] ==> F : Stable (A Int A')"
   212 apply (unfold Stable_def)
   213 apply (blast intro: Constrains_Int)
   214 done
   215 
   216 lemma Stable_Constrains_Un: 
   217     "[| F : Stable C; F : A Co (C Un A') |]    
   218      ==> F : (C Un A) Co (C Un A')"
   219 apply (unfold Stable_def)
   220 apply (blast intro: Constrains_Un [THEN Constrains_weaken])
   221 done
   222 
   223 lemma Stable_Constrains_Int: 
   224     "[| F : Stable C; F : (C Int A) Co A' |]    
   225      ==> F : (C Int A) Co (C Int A')"
   226 apply (unfold Stable_def)
   227 apply (blast intro: Constrains_Int [THEN Constrains_weaken])
   228 done
   229 
   230 lemma Stable_UN: 
   231     "(!!i. i:I ==> F : Stable (A i)) ==> F : Stable (UN i:I. A i)"
   232 by (simp add: Stable_def Constrains_UN) 
   233 
   234 lemma Stable_INT: 
   235     "(!!i. i:I ==> F : Stable (A i)) ==> F : Stable (INT i:I. A i)"
   236 by (simp add: Stable_def Constrains_INT) 
   237 
   238 lemma Stable_reachable: "F : Stable (reachable F)"
   239 by (simp add: Stable_eq_stable)
   240 
   241 
   242 
   243 subsection{*Increasing*}
   244 
   245 lemma IncreasingD: 
   246      "F : Increasing f ==> F : Stable {s. x <= f s}"
   247 by (unfold Increasing_def, blast)
   248 
   249 lemma mono_Increasing_o: 
   250      "mono g ==> Increasing f <= Increasing (g o f)"
   251 apply (simp add: Increasing_def Stable_def Constrains_def stable_def 
   252                  constrains_def)
   253 apply (blast intro: monoD order_trans)
   254 done
   255 
   256 lemma strict_IncreasingD: 
   257      "!!z::nat. F : Increasing f ==> F: Stable {s. z < f s}"
   258 by (simp add: Increasing_def Suc_le_eq [symmetric])
   259 
   260 lemma increasing_imp_Increasing: 
   261      "F : increasing f ==> F : Increasing f"
   262 apply (unfold increasing_def Increasing_def)
   263 apply (blast intro: stable_imp_Stable)
   264 done
   265 
   266 lemmas Increasing_constant =  
   267     increasing_constant [THEN increasing_imp_Increasing, standard, iff]
   268 
   269 
   270 subsection{*The Elimination Theorem*}
   271 
   272 (*The "free" m has become universally quantified! Should the premise be !!m
   273 instead of ALL m ?  Would make it harder to use in forward proof.*)
   274 
   275 lemma Elimination: 
   276     "[| ALL m. F : {s. s x = m} Co (B m) |]  
   277      ==> F : {s. s x : M} Co (UN m:M. B m)"
   278 by (unfold Constrains_def constrains_def, blast)
   279 
   280 (*As above, but for the trivial case of a one-variable state, in which the
   281   state is identified with its one variable.*)
   282 lemma Elimination_sing: 
   283     "(ALL m. F : {m} Co (B m)) ==> F : M Co (UN m:M. B m)"
   284 by (unfold Constrains_def constrains_def, blast)
   285 
   286 
   287 subsection{*Specialized laws for handling Always*}
   288 
   289 (** Natural deduction rules for "Always A" **)
   290 
   291 lemma AlwaysI: "[| Init F<=A;  F : Stable A |] ==> F : Always A"
   292 by (simp add: Always_def)
   293 
   294 lemma AlwaysD: "F : Always A ==> Init F<=A & F : Stable A"
   295 by (simp add: Always_def)
   296 
   297 lemmas AlwaysE = AlwaysD [THEN conjE, standard]
   298 lemmas Always_imp_Stable = AlwaysD [THEN conjunct2, standard]
   299 
   300 
   301 (*The set of all reachable states is Always*)
   302 lemma Always_includes_reachable: "F : Always A ==> reachable F <= A"
   303 apply (simp add: Stable_def Constrains_def constrains_def Always_def)
   304 apply (rule subsetI)
   305 apply (erule reachable.induct)
   306 apply (blast intro: reachable.intros)+
   307 done
   308 
   309 lemma invariant_imp_Always: 
   310      "F : invariant A ==> F : Always A"
   311 apply (unfold Always_def invariant_def Stable_def stable_def)
   312 apply (blast intro: constrains_imp_Constrains)
   313 done
   314 
   315 lemmas Always_reachable =
   316     invariant_reachable [THEN invariant_imp_Always, standard]
   317 
   318 lemma Always_eq_invariant_reachable:
   319      "Always A = {F. F : invariant (reachable F Int A)}"
   320 apply (simp add: Always_def invariant_def Stable_def Constrains_eq_constrains
   321                  stable_def)
   322 apply (blast intro: reachable.intros)
   323 done
   324 
   325 (*the RHS is the traditional definition of the "always" operator*)
   326 lemma Always_eq_includes_reachable: "Always A = {F. reachable F <= A}"
   327 by (auto dest: invariant_includes_reachable simp add: Int_absorb2 invariant_reachable Always_eq_invariant_reachable)
   328 
   329 lemma Always_UNIV_eq [simp]: "Always UNIV = UNIV"
   330 by (auto simp add: Always_eq_includes_reachable)
   331 
   332 lemma UNIV_AlwaysI: "UNIV <= A ==> F : Always A"
   333 by (auto simp add: Always_eq_includes_reachable)
   334 
   335 lemma Always_eq_UN_invariant: "Always A = (UN I: Pow A. invariant I)"
   336 apply (simp add: Always_eq_includes_reachable)
   337 apply (blast intro: invariantI Init_subset_reachable [THEN subsetD] 
   338                     invariant_includes_reachable [THEN subsetD])
   339 done
   340 
   341 lemma Always_weaken: "[| F : Always A; A <= B |] ==> F : Always B"
   342 by (auto simp add: Always_eq_includes_reachable)
   343 
   344 
   345 subsection{*"Co" rules involving Always*}
   346 
   347 lemma Always_Constrains_pre:
   348      "F : Always INV ==> (F : (INV Int A) Co A') = (F : A Co A')"
   349 by (simp add: Always_includes_reachable [THEN Int_absorb2] Constrains_def 
   350               Int_assoc [symmetric])
   351 
   352 lemma Always_Constrains_post:
   353      "F : Always INV ==> (F : A Co (INV Int A')) = (F : A Co A')"
   354 by (simp add: Always_includes_reachable [THEN Int_absorb2] 
   355               Constrains_eq_constrains Int_assoc [symmetric])
   356 
   357 (* [| F : Always INV;  F : (INV Int A) Co A' |] ==> F : A Co A' *)
   358 lemmas Always_ConstrainsI = Always_Constrains_pre [THEN iffD1, standard]
   359 
   360 (* [| F : Always INV;  F : A Co A' |] ==> F : A Co (INV Int A') *)
   361 lemmas Always_ConstrainsD = Always_Constrains_post [THEN iffD2, standard]
   362 
   363 (*The analogous proof of Always_LeadsTo_weaken doesn't terminate*)
   364 lemma Always_Constrains_weaken:
   365      "[| F : Always C;  F : A Co A';    
   366          C Int B <= A;   C Int A' <= B' |]  
   367       ==> F : B Co B'"
   368 apply (rule Always_ConstrainsI, assumption)
   369 apply (drule Always_ConstrainsD, assumption)
   370 apply (blast intro: Constrains_weaken)
   371 done
   372 
   373 
   374 (** Conjoining Always properties **)
   375 
   376 lemma Always_Int_distrib: "Always (A Int B) = Always A Int Always B"
   377 by (auto simp add: Always_eq_includes_reachable)
   378 
   379 lemma Always_INT_distrib: "Always (INTER I A) = (INT i:I. Always (A i))"
   380 by (auto simp add: Always_eq_includes_reachable)
   381 
   382 lemma Always_Int_I:
   383      "[| F : Always A;  F : Always B |] ==> F : Always (A Int B)"
   384 by (simp add: Always_Int_distrib)
   385 
   386 (*Allows a kind of "implication introduction"*)
   387 lemma Always_Compl_Un_eq:
   388      "F : Always A ==> (F : Always (-A Un B)) = (F : Always B)"
   389 by (auto simp add: Always_eq_includes_reachable)
   390 
   391 (*Delete the nearest invariance assumption (which will be the second one
   392   used by Always_Int_I) *)
   393 lemmas Always_thin = thin_rl [of "F : Always A", standard]
   394 
   395 end