src/HOL/HOLCF/Bifinite.thy
changeset 62175 8ffc4d0e652d
parent 61169 4de9ff3ea29a
child 62390 842917225d56
equal deleted inserted replaced
62174:fae6233c5f37 62175:8ffc4d0e652d
     1 (*  Title:      HOL/HOLCF/Bifinite.thy
     1 (*  Title:      HOL/HOLCF/Bifinite.thy
     2     Author:     Brian Huffman
     2     Author:     Brian Huffman
     3 *)
     3 *)
     4 
     4 
     5 section {* Profinite and bifinite cpos *}
     5 section \<open>Profinite and bifinite cpos\<close>
     6 
     6 
     7 theory Bifinite
     7 theory Bifinite
     8 imports Map_Functions "~~/src/HOL/Library/Countable"
     8 imports Map_Functions "~~/src/HOL/Library/Countable"
     9 begin
     9 begin
    10 
    10 
    11 default_sort cpo
    11 default_sort cpo
    12 
    12 
    13 subsection {* Chains of finite deflations *}
    13 subsection \<open>Chains of finite deflations\<close>
    14 
    14 
    15 locale approx_chain =
    15 locale approx_chain =
    16   fixes approx :: "nat \<Rightarrow> 'a \<rightarrow> 'a"
    16   fixes approx :: "nat \<Rightarrow> 'a \<rightarrow> 'a"
    17   assumes chain_approx [simp]: "chain (\<lambda>i. approx i)"
    17   assumes chain_approx [simp]: "chain (\<lambda>i. approx i)"
    18   assumes lub_approx [simp]: "(\<Squnion>i. approx i) = ID"
    18   assumes lub_approx [simp]: "(\<Squnion>i. approx i) = ID"
    41 lemma compact_eq_approx: "compact x \<Longrightarrow> \<exists>i. approx i\<cdot>x = x"
    41 lemma compact_eq_approx: "compact x \<Longrightarrow> \<exists>i. approx i\<cdot>x = x"
    42 by (rule admD2, simp_all)
    42 by (rule admD2, simp_all)
    43 
    43 
    44 end
    44 end
    45 
    45 
    46 subsection {* Omega-profinite and bifinite domains *}
    46 subsection \<open>Omega-profinite and bifinite domains\<close>
    47 
    47 
    48 class bifinite = pcpo +
    48 class bifinite = pcpo +
    49   assumes bifinite: "\<exists>(a::nat \<Rightarrow> 'a \<rightarrow> 'a). approx_chain a"
    49   assumes bifinite: "\<exists>(a::nat \<Rightarrow> 'a \<rightarrow> 'a). approx_chain a"
    50 
    50 
    51 class profinite = cpo +
    51 class profinite = cpo +
    52   assumes profinite: "\<exists>(a::nat \<Rightarrow> 'a\<^sub>\<bottom> \<rightarrow> 'a\<^sub>\<bottom>). approx_chain a"
    52   assumes profinite: "\<exists>(a::nat \<Rightarrow> 'a\<^sub>\<bottom> \<rightarrow> 'a\<^sub>\<bottom>). approx_chain a"
    53 
    53 
    54 subsection {* Building approx chains *}
    54 subsection \<open>Building approx chains\<close>
    55 
    55 
    56 lemma approx_chain_iso:
    56 lemma approx_chain_iso:
    57   assumes a: "approx_chain a"
    57   assumes a: "approx_chain a"
    58   assumes [simp]: "\<And>x. f\<cdot>(g\<cdot>x) = x"
    58   assumes [simp]: "\<And>x. f\<cdot>(g\<cdot>x) = x"
    59   assumes [simp]: "\<And>y. g\<cdot>(f\<cdot>y) = y"
    59   assumes [simp]: "\<And>y. g\<cdot>(f\<cdot>y) = y"
   100   assumes "approx_chain a" and "approx_chain b"
   100   assumes "approx_chain a" and "approx_chain b"
   101   shows "approx_chain (\<lambda>i. prod_map\<cdot>(a i)\<cdot>(b i))"
   101   shows "approx_chain (\<lambda>i. prod_map\<cdot>(a i)\<cdot>(b i))"
   102   using assms unfolding approx_chain_def
   102   using assms unfolding approx_chain_def
   103   by (simp add: lub_APP prod_map_ID finite_deflation_prod_map)
   103   by (simp add: lub_APP prod_map_ID finite_deflation_prod_map)
   104 
   104 
   105 text {* Approx chains for countable discrete types. *}
   105 text \<open>Approx chains for countable discrete types.\<close>
   106 
   106 
   107 definition discr_approx :: "nat \<Rightarrow> 'a::countable discr u \<rightarrow> 'a discr u"
   107 definition discr_approx :: "nat \<Rightarrow> 'a::countable discr u \<rightarrow> 'a discr u"
   108   where "discr_approx = (\<lambda>i. \<Lambda>(up\<cdot>x). if to_nat (undiscr x) < i then up\<cdot>x else \<bottom>)"
   108   where "discr_approx = (\<lambda>i. \<Lambda>(up\<cdot>x). if to_nat (undiscr x) < i then up\<cdot>x else \<bottom>)"
   109 
   109 
   110 lemma chain_discr_approx [simp]: "chain discr_approx"
   110 lemma chain_discr_approx [simp]: "chain discr_approx"
   150 
   150 
   151 lemma discr_approx: "approx_chain discr_approx"
   151 lemma discr_approx: "approx_chain discr_approx"
   152 using chain_discr_approx lub_discr_approx finite_deflation_discr_approx
   152 using chain_discr_approx lub_discr_approx finite_deflation_discr_approx
   153 by (rule approx_chain.intro)
   153 by (rule approx_chain.intro)
   154 
   154 
   155 subsection {* Class instance proofs *}
   155 subsection \<open>Class instance proofs\<close>
   156 
   156 
   157 instance bifinite \<subseteq> profinite
   157 instance bifinite \<subseteq> profinite
   158 proof
   158 proof
   159   show "\<exists>(a::nat \<Rightarrow> 'a\<^sub>\<bottom> \<rightarrow> 'a\<^sub>\<bottom>). approx_chain a"
   159   show "\<exists>(a::nat \<Rightarrow> 'a\<^sub>\<bottom> \<rightarrow> 'a\<^sub>\<bottom>). approx_chain a"
   160     using bifinite [where 'a='a]
   160     using bifinite [where 'a='a]
   162 qed
   162 qed
   163 
   163 
   164 instance u :: (profinite) bifinite
   164 instance u :: (profinite) bifinite
   165   by standard (rule profinite)
   165   by standard (rule profinite)
   166 
   166 
   167 text {*
   167 text \<open>
   168   Types @{typ "'a \<rightarrow> 'b"} and @{typ "'a u \<rightarrow>! 'b"} are isomorphic.
   168   Types @{typ "'a \<rightarrow> 'b"} and @{typ "'a u \<rightarrow>! 'b"} are isomorphic.
   169 *}
   169 \<close>
   170 
   170 
   171 definition "encode_cfun = (\<Lambda> f. sfun_abs\<cdot>(fup\<cdot>f))"
   171 definition "encode_cfun = (\<Lambda> f. sfun_abs\<cdot>(fup\<cdot>f))"
   172 
   172 
   173 definition "decode_cfun = (\<Lambda> g x. sfun_rep\<cdot>g\<cdot>(up\<cdot>x))"
   173 definition "decode_cfun = (\<Lambda> g x. sfun_rep\<cdot>g\<cdot>(up\<cdot>x))"
   174 
   174 
   192     using a b by (simp add: approx_chain_iso approx_chain_sfun_map)
   192     using a b by (simp add: approx_chain_iso approx_chain_sfun_map)
   193   thus "\<exists>(a::nat \<Rightarrow> ('a \<rightarrow> 'b) \<rightarrow> ('a \<rightarrow> 'b)). approx_chain a"
   193   thus "\<exists>(a::nat \<Rightarrow> ('a \<rightarrow> 'b) \<rightarrow> ('a \<rightarrow> 'b)). approx_chain a"
   194     by - (rule exI)
   194     by - (rule exI)
   195 qed
   195 qed
   196 
   196 
   197 text {*
   197 text \<open>
   198   Types @{typ "('a * 'b) u"} and @{typ "'a u \<otimes> 'b u"} are isomorphic.
   198   Types @{typ "('a * 'b) u"} and @{typ "'a u \<otimes> 'b u"} are isomorphic.
   199 *}
   199 \<close>
   200 
   200 
   201 definition "encode_prod_u = (\<Lambda>(up\<cdot>(x, y)). (:up\<cdot>x, up\<cdot>y:))"
   201 definition "encode_prod_u = (\<Lambda>(up\<cdot>(x, y)). (:up\<cdot>x, up\<cdot>y:))"
   202 
   202 
   203 definition "decode_prod_u = (\<Lambda>(:up\<cdot>x, up\<cdot>y:). up\<cdot>(x, y))"
   203 definition "decode_prod_u = (\<Lambda>(:up\<cdot>x, up\<cdot>y:). up\<cdot>(x, y))"
   204 
   204