src/HOLCF/ConvexPD.thy
author huffman
Wed Nov 10 17:56:08 2010 -0800 (2010-11-10)
changeset 40502 8e92772bc0e8
parent 40497 d2e876d6da8c
child 40576 fa5e0cacd5e7
permissions -rw-r--r--
move map functions to new theory file Map_Functions; add theory file Plain_HOLCF
huffman@25904
     1
(*  Title:      HOLCF/ConvexPD.thy
huffman@25904
     2
    Author:     Brian Huffman
huffman@25904
     3
*)
huffman@25904
     4
huffman@25904
     5
header {* Convex powerdomain *}
huffman@25904
     6
huffman@25904
     7
theory ConvexPD
huffman@25904
     8
imports UpperPD LowerPD
huffman@25904
     9
begin
huffman@25904
    10
huffman@25904
    11
subsection {* Basis preorder *}
huffman@25904
    12
huffman@25904
    13
definition
huffman@25904
    14
  convex_le :: "'a pd_basis \<Rightarrow> 'a pd_basis \<Rightarrow> bool" (infix "\<le>\<natural>" 50) where
huffman@25904
    15
  "convex_le = (\<lambda>u v. u \<le>\<sharp> v \<and> u \<le>\<flat> v)"
huffman@25904
    16
huffman@25904
    17
lemma convex_le_refl [simp]: "t \<le>\<natural> t"
huffman@25904
    18
unfolding convex_le_def by (fast intro: upper_le_refl lower_le_refl)
huffman@25904
    19
huffman@25904
    20
lemma convex_le_trans: "\<lbrakk>t \<le>\<natural> u; u \<le>\<natural> v\<rbrakk> \<Longrightarrow> t \<le>\<natural> v"
huffman@25904
    21
unfolding convex_le_def by (fast intro: upper_le_trans lower_le_trans)
huffman@25904
    22
wenzelm@30729
    23
interpretation convex_le: preorder convex_le
huffman@25904
    24
by (rule preorder.intro, rule convex_le_refl, rule convex_le_trans)
huffman@25904
    25
huffman@25904
    26
lemma upper_le_minimal [simp]: "PDUnit compact_bot \<le>\<natural> t"
huffman@25904
    27
unfolding convex_le_def Rep_PDUnit by simp
huffman@25904
    28
huffman@26420
    29
lemma PDUnit_convex_mono: "x \<sqsubseteq> y \<Longrightarrow> PDUnit x \<le>\<natural> PDUnit y"
huffman@25904
    30
unfolding convex_le_def by (fast intro: PDUnit_upper_mono PDUnit_lower_mono)
huffman@25904
    31
huffman@25904
    32
lemma PDPlus_convex_mono: "\<lbrakk>s \<le>\<natural> t; u \<le>\<natural> v\<rbrakk> \<Longrightarrow> PDPlus s u \<le>\<natural> PDPlus t v"
huffman@25904
    33
unfolding convex_le_def by (fast intro: PDPlus_upper_mono PDPlus_lower_mono)
huffman@25904
    34
huffman@25904
    35
lemma convex_le_PDUnit_PDUnit_iff [simp]:
huffman@40436
    36
  "(PDUnit a \<le>\<natural> PDUnit b) = (a \<sqsubseteq> b)"
huffman@25904
    37
unfolding convex_le_def upper_le_def lower_le_def Rep_PDUnit by fast
huffman@25904
    38
huffman@25904
    39
lemma convex_le_PDUnit_lemma1:
huffman@26420
    40
  "(PDUnit a \<le>\<natural> t) = (\<forall>b\<in>Rep_pd_basis t. a \<sqsubseteq> b)"
huffman@25904
    41
unfolding convex_le_def upper_le_def lower_le_def Rep_PDUnit
huffman@25904
    42
using Rep_pd_basis_nonempty [of t, folded ex_in_conv] by fast
huffman@25904
    43
huffman@25904
    44
lemma convex_le_PDUnit_PDPlus_iff [simp]:
huffman@25904
    45
  "(PDUnit a \<le>\<natural> PDPlus t u) = (PDUnit a \<le>\<natural> t \<and> PDUnit a \<le>\<natural> u)"
huffman@25904
    46
unfolding convex_le_PDUnit_lemma1 Rep_PDPlus by fast
huffman@25904
    47
huffman@25904
    48
lemma convex_le_PDUnit_lemma2:
huffman@26420
    49
  "(t \<le>\<natural> PDUnit b) = (\<forall>a\<in>Rep_pd_basis t. a \<sqsubseteq> b)"
huffman@25904
    50
unfolding convex_le_def upper_le_def lower_le_def Rep_PDUnit
huffman@25904
    51
using Rep_pd_basis_nonempty [of t, folded ex_in_conv] by fast
huffman@25904
    52
huffman@25904
    53
lemma convex_le_PDPlus_PDUnit_iff [simp]:
huffman@25904
    54
  "(PDPlus t u \<le>\<natural> PDUnit a) = (t \<le>\<natural> PDUnit a \<and> u \<le>\<natural> PDUnit a)"
huffman@25904
    55
unfolding convex_le_PDUnit_lemma2 Rep_PDPlus by fast
huffman@25904
    56
huffman@25904
    57
lemma convex_le_PDPlus_lemma:
huffman@25904
    58
  assumes z: "PDPlus t u \<le>\<natural> z"
huffman@25904
    59
  shows "\<exists>v w. z = PDPlus v w \<and> t \<le>\<natural> v \<and> u \<le>\<natural> w"
huffman@25904
    60
proof (intro exI conjI)
huffman@26420
    61
  let ?A = "{b\<in>Rep_pd_basis z. \<exists>a\<in>Rep_pd_basis t. a \<sqsubseteq> b}"
huffman@26420
    62
  let ?B = "{b\<in>Rep_pd_basis z. \<exists>a\<in>Rep_pd_basis u. a \<sqsubseteq> b}"
huffman@25904
    63
  let ?v = "Abs_pd_basis ?A"
huffman@25904
    64
  let ?w = "Abs_pd_basis ?B"
huffman@25904
    65
  have Rep_v: "Rep_pd_basis ?v = ?A"
huffman@25904
    66
    apply (rule Abs_pd_basis_inverse)
huffman@25904
    67
    apply (rule Rep_pd_basis_nonempty [of t, folded ex_in_conv, THEN exE])
huffman@25904
    68
    apply (cut_tac z, simp only: convex_le_def lower_le_def, clarify)
huffman@25904
    69
    apply (drule_tac x=x in bspec, simp add: Rep_PDPlus, erule bexE)
huffman@25904
    70
    apply (simp add: pd_basis_def)
huffman@25904
    71
    apply fast
huffman@25904
    72
    done
huffman@25904
    73
  have Rep_w: "Rep_pd_basis ?w = ?B"
huffman@25904
    74
    apply (rule Abs_pd_basis_inverse)
huffman@25904
    75
    apply (rule Rep_pd_basis_nonempty [of u, folded ex_in_conv, THEN exE])
huffman@25904
    76
    apply (cut_tac z, simp only: convex_le_def lower_le_def, clarify)
huffman@25904
    77
    apply (drule_tac x=x in bspec, simp add: Rep_PDPlus, erule bexE)
huffman@25904
    78
    apply (simp add: pd_basis_def)
huffman@25904
    79
    apply fast
huffman@25904
    80
    done
huffman@25904
    81
  show "z = PDPlus ?v ?w"
huffman@25904
    82
    apply (insert z)
huffman@25904
    83
    apply (simp add: convex_le_def, erule conjE)
huffman@25904
    84
    apply (simp add: Rep_pd_basis_inject [symmetric] Rep_PDPlus)
huffman@25904
    85
    apply (simp add: Rep_v Rep_w)
huffman@25904
    86
    apply (rule equalityI)
huffman@25904
    87
     apply (rule subsetI)
huffman@25904
    88
     apply (simp only: upper_le_def)
huffman@25904
    89
     apply (drule (1) bspec, erule bexE)
huffman@25904
    90
     apply (simp add: Rep_PDPlus)
huffman@25904
    91
     apply fast
huffman@25904
    92
    apply fast
huffman@25904
    93
    done
huffman@25904
    94
  show "t \<le>\<natural> ?v" "u \<le>\<natural> ?w"
huffman@25904
    95
   apply (insert z)
huffman@25904
    96
   apply (simp_all add: convex_le_def upper_le_def lower_le_def Rep_PDPlus Rep_v Rep_w)
huffman@25904
    97
   apply fast+
huffman@25904
    98
   done
huffman@25904
    99
qed
huffman@25904
   100
huffman@25904
   101
lemma convex_le_induct [induct set: convex_le]:
huffman@25904
   102
  assumes le: "t \<le>\<natural> u"
huffman@25904
   103
  assumes 2: "\<And>t u v. \<lbrakk>P t u; P u v\<rbrakk> \<Longrightarrow> P t v"
huffman@26420
   104
  assumes 3: "\<And>a b. a \<sqsubseteq> b \<Longrightarrow> P (PDUnit a) (PDUnit b)"
huffman@25904
   105
  assumes 4: "\<And>t u v w. \<lbrakk>P t v; P u w\<rbrakk> \<Longrightarrow> P (PDPlus t u) (PDPlus v w)"
huffman@25904
   106
  shows "P t u"
huffman@25904
   107
using le apply (induct t arbitrary: u rule: pd_basis_induct)
huffman@25904
   108
apply (erule rev_mp)
huffman@25904
   109
apply (induct_tac u rule: pd_basis_induct1)
huffman@25904
   110
apply (simp add: 3)
huffman@25904
   111
apply (simp, clarify, rename_tac a b t)
huffman@25904
   112
apply (subgoal_tac "P (PDPlus (PDUnit a) (PDUnit a)) (PDPlus (PDUnit b) t)")
huffman@25904
   113
apply (simp add: PDPlus_absorb)
huffman@25904
   114
apply (erule (1) 4 [OF 3])
huffman@25904
   115
apply (drule convex_le_PDPlus_lemma, clarify)
huffman@25904
   116
apply (simp add: 4)
huffman@25904
   117
done
huffman@25904
   118
huffman@25904
   119
huffman@25904
   120
subsection {* Type definition *}
huffman@25904
   121
huffman@27373
   122
typedef (open) 'a convex_pd =
huffman@27373
   123
  "{S::'a pd_basis set. convex_le.ideal S}"
huffman@27373
   124
by (fast intro: convex_le.ideal_principal)
huffman@27373
   125
huffman@40497
   126
instantiation convex_pd :: ("domain") below
huffman@27373
   127
begin
huffman@27373
   128
huffman@27373
   129
definition
huffman@27373
   130
  "x \<sqsubseteq> y \<longleftrightarrow> Rep_convex_pd x \<subseteq> Rep_convex_pd y"
huffman@27373
   131
huffman@27373
   132
instance ..
huffman@27373
   133
end
huffman@25904
   134
huffman@40497
   135
instance convex_pd :: ("domain") po
huffman@39974
   136
using type_definition_convex_pd below_convex_pd_def
huffman@39974
   137
by (rule convex_le.typedef_ideal_po)
huffman@27373
   138
huffman@40497
   139
instance convex_pd :: ("domain") cpo
huffman@39974
   140
using type_definition_convex_pd below_convex_pd_def
huffman@39974
   141
by (rule convex_le.typedef_ideal_cpo)
huffman@27373
   142
huffman@25904
   143
definition
huffman@25904
   144
  convex_principal :: "'a pd_basis \<Rightarrow> 'a convex_pd" where
huffman@27373
   145
  "convex_principal t = Abs_convex_pd {u. u \<le>\<natural> t}"
huffman@25904
   146
wenzelm@30729
   147
interpretation convex_pd:
huffman@39974
   148
  ideal_completion convex_le convex_principal Rep_convex_pd
huffman@39984
   149
using type_definition_convex_pd below_convex_pd_def
huffman@39984
   150
using convex_principal_def pd_basis_countable
huffman@39984
   151
by (rule convex_le.typedef_ideal_completion)
huffman@25904
   152
huffman@27289
   153
text {* Convex powerdomain is pointed *}
huffman@25904
   154
huffman@25904
   155
lemma convex_pd_minimal: "convex_principal (PDUnit compact_bot) \<sqsubseteq> ys"
huffman@25904
   156
by (induct ys rule: convex_pd.principal_induct, simp, simp)
huffman@25904
   157
huffman@40497
   158
instance convex_pd :: ("domain") pcpo
huffman@26927
   159
by intro_classes (fast intro: convex_pd_minimal)
huffman@25904
   160
huffman@25904
   161
lemma inst_convex_pd_pcpo: "\<bottom> = convex_principal (PDUnit compact_bot)"
huffman@25904
   162
by (rule convex_pd_minimal [THEN UU_I, symmetric])
huffman@25904
   163
huffman@25904
   164
huffman@26927
   165
subsection {* Monadic unit and plus *}
huffman@25904
   166
huffman@25904
   167
definition
huffman@25904
   168
  convex_unit :: "'a \<rightarrow> 'a convex_pd" where
huffman@25904
   169
  "convex_unit = compact_basis.basis_fun (\<lambda>a. convex_principal (PDUnit a))"
huffman@25904
   170
huffman@25904
   171
definition
huffman@25904
   172
  convex_plus :: "'a convex_pd \<rightarrow> 'a convex_pd \<rightarrow> 'a convex_pd" where
huffman@25904
   173
  "convex_plus = convex_pd.basis_fun (\<lambda>t. convex_pd.basis_fun (\<lambda>u.
huffman@25904
   174
      convex_principal (PDPlus t u)))"
huffman@25904
   175
huffman@25904
   176
abbreviation
huffman@25904
   177
  convex_add :: "'a convex_pd \<Rightarrow> 'a convex_pd \<Rightarrow> 'a convex_pd"
huffman@25904
   178
    (infixl "+\<natural>" 65) where
huffman@25904
   179
  "xs +\<natural> ys == convex_plus\<cdot>xs\<cdot>ys"
huffman@25904
   180
huffman@26927
   181
syntax
huffman@26927
   182
  "_convex_pd" :: "args \<Rightarrow> 'a convex_pd" ("{_}\<natural>")
huffman@26927
   183
huffman@26927
   184
translations
huffman@26927
   185
  "{x,xs}\<natural>" == "{x}\<natural> +\<natural> {xs}\<natural>"
huffman@26927
   186
  "{x}\<natural>" == "CONST convex_unit\<cdot>x"
huffman@26927
   187
huffman@26927
   188
lemma convex_unit_Rep_compact_basis [simp]:
huffman@26927
   189
  "{Rep_compact_basis a}\<natural> = convex_principal (PDUnit a)"
huffman@26927
   190
unfolding convex_unit_def
huffman@27289
   191
by (simp add: compact_basis.basis_fun_principal PDUnit_convex_mono)
huffman@26927
   192
huffman@25904
   193
lemma convex_plus_principal [simp]:
huffman@26927
   194
  "convex_principal t +\<natural> convex_principal u = convex_principal (PDPlus t u)"
huffman@25904
   195
unfolding convex_plus_def
huffman@25904
   196
by (simp add: convex_pd.basis_fun_principal
huffman@25904
   197
    convex_pd.basis_fun_mono PDPlus_convex_mono)
huffman@25904
   198
haftmann@37770
   199
interpretation convex_add: semilattice convex_add proof
haftmann@34973
   200
  fix xs ys zs :: "'a convex_pd"
haftmann@34973
   201
  show "(xs +\<natural> ys) +\<natural> zs = xs +\<natural> (ys +\<natural> zs)"
haftmann@34973
   202
    apply (induct xs ys arbitrary: zs rule: convex_pd.principal_induct2, simp, simp)
haftmann@34973
   203
    apply (rule_tac x=zs in convex_pd.principal_induct, simp)
haftmann@34973
   204
    apply (simp add: PDPlus_assoc)
haftmann@34973
   205
    done
haftmann@34973
   206
  show "xs +\<natural> ys = ys +\<natural> xs"
haftmann@34973
   207
    apply (induct xs ys rule: convex_pd.principal_induct2, simp, simp)
haftmann@34973
   208
    apply (simp add: PDPlus_commute)
haftmann@34973
   209
    done
haftmann@34973
   210
  show "xs +\<natural> xs = xs"
haftmann@34973
   211
    apply (induct xs rule: convex_pd.principal_induct, simp)
haftmann@34973
   212
    apply (simp add: PDPlus_absorb)
haftmann@34973
   213
    done
haftmann@34973
   214
qed
huffman@26927
   215
haftmann@34973
   216
lemmas convex_plus_assoc = convex_add.assoc
haftmann@34973
   217
lemmas convex_plus_commute = convex_add.commute
haftmann@34973
   218
lemmas convex_plus_absorb = convex_add.idem
haftmann@34973
   219
lemmas convex_plus_left_commute = convex_add.left_commute
haftmann@34973
   220
lemmas convex_plus_left_absorb = convex_add.left_idem
huffman@26927
   221
huffman@29990
   222
text {* Useful for @{text "simp add: convex_plus_ac"} *}
huffman@29990
   223
lemmas convex_plus_ac =
huffman@29990
   224
  convex_plus_assoc convex_plus_commute convex_plus_left_commute
huffman@29990
   225
huffman@29990
   226
text {* Useful for @{text "simp only: convex_plus_aci"} *}
huffman@29990
   227
lemmas convex_plus_aci =
huffman@29990
   228
  convex_plus_ac convex_plus_absorb convex_plus_left_absorb
huffman@29990
   229
huffman@31076
   230
lemma convex_unit_below_plus_iff [simp]:
huffman@26927
   231
  "{x}\<natural> \<sqsubseteq> ys +\<natural> zs \<longleftrightarrow> {x}\<natural> \<sqsubseteq> ys \<and> {x}\<natural> \<sqsubseteq> zs"
brianh@39970
   232
apply (induct x rule: compact_basis.principal_induct, simp)
brianh@39970
   233
apply (induct ys rule: convex_pd.principal_induct, simp)
brianh@39970
   234
apply (induct zs rule: convex_pd.principal_induct, simp)
brianh@39970
   235
apply simp
huffman@25904
   236
done
huffman@25904
   237
huffman@31076
   238
lemma convex_plus_below_unit_iff [simp]:
huffman@26927
   239
  "xs +\<natural> ys \<sqsubseteq> {z}\<natural> \<longleftrightarrow> xs \<sqsubseteq> {z}\<natural> \<and> ys \<sqsubseteq> {z}\<natural>"
brianh@39970
   240
apply (induct xs rule: convex_pd.principal_induct, simp)
brianh@39970
   241
apply (induct ys rule: convex_pd.principal_induct, simp)
brianh@39970
   242
apply (induct z rule: compact_basis.principal_induct, simp)
brianh@39970
   243
apply simp
huffman@25904
   244
done
huffman@25904
   245
huffman@31076
   246
lemma convex_unit_below_iff [simp]: "{x}\<natural> \<sqsubseteq> {y}\<natural> \<longleftrightarrow> x \<sqsubseteq> y"
brianh@39970
   247
apply (induct x rule: compact_basis.principal_induct, simp)
brianh@39970
   248
apply (induct y rule: compact_basis.principal_induct, simp)
brianh@39970
   249
apply simp
huffman@26927
   250
done
huffman@26927
   251
huffman@26927
   252
lemma convex_unit_eq_iff [simp]: "{x}\<natural> = {y}\<natural> \<longleftrightarrow> x = y"
huffman@26927
   253
unfolding po_eq_conv by simp
huffman@26927
   254
huffman@26927
   255
lemma convex_unit_strict [simp]: "{\<bottom>}\<natural> = \<bottom>"
huffman@39974
   256
using convex_unit_Rep_compact_basis [of compact_bot]
huffman@39974
   257
by (simp add: inst_convex_pd_pcpo)
huffman@26927
   258
huffman@40321
   259
lemma convex_unit_bottom_iff [simp]: "{x}\<natural> = \<bottom> \<longleftrightarrow> x = \<bottom>"
huffman@26927
   260
unfolding convex_unit_strict [symmetric] by (rule convex_unit_eq_iff)
huffman@26927
   261
huffman@39974
   262
lemma compact_convex_unit: "compact x \<Longrightarrow> compact {x}\<natural>"
huffman@39974
   263
by (auto dest!: compact_basis.compact_imp_principal)
huffman@39974
   264
huffman@39974
   265
lemma compact_convex_unit_iff [simp]: "compact {x}\<natural> \<longleftrightarrow> compact x"
huffman@39974
   266
apply (safe elim!: compact_convex_unit)
huffman@39974
   267
apply (simp only: compact_def convex_unit_below_iff [symmetric])
huffman@40327
   268
apply (erule adm_subst [OF cont_Rep_cfun2])
huffman@39974
   269
done
huffman@26927
   270
huffman@26927
   271
lemma compact_convex_plus [simp]:
huffman@26927
   272
  "\<lbrakk>compact xs; compact ys\<rbrakk> \<Longrightarrow> compact (xs +\<natural> ys)"
huffman@27289
   273
by (auto dest!: convex_pd.compact_imp_principal)
huffman@26927
   274
huffman@25904
   275
huffman@25904
   276
subsection {* Induction rules *}
huffman@25904
   277
huffman@25904
   278
lemma convex_pd_induct1:
huffman@25904
   279
  assumes P: "adm P"
huffman@26927
   280
  assumes unit: "\<And>x. P {x}\<natural>"
huffman@26927
   281
  assumes insert: "\<And>x ys. \<lbrakk>P {x}\<natural>; P ys\<rbrakk> \<Longrightarrow> P ({x}\<natural> +\<natural> ys)"
huffman@25904
   282
  shows "P (xs::'a convex_pd)"
huffman@27289
   283
apply (induct xs rule: convex_pd.principal_induct, rule P)
huffman@27289
   284
apply (induct_tac a rule: pd_basis_induct1)
huffman@25904
   285
apply (simp only: convex_unit_Rep_compact_basis [symmetric])
huffman@25904
   286
apply (rule unit)
huffman@25904
   287
apply (simp only: convex_unit_Rep_compact_basis [symmetric]
huffman@25904
   288
                  convex_plus_principal [symmetric])
huffman@25904
   289
apply (erule insert [OF unit])
huffman@25904
   290
done
huffman@25904
   291
huffman@25904
   292
lemma convex_pd_induct:
huffman@25904
   293
  assumes P: "adm P"
huffman@26927
   294
  assumes unit: "\<And>x. P {x}\<natural>"
huffman@26927
   295
  assumes plus: "\<And>xs ys. \<lbrakk>P xs; P ys\<rbrakk> \<Longrightarrow> P (xs +\<natural> ys)"
huffman@25904
   296
  shows "P (xs::'a convex_pd)"
huffman@27289
   297
apply (induct xs rule: convex_pd.principal_induct, rule P)
huffman@27289
   298
apply (induct_tac a rule: pd_basis_induct)
huffman@25904
   299
apply (simp only: convex_unit_Rep_compact_basis [symmetric] unit)
huffman@25904
   300
apply (simp only: convex_plus_principal [symmetric] plus)
huffman@25904
   301
done
huffman@25904
   302
huffman@25904
   303
huffman@25904
   304
subsection {* Monadic bind *}
huffman@25904
   305
huffman@25904
   306
definition
huffman@25904
   307
  convex_bind_basis ::
huffman@25904
   308
  "'a pd_basis \<Rightarrow> ('a \<rightarrow> 'b convex_pd) \<rightarrow> 'b convex_pd" where
huffman@25904
   309
  "convex_bind_basis = fold_pd
huffman@25904
   310
    (\<lambda>a. \<Lambda> f. f\<cdot>(Rep_compact_basis a))
huffman@26927
   311
    (\<lambda>x y. \<Lambda> f. x\<cdot>f +\<natural> y\<cdot>f)"
huffman@25904
   312
huffman@26927
   313
lemma ACI_convex_bind:
haftmann@36635
   314
  "class.ab_semigroup_idem_mult (\<lambda>x y. \<Lambda> f. x\<cdot>f +\<natural> y\<cdot>f)"
huffman@25904
   315
apply unfold_locales
haftmann@26041
   316
apply (simp add: convex_plus_assoc)
huffman@25904
   317
apply (simp add: convex_plus_commute)
huffman@29990
   318
apply (simp add: eta_cfun)
huffman@25904
   319
done
huffman@25904
   320
huffman@25904
   321
lemma convex_bind_basis_simps [simp]:
huffman@25904
   322
  "convex_bind_basis (PDUnit a) =
huffman@25904
   323
    (\<Lambda> f. f\<cdot>(Rep_compact_basis a))"
huffman@25904
   324
  "convex_bind_basis (PDPlus t u) =
huffman@26927
   325
    (\<Lambda> f. convex_bind_basis t\<cdot>f +\<natural> convex_bind_basis u\<cdot>f)"
huffman@25904
   326
unfolding convex_bind_basis_def
huffman@25904
   327
apply -
huffman@26927
   328
apply (rule fold_pd_PDUnit [OF ACI_convex_bind])
huffman@26927
   329
apply (rule fold_pd_PDPlus [OF ACI_convex_bind])
huffman@25904
   330
done
huffman@25904
   331
huffman@25904
   332
lemma convex_bind_basis_mono:
huffman@25904
   333
  "t \<le>\<natural> u \<Longrightarrow> convex_bind_basis t \<sqsubseteq> convex_bind_basis u"
huffman@25904
   334
apply (erule convex_le_induct)
huffman@31076
   335
apply (erule (1) below_trans)
huffman@27289
   336
apply (simp add: monofun_LAM monofun_cfun)
huffman@27289
   337
apply (simp add: monofun_LAM monofun_cfun)
huffman@25904
   338
done
huffman@25904
   339
huffman@25904
   340
definition
huffman@25904
   341
  convex_bind :: "'a convex_pd \<rightarrow> ('a \<rightarrow> 'b convex_pd) \<rightarrow> 'b convex_pd" where
huffman@25904
   342
  "convex_bind = convex_pd.basis_fun convex_bind_basis"
huffman@25904
   343
huffman@25904
   344
lemma convex_bind_principal [simp]:
huffman@25904
   345
  "convex_bind\<cdot>(convex_principal t) = convex_bind_basis t"
huffman@25904
   346
unfolding convex_bind_def
huffman@25904
   347
apply (rule convex_pd.basis_fun_principal)
huffman@25904
   348
apply (erule convex_bind_basis_mono)
huffman@25904
   349
done
huffman@25904
   350
huffman@25904
   351
lemma convex_bind_unit [simp]:
huffman@26927
   352
  "convex_bind\<cdot>{x}\<natural>\<cdot>f = f\<cdot>x"
huffman@27289
   353
by (induct x rule: compact_basis.principal_induct, simp, simp)
huffman@25904
   354
huffman@25904
   355
lemma convex_bind_plus [simp]:
huffman@26927
   356
  "convex_bind\<cdot>(xs +\<natural> ys)\<cdot>f = convex_bind\<cdot>xs\<cdot>f +\<natural> convex_bind\<cdot>ys\<cdot>f"
huffman@27289
   357
by (induct xs ys rule: convex_pd.principal_induct2, simp, simp, simp)
huffman@25904
   358
huffman@25904
   359
lemma convex_bind_strict [simp]: "convex_bind\<cdot>\<bottom>\<cdot>f = f\<cdot>\<bottom>"
huffman@25904
   360
unfolding convex_unit_strict [symmetric] by (rule convex_bind_unit)
huffman@25904
   361
huffman@25904
   362
huffman@39974
   363
subsection {* Map *}
huffman@25904
   364
huffman@25904
   365
definition
huffman@25904
   366
  convex_map :: "('a \<rightarrow> 'b) \<rightarrow> 'a convex_pd \<rightarrow> 'b convex_pd" where
huffman@26927
   367
  "convex_map = (\<Lambda> f xs. convex_bind\<cdot>xs\<cdot>(\<Lambda> x. {f\<cdot>x}\<natural>))"
huffman@25904
   368
huffman@25904
   369
lemma convex_map_unit [simp]:
huffman@39974
   370
  "convex_map\<cdot>f\<cdot>{x}\<natural> = {f\<cdot>x}\<natural>"
huffman@25904
   371
unfolding convex_map_def by simp
huffman@25904
   372
huffman@25904
   373
lemma convex_map_plus [simp]:
huffman@26927
   374
  "convex_map\<cdot>f\<cdot>(xs +\<natural> ys) = convex_map\<cdot>f\<cdot>xs +\<natural> convex_map\<cdot>f\<cdot>ys"
huffman@25904
   375
unfolding convex_map_def by simp
huffman@25904
   376
huffman@25904
   377
lemma convex_map_ident: "convex_map\<cdot>(\<Lambda> x. x)\<cdot>xs = xs"
huffman@25904
   378
by (induct xs rule: convex_pd_induct, simp_all)
huffman@25904
   379
huffman@33808
   380
lemma convex_map_ID: "convex_map\<cdot>ID = ID"
huffman@40002
   381
by (simp add: cfun_eq_iff ID_def convex_map_ident)
huffman@33808
   382
huffman@25904
   383
lemma convex_map_map:
huffman@25904
   384
  "convex_map\<cdot>f\<cdot>(convex_map\<cdot>g\<cdot>xs) = convex_map\<cdot>(\<Lambda> x. f\<cdot>(g\<cdot>x))\<cdot>xs"
huffman@25904
   385
by (induct xs rule: convex_pd_induct, simp_all)
huffman@25904
   386
huffman@39974
   387
lemma ep_pair_convex_map: "ep_pair e p \<Longrightarrow> ep_pair (convex_map\<cdot>e) (convex_map\<cdot>p)"
huffman@39974
   388
apply default
huffman@39974
   389
apply (induct_tac x rule: convex_pd_induct, simp_all add: ep_pair.e_inverse)
huffman@39974
   390
apply (induct_tac y rule: convex_pd_induct)
huffman@39974
   391
apply (simp_all add: ep_pair.e_p_below monofun_cfun)
huffman@39974
   392
done
huffman@39974
   393
huffman@39974
   394
lemma deflation_convex_map: "deflation d \<Longrightarrow> deflation (convex_map\<cdot>d)"
huffman@39974
   395
apply default
huffman@39974
   396
apply (induct_tac x rule: convex_pd_induct, simp_all add: deflation.idem)
huffman@39974
   397
apply (induct_tac x rule: convex_pd_induct)
huffman@39974
   398
apply (simp_all add: deflation.below monofun_cfun)
huffman@39974
   399
done
huffman@39974
   400
huffman@39974
   401
(* FIXME: long proof! *)
huffman@39974
   402
lemma finite_deflation_convex_map:
huffman@39974
   403
  assumes "finite_deflation d" shows "finite_deflation (convex_map\<cdot>d)"
huffman@39974
   404
proof (rule finite_deflation_intro)
huffman@39974
   405
  interpret d: finite_deflation d by fact
huffman@39974
   406
  have "deflation d" by fact
huffman@39974
   407
  thus "deflation (convex_map\<cdot>d)" by (rule deflation_convex_map)
huffman@39974
   408
  have "finite (range (\<lambda>x. d\<cdot>x))" by (rule d.finite_range)
huffman@39974
   409
  hence "finite (Rep_compact_basis -` range (\<lambda>x. d\<cdot>x))"
huffman@39974
   410
    by (rule finite_vimageI, simp add: inj_on_def Rep_compact_basis_inject)
huffman@39974
   411
  hence "finite (Pow (Rep_compact_basis -` range (\<lambda>x. d\<cdot>x)))" by simp
huffman@39974
   412
  hence "finite (Rep_pd_basis -` (Pow (Rep_compact_basis -` range (\<lambda>x. d\<cdot>x))))"
huffman@39974
   413
    by (rule finite_vimageI, simp add: inj_on_def Rep_pd_basis_inject)
huffman@39974
   414
  hence *: "finite (convex_principal ` Rep_pd_basis -` (Pow (Rep_compact_basis -` range (\<lambda>x. d\<cdot>x))))" by simp
huffman@39974
   415
  hence "finite (range (\<lambda>xs. convex_map\<cdot>d\<cdot>xs))"
huffman@39974
   416
    apply (rule rev_finite_subset)
huffman@39974
   417
    apply clarsimp
huffman@39974
   418
    apply (induct_tac xs rule: convex_pd.principal_induct)
huffman@39974
   419
    apply (simp add: adm_mem_finite *)
huffman@39974
   420
    apply (rename_tac t, induct_tac t rule: pd_basis_induct)
huffman@39974
   421
    apply (simp only: convex_unit_Rep_compact_basis [symmetric] convex_map_unit)
huffman@39974
   422
    apply simp
huffman@39974
   423
    apply (subgoal_tac "\<exists>b. d\<cdot>(Rep_compact_basis a) = Rep_compact_basis b")
huffman@39974
   424
    apply clarsimp
huffman@39974
   425
    apply (rule imageI)
huffman@39974
   426
    apply (rule vimageI2)
huffman@39974
   427
    apply (simp add: Rep_PDUnit)
huffman@39974
   428
    apply (rule range_eqI)
huffman@39974
   429
    apply (erule sym)
huffman@39974
   430
    apply (rule exI)
huffman@39974
   431
    apply (rule Abs_compact_basis_inverse [symmetric])
huffman@39974
   432
    apply (simp add: d.compact)
huffman@39974
   433
    apply (simp only: convex_plus_principal [symmetric] convex_map_plus)
huffman@39974
   434
    apply clarsimp
huffman@39974
   435
    apply (rule imageI)
huffman@39974
   436
    apply (rule vimageI2)
huffman@39974
   437
    apply (simp add: Rep_PDPlus)
huffman@39974
   438
    done
huffman@39974
   439
  thus "finite {xs. convex_map\<cdot>d\<cdot>xs = xs}"
huffman@39974
   440
    by (rule finite_range_imp_finite_fixes)
huffman@39974
   441
qed
huffman@39974
   442
huffman@40497
   443
subsection {* Convex powerdomain is a domain *}
huffman@39974
   444
huffman@39974
   445
definition
huffman@39974
   446
  convex_approx :: "nat \<Rightarrow> udom convex_pd \<rightarrow> udom convex_pd"
huffman@39974
   447
where
huffman@39974
   448
  "convex_approx = (\<lambda>i. convex_map\<cdot>(udom_approx i))"
huffman@39974
   449
huffman@39974
   450
lemma convex_approx: "approx_chain convex_approx"
huffman@40484
   451
using convex_map_ID finite_deflation_convex_map
huffman@40484
   452
unfolding convex_approx_def by (rule approx_chain_lemma1)
huffman@39974
   453
huffman@39989
   454
definition convex_defl :: "defl \<rightarrow> defl"
huffman@39989
   455
where "convex_defl = defl_fun1 convex_approx convex_map"
huffman@39974
   456
huffman@39989
   457
lemma cast_convex_defl:
huffman@39989
   458
  "cast\<cdot>(convex_defl\<cdot>A) =
huffman@39974
   459
    udom_emb convex_approx oo convex_map\<cdot>(cast\<cdot>A) oo udom_prj convex_approx"
huffman@40484
   460
using convex_approx finite_deflation_convex_map
huffman@40484
   461
unfolding convex_defl_def by (rule cast_defl_fun1)
huffman@39974
   462
huffman@40497
   463
instantiation convex_pd :: ("domain") liftdomain
huffman@39974
   464
begin
huffman@39974
   465
huffman@39974
   466
definition
huffman@39974
   467
  "emb = udom_emb convex_approx oo convex_map\<cdot>emb"
huffman@39974
   468
huffman@39974
   469
definition
huffman@39974
   470
  "prj = convex_map\<cdot>prj oo udom_prj convex_approx"
huffman@39974
   471
huffman@39974
   472
definition
huffman@39989
   473
  "defl (t::'a convex_pd itself) = convex_defl\<cdot>DEFL('a)"
huffman@39974
   474
huffman@40491
   475
definition
huffman@40491
   476
  "(liftemb :: 'a convex_pd u \<rightarrow> udom) = udom_emb u_approx oo u_map\<cdot>emb"
huffman@40491
   477
huffman@40491
   478
definition
huffman@40491
   479
  "(liftprj :: udom \<rightarrow> 'a convex_pd u) = u_map\<cdot>prj oo udom_prj u_approx"
huffman@40491
   480
huffman@40491
   481
definition
huffman@40491
   482
  "liftdefl (t::'a convex_pd itself) = u_defl\<cdot>DEFL('a convex_pd)"
huffman@40491
   483
huffman@40491
   484
instance
huffman@40491
   485
using liftemb_convex_pd_def liftprj_convex_pd_def liftdefl_convex_pd_def
huffman@40494
   486
proof (rule liftdomain_class_intro)
huffman@39974
   487
  show "ep_pair emb (prj :: udom \<rightarrow> 'a convex_pd)"
huffman@39974
   488
    unfolding emb_convex_pd_def prj_convex_pd_def
huffman@39974
   489
    using ep_pair_udom [OF convex_approx]
huffman@39974
   490
    by (intro ep_pair_comp ep_pair_convex_map ep_pair_emb_prj)
huffman@39974
   491
next
huffman@39989
   492
  show "cast\<cdot>DEFL('a convex_pd) = emb oo (prj :: udom \<rightarrow> 'a convex_pd)"
huffman@39989
   493
    unfolding emb_convex_pd_def prj_convex_pd_def defl_convex_pd_def cast_convex_defl
huffman@40002
   494
    by (simp add: cast_DEFL oo_def cfun_eq_iff convex_map_map)
huffman@39974
   495
qed
huffman@39974
   496
huffman@39974
   497
end
huffman@39974
   498
huffman@39989
   499
text {* DEFL of type constructor = type combinator *}
huffman@39974
   500
huffman@39989
   501
lemma DEFL_convex: "DEFL('a convex_pd) = convex_defl\<cdot>DEFL('a)"
huffman@39989
   502
by (rule defl_convex_pd_def)
huffman@39974
   503
huffman@39974
   504
huffman@39974
   505
subsection {* Join *}
huffman@39974
   506
huffman@39974
   507
definition
huffman@39974
   508
  convex_join :: "'a convex_pd convex_pd \<rightarrow> 'a convex_pd" where
huffman@39974
   509
  "convex_join = (\<Lambda> xss. convex_bind\<cdot>xss\<cdot>(\<Lambda> xs. xs))"
huffman@39974
   510
huffman@39974
   511
lemma convex_join_unit [simp]:
huffman@39974
   512
  "convex_join\<cdot>{xs}\<natural> = xs"
huffman@39974
   513
unfolding convex_join_def by simp
huffman@39974
   514
huffman@39974
   515
lemma convex_join_plus [simp]:
huffman@39974
   516
  "convex_join\<cdot>(xss +\<natural> yss) = convex_join\<cdot>xss +\<natural> convex_join\<cdot>yss"
huffman@39974
   517
unfolding convex_join_def by simp
huffman@39974
   518
huffman@25904
   519
lemma convex_join_map_unit:
huffman@25904
   520
  "convex_join\<cdot>(convex_map\<cdot>convex_unit\<cdot>xs) = xs"
huffman@25904
   521
by (induct xs rule: convex_pd_induct, simp_all)
huffman@25904
   522
huffman@25904
   523
lemma convex_join_map_join:
huffman@25904
   524
  "convex_join\<cdot>(convex_map\<cdot>convex_join\<cdot>xsss) = convex_join\<cdot>(convex_join\<cdot>xsss)"
huffman@25904
   525
by (induct xsss rule: convex_pd_induct, simp_all)
huffman@25904
   526
huffman@25904
   527
lemma convex_join_map_map:
huffman@25904
   528
  "convex_join\<cdot>(convex_map\<cdot>(convex_map\<cdot>f)\<cdot>xss) =
huffman@25904
   529
   convex_map\<cdot>f\<cdot>(convex_join\<cdot>xss)"
huffman@25904
   530
by (induct xss rule: convex_pd_induct, simp_all)
huffman@25904
   531
huffman@25904
   532
huffman@25904
   533
subsection {* Conversions to other powerdomains *}
huffman@25904
   534
huffman@25904
   535
text {* Convex to upper *}
huffman@25904
   536
huffman@25904
   537
lemma convex_le_imp_upper_le: "t \<le>\<natural> u \<Longrightarrow> t \<le>\<sharp> u"
huffman@25904
   538
unfolding convex_le_def by simp
huffman@25904
   539
huffman@25904
   540
definition
huffman@25904
   541
  convex_to_upper :: "'a convex_pd \<rightarrow> 'a upper_pd" where
huffman@25904
   542
  "convex_to_upper = convex_pd.basis_fun upper_principal"
huffman@25904
   543
huffman@25904
   544
lemma convex_to_upper_principal [simp]:
huffman@25904
   545
  "convex_to_upper\<cdot>(convex_principal t) = upper_principal t"
huffman@25904
   546
unfolding convex_to_upper_def
huffman@25904
   547
apply (rule convex_pd.basis_fun_principal)
huffman@27289
   548
apply (rule upper_pd.principal_mono)
huffman@25904
   549
apply (erule convex_le_imp_upper_le)
huffman@25904
   550
done
huffman@25904
   551
huffman@25904
   552
lemma convex_to_upper_unit [simp]:
huffman@26927
   553
  "convex_to_upper\<cdot>{x}\<natural> = {x}\<sharp>"
huffman@27289
   554
by (induct x rule: compact_basis.principal_induct, simp, simp)
huffman@25904
   555
huffman@25904
   556
lemma convex_to_upper_plus [simp]:
huffman@26927
   557
  "convex_to_upper\<cdot>(xs +\<natural> ys) = convex_to_upper\<cdot>xs +\<sharp> convex_to_upper\<cdot>ys"
huffman@27289
   558
by (induct xs ys rule: convex_pd.principal_induct2, simp, simp, simp)
huffman@25904
   559
huffman@27289
   560
lemma convex_to_upper_bind [simp]:
huffman@27289
   561
  "convex_to_upper\<cdot>(convex_bind\<cdot>xs\<cdot>f) =
huffman@27289
   562
    upper_bind\<cdot>(convex_to_upper\<cdot>xs)\<cdot>(convex_to_upper oo f)"
huffman@27289
   563
by (induct xs rule: convex_pd_induct, simp, simp, simp)
huffman@27289
   564
huffman@27289
   565
lemma convex_to_upper_map [simp]:
huffman@27289
   566
  "convex_to_upper\<cdot>(convex_map\<cdot>f\<cdot>xs) = upper_map\<cdot>f\<cdot>(convex_to_upper\<cdot>xs)"
huffman@27289
   567
by (simp add: convex_map_def upper_map_def cfcomp_LAM)
huffman@27289
   568
huffman@27289
   569
lemma convex_to_upper_join [simp]:
huffman@27289
   570
  "convex_to_upper\<cdot>(convex_join\<cdot>xss) =
huffman@27289
   571
    upper_bind\<cdot>(convex_to_upper\<cdot>xss)\<cdot>convex_to_upper"
huffman@27289
   572
by (simp add: convex_join_def upper_join_def cfcomp_LAM eta_cfun)
huffman@27289
   573
huffman@25904
   574
text {* Convex to lower *}
huffman@25904
   575
huffman@25904
   576
lemma convex_le_imp_lower_le: "t \<le>\<natural> u \<Longrightarrow> t \<le>\<flat> u"
huffman@25904
   577
unfolding convex_le_def by simp
huffman@25904
   578
huffman@25904
   579
definition
huffman@25904
   580
  convex_to_lower :: "'a convex_pd \<rightarrow> 'a lower_pd" where
huffman@25904
   581
  "convex_to_lower = convex_pd.basis_fun lower_principal"
huffman@25904
   582
huffman@25904
   583
lemma convex_to_lower_principal [simp]:
huffman@25904
   584
  "convex_to_lower\<cdot>(convex_principal t) = lower_principal t"
huffman@25904
   585
unfolding convex_to_lower_def
huffman@25904
   586
apply (rule convex_pd.basis_fun_principal)
huffman@27289
   587
apply (rule lower_pd.principal_mono)
huffman@25904
   588
apply (erule convex_le_imp_lower_le)
huffman@25904
   589
done
huffman@25904
   590
huffman@25904
   591
lemma convex_to_lower_unit [simp]:
huffman@26927
   592
  "convex_to_lower\<cdot>{x}\<natural> = {x}\<flat>"
huffman@27289
   593
by (induct x rule: compact_basis.principal_induct, simp, simp)
huffman@25904
   594
huffman@25904
   595
lemma convex_to_lower_plus [simp]:
huffman@26927
   596
  "convex_to_lower\<cdot>(xs +\<natural> ys) = convex_to_lower\<cdot>xs +\<flat> convex_to_lower\<cdot>ys"
huffman@27289
   597
by (induct xs ys rule: convex_pd.principal_induct2, simp, simp, simp)
huffman@25904
   598
huffman@27289
   599
lemma convex_to_lower_bind [simp]:
huffman@27289
   600
  "convex_to_lower\<cdot>(convex_bind\<cdot>xs\<cdot>f) =
huffman@27289
   601
    lower_bind\<cdot>(convex_to_lower\<cdot>xs)\<cdot>(convex_to_lower oo f)"
huffman@27289
   602
by (induct xs rule: convex_pd_induct, simp, simp, simp)
huffman@27289
   603
huffman@27289
   604
lemma convex_to_lower_map [simp]:
huffman@27289
   605
  "convex_to_lower\<cdot>(convex_map\<cdot>f\<cdot>xs) = lower_map\<cdot>f\<cdot>(convex_to_lower\<cdot>xs)"
huffman@27289
   606
by (simp add: convex_map_def lower_map_def cfcomp_LAM)
huffman@27289
   607
huffman@27289
   608
lemma convex_to_lower_join [simp]:
huffman@27289
   609
  "convex_to_lower\<cdot>(convex_join\<cdot>xss) =
huffman@27289
   610
    lower_bind\<cdot>(convex_to_lower\<cdot>xss)\<cdot>convex_to_lower"
huffman@27289
   611
by (simp add: convex_join_def lower_join_def cfcomp_LAM eta_cfun)
huffman@27289
   612
huffman@25904
   613
text {* Ordering property *}
huffman@25904
   614
huffman@31076
   615
lemma convex_pd_below_iff:
huffman@25904
   616
  "(xs \<sqsubseteq> ys) =
huffman@25904
   617
    (convex_to_upper\<cdot>xs \<sqsubseteq> convex_to_upper\<cdot>ys \<and>
huffman@25904
   618
     convex_to_lower\<cdot>xs \<sqsubseteq> convex_to_lower\<cdot>ys)"
brianh@39970
   619
apply (induct xs rule: convex_pd.principal_induct, simp)
brianh@39970
   620
apply (induct ys rule: convex_pd.principal_induct, simp)
brianh@39970
   621
apply (simp add: convex_le_def)
huffman@25904
   622
done
huffman@25904
   623
huffman@31076
   624
lemmas convex_plus_below_plus_iff =
huffman@31076
   625
  convex_pd_below_iff [where xs="xs +\<natural> ys" and ys="zs +\<natural> ws", standard]
huffman@26927
   626
huffman@31076
   627
lemmas convex_pd_below_simps =
huffman@31076
   628
  convex_unit_below_plus_iff
huffman@31076
   629
  convex_plus_below_unit_iff
huffman@31076
   630
  convex_plus_below_plus_iff
huffman@31076
   631
  convex_unit_below_iff
huffman@26927
   632
  convex_to_upper_unit
huffman@26927
   633
  convex_to_upper_plus
huffman@26927
   634
  convex_to_lower_unit
huffman@26927
   635
  convex_to_lower_plus
huffman@31076
   636
  upper_pd_below_simps
huffman@31076
   637
  lower_pd_below_simps
huffman@26927
   638
huffman@25904
   639
end