src/HOL/Library/Quotient_List.thy
 changeset 47308 9caab698dbe4 parent 47094 1a7ad2601cb5 child 47455 26315a545e26
```     1.1 --- a/src/HOL/Library/Quotient_List.thy	Tue Apr 03 14:09:37 2012 +0200
1.2 +++ b/src/HOL/Library/Quotient_List.thy	Tue Apr 03 16:26:48 2012 +0200
1.3 @@ -1,4 +1,4 @@
1.4 -(*  Title:      HOL/Library/Quotient_List.thy
1.5 +(*  Title:      HOL/Library/Quotient3_List.thy
1.6      Author:     Cezary Kaliszyk and Christian Urban
1.7  *)
1.8
1.9 @@ -56,63 +56,63 @@
1.10    "equivp R \<Longrightarrow> equivp (list_all2 R)"
1.11    by (blast intro: equivpI list_reflp list_symp list_transp elim: equivpE)
1.12
1.13 -lemma list_quotient [quot_thm]:
1.14 -  assumes "Quotient R Abs Rep"
1.15 -  shows "Quotient (list_all2 R) (map Abs) (map Rep)"
1.16 -proof (rule QuotientI)
1.17 -  from assms have "\<And>x. Abs (Rep x) = x" by (rule Quotient_abs_rep)
1.18 +lemma list_quotient3 [quot_thm]:
1.19 +  assumes "Quotient3 R Abs Rep"
1.20 +  shows "Quotient3 (list_all2 R) (map Abs) (map Rep)"
1.21 +proof (rule Quotient3I)
1.22 +  from assms have "\<And>x. Abs (Rep x) = x" by (rule Quotient3_abs_rep)
1.23    then show "\<And>xs. map Abs (map Rep xs) = xs" by (simp add: comp_def)
1.24  next
1.25 -  from assms have "\<And>x y. R (Rep x) (Rep y) \<longleftrightarrow> x = y" by (rule Quotient_rel_rep)
1.26 +  from assms have "\<And>x y. R (Rep x) (Rep y) \<longleftrightarrow> x = y" by (rule Quotient3_rel_rep)
1.27    then show "\<And>xs. list_all2 R (map Rep xs) (map Rep xs)"
1.28      by (simp add: list_all2_map1 list_all2_map2 list_all2_eq)
1.29  next
1.30    fix xs ys
1.31 -  from assms have "\<And>x y. R x x \<and> R y y \<and> Abs x = Abs y \<longleftrightarrow> R x y" by (rule Quotient_rel)
1.32 +  from assms have "\<And>x y. R x x \<and> R y y \<and> Abs x = Abs y \<longleftrightarrow> R x y" by (rule Quotient3_rel)
1.33    then show "list_all2 R xs ys \<longleftrightarrow> list_all2 R xs xs \<and> list_all2 R ys ys \<and> map Abs xs = map Abs ys"
1.34      by (induct xs ys rule: list_induct2') auto
1.35  qed
1.36
1.37 -declare [[map list = (list_all2, list_quotient)]]
1.38 +declare [[mapQ3 list = (list_all2, list_quotient3)]]
1.39
1.40  lemma cons_prs [quot_preserve]:
1.41 -  assumes q: "Quotient R Abs Rep"
1.42 +  assumes q: "Quotient3 R Abs Rep"
1.43    shows "(Rep ---> (map Rep) ---> (map Abs)) (op #) = (op #)"
1.44 -  by (auto simp add: fun_eq_iff comp_def Quotient_abs_rep [OF q])
1.45 +  by (auto simp add: fun_eq_iff comp_def Quotient3_abs_rep [OF q])
1.46
1.47  lemma cons_rsp [quot_respect]:
1.48 -  assumes q: "Quotient R Abs Rep"
1.49 +  assumes q: "Quotient3 R Abs Rep"
1.50    shows "(R ===> list_all2 R ===> list_all2 R) (op #) (op #)"
1.51    by auto
1.52
1.53  lemma nil_prs [quot_preserve]:
1.54 -  assumes q: "Quotient R Abs Rep"
1.55 +  assumes q: "Quotient3 R Abs Rep"
1.56    shows "map Abs [] = []"
1.57    by simp
1.58
1.59  lemma nil_rsp [quot_respect]:
1.60 -  assumes q: "Quotient R Abs Rep"
1.61 +  assumes q: "Quotient3 R Abs Rep"
1.62    shows "list_all2 R [] []"
1.63    by simp
1.64
1.65  lemma map_prs_aux:
1.66 -  assumes a: "Quotient R1 abs1 rep1"
1.67 -  and     b: "Quotient R2 abs2 rep2"
1.68 +  assumes a: "Quotient3 R1 abs1 rep1"
1.69 +  and     b: "Quotient3 R2 abs2 rep2"
1.70    shows "(map abs2) (map ((abs1 ---> rep2) f) (map rep1 l)) = map f l"
1.71    by (induct l)
1.72 -     (simp_all add: Quotient_abs_rep[OF a] Quotient_abs_rep[OF b])
1.73 +     (simp_all add: Quotient3_abs_rep[OF a] Quotient3_abs_rep[OF b])
1.74
1.75  lemma map_prs [quot_preserve]:
1.76 -  assumes a: "Quotient R1 abs1 rep1"
1.77 -  and     b: "Quotient R2 abs2 rep2"
1.78 +  assumes a: "Quotient3 R1 abs1 rep1"
1.79 +  and     b: "Quotient3 R2 abs2 rep2"
1.80    shows "((abs1 ---> rep2) ---> (map rep1) ---> (map abs2)) map = map"
1.81    and   "((abs1 ---> id) ---> map rep1 ---> id) map = map"
1.82    by (simp_all only: fun_eq_iff map_prs_aux[OF a b] comp_def)
1.83 -    (simp_all add: Quotient_abs_rep[OF a] Quotient_abs_rep[OF b])
1.84 +    (simp_all add: Quotient3_abs_rep[OF a] Quotient3_abs_rep[OF b])
1.85
1.86  lemma map_rsp [quot_respect]:
1.87 -  assumes q1: "Quotient R1 Abs1 Rep1"
1.88 -  and     q2: "Quotient R2 Abs2 Rep2"
1.89 +  assumes q1: "Quotient3 R1 Abs1 Rep1"
1.90 +  and     q2: "Quotient3 R2 Abs2 Rep2"
1.91    shows "((R1 ===> R2) ===> (list_all2 R1) ===> list_all2 R2) map map"
1.92    and   "((R1 ===> op =) ===> (list_all2 R1) ===> op =) map map"
1.94 @@ -124,35 +124,35 @@
1.95    done
1.96
1.97  lemma foldr_prs_aux:
1.98 -  assumes a: "Quotient R1 abs1 rep1"
1.99 -  and     b: "Quotient R2 abs2 rep2"
1.100 +  assumes a: "Quotient3 R1 abs1 rep1"
1.101 +  and     b: "Quotient3 R2 abs2 rep2"
1.102    shows "abs2 (foldr ((abs1 ---> abs2 ---> rep2) f) (map rep1 l) (rep2 e)) = foldr f l e"
1.103 -  by (induct l) (simp_all add: Quotient_abs_rep[OF a] Quotient_abs_rep[OF b])
1.104 +  by (induct l) (simp_all add: Quotient3_abs_rep[OF a] Quotient3_abs_rep[OF b])
1.105
1.106  lemma foldr_prs [quot_preserve]:
1.107 -  assumes a: "Quotient R1 abs1 rep1"
1.108 -  and     b: "Quotient R2 abs2 rep2"
1.109 +  assumes a: "Quotient3 R1 abs1 rep1"
1.110 +  and     b: "Quotient3 R2 abs2 rep2"
1.111    shows "((abs1 ---> abs2 ---> rep2) ---> (map rep1) ---> rep2 ---> abs2) foldr = foldr"
1.113    by (simp only: fun_eq_iff foldr_prs_aux[OF a b])
1.114       (simp)
1.115
1.116  lemma foldl_prs_aux:
1.117 -  assumes a: "Quotient R1 abs1 rep1"
1.118 -  and     b: "Quotient R2 abs2 rep2"
1.119 +  assumes a: "Quotient3 R1 abs1 rep1"
1.120 +  and     b: "Quotient3 R2 abs2 rep2"
1.121    shows "abs1 (foldl ((abs1 ---> abs2 ---> rep1) f) (rep1 e) (map rep2 l)) = foldl f e l"
1.122 -  by (induct l arbitrary:e) (simp_all add: Quotient_abs_rep[OF a] Quotient_abs_rep[OF b])
1.123 +  by (induct l arbitrary:e) (simp_all add: Quotient3_abs_rep[OF a] Quotient3_abs_rep[OF b])
1.124
1.125  lemma foldl_prs [quot_preserve]:
1.126 -  assumes a: "Quotient R1 abs1 rep1"
1.127 -  and     b: "Quotient R2 abs2 rep2"
1.128 +  assumes a: "Quotient3 R1 abs1 rep1"
1.129 +  and     b: "Quotient3 R2 abs2 rep2"
1.130    shows "((abs1 ---> abs2 ---> rep1) ---> rep1 ---> (map rep2) ---> abs1) foldl = foldl"
1.131    by (simp add: fun_eq_iff foldl_prs_aux [OF a b])
1.132
1.133  (* induct_tac doesn't accept 'arbitrary', so we manually 'spec' *)
1.134  lemma foldl_rsp[quot_respect]:
1.135 -  assumes q1: "Quotient R1 Abs1 Rep1"
1.136 -  and     q2: "Quotient R2 Abs2 Rep2"
1.137 +  assumes q1: "Quotient3 R1 Abs1 Rep1"
1.138 +  and     q2: "Quotient3 R2 Abs2 Rep2"
1.139    shows "((R1 ===> R2 ===> R1) ===> R1 ===> list_all2 R2 ===> R1) foldl foldl"
1.141    apply (erule_tac P="R1 xa ya" in rev_mp)
1.142 @@ -162,8 +162,8 @@
1.143    done
1.144
1.145  lemma foldr_rsp[quot_respect]:
1.146 -  assumes q1: "Quotient R1 Abs1 Rep1"
1.147 -  and     q2: "Quotient R2 Abs2 Rep2"
1.148 +  assumes q1: "Quotient3 R1 Abs1 Rep1"
1.149 +  and     q2: "Quotient3 R2 Abs2 Rep2"
1.150    shows "((R1 ===> R2 ===> R2) ===> list_all2 R1 ===> R2 ===> R2) foldr foldr"
1.151    apply (auto simp add: fun_rel_def)
1.152    apply (erule list_all2_induct, simp_all)
1.153 @@ -183,18 +183,18 @@
1.154    by (simp add: list_all2_rsp fun_rel_def)
1.155
1.156  lemma [quot_preserve]:
1.157 -  assumes a: "Quotient R abs1 rep1"
1.158 +  assumes a: "Quotient3 R abs1 rep1"
1.159    shows "((abs1 ---> abs1 ---> id) ---> map rep1 ---> map rep1 ---> id) list_all2 = list_all2"
1.161    apply clarify
1.162    apply (induct_tac xa xb rule: list_induct2')
1.163 -  apply (simp_all add: Quotient_abs_rep[OF a])
1.164 +  apply (simp_all add: Quotient3_abs_rep[OF a])
1.165    done
1.166
1.167  lemma [quot_preserve]:
1.168 -  assumes a: "Quotient R abs1 rep1"
1.169 +  assumes a: "Quotient3 R abs1 rep1"
1.170    shows "(list_all2 ((rep1 ---> rep1 ---> id) R) l m) = (l = m)"
1.171 -  by (induct l m rule: list_induct2') (simp_all add: Quotient_rel_rep[OF a])
1.172 +  by (induct l m rule: list_induct2') (simp_all add: Quotient3_rel_rep[OF a])
1.173
1.174  lemma list_all2_find_element:
1.175    assumes a: "x \<in> set a"
1.176 @@ -207,4 +207,48 @@
1.177    shows "list_all2 R x x"
1.178    by (induct x) (auto simp add: a)
1.179
1.180 +lemma list_quotient:
1.181 +  assumes "Quotient R Abs Rep T"
1.182 +  shows "Quotient (list_all2 R) (List.map Abs) (List.map Rep) (list_all2 T)"
1.183 +proof (rule QuotientI)
1.184 +  from assms have "\<And>x. Abs (Rep x) = x" by (rule Quotient_abs_rep)
1.185 +  then show "\<And>xs. List.map Abs (List.map Rep xs) = xs" by (simp add: comp_def)
1.186 +next
1.187 +  from assms have "\<And>x y. R (Rep x) (Rep y) \<longleftrightarrow> x = y" by (rule Quotient_rel_rep)
1.188 +  then show "\<And>xs. list_all2 R (List.map Rep xs) (List.map Rep xs)"
1.189 +    by (simp add: list_all2_map1 list_all2_map2 list_all2_eq)
1.190 +next
1.191 +  fix xs ys
1.192 +  from assms have "\<And>x y. R x x \<and> R y y \<and> Abs x = Abs y \<longleftrightarrow> R x y" by (rule Quotient_rel)
1.193 +  then show "list_all2 R xs ys \<longleftrightarrow> list_all2 R xs xs \<and> list_all2 R ys ys \<and> List.map Abs xs = List.map Abs ys"
1.194 +    by (induct xs ys rule: list_induct2') auto
1.195 +next
1.196 +  {
1.197 +    fix l1 l2
1.198 +    have "List.length l1 = List.length l2 \<Longrightarrow>
1.199 +         (\<forall>(x, y)\<in>set (zip l1 l1). R x y) = (\<forall>(x, y)\<in>set (zip l1 l2). R x x)"
1.200 +     by (induction rule: list_induct2) auto
1.201 +  } note x = this
1.202 +  {
1.203 +    fix f g
1.204 +    have "list_all2 (\<lambda>x y. f x y \<and> g x y) = (\<lambda> x y. list_all2 f x y \<and> list_all2 g x y)"
1.205 +      by (intro ext) (auto simp add: list_all2_def)
1.206 +  } note list_all2_conj = this
1.207 +  from assms have t: "T = (\<lambda>x y. R x x \<and> Abs x = y)" by (rule Quotient_cr_rel)
1.208 +  show "list_all2 T = (\<lambda>x y. list_all2 R x x \<and> List.map Abs x = y)"
1.209 +    apply (simp add: t list_all2_conj[symmetric])
1.210 +    apply (rule sym)
1.211 +    apply (simp add: list_all2_conj)
1.212 +    apply(intro ext)
1.213 +    apply (intro rev_conj_cong)
1.214 +      unfolding list_all2_def apply (metis List.list_all2_eq list_all2_def list_all2_map1)
1.215 +    apply (drule conjunct1)
1.216 +    apply (intro conj_cong)
1.217 +      apply simp