src/HOL/HOLCF/UpperPD.thy
author huffman
Sun Dec 19 05:15:31 2010 -0800 (2010-12-19)
changeset 41286 3d7685a4a5ff
parent 41284 6d66975b711f
child 41287 029a6fc1bfb8
permissions -rw-r--r--
reintroduce 'bifinite' class, now with existentially-quantified approx function (cf. b525988432e9)
huffman@25904
     1
(*  Title:      HOLCF/UpperPD.thy
huffman@25904
     2
    Author:     Brian Huffman
huffman@25904
     3
*)
huffman@25904
     4
huffman@25904
     5
header {* Upper powerdomain *}
huffman@25904
     6
huffman@25904
     7
theory UpperPD
huffman@41284
     8
imports Compact_Basis
huffman@25904
     9
begin
huffman@25904
    10
huffman@25904
    11
subsection {* Basis preorder *}
huffman@25904
    12
huffman@25904
    13
definition
huffman@25904
    14
  upper_le :: "'a pd_basis \<Rightarrow> 'a pd_basis \<Rightarrow> bool" (infix "\<le>\<sharp>" 50) where
huffman@26420
    15
  "upper_le = (\<lambda>u v. \<forall>y\<in>Rep_pd_basis v. \<exists>x\<in>Rep_pd_basis u. x \<sqsubseteq> y)"
huffman@25904
    16
huffman@25904
    17
lemma upper_le_refl [simp]: "t \<le>\<sharp> t"
huffman@26420
    18
unfolding upper_le_def by fast
huffman@25904
    19
huffman@25904
    20
lemma upper_le_trans: "\<lbrakk>t \<le>\<sharp> u; u \<le>\<sharp> v\<rbrakk> \<Longrightarrow> t \<le>\<sharp> v"
huffman@25904
    21
unfolding upper_le_def
huffman@25904
    22
apply (rule ballI)
huffman@25904
    23
apply (drule (1) bspec, erule bexE)
huffman@25904
    24
apply (drule (1) bspec, erule bexE)
huffman@25904
    25
apply (erule rev_bexI)
huffman@31076
    26
apply (erule (1) below_trans)
huffman@25904
    27
done
huffman@25904
    28
wenzelm@30729
    29
interpretation upper_le: preorder upper_le
huffman@25904
    30
by (rule preorder.intro, rule upper_le_refl, rule upper_le_trans)
huffman@25904
    31
huffman@25904
    32
lemma upper_le_minimal [simp]: "PDUnit compact_bot \<le>\<sharp> t"
huffman@25904
    33
unfolding upper_le_def Rep_PDUnit by simp
huffman@25904
    34
huffman@26420
    35
lemma PDUnit_upper_mono: "x \<sqsubseteq> y \<Longrightarrow> PDUnit x \<le>\<sharp> PDUnit y"
huffman@25904
    36
unfolding upper_le_def Rep_PDUnit by simp
huffman@25904
    37
huffman@25904
    38
lemma PDPlus_upper_mono: "\<lbrakk>s \<le>\<sharp> t; u \<le>\<sharp> v\<rbrakk> \<Longrightarrow> PDPlus s u \<le>\<sharp> PDPlus t v"
huffman@25904
    39
unfolding upper_le_def Rep_PDPlus by fast
huffman@25904
    40
huffman@31076
    41
lemma PDPlus_upper_le: "PDPlus t u \<le>\<sharp> t"
huffman@26420
    42
unfolding upper_le_def Rep_PDPlus by fast
huffman@25904
    43
huffman@25904
    44
lemma upper_le_PDUnit_PDUnit_iff [simp]:
huffman@40436
    45
  "(PDUnit a \<le>\<sharp> PDUnit b) = (a \<sqsubseteq> b)"
huffman@25904
    46
unfolding upper_le_def Rep_PDUnit by fast
huffman@25904
    47
huffman@25904
    48
lemma upper_le_PDPlus_PDUnit_iff:
huffman@25904
    49
  "(PDPlus t u \<le>\<sharp> PDUnit a) = (t \<le>\<sharp> PDUnit a \<or> u \<le>\<sharp> PDUnit a)"
huffman@25904
    50
unfolding upper_le_def Rep_PDPlus Rep_PDUnit by fast
huffman@25904
    51
huffman@25904
    52
lemma upper_le_PDPlus_iff: "(t \<le>\<sharp> PDPlus u v) = (t \<le>\<sharp> u \<and> t \<le>\<sharp> v)"
huffman@25904
    53
unfolding upper_le_def Rep_PDPlus by fast
huffman@25904
    54
huffman@25904
    55
lemma upper_le_induct [induct set: upper_le]:
huffman@25904
    56
  assumes le: "t \<le>\<sharp> u"
huffman@26420
    57
  assumes 1: "\<And>a b. a \<sqsubseteq> b \<Longrightarrow> P (PDUnit a) (PDUnit b)"
huffman@25904
    58
  assumes 2: "\<And>t u a. P t (PDUnit a) \<Longrightarrow> P (PDPlus t u) (PDUnit a)"
huffman@25904
    59
  assumes 3: "\<And>t u v. \<lbrakk>P t u; P t v\<rbrakk> \<Longrightarrow> P t (PDPlus u v)"
huffman@25904
    60
  shows "P t u"
huffman@25904
    61
using le apply (induct u arbitrary: t rule: pd_basis_induct)
huffman@25904
    62
apply (erule rev_mp)
huffman@25904
    63
apply (induct_tac t rule: pd_basis_induct)
huffman@25904
    64
apply (simp add: 1)
huffman@25904
    65
apply (simp add: upper_le_PDPlus_PDUnit_iff)
huffman@25904
    66
apply (simp add: 2)
huffman@25904
    67
apply (subst PDPlus_commute)
huffman@25904
    68
apply (simp add: 2)
huffman@25904
    69
apply (simp add: upper_le_PDPlus_iff 3)
huffman@25904
    70
done
huffman@25904
    71
huffman@25904
    72
huffman@25904
    73
subsection {* Type definition *}
huffman@25904
    74
huffman@27373
    75
typedef (open) 'a upper_pd =
huffman@27373
    76
  "{S::'a pd_basis set. upper_le.ideal S}"
huffman@40888
    77
by (rule upper_le.ex_ideal)
huffman@27373
    78
huffman@41111
    79
type_notation (xsymbols) upper_pd ("('(_')\<sharp>)")
huffman@41111
    80
huffman@40497
    81
instantiation upper_pd :: ("domain") below
huffman@27373
    82
begin
huffman@27373
    83
huffman@27373
    84
definition
huffman@27373
    85
  "x \<sqsubseteq> y \<longleftrightarrow> Rep_upper_pd x \<subseteq> Rep_upper_pd y"
huffman@27373
    86
huffman@27373
    87
instance ..
huffman@27373
    88
end
huffman@25904
    89
huffman@40497
    90
instance upper_pd :: ("domain") po
huffman@39974
    91
using type_definition_upper_pd below_upper_pd_def
huffman@39974
    92
by (rule upper_le.typedef_ideal_po)
huffman@27373
    93
huffman@40497
    94
instance upper_pd :: ("domain") cpo
huffman@39974
    95
using type_definition_upper_pd below_upper_pd_def
huffman@39974
    96
by (rule upper_le.typedef_ideal_cpo)
huffman@27373
    97
huffman@25904
    98
definition
huffman@25904
    99
  upper_principal :: "'a pd_basis \<Rightarrow> 'a upper_pd" where
huffman@27373
   100
  "upper_principal t = Abs_upper_pd {u. u \<le>\<sharp> t}"
huffman@25904
   101
wenzelm@30729
   102
interpretation upper_pd:
huffman@39974
   103
  ideal_completion upper_le upper_principal Rep_upper_pd
huffman@39984
   104
using type_definition_upper_pd below_upper_pd_def
huffman@39984
   105
using upper_principal_def pd_basis_countable
huffman@39984
   106
by (rule upper_le.typedef_ideal_completion)
huffman@25904
   107
huffman@27289
   108
text {* Upper powerdomain is pointed *}
huffman@25904
   109
huffman@25904
   110
lemma upper_pd_minimal: "upper_principal (PDUnit compact_bot) \<sqsubseteq> ys"
huffman@25904
   111
by (induct ys rule: upper_pd.principal_induct, simp, simp)
huffman@25904
   112
huffman@40497
   113
instance upper_pd :: ("domain") pcpo
huffman@26927
   114
by intro_classes (fast intro: upper_pd_minimal)
huffman@25904
   115
huffman@25904
   116
lemma inst_upper_pd_pcpo: "\<bottom> = upper_principal (PDUnit compact_bot)"
huffman@25904
   117
by (rule upper_pd_minimal [THEN UU_I, symmetric])
huffman@25904
   118
huffman@25904
   119
huffman@26927
   120
subsection {* Monadic unit and plus *}
huffman@25904
   121
huffman@25904
   122
definition
huffman@25904
   123
  upper_unit :: "'a \<rightarrow> 'a upper_pd" where
huffman@25904
   124
  "upper_unit = compact_basis.basis_fun (\<lambda>a. upper_principal (PDUnit a))"
huffman@25904
   125
huffman@25904
   126
definition
huffman@25904
   127
  upper_plus :: "'a upper_pd \<rightarrow> 'a upper_pd \<rightarrow> 'a upper_pd" where
huffman@25904
   128
  "upper_plus = upper_pd.basis_fun (\<lambda>t. upper_pd.basis_fun (\<lambda>u.
huffman@25904
   129
      upper_principal (PDPlus t u)))"
huffman@25904
   130
huffman@25904
   131
abbreviation
huffman@25904
   132
  upper_add :: "'a upper_pd \<Rightarrow> 'a upper_pd \<Rightarrow> 'a upper_pd"
huffman@25904
   133
    (infixl "+\<sharp>" 65) where
huffman@25904
   134
  "xs +\<sharp> ys == upper_plus\<cdot>xs\<cdot>ys"
huffman@25904
   135
huffman@26927
   136
syntax
huffman@26927
   137
  "_upper_pd" :: "args \<Rightarrow> 'a upper_pd" ("{_}\<sharp>")
huffman@26927
   138
huffman@26927
   139
translations
huffman@26927
   140
  "{x,xs}\<sharp>" == "{x}\<sharp> +\<sharp> {xs}\<sharp>"
huffman@26927
   141
  "{x}\<sharp>" == "CONST upper_unit\<cdot>x"
huffman@26927
   142
huffman@26927
   143
lemma upper_unit_Rep_compact_basis [simp]:
huffman@26927
   144
  "{Rep_compact_basis a}\<sharp> = upper_principal (PDUnit a)"
huffman@26927
   145
unfolding upper_unit_def
huffman@27289
   146
by (simp add: compact_basis.basis_fun_principal PDUnit_upper_mono)
huffman@26927
   147
huffman@25904
   148
lemma upper_plus_principal [simp]:
huffman@26927
   149
  "upper_principal t +\<sharp> upper_principal u = upper_principal (PDPlus t u)"
huffman@25904
   150
unfolding upper_plus_def
huffman@25904
   151
by (simp add: upper_pd.basis_fun_principal
huffman@25904
   152
    upper_pd.basis_fun_mono PDPlus_upper_mono)
huffman@25904
   153
haftmann@37770
   154
interpretation upper_add: semilattice upper_add proof
haftmann@34973
   155
  fix xs ys zs :: "'a upper_pd"
haftmann@34973
   156
  show "(xs +\<sharp> ys) +\<sharp> zs = xs +\<sharp> (ys +\<sharp> zs)"
haftmann@34973
   157
    apply (induct xs ys arbitrary: zs rule: upper_pd.principal_induct2, simp, simp)
haftmann@34973
   158
    apply (rule_tac x=zs in upper_pd.principal_induct, simp)
haftmann@34973
   159
    apply (simp add: PDPlus_assoc)
haftmann@34973
   160
    done
haftmann@34973
   161
  show "xs +\<sharp> ys = ys +\<sharp> xs"
haftmann@34973
   162
    apply (induct xs ys rule: upper_pd.principal_induct2, simp, simp)
haftmann@34973
   163
    apply (simp add: PDPlus_commute)
haftmann@34973
   164
    done
haftmann@34973
   165
  show "xs +\<sharp> xs = xs"
haftmann@34973
   166
    apply (induct xs rule: upper_pd.principal_induct, simp)
haftmann@34973
   167
    apply (simp add: PDPlus_absorb)
haftmann@34973
   168
    done
haftmann@34973
   169
qed
huffman@26927
   170
haftmann@34973
   171
lemmas upper_plus_assoc = upper_add.assoc
haftmann@34973
   172
lemmas upper_plus_commute = upper_add.commute
haftmann@34973
   173
lemmas upper_plus_absorb = upper_add.idem
haftmann@34973
   174
lemmas upper_plus_left_commute = upper_add.left_commute
haftmann@34973
   175
lemmas upper_plus_left_absorb = upper_add.left_idem
huffman@26927
   176
huffman@29990
   177
text {* Useful for @{text "simp add: upper_plus_ac"} *}
huffman@29990
   178
lemmas upper_plus_ac =
huffman@29990
   179
  upper_plus_assoc upper_plus_commute upper_plus_left_commute
huffman@29990
   180
huffman@29990
   181
text {* Useful for @{text "simp only: upper_plus_aci"} *}
huffman@29990
   182
lemmas upper_plus_aci =
huffman@29990
   183
  upper_plus_ac upper_plus_absorb upper_plus_left_absorb
huffman@29990
   184
huffman@31076
   185
lemma upper_plus_below1: "xs +\<sharp> ys \<sqsubseteq> xs"
huffman@27289
   186
apply (induct xs ys rule: upper_pd.principal_induct2, simp, simp)
huffman@31076
   187
apply (simp add: PDPlus_upper_le)
huffman@25904
   188
done
huffman@25904
   189
huffman@31076
   190
lemma upper_plus_below2: "xs +\<sharp> ys \<sqsubseteq> ys"
huffman@31076
   191
by (subst upper_plus_commute, rule upper_plus_below1)
huffman@25904
   192
huffman@26927
   193
lemma upper_plus_greatest: "\<lbrakk>xs \<sqsubseteq> ys; xs \<sqsubseteq> zs\<rbrakk> \<Longrightarrow> xs \<sqsubseteq> ys +\<sharp> zs"
huffman@25904
   194
apply (subst upper_plus_absorb [of xs, symmetric])
huffman@25904
   195
apply (erule (1) monofun_cfun [OF monofun_cfun_arg])
huffman@25904
   196
done
huffman@25904
   197
huffman@40734
   198
lemma upper_below_plus_iff [simp]:
huffman@26927
   199
  "xs \<sqsubseteq> ys +\<sharp> zs \<longleftrightarrow> xs \<sqsubseteq> ys \<and> xs \<sqsubseteq> zs"
huffman@25904
   200
apply safe
huffman@31076
   201
apply (erule below_trans [OF _ upper_plus_below1])
huffman@31076
   202
apply (erule below_trans [OF _ upper_plus_below2])
huffman@25904
   203
apply (erule (1) upper_plus_greatest)
huffman@25904
   204
done
huffman@25904
   205
huffman@40734
   206
lemma upper_plus_below_unit_iff [simp]:
huffman@26927
   207
  "xs +\<sharp> ys \<sqsubseteq> {z}\<sharp> \<longleftrightarrow> xs \<sqsubseteq> {z}\<sharp> \<or> ys \<sqsubseteq> {z}\<sharp>"
brianh@39970
   208
apply (induct xs rule: upper_pd.principal_induct, simp)
brianh@39970
   209
apply (induct ys rule: upper_pd.principal_induct, simp)
brianh@39970
   210
apply (induct z rule: compact_basis.principal_induct, simp)
brianh@39970
   211
apply (simp add: upper_le_PDPlus_PDUnit_iff)
huffman@25904
   212
done
huffman@25904
   213
huffman@31076
   214
lemma upper_unit_below_iff [simp]: "{x}\<sharp> \<sqsubseteq> {y}\<sharp> \<longleftrightarrow> x \<sqsubseteq> y"
brianh@39970
   215
apply (induct x rule: compact_basis.principal_induct, simp)
brianh@39970
   216
apply (induct y rule: compact_basis.principal_induct, simp)
brianh@39970
   217
apply simp
huffman@26927
   218
done
huffman@26927
   219
huffman@31076
   220
lemmas upper_pd_below_simps =
huffman@31076
   221
  upper_unit_below_iff
huffman@31076
   222
  upper_below_plus_iff
huffman@31076
   223
  upper_plus_below_unit_iff
huffman@25904
   224
huffman@26927
   225
lemma upper_unit_eq_iff [simp]: "{x}\<sharp> = {y}\<sharp> \<longleftrightarrow> x = y"
huffman@26927
   226
unfolding po_eq_conv by simp
huffman@26927
   227
huffman@26927
   228
lemma upper_unit_strict [simp]: "{\<bottom>}\<sharp> = \<bottom>"
huffman@39974
   229
using upper_unit_Rep_compact_basis [of compact_bot]
huffman@39974
   230
by (simp add: inst_upper_pd_pcpo)
huffman@26927
   231
huffman@26927
   232
lemma upper_plus_strict1 [simp]: "\<bottom> +\<sharp> ys = \<bottom>"
huffman@31076
   233
by (rule UU_I, rule upper_plus_below1)
huffman@26927
   234
huffman@26927
   235
lemma upper_plus_strict2 [simp]: "xs +\<sharp> \<bottom> = \<bottom>"
huffman@31076
   236
by (rule UU_I, rule upper_plus_below2)
huffman@26927
   237
huffman@40321
   238
lemma upper_unit_bottom_iff [simp]: "{x}\<sharp> = \<bottom> \<longleftrightarrow> x = \<bottom>"
huffman@26927
   239
unfolding upper_unit_strict [symmetric] by (rule upper_unit_eq_iff)
huffman@26927
   240
huffman@40321
   241
lemma upper_plus_bottom_iff [simp]:
huffman@26927
   242
  "xs +\<sharp> ys = \<bottom> \<longleftrightarrow> xs = \<bottom> \<or> ys = \<bottom>"
huffman@26927
   243
apply (rule iffI)
huffman@26927
   244
apply (erule rev_mp)
huffman@27289
   245
apply (rule upper_pd.principal_induct2 [where x=xs and y=ys], simp, simp)
huffman@27289
   246
apply (simp add: inst_upper_pd_pcpo upper_pd.principal_eq_iff
huffman@26927
   247
                 upper_le_PDPlus_PDUnit_iff)
huffman@26927
   248
apply auto
huffman@26927
   249
done
huffman@26927
   250
huffman@39974
   251
lemma compact_upper_unit: "compact x \<Longrightarrow> compact {x}\<sharp>"
huffman@39974
   252
by (auto dest!: compact_basis.compact_imp_principal)
huffman@39974
   253
huffman@26927
   254
lemma compact_upper_unit_iff [simp]: "compact {x}\<sharp> \<longleftrightarrow> compact x"
huffman@39974
   255
apply (safe elim!: compact_upper_unit)
huffman@39974
   256
apply (simp only: compact_def upper_unit_below_iff [symmetric])
huffman@40327
   257
apply (erule adm_subst [OF cont_Rep_cfun2])
huffman@39974
   258
done
huffman@26927
   259
huffman@26927
   260
lemma compact_upper_plus [simp]:
huffman@26927
   261
  "\<lbrakk>compact xs; compact ys\<rbrakk> \<Longrightarrow> compact (xs +\<sharp> ys)"
huffman@27289
   262
by (auto dest!: upper_pd.compact_imp_principal)
huffman@26927
   263
huffman@25904
   264
huffman@25904
   265
subsection {* Induction rules *}
huffman@25904
   266
huffman@25904
   267
lemma upper_pd_induct1:
huffman@25904
   268
  assumes P: "adm P"
huffman@26927
   269
  assumes unit: "\<And>x. P {x}\<sharp>"
huffman@26927
   270
  assumes insert: "\<And>x ys. \<lbrakk>P {x}\<sharp>; P ys\<rbrakk> \<Longrightarrow> P ({x}\<sharp> +\<sharp> ys)"
huffman@25904
   271
  shows "P (xs::'a upper_pd)"
huffman@27289
   272
apply (induct xs rule: upper_pd.principal_induct, rule P)
huffman@27289
   273
apply (induct_tac a rule: pd_basis_induct1)
huffman@25904
   274
apply (simp only: upper_unit_Rep_compact_basis [symmetric])
huffman@25904
   275
apply (rule unit)
huffman@25904
   276
apply (simp only: upper_unit_Rep_compact_basis [symmetric]
huffman@25904
   277
                  upper_plus_principal [symmetric])
huffman@25904
   278
apply (erule insert [OF unit])
huffman@25904
   279
done
huffman@25904
   280
huffman@40576
   281
lemma upper_pd_induct
huffman@40576
   282
  [case_names adm upper_unit upper_plus, induct type: upper_pd]:
huffman@25904
   283
  assumes P: "adm P"
huffman@26927
   284
  assumes unit: "\<And>x. P {x}\<sharp>"
huffman@26927
   285
  assumes plus: "\<And>xs ys. \<lbrakk>P xs; P ys\<rbrakk> \<Longrightarrow> P (xs +\<sharp> ys)"
huffman@25904
   286
  shows "P (xs::'a upper_pd)"
huffman@27289
   287
apply (induct xs rule: upper_pd.principal_induct, rule P)
huffman@27289
   288
apply (induct_tac a rule: pd_basis_induct)
huffman@25904
   289
apply (simp only: upper_unit_Rep_compact_basis [symmetric] unit)
huffman@25904
   290
apply (simp only: upper_plus_principal [symmetric] plus)
huffman@25904
   291
done
huffman@25904
   292
huffman@25904
   293
huffman@25904
   294
subsection {* Monadic bind *}
huffman@25904
   295
huffman@25904
   296
definition
huffman@25904
   297
  upper_bind_basis ::
huffman@25904
   298
  "'a pd_basis \<Rightarrow> ('a \<rightarrow> 'b upper_pd) \<rightarrow> 'b upper_pd" where
huffman@25904
   299
  "upper_bind_basis = fold_pd
huffman@25904
   300
    (\<lambda>a. \<Lambda> f. f\<cdot>(Rep_compact_basis a))
huffman@26927
   301
    (\<lambda>x y. \<Lambda> f. x\<cdot>f +\<sharp> y\<cdot>f)"
huffman@25904
   302
huffman@26927
   303
lemma ACI_upper_bind:
haftmann@36635
   304
  "class.ab_semigroup_idem_mult (\<lambda>x y. \<Lambda> f. x\<cdot>f +\<sharp> y\<cdot>f)"
huffman@25904
   305
apply unfold_locales
haftmann@26041
   306
apply (simp add: upper_plus_assoc)
huffman@25904
   307
apply (simp add: upper_plus_commute)
huffman@29990
   308
apply (simp add: eta_cfun)
huffman@25904
   309
done
huffman@25904
   310
huffman@25904
   311
lemma upper_bind_basis_simps [simp]:
huffman@25904
   312
  "upper_bind_basis (PDUnit a) =
huffman@25904
   313
    (\<Lambda> f. f\<cdot>(Rep_compact_basis a))"
huffman@25904
   314
  "upper_bind_basis (PDPlus t u) =
huffman@26927
   315
    (\<Lambda> f. upper_bind_basis t\<cdot>f +\<sharp> upper_bind_basis u\<cdot>f)"
huffman@25904
   316
unfolding upper_bind_basis_def
huffman@25904
   317
apply -
huffman@26927
   318
apply (rule fold_pd_PDUnit [OF ACI_upper_bind])
huffman@26927
   319
apply (rule fold_pd_PDPlus [OF ACI_upper_bind])
huffman@25904
   320
done
huffman@25904
   321
huffman@25904
   322
lemma upper_bind_basis_mono:
huffman@25904
   323
  "t \<le>\<sharp> u \<Longrightarrow> upper_bind_basis t \<sqsubseteq> upper_bind_basis u"
huffman@40002
   324
unfolding cfun_below_iff
huffman@25904
   325
apply (erule upper_le_induct, safe)
huffman@27289
   326
apply (simp add: monofun_cfun)
huffman@31076
   327
apply (simp add: below_trans [OF upper_plus_below1])
huffman@40734
   328
apply simp
huffman@25904
   329
done
huffman@25904
   330
huffman@25904
   331
definition
huffman@25904
   332
  upper_bind :: "'a upper_pd \<rightarrow> ('a \<rightarrow> 'b upper_pd) \<rightarrow> 'b upper_pd" where
huffman@25904
   333
  "upper_bind = upper_pd.basis_fun upper_bind_basis"
huffman@25904
   334
huffman@41036
   335
syntax
huffman@41036
   336
  "_upper_bind" :: "[logic, logic, logic] \<Rightarrow> logic"
huffman@41036
   337
    ("(3\<Union>\<sharp>_\<in>_./ _)" [0, 0, 10] 10)
huffman@41036
   338
huffman@41036
   339
translations
huffman@41036
   340
  "\<Union>\<sharp>x\<in>xs. e" == "CONST upper_bind\<cdot>xs\<cdot>(\<Lambda> x. e)"
huffman@41036
   341
huffman@25904
   342
lemma upper_bind_principal [simp]:
huffman@25904
   343
  "upper_bind\<cdot>(upper_principal t) = upper_bind_basis t"
huffman@25904
   344
unfolding upper_bind_def
huffman@25904
   345
apply (rule upper_pd.basis_fun_principal)
huffman@25904
   346
apply (erule upper_bind_basis_mono)
huffman@25904
   347
done
huffman@25904
   348
huffman@25904
   349
lemma upper_bind_unit [simp]:
huffman@26927
   350
  "upper_bind\<cdot>{x}\<sharp>\<cdot>f = f\<cdot>x"
huffman@27289
   351
by (induct x rule: compact_basis.principal_induct, simp, simp)
huffman@25904
   352
huffman@25904
   353
lemma upper_bind_plus [simp]:
huffman@26927
   354
  "upper_bind\<cdot>(xs +\<sharp> ys)\<cdot>f = upper_bind\<cdot>xs\<cdot>f +\<sharp> upper_bind\<cdot>ys\<cdot>f"
huffman@27289
   355
by (induct xs ys rule: upper_pd.principal_induct2, simp, simp, simp)
huffman@25904
   356
huffman@25904
   357
lemma upper_bind_strict [simp]: "upper_bind\<cdot>\<bottom>\<cdot>f = f\<cdot>\<bottom>"
huffman@25904
   358
unfolding upper_unit_strict [symmetric] by (rule upper_bind_unit)
huffman@25904
   359
huffman@40589
   360
lemma upper_bind_bind:
huffman@40589
   361
  "upper_bind\<cdot>(upper_bind\<cdot>xs\<cdot>f)\<cdot>g = upper_bind\<cdot>xs\<cdot>(\<Lambda> x. upper_bind\<cdot>(f\<cdot>x)\<cdot>g)"
huffman@40589
   362
by (induct xs, simp_all)
huffman@40589
   363
huffman@25904
   364
huffman@39974
   365
subsection {* Map *}
huffman@25904
   366
huffman@25904
   367
definition
huffman@25904
   368
  upper_map :: "('a \<rightarrow> 'b) \<rightarrow> 'a upper_pd \<rightarrow> 'b upper_pd" where
huffman@26927
   369
  "upper_map = (\<Lambda> f xs. upper_bind\<cdot>xs\<cdot>(\<Lambda> x. {f\<cdot>x}\<sharp>))"
huffman@25904
   370
huffman@25904
   371
lemma upper_map_unit [simp]:
huffman@26927
   372
  "upper_map\<cdot>f\<cdot>{x}\<sharp> = {f\<cdot>x}\<sharp>"
huffman@25904
   373
unfolding upper_map_def by simp
huffman@25904
   374
huffman@25904
   375
lemma upper_map_plus [simp]:
huffman@26927
   376
  "upper_map\<cdot>f\<cdot>(xs +\<sharp> ys) = upper_map\<cdot>f\<cdot>xs +\<sharp> upper_map\<cdot>f\<cdot>ys"
huffman@25904
   377
unfolding upper_map_def by simp
huffman@25904
   378
huffman@40577
   379
lemma upper_map_bottom [simp]: "upper_map\<cdot>f\<cdot>\<bottom> = {f\<cdot>\<bottom>}\<sharp>"
huffman@40577
   380
unfolding upper_map_def by simp
huffman@40577
   381
huffman@25904
   382
lemma upper_map_ident: "upper_map\<cdot>(\<Lambda> x. x)\<cdot>xs = xs"
huffman@25904
   383
by (induct xs rule: upper_pd_induct, simp_all)
huffman@25904
   384
huffman@33808
   385
lemma upper_map_ID: "upper_map\<cdot>ID = ID"
huffman@40002
   386
by (simp add: cfun_eq_iff ID_def upper_map_ident)
huffman@33808
   387
huffman@25904
   388
lemma upper_map_map:
huffman@25904
   389
  "upper_map\<cdot>f\<cdot>(upper_map\<cdot>g\<cdot>xs) = upper_map\<cdot>(\<Lambda> x. f\<cdot>(g\<cdot>x))\<cdot>xs"
huffman@25904
   390
by (induct xs rule: upper_pd_induct, simp_all)
huffman@25904
   391
huffman@41110
   392
lemma upper_bind_map:
huffman@41110
   393
  "upper_bind\<cdot>(upper_map\<cdot>f\<cdot>xs)\<cdot>g = upper_bind\<cdot>xs\<cdot>(\<Lambda> x. g\<cdot>(f\<cdot>x))"
huffman@41110
   394
by (simp add: upper_map_def upper_bind_bind)
huffman@41110
   395
huffman@41110
   396
lemma upper_map_bind:
huffman@41110
   397
  "upper_map\<cdot>f\<cdot>(upper_bind\<cdot>xs\<cdot>g) = upper_bind\<cdot>xs\<cdot>(\<Lambda> x. upper_map\<cdot>f\<cdot>(g\<cdot>x))"
huffman@41110
   398
by (simp add: upper_map_def upper_bind_bind)
huffman@41110
   399
huffman@33585
   400
lemma ep_pair_upper_map: "ep_pair e p \<Longrightarrow> ep_pair (upper_map\<cdot>e) (upper_map\<cdot>p)"
huffman@33585
   401
apply default
huffman@33585
   402
apply (induct_tac x rule: upper_pd_induct, simp_all add: ep_pair.e_inverse)
huffman@35901
   403
apply (induct_tac y rule: upper_pd_induct)
huffman@40734
   404
apply (simp_all add: ep_pair.e_p_below monofun_cfun del: upper_below_plus_iff)
huffman@33585
   405
done
huffman@33585
   406
huffman@33585
   407
lemma deflation_upper_map: "deflation d \<Longrightarrow> deflation (upper_map\<cdot>d)"
huffman@33585
   408
apply default
huffman@33585
   409
apply (induct_tac x rule: upper_pd_induct, simp_all add: deflation.idem)
huffman@35901
   410
apply (induct_tac x rule: upper_pd_induct)
huffman@40734
   411
apply (simp_all add: deflation.below monofun_cfun del: upper_below_plus_iff)
huffman@33585
   412
done
huffman@33585
   413
huffman@39974
   414
(* FIXME: long proof! *)
huffman@39974
   415
lemma finite_deflation_upper_map:
huffman@39974
   416
  assumes "finite_deflation d" shows "finite_deflation (upper_map\<cdot>d)"
huffman@39974
   417
proof (rule finite_deflation_intro)
huffman@39974
   418
  interpret d: finite_deflation d by fact
huffman@39974
   419
  have "deflation d" by fact
huffman@39974
   420
  thus "deflation (upper_map\<cdot>d)" by (rule deflation_upper_map)
huffman@39974
   421
  have "finite (range (\<lambda>x. d\<cdot>x))" by (rule d.finite_range)
huffman@39974
   422
  hence "finite (Rep_compact_basis -` range (\<lambda>x. d\<cdot>x))"
huffman@39974
   423
    by (rule finite_vimageI, simp add: inj_on_def Rep_compact_basis_inject)
huffman@39974
   424
  hence "finite (Pow (Rep_compact_basis -` range (\<lambda>x. d\<cdot>x)))" by simp
huffman@39974
   425
  hence "finite (Rep_pd_basis -` (Pow (Rep_compact_basis -` range (\<lambda>x. d\<cdot>x))))"
huffman@39974
   426
    by (rule finite_vimageI, simp add: inj_on_def Rep_pd_basis_inject)
huffman@39974
   427
  hence *: "finite (upper_principal ` Rep_pd_basis -` (Pow (Rep_compact_basis -` range (\<lambda>x. d\<cdot>x))))" by simp
huffman@39974
   428
  hence "finite (range (\<lambda>xs. upper_map\<cdot>d\<cdot>xs))"
huffman@39974
   429
    apply (rule rev_finite_subset)
huffman@39974
   430
    apply clarsimp
huffman@39974
   431
    apply (induct_tac xs rule: upper_pd.principal_induct)
huffman@39974
   432
    apply (simp add: adm_mem_finite *)
huffman@39974
   433
    apply (rename_tac t, induct_tac t rule: pd_basis_induct)
huffman@39974
   434
    apply (simp only: upper_unit_Rep_compact_basis [symmetric] upper_map_unit)
huffman@39974
   435
    apply simp
huffman@39974
   436
    apply (subgoal_tac "\<exists>b. d\<cdot>(Rep_compact_basis a) = Rep_compact_basis b")
huffman@39974
   437
    apply clarsimp
huffman@39974
   438
    apply (rule imageI)
huffman@39974
   439
    apply (rule vimageI2)
huffman@39974
   440
    apply (simp add: Rep_PDUnit)
huffman@39974
   441
    apply (rule range_eqI)
huffman@39974
   442
    apply (erule sym)
huffman@39974
   443
    apply (rule exI)
huffman@39974
   444
    apply (rule Abs_compact_basis_inverse [symmetric])
huffman@39974
   445
    apply (simp add: d.compact)
huffman@39974
   446
    apply (simp only: upper_plus_principal [symmetric] upper_map_plus)
huffman@39974
   447
    apply clarsimp
huffman@39974
   448
    apply (rule imageI)
huffman@39974
   449
    apply (rule vimageI2)
huffman@39974
   450
    apply (simp add: Rep_PDPlus)
huffman@39974
   451
    done
huffman@39974
   452
  thus "finite {xs. upper_map\<cdot>d\<cdot>xs = xs}"
huffman@39974
   453
    by (rule finite_range_imp_finite_fixes)
huffman@39974
   454
qed
huffman@39974
   455
huffman@40497
   456
subsection {* Upper powerdomain is a domain *}
huffman@39974
   457
huffman@41286
   458
lemma approx_chain_upper_map:
huffman@41286
   459
  assumes "approx_chain a"
huffman@41286
   460
  shows "approx_chain (\<lambda>i. upper_map\<cdot>(a i))"
huffman@41286
   461
  using assms unfolding approx_chain_def
huffman@41286
   462
  by (simp add: lub_APP upper_map_ID finite_deflation_upper_map)
huffman@41286
   463
huffman@41286
   464
instance upper_pd :: ("domain") bifinite
huffman@41286
   465
proof
huffman@41286
   466
  show "\<exists>(a::nat \<Rightarrow> 'a upper_pd \<rightarrow> 'a upper_pd). approx_chain a"
huffman@41286
   467
    using bifinite [where 'a='a]
huffman@41286
   468
    by (fast intro!: approx_chain_upper_map)
huffman@41286
   469
qed
huffman@41286
   470
huffman@39974
   471
definition
huffman@39974
   472
  upper_approx :: "nat \<Rightarrow> udom upper_pd \<rightarrow> udom upper_pd"
huffman@39974
   473
where
huffman@39974
   474
  "upper_approx = (\<lambda>i. upper_map\<cdot>(udom_approx i))"
huffman@39974
   475
huffman@39974
   476
lemma upper_approx: "approx_chain upper_approx"
huffman@40484
   477
using upper_map_ID finite_deflation_upper_map
huffman@40484
   478
unfolding upper_approx_def by (rule approx_chain_lemma1)
huffman@39974
   479
huffman@39989
   480
definition upper_defl :: "defl \<rightarrow> defl"
huffman@39989
   481
where "upper_defl = defl_fun1 upper_approx upper_map"
huffman@39974
   482
huffman@39989
   483
lemma cast_upper_defl:
huffman@39989
   484
  "cast\<cdot>(upper_defl\<cdot>A) =
huffman@39974
   485
    udom_emb upper_approx oo upper_map\<cdot>(cast\<cdot>A) oo udom_prj upper_approx"
huffman@40484
   486
using upper_approx finite_deflation_upper_map
huffman@40484
   487
unfolding upper_defl_def by (rule cast_defl_fun1)
huffman@39974
   488
huffman@40497
   489
instantiation upper_pd :: ("domain") liftdomain
huffman@39974
   490
begin
huffman@39974
   491
huffman@39974
   492
definition
huffman@39974
   493
  "emb = udom_emb upper_approx oo upper_map\<cdot>emb"
huffman@39974
   494
huffman@39974
   495
definition
huffman@39974
   496
  "prj = upper_map\<cdot>prj oo udom_prj upper_approx"
huffman@39974
   497
huffman@39974
   498
definition
huffman@39989
   499
  "defl (t::'a upper_pd itself) = upper_defl\<cdot>DEFL('a)"
huffman@39974
   500
huffman@40491
   501
definition
huffman@40491
   502
  "(liftemb :: 'a upper_pd u \<rightarrow> udom) = udom_emb u_approx oo u_map\<cdot>emb"
huffman@40491
   503
huffman@40491
   504
definition
huffman@40491
   505
  "(liftprj :: udom \<rightarrow> 'a upper_pd u) = u_map\<cdot>prj oo udom_prj u_approx"
huffman@40491
   506
huffman@40491
   507
definition
huffman@40491
   508
  "liftdefl (t::'a upper_pd itself) = u_defl\<cdot>DEFL('a upper_pd)"
huffman@40491
   509
huffman@40491
   510
instance
huffman@40491
   511
using liftemb_upper_pd_def liftprj_upper_pd_def liftdefl_upper_pd_def
huffman@40494
   512
proof (rule liftdomain_class_intro)
huffman@39974
   513
  show "ep_pair emb (prj :: udom \<rightarrow> 'a upper_pd)"
huffman@39974
   514
    unfolding emb_upper_pd_def prj_upper_pd_def
huffman@39974
   515
    using ep_pair_udom [OF upper_approx]
huffman@39974
   516
    by (intro ep_pair_comp ep_pair_upper_map ep_pair_emb_prj)
huffman@39974
   517
next
huffman@39989
   518
  show "cast\<cdot>DEFL('a upper_pd) = emb oo (prj :: udom \<rightarrow> 'a upper_pd)"
huffman@39989
   519
    unfolding emb_upper_pd_def prj_upper_pd_def defl_upper_pd_def cast_upper_defl
huffman@40002
   520
    by (simp add: cast_DEFL oo_def cfun_eq_iff upper_map_map)
huffman@39974
   521
qed
huffman@39974
   522
huffman@25904
   523
end
huffman@39974
   524
huffman@39989
   525
lemma DEFL_upper: "DEFL('a upper_pd) = upper_defl\<cdot>DEFL('a)"
huffman@39989
   526
by (rule defl_upper_pd_def)
huffman@39974
   527
huffman@39974
   528
huffman@39974
   529
subsection {* Join *}
huffman@39974
   530
huffman@39974
   531
definition
huffman@39974
   532
  upper_join :: "'a upper_pd upper_pd \<rightarrow> 'a upper_pd" where
huffman@39974
   533
  "upper_join = (\<Lambda> xss. upper_bind\<cdot>xss\<cdot>(\<Lambda> xs. xs))"
huffman@39974
   534
huffman@39974
   535
lemma upper_join_unit [simp]:
huffman@39974
   536
  "upper_join\<cdot>{xs}\<sharp> = xs"
huffman@39974
   537
unfolding upper_join_def by simp
huffman@39974
   538
huffman@39974
   539
lemma upper_join_plus [simp]:
huffman@39974
   540
  "upper_join\<cdot>(xss +\<sharp> yss) = upper_join\<cdot>xss +\<sharp> upper_join\<cdot>yss"
huffman@39974
   541
unfolding upper_join_def by simp
huffman@39974
   542
huffman@40577
   543
lemma upper_join_bottom [simp]: "upper_join\<cdot>\<bottom> = \<bottom>"
huffman@40577
   544
unfolding upper_join_def by simp
huffman@40577
   545
huffman@39974
   546
lemma upper_join_map_unit:
huffman@39974
   547
  "upper_join\<cdot>(upper_map\<cdot>upper_unit\<cdot>xs) = xs"
huffman@39974
   548
by (induct xs rule: upper_pd_induct, simp_all)
huffman@39974
   549
huffman@39974
   550
lemma upper_join_map_join:
huffman@39974
   551
  "upper_join\<cdot>(upper_map\<cdot>upper_join\<cdot>xsss) = upper_join\<cdot>(upper_join\<cdot>xsss)"
huffman@39974
   552
by (induct xsss rule: upper_pd_induct, simp_all)
huffman@39974
   553
huffman@39974
   554
lemma upper_join_map_map:
huffman@39974
   555
  "upper_join\<cdot>(upper_map\<cdot>(upper_map\<cdot>f)\<cdot>xss) =
huffman@39974
   556
   upper_map\<cdot>f\<cdot>(upper_join\<cdot>xss)"
huffman@39974
   557
by (induct xss rule: upper_pd_induct, simp_all)
huffman@39974
   558
huffman@39974
   559
end