author | nipkow |
Tue, 17 Jun 2025 14:11:40 +0200 | |
changeset 82733 | 8b537e1af2ec |
parent 81586 | 257f93d40d7c |
permissions | -rw-r--r-- |
11608 | 1 |
(* Title: HOL/Typedef.thy |
2 |
Author: Markus Wenzel, TU Munich |
|
11743 | 3 |
*) |
11608 | 4 |
|
60758 | 5 |
section \<open>HOL type definitions\<close> |
11608 | 6 |
|
15131 | 7 |
theory Typedef |
15140 | 8 |
imports Set |
63434 | 9 |
keywords |
69913 | 10 |
"typedef" :: thy_goal_defn and |
63434 | 11 |
"morphisms" :: quasi_command |
15131 | 12 |
begin |
11608 | 13 |
|
13412 | 14 |
locale type_definition = |
15 |
fixes Rep and Abs and A |
|
16 |
assumes Rep: "Rep x \<in> A" |
|
17 |
and Rep_inverse: "Abs (Rep x) = x" |
|
61102 | 18 |
and Abs_inverse: "y \<in> A \<Longrightarrow> Rep (Abs y) = y" |
61799 | 19 |
\<comment> \<open>This will be axiomatized for each typedef!\<close> |
23247 | 20 |
begin |
11608 | 21 |
|
61102 | 22 |
lemma Rep_inject: "Rep x = Rep y \<longleftrightarrow> x = y" |
13412 | 23 |
proof |
24 |
assume "Rep x = Rep y" |
|
23710
a8ac2305eaf2
removed proof dependency on transitivity theorems
haftmann
parents:
23433
diff
changeset
|
25 |
then have "Abs (Rep x) = Abs (Rep y)" by (simp only:) |
81586 | 26 |
also have "Abs (Rep x) = x" by (rule Rep_inverse) |
27 |
also have "Abs (Rep y) = y" by (rule Rep_inverse) |
|
28 |
finally show "x = y" . |
|
13412 | 29 |
next |
81586 | 30 |
show "x = y \<Longrightarrow> Rep x = Rep y" by (simp only:) |
13412 | 31 |
qed |
11608 | 32 |
|
23247 | 33 |
lemma Abs_inject: |
61102 | 34 |
assumes "x \<in> A" and "y \<in> A" |
35 |
shows "Abs x = Abs y \<longleftrightarrow> x = y" |
|
13412 | 36 |
proof |
37 |
assume "Abs x = Abs y" |
|
23710
a8ac2305eaf2
removed proof dependency on transitivity theorems
haftmann
parents:
23433
diff
changeset
|
38 |
then have "Rep (Abs x) = Rep (Abs y)" by (simp only:) |
81586 | 39 |
also from \<open>x \<in> A\<close> have "Rep (Abs x) = x" by (rule Abs_inverse) |
40 |
also from \<open>y \<in> A\<close> have "Rep (Abs y) = y" by (rule Abs_inverse) |
|
41 |
finally show "x = y" . |
|
13412 | 42 |
next |
81586 | 43 |
show "x = y \<Longrightarrow> Abs x = Abs y" by (simp only:) |
11608 | 44 |
qed |
45 |
||
23247 | 46 |
lemma Rep_cases [cases set]: |
61102 | 47 |
assumes "y \<in> A" |
48 |
and hyp: "\<And>x. y = Rep x \<Longrightarrow> P" |
|
13412 | 49 |
shows P |
50 |
proof (rule hyp) |
|
61102 | 51 |
from \<open>y \<in> A\<close> have "Rep (Abs y) = y" by (rule Abs_inverse) |
52 |
then show "y = Rep (Abs y)" .. |
|
11608 | 53 |
qed |
54 |
||
23247 | 55 |
lemma Abs_cases [cases type]: |
61102 | 56 |
assumes r: "\<And>y. x = Abs y \<Longrightarrow> y \<in> A \<Longrightarrow> P" |
13412 | 57 |
shows P |
58 |
proof (rule r) |
|
59 |
have "Abs (Rep x) = x" by (rule Rep_inverse) |
|
61102 | 60 |
then show "x = Abs (Rep x)" .. |
13412 | 61 |
show "Rep x \<in> A" by (rule Rep) |
11608 | 62 |
qed |
63 |
||
23247 | 64 |
lemma Rep_induct [induct set]: |
13412 | 65 |
assumes y: "y \<in> A" |
61102 | 66 |
and hyp: "\<And>x. P (Rep x)" |
13412 | 67 |
shows "P y" |
11608 | 68 |
proof - |
13412 | 69 |
have "P (Rep (Abs y))" by (rule hyp) |
81586 | 70 |
also from y have "Rep (Abs y) = y" by (rule Abs_inverse) |
71 |
finally show "P y" . |
|
11608 | 72 |
qed |
73 |
||
23247 | 74 |
lemma Abs_induct [induct type]: |
61102 | 75 |
assumes r: "\<And>y. y \<in> A \<Longrightarrow> P (Abs y)" |
13412 | 76 |
shows "P x" |
11608 | 77 |
proof - |
13412 | 78 |
have "Rep x \<in> A" by (rule Rep) |
23710
a8ac2305eaf2
removed proof dependency on transitivity theorems
haftmann
parents:
23433
diff
changeset
|
79 |
then have "P (Abs (Rep x))" by (rule r) |
81586 | 80 |
also have "Abs (Rep x) = x" by (rule Rep_inverse) |
81 |
finally show "P x" . |
|
11608 | 82 |
qed |
83 |
||
27295 | 84 |
lemma Rep_range: "range Rep = A" |
24269 | 85 |
proof |
61102 | 86 |
show "range Rep \<subseteq> A" using Rep by (auto simp add: image_def) |
87 |
show "A \<subseteq> range Rep" |
|
23433 | 88 |
proof |
61102 | 89 |
fix x assume "x \<in> A" |
90 |
then have "x = Rep (Abs x)" by (rule Abs_inverse [symmetric]) |
|
91 |
then show "x \<in> range Rep" by (rule range_eqI) |
|
23433 | 92 |
qed |
93 |
qed |
|
94 |
||
27295 | 95 |
lemma Abs_image: "Abs ` A = UNIV" |
96 |
proof |
|
61102 | 97 |
show "Abs ` A \<subseteq> UNIV" by (rule subset_UNIV) |
98 |
show "UNIV \<subseteq> Abs ` A" |
|
27295 | 99 |
proof |
81586 | 100 |
show "x \<in> Abs ` A" for x |
101 |
proof (rule image_eqI) |
|
102 |
show "x = Abs (Rep x)" by (rule Rep_inverse [symmetric]) |
|
103 |
show "Rep x \<in> A" by (rule Rep) |
|
104 |
qed |
|
27295 | 105 |
qed |
106 |
qed |
|
107 |
||
23247 | 108 |
end |
109 |
||
69605 | 110 |
ML_file \<open>Tools/typedef.ML\<close> |
11608 | 111 |
|
112 |
end |