src/HOLCF/UpperPD.thy
author huffman
Fri Jan 18 20:22:07 2008 +0100 (2008-01-18)
changeset 25925 3dc4acca4388
parent 25904 8161f137b0e9
child 26041 c2e15e65165f
permissions -rw-r--r--
change lemma admD to rule_format
huffman@25904
     1
(*  Title:      HOLCF/UpperPD.thy
huffman@25904
     2
    ID:         $Id$
huffman@25904
     3
    Author:     Brian Huffman
huffman@25904
     4
*)
huffman@25904
     5
huffman@25904
     6
header {* Upper powerdomain *}
huffman@25904
     7
huffman@25904
     8
theory UpperPD
huffman@25904
     9
imports CompactBasis
huffman@25904
    10
begin
huffman@25904
    11
huffman@25904
    12
subsection {* Basis preorder *}
huffman@25904
    13
huffman@25904
    14
definition
huffman@25904
    15
  upper_le :: "'a pd_basis \<Rightarrow> 'a pd_basis \<Rightarrow> bool" (infix "\<le>\<sharp>" 50) where
huffman@25904
    16
  "upper_le = (\<lambda>u v. \<forall>y\<in>Rep_pd_basis v. \<exists>x\<in>Rep_pd_basis u. compact_le x y)"
huffman@25904
    17
huffman@25904
    18
lemma upper_le_refl [simp]: "t \<le>\<sharp> t"
huffman@25904
    19
unfolding upper_le_def by (fast intro: compact_le_refl)
huffman@25904
    20
huffman@25904
    21
lemma upper_le_trans: "\<lbrakk>t \<le>\<sharp> u; u \<le>\<sharp> v\<rbrakk> \<Longrightarrow> t \<le>\<sharp> v"
huffman@25904
    22
unfolding upper_le_def
huffman@25904
    23
apply (rule ballI)
huffman@25904
    24
apply (drule (1) bspec, erule bexE)
huffman@25904
    25
apply (drule (1) bspec, erule bexE)
huffman@25904
    26
apply (erule rev_bexI)
huffman@25904
    27
apply (erule (1) compact_le_trans)
huffman@25904
    28
done
huffman@25904
    29
huffman@25904
    30
interpretation upper_le: preorder [upper_le]
huffman@25904
    31
by (rule preorder.intro, rule upper_le_refl, rule upper_le_trans)
huffman@25904
    32
huffman@25904
    33
lemma upper_le_minimal [simp]: "PDUnit compact_bot \<le>\<sharp> t"
huffman@25904
    34
unfolding upper_le_def Rep_PDUnit by simp
huffman@25904
    35
huffman@25904
    36
lemma PDUnit_upper_mono: "compact_le x y \<Longrightarrow> PDUnit x \<le>\<sharp> PDUnit y"
huffman@25904
    37
unfolding upper_le_def Rep_PDUnit by simp
huffman@25904
    38
huffman@25904
    39
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
    40
unfolding upper_le_def Rep_PDPlus by fast
huffman@25904
    41
huffman@25904
    42
lemma PDPlus_upper_less: "PDPlus t u \<le>\<sharp> t"
huffman@25904
    43
unfolding upper_le_def Rep_PDPlus by (fast intro: compact_le_refl)
huffman@25904
    44
huffman@25904
    45
lemma upper_le_PDUnit_PDUnit_iff [simp]:
huffman@25904
    46
  "(PDUnit a \<le>\<sharp> PDUnit b) = compact_le a b"
huffman@25904
    47
unfolding upper_le_def Rep_PDUnit by fast
huffman@25904
    48
huffman@25904
    49
lemma upper_le_PDPlus_PDUnit_iff:
huffman@25904
    50
  "(PDPlus t u \<le>\<sharp> PDUnit a) = (t \<le>\<sharp> PDUnit a \<or> u \<le>\<sharp> PDUnit a)"
huffman@25904
    51
unfolding upper_le_def Rep_PDPlus Rep_PDUnit by fast
huffman@25904
    52
huffman@25904
    53
lemma upper_le_PDPlus_iff: "(t \<le>\<sharp> PDPlus u v) = (t \<le>\<sharp> u \<and> t \<le>\<sharp> v)"
huffman@25904
    54
unfolding upper_le_def Rep_PDPlus by fast
huffman@25904
    55
huffman@25904
    56
lemma upper_le_induct [induct set: upper_le]:
huffman@25904
    57
  assumes le: "t \<le>\<sharp> u"
huffman@25904
    58
  assumes 1: "\<And>a b. compact_le a b \<Longrightarrow> P (PDUnit a) (PDUnit b)"
huffman@25904
    59
  assumes 2: "\<And>t u a. P t (PDUnit a) \<Longrightarrow> P (PDPlus t u) (PDUnit a)"
huffman@25904
    60
  assumes 3: "\<And>t u v. \<lbrakk>P t u; P t v\<rbrakk> \<Longrightarrow> P t (PDPlus u v)"
huffman@25904
    61
  shows "P t u"
huffman@25904
    62
using le apply (induct u arbitrary: t rule: pd_basis_induct)
huffman@25904
    63
apply (erule rev_mp)
huffman@25904
    64
apply (induct_tac t rule: pd_basis_induct)
huffman@25904
    65
apply (simp add: 1)
huffman@25904
    66
apply (simp add: upper_le_PDPlus_PDUnit_iff)
huffman@25904
    67
apply (simp add: 2)
huffman@25904
    68
apply (subst PDPlus_commute)
huffman@25904
    69
apply (simp add: 2)
huffman@25904
    70
apply (simp add: upper_le_PDPlus_iff 3)
huffman@25904
    71
done
huffman@25904
    72
huffman@25904
    73
lemma approx_pd_upper_mono1:
huffman@25904
    74
  "i \<le> j \<Longrightarrow> approx_pd i t \<le>\<sharp> approx_pd j t"
huffman@25904
    75
apply (induct t rule: pd_basis_induct)
huffman@25904
    76
apply (simp add: compact_approx_mono1)
huffman@25904
    77
apply (simp add: PDPlus_upper_mono)
huffman@25904
    78
done
huffman@25904
    79
huffman@25904
    80
lemma approx_pd_upper_le: "approx_pd i t \<le>\<sharp> t"
huffman@25904
    81
apply (induct t rule: pd_basis_induct)
huffman@25904
    82
apply (simp add: compact_approx_le)
huffman@25904
    83
apply (simp add: PDPlus_upper_mono)
huffman@25904
    84
done
huffman@25904
    85
huffman@25904
    86
lemma approx_pd_upper_mono:
huffman@25904
    87
  "t \<le>\<sharp> u \<Longrightarrow> approx_pd n t \<le>\<sharp> approx_pd n u"
huffman@25904
    88
apply (erule upper_le_induct)
huffman@25904
    89
apply (simp add: compact_approx_mono)
huffman@25904
    90
apply (simp add: upper_le_PDPlus_PDUnit_iff)
huffman@25904
    91
apply (simp add: upper_le_PDPlus_iff)
huffman@25904
    92
done
huffman@25904
    93
huffman@25904
    94
huffman@25904
    95
subsection {* Type definition *}
huffman@25904
    96
huffman@25904
    97
cpodef (open) 'a upper_pd =
huffman@25904
    98
  "{S::'a::bifinite pd_basis set. upper_le.ideal S}"
huffman@25904
    99
apply (simp add: upper_le.adm_ideal)
huffman@25904
   100
apply (fast intro: upper_le.ideal_principal)
huffman@25904
   101
done
huffman@25904
   102
huffman@25904
   103
lemma ideal_Rep_upper_pd: "upper_le.ideal (Rep_upper_pd x)"
huffman@25904
   104
by (rule Rep_upper_pd [simplified])
huffman@25904
   105
huffman@25904
   106
definition
huffman@25904
   107
  upper_principal :: "'a pd_basis \<Rightarrow> 'a upper_pd" where
huffman@25904
   108
  "upper_principal t = Abs_upper_pd {u. u \<le>\<sharp> t}"
huffman@25904
   109
huffman@25904
   110
lemma Rep_upper_principal:
huffman@25904
   111
  "Rep_upper_pd (upper_principal t) = {u. u \<le>\<sharp> t}"
huffman@25904
   112
unfolding upper_principal_def
huffman@25904
   113
apply (rule Abs_upper_pd_inverse [simplified])
huffman@25904
   114
apply (rule upper_le.ideal_principal)
huffman@25904
   115
done
huffman@25904
   116
huffman@25904
   117
interpretation upper_pd:
huffman@25904
   118
  bifinite_basis [upper_le upper_principal Rep_upper_pd approx_pd]
huffman@25904
   119
apply unfold_locales
huffman@25904
   120
apply (rule ideal_Rep_upper_pd)
huffman@25904
   121
apply (rule cont_Rep_upper_pd)
huffman@25904
   122
apply (rule Rep_upper_principal)
huffman@25904
   123
apply (simp only: less_upper_pd_def less_set_def)
huffman@25904
   124
apply (rule approx_pd_upper_le)
huffman@25904
   125
apply (rule approx_pd_idem)
huffman@25904
   126
apply (erule approx_pd_upper_mono)
huffman@25904
   127
apply (rule approx_pd_upper_mono1, simp)
huffman@25904
   128
apply (rule finite_range_approx_pd)
huffman@25904
   129
apply (rule ex_approx_pd_eq)
huffman@25904
   130
done
huffman@25904
   131
huffman@25904
   132
lemma upper_principal_less_iff [simp]:
huffman@25904
   133
  "(upper_principal t \<sqsubseteq> upper_principal u) = (t \<le>\<sharp> u)"
huffman@25904
   134
unfolding less_upper_pd_def Rep_upper_principal less_set_def
huffman@25904
   135
by (fast intro: upper_le_refl elim: upper_le_trans)
huffman@25904
   136
huffman@25904
   137
lemma upper_principal_mono:
huffman@25904
   138
  "t \<le>\<sharp> u \<Longrightarrow> upper_principal t \<sqsubseteq> upper_principal u"
huffman@25904
   139
by (rule upper_pd.principal_mono)
huffman@25904
   140
huffman@25904
   141
lemma compact_upper_principal: "compact (upper_principal t)"
huffman@25904
   142
by (rule upper_pd.compact_principal)
huffman@25904
   143
huffman@25904
   144
lemma upper_pd_minimal: "upper_principal (PDUnit compact_bot) \<sqsubseteq> ys"
huffman@25904
   145
by (induct ys rule: upper_pd.principal_induct, simp, simp)
huffman@25904
   146
huffman@25904
   147
instance upper_pd :: (bifinite) pcpo
huffman@25904
   148
by (intro_classes, fast intro: upper_pd_minimal)
huffman@25904
   149
huffman@25904
   150
lemma inst_upper_pd_pcpo: "\<bottom> = upper_principal (PDUnit compact_bot)"
huffman@25904
   151
by (rule upper_pd_minimal [THEN UU_I, symmetric])
huffman@25904
   152
huffman@25904
   153
huffman@25904
   154
subsection {* Approximation *}
huffman@25904
   155
huffman@25904
   156
instance upper_pd :: (bifinite) approx ..
huffman@25904
   157
huffman@25904
   158
defs (overloaded)
huffman@25904
   159
  approx_upper_pd_def:
huffman@25904
   160
    "approx \<equiv> (\<lambda>n. upper_pd.basis_fun (\<lambda>t. upper_principal (approx_pd n t)))"
huffman@25904
   161
huffman@25904
   162
lemma approx_upper_principal [simp]:
huffman@25904
   163
  "approx n\<cdot>(upper_principal t) = upper_principal (approx_pd n t)"
huffman@25904
   164
unfolding approx_upper_pd_def
huffman@25904
   165
apply (rule upper_pd.basis_fun_principal)
huffman@25904
   166
apply (erule upper_principal_mono [OF approx_pd_upper_mono])
huffman@25904
   167
done
huffman@25904
   168
huffman@25904
   169
lemma chain_approx_upper_pd:
huffman@25904
   170
  "chain (approx :: nat \<Rightarrow> 'a upper_pd \<rightarrow> 'a upper_pd)"
huffman@25904
   171
unfolding approx_upper_pd_def
huffman@25904
   172
by (rule upper_pd.chain_basis_fun_take)
huffman@25904
   173
huffman@25904
   174
lemma lub_approx_upper_pd:
huffman@25904
   175
  "(\<Squnion>i. approx i\<cdot>xs) = (xs::'a upper_pd)"
huffman@25904
   176
unfolding approx_upper_pd_def
huffman@25904
   177
by (rule upper_pd.lub_basis_fun_take)
huffman@25904
   178
huffman@25904
   179
lemma approx_upper_pd_idem:
huffman@25904
   180
  "approx n\<cdot>(approx n\<cdot>xs) = approx n\<cdot>(xs::'a upper_pd)"
huffman@25904
   181
apply (induct xs rule: upper_pd.principal_induct, simp)
huffman@25904
   182
apply (simp add: approx_pd_idem)
huffman@25904
   183
done
huffman@25904
   184
huffman@25904
   185
lemma approx_eq_upper_principal:
huffman@25904
   186
  "\<exists>t\<in>Rep_upper_pd xs. approx n\<cdot>xs = upper_principal (approx_pd n t)"
huffman@25904
   187
unfolding approx_upper_pd_def
huffman@25904
   188
by (rule upper_pd.basis_fun_take_eq_principal)
huffman@25904
   189
huffman@25904
   190
lemma finite_fixes_approx_upper_pd:
huffman@25904
   191
  "finite {xs::'a upper_pd. approx n\<cdot>xs = xs}"
huffman@25904
   192
unfolding approx_upper_pd_def
huffman@25904
   193
by (rule upper_pd.finite_fixes_basis_fun_take)
huffman@25904
   194
huffman@25904
   195
instance upper_pd :: (bifinite) bifinite
huffman@25904
   196
apply intro_classes
huffman@25904
   197
apply (simp add: chain_approx_upper_pd)
huffman@25904
   198
apply (rule lub_approx_upper_pd)
huffman@25904
   199
apply (rule approx_upper_pd_idem)
huffman@25904
   200
apply (rule finite_fixes_approx_upper_pd)
huffman@25904
   201
done
huffman@25904
   202
huffman@25904
   203
lemma compact_imp_upper_principal:
huffman@25904
   204
  "compact xs \<Longrightarrow> \<exists>t. xs = upper_principal t"
huffman@25904
   205
apply (drule bifinite_compact_eq_approx)
huffman@25904
   206
apply (erule exE)
huffman@25904
   207
apply (erule subst)
huffman@25904
   208
apply (cut_tac n=i and xs=xs in approx_eq_upper_principal)
huffman@25904
   209
apply fast
huffman@25904
   210
done
huffman@25904
   211
huffman@25904
   212
lemma upper_principal_induct:
huffman@25904
   213
  "\<lbrakk>adm P; \<And>t. P (upper_principal t)\<rbrakk> \<Longrightarrow> P xs"
huffman@25904
   214
apply (erule approx_induct, rename_tac xs)
huffman@25904
   215
apply (cut_tac n=n and xs=xs in approx_eq_upper_principal)
huffman@25904
   216
apply (clarify, simp)
huffman@25904
   217
done
huffman@25904
   218
huffman@25904
   219
lemma upper_principal_induct2:
huffman@25904
   220
  "\<lbrakk>\<And>ys. adm (\<lambda>xs. P xs ys); \<And>xs. adm (\<lambda>ys. P xs ys);
huffman@25904
   221
    \<And>t u. P (upper_principal t) (upper_principal u)\<rbrakk> \<Longrightarrow> P xs ys"
huffman@25904
   222
apply (rule_tac x=ys in spec)
huffman@25904
   223
apply (rule_tac xs=xs in upper_principal_induct, simp)
huffman@25904
   224
apply (rule allI, rename_tac ys)
huffman@25904
   225
apply (rule_tac xs=ys in upper_principal_induct, simp)
huffman@25904
   226
apply simp
huffman@25904
   227
done
huffman@25904
   228
huffman@25904
   229
huffman@25904
   230
subsection {* Monadic unit *}
huffman@25904
   231
huffman@25904
   232
definition
huffman@25904
   233
  upper_unit :: "'a \<rightarrow> 'a upper_pd" where
huffman@25904
   234
  "upper_unit = compact_basis.basis_fun (\<lambda>a. upper_principal (PDUnit a))"
huffman@25904
   235
huffman@25904
   236
lemma upper_unit_Rep_compact_basis [simp]:
huffman@25904
   237
  "upper_unit\<cdot>(Rep_compact_basis a) = upper_principal (PDUnit a)"
huffman@25904
   238
unfolding upper_unit_def
huffman@25904
   239
apply (rule compact_basis.basis_fun_principal)
huffman@25904
   240
apply (rule upper_principal_mono)
huffman@25904
   241
apply (erule PDUnit_upper_mono)
huffman@25904
   242
done
huffman@25904
   243
huffman@25904
   244
lemma upper_unit_strict [simp]: "upper_unit\<cdot>\<bottom> = \<bottom>"
huffman@25904
   245
unfolding inst_upper_pd_pcpo Rep_compact_bot [symmetric] by simp
huffman@25904
   246
huffman@25904
   247
lemma approx_upper_unit [simp]:
huffman@25904
   248
  "approx n\<cdot>(upper_unit\<cdot>x) = upper_unit\<cdot>(approx n\<cdot>x)"
huffman@25904
   249
apply (induct x rule: compact_basis_induct, simp)
huffman@25904
   250
apply (simp add: approx_Rep_compact_basis)
huffman@25904
   251
done
huffman@25904
   252
huffman@25904
   253
lemma upper_unit_less_iff [simp]:
huffman@25904
   254
  "(upper_unit\<cdot>x \<sqsubseteq> upper_unit\<cdot>y) = (x \<sqsubseteq> y)"
huffman@25904
   255
 apply (rule iffI)
huffman@25904
   256
  apply (rule bifinite_less_ext)
huffman@25904
   257
  apply (drule_tac f="approx i" in monofun_cfun_arg, simp)
huffman@25904
   258
  apply (cut_tac x="approx i\<cdot>x" in compact_imp_Rep_compact_basis, simp)
huffman@25904
   259
  apply (cut_tac x="approx i\<cdot>y" in compact_imp_Rep_compact_basis, simp)
huffman@25904
   260
  apply (clarify, simp add: compact_le_def)
huffman@25904
   261
 apply (erule monofun_cfun_arg)
huffman@25904
   262
done
huffman@25904
   263
huffman@25904
   264
lemma upper_unit_eq_iff [simp]:
huffman@25904
   265
  "(upper_unit\<cdot>x = upper_unit\<cdot>y) = (x = y)"
huffman@25904
   266
unfolding po_eq_conv by simp
huffman@25904
   267
huffman@25904
   268
lemma upper_unit_strict_iff [simp]: "(upper_unit\<cdot>x = \<bottom>) = (x = \<bottom>)"
huffman@25904
   269
unfolding upper_unit_strict [symmetric] by (rule upper_unit_eq_iff)
huffman@25904
   270
huffman@25904
   271
lemma compact_upper_unit_iff [simp]:
huffman@25904
   272
  "compact (upper_unit\<cdot>x) = compact x"
huffman@25904
   273
unfolding bifinite_compact_iff by simp
huffman@25904
   274
huffman@25904
   275
huffman@25904
   276
subsection {* Monadic plus *}
huffman@25904
   277
huffman@25904
   278
definition
huffman@25904
   279
  upper_plus :: "'a upper_pd \<rightarrow> 'a upper_pd \<rightarrow> 'a upper_pd" where
huffman@25904
   280
  "upper_plus = upper_pd.basis_fun (\<lambda>t. upper_pd.basis_fun (\<lambda>u.
huffman@25904
   281
      upper_principal (PDPlus t u)))"
huffman@25904
   282
huffman@25904
   283
abbreviation
huffman@25904
   284
  upper_add :: "'a upper_pd \<Rightarrow> 'a upper_pd \<Rightarrow> 'a upper_pd"
huffman@25904
   285
    (infixl "+\<sharp>" 65) where
huffman@25904
   286
  "xs +\<sharp> ys == upper_plus\<cdot>xs\<cdot>ys"
huffman@25904
   287
huffman@25904
   288
lemma upper_plus_principal [simp]:
huffman@25904
   289
  "upper_plus\<cdot>(upper_principal t)\<cdot>(upper_principal u) =
huffman@25904
   290
   upper_principal (PDPlus t u)"
huffman@25904
   291
unfolding upper_plus_def
huffman@25904
   292
by (simp add: upper_pd.basis_fun_principal
huffman@25904
   293
    upper_pd.basis_fun_mono PDPlus_upper_mono)
huffman@25904
   294
huffman@25904
   295
lemma approx_upper_plus [simp]:
huffman@25904
   296
  "approx n\<cdot>(upper_plus\<cdot>xs\<cdot>ys) = upper_plus\<cdot>(approx n\<cdot>xs)\<cdot>(approx n\<cdot>ys)"
huffman@25904
   297
by (induct xs ys rule: upper_principal_induct2, simp, simp, simp)
huffman@25904
   298
huffman@25904
   299
lemma upper_plus_commute: "upper_plus\<cdot>xs\<cdot>ys = upper_plus\<cdot>ys\<cdot>xs"
huffman@25904
   300
apply (induct xs ys rule: upper_principal_induct2, simp, simp)
huffman@25904
   301
apply (simp add: PDPlus_commute)
huffman@25904
   302
done
huffman@25904
   303
huffman@25904
   304
lemma upper_plus_assoc:
huffman@25904
   305
  "upper_plus\<cdot>(upper_plus\<cdot>xs\<cdot>ys)\<cdot>zs = upper_plus\<cdot>xs\<cdot>(upper_plus\<cdot>ys\<cdot>zs)"
huffman@25904
   306
apply (induct xs ys arbitrary: zs rule: upper_principal_induct2, simp, simp)
huffman@25904
   307
apply (rule_tac xs=zs in upper_principal_induct, simp)
huffman@25904
   308
apply (simp add: PDPlus_assoc)
huffman@25904
   309
done
huffman@25904
   310
huffman@25904
   311
lemma upper_plus_absorb: "upper_plus\<cdot>xs\<cdot>xs = xs"
huffman@25904
   312
apply (induct xs rule: upper_principal_induct, simp)
huffman@25904
   313
apply (simp add: PDPlus_absorb)
huffman@25904
   314
done
huffman@25904
   315
huffman@25904
   316
lemma upper_plus_less1: "upper_plus\<cdot>xs\<cdot>ys \<sqsubseteq> xs"
huffman@25904
   317
apply (induct xs ys rule: upper_principal_induct2, simp, simp)
huffman@25904
   318
apply (simp add: PDPlus_upper_less)
huffman@25904
   319
done
huffman@25904
   320
huffman@25904
   321
lemma upper_plus_less2: "upper_plus\<cdot>xs\<cdot>ys \<sqsubseteq> ys"
huffman@25904
   322
by (subst upper_plus_commute, rule upper_plus_less1)
huffman@25904
   323
huffman@25904
   324
lemma upper_plus_greatest: "\<lbrakk>xs \<sqsubseteq> ys; xs \<sqsubseteq> zs\<rbrakk> \<Longrightarrow> xs \<sqsubseteq> upper_plus\<cdot>ys\<cdot>zs"
huffman@25904
   325
apply (subst upper_plus_absorb [of xs, symmetric])
huffman@25904
   326
apply (erule (1) monofun_cfun [OF monofun_cfun_arg])
huffman@25904
   327
done
huffman@25904
   328
huffman@25904
   329
lemma upper_less_plus_iff:
huffman@25904
   330
  "(xs \<sqsubseteq> upper_plus\<cdot>ys\<cdot>zs) = (xs \<sqsubseteq> ys \<and> xs \<sqsubseteq> zs)"
huffman@25904
   331
apply safe
huffman@25904
   332
apply (erule trans_less [OF _ upper_plus_less1])
huffman@25904
   333
apply (erule trans_less [OF _ upper_plus_less2])
huffman@25904
   334
apply (erule (1) upper_plus_greatest)
huffman@25904
   335
done
huffman@25904
   336
huffman@25904
   337
lemma upper_plus_strict1 [simp]: "upper_plus\<cdot>\<bottom>\<cdot>ys = \<bottom>"
huffman@25904
   338
by (rule UU_I, rule upper_plus_less1)
huffman@25904
   339
huffman@25904
   340
lemma upper_plus_strict2 [simp]: "upper_plus\<cdot>xs\<cdot>\<bottom> = \<bottom>"
huffman@25904
   341
by (rule UU_I, rule upper_plus_less2)
huffman@25904
   342
huffman@25904
   343
lemma upper_plus_less_unit_iff:
huffman@25904
   344
  "(upper_plus\<cdot>xs\<cdot>ys \<sqsubseteq> upper_unit\<cdot>z) =
huffman@25904
   345
    (xs \<sqsubseteq> upper_unit\<cdot>z \<or> ys \<sqsubseteq> upper_unit\<cdot>z)"
huffman@25904
   346
 apply (rule iffI)
huffman@25904
   347
  apply (subgoal_tac
huffman@25904
   348
    "adm (\<lambda>f. f\<cdot>xs \<sqsubseteq> f\<cdot>(upper_unit\<cdot>z) \<or> f\<cdot>ys \<sqsubseteq> f\<cdot>(upper_unit\<cdot>z))")
huffman@25925
   349
   apply (drule admD, rule chain_approx)
huffman@25904
   350
    apply (drule_tac f="approx i" in monofun_cfun_arg)
huffman@25904
   351
    apply (cut_tac xs="approx i\<cdot>xs" in compact_imp_upper_principal, simp)
huffman@25904
   352
    apply (cut_tac xs="approx i\<cdot>ys" in compact_imp_upper_principal, simp)
huffman@25904
   353
    apply (cut_tac x="approx i\<cdot>z" in compact_imp_Rep_compact_basis, simp)
huffman@25904
   354
    apply (clarify, simp add: upper_le_PDPlus_PDUnit_iff)
huffman@25904
   355
   apply simp
huffman@25904
   356
  apply simp
huffman@25904
   357
 apply (erule disjE)
huffman@25904
   358
  apply (erule trans_less [OF upper_plus_less1])
huffman@25904
   359
 apply (erule trans_less [OF upper_plus_less2])
huffman@25904
   360
done
huffman@25904
   361
huffman@25904
   362
lemmas upper_pd_less_simps =
huffman@25904
   363
  upper_unit_less_iff
huffman@25904
   364
  upper_less_plus_iff
huffman@25904
   365
  upper_plus_less_unit_iff
huffman@25904
   366
huffman@25904
   367
huffman@25904
   368
subsection {* Induction rules *}
huffman@25904
   369
huffman@25904
   370
lemma upper_pd_induct1:
huffman@25904
   371
  assumes P: "adm P"
huffman@25904
   372
  assumes unit: "\<And>x. P (upper_unit\<cdot>x)"
huffman@25904
   373
  assumes insert:
huffman@25904
   374
    "\<And>x ys. \<lbrakk>P (upper_unit\<cdot>x); P ys\<rbrakk> \<Longrightarrow> P (upper_plus\<cdot>(upper_unit\<cdot>x)\<cdot>ys)"
huffman@25904
   375
  shows "P (xs::'a upper_pd)"
huffman@25904
   376
apply (induct xs rule: upper_principal_induct, rule P)
huffman@25904
   377
apply (induct_tac t rule: pd_basis_induct1)
huffman@25904
   378
apply (simp only: upper_unit_Rep_compact_basis [symmetric])
huffman@25904
   379
apply (rule unit)
huffman@25904
   380
apply (simp only: upper_unit_Rep_compact_basis [symmetric]
huffman@25904
   381
                  upper_plus_principal [symmetric])
huffman@25904
   382
apply (erule insert [OF unit])
huffman@25904
   383
done
huffman@25904
   384
huffman@25904
   385
lemma upper_pd_induct:
huffman@25904
   386
  assumes P: "adm P"
huffman@25904
   387
  assumes unit: "\<And>x. P (upper_unit\<cdot>x)"
huffman@25904
   388
  assumes plus: "\<And>xs ys. \<lbrakk>P xs; P ys\<rbrakk> \<Longrightarrow> P (upper_plus\<cdot>xs\<cdot>ys)"
huffman@25904
   389
  shows "P (xs::'a upper_pd)"
huffman@25904
   390
apply (induct xs rule: upper_principal_induct, rule P)
huffman@25904
   391
apply (induct_tac t rule: pd_basis_induct)
huffman@25904
   392
apply (simp only: upper_unit_Rep_compact_basis [symmetric] unit)
huffman@25904
   393
apply (simp only: upper_plus_principal [symmetric] plus)
huffman@25904
   394
done
huffman@25904
   395
huffman@25904
   396
huffman@25904
   397
subsection {* Monadic bind *}
huffman@25904
   398
huffman@25904
   399
definition
huffman@25904
   400
  upper_bind_basis ::
huffman@25904
   401
  "'a pd_basis \<Rightarrow> ('a \<rightarrow> 'b upper_pd) \<rightarrow> 'b upper_pd" where
huffman@25904
   402
  "upper_bind_basis = fold_pd
huffman@25904
   403
    (\<lambda>a. \<Lambda> f. f\<cdot>(Rep_compact_basis a))
huffman@25904
   404
    (\<lambda>x y. \<Lambda> f. upper_plus\<cdot>(x\<cdot>f)\<cdot>(y\<cdot>f))"
huffman@25904
   405
huffman@25904
   406
lemma ACI_upper_bind: "ACIf (\<lambda>x y. \<Lambda> f. upper_plus\<cdot>(x\<cdot>f)\<cdot>(y\<cdot>f))"
huffman@25904
   407
apply unfold_locales
huffman@25904
   408
apply (simp add: upper_plus_commute)
huffman@25904
   409
apply (simp add: upper_plus_assoc)
huffman@25904
   410
apply (simp add: upper_plus_absorb eta_cfun)
huffman@25904
   411
done
huffman@25904
   412
huffman@25904
   413
lemma upper_bind_basis_simps [simp]:
huffman@25904
   414
  "upper_bind_basis (PDUnit a) =
huffman@25904
   415
    (\<Lambda> f. f\<cdot>(Rep_compact_basis a))"
huffman@25904
   416
  "upper_bind_basis (PDPlus t u) =
huffman@25904
   417
    (\<Lambda> f. upper_plus\<cdot>(upper_bind_basis t\<cdot>f)\<cdot>(upper_bind_basis u\<cdot>f))"
huffman@25904
   418
unfolding upper_bind_basis_def
huffman@25904
   419
apply -
huffman@25904
   420
apply (rule ACIf.fold_pd_PDUnit [OF ACI_upper_bind])
huffman@25904
   421
apply (rule ACIf.fold_pd_PDPlus [OF ACI_upper_bind])
huffman@25904
   422
done
huffman@25904
   423
huffman@25904
   424
lemma upper_bind_basis_mono:
huffman@25904
   425
  "t \<le>\<sharp> u \<Longrightarrow> upper_bind_basis t \<sqsubseteq> upper_bind_basis u"
huffman@25904
   426
unfolding expand_cfun_less
huffman@25904
   427
apply (erule upper_le_induct, safe)
huffman@25904
   428
apply (simp add: compact_le_def monofun_cfun)
huffman@25904
   429
apply (simp add: trans_less [OF upper_plus_less1])
huffman@25904
   430
apply (simp add: upper_less_plus_iff)
huffman@25904
   431
done
huffman@25904
   432
huffman@25904
   433
definition
huffman@25904
   434
  upper_bind :: "'a upper_pd \<rightarrow> ('a \<rightarrow> 'b upper_pd) \<rightarrow> 'b upper_pd" where
huffman@25904
   435
  "upper_bind = upper_pd.basis_fun upper_bind_basis"
huffman@25904
   436
huffman@25904
   437
lemma upper_bind_principal [simp]:
huffman@25904
   438
  "upper_bind\<cdot>(upper_principal t) = upper_bind_basis t"
huffman@25904
   439
unfolding upper_bind_def
huffman@25904
   440
apply (rule upper_pd.basis_fun_principal)
huffman@25904
   441
apply (erule upper_bind_basis_mono)
huffman@25904
   442
done
huffman@25904
   443
huffman@25904
   444
lemma upper_bind_unit [simp]:
huffman@25904
   445
  "upper_bind\<cdot>(upper_unit\<cdot>x)\<cdot>f = f\<cdot>x"
huffman@25904
   446
by (induct x rule: compact_basis_induct, simp, simp)
huffman@25904
   447
huffman@25904
   448
lemma upper_bind_plus [simp]:
huffman@25904
   449
  "upper_bind\<cdot>(upper_plus\<cdot>xs\<cdot>ys)\<cdot>f =
huffman@25904
   450
   upper_plus\<cdot>(upper_bind\<cdot>xs\<cdot>f)\<cdot>(upper_bind\<cdot>ys\<cdot>f)"
huffman@25904
   451
by (induct xs ys rule: upper_principal_induct2, simp, simp, simp)
huffman@25904
   452
huffman@25904
   453
lemma upper_bind_strict [simp]: "upper_bind\<cdot>\<bottom>\<cdot>f = f\<cdot>\<bottom>"
huffman@25904
   454
unfolding upper_unit_strict [symmetric] by (rule upper_bind_unit)
huffman@25904
   455
huffman@25904
   456
huffman@25904
   457
subsection {* Map and join *}
huffman@25904
   458
huffman@25904
   459
definition
huffman@25904
   460
  upper_map :: "('a \<rightarrow> 'b) \<rightarrow> 'a upper_pd \<rightarrow> 'b upper_pd" where
huffman@25904
   461
  "upper_map = (\<Lambda> f xs. upper_bind\<cdot>xs\<cdot>(\<Lambda> x. upper_unit\<cdot>(f\<cdot>x)))"
huffman@25904
   462
huffman@25904
   463
definition
huffman@25904
   464
  upper_join :: "'a upper_pd upper_pd \<rightarrow> 'a upper_pd" where
huffman@25904
   465
  "upper_join = (\<Lambda> xss. upper_bind\<cdot>xss\<cdot>(\<Lambda> xs. xs))"
huffman@25904
   466
huffman@25904
   467
lemma upper_map_unit [simp]:
huffman@25904
   468
  "upper_map\<cdot>f\<cdot>(upper_unit\<cdot>x) = upper_unit\<cdot>(f\<cdot>x)"
huffman@25904
   469
unfolding upper_map_def by simp
huffman@25904
   470
huffman@25904
   471
lemma upper_map_plus [simp]:
huffman@25904
   472
  "upper_map\<cdot>f\<cdot>(upper_plus\<cdot>xs\<cdot>ys) =
huffman@25904
   473
   upper_plus\<cdot>(upper_map\<cdot>f\<cdot>xs)\<cdot>(upper_map\<cdot>f\<cdot>ys)"
huffman@25904
   474
unfolding upper_map_def by simp
huffman@25904
   475
huffman@25904
   476
lemma upper_join_unit [simp]:
huffman@25904
   477
  "upper_join\<cdot>(upper_unit\<cdot>xs) = xs"
huffman@25904
   478
unfolding upper_join_def by simp
huffman@25904
   479
huffman@25904
   480
lemma upper_join_plus [simp]:
huffman@25904
   481
  "upper_join\<cdot>(upper_plus\<cdot>xss\<cdot>yss) =
huffman@25904
   482
   upper_plus\<cdot>(upper_join\<cdot>xss)\<cdot>(upper_join\<cdot>yss)"
huffman@25904
   483
unfolding upper_join_def by simp
huffman@25904
   484
huffman@25904
   485
lemma upper_map_ident: "upper_map\<cdot>(\<Lambda> x. x)\<cdot>xs = xs"
huffman@25904
   486
by (induct xs rule: upper_pd_induct, simp_all)
huffman@25904
   487
huffman@25904
   488
lemma upper_map_map:
huffman@25904
   489
  "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
   490
by (induct xs rule: upper_pd_induct, simp_all)
huffman@25904
   491
huffman@25904
   492
lemma upper_join_map_unit:
huffman@25904
   493
  "upper_join\<cdot>(upper_map\<cdot>upper_unit\<cdot>xs) = xs"
huffman@25904
   494
by (induct xs rule: upper_pd_induct, simp_all)
huffman@25904
   495
huffman@25904
   496
lemma upper_join_map_join:
huffman@25904
   497
  "upper_join\<cdot>(upper_map\<cdot>upper_join\<cdot>xsss) = upper_join\<cdot>(upper_join\<cdot>xsss)"
huffman@25904
   498
by (induct xsss rule: upper_pd_induct, simp_all)
huffman@25904
   499
huffman@25904
   500
lemma upper_join_map_map:
huffman@25904
   501
  "upper_join\<cdot>(upper_map\<cdot>(upper_map\<cdot>f)\<cdot>xss) =
huffman@25904
   502
   upper_map\<cdot>f\<cdot>(upper_join\<cdot>xss)"
huffman@25904
   503
by (induct xss rule: upper_pd_induct, simp_all)
huffman@25904
   504
huffman@25904
   505
lemma upper_map_approx: "upper_map\<cdot>(approx n)\<cdot>xs = approx n\<cdot>xs"
huffman@25904
   506
by (induct xs rule: upper_pd_induct, simp_all)
huffman@25904
   507
huffman@25904
   508
end