summary |
shortlog |
changelog |
graph |
tags |
branches |
files |
changeset |
file |
revisions |
annotate |
diff |
raw

src/HOL/Typedef.thy

author | haftmann |

Sun Jun 23 21:16:07 2013 +0200 (2013-06-23) | |

changeset 52435 | 6646bb548c6b |

parent 48891 | c0eafbd55de3 |

child 58239 | 1c5bc387bd4c |

permissions | -rw-r--r-- |

migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier

1 (* Title: HOL/Typedef.thy

2 Author: Markus Wenzel, TU Munich

3 *)

5 header {* HOL type definitions *}

7 theory Typedef

8 imports Set

9 keywords "typedef" :: thy_goal and "morphisms"

10 begin

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! *}

18 begin

20 lemma Rep_inject:

21 "(Rep x = Rep y) = (x = y)"

22 proof

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

28 next

29 assume "x = y"

30 thus "Rep x = Rep y" by (simp only:)

31 qed

33 lemma Abs_inject:

34 assumes x: "x \<in> A" and y: "y \<in> A"

35 shows "(Abs x = Abs y) = (x = y)"

36 proof

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

42 next

43 assume "x = y"

44 thus "Abs x = Abs y" by (simp only:)

45 qed

47 lemma Rep_cases [cases set]:

48 assumes y: "y \<in> A"

49 and hyp: "!!x. y = Rep x ==> P"

50 shows P

51 proof (rule hyp)

52 from y have "Rep (Abs y) = y" by (rule Abs_inverse)

53 thus "y = Rep (Abs y)" ..

54 qed

56 lemma Abs_cases [cases type]:

57 assumes r: "!!y. x = Abs y ==> y \<in> A ==> P"

58 shows P

59 proof (rule r)

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)

63 qed

65 lemma Rep_induct [induct set]:

66 assumes y: "y \<in> A"

67 and hyp: "!!x. P (Rep x)"

68 shows "P y"

69 proof -

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

73 qed

75 lemma Abs_induct [induct type]:

76 assumes r: "!!y. y \<in> A ==> P (Abs y)"

77 shows "P x"

78 proof -

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

83 qed

85 lemma Rep_range: "range Rep = A"

86 proof

87 show "range Rep <= A" using Rep by (auto simp add: image_def)

88 show "A <= range Rep"

89 proof

90 fix x assume "x : A"

91 hence "x = Rep (Abs x)" by (rule Abs_inverse [symmetric])

92 thus "x : range Rep" by (rule range_eqI)

93 qed

94 qed

96 lemma Abs_image: "Abs ` A = UNIV"

97 proof

98 show "Abs ` A <= UNIV" by (rule subset_UNIV)

99 next

100 show "UNIV <= Abs ` A"

101 proof

102 fix x

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)

106 qed

107 qed

109 end

111 ML_file "Tools/typedef.ML" setup Typedef.setup

113 end