src/HOL/UNITY/Follows.thy
author paulson
Tue Feb 04 18:12:40 2003 +0100 (2003-02-04)
changeset 13805 3786b2fd6808
parent 13798 4c1a53627500
child 13812 91713a1915ee
permissions -rw-r--r--
some x-symbols
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@13796
    65
apply (unfold Follows_def, blast)
paulson@13796
    66
done
paulson@13796
    67
paulson@13805
    68
lemma Follows_Increasing2: "F \<in> f Fols g ==> F \<in> Increasing g"
paulson@13796
    69
apply (unfold Follows_def, blast)
paulson@13796
    70
done
paulson@13796
    71
paulson@13805
    72
lemma Follows_Bounded: "F \<in> f Fols g ==> F \<in> Always {s. f s \<subseteq> g s}"
paulson@13796
    73
apply (unfold Follows_def, blast)
paulson@13796
    74
done
paulson@13796
    75
paulson@13796
    76
lemma Follows_LeadsTo: 
paulson@13805
    77
     "F \<in> f Fols g ==> F \<in> {s. k \<le> g s} LeadsTo {s. k \<le> f s}"
paulson@13798
    78
by (unfold Follows_def, blast)
paulson@13796
    79
paulson@13796
    80
lemma Follows_LeadsTo_pfixLe:
paulson@13805
    81
     "F \<in> f Fols g ==> F \<in> {s. k pfixLe g s} LeadsTo {s. k pfixLe 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: pfixLe_trans prefix_imp_pfixLe)
paulson@13796
    87
done
paulson@13796
    88
paulson@13796
    89
lemma Follows_LeadsTo_pfixGe:
paulson@13805
    90
     "F \<in> f Fols g ==> F \<in> {s. k pfixGe g s} LeadsTo {s. k pfixGe f s}"
paulson@13796
    91
apply (rule single_LeadsTo_I, clarify)
paulson@13796
    92
apply (drule_tac k="g s" in Follows_LeadsTo)
paulson@13796
    93
apply (erule LeadsTo_weaken)
paulson@13796
    94
 apply blast 
paulson@13796
    95
apply (blast intro: pfixGe_trans prefix_imp_pfixGe)
paulson@13796
    96
done
paulson@13796
    97
paulson@13796
    98
paulson@13796
    99
lemma Always_Follows1: 
paulson@13805
   100
     "[| F \<in> Always {s. f s = f' s}; F \<in> f Fols g |] ==> F \<in> f' Fols g"
paulson@13796
   101
paulson@13796
   102
apply (unfold Follows_def Increasing_def Stable_def, auto)
paulson@13796
   103
apply (erule_tac [3] Always_LeadsTo_weaken)
paulson@13805
   104
apply (erule_tac A = "{s. z \<le> f s}" and A' = "{s. z \<le> f s}" 
paulson@13798
   105
       in Always_Constrains_weaken, auto)
paulson@13796
   106
apply (drule Always_Int_I, assumption)
paulson@13796
   107
apply (force intro: Always_weaken)
paulson@13796
   108
done
paulson@13796
   109
paulson@13796
   110
lemma Always_Follows2: 
paulson@13805
   111
     "[| F \<in> Always {s. g s = g' s}; F \<in> f Fols g |] ==> F \<in> f Fols g'"
paulson@13796
   112
apply (unfold Follows_def Increasing_def Stable_def, auto)
paulson@13796
   113
apply (erule_tac [3] Always_LeadsTo_weaken)
paulson@13805
   114
apply (erule_tac A = "{s. z \<le> g s}" and A' = "{s. z \<le> g s}"
paulson@13798
   115
       in Always_Constrains_weaken, auto)
paulson@13796
   116
apply (drule Always_Int_I, assumption)
paulson@13796
   117
apply (force intro: Always_weaken)
paulson@13796
   118
done
paulson@13796
   119
paulson@13796
   120
paulson@13798
   121
subsection{*Union properties (with the subset ordering)*}
paulson@13796
   122
paulson@13796
   123
(*Can replace "Un" by any sup.  But existing max only works for linorders.*)
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@13796
   127
apply (unfold increasing_def stable_def constrains_def, auto)
paulson@13796
   128
apply (drule_tac x = "f xa" in spec)
paulson@13796
   129
apply (drule_tac x = "g xa" in spec)
paulson@13796
   130
apply (blast dest!: bspec)
paulson@13796
   131
done
paulson@13796
   132
paulson@13796
   133
lemma Increasing_Un: 
paulson@13805
   134
    "[| F \<in> Increasing f;  F \<in> Increasing g |]  
paulson@13805
   135
     ==> F \<in> Increasing (%s. (f s) \<union> (g s))"
paulson@13798
   136
apply (auto simp add: Increasing_def Stable_def Constrains_def
paulson@13798
   137
                      stable_def constrains_def)
paulson@13796
   138
apply (drule_tac x = "f xa" in spec)
paulson@13796
   139
apply (drule_tac x = "g xa" in spec)
paulson@13796
   140
apply (blast dest!: bspec)
paulson@13796
   141
done
paulson@13796
   142
paulson@13796
   143
paulson@13796
   144
lemma Always_Un:
paulson@13805
   145
     "[| F \<in> Always {s. f' s \<le> f s}; F \<in> Always {s. g' s \<le> g s} |]  
paulson@13805
   146
      ==> F \<in> Always {s. f' s \<union> g' s \<le> f s \<union> g s}"
paulson@13798
   147
by (simp add: Always_eq_includes_reachable, blast)
paulson@13796
   148
paulson@13796
   149
(*Lemma to re-use the argument that one variable increases (progress)
paulson@13796
   150
  while the other variable doesn't decrease (safety)*)
paulson@13796
   151
lemma Follows_Un_lemma:
paulson@13805
   152
     "[| F \<in> Increasing f; F \<in> Increasing g;  
paulson@13805
   153
         F \<in> Increasing g'; F \<in> Always {s. f' s \<le> f s}; 
paulson@13805
   154
         \<forall>k. F \<in> {s. k \<le> f s} LeadsTo {s. k \<le> f' s} |] 
paulson@13805
   155
      ==> F \<in> {s. k \<le> f s \<union> g s} LeadsTo {s. k \<le> f' s \<union> g s}"
paulson@13796
   156
apply (rule single_LeadsTo_I)
paulson@13796
   157
apply (drule_tac x = "f s" in IncreasingD)
paulson@13796
   158
apply (drule_tac x = "g s" in IncreasingD)
paulson@13796
   159
apply (rule LeadsTo_weaken)
paulson@13796
   160
apply (rule PSP_Stable)
paulson@13796
   161
apply (erule_tac x = "f s" in spec)
paulson@13796
   162
apply (erule Stable_Int, assumption)
paulson@13798
   163
apply blast+
paulson@13796
   164
done
paulson@13796
   165
paulson@13796
   166
lemma Follows_Un: 
paulson@13805
   167
    "[| F \<in> f' Fols f;  F \<in> g' Fols g |]  
paulson@13805
   168
     ==> F \<in> (%s. (f' s) \<union> (g' s)) Fols (%s. (f s) \<union> (g s))"
paulson@13796
   169
apply (unfold Follows_def)
paulson@13796
   170
apply (simp add: Increasing_Un Always_Un, auto)
paulson@13796
   171
apply (rule LeadsTo_Trans)
paulson@13796
   172
apply (blast intro: Follows_Un_lemma)
paulson@13796
   173
(*Weakening is used to exchange Un's arguments*)
paulson@13796
   174
apply (blast intro: Follows_Un_lemma [THEN LeadsTo_weaken])
paulson@13796
   175
done
paulson@13796
   176
paulson@13796
   177
paulson@13798
   178
subsection{*Multiset union properties (with the multiset ordering)*}
paulson@13796
   179
paulson@13796
   180
lemma increasing_union: 
paulson@13805
   181
    "[| F \<in> increasing f;  F \<in> increasing g |]  
paulson@13805
   182
     ==> F \<in> increasing (%s. (f s) + (g s :: ('a::order) multiset))"
paulson@13796
   183
apply (unfold increasing_def stable_def constrains_def, auto)
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) 
paulson@13796
   187
apply (blast intro: union_le_mono order_trans)
paulson@13796
   188
done
paulson@13796
   189
paulson@13796
   190
lemma Increasing_union: 
paulson@13805
   191
    "[| F \<in> Increasing f;  F \<in> Increasing g |]  
paulson@13805
   192
     ==> F \<in> Increasing (%s. (f s) + (g s :: ('a::order) multiset))"
paulson@13798
   193
apply (auto simp add: Increasing_def Stable_def Constrains_def
paulson@13798
   194
                      stable_def constrains_def)
paulson@13796
   195
apply (drule_tac x = "f xa" in spec)
paulson@13796
   196
apply (drule_tac x = "g xa" in spec)
paulson@13796
   197
apply (drule bspec, assumption) 
paulson@13796
   198
apply (blast intro: union_le_mono order_trans)
paulson@13796
   199
done
paulson@13796
   200
paulson@13796
   201
lemma Always_union:
paulson@13805
   202
     "[| F \<in> Always {s. f' s \<le> f s}; F \<in> Always {s. g' s \<le> g s} |]  
paulson@13805
   203
      ==> F \<in> Always {s. f' s + g' s \<le> f s + (g s :: ('a::order) multiset)}"
paulson@13796
   204
apply (simp add: Always_eq_includes_reachable)
paulson@13796
   205
apply (blast intro: union_le_mono)
paulson@13796
   206
done
paulson@13796
   207
paulson@13796
   208
(*Except the last line, IDENTICAL to the proof script for Follows_Un_lemma*)
paulson@13796
   209
lemma Follows_union_lemma:
paulson@13805
   210
     "[| F \<in> Increasing f; F \<in> Increasing g;  
paulson@13805
   211
         F \<in> Increasing g'; F \<in> Always {s. f' s \<le> f s}; 
paulson@13805
   212
         \<forall>k::('a::order) multiset.  
paulson@13805
   213
           F \<in> {s. k \<le> f s} LeadsTo {s. k \<le> f' s} |] 
paulson@13805
   214
      ==> F \<in> {s. k \<le> f s + g s} LeadsTo {s. k \<le> f' s + g s}"
paulson@13796
   215
apply (rule single_LeadsTo_I)
paulson@13796
   216
apply (drule_tac x = "f s" in IncreasingD)
paulson@13796
   217
apply (drule_tac x = "g s" in IncreasingD)
paulson@13796
   218
apply (rule LeadsTo_weaken)
paulson@13796
   219
apply (rule PSP_Stable)
paulson@13796
   220
apply (erule_tac x = "f s" in spec)
paulson@13796
   221
apply (erule Stable_Int, assumption)
paulson@13796
   222
apply blast
paulson@13796
   223
apply (blast intro: union_le_mono order_trans)
paulson@13796
   224
done
paulson@13796
   225
paulson@13796
   226
(*The !! is there to influence to effect of permutative rewriting at the end*)
paulson@13796
   227
lemma Follows_union: 
paulson@13796
   228
     "!!g g' ::'b => ('a::order) multiset.  
paulson@13805
   229
        [| F \<in> f' Fols f;  F \<in> g' Fols g |]  
paulson@13805
   230
        ==> F \<in> (%s. (f' s) + (g' s)) Fols (%s. (f s) + (g s))"
paulson@13796
   231
apply (unfold Follows_def)
paulson@13796
   232
apply (simp add: Increasing_union Always_union, auto)
paulson@13796
   233
apply (rule LeadsTo_Trans)
paulson@13796
   234
apply (blast intro: Follows_union_lemma)
paulson@13796
   235
(*now exchange union's arguments*)
paulson@13796
   236
apply (simp add: union_commute)
paulson@13796
   237
apply (blast intro: Follows_union_lemma)
paulson@13796
   238
done
paulson@13796
   239
paulson@13796
   240
lemma Follows_setsum:
paulson@13796
   241
     "!!f ::['c,'b] => ('a::order) multiset.  
paulson@13805
   242
        [| \<forall>i \<in> I. F \<in> f' i Fols f i;  finite I |]  
paulson@13805
   243
        ==> F \<in> (%s. \<Sum>i \<in> I. f' i s) Fols (%s. \<Sum>i \<in> I. f i s)"
paulson@13796
   244
apply (erule rev_mp)
paulson@13796
   245
apply (erule finite_induct, simp) 
paulson@13796
   246
apply (simp add: Follows_union)
paulson@13796
   247
done
paulson@13796
   248
paulson@13796
   249
paulson@13796
   250
(*Currently UNUSED, but possibly of interest*)
paulson@13796
   251
lemma Increasing_imp_Stable_pfixGe:
paulson@13805
   252
     "F \<in> Increasing func ==> F \<in> Stable {s. h pfixGe (func s)}"
paulson@13796
   253
apply (simp add: Increasing_def Stable_def Constrains_def constrains_def)
paulson@13796
   254
apply (blast intro: trans_Ge [THEN trans_genPrefix, THEN transD] 
paulson@13796
   255
                    prefix_imp_pfixGe)
paulson@13796
   256
done
paulson@13796
   257
paulson@13796
   258
(*Currently UNUSED, but possibly of interest*)
paulson@13796
   259
lemma LeadsTo_le_imp_pfixGe:
paulson@13805
   260
     "\<forall>z. F \<in> {s. z \<le> f s} LeadsTo {s. z \<le> g s}  
paulson@13805
   261
      ==> F \<in> {s. z pfixGe f s} LeadsTo {s. z pfixGe g s}"
paulson@13796
   262
apply (rule single_LeadsTo_I)
paulson@13796
   263
apply (drule_tac x = "f s" in spec)
paulson@13796
   264
apply (erule LeadsTo_weaken)
paulson@13796
   265
 prefer 2
paulson@13796
   266
 apply (blast intro: trans_Ge [THEN trans_genPrefix, THEN transD] 
paulson@13796
   267
                     prefix_imp_pfixGe, blast)
paulson@13796
   268
done
paulson@13796
   269
paulson@6706
   270
end