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