src/HOLCF/LowerPD.thy
author huffman
Mon Jan 14 19:26:41 2008 +0100 (2008-01-14)
changeset 25904 8161f137b0e9
child 25925 3dc4acca4388
permissions -rw-r--r--
new theory of powerdomains
huffman@25904
     1
(*  Title:      HOLCF/LowerPD.thy
huffman@25904
     2
    ID:         $Id$
huffman@25904
     3
    Author:     Brian Huffman
huffman@25904
     4
*)
huffman@25904
     5
huffman@25904
     6
header {* Lower powerdomain *}
huffman@25904
     7
huffman@25904
     8
theory LowerPD
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
  lower_le :: "'a pd_basis \<Rightarrow> 'a pd_basis \<Rightarrow> bool" (infix "\<le>\<flat>" 50) where
huffman@25904
    16
  "lower_le = (\<lambda>u v. \<forall>x\<in>Rep_pd_basis u. \<exists>y\<in>Rep_pd_basis v. compact_le x y)"
huffman@25904
    17
huffman@25904
    18
lemma lower_le_refl [simp]: "t \<le>\<flat> t"
huffman@25904
    19
unfolding lower_le_def by (fast intro: compact_le_refl)
huffman@25904
    20
huffman@25904
    21
lemma lower_le_trans: "\<lbrakk>t \<le>\<flat> u; u \<le>\<flat> v\<rbrakk> \<Longrightarrow> t \<le>\<flat> v"
huffman@25904
    22
unfolding lower_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 lower_le: preorder [lower_le]
huffman@25904
    31
by (rule preorder.intro, rule lower_le_refl, rule lower_le_trans)
huffman@25904
    32
huffman@25904
    33
lemma lower_le_minimal [simp]: "PDUnit compact_bot \<le>\<flat> t"
huffman@25904
    34
unfolding lower_le_def Rep_PDUnit
huffman@25904
    35
by (simp, rule Rep_pd_basis_nonempty [folded ex_in_conv])
huffman@25904
    36
huffman@25904
    37
lemma PDUnit_lower_mono: "compact_le x y \<Longrightarrow> PDUnit x \<le>\<flat> PDUnit y"
huffman@25904
    38
unfolding lower_le_def Rep_PDUnit by fast
huffman@25904
    39
huffman@25904
    40
lemma PDPlus_lower_mono: "\<lbrakk>s \<le>\<flat> t; u \<le>\<flat> v\<rbrakk> \<Longrightarrow> PDPlus s u \<le>\<flat> PDPlus t v"
huffman@25904
    41
unfolding lower_le_def Rep_PDPlus by fast
huffman@25904
    42
huffman@25904
    43
lemma PDPlus_lower_less: "t \<le>\<flat> PDPlus t u"
huffman@25904
    44
unfolding lower_le_def Rep_PDPlus by (fast intro: compact_le_refl)
huffman@25904
    45
huffman@25904
    46
lemma lower_le_PDUnit_PDUnit_iff [simp]:
huffman@25904
    47
  "(PDUnit a \<le>\<flat> PDUnit b) = compact_le a b"
huffman@25904
    48
unfolding lower_le_def Rep_PDUnit by fast
huffman@25904
    49
huffman@25904
    50
lemma lower_le_PDUnit_PDPlus_iff:
huffman@25904
    51
  "(PDUnit a \<le>\<flat> PDPlus t u) = (PDUnit a \<le>\<flat> t \<or> PDUnit a \<le>\<flat> u)"
huffman@25904
    52
unfolding lower_le_def Rep_PDPlus Rep_PDUnit by fast
huffman@25904
    53
huffman@25904
    54
lemma lower_le_PDPlus_iff: "(PDPlus t u \<le>\<flat> v) = (t \<le>\<flat> v \<and> u \<le>\<flat> v)"
huffman@25904
    55
unfolding lower_le_def Rep_PDPlus by fast
huffman@25904
    56
huffman@25904
    57
lemma lower_le_induct [induct set: lower_le]:
huffman@25904
    58
  assumes le: "t \<le>\<flat> u"
huffman@25904
    59
  assumes 1: "\<And>a b. compact_le a b \<Longrightarrow> P (PDUnit a) (PDUnit b)"
huffman@25904
    60
  assumes 2: "\<And>t u a. P (PDUnit a) t \<Longrightarrow> P (PDUnit a) (PDPlus t u)"
huffman@25904
    61
  assumes 3: "\<And>t u v. \<lbrakk>P t v; P u v\<rbrakk> \<Longrightarrow> P (PDPlus t u) v"
huffman@25904
    62
  shows "P t u"
huffman@25904
    63
using le
huffman@25904
    64
apply (induct t arbitrary: u rule: pd_basis_induct)
huffman@25904
    65
apply (erule rev_mp)
huffman@25904
    66
apply (induct_tac u rule: pd_basis_induct)
huffman@25904
    67
apply (simp add: 1)
huffman@25904
    68
apply (simp add: lower_le_PDUnit_PDPlus_iff)
huffman@25904
    69
apply (simp add: 2)
huffman@25904
    70
apply (subst PDPlus_commute)
huffman@25904
    71
apply (simp add: 2)
huffman@25904
    72
apply (simp add: lower_le_PDPlus_iff 3)
huffman@25904
    73
done
huffman@25904
    74
huffman@25904
    75
lemma approx_pd_lower_mono1:
huffman@25904
    76
  "i \<le> j \<Longrightarrow> approx_pd i t \<le>\<flat> approx_pd j t"
huffman@25904
    77
apply (induct t rule: pd_basis_induct)
huffman@25904
    78
apply (simp add: compact_approx_mono1)
huffman@25904
    79
apply (simp add: PDPlus_lower_mono)
huffman@25904
    80
done
huffman@25904
    81
huffman@25904
    82
lemma approx_pd_lower_le: "approx_pd i t \<le>\<flat> t"
huffman@25904
    83
apply (induct t rule: pd_basis_induct)
huffman@25904
    84
apply (simp add: compact_approx_le)
huffman@25904
    85
apply (simp add: PDPlus_lower_mono)
huffman@25904
    86
done
huffman@25904
    87
huffman@25904
    88
lemma approx_pd_lower_mono:
huffman@25904
    89
  "t \<le>\<flat> u \<Longrightarrow> approx_pd n t \<le>\<flat> approx_pd n u"
huffman@25904
    90
apply (erule lower_le_induct)
huffman@25904
    91
apply (simp add: compact_approx_mono)
huffman@25904
    92
apply (simp add: lower_le_PDUnit_PDPlus_iff)
huffman@25904
    93
apply (simp add: lower_le_PDPlus_iff)
huffman@25904
    94
done
huffman@25904
    95
huffman@25904
    96
huffman@25904
    97
subsection {* Type definition *}
huffman@25904
    98
huffman@25904
    99
cpodef (open) 'a lower_pd =
huffman@25904
   100
  "{S::'a::bifinite pd_basis set. lower_le.ideal S}"
huffman@25904
   101
apply (simp add: lower_le.adm_ideal)
huffman@25904
   102
apply (fast intro: lower_le.ideal_principal)
huffman@25904
   103
done
huffman@25904
   104
huffman@25904
   105
lemma ideal_Rep_lower_pd: "lower_le.ideal (Rep_lower_pd x)"
huffman@25904
   106
by (rule Rep_lower_pd [simplified])
huffman@25904
   107
huffman@25904
   108
lemma Rep_lower_pd_mono: "x \<sqsubseteq> y \<Longrightarrow> Rep_lower_pd x \<subseteq> Rep_lower_pd y"
huffman@25904
   109
unfolding less_lower_pd_def less_set_def .
huffman@25904
   110
huffman@25904
   111
huffman@25904
   112
subsection {* Principal ideals *}
huffman@25904
   113
huffman@25904
   114
definition
huffman@25904
   115
  lower_principal :: "'a pd_basis \<Rightarrow> 'a lower_pd" where
huffman@25904
   116
  "lower_principal t = Abs_lower_pd {u. u \<le>\<flat> t}"
huffman@25904
   117
huffman@25904
   118
lemma Rep_lower_principal:
huffman@25904
   119
  "Rep_lower_pd (lower_principal t) = {u. u \<le>\<flat> t}"
huffman@25904
   120
unfolding lower_principal_def
huffman@25904
   121
apply (rule Abs_lower_pd_inverse [simplified])
huffman@25904
   122
apply (rule lower_le.ideal_principal)
huffman@25904
   123
done
huffman@25904
   124
huffman@25904
   125
interpretation lower_pd:
huffman@25904
   126
  bifinite_basis [lower_le lower_principal Rep_lower_pd approx_pd]
huffman@25904
   127
apply unfold_locales
huffman@25904
   128
apply (rule ideal_Rep_lower_pd)
huffman@25904
   129
apply (rule cont_Rep_lower_pd)
huffman@25904
   130
apply (rule Rep_lower_principal)
huffman@25904
   131
apply (simp only: less_lower_pd_def less_set_def)
huffman@25904
   132
apply (rule approx_pd_lower_le)
huffman@25904
   133
apply (rule approx_pd_idem)
huffman@25904
   134
apply (erule approx_pd_lower_mono)
huffman@25904
   135
apply (rule approx_pd_lower_mono1, simp)
huffman@25904
   136
apply (rule finite_range_approx_pd)
huffman@25904
   137
apply (rule ex_approx_pd_eq)
huffman@25904
   138
done
huffman@25904
   139
huffman@25904
   140
lemma lower_principal_less_iff [simp]:
huffman@25904
   141
  "(lower_principal t \<sqsubseteq> lower_principal u) = (t \<le>\<flat> u)"
huffman@25904
   142
unfolding less_lower_pd_def Rep_lower_principal less_set_def
huffman@25904
   143
by (fast intro: lower_le_refl elim: lower_le_trans)
huffman@25904
   144
huffman@25904
   145
lemma lower_principal_mono:
huffman@25904
   146
  "t \<le>\<flat> u \<Longrightarrow> lower_principal t \<sqsubseteq> lower_principal u"
huffman@25904
   147
by (rule lower_principal_less_iff [THEN iffD2])
huffman@25904
   148
huffman@25904
   149
lemma compact_lower_principal: "compact (lower_principal t)"
huffman@25904
   150
apply (rule compactI2)
huffman@25904
   151
apply (simp add: less_lower_pd_def)
huffman@25904
   152
apply (simp add: cont2contlubE [OF cont_Rep_lower_pd])
huffman@25904
   153
apply (simp add: Rep_lower_principal set_cpo_simps)
huffman@25904
   154
apply (simp add: subset_def)
huffman@25904
   155
apply (drule spec, drule mp, rule lower_le_refl)
huffman@25904
   156
apply (erule exE, rename_tac i)
huffman@25904
   157
apply (rule_tac x=i in exI)
huffman@25904
   158
apply clarify
huffman@25904
   159
apply (erule (1) lower_le.idealD3 [OF ideal_Rep_lower_pd])
huffman@25904
   160
done
huffman@25904
   161
huffman@25904
   162
lemma lower_pd_minimal: "lower_principal (PDUnit compact_bot) \<sqsubseteq> ys"
huffman@25904
   163
by (induct ys rule: lower_pd.principal_induct, simp, simp)
huffman@25904
   164
huffman@25904
   165
instance lower_pd :: (bifinite) pcpo
huffman@25904
   166
by (intro_classes, fast intro: lower_pd_minimal)
huffman@25904
   167
huffman@25904
   168
lemma inst_lower_pd_pcpo: "\<bottom> = lower_principal (PDUnit compact_bot)"
huffman@25904
   169
by (rule lower_pd_minimal [THEN UU_I, symmetric])
huffman@25904
   170
huffman@25904
   171
huffman@25904
   172
subsection {* Approximation *}
huffman@25904
   173
huffman@25904
   174
instance lower_pd :: (bifinite) approx ..
huffman@25904
   175
huffman@25904
   176
defs (overloaded)
huffman@25904
   177
  approx_lower_pd_def:
huffman@25904
   178
    "approx \<equiv> (\<lambda>n. lower_pd.basis_fun (\<lambda>t. lower_principal (approx_pd n t)))"
huffman@25904
   179
huffman@25904
   180
lemma approx_lower_principal [simp]:
huffman@25904
   181
  "approx n\<cdot>(lower_principal t) = lower_principal (approx_pd n t)"
huffman@25904
   182
unfolding approx_lower_pd_def
huffman@25904
   183
apply (rule lower_pd.basis_fun_principal)
huffman@25904
   184
apply (erule lower_principal_mono [OF approx_pd_lower_mono])
huffman@25904
   185
done
huffman@25904
   186
huffman@25904
   187
lemma chain_approx_lower_pd:
huffman@25904
   188
  "chain (approx :: nat \<Rightarrow> 'a lower_pd \<rightarrow> 'a lower_pd)"
huffman@25904
   189
unfolding approx_lower_pd_def
huffman@25904
   190
by (rule lower_pd.chain_basis_fun_take)
huffman@25904
   191
huffman@25904
   192
lemma lub_approx_lower_pd:
huffman@25904
   193
  "(\<Squnion>i. approx i\<cdot>xs) = (xs::'a lower_pd)"
huffman@25904
   194
unfolding approx_lower_pd_def
huffman@25904
   195
by (rule lower_pd.lub_basis_fun_take)
huffman@25904
   196
huffman@25904
   197
lemma approx_lower_pd_idem:
huffman@25904
   198
  "approx n\<cdot>(approx n\<cdot>xs) = approx n\<cdot>(xs::'a lower_pd)"
huffman@25904
   199
apply (induct xs rule: lower_pd.principal_induct, simp)
huffman@25904
   200
apply (simp add: approx_pd_idem)
huffman@25904
   201
done
huffman@25904
   202
huffman@25904
   203
lemma approx_eq_lower_principal:
huffman@25904
   204
  "\<exists>t\<in>Rep_lower_pd xs. approx n\<cdot>xs = lower_principal (approx_pd n t)"
huffman@25904
   205
unfolding approx_lower_pd_def
huffman@25904
   206
by (rule lower_pd.basis_fun_take_eq_principal)
huffman@25904
   207
huffman@25904
   208
lemma finite_fixes_approx_lower_pd:
huffman@25904
   209
  "finite {xs::'a lower_pd. approx n\<cdot>xs = xs}"
huffman@25904
   210
unfolding approx_lower_pd_def
huffman@25904
   211
by (rule lower_pd.finite_fixes_basis_fun_take)
huffman@25904
   212
huffman@25904
   213
instance lower_pd :: (bifinite) bifinite
huffman@25904
   214
apply intro_classes
huffman@25904
   215
apply (simp add: chain_approx_lower_pd)
huffman@25904
   216
apply (rule lub_approx_lower_pd)
huffman@25904
   217
apply (rule approx_lower_pd_idem)
huffman@25904
   218
apply (rule finite_fixes_approx_lower_pd)
huffman@25904
   219
done
huffman@25904
   220
huffman@25904
   221
lemma compact_imp_lower_principal:
huffman@25904
   222
  "compact xs \<Longrightarrow> \<exists>t. xs = lower_principal t"
huffman@25904
   223
apply (drule bifinite_compact_eq_approx)
huffman@25904
   224
apply (erule exE)
huffman@25904
   225
apply (erule subst)
huffman@25904
   226
apply (cut_tac n=i and xs=xs in approx_eq_lower_principal)
huffman@25904
   227
apply fast
huffman@25904
   228
done
huffman@25904
   229
huffman@25904
   230
lemma lower_principal_induct:
huffman@25904
   231
  "\<lbrakk>adm P; \<And>t. P (lower_principal t)\<rbrakk> \<Longrightarrow> P xs"
huffman@25904
   232
apply (erule approx_induct, rename_tac xs)
huffman@25904
   233
apply (cut_tac n=n and xs=xs in approx_eq_lower_principal)
huffman@25904
   234
apply (clarify, simp)
huffman@25904
   235
done
huffman@25904
   236
huffman@25904
   237
lemma lower_principal_induct2:
huffman@25904
   238
  "\<lbrakk>\<And>ys. adm (\<lambda>xs. P xs ys); \<And>xs. adm (\<lambda>ys. P xs ys);
huffman@25904
   239
    \<And>t u. P (lower_principal t) (lower_principal u)\<rbrakk> \<Longrightarrow> P xs ys"
huffman@25904
   240
apply (rule_tac x=ys in spec)
huffman@25904
   241
apply (rule_tac xs=xs in lower_principal_induct, simp)
huffman@25904
   242
apply (rule allI, rename_tac ys)
huffman@25904
   243
apply (rule_tac xs=ys in lower_principal_induct, simp)
huffman@25904
   244
apply simp
huffman@25904
   245
done
huffman@25904
   246
huffman@25904
   247
huffman@25904
   248
subsection {* Monadic unit *}
huffman@25904
   249
huffman@25904
   250
definition
huffman@25904
   251
  lower_unit :: "'a \<rightarrow> 'a lower_pd" where
huffman@25904
   252
  "lower_unit = compact_basis.basis_fun (\<lambda>a. lower_principal (PDUnit a))"
huffman@25904
   253
huffman@25904
   254
lemma lower_unit_Rep_compact_basis [simp]:
huffman@25904
   255
  "lower_unit\<cdot>(Rep_compact_basis a) = lower_principal (PDUnit a)"
huffman@25904
   256
unfolding lower_unit_def
huffman@25904
   257
apply (rule compact_basis.basis_fun_principal)
huffman@25904
   258
apply (rule lower_principal_mono)
huffman@25904
   259
apply (erule PDUnit_lower_mono)
huffman@25904
   260
done
huffman@25904
   261
huffman@25904
   262
lemma lower_unit_strict [simp]: "lower_unit\<cdot>\<bottom> = \<bottom>"
huffman@25904
   263
unfolding inst_lower_pd_pcpo Rep_compact_bot [symmetric] by simp
huffman@25904
   264
huffman@25904
   265
lemma approx_lower_unit [simp]:
huffman@25904
   266
  "approx n\<cdot>(lower_unit\<cdot>x) = lower_unit\<cdot>(approx n\<cdot>x)"
huffman@25904
   267
apply (induct x rule: compact_basis_induct, simp)
huffman@25904
   268
apply (simp add: approx_Rep_compact_basis)
huffman@25904
   269
done
huffman@25904
   270
huffman@25904
   271
lemma lower_unit_less_iff [simp]:
huffman@25904
   272
  "(lower_unit\<cdot>x \<sqsubseteq> lower_unit\<cdot>y) = (x \<sqsubseteq> y)"
huffman@25904
   273
 apply (rule iffI)
huffman@25904
   274
  apply (rule bifinite_less_ext)
huffman@25904
   275
  apply (drule_tac f="approx i" in monofun_cfun_arg, simp)
huffman@25904
   276
  apply (cut_tac x="approx i\<cdot>x" in compact_imp_Rep_compact_basis, simp)
huffman@25904
   277
  apply (cut_tac x="approx i\<cdot>y" in compact_imp_Rep_compact_basis, simp)
huffman@25904
   278
  apply (clarify, simp add: compact_le_def)
huffman@25904
   279
 apply (erule monofun_cfun_arg)
huffman@25904
   280
done
huffman@25904
   281
huffman@25904
   282
lemma lower_unit_eq_iff [simp]:
huffman@25904
   283
  "(lower_unit\<cdot>x = lower_unit\<cdot>y) = (x = y)"
huffman@25904
   284
unfolding po_eq_conv by simp
huffman@25904
   285
huffman@25904
   286
lemma lower_unit_strict_iff [simp]: "(lower_unit\<cdot>x = \<bottom>) = (x = \<bottom>)"
huffman@25904
   287
unfolding lower_unit_strict [symmetric] by (rule lower_unit_eq_iff)
huffman@25904
   288
huffman@25904
   289
lemma compact_lower_unit_iff [simp]:
huffman@25904
   290
  "compact (lower_unit\<cdot>x) = compact x"
huffman@25904
   291
unfolding bifinite_compact_iff by simp
huffman@25904
   292
huffman@25904
   293
huffman@25904
   294
subsection {* Monadic plus *}
huffman@25904
   295
huffman@25904
   296
definition
huffman@25904
   297
  lower_plus :: "'a lower_pd \<rightarrow> 'a lower_pd \<rightarrow> 'a lower_pd" where
huffman@25904
   298
  "lower_plus = lower_pd.basis_fun (\<lambda>t. lower_pd.basis_fun (\<lambda>u.
huffman@25904
   299
      lower_principal (PDPlus t u)))"
huffman@25904
   300
huffman@25904
   301
abbreviation
huffman@25904
   302
  lower_add :: "'a lower_pd \<Rightarrow> 'a lower_pd \<Rightarrow> 'a lower_pd"
huffman@25904
   303
    (infixl "+\<flat>" 65) where
huffman@25904
   304
  "xs +\<flat> ys == lower_plus\<cdot>xs\<cdot>ys"
huffman@25904
   305
huffman@25904
   306
lemma lower_plus_principal [simp]:
huffman@25904
   307
  "lower_plus\<cdot>(lower_principal t)\<cdot>(lower_principal u) =
huffman@25904
   308
   lower_principal (PDPlus t u)"
huffman@25904
   309
unfolding lower_plus_def
huffman@25904
   310
by (simp add: lower_pd.basis_fun_principal
huffman@25904
   311
    lower_pd.basis_fun_mono PDPlus_lower_mono)
huffman@25904
   312
huffman@25904
   313
lemma approx_lower_plus [simp]:
huffman@25904
   314
  "approx n\<cdot>(lower_plus\<cdot>xs\<cdot>ys) = lower_plus\<cdot>(approx n\<cdot>xs)\<cdot>(approx n\<cdot>ys)"
huffman@25904
   315
by (induct xs ys rule: lower_principal_induct2, simp, simp, simp)
huffman@25904
   316
huffman@25904
   317
lemma lower_plus_commute: "lower_plus\<cdot>xs\<cdot>ys = lower_plus\<cdot>ys\<cdot>xs"
huffman@25904
   318
apply (induct xs ys rule: lower_principal_induct2, simp, simp)
huffman@25904
   319
apply (simp add: PDPlus_commute)
huffman@25904
   320
done
huffman@25904
   321
huffman@25904
   322
lemma lower_plus_assoc:
huffman@25904
   323
  "lower_plus\<cdot>(lower_plus\<cdot>xs\<cdot>ys)\<cdot>zs = lower_plus\<cdot>xs\<cdot>(lower_plus\<cdot>ys\<cdot>zs)"
huffman@25904
   324
apply (induct xs ys arbitrary: zs rule: lower_principal_induct2, simp, simp)
huffman@25904
   325
apply (rule_tac xs=zs in lower_principal_induct, simp)
huffman@25904
   326
apply (simp add: PDPlus_assoc)
huffman@25904
   327
done
huffman@25904
   328
huffman@25904
   329
lemma lower_plus_absorb: "lower_plus\<cdot>xs\<cdot>xs = xs"
huffman@25904
   330
apply (induct xs rule: lower_principal_induct, simp)
huffman@25904
   331
apply (simp add: PDPlus_absorb)
huffman@25904
   332
done
huffman@25904
   333
huffman@25904
   334
lemma lower_plus_less1: "xs \<sqsubseteq> lower_plus\<cdot>xs\<cdot>ys"
huffman@25904
   335
apply (induct xs ys rule: lower_principal_induct2, simp, simp)
huffman@25904
   336
apply (simp add: PDPlus_lower_less)
huffman@25904
   337
done
huffman@25904
   338
huffman@25904
   339
lemma lower_plus_less2: "ys \<sqsubseteq> lower_plus\<cdot>xs\<cdot>ys"
huffman@25904
   340
by (subst lower_plus_commute, rule lower_plus_less1)
huffman@25904
   341
huffman@25904
   342
lemma lower_plus_least: "\<lbrakk>xs \<sqsubseteq> zs; ys \<sqsubseteq> zs\<rbrakk> \<Longrightarrow> lower_plus\<cdot>xs\<cdot>ys \<sqsubseteq> zs"
huffman@25904
   343
apply (subst lower_plus_absorb [of zs, symmetric])
huffman@25904
   344
apply (erule (1) monofun_cfun [OF monofun_cfun_arg])
huffman@25904
   345
done
huffman@25904
   346
huffman@25904
   347
lemma lower_plus_less_iff:
huffman@25904
   348
  "(lower_plus\<cdot>xs\<cdot>ys \<sqsubseteq> zs) = (xs \<sqsubseteq> zs \<and> ys \<sqsubseteq> zs)"
huffman@25904
   349
apply safe
huffman@25904
   350
apply (erule trans_less [OF lower_plus_less1])
huffman@25904
   351
apply (erule trans_less [OF lower_plus_less2])
huffman@25904
   352
apply (erule (1) lower_plus_least)
huffman@25904
   353
done
huffman@25904
   354
huffman@25904
   355
lemma lower_plus_strict_iff [simp]:
huffman@25904
   356
  "(lower_plus\<cdot>xs\<cdot>ys = \<bottom>) = (xs = \<bottom> \<and> ys = \<bottom>)"
huffman@25904
   357
apply safe
huffman@25904
   358
apply (rule UU_I, erule subst, rule lower_plus_less1)
huffman@25904
   359
apply (rule UU_I, erule subst, rule lower_plus_less2)
huffman@25904
   360
apply (rule lower_plus_absorb)
huffman@25904
   361
done
huffman@25904
   362
huffman@25904
   363
lemma lower_plus_strict1 [simp]: "lower_plus\<cdot>\<bottom>\<cdot>ys = ys"
huffman@25904
   364
apply (rule antisym_less [OF _ lower_plus_less2])
huffman@25904
   365
apply (simp add: lower_plus_least)
huffman@25904
   366
done
huffman@25904
   367
huffman@25904
   368
lemma lower_plus_strict2 [simp]: "lower_plus\<cdot>xs\<cdot>\<bottom> = xs"
huffman@25904
   369
apply (rule antisym_less [OF _ lower_plus_less1])
huffman@25904
   370
apply (simp add: lower_plus_least)
huffman@25904
   371
done
huffman@25904
   372
huffman@25904
   373
lemma lower_unit_less_plus_iff:
huffman@25904
   374
  "(lower_unit\<cdot>x \<sqsubseteq> lower_plus\<cdot>ys\<cdot>zs) =
huffman@25904
   375
    (lower_unit\<cdot>x \<sqsubseteq> ys \<or> lower_unit\<cdot>x \<sqsubseteq> zs)"
huffman@25904
   376
 apply (rule iffI)
huffman@25904
   377
  apply (subgoal_tac
huffman@25904
   378
    "adm (\<lambda>f. f\<cdot>(lower_unit\<cdot>x) \<sqsubseteq> f\<cdot>ys \<or> f\<cdot>(lower_unit\<cdot>x) \<sqsubseteq> f\<cdot>zs)")
huffman@25904
   379
   apply (drule admD [rule_format], rule chain_approx)
huffman@25904
   380
    apply (drule_tac f="approx i" in monofun_cfun_arg)
huffman@25904
   381
    apply (cut_tac x="approx i\<cdot>x" in compact_imp_Rep_compact_basis, simp)
huffman@25904
   382
    apply (cut_tac xs="approx i\<cdot>ys" in compact_imp_lower_principal, simp)
huffman@25904
   383
    apply (cut_tac xs="approx i\<cdot>zs" in compact_imp_lower_principal, simp)
huffman@25904
   384
    apply (clarify, simp add: lower_le_PDUnit_PDPlus_iff)
huffman@25904
   385
   apply simp
huffman@25904
   386
  apply simp
huffman@25904
   387
 apply (erule disjE)
huffman@25904
   388
  apply (erule trans_less [OF _ lower_plus_less1])
huffman@25904
   389
 apply (erule trans_less [OF _ lower_plus_less2])
huffman@25904
   390
done
huffman@25904
   391
huffman@25904
   392
lemmas lower_pd_less_simps =
huffman@25904
   393
  lower_unit_less_iff
huffman@25904
   394
  lower_plus_less_iff
huffman@25904
   395
  lower_unit_less_plus_iff
huffman@25904
   396
huffman@25904
   397
huffman@25904
   398
subsection {* Induction rules *}
huffman@25904
   399
huffman@25904
   400
lemma lower_pd_induct1:
huffman@25904
   401
  assumes P: "adm P"
huffman@25904
   402
  assumes unit: "\<And>x. P (lower_unit\<cdot>x)"
huffman@25904
   403
  assumes insert:
huffman@25904
   404
    "\<And>x ys. \<lbrakk>P (lower_unit\<cdot>x); P ys\<rbrakk> \<Longrightarrow> P (lower_plus\<cdot>(lower_unit\<cdot>x)\<cdot>ys)"
huffman@25904
   405
  shows "P (xs::'a lower_pd)"
huffman@25904
   406
apply (induct xs rule: lower_principal_induct, rule P)
huffman@25904
   407
apply (induct_tac t rule: pd_basis_induct1)
huffman@25904
   408
apply (simp only: lower_unit_Rep_compact_basis [symmetric])
huffman@25904
   409
apply (rule unit)
huffman@25904
   410
apply (simp only: lower_unit_Rep_compact_basis [symmetric]
huffman@25904
   411
                  lower_plus_principal [symmetric])
huffman@25904
   412
apply (erule insert [OF unit])
huffman@25904
   413
done
huffman@25904
   414
huffman@25904
   415
lemma lower_pd_induct:
huffman@25904
   416
  assumes P: "adm P"
huffman@25904
   417
  assumes unit: "\<And>x. P (lower_unit\<cdot>x)"
huffman@25904
   418
  assumes plus: "\<And>xs ys. \<lbrakk>P xs; P ys\<rbrakk> \<Longrightarrow> P (lower_plus\<cdot>xs\<cdot>ys)"
huffman@25904
   419
  shows "P (xs::'a lower_pd)"
huffman@25904
   420
apply (induct xs rule: lower_principal_induct, rule P)
huffman@25904
   421
apply (induct_tac t rule: pd_basis_induct)
huffman@25904
   422
apply (simp only: lower_unit_Rep_compact_basis [symmetric] unit)
huffman@25904
   423
apply (simp only: lower_plus_principal [symmetric] plus)
huffman@25904
   424
done
huffman@25904
   425
huffman@25904
   426
huffman@25904
   427
subsection {* Monadic bind *}
huffman@25904
   428
huffman@25904
   429
definition
huffman@25904
   430
  lower_bind_basis ::
huffman@25904
   431
  "'a pd_basis \<Rightarrow> ('a \<rightarrow> 'b lower_pd) \<rightarrow> 'b lower_pd" where
huffman@25904
   432
  "lower_bind_basis = fold_pd
huffman@25904
   433
    (\<lambda>a. \<Lambda> f. f\<cdot>(Rep_compact_basis a))
huffman@25904
   434
    (\<lambda>x y. \<Lambda> f. lower_plus\<cdot>(x\<cdot>f)\<cdot>(y\<cdot>f))"
huffman@25904
   435
huffman@25904
   436
lemma ACI_lower_bind: "ACIf (\<lambda>x y. \<Lambda> f. lower_plus\<cdot>(x\<cdot>f)\<cdot>(y\<cdot>f))"
huffman@25904
   437
apply unfold_locales
huffman@25904
   438
apply (simp add: lower_plus_commute)
huffman@25904
   439
apply (simp add: lower_plus_assoc)
huffman@25904
   440
apply (simp add: lower_plus_absorb eta_cfun)
huffman@25904
   441
done
huffman@25904
   442
huffman@25904
   443
lemma lower_bind_basis_simps [simp]:
huffman@25904
   444
  "lower_bind_basis (PDUnit a) =
huffman@25904
   445
    (\<Lambda> f. f\<cdot>(Rep_compact_basis a))"
huffman@25904
   446
  "lower_bind_basis (PDPlus t u) =
huffman@25904
   447
    (\<Lambda> f. lower_plus\<cdot>(lower_bind_basis t\<cdot>f)\<cdot>(lower_bind_basis u\<cdot>f))"
huffman@25904
   448
unfolding lower_bind_basis_def
huffman@25904
   449
apply -
huffman@25904
   450
apply (rule ACIf.fold_pd_PDUnit [OF ACI_lower_bind])
huffman@25904
   451
apply (rule ACIf.fold_pd_PDPlus [OF ACI_lower_bind])
huffman@25904
   452
done
huffman@25904
   453
huffman@25904
   454
lemma lower_bind_basis_mono:
huffman@25904
   455
  "t \<le>\<flat> u \<Longrightarrow> lower_bind_basis t \<sqsubseteq> lower_bind_basis u"
huffman@25904
   456
unfolding expand_cfun_less
huffman@25904
   457
apply (erule lower_le_induct, safe)
huffman@25904
   458
apply (simp add: compact_le_def monofun_cfun)
huffman@25904
   459
apply (simp add: rev_trans_less [OF lower_plus_less1])
huffman@25904
   460
apply (simp add: lower_plus_less_iff)
huffman@25904
   461
done
huffman@25904
   462
huffman@25904
   463
definition
huffman@25904
   464
  lower_bind :: "'a lower_pd \<rightarrow> ('a \<rightarrow> 'b lower_pd) \<rightarrow> 'b lower_pd" where
huffman@25904
   465
  "lower_bind = lower_pd.basis_fun lower_bind_basis"
huffman@25904
   466
huffman@25904
   467
lemma lower_bind_principal [simp]:
huffman@25904
   468
  "lower_bind\<cdot>(lower_principal t) = lower_bind_basis t"
huffman@25904
   469
unfolding lower_bind_def
huffman@25904
   470
apply (rule lower_pd.basis_fun_principal)
huffman@25904
   471
apply (erule lower_bind_basis_mono)
huffman@25904
   472
done
huffman@25904
   473
huffman@25904
   474
lemma lower_bind_unit [simp]:
huffman@25904
   475
  "lower_bind\<cdot>(lower_unit\<cdot>x)\<cdot>f = f\<cdot>x"
huffman@25904
   476
by (induct x rule: compact_basis_induct, simp, simp)
huffman@25904
   477
huffman@25904
   478
lemma lower_bind_plus [simp]:
huffman@25904
   479
  "lower_bind\<cdot>(lower_plus\<cdot>xs\<cdot>ys)\<cdot>f =
huffman@25904
   480
   lower_plus\<cdot>(lower_bind\<cdot>xs\<cdot>f)\<cdot>(lower_bind\<cdot>ys\<cdot>f)"
huffman@25904
   481
by (induct xs ys rule: lower_principal_induct2, simp, simp, simp)
huffman@25904
   482
huffman@25904
   483
lemma lower_bind_strict [simp]: "lower_bind\<cdot>\<bottom>\<cdot>f = f\<cdot>\<bottom>"
huffman@25904
   484
unfolding lower_unit_strict [symmetric] by (rule lower_bind_unit)
huffman@25904
   485
huffman@25904
   486
huffman@25904
   487
subsection {* Map and join *}
huffman@25904
   488
huffman@25904
   489
definition
huffman@25904
   490
  lower_map :: "('a \<rightarrow> 'b) \<rightarrow> 'a lower_pd \<rightarrow> 'b lower_pd" where
huffman@25904
   491
  "lower_map = (\<Lambda> f xs. lower_bind\<cdot>xs\<cdot>(\<Lambda> x. lower_unit\<cdot>(f\<cdot>x)))"
huffman@25904
   492
huffman@25904
   493
definition
huffman@25904
   494
  lower_join :: "'a lower_pd lower_pd \<rightarrow> 'a lower_pd" where
huffman@25904
   495
  "lower_join = (\<Lambda> xss. lower_bind\<cdot>xss\<cdot>(\<Lambda> xs. xs))"
huffman@25904
   496
huffman@25904
   497
lemma lower_map_unit [simp]:
huffman@25904
   498
  "lower_map\<cdot>f\<cdot>(lower_unit\<cdot>x) = lower_unit\<cdot>(f\<cdot>x)"
huffman@25904
   499
unfolding lower_map_def by simp
huffman@25904
   500
huffman@25904
   501
lemma lower_map_plus [simp]:
huffman@25904
   502
  "lower_map\<cdot>f\<cdot>(lower_plus\<cdot>xs\<cdot>ys) =
huffman@25904
   503
   lower_plus\<cdot>(lower_map\<cdot>f\<cdot>xs)\<cdot>(lower_map\<cdot>f\<cdot>ys)"
huffman@25904
   504
unfolding lower_map_def by simp
huffman@25904
   505
huffman@25904
   506
lemma lower_join_unit [simp]:
huffman@25904
   507
  "lower_join\<cdot>(lower_unit\<cdot>xs) = xs"
huffman@25904
   508
unfolding lower_join_def by simp
huffman@25904
   509
huffman@25904
   510
lemma lower_join_plus [simp]:
huffman@25904
   511
  "lower_join\<cdot>(lower_plus\<cdot>xss\<cdot>yss) =
huffman@25904
   512
   lower_plus\<cdot>(lower_join\<cdot>xss)\<cdot>(lower_join\<cdot>yss)"
huffman@25904
   513
unfolding lower_join_def by simp
huffman@25904
   514
huffman@25904
   515
lemma lower_map_ident: "lower_map\<cdot>(\<Lambda> x. x)\<cdot>xs = xs"
huffman@25904
   516
by (induct xs rule: lower_pd_induct, simp_all)
huffman@25904
   517
huffman@25904
   518
lemma lower_map_map:
huffman@25904
   519
  "lower_map\<cdot>f\<cdot>(lower_map\<cdot>g\<cdot>xs) = lower_map\<cdot>(\<Lambda> x. f\<cdot>(g\<cdot>x))\<cdot>xs"
huffman@25904
   520
by (induct xs rule: lower_pd_induct, simp_all)
huffman@25904
   521
huffman@25904
   522
lemma lower_join_map_unit:
huffman@25904
   523
  "lower_join\<cdot>(lower_map\<cdot>lower_unit\<cdot>xs) = xs"
huffman@25904
   524
by (induct xs rule: lower_pd_induct, simp_all)
huffman@25904
   525
huffman@25904
   526
lemma lower_join_map_join:
huffman@25904
   527
  "lower_join\<cdot>(lower_map\<cdot>lower_join\<cdot>xsss) = lower_join\<cdot>(lower_join\<cdot>xsss)"
huffman@25904
   528
by (induct xsss rule: lower_pd_induct, simp_all)
huffman@25904
   529
huffman@25904
   530
lemma lower_join_map_map:
huffman@25904
   531
  "lower_join\<cdot>(lower_map\<cdot>(lower_map\<cdot>f)\<cdot>xss) =
huffman@25904
   532
   lower_map\<cdot>f\<cdot>(lower_join\<cdot>xss)"
huffman@25904
   533
by (induct xss rule: lower_pd_induct, simp_all)
huffman@25904
   534
huffman@25904
   535
lemma lower_map_approx: "lower_map\<cdot>(approx n)\<cdot>xs = approx n\<cdot>xs"
huffman@25904
   536
by (induct xs rule: lower_pd_induct, simp_all)
huffman@25904
   537
huffman@25904
   538
end