src/HOLCF/Completion.thy
author huffman
Thu, 07 Oct 2010 13:22:13 -0700
changeset 39983 910d3ea1efa8
parent 39974 b525988432e9
child 39984 0300d5170622
permissions -rw-r--r--
remove unused lemmas
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
27404
62171da527d6 split Completion.thy from CompactBasis.thy
huffman
parents:
diff changeset
     1
(*  Title:      HOLCF/Completion.thy
62171da527d6 split Completion.thy from CompactBasis.thy
huffman
parents:
diff changeset
     2
    Author:     Brian Huffman
62171da527d6 split Completion.thy from CompactBasis.thy
huffman
parents:
diff changeset
     3
*)
62171da527d6 split Completion.thy from CompactBasis.thy
huffman
parents:
diff changeset
     4
39974
b525988432e9 major reorganization/simplification of HOLCF type classes:
huffman
parents: 39967
diff changeset
     5
header {* Defining algebraic domains by ideal completion *}
27404
62171da527d6 split Completion.thy from CompactBasis.thy
huffman
parents:
diff changeset
     6
62171da527d6 split Completion.thy from CompactBasis.thy
huffman
parents:
diff changeset
     7
theory Completion
39967
1c6dce3ef477 minimize theory imports
huffman
parents: 31076
diff changeset
     8
imports Cfun
27404
62171da527d6 split Completion.thy from CompactBasis.thy
huffman
parents:
diff changeset
     9
begin
62171da527d6 split Completion.thy from CompactBasis.thy
huffman
parents:
diff changeset
    10
62171da527d6 split Completion.thy from CompactBasis.thy
huffman
parents:
diff changeset
    11
subsection {* Ideals over a preorder *}
62171da527d6 split Completion.thy from CompactBasis.thy
huffman
parents:
diff changeset
    12
62171da527d6 split Completion.thy from CompactBasis.thy
huffman
parents:
diff changeset
    13
locale preorder =
62171da527d6 split Completion.thy from CompactBasis.thy
huffman
parents:
diff changeset
    14
  fixes r :: "'a::type \<Rightarrow> 'a \<Rightarrow> bool" (infix "\<preceq>" 50)
62171da527d6 split Completion.thy from CompactBasis.thy
huffman
parents:
diff changeset
    15
  assumes r_refl: "x \<preceq> x"
62171da527d6 split Completion.thy from CompactBasis.thy
huffman
parents:
diff changeset
    16
  assumes r_trans: "\<lbrakk>x \<preceq> y; y \<preceq> z\<rbrakk> \<Longrightarrow> x \<preceq> z"
62171da527d6 split Completion.thy from CompactBasis.thy
huffman
parents:
diff changeset
    17
begin
62171da527d6 split Completion.thy from CompactBasis.thy
huffman
parents:
diff changeset
    18
62171da527d6 split Completion.thy from CompactBasis.thy
huffman
parents:
diff changeset
    19
definition
62171da527d6 split Completion.thy from CompactBasis.thy
huffman
parents:
diff changeset
    20
  ideal :: "'a set \<Rightarrow> bool" where
62171da527d6 split Completion.thy from CompactBasis.thy
huffman
parents:
diff changeset
    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>
62171da527d6 split Completion.thy from CompactBasis.thy
huffman
parents:
diff changeset
    22
    (\<forall>x y. x \<preceq> y \<longrightarrow> y \<in> A \<longrightarrow> x \<in> A))"
62171da527d6 split Completion.thy from CompactBasis.thy
huffman
parents:
diff changeset
    23
62171da527d6 split Completion.thy from CompactBasis.thy
huffman
parents:
diff changeset
    24
lemma idealI:
62171da527d6 split Completion.thy from CompactBasis.thy
huffman
parents:
diff changeset
    25
  assumes "\<exists>x. x \<in> A"
62171da527d6 split Completion.thy from CompactBasis.thy
huffman
parents:
diff changeset
    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"
62171da527d6 split Completion.thy from CompactBasis.thy
huffman
parents:
diff changeset
    27
  assumes "\<And>x y. \<lbrakk>x \<preceq> y; y \<in> A\<rbrakk> \<Longrightarrow> x \<in> A"
62171da527d6 split Completion.thy from CompactBasis.thy
huffman
parents:
diff changeset
    28
  shows "ideal A"
62171da527d6 split Completion.thy from CompactBasis.thy
huffman
parents:
diff changeset
    29
unfolding ideal_def using prems by fast
62171da527d6 split Completion.thy from CompactBasis.thy
huffman
parents:
diff changeset
    30
62171da527d6 split Completion.thy from CompactBasis.thy
huffman
parents:
diff changeset
    31
lemma idealD1:
62171da527d6 split Completion.thy from CompactBasis.thy
huffman
parents:
diff changeset
    32
  "ideal A \<Longrightarrow> \<exists>x. x \<in> A"
62171da527d6 split Completion.thy from CompactBasis.thy
huffman
parents:
diff changeset
    33
unfolding ideal_def by fast
62171da527d6 split Completion.thy from CompactBasis.thy
huffman
parents:
diff changeset
    34
62171da527d6 split Completion.thy from CompactBasis.thy
huffman
parents:
diff changeset
    35
lemma idealD2:
62171da527d6 split Completion.thy from CompactBasis.thy
huffman
parents:
diff changeset
    36
  "\<lbrakk>ideal A; x \<in> A; y \<in> A\<rbrakk> \<Longrightarrow> \<exists>z\<in>A. x \<preceq> z \<and> y \<preceq> z"
62171da527d6 split Completion.thy from CompactBasis.thy
huffman
parents:
diff changeset
    37
unfolding ideal_def by fast
62171da527d6 split Completion.thy from CompactBasis.thy
huffman
parents:
diff changeset
    38
62171da527d6 split Completion.thy from CompactBasis.thy
huffman
parents:
diff changeset
    39
lemma idealD3:
62171da527d6 split Completion.thy from CompactBasis.thy
huffman
parents:
diff changeset
    40
  "\<lbrakk>ideal A; x \<preceq> y; y \<in> A\<rbrakk> \<Longrightarrow> x \<in> A"
62171da527d6 split Completion.thy from CompactBasis.thy
huffman
parents:
diff changeset
    41
unfolding ideal_def by fast
62171da527d6 split Completion.thy from CompactBasis.thy
huffman
parents:
diff changeset
    42
62171da527d6 split Completion.thy from CompactBasis.thy
huffman
parents:
diff changeset
    43
lemma ideal_principal: "ideal {x. x \<preceq> z}"
62171da527d6 split Completion.thy from CompactBasis.thy
huffman
parents:
diff changeset
    44
apply (rule idealI)
62171da527d6 split Completion.thy from CompactBasis.thy
huffman
parents:
diff changeset
    45
apply (rule_tac x=z in exI)
62171da527d6 split Completion.thy from CompactBasis.thy
huffman
parents:
diff changeset
    46
apply (fast intro: r_refl)
62171da527d6 split Completion.thy from CompactBasis.thy
huffman
parents:
diff changeset
    47
apply (rule_tac x=z in bexI, fast)
62171da527d6 split Completion.thy from CompactBasis.thy
huffman
parents:
diff changeset
    48
apply (fast intro: r_refl)
62171da527d6 split Completion.thy from CompactBasis.thy
huffman
parents:
diff changeset
    49
apply (fast intro: r_trans)
62171da527d6 split Completion.thy from CompactBasis.thy
huffman
parents:
diff changeset
    50
done
62171da527d6 split Completion.thy from CompactBasis.thy
huffman
parents:
diff changeset
    51
62171da527d6 split Completion.thy from CompactBasis.thy
huffman
parents:
diff changeset
    52
lemma ex_ideal: "\<exists>A. ideal A"
62171da527d6 split Completion.thy from CompactBasis.thy
huffman
parents:
diff changeset
    53
by (rule exI, rule ideal_principal)
62171da527d6 split Completion.thy from CompactBasis.thy
huffman
parents:
diff changeset
    54
62171da527d6 split Completion.thy from CompactBasis.thy
huffman
parents:
diff changeset
    55
lemma lub_image_principal:
62171da527d6 split Completion.thy from CompactBasis.thy
huffman
parents:
diff changeset
    56
  assumes f: "\<And>x y. x \<preceq> y \<Longrightarrow> f x \<sqsubseteq> f y"
62171da527d6 split Completion.thy from CompactBasis.thy
huffman
parents:
diff changeset
    57
  shows "(\<Squnion>x\<in>{x. x \<preceq> y}. f x) = f y"
62171da527d6 split Completion.thy from CompactBasis.thy
huffman
parents:
diff changeset
    58
apply (rule thelubI)
62171da527d6 split Completion.thy from CompactBasis.thy
huffman
parents:
diff changeset
    59
apply (rule is_lub_maximal)
62171da527d6 split Completion.thy from CompactBasis.thy
huffman
parents:
diff changeset
    60
apply (rule ub_imageI)
62171da527d6 split Completion.thy from CompactBasis.thy
huffman
parents:
diff changeset
    61
apply (simp add: f)
62171da527d6 split Completion.thy from CompactBasis.thy
huffman
parents:
diff changeset
    62
apply (rule imageI)
62171da527d6 split Completion.thy from CompactBasis.thy
huffman
parents:
diff changeset
    63
apply (simp add: r_refl)
62171da527d6 split Completion.thy from CompactBasis.thy
huffman
parents:
diff changeset
    64
done
62171da527d6 split Completion.thy from CompactBasis.thy
huffman
parents:
diff changeset
    65
62171da527d6 split Completion.thy from CompactBasis.thy
huffman
parents:
diff changeset
    66
text {* The set of ideals is a cpo *}
62171da527d6 split Completion.thy from CompactBasis.thy
huffman
parents:
diff changeset
    67
62171da527d6 split Completion.thy from CompactBasis.thy
huffman
parents:
diff changeset
    68
lemma ideal_UN:
62171da527d6 split Completion.thy from CompactBasis.thy
huffman
parents:
diff changeset
    69
  fixes A :: "nat \<Rightarrow> 'a set"
62171da527d6 split Completion.thy from CompactBasis.thy
huffman
parents:
diff changeset
    70
  assumes ideal_A: "\<And>i. ideal (A i)"
62171da527d6 split Completion.thy from CompactBasis.thy
huffman
parents:
diff changeset
    71
  assumes chain_A: "\<And>i j. i \<le> j \<Longrightarrow> A i \<subseteq> A j"
62171da527d6 split Completion.thy from CompactBasis.thy
huffman
parents:
diff changeset
    72
  shows "ideal (\<Union>i. A i)"
62171da527d6 split Completion.thy from CompactBasis.thy
huffman
parents:
diff changeset
    73
 apply (rule idealI)
62171da527d6 split Completion.thy from CompactBasis.thy
huffman
parents:
diff changeset
    74
   apply (cut_tac idealD1 [OF ideal_A], fast)
62171da527d6 split Completion.thy from CompactBasis.thy
huffman
parents:
diff changeset
    75
  apply (clarify, rename_tac i j)
62171da527d6 split Completion.thy from CompactBasis.thy
huffman
parents:
diff changeset
    76
  apply (drule subsetD [OF chain_A [OF le_maxI1]])
62171da527d6 split Completion.thy from CompactBasis.thy
huffman
parents:
diff changeset
    77
  apply (drule subsetD [OF chain_A [OF le_maxI2]])
62171da527d6 split Completion.thy from CompactBasis.thy
huffman
parents:
diff changeset
    78
  apply (drule (1) idealD2 [OF ideal_A])
62171da527d6 split Completion.thy from CompactBasis.thy
huffman
parents:
diff changeset
    79
  apply blast
62171da527d6 split Completion.thy from CompactBasis.thy
huffman
parents:
diff changeset
    80
 apply clarify
62171da527d6 split Completion.thy from CompactBasis.thy
huffman
parents:
diff changeset
    81
 apply (drule (1) idealD3 [OF ideal_A])
62171da527d6 split Completion.thy from CompactBasis.thy
huffman
parents:
diff changeset
    82
 apply fast
62171da527d6 split Completion.thy from CompactBasis.thy
huffman
parents:
diff changeset
    83
done
62171da527d6 split Completion.thy from CompactBasis.thy
huffman
parents:
diff changeset
    84
62171da527d6 split Completion.thy from CompactBasis.thy
huffman
parents:
diff changeset
    85
lemma typedef_ideal_po:
31076
99fe356cbbc2 rename constant sq_le to below; rename class sq_ord to below; less->below in many lemma names
huffman
parents: 30729
diff changeset
    86
  fixes Abs :: "'a set \<Rightarrow> 'b::below"
27404
62171da527d6 split Completion.thy from CompactBasis.thy
huffman
parents:
diff changeset
    87
  assumes type: "type_definition Rep Abs {S. ideal S}"
31076
99fe356cbbc2 rename constant sq_le to below; rename class sq_ord to below; less->below in many lemma names
huffman
parents: 30729
diff changeset
    88
  assumes below: "\<And>x y. x \<sqsubseteq> y \<longleftrightarrow> Rep x \<subseteq> Rep y"
27404
62171da527d6 split Completion.thy from CompactBasis.thy
huffman
parents:
diff changeset
    89
  shows "OFCLASS('b, po_class)"
31076
99fe356cbbc2 rename constant sq_le to below; rename class sq_ord to below; less->below in many lemma names
huffman
parents: 30729
diff changeset
    90
 apply (intro_classes, unfold below)
27404
62171da527d6 split Completion.thy from CompactBasis.thy
huffman
parents:
diff changeset
    91
   apply (rule subset_refl)
62171da527d6 split Completion.thy from CompactBasis.thy
huffman
parents:
diff changeset
    92
  apply (erule (1) subset_trans)
62171da527d6 split Completion.thy from CompactBasis.thy
huffman
parents:
diff changeset
    93
 apply (rule type_definition.Rep_inject [OF type, THEN iffD1])
62171da527d6 split Completion.thy from CompactBasis.thy
huffman
parents:
diff changeset
    94
 apply (erule (1) subset_antisym)
62171da527d6 split Completion.thy from CompactBasis.thy
huffman
parents:
diff changeset
    95
done
62171da527d6 split Completion.thy from CompactBasis.thy
huffman
parents:
diff changeset
    96
62171da527d6 split Completion.thy from CompactBasis.thy
huffman
parents:
diff changeset
    97
lemma
62171da527d6 split Completion.thy from CompactBasis.thy
huffman
parents:
diff changeset
    98
  fixes Abs :: "'a set \<Rightarrow> 'b::po"
62171da527d6 split Completion.thy from CompactBasis.thy
huffman
parents:
diff changeset
    99
  assumes type: "type_definition Rep Abs {S. ideal S}"
31076
99fe356cbbc2 rename constant sq_le to below; rename class sq_ord to below; less->below in many lemma names
huffman
parents: 30729
diff changeset
   100
  assumes below: "\<And>x y. x \<sqsubseteq> y \<longleftrightarrow> Rep x \<subseteq> Rep y"
27404
62171da527d6 split Completion.thy from CompactBasis.thy
huffman
parents:
diff changeset
   101
  assumes S: "chain S"
62171da527d6 split Completion.thy from CompactBasis.thy
huffman
parents:
diff changeset
   102
  shows typedef_ideal_lub: "range S <<| Abs (\<Union>i. Rep (S i))"
62171da527d6 split Completion.thy from CompactBasis.thy
huffman
parents:
diff changeset
   103
    and typedef_ideal_rep_contlub: "Rep (\<Squnion>i. S i) = (\<Union>i. Rep (S i))"
62171da527d6 split Completion.thy from CompactBasis.thy
huffman
parents:
diff changeset
   104
proof -
62171da527d6 split Completion.thy from CompactBasis.thy
huffman
parents:
diff changeset
   105
  have 1: "ideal (\<Union>i. Rep (S i))"
62171da527d6 split Completion.thy from CompactBasis.thy
huffman
parents:
diff changeset
   106
    apply (rule ideal_UN)
62171da527d6 split Completion.thy from CompactBasis.thy
huffman
parents:
diff changeset
   107
     apply (rule type_definition.Rep [OF type, unfolded mem_Collect_eq])
31076
99fe356cbbc2 rename constant sq_le to below; rename class sq_ord to below; less->below in many lemma names
huffman
parents: 30729
diff changeset
   108
    apply (subst below [symmetric])
27404
62171da527d6 split Completion.thy from CompactBasis.thy
huffman
parents:
diff changeset
   109
    apply (erule chain_mono [OF S])
62171da527d6 split Completion.thy from CompactBasis.thy
huffman
parents:
diff changeset
   110
    done
62171da527d6 split Completion.thy from CompactBasis.thy
huffman
parents:
diff changeset
   111
  hence 2: "Rep (Abs (\<Union>i. Rep (S i))) = (\<Union>i. Rep (S i))"
62171da527d6 split Completion.thy from CompactBasis.thy
huffman
parents:
diff changeset
   112
    by (simp add: type_definition.Abs_inverse [OF type])
62171da527d6 split Completion.thy from CompactBasis.thy
huffman
parents:
diff changeset
   113
  show 3: "range S <<| Abs (\<Union>i. Rep (S i))"
62171da527d6 split Completion.thy from CompactBasis.thy
huffman
parents:
diff changeset
   114
    apply (rule is_lubI)
62171da527d6 split Completion.thy from CompactBasis.thy
huffman
parents:
diff changeset
   115
     apply (rule is_ubI)
31076
99fe356cbbc2 rename constant sq_le to below; rename class sq_ord to below; less->below in many lemma names
huffman
parents: 30729
diff changeset
   116
     apply (simp add: below 2, fast)
99fe356cbbc2 rename constant sq_le to below; rename class sq_ord to below; less->below in many lemma names
huffman
parents: 30729
diff changeset
   117
    apply (simp add: below 2 is_ub_def, fast)
27404
62171da527d6 split Completion.thy from CompactBasis.thy
huffman
parents:
diff changeset
   118
    done
62171da527d6 split Completion.thy from CompactBasis.thy
huffman
parents:
diff changeset
   119
  hence 4: "(\<Squnion>i. S i) = Abs (\<Union>i. Rep (S i))"
62171da527d6 split Completion.thy from CompactBasis.thy
huffman
parents:
diff changeset
   120
    by (rule thelubI)
62171da527d6 split Completion.thy from CompactBasis.thy
huffman
parents:
diff changeset
   121
  show 5: "Rep (\<Squnion>i. S i) = (\<Union>i. Rep (S i))"
62171da527d6 split Completion.thy from CompactBasis.thy
huffman
parents:
diff changeset
   122
    by (simp add: 4 2)
62171da527d6 split Completion.thy from CompactBasis.thy
huffman
parents:
diff changeset
   123
qed
62171da527d6 split Completion.thy from CompactBasis.thy
huffman
parents:
diff changeset
   124
62171da527d6 split Completion.thy from CompactBasis.thy
huffman
parents:
diff changeset
   125
lemma typedef_ideal_cpo:
62171da527d6 split Completion.thy from CompactBasis.thy
huffman
parents:
diff changeset
   126
  fixes Abs :: "'a set \<Rightarrow> 'b::po"
62171da527d6 split Completion.thy from CompactBasis.thy
huffman
parents:
diff changeset
   127
  assumes type: "type_definition Rep Abs {S. ideal S}"
31076
99fe356cbbc2 rename constant sq_le to below; rename class sq_ord to below; less->below in many lemma names
huffman
parents: 30729
diff changeset
   128
  assumes below: "\<And>x y. x \<sqsubseteq> y \<longleftrightarrow> Rep x \<subseteq> Rep y"
27404
62171da527d6 split Completion.thy from CompactBasis.thy
huffman
parents:
diff changeset
   129
  shows "OFCLASS('b, cpo_class)"
31076
99fe356cbbc2 rename constant sq_le to below; rename class sq_ord to below; less->below in many lemma names
huffman
parents: 30729
diff changeset
   130
by (default, rule exI, erule typedef_ideal_lub [OF type below])
27404
62171da527d6 split Completion.thy from CompactBasis.thy
huffman
parents:
diff changeset
   131
62171da527d6 split Completion.thy from CompactBasis.thy
huffman
parents:
diff changeset
   132
end
62171da527d6 split Completion.thy from CompactBasis.thy
huffman
parents:
diff changeset
   133
31076
99fe356cbbc2 rename constant sq_le to below; rename class sq_ord to below; less->below in many lemma names
huffman
parents: 30729
diff changeset
   134
interpretation below: preorder "below :: 'a::po \<Rightarrow> 'a \<Rightarrow> bool"
27404
62171da527d6 split Completion.thy from CompactBasis.thy
huffman
parents:
diff changeset
   135
apply unfold_locales
31076
99fe356cbbc2 rename constant sq_le to below; rename class sq_ord to below; less->below in many lemma names
huffman
parents: 30729
diff changeset
   136
apply (rule below_refl)
99fe356cbbc2 rename constant sq_le to below; rename class sq_ord to below; less->below in many lemma names
huffman
parents: 30729
diff changeset
   137
apply (erule (1) below_trans)
27404
62171da527d6 split Completion.thy from CompactBasis.thy
huffman
parents:
diff changeset
   138
done
62171da527d6 split Completion.thy from CompactBasis.thy
huffman
parents:
diff changeset
   139
28133
218252dfd81e reorganize subsections
huffman
parents: 28053
diff changeset
   140
subsection {* Lemmas about least upper bounds *}
27404
62171da527d6 split Completion.thy from CompactBasis.thy
huffman
parents:
diff changeset
   141
39974
b525988432e9 major reorganization/simplification of HOLCF type classes:
huffman
parents: 39967
diff changeset
   142
lemma is_ub_thelub_ex: "\<lbrakk>\<exists>u. S <<| u; x \<in> S\<rbrakk> \<Longrightarrow> x \<sqsubseteq> lub S"
27404
62171da527d6 split Completion.thy from CompactBasis.thy
huffman
parents:
diff changeset
   143
apply (erule exE, drule lubI)
62171da527d6 split Completion.thy from CompactBasis.thy
huffman
parents:
diff changeset
   144
apply (drule is_lubD1)
62171da527d6 split Completion.thy from CompactBasis.thy
huffman
parents:
diff changeset
   145
apply (erule (1) is_ubD)
62171da527d6 split Completion.thy from CompactBasis.thy
huffman
parents:
diff changeset
   146
done
62171da527d6 split Completion.thy from CompactBasis.thy
huffman
parents:
diff changeset
   147
39974
b525988432e9 major reorganization/simplification of HOLCF type classes:
huffman
parents: 39967
diff changeset
   148
lemma is_lub_thelub_ex: "\<lbrakk>\<exists>u. S <<| u; S <| x\<rbrakk> \<Longrightarrow> lub S \<sqsubseteq> x"
27404
62171da527d6 split Completion.thy from CompactBasis.thy
huffman
parents:
diff changeset
   149
by (erule exE, drule lubI, erule is_lub_lub)
62171da527d6 split Completion.thy from CompactBasis.thy
huffman
parents:
diff changeset
   150
28133
218252dfd81e reorganize subsections
huffman
parents: 28053
diff changeset
   151
subsection {* Locale for ideal completion *}
218252dfd81e reorganize subsections
huffman
parents: 28053
diff changeset
   152
39974
b525988432e9 major reorganization/simplification of HOLCF type classes:
huffman
parents: 39967
diff changeset
   153
locale ideal_completion = preorder +
27404
62171da527d6 split Completion.thy from CompactBasis.thy
huffman
parents:
diff changeset
   154
  fixes principal :: "'a::type \<Rightarrow> 'b::cpo"
62171da527d6 split Completion.thy from CompactBasis.thy
huffman
parents:
diff changeset
   155
  fixes rep :: "'b::cpo \<Rightarrow> 'a::type set"
39974
b525988432e9 major reorganization/simplification of HOLCF type classes:
huffman
parents: 39967
diff changeset
   156
  assumes ideal_rep: "\<And>x. ideal (rep x)"
27404
62171da527d6 split Completion.thy from CompactBasis.thy
huffman
parents:
diff changeset
   157
  assumes rep_contlub: "\<And>Y. chain Y \<Longrightarrow> rep (\<Squnion>i. Y i) = (\<Union>i. rep (Y i))"
62171da527d6 split Completion.thy from CompactBasis.thy
huffman
parents:
diff changeset
   158
  assumes rep_principal: "\<And>a. rep (principal a) = {b. b \<preceq> a}"
62171da527d6 split Completion.thy from CompactBasis.thy
huffman
parents:
diff changeset
   159
  assumes subset_repD: "\<And>x y. rep x \<subseteq> rep y \<Longrightarrow> x \<sqsubseteq> y"
39974
b525988432e9 major reorganization/simplification of HOLCF type classes:
huffman
parents: 39967
diff changeset
   160
  assumes countable: "\<exists>f::'a \<Rightarrow> nat. inj f"
27404
62171da527d6 split Completion.thy from CompactBasis.thy
huffman
parents:
diff changeset
   161
begin
62171da527d6 split Completion.thy from CompactBasis.thy
huffman
parents:
diff changeset
   162
28133
218252dfd81e reorganize subsections
huffman
parents: 28053
diff changeset
   163
lemma rep_mono: "x \<sqsubseteq> y \<Longrightarrow> rep x \<subseteq> rep y"
218252dfd81e reorganize subsections
huffman
parents: 28053
diff changeset
   164
apply (frule bin_chain)
218252dfd81e reorganize subsections
huffman
parents: 28053
diff changeset
   165
apply (drule rep_contlub)
218252dfd81e reorganize subsections
huffman
parents: 28053
diff changeset
   166
apply (simp only: thelubI [OF lub_bin_chain])
218252dfd81e reorganize subsections
huffman
parents: 28053
diff changeset
   167
apply (rule subsetI, rule UN_I [where a=0], simp_all)
218252dfd81e reorganize subsections
huffman
parents: 28053
diff changeset
   168
done
218252dfd81e reorganize subsections
huffman
parents: 28053
diff changeset
   169
31076
99fe356cbbc2 rename constant sq_le to below; rename class sq_ord to below; less->below in many lemma names
huffman
parents: 30729
diff changeset
   170
lemma below_def: "x \<sqsubseteq> y \<longleftrightarrow> rep x \<subseteq> rep y"
28133
218252dfd81e reorganize subsections
huffman
parents: 28053
diff changeset
   171
by (rule iffI [OF rep_mono subset_repD])
218252dfd81e reorganize subsections
huffman
parents: 28053
diff changeset
   172
218252dfd81e reorganize subsections
huffman
parents: 28053
diff changeset
   173
lemma rep_eq: "rep x = {a. principal a \<sqsubseteq> x}"
31076
99fe356cbbc2 rename constant sq_le to below; rename class sq_ord to below; less->below in many lemma names
huffman
parents: 30729
diff changeset
   174
unfolding below_def rep_principal
28133
218252dfd81e reorganize subsections
huffman
parents: 28053
diff changeset
   175
apply safe
218252dfd81e reorganize subsections
huffman
parents: 28053
diff changeset
   176
apply (erule (1) idealD3 [OF ideal_rep])
218252dfd81e reorganize subsections
huffman
parents: 28053
diff changeset
   177
apply (erule subsetD, simp add: r_refl)
218252dfd81e reorganize subsections
huffman
parents: 28053
diff changeset
   178
done
218252dfd81e reorganize subsections
huffman
parents: 28053
diff changeset
   179
31076
99fe356cbbc2 rename constant sq_le to below; rename class sq_ord to below; less->below in many lemma names
huffman
parents: 30729
diff changeset
   180
lemma mem_rep_iff_principal_below: "a \<in> rep x \<longleftrightarrow> principal a \<sqsubseteq> x"
28133
218252dfd81e reorganize subsections
huffman
parents: 28053
diff changeset
   181
by (simp add: rep_eq)
218252dfd81e reorganize subsections
huffman
parents: 28053
diff changeset
   182
31076
99fe356cbbc2 rename constant sq_le to below; rename class sq_ord to below; less->below in many lemma names
huffman
parents: 30729
diff changeset
   183
lemma principal_below_iff_mem_rep: "principal a \<sqsubseteq> x \<longleftrightarrow> a \<in> rep x"
28133
218252dfd81e reorganize subsections
huffman
parents: 28053
diff changeset
   184
by (simp add: rep_eq)
218252dfd81e reorganize subsections
huffman
parents: 28053
diff changeset
   185
31076
99fe356cbbc2 rename constant sq_le to below; rename class sq_ord to below; less->below in many lemma names
huffman
parents: 30729
diff changeset
   186
lemma principal_below_iff [simp]: "principal a \<sqsubseteq> principal b \<longleftrightarrow> a \<preceq> b"
99fe356cbbc2 rename constant sq_le to below; rename class sq_ord to below; less->below in many lemma names
huffman
parents: 30729
diff changeset
   187
by (simp add: principal_below_iff_mem_rep rep_principal)
28133
218252dfd81e reorganize subsections
huffman
parents: 28053
diff changeset
   188
218252dfd81e reorganize subsections
huffman
parents: 28053
diff changeset
   189
lemma principal_eq_iff: "principal a = principal b \<longleftrightarrow> a \<preceq> b \<and> b \<preceq> a"
31076
99fe356cbbc2 rename constant sq_le to below; rename class sq_ord to below; less->below in many lemma names
huffman
parents: 30729
diff changeset
   190
unfolding po_eq_conv [where 'a='b] principal_below_iff ..
28133
218252dfd81e reorganize subsections
huffman
parents: 28053
diff changeset
   191
39974
b525988432e9 major reorganization/simplification of HOLCF type classes:
huffman
parents: 39967
diff changeset
   192
lemma eq_iff: "x = y \<longleftrightarrow> rep x = rep y"
b525988432e9 major reorganization/simplification of HOLCF type classes:
huffman
parents: 39967
diff changeset
   193
unfolding po_eq_conv below_def by auto
b525988432e9 major reorganization/simplification of HOLCF type classes:
huffman
parents: 39967
diff changeset
   194
28133
218252dfd81e reorganize subsections
huffman
parents: 28053
diff changeset
   195
lemma repD: "a \<in> rep x \<Longrightarrow> principal a \<sqsubseteq> x"
218252dfd81e reorganize subsections
huffman
parents: 28053
diff changeset
   196
by (simp add: rep_eq)
218252dfd81e reorganize subsections
huffman
parents: 28053
diff changeset
   197
218252dfd81e reorganize subsections
huffman
parents: 28053
diff changeset
   198
lemma principal_mono: "a \<preceq> b \<Longrightarrow> principal a \<sqsubseteq> principal b"
31076
99fe356cbbc2 rename constant sq_le to below; rename class sq_ord to below; less->below in many lemma names
huffman
parents: 30729
diff changeset
   199
by (simp only: principal_below_iff)
28133
218252dfd81e reorganize subsections
huffman
parents: 28053
diff changeset
   200
39974
b525988432e9 major reorganization/simplification of HOLCF type classes:
huffman
parents: 39967
diff changeset
   201
lemma ch2ch_principal [simp]:
b525988432e9 major reorganization/simplification of HOLCF type classes:
huffman
parents: 39967
diff changeset
   202
  "\<forall>i. Y i \<preceq> Y (Suc i) \<Longrightarrow> chain (\<lambda>i. principal (Y i))"
b525988432e9 major reorganization/simplification of HOLCF type classes:
huffman
parents: 39967
diff changeset
   203
by (simp add: chainI principal_mono)
b525988432e9 major reorganization/simplification of HOLCF type classes:
huffman
parents: 39967
diff changeset
   204
28133
218252dfd81e reorganize subsections
huffman
parents: 28053
diff changeset
   205
lemma lub_principal_rep: "principal ` rep x <<| x"
218252dfd81e reorganize subsections
huffman
parents: 28053
diff changeset
   206
apply (rule is_lubI)
218252dfd81e reorganize subsections
huffman
parents: 28053
diff changeset
   207
apply (rule ub_imageI)
218252dfd81e reorganize subsections
huffman
parents: 28053
diff changeset
   208
apply (erule repD)
31076
99fe356cbbc2 rename constant sq_le to below; rename class sq_ord to below; less->below in many lemma names
huffman
parents: 30729
diff changeset
   209
apply (subst below_def)
28133
218252dfd81e reorganize subsections
huffman
parents: 28053
diff changeset
   210
apply (rule subsetI)
218252dfd81e reorganize subsections
huffman
parents: 28053
diff changeset
   211
apply (drule (1) ub_imageD)
218252dfd81e reorganize subsections
huffman
parents: 28053
diff changeset
   212
apply (simp add: rep_eq)
218252dfd81e reorganize subsections
huffman
parents: 28053
diff changeset
   213
done
218252dfd81e reorganize subsections
huffman
parents: 28053
diff changeset
   214
39974
b525988432e9 major reorganization/simplification of HOLCF type classes:
huffman
parents: 39967
diff changeset
   215
subsubsection {* Principal ideals approximate all elements *}
b525988432e9 major reorganization/simplification of HOLCF type classes:
huffman
parents: 39967
diff changeset
   216
b525988432e9 major reorganization/simplification of HOLCF type classes:
huffman
parents: 39967
diff changeset
   217
lemma compact_principal [simp]: "compact (principal a)"
b525988432e9 major reorganization/simplification of HOLCF type classes:
huffman
parents: 39967
diff changeset
   218
by (rule compactI2, simp add: principal_below_iff_mem_rep rep_contlub)
b525988432e9 major reorganization/simplification of HOLCF type classes:
huffman
parents: 39967
diff changeset
   219
b525988432e9 major reorganization/simplification of HOLCF type classes:
huffman
parents: 39967
diff changeset
   220
text {* Construct a chain whose lub is the same as a given ideal *}
b525988432e9 major reorganization/simplification of HOLCF type classes:
huffman
parents: 39967
diff changeset
   221
b525988432e9 major reorganization/simplification of HOLCF type classes:
huffman
parents: 39967
diff changeset
   222
lemma obtain_principal_chain:
b525988432e9 major reorganization/simplification of HOLCF type classes:
huffman
parents: 39967
diff changeset
   223
  obtains Y where "\<forall>i. Y i \<preceq> Y (Suc i)" and "x = (\<Squnion>i. principal (Y i))"
b525988432e9 major reorganization/simplification of HOLCF type classes:
huffman
parents: 39967
diff changeset
   224
proof -
b525988432e9 major reorganization/simplification of HOLCF type classes:
huffman
parents: 39967
diff changeset
   225
  obtain count :: "'a \<Rightarrow> nat" where inj: "inj count"
b525988432e9 major reorganization/simplification of HOLCF type classes:
huffman
parents: 39967
diff changeset
   226
    using countable ..
b525988432e9 major reorganization/simplification of HOLCF type classes:
huffman
parents: 39967
diff changeset
   227
  def enum \<equiv> "\<lambda>i. THE a. count a = i"
b525988432e9 major reorganization/simplification of HOLCF type classes:
huffman
parents: 39967
diff changeset
   228
  have enum_count [simp]: "\<And>x. enum (count x) = x"
b525988432e9 major reorganization/simplification of HOLCF type classes:
huffman
parents: 39967
diff changeset
   229
    unfolding enum_def by (simp add: inj_eq [OF inj])
b525988432e9 major reorganization/simplification of HOLCF type classes:
huffman
parents: 39967
diff changeset
   230
  def a \<equiv> "LEAST i. enum i \<in> rep x"
b525988432e9 major reorganization/simplification of HOLCF type classes:
huffman
parents: 39967
diff changeset
   231
  def b \<equiv> "\<lambda>i. LEAST j. enum j \<in> rep x \<and> \<not> enum j \<preceq> enum i"
b525988432e9 major reorganization/simplification of HOLCF type classes:
huffman
parents: 39967
diff changeset
   232
  def c \<equiv> "\<lambda>i j. LEAST k. enum k \<in> rep x \<and> enum i \<preceq> enum k \<and> enum j \<preceq> enum k"
b525988432e9 major reorganization/simplification of HOLCF type classes:
huffman
parents: 39967
diff changeset
   233
  def P \<equiv> "\<lambda>i. \<exists>j. enum j \<in> rep x \<and> \<not> enum j \<preceq> enum i"
b525988432e9 major reorganization/simplification of HOLCF type classes:
huffman
parents: 39967
diff changeset
   234
  def X \<equiv> "nat_rec a (\<lambda>n i. if P i then c i (b i) else i)"
b525988432e9 major reorganization/simplification of HOLCF type classes:
huffman
parents: 39967
diff changeset
   235
  have X_0: "X 0 = a" unfolding X_def by simp
b525988432e9 major reorganization/simplification of HOLCF type classes:
huffman
parents: 39967
diff changeset
   236
  have X_Suc: "\<And>n. X (Suc n) = (if P (X n) then c (X n) (b (X n)) else X n)"
b525988432e9 major reorganization/simplification of HOLCF type classes:
huffman
parents: 39967
diff changeset
   237
    unfolding X_def by simp
b525988432e9 major reorganization/simplification of HOLCF type classes:
huffman
parents: 39967
diff changeset
   238
  have a_mem: "enum a \<in> rep x"
b525988432e9 major reorganization/simplification of HOLCF type classes:
huffman
parents: 39967
diff changeset
   239
    unfolding a_def
b525988432e9 major reorganization/simplification of HOLCF type classes:
huffman
parents: 39967
diff changeset
   240
    apply (rule LeastI_ex)
b525988432e9 major reorganization/simplification of HOLCF type classes:
huffman
parents: 39967
diff changeset
   241
    apply (cut_tac ideal_rep [of x])
b525988432e9 major reorganization/simplification of HOLCF type classes:
huffman
parents: 39967
diff changeset
   242
    apply (drule idealD1)
b525988432e9 major reorganization/simplification of HOLCF type classes:
huffman
parents: 39967
diff changeset
   243
    apply (clarify, rename_tac a)
b525988432e9 major reorganization/simplification of HOLCF type classes:
huffman
parents: 39967
diff changeset
   244
    apply (rule_tac x="count a" in exI, simp)
b525988432e9 major reorganization/simplification of HOLCF type classes:
huffman
parents: 39967
diff changeset
   245
    done
b525988432e9 major reorganization/simplification of HOLCF type classes:
huffman
parents: 39967
diff changeset
   246
  have b: "\<And>i. P i \<Longrightarrow> enum i \<in> rep x
b525988432e9 major reorganization/simplification of HOLCF type classes:
huffman
parents: 39967
diff changeset
   247
    \<Longrightarrow> enum (b i) \<in> rep x \<and> \<not> enum (b i) \<preceq> enum i"
b525988432e9 major reorganization/simplification of HOLCF type classes:
huffman
parents: 39967
diff changeset
   248
    unfolding P_def b_def by (erule LeastI2_ex, simp)
b525988432e9 major reorganization/simplification of HOLCF type classes:
huffman
parents: 39967
diff changeset
   249
  have c: "\<And>i j. enum i \<in> rep x \<Longrightarrow> enum j \<in> rep x
b525988432e9 major reorganization/simplification of HOLCF type classes:
huffman
parents: 39967
diff changeset
   250
    \<Longrightarrow> enum (c i j) \<in> rep x \<and> enum i \<preceq> enum (c i j) \<and> enum j \<preceq> enum (c i j)"
b525988432e9 major reorganization/simplification of HOLCF type classes:
huffman
parents: 39967
diff changeset
   251
    unfolding c_def
b525988432e9 major reorganization/simplification of HOLCF type classes:
huffman
parents: 39967
diff changeset
   252
    apply (drule (1) idealD2 [OF ideal_rep], clarify)
b525988432e9 major reorganization/simplification of HOLCF type classes:
huffman
parents: 39967
diff changeset
   253
    apply (rule_tac a="count z" in LeastI2, simp, simp)
b525988432e9 major reorganization/simplification of HOLCF type classes:
huffman
parents: 39967
diff changeset
   254
    done
b525988432e9 major reorganization/simplification of HOLCF type classes:
huffman
parents: 39967
diff changeset
   255
  have X_mem: "\<And>n. enum (X n) \<in> rep x"
b525988432e9 major reorganization/simplification of HOLCF type classes:
huffman
parents: 39967
diff changeset
   256
    apply (induct_tac n)
b525988432e9 major reorganization/simplification of HOLCF type classes:
huffman
parents: 39967
diff changeset
   257
    apply (simp add: X_0 a_mem)
b525988432e9 major reorganization/simplification of HOLCF type classes:
huffman
parents: 39967
diff changeset
   258
    apply (clarsimp simp add: X_Suc, rename_tac n)
b525988432e9 major reorganization/simplification of HOLCF type classes:
huffman
parents: 39967
diff changeset
   259
    apply (simp add: b c)
b525988432e9 major reorganization/simplification of HOLCF type classes:
huffman
parents: 39967
diff changeset
   260
    done
b525988432e9 major reorganization/simplification of HOLCF type classes:
huffman
parents: 39967
diff changeset
   261
  have X_chain: "\<And>n. enum (X n) \<preceq> enum (X (Suc n))"
b525988432e9 major reorganization/simplification of HOLCF type classes:
huffman
parents: 39967
diff changeset
   262
    apply (clarsimp simp add: X_Suc r_refl)
b525988432e9 major reorganization/simplification of HOLCF type classes:
huffman
parents: 39967
diff changeset
   263
    apply (simp add: b c X_mem)
b525988432e9 major reorganization/simplification of HOLCF type classes:
huffman
parents: 39967
diff changeset
   264
    done
b525988432e9 major reorganization/simplification of HOLCF type classes:
huffman
parents: 39967
diff changeset
   265
  have less_b: "\<And>n i. n < b i \<Longrightarrow> enum n \<in> rep x \<Longrightarrow> enum n \<preceq> enum i"
b525988432e9 major reorganization/simplification of HOLCF type classes:
huffman
parents: 39967
diff changeset
   266
    unfolding b_def by (drule not_less_Least, simp)
b525988432e9 major reorganization/simplification of HOLCF type classes:
huffman
parents: 39967
diff changeset
   267
  have X_covers: "\<And>n. \<forall>k\<le>n. enum k \<in> rep x \<longrightarrow> enum k \<preceq> enum (X n)"
b525988432e9 major reorganization/simplification of HOLCF type classes:
huffman
parents: 39967
diff changeset
   268
    apply (induct_tac n)
b525988432e9 major reorganization/simplification of HOLCF type classes:
huffman
parents: 39967
diff changeset
   269
    apply (clarsimp simp add: X_0 a_def)
b525988432e9 major reorganization/simplification of HOLCF type classes:
huffman
parents: 39967
diff changeset
   270
    apply (drule_tac k=0 in Least_le, simp add: r_refl)
b525988432e9 major reorganization/simplification of HOLCF type classes:
huffman
parents: 39967
diff changeset
   271
    apply (clarsimp, rename_tac n k)
b525988432e9 major reorganization/simplification of HOLCF type classes:
huffman
parents: 39967
diff changeset
   272
    apply (erule le_SucE)
b525988432e9 major reorganization/simplification of HOLCF type classes:
huffman
parents: 39967
diff changeset
   273
    apply (rule r_trans [OF _ X_chain], simp)
b525988432e9 major reorganization/simplification of HOLCF type classes:
huffman
parents: 39967
diff changeset
   274
    apply (case_tac "P (X n)", simp add: X_Suc)
b525988432e9 major reorganization/simplification of HOLCF type classes:
huffman
parents: 39967
diff changeset
   275
    apply (rule_tac x="b (X n)" and y="Suc n" in linorder_cases)
b525988432e9 major reorganization/simplification of HOLCF type classes:
huffman
parents: 39967
diff changeset
   276
    apply (simp only: less_Suc_eq_le)
b525988432e9 major reorganization/simplification of HOLCF type classes:
huffman
parents: 39967
diff changeset
   277
    apply (drule spec, drule (1) mp, simp add: b X_mem)
b525988432e9 major reorganization/simplification of HOLCF type classes:
huffman
parents: 39967
diff changeset
   278
    apply (simp add: c X_mem)
b525988432e9 major reorganization/simplification of HOLCF type classes:
huffman
parents: 39967
diff changeset
   279
    apply (drule (1) less_b)
b525988432e9 major reorganization/simplification of HOLCF type classes:
huffman
parents: 39967
diff changeset
   280
    apply (erule r_trans)
b525988432e9 major reorganization/simplification of HOLCF type classes:
huffman
parents: 39967
diff changeset
   281
    apply (simp add: b c X_mem)
b525988432e9 major reorganization/simplification of HOLCF type classes:
huffman
parents: 39967
diff changeset
   282
    apply (simp add: X_Suc)
b525988432e9 major reorganization/simplification of HOLCF type classes:
huffman
parents: 39967
diff changeset
   283
    apply (simp add: P_def)
b525988432e9 major reorganization/simplification of HOLCF type classes:
huffman
parents: 39967
diff changeset
   284
    done
b525988432e9 major reorganization/simplification of HOLCF type classes:
huffman
parents: 39967
diff changeset
   285
  have 1: "\<forall>i. enum (X i) \<preceq> enum (X (Suc i))"
b525988432e9 major reorganization/simplification of HOLCF type classes:
huffman
parents: 39967
diff changeset
   286
    by (simp add: X_chain)
b525988432e9 major reorganization/simplification of HOLCF type classes:
huffman
parents: 39967
diff changeset
   287
  have 2: "x = (\<Squnion>n. principal (enum (X n)))"
b525988432e9 major reorganization/simplification of HOLCF type classes:
huffman
parents: 39967
diff changeset
   288
    apply (simp add: eq_iff rep_contlub 1 rep_principal)
b525988432e9 major reorganization/simplification of HOLCF type classes:
huffman
parents: 39967
diff changeset
   289
    apply (auto, rename_tac a)
b525988432e9 major reorganization/simplification of HOLCF type classes:
huffman
parents: 39967
diff changeset
   290
    apply (subgoal_tac "\<exists>i. a = enum i", erule exE)
b525988432e9 major reorganization/simplification of HOLCF type classes:
huffman
parents: 39967
diff changeset
   291
    apply (rule_tac x=i in exI, simp add: X_covers)
b525988432e9 major reorganization/simplification of HOLCF type classes:
huffman
parents: 39967
diff changeset
   292
    apply (rule_tac x="count a" in exI, simp)
b525988432e9 major reorganization/simplification of HOLCF type classes:
huffman
parents: 39967
diff changeset
   293
    apply (erule idealD3 [OF ideal_rep])
b525988432e9 major reorganization/simplification of HOLCF type classes:
huffman
parents: 39967
diff changeset
   294
    apply (rule X_mem)
b525988432e9 major reorganization/simplification of HOLCF type classes:
huffman
parents: 39967
diff changeset
   295
    done
b525988432e9 major reorganization/simplification of HOLCF type classes:
huffman
parents: 39967
diff changeset
   296
  from 1 2 show ?thesis ..
b525988432e9 major reorganization/simplification of HOLCF type classes:
huffman
parents: 39967
diff changeset
   297
qed
b525988432e9 major reorganization/simplification of HOLCF type classes:
huffman
parents: 39967
diff changeset
   298
b525988432e9 major reorganization/simplification of HOLCF type classes:
huffman
parents: 39967
diff changeset
   299
lemma principal_induct:
b525988432e9 major reorganization/simplification of HOLCF type classes:
huffman
parents: 39967
diff changeset
   300
  assumes adm: "adm P"
b525988432e9 major reorganization/simplification of HOLCF type classes:
huffman
parents: 39967
diff changeset
   301
  assumes P: "\<And>a. P (principal a)"
b525988432e9 major reorganization/simplification of HOLCF type classes:
huffman
parents: 39967
diff changeset
   302
  shows "P x"
b525988432e9 major reorganization/simplification of HOLCF type classes:
huffman
parents: 39967
diff changeset
   303
apply (rule obtain_principal_chain [of x])
b525988432e9 major reorganization/simplification of HOLCF type classes:
huffman
parents: 39967
diff changeset
   304
apply (simp add: admD [OF adm] P)
b525988432e9 major reorganization/simplification of HOLCF type classes:
huffman
parents: 39967
diff changeset
   305
done
b525988432e9 major reorganization/simplification of HOLCF type classes:
huffman
parents: 39967
diff changeset
   306
b525988432e9 major reorganization/simplification of HOLCF type classes:
huffman
parents: 39967
diff changeset
   307
lemma principal_induct2:
b525988432e9 major reorganization/simplification of HOLCF type classes:
huffman
parents: 39967
diff changeset
   308
  "\<lbrakk>\<And>y. adm (\<lambda>x. P x y); \<And>x. adm (\<lambda>y. P x y);
b525988432e9 major reorganization/simplification of HOLCF type classes:
huffman
parents: 39967
diff changeset
   309
    \<And>a b. P (principal a) (principal b)\<rbrakk> \<Longrightarrow> P x y"
b525988432e9 major reorganization/simplification of HOLCF type classes:
huffman
parents: 39967
diff changeset
   310
apply (rule_tac x=y in spec)
b525988432e9 major reorganization/simplification of HOLCF type classes:
huffman
parents: 39967
diff changeset
   311
apply (rule_tac x=x in principal_induct, simp)
b525988432e9 major reorganization/simplification of HOLCF type classes:
huffman
parents: 39967
diff changeset
   312
apply (rule allI, rename_tac y)
b525988432e9 major reorganization/simplification of HOLCF type classes:
huffman
parents: 39967
diff changeset
   313
apply (rule_tac x=y in principal_induct, simp)
b525988432e9 major reorganization/simplification of HOLCF type classes:
huffman
parents: 39967
diff changeset
   314
apply simp
b525988432e9 major reorganization/simplification of HOLCF type classes:
huffman
parents: 39967
diff changeset
   315
done
b525988432e9 major reorganization/simplification of HOLCF type classes:
huffman
parents: 39967
diff changeset
   316
b525988432e9 major reorganization/simplification of HOLCF type classes:
huffman
parents: 39967
diff changeset
   317
lemma compact_imp_principal: "compact x \<Longrightarrow> \<exists>a. x = principal a"
b525988432e9 major reorganization/simplification of HOLCF type classes:
huffman
parents: 39967
diff changeset
   318
apply (rule obtain_principal_chain [of x])
b525988432e9 major reorganization/simplification of HOLCF type classes:
huffman
parents: 39967
diff changeset
   319
apply (drule adm_compact_neq [OF _ cont_id])
b525988432e9 major reorganization/simplification of HOLCF type classes:
huffman
parents: 39967
diff changeset
   320
apply (subgoal_tac "chain (\<lambda>i. principal (Y i))")
b525988432e9 major reorganization/simplification of HOLCF type classes:
huffman
parents: 39967
diff changeset
   321
apply (drule (2) admD2, fast, simp)
b525988432e9 major reorganization/simplification of HOLCF type classes:
huffman
parents: 39967
diff changeset
   322
done
b525988432e9 major reorganization/simplification of HOLCF type classes:
huffman
parents: 39967
diff changeset
   323
b525988432e9 major reorganization/simplification of HOLCF type classes:
huffman
parents: 39967
diff changeset
   324
lemma obtain_compact_chain:
b525988432e9 major reorganization/simplification of HOLCF type classes:
huffman
parents: 39967
diff changeset
   325
  obtains Y :: "nat \<Rightarrow> 'b"
b525988432e9 major reorganization/simplification of HOLCF type classes:
huffman
parents: 39967
diff changeset
   326
  where "chain Y" and "\<forall>i. compact (Y i)" and "x = (\<Squnion>i. Y i)"
b525988432e9 major reorganization/simplification of HOLCF type classes:
huffman
parents: 39967
diff changeset
   327
apply (rule obtain_principal_chain [of x])
b525988432e9 major reorganization/simplification of HOLCF type classes:
huffman
parents: 39967
diff changeset
   328
apply (rule_tac Y="\<lambda>i. principal (Y i)" in that, simp_all)
b525988432e9 major reorganization/simplification of HOLCF type classes:
huffman
parents: 39967
diff changeset
   329
done
b525988432e9 major reorganization/simplification of HOLCF type classes:
huffman
parents: 39967
diff changeset
   330
28133
218252dfd81e reorganize subsections
huffman
parents: 28053
diff changeset
   331
subsection {* Defining functions in terms of basis elements *}
218252dfd81e reorganize subsections
huffman
parents: 28053
diff changeset
   332
218252dfd81e reorganize subsections
huffman
parents: 28053
diff changeset
   333
definition
218252dfd81e reorganize subsections
huffman
parents: 28053
diff changeset
   334
  basis_fun :: "('a::type \<Rightarrow> 'c::cpo) \<Rightarrow> 'b \<rightarrow> 'c" where
218252dfd81e reorganize subsections
huffman
parents: 28053
diff changeset
   335
  "basis_fun = (\<lambda>f. (\<Lambda> x. lub (f ` rep x)))"
218252dfd81e reorganize subsections
huffman
parents: 28053
diff changeset
   336
27404
62171da527d6 split Completion.thy from CompactBasis.thy
huffman
parents:
diff changeset
   337
lemma basis_fun_lemma:
62171da527d6 split Completion.thy from CompactBasis.thy
huffman
parents:
diff changeset
   338
  fixes f :: "'a::type \<Rightarrow> 'c::cpo"
62171da527d6 split Completion.thy from CompactBasis.thy
huffman
parents:
diff changeset
   339
  assumes f_mono: "\<And>a b. a \<preceq> b \<Longrightarrow> f a \<sqsubseteq> f b"
62171da527d6 split Completion.thy from CompactBasis.thy
huffman
parents:
diff changeset
   340
  shows "\<exists>u. f ` rep x <<| u"
39974
b525988432e9 major reorganization/simplification of HOLCF type classes:
huffman
parents: 39967
diff changeset
   341
proof -
b525988432e9 major reorganization/simplification of HOLCF type classes:
huffman
parents: 39967
diff changeset
   342
  obtain Y where Y: "\<forall>i. Y i \<preceq> Y (Suc i)"
b525988432e9 major reorganization/simplification of HOLCF type classes:
huffman
parents: 39967
diff changeset
   343
  and x: "x = (\<Squnion>i. principal (Y i))"
b525988432e9 major reorganization/simplification of HOLCF type classes:
huffman
parents: 39967
diff changeset
   344
    by (rule obtain_principal_chain [of x])
b525988432e9 major reorganization/simplification of HOLCF type classes:
huffman
parents: 39967
diff changeset
   345
  have chain: "chain (\<lambda>i. f (Y i))"
b525988432e9 major reorganization/simplification of HOLCF type classes:
huffman
parents: 39967
diff changeset
   346
    by (rule chainI, simp add: f_mono Y)
b525988432e9 major reorganization/simplification of HOLCF type classes:
huffman
parents: 39967
diff changeset
   347
  have rep_x: "rep x = (\<Union>n. {a. a \<preceq> Y n})"
b525988432e9 major reorganization/simplification of HOLCF type classes:
huffman
parents: 39967
diff changeset
   348
    by (simp add: x rep_contlub Y rep_principal)
b525988432e9 major reorganization/simplification of HOLCF type classes:
huffman
parents: 39967
diff changeset
   349
  have "f ` rep x <<| (\<Squnion>n. f (Y n))"
b525988432e9 major reorganization/simplification of HOLCF type classes:
huffman
parents: 39967
diff changeset
   350
    apply (rule is_lubI)
b525988432e9 major reorganization/simplification of HOLCF type classes:
huffman
parents: 39967
diff changeset
   351
    apply (rule ub_imageI, rename_tac a)
b525988432e9 major reorganization/simplification of HOLCF type classes:
huffman
parents: 39967
diff changeset
   352
    apply (clarsimp simp add: rep_x)
b525988432e9 major reorganization/simplification of HOLCF type classes:
huffman
parents: 39967
diff changeset
   353
    apply (drule f_mono)
b525988432e9 major reorganization/simplification of HOLCF type classes:
huffman
parents: 39967
diff changeset
   354
    apply (erule below_trans)
b525988432e9 major reorganization/simplification of HOLCF type classes:
huffman
parents: 39967
diff changeset
   355
    apply (rule is_ub_thelub [OF chain])
b525988432e9 major reorganization/simplification of HOLCF type classes:
huffman
parents: 39967
diff changeset
   356
    apply (rule is_lub_thelub [OF chain])
b525988432e9 major reorganization/simplification of HOLCF type classes:
huffman
parents: 39967
diff changeset
   357
    apply (rule ub_rangeI)
b525988432e9 major reorganization/simplification of HOLCF type classes:
huffman
parents: 39967
diff changeset
   358
    apply (drule_tac x="Y i" in ub_imageD)
b525988432e9 major reorganization/simplification of HOLCF type classes:
huffman
parents: 39967
diff changeset
   359
    apply (simp add: rep_x, fast intro: r_refl)
b525988432e9 major reorganization/simplification of HOLCF type classes:
huffman
parents: 39967
diff changeset
   360
    apply assumption
b525988432e9 major reorganization/simplification of HOLCF type classes:
huffman
parents: 39967
diff changeset
   361
    done
b525988432e9 major reorganization/simplification of HOLCF type classes:
huffman
parents: 39967
diff changeset
   362
  thus ?thesis ..
b525988432e9 major reorganization/simplification of HOLCF type classes:
huffman
parents: 39967
diff changeset
   363
qed
27404
62171da527d6 split Completion.thy from CompactBasis.thy
huffman
parents:
diff changeset
   364
62171da527d6 split Completion.thy from CompactBasis.thy
huffman
parents:
diff changeset
   365
lemma basis_fun_beta:
62171da527d6 split Completion.thy from CompactBasis.thy
huffman
parents:
diff changeset
   366
  fixes f :: "'a::type \<Rightarrow> 'c::cpo"
62171da527d6 split Completion.thy from CompactBasis.thy
huffman
parents:
diff changeset
   367
  assumes f_mono: "\<And>a b. a \<preceq> b \<Longrightarrow> f a \<sqsubseteq> f b"
62171da527d6 split Completion.thy from CompactBasis.thy
huffman
parents:
diff changeset
   368
  shows "basis_fun f\<cdot>x = lub (f ` rep x)"
62171da527d6 split Completion.thy from CompactBasis.thy
huffman
parents:
diff changeset
   369
unfolding basis_fun_def
62171da527d6 split Completion.thy from CompactBasis.thy
huffman
parents:
diff changeset
   370
proof (rule beta_cfun)
62171da527d6 split Completion.thy from CompactBasis.thy
huffman
parents:
diff changeset
   371
  have lub: "\<And>x. \<exists>u. f ` rep x <<| u"
62171da527d6 split Completion.thy from CompactBasis.thy
huffman
parents:
diff changeset
   372
    using f_mono by (rule basis_fun_lemma)
62171da527d6 split Completion.thy from CompactBasis.thy
huffman
parents:
diff changeset
   373
  show cont: "cont (\<lambda>x. lub (f ` rep x))"
62171da527d6 split Completion.thy from CompactBasis.thy
huffman
parents:
diff changeset
   374
    apply (rule contI2)
62171da527d6 split Completion.thy from CompactBasis.thy
huffman
parents:
diff changeset
   375
     apply (rule monofunI)
39974
b525988432e9 major reorganization/simplification of HOLCF type classes:
huffman
parents: 39967
diff changeset
   376
     apply (rule is_lub_thelub_ex [OF lub ub_imageI])
b525988432e9 major reorganization/simplification of HOLCF type classes:
huffman
parents: 39967
diff changeset
   377
     apply (rule is_ub_thelub_ex [OF lub imageI])
27404
62171da527d6 split Completion.thy from CompactBasis.thy
huffman
parents:
diff changeset
   378
     apply (erule (1) subsetD [OF rep_mono])
39974
b525988432e9 major reorganization/simplification of HOLCF type classes:
huffman
parents: 39967
diff changeset
   379
    apply (rule is_lub_thelub_ex [OF lub ub_imageI])
27404
62171da527d6 split Completion.thy from CompactBasis.thy
huffman
parents:
diff changeset
   380
    apply (simp add: rep_contlub, clarify)
31076
99fe356cbbc2 rename constant sq_le to below; rename class sq_ord to below; less->below in many lemma names
huffman
parents: 30729
diff changeset
   381
    apply (erule rev_below_trans [OF is_ub_thelub])
39974
b525988432e9 major reorganization/simplification of HOLCF type classes:
huffman
parents: 39967
diff changeset
   382
    apply (erule is_ub_thelub_ex [OF lub imageI])
27404
62171da527d6 split Completion.thy from CompactBasis.thy
huffman
parents:
diff changeset
   383
    done
62171da527d6 split Completion.thy from CompactBasis.thy
huffman
parents:
diff changeset
   384
qed
62171da527d6 split Completion.thy from CompactBasis.thy
huffman
parents:
diff changeset
   385
62171da527d6 split Completion.thy from CompactBasis.thy
huffman
parents:
diff changeset
   386
lemma basis_fun_principal:
62171da527d6 split Completion.thy from CompactBasis.thy
huffman
parents:
diff changeset
   387
  fixes f :: "'a::type \<Rightarrow> 'c::cpo"
62171da527d6 split Completion.thy from CompactBasis.thy
huffman
parents:
diff changeset
   388
  assumes f_mono: "\<And>a b. a \<preceq> b \<Longrightarrow> f a \<sqsubseteq> f b"
62171da527d6 split Completion.thy from CompactBasis.thy
huffman
parents:
diff changeset
   389
  shows "basis_fun f\<cdot>(principal a) = f a"
62171da527d6 split Completion.thy from CompactBasis.thy
huffman
parents:
diff changeset
   390
apply (subst basis_fun_beta, erule f_mono)
62171da527d6 split Completion.thy from CompactBasis.thy
huffman
parents:
diff changeset
   391
apply (subst rep_principal)
62171da527d6 split Completion.thy from CompactBasis.thy
huffman
parents:
diff changeset
   392
apply (rule lub_image_principal, erule f_mono)
62171da527d6 split Completion.thy from CompactBasis.thy
huffman
parents:
diff changeset
   393
done
62171da527d6 split Completion.thy from CompactBasis.thy
huffman
parents:
diff changeset
   394
62171da527d6 split Completion.thy from CompactBasis.thy
huffman
parents:
diff changeset
   395
lemma basis_fun_mono:
62171da527d6 split Completion.thy from CompactBasis.thy
huffman
parents:
diff changeset
   396
  assumes f_mono: "\<And>a b. a \<preceq> b \<Longrightarrow> f a \<sqsubseteq> f b"
62171da527d6 split Completion.thy from CompactBasis.thy
huffman
parents:
diff changeset
   397
  assumes g_mono: "\<And>a b. a \<preceq> b \<Longrightarrow> g a \<sqsubseteq> g b"
31076
99fe356cbbc2 rename constant sq_le to below; rename class sq_ord to below; less->below in many lemma names
huffman
parents: 30729
diff changeset
   398
  assumes below: "\<And>a. f a \<sqsubseteq> g a"
27404
62171da527d6 split Completion.thy from CompactBasis.thy
huffman
parents:
diff changeset
   399
  shows "basis_fun f \<sqsubseteq> basis_fun g"
31076
99fe356cbbc2 rename constant sq_le to below; rename class sq_ord to below; less->below in many lemma names
huffman
parents: 30729
diff changeset
   400
 apply (rule below_cfun_ext)
27404
62171da527d6 split Completion.thy from CompactBasis.thy
huffman
parents:
diff changeset
   401
 apply (simp only: basis_fun_beta f_mono g_mono)
39974
b525988432e9 major reorganization/simplification of HOLCF type classes:
huffman
parents: 39967
diff changeset
   402
 apply (rule is_lub_thelub_ex)
27404
62171da527d6 split Completion.thy from CompactBasis.thy
huffman
parents:
diff changeset
   403
  apply (rule basis_fun_lemma, erule f_mono)
62171da527d6 split Completion.thy from CompactBasis.thy
huffman
parents:
diff changeset
   404
 apply (rule ub_imageI, rename_tac a)
31076
99fe356cbbc2 rename constant sq_le to below; rename class sq_ord to below; less->below in many lemma names
huffman
parents: 30729
diff changeset
   405
 apply (rule below_trans [OF below])
39974
b525988432e9 major reorganization/simplification of HOLCF type classes:
huffman
parents: 39967
diff changeset
   406
 apply (rule is_ub_thelub_ex)
27404
62171da527d6 split Completion.thy from CompactBasis.thy
huffman
parents:
diff changeset
   407
  apply (rule basis_fun_lemma, erule g_mono)
62171da527d6 split Completion.thy from CompactBasis.thy
huffman
parents:
diff changeset
   408
 apply (erule imageI)
62171da527d6 split Completion.thy from CompactBasis.thy
huffman
parents:
diff changeset
   409
done
62171da527d6 split Completion.thy from CompactBasis.thy
huffman
parents:
diff changeset
   410
62171da527d6 split Completion.thy from CompactBasis.thy
huffman
parents:
diff changeset
   411
end
62171da527d6 split Completion.thy from CompactBasis.thy
huffman
parents:
diff changeset
   412
62171da527d6 split Completion.thy from CompactBasis.thy
huffman
parents:
diff changeset
   413
end