src/HOL/Library/Quotient_Type.thy
author wenzelm
Thu, 24 Sep 2015 13:33:42 +0200
changeset 61260 e6f03fae14d5
parent 59192 a1d6d6db781b
child 61585 a9599d3d7610
permissions -rw-r--r--
explicit indication of overloaded typedefs;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
35100
53754ec7360b renamed Library/Quotient.thy to Library/Quotient_Type.thy to avoid clash with new theory Quotient in Main HOL;
wenzelm
parents: 30738
diff changeset
     1
(*  Title:      HOL/Library/Quotient_Type.thy
10483
eb93ace45a6e removed quot_cond_function1, quot_function1;
wenzelm
parents: 10477
diff changeset
     2
    Author:     Markus Wenzel, TU Muenchen
10250
ca93fe25a84b Quotient types;
wenzelm
parents:
diff changeset
     3
*)
ca93fe25a84b Quotient types;
wenzelm
parents:
diff changeset
     4
59192
a1d6d6db781b modernized historic example;
wenzelm
parents: 58881
diff changeset
     5
section \<open>Quotient types\<close>
10250
ca93fe25a84b Quotient types;
wenzelm
parents:
diff changeset
     6
35100
53754ec7360b renamed Library/Quotient.thy to Library/Quotient_Type.thy to avoid clash with new theory Quotient in Main HOL;
wenzelm
parents: 30738
diff changeset
     7
theory Quotient_Type
30738
0842e906300c normalized imports
haftmann
parents: 29608
diff changeset
     8
imports Main
15131
c69542757a4d New theory header syntax.
nipkow
parents: 14981
diff changeset
     9
begin
10250
ca93fe25a84b Quotient types;
wenzelm
parents:
diff changeset
    10
59192
a1d6d6db781b modernized historic example;
wenzelm
parents: 58881
diff changeset
    11
text \<open>We introduce the notion of quotient types over equivalence relations
a1d6d6db781b modernized historic example;
wenzelm
parents: 58881
diff changeset
    12
  via type classes.\<close>
a1d6d6db781b modernized historic example;
wenzelm
parents: 58881
diff changeset
    13
10250
ca93fe25a84b Quotient types;
wenzelm
parents:
diff changeset
    14
59192
a1d6d6db781b modernized historic example;
wenzelm
parents: 58881
diff changeset
    15
subsection \<open>Equivalence relations and quotient types\<close>
10250
ca93fe25a84b Quotient types;
wenzelm
parents:
diff changeset
    16
59192
a1d6d6db781b modernized historic example;
wenzelm
parents: 58881
diff changeset
    17
text \<open>Type class @{text equiv} models equivalence relations
a1d6d6db781b modernized historic example;
wenzelm
parents: 58881
diff changeset
    18
  @{text "\<sim> :: 'a \<Rightarrow> 'a \<Rightarrow> bool"}.\<close>
10250
ca93fe25a84b Quotient types;
wenzelm
parents:
diff changeset
    19
29608
564ea783ace8 no base sort in class import
haftmann
parents: 27487
diff changeset
    20
class eqv =
59192
a1d6d6db781b modernized historic example;
wenzelm
parents: 58881
diff changeset
    21
  fixes eqv :: "'a \<Rightarrow> 'a \<Rightarrow> bool"  (infixl "\<sim>" 50)
10250
ca93fe25a84b Quotient types;
wenzelm
parents:
diff changeset
    22
22390
378f34b1e380 now using "class"
haftmann
parents: 21404
diff changeset
    23
class equiv = eqv +
25062
af5ef0d4d655 global class syntax
haftmann
parents: 23394
diff changeset
    24
  assumes equiv_refl [intro]: "x \<sim> x"
59192
a1d6d6db781b modernized historic example;
wenzelm
parents: 58881
diff changeset
    25
    and equiv_trans [trans]: "x \<sim> y \<Longrightarrow> y \<sim> z \<Longrightarrow> x \<sim> z"
a1d6d6db781b modernized historic example;
wenzelm
parents: 58881
diff changeset
    26
    and equiv_sym [sym]: "x \<sim> y \<Longrightarrow> y \<sim> x"
a1d6d6db781b modernized historic example;
wenzelm
parents: 58881
diff changeset
    27
begin
10250
ca93fe25a84b Quotient types;
wenzelm
parents:
diff changeset
    28
59192
a1d6d6db781b modernized historic example;
wenzelm
parents: 58881
diff changeset
    29
lemma equiv_not_sym [sym]: "\<not> x \<sim> y \<Longrightarrow> \<not> y \<sim> x"
10477
c21bee84cefe added not_equiv_sym, not_equiv_trans1/2;
wenzelm
parents: 10473
diff changeset
    30
proof -
59192
a1d6d6db781b modernized historic example;
wenzelm
parents: 58881
diff changeset
    31
  assume "\<not> x \<sim> y"
a1d6d6db781b modernized historic example;
wenzelm
parents: 58881
diff changeset
    32
  then show "\<not> y \<sim> x" by (rule contrapos_nn) (rule equiv_sym)
10477
c21bee84cefe added not_equiv_sym, not_equiv_trans1/2;
wenzelm
parents: 10473
diff changeset
    33
qed
c21bee84cefe added not_equiv_sym, not_equiv_trans1/2;
wenzelm
parents: 10473
diff changeset
    34
59192
a1d6d6db781b modernized historic example;
wenzelm
parents: 58881
diff changeset
    35
lemma not_equiv_trans1 [trans]: "\<not> x \<sim> y \<Longrightarrow> y \<sim> z \<Longrightarrow> \<not> x \<sim> z"
10477
c21bee84cefe added not_equiv_sym, not_equiv_trans1/2;
wenzelm
parents: 10473
diff changeset
    36
proof -
59192
a1d6d6db781b modernized historic example;
wenzelm
parents: 58881
diff changeset
    37
  assume "\<not> x \<sim> y" and "y \<sim> z"
a1d6d6db781b modernized historic example;
wenzelm
parents: 58881
diff changeset
    38
  show "\<not> x \<sim> z"
10477
c21bee84cefe added not_equiv_sym, not_equiv_trans1/2;
wenzelm
parents: 10473
diff changeset
    39
  proof
c21bee84cefe added not_equiv_sym, not_equiv_trans1/2;
wenzelm
parents: 10473
diff changeset
    40
    assume "x \<sim> z"
59192
a1d6d6db781b modernized historic example;
wenzelm
parents: 58881
diff changeset
    41
    also from \<open>y \<sim> z\<close> have "z \<sim> y" ..
10477
c21bee84cefe added not_equiv_sym, not_equiv_trans1/2;
wenzelm
parents: 10473
diff changeset
    42
    finally have "x \<sim> y" .
59192
a1d6d6db781b modernized historic example;
wenzelm
parents: 58881
diff changeset
    43
    with \<open>\<not> x \<sim> y\<close> show False by contradiction
10477
c21bee84cefe added not_equiv_sym, not_equiv_trans1/2;
wenzelm
parents: 10473
diff changeset
    44
  qed
c21bee84cefe added not_equiv_sym, not_equiv_trans1/2;
wenzelm
parents: 10473
diff changeset
    45
qed
c21bee84cefe added not_equiv_sym, not_equiv_trans1/2;
wenzelm
parents: 10473
diff changeset
    46
59192
a1d6d6db781b modernized historic example;
wenzelm
parents: 58881
diff changeset
    47
lemma not_equiv_trans2 [trans]: "x \<sim> y \<Longrightarrow> \<not> y \<sim> z \<Longrightarrow> \<not> x \<sim> z"
10477
c21bee84cefe added not_equiv_sym, not_equiv_trans1/2;
wenzelm
parents: 10473
diff changeset
    48
proof -
59192
a1d6d6db781b modernized historic example;
wenzelm
parents: 58881
diff changeset
    49
  assume "\<not> y \<sim> z"
a1d6d6db781b modernized historic example;
wenzelm
parents: 58881
diff changeset
    50
  then have "\<not> z \<sim> y" ..
a1d6d6db781b modernized historic example;
wenzelm
parents: 58881
diff changeset
    51
  also
a1d6d6db781b modernized historic example;
wenzelm
parents: 58881
diff changeset
    52
  assume "x \<sim> y"
a1d6d6db781b modernized historic example;
wenzelm
parents: 58881
diff changeset
    53
  then have "y \<sim> x" ..
a1d6d6db781b modernized historic example;
wenzelm
parents: 58881
diff changeset
    54
  finally have "\<not> z \<sim> x" .
a1d6d6db781b modernized historic example;
wenzelm
parents: 58881
diff changeset
    55
  then show "\<not> x \<sim> z" ..
10477
c21bee84cefe added not_equiv_sym, not_equiv_trans1/2;
wenzelm
parents: 10473
diff changeset
    56
qed
c21bee84cefe added not_equiv_sym, not_equiv_trans1/2;
wenzelm
parents: 10473
diff changeset
    57
59192
a1d6d6db781b modernized historic example;
wenzelm
parents: 58881
diff changeset
    58
end
10250
ca93fe25a84b Quotient types;
wenzelm
parents:
diff changeset
    59
59192
a1d6d6db781b modernized historic example;
wenzelm
parents: 58881
diff changeset
    60
text \<open>The quotient type @{text "'a quot"} consists of all \emph{equivalence
a1d6d6db781b modernized historic example;
wenzelm
parents: 58881
diff changeset
    61
  classes} over elements of the base type @{typ 'a}.\<close>
a1d6d6db781b modernized historic example;
wenzelm
parents: 58881
diff changeset
    62
a1d6d6db781b modernized historic example;
wenzelm
parents: 58881
diff changeset
    63
definition (in eqv) "quot = {{x. a \<sim> x} | a. True}"
45694
4a8743618257 prefer typedef without extra definition and alternative name;
wenzelm
parents: 35100
diff changeset
    64
61260
e6f03fae14d5 explicit indication of overloaded typedefs;
wenzelm
parents: 59192
diff changeset
    65
typedef (overloaded) 'a quot = "quot :: 'a::eqv set set"
45694
4a8743618257 prefer typedef without extra definition and alternative name;
wenzelm
parents: 35100
diff changeset
    66
  unfolding quot_def by blast
10250
ca93fe25a84b Quotient types;
wenzelm
parents:
diff changeset
    67
ca93fe25a84b Quotient types;
wenzelm
parents:
diff changeset
    68
lemma quotI [intro]: "{x. a \<sim> x} \<in> quot"
18730
843da46f89ac tuned proofs;
wenzelm
parents: 18551
diff changeset
    69
  unfolding quot_def by blast
10250
ca93fe25a84b Quotient types;
wenzelm
parents:
diff changeset
    70
59192
a1d6d6db781b modernized historic example;
wenzelm
parents: 58881
diff changeset
    71
lemma quotE [elim]:
a1d6d6db781b modernized historic example;
wenzelm
parents: 58881
diff changeset
    72
  assumes "R \<in> quot"
a1d6d6db781b modernized historic example;
wenzelm
parents: 58881
diff changeset
    73
  obtains a where "R = {x. a \<sim> x}"
a1d6d6db781b modernized historic example;
wenzelm
parents: 58881
diff changeset
    74
  using assms unfolding quot_def by blast
10250
ca93fe25a84b Quotient types;
wenzelm
parents:
diff changeset
    75
59192
a1d6d6db781b modernized historic example;
wenzelm
parents: 58881
diff changeset
    76
text \<open>Abstracted equivalence classes are the canonical representation of
a1d6d6db781b modernized historic example;
wenzelm
parents: 58881
diff changeset
    77
  elements of a quotient type.\<close>
10250
ca93fe25a84b Quotient types;
wenzelm
parents:
diff changeset
    78
59192
a1d6d6db781b modernized historic example;
wenzelm
parents: 58881
diff changeset
    79
definition "class" :: "'a::equiv \<Rightarrow> 'a quot"  ("\<lfloor>_\<rfloor>")
a1d6d6db781b modernized historic example;
wenzelm
parents: 58881
diff changeset
    80
  where "\<lfloor>a\<rfloor> = Abs_quot {x. a \<sim> x}"
10250
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)
59192
a1d6d6db781b modernized historic example;
wenzelm
parents: 58881
diff changeset
    84
  fix R
a1d6d6db781b modernized historic example;
wenzelm
parents: 58881
diff changeset
    85
  assume R: "A = Abs_quot R"
a1d6d6db781b modernized historic example;
wenzelm
parents: 58881
diff changeset
    86
  assume "R \<in> quot"
a1d6d6db781b modernized historic example;
wenzelm
parents: 58881
diff changeset
    87
  then have "\<exists>a. R = {x. a \<sim> x}" by blast
10278
ea1bf4b6255c improved typedef;
wenzelm
parents: 10250
diff changeset
    88
  with R have "\<exists>a. A = Abs_quot {x. a \<sim> x}" by blast
23373
ead82c82da9e tuned proofs: avoid implicit prems;
wenzelm
parents: 22473
diff changeset
    89
  then show ?thesis unfolding class_def .
10250
ca93fe25a84b Quotient types;
wenzelm
parents:
diff changeset
    90
qed
ca93fe25a84b Quotient types;
wenzelm
parents:
diff changeset
    91
59192
a1d6d6db781b modernized historic example;
wenzelm
parents: 58881
diff changeset
    92
lemma quot_cases [cases type: quot]:
a1d6d6db781b modernized historic example;
wenzelm
parents: 58881
diff changeset
    93
  obtains a where "A = \<lfloor>a\<rfloor>"
18730
843da46f89ac tuned proofs;
wenzelm
parents: 18551
diff changeset
    94
  using quot_exhaust by blast
10250
ca93fe25a84b Quotient types;
wenzelm
parents:
diff changeset
    95
ca93fe25a84b Quotient types;
wenzelm
parents:
diff changeset
    96
59192
a1d6d6db781b modernized historic example;
wenzelm
parents: 58881
diff changeset
    97
subsection \<open>Equality on quotients\<close>
10250
ca93fe25a84b Quotient types;
wenzelm
parents:
diff changeset
    98
59192
a1d6d6db781b modernized historic example;
wenzelm
parents: 58881
diff changeset
    99
text \<open>Equality of canonical quotient elements coincides with the original
a1d6d6db781b modernized historic example;
wenzelm
parents: 58881
diff changeset
   100
  relation.\<close>
10250
ca93fe25a84b Quotient types;
wenzelm
parents:
diff changeset
   101
59192
a1d6d6db781b modernized historic example;
wenzelm
parents: 58881
diff changeset
   102
theorem quot_equality [iff?]: "\<lfloor>a\<rfloor> = \<lfloor>b\<rfloor> \<longleftrightarrow> a \<sim> b"
10285
6949e17f314a simplified quotients (only plain total equivs);
wenzelm
parents: 10278
diff changeset
   103
proof
6949e17f314a simplified quotients (only plain total equivs);
wenzelm
parents: 10278
diff changeset
   104
  assume eq: "\<lfloor>a\<rfloor> = \<lfloor>b\<rfloor>"
6949e17f314a simplified quotients (only plain total equivs);
wenzelm
parents: 10278
diff changeset
   105
  show "a \<sim> b"
6949e17f314a simplified quotients (only plain total equivs);
wenzelm
parents: 10278
diff changeset
   106
  proof -
6949e17f314a simplified quotients (only plain total equivs);
wenzelm
parents: 10278
diff changeset
   107
    from eq have "{x. a \<sim> x} = {x. b \<sim> x}"
10551
ec9fab41b3a0 renamed "equivalence_class" to "class";
wenzelm
parents: 10505
diff changeset
   108
      by (simp only: class_def Abs_quot_inject quotI)
10285
6949e17f314a simplified quotients (only plain total equivs);
wenzelm
parents: 10278
diff changeset
   109
    moreover have "a \<sim> a" ..
6949e17f314a simplified quotients (only plain total equivs);
wenzelm
parents: 10278
diff changeset
   110
    ultimately have "a \<in> {x. b \<sim> x}" by blast
23373
ead82c82da9e tuned proofs: avoid implicit prems;
wenzelm
parents: 22473
diff changeset
   111
    then have "b \<sim> a" by blast
ead82c82da9e tuned proofs: avoid implicit prems;
wenzelm
parents: 22473
diff changeset
   112
    then show ?thesis ..
10285
6949e17f314a simplified quotients (only plain total equivs);
wenzelm
parents: 10278
diff changeset
   113
  qed
6949e17f314a simplified quotients (only plain total equivs);
wenzelm
parents: 10278
diff changeset
   114
next
10250
ca93fe25a84b Quotient types;
wenzelm
parents:
diff changeset
   115
  assume ab: "a \<sim> b"
10285
6949e17f314a simplified quotients (only plain total equivs);
wenzelm
parents: 10278
diff changeset
   116
  show "\<lfloor>a\<rfloor> = \<lfloor>b\<rfloor>"
6949e17f314a simplified quotients (only plain total equivs);
wenzelm
parents: 10278
diff changeset
   117
  proof -
6949e17f314a simplified quotients (only plain total equivs);
wenzelm
parents: 10278
diff changeset
   118
    have "{x. a \<sim> x} = {x. b \<sim> x}"
6949e17f314a simplified quotients (only plain total equivs);
wenzelm
parents: 10278
diff changeset
   119
    proof (rule Collect_cong)
6949e17f314a simplified quotients (only plain total equivs);
wenzelm
parents: 10278
diff changeset
   120
      fix x show "(a \<sim> x) = (b \<sim> x)"
6949e17f314a simplified quotients (only plain total equivs);
wenzelm
parents: 10278
diff changeset
   121
      proof
6949e17f314a simplified quotients (only plain total equivs);
wenzelm
parents: 10278
diff changeset
   122
        from ab have "b \<sim> a" ..
6949e17f314a simplified quotients (only plain total equivs);
wenzelm
parents: 10278
diff changeset
   123
        also assume "a \<sim> x"
6949e17f314a simplified quotients (only plain total equivs);
wenzelm
parents: 10278
diff changeset
   124
        finally show "b \<sim> x" .
6949e17f314a simplified quotients (only plain total equivs);
wenzelm
parents: 10278
diff changeset
   125
      next
6949e17f314a simplified quotients (only plain total equivs);
wenzelm
parents: 10278
diff changeset
   126
        note ab
6949e17f314a simplified quotients (only plain total equivs);
wenzelm
parents: 10278
diff changeset
   127
        also assume "b \<sim> x"
6949e17f314a simplified quotients (only plain total equivs);
wenzelm
parents: 10278
diff changeset
   128
        finally show "a \<sim> x" .
6949e17f314a simplified quotients (only plain total equivs);
wenzelm
parents: 10278
diff changeset
   129
      qed
10250
ca93fe25a84b Quotient types;
wenzelm
parents:
diff changeset
   130
    qed
23373
ead82c82da9e tuned proofs: avoid implicit prems;
wenzelm
parents: 22473
diff changeset
   131
    then show ?thesis by (simp only: class_def)
10250
ca93fe25a84b Quotient types;
wenzelm
parents:
diff changeset
   132
  qed
ca93fe25a84b Quotient types;
wenzelm
parents:
diff changeset
   133
qed
ca93fe25a84b Quotient types;
wenzelm
parents:
diff changeset
   134
ca93fe25a84b Quotient types;
wenzelm
parents:
diff changeset
   135
59192
a1d6d6db781b modernized historic example;
wenzelm
parents: 58881
diff changeset
   136
subsection \<open>Picking representing elements\<close>
10250
ca93fe25a84b Quotient types;
wenzelm
parents:
diff changeset
   137
59192
a1d6d6db781b modernized historic example;
wenzelm
parents: 58881
diff changeset
   138
definition pick :: "'a::equiv quot \<Rightarrow> 'a"
a1d6d6db781b modernized historic example;
wenzelm
parents: 58881
diff changeset
   139
  where "pick A = (SOME a. A = \<lfloor>a\<rfloor>)"
10250
ca93fe25a84b Quotient types;
wenzelm
parents:
diff changeset
   140
10285
6949e17f314a simplified quotients (only plain total equivs);
wenzelm
parents: 10278
diff changeset
   141
theorem pick_equiv [intro]: "pick \<lfloor>a\<rfloor> \<sim> a"
10250
ca93fe25a84b Quotient types;
wenzelm
parents:
diff changeset
   142
proof (unfold pick_def)
ca93fe25a84b Quotient types;
wenzelm
parents:
diff changeset
   143
  show "(SOME x. \<lfloor>a\<rfloor> = \<lfloor>x\<rfloor>) \<sim> a"
ca93fe25a84b Quotient types;
wenzelm
parents:
diff changeset
   144
  proof (rule someI2)
ca93fe25a84b Quotient types;
wenzelm
parents:
diff changeset
   145
    show "\<lfloor>a\<rfloor> = \<lfloor>a\<rfloor>" ..
ca93fe25a84b Quotient types;
wenzelm
parents:
diff changeset
   146
    fix x assume "\<lfloor>a\<rfloor> = \<lfloor>x\<rfloor>"
59192
a1d6d6db781b modernized historic example;
wenzelm
parents: 58881
diff changeset
   147
    then have "a \<sim> x" ..
a1d6d6db781b modernized historic example;
wenzelm
parents: 58881
diff changeset
   148
    then show "x \<sim> a" ..
10250
ca93fe25a84b Quotient types;
wenzelm
parents:
diff changeset
   149
  qed
ca93fe25a84b Quotient types;
wenzelm
parents:
diff changeset
   150
qed
ca93fe25a84b Quotient types;
wenzelm
parents:
diff changeset
   151
10483
eb93ace45a6e removed quot_cond_function1, quot_function1;
wenzelm
parents: 10477
diff changeset
   152
theorem pick_inverse [intro]: "\<lfloor>pick A\<rfloor> = A"
10250
ca93fe25a84b Quotient types;
wenzelm
parents:
diff changeset
   153
proof (cases A)
ca93fe25a84b Quotient types;
wenzelm
parents:
diff changeset
   154
  fix a assume a: "A = \<lfloor>a\<rfloor>"
23373
ead82c82da9e tuned proofs: avoid implicit prems;
wenzelm
parents: 22473
diff changeset
   155
  then have "pick A \<sim> a" by (simp only: pick_equiv)
ead82c82da9e tuned proofs: avoid implicit prems;
wenzelm
parents: 22473
diff changeset
   156
  then have "\<lfloor>pick A\<rfloor> = \<lfloor>a\<rfloor>" ..
10250
ca93fe25a84b Quotient types;
wenzelm
parents:
diff changeset
   157
  with a show ?thesis by simp
ca93fe25a84b Quotient types;
wenzelm
parents:
diff changeset
   158
qed
ca93fe25a84b Quotient types;
wenzelm
parents:
diff changeset
   159
59192
a1d6d6db781b modernized historic example;
wenzelm
parents: 58881
diff changeset
   160
text \<open>The following rules support canonical function definitions on quotient
a1d6d6db781b modernized historic example;
wenzelm
parents: 58881
diff changeset
   161
  types (with up to two arguments). Note that the stripped-down version
a1d6d6db781b modernized historic example;
wenzelm
parents: 58881
diff changeset
   162
  without additional conditions is sufficient most of the time.\<close>
10285
6949e17f314a simplified quotients (only plain total equivs);
wenzelm
parents: 10278
diff changeset
   163
10483
eb93ace45a6e removed quot_cond_function1, quot_function1;
wenzelm
parents: 10477
diff changeset
   164
theorem quot_cond_function:
59192
a1d6d6db781b modernized historic example;
wenzelm
parents: 58881
diff changeset
   165
  assumes eq: "\<And>X Y. P X Y \<Longrightarrow> f X Y \<equiv> g (pick X) (pick Y)"
a1d6d6db781b modernized historic example;
wenzelm
parents: 58881
diff changeset
   166
    and cong: "\<And>x x' y y'. \<lfloor>x\<rfloor> = \<lfloor>x'\<rfloor> \<Longrightarrow> \<lfloor>y\<rfloor> = \<lfloor>y'\<rfloor>
a1d6d6db781b modernized historic example;
wenzelm
parents: 58881
diff changeset
   167
      \<Longrightarrow> P \<lfloor>x\<rfloor> \<lfloor>y\<rfloor> \<Longrightarrow> P \<lfloor>x'\<rfloor> \<lfloor>y'\<rfloor> \<Longrightarrow> g x y = g x' y'"
18372
2bffdf62fe7f tuned proofs;
wenzelm
parents: 15140
diff changeset
   168
    and P: "P \<lfloor>a\<rfloor> \<lfloor>b\<rfloor>"
2bffdf62fe7f tuned proofs;
wenzelm
parents: 15140
diff changeset
   169
  shows "f \<lfloor>a\<rfloor> \<lfloor>b\<rfloor> = g a b"
10473
4f15b844fea6 separate rules for function/operation definitions;
wenzelm
parents: 10459
diff changeset
   170
proof -
18372
2bffdf62fe7f tuned proofs;
wenzelm
parents: 15140
diff changeset
   171
  from eq and P have "f \<lfloor>a\<rfloor> \<lfloor>b\<rfloor> = g (pick \<lfloor>a\<rfloor>) (pick \<lfloor>b\<rfloor>)" by (simp only:)
10505
b89e6cc963e3 unsymbolize;
wenzelm
parents: 10499
diff changeset
   172
  also have "... = g a b"
10491
e4a408728012 quot_cond_function: simplified, support conditional definition;
wenzelm
parents: 10483
diff changeset
   173
  proof (rule cong)
10483
eb93ace45a6e removed quot_cond_function1, quot_function1;
wenzelm
parents: 10477
diff changeset
   174
    show "\<lfloor>pick \<lfloor>a\<rfloor>\<rfloor> = \<lfloor>a\<rfloor>" ..
eb93ace45a6e removed quot_cond_function1, quot_function1;
wenzelm
parents: 10477
diff changeset
   175
    moreover
eb93ace45a6e removed quot_cond_function1, quot_function1;
wenzelm
parents: 10477
diff changeset
   176
    show "\<lfloor>pick \<lfloor>b\<rfloor>\<rfloor> = \<lfloor>b\<rfloor>" ..
10491
e4a408728012 quot_cond_function: simplified, support conditional definition;
wenzelm
parents: 10483
diff changeset
   177
    moreover
23373
ead82c82da9e tuned proofs: avoid implicit prems;
wenzelm
parents: 22473
diff changeset
   178
    show "P \<lfloor>a\<rfloor> \<lfloor>b\<rfloor>" by (rule P)
10491
e4a408728012 quot_cond_function: simplified, support conditional definition;
wenzelm
parents: 10483
diff changeset
   179
    ultimately show "P \<lfloor>pick \<lfloor>a\<rfloor>\<rfloor> \<lfloor>pick \<lfloor>b\<rfloor>\<rfloor>" by (simp only:)
10285
6949e17f314a simplified quotients (only plain total equivs);
wenzelm
parents: 10278
diff changeset
   180
  qed
6949e17f314a simplified quotients (only plain total equivs);
wenzelm
parents: 10278
diff changeset
   181
  finally show ?thesis .
6949e17f314a simplified quotients (only plain total equivs);
wenzelm
parents: 10278
diff changeset
   182
qed
6949e17f314a simplified quotients (only plain total equivs);
wenzelm
parents: 10278
diff changeset
   183
10483
eb93ace45a6e removed quot_cond_function1, quot_function1;
wenzelm
parents: 10477
diff changeset
   184
theorem quot_function:
59192
a1d6d6db781b modernized historic example;
wenzelm
parents: 58881
diff changeset
   185
  assumes "\<And>X Y. f X Y \<equiv> g (pick X) (pick Y)"
a1d6d6db781b modernized historic example;
wenzelm
parents: 58881
diff changeset
   186
    and "\<And>x x' y y'. \<lfloor>x\<rfloor> = \<lfloor>x'\<rfloor> \<Longrightarrow> \<lfloor>y\<rfloor> = \<lfloor>y'\<rfloor> \<Longrightarrow> g x y = g x' y'"
18372
2bffdf62fe7f tuned proofs;
wenzelm
parents: 15140
diff changeset
   187
  shows "f \<lfloor>a\<rfloor> \<lfloor>b\<rfloor> = g a b"
23394
474ff28210c0 tuned proofs;
wenzelm
parents: 23373
diff changeset
   188
  using assms and TrueI
18372
2bffdf62fe7f tuned proofs;
wenzelm
parents: 15140
diff changeset
   189
  by (rule quot_cond_function)
10285
6949e17f314a simplified quotients (only plain total equivs);
wenzelm
parents: 10278
diff changeset
   190
10499
2f33d0fd242e alternative function definition;
bauerg
parents: 10491
diff changeset
   191
theorem quot_function':
59192
a1d6d6db781b modernized historic example;
wenzelm
parents: 58881
diff changeset
   192
  "(\<And>X Y. f X Y \<equiv> g (pick X) (pick Y)) \<Longrightarrow>
a1d6d6db781b modernized historic example;
wenzelm
parents: 58881
diff changeset
   193
    (\<And>x x' y y'. x \<sim> x' \<Longrightarrow> y \<sim> y' \<Longrightarrow> g x y = g x' y') \<Longrightarrow>
10499
2f33d0fd242e alternative function definition;
bauerg
parents: 10491
diff changeset
   194
    f \<lfloor>a\<rfloor> \<lfloor>b\<rfloor> = g a b"
18372
2bffdf62fe7f tuned proofs;
wenzelm
parents: 15140
diff changeset
   195
  by (rule quot_function) (simp_all only: quot_equality)
10499
2f33d0fd242e alternative function definition;
bauerg
parents: 10491
diff changeset
   196
10250
ca93fe25a84b Quotient types;
wenzelm
parents:
diff changeset
   197
end