src/HOLCF/LowerPD.thy
author huffman
Fri Jun 20 23:01:09 2008 +0200 (2008-06-20)
changeset 27310 d0229bc6c461
parent 27309 c74270fd72a8
child 27373 5794a0e3e26c
permissions -rw-r--r--
simplify profinite class axioms
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@26420
    16
  "lower_le = (\<lambda>u v. \<forall>x\<in>Rep_pd_basis u. \<exists>y\<in>Rep_pd_basis v. x \<sqsubseteq> y)"
huffman@25904
    17
huffman@25904
    18
lemma lower_le_refl [simp]: "t \<le>\<flat> t"
huffman@26420
    19
unfolding lower_le_def by fast
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@26420
    27
apply (erule (1) trans_less)
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@26420
    37
lemma PDUnit_lower_mono: "x \<sqsubseteq> 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@26420
    44
unfolding lower_le_def Rep_PDPlus by fast
huffman@25904
    45
huffman@25904
    46
lemma lower_le_PDUnit_PDUnit_iff [simp]:
huffman@26420
    47
  "(PDUnit a \<le>\<flat> PDUnit b) = a \<sqsubseteq> 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@26420
    59
  assumes 1: "\<And>a b. a \<sqsubseteq> 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@27289
    75
lemma approx_pd_lower_chain:
huffman@27289
    76
  "approx_pd n t \<le>\<flat> approx_pd (Suc n) t"
huffman@25904
    77
apply (induct t rule: pd_basis_induct)
huffman@27289
    78
apply (simp add: compact_basis.take_chain)
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@27289
    84
apply (simp add: compact_basis.take_less)
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@27289
    91
apply (simp add: compact_basis.take_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@27297
   100
  "{S::'a pd_basis cset. lower_le.ideal (Rep_cset S)}"
huffman@27297
   101
by (rule lower_le.cpodef_ideal_lemma)
huffman@25904
   102
huffman@27297
   103
lemma ideal_Rep_lower_pd: "lower_le.ideal (Rep_cset (Rep_lower_pd xs))"
huffman@26927
   104
by (rule Rep_lower_pd [unfolded mem_Collect_eq])
huffman@25904
   105
huffman@25904
   106
definition
huffman@25904
   107
  lower_principal :: "'a pd_basis \<Rightarrow> 'a lower_pd" where
huffman@27297
   108
  "lower_principal t = Abs_lower_pd (Abs_cset {u. u \<le>\<flat> t})"
huffman@25904
   109
huffman@25904
   110
lemma Rep_lower_principal:
huffman@27297
   111
  "Rep_cset (Rep_lower_pd (lower_principal t)) = {u. u \<le>\<flat> t}"
huffman@25904
   112
unfolding lower_principal_def
huffman@27297
   113
by (simp add: Abs_lower_pd_inverse lower_le.ideal_principal)
huffman@25904
   114
huffman@25904
   115
interpretation lower_pd:
huffman@27297
   116
  ideal_completion
huffman@27297
   117
    [lower_le approx_pd lower_principal "\<lambda>x. Rep_cset (Rep_lower_pd x)"]
huffman@25904
   118
apply unfold_locales
huffman@25904
   119
apply (rule approx_pd_lower_le)
huffman@25904
   120
apply (rule approx_pd_idem)
huffman@25904
   121
apply (erule approx_pd_lower_mono)
huffman@27289
   122
apply (rule approx_pd_lower_chain)
huffman@25904
   123
apply (rule finite_range_approx_pd)
huffman@27289
   124
apply (rule approx_pd_covers)
huffman@26420
   125
apply (rule ideal_Rep_lower_pd)
huffman@27297
   126
apply (simp add: cont2contlubE [OF cont_Rep_lower_pd] Rep_cset_lub)
huffman@26420
   127
apply (rule Rep_lower_principal)
huffman@27297
   128
apply (simp only: less_lower_pd_def sq_le_cset_def)
huffman@25904
   129
done
huffman@25904
   130
huffman@27289
   131
text {* Lower powerdomain is pointed *}
huffman@25904
   132
huffman@25904
   133
lemma lower_pd_minimal: "lower_principal (PDUnit compact_bot) \<sqsubseteq> ys"
huffman@25904
   134
by (induct ys rule: lower_pd.principal_induct, simp, simp)
huffman@25904
   135
huffman@25904
   136
instance lower_pd :: (bifinite) pcpo
huffman@26927
   137
by intro_classes (fast intro: lower_pd_minimal)
huffman@25904
   138
huffman@25904
   139
lemma inst_lower_pd_pcpo: "\<bottom> = lower_principal (PDUnit compact_bot)"
huffman@25904
   140
by (rule lower_pd_minimal [THEN UU_I, symmetric])
huffman@25904
   141
huffman@27289
   142
text {* Lower powerdomain is profinite *}
huffman@25904
   143
huffman@26962
   144
instantiation lower_pd :: (profinite) profinite
huffman@26962
   145
begin
huffman@25904
   146
huffman@26962
   147
definition
huffman@26962
   148
  approx_lower_pd_def: "approx = lower_pd.completion_approx"
huffman@26927
   149
huffman@26962
   150
instance
huffman@26927
   151
apply (intro_classes, unfold approx_lower_pd_def)
huffman@27310
   152
apply (rule lower_pd.chain_completion_approx)
huffman@26927
   153
apply (rule lower_pd.lub_completion_approx)
huffman@26927
   154
apply (rule lower_pd.completion_approx_idem)
huffman@26927
   155
apply (rule lower_pd.finite_fixes_completion_approx)
huffman@26927
   156
done
huffman@26927
   157
huffman@26962
   158
end
huffman@26962
   159
huffman@26927
   160
instance lower_pd :: (bifinite) bifinite ..
huffman@25904
   161
huffman@25904
   162
lemma approx_lower_principal [simp]:
huffman@25904
   163
  "approx n\<cdot>(lower_principal t) = lower_principal (approx_pd n t)"
huffman@25904
   164
unfolding approx_lower_pd_def
huffman@26927
   165
by (rule lower_pd.completion_approx_principal)
huffman@25904
   166
huffman@25904
   167
lemma approx_eq_lower_principal:
huffman@27297
   168
  "\<exists>t\<in>Rep_cset (Rep_lower_pd xs).
huffman@27297
   169
    approx n\<cdot>xs = lower_principal (approx_pd n t)"
huffman@25904
   170
unfolding approx_lower_pd_def
huffman@26927
   171
by (rule lower_pd.completion_approx_eq_principal)
huffman@26407
   172
huffman@25904
   173
huffman@26927
   174
subsection {* Monadic unit and plus *}
huffman@25904
   175
huffman@25904
   176
definition
huffman@25904
   177
  lower_unit :: "'a \<rightarrow> 'a lower_pd" where
huffman@25904
   178
  "lower_unit = compact_basis.basis_fun (\<lambda>a. lower_principal (PDUnit a))"
huffman@25904
   179
huffman@25904
   180
definition
huffman@25904
   181
  lower_plus :: "'a lower_pd \<rightarrow> 'a lower_pd \<rightarrow> 'a lower_pd" where
huffman@25904
   182
  "lower_plus = lower_pd.basis_fun (\<lambda>t. lower_pd.basis_fun (\<lambda>u.
huffman@25904
   183
      lower_principal (PDPlus t u)))"
huffman@25904
   184
huffman@25904
   185
abbreviation
huffman@25904
   186
  lower_add :: "'a lower_pd \<Rightarrow> 'a lower_pd \<Rightarrow> 'a lower_pd"
huffman@25904
   187
    (infixl "+\<flat>" 65) where
huffman@25904
   188
  "xs +\<flat> ys == lower_plus\<cdot>xs\<cdot>ys"
huffman@25904
   189
huffman@26927
   190
syntax
huffman@26927
   191
  "_lower_pd" :: "args \<Rightarrow> 'a lower_pd" ("{_}\<flat>")
huffman@26927
   192
huffman@26927
   193
translations
huffman@26927
   194
  "{x,xs}\<flat>" == "{x}\<flat> +\<flat> {xs}\<flat>"
huffman@26927
   195
  "{x}\<flat>" == "CONST lower_unit\<cdot>x"
huffman@26927
   196
huffman@26927
   197
lemma lower_unit_Rep_compact_basis [simp]:
huffman@26927
   198
  "{Rep_compact_basis a}\<flat> = lower_principal (PDUnit a)"
huffman@26927
   199
unfolding lower_unit_def
huffman@27289
   200
by (simp add: compact_basis.basis_fun_principal PDUnit_lower_mono)
huffman@26927
   201
huffman@25904
   202
lemma lower_plus_principal [simp]:
huffman@26927
   203
  "lower_principal t +\<flat> lower_principal u = lower_principal (PDPlus t u)"
huffman@25904
   204
unfolding lower_plus_def
huffman@25904
   205
by (simp add: lower_pd.basis_fun_principal
huffman@25904
   206
    lower_pd.basis_fun_mono PDPlus_lower_mono)
huffman@25904
   207
huffman@26927
   208
lemma approx_lower_unit [simp]:
huffman@26927
   209
  "approx n\<cdot>{x}\<flat> = {approx n\<cdot>x}\<flat>"
huffman@27289
   210
apply (induct x rule: compact_basis.principal_induct, simp)
huffman@26927
   211
apply (simp add: approx_Rep_compact_basis)
huffman@26927
   212
done
huffman@26927
   213
huffman@25904
   214
lemma approx_lower_plus [simp]:
huffman@26927
   215
  "approx n\<cdot>(xs +\<flat> ys) = (approx n\<cdot>xs) +\<flat> (approx n\<cdot>ys)"
huffman@27289
   216
by (induct xs ys rule: lower_pd.principal_induct2, simp, simp, simp)
huffman@25904
   217
huffman@26927
   218
lemma lower_plus_assoc: "(xs +\<flat> ys) +\<flat> zs = xs +\<flat> (ys +\<flat> zs)"
huffman@27289
   219
apply (induct xs ys arbitrary: zs rule: lower_pd.principal_induct2, simp, simp)
huffman@27289
   220
apply (rule_tac x=zs in lower_pd.principal_induct, simp)
huffman@25904
   221
apply (simp add: PDPlus_assoc)
huffman@25904
   222
done
huffman@25904
   223
huffman@26927
   224
lemma lower_plus_commute: "xs +\<flat> ys = ys +\<flat> xs"
huffman@27289
   225
apply (induct xs ys rule: lower_pd.principal_induct2, simp, simp)
huffman@26927
   226
apply (simp add: PDPlus_commute)
huffman@26927
   227
done
huffman@26927
   228
huffman@26927
   229
lemma lower_plus_absorb: "xs +\<flat> xs = xs"
huffman@27289
   230
apply (induct xs rule: lower_pd.principal_induct, simp)
huffman@25904
   231
apply (simp add: PDPlus_absorb)
huffman@25904
   232
done
huffman@25904
   233
huffman@26927
   234
interpretation aci_lower_plus: ab_semigroup_idem_mult ["op +\<flat>"]
huffman@26927
   235
  by unfold_locales
huffman@26927
   236
    (rule lower_plus_assoc lower_plus_commute lower_plus_absorb)+
huffman@26927
   237
huffman@26927
   238
lemma lower_plus_left_commute: "xs +\<flat> (ys +\<flat> zs) = ys +\<flat> (xs +\<flat> zs)"
huffman@26927
   239
by (rule aci_lower_plus.mult_left_commute)
huffman@26927
   240
huffman@26927
   241
lemma lower_plus_left_absorb: "xs +\<flat> (xs +\<flat> ys) = xs +\<flat> ys"
huffman@26927
   242
by (rule aci_lower_plus.mult_left_idem)
huffman@26927
   243
huffman@26927
   244
lemmas lower_plus_aci = aci_lower_plus.mult_ac_idem
huffman@26927
   245
huffman@26927
   246
lemma lower_plus_less1: "xs \<sqsubseteq> xs +\<flat> ys"
huffman@27289
   247
apply (induct xs ys rule: lower_pd.principal_induct2, simp, simp)
huffman@25904
   248
apply (simp add: PDPlus_lower_less)
huffman@25904
   249
done
huffman@25904
   250
huffman@26927
   251
lemma lower_plus_less2: "ys \<sqsubseteq> xs +\<flat> ys"
huffman@25904
   252
by (subst lower_plus_commute, rule lower_plus_less1)
huffman@25904
   253
huffman@26927
   254
lemma lower_plus_least: "\<lbrakk>xs \<sqsubseteq> zs; ys \<sqsubseteq> zs\<rbrakk> \<Longrightarrow> xs +\<flat> ys \<sqsubseteq> zs"
huffman@25904
   255
apply (subst lower_plus_absorb [of zs, symmetric])
huffman@25904
   256
apply (erule (1) monofun_cfun [OF monofun_cfun_arg])
huffman@25904
   257
done
huffman@25904
   258
huffman@25904
   259
lemma lower_plus_less_iff:
huffman@26927
   260
  "xs +\<flat> ys \<sqsubseteq> zs \<longleftrightarrow> xs \<sqsubseteq> zs \<and> ys \<sqsubseteq> zs"
huffman@25904
   261
apply safe
huffman@25904
   262
apply (erule trans_less [OF lower_plus_less1])
huffman@25904
   263
apply (erule trans_less [OF lower_plus_less2])
huffman@25904
   264
apply (erule (1) lower_plus_least)
huffman@25904
   265
done
huffman@25904
   266
huffman@25904
   267
lemma lower_unit_less_plus_iff:
huffman@26927
   268
  "{x}\<flat> \<sqsubseteq> ys +\<flat> zs \<longleftrightarrow> {x}\<flat> \<sqsubseteq> ys \<or> {x}\<flat> \<sqsubseteq> zs"
huffman@25904
   269
 apply (rule iffI)
huffman@25904
   270
  apply (subgoal_tac
huffman@26927
   271
    "adm (\<lambda>f. f\<cdot>{x}\<flat> \<sqsubseteq> f\<cdot>ys \<or> f\<cdot>{x}\<flat> \<sqsubseteq> f\<cdot>zs)")
huffman@25925
   272
   apply (drule admD, rule chain_approx)
huffman@25904
   273
    apply (drule_tac f="approx i" in monofun_cfun_arg)
huffman@27289
   274
    apply (cut_tac x="approx i\<cdot>x" in compact_basis.compact_imp_principal, simp)
huffman@27289
   275
    apply (cut_tac x="approx i\<cdot>ys" in lower_pd.compact_imp_principal, simp)
huffman@27289
   276
    apply (cut_tac x="approx i\<cdot>zs" in lower_pd.compact_imp_principal, simp)
huffman@25904
   277
    apply (clarify, simp add: lower_le_PDUnit_PDPlus_iff)
huffman@25904
   278
   apply simp
huffman@25904
   279
  apply simp
huffman@25904
   280
 apply (erule disjE)
huffman@25904
   281
  apply (erule trans_less [OF _ lower_plus_less1])
huffman@25904
   282
 apply (erule trans_less [OF _ lower_plus_less2])
huffman@25904
   283
done
huffman@25904
   284
huffman@26927
   285
lemma lower_unit_less_iff [simp]: "{x}\<flat> \<sqsubseteq> {y}\<flat> \<longleftrightarrow> x \<sqsubseteq> y"
huffman@26927
   286
 apply (rule iffI)
huffman@27309
   287
  apply (rule profinite_less_ext)
huffman@26927
   288
  apply (drule_tac f="approx i" in monofun_cfun_arg, simp)
huffman@27289
   289
  apply (cut_tac x="approx i\<cdot>x" in compact_basis.compact_imp_principal, simp)
huffman@27289
   290
  apply (cut_tac x="approx i\<cdot>y" in compact_basis.compact_imp_principal, simp)
huffman@27289
   291
  apply clarsimp
huffman@26927
   292
 apply (erule monofun_cfun_arg)
huffman@26927
   293
done
huffman@26927
   294
huffman@25904
   295
lemmas lower_pd_less_simps =
huffman@25904
   296
  lower_unit_less_iff
huffman@25904
   297
  lower_plus_less_iff
huffman@25904
   298
  lower_unit_less_plus_iff
huffman@25904
   299
huffman@27289
   300
lemma fooble:
huffman@27289
   301
  fixes f :: "'a::po \<Rightarrow> 'b::po"
huffman@27289
   302
  assumes f: "\<And>x y. f x \<sqsubseteq> f y \<longleftrightarrow> x \<sqsubseteq> y"
huffman@27289
   303
  shows "f x = f y \<longleftrightarrow> x = y"
huffman@27289
   304
unfolding po_eq_conv by (simp add: f)
huffman@27289
   305
huffman@26927
   306
lemma lower_unit_eq_iff [simp]: "{x}\<flat> = {y}\<flat> \<longleftrightarrow> x = y"
huffman@27289
   307
by (rule lower_unit_less_iff [THEN fooble])
huffman@26927
   308
huffman@26927
   309
lemma lower_unit_strict [simp]: "{\<bottom>}\<flat> = \<bottom>"
huffman@26927
   310
unfolding inst_lower_pd_pcpo Rep_compact_bot [symmetric] by simp
huffman@26927
   311
huffman@26927
   312
lemma lower_unit_strict_iff [simp]: "{x}\<flat> = \<bottom> \<longleftrightarrow> x = \<bottom>"
huffman@26927
   313
unfolding lower_unit_strict [symmetric] by (rule lower_unit_eq_iff)
huffman@26927
   314
huffman@26927
   315
lemma lower_plus_strict_iff [simp]:
huffman@26927
   316
  "xs +\<flat> ys = \<bottom> \<longleftrightarrow> xs = \<bottom> \<and> ys = \<bottom>"
huffman@26927
   317
apply safe
huffman@26927
   318
apply (rule UU_I, erule subst, rule lower_plus_less1)
huffman@26927
   319
apply (rule UU_I, erule subst, rule lower_plus_less2)
huffman@26927
   320
apply (rule lower_plus_absorb)
huffman@26927
   321
done
huffman@26927
   322
huffman@26927
   323
lemma lower_plus_strict1 [simp]: "\<bottom> +\<flat> ys = ys"
huffman@26927
   324
apply (rule antisym_less [OF _ lower_plus_less2])
huffman@26927
   325
apply (simp add: lower_plus_least)
huffman@26927
   326
done
huffman@26927
   327
huffman@26927
   328
lemma lower_plus_strict2 [simp]: "xs +\<flat> \<bottom> = xs"
huffman@26927
   329
apply (rule antisym_less [OF _ lower_plus_less1])
huffman@26927
   330
apply (simp add: lower_plus_least)
huffman@26927
   331
done
huffman@26927
   332
huffman@26927
   333
lemma compact_lower_unit_iff [simp]: "compact {x}\<flat> \<longleftrightarrow> compact x"
huffman@27309
   334
unfolding profinite_compact_iff by simp
huffman@26927
   335
huffman@26927
   336
lemma compact_lower_plus [simp]:
huffman@26927
   337
  "\<lbrakk>compact xs; compact ys\<rbrakk> \<Longrightarrow> compact (xs +\<flat> ys)"
huffman@27289
   338
by (auto dest!: lower_pd.compact_imp_principal)
huffman@26927
   339
huffman@25904
   340
huffman@25904
   341
subsection {* Induction rules *}
huffman@25904
   342
huffman@25904
   343
lemma lower_pd_induct1:
huffman@25904
   344
  assumes P: "adm P"
huffman@26927
   345
  assumes unit: "\<And>x. P {x}\<flat>"
huffman@25904
   346
  assumes insert:
huffman@26927
   347
    "\<And>x ys. \<lbrakk>P {x}\<flat>; P ys\<rbrakk> \<Longrightarrow> P ({x}\<flat> +\<flat> ys)"
huffman@25904
   348
  shows "P (xs::'a lower_pd)"
huffman@27289
   349
apply (induct xs rule: lower_pd.principal_induct, rule P)
huffman@27289
   350
apply (induct_tac a rule: pd_basis_induct1)
huffman@25904
   351
apply (simp only: lower_unit_Rep_compact_basis [symmetric])
huffman@25904
   352
apply (rule unit)
huffman@25904
   353
apply (simp only: lower_unit_Rep_compact_basis [symmetric]
huffman@25904
   354
                  lower_plus_principal [symmetric])
huffman@25904
   355
apply (erule insert [OF unit])
huffman@25904
   356
done
huffman@25904
   357
huffman@25904
   358
lemma lower_pd_induct:
huffman@25904
   359
  assumes P: "adm P"
huffman@26927
   360
  assumes unit: "\<And>x. P {x}\<flat>"
huffman@26927
   361
  assumes plus: "\<And>xs ys. \<lbrakk>P xs; P ys\<rbrakk> \<Longrightarrow> P (xs +\<flat> ys)"
huffman@25904
   362
  shows "P (xs::'a lower_pd)"
huffman@27289
   363
apply (induct xs rule: lower_pd.principal_induct, rule P)
huffman@27289
   364
apply (induct_tac a rule: pd_basis_induct)
huffman@25904
   365
apply (simp only: lower_unit_Rep_compact_basis [symmetric] unit)
huffman@25904
   366
apply (simp only: lower_plus_principal [symmetric] plus)
huffman@25904
   367
done
huffman@25904
   368
huffman@25904
   369
huffman@25904
   370
subsection {* Monadic bind *}
huffman@25904
   371
huffman@25904
   372
definition
huffman@25904
   373
  lower_bind_basis ::
huffman@25904
   374
  "'a pd_basis \<Rightarrow> ('a \<rightarrow> 'b lower_pd) \<rightarrow> 'b lower_pd" where
huffman@25904
   375
  "lower_bind_basis = fold_pd
huffman@25904
   376
    (\<lambda>a. \<Lambda> f. f\<cdot>(Rep_compact_basis a))
huffman@26927
   377
    (\<lambda>x y. \<Lambda> f. x\<cdot>f +\<flat> y\<cdot>f)"
huffman@25904
   378
huffman@26927
   379
lemma ACI_lower_bind:
huffman@26927
   380
  "ab_semigroup_idem_mult (\<lambda>x y. \<Lambda> f. x\<cdot>f +\<flat> y\<cdot>f)"
huffman@25904
   381
apply unfold_locales
haftmann@26041
   382
apply (simp add: lower_plus_assoc)
huffman@25904
   383
apply (simp add: lower_plus_commute)
huffman@25904
   384
apply (simp add: lower_plus_absorb eta_cfun)
huffman@25904
   385
done
huffman@25904
   386
huffman@25904
   387
lemma lower_bind_basis_simps [simp]:
huffman@25904
   388
  "lower_bind_basis (PDUnit a) =
huffman@25904
   389
    (\<Lambda> f. f\<cdot>(Rep_compact_basis a))"
huffman@25904
   390
  "lower_bind_basis (PDPlus t u) =
huffman@26927
   391
    (\<Lambda> f. lower_bind_basis t\<cdot>f +\<flat> lower_bind_basis u\<cdot>f)"
huffman@25904
   392
unfolding lower_bind_basis_def
huffman@25904
   393
apply -
huffman@26927
   394
apply (rule fold_pd_PDUnit [OF ACI_lower_bind])
huffman@26927
   395
apply (rule fold_pd_PDPlus [OF ACI_lower_bind])
huffman@25904
   396
done
huffman@25904
   397
huffman@25904
   398
lemma lower_bind_basis_mono:
huffman@25904
   399
  "t \<le>\<flat> u \<Longrightarrow> lower_bind_basis t \<sqsubseteq> lower_bind_basis u"
huffman@25904
   400
unfolding expand_cfun_less
huffman@25904
   401
apply (erule lower_le_induct, safe)
huffman@27289
   402
apply (simp add: monofun_cfun)
huffman@25904
   403
apply (simp add: rev_trans_less [OF lower_plus_less1])
huffman@25904
   404
apply (simp add: lower_plus_less_iff)
huffman@25904
   405
done
huffman@25904
   406
huffman@25904
   407
definition
huffman@25904
   408
  lower_bind :: "'a lower_pd \<rightarrow> ('a \<rightarrow> 'b lower_pd) \<rightarrow> 'b lower_pd" where
huffman@25904
   409
  "lower_bind = lower_pd.basis_fun lower_bind_basis"
huffman@25904
   410
huffman@25904
   411
lemma lower_bind_principal [simp]:
huffman@25904
   412
  "lower_bind\<cdot>(lower_principal t) = lower_bind_basis t"
huffman@25904
   413
unfolding lower_bind_def
huffman@25904
   414
apply (rule lower_pd.basis_fun_principal)
huffman@25904
   415
apply (erule lower_bind_basis_mono)
huffman@25904
   416
done
huffman@25904
   417
huffman@25904
   418
lemma lower_bind_unit [simp]:
huffman@26927
   419
  "lower_bind\<cdot>{x}\<flat>\<cdot>f = f\<cdot>x"
huffman@27289
   420
by (induct x rule: compact_basis.principal_induct, simp, simp)
huffman@25904
   421
huffman@25904
   422
lemma lower_bind_plus [simp]:
huffman@26927
   423
  "lower_bind\<cdot>(xs +\<flat> ys)\<cdot>f = lower_bind\<cdot>xs\<cdot>f +\<flat> lower_bind\<cdot>ys\<cdot>f"
huffman@27289
   424
by (induct xs ys rule: lower_pd.principal_induct2, simp, simp, simp)
huffman@25904
   425
huffman@25904
   426
lemma lower_bind_strict [simp]: "lower_bind\<cdot>\<bottom>\<cdot>f = f\<cdot>\<bottom>"
huffman@25904
   427
unfolding lower_unit_strict [symmetric] by (rule lower_bind_unit)
huffman@25904
   428
huffman@25904
   429
huffman@25904
   430
subsection {* Map and join *}
huffman@25904
   431
huffman@25904
   432
definition
huffman@25904
   433
  lower_map :: "('a \<rightarrow> 'b) \<rightarrow> 'a lower_pd \<rightarrow> 'b lower_pd" where
huffman@26927
   434
  "lower_map = (\<Lambda> f xs. lower_bind\<cdot>xs\<cdot>(\<Lambda> x. {f\<cdot>x}\<flat>))"
huffman@25904
   435
huffman@25904
   436
definition
huffman@25904
   437
  lower_join :: "'a lower_pd lower_pd \<rightarrow> 'a lower_pd" where
huffman@25904
   438
  "lower_join = (\<Lambda> xss. lower_bind\<cdot>xss\<cdot>(\<Lambda> xs. xs))"
huffman@25904
   439
huffman@25904
   440
lemma lower_map_unit [simp]:
huffman@26927
   441
  "lower_map\<cdot>f\<cdot>{x}\<flat> = {f\<cdot>x}\<flat>"
huffman@25904
   442
unfolding lower_map_def by simp
huffman@25904
   443
huffman@25904
   444
lemma lower_map_plus [simp]:
huffman@26927
   445
  "lower_map\<cdot>f\<cdot>(xs +\<flat> ys) = lower_map\<cdot>f\<cdot>xs +\<flat> lower_map\<cdot>f\<cdot>ys"
huffman@25904
   446
unfolding lower_map_def by simp
huffman@25904
   447
huffman@25904
   448
lemma lower_join_unit [simp]:
huffman@26927
   449
  "lower_join\<cdot>{xs}\<flat> = xs"
huffman@25904
   450
unfolding lower_join_def by simp
huffman@25904
   451
huffman@25904
   452
lemma lower_join_plus [simp]:
huffman@26927
   453
  "lower_join\<cdot>(xss +\<flat> yss) = lower_join\<cdot>xss +\<flat> lower_join\<cdot>yss"
huffman@25904
   454
unfolding lower_join_def by simp
huffman@25904
   455
huffman@25904
   456
lemma lower_map_ident: "lower_map\<cdot>(\<Lambda> x. x)\<cdot>xs = xs"
huffman@25904
   457
by (induct xs rule: lower_pd_induct, simp_all)
huffman@25904
   458
huffman@25904
   459
lemma lower_map_map:
huffman@25904
   460
  "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
   461
by (induct xs rule: lower_pd_induct, simp_all)
huffman@25904
   462
huffman@25904
   463
lemma lower_join_map_unit:
huffman@25904
   464
  "lower_join\<cdot>(lower_map\<cdot>lower_unit\<cdot>xs) = xs"
huffman@25904
   465
by (induct xs rule: lower_pd_induct, simp_all)
huffman@25904
   466
huffman@25904
   467
lemma lower_join_map_join:
huffman@25904
   468
  "lower_join\<cdot>(lower_map\<cdot>lower_join\<cdot>xsss) = lower_join\<cdot>(lower_join\<cdot>xsss)"
huffman@25904
   469
by (induct xsss rule: lower_pd_induct, simp_all)
huffman@25904
   470
huffman@25904
   471
lemma lower_join_map_map:
huffman@25904
   472
  "lower_join\<cdot>(lower_map\<cdot>(lower_map\<cdot>f)\<cdot>xss) =
huffman@25904
   473
   lower_map\<cdot>f\<cdot>(lower_join\<cdot>xss)"
huffman@25904
   474
by (induct xss rule: lower_pd_induct, simp_all)
huffman@25904
   475
huffman@25904
   476
lemma lower_map_approx: "lower_map\<cdot>(approx n)\<cdot>xs = approx n\<cdot>xs"
huffman@25904
   477
by (induct xs rule: lower_pd_induct, simp_all)
huffman@25904
   478
huffman@25904
   479
end