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