src/HOLCF/Algebraic.thy
author Brian Huffman <brianh@cs.pdx.edu>
Tue Oct 05 17:36:45 2010 -0700 (2010-10-05)
changeset 39972 4244ff4f9649
parent 39971 2949af5e6b9c
child 39974 b525988432e9
permissions -rw-r--r--
add lemmas finite_deflation_imp_compact, cast_below_cast_iff
huffman@27409
     1
(*  Title:      HOLCF/Algebraic.thy
huffman@27409
     2
    Author:     Brian Huffman
huffman@27409
     3
*)
huffman@27409
     4
huffman@27409
     5
header {* Algebraic deflations *}
huffman@27409
     6
huffman@27409
     7
theory Algebraic
huffman@39967
     8
imports Completion Fix Eventual Bifinite
huffman@27409
     9
begin
huffman@27409
    10
huffman@27409
    11
subsection {* Constructing finite deflations by iteration *}
huffman@27409
    12
huffman@27409
    13
lemma le_Suc_induct:
huffman@27409
    14
  assumes le: "i \<le> j"
huffman@27409
    15
  assumes step: "\<And>i. P i (Suc i)"
huffman@27409
    16
  assumes refl: "\<And>i. P i i"
huffman@27409
    17
  assumes trans: "\<And>i j k. \<lbrakk>P i j; P j k\<rbrakk> \<Longrightarrow> P i k"
huffman@27409
    18
  shows "P i j"
huffman@27409
    19
proof (cases "i = j")
huffman@27409
    20
  assume "i = j"
huffman@27409
    21
  thus "P i j" by (simp add: refl)
huffman@27409
    22
next
huffman@27409
    23
  assume "i \<noteq> j"
huffman@27409
    24
  with le have "i < j" by simp
huffman@27409
    25
  thus "P i j" using step trans by (rule less_Suc_induct)
huffman@27409
    26
qed
huffman@27409
    27
huffman@31164
    28
definition
huffman@31164
    29
  eventual_iterate :: "('a \<rightarrow> 'a::cpo) \<Rightarrow> ('a \<rightarrow> 'a)"
huffman@31164
    30
where
huffman@31164
    31
  "eventual_iterate f = eventual (\<lambda>n. iterate n\<cdot>f)"
huffman@31164
    32
huffman@27409
    33
text {* A pre-deflation is like a deflation, but not idempotent. *}
huffman@27409
    34
huffman@27409
    35
locale pre_deflation =
huffman@27409
    36
  fixes f :: "'a \<rightarrow> 'a::cpo"
huffman@31076
    37
  assumes below: "\<And>x. f\<cdot>x \<sqsubseteq> x"
huffman@27409
    38
  assumes finite_range: "finite (range (\<lambda>x. f\<cdot>x))"
huffman@27409
    39
begin
huffman@27409
    40
huffman@31076
    41
lemma iterate_below: "iterate i\<cdot>f\<cdot>x \<sqsubseteq> x"
huffman@31076
    42
by (induct i, simp_all add: below_trans [OF below])
huffman@27409
    43
huffman@27409
    44
lemma iterate_fixed: "f\<cdot>x = x \<Longrightarrow> iterate i\<cdot>f\<cdot>x = x"
huffman@27409
    45
by (induct i, simp_all)
huffman@27409
    46
huffman@27409
    47
lemma antichain_iterate_app: "i \<le> j \<Longrightarrow> iterate j\<cdot>f\<cdot>x \<sqsubseteq> iterate i\<cdot>f\<cdot>x"
huffman@27409
    48
apply (erule le_Suc_induct)
huffman@31076
    49
apply (simp add: below)
huffman@31076
    50
apply (rule below_refl)
huffman@31076
    51
apply (erule (1) below_trans)
huffman@27409
    52
done
huffman@27409
    53
huffman@27409
    54
lemma finite_range_iterate_app: "finite (range (\<lambda>i. iterate i\<cdot>f\<cdot>x))"
huffman@27409
    55
proof (rule finite_subset)
huffman@27409
    56
  show "range (\<lambda>i. iterate i\<cdot>f\<cdot>x) \<subseteq> insert x (range (\<lambda>x. f\<cdot>x))"
huffman@27409
    57
    by (clarify, case_tac i, simp_all)
huffman@27409
    58
  show "finite (insert x (range (\<lambda>x. f\<cdot>x)))"
huffman@27409
    59
    by (simp add: finite_range)
huffman@27409
    60
qed
huffman@27409
    61
huffman@27409
    62
lemma eventually_constant_iterate_app:
huffman@27409
    63
  "eventually_constant (\<lambda>i. iterate i\<cdot>f\<cdot>x)"
huffman@27409
    64
unfolding eventually_constant_def MOST_nat_le
huffman@27409
    65
proof -
huffman@27409
    66
  let ?Y = "\<lambda>i. iterate i\<cdot>f\<cdot>x"
huffman@27409
    67
  have "\<exists>j. \<forall>k. ?Y j \<sqsubseteq> ?Y k"
huffman@27409
    68
    apply (rule finite_range_has_max)
huffman@27409
    69
    apply (erule antichain_iterate_app)
huffman@27409
    70
    apply (rule finite_range_iterate_app)
huffman@27409
    71
    done
huffman@27409
    72
  then obtain j where j: "\<And>k. ?Y j \<sqsubseteq> ?Y k" by fast
huffman@27409
    73
  show "\<exists>z m. \<forall>n\<ge>m. ?Y n = z"
huffman@27409
    74
  proof (intro exI allI impI)
huffman@27409
    75
    fix k
huffman@27409
    76
    assume "j \<le> k"
huffman@27409
    77
    hence "?Y k \<sqsubseteq> ?Y j" by (rule antichain_iterate_app)
huffman@27409
    78
    also have "?Y j \<sqsubseteq> ?Y k" by (rule j)
huffman@27409
    79
    finally show "?Y k = ?Y j" .
huffman@27409
    80
  qed
huffman@27409
    81
qed
huffman@27409
    82
huffman@27409
    83
lemma eventually_constant_iterate:
huffman@27409
    84
  "eventually_constant (\<lambda>n. iterate n\<cdot>f)"
huffman@27409
    85
proof -
huffman@27409
    86
  have "\<forall>y\<in>range (\<lambda>x. f\<cdot>x). eventually_constant (\<lambda>i. iterate i\<cdot>f\<cdot>y)"
huffman@27409
    87
    by (simp add: eventually_constant_iterate_app)
huffman@27409
    88
  hence "\<forall>y\<in>range (\<lambda>x. f\<cdot>x). MOST i. MOST j. iterate j\<cdot>f\<cdot>y = iterate i\<cdot>f\<cdot>y"
huffman@27409
    89
    unfolding eventually_constant_MOST_MOST .
huffman@27409
    90
  hence "MOST i. MOST j. \<forall>y\<in>range (\<lambda>x. f\<cdot>x). iterate j\<cdot>f\<cdot>y = iterate i\<cdot>f\<cdot>y"
huffman@27409
    91
    by (simp only: MOST_finite_Ball_distrib [OF finite_range])
huffman@27409
    92
  hence "MOST i. MOST j. \<forall>x. iterate j\<cdot>f\<cdot>(f\<cdot>x) = iterate i\<cdot>f\<cdot>(f\<cdot>x)"
huffman@27409
    93
    by simp
huffman@27409
    94
  hence "MOST i. MOST j. \<forall>x. iterate (Suc j)\<cdot>f\<cdot>x = iterate (Suc i)\<cdot>f\<cdot>x"
huffman@27409
    95
    by (simp only: iterate_Suc2)
huffman@27409
    96
  hence "MOST i. MOST j. iterate (Suc j)\<cdot>f = iterate (Suc i)\<cdot>f"
huffman@27409
    97
    by (simp only: expand_cfun_eq)
huffman@27409
    98
  hence "eventually_constant (\<lambda>i. iterate (Suc i)\<cdot>f)"
huffman@27409
    99
    unfolding eventually_constant_MOST_MOST .
huffman@27409
   100
  thus "eventually_constant (\<lambda>i. iterate i\<cdot>f)"
huffman@27409
   101
    by (rule eventually_constant_SucD)
huffman@27409
   102
qed
huffman@27409
   103
huffman@27409
   104
abbreviation
huffman@27409
   105
  d :: "'a \<rightarrow> 'a"
huffman@27409
   106
where
huffman@31164
   107
  "d \<equiv> eventual_iterate f"
huffman@27409
   108
huffman@27409
   109
lemma MOST_d: "MOST n. P (iterate n\<cdot>f) \<Longrightarrow> P d"
huffman@31164
   110
unfolding eventual_iterate_def
huffman@27409
   111
using eventually_constant_iterate by (rule MOST_eventual)
huffman@27409
   112
huffman@27409
   113
lemma f_d: "f\<cdot>(d\<cdot>x) = d\<cdot>x"
huffman@27409
   114
apply (rule MOST_d)
huffman@27409
   115
apply (subst iterate_Suc [symmetric])
huffman@27409
   116
apply (rule eventually_constant_MOST_Suc_eq)
huffman@27409
   117
apply (rule eventually_constant_iterate_app)
huffman@27409
   118
done
huffman@27409
   119
huffman@27409
   120
lemma d_fixed_iff: "d\<cdot>x = x \<longleftrightarrow> f\<cdot>x = x"
huffman@27409
   121
proof
huffman@27409
   122
  assume "d\<cdot>x = x"
huffman@27409
   123
  with f_d [where x=x]
huffman@27409
   124
  show "f\<cdot>x = x" by simp
huffman@27409
   125
next
huffman@27409
   126
  assume f: "f\<cdot>x = x"
huffman@27409
   127
  have "\<forall>n. iterate n\<cdot>f\<cdot>x = x"
huffman@27409
   128
    by (rule allI, rule nat.induct, simp, simp add: f)
huffman@27409
   129
  hence "MOST n. iterate n\<cdot>f\<cdot>x = x"
huffman@27409
   130
    by (rule ALL_MOST)
huffman@27409
   131
  thus "d\<cdot>x = x"
huffman@27409
   132
    by (rule MOST_d)
huffman@27409
   133
qed
huffman@27409
   134
huffman@27409
   135
lemma finite_deflation_d: "finite_deflation d"
huffman@27409
   136
proof
huffman@27409
   137
  fix x :: 'a
huffman@27409
   138
  have "d \<in> range (\<lambda>n. iterate n\<cdot>f)"
huffman@31164
   139
    unfolding eventual_iterate_def
huffman@27409
   140
    using eventually_constant_iterate
huffman@27409
   141
    by (rule eventual_mem_range)
huffman@27409
   142
  then obtain n where n: "d = iterate n\<cdot>f" ..
huffman@27409
   143
  have "iterate n\<cdot>f\<cdot>(d\<cdot>x) = d\<cdot>x"
huffman@27409
   144
    using f_d by (rule iterate_fixed)
huffman@27409
   145
  thus "d\<cdot>(d\<cdot>x) = d\<cdot>x"
huffman@27409
   146
    by (simp add: n)
huffman@27409
   147
next
huffman@27409
   148
  fix x :: 'a
huffman@27409
   149
  show "d\<cdot>x \<sqsubseteq> x"
huffman@31076
   150
    by (rule MOST_d, simp add: iterate_below)
huffman@27409
   151
next
huffman@27409
   152
  from finite_range
huffman@27409
   153
  have "finite {x. f\<cdot>x = x}"
huffman@27409
   154
    by (rule finite_range_imp_finite_fixes)
huffman@27409
   155
  thus "finite {x. d\<cdot>x = x}"
huffman@27409
   156
    by (simp add: d_fixed_iff)
huffman@27409
   157
qed
huffman@27409
   158
huffman@31164
   159
lemma deflation_d: "deflation d"
huffman@31164
   160
using finite_deflation_d
huffman@31164
   161
by (rule finite_deflation_imp_deflation)
huffman@31164
   162
huffman@27409
   163
end
huffman@27409
   164
huffman@31164
   165
lemma finite_deflation_eventual_iterate:
huffman@31164
   166
  "pre_deflation d \<Longrightarrow> finite_deflation (eventual_iterate d)"
huffman@31164
   167
by (rule pre_deflation.finite_deflation_d)
huffman@31164
   168
huffman@31164
   169
lemma pre_deflation_oo:
ballarin@28611
   170
  assumes "finite_deflation d"
huffman@27409
   171
  assumes f: "\<And>x. f\<cdot>x \<sqsubseteq> x"
huffman@27409
   172
  shows "pre_deflation (d oo f)"
huffman@27409
   173
proof
ballarin@29237
   174
  interpret d: finite_deflation d by fact
huffman@27409
   175
  fix x
huffman@27409
   176
  show "\<And>x. (d oo f)\<cdot>x \<sqsubseteq> x"
huffman@31076
   177
    by (simp, rule below_trans [OF d.below f])
huffman@27409
   178
  show "finite (range (\<lambda>x. (d oo f)\<cdot>x))"
huffman@27409
   179
    by (rule finite_subset [OF _ d.finite_range], auto)
huffman@27409
   180
qed
huffman@27409
   181
huffman@27409
   182
lemma eventual_iterate_oo_fixed_iff:
ballarin@28611
   183
  assumes "finite_deflation d"
huffman@27409
   184
  assumes f: "\<And>x. f\<cdot>x \<sqsubseteq> x"
huffman@31164
   185
  shows "eventual_iterate (d oo f)\<cdot>x = x \<longleftrightarrow> d\<cdot>x = x \<and> f\<cdot>x = x"
huffman@27409
   186
proof -
ballarin@29237
   187
  interpret d: finite_deflation d by fact
huffman@27409
   188
  let ?e = "d oo f"
ballarin@29237
   189
  interpret e: pre_deflation "d oo f"
huffman@27409
   190
    using `finite_deflation d` f
huffman@31164
   191
    by (rule pre_deflation_oo)
huffman@27409
   192
  let ?g = "eventual (\<lambda>n. iterate n\<cdot>?e)"
huffman@27409
   193
  show ?thesis
huffman@27409
   194
    apply (subst e.d_fixed_iff)
huffman@27409
   195
    apply simp
huffman@27409
   196
    apply safe
huffman@27409
   197
    apply (erule subst)
huffman@27409
   198
    apply (rule d.idem)
huffman@31076
   199
    apply (rule below_antisym)
huffman@27409
   200
    apply (rule f)
huffman@31076
   201
    apply (erule subst, rule d.below)
huffman@27409
   202
    apply simp
huffman@27409
   203
    done
huffman@27409
   204
qed
huffman@27409
   205
huffman@31164
   206
lemma eventual_mono:
huffman@31164
   207
  assumes A: "eventually_constant A"
huffman@31164
   208
  assumes B: "eventually_constant B"
huffman@31164
   209
  assumes below: "\<And>n. A n \<sqsubseteq> B n"
huffman@31164
   210
  shows "eventual A \<sqsubseteq> eventual B"
huffman@31164
   211
proof -
huffman@31164
   212
  from A have "MOST n. A n = eventual A"
huffman@31164
   213
    by (rule MOST_eq_eventual)
huffman@31164
   214
  then have "MOST n. eventual A \<sqsubseteq> B n"
huffman@31164
   215
    by (rule MOST_mono) (erule subst, rule below)
huffman@31164
   216
  with B show "eventual A \<sqsubseteq> eventual B"
huffman@31164
   217
    by (rule MOST_eventual)
huffman@31164
   218
qed
huffman@31164
   219
huffman@31164
   220
lemma eventual_iterate_mono:
huffman@31164
   221
  assumes f: "pre_deflation f" and g: "pre_deflation g" and "f \<sqsubseteq> g"
huffman@31164
   222
  shows "eventual_iterate f \<sqsubseteq> eventual_iterate g"
huffman@31164
   223
unfolding eventual_iterate_def
huffman@31164
   224
apply (rule eventual_mono)
huffman@31164
   225
apply (rule pre_deflation.eventually_constant_iterate [OF f])
huffman@31164
   226
apply (rule pre_deflation.eventually_constant_iterate [OF g])
huffman@31164
   227
apply (rule monofun_cfun_arg [OF `f \<sqsubseteq> g`])
huffman@31164
   228
done
huffman@31164
   229
huffman@31164
   230
lemma cont2cont_eventual_iterate_oo:
huffman@31164
   231
  assumes d: "finite_deflation d"
huffman@31164
   232
  assumes cont: "cont f" and below: "\<And>x y. f x\<cdot>y \<sqsubseteq> y"
huffman@31164
   233
  shows "cont (\<lambda>x. eventual_iterate (d oo f x))"
huffman@31164
   234
    (is "cont ?e")
huffman@31164
   235
proof (rule contI2)
huffman@31164
   236
  show "monofun ?e"
huffman@31164
   237
    apply (rule monofunI)
huffman@31164
   238
    apply (rule eventual_iterate_mono)
huffman@31164
   239
    apply (rule pre_deflation_oo [OF d below])
huffman@31164
   240
    apply (rule pre_deflation_oo [OF d below])
huffman@31164
   241
    apply (rule monofun_cfun_arg)
huffman@31164
   242
    apply (erule cont2monofunE [OF cont])
huffman@31164
   243
    done
huffman@31164
   244
next
huffman@31164
   245
  fix Y :: "nat \<Rightarrow> 'b"
huffman@31164
   246
  assume Y: "chain Y"
huffman@31164
   247
  with cont have fY: "chain (\<lambda>i. f (Y i))"
huffman@31164
   248
    by (rule ch2ch_cont)
huffman@31164
   249
  assume eY: "chain (\<lambda>i. ?e (Y i))"
huffman@31164
   250
  have lub_below: "\<And>x. f (\<Squnion>i. Y i)\<cdot>x \<sqsubseteq> x"
huffman@31164
   251
    by (rule admD [OF _ Y], simp add: cont, rule below)
huffman@31164
   252
  have "deflation (?e (\<Squnion>i. Y i))"
huffman@31164
   253
    apply (rule pre_deflation.deflation_d)
huffman@31164
   254
    apply (rule pre_deflation_oo [OF d lub_below])
huffman@31164
   255
    done
huffman@31164
   256
  then show "?e (\<Squnion>i. Y i) \<sqsubseteq> (\<Squnion>i. ?e (Y i))"
huffman@31164
   257
  proof (rule deflation.belowI)
huffman@31164
   258
    fix x :: 'a
huffman@31164
   259
    assume "?e (\<Squnion>i. Y i)\<cdot>x = x"
huffman@31164
   260
    hence "d\<cdot>x = x" and "f (\<Squnion>i. Y i)\<cdot>x = x"
huffman@31164
   261
      by (simp_all add: eventual_iterate_oo_fixed_iff [OF d lub_below])
huffman@31164
   262
    hence "(\<Squnion>i. f (Y i)\<cdot>x) = x"
huffman@31164
   263
      apply (simp only: cont2contlubE [OF cont Y])
huffman@31164
   264
      apply (simp only: contlub_cfun_fun [OF fY])
huffman@31164
   265
      done
huffman@31164
   266
    have "compact (d\<cdot>x)"
huffman@31164
   267
      using d by (rule finite_deflation.compact)
huffman@31164
   268
    then have "compact x"
huffman@31164
   269
      using `d\<cdot>x = x` by simp
huffman@31164
   270
    then have "compact (\<Squnion>i. f (Y i)\<cdot>x)"
huffman@31164
   271
      using `(\<Squnion>i. f (Y i)\<cdot>x) = x` by simp
huffman@31164
   272
    then have "\<exists>n. max_in_chain n (\<lambda>i. f (Y i)\<cdot>x)"
huffman@31164
   273
      by - (rule compact_imp_max_in_chain, simp add: fY, assumption)
huffman@31164
   274
    then obtain n where n: "max_in_chain n (\<lambda>i. f (Y i)\<cdot>x)" ..
huffman@31164
   275
    then have "f (Y n)\<cdot>x = x"
huffman@31164
   276
      using `(\<Squnion>i. f (Y i)\<cdot>x) = x` fY by (simp add: maxinch_is_thelub)
huffman@31164
   277
    with `d\<cdot>x = x` have "?e (Y n)\<cdot>x = x"
huffman@31164
   278
      by (simp add: eventual_iterate_oo_fixed_iff [OF d below])
huffman@31164
   279
    moreover have "?e (Y n)\<cdot>x \<sqsubseteq> (\<Squnion>i. ?e (Y i)\<cdot>x)"
huffman@31164
   280
      by (rule is_ub_thelub, simp add: eY)
huffman@31164
   281
    ultimately have "x \<sqsubseteq> (\<Squnion>i. ?e (Y i))\<cdot>x"
huffman@31164
   282
      by (simp add: contlub_cfun_fun eY)
huffman@31164
   283
    also have "(\<Squnion>i. ?e (Y i))\<cdot>x \<sqsubseteq> x"
huffman@31164
   284
      apply (rule deflation.below)
huffman@31164
   285
      apply (rule admD [OF adm_deflation eY])
huffman@31164
   286
      apply (rule pre_deflation.deflation_d)
huffman@31164
   287
      apply (rule pre_deflation_oo [OF d below])
huffman@31164
   288
      done
huffman@31164
   289
    finally show "(\<Squnion>i. ?e (Y i))\<cdot>x = x" ..
huffman@31164
   290
  qed
huffman@31164
   291
qed
huffman@31164
   292
huffman@31164
   293
huffman@27409
   294
subsection {* Type constructor for finite deflations *}
huffman@27409
   295
wenzelm@36452
   296
default_sort profinite
huffman@27409
   297
huffman@27409
   298
typedef (open) 'a fin_defl = "{d::'a \<rightarrow> 'a. finite_deflation d}"
huffman@27409
   299
by (fast intro: finite_deflation_approx)
huffman@27409
   300
huffman@31076
   301
instantiation fin_defl :: (profinite) below
huffman@27409
   302
begin
huffman@27409
   303
huffman@31076
   304
definition below_fin_defl_def:
huffman@27409
   305
    "op \<sqsubseteq> \<equiv> \<lambda>x y. Rep_fin_defl x \<sqsubseteq> Rep_fin_defl y"
huffman@27409
   306
huffman@27409
   307
instance ..
huffman@27409
   308
end
huffman@27409
   309
huffman@27409
   310
instance fin_defl :: (profinite) po
huffman@31076
   311
by (rule typedef_po [OF type_definition_fin_defl below_fin_defl_def])
huffman@27409
   312
huffman@27409
   313
lemma finite_deflation_Rep_fin_defl: "finite_deflation (Rep_fin_defl d)"
huffman@27409
   314
using Rep_fin_defl by simp
huffman@27409
   315
huffman@31164
   316
lemma deflation_Rep_fin_defl: "deflation (Rep_fin_defl d)"
huffman@31164
   317
using finite_deflation_Rep_fin_defl
huffman@31164
   318
by (rule finite_deflation_imp_deflation)
huffman@31164
   319
wenzelm@30729
   320
interpretation Rep_fin_defl: finite_deflation "Rep_fin_defl d"
huffman@27409
   321
by (rule finite_deflation_Rep_fin_defl)
huffman@27409
   322
huffman@31076
   323
lemma fin_defl_belowI:
huffman@27409
   324
  "(\<And>x. Rep_fin_defl a\<cdot>x = x \<Longrightarrow> Rep_fin_defl b\<cdot>x = x) \<Longrightarrow> a \<sqsubseteq> b"
huffman@31076
   325
unfolding below_fin_defl_def
huffman@31076
   326
by (rule Rep_fin_defl.belowI)
huffman@27409
   327
huffman@31076
   328
lemma fin_defl_belowD:
huffman@27409
   329
  "\<lbrakk>a \<sqsubseteq> b; Rep_fin_defl a\<cdot>x = x\<rbrakk> \<Longrightarrow> Rep_fin_defl b\<cdot>x = x"
huffman@31076
   330
unfolding below_fin_defl_def
huffman@31076
   331
by (rule Rep_fin_defl.belowD)
huffman@27409
   332
huffman@27409
   333
lemma fin_defl_eqI:
huffman@27409
   334
  "(\<And>x. Rep_fin_defl a\<cdot>x = x \<longleftrightarrow> Rep_fin_defl b\<cdot>x = x) \<Longrightarrow> a = b"
huffman@31076
   335
apply (rule below_antisym)
huffman@31076
   336
apply (rule fin_defl_belowI, simp)
huffman@31076
   337
apply (rule fin_defl_belowI, simp)
huffman@27409
   338
done
huffman@27409
   339
huffman@27409
   340
lemma Abs_fin_defl_mono:
huffman@27409
   341
  "\<lbrakk>finite_deflation a; finite_deflation b; a \<sqsubseteq> b\<rbrakk>
huffman@27409
   342
    \<Longrightarrow> Abs_fin_defl a \<sqsubseteq> Abs_fin_defl b"
huffman@31076
   343
unfolding below_fin_defl_def
huffman@27409
   344
by (simp add: Abs_fin_defl_inverse)
huffman@27409
   345
huffman@27409
   346
huffman@27409
   347
subsection {* Take function for finite deflations *}
huffman@27409
   348
huffman@27409
   349
definition
huffman@31164
   350
  defl_approx :: "nat \<Rightarrow> ('a \<rightarrow> 'a) \<Rightarrow> ('a \<rightarrow> 'a)"
huffman@31164
   351
where
huffman@31164
   352
  "defl_approx i d = eventual_iterate (approx i oo d)"
huffman@31164
   353
huffman@31164
   354
lemma finite_deflation_defl_approx:
huffman@31164
   355
  "deflation d \<Longrightarrow> finite_deflation (defl_approx i d)"
huffman@31164
   356
unfolding defl_approx_def
huffman@31164
   357
apply (rule pre_deflation.finite_deflation_d)
huffman@31164
   358
apply (rule pre_deflation_oo)
huffman@31164
   359
apply (rule finite_deflation_approx)
huffman@31164
   360
apply (erule deflation.below)
huffman@31164
   361
done
huffman@31164
   362
huffman@31164
   363
lemma deflation_defl_approx:
huffman@31164
   364
  "deflation d \<Longrightarrow> deflation (defl_approx i d)"
huffman@31164
   365
apply (rule finite_deflation_imp_deflation)
huffman@31164
   366
apply (erule finite_deflation_defl_approx)
huffman@31164
   367
done
huffman@31164
   368
huffman@31164
   369
lemma defl_approx_fixed_iff:
huffman@31164
   370
  "deflation d \<Longrightarrow> defl_approx i d\<cdot>x = x \<longleftrightarrow> approx i\<cdot>x = x \<and> d\<cdot>x = x"
huffman@31164
   371
unfolding defl_approx_def
huffman@31164
   372
apply (rule eventual_iterate_oo_fixed_iff)
huffman@31164
   373
apply (rule finite_deflation_approx)
huffman@31164
   374
apply (erule deflation.below)
huffman@31164
   375
done
huffman@31164
   376
huffman@31164
   377
lemma defl_approx_below:
huffman@31164
   378
  "\<lbrakk>a \<sqsubseteq> b; deflation a; deflation b\<rbrakk> \<Longrightarrow> defl_approx i a \<sqsubseteq> defl_approx i b"
huffman@31164
   379
apply (rule deflation.belowI)
huffman@31164
   380
apply (erule deflation_defl_approx)
huffman@31164
   381
apply (simp add: defl_approx_fixed_iff)
huffman@31164
   382
apply (erule (1) deflation.belowD)
huffman@31164
   383
apply (erule conjunct2)
huffman@31164
   384
done
huffman@31164
   385
huffman@31164
   386
lemma cont2cont_defl_approx:
huffman@31164
   387
  assumes cont: "cont f" and below: "\<And>x y. f x\<cdot>y \<sqsubseteq> y"
huffman@31164
   388
  shows "cont (\<lambda>x. defl_approx i (f x))"
huffman@31164
   389
unfolding defl_approx_def
huffman@31164
   390
using finite_deflation_approx assms
huffman@31164
   391
by (rule cont2cont_eventual_iterate_oo)
huffman@31164
   392
huffman@31164
   393
definition
huffman@27409
   394
  fd_take :: "nat \<Rightarrow> 'a fin_defl \<Rightarrow> 'a fin_defl"
huffman@27409
   395
where
huffman@31164
   396
  "fd_take i d = Abs_fin_defl (defl_approx i (Rep_fin_defl d))"
huffman@27409
   397
huffman@27409
   398
lemma Rep_fin_defl_fd_take:
huffman@31164
   399
  "Rep_fin_defl (fd_take i d) = defl_approx i (Rep_fin_defl d)"
huffman@27409
   400
unfolding fd_take_def
huffman@27409
   401
apply (rule Abs_fin_defl_inverse [unfolded mem_Collect_eq])
huffman@31164
   402
apply (rule finite_deflation_defl_approx)
huffman@31164
   403
apply (rule deflation_Rep_fin_defl)
huffman@27409
   404
done
huffman@27409
   405
huffman@27409
   406
lemma fd_take_fixed_iff:
huffman@27409
   407
  "Rep_fin_defl (fd_take i d)\<cdot>x = x \<longleftrightarrow>
huffman@27409
   408
    approx i\<cdot>x = x \<and> Rep_fin_defl d\<cdot>x = x"
huffman@27409
   409
unfolding Rep_fin_defl_fd_take
huffman@31164
   410
apply (rule defl_approx_fixed_iff)
huffman@31164
   411
apply (rule deflation_Rep_fin_defl)
huffman@31164
   412
done
huffman@27409
   413
huffman@31076
   414
lemma fd_take_below: "fd_take n d \<sqsubseteq> d"
huffman@31076
   415
apply (rule fin_defl_belowI)
huffman@27409
   416
apply (simp add: fd_take_fixed_iff)
huffman@27409
   417
done
huffman@27409
   418
huffman@27409
   419
lemma fd_take_idem: "fd_take n (fd_take n d) = fd_take n d"
huffman@27409
   420
apply (rule fin_defl_eqI)
huffman@27409
   421
apply (simp add: fd_take_fixed_iff)
huffman@27409
   422
done
huffman@27409
   423
huffman@27409
   424
lemma fd_take_mono: "a \<sqsubseteq> b \<Longrightarrow> fd_take n a \<sqsubseteq> fd_take n b"
huffman@31076
   425
apply (rule fin_defl_belowI)
huffman@27409
   426
apply (simp add: fd_take_fixed_iff)
huffman@31076
   427
apply (simp add: fin_defl_belowD)
huffman@27409
   428
done
huffman@27409
   429
huffman@27409
   430
lemma approx_fixed_le_lemma: "\<lbrakk>i \<le> j; approx i\<cdot>x = x\<rbrakk> \<Longrightarrow> approx j\<cdot>x = x"
huffman@27409
   431
by (erule subst, simp add: min_def)
huffman@27409
   432
huffman@27409
   433
lemma fd_take_chain: "m \<le> n \<Longrightarrow> fd_take m a \<sqsubseteq> fd_take n a"
huffman@31076
   434
apply (rule fin_defl_belowI)
huffman@27409
   435
apply (simp add: fd_take_fixed_iff)
huffman@27409
   436
apply (simp add: approx_fixed_le_lemma)
huffman@27409
   437
done
huffman@27409
   438
huffman@27409
   439
lemma finite_range_fd_take: "finite (range (fd_take n))"
huffman@27409
   440
apply (rule finite_imageD [where f="\<lambda>a. {x. Rep_fin_defl a\<cdot>x = x}"])
huffman@27409
   441
apply (rule finite_subset [where B="Pow {x. approx n\<cdot>x = x}"])
huffman@27409
   442
apply (clarify, simp add: fd_take_fixed_iff)
huffman@27409
   443
apply (simp add: finite_fixes_approx)
huffman@27409
   444
apply (rule inj_onI, clarify)
nipkow@39302
   445
apply (simp add: set_eq_iff fin_defl_eqI)
huffman@27409
   446
done
huffman@27409
   447
huffman@27409
   448
lemma fd_take_covers: "\<exists>n. fd_take n a = a"
huffman@27409
   449
apply (rule_tac x=
huffman@27409
   450
  "Max ((\<lambda>x. LEAST n. approx n\<cdot>x = x) ` {x. Rep_fin_defl a\<cdot>x = x})" in exI)
huffman@31076
   451
apply (rule below_antisym)
huffman@31076
   452
apply (rule fd_take_below)
huffman@31076
   453
apply (rule fin_defl_belowI)
huffman@27409
   454
apply (simp add: fd_take_fixed_iff)
huffman@27409
   455
apply (rule approx_fixed_le_lemma)
huffman@27409
   456
apply (rule Max_ge)
huffman@27409
   457
apply (rule finite_imageI)
huffman@27409
   458
apply (rule Rep_fin_defl.finite_fixes)
huffman@27409
   459
apply (rule imageI)
huffman@27409
   460
apply (erule CollectI)
huffman@27409
   461
apply (rule LeastI_ex)
huffman@27409
   462
apply (rule profinite_compact_eq_approx)
huffman@27409
   463
apply (erule subst)
huffman@27409
   464
apply (rule Rep_fin_defl.compact)
huffman@27409
   465
done
huffman@27409
   466
huffman@31076
   467
interpretation fin_defl: basis_take below fd_take
huffman@27409
   468
apply default
huffman@31076
   469
apply (rule fd_take_below)
huffman@27409
   470
apply (rule fd_take_idem)
huffman@27409
   471
apply (erule fd_take_mono)
huffman@27409
   472
apply (rule fd_take_chain, simp)
huffman@27409
   473
apply (rule finite_range_fd_take)
huffman@27409
   474
apply (rule fd_take_covers)
huffman@27409
   475
done
huffman@27409
   476
huffman@33586
   477
huffman@27409
   478
subsection {* Defining algebraic deflations by ideal completion *}
huffman@27409
   479
huffman@27409
   480
typedef (open) 'a alg_defl =
huffman@31076
   481
  "{S::'a fin_defl set. below.ideal S}"
huffman@31076
   482
by (fast intro: below.ideal_principal)
huffman@27409
   483
huffman@31076
   484
instantiation alg_defl :: (profinite) below
huffman@27409
   485
begin
huffman@27409
   486
huffman@27409
   487
definition
huffman@27409
   488
  "x \<sqsubseteq> y \<longleftrightarrow> Rep_alg_defl x \<subseteq> Rep_alg_defl y"
huffman@27409
   489
huffman@27409
   490
instance ..
huffman@27409
   491
end
huffman@27409
   492
huffman@27409
   493
instance alg_defl :: (profinite) po
huffman@31076
   494
by (rule below.typedef_ideal_po
huffman@31076
   495
    [OF type_definition_alg_defl below_alg_defl_def])
huffman@27409
   496
huffman@27409
   497
instance alg_defl :: (profinite) cpo
huffman@31076
   498
by (rule below.typedef_ideal_cpo
huffman@31076
   499
    [OF type_definition_alg_defl below_alg_defl_def])
huffman@27409
   500
huffman@27409
   501
lemma Rep_alg_defl_lub:
huffman@27409
   502
  "chain Y \<Longrightarrow> Rep_alg_defl (\<Squnion>i. Y i) = (\<Union>i. Rep_alg_defl (Y i))"
huffman@31076
   503
by (rule below.typedef_ideal_rep_contlub
huffman@31076
   504
    [OF type_definition_alg_defl below_alg_defl_def])
huffman@27409
   505
huffman@31076
   506
lemma ideal_Rep_alg_defl: "below.ideal (Rep_alg_defl xs)"
huffman@27409
   507
by (rule Rep_alg_defl [unfolded mem_Collect_eq])
huffman@27409
   508
huffman@27409
   509
definition
huffman@27409
   510
  alg_defl_principal :: "'a fin_defl \<Rightarrow> 'a alg_defl" where
huffman@27409
   511
  "alg_defl_principal t = Abs_alg_defl {u. u \<sqsubseteq> t}"
huffman@27409
   512
huffman@27409
   513
lemma Rep_alg_defl_principal:
huffman@27409
   514
  "Rep_alg_defl (alg_defl_principal t) = {u. u \<sqsubseteq> t}"
huffman@27409
   515
unfolding alg_defl_principal_def
huffman@31076
   516
by (simp add: Abs_alg_defl_inverse below.ideal_principal)
huffman@27409
   517
wenzelm@30729
   518
interpretation alg_defl:
huffman@31076
   519
  ideal_completion below fd_take alg_defl_principal Rep_alg_defl
huffman@27409
   520
apply default
huffman@27409
   521
apply (rule ideal_Rep_alg_defl)
huffman@27409
   522
apply (erule Rep_alg_defl_lub)
huffman@27409
   523
apply (rule Rep_alg_defl_principal)
huffman@31076
   524
apply (simp only: below_alg_defl_def)
huffman@27409
   525
done
huffman@27409
   526
huffman@27409
   527
text {* Algebraic deflations are pointed *}
huffman@27409
   528
huffman@27409
   529
lemma alg_defl_minimal:
huffman@27409
   530
  "alg_defl_principal (Abs_fin_defl \<bottom>) \<sqsubseteq> x"
huffman@27409
   531
apply (induct x rule: alg_defl.principal_induct, simp)
huffman@27409
   532
apply (rule alg_defl.principal_mono)
huffman@27409
   533
apply (induct_tac a)
huffman@27409
   534
apply (rule Abs_fin_defl_mono)
huffman@27409
   535
apply (rule finite_deflation_UU)
huffman@27409
   536
apply simp
huffman@27409
   537
apply (rule minimal)
huffman@27409
   538
done
huffman@27409
   539
huffman@27409
   540
instance alg_defl :: (bifinite) pcpo
huffman@27409
   541
by intro_classes (fast intro: alg_defl_minimal)
huffman@27409
   542
huffman@27409
   543
lemma inst_alg_defl_pcpo: "\<bottom> = alg_defl_principal (Abs_fin_defl \<bottom>)"
huffman@27409
   544
by (rule alg_defl_minimal [THEN UU_I, symmetric])
huffman@27409
   545
huffman@27409
   546
text {* Algebraic deflations are profinite *}
huffman@27409
   547
huffman@27409
   548
instantiation alg_defl :: (profinite) profinite
huffman@27409
   549
begin
huffman@27409
   550
huffman@27409
   551
definition
huffman@27409
   552
  approx_alg_defl_def: "approx = alg_defl.completion_approx"
huffman@27409
   553
huffman@27409
   554
instance
huffman@27409
   555
apply (intro_classes, unfold approx_alg_defl_def)
huffman@27409
   556
apply (rule alg_defl.chain_completion_approx)
huffman@27409
   557
apply (rule alg_defl.lub_completion_approx)
huffman@27409
   558
apply (rule alg_defl.completion_approx_idem)
huffman@27409
   559
apply (rule alg_defl.finite_fixes_completion_approx)
huffman@27409
   560
done
huffman@27409
   561
huffman@27409
   562
end
huffman@27409
   563
huffman@27409
   564
instance alg_defl :: (bifinite) bifinite ..
huffman@27409
   565
huffman@27409
   566
lemma approx_alg_defl_principal [simp]:
huffman@27409
   567
  "approx n\<cdot>(alg_defl_principal t) = alg_defl_principal (fd_take n t)"
huffman@27409
   568
unfolding approx_alg_defl_def
huffman@27409
   569
by (rule alg_defl.completion_approx_principal)
huffman@27409
   570
huffman@27409
   571
lemma approx_eq_alg_defl_principal:
huffman@27409
   572
  "\<exists>t\<in>Rep_alg_defl xs. approx n\<cdot>xs = alg_defl_principal (fd_take n t)"
huffman@27409
   573
unfolding approx_alg_defl_def
huffman@27409
   574
by (rule alg_defl.completion_approx_eq_principal)
huffman@27409
   575
huffman@27409
   576
huffman@27409
   577
subsection {* Applying algebraic deflations *}
huffman@27409
   578
huffman@27409
   579
definition
huffman@27409
   580
  cast :: "'a alg_defl \<rightarrow> 'a \<rightarrow> 'a"
huffman@27409
   581
where
huffman@27409
   582
  "cast = alg_defl.basis_fun Rep_fin_defl"
huffman@27409
   583
huffman@27409
   584
lemma cast_alg_defl_principal:
huffman@27409
   585
  "cast\<cdot>(alg_defl_principal a) = Rep_fin_defl a"
huffman@27409
   586
unfolding cast_def
huffman@27409
   587
apply (rule alg_defl.basis_fun_principal)
huffman@31076
   588
apply (simp only: below_fin_defl_def)
huffman@27409
   589
done
huffman@27409
   590
huffman@27409
   591
lemma deflation_cast: "deflation (cast\<cdot>d)"
huffman@27409
   592
apply (induct d rule: alg_defl.principal_induct)
huffman@27409
   593
apply (rule adm_subst [OF _ adm_deflation], simp)
huffman@27409
   594
apply (simp add: cast_alg_defl_principal)
huffman@27409
   595
apply (rule finite_deflation_imp_deflation)
huffman@27409
   596
apply (rule finite_deflation_Rep_fin_defl)
huffman@27409
   597
done
huffman@27409
   598
huffman@27409
   599
lemma finite_deflation_cast:
huffman@27409
   600
  "compact d \<Longrightarrow> finite_deflation (cast\<cdot>d)"
huffman@27409
   601
apply (drule alg_defl.compact_imp_principal, clarify)
huffman@27409
   602
apply (simp add: cast_alg_defl_principal)
huffman@27409
   603
apply (rule finite_deflation_Rep_fin_defl)
huffman@27409
   604
done
huffman@27409
   605
wenzelm@30729
   606
interpretation cast: deflation "cast\<cdot>d"
huffman@27409
   607
by (rule deflation_cast)
huffman@27409
   608
huffman@33586
   609
declare cast.idem [simp]
huffman@33586
   610
huffman@31164
   611
lemma cast_approx: "cast\<cdot>(approx n\<cdot>A) = defl_approx n (cast\<cdot>A)"
huffman@31164
   612
apply (rule alg_defl.principal_induct)
huffman@31164
   613
apply (rule adm_eq)
huffman@31164
   614
apply simp
huffman@31164
   615
apply (simp add: cont2cont_defl_approx cast.below)
huffman@31164
   616
apply (simp only: approx_alg_defl_principal)
huffman@31164
   617
apply (simp only: cast_alg_defl_principal)
huffman@31164
   618
apply (simp only: Rep_fin_defl_fd_take)
huffman@31164
   619
done
huffman@31164
   620
huffman@31164
   621
lemma cast_approx_fixed_iff:
huffman@31164
   622
  "cast\<cdot>(approx i\<cdot>A)\<cdot>x = x \<longleftrightarrow> approx i\<cdot>x = x \<and> cast\<cdot>A\<cdot>x = x"
huffman@31164
   623
apply (simp only: cast_approx)
huffman@31164
   624
apply (rule defl_approx_fixed_iff)
huffman@31164
   625
apply (rule deflation_cast)
huffman@31164
   626
done
huffman@31164
   627
huffman@31164
   628
lemma defl_approx_cast: "defl_approx i (cast\<cdot>A) = cast\<cdot>(approx i\<cdot>A)"
huffman@31164
   629
by (rule cast_approx [symmetric])
huffman@31164
   630
brianh@39972
   631
lemma cast_below_cast_iff: "cast\<cdot>A \<sqsubseteq> cast\<cdot>B \<longleftrightarrow> A \<sqsubseteq> B"
brianh@39972
   632
apply (induct A rule: alg_defl.principal_induct, simp)
brianh@39972
   633
apply (induct B rule: alg_defl.principal_induct)
brianh@39972
   634
apply (simp add: cast_alg_defl_principal)
brianh@39972
   635
apply (simp add: finite_deflation_imp_compact finite_deflation_Rep_fin_defl)
brianh@39972
   636
apply (simp add: cast_alg_defl_principal below_fin_defl_def)
brianh@39972
   637
done
brianh@39972
   638
huffman@31164
   639
lemma cast_below_imp_below: "cast\<cdot>A \<sqsubseteq> cast\<cdot>B \<Longrightarrow> A \<sqsubseteq> B"
brianh@39972
   640
by (simp only: cast_below_cast_iff)
huffman@31164
   641
huffman@33586
   642
lemma cast_eq_imp_eq: "cast\<cdot>A = cast\<cdot>B \<Longrightarrow> A = B"
huffman@33586
   643
by (simp add: below_antisym cast_below_imp_below)
huffman@33586
   644
huffman@33586
   645
lemma cast_strict1 [simp]: "cast\<cdot>\<bottom> = \<bottom>"
huffman@33586
   646
apply (subst inst_alg_defl_pcpo)
huffman@33586
   647
apply (subst cast_alg_defl_principal)
huffman@33586
   648
apply (rule Abs_fin_defl_inverse)
huffman@33586
   649
apply (simp add: finite_deflation_UU)
huffman@33586
   650
done
huffman@33586
   651
huffman@33586
   652
lemma cast_strict2 [simp]: "cast\<cdot>A\<cdot>\<bottom> = \<bottom>"
huffman@33586
   653
by (rule cast.below [THEN UU_I])
huffman@33586
   654
huffman@33586
   655
huffman@33586
   656
subsection {* Deflation membership relation *}
huffman@33586
   657
huffman@33586
   658
definition
huffman@33586
   659
  in_deflation :: "'a::profinite \<Rightarrow> 'a alg_defl \<Rightarrow> bool" (infixl ":::" 50)
huffman@33586
   660
where
huffman@33586
   661
  "x ::: A \<longleftrightarrow> cast\<cdot>A\<cdot>x = x"
huffman@33586
   662
huffman@33586
   663
lemma adm_in_deflation: "adm (\<lambda>x. x ::: A)"
huffman@33586
   664
unfolding in_deflation_def by simp
huffman@33586
   665
huffman@33586
   666
lemma in_deflationI: "cast\<cdot>A\<cdot>x = x \<Longrightarrow> x ::: A"
huffman@33586
   667
unfolding in_deflation_def .
huffman@33586
   668
huffman@33586
   669
lemma cast_fixed: "x ::: A \<Longrightarrow> cast\<cdot>A\<cdot>x = x"
huffman@33586
   670
unfolding in_deflation_def .
huffman@33586
   671
huffman@33586
   672
lemma cast_in_deflation [simp]: "cast\<cdot>A\<cdot>x ::: A"
huffman@33586
   673
unfolding in_deflation_def by (rule cast.idem)
huffman@33586
   674
huffman@33586
   675
lemma bottom_in_deflation [simp]: "\<bottom> ::: A"
huffman@33586
   676
unfolding in_deflation_def by (rule cast_strict2)
huffman@33586
   677
huffman@33586
   678
lemma subdeflationD: "A \<sqsubseteq> B \<Longrightarrow> x ::: A \<Longrightarrow> x ::: B"
huffman@33586
   679
unfolding in_deflation_def
huffman@33586
   680
 apply (rule deflation.belowD)
huffman@33586
   681
   apply (rule deflation_cast)
huffman@33586
   682
  apply (erule monofun_cfun_arg)
huffman@33586
   683
 apply assumption
huffman@33586
   684
done
huffman@33586
   685
huffman@33586
   686
lemma rev_subdeflationD: "x ::: A \<Longrightarrow> A \<sqsubseteq> B \<Longrightarrow> x ::: B"
huffman@33586
   687
by (rule subdeflationD)
huffman@33586
   688
huffman@33586
   689
lemma subdeflationI: "(\<And>x. x ::: A \<Longrightarrow> x ::: B) \<Longrightarrow> A \<sqsubseteq> B"
huffman@33586
   690
apply (rule cast_below_imp_below)
huffman@33586
   691
apply (rule cast.belowI)
huffman@33586
   692
apply (simp add: in_deflation_def)
huffman@33586
   693
done
huffman@33586
   694
huffman@33586
   695
text "Identity deflation:"
huffman@33586
   696
huffman@27409
   697
lemma "cast\<cdot>(\<Squnion>i. alg_defl_principal (Abs_fin_defl (approx i)))\<cdot>x = x"
huffman@27409
   698
apply (subst contlub_cfun_arg)
huffman@27409
   699
apply (rule chainI)
huffman@27409
   700
apply (rule alg_defl.principal_mono)
huffman@27409
   701
apply (rule Abs_fin_defl_mono)
huffman@27409
   702
apply (rule finite_deflation_approx)
huffman@27409
   703
apply (rule finite_deflation_approx)
huffman@27409
   704
apply (rule chainE)
huffman@27409
   705
apply (rule chain_approx)
huffman@35901
   706
apply (simp add: cast_alg_defl_principal
huffman@35901
   707
  Abs_fin_defl_inverse finite_deflation_approx)
huffman@27409
   708
done
huffman@27409
   709
huffman@33586
   710
subsection {* Bifinite domains and algebraic deflations *}
huffman@33586
   711
huffman@27409
   712
text {* This lemma says that if we have an ep-pair from
huffman@27409
   713
a bifinite domain into a universal domain, then e oo p
huffman@27409
   714
is an algebraic deflation. *}
huffman@27409
   715
huffman@27409
   716
lemma
ballarin@28611
   717
  assumes "ep_pair e p"
huffman@27409
   718
  constrains e :: "'a::profinite \<rightarrow> 'b::profinite"
huffman@27409
   719
  shows "\<exists>d. cast\<cdot>d = e oo p"
huffman@27409
   720
proof
ballarin@29237
   721
  interpret ep_pair e p by fact
huffman@27409
   722
  let ?a = "\<lambda>i. e oo approx i oo p"
huffman@27409
   723
  have a: "\<And>i. finite_deflation (?a i)"
huffman@27409
   724
    apply (rule finite_deflation_e_d_p)
huffman@27409
   725
    apply (rule finite_deflation_approx)
huffman@27409
   726
    done
huffman@27409
   727
  let ?d = "\<Squnion>i. alg_defl_principal (Abs_fin_defl (?a i))"
huffman@27409
   728
  show "cast\<cdot>?d = e oo p"
huffman@27409
   729
    apply (subst contlub_cfun_arg)
huffman@27409
   730
    apply (rule chainI)
huffman@27409
   731
    apply (rule alg_defl.principal_mono)
huffman@27409
   732
    apply (rule Abs_fin_defl_mono [OF a a])
huffman@27409
   733
    apply (rule chainE, simp)
huffman@27409
   734
    apply (subst cast_alg_defl_principal)
huffman@27409
   735
    apply (simp add: Abs_fin_defl_inverse a)
huffman@27409
   736
    apply (simp add: expand_cfun_eq lub_distribs)
huffman@27409
   737
    done
huffman@27409
   738
qed
huffman@27409
   739
huffman@27409
   740
text {* This lemma says that if we have an ep-pair
huffman@27409
   741
from a cpo into a bifinite domain, and e oo p is
huffman@27409
   742
an algebraic deflation, then the cpo is bifinite. *}
huffman@27409
   743
huffman@27409
   744
lemma
ballarin@28611
   745
  assumes "ep_pair e p"
huffman@27409
   746
  constrains e :: "'a::cpo \<rightarrow> 'b::profinite"
huffman@27409
   747
  assumes d: "\<And>x. cast\<cdot>d\<cdot>x = e\<cdot>(p\<cdot>x)"
huffman@27409
   748
  obtains a :: "nat \<Rightarrow> 'a \<rightarrow> 'a" where
huffman@27409
   749
    "\<And>i. finite_deflation (a i)"
huffman@27409
   750
    "(\<Squnion>i. a i) = ID"
huffman@27409
   751
proof
ballarin@29237
   752
  interpret ep_pair e p by fact
huffman@27409
   753
  let ?a = "\<lambda>i. p oo cast\<cdot>(approx i\<cdot>d) oo e"
huffman@27409
   754
  show "\<And>i. finite_deflation (?a i)"
huffman@27409
   755
    apply (rule finite_deflation_p_d_e)
huffman@27409
   756
    apply (rule finite_deflation_cast)
huffman@27409
   757
    apply (rule compact_approx)
huffman@31076
   758
    apply (rule below_eq_trans [OF _ d])
huffman@27409
   759
    apply (rule monofun_cfun_fun)
huffman@27409
   760
    apply (rule monofun_cfun_arg)
huffman@31076
   761
    apply (rule approx_below)
huffman@27409
   762
    done
huffman@27409
   763
  show "(\<Squnion>i. ?a i) = ID"
huffman@27409
   764
    apply (rule ext_cfun, simp)
huffman@27409
   765
    apply (simp add: lub_distribs)
huffman@27409
   766
    apply (simp add: d)
huffman@27409
   767
    done
huffman@27409
   768
qed
huffman@27409
   769
huffman@27409
   770
end