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