src/HOL/UNITY/Extend.thy
author haftmann
Sun Nov 18 18:07:51 2018 +0000 (8 months ago)
changeset 69313 b021008c5397
parent 67613 ce654b0e6d69
child 69597 ff784d5a5bfb
permissions -rw-r--r--
removed legacy input syntax
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
wenzelm@63146
    10
section\<open>Extending State Sets\<close>
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@61943
    17
  where "Restrict A r = r \<inter> (A \<times> UNIV)"
paulson@8948
    18
wenzelm@36866
    19
definition
paulson@7482
    20
  good_map :: "['a*'b => 'c] => bool"
wenzelm@61941
    21
  where "good_map h \<longleftrightarrow> 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@61943
    26
  where "extend_set h A = h ` (A \<times> 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@67613
    52
                   {act. Restrict (project_set h C) act \<in>
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
wenzelm@63146
    70
subsection\<open>Restrict\<close>
paulson@13798
    71
(*MOVE to Relation.thy?*)
paulson@13790
    72
wenzelm@67613
    73
lemma Restrict_iff [iff]: "((x,y) \<in> Restrict A r) = ((x,y) \<in> 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"
haftmann@61424
   130
by (metis UNIV_I f_inv_into_f prod.collapse prem surj_h)
paulson@13790
   131
paulson@13790
   132
wenzelm@63146
   133
subsection\<open>Trivial properties of f, g, h\<close>
paulson@13790
   134
wenzelm@46912
   135
context Extend
wenzelm@46912
   136
begin
wenzelm@46912
   137
wenzelm@46912
   138
lemma f_h_eq [simp]: "f(h(x,y)) = x" 
paulson@13790
   139
by (simp add: f_def good_h [unfolded good_map_def, THEN conjunct2])
paulson@13790
   140
wenzelm@46912
   141
lemma h_inject1 [dest]: "h(x,y) = h(x',y') ==> x=x'"
paulson@13790
   142
apply (drule_tac f = f in arg_cong)
paulson@13790
   143
apply (simp add: f_def good_h [unfolded good_map_def, THEN conjunct2])
paulson@13790
   144
done
paulson@13790
   145
wenzelm@46912
   146
lemma h_f_g_equiv: "h(f z, g z) == z"
paulson@13790
   147
by (simp add: f_def g_def 
paulson@13790
   148
            good_h [unfolded good_map_def, THEN conjunct1, THEN surj_f_inv_f])
paulson@13790
   149
wenzelm@46912
   150
lemma h_f_g_eq: "h(f z, g z) = z"
paulson@13790
   151
by (simp add: h_f_g_equiv)
paulson@13790
   152
paulson@13790
   153
wenzelm@46912
   154
lemma split_extended_all:
paulson@13790
   155
     "(!!z. PROP P z) == (!!u y. PROP P (h (u, y)))"
paulson@13790
   156
proof 
paulson@13790
   157
   assume allP: "\<And>z. PROP P z"
paulson@13790
   158
   fix u y
paulson@13790
   159
   show "PROP P (h (u, y))" by (rule allP)
paulson@13790
   160
 next
paulson@13790
   161
   assume allPh: "\<And>u y. PROP P (h(u,y))"
paulson@13790
   162
   fix z
paulson@13790
   163
   have Phfgz: "PROP P (h (f z, g z))" by (rule allPh)
paulson@13790
   164
   show "PROP P z" by (rule Phfgz [unfolded h_f_g_equiv])
paulson@13790
   165
qed 
paulson@13790
   166
wenzelm@46912
   167
end
paulson@13790
   168
paulson@13790
   169
wenzelm@63146
   170
subsection\<open>@{term extend_set}: basic properties\<close>
paulson@13790
   171
paulson@13790
   172
lemma project_set_iff [iff]:
paulson@13805
   173
     "(x \<in> project_set h C) = (\<exists>y. h(x,y) \<in> C)"
paulson@13790
   174
by (simp add: project_set_def)
paulson@13790
   175
paulson@13805
   176
lemma extend_set_mono: "A \<subseteq> B ==> extend_set h A \<subseteq> extend_set h B"
paulson@13790
   177
by (unfold extend_set_def, blast)
paulson@13790
   178
wenzelm@46912
   179
context Extend
wenzelm@46912
   180
begin
wenzelm@46912
   181
wenzelm@46912
   182
lemma mem_extend_set_iff [iff]: "z \<in> extend_set h A = (f z \<in> A)"
paulson@13790
   183
apply (unfold extend_set_def)
paulson@13790
   184
apply (force intro: h_f_g_eq [symmetric])
paulson@13790
   185
done
paulson@13790
   186
wenzelm@46912
   187
lemma extend_set_strict_mono [iff]:
paulson@13805
   188
     "(extend_set h A \<subseteq> extend_set h B) = (A \<subseteq> B)"
paulson@13790
   189
by (unfold extend_set_def, force)
paulson@13790
   190
wenzelm@46912
   191
lemma (in -) extend_set_empty [simp]: "extend_set h {} = {}"
paulson@13790
   192
by (unfold extend_set_def, auto)
paulson@13790
   193
wenzelm@46912
   194
lemma extend_set_eq_Collect: "extend_set h {s. P s} = {s. P(f s)}"
paulson@13790
   195
by auto
paulson@13790
   196
wenzelm@46912
   197
lemma extend_set_sing: "extend_set h {x} = {s. f s = x}"
paulson@13790
   198
by auto
paulson@13790
   199
wenzelm@46912
   200
lemma extend_set_inverse [simp]: "project_set h (extend_set h C) = C"
paulson@13790
   201
by (unfold extend_set_def, auto)
paulson@13790
   202
wenzelm@46912
   203
lemma extend_set_project_set: "C \<subseteq> extend_set h (project_set h C)"
paulson@13790
   204
apply (unfold extend_set_def)
paulson@13790
   205
apply (auto simp add: split_extended_all, blast)
paulson@13790
   206
done
paulson@13790
   207
wenzelm@46912
   208
lemma inj_extend_set: "inj (extend_set h)"
paulson@13790
   209
apply (rule inj_on_inverseI)
paulson@13790
   210
apply (rule extend_set_inverse)
paulson@13790
   211
done
paulson@13790
   212
wenzelm@46912
   213
lemma extend_set_UNIV_eq [simp]: "extend_set h UNIV = UNIV"
paulson@13790
   214
apply (unfold extend_set_def)
paulson@13790
   215
apply (auto simp add: split_extended_all)
paulson@13790
   216
done
paulson@13790
   217
wenzelm@63146
   218
subsection\<open>@{term project_set}: basic properties\<close>
paulson@13790
   219
paulson@13790
   220
(*project_set is simply image!*)
wenzelm@46912
   221
lemma project_set_eq: "project_set h C = f ` C"
paulson@13790
   222
by (auto intro: f_h_eq [symmetric] simp add: split_extended_all)
paulson@13790
   223
paulson@13790
   224
(*Converse appears to fail*)
wenzelm@46912
   225
lemma project_set_I: "!!z. z \<in> C ==> f z \<in> project_set h C"
paulson@13790
   226
by (auto simp add: split_extended_all)
paulson@13790
   227
paulson@13790
   228
wenzelm@63146
   229
subsection\<open>More laws\<close>
paulson@13790
   230
paulson@13790
   231
(*Because A and B could differ on the "other" part of the state, 
paulson@13790
   232
   cannot generalize to 
paulson@13805
   233
      project_set h (A \<inter> B) = project_set h A \<inter> project_set h B
paulson@13790
   234
*)
wenzelm@46912
   235
lemma project_set_extend_set_Int: "project_set h ((extend_set h A) \<inter> B) = A \<inter> (project_set h B)"
wenzelm@46912
   236
  by auto
paulson@13790
   237
paulson@13790
   238
(*Unused, but interesting?*)
wenzelm@46912
   239
lemma project_set_extend_set_Un: "project_set h ((extend_set h A) \<union> B) = A \<union> (project_set h B)"
wenzelm@46912
   240
  by auto
paulson@13790
   241
wenzelm@46912
   242
lemma (in -) project_set_Int_subset:
wenzelm@46912
   243
    "project_set h (A \<inter> B) \<subseteq> (project_set h A) \<inter> (project_set h B)"
wenzelm@46912
   244
  by auto
paulson@13790
   245
wenzelm@46912
   246
lemma extend_set_Un_distrib: "extend_set h (A \<union> B) = extend_set h A \<union> extend_set h B"
wenzelm@46912
   247
  by auto
paulson@13790
   248
wenzelm@46912
   249
lemma extend_set_Int_distrib: "extend_set h (A \<inter> B) = extend_set h A \<inter> extend_set h B"
wenzelm@46912
   250
  by auto
paulson@13790
   251
haftmann@69313
   252
lemma extend_set_INT_distrib: "extend_set h (\<Inter>(B ` A)) = (\<Inter>x \<in> A. extend_set h (B x))"
wenzelm@46912
   253
  by auto
paulson@13790
   254
wenzelm@46912
   255
lemma extend_set_Diff_distrib: "extend_set h (A - B) = extend_set h A - extend_set h B"
wenzelm@46912
   256
  by auto
paulson@13790
   257
wenzelm@61952
   258
lemma extend_set_Union: "extend_set h (\<Union>A) = (\<Union>X \<in> A. extend_set h X)"
wenzelm@46912
   259
  by blast
wenzelm@46912
   260
wenzelm@46912
   261
lemma extend_set_subset_Compl_eq: "(extend_set h A \<subseteq> - extend_set h B) = (A \<subseteq> - B)"
wenzelm@46912
   262
  by (auto simp: extend_set_def)
paulson@13790
   263
paulson@13790
   264
wenzelm@63146
   265
subsection\<open>@{term extend_act}\<close>
paulson@13790
   266
paulson@13790
   267
(*Can't strengthen it to
paulson@13805
   268
  ((h(s,y), h(s',y')) \<in> extend_act h act) = ((s, s') \<in> act & y=y')
paulson@13790
   269
  because h doesn't have to be injective in the 2nd argument*)
wenzelm@46912
   270
lemma mem_extend_act_iff [iff]: "((h(s,y), h(s',y)) \<in> extend_act h act) = ((s, s') \<in> act)"
wenzelm@46912
   271
  by (auto simp: extend_act_def)
paulson@13790
   272
paulson@13790
   273
(*Converse fails: (z,z') would include actions that changed the g-part*)
wenzelm@46912
   274
lemma extend_act_D: "(z, z') \<in> extend_act h act ==> (f z, f z') \<in> act"
wenzelm@46912
   275
  by (auto simp: extend_act_def)
paulson@13790
   276
wenzelm@46912
   277
lemma extend_act_inverse [simp]: "project_act h (extend_act h act) = act"
wenzelm@46912
   278
  unfolding extend_act_def project_act_def by blast
paulson@13790
   279
wenzelm@46912
   280
lemma project_act_extend_act_restrict [simp]:
paulson@13790
   281
     "project_act h (Restrict C (extend_act h act)) =  
paulson@13790
   282
      Restrict (project_set h C) act"
wenzelm@46912
   283
  unfolding extend_act_def project_act_def by blast
paulson@13790
   284
wenzelm@46912
   285
lemma subset_extend_act_D: "act' \<subseteq> extend_act h act ==> project_act h act' \<subseteq> act"
wenzelm@46912
   286
  unfolding extend_act_def project_act_def by force
paulson@13790
   287
wenzelm@46912
   288
lemma inj_extend_act: "inj (extend_act h)"
paulson@13790
   289
apply (rule inj_on_inverseI)
paulson@13790
   290
apply (rule extend_act_inverse)
paulson@13790
   291
done
paulson@13790
   292
wenzelm@46912
   293
lemma extend_act_Image [simp]:
paulson@13790
   294
     "extend_act h act `` (extend_set h A) = extend_set h (act `` A)"
wenzelm@46912
   295
  unfolding extend_set_def extend_act_def by force
paulson@13790
   296
wenzelm@46912
   297
lemma extend_act_strict_mono [iff]:
paulson@13805
   298
     "(extend_act h act' \<subseteq> extend_act h act) = (act'<=act)"
wenzelm@46912
   299
  by (auto simp: extend_act_def)
paulson@13790
   300
wenzelm@46912
   301
lemma [iff]: "(extend_act h act = extend_act h act') = (act = act')"
wenzelm@46912
   302
  by (rule inj_extend_act [THEN inj_eq])
paulson@13790
   303
wenzelm@46912
   304
lemma (in -) Domain_extend_act:
wenzelm@46912
   305
    "Domain (extend_act h act) = extend_set h (Domain act)"
wenzelm@46912
   306
  unfolding extend_set_def extend_act_def by force
wenzelm@46912
   307
wenzelm@46912
   308
lemma extend_act_Id [simp]: "extend_act h Id = Id"
wenzelm@46912
   309
  unfolding extend_act_def by (force intro: h_f_g_eq [symmetric])
paulson@13790
   310
wenzelm@46912
   311
lemma project_act_I:  "!!z z'. (z, z') \<in> act ==> (f z, f z') \<in> project_act h act"
wenzelm@46912
   312
  unfolding project_act_def by (force simp add: split_extended_all)
paulson@13790
   313
wenzelm@46912
   314
lemma project_act_Id [simp]: "project_act h Id = Id"
wenzelm@46912
   315
  unfolding project_act_def by force
paulson@13790
   316
wenzelm@46912
   317
lemma Domain_project_act: "Domain (project_act h act) = project_set h (Domain act)"
wenzelm@46912
   318
  unfolding project_act_def by (force simp add: split_extended_all)
paulson@13790
   319
paulson@13790
   320
wenzelm@63146
   321
subsection\<open>extend\<close>
paulson@13790
   322
wenzelm@63146
   323
text\<open>Basic properties\<close>
paulson@13790
   324
wenzelm@46912
   325
lemma (in -) Init_extend [simp]:
paulson@13790
   326
     "Init (extend h F) = extend_set h (Init F)"
wenzelm@46912
   327
  by (auto simp: extend_def)
paulson@13790
   328
wenzelm@46912
   329
lemma (in -) Init_project [simp]:
paulson@13790
   330
     "Init (project h C F) = project_set h (Init F)"
wenzelm@46912
   331
  by (auto simp: project_def)
paulson@13790
   332
wenzelm@46912
   333
lemma Acts_extend [simp]: "Acts (extend h F) = (extend_act h ` Acts F)"
wenzelm@46912
   334
  by (simp add: extend_def insert_Id_image_Acts)
paulson@13790
   335
wenzelm@46912
   336
lemma AllowedActs_extend [simp]:
paulson@13790
   337
     "AllowedActs (extend h F) = project_act h -` AllowedActs F"
wenzelm@46912
   338
  by (simp add: extend_def insert_absorb)
paulson@13790
   339
wenzelm@46912
   340
lemma (in -) Acts_project [simp]:
paulson@13790
   341
     "Acts(project h C F) = insert Id (project_act h ` Restrict C ` Acts F)"
wenzelm@46912
   342
  by (auto simp add: project_def image_iff)
paulson@13790
   343
wenzelm@46912
   344
lemma AllowedActs_project [simp]:
paulson@13790
   345
     "AllowedActs(project h C F) =  
paulson@13790
   346
        {act. Restrict (project_set h C) act  
paulson@13805
   347
               \<in> project_act h ` Restrict C ` AllowedActs F}"
paulson@13790
   348
apply (simp (no_asm) add: project_def image_iff)
paulson@13790
   349
apply (subst insert_absorb)
paulson@13790
   350
apply (auto intro!: bexI [of _ Id] simp add: project_act_def)
paulson@13790
   351
done
paulson@13790
   352
wenzelm@46912
   353
lemma Allowed_extend: "Allowed (extend h F) = project h UNIV -` Allowed F"
wenzelm@46912
   354
  by (auto simp add: Allowed_def)
paulson@13790
   355
wenzelm@46912
   356
lemma extend_SKIP [simp]: "extend h SKIP = SKIP"
paulson@13790
   357
apply (unfold SKIP_def)
paulson@13790
   358
apply (rule program_equalityI, auto)
paulson@13790
   359
done
paulson@13790
   360
wenzelm@46912
   361
lemma (in -) project_set_UNIV [simp]: "project_set h UNIV = UNIV"
wenzelm@46912
   362
  by auto
paulson@13790
   363
wenzelm@61952
   364
lemma (in -) project_set_Union: "project_set h (\<Union>A) = (\<Union>X \<in> A. project_set h X)"
wenzelm@46912
   365
  by blast
paulson@13790
   366
paulson@6297
   367
paulson@13790
   368
(*Converse FAILS: the extended state contributing to project_set h C
paulson@13790
   369
  may not coincide with the one contributing to project_act h act*)
wenzelm@46912
   370
lemma (in -) project_act_Restrict_subset:
wenzelm@46912
   371
     "project_act h (Restrict C act) \<subseteq> Restrict (project_set h C) (project_act h act)"
wenzelm@46912
   372
  by (auto simp add: project_act_def)
paulson@13790
   373
wenzelm@46912
   374
lemma project_act_Restrict_Id_eq: "project_act h (Restrict C Id) = Restrict (project_set h C) Id"
wenzelm@46912
   375
  by (auto simp add: project_act_def)
paulson@13790
   376
wenzelm@46912
   377
lemma project_extend_eq:
paulson@13790
   378
     "project h C (extend h F) =  
paulson@13790
   379
      mk_program (Init F, Restrict (project_set h C) ` Acts F,  
paulson@13790
   380
                  {act. Restrict (project_set h C) act 
paulson@13805
   381
                          \<in> project_act h ` Restrict C ` 
paulson@13790
   382
                                     (project_act h -` AllowedActs F)})"
paulson@13790
   383
apply (rule program_equalityI)
paulson@13790
   384
  apply simp
haftmann@62343
   385
 apply (simp add: image_image)
paulson@13790
   386
apply (simp add: project_def)
paulson@13790
   387
done
paulson@13790
   388
wenzelm@46912
   389
lemma extend_inverse [simp]:
paulson@13790
   390
     "project h UNIV (extend h F) = F"
haftmann@62343
   391
apply (simp (no_asm_simp) add: project_extend_eq
paulson@13790
   392
          subset_UNIV [THEN subset_trans, THEN Restrict_triv])
paulson@13790
   393
apply (rule program_equalityI)
paulson@13790
   394
apply (simp_all (no_asm))
paulson@13790
   395
apply (subst insert_absorb)
paulson@13790
   396
apply (simp (no_asm) add: bexI [of _ Id])
paulson@13790
   397
apply auto
haftmann@62343
   398
apply (simp add: image_def)
haftmann@62343
   399
using project_act_Id apply blast
haftmann@62343
   400
apply (simp add: image_def)
paulson@13790
   401
apply (rename_tac "act")
haftmann@62343
   402
apply (rule_tac x = "extend_act h act" in exI)
haftmann@62343
   403
apply simp
paulson@13790
   404
done
paulson@13790
   405
wenzelm@46912
   406
lemma inj_extend: "inj (extend h)"
paulson@13790
   407
apply (rule inj_on_inverseI)
paulson@13790
   408
apply (rule extend_inverse)
paulson@13790
   409
done
paulson@13790
   410
wenzelm@46912
   411
lemma extend_Join [simp]: "extend h (F\<squnion>G) = extend h F\<squnion>extend h G"
paulson@13790
   412
apply (rule program_equalityI)
paulson@13790
   413
apply (simp (no_asm) add: extend_set_Int_distrib)
paulson@13790
   414
apply (simp add: image_Un, auto)
paulson@13790
   415
done
paulson@13790
   416
wenzelm@46912
   417
lemma extend_JN [simp]: "extend h (JOIN I F) = (\<Squnion>i \<in> I. extend h (F i))"
paulson@13790
   418
apply (rule program_equalityI)
paulson@13790
   419
  apply (simp (no_asm) add: extend_set_INT_distrib)
paulson@13790
   420
 apply (simp add: image_UN, auto)
paulson@13790
   421
done
paulson@13790
   422
paulson@13790
   423
(** These monotonicity results look natural but are UNUSED **)
paulson@13790
   424
wenzelm@46912
   425
lemma extend_mono: "F \<le> G ==> extend h F \<le> extend h G"
wenzelm@46912
   426
  by (force simp add: component_eq_subset)
paulson@13790
   427
wenzelm@46912
   428
lemma project_mono: "F \<le> G ==> project h C F \<le> project h C G"
wenzelm@46912
   429
  by (simp add: component_eq_subset, blast)
paulson@13790
   430
wenzelm@46912
   431
lemma all_total_extend: "all_total F ==> all_total (extend h F)"
wenzelm@46912
   432
  by (simp add: all_total_def Domain_extend_act)
paulson@13790
   433
wenzelm@63146
   434
subsection\<open>Safety: co, stable\<close>
paulson@13790
   435
wenzelm@46912
   436
lemma extend_constrains:
paulson@13805
   437
     "(extend h F \<in> (extend_set h A) co (extend_set h B)) =  
paulson@13805
   438
      (F \<in> A co B)"
wenzelm@46912
   439
  by (simp add: constrains_def)
paulson@13790
   440
wenzelm@46912
   441
lemma extend_stable:
paulson@13805
   442
     "(extend h F \<in> stable (extend_set h A)) = (F \<in> stable A)"
wenzelm@46912
   443
  by (simp add: stable_def extend_constrains)
paulson@13790
   444
wenzelm@46912
   445
lemma extend_invariant:
paulson@13805
   446
     "(extend h F \<in> invariant (extend_set h A)) = (F \<in> invariant A)"
wenzelm@46912
   447
  by (simp add: invariant_def extend_stable)
paulson@13790
   448
paulson@13790
   449
(*Projects the state predicates in the property satisfied by  extend h F.
paulson@13790
   450
  Converse fails: A and B may differ in their extra variables*)
wenzelm@46912
   451
lemma extend_constrains_project_set:
paulson@13805
   452
     "extend h F \<in> A co B ==> F \<in> (project_set h A) co (project_set h B)"
wenzelm@46912
   453
  by (auto simp add: constrains_def, force)
paulson@13790
   454
wenzelm@46912
   455
lemma extend_stable_project_set:
paulson@13805
   456
     "extend h F \<in> stable A ==> F \<in> stable (project_set h A)"
wenzelm@46912
   457
  by (simp add: stable_def extend_constrains_project_set)
paulson@13790
   458
paulson@13790
   459
wenzelm@63146
   460
subsection\<open>Weak safety primitives: Co, Stable\<close>
paulson@13790
   461
wenzelm@46912
   462
lemma reachable_extend_f: "p \<in> reachable (extend h F) ==> f p \<in> reachable F"
wenzelm@46912
   463
  by (induct set: reachable) (auto intro: reachable.intros simp add: extend_act_def image_iff)
paulson@13790
   464
wenzelm@46912
   465
lemma h_reachable_extend: "h(s,y) \<in> reachable (extend h F) ==> s \<in> reachable F"
wenzelm@46912
   466
  by (force dest!: reachable_extend_f)
paulson@13790
   467
wenzelm@46912
   468
lemma reachable_extend_eq: "reachable (extend h F) = extend_set h (reachable F)"
paulson@13790
   469
apply (unfold extend_set_def)
paulson@13790
   470
apply (rule equalityI)
paulson@13790
   471
apply (force intro: h_f_g_eq [symmetric] dest!: reachable_extend_f, clarify)
paulson@13790
   472
apply (erule reachable.induct)
paulson@13790
   473
apply (force intro: reachable.intros)+
paulson@13790
   474
done
paulson@13790
   475
wenzelm@46912
   476
lemma extend_Constrains:
paulson@13805
   477
     "(extend h F \<in> (extend_set h A) Co (extend_set h B)) =   
paulson@13805
   478
      (F \<in> A Co B)"
wenzelm@46912
   479
  by (simp add: Constrains_def reachable_extend_eq extend_constrains 
paulson@13790
   480
              extend_set_Int_distrib [symmetric])
paulson@13790
   481
wenzelm@46912
   482
lemma extend_Stable: "(extend h F \<in> Stable (extend_set h A)) = (F \<in> Stable A)"
wenzelm@46912
   483
  by (simp add: Stable_def extend_Constrains)
paulson@13790
   484
wenzelm@46912
   485
lemma extend_Always: "(extend h F \<in> Always (extend_set h A)) = (F \<in> Always A)"
wenzelm@46912
   486
  by (simp add: Always_def extend_Stable)
paulson@13790
   487
paulson@13790
   488
paulson@13790
   489
(** Safety and "project" **)
paulson@13790
   490
paulson@13790
   491
(** projection: monotonicity for safety **)
paulson@13790
   492
wenzelm@46912
   493
lemma (in -) project_act_mono:
paulson@13805
   494
     "D \<subseteq> C ==>  
paulson@13805
   495
      project_act h (Restrict D act) \<subseteq> project_act h (Restrict C act)"
wenzelm@46912
   496
  by (auto simp add: project_act_def)
paulson@13790
   497
wenzelm@46912
   498
lemma project_constrains_mono:
paulson@13805
   499
     "[| D \<subseteq> C; project h C F \<in> A co B |] ==> project h D F \<in> A co B"
paulson@13790
   500
apply (auto simp add: constrains_def)
paulson@13790
   501
apply (drule project_act_mono, blast)
paulson@13790
   502
done
paulson@13790
   503
wenzelm@46912
   504
lemma project_stable_mono:
paulson@13805
   505
     "[| D \<subseteq> C;  project h C F \<in> stable A |] ==> project h D F \<in> stable A"
wenzelm@46912
   506
  by (simp add: stable_def project_constrains_mono)
paulson@13790
   507
paulson@13790
   508
(*Key lemma used in several proofs about project and co*)
wenzelm@46912
   509
lemma project_constrains: 
paulson@13805
   510
     "(project h C F \<in> A co B)  =   
paulson@13805
   511
      (F \<in> (C \<inter> extend_set h A) co (extend_set h B) & A \<subseteq> B)"
paulson@13790
   512
apply (unfold constrains_def)
paulson@13790
   513
apply (auto intro!: project_act_I simp add: ball_Un)
paulson@13790
   514
apply (force intro!: project_act_I dest!: subsetD)
paulson@13790
   515
(*the <== direction*)
paulson@13790
   516
apply (unfold project_act_def)
paulson@13790
   517
apply (force dest!: subsetD)
paulson@13790
   518
done
paulson@13790
   519
wenzelm@46912
   520
lemma project_stable: "(project h UNIV F \<in> stable A) = (F \<in> stable (extend_set h A))"
wenzelm@46912
   521
  by (simp add: stable_def project_constrains)
paulson@13790
   522
wenzelm@46912
   523
lemma project_stable_I: "F \<in> stable (extend_set h A) ==> project h C F \<in> stable A"
paulson@13790
   524
apply (drule project_stable [THEN iffD2])
paulson@13790
   525
apply (blast intro: project_stable_mono)
paulson@13790
   526
done
paulson@13790
   527
wenzelm@46912
   528
lemma Int_extend_set_lemma:
paulson@13805
   529
     "A \<inter> extend_set h ((project_set h A) \<inter> B) = A \<inter> extend_set h B"
wenzelm@46912
   530
  by (auto simp add: split_extended_all)
paulson@13790
   531
paulson@13790
   532
(*Strange (look at occurrences of C) but used in leadsETo proofs*)
paulson@13790
   533
lemma project_constrains_project_set:
paulson@13805
   534
     "G \<in> C co B ==> project h C G \<in> project_set h C co project_set h B"
wenzelm@46912
   535
  by (simp add: constrains_def project_def project_act_def, blast)
paulson@13790
   536
paulson@13790
   537
lemma project_stable_project_set:
paulson@13805
   538
     "G \<in> stable C ==> project h C G \<in> stable (project_set h C)"
wenzelm@46912
   539
  by (simp add: stable_def project_constrains_project_set)
paulson@13790
   540
paulson@13790
   541
wenzelm@63146
   542
subsection\<open>Progress: transient, ensures\<close>
paulson@13790
   543
wenzelm@46912
   544
lemma extend_transient:
paulson@13805
   545
     "(extend h F \<in> transient (extend_set h A)) = (F \<in> transient A)"
wenzelm@46912
   546
  by (auto simp add: transient_def extend_set_subset_Compl_eq Domain_extend_act)
paulson@13790
   547
wenzelm@46912
   548
lemma extend_ensures:
paulson@13805
   549
     "(extend h F \<in> (extend_set h A) ensures (extend_set h B)) =  
paulson@13805
   550
      (F \<in> A ensures B)"
wenzelm@46912
   551
  by (simp add: ensures_def extend_constrains extend_transient 
paulson@13790
   552
        extend_set_Un_distrib [symmetric] extend_set_Diff_distrib [symmetric])
paulson@13790
   553
wenzelm@46912
   554
lemma leadsTo_imp_extend_leadsTo:
paulson@13805
   555
     "F \<in> A leadsTo B  
paulson@13805
   556
      ==> extend h F \<in> (extend_set h A) leadsTo (extend_set h B)"
paulson@13790
   557
apply (erule leadsTo_induct)
paulson@13790
   558
  apply (simp add: leadsTo_Basis extend_ensures)
paulson@13790
   559
 apply (blast intro: leadsTo_Trans)
paulson@13790
   560
apply (simp add: leadsTo_UN extend_set_Union)
paulson@13790
   561
done
paulson@13790
   562
wenzelm@63146
   563
subsection\<open>Proving the converse takes some doing!\<close>
paulson@13790
   564
wenzelm@46912
   565
lemma slice_iff [iff]: "(x \<in> slice C y) = (h(x,y) \<in> C)"
wenzelm@46912
   566
  by (simp add: slice_def)
paulson@13790
   567
wenzelm@61952
   568
lemma slice_Union: "slice (\<Union>S) y = (\<Union>x \<in> S. slice x y)"
wenzelm@46912
   569
  by auto
paulson@13790
   570
wenzelm@46912
   571
lemma slice_extend_set: "slice (extend_set h A) y = A"
wenzelm@46912
   572
  by auto
paulson@13790
   573
wenzelm@46912
   574
lemma project_set_is_UN_slice: "project_set h A = (\<Union>y. slice A y)"
wenzelm@46912
   575
  by auto
paulson@13790
   576
wenzelm@46912
   577
lemma extend_transient_slice:
paulson@13805
   578
     "extend h F \<in> transient A ==> F \<in> transient (slice A y)"
wenzelm@46912
   579
  by (auto simp: transient_def)
paulson@13790
   580
paulson@13790
   581
(*Converse?*)
wenzelm@46912
   582
lemma extend_constrains_slice:
paulson@13805
   583
     "extend h F \<in> A co B ==> F \<in> (slice A y) co (slice B y)"
wenzelm@46912
   584
  by (auto simp add: constrains_def)
paulson@13790
   585
wenzelm@46912
   586
lemma extend_ensures_slice:
paulson@13805
   587
     "extend h F \<in> A ensures B ==> F \<in> (slice A y) ensures (project_set h B)"
paulson@13790
   588
apply (auto simp add: ensures_def extend_constrains extend_transient)
paulson@13790
   589
apply (erule_tac [2] extend_transient_slice [THEN transient_strengthen])
paulson@13790
   590
apply (erule extend_constrains_slice [THEN constrains_weaken], auto)
paulson@13790
   591
done
paulson@13790
   592
wenzelm@46912
   593
lemma leadsTo_slice_project_set:
paulson@13805
   594
     "\<forall>y. F \<in> (slice B y) leadsTo CU ==> F \<in> (project_set h B) leadsTo CU"
wenzelm@46912
   595
apply (simp add: project_set_is_UN_slice)
paulson@13790
   596
apply (blast intro: leadsTo_UN)
paulson@13790
   597
done
paulson@13790
   598
wenzelm@46912
   599
lemma extend_leadsTo_slice [rule_format]:
paulson@13805
   600
     "extend h F \<in> AU leadsTo BU  
paulson@13805
   601
      ==> \<forall>y. F \<in> (slice AU y) leadsTo (project_set h BU)"
paulson@13790
   602
apply (erule leadsTo_induct)
wenzelm@46577
   603
  apply (blast intro: extend_ensures_slice)
paulson@13790
   604
 apply (blast intro: leadsTo_slice_project_set leadsTo_Trans)
paulson@13790
   605
apply (simp add: leadsTo_UN slice_Union)
paulson@13790
   606
done
paulson@13790
   607
wenzelm@46912
   608
lemma extend_leadsTo:
paulson@13805
   609
     "(extend h F \<in> (extend_set h A) leadsTo (extend_set h B)) =  
paulson@13805
   610
      (F \<in> A leadsTo B)"
paulson@13790
   611
apply safe
paulson@13790
   612
apply (erule_tac [2] leadsTo_imp_extend_leadsTo)
paulson@13790
   613
apply (drule extend_leadsTo_slice)
paulson@13790
   614
apply (simp add: slice_extend_set)
paulson@13790
   615
done
paulson@13790
   616
wenzelm@46912
   617
lemma extend_LeadsTo:
paulson@13805
   618
     "(extend h F \<in> (extend_set h A) LeadsTo (extend_set h B)) =   
paulson@13805
   619
      (F \<in> A LeadsTo B)"
wenzelm@46912
   620
  by (simp add: LeadsTo_def reachable_extend_eq extend_leadsTo
paulson@13790
   621
              extend_set_Int_distrib [symmetric])
paulson@13790
   622
paulson@13790
   623
wenzelm@63146
   624
subsection\<open>preserves\<close>
paulson@13790
   625
wenzelm@46912
   626
lemma project_preserves_I:
paulson@13805
   627
     "G \<in> preserves (v o f) ==> project h C G \<in> preserves v"
wenzelm@46912
   628
  by (auto simp add: preserves_def project_stable_I extend_set_eq_Collect)
paulson@13790
   629
paulson@13790
   630
(*to preserve f is to preserve the whole original state*)
wenzelm@46912
   631
lemma project_preserves_id_I:
paulson@13805
   632
     "G \<in> preserves f ==> project h C G \<in> preserves id"
wenzelm@46912
   633
  by (simp add: project_preserves_I)
paulson@13790
   634
wenzelm@46912
   635
lemma extend_preserves:
paulson@13805
   636
     "(extend h G \<in> preserves (v o f)) = (G \<in> preserves v)"
wenzelm@46912
   637
  by (auto simp add: preserves_def extend_stable [symmetric] 
paulson@13790
   638
                   extend_set_eq_Collect)
paulson@13790
   639
wenzelm@46912
   640
lemma inj_extend_preserves: "inj h ==> (extend h G \<in> preserves g)"
wenzelm@46912
   641
  by (auto simp add: preserves_def extend_def extend_act_def stable_def 
paulson@13790
   642
                   constrains_def g_def)
paulson@13790
   643
paulson@13790
   644
wenzelm@63146
   645
subsection\<open>Guarantees\<close>
paulson@13790
   646
wenzelm@46912
   647
lemma project_extend_Join: "project h UNIV ((extend h F)\<squnion>G) = F\<squnion>(project h UNIV G)"
haftmann@62343
   648
  apply (rule program_equalityI)
haftmann@62343
   649
  apply (auto simp add: project_set_extend_set_Int image_iff)
haftmann@62343
   650
  apply (metis Un_iff extend_act_inverse image_iff)
haftmann@62343
   651
  apply (metis Un_iff extend_act_inverse image_iff)
haftmann@62343
   652
  done
haftmann@62343
   653
  
wenzelm@46912
   654
lemma extend_Join_eq_extend_D:
paulson@13819
   655
     "(extend h F)\<squnion>G = extend h H ==> H = F\<squnion>(project h UNIV G)"
paulson@13790
   656
apply (drule_tac f = "project h UNIV" in arg_cong)
paulson@13790
   657
apply (simp add: project_extend_Join)
paulson@13790
   658
done
paulson@13790
   659
paulson@13790
   660
(** Strong precondition and postcondition; only useful when
paulson@13790
   661
    the old and new state sets are in bijection **)
paulson@13790
   662
paulson@13790
   663
wenzelm@46912
   664
lemma ok_extend_imp_ok_project: "extend h F ok G ==> F ok project h UNIV G"
paulson@13790
   665
apply (auto simp add: ok_def)
paulson@13790
   666
apply (drule subsetD)
paulson@13790
   667
apply (auto intro!: rev_image_eqI)
paulson@13790
   668
done
paulson@13790
   669
wenzelm@46912
   670
lemma ok_extend_iff: "(extend h F ok extend h G) = (F ok G)"
paulson@13790
   671
apply (simp add: ok_def, safe)
wenzelm@46912
   672
apply force+
paulson@13790
   673
done
paulson@13790
   674
wenzelm@46912
   675
lemma OK_extend_iff: "OK I (%i. extend h (F i)) = (OK I F)"
paulson@13790
   676
apply (unfold OK_def, safe)
paulson@13790
   677
apply (drule_tac x = i in bspec)
paulson@13790
   678
apply (drule_tac [2] x = j in bspec)
wenzelm@46912
   679
apply force+
paulson@13790
   680
done
paulson@13790
   681
wenzelm@46912
   682
lemma guarantees_imp_extend_guarantees:
paulson@13805
   683
     "F \<in> X guarantees Y ==>  
paulson@13805
   684
      extend h F \<in> (extend h ` X) guarantees (extend h ` Y)"
paulson@13790
   685
apply (rule guaranteesI, clarify)
paulson@13790
   686
apply (blast dest: ok_extend_imp_ok_project extend_Join_eq_extend_D 
paulson@13790
   687
                   guaranteesD)
paulson@13790
   688
done
paulson@13790
   689
wenzelm@46912
   690
lemma extend_guarantees_imp_guarantees:
paulson@13805
   691
     "extend h F \<in> (extend h ` X) guarantees (extend h ` Y)  
paulson@13805
   692
      ==> F \<in> X guarantees Y"
paulson@13790
   693
apply (auto simp add: guar_def)
paulson@13790
   694
apply (drule_tac x = "extend h G" in spec)
paulson@13790
   695
apply (simp del: extend_Join 
paulson@13790
   696
            add: extend_Join [symmetric] ok_extend_iff 
paulson@13790
   697
                 inj_extend [THEN inj_image_mem_iff])
paulson@13790
   698
done
paulson@13790
   699
wenzelm@46912
   700
lemma extend_guarantees_eq:
paulson@13805
   701
     "(extend h F \<in> (extend h ` X) guarantees (extend h ` Y)) =  
paulson@13805
   702
      (F \<in> X guarantees Y)"
wenzelm@46912
   703
  by (blast intro: guarantees_imp_extend_guarantees 
paulson@13790
   704
                 extend_guarantees_imp_guarantees)
paulson@6297
   705
paulson@6297
   706
end
wenzelm@46912
   707
wenzelm@46912
   708
end