src/HOL/Library/Quotient_List.thy
changeset 40820 fd9c98ead9a9
parent 40463 75e544159549
child 45802 b16f976db515
child 45803 fe44c0b216ef
     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"