1 (* Title: HOL/Typedef.thy
2 Author: Markus Wenzel, TU Munich
5 header {* HOL type definitions *}
9 uses ("Tools/typedef.ML")
12 locale type_definition =
13 fixes Rep and Abs and A
14 assumes Rep: "Rep x \<in> A"
15 and Rep_inverse: "Abs (Rep x) = x"
16 and Abs_inverse: "y \<in> A ==> Rep (Abs y) = y"
17 -- {* This will be axiomatized for each typedef! *}
21 "(Rep x = Rep y) = (x = y)"
23 assume "Rep x = Rep y"
24 then have "Abs (Rep x) = Abs (Rep y)" by (simp only:)
25 moreover have "Abs (Rep x) = x" by (rule Rep_inverse)
26 moreover have "Abs (Rep y) = y" by (rule Rep_inverse)
27 ultimately show "x = y" by simp
30 thus "Rep x = Rep y" by (simp only:)
34 assumes x: "x \<in> A" and y: "y \<in> A"
35 shows "(Abs x = Abs y) = (x = y)"
37 assume "Abs x = Abs y"
38 then have "Rep (Abs x) = Rep (Abs y)" by (simp only:)
39 moreover from x have "Rep (Abs x) = x" by (rule Abs_inverse)
40 moreover from y have "Rep (Abs y) = y" by (rule Abs_inverse)
41 ultimately show "x = y" by simp
44 thus "Abs x = Abs y" by (simp only:)
47 lemma Rep_cases [cases set]:
48 assumes y: "y \<in> A"
49 and hyp: "!!x. y = Rep x ==> P"
52 from y have "Rep (Abs y) = y" by (rule Abs_inverse)
53 thus "y = Rep (Abs y)" ..
56 lemma Abs_cases [cases type]:
57 assumes r: "!!y. x = Abs y ==> y \<in> A ==> P"
60 have "Abs (Rep x) = x" by (rule Rep_inverse)
61 thus "x = Abs (Rep x)" ..
62 show "Rep x \<in> A" by (rule Rep)
65 lemma Rep_induct [induct set]:
66 assumes y: "y \<in> A"
67 and hyp: "!!x. P (Rep x)"
70 have "P (Rep (Abs y))" by (rule hyp)
71 moreover from y have "Rep (Abs y) = y" by (rule Abs_inverse)
72 ultimately show "P y" by simp
75 lemma Abs_induct [induct type]:
76 assumes r: "!!y. y \<in> A ==> P (Abs y)"
79 have "Rep x \<in> A" by (rule Rep)
80 then have "P (Abs (Rep x))" by (rule r)
81 moreover have "Abs (Rep x) = x" by (rule Rep_inverse)
82 ultimately show "P x" by simp
85 lemma Rep_range: "range Rep = A"
87 show "range Rep <= A" using Rep by (auto simp add: image_def)
91 hence "x = Rep (Abs x)" by (rule Abs_inverse [symmetric])
92 thus "x : range Rep" by (rule range_eqI)
96 lemma Abs_image: "Abs ` A = UNIV"
98 show "Abs ` A <= UNIV" by (rule subset_UNIV)
100 show "UNIV <= Abs ` A"
103 have "x = Abs (Rep x)" by (rule Rep_inverse [symmetric])
104 moreover have "Rep x : A" by (rule Rep)
105 ultimately show "x : Abs ` A" by (rule image_eqI)
111 use "Tools/typedef.ML" setup Typedef.setup