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