src/HOL/HOLCF/ConvexPD.thy
author wenzelm
Sat Nov 04 15:24:40 2017 +0100 (20 months ago)
changeset 67003 49850a679c2c
parent 62175 8ffc4d0e652d
child 67682 00c436488398
permissions -rw-r--r--
more robust sorted_entries;
wenzelm@42151
     1
(*  Title:      HOL/HOLCF/ConvexPD.thy
huffman@25904
     2
    Author:     Brian Huffman
huffman@25904
     3
*)
huffman@25904
     4
wenzelm@62175
     5
section \<open>Convex powerdomain\<close>
huffman@25904
     6
huffman@25904
     7
theory ConvexPD
huffman@25904
     8
imports UpperPD LowerPD
huffman@25904
     9
begin
huffman@25904
    10
wenzelm@62175
    11
subsection \<open>Basis preorder\<close>
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
wenzelm@62175
   120
subsection \<open>Type definition\<close>
huffman@25904
   121
wenzelm@61998
   122
typedef 'a convex_pd  ("('(_')\<natural>)") =
huffman@27373
   123
  "{S::'a pd_basis set. convex_le.ideal S}"
huffman@40888
   124
by (rule convex_le.ex_ideal)
huffman@27373
   125
huffman@41288
   126
instantiation convex_pd :: (bifinite) 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@41288
   135
instance convex_pd :: (bifinite) 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@41288
   139
instance convex_pd :: (bifinite) 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
wenzelm@62175
   153
text \<open>Convex powerdomain is pointed\<close>
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@41288
   158
instance convex_pd :: (bifinite) 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@41430
   162
by (rule convex_pd_minimal [THEN bottomI, symmetric])
huffman@25904
   163
huffman@25904
   164
wenzelm@62175
   165
subsection \<open>Monadic unit and plus\<close>
huffman@25904
   166
huffman@25904
   167
definition
huffman@25904
   168
  convex_unit :: "'a \<rightarrow> 'a convex_pd" where
huffman@41394
   169
  "convex_unit = compact_basis.extension (\<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@41394
   173
  "convex_plus = convex_pd.extension (\<lambda>t. convex_pd.extension (\<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@41399
   178
    (infixl "\<union>\<natural>" 65) where
huffman@41399
   179
  "xs \<union>\<natural> ys == convex_plus\<cdot>xs\<cdot>ys"
huffman@25904
   180
huffman@26927
   181
syntax
huffman@41479
   182
  "_convex_pd" :: "args \<Rightarrow> logic" ("{_}\<natural>")
huffman@26927
   183
huffman@26927
   184
translations
huffman@41399
   185
  "{x,xs}\<natural>" == "{x}\<natural> \<union>\<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@41394
   191
by (simp add: compact_basis.extension_principal PDUnit_convex_mono)
huffman@26927
   192
huffman@25904
   193
lemma convex_plus_principal [simp]:
huffman@41399
   194
  "convex_principal t \<union>\<natural> convex_principal u = convex_principal (PDPlus t u)"
huffman@25904
   195
unfolding convex_plus_def
huffman@41394
   196
by (simp add: convex_pd.extension_principal
huffman@41394
   197
    convex_pd.extension_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"
huffman@41399
   201
  show "(xs \<union>\<natural> ys) \<union>\<natural> zs = xs \<union>\<natural> (ys \<union>\<natural> zs)"
huffman@41402
   202
    apply (induct xs rule: convex_pd.principal_induct, simp)
huffman@41402
   203
    apply (induct ys rule: convex_pd.principal_induct, simp)
huffman@41402
   204
    apply (induct zs rule: convex_pd.principal_induct, simp)
haftmann@34973
   205
    apply (simp add: PDPlus_assoc)
haftmann@34973
   206
    done
huffman@41399
   207
  show "xs \<union>\<natural> ys = ys \<union>\<natural> xs"
huffman@41402
   208
    apply (induct xs rule: convex_pd.principal_induct, simp)
huffman@41402
   209
    apply (induct ys rule: convex_pd.principal_induct, simp)
haftmann@34973
   210
    apply (simp add: PDPlus_commute)
haftmann@34973
   211
    done
huffman@41399
   212
  show "xs \<union>\<natural> xs = xs"
haftmann@34973
   213
    apply (induct xs rule: convex_pd.principal_induct, simp)
haftmann@34973
   214
    apply (simp add: PDPlus_absorb)
haftmann@34973
   215
    done
haftmann@34973
   216
qed
huffman@26927
   217
haftmann@34973
   218
lemmas convex_plus_assoc = convex_add.assoc
haftmann@34973
   219
lemmas convex_plus_commute = convex_add.commute
haftmann@34973
   220
lemmas convex_plus_absorb = convex_add.idem
haftmann@34973
   221
lemmas convex_plus_left_commute = convex_add.left_commute
haftmann@34973
   222
lemmas convex_plus_left_absorb = convex_add.left_idem
huffman@26927
   223
wenzelm@62175
   224
text \<open>Useful for \<open>simp add: convex_plus_ac\<close>\<close>
huffman@29990
   225
lemmas convex_plus_ac =
huffman@29990
   226
  convex_plus_assoc convex_plus_commute convex_plus_left_commute
huffman@29990
   227
wenzelm@62175
   228
text \<open>Useful for \<open>simp only: convex_plus_aci\<close>\<close>
huffman@29990
   229
lemmas convex_plus_aci =
huffman@29990
   230
  convex_plus_ac convex_plus_absorb convex_plus_left_absorb
huffman@29990
   231
huffman@31076
   232
lemma convex_unit_below_plus_iff [simp]:
huffman@41399
   233
  "{x}\<natural> \<sqsubseteq> ys \<union>\<natural> zs \<longleftrightarrow> {x}\<natural> \<sqsubseteq> ys \<and> {x}\<natural> \<sqsubseteq> zs"
brianh@39970
   234
apply (induct x rule: compact_basis.principal_induct, simp)
brianh@39970
   235
apply (induct ys rule: convex_pd.principal_induct, simp)
brianh@39970
   236
apply (induct zs rule: convex_pd.principal_induct, simp)
brianh@39970
   237
apply simp
huffman@25904
   238
done
huffman@25904
   239
huffman@31076
   240
lemma convex_plus_below_unit_iff [simp]:
huffman@41399
   241
  "xs \<union>\<natural> ys \<sqsubseteq> {z}\<natural> \<longleftrightarrow> xs \<sqsubseteq> {z}\<natural> \<and> ys \<sqsubseteq> {z}\<natural>"
brianh@39970
   242
apply (induct xs rule: convex_pd.principal_induct, simp)
brianh@39970
   243
apply (induct ys rule: convex_pd.principal_induct, simp)
brianh@39970
   244
apply (induct z rule: compact_basis.principal_induct, simp)
brianh@39970
   245
apply simp
huffman@25904
   246
done
huffman@25904
   247
huffman@31076
   248
lemma convex_unit_below_iff [simp]: "{x}\<natural> \<sqsubseteq> {y}\<natural> \<longleftrightarrow> x \<sqsubseteq> y"
brianh@39970
   249
apply (induct x rule: compact_basis.principal_induct, simp)
brianh@39970
   250
apply (induct y rule: compact_basis.principal_induct, simp)
brianh@39970
   251
apply simp
huffman@26927
   252
done
huffman@26927
   253
huffman@26927
   254
lemma convex_unit_eq_iff [simp]: "{x}\<natural> = {y}\<natural> \<longleftrightarrow> x = y"
huffman@26927
   255
unfolding po_eq_conv by simp
huffman@26927
   256
huffman@26927
   257
lemma convex_unit_strict [simp]: "{\<bottom>}\<natural> = \<bottom>"
huffman@39974
   258
using convex_unit_Rep_compact_basis [of compact_bot]
huffman@39974
   259
by (simp add: inst_convex_pd_pcpo)
huffman@26927
   260
huffman@40321
   261
lemma convex_unit_bottom_iff [simp]: "{x}\<natural> = \<bottom> \<longleftrightarrow> x = \<bottom>"
huffman@26927
   262
unfolding convex_unit_strict [symmetric] by (rule convex_unit_eq_iff)
huffman@26927
   263
huffman@39974
   264
lemma compact_convex_unit: "compact x \<Longrightarrow> compact {x}\<natural>"
huffman@39974
   265
by (auto dest!: compact_basis.compact_imp_principal)
huffman@39974
   266
huffman@39974
   267
lemma compact_convex_unit_iff [simp]: "compact {x}\<natural> \<longleftrightarrow> compact x"
huffman@39974
   268
apply (safe elim!: compact_convex_unit)
huffman@39974
   269
apply (simp only: compact_def convex_unit_below_iff [symmetric])
huffman@40327
   270
apply (erule adm_subst [OF cont_Rep_cfun2])
huffman@39974
   271
done
huffman@26927
   272
huffman@26927
   273
lemma compact_convex_plus [simp]:
huffman@41399
   274
  "\<lbrakk>compact xs; compact ys\<rbrakk> \<Longrightarrow> compact (xs \<union>\<natural> ys)"
huffman@27289
   275
by (auto dest!: convex_pd.compact_imp_principal)
huffman@26927
   276
huffman@25904
   277
wenzelm@62175
   278
subsection \<open>Induction rules\<close>
huffman@25904
   279
huffman@25904
   280
lemma convex_pd_induct1:
huffman@25904
   281
  assumes P: "adm P"
huffman@26927
   282
  assumes unit: "\<And>x. P {x}\<natural>"
huffman@41399
   283
  assumes insert: "\<And>x ys. \<lbrakk>P {x}\<natural>; P ys\<rbrakk> \<Longrightarrow> P ({x}\<natural> \<union>\<natural> ys)"
huffman@25904
   284
  shows "P (xs::'a convex_pd)"
huffman@27289
   285
apply (induct xs rule: convex_pd.principal_induct, rule P)
huffman@27289
   286
apply (induct_tac a rule: pd_basis_induct1)
huffman@25904
   287
apply (simp only: convex_unit_Rep_compact_basis [symmetric])
huffman@25904
   288
apply (rule unit)
huffman@25904
   289
apply (simp only: convex_unit_Rep_compact_basis [symmetric]
huffman@25904
   290
                  convex_plus_principal [symmetric])
huffman@25904
   291
apply (erule insert [OF unit])
huffman@25904
   292
done
huffman@25904
   293
huffman@40576
   294
lemma convex_pd_induct
huffman@40576
   295
  [case_names adm convex_unit convex_plus, induct type: convex_pd]:
huffman@25904
   296
  assumes P: "adm P"
huffman@26927
   297
  assumes unit: "\<And>x. P {x}\<natural>"
huffman@41399
   298
  assumes plus: "\<And>xs ys. \<lbrakk>P xs; P ys\<rbrakk> \<Longrightarrow> P (xs \<union>\<natural> ys)"
huffman@25904
   299
  shows "P (xs::'a convex_pd)"
huffman@27289
   300
apply (induct xs rule: convex_pd.principal_induct, rule P)
huffman@27289
   301
apply (induct_tac a rule: pd_basis_induct)
huffman@25904
   302
apply (simp only: convex_unit_Rep_compact_basis [symmetric] unit)
huffman@25904
   303
apply (simp only: convex_plus_principal [symmetric] plus)
huffman@25904
   304
done
huffman@25904
   305
huffman@25904
   306
wenzelm@62175
   307
subsection \<open>Monadic bind\<close>
huffman@25904
   308
huffman@25904
   309
definition
huffman@25904
   310
  convex_bind_basis ::
huffman@25904
   311
  "'a pd_basis \<Rightarrow> ('a \<rightarrow> 'b convex_pd) \<rightarrow> 'b convex_pd" where
huffman@25904
   312
  "convex_bind_basis = fold_pd
huffman@25904
   313
    (\<lambda>a. \<Lambda> f. f\<cdot>(Rep_compact_basis a))
huffman@41399
   314
    (\<lambda>x y. \<Lambda> f. x\<cdot>f \<union>\<natural> y\<cdot>f)"
huffman@25904
   315
huffman@26927
   316
lemma ACI_convex_bind:
haftmann@51489
   317
  "semilattice (\<lambda>x y. \<Lambda> f. x\<cdot>f \<union>\<natural> y\<cdot>f)"
huffman@25904
   318
apply unfold_locales
haftmann@26041
   319
apply (simp add: convex_plus_assoc)
huffman@25904
   320
apply (simp add: convex_plus_commute)
huffman@29990
   321
apply (simp add: eta_cfun)
huffman@25904
   322
done
huffman@25904
   323
huffman@25904
   324
lemma convex_bind_basis_simps [simp]:
huffman@25904
   325
  "convex_bind_basis (PDUnit a) =
huffman@25904
   326
    (\<Lambda> f. f\<cdot>(Rep_compact_basis a))"
huffman@25904
   327
  "convex_bind_basis (PDPlus t u) =
huffman@41399
   328
    (\<Lambda> f. convex_bind_basis t\<cdot>f \<union>\<natural> convex_bind_basis u\<cdot>f)"
huffman@25904
   329
unfolding convex_bind_basis_def
huffman@25904
   330
apply -
huffman@26927
   331
apply (rule fold_pd_PDUnit [OF ACI_convex_bind])
huffman@26927
   332
apply (rule fold_pd_PDPlus [OF ACI_convex_bind])
huffman@25904
   333
done
huffman@25904
   334
huffman@25904
   335
lemma convex_bind_basis_mono:
huffman@25904
   336
  "t \<le>\<natural> u \<Longrightarrow> convex_bind_basis t \<sqsubseteq> convex_bind_basis u"
huffman@25904
   337
apply (erule convex_le_induct)
huffman@31076
   338
apply (erule (1) below_trans)
huffman@27289
   339
apply (simp add: monofun_LAM monofun_cfun)
huffman@27289
   340
apply (simp add: monofun_LAM monofun_cfun)
huffman@25904
   341
done
huffman@25904
   342
huffman@25904
   343
definition
huffman@25904
   344
  convex_bind :: "'a convex_pd \<rightarrow> ('a \<rightarrow> 'b convex_pd) \<rightarrow> 'b convex_pd" where
huffman@41394
   345
  "convex_bind = convex_pd.extension convex_bind_basis"
huffman@25904
   346
huffman@41036
   347
syntax
huffman@41036
   348
  "_convex_bind" :: "[logic, logic, logic] \<Rightarrow> logic"
huffman@41036
   349
    ("(3\<Union>\<natural>_\<in>_./ _)" [0, 0, 10] 10)
huffman@41036
   350
huffman@41036
   351
translations
huffman@41036
   352
  "\<Union>\<natural>x\<in>xs. e" == "CONST convex_bind\<cdot>xs\<cdot>(\<Lambda> x. e)"
huffman@41036
   353
huffman@25904
   354
lemma convex_bind_principal [simp]:
huffman@25904
   355
  "convex_bind\<cdot>(convex_principal t) = convex_bind_basis t"
huffman@25904
   356
unfolding convex_bind_def
huffman@41394
   357
apply (rule convex_pd.extension_principal)
huffman@25904
   358
apply (erule convex_bind_basis_mono)
huffman@25904
   359
done
huffman@25904
   360
huffman@25904
   361
lemma convex_bind_unit [simp]:
huffman@26927
   362
  "convex_bind\<cdot>{x}\<natural>\<cdot>f = f\<cdot>x"
huffman@27289
   363
by (induct x rule: compact_basis.principal_induct, simp, simp)
huffman@25904
   364
huffman@25904
   365
lemma convex_bind_plus [simp]:
huffman@41399
   366
  "convex_bind\<cdot>(xs \<union>\<natural> ys)\<cdot>f = convex_bind\<cdot>xs\<cdot>f \<union>\<natural> convex_bind\<cdot>ys\<cdot>f"
huffman@41402
   367
by (induct xs rule: convex_pd.principal_induct, simp,
huffman@41402
   368
    induct ys rule: convex_pd.principal_induct, simp, simp)
huffman@25904
   369
huffman@25904
   370
lemma convex_bind_strict [simp]: "convex_bind\<cdot>\<bottom>\<cdot>f = f\<cdot>\<bottom>"
huffman@25904
   371
unfolding convex_unit_strict [symmetric] by (rule convex_bind_unit)
huffman@25904
   372
huffman@40589
   373
lemma convex_bind_bind:
huffman@40589
   374
  "convex_bind\<cdot>(convex_bind\<cdot>xs\<cdot>f)\<cdot>g =
huffman@40589
   375
    convex_bind\<cdot>xs\<cdot>(\<Lambda> x. convex_bind\<cdot>(f\<cdot>x)\<cdot>g)"
huffman@40589
   376
by (induct xs, simp_all)
huffman@40589
   377
huffman@25904
   378
wenzelm@62175
   379
subsection \<open>Map\<close>
huffman@25904
   380
huffman@25904
   381
definition
huffman@25904
   382
  convex_map :: "('a \<rightarrow> 'b) \<rightarrow> 'a convex_pd \<rightarrow> 'b convex_pd" where
huffman@26927
   383
  "convex_map = (\<Lambda> f xs. convex_bind\<cdot>xs\<cdot>(\<Lambda> x. {f\<cdot>x}\<natural>))"
huffman@25904
   384
huffman@25904
   385
lemma convex_map_unit [simp]:
huffman@39974
   386
  "convex_map\<cdot>f\<cdot>{x}\<natural> = {f\<cdot>x}\<natural>"
huffman@25904
   387
unfolding convex_map_def by simp
huffman@25904
   388
huffman@25904
   389
lemma convex_map_plus [simp]:
huffman@41399
   390
  "convex_map\<cdot>f\<cdot>(xs \<union>\<natural> ys) = convex_map\<cdot>f\<cdot>xs \<union>\<natural> convex_map\<cdot>f\<cdot>ys"
huffman@25904
   391
unfolding convex_map_def by simp
huffman@25904
   392
huffman@40577
   393
lemma convex_map_bottom [simp]: "convex_map\<cdot>f\<cdot>\<bottom> = {f\<cdot>\<bottom>}\<natural>"
huffman@40577
   394
unfolding convex_map_def by simp
huffman@40577
   395
huffman@25904
   396
lemma convex_map_ident: "convex_map\<cdot>(\<Lambda> x. x)\<cdot>xs = xs"
huffman@25904
   397
by (induct xs rule: convex_pd_induct, simp_all)
huffman@25904
   398
huffman@33808
   399
lemma convex_map_ID: "convex_map\<cdot>ID = ID"
huffman@40002
   400
by (simp add: cfun_eq_iff ID_def convex_map_ident)
huffman@33808
   401
huffman@25904
   402
lemma convex_map_map:
huffman@25904
   403
  "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
   404
by (induct xs rule: convex_pd_induct, simp_all)
huffman@25904
   405
huffman@41110
   406
lemma convex_bind_map:
huffman@41110
   407
  "convex_bind\<cdot>(convex_map\<cdot>f\<cdot>xs)\<cdot>g = convex_bind\<cdot>xs\<cdot>(\<Lambda> x. g\<cdot>(f\<cdot>x))"
huffman@41110
   408
by (simp add: convex_map_def convex_bind_bind)
huffman@41110
   409
huffman@41110
   410
lemma convex_map_bind:
huffman@41110
   411
  "convex_map\<cdot>f\<cdot>(convex_bind\<cdot>xs\<cdot>g) = convex_bind\<cdot>xs\<cdot>(\<Lambda> x. convex_map\<cdot>f\<cdot>(g\<cdot>x))"
huffman@41110
   412
by (simp add: convex_map_def convex_bind_bind)
huffman@41110
   413
huffman@39974
   414
lemma ep_pair_convex_map: "ep_pair e p \<Longrightarrow> ep_pair (convex_map\<cdot>e) (convex_map\<cdot>p)"
wenzelm@61169
   415
apply standard
huffman@39974
   416
apply (induct_tac x rule: convex_pd_induct, simp_all add: ep_pair.e_inverse)
huffman@39974
   417
apply (induct_tac y rule: convex_pd_induct)
huffman@39974
   418
apply (simp_all add: ep_pair.e_p_below monofun_cfun)
huffman@39974
   419
done
huffman@39974
   420
huffman@39974
   421
lemma deflation_convex_map: "deflation d \<Longrightarrow> deflation (convex_map\<cdot>d)"
wenzelm@61169
   422
apply standard
huffman@39974
   423
apply (induct_tac x rule: convex_pd_induct, simp_all add: deflation.idem)
huffman@39974
   424
apply (induct_tac x rule: convex_pd_induct)
huffman@39974
   425
apply (simp_all add: deflation.below monofun_cfun)
huffman@39974
   426
done
huffman@39974
   427
huffman@39974
   428
(* FIXME: long proof! *)
huffman@39974
   429
lemma finite_deflation_convex_map:
huffman@39974
   430
  assumes "finite_deflation d" shows "finite_deflation (convex_map\<cdot>d)"
huffman@39974
   431
proof (rule finite_deflation_intro)
huffman@39974
   432
  interpret d: finite_deflation d by fact
huffman@39974
   433
  have "deflation d" by fact
huffman@39974
   434
  thus "deflation (convex_map\<cdot>d)" by (rule deflation_convex_map)
huffman@39974
   435
  have "finite (range (\<lambda>x. d\<cdot>x))" by (rule d.finite_range)
huffman@39974
   436
  hence "finite (Rep_compact_basis -` range (\<lambda>x. d\<cdot>x))"
huffman@39974
   437
    by (rule finite_vimageI, simp add: inj_on_def Rep_compact_basis_inject)
huffman@39974
   438
  hence "finite (Pow (Rep_compact_basis -` range (\<lambda>x. d\<cdot>x)))" by simp
huffman@39974
   439
  hence "finite (Rep_pd_basis -` (Pow (Rep_compact_basis -` range (\<lambda>x. d\<cdot>x))))"
huffman@39974
   440
    by (rule finite_vimageI, simp add: inj_on_def Rep_pd_basis_inject)
huffman@39974
   441
  hence *: "finite (convex_principal ` Rep_pd_basis -` (Pow (Rep_compact_basis -` range (\<lambda>x. d\<cdot>x))))" by simp
huffman@39974
   442
  hence "finite (range (\<lambda>xs. convex_map\<cdot>d\<cdot>xs))"
huffman@39974
   443
    apply (rule rev_finite_subset)
huffman@39974
   444
    apply clarsimp
huffman@39974
   445
    apply (induct_tac xs rule: convex_pd.principal_induct)
huffman@39974
   446
    apply (simp add: adm_mem_finite *)
huffman@39974
   447
    apply (rename_tac t, induct_tac t rule: pd_basis_induct)
huffman@39974
   448
    apply (simp only: convex_unit_Rep_compact_basis [symmetric] convex_map_unit)
huffman@39974
   449
    apply simp
huffman@39974
   450
    apply (subgoal_tac "\<exists>b. d\<cdot>(Rep_compact_basis a) = Rep_compact_basis b")
huffman@39974
   451
    apply clarsimp
huffman@39974
   452
    apply (rule imageI)
huffman@39974
   453
    apply (rule vimageI2)
huffman@39974
   454
    apply (simp add: Rep_PDUnit)
huffman@39974
   455
    apply (rule range_eqI)
huffman@39974
   456
    apply (erule sym)
huffman@39974
   457
    apply (rule exI)
huffman@39974
   458
    apply (rule Abs_compact_basis_inverse [symmetric])
huffman@39974
   459
    apply (simp add: d.compact)
huffman@39974
   460
    apply (simp only: convex_plus_principal [symmetric] convex_map_plus)
huffman@39974
   461
    apply clarsimp
huffman@39974
   462
    apply (rule imageI)
huffman@39974
   463
    apply (rule vimageI2)
huffman@39974
   464
    apply (simp add: Rep_PDPlus)
huffman@39974
   465
    done
huffman@39974
   466
  thus "finite {xs. convex_map\<cdot>d\<cdot>xs = xs}"
huffman@39974
   467
    by (rule finite_range_imp_finite_fixes)
huffman@39974
   468
qed
huffman@39974
   469
wenzelm@62175
   470
subsection \<open>Convex powerdomain is bifinite\<close>
huffman@39974
   471
huffman@41286
   472
lemma approx_chain_convex_map:
huffman@41286
   473
  assumes "approx_chain a"
huffman@41286
   474
  shows "approx_chain (\<lambda>i. convex_map\<cdot>(a i))"
huffman@41286
   475
  using assms unfolding approx_chain_def
huffman@41286
   476
  by (simp add: lub_APP convex_map_ID finite_deflation_convex_map)
huffman@41286
   477
huffman@41288
   478
instance convex_pd :: (bifinite) bifinite
huffman@41286
   479
proof
huffman@41286
   480
  show "\<exists>(a::nat \<Rightarrow> 'a convex_pd \<rightarrow> 'a convex_pd). approx_chain a"
huffman@41286
   481
    using bifinite [where 'a='a]
huffman@41286
   482
    by (fast intro!: approx_chain_convex_map)
huffman@41286
   483
qed
huffman@41286
   484
wenzelm@62175
   485
subsection \<open>Join\<close>
huffman@39974
   486
huffman@39974
   487
definition
huffman@39974
   488
  convex_join :: "'a convex_pd convex_pd \<rightarrow> 'a convex_pd" where
huffman@39974
   489
  "convex_join = (\<Lambda> xss. convex_bind\<cdot>xss\<cdot>(\<Lambda> xs. xs))"
huffman@39974
   490
huffman@39974
   491
lemma convex_join_unit [simp]:
huffman@39974
   492
  "convex_join\<cdot>{xs}\<natural> = xs"
huffman@39974
   493
unfolding convex_join_def by simp
huffman@39974
   494
huffman@39974
   495
lemma convex_join_plus [simp]:
huffman@41399
   496
  "convex_join\<cdot>(xss \<union>\<natural> yss) = convex_join\<cdot>xss \<union>\<natural> convex_join\<cdot>yss"
huffman@39974
   497
unfolding convex_join_def by simp
huffman@39974
   498
huffman@40577
   499
lemma convex_join_bottom [simp]: "convex_join\<cdot>\<bottom> = \<bottom>"
huffman@40577
   500
unfolding convex_join_def by simp
huffman@40577
   501
huffman@25904
   502
lemma convex_join_map_unit:
huffman@25904
   503
  "convex_join\<cdot>(convex_map\<cdot>convex_unit\<cdot>xs) = xs"
huffman@25904
   504
by (induct xs rule: convex_pd_induct, simp_all)
huffman@25904
   505
huffman@25904
   506
lemma convex_join_map_join:
huffman@25904
   507
  "convex_join\<cdot>(convex_map\<cdot>convex_join\<cdot>xsss) = convex_join\<cdot>(convex_join\<cdot>xsss)"
huffman@25904
   508
by (induct xsss rule: convex_pd_induct, simp_all)
huffman@25904
   509
huffman@25904
   510
lemma convex_join_map_map:
huffman@25904
   511
  "convex_join\<cdot>(convex_map\<cdot>(convex_map\<cdot>f)\<cdot>xss) =
huffman@25904
   512
   convex_map\<cdot>f\<cdot>(convex_join\<cdot>xss)"
huffman@25904
   513
by (induct xss rule: convex_pd_induct, simp_all)
huffman@25904
   514
huffman@25904
   515
wenzelm@62175
   516
subsection \<open>Conversions to other powerdomains\<close>
huffman@25904
   517
wenzelm@62175
   518
text \<open>Convex to upper\<close>
huffman@25904
   519
huffman@25904
   520
lemma convex_le_imp_upper_le: "t \<le>\<natural> u \<Longrightarrow> t \<le>\<sharp> u"
huffman@25904
   521
unfolding convex_le_def by simp
huffman@25904
   522
huffman@25904
   523
definition
huffman@25904
   524
  convex_to_upper :: "'a convex_pd \<rightarrow> 'a upper_pd" where
huffman@41394
   525
  "convex_to_upper = convex_pd.extension upper_principal"
huffman@25904
   526
huffman@25904
   527
lemma convex_to_upper_principal [simp]:
huffman@25904
   528
  "convex_to_upper\<cdot>(convex_principal t) = upper_principal t"
huffman@25904
   529
unfolding convex_to_upper_def
huffman@41394
   530
apply (rule convex_pd.extension_principal)
huffman@27289
   531
apply (rule upper_pd.principal_mono)
huffman@25904
   532
apply (erule convex_le_imp_upper_le)
huffman@25904
   533
done
huffman@25904
   534
huffman@25904
   535
lemma convex_to_upper_unit [simp]:
huffman@26927
   536
  "convex_to_upper\<cdot>{x}\<natural> = {x}\<sharp>"
huffman@27289
   537
by (induct x rule: compact_basis.principal_induct, simp, simp)
huffman@25904
   538
huffman@25904
   539
lemma convex_to_upper_plus [simp]:
huffman@41399
   540
  "convex_to_upper\<cdot>(xs \<union>\<natural> ys) = convex_to_upper\<cdot>xs \<union>\<sharp> convex_to_upper\<cdot>ys"
huffman@41402
   541
by (induct xs rule: convex_pd.principal_induct, simp,
huffman@41402
   542
    induct ys rule: convex_pd.principal_induct, simp, simp)
huffman@25904
   543
huffman@27289
   544
lemma convex_to_upper_bind [simp]:
huffman@27289
   545
  "convex_to_upper\<cdot>(convex_bind\<cdot>xs\<cdot>f) =
huffman@27289
   546
    upper_bind\<cdot>(convex_to_upper\<cdot>xs)\<cdot>(convex_to_upper oo f)"
huffman@27289
   547
by (induct xs rule: convex_pd_induct, simp, simp, simp)
huffman@27289
   548
huffman@27289
   549
lemma convex_to_upper_map [simp]:
huffman@27289
   550
  "convex_to_upper\<cdot>(convex_map\<cdot>f\<cdot>xs) = upper_map\<cdot>f\<cdot>(convex_to_upper\<cdot>xs)"
huffman@27289
   551
by (simp add: convex_map_def upper_map_def cfcomp_LAM)
huffman@27289
   552
huffman@27289
   553
lemma convex_to_upper_join [simp]:
huffman@27289
   554
  "convex_to_upper\<cdot>(convex_join\<cdot>xss) =
huffman@27289
   555
    upper_bind\<cdot>(convex_to_upper\<cdot>xss)\<cdot>convex_to_upper"
huffman@27289
   556
by (simp add: convex_join_def upper_join_def cfcomp_LAM eta_cfun)
huffman@27289
   557
wenzelm@62175
   558
text \<open>Convex to lower\<close>
huffman@25904
   559
huffman@25904
   560
lemma convex_le_imp_lower_le: "t \<le>\<natural> u \<Longrightarrow> t \<le>\<flat> u"
huffman@25904
   561
unfolding convex_le_def by simp
huffman@25904
   562
huffman@25904
   563
definition
huffman@25904
   564
  convex_to_lower :: "'a convex_pd \<rightarrow> 'a lower_pd" where
huffman@41394
   565
  "convex_to_lower = convex_pd.extension lower_principal"
huffman@25904
   566
huffman@25904
   567
lemma convex_to_lower_principal [simp]:
huffman@25904
   568
  "convex_to_lower\<cdot>(convex_principal t) = lower_principal t"
huffman@25904
   569
unfolding convex_to_lower_def
huffman@41394
   570
apply (rule convex_pd.extension_principal)
huffman@27289
   571
apply (rule lower_pd.principal_mono)
huffman@25904
   572
apply (erule convex_le_imp_lower_le)
huffman@25904
   573
done
huffman@25904
   574
huffman@25904
   575
lemma convex_to_lower_unit [simp]:
huffman@26927
   576
  "convex_to_lower\<cdot>{x}\<natural> = {x}\<flat>"
huffman@27289
   577
by (induct x rule: compact_basis.principal_induct, simp, simp)
huffman@25904
   578
huffman@25904
   579
lemma convex_to_lower_plus [simp]:
huffman@41399
   580
  "convex_to_lower\<cdot>(xs \<union>\<natural> ys) = convex_to_lower\<cdot>xs \<union>\<flat> convex_to_lower\<cdot>ys"
huffman@41402
   581
by (induct xs rule: convex_pd.principal_induct, simp,
huffman@41402
   582
    induct ys rule: convex_pd.principal_induct, simp, simp)
huffman@25904
   583
huffman@27289
   584
lemma convex_to_lower_bind [simp]:
huffman@27289
   585
  "convex_to_lower\<cdot>(convex_bind\<cdot>xs\<cdot>f) =
huffman@27289
   586
    lower_bind\<cdot>(convex_to_lower\<cdot>xs)\<cdot>(convex_to_lower oo f)"
huffman@27289
   587
by (induct xs rule: convex_pd_induct, simp, simp, simp)
huffman@27289
   588
huffman@27289
   589
lemma convex_to_lower_map [simp]:
huffman@27289
   590
  "convex_to_lower\<cdot>(convex_map\<cdot>f\<cdot>xs) = lower_map\<cdot>f\<cdot>(convex_to_lower\<cdot>xs)"
huffman@27289
   591
by (simp add: convex_map_def lower_map_def cfcomp_LAM)
huffman@27289
   592
huffman@27289
   593
lemma convex_to_lower_join [simp]:
huffman@27289
   594
  "convex_to_lower\<cdot>(convex_join\<cdot>xss) =
huffman@27289
   595
    lower_bind\<cdot>(convex_to_lower\<cdot>xss)\<cdot>convex_to_lower"
huffman@27289
   596
by (simp add: convex_join_def lower_join_def cfcomp_LAM eta_cfun)
huffman@27289
   597
wenzelm@62175
   598
text \<open>Ordering property\<close>
huffman@25904
   599
huffman@31076
   600
lemma convex_pd_below_iff:
huffman@25904
   601
  "(xs \<sqsubseteq> ys) =
huffman@25904
   602
    (convex_to_upper\<cdot>xs \<sqsubseteq> convex_to_upper\<cdot>ys \<and>
huffman@25904
   603
     convex_to_lower\<cdot>xs \<sqsubseteq> convex_to_lower\<cdot>ys)"
brianh@39970
   604
apply (induct xs rule: convex_pd.principal_induct, simp)
brianh@39970
   605
apply (induct ys rule: convex_pd.principal_induct, simp)
brianh@39970
   606
apply (simp add: convex_le_def)
huffman@25904
   607
done
huffman@25904
   608
huffman@31076
   609
lemmas convex_plus_below_plus_iff =
wenzelm@45606
   610
  convex_pd_below_iff [where xs="xs \<union>\<natural> ys" and ys="zs \<union>\<natural> ws"]
wenzelm@45606
   611
  for xs ys zs ws
huffman@26927
   612
huffman@31076
   613
lemmas convex_pd_below_simps =
huffman@31076
   614
  convex_unit_below_plus_iff
huffman@31076
   615
  convex_plus_below_unit_iff
huffman@31076
   616
  convex_plus_below_plus_iff
huffman@31076
   617
  convex_unit_below_iff
huffman@26927
   618
  convex_to_upper_unit
huffman@26927
   619
  convex_to_upper_plus
huffman@26927
   620
  convex_to_lower_unit
huffman@26927
   621
  convex_to_lower_plus
huffman@31076
   622
  upper_pd_below_simps
huffman@31076
   623
  lower_pd_below_simps
huffman@26927
   624
huffman@25904
   625
end