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