src/HOL/UNITY/ELT.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/ELT.thy
```
```     2     Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
```
```     3     Copyright   1999  University of Cambridge
```
```     4
```
```     5 leadsTo strengthened with a specification of the allowable sets transient parts
```
```     6
```
```     7 TRY INSTEAD (to get rid of the {} and to gain strong induction)
```
```     8
```
```     9   elt :: "['a set set, 'a program, 'a set] => ('a set) set"
```
```    10
```
```    11 inductive "elt CC F B"
```
```    12   intros
```
```    13
```
```    14     Weaken:  "A <= B ==> A : elt CC F B"
```
```    15
```
```    16     ETrans:  "[| F : A ensures A';  A-A' : CC;  A' : elt CC F B |]
```
```    17               ==> A : elt CC F B"
```
```    18
```
```    19     Union:  "{A. A: S} : Pow (elt CC F B) ==> (Union S) : elt CC F B"
```
```    20
```
```    21   monos Pow_mono
```
```    22 *)
```
```    23
```
```    24 section{*Progress Under Allowable Sets*}
```
```    25
```
```    26 theory ELT imports Project begin
```
```    27
```
```    28 inductive_set
```
```    29   (*LEADS-TO constant for the inductive definition*)
```
```    30   elt :: "['a set set, 'a program] => ('a set * 'a set) set"
```
```    31   for CC :: "'a set set" and F :: "'a program"
```
```    32  where
```
```    33
```
```    34    Basis:  "[| F : A ensures B;  A-B : (insert {} CC) |] ==> (A,B) : elt CC F"
```
```    35
```
```    36  | Trans:  "[| (A,B) : elt CC F;  (B,C) : elt CC F |] ==> (A,C) : elt CC F"
```
```    37
```
```    38  | Union:  "ALL A: S. (A,B) : elt CC F ==> (Union S, B) : elt CC F"
```
```    39
```
```    40
```
```    41 definition
```
```    42   (*the set of all sets determined by f alone*)
```
```    43   givenBy :: "['a => 'b] => 'a set set"
```
```    44   where "givenBy f = range (%B. f-` B)"
```
```    45
```
```    46 definition
```
```    47   (*visible version of the LEADS-TO relation*)
```
```    48   leadsETo :: "['a set, 'a set set, 'a set] => 'a program set"
```
```    49                                         ("(3_/ leadsTo[_]/ _)" [80,0,80] 80)
```
```    50   where "leadsETo A CC B = {F. (A,B) : elt CC F}"
```
```    51
```
```    52 definition
```
```    53   LeadsETo :: "['a set, 'a set set, 'a set] => 'a program set"
```
```    54                                         ("(3_/ LeadsTo[_]/ _)" [80,0,80] 80)
```
```    55   where "LeadsETo A CC B =
```
```    56       {F. F : (reachable F Int A) leadsTo[(%C. reachable F Int C) ` CC] B}"
```
```    57
```
```    58
```
```    59 (*** givenBy ***)
```
```    60
```
```    61 lemma givenBy_id [simp]: "givenBy id = UNIV"
```
```    62 by (unfold givenBy_def, auto)
```
```    63
```
```    64 lemma givenBy_eq_all: "(givenBy v) = {A. ALL x:A. ALL y. v x = v y --> y: A}"
```
```    65 apply (unfold givenBy_def, safe)
```
```    66 apply (rule_tac  x = "v ` _" in image_eqI, auto)
```
```    67 done
```
```    68
```
```    69 lemma givenByI: "(!!x y. [| x:A;  v x = v y |] ==> y: A) ==> A: givenBy v"
```
```    70 by (subst givenBy_eq_all, blast)
```
```    71
```
```    72 lemma givenByD: "[| A: givenBy v;  x:A;  v x = v y |] ==> y: A"
```
```    73 by (unfold givenBy_def, auto)
```
```    74
```
```    75 lemma empty_mem_givenBy [iff]: "{} : givenBy v"
```
```    76 by (blast intro!: givenByI)
```
```    77
```
```    78 lemma givenBy_imp_eq_Collect: "A: givenBy v ==> EX P. A = {s. P(v s)}"
```
```    79 apply (rule_tac x = "%n. EX s. v s = n & s : A" in exI)
```
```    80 apply (simp (no_asm_use) add: givenBy_eq_all)
```
```    81 apply blast
```
```    82 done
```
```    83
```
```    84 lemma Collect_mem_givenBy: "{s. P(v s)} : givenBy v"
```
```    85 by (unfold givenBy_def, best)
```
```    86
```
```    87 lemma givenBy_eq_Collect: "givenBy v = {A. EX P. A = {s. P(v s)}}"
```
```    88 by (blast intro: Collect_mem_givenBy givenBy_imp_eq_Collect)
```
```    89
```
```    90 (*preserving v preserves properties given by v*)
```
```    91 lemma preserves_givenBy_imp_stable:
```
```    92      "[| F : preserves v;  D : givenBy v |] ==> F : stable D"
```
```    93 by (force simp add: preserves_subset_stable [THEN subsetD] givenBy_eq_Collect)
```
```    94
```
```    95 lemma givenBy_o_subset: "givenBy (w o v) <= givenBy v"
```
```    96 apply (simp (no_asm) add: givenBy_eq_Collect)
```
```    97 apply best
```
```    98 done
```
```    99
```
```   100 lemma givenBy_DiffI:
```
```   101      "[| A : givenBy v;  B : givenBy v |] ==> A-B : givenBy v"
```
```   102 apply (simp (no_asm_use) add: givenBy_eq_Collect)
```
```   103 apply safe
```
```   104 apply (rule_tac x = "%z. R z & ~ Q z" for R Q in exI)
```
```   105 unfolding set_diff_eq
```
```   106 apply auto
```
```   107 done
```
```   108
```
```   109
```
```   110 (** Standard leadsTo rules **)
```
```   111
```
```   112 lemma leadsETo_Basis [intro]:
```
```   113      "[| F: A ensures B;  A-B: insert {} CC |] ==> F : A leadsTo[CC] B"
```
```   114 apply (unfold leadsETo_def)
```
```   115 apply (blast intro: elt.Basis)
```
```   116 done
```
```   117
```
```   118 lemma leadsETo_Trans:
```
```   119      "[| F : A leadsTo[CC] B;  F : B leadsTo[CC] C |] ==> F : A leadsTo[CC] C"
```
```   120 apply (unfold leadsETo_def)
```
```   121 apply (blast intro: elt.Trans)
```
```   122 done
```
```   123
```
```   124
```
```   125 (*Useful with cancellation, disjunction*)
```
```   126 lemma leadsETo_Un_duplicate:
```
```   127      "F : A leadsTo[CC] (A' Un A') ==> F : A leadsTo[CC] A'"
```
```   128 by (simp add: Un_ac)
```
```   129
```
```   130 lemma leadsETo_Un_duplicate2:
```
```   131      "F : A leadsTo[CC] (A' Un C Un C) ==> F : A leadsTo[CC] (A' Un C)"
```
```   132 by (simp add: Un_ac)
```
```   133
```
```   134 (*The Union introduction rule as we should have liked to state it*)
```
```   135 lemma leadsETo_Union:
```
```   136     "(!!A. A : S ==> F : A leadsTo[CC] B) ==> F : (\<Union>S) leadsTo[CC] B"
```
```   137 apply (unfold leadsETo_def)
```
```   138 apply (blast intro: elt.Union)
```
```   139 done
```
```   140
```
```   141 lemma leadsETo_UN:
```
```   142     "(!!i. i : I ==> F : (A i) leadsTo[CC] B)
```
```   143      ==> F : (UN i:I. A i) leadsTo[CC] B"
```
```   144 apply (blast intro: leadsETo_Union)
```
```   145 done
```
```   146
```
```   147 (*The INDUCTION rule as we should have liked to state it*)
```
```   148 lemma leadsETo_induct:
```
```   149   "[| F : za leadsTo[CC] zb;
```
```   150       !!A B. [| F : A ensures B;  A-B : insert {} CC |] ==> P A B;
```
```   151       !!A B C. [| F : A leadsTo[CC] B; P A B; F : B leadsTo[CC] C; P B C |]
```
```   152                ==> P A C;
```
```   153       !!B S. ALL A:S. F : A leadsTo[CC] B & P A B ==> P (\<Union>S) B
```
```   154    |] ==> P za zb"
```
```   155 apply (unfold leadsETo_def)
```
```   156 apply (drule CollectD)
```
```   157 apply (erule elt.induct, blast+)
```
```   158 done
```
```   159
```
```   160
```
```   161 (** New facts involving leadsETo **)
```
```   162
```
```   163 lemma leadsETo_mono: "CC' <= CC ==> (A leadsTo[CC'] B) <= (A leadsTo[CC] B)"
```
```   164 apply safe
```
```   165 apply (erule leadsETo_induct)
```
```   166 prefer 3 apply (blast intro: leadsETo_Union)
```
```   167 prefer 2 apply (blast intro: leadsETo_Trans)
```
```   168 apply blast
```
```   169 done
```
```   170
```
```   171 lemma leadsETo_Trans_Un:
```
```   172      "[| F : A leadsTo[CC] B;  F : B leadsTo[DD] C |]
```
```   173       ==> F : A leadsTo[CC Un DD] C"
```
```   174 by (blast intro: leadsETo_mono [THEN subsetD] leadsETo_Trans)
```
```   175
```
```   176 lemma leadsETo_Union_Int:
```
```   177  "(!!A. A : S ==> F : (A Int C) leadsTo[CC] B)
```
```   178   ==> F : (\<Union>S Int C) leadsTo[CC] B"
```
```   179 apply (unfold leadsETo_def)
```
```   180 apply (simp only: Int_Union_Union)
```
```   181 apply (blast intro: elt.Union)
```
```   182 done
```
```   183
```
```   184 (*Binary union introduction rule*)
```
```   185 lemma leadsETo_Un:
```
```   186      "[| F : A leadsTo[CC] C; F : B leadsTo[CC] C |]
```
```   187       ==> F : (A Un B) leadsTo[CC] C"
```
```   188   using leadsETo_Union [of "{A, B}" F CC C] by auto
```
```   189
```
```   190 lemma single_leadsETo_I:
```
```   191      "(!!x. x : A ==> F : {x} leadsTo[CC] B) ==> F : A leadsTo[CC] B"
```
```   192 by (subst UN_singleton [symmetric], rule leadsETo_UN, blast)
```
```   193
```
```   194
```
```   195 lemma subset_imp_leadsETo: "A<=B ==> F : A leadsTo[CC] B"
```
```   196 by (simp add: subset_imp_ensures [THEN leadsETo_Basis]
```
```   197               Diff_eq_empty_iff [THEN iffD2])
```
```   198
```
```   199 lemmas empty_leadsETo = empty_subsetI [THEN subset_imp_leadsETo, simp]
```
```   200
```
```   201
```
```   202
```
```   203 (** Weakening laws **)
```
```   204
```
```   205 lemma leadsETo_weaken_R:
```
```   206      "[| F : A leadsTo[CC] A';  A'<=B' |] ==> F : A leadsTo[CC] B'"
```
```   207 by (blast intro: subset_imp_leadsETo leadsETo_Trans)
```
```   208
```
```   209 lemma leadsETo_weaken_L:
```
```   210      "[| F : A leadsTo[CC] A'; B<=A |] ==> F : B leadsTo[CC] A'"
```
```   211 by (blast intro: leadsETo_Trans subset_imp_leadsETo)
```
```   212
```
```   213 (*Distributes over binary unions*)
```
```   214 lemma leadsETo_Un_distrib:
```
```   215      "F : (A Un B) leadsTo[CC] C  =
```
```   216       (F : A leadsTo[CC] C & F : B leadsTo[CC] C)"
```
```   217 by (blast intro: leadsETo_Un leadsETo_weaken_L)
```
```   218
```
```   219 lemma leadsETo_UN_distrib:
```
```   220      "F : (UN i:I. A i) leadsTo[CC] B  =
```
```   221       (ALL i : I. F : (A i) leadsTo[CC] B)"
```
```   222 by (blast intro: leadsETo_UN leadsETo_weaken_L)
```
```   223
```
```   224 lemma leadsETo_Union_distrib:
```
```   225      "F : (\<Union>S) leadsTo[CC] B  =  (ALL A : S. F : A leadsTo[CC] B)"
```
```   226 by (blast intro: leadsETo_Union leadsETo_weaken_L)
```
```   227
```
```   228 lemma leadsETo_weaken:
```
```   229      "[| F : A leadsTo[CC'] A'; B<=A; A'<=B';  CC' <= CC |]
```
```   230       ==> F : B leadsTo[CC] B'"
```
```   231 apply (drule leadsETo_mono [THEN subsetD], assumption)
```
```   232 apply (blast del: subsetCE
```
```   233              intro: leadsETo_weaken_R leadsETo_weaken_L leadsETo_Trans)
```
```   234 done
```
```   235
```
```   236 lemma leadsETo_givenBy:
```
```   237      "[| F : A leadsTo[CC] A';  CC <= givenBy v |]
```
```   238       ==> F : A leadsTo[givenBy v] A'"
```
```   239 by (blast intro: leadsETo_weaken)
```
```   240
```
```   241
```
```   242 (*Set difference*)
```
```   243 lemma leadsETo_Diff:
```
```   244      "[| F : (A-B) leadsTo[CC] C; F : B leadsTo[CC] C |]
```
```   245       ==> F : A leadsTo[CC] C"
```
```   246 by (blast intro: leadsETo_Un leadsETo_weaken)
```
```   247
```
```   248
```
```   249 (*Binary union version*)
```
```   250 lemma leadsETo_Un_Un:
```
```   251      "[| F : A leadsTo[CC] A';  F : B leadsTo[CC] B' |]
```
```   252       ==> F : (A Un B) leadsTo[CC] (A' Un B')"
```
```   253 by (blast intro: leadsETo_Un leadsETo_weaken_R)
```
```   254
```
```   255
```
```   256 (** The cancellation law **)
```
```   257
```
```   258 lemma leadsETo_cancel2:
```
```   259      "[| F : A leadsTo[CC] (A' Un B); F : B leadsTo[CC] B' |]
```
```   260       ==> F : A leadsTo[CC] (A' Un B')"
```
```   261 by (blast intro: leadsETo_Un_Un subset_imp_leadsETo leadsETo_Trans)
```
```   262
```
```   263 lemma leadsETo_cancel1:
```
```   264      "[| F : A leadsTo[CC] (B Un A'); F : B leadsTo[CC] B' |]
```
```   265     ==> F : A leadsTo[CC] (B' Un A')"
```
```   266 apply (simp add: Un_commute)
```
```   267 apply (blast intro!: leadsETo_cancel2)
```
```   268 done
```
```   269
```
```   270 lemma leadsETo_cancel_Diff1:
```
```   271      "[| F : A leadsTo[CC] (B Un A'); F : (B-A') leadsTo[CC] B' |]
```
```   272     ==> F : A leadsTo[CC] (B' Un A')"
```
```   273 apply (rule leadsETo_cancel1)
```
```   274  prefer 2 apply assumption
```
```   275 apply simp_all
```
```   276 done
```
```   277
```
```   278
```
```   279 (** PSP: Progress-Safety-Progress **)
```
```   280
```
```   281 (*Special case of PSP: Misra's "stable conjunction"*)
```
```   282 lemma e_psp_stable:
```
```   283    "[| F : A leadsTo[CC] A';  F : stable B;  ALL C:CC. C Int B : CC |]
```
```   284     ==> F : (A Int B) leadsTo[CC] (A' Int B)"
```
```   285 apply (unfold stable_def)
```
```   286 apply (erule leadsETo_induct)
```
```   287 prefer 3 apply (blast intro: leadsETo_Union_Int)
```
```   288 prefer 2 apply (blast intro: leadsETo_Trans)
```
```   289 apply (rule leadsETo_Basis)
```
```   290 prefer 2 apply (force simp add: Diff_Int_distrib2 [symmetric])
```
```   291 apply (simp add: ensures_def Diff_Int_distrib2 [symmetric]
```
```   292                  Int_Un_distrib2 [symmetric])
```
```   293 apply (blast intro: transient_strengthen constrains_Int)
```
```   294 done
```
```   295
```
```   296 lemma e_psp_stable2:
```
```   297      "[| F : A leadsTo[CC] A'; F : stable B;  ALL C:CC. C Int B : CC |]
```
```   298       ==> F : (B Int A) leadsTo[CC] (B Int A')"
```
```   299 by (simp (no_asm_simp) add: e_psp_stable Int_ac)
```
```   300
```
```   301 lemma e_psp:
```
```   302      "[| F : A leadsTo[CC] A'; F : B co B';
```
```   303          ALL C:CC. C Int B Int B' : CC |]
```
```   304       ==> F : (A Int B') leadsTo[CC] ((A' Int B) Un (B' - B))"
```
```   305 apply (erule leadsETo_induct)
```
```   306 prefer 3 apply (blast intro: leadsETo_Union_Int)
```
```   307 (*Transitivity case has a delicate argument involving "cancellation"*)
```
```   308 apply (rule_tac  leadsETo_Un_duplicate2)
```
```   309 apply (erule_tac  leadsETo_cancel_Diff1)
```
```   310 prefer 2
```
```   311  apply (simp add: Int_Diff Diff_triv)
```
```   312  apply (blast intro: leadsETo_weaken_L dest: constrains_imp_subset)
```
```   313 (*Basis case*)
```
```   314 apply (rule leadsETo_Basis)
```
```   315 apply (blast intro: psp_ensures)
```
```   316 apply (subgoal_tac "A Int B' - (Ba Int B Un (B' - B)) = (A - Ba) Int B Int B'")
```
```   317 apply auto
```
```   318 done
```
```   319
```
```   320 lemma e_psp2:
```
```   321      "[| F : A leadsTo[CC] A'; F : B co B';
```
```   322          ALL C:CC. C Int B Int B' : CC |]
```
```   323       ==> F : (B' Int A) leadsTo[CC] ((B Int A') Un (B' - B))"
```
```   324 by (simp add: e_psp Int_ac)
```
```   325
```
```   326
```
```   327 (*** Special properties involving the parameter [CC] ***)
```
```   328
```
```   329 (*??IS THIS NEEDED?? or is it just an example of what's provable??*)
```
```   330 lemma gen_leadsETo_imp_Join_leadsETo:
```
```   331      "[| F: (A leadsTo[givenBy v] B);  G : preserves v;
```
```   332          F\<squnion>G : stable C |]
```
```   333       ==> F\<squnion>G : ((C Int A) leadsTo[(%D. C Int D) ` givenBy v] B)"
```
```   334 apply (erule leadsETo_induct)
```
```   335   prefer 3
```
```   336   apply (subst Int_Union)
```
```   337   apply (blast intro: leadsETo_UN)
```
```   338 prefer 2
```
```   339  apply (blast intro: e_psp_stable2 [THEN leadsETo_weaken_L] leadsETo_Trans)
```
```   340 apply (rule leadsETo_Basis)
```
```   341 apply (auto simp add: Diff_eq_empty_iff [THEN iffD2]
```
```   342                       Int_Diff ensures_def givenBy_eq_Collect)
```
```   343 prefer 3 apply (blast intro: transient_strengthen)
```
```   344 apply (drule_tac  P1 = P in preserves_subset_stable [THEN subsetD])
```
```   345 apply (drule_tac P1 = P in preserves_subset_stable [THEN subsetD])
```
```   346 apply (unfold stable_def)
```
```   347 apply (blast intro: constrains_Int [THEN constrains_weaken])+
```
```   348 done
```
```   349
```
```   350 (**** Relationship with traditional "leadsTo", strong & weak ****)
```
```   351
```
```   352 (** strong **)
```
```   353
```
```   354 lemma leadsETo_subset_leadsTo: "(A leadsTo[CC] B) <= (A leadsTo B)"
```
```   355 apply safe
```
```   356 apply (erule leadsETo_induct)
```
```   357   prefer 3 apply (blast intro: leadsTo_Union)
```
```   358  prefer 2 apply (blast intro: leadsTo_Trans, blast)
```
```   359 done
```
```   360
```
```   361 lemma leadsETo_UNIV_eq_leadsTo: "(A leadsTo[UNIV] B) = (A leadsTo B)"
```
```   362 apply safe
```
```   363 apply (erule leadsETo_subset_leadsTo [THEN subsetD])
```
```   364 (*right-to-left case*)
```
```   365 apply (erule leadsTo_induct)
```
```   366   prefer 3 apply (blast intro: leadsETo_Union)
```
```   367  prefer 2 apply (blast intro: leadsETo_Trans, blast)
```
```   368 done
```
```   369
```
```   370 (**** weak ****)
```
```   371
```
```   372 lemma LeadsETo_eq_leadsETo:
```
```   373      "A LeadsTo[CC] B =
```
```   374         {F. F : (reachable F Int A) leadsTo[(%C. reachable F Int C) ` CC]
```
```   375         (reachable F Int B)}"
```
```   376 apply (unfold LeadsETo_def)
```
```   377 apply (blast dest: e_psp_stable2 intro: leadsETo_weaken)
```
```   378 done
```
```   379
```
```   380 (*** Introduction rules: Basis, Trans, Union ***)
```
```   381
```
```   382 lemma LeadsETo_Trans:
```
```   383      "[| F : A LeadsTo[CC] B;  F : B LeadsTo[CC] C |]
```
```   384       ==> F : A LeadsTo[CC] C"
```
```   385 apply (simp add: LeadsETo_eq_leadsETo)
```
```   386 apply (blast intro: leadsETo_Trans)
```
```   387 done
```
```   388
```
```   389 lemma LeadsETo_Union:
```
```   390      "(!!A. A : S ==> F : A LeadsTo[CC] B) ==> F : (\<Union>S) LeadsTo[CC] B"
```
```   391 apply (simp add: LeadsETo_def)
```
```   392 apply (subst Int_Union)
```
```   393 apply (blast intro: leadsETo_UN)
```
```   394 done
```
```   395
```
```   396 lemma LeadsETo_UN:
```
```   397      "(!!i. i : I ==> F : (A i) LeadsTo[CC] B)
```
```   398       ==> F : (UN i:I. A i) LeadsTo[CC] B"
```
```   399 apply (blast intro: LeadsETo_Union)
```
```   400 done
```
```   401
```
```   402 (*Binary union introduction rule*)
```
```   403 lemma LeadsETo_Un:
```
```   404      "[| F : A LeadsTo[CC] C; F : B LeadsTo[CC] C |]
```
```   405       ==> F : (A Un B) LeadsTo[CC] C"
```
```   406   using LeadsETo_Union [of "{A, B}" F CC C] by auto
```
```   407
```
```   408 (*Lets us look at the starting state*)
```
```   409 lemma single_LeadsETo_I:
```
```   410      "(!!s. s : A ==> F : {s} LeadsTo[CC] B) ==> F : A LeadsTo[CC] B"
```
```   411 by (subst UN_singleton [symmetric], rule LeadsETo_UN, blast)
```
```   412
```
```   413 lemma subset_imp_LeadsETo:
```
```   414      "A <= B ==> F : A LeadsTo[CC] B"
```
```   415 apply (simp (no_asm) add: LeadsETo_def)
```
```   416 apply (blast intro: subset_imp_leadsETo)
```
```   417 done
```
```   418
```
```   419 lemmas empty_LeadsETo = empty_subsetI [THEN subset_imp_LeadsETo]
```
```   420
```
```   421 lemma LeadsETo_weaken_R:
```
```   422      "[| F : A LeadsTo[CC] A';  A' <= B' |] ==> F : A LeadsTo[CC] B'"
```
```   423 apply (simp add: LeadsETo_def)
```
```   424 apply (blast intro: leadsETo_weaken_R)
```
```   425 done
```
```   426
```
```   427 lemma LeadsETo_weaken_L:
```
```   428      "[| F : A LeadsTo[CC] A';  B <= A |] ==> F : B LeadsTo[CC] A'"
```
```   429 apply (simp add: LeadsETo_def)
```
```   430 apply (blast intro: leadsETo_weaken_L)
```
```   431 done
```
```   432
```
```   433 lemma LeadsETo_weaken:
```
```   434      "[| F : A LeadsTo[CC'] A';
```
```   435          B <= A;  A' <= B';  CC' <= CC |]
```
```   436       ==> F : B LeadsTo[CC] B'"
```
```   437 apply (simp (no_asm_use) add: LeadsETo_def)
```
```   438 apply (blast intro: leadsETo_weaken)
```
```   439 done
```
```   440
```
```   441 lemma LeadsETo_subset_LeadsTo: "(A LeadsTo[CC] B) <= (A LeadsTo B)"
```
```   442 apply (unfold LeadsETo_def LeadsTo_def)
```
```   443 apply (blast intro: leadsETo_subset_leadsTo [THEN subsetD])
```
```   444 done
```
```   445
```
```   446 (*Postcondition can be strengthened to (reachable F Int B) *)
```
```   447 lemma reachable_ensures:
```
```   448      "F : A ensures B ==> F : (reachable F Int A) ensures B"
```
```   449 apply (rule stable_ensures_Int [THEN ensures_weaken_R], auto)
```
```   450 done
```
```   451
```
```   452 lemma lel_lemma:
```
```   453      "F : A leadsTo B ==> F : (reachable F Int A) leadsTo[Pow(reachable F)] B"
```
```   454 apply (erule leadsTo_induct)
```
```   455   apply (blast intro: reachable_ensures)
```
```   456  apply (blast dest: e_psp_stable2 intro: leadsETo_Trans leadsETo_weaken_L)
```
```   457 apply (subst Int_Union)
```
```   458 apply (blast intro: leadsETo_UN)
```
```   459 done
```
```   460
```
```   461 lemma LeadsETo_UNIV_eq_LeadsTo: "(A LeadsTo[UNIV] B) = (A LeadsTo B)"
```
```   462 apply safe
```
```   463 apply (erule LeadsETo_subset_LeadsTo [THEN subsetD])
```
```   464 (*right-to-left case*)
```
```   465 apply (unfold LeadsETo_def LeadsTo_def)
```
```   466 apply (blast intro: lel_lemma [THEN leadsETo_weaken])
```
```   467 done
```
```   468
```
```   469
```
```   470 (**** EXTEND/PROJECT PROPERTIES ****)
```
```   471
```
```   472 context Extend
```
```   473 begin
```
```   474
```
```   475 lemma givenBy_o_eq_extend_set:
```
```   476      "givenBy (v o f) = extend_set h ` (givenBy v)"
```
```   477 apply (simp add: givenBy_eq_Collect)
```
```   478 apply (rule equalityI, best)
```
```   479 apply blast
```
```   480 done
```
```   481
```
```   482 lemma givenBy_eq_extend_set: "givenBy f = range (extend_set h)"
```
```   483 by (simp add: givenBy_eq_Collect, best)
```
```   484
```
```   485 lemma extend_set_givenBy_I:
```
```   486      "D : givenBy v ==> extend_set h D : givenBy (v o f)"
```
```   487 apply (simp (no_asm_use) add: givenBy_eq_all, blast)
```
```   488 done
```
```   489
```
```   490 lemma leadsETo_imp_extend_leadsETo:
```
```   491      "F : A leadsTo[CC] B
```
```   492       ==> extend h F : (extend_set h A) leadsTo[extend_set h ` CC]
```
```   493                        (extend_set h B)"
```
```   494 apply (erule leadsETo_induct)
```
```   495   apply (force intro: subset_imp_ensures
```
```   496                simp add: extend_ensures extend_set_Diff_distrib [symmetric])
```
```   497  apply (blast intro: leadsETo_Trans)
```
```   498 apply (simp add: leadsETo_UN extend_set_Union)
```
```   499 done
```
```   500
```
```   501
```
```   502 (*This version's stronger in the "ensures" precondition
```
```   503   BUT there's no ensures_weaken_L*)
```
```   504 lemma Join_project_ensures_strong:
```
```   505      "[| project h C G ~: transient (project_set h C Int (A-B)) |
```
```   506            project_set h C Int (A - B) = {};
```
```   507          extend h F\<squnion>G : stable C;
```
```   508          F\<squnion>project h C G : (project_set h C Int A) ensures B |]
```
```   509       ==> extend h F\<squnion>G : (C Int extend_set h A) ensures (extend_set h B)"
```
```   510 apply (subst Int_extend_set_lemma [symmetric])
```
```   511 apply (rule Join_project_ensures)
```
```   512 apply (auto simp add: Int_Diff)
```
```   513 done
```
```   514
```
```   515 (*NOT WORKING.  MODIFY AS IN Project.thy
```
```   516 lemma pld_lemma:
```
```   517      "[| extend h F\<squnion>G : stable C;
```
```   518          F\<squnion>project h C G : (project_set h C Int A) leadsTo[(%D. project_set h C Int D)`givenBy v] B;
```
```   519          G : preserves (v o f) |]
```
```   520       ==> extend h F\<squnion>G :
```
```   521             (C Int extend_set h (project_set h C Int A))
```
```   522             leadsTo[(%D. C Int extend_set h D)`givenBy v]  (extend_set h B)"
```
```   523 apply (erule leadsETo_induct)
```
```   524   prefer 3
```
```   525   apply (simp del: UN_simps add: Int_UN_distrib leadsETo_UN extend_set_Union)
```
```   526  prefer 2
```
```   527  apply (blast intro: e_psp_stable2 [THEN leadsETo_weaken_L] leadsETo_Trans)
```
```   528 txt{*Base case is hard*}
```
```   529 apply auto
```
```   530 apply (force intro: leadsETo_Basis subset_imp_ensures)
```
```   531 apply (rule leadsETo_Basis)
```
```   532  prefer 2
```
```   533  apply (simp add: Int_Diff Int_extend_set_lemma extend_set_Diff_distrib [symmetric])
```
```   534 apply (rule Join_project_ensures_strong)
```
```   535 apply (auto intro: project_stable_project_set simp add: Int_left_absorb)
```
```   536 apply (simp (no_asm_simp) add: stable_ensures_Int [THEN ensures_weaken_R] Int_lower2 project_stable_project_set extend_stable_project_set)
```
```   537 done
```
```   538
```
```   539 lemma project_leadsETo_D_lemma:
```
```   540      "[| extend h F\<squnion>G : stable C;
```
```   541          F\<squnion>project h C G :
```
```   542              (project_set h C Int A)
```
```   543              leadsTo[(%D. project_set h C Int D)`givenBy v] B;
```
```   544          G : preserves (v o f) |]
```
```   545       ==> extend h F\<squnion>G : (C Int extend_set h A)
```
```   546             leadsTo[(%D. C Int extend_set h D)`givenBy v] (extend_set h B)"
```
```   547 apply (rule pld_lemma [THEN leadsETo_weaken])
```
```   548 apply (auto simp add: split_extended_all)
```
```   549 done
```
```   550
```
```   551 lemma project_leadsETo_D:
```
```   552      "[| F\<squnion>project h UNIV G : A leadsTo[givenBy v] B;
```
```   553          G : preserves (v o f) |]
```
```   554       ==> extend h F\<squnion>G : (extend_set h A)
```
```   555             leadsTo[givenBy (v o f)] (extend_set h B)"
```
```   556 apply (cut_tac project_leadsETo_D_lemma [of _ _ UNIV], auto)
```
```   557 apply (erule leadsETo_givenBy)
```
```   558 apply (rule givenBy_o_eq_extend_set [THEN equalityD2])
```
```   559 done
```
```   560
```
```   561 lemma project_LeadsETo_D:
```
```   562      "[| F\<squnion>project h (reachable (extend h F\<squnion>G)) G
```
```   563              : A LeadsTo[givenBy v] B;
```
```   564          G : preserves (v o f) |]
```
```   565       ==> extend h F\<squnion>G :
```
```   566             (extend_set h A) LeadsTo[givenBy (v o f)] (extend_set h B)"
```
```   567 apply (cut_tac subset_refl [THEN stable_reachable, THEN project_leadsETo_D_lemma])
```
```   568 apply (auto simp add: LeadsETo_def)
```
```   569  apply (erule leadsETo_mono [THEN  rev_subsetD])
```
```   570  apply (blast intro: extend_set_givenBy_I)
```
```   571 apply (simp add: project_set_reachable_extend_eq [symmetric])
```
```   572 done
```
```   573
```
```   574 lemma extending_leadsETo:
```
```   575      "(ALL G. extend h F ok G --> G : preserves (v o f))
```
```   576       ==> extending (%G. UNIV) h F
```
```   577                 (extend_set h A leadsTo[givenBy (v o f)] extend_set h B)
```
```   578                 (A leadsTo[givenBy v] B)"
```
```   579 apply (unfold extending_def)
```
```   580 apply (auto simp add: project_leadsETo_D)
```
```   581 done
```
```   582
```
```   583 lemma extending_LeadsETo:
```
```   584      "(ALL G. extend h F ok G --> G : preserves (v o f))
```
```   585       ==> extending (%G. reachable (extend h F\<squnion>G)) h F
```
```   586                 (extend_set h A LeadsTo[givenBy (v o f)] extend_set h B)
```
```   587                 (A LeadsTo[givenBy v]  B)"
```
```   588 apply (unfold extending_def)
```
```   589 apply (blast intro: project_LeadsETo_D)
```
```   590 done
```
```   591 *)
```
```   592
```
```   593
```
```   594 (*** leadsETo in the precondition ***)
```
```   595
```
```   596 (*Lemma for the Trans case*)
```
```   597 lemma pli_lemma:
```
```   598      "[| extend h F\<squnion>G : stable C;
```
```   599          F\<squnion>project h C G
```
```   600            : project_set h C Int project_set h A leadsTo project_set h B |]
```
```   601       ==> F\<squnion>project h C G
```
```   602             : project_set h C Int project_set h A leadsTo
```
```   603               project_set h C Int project_set h B"
```
```   604 apply (rule psp_stable2 [THEN leadsTo_weaken_L])
```
```   605 apply (auto simp add: project_stable_project_set extend_stable_project_set)
```
```   606 done
```
```   607
```
```   608 lemma project_leadsETo_I_lemma:
```
```   609      "[| extend h F\<squnion>G : stable C;
```
```   610          extend h F\<squnion>G :
```
```   611            (C Int A) leadsTo[(%D. C Int D)`givenBy f]  B |]
```
```   612   ==> F\<squnion>project h C G
```
```   613     : (project_set h C Int project_set h (C Int A)) leadsTo (project_set h B)"
```
```   614 apply (erule leadsETo_induct)
```
```   615   prefer 3
```
```   616   apply (simp only: Int_UN_distrib project_set_Union)
```
```   617   apply (blast intro: leadsTo_UN)
```
```   618  prefer 2 apply (blast intro: leadsTo_Trans pli_lemma)
```
```   619 apply (simp add: givenBy_eq_extend_set)
```
```   620 apply (rule leadsTo_Basis)
```
```   621 apply (blast intro: ensures_extend_set_imp_project_ensures)
```
```   622 done
```
```   623
```
```   624 lemma project_leadsETo_I:
```
```   625      "extend h F\<squnion>G : (extend_set h A) leadsTo[givenBy f] (extend_set h B)
```
```   626       ==> F\<squnion>project h UNIV G : A leadsTo B"
```
```   627 apply (rule project_leadsETo_I_lemma [THEN leadsTo_weaken], auto)
```
```   628 done
```
```   629
```
```   630 lemma project_LeadsETo_I:
```
```   631      "extend h F\<squnion>G : (extend_set h A) LeadsTo[givenBy f] (extend_set h B)
```
```   632       ==> F\<squnion>project h (reachable (extend h F\<squnion>G)) G
```
```   633            : A LeadsTo B"
```
```   634 apply (simp (no_asm_use) add: LeadsTo_def LeadsETo_def)
```
```   635 apply (rule project_leadsETo_I_lemma [THEN leadsTo_weaken])
```
```   636 apply (auto simp add: project_set_reachable_extend_eq [symmetric])
```
```   637 done
```
```   638
```
```   639 lemma projecting_leadsTo:
```
```   640      "projecting (%G. UNIV) h F
```
```   641                  (extend_set h A leadsTo[givenBy f] extend_set h B)
```
```   642                  (A leadsTo B)"
```
```   643 apply (unfold projecting_def)
```
```   644 apply (force dest: project_leadsETo_I)
```
```   645 done
```
```   646
```
```   647 lemma projecting_LeadsTo:
```
```   648      "projecting (%G. reachable (extend h F\<squnion>G)) h F
```
```   649                  (extend_set h A LeadsTo[givenBy f] extend_set h B)
```
```   650                  (A LeadsTo B)"
```
```   651 apply (unfold projecting_def)
```
```   652 apply (force dest: project_LeadsETo_I)
```
```   653 done
```
```   654
```
```   655 end
```
```   656
```
```   657 end
```