src/HOL/Typedef.thy
author wenzelm
Thu Sep 27 22:26:00 2001 +0200 (2001-09-27)
changeset 11608 c760ea8154ee
child 11654 53d18ab990f6
permissions -rw-r--r--
renamed theory "subset" to "Typedef";
wenzelm@11608
     1
(*  Title:      HOL/Typedef.thy
wenzelm@11608
     2
    ID:         $Id$
wenzelm@11608
     3
    Author:     Markus Wenzel, TU Munich
wenzelm@11608
     4
wenzelm@11608
     5
Misc set-theory lemmas and HOL type definitions.
wenzelm@11608
     6
*)
wenzelm@11608
     7
wenzelm@11608
     8
theory Typedef = Set
wenzelm@11608
     9
files "subset.ML" "equalities.ML" "mono.ML"
wenzelm@11608
    10
  "Tools/induct_attrib.ML" ("Tools/typedef_package.ML"):
wenzelm@11608
    11
wenzelm@11608
    12
(** belongs to theory Ord **)
wenzelm@11608
    13
  
wenzelm@11608
    14
theorems linorder_cases [case_names less equal greater] =
wenzelm@11608
    15
  linorder_less_split
wenzelm@11608
    16
wenzelm@11608
    17
(* Courtesy of Stephan Merz *)
wenzelm@11608
    18
lemma Least_mono: 
wenzelm@11608
    19
  "mono (f::'a::order => 'b::order) ==> EX x:S. ALL y:S. x <= y
wenzelm@11608
    20
    ==> (LEAST y. y : f ` S) = f (LEAST x. x : S)"
wenzelm@11608
    21
  apply clarify
wenzelm@11608
    22
  apply (erule_tac P = "%x. x : S" in LeastI2)
wenzelm@11608
    23
   apply fast
wenzelm@11608
    24
  apply (rule LeastI2)
wenzelm@11608
    25
  apply (auto elim: monoD intro!: order_antisym)
wenzelm@11608
    26
  done
wenzelm@11608
    27
wenzelm@11608
    28
wenzelm@11608
    29
(*belongs to theory Set*)
wenzelm@11608
    30
setup Rulify.setup
wenzelm@11608
    31
wenzelm@11608
    32
wenzelm@11608
    33
section {* HOL type definitions *}
wenzelm@11608
    34
wenzelm@11608
    35
constdefs
wenzelm@11608
    36
  type_definition :: "('a => 'b) => ('b => 'a) => 'b set => bool"
wenzelm@11608
    37
  "type_definition Rep Abs A ==
wenzelm@11608
    38
    (\<forall>x. Rep x \<in> A) \<and>
wenzelm@11608
    39
    (\<forall>x. Abs (Rep x) = x) \<and>
wenzelm@11608
    40
    (\<forall>y \<in> A. Rep (Abs y) = y)"
wenzelm@11608
    41
  -- {* This will be stated as an axiom for each typedef! *}
wenzelm@11608
    42
wenzelm@11608
    43
lemma type_definitionI [intro]:
wenzelm@11608
    44
  "(!!x. Rep x \<in> A) ==>
wenzelm@11608
    45
    (!!x. Abs (Rep x) = x) ==>
wenzelm@11608
    46
    (!!y. y \<in> A ==> Rep (Abs y) = y) ==>
wenzelm@11608
    47
    type_definition Rep Abs A"
wenzelm@11608
    48
  by (unfold type_definition_def) blast
wenzelm@11608
    49
wenzelm@11608
    50
theorem Rep: "type_definition Rep Abs A ==> Rep x \<in> A"
wenzelm@11608
    51
  by (unfold type_definition_def) blast
wenzelm@11608
    52
wenzelm@11608
    53
theorem Rep_inverse: "type_definition Rep Abs A ==> Abs (Rep x) = x"
wenzelm@11608
    54
  by (unfold type_definition_def) blast
wenzelm@11608
    55
wenzelm@11608
    56
theorem Abs_inverse: "type_definition Rep Abs A ==> y \<in> A ==> Rep (Abs y) = y"
wenzelm@11608
    57
  by (unfold type_definition_def) blast
wenzelm@11608
    58
wenzelm@11608
    59
theorem Rep_inject: "type_definition Rep Abs A ==> (Rep x = Rep y) = (x = y)"
wenzelm@11608
    60
proof -
wenzelm@11608
    61
  assume tydef: "type_definition Rep Abs A"
wenzelm@11608
    62
  show ?thesis
wenzelm@11608
    63
  proof
wenzelm@11608
    64
    assume "Rep x = Rep y"
wenzelm@11608
    65
    hence "Abs (Rep x) = Abs (Rep y)" by (simp only:)
wenzelm@11608
    66
    thus "x = y" by (simp only: Rep_inverse [OF tydef])
wenzelm@11608
    67
  next
wenzelm@11608
    68
    assume "x = y"
wenzelm@11608
    69
    thus "Rep x = Rep y" by simp
wenzelm@11608
    70
  qed
wenzelm@11608
    71
qed
wenzelm@11608
    72
wenzelm@11608
    73
theorem Abs_inject:
wenzelm@11608
    74
  "type_definition Rep Abs A ==> x \<in> A ==> y \<in> A ==> (Abs x = Abs y) = (x = y)"
wenzelm@11608
    75
proof -
wenzelm@11608
    76
  assume tydef: "type_definition Rep Abs A"
wenzelm@11608
    77
  assume x: "x \<in> A" and y: "y \<in> A"
wenzelm@11608
    78
  show ?thesis
wenzelm@11608
    79
  proof
wenzelm@11608
    80
    assume "Abs x = Abs y"
wenzelm@11608
    81
    hence "Rep (Abs x) = Rep (Abs y)" by simp
wenzelm@11608
    82
    moreover from x have "Rep (Abs x) = x" by (rule Abs_inverse [OF tydef])
wenzelm@11608
    83
    moreover from y have "Rep (Abs y) = y" by (rule Abs_inverse [OF tydef])
wenzelm@11608
    84
    ultimately show "x = y" by (simp only:)
wenzelm@11608
    85
  next
wenzelm@11608
    86
    assume "x = y"
wenzelm@11608
    87
    thus "Abs x = Abs y" by simp
wenzelm@11608
    88
  qed
wenzelm@11608
    89
qed
wenzelm@11608
    90
wenzelm@11608
    91
theorem Rep_cases:
wenzelm@11608
    92
  "type_definition Rep Abs A ==> y \<in> A ==> (!!x. y = Rep x ==> P) ==> P"
wenzelm@11608
    93
proof -
wenzelm@11608
    94
  assume tydef: "type_definition Rep Abs A"
wenzelm@11608
    95
  assume y: "y \<in> A" and r: "(!!x. y = Rep x ==> P)"
wenzelm@11608
    96
  show P
wenzelm@11608
    97
  proof (rule r)
wenzelm@11608
    98
    from y have "Rep (Abs y) = y" by (rule Abs_inverse [OF tydef])
wenzelm@11608
    99
    thus "y = Rep (Abs y)" ..
wenzelm@11608
   100
  qed
wenzelm@11608
   101
qed
wenzelm@11608
   102
wenzelm@11608
   103
theorem Abs_cases:
wenzelm@11608
   104
  "type_definition Rep Abs A ==> (!!y. x = Abs y ==> y \<in> A ==> P) ==> P"
wenzelm@11608
   105
proof -
wenzelm@11608
   106
  assume tydef: "type_definition Rep Abs A"
wenzelm@11608
   107
  assume r: "!!y. x = Abs y ==> y \<in> A ==> P"
wenzelm@11608
   108
  show P
wenzelm@11608
   109
  proof (rule r)
wenzelm@11608
   110
    have "Abs (Rep x) = x" by (rule Rep_inverse [OF tydef])
wenzelm@11608
   111
    thus "x = Abs (Rep x)" ..
wenzelm@11608
   112
    show "Rep x \<in> A" by (rule Rep [OF tydef])
wenzelm@11608
   113
  qed
wenzelm@11608
   114
qed
wenzelm@11608
   115
wenzelm@11608
   116
theorem Rep_induct:
wenzelm@11608
   117
  "type_definition Rep Abs A ==> y \<in> A ==> (!!x. P (Rep x)) ==> P y"
wenzelm@11608
   118
proof -
wenzelm@11608
   119
  assume tydef: "type_definition Rep Abs A"
wenzelm@11608
   120
  assume "!!x. P (Rep x)" hence "P (Rep (Abs y))" .
wenzelm@11608
   121
  moreover assume "y \<in> A" hence "Rep (Abs y) = y" by (rule Abs_inverse [OF tydef])
wenzelm@11608
   122
  ultimately show "P y" by (simp only:)
wenzelm@11608
   123
qed
wenzelm@11608
   124
wenzelm@11608
   125
theorem Abs_induct:
wenzelm@11608
   126
  "type_definition Rep Abs A ==> (!!y. y \<in> A ==> P (Abs y)) ==> P x"
wenzelm@11608
   127
proof -
wenzelm@11608
   128
  assume tydef: "type_definition Rep Abs A"
wenzelm@11608
   129
  assume r: "!!y. y \<in> A ==> P (Abs y)"
wenzelm@11608
   130
  have "Rep x \<in> A" by (rule Rep [OF tydef])
wenzelm@11608
   131
  hence "P (Abs (Rep x))" by (rule r)
wenzelm@11608
   132
  moreover have "Abs (Rep x) = x" by (rule Rep_inverse [OF tydef])
wenzelm@11608
   133
  ultimately show "P x" by (simp only:)
wenzelm@11608
   134
qed
wenzelm@11608
   135
wenzelm@11608
   136
setup InductAttrib.setup
wenzelm@11608
   137
use "Tools/typedef_package.ML"
wenzelm@11608
   138
wenzelm@11608
   139
end