src/HOLCF/Porder.thy
author huffman
Tue Oct 12 06:20:05 2010 -0700 (2010-10-12)
changeset 40006 116e94f9543b
parent 40000 9c6ad000dc89
child 40430 483a4876e428
permissions -rw-r--r--
remove unneeded lemmas from Fun_Cpo.thy
     1 (*  Title:      HOLCF/Porder.thy
     2     Author:     Franz Regensburger and Brian Huffman
     3 *)
     4 
     5 header {* Partial orders *}
     6 
     7 theory Porder
     8 imports Main
     9 begin
    10 
    11 subsection {* Type class for partial orders *}
    12 
    13 class below =
    14   fixes below :: "'a \<Rightarrow> 'a \<Rightarrow> bool"
    15 begin
    16 
    17 notation
    18   below (infixl "<<" 55)
    19 
    20 notation (xsymbols)
    21   below (infixl "\<sqsubseteq>" 55)
    22 
    23 lemma below_eq_trans: "\<lbrakk>a \<sqsubseteq> b; b = c\<rbrakk> \<Longrightarrow> a \<sqsubseteq> c"
    24   by (rule subst)
    25 
    26 lemma eq_below_trans: "\<lbrakk>a = b; b \<sqsubseteq> c\<rbrakk> \<Longrightarrow> a \<sqsubseteq> c"
    27   by (rule ssubst)
    28 
    29 end
    30 
    31 class po = below +
    32   assumes below_refl [iff]: "x \<sqsubseteq> x"
    33   assumes below_trans: "x \<sqsubseteq> y \<Longrightarrow> y \<sqsubseteq> z \<Longrightarrow> x \<sqsubseteq> z"
    34   assumes below_antisym: "x \<sqsubseteq> y \<Longrightarrow> y \<sqsubseteq> x \<Longrightarrow> x = y"
    35 begin
    36 
    37 text {* minimal fixes least element *}
    38 
    39 lemma minimal2UU[OF allI] : "\<forall>x. uu \<sqsubseteq> x \<Longrightarrow> uu = (THE u. \<forall>y. u \<sqsubseteq> y)"
    40   by (blast intro: theI2 below_antisym)
    41 
    42 text {* the reverse law of anti-symmetry of @{term "op <<"} *}
    43 (* Is this rule ever useful? *)
    44 lemma below_antisym_inverse: "x = y \<Longrightarrow> x \<sqsubseteq> y \<and> y \<sqsubseteq> x"
    45   by simp
    46 
    47 lemma box_below: "a \<sqsubseteq> b \<Longrightarrow> c \<sqsubseteq> a \<Longrightarrow> b \<sqsubseteq> d \<Longrightarrow> c \<sqsubseteq> d"
    48   by (rule below_trans [OF below_trans])
    49 
    50 lemma po_eq_conv: "x = y \<longleftrightarrow> x \<sqsubseteq> y \<and> y \<sqsubseteq> x"
    51   by (fast intro!: below_antisym)
    52 
    53 lemma rev_below_trans: "y \<sqsubseteq> z \<Longrightarrow> x \<sqsubseteq> y \<Longrightarrow> x \<sqsubseteq> z"
    54   by (rule below_trans)
    55 
    56 lemma not_below2not_eq: "\<not> x \<sqsubseteq> y \<Longrightarrow> x \<noteq> y"
    57   by auto
    58 
    59 end
    60 
    61 lemmas HOLCF_trans_rules [trans] =
    62   below_trans
    63   below_antisym
    64   below_eq_trans
    65   eq_below_trans
    66 
    67 context po
    68 begin
    69 
    70 subsection {* Upper bounds *}
    71 
    72 definition is_ub :: "'a set \<Rightarrow> 'a \<Rightarrow> bool" (infixl "<|" 55) where
    73   "S <| x \<longleftrightarrow> (\<forall>y\<in>S. y \<sqsubseteq> x)"
    74 
    75 lemma is_ubI: "(\<And>x. x \<in> S \<Longrightarrow> x \<sqsubseteq> u) \<Longrightarrow> S <| u"
    76   by (simp add: is_ub_def)
    77 
    78 lemma is_ubD: "\<lbrakk>S <| u; x \<in> S\<rbrakk> \<Longrightarrow> x \<sqsubseteq> u"
    79   by (simp add: is_ub_def)
    80 
    81 lemma ub_imageI: "(\<And>x. x \<in> S \<Longrightarrow> f x \<sqsubseteq> u) \<Longrightarrow> (\<lambda>x. f x) ` S <| u"
    82   unfolding is_ub_def by fast
    83 
    84 lemma ub_imageD: "\<lbrakk>f ` S <| u; x \<in> S\<rbrakk> \<Longrightarrow> f x \<sqsubseteq> u"
    85   unfolding is_ub_def by fast
    86 
    87 lemma ub_rangeI: "(\<And>i. S i \<sqsubseteq> x) \<Longrightarrow> range S <| x"
    88   unfolding is_ub_def by fast
    89 
    90 lemma ub_rangeD: "range S <| x \<Longrightarrow> S i \<sqsubseteq> x"
    91   unfolding is_ub_def by fast
    92 
    93 lemma is_ub_empty [simp]: "{} <| u"
    94   unfolding is_ub_def by fast
    95 
    96 lemma is_ub_insert [simp]: "(insert x A) <| y = (x \<sqsubseteq> y \<and> A <| y)"
    97   unfolding is_ub_def by fast
    98 
    99 lemma is_ub_upward: "\<lbrakk>S <| x; x \<sqsubseteq> y\<rbrakk> \<Longrightarrow> S <| y"
   100   unfolding is_ub_def by (fast intro: below_trans)
   101 
   102 subsection {* Least upper bounds *}
   103 
   104 definition is_lub :: "'a set \<Rightarrow> 'a \<Rightarrow> bool" (infixl "<<|" 55) where
   105   "S <<| x \<longleftrightarrow> S <| x \<and> (\<forall>u. S <| u \<longrightarrow> x \<sqsubseteq> u)"
   106 
   107 definition lub :: "'a set \<Rightarrow> 'a" where
   108   "lub S = (THE x. S <<| x)"
   109 
   110 end
   111 
   112 syntax
   113   "_BLub" :: "[pttrn, 'a set, 'b] \<Rightarrow> 'b" ("(3LUB _:_./ _)" [0,0, 10] 10)
   114 
   115 syntax (xsymbols)
   116   "_BLub" :: "[pttrn, 'a set, 'b] \<Rightarrow> 'b" ("(3\<Squnion>_\<in>_./ _)" [0,0, 10] 10)
   117 
   118 translations
   119   "LUB x:A. t" == "CONST lub ((%x. t) ` A)"
   120 
   121 context po
   122 begin
   123 
   124 abbreviation
   125   Lub  (binder "LUB " 10) where
   126   "LUB n. t n == lub (range t)"
   127 
   128 notation (xsymbols)
   129   Lub  (binder "\<Squnion> " 10)
   130 
   131 text {* access to some definition as inference rule *}
   132 
   133 lemma is_lubD1: "S <<| x \<Longrightarrow> S <| x"
   134   unfolding is_lub_def by fast
   135 
   136 lemma is_lub_lub: "\<lbrakk>S <<| x; S <| u\<rbrakk> \<Longrightarrow> x \<sqsubseteq> u"
   137   unfolding is_lub_def by fast
   138 
   139 lemma is_lubI: "\<lbrakk>S <| x; \<And>u. S <| u \<Longrightarrow> x \<sqsubseteq> u\<rbrakk> \<Longrightarrow> S <<| x"
   140   unfolding is_lub_def by fast
   141 
   142 lemma is_lub_below_iff: "S <<| x \<Longrightarrow> x \<sqsubseteq> u \<longleftrightarrow> S <| u"
   143   unfolding is_lub_def is_ub_def by (metis below_trans)
   144 
   145 text {* lubs are unique *}
   146 
   147 lemma unique_lub: "\<lbrakk>S <<| x; S <<| y\<rbrakk> \<Longrightarrow> x = y"
   148 apply (unfold is_lub_def is_ub_def)
   149 apply (blast intro: below_antisym)
   150 done
   151 
   152 text {* technical lemmas about @{term lub} and @{term is_lub} *}
   153 
   154 lemma lubI: "M <<| x \<Longrightarrow> M <<| lub M"
   155 apply (unfold lub_def)
   156 apply (rule theI)
   157 apply assumption
   158 apply (erule (1) unique_lub)
   159 done
   160 
   161 lemma thelubI: "M <<| l \<Longrightarrow> lub M = l"
   162   by (rule unique_lub [OF lubI])
   163 
   164 lemma is_lub_singleton: "{x} <<| x"
   165   by (simp add: is_lub_def)
   166 
   167 lemma lub_singleton [simp]: "lub {x} = x"
   168   by (rule thelubI [OF is_lub_singleton])
   169 
   170 lemma is_lub_bin: "x \<sqsubseteq> y \<Longrightarrow> {x, y} <<| y"
   171   by (simp add: is_lub_def)
   172 
   173 lemma lub_bin: "x \<sqsubseteq> y \<Longrightarrow> lub {x, y} = y"
   174   by (rule is_lub_bin [THEN thelubI])
   175 
   176 lemma is_lub_maximal: "\<lbrakk>S <| x; x \<in> S\<rbrakk> \<Longrightarrow> S <<| x"
   177   by (erule is_lubI, erule (1) is_ubD)
   178 
   179 lemma lub_maximal: "\<lbrakk>S <| x; x \<in> S\<rbrakk> \<Longrightarrow> lub S = x"
   180   by (rule is_lub_maximal [THEN thelubI])
   181 
   182 subsection {* Countable chains *}
   183 
   184 definition chain :: "(nat \<Rightarrow> 'a) \<Rightarrow> bool" where
   185   -- {* Here we use countable chains and I prefer to code them as functions! *}
   186   "chain Y = (\<forall>i. Y i \<sqsubseteq> Y (Suc i))"
   187 
   188 lemma chainI: "(\<And>i. Y i \<sqsubseteq> Y (Suc i)) \<Longrightarrow> chain Y"
   189   unfolding chain_def by fast
   190 
   191 lemma chainE: "chain Y \<Longrightarrow> Y i \<sqsubseteq> Y (Suc i)"
   192   unfolding chain_def by fast
   193 
   194 text {* chains are monotone functions *}
   195 
   196 lemma chain_mono_less: "\<lbrakk>chain Y; i < j\<rbrakk> \<Longrightarrow> Y i \<sqsubseteq> Y j"
   197   by (erule less_Suc_induct, erule chainE, erule below_trans)
   198 
   199 lemma chain_mono: "\<lbrakk>chain Y; i \<le> j\<rbrakk> \<Longrightarrow> Y i \<sqsubseteq> Y j"
   200   by (cases "i = j", simp, simp add: chain_mono_less)
   201 
   202 lemma chain_shift: "chain Y \<Longrightarrow> chain (\<lambda>i. Y (i + j))"
   203   by (rule chainI, simp, erule chainE)
   204 
   205 text {* technical lemmas about (least) upper bounds of chains *}
   206 
   207 lemma is_ub_lub: "range S <<| x \<Longrightarrow> S i \<sqsubseteq> x"
   208   by (rule is_lubD1 [THEN ub_rangeD])
   209 
   210 lemma is_ub_range_shift:
   211   "chain S \<Longrightarrow> range (\<lambda>i. S (i + j)) <| x = range S <| x"
   212 apply (rule iffI)
   213 apply (rule ub_rangeI)
   214 apply (rule_tac y="S (i + j)" in below_trans)
   215 apply (erule chain_mono)
   216 apply (rule le_add1)
   217 apply (erule ub_rangeD)
   218 apply (rule ub_rangeI)
   219 apply (erule ub_rangeD)
   220 done
   221 
   222 lemma is_lub_range_shift:
   223   "chain S \<Longrightarrow> range (\<lambda>i. S (i + j)) <<| x = range S <<| x"
   224   by (simp add: is_lub_def is_ub_range_shift)
   225 
   226 text {* the lub of a constant chain is the constant *}
   227 
   228 lemma chain_const [simp]: "chain (\<lambda>i. c)"
   229   by (simp add: chainI)
   230 
   231 lemma lub_const: "range (\<lambda>x. c) <<| c"
   232 by (blast dest: ub_rangeD intro: is_lubI ub_rangeI)
   233 
   234 lemma thelub_const [simp]: "(\<Squnion>i. c) = c"
   235   by (rule lub_const [THEN thelubI])
   236 
   237 subsection {* Finite chains *}
   238 
   239 definition max_in_chain :: "nat \<Rightarrow> (nat \<Rightarrow> 'a) \<Rightarrow> bool" where
   240   -- {* finite chains, needed for monotony of continuous functions *}
   241   "max_in_chain i C \<longleftrightarrow> (\<forall>j. i \<le> j \<longrightarrow> C i = C j)"
   242 
   243 definition finite_chain :: "(nat \<Rightarrow> 'a) \<Rightarrow> bool" where
   244   "finite_chain C = (chain C \<and> (\<exists>i. max_in_chain i C))"
   245 
   246 text {* results about finite chains *}
   247 
   248 lemma max_in_chainI: "(\<And>j. i \<le> j \<Longrightarrow> Y i = Y j) \<Longrightarrow> max_in_chain i Y"
   249   unfolding max_in_chain_def by fast
   250 
   251 lemma max_in_chainD: "\<lbrakk>max_in_chain i Y; i \<le> j\<rbrakk> \<Longrightarrow> Y i = Y j"
   252   unfolding max_in_chain_def by fast
   253 
   254 lemma finite_chainI:
   255   "\<lbrakk>chain C; max_in_chain i C\<rbrakk> \<Longrightarrow> finite_chain C"
   256   unfolding finite_chain_def by fast
   257 
   258 lemma finite_chainE:
   259   "\<lbrakk>finite_chain C; \<And>i. \<lbrakk>chain C; max_in_chain i C\<rbrakk> \<Longrightarrow> R\<rbrakk> \<Longrightarrow> R"
   260   unfolding finite_chain_def by fast
   261 
   262 lemma lub_finch1: "\<lbrakk>chain C; max_in_chain i C\<rbrakk> \<Longrightarrow> range C <<| C i"
   263 apply (rule is_lubI)
   264 apply (rule ub_rangeI, rename_tac j)
   265 apply (rule_tac x=i and y=j in linorder_le_cases)
   266 apply (drule (1) max_in_chainD, simp)
   267 apply (erule (1) chain_mono)
   268 apply (erule ub_rangeD)
   269 done
   270 
   271 lemma lub_finch2:
   272   "finite_chain C \<Longrightarrow> range C <<| C (LEAST i. max_in_chain i C)"
   273 apply (erule finite_chainE)
   274 apply (erule LeastI2 [where Q="\<lambda>i. range C <<| C i"])
   275 apply (erule (1) lub_finch1)
   276 done
   277 
   278 lemma finch_imp_finite_range: "finite_chain Y \<Longrightarrow> finite (range Y)"
   279  apply (erule finite_chainE)
   280  apply (rule_tac B="Y ` {..i}" in finite_subset)
   281   apply (rule subsetI)
   282   apply (erule rangeE, rename_tac j)
   283   apply (rule_tac x=i and y=j in linorder_le_cases)
   284    apply (subgoal_tac "Y j = Y i", simp)
   285    apply (simp add: max_in_chain_def)
   286   apply simp
   287  apply simp
   288 done
   289 
   290 lemma finite_range_has_max:
   291   fixes f :: "nat \<Rightarrow> 'a" and r :: "'a \<Rightarrow> 'a \<Rightarrow> bool"
   292   assumes mono: "\<And>i j. i \<le> j \<Longrightarrow> r (f i) (f j)"
   293   assumes finite_range: "finite (range f)"
   294   shows "\<exists>k. \<forall>i. r (f i) (f k)"
   295 proof (intro exI allI)
   296   fix i :: nat
   297   let ?j = "LEAST k. f k = f i"
   298   let ?k = "Max ((\<lambda>x. LEAST k. f k = x) ` range f)"
   299   have "?j \<le> ?k"
   300   proof (rule Max_ge)
   301     show "finite ((\<lambda>x. LEAST k. f k = x) ` range f)"
   302       using finite_range by (rule finite_imageI)
   303     show "?j \<in> (\<lambda>x. LEAST k. f k = x) ` range f"
   304       by (intro imageI rangeI)
   305   qed
   306   hence "r (f ?j) (f ?k)"
   307     by (rule mono)
   308   also have "f ?j = f i"
   309     by (rule LeastI, rule refl)
   310   finally show "r (f i) (f ?k)" .
   311 qed
   312 
   313 lemma finite_range_imp_finch:
   314   "\<lbrakk>chain Y; finite (range Y)\<rbrakk> \<Longrightarrow> finite_chain Y"
   315  apply (subgoal_tac "\<exists>k. \<forall>i. Y i \<sqsubseteq> Y k")
   316   apply (erule exE)
   317   apply (rule finite_chainI, assumption)
   318   apply (rule max_in_chainI)
   319   apply (rule below_antisym)
   320    apply (erule (1) chain_mono)
   321   apply (erule spec)
   322  apply (rule finite_range_has_max)
   323   apply (erule (1) chain_mono)
   324  apply assumption
   325 done
   326 
   327 lemma bin_chain: "x \<sqsubseteq> y \<Longrightarrow> chain (\<lambda>i. if i=0 then x else y)"
   328   by (rule chainI, simp)
   329 
   330 lemma bin_chainmax:
   331   "x \<sqsubseteq> y \<Longrightarrow> max_in_chain (Suc 0) (\<lambda>i. if i=0 then x else y)"
   332   unfolding max_in_chain_def by simp
   333 
   334 lemma lub_bin_chain:
   335   "x \<sqsubseteq> y \<Longrightarrow> range (\<lambda>i::nat. if i=0 then x else y) <<| y"
   336 apply (frule bin_chain)
   337 apply (drule bin_chainmax)
   338 apply (drule (1) lub_finch1)
   339 apply simp
   340 done
   341 
   342 text {* the maximal element in a chain is its lub *}
   343 
   344 lemma lub_chain_maxelem: "\<lbrakk>Y i = c; \<forall>i. Y i \<sqsubseteq> c\<rbrakk> \<Longrightarrow> lub (range Y) = c"
   345   by (blast dest: ub_rangeD intro: thelubI is_lubI ub_rangeI)
   346 
   347 text {* lemmata for improved admissibility introdution rule *}
   348 
   349 lemma infinite_chain_adm_lemma:
   350   "\<lbrakk>chain Y; \<forall>i. P (Y i);  
   351     \<And>Y. \<lbrakk>chain Y; \<forall>i. P (Y i); \<not> finite_chain Y\<rbrakk> \<Longrightarrow> P (\<Squnion>i. Y i)\<rbrakk>
   352       \<Longrightarrow> P (\<Squnion>i. Y i)"
   353 apply (case_tac "finite_chain Y")
   354 prefer 2 apply fast
   355 apply (unfold finite_chain_def)
   356 apply safe
   357 apply (erule lub_finch1 [THEN thelubI, THEN ssubst])
   358 apply assumption
   359 apply (erule spec)
   360 done
   361 
   362 lemma increasing_chain_adm_lemma:
   363   "\<lbrakk>chain Y;  \<forall>i. P (Y i); \<And>Y. \<lbrakk>chain Y; \<forall>i. P (Y i);
   364     \<forall>i. \<exists>j>i. Y i \<noteq> Y j \<and> Y i \<sqsubseteq> Y j\<rbrakk> \<Longrightarrow> P (\<Squnion>i. Y i)\<rbrakk>
   365       \<Longrightarrow> P (\<Squnion>i. Y i)"
   366 apply (erule infinite_chain_adm_lemma)
   367 apply assumption
   368 apply (erule thin_rl)
   369 apply (unfold finite_chain_def)
   370 apply (unfold max_in_chain_def)
   371 apply (fast dest: le_imp_less_or_eq elim: chain_mono_less)
   372 done
   373 
   374 end
   375 
   376 end