src/HOL/HOLCF/Map_Functions.thy
author haftmann
Sun Jun 23 21:16:07 2013 +0200 (2013-06-23)
changeset 52435 6646bb548c6b
parent 42151 4da4fc77664b
child 58880 0baae4311a9f
permissions -rw-r--r--
migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
wenzelm@42151
     1
(*  Title:      HOL/HOLCF/Map_Functions.thy
huffman@40502
     2
    Author:     Brian Huffman
huffman@40502
     3
*)
huffman@40502
     4
huffman@40502
     5
header {* Map functions for various types *}
huffman@40502
     6
huffman@40502
     7
theory Map_Functions
huffman@40502
     8
imports Deflation
huffman@40502
     9
begin
huffman@40502
    10
huffman@40502
    11
subsection {* Map operator for continuous function space *}
huffman@40502
    12
huffman@40502
    13
default_sort cpo
huffman@40502
    14
huffman@40502
    15
definition
huffman@40502
    16
  cfun_map :: "('b \<rightarrow> 'a) \<rightarrow> ('c \<rightarrow> 'd) \<rightarrow> ('a \<rightarrow> 'c) \<rightarrow> ('b \<rightarrow> 'd)"
huffman@40502
    17
where
huffman@40502
    18
  "cfun_map = (\<Lambda> a b f x. b\<cdot>(f\<cdot>(a\<cdot>x)))"
huffman@40502
    19
huffman@40502
    20
lemma cfun_map_beta [simp]: "cfun_map\<cdot>a\<cdot>b\<cdot>f\<cdot>x = b\<cdot>(f\<cdot>(a\<cdot>x))"
huffman@40502
    21
unfolding cfun_map_def by simp
huffman@40502
    22
huffman@40502
    23
lemma cfun_map_ID: "cfun_map\<cdot>ID\<cdot>ID = ID"
huffman@40502
    24
unfolding cfun_eq_iff by simp
huffman@40502
    25
huffman@40502
    26
lemma cfun_map_map:
huffman@40502
    27
  "cfun_map\<cdot>f1\<cdot>g1\<cdot>(cfun_map\<cdot>f2\<cdot>g2\<cdot>p) =
huffman@40502
    28
    cfun_map\<cdot>(\<Lambda> x. f2\<cdot>(f1\<cdot>x))\<cdot>(\<Lambda> x. g1\<cdot>(g2\<cdot>x))\<cdot>p"
huffman@40502
    29
by (rule cfun_eqI) simp
huffman@40502
    30
huffman@40502
    31
lemma ep_pair_cfun_map:
huffman@40502
    32
  assumes "ep_pair e1 p1" and "ep_pair e2 p2"
huffman@40502
    33
  shows "ep_pair (cfun_map\<cdot>p1\<cdot>e2) (cfun_map\<cdot>e1\<cdot>p2)"
huffman@40502
    34
proof
huffman@40502
    35
  interpret e1p1: ep_pair e1 p1 by fact
huffman@40502
    36
  interpret e2p2: ep_pair e2 p2 by fact
huffman@40502
    37
  fix f show "cfun_map\<cdot>e1\<cdot>p2\<cdot>(cfun_map\<cdot>p1\<cdot>e2\<cdot>f) = f"
huffman@40502
    38
    by (simp add: cfun_eq_iff)
huffman@40502
    39
  fix g show "cfun_map\<cdot>p1\<cdot>e2\<cdot>(cfun_map\<cdot>e1\<cdot>p2\<cdot>g) \<sqsubseteq> g"
huffman@40502
    40
    apply (rule cfun_belowI, simp)
huffman@40502
    41
    apply (rule below_trans [OF e2p2.e_p_below])
huffman@40502
    42
    apply (rule monofun_cfun_arg)
huffman@40502
    43
    apply (rule e1p1.e_p_below)
huffman@40502
    44
    done
huffman@40502
    45
qed
huffman@40502
    46
huffman@40502
    47
lemma deflation_cfun_map:
huffman@40502
    48
  assumes "deflation d1" and "deflation d2"
huffman@40502
    49
  shows "deflation (cfun_map\<cdot>d1\<cdot>d2)"
huffman@40502
    50
proof
huffman@40502
    51
  interpret d1: deflation d1 by fact
huffman@40502
    52
  interpret d2: deflation d2 by fact
huffman@40502
    53
  fix f
huffman@40502
    54
  show "cfun_map\<cdot>d1\<cdot>d2\<cdot>(cfun_map\<cdot>d1\<cdot>d2\<cdot>f) = cfun_map\<cdot>d1\<cdot>d2\<cdot>f"
huffman@40502
    55
    by (simp add: cfun_eq_iff d1.idem d2.idem)
huffman@40502
    56
  show "cfun_map\<cdot>d1\<cdot>d2\<cdot>f \<sqsubseteq> f"
huffman@40502
    57
    apply (rule cfun_belowI, simp)
huffman@40502
    58
    apply (rule below_trans [OF d2.below])
huffman@40502
    59
    apply (rule monofun_cfun_arg)
huffman@40502
    60
    apply (rule d1.below)
huffman@40502
    61
    done
huffman@40502
    62
qed
huffman@40502
    63
huffman@40502
    64
lemma finite_range_cfun_map:
huffman@40502
    65
  assumes a: "finite (range (\<lambda>x. a\<cdot>x))"
huffman@40502
    66
  assumes b: "finite (range (\<lambda>y. b\<cdot>y))"
huffman@40502
    67
  shows "finite (range (\<lambda>f. cfun_map\<cdot>a\<cdot>b\<cdot>f))"  (is "finite (range ?h)")
huffman@40502
    68
proof (rule finite_imageD)
huffman@40502
    69
  let ?f = "\<lambda>g. range (\<lambda>x. (a\<cdot>x, g\<cdot>x))"
huffman@40502
    70
  show "finite (?f ` range ?h)"
huffman@40502
    71
  proof (rule finite_subset)
huffman@40502
    72
    let ?B = "Pow (range (\<lambda>x. a\<cdot>x) \<times> range (\<lambda>y. b\<cdot>y))"
huffman@40502
    73
    show "?f ` range ?h \<subseteq> ?B"
huffman@40502
    74
      by clarsimp
huffman@40502
    75
    show "finite ?B"
huffman@40502
    76
      by (simp add: a b)
huffman@40502
    77
  qed
huffman@40502
    78
  show "inj_on ?f (range ?h)"
huffman@40502
    79
  proof (rule inj_onI, rule cfun_eqI, clarsimp)
huffman@40502
    80
    fix x f g
huffman@40502
    81
    assume "range (\<lambda>x. (a\<cdot>x, b\<cdot>(f\<cdot>(a\<cdot>x)))) = range (\<lambda>x. (a\<cdot>x, b\<cdot>(g\<cdot>(a\<cdot>x))))"
huffman@40502
    82
    hence "range (\<lambda>x. (a\<cdot>x, b\<cdot>(f\<cdot>(a\<cdot>x)))) \<subseteq> range (\<lambda>x. (a\<cdot>x, b\<cdot>(g\<cdot>(a\<cdot>x))))"
huffman@40502
    83
      by (rule equalityD1)
huffman@40502
    84
    hence "(a\<cdot>x, b\<cdot>(f\<cdot>(a\<cdot>x))) \<in> range (\<lambda>x. (a\<cdot>x, b\<cdot>(g\<cdot>(a\<cdot>x))))"
huffman@40502
    85
      by (simp add: subset_eq)
huffman@40502
    86
    then obtain y where "(a\<cdot>x, b\<cdot>(f\<cdot>(a\<cdot>x))) = (a\<cdot>y, b\<cdot>(g\<cdot>(a\<cdot>y)))"
huffman@40502
    87
      by (rule rangeE)
huffman@40502
    88
    thus "b\<cdot>(f\<cdot>(a\<cdot>x)) = b\<cdot>(g\<cdot>(a\<cdot>x))"
huffman@40502
    89
      by clarsimp
huffman@40502
    90
  qed
huffman@40502
    91
qed
huffman@40502
    92
huffman@40502
    93
lemma finite_deflation_cfun_map:
huffman@40502
    94
  assumes "finite_deflation d1" and "finite_deflation d2"
huffman@40502
    95
  shows "finite_deflation (cfun_map\<cdot>d1\<cdot>d2)"
huffman@40502
    96
proof (rule finite_deflation_intro)
huffman@40502
    97
  interpret d1: finite_deflation d1 by fact
huffman@40502
    98
  interpret d2: finite_deflation d2 by fact
huffman@40502
    99
  have "deflation d1" and "deflation d2" by fact+
huffman@40502
   100
  thus "deflation (cfun_map\<cdot>d1\<cdot>d2)" by (rule deflation_cfun_map)
huffman@40502
   101
  have "finite (range (\<lambda>f. cfun_map\<cdot>d1\<cdot>d2\<cdot>f))"
huffman@40502
   102
    using d1.finite_range d2.finite_range
huffman@40502
   103
    by (rule finite_range_cfun_map)
huffman@40502
   104
  thus "finite {f. cfun_map\<cdot>d1\<cdot>d2\<cdot>f = f}"
huffman@40502
   105
    by (rule finite_range_imp_finite_fixes)
huffman@40502
   106
qed
huffman@40502
   107
huffman@40502
   108
text {* Finite deflations are compact elements of the function space *}
huffman@40502
   109
huffman@40502
   110
lemma finite_deflation_imp_compact: "finite_deflation d \<Longrightarrow> compact d"
huffman@40502
   111
apply (frule finite_deflation_imp_deflation)
huffman@40502
   112
apply (subgoal_tac "compact (cfun_map\<cdot>d\<cdot>d\<cdot>d)")
huffman@40502
   113
apply (simp add: cfun_map_def deflation.idem eta_cfun)
huffman@40502
   114
apply (rule finite_deflation.compact)
huffman@40502
   115
apply (simp only: finite_deflation_cfun_map)
huffman@40502
   116
done
huffman@40502
   117
huffman@40502
   118
subsection {* Map operator for product type *}
huffman@40502
   119
huffman@40502
   120
definition
huffman@41297
   121
  prod_map :: "('a \<rightarrow> 'b) \<rightarrow> ('c \<rightarrow> 'd) \<rightarrow> 'a \<times> 'c \<rightarrow> 'b \<times> 'd"
huffman@40502
   122
where
huffman@41297
   123
  "prod_map = (\<Lambda> f g p. (f\<cdot>(fst p), g\<cdot>(snd p)))"
huffman@40502
   124
huffman@41297
   125
lemma prod_map_Pair [simp]: "prod_map\<cdot>f\<cdot>g\<cdot>(x, y) = (f\<cdot>x, g\<cdot>y)"
huffman@41297
   126
unfolding prod_map_def by simp
huffman@40502
   127
huffman@41297
   128
lemma prod_map_ID: "prod_map\<cdot>ID\<cdot>ID = ID"
huffman@40502
   129
unfolding cfun_eq_iff by auto
huffman@40502
   130
huffman@41297
   131
lemma prod_map_map:
huffman@41297
   132
  "prod_map\<cdot>f1\<cdot>g1\<cdot>(prod_map\<cdot>f2\<cdot>g2\<cdot>p) =
huffman@41297
   133
    prod_map\<cdot>(\<Lambda> x. f1\<cdot>(f2\<cdot>x))\<cdot>(\<Lambda> x. g1\<cdot>(g2\<cdot>x))\<cdot>p"
huffman@40502
   134
by (induct p) simp
huffman@40502
   135
huffman@41297
   136
lemma ep_pair_prod_map:
huffman@40502
   137
  assumes "ep_pair e1 p1" and "ep_pair e2 p2"
huffman@41297
   138
  shows "ep_pair (prod_map\<cdot>e1\<cdot>e2) (prod_map\<cdot>p1\<cdot>p2)"
huffman@40502
   139
proof
huffman@40502
   140
  interpret e1p1: ep_pair e1 p1 by fact
huffman@40502
   141
  interpret e2p2: ep_pair e2 p2 by fact
huffman@41297
   142
  fix x show "prod_map\<cdot>p1\<cdot>p2\<cdot>(prod_map\<cdot>e1\<cdot>e2\<cdot>x) = x"
huffman@40502
   143
    by (induct x) simp
huffman@41297
   144
  fix y show "prod_map\<cdot>e1\<cdot>e2\<cdot>(prod_map\<cdot>p1\<cdot>p2\<cdot>y) \<sqsubseteq> y"
huffman@40502
   145
    by (induct y) (simp add: e1p1.e_p_below e2p2.e_p_below)
huffman@40502
   146
qed
huffman@40502
   147
huffman@41297
   148
lemma deflation_prod_map:
huffman@40502
   149
  assumes "deflation d1" and "deflation d2"
huffman@41297
   150
  shows "deflation (prod_map\<cdot>d1\<cdot>d2)"
huffman@40502
   151
proof
huffman@40502
   152
  interpret d1: deflation d1 by fact
huffman@40502
   153
  interpret d2: deflation d2 by fact
huffman@40502
   154
  fix x
huffman@41297
   155
  show "prod_map\<cdot>d1\<cdot>d2\<cdot>(prod_map\<cdot>d1\<cdot>d2\<cdot>x) = prod_map\<cdot>d1\<cdot>d2\<cdot>x"
huffman@40502
   156
    by (induct x) (simp add: d1.idem d2.idem)
huffman@41297
   157
  show "prod_map\<cdot>d1\<cdot>d2\<cdot>x \<sqsubseteq> x"
huffman@40502
   158
    by (induct x) (simp add: d1.below d2.below)
huffman@40502
   159
qed
huffman@40502
   160
huffman@41297
   161
lemma finite_deflation_prod_map:
huffman@40502
   162
  assumes "finite_deflation d1" and "finite_deflation d2"
huffman@41297
   163
  shows "finite_deflation (prod_map\<cdot>d1\<cdot>d2)"
huffman@40502
   164
proof (rule finite_deflation_intro)
huffman@40502
   165
  interpret d1: finite_deflation d1 by fact
huffman@40502
   166
  interpret d2: finite_deflation d2 by fact
huffman@40502
   167
  have "deflation d1" and "deflation d2" by fact+
huffman@41297
   168
  thus "deflation (prod_map\<cdot>d1\<cdot>d2)" by (rule deflation_prod_map)
huffman@41297
   169
  have "{p. prod_map\<cdot>d1\<cdot>d2\<cdot>p = p} \<subseteq> {x. d1\<cdot>x = x} \<times> {y. d2\<cdot>y = y}"
huffman@40502
   170
    by clarsimp
huffman@41297
   171
  thus "finite {p. prod_map\<cdot>d1\<cdot>d2\<cdot>p = p}"
huffman@40502
   172
    by (rule finite_subset, simp add: d1.finite_fixes d2.finite_fixes)
huffman@40502
   173
qed
huffman@40502
   174
huffman@40502
   175
subsection {* Map function for lifted cpo *}
huffman@40502
   176
huffman@40502
   177
definition
huffman@40502
   178
  u_map :: "('a \<rightarrow> 'b) \<rightarrow> 'a u \<rightarrow> 'b u"
huffman@40502
   179
where
huffman@40502
   180
  "u_map = (\<Lambda> f. fup\<cdot>(up oo f))"
huffman@40502
   181
huffman@40502
   182
lemma u_map_strict [simp]: "u_map\<cdot>f\<cdot>\<bottom> = \<bottom>"
huffman@40502
   183
unfolding u_map_def by simp
huffman@40502
   184
huffman@40502
   185
lemma u_map_up [simp]: "u_map\<cdot>f\<cdot>(up\<cdot>x) = up\<cdot>(f\<cdot>x)"
huffman@40502
   186
unfolding u_map_def by simp
huffman@40502
   187
huffman@40502
   188
lemma u_map_ID: "u_map\<cdot>ID = ID"
huffman@40502
   189
unfolding u_map_def by (simp add: cfun_eq_iff eta_cfun)
huffman@40502
   190
huffman@40502
   191
lemma u_map_map: "u_map\<cdot>f\<cdot>(u_map\<cdot>g\<cdot>p) = u_map\<cdot>(\<Lambda> x. f\<cdot>(g\<cdot>x))\<cdot>p"
huffman@40502
   192
by (induct p) simp_all
huffman@40502
   193
huffman@41291
   194
lemma u_map_oo: "u_map\<cdot>(f oo g) = u_map\<cdot>f oo u_map\<cdot>g"
huffman@41291
   195
by (simp add: cfcomp1 u_map_map eta_cfun)
huffman@41291
   196
huffman@40502
   197
lemma ep_pair_u_map: "ep_pair e p \<Longrightarrow> ep_pair (u_map\<cdot>e) (u_map\<cdot>p)"
huffman@40502
   198
apply default
huffman@40502
   199
apply (case_tac x, simp, simp add: ep_pair.e_inverse)
huffman@40502
   200
apply (case_tac y, simp, simp add: ep_pair.e_p_below)
huffman@40502
   201
done
huffman@40502
   202
huffman@40502
   203
lemma deflation_u_map: "deflation d \<Longrightarrow> deflation (u_map\<cdot>d)"
huffman@40502
   204
apply default
huffman@40502
   205
apply (case_tac x, simp, simp add: deflation.idem)
huffman@40502
   206
apply (case_tac x, simp, simp add: deflation.below)
huffman@40502
   207
done
huffman@40502
   208
huffman@40502
   209
lemma finite_deflation_u_map:
huffman@40502
   210
  assumes "finite_deflation d" shows "finite_deflation (u_map\<cdot>d)"
huffman@40502
   211
proof (rule finite_deflation_intro)
huffman@40502
   212
  interpret d: finite_deflation d by fact
huffman@40502
   213
  have "deflation d" by fact
huffman@40502
   214
  thus "deflation (u_map\<cdot>d)" by (rule deflation_u_map)
huffman@40502
   215
  have "{x. u_map\<cdot>d\<cdot>x = x} \<subseteq> insert \<bottom> ((\<lambda>x. up\<cdot>x) ` {x. d\<cdot>x = x})"
huffman@40502
   216
    by (rule subsetI, case_tac x, simp_all)
huffman@40502
   217
  thus "finite {x. u_map\<cdot>d\<cdot>x = x}"
huffman@40502
   218
    by (rule finite_subset, simp add: d.finite_fixes)
huffman@40502
   219
qed
huffman@40502
   220
huffman@40502
   221
subsection {* Map function for strict products *}
huffman@40502
   222
huffman@40502
   223
default_sort pcpo
huffman@40502
   224
huffman@40502
   225
definition
huffman@40502
   226
  sprod_map :: "('a \<rightarrow> 'b) \<rightarrow> ('c \<rightarrow> 'd) \<rightarrow> 'a \<otimes> 'c \<rightarrow> 'b \<otimes> 'd"
huffman@40502
   227
where
huffman@40502
   228
  "sprod_map = (\<Lambda> f g. ssplit\<cdot>(\<Lambda> x y. (:f\<cdot>x, g\<cdot>y:)))"
huffman@40502
   229
huffman@40502
   230
lemma sprod_map_strict [simp]: "sprod_map\<cdot>a\<cdot>b\<cdot>\<bottom> = \<bottom>"
huffman@40502
   231
unfolding sprod_map_def by simp
huffman@40502
   232
huffman@40502
   233
lemma sprod_map_spair [simp]:
huffman@40502
   234
  "x \<noteq> \<bottom> \<Longrightarrow> y \<noteq> \<bottom> \<Longrightarrow> sprod_map\<cdot>f\<cdot>g\<cdot>(:x, y:) = (:f\<cdot>x, g\<cdot>y:)"
huffman@40502
   235
by (simp add: sprod_map_def)
huffman@40502
   236
huffman@40502
   237
lemma sprod_map_spair':
huffman@40502
   238
  "f\<cdot>\<bottom> = \<bottom> \<Longrightarrow> g\<cdot>\<bottom> = \<bottom> \<Longrightarrow> sprod_map\<cdot>f\<cdot>g\<cdot>(:x, y:) = (:f\<cdot>x, g\<cdot>y:)"
huffman@40502
   239
by (cases "x = \<bottom> \<or> y = \<bottom>") auto
huffman@40502
   240
huffman@40502
   241
lemma sprod_map_ID: "sprod_map\<cdot>ID\<cdot>ID = ID"
huffman@40502
   242
unfolding sprod_map_def by (simp add: cfun_eq_iff eta_cfun)
huffman@40502
   243
huffman@40502
   244
lemma sprod_map_map:
huffman@40502
   245
  "\<lbrakk>f1\<cdot>\<bottom> = \<bottom>; g1\<cdot>\<bottom> = \<bottom>\<rbrakk> \<Longrightarrow>
huffman@40502
   246
    sprod_map\<cdot>f1\<cdot>g1\<cdot>(sprod_map\<cdot>f2\<cdot>g2\<cdot>p) =
huffman@40502
   247
     sprod_map\<cdot>(\<Lambda> x. f1\<cdot>(f2\<cdot>x))\<cdot>(\<Lambda> x. g1\<cdot>(g2\<cdot>x))\<cdot>p"
huffman@40502
   248
apply (induct p, simp)
huffman@40502
   249
apply (case_tac "f2\<cdot>x = \<bottom>", simp)
huffman@40502
   250
apply (case_tac "g2\<cdot>y = \<bottom>", simp)
huffman@40502
   251
apply simp
huffman@40502
   252
done
huffman@40502
   253
huffman@40502
   254
lemma ep_pair_sprod_map:
huffman@40502
   255
  assumes "ep_pair e1 p1" and "ep_pair e2 p2"
huffman@40502
   256
  shows "ep_pair (sprod_map\<cdot>e1\<cdot>e2) (sprod_map\<cdot>p1\<cdot>p2)"
huffman@40502
   257
proof
huffman@40502
   258
  interpret e1p1: pcpo_ep_pair e1 p1 unfolding pcpo_ep_pair_def by fact
huffman@40502
   259
  interpret e2p2: pcpo_ep_pair e2 p2 unfolding pcpo_ep_pair_def by fact
huffman@40502
   260
  fix x show "sprod_map\<cdot>p1\<cdot>p2\<cdot>(sprod_map\<cdot>e1\<cdot>e2\<cdot>x) = x"
huffman@40502
   261
    by (induct x) simp_all
huffman@40502
   262
  fix y show "sprod_map\<cdot>e1\<cdot>e2\<cdot>(sprod_map\<cdot>p1\<cdot>p2\<cdot>y) \<sqsubseteq> y"
huffman@40502
   263
    apply (induct y, simp)
huffman@40502
   264
    apply (case_tac "p1\<cdot>x = \<bottom>", simp, case_tac "p2\<cdot>y = \<bottom>", simp)
huffman@40502
   265
    apply (simp add: monofun_cfun e1p1.e_p_below e2p2.e_p_below)
huffman@40502
   266
    done
huffman@40502
   267
qed
huffman@40502
   268
huffman@40502
   269
lemma deflation_sprod_map:
huffman@40502
   270
  assumes "deflation d1" and "deflation d2"
huffman@40502
   271
  shows "deflation (sprod_map\<cdot>d1\<cdot>d2)"
huffman@40502
   272
proof
huffman@40502
   273
  interpret d1: deflation d1 by fact
huffman@40502
   274
  interpret d2: deflation d2 by fact
huffman@40502
   275
  fix x
huffman@40502
   276
  show "sprod_map\<cdot>d1\<cdot>d2\<cdot>(sprod_map\<cdot>d1\<cdot>d2\<cdot>x) = sprod_map\<cdot>d1\<cdot>d2\<cdot>x"
huffman@40502
   277
    apply (induct x, simp)
huffman@40502
   278
    apply (case_tac "d1\<cdot>x = \<bottom>", simp, case_tac "d2\<cdot>y = \<bottom>", simp)
huffman@40502
   279
    apply (simp add: d1.idem d2.idem)
huffman@40502
   280
    done
huffman@40502
   281
  show "sprod_map\<cdot>d1\<cdot>d2\<cdot>x \<sqsubseteq> x"
huffman@40502
   282
    apply (induct x, simp)
huffman@40502
   283
    apply (simp add: monofun_cfun d1.below d2.below)
huffman@40502
   284
    done
huffman@40502
   285
qed
huffman@40502
   286
huffman@40502
   287
lemma finite_deflation_sprod_map:
huffman@40502
   288
  assumes "finite_deflation d1" and "finite_deflation d2"
huffman@40502
   289
  shows "finite_deflation (sprod_map\<cdot>d1\<cdot>d2)"
huffman@40502
   290
proof (rule finite_deflation_intro)
huffman@40502
   291
  interpret d1: finite_deflation d1 by fact
huffman@40502
   292
  interpret d2: finite_deflation d2 by fact
huffman@40502
   293
  have "deflation d1" and "deflation d2" by fact+
huffman@40502
   294
  thus "deflation (sprod_map\<cdot>d1\<cdot>d2)" by (rule deflation_sprod_map)
huffman@40502
   295
  have "{x. sprod_map\<cdot>d1\<cdot>d2\<cdot>x = x} \<subseteq> insert \<bottom>
huffman@40502
   296
        ((\<lambda>(x, y). (:x, y:)) ` ({x. d1\<cdot>x = x} \<times> {y. d2\<cdot>y = y}))"
huffman@40502
   297
    by (rule subsetI, case_tac x, auto simp add: spair_eq_iff)
huffman@40502
   298
  thus "finite {x. sprod_map\<cdot>d1\<cdot>d2\<cdot>x = x}"
huffman@40502
   299
    by (rule finite_subset, simp add: d1.finite_fixes d2.finite_fixes)
huffman@40502
   300
qed
huffman@40502
   301
huffman@40502
   302
subsection {* Map function for strict sums *}
huffman@40502
   303
huffman@40502
   304
definition
huffman@40502
   305
  ssum_map :: "('a \<rightarrow> 'b) \<rightarrow> ('c \<rightarrow> 'd) \<rightarrow> 'a \<oplus> 'c \<rightarrow> 'b \<oplus> 'd"
huffman@40502
   306
where
huffman@40502
   307
  "ssum_map = (\<Lambda> f g. sscase\<cdot>(sinl oo f)\<cdot>(sinr oo g))"
huffman@40502
   308
huffman@40502
   309
lemma ssum_map_strict [simp]: "ssum_map\<cdot>f\<cdot>g\<cdot>\<bottom> = \<bottom>"
huffman@40502
   310
unfolding ssum_map_def by simp
huffman@40502
   311
huffman@40502
   312
lemma ssum_map_sinl [simp]: "x \<noteq> \<bottom> \<Longrightarrow> ssum_map\<cdot>f\<cdot>g\<cdot>(sinl\<cdot>x) = sinl\<cdot>(f\<cdot>x)"
huffman@40502
   313
unfolding ssum_map_def by simp
huffman@40502
   314
huffman@40502
   315
lemma ssum_map_sinr [simp]: "x \<noteq> \<bottom> \<Longrightarrow> ssum_map\<cdot>f\<cdot>g\<cdot>(sinr\<cdot>x) = sinr\<cdot>(g\<cdot>x)"
huffman@40502
   316
unfolding ssum_map_def by simp
huffman@40502
   317
huffman@40502
   318
lemma ssum_map_sinl': "f\<cdot>\<bottom> = \<bottom> \<Longrightarrow> ssum_map\<cdot>f\<cdot>g\<cdot>(sinl\<cdot>x) = sinl\<cdot>(f\<cdot>x)"
huffman@40502
   319
by (cases "x = \<bottom>") simp_all
huffman@40502
   320
huffman@40502
   321
lemma ssum_map_sinr': "g\<cdot>\<bottom> = \<bottom> \<Longrightarrow> ssum_map\<cdot>f\<cdot>g\<cdot>(sinr\<cdot>x) = sinr\<cdot>(g\<cdot>x)"
huffman@40502
   322
by (cases "x = \<bottom>") simp_all
huffman@40502
   323
huffman@40502
   324
lemma ssum_map_ID: "ssum_map\<cdot>ID\<cdot>ID = ID"
huffman@40502
   325
unfolding ssum_map_def by (simp add: cfun_eq_iff eta_cfun)
huffman@40502
   326
huffman@40502
   327
lemma ssum_map_map:
huffman@40502
   328
  "\<lbrakk>f1\<cdot>\<bottom> = \<bottom>; g1\<cdot>\<bottom> = \<bottom>\<rbrakk> \<Longrightarrow>
huffman@40502
   329
    ssum_map\<cdot>f1\<cdot>g1\<cdot>(ssum_map\<cdot>f2\<cdot>g2\<cdot>p) =
huffman@40502
   330
     ssum_map\<cdot>(\<Lambda> x. f1\<cdot>(f2\<cdot>x))\<cdot>(\<Lambda> x. g1\<cdot>(g2\<cdot>x))\<cdot>p"
huffman@40502
   331
apply (induct p, simp)
huffman@40502
   332
apply (case_tac "f2\<cdot>x = \<bottom>", simp, simp)
huffman@40502
   333
apply (case_tac "g2\<cdot>y = \<bottom>", simp, simp)
huffman@40502
   334
done
huffman@40502
   335
huffman@40502
   336
lemma ep_pair_ssum_map:
huffman@40502
   337
  assumes "ep_pair e1 p1" and "ep_pair e2 p2"
huffman@40502
   338
  shows "ep_pair (ssum_map\<cdot>e1\<cdot>e2) (ssum_map\<cdot>p1\<cdot>p2)"
huffman@40502
   339
proof
huffman@40502
   340
  interpret e1p1: pcpo_ep_pair e1 p1 unfolding pcpo_ep_pair_def by fact
huffman@40502
   341
  interpret e2p2: pcpo_ep_pair e2 p2 unfolding pcpo_ep_pair_def by fact
huffman@40502
   342
  fix x show "ssum_map\<cdot>p1\<cdot>p2\<cdot>(ssum_map\<cdot>e1\<cdot>e2\<cdot>x) = x"
huffman@40502
   343
    by (induct x) simp_all
huffman@40502
   344
  fix y show "ssum_map\<cdot>e1\<cdot>e2\<cdot>(ssum_map\<cdot>p1\<cdot>p2\<cdot>y) \<sqsubseteq> y"
huffman@40502
   345
    apply (induct y, simp)
huffman@40502
   346
    apply (case_tac "p1\<cdot>x = \<bottom>", simp, simp add: e1p1.e_p_below)
huffman@40502
   347
    apply (case_tac "p2\<cdot>y = \<bottom>", simp, simp add: e2p2.e_p_below)
huffman@40502
   348
    done
huffman@40502
   349
qed
huffman@40502
   350
huffman@40502
   351
lemma deflation_ssum_map:
huffman@40502
   352
  assumes "deflation d1" and "deflation d2"
huffman@40502
   353
  shows "deflation (ssum_map\<cdot>d1\<cdot>d2)"
huffman@40502
   354
proof
huffman@40502
   355
  interpret d1: deflation d1 by fact
huffman@40502
   356
  interpret d2: deflation d2 by fact
huffman@40502
   357
  fix x
huffman@40502
   358
  show "ssum_map\<cdot>d1\<cdot>d2\<cdot>(ssum_map\<cdot>d1\<cdot>d2\<cdot>x) = ssum_map\<cdot>d1\<cdot>d2\<cdot>x"
huffman@40502
   359
    apply (induct x, simp)
huffman@40502
   360
    apply (case_tac "d1\<cdot>x = \<bottom>", simp, simp add: d1.idem)
huffman@40502
   361
    apply (case_tac "d2\<cdot>y = \<bottom>", simp, simp add: d2.idem)
huffman@40502
   362
    done
huffman@40502
   363
  show "ssum_map\<cdot>d1\<cdot>d2\<cdot>x \<sqsubseteq> x"
huffman@40502
   364
    apply (induct x, simp)
huffman@40502
   365
    apply (case_tac "d1\<cdot>x = \<bottom>", simp, simp add: d1.below)
huffman@40502
   366
    apply (case_tac "d2\<cdot>y = \<bottom>", simp, simp add: d2.below)
huffman@40502
   367
    done
huffman@40502
   368
qed
huffman@40502
   369
huffman@40502
   370
lemma finite_deflation_ssum_map:
huffman@40502
   371
  assumes "finite_deflation d1" and "finite_deflation d2"
huffman@40502
   372
  shows "finite_deflation (ssum_map\<cdot>d1\<cdot>d2)"
huffman@40502
   373
proof (rule finite_deflation_intro)
huffman@40502
   374
  interpret d1: finite_deflation d1 by fact
huffman@40502
   375
  interpret d2: finite_deflation d2 by fact
huffman@40502
   376
  have "deflation d1" and "deflation d2" by fact+
huffman@40502
   377
  thus "deflation (ssum_map\<cdot>d1\<cdot>d2)" by (rule deflation_ssum_map)
huffman@40502
   378
  have "{x. ssum_map\<cdot>d1\<cdot>d2\<cdot>x = x} \<subseteq>
huffman@40502
   379
        (\<lambda>x. sinl\<cdot>x) ` {x. d1\<cdot>x = x} \<union>
huffman@40502
   380
        (\<lambda>x. sinr\<cdot>x) ` {x. d2\<cdot>x = x} \<union> {\<bottom>}"
huffman@40502
   381
    by (rule subsetI, case_tac x, simp_all)
huffman@40502
   382
  thus "finite {x. ssum_map\<cdot>d1\<cdot>d2\<cdot>x = x}"
huffman@40502
   383
    by (rule finite_subset, simp add: d1.finite_fixes d2.finite_fixes)
huffman@40502
   384
qed
huffman@40502
   385
huffman@40592
   386
subsection {* Map operator for strict function space *}
huffman@40592
   387
huffman@40592
   388
definition
huffman@40592
   389
  sfun_map :: "('b \<rightarrow> 'a) \<rightarrow> ('c \<rightarrow> 'd) \<rightarrow> ('a \<rightarrow>! 'c) \<rightarrow> ('b \<rightarrow>! 'd)"
huffman@40592
   390
where
huffman@40592
   391
  "sfun_map = (\<Lambda> a b. sfun_abs oo cfun_map\<cdot>a\<cdot>b oo sfun_rep)"
huffman@40592
   392
huffman@40592
   393
lemma sfun_map_ID: "sfun_map\<cdot>ID\<cdot>ID = ID"
huffman@40592
   394
  unfolding sfun_map_def
huffman@40592
   395
  by (simp add: cfun_map_ID cfun_eq_iff)
huffman@40592
   396
huffman@40592
   397
lemma sfun_map_map:
huffman@40592
   398
  assumes "f2\<cdot>\<bottom> = \<bottom>" and "g2\<cdot>\<bottom> = \<bottom>" shows
huffman@40592
   399
  "sfun_map\<cdot>f1\<cdot>g1\<cdot>(sfun_map\<cdot>f2\<cdot>g2\<cdot>p) =
huffman@40592
   400
    sfun_map\<cdot>(\<Lambda> x. f2\<cdot>(f1\<cdot>x))\<cdot>(\<Lambda> x. g1\<cdot>(g2\<cdot>x))\<cdot>p"
huffman@40592
   401
unfolding sfun_map_def
huffman@40592
   402
by (simp add: cfun_eq_iff strictify_cancel assms cfun_map_map)
huffman@40592
   403
huffman@40592
   404
lemma ep_pair_sfun_map:
huffman@40592
   405
  assumes 1: "ep_pair e1 p1"
huffman@40592
   406
  assumes 2: "ep_pair e2 p2"
huffman@40592
   407
  shows "ep_pair (sfun_map\<cdot>p1\<cdot>e2) (sfun_map\<cdot>e1\<cdot>p2)"
huffman@40592
   408
proof
huffman@40592
   409
  interpret e1p1: pcpo_ep_pair e1 p1
huffman@40592
   410
    unfolding pcpo_ep_pair_def by fact
huffman@40592
   411
  interpret e2p2: pcpo_ep_pair e2 p2
huffman@40592
   412
    unfolding pcpo_ep_pair_def by fact
huffman@40592
   413
  fix f show "sfun_map\<cdot>e1\<cdot>p2\<cdot>(sfun_map\<cdot>p1\<cdot>e2\<cdot>f) = f"
huffman@40592
   414
    unfolding sfun_map_def
huffman@40592
   415
    apply (simp add: sfun_eq_iff strictify_cancel)
huffman@40592
   416
    apply (rule ep_pair.e_inverse)
huffman@40592
   417
    apply (rule ep_pair_cfun_map [OF 1 2])
huffman@40592
   418
    done
huffman@40592
   419
  fix g show "sfun_map\<cdot>p1\<cdot>e2\<cdot>(sfun_map\<cdot>e1\<cdot>p2\<cdot>g) \<sqsubseteq> g"
huffman@40592
   420
    unfolding sfun_map_def
huffman@40592
   421
    apply (simp add: sfun_below_iff strictify_cancel)
huffman@40592
   422
    apply (rule ep_pair.e_p_below)
huffman@40592
   423
    apply (rule ep_pair_cfun_map [OF 1 2])
huffman@40592
   424
    done
huffman@40592
   425
qed
huffman@40592
   426
huffman@40592
   427
lemma deflation_sfun_map:
huffman@40592
   428
  assumes 1: "deflation d1"
huffman@40592
   429
  assumes 2: "deflation d2"
huffman@40592
   430
  shows "deflation (sfun_map\<cdot>d1\<cdot>d2)"
huffman@40592
   431
apply (simp add: sfun_map_def)
huffman@40592
   432
apply (rule deflation.intro)
huffman@40592
   433
apply simp
huffman@40592
   434
apply (subst strictify_cancel)
huffman@40592
   435
apply (simp add: cfun_map_def deflation_strict 1 2)
huffman@40592
   436
apply (simp add: cfun_map_def deflation.idem 1 2)
huffman@40592
   437
apply (simp add: sfun_below_iff)
huffman@40592
   438
apply (subst strictify_cancel)
huffman@40592
   439
apply (simp add: cfun_map_def deflation_strict 1 2)
huffman@40592
   440
apply (rule deflation.below)
huffman@40592
   441
apply (rule deflation_cfun_map [OF 1 2])
huffman@40592
   442
done
huffman@40592
   443
huffman@40592
   444
lemma finite_deflation_sfun_map:
huffman@40592
   445
  assumes 1: "finite_deflation d1"
huffman@40592
   446
  assumes 2: "finite_deflation d2"
huffman@40592
   447
  shows "finite_deflation (sfun_map\<cdot>d1\<cdot>d2)"
huffman@40592
   448
proof (intro finite_deflation_intro)
huffman@40592
   449
  interpret d1: finite_deflation d1 by fact
huffman@40592
   450
  interpret d2: finite_deflation d2 by fact
huffman@40592
   451
  have "deflation d1" and "deflation d2" by fact+
huffman@40592
   452
  thus "deflation (sfun_map\<cdot>d1\<cdot>d2)" by (rule deflation_sfun_map)
huffman@40592
   453
  from 1 2 have "finite_deflation (cfun_map\<cdot>d1\<cdot>d2)"
huffman@40592
   454
    by (rule finite_deflation_cfun_map)
huffman@40592
   455
  then have "finite {f. cfun_map\<cdot>d1\<cdot>d2\<cdot>f = f}"
huffman@40592
   456
    by (rule finite_deflation.finite_fixes)
huffman@40592
   457
  moreover have "inj (\<lambda>f. sfun_rep\<cdot>f)"
huffman@40592
   458
    by (rule inj_onI, simp add: sfun_eq_iff)
huffman@40592
   459
  ultimately have "finite ((\<lambda>f. sfun_rep\<cdot>f) -` {f. cfun_map\<cdot>d1\<cdot>d2\<cdot>f = f})"
huffman@40592
   460
    by (rule finite_vimageI)
huffman@40592
   461
  then show "finite {f. sfun_map\<cdot>d1\<cdot>d2\<cdot>f = f}"
huffman@40592
   462
    unfolding sfun_map_def sfun_eq_iff
huffman@40592
   463
    by (simp add: strictify_cancel
huffman@40592
   464
         deflation_strict `deflation d1` `deflation d2`)
huffman@40592
   465
qed
huffman@40592
   466
huffman@40502
   467
end