author | haftmann |
Thu, 19 Jun 2025 17:15:40 +0200 | |
changeset 82734 | 89347c0cc6a3 |
parent 81585 | adbd2e1407cc |
permissions | -rw-r--r-- |
42151 | 1 |
(* Title: HOL/HOLCF/Cpodef.thy |
16697 | 2 |
Author: Brian Huffman |
3 |
*) |
|
4 |
||
62175 | 5 |
section \<open>Subtypes of pcpos\<close> |
16697 | 6 |
|
40772 | 7 |
theory Cpodef |
81575 | 8 |
imports Cpo |
69913 | 9 |
keywords "pcpodef" "cpodef" :: thy_goal_defn |
16697 | 10 |
begin |
11 |
||
62175 | 12 |
subsection \<open>Proving a subtype is a partial order\<close> |
16697 | 13 |
|
62175 | 14 |
text \<open> |
16697 | 15 |
A subtype of a partial order is itself a partial order, |
16 |
if the ordering is defined in the standard way. |
|
62175 | 17 |
\<close> |
16697 | 18 |
|
81584
a065d8bcfd3d
clarified class/locale reasoning: avoid side-stepping constraints;
wenzelm
parents:
81575
diff
changeset
|
19 |
theorem (in below) typedef_class_po: |
a065d8bcfd3d
clarified class/locale reasoning: avoid side-stepping constraints;
wenzelm
parents:
81575
diff
changeset
|
20 |
fixes Abs :: "'b::po \<Rightarrow> 'a" |
16697 | 21 |
assumes type: "type_definition Rep Abs A" |
67399 | 22 |
and below: "(\<sqsubseteq>) \<equiv> \<lambda>x y. Rep x \<sqsubseteq> Rep y" |
81584
a065d8bcfd3d
clarified class/locale reasoning: avoid side-stepping constraints;
wenzelm
parents:
81575
diff
changeset
|
23 |
shows "class.po below" |
a065d8bcfd3d
clarified class/locale reasoning: avoid side-stepping constraints;
wenzelm
parents:
81575
diff
changeset
|
24 |
apply (rule class.po.intro) |
a065d8bcfd3d
clarified class/locale reasoning: avoid side-stepping constraints;
wenzelm
parents:
81575
diff
changeset
|
25 |
apply (unfold below) |
67312 | 26 |
apply (rule below_refl) |
81585 | 27 |
apply (fact below_trans) |
67312 | 28 |
apply (rule type_definition.Rep_inject [OF type, THEN iffD1]) |
81585 | 29 |
apply (fact below_antisym) |
67312 | 30 |
done |
16697 | 31 |
|
81584
a065d8bcfd3d
clarified class/locale reasoning: avoid side-stepping constraints;
wenzelm
parents:
81575
diff
changeset
|
32 |
lemmas typedef_po_class = below.typedef_class_po [THEN po.intro_of_class] |
67312 | 33 |
|
28073 | 34 |
|
62175 | 35 |
subsection \<open>Proving a subtype is finite\<close> |
25827
c2adeb1bae5c
new instance proofs for classes finite_po, chfin, flat
huffman
parents:
23152
diff
changeset
|
36 |
|
27296
eec7a1889ca5
moved Abs_image to Typedef.thy; prove finite_UNIV outside the locale
huffman
parents:
26420
diff
changeset
|
37 |
lemma typedef_finite_UNIV: |
eec7a1889ca5
moved Abs_image to Typedef.thy; prove finite_UNIV outside the locale
huffman
parents:
26420
diff
changeset
|
38 |
fixes Abs :: "'a::type \<Rightarrow> 'b::type" |
eec7a1889ca5
moved Abs_image to Typedef.thy; prove finite_UNIV outside the locale
huffman
parents:
26420
diff
changeset
|
39 |
assumes type: "type_definition Rep Abs A" |
eec7a1889ca5
moved Abs_image to Typedef.thy; prove finite_UNIV outside the locale
huffman
parents:
26420
diff
changeset
|
40 |
shows "finite A \<Longrightarrow> finite (UNIV :: 'b set)" |
25827
c2adeb1bae5c
new instance proofs for classes finite_po, chfin, flat
huffman
parents:
23152
diff
changeset
|
41 |
proof - |
c2adeb1bae5c
new instance proofs for classes finite_po, chfin, flat
huffman
parents:
23152
diff
changeset
|
42 |
assume "finite A" |
67312 | 43 |
then have "finite (Abs ` A)" |
44 |
by (rule finite_imageI) |
|
45 |
then show "finite (UNIV :: 'b set)" |
|
27296
eec7a1889ca5
moved Abs_image to Typedef.thy; prove finite_UNIV outside the locale
huffman
parents:
26420
diff
changeset
|
46 |
by (simp only: type_definition.Abs_image [OF type]) |
25827
c2adeb1bae5c
new instance proofs for classes finite_po, chfin, flat
huffman
parents:
23152
diff
changeset
|
47 |
qed |
c2adeb1bae5c
new instance proofs for classes finite_po, chfin, flat
huffman
parents:
23152
diff
changeset
|
48 |
|
67312 | 49 |
|
62175 | 50 |
subsection \<open>Proving a subtype is chain-finite\<close> |
17812 | 51 |
|
40035 | 52 |
lemma ch2ch_Rep: |
67399 | 53 |
assumes below: "(\<sqsubseteq>) \<equiv> \<lambda>x y. Rep x \<sqsubseteq> Rep y" |
40035 | 54 |
shows "chain S \<Longrightarrow> chain (\<lambda>i. Rep (S i))" |
67312 | 55 |
unfolding chain_def below . |
17812 | 56 |
|
57 |
theorem typedef_chfin: |
|
58 |
fixes Abs :: "'a::chfin \<Rightarrow> 'b::po" |
|
59 |
assumes type: "type_definition Rep Abs A" |
|
67399 | 60 |
and below: "(\<sqsubseteq>) \<equiv> \<lambda>x y. Rep x \<sqsubseteq> Rep y" |
17812 | 61 |
shows "OFCLASS('b, chfin_class)" |
67312 | 62 |
apply intro_classes |
63 |
apply (drule ch2ch_Rep [OF below]) |
|
64 |
apply (drule chfin) |
|
65 |
apply (unfold max_in_chain_def) |
|
66 |
apply (simp add: type_definition.Rep_inject [OF type]) |
|
67 |
done |
|
68 |
||
17812 | 69 |
|
62175 | 70 |
subsection \<open>Proving a subtype is complete\<close> |
16697 | 71 |
|
62175 | 72 |
text \<open> |
16697 | 73 |
A subtype of a cpo is itself a cpo if the ordering is |
74 |
defined in the standard way, and the defining subset |
|
75 |
is closed with respect to limits of chains. A set is |
|
76 |
closed if and only if membership in the set is an |
|
77 |
admissible predicate. |
|
62175 | 78 |
\<close> |
16697 | 79 |
|
40035 | 80 |
lemma typedef_is_lubI: |
67399 | 81 |
assumes below: "(\<sqsubseteq>) \<equiv> \<lambda>x y. Rep x \<sqsubseteq> Rep y" |
40035 | 82 |
shows "range (\<lambda>i. Rep (S i)) <<| Rep x \<Longrightarrow> range S <<| x" |
67312 | 83 |
by (simp add: is_lub_def is_ub_def below) |
40035 | 84 |
|
16918 | 85 |
lemma Abs_inverse_lub_Rep: |
16697 | 86 |
fixes Abs :: "'a::cpo \<Rightarrow> 'b::po" |
87 |
assumes type: "type_definition Rep Abs A" |
|
67399 | 88 |
and below: "(\<sqsubseteq>) \<equiv> \<lambda>x y. Rep x \<sqsubseteq> Rep y" |
16697 | 89 |
and adm: "adm (\<lambda>x. x \<in> A)" |
16918 | 90 |
shows "chain S \<Longrightarrow> Rep (Abs (\<Squnion>i. Rep (S i))) = (\<Squnion>i. Rep (S i))" |
67312 | 91 |
apply (rule type_definition.Abs_inverse [OF type]) |
92 |
apply (erule admD [OF adm ch2ch_Rep [OF below]]) |
|
93 |
apply (rule type_definition.Rep [OF type]) |
|
94 |
done |
|
16697 | 95 |
|
40770
6023808b38d4
rename cpodef theorems: lub_foo -> is_lub_foo, thelub_foo -> lub_foo
huffman
parents:
40325
diff
changeset
|
96 |
theorem typedef_is_lub: |
16697 | 97 |
fixes Abs :: "'a::cpo \<Rightarrow> 'b::po" |
98 |
assumes type: "type_definition Rep Abs A" |
|
67399 | 99 |
and below: "(\<sqsubseteq>) \<equiv> \<lambda>x y. Rep x \<sqsubseteq> Rep y" |
16697 | 100 |
and adm: "adm (\<lambda>x. x \<in> A)" |
67312 | 101 |
assumes S: "chain S" |
102 |
shows "range S <<| Abs (\<Squnion>i. Rep (S i))" |
|
40035 | 103 |
proof - |
67312 | 104 |
from S have "chain (\<lambda>i. Rep (S i))" |
105 |
by (rule ch2ch_Rep [OF below]) |
|
106 |
then have "range (\<lambda>i. Rep (S i)) <<| (\<Squnion>i. Rep (S i))" |
|
107 |
by (rule cpo_lubI) |
|
108 |
then have "range (\<lambda>i. Rep (S i)) <<| Rep (Abs (\<Squnion>i. Rep (S i)))" |
|
40035 | 109 |
by (simp only: Abs_inverse_lub_Rep [OF type below adm S]) |
67312 | 110 |
then show "range S <<| Abs (\<Squnion>i. Rep (S i))" |
40035 | 111 |
by (rule typedef_is_lubI [OF below]) |
112 |
qed |
|
16697 | 113 |
|
45606 | 114 |
lemmas typedef_lub = typedef_is_lub [THEN lub_eqI] |
16918 | 115 |
|
16697 | 116 |
theorem typedef_cpo: |
117 |
fixes Abs :: "'a::cpo \<Rightarrow> 'b::po" |
|
118 |
assumes type: "type_definition Rep Abs A" |
|
67399 | 119 |
and below: "(\<sqsubseteq>) \<equiv> \<lambda>x y. Rep x \<sqsubseteq> Rep y" |
16697 | 120 |
and adm: "adm (\<lambda>x. x \<in> A)" |
121 |
shows "OFCLASS('b, cpo_class)" |
|
16918 | 122 |
proof |
67312 | 123 |
fix S :: "nat \<Rightarrow> 'b" |
124 |
assume "chain S" |
|
125 |
then have "range S <<| Abs (\<Squnion>i. Rep (S i))" |
|
40770
6023808b38d4
rename cpodef theorems: lub_foo -> is_lub_foo, thelub_foo -> lub_foo
huffman
parents:
40325
diff
changeset
|
126 |
by (rule typedef_is_lub [OF type below adm]) |
67312 | 127 |
then show "\<exists>x. range S <<| x" .. |
16918 | 128 |
qed |
16697 | 129 |
|
67312 | 130 |
|
62175 | 131 |
subsubsection \<open>Continuity of \emph{Rep} and \emph{Abs}\<close> |
16697 | 132 |
|
69597 | 133 |
text \<open>For any sub-cpo, the \<^term>\<open>Rep\<close> function is continuous.\<close> |
16697 | 134 |
|
135 |
theorem typedef_cont_Rep: |
|
136 |
fixes Abs :: "'a::cpo \<Rightarrow> 'b::cpo" |
|
137 |
assumes type: "type_definition Rep Abs A" |
|
67399 | 138 |
and below: "(\<sqsubseteq>) \<equiv> \<lambda>x y. Rep x \<sqsubseteq> Rep y" |
16697 | 139 |
and adm: "adm (\<lambda>x. x \<in> A)" |
40834
a1249aeff5b6
change cpodef-generated cont_Rep rules to cont2cont format
huffman
parents:
40774
diff
changeset
|
140 |
shows "cont (\<lambda>x. f x) \<Longrightarrow> cont (\<lambda>x. Rep (f x))" |
67312 | 141 |
apply (erule cont_apply [OF _ _ cont_const]) |
142 |
apply (rule contI) |
|
143 |
apply (simp only: typedef_lub [OF type below adm]) |
|
144 |
apply (simp only: Abs_inverse_lub_Rep [OF type below adm]) |
|
145 |
apply (rule cpo_lubI) |
|
146 |
apply (erule ch2ch_Rep [OF below]) |
|
147 |
done |
|
16697 | 148 |
|
62175 | 149 |
text \<open> |
69597 | 150 |
For a sub-cpo, we can make the \<^term>\<open>Abs\<close> function continuous |
16697 | 151 |
only if we restrict its domain to the defining subset by |
152 |
composing it with another continuous function. |
|
62175 | 153 |
\<close> |
16697 | 154 |
|
155 |
theorem typedef_cont_Abs: |
|
156 |
fixes Abs :: "'a::cpo \<Rightarrow> 'b::cpo" |
|
157 |
fixes f :: "'c::cpo \<Rightarrow> 'a::cpo" |
|
158 |
assumes type: "type_definition Rep Abs A" |
|
67399 | 159 |
and below: "(\<sqsubseteq>) \<equiv> \<lambda>x y. Rep x \<sqsubseteq> Rep y" |
16918 | 160 |
and adm: "adm (\<lambda>x. x \<in> A)" (* not used *) |
16697 | 161 |
and f_in_A: "\<And>x. f x \<in> A" |
40325 | 162 |
shows "cont f \<Longrightarrow> cont (\<lambda>x. Abs (f x))" |
67312 | 163 |
unfolding cont_def is_lub_def is_ub_def ball_simps below |
164 |
by (simp add: type_definition.Abs_inverse [OF type f_in_A]) |
|
165 |
||
16697 | 166 |
|
62175 | 167 |
subsection \<open>Proving subtype elements are compact\<close> |
17833 | 168 |
|
169 |
theorem typedef_compact: |
|
170 |
fixes Abs :: "'a::cpo \<Rightarrow> 'b::cpo" |
|
171 |
assumes type: "type_definition Rep Abs A" |
|
67399 | 172 |
and below: "(\<sqsubseteq>) \<equiv> \<lambda>x y. Rep x \<sqsubseteq> Rep y" |
17833 | 173 |
and adm: "adm (\<lambda>x. x \<in> A)" |
174 |
shows "compact (Rep k) \<Longrightarrow> compact k" |
|
175 |
proof (unfold compact_def) |
|
176 |
have cont_Rep: "cont Rep" |
|
40834
a1249aeff5b6
change cpodef-generated cont_Rep rules to cont2cont format
huffman
parents:
40774
diff
changeset
|
177 |
by (rule typedef_cont_Rep [OF type below adm cont_id]) |
41182 | 178 |
assume "adm (\<lambda>x. Rep k \<notsqsubseteq> x)" |
179 |
with cont_Rep have "adm (\<lambda>x. Rep k \<notsqsubseteq> Rep x)" by (rule adm_subst) |
|
67312 | 180 |
then show "adm (\<lambda>x. k \<notsqsubseteq> x)" by (unfold below) |
17833 | 181 |
qed |
182 |
||
67312 | 183 |
|
62175 | 184 |
subsection \<open>Proving a subtype is pointed\<close> |
16697 | 185 |
|
62175 | 186 |
text \<open> |
16697 | 187 |
A subtype of a cpo has a least element if and only if |
188 |
the defining subset has a least element. |
|
62175 | 189 |
\<close> |
16697 | 190 |
|
16918 | 191 |
theorem typedef_pcpo_generic: |
16697 | 192 |
fixes Abs :: "'a::cpo \<Rightarrow> 'b::cpo" |
193 |
assumes type: "type_definition Rep Abs A" |
|
67399 | 194 |
and below: "(\<sqsubseteq>) \<equiv> \<lambda>x y. Rep x \<sqsubseteq> Rep y" |
16697 | 195 |
and z_in_A: "z \<in> A" |
196 |
and z_least: "\<And>x. x \<in> A \<Longrightarrow> z \<sqsubseteq> x" |
|
197 |
shows "OFCLASS('b, pcpo_class)" |
|
67312 | 198 |
apply (intro_classes) |
199 |
apply (rule_tac x="Abs z" in exI, rule allI) |
|
200 |
apply (unfold below) |
|
201 |
apply (subst type_definition.Abs_inverse [OF type z_in_A]) |
|
202 |
apply (rule z_least [OF type_definition.Rep [OF type]]) |
|
203 |
done |
|
16697 | 204 |
|
62175 | 205 |
text \<open> |
16697 | 206 |
As a special case, a subtype of a pcpo has a least element |
69597 | 207 |
if the defining subset contains \<^term>\<open>\<bottom>\<close>. |
62175 | 208 |
\<close> |
16697 | 209 |
|
16918 | 210 |
theorem typedef_pcpo: |
16697 | 211 |
fixes Abs :: "'a::pcpo \<Rightarrow> 'b::cpo" |
212 |
assumes type: "type_definition Rep Abs A" |
|
67399 | 213 |
and below: "(\<sqsubseteq>) \<equiv> \<lambda>x y. Rep x \<sqsubseteq> Rep y" |
41430
1aa23e9f2c87
change some lemma names containing 'UU' to 'bottom'
huffman
parents:
41182
diff
changeset
|
214 |
and bottom_in_A: "\<bottom> \<in> A" |
16697 | 215 |
shows "OFCLASS('b, pcpo_class)" |
67312 | 216 |
by (rule typedef_pcpo_generic [OF type below bottom_in_A], rule minimal) |
217 |
||
16697 | 218 |
|
62175 | 219 |
subsubsection \<open>Strictness of \emph{Rep} and \emph{Abs}\<close> |
16697 | 220 |
|
62175 | 221 |
text \<open> |
69597 | 222 |
For a sub-pcpo where \<^term>\<open>\<bottom>\<close> is a member of the defining |
223 |
subset, \<^term>\<open>Rep\<close> and \<^term>\<open>Abs\<close> are both strict. |
|
62175 | 224 |
\<close> |
16697 | 225 |
|
226 |
theorem typedef_Abs_strict: |
|
227 |
assumes type: "type_definition Rep Abs A" |
|
67399 | 228 |
and below: "(\<sqsubseteq>) \<equiv> \<lambda>x y. Rep x \<sqsubseteq> Rep y" |
41430
1aa23e9f2c87
change some lemma names containing 'UU' to 'bottom'
huffman
parents:
41182
diff
changeset
|
229 |
and bottom_in_A: "\<bottom> \<in> A" |
16697 | 230 |
shows "Abs \<bottom> = \<bottom>" |
67312 | 231 |
apply (rule bottomI, unfold below) |
232 |
apply (simp add: type_definition.Abs_inverse [OF type bottom_in_A]) |
|
233 |
done |
|
16697 | 234 |
|
235 |
theorem typedef_Rep_strict: |
|
236 |
assumes type: "type_definition Rep Abs A" |
|
67399 | 237 |
and below: "(\<sqsubseteq>) \<equiv> \<lambda>x y. Rep x \<sqsubseteq> Rep y" |
41430
1aa23e9f2c87
change some lemma names containing 'UU' to 'bottom'
huffman
parents:
41182
diff
changeset
|
238 |
and bottom_in_A: "\<bottom> \<in> A" |
16697 | 239 |
shows "Rep \<bottom> = \<bottom>" |
67312 | 240 |
apply (rule typedef_Abs_strict [OF type below bottom_in_A, THEN subst]) |
241 |
apply (rule type_definition.Abs_inverse [OF type bottom_in_A]) |
|
242 |
done |
|
16697 | 243 |
|
40321
d065b195ec89
rename lemmas *_defined_iff and *_strict_iff to *_bottom_iff
huffman
parents:
40089
diff
changeset
|
244 |
theorem typedef_Abs_bottom_iff: |
25926 | 245 |
assumes type: "type_definition Rep Abs A" |
67399 | 246 |
and below: "(\<sqsubseteq>) \<equiv> \<lambda>x y. Rep x \<sqsubseteq> Rep y" |
41430
1aa23e9f2c87
change some lemma names containing 'UU' to 'bottom'
huffman
parents:
41182
diff
changeset
|
247 |
and bottom_in_A: "\<bottom> \<in> A" |
25926 | 248 |
shows "x \<in> A \<Longrightarrow> (Abs x = \<bottom>) = (x = \<bottom>)" |
67312 | 249 |
apply (rule typedef_Abs_strict [OF type below bottom_in_A, THEN subst]) |
250 |
apply (simp add: type_definition.Abs_inject [OF type] bottom_in_A) |
|
251 |
done |
|
25926 | 252 |
|
40321
d065b195ec89
rename lemmas *_defined_iff and *_strict_iff to *_bottom_iff
huffman
parents:
40089
diff
changeset
|
253 |
theorem typedef_Rep_bottom_iff: |
25926 | 254 |
assumes type: "type_definition Rep Abs A" |
67399 | 255 |
and below: "(\<sqsubseteq>) \<equiv> \<lambda>x y. Rep x \<sqsubseteq> Rep y" |
41430
1aa23e9f2c87
change some lemma names containing 'UU' to 'bottom'
huffman
parents:
41182
diff
changeset
|
256 |
and bottom_in_A: "\<bottom> \<in> A" |
25926 | 257 |
shows "(Rep x = \<bottom>) = (x = \<bottom>)" |
67312 | 258 |
apply (rule typedef_Rep_strict [OF type below bottom_in_A, THEN subst]) |
259 |
apply (simp add: type_definition.Rep_inject [OF type]) |
|
260 |
done |
|
261 |
||
25926 | 262 |
|
62175 | 263 |
subsection \<open>Proving a subtype is flat\<close> |
19519 | 264 |
|
265 |
theorem typedef_flat: |
|
266 |
fixes Abs :: "'a::flat \<Rightarrow> 'b::pcpo" |
|
267 |
assumes type: "type_definition Rep Abs A" |
|
67399 | 268 |
and below: "(\<sqsubseteq>) \<equiv> \<lambda>x y. Rep x \<sqsubseteq> Rep y" |
41430
1aa23e9f2c87
change some lemma names containing 'UU' to 'bottom'
huffman
parents:
41182
diff
changeset
|
269 |
and bottom_in_A: "\<bottom> \<in> A" |
19519 | 270 |
shows "OFCLASS('b, flat_class)" |
67312 | 271 |
apply (intro_classes) |
272 |
apply (unfold below) |
|
273 |
apply (simp add: type_definition.Rep_inject [OF type, symmetric]) |
|
274 |
apply (simp add: typedef_Rep_strict [OF type below bottom_in_A]) |
|
275 |
apply (simp add: ax_flat) |
|
276 |
done |
|
277 |
||
19519 | 278 |
|
62175 | 279 |
subsection \<open>HOLCF type definition package\<close> |
16697 | 280 |
|
69605 | 281 |
ML_file \<open>Tools/cpodef.ML\<close> |
16697 | 282 |
|
283 |
end |