src/HOL/UNITY/PPROD.thy
author wenzelm
Mon Mar 16 18:24:30 2009 +0100 (2009-03-16)
changeset 30549 d2d7874648bd
parent 16417 9bc16273c2d4
child 32960 69916a850301
permissions -rw-r--r--
simplified method setup;
paulson@5899
     1
(*  Title:      HOL/UNITY/PPROD.thy
paulson@5899
     2
    ID:         $Id$
paulson@5899
     3
    Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
paulson@5899
     4
    Copyright   1998  University of Cambridge
paulson@5899
     5
paulson@7188
     6
Abstraction over replicated components (PLam)
paulson@7188
     7
General products of programs (Pi operation)
paulson@13786
     8
paulson@13786
     9
Some dead wood here!
paulson@5899
    10
*)
paulson@5899
    11
haftmann@16417
    12
theory PPROD imports Lift_prog begin
paulson@5899
    13
paulson@5899
    14
constdefs
paulson@5899
    15
paulson@8251
    16
  PLam  :: "[nat set, nat => ('b * ((nat=>'b) * 'c)) program]
paulson@8251
    17
            => ((nat=>'b) * 'c) program"
paulson@13805
    18
    "PLam I F == \<Squnion>i \<in> I. lift i (F i)"
paulson@5899
    19
paulson@5899
    20
syntax
paulson@13786
    21
  "@PLam" :: "[pttrn, nat set, 'b set] => (nat => 'b) set"
paulson@13786
    22
              ("(3plam _:_./ _)" 10)
paulson@5899
    23
paulson@5899
    24
translations
paulson@13805
    25
  "plam x : A. B"   == "PLam A (%x. B)"
paulson@5899
    26
paulson@13786
    27
paulson@13786
    28
(*** Basic properties ***)
paulson@13786
    29
paulson@13812
    30
lemma Init_PLam [simp]: "Init (PLam I F) = (\<Inter>i \<in> I. lift_set i (Init (F i)))"
paulson@13812
    31
by (simp add: PLam_def lift_def lift_set_def)
paulson@13786
    32
paulson@13812
    33
lemma PLam_empty [simp]: "PLam {} F = SKIP"
paulson@13812
    34
by (simp add: PLam_def)
paulson@13786
    35
paulson@13812
    36
lemma PLam_SKIP [simp]: "(plam i : I. SKIP) = SKIP"
paulson@13812
    37
by (simp add: PLam_def lift_SKIP JN_constant)
paulson@13786
    38
paulson@13786
    39
lemma PLam_insert: "PLam (insert i I) F = (lift i (F i)) Join (PLam I F)"
paulson@13786
    40
by (unfold PLam_def, auto)
paulson@13786
    41
paulson@13805
    42
lemma PLam_component_iff: "((PLam I F) \<le> H) = (\<forall>i \<in> I. lift i (F i) \<le> H)"
paulson@13812
    43
by (simp add: PLam_def JN_component_iff)
paulson@13786
    44
paulson@13805
    45
lemma component_PLam: "i \<in> I ==> lift i (F i) \<le> (PLam I F)"
paulson@13786
    46
apply (unfold PLam_def)
paulson@13786
    47
(*blast_tac doesn't use HO unification*)
paulson@13786
    48
apply (fast intro: component_JN)
paulson@13786
    49
done
paulson@13786
    50
paulson@13786
    51
paulson@13786
    52
(** Safety & Progress: but are they used anywhere? **)
paulson@13786
    53
paulson@13812
    54
lemma PLam_constrains:
paulson@13812
    55
     "[| i \<in> I;  \<forall>j. F j \<in> preserves snd |]
paulson@13812
    56
      ==> (PLam I F \<in> (lift_set i (A <*> UNIV)) co
paulson@13812
    57
                      (lift_set i (B <*> UNIV)))  =
paulson@13812
    58
          (F i \<in> (A <*> UNIV) co (B <*> UNIV))"
paulson@13812
    59
apply (simp add: PLam_def JN_constrains)
paulson@13786
    60
apply (subst insert_Diff [symmetric], assumption)
paulson@13812
    61
apply (simp add: lift_constrains)
paulson@13786
    62
apply (blast intro: constrains_imp_lift_constrains)
paulson@13786
    63
done
paulson@13786
    64
paulson@13812
    65
lemma PLam_stable:
paulson@13812
    66
     "[| i \<in> I;  \<forall>j. F j \<in> preserves snd |]
paulson@13812
    67
      ==> (PLam I F \<in> stable (lift_set i (A <*> UNIV))) =
paulson@13805
    68
          (F i \<in> stable (A <*> UNIV))"
paulson@13812
    69
by (simp add: stable_def PLam_constrains)
paulson@13812
    70
paulson@13812
    71
lemma PLam_transient:
paulson@13812
    72
     "i \<in> I ==>
paulson@13812
    73
    PLam I F \<in> transient A = (\<exists>i \<in> I. lift i (F i) \<in> transient A)"
paulson@13812
    74
by (simp add: JN_transient PLam_def)
paulson@13786
    75
paulson@13812
    76
text{*This holds because the @{term "F j"} cannot change @{term "lift_set i"}*}
paulson@13812
    77
lemma PLam_ensures:
paulson@13812
    78
     "[| i \<in> I;  F i \<in> (A <*> UNIV) ensures (B <*> UNIV);
paulson@13812
    79
         \<forall>j. F j \<in> preserves snd |]
paulson@13812
    80
      ==> PLam I F \<in> lift_set i (A <*> UNIV) ensures lift_set i (B <*> UNIV)"
paulson@13812
    81
apply (simp add: ensures_def PLam_constrains PLam_transient
paulson@13812
    82
              lift_set_Un_distrib [symmetric] lift_set_Diff_distrib [symmetric]
paulson@13812
    83
              Times_Un_distrib1 [symmetric] Times_Diff_distrib1 [symmetric])
paulson@13812
    84
apply (rule rev_bexI, assumption)
paulson@13812
    85
apply (simp add: lift_transient)
paulson@13786
    86
done
paulson@13786
    87
paulson@13812
    88
lemma PLam_leadsTo_Basis:
paulson@13812
    89
     "[| i \<in> I;
paulson@13812
    90
         F i \<in> ((A <*> UNIV) - (B <*> UNIV)) co
paulson@13812
    91
               ((A <*> UNIV) \<union> (B <*> UNIV));
paulson@13812
    92
         F i \<in> transient ((A <*> UNIV) - (B <*> UNIV));
paulson@13812
    93
         \<forall>j. F j \<in> preserves snd |]
paulson@13812
    94
      ==> PLam I F \<in> lift_set i (A <*> UNIV) leadsTo lift_set i (B <*> UNIV)"
paulson@13786
    95
by (rule PLam_ensures [THEN leadsTo_Basis], rule_tac [2] ensuresI)
paulson@13786
    96
paulson@13786
    97
paulson@13786
    98
paulson@13786
    99
(** invariant **)
paulson@13786
   100
paulson@13812
   101
lemma invariant_imp_PLam_invariant:
paulson@13812
   102
     "[| F i \<in> invariant (A <*> UNIV);  i \<in> I;
paulson@13812
   103
         \<forall>j. F j \<in> preserves snd |]
paulson@13805
   104
      ==> PLam I F \<in> invariant (lift_set i (A <*> UNIV))"
paulson@13786
   105
by (auto simp add: PLam_stable invariant_def)
paulson@13786
   106
paulson@13786
   107
paulson@13786
   108
lemma PLam_preserves_fst [simp]:
paulson@13812
   109
     "\<forall>j. F j \<in> preserves snd
paulson@13812
   110
      ==> (PLam I F \<in> preserves (v o sub j o fst)) =
paulson@13805
   111
          (if j \<in> I then F j \<in> preserves (v o fst) else True)"
paulson@13812
   112
by (simp add: PLam_def lift_preserves_sub)
paulson@13786
   113
paulson@13786
   114
lemma PLam_preserves_snd [simp,intro]:
paulson@13805
   115
     "\<forall>j. F j \<in> preserves snd ==> PLam I F \<in> preserves snd"
paulson@13812
   116
by (simp add: PLam_def lift_preserves_snd_I)
paulson@13786
   117
paulson@13786
   118
paulson@13786
   119
paulson@13786
   120
(*** guarantees properties ***)
paulson@13786
   121
paulson@14150
   122
text{*This rule looks unsatisfactory because it refers to @{term lift}. 
paulson@14150
   123
  One must use
paulson@14150
   124
  @{text lift_guarantees_eq_lift_inv} to rewrite the first subgoal and
paulson@14150
   125
  something like @{text lift_preserves_sub} to rewrite the third.  However
paulson@14150
   126
  there's no obvious alternative for the third premise.*}
paulson@13812
   127
lemma guarantees_PLam_I:
paulson@13812
   128
    "[| lift i (F i): X guarantees Y;  i \<in> I;
paulson@13812
   129
        OK I (%i. lift i (F i)) |]
paulson@13805
   130
     ==> (PLam I F) \<in> X guarantees Y"
paulson@13786
   131
apply (unfold PLam_def)
paulson@13812
   132
apply (simp add: guarantees_JN_I)
paulson@13786
   133
done
paulson@13786
   134
paulson@13786
   135
lemma Allowed_PLam [simp]:
paulson@13805
   136
     "Allowed (PLam I F) = (\<Inter>i \<in> I. lift i ` Allowed(F i))"
paulson@13812
   137
by (simp add: PLam_def)
paulson@13786
   138
paulson@13786
   139
paulson@13786
   140
lemma PLam_preserves [simp]:
paulson@13805
   141
     "(PLam I F) \<in> preserves v = (\<forall>i \<in> I. F i \<in> preserves (v o lift_map i))"
paulson@13805
   142
by (simp add: PLam_def lift_def rename_preserves)
paulson@13786
   143
paulson@13786
   144
paulson@13786
   145
(**UNUSED
paulson@13786
   146
    (*The f0 premise ensures that the product is well-defined.*)
paulson@13812
   147
    lemma PLam_invariant_imp_invariant:
paulson@13812
   148
     "[| PLam I F \<in> invariant (lift_set i A);  i \<in> I;
paulson@13805
   149
             f0: Init (PLam I F) |] ==> F i \<in> invariant A"
paulson@13786
   150
    apply (auto simp add: invariant_def)
paulson@13786
   151
    apply (drule_tac c = "f0 (i:=x) " in subsetD)
paulson@13786
   152
    apply auto
paulson@13786
   153
    done
paulson@13786
   154
paulson@13812
   155
    lemma PLam_invariant:
paulson@13812
   156
     "[| i \<in> I;  f0: Init (PLam I F) |]
paulson@13805
   157
          ==> (PLam I F \<in> invariant (lift_set i A)) = (F i \<in> invariant A)"
paulson@13786
   158
    apply (blast intro: invariant_imp_PLam_invariant PLam_invariant_imp_invariant)
paulson@13786
   159
    done
paulson@13786
   160
paulson@13786
   161
    (*The f0 premise isn't needed if F is a constant program because then
paulson@13786
   162
      we get an initial state by replicating that of F*)
paulson@13812
   163
    lemma reachable_PLam:
paulson@13812
   164
     "i \<in> I
paulson@13805
   165
          ==> ((plam x \<in> I. F) \<in> invariant (lift_set i A)) = (F \<in> invariant A)"
paulson@13786
   166
    apply (auto simp add: invariant_def)
paulson@13786
   167
    done
paulson@13786
   168
**)
paulson@13786
   169
paulson@13786
   170
paulson@13786
   171
(**UNUSED
paulson@13786
   172
    (** Reachability **)
paulson@13786
   173
paulson@13805
   174
    Goal "[| f \<in> reachable (PLam I F);  i \<in> I |] ==> f i \<in> reachable (F i)"
paulson@13786
   175
    apply (erule reachable.induct)
paulson@13786
   176
    apply (auto intro: reachable.intrs)
paulson@13786
   177
    done
paulson@13786
   178
paulson@13786
   179
    (*Result to justify a re-organization of this file*)
paulson@13805
   180
    lemma "{f. \<forall>i \<in> I. f i \<in> R i} = (\<Inter>i \<in> I. lift_set i (R i))"
paulson@13798
   181
    by auto
paulson@13786
   182
paulson@13812
   183
    lemma reachable_PLam_subset1:
paulson@13805
   184
     "reachable (PLam I F) \<subseteq> (\<Inter>i \<in> I. lift_set i (reachable (F i)))"
paulson@13786
   185
    apply (force dest!: reachable_PLam)
paulson@13786
   186
    done
paulson@13786
   187
paulson@13786
   188
    (*simplify using reachable_lift??*)
paulson@13798
   189
    lemma reachable_lift_Join_PLam [rule_format]:
paulson@13812
   190
      "[| i \<notin> I;  A \<in> reachable (F i) |]
paulson@13812
   191
       ==> \<forall>f. f \<in> reachable (PLam I F)
paulson@13805
   192
                  --> f(i:=A) \<in> reachable (lift i (F i) Join PLam I F)"
paulson@13786
   193
    apply (erule reachable.induct)
paulson@13786
   194
    apply (ALLGOALS Clarify_tac)
paulson@13786
   195
    apply (erule reachable.induct)
paulson@13786
   196
    (*Init, Init case*)
paulson@13786
   197
    apply (force intro: reachable.intrs)
paulson@13786
   198
    (*Init of F, action of PLam F case*)
paulson@13786
   199
    apply (rule_tac act = act in reachable.Acts)
paulson@13786
   200
    apply force
paulson@13786
   201
    apply assumption
paulson@13786
   202
    apply (force intro: ext)
paulson@13786
   203
    (*induction over the 2nd "reachable" assumption*)
paulson@13786
   204
    apply (erule_tac xa = f in reachable.induct)
paulson@13786
   205
    (*Init of PLam F, action of F case*)
paulson@13786
   206
    apply (rule_tac act = "lift_act i act" in reachable.Acts)
paulson@13786
   207
    apply force
paulson@13786
   208
    apply (force intro: reachable.Init)
paulson@13786
   209
    apply (force intro: ext simp add: lift_act_def)
paulson@13786
   210
    (*last case: an action of PLam I F*)
paulson@13786
   211
    apply (rule_tac act = acta in reachable.Acts)
paulson@13786
   212
    apply force
paulson@13786
   213
    apply assumption
paulson@13786
   214
    apply (force intro: ext)
paulson@13786
   215
    done
paulson@13786
   216
paulson@13786
   217
paulson@13786
   218
    (*The index set must be finite: otherwise infinitely many copies of F can
paulson@13786
   219
      perform actions, and PLam can never catch up in finite time.*)
paulson@13812
   220
    lemma reachable_PLam_subset2:
paulson@13812
   221
     "finite I
paulson@13805
   222
          ==> (\<Inter>i \<in> I. lift_set i (reachable (F i))) \<subseteq> reachable (PLam I F)"
paulson@13786
   223
    apply (erule finite_induct)
paulson@13786
   224
    apply (simp (no_asm))
paulson@13786
   225
    apply (force dest: reachable_lift_Join_PLam simp add: PLam_insert)
paulson@13786
   226
    done
paulson@13786
   227
paulson@13812
   228
    lemma reachable_PLam_eq:
paulson@13812
   229
     "finite I ==>
paulson@13805
   230
          reachable (PLam I F) = (\<Inter>i \<in> I. lift_set i (reachable (F i)))"
paulson@13786
   231
    apply (REPEAT_FIRST (ares_tac [equalityI, reachable_PLam_subset1, reachable_PLam_subset2]))
paulson@13786
   232
    done
paulson@13786
   233
paulson@13786
   234
paulson@13786
   235
    (** Co **)
paulson@13786
   236
paulson@13812
   237
    lemma Constrains_imp_PLam_Constrains:
paulson@13812
   238
     "[| F i \<in> A Co B;  i \<in> I;  finite I |]
paulson@13805
   239
          ==> PLam I F \<in> (lift_set i A) Co (lift_set i B)"
paulson@13786
   240
    apply (auto simp add: Constrains_def Collect_conj_eq [symmetric] reachable_PLam_eq)
paulson@13786
   241
    apply (auto simp add: constrains_def PLam_def)
paulson@13786
   242
    apply (REPEAT (blast intro: reachable.intrs))
paulson@13786
   243
    done
paulson@13786
   244
paulson@13786
   245
paulson@13786
   246
paulson@13812
   247
    lemma PLam_Constrains:
paulson@13812
   248
     "[| i \<in> I;  finite I;  f0: Init (PLam I F) |]
paulson@13812
   249
          ==> (PLam I F \<in> (lift_set i A) Co (lift_set i B)) =
paulson@13805
   250
              (F i \<in> A Co B)"
paulson@13786
   251
    apply (blast intro: Constrains_imp_PLam_Constrains PLam_Constrains_imp_Constrains)
paulson@13786
   252
    done
paulson@13786
   253
paulson@13812
   254
    lemma PLam_Stable:
paulson@13812
   255
     "[| i \<in> I;  finite I;  f0: Init (PLam I F) |]
paulson@13805
   256
          ==> (PLam I F \<in> Stable (lift_set i A)) = (F i \<in> Stable A)"
paulson@13812
   257
    apply (simp del: Init_PLam add: Stable_def PLam_Constrains)
paulson@13786
   258
    done
paulson@13786
   259
paulson@13786
   260
paulson@13786
   261
    (** const_PLam (no dependence on i) doesn't require the f0 premise **)
paulson@13786
   262
paulson@13812
   263
    lemma const_PLam_Constrains:
paulson@13812
   264
     "[| i \<in> I;  finite I |]
paulson@13812
   265
          ==> ((plam x \<in> I. F) \<in> (lift_set i A) Co (lift_set i B)) =
paulson@13805
   266
              (F \<in> A Co B)"
paulson@13786
   267
    apply (blast intro: Constrains_imp_PLam_Constrains const_PLam_Constrains_imp_Constrains)
paulson@13786
   268
    done
paulson@13786
   269
paulson@13812
   270
    lemma const_PLam_Stable:
paulson@13812
   271
     "[| i \<in> I;  finite I |]
paulson@13805
   272
          ==> ((plam x \<in> I. F) \<in> Stable (lift_set i A)) = (F \<in> Stable A)"
paulson@13812
   273
    apply (simp add: Stable_def const_PLam_Constrains)
paulson@13786
   274
    done
paulson@13786
   275
paulson@13812
   276
    lemma const_PLam_Increasing:
paulson@13812
   277
	 "[| i \<in> I;  finite I |]
paulson@13805
   278
          ==> ((plam x \<in> I. F) \<in> Increasing (f o sub i)) = (F \<in> Increasing f)"
paulson@13786
   279
    apply (unfold Increasing_def)
paulson@13805
   280
    apply (subgoal_tac "\<forall>z. {s. z \<subseteq> (f o sub i) s} = lift_set i {s. z \<subseteq> f s}")
paulson@13786
   281
    apply (asm_simp_tac (simpset () add: lift_set_sub) 2)
paulson@13786
   282
    apply (simp add: finite_lessThan const_PLam_Stable)
paulson@13786
   283
    done
paulson@13786
   284
**)
paulson@13786
   285
paulson@13786
   286
paulson@5899
   287
end