src/HOLCF/Bifinite.thy
author huffman
Mon Nov 08 06:58:09 2010 -0800 (2010-11-08)
changeset 40484 768f7e264e2b
parent 40086 c339c0e8fdfb
child 40491 6de5839e2fb3
permissions -rw-r--r--
reorganize Bifinite.thy; simplify some proofs related to bifinite class instances
huffman@25903
     1
(*  Title:      HOLCF/Bifinite.thy
huffman@25903
     2
    Author:     Brian Huffman
huffman@25903
     3
*)
huffman@25903
     4
huffman@39985
     5
header {* Bifinite domains *}
huffman@25903
     6
huffman@25903
     7
theory Bifinite
huffman@40086
     8
imports Algebraic Cprod Sprod Ssum Up Lift One Tr Countable
huffman@25903
     9
begin
huffman@25903
    10
huffman@39986
    11
subsection {* Class of bifinite domains *}
huffman@39985
    12
huffman@39985
    13
text {*
huffman@39986
    14
  We define a bifinite domain as a pcpo that is isomorphic to some
huffman@39985
    15
  algebraic deflation over the universal domain.
huffman@39985
    16
*}
huffman@39985
    17
huffman@39986
    18
class bifinite = pcpo +
huffman@39985
    19
  fixes emb :: "'a::pcpo \<rightarrow> udom"
huffman@39985
    20
  fixes prj :: "udom \<rightarrow> 'a::pcpo"
huffman@39989
    21
  fixes defl :: "'a itself \<Rightarrow> defl"
huffman@39985
    22
  assumes ep_pair_emb_prj: "ep_pair emb prj"
huffman@39989
    23
  assumes cast_DEFL: "cast\<cdot>(defl TYPE('a)) = emb oo prj"
huffman@31113
    24
huffman@39989
    25
syntax "_DEFL" :: "type \<Rightarrow> defl"  ("(1DEFL/(1'(_')))")
huffman@39989
    26
translations "DEFL('t)" \<rightleftharpoons> "CONST defl TYPE('t)"
huffman@39985
    27
huffman@39986
    28
interpretation bifinite:
huffman@39986
    29
  pcpo_ep_pair "emb :: 'a::bifinite \<rightarrow> udom" "prj :: udom \<rightarrow> 'a::bifinite"
huffman@39985
    30
  unfolding pcpo_ep_pair_def
huffman@39985
    31
  by (rule ep_pair_emb_prj)
huffman@33504
    32
huffman@39986
    33
lemmas emb_inverse = bifinite.e_inverse
huffman@39986
    34
lemmas emb_prj_below = bifinite.e_p_below
huffman@39986
    35
lemmas emb_eq_iff = bifinite.e_eq_iff
huffman@39986
    36
lemmas emb_strict = bifinite.e_strict
huffman@39986
    37
lemmas prj_strict = bifinite.p_strict
huffman@33504
    38
huffman@39986
    39
subsection {* Bifinite domains have a countable compact basis *}
huffman@33808
    40
huffman@39985
    41
text {*
huffman@39985
    42
  Eventually it should be possible to generalize this to an unpointed
huffman@39986
    43
  variant of the bifinite class.
huffman@39985
    44
*}
huffman@33587
    45
huffman@39985
    46
interpretation compact_basis:
huffman@39986
    47
  ideal_completion below Rep_compact_basis "approximants::'a::bifinite \<Rightarrow> _"
huffman@39985
    48
proof -
huffman@39985
    49
  obtain Y where Y: "\<forall>i. Y i \<sqsubseteq> Y (Suc i)"
huffman@39989
    50
  and DEFL: "DEFL('a) = (\<Squnion>i. defl_principal (Y i))"
huffman@39989
    51
    by (rule defl.obtain_principal_chain)
huffman@39989
    52
  def approx \<equiv> "\<lambda>i. (prj oo cast\<cdot>(defl_principal (Y i)) oo emb) :: 'a \<rightarrow> 'a"
huffman@39989
    53
  interpret defl_approx: approx_chain approx
huffman@39985
    54
  proof (rule approx_chain.intro)
huffman@39985
    55
    show "chain (\<lambda>i. approx i)"
huffman@39985
    56
      unfolding approx_def by (simp add: Y)
huffman@39985
    57
    show "(\<Squnion>i. approx i) = ID"
huffman@39985
    58
      unfolding approx_def
huffman@40002
    59
      by (simp add: lub_distribs Y DEFL [symmetric] cast_DEFL cfun_eq_iff)
huffman@39985
    60
    show "\<And>i. finite_deflation (approx i)"
huffman@39985
    61
      unfolding approx_def
huffman@39986
    62
      apply (rule bifinite.finite_deflation_p_d_e)
huffman@39985
    63
      apply (rule finite_deflation_cast)
huffman@39989
    64
      apply (rule defl.compact_principal)
huffman@39985
    65
      apply (rule below_trans [OF monofun_cfun_fun])
huffman@39985
    66
      apply (rule is_ub_thelub, simp add: Y)
huffman@39989
    67
      apply (simp add: lub_distribs Y DEFL [symmetric] cast_DEFL)
huffman@39985
    68
      done
huffman@39985
    69
  qed
huffman@39985
    70
  (* FIXME: why does show ?thesis fail here? *)
huffman@39985
    71
  show "ideal_completion below Rep_compact_basis (approximants::'a \<Rightarrow> _)" ..
huffman@33504
    72
qed
huffman@33504
    73
huffman@40484
    74
subsection {* Chains of approx functions *}
huffman@40484
    75
huffman@40484
    76
definition u_approx :: "nat \<Rightarrow> udom\<^sub>\<bottom> \<rightarrow> udom\<^sub>\<bottom>"
huffman@40484
    77
  where "u_approx = (\<lambda>i. u_map\<cdot>(udom_approx i))"
huffman@40484
    78
huffman@40484
    79
definition cfun_approx :: "nat \<Rightarrow> (udom \<rightarrow> udom) \<rightarrow> (udom \<rightarrow> udom)"
huffman@40484
    80
  where "cfun_approx = (\<lambda>i. cfun_map\<cdot>(udom_approx i)\<cdot>(udom_approx i))"
huffman@40484
    81
huffman@40484
    82
definition prod_approx :: "nat \<Rightarrow> udom \<times> udom \<rightarrow> udom \<times> udom"
huffman@40484
    83
  where "prod_approx = (\<lambda>i. cprod_map\<cdot>(udom_approx i)\<cdot>(udom_approx i))"
huffman@40484
    84
huffman@40484
    85
definition sprod_approx :: "nat \<Rightarrow> udom \<otimes> udom \<rightarrow> udom \<otimes> udom"
huffman@40484
    86
  where "sprod_approx = (\<lambda>i. sprod_map\<cdot>(udom_approx i)\<cdot>(udom_approx i))"
huffman@40484
    87
huffman@40484
    88
definition ssum_approx :: "nat \<Rightarrow> udom \<oplus> udom \<rightarrow> udom \<oplus> udom"
huffman@40484
    89
  where "ssum_approx = (\<lambda>i. ssum_map\<cdot>(udom_approx i)\<cdot>(udom_approx i))"
huffman@40484
    90
huffman@40484
    91
lemma approx_chain_lemma1:
huffman@40484
    92
  assumes "m\<cdot>ID = ID"
huffman@40484
    93
  assumes "\<And>d. finite_deflation d \<Longrightarrow> finite_deflation (m\<cdot>d)"
huffman@40484
    94
  shows "approx_chain (\<lambda>i. m\<cdot>(udom_approx i))"
huffman@40484
    95
by (rule approx_chain.intro)
huffman@40484
    96
   (simp_all add: lub_distribs finite_deflation_udom_approx assms)
huffman@40484
    97
huffman@40484
    98
lemma approx_chain_lemma2:
huffman@40484
    99
  assumes "m\<cdot>ID\<cdot>ID = ID"
huffman@40484
   100
  assumes "\<And>a b. \<lbrakk>finite_deflation a; finite_deflation b\<rbrakk>
huffman@40484
   101
    \<Longrightarrow> finite_deflation (m\<cdot>a\<cdot>b)"
huffman@40484
   102
  shows "approx_chain (\<lambda>i. m\<cdot>(udom_approx i)\<cdot>(udom_approx i))"
huffman@40484
   103
by (rule approx_chain.intro)
huffman@40484
   104
   (simp_all add: lub_distribs finite_deflation_udom_approx assms)
huffman@40484
   105
huffman@40484
   106
lemma u_approx: "approx_chain u_approx"
huffman@40484
   107
using u_map_ID finite_deflation_u_map
huffman@40484
   108
unfolding u_approx_def by (rule approx_chain_lemma1)
huffman@40484
   109
huffman@40484
   110
lemma cfun_approx: "approx_chain cfun_approx"
huffman@40484
   111
using cfun_map_ID finite_deflation_cfun_map
huffman@40484
   112
unfolding cfun_approx_def by (rule approx_chain_lemma2)
huffman@40484
   113
huffman@40484
   114
lemma prod_approx: "approx_chain prod_approx"
huffman@40484
   115
using cprod_map_ID finite_deflation_cprod_map
huffman@40484
   116
unfolding prod_approx_def by (rule approx_chain_lemma2)
huffman@40484
   117
huffman@40484
   118
lemma sprod_approx: "approx_chain sprod_approx"
huffman@40484
   119
using sprod_map_ID finite_deflation_sprod_map
huffman@40484
   120
unfolding sprod_approx_def by (rule approx_chain_lemma2)
huffman@40484
   121
huffman@40484
   122
lemma ssum_approx: "approx_chain ssum_approx"
huffman@40484
   123
using ssum_map_ID finite_deflation_ssum_map
huffman@40484
   124
unfolding ssum_approx_def by (rule approx_chain_lemma2)
huffman@40484
   125
huffman@39985
   126
subsection {* Type combinators *}
huffman@39985
   127
huffman@39985
   128
definition
huffman@39989
   129
  defl_fun1 ::
huffman@39989
   130
    "(nat \<Rightarrow> 'a \<rightarrow> 'a) \<Rightarrow> ((udom \<rightarrow> udom) \<rightarrow> ('a \<rightarrow> 'a)) \<Rightarrow> (defl \<rightarrow> defl)"
huffman@39985
   131
where
huffman@39989
   132
  "defl_fun1 approx f =
huffman@39989
   133
    defl.basis_fun (\<lambda>a.
huffman@39989
   134
      defl_principal (Abs_fin_defl
huffman@39985
   135
        (udom_emb approx oo f\<cdot>(Rep_fin_defl a) oo udom_prj approx)))"
huffman@39985
   136
huffman@39985
   137
definition
huffman@39989
   138
  defl_fun2 ::
huffman@39985
   139
    "(nat \<Rightarrow> 'a \<rightarrow> 'a) \<Rightarrow> ((udom \<rightarrow> udom) \<rightarrow> (udom \<rightarrow> udom) \<rightarrow> ('a \<rightarrow> 'a))
huffman@39989
   140
      \<Rightarrow> (defl \<rightarrow> defl \<rightarrow> defl)"
huffman@39985
   141
where
huffman@39989
   142
  "defl_fun2 approx f =
huffman@39989
   143
    defl.basis_fun (\<lambda>a.
huffman@39989
   144
      defl.basis_fun (\<lambda>b.
huffman@39989
   145
        defl_principal (Abs_fin_defl
huffman@39985
   146
          (udom_emb approx oo
huffman@39985
   147
            f\<cdot>(Rep_fin_defl a)\<cdot>(Rep_fin_defl b) oo udom_prj approx))))"
huffman@33504
   148
huffman@39989
   149
lemma cast_defl_fun1:
huffman@39985
   150
  assumes approx: "approx_chain approx"
huffman@39985
   151
  assumes f: "\<And>a. finite_deflation a \<Longrightarrow> finite_deflation (f\<cdot>a)"
huffman@39989
   152
  shows "cast\<cdot>(defl_fun1 approx f\<cdot>A) = udom_emb approx oo f\<cdot>(cast\<cdot>A) oo udom_prj approx"
huffman@39985
   153
proof -
huffman@39985
   154
  have 1: "\<And>a. finite_deflation
huffman@39985
   155
        (udom_emb approx oo f\<cdot>(Rep_fin_defl a) oo udom_prj approx)"
huffman@39985
   156
    apply (rule ep_pair.finite_deflation_e_d_p)
huffman@39985
   157
    apply (rule approx_chain.ep_pair_udom [OF approx])
huffman@39985
   158
    apply (rule f, rule finite_deflation_Rep_fin_defl)
huffman@39985
   159
    done
huffman@39985
   160
  show ?thesis
huffman@39989
   161
    by (induct A rule: defl.principal_induct, simp)
huffman@39989
   162
       (simp only: defl_fun1_def
huffman@39989
   163
                   defl.basis_fun_principal
huffman@39989
   164
                   defl.basis_fun_mono
huffman@39989
   165
                   defl.principal_mono
huffman@39985
   166
                   Abs_fin_defl_mono [OF 1 1]
huffman@39985
   167
                   monofun_cfun below_refl
huffman@39985
   168
                   Rep_fin_defl_mono
huffman@39989
   169
                   cast_defl_principal
huffman@39985
   170
                   Abs_fin_defl_inverse [unfolded mem_Collect_eq, OF 1])
huffman@33504
   171
qed
huffman@33504
   172
huffman@39989
   173
lemma cast_defl_fun2:
huffman@39985
   174
  assumes approx: "approx_chain approx"
huffman@39985
   175
  assumes f: "\<And>a b. finite_deflation a \<Longrightarrow> finite_deflation b \<Longrightarrow>
huffman@39985
   176
                finite_deflation (f\<cdot>a\<cdot>b)"
huffman@39989
   177
  shows "cast\<cdot>(defl_fun2 approx f\<cdot>A\<cdot>B) =
huffman@39985
   178
    udom_emb approx oo f\<cdot>(cast\<cdot>A)\<cdot>(cast\<cdot>B) oo udom_prj approx"
huffman@39985
   179
proof -
huffman@39985
   180
  have 1: "\<And>a b. finite_deflation (udom_emb approx oo
huffman@39985
   181
      f\<cdot>(Rep_fin_defl a)\<cdot>(Rep_fin_defl b) oo udom_prj approx)"
huffman@39985
   182
    apply (rule ep_pair.finite_deflation_e_d_p)
huffman@39985
   183
    apply (rule ep_pair_udom [OF approx])
huffman@39985
   184
    apply (rule f, (rule finite_deflation_Rep_fin_defl)+)
huffman@39985
   185
    done
huffman@39985
   186
  show ?thesis
huffman@39989
   187
    by (induct A B rule: defl.principal_induct2, simp, simp)
huffman@39989
   188
       (simp only: defl_fun2_def
huffman@39989
   189
                   defl.basis_fun_principal
huffman@39989
   190
                   defl.basis_fun_mono
huffman@39989
   191
                   defl.principal_mono
huffman@39985
   192
                   Abs_fin_defl_mono [OF 1 1]
huffman@39985
   193
                   monofun_cfun below_refl
huffman@39985
   194
                   Rep_fin_defl_mono
huffman@39989
   195
                   cast_defl_principal
huffman@39985
   196
                   Abs_fin_defl_inverse [unfolded mem_Collect_eq, OF 1])
huffman@39985
   197
qed
huffman@39985
   198
huffman@40484
   199
definition u_defl :: "defl \<rightarrow> defl"
huffman@40484
   200
  where "u_defl = defl_fun1 u_approx u_map"
huffman@40484
   201
huffman@40484
   202
definition cfun_defl :: "defl \<rightarrow> defl \<rightarrow> defl"
huffman@40484
   203
  where "cfun_defl = defl_fun2 cfun_approx cfun_map"
huffman@40484
   204
huffman@40484
   205
definition prod_defl :: "defl \<rightarrow> defl \<rightarrow> defl"
huffman@40484
   206
  where "prod_defl = defl_fun2 prod_approx cprod_map"
huffman@40484
   207
huffman@40484
   208
definition sprod_defl :: "defl \<rightarrow> defl \<rightarrow> defl"
huffman@40484
   209
  where "sprod_defl = defl_fun2 sprod_approx sprod_map"
huffman@40484
   210
huffman@40484
   211
definition ssum_defl :: "defl \<rightarrow> defl \<rightarrow> defl"
huffman@40484
   212
where "ssum_defl = defl_fun2 ssum_approx ssum_map"
huffman@40484
   213
huffman@40484
   214
lemma cast_u_defl:
huffman@40484
   215
  "cast\<cdot>(u_defl\<cdot>A) =
huffman@40484
   216
    udom_emb u_approx oo u_map\<cdot>(cast\<cdot>A) oo udom_prj u_approx"
huffman@40484
   217
using u_approx finite_deflation_u_map
huffman@40484
   218
unfolding u_defl_def by (rule cast_defl_fun1)
huffman@40484
   219
huffman@40484
   220
lemma cast_cfun_defl:
huffman@40484
   221
  "cast\<cdot>(cfun_defl\<cdot>A\<cdot>B) =
huffman@40484
   222
    udom_emb cfun_approx oo cfun_map\<cdot>(cast\<cdot>A)\<cdot>(cast\<cdot>B) oo udom_prj cfun_approx"
huffman@40484
   223
using cfun_approx finite_deflation_cfun_map
huffman@40484
   224
unfolding cfun_defl_def by (rule cast_defl_fun2)
huffman@40484
   225
huffman@40484
   226
lemma cast_prod_defl:
huffman@40484
   227
  "cast\<cdot>(prod_defl\<cdot>A\<cdot>B) = udom_emb prod_approx oo
huffman@40484
   228
    cprod_map\<cdot>(cast\<cdot>A)\<cdot>(cast\<cdot>B) oo udom_prj prod_approx"
huffman@40484
   229
using prod_approx finite_deflation_cprod_map
huffman@40484
   230
unfolding prod_defl_def by (rule cast_defl_fun2)
huffman@40484
   231
huffman@40484
   232
lemma cast_sprod_defl:
huffman@40484
   233
  "cast\<cdot>(sprod_defl\<cdot>A\<cdot>B) =
huffman@40484
   234
    udom_emb sprod_approx oo
huffman@40484
   235
      sprod_map\<cdot>(cast\<cdot>A)\<cdot>(cast\<cdot>B) oo
huffman@40484
   236
        udom_prj sprod_approx"
huffman@40484
   237
using sprod_approx finite_deflation_sprod_map
huffman@40484
   238
unfolding sprod_defl_def by (rule cast_defl_fun2)
huffman@40484
   239
huffman@40484
   240
lemma cast_ssum_defl:
huffman@40484
   241
  "cast\<cdot>(ssum_defl\<cdot>A\<cdot>B) =
huffman@40484
   242
    udom_emb ssum_approx oo ssum_map\<cdot>(cast\<cdot>A)\<cdot>(cast\<cdot>B) oo udom_prj ssum_approx"
huffman@40484
   243
using ssum_approx finite_deflation_ssum_map
huffman@40484
   244
unfolding ssum_defl_def by (rule cast_defl_fun2)
huffman@40484
   245
huffman@39987
   246
subsection {* The universal domain is bifinite *}
huffman@39985
   247
huffman@39986
   248
instantiation udom :: bifinite
huffman@39985
   249
begin
huffman@39985
   250
huffman@39985
   251
definition [simp]:
huffman@39985
   252
  "emb = (ID :: udom \<rightarrow> udom)"
huffman@39985
   253
huffman@39985
   254
definition [simp]:
huffman@39985
   255
  "prj = (ID :: udom \<rightarrow> udom)"
huffman@25903
   256
huffman@33504
   257
definition
huffman@39989
   258
  "defl (t::udom itself) = (\<Squnion>i. defl_principal (Abs_fin_defl (udom_approx i)))"
huffman@33808
   259
huffman@39985
   260
instance proof
huffman@39985
   261
  show "ep_pair emb (prj :: udom \<rightarrow> udom)"
huffman@39985
   262
    by (simp add: ep_pair.intro)
huffman@39989
   263
  show "cast\<cdot>DEFL(udom) = emb oo (prj :: udom \<rightarrow> udom)"
huffman@39989
   264
    unfolding defl_udom_def
huffman@39985
   265
    apply (subst contlub_cfun_arg)
huffman@39985
   266
    apply (rule chainI)
huffman@39989
   267
    apply (rule defl.principal_mono)
huffman@39985
   268
    apply (simp add: below_fin_defl_def)
huffman@39985
   269
    apply (simp add: Abs_fin_defl_inverse finite_deflation_udom_approx)
huffman@39985
   270
    apply (rule chainE)
huffman@39985
   271
    apply (rule chain_udom_approx)
huffman@39989
   272
    apply (subst cast_defl_principal)
huffman@39985
   273
    apply (simp add: Abs_fin_defl_inverse finite_deflation_udom_approx)
huffman@33504
   274
    done
huffman@33504
   275
qed
huffman@33504
   276
huffman@39985
   277
end
huffman@39985
   278
huffman@39987
   279
subsection {* Continuous function space is a bifinite domain *}
huffman@39985
   280
huffman@39986
   281
instantiation cfun :: (bifinite, bifinite) bifinite
huffman@39985
   282
begin
huffman@39985
   283
huffman@39985
   284
definition
huffman@39985
   285
  "emb = udom_emb cfun_approx oo cfun_map\<cdot>prj\<cdot>emb"
huffman@39985
   286
huffman@39985
   287
definition
huffman@39985
   288
  "prj = cfun_map\<cdot>emb\<cdot>prj oo udom_prj cfun_approx"
huffman@39985
   289
huffman@39985
   290
definition
huffman@39989
   291
  "defl (t::('a \<rightarrow> 'b) itself) = cfun_defl\<cdot>DEFL('a)\<cdot>DEFL('b)"
huffman@39985
   292
huffman@39985
   293
instance proof
huffman@39985
   294
  show "ep_pair emb (prj :: udom \<rightarrow> 'a \<rightarrow> 'b)"
huffman@39985
   295
    unfolding emb_cfun_def prj_cfun_def
huffman@39985
   296
    using ep_pair_udom [OF cfun_approx]
huffman@39985
   297
    by (intro ep_pair_comp ep_pair_cfun_map ep_pair_emb_prj)
huffman@39985
   298
next
huffman@39989
   299
  show "cast\<cdot>DEFL('a \<rightarrow> 'b) = emb oo (prj :: udom \<rightarrow> 'a \<rightarrow> 'b)"
huffman@39989
   300
    unfolding emb_cfun_def prj_cfun_def defl_cfun_def cast_cfun_defl
huffman@40002
   301
    by (simp add: cast_DEFL oo_def cfun_eq_iff cfun_map_map)
huffman@27402
   302
qed
huffman@25903
   303
huffman@39985
   304
end
huffman@33504
   305
huffman@39989
   306
lemma DEFL_cfun:
huffman@39989
   307
  "DEFL('a::bifinite \<rightarrow> 'b::bifinite) = cfun_defl\<cdot>DEFL('a)\<cdot>DEFL('b)"
huffman@39989
   308
by (rule defl_cfun_def)
brianh@39972
   309
huffman@39987
   310
subsection {* Cartesian product is a bifinite domain *}
huffman@39987
   311
huffman@39987
   312
instantiation prod :: (bifinite, bifinite) bifinite
huffman@39987
   313
begin
huffman@39987
   314
huffman@39987
   315
definition
huffman@39987
   316
  "emb = udom_emb prod_approx oo cprod_map\<cdot>emb\<cdot>emb"
huffman@39987
   317
huffman@39987
   318
definition
huffman@39987
   319
  "prj = cprod_map\<cdot>prj\<cdot>prj oo udom_prj prod_approx"
huffman@39987
   320
huffman@39987
   321
definition
huffman@39989
   322
  "defl (t::('a \<times> 'b) itself) = prod_defl\<cdot>DEFL('a)\<cdot>DEFL('b)"
huffman@39987
   323
huffman@39987
   324
instance proof
huffman@39987
   325
  show "ep_pair emb (prj :: udom \<rightarrow> 'a \<times> 'b)"
huffman@39987
   326
    unfolding emb_prod_def prj_prod_def
huffman@39987
   327
    using ep_pair_udom [OF prod_approx]
huffman@39987
   328
    by (intro ep_pair_comp ep_pair_cprod_map ep_pair_emb_prj)
huffman@39987
   329
next
huffman@39989
   330
  show "cast\<cdot>DEFL('a \<times> 'b) = emb oo (prj :: udom \<rightarrow> 'a \<times> 'b)"
huffman@39989
   331
    unfolding emb_prod_def prj_prod_def defl_prod_def cast_prod_defl
huffman@40002
   332
    by (simp add: cast_DEFL oo_def cfun_eq_iff cprod_map_map)
huffman@39987
   333
qed
huffman@39987
   334
huffman@26962
   335
end
huffman@39987
   336
huffman@39989
   337
lemma DEFL_prod:
huffman@39989
   338
  "DEFL('a::bifinite \<times> 'b::bifinite) = prod_defl\<cdot>DEFL('a)\<cdot>DEFL('b)"
huffman@39989
   339
by (rule defl_prod_def)
huffman@39987
   340
huffman@39987
   341
subsection {* Strict product is a bifinite domain *}
huffman@39987
   342
huffman@39987
   343
instantiation sprod :: (bifinite, bifinite) bifinite
huffman@39987
   344
begin
huffman@39987
   345
huffman@39987
   346
definition
huffman@39987
   347
  "emb = udom_emb sprod_approx oo sprod_map\<cdot>emb\<cdot>emb"
huffman@39987
   348
huffman@39987
   349
definition
huffman@39987
   350
  "prj = sprod_map\<cdot>prj\<cdot>prj oo udom_prj sprod_approx"
huffman@39987
   351
huffman@39987
   352
definition
huffman@39989
   353
  "defl (t::('a \<otimes> 'b) itself) = sprod_defl\<cdot>DEFL('a)\<cdot>DEFL('b)"
huffman@39987
   354
huffman@39987
   355
instance proof
huffman@39987
   356
  show "ep_pair emb (prj :: udom \<rightarrow> 'a \<otimes> 'b)"
huffman@39987
   357
    unfolding emb_sprod_def prj_sprod_def
huffman@39987
   358
    using ep_pair_udom [OF sprod_approx]
huffman@39987
   359
    by (intro ep_pair_comp ep_pair_sprod_map ep_pair_emb_prj)
huffman@39987
   360
next
huffman@39989
   361
  show "cast\<cdot>DEFL('a \<otimes> 'b) = emb oo (prj :: udom \<rightarrow> 'a \<otimes> 'b)"
huffman@39989
   362
    unfolding emb_sprod_def prj_sprod_def defl_sprod_def cast_sprod_defl
huffman@40002
   363
    by (simp add: cast_DEFL oo_def cfun_eq_iff sprod_map_map)
huffman@39987
   364
qed
huffman@39987
   365
huffman@39987
   366
end
huffman@39987
   367
huffman@39989
   368
lemma DEFL_sprod:
huffman@39989
   369
  "DEFL('a::bifinite \<otimes> 'b::bifinite) = sprod_defl\<cdot>DEFL('a)\<cdot>DEFL('b)"
huffman@39989
   370
by (rule defl_sprod_def)
huffman@39987
   371
huffman@39987
   372
subsection {* Lifted cpo is a bifinite domain *}
huffman@39987
   373
huffman@39987
   374
instantiation u :: (bifinite) bifinite
huffman@39987
   375
begin
huffman@39987
   376
huffman@39987
   377
definition
huffman@39987
   378
  "emb = udom_emb u_approx oo u_map\<cdot>emb"
huffman@39987
   379
huffman@39987
   380
definition
huffman@39987
   381
  "prj = u_map\<cdot>prj oo udom_prj u_approx"
huffman@39987
   382
huffman@39987
   383
definition
huffman@39989
   384
  "defl (t::'a u itself) = u_defl\<cdot>DEFL('a)"
huffman@39987
   385
huffman@39987
   386
instance proof
huffman@39987
   387
  show "ep_pair emb (prj :: udom \<rightarrow> 'a u)"
huffman@39987
   388
    unfolding emb_u_def prj_u_def
huffman@39987
   389
    using ep_pair_udom [OF u_approx]
huffman@39987
   390
    by (intro ep_pair_comp ep_pair_u_map ep_pair_emb_prj)
huffman@39987
   391
next
huffman@39989
   392
  show "cast\<cdot>DEFL('a u) = emb oo (prj :: udom \<rightarrow> 'a u)"
huffman@39989
   393
    unfolding emb_u_def prj_u_def defl_u_def cast_u_defl
huffman@40002
   394
    by (simp add: cast_DEFL oo_def cfun_eq_iff u_map_map)
huffman@39987
   395
qed
huffman@39987
   396
huffman@39987
   397
end
huffman@39987
   398
huffman@39989
   399
lemma DEFL_u: "DEFL('a::bifinite u) = u_defl\<cdot>DEFL('a)"
huffman@39989
   400
by (rule defl_u_def)
huffman@39987
   401
huffman@39987
   402
subsection {* Lifted countable types are bifinite domains *}
huffman@39987
   403
huffman@39987
   404
definition
huffman@39987
   405
  lift_approx :: "nat \<Rightarrow> 'a::countable lift \<rightarrow> 'a lift"
huffman@39987
   406
where
huffman@39987
   407
  "lift_approx = (\<lambda>i. FLIFT x. if to_nat x < i then Def x else \<bottom>)"
huffman@39987
   408
huffman@39987
   409
lemma chain_lift_approx [simp]: "chain lift_approx"
huffman@39987
   410
  unfolding lift_approx_def
huffman@39987
   411
  by (rule chainI, simp add: FLIFT_mono)
huffman@39987
   412
huffman@39987
   413
lemma lub_lift_approx [simp]: "(\<Squnion>i. lift_approx i) = ID"
huffman@40002
   414
apply (rule cfun_eqI)
huffman@39987
   415
apply (simp add: contlub_cfun_fun)
huffman@39987
   416
apply (simp add: lift_approx_def)
huffman@39987
   417
apply (case_tac x, simp)
huffman@39987
   418
apply (rule thelubI)
huffman@39987
   419
apply (rule is_lubI)
huffman@39987
   420
apply (rule ub_rangeI, simp)
huffman@39987
   421
apply (drule ub_rangeD)
huffman@39987
   422
apply (erule rev_below_trans)
huffman@39987
   423
apply simp
huffman@39987
   424
apply (rule lessI)
huffman@39987
   425
done
huffman@39987
   426
huffman@39987
   427
lemma finite_deflation_lift_approx: "finite_deflation (lift_approx i)"
huffman@39987
   428
proof
huffman@40012
   429
  fix x :: "'a lift"
huffman@39987
   430
  show "lift_approx i\<cdot>x \<sqsubseteq> x"
huffman@39987
   431
    unfolding lift_approx_def
huffman@39987
   432
    by (cases x, simp, simp)
huffman@39987
   433
  show "lift_approx i\<cdot>(lift_approx i\<cdot>x) = lift_approx i\<cdot>x"
huffman@39987
   434
    unfolding lift_approx_def
huffman@39987
   435
    by (cases x, simp, simp)
huffman@39987
   436
  show "finite {x::'a lift. lift_approx i\<cdot>x = x}"
huffman@39987
   437
  proof (rule finite_subset)
huffman@39987
   438
    let ?S = "insert (\<bottom>::'a lift) (Def ` to_nat -` {..<i})"
huffman@39987
   439
    show "{x::'a lift. lift_approx i\<cdot>x = x} \<subseteq> ?S"
huffman@39987
   440
      unfolding lift_approx_def
huffman@39987
   441
      by (rule subsetI, case_tac x, simp, simp split: split_if_asm)
huffman@39987
   442
    show "finite ?S"
huffman@39987
   443
      by (simp add: finite_vimageI)
huffman@39987
   444
  qed
huffman@39987
   445
qed
huffman@39987
   446
huffman@39987
   447
lemma lift_approx: "approx_chain lift_approx"
huffman@39987
   448
using chain_lift_approx lub_lift_approx finite_deflation_lift_approx
huffman@39987
   449
by (rule approx_chain.intro)
huffman@39987
   450
huffman@39987
   451
instantiation lift :: (countable) bifinite
huffman@39987
   452
begin
huffman@39987
   453
huffman@39987
   454
definition
huffman@39987
   455
  "emb = udom_emb lift_approx"
huffman@39987
   456
huffman@39987
   457
definition
huffman@39987
   458
  "prj = udom_prj lift_approx"
huffman@39987
   459
huffman@39987
   460
definition
huffman@39989
   461
  "defl (t::'a lift itself) =
huffman@39989
   462
    (\<Squnion>i. defl_principal (Abs_fin_defl (emb oo lift_approx i oo prj)))"
huffman@39987
   463
huffman@39987
   464
instance proof
huffman@39987
   465
  show ep: "ep_pair emb (prj :: udom \<rightarrow> 'a lift)"
huffman@39987
   466
    unfolding emb_lift_def prj_lift_def
huffman@39987
   467
    by (rule ep_pair_udom [OF lift_approx])
huffman@39989
   468
  show "cast\<cdot>DEFL('a lift) = emb oo (prj :: udom \<rightarrow> 'a lift)"
huffman@39989
   469
    unfolding defl_lift_def
huffman@39987
   470
    apply (subst contlub_cfun_arg)
huffman@39987
   471
    apply (rule chainI)
huffman@39989
   472
    apply (rule defl.principal_mono)
huffman@39987
   473
    apply (simp add: below_fin_defl_def)
huffman@39987
   474
    apply (simp add: Abs_fin_defl_inverse finite_deflation_lift_approx
huffman@39987
   475
                     ep_pair.finite_deflation_e_d_p [OF ep])
huffman@39987
   476
    apply (intro monofun_cfun below_refl)
huffman@39987
   477
    apply (rule chainE)
huffman@39987
   478
    apply (rule chain_lift_approx)
huffman@39989
   479
    apply (subst cast_defl_principal)
huffman@39987
   480
    apply (simp add: Abs_fin_defl_inverse finite_deflation_lift_approx
huffman@39987
   481
                     ep_pair.finite_deflation_e_d_p [OF ep] lub_distribs)
huffman@39987
   482
    done
huffman@39987
   483
qed
huffman@39987
   484
huffman@39987
   485
end
huffman@39987
   486
huffman@39987
   487
subsection {* Strict sum is a bifinite domain *}
huffman@39987
   488
huffman@39987
   489
instantiation ssum :: (bifinite, bifinite) bifinite
huffman@39987
   490
begin
huffman@39987
   491
huffman@39987
   492
definition
huffman@39987
   493
  "emb = udom_emb ssum_approx oo ssum_map\<cdot>emb\<cdot>emb"
huffman@39987
   494
huffman@39987
   495
definition
huffman@39987
   496
  "prj = ssum_map\<cdot>prj\<cdot>prj oo udom_prj ssum_approx"
huffman@39987
   497
huffman@39987
   498
definition
huffman@39989
   499
  "defl (t::('a \<oplus> 'b) itself) = ssum_defl\<cdot>DEFL('a)\<cdot>DEFL('b)"
huffman@39987
   500
huffman@39987
   501
instance proof
huffman@39987
   502
  show "ep_pair emb (prj :: udom \<rightarrow> 'a \<oplus> 'b)"
huffman@39987
   503
    unfolding emb_ssum_def prj_ssum_def
huffman@39987
   504
    using ep_pair_udom [OF ssum_approx]
huffman@39987
   505
    by (intro ep_pair_comp ep_pair_ssum_map ep_pair_emb_prj)
huffman@39987
   506
next
huffman@39989
   507
  show "cast\<cdot>DEFL('a \<oplus> 'b) = emb oo (prj :: udom \<rightarrow> 'a \<oplus> 'b)"
huffman@39989
   508
    unfolding emb_ssum_def prj_ssum_def defl_ssum_def cast_ssum_defl
huffman@40002
   509
    by (simp add: cast_DEFL oo_def cfun_eq_iff ssum_map_map)
huffman@39987
   510
qed
huffman@39987
   511
huffman@39987
   512
end
huffman@39987
   513
huffman@39989
   514
lemma DEFL_ssum:
huffman@39989
   515
  "DEFL('a::bifinite \<oplus> 'b::bifinite) = ssum_defl\<cdot>DEFL('a)\<cdot>DEFL('b)"
huffman@39989
   516
by (rule defl_ssum_def)
huffman@39987
   517
huffman@39987
   518
end