src/HOL/Typedef.thy
author wenzelm
Sat Nov 03 01:33:54 2001 +0100 (2001-11-03)
changeset 12023 d982f98e0f0d
parent 11982 65e2822d83dd
child 13412 666137b488a4
permissions -rw-r--r--
tuned;
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@11608
    11
constdefs
wenzelm@11608
    12
  type_definition :: "('a => 'b) => ('b => 'a) => 'b set => bool"
wenzelm@11608
    13
  "type_definition Rep Abs A ==
wenzelm@11608
    14
    (\<forall>x. Rep x \<in> A) \<and>
wenzelm@11608
    15
    (\<forall>x. Abs (Rep x) = x) \<and>
wenzelm@11608
    16
    (\<forall>y \<in> A. Rep (Abs y) = y)"
wenzelm@11608
    17
  -- {* This will be stated as an axiom for each typedef! *}
wenzelm@11608
    18
wenzelm@11608
    19
lemma type_definitionI [intro]:
wenzelm@11608
    20
  "(!!x. Rep x \<in> A) ==>
wenzelm@11608
    21
    (!!x. Abs (Rep x) = x) ==>
wenzelm@11608
    22
    (!!y. y \<in> A ==> Rep (Abs y) = y) ==>
wenzelm@11608
    23
    type_definition Rep Abs A"
wenzelm@11608
    24
  by (unfold type_definition_def) blast
wenzelm@11608
    25
wenzelm@11608
    26
theorem Rep: "type_definition Rep Abs A ==> Rep x \<in> A"
wenzelm@11608
    27
  by (unfold type_definition_def) blast
wenzelm@11608
    28
wenzelm@11608
    29
theorem Rep_inverse: "type_definition Rep Abs A ==> Abs (Rep x) = x"
wenzelm@11608
    30
  by (unfold type_definition_def) blast
wenzelm@11608
    31
wenzelm@11608
    32
theorem Abs_inverse: "type_definition Rep Abs A ==> y \<in> A ==> Rep (Abs y) = y"
wenzelm@11608
    33
  by (unfold type_definition_def) blast
wenzelm@11608
    34
wenzelm@11608
    35
theorem Rep_inject: "type_definition Rep Abs A ==> (Rep x = Rep y) = (x = y)"
wenzelm@11608
    36
proof -
wenzelm@11608
    37
  assume tydef: "type_definition Rep Abs A"
wenzelm@11608
    38
  show ?thesis
wenzelm@11608
    39
  proof
wenzelm@11608
    40
    assume "Rep x = Rep y"
wenzelm@11608
    41
    hence "Abs (Rep x) = Abs (Rep y)" by (simp only:)
wenzelm@11608
    42
    thus "x = y" by (simp only: Rep_inverse [OF tydef])
wenzelm@11608
    43
  next
wenzelm@11608
    44
    assume "x = y"
wenzelm@11608
    45
    thus "Rep x = Rep y" by simp
wenzelm@11608
    46
  qed
wenzelm@11608
    47
qed
wenzelm@11608
    48
wenzelm@11608
    49
theorem Abs_inject:
wenzelm@11608
    50
  "type_definition Rep Abs A ==> x \<in> A ==> y \<in> A ==> (Abs x = Abs y) = (x = y)"
wenzelm@11608
    51
proof -
wenzelm@11608
    52
  assume tydef: "type_definition Rep Abs A"
wenzelm@11608
    53
  assume x: "x \<in> A" and y: "y \<in> A"
wenzelm@11608
    54
  show ?thesis
wenzelm@11608
    55
  proof
wenzelm@11608
    56
    assume "Abs x = Abs y"
wenzelm@11608
    57
    hence "Rep (Abs x) = Rep (Abs y)" by simp
wenzelm@11608
    58
    moreover from x have "Rep (Abs x) = x" by (rule Abs_inverse [OF tydef])
wenzelm@11608
    59
    moreover from y have "Rep (Abs y) = y" by (rule Abs_inverse [OF tydef])
wenzelm@11608
    60
    ultimately show "x = y" by (simp only:)
wenzelm@11608
    61
  next
wenzelm@11608
    62
    assume "x = y"
wenzelm@11608
    63
    thus "Abs x = Abs y" by simp
wenzelm@11608
    64
  qed
wenzelm@11608
    65
qed
wenzelm@11608
    66
wenzelm@11608
    67
theorem Rep_cases:
wenzelm@11608
    68
  "type_definition Rep Abs A ==> y \<in> A ==> (!!x. y = Rep x ==> P) ==> P"
wenzelm@11608
    69
proof -
wenzelm@11608
    70
  assume tydef: "type_definition Rep Abs A"
wenzelm@11608
    71
  assume y: "y \<in> A" and r: "(!!x. y = Rep x ==> P)"
wenzelm@11608
    72
  show P
wenzelm@11608
    73
  proof (rule r)
wenzelm@11608
    74
    from y have "Rep (Abs y) = y" by (rule Abs_inverse [OF tydef])
wenzelm@11608
    75
    thus "y = Rep (Abs y)" ..
wenzelm@11608
    76
  qed
wenzelm@11608
    77
qed
wenzelm@11608
    78
wenzelm@11608
    79
theorem Abs_cases:
wenzelm@11608
    80
  "type_definition Rep Abs A ==> (!!y. x = Abs y ==> y \<in> A ==> P) ==> P"
wenzelm@11608
    81
proof -
wenzelm@11608
    82
  assume tydef: "type_definition Rep Abs A"
wenzelm@11608
    83
  assume r: "!!y. x = Abs y ==> y \<in> A ==> P"
wenzelm@11608
    84
  show P
wenzelm@11608
    85
  proof (rule r)
wenzelm@11608
    86
    have "Abs (Rep x) = x" by (rule Rep_inverse [OF tydef])
wenzelm@11608
    87
    thus "x = Abs (Rep x)" ..
wenzelm@11608
    88
    show "Rep x \<in> A" by (rule Rep [OF tydef])
wenzelm@11608
    89
  qed
wenzelm@11608
    90
qed
wenzelm@11608
    91
wenzelm@11608
    92
theorem Rep_induct:
wenzelm@11608
    93
  "type_definition Rep Abs A ==> y \<in> A ==> (!!x. P (Rep x)) ==> P y"
wenzelm@11608
    94
proof -
wenzelm@11608
    95
  assume tydef: "type_definition Rep Abs A"
wenzelm@11608
    96
  assume "!!x. P (Rep x)" hence "P (Rep (Abs y))" .
wenzelm@11608
    97
  moreover assume "y \<in> A" hence "Rep (Abs y) = y" by (rule Abs_inverse [OF tydef])
wenzelm@11608
    98
  ultimately show "P y" by (simp only:)
wenzelm@11608
    99
qed
wenzelm@11608
   100
wenzelm@11608
   101
theorem Abs_induct:
wenzelm@11608
   102
  "type_definition Rep Abs A ==> (!!y. y \<in> A ==> P (Abs y)) ==> P x"
wenzelm@11608
   103
proof -
wenzelm@11608
   104
  assume tydef: "type_definition Rep Abs A"
wenzelm@11608
   105
  assume r: "!!y. y \<in> A ==> P (Abs y)"
wenzelm@11608
   106
  have "Rep x \<in> A" by (rule Rep [OF tydef])
wenzelm@11608
   107
  hence "P (Abs (Rep x))" by (rule r)
wenzelm@11608
   108
  moreover have "Abs (Rep x) = x" by (rule Rep_inverse [OF tydef])
wenzelm@11608
   109
  ultimately show "P x" by (simp only:)
wenzelm@11608
   110
qed
wenzelm@11608
   111
wenzelm@11608
   112
use "Tools/typedef_package.ML"
wenzelm@11608
   113
wenzelm@11608
   114
end