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