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