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