src/HOL/UNITY/Follows.thy
author paulson <lp15@cam.ac.uk>
Mon May 23 15:33:24 2016 +0100 (2016-05-23)
changeset 63114 27afe7af7379
parent 62430 9527ff088c15
child 63146 f1ecba0272f9
permissions -rw-r--r--
Lots of new material for multivariate analysis
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
wenzelm@58889
     6
section{*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
haftmann@62430
    39
lemma mono_Follows_o:
haftmann@62430
    40
  assumes "mono h"
haftmann@62430
    41
  shows "f Fols g \<subseteq> (h o f) Fols (h o g)"
haftmann@62430
    42
proof
haftmann@62430
    43
  fix x
haftmann@62430
    44
  assume "x \<in> f Fols g"
haftmann@62430
    45
  with assms show "x \<in> (h \<circ> f) Fols (h \<circ> g)"
haftmann@62430
    46
  by (auto simp add: Follows_def mono_Increasing_o [THEN [2] rev_subsetD]
haftmann@62430
    47
    mono_Always_o [THEN [2] rev_subsetD]
haftmann@62430
    48
    mono_LeadsTo_o [THEN [2] rev_subsetD, THEN INT_D])
haftmann@62430
    49
qed
paulson@13796
    50
paulson@13796
    51
lemma mono_Follows_apply:
paulson@13805
    52
     "mono h ==> f Fols g \<subseteq> (%x. h (f x)) Fols (%x. h (g x))"
paulson@13796
    53
apply (drule mono_Follows_o)
paulson@13796
    54
apply (force simp add: o_def)
paulson@13796
    55
done
paulson@13796
    56
paulson@13796
    57
lemma Follows_trans: 
paulson@13805
    58
     "[| F \<in> f Fols g;  F \<in> g Fols h |] ==> F \<in> f Fols h"
paulson@15102
    59
apply (simp add: Follows_def)
paulson@13796
    60
apply (simp add: Always_eq_includes_reachable)
paulson@13796
    61
apply (blast intro: order_trans LeadsTo_Trans)
paulson@13796
    62
done
paulson@13796
    63
paulson@13796
    64
paulson@13798
    65
subsection{*Destruction rules*}
paulson@13796
    66
paulson@13805
    67
lemma Follows_Increasing1: "F \<in> f Fols g ==> F \<in> Increasing f"
paulson@15102
    68
by (simp add: Follows_def)
paulson@13796
    69
paulson@13805
    70
lemma Follows_Increasing2: "F \<in> f Fols g ==> F \<in> Increasing g"
paulson@15102
    71
by (simp add: Follows_def)
paulson@13796
    72
paulson@21710
    73
lemma Follows_Bounded: "F \<in> f Fols g ==> F \<in> Always {s. f s \<le> g s}"
paulson@15102
    74
by (simp add: Follows_def)
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@15102
    78
by (simp add: Follows_def)
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@15102
   102
apply (simp add: Follows_def Increasing_def Stable_def, auto)
paulson@13796
   103
apply (erule_tac [3] Always_LeadsTo_weaken)
haftmann@56248
   104
apply (erule_tac A = "{s. x \<le> f s}" and A' = "{s. x \<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@15102
   112
apply (simp add: Follows_def Increasing_def Stable_def, auto)
paulson@13796
   113
apply (erule_tac [3] Always_LeadsTo_weaken)
haftmann@56248
   114
apply (erule_tac A = "{s. x \<le> g s}" and A' = "{s. x \<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.*)
haftmann@56248
   124
paulson@13796
   125
lemma increasing_Un: 
paulson@13805
   126
    "[| F \<in> increasing f;  F \<in> increasing g |]  
paulson@13805
   127
     ==> F \<in> increasing (%s. (f s) \<union> (g s))"
paulson@15102
   128
apply (simp add: increasing_def stable_def constrains_def, auto)
haftmann@56248
   129
apply (drule_tac x = "f xb" in spec)
haftmann@56248
   130
apply (drule_tac x = "g xb" in spec)
paulson@13796
   131
apply (blast dest!: bspec)
paulson@13796
   132
done
paulson@13796
   133
paulson@13796
   134
lemma Increasing_Un: 
paulson@13805
   135
    "[| F \<in> Increasing f;  F \<in> Increasing g |]  
paulson@13805
   136
     ==> F \<in> Increasing (%s. (f s) \<union> (g s))"
paulson@13798
   137
apply (auto simp add: Increasing_def Stable_def Constrains_def
paulson@13798
   138
                      stable_def constrains_def)
haftmann@56248
   139
apply (drule_tac x = "f xb" in spec)
haftmann@56248
   140
apply (drule_tac x = "g xb" in spec)
paulson@13796
   141
apply (blast dest!: bspec)
paulson@13796
   142
done
paulson@13796
   143
paulson@13796
   144
paulson@13796
   145
lemma Always_Un:
paulson@13805
   146
     "[| F \<in> Always {s. f' s \<le> f s}; F \<in> Always {s. g' s \<le> g s} |]  
paulson@13805
   147
      ==> F \<in> Always {s. f' s \<union> g' s \<le> f s \<union> g s}"
paulson@13798
   148
by (simp add: Always_eq_includes_reachable, blast)
paulson@13796
   149
paulson@13796
   150
(*Lemma to re-use the argument that one variable increases (progress)
paulson@13796
   151
  while the other variable doesn't decrease (safety)*)
paulson@13796
   152
lemma Follows_Un_lemma:
paulson@13805
   153
     "[| F \<in> Increasing f; F \<in> Increasing g;  
paulson@13805
   154
         F \<in> Increasing g'; F \<in> Always {s. f' s \<le> f s}; 
paulson@13805
   155
         \<forall>k. F \<in> {s. k \<le> f s} LeadsTo {s. k \<le> f' s} |] 
paulson@13805
   156
      ==> F \<in> {s. k \<le> f s \<union> g s} LeadsTo {s. k \<le> f' s \<union> g s}"
paulson@13796
   157
apply (rule single_LeadsTo_I)
paulson@13796
   158
apply (drule_tac x = "f s" in IncreasingD)
paulson@13796
   159
apply (drule_tac x = "g s" in IncreasingD)
paulson@13796
   160
apply (rule LeadsTo_weaken)
paulson@13796
   161
apply (rule PSP_Stable)
paulson@13796
   162
apply (erule_tac x = "f s" in spec)
paulson@13812
   163
apply (erule Stable_Int, assumption, 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))"
haftmann@54859
   169
apply (simp add: Follows_def Increasing_Un Always_Un del: Un_subset_iff sup.bounded_iff, auto)
paulson@13796
   170
apply (rule LeadsTo_Trans)
paulson@13796
   171
apply (blast intro: Follows_Un_lemma)
paulson@13796
   172
(*Weakening is used to exchange Un's arguments*)
paulson@13796
   173
apply (blast intro: Follows_Un_lemma [THEN LeadsTo_weaken])
paulson@13796
   174
done
paulson@13796
   175
paulson@13796
   176
paulson@13798
   177
subsection{*Multiset union properties (with the multiset ordering)*}
Mathias@60397
   178
(*TODO: remove when multiset is of sort ord again*)
Mathias@60397
   179
instantiation multiset :: (order) ordered_ab_semigroup_add
Mathias@60397
   180
begin
Mathias@60397
   181
wenzelm@61076
   182
definition less_multiset :: "'a::order multiset \<Rightarrow> 'a multiset \<Rightarrow> bool" where
haftmann@62430
   183
  "M' < M \<longleftrightarrow> M' #\<subset># M"
Mathias@60397
   184
Mathias@60397
   185
definition less_eq_multiset :: "'a multiset \<Rightarrow> 'a multiset \<Rightarrow> bool" where
haftmann@62430
   186
   "(M'::'a multiset) \<le> M \<longleftrightarrow> M' #\<subseteq># M"
Mathias@60397
   187
Mathias@60397
   188
instance
wenzelm@61169
   189
  by standard (auto simp add: less_eq_multiset_def less_multiset_def multiset_order.less_le_not_le add.commute multiset_order.add_right_mono)
Mathias@60397
   190
end
paulson@13796
   191
paulson@13796
   192
lemma increasing_union: 
paulson@13805
   193
    "[| F \<in> increasing f;  F \<in> increasing g |]  
paulson@13805
   194
     ==> F \<in> increasing (%s. (f s) + (g s :: ('a::order) multiset))"
paulson@15102
   195
apply (simp add: increasing_def stable_def constrains_def, auto)
haftmann@56248
   196
apply (drule_tac x = "f xb" in spec)
haftmann@56248
   197
apply (drule_tac x = "g xb" in spec)
paulson@13796
   198
apply (drule bspec, assumption) 
haftmann@35274
   199
apply (blast intro: add_mono order_trans)
paulson@13796
   200
done
paulson@13796
   201
paulson@13796
   202
lemma Increasing_union: 
paulson@13805
   203
    "[| F \<in> Increasing f;  F \<in> Increasing g |]  
paulson@13805
   204
     ==> F \<in> Increasing (%s. (f s) + (g s :: ('a::order) multiset))"
paulson@13798
   205
apply (auto simp add: Increasing_def Stable_def Constrains_def
paulson@13798
   206
                      stable_def constrains_def)
haftmann@56248
   207
apply (drule_tac x = "f xb" in spec)
haftmann@56248
   208
apply (drule_tac x = "g xb" in spec)
paulson@13796
   209
apply (drule bspec, assumption) 
haftmann@35274
   210
apply (blast intro: add_mono order_trans)
paulson@13796
   211
done
paulson@13796
   212
paulson@13796
   213
lemma Always_union:
paulson@13805
   214
     "[| F \<in> Always {s. f' s \<le> f s}; F \<in> Always {s. g' s \<le> g s} |]  
paulson@13805
   215
      ==> F \<in> Always {s. f' s + g' s \<le> f s + (g s :: ('a::order) multiset)}"
paulson@13796
   216
apply (simp add: Always_eq_includes_reachable)
haftmann@35274
   217
apply (blast intro: add_mono)
paulson@13796
   218
done
paulson@13796
   219
paulson@13796
   220
(*Except the last line, IDENTICAL to the proof script for Follows_Un_lemma*)
paulson@13796
   221
lemma Follows_union_lemma:
paulson@13805
   222
     "[| F \<in> Increasing f; F \<in> Increasing g;  
paulson@13805
   223
         F \<in> Increasing g'; F \<in> Always {s. f' s \<le> f s}; 
paulson@13805
   224
         \<forall>k::('a::order) multiset.  
paulson@13805
   225
           F \<in> {s. k \<le> f s} LeadsTo {s. k \<le> f' s} |] 
paulson@13805
   226
      ==> F \<in> {s. k \<le> f s + g s} LeadsTo {s. k \<le> f' s + g s}"
paulson@13796
   227
apply (rule single_LeadsTo_I)
paulson@13796
   228
apply (drule_tac x = "f s" in IncreasingD)
paulson@13796
   229
apply (drule_tac x = "g s" in IncreasingD)
paulson@13796
   230
apply (rule LeadsTo_weaken)
paulson@13796
   231
apply (rule PSP_Stable)
paulson@13796
   232
apply (erule_tac x = "f s" in spec)
paulson@13812
   233
apply (erule Stable_Int, assumption, blast)
haftmann@35274
   234
apply (blast intro: add_mono order_trans)
paulson@13796
   235
done
paulson@13796
   236
paulson@13796
   237
(*The !! is there to influence to effect of permutative rewriting at the end*)
paulson@13796
   238
lemma Follows_union: 
paulson@13796
   239
     "!!g g' ::'b => ('a::order) multiset.  
paulson@13805
   240
        [| F \<in> f' Fols f;  F \<in> g' Fols g |]  
paulson@13805
   241
        ==> F \<in> (%s. (f' s) + (g' s)) Fols (%s. (f s) + (g s))"
paulson@15102
   242
apply (simp add: Follows_def)
paulson@13796
   243
apply (simp add: Increasing_union Always_union, auto)
paulson@13796
   244
apply (rule LeadsTo_Trans)
paulson@13796
   245
apply (blast intro: Follows_union_lemma)
paulson@13796
   246
(*now exchange union's arguments*)
paulson@13796
   247
apply (simp add: union_commute)
paulson@13796
   248
apply (blast intro: Follows_union_lemma)
paulson@13796
   249
done
paulson@13796
   250
paulson@13796
   251
lemma Follows_setsum:
paulson@13796
   252
     "!!f ::['c,'b] => ('a::order) multiset.  
paulson@13805
   253
        [| \<forall>i \<in> I. F \<in> f' i Fols f i;  finite I |]  
paulson@13805
   254
        ==> F \<in> (%s. \<Sum>i \<in> I. f' i s) Fols (%s. \<Sum>i \<in> I. f i s)"
paulson@13796
   255
apply (erule rev_mp)
paulson@13796
   256
apply (erule finite_induct, simp) 
paulson@13796
   257
apply (simp add: Follows_union)
paulson@13796
   258
done
paulson@13796
   259
paulson@13796
   260
paulson@13796
   261
(*Currently UNUSED, but possibly of interest*)
paulson@13796
   262
lemma Increasing_imp_Stable_pfixGe:
paulson@13805
   263
     "F \<in> Increasing func ==> F \<in> Stable {s. h pfixGe (func s)}"
paulson@13796
   264
apply (simp add: Increasing_def Stable_def Constrains_def constrains_def)
paulson@13796
   265
apply (blast intro: trans_Ge [THEN trans_genPrefix, THEN transD] 
paulson@13796
   266
                    prefix_imp_pfixGe)
paulson@13796
   267
done
paulson@13796
   268
paulson@13796
   269
(*Currently UNUSED, but possibly of interest*)
paulson@13796
   270
lemma LeadsTo_le_imp_pfixGe:
paulson@13805
   271
     "\<forall>z. F \<in> {s. z \<le> f s} LeadsTo {s. z \<le> g s}  
paulson@13805
   272
      ==> F \<in> {s. z pfixGe f s} LeadsTo {s. z pfixGe g s}"
paulson@13796
   273
apply (rule single_LeadsTo_I)
paulson@13796
   274
apply (drule_tac x = "f s" in spec)
paulson@13796
   275
apply (erule LeadsTo_weaken)
paulson@13796
   276
 prefer 2
paulson@13796
   277
 apply (blast intro: trans_Ge [THEN trans_genPrefix, THEN transD] 
paulson@13796
   278
                     prefix_imp_pfixGe, blast)
paulson@13796
   279
done
paulson@13796
   280
paulson@6706
   281
end