# HG changeset patch # User wenzelm # Date 972245920 -7200 # Node ID 6949e17f314aea35cd1be67351763d3fd1b54ee1 # Parent ec98fc455272244c6afcfcc8fbf7c093d0b6d909 simplified quotients (only plain total equivs); diff -r ec98fc455272 -r 6949e17f314a src/HOL/Library/Quotient.thy --- a/src/HOL/Library/Quotient.thy Fri Oct 20 19:46:53 2000 +0200 +++ b/src/HOL/Library/Quotient.thy Sun Oct 22 22:18:40 2000 +0200 @@ -11,149 +11,32 @@ theory Quotient = Main: text {* - Higher-order quotients are defined over partial equivalence relations - (PERs) instead of total ones. We provide axiomatic type classes - @{text "equiv < partial_equiv"} and a type constructor - @{text "'a quot"} with basic operations. Note that conventional - quotient constructions emerge as a special case. This development is - loosely based on \cite{Slotosch:1997}. -*} - - -subsection {* Equivalence relations *} - -subsubsection {* Partial equivalence *} - -text {* - Type class @{text partial_equiv} models partial equivalence relations - (PERs) using the polymorphic @{text "\ :: 'a => 'a => bool"} relation, - which is required to be symmetric and transitive, but not necessarily - reflexive. -*} - -consts - eqv :: "'a => 'a => bool" (infixl "\" 50) - -axclass partial_equiv < "term" - eqv_sym [elim?]: "x \ y ==> y \ x" - eqv_trans [trans]: "x \ y ==> y \ z ==> x \ z" - -text {* - \medskip The domain of a partial equivalence relation is the set of - reflexive elements. Due to symmetry and transitivity this - characterizes exactly those elements that are connected with - \emph{any} other one. + We introduce the notion of quotient types over equivalence relations + via axiomatic type classes. *} -constdefs - domain :: "'a::partial_equiv set" - "domain == {x. x \ x}" - -lemma domainI [intro]: "x \ x ==> x \ domain" - by (unfold domain_def) blast - -lemma domainD [dest]: "x \ domain ==> x \ x" - by (unfold domain_def) blast - -theorem domainI' [elim?]: "x \ y ==> x \ domain" -proof - assume xy: "x \ y" - also from xy have "y \ x" .. - finally show "x \ x" . -qed - - -subsubsection {* Equivalence on function spaces *} - -text {* - The @{text \} relation is lifted to function spaces. It is - important to note that this is \emph{not} the direct product, but a - structural one corresponding to the congruence property. -*} - -defs (overloaded) - eqv_fun_def: "f \ g == \x \ domain. \y \ domain. x \ y --> f x \ g y" - -lemma partial_equiv_funI [intro?]: - "(!!x y. x \ domain ==> y \ domain ==> x \ y ==> f x \ g y) ==> f \ g" - by (unfold eqv_fun_def) blast - -lemma partial_equiv_funD [dest?]: - "f \ g ==> x \ domain ==> y \ domain ==> x \ y ==> f x \ g y" - by (unfold eqv_fun_def) blast +subsection {* Equivalence relations and quotient types *} text {* - The class of partial equivalence relations is closed under function - spaces (in \emph{both} argument positions). + \medskip Type class @{text equiv} models equivalence relations using + the polymorphic @{text "\ :: 'a => 'a => bool"} relation. *} -instance fun :: (partial_equiv, partial_equiv) partial_equiv -proof intro_classes - fix f g h :: "'a::partial_equiv => 'b::partial_equiv" - assume fg: "f \ g" - show "g \ f" - proof - fix x y :: 'a - assume x: "x \ domain" and y: "y \ domain" - assume "x \ y" hence "y \ x" .. - with fg y x have "f y \ g x" .. - thus "g x \ f y" .. - qed - assume gh: "g \ h" - show "f \ h" - proof - fix x y :: 'a - assume x: "x \ domain" and y: "y \ domain" and "x \ y" - with fg have "f x \ g y" .. - also from y have "y \ y" .. - with gh y y have "g y \ h y" .. - finally show "f x \ h y" . - qed -qed +axclass eqv < "term" +consts + eqv :: "('a::eqv) => 'a => bool" (infixl "\" 50) - -subsubsection {* Total equivalence *} +axclass equiv < eqv + eqv_refl [intro]: "x \ x" + eqv_trans [trans]: "x \ y ==> y \ z ==> x \ z" + eqv_sym [elim?]: "x \ y ==> y \ x" text {* - The class of total equivalence relations on top of PERs. It - coincides with the standard notion of equivalence, i.e.\ - @{text "\ :: 'a => 'a => bool"} is required to be reflexive, transitive - and symmetric. -*} - -axclass equiv < partial_equiv - eqv_refl [intro]: "x \ x" - -text {* - On total equivalences all elements are reflexive, and congruence - holds unconditionally. + \medskip The quotient type @{text "'a quot"} consists of all + \emph{equivalence classes} over elements of the base type @{typ 'a}. *} -theorem equiv_domain [intro]: "(x::'a::equiv) \ domain" -proof - show "x \ x" .. -qed - -theorem equiv_cong [dest?]: "f \ g ==> x \ y ==> f x \ g (y::'a::equiv)" -proof - - assume "f \ g" - moreover have "x \ domain" .. - moreover have "y \ domain" .. - moreover assume "x \ y" - ultimately show ?thesis .. -qed - - -subsection {* Quotient types *} - -subsubsection {* General quotients and equivalence classes *} - -text {* - The quotient type @{text "'a quot"} consists of all \emph{equivalence - classes} over elements of the base type @{typ 'a}. -*} - -typedef 'a quot = "{{x. a \ x}| a::'a. True}" +typedef 'a quot = "{{x. a \ x}| a::'a::eqv. True}" by blast lemma quotI [intro]: "{x. a \ x} \ quot" @@ -168,7 +51,7 @@ *} constdefs - eqv_class :: "('a::partial_equiv) => 'a quot" ("\_\") + equivalence_class :: "'a::equiv => 'a quot" ("\_\") "\a\ == Abs_quot {x. a \ x}" theorem quot_rep: "\a. A = \a\" @@ -176,7 +59,7 @@ fix R assume R: "A = Abs_quot R" assume "R \ quot" hence "\a. R = {x. a \ x}" by blast with R have "\a. A = Abs_quot {x. a \ x}" by blast - thus ?thesis by (unfold eqv_class_def) + thus ?thesis by (unfold equivalence_class_def) qed lemma quot_cases [case_names rep, cases type: quot]: @@ -184,83 +67,105 @@ by (insert quot_rep) blast -subsubsection {* Equality on quotients *} +subsection {* Equality on quotients *} text {* Equality of canonical quotient elements corresponds to the original relation as follows. *} -theorem eqv_class_eqI [intro]: "a \ b ==> \a\ = \b\" -proof - +theorem equivalence_class_eq [iff?]: "(\a\ = \b\) = (a \ b)" +proof + assume eq: "\a\ = \b\" + show "a \ b" + proof - + from eq have "{x. a \ x} = {x. b \ x}" + by (simp only: equivalence_class_def Abs_quot_inject quotI) + moreover have "a \ a" .. + ultimately have "a \ {x. b \ x}" by blast + hence "b \ a" by blast + thus ?thesis .. + qed +next assume ab: "a \ b" - have "{x. a \ x} = {x. b \ x}" - proof (rule Collect_cong) - fix x show "(a \ x) = (b \ x)" - proof - from ab have "b \ a" .. - also assume "a \ x" - finally show "b \ x" . - next - note ab - also assume "b \ x" - finally show "a \ x" . + show "\a\ = \b\" + proof - + have "{x. a \ x} = {x. b \ x}" + proof (rule Collect_cong) + fix x show "(a \ x) = (b \ x)" + proof + from ab have "b \ a" .. + also assume "a \ x" + finally show "b \ x" . + next + note ab + also assume "b \ x" + finally show "a \ x" . + qed qed + thus ?thesis by (simp only: equivalence_class_def) qed - thus ?thesis by (simp only: eqv_class_def) qed -theorem eqv_class_eqD' [dest?]: "\a\ = \b\ ==> a \ domain ==> a \ b" (* FIXME [dest] would cause trouble with blast due to overloading *) -proof (unfold eqv_class_def) - assume "Abs_quot {x. a \ x} = Abs_quot {x. b \ x}" - hence "{x. a \ x} = {x. b \ x}" by (simp only: Abs_quot_inject quotI) - moreover assume "a \ domain" hence "a \ a" .. - ultimately have "a \ {x. b \ x}" by blast - hence "b \ a" by blast - thus "a \ b" .. -qed -theorem eqv_class_eqD [dest?]: "\a\ = \b\ ==> a \ (b::'a::equiv)" (* FIXME [dest] would cause trouble with blast due to overloading *) -proof (rule eqv_class_eqD') - show "a \ domain" .. -qed - -lemma eqv_class_eq' [simp]: "a \ domain ==> (\a\ = \b\) = (a \ b)" - by (insert eqv_class_eqI eqv_class_eqD') blast - -lemma eqv_class_eq [simp]: "(\a\ = \b\) = (a \ (b::'a::equiv))" - by (insert eqv_class_eqI eqv_class_eqD) blast - - -subsubsection {* Picking representing elements *} +subsection {* Picking representing elements *} constdefs - pick :: "'a::partial_equiv quot => 'a" + pick :: "'a::equiv quot => 'a" "pick A == SOME a. A = \a\" -theorem pick_eqv' [intro?, simp]: "a \ domain ==> pick \a\ \ a" (* FIXME [intro] !? *) +theorem pick_equiv [intro]: "pick \a\ \ a" proof (unfold pick_def) - assume a: "a \ domain" show "(SOME x. \a\ = \x\) \ a" proof (rule someI2) show "\a\ = \a\" .. fix x assume "\a\ = \x\" - hence "a \ x" .. - thus "x \ a" .. + hence "a \ x" .. thus "x \ a" .. qed qed -theorem pick_eqv [intro, simp]: "pick \a\ \ (a::'a::equiv)" -proof (rule pick_eqv') - show "a \ domain" .. -qed - -theorem pick_inverse: "\pick A\ = (A::'a::equiv quot)" +theorem pick_inverse: "\pick A\ = A" proof (cases A) fix a assume a: "A = \a\" - hence "pick A \ a" by simp - hence "\pick A\ = \a\" by simp + hence "pick A \ a" by (simp only: pick_equiv) + hence "\pick A\ = \a\" .. with a show ?thesis by simp qed +text {* + \medskip The following rules support canonical function definitions + on quotient types. +*} + +theorem cong_definition1: + "(!!X. f X == g (pick X)) ==> + (!!x x'. x \ x' ==> g x = g x') ==> + f \a\ = g a" +proof - + assume cong: "!!x x'. x \ x' ==> g x = g x'" + assume "!!X. f X == g (pick X)" + hence "f \a\ = g (pick \a\)" by (simp only:) + also have "\ = g a" + proof (rule cong) + show "pick \a\ \ a" .. + qed + finally show ?thesis . +qed + +theorem cong_definition2: + "(!!X Y. f X Y == g (pick X) (pick Y)) ==> + (!!x x' y y'. x \ x' ==> y \ y' ==> g x y = g x' y') ==> + f \a\ \b\ = g a b" +proof - + assume cong: "!!x x' y y'. x \ x' ==> y \ y' ==> g x y = g x' y'" + assume "!!X Y. f X Y == g (pick X) (pick Y)" + hence "f \a\ \b\ = g (pick \a\) (pick \b\)" by (simp only:) + also have "\ = g a b" + proof (rule cong) + show "pick \a\ \ a" .. + show "pick \b\ \ b" .. + qed + finally show ?thesis . +qed + end diff -r ec98fc455272 -r 6949e17f314a src/HOL/Library/document/root.bib --- a/src/HOL/Library/document/root.bib Fri Oct 20 19:46:53 2000 +0200 +++ b/src/HOL/Library/document/root.bib Sun Oct 22 22:18:40 2000 +0200 @@ -1,8 +1,3 @@ - -@InProceedings{Slotosch:1997, - author = {Oscar Slotosch}, - title = {Higher Order Quotients and their Implementation in {Isabelle HOL}}, - crossref = {tphols97}} @InProceedings{paulin-tlca, author = {Christine Paulin-Mohring}, @@ -18,10 +13,3 @@ year = 1993, publisher = {Springer}, series = {LNCS 664}} - -@Proceedings{tphols97, - title = {Theorem Proving in Higher Order Logics: {TPHOLs} '97}, - booktitle = {Theorem Proving in Higher Order Logics: {TPHOLs} '97}, - editor = {Elsa L. Gunter and Amy Felty}, - series = {LNCS 1275}, - year = 1997}