src/HOL/Typedef.thy
author wenzelm
Wed Jul 24 22:15:55 2002 +0200 (2002-07-24)
changeset 13421 8fcdf4a26468
parent 13412 666137b488a4
child 15131 c69542757a4d
permissions -rw-r--r--
simplified locale predicates;
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
lemma (in type_definition) Rep_inject:
wenzelm@13412
    19
  "(Rep x = Rep y) = (x = y)"
wenzelm@13412
    20
proof
wenzelm@13412
    21
  assume "Rep x = Rep y"
wenzelm@13412
    22
  hence "Abs (Rep x) = Abs (Rep y)" by (simp only:)
wenzelm@13412
    23
  also have "Abs (Rep x) = x" by (rule Rep_inverse)
wenzelm@13412
    24
  also have "Abs (Rep y) = y" by (rule Rep_inverse)
wenzelm@13412
    25
  finally show "x = y" .
wenzelm@13412
    26
next
wenzelm@13412
    27
  assume "x = y"
wenzelm@13412
    28
  thus "Rep x = Rep y" by (simp only:)
wenzelm@13412
    29
qed
wenzelm@11608
    30
wenzelm@13412
    31
lemma (in type_definition) Abs_inject:
wenzelm@13412
    32
  assumes x: "x \<in> A" and y: "y \<in> A"
wenzelm@13412
    33
  shows "(Abs x = Abs y) = (x = y)"
wenzelm@13412
    34
proof
wenzelm@13412
    35
  assume "Abs x = Abs y"
wenzelm@13412
    36
  hence "Rep (Abs x) = Rep (Abs y)" by (simp only:)
wenzelm@13412
    37
  also from x have "Rep (Abs x) = x" by (rule Abs_inverse)
wenzelm@13412
    38
  also from y have "Rep (Abs y) = y" by (rule Abs_inverse)
wenzelm@13412
    39
  finally show "x = y" .
wenzelm@13412
    40
next
wenzelm@13412
    41
  assume "x = y"
wenzelm@13412
    42
  thus "Abs x = Abs y" by (simp only:)
wenzelm@11608
    43
qed
wenzelm@11608
    44
wenzelm@13412
    45
lemma (in type_definition) Rep_cases [cases set]:
wenzelm@13412
    46
  assumes y: "y \<in> A"
wenzelm@13412
    47
    and hyp: "!!x. y = Rep x ==> P"
wenzelm@13412
    48
  shows P
wenzelm@13412
    49
proof (rule hyp)
wenzelm@13412
    50
  from y have "Rep (Abs y) = y" by (rule Abs_inverse)
wenzelm@13412
    51
  thus "y = Rep (Abs y)" ..
wenzelm@11608
    52
qed
wenzelm@11608
    53
wenzelm@13412
    54
lemma (in type_definition) Abs_cases [cases type]:
wenzelm@13412
    55
  assumes r: "!!y. x = Abs y ==> y \<in> A ==> P"
wenzelm@13412
    56
  shows P
wenzelm@13412
    57
proof (rule r)
wenzelm@13412
    58
  have "Abs (Rep x) = x" by (rule Rep_inverse)
wenzelm@13412
    59
  thus "x = Abs (Rep x)" ..
wenzelm@13412
    60
  show "Rep x \<in> A" by (rule Rep)
wenzelm@11608
    61
qed
wenzelm@11608
    62
wenzelm@13412
    63
lemma (in type_definition) Rep_induct [induct set]:
wenzelm@13412
    64
  assumes y: "y \<in> A"
wenzelm@13412
    65
    and hyp: "!!x. P (Rep x)"
wenzelm@13412
    66
  shows "P y"
wenzelm@11608
    67
proof -
wenzelm@13412
    68
  have "P (Rep (Abs y))" by (rule hyp)
wenzelm@13412
    69
  also from y have "Rep (Abs y) = y" by (rule Abs_inverse)
wenzelm@13412
    70
  finally show "P y" .
wenzelm@11608
    71
qed
wenzelm@11608
    72
wenzelm@13412
    73
lemma (in type_definition) Abs_induct [induct type]:
wenzelm@13412
    74
  assumes r: "!!y. y \<in> A ==> P (Abs y)"
wenzelm@13412
    75
  shows "P x"
wenzelm@11608
    76
proof -
wenzelm@13412
    77
  have "Rep x \<in> A" by (rule Rep)
wenzelm@11608
    78
  hence "P (Abs (Rep x))" by (rule r)
wenzelm@13412
    79
  also have "Abs (Rep x) = x" by (rule Rep_inverse)
wenzelm@13412
    80
  finally show "P x" .
wenzelm@11608
    81
qed
wenzelm@11608
    82
wenzelm@11608
    83
use "Tools/typedef_package.ML"
wenzelm@11608
    84
wenzelm@11608
    85
end