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