6 header {* Partial equivalence relations *} |
6 header {* Partial equivalence relations *} |
7 |
7 |
8 theory PER = Main: |
8 theory PER = Main: |
9 |
9 |
10 text {* |
10 text {* |
11 Higher-order quotients are defined over partial equivalence relations |
11 Higher-order quotients are defined over partial equivalence |
12 (PERs) instead of total ones. We provide axiomatic type classes |
12 relations (PERs) instead of total ones. We provide axiomatic type |
13 @{text "equiv < partial_equiv"} and a type constructor |
13 classes @{text "equiv < partial_equiv"} and a type constructor |
14 @{text "'a quot"} with basic operations. This development is based |
14 @{text "'a quot"} with basic operations. This development is based |
15 on: |
15 on: |
16 |
16 |
17 Oscar Slotosch: \emph{Higher Order Quotients and their Implementation |
17 Oscar Slotosch: \emph{Higher Order Quotients and their |
18 in Isabelle HOL.} Elsa L. Gunter and Amy Felty, editors, Theorem |
18 Implementation in Isabelle HOL.} Elsa L. Gunter and Amy Felty, |
19 Proving in Higher Order Logics: TPHOLs '97, Springer LNCS 1275, 1997. |
19 editors, Theorem Proving in Higher Order Logics: TPHOLs '97, |
|
20 Springer LNCS 1275, 1997. |
20 *} |
21 *} |
21 |
22 |
22 |
23 |
23 subsection {* Partial equivalence *} |
24 subsection {* Partial equivalence *} |
24 |
25 |
25 text {* |
26 text {* |
26 Type class @{text partial_equiv} models partial equivalence relations |
27 Type class @{text partial_equiv} models partial equivalence |
27 (PERs) using the polymorphic @{text "\<sim> :: 'a => 'a => bool"} relation, |
28 relations (PERs) using the polymorphic @{text "\<sim> :: 'a => 'a => |
28 which is required to be symmetric and transitive, but not necessarily |
29 bool"} relation, which is required to be symmetric and transitive, |
29 reflexive. |
30 but not necessarily reflexive. |
30 *} |
31 *} |
31 |
32 |
32 consts |
33 consts |
33 eqv :: "'a => 'a => bool" (infixl "\<sim>" 50) |
34 eqv :: "'a => 'a => bool" (infixl "\<sim>" 50) |
34 |
35 |
35 axclass partial_equiv < "term" |
36 axclass partial_equiv < type |
36 partial_equiv_sym [elim?]: "x \<sim> y ==> y \<sim> x" |
37 partial_equiv_sym [elim?]: "x \<sim> y ==> y \<sim> x" |
37 partial_equiv_trans [trans]: "x \<sim> y ==> y \<sim> z ==> x \<sim> z" |
38 partial_equiv_trans [trans]: "x \<sim> y ==> y \<sim> z ==> x \<sim> z" |
38 |
39 |
39 text {* |
40 text {* |
40 \medskip The domain of a partial equivalence relation is the set of |
41 \medskip The domain of a partial equivalence relation is the set of |
41 reflexive elements. Due to symmetry and transitivity this |
42 reflexive elements. Due to symmetry and transitivity this |
42 characterizes exactly those elements that are connected with |
43 characterizes exactly those elements that are connected with |
43 \emph{any} other one. |
44 \emph{any} other one. |
44 *} |
45 *} |
45 |
46 |
46 constdefs |
47 constdefs |
47 domain :: "'a::partial_equiv set" |
48 domain :: "'a::partial_equiv set" |
48 "domain == {x. x \<sim> x}" |
49 "domain == {x. x \<sim> x}" |
62 |
63 |
63 |
64 |
64 subsection {* Equivalence on function spaces *} |
65 subsection {* Equivalence on function spaces *} |
65 |
66 |
66 text {* |
67 text {* |
67 The @{text \<sim>} relation is lifted to function spaces. It is |
68 The @{text \<sim>} relation is lifted to function spaces. It is |
68 important to note that this is \emph{not} the direct product, but a |
69 important to note that this is \emph{not} the direct product, but a |
69 structural one corresponding to the congruence property. |
70 structural one corresponding to the congruence property. |
70 *} |
71 *} |
71 |
72 |
72 defs (overloaded) |
73 defs (overloaded) |
73 eqv_fun_def: "f \<sim> g == \<forall>x \<in> domain. \<forall>y \<in> domain. x \<sim> y --> f x \<sim> g y" |
74 eqv_fun_def: "f \<sim> g == \<forall>x \<in> domain. \<forall>y \<in> domain. x \<sim> y --> f x \<sim> g y" |
74 |
75 |
79 lemma partial_equiv_funD [dest?]: |
80 lemma partial_equiv_funD [dest?]: |
80 "f \<sim> g ==> x \<in> domain ==> y \<in> domain ==> x \<sim> y ==> f x \<sim> g y" |
81 "f \<sim> g ==> x \<in> domain ==> y \<in> domain ==> x \<sim> y ==> f x \<sim> g y" |
81 by (unfold eqv_fun_def) blast |
82 by (unfold eqv_fun_def) blast |
82 |
83 |
83 text {* |
84 text {* |
84 The class of partial equivalence relations is closed under function |
85 The class of partial equivalence relations is closed under function |
85 spaces (in \emph{both} argument positions). |
86 spaces (in \emph{both} argument positions). |
86 *} |
87 *} |
87 |
88 |
88 instance fun :: (partial_equiv, partial_equiv) partial_equiv |
89 instance fun :: (partial_equiv, partial_equiv) partial_equiv |
89 proof |
90 proof |
90 fix f g h :: "'a::partial_equiv => 'b::partial_equiv" |
91 fix f g h :: "'a::partial_equiv => 'b::partial_equiv" |
111 |
112 |
112 |
113 |
113 subsection {* Total equivalence *} |
114 subsection {* Total equivalence *} |
114 |
115 |
115 text {* |
116 text {* |
116 The class of total equivalence relations on top of PERs. It |
117 The class of total equivalence relations on top of PERs. It |
117 coincides with the standard notion of equivalence, i.e.\ |
118 coincides with the standard notion of equivalence, i.e.\ @{text "\<sim> |
118 @{text "\<sim> :: 'a => 'a => bool"} is required to be reflexive, transitive |
119 :: 'a => 'a => bool"} is required to be reflexive, transitive and |
119 and symmetric. |
120 symmetric. |
120 *} |
121 *} |
121 |
122 |
122 axclass equiv < partial_equiv |
123 axclass equiv < partial_equiv |
123 eqv_refl [intro]: "x \<sim> x" |
124 eqv_refl [intro]: "x \<sim> x" |
124 |
125 |
125 text {* |
126 text {* |
126 On total equivalences all elements are reflexive, and congruence |
127 On total equivalences all elements are reflexive, and congruence |
127 holds unconditionally. |
128 holds unconditionally. |
128 *} |
129 *} |
129 |
130 |
130 theorem equiv_domain [intro]: "(x::'a::equiv) \<in> domain" |
131 theorem equiv_domain [intro]: "(x::'a::equiv) \<in> domain" |
131 proof |
132 proof |
132 show "x \<sim> x" .. |
133 show "x \<sim> x" .. |
157 |
158 |
158 lemma quotE [elim]: "R \<in> quot ==> (!!a. R = {x. a \<sim> x} ==> C) ==> C" |
159 lemma quotE [elim]: "R \<in> quot ==> (!!a. R = {x. a \<sim> x} ==> C) ==> C" |
159 by (unfold quot_def) blast |
160 by (unfold quot_def) blast |
160 |
161 |
161 text {* |
162 text {* |
162 \medskip Abstracted equivalence classes are the canonical |
163 \medskip Abstracted equivalence classes are the canonical |
163 representation of elements of a quotient type. |
164 representation of elements of a quotient type. |
164 *} |
165 *} |
165 |
166 |
166 constdefs |
167 constdefs |
167 eqv_class :: "('a::partial_equiv) => 'a quot" ("\<lfloor>_\<rfloor>") |
168 eqv_class :: "('a::partial_equiv) => 'a quot" ("\<lfloor>_\<rfloor>") |
168 "\<lfloor>a\<rfloor> == Abs_quot {x. a \<sim> x}" |
169 "\<lfloor>a\<rfloor> == Abs_quot {x. a \<sim> x}" |