src/HOL/Library/Quotient.thy
author wenzelm
Thu Oct 19 21:23:15 2000 +0200 (2000-10-19)
changeset 10278 ea1bf4b6255c
parent 10250 ca93fe25a84b
child 10285 6949e17f314a
permissions -rw-r--r--
improved typedef;
tuned proofs;
wenzelm@10250
     1
(*  Title:      HOL/Library/Quotient.thy
wenzelm@10250
     2
    ID:         $Id$
wenzelm@10250
     3
    Author:     Gertrud Bauer and Markus Wenzel, TU Muenchen
wenzelm@10250
     4
*)
wenzelm@10250
     5
wenzelm@10250
     6
header {*
wenzelm@10250
     7
  \title{Quotients}
wenzelm@10250
     8
  \author{Gertrud Bauer and Markus Wenzel}
wenzelm@10250
     9
*}
wenzelm@10250
    10
wenzelm@10250
    11
theory Quotient = Main:
wenzelm@10250
    12
wenzelm@10250
    13
text {*
wenzelm@10250
    14
 Higher-order quotients are defined over partial equivalence relations
wenzelm@10250
    15
 (PERs) instead of total ones.  We provide axiomatic type classes
wenzelm@10250
    16
 @{text "equiv < partial_equiv"} and a type constructor
wenzelm@10250
    17
 @{text "'a quot"} with basic operations.  Note that conventional
wenzelm@10250
    18
 quotient constructions emerge as a special case.  This development is
wenzelm@10250
    19
 loosely based on \cite{Slotosch:1997}.
wenzelm@10250
    20
*}
wenzelm@10250
    21
wenzelm@10250
    22
wenzelm@10250
    23
subsection {* Equivalence relations *}
wenzelm@10250
    24
wenzelm@10250
    25
subsubsection {* Partial equivalence *}
wenzelm@10250
    26
wenzelm@10250
    27
text {*
wenzelm@10250
    28
 Type class @{text partial_equiv} models partial equivalence relations
wenzelm@10250
    29
 (PERs) using the polymorphic @{text "\<sim> :: 'a => 'a => bool"} relation,
wenzelm@10250
    30
 which is required to be symmetric and transitive, but not necessarily
wenzelm@10250
    31
 reflexive.
wenzelm@10250
    32
*}
wenzelm@10250
    33
wenzelm@10250
    34
consts
wenzelm@10250
    35
  eqv :: "'a => 'a => bool"    (infixl "\<sim>" 50)
wenzelm@10250
    36
wenzelm@10250
    37
axclass partial_equiv < "term"
wenzelm@10250
    38
  eqv_sym [elim?]: "x \<sim> y ==> y \<sim> x"
wenzelm@10250
    39
  eqv_trans [trans]: "x \<sim> y ==> y \<sim> z ==> x \<sim> z"
wenzelm@10250
    40
wenzelm@10250
    41
text {*
wenzelm@10250
    42
 \medskip The domain of a partial equivalence relation is the set of
wenzelm@10250
    43
 reflexive elements.  Due to symmetry and transitivity this
wenzelm@10250
    44
 characterizes exactly those elements that are connected with
wenzelm@10250
    45
 \emph{any} other one.
wenzelm@10250
    46
*}
wenzelm@10250
    47
wenzelm@10250
    48
constdefs
wenzelm@10250
    49
  domain :: "'a::partial_equiv set"
wenzelm@10250
    50
  "domain == {x. x \<sim> x}"
wenzelm@10250
    51
wenzelm@10250
    52
lemma domainI [intro]: "x \<sim> x ==> x \<in> domain"
wenzelm@10250
    53
  by (unfold domain_def) blast
wenzelm@10250
    54
wenzelm@10250
    55
lemma domainD [dest]: "x \<in> domain ==> x \<sim> x"
wenzelm@10250
    56
  by (unfold domain_def) blast
wenzelm@10250
    57
wenzelm@10250
    58
theorem domainI' [elim?]: "x \<sim> y ==> x \<in> domain"
wenzelm@10250
    59
proof
wenzelm@10250
    60
  assume xy: "x \<sim> y"
wenzelm@10250
    61
  also from xy have "y \<sim> x" ..
wenzelm@10250
    62
  finally show "x \<sim> x" .
wenzelm@10250
    63
qed
wenzelm@10250
    64
wenzelm@10250
    65
wenzelm@10250
    66
subsubsection {* Equivalence on function spaces *}
wenzelm@10250
    67
wenzelm@10250
    68
text {*
wenzelm@10250
    69
 The @{text \<sim>} relation is lifted to function spaces.  It is
wenzelm@10250
    70
 important to note that this is \emph{not} the direct product, but a
wenzelm@10250
    71
 structural one corresponding to the congruence property.
wenzelm@10250
    72
*}
wenzelm@10250
    73
wenzelm@10250
    74
defs (overloaded)
wenzelm@10250
    75
  eqv_fun_def: "f \<sim> g == \<forall>x \<in> domain. \<forall>y \<in> domain. x \<sim> y --> f x \<sim> g y"
wenzelm@10250
    76
wenzelm@10250
    77
lemma partial_equiv_funI [intro?]:
wenzelm@10250
    78
    "(!!x y. x \<in> domain ==> y \<in> domain ==> x \<sim> y ==> f x \<sim> g y) ==> f \<sim> g"
wenzelm@10250
    79
  by (unfold eqv_fun_def) blast
wenzelm@10250
    80
wenzelm@10250
    81
lemma partial_equiv_funD [dest?]:
wenzelm@10250
    82
    "f \<sim> g ==> x \<in> domain ==> y \<in> domain ==> x \<sim> y ==> f x \<sim> g y"
wenzelm@10250
    83
  by (unfold eqv_fun_def) blast
wenzelm@10250
    84
wenzelm@10250
    85
text {*
wenzelm@10250
    86
 The class of partial equivalence relations is closed under function
wenzelm@10250
    87
 spaces (in \emph{both} argument positions).
wenzelm@10250
    88
*}
wenzelm@10250
    89
wenzelm@10250
    90
instance fun :: (partial_equiv, partial_equiv) partial_equiv
wenzelm@10250
    91
proof intro_classes
wenzelm@10250
    92
  fix f g h :: "'a::partial_equiv => 'b::partial_equiv"
wenzelm@10250
    93
  assume fg: "f \<sim> g"
wenzelm@10250
    94
  show "g \<sim> f"
wenzelm@10250
    95
  proof
wenzelm@10250
    96
    fix x y :: 'a
wenzelm@10250
    97
    assume x: "x \<in> domain" and y: "y \<in> domain"
wenzelm@10250
    98
    assume "x \<sim> y" hence "y \<sim> x" ..
wenzelm@10250
    99
    with fg y x have "f y \<sim> g x" ..
wenzelm@10250
   100
    thus "g x \<sim> f y" ..
wenzelm@10250
   101
  qed
wenzelm@10250
   102
  assume gh: "g \<sim> h"
wenzelm@10250
   103
  show "f \<sim> h"
wenzelm@10250
   104
  proof
wenzelm@10250
   105
    fix x y :: 'a
wenzelm@10250
   106
    assume x: "x \<in> domain" and y: "y \<in> domain" and "x \<sim> y"
wenzelm@10250
   107
    with fg have "f x \<sim> g y" ..
wenzelm@10250
   108
    also from y have "y \<sim> y" ..
wenzelm@10250
   109
    with gh y y have "g y \<sim> h y" ..
wenzelm@10250
   110
    finally show "f x \<sim> h y" .
wenzelm@10250
   111
  qed
wenzelm@10250
   112
qed
wenzelm@10250
   113
wenzelm@10250
   114
wenzelm@10250
   115
subsubsection {* Total equivalence *}
wenzelm@10250
   116
wenzelm@10250
   117
text {*
wenzelm@10250
   118
 The class of total equivalence relations on top of PERs.  It
wenzelm@10250
   119
 coincides with the standard notion of equivalence, i.e.\
wenzelm@10250
   120
 @{text "\<sim> :: 'a => 'a => bool"} is required to be reflexive, transitive
wenzelm@10250
   121
 and symmetric.
wenzelm@10250
   122
*}
wenzelm@10250
   123
wenzelm@10250
   124
axclass equiv < partial_equiv
wenzelm@10250
   125
  eqv_refl [intro]: "x \<sim> x"
wenzelm@10250
   126
wenzelm@10250
   127
text {*
wenzelm@10250
   128
 On total equivalences all elements are reflexive, and congruence
wenzelm@10250
   129
 holds unconditionally.
wenzelm@10250
   130
*}
wenzelm@10250
   131
wenzelm@10250
   132
theorem equiv_domain [intro]: "(x::'a::equiv) \<in> domain"
wenzelm@10250
   133
proof
wenzelm@10250
   134
  show "x \<sim> x" ..
wenzelm@10250
   135
qed
wenzelm@10250
   136
wenzelm@10250
   137
theorem equiv_cong [dest?]: "f \<sim> g ==> x \<sim> y ==> f x \<sim> g (y::'a::equiv)"
wenzelm@10250
   138
proof -
wenzelm@10250
   139
  assume "f \<sim> g"
wenzelm@10250
   140
  moreover have "x \<in> domain" ..
wenzelm@10250
   141
  moreover have "y \<in> domain" ..
wenzelm@10250
   142
  moreover assume "x \<sim> y"
wenzelm@10250
   143
  ultimately show ?thesis ..
wenzelm@10250
   144
qed
wenzelm@10250
   145
wenzelm@10250
   146
wenzelm@10250
   147
subsection {* Quotient types *}
wenzelm@10250
   148
wenzelm@10250
   149
subsubsection {* General quotients and equivalence classes *}
wenzelm@10250
   150
wenzelm@10250
   151
text {*
wenzelm@10250
   152
 The quotient type @{text "'a quot"} consists of all \emph{equivalence
wenzelm@10250
   153
 classes} over elements of the base type @{typ 'a}.
wenzelm@10250
   154
*}
wenzelm@10250
   155
wenzelm@10250
   156
typedef 'a quot = "{{x. a \<sim> x}| a::'a. True}"
wenzelm@10250
   157
  by blast
wenzelm@10250
   158
wenzelm@10250
   159
lemma quotI [intro]: "{x. a \<sim> x} \<in> quot"
wenzelm@10250
   160
  by (unfold quot_def) blast
wenzelm@10250
   161
wenzelm@10250
   162
lemma quotE [elim]: "R \<in> quot ==> (!!a. R = {x. a \<sim> x} ==> C) ==> C"
wenzelm@10250
   163
  by (unfold quot_def) blast
wenzelm@10250
   164
wenzelm@10250
   165
text {*
wenzelm@10250
   166
 \medskip Abstracted equivalence classes are the canonical
wenzelm@10250
   167
 representation of elements of a quotient type.
wenzelm@10250
   168
*}
wenzelm@10250
   169
wenzelm@10250
   170
constdefs
wenzelm@10250
   171
  eqv_class :: "('a::partial_equiv) => 'a quot"    ("\<lfloor>_\<rfloor>")
wenzelm@10250
   172
  "\<lfloor>a\<rfloor> == Abs_quot {x. a \<sim> x}"
wenzelm@10250
   173
wenzelm@10250
   174
theorem quot_rep: "\<exists>a. A = \<lfloor>a\<rfloor>"
wenzelm@10278
   175
proof (cases A)
wenzelm@10278
   176
  fix R assume R: "A = Abs_quot R"
wenzelm@10278
   177
  assume "R \<in> quot" hence "\<exists>a. R = {x. a \<sim> x}" by blast
wenzelm@10278
   178
  with R have "\<exists>a. A = Abs_quot {x. a \<sim> x}" by blast
wenzelm@10278
   179
  thus ?thesis by (unfold eqv_class_def)
wenzelm@10250
   180
qed
wenzelm@10250
   181
wenzelm@10250
   182
lemma quot_cases [case_names rep, cases type: quot]:
wenzelm@10250
   183
    "(!!a. A = \<lfloor>a\<rfloor> ==> C) ==> C"
wenzelm@10250
   184
  by (insert quot_rep) blast
wenzelm@10250
   185
wenzelm@10250
   186
wenzelm@10250
   187
subsubsection {* Equality on quotients *}
wenzelm@10250
   188
wenzelm@10250
   189
text {*
wenzelm@10250
   190
 Equality of canonical quotient elements corresponds to the original
wenzelm@10250
   191
 relation as follows.
wenzelm@10250
   192
*}
wenzelm@10250
   193
wenzelm@10250
   194
theorem eqv_class_eqI [intro]: "a \<sim> b ==> \<lfloor>a\<rfloor> = \<lfloor>b\<rfloor>"
wenzelm@10250
   195
proof -
wenzelm@10250
   196
  assume ab: "a \<sim> b"
wenzelm@10250
   197
  have "{x. a \<sim> x} = {x. b \<sim> x}"
wenzelm@10250
   198
  proof (rule Collect_cong)
wenzelm@10250
   199
    fix x show "(a \<sim> x) = (b \<sim> x)"
wenzelm@10250
   200
    proof
wenzelm@10250
   201
      from ab have "b \<sim> a" ..
wenzelm@10250
   202
      also assume "a \<sim> x"
wenzelm@10250
   203
      finally show "b \<sim> x" .
wenzelm@10250
   204
    next
wenzelm@10250
   205
      note ab
wenzelm@10250
   206
      also assume "b \<sim> x"
wenzelm@10250
   207
      finally show "a \<sim> x" .
wenzelm@10250
   208
    qed
wenzelm@10250
   209
  qed
wenzelm@10250
   210
  thus ?thesis by (simp only: eqv_class_def)
wenzelm@10250
   211
qed
wenzelm@10250
   212
wenzelm@10250
   213
theorem eqv_class_eqD' [dest?]: "\<lfloor>a\<rfloor> = \<lfloor>b\<rfloor> ==> a \<in> domain ==> a \<sim> b"  (* FIXME [dest] would cause trouble with blast due to overloading *)
wenzelm@10250
   214
proof (unfold eqv_class_def)
wenzelm@10250
   215
  assume "Abs_quot {x. a \<sim> x} = Abs_quot {x. b \<sim> x}"
wenzelm@10250
   216
  hence "{x. a \<sim> x} = {x. b \<sim> x}" by (simp only: Abs_quot_inject quotI)
wenzelm@10250
   217
  moreover assume "a \<in> domain" hence "a \<sim> a" ..
wenzelm@10250
   218
  ultimately have "a \<in> {x. b \<sim> x}" by blast
wenzelm@10250
   219
  hence "b \<sim> a" by blast
wenzelm@10250
   220
  thus "a \<sim> b" ..
wenzelm@10250
   221
qed
wenzelm@10250
   222
wenzelm@10250
   223
theorem eqv_class_eqD [dest?]: "\<lfloor>a\<rfloor> = \<lfloor>b\<rfloor> ==> a \<sim> (b::'a::equiv)"  (* FIXME [dest] would cause trouble with blast due to overloading *)
wenzelm@10250
   224
proof (rule eqv_class_eqD')
wenzelm@10250
   225
  show "a \<in> domain" ..
wenzelm@10250
   226
qed
wenzelm@10250
   227
wenzelm@10250
   228
lemma eqv_class_eq' [simp]: "a \<in> domain ==> (\<lfloor>a\<rfloor> = \<lfloor>b\<rfloor>) = (a \<sim> b)"
wenzelm@10250
   229
  by (insert eqv_class_eqI eqv_class_eqD') blast
wenzelm@10250
   230
wenzelm@10250
   231
lemma eqv_class_eq [simp]: "(\<lfloor>a\<rfloor> = \<lfloor>b\<rfloor>) = (a \<sim> (b::'a::equiv))"
wenzelm@10250
   232
  by (insert eqv_class_eqI eqv_class_eqD) blast
wenzelm@10250
   233
wenzelm@10250
   234
wenzelm@10250
   235
subsubsection {* Picking representing elements *}
wenzelm@10250
   236
wenzelm@10250
   237
constdefs
wenzelm@10250
   238
  pick :: "'a::partial_equiv quot => 'a"
wenzelm@10250
   239
  "pick A == SOME a. A = \<lfloor>a\<rfloor>"
wenzelm@10250
   240
wenzelm@10250
   241
theorem pick_eqv' [intro?, simp]: "a \<in> domain ==> pick \<lfloor>a\<rfloor> \<sim> a" (* FIXME [intro] !? *)
wenzelm@10250
   242
proof (unfold pick_def)
wenzelm@10250
   243
  assume a: "a \<in> domain"
wenzelm@10250
   244
  show "(SOME x. \<lfloor>a\<rfloor> = \<lfloor>x\<rfloor>) \<sim> a"
wenzelm@10250
   245
  proof (rule someI2)
wenzelm@10250
   246
    show "\<lfloor>a\<rfloor> = \<lfloor>a\<rfloor>" ..
wenzelm@10250
   247
    fix x assume "\<lfloor>a\<rfloor> = \<lfloor>x\<rfloor>"
wenzelm@10250
   248
    hence "a \<sim> x" ..
wenzelm@10250
   249
    thus "x \<sim> a" ..
wenzelm@10250
   250
  qed
wenzelm@10250
   251
qed
wenzelm@10250
   252
wenzelm@10250
   253
theorem pick_eqv [intro, simp]: "pick \<lfloor>a\<rfloor> \<sim> (a::'a::equiv)"
wenzelm@10250
   254
proof (rule pick_eqv')
wenzelm@10250
   255
  show "a \<in> domain" ..
wenzelm@10250
   256
qed
wenzelm@10250
   257
wenzelm@10278
   258
theorem pick_inverse: "\<lfloor>pick A\<rfloor> = (A::'a::equiv quot)"
wenzelm@10250
   259
proof (cases A)
wenzelm@10250
   260
  fix a assume a: "A = \<lfloor>a\<rfloor>"
wenzelm@10278
   261
  hence "pick A \<sim> a" by simp
wenzelm@10250
   262
  hence "\<lfloor>pick A\<rfloor> = \<lfloor>a\<rfloor>" by simp
wenzelm@10250
   263
  with a show ?thesis by simp
wenzelm@10250
   264
qed
wenzelm@10250
   265
wenzelm@10250
   266
end