src/HOL/Typedef.thy
author wenzelm
Wed Jul 24 00:10:52 2002 +0200 (2002-07-24)
changeset 13412 666137b488a4
parent 12023 d982f98e0f0d
child 13421 8fcdf4a26468
permissions -rw-r--r--
predicate defs via locales;
wenzelm@11608
     1
(*  Title:      HOL/Typedef.thy
wenzelm@11608
     2
    ID:         $Id$
wenzelm@11608
     3
    Author:     Markus Wenzel, TU Munich
wenzelm@11743
     4
*)
wenzelm@11608
     5
wenzelm@11979
     6
header {* HOL type definitions *}
wenzelm@11608
     7
wenzelm@11608
     8
theory Typedef = Set
wenzelm@11979
     9
files ("Tools/typedef_package.ML"):
wenzelm@11608
    10
wenzelm@13412
    11
locale type_definition =
wenzelm@13412
    12
  fixes Rep and Abs and A
wenzelm@13412
    13
  assumes Rep: "Rep x \<in> A"
wenzelm@13412
    14
    and Rep_inverse: "Abs (Rep x) = x"
wenzelm@13412
    15
    and Abs_inverse: "y \<in> A ==> Rep (Abs y) = y"
wenzelm@13412
    16
  -- {* This will be axiomatized for each typedef! *}
wenzelm@11608
    17
wenzelm@13412
    18
lemmas type_definitionI [intro] =
wenzelm@13412
    19
  type_definition.intro [OF type_definition_axioms.intro]
wenzelm@11608
    20
wenzelm@13412
    21
lemma (in type_definition) Rep_inject:
wenzelm@13412
    22
  "(Rep x = Rep y) = (x = y)"
wenzelm@13412
    23
proof
wenzelm@13412
    24
  assume "Rep x = Rep y"
wenzelm@13412
    25
  hence "Abs (Rep x) = Abs (Rep y)" by (simp only:)
wenzelm@13412
    26
  also have "Abs (Rep x) = x" by (rule Rep_inverse)
wenzelm@13412
    27
  also have "Abs (Rep y) = y" by (rule Rep_inverse)
wenzelm@13412
    28
  finally show "x = y" .
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
wenzelm@13412
    34
lemma (in type_definition) 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"
wenzelm@13412
    39
  hence "Rep (Abs x) = Rep (Abs y)" by (simp only:)
wenzelm@13412
    40
  also from x have "Rep (Abs x) = x" by (rule Abs_inverse)
wenzelm@13412
    41
  also from y have "Rep (Abs y) = y" by (rule Abs_inverse)
wenzelm@13412
    42
  finally show "x = y" .
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
wenzelm@13412
    48
lemma (in type_definition) 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
wenzelm@13412
    57
lemma (in type_definition) 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
wenzelm@13412
    66
lemma (in type_definition) 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)
wenzelm@13412
    72
  also from y have "Rep (Abs y) = y" by (rule Abs_inverse)
wenzelm@13412
    73
  finally show "P y" .
wenzelm@11608
    74
qed
wenzelm@11608
    75
wenzelm@13412
    76
lemma (in type_definition) 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)
wenzelm@11608
    81
  hence "P (Abs (Rep x))" by (rule r)
wenzelm@13412
    82
  also have "Abs (Rep x) = x" by (rule Rep_inverse)
wenzelm@13412
    83
  finally show "P x" .
wenzelm@11608
    84
qed
wenzelm@11608
    85
wenzelm@11608
    86
use "Tools/typedef_package.ML"
wenzelm@11608
    87
wenzelm@11608
    88
end