src/HOLCF/Map_Functions.thy
author huffman
Wed Nov 10 17:56:08 2010 -0800 (2010-11-10)
changeset 40502 8e92772bc0e8
child 40592 f432973ce0f6
permissions -rw-r--r--
move map functions to new theory file Map_Functions; add theory file Plain_HOLCF
huffman@40502
     1
(*  Title:      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@40502
   121
  cprod_map :: "('a \<rightarrow> 'b) \<rightarrow> ('c \<rightarrow> 'd) \<rightarrow> 'a \<times> 'c \<rightarrow> 'b \<times> 'd"
huffman@40502
   122
where
huffman@40502
   123
  "cprod_map = (\<Lambda> f g p. (f\<cdot>(fst p), g\<cdot>(snd p)))"
huffman@40502
   124
huffman@40502
   125
lemma cprod_map_Pair [simp]: "cprod_map\<cdot>f\<cdot>g\<cdot>(x, y) = (f\<cdot>x, g\<cdot>y)"
huffman@40502
   126
unfolding cprod_map_def by simp
huffman@40502
   127
huffman@40502
   128
lemma cprod_map_ID: "cprod_map\<cdot>ID\<cdot>ID = ID"
huffman@40502
   129
unfolding cfun_eq_iff by auto
huffman@40502
   130
huffman@40502
   131
lemma cprod_map_map:
huffman@40502
   132
  "cprod_map\<cdot>f1\<cdot>g1\<cdot>(cprod_map\<cdot>f2\<cdot>g2\<cdot>p) =
huffman@40502
   133
    cprod_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@40502
   136
lemma ep_pair_cprod_map:
huffman@40502
   137
  assumes "ep_pair e1 p1" and "ep_pair e2 p2"
huffman@40502
   138
  shows "ep_pair (cprod_map\<cdot>e1\<cdot>e2) (cprod_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@40502
   142
  fix x show "cprod_map\<cdot>p1\<cdot>p2\<cdot>(cprod_map\<cdot>e1\<cdot>e2\<cdot>x) = x"
huffman@40502
   143
    by (induct x) simp
huffman@40502
   144
  fix y show "cprod_map\<cdot>e1\<cdot>e2\<cdot>(cprod_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@40502
   148
lemma deflation_cprod_map:
huffman@40502
   149
  assumes "deflation d1" and "deflation d2"
huffman@40502
   150
  shows "deflation (cprod_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@40502
   155
  show "cprod_map\<cdot>d1\<cdot>d2\<cdot>(cprod_map\<cdot>d1\<cdot>d2\<cdot>x) = cprod_map\<cdot>d1\<cdot>d2\<cdot>x"
huffman@40502
   156
    by (induct x) (simp add: d1.idem d2.idem)
huffman@40502
   157
  show "cprod_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@40502
   161
lemma finite_deflation_cprod_map:
huffman@40502
   162
  assumes "finite_deflation d1" and "finite_deflation d2"
huffman@40502
   163
  shows "finite_deflation (cprod_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@40502
   168
  thus "deflation (cprod_map\<cdot>d1\<cdot>d2)" by (rule deflation_cprod_map)
huffman@40502
   169
  have "{p. cprod_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@40502
   171
  thus "finite {p. cprod_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@40502
   194
lemma ep_pair_u_map: "ep_pair e p \<Longrightarrow> ep_pair (u_map\<cdot>e) (u_map\<cdot>p)"
huffman@40502
   195
apply default
huffman@40502
   196
apply (case_tac x, simp, simp add: ep_pair.e_inverse)
huffman@40502
   197
apply (case_tac y, simp, simp add: ep_pair.e_p_below)
huffman@40502
   198
done
huffman@40502
   199
huffman@40502
   200
lemma deflation_u_map: "deflation d \<Longrightarrow> deflation (u_map\<cdot>d)"
huffman@40502
   201
apply default
huffman@40502
   202
apply (case_tac x, simp, simp add: deflation.idem)
huffman@40502
   203
apply (case_tac x, simp, simp add: deflation.below)
huffman@40502
   204
done
huffman@40502
   205
huffman@40502
   206
lemma finite_deflation_u_map:
huffman@40502
   207
  assumes "finite_deflation d" shows "finite_deflation (u_map\<cdot>d)"
huffman@40502
   208
proof (rule finite_deflation_intro)
huffman@40502
   209
  interpret d: finite_deflation d by fact
huffman@40502
   210
  have "deflation d" by fact
huffman@40502
   211
  thus "deflation (u_map\<cdot>d)" by (rule deflation_u_map)
huffman@40502
   212
  have "{x. u_map\<cdot>d\<cdot>x = x} \<subseteq> insert \<bottom> ((\<lambda>x. up\<cdot>x) ` {x. d\<cdot>x = x})"
huffman@40502
   213
    by (rule subsetI, case_tac x, simp_all)
huffman@40502
   214
  thus "finite {x. u_map\<cdot>d\<cdot>x = x}"
huffman@40502
   215
    by (rule finite_subset, simp add: d.finite_fixes)
huffman@40502
   216
qed
huffman@40502
   217
huffman@40502
   218
subsection {* Map function for strict products *}
huffman@40502
   219
huffman@40502
   220
default_sort pcpo
huffman@40502
   221
huffman@40502
   222
definition
huffman@40502
   223
  sprod_map :: "('a \<rightarrow> 'b) \<rightarrow> ('c \<rightarrow> 'd) \<rightarrow> 'a \<otimes> 'c \<rightarrow> 'b \<otimes> 'd"
huffman@40502
   224
where
huffman@40502
   225
  "sprod_map = (\<Lambda> f g. ssplit\<cdot>(\<Lambda> x y. (:f\<cdot>x, g\<cdot>y:)))"
huffman@40502
   226
huffman@40502
   227
lemma sprod_map_strict [simp]: "sprod_map\<cdot>a\<cdot>b\<cdot>\<bottom> = \<bottom>"
huffman@40502
   228
unfolding sprod_map_def by simp
huffman@40502
   229
huffman@40502
   230
lemma sprod_map_spair [simp]:
huffman@40502
   231
  "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
   232
by (simp add: sprod_map_def)
huffman@40502
   233
huffman@40502
   234
lemma sprod_map_spair':
huffman@40502
   235
  "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
   236
by (cases "x = \<bottom> \<or> y = \<bottom>") auto
huffman@40502
   237
huffman@40502
   238
lemma sprod_map_ID: "sprod_map\<cdot>ID\<cdot>ID = ID"
huffman@40502
   239
unfolding sprod_map_def by (simp add: cfun_eq_iff eta_cfun)
huffman@40502
   240
huffman@40502
   241
lemma sprod_map_map:
huffman@40502
   242
  "\<lbrakk>f1\<cdot>\<bottom> = \<bottom>; g1\<cdot>\<bottom> = \<bottom>\<rbrakk> \<Longrightarrow>
huffman@40502
   243
    sprod_map\<cdot>f1\<cdot>g1\<cdot>(sprod_map\<cdot>f2\<cdot>g2\<cdot>p) =
huffman@40502
   244
     sprod_map\<cdot>(\<Lambda> x. f1\<cdot>(f2\<cdot>x))\<cdot>(\<Lambda> x. g1\<cdot>(g2\<cdot>x))\<cdot>p"
huffman@40502
   245
apply (induct p, simp)
huffman@40502
   246
apply (case_tac "f2\<cdot>x = \<bottom>", simp)
huffman@40502
   247
apply (case_tac "g2\<cdot>y = \<bottom>", simp)
huffman@40502
   248
apply simp
huffman@40502
   249
done
huffman@40502
   250
huffman@40502
   251
lemma ep_pair_sprod_map:
huffman@40502
   252
  assumes "ep_pair e1 p1" and "ep_pair e2 p2"
huffman@40502
   253
  shows "ep_pair (sprod_map\<cdot>e1\<cdot>e2) (sprod_map\<cdot>p1\<cdot>p2)"
huffman@40502
   254
proof
huffman@40502
   255
  interpret e1p1: pcpo_ep_pair e1 p1 unfolding pcpo_ep_pair_def by fact
huffman@40502
   256
  interpret e2p2: pcpo_ep_pair e2 p2 unfolding pcpo_ep_pair_def by fact
huffman@40502
   257
  fix x show "sprod_map\<cdot>p1\<cdot>p2\<cdot>(sprod_map\<cdot>e1\<cdot>e2\<cdot>x) = x"
huffman@40502
   258
    by (induct x) simp_all
huffman@40502
   259
  fix y show "sprod_map\<cdot>e1\<cdot>e2\<cdot>(sprod_map\<cdot>p1\<cdot>p2\<cdot>y) \<sqsubseteq> y"
huffman@40502
   260
    apply (induct y, simp)
huffman@40502
   261
    apply (case_tac "p1\<cdot>x = \<bottom>", simp, case_tac "p2\<cdot>y = \<bottom>", simp)
huffman@40502
   262
    apply (simp add: monofun_cfun e1p1.e_p_below e2p2.e_p_below)
huffman@40502
   263
    done
huffman@40502
   264
qed
huffman@40502
   265
huffman@40502
   266
lemma deflation_sprod_map:
huffman@40502
   267
  assumes "deflation d1" and "deflation d2"
huffman@40502
   268
  shows "deflation (sprod_map\<cdot>d1\<cdot>d2)"
huffman@40502
   269
proof
huffman@40502
   270
  interpret d1: deflation d1 by fact
huffman@40502
   271
  interpret d2: deflation d2 by fact
huffman@40502
   272
  fix x
huffman@40502
   273
  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
   274
    apply (induct x, simp)
huffman@40502
   275
    apply (case_tac "d1\<cdot>x = \<bottom>", simp, case_tac "d2\<cdot>y = \<bottom>", simp)
huffman@40502
   276
    apply (simp add: d1.idem d2.idem)
huffman@40502
   277
    done
huffman@40502
   278
  show "sprod_map\<cdot>d1\<cdot>d2\<cdot>x \<sqsubseteq> x"
huffman@40502
   279
    apply (induct x, simp)
huffman@40502
   280
    apply (simp add: monofun_cfun d1.below d2.below)
huffman@40502
   281
    done
huffman@40502
   282
qed
huffman@40502
   283
huffman@40502
   284
lemma finite_deflation_sprod_map:
huffman@40502
   285
  assumes "finite_deflation d1" and "finite_deflation d2"
huffman@40502
   286
  shows "finite_deflation (sprod_map\<cdot>d1\<cdot>d2)"
huffman@40502
   287
proof (rule finite_deflation_intro)
huffman@40502
   288
  interpret d1: finite_deflation d1 by fact
huffman@40502
   289
  interpret d2: finite_deflation d2 by fact
huffman@40502
   290
  have "deflation d1" and "deflation d2" by fact+
huffman@40502
   291
  thus "deflation (sprod_map\<cdot>d1\<cdot>d2)" by (rule deflation_sprod_map)
huffman@40502
   292
  have "{x. sprod_map\<cdot>d1\<cdot>d2\<cdot>x = x} \<subseteq> insert \<bottom>
huffman@40502
   293
        ((\<lambda>(x, y). (:x, y:)) ` ({x. d1\<cdot>x = x} \<times> {y. d2\<cdot>y = y}))"
huffman@40502
   294
    by (rule subsetI, case_tac x, auto simp add: spair_eq_iff)
huffman@40502
   295
  thus "finite {x. sprod_map\<cdot>d1\<cdot>d2\<cdot>x = x}"
huffman@40502
   296
    by (rule finite_subset, simp add: d1.finite_fixes d2.finite_fixes)
huffman@40502
   297
qed
huffman@40502
   298
huffman@40502
   299
subsection {* Map function for strict sums *}
huffman@40502
   300
huffman@40502
   301
definition
huffman@40502
   302
  ssum_map :: "('a \<rightarrow> 'b) \<rightarrow> ('c \<rightarrow> 'd) \<rightarrow> 'a \<oplus> 'c \<rightarrow> 'b \<oplus> 'd"
huffman@40502
   303
where
huffman@40502
   304
  "ssum_map = (\<Lambda> f g. sscase\<cdot>(sinl oo f)\<cdot>(sinr oo g))"
huffman@40502
   305
huffman@40502
   306
lemma ssum_map_strict [simp]: "ssum_map\<cdot>f\<cdot>g\<cdot>\<bottom> = \<bottom>"
huffman@40502
   307
unfolding ssum_map_def by simp
huffman@40502
   308
huffman@40502
   309
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
   310
unfolding ssum_map_def by simp
huffman@40502
   311
huffman@40502
   312
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
   313
unfolding ssum_map_def by simp
huffman@40502
   314
huffman@40502
   315
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
   316
by (cases "x = \<bottom>") simp_all
huffman@40502
   317
huffman@40502
   318
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
   319
by (cases "x = \<bottom>") simp_all
huffman@40502
   320
huffman@40502
   321
lemma ssum_map_ID: "ssum_map\<cdot>ID\<cdot>ID = ID"
huffman@40502
   322
unfolding ssum_map_def by (simp add: cfun_eq_iff eta_cfun)
huffman@40502
   323
huffman@40502
   324
lemma ssum_map_map:
huffman@40502
   325
  "\<lbrakk>f1\<cdot>\<bottom> = \<bottom>; g1\<cdot>\<bottom> = \<bottom>\<rbrakk> \<Longrightarrow>
huffman@40502
   326
    ssum_map\<cdot>f1\<cdot>g1\<cdot>(ssum_map\<cdot>f2\<cdot>g2\<cdot>p) =
huffman@40502
   327
     ssum_map\<cdot>(\<Lambda> x. f1\<cdot>(f2\<cdot>x))\<cdot>(\<Lambda> x. g1\<cdot>(g2\<cdot>x))\<cdot>p"
huffman@40502
   328
apply (induct p, simp)
huffman@40502
   329
apply (case_tac "f2\<cdot>x = \<bottom>", simp, simp)
huffman@40502
   330
apply (case_tac "g2\<cdot>y = \<bottom>", simp, simp)
huffman@40502
   331
done
huffman@40502
   332
huffman@40502
   333
lemma ep_pair_ssum_map:
huffman@40502
   334
  assumes "ep_pair e1 p1" and "ep_pair e2 p2"
huffman@40502
   335
  shows "ep_pair (ssum_map\<cdot>e1\<cdot>e2) (ssum_map\<cdot>p1\<cdot>p2)"
huffman@40502
   336
proof
huffman@40502
   337
  interpret e1p1: pcpo_ep_pair e1 p1 unfolding pcpo_ep_pair_def by fact
huffman@40502
   338
  interpret e2p2: pcpo_ep_pair e2 p2 unfolding pcpo_ep_pair_def by fact
huffman@40502
   339
  fix x show "ssum_map\<cdot>p1\<cdot>p2\<cdot>(ssum_map\<cdot>e1\<cdot>e2\<cdot>x) = x"
huffman@40502
   340
    by (induct x) simp_all
huffman@40502
   341
  fix y show "ssum_map\<cdot>e1\<cdot>e2\<cdot>(ssum_map\<cdot>p1\<cdot>p2\<cdot>y) \<sqsubseteq> y"
huffman@40502
   342
    apply (induct y, simp)
huffman@40502
   343
    apply (case_tac "p1\<cdot>x = \<bottom>", simp, simp add: e1p1.e_p_below)
huffman@40502
   344
    apply (case_tac "p2\<cdot>y = \<bottom>", simp, simp add: e2p2.e_p_below)
huffman@40502
   345
    done
huffman@40502
   346
qed
huffman@40502
   347
huffman@40502
   348
lemma deflation_ssum_map:
huffman@40502
   349
  assumes "deflation d1" and "deflation d2"
huffman@40502
   350
  shows "deflation (ssum_map\<cdot>d1\<cdot>d2)"
huffman@40502
   351
proof
huffman@40502
   352
  interpret d1: deflation d1 by fact
huffman@40502
   353
  interpret d2: deflation d2 by fact
huffman@40502
   354
  fix x
huffman@40502
   355
  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
   356
    apply (induct x, simp)
huffman@40502
   357
    apply (case_tac "d1\<cdot>x = \<bottom>", simp, simp add: d1.idem)
huffman@40502
   358
    apply (case_tac "d2\<cdot>y = \<bottom>", simp, simp add: d2.idem)
huffman@40502
   359
    done
huffman@40502
   360
  show "ssum_map\<cdot>d1\<cdot>d2\<cdot>x \<sqsubseteq> x"
huffman@40502
   361
    apply (induct x, simp)
huffman@40502
   362
    apply (case_tac "d1\<cdot>x = \<bottom>", simp, simp add: d1.below)
huffman@40502
   363
    apply (case_tac "d2\<cdot>y = \<bottom>", simp, simp add: d2.below)
huffman@40502
   364
    done
huffman@40502
   365
qed
huffman@40502
   366
huffman@40502
   367
lemma finite_deflation_ssum_map:
huffman@40502
   368
  assumes "finite_deflation d1" and "finite_deflation d2"
huffman@40502
   369
  shows "finite_deflation (ssum_map\<cdot>d1\<cdot>d2)"
huffman@40502
   370
proof (rule finite_deflation_intro)
huffman@40502
   371
  interpret d1: finite_deflation d1 by fact
huffman@40502
   372
  interpret d2: finite_deflation d2 by fact
huffman@40502
   373
  have "deflation d1" and "deflation d2" by fact+
huffman@40502
   374
  thus "deflation (ssum_map\<cdot>d1\<cdot>d2)" by (rule deflation_ssum_map)
huffman@40502
   375
  have "{x. ssum_map\<cdot>d1\<cdot>d2\<cdot>x = x} \<subseteq>
huffman@40502
   376
        (\<lambda>x. sinl\<cdot>x) ` {x. d1\<cdot>x = x} \<union>
huffman@40502
   377
        (\<lambda>x. sinr\<cdot>x) ` {x. d2\<cdot>x = x} \<union> {\<bottom>}"
huffman@40502
   378
    by (rule subsetI, case_tac x, simp_all)
huffman@40502
   379
  thus "finite {x. ssum_map\<cdot>d1\<cdot>d2\<cdot>x = x}"
huffman@40502
   380
    by (rule finite_subset, simp add: d1.finite_fixes d2.finite_fixes)
huffman@40502
   381
qed
huffman@40502
   382
huffman@40502
   383
end