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