merged
authorblanchet
Wed, 23 Jun 2010 10:20:54 +0200
changeset 37513 4dca51ef0285
parent 37494 6e9f48cf6adf (diff)
parent 37512 ff72d3ddc898 (current diff)
child 37514 b147d01b8ebc
merged
--- a/src/HOL/Library/Quotient_List.thy	Wed Jun 23 10:20:33 2010 +0200
+++ b/src/HOL/Library/Quotient_List.thy	Wed Jun 23 10:20:54 2010 +0200
@@ -8,15 +8,7 @@
 imports Main Quotient_Syntax
 begin
 
-fun
-  list_rel
-where
-  "list_rel R [] [] = True"
-| "list_rel R (x#xs) [] = False"
-| "list_rel R [] (x#xs) = False"
-| "list_rel R (x#xs) (y#ys) = (R x y \<and> list_rel R xs ys)"
-
-declare [[map list = (map, list_rel)]]
+declare [[map list = (map, list_all2)]]
 
 lemma split_list_all:
   shows "(\<forall>x. P x) \<longleftrightarrow> P [] \<and> (\<forall>x xs. P (x#xs))"
@@ -33,52 +25,47 @@
   apply(simp_all)
   done
 
+lemma list_all2_reflp:
+  shows "equivp R \<Longrightarrow> list_all2 R xs xs"
+  by (induct xs, simp_all add: equivp_reflp)
 
-lemma list_rel_reflp:
-  shows "equivp R \<Longrightarrow> list_rel R xs xs"
-  apply(induct xs)
-  apply(simp_all add: equivp_reflp)
-  done
-
-lemma list_rel_symp:
+lemma list_all2_symp:
   assumes a: "equivp R"
-  shows "list_rel R xs ys \<Longrightarrow> list_rel R ys xs"
-  apply(induct xs ys rule: list_induct2')
+  and b: "list_all2 R xs ys"
+  shows "list_all2 R ys xs"
+  using list_all2_lengthD[OF b] b
+  apply(induct xs ys rule: list_induct2)
   apply(simp_all)
   apply(rule equivp_symp[OF a])
   apply(simp)
   done
 
-lemma list_rel_transp:
+thm list_induct3
+
+lemma list_all2_transp:
   assumes a: "equivp R"
-  shows "list_rel R xs1 xs2 \<Longrightarrow> list_rel R xs2 xs3 \<Longrightarrow> list_rel R xs1 xs3"
-  using a
-  apply(induct R xs1 xs2 arbitrary: xs3 rule: list_rel.induct)
-  apply(simp)
-  apply(simp)
-  apply(simp)
-  apply(case_tac xs3)
-  apply(clarify)
-  apply(simp (no_asm_use))
-  apply(clarify)
-  apply(simp (no_asm_use))
-  apply(auto intro: equivp_transp)
+  and b: "list_all2 R xs1 xs2"
+  and c: "list_all2 R xs2 xs3"
+  shows "list_all2 R xs1 xs3"
+  using list_all2_lengthD[OF b] list_all2_lengthD[OF c] b c
+  apply(induct rule: list_induct3)
+  apply(simp_all)
+  apply(auto intro: equivp_transp[OF a])
   done
 
 lemma list_equivp[quot_equiv]:
   assumes a: "equivp R"
-  shows "equivp (list_rel R)"
-  apply(rule equivpI)
+  shows "equivp (list_all2 R)"
+  apply (intro equivpI)
   unfolding reflp_def symp_def transp_def
-  apply(subst split_list_all)
-  apply(simp add: equivp_reflp[OF a] list_rel_reflp[OF a])
-  apply(blast intro: list_rel_symp[OF a])
-  apply(blast intro: list_rel_transp[OF a])
+  apply(simp add: list_all2_reflp[OF a])
+  apply(blast intro: list_all2_symp[OF a])
+  apply(blast intro: list_all2_transp[OF a])
   done
 
-lemma list_rel_rel:
+lemma list_all2_rel:
   assumes q: "Quotient R Abs Rep"
-  shows "list_rel R r s = (list_rel R r r \<and> list_rel R s s \<and> (map Abs r = map Abs s))"
+  shows "list_all2 R r s = (list_all2 R r r \<and> list_all2 R s s \<and> (map Abs r = map Abs s))"
   apply(induct r s rule: list_induct2')
   apply(simp_all)
   using Quotient_rel[OF q]
@@ -87,21 +74,16 @@
 
 lemma list_quotient[quot_thm]:
   assumes q: "Quotient R Abs Rep"
-  shows "Quotient (list_rel R) (map Abs) (map Rep)"
+  shows "Quotient (list_all2 R) (map Abs) (map Rep)"
   unfolding Quotient_def
   apply(subst split_list_all)
   apply(simp add: Quotient_abs_rep[OF q] abs_o_rep[OF q] map_id)
-  apply(rule conjI)
-  apply(rule allI)
+  apply(intro conjI allI)
   apply(induct_tac a)
-  apply(simp)
-  apply(simp)
-  apply(simp add: Quotient_rep_reflp[OF q])
-  apply(rule allI)+
-  apply(rule list_rel_rel[OF q])
+  apply(simp_all add: Quotient_rep_reflp[OF q])
+  apply(rule list_all2_rel[OF q])
   done
 
-
 lemma cons_prs_aux:
   assumes q: "Quotient R Abs Rep"
   shows "(map Abs) ((Rep h) # (map Rep t)) = h # t"
@@ -115,7 +97,7 @@
 
 lemma cons_rsp[quot_respect]:
   assumes q: "Quotient R Abs Rep"
-  shows "(R ===> list_rel R ===> list_rel R) (op #) (op #)"
+  shows "(R ===> list_all2 R ===> list_all2 R) (op #) (op #)"
   by (auto)
 
 lemma nil_prs[quot_preserve]:
@@ -125,7 +107,7 @@
 
 lemma nil_rsp[quot_respect]:
   assumes q: "Quotient R Abs Rep"
-  shows "list_rel R [] []"
+  shows "list_all2 R [] []"
   by simp
 
 lemma map_prs_aux:
@@ -146,8 +128,8 @@
 lemma map_rsp[quot_respect]:
   assumes q1: "Quotient R1 Abs1 Rep1"
   and     q2: "Quotient R2 Abs2 Rep2"
-  shows "((R1 ===> R2) ===> (list_rel R1) ===> list_rel R2) map map"
-  and   "((R1 ===> op =) ===> (list_rel R1) ===> op =) map map"
+  shows "((R1 ===> R2) ===> (list_all2 R1) ===> list_all2 R2) map map"
+  and   "((R1 ===> op =) ===> (list_all2 R1) ===> op =) map map"
   apply simp_all
   apply(rule_tac [!] allI)+
   apply(rule_tac [!] impI)
@@ -183,53 +165,45 @@
   by (simp only: expand_fun_eq fun_map_def foldl_prs_aux[OF a b])
      (simp)
 
-lemma list_rel_empty:
-  shows "list_rel R [] b \<Longrightarrow> length b = 0"
+lemma list_all2_empty:
+  shows "list_all2 R [] b \<Longrightarrow> length b = 0"
   by (induct b) (simp_all)
 
-lemma list_rel_len:
-  shows "list_rel R a b \<Longrightarrow> length a = length b"
-  apply (induct a arbitrary: b)
-  apply (simp add: list_rel_empty)
-  apply (case_tac b)
-  apply simp_all
-  done
-
 (* induct_tac doesn't accept 'arbitrary', so we manually 'spec' *)
 lemma foldl_rsp[quot_respect]:
   assumes q1: "Quotient R1 Abs1 Rep1"
   and     q2: "Quotient R2 Abs2 Rep2"
-  shows "((R1 ===> R2 ===> R1) ===> R1 ===> list_rel R2 ===> R1) foldl foldl"
+  shows "((R1 ===> R2 ===> R1) ===> R1 ===> list_all2 R2 ===> R1) foldl foldl"
   apply(auto)
-  apply (subgoal_tac "R1 xa ya \<longrightarrow> list_rel R2 xb yb \<longrightarrow> R1 (foldl x xa xb) (foldl y ya yb)")
+  apply (subgoal_tac "R1 xa ya \<longrightarrow> list_all2 R2 xb yb \<longrightarrow> R1 (foldl x xa xb) (foldl y ya yb)")
   apply simp
   apply (rule_tac x="xa" in spec)
   apply (rule_tac x="ya" in spec)
   apply (rule_tac xs="xb" and ys="yb" in list_induct2)
-  apply (rule list_rel_len)
+  apply (rule list_all2_lengthD)
   apply (simp_all)
   done
 
 lemma foldr_rsp[quot_respect]:
   assumes q1: "Quotient R1 Abs1 Rep1"
   and     q2: "Quotient R2 Abs2 Rep2"
-  shows "((R1 ===> R2 ===> R2) ===> list_rel R1 ===> R2 ===> R2) foldr foldr"
+  shows "((R1 ===> R2 ===> R2) ===> list_all2 R1 ===> R2 ===> R2) foldr foldr"
   apply auto
-  apply(subgoal_tac "R2 xb yb \<longrightarrow> list_rel R1 xa ya \<longrightarrow> R2 (foldr x xa xb) (foldr y ya yb)")
+  apply(subgoal_tac "R2 xb yb \<longrightarrow> list_all2 R1 xa ya \<longrightarrow> R2 (foldr x xa xb) (foldr y ya yb)")
   apply simp
   apply (rule_tac xs="xa" and ys="ya" in list_induct2)
-  apply (rule list_rel_len)
+  apply (rule list_all2_lengthD)
   apply (simp_all)
   done
 
-lemma list_rel_rsp:
+lemma list_all2_rsp:
   assumes r: "\<forall>x y. R x y \<longrightarrow> (\<forall>a b. R a b \<longrightarrow> S x a = T y b)"
-  and l1: "list_rel R x y"
-  and l2: "list_rel R a b"
-  shows "list_rel S x a = list_rel T y b"
+  and l1: "list_all2 R x y"
+  and l2: "list_all2 R a b"
+  shows "list_all2 S x a = list_all2 T y b"
   proof -
-    have a: "length y = length x" by (rule list_rel_len[OF l1, symmetric])
-    have c: "length a = length b" by (rule list_rel_len[OF l2])
+    have a: "length y = length x" by (rule list_all2_lengthD[OF l1, symmetric])
+    have c: "length a = length b" by (rule list_all2_lengthD[OF l2])
     show ?thesis proof (cases "length x = length a")
       case True
       have b: "length x = length a" by fact
@@ -243,20 +217,20 @@
     next
       case False
       have d: "length x \<noteq> length a" by fact
-      then have e: "\<not>list_rel S x a" using list_rel_len by auto
+      then have e: "\<not>list_all2 S x a" using list_all2_lengthD by auto
       have "length y \<noteq> length b" using d a c by simp
-      then have "\<not>list_rel T y b" using list_rel_len by auto
+      then have "\<not>list_all2 T y b" using list_all2_lengthD by auto
       then show ?thesis using e by simp
     qed
   qed
 
 lemma[quot_respect]:
-  "((R ===> R ===> op =) ===> list_rel R ===> list_rel R ===> op =) list_rel list_rel"
-  by (simp add: list_rel_rsp)
+  "((R ===> R ===> op =) ===> list_all2 R ===> list_all2 R ===> op =) list_all2 list_all2"
+  by (simp add: list_all2_rsp)
 
 lemma[quot_preserve]:
   assumes a: "Quotient R abs1 rep1"
-  shows "((abs1 ---> abs1 ---> id) ---> map rep1 ---> map rep1 ---> id) list_rel = list_rel"
+  shows "((abs1 ---> abs1 ---> id) ---> map rep1 ---> map rep1 ---> id) list_all2 = list_all2"
   apply (simp add: expand_fun_eq)
   apply clarify
   apply (induct_tac xa xb rule: list_induct2')
@@ -265,29 +239,29 @@
 
 lemma[quot_preserve]:
   assumes a: "Quotient R abs1 rep1"
-  shows "(list_rel ((rep1 ---> rep1 ---> id) R) l m) = (l = m)"
+  shows "(list_all2 ((rep1 ---> rep1 ---> id) R) l m) = (l = m)"
   by (induct l m rule: list_induct2') (simp_all add: Quotient_rel_rep[OF a])
 
-lemma list_rel_eq[id_simps]:
-  shows "(list_rel (op =)) = (op =)"
+lemma list_all2_eq[id_simps]:
+  shows "(list_all2 (op =)) = (op =)"
   unfolding expand_fun_eq
   apply(rule allI)+
   apply(induct_tac x xa rule: list_induct2')
   apply(simp_all)
   done
 
-lemma list_rel_find_element:
+lemma list_all2_find_element:
   assumes a: "x \<in> set a"
-  and b: "list_rel R a b"
+  and b: "list_all2 R a b"
   shows "\<exists>y. (y \<in> set b \<and> R x y)"
 proof -
-  have "length a = length b" using b by (rule list_rel_len)
+  have "length a = length b" using b by (rule list_all2_lengthD)
   then show ?thesis using a b by (induct a b rule: list_induct2) auto
 qed
 
-lemma list_rel_refl:
+lemma list_all2_refl:
   assumes a: "\<And>x y. R x y = (R x = R y)"
-  shows "list_rel R x x"
+  shows "list_all2 R x x"
   by (induct x) (auto simp add: a)
 
 end
--- a/src/HOL/Multivariate_Analysis/Cartesian_Euclidean_Space.thy	Wed Jun 23 10:20:33 2010 +0200
+++ b/src/HOL/Multivariate_Analysis/Cartesian_Euclidean_Space.thy	Wed Jun 23 10:20:54 2010 +0200
@@ -975,12 +975,12 @@
   apply (subst matrix_vector_mul[OF lf])
   unfolding adjoint_matrix matrix_of_matrix_vector_mul ..
 
-section {* lambda_skolem on cartesian products *}
+section {* lambda skolemization on cartesian products *}
 
 (* FIXME: rename do choice_cart *)
 
 lemma lambda_skolem: "(\<forall>i. \<exists>x. P i x) \<longleftrightarrow>
-   (\<exists>x::'a ^ 'n. \<forall>i. P i (x$i))" (is "?lhs \<longleftrightarrow> ?rhs")
+   (\<exists>x::'a ^ 'n. \<forall>i. P i (x $ i))" (is "?lhs \<longleftrightarrow> ?rhs")
 proof-
   let ?S = "(UNIV :: 'n set)"
   {assume H: "?rhs"
@@ -991,7 +991,7 @@
     let ?x = "(\<chi> i. (f i)) :: 'a ^ 'n"
     {fix i
       from f have "P i (f i)" by metis
-      then have "P i (?x$i)" by auto
+      then have "P i (?x $ i)" by auto
     }
     hence "\<forall>i. P i (?x$i)" by metis
     hence ?rhs by metis }
@@ -1830,7 +1830,7 @@
     unfolding abs_mult diff_minus_eq_add scaleR.minus_left unfolding algebra_simps by (auto intro: mult_pos_pos)
 qed
 
-subsection {* Lemmas for working on real^1 *}
+subsection {* Lemmas for working on @{typ "real^1"} *}
 
 lemma forall_1[simp]: "(\<forall>i::1. P i) \<longleftrightarrow> P 1"
   by (metis num1_eq_iff)
--- a/src/HOL/Quotient.thy	Wed Jun 23 10:20:33 2010 +0200
+++ b/src/HOL/Quotient.thy	Wed Jun 23 10:20:54 2010 +0200
@@ -59,7 +59,7 @@
   unfolding equivp_def
   by auto
 
-text {* Partial equivalences: not yet used anywhere *}
+text {* Partial equivalences *}
 
 definition
   "part_equivp E \<equiv> (\<exists>x. E x x) \<and> (\<forall>x y. E x y = (E x x \<and> E y y \<and> (E x = E y)))"
@@ -71,6 +71,23 @@
   unfolding equivp_def part_equivp_def
   by auto
 
+lemma part_equivp_symp:
+  assumes e: "part_equivp R"
+  and a: "R x y"
+  shows "R y x"
+  using e[simplified part_equivp_def] a
+  by (metis)
+
+lemma part_equivp_typedef:
+  shows "part_equivp R \<Longrightarrow> \<exists>d. d \<in> (\<lambda>c. \<exists>x. R x x \<and> c = R x)"
+  unfolding part_equivp_def mem_def
+  apply clarify
+  apply (intro exI)
+  apply (rule conjI)
+  apply assumption
+  apply (rule refl)
+  done
+
 text {* Composition of Relations *}
 
 abbreviation
@@ -630,10 +647,10 @@
   fixes R :: "'a \<Rightarrow> 'a \<Rightarrow> bool"
   and   Abs :: "('a \<Rightarrow> bool) \<Rightarrow> 'b"
   and   Rep :: "'b \<Rightarrow> ('a \<Rightarrow> bool)"
-  assumes equivp: "equivp R"
-  and     rep_prop: "\<And>y. \<exists>x. Rep y = R x"
+  assumes equivp: "part_equivp R"
+  and     rep_prop: "\<And>y. \<exists>x. R x x \<and> Rep y = R x"
   and     rep_inverse: "\<And>x. Abs (Rep x) = x"
-  and     abs_inverse: "\<And>x. (Rep (Abs (R x))) = (R x)"
+  and     abs_inverse: "\<And>c. (\<exists>x. ((R x x) \<and> (c = R x))) \<Longrightarrow> (Rep (Abs c)) = c"
   and     rep_inject: "\<And>x y. (Rep x = Rep y) = (x = y)"
 begin
 
@@ -647,64 +664,46 @@
 where
   "rep a = Eps (Rep a)"
 
-lemma homeier_lem9:
-  shows "R (Eps (R x)) = R x"
-proof -
-  have a: "R x x" using equivp by (simp add: equivp_reflp_symp_transp reflp_def)
-  then have "R x (Eps (R x))" by (rule someI)
-  then show "R (Eps (R x)) = R x"
-    using equivp unfolding equivp_def by simp
-qed
-
-theorem homeier_thm10:
-  shows "abs (rep a) = a"
-  unfolding abs_def rep_def
-proof -
-  from rep_prop
-  obtain x where eq: "Rep a = R x" by auto
-  have "Abs (R (Eps (Rep a))) = Abs (R (Eps (R x)))" using eq by simp
-  also have "\<dots> = Abs (R x)" using homeier_lem9 by simp
-  also have "\<dots> = Abs (Rep a)" using eq by simp
-  also have "\<dots> = a" using rep_inverse by simp
-  finally
-  show "Abs (R (Eps (Rep a))) = a" by simp
-qed
+lemma homeier5:
+  assumes a: "R r r"
+  shows "Rep (Abs (R r)) = R r"
+  apply (subst abs_inverse)
+  using a by auto
 
-lemma homeier_lem7:
-  shows "(R x = R y) = (Abs (R x) = Abs (R y))" (is "?LHS = ?RHS")
-proof -
-  have "?RHS = (Rep (Abs (R x)) = Rep (Abs (R y)))" by (simp add: rep_inject)
-  also have "\<dots> = ?LHS" by (simp add: abs_inverse)
-  finally show "?LHS = ?RHS" by simp
-qed
+theorem homeier6:
+  assumes a: "R r r"
+  and b: "R s s"
+  shows "Abs (R r) = Abs (R s) \<longleftrightarrow> R r = R s"
+  by (metis a b homeier5)
 
-theorem homeier_thm11:
-  shows "R r r' = (abs r = abs r')"
-  unfolding abs_def
-  by (simp only: equivp[simplified equivp_def] homeier_lem7)
-
-lemma rep_refl:
-  shows "R (rep a) (rep a)"
-  unfolding rep_def
-  by (simp add: equivp[simplified equivp_def])
-
-
-lemma rep_abs_rsp:
-  shows "R f (rep (abs g)) = R f g"
-  and   "R (rep (abs g)) f = R g f"
-  by (simp_all add: homeier_thm10 homeier_thm11)
+theorem homeier8:
+  assumes "R r r"
+  shows "R (Eps (R r)) = R r"
+  using assms equivp[simplified part_equivp_def]
+  apply clarify
+  by (metis assms exE_some)
 
 lemma Quotient:
   shows "Quotient R abs rep"
-  unfolding Quotient_def
-  apply(simp add: homeier_thm10)
-  apply(simp add: rep_refl)
-  apply(subst homeier_thm11[symmetric])
-  apply(simp add: equivp[simplified equivp_def])
-  done
+  unfolding Quotient_def abs_def rep_def
+  proof (intro conjI allI)
+    fix a r s
+    show "Abs (R (Eps (Rep a))) = a"
+      by (metis equivp exE_some part_equivp_def rep_inverse rep_prop)
+    show "R r s \<longleftrightarrow> R r r \<and> R s s \<and> (Abs (R r) = Abs (R s))"
+      by (metis homeier6 equivp[simplified part_equivp_def])
+    show "R (Eps (Rep a)) (Eps (Rep a))" proof -
+      obtain x where r: "R x x" and rep: "Rep a = R x" using rep_prop[of a] by auto
+      have "R (Eps (R x)) x" using homeier8 r by simp
+      then have "R x (Eps (R x))" using part_equivp_symp[OF equivp] by fast
+      then have "R (Eps (R x)) (Eps (R x))" using homeier8[OF r] by simp
+      then show "R (Eps (Rep a)) (Eps (Rep a))" using rep by simp
+    qed
+  qed
 
 end
 
+
 subsection {* ML setup *}
 
 text {* Auxiliary data for the quotient package *}
--- a/src/HOL/Quotient_Examples/FSet.thy	Wed Jun 23 10:20:33 2010 +0200
+++ b/src/HOL/Quotient_Examples/FSet.thy	Wed Jun 23 10:20:54 2010 +0200
@@ -80,20 +80,20 @@
 
 text {* Composition Quotient *}
 
-lemma list_rel_refl:
-  shows "(list_rel op \<approx>) r r"
-  by (rule list_rel_refl) (metis equivp_def fset_equivp)
+lemma list_all2_refl:
+  shows "(list_all2 op \<approx>) r r"
+  by (rule list_all2_refl) (metis equivp_def fset_equivp)
 
 lemma compose_list_refl:
-  shows "(list_rel op \<approx> OOO op \<approx>) r r"
+  shows "(list_all2 op \<approx> OOO op \<approx>) r r"
 proof
   have *: "r \<approx> r" by (rule equivp_reflp[OF fset_equivp])
-  show "list_rel op \<approx> r r" by (rule list_rel_refl)
-  with * show "(op \<approx> OO list_rel op \<approx>) r r" ..
+  show "list_all2 op \<approx> r r" by (rule list_all2_refl)
+  with * show "(op \<approx> OO list_all2 op \<approx>) r r" ..
 qed
 
 lemma Quotient_fset_list:
-  shows "Quotient (list_rel op \<approx>) (map abs_fset) (map rep_fset)"
+  shows "Quotient (list_all2 op \<approx>) (map abs_fset) (map rep_fset)"
   by (fact list_quotient[OF Quotient_fset])
 
 lemma set_in_eq: "(\<forall>e. ((e \<in> xs) \<longleftrightarrow> (e \<in> ys))) \<equiv> xs = ys"
@@ -104,32 +104,32 @@
   by (simp only: set_map set_in_eq)
 
 lemma quotient_compose_list[quot_thm]:
-  shows  "Quotient ((list_rel op \<approx>) OOO (op \<approx>))
+  shows  "Quotient ((list_all2 op \<approx>) OOO (op \<approx>))
     (abs_fset \<circ> (map abs_fset)) ((map rep_fset) \<circ> rep_fset)"
   unfolding Quotient_def comp_def
 proof (intro conjI allI)
   fix a r s
   show "abs_fset (map abs_fset (map rep_fset (rep_fset a))) = a"
     by (simp add: abs_o_rep[OF Quotient_fset] Quotient_abs_rep[OF Quotient_fset] map_id)
-  have b: "list_rel op \<approx> (map rep_fset (rep_fset a)) (map rep_fset (rep_fset a))"
-    by (rule list_rel_refl)
-  have c: "(op \<approx> OO list_rel op \<approx>) (map rep_fset (rep_fset a)) (map rep_fset (rep_fset a))"
+  have b: "list_all2 op \<approx> (map rep_fset (rep_fset a)) (map rep_fset (rep_fset a))"
+    by (rule list_all2_refl)
+  have c: "(op \<approx> OO list_all2 op \<approx>) (map rep_fset (rep_fset a)) (map rep_fset (rep_fset a))"
     by (rule, rule equivp_reflp[OF fset_equivp]) (rule b)
-  show "(list_rel op \<approx> OOO op \<approx>) (map rep_fset (rep_fset a)) (map rep_fset (rep_fset a))"
-    by (rule, rule list_rel_refl) (rule c)
-  show "(list_rel op \<approx> OOO op \<approx>) r s = ((list_rel op \<approx> OOO op \<approx>) r r \<and>
-        (list_rel op \<approx> OOO op \<approx>) s s \<and> abs_fset (map abs_fset r) = abs_fset (map abs_fset s))"
+  show "(list_all2 op \<approx> OOO op \<approx>) (map rep_fset (rep_fset a)) (map rep_fset (rep_fset a))"
+    by (rule, rule list_all2_refl) (rule c)
+  show "(list_all2 op \<approx> OOO op \<approx>) r s = ((list_all2 op \<approx> OOO op \<approx>) r r \<and>
+        (list_all2 op \<approx> OOO op \<approx>) s s \<and> abs_fset (map abs_fset r) = abs_fset (map abs_fset s))"
   proof (intro iffI conjI)
-    show "(list_rel op \<approx> OOO op \<approx>) r r" by (rule compose_list_refl)
-    show "(list_rel op \<approx> OOO op \<approx>) s s" by (rule compose_list_refl)
+    show "(list_all2 op \<approx> OOO op \<approx>) r r" by (rule compose_list_refl)
+    show "(list_all2 op \<approx> OOO op \<approx>) s s" by (rule compose_list_refl)
   next
-    assume a: "(list_rel op \<approx> OOO op \<approx>) r s"
+    assume a: "(list_all2 op \<approx> OOO op \<approx>) r s"
     then have b: "map abs_fset r \<approx> map abs_fset s"
     proof (elim pred_compE)
       fix b ba
-      assume c: "list_rel op \<approx> r b"
+      assume c: "list_all2 op \<approx> r b"
       assume d: "b \<approx> ba"
-      assume e: "list_rel op \<approx> ba s"
+      assume e: "list_all2 op \<approx> ba s"
       have f: "map abs_fset r = map abs_fset b"
         using Quotient_rel[OF Quotient_fset_list] c by blast
       have "map abs_fset ba = map abs_fset s"
@@ -140,20 +140,20 @@
     then show "abs_fset (map abs_fset r) = abs_fset (map abs_fset s)"
       using Quotient_rel[OF Quotient_fset] by blast
   next
-    assume a: "(list_rel op \<approx> OOO op \<approx>) r r \<and> (list_rel op \<approx> OOO op \<approx>) s s
+    assume a: "(list_all2 op \<approx> OOO op \<approx>) r r \<and> (list_all2 op \<approx> OOO op \<approx>) s s
       \<and> abs_fset (map abs_fset r) = abs_fset (map abs_fset s)"
-    then have s: "(list_rel op \<approx> OOO op \<approx>) s s" by simp
+    then have s: "(list_all2 op \<approx> OOO op \<approx>) s s" by simp
     have d: "map abs_fset r \<approx> map abs_fset s"
       by (subst Quotient_rel[OF Quotient_fset]) (simp add: a)
     have b: "map rep_fset (map abs_fset r) \<approx> map rep_fset (map abs_fset s)"
       by (rule map_rel_cong[OF d])
-    have y: "list_rel op \<approx> (map rep_fset (map abs_fset s)) s"
-      by (fact rep_abs_rsp_left[OF Quotient_fset_list, OF list_rel_refl[of s]])
-    have c: "(op \<approx> OO list_rel op \<approx>) (map rep_fset (map abs_fset r)) s"
+    have y: "list_all2 op \<approx> (map rep_fset (map abs_fset s)) s"
+      by (fact rep_abs_rsp_left[OF Quotient_fset_list, OF list_all2_refl[of s]])
+    have c: "(op \<approx> OO list_all2 op \<approx>) (map rep_fset (map abs_fset r)) s"
       by (rule pred_compI) (rule b, rule y)
-    have z: "list_rel op \<approx> r (map rep_fset (map abs_fset r))"
-      by (fact rep_abs_rsp[OF Quotient_fset_list, OF list_rel_refl[of r]])
-    then show "(list_rel op \<approx> OOO op \<approx>) r s"
+    have z: "list_all2 op \<approx> r (map rep_fset (map abs_fset r))"
+      by (fact rep_abs_rsp[OF Quotient_fset_list, OF list_all2_refl[of r]])
+    then show "(list_all2 op \<approx> OOO op \<approx>) r s"
       using a c pred_compI by simp
   qed
 qed
@@ -336,27 +336,27 @@
   by (simp add: memb_def[symmetric] ffold_raw_rsp_pre)
 
 lemma concat_rsp_pre:
-  assumes a: "list_rel op \<approx> x x'"
+  assumes a: "list_all2 op \<approx> x x'"
   and     b: "x' \<approx> y'"
-  and     c: "list_rel op \<approx> y' y"
+  and     c: "list_all2 op \<approx> y' y"
   and     d: "\<exists>x\<in>set x. xa \<in> set x"
   shows "\<exists>x\<in>set y. xa \<in> set x"
 proof -
   obtain xb where e: "xb \<in> set x" and f: "xa \<in> set xb" using d by auto
-  have "\<exists>y. y \<in> set x' \<and> xb \<approx> y" by (rule list_rel_find_element[OF e a])
+  have "\<exists>y. y \<in> set x' \<and> xb \<approx> y" by (rule list_all2_find_element[OF e a])
   then obtain ya where h: "ya \<in> set x'" and i: "xb \<approx> ya" by auto
   have "ya \<in> set y'" using b h by simp
-  then have "\<exists>yb. yb \<in> set y \<and> ya \<approx> yb" using c by (rule list_rel_find_element)
+  then have "\<exists>yb. yb \<in> set y \<and> ya \<approx> yb" using c by (rule list_all2_find_element)
   then show ?thesis using f i by auto
 qed
 
 lemma [quot_respect]:
-  shows "(list_rel op \<approx> OOO op \<approx> ===> op \<approx>) concat concat"
+  shows "(list_all2 op \<approx> OOO op \<approx> ===> op \<approx>) concat concat"
 proof (rule fun_relI, elim pred_compE)
   fix a b ba bb
-  assume a: "list_rel op \<approx> a ba"
+  assume a: "list_all2 op \<approx> a ba"
   assume b: "ba \<approx> bb"
-  assume c: "list_rel op \<approx> bb b"
+  assume c: "list_all2 op \<approx> bb b"
   have "\<forall>x. (\<exists>xa\<in>set a. x \<in> set xa) = (\<exists>xa\<in>set b. x \<in> set xa)" proof
     fix x
     show "(\<exists>xa\<in>set a. x \<in> set xa) = (\<exists>xa\<in>set b. x \<in> set xa)" proof
@@ -364,9 +364,9 @@
       show "\<exists>xa\<in>set b. x \<in> set xa" by (rule concat_rsp_pre[OF a b c d])
     next
       assume e: "\<exists>xa\<in>set b. x \<in> set xa"
-      have a': "list_rel op \<approx> ba a" by (rule list_rel_symp[OF list_eq_equivp, OF a])
+      have a': "list_all2 op \<approx> ba a" by (rule list_all2_symp[OF list_eq_equivp, OF a])
       have b': "bb \<approx> ba" by (rule equivp_symp[OF list_eq_equivp, OF b])
-      have c': "list_rel op \<approx> b bb" by (rule list_rel_symp[OF list_eq_equivp, OF c])
+      have c': "list_all2 op \<approx> b bb" by (rule list_all2_symp[OF list_eq_equivp, OF c])
       show "\<exists>xa\<in>set a. x \<in> set xa" by (rule concat_rsp_pre[OF c' b' a' e])
     qed
   qed
@@ -581,14 +581,14 @@
 
 text {* Compositional Respectfullness and Preservation *}
 
-lemma [quot_respect]: "(list_rel op \<approx> OOO op \<approx>) [] []"
+lemma [quot_respect]: "(list_all2 op \<approx> OOO op \<approx>) [] []"
   by (fact compose_list_refl)
 
 lemma [quot_preserve]: "(abs_fset \<circ> map f) [] = abs_fset []"
   by simp
 
 lemma [quot_respect]:
-  "(op \<approx> ===> list_rel op \<approx> OOO op \<approx> ===> list_rel op \<approx> OOO op \<approx>) op # op #"
+  "(op \<approx> ===> list_all2 op \<approx> OOO op \<approx> ===> list_all2 op \<approx> OOO op \<approx>) op # op #"
   apply auto
   apply (simp add: set_in_eq)
   apply (rule_tac b="x # b" in pred_compI)
@@ -607,59 +607,59 @@
   by (simp add: expand_fun_eq Quotient_abs_rep[OF Quotient_fset]
       abs_o_rep[OF Quotient_fset] map_id sup_fset_def)
 
-lemma list_rel_app_l:
+lemma list_all2_app_l:
   assumes a: "reflp R"
-  and b: "list_rel R l r"
-  shows "list_rel R (z @ l) (z @ r)"
+  and b: "list_all2 R l r"
+  shows "list_all2 R (z @ l) (z @ r)"
   by (induct z) (simp_all add: b rev_iffD1[OF a meta_eq_to_obj_eq[OF reflp_def]])
 
 lemma append_rsp2_pre0:
-  assumes a:"list_rel op \<approx> x x'"
-  shows "list_rel op \<approx> (x @ z) (x' @ z)"
+  assumes a:"list_all2 op \<approx> x x'"
+  shows "list_all2 op \<approx> (x @ z) (x' @ z)"
   using a apply (induct x x' rule: list_induct2')
-  by simp_all (rule list_rel_refl)
+  by simp_all (rule list_all2_refl)
 
 lemma append_rsp2_pre1:
-  assumes a:"list_rel op \<approx> x x'"
-  shows "list_rel op \<approx> (z @ x) (z @ x')"
+  assumes a:"list_all2 op \<approx> x x'"
+  shows "list_all2 op \<approx> (z @ x) (z @ x')"
   using a apply (induct x x' arbitrary: z rule: list_induct2')
-  apply (rule list_rel_refl)
+  apply (rule list_all2_refl)
   apply (simp_all del: list_eq.simps)
-  apply (rule list_rel_app_l)
+  apply (rule list_all2_app_l)
   apply (simp_all add: reflp_def)
   done
 
 lemma append_rsp2_pre:
-  assumes a:"list_rel op \<approx> x x'"
-  and     b: "list_rel op \<approx> z z'"
-  shows "list_rel op \<approx> (x @ z) (x' @ z')"
-  apply (rule list_rel_transp[OF fset_equivp])
+  assumes a:"list_all2 op \<approx> x x'"
+  and     b: "list_all2 op \<approx> z z'"
+  shows "list_all2 op \<approx> (x @ z) (x' @ z')"
+  apply (rule list_all2_transp[OF fset_equivp])
   apply (rule append_rsp2_pre0)
   apply (rule a)
   using b apply (induct z z' rule: list_induct2')
   apply (simp_all only: append_Nil2)
-  apply (rule list_rel_refl)
+  apply (rule list_all2_refl)
   apply simp_all
   apply (rule append_rsp2_pre1)
   apply simp
   done
 
 lemma [quot_respect]:
-  "(list_rel op \<approx> OOO op \<approx> ===> list_rel op \<approx> OOO op \<approx> ===> list_rel op \<approx> OOO op \<approx>) op @ op @"
+  "(list_all2 op \<approx> OOO op \<approx> ===> list_all2 op \<approx> OOO op \<approx> ===> list_all2 op \<approx> OOO op \<approx>) op @ op @"
 proof (intro fun_relI, elim pred_compE)
   fix x y z w x' z' y' w' :: "'a list list"
-  assume a:"list_rel op \<approx> x x'"
+  assume a:"list_all2 op \<approx> x x'"
   and b:    "x' \<approx> y'"
-  and c:    "list_rel op \<approx> y' y"
-  assume aa: "list_rel op \<approx> z z'"
+  and c:    "list_all2 op \<approx> y' y"
+  assume aa: "list_all2 op \<approx> z z'"
   and bb:   "z' \<approx> w'"
-  and cc:   "list_rel op \<approx> w' w"
-  have a': "list_rel op \<approx> (x @ z) (x' @ z')" using a aa append_rsp2_pre by auto
+  and cc:   "list_all2 op \<approx> w' w"
+  have a': "list_all2 op \<approx> (x @ z) (x' @ z')" using a aa append_rsp2_pre by auto
   have b': "x' @ z' \<approx> y' @ w'" using b bb by simp
-  have c': "list_rel op \<approx> (y' @ w') (y @ w)" using c cc append_rsp2_pre by auto
-  have d': "(op \<approx> OO list_rel op \<approx>) (x' @ z') (y @ w)"
+  have c': "list_all2 op \<approx> (y' @ w') (y @ w)" using c cc append_rsp2_pre by auto
+  have d': "(op \<approx> OO list_all2 op \<approx>) (x' @ z') (y @ w)"
     by (rule pred_compI) (rule b', rule c')
-  show "(list_rel op \<approx> OOO op \<approx>) (x @ z) (y @ w)"
+  show "(list_all2 op \<approx> OOO op \<approx>) (x @ z) (y @ w)"
     by (rule pred_compI) (rule a', rule d')
 qed
 
--- a/src/HOL/Tools/Quotient/quotient_tacs.ML	Wed Jun 23 10:20:33 2010 +0200
+++ b/src/HOL/Tools/Quotient/quotient_tacs.ML	Wed Jun 23 10:20:54 2010 +0200
@@ -147,6 +147,14 @@
   finally jump back to 1
 *)
 
+fun reflp_get ctxt =
+  map_filter (fn th => if prems_of th = [] then SOME (OF1 @{thm equivp_reflp} th) else NONE
+    handle THM _ => NONE) (equiv_rules_get ctxt)
+
+val eq_imp_rel = @{lemma "equivp R ==> a = b --> R a b" by (simp add: equivp_reflp)}
+
+fun eq_imp_rel_get ctxt = map (OF1 eq_imp_rel) (equiv_rules_get ctxt)
+
 fun regularize_tac ctxt =
 let
   val thy = ProofContext.theory_of ctxt
@@ -157,8 +165,7 @@
                        addsimps @{thms ball_reg_eqv bex_reg_eqv babs_reg_eqv babs_simp}
                        addsimprocs [simproc]
                        addSolver equiv_solver addSolver quotient_solver
-  val eq_imp_rel = @{lemma "equivp R ==> a = b --> R a b" by (simp add: equivp_reflp)}
-  val eq_eqvs = map (OF1 eq_imp_rel) (equiv_rules_get ctxt)
+  val eq_eqvs = eq_imp_rel_get ctxt
 in
   simp_tac simpset THEN'
   REPEAT_ALL_NEW (CHANGED o FIRST'
@@ -254,7 +261,7 @@
              val inst_thm = Drule.instantiate' ty_inst
                ([NONE, NONE, NONE] @ t_inst) @{thm apply_rsp}
            in
-             (rtac inst_thm THEN' quotient_tac context) 1
+             (rtac inst_thm THEN' SOLVED' (quotient_tac context)) 1
            end
     | _ => no_tac
   end)
@@ -406,7 +413,7 @@
 
 fun injection_tac ctxt =
 let
-  val rel_refl = map (OF1 @{thm equivp_reflp}) (equiv_rules_get ctxt)
+  val rel_refl = reflp_get ctxt
 in
   injection_step_tac ctxt rel_refl
 end
--- a/src/HOL/Tools/Quotient/quotient_typ.ML	Wed Jun 23 10:20:33 2010 +0200
+++ b/src/HOL/Tools/Quotient/quotient_typ.ML	Wed Jun 23 10:20:54 2010 +0200
@@ -7,13 +7,13 @@
 
 signature QUOTIENT_TYPE =
 sig
-  val add_quotient_type: ((string list * binding * mixfix) * (typ * term)) * thm
+  val add_quotient_type: ((string list * binding * mixfix) * (typ * term * bool)) * thm
     -> Proof.context -> (thm * thm) * local_theory
 
-  val quotient_type: ((string list * binding * mixfix) * (typ * term)) list
+  val quotient_type: ((string list * binding * mixfix) * (typ * term * bool)) list
     -> Proof.context -> Proof.state
 
-  val quotient_type_cmd: ((((string list * binding) * mixfix) * string) * string) list
+  val quotient_type_cmd: ((((string list * binding) * mixfix) * string) * (bool * string)) list
     -> Proof.context -> Proof.state
 end;
 
@@ -64,15 +64,15 @@
     |> map Free
 in
   lambda c (HOLogic.exists_const rty $
-     lambda x (HOLogic.mk_eq (c, (rel $ x))))
+     lambda x (HOLogic.mk_conj ((rel $ x $ x), (HOLogic.mk_eq (c, (rel $ x))))))
 end
 
 
 (* makes the new type definitions and proves non-emptyness *)
-fun typedef_make (vs, qty_name, mx, rel, rty) lthy =
+fun typedef_make (vs, qty_name, mx, rel, rty) equiv_thm lthy =
 let
   val typedef_tac =
-    EVERY1 (map rtac [@{thm exI}, mem_def2, @{thm exI}, @{thm refl}])
+    EVERY1 (map rtac [@{thm part_equivp_typedef}, equiv_thm])
 in
 (* FIXME: purely local typedef causes at the moment 
    problems with type variables
@@ -93,14 +93,14 @@
 let
   val rep_thm = #Rep typedef_info RS mem_def1
   val rep_inv = #Rep_inverse typedef_info
-  val abs_inv = mem_def2 RS #Abs_inverse typedef_info
+  val abs_inv = #Abs_inverse typedef_info
   val rep_inj = #Rep_inject typedef_info
 in
   (rtac @{thm quot_type.intro} THEN' RANGE [
     rtac equiv_thm,
     rtac rep_thm,
     rtac rep_inv,
-    EVERY' (map rtac [abs_inv, @{thm exI}, @{thm refl}]),
+    rtac abs_inv THEN' rtac mem_def2 THEN' atac,
     rtac rep_inj]) 1
 end
 
@@ -137,10 +137,12 @@
 
 
 (* main function for constructing a quotient type *)
-fun add_quotient_type (((vs, qty_name, mx), (rty, rel)), equiv_thm) lthy =
+fun add_quotient_type (((vs, qty_name, mx), (rty, rel, partial)), equiv_thm) lthy =
 let
+  val part_equiv = if partial then equiv_thm else equiv_thm RS @{thm equivp_implies_part_equivp}
+
   (* generates the typedef *)
-  val ((qty_full_name, typedef_info), lthy1) = typedef_make (vs, qty_name, mx, rel, rty) lthy
+  val ((qty_full_name, typedef_info), lthy1) = typedef_make (vs, qty_name, mx, rel, rty) part_equiv lthy
 
   (* abs and rep functions from the typedef *)
   val Abs_ty = #abs_type (#1 typedef_info)
@@ -162,7 +164,7 @@
   val ((rep, rep_def), lthy3) = define (rep_name, NoSyn, rep_trm) lthy2
 
   (* quot_type theorem *)
-  val quot_thm = typedef_quot_type_thm (rel, Abs_const, Rep_const, equiv_thm, typedef_info) lthy3
+  val quot_thm = typedef_quot_type_thm (rel, Abs_const, Rep_const, part_equiv, typedef_info) lthy3
 
   (* quotient theorem *)
   val quotient_thm = typedef_quotient_thm (rel, abs, rep, abs_def, rep_def, quot_thm) lthy3
@@ -179,12 +181,12 @@
 in
   lthy4
   |> note (quotient_thm_name, quotient_thm, [intern_attr quotient_rules_add])
-  ||>> note (equiv_thm_name, equiv_thm, [intern_attr equiv_rules_add])
+  ||>> note (equiv_thm_name, equiv_thm, if partial then [] else [intern_attr equiv_rules_add])
 end
 
 
 (* sanity checks for the quotient type specifications *)
-fun sanity_check ((vs, qty_name, _), (rty, rel)) =
+fun sanity_check ((vs, qty_name, _), (rty, rel, _)) =
 let
   val rty_tfreesT = map fst (Term.add_tfreesT rty [])
   val rel_tfrees = map fst (Term.add_tfrees rel [])
@@ -223,7 +225,7 @@
 end
 
 (* check for existence of map functions *)
-fun map_check ctxt (_, (rty, _)) =
+fun map_check ctxt (_, (rty, _, _)) =
 let
   val thy = ProofContext.theory_of ctxt
 
@@ -263,11 +265,12 @@
   val _ = List.app sanity_check quot_list
   val _ = List.app (map_check lthy) quot_list
 
-  fun mk_goal (rty, rel) =
+  fun mk_goal (rty, rel, partial) =
   let
     val equivp_ty = ([rty, rty] ---> @{typ bool}) --> @{typ bool}
+    val const = if partial then @{const_name part_equivp} else @{const_name equivp}
   in
-    HOLogic.mk_Trueprop (Const (@{const_name equivp}, equivp_ty) $ rel)
+    HOLogic.mk_Trueprop (Const (const, equivp_ty) $ rel)
   end
 
   val goals = map (mk_goal o snd) quot_list
@@ -280,7 +283,7 @@
 
 fun quotient_type_cmd specs lthy =
 let
-  fun parse_spec ((((vs, qty_name), mx), rty_str), rel_str) lthy =
+  fun parse_spec ((((vs, qty_name), mx), rty_str), (partial, rel_str)) lthy =
   let
     val rty = Syntax.read_typ lthy rty_str
     val lthy1 = Variable.declare_typ rty lthy
@@ -290,7 +293,7 @@
       |> Syntax.check_term lthy1 
     val lthy2 = Variable.declare_term rel lthy1 
   in
-    (((vs, qty_name, mx), (rty, rel)), lthy2)
+    (((vs, qty_name, mx), (rty, rel, partial)), lthy2)
   end
 
   val (spec', lthy') = fold_map parse_spec specs lthy
@@ -298,11 +301,13 @@
   quotient_type spec' lthy'
 end
 
+val partial = Scan.optional (Parse.reserved "partial" -- Parse.$$$ ":" >> K true) false
+
 val quotspec_parser =
-    Parse.and_list1
-     ((Parse.type_args -- Parse.binding) --
-        Parse.opt_mixfix -- (Parse.$$$ "=" |-- Parse.typ) --
-         (Parse.$$$ "/" |-- Parse.term))
+  Parse.and_list1
+    ((Parse.type_args -- Parse.binding) --
+      Parse.opt_mixfix -- (Parse.$$$ "=" |-- Parse.typ) --
+        (Parse.$$$ "/" |-- (partial -- Parse.term)))
 
 val _ = Keyword.keyword "/"