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