src/HOL/Typedef.thy
author haftmann
Fri Jun 19 07:53:35 2015 +0200 (2015-06-19)
changeset 60517 f16e4fb20652
parent 58889 5b7a9633cfa8
child 60758 d8d85a8172b5
permissions -rw-r--r--
separate class for notions specific for integral (semi)domains, in contrast to fields where these are trivial
wenzelm@11608
     1
(*  Title:      HOL/Typedef.thy
wenzelm@11608
     2
    Author:     Markus Wenzel, TU Munich
wenzelm@11743
     3
*)
wenzelm@11608
     4
wenzelm@58889
     5
section {* 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"
nipkow@15131
    10
begin
wenzelm@11608
    11
wenzelm@13412
    12
locale type_definition =
wenzelm@13412
    13
  fixes Rep and Abs and A
wenzelm@13412
    14
  assumes Rep: "Rep x \<in> A"
wenzelm@13412
    15
    and Rep_inverse: "Abs (Rep x) = x"
wenzelm@13412
    16
    and Abs_inverse: "y \<in> A ==> Rep (Abs y) = y"
wenzelm@13412
    17
  -- {* This will be axiomatized for each typedef! *}
haftmann@23247
    18
begin
wenzelm@11608
    19
haftmann@23247
    20
lemma Rep_inject:
wenzelm@13412
    21
  "(Rep x = Rep y) = (x = y)"
wenzelm@13412
    22
proof
wenzelm@13412
    23
  assume "Rep x = Rep y"
haftmann@23710
    24
  then have "Abs (Rep x) = Abs (Rep y)" by (simp only:)
haftmann@23710
    25
  moreover have "Abs (Rep x) = x" by (rule Rep_inverse)
haftmann@23710
    26
  moreover have "Abs (Rep y) = y" by (rule Rep_inverse)
haftmann@23710
    27
  ultimately show "x = y" by simp
wenzelm@13412
    28
next
wenzelm@13412
    29
  assume "x = y"
wenzelm@13412
    30
  thus "Rep x = Rep y" by (simp only:)
wenzelm@13412
    31
qed
wenzelm@11608
    32
haftmann@23247
    33
lemma Abs_inject:
wenzelm@13412
    34
  assumes x: "x \<in> A" and y: "y \<in> A"
wenzelm@13412
    35
  shows "(Abs x = Abs y) = (x = y)"
wenzelm@13412
    36
proof
wenzelm@13412
    37
  assume "Abs x = Abs y"
haftmann@23710
    38
  then have "Rep (Abs x) = Rep (Abs y)" by (simp only:)
haftmann@23710
    39
  moreover from x have "Rep (Abs x) = x" by (rule Abs_inverse)
haftmann@23710
    40
  moreover from y have "Rep (Abs y) = y" by (rule Abs_inverse)
haftmann@23710
    41
  ultimately show "x = y" by simp
wenzelm@13412
    42
next
wenzelm@13412
    43
  assume "x = y"
wenzelm@13412
    44
  thus "Abs x = Abs y" by (simp only:)
wenzelm@11608
    45
qed
wenzelm@11608
    46
haftmann@23247
    47
lemma Rep_cases [cases set]:
wenzelm@13412
    48
  assumes y: "y \<in> A"
wenzelm@13412
    49
    and hyp: "!!x. y = Rep x ==> P"
wenzelm@13412
    50
  shows P
wenzelm@13412
    51
proof (rule hyp)
wenzelm@13412
    52
  from y have "Rep (Abs y) = y" by (rule Abs_inverse)
wenzelm@13412
    53
  thus "y = Rep (Abs y)" ..
wenzelm@11608
    54
qed
wenzelm@11608
    55
haftmann@23247
    56
lemma Abs_cases [cases type]:
wenzelm@13412
    57
  assumes r: "!!y. x = Abs y ==> y \<in> A ==> P"
wenzelm@13412
    58
  shows P
wenzelm@13412
    59
proof (rule r)
wenzelm@13412
    60
  have "Abs (Rep x) = x" by (rule Rep_inverse)
wenzelm@13412
    61
  thus "x = Abs (Rep x)" ..
wenzelm@13412
    62
  show "Rep x \<in> A" by (rule Rep)
wenzelm@11608
    63
qed
wenzelm@11608
    64
haftmann@23247
    65
lemma Rep_induct [induct set]:
wenzelm@13412
    66
  assumes y: "y \<in> A"
wenzelm@13412
    67
    and hyp: "!!x. P (Rep x)"
wenzelm@13412
    68
  shows "P y"
wenzelm@11608
    69
proof -
wenzelm@13412
    70
  have "P (Rep (Abs y))" by (rule hyp)
haftmann@23710
    71
  moreover from y have "Rep (Abs y) = y" by (rule Abs_inverse)
haftmann@23710
    72
  ultimately show "P y" by simp
wenzelm@11608
    73
qed
wenzelm@11608
    74
haftmann@23247
    75
lemma Abs_induct [induct type]:
wenzelm@13412
    76
  assumes r: "!!y. y \<in> A ==> P (Abs y)"
wenzelm@13412
    77
  shows "P x"
wenzelm@11608
    78
proof -
wenzelm@13412
    79
  have "Rep x \<in> A" by (rule Rep)
haftmann@23710
    80
  then have "P (Abs (Rep x))" by (rule r)
haftmann@23710
    81
  moreover have "Abs (Rep x) = x" by (rule Rep_inverse)
haftmann@23710
    82
  ultimately show "P x" by simp
wenzelm@11608
    83
qed
wenzelm@11608
    84
huffman@27295
    85
lemma Rep_range: "range Rep = A"
huffman@24269
    86
proof
huffman@24269
    87
  show "range Rep <= A" using Rep by (auto simp add: image_def)
huffman@24269
    88
  show "A <= range Rep"
nipkow@23433
    89
  proof
nipkow@23433
    90
    fix x assume "x : A"
huffman@24269
    91
    hence "x = Rep (Abs x)" by (rule Abs_inverse [symmetric])
huffman@24269
    92
    thus "x : range Rep" by (rule range_eqI)
nipkow@23433
    93
  qed
nipkow@23433
    94
qed
nipkow@23433
    95
huffman@27295
    96
lemma Abs_image: "Abs ` A = UNIV"
huffman@27295
    97
proof
huffman@27295
    98
  show "Abs ` A <= UNIV" by (rule subset_UNIV)
huffman@27295
    99
next
huffman@27295
   100
  show "UNIV <= Abs ` A"
huffman@27295
   101
  proof
huffman@27295
   102
    fix x
huffman@27295
   103
    have "x = Abs (Rep x)" by (rule Rep_inverse [symmetric])
huffman@27295
   104
    moreover have "Rep x : A" by (rule Rep)
huffman@27295
   105
    ultimately show "x : Abs ` A" by (rule image_eqI)
huffman@27295
   106
  qed
huffman@27295
   107
qed
huffman@27295
   108
haftmann@23247
   109
end
haftmann@23247
   110
blanchet@58239
   111
ML_file "Tools/typedef.ML"
wenzelm@11608
   112
wenzelm@11608
   113
end