src/HOL/Typedef.thy
author wenzelm
Fri, 30 Mar 2012 17:22:17 +0200
changeset 47230 6584098d5378
parent 46950 d0181abdbdac
child 48891 c0eafbd55de3
permissions -rw-r--r--
tuned proofs, less guesswork;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
11608
c760ea8154ee renamed theory "subset" to "Typedef";
wenzelm
parents:
diff changeset
     1
(*  Title:      HOL/Typedef.thy
c760ea8154ee renamed theory "subset" to "Typedef";
wenzelm
parents:
diff changeset
     2
    Author:     Markus Wenzel, TU Munich
11743
wenzelm
parents: 11659
diff changeset
     3
*)
11608
c760ea8154ee renamed theory "subset" to "Typedef";
wenzelm
parents:
diff changeset
     4
11979
0a3dace545c5 converted theory "Set";
wenzelm
parents: 11770
diff changeset
     5
header {* HOL type definitions *}
11608
c760ea8154ee renamed theory "subset" to "Typedef";
wenzelm
parents:
diff changeset
     6
15131
c69542757a4d New theory header syntax.
nipkow
parents: 13421
diff changeset
     7
theory Typedef
15140
322485b816ac import -> imports
nipkow
parents: 15131
diff changeset
     8
imports Set
46950
d0181abdbdac declare command keywords via theory header, including strict checking outside Pure;
wenzelm
parents: 46947
diff changeset
     9
keywords "typedef" :: thy_goal and "morphisms"
38536
7e57a0dcbd4f dropped SML typedef_codegen: does not fit to code equations for record operations any longer
haftmann
parents: 38393
diff changeset
    10
uses ("Tools/typedef.ML")
15131
c69542757a4d New theory header syntax.
nipkow
parents: 13421
diff changeset
    11
begin
11608
c760ea8154ee renamed theory "subset" to "Typedef";
wenzelm
parents:
diff changeset
    12
13412
666137b488a4 predicate defs via locales;
wenzelm
parents: 12023
diff changeset
    13
locale type_definition =
666137b488a4 predicate defs via locales;
wenzelm
parents: 12023
diff changeset
    14
  fixes Rep and Abs and A
666137b488a4 predicate defs via locales;
wenzelm
parents: 12023
diff changeset
    15
  assumes Rep: "Rep x \<in> A"
666137b488a4 predicate defs via locales;
wenzelm
parents: 12023
diff changeset
    16
    and Rep_inverse: "Abs (Rep x) = x"
666137b488a4 predicate defs via locales;
wenzelm
parents: 12023
diff changeset
    17
    and Abs_inverse: "y \<in> A ==> Rep (Abs y) = y"
666137b488a4 predicate defs via locales;
wenzelm
parents: 12023
diff changeset
    18
  -- {* This will be axiomatized for each typedef! *}
23247
b99dce43d252 merged Code_Generator.thy into HOL.thy
haftmann
parents: 22846
diff changeset
    19
begin
11608
c760ea8154ee renamed theory "subset" to "Typedef";
wenzelm
parents:
diff changeset
    20
23247
b99dce43d252 merged Code_Generator.thy into HOL.thy
haftmann
parents: 22846
diff changeset
    21
lemma Rep_inject:
13412
666137b488a4 predicate defs via locales;
wenzelm
parents: 12023
diff changeset
    22
  "(Rep x = Rep y) = (x = y)"
666137b488a4 predicate defs via locales;
wenzelm
parents: 12023
diff changeset
    23
proof
666137b488a4 predicate defs via locales;
wenzelm
parents: 12023
diff changeset
    24
  assume "Rep x = Rep y"
23710
a8ac2305eaf2 removed proof dependency on transitivity theorems
haftmann
parents: 23433
diff changeset
    25
  then have "Abs (Rep x) = Abs (Rep y)" by (simp only:)
a8ac2305eaf2 removed proof dependency on transitivity theorems
haftmann
parents: 23433
diff changeset
    26
  moreover have "Abs (Rep x) = x" by (rule Rep_inverse)
a8ac2305eaf2 removed proof dependency on transitivity theorems
haftmann
parents: 23433
diff changeset
    27
  moreover have "Abs (Rep y) = y" by (rule Rep_inverse)
a8ac2305eaf2 removed proof dependency on transitivity theorems
haftmann
parents: 23433
diff changeset
    28
  ultimately show "x = y" by simp
13412
666137b488a4 predicate defs via locales;
wenzelm
parents: 12023
diff changeset
    29
next
666137b488a4 predicate defs via locales;
wenzelm
parents: 12023
diff changeset
    30
  assume "x = y"
666137b488a4 predicate defs via locales;
wenzelm
parents: 12023
diff changeset
    31
  thus "Rep x = Rep y" by (simp only:)
666137b488a4 predicate defs via locales;
wenzelm
parents: 12023
diff changeset
    32
qed
11608
c760ea8154ee renamed theory "subset" to "Typedef";
wenzelm
parents:
diff changeset
    33
23247
b99dce43d252 merged Code_Generator.thy into HOL.thy
haftmann
parents: 22846
diff changeset
    34
lemma Abs_inject:
13412
666137b488a4 predicate defs via locales;
wenzelm
parents: 12023
diff changeset
    35
  assumes x: "x \<in> A" and y: "y \<in> A"
666137b488a4 predicate defs via locales;
wenzelm
parents: 12023
diff changeset
    36
  shows "(Abs x = Abs y) = (x = y)"
666137b488a4 predicate defs via locales;
wenzelm
parents: 12023
diff changeset
    37
proof
666137b488a4 predicate defs via locales;
wenzelm
parents: 12023
diff changeset
    38
  assume "Abs x = Abs y"
23710
a8ac2305eaf2 removed proof dependency on transitivity theorems
haftmann
parents: 23433
diff changeset
    39
  then have "Rep (Abs x) = Rep (Abs y)" by (simp only:)
a8ac2305eaf2 removed proof dependency on transitivity theorems
haftmann
parents: 23433
diff changeset
    40
  moreover from x have "Rep (Abs x) = x" by (rule Abs_inverse)
a8ac2305eaf2 removed proof dependency on transitivity theorems
haftmann
parents: 23433
diff changeset
    41
  moreover from y have "Rep (Abs y) = y" by (rule Abs_inverse)
a8ac2305eaf2 removed proof dependency on transitivity theorems
haftmann
parents: 23433
diff changeset
    42
  ultimately show "x = y" by simp
13412
666137b488a4 predicate defs via locales;
wenzelm
parents: 12023
diff changeset
    43
next
666137b488a4 predicate defs via locales;
wenzelm
parents: 12023
diff changeset
    44
  assume "x = y"
666137b488a4 predicate defs via locales;
wenzelm
parents: 12023
diff changeset
    45
  thus "Abs x = Abs y" by (simp only:)
11608
c760ea8154ee renamed theory "subset" to "Typedef";
wenzelm
parents:
diff changeset
    46
qed
c760ea8154ee renamed theory "subset" to "Typedef";
wenzelm
parents:
diff changeset
    47
23247
b99dce43d252 merged Code_Generator.thy into HOL.thy
haftmann
parents: 22846
diff changeset
    48
lemma Rep_cases [cases set]:
13412
666137b488a4 predicate defs via locales;
wenzelm
parents: 12023
diff changeset
    49
  assumes y: "y \<in> A"
666137b488a4 predicate defs via locales;
wenzelm
parents: 12023
diff changeset
    50
    and hyp: "!!x. y = Rep x ==> P"
666137b488a4 predicate defs via locales;
wenzelm
parents: 12023
diff changeset
    51
  shows P
666137b488a4 predicate defs via locales;
wenzelm
parents: 12023
diff changeset
    52
proof (rule hyp)
666137b488a4 predicate defs via locales;
wenzelm
parents: 12023
diff changeset
    53
  from y have "Rep (Abs y) = y" by (rule Abs_inverse)
666137b488a4 predicate defs via locales;
wenzelm
parents: 12023
diff changeset
    54
  thus "y = Rep (Abs y)" ..
11608
c760ea8154ee renamed theory "subset" to "Typedef";
wenzelm
parents:
diff changeset
    55
qed
c760ea8154ee renamed theory "subset" to "Typedef";
wenzelm
parents:
diff changeset
    56
23247
b99dce43d252 merged Code_Generator.thy into HOL.thy
haftmann
parents: 22846
diff changeset
    57
lemma Abs_cases [cases type]:
13412
666137b488a4 predicate defs via locales;
wenzelm
parents: 12023
diff changeset
    58
  assumes r: "!!y. x = Abs y ==> y \<in> A ==> P"
666137b488a4 predicate defs via locales;
wenzelm
parents: 12023
diff changeset
    59
  shows P
666137b488a4 predicate defs via locales;
wenzelm
parents: 12023
diff changeset
    60
proof (rule r)
666137b488a4 predicate defs via locales;
wenzelm
parents: 12023
diff changeset
    61
  have "Abs (Rep x) = x" by (rule Rep_inverse)
666137b488a4 predicate defs via locales;
wenzelm
parents: 12023
diff changeset
    62
  thus "x = Abs (Rep x)" ..
666137b488a4 predicate defs via locales;
wenzelm
parents: 12023
diff changeset
    63
  show "Rep x \<in> A" by (rule Rep)
11608
c760ea8154ee renamed theory "subset" to "Typedef";
wenzelm
parents:
diff changeset
    64
qed
c760ea8154ee renamed theory "subset" to "Typedef";
wenzelm
parents:
diff changeset
    65
23247
b99dce43d252 merged Code_Generator.thy into HOL.thy
haftmann
parents: 22846
diff changeset
    66
lemma Rep_induct [induct set]:
13412
666137b488a4 predicate defs via locales;
wenzelm
parents: 12023
diff changeset
    67
  assumes y: "y \<in> A"
666137b488a4 predicate defs via locales;
wenzelm
parents: 12023
diff changeset
    68
    and hyp: "!!x. P (Rep x)"
666137b488a4 predicate defs via locales;
wenzelm
parents: 12023
diff changeset
    69
  shows "P y"
11608
c760ea8154ee renamed theory "subset" to "Typedef";
wenzelm
parents:
diff changeset
    70
proof -
13412
666137b488a4 predicate defs via locales;
wenzelm
parents: 12023
diff changeset
    71
  have "P (Rep (Abs y))" by (rule hyp)
23710
a8ac2305eaf2 removed proof dependency on transitivity theorems
haftmann
parents: 23433
diff changeset
    72
  moreover from y have "Rep (Abs y) = y" by (rule Abs_inverse)
a8ac2305eaf2 removed proof dependency on transitivity theorems
haftmann
parents: 23433
diff changeset
    73
  ultimately show "P y" by simp
11608
c760ea8154ee renamed theory "subset" to "Typedef";
wenzelm
parents:
diff changeset
    74
qed
c760ea8154ee renamed theory "subset" to "Typedef";
wenzelm
parents:
diff changeset
    75
23247
b99dce43d252 merged Code_Generator.thy into HOL.thy
haftmann
parents: 22846
diff changeset
    76
lemma Abs_induct [induct type]:
13412
666137b488a4 predicate defs via locales;
wenzelm
parents: 12023
diff changeset
    77
  assumes r: "!!y. y \<in> A ==> P (Abs y)"
666137b488a4 predicate defs via locales;
wenzelm
parents: 12023
diff changeset
    78
  shows "P x"
11608
c760ea8154ee renamed theory "subset" to "Typedef";
wenzelm
parents:
diff changeset
    79
proof -
13412
666137b488a4 predicate defs via locales;
wenzelm
parents: 12023
diff changeset
    80
  have "Rep x \<in> A" by (rule Rep)
23710
a8ac2305eaf2 removed proof dependency on transitivity theorems
haftmann
parents: 23433
diff changeset
    81
  then have "P (Abs (Rep x))" by (rule r)
a8ac2305eaf2 removed proof dependency on transitivity theorems
haftmann
parents: 23433
diff changeset
    82
  moreover have "Abs (Rep x) = x" by (rule Rep_inverse)
a8ac2305eaf2 removed proof dependency on transitivity theorems
haftmann
parents: 23433
diff changeset
    83
  ultimately show "P x" by simp
11608
c760ea8154ee renamed theory "subset" to "Typedef";
wenzelm
parents:
diff changeset
    84
qed
c760ea8154ee renamed theory "subset" to "Typedef";
wenzelm
parents:
diff changeset
    85
27295
cfe5244301dd add lemma Abs_image
huffman
parents: 26802
diff changeset
    86
lemma Rep_range: "range Rep = A"
24269
4b2aac7669b3 remove redundant assumption from Rep_range lemma
huffman
parents: 23710
diff changeset
    87
proof
4b2aac7669b3 remove redundant assumption from Rep_range lemma
huffman
parents: 23710
diff changeset
    88
  show "range Rep <= A" using Rep by (auto simp add: image_def)
4b2aac7669b3 remove redundant assumption from Rep_range lemma
huffman
parents: 23710
diff changeset
    89
  show "A <= range Rep"
23433
c2c10abd2a1e added lemmas
nipkow
parents: 23247
diff changeset
    90
  proof
c2c10abd2a1e added lemmas
nipkow
parents: 23247
diff changeset
    91
    fix x assume "x : A"
24269
4b2aac7669b3 remove redundant assumption from Rep_range lemma
huffman
parents: 23710
diff changeset
    92
    hence "x = Rep (Abs x)" by (rule Abs_inverse [symmetric])
4b2aac7669b3 remove redundant assumption from Rep_range lemma
huffman
parents: 23710
diff changeset
    93
    thus "x : range Rep" by (rule range_eqI)
23433
c2c10abd2a1e added lemmas
nipkow
parents: 23247
diff changeset
    94
  qed
c2c10abd2a1e added lemmas
nipkow
parents: 23247
diff changeset
    95
qed
c2c10abd2a1e added lemmas
nipkow
parents: 23247
diff changeset
    96
27295
cfe5244301dd add lemma Abs_image
huffman
parents: 26802
diff changeset
    97
lemma Abs_image: "Abs ` A = UNIV"
cfe5244301dd add lemma Abs_image
huffman
parents: 26802
diff changeset
    98
proof
cfe5244301dd add lemma Abs_image
huffman
parents: 26802
diff changeset
    99
  show "Abs ` A <= UNIV" by (rule subset_UNIV)
cfe5244301dd add lemma Abs_image
huffman
parents: 26802
diff changeset
   100
next
cfe5244301dd add lemma Abs_image
huffman
parents: 26802
diff changeset
   101
  show "UNIV <= Abs ` A"
cfe5244301dd add lemma Abs_image
huffman
parents: 26802
diff changeset
   102
  proof
cfe5244301dd add lemma Abs_image
huffman
parents: 26802
diff changeset
   103
    fix x
cfe5244301dd add lemma Abs_image
huffman
parents: 26802
diff changeset
   104
    have "x = Abs (Rep x)" by (rule Rep_inverse [symmetric])
cfe5244301dd add lemma Abs_image
huffman
parents: 26802
diff changeset
   105
    moreover have "Rep x : A" by (rule Rep)
cfe5244301dd add lemma Abs_image
huffman
parents: 26802
diff changeset
   106
    ultimately show "x : Abs ` A" by (rule image_eqI)
cfe5244301dd add lemma Abs_image
huffman
parents: 26802
diff changeset
   107
  qed
cfe5244301dd add lemma Abs_image
huffman
parents: 26802
diff changeset
   108
qed
cfe5244301dd add lemma Abs_image
huffman
parents: 26802
diff changeset
   109
23247
b99dce43d252 merged Code_Generator.thy into HOL.thy
haftmann
parents: 22846
diff changeset
   110
end
b99dce43d252 merged Code_Generator.thy into HOL.thy
haftmann
parents: 22846
diff changeset
   111
31723
f5cafe803b55 discontinued ancient tradition to suffix certain ML module names with "_package"
haftmann
parents: 29797
diff changeset
   112
use "Tools/typedef.ML" setup Typedef.setup
11608
c760ea8154ee renamed theory "subset" to "Typedef";
wenzelm
parents:
diff changeset
   113
c760ea8154ee renamed theory "subset" to "Typedef";
wenzelm
parents:
diff changeset
   114
end