src/HOL/HOLCF/Representable.thy
author wenzelm
Mon Apr 25 16:09:26 2016 +0200 (2016-04-25)
changeset 63040 eb4ddd18d635
parent 62175 8ffc4d0e652d
child 66453 cc19f7ca2ed6
permissions -rw-r--r--
eliminated old 'def';
tuned comments;
wenzelm@42151
     1
(*  Title:      HOL/HOLCF/Representable.thy
huffman@25903
     2
    Author:     Brian Huffman
huffman@25903
     3
*)
huffman@25903
     4
wenzelm@62175
     5
section \<open>Representable domains\<close>
huffman@25903
     6
huffman@41285
     7
theory Representable
wenzelm@44781
     8
imports Algebraic Map_Functions "~~/src/HOL/Library/Countable"
huffman@25903
     9
begin
huffman@25903
    10
huffman@41292
    11
default_sort cpo
huffman@41292
    12
wenzelm@62175
    13
subsection \<open>Class of representable domains\<close>
huffman@39985
    14
wenzelm@62175
    15
text \<open>
huffman@40497
    16
  We define a ``domain'' as a pcpo that is isomorphic to some
huffman@40497
    17
  algebraic deflation over the universal domain; this is equivalent
huffman@40497
    18
  to being omega-bifinite.
huffman@40491
    19
huffman@40497
    20
  A predomain is a cpo that, when lifted, becomes a domain.
huffman@41292
    21
  Predomains are represented by deflations over a lifted universal
huffman@41292
    22
  domain type.
wenzelm@62175
    23
\<close>
huffman@39985
    24
huffman@41292
    25
class predomain_syn = cpo +
huffman@41292
    26
  fixes liftemb :: "'a\<^sub>\<bottom> \<rightarrow> udom\<^sub>\<bottom>"
huffman@41292
    27
  fixes liftprj :: "udom\<^sub>\<bottom> \<rightarrow> 'a\<^sub>\<bottom>"
huffman@41292
    28
  fixes liftdefl :: "'a itself \<Rightarrow> udom u defl"
huffman@41292
    29
huffman@41292
    30
class predomain = predomain_syn +
huffman@40491
    31
  assumes predomain_ep: "ep_pair liftemb liftprj"
huffman@41292
    32
  assumes cast_liftdefl: "cast\<cdot>(liftdefl TYPE('a)) = liftemb oo liftprj"
huffman@40491
    33
huffman@40491
    34
syntax "_LIFTDEFL" :: "type \<Rightarrow> logic"  ("(1LIFTDEFL/(1'(_')))")
huffman@40491
    35
translations "LIFTDEFL('t)" \<rightleftharpoons> "CONST liftdefl TYPE('t)"
huffman@40491
    36
huffman@41436
    37
definition liftdefl_of :: "udom defl \<rightarrow> udom u defl"
huffman@41436
    38
  where "liftdefl_of = defl_fun1 ID ID u_map"
huffman@41292
    39
huffman@41436
    40
lemma cast_liftdefl_of: "cast\<cdot>(liftdefl_of\<cdot>t) = u_map\<cdot>(cast\<cdot>t)"
huffman@41436
    41
by (simp add: liftdefl_of_def cast_defl_fun1 ep_pair_def finite_deflation_u_map)
huffman@41292
    42
huffman@41292
    43
class "domain" = predomain_syn + pcpo +
huffman@41292
    44
  fixes emb :: "'a \<rightarrow> udom"
huffman@41292
    45
  fixes prj :: "udom \<rightarrow> 'a"
huffman@41287
    46
  fixes defl :: "'a itself \<Rightarrow> udom defl"
huffman@39985
    47
  assumes ep_pair_emb_prj: "ep_pair emb prj"
huffman@39989
    48
  assumes cast_DEFL: "cast\<cdot>(defl TYPE('a)) = emb oo prj"
huffman@41292
    49
  assumes liftemb_eq: "liftemb = u_map\<cdot>emb"
huffman@41292
    50
  assumes liftprj_eq: "liftprj = u_map\<cdot>prj"
huffman@41436
    51
  assumes liftdefl_eq: "liftdefl TYPE('a) = liftdefl_of\<cdot>(defl TYPE('a))"
huffman@31113
    52
huffman@41287
    53
syntax "_DEFL" :: "type \<Rightarrow> logic"  ("(1DEFL/(1'(_')))")
huffman@39989
    54
translations "DEFL('t)" \<rightleftharpoons> "CONST defl TYPE('t)"
huffman@39985
    55
huffman@41292
    56
instance "domain" \<subseteq> predomain
huffman@41292
    57
proof
huffman@41292
    58
  show "ep_pair liftemb (liftprj::udom\<^sub>\<bottom> \<rightarrow> 'a\<^sub>\<bottom>)"
huffman@41292
    59
    unfolding liftemb_eq liftprj_eq
huffman@41292
    60
    by (intro ep_pair_u_map ep_pair_emb_prj)
huffman@41292
    61
  show "cast\<cdot>LIFTDEFL('a) = liftemb oo (liftprj::udom\<^sub>\<bottom> \<rightarrow> 'a\<^sub>\<bottom>)"
huffman@41292
    62
    unfolding liftemb_eq liftprj_eq liftdefl_eq
huffman@41436
    63
    by (simp add: cast_liftdefl_of cast_DEFL u_map_oo)
huffman@41292
    64
qed
huffman@41292
    65
wenzelm@62175
    66
text \<open>
huffman@41292
    67
  Constants @{const liftemb} and @{const liftprj} imply class predomain.
wenzelm@62175
    68
\<close>
huffman@41292
    69
wenzelm@62175
    70
setup \<open>
huffman@41292
    71
  fold Sign.add_const_constraint
huffman@41292
    72
  [(@{const_name liftemb}, SOME @{typ "'a::predomain u \<rightarrow> udom u"}),
huffman@41292
    73
   (@{const_name liftprj}, SOME @{typ "udom u \<rightarrow> 'a::predomain u"}),
huffman@41292
    74
   (@{const_name liftdefl}, SOME @{typ "'a::predomain itself \<Rightarrow> udom u defl"})]
wenzelm@62175
    75
\<close>
huffman@41292
    76
huffman@41292
    77
interpretation predomain: pcpo_ep_pair liftemb liftprj
huffman@41292
    78
  unfolding pcpo_ep_pair_def by (rule predomain_ep)
huffman@41292
    79
huffman@40497
    80
interpretation "domain": pcpo_ep_pair emb prj
huffman@41292
    81
  unfolding pcpo_ep_pair_def by (rule ep_pair_emb_prj)
huffman@33504
    82
huffman@40497
    83
lemmas emb_inverse = domain.e_inverse
huffman@40497
    84
lemmas emb_prj_below = domain.e_p_below
huffman@40497
    85
lemmas emb_eq_iff = domain.e_eq_iff
huffman@40497
    86
lemmas emb_strict = domain.e_strict
huffman@40497
    87
lemmas prj_strict = domain.p_strict
huffman@33504
    88
wenzelm@62175
    89
subsection \<open>Domains are bifinite\<close>
huffman@33587
    90
huffman@41286
    91
lemma approx_chain_ep_cast:
huffman@41292
    92
  assumes ep: "ep_pair (e::'a::pcpo \<rightarrow> 'b::bifinite) (p::'b \<rightarrow> 'a)"
huffman@41286
    93
  assumes cast_t: "cast\<cdot>t = e oo p"
huffman@41287
    94
  shows "\<exists>(a::nat \<Rightarrow> 'a::pcpo \<rightarrow> 'a). approx_chain a"
huffman@39985
    95
proof -
huffman@41286
    96
  interpret ep_pair e p by fact
huffman@39985
    97
  obtain Y where Y: "\<forall>i. Y i \<sqsubseteq> Y (Suc i)"
huffman@41286
    98
  and t: "t = (\<Squnion>i. defl_principal (Y i))"
huffman@39989
    99
    by (rule defl.obtain_principal_chain)
wenzelm@63040
   100
  define approx where "approx i = (p oo cast\<cdot>(defl_principal (Y i)) oo e)" for i
huffman@41286
   101
  have "approx_chain approx"
huffman@39985
   102
  proof (rule approx_chain.intro)
huffman@39985
   103
    show "chain (\<lambda>i. approx i)"
huffman@39985
   104
      unfolding approx_def by (simp add: Y)
huffman@39985
   105
    show "(\<Squnion>i. approx i) = ID"
huffman@39985
   106
      unfolding approx_def
huffman@41286
   107
      by (simp add: lub_distribs Y t [symmetric] cast_t cfun_eq_iff)
huffman@39985
   108
    show "\<And>i. finite_deflation (approx i)"
huffman@39985
   109
      unfolding approx_def
huffman@41286
   110
      apply (rule finite_deflation_p_d_e)
huffman@39985
   111
      apply (rule finite_deflation_cast)
huffman@39989
   112
      apply (rule defl.compact_principal)
huffman@39985
   113
      apply (rule below_trans [OF monofun_cfun_fun])
huffman@39985
   114
      apply (rule is_ub_thelub, simp add: Y)
huffman@41286
   115
      apply (simp add: lub_distribs Y t [symmetric] cast_t)
huffman@39985
   116
      done
huffman@39985
   117
  qed
huffman@41286
   118
  thus "\<exists>(a::nat \<Rightarrow> 'a \<rightarrow> 'a). approx_chain a" by - (rule exI)
huffman@33504
   119
qed
huffman@33504
   120
huffman@41286
   121
instance "domain" \<subseteq> bifinite
wenzelm@61169
   122
by standard (rule approx_chain_ep_cast [OF ep_pair_emb_prj cast_DEFL])
huffman@41286
   123
huffman@41286
   124
instance predomain \<subseteq> profinite
wenzelm@61169
   125
by standard (rule approx_chain_ep_cast [OF predomain_ep cast_liftdefl])
huffman@41286
   126
wenzelm@62175
   127
subsection \<open>Universal domain ep-pairs\<close>
huffman@40484
   128
huffman@41290
   129
definition "u_emb = udom_emb (\<lambda>i. u_map\<cdot>(udom_approx i))"
huffman@41290
   130
definition "u_prj = udom_prj (\<lambda>i. u_map\<cdot>(udom_approx i))"
huffman@40484
   131
huffman@41297
   132
definition "prod_emb = udom_emb (\<lambda>i. prod_map\<cdot>(udom_approx i)\<cdot>(udom_approx i))"
huffman@41297
   133
definition "prod_prj = udom_prj (\<lambda>i. prod_map\<cdot>(udom_approx i)\<cdot>(udom_approx i))"
huffman@40484
   134
huffman@41290
   135
definition "sprod_emb = udom_emb (\<lambda>i. sprod_map\<cdot>(udom_approx i)\<cdot>(udom_approx i))"
huffman@41290
   136
definition "sprod_prj = udom_prj (\<lambda>i. sprod_map\<cdot>(udom_approx i)\<cdot>(udom_approx i))"
huffman@40484
   137
huffman@41290
   138
definition "ssum_emb = udom_emb (\<lambda>i. ssum_map\<cdot>(udom_approx i)\<cdot>(udom_approx i))"
huffman@41290
   139
definition "ssum_prj = udom_prj (\<lambda>i. ssum_map\<cdot>(udom_approx i)\<cdot>(udom_approx i))"
huffman@41290
   140
huffman@41290
   141
definition "sfun_emb = udom_emb (\<lambda>i. sfun_map\<cdot>(udom_approx i)\<cdot>(udom_approx i))"
huffman@41290
   142
definition "sfun_prj = udom_prj (\<lambda>i. sfun_map\<cdot>(udom_approx i)\<cdot>(udom_approx i))"
huffman@40484
   143
huffman@41290
   144
lemma ep_pair_u: "ep_pair u_emb u_prj"
huffman@41290
   145
  unfolding u_emb_def u_prj_def
huffman@41290
   146
  by (simp add: ep_pair_udom approx_chain_u_map)
huffman@40484
   147
huffman@41290
   148
lemma ep_pair_prod: "ep_pair prod_emb prod_prj"
huffman@41290
   149
  unfolding prod_emb_def prod_prj_def
huffman@41297
   150
  by (simp add: ep_pair_udom approx_chain_prod_map)
huffman@40484
   151
huffman@41290
   152
lemma ep_pair_sprod: "ep_pair sprod_emb sprod_prj"
huffman@41290
   153
  unfolding sprod_emb_def sprod_prj_def
huffman@41290
   154
  by (simp add: ep_pair_udom approx_chain_sprod_map)
huffman@40484
   155
huffman@41290
   156
lemma ep_pair_ssum: "ep_pair ssum_emb ssum_prj"
huffman@41290
   157
  unfolding ssum_emb_def ssum_prj_def
huffman@41290
   158
  by (simp add: ep_pair_udom approx_chain_ssum_map)
huffman@40484
   159
huffman@41290
   160
lemma ep_pair_sfun: "ep_pair sfun_emb sfun_prj"
huffman@41290
   161
  unfolding sfun_emb_def sfun_prj_def
huffman@41290
   162
  by (simp add: ep_pair_udom approx_chain_sfun_map)
huffman@40484
   163
wenzelm@62175
   164
subsection \<open>Type combinators\<close>
huffman@39985
   165
huffman@41437
   166
definition u_defl :: "udom defl \<rightarrow> udom defl"
huffman@41437
   167
  where "u_defl = defl_fun1 u_emb u_prj u_map"
huffman@39985
   168
huffman@41290
   169
definition prod_defl :: "udom defl \<rightarrow> udom defl \<rightarrow> udom defl"
huffman@41297
   170
  where "prod_defl = defl_fun2 prod_emb prod_prj prod_map"
huffman@33504
   171
huffman@41290
   172
definition sprod_defl :: "udom defl \<rightarrow> udom defl \<rightarrow> udom defl"
huffman@41290
   173
  where "sprod_defl = defl_fun2 sprod_emb sprod_prj sprod_map"
huffman@33504
   174
huffman@41290
   175
definition ssum_defl :: "udom defl \<rightarrow> udom defl \<rightarrow> udom defl"
huffman@41290
   176
where "ssum_defl = defl_fun2 ssum_emb ssum_prj ssum_map"
huffman@40484
   177
huffman@41287
   178
definition sfun_defl :: "udom defl \<rightarrow> udom defl \<rightarrow> udom defl"
huffman@41290
   179
  where "sfun_defl = defl_fun2 sfun_emb sfun_prj sfun_map"
huffman@40484
   180
huffman@40484
   181
lemma cast_u_defl:
huffman@41437
   182
  "cast\<cdot>(u_defl\<cdot>A) = u_emb oo u_map\<cdot>(cast\<cdot>A) oo u_prj"
huffman@41437
   183
using ep_pair_u finite_deflation_u_map
huffman@41437
   184
unfolding u_defl_def by (rule cast_defl_fun1)
huffman@40484
   185
huffman@40484
   186
lemma cast_prod_defl:
huffman@41290
   187
  "cast\<cdot>(prod_defl\<cdot>A\<cdot>B) =
huffman@41297
   188
    prod_emb oo prod_map\<cdot>(cast\<cdot>A)\<cdot>(cast\<cdot>B) oo prod_prj"
huffman@41297
   189
using ep_pair_prod finite_deflation_prod_map
huffman@40484
   190
unfolding prod_defl_def by (rule cast_defl_fun2)
huffman@40484
   191
huffman@40484
   192
lemma cast_sprod_defl:
huffman@40484
   193
  "cast\<cdot>(sprod_defl\<cdot>A\<cdot>B) =
huffman@41290
   194
    sprod_emb oo sprod_map\<cdot>(cast\<cdot>A)\<cdot>(cast\<cdot>B) oo sprod_prj"
huffman@41290
   195
using ep_pair_sprod finite_deflation_sprod_map
huffman@40484
   196
unfolding sprod_defl_def by (rule cast_defl_fun2)
huffman@40484
   197
huffman@40484
   198
lemma cast_ssum_defl:
huffman@40484
   199
  "cast\<cdot>(ssum_defl\<cdot>A\<cdot>B) =
huffman@41290
   200
    ssum_emb oo ssum_map\<cdot>(cast\<cdot>A)\<cdot>(cast\<cdot>B) oo ssum_prj"
huffman@41290
   201
using ep_pair_ssum finite_deflation_ssum_map
huffman@40484
   202
unfolding ssum_defl_def by (rule cast_defl_fun2)
huffman@40484
   203
huffman@41290
   204
lemma cast_sfun_defl:
huffman@41290
   205
  "cast\<cdot>(sfun_defl\<cdot>A\<cdot>B) =
huffman@41290
   206
    sfun_emb oo sfun_map\<cdot>(cast\<cdot>A)\<cdot>(cast\<cdot>B) oo sfun_prj"
huffman@41290
   207
using ep_pair_sfun finite_deflation_sfun_map
huffman@41290
   208
unfolding sfun_defl_def by (rule cast_defl_fun2)
huffman@41290
   209
wenzelm@62175
   210
text \<open>Special deflation combinator for unpointed types.\<close>
huffman@41437
   211
huffman@41437
   212
definition u_liftdefl :: "udom u defl \<rightarrow> udom defl"
huffman@41437
   213
  where "u_liftdefl = defl_fun1 u_emb u_prj ID"
huffman@41437
   214
huffman@41437
   215
lemma cast_u_liftdefl:
huffman@41437
   216
  "cast\<cdot>(u_liftdefl\<cdot>A) = u_emb oo cast\<cdot>A oo u_prj"
huffman@41437
   217
unfolding u_liftdefl_def by (simp add: cast_defl_fun1 ep_pair_u)
huffman@41437
   218
huffman@41437
   219
lemma u_liftdefl_liftdefl_of:
huffman@41437
   220
  "u_liftdefl\<cdot>(liftdefl_of\<cdot>A) = u_defl\<cdot>A"
huffman@41437
   221
by (rule cast_eq_imp_eq)
huffman@41437
   222
   (simp add: cast_u_liftdefl cast_liftdefl_of cast_u_defl)
huffman@41437
   223
wenzelm@62175
   224
subsection \<open>Class instance proofs\<close>
huffman@40506
   225
wenzelm@62175
   226
subsubsection \<open>Universal domain\<close>
huffman@39985
   227
huffman@41292
   228
instantiation udom :: "domain"
huffman@39985
   229
begin
huffman@39985
   230
huffman@39985
   231
definition [simp]:
huffman@39985
   232
  "emb = (ID :: udom \<rightarrow> udom)"
huffman@39985
   233
huffman@39985
   234
definition [simp]:
huffman@39985
   235
  "prj = (ID :: udom \<rightarrow> udom)"
huffman@25903
   236
huffman@33504
   237
definition
huffman@39989
   238
  "defl (t::udom itself) = (\<Squnion>i. defl_principal (Abs_fin_defl (udom_approx i)))"
huffman@33808
   239
huffman@40491
   240
definition
huffman@41292
   241
  "(liftemb :: udom u \<rightarrow> udom u) = u_map\<cdot>emb"
huffman@40491
   242
huffman@40491
   243
definition
huffman@41292
   244
  "(liftprj :: udom u \<rightarrow> udom u) = u_map\<cdot>prj"
huffman@40491
   245
huffman@41292
   246
definition
huffman@41436
   247
  "liftdefl (t::udom itself) = liftdefl_of\<cdot>DEFL(udom)"
huffman@41292
   248
huffman@41292
   249
instance proof
huffman@39985
   250
  show "ep_pair emb (prj :: udom \<rightarrow> udom)"
huffman@39985
   251
    by (simp add: ep_pair.intro)
huffman@39989
   252
  show "cast\<cdot>DEFL(udom) = emb oo (prj :: udom \<rightarrow> udom)"
huffman@39989
   253
    unfolding defl_udom_def
huffman@39985
   254
    apply (subst contlub_cfun_arg)
huffman@39985
   255
    apply (rule chainI)
huffman@39989
   256
    apply (rule defl.principal_mono)
huffman@39985
   257
    apply (simp add: below_fin_defl_def)
huffman@39985
   258
    apply (simp add: Abs_fin_defl_inverse finite_deflation_udom_approx)
huffman@39985
   259
    apply (rule chainE)
huffman@39985
   260
    apply (rule chain_udom_approx)
huffman@39989
   261
    apply (subst cast_defl_principal)
huffman@39985
   262
    apply (simp add: Abs_fin_defl_inverse finite_deflation_udom_approx)
huffman@33504
   263
    done
huffman@41292
   264
qed (fact liftemb_udom_def liftprj_udom_def liftdefl_udom_def)+
huffman@33504
   265
huffman@39985
   266
end
huffman@39985
   267
wenzelm@62175
   268
subsubsection \<open>Lifted cpo\<close>
huffman@40491
   269
huffman@41292
   270
instantiation u :: (predomain) "domain"
huffman@40491
   271
begin
huffman@40491
   272
huffman@40491
   273
definition
huffman@41292
   274
  "emb = u_emb oo liftemb"
huffman@40491
   275
huffman@40491
   276
definition
huffman@41292
   277
  "prj = liftprj oo u_prj"
huffman@40491
   278
huffman@40491
   279
definition
huffman@41437
   280
  "defl (t::'a u itself) = u_liftdefl\<cdot>LIFTDEFL('a)"
huffman@40491
   281
huffman@40491
   282
definition
huffman@41292
   283
  "(liftemb :: 'a u u \<rightarrow> udom u) = u_map\<cdot>emb"
huffman@40491
   284
huffman@40491
   285
definition
huffman@41292
   286
  "(liftprj :: udom u \<rightarrow> 'a u u) = u_map\<cdot>prj"
huffman@40491
   287
huffman@40491
   288
definition
huffman@41436
   289
  "liftdefl (t::'a u itself) = liftdefl_of\<cdot>DEFL('a u)"
huffman@40491
   290
huffman@41292
   291
instance proof
huffman@40491
   292
  show "ep_pair emb (prj :: udom \<rightarrow> 'a u)"
huffman@40491
   293
    unfolding emb_u_def prj_u_def
huffman@41292
   294
    by (intro ep_pair_comp ep_pair_u predomain_ep)
huffman@40491
   295
  show "cast\<cdot>DEFL('a u) = emb oo (prj :: udom \<rightarrow> 'a u)"
huffman@40491
   296
    unfolding emb_u_def prj_u_def defl_u_def
huffman@41437
   297
    by (simp add: cast_u_liftdefl cast_liftdefl assoc_oo)
huffman@41292
   298
qed (fact liftemb_u_def liftprj_u_def liftdefl_u_def)+
huffman@40491
   299
huffman@40491
   300
end
huffman@40491
   301
huffman@41437
   302
lemma DEFL_u: "DEFL('a::predomain u) = u_liftdefl\<cdot>LIFTDEFL('a)"
huffman@40491
   303
by (rule defl_u_def)
huffman@40491
   304
wenzelm@62175
   305
subsubsection \<open>Strict function space\<close>
huffman@39985
   306
huffman@41292
   307
instantiation sfun :: ("domain", "domain") "domain"
huffman@39985
   308
begin
huffman@39985
   309
huffman@39985
   310
definition
huffman@41290
   311
  "emb = sfun_emb oo sfun_map\<cdot>prj\<cdot>emb"
huffman@40592
   312
huffman@40592
   313
definition
huffman@41290
   314
  "prj = sfun_map\<cdot>emb\<cdot>prj oo sfun_prj"
huffman@40592
   315
huffman@40592
   316
definition
huffman@40592
   317
  "defl (t::('a \<rightarrow>! 'b) itself) = sfun_defl\<cdot>DEFL('a)\<cdot>DEFL('b)"
huffman@40592
   318
huffman@40592
   319
definition
huffman@41292
   320
  "(liftemb :: ('a \<rightarrow>! 'b) u \<rightarrow> udom u) = u_map\<cdot>emb"
huffman@39985
   321
huffman@39985
   322
definition
huffman@41292
   323
  "(liftprj :: udom u \<rightarrow> ('a \<rightarrow>! 'b) u) = u_map\<cdot>prj"
huffman@40592
   324
huffman@41292
   325
definition
huffman@41436
   326
  "liftdefl (t::('a \<rightarrow>! 'b) itself) = liftdefl_of\<cdot>DEFL('a \<rightarrow>! 'b)"
huffman@41292
   327
huffman@41292
   328
instance proof
huffman@40592
   329
  show "ep_pair emb (prj :: udom \<rightarrow> 'a \<rightarrow>! 'b)"
huffman@40592
   330
    unfolding emb_sfun_def prj_sfun_def
huffman@41290
   331
    by (intro ep_pair_comp ep_pair_sfun ep_pair_sfun_map ep_pair_emb_prj)
huffman@40592
   332
  show "cast\<cdot>DEFL('a \<rightarrow>! 'b) = emb oo (prj :: udom \<rightarrow> 'a \<rightarrow>! 'b)"
huffman@40592
   333
    unfolding emb_sfun_def prj_sfun_def defl_sfun_def cast_sfun_defl
huffman@40592
   334
    by (simp add: cast_DEFL oo_def sfun_eq_iff sfun_map_map)
huffman@41292
   335
qed (fact liftemb_sfun_def liftprj_sfun_def liftdefl_sfun_def)+
huffman@40592
   336
huffman@40592
   337
end
huffman@40592
   338
huffman@40592
   339
lemma DEFL_sfun:
huffman@40592
   340
  "DEFL('a::domain \<rightarrow>! 'b::domain) = sfun_defl\<cdot>DEFL('a)\<cdot>DEFL('b)"
huffman@40592
   341
by (rule defl_sfun_def)
huffman@40592
   342
wenzelm@62175
   343
subsubsection \<open>Continuous function space\<close>
huffman@40592
   344
huffman@41292
   345
instantiation cfun :: (predomain, "domain") "domain"
huffman@40592
   346
begin
huffman@40592
   347
huffman@40592
   348
definition
huffman@40830
   349
  "emb = emb oo encode_cfun"
huffman@40592
   350
huffman@40592
   351
definition
huffman@40830
   352
  "prj = decode_cfun oo prj"
huffman@40592
   353
huffman@40592
   354
definition
huffman@40830
   355
  "defl (t::('a \<rightarrow> 'b) itself) = DEFL('a u \<rightarrow>! 'b)"
huffman@39985
   356
huffman@40491
   357
definition
huffman@41292
   358
  "(liftemb :: ('a \<rightarrow> 'b) u \<rightarrow> udom u) = u_map\<cdot>emb"
huffman@40491
   359
huffman@40491
   360
definition
huffman@41292
   361
  "(liftprj :: udom u \<rightarrow> ('a \<rightarrow> 'b) u) = u_map\<cdot>prj"
huffman@40491
   362
huffman@41292
   363
definition
huffman@41436
   364
  "liftdefl (t::('a \<rightarrow> 'b) itself) = liftdefl_of\<cdot>DEFL('a \<rightarrow> 'b)"
huffman@41292
   365
huffman@41292
   366
instance proof
huffman@40592
   367
  have "ep_pair encode_cfun decode_cfun"
huffman@40592
   368
    by (rule ep_pair.intro, simp_all)
huffman@40592
   369
  thus "ep_pair emb (prj :: udom \<rightarrow> 'a \<rightarrow> 'b)"
huffman@39985
   370
    unfolding emb_cfun_def prj_cfun_def
huffman@40830
   371
    using ep_pair_emb_prj by (rule ep_pair_comp)
huffman@39989
   372
  show "cast\<cdot>DEFL('a \<rightarrow> 'b) = emb oo (prj :: udom \<rightarrow> 'a \<rightarrow> 'b)"
huffman@40830
   373
    unfolding emb_cfun_def prj_cfun_def defl_cfun_def
huffman@40830
   374
    by (simp add: cast_DEFL cfcomp1)
huffman@41292
   375
qed (fact liftemb_cfun_def liftprj_cfun_def liftdefl_cfun_def)+
huffman@25903
   376
huffman@39985
   377
end
huffman@33504
   378
huffman@39989
   379
lemma DEFL_cfun:
huffman@40830
   380
  "DEFL('a::predomain \<rightarrow> 'b::domain) = DEFL('a u \<rightarrow>! 'b)"
huffman@39989
   381
by (rule defl_cfun_def)
brianh@39972
   382
wenzelm@62175
   383
subsubsection \<open>Strict product\<close>
huffman@39987
   384
huffman@41292
   385
instantiation sprod :: ("domain", "domain") "domain"
huffman@39987
   386
begin
huffman@39987
   387
huffman@39987
   388
definition
huffman@41290
   389
  "emb = sprod_emb oo sprod_map\<cdot>emb\<cdot>emb"
huffman@39987
   390
huffman@39987
   391
definition
huffman@41290
   392
  "prj = sprod_map\<cdot>prj\<cdot>prj oo sprod_prj"
huffman@39987
   393
huffman@39987
   394
definition
huffman@39989
   395
  "defl (t::('a \<otimes> 'b) itself) = sprod_defl\<cdot>DEFL('a)\<cdot>DEFL('b)"
huffman@39987
   396
huffman@40491
   397
definition
huffman@41292
   398
  "(liftemb :: ('a \<otimes> 'b) u \<rightarrow> udom u) = u_map\<cdot>emb"
huffman@40491
   399
huffman@40491
   400
definition
huffman@41292
   401
  "(liftprj :: udom u \<rightarrow> ('a \<otimes> 'b) u) = u_map\<cdot>prj"
huffman@40491
   402
huffman@41292
   403
definition
huffman@41436
   404
  "liftdefl (t::('a \<otimes> 'b) itself) = liftdefl_of\<cdot>DEFL('a \<otimes> 'b)"
huffman@41292
   405
huffman@41292
   406
instance proof
huffman@39987
   407
  show "ep_pair emb (prj :: udom \<rightarrow> 'a \<otimes> 'b)"
huffman@39987
   408
    unfolding emb_sprod_def prj_sprod_def
huffman@41290
   409
    by (intro ep_pair_comp ep_pair_sprod ep_pair_sprod_map ep_pair_emb_prj)
huffman@39989
   410
  show "cast\<cdot>DEFL('a \<otimes> 'b) = emb oo (prj :: udom \<rightarrow> 'a \<otimes> 'b)"
huffman@39989
   411
    unfolding emb_sprod_def prj_sprod_def defl_sprod_def cast_sprod_defl
huffman@40002
   412
    by (simp add: cast_DEFL oo_def cfun_eq_iff sprod_map_map)
huffman@41292
   413
qed (fact liftemb_sprod_def liftprj_sprod_def liftdefl_sprod_def)+
huffman@39987
   414
huffman@39987
   415
end
huffman@39987
   416
huffman@39989
   417
lemma DEFL_sprod:
huffman@40497
   418
  "DEFL('a::domain \<otimes> 'b::domain) = sprod_defl\<cdot>DEFL('a)\<cdot>DEFL('b)"
huffman@39989
   419
by (rule defl_sprod_def)
huffman@39987
   420
wenzelm@62175
   421
subsubsection \<open>Cartesian product\<close>
huffman@40830
   422
huffman@41292
   423
definition prod_liftdefl :: "udom u defl \<rightarrow> udom u defl \<rightarrow> udom u defl"
huffman@41292
   424
  where "prod_liftdefl = defl_fun2 (u_map\<cdot>prod_emb oo decode_prod_u)
huffman@41292
   425
    (encode_prod_u oo u_map\<cdot>prod_prj) sprod_map"
huffman@41292
   426
huffman@41292
   427
lemma cast_prod_liftdefl:
huffman@41292
   428
  "cast\<cdot>(prod_liftdefl\<cdot>a\<cdot>b) =
huffman@41292
   429
    (u_map\<cdot>prod_emb oo decode_prod_u) oo sprod_map\<cdot>(cast\<cdot>a)\<cdot>(cast\<cdot>b) oo
huffman@41292
   430
      (encode_prod_u oo u_map\<cdot>prod_prj)"
huffman@41292
   431
unfolding prod_liftdefl_def
huffman@41292
   432
apply (rule cast_defl_fun2)
huffman@41292
   433
apply (intro ep_pair_comp ep_pair_u_map ep_pair_prod)
huffman@41292
   434
apply (simp add: ep_pair.intro)
huffman@41292
   435
apply (erule (1) finite_deflation_sprod_map)
huffman@41292
   436
done
huffman@41292
   437
huffman@40830
   438
instantiation prod :: (predomain, predomain) predomain
huffman@40830
   439
begin
huffman@40830
   440
huffman@40830
   441
definition
huffman@41292
   442
  "liftemb = (u_map\<cdot>prod_emb oo decode_prod_u) oo
huffman@41292
   443
    (sprod_map\<cdot>liftemb\<cdot>liftemb oo encode_prod_u)"
huffman@40830
   444
huffman@40830
   445
definition
huffman@41292
   446
  "liftprj = (decode_prod_u oo sprod_map\<cdot>liftprj\<cdot>liftprj) oo
huffman@41292
   447
    (encode_prod_u oo u_map\<cdot>prod_prj)"
huffman@40830
   448
huffman@40830
   449
definition
huffman@41292
   450
  "liftdefl (t::('a \<times> 'b) itself) = prod_liftdefl\<cdot>LIFTDEFL('a)\<cdot>LIFTDEFL('b)"
huffman@40830
   451
huffman@40830
   452
instance proof
huffman@41292
   453
  show "ep_pair liftemb (liftprj :: udom u \<rightarrow> ('a \<times> 'b) u)"
huffman@40830
   454
    unfolding liftemb_prod_def liftprj_prod_def
huffman@41292
   455
    by (intro ep_pair_comp ep_pair_sprod_map ep_pair_u_map
huffman@41292
   456
       ep_pair_prod predomain_ep, simp_all add: ep_pair.intro)
huffman@41292
   457
  show "cast\<cdot>LIFTDEFL('a \<times> 'b) = liftemb oo (liftprj :: udom u \<rightarrow> ('a \<times> 'b) u)"
huffman@40830
   458
    unfolding liftemb_prod_def liftprj_prod_def liftdefl_prod_def
huffman@41292
   459
    by (simp add: cast_prod_liftdefl cast_liftdefl cfcomp1 sprod_map_map)
huffman@40830
   460
qed
huffman@40830
   461
huffman@40830
   462
end
huffman@40830
   463
huffman@40830
   464
instantiation prod :: ("domain", "domain") "domain"
huffman@40830
   465
begin
huffman@40830
   466
huffman@40830
   467
definition
huffman@41297
   468
  "emb = prod_emb oo prod_map\<cdot>emb\<cdot>emb"
huffman@40830
   469
huffman@40830
   470
definition
huffman@41297
   471
  "prj = prod_map\<cdot>prj\<cdot>prj oo prod_prj"
huffman@40830
   472
huffman@40830
   473
definition
huffman@40830
   474
  "defl (t::('a \<times> 'b) itself) = prod_defl\<cdot>DEFL('a)\<cdot>DEFL('b)"
huffman@40830
   475
huffman@40830
   476
instance proof
huffman@41292
   477
  show 1: "ep_pair emb (prj :: udom \<rightarrow> 'a \<times> 'b)"
huffman@40830
   478
    unfolding emb_prod_def prj_prod_def
huffman@41297
   479
    by (intro ep_pair_comp ep_pair_prod ep_pair_prod_map ep_pair_emb_prj)
huffman@41292
   480
  show 2: "cast\<cdot>DEFL('a \<times> 'b) = emb oo (prj :: udom \<rightarrow> 'a \<times> 'b)"
huffman@40830
   481
    unfolding emb_prod_def prj_prod_def defl_prod_def cast_prod_defl
huffman@41297
   482
    by (simp add: cast_DEFL oo_def cfun_eq_iff prod_map_map)
huffman@41292
   483
  show 3: "liftemb = u_map\<cdot>(emb :: 'a \<times> 'b \<rightarrow> udom)"
huffman@41292
   484
    unfolding emb_prod_def liftemb_prod_def liftemb_eq
huffman@41292
   485
    unfolding encode_prod_u_def decode_prod_u_def
huffman@41292
   486
    by (rule cfun_eqI, case_tac x, simp, clarsimp)
huffman@41292
   487
  show 4: "liftprj = u_map\<cdot>(prj :: udom \<rightarrow> 'a \<times> 'b)"
huffman@41292
   488
    unfolding prj_prod_def liftprj_prod_def liftprj_eq
huffman@41292
   489
    unfolding encode_prod_u_def decode_prod_u_def
huffman@41292
   490
    apply (rule cfun_eqI, case_tac x, simp)
huffman@41292
   491
    apply (rename_tac y, case_tac "prod_prj\<cdot>y", simp)
huffman@41292
   492
    done
huffman@41436
   493
  show 5: "LIFTDEFL('a \<times> 'b) = liftdefl_of\<cdot>DEFL('a \<times> 'b)"
huffman@41292
   494
    by (rule cast_eq_imp_eq)
huffman@41436
   495
      (simp add: cast_liftdefl cast_liftdefl_of cast_DEFL 2 3 4 u_map_oo)
huffman@40830
   496
qed
huffman@40830
   497
huffman@40830
   498
end
huffman@40830
   499
huffman@40830
   500
lemma DEFL_prod:
huffman@40830
   501
  "DEFL('a::domain \<times> 'b::domain) = prod_defl\<cdot>DEFL('a)\<cdot>DEFL('b)"
huffman@40830
   502
by (rule defl_prod_def)
huffman@40830
   503
huffman@40830
   504
lemma LIFTDEFL_prod:
huffman@41292
   505
  "LIFTDEFL('a::predomain \<times> 'b::predomain) =
huffman@41292
   506
    prod_liftdefl\<cdot>LIFTDEFL('a)\<cdot>LIFTDEFL('b)"
huffman@40830
   507
by (rule liftdefl_prod_def)
huffman@40830
   508
wenzelm@62175
   509
subsubsection \<open>Unit type\<close>
huffman@41034
   510
huffman@41292
   511
instantiation unit :: "domain"
huffman@41034
   512
begin
huffman@41034
   513
huffman@41034
   514
definition
huffman@41034
   515
  "emb = (\<bottom> :: unit \<rightarrow> udom)"
huffman@41034
   516
huffman@41034
   517
definition
huffman@41034
   518
  "prj = (\<bottom> :: udom \<rightarrow> unit)"
huffman@41034
   519
huffman@41034
   520
definition
huffman@41034
   521
  "defl (t::unit itself) = \<bottom>"
huffman@41034
   522
huffman@41034
   523
definition
huffman@41292
   524
  "(liftemb :: unit u \<rightarrow> udom u) = u_map\<cdot>emb"
huffman@41034
   525
huffman@41034
   526
definition
huffman@41292
   527
  "(liftprj :: udom u \<rightarrow> unit u) = u_map\<cdot>prj"
huffman@41034
   528
huffman@41292
   529
definition
huffman@41436
   530
  "liftdefl (t::unit itself) = liftdefl_of\<cdot>DEFL(unit)"
huffman@41292
   531
huffman@41292
   532
instance proof
huffman@41034
   533
  show "ep_pair emb (prj :: udom \<rightarrow> unit)"
huffman@41034
   534
    unfolding emb_unit_def prj_unit_def
huffman@41034
   535
    by (simp add: ep_pair.intro)
huffman@41034
   536
  show "cast\<cdot>DEFL(unit) = emb oo (prj :: udom \<rightarrow> unit)"
huffman@41034
   537
    unfolding emb_unit_def prj_unit_def defl_unit_def by simp
huffman@41292
   538
qed (fact liftemb_unit_def liftprj_unit_def liftdefl_unit_def)+
huffman@41034
   539
huffman@41034
   540
end
huffman@41034
   541
wenzelm@62175
   542
subsubsection \<open>Discrete cpo\<close>
huffman@39987
   543
huffman@40491
   544
instantiation discr :: (countable) predomain
huffman@39987
   545
begin
huffman@39987
   546
huffman@39987
   547
definition
huffman@41292
   548
  "(liftemb :: 'a discr u \<rightarrow> udom u) = strictify\<cdot>up oo udom_emb discr_approx"
huffman@39987
   549
huffman@39987
   550
definition
huffman@41292
   551
  "(liftprj :: udom u \<rightarrow> 'a discr u) = udom_prj discr_approx oo fup\<cdot>ID"
huffman@39987
   552
huffman@39987
   553
definition
huffman@40491
   554
  "liftdefl (t::'a discr itself) =
huffman@41292
   555
    (\<Squnion>i. defl_principal (Abs_fin_defl (liftemb oo discr_approx i oo (liftprj::udom u \<rightarrow> 'a discr u))))"
huffman@39987
   556
huffman@39987
   557
instance proof
huffman@41292
   558
  show 1: "ep_pair liftemb (liftprj :: udom u \<rightarrow> 'a discr u)"
huffman@40491
   559
    unfolding liftemb_discr_def liftprj_discr_def
huffman@41292
   560
    apply (intro ep_pair_comp ep_pair_udom [OF discr_approx])
huffman@41292
   561
    apply (rule ep_pair.intro)
huffman@41292
   562
    apply (simp add: strictify_conv_if)
huffman@41292
   563
    apply (case_tac y, simp, simp add: strictify_conv_if)
huffman@41292
   564
    done
huffman@41292
   565
  show "cast\<cdot>LIFTDEFL('a discr) = liftemb oo (liftprj :: udom u \<rightarrow> 'a discr u)"
huffman@41292
   566
    unfolding liftdefl_discr_def
huffman@39987
   567
    apply (subst contlub_cfun_arg)
huffman@39987
   568
    apply (rule chainI)
huffman@39989
   569
    apply (rule defl.principal_mono)
huffman@39987
   570
    apply (simp add: below_fin_defl_def)
huffman@40491
   571
    apply (simp add: Abs_fin_defl_inverse
huffman@41292
   572
        ep_pair.finite_deflation_e_d_p [OF 1]
huffman@40491
   573
        approx_chain.finite_deflation_approx [OF discr_approx])
huffman@39987
   574
    apply (intro monofun_cfun below_refl)
huffman@39987
   575
    apply (rule chainE)
huffman@40491
   576
    apply (rule chain_discr_approx)
huffman@39989
   577
    apply (subst cast_defl_principal)
huffman@40491
   578
    apply (simp add: Abs_fin_defl_inverse
huffman@41292
   579
        ep_pair.finite_deflation_e_d_p [OF 1]
huffman@40491
   580
        approx_chain.finite_deflation_approx [OF discr_approx])
huffman@40491
   581
    apply (simp add: lub_distribs)
huffman@39987
   582
    done
huffman@39987
   583
qed
huffman@39987
   584
huffman@39987
   585
end
huffman@39987
   586
wenzelm@62175
   587
subsubsection \<open>Strict sum\<close>
huffman@39987
   588
huffman@41292
   589
instantiation ssum :: ("domain", "domain") "domain"
huffman@39987
   590
begin
huffman@39987
   591
huffman@39987
   592
definition
huffman@41290
   593
  "emb = ssum_emb oo ssum_map\<cdot>emb\<cdot>emb"
huffman@39987
   594
huffman@39987
   595
definition
huffman@41290
   596
  "prj = ssum_map\<cdot>prj\<cdot>prj oo ssum_prj"
huffman@39987
   597
huffman@39987
   598
definition
huffman@39989
   599
  "defl (t::('a \<oplus> 'b) itself) = ssum_defl\<cdot>DEFL('a)\<cdot>DEFL('b)"
huffman@39987
   600
huffman@40491
   601
definition
huffman@41292
   602
  "(liftemb :: ('a \<oplus> 'b) u \<rightarrow> udom u) = u_map\<cdot>emb"
huffman@40491
   603
huffman@40491
   604
definition
huffman@41292
   605
  "(liftprj :: udom u \<rightarrow> ('a \<oplus> 'b) u) = u_map\<cdot>prj"
huffman@40491
   606
huffman@41292
   607
definition
huffman@41436
   608
  "liftdefl (t::('a \<oplus> 'b) itself) = liftdefl_of\<cdot>DEFL('a \<oplus> 'b)"
huffman@41292
   609
huffman@41292
   610
instance proof
huffman@39987
   611
  show "ep_pair emb (prj :: udom \<rightarrow> 'a \<oplus> 'b)"
huffman@39987
   612
    unfolding emb_ssum_def prj_ssum_def
huffman@41290
   613
    by (intro ep_pair_comp ep_pair_ssum ep_pair_ssum_map ep_pair_emb_prj)
huffman@39989
   614
  show "cast\<cdot>DEFL('a \<oplus> 'b) = emb oo (prj :: udom \<rightarrow> 'a \<oplus> 'b)"
huffman@39989
   615
    unfolding emb_ssum_def prj_ssum_def defl_ssum_def cast_ssum_defl
huffman@40002
   616
    by (simp add: cast_DEFL oo_def cfun_eq_iff ssum_map_map)
huffman@41292
   617
qed (fact liftemb_ssum_def liftprj_ssum_def liftdefl_ssum_def)+
huffman@39987
   618
huffman@39987
   619
end
huffman@39987
   620
huffman@39989
   621
lemma DEFL_ssum:
huffman@40497
   622
  "DEFL('a::domain \<oplus> 'b::domain) = ssum_defl\<cdot>DEFL('a)\<cdot>DEFL('b)"
huffman@39989
   623
by (rule defl_ssum_def)
huffman@39987
   624
wenzelm@62175
   625
subsubsection \<open>Lifted HOL type\<close>
huffman@40491
   626
huffman@41292
   627
instantiation lift :: (countable) "domain"
huffman@40491
   628
begin
huffman@40491
   629
huffman@40491
   630
definition
huffman@40491
   631
  "emb = emb oo (\<Lambda> x. Rep_lift x)"
huffman@40491
   632
huffman@40491
   633
definition
huffman@40491
   634
  "prj = (\<Lambda> y. Abs_lift y) oo prj"
huffman@40491
   635
huffman@40491
   636
definition
huffman@40491
   637
  "defl (t::'a lift itself) = DEFL('a discr u)"
huffman@40491
   638
huffman@40491
   639
definition
huffman@41292
   640
  "(liftemb :: 'a lift u \<rightarrow> udom u) = u_map\<cdot>emb"
huffman@40491
   641
huffman@40491
   642
definition
huffman@41292
   643
  "(liftprj :: udom u \<rightarrow> 'a lift u) = u_map\<cdot>prj"
huffman@40491
   644
huffman@41292
   645
definition
huffman@41436
   646
  "liftdefl (t::'a lift itself) = liftdefl_of\<cdot>DEFL('a lift)"
huffman@41292
   647
huffman@41292
   648
instance proof
huffman@40491
   649
  note [simp] = cont_Rep_lift cont_Abs_lift Rep_lift_inverse Abs_lift_inverse
huffman@40491
   650
  have "ep_pair (\<Lambda>(x::'a lift). Rep_lift x) (\<Lambda> y. Abs_lift y)"
huffman@40491
   651
    by (simp add: ep_pair_def)
huffman@40491
   652
  thus "ep_pair emb (prj :: udom \<rightarrow> 'a lift)"
huffman@40491
   653
    unfolding emb_lift_def prj_lift_def
huffman@40491
   654
    using ep_pair_emb_prj by (rule ep_pair_comp)
huffman@40491
   655
  show "cast\<cdot>DEFL('a lift) = emb oo (prj :: udom \<rightarrow> 'a lift)"
huffman@40491
   656
    unfolding emb_lift_def prj_lift_def defl_lift_def cast_DEFL
huffman@40491
   657
    by (simp add: cfcomp1)
huffman@41292
   658
qed (fact liftemb_lift_def liftprj_lift_def liftdefl_lift_def)+
huffman@40491
   659
huffman@39987
   660
end
huffman@40491
   661
huffman@40491
   662
end