src/HOL/Typedef.thy
author haftmann
Mon, 24 Apr 2006 16:37:52 +0200
changeset 19459 2041d472fc17
parent 16417 9bc16273c2d4
child 20426 9ffea7a8b31c
permissions -rw-r--r--
seperated typedef codegen from main code
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
19459
2041d472fc17 seperated typedef codegen from main code
haftmann
parents: 16417
diff changeset
    10
uses ("Tools/typedef_package.ML") ("Tools/typedef_codegen.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! *}
11608
c760ea8154ee renamed theory "subset" to "Typedef";
wenzelm
parents:
diff changeset
    19
13412
666137b488a4 predicate defs via locales;
wenzelm
parents: 12023
diff changeset
    20
lemma (in type_definition) Rep_inject:
666137b488a4 predicate defs via locales;
wenzelm
parents: 12023
diff changeset
    21
  "(Rep x = Rep y) = (x = y)"
666137b488a4 predicate defs via locales;
wenzelm
parents: 12023
diff changeset
    22
proof
666137b488a4 predicate defs via locales;
wenzelm
parents: 12023
diff changeset
    23
  assume "Rep x = Rep y"
666137b488a4 predicate defs via locales;
wenzelm
parents: 12023
diff changeset
    24
  hence "Abs (Rep x) = Abs (Rep y)" by (simp only:)
666137b488a4 predicate defs via locales;
wenzelm
parents: 12023
diff changeset
    25
  also have "Abs (Rep x) = x" by (rule Rep_inverse)
666137b488a4 predicate defs via locales;
wenzelm
parents: 12023
diff changeset
    26
  also have "Abs (Rep y) = y" by (rule Rep_inverse)
666137b488a4 predicate defs via locales;
wenzelm
parents: 12023
diff changeset
    27
  finally show "x = y" .
666137b488a4 predicate defs via locales;
wenzelm
parents: 12023
diff changeset
    28
next
666137b488a4 predicate defs via locales;
wenzelm
parents: 12023
diff changeset
    29
  assume "x = y"
666137b488a4 predicate defs via locales;
wenzelm
parents: 12023
diff changeset
    30
  thus "Rep x = Rep y" by (simp only:)
666137b488a4 predicate defs via locales;
wenzelm
parents: 12023
diff changeset
    31
qed
11608
c760ea8154ee renamed theory "subset" to "Typedef";
wenzelm
parents:
diff changeset
    32
13412
666137b488a4 predicate defs via locales;
wenzelm
parents: 12023
diff changeset
    33
lemma (in type_definition) Abs_inject:
666137b488a4 predicate defs via locales;
wenzelm
parents: 12023
diff changeset
    34
  assumes x: "x \<in> A" and y: "y \<in> A"
666137b488a4 predicate defs via locales;
wenzelm
parents: 12023
diff changeset
    35
  shows "(Abs x = Abs y) = (x = y)"
666137b488a4 predicate defs via locales;
wenzelm
parents: 12023
diff changeset
    36
proof
666137b488a4 predicate defs via locales;
wenzelm
parents: 12023
diff changeset
    37
  assume "Abs x = Abs y"
666137b488a4 predicate defs via locales;
wenzelm
parents: 12023
diff changeset
    38
  hence "Rep (Abs x) = Rep (Abs y)" by (simp only:)
666137b488a4 predicate defs via locales;
wenzelm
parents: 12023
diff changeset
    39
  also from x have "Rep (Abs x) = x" by (rule Abs_inverse)
666137b488a4 predicate defs via locales;
wenzelm
parents: 12023
diff changeset
    40
  also from y have "Rep (Abs y) = y" by (rule Abs_inverse)
666137b488a4 predicate defs via locales;
wenzelm
parents: 12023
diff changeset
    41
  finally show "x = y" .
666137b488a4 predicate defs via locales;
wenzelm
parents: 12023
diff changeset
    42
next
666137b488a4 predicate defs via locales;
wenzelm
parents: 12023
diff changeset
    43
  assume "x = y"
666137b488a4 predicate defs via locales;
wenzelm
parents: 12023
diff changeset
    44
  thus "Abs x = Abs y" by (simp only:)
11608
c760ea8154ee renamed theory "subset" to "Typedef";
wenzelm
parents:
diff changeset
    45
qed
c760ea8154ee renamed theory "subset" to "Typedef";
wenzelm
parents:
diff changeset
    46
13412
666137b488a4 predicate defs via locales;
wenzelm
parents: 12023
diff changeset
    47
lemma (in type_definition) Rep_cases [cases set]:
666137b488a4 predicate defs via locales;
wenzelm
parents: 12023
diff changeset
    48
  assumes y: "y \<in> A"
666137b488a4 predicate defs via locales;
wenzelm
parents: 12023
diff changeset
    49
    and hyp: "!!x. y = Rep x ==> P"
666137b488a4 predicate defs via locales;
wenzelm
parents: 12023
diff changeset
    50
  shows P
666137b488a4 predicate defs via locales;
wenzelm
parents: 12023
diff changeset
    51
proof (rule hyp)
666137b488a4 predicate defs via locales;
wenzelm
parents: 12023
diff changeset
    52
  from y have "Rep (Abs y) = y" by (rule Abs_inverse)
666137b488a4 predicate defs via locales;
wenzelm
parents: 12023
diff changeset
    53
  thus "y = Rep (Abs y)" ..
11608
c760ea8154ee renamed theory "subset" to "Typedef";
wenzelm
parents:
diff changeset
    54
qed
c760ea8154ee renamed theory "subset" to "Typedef";
wenzelm
parents:
diff changeset
    55
13412
666137b488a4 predicate defs via locales;
wenzelm
parents: 12023
diff changeset
    56
lemma (in type_definition) Abs_cases [cases type]:
666137b488a4 predicate defs via locales;
wenzelm
parents: 12023
diff changeset
    57
  assumes r: "!!y. x = Abs y ==> y \<in> A ==> 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 r)
666137b488a4 predicate defs via locales;
wenzelm
parents: 12023
diff changeset
    60
  have "Abs (Rep x) = x" by (rule Rep_inverse)
666137b488a4 predicate defs via locales;
wenzelm
parents: 12023
diff changeset
    61
  thus "x = Abs (Rep x)" ..
666137b488a4 predicate defs via locales;
wenzelm
parents: 12023
diff changeset
    62
  show "Rep x \<in> A" by (rule Rep)
11608
c760ea8154ee renamed theory "subset" to "Typedef";
wenzelm
parents:
diff changeset
    63
qed
c760ea8154ee renamed theory "subset" to "Typedef";
wenzelm
parents:
diff changeset
    64
13412
666137b488a4 predicate defs via locales;
wenzelm
parents: 12023
diff changeset
    65
lemma (in type_definition) Rep_induct [induct set]:
666137b488a4 predicate defs via locales;
wenzelm
parents: 12023
diff changeset
    66
  assumes y: "y \<in> A"
666137b488a4 predicate defs via locales;
wenzelm
parents: 12023
diff changeset
    67
    and hyp: "!!x. P (Rep x)"
666137b488a4 predicate defs via locales;
wenzelm
parents: 12023
diff changeset
    68
  shows "P y"
11608
c760ea8154ee renamed theory "subset" to "Typedef";
wenzelm
parents:
diff changeset
    69
proof -
13412
666137b488a4 predicate defs via locales;
wenzelm
parents: 12023
diff changeset
    70
  have "P (Rep (Abs y))" by (rule hyp)
666137b488a4 predicate defs via locales;
wenzelm
parents: 12023
diff changeset
    71
  also from y have "Rep (Abs y) = y" by (rule Abs_inverse)
666137b488a4 predicate defs via locales;
wenzelm
parents: 12023
diff changeset
    72
  finally show "P y" .
11608
c760ea8154ee renamed theory "subset" to "Typedef";
wenzelm
parents:
diff changeset
    73
qed
c760ea8154ee renamed theory "subset" to "Typedef";
wenzelm
parents:
diff changeset
    74
13412
666137b488a4 predicate defs via locales;
wenzelm
parents: 12023
diff changeset
    75
lemma (in type_definition) Abs_induct [induct type]:
666137b488a4 predicate defs via locales;
wenzelm
parents: 12023
diff changeset
    76
  assumes r: "!!y. y \<in> A ==> P (Abs y)"
666137b488a4 predicate defs via locales;
wenzelm
parents: 12023
diff changeset
    77
  shows "P x"
11608
c760ea8154ee renamed theory "subset" to "Typedef";
wenzelm
parents:
diff changeset
    78
proof -
13412
666137b488a4 predicate defs via locales;
wenzelm
parents: 12023
diff changeset
    79
  have "Rep x \<in> A" by (rule Rep)
11608
c760ea8154ee renamed theory "subset" to "Typedef";
wenzelm
parents:
diff changeset
    80
  hence "P (Abs (Rep x))" by (rule r)
13412
666137b488a4 predicate defs via locales;
wenzelm
parents: 12023
diff changeset
    81
  also have "Abs (Rep x) = x" by (rule Rep_inverse)
666137b488a4 predicate defs via locales;
wenzelm
parents: 12023
diff changeset
    82
  finally show "P x" .
11608
c760ea8154ee renamed theory "subset" to "Typedef";
wenzelm
parents:
diff changeset
    83
qed
c760ea8154ee renamed theory "subset" to "Typedef";
wenzelm
parents:
diff changeset
    84
c760ea8154ee renamed theory "subset" to "Typedef";
wenzelm
parents:
diff changeset
    85
use "Tools/typedef_package.ML"
19459
2041d472fc17 seperated typedef codegen from main code
haftmann
parents: 16417
diff changeset
    86
use "Tools/typedef_codegen.ML"
11608
c760ea8154ee renamed theory "subset" to "Typedef";
wenzelm
parents:
diff changeset
    87
19459
2041d472fc17 seperated typedef codegen from main code
haftmann
parents: 16417
diff changeset
    88
setup {* TypedefPackage.setup #> TypedefCodegen.setup *}
15260
a12e999a0113 Added setup for code generator.
berghofe
parents: 15140
diff changeset
    89
11608
c760ea8154ee renamed theory "subset" to "Typedef";
wenzelm
parents:
diff changeset
    90
end