src/HOL/Typedef.thy
 author haftmann Tue Aug 17 16:44:24 2010 +0200 (2010-08-17) changeset 38536 7e57a0dcbd4f parent 38393 7c045c03598f child 41732 996b0c14a430 permissions -rw-r--r--
dropped SML typedef_codegen: does not fit to code equations for record operations any longer
```     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 uses ("Tools/typedef.ML")
```
```    10 begin
```
```    11
```
```    12 ML {*
```
```    13 structure HOL = struct val thy = @{theory HOL} end;
```
```    14 *}  -- "belongs to theory HOL"
```
```    15
```
```    16 locale type_definition =
```
```    17   fixes Rep and Abs and A
```
```    18   assumes Rep: "Rep x \<in> A"
```
```    19     and Rep_inverse: "Abs (Rep x) = x"
```
```    20     and Abs_inverse: "y \<in> A ==> Rep (Abs y) = y"
```
```    21   -- {* This will be axiomatized for each typedef! *}
```
```    22 begin
```
```    23
```
```    24 lemma Rep_inject:
```
```    25   "(Rep x = Rep y) = (x = y)"
```
```    26 proof
```
```    27   assume "Rep x = Rep y"
```
```    28   then have "Abs (Rep x) = Abs (Rep y)" by (simp only:)
```
```    29   moreover have "Abs (Rep x) = x" by (rule Rep_inverse)
```
```    30   moreover have "Abs (Rep y) = y" by (rule Rep_inverse)
```
```    31   ultimately show "x = y" by simp
```
```    32 next
```
```    33   assume "x = y"
```
```    34   thus "Rep x = Rep y" by (simp only:)
```
```    35 qed
```
```    36
```
```    37 lemma Abs_inject:
```
```    38   assumes x: "x \<in> A" and y: "y \<in> A"
```
```    39   shows "(Abs x = Abs y) = (x = y)"
```
```    40 proof
```
```    41   assume "Abs x = Abs y"
```
```    42   then have "Rep (Abs x) = Rep (Abs y)" by (simp only:)
```
```    43   moreover from x have "Rep (Abs x) = x" by (rule Abs_inverse)
```
```    44   moreover from y have "Rep (Abs y) = y" by (rule Abs_inverse)
```
```    45   ultimately show "x = y" by simp
```
```    46 next
```
```    47   assume "x = y"
```
```    48   thus "Abs x = Abs y" by (simp only:)
```
```    49 qed
```
```    50
```
```    51 lemma Rep_cases [cases set]:
```
```    52   assumes y: "y \<in> A"
```
```    53     and hyp: "!!x. y = Rep x ==> P"
```
```    54   shows P
```
```    55 proof (rule hyp)
```
```    56   from y have "Rep (Abs y) = y" by (rule Abs_inverse)
```
```    57   thus "y = Rep (Abs y)" ..
```
```    58 qed
```
```    59
```
```    60 lemma Abs_cases [cases type]:
```
```    61   assumes r: "!!y. x = Abs y ==> y \<in> A ==> P"
```
```    62   shows P
```
```    63 proof (rule r)
```
```    64   have "Abs (Rep x) = x" by (rule Rep_inverse)
```
```    65   thus "x = Abs (Rep x)" ..
```
```    66   show "Rep x \<in> A" by (rule Rep)
```
```    67 qed
```
```    68
```
```    69 lemma Rep_induct [induct set]:
```
```    70   assumes y: "y \<in> A"
```
```    71     and hyp: "!!x. P (Rep x)"
```
```    72   shows "P y"
```
```    73 proof -
```
```    74   have "P (Rep (Abs y))" by (rule hyp)
```
```    75   moreover from y have "Rep (Abs y) = y" by (rule Abs_inverse)
```
```    76   ultimately show "P y" by simp
```
```    77 qed
```
```    78
```
```    79 lemma Abs_induct [induct type]:
```
```    80   assumes r: "!!y. y \<in> A ==> P (Abs y)"
```
```    81   shows "P x"
```
```    82 proof -
```
```    83   have "Rep x \<in> A" by (rule Rep)
```
```    84   then have "P (Abs (Rep x))" by (rule r)
```
```    85   moreover have "Abs (Rep x) = x" by (rule Rep_inverse)
```
```    86   ultimately show "P x" by simp
```
```    87 qed
```
```    88
```
```    89 lemma Rep_range: "range Rep = A"
```
```    90 proof
```
```    91   show "range Rep <= A" using Rep by (auto simp add: image_def)
```
```    92   show "A <= range Rep"
```
```    93   proof
```
```    94     fix x assume "x : A"
```
```    95     hence "x = Rep (Abs x)" by (rule Abs_inverse [symmetric])
```
```    96     thus "x : range Rep" by (rule range_eqI)
```
```    97   qed
```
```    98 qed
```
```    99
```
```   100 lemma Abs_image: "Abs ` A = UNIV"
```
```   101 proof
```
```   102   show "Abs ` A <= UNIV" by (rule subset_UNIV)
```
```   103 next
```
```   104   show "UNIV <= Abs ` A"
```
```   105   proof
```
```   106     fix x
```
```   107     have "x = Abs (Rep x)" by (rule Rep_inverse [symmetric])
```
```   108     moreover have "Rep x : A" by (rule Rep)
```
```   109     ultimately show "x : Abs ` A" by (rule image_eqI)
```
```   110   qed
```
```   111 qed
```
```   112
```
```   113 end
```
```   114
```
```   115 use "Tools/typedef.ML" setup Typedef.setup
```
```   116
```
```   117 end
```