src/HOLCF/Deflation.thy
author huffman
Wed Feb 17 08:19:46 2010 -0800 (2010-02-17)
changeset 35168 07b3112e464b
parent 33503 3496616b2171
child 35794 8cd7134275cc
permissions -rw-r--r--
fix warnings about duplicate simp rules
     1 (*  Title:      HOLCF/Deflation.thy
     2     Author:     Brian Huffman
     3 *)
     4 
     5 header {* Continuous Deflations and Embedding-Projection Pairs *}
     6 
     7 theory Deflation
     8 imports Cfun
     9 begin
    10 
    11 defaultsort cpo
    12 
    13 subsection {* Continuous deflations *}
    14 
    15 locale deflation =
    16   fixes d :: "'a \<rightarrow> 'a"
    17   assumes idem: "\<And>x. d\<cdot>(d\<cdot>x) = d\<cdot>x"
    18   assumes below: "\<And>x. d\<cdot>x \<sqsubseteq> x"
    19 begin
    20 
    21 lemma below_ID: "d \<sqsubseteq> ID"
    22 by (rule below_cfun_ext, simp add: below)
    23 
    24 text {* The set of fixed points is the same as the range. *}
    25 
    26 lemma fixes_eq_range: "{x. d\<cdot>x = x} = range (\<lambda>x. d\<cdot>x)"
    27 by (auto simp add: eq_sym_conv idem)
    28 
    29 lemma range_eq_fixes: "range (\<lambda>x. d\<cdot>x) = {x. d\<cdot>x = x}"
    30 by (auto simp add: eq_sym_conv idem)
    31 
    32 text {*
    33   The pointwise ordering on deflation functions coincides with
    34   the subset ordering of their sets of fixed-points.
    35 *}
    36 
    37 lemma belowI:
    38   assumes f: "\<And>x. d\<cdot>x = x \<Longrightarrow> f\<cdot>x = x" shows "d \<sqsubseteq> f"
    39 proof (rule below_cfun_ext)
    40   fix x
    41   from below have "f\<cdot>(d\<cdot>x) \<sqsubseteq> f\<cdot>x" by (rule monofun_cfun_arg)
    42   also from idem have "f\<cdot>(d\<cdot>x) = d\<cdot>x" by (rule f)
    43   finally show "d\<cdot>x \<sqsubseteq> f\<cdot>x" .
    44 qed
    45 
    46 lemma belowD: "\<lbrakk>f \<sqsubseteq> d; f\<cdot>x = x\<rbrakk> \<Longrightarrow> d\<cdot>x = x"
    47 proof (rule below_antisym)
    48   from below show "d\<cdot>x \<sqsubseteq> x" .
    49 next
    50   assume "f \<sqsubseteq> d"
    51   hence "f\<cdot>x \<sqsubseteq> d\<cdot>x" by (rule monofun_cfun_fun)
    52   also assume "f\<cdot>x = x"
    53   finally show "x \<sqsubseteq> d\<cdot>x" .
    54 qed
    55 
    56 end
    57 
    58 lemma deflation_strict: "deflation d \<Longrightarrow> d\<cdot>\<bottom> = \<bottom>"
    59 by (rule deflation.below [THEN UU_I])
    60 
    61 lemma adm_deflation: "adm (\<lambda>d. deflation d)"
    62 by (simp add: deflation_def)
    63 
    64 lemma deflation_ID: "deflation ID"
    65 by (simp add: deflation.intro)
    66 
    67 lemma deflation_UU: "deflation \<bottom>"
    68 by (simp add: deflation.intro)
    69 
    70 lemma deflation_below_iff:
    71   "\<lbrakk>deflation p; deflation q\<rbrakk> \<Longrightarrow> p \<sqsubseteq> q \<longleftrightarrow> (\<forall>x. p\<cdot>x = x \<longrightarrow> q\<cdot>x = x)"
    72  apply safe
    73   apply (simp add: deflation.belowD)
    74  apply (simp add: deflation.belowI)
    75 done
    76 
    77 text {*
    78   The composition of two deflations is equal to
    79   the lesser of the two (if they are comparable).
    80 *}
    81 
    82 lemma deflation_below_comp1:
    83   assumes "deflation f"
    84   assumes "deflation g"
    85   shows "f \<sqsubseteq> g \<Longrightarrow> f\<cdot>(g\<cdot>x) = f\<cdot>x"
    86 proof (rule below_antisym)
    87   interpret g: deflation g by fact
    88   from g.below show "f\<cdot>(g\<cdot>x) \<sqsubseteq> f\<cdot>x" by (rule monofun_cfun_arg)
    89 next
    90   interpret f: deflation f by fact
    91   assume "f \<sqsubseteq> g" hence "f\<cdot>x \<sqsubseteq> g\<cdot>x" by (rule monofun_cfun_fun)
    92   hence "f\<cdot>(f\<cdot>x) \<sqsubseteq> f\<cdot>(g\<cdot>x)" by (rule monofun_cfun_arg)
    93   also have "f\<cdot>(f\<cdot>x) = f\<cdot>x" by (rule f.idem)
    94   finally show "f\<cdot>x \<sqsubseteq> f\<cdot>(g\<cdot>x)" .
    95 qed
    96 
    97 lemma deflation_below_comp2:
    98   "\<lbrakk>deflation f; deflation g; f \<sqsubseteq> g\<rbrakk> \<Longrightarrow> g\<cdot>(f\<cdot>x) = f\<cdot>x"
    99 by (simp only: deflation.belowD deflation.idem)
   100 
   101 
   102 subsection {* Deflations with finite range *}
   103 
   104 lemma finite_range_imp_finite_fixes:
   105   "finite (range f) \<Longrightarrow> finite {x. f x = x}"
   106 proof -
   107   have "{x. f x = x} \<subseteq> range f"
   108     by (clarify, erule subst, rule rangeI)
   109   moreover assume "finite (range f)"
   110   ultimately show "finite {x. f x = x}"
   111     by (rule finite_subset)
   112 qed
   113 
   114 locale finite_deflation = deflation +
   115   assumes finite_fixes: "finite {x. d\<cdot>x = x}"
   116 begin
   117 
   118 lemma finite_range: "finite (range (\<lambda>x. d\<cdot>x))"
   119 by (simp add: range_eq_fixes finite_fixes)
   120 
   121 lemma finite_image: "finite ((\<lambda>x. d\<cdot>x) ` A)"
   122 by (rule finite_subset [OF image_mono [OF subset_UNIV] finite_range])
   123 
   124 lemma compact: "compact (d\<cdot>x)"
   125 proof (rule compactI2)
   126   fix Y :: "nat \<Rightarrow> 'a"
   127   assume Y: "chain Y"
   128   have "finite_chain (\<lambda>i. d\<cdot>(Y i))"
   129   proof (rule finite_range_imp_finch)
   130     show "chain (\<lambda>i. d\<cdot>(Y i))"
   131       using Y by simp
   132     have "range (\<lambda>i. d\<cdot>(Y i)) \<subseteq> range (\<lambda>x. d\<cdot>x)"
   133       by clarsimp
   134     thus "finite (range (\<lambda>i. d\<cdot>(Y i)))"
   135       using finite_range by (rule finite_subset)
   136   qed
   137   hence "\<exists>j. (\<Squnion>i. d\<cdot>(Y i)) = d\<cdot>(Y j)"
   138     by (simp add: finite_chain_def maxinch_is_thelub Y)
   139   then obtain j where j: "(\<Squnion>i. d\<cdot>(Y i)) = d\<cdot>(Y j)" ..
   140 
   141   assume "d\<cdot>x \<sqsubseteq> (\<Squnion>i. Y i)"
   142   hence "d\<cdot>(d\<cdot>x) \<sqsubseteq> d\<cdot>(\<Squnion>i. Y i)"
   143     by (rule monofun_cfun_arg)
   144   hence "d\<cdot>x \<sqsubseteq> (\<Squnion>i. d\<cdot>(Y i))"
   145     by (simp add: contlub_cfun_arg Y idem)
   146   hence "d\<cdot>x \<sqsubseteq> d\<cdot>(Y j)"
   147     using j by simp
   148   hence "d\<cdot>x \<sqsubseteq> Y j"
   149     using below by (rule below_trans)
   150   thus "\<exists>j. d\<cdot>x \<sqsubseteq> Y j" ..
   151 qed
   152 
   153 end
   154 
   155 
   156 subsection {* Continuous embedding-projection pairs *}
   157 
   158 locale ep_pair =
   159   fixes e :: "'a \<rightarrow> 'b" and p :: "'b \<rightarrow> 'a"
   160   assumes e_inverse [simp]: "\<And>x. p\<cdot>(e\<cdot>x) = x"
   161   and e_p_below: "\<And>y. e\<cdot>(p\<cdot>y) \<sqsubseteq> y"
   162 begin
   163 
   164 lemma e_below_iff [simp]: "e\<cdot>x \<sqsubseteq> e\<cdot>y \<longleftrightarrow> x \<sqsubseteq> y"
   165 proof
   166   assume "e\<cdot>x \<sqsubseteq> e\<cdot>y"
   167   hence "p\<cdot>(e\<cdot>x) \<sqsubseteq> p\<cdot>(e\<cdot>y)" by (rule monofun_cfun_arg)
   168   thus "x \<sqsubseteq> y" by simp
   169 next
   170   assume "x \<sqsubseteq> y"
   171   thus "e\<cdot>x \<sqsubseteq> e\<cdot>y" by (rule monofun_cfun_arg)
   172 qed
   173 
   174 lemma e_eq_iff [simp]: "e\<cdot>x = e\<cdot>y \<longleftrightarrow> x = y"
   175 unfolding po_eq_conv e_below_iff ..
   176 
   177 lemma p_eq_iff:
   178   "\<lbrakk>e\<cdot>(p\<cdot>x) = x; e\<cdot>(p\<cdot>y) = y\<rbrakk> \<Longrightarrow> p\<cdot>x = p\<cdot>y \<longleftrightarrow> x = y"
   179 by (safe, erule subst, erule subst, simp)
   180 
   181 lemma p_inverse: "(\<exists>x. y = e\<cdot>x) = (e\<cdot>(p\<cdot>y) = y)"
   182 by (auto, rule exI, erule sym)
   183 
   184 lemma e_below_iff_below_p: "e\<cdot>x \<sqsubseteq> y \<longleftrightarrow> x \<sqsubseteq> p\<cdot>y"
   185 proof
   186   assume "e\<cdot>x \<sqsubseteq> y"
   187   then have "p\<cdot>(e\<cdot>x) \<sqsubseteq> p\<cdot>y" by (rule monofun_cfun_arg)
   188   then show "x \<sqsubseteq> p\<cdot>y" by simp
   189 next
   190   assume "x \<sqsubseteq> p\<cdot>y"
   191   then have "e\<cdot>x \<sqsubseteq> e\<cdot>(p\<cdot>y)" by (rule monofun_cfun_arg)
   192   then show "e\<cdot>x \<sqsubseteq> y" using e_p_below by (rule below_trans)
   193 qed
   194 
   195 lemma compact_e_rev: "compact (e\<cdot>x) \<Longrightarrow> compact x"
   196 proof -
   197   assume "compact (e\<cdot>x)"
   198   hence "adm (\<lambda>y. \<not> e\<cdot>x \<sqsubseteq> y)" by (rule compactD)
   199   hence "adm (\<lambda>y. \<not> e\<cdot>x \<sqsubseteq> e\<cdot>y)" by (rule adm_subst [OF cont_Rep_CFun2])
   200   hence "adm (\<lambda>y. \<not> x \<sqsubseteq> y)" by simp
   201   thus "compact x" by (rule compactI)
   202 qed
   203 
   204 lemma compact_e: "compact x \<Longrightarrow> compact (e\<cdot>x)"
   205 proof -
   206   assume "compact x"
   207   hence "adm (\<lambda>y. \<not> x \<sqsubseteq> y)" by (rule compactD)
   208   hence "adm (\<lambda>y. \<not> x \<sqsubseteq> p\<cdot>y)" by (rule adm_subst [OF cont_Rep_CFun2])
   209   hence "adm (\<lambda>y. \<not> e\<cdot>x \<sqsubseteq> y)" by (simp add: e_below_iff_below_p)
   210   thus "compact (e\<cdot>x)" by (rule compactI)
   211 qed
   212 
   213 lemma compact_e_iff: "compact (e\<cdot>x) \<longleftrightarrow> compact x"
   214 by (rule iffI [OF compact_e_rev compact_e])
   215 
   216 text {* Deflations from ep-pairs *}
   217 
   218 lemma deflation_e_p: "deflation (e oo p)"
   219 by (simp add: deflation.intro e_p_below)
   220 
   221 lemma deflation_e_d_p:
   222   assumes "deflation d"
   223   shows "deflation (e oo d oo p)"
   224 proof
   225   interpret deflation d by fact
   226   fix x :: 'b
   227   show "(e oo d oo p)\<cdot>((e oo d oo p)\<cdot>x) = (e oo d oo p)\<cdot>x"
   228     by (simp add: idem)
   229   show "(e oo d oo p)\<cdot>x \<sqsubseteq> x"
   230     by (simp add: e_below_iff_below_p below)
   231 qed
   232 
   233 lemma finite_deflation_e_d_p:
   234   assumes "finite_deflation d"
   235   shows "finite_deflation (e oo d oo p)"
   236 proof
   237   interpret finite_deflation d by fact
   238   fix x :: 'b
   239   show "(e oo d oo p)\<cdot>((e oo d oo p)\<cdot>x) = (e oo d oo p)\<cdot>x"
   240     by (simp add: idem)
   241   show "(e oo d oo p)\<cdot>x \<sqsubseteq> x"
   242     by (simp add: e_below_iff_below_p below)
   243   have "finite ((\<lambda>x. e\<cdot>x) ` (\<lambda>x. d\<cdot>x) ` range (\<lambda>x. p\<cdot>x))"
   244     by (simp add: finite_image)
   245   hence "finite (range (\<lambda>x. (e oo d oo p)\<cdot>x))"
   246     by (simp add: image_image)
   247   thus "finite {x. (e oo d oo p)\<cdot>x = x}"
   248     by (rule finite_range_imp_finite_fixes)
   249 qed
   250 
   251 lemma deflation_p_d_e:
   252   assumes "deflation d"
   253   assumes d: "\<And>x. d\<cdot>x \<sqsubseteq> e\<cdot>(p\<cdot>x)"
   254   shows "deflation (p oo d oo e)"
   255 proof -
   256   interpret d: deflation d by fact
   257   {
   258     fix x
   259     have "d\<cdot>(e\<cdot>x) \<sqsubseteq> e\<cdot>x"
   260       by (rule d.below)
   261     hence "p\<cdot>(d\<cdot>(e\<cdot>x)) \<sqsubseteq> p\<cdot>(e\<cdot>x)"
   262       by (rule monofun_cfun_arg)
   263     hence "(p oo d oo e)\<cdot>x \<sqsubseteq> x"
   264       by simp
   265   }
   266   note p_d_e_below = this
   267   show ?thesis
   268   proof
   269     fix x
   270     show "(p oo d oo e)\<cdot>x \<sqsubseteq> x"
   271       by (rule p_d_e_below)
   272   next
   273     fix x
   274     show "(p oo d oo e)\<cdot>((p oo d oo e)\<cdot>x) = (p oo d oo e)\<cdot>x"
   275     proof (rule below_antisym)
   276       show "(p oo d oo e)\<cdot>((p oo d oo e)\<cdot>x) \<sqsubseteq> (p oo d oo e)\<cdot>x"
   277         by (rule p_d_e_below)
   278       have "p\<cdot>(d\<cdot>(d\<cdot>(d\<cdot>(e\<cdot>x)))) \<sqsubseteq> p\<cdot>(d\<cdot>(e\<cdot>(p\<cdot>(d\<cdot>(e\<cdot>x)))))"
   279         by (intro monofun_cfun_arg d)
   280       hence "p\<cdot>(d\<cdot>(e\<cdot>x)) \<sqsubseteq> p\<cdot>(d\<cdot>(e\<cdot>(p\<cdot>(d\<cdot>(e\<cdot>x)))))"
   281         by (simp only: d.idem)
   282       thus "(p oo d oo e)\<cdot>x \<sqsubseteq> (p oo d oo e)\<cdot>((p oo d oo e)\<cdot>x)"
   283         by simp
   284     qed
   285   qed
   286 qed
   287 
   288 lemma finite_deflation_p_d_e:
   289   assumes "finite_deflation d"
   290   assumes d: "\<And>x. d\<cdot>x \<sqsubseteq> e\<cdot>(p\<cdot>x)"
   291   shows "finite_deflation (p oo d oo e)"
   292 proof -
   293   interpret d: finite_deflation d by fact
   294   show ?thesis
   295   proof (intro_locales)
   296     have "deflation d" ..
   297     thus "deflation (p oo d oo e)"
   298       using d by (rule deflation_p_d_e)
   299   next
   300     show "finite_deflation_axioms (p oo d oo e)"
   301     proof
   302       have "finite ((\<lambda>x. d\<cdot>x) ` range (\<lambda>x. e\<cdot>x))"
   303         by (rule d.finite_image)
   304       hence "finite ((\<lambda>x. p\<cdot>x) ` (\<lambda>x. d\<cdot>x) ` range (\<lambda>x. e\<cdot>x))"
   305         by (rule finite_imageI)
   306       hence "finite (range (\<lambda>x. (p oo d oo e)\<cdot>x))"
   307         by (simp add: image_image)
   308       thus "finite {x. (p oo d oo e)\<cdot>x = x}"
   309         by (rule finite_range_imp_finite_fixes)
   310     qed
   311   qed
   312 qed
   313 
   314 end
   315 
   316 subsection {* Uniqueness of ep-pairs *}
   317 
   318 lemma ep_pair_unique_e_lemma:
   319   assumes 1: "ep_pair e1 p" and 2: "ep_pair e2 p"
   320   shows "e1 \<sqsubseteq> e2"
   321 proof (rule below_cfun_ext)
   322   fix x
   323   have "e1\<cdot>(p\<cdot>(e2\<cdot>x)) \<sqsubseteq> e2\<cdot>x"
   324     by (rule ep_pair.e_p_below [OF 1])
   325   thus "e1\<cdot>x \<sqsubseteq> e2\<cdot>x"
   326     by (simp only: ep_pair.e_inverse [OF 2])
   327 qed
   328 
   329 lemma ep_pair_unique_e:
   330   "\<lbrakk>ep_pair e1 p; ep_pair e2 p\<rbrakk> \<Longrightarrow> e1 = e2"
   331 by (fast intro: below_antisym elim: ep_pair_unique_e_lemma)
   332 
   333 lemma ep_pair_unique_p_lemma:
   334   assumes 1: "ep_pair e p1" and 2: "ep_pair e p2"
   335   shows "p1 \<sqsubseteq> p2"
   336 proof (rule below_cfun_ext)
   337   fix x
   338   have "e\<cdot>(p1\<cdot>x) \<sqsubseteq> x"
   339     by (rule ep_pair.e_p_below [OF 1])
   340   hence "p2\<cdot>(e\<cdot>(p1\<cdot>x)) \<sqsubseteq> p2\<cdot>x"
   341     by (rule monofun_cfun_arg)
   342   thus "p1\<cdot>x \<sqsubseteq> p2\<cdot>x"
   343     by (simp only: ep_pair.e_inverse [OF 2])
   344 qed
   345 
   346 lemma ep_pair_unique_p:
   347   "\<lbrakk>ep_pair e p1; ep_pair e p2\<rbrakk> \<Longrightarrow> p1 = p2"
   348 by (fast intro: below_antisym elim: ep_pair_unique_p_lemma)
   349 
   350 subsection {* Composing ep-pairs *}
   351 
   352 lemma ep_pair_ID_ID: "ep_pair ID ID"
   353 by default simp_all
   354 
   355 lemma ep_pair_comp:
   356   assumes "ep_pair e1 p1" and "ep_pair e2 p2"
   357   shows "ep_pair (e2 oo e1) (p1 oo p2)"
   358 proof
   359   interpret ep1: ep_pair e1 p1 by fact
   360   interpret ep2: ep_pair e2 p2 by fact
   361   fix x y
   362   show "(p1 oo p2)\<cdot>((e2 oo e1)\<cdot>x) = x"
   363     by simp
   364   have "e1\<cdot>(p1\<cdot>(p2\<cdot>y)) \<sqsubseteq> p2\<cdot>y"
   365     by (rule ep1.e_p_below)
   366   hence "e2\<cdot>(e1\<cdot>(p1\<cdot>(p2\<cdot>y))) \<sqsubseteq> e2\<cdot>(p2\<cdot>y)"
   367     by (rule monofun_cfun_arg)
   368   also have "e2\<cdot>(p2\<cdot>y) \<sqsubseteq> y"
   369     by (rule ep2.e_p_below)
   370   finally show "(e2 oo e1)\<cdot>((p1 oo p2)\<cdot>y) \<sqsubseteq> y"
   371     by simp
   372 qed
   373 
   374 locale pcpo_ep_pair = ep_pair +
   375   constrains e :: "'a::pcpo \<rightarrow> 'b::pcpo"
   376   constrains p :: "'b::pcpo \<rightarrow> 'a::pcpo"
   377 begin
   378 
   379 lemma e_strict [simp]: "e\<cdot>\<bottom> = \<bottom>"
   380 proof -
   381   have "\<bottom> \<sqsubseteq> p\<cdot>\<bottom>" by (rule minimal)
   382   hence "e\<cdot>\<bottom> \<sqsubseteq> e\<cdot>(p\<cdot>\<bottom>)" by (rule monofun_cfun_arg)
   383   also have "e\<cdot>(p\<cdot>\<bottom>) \<sqsubseteq> \<bottom>" by (rule e_p_below)
   384   finally show "e\<cdot>\<bottom> = \<bottom>" by simp
   385 qed
   386 
   387 lemma e_defined_iff [simp]: "e\<cdot>x = \<bottom> \<longleftrightarrow> x = \<bottom>"
   388 by (rule e_eq_iff [where y="\<bottom>", unfolded e_strict])
   389 
   390 lemma e_defined: "x \<noteq> \<bottom> \<Longrightarrow> e\<cdot>x \<noteq> \<bottom>"
   391 by simp
   392 
   393 lemma p_strict [simp]: "p\<cdot>\<bottom> = \<bottom>"
   394 by (rule e_inverse [where x="\<bottom>", unfolded e_strict])
   395 
   396 lemmas stricts = e_strict p_strict
   397 
   398 end
   399 
   400 end