src/HOL/Typedef.thy
author wenzelm
Sun Oct 14 22:08:29 2001 +0200 (2001-10-14)
changeset 11770 b6bb7a853dd2
parent 11743 b9739c85dd44
child 11979 0a3dace545c5
permissions -rw-r--r--
moved rulify to ObjectLogic;
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@11743
     6
header {* Set-theory lemmas and HOL type definitions *}
wenzelm@11608
     7
wenzelm@11608
     8
theory Typedef = Set
wenzelm@11659
     9
files "subset.ML" "equalities.ML" "mono.ML" ("Tools/typedef_package.ML"):
wenzelm@11608
    10
wenzelm@11770
    11
(*belongs to theory Set*)
wenzelm@11770
    12
declare atomize_ball [symmetric, rulify]
wenzelm@11770
    13
wenzelm@11608
    14
(* Courtesy of Stephan Merz *)
wenzelm@11608
    15
lemma Least_mono: 
wenzelm@11608
    16
  "mono (f::'a::order => 'b::order) ==> EX x:S. ALL y:S. x <= y
wenzelm@11608
    17
    ==> (LEAST y. y : f ` S) = f (LEAST x. x : S)"
wenzelm@11608
    18
  apply clarify
wenzelm@11608
    19
  apply (erule_tac P = "%x. x : S" in LeastI2)
wenzelm@11608
    20
   apply fast
wenzelm@11608
    21
  apply (rule LeastI2)
wenzelm@11608
    22
  apply (auto elim: monoD intro!: order_antisym)
wenzelm@11608
    23
  done
wenzelm@11608
    24
wenzelm@11608
    25
wenzelm@11743
    26
subsection {* HOL type definitions *}
wenzelm@11608
    27
wenzelm@11608
    28
constdefs
wenzelm@11608
    29
  type_definition :: "('a => 'b) => ('b => 'a) => 'b set => bool"
wenzelm@11608
    30
  "type_definition Rep Abs A ==
wenzelm@11608
    31
    (\<forall>x. Rep x \<in> A) \<and>
wenzelm@11608
    32
    (\<forall>x. Abs (Rep x) = x) \<and>
wenzelm@11608
    33
    (\<forall>y \<in> A. Rep (Abs y) = y)"
wenzelm@11608
    34
  -- {* This will be stated as an axiom for each typedef! *}
wenzelm@11608
    35
wenzelm@11608
    36
lemma type_definitionI [intro]:
wenzelm@11608
    37
  "(!!x. Rep x \<in> A) ==>
wenzelm@11608
    38
    (!!x. Abs (Rep x) = x) ==>
wenzelm@11608
    39
    (!!y. y \<in> A ==> Rep (Abs y) = y) ==>
wenzelm@11608
    40
    type_definition Rep Abs A"
wenzelm@11608
    41
  by (unfold type_definition_def) blast
wenzelm@11608
    42
wenzelm@11608
    43
theorem Rep: "type_definition Rep Abs A ==> Rep x \<in> A"
wenzelm@11608
    44
  by (unfold type_definition_def) blast
wenzelm@11608
    45
wenzelm@11608
    46
theorem Rep_inverse: "type_definition Rep Abs A ==> Abs (Rep x) = x"
wenzelm@11608
    47
  by (unfold type_definition_def) blast
wenzelm@11608
    48
wenzelm@11608
    49
theorem Abs_inverse: "type_definition Rep Abs A ==> y \<in> A ==> Rep (Abs y) = y"
wenzelm@11608
    50
  by (unfold type_definition_def) blast
wenzelm@11608
    51
wenzelm@11608
    52
theorem Rep_inject: "type_definition Rep Abs A ==> (Rep x = Rep y) = (x = y)"
wenzelm@11608
    53
proof -
wenzelm@11608
    54
  assume tydef: "type_definition Rep Abs A"
wenzelm@11608
    55
  show ?thesis
wenzelm@11608
    56
  proof
wenzelm@11608
    57
    assume "Rep x = Rep y"
wenzelm@11608
    58
    hence "Abs (Rep x) = Abs (Rep y)" by (simp only:)
wenzelm@11608
    59
    thus "x = y" by (simp only: Rep_inverse [OF tydef])
wenzelm@11608
    60
  next
wenzelm@11608
    61
    assume "x = y"
wenzelm@11608
    62
    thus "Rep x = Rep y" by simp
wenzelm@11608
    63
  qed
wenzelm@11608
    64
qed
wenzelm@11608
    65
wenzelm@11608
    66
theorem Abs_inject:
wenzelm@11608
    67
  "type_definition Rep Abs A ==> x \<in> A ==> y \<in> A ==> (Abs x = Abs y) = (x = y)"
wenzelm@11608
    68
proof -
wenzelm@11608
    69
  assume tydef: "type_definition Rep Abs A"
wenzelm@11608
    70
  assume x: "x \<in> A" and y: "y \<in> A"
wenzelm@11608
    71
  show ?thesis
wenzelm@11608
    72
  proof
wenzelm@11608
    73
    assume "Abs x = Abs y"
wenzelm@11608
    74
    hence "Rep (Abs x) = Rep (Abs y)" by simp
wenzelm@11608
    75
    moreover from x have "Rep (Abs x) = x" by (rule Abs_inverse [OF tydef])
wenzelm@11608
    76
    moreover from y have "Rep (Abs y) = y" by (rule Abs_inverse [OF tydef])
wenzelm@11608
    77
    ultimately show "x = y" by (simp only:)
wenzelm@11608
    78
  next
wenzelm@11608
    79
    assume "x = y"
wenzelm@11608
    80
    thus "Abs x = Abs y" by simp
wenzelm@11608
    81
  qed
wenzelm@11608
    82
qed
wenzelm@11608
    83
wenzelm@11608
    84
theorem Rep_cases:
wenzelm@11608
    85
  "type_definition Rep Abs A ==> y \<in> A ==> (!!x. y = Rep x ==> P) ==> P"
wenzelm@11608
    86
proof -
wenzelm@11608
    87
  assume tydef: "type_definition Rep Abs A"
wenzelm@11608
    88
  assume y: "y \<in> A" and r: "(!!x. y = Rep x ==> P)"
wenzelm@11608
    89
  show P
wenzelm@11608
    90
  proof (rule r)
wenzelm@11608
    91
    from y have "Rep (Abs y) = y" by (rule Abs_inverse [OF tydef])
wenzelm@11608
    92
    thus "y = Rep (Abs y)" ..
wenzelm@11608
    93
  qed
wenzelm@11608
    94
qed
wenzelm@11608
    95
wenzelm@11608
    96
theorem Abs_cases:
wenzelm@11608
    97
  "type_definition Rep Abs A ==> (!!y. x = Abs y ==> y \<in> A ==> P) ==> P"
wenzelm@11608
    98
proof -
wenzelm@11608
    99
  assume tydef: "type_definition Rep Abs A"
wenzelm@11608
   100
  assume r: "!!y. x = Abs y ==> y \<in> A ==> P"
wenzelm@11608
   101
  show P
wenzelm@11608
   102
  proof (rule r)
wenzelm@11608
   103
    have "Abs (Rep x) = x" by (rule Rep_inverse [OF tydef])
wenzelm@11608
   104
    thus "x = Abs (Rep x)" ..
wenzelm@11608
   105
    show "Rep x \<in> A" by (rule Rep [OF tydef])
wenzelm@11608
   106
  qed
wenzelm@11608
   107
qed
wenzelm@11608
   108
wenzelm@11608
   109
theorem Rep_induct:
wenzelm@11608
   110
  "type_definition Rep Abs A ==> y \<in> A ==> (!!x. P (Rep x)) ==> P y"
wenzelm@11608
   111
proof -
wenzelm@11608
   112
  assume tydef: "type_definition Rep Abs A"
wenzelm@11608
   113
  assume "!!x. P (Rep x)" hence "P (Rep (Abs y))" .
wenzelm@11608
   114
  moreover assume "y \<in> A" hence "Rep (Abs y) = y" by (rule Abs_inverse [OF tydef])
wenzelm@11608
   115
  ultimately show "P y" by (simp only:)
wenzelm@11608
   116
qed
wenzelm@11608
   117
wenzelm@11608
   118
theorem Abs_induct:
wenzelm@11608
   119
  "type_definition Rep Abs A ==> (!!y. y \<in> A ==> P (Abs y)) ==> P x"
wenzelm@11608
   120
proof -
wenzelm@11608
   121
  assume tydef: "type_definition Rep Abs A"
wenzelm@11608
   122
  assume r: "!!y. y \<in> A ==> P (Abs y)"
wenzelm@11608
   123
  have "Rep x \<in> A" by (rule Rep [OF tydef])
wenzelm@11608
   124
  hence "P (Abs (Rep x))" by (rule r)
wenzelm@11608
   125
  moreover have "Abs (Rep x) = x" by (rule Rep_inverse [OF tydef])
wenzelm@11608
   126
  ultimately show "P x" by (simp only:)
wenzelm@11608
   127
qed
wenzelm@11608
   128
wenzelm@11608
   129
use "Tools/typedef_package.ML"
wenzelm@11608
   130
wenzelm@11608
   131
end