src/HOL/HOLCF/UpperPD.thy
author blanchet
Tue Nov 07 15:16:42 2017 +0100 (20 months ago)
changeset 67022 49309fe530fd
parent 62175 8ffc4d0e652d
child 67682 00c436488398
permissions -rw-r--r--
more robust parsing for THF proofs (esp. polymorphic Leo-III proofs)
wenzelm@42151
     1
(*  Title:      HOL/HOLCF/UpperPD.thy
huffman@25904
     2
    Author:     Brian Huffman
huffman@25904
     3
*)
huffman@25904
     4
wenzelm@62175
     5
section \<open>Upper powerdomain\<close>
huffman@25904
     6
huffman@25904
     7
theory UpperPD
huffman@41284
     8
imports Compact_Basis
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
  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
wenzelm@62175
    73
subsection \<open>Type definition\<close>
huffman@25904
    74
wenzelm@61998
    75
typedef 'a upper_pd  ("('(_')\<sharp>)") =
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@41288
    79
instantiation upper_pd :: (bifinite) below
huffman@27373
    80
begin
huffman@27373
    81
huffman@27373
    82
definition
huffman@27373
    83
  "x \<sqsubseteq> y \<longleftrightarrow> Rep_upper_pd x \<subseteq> Rep_upper_pd y"
huffman@27373
    84
huffman@27373
    85
instance ..
huffman@27373
    86
end
huffman@25904
    87
huffman@41288
    88
instance upper_pd :: (bifinite) po
huffman@39974
    89
using type_definition_upper_pd below_upper_pd_def
huffman@39974
    90
by (rule upper_le.typedef_ideal_po)
huffman@27373
    91
huffman@41288
    92
instance upper_pd :: (bifinite) cpo
huffman@39974
    93
using type_definition_upper_pd below_upper_pd_def
huffman@39974
    94
by (rule upper_le.typedef_ideal_cpo)
huffman@27373
    95
huffman@25904
    96
definition
huffman@25904
    97
  upper_principal :: "'a pd_basis \<Rightarrow> 'a upper_pd" where
huffman@27373
    98
  "upper_principal t = Abs_upper_pd {u. u \<le>\<sharp> t}"
huffman@25904
    99
wenzelm@30729
   100
interpretation upper_pd:
huffman@39974
   101
  ideal_completion upper_le upper_principal Rep_upper_pd
huffman@39984
   102
using type_definition_upper_pd below_upper_pd_def
huffman@39984
   103
using upper_principal_def pd_basis_countable
huffman@39984
   104
by (rule upper_le.typedef_ideal_completion)
huffman@25904
   105
wenzelm@62175
   106
text \<open>Upper powerdomain is pointed\<close>
huffman@25904
   107
huffman@25904
   108
lemma upper_pd_minimal: "upper_principal (PDUnit compact_bot) \<sqsubseteq> ys"
huffman@25904
   109
by (induct ys rule: upper_pd.principal_induct, simp, simp)
huffman@25904
   110
huffman@41288
   111
instance upper_pd :: (bifinite) pcpo
huffman@26927
   112
by intro_classes (fast intro: upper_pd_minimal)
huffman@25904
   113
huffman@25904
   114
lemma inst_upper_pd_pcpo: "\<bottom> = upper_principal (PDUnit compact_bot)"
huffman@41430
   115
by (rule upper_pd_minimal [THEN bottomI, symmetric])
huffman@25904
   116
huffman@25904
   117
wenzelm@62175
   118
subsection \<open>Monadic unit and plus\<close>
huffman@25904
   119
huffman@25904
   120
definition
huffman@25904
   121
  upper_unit :: "'a \<rightarrow> 'a upper_pd" where
huffman@41394
   122
  "upper_unit = compact_basis.extension (\<lambda>a. upper_principal (PDUnit a))"
huffman@25904
   123
huffman@25904
   124
definition
huffman@25904
   125
  upper_plus :: "'a upper_pd \<rightarrow> 'a upper_pd \<rightarrow> 'a upper_pd" where
huffman@41394
   126
  "upper_plus = upper_pd.extension (\<lambda>t. upper_pd.extension (\<lambda>u.
huffman@25904
   127
      upper_principal (PDPlus t u)))"
huffman@25904
   128
huffman@25904
   129
abbreviation
huffman@25904
   130
  upper_add :: "'a upper_pd \<Rightarrow> 'a upper_pd \<Rightarrow> 'a upper_pd"
huffman@41399
   131
    (infixl "\<union>\<sharp>" 65) where
huffman@41399
   132
  "xs \<union>\<sharp> ys == upper_plus\<cdot>xs\<cdot>ys"
huffman@25904
   133
huffman@26927
   134
syntax
huffman@41479
   135
  "_upper_pd" :: "args \<Rightarrow> logic" ("{_}\<sharp>")
huffman@26927
   136
huffman@26927
   137
translations
huffman@41399
   138
  "{x,xs}\<sharp>" == "{x}\<sharp> \<union>\<sharp> {xs}\<sharp>"
huffman@26927
   139
  "{x}\<sharp>" == "CONST upper_unit\<cdot>x"
huffman@26927
   140
huffman@26927
   141
lemma upper_unit_Rep_compact_basis [simp]:
huffman@26927
   142
  "{Rep_compact_basis a}\<sharp> = upper_principal (PDUnit a)"
huffman@26927
   143
unfolding upper_unit_def
huffman@41394
   144
by (simp add: compact_basis.extension_principal PDUnit_upper_mono)
huffman@26927
   145
huffman@25904
   146
lemma upper_plus_principal [simp]:
huffman@41399
   147
  "upper_principal t \<union>\<sharp> upper_principal u = upper_principal (PDPlus t u)"
huffman@25904
   148
unfolding upper_plus_def
huffman@41394
   149
by (simp add: upper_pd.extension_principal
huffman@41394
   150
    upper_pd.extension_mono PDPlus_upper_mono)
huffman@25904
   151
haftmann@37770
   152
interpretation upper_add: semilattice upper_add proof
haftmann@34973
   153
  fix xs ys zs :: "'a upper_pd"
huffman@41399
   154
  show "(xs \<union>\<sharp> ys) \<union>\<sharp> zs = xs \<union>\<sharp> (ys \<union>\<sharp> zs)"
huffman@41402
   155
    apply (induct xs rule: upper_pd.principal_induct, simp)
huffman@41402
   156
    apply (induct ys rule: upper_pd.principal_induct, simp)
huffman@41402
   157
    apply (induct zs rule: upper_pd.principal_induct, simp)
haftmann@34973
   158
    apply (simp add: PDPlus_assoc)
haftmann@34973
   159
    done
huffman@41399
   160
  show "xs \<union>\<sharp> ys = ys \<union>\<sharp> xs"
huffman@41402
   161
    apply (induct xs rule: upper_pd.principal_induct, simp)
huffman@41402
   162
    apply (induct ys rule: upper_pd.principal_induct, simp)
haftmann@34973
   163
    apply (simp add: PDPlus_commute)
haftmann@34973
   164
    done
huffman@41399
   165
  show "xs \<union>\<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
wenzelm@62175
   177
text \<open>Useful for \<open>simp add: upper_plus_ac\<close>\<close>
huffman@29990
   178
lemmas upper_plus_ac =
huffman@29990
   179
  upper_plus_assoc upper_plus_commute upper_plus_left_commute
huffman@29990
   180
wenzelm@62175
   181
text \<open>Useful for \<open>simp only: upper_plus_aci\<close>\<close>
huffman@29990
   182
lemmas upper_plus_aci =
huffman@29990
   183
  upper_plus_ac upper_plus_absorb upper_plus_left_absorb
huffman@29990
   184
huffman@41399
   185
lemma upper_plus_below1: "xs \<union>\<sharp> ys \<sqsubseteq> xs"
huffman@41402
   186
apply (induct xs rule: upper_pd.principal_induct, simp)
huffman@41402
   187
apply (induct ys rule: upper_pd.principal_induct, simp)
huffman@31076
   188
apply (simp add: PDPlus_upper_le)
huffman@25904
   189
done
huffman@25904
   190
huffman@41399
   191
lemma upper_plus_below2: "xs \<union>\<sharp> ys \<sqsubseteq> ys"
huffman@31076
   192
by (subst upper_plus_commute, rule upper_plus_below1)
huffman@25904
   193
huffman@41399
   194
lemma upper_plus_greatest: "\<lbrakk>xs \<sqsubseteq> ys; xs \<sqsubseteq> zs\<rbrakk> \<Longrightarrow> xs \<sqsubseteq> ys \<union>\<sharp> zs"
huffman@25904
   195
apply (subst upper_plus_absorb [of xs, symmetric])
huffman@25904
   196
apply (erule (1) monofun_cfun [OF monofun_cfun_arg])
huffman@25904
   197
done
huffman@25904
   198
huffman@40734
   199
lemma upper_below_plus_iff [simp]:
huffman@41399
   200
  "xs \<sqsubseteq> ys \<union>\<sharp> zs \<longleftrightarrow> xs \<sqsubseteq> ys \<and> xs \<sqsubseteq> zs"
huffman@25904
   201
apply safe
huffman@31076
   202
apply (erule below_trans [OF _ upper_plus_below1])
huffman@31076
   203
apply (erule below_trans [OF _ upper_plus_below2])
huffman@25904
   204
apply (erule (1) upper_plus_greatest)
huffman@25904
   205
done
huffman@25904
   206
huffman@40734
   207
lemma upper_plus_below_unit_iff [simp]:
huffman@41399
   208
  "xs \<union>\<sharp> ys \<sqsubseteq> {z}\<sharp> \<longleftrightarrow> xs \<sqsubseteq> {z}\<sharp> \<or> ys \<sqsubseteq> {z}\<sharp>"
brianh@39970
   209
apply (induct xs rule: upper_pd.principal_induct, simp)
brianh@39970
   210
apply (induct ys rule: upper_pd.principal_induct, simp)
brianh@39970
   211
apply (induct z rule: compact_basis.principal_induct, simp)
brianh@39970
   212
apply (simp add: upper_le_PDPlus_PDUnit_iff)
huffman@25904
   213
done
huffman@25904
   214
huffman@31076
   215
lemma upper_unit_below_iff [simp]: "{x}\<sharp> \<sqsubseteq> {y}\<sharp> \<longleftrightarrow> x \<sqsubseteq> y"
brianh@39970
   216
apply (induct x rule: compact_basis.principal_induct, simp)
brianh@39970
   217
apply (induct y rule: compact_basis.principal_induct, simp)
brianh@39970
   218
apply simp
huffman@26927
   219
done
huffman@26927
   220
huffman@31076
   221
lemmas upper_pd_below_simps =
huffman@31076
   222
  upper_unit_below_iff
huffman@31076
   223
  upper_below_plus_iff
huffman@31076
   224
  upper_plus_below_unit_iff
huffman@25904
   225
huffman@26927
   226
lemma upper_unit_eq_iff [simp]: "{x}\<sharp> = {y}\<sharp> \<longleftrightarrow> x = y"
huffman@26927
   227
unfolding po_eq_conv by simp
huffman@26927
   228
huffman@26927
   229
lemma upper_unit_strict [simp]: "{\<bottom>}\<sharp> = \<bottom>"
huffman@39974
   230
using upper_unit_Rep_compact_basis [of compact_bot]
huffman@39974
   231
by (simp add: inst_upper_pd_pcpo)
huffman@26927
   232
huffman@41399
   233
lemma upper_plus_strict1 [simp]: "\<bottom> \<union>\<sharp> ys = \<bottom>"
huffman@41430
   234
by (rule bottomI, rule upper_plus_below1)
huffman@26927
   235
huffman@41399
   236
lemma upper_plus_strict2 [simp]: "xs \<union>\<sharp> \<bottom> = \<bottom>"
huffman@41430
   237
by (rule bottomI, rule upper_plus_below2)
huffman@26927
   238
huffman@40321
   239
lemma upper_unit_bottom_iff [simp]: "{x}\<sharp> = \<bottom> \<longleftrightarrow> x = \<bottom>"
huffman@26927
   240
unfolding upper_unit_strict [symmetric] by (rule upper_unit_eq_iff)
huffman@26927
   241
huffman@40321
   242
lemma upper_plus_bottom_iff [simp]:
huffman@41399
   243
  "xs \<union>\<sharp> ys = \<bottom> \<longleftrightarrow> xs = \<bottom> \<or> ys = \<bottom>"
huffman@41402
   244
apply (induct xs rule: upper_pd.principal_induct, simp)
huffman@41402
   245
apply (induct ys rule: upper_pd.principal_induct, 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
done
huffman@26927
   249
huffman@39974
   250
lemma compact_upper_unit: "compact x \<Longrightarrow> compact {x}\<sharp>"
huffman@39974
   251
by (auto dest!: compact_basis.compact_imp_principal)
huffman@39974
   252
huffman@26927
   253
lemma compact_upper_unit_iff [simp]: "compact {x}\<sharp> \<longleftrightarrow> compact x"
huffman@39974
   254
apply (safe elim!: compact_upper_unit)
huffman@39974
   255
apply (simp only: compact_def upper_unit_below_iff [symmetric])
huffman@40327
   256
apply (erule adm_subst [OF cont_Rep_cfun2])
huffman@39974
   257
done
huffman@26927
   258
huffman@26927
   259
lemma compact_upper_plus [simp]:
huffman@41399
   260
  "\<lbrakk>compact xs; compact ys\<rbrakk> \<Longrightarrow> compact (xs \<union>\<sharp> ys)"
huffman@27289
   261
by (auto dest!: upper_pd.compact_imp_principal)
huffman@26927
   262
huffman@25904
   263
wenzelm@62175
   264
subsection \<open>Induction rules\<close>
huffman@25904
   265
huffman@25904
   266
lemma upper_pd_induct1:
huffman@25904
   267
  assumes P: "adm P"
huffman@26927
   268
  assumes unit: "\<And>x. P {x}\<sharp>"
huffman@41399
   269
  assumes insert: "\<And>x ys. \<lbrakk>P {x}\<sharp>; P ys\<rbrakk> \<Longrightarrow> P ({x}\<sharp> \<union>\<sharp> ys)"
huffman@25904
   270
  shows "P (xs::'a upper_pd)"
huffman@27289
   271
apply (induct xs rule: upper_pd.principal_induct, rule P)
huffman@27289
   272
apply (induct_tac a rule: pd_basis_induct1)
huffman@25904
   273
apply (simp only: upper_unit_Rep_compact_basis [symmetric])
huffman@25904
   274
apply (rule unit)
huffman@25904
   275
apply (simp only: upper_unit_Rep_compact_basis [symmetric]
huffman@25904
   276
                  upper_plus_principal [symmetric])
huffman@25904
   277
apply (erule insert [OF unit])
huffman@25904
   278
done
huffman@25904
   279
huffman@40576
   280
lemma upper_pd_induct
huffman@40576
   281
  [case_names adm upper_unit upper_plus, induct type: upper_pd]:
huffman@25904
   282
  assumes P: "adm P"
huffman@26927
   283
  assumes unit: "\<And>x. P {x}\<sharp>"
huffman@41399
   284
  assumes plus: "\<And>xs ys. \<lbrakk>P xs; P ys\<rbrakk> \<Longrightarrow> P (xs \<union>\<sharp> ys)"
huffman@25904
   285
  shows "P (xs::'a upper_pd)"
huffman@27289
   286
apply (induct xs rule: upper_pd.principal_induct, rule P)
huffman@27289
   287
apply (induct_tac a rule: pd_basis_induct)
huffman@25904
   288
apply (simp only: upper_unit_Rep_compact_basis [symmetric] unit)
huffman@25904
   289
apply (simp only: upper_plus_principal [symmetric] plus)
huffman@25904
   290
done
huffman@25904
   291
huffman@25904
   292
wenzelm@62175
   293
subsection \<open>Monadic bind\<close>
huffman@25904
   294
huffman@25904
   295
definition
huffman@25904
   296
  upper_bind_basis ::
huffman@25904
   297
  "'a pd_basis \<Rightarrow> ('a \<rightarrow> 'b upper_pd) \<rightarrow> 'b upper_pd" where
huffman@25904
   298
  "upper_bind_basis = fold_pd
huffman@25904
   299
    (\<lambda>a. \<Lambda> f. f\<cdot>(Rep_compact_basis a))
huffman@41399
   300
    (\<lambda>x y. \<Lambda> f. x\<cdot>f \<union>\<sharp> y\<cdot>f)"
huffman@25904
   301
huffman@26927
   302
lemma ACI_upper_bind:
haftmann@51489
   303
  "semilattice (\<lambda>x y. \<Lambda> f. x\<cdot>f \<union>\<sharp> y\<cdot>f)"
huffman@25904
   304
apply unfold_locales
haftmann@26041
   305
apply (simp add: upper_plus_assoc)
huffman@25904
   306
apply (simp add: upper_plus_commute)
huffman@29990
   307
apply (simp add: eta_cfun)
huffman@25904
   308
done
huffman@25904
   309
huffman@25904
   310
lemma upper_bind_basis_simps [simp]:
huffman@25904
   311
  "upper_bind_basis (PDUnit a) =
huffman@25904
   312
    (\<Lambda> f. f\<cdot>(Rep_compact_basis a))"
huffman@25904
   313
  "upper_bind_basis (PDPlus t u) =
huffman@41399
   314
    (\<Lambda> f. upper_bind_basis t\<cdot>f \<union>\<sharp> upper_bind_basis u\<cdot>f)"
huffman@25904
   315
unfolding upper_bind_basis_def
huffman@25904
   316
apply -
huffman@26927
   317
apply (rule fold_pd_PDUnit [OF ACI_upper_bind])
huffman@26927
   318
apply (rule fold_pd_PDPlus [OF ACI_upper_bind])
huffman@25904
   319
done
huffman@25904
   320
huffman@25904
   321
lemma upper_bind_basis_mono:
huffman@25904
   322
  "t \<le>\<sharp> u \<Longrightarrow> upper_bind_basis t \<sqsubseteq> upper_bind_basis u"
huffman@40002
   323
unfolding cfun_below_iff
huffman@25904
   324
apply (erule upper_le_induct, safe)
huffman@27289
   325
apply (simp add: monofun_cfun)
huffman@31076
   326
apply (simp add: below_trans [OF upper_plus_below1])
huffman@40734
   327
apply simp
huffman@25904
   328
done
huffman@25904
   329
huffman@25904
   330
definition
huffman@25904
   331
  upper_bind :: "'a upper_pd \<rightarrow> ('a \<rightarrow> 'b upper_pd) \<rightarrow> 'b upper_pd" where
huffman@41394
   332
  "upper_bind = upper_pd.extension upper_bind_basis"
huffman@25904
   333
huffman@41036
   334
syntax
huffman@41036
   335
  "_upper_bind" :: "[logic, logic, logic] \<Rightarrow> logic"
huffman@41036
   336
    ("(3\<Union>\<sharp>_\<in>_./ _)" [0, 0, 10] 10)
huffman@41036
   337
huffman@41036
   338
translations
huffman@41036
   339
  "\<Union>\<sharp>x\<in>xs. e" == "CONST upper_bind\<cdot>xs\<cdot>(\<Lambda> x. e)"
huffman@41036
   340
huffman@25904
   341
lemma upper_bind_principal [simp]:
huffman@25904
   342
  "upper_bind\<cdot>(upper_principal t) = upper_bind_basis t"
huffman@25904
   343
unfolding upper_bind_def
huffman@41394
   344
apply (rule upper_pd.extension_principal)
huffman@25904
   345
apply (erule upper_bind_basis_mono)
huffman@25904
   346
done
huffman@25904
   347
huffman@25904
   348
lemma upper_bind_unit [simp]:
huffman@26927
   349
  "upper_bind\<cdot>{x}\<sharp>\<cdot>f = f\<cdot>x"
huffman@27289
   350
by (induct x rule: compact_basis.principal_induct, simp, simp)
huffman@25904
   351
huffman@25904
   352
lemma upper_bind_plus [simp]:
huffman@41399
   353
  "upper_bind\<cdot>(xs \<union>\<sharp> ys)\<cdot>f = upper_bind\<cdot>xs\<cdot>f \<union>\<sharp> upper_bind\<cdot>ys\<cdot>f"
huffman@41402
   354
by (induct xs rule: upper_pd.principal_induct, simp,
huffman@41402
   355
    induct ys rule: upper_pd.principal_induct, 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
wenzelm@62175
   365
subsection \<open>Map\<close>
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@41399
   376
  "upper_map\<cdot>f\<cdot>(xs \<union>\<sharp> ys) = upper_map\<cdot>f\<cdot>xs \<union>\<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)"
wenzelm@61169
   401
apply standard
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)"
wenzelm@61169
   408
apply standard
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
wenzelm@62175
   456
subsection \<open>Upper powerdomain is bifinite\<close>
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@41288
   464
instance upper_pd :: (bifinite) 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
wenzelm@62175
   471
subsection \<open>Join\<close>
huffman@39974
   472
huffman@39974
   473
definition
huffman@39974
   474
  upper_join :: "'a upper_pd upper_pd \<rightarrow> 'a upper_pd" where
huffman@39974
   475
  "upper_join = (\<Lambda> xss. upper_bind\<cdot>xss\<cdot>(\<Lambda> xs. xs))"
huffman@39974
   476
huffman@39974
   477
lemma upper_join_unit [simp]:
huffman@39974
   478
  "upper_join\<cdot>{xs}\<sharp> = xs"
huffman@39974
   479
unfolding upper_join_def by simp
huffman@39974
   480
huffman@39974
   481
lemma upper_join_plus [simp]:
huffman@41399
   482
  "upper_join\<cdot>(xss \<union>\<sharp> yss) = upper_join\<cdot>xss \<union>\<sharp> upper_join\<cdot>yss"
huffman@39974
   483
unfolding upper_join_def by simp
huffman@39974
   484
huffman@40577
   485
lemma upper_join_bottom [simp]: "upper_join\<cdot>\<bottom> = \<bottom>"
huffman@40577
   486
unfolding upper_join_def by simp
huffman@40577
   487
huffman@39974
   488
lemma upper_join_map_unit:
huffman@39974
   489
  "upper_join\<cdot>(upper_map\<cdot>upper_unit\<cdot>xs) = xs"
huffman@39974
   490
by (induct xs rule: upper_pd_induct, simp_all)
huffman@39974
   491
huffman@39974
   492
lemma upper_join_map_join:
huffman@39974
   493
  "upper_join\<cdot>(upper_map\<cdot>upper_join\<cdot>xsss) = upper_join\<cdot>(upper_join\<cdot>xsss)"
huffman@39974
   494
by (induct xsss rule: upper_pd_induct, simp_all)
huffman@39974
   495
huffman@39974
   496
lemma upper_join_map_map:
huffman@39974
   497
  "upper_join\<cdot>(upper_map\<cdot>(upper_map\<cdot>f)\<cdot>xss) =
huffman@39974
   498
   upper_map\<cdot>f\<cdot>(upper_join\<cdot>xss)"
huffman@39974
   499
by (induct xss rule: upper_pd_induct, simp_all)
huffman@39974
   500
huffman@39974
   501
end