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