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