src/HOL/Library/Quotient.thy
author wenzelm
Thu, 16 Nov 2000 19:03:26 +0100
changeset 10477 c21bee84cefe
parent 10473 4f15b844fea6
child 10483 eb93ace45a6e
permissions -rw-r--r--
added not_equiv_sym, not_equiv_trans1/2; tuned;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10250
ca93fe25a84b Quotient types;
wenzelm
parents:
diff changeset
     1
(*  Title:      HOL/Library/Quotient.thy
ca93fe25a84b Quotient types;
wenzelm
parents:
diff changeset
     2
    ID:         $Id$
ca93fe25a84b Quotient types;
wenzelm
parents:
diff changeset
     3
    Author:     Gertrud Bauer and Markus Wenzel, TU Muenchen
ca93fe25a84b Quotient types;
wenzelm
parents:
diff changeset
     4
*)
ca93fe25a84b Quotient types;
wenzelm
parents:
diff changeset
     5
ca93fe25a84b Quotient types;
wenzelm
parents:
diff changeset
     6
header {*
10473
4f15b844fea6 separate rules for function/operation definitions;
wenzelm
parents: 10459
diff changeset
     7
  \title{Quotient types}
10250
ca93fe25a84b Quotient types;
wenzelm
parents:
diff changeset
     8
  \author{Gertrud Bauer and Markus Wenzel}
ca93fe25a84b Quotient types;
wenzelm
parents:
diff changeset
     9
*}
ca93fe25a84b Quotient types;
wenzelm
parents:
diff changeset
    10
ca93fe25a84b Quotient types;
wenzelm
parents:
diff changeset
    11
theory Quotient = Main:
ca93fe25a84b Quotient types;
wenzelm
parents:
diff changeset
    12
ca93fe25a84b Quotient types;
wenzelm
parents:
diff changeset
    13
text {*
10285
6949e17f314a simplified quotients (only plain total equivs);
wenzelm
parents: 10278
diff changeset
    14
 We introduce the notion of quotient types over equivalence relations
6949e17f314a simplified quotients (only plain total equivs);
wenzelm
parents: 10278
diff changeset
    15
 via axiomatic type classes.
10250
ca93fe25a84b Quotient types;
wenzelm
parents:
diff changeset
    16
*}
ca93fe25a84b Quotient types;
wenzelm
parents:
diff changeset
    17
10285
6949e17f314a simplified quotients (only plain total equivs);
wenzelm
parents: 10278
diff changeset
    18
subsection {* Equivalence relations and quotient types *}
10250
ca93fe25a84b Quotient types;
wenzelm
parents:
diff changeset
    19
ca93fe25a84b Quotient types;
wenzelm
parents:
diff changeset
    20
text {*
10390
wenzelm
parents: 10333
diff changeset
    21
 \medskip Type class @{text equiv} models equivalence relations @{text
wenzelm
parents: 10333
diff changeset
    22
 "\<sim> :: 'a => 'a => bool"}.
10250
ca93fe25a84b Quotient types;
wenzelm
parents:
diff changeset
    23
*}
ca93fe25a84b Quotient types;
wenzelm
parents:
diff changeset
    24
10285
6949e17f314a simplified quotients (only plain total equivs);
wenzelm
parents: 10278
diff changeset
    25
axclass eqv < "term"
6949e17f314a simplified quotients (only plain total equivs);
wenzelm
parents: 10278
diff changeset
    26
consts
6949e17f314a simplified quotients (only plain total equivs);
wenzelm
parents: 10278
diff changeset
    27
  eqv :: "('a::eqv) => 'a => bool"    (infixl "\<sim>" 50)
10250
ca93fe25a84b Quotient types;
wenzelm
parents:
diff changeset
    28
10285
6949e17f314a simplified quotients (only plain total equivs);
wenzelm
parents: 10278
diff changeset
    29
axclass equiv < eqv
10333
f12ff6a4bc7b tuned names;
wenzelm
parents: 10311
diff changeset
    30
  equiv_refl [intro]: "x \<sim> x"
f12ff6a4bc7b tuned names;
wenzelm
parents: 10311
diff changeset
    31
  equiv_trans [trans]: "x \<sim> y ==> y \<sim> z ==> x \<sim> z"
f12ff6a4bc7b tuned names;
wenzelm
parents: 10311
diff changeset
    32
  equiv_sym [elim?]: "x \<sim> y ==> y \<sim> x"
10250
ca93fe25a84b Quotient types;
wenzelm
parents:
diff changeset
    33
10477
c21bee84cefe added not_equiv_sym, not_equiv_trans1/2;
wenzelm
parents: 10473
diff changeset
    34
lemma not_equiv_sym [elim?]: "\<not> (x \<sim> y) ==> \<not> (y \<sim> (x::'a::equiv))"
c21bee84cefe added not_equiv_sym, not_equiv_trans1/2;
wenzelm
parents: 10473
diff changeset
    35
proof -
c21bee84cefe added not_equiv_sym, not_equiv_trans1/2;
wenzelm
parents: 10473
diff changeset
    36
  assume "\<not> (x \<sim> y)" thus "\<not> (y \<sim> x)"
c21bee84cefe added not_equiv_sym, not_equiv_trans1/2;
wenzelm
parents: 10473
diff changeset
    37
    by (rule contrapos_nn) (rule equiv_sym)
c21bee84cefe added not_equiv_sym, not_equiv_trans1/2;
wenzelm
parents: 10473
diff changeset
    38
qed
c21bee84cefe added not_equiv_sym, not_equiv_trans1/2;
wenzelm
parents: 10473
diff changeset
    39
c21bee84cefe added not_equiv_sym, not_equiv_trans1/2;
wenzelm
parents: 10473
diff changeset
    40
lemma not_equiv_trans1 [trans]: "\<not> (x \<sim> y) ==> y \<sim> z ==> \<not> (x \<sim> (z::'a::equiv))"
c21bee84cefe added not_equiv_sym, not_equiv_trans1/2;
wenzelm
parents: 10473
diff changeset
    41
proof -
c21bee84cefe added not_equiv_sym, not_equiv_trans1/2;
wenzelm
parents: 10473
diff changeset
    42
  assume "\<not> (x \<sim> y)" and yz: "y \<sim> z"
c21bee84cefe added not_equiv_sym, not_equiv_trans1/2;
wenzelm
parents: 10473
diff changeset
    43
  show "\<not> (x \<sim> z)"
c21bee84cefe added not_equiv_sym, not_equiv_trans1/2;
wenzelm
parents: 10473
diff changeset
    44
  proof
c21bee84cefe added not_equiv_sym, not_equiv_trans1/2;
wenzelm
parents: 10473
diff changeset
    45
    assume "x \<sim> z"
c21bee84cefe added not_equiv_sym, not_equiv_trans1/2;
wenzelm
parents: 10473
diff changeset
    46
    also from yz have "z \<sim> y" ..
c21bee84cefe added not_equiv_sym, not_equiv_trans1/2;
wenzelm
parents: 10473
diff changeset
    47
    finally have "x \<sim> y" .
c21bee84cefe added not_equiv_sym, not_equiv_trans1/2;
wenzelm
parents: 10473
diff changeset
    48
    thus False by contradiction
c21bee84cefe added not_equiv_sym, not_equiv_trans1/2;
wenzelm
parents: 10473
diff changeset
    49
  qed
c21bee84cefe added not_equiv_sym, not_equiv_trans1/2;
wenzelm
parents: 10473
diff changeset
    50
qed
c21bee84cefe added not_equiv_sym, not_equiv_trans1/2;
wenzelm
parents: 10473
diff changeset
    51
c21bee84cefe added not_equiv_sym, not_equiv_trans1/2;
wenzelm
parents: 10473
diff changeset
    52
lemma not_equiv_trans2 [trans]: "x \<sim> y ==> \<not> (y \<sim> z) ==> \<not> (x \<sim> (z::'a::equiv))"
c21bee84cefe added not_equiv_sym, not_equiv_trans1/2;
wenzelm
parents: 10473
diff changeset
    53
proof -
c21bee84cefe added not_equiv_sym, not_equiv_trans1/2;
wenzelm
parents: 10473
diff changeset
    54
  assume "\<not> (y \<sim> z)" hence "\<not> (z \<sim> y)" ..
c21bee84cefe added not_equiv_sym, not_equiv_trans1/2;
wenzelm
parents: 10473
diff changeset
    55
  also assume "x \<sim> y" hence "y \<sim> x" ..
c21bee84cefe added not_equiv_sym, not_equiv_trans1/2;
wenzelm
parents: 10473
diff changeset
    56
  finally have "\<not> (z \<sim> x)" . thus "(\<not> x \<sim> z)" ..
c21bee84cefe added not_equiv_sym, not_equiv_trans1/2;
wenzelm
parents: 10473
diff changeset
    57
qed
c21bee84cefe added not_equiv_sym, not_equiv_trans1/2;
wenzelm
parents: 10473
diff changeset
    58
10250
ca93fe25a84b Quotient types;
wenzelm
parents:
diff changeset
    59
text {*
10285
6949e17f314a simplified quotients (only plain total equivs);
wenzelm
parents: 10278
diff changeset
    60
 \medskip The quotient type @{text "'a quot"} consists of all
6949e17f314a simplified quotients (only plain total equivs);
wenzelm
parents: 10278
diff changeset
    61
 \emph{equivalence classes} over elements of the base type @{typ 'a}.
10250
ca93fe25a84b Quotient types;
wenzelm
parents:
diff changeset
    62
*}
ca93fe25a84b Quotient types;
wenzelm
parents:
diff changeset
    63
10392
wenzelm
parents: 10390
diff changeset
    64
typedef 'a quot = "{{x. a \<sim> x} | a::'a::eqv. True}"
10250
ca93fe25a84b Quotient types;
wenzelm
parents:
diff changeset
    65
  by blast
ca93fe25a84b Quotient types;
wenzelm
parents:
diff changeset
    66
ca93fe25a84b Quotient types;
wenzelm
parents:
diff changeset
    67
lemma quotI [intro]: "{x. a \<sim> x} \<in> quot"
ca93fe25a84b Quotient types;
wenzelm
parents:
diff changeset
    68
  by (unfold quot_def) blast
ca93fe25a84b Quotient types;
wenzelm
parents:
diff changeset
    69
ca93fe25a84b Quotient types;
wenzelm
parents:
diff changeset
    70
lemma quotE [elim]: "R \<in> quot ==> (!!a. R = {x. a \<sim> x} ==> C) ==> C"
ca93fe25a84b Quotient types;
wenzelm
parents:
diff changeset
    71
  by (unfold quot_def) blast
ca93fe25a84b Quotient types;
wenzelm
parents:
diff changeset
    72
ca93fe25a84b Quotient types;
wenzelm
parents:
diff changeset
    73
text {*
ca93fe25a84b Quotient types;
wenzelm
parents:
diff changeset
    74
 \medskip Abstracted equivalence classes are the canonical
ca93fe25a84b Quotient types;
wenzelm
parents:
diff changeset
    75
 representation of elements of a quotient type.
ca93fe25a84b Quotient types;
wenzelm
parents:
diff changeset
    76
*}
ca93fe25a84b Quotient types;
wenzelm
parents:
diff changeset
    77
ca93fe25a84b Quotient types;
wenzelm
parents:
diff changeset
    78
constdefs
10285
6949e17f314a simplified quotients (only plain total equivs);
wenzelm
parents: 10278
diff changeset
    79
  equivalence_class :: "'a::equiv => 'a quot"    ("\<lfloor>_\<rfloor>")
10250
ca93fe25a84b Quotient types;
wenzelm
parents:
diff changeset
    80
  "\<lfloor>a\<rfloor> == Abs_quot {x. a \<sim> x}"
ca93fe25a84b Quotient types;
wenzelm
parents:
diff changeset
    81
10311
wenzelm
parents: 10286
diff changeset
    82
theorem quot_exhaust: "\<exists>a. A = \<lfloor>a\<rfloor>"
10278
ea1bf4b6255c improved typedef;
wenzelm
parents: 10250
diff changeset
    83
proof (cases A)
ea1bf4b6255c improved typedef;
wenzelm
parents: 10250
diff changeset
    84
  fix R assume R: "A = Abs_quot R"
ea1bf4b6255c improved typedef;
wenzelm
parents: 10250
diff changeset
    85
  assume "R \<in> quot" hence "\<exists>a. R = {x. a \<sim> x}" by blast
ea1bf4b6255c improved typedef;
wenzelm
parents: 10250
diff changeset
    86
  with R have "\<exists>a. A = Abs_quot {x. a \<sim> x}" by blast
10285
6949e17f314a simplified quotients (only plain total equivs);
wenzelm
parents: 10278
diff changeset
    87
  thus ?thesis by (unfold equivalence_class_def)
10250
ca93fe25a84b Quotient types;
wenzelm
parents:
diff changeset
    88
qed
ca93fe25a84b Quotient types;
wenzelm
parents:
diff changeset
    89
10311
wenzelm
parents: 10286
diff changeset
    90
lemma quot_cases [cases type: quot]: "(!!a. A = \<lfloor>a\<rfloor> ==> C) ==> C"
wenzelm
parents: 10286
diff changeset
    91
  by (insert quot_exhaust) blast
10250
ca93fe25a84b Quotient types;
wenzelm
parents:
diff changeset
    92
ca93fe25a84b Quotient types;
wenzelm
parents:
diff changeset
    93
10285
6949e17f314a simplified quotients (only plain total equivs);
wenzelm
parents: 10278
diff changeset
    94
subsection {* Equality on quotients *}
10250
ca93fe25a84b Quotient types;
wenzelm
parents:
diff changeset
    95
ca93fe25a84b Quotient types;
wenzelm
parents:
diff changeset
    96
text {*
10286
wenzelm
parents: 10285
diff changeset
    97
 Equality of canonical quotient elements coincides with the original
wenzelm
parents: 10285
diff changeset
    98
 relation.
10250
ca93fe25a84b Quotient types;
wenzelm
parents:
diff changeset
    99
*}
ca93fe25a84b Quotient types;
wenzelm
parents:
diff changeset
   100
10477
c21bee84cefe added not_equiv_sym, not_equiv_trans1/2;
wenzelm
parents: 10473
diff changeset
   101
theorem quot_equality: "(\<lfloor>a\<rfloor> = \<lfloor>b\<rfloor>) = (a \<sim> b)"
10285
6949e17f314a simplified quotients (only plain total equivs);
wenzelm
parents: 10278
diff changeset
   102
proof
6949e17f314a simplified quotients (only plain total equivs);
wenzelm
parents: 10278
diff changeset
   103
  assume eq: "\<lfloor>a\<rfloor> = \<lfloor>b\<rfloor>"
6949e17f314a simplified quotients (only plain total equivs);
wenzelm
parents: 10278
diff changeset
   104
  show "a \<sim> b"
6949e17f314a simplified quotients (only plain total equivs);
wenzelm
parents: 10278
diff changeset
   105
  proof -
6949e17f314a simplified quotients (only plain total equivs);
wenzelm
parents: 10278
diff changeset
   106
    from eq have "{x. a \<sim> x} = {x. b \<sim> x}"
6949e17f314a simplified quotients (only plain total equivs);
wenzelm
parents: 10278
diff changeset
   107
      by (simp only: equivalence_class_def Abs_quot_inject quotI)
6949e17f314a simplified quotients (only plain total equivs);
wenzelm
parents: 10278
diff changeset
   108
    moreover have "a \<sim> a" ..
6949e17f314a simplified quotients (only plain total equivs);
wenzelm
parents: 10278
diff changeset
   109
    ultimately have "a \<in> {x. b \<sim> x}" by blast
6949e17f314a simplified quotients (only plain total equivs);
wenzelm
parents: 10278
diff changeset
   110
    hence "b \<sim> a" by blast
6949e17f314a simplified quotients (only plain total equivs);
wenzelm
parents: 10278
diff changeset
   111
    thus ?thesis ..
6949e17f314a simplified quotients (only plain total equivs);
wenzelm
parents: 10278
diff changeset
   112
  qed
6949e17f314a simplified quotients (only plain total equivs);
wenzelm
parents: 10278
diff changeset
   113
next
10250
ca93fe25a84b Quotient types;
wenzelm
parents:
diff changeset
   114
  assume ab: "a \<sim> b"
10285
6949e17f314a simplified quotients (only plain total equivs);
wenzelm
parents: 10278
diff changeset
   115
  show "\<lfloor>a\<rfloor> = \<lfloor>b\<rfloor>"
6949e17f314a simplified quotients (only plain total equivs);
wenzelm
parents: 10278
diff changeset
   116
  proof -
6949e17f314a simplified quotients (only plain total equivs);
wenzelm
parents: 10278
diff changeset
   117
    have "{x. a \<sim> x} = {x. b \<sim> x}"
6949e17f314a simplified quotients (only plain total equivs);
wenzelm
parents: 10278
diff changeset
   118
    proof (rule Collect_cong)
6949e17f314a simplified quotients (only plain total equivs);
wenzelm
parents: 10278
diff changeset
   119
      fix x show "(a \<sim> x) = (b \<sim> x)"
6949e17f314a simplified quotients (only plain total equivs);
wenzelm
parents: 10278
diff changeset
   120
      proof
6949e17f314a simplified quotients (only plain total equivs);
wenzelm
parents: 10278
diff changeset
   121
        from ab have "b \<sim> a" ..
6949e17f314a simplified quotients (only plain total equivs);
wenzelm
parents: 10278
diff changeset
   122
        also assume "a \<sim> x"
6949e17f314a simplified quotients (only plain total equivs);
wenzelm
parents: 10278
diff changeset
   123
        finally show "b \<sim> x" .
6949e17f314a simplified quotients (only plain total equivs);
wenzelm
parents: 10278
diff changeset
   124
      next
6949e17f314a simplified quotients (only plain total equivs);
wenzelm
parents: 10278
diff changeset
   125
        note ab
6949e17f314a simplified quotients (only plain total equivs);
wenzelm
parents: 10278
diff changeset
   126
        also assume "b \<sim> x"
6949e17f314a simplified quotients (only plain total equivs);
wenzelm
parents: 10278
diff changeset
   127
        finally show "a \<sim> x" .
6949e17f314a simplified quotients (only plain total equivs);
wenzelm
parents: 10278
diff changeset
   128
      qed
10250
ca93fe25a84b Quotient types;
wenzelm
parents:
diff changeset
   129
    qed
10285
6949e17f314a simplified quotients (only plain total equivs);
wenzelm
parents: 10278
diff changeset
   130
    thus ?thesis by (simp only: equivalence_class_def)
10250
ca93fe25a84b Quotient types;
wenzelm
parents:
diff changeset
   131
  qed
ca93fe25a84b Quotient types;
wenzelm
parents:
diff changeset
   132
qed
ca93fe25a84b Quotient types;
wenzelm
parents:
diff changeset
   133
10477
c21bee84cefe added not_equiv_sym, not_equiv_trans1/2;
wenzelm
parents: 10473
diff changeset
   134
lemma quot_equalI [intro?]: "a \<sim> b ==> \<lfloor>a\<rfloor> = \<lfloor>b\<rfloor>"
c21bee84cefe added not_equiv_sym, not_equiv_trans1/2;
wenzelm
parents: 10473
diff changeset
   135
  by (simp only: quot_equality)
c21bee84cefe added not_equiv_sym, not_equiv_trans1/2;
wenzelm
parents: 10473
diff changeset
   136
c21bee84cefe added not_equiv_sym, not_equiv_trans1/2;
wenzelm
parents: 10473
diff changeset
   137
lemma quot_equalD [dest?]: "\<lfloor>a\<rfloor> = \<lfloor>b\<rfloor> ==> a \<sim> b"
c21bee84cefe added not_equiv_sym, not_equiv_trans1/2;
wenzelm
parents: 10473
diff changeset
   138
  by (simp only: quot_equality)
c21bee84cefe added not_equiv_sym, not_equiv_trans1/2;
wenzelm
parents: 10473
diff changeset
   139
c21bee84cefe added not_equiv_sym, not_equiv_trans1/2;
wenzelm
parents: 10473
diff changeset
   140
lemma quot_not_equalI [intro?]: "\<not> (a \<sim> b) ==> \<lfloor>a\<rfloor> \<noteq> \<lfloor>b\<rfloor>"
c21bee84cefe added not_equiv_sym, not_equiv_trans1/2;
wenzelm
parents: 10473
diff changeset
   141
  by (simp add: quot_equality)
c21bee84cefe added not_equiv_sym, not_equiv_trans1/2;
wenzelm
parents: 10473
diff changeset
   142
c21bee84cefe added not_equiv_sym, not_equiv_trans1/2;
wenzelm
parents: 10473
diff changeset
   143
lemma quot_not_equalD [dest?]: "\<lfloor>a\<rfloor> \<noteq> \<lfloor>b\<rfloor> ==> \<not> (a \<sim> b)"
c21bee84cefe added not_equiv_sym, not_equiv_trans1/2;
wenzelm
parents: 10473
diff changeset
   144
  by (simp add: quot_equality)
c21bee84cefe added not_equiv_sym, not_equiv_trans1/2;
wenzelm
parents: 10473
diff changeset
   145
10250
ca93fe25a84b Quotient types;
wenzelm
parents:
diff changeset
   146
10285
6949e17f314a simplified quotients (only plain total equivs);
wenzelm
parents: 10278
diff changeset
   147
subsection {* Picking representing elements *}
10250
ca93fe25a84b Quotient types;
wenzelm
parents:
diff changeset
   148
ca93fe25a84b Quotient types;
wenzelm
parents:
diff changeset
   149
constdefs
10285
6949e17f314a simplified quotients (only plain total equivs);
wenzelm
parents: 10278
diff changeset
   150
  pick :: "'a::equiv quot => 'a"
10250
ca93fe25a84b Quotient types;
wenzelm
parents:
diff changeset
   151
  "pick A == SOME a. A = \<lfloor>a\<rfloor>"
ca93fe25a84b Quotient types;
wenzelm
parents:
diff changeset
   152
10285
6949e17f314a simplified quotients (only plain total equivs);
wenzelm
parents: 10278
diff changeset
   153
theorem pick_equiv [intro]: "pick \<lfloor>a\<rfloor> \<sim> a"
10250
ca93fe25a84b Quotient types;
wenzelm
parents:
diff changeset
   154
proof (unfold pick_def)
ca93fe25a84b Quotient types;
wenzelm
parents:
diff changeset
   155
  show "(SOME x. \<lfloor>a\<rfloor> = \<lfloor>x\<rfloor>) \<sim> a"
ca93fe25a84b Quotient types;
wenzelm
parents:
diff changeset
   156
  proof (rule someI2)
ca93fe25a84b Quotient types;
wenzelm
parents:
diff changeset
   157
    show "\<lfloor>a\<rfloor> = \<lfloor>a\<rfloor>" ..
ca93fe25a84b Quotient types;
wenzelm
parents:
diff changeset
   158
    fix x assume "\<lfloor>a\<rfloor> = \<lfloor>x\<rfloor>"
10285
6949e17f314a simplified quotients (only plain total equivs);
wenzelm
parents: 10278
diff changeset
   159
    hence "a \<sim> x" .. thus "x \<sim> a" ..
10250
ca93fe25a84b Quotient types;
wenzelm
parents:
diff changeset
   160
  qed
ca93fe25a84b Quotient types;
wenzelm
parents:
diff changeset
   161
qed
ca93fe25a84b Quotient types;
wenzelm
parents:
diff changeset
   162
10285
6949e17f314a simplified quotients (only plain total equivs);
wenzelm
parents: 10278
diff changeset
   163
theorem pick_inverse: "\<lfloor>pick A\<rfloor> = A"
10250
ca93fe25a84b Quotient types;
wenzelm
parents:
diff changeset
   164
proof (cases A)
ca93fe25a84b Quotient types;
wenzelm
parents:
diff changeset
   165
  fix a assume a: "A = \<lfloor>a\<rfloor>"
10285
6949e17f314a simplified quotients (only plain total equivs);
wenzelm
parents: 10278
diff changeset
   166
  hence "pick A \<sim> a" by (simp only: pick_equiv)
6949e17f314a simplified quotients (only plain total equivs);
wenzelm
parents: 10278
diff changeset
   167
  hence "\<lfloor>pick A\<rfloor> = \<lfloor>a\<rfloor>" ..
10250
ca93fe25a84b Quotient types;
wenzelm
parents:
diff changeset
   168
  with a show ?thesis by simp
ca93fe25a84b Quotient types;
wenzelm
parents:
diff changeset
   169
qed
ca93fe25a84b Quotient types;
wenzelm
parents:
diff changeset
   170
10285
6949e17f314a simplified quotients (only plain total equivs);
wenzelm
parents: 10278
diff changeset
   171
text {*
6949e17f314a simplified quotients (only plain total equivs);
wenzelm
parents: 10278
diff changeset
   172
 \medskip The following rules support canonical function definitions
6949e17f314a simplified quotients (only plain total equivs);
wenzelm
parents: 10278
diff changeset
   173
 on quotient types.
6949e17f314a simplified quotients (only plain total equivs);
wenzelm
parents: 10278
diff changeset
   174
*}
6949e17f314a simplified quotients (only plain total equivs);
wenzelm
parents: 10278
diff changeset
   175
10473
4f15b844fea6 separate rules for function/operation definitions;
wenzelm
parents: 10459
diff changeset
   176
theorem quot_cond_function1:
4f15b844fea6 separate rules for function/operation definitions;
wenzelm
parents: 10459
diff changeset
   177
  "(!!X. f X == g (pick X)) ==>
4f15b844fea6 separate rules for function/operation definitions;
wenzelm
parents: 10459
diff changeset
   178
    (!!x x'. x \<sim> x' ==> P x ==> P x' ==> g x = g x') ==>
4f15b844fea6 separate rules for function/operation definitions;
wenzelm
parents: 10459
diff changeset
   179
    (!!x x'. x \<sim> x' ==> P x = P x') ==>
4f15b844fea6 separate rules for function/operation definitions;
wenzelm
parents: 10459
diff changeset
   180
  P a ==> f \<lfloor>a\<rfloor> = g a"
4f15b844fea6 separate rules for function/operation definitions;
wenzelm
parents: 10459
diff changeset
   181
proof -
4f15b844fea6 separate rules for function/operation definitions;
wenzelm
parents: 10459
diff changeset
   182
  assume cong_g: "!!x x'. x \<sim> x' ==> P x ==> P x' ==> g x = g x'"
4f15b844fea6 separate rules for function/operation definitions;
wenzelm
parents: 10459
diff changeset
   183
  assume cong_P: "!!x x'. x \<sim> x' ==> P x = P x'"
4f15b844fea6 separate rules for function/operation definitions;
wenzelm
parents: 10459
diff changeset
   184
  assume P: "P a"
4f15b844fea6 separate rules for function/operation definitions;
wenzelm
parents: 10459
diff changeset
   185
  assume "!!X. f X == g (pick X)"
4f15b844fea6 separate rules for function/operation definitions;
wenzelm
parents: 10459
diff changeset
   186
  hence "f \<lfloor>a\<rfloor> = g (pick \<lfloor>a\<rfloor>)" by (simp only:)
4f15b844fea6 separate rules for function/operation definitions;
wenzelm
parents: 10459
diff changeset
   187
  also have "\<dots> = g a"
4f15b844fea6 separate rules for function/operation definitions;
wenzelm
parents: 10459
diff changeset
   188
  proof (rule cong_g)
4f15b844fea6 separate rules for function/operation definitions;
wenzelm
parents: 10459
diff changeset
   189
    show "pick \<lfloor>a\<rfloor> \<sim> a" ..
4f15b844fea6 separate rules for function/operation definitions;
wenzelm
parents: 10459
diff changeset
   190
    hence "P (pick \<lfloor>a\<rfloor>) = P a" by (rule cong_P)
4f15b844fea6 separate rules for function/operation definitions;
wenzelm
parents: 10459
diff changeset
   191
    also note P
4f15b844fea6 separate rules for function/operation definitions;
wenzelm
parents: 10459
diff changeset
   192
    finally show "P (pick \<lfloor>a\<rfloor>)" .
4f15b844fea6 separate rules for function/operation definitions;
wenzelm
parents: 10459
diff changeset
   193
  qed
4f15b844fea6 separate rules for function/operation definitions;
wenzelm
parents: 10459
diff changeset
   194
  finally show ?thesis .
4f15b844fea6 separate rules for function/operation definitions;
wenzelm
parents: 10459
diff changeset
   195
qed
4f15b844fea6 separate rules for function/operation definitions;
wenzelm
parents: 10459
diff changeset
   196
4f15b844fea6 separate rules for function/operation definitions;
wenzelm
parents: 10459
diff changeset
   197
theorem quot_function1:
4f15b844fea6 separate rules for function/operation definitions;
wenzelm
parents: 10459
diff changeset
   198
  "(!!X. f X == g (pick X)) ==>
4f15b844fea6 separate rules for function/operation definitions;
wenzelm
parents: 10459
diff changeset
   199
    (!!x x'. x \<sim> x' ==> g x = g x') ==>
4f15b844fea6 separate rules for function/operation definitions;
wenzelm
parents: 10459
diff changeset
   200
    f \<lfloor>a\<rfloor> = g a"
4f15b844fea6 separate rules for function/operation definitions;
wenzelm
parents: 10459
diff changeset
   201
proof -
4f15b844fea6 separate rules for function/operation definitions;
wenzelm
parents: 10459
diff changeset
   202
  case antecedent from this refl TrueI
4f15b844fea6 separate rules for function/operation definitions;
wenzelm
parents: 10459
diff changeset
   203
  show ?thesis by (rule quot_cond_function1)
4f15b844fea6 separate rules for function/operation definitions;
wenzelm
parents: 10459
diff changeset
   204
qed
4f15b844fea6 separate rules for function/operation definitions;
wenzelm
parents: 10459
diff changeset
   205
4f15b844fea6 separate rules for function/operation definitions;
wenzelm
parents: 10459
diff changeset
   206
theorem quot_cond_operation1:
10459
df3cd3e76046 quot_cond_definition;
wenzelm
parents: 10437
diff changeset
   207
  "(!!X. f X == \<lfloor>g (pick X)\<rfloor>) ==>
df3cd3e76046 quot_cond_definition;
wenzelm
parents: 10437
diff changeset
   208
    (!!x x'. x \<sim> x' ==> P x ==> P x' ==> g x \<sim> g x') ==>
df3cd3e76046 quot_cond_definition;
wenzelm
parents: 10437
diff changeset
   209
    (!!x x'. x \<sim> x' ==> P x = P x') ==>
df3cd3e76046 quot_cond_definition;
wenzelm
parents: 10437
diff changeset
   210
  P a ==> f \<lfloor>a\<rfloor> = \<lfloor>g a\<rfloor>"
df3cd3e76046 quot_cond_definition;
wenzelm
parents: 10437
diff changeset
   211
proof -
10473
4f15b844fea6 separate rules for function/operation definitions;
wenzelm
parents: 10459
diff changeset
   212
  assume defn: "!!X. f X == \<lfloor>g (pick X)\<rfloor>"
4f15b844fea6 separate rules for function/operation definitions;
wenzelm
parents: 10459
diff changeset
   213
  assume "!!x x'. x \<sim> x' ==> P x ==> P x' ==> g x \<sim> g x'"
4f15b844fea6 separate rules for function/operation definitions;
wenzelm
parents: 10459
diff changeset
   214
  hence cong_g: "!!x x'. x \<sim> x' ==> P x ==> P x' ==> \<lfloor>g x\<rfloor> = \<lfloor>g x'\<rfloor>" ..
4f15b844fea6 separate rules for function/operation definitions;
wenzelm
parents: 10459
diff changeset
   215
  assume "!!x x'. x \<sim> x' ==> P x = P x'" and "P a"
4f15b844fea6 separate rules for function/operation definitions;
wenzelm
parents: 10459
diff changeset
   216
  with defn cong_g show ?thesis by (rule quot_cond_function1)
10459
df3cd3e76046 quot_cond_definition;
wenzelm
parents: 10437
diff changeset
   217
qed
df3cd3e76046 quot_cond_definition;
wenzelm
parents: 10437
diff changeset
   218
10473
4f15b844fea6 separate rules for function/operation definitions;
wenzelm
parents: 10459
diff changeset
   219
theorem quot_operation1:
10437
7528f9e30ca4 improved cong_definition theorems;
wenzelm
parents: 10392
diff changeset
   220
  "(!!X. f X == \<lfloor>g (pick X)\<rfloor>) ==>
7528f9e30ca4 improved cong_definition theorems;
wenzelm
parents: 10392
diff changeset
   221
    (!!x x'. x \<sim> x' ==> g x \<sim> g x') ==>
7528f9e30ca4 improved cong_definition theorems;
wenzelm
parents: 10392
diff changeset
   222
    f \<lfloor>a\<rfloor> = \<lfloor>g a\<rfloor>"
10285
6949e17f314a simplified quotients (only plain total equivs);
wenzelm
parents: 10278
diff changeset
   223
proof -
10459
df3cd3e76046 quot_cond_definition;
wenzelm
parents: 10437
diff changeset
   224
  case antecedent from this refl TrueI
10473
4f15b844fea6 separate rules for function/operation definitions;
wenzelm
parents: 10459
diff changeset
   225
  show ?thesis by (rule quot_cond_operation1)
10459
df3cd3e76046 quot_cond_definition;
wenzelm
parents: 10437
diff changeset
   226
qed
df3cd3e76046 quot_cond_definition;
wenzelm
parents: 10437
diff changeset
   227
10473
4f15b844fea6 separate rules for function/operation definitions;
wenzelm
parents: 10459
diff changeset
   228
theorem quot_cond_function2:
4f15b844fea6 separate rules for function/operation definitions;
wenzelm
parents: 10459
diff changeset
   229
  "(!!X Y. f X Y == g (pick X) (pick Y)) ==>
4f15b844fea6 separate rules for function/operation definitions;
wenzelm
parents: 10459
diff changeset
   230
    (!!x x' y y'. x \<sim> x' ==> y \<sim> y' ==> P x y ==> P x' y'
4f15b844fea6 separate rules for function/operation definitions;
wenzelm
parents: 10459
diff changeset
   231
      ==> g x y = g x' y') ==>
10459
df3cd3e76046 quot_cond_definition;
wenzelm
parents: 10437
diff changeset
   232
    (!!x x' y y'. x \<sim> x' ==> y \<sim> y' ==> P x y = P x' y') ==>
10473
4f15b844fea6 separate rules for function/operation definitions;
wenzelm
parents: 10459
diff changeset
   233
    P a b ==> f \<lfloor>a\<rfloor> \<lfloor>b\<rfloor> = g a b"
10459
df3cd3e76046 quot_cond_definition;
wenzelm
parents: 10437
diff changeset
   234
proof -
10473
4f15b844fea6 separate rules for function/operation definitions;
wenzelm
parents: 10459
diff changeset
   235
  assume cong_g: "!!x x' y y'. x \<sim> x' ==> y \<sim> y' ==> P x y ==> P x' y'
4f15b844fea6 separate rules for function/operation definitions;
wenzelm
parents: 10459
diff changeset
   236
    ==> g x y = g x' y'"
10459
df3cd3e76046 quot_cond_definition;
wenzelm
parents: 10437
diff changeset
   237
  assume cong_P: "!!x x' y y'. x \<sim> x' ==> y \<sim> y' ==> P x y = P x' y'"
df3cd3e76046 quot_cond_definition;
wenzelm
parents: 10437
diff changeset
   238
  assume P: "P a b"
10473
4f15b844fea6 separate rules for function/operation definitions;
wenzelm
parents: 10459
diff changeset
   239
  assume "!!X Y. f X Y == g (pick X) (pick Y)"
4f15b844fea6 separate rules for function/operation definitions;
wenzelm
parents: 10459
diff changeset
   240
  hence "f \<lfloor>a\<rfloor> \<lfloor>b\<rfloor> = g (pick \<lfloor>a\<rfloor>) (pick \<lfloor>b\<rfloor>)" by (simp only:)
4f15b844fea6 separate rules for function/operation definitions;
wenzelm
parents: 10459
diff changeset
   241
  also have "\<dots> = g a b"
4f15b844fea6 separate rules for function/operation definitions;
wenzelm
parents: 10459
diff changeset
   242
  proof (rule cong_g)
4f15b844fea6 separate rules for function/operation definitions;
wenzelm
parents: 10459
diff changeset
   243
    show "pick \<lfloor>a\<rfloor> \<sim> a" ..
4f15b844fea6 separate rules for function/operation definitions;
wenzelm
parents: 10459
diff changeset
   244
    moreover show "pick \<lfloor>b\<rfloor> \<sim> b" ..
4f15b844fea6 separate rules for function/operation definitions;
wenzelm
parents: 10459
diff changeset
   245
    ultimately have "P (pick \<lfloor>a\<rfloor>) (pick \<lfloor>b\<rfloor>) = P a b" by (rule cong_P)
4f15b844fea6 separate rules for function/operation definitions;
wenzelm
parents: 10459
diff changeset
   246
    also show "P a b" .
4f15b844fea6 separate rules for function/operation definitions;
wenzelm
parents: 10459
diff changeset
   247
    finally show "P (pick \<lfloor>a\<rfloor>) (pick \<lfloor>b\<rfloor>)" .
10285
6949e17f314a simplified quotients (only plain total equivs);
wenzelm
parents: 10278
diff changeset
   248
  qed
6949e17f314a simplified quotients (only plain total equivs);
wenzelm
parents: 10278
diff changeset
   249
  finally show ?thesis .
6949e17f314a simplified quotients (only plain total equivs);
wenzelm
parents: 10278
diff changeset
   250
qed
6949e17f314a simplified quotients (only plain total equivs);
wenzelm
parents: 10278
diff changeset
   251
10473
4f15b844fea6 separate rules for function/operation definitions;
wenzelm
parents: 10459
diff changeset
   252
theorem quot_function2:
4f15b844fea6 separate rules for function/operation definitions;
wenzelm
parents: 10459
diff changeset
   253
  "(!!X Y. f X Y == g (pick X) (pick Y)) ==>
4f15b844fea6 separate rules for function/operation definitions;
wenzelm
parents: 10459
diff changeset
   254
    (!!x x' y y'. x \<sim> x' ==> y \<sim> y' ==> g x y = g x' y') ==>
4f15b844fea6 separate rules for function/operation definitions;
wenzelm
parents: 10459
diff changeset
   255
    f \<lfloor>a\<rfloor> \<lfloor>b\<rfloor> = g a b"
4f15b844fea6 separate rules for function/operation definitions;
wenzelm
parents: 10459
diff changeset
   256
proof -
4f15b844fea6 separate rules for function/operation definitions;
wenzelm
parents: 10459
diff changeset
   257
  case antecedent from this refl TrueI
4f15b844fea6 separate rules for function/operation definitions;
wenzelm
parents: 10459
diff changeset
   258
  show ?thesis by (rule quot_cond_function2)
4f15b844fea6 separate rules for function/operation definitions;
wenzelm
parents: 10459
diff changeset
   259
qed
4f15b844fea6 separate rules for function/operation definitions;
wenzelm
parents: 10459
diff changeset
   260
4f15b844fea6 separate rules for function/operation definitions;
wenzelm
parents: 10459
diff changeset
   261
theorem quot_cond_operation2:
4f15b844fea6 separate rules for function/operation definitions;
wenzelm
parents: 10459
diff changeset
   262
  "(!!X Y. f X Y == \<lfloor>g (pick X) (pick Y)\<rfloor>) ==>
4f15b844fea6 separate rules for function/operation definitions;
wenzelm
parents: 10459
diff changeset
   263
    (!!x x' y y'. x \<sim> x' ==> y \<sim> y' ==> P x y ==> P x' y'
4f15b844fea6 separate rules for function/operation definitions;
wenzelm
parents: 10459
diff changeset
   264
      ==> g x y \<sim> g x' y') ==>
4f15b844fea6 separate rules for function/operation definitions;
wenzelm
parents: 10459
diff changeset
   265
    (!!x x' y y'. x \<sim> x' ==> y \<sim> y' ==> P x y = P x' y') ==>
4f15b844fea6 separate rules for function/operation definitions;
wenzelm
parents: 10459
diff changeset
   266
    P a b ==> f \<lfloor>a\<rfloor> \<lfloor>b\<rfloor> = \<lfloor>g a b\<rfloor>"
4f15b844fea6 separate rules for function/operation definitions;
wenzelm
parents: 10459
diff changeset
   267
proof -
4f15b844fea6 separate rules for function/operation definitions;
wenzelm
parents: 10459
diff changeset
   268
  assume defn: "!!X Y. f X Y == \<lfloor>g (pick X) (pick Y)\<rfloor>"
4f15b844fea6 separate rules for function/operation definitions;
wenzelm
parents: 10459
diff changeset
   269
  assume "!!x x' y y'. x \<sim> x' ==> y \<sim> y' ==> P x y ==> P x' y'
4f15b844fea6 separate rules for function/operation definitions;
wenzelm
parents: 10459
diff changeset
   270
    ==> g x y \<sim> g x' y'"
4f15b844fea6 separate rules for function/operation definitions;
wenzelm
parents: 10459
diff changeset
   271
  hence cong_g: "!!x x' y y'. x \<sim> x' ==> y \<sim> y' ==> P x y ==> P x' y'
4f15b844fea6 separate rules for function/operation definitions;
wenzelm
parents: 10459
diff changeset
   272
    ==> \<lfloor>g x y\<rfloor> = \<lfloor>g x' y'\<rfloor>" ..
4f15b844fea6 separate rules for function/operation definitions;
wenzelm
parents: 10459
diff changeset
   273
  assume "!!x x' y y'. x \<sim> x' ==> y \<sim> y' ==> P x y = P x' y'" and "P a b"
4f15b844fea6 separate rules for function/operation definitions;
wenzelm
parents: 10459
diff changeset
   274
  with defn cong_g show ?thesis by (rule quot_cond_function2)
4f15b844fea6 separate rules for function/operation definitions;
wenzelm
parents: 10459
diff changeset
   275
qed
4f15b844fea6 separate rules for function/operation definitions;
wenzelm
parents: 10459
diff changeset
   276
4f15b844fea6 separate rules for function/operation definitions;
wenzelm
parents: 10459
diff changeset
   277
theorem quot_operation2:
10437
7528f9e30ca4 improved cong_definition theorems;
wenzelm
parents: 10392
diff changeset
   278
  "(!!X Y. f X Y == \<lfloor>g (pick X) (pick Y)\<rfloor>) ==>
7528f9e30ca4 improved cong_definition theorems;
wenzelm
parents: 10392
diff changeset
   279
    (!!x x' y y'. x \<sim> x' ==> y \<sim> y' ==> g x y \<sim> g x' y') ==>
7528f9e30ca4 improved cong_definition theorems;
wenzelm
parents: 10392
diff changeset
   280
    f \<lfloor>a\<rfloor> \<lfloor>b\<rfloor> = \<lfloor>g a b\<rfloor>"
10285
6949e17f314a simplified quotients (only plain total equivs);
wenzelm
parents: 10278
diff changeset
   281
proof -
10459
df3cd3e76046 quot_cond_definition;
wenzelm
parents: 10437
diff changeset
   282
  case antecedent from this refl TrueI
10473
4f15b844fea6 separate rules for function/operation definitions;
wenzelm
parents: 10459
diff changeset
   283
  show ?thesis by (rule quot_cond_operation2)
10285
6949e17f314a simplified quotients (only plain total equivs);
wenzelm
parents: 10278
diff changeset
   284
qed
6949e17f314a simplified quotients (only plain total equivs);
wenzelm
parents: 10278
diff changeset
   285
10437
7528f9e30ca4 improved cong_definition theorems;
wenzelm
parents: 10392
diff changeset
   286
text {*
7528f9e30ca4 improved cong_definition theorems;
wenzelm
parents: 10392
diff changeset
   287
 \medskip HOL's collection of overloaded standard operations is lifted
7528f9e30ca4 improved cong_definition theorems;
wenzelm
parents: 10392
diff changeset
   288
 to quotient types in the canonical manner.
7528f9e30ca4 improved cong_definition theorems;
wenzelm
parents: 10392
diff changeset
   289
*}
7528f9e30ca4 improved cong_definition theorems;
wenzelm
parents: 10392
diff changeset
   290
7528f9e30ca4 improved cong_definition theorems;
wenzelm
parents: 10392
diff changeset
   291
instance quot :: (zero) zero ..
7528f9e30ca4 improved cong_definition theorems;
wenzelm
parents: 10392
diff changeset
   292
instance quot :: (plus) plus ..
7528f9e30ca4 improved cong_definition theorems;
wenzelm
parents: 10392
diff changeset
   293
instance quot :: (minus) minus ..
7528f9e30ca4 improved cong_definition theorems;
wenzelm
parents: 10392
diff changeset
   294
instance quot :: (times) times ..
7528f9e30ca4 improved cong_definition theorems;
wenzelm
parents: 10392
diff changeset
   295
instance quot :: (inverse) inverse ..
7528f9e30ca4 improved cong_definition theorems;
wenzelm
parents: 10392
diff changeset
   296
instance quot :: (power) power ..
7528f9e30ca4 improved cong_definition theorems;
wenzelm
parents: 10392
diff changeset
   297
instance quot :: (number) number ..
10459
df3cd3e76046 quot_cond_definition;
wenzelm
parents: 10437
diff changeset
   298
instance quot :: (ord) ord ..
10437
7528f9e30ca4 improved cong_definition theorems;
wenzelm
parents: 10392
diff changeset
   299
7528f9e30ca4 improved cong_definition theorems;
wenzelm
parents: 10392
diff changeset
   300
defs (overloaded)
7528f9e30ca4 improved cong_definition theorems;
wenzelm
parents: 10392
diff changeset
   301
  zero_quot_def: "0 == \<lfloor>0\<rfloor>"
7528f9e30ca4 improved cong_definition theorems;
wenzelm
parents: 10392
diff changeset
   302
  add_quot_def: "X + Y == \<lfloor>pick X + pick Y\<rfloor>"
7528f9e30ca4 improved cong_definition theorems;
wenzelm
parents: 10392
diff changeset
   303
  diff_quot_def: "X - Y == \<lfloor>pick X - pick Y\<rfloor>"
7528f9e30ca4 improved cong_definition theorems;
wenzelm
parents: 10392
diff changeset
   304
  minus_quot_def: "- X == \<lfloor>- pick X\<rfloor>"
7528f9e30ca4 improved cong_definition theorems;
wenzelm
parents: 10392
diff changeset
   305
  abs_quot_def: "abs X == \<lfloor>abs (pick X)\<rfloor>"
7528f9e30ca4 improved cong_definition theorems;
wenzelm
parents: 10392
diff changeset
   306
  mult_quot_def: "X * Y == \<lfloor>pick X * pick Y\<rfloor>"
7528f9e30ca4 improved cong_definition theorems;
wenzelm
parents: 10392
diff changeset
   307
  inverse_quot_def: "inverse X == \<lfloor>inverse (pick X)\<rfloor>"
7528f9e30ca4 improved cong_definition theorems;
wenzelm
parents: 10392
diff changeset
   308
  divide_quot_def: "X / Y == \<lfloor>pick X / pick Y\<rfloor>"
7528f9e30ca4 improved cong_definition theorems;
wenzelm
parents: 10392
diff changeset
   309
  power_quot_def: "X^n == \<lfloor>(pick X)^n\<rfloor>"
7528f9e30ca4 improved cong_definition theorems;
wenzelm
parents: 10392
diff changeset
   310
  number_of_quot_def: "number_of b == \<lfloor>number_of b\<rfloor>"
10459
df3cd3e76046 quot_cond_definition;
wenzelm
parents: 10437
diff changeset
   311
  le_quot_def: "X \<le> Y == pick X \<le> pick Y"
df3cd3e76046 quot_cond_definition;
wenzelm
parents: 10437
diff changeset
   312
  less_quot_def: "X < Y == pick X < pick Y"
10437
7528f9e30ca4 improved cong_definition theorems;
wenzelm
parents: 10392
diff changeset
   313
10250
ca93fe25a84b Quotient types;
wenzelm
parents:
diff changeset
   314
end