src/HOL/Typedef.thy
 author wenzelm Thu Mar 15 19:02:34 2012 +0100 (2012-03-15) changeset 46947 b8c7eb0c2f89 parent 41732 996b0c14a430 child 46950 d0181abdbdac permissions -rw-r--r--
declare minor keywords via theory header;
```     1 (*  Title:      HOL/Typedef.thy
```
```     2     Author:     Markus Wenzel, TU Munich
```
```     3 *)
```
```     4
```
```     5 header {* HOL type definitions *}
```
```     6
```
```     7 theory Typedef
```
```     8 imports Set
```
```     9 keywords "morphisms"
```
```    10 uses ("Tools/typedef.ML")
```
```    11 begin
```
```    12
```
```    13 locale type_definition =
```
```    14   fixes Rep and Abs and A
```
```    15   assumes Rep: "Rep x \<in> A"
```
```    16     and Rep_inverse: "Abs (Rep x) = x"
```
```    17     and Abs_inverse: "y \<in> A ==> Rep (Abs y) = y"
```
```    18   -- {* This will be axiomatized for each typedef! *}
```
```    19 begin
```
```    20
```
```    21 lemma Rep_inject:
```
```    22   "(Rep x = Rep y) = (x = y)"
```
```    23 proof
```
```    24   assume "Rep x = Rep y"
```
```    25   then have "Abs (Rep x) = Abs (Rep y)" by (simp only:)
```
```    26   moreover have "Abs (Rep x) = x" by (rule Rep_inverse)
```
```    27   moreover have "Abs (Rep y) = y" by (rule Rep_inverse)
```
```    28   ultimately show "x = y" by simp
```
```    29 next
```
```    30   assume "x = y"
```
```    31   thus "Rep x = Rep y" by (simp only:)
```
```    32 qed
```
```    33
```
```    34 lemma Abs_inject:
```
```    35   assumes x: "x \<in> A" and y: "y \<in> A"
```
```    36   shows "(Abs x = Abs y) = (x = y)"
```
```    37 proof
```
```    38   assume "Abs x = Abs y"
```
```    39   then have "Rep (Abs x) = Rep (Abs y)" by (simp only:)
```
```    40   moreover from x have "Rep (Abs x) = x" by (rule Abs_inverse)
```
```    41   moreover from y have "Rep (Abs y) = y" by (rule Abs_inverse)
```
```    42   ultimately show "x = y" by simp
```
```    43 next
```
```    44   assume "x = y"
```
```    45   thus "Abs x = Abs y" by (simp only:)
```
```    46 qed
```
```    47
```
```    48 lemma Rep_cases [cases set]:
```
```    49   assumes y: "y \<in> A"
```
```    50     and hyp: "!!x. y = Rep x ==> P"
```
```    51   shows P
```
```    52 proof (rule hyp)
```
```    53   from y have "Rep (Abs y) = y" by (rule Abs_inverse)
```
```    54   thus "y = Rep (Abs y)" ..
```
```    55 qed
```
```    56
```
```    57 lemma Abs_cases [cases type]:
```
```    58   assumes r: "!!y. x = Abs y ==> y \<in> A ==> P"
```
```    59   shows P
```
```    60 proof (rule r)
```
```    61   have "Abs (Rep x) = x" by (rule Rep_inverse)
```
```    62   thus "x = Abs (Rep x)" ..
```
```    63   show "Rep x \<in> A" by (rule Rep)
```
```    64 qed
```
```    65
```
```    66 lemma Rep_induct [induct set]:
```
```    67   assumes y: "y \<in> A"
```
```    68     and hyp: "!!x. P (Rep x)"
```
```    69   shows "P y"
```
```    70 proof -
```
```    71   have "P (Rep (Abs y))" by (rule hyp)
```
```    72   moreover from y have "Rep (Abs y) = y" by (rule Abs_inverse)
```
```    73   ultimately show "P y" by simp
```
```    74 qed
```
```    75
```
```    76 lemma Abs_induct [induct type]:
```
```    77   assumes r: "!!y. y \<in> A ==> P (Abs y)"
```
```    78   shows "P x"
```
```    79 proof -
```
```    80   have "Rep x \<in> A" by (rule Rep)
```
```    81   then have "P (Abs (Rep x))" by (rule r)
```
```    82   moreover have "Abs (Rep x) = x" by (rule Rep_inverse)
```
```    83   ultimately show "P x" by simp
```
```    84 qed
```
```    85
```
```    86 lemma Rep_range: "range Rep = A"
```
```    87 proof
```
```    88   show "range Rep <= A" using Rep by (auto simp add: image_def)
```
```    89   show "A <= range Rep"
```
```    90   proof
```
```    91     fix x assume "x : A"
```
```    92     hence "x = Rep (Abs x)" by (rule Abs_inverse [symmetric])
```
```    93     thus "x : range Rep" by (rule range_eqI)
```
```    94   qed
```
```    95 qed
```
```    96
```
```    97 lemma Abs_image: "Abs ` A = UNIV"
```
```    98 proof
```
```    99   show "Abs ` A <= UNIV" by (rule subset_UNIV)
```
```   100 next
```
```   101   show "UNIV <= Abs ` A"
```
```   102   proof
```
```   103     fix x
```
```   104     have "x = Abs (Rep x)" by (rule Rep_inverse [symmetric])
```
```   105     moreover have "Rep x : A" by (rule Rep)
```
```   106     ultimately show "x : Abs ` A" by (rule image_eqI)
```
```   107   qed
```
```   108 qed
```
```   109
```
```   110 end
```
```   111
```
```   112 use "Tools/typedef.ML" setup Typedef.setup
```
```   113
```
```   114 end
```