src/HOL/UNITY/Extend.thy
author paulson
Wed Jan 29 11:02:08 2003 +0100 (2003-01-29)
changeset 13790 8d7e9fce8c50
parent 10834 a7897aebbffc
child 13798 4c1a53627500
permissions -rw-r--r--
converting UNITY to new-style theories
paulson@6297
     1
(*  Title:      HOL/UNITY/Extend.thy
paulson@6297
     2
    ID:         $Id$
paulson@6297
     3
    Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
paulson@6297
     4
    Copyright   1998  University of Cambridge
paulson@6297
     5
paulson@6297
     6
Extending of state sets
paulson@6297
     7
  function f (forget)    maps the extended state to the original state
paulson@6297
     8
  function g (forgotten) maps the extended state to the "extending part"
paulson@6297
     9
*)
paulson@6297
    10
paulson@13790
    11
theory Extend = Guar:
paulson@6297
    12
paulson@6297
    13
constdefs
paulson@6297
    14
paulson@8948
    15
  (*MOVE to Relation.thy?*)
paulson@8948
    16
  Restrict :: "[ 'a set, ('a*'b) set] => ('a*'b) set"
paulson@8948
    17
    "Restrict A r == r Int (A <*> UNIV)"
paulson@8948
    18
paulson@7482
    19
  good_map :: "['a*'b => 'c] => bool"
paulson@7482
    20
    "good_map h == surj h & (ALL x y. fst (inv h (h (x,y))) = x)"
paulson@7482
    21
     (*Using the locale constant "f", this is  f (h (x,y))) = x*)
paulson@7482
    22
  
paulson@6297
    23
  extend_set :: "['a*'b => 'c, 'a set] => 'c set"
nipkow@10834
    24
    "extend_set h A == h ` (A <*> UNIV)"
paulson@6297
    25
paulson@7342
    26
  project_set :: "['a*'b => 'c, 'c set] => 'a set"
paulson@7342
    27
    "project_set h C == {x. EX y. h(x,y) : C}"
paulson@7342
    28
paulson@7342
    29
  extend_act :: "['a*'b => 'c, ('a*'a) set] => ('c*'c) set"
paulson@7826
    30
    "extend_act h == %act. UN (s,s'): act. UN y. {(h(s,y), h(s',y))}"
paulson@6297
    31
paulson@7878
    32
  project_act :: "['a*'b => 'c, ('c*'c) set] => ('a*'a) set"
paulson@7878
    33
    "project_act h act == {(x,x'). EX y y'. (h(x,y), h(x',y')) : act}"
paulson@7342
    34
paulson@6297
    35
  extend :: "['a*'b => 'c, 'a program] => 'c program"
paulson@6297
    36
    "extend h F == mk_program (extend_set h (Init F),
nipkow@10834
    37
			       extend_act h ` Acts F,
nipkow@10834
    38
			       project_act h -` AllowedActs F)"
paulson@6297
    39
paulson@7878
    40
  (*Argument C allows weak safety laws to be projected*)
paulson@7880
    41
  project :: "['a*'b => 'c, 'c set, 'c program] => 'a program"
paulson@10064
    42
    "project h C F ==
paulson@10064
    43
       mk_program (project_set h (Init F),
nipkow@10834
    44
		   project_act h ` Restrict C ` Acts F,
paulson@10064
    45
		   {act. Restrict (project_set h C) act :
nipkow@10834
    46
		         project_act h ` Restrict C ` AllowedActs F})"
paulson@7342
    47
paulson@6297
    48
locale Extend =
paulson@13790
    49
  fixes f     :: "'c => 'a"
paulson@13790
    50
    and g     :: "'c => 'b"
paulson@13790
    51
    and h     :: "'a*'b => 'c"    (*isomorphism between 'a * 'b and 'c *)
paulson@13790
    52
    and slice :: "['c set, 'b] => 'a set"
paulson@13790
    53
  assumes
paulson@13790
    54
    good_h:  "good_map h"
paulson@13790
    55
  defines f_def: "f z == fst (inv h z)"
paulson@13790
    56
      and g_def: "g z == snd (inv h z)"
paulson@13790
    57
      and slice_def: "slice Z y == {x. h(x,y) : Z}"
paulson@13790
    58
paulson@13790
    59
paulson@13790
    60
(** These we prove OUTSIDE the locale. **)
paulson@13790
    61
paulson@13790
    62
paulson@13790
    63
(*** Restrict [MOVE to Relation.thy?] ***)
paulson@13790
    64
paulson@13790
    65
lemma Restrict_iff [iff]: "((x,y): Restrict A r) = ((x,y): r & x: A)"
paulson@13790
    66
by (unfold Restrict_def, blast)
paulson@13790
    67
paulson@13790
    68
lemma Restrict_UNIV [simp]: "Restrict UNIV = id"
paulson@13790
    69
apply (rule ext)
paulson@13790
    70
apply (auto simp add: Restrict_def)
paulson@13790
    71
done
paulson@13790
    72
paulson@13790
    73
lemma Restrict_empty [simp]: "Restrict {} r = {}"
paulson@13790
    74
by (auto simp add: Restrict_def)
paulson@13790
    75
paulson@13790
    76
lemma Restrict_Int [simp]: "Restrict A (Restrict B r) = Restrict (A Int B) r"
paulson@13790
    77
by (unfold Restrict_def, blast)
paulson@13790
    78
paulson@13790
    79
lemma Restrict_triv: "Domain r <= A ==> Restrict A r = r"
paulson@13790
    80
by (unfold Restrict_def, auto)
paulson@13790
    81
paulson@13790
    82
lemma Restrict_subset: "Restrict A r <= r"
paulson@13790
    83
by (unfold Restrict_def, auto)
paulson@13790
    84
paulson@13790
    85
lemma Restrict_eq_mono: 
paulson@13790
    86
     "[| A <= B;  Restrict B r = Restrict B s |]  
paulson@13790
    87
      ==> Restrict A r = Restrict A s"
paulson@13790
    88
by (unfold Restrict_def, blast)
paulson@13790
    89
paulson@13790
    90
lemma Restrict_imageI: 
paulson@13790
    91
     "[| s : RR;  Restrict A r = Restrict A s |]  
paulson@13790
    92
      ==> Restrict A r : Restrict A ` RR"
paulson@13790
    93
by (unfold Restrict_def image_def, auto)
paulson@13790
    94
paulson@13790
    95
lemma Domain_Restrict [simp]: "Domain (Restrict A r) = A Int Domain r"
paulson@13790
    96
by blast
paulson@13790
    97
paulson@13790
    98
lemma Image_Restrict [simp]: "(Restrict A r) `` B = r `` (A Int B)"
paulson@13790
    99
by blast
paulson@13790
   100
paulson@13790
   101
lemma insert_Id_image_Acts: "f Id = Id ==> insert Id (f`Acts F) = f ` Acts F"
paulson@13790
   102
by (blast intro: sym [THEN image_eqI])
paulson@13790
   103
paulson@13790
   104
(*Possibly easier than reasoning about "inv h"*)
paulson@13790
   105
lemma good_mapI: 
paulson@13790
   106
     assumes surj_h: "surj h"
paulson@13790
   107
	 and prem:   "!! x x' y y'. h(x,y) = h(x',y') ==> x=x'"
paulson@13790
   108
     shows "good_map h"
paulson@13790
   109
apply (simp add: good_map_def) 
paulson@13790
   110
apply (safe intro!: surj_h)
paulson@13790
   111
apply (rule prem)
paulson@13790
   112
apply (subst surjective_pairing [symmetric])
paulson@13790
   113
apply (subst surj_h [THEN surj_f_inv_f])
paulson@13790
   114
apply (rule refl)
paulson@13790
   115
done
paulson@13790
   116
paulson@13790
   117
lemma good_map_is_surj: "good_map h ==> surj h"
paulson@13790
   118
by (unfold good_map_def, auto)
paulson@13790
   119
paulson@13790
   120
(*A convenient way of finding a closed form for inv h*)
paulson@13790
   121
lemma fst_inv_equalityI: 
paulson@13790
   122
     assumes surj_h: "surj h"
paulson@13790
   123
	 and prem:   "!! x y. g (h(x,y)) = x"
paulson@13790
   124
     shows "fst (inv h z) = g z"
paulson@13790
   125
apply (unfold inv_def)
paulson@13790
   126
apply (rule_tac y1 = z in surj_h [THEN surjD, THEN exE])
paulson@13790
   127
apply (rule someI2)
paulson@13790
   128
apply (drule_tac [2] f = g in arg_cong)
paulson@13790
   129
apply (auto simp add: prem)
paulson@13790
   130
done
paulson@13790
   131
paulson@13790
   132
paulson@13790
   133
(*** 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@13790
   166
(*** extend_set: basic properties ***)
paulson@13790
   167
paulson@13790
   168
lemma project_set_iff [iff]:
paulson@13790
   169
     "(x : project_set h C) = (EX y. h(x,y) : C)"
paulson@13790
   170
by (simp add: project_set_def)
paulson@13790
   171
paulson@13790
   172
lemma extend_set_mono: "A<=B ==> extend_set h A <= extend_set h B"
paulson@13790
   173
by (unfold extend_set_def, blast)
paulson@13790
   174
paulson@13790
   175
lemma (in Extend) mem_extend_set_iff [iff]: "z : extend_set h A = (f z : 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@13790
   181
     "(extend_set h A <= extend_set h B) = (A <= 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@13790
   198
     "C <= 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@13790
   213
(*** 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@13790
   220
lemma (in Extend) project_set_I: "!!z. z : C ==> f z : project_set h C"
paulson@13790
   221
by (auto simp add: split_extended_all)
paulson@13790
   222
paulson@13790
   223
paulson@13790
   224
(*** 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@13790
   228
      project_set h (A Int B) = project_set h A Int project_set h B
paulson@13790
   229
*)
paulson@13790
   230
lemma (in Extend) project_set_extend_set_Int:
paulson@13790
   231
     "project_set h ((extend_set h A) Int B) = A Int (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@13790
   236
     "project_set h ((extend_set h A) Un B) = A Un (project_set h B)"
paulson@13790
   237
by auto
paulson@13790
   238
paulson@13790
   239
lemma project_set_Int_subset:
paulson@13790
   240
     "project_set h (A Int B) <= (project_set h A) Int (project_set h B)"
paulson@13790
   241
by auto
paulson@13790
   242
paulson@13790
   243
lemma (in Extend) extend_set_Un_distrib:
paulson@13790
   244
     "extend_set h (A Un B) = extend_set h A Un extend_set h B"
paulson@13790
   245
by auto
paulson@13790
   246
paulson@13790
   247
lemma (in Extend) extend_set_Int_distrib:
paulson@13790
   248
     "extend_set h (A Int B) = extend_set h A Int extend_set h B"
paulson@13790
   249
by auto
paulson@13790
   250
paulson@13790
   251
lemma (in Extend) extend_set_INT_distrib:
paulson@13790
   252
     "extend_set h (INTER A B) = (INT x: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@13790
   260
     "extend_set h (Union A) = (UN X: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@13790
   264
     "(extend_set h A <= - extend_set h B) = (A <= - B)"
paulson@13790
   265
by (unfold extend_set_def, auto)
paulson@13790
   266
paulson@13790
   267
paulson@13790
   268
(*** extend_act ***)
paulson@13790
   269
paulson@13790
   270
(*Can't strengthen it to
paulson@13790
   271
  ((h(s,y), h(s',y')) : extend_act h act) = ((s, s') : 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@13790
   274
     "((h(s,y), h(s',y)) : extend_act h act) = ((s, s') : 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@13790
   279
     "(z, z') : extend_act h act ==> (f z, f z') : 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@13790
   292
     "act' <= extend_act h act ==> project_act h act' <= 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@13790
   305
     "(extend_act h act' <= 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@13790
   322
     "!!z z'. (z, z') : act ==> (f z, f z') : 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@13790
   338
(**** extend ****)
paulson@13790
   339
paulson@13790
   340
(*** 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@13790
   365
               : 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@13790
   386
     "project_set h (Union A) = (UN X: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@13790
   393
     "project_act h (Restrict C act) <=  
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@13790
   405
                          : 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@13790
   432
     "extend h (F Join G) = extend h F Join 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@13790
   439
     "extend h (JOIN I F) = (JN i: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@13790
   447
lemma (in Extend) extend_mono: "F <= G ==> extend h F <= extend h G"
paulson@13790
   448
by (force simp add: component_eq_subset)
paulson@13790
   449
paulson@13790
   450
lemma (in Extend) project_mono: "F <= G ==> project h C F <= project h C G"
paulson@13790
   451
by (simp add: component_eq_subset, blast)
paulson@13790
   452
paulson@13790
   453
paulson@13790
   454
(*** Safety: co, stable ***)
paulson@13790
   455
paulson@13790
   456
lemma (in Extend) extend_constrains:
paulson@13790
   457
     "(extend h F : (extend_set h A) co (extend_set h B)) =  
paulson@13790
   458
      (F : A co B)"
paulson@13790
   459
by (simp add: constrains_def)
paulson@13790
   460
paulson@13790
   461
lemma (in Extend) extend_stable:
paulson@13790
   462
     "(extend h F : stable (extend_set h A)) = (F : stable A)"
paulson@13790
   463
by (simp add: stable_def extend_constrains)
paulson@13790
   464
paulson@13790
   465
lemma (in Extend) extend_invariant:
paulson@13790
   466
     "(extend h F : invariant (extend_set h A)) = (F : invariant A)"
paulson@13790
   467
by (simp add: invariant_def extend_stable)
paulson@13790
   468
paulson@13790
   469
(*Projects the state predicates in the property satisfied by  extend h F.
paulson@13790
   470
  Converse fails: A and B may differ in their extra variables*)
paulson@13790
   471
lemma (in Extend) extend_constrains_project_set:
paulson@13790
   472
     "extend h F : A co B ==> F : (project_set h A) co (project_set h B)"
paulson@13790
   473
by (auto simp add: constrains_def, force)
paulson@13790
   474
paulson@13790
   475
lemma (in Extend) extend_stable_project_set:
paulson@13790
   476
     "extend h F : stable A ==> F : stable (project_set h A)"
paulson@13790
   477
by (simp add: stable_def extend_constrains_project_set)
paulson@13790
   478
paulson@13790
   479
paulson@13790
   480
(*** Weak safety primitives: Co, Stable ***)
paulson@13790
   481
paulson@13790
   482
lemma (in Extend) reachable_extend_f:
paulson@13790
   483
     "p : reachable (extend h F) ==> f p : reachable F"
paulson@13790
   484
apply (erule reachable.induct)
paulson@13790
   485
apply (auto intro: reachable.intros simp add: extend_act_def image_iff)
paulson@13790
   486
done
paulson@13790
   487
paulson@13790
   488
lemma (in Extend) h_reachable_extend:
paulson@13790
   489
     "h(s,y) : reachable (extend h F) ==> s : reachable F"
paulson@13790
   490
by (force dest!: reachable_extend_f)
paulson@13790
   491
paulson@13790
   492
lemma (in Extend) reachable_extend_eq: 
paulson@13790
   493
     "reachable (extend h F) = extend_set h (reachable F)"
paulson@13790
   494
apply (unfold extend_set_def)
paulson@13790
   495
apply (rule equalityI)
paulson@13790
   496
apply (force intro: h_f_g_eq [symmetric] dest!: reachable_extend_f, clarify)
paulson@13790
   497
apply (erule reachable.induct)
paulson@13790
   498
apply (force intro: reachable.intros)+
paulson@13790
   499
done
paulson@13790
   500
paulson@13790
   501
lemma (in Extend) extend_Constrains:
paulson@13790
   502
     "(extend h F : (extend_set h A) Co (extend_set h B)) =   
paulson@13790
   503
      (F : A Co B)"
paulson@13790
   504
by (simp add: Constrains_def reachable_extend_eq extend_constrains 
paulson@13790
   505
              extend_set_Int_distrib [symmetric])
paulson@13790
   506
paulson@13790
   507
lemma (in Extend) extend_Stable:
paulson@13790
   508
     "(extend h F : Stable (extend_set h A)) = (F : Stable A)"
paulson@13790
   509
by (simp add: Stable_def extend_Constrains)
paulson@13790
   510
paulson@13790
   511
lemma (in Extend) extend_Always:
paulson@13790
   512
     "(extend h F : Always (extend_set h A)) = (F : Always A)"
paulson@13790
   513
by (simp (no_asm_simp) add: Always_def extend_Stable)
paulson@13790
   514
paulson@13790
   515
paulson@13790
   516
(** Safety and "project" **)
paulson@13790
   517
paulson@13790
   518
(** projection: monotonicity for safety **)
paulson@13790
   519
paulson@13790
   520
lemma project_act_mono:
paulson@13790
   521
     "D <= C ==>  
paulson@13790
   522
      project_act h (Restrict D act) <= project_act h (Restrict C act)"
paulson@13790
   523
by (auto simp add: project_act_def)
paulson@13790
   524
paulson@13790
   525
lemma (in Extend) project_constrains_mono:
paulson@13790
   526
     "[| D <= C; project h C F : A co B |] ==> project h D F : A co B"
paulson@13790
   527
apply (auto simp add: constrains_def)
paulson@13790
   528
apply (drule project_act_mono, blast)
paulson@13790
   529
done
paulson@13790
   530
paulson@13790
   531
lemma (in Extend) project_stable_mono:
paulson@13790
   532
     "[| D <= C;  project h C F : stable A |] ==> project h D F : stable A"
paulson@13790
   533
by (simp add: stable_def project_constrains_mono)
paulson@13790
   534
paulson@13790
   535
(*Key lemma used in several proofs about project and co*)
paulson@13790
   536
lemma (in Extend) project_constrains: 
paulson@13790
   537
     "(project h C F : A co B)  =   
paulson@13790
   538
      (F : (C Int extend_set h A) co (extend_set h B) & A <= B)"
paulson@13790
   539
apply (unfold constrains_def)
paulson@13790
   540
apply (auto intro!: project_act_I simp add: ball_Un)
paulson@13790
   541
apply (force intro!: project_act_I dest!: subsetD)
paulson@13790
   542
(*the <== direction*)
paulson@13790
   543
apply (unfold project_act_def)
paulson@13790
   544
apply (force dest!: subsetD)
paulson@13790
   545
done
paulson@13790
   546
paulson@13790
   547
lemma (in Extend) project_stable: 
paulson@13790
   548
     "(project h UNIV F : stable A) = (F : stable (extend_set h A))"
paulson@13790
   549
apply (unfold stable_def)
paulson@13790
   550
apply (simp (no_asm) add: project_constrains)
paulson@13790
   551
done
paulson@13790
   552
paulson@13790
   553
lemma (in Extend) project_stable_I:
paulson@13790
   554
     "F : stable (extend_set h A) ==> project h C F : stable A"
paulson@13790
   555
apply (drule project_stable [THEN iffD2])
paulson@13790
   556
apply (blast intro: project_stable_mono)
paulson@13790
   557
done
paulson@13790
   558
paulson@13790
   559
lemma (in Extend) Int_extend_set_lemma:
paulson@13790
   560
     "A Int extend_set h ((project_set h A) Int B) = A Int extend_set h B"
paulson@13790
   561
by (auto simp add: split_extended_all)
paulson@13790
   562
paulson@13790
   563
(*Strange (look at occurrences of C) but used in leadsETo proofs*)
paulson@13790
   564
lemma project_constrains_project_set:
paulson@13790
   565
     "G : C co B ==> project h C G : project_set h C co project_set h B"
paulson@13790
   566
by (simp add: constrains_def project_def project_act_def, blast)
paulson@13790
   567
paulson@13790
   568
lemma project_stable_project_set:
paulson@13790
   569
     "G : stable C ==> project h C G : stable (project_set h C)"
paulson@13790
   570
by (simp add: stable_def project_constrains_project_set)
paulson@13790
   571
paulson@13790
   572
paulson@13790
   573
(*** Progress: transient, ensures ***)
paulson@13790
   574
paulson@13790
   575
lemma (in Extend) extend_transient:
paulson@13790
   576
     "(extend h F : transient (extend_set h A)) = (F : transient A)"
paulson@13790
   577
by (auto simp add: transient_def extend_set_subset_Compl_eq Domain_extend_act)
paulson@13790
   578
paulson@13790
   579
lemma (in Extend) extend_ensures:
paulson@13790
   580
     "(extend h F : (extend_set h A) ensures (extend_set h B)) =  
paulson@13790
   581
      (F : A ensures B)"
paulson@13790
   582
by (simp add: ensures_def extend_constrains extend_transient 
paulson@13790
   583
        extend_set_Un_distrib [symmetric] extend_set_Diff_distrib [symmetric])
paulson@13790
   584
paulson@13790
   585
lemma (in Extend) leadsTo_imp_extend_leadsTo:
paulson@13790
   586
     "F : A leadsTo B  
paulson@13790
   587
      ==> extend h F : (extend_set h A) leadsTo (extend_set h B)"
paulson@13790
   588
apply (erule leadsTo_induct)
paulson@13790
   589
  apply (simp add: leadsTo_Basis extend_ensures)
paulson@13790
   590
 apply (blast intro: leadsTo_Trans)
paulson@13790
   591
apply (simp add: leadsTo_UN extend_set_Union)
paulson@13790
   592
done
paulson@13790
   593
paulson@13790
   594
(*** Proving the converse takes some doing! ***)
paulson@13790
   595
paulson@13790
   596
lemma (in Extend) slice_iff [iff]: "(x : slice C y) = (h(x,y) : C)"
paulson@13790
   597
by (simp (no_asm) add: slice_def)
paulson@13790
   598
paulson@13790
   599
lemma (in Extend) slice_Union: "slice (Union S) y = (UN x:S. slice x y)"
paulson@13790
   600
by auto
paulson@13790
   601
paulson@13790
   602
lemma (in Extend) slice_extend_set: "slice (extend_set h A) y = A"
paulson@13790
   603
by auto
paulson@13790
   604
paulson@13790
   605
lemma (in Extend) project_set_is_UN_slice:
paulson@13790
   606
     "project_set h A = (UN y. slice A y)"
paulson@13790
   607
by auto
paulson@13790
   608
paulson@13790
   609
lemma (in Extend) extend_transient_slice:
paulson@13790
   610
     "extend h F : transient A ==> F : transient (slice A y)"
paulson@13790
   611
apply (unfold transient_def, auto)
paulson@13790
   612
apply (rule bexI, auto)
paulson@13790
   613
apply (force simp add: extend_act_def)
paulson@13790
   614
done
paulson@13790
   615
paulson@13790
   616
(*Converse?*)
paulson@13790
   617
lemma (in Extend) extend_constrains_slice:
paulson@13790
   618
     "extend h F : A co B ==> F : (slice A y) co (slice B y)"
paulson@13790
   619
by (auto simp add: constrains_def)
paulson@13790
   620
paulson@13790
   621
lemma (in Extend) extend_ensures_slice:
paulson@13790
   622
     "extend h F : A ensures B ==> F : (slice A y) ensures (project_set h B)"
paulson@13790
   623
apply (auto simp add: ensures_def extend_constrains extend_transient)
paulson@13790
   624
apply (erule_tac [2] extend_transient_slice [THEN transient_strengthen])
paulson@13790
   625
apply (erule extend_constrains_slice [THEN constrains_weaken], auto)
paulson@13790
   626
done
paulson@13790
   627
paulson@13790
   628
lemma (in Extend) leadsTo_slice_project_set:
paulson@13790
   629
     "ALL y. F : (slice B y) leadsTo CU ==> F : (project_set h B) leadsTo CU"
paulson@13790
   630
apply (simp (no_asm) add: project_set_is_UN_slice)
paulson@13790
   631
apply (blast intro: leadsTo_UN)
paulson@13790
   632
done
paulson@13790
   633
paulson@13790
   634
lemma (in Extend) extend_leadsTo_slice [rule_format (no_asm)]:
paulson@13790
   635
     "extend h F : AU leadsTo BU  
paulson@13790
   636
      ==> ALL y. F : (slice AU y) leadsTo (project_set h BU)"
paulson@13790
   637
apply (erule leadsTo_induct)
paulson@13790
   638
  apply (blast intro: extend_ensures_slice leadsTo_Basis)
paulson@13790
   639
 apply (blast intro: leadsTo_slice_project_set leadsTo_Trans)
paulson@13790
   640
apply (simp add: leadsTo_UN slice_Union)
paulson@13790
   641
done
paulson@13790
   642
paulson@13790
   643
lemma (in Extend) extend_leadsTo:
paulson@13790
   644
     "(extend h F : (extend_set h A) leadsTo (extend_set h B)) =  
paulson@13790
   645
      (F : A leadsTo B)"
paulson@13790
   646
apply safe
paulson@13790
   647
apply (erule_tac [2] leadsTo_imp_extend_leadsTo)
paulson@13790
   648
apply (drule extend_leadsTo_slice)
paulson@13790
   649
apply (simp add: slice_extend_set)
paulson@13790
   650
done
paulson@13790
   651
paulson@13790
   652
lemma (in Extend) extend_LeadsTo:
paulson@13790
   653
     "(extend h F : (extend_set h A) LeadsTo (extend_set h B)) =   
paulson@13790
   654
      (F : A LeadsTo B)"
paulson@13790
   655
by (simp add: LeadsTo_def reachable_extend_eq extend_leadsTo
paulson@13790
   656
              extend_set_Int_distrib [symmetric])
paulson@13790
   657
paulson@13790
   658
paulson@13790
   659
(*** preserves ***)
paulson@13790
   660
paulson@13790
   661
lemma (in Extend) project_preserves_I:
paulson@13790
   662
     "G : preserves (v o f) ==> project h C G : preserves v"
paulson@13790
   663
by (auto simp add: preserves_def project_stable_I extend_set_eq_Collect)
paulson@13790
   664
paulson@13790
   665
(*to preserve f is to preserve the whole original state*)
paulson@13790
   666
lemma (in Extend) project_preserves_id_I:
paulson@13790
   667
     "G : preserves f ==> project h C G : preserves id"
paulson@13790
   668
by (simp add: project_preserves_I)
paulson@13790
   669
paulson@13790
   670
lemma (in Extend) extend_preserves:
paulson@13790
   671
     "(extend h G : preserves (v o f)) = (G : preserves v)"
paulson@13790
   672
by (auto simp add: preserves_def extend_stable [symmetric] 
paulson@13790
   673
                   extend_set_eq_Collect)
paulson@13790
   674
paulson@13790
   675
lemma (in Extend) inj_extend_preserves: "inj h ==> (extend h G : preserves g)"
paulson@13790
   676
by (auto simp add: preserves_def extend_def extend_act_def stable_def 
paulson@13790
   677
                   constrains_def g_def)
paulson@13790
   678
paulson@13790
   679
paulson@13790
   680
(*** Guarantees ***)
paulson@13790
   681
paulson@13790
   682
lemma (in Extend) project_extend_Join:
paulson@13790
   683
     "project h UNIV ((extend h F) Join G) = F Join (project h UNIV G)"
paulson@13790
   684
apply (rule program_equalityI)
paulson@13790
   685
  apply (simp add: project_set_extend_set_Int)
paulson@13790
   686
 apply (simp add: image_eq_UN UN_Un, auto)
paulson@13790
   687
done
paulson@13790
   688
paulson@13790
   689
lemma (in Extend) extend_Join_eq_extend_D:
paulson@13790
   690
     "(extend h F) Join G = extend h H ==> H = F Join (project h UNIV G)"
paulson@13790
   691
apply (drule_tac f = "project h UNIV" in arg_cong)
paulson@13790
   692
apply (simp add: project_extend_Join)
paulson@13790
   693
done
paulson@13790
   694
paulson@13790
   695
(** Strong precondition and postcondition; only useful when
paulson@13790
   696
    the old and new state sets are in bijection **)
paulson@13790
   697
paulson@13790
   698
paulson@13790
   699
lemma (in Extend) ok_extend_imp_ok_project:
paulson@13790
   700
     "extend h F ok G ==> F ok project h UNIV G"
paulson@13790
   701
apply (auto simp add: ok_def)
paulson@13790
   702
apply (drule subsetD)
paulson@13790
   703
apply (auto intro!: rev_image_eqI)
paulson@13790
   704
done
paulson@13790
   705
paulson@13790
   706
lemma (in Extend) ok_extend_iff: "(extend h F ok extend h G) = (F ok G)"
paulson@13790
   707
apply (simp add: ok_def, safe)
paulson@13790
   708
apply (force+)
paulson@13790
   709
done
paulson@13790
   710
paulson@13790
   711
lemma (in Extend) OK_extend_iff: "OK I (%i. extend h (F i)) = (OK I F)"
paulson@13790
   712
apply (unfold OK_def, safe)
paulson@13790
   713
apply (drule_tac x = i in bspec)
paulson@13790
   714
apply (drule_tac [2] x = j in bspec)
paulson@13790
   715
apply (force+)
paulson@13790
   716
done
paulson@13790
   717
paulson@13790
   718
lemma (in Extend) guarantees_imp_extend_guarantees:
paulson@13790
   719
     "F : X guarantees Y ==>  
paulson@13790
   720
      extend h F : (extend h ` X) guarantees (extend h ` Y)"
paulson@13790
   721
apply (rule guaranteesI, clarify)
paulson@13790
   722
apply (blast dest: ok_extend_imp_ok_project extend_Join_eq_extend_D 
paulson@13790
   723
                   guaranteesD)
paulson@13790
   724
done
paulson@13790
   725
paulson@13790
   726
lemma (in Extend) extend_guarantees_imp_guarantees:
paulson@13790
   727
     "extend h F : (extend h ` X) guarantees (extend h ` Y)  
paulson@13790
   728
      ==> F : X guarantees Y"
paulson@13790
   729
apply (auto simp add: guar_def)
paulson@13790
   730
apply (drule_tac x = "extend h G" in spec)
paulson@13790
   731
apply (simp del: extend_Join 
paulson@13790
   732
            add: extend_Join [symmetric] ok_extend_iff 
paulson@13790
   733
                 inj_extend [THEN inj_image_mem_iff])
paulson@13790
   734
done
paulson@13790
   735
paulson@13790
   736
lemma (in Extend) extend_guarantees_eq:
paulson@13790
   737
     "(extend h F : (extend h ` X) guarantees (extend h ` Y)) =  
paulson@13790
   738
      (F : X guarantees Y)"
paulson@13790
   739
by (blast intro: guarantees_imp_extend_guarantees 
paulson@13790
   740
                 extend_guarantees_imp_guarantees)
paulson@6297
   741
paulson@6297
   742
end