47 definition |
47 definition |
48 "domain" :: "'a::partial_equiv set" |
48 "domain" :: "'a::partial_equiv set" |
49 "domain = {x. x \<sim> x}" |
49 "domain = {x. x \<sim> x}" |
50 |
50 |
51 lemma domainI [intro]: "x \<sim> x ==> x \<in> domain" |
51 lemma domainI [intro]: "x \<sim> x ==> x \<in> domain" |
52 by (unfold domain_def) blast |
52 unfolding domain_def by blast |
53 |
53 |
54 lemma domainD [dest]: "x \<in> domain ==> x \<sim> x" |
54 lemma domainD [dest]: "x \<in> domain ==> x \<sim> x" |
55 by (unfold domain_def) blast |
55 unfolding domain_def by blast |
56 |
56 |
57 theorem domainI' [elim?]: "x \<sim> y ==> x \<in> domain" |
57 theorem domainI' [elim?]: "x \<sim> y ==> x \<in> domain" |
58 proof |
58 proof |
59 assume xy: "x \<sim> y" |
59 assume xy: "x \<sim> y" |
60 also from xy have "y \<sim> x" .. |
60 also from xy have "y \<sim> x" .. |
73 defs (overloaded) |
73 defs (overloaded) |
74 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" |
75 |
75 |
76 lemma partial_equiv_funI [intro?]: |
76 lemma partial_equiv_funI [intro?]: |
77 "(!!x y. x \<in> domain ==> y \<in> domain ==> x \<sim> y ==> f x \<sim> g y) ==> f \<sim> g" |
77 "(!!x y. x \<in> domain ==> y \<in> domain ==> x \<sim> y ==> f x \<sim> g y) ==> f \<sim> g" |
78 by (unfold eqv_fun_def) blast |
78 unfolding eqv_fun_def by blast |
79 |
79 |
80 lemma partial_equiv_funD [dest?]: |
80 lemma partial_equiv_funD [dest?]: |
81 "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" |
82 by (unfold eqv_fun_def) blast |
82 unfolding eqv_fun_def by blast |
83 |
83 |
84 text {* |
84 text {* |
85 The class of partial equivalence relations is closed under function |
85 The class of partial equivalence relations is closed under function |
86 spaces (in \emph{both} argument positions). |
86 spaces (in \emph{both} argument positions). |
87 *} |
87 *} |
88 |
88 |
89 instance fun :: (partial_equiv, partial_equiv) partial_equiv |
89 instance "fun" :: (partial_equiv, partial_equiv) partial_equiv |
90 proof |
90 proof |
91 fix f g h :: "'a::partial_equiv => 'b::partial_equiv" |
91 fix f g h :: "'a::partial_equiv => 'b::partial_equiv" |
92 assume fg: "f \<sim> g" |
92 assume fg: "f \<sim> g" |
93 show "g \<sim> f" |
93 show "g \<sim> f" |
94 proof |
94 proof |
95 fix x y :: 'a |
95 fix x y :: 'a |
96 assume x: "x \<in> domain" and y: "y \<in> domain" |
96 assume x: "x \<in> domain" and y: "y \<in> domain" |
97 assume "x \<sim> y" hence "y \<sim> x" .. |
97 assume "x \<sim> y" then have "y \<sim> x" .. |
98 with fg y x have "f y \<sim> g x" .. |
98 with fg y x have "f y \<sim> g x" .. |
99 thus "g x \<sim> f y" .. |
99 then show "g x \<sim> f y" .. |
100 qed |
100 qed |
101 assume gh: "g \<sim> h" |
101 assume gh: "g \<sim> h" |
102 show "f \<sim> h" |
102 show "f \<sim> h" |
103 proof |
103 proof |
104 fix x y :: 'a |
104 fix x y :: 'a |
152 |
152 |
153 typedef 'a quot = "{{x. a \<sim> x}| a::'a. True}" |
153 typedef 'a quot = "{{x. a \<sim> x}| a::'a. True}" |
154 by blast |
154 by blast |
155 |
155 |
156 lemma quotI [intro]: "{x. a \<sim> x} \<in> quot" |
156 lemma quotI [intro]: "{x. a \<sim> x} \<in> quot" |
157 by (unfold quot_def) blast |
157 unfolding quot_def by blast |
158 |
158 |
159 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" |
160 by (unfold quot_def) blast |
160 unfolding quot_def by blast |
161 |
161 |
162 text {* |
162 text {* |
163 \medskip Abstracted equivalence classes are the canonical |
163 \medskip Abstracted equivalence classes are the canonical |
164 representation of elements of a quotient type. |
164 representation of elements of a quotient type. |
165 *} |
165 *} |
169 "\<lfloor>a\<rfloor> = Abs_quot {x. a \<sim> x}" |
169 "\<lfloor>a\<rfloor> = Abs_quot {x. a \<sim> x}" |
170 |
170 |
171 theorem quot_rep: "\<exists>a. A = \<lfloor>a\<rfloor>" |
171 theorem quot_rep: "\<exists>a. A = \<lfloor>a\<rfloor>" |
172 proof (cases A) |
172 proof (cases A) |
173 fix R assume R: "A = Abs_quot R" |
173 fix R assume R: "A = Abs_quot R" |
174 assume "R \<in> quot" hence "\<exists>a. R = {x. a \<sim> x}" by blast |
174 assume "R \<in> quot" then have "\<exists>a. R = {x. a \<sim> x}" by blast |
175 with R have "\<exists>a. A = Abs_quot {x. a \<sim> x}" by blast |
175 with R have "\<exists>a. A = Abs_quot {x. a \<sim> x}" by blast |
176 thus ?thesis by (unfold eqv_class_def) |
176 then show ?thesis by (unfold eqv_class_def) |
177 qed |
177 qed |
178 |
178 |
179 lemma quot_cases [case_names rep, cases type: quot]: |
179 lemma quot_cases [cases type: quot]: |
180 "(!!a. A = \<lfloor>a\<rfloor> ==> C) ==> C" |
180 obtains (rep) a where "A = \<lfloor>a\<rfloor>" |
181 by (insert quot_rep) blast |
181 using quot_rep by blast |
182 |
182 |
183 |
183 |
184 subsection {* Equality on quotients *} |
184 subsection {* Equality on quotients *} |
185 |
185 |
186 text {* |
186 text {* |
202 note ab |
202 note ab |
203 also assume "b \<sim> x" |
203 also assume "b \<sim> x" |
204 finally show "a \<sim> x" . |
204 finally show "a \<sim> x" . |
205 qed |
205 qed |
206 qed |
206 qed |
207 thus ?thesis by (simp only: eqv_class_def) |
207 then show ?thesis by (simp only: eqv_class_def) |
208 qed |
208 qed |
209 |
209 |
210 theorem eqv_class_eqD' [dest?]: "\<lfloor>a\<rfloor> = \<lfloor>b\<rfloor> ==> a \<in> domain ==> a \<sim> b" |
210 theorem eqv_class_eqD' [dest?]: "\<lfloor>a\<rfloor> = \<lfloor>b\<rfloor> ==> a \<in> domain ==> a \<sim> b" |
211 proof (unfold eqv_class_def) |
211 proof (unfold eqv_class_def) |
212 assume "Abs_quot {x. a \<sim> x} = Abs_quot {x. b \<sim> x}" |
212 assume "Abs_quot {x. a \<sim> x} = Abs_quot {x. b \<sim> x}" |
213 hence "{x. a \<sim> x} = {x. b \<sim> x}" by (simp only: Abs_quot_inject quotI) |
213 then have "{x. a \<sim> x} = {x. b \<sim> x}" by (simp only: Abs_quot_inject quotI) |
214 moreover assume "a \<in> domain" hence "a \<sim> a" .. |
214 moreover assume "a \<in> domain" then have "a \<sim> a" .. |
215 ultimately have "a \<in> {x. b \<sim> x}" by blast |
215 ultimately have "a \<in> {x. b \<sim> x}" by blast |
216 hence "b \<sim> a" by blast |
216 then have "b \<sim> a" by blast |
217 thus "a \<sim> b" .. |
217 then show "a \<sim> b" .. |
218 qed |
218 qed |
219 |
219 |
220 theorem eqv_class_eqD [dest?]: "\<lfloor>a\<rfloor> = \<lfloor>b\<rfloor> ==> a \<sim> (b::'a::equiv)" |
220 theorem eqv_class_eqD [dest?]: "\<lfloor>a\<rfloor> = \<lfloor>b\<rfloor> ==> a \<sim> (b::'a::equiv)" |
221 proof (rule eqv_class_eqD') |
221 proof (rule eqv_class_eqD') |
222 show "a \<in> domain" .. |
222 show "a \<in> domain" .. |
223 qed |
223 qed |
224 |
224 |
225 lemma eqv_class_eq' [simp]: "a \<in> domain ==> (\<lfloor>a\<rfloor> = \<lfloor>b\<rfloor>) = (a \<sim> b)" |
225 lemma eqv_class_eq' [simp]: "a \<in> domain ==> (\<lfloor>a\<rfloor> = \<lfloor>b\<rfloor>) = (a \<sim> b)" |
226 by (insert eqv_class_eqI eqv_class_eqD') blast |
226 using eqv_class_eqI eqv_class_eqD' by blast |
227 |
227 |
228 lemma eqv_class_eq [simp]: "(\<lfloor>a\<rfloor> = \<lfloor>b\<rfloor>) = (a \<sim> (b::'a::equiv))" |
228 lemma eqv_class_eq [simp]: "(\<lfloor>a\<rfloor> = \<lfloor>b\<rfloor>) = (a \<sim> (b::'a::equiv))" |
229 by (insert eqv_class_eqI eqv_class_eqD) blast |
229 using eqv_class_eqI eqv_class_eqD by blast |
230 |
230 |
231 |
231 |
232 subsection {* Picking representing elements *} |
232 subsection {* Picking representing elements *} |
233 |
233 |
234 definition |
234 definition |
240 assume a: "a \<in> domain" |
240 assume a: "a \<in> domain" |
241 show "(SOME x. \<lfloor>a\<rfloor> = \<lfloor>x\<rfloor>) \<sim> a" |
241 show "(SOME x. \<lfloor>a\<rfloor> = \<lfloor>x\<rfloor>) \<sim> a" |
242 proof (rule someI2) |
242 proof (rule someI2) |
243 show "\<lfloor>a\<rfloor> = \<lfloor>a\<rfloor>" .. |
243 show "\<lfloor>a\<rfloor> = \<lfloor>a\<rfloor>" .. |
244 fix x assume "\<lfloor>a\<rfloor> = \<lfloor>x\<rfloor>" |
244 fix x assume "\<lfloor>a\<rfloor> = \<lfloor>x\<rfloor>" |
245 hence "a \<sim> x" .. |
245 then have "a \<sim> x" .. |
246 thus "x \<sim> a" .. |
246 then show "x \<sim> a" .. |
247 qed |
247 qed |
248 qed |
248 qed |
249 |
249 |
250 theorem pick_eqv [intro, simp]: "pick \<lfloor>a\<rfloor> \<sim> (a::'a::equiv)" |
250 theorem pick_eqv [intro, simp]: "pick \<lfloor>a\<rfloor> \<sim> (a::'a::equiv)" |
251 proof (rule pick_eqv') |
251 proof (rule pick_eqv') |
253 qed |
253 qed |
254 |
254 |
255 theorem pick_inverse: "\<lfloor>pick A\<rfloor> = (A::'a::equiv quot)" |
255 theorem pick_inverse: "\<lfloor>pick A\<rfloor> = (A::'a::equiv quot)" |
256 proof (cases A) |
256 proof (cases A) |
257 fix a assume a: "A = \<lfloor>a\<rfloor>" |
257 fix a assume a: "A = \<lfloor>a\<rfloor>" |
258 hence "pick A \<sim> a" by simp |
258 then have "pick A \<sim> a" by simp |
259 hence "\<lfloor>pick A\<rfloor> = \<lfloor>a\<rfloor>" by simp |
259 then have "\<lfloor>pick A\<rfloor> = \<lfloor>a\<rfloor>" by simp |
260 with a show ?thesis by simp |
260 with a show ?thesis by simp |
261 qed |
261 qed |
262 |
262 |
263 end |
263 end |