src/HOL/UNITY/ProgressSets.thy
author hoelzl
Fri Feb 19 13:40:50 2016 +0100 (2016-02-19)
changeset 62378 85ed00c1fe7c
parent 62343 24106dc44def
child 63146 f1ecba0272f9
permissions -rw-r--r--
generalize more theorems to support enat and ennreal
     1 (*  Title:      HOL/UNITY/ProgressSets.thy
     2     Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
     3     Copyright   2003  University of Cambridge
     4 
     5 Progress Sets.  From 
     6 
     7     David Meier and Beverly Sanders,
     8     Composing Leads-to Properties
     9     Theoretical Computer Science 243:1-2 (2000), 339-361.
    10 
    11     David Meier,
    12     Progress Properties in Program Refinement and Parallel Composition
    13     Swiss Federal Institute of Technology Zurich (1997)
    14 *)
    15 
    16 section{*Progress Sets*}
    17 
    18 theory ProgressSets imports Transformers begin
    19 
    20 subsection {*Complete Lattices and the Operator @{term cl}*}
    21 
    22 definition lattice :: "'a set set => bool" where
    23    --{*Meier calls them closure sets, but they are just complete lattices*}
    24    "lattice L ==
    25          (\<forall>M. M \<subseteq> L --> \<Inter>M \<in> L) & (\<forall>M. M \<subseteq> L --> \<Union>M \<in> L)"
    26 
    27 definition cl :: "['a set set, 'a set] => 'a set" where
    28    --{*short for ``closure''*}
    29    "cl L r == \<Inter>{x. x\<in>L & r \<subseteq> x}"
    30 
    31 lemma UNIV_in_lattice: "lattice L ==> UNIV \<in> L"
    32 by (force simp add: lattice_def)
    33 
    34 lemma empty_in_lattice: "lattice L ==> {} \<in> L"
    35 by (force simp add: lattice_def)
    36 
    37 lemma Union_in_lattice: "[|M \<subseteq> L; lattice L|] ==> \<Union>M \<in> L"
    38 by (simp add: lattice_def)
    39 
    40 lemma Inter_in_lattice: "[|M \<subseteq> L; lattice L|] ==> \<Inter>M \<in> L"
    41 by (simp add: lattice_def)
    42 
    43 lemma UN_in_lattice:
    44      "[|lattice L; !!i. i\<in>I ==> r i \<in> L|] ==> (\<Union>i\<in>I. r i) \<in> L"
    45 apply (blast intro: Union_in_lattice) 
    46 done
    47 
    48 lemma INT_in_lattice:
    49      "[|lattice L; !!i. i\<in>I ==> r i \<in> L|] ==> (\<Inter>i\<in>I. r i)  \<in> L"
    50 apply (blast intro: Inter_in_lattice) 
    51 done
    52 
    53 lemma Un_in_lattice: "[|x\<in>L; y\<in>L; lattice L|] ==> x\<union>y \<in> L"
    54   using Union_in_lattice [of "{x, y}" L] by simp
    55 
    56 lemma Int_in_lattice: "[|x\<in>L; y\<in>L; lattice L|] ==> x\<inter>y \<in> L"
    57   using Inter_in_lattice [of "{x, y}" L] by simp
    58 
    59 lemma lattice_stable: "lattice {X. F \<in> stable X}"
    60 by (simp add: lattice_def stable_def constrains_def, blast)
    61 
    62 text{*The next three results state that @{term "cl L r"} is the minimal
    63  element of @{term L} that includes @{term r}.*}
    64 lemma cl_in_lattice: "lattice L ==> cl L r \<in> L"
    65 apply (simp add: lattice_def cl_def)
    66 apply (erule conjE)  
    67 apply (drule spec, erule mp, blast) 
    68 done
    69 
    70 lemma cl_least: "[|c\<in>L; r\<subseteq>c|] ==> cl L r \<subseteq> c" 
    71 by (force simp add: cl_def)
    72 
    73 text{*The next three lemmas constitute assertion (4.61)*}
    74 lemma cl_mono: "r \<subseteq> r' ==> cl L r \<subseteq> cl L r'"
    75 by (simp add: cl_def, blast)
    76 
    77 lemma subset_cl: "r \<subseteq> cl L r"
    78 by (simp add: cl_def le_Inf_iff)
    79 
    80 text{*A reformulation of @{thm subset_cl}*}
    81 lemma clI: "x \<in> r ==> x \<in> cl L r"
    82 by (simp add: cl_def, blast)
    83 
    84 text{*A reformulation of @{thm cl_least}*}
    85 lemma clD: "[|c \<in> cl L r; B \<in> L; r \<subseteq> B|] ==> c \<in> B"
    86 by (force simp add: cl_def)
    87 
    88 lemma cl_UN_subset: "(\<Union>i\<in>I. cl L (r i)) \<subseteq> cl L (\<Union>i\<in>I. r i)"
    89 by (simp add: cl_def, blast)
    90 
    91 lemma cl_Un: "lattice L ==> cl L (r\<union>s) = cl L r \<union> cl L s"
    92 apply (rule equalityI) 
    93  prefer 2 
    94   apply (simp add: cl_def, blast)
    95 apply (rule cl_least)
    96  apply (blast intro: Un_in_lattice cl_in_lattice)
    97 apply (blast intro: subset_cl [THEN subsetD])  
    98 done
    99 
   100 lemma cl_UN: "lattice L ==> cl L (\<Union>i\<in>I. r i) = (\<Union>i\<in>I. cl L (r i))"
   101 apply (rule equalityI) 
   102  prefer 2 apply (simp add: cl_def, blast)
   103 apply (rule cl_least)
   104  apply (blast intro: UN_in_lattice cl_in_lattice)
   105 apply (blast intro: subset_cl [THEN subsetD])  
   106 done
   107 
   108 lemma cl_Int_subset: "cl L (r\<inter>s) \<subseteq> cl L r \<inter> cl L s"
   109 by (simp add: cl_def, blast)
   110 
   111 lemma cl_idem [simp]: "cl L (cl L r) = cl L r"
   112 by (simp add: cl_def, blast)
   113 
   114 lemma cl_ident: "r\<in>L ==> cl L r = r" 
   115 by (force simp add: cl_def)
   116 
   117 lemma cl_empty [simp]: "lattice L ==> cl L {} = {}"
   118 by (simp add: cl_ident empty_in_lattice)
   119 
   120 lemma cl_UNIV [simp]: "lattice L ==> cl L UNIV = UNIV"
   121 by (simp add: cl_ident UNIV_in_lattice)
   122 
   123 text{*Assertion (4.62)*}
   124 lemma cl_ident_iff: "lattice L ==> (cl L r = r) = (r\<in>L)" 
   125 apply (rule iffI) 
   126  apply (erule subst)
   127  apply (erule cl_in_lattice)  
   128 apply (erule cl_ident) 
   129 done
   130 
   131 lemma cl_subset_in_lattice: "[|cl L r \<subseteq> r; lattice L|] ==> r\<in>L" 
   132 by (simp add: cl_ident_iff [symmetric] equalityI subset_cl)
   133 
   134 
   135 subsection {*Progress Sets and the Main Lemma*}
   136 text{*A progress set satisfies certain closure conditions and is a 
   137 simple way of including the set @{term "wens_set F B"}.*}
   138 
   139 definition closed :: "['a program, 'a set, 'a set,  'a set set] => bool" where
   140    "closed F T B L == \<forall>M. \<forall>act \<in> Acts F. B\<subseteq>M & T\<inter>M \<in> L -->
   141                               T \<inter> (B \<union> wp act M) \<in> L"
   142 
   143 definition progress_set :: "['a program, 'a set, 'a set] => 'a set set set" where
   144    "progress_set F T B ==
   145       {L. lattice L & B \<in> L & T \<in> L & closed F T B L}"
   146 
   147 lemma closedD:
   148    "[|closed F T B L; act \<in> Acts F; B\<subseteq>M; T\<inter>M \<in> L|] 
   149     ==> T \<inter> (B \<union> wp act M) \<in> L" 
   150 by (simp add: closed_def) 
   151 
   152 text{*Note: the formalization below replaces Meier's @{term q} by @{term B}
   153 and @{term m} by @{term X}. *}
   154 
   155 text{*Part of the proof of the claim at the bottom of page 97.  It's
   156 proved separately because the argument requires a generalization over
   157 all @{term "act \<in> Acts F"}.*}
   158 lemma lattice_awp_lemma:
   159   assumes TXC:  "T\<inter>X \<in> C" --{*induction hypothesis in theorem below*}
   160       and BsubX:  "B \<subseteq> X"   --{*holds in inductive step*}
   161       and latt: "lattice C"
   162       and TC:   "T \<in> C"
   163       and BC:   "B \<in> C"
   164       and clos: "closed F T B C"
   165     shows "T \<inter> (B \<union> awp F (X \<union> cl C (T\<inter>r))) \<in> C"
   166 apply (simp del: INT_simps add: awp_def INT_extend_simps) 
   167 apply (rule INT_in_lattice [OF latt]) 
   168 apply (erule closedD [OF clos]) 
   169 apply (simp add: subset_trans [OF BsubX Un_upper1]) 
   170 apply (subgoal_tac "T \<inter> (X \<union> cl C (T\<inter>r)) = (T\<inter>X) \<union> cl C (T\<inter>r)")
   171  prefer 2 apply (blast intro: TC clD) 
   172 apply (erule ssubst) 
   173 apply (blast intro: Un_in_lattice latt cl_in_lattice TXC) 
   174 done
   175 
   176 text{*Remainder of the proof of the claim at the bottom of page 97.*}
   177 lemma lattice_lemma:
   178   assumes TXC:  "T\<inter>X \<in> C" --{*induction hypothesis in theorem below*}
   179       and BsubX:  "B \<subseteq> X"   --{*holds in inductive step*}
   180       and act:  "act \<in> Acts F"
   181       and latt: "lattice C"
   182       and TC:   "T \<in> C"
   183       and BC:   "B \<in> C"
   184       and clos: "closed F T B C"
   185     shows "T \<inter> (wp act X \<inter> awp F (X \<union> cl C (T\<inter>r)) \<union> X) \<in> C"
   186 apply (subgoal_tac "T \<inter> (B \<union> wp act X) \<in> C")
   187  prefer 2 apply (simp add: closedD [OF clos] act BsubX TXC)
   188 apply (drule Int_in_lattice
   189               [OF _ lattice_awp_lemma [OF TXC BsubX latt TC BC clos, of r]
   190                     latt])
   191 apply (subgoal_tac
   192          "T \<inter> (B \<union> wp act X) \<inter> (T \<inter> (B \<union> awp F (X \<union> cl C (T\<inter>r)))) = 
   193           T \<inter> (B \<union> wp act X \<inter> awp F (X \<union> cl C (T\<inter>r)))") 
   194  prefer 2 apply blast 
   195 apply simp  
   196 apply (drule Un_in_lattice [OF _ TXC latt])  
   197 apply (subgoal_tac
   198          "T \<inter> (B \<union> wp act X \<inter> awp F (X \<union> cl C (T\<inter>r))) \<union> T\<inter>X = 
   199           T \<inter> (wp act X \<inter> awp F (X \<union> cl C (T\<inter>r)) \<union> X)")
   200  apply simp 
   201 apply (blast intro: BsubX [THEN subsetD]) 
   202 done
   203 
   204 
   205 text{*Induction step for the main lemma*}
   206 lemma progress_induction_step:
   207   assumes TXC:  "T\<inter>X \<in> C" --{*induction hypothesis in theorem below*}
   208       and act:  "act \<in> Acts F"
   209       and Xwens: "X \<in> wens_set F B"
   210       and latt: "lattice C"
   211       and  TC:  "T \<in> C"
   212       and  BC:  "B \<in> C"
   213       and clos: "closed F T B C"
   214       and Fstable: "F \<in> stable T"
   215   shows "T \<inter> wens F act X \<in> C"
   216 proof -
   217   from Xwens have BsubX: "B \<subseteq> X"
   218     by (rule wens_set_imp_subset) 
   219   let ?r = "wens F act X"
   220   have "?r \<subseteq> (wp act X \<inter> awp F (X\<union>?r)) \<union> X"
   221     by (simp add: wens_unfold [symmetric])
   222   then have "T\<inter>?r \<subseteq> T \<inter> ((wp act X \<inter> awp F (X\<union>?r)) \<union> X)"
   223     by blast
   224   then have "T\<inter>?r \<subseteq> T \<inter> ((wp act X \<inter> awp F (T \<inter> (X\<union>?r))) \<union> X)"
   225     by (simp add: awp_Int_eq Fstable stable_imp_awp_ident, blast) 
   226   then have "T\<inter>?r \<subseteq> T \<inter> ((wp act X \<inter> awp F (X \<union> cl C (T\<inter>?r))) \<union> X)"
   227     by (blast intro: awp_mono [THEN [2] rev_subsetD] subset_cl [THEN subsetD])
   228   then have "cl C (T\<inter>?r) \<subseteq> 
   229              cl C (T \<inter> ((wp act X \<inter> awp F (X \<union> cl C (T\<inter>?r))) \<union> X))"
   230     by (rule cl_mono) 
   231   then have "cl C (T\<inter>?r) \<subseteq> 
   232              T \<inter> ((wp act X \<inter> awp F (X \<union> cl C (T\<inter>?r))) \<union> X)"
   233     by (simp add: cl_ident lattice_lemma [OF TXC BsubX act latt TC BC clos])
   234   then have "cl C (T\<inter>?r) \<subseteq> (wp act X \<inter> awp F (X \<union> cl C (T\<inter>?r))) \<union> X"
   235     by blast
   236   then have "cl C (T\<inter>?r) \<subseteq> ?r"
   237     by (blast intro!: subset_wens) 
   238   then have cl_subset: "cl C (T\<inter>?r) \<subseteq> T\<inter>?r"
   239     by (simp add: cl_ident TC
   240                   subset_trans [OF cl_mono [OF Int_lower1]]) 
   241   show ?thesis
   242     by (rule cl_subset_in_lattice [OF cl_subset latt]) 
   243 qed
   244 
   245 text{*Proved on page 96 of Meier's thesis.  The special case when
   246    @{term "T=UNIV"} states that every progress set for the program @{term F}
   247    and set @{term B} includes the set @{term "wens_set F B"}.*}
   248 lemma progress_set_lemma:
   249      "[|C \<in> progress_set F T B; r \<in> wens_set F B; F \<in> stable T|] ==> T\<inter>r \<in> C"
   250 apply (simp add: progress_set_def, clarify) 
   251 apply (erule wens_set.induct) 
   252   txt{*Base*}
   253   apply (simp add: Int_in_lattice) 
   254  txt{*The difficult @{term wens} case*}
   255  apply (simp add: progress_induction_step) 
   256 txt{*Disjunctive case*}
   257 apply (subgoal_tac "(\<Union>U\<in>W. T \<inter> U) \<in> C") 
   258  apply simp 
   259 apply (blast intro: UN_in_lattice) 
   260 done
   261 
   262 
   263 subsection {*The Progress Set Union Theorem*}
   264 
   265 lemma closed_mono:
   266   assumes BB':  "B \<subseteq> B'"
   267       and TBwp: "T \<inter> (B \<union> wp act M) \<in> C"
   268       and B'C:  "B' \<in> C"
   269       and TC:   "T \<in> C"
   270       and latt: "lattice C"
   271   shows "T \<inter> (B' \<union> wp act M) \<in> C"
   272 proof -
   273   from TBwp have "(T\<inter>B) \<union> (T \<inter> wp act M) \<in> C"
   274     by (simp add: Int_Un_distrib)
   275   then have TBBC: "(T\<inter>B') \<union> ((T\<inter>B) \<union> (T \<inter> wp act M)) \<in> C"
   276     by (blast intro: Int_in_lattice Un_in_lattice TC B'C latt) 
   277   show ?thesis
   278     by (rule eqelem_imp_iff [THEN iffD1, OF _ TBBC], 
   279         blast intro: BB' [THEN subsetD]) 
   280 qed
   281 
   282 
   283 lemma progress_set_mono:
   284     assumes BB':  "B \<subseteq> B'"
   285     shows
   286      "[| B' \<in> C;  C \<in> progress_set F T B|] 
   287       ==> C \<in> progress_set F T B'"
   288 by (simp add: progress_set_def closed_def closed_mono [OF BB'] 
   289                  subset_trans [OF BB']) 
   290 
   291 theorem progress_set_Union:
   292   assumes leadsTo: "F \<in> A leadsTo B'"
   293       and prog: "C \<in> progress_set F T B"
   294       and Fstable: "F \<in> stable T"
   295       and BB':  "B \<subseteq> B'"
   296       and B'C:  "B' \<in> C"
   297       and Gco: "!!X. X\<in>C ==> G \<in> X-B co X"
   298   shows "F\<squnion>G \<in> T\<inter>A leadsTo B'"
   299 apply (insert prog Fstable) 
   300 apply (rule leadsTo_Join [OF leadsTo]) 
   301   apply (force simp add: progress_set_def awp_iff_stable [symmetric]) 
   302 apply (simp add: awp_iff_constrains)
   303 apply (drule progress_set_mono [OF BB' B'C]) 
   304 apply (blast intro: progress_set_lemma Gco constrains_weaken_L 
   305                     BB' [THEN subsetD]) 
   306 done
   307 
   308 
   309 subsection {*Some Progress Sets*}
   310 
   311 lemma UNIV_in_progress_set: "UNIV \<in> progress_set F T B"
   312 by (simp add: progress_set_def lattice_def closed_def)
   313 
   314 
   315 
   316 subsubsection {*Lattices and Relations*}
   317 text{*From Meier's thesis, section 4.5.3*}
   318 
   319 definition relcl :: "'a set set => ('a * 'a) set" where
   320     -- {*Derived relation from a lattice*}
   321     "relcl L == {(x,y). y \<in> cl L {x}}"
   322   
   323 definition latticeof :: "('a * 'a) set => 'a set set" where
   324     -- {*Derived lattice from a relation: the set of upwards-closed sets*}
   325     "latticeof r == {X. \<forall>s t. s \<in> X & (s,t) \<in> r --> t \<in> X}"
   326 
   327 
   328 lemma relcl_refl: "(a,a) \<in> relcl L"
   329 by (simp add: relcl_def subset_cl [THEN subsetD])
   330 
   331 lemma relcl_trans:
   332      "[| (a,b) \<in> relcl L; (b,c) \<in> relcl L; lattice L |] ==> (a,c) \<in> relcl L"
   333 apply (simp add: relcl_def)
   334 apply (blast intro: clD cl_in_lattice)
   335 done
   336 
   337 lemma refl_relcl: "lattice L ==> refl (relcl L)"
   338 by (simp add: refl_onI relcl_def subset_cl [THEN subsetD])
   339 
   340 lemma trans_relcl: "lattice L ==> trans (relcl L)"
   341 by (blast intro: relcl_trans transI)
   342 
   343 lemma lattice_latticeof: "lattice (latticeof r)"
   344 by (auto simp add: lattice_def latticeof_def)
   345 
   346 lemma lattice_singletonI:
   347      "[|lattice L; !!s. s \<in> X ==> {s} \<in> L|] ==> X \<in> L"
   348 apply (cut_tac UN_singleton [of X]) 
   349 apply (erule subst) 
   350 apply (simp only: UN_in_lattice) 
   351 done
   352 
   353 text{*Equation (4.71) of Meier's thesis.  He gives no proof.*}
   354 lemma cl_latticeof:
   355      "[|refl r; trans r|] 
   356       ==> cl (latticeof r) X = {t. \<exists>s. s\<in>X & (s,t) \<in> r}" 
   357 apply (rule equalityI) 
   358  apply (rule cl_least) 
   359   apply (simp (no_asm_use) add: latticeof_def trans_def, blast)
   360  apply (simp add: latticeof_def refl_on_def, blast)
   361 apply (simp add: latticeof_def, clarify)
   362 apply (unfold cl_def, blast) 
   363 done
   364 
   365 text{*Related to (4.71).*}
   366 lemma cl_eq_Collect_relcl:
   367      "lattice L ==> cl L X = {t. \<exists>s. s\<in>X & (s,t) \<in> relcl L}" 
   368 apply (cut_tac UN_singleton [of X]) 
   369 apply (erule subst) 
   370 apply (force simp only: relcl_def cl_UN)
   371 done
   372 
   373 text{*Meier's theorem of section 4.5.3*}
   374 theorem latticeof_relcl_eq: "lattice L ==> latticeof (relcl L) = L"
   375 apply (rule equalityI) 
   376  prefer 2 apply (force simp add: latticeof_def relcl_def cl_def, clarify) 
   377 apply (rename_tac X)
   378 apply (rule cl_subset_in_lattice)   
   379  prefer 2 apply assumption
   380 apply (drule cl_ident_iff [OF lattice_latticeof, THEN iffD2])
   381 apply (drule equalityD1)   
   382 apply (rule subset_trans) 
   383  prefer 2 apply assumption
   384 apply (thin_tac "_ \<subseteq> X") 
   385 apply (cut_tac A=X in UN_singleton) 
   386 apply (erule subst) 
   387 apply (simp only: cl_UN lattice_latticeof 
   388                   cl_latticeof [OF refl_relcl trans_relcl]) 
   389 apply (simp add: relcl_def) 
   390 done
   391 
   392 theorem relcl_latticeof_eq:
   393      "[|refl r; trans r|] ==> relcl (latticeof r) = r"
   394 by (simp add: relcl_def cl_latticeof)
   395 
   396 
   397 subsubsection {*Decoupling Theorems*}
   398 
   399 definition decoupled :: "['a program, 'a program] => bool" where
   400    "decoupled F G ==
   401         \<forall>act \<in> Acts F. \<forall>B. G \<in> stable B --> G \<in> stable (wp act B)"
   402 
   403 
   404 text{*Rao's Decoupling Theorem*}
   405 lemma stableco: "F \<in> stable A ==> F \<in> A-B co A"
   406 by (simp add: stable_def constrains_def, blast) 
   407 
   408 theorem decoupling:
   409   assumes leadsTo: "F \<in> A leadsTo B"
   410       and Gstable: "G \<in> stable B"
   411       and dec:     "decoupled F G"
   412   shows "F\<squnion>G \<in> A leadsTo B"
   413 proof -
   414   have prog: "{X. G \<in> stable X} \<in> progress_set F UNIV B"
   415     by (simp add: progress_set_def lattice_stable Gstable closed_def
   416                   stable_Un [OF Gstable] dec [unfolded decoupled_def]) 
   417   have "F\<squnion>G \<in> (UNIV\<inter>A) leadsTo B" 
   418     by (rule progress_set_Union [OF leadsTo prog],
   419         simp_all add: Gstable stableco)
   420   thus ?thesis by simp
   421 qed
   422 
   423 
   424 text{*Rao's Weak Decoupling Theorem*}
   425 theorem weak_decoupling:
   426   assumes leadsTo: "F \<in> A leadsTo B"
   427       and stable: "F\<squnion>G \<in> stable B"
   428       and dec:     "decoupled F (F\<squnion>G)"
   429   shows "F\<squnion>G \<in> A leadsTo B"
   430 proof -
   431   have prog: "{X. F\<squnion>G \<in> stable X} \<in> progress_set F UNIV B" 
   432     by (simp del: Join_stable
   433              add: progress_set_def lattice_stable stable closed_def
   434                   stable_Un [OF stable] dec [unfolded decoupled_def])
   435   have "F\<squnion>G \<in> (UNIV\<inter>A) leadsTo B" 
   436     by (rule progress_set_Union [OF leadsTo prog],
   437         simp_all del: Join_stable add: stable,
   438         simp add: stableco) 
   439   thus ?thesis by simp
   440 qed
   441 
   442 text{*The ``Decoupling via @{term G'} Union Theorem''*}
   443 theorem decoupling_via_aux:
   444   assumes leadsTo: "F \<in> A leadsTo B"
   445       and prog: "{X. G' \<in> stable X} \<in> progress_set F UNIV B"
   446       and GG':  "G \<le> G'"  
   447                --{*Beware!  This is the converse of the refinement relation!*}
   448   shows "F\<squnion>G \<in> A leadsTo B"
   449 proof -
   450   from prog have stable: "G' \<in> stable B"
   451     by (simp add: progress_set_def)
   452   have "F\<squnion>G \<in> (UNIV\<inter>A) leadsTo B" 
   453     by (rule progress_set_Union [OF leadsTo prog],
   454         simp_all add: stable stableco component_stable [OF GG'])
   455   thus ?thesis by simp
   456 qed
   457 
   458 
   459 subsection{*Composition Theorems Based on Monotonicity and Commutativity*}
   460 
   461 subsubsection{*Commutativity of @{term "cl L"} and assignment.*}
   462 definition commutes :: "['a program, 'a set, 'a set,  'a set set] => bool" where
   463    "commutes F T B L ==
   464        \<forall>M. \<forall>act \<in> Acts F. B \<subseteq> M --> 
   465            cl L (T \<inter> wp act M) \<subseteq> T \<inter> (B \<union> wp act (cl L (T\<inter>M)))"
   466 
   467 
   468 text{*From Meier's thesis, section 4.5.6*}
   469 lemma commutativity1_lemma:
   470   assumes commutes: "commutes F T B L" 
   471       and lattice:  "lattice L"
   472       and BL: "B \<in> L"
   473       and TL: "T \<in> L"
   474   shows "closed F T B L"
   475 apply (simp add: closed_def, clarify)
   476 apply (rule ProgressSets.cl_subset_in_lattice [OF _ lattice])  
   477 apply (simp add: Int_Un_distrib cl_Un [OF lattice] 
   478                  cl_ident Int_in_lattice [OF TL BL lattice] Un_upper1)
   479 apply (subgoal_tac "cl L (T \<inter> wp act M) \<subseteq> T \<inter> (B \<union> wp act (cl L (T \<inter> M)))") 
   480  prefer 2 
   481  apply (cut_tac commutes, simp add: commutes_def) 
   482 apply (erule subset_trans) 
   483 apply (simp add: cl_ident)
   484 apply (blast intro: rev_subsetD [OF _ wp_mono]) 
   485 done
   486 
   487 text{*Version packaged with @{thm progress_set_Union}*}
   488 lemma commutativity1:
   489   assumes leadsTo: "F \<in> A leadsTo B"
   490       and lattice:  "lattice L"
   491       and BL: "B \<in> L"
   492       and TL: "T \<in> L"
   493       and Fstable: "F \<in> stable T"
   494       and Gco: "!!X. X\<in>L ==> G \<in> X-B co X"
   495       and commutes: "commutes F T B L" 
   496   shows "F\<squnion>G \<in> T\<inter>A leadsTo B"
   497 by (rule progress_set_Union [OF leadsTo _ Fstable subset_refl BL Gco],
   498     simp add: progress_set_def commutativity1_lemma commutes lattice BL TL) 
   499 
   500 
   501 
   502 text{*Possibly move to Relation.thy, after @{term single_valued}*}
   503 definition funof :: "[('a*'b)set, 'a] => 'b" where
   504    "funof r == (\<lambda>x. THE y. (x,y) \<in> r)"
   505 
   506 lemma funof_eq: "[|single_valued r; (x,y) \<in> r|] ==> funof r x = y"
   507 by (simp add: funof_def single_valued_def, blast)
   508 
   509 lemma funof_Pair_in:
   510      "[|single_valued r; x \<in> Domain r|] ==> (x, funof r x) \<in> r"
   511 by (force simp add: funof_eq) 
   512 
   513 lemma funof_in:
   514      "[|r``{x} \<subseteq> A; single_valued r; x \<in> Domain r|] ==> funof r x \<in> A" 
   515 by (force simp add: funof_eq)
   516  
   517 lemma funof_imp_wp: "[|funof act t \<in> A; single_valued act|] ==> t \<in> wp act A"
   518 by (force simp add: in_wp_iff funof_eq)
   519 
   520 
   521 subsubsection{*Commutativity of Functions and Relation*}
   522 text{*Thesis, page 109*}
   523 
   524 (*FIXME: this proof is still an ungodly mess*)
   525 text{*From Meier's thesis, section 4.5.6*}
   526 lemma commutativity2_lemma:
   527   assumes dcommutes: 
   528       "\<And>act s t. act \<in> Acts F \<Longrightarrow> s \<in> T \<Longrightarrow> (s, t) \<in> relcl L \<Longrightarrow>
   529         s \<in> B | t \<in> B | (funof act s, funof act t) \<in> relcl L"
   530     and determ: "!!act. act \<in> Acts F ==> single_valued act"
   531     and total: "!!act. act \<in> Acts F ==> Domain act = UNIV"
   532     and lattice:  "lattice L"
   533     and BL: "B \<in> L"
   534     and TL: "T \<in> L"
   535     and Fstable: "F \<in> stable T"
   536   shows  "commutes F T B L"
   537 proof -
   538   { fix M and act and t
   539     assume 1: "B \<subseteq> M" "act \<in> Acts F" "t \<in> cl L (T \<inter> wp act M)"
   540     then have "\<exists>s. (s,t) \<in> relcl L \<and> s \<in> T \<inter> wp act M"
   541       by (force simp add: cl_eq_Collect_relcl [OF lattice])
   542     then obtain s where 2: "(s, t) \<in> relcl L" "s \<in> T" "s \<in> wp act M"
   543       by blast
   544     then have 3: "\<forall>u\<in>L. s \<in> u --> t \<in> u"
   545       apply (intro ballI impI) 
   546       apply (subst cl_ident [symmetric], assumption)
   547       apply (simp add: relcl_def)  
   548       apply (blast intro: cl_mono [THEN [2] rev_subsetD])
   549       done
   550     with 1 2 Fstable have 4: "funof act s \<in> T\<inter>M"
   551       by (force intro!: funof_in 
   552         simp add: wp_def stable_def constrains_def determ total)
   553     with 1 2 3 have 5: "s \<in> B | t \<in> B | (funof act s, funof act t) \<in> relcl L"
   554       by (intro dcommutes) assumption+ 
   555     with 1 2 3 4 have "t \<in> B | funof act t \<in> cl L (T\<inter>M)"
   556       by (simp add: relcl_def) (blast intro: BL cl_mono [THEN [2] rev_subsetD])  
   557     with 1 2 3 4 5 have "t \<in> B | t \<in> wp act (cl L (T\<inter>M))"
   558       by (blast intro: funof_imp_wp determ) 
   559     with 2 3 have "t \<in> T \<and> (t \<in> B \<or> t \<in> wp act (cl L (T \<inter> M)))"
   560       by (blast intro: TL cl_mono [THEN [2] rev_subsetD])
   561     then have"t \<in> T \<inter> (B \<union> wp act (cl L (T \<inter> M)))"
   562       by simp
   563   }
   564   then show "commutes F T B L" unfolding commutes_def by clarify
   565 qed
   566   
   567 text{*Version packaged with @{thm progress_set_Union}*}
   568 lemma commutativity2:
   569   assumes leadsTo: "F \<in> A leadsTo B"
   570       and dcommutes: 
   571         "\<forall>act \<in> Acts F. 
   572          \<forall>s \<in> T. \<forall>t. (s,t) \<in> relcl L --> 
   573                       s \<in> B | t \<in> B | (funof act s, funof act t) \<in> relcl L"
   574       and determ: "!!act. act \<in> Acts F ==> single_valued act"
   575       and total: "!!act. act \<in> Acts F ==> Domain act = UNIV"
   576       and lattice:  "lattice L"
   577       and BL: "B \<in> L"
   578       and TL: "T \<in> L"
   579       and Fstable: "F \<in> stable T"
   580       and Gco: "!!X. X\<in>L ==> G \<in> X-B co X"
   581   shows "F\<squnion>G \<in> T\<inter>A leadsTo B"
   582 apply (rule commutativity1 [OF leadsTo lattice]) 
   583 apply (simp_all add: Gco commutativity2_lemma dcommutes determ total
   584                      lattice BL TL Fstable)
   585 done
   586 
   587 
   588 subsection {*Monotonicity*}
   589 text{*From Meier's thesis, section 4.5.7, page 110*}
   590 (*to be continued?*)
   591 
   592 end