src/HOL/UNITY/Extend.thy
author wenzelm
Tue, 21 Feb 2012 17:09:17 +0100
changeset 47448 e5438c5797ae
parent 40950 cf26dd7395e4
child 47783 e0cd5c4df8e6
permissions -rw-r--r--
tuned proofs;
     1 (*  Title:      HOL/UNITY/Extend.thy
     2     Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
     3     Copyright   1998  University of Cambridge
     4 
     5 Extending of state setsExtending of state sets
     6   function f (forget)    maps the extended state to the original state
     7   function g (forgotten) maps the extended state to the "extending part"
     8 *)
     9 
    10 header{*Extending State Sets*}
    11 
    12 theory Extend imports Guar begin
    13 
    14 definition
    15   (*MOVE to Relation.thy?*)
    16   Restrict :: "[ 'a set, ('a*'b) set] => ('a*'b) set"
    17   where "Restrict A r = r \<inter> (A <*> UNIV)"
    18 
    19 definition
    20   good_map :: "['a*'b => 'c] => bool"
    21   where "good_map h <-> surj h & (\<forall>x y. fst (inv h (h (x,y))) = x)"
    22      (*Using the locale constant "f", this is  f (h (x,y))) = x*)
    23   
    24 definition
    25   extend_set :: "['a*'b => 'c, 'a set] => 'c set"
    26   where "extend_set h A = h ` (A <*> UNIV)"
    27 
    28 definition
    29   project_set :: "['a*'b => 'c, 'c set] => 'a set"
    30   where "project_set h C = {x. \<exists>y. h(x,y) \<in> C}"
    31 
    32 definition
    33   extend_act :: "['a*'b => 'c, ('a*'a) set] => ('c*'c) set"
    34   where "extend_act h = (%act. \<Union>(s,s') \<in> act. \<Union>y. {(h(s,y), h(s',y))})"
    35 
    36 definition
    37   project_act :: "['a*'b => 'c, ('c*'c) set] => ('a*'a) set"
    38   where "project_act h act = {(x,x'). \<exists>y y'. (h(x,y), h(x',y')) \<in> act}"
    39 
    40 definition
    41   extend :: "['a*'b => 'c, 'a program] => 'c program"
    42   where "extend h F = mk_program (extend_set h (Init F),
    43                                extend_act h ` Acts F,
    44                                project_act h -` AllowedActs F)"
    45 
    46 definition
    47   (*Argument C allows weak safety laws to be projected*)
    48   project :: "['a*'b => 'c, 'c set, 'c program] => 'a program"
    49   where "project h C F =
    50        mk_program (project_set h (Init F),
    51                    project_act h ` Restrict C ` Acts F,
    52                    {act. Restrict (project_set h C) act :
    53                          project_act h ` Restrict C ` AllowedActs F})"
    54 
    55 locale Extend =
    56   fixes f     :: "'c => 'a"
    57     and g     :: "'c => 'b"
    58     and h     :: "'a*'b => 'c"    (*isomorphism between 'a * 'b and 'c *)
    59     and slice :: "['c set, 'b] => 'a set"
    60   assumes
    61     good_h:  "good_map h"
    62   defines f_def: "f z == fst (inv h z)"
    63       and g_def: "g z == snd (inv h z)"
    64       and slice_def: "slice Z y == {x. h(x,y) \<in> Z}"
    65 
    66 
    67 (** These we prove OUTSIDE the locale. **)
    68 
    69 
    70 subsection{*Restrict*}
    71 (*MOVE to Relation.thy?*)
    72 
    73 lemma Restrict_iff [iff]: "((x,y): Restrict A r) = ((x,y): r & x \<in> A)"
    74 by (unfold Restrict_def, blast)
    75 
    76 lemma Restrict_UNIV [simp]: "Restrict UNIV = id"
    77 apply (rule ext)
    78 apply (auto simp add: Restrict_def)
    79 done
    80 
    81 lemma Restrict_empty [simp]: "Restrict {} r = {}"
    82 by (auto simp add: Restrict_def)
    83 
    84 lemma Restrict_Int [simp]: "Restrict A (Restrict B r) = Restrict (A \<inter> B) r"
    85 by (unfold Restrict_def, blast)
    86 
    87 lemma Restrict_triv: "Domain r \<subseteq> A ==> Restrict A r = r"
    88 by (unfold Restrict_def, auto)
    89 
    90 lemma Restrict_subset: "Restrict A r \<subseteq> r"
    91 by (unfold Restrict_def, auto)
    92 
    93 lemma Restrict_eq_mono: 
    94      "[| A \<subseteq> B;  Restrict B r = Restrict B s |]  
    95       ==> Restrict A r = Restrict A s"
    96 by (unfold Restrict_def, blast)
    97 
    98 lemma Restrict_imageI: 
    99      "[| s \<in> RR;  Restrict A r = Restrict A s |]  
   100       ==> Restrict A r \<in> Restrict A ` RR"
   101 by (unfold Restrict_def image_def, auto)
   102 
   103 lemma Domain_Restrict [simp]: "Domain (Restrict A r) = A \<inter> Domain r"
   104 by blast
   105 
   106 lemma Image_Restrict [simp]: "(Restrict A r) `` B = r `` (A \<inter> B)"
   107 by blast
   108 
   109 (*Possibly easier than reasoning about "inv h"*)
   110 lemma good_mapI: 
   111      assumes surj_h: "surj h"
   112          and prem:   "!! x x' y y'. h(x,y) = h(x',y') ==> x=x'"
   113      shows "good_map h"
   114 apply (simp add: good_map_def) 
   115 apply (safe intro!: surj_h)
   116 apply (rule prem)
   117 apply (subst surjective_pairing [symmetric])
   118 apply (subst surj_h [THEN surj_f_inv_f])
   119 apply (rule refl)
   120 done
   121 
   122 lemma good_map_is_surj: "good_map h ==> surj h"
   123 by (unfold good_map_def, auto)
   124 
   125 (*A convenient way of finding a closed form for inv h*)
   126 lemma fst_inv_equalityI: 
   127      assumes surj_h: "surj h"
   128          and prem:   "!! x y. g (h(x,y)) = x"
   129      shows "fst (inv h z) = g z"
   130 by (metis UNIV_I f_inv_into_f pair_collapse prem surj_h)
   131 
   132 
   133 subsection{*Trivial properties of f, g, h*}
   134 
   135 lemma (in Extend) f_h_eq [simp]: "f(h(x,y)) = x" 
   136 by (simp add: f_def good_h [unfolded good_map_def, THEN conjunct2])
   137 
   138 lemma (in Extend) h_inject1 [dest]: "h(x,y) = h(x',y') ==> x=x'"
   139 apply (drule_tac f = f in arg_cong)
   140 apply (simp add: f_def good_h [unfolded good_map_def, THEN conjunct2])
   141 done
   142 
   143 lemma (in Extend) h_f_g_equiv: "h(f z, g z) == z"
   144 by (simp add: f_def g_def 
   145             good_h [unfolded good_map_def, THEN conjunct1, THEN surj_f_inv_f])
   146 
   147 lemma (in Extend) h_f_g_eq: "h(f z, g z) = z"
   148 by (simp add: h_f_g_equiv)
   149 
   150 
   151 lemma (in Extend) split_extended_all:
   152      "(!!z. PROP P z) == (!!u y. PROP P (h (u, y)))"
   153 proof 
   154    assume allP: "\<And>z. PROP P z"
   155    fix u y
   156    show "PROP P (h (u, y))" by (rule allP)
   157  next
   158    assume allPh: "\<And>u y. PROP P (h(u,y))"
   159    fix z
   160    have Phfgz: "PROP P (h (f z, g z))" by (rule allPh)
   161    show "PROP P z" by (rule Phfgz [unfolded h_f_g_equiv])
   162 qed 
   163 
   164 
   165 
   166 subsection{*@{term extend_set}: basic properties*}
   167 
   168 lemma project_set_iff [iff]:
   169      "(x \<in> project_set h C) = (\<exists>y. h(x,y) \<in> C)"
   170 by (simp add: project_set_def)
   171 
   172 lemma extend_set_mono: "A \<subseteq> B ==> extend_set h A \<subseteq> extend_set h B"
   173 by (unfold extend_set_def, blast)
   174 
   175 lemma (in Extend) mem_extend_set_iff [iff]: "z \<in> extend_set h A = (f z \<in> A)"
   176 apply (unfold extend_set_def)
   177 apply (force intro: h_f_g_eq [symmetric])
   178 done
   179 
   180 lemma (in Extend) extend_set_strict_mono [iff]:
   181      "(extend_set h A \<subseteq> extend_set h B) = (A \<subseteq> B)"
   182 by (unfold extend_set_def, force)
   183 
   184 lemma extend_set_empty [simp]: "extend_set h {} = {}"
   185 by (unfold extend_set_def, auto)
   186 
   187 lemma (in Extend) extend_set_eq_Collect: "extend_set h {s. P s} = {s. P(f s)}"
   188 by auto
   189 
   190 lemma (in Extend) extend_set_sing: "extend_set h {x} = {s. f s = x}"
   191 by auto
   192 
   193 lemma (in Extend) extend_set_inverse [simp]:
   194      "project_set h (extend_set h C) = C"
   195 by (unfold extend_set_def, auto)
   196 
   197 lemma (in Extend) extend_set_project_set:
   198      "C \<subseteq> extend_set h (project_set h C)"
   199 apply (unfold extend_set_def)
   200 apply (auto simp add: split_extended_all, blast)
   201 done
   202 
   203 lemma (in Extend) inj_extend_set: "inj (extend_set h)"
   204 apply (rule inj_on_inverseI)
   205 apply (rule extend_set_inverse)
   206 done
   207 
   208 lemma (in Extend) extend_set_UNIV_eq [simp]: "extend_set h UNIV = UNIV"
   209 apply (unfold extend_set_def)
   210 apply (auto simp add: split_extended_all)
   211 done
   212 
   213 subsection{*@{term project_set}: basic properties*}
   214 
   215 (*project_set is simply image!*)
   216 lemma (in Extend) project_set_eq: "project_set h C = f ` C"
   217 by (auto intro: f_h_eq [symmetric] simp add: split_extended_all)
   218 
   219 (*Converse appears to fail*)
   220 lemma (in Extend) project_set_I: "!!z. z \<in> C ==> f z \<in> project_set h C"
   221 by (auto simp add: split_extended_all)
   222 
   223 
   224 subsection{*More laws*}
   225 
   226 (*Because A and B could differ on the "other" part of the state, 
   227    cannot generalize to 
   228       project_set h (A \<inter> B) = project_set h A \<inter> project_set h B
   229 *)
   230 lemma (in Extend) project_set_extend_set_Int:
   231      "project_set h ((extend_set h A) \<inter> B) = A \<inter> (project_set h B)"
   232 by auto
   233 
   234 (*Unused, but interesting?*)
   235 lemma (in Extend) project_set_extend_set_Un:
   236      "project_set h ((extend_set h A) \<union> B) = A \<union> (project_set h B)"
   237 by auto
   238 
   239 lemma project_set_Int_subset:
   240      "project_set h (A \<inter> B) \<subseteq> (project_set h A) \<inter> (project_set h B)"
   241 by auto
   242 
   243 lemma (in Extend) extend_set_Un_distrib:
   244      "extend_set h (A \<union> B) = extend_set h A \<union> extend_set h B"
   245 by auto
   246 
   247 lemma (in Extend) extend_set_Int_distrib:
   248      "extend_set h (A \<inter> B) = extend_set h A \<inter> extend_set h B"
   249 by auto
   250 
   251 lemma (in Extend) extend_set_INT_distrib:
   252      "extend_set h (INTER A B) = (\<Inter>x \<in> A. extend_set h (B x))"
   253 by auto
   254 
   255 lemma (in Extend) extend_set_Diff_distrib:
   256      "extend_set h (A - B) = extend_set h A - extend_set h B"
   257 by auto
   258 
   259 lemma (in Extend) extend_set_Union:
   260      "extend_set h (Union A) = (\<Union>X \<in> A. extend_set h X)"
   261 by blast
   262 
   263 lemma (in Extend) extend_set_subset_Compl_eq:
   264      "(extend_set h A \<subseteq> - extend_set h B) = (A \<subseteq> - B)"
   265 by (unfold extend_set_def, auto)
   266 
   267 
   268 subsection{*@{term extend_act}*}
   269 
   270 (*Can't strengthen it to
   271   ((h(s,y), h(s',y')) \<in> extend_act h act) = ((s, s') \<in> act & y=y')
   272   because h doesn't have to be injective in the 2nd argument*)
   273 lemma (in Extend) mem_extend_act_iff [iff]: 
   274      "((h(s,y), h(s',y)) \<in> extend_act h act) = ((s, s') \<in> act)"
   275 by (unfold extend_act_def, auto)
   276 
   277 (*Converse fails: (z,z') would include actions that changed the g-part*)
   278 lemma (in Extend) extend_act_D: 
   279      "(z, z') \<in> extend_act h act ==> (f z, f z') \<in> act"
   280 by (unfold extend_act_def, auto)
   281 
   282 lemma (in Extend) extend_act_inverse [simp]: 
   283      "project_act h (extend_act h act) = act"
   284 by (unfold extend_act_def project_act_def, blast)
   285 
   286 lemma (in Extend) project_act_extend_act_restrict [simp]: 
   287      "project_act h (Restrict C (extend_act h act)) =  
   288       Restrict (project_set h C) act"
   289 by (unfold extend_act_def project_act_def, blast)
   290 
   291 lemma (in Extend) subset_extend_act_D: 
   292      "act' \<subseteq> extend_act h act ==> project_act h act' \<subseteq> act"
   293 by (unfold extend_act_def project_act_def, force)
   294 
   295 lemma (in Extend) inj_extend_act: "inj (extend_act h)"
   296 apply (rule inj_on_inverseI)
   297 apply (rule extend_act_inverse)
   298 done
   299 
   300 lemma (in Extend) extend_act_Image [simp]: 
   301      "extend_act h act `` (extend_set h A) = extend_set h (act `` A)"
   302 by (unfold extend_set_def extend_act_def, force)
   303 
   304 lemma (in Extend) extend_act_strict_mono [iff]:
   305      "(extend_act h act' \<subseteq> extend_act h act) = (act'<=act)"
   306 by (unfold extend_act_def, auto)
   307 
   308 declare (in Extend) inj_extend_act [THEN inj_eq, iff]
   309 (*This theorem is  (extend_act h act' = extend_act h act) = (act'=act) *)
   310 
   311 lemma Domain_extend_act: 
   312     "Domain (extend_act h act) = extend_set h (Domain act)"
   313 by (unfold extend_set_def extend_act_def, force)
   314 
   315 lemma (in Extend) extend_act_Id [simp]: 
   316     "extend_act h Id = Id"
   317 apply (unfold extend_act_def)
   318 apply (force intro: h_f_g_eq [symmetric])
   319 done
   320 
   321 lemma (in Extend) project_act_I: 
   322      "!!z z'. (z, z') \<in> act ==> (f z, f z') \<in> project_act h act"
   323 apply (unfold project_act_def)
   324 apply (force simp add: split_extended_all)
   325 done
   326 
   327 lemma (in Extend) project_act_Id [simp]: "project_act h Id = Id"
   328 by (unfold project_act_def, force)
   329 
   330 lemma (in Extend) Domain_project_act: 
   331   "Domain (project_act h act) = project_set h (Domain act)"
   332 apply (unfold project_act_def)
   333 apply (force simp add: split_extended_all)
   334 done
   335 
   336 
   337 
   338 subsection{*extend*}
   339 
   340 text{*Basic properties*}
   341 
   342 lemma Init_extend [simp]:
   343      "Init (extend h F) = extend_set h (Init F)"
   344 by (unfold extend_def, auto)
   345 
   346 lemma Init_project [simp]:
   347      "Init (project h C F) = project_set h (Init F)"
   348 by (unfold project_def, auto)
   349 
   350 lemma (in Extend) Acts_extend [simp]:
   351      "Acts (extend h F) = (extend_act h ` Acts F)"
   352 by (simp add: extend_def insert_Id_image_Acts)
   353 
   354 lemma (in Extend) AllowedActs_extend [simp]:
   355      "AllowedActs (extend h F) = project_act h -` AllowedActs F"
   356 by (simp add: extend_def insert_absorb)
   357 
   358 lemma Acts_project [simp]:
   359      "Acts(project h C F) = insert Id (project_act h ` Restrict C ` Acts F)"
   360 by (auto simp add: project_def image_iff)
   361 
   362 lemma (in Extend) AllowedActs_project [simp]:
   363      "AllowedActs(project h C F) =  
   364         {act. Restrict (project_set h C) act  
   365                \<in> project_act h ` Restrict C ` AllowedActs F}"
   366 apply (simp (no_asm) add: project_def image_iff)
   367 apply (subst insert_absorb)
   368 apply (auto intro!: bexI [of _ Id] simp add: project_act_def)
   369 done
   370 
   371 lemma (in Extend) Allowed_extend:
   372      "Allowed (extend h F) = project h UNIV -` Allowed F"
   373 by (auto simp add: Allowed_def)
   374 
   375 lemma (in Extend) extend_SKIP [simp]: "extend h SKIP = SKIP"
   376 apply (unfold SKIP_def)
   377 apply (rule program_equalityI, auto)
   378 done
   379 
   380 lemma project_set_UNIV [simp]: "project_set h UNIV = UNIV"
   381 by auto
   382 
   383 lemma project_set_Union:
   384      "project_set h (Union A) = (\<Union>X \<in> A. project_set h X)"
   385 by blast
   386 
   387 
   388 (*Converse FAILS: the extended state contributing to project_set h C
   389   may not coincide with the one contributing to project_act h act*)
   390 lemma (in Extend) project_act_Restrict_subset:
   391      "project_act h (Restrict C act) \<subseteq>  
   392       Restrict (project_set h C) (project_act h act)"
   393 by (auto simp add: project_act_def)
   394 
   395 lemma (in Extend) project_act_Restrict_Id_eq:
   396      "project_act h (Restrict C Id) = Restrict (project_set h C) Id"
   397 by (auto simp add: project_act_def)
   398 
   399 lemma (in Extend) project_extend_eq:
   400      "project h C (extend h F) =  
   401       mk_program (Init F, Restrict (project_set h C) ` Acts F,  
   402                   {act. Restrict (project_set h C) act 
   403                           \<in> project_act h ` Restrict C ` 
   404                                      (project_act h -` AllowedActs F)})"
   405 apply (rule program_equalityI)
   406   apply simp
   407  apply (simp add: image_eq_UN)
   408 apply (simp add: project_def)
   409 done
   410 
   411 lemma (in Extend) extend_inverse [simp]:
   412      "project h UNIV (extend h F) = F"
   413 apply (simp (no_asm_simp) add: project_extend_eq image_eq_UN
   414           subset_UNIV [THEN subset_trans, THEN Restrict_triv])
   415 apply (rule program_equalityI)
   416 apply (simp_all (no_asm))
   417 apply (subst insert_absorb)
   418 apply (simp (no_asm) add: bexI [of _ Id])
   419 apply auto
   420 apply (rename_tac "act")
   421 apply (rule_tac x = "extend_act h act" in bexI, auto)
   422 done
   423 
   424 lemma (in Extend) inj_extend: "inj (extend h)"
   425 apply (rule inj_on_inverseI)
   426 apply (rule extend_inverse)
   427 done
   428 
   429 lemma (in Extend) extend_Join [simp]:
   430      "extend h (F\<squnion>G) = extend h F\<squnion>extend h G"
   431 apply (rule program_equalityI)
   432 apply (simp (no_asm) add: extend_set_Int_distrib)
   433 apply (simp add: image_Un, auto)
   434 done
   435 
   436 lemma (in Extend) extend_JN [simp]:
   437      "extend h (JOIN I F) = (\<Squnion>i \<in> I. extend h (F i))"
   438 apply (rule program_equalityI)
   439   apply (simp (no_asm) add: extend_set_INT_distrib)
   440  apply (simp add: image_UN, auto)
   441 done
   442 
   443 (** These monotonicity results look natural but are UNUSED **)
   444 
   445 lemma (in Extend) extend_mono: "F \<le> G ==> extend h F \<le> extend h G"
   446 by (force simp add: component_eq_subset)
   447 
   448 lemma (in Extend) project_mono: "F \<le> G ==> project h C F \<le> project h C G"
   449 by (simp add: component_eq_subset, blast)
   450 
   451 lemma (in Extend) all_total_extend: "all_total F ==> all_total (extend h F)"
   452 by (simp add: all_total_def Domain_extend_act)
   453 
   454 subsection{*Safety: co, stable*}
   455 
   456 lemma (in Extend) extend_constrains:
   457      "(extend h F \<in> (extend_set h A) co (extend_set h B)) =  
   458       (F \<in> A co B)"
   459 by (simp add: constrains_def)
   460 
   461 lemma (in Extend) extend_stable:
   462      "(extend h F \<in> stable (extend_set h A)) = (F \<in> stable A)"
   463 by (simp add: stable_def extend_constrains)
   464 
   465 lemma (in Extend) extend_invariant:
   466      "(extend h F \<in> invariant (extend_set h A)) = (F \<in> invariant A)"
   467 by (simp add: invariant_def extend_stable)
   468 
   469 (*Projects the state predicates in the property satisfied by  extend h F.
   470   Converse fails: A and B may differ in their extra variables*)
   471 lemma (in Extend) extend_constrains_project_set:
   472      "extend h F \<in> A co B ==> F \<in> (project_set h A) co (project_set h B)"
   473 by (auto simp add: constrains_def, force)
   474 
   475 lemma (in Extend) extend_stable_project_set:
   476      "extend h F \<in> stable A ==> F \<in> stable (project_set h A)"
   477 by (simp add: stable_def extend_constrains_project_set)
   478 
   479 
   480 subsection{*Weak safety primitives: Co, Stable*}
   481 
   482 lemma (in Extend) reachable_extend_f:
   483      "p \<in> reachable (extend h F) ==> f p \<in> reachable F"
   484 apply (erule reachable.induct)
   485 apply (auto intro: reachable.intros simp add: extend_act_def image_iff)
   486 done
   487 
   488 lemma (in Extend) h_reachable_extend:
   489      "h(s,y) \<in> reachable (extend h F) ==> s \<in> reachable F"
   490 by (force dest!: reachable_extend_f)
   491 
   492 lemma (in Extend) reachable_extend_eq: 
   493      "reachable (extend h F) = extend_set h (reachable F)"
   494 apply (unfold extend_set_def)
   495 apply (rule equalityI)
   496 apply (force intro: h_f_g_eq [symmetric] dest!: reachable_extend_f, clarify)
   497 apply (erule reachable.induct)
   498 apply (force intro: reachable.intros)+
   499 done
   500 
   501 lemma (in Extend) extend_Constrains:
   502      "(extend h F \<in> (extend_set h A) Co (extend_set h B)) =   
   503       (F \<in> A Co B)"
   504 by (simp add: Constrains_def reachable_extend_eq extend_constrains 
   505               extend_set_Int_distrib [symmetric])
   506 
   507 lemma (in Extend) extend_Stable:
   508      "(extend h F \<in> Stable (extend_set h A)) = (F \<in> Stable A)"
   509 by (simp add: Stable_def extend_Constrains)
   510 
   511 lemma (in Extend) extend_Always:
   512      "(extend h F \<in> Always (extend_set h A)) = (F \<in> Always A)"
   513 by (simp (no_asm_simp) add: Always_def extend_Stable)
   514 
   515 
   516 (** Safety and "project" **)
   517 
   518 (** projection: monotonicity for safety **)
   519 
   520 lemma project_act_mono:
   521      "D \<subseteq> C ==>  
   522       project_act h (Restrict D act) \<subseteq> project_act h (Restrict C act)"
   523 by (auto simp add: project_act_def)
   524 
   525 lemma (in Extend) project_constrains_mono:
   526      "[| D \<subseteq> C; project h C F \<in> A co B |] ==> project h D F \<in> A co B"
   527 apply (auto simp add: constrains_def)
   528 apply (drule project_act_mono, blast)
   529 done
   530 
   531 lemma (in Extend) project_stable_mono:
   532      "[| D \<subseteq> C;  project h C F \<in> stable A |] ==> project h D F \<in> stable A"
   533 by (simp add: stable_def project_constrains_mono)
   534 
   535 (*Key lemma used in several proofs about project and co*)
   536 lemma (in Extend) project_constrains: 
   537      "(project h C F \<in> A co B)  =   
   538       (F \<in> (C \<inter> extend_set h A) co (extend_set h B) & A \<subseteq> B)"
   539 apply (unfold constrains_def)
   540 apply (auto intro!: project_act_I simp add: ball_Un)
   541 apply (force intro!: project_act_I dest!: subsetD)
   542 (*the <== direction*)
   543 apply (unfold project_act_def)
   544 apply (force dest!: subsetD)
   545 done
   546 
   547 lemma (in Extend) project_stable: 
   548      "(project h UNIV F \<in> stable A) = (F \<in> stable (extend_set h A))"
   549 apply (unfold stable_def)
   550 apply (simp (no_asm) add: project_constrains)
   551 done
   552 
   553 lemma (in Extend) project_stable_I:
   554      "F \<in> stable (extend_set h A) ==> project h C F \<in> stable A"
   555 apply (drule project_stable [THEN iffD2])
   556 apply (blast intro: project_stable_mono)
   557 done
   558 
   559 lemma (in Extend) Int_extend_set_lemma:
   560      "A \<inter> extend_set h ((project_set h A) \<inter> B) = A \<inter> extend_set h B"
   561 by (auto simp add: split_extended_all)
   562 
   563 (*Strange (look at occurrences of C) but used in leadsETo proofs*)
   564 lemma project_constrains_project_set:
   565      "G \<in> C co B ==> project h C G \<in> project_set h C co project_set h B"
   566 by (simp add: constrains_def project_def project_act_def, blast)
   567 
   568 lemma project_stable_project_set:
   569      "G \<in> stable C ==> project h C G \<in> stable (project_set h C)"
   570 by (simp add: stable_def project_constrains_project_set)
   571 
   572 
   573 subsection{*Progress: transient, ensures*}
   574 
   575 lemma (in Extend) extend_transient:
   576      "(extend h F \<in> transient (extend_set h A)) = (F \<in> transient A)"
   577 by (auto simp add: transient_def extend_set_subset_Compl_eq Domain_extend_act)
   578 
   579 lemma (in Extend) extend_ensures:
   580      "(extend h F \<in> (extend_set h A) ensures (extend_set h B)) =  
   581       (F \<in> A ensures B)"
   582 by (simp add: ensures_def extend_constrains extend_transient 
   583         extend_set_Un_distrib [symmetric] extend_set_Diff_distrib [symmetric])
   584 
   585 lemma (in Extend) leadsTo_imp_extend_leadsTo:
   586      "F \<in> A leadsTo B  
   587       ==> extend h F \<in> (extend_set h A) leadsTo (extend_set h B)"
   588 apply (erule leadsTo_induct)
   589   apply (simp add: leadsTo_Basis extend_ensures)
   590  apply (blast intro: leadsTo_Trans)
   591 apply (simp add: leadsTo_UN extend_set_Union)
   592 done
   593 
   594 subsection{*Proving the converse takes some doing!*}
   595 
   596 lemma (in Extend) slice_iff [iff]: "(x \<in> slice C y) = (h(x,y) \<in> C)"
   597 by (simp (no_asm) add: slice_def)
   598 
   599 lemma (in Extend) slice_Union: "slice (Union S) y = (\<Union>x \<in> S. slice x y)"
   600 by auto
   601 
   602 lemma (in Extend) slice_extend_set: "slice (extend_set h A) y = A"
   603 by auto
   604 
   605 lemma (in Extend) project_set_is_UN_slice:
   606      "project_set h A = (\<Union>y. slice A y)"
   607 by auto
   608 
   609 lemma (in Extend) extend_transient_slice:
   610      "extend h F \<in> transient A ==> F \<in> transient (slice A y)"
   611 by (unfold transient_def, auto)
   612 
   613 (*Converse?*)
   614 lemma (in Extend) extend_constrains_slice:
   615      "extend h F \<in> A co B ==> F \<in> (slice A y) co (slice B y)"
   616 by (auto simp add: constrains_def)
   617 
   618 lemma (in Extend) extend_ensures_slice:
   619      "extend h F \<in> A ensures B ==> F \<in> (slice A y) ensures (project_set h B)"
   620 apply (auto simp add: ensures_def extend_constrains extend_transient)
   621 apply (erule_tac [2] extend_transient_slice [THEN transient_strengthen])
   622 apply (erule extend_constrains_slice [THEN constrains_weaken], auto)
   623 done
   624 
   625 lemma (in Extend) leadsTo_slice_project_set:
   626      "\<forall>y. F \<in> (slice B y) leadsTo CU ==> F \<in> (project_set h B) leadsTo CU"
   627 apply (simp (no_asm) add: project_set_is_UN_slice)
   628 apply (blast intro: leadsTo_UN)
   629 done
   630 
   631 lemma (in Extend) extend_leadsTo_slice [rule_format]:
   632      "extend h F \<in> AU leadsTo BU  
   633       ==> \<forall>y. F \<in> (slice AU y) leadsTo (project_set h BU)"
   634 apply (erule leadsTo_induct)
   635   apply (blast intro: extend_ensures_slice)
   636  apply (blast intro: leadsTo_slice_project_set leadsTo_Trans)
   637 apply (simp add: leadsTo_UN slice_Union)
   638 done
   639 
   640 lemma (in Extend) extend_leadsTo:
   641      "(extend h F \<in> (extend_set h A) leadsTo (extend_set h B)) =  
   642       (F \<in> A leadsTo B)"
   643 apply safe
   644 apply (erule_tac [2] leadsTo_imp_extend_leadsTo)
   645 apply (drule extend_leadsTo_slice)
   646 apply (simp add: slice_extend_set)
   647 done
   648 
   649 lemma (in Extend) extend_LeadsTo:
   650      "(extend h F \<in> (extend_set h A) LeadsTo (extend_set h B)) =   
   651       (F \<in> A LeadsTo B)"
   652 by (simp add: LeadsTo_def reachable_extend_eq extend_leadsTo
   653               extend_set_Int_distrib [symmetric])
   654 
   655 
   656 subsection{*preserves*}
   657 
   658 lemma (in Extend) project_preserves_I:
   659      "G \<in> preserves (v o f) ==> project h C G \<in> preserves v"
   660 by (auto simp add: preserves_def project_stable_I extend_set_eq_Collect)
   661 
   662 (*to preserve f is to preserve the whole original state*)
   663 lemma (in Extend) project_preserves_id_I:
   664      "G \<in> preserves f ==> project h C G \<in> preserves id"
   665 by (simp add: project_preserves_I)
   666 
   667 lemma (in Extend) extend_preserves:
   668      "(extend h G \<in> preserves (v o f)) = (G \<in> preserves v)"
   669 by (auto simp add: preserves_def extend_stable [symmetric] 
   670                    extend_set_eq_Collect)
   671 
   672 lemma (in Extend) inj_extend_preserves: "inj h ==> (extend h G \<in> preserves g)"
   673 by (auto simp add: preserves_def extend_def extend_act_def stable_def 
   674                    constrains_def g_def)
   675 
   676 
   677 subsection{*Guarantees*}
   678 
   679 lemma (in Extend) project_extend_Join:
   680      "project h UNIV ((extend h F)\<squnion>G) = F\<squnion>(project h UNIV G)"
   681 apply (rule program_equalityI)
   682   apply (simp add: project_set_extend_set_Int)
   683  apply (auto simp add: image_eq_UN)
   684 done
   685 
   686 lemma (in Extend) extend_Join_eq_extend_D:
   687      "(extend h F)\<squnion>G = extend h H ==> H = F\<squnion>(project h UNIV G)"
   688 apply (drule_tac f = "project h UNIV" in arg_cong)
   689 apply (simp add: project_extend_Join)
   690 done
   691 
   692 (** Strong precondition and postcondition; only useful when
   693     the old and new state sets are in bijection **)
   694 
   695 
   696 lemma (in Extend) ok_extend_imp_ok_project:
   697      "extend h F ok G ==> F ok project h UNIV G"
   698 apply (auto simp add: ok_def)
   699 apply (drule subsetD)
   700 apply (auto intro!: rev_image_eqI)
   701 done
   702 
   703 lemma (in Extend) ok_extend_iff: "(extend h F ok extend h G) = (F ok G)"
   704 apply (simp add: ok_def, safe)
   705 apply (force+)
   706 done
   707 
   708 lemma (in Extend) OK_extend_iff: "OK I (%i. extend h (F i)) = (OK I F)"
   709 apply (unfold OK_def, safe)
   710 apply (drule_tac x = i in bspec)
   711 apply (drule_tac [2] x = j in bspec)
   712 apply (force+)
   713 done
   714 
   715 lemma (in Extend) guarantees_imp_extend_guarantees:
   716      "F \<in> X guarantees Y ==>  
   717       extend h F \<in> (extend h ` X) guarantees (extend h ` Y)"
   718 apply (rule guaranteesI, clarify)
   719 apply (blast dest: ok_extend_imp_ok_project extend_Join_eq_extend_D 
   720                    guaranteesD)
   721 done
   722 
   723 lemma (in Extend) extend_guarantees_imp_guarantees:
   724      "extend h F \<in> (extend h ` X) guarantees (extend h ` Y)  
   725       ==> F \<in> X guarantees Y"
   726 apply (auto simp add: guar_def)
   727 apply (drule_tac x = "extend h G" in spec)
   728 apply (simp del: extend_Join 
   729             add: extend_Join [symmetric] ok_extend_iff 
   730                  inj_extend [THEN inj_image_mem_iff])
   731 done
   732 
   733 lemma (in Extend) extend_guarantees_eq:
   734      "(extend h F \<in> (extend h ` X) guarantees (extend h ` Y)) =  
   735       (F \<in> X guarantees Y)"
   736 by (blast intro: guarantees_imp_extend_guarantees 
   737                  extend_guarantees_imp_guarantees)
   738 
   739 end