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