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