src/HOL/UNITY/WFair.thy
author paulson
Fri Aug 15 13:07:01 2003 +0200 (2003-08-15)
changeset 14150 9a23e4eb5eb3
parent 14112 95d51043d2a3
child 15045 d59f7e2e18d3
permissions -rw-r--r--
A document for UNITY
paulson@4776
     1
(*  Title:      HOL/UNITY/WFair
paulson@4776
     2
    ID:         $Id$
paulson@4776
     3
    Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
paulson@4776
     4
    Copyright   1998  University of Cambridge
paulson@4776
     5
paulson@13812
     6
Conditional Fairness versions of transient, ensures, leadsTo.
paulson@4776
     7
paulson@4776
     8
From Misra, "A Logic for Concurrent Programming", 1994
paulson@4776
     9
*)
paulson@4776
    10
paulson@13812
    11
header{*Progress*}
paulson@13798
    12
paulson@13797
    13
theory WFair = UNITY:
paulson@4776
    14
paulson@13812
    15
text{*The original version of this theory was based on weak fairness.  (Thus,
paulson@13812
    16
the entire UNITY development embodied this assumption, until February 2003.)
paulson@13812
    17
Weak fairness states that if a command is enabled continuously, then it is
paulson@13812
    18
eventually executed.  Ernie Cohen suggested that I instead adopt unconditional
paulson@13812
    19
fairness: every command is executed infinitely often.  
paulson@13812
    20
paulson@13812
    21
In fact, Misra's paper on "Progress" seems to be ambiguous about the correct
paulson@13812
    22
interpretation, and says that the two forms of fairness are equivalent.  They
paulson@13812
    23
differ only on their treatment of partial transitions, which under
paulson@13812
    24
unconditional fairness behave magically.  That is because if there are partial
paulson@13812
    25
transitions then there may be no fair executions, making all leads-to
paulson@13812
    26
properties hold vacuously.
paulson@13812
    27
paulson@13812
    28
Unconditional fairness has some great advantages.  By distinguishing partial
paulson@13812
    29
transitions from total ones that are the identity on part of their domain, it
paulson@13812
    30
is more expressive.  Also, by simplifying the definition of the transient
paulson@13812
    31
property, it simplifies many proofs.  A drawback is that some laws only hold
paulson@13812
    32
under the assumption that all transitions are total.  The best-known of these
paulson@13812
    33
is the impossibility law for leads-to.
paulson@13812
    34
*}
paulson@13812
    35
paulson@4776
    36
constdefs
paulson@4776
    37
paulson@13812
    38
  --{*This definition specifies conditional fairness.  The rest of the theory
paulson@13812
    39
      is generic to all forms of fairness.  To get weak fairness, conjoin
paulson@13812
    40
      the inclusion below with @{term "A \<subseteq> Domain act"}, which specifies 
paulson@13812
    41
      that the action is enabled over all of @{term A}.*}
paulson@5648
    42
  transient :: "'a set => 'a program set"
paulson@13812
    43
    "transient A == {F. \<exists>act\<in>Acts F. act``A \<subseteq> -A}"
paulson@4776
    44
paulson@13797
    45
  ensures :: "['a set, 'a set] => 'a program set"       (infixl "ensures" 60)
paulson@13805
    46
    "A ensures B == (A-B co A \<union> B) \<inter> transient (A-B)"
paulson@8006
    47
paulson@6536
    48
paulson@6536
    49
consts
paulson@6536
    50
paulson@6801
    51
  leads :: "'a program => ('a set * 'a set) set"
paulson@13812
    52
    --{*LEADS-TO constant for the inductive definition*}
paulson@5648
    53
paulson@6801
    54
paulson@6801
    55
inductive "leads F"
paulson@13797
    56
  intros 
paulson@4776
    57
paulson@13805
    58
    Basis:  "F \<in> A ensures B ==> (A,B) \<in> leads F"
paulson@4776
    59
paulson@13805
    60
    Trans:  "[| (A,B) \<in> leads F;  (B,C) \<in> leads F |] ==> (A,C) \<in> leads F"
paulson@4776
    61
paulson@13805
    62
    Union:  "\<forall>A \<in> S. (A,B) \<in> leads F ==> (Union S, B) \<in> leads F"
paulson@4776
    63
paulson@5155
    64
paulson@8006
    65
constdefs
paulson@6536
    66
paulson@13797
    67
  leadsTo :: "['a set, 'a set] => 'a program set"    (infixl "leadsTo" 60)
paulson@13812
    68
     --{*visible version of the LEADS-TO relation*}
paulson@13805
    69
    "A leadsTo B == {F. (A,B) \<in> leads F}"
paulson@5648
    70
  
paulson@5648
    71
  wlt :: "['a program, 'a set] => 'a set"
paulson@13812
    72
     --{*predicate transformer: the largest set that leads to @{term B}*}
paulson@13805
    73
    "wlt F B == Union {A. F \<in> A leadsTo B}"
paulson@4776
    74
paulson@9685
    75
syntax (xsymbols)
paulson@13797
    76
  "op leadsTo" :: "['a set, 'a set] => 'a program set" (infixl "\<longmapsto>" 60)
paulson@13797
    77
paulson@13797
    78
paulson@13798
    79
subsection{*transient*}
paulson@13797
    80
paulson@13812
    81
lemma stable_transient: 
paulson@13812
    82
    "[| F \<in> stable A; F \<in> transient A |] ==> \<exists>act\<in>Acts F. A \<subseteq> - (Domain act)"
paulson@13812
    83
apply (simp add: stable_def constrains_def transient_def, clarify)
paulson@13812
    84
apply (rule rev_bexI, auto)  
paulson@13812
    85
done
paulson@13812
    86
paulson@13797
    87
lemma stable_transient_empty: 
paulson@13812
    88
    "[| F \<in> stable A; F \<in> transient A; all_total F |] ==> A = {}"
paulson@13812
    89
apply (drule stable_transient, assumption)
paulson@13812
    90
apply (simp add: all_total_def)
paulson@13812
    91
done
paulson@13797
    92
paulson@13797
    93
lemma transient_strengthen: 
paulson@13805
    94
    "[| F \<in> transient A; B \<subseteq> A |] ==> F \<in> transient B"
paulson@13797
    95
apply (unfold transient_def, clarify)
paulson@13797
    96
apply (blast intro!: rev_bexI)
paulson@13797
    97
done
paulson@13797
    98
paulson@13797
    99
lemma transientI: 
paulson@13812
   100
    "[| act: Acts F;  act``A \<subseteq> -A |] ==> F \<in> transient A"
paulson@13797
   101
by (unfold transient_def, blast)
paulson@13797
   102
paulson@13797
   103
lemma transientE: 
paulson@13805
   104
    "[| F \<in> transient A;   
paulson@13812
   105
        !!act. [| act: Acts F;  act``A \<subseteq> -A |] ==> P |]  
paulson@13797
   106
     ==> P"
paulson@13797
   107
by (unfold transient_def, blast)
paulson@13797
   108
paulson@13797
   109
lemma transient_empty [simp]: "transient {} = UNIV"
paulson@13797
   110
by (unfold transient_def, auto)
paulson@13797
   111
paulson@13797
   112
paulson@13812
   113
text{*This equation recovers the notion of weak fairness.  A totalized
paulson@13812
   114
      program satisfies a transient assertion just if the original program
paulson@13812
   115
      contains a suitable action that is also enabled.*}
paulson@13812
   116
lemma totalize_transient_iff:
paulson@13812
   117
   "(totalize F \<in> transient A) = (\<exists>act\<in>Acts F. A \<subseteq> Domain act & act``A \<subseteq> -A)"
paulson@13812
   118
apply (simp add: totalize_def totalize_act_def transient_def 
paulson@13812
   119
                 Un_Image Un_subset_iff, safe)
paulson@13812
   120
apply (blast intro!: rev_bexI)+
paulson@13812
   121
done
paulson@13812
   122
paulson@13812
   123
lemma totalize_transientI: 
paulson@13812
   124
    "[| act: Acts F;  A \<subseteq> Domain act;  act``A \<subseteq> -A |] 
paulson@13812
   125
     ==> totalize F \<in> transient A"
paulson@13812
   126
by (simp add: totalize_transient_iff, blast)
paulson@13812
   127
paulson@13798
   128
subsection{*ensures*}
paulson@13797
   129
paulson@13797
   130
lemma ensuresI: 
paulson@13805
   131
    "[| F \<in> (A-B) co (A \<union> B); F \<in> transient (A-B) |] ==> F \<in> A ensures B"
paulson@13797
   132
by (unfold ensures_def, blast)
paulson@13797
   133
paulson@13797
   134
lemma ensuresD: 
paulson@13805
   135
    "F \<in> A ensures B ==> F \<in> (A-B) co (A \<union> B) & F \<in> transient (A-B)"
paulson@13797
   136
by (unfold ensures_def, blast)
paulson@13797
   137
paulson@13797
   138
lemma ensures_weaken_R: 
paulson@13805
   139
    "[| F \<in> A ensures A'; A'<=B' |] ==> F \<in> A ensures B'"
paulson@13797
   140
apply (unfold ensures_def)
paulson@13797
   141
apply (blast intro: constrains_weaken transient_strengthen)
paulson@13797
   142
done
paulson@13797
   143
paulson@13812
   144
text{*The L-version (precondition strengthening) fails, but we have this*}
paulson@13797
   145
lemma stable_ensures_Int: 
paulson@13805
   146
    "[| F \<in> stable C;  F \<in> A ensures B |]    
paulson@13805
   147
    ==> F \<in> (C \<inter> A) ensures (C \<inter> B)"
paulson@13797
   148
apply (unfold ensures_def)
paulson@13797
   149
apply (auto simp add: ensures_def Int_Un_distrib [symmetric] Diff_Int_distrib [symmetric])
paulson@13797
   150
prefer 2 apply (blast intro: transient_strengthen)
paulson@13797
   151
apply (blast intro: stable_constrains_Int constrains_weaken)
paulson@13797
   152
done
paulson@13797
   153
paulson@13797
   154
lemma stable_transient_ensures:
paulson@13805
   155
     "[| F \<in> stable A;  F \<in> transient C;  A \<subseteq> B \<union> C |] ==> F \<in> A ensures B"
paulson@13797
   156
apply (simp add: ensures_def stable_def)
paulson@13797
   157
apply (blast intro: constrains_weaken transient_strengthen)
paulson@13797
   158
done
paulson@13797
   159
paulson@13805
   160
lemma ensures_eq: "(A ensures B) = (A unless B) \<inter> transient (A-B)"
paulson@13797
   161
by (simp (no_asm) add: ensures_def unless_def)
paulson@13797
   162
paulson@13797
   163
paulson@13798
   164
subsection{*leadsTo*}
paulson@13797
   165
paulson@13805
   166
lemma leadsTo_Basis [intro]: "F \<in> A ensures B ==> F \<in> A leadsTo B"
paulson@13797
   167
apply (unfold leadsTo_def)
paulson@13797
   168
apply (blast intro: leads.Basis)
paulson@13797
   169
done
paulson@13797
   170
paulson@13797
   171
lemma leadsTo_Trans: 
paulson@13805
   172
     "[| F \<in> A leadsTo B;  F \<in> B leadsTo C |] ==> F \<in> A leadsTo C"
paulson@13797
   173
apply (unfold leadsTo_def)
paulson@13797
   174
apply (blast intro: leads.Trans)
paulson@13797
   175
done
paulson@13797
   176
paulson@14112
   177
lemma leadsTo_Basis':
paulson@14112
   178
     "[| F \<in> A co A \<union> B; F \<in> transient A |] ==> F \<in> A leadsTo B"
paulson@14112
   179
apply (drule_tac B = "A-B" in constrains_weaken_L)
paulson@14112
   180
apply (drule_tac [2] B = "A-B" in transient_strengthen)
paulson@14112
   181
apply (rule_tac [3] ensuresI [THEN leadsTo_Basis])
paulson@14112
   182
apply (blast+)
paulson@14112
   183
done
paulson@14112
   184
paulson@13805
   185
lemma transient_imp_leadsTo: "F \<in> transient A ==> F \<in> A leadsTo (-A)"
paulson@13797
   186
by (simp (no_asm_simp) add: leadsTo_Basis ensuresI Compl_partition)
paulson@13797
   187
paulson@13812
   188
text{*Useful with cancellation, disjunction*}
paulson@13805
   189
lemma leadsTo_Un_duplicate: "F \<in> A leadsTo (A' \<union> A') ==> F \<in> A leadsTo A'"
paulson@13797
   190
by (simp add: Un_ac)
paulson@13797
   191
paulson@13797
   192
lemma leadsTo_Un_duplicate2:
paulson@13805
   193
     "F \<in> A leadsTo (A' \<union> C \<union> C) ==> F \<in> A leadsTo (A' \<union> C)"
paulson@13797
   194
by (simp add: Un_ac)
paulson@13797
   195
paulson@13812
   196
text{*The Union introduction rule as we should have liked to state it*}
paulson@13797
   197
lemma leadsTo_Union: 
paulson@13805
   198
    "(!!A. A \<in> S ==> F \<in> A leadsTo B) ==> F \<in> (Union S) leadsTo B"
paulson@13797
   199
apply (unfold leadsTo_def)
paulson@13797
   200
apply (blast intro: leads.Union)
paulson@13797
   201
done
paulson@13797
   202
paulson@13797
   203
lemma leadsTo_Union_Int: 
paulson@13805
   204
 "(!!A. A \<in> S ==> F \<in> (A \<inter> C) leadsTo B) ==> F \<in> (Union S \<inter> C) leadsTo B"
paulson@13797
   205
apply (unfold leadsTo_def)
paulson@13797
   206
apply (simp only: Int_Union_Union)
paulson@13797
   207
apply (blast intro: leads.Union)
paulson@13797
   208
done
paulson@13797
   209
paulson@13797
   210
lemma leadsTo_UN: 
paulson@13805
   211
    "(!!i. i \<in> I ==> F \<in> (A i) leadsTo B) ==> F \<in> (\<Union>i \<in> I. A i) leadsTo B"
paulson@13797
   212
apply (subst Union_image_eq [symmetric])
paulson@13797
   213
apply (blast intro: leadsTo_Union)
paulson@13797
   214
done
paulson@13797
   215
paulson@13812
   216
text{*Binary union introduction rule*}
paulson@13797
   217
lemma leadsTo_Un:
paulson@13805
   218
     "[| F \<in> A leadsTo C; F \<in> B leadsTo C |] ==> F \<in> (A \<union> B) leadsTo C"
paulson@13797
   219
apply (subst Un_eq_Union)
paulson@13797
   220
apply (blast intro: leadsTo_Union)
paulson@13797
   221
done
paulson@13797
   222
paulson@13797
   223
lemma single_leadsTo_I: 
paulson@13805
   224
     "(!!x. x \<in> A ==> F \<in> {x} leadsTo B) ==> F \<in> A leadsTo B"
paulson@13797
   225
by (subst UN_singleton [symmetric], rule leadsTo_UN, blast)
paulson@13797
   226
paulson@13797
   227
paulson@13812
   228
text{*The INDUCTION rule as we should have liked to state it*}
paulson@13797
   229
lemma leadsTo_induct: 
paulson@13805
   230
  "[| F \<in> za leadsTo zb;   
paulson@13805
   231
      !!A B. F \<in> A ensures B ==> P A B;  
paulson@13805
   232
      !!A B C. [| F \<in> A leadsTo B; P A B; F \<in> B leadsTo C; P B C |]  
paulson@13797
   233
               ==> P A C;  
paulson@13805
   234
      !!B S. \<forall>A \<in> S. F \<in> A leadsTo B & P A B ==> P (Union S) B  
paulson@13797
   235
   |] ==> P za zb"
paulson@13797
   236
apply (unfold leadsTo_def)
paulson@13797
   237
apply (drule CollectD, erule leads.induct)
paulson@13797
   238
apply (blast+)
paulson@13797
   239
done
paulson@13797
   240
paulson@13797
   241
paulson@13805
   242
lemma subset_imp_ensures: "A \<subseteq> B ==> F \<in> A ensures B"
paulson@13797
   243
by (unfold ensures_def constrains_def transient_def, blast)
paulson@13797
   244
paulson@13797
   245
lemmas subset_imp_leadsTo = subset_imp_ensures [THEN leadsTo_Basis, standard]
paulson@13797
   246
paulson@13797
   247
lemmas leadsTo_refl = subset_refl [THEN subset_imp_leadsTo, standard]
paulson@13797
   248
paulson@13797
   249
lemmas empty_leadsTo = empty_subsetI [THEN subset_imp_leadsTo, standard, simp]
paulson@13797
   250
paulson@13797
   251
lemmas leadsTo_UNIV = subset_UNIV [THEN subset_imp_leadsTo, standard, simp]
paulson@13797
   252
paulson@13797
   253
paulson@13797
   254
paulson@13797
   255
(** Variant induction rule: on the preconditions for B **)
paulson@13797
   256
paulson@13812
   257
text{*Lemma is the weak version: can't see how to do it in one step*}
paulson@13797
   258
lemma leadsTo_induct_pre_lemma: 
paulson@13805
   259
  "[| F \<in> za leadsTo zb;   
paulson@13797
   260
      P zb;  
paulson@13805
   261
      !!A B. [| F \<in> A ensures B;  P B |] ==> P A;  
paulson@13805
   262
      !!S. \<forall>A \<in> S. P A ==> P (Union S)  
paulson@13797
   263
   |] ==> P za"
paulson@13812
   264
txt{*by induction on this formula*}
paulson@13797
   265
apply (subgoal_tac "P zb --> P za")
paulson@13812
   266
txt{*now solve first subgoal: this formula is sufficient*}
paulson@13797
   267
apply (blast intro: leadsTo_refl)
paulson@13797
   268
apply (erule leadsTo_induct)
paulson@13797
   269
apply (blast+)
paulson@13797
   270
done
paulson@13797
   271
paulson@13797
   272
lemma leadsTo_induct_pre: 
paulson@13805
   273
  "[| F \<in> za leadsTo zb;   
paulson@13797
   274
      P zb;  
paulson@13805
   275
      !!A B. [| F \<in> A ensures B;  F \<in> B leadsTo zb;  P B |] ==> P A;  
paulson@13805
   276
      !!S. \<forall>A \<in> S. F \<in> A leadsTo zb & P A ==> P (Union S)  
paulson@13797
   277
   |] ==> P za"
paulson@13805
   278
apply (subgoal_tac "F \<in> za leadsTo zb & P za")
paulson@13797
   279
apply (erule conjunct2)
paulson@13797
   280
apply (erule leadsTo_induct_pre_lemma)
paulson@13797
   281
prefer 3 apply (blast intro: leadsTo_Union)
paulson@13797
   282
prefer 2 apply (blast intro: leadsTo_Trans)
paulson@13797
   283
apply (blast intro: leadsTo_refl)
paulson@13797
   284
done
paulson@13797
   285
paulson@13797
   286
paulson@13805
   287
lemma leadsTo_weaken_R: "[| F \<in> A leadsTo A'; A'<=B' |] ==> F \<in> A leadsTo B'"
paulson@13797
   288
by (blast intro: subset_imp_leadsTo leadsTo_Trans)
paulson@13797
   289
paulson@13798
   290
lemma leadsTo_weaken_L [rule_format]:
paulson@13805
   291
     "[| F \<in> A leadsTo A'; B \<subseteq> A |] ==> F \<in> B leadsTo A'"
paulson@13797
   292
by (blast intro: leadsTo_Trans subset_imp_leadsTo)
paulson@13797
   293
paulson@13812
   294
text{*Distributes over binary unions*}
paulson@13797
   295
lemma leadsTo_Un_distrib:
paulson@13805
   296
     "F \<in> (A \<union> B) leadsTo C  =  (F \<in> A leadsTo C & F \<in> B leadsTo C)"
paulson@13797
   297
by (blast intro: leadsTo_Un leadsTo_weaken_L)
paulson@13797
   298
paulson@13797
   299
lemma leadsTo_UN_distrib:
paulson@13805
   300
     "F \<in> (\<Union>i \<in> I. A i) leadsTo B  =  (\<forall>i \<in> I. F \<in> (A i) leadsTo B)"
paulson@13797
   301
by (blast intro: leadsTo_UN leadsTo_weaken_L)
paulson@13797
   302
paulson@13797
   303
lemma leadsTo_Union_distrib:
paulson@13805
   304
     "F \<in> (Union S) leadsTo B  =  (\<forall>A \<in> S. F \<in> A leadsTo B)"
paulson@13797
   305
by (blast intro: leadsTo_Union leadsTo_weaken_L)
paulson@13797
   306
paulson@13797
   307
paulson@13797
   308
lemma leadsTo_weaken:
paulson@13805
   309
     "[| F \<in> A leadsTo A'; B \<subseteq> A; A'<=B' |] ==> F \<in> B leadsTo B'"
paulson@13797
   310
by (blast intro: leadsTo_weaken_R leadsTo_weaken_L leadsTo_Trans)
paulson@13797
   311
paulson@13797
   312
paulson@14150
   313
text{*Set difference: maybe combine with @{text leadsTo_weaken_L}??*}
paulson@13797
   314
lemma leadsTo_Diff:
paulson@13805
   315
     "[| F \<in> (A-B) leadsTo C; F \<in> B leadsTo C |]   ==> F \<in> A leadsTo C"
paulson@13797
   316
by (blast intro: leadsTo_Un leadsTo_weaken)
paulson@13797
   317
paulson@13797
   318
lemma leadsTo_UN_UN:
paulson@13805
   319
   "(!! i. i \<in> I ==> F \<in> (A i) leadsTo (A' i))  
paulson@13805
   320
    ==> F \<in> (\<Union>i \<in> I. A i) leadsTo (\<Union>i \<in> I. A' i)"
paulson@13797
   321
apply (simp only: Union_image_eq [symmetric])
paulson@13797
   322
apply (blast intro: leadsTo_Union leadsTo_weaken_R)
paulson@13797
   323
done
paulson@13797
   324
paulson@13812
   325
text{*Binary union version*}
paulson@13797
   326
lemma leadsTo_Un_Un:
paulson@13805
   327
     "[| F \<in> A leadsTo A'; F \<in> B leadsTo B' |]  
paulson@13805
   328
      ==> F \<in> (A \<union> B) leadsTo (A' \<union> B')"
paulson@13797
   329
by (blast intro: leadsTo_Un leadsTo_weaken_R)
paulson@13797
   330
paulson@13797
   331
paulson@13797
   332
(** The cancellation law **)
paulson@13797
   333
paulson@13797
   334
lemma leadsTo_cancel2:
paulson@13805
   335
     "[| F \<in> A leadsTo (A' \<union> B); F \<in> B leadsTo B' |]  
paulson@13805
   336
      ==> F \<in> A leadsTo (A' \<union> B')"
paulson@13797
   337
by (blast intro: leadsTo_Un_Un subset_imp_leadsTo leadsTo_Trans)
paulson@13797
   338
paulson@13797
   339
lemma leadsTo_cancel_Diff2:
paulson@13805
   340
     "[| F \<in> A leadsTo (A' \<union> B); F \<in> (B-A') leadsTo B' |]  
paulson@13805
   341
      ==> F \<in> A leadsTo (A' \<union> B')"
paulson@13797
   342
apply (rule leadsTo_cancel2)
paulson@13797
   343
prefer 2 apply assumption
paulson@13797
   344
apply (simp_all (no_asm_simp))
paulson@13797
   345
done
paulson@13797
   346
paulson@13797
   347
lemma leadsTo_cancel1:
paulson@13805
   348
     "[| F \<in> A leadsTo (B \<union> A'); F \<in> B leadsTo B' |]  
paulson@13805
   349
    ==> F \<in> A leadsTo (B' \<union> A')"
paulson@13797
   350
apply (simp add: Un_commute)
paulson@13797
   351
apply (blast intro!: leadsTo_cancel2)
paulson@13797
   352
done
paulson@13797
   353
paulson@13797
   354
lemma leadsTo_cancel_Diff1:
paulson@13805
   355
     "[| F \<in> A leadsTo (B \<union> A'); F \<in> (B-A') leadsTo B' |]  
paulson@13805
   356
    ==> F \<in> A leadsTo (B' \<union> A')"
paulson@13797
   357
apply (rule leadsTo_cancel1)
paulson@13797
   358
prefer 2 apply assumption
paulson@13797
   359
apply (simp_all (no_asm_simp))
paulson@13797
   360
done
paulson@13797
   361
paulson@13797
   362
paulson@13812
   363
text{*The impossibility law*}
paulson@13812
   364
lemma leadsTo_empty: "[|F \<in> A leadsTo {}; all_total F|] ==> A={}"
paulson@13797
   365
apply (erule leadsTo_induct_pre)
paulson@13812
   366
apply (simp_all add: ensures_def constrains_def transient_def all_total_def, clarify)
paulson@13812
   367
apply (drule bspec, assumption)+
paulson@13812
   368
apply blast
paulson@13797
   369
done
paulson@13797
   370
paulson@13812
   371
subsection{*PSP: Progress-Safety-Progress*}
paulson@13797
   372
paulson@13812
   373
text{*Special case of PSP: Misra's "stable conjunction"*}
paulson@13797
   374
lemma psp_stable: 
paulson@13805
   375
   "[| F \<in> A leadsTo A'; F \<in> stable B |]  
paulson@13805
   376
    ==> F \<in> (A \<inter> B) leadsTo (A' \<inter> B)"
paulson@13797
   377
apply (unfold stable_def)
paulson@13797
   378
apply (erule leadsTo_induct)
paulson@13797
   379
prefer 3 apply (blast intro: leadsTo_Union_Int)
paulson@13797
   380
prefer 2 apply (blast intro: leadsTo_Trans)
paulson@13797
   381
apply (rule leadsTo_Basis)
paulson@13797
   382
apply (simp add: ensures_def Diff_Int_distrib2 [symmetric] Int_Un_distrib2 [symmetric])
paulson@13797
   383
apply (blast intro: transient_strengthen constrains_Int)
paulson@13797
   384
done
paulson@13797
   385
paulson@13797
   386
lemma psp_stable2: 
paulson@13805
   387
   "[| F \<in> A leadsTo A'; F \<in> stable B |] ==> F \<in> (B \<inter> A) leadsTo (B \<inter> A')"
paulson@13797
   388
by (simp add: psp_stable Int_ac)
paulson@13797
   389
paulson@13797
   390
lemma psp_ensures: 
paulson@13805
   391
   "[| F \<in> A ensures A'; F \<in> B co B' |]  
paulson@13805
   392
    ==> F \<in> (A \<inter> B') ensures ((A' \<inter> B) \<union> (B' - B))"
paulson@13797
   393
apply (unfold ensures_def constrains_def, clarify) (*speeds up the proof*)
paulson@13797
   394
apply (blast intro: transient_strengthen)
paulson@13797
   395
done
paulson@13797
   396
paulson@13797
   397
lemma psp:
paulson@13805
   398
     "[| F \<in> A leadsTo A'; F \<in> B co B' |]  
paulson@13805
   399
      ==> F \<in> (A \<inter> B') leadsTo ((A' \<inter> B) \<union> (B' - B))"
paulson@13797
   400
apply (erule leadsTo_induct)
paulson@13797
   401
  prefer 3 apply (blast intro: leadsTo_Union_Int)
paulson@13797
   402
 txt{*Basis case*}
paulson@13797
   403
 apply (blast intro: psp_ensures)
paulson@13797
   404
txt{*Transitivity case has a delicate argument involving "cancellation"*}
paulson@13797
   405
apply (rule leadsTo_Un_duplicate2)
paulson@13797
   406
apply (erule leadsTo_cancel_Diff1)
paulson@13797
   407
apply (simp add: Int_Diff Diff_triv)
paulson@13797
   408
apply (blast intro: leadsTo_weaken_L dest: constrains_imp_subset)
paulson@13797
   409
done
paulson@13797
   410
paulson@13797
   411
lemma psp2:
paulson@13805
   412
     "[| F \<in> A leadsTo A'; F \<in> B co B' |]  
paulson@13805
   413
    ==> F \<in> (B' \<inter> A) leadsTo ((B \<inter> A') \<union> (B' - B))"
paulson@13797
   414
by (simp (no_asm_simp) add: psp Int_ac)
paulson@13797
   415
paulson@13797
   416
lemma psp_unless: 
paulson@13805
   417
   "[| F \<in> A leadsTo A';  F \<in> B unless B' |]  
paulson@13805
   418
    ==> F \<in> (A \<inter> B) leadsTo ((A' \<inter> B) \<union> B')"
paulson@13797
   419
paulson@13797
   420
apply (unfold unless_def)
paulson@13797
   421
apply (drule psp, assumption)
paulson@13797
   422
apply (blast intro: leadsTo_weaken)
paulson@13797
   423
done
paulson@13797
   424
paulson@13797
   425
paulson@13798
   426
subsection{*Proving the induction rules*}
paulson@13797
   427
paulson@13797
   428
(** The most general rule: r is any wf relation; f is any variant function **)
paulson@13797
   429
paulson@13797
   430
lemma leadsTo_wf_induct_lemma:
paulson@13797
   431
     "[| wf r;      
paulson@13805
   432
         \<forall>m. F \<in> (A \<inter> f-`{m}) leadsTo                      
paulson@13805
   433
                    ((A \<inter> f-`(r^-1 `` {m})) \<union> B) |]  
paulson@13805
   434
      ==> F \<in> (A \<inter> f-`{m}) leadsTo B"
paulson@13797
   435
apply (erule_tac a = m in wf_induct)
paulson@13805
   436
apply (subgoal_tac "F \<in> (A \<inter> (f -` (r^-1 `` {x}))) leadsTo B")
paulson@13797
   437
 apply (blast intro: leadsTo_cancel1 leadsTo_Un_duplicate)
paulson@13797
   438
apply (subst vimage_eq_UN)
paulson@13797
   439
apply (simp only: UN_simps [symmetric])
paulson@13797
   440
apply (blast intro: leadsTo_UN)
paulson@13797
   441
done
paulson@13797
   442
paulson@13797
   443
paulson@13797
   444
(** Meta or object quantifier ? **)
paulson@13797
   445
lemma leadsTo_wf_induct:
paulson@13797
   446
     "[| wf r;      
paulson@13805
   447
         \<forall>m. F \<in> (A \<inter> f-`{m}) leadsTo                      
paulson@13805
   448
                    ((A \<inter> f-`(r^-1 `` {m})) \<union> B) |]  
paulson@13805
   449
      ==> F \<in> A leadsTo B"
paulson@13797
   450
apply (rule_tac t = A in subst)
paulson@13797
   451
 defer 1
paulson@13797
   452
 apply (rule leadsTo_UN)
paulson@13797
   453
 apply (erule leadsTo_wf_induct_lemma)
paulson@13797
   454
 apply assumption
paulson@13797
   455
apply fast (*Blast_tac: Function unknown's argument not a parameter*)
paulson@13797
   456
done
paulson@13797
   457
paulson@13797
   458
paulson@13797
   459
lemma bounded_induct:
paulson@13797
   460
     "[| wf r;      
paulson@13805
   461
         \<forall>m \<in> I. F \<in> (A \<inter> f-`{m}) leadsTo                    
paulson@13805
   462
                      ((A \<inter> f-`(r^-1 `` {m})) \<union> B) |]  
paulson@13805
   463
      ==> F \<in> A leadsTo ((A - (f-`I)) \<union> B)"
paulson@13797
   464
apply (erule leadsTo_wf_induct, safe)
paulson@13805
   465
apply (case_tac "m \<in> I")
paulson@13797
   466
apply (blast intro: leadsTo_weaken)
paulson@13797
   467
apply (blast intro: subset_imp_leadsTo)
paulson@13797
   468
done
paulson@13797
   469
paulson@13797
   470
paulson@13805
   471
(*Alternative proof is via the lemma F \<in> (A \<inter> f-`(lessThan m)) leadsTo B*)
paulson@13797
   472
lemma lessThan_induct: 
paulson@13805
   473
     "[| !!m::nat. F \<in> (A \<inter> f-`{m}) leadsTo ((A \<inter> f-`{..m(}) \<union> B) |]  
paulson@13805
   474
      ==> F \<in> A leadsTo B"
paulson@13797
   475
apply (rule wf_less_than [THEN leadsTo_wf_induct])
paulson@13797
   476
apply (simp (no_asm_simp))
paulson@13797
   477
apply blast
paulson@13797
   478
done
paulson@13797
   479
paulson@13797
   480
lemma lessThan_bounded_induct:
paulson@13805
   481
     "!!l::nat. [| \<forall>m \<in> greaterThan l.     
paulson@13805
   482
            F \<in> (A \<inter> f-`{m}) leadsTo ((A \<inter> f-`(lessThan m)) \<union> B) |]  
paulson@13805
   483
      ==> F \<in> A leadsTo ((A \<inter> (f-`(atMost l))) \<union> B)"
paulson@13797
   484
apply (simp only: Diff_eq [symmetric] vimage_Compl Compl_greaterThan [symmetric])
paulson@13797
   485
apply (rule wf_less_than [THEN bounded_induct])
paulson@13797
   486
apply (simp (no_asm_simp))
paulson@13797
   487
done
paulson@13797
   488
paulson@13797
   489
lemma greaterThan_bounded_induct:
paulson@13805
   490
     "(!!l::nat. \<forall>m \<in> lessThan l.     
paulson@13805
   491
                 F \<in> (A \<inter> f-`{m}) leadsTo ((A \<inter> f-`(greaterThan m)) \<union> B))
paulson@13805
   492
      ==> F \<in> A leadsTo ((A \<inter> (f-`(atLeast l))) \<union> B)"
paulson@13797
   493
apply (rule_tac f = f and f1 = "%k. l - k" 
paulson@13797
   494
       in wf_less_than [THEN wf_inv_image, THEN leadsTo_wf_induct])
paulson@13797
   495
apply (simp (no_asm) add: inv_image_def Image_singleton)
paulson@13797
   496
apply clarify
paulson@13797
   497
apply (case_tac "m<l")
paulson@13805
   498
 apply (blast intro: leadsTo_weaken_R diff_less_mono2)
paulson@13805
   499
apply (blast intro: not_leE subset_imp_leadsTo)
paulson@13797
   500
done
paulson@13797
   501
paulson@13797
   502
paulson@13798
   503
subsection{*wlt*}
paulson@13797
   504
paulson@13812
   505
text{*Misra's property W3*}
paulson@13805
   506
lemma wlt_leadsTo: "F \<in> (wlt F B) leadsTo B"
paulson@13797
   507
apply (unfold wlt_def)
paulson@13797
   508
apply (blast intro!: leadsTo_Union)
paulson@13797
   509
done
paulson@13797
   510
paulson@13805
   511
lemma leadsTo_subset: "F \<in> A leadsTo B ==> A \<subseteq> wlt F B"
paulson@13797
   512
apply (unfold wlt_def)
paulson@13797
   513
apply (blast intro!: leadsTo_Union)
paulson@13797
   514
done
paulson@13797
   515
paulson@13812
   516
text{*Misra's property W2*}
paulson@13805
   517
lemma leadsTo_eq_subset_wlt: "F \<in> A leadsTo B = (A \<subseteq> wlt F B)"
paulson@13797
   518
by (blast intro!: leadsTo_subset wlt_leadsTo [THEN leadsTo_weaken_L])
paulson@13797
   519
paulson@13812
   520
text{*Misra's property W4*}
paulson@13805
   521
lemma wlt_increasing: "B \<subseteq> wlt F B"
paulson@13797
   522
apply (simp (no_asm_simp) add: leadsTo_eq_subset_wlt [symmetric] subset_imp_leadsTo)
paulson@13797
   523
done
paulson@13797
   524
paulson@13797
   525
paulson@13812
   526
text{*Used in the Trans case below*}
paulson@13797
   527
lemma lemma1: 
paulson@13805
   528
   "[| B \<subseteq> A2;   
paulson@13805
   529
       F \<in> (A1 - B) co (A1 \<union> B);  
paulson@13805
   530
       F \<in> (A2 - C) co (A2 \<union> C) |]  
paulson@13805
   531
    ==> F \<in> (A1 \<union> A2 - C) co (A1 \<union> A2 \<union> C)"
paulson@13797
   532
by (unfold constrains_def, clarify,  blast)
paulson@13797
   533
paulson@13812
   534
text{*Lemma (1,2,3) of Misra's draft book, Chapter 4, "Progress"*}
paulson@13797
   535
lemma leadsTo_123:
paulson@13805
   536
     "F \<in> A leadsTo A'  
paulson@13805
   537
      ==> \<exists>B. A \<subseteq> B & F \<in> B leadsTo A' & F \<in> (B-A') co (B \<union> A')"
paulson@13797
   538
apply (erule leadsTo_induct)
paulson@13812
   539
  txt{*Basis*}
paulson@13812
   540
  apply (blast dest: ensuresD)
paulson@13812
   541
 txt{*Trans*}
paulson@13812
   542
 apply clarify
paulson@13812
   543
 apply (rule_tac x = "Ba \<union> Bb" in exI)
paulson@13812
   544
 apply (blast intro: lemma1 leadsTo_Un_Un leadsTo_cancel1 leadsTo_Un_duplicate)
paulson@13812
   545
txt{*Union*}
paulson@13797
   546
apply (clarify dest!: ball_conj_distrib [THEN iffD1] bchoice)
paulson@13805
   547
apply (rule_tac x = "\<Union>A \<in> S. f A" in exI)
paulson@13797
   548
apply (auto intro: leadsTo_UN)
paulson@13797
   549
(*Blast_tac says PROOF FAILED*)
paulson@13805
   550
apply (rule_tac I1=S and A1="%i. f i - B" and A'1="%i. f i \<union> B" 
paulson@13798
   551
       in constrains_UN [THEN constrains_weaken], auto) 
paulson@13797
   552
done
paulson@13797
   553
paulson@13797
   554
paulson@13812
   555
text{*Misra's property W5*}
paulson@13805
   556
lemma wlt_constrains_wlt: "F \<in> (wlt F B - B) co (wlt F B)"
paulson@13798
   557
proof -
paulson@13798
   558
  from wlt_leadsTo [of F B, THEN leadsTo_123]
paulson@13798
   559
  show ?thesis
paulson@13798
   560
  proof (elim exE conjE)
paulson@13798
   561
(* assumes have to be in exactly the form as in the goal displayed at
paulson@13798
   562
   this point.  Isar doesn't give you any automation. *)
paulson@13798
   563
    fix C
paulson@13798
   564
    assume wlt: "wlt F B \<subseteq> C"
paulson@13798
   565
       and lt:  "F \<in> C leadsTo B"
paulson@13798
   566
       and co:  "F \<in> C - B co C \<union> B"
paulson@13798
   567
    have eq: "C = wlt F B"
paulson@13798
   568
    proof -
paulson@13798
   569
      from lt and wlt show ?thesis 
paulson@13798
   570
           by (blast dest: leadsTo_eq_subset_wlt [THEN iffD1])
paulson@13798
   571
    qed
paulson@13798
   572
    from co show ?thesis by (simp add: eq wlt_increasing Un_absorb2)
paulson@13798
   573
  qed
paulson@13798
   574
qed
paulson@13797
   575
paulson@13797
   576
paulson@13798
   577
subsection{*Completion: Binary and General Finite versions*}
paulson@13797
   578
paulson@13797
   579
lemma completion_lemma :
paulson@13805
   580
     "[| W = wlt F (B' \<union> C);      
paulson@13805
   581
       F \<in> A leadsTo (A' \<union> C);  F \<in> A' co (A' \<union> C);    
paulson@13805
   582
       F \<in> B leadsTo (B' \<union> C);  F \<in> B' co (B' \<union> C) |]  
paulson@13805
   583
    ==> F \<in> (A \<inter> B) leadsTo ((A' \<inter> B') \<union> C)"
paulson@13805
   584
apply (subgoal_tac "F \<in> (W-C) co (W \<union> B' \<union> C) ")
paulson@13797
   585
 prefer 2
paulson@13797
   586
 apply (blast intro: wlt_constrains_wlt [THEN [2] constrains_Un, 
paulson@13797
   587
                                         THEN constrains_weaken])
paulson@13805
   588
apply (subgoal_tac "F \<in> (W-C) co W")
paulson@13797
   589
 prefer 2
paulson@13797
   590
 apply (simp add: wlt_increasing Un_assoc Un_absorb2)
paulson@13805
   591
apply (subgoal_tac "F \<in> (A \<inter> W - C) leadsTo (A' \<inter> W \<union> C) ")
paulson@13797
   592
 prefer 2 apply (blast intro: wlt_leadsTo psp [THEN leadsTo_weaken])
paulson@13797
   593
(** LEVEL 6 **)
paulson@13805
   594
apply (subgoal_tac "F \<in> (A' \<inter> W \<union> C) leadsTo (A' \<inter> B' \<union> C) ")
paulson@13797
   595
 prefer 2
paulson@13797
   596
 apply (rule leadsTo_Un_duplicate2)
paulson@13797
   597
 apply (blast intro: leadsTo_Un_Un wlt_leadsTo
paulson@13797
   598
                         [THEN psp2, THEN leadsTo_weaken] leadsTo_refl)
paulson@13797
   599
apply (drule leadsTo_Diff)
paulson@13797
   600
apply (blast intro: subset_imp_leadsTo)
paulson@13805
   601
apply (subgoal_tac "A \<inter> B \<subseteq> A \<inter> W")
paulson@13797
   602
 prefer 2
paulson@13797
   603
 apply (blast dest!: leadsTo_subset intro!: subset_refl [THEN Int_mono])
paulson@13797
   604
apply (blast intro: leadsTo_Trans subset_imp_leadsTo)
paulson@13797
   605
done
paulson@13797
   606
paulson@13797
   607
lemmas completion = completion_lemma [OF refl]
paulson@13797
   608
paulson@13797
   609
lemma finite_completion_lemma:
paulson@13805
   610
     "finite I ==> (\<forall>i \<in> I. F \<in> (A i) leadsTo (A' i \<union> C)) -->   
paulson@13805
   611
                   (\<forall>i \<in> I. F \<in> (A' i) co (A' i \<union> C)) -->  
paulson@13805
   612
                   F \<in> (\<Inter>i \<in> I. A i) leadsTo ((\<Inter>i \<in> I. A' i) \<union> C)"
paulson@13797
   613
apply (erule finite_induct, auto)
paulson@13797
   614
apply (rule completion)
paulson@13797
   615
   prefer 4
paulson@13797
   616
   apply (simp only: INT_simps [symmetric])
paulson@13797
   617
   apply (rule constrains_INT, auto)
paulson@13797
   618
done
paulson@13797
   619
paulson@13797
   620
lemma finite_completion: 
paulson@13797
   621
     "[| finite I;   
paulson@13805
   622
         !!i. i \<in> I ==> F \<in> (A i) leadsTo (A' i \<union> C);  
paulson@13805
   623
         !!i. i \<in> I ==> F \<in> (A' i) co (A' i \<union> C) |]    
paulson@13805
   624
      ==> F \<in> (\<Inter>i \<in> I. A i) leadsTo ((\<Inter>i \<in> I. A' i) \<union> C)"
paulson@13797
   625
by (blast intro: finite_completion_lemma [THEN mp, THEN mp])
paulson@13797
   626
paulson@13797
   627
lemma stable_completion: 
paulson@13805
   628
     "[| F \<in> A leadsTo A';  F \<in> stable A';    
paulson@13805
   629
         F \<in> B leadsTo B';  F \<in> stable B' |]  
paulson@13805
   630
    ==> F \<in> (A \<inter> B) leadsTo (A' \<inter> B')"
paulson@13797
   631
apply (unfold stable_def)
paulson@13797
   632
apply (rule_tac C1 = "{}" in completion [THEN leadsTo_weaken_R])
paulson@13797
   633
apply (force+)
paulson@13797
   634
done
paulson@13797
   635
paulson@13797
   636
lemma finite_stable_completion: 
paulson@13797
   637
     "[| finite I;   
paulson@13805
   638
         !!i. i \<in> I ==> F \<in> (A i) leadsTo (A' i);  
paulson@13805
   639
         !!i. i \<in> I ==> F \<in> stable (A' i) |]    
paulson@13805
   640
      ==> F \<in> (\<Inter>i \<in> I. A i) leadsTo (\<Inter>i \<in> I. A' i)"
paulson@13797
   641
apply (unfold stable_def)
paulson@13797
   642
apply (rule_tac C1 = "{}" in finite_completion [THEN leadsTo_weaken_R])
paulson@13797
   643
apply (simp_all (no_asm_simp))
paulson@13797
   644
apply blast+
paulson@13797
   645
done
paulson@9685
   646
paulson@4776
   647
end