src/HOL/UNITY/Follows.thy
author paulson
Sat Feb 08 16:05:33 2003 +0100 (2003-02-08)
changeset 13812 91713a1915ee
parent 13805 3786b2fd6808
child 15102 04b0e943fcc9
permissions -rw-r--r--
converting HOL/UNITY to use unconditional fairness
paulson@6706
     1
(*  Title:      HOL/UNITY/Follows
paulson@6706
     2
    ID:         $Id$
paulson@6706
     3
    Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
paulson@6706
     4
    Copyright   1998  University of Cambridge
paulson@13798
     5
*)
paulson@6706
     6
paulson@13798
     7
header{*The Follows Relation of Charpentier and Sivilotte*}
paulson@6706
     8
paulson@13796
     9
theory Follows = SubstAx + ListOrder + Multiset:
paulson@6706
    10
paulson@6706
    11
constdefs
paulson@6706
    12
paulson@6706
    13
  Follows :: "['a => 'b::{order}, 'a => 'b::{order}] => 'a program set"
paulson@6809
    14
                 (infixl "Fols" 65)
paulson@13805
    15
   "f Fols g == Increasing g \<inter> Increasing f Int
paulson@13805
    16
                Always {s. f s \<le> g s} Int
paulson@13805
    17
                (\<Inter>k. {s. k \<le> g s} LeadsTo {s. k \<le> f s})"
paulson@6706
    18
paulson@6706
    19
paulson@13796
    20
(*Does this hold for "invariant"?*)
paulson@13796
    21
lemma mono_Always_o:
paulson@13805
    22
     "mono h ==> Always {s. f s \<le> g s} \<subseteq> Always {s. h (f s) \<le> h (g s)}"
paulson@13796
    23
apply (simp add: Always_eq_includes_reachable)
paulson@13796
    24
apply (blast intro: monoD)
paulson@13796
    25
done
paulson@13796
    26
paulson@13796
    27
lemma mono_LeadsTo_o:
paulson@13796
    28
     "mono (h::'a::order => 'b::order)  
paulson@13805
    29
      ==> (\<Inter>j. {s. j \<le> g s} LeadsTo {s. j \<le> f s}) \<subseteq>  
paulson@13805
    30
          (\<Inter>k. {s. k \<le> h (g s)} LeadsTo {s. k \<le> h (f s)})"
paulson@13796
    31
apply auto
paulson@13796
    32
apply (rule single_LeadsTo_I)
paulson@13796
    33
apply (drule_tac x = "g s" in spec)
paulson@13796
    34
apply (erule LeadsTo_weaken)
paulson@13796
    35
apply (blast intro: monoD order_trans)+
paulson@13796
    36
done
paulson@13796
    37
paulson@13805
    38
lemma Follows_constant [iff]: "F \<in> (%s. c) Fols (%s. c)"
paulson@13796
    39
by (unfold Follows_def, auto)
paulson@13796
    40
paulson@13805
    41
lemma mono_Follows_o: "mono h ==> f Fols g \<subseteq> (h o f) Fols (h o g)"
paulson@13796
    42
apply (unfold Follows_def, clarify)
paulson@13796
    43
apply (simp add: mono_Increasing_o [THEN [2] rev_subsetD]
paulson@13796
    44
                 mono_Always_o [THEN [2] rev_subsetD]
paulson@13796
    45
                 mono_LeadsTo_o [THEN [2] rev_subsetD, THEN INT_D])
paulson@13796
    46
done
paulson@13796
    47
paulson@13796
    48
lemma mono_Follows_apply:
paulson@13805
    49
     "mono h ==> f Fols g \<subseteq> (%x. h (f x)) Fols (%x. h (g x))"
paulson@13796
    50
apply (drule mono_Follows_o)
paulson@13796
    51
apply (force simp add: o_def)
paulson@13796
    52
done
paulson@13796
    53
paulson@13796
    54
lemma Follows_trans: 
paulson@13805
    55
     "[| F \<in> f Fols g;  F \<in> g Fols h |] ==> F \<in> f Fols h"
paulson@13796
    56
apply (unfold Follows_def)
paulson@13796
    57
apply (simp add: Always_eq_includes_reachable)
paulson@13796
    58
apply (blast intro: order_trans LeadsTo_Trans)
paulson@13796
    59
done
paulson@13796
    60
paulson@13796
    61
paulson@13798
    62
subsection{*Destruction rules*}
paulson@13796
    63
paulson@13805
    64
lemma Follows_Increasing1: "F \<in> f Fols g ==> F \<in> Increasing f"
paulson@13812
    65
by (unfold Follows_def, blast)
paulson@13796
    66
paulson@13805
    67
lemma Follows_Increasing2: "F \<in> f Fols g ==> F \<in> Increasing g"
paulson@13812
    68
by (unfold Follows_def, blast)
paulson@13796
    69
paulson@13805
    70
lemma Follows_Bounded: "F \<in> f Fols g ==> F \<in> Always {s. f s \<subseteq> g s}"
paulson@13812
    71
by (unfold Follows_def, blast)
paulson@13796
    72
paulson@13796
    73
lemma Follows_LeadsTo: 
paulson@13805
    74
     "F \<in> f Fols g ==> F \<in> {s. k \<le> g s} LeadsTo {s. k \<le> f s}"
paulson@13798
    75
by (unfold Follows_def, blast)
paulson@13796
    76
paulson@13796
    77
lemma Follows_LeadsTo_pfixLe:
paulson@13805
    78
     "F \<in> f Fols g ==> F \<in> {s. k pfixLe g s} LeadsTo {s. k pfixLe f s}"
paulson@13796
    79
apply (rule single_LeadsTo_I, clarify)
paulson@13796
    80
apply (drule_tac k="g s" in Follows_LeadsTo)
paulson@13796
    81
apply (erule LeadsTo_weaken)
paulson@13796
    82
 apply blast 
paulson@13796
    83
apply (blast intro: pfixLe_trans prefix_imp_pfixLe)
paulson@13796
    84
done
paulson@13796
    85
paulson@13796
    86
lemma Follows_LeadsTo_pfixGe:
paulson@13805
    87
     "F \<in> f Fols g ==> F \<in> {s. k pfixGe g s} LeadsTo {s. k pfixGe f s}"
paulson@13796
    88
apply (rule single_LeadsTo_I, clarify)
paulson@13796
    89
apply (drule_tac k="g s" in Follows_LeadsTo)
paulson@13796
    90
apply (erule LeadsTo_weaken)
paulson@13796
    91
 apply blast 
paulson@13796
    92
apply (blast intro: pfixGe_trans prefix_imp_pfixGe)
paulson@13796
    93
done
paulson@13796
    94
paulson@13796
    95
paulson@13796
    96
lemma Always_Follows1: 
paulson@13805
    97
     "[| F \<in> Always {s. f s = f' s}; F \<in> f Fols g |] ==> F \<in> f' Fols g"
paulson@13796
    98
paulson@13796
    99
apply (unfold Follows_def Increasing_def Stable_def, auto)
paulson@13796
   100
apply (erule_tac [3] Always_LeadsTo_weaken)
paulson@13805
   101
apply (erule_tac A = "{s. z \<le> f s}" and A' = "{s. z \<le> f s}" 
paulson@13798
   102
       in Always_Constrains_weaken, auto)
paulson@13796
   103
apply (drule Always_Int_I, assumption)
paulson@13796
   104
apply (force intro: Always_weaken)
paulson@13796
   105
done
paulson@13796
   106
paulson@13796
   107
lemma Always_Follows2: 
paulson@13805
   108
     "[| F \<in> Always {s. g s = g' s}; F \<in> f Fols g |] ==> F \<in> f Fols g'"
paulson@13796
   109
apply (unfold Follows_def Increasing_def Stable_def, auto)
paulson@13796
   110
apply (erule_tac [3] Always_LeadsTo_weaken)
paulson@13805
   111
apply (erule_tac A = "{s. z \<le> g s}" and A' = "{s. z \<le> g s}"
paulson@13798
   112
       in Always_Constrains_weaken, auto)
paulson@13796
   113
apply (drule Always_Int_I, assumption)
paulson@13796
   114
apply (force intro: Always_weaken)
paulson@13796
   115
done
paulson@13796
   116
paulson@13796
   117
paulson@13798
   118
subsection{*Union properties (with the subset ordering)*}
paulson@13796
   119
paulson@13796
   120
(*Can replace "Un" by any sup.  But existing max only works for linorders.*)
paulson@13796
   121
lemma increasing_Un: 
paulson@13805
   122
    "[| F \<in> increasing f;  F \<in> increasing g |]  
paulson@13805
   123
     ==> F \<in> increasing (%s. (f s) \<union> (g s))"
paulson@13796
   124
apply (unfold increasing_def stable_def constrains_def, auto)
paulson@13796
   125
apply (drule_tac x = "f xa" in spec)
paulson@13796
   126
apply (drule_tac x = "g xa" in spec)
paulson@13796
   127
apply (blast dest!: bspec)
paulson@13796
   128
done
paulson@13796
   129
paulson@13796
   130
lemma Increasing_Un: 
paulson@13805
   131
    "[| F \<in> Increasing f;  F \<in> Increasing g |]  
paulson@13805
   132
     ==> F \<in> Increasing (%s. (f s) \<union> (g s))"
paulson@13798
   133
apply (auto simp add: Increasing_def Stable_def Constrains_def
paulson@13798
   134
                      stable_def constrains_def)
paulson@13796
   135
apply (drule_tac x = "f xa" in spec)
paulson@13796
   136
apply (drule_tac x = "g xa" in spec)
paulson@13796
   137
apply (blast dest!: bspec)
paulson@13796
   138
done
paulson@13796
   139
paulson@13796
   140
paulson@13796
   141
lemma Always_Un:
paulson@13805
   142
     "[| F \<in> Always {s. f' s \<le> f s}; F \<in> Always {s. g' s \<le> g s} |]  
paulson@13805
   143
      ==> F \<in> Always {s. f' s \<union> g' s \<le> f s \<union> g s}"
paulson@13798
   144
by (simp add: Always_eq_includes_reachable, blast)
paulson@13796
   145
paulson@13796
   146
(*Lemma to re-use the argument that one variable increases (progress)
paulson@13796
   147
  while the other variable doesn't decrease (safety)*)
paulson@13796
   148
lemma Follows_Un_lemma:
paulson@13805
   149
     "[| F \<in> Increasing f; F \<in> Increasing g;  
paulson@13805
   150
         F \<in> Increasing g'; F \<in> Always {s. f' s \<le> f s}; 
paulson@13805
   151
         \<forall>k. F \<in> {s. k \<le> f s} LeadsTo {s. k \<le> f' s} |] 
paulson@13805
   152
      ==> F \<in> {s. k \<le> f s \<union> g s} LeadsTo {s. k \<le> f' s \<union> g s}"
paulson@13796
   153
apply (rule single_LeadsTo_I)
paulson@13796
   154
apply (drule_tac x = "f s" in IncreasingD)
paulson@13796
   155
apply (drule_tac x = "g s" in IncreasingD)
paulson@13796
   156
apply (rule LeadsTo_weaken)
paulson@13796
   157
apply (rule PSP_Stable)
paulson@13796
   158
apply (erule_tac x = "f s" in spec)
paulson@13812
   159
apply (erule Stable_Int, assumption, blast+)
paulson@13796
   160
done
paulson@13796
   161
paulson@13796
   162
lemma Follows_Un: 
paulson@13805
   163
    "[| F \<in> f' Fols f;  F \<in> g' Fols g |]  
paulson@13805
   164
     ==> F \<in> (%s. (f' s) \<union> (g' s)) Fols (%s. (f s) \<union> (g s))"
paulson@13796
   165
apply (unfold Follows_def)
paulson@13796
   166
apply (simp add: Increasing_Un Always_Un, auto)
paulson@13796
   167
apply (rule LeadsTo_Trans)
paulson@13796
   168
apply (blast intro: Follows_Un_lemma)
paulson@13796
   169
(*Weakening is used to exchange Un's arguments*)
paulson@13796
   170
apply (blast intro: Follows_Un_lemma [THEN LeadsTo_weaken])
paulson@13796
   171
done
paulson@13796
   172
paulson@13796
   173
paulson@13798
   174
subsection{*Multiset union properties (with the multiset ordering)*}
paulson@13796
   175
paulson@13796
   176
lemma increasing_union: 
paulson@13805
   177
    "[| F \<in> increasing f;  F \<in> increasing g |]  
paulson@13805
   178
     ==> F \<in> increasing (%s. (f s) + (g s :: ('a::order) multiset))"
paulson@13796
   179
apply (unfold increasing_def stable_def constrains_def, auto)
paulson@13796
   180
apply (drule_tac x = "f xa" in spec)
paulson@13796
   181
apply (drule_tac x = "g xa" in spec)
paulson@13796
   182
apply (drule bspec, assumption) 
paulson@13796
   183
apply (blast intro: union_le_mono order_trans)
paulson@13796
   184
done
paulson@13796
   185
paulson@13796
   186
lemma Increasing_union: 
paulson@13805
   187
    "[| F \<in> Increasing f;  F \<in> Increasing g |]  
paulson@13805
   188
     ==> F \<in> Increasing (%s. (f s) + (g s :: ('a::order) multiset))"
paulson@13798
   189
apply (auto simp add: Increasing_def Stable_def Constrains_def
paulson@13798
   190
                      stable_def constrains_def)
paulson@13796
   191
apply (drule_tac x = "f xa" in spec)
paulson@13796
   192
apply (drule_tac x = "g xa" in spec)
paulson@13796
   193
apply (drule bspec, assumption) 
paulson@13796
   194
apply (blast intro: union_le_mono order_trans)
paulson@13796
   195
done
paulson@13796
   196
paulson@13796
   197
lemma Always_union:
paulson@13805
   198
     "[| F \<in> Always {s. f' s \<le> f s}; F \<in> Always {s. g' s \<le> g s} |]  
paulson@13805
   199
      ==> F \<in> Always {s. f' s + g' s \<le> f s + (g s :: ('a::order) multiset)}"
paulson@13796
   200
apply (simp add: Always_eq_includes_reachable)
paulson@13796
   201
apply (blast intro: union_le_mono)
paulson@13796
   202
done
paulson@13796
   203
paulson@13796
   204
(*Except the last line, IDENTICAL to the proof script for Follows_Un_lemma*)
paulson@13796
   205
lemma Follows_union_lemma:
paulson@13805
   206
     "[| F \<in> Increasing f; F \<in> Increasing g;  
paulson@13805
   207
         F \<in> Increasing g'; F \<in> Always {s. f' s \<le> f s}; 
paulson@13805
   208
         \<forall>k::('a::order) multiset.  
paulson@13805
   209
           F \<in> {s. k \<le> f s} LeadsTo {s. k \<le> f' s} |] 
paulson@13805
   210
      ==> F \<in> {s. k \<le> f s + g s} LeadsTo {s. k \<le> f' s + g s}"
paulson@13796
   211
apply (rule single_LeadsTo_I)
paulson@13796
   212
apply (drule_tac x = "f s" in IncreasingD)
paulson@13796
   213
apply (drule_tac x = "g s" in IncreasingD)
paulson@13796
   214
apply (rule LeadsTo_weaken)
paulson@13796
   215
apply (rule PSP_Stable)
paulson@13796
   216
apply (erule_tac x = "f s" in spec)
paulson@13812
   217
apply (erule Stable_Int, assumption, blast)
paulson@13796
   218
apply (blast intro: union_le_mono order_trans)
paulson@13796
   219
done
paulson@13796
   220
paulson@13796
   221
(*The !! is there to influence to effect of permutative rewriting at the end*)
paulson@13796
   222
lemma Follows_union: 
paulson@13796
   223
     "!!g g' ::'b => ('a::order) multiset.  
paulson@13805
   224
        [| F \<in> f' Fols f;  F \<in> g' Fols g |]  
paulson@13805
   225
        ==> F \<in> (%s. (f' s) + (g' s)) Fols (%s. (f s) + (g s))"
paulson@13796
   226
apply (unfold Follows_def)
paulson@13796
   227
apply (simp add: Increasing_union Always_union, auto)
paulson@13796
   228
apply (rule LeadsTo_Trans)
paulson@13796
   229
apply (blast intro: Follows_union_lemma)
paulson@13796
   230
(*now exchange union's arguments*)
paulson@13796
   231
apply (simp add: union_commute)
paulson@13796
   232
apply (blast intro: Follows_union_lemma)
paulson@13796
   233
done
paulson@13796
   234
paulson@13796
   235
lemma Follows_setsum:
paulson@13796
   236
     "!!f ::['c,'b] => ('a::order) multiset.  
paulson@13805
   237
        [| \<forall>i \<in> I. F \<in> f' i Fols f i;  finite I |]  
paulson@13805
   238
        ==> F \<in> (%s. \<Sum>i \<in> I. f' i s) Fols (%s. \<Sum>i \<in> I. f i s)"
paulson@13796
   239
apply (erule rev_mp)
paulson@13796
   240
apply (erule finite_induct, simp) 
paulson@13796
   241
apply (simp add: Follows_union)
paulson@13796
   242
done
paulson@13796
   243
paulson@13796
   244
paulson@13796
   245
(*Currently UNUSED, but possibly of interest*)
paulson@13796
   246
lemma Increasing_imp_Stable_pfixGe:
paulson@13805
   247
     "F \<in> Increasing func ==> F \<in> Stable {s. h pfixGe (func s)}"
paulson@13796
   248
apply (simp add: Increasing_def Stable_def Constrains_def constrains_def)
paulson@13796
   249
apply (blast intro: trans_Ge [THEN trans_genPrefix, THEN transD] 
paulson@13796
   250
                    prefix_imp_pfixGe)
paulson@13796
   251
done
paulson@13796
   252
paulson@13796
   253
(*Currently UNUSED, but possibly of interest*)
paulson@13796
   254
lemma LeadsTo_le_imp_pfixGe:
paulson@13805
   255
     "\<forall>z. F \<in> {s. z \<le> f s} LeadsTo {s. z \<le> g s}  
paulson@13805
   256
      ==> F \<in> {s. z pfixGe f s} LeadsTo {s. z pfixGe g s}"
paulson@13796
   257
apply (rule single_LeadsTo_I)
paulson@13796
   258
apply (drule_tac x = "f s" in spec)
paulson@13796
   259
apply (erule LeadsTo_weaken)
paulson@13796
   260
 prefer 2
paulson@13796
   261
 apply (blast intro: trans_Ge [THEN trans_genPrefix, THEN transD] 
paulson@13796
   262
                     prefix_imp_pfixGe, blast)
paulson@13796
   263
done
paulson@13796
   264
paulson@6706
   265
end