src/HOLCF/Completion.thy
author huffman
Tue Jul 01 00:52:46 2008 +0200 (2008-07-01)
changeset 27404 62171da527d6
child 28053 a2106c0d8c45
permissions -rw-r--r--
split Completion.thy from CompactBasis.thy
huffman@27404
     1
(*  Title:      HOLCF/Completion.thy
huffman@27404
     2
    ID:         $Id$
huffman@27404
     3
    Author:     Brian Huffman
huffman@27404
     4
*)
huffman@27404
     5
huffman@27404
     6
header {* Defining bifinite domains by ideal completion *}
huffman@27404
     7
huffman@27404
     8
theory Completion
huffman@27404
     9
imports Bifinite
huffman@27404
    10
begin
huffman@27404
    11
huffman@27404
    12
subsection {* Ideals over a preorder *}
huffman@27404
    13
huffman@27404
    14
locale preorder =
huffman@27404
    15
  fixes r :: "'a::type \<Rightarrow> 'a \<Rightarrow> bool" (infix "\<preceq>" 50)
huffman@27404
    16
  assumes r_refl: "x \<preceq> x"
huffman@27404
    17
  assumes r_trans: "\<lbrakk>x \<preceq> y; y \<preceq> z\<rbrakk> \<Longrightarrow> x \<preceq> z"
huffman@27404
    18
begin
huffman@27404
    19
huffman@27404
    20
definition
huffman@27404
    21
  ideal :: "'a set \<Rightarrow> bool" where
huffman@27404
    22
  "ideal A = ((\<exists>x. x \<in> A) \<and> (\<forall>x\<in>A. \<forall>y\<in>A. \<exists>z\<in>A. x \<preceq> z \<and> y \<preceq> z) \<and>
huffman@27404
    23
    (\<forall>x y. x \<preceq> y \<longrightarrow> y \<in> A \<longrightarrow> x \<in> A))"
huffman@27404
    24
huffman@27404
    25
lemma idealI:
huffman@27404
    26
  assumes "\<exists>x. x \<in> A"
huffman@27404
    27
  assumes "\<And>x y. \<lbrakk>x \<in> A; y \<in> A\<rbrakk> \<Longrightarrow> \<exists>z\<in>A. x \<preceq> z \<and> y \<preceq> z"
huffman@27404
    28
  assumes "\<And>x y. \<lbrakk>x \<preceq> y; y \<in> A\<rbrakk> \<Longrightarrow> x \<in> A"
huffman@27404
    29
  shows "ideal A"
huffman@27404
    30
unfolding ideal_def using prems by fast
huffman@27404
    31
huffman@27404
    32
lemma idealD1:
huffman@27404
    33
  "ideal A \<Longrightarrow> \<exists>x. x \<in> A"
huffman@27404
    34
unfolding ideal_def by fast
huffman@27404
    35
huffman@27404
    36
lemma idealD2:
huffman@27404
    37
  "\<lbrakk>ideal A; x \<in> A; y \<in> A\<rbrakk> \<Longrightarrow> \<exists>z\<in>A. x \<preceq> z \<and> y \<preceq> z"
huffman@27404
    38
unfolding ideal_def by fast
huffman@27404
    39
huffman@27404
    40
lemma idealD3:
huffman@27404
    41
  "\<lbrakk>ideal A; x \<preceq> y; y \<in> A\<rbrakk> \<Longrightarrow> x \<in> A"
huffman@27404
    42
unfolding ideal_def by fast
huffman@27404
    43
huffman@27404
    44
lemma ideal_directed_finite:
huffman@27404
    45
  assumes A: "ideal A"
huffman@27404
    46
  shows "\<lbrakk>finite U; U \<subseteq> A\<rbrakk> \<Longrightarrow> \<exists>z\<in>A. \<forall>x\<in>U. x \<preceq> z"
huffman@27404
    47
apply (induct U set: finite)
huffman@27404
    48
apply (simp add: idealD1 [OF A])
huffman@27404
    49
apply (simp, clarify, rename_tac y)
huffman@27404
    50
apply (drule (1) idealD2 [OF A])
huffman@27404
    51
apply (clarify, erule_tac x=z in rev_bexI)
huffman@27404
    52
apply (fast intro: r_trans)
huffman@27404
    53
done
huffman@27404
    54
huffman@27404
    55
lemma ideal_principal: "ideal {x. x \<preceq> z}"
huffman@27404
    56
apply (rule idealI)
huffman@27404
    57
apply (rule_tac x=z in exI)
huffman@27404
    58
apply (fast intro: r_refl)
huffman@27404
    59
apply (rule_tac x=z in bexI, fast)
huffman@27404
    60
apply (fast intro: r_refl)
huffman@27404
    61
apply (fast intro: r_trans)
huffman@27404
    62
done
huffman@27404
    63
huffman@27404
    64
lemma ex_ideal: "\<exists>A. ideal A"
huffman@27404
    65
by (rule exI, rule ideal_principal)
huffman@27404
    66
huffman@27404
    67
lemma directed_image_ideal:
huffman@27404
    68
  assumes A: "ideal A"
huffman@27404
    69
  assumes f: "\<And>x y. x \<preceq> y \<Longrightarrow> f x \<sqsubseteq> f y"
huffman@27404
    70
  shows "directed (f ` A)"
huffman@27404
    71
apply (rule directedI)
huffman@27404
    72
apply (cut_tac idealD1 [OF A], fast)
huffman@27404
    73
apply (clarify, rename_tac a b)
huffman@27404
    74
apply (drule (1) idealD2 [OF A])
huffman@27404
    75
apply (clarify, rename_tac c)
huffman@27404
    76
apply (rule_tac x="f c" in rev_bexI)
huffman@27404
    77
apply (erule imageI)
huffman@27404
    78
apply (simp add: f)
huffman@27404
    79
done
huffman@27404
    80
huffman@27404
    81
lemma lub_image_principal:
huffman@27404
    82
  assumes f: "\<And>x y. x \<preceq> y \<Longrightarrow> f x \<sqsubseteq> f y"
huffman@27404
    83
  shows "(\<Squnion>x\<in>{x. x \<preceq> y}. f x) = f y"
huffman@27404
    84
apply (rule thelubI)
huffman@27404
    85
apply (rule is_lub_maximal)
huffman@27404
    86
apply (rule ub_imageI)
huffman@27404
    87
apply (simp add: f)
huffman@27404
    88
apply (rule imageI)
huffman@27404
    89
apply (simp add: r_refl)
huffman@27404
    90
done
huffman@27404
    91
huffman@27404
    92
text {* The set of ideals is a cpo *}
huffman@27404
    93
huffman@27404
    94
lemma ideal_UN:
huffman@27404
    95
  fixes A :: "nat \<Rightarrow> 'a set"
huffman@27404
    96
  assumes ideal_A: "\<And>i. ideal (A i)"
huffman@27404
    97
  assumes chain_A: "\<And>i j. i \<le> j \<Longrightarrow> A i \<subseteq> A j"
huffman@27404
    98
  shows "ideal (\<Union>i. A i)"
huffman@27404
    99
 apply (rule idealI)
huffman@27404
   100
   apply (cut_tac idealD1 [OF ideal_A], fast)
huffman@27404
   101
  apply (clarify, rename_tac i j)
huffman@27404
   102
  apply (drule subsetD [OF chain_A [OF le_maxI1]])
huffman@27404
   103
  apply (drule subsetD [OF chain_A [OF le_maxI2]])
huffman@27404
   104
  apply (drule (1) idealD2 [OF ideal_A])
huffman@27404
   105
  apply blast
huffman@27404
   106
 apply clarify
huffman@27404
   107
 apply (drule (1) idealD3 [OF ideal_A])
huffman@27404
   108
 apply fast
huffman@27404
   109
done
huffman@27404
   110
huffman@27404
   111
lemma typedef_ideal_po:
huffman@27404
   112
  fixes Abs :: "'a set \<Rightarrow> 'b::sq_ord"
huffman@27404
   113
  assumes type: "type_definition Rep Abs {S. ideal S}"
huffman@27404
   114
  assumes less: "\<And>x y. x \<sqsubseteq> y \<longleftrightarrow> Rep x \<subseteq> Rep y"
huffman@27404
   115
  shows "OFCLASS('b, po_class)"
huffman@27404
   116
 apply (intro_classes, unfold less)
huffman@27404
   117
   apply (rule subset_refl)
huffman@27404
   118
  apply (erule (1) subset_trans)
huffman@27404
   119
 apply (rule type_definition.Rep_inject [OF type, THEN iffD1])
huffman@27404
   120
 apply (erule (1) subset_antisym)
huffman@27404
   121
done
huffman@27404
   122
huffman@27404
   123
lemma
huffman@27404
   124
  fixes Abs :: "'a set \<Rightarrow> 'b::po"
huffman@27404
   125
  assumes type: "type_definition Rep Abs {S. ideal S}"
huffman@27404
   126
  assumes less: "\<And>x y. x \<sqsubseteq> y \<longleftrightarrow> Rep x \<subseteq> Rep y"
huffman@27404
   127
  assumes S: "chain S"
huffman@27404
   128
  shows typedef_ideal_lub: "range S <<| Abs (\<Union>i. Rep (S i))"
huffman@27404
   129
    and typedef_ideal_rep_contlub: "Rep (\<Squnion>i. S i) = (\<Union>i. Rep (S i))"
huffman@27404
   130
proof -
huffman@27404
   131
  have 1: "ideal (\<Union>i. Rep (S i))"
huffman@27404
   132
    apply (rule ideal_UN)
huffman@27404
   133
     apply (rule type_definition.Rep [OF type, unfolded mem_Collect_eq])
huffman@27404
   134
    apply (subst less [symmetric])
huffman@27404
   135
    apply (erule chain_mono [OF S])
huffman@27404
   136
    done
huffman@27404
   137
  hence 2: "Rep (Abs (\<Union>i. Rep (S i))) = (\<Union>i. Rep (S i))"
huffman@27404
   138
    by (simp add: type_definition.Abs_inverse [OF type])
huffman@27404
   139
  show 3: "range S <<| Abs (\<Union>i. Rep (S i))"
huffman@27404
   140
    apply (rule is_lubI)
huffman@27404
   141
     apply (rule is_ubI)
huffman@27404
   142
     apply (simp add: less 2, fast)
huffman@27404
   143
    apply (simp add: less 2 is_ub_def, fast)
huffman@27404
   144
    done
huffman@27404
   145
  hence 4: "(\<Squnion>i. S i) = Abs (\<Union>i. Rep (S i))"
huffman@27404
   146
    by (rule thelubI)
huffman@27404
   147
  show 5: "Rep (\<Squnion>i. S i) = (\<Union>i. Rep (S i))"
huffman@27404
   148
    by (simp add: 4 2)
huffman@27404
   149
qed
huffman@27404
   150
huffman@27404
   151
lemma typedef_ideal_cpo:
huffman@27404
   152
  fixes Abs :: "'a set \<Rightarrow> 'b::po"
huffman@27404
   153
  assumes type: "type_definition Rep Abs {S. ideal S}"
huffman@27404
   154
  assumes less: "\<And>x y. x \<sqsubseteq> y \<longleftrightarrow> Rep x \<subseteq> Rep y"
huffman@27404
   155
  shows "OFCLASS('b, cpo_class)"
huffman@27404
   156
by (default, rule exI, erule typedef_ideal_lub [OF type less])
huffman@27404
   157
huffman@27404
   158
end
huffman@27404
   159
huffman@27404
   160
interpretation sq_le: preorder ["sq_le :: 'a::po \<Rightarrow> 'a \<Rightarrow> bool"]
huffman@27404
   161
apply unfold_locales
huffman@27404
   162
apply (rule refl_less)
huffman@27404
   163
apply (erule (1) trans_less)
huffman@27404
   164
done
huffman@27404
   165
huffman@27404
   166
subsection {* Defining functions in terms of basis elements *}
huffman@27404
   167
huffman@27404
   168
lemma finite_directed_contains_lub:
huffman@27404
   169
  "\<lbrakk>finite S; directed S\<rbrakk> \<Longrightarrow> \<exists>u\<in>S. S <<| u"
huffman@27404
   170
apply (drule (1) directed_finiteD, rule subset_refl)
huffman@27404
   171
apply (erule bexE)
huffman@27404
   172
apply (rule rev_bexI, assumption)
huffman@27404
   173
apply (erule (1) is_lub_maximal)
huffman@27404
   174
done
huffman@27404
   175
huffman@27404
   176
lemma lub_finite_directed_in_self:
huffman@27404
   177
  "\<lbrakk>finite S; directed S\<rbrakk> \<Longrightarrow> lub S \<in> S"
huffman@27404
   178
apply (drule (1) finite_directed_contains_lub, clarify)
huffman@27404
   179
apply (drule thelubI, simp)
huffman@27404
   180
done
huffman@27404
   181
huffman@27404
   182
lemma finite_directed_has_lub: "\<lbrakk>finite S; directed S\<rbrakk> \<Longrightarrow> \<exists>u. S <<| u"
huffman@27404
   183
by (drule (1) finite_directed_contains_lub, fast)
huffman@27404
   184
huffman@27404
   185
lemma is_ub_thelub0: "\<lbrakk>\<exists>u. S <<| u; x \<in> S\<rbrakk> \<Longrightarrow> x \<sqsubseteq> lub S"
huffman@27404
   186
apply (erule exE, drule lubI)
huffman@27404
   187
apply (drule is_lubD1)
huffman@27404
   188
apply (erule (1) is_ubD)
huffman@27404
   189
done
huffman@27404
   190
huffman@27404
   191
lemma is_lub_thelub0: "\<lbrakk>\<exists>u. S <<| u; S <| x\<rbrakk> \<Longrightarrow> lub S \<sqsubseteq> x"
huffman@27404
   192
by (erule exE, drule lubI, erule is_lub_lub)
huffman@27404
   193
huffman@27404
   194
locale basis_take = preorder +
huffman@27404
   195
  fixes take :: "nat \<Rightarrow> 'a::type \<Rightarrow> 'a"
huffman@27404
   196
  assumes take_less: "take n a \<preceq> a"
huffman@27404
   197
  assumes take_take: "take n (take n a) = take n a"
huffman@27404
   198
  assumes take_mono: "a \<preceq> b \<Longrightarrow> take n a \<preceq> take n b"
huffman@27404
   199
  assumes take_chain: "take n a \<preceq> take (Suc n) a"
huffman@27404
   200
  assumes finite_range_take: "finite (range (take n))"
huffman@27404
   201
  assumes take_covers: "\<exists>n. take n a = a"
huffman@27404
   202
begin
huffman@27404
   203
huffman@27404
   204
lemma take_chain_less: "m < n \<Longrightarrow> take m a \<preceq> take n a"
huffman@27404
   205
by (erule less_Suc_induct, rule take_chain, erule (1) r_trans)
huffman@27404
   206
huffman@27404
   207
lemma take_chain_le: "m \<le> n \<Longrightarrow> take m a \<preceq> take n a"
huffman@27404
   208
by (cases "m = n", simp add: r_refl, simp add: take_chain_less)
huffman@27404
   209
huffman@27404
   210
end
huffman@27404
   211
huffman@27404
   212
locale ideal_completion = basis_take +
huffman@27404
   213
  fixes principal :: "'a::type \<Rightarrow> 'b::cpo"
huffman@27404
   214
  fixes rep :: "'b::cpo \<Rightarrow> 'a::type set"
huffman@27404
   215
  assumes ideal_rep: "\<And>x. preorder.ideal r (rep x)"
huffman@27404
   216
  assumes rep_contlub: "\<And>Y. chain Y \<Longrightarrow> rep (\<Squnion>i. Y i) = (\<Union>i. rep (Y i))"
huffman@27404
   217
  assumes rep_principal: "\<And>a. rep (principal a) = {b. b \<preceq> a}"
huffman@27404
   218
  assumes subset_repD: "\<And>x y. rep x \<subseteq> rep y \<Longrightarrow> x \<sqsubseteq> y"
huffman@27404
   219
begin
huffman@27404
   220
huffman@27404
   221
lemma finite_take_rep: "finite (take n ` rep x)"
huffman@27404
   222
by (rule finite_subset [OF image_mono [OF subset_UNIV] finite_range_take])
huffman@27404
   223
huffman@27404
   224
lemma basis_fun_lemma0:
huffman@27404
   225
  fixes f :: "'a::type \<Rightarrow> 'c::cpo"
huffman@27404
   226
  assumes f_mono: "\<And>a b. a \<preceq> b \<Longrightarrow> f a \<sqsubseteq> f b"
huffman@27404
   227
  shows "\<exists>u. f ` take i ` rep x <<| u"
huffman@27404
   228
apply (rule finite_directed_has_lub)
huffman@27404
   229
apply (rule finite_imageI)
huffman@27404
   230
apply (rule finite_take_rep)
huffman@27404
   231
apply (subst image_image)
huffman@27404
   232
apply (rule directed_image_ideal)
huffman@27404
   233
apply (rule ideal_rep)
huffman@27404
   234
apply (rule f_mono)
huffman@27404
   235
apply (erule take_mono)
huffman@27404
   236
done
huffman@27404
   237
huffman@27404
   238
lemma basis_fun_lemma1:
huffman@27404
   239
  fixes f :: "'a::type \<Rightarrow> 'c::cpo"
huffman@27404
   240
  assumes f_mono: "\<And>a b. a \<preceq> b \<Longrightarrow> f a \<sqsubseteq> f b"
huffman@27404
   241
  shows "chain (\<lambda>i. lub (f ` take i ` rep x))"
huffman@27404
   242
 apply (rule chainI)
huffman@27404
   243
 apply (rule is_lub_thelub0)
huffman@27404
   244
  apply (rule basis_fun_lemma0, erule f_mono)
huffman@27404
   245
 apply (rule is_ubI, clarsimp, rename_tac a)
huffman@27404
   246
 apply (rule sq_le.trans_less [OF f_mono [OF take_chain]])
huffman@27404
   247
 apply (rule is_ub_thelub0)
huffman@27404
   248
  apply (rule basis_fun_lemma0, erule f_mono)
huffman@27404
   249
 apply simp
huffman@27404
   250
done
huffman@27404
   251
huffman@27404
   252
lemma basis_fun_lemma2:
huffman@27404
   253
  fixes f :: "'a::type \<Rightarrow> 'c::cpo"
huffman@27404
   254
  assumes f_mono: "\<And>a b. a \<preceq> b \<Longrightarrow> f a \<sqsubseteq> f b"
huffman@27404
   255
  shows "f ` rep x <<| (\<Squnion>i. lub (f ` take i ` rep x))"
huffman@27404
   256
 apply (rule is_lubI)
huffman@27404
   257
 apply (rule ub_imageI, rename_tac a)
huffman@27404
   258
  apply (cut_tac a=a in take_covers, erule exE, rename_tac i)
huffman@27404
   259
  apply (erule subst)
huffman@27404
   260
  apply (rule rev_trans_less)
huffman@27404
   261
   apply (rule_tac x=i in is_ub_thelub)
huffman@27404
   262
   apply (rule basis_fun_lemma1, erule f_mono)
huffman@27404
   263
  apply (rule is_ub_thelub0)
huffman@27404
   264
   apply (rule basis_fun_lemma0, erule f_mono)
huffman@27404
   265
  apply simp
huffman@27404
   266
 apply (rule is_lub_thelub [OF _ ub_rangeI])
huffman@27404
   267
  apply (rule basis_fun_lemma1, erule f_mono)
huffman@27404
   268
 apply (rule is_lub_thelub0)
huffman@27404
   269
  apply (rule basis_fun_lemma0, erule f_mono)
huffman@27404
   270
 apply (rule is_ubI, clarsimp, rename_tac a)
huffman@27404
   271
 apply (rule sq_le.trans_less [OF f_mono [OF take_less]])
huffman@27404
   272
 apply (erule (1) ub_imageD)
huffman@27404
   273
done
huffman@27404
   274
huffman@27404
   275
lemma basis_fun_lemma:
huffman@27404
   276
  fixes f :: "'a::type \<Rightarrow> 'c::cpo"
huffman@27404
   277
  assumes f_mono: "\<And>a b. a \<preceq> b \<Longrightarrow> f a \<sqsubseteq> f b"
huffman@27404
   278
  shows "\<exists>u. f ` rep x <<| u"
huffman@27404
   279
by (rule exI, rule basis_fun_lemma2, erule f_mono)
huffman@27404
   280
huffman@27404
   281
lemma rep_mono: "x \<sqsubseteq> y \<Longrightarrow> rep x \<subseteq> rep y"
huffman@27404
   282
apply (frule bin_chain)
huffman@27404
   283
apply (drule rep_contlub)
huffman@27404
   284
apply (simp only: thelubI [OF lub_bin_chain])
huffman@27404
   285
apply (rule subsetI, rule UN_I [where a=0], simp_all)
huffman@27404
   286
done
huffman@27404
   287
huffman@27404
   288
lemma less_def: "x \<sqsubseteq> y \<longleftrightarrow> rep x \<subseteq> rep y"
huffman@27404
   289
by (rule iffI [OF rep_mono subset_repD])
huffman@27404
   290
huffman@27404
   291
lemma rep_eq: "rep x = {a. principal a \<sqsubseteq> x}"
huffman@27404
   292
unfolding less_def rep_principal
huffman@27404
   293
apply safe
huffman@27404
   294
apply (erule (1) idealD3 [OF ideal_rep])
huffman@27404
   295
apply (erule subsetD, simp add: r_refl)
huffman@27404
   296
done
huffman@27404
   297
huffman@27404
   298
lemma mem_rep_iff_principal_less: "a \<in> rep x \<longleftrightarrow> principal a \<sqsubseteq> x"
huffman@27404
   299
by (simp add: rep_eq)
huffman@27404
   300
huffman@27404
   301
lemma principal_less_iff_mem_rep: "principal a \<sqsubseteq> x \<longleftrightarrow> a \<in> rep x"
huffman@27404
   302
by (simp add: rep_eq)
huffman@27404
   303
huffman@27404
   304
lemma principal_less_iff [simp]: "principal a \<sqsubseteq> principal b \<longleftrightarrow> a \<preceq> b"
huffman@27404
   305
by (simp add: principal_less_iff_mem_rep rep_principal)
huffman@27404
   306
huffman@27404
   307
lemma principal_eq_iff: "principal a = principal b \<longleftrightarrow> a \<preceq> b \<and> b \<preceq> a"
huffman@27404
   308
unfolding po_eq_conv [where 'a='b] principal_less_iff ..
huffman@27404
   309
huffman@27404
   310
lemma repD: "a \<in> rep x \<Longrightarrow> principal a \<sqsubseteq> x"
huffman@27404
   311
by (simp add: rep_eq)
huffman@27404
   312
huffman@27404
   313
lemma principal_mono: "a \<preceq> b \<Longrightarrow> principal a \<sqsubseteq> principal b"
huffman@27404
   314
by (simp only: principal_less_iff)
huffman@27404
   315
huffman@27404
   316
lemma lessI: "(\<And>a. principal a \<sqsubseteq> x \<Longrightarrow> principal a \<sqsubseteq> u) \<Longrightarrow> x \<sqsubseteq> u"
huffman@27404
   317
unfolding principal_less_iff_mem_rep
huffman@27404
   318
by (simp add: less_def subset_eq)
huffman@27404
   319
huffman@27404
   320
lemma lub_principal_rep: "principal ` rep x <<| x"
huffman@27404
   321
apply (rule is_lubI)
huffman@27404
   322
apply (rule ub_imageI)
huffman@27404
   323
apply (erule repD)
huffman@27404
   324
apply (subst less_def)
huffman@27404
   325
apply (rule subsetI)
huffman@27404
   326
apply (drule (1) ub_imageD)
huffman@27404
   327
apply (simp add: rep_eq)
huffman@27404
   328
done
huffman@27404
   329
huffman@27404
   330
definition
huffman@27404
   331
  basis_fun :: "('a::type \<Rightarrow> 'c::cpo) \<Rightarrow> 'b \<rightarrow> 'c" where
huffman@27404
   332
  "basis_fun = (\<lambda>f. (\<Lambda> x. lub (f ` rep x)))"
huffman@27404
   333
huffman@27404
   334
lemma basis_fun_beta:
huffman@27404
   335
  fixes f :: "'a::type \<Rightarrow> 'c::cpo"
huffman@27404
   336
  assumes f_mono: "\<And>a b. a \<preceq> b \<Longrightarrow> f a \<sqsubseteq> f b"
huffman@27404
   337
  shows "basis_fun f\<cdot>x = lub (f ` rep x)"
huffman@27404
   338
unfolding basis_fun_def
huffman@27404
   339
proof (rule beta_cfun)
huffman@27404
   340
  have lub: "\<And>x. \<exists>u. f ` rep x <<| u"
huffman@27404
   341
    using f_mono by (rule basis_fun_lemma)
huffman@27404
   342
  show cont: "cont (\<lambda>x. lub (f ` rep x))"
huffman@27404
   343
    apply (rule contI2)
huffman@27404
   344
     apply (rule monofunI)
huffman@27404
   345
     apply (rule is_lub_thelub0 [OF lub ub_imageI])
huffman@27404
   346
     apply (rule is_ub_thelub0 [OF lub imageI])
huffman@27404
   347
     apply (erule (1) subsetD [OF rep_mono])
huffman@27404
   348
    apply (rule is_lub_thelub0 [OF lub ub_imageI])
huffman@27404
   349
    apply (simp add: rep_contlub, clarify)
huffman@27404
   350
    apply (erule rev_trans_less [OF is_ub_thelub])
huffman@27404
   351
    apply (erule is_ub_thelub0 [OF lub imageI])
huffman@27404
   352
    done
huffman@27404
   353
qed
huffman@27404
   354
huffman@27404
   355
lemma basis_fun_principal:
huffman@27404
   356
  fixes f :: "'a::type \<Rightarrow> 'c::cpo"
huffman@27404
   357
  assumes f_mono: "\<And>a b. a \<preceq> b \<Longrightarrow> f a \<sqsubseteq> f b"
huffman@27404
   358
  shows "basis_fun f\<cdot>(principal a) = f a"
huffman@27404
   359
apply (subst basis_fun_beta, erule f_mono)
huffman@27404
   360
apply (subst rep_principal)
huffman@27404
   361
apply (rule lub_image_principal, erule f_mono)
huffman@27404
   362
done
huffman@27404
   363
huffman@27404
   364
lemma basis_fun_mono:
huffman@27404
   365
  assumes f_mono: "\<And>a b. a \<preceq> b \<Longrightarrow> f a \<sqsubseteq> f b"
huffman@27404
   366
  assumes g_mono: "\<And>a b. a \<preceq> b \<Longrightarrow> g a \<sqsubseteq> g b"
huffman@27404
   367
  assumes less: "\<And>a. f a \<sqsubseteq> g a"
huffman@27404
   368
  shows "basis_fun f \<sqsubseteq> basis_fun g"
huffman@27404
   369
 apply (rule less_cfun_ext)
huffman@27404
   370
 apply (simp only: basis_fun_beta f_mono g_mono)
huffman@27404
   371
 apply (rule is_lub_thelub0)
huffman@27404
   372
  apply (rule basis_fun_lemma, erule f_mono)
huffman@27404
   373
 apply (rule ub_imageI, rename_tac a)
huffman@27404
   374
 apply (rule sq_le.trans_less [OF less])
huffman@27404
   375
 apply (rule is_ub_thelub0)
huffman@27404
   376
  apply (rule basis_fun_lemma, erule g_mono)
huffman@27404
   377
 apply (erule imageI)
huffman@27404
   378
done
huffman@27404
   379
huffman@27404
   380
lemma compact_principal [simp]: "compact (principal a)"
huffman@27404
   381
by (rule compactI2, simp add: principal_less_iff_mem_rep rep_contlub)
huffman@27404
   382
huffman@27404
   383
definition
huffman@27404
   384
  completion_approx :: "nat \<Rightarrow> 'b \<rightarrow> 'b" where
huffman@27404
   385
  "completion_approx = (\<lambda>i. basis_fun (\<lambda>a. principal (take i a)))"
huffman@27404
   386
huffman@27404
   387
lemma completion_approx_beta:
huffman@27404
   388
  "completion_approx i\<cdot>x = (\<Squnion>a\<in>rep x. principal (take i a))"
huffman@27404
   389
unfolding completion_approx_def
huffman@27404
   390
by (simp add: basis_fun_beta principal_mono take_mono)
huffman@27404
   391
huffman@27404
   392
lemma completion_approx_principal:
huffman@27404
   393
  "completion_approx i\<cdot>(principal a) = principal (take i a)"
huffman@27404
   394
unfolding completion_approx_def
huffman@27404
   395
by (simp add: basis_fun_principal principal_mono take_mono)
huffman@27404
   396
huffman@27404
   397
lemma chain_completion_approx: "chain completion_approx"
huffman@27404
   398
unfolding completion_approx_def
huffman@27404
   399
apply (rule chainI)
huffman@27404
   400
apply (rule basis_fun_mono)
huffman@27404
   401
apply (erule principal_mono [OF take_mono])
huffman@27404
   402
apply (erule principal_mono [OF take_mono])
huffman@27404
   403
apply (rule principal_mono [OF take_chain])
huffman@27404
   404
done
huffman@27404
   405
huffman@27404
   406
lemma lub_completion_approx: "(\<Squnion>i. completion_approx i\<cdot>x) = x"
huffman@27404
   407
unfolding completion_approx_beta
huffman@27404
   408
 apply (subst image_image [where f=principal, symmetric])
huffman@27404
   409
 apply (rule unique_lub [OF _ lub_principal_rep])
huffman@27404
   410
 apply (rule basis_fun_lemma2, erule principal_mono)
huffman@27404
   411
done
huffman@27404
   412
huffman@27404
   413
lemma completion_approx_eq_principal:
huffman@27404
   414
  "\<exists>a\<in>rep x. completion_approx i\<cdot>x = principal (take i a)"
huffman@27404
   415
unfolding completion_approx_beta
huffman@27404
   416
 apply (subst image_image [where f=principal, symmetric])
huffman@27404
   417
 apply (subgoal_tac "finite (principal ` take i ` rep x)")
huffman@27404
   418
  apply (subgoal_tac "directed (principal ` take i ` rep x)")
huffman@27404
   419
   apply (drule (1) lub_finite_directed_in_self, fast)
huffman@27404
   420
  apply (subst image_image)
huffman@27404
   421
  apply (rule directed_image_ideal)
huffman@27404
   422
   apply (rule ideal_rep)
huffman@27404
   423
  apply (erule principal_mono [OF take_mono])
huffman@27404
   424
 apply (rule finite_imageI)
huffman@27404
   425
 apply (rule finite_take_rep)
huffman@27404
   426
done
huffman@27404
   427
huffman@27404
   428
lemma completion_approx_idem:
huffman@27404
   429
  "completion_approx i\<cdot>(completion_approx i\<cdot>x) = completion_approx i\<cdot>x"
huffman@27404
   430
using completion_approx_eq_principal [where i=i and x=x]
huffman@27404
   431
by (auto simp add: completion_approx_principal take_take)
huffman@27404
   432
huffman@27404
   433
lemma finite_fixes_completion_approx:
huffman@27404
   434
  "finite {x. completion_approx i\<cdot>x = x}" (is "finite ?S")
huffman@27404
   435
apply (subgoal_tac "?S \<subseteq> principal ` range (take i)")
huffman@27404
   436
apply (erule finite_subset)
huffman@27404
   437
apply (rule finite_imageI)
huffman@27404
   438
apply (rule finite_range_take)
huffman@27404
   439
apply (clarify, erule subst)
huffman@27404
   440
apply (cut_tac x=x and i=i in completion_approx_eq_principal)
huffman@27404
   441
apply fast
huffman@27404
   442
done
huffman@27404
   443
huffman@27404
   444
lemma principal_induct:
huffman@27404
   445
  assumes adm: "adm P"
huffman@27404
   446
  assumes P: "\<And>a. P (principal a)"
huffman@27404
   447
  shows "P x"
huffman@27404
   448
 apply (subgoal_tac "P (\<Squnion>i. completion_approx i\<cdot>x)")
huffman@27404
   449
 apply (simp add: lub_completion_approx)
huffman@27404
   450
 apply (rule admD [OF adm])
huffman@27404
   451
  apply (simp add: chain_completion_approx)
huffman@27404
   452
 apply (cut_tac x=x and i=i in completion_approx_eq_principal)
huffman@27404
   453
 apply (clarify, simp add: P)
huffman@27404
   454
done
huffman@27404
   455
huffman@27404
   456
lemma principal_induct2:
huffman@27404
   457
  "\<lbrakk>\<And>y. adm (\<lambda>x. P x y); \<And>x. adm (\<lambda>y. P x y);
huffman@27404
   458
    \<And>a b. P (principal a) (principal b)\<rbrakk> \<Longrightarrow> P x y"
huffman@27404
   459
apply (rule_tac x=y in spec)
huffman@27404
   460
apply (rule_tac x=x in principal_induct, simp)
huffman@27404
   461
apply (rule allI, rename_tac y)
huffman@27404
   462
apply (rule_tac x=y in principal_induct, simp)
huffman@27404
   463
apply simp
huffman@27404
   464
done
huffman@27404
   465
huffman@27404
   466
lemma compact_imp_principal: "compact x \<Longrightarrow> \<exists>a. x = principal a"
huffman@27404
   467
apply (drule adm_compact_neq [OF _ cont_id])
huffman@27404
   468
apply (drule admD2 [where Y="\<lambda>n. completion_approx n\<cdot>x"])
huffman@27404
   469
apply (simp add: chain_completion_approx)
huffman@27404
   470
apply (simp add: lub_completion_approx)
huffman@27404
   471
apply (erule exE, erule ssubst)
huffman@27404
   472
apply (cut_tac i=i and x=x in completion_approx_eq_principal)
huffman@27404
   473
apply (clarify, erule exI)
huffman@27404
   474
done
huffman@27404
   475
huffman@27404
   476
end
huffman@27404
   477
huffman@27404
   478
end