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