src/HOL/Typedef.thy
author haftmann
Tue, 05 Jun 2007 15:16:08 +0200
changeset 23247 b99dce43d252
parent 22846 fb79144af9a3
child 23433 c2c10abd2a1e
permissions -rw-r--r--
merged Code_Generator.thy into HOL.thy
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
    ID:         $Id$
c760ea8154ee renamed theory "subset" to "Typedef";
wenzelm
parents:
diff changeset
     3
    Author:     Markus Wenzel, TU Munich
11743
wenzelm
parents: 11659
diff changeset
     4
*)
11608
c760ea8154ee renamed theory "subset" to "Typedef";
wenzelm
parents:
diff changeset
     5
11979
0a3dace545c5 converted theory "Set";
wenzelm
parents: 11770
diff changeset
     6
header {* HOL type definitions *}
11608
c760ea8154ee renamed theory "subset" to "Typedef";
wenzelm
parents:
diff changeset
     7
15131
c69542757a4d New theory header syntax.
nipkow
parents: 13421
diff changeset
     8
theory Typedef
15140
322485b816ac import -> imports
nipkow
parents: 15131
diff changeset
     9
imports Set
20426
9ffea7a8b31c added typecopy_package
haftmann
parents: 19459
diff changeset
    10
uses
9ffea7a8b31c added typecopy_package
haftmann
parents: 19459
diff changeset
    11
  ("Tools/typedef_package.ML")
9ffea7a8b31c added typecopy_package
haftmann
parents: 19459
diff changeset
    12
  ("Tools/typecopy_package.ML")
9ffea7a8b31c added typecopy_package
haftmann
parents: 19459
diff changeset
    13
  ("Tools/typedef_codegen.ML")
15131
c69542757a4d New theory header syntax.
nipkow
parents: 13421
diff changeset
    14
begin
11608
c760ea8154ee renamed theory "subset" to "Typedef";
wenzelm
parents:
diff changeset
    15
23247
b99dce43d252 merged Code_Generator.thy into HOL.thy
haftmann
parents: 22846
diff changeset
    16
ML {*
b99dce43d252 merged Code_Generator.thy into HOL.thy
haftmann
parents: 22846
diff changeset
    17
structure HOL = struct val thy = theory "HOL" end;
b99dce43d252 merged Code_Generator.thy into HOL.thy
haftmann
parents: 22846
diff changeset
    18
*}  -- "belongs to theory HOL"
b99dce43d252 merged Code_Generator.thy into HOL.thy
haftmann
parents: 22846
diff changeset
    19
13412
666137b488a4 predicate defs via locales;
wenzelm
parents: 12023
diff changeset
    20
locale type_definition =
666137b488a4 predicate defs via locales;
wenzelm
parents: 12023
diff changeset
    21
  fixes Rep and Abs and A
666137b488a4 predicate defs via locales;
wenzelm
parents: 12023
diff changeset
    22
  assumes Rep: "Rep x \<in> A"
666137b488a4 predicate defs via locales;
wenzelm
parents: 12023
diff changeset
    23
    and Rep_inverse: "Abs (Rep x) = x"
666137b488a4 predicate defs via locales;
wenzelm
parents: 12023
diff changeset
    24
    and Abs_inverse: "y \<in> A ==> Rep (Abs y) = y"
666137b488a4 predicate defs via locales;
wenzelm
parents: 12023
diff changeset
    25
  -- {* This will be axiomatized for each typedef! *}
23247
b99dce43d252 merged Code_Generator.thy into HOL.thy
haftmann
parents: 22846
diff changeset
    26
begin
11608
c760ea8154ee renamed theory "subset" to "Typedef";
wenzelm
parents:
diff changeset
    27
23247
b99dce43d252 merged Code_Generator.thy into HOL.thy
haftmann
parents: 22846
diff changeset
    28
lemma Rep_inject:
13412
666137b488a4 predicate defs via locales;
wenzelm
parents: 12023
diff changeset
    29
  "(Rep x = Rep y) = (x = y)"
666137b488a4 predicate defs via locales;
wenzelm
parents: 12023
diff changeset
    30
proof
666137b488a4 predicate defs via locales;
wenzelm
parents: 12023
diff changeset
    31
  assume "Rep x = Rep y"
666137b488a4 predicate defs via locales;
wenzelm
parents: 12023
diff changeset
    32
  hence "Abs (Rep x) = Abs (Rep y)" by (simp only:)
666137b488a4 predicate defs via locales;
wenzelm
parents: 12023
diff changeset
    33
  also have "Abs (Rep x) = x" by (rule Rep_inverse)
666137b488a4 predicate defs via locales;
wenzelm
parents: 12023
diff changeset
    34
  also have "Abs (Rep y) = y" by (rule Rep_inverse)
666137b488a4 predicate defs via locales;
wenzelm
parents: 12023
diff changeset
    35
  finally show "x = y" .
666137b488a4 predicate defs via locales;
wenzelm
parents: 12023
diff changeset
    36
next
666137b488a4 predicate defs via locales;
wenzelm
parents: 12023
diff changeset
    37
  assume "x = y"
666137b488a4 predicate defs via locales;
wenzelm
parents: 12023
diff changeset
    38
  thus "Rep x = Rep y" by (simp only:)
666137b488a4 predicate defs via locales;
wenzelm
parents: 12023
diff changeset
    39
qed
11608
c760ea8154ee renamed theory "subset" to "Typedef";
wenzelm
parents:
diff changeset
    40
23247
b99dce43d252 merged Code_Generator.thy into HOL.thy
haftmann
parents: 22846
diff changeset
    41
lemma Abs_inject:
13412
666137b488a4 predicate defs via locales;
wenzelm
parents: 12023
diff changeset
    42
  assumes x: "x \<in> A" and y: "y \<in> A"
666137b488a4 predicate defs via locales;
wenzelm
parents: 12023
diff changeset
    43
  shows "(Abs x = Abs y) = (x = y)"
666137b488a4 predicate defs via locales;
wenzelm
parents: 12023
diff changeset
    44
proof
666137b488a4 predicate defs via locales;
wenzelm
parents: 12023
diff changeset
    45
  assume "Abs x = Abs y"
666137b488a4 predicate defs via locales;
wenzelm
parents: 12023
diff changeset
    46
  hence "Rep (Abs x) = Rep (Abs y)" by (simp only:)
666137b488a4 predicate defs via locales;
wenzelm
parents: 12023
diff changeset
    47
  also from x have "Rep (Abs x) = x" by (rule Abs_inverse)
666137b488a4 predicate defs via locales;
wenzelm
parents: 12023
diff changeset
    48
  also from y have "Rep (Abs y) = y" by (rule Abs_inverse)
666137b488a4 predicate defs via locales;
wenzelm
parents: 12023
diff changeset
    49
  finally show "x = y" .
666137b488a4 predicate defs via locales;
wenzelm
parents: 12023
diff changeset
    50
next
666137b488a4 predicate defs via locales;
wenzelm
parents: 12023
diff changeset
    51
  assume "x = y"
666137b488a4 predicate defs via locales;
wenzelm
parents: 12023
diff changeset
    52
  thus "Abs x = Abs y" by (simp only:)
11608
c760ea8154ee renamed theory "subset" to "Typedef";
wenzelm
parents:
diff changeset
    53
qed
c760ea8154ee renamed theory "subset" to "Typedef";
wenzelm
parents:
diff changeset
    54
23247
b99dce43d252 merged Code_Generator.thy into HOL.thy
haftmann
parents: 22846
diff changeset
    55
lemma Rep_cases [cases set]:
13412
666137b488a4 predicate defs via locales;
wenzelm
parents: 12023
diff changeset
    56
  assumes y: "y \<in> A"
666137b488a4 predicate defs via locales;
wenzelm
parents: 12023
diff changeset
    57
    and hyp: "!!x. y = Rep x ==> P"
666137b488a4 predicate defs via locales;
wenzelm
parents: 12023
diff changeset
    58
  shows P
666137b488a4 predicate defs via locales;
wenzelm
parents: 12023
diff changeset
    59
proof (rule hyp)
666137b488a4 predicate defs via locales;
wenzelm
parents: 12023
diff changeset
    60
  from y have "Rep (Abs y) = y" by (rule Abs_inverse)
666137b488a4 predicate defs via locales;
wenzelm
parents: 12023
diff changeset
    61
  thus "y = Rep (Abs y)" ..
11608
c760ea8154ee renamed theory "subset" to "Typedef";
wenzelm
parents:
diff changeset
    62
qed
c760ea8154ee renamed theory "subset" to "Typedef";
wenzelm
parents:
diff changeset
    63
23247
b99dce43d252 merged Code_Generator.thy into HOL.thy
haftmann
parents: 22846
diff changeset
    64
lemma Abs_cases [cases type]:
13412
666137b488a4 predicate defs via locales;
wenzelm
parents: 12023
diff changeset
    65
  assumes r: "!!y. x = Abs y ==> y \<in> A ==> P"
666137b488a4 predicate defs via locales;
wenzelm
parents: 12023
diff changeset
    66
  shows P
666137b488a4 predicate defs via locales;
wenzelm
parents: 12023
diff changeset
    67
proof (rule r)
666137b488a4 predicate defs via locales;
wenzelm
parents: 12023
diff changeset
    68
  have "Abs (Rep x) = x" by (rule Rep_inverse)
666137b488a4 predicate defs via locales;
wenzelm
parents: 12023
diff changeset
    69
  thus "x = Abs (Rep x)" ..
666137b488a4 predicate defs via locales;
wenzelm
parents: 12023
diff changeset
    70
  show "Rep x \<in> A" by (rule Rep)
11608
c760ea8154ee renamed theory "subset" to "Typedef";
wenzelm
parents:
diff changeset
    71
qed
c760ea8154ee renamed theory "subset" to "Typedef";
wenzelm
parents:
diff changeset
    72
23247
b99dce43d252 merged Code_Generator.thy into HOL.thy
haftmann
parents: 22846
diff changeset
    73
lemma Rep_induct [induct set]:
13412
666137b488a4 predicate defs via locales;
wenzelm
parents: 12023
diff changeset
    74
  assumes y: "y \<in> A"
666137b488a4 predicate defs via locales;
wenzelm
parents: 12023
diff changeset
    75
    and hyp: "!!x. P (Rep x)"
666137b488a4 predicate defs via locales;
wenzelm
parents: 12023
diff changeset
    76
  shows "P y"
11608
c760ea8154ee renamed theory "subset" to "Typedef";
wenzelm
parents:
diff changeset
    77
proof -
13412
666137b488a4 predicate defs via locales;
wenzelm
parents: 12023
diff changeset
    78
  have "P (Rep (Abs y))" by (rule hyp)
666137b488a4 predicate defs via locales;
wenzelm
parents: 12023
diff changeset
    79
  also from y have "Rep (Abs y) = y" by (rule Abs_inverse)
666137b488a4 predicate defs via locales;
wenzelm
parents: 12023
diff changeset
    80
  finally show "P y" .
11608
c760ea8154ee renamed theory "subset" to "Typedef";
wenzelm
parents:
diff changeset
    81
qed
c760ea8154ee renamed theory "subset" to "Typedef";
wenzelm
parents:
diff changeset
    82
23247
b99dce43d252 merged Code_Generator.thy into HOL.thy
haftmann
parents: 22846
diff changeset
    83
lemma Abs_induct [induct type]:
13412
666137b488a4 predicate defs via locales;
wenzelm
parents: 12023
diff changeset
    84
  assumes r: "!!y. y \<in> A ==> P (Abs y)"
666137b488a4 predicate defs via locales;
wenzelm
parents: 12023
diff changeset
    85
  shows "P x"
11608
c760ea8154ee renamed theory "subset" to "Typedef";
wenzelm
parents:
diff changeset
    86
proof -
13412
666137b488a4 predicate defs via locales;
wenzelm
parents: 12023
diff changeset
    87
  have "Rep x \<in> A" by (rule Rep)
11608
c760ea8154ee renamed theory "subset" to "Typedef";
wenzelm
parents:
diff changeset
    88
  hence "P (Abs (Rep x))" by (rule r)
13412
666137b488a4 predicate defs via locales;
wenzelm
parents: 12023
diff changeset
    89
  also have "Abs (Rep x) = x" by (rule Rep_inverse)
666137b488a4 predicate defs via locales;
wenzelm
parents: 12023
diff changeset
    90
  finally show "P x" .
11608
c760ea8154ee renamed theory "subset" to "Typedef";
wenzelm
parents:
diff changeset
    91
qed
c760ea8154ee renamed theory "subset" to "Typedef";
wenzelm
parents:
diff changeset
    92
23247
b99dce43d252 merged Code_Generator.thy into HOL.thy
haftmann
parents: 22846
diff changeset
    93
end
b99dce43d252 merged Code_Generator.thy into HOL.thy
haftmann
parents: 22846
diff changeset
    94
11608
c760ea8154ee renamed theory "subset" to "Typedef";
wenzelm
parents:
diff changeset
    95
use "Tools/typedef_package.ML"
20426
9ffea7a8b31c added typecopy_package
haftmann
parents: 19459
diff changeset
    96
use "Tools/typecopy_package.ML"
19459
2041d472fc17 seperated typedef codegen from main code
haftmann
parents: 16417
diff changeset
    97
use "Tools/typedef_codegen.ML"
11608
c760ea8154ee renamed theory "subset" to "Typedef";
wenzelm
parents:
diff changeset
    98
20426
9ffea7a8b31c added typecopy_package
haftmann
parents: 19459
diff changeset
    99
setup {*
22846
fb79144af9a3 simplified DataFun interfaces;
wenzelm
parents: 20426
diff changeset
   100
  TypecopyPackage.setup
20426
9ffea7a8b31c added typecopy_package
haftmann
parents: 19459
diff changeset
   101
  #> TypedefCodegen.setup
9ffea7a8b31c added typecopy_package
haftmann
parents: 19459
diff changeset
   102
*}
15260
a12e999a0113 Added setup for code generator.
berghofe
parents: 15140
diff changeset
   103
11608
c760ea8154ee renamed theory "subset" to "Typedef";
wenzelm
parents:
diff changeset
   104
end