more systematic and compact proofs on type relation operators using natural deduction rules
authorhaftmann
Tue Nov 30 15:58:09 2010 +0100 (2010-11-30)
changeset 40820fd9c98ead9a9
parent 40819 2ac5af6eb8a8
child 40821 9f32d7b8b24f
more systematic and compact proofs on type relation operators using natural deduction rules
src/HOL/Library/Quotient_List.thy
src/HOL/Library/Quotient_Option.thy
src/HOL/Library/Quotient_Product.thy
src/HOL/Library/Quotient_Sum.thy
     1.1 --- a/src/HOL/Library/Quotient_List.thy	Tue Nov 30 15:58:09 2010 +0100
     1.2 +++ b/src/HOL/Library/Quotient_List.thy	Tue Nov 30 15:58:09 2010 +0100
     1.3 @@ -10,94 +10,96 @@
     1.4  
     1.5  declare [[map list = (map, list_all2)]]
     1.6  
     1.7 -lemma split_list_all:
     1.8 -  shows "(\<forall>x. P x) \<longleftrightarrow> P [] \<and> (\<forall>x xs. P (x#xs))"
     1.9 -  apply(auto)
    1.10 -  apply(case_tac x)
    1.11 -  apply(simp_all)
    1.12 -  done
    1.13 +lemma map_id [id_simps]:
    1.14 +  "map id = id"
    1.15 +  by (simp add: id_def fun_eq_iff map.identity)
    1.16  
    1.17 -lemma map_id[id_simps]:
    1.18 -  shows "map id = id"
    1.19 -  apply(simp add: fun_eq_iff)
    1.20 -  apply(rule allI)
    1.21 -  apply(induct_tac x)
    1.22 -  apply(simp_all)
    1.23 -  done
    1.24 +lemma list_all2_map1:
    1.25 +  "list_all2 R (map f xs) ys \<longleftrightarrow> list_all2 (\<lambda>x. R (f x)) xs ys"
    1.26 +  by (induct xs ys rule: list_induct2') simp_all
    1.27 +
    1.28 +lemma list_all2_map2:
    1.29 +  "list_all2 R xs (map f ys) \<longleftrightarrow> list_all2 (\<lambda>x y. R x (f y)) xs ys"
    1.30 +  by (induct xs ys rule: list_induct2') simp_all
    1.31  
    1.32 -lemma list_all2_reflp:
    1.33 -  shows "equivp R \<Longrightarrow> list_all2 R xs xs"
    1.34 -  by (induct xs, simp_all add: equivp_reflp)
    1.35 +lemma list_all2_eq [id_simps]:
    1.36 +  "list_all2 (op =) = (op =)"
    1.37 +proof (rule ext)+
    1.38 +  fix xs ys
    1.39 +  show "list_all2 (op =) xs ys \<longleftrightarrow> xs = ys"
    1.40 +    by (induct xs ys rule: list_induct2') simp_all
    1.41 +qed
    1.42  
    1.43 -lemma list_all2_symp:
    1.44 -  assumes a: "equivp R"
    1.45 -  and b: "list_all2 R xs ys"
    1.46 -  shows "list_all2 R ys xs"
    1.47 -  using list_all2_lengthD[OF b] b
    1.48 -  apply(induct xs ys rule: list_induct2)
    1.49 -  apply(simp_all)
    1.50 -  apply(rule equivp_symp[OF a])
    1.51 -  apply(simp)
    1.52 -  done
    1.53 +lemma list_reflp:
    1.54 +  assumes "reflp R"
    1.55 +  shows "reflp (list_all2 R)"
    1.56 +proof (rule reflpI)
    1.57 +  from assms have *: "\<And>xs. R xs xs" by (rule reflpE)
    1.58 +  fix xs
    1.59 +  show "list_all2 R xs xs"
    1.60 +    by (induct xs) (simp_all add: *)
    1.61 +qed
    1.62  
    1.63 -lemma list_all2_transp:
    1.64 -  assumes a: "equivp R"
    1.65 -  and b: "list_all2 R xs1 xs2"
    1.66 -  and c: "list_all2 R xs2 xs3"
    1.67 -  shows "list_all2 R xs1 xs3"
    1.68 -  using list_all2_lengthD[OF b] list_all2_lengthD[OF c] b c
    1.69 -  apply(induct rule: list_induct3)
    1.70 -  apply(simp_all)
    1.71 -  apply(auto intro: equivp_transp[OF a])
    1.72 -  done
    1.73 +lemma list_symp:
    1.74 +  assumes "symp R"
    1.75 +  shows "symp (list_all2 R)"
    1.76 +proof (rule sympI)
    1.77 +  from assms have *: "\<And>xs ys. R xs ys \<Longrightarrow> R ys xs" by (rule sympE)
    1.78 +  fix xs ys
    1.79 +  assume "list_all2 R xs ys"
    1.80 +  then show "list_all2 R ys xs"
    1.81 +    by (induct xs ys rule: list_induct2') (simp_all add: *)
    1.82 +qed
    1.83  
    1.84 -lemma list_equivp[quot_equiv]:
    1.85 -  assumes a: "equivp R"
    1.86 -  shows "equivp (list_all2 R)"
    1.87 -  apply (intro equivpI)
    1.88 -  unfolding reflp_def symp_def transp_def
    1.89 -  apply(simp add: list_all2_reflp[OF a])
    1.90 -  apply(blast intro: list_all2_symp[OF a])
    1.91 -  apply(blast intro: list_all2_transp[OF a])
    1.92 -  done
    1.93 +lemma list_transp:
    1.94 +  assumes "transp R"
    1.95 +  shows "transp (list_all2 R)"
    1.96 +proof (rule transpI)
    1.97 +  from assms have *: "\<And>xs ys zs. R xs ys \<Longrightarrow> R ys zs \<Longrightarrow> R xs zs" by (rule transpE)
    1.98 +  fix xs ys zs
    1.99 +  assume A: "list_all2 R xs ys" "list_all2 R ys zs"
   1.100 +  then have "length xs = length ys" "length ys = length zs" by (blast dest: list_all2_lengthD)+
   1.101 +  then show "list_all2 R xs zs" using A
   1.102 +    by (induct xs ys zs rule: list_induct3) (auto intro: *)
   1.103 +qed
   1.104  
   1.105 -lemma list_all2_rel:
   1.106 -  assumes q: "Quotient R Abs Rep"
   1.107 -  shows "list_all2 R r s = (list_all2 R r r \<and> list_all2 R s s \<and> (map Abs r = map Abs s))"
   1.108 -  apply(induct r s rule: list_induct2')
   1.109 -  apply(simp_all)
   1.110 -  using Quotient_rel[OF q]
   1.111 -  apply(metis)
   1.112 -  done
   1.113 +lemma list_equivp [quot_equiv]:
   1.114 +  "equivp R \<Longrightarrow> equivp (list_all2 R)"
   1.115 +  by (blast intro: equivpI list_reflp list_symp list_transp elim: equivpE)
   1.116  
   1.117 -lemma list_quotient[quot_thm]:
   1.118 -  assumes q: "Quotient R Abs Rep"
   1.119 +lemma list_quotient [quot_thm]:
   1.120 +  assumes "Quotient R Abs Rep"
   1.121    shows "Quotient (list_all2 R) (map Abs) (map Rep)"
   1.122 -  unfolding Quotient_def
   1.123 -  apply(subst split_list_all)
   1.124 -  apply(simp add: Quotient_abs_rep[OF q] abs_o_rep[OF q] map_id)
   1.125 -  apply(intro conjI allI)
   1.126 -  apply(induct_tac a)
   1.127 -  apply(simp_all add: Quotient_rep_reflp[OF q])
   1.128 -  apply(rule list_all2_rel[OF q])
   1.129 -  done
   1.130 +proof (rule QuotientI)
   1.131 +  from assms have "\<And>x. Abs (Rep x) = x" by (rule Quotient_abs_rep)
   1.132 +  then show "\<And>xs. map Abs (map Rep xs) = xs" by (simp add: comp_def)
   1.133 +next
   1.134 +  from assms have "\<And>x y. R (Rep x) (Rep y) \<longleftrightarrow> x = y" by (rule Quotient_rel_rep)
   1.135 +  then show "\<And>xs. list_all2 R (map Rep xs) (map Rep xs)"
   1.136 +    by (simp add: list_all2_map1 list_all2_map2 list_all2_eq)
   1.137 +next
   1.138 +  fix xs ys
   1.139 +  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.140 +  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.141 +    by (induct xs ys rule: list_induct2') auto
   1.142 +qed
   1.143  
   1.144 -lemma cons_prs[quot_preserve]:
   1.145 +lemma cons_prs [quot_preserve]:
   1.146    assumes q: "Quotient R Abs Rep"
   1.147    shows "(Rep ---> (map Rep) ---> (map Abs)) (op #) = (op #)"
   1.148    by (auto simp add: fun_eq_iff comp_def Quotient_abs_rep [OF q])
   1.149  
   1.150 -lemma cons_rsp[quot_respect]:
   1.151 +lemma cons_rsp [quot_respect]:
   1.152    assumes q: "Quotient R Abs Rep"
   1.153    shows "(R ===> list_all2 R ===> list_all2 R) (op #) (op #)"
   1.154    by auto
   1.155  
   1.156 -lemma nil_prs[quot_preserve]:
   1.157 +lemma nil_prs [quot_preserve]:
   1.158    assumes q: "Quotient R Abs Rep"
   1.159    shows "map Abs [] = []"
   1.160    by simp
   1.161  
   1.162 -lemma nil_rsp[quot_respect]:
   1.163 +lemma nil_rsp [quot_respect]:
   1.164    assumes q: "Quotient R Abs Rep"
   1.165    shows "list_all2 R [] []"
   1.166    by simp
   1.167 @@ -109,7 +111,7 @@
   1.168    by (induct l)
   1.169       (simp_all add: Quotient_abs_rep[OF a] Quotient_abs_rep[OF b])
   1.170  
   1.171 -lemma map_prs[quot_preserve]:
   1.172 +lemma map_prs [quot_preserve]:
   1.173    assumes a: "Quotient R1 abs1 rep1"
   1.174    and     b: "Quotient R2 abs2 rep2"
   1.175    shows "((abs1 ---> rep2) ---> (map rep1) ---> (map abs2)) map = map"
   1.176 @@ -117,8 +119,7 @@
   1.177    by (simp_all only: fun_eq_iff map_prs_aux[OF a b] comp_def)
   1.178      (simp_all add: Quotient_abs_rep[OF a] Quotient_abs_rep[OF b])
   1.179  
   1.180 -
   1.181 -lemma map_rsp[quot_respect]:
   1.182 +lemma map_rsp [quot_respect]:
   1.183    assumes q1: "Quotient R1 Abs1 Rep1"
   1.184    and     q2: "Quotient R2 Abs2 Rep2"
   1.185    shows "((R1 ===> R2) ===> (list_all2 R1) ===> list_all2 R2) map map"
   1.186 @@ -137,7 +138,7 @@
   1.187    shows "abs2 (foldr ((abs1 ---> abs2 ---> rep2) f) (map rep1 l) (rep2 e)) = foldr f l e"
   1.188    by (induct l) (simp_all add: Quotient_abs_rep[OF a] Quotient_abs_rep[OF b])
   1.189  
   1.190 -lemma foldr_prs[quot_preserve]:
   1.191 +lemma foldr_prs [quot_preserve]:
   1.192    assumes a: "Quotient R1 abs1 rep1"
   1.193    and     b: "Quotient R2 abs2 rep2"
   1.194    shows "((abs1 ---> abs2 ---> rep2) ---> (map rep1) ---> rep2 ---> abs2) foldr = foldr"
   1.195 @@ -151,8 +152,7 @@
   1.196    shows "abs1 (foldl ((abs1 ---> abs2 ---> rep1) f) (rep1 e) (map rep2 l)) = foldl f e l"
   1.197    by (induct l arbitrary:e) (simp_all add: Quotient_abs_rep[OF a] Quotient_abs_rep[OF b])
   1.198  
   1.199 -
   1.200 -lemma foldl_prs[quot_preserve]:
   1.201 +lemma foldl_prs [quot_preserve]:
   1.202    assumes a: "Quotient R1 abs1 rep1"
   1.203    and     b: "Quotient R2 abs2 rep2"
   1.204    shows "((abs1 ---> abs2 ---> rep1) ---> rep1 ---> (map rep2) ---> abs1) foldl = foldl"
   1.205 @@ -217,11 +217,11 @@
   1.206      qed
   1.207    qed
   1.208  
   1.209 -lemma[quot_respect]:
   1.210 +lemma [quot_respect]:
   1.211    "((R ===> R ===> op =) ===> list_all2 R ===> list_all2 R ===> op =) list_all2 list_all2"
   1.212    by (simp add: list_all2_rsp fun_rel_def)
   1.213  
   1.214 -lemma[quot_preserve]:
   1.215 +lemma [quot_preserve]:
   1.216    assumes a: "Quotient R abs1 rep1"
   1.217    shows "((abs1 ---> abs1 ---> id) ---> map rep1 ---> map rep1 ---> id) list_all2 = list_all2"
   1.218    apply (simp add: fun_eq_iff)
   1.219 @@ -230,19 +230,11 @@
   1.220    apply (simp_all add: Quotient_abs_rep[OF a])
   1.221    done
   1.222  
   1.223 -lemma[quot_preserve]:
   1.224 +lemma [quot_preserve]:
   1.225    assumes a: "Quotient R abs1 rep1"
   1.226    shows "(list_all2 ((rep1 ---> rep1 ---> id) R) l m) = (l = m)"
   1.227    by (induct l m rule: list_induct2') (simp_all add: Quotient_rel_rep[OF a])
   1.228  
   1.229 -lemma list_all2_eq[id_simps]:
   1.230 -  shows "(list_all2 (op =)) = (op =)"
   1.231 -  unfolding fun_eq_iff
   1.232 -  apply(rule allI)+
   1.233 -  apply(induct_tac x xa rule: list_induct2')
   1.234 -  apply(simp_all)
   1.235 -  done
   1.236 -
   1.237  lemma list_all2_find_element:
   1.238    assumes a: "x \<in> set a"
   1.239    and b: "list_all2 R a b"
     2.1 --- a/src/HOL/Library/Quotient_Option.thy	Tue Nov 30 15:58:09 2010 +0100
     2.2 +++ b/src/HOL/Library/Quotient_Option.thy	Tue Nov 30 15:58:09 2010 +0100
     2.3 @@ -18,64 +18,73 @@
     2.4  
     2.5  declare [[map option = (Option.map, option_rel)]]
     2.6  
     2.7 -text {* should probably be in Option.thy *}
     2.8 -lemma split_option_all:
     2.9 -  shows "(\<forall>x. P x) \<longleftrightarrow> P None \<and> (\<forall>a. P (Some a))"
    2.10 -  apply(auto)
    2.11 -  apply(case_tac x)
    2.12 -  apply(simp_all)
    2.13 +lemma option_rel_unfold:
    2.14 +  "option_rel R x y = (case (x, y) of (None, None) \<Rightarrow> True
    2.15 +    | (Some x, Some y) \<Rightarrow> R x y
    2.16 +    | _ \<Rightarrow> False)"
    2.17 +  by (cases x) (cases y, simp_all)+
    2.18 +
    2.19 +lemma option_rel_map1:
    2.20 +  "option_rel R (Option.map f x) y \<longleftrightarrow> option_rel (\<lambda>x. R (f x)) x y"
    2.21 +  by (simp add: option_rel_unfold split: option.split)
    2.22 +
    2.23 +lemma option_rel_map2:
    2.24 +  "option_rel R x (Option.map f y) \<longleftrightarrow> option_rel (\<lambda>x y. R x (f y)) x y"
    2.25 +  by (simp add: option_rel_unfold split: option.split)
    2.26 +
    2.27 +lemma option_map_id [id_simps]:
    2.28 +  "Option.map id = id"
    2.29 +  by (simp add: id_def Option.map.identity fun_eq_iff)
    2.30 +
    2.31 +lemma option_rel_eq [id_simps]:
    2.32 +  "option_rel (op =) = (op =)"
    2.33 +  by (simp add: option_rel_unfold fun_eq_iff split: option.split)
    2.34 +
    2.35 +lemma option_reflp:
    2.36 +  "reflp R \<Longrightarrow> reflp (option_rel R)"
    2.37 +  by (auto simp add: option_rel_unfold split: option.splits intro!: reflpI elim: reflpE)
    2.38 +
    2.39 +lemma option_symp:
    2.40 +  "symp R \<Longrightarrow> symp (option_rel R)"
    2.41 +  by (auto simp add: option_rel_unfold split: option.splits intro!: sympI elim: sympE)
    2.42 +
    2.43 +lemma option_transp:
    2.44 +  "transp R \<Longrightarrow> transp (option_rel R)"
    2.45 +  by (auto simp add: option_rel_unfold split: option.splits intro!: transpI elim: transpE)
    2.46 +
    2.47 +lemma option_equivp [quot_equiv]:
    2.48 +  "equivp R \<Longrightarrow> equivp (option_rel R)"
    2.49 +  by (blast intro: equivpI option_reflp option_symp option_transp elim: equivpE)
    2.50 +
    2.51 +lemma option_quotient [quot_thm]:
    2.52 +  assumes "Quotient R Abs Rep"
    2.53 +  shows "Quotient (option_rel R) (Option.map Abs) (Option.map Rep)"
    2.54 +  apply (rule QuotientI)
    2.55 +  apply (simp_all add: Option.map.compositionality Option.map.identity option_rel_eq option_rel_map1 option_rel_map2 Quotient_abs_rep [OF assms] Quotient_rel_rep [OF assms])
    2.56 +  using Quotient_rel [OF assms]
    2.57 +  apply (simp add: option_rel_unfold split: option.split)
    2.58    done
    2.59  
    2.60 -lemma option_quotient[quot_thm]:
    2.61 -  assumes q: "Quotient R Abs Rep"
    2.62 -  shows "Quotient (option_rel R) (Option.map Abs) (Option.map Rep)"
    2.63 -  unfolding Quotient_def
    2.64 -  apply(simp add: split_option_all)
    2.65 -  apply(simp add: Quotient_abs_rep[OF q] Quotient_rel_rep[OF q])
    2.66 -  using q
    2.67 -  unfolding Quotient_def
    2.68 -  apply(blast)
    2.69 -  done
    2.70 -
    2.71 -lemma option_equivp[quot_equiv]:
    2.72 -  assumes a: "equivp R"
    2.73 -  shows "equivp (option_rel R)"
    2.74 -  apply(rule equivpI)
    2.75 -  unfolding reflp_def symp_def transp_def
    2.76 -  apply(simp_all add: split_option_all)
    2.77 -  apply(blast intro: equivp_reflp[OF a])
    2.78 -  apply(blast intro: equivp_symp[OF a])
    2.79 -  apply(blast intro: equivp_transp[OF a])
    2.80 -  done
    2.81 -
    2.82 -lemma option_None_rsp[quot_respect]:
    2.83 +lemma option_None_rsp [quot_respect]:
    2.84    assumes q: "Quotient R Abs Rep"
    2.85    shows "option_rel R None None"
    2.86    by simp
    2.87  
    2.88 -lemma option_Some_rsp[quot_respect]:
    2.89 +lemma option_Some_rsp [quot_respect]:
    2.90    assumes q: "Quotient R Abs Rep"
    2.91    shows "(R ===> option_rel R) Some Some"
    2.92    by auto
    2.93  
    2.94 -lemma option_None_prs[quot_preserve]:
    2.95 +lemma option_None_prs [quot_preserve]:
    2.96    assumes q: "Quotient R Abs Rep"
    2.97    shows "Option.map Abs None = None"
    2.98    by simp
    2.99  
   2.100 -lemma option_Some_prs[quot_preserve]:
   2.101 +lemma option_Some_prs [quot_preserve]:
   2.102    assumes q: "Quotient R Abs Rep"
   2.103    shows "(Rep ---> Option.map Abs) Some = Some"
   2.104    apply(simp add: fun_eq_iff)
   2.105    apply(simp add: Quotient_abs_rep[OF q])
   2.106    done
   2.107  
   2.108 -lemma option_map_id[id_simps]:
   2.109 -  shows "Option.map id = id"
   2.110 -  by (simp add: fun_eq_iff split_option_all)
   2.111 -
   2.112 -lemma option_rel_eq[id_simps]:
   2.113 -  shows "option_rel (op =) = (op =)"
   2.114 -  by (simp add: fun_eq_iff split_option_all)
   2.115 -
   2.116  end
     3.1 --- a/src/HOL/Library/Quotient_Product.thy	Tue Nov 30 15:58:09 2010 +0100
     3.2 +++ b/src/HOL/Library/Quotient_Product.thy	Tue Nov 30 15:58:09 2010 +0100
     3.3 @@ -19,38 +19,39 @@
     3.4    "prod_rel R1 R2 (a, b) (c, d) \<longleftrightarrow> R1 a c \<and> R2 b d"
     3.5    by (simp add: prod_rel_def)
     3.6  
     3.7 -lemma prod_equivp[quot_equiv]:
     3.8 -  assumes a: "equivp R1"
     3.9 -  assumes b: "equivp R2"
    3.10 +lemma map_pair_id [id_simps]:
    3.11 +  shows "map_pair id id = id"
    3.12 +  by (simp add: fun_eq_iff)
    3.13 +
    3.14 +lemma prod_rel_eq [id_simps]:
    3.15 +  shows "prod_rel (op =) (op =) = (op =)"
    3.16 +  by (simp add: fun_eq_iff)
    3.17 +
    3.18 +lemma prod_equivp [quot_equiv]:
    3.19 +  assumes "equivp R1"
    3.20 +  assumes "equivp R2"
    3.21    shows "equivp (prod_rel R1 R2)"
    3.22 -  apply(rule equivpI)
    3.23 -  unfolding reflp_def symp_def transp_def
    3.24 -  apply(simp_all add: split_paired_all prod_rel_def)
    3.25 -  apply(blast intro: equivp_reflp[OF a] equivp_reflp[OF b])
    3.26 -  apply(blast intro: equivp_symp[OF a] equivp_symp[OF b])
    3.27 -  apply(blast intro: equivp_transp[OF a] equivp_transp[OF b])
    3.28 +  using assms by (auto intro!: equivpI reflpI sympI transpI elim!: equivpE elim: reflpE sympE transpE)
    3.29 +
    3.30 +lemma prod_quotient [quot_thm]:
    3.31 +  assumes "Quotient R1 Abs1 Rep1"
    3.32 +  assumes "Quotient R2 Abs2 Rep2"
    3.33 +  shows "Quotient (prod_rel R1 R2) (map_pair Abs1 Abs2) (map_pair Rep1 Rep2)"
    3.34 +  apply (rule QuotientI)
    3.35 +  apply (simp add: map_pair.compositionality map_pair.identity
    3.36 +     Quotient_abs_rep [OF assms(1)] Quotient_abs_rep [OF assms(2)])
    3.37 +  apply (simp add: split_paired_all Quotient_rel_rep [OF assms(1)] Quotient_rel_rep [OF assms(2)])
    3.38 +  using Quotient_rel [OF assms(1)] Quotient_rel [OF assms(2)]
    3.39 +  apply (auto simp add: split_paired_all)
    3.40    done
    3.41  
    3.42 -lemma prod_quotient[quot_thm]:
    3.43 -  assumes q1: "Quotient R1 Abs1 Rep1"
    3.44 -  assumes q2: "Quotient R2 Abs2 Rep2"
    3.45 -  shows "Quotient (prod_rel R1 R2) (map_pair Abs1 Abs2) (map_pair Rep1 Rep2)"
    3.46 -  unfolding Quotient_def
    3.47 -  apply(simp add: split_paired_all)
    3.48 -  apply(simp add: Quotient_abs_rep[OF q1] Quotient_rel_rep[OF q1])
    3.49 -  apply(simp add: Quotient_abs_rep[OF q2] Quotient_rel_rep[OF q2])
    3.50 -  using q1 q2
    3.51 -  unfolding Quotient_def
    3.52 -  apply(blast)
    3.53 -  done
    3.54 -
    3.55 -lemma Pair_rsp[quot_respect]:
    3.56 +lemma Pair_rsp [quot_respect]:
    3.57    assumes q1: "Quotient R1 Abs1 Rep1"
    3.58    assumes q2: "Quotient R2 Abs2 Rep2"
    3.59    shows "(R1 ===> R2 ===> prod_rel R1 R2) Pair Pair"
    3.60    by (auto simp add: prod_rel_def)
    3.61  
    3.62 -lemma Pair_prs[quot_preserve]:
    3.63 +lemma Pair_prs [quot_preserve]:
    3.64    assumes q1: "Quotient R1 Abs1 Rep1"
    3.65    assumes q2: "Quotient R2 Abs2 Rep2"
    3.66    shows "(Rep1 ---> Rep2 ---> (map_pair Abs1 Abs2)) Pair = Pair"
    3.67 @@ -58,35 +59,35 @@
    3.68    apply(simp add: Quotient_abs_rep[OF q1] Quotient_abs_rep[OF q2])
    3.69    done
    3.70  
    3.71 -lemma fst_rsp[quot_respect]:
    3.72 +lemma fst_rsp [quot_respect]:
    3.73    assumes "Quotient R1 Abs1 Rep1"
    3.74    assumes "Quotient R2 Abs2 Rep2"
    3.75    shows "(prod_rel R1 R2 ===> R1) fst fst"
    3.76    by auto
    3.77  
    3.78 -lemma fst_prs[quot_preserve]:
    3.79 +lemma fst_prs [quot_preserve]:
    3.80    assumes q1: "Quotient R1 Abs1 Rep1"
    3.81    assumes q2: "Quotient R2 Abs2 Rep2"
    3.82    shows "(map_pair Rep1 Rep2 ---> Abs1) fst = fst"
    3.83    by (simp add: fun_eq_iff Quotient_abs_rep[OF q1])
    3.84  
    3.85 -lemma snd_rsp[quot_respect]:
    3.86 +lemma snd_rsp [quot_respect]:
    3.87    assumes "Quotient R1 Abs1 Rep1"
    3.88    assumes "Quotient R2 Abs2 Rep2"
    3.89    shows "(prod_rel R1 R2 ===> R2) snd snd"
    3.90    by auto
    3.91  
    3.92 -lemma snd_prs[quot_preserve]:
    3.93 +lemma snd_prs [quot_preserve]:
    3.94    assumes q1: "Quotient R1 Abs1 Rep1"
    3.95    assumes q2: "Quotient R2 Abs2 Rep2"
    3.96    shows "(map_pair Rep1 Rep2 ---> Abs2) snd = snd"
    3.97    by (simp add: fun_eq_iff Quotient_abs_rep[OF q2])
    3.98  
    3.99 -lemma split_rsp[quot_respect]:
   3.100 +lemma split_rsp [quot_respect]:
   3.101    shows "((R1 ===> R2 ===> (op =)) ===> (prod_rel R1 R2) ===> (op =)) split split"
   3.102    by (auto intro!: fun_relI elim!: fun_relE)
   3.103  
   3.104 -lemma split_prs[quot_preserve]:
   3.105 +lemma split_prs [quot_preserve]:
   3.106    assumes q1: "Quotient R1 Abs1 Rep1"
   3.107    and     q2: "Quotient R2 Abs2 Rep2"
   3.108    shows "(((Abs1 ---> Abs2 ---> id) ---> map_pair Rep1 Rep2 ---> id) split) = split"
   3.109 @@ -111,12 +112,4 @@
   3.110  
   3.111  declare Pair_eq[quot_preserve]
   3.112  
   3.113 -lemma map_pair_id[id_simps]:
   3.114 -  shows "map_pair id id = id"
   3.115 -  by (simp add: fun_eq_iff)
   3.116 -
   3.117 -lemma prod_rel_eq[id_simps]:
   3.118 -  shows "prod_rel (op =) (op =) = (op =)"
   3.119 -  by (simp add: fun_eq_iff)
   3.120 -
   3.121  end
     4.1 --- a/src/HOL/Library/Quotient_Sum.thy	Tue Nov 30 15:58:09 2010 +0100
     4.2 +++ b/src/HOL/Library/Quotient_Sum.thy	Tue Nov 30 15:58:09 2010 +0100
     4.3 @@ -18,53 +18,68 @@
     4.4  
     4.5  declare [[map sum = (sum_map, sum_rel)]]
     4.6  
     4.7 +lemma sum_rel_unfold:
     4.8 +  "sum_rel R1 R2 x y = (case (x, y) of (Inl x, Inl y) \<Rightarrow> R1 x y
     4.9 +    | (Inr x, Inr y) \<Rightarrow> R2 x y
    4.10 +    | _ \<Rightarrow> False)"
    4.11 +  by (cases x) (cases y, simp_all)+
    4.12  
    4.13 -text {* should probably be in @{theory Sum_Type} *}
    4.14 -lemma split_sum_all:
    4.15 -  shows "(\<forall>x. P x) \<longleftrightarrow> (\<forall>x. P (Inl x)) \<and> (\<forall>x. P (Inr x))"
    4.16 -  apply(auto)
    4.17 -  apply(case_tac x)
    4.18 -  apply(simp_all)
    4.19 -  done
    4.20 +lemma sum_rel_map1:
    4.21 +  "sum_rel R1 R2 (sum_map f1 f2 x) y \<longleftrightarrow> sum_rel (\<lambda>x. R1 (f1 x)) (\<lambda>x. R2 (f2 x)) x y"
    4.22 +  by (simp add: sum_rel_unfold split: sum.split)
    4.23 +
    4.24 +lemma sum_rel_map2:
    4.25 +  "sum_rel R1 R2 x (sum_map f1 f2 y) \<longleftrightarrow> sum_rel (\<lambda>x y. R1 x (f1 y)) (\<lambda>x y. R2 x (f2 y)) x y"
    4.26 +  by (simp add: sum_rel_unfold split: sum.split)
    4.27 +
    4.28 +lemma sum_map_id [id_simps]:
    4.29 +  "sum_map id id = id"
    4.30 +  by (simp add: id_def sum_map.identity fun_eq_iff)
    4.31  
    4.32 -lemma sum_equivp[quot_equiv]:
    4.33 -  assumes a: "equivp R1"
    4.34 -  assumes b: "equivp R2"
    4.35 -  shows "equivp (sum_rel R1 R2)"
    4.36 -  apply(rule equivpI)
    4.37 -  unfolding reflp_def symp_def transp_def
    4.38 -  apply(simp_all add: split_sum_all)
    4.39 -  apply(blast intro: equivp_reflp[OF a] equivp_reflp[OF b])
    4.40 -  apply(blast intro: equivp_symp[OF a] equivp_symp[OF b])
    4.41 -  apply(blast intro: equivp_transp[OF a] equivp_transp[OF b])
    4.42 -  done
    4.43 +lemma sum_rel_eq [id_simps]:
    4.44 +  "sum_rel (op =) (op =) = (op =)"
    4.45 +  by (simp add: sum_rel_unfold fun_eq_iff split: sum.split)
    4.46 +
    4.47 +lemma sum_reflp:
    4.48 +  "reflp R1 \<Longrightarrow> reflp R2 \<Longrightarrow> reflp (sum_rel R1 R2)"
    4.49 +  by (auto simp add: sum_rel_unfold split: sum.splits intro!: reflpI elim: reflpE)
    4.50  
    4.51 -lemma sum_quotient[quot_thm]:
    4.52 +lemma sum_symp:
    4.53 +  "symp R1 \<Longrightarrow> symp R2 \<Longrightarrow> symp (sum_rel R1 R2)"
    4.54 +  by (auto simp add: sum_rel_unfold split: sum.splits intro!: sympI elim: sympE)
    4.55 +
    4.56 +lemma sum_transp:
    4.57 +  "transp R1 \<Longrightarrow> transp R2 \<Longrightarrow> transp (sum_rel R1 R2)"
    4.58 +  by (auto simp add: sum_rel_unfold split: sum.splits intro!: transpI elim: transpE)
    4.59 +
    4.60 +lemma sum_equivp [quot_equiv]:
    4.61 +  "equivp R1 \<Longrightarrow> equivp R2 \<Longrightarrow> equivp (sum_rel R1 R2)"
    4.62 +  by (blast intro: equivpI sum_reflp sum_symp sum_transp elim: equivpE)
    4.63 +  
    4.64 +lemma sum_quotient [quot_thm]:
    4.65    assumes q1: "Quotient R1 Abs1 Rep1"
    4.66    assumes q2: "Quotient R2 Abs2 Rep2"
    4.67    shows "Quotient (sum_rel R1 R2) (sum_map Abs1 Abs2) (sum_map Rep1 Rep2)"
    4.68 -  unfolding Quotient_def
    4.69 -  apply(simp add: split_sum_all)
    4.70 -  apply(simp_all add: Quotient_abs_rep[OF q1] Quotient_rel_rep[OF q1])
    4.71 -  apply(simp_all add: Quotient_abs_rep[OF q2] Quotient_rel_rep[OF q2])
    4.72 -  using q1 q2
    4.73 -  unfolding Quotient_def
    4.74 -  apply(blast)+
    4.75 +  apply (rule QuotientI)
    4.76 +  apply (simp_all add: sum_map.compositionality sum_map.identity sum_rel_eq sum_rel_map1 sum_rel_map2
    4.77 +    Quotient_abs_rep [OF q1] Quotient_rel_rep [OF q1] Quotient_abs_rep [OF q2] Quotient_rel_rep [OF q2])
    4.78 +  using Quotient_rel [OF q1] Quotient_rel [OF q2]
    4.79 +  apply (simp add: sum_rel_unfold split: sum.split)
    4.80    done
    4.81  
    4.82 -lemma sum_Inl_rsp[quot_respect]:
    4.83 +lemma sum_Inl_rsp [quot_respect]:
    4.84    assumes q1: "Quotient R1 Abs1 Rep1"
    4.85    assumes q2: "Quotient R2 Abs2 Rep2"
    4.86    shows "(R1 ===> sum_rel R1 R2) Inl Inl"
    4.87    by auto
    4.88  
    4.89 -lemma sum_Inr_rsp[quot_respect]:
    4.90 +lemma sum_Inr_rsp [quot_respect]:
    4.91    assumes q1: "Quotient R1 Abs1 Rep1"
    4.92    assumes q2: "Quotient R2 Abs2 Rep2"
    4.93    shows "(R2 ===> sum_rel R1 R2) Inr Inr"
    4.94    by auto
    4.95  
    4.96 -lemma sum_Inl_prs[quot_preserve]:
    4.97 +lemma sum_Inl_prs [quot_preserve]:
    4.98    assumes q1: "Quotient R1 Abs1 Rep1"
    4.99    assumes q2: "Quotient R2 Abs2 Rep2"
   4.100    shows "(Rep1 ---> sum_map Abs1 Abs2) Inl = Inl"
   4.101 @@ -72,7 +87,7 @@
   4.102    apply(simp add: Quotient_abs_rep[OF q1])
   4.103    done
   4.104  
   4.105 -lemma sum_Inr_prs[quot_preserve]:
   4.106 +lemma sum_Inr_prs [quot_preserve]:
   4.107    assumes q1: "Quotient R1 Abs1 Rep1"
   4.108    assumes q2: "Quotient R2 Abs2 Rep2"
   4.109    shows "(Rep2 ---> sum_map Abs1 Abs2) Inr = Inr"
   4.110 @@ -80,12 +95,4 @@
   4.111    apply(simp add: Quotient_abs_rep[OF q2])
   4.112    done
   4.113  
   4.114 -lemma sum_map_id[id_simps]:
   4.115 -  shows "sum_map id id = id"
   4.116 -  by (simp add: fun_eq_iff split_sum_all)
   4.117 -
   4.118 -lemma sum_rel_eq[id_simps]:
   4.119 -  shows "sum_rel (op =) (op =) = (op =)"
   4.120 -  by (simp add: fun_eq_iff split_sum_all)
   4.121 -
   4.122  end