src/HOL/UNITY/SubstAx.thy
author hoelzl
Thu Sep 02 10:14:32 2010 +0200 (2010-09-02)
changeset 39072 1030b1a166ef
parent 37936 1e4c5015a72e
child 44106 0e018cbcc0de
permissions -rw-r--r--
Add lessThan_Suc_eq_insert_0
     1 (*  Title:      HOL/UNITY/SubstAx.thy
     2     Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
     3     Copyright   1998  University of Cambridge
     4 
     5 Weak LeadsTo relation (restricted to the set of reachable states)
     6 *)
     7 
     8 header{*Weak Progress*}
     9 
    10 theory SubstAx imports WFair Constrains begin
    11 
    12 definition Ensures :: "['a set, 'a set] => 'a program set" (infixl "Ensures" 60) where
    13     "A Ensures B == {F. F \<in> (reachable F \<inter> A) ensures B}"
    14 
    15 definition LeadsTo :: "['a set, 'a set] => 'a program set" (infixl "LeadsTo" 60) where
    16     "A LeadsTo B == {F. F \<in> (reachable F \<inter> A) leadsTo B}"
    17 
    18 notation (xsymbols)
    19   LeadsTo  (infixl " \<longmapsto>w " 60)
    20 
    21 
    22 text{*Resembles the previous definition of LeadsTo*}
    23 lemma LeadsTo_eq_leadsTo: 
    24      "A LeadsTo B = {F. F \<in> (reachable F \<inter> A) leadsTo (reachable F \<inter> B)}"
    25 apply (unfold LeadsTo_def)
    26 apply (blast dest: psp_stable2 intro: leadsTo_weaken)
    27 done
    28 
    29 
    30 subsection{*Specialized laws for handling invariants*}
    31 
    32 (** Conjoining an Always property **)
    33 
    34 lemma Always_LeadsTo_pre:
    35      "F \<in> Always INV ==> (F \<in> (INV \<inter> A) LeadsTo A') = (F \<in> A LeadsTo A')"
    36 by (simp add: LeadsTo_def Always_eq_includes_reachable Int_absorb2 
    37               Int_assoc [symmetric])
    38 
    39 lemma Always_LeadsTo_post:
    40      "F \<in> Always INV ==> (F \<in> A LeadsTo (INV \<inter> A')) = (F \<in> A LeadsTo A')"
    41 by (simp add: LeadsTo_eq_leadsTo Always_eq_includes_reachable Int_absorb2 
    42               Int_assoc [symmetric])
    43 
    44 (* [| F \<in> Always C;  F \<in> (C \<inter> A) LeadsTo A' |] ==> F \<in> A LeadsTo A' *)
    45 lemmas Always_LeadsToI = Always_LeadsTo_pre [THEN iffD1, standard]
    46 
    47 (* [| F \<in> Always INV;  F \<in> A LeadsTo A' |] ==> F \<in> A LeadsTo (INV \<inter> A') *)
    48 lemmas Always_LeadsToD = Always_LeadsTo_post [THEN iffD2, standard]
    49 
    50 
    51 subsection{*Introduction rules: Basis, Trans, Union*}
    52 
    53 lemma leadsTo_imp_LeadsTo: "F \<in> A leadsTo B ==> F \<in> A LeadsTo B"
    54 apply (simp add: LeadsTo_def)
    55 apply (blast intro: leadsTo_weaken_L)
    56 done
    57 
    58 lemma LeadsTo_Trans:
    59      "[| F \<in> A LeadsTo B;  F \<in> B LeadsTo C |] ==> F \<in> A LeadsTo C"
    60 apply (simp add: LeadsTo_eq_leadsTo)
    61 apply (blast intro: leadsTo_Trans)
    62 done
    63 
    64 lemma LeadsTo_Union: 
    65      "(!!A. A \<in> S ==> F \<in> A LeadsTo B) ==> F \<in> (Union S) LeadsTo B"
    66 apply (simp add: LeadsTo_def)
    67 apply (subst Int_Union)
    68 apply (blast intro: leadsTo_UN)
    69 done
    70 
    71 
    72 subsection{*Derived rules*}
    73 
    74 lemma LeadsTo_UNIV [simp]: "F \<in> A LeadsTo UNIV"
    75 by (simp add: LeadsTo_def)
    76 
    77 text{*Useful with cancellation, disjunction*}
    78 lemma LeadsTo_Un_duplicate:
    79      "F \<in> A LeadsTo (A' \<union> A') ==> F \<in> A LeadsTo A'"
    80 by (simp add: Un_ac)
    81 
    82 lemma LeadsTo_Un_duplicate2:
    83      "F \<in> A LeadsTo (A' \<union> C \<union> C) ==> F \<in> A LeadsTo (A' \<union> C)"
    84 by (simp add: Un_ac)
    85 
    86 lemma LeadsTo_UN: 
    87      "(!!i. i \<in> I ==> F \<in> (A i) LeadsTo B) ==> F \<in> (\<Union>i \<in> I. A i) LeadsTo B"
    88 apply (simp only: Union_image_eq [symmetric])
    89 apply (blast intro: LeadsTo_Union)
    90 done
    91 
    92 text{*Binary union introduction rule*}
    93 lemma LeadsTo_Un:
    94      "[| F \<in> A LeadsTo C; F \<in> B LeadsTo C |] ==> F \<in> (A \<union> B) LeadsTo C"
    95 apply (subst Un_eq_Union)
    96 apply (blast intro: LeadsTo_Union)
    97 done
    98 
    99 text{*Lets us look at the starting state*}
   100 lemma single_LeadsTo_I:
   101      "(!!s. s \<in> A ==> F \<in> {s} LeadsTo B) ==> F \<in> A LeadsTo B"
   102 by (subst UN_singleton [symmetric], rule LeadsTo_UN, blast)
   103 
   104 lemma subset_imp_LeadsTo: "A \<subseteq> B ==> F \<in> A LeadsTo B"
   105 apply (simp add: LeadsTo_def)
   106 apply (blast intro: subset_imp_leadsTo)
   107 done
   108 
   109 lemmas empty_LeadsTo = empty_subsetI [THEN subset_imp_LeadsTo, standard, simp]
   110 
   111 lemma LeadsTo_weaken_R [rule_format]:
   112      "[| F \<in> A LeadsTo A';  A' \<subseteq> B' |] ==> F \<in> A LeadsTo B'"
   113 apply (simp add: LeadsTo_def)
   114 apply (blast intro: leadsTo_weaken_R)
   115 done
   116 
   117 lemma LeadsTo_weaken_L [rule_format]:
   118      "[| F \<in> A LeadsTo A';  B \<subseteq> A |]   
   119       ==> F \<in> B LeadsTo A'"
   120 apply (simp add: LeadsTo_def)
   121 apply (blast intro: leadsTo_weaken_L)
   122 done
   123 
   124 lemma LeadsTo_weaken:
   125      "[| F \<in> A LeadsTo A';    
   126          B  \<subseteq> A;   A' \<subseteq> B' |]  
   127       ==> F \<in> B LeadsTo B'"
   128 by (blast intro: LeadsTo_weaken_R LeadsTo_weaken_L LeadsTo_Trans)
   129 
   130 lemma Always_LeadsTo_weaken:
   131      "[| F \<in> Always C;  F \<in> A LeadsTo A';    
   132          C \<inter> B \<subseteq> A;   C \<inter> A' \<subseteq> B' |]  
   133       ==> F \<in> B LeadsTo B'"
   134 by (blast dest: Always_LeadsToI intro: LeadsTo_weaken intro: Always_LeadsToD)
   135 
   136 (** Two theorems for "proof lattices" **)
   137 
   138 lemma LeadsTo_Un_post: "F \<in> A LeadsTo B ==> F \<in> (A \<union> B) LeadsTo B"
   139 by (blast intro: LeadsTo_Un subset_imp_LeadsTo)
   140 
   141 lemma LeadsTo_Trans_Un:
   142      "[| F \<in> A LeadsTo B;  F \<in> B LeadsTo C |]  
   143       ==> F \<in> (A \<union> B) LeadsTo C"
   144 by (blast intro: LeadsTo_Un subset_imp_LeadsTo LeadsTo_weaken_L LeadsTo_Trans)
   145 
   146 
   147 (** Distributive laws **)
   148 
   149 lemma LeadsTo_Un_distrib:
   150      "(F \<in> (A \<union> B) LeadsTo C)  = (F \<in> A LeadsTo C & F \<in> B LeadsTo C)"
   151 by (blast intro: LeadsTo_Un LeadsTo_weaken_L)
   152 
   153 lemma LeadsTo_UN_distrib:
   154      "(F \<in> (\<Union>i \<in> I. A i) LeadsTo B)  =  (\<forall>i \<in> I. F \<in> (A i) LeadsTo B)"
   155 by (blast intro: LeadsTo_UN LeadsTo_weaken_L)
   156 
   157 lemma LeadsTo_Union_distrib:
   158      "(F \<in> (Union S) LeadsTo B)  =  (\<forall>A \<in> S. F \<in> A LeadsTo B)"
   159 by (blast intro: LeadsTo_Union LeadsTo_weaken_L)
   160 
   161 
   162 (** More rules using the premise "Always INV" **)
   163 
   164 lemma LeadsTo_Basis: "F \<in> A Ensures B ==> F \<in> A LeadsTo B"
   165 by (simp add: Ensures_def LeadsTo_def leadsTo_Basis)
   166 
   167 lemma EnsuresI:
   168      "[| F \<in> (A-B) Co (A \<union> B);  F \<in> transient (A-B) |]    
   169       ==> F \<in> A Ensures B"
   170 apply (simp add: Ensures_def Constrains_eq_constrains)
   171 apply (blast intro: ensuresI constrains_weaken transient_strengthen)
   172 done
   173 
   174 lemma Always_LeadsTo_Basis:
   175      "[| F \<in> Always INV;       
   176          F \<in> (INV \<inter> (A-A')) Co (A \<union> A');  
   177          F \<in> transient (INV \<inter> (A-A')) |]    
   178   ==> F \<in> A LeadsTo A'"
   179 apply (rule Always_LeadsToI, assumption)
   180 apply (blast intro: EnsuresI LeadsTo_Basis Always_ConstrainsD [THEN Constrains_weaken] transient_strengthen)
   181 done
   182 
   183 text{*Set difference: maybe combine with @{text leadsTo_weaken_L}??
   184   This is the most useful form of the "disjunction" rule*}
   185 lemma LeadsTo_Diff:
   186      "[| F \<in> (A-B) LeadsTo C;  F \<in> (A \<inter> B) LeadsTo C |]  
   187       ==> F \<in> A LeadsTo C"
   188 by (blast intro: LeadsTo_Un LeadsTo_weaken)
   189 
   190 
   191 lemma LeadsTo_UN_UN: 
   192      "(!! i. i \<in> I ==> F \<in> (A i) LeadsTo (A' i))  
   193       ==> F \<in> (\<Union>i \<in> I. A i) LeadsTo (\<Union>i \<in> I. A' i)"
   194 apply (simp only: Union_image_eq [symmetric])
   195 apply (blast intro: LeadsTo_Union LeadsTo_weaken_R)
   196 done
   197 
   198 
   199 text{*Version with no index set*}
   200 lemma LeadsTo_UN_UN_noindex: 
   201      "(!!i. F \<in> (A i) LeadsTo (A' i)) ==> F \<in> (\<Union>i. A i) LeadsTo (\<Union>i. A' i)"
   202 by (blast intro: LeadsTo_UN_UN)
   203 
   204 text{*Version with no index set*}
   205 lemma all_LeadsTo_UN_UN:
   206      "\<forall>i. F \<in> (A i) LeadsTo (A' i)  
   207       ==> F \<in> (\<Union>i. A i) LeadsTo (\<Union>i. A' i)"
   208 by (blast intro: LeadsTo_UN_UN)
   209 
   210 text{*Binary union version*}
   211 lemma LeadsTo_Un_Un:
   212      "[| F \<in> A LeadsTo A'; F \<in> B LeadsTo B' |]  
   213             ==> F \<in> (A \<union> B) LeadsTo (A' \<union> B')"
   214 by (blast intro: LeadsTo_Un LeadsTo_weaken_R)
   215 
   216 
   217 (** The cancellation law **)
   218 
   219 lemma LeadsTo_cancel2:
   220      "[| F \<in> A LeadsTo (A' \<union> B); F \<in> B LeadsTo B' |]     
   221       ==> F \<in> A LeadsTo (A' \<union> B')"
   222 by (blast intro: LeadsTo_Un_Un subset_imp_LeadsTo LeadsTo_Trans)
   223 
   224 lemma LeadsTo_cancel_Diff2:
   225      "[| F \<in> A LeadsTo (A' \<union> B); F \<in> (B-A') LeadsTo B' |]  
   226       ==> F \<in> A LeadsTo (A' \<union> B')"
   227 apply (rule LeadsTo_cancel2)
   228 prefer 2 apply assumption
   229 apply (simp_all (no_asm_simp))
   230 done
   231 
   232 lemma LeadsTo_cancel1:
   233      "[| F \<in> A LeadsTo (B \<union> A'); F \<in> B LeadsTo B' |]  
   234       ==> F \<in> A LeadsTo (B' \<union> A')"
   235 apply (simp add: Un_commute)
   236 apply (blast intro!: LeadsTo_cancel2)
   237 done
   238 
   239 lemma LeadsTo_cancel_Diff1:
   240      "[| F \<in> A LeadsTo (B \<union> A'); F \<in> (B-A') LeadsTo B' |]  
   241       ==> F \<in> A LeadsTo (B' \<union> A')"
   242 apply (rule LeadsTo_cancel1)
   243 prefer 2 apply assumption
   244 apply (simp_all (no_asm_simp))
   245 done
   246 
   247 
   248 text{*The impossibility law*}
   249 
   250 text{*The set "A" may be non-empty, but it contains no reachable states*}
   251 lemma LeadsTo_empty: "[|F \<in> A LeadsTo {}; all_total F|] ==> F \<in> Always (-A)"
   252 apply (simp add: LeadsTo_def Always_eq_includes_reachable)
   253 apply (drule leadsTo_empty, auto)
   254 done
   255 
   256 
   257 subsection{*PSP: Progress-Safety-Progress*}
   258 
   259 text{*Special case of PSP: Misra's "stable conjunction"*}
   260 lemma PSP_Stable:
   261      "[| F \<in> A LeadsTo A';  F \<in> Stable B |]  
   262       ==> F \<in> (A \<inter> B) LeadsTo (A' \<inter> B)"
   263 apply (simp add: LeadsTo_eq_leadsTo Stable_eq_stable)
   264 apply (drule psp_stable, assumption)
   265 apply (simp add: Int_ac)
   266 done
   267 
   268 lemma PSP_Stable2:
   269      "[| F \<in> A LeadsTo A'; F \<in> Stable B |]  
   270       ==> F \<in> (B \<inter> A) LeadsTo (B \<inter> A')"
   271 by (simp add: PSP_Stable Int_ac)
   272 
   273 lemma PSP:
   274      "[| F \<in> A LeadsTo A'; F \<in> B Co B' |]  
   275       ==> F \<in> (A \<inter> B') LeadsTo ((A' \<inter> B) \<union> (B' - B))"
   276 apply (simp add: LeadsTo_def Constrains_eq_constrains)
   277 apply (blast dest: psp intro: leadsTo_weaken)
   278 done
   279 
   280 lemma PSP2:
   281      "[| F \<in> A LeadsTo A'; F \<in> B Co B' |]  
   282       ==> F \<in> (B' \<inter> A) LeadsTo ((B \<inter> A') \<union> (B' - B))"
   283 by (simp add: PSP Int_ac)
   284 
   285 lemma PSP_Unless: 
   286      "[| F \<in> A LeadsTo A'; F \<in> B Unless B' |]  
   287       ==> F \<in> (A \<inter> B) LeadsTo ((A' \<inter> B) \<union> B')"
   288 apply (unfold Unless_def)
   289 apply (drule PSP, assumption)
   290 apply (blast intro: LeadsTo_Diff LeadsTo_weaken subset_imp_LeadsTo)
   291 done
   292 
   293 
   294 lemma Stable_transient_Always_LeadsTo:
   295      "[| F \<in> Stable A;  F \<in> transient C;   
   296          F \<in> Always (-A \<union> B \<union> C) |] ==> F \<in> A LeadsTo B"
   297 apply (erule Always_LeadsTo_weaken)
   298 apply (rule LeadsTo_Diff)
   299    prefer 2
   300    apply (erule
   301           transient_imp_leadsTo [THEN leadsTo_imp_LeadsTo, THEN PSP_Stable2])
   302    apply (blast intro: subset_imp_LeadsTo)+
   303 done
   304 
   305 
   306 subsection{*Induction rules*}
   307 
   308 (** Meta or object quantifier ????? **)
   309 lemma LeadsTo_wf_induct:
   310      "[| wf r;      
   311          \<forall>m. F \<in> (A \<inter> f-`{m}) LeadsTo                      
   312                     ((A \<inter> f-`(r^-1 `` {m})) \<union> B) |]  
   313       ==> F \<in> A LeadsTo B"
   314 apply (simp add: LeadsTo_eq_leadsTo)
   315 apply (erule leadsTo_wf_induct)
   316 apply (blast intro: leadsTo_weaken)
   317 done
   318 
   319 
   320 lemma Bounded_induct:
   321      "[| wf r;      
   322          \<forall>m \<in> I. F \<in> (A \<inter> f-`{m}) LeadsTo                    
   323                       ((A \<inter> f-`(r^-1 `` {m})) \<union> B) |]  
   324       ==> F \<in> A LeadsTo ((A - (f-`I)) \<union> B)"
   325 apply (erule LeadsTo_wf_induct, safe)
   326 apply (case_tac "m \<in> I")
   327 apply (blast intro: LeadsTo_weaken)
   328 apply (blast intro: subset_imp_LeadsTo)
   329 done
   330 
   331 
   332 lemma LessThan_induct:
   333      "(!!m::nat. F \<in> (A \<inter> f-`{m}) LeadsTo ((A \<inter> f-`(lessThan m)) \<union> B))
   334       ==> F \<in> A LeadsTo B"
   335 by (rule wf_less_than [THEN LeadsTo_wf_induct], auto)
   336 
   337 text{*Integer version.  Could generalize from 0 to any lower bound*}
   338 lemma integ_0_le_induct:
   339      "[| F \<in> Always {s. (0::int) \<le> f s};   
   340          !! z. F \<in> (A \<inter> {s. f s = z}) LeadsTo                      
   341                    ((A \<inter> {s. f s < z}) \<union> B) |]  
   342       ==> F \<in> A LeadsTo B"
   343 apply (rule_tac f = "nat o f" in LessThan_induct)
   344 apply (simp add: vimage_def)
   345 apply (rule Always_LeadsTo_weaken, assumption+)
   346 apply (auto simp add: nat_eq_iff nat_less_iff)
   347 done
   348 
   349 lemma LessThan_bounded_induct:
   350      "!!l::nat. \<forall>m \<in> greaterThan l. 
   351                    F \<in> (A \<inter> f-`{m}) LeadsTo ((A \<inter> f-`(lessThan m)) \<union> B)
   352             ==> F \<in> A LeadsTo ((A \<inter> (f-`(atMost l))) \<union> B)"
   353 apply (simp only: Diff_eq [symmetric] vimage_Compl 
   354                   Compl_greaterThan [symmetric])
   355 apply (rule wf_less_than [THEN Bounded_induct], simp)
   356 done
   357 
   358 lemma GreaterThan_bounded_induct:
   359      "!!l::nat. \<forall>m \<in> lessThan l. 
   360                  F \<in> (A \<inter> f-`{m}) LeadsTo ((A \<inter> f-`(greaterThan m)) \<union> B)
   361       ==> F \<in> A LeadsTo ((A \<inter> (f-`(atLeast l))) \<union> B)"
   362 apply (rule_tac f = f and f1 = "%k. l - k" 
   363        in wf_less_than [THEN wf_inv_image, THEN LeadsTo_wf_induct])
   364 apply (simp add: Image_singleton, clarify)
   365 apply (case_tac "m<l")
   366  apply (blast intro: LeadsTo_weaken_R diff_less_mono2)
   367 apply (blast intro: not_leE subset_imp_LeadsTo)
   368 done
   369 
   370 
   371 subsection{*Completion: Binary and General Finite versions*}
   372 
   373 lemma Completion:
   374      "[| F \<in> A LeadsTo (A' \<union> C);  F \<in> A' Co (A' \<union> C);  
   375          F \<in> B LeadsTo (B' \<union> C);  F \<in> B' Co (B' \<union> C) |]  
   376       ==> F \<in> (A \<inter> B) LeadsTo ((A' \<inter> B') \<union> C)"
   377 apply (simp add: LeadsTo_eq_leadsTo Constrains_eq_constrains Int_Un_distrib)
   378 apply (blast intro: completion leadsTo_weaken)
   379 done
   380 
   381 lemma Finite_completion_lemma:
   382      "finite I  
   383       ==> (\<forall>i \<in> I. F \<in> (A i) LeadsTo (A' i \<union> C)) -->   
   384           (\<forall>i \<in> I. F \<in> (A' i) Co (A' i \<union> C)) -->  
   385           F \<in> (\<Inter>i \<in> I. A i) LeadsTo ((\<Inter>i \<in> I. A' i) \<union> C)"
   386 apply (erule finite_induct, auto)
   387 apply (rule Completion)
   388    prefer 4
   389    apply (simp only: INT_simps [symmetric])
   390    apply (rule Constrains_INT, auto)
   391 done
   392 
   393 lemma Finite_completion: 
   394      "[| finite I;   
   395          !!i. i \<in> I ==> F \<in> (A i) LeadsTo (A' i \<union> C);  
   396          !!i. i \<in> I ==> F \<in> (A' i) Co (A' i \<union> C) |]    
   397       ==> F \<in> (\<Inter>i \<in> I. A i) LeadsTo ((\<Inter>i \<in> I. A' i) \<union> C)"
   398 by (blast intro: Finite_completion_lemma [THEN mp, THEN mp])
   399 
   400 lemma Stable_completion: 
   401      "[| F \<in> A LeadsTo A';  F \<in> Stable A';    
   402          F \<in> B LeadsTo B';  F \<in> Stable B' |]  
   403       ==> F \<in> (A \<inter> B) LeadsTo (A' \<inter> B')"
   404 apply (unfold Stable_def)
   405 apply (rule_tac C1 = "{}" in Completion [THEN LeadsTo_weaken_R])
   406 apply (force+)
   407 done
   408 
   409 lemma Finite_stable_completion: 
   410      "[| finite I;   
   411          !!i. i \<in> I ==> F \<in> (A i) LeadsTo (A' i);  
   412          !!i. i \<in> I ==> F \<in> Stable (A' i) |]    
   413       ==> F \<in> (\<Inter>i \<in> I. A i) LeadsTo (\<Inter>i \<in> I. A' i)"
   414 apply (unfold Stable_def)
   415 apply (rule_tac C1 = "{}" in Finite_completion [THEN LeadsTo_weaken_R])
   416 apply (simp_all, blast+)
   417 done
   418 
   419 end