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