src/HOL/Library/Quotient_List.thy
changeset 37492 ab36b1a50ca8
parent 36812 e090bdb4e1c5
child 39198 f967a16dfcdd
     1.1 --- a/src/HOL/Library/Quotient_List.thy	Tue Jun 22 19:46:16 2010 +0200
     1.2 +++ b/src/HOL/Library/Quotient_List.thy	Wed Jun 23 08:42:41 2010 +0200
     1.3 @@ -8,15 +8,7 @@
     1.4  imports Main Quotient_Syntax
     1.5  begin
     1.6  
     1.7 -fun
     1.8 -  list_rel
     1.9 -where
    1.10 -  "list_rel R [] [] = True"
    1.11 -| "list_rel R (x#xs) [] = False"
    1.12 -| "list_rel R [] (x#xs) = False"
    1.13 -| "list_rel R (x#xs) (y#ys) = (R x y \<and> list_rel R xs ys)"
    1.14 -
    1.15 -declare [[map list = (map, list_rel)]]
    1.16 +declare [[map list = (map, list_all2)]]
    1.17  
    1.18  lemma split_list_all:
    1.19    shows "(\<forall>x. P x) \<longleftrightarrow> P [] \<and> (\<forall>x xs. P (x#xs))"
    1.20 @@ -33,52 +25,47 @@
    1.21    apply(simp_all)
    1.22    done
    1.23  
    1.24 +lemma list_all2_reflp:
    1.25 +  shows "equivp R \<Longrightarrow> list_all2 R xs xs"
    1.26 +  by (induct xs, simp_all add: equivp_reflp)
    1.27  
    1.28 -lemma list_rel_reflp:
    1.29 -  shows "equivp R \<Longrightarrow> list_rel R xs xs"
    1.30 -  apply(induct xs)
    1.31 -  apply(simp_all add: equivp_reflp)
    1.32 -  done
    1.33 -
    1.34 -lemma list_rel_symp:
    1.35 +lemma list_all2_symp:
    1.36    assumes a: "equivp R"
    1.37 -  shows "list_rel R xs ys \<Longrightarrow> list_rel R ys xs"
    1.38 -  apply(induct xs ys rule: list_induct2')
    1.39 +  and b: "list_all2 R xs ys"
    1.40 +  shows "list_all2 R ys xs"
    1.41 +  using list_all2_lengthD[OF b] b
    1.42 +  apply(induct xs ys rule: list_induct2)
    1.43    apply(simp_all)
    1.44    apply(rule equivp_symp[OF a])
    1.45    apply(simp)
    1.46    done
    1.47  
    1.48 -lemma list_rel_transp:
    1.49 +thm list_induct3
    1.50 +
    1.51 +lemma list_all2_transp:
    1.52    assumes a: "equivp R"
    1.53 -  shows "list_rel R xs1 xs2 \<Longrightarrow> list_rel R xs2 xs3 \<Longrightarrow> list_rel R xs1 xs3"
    1.54 -  using a
    1.55 -  apply(induct R xs1 xs2 arbitrary: xs3 rule: list_rel.induct)
    1.56 -  apply(simp)
    1.57 -  apply(simp)
    1.58 -  apply(simp)
    1.59 -  apply(case_tac xs3)
    1.60 -  apply(clarify)
    1.61 -  apply(simp (no_asm_use))
    1.62 -  apply(clarify)
    1.63 -  apply(simp (no_asm_use))
    1.64 -  apply(auto intro: equivp_transp)
    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  
    1.74  lemma list_equivp[quot_equiv]:
    1.75    assumes a: "equivp R"
    1.76 -  shows "equivp (list_rel R)"
    1.77 -  apply(rule equivpI)
    1.78 +  shows "equivp (list_all2 R)"
    1.79 +  apply (intro equivpI)
    1.80    unfolding reflp_def symp_def transp_def
    1.81 -  apply(subst split_list_all)
    1.82 -  apply(simp add: equivp_reflp[OF a] list_rel_reflp[OF a])
    1.83 -  apply(blast intro: list_rel_symp[OF a])
    1.84 -  apply(blast intro: list_rel_transp[OF a])
    1.85 +  apply(simp add: list_all2_reflp[OF a])
    1.86 +  apply(blast intro: list_all2_symp[OF a])
    1.87 +  apply(blast intro: list_all2_transp[OF a])
    1.88    done
    1.89  
    1.90 -lemma list_rel_rel:
    1.91 +lemma list_all2_rel:
    1.92    assumes q: "Quotient R Abs Rep"
    1.93 -  shows "list_rel R r s = (list_rel R r r \<and> list_rel R s s \<and> (map Abs r = map Abs s))"
    1.94 +  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.95    apply(induct r s rule: list_induct2')
    1.96    apply(simp_all)
    1.97    using Quotient_rel[OF q]
    1.98 @@ -87,21 +74,16 @@
    1.99  
   1.100  lemma list_quotient[quot_thm]:
   1.101    assumes q: "Quotient R Abs Rep"
   1.102 -  shows "Quotient (list_rel R) (map Abs) (map Rep)"
   1.103 +  shows "Quotient (list_all2 R) (map Abs) (map Rep)"
   1.104    unfolding Quotient_def
   1.105    apply(subst split_list_all)
   1.106    apply(simp add: Quotient_abs_rep[OF q] abs_o_rep[OF q] map_id)
   1.107 -  apply(rule conjI)
   1.108 -  apply(rule allI)
   1.109 +  apply(intro conjI allI)
   1.110    apply(induct_tac a)
   1.111 -  apply(simp)
   1.112 -  apply(simp)
   1.113 -  apply(simp add: Quotient_rep_reflp[OF q])
   1.114 -  apply(rule allI)+
   1.115 -  apply(rule list_rel_rel[OF q])
   1.116 +  apply(simp_all add: Quotient_rep_reflp[OF q])
   1.117 +  apply(rule list_all2_rel[OF q])
   1.118    done
   1.119  
   1.120 -
   1.121  lemma cons_prs_aux:
   1.122    assumes q: "Quotient R Abs Rep"
   1.123    shows "(map Abs) ((Rep h) # (map Rep t)) = h # t"
   1.124 @@ -115,7 +97,7 @@
   1.125  
   1.126  lemma cons_rsp[quot_respect]:
   1.127    assumes q: "Quotient R Abs Rep"
   1.128 -  shows "(R ===> list_rel R ===> list_rel R) (op #) (op #)"
   1.129 +  shows "(R ===> list_all2 R ===> list_all2 R) (op #) (op #)"
   1.130    by (auto)
   1.131  
   1.132  lemma nil_prs[quot_preserve]:
   1.133 @@ -125,7 +107,7 @@
   1.134  
   1.135  lemma nil_rsp[quot_respect]:
   1.136    assumes q: "Quotient R Abs Rep"
   1.137 -  shows "list_rel R [] []"
   1.138 +  shows "list_all2 R [] []"
   1.139    by simp
   1.140  
   1.141  lemma map_prs_aux:
   1.142 @@ -146,8 +128,8 @@
   1.143  lemma map_rsp[quot_respect]:
   1.144    assumes q1: "Quotient R1 Abs1 Rep1"
   1.145    and     q2: "Quotient R2 Abs2 Rep2"
   1.146 -  shows "((R1 ===> R2) ===> (list_rel R1) ===> list_rel R2) map map"
   1.147 -  and   "((R1 ===> op =) ===> (list_rel R1) ===> op =) map map"
   1.148 +  shows "((R1 ===> R2) ===> (list_all2 R1) ===> list_all2 R2) map map"
   1.149 +  and   "((R1 ===> op =) ===> (list_all2 R1) ===> op =) map map"
   1.150    apply simp_all
   1.151    apply(rule_tac [!] allI)+
   1.152    apply(rule_tac [!] impI)
   1.153 @@ -183,53 +165,45 @@
   1.154    by (simp only: expand_fun_eq fun_map_def foldl_prs_aux[OF a b])
   1.155       (simp)
   1.156  
   1.157 -lemma list_rel_empty:
   1.158 -  shows "list_rel R [] b \<Longrightarrow> length b = 0"
   1.159 +lemma list_all2_empty:
   1.160 +  shows "list_all2 R [] b \<Longrightarrow> length b = 0"
   1.161    by (induct b) (simp_all)
   1.162  
   1.163 -lemma list_rel_len:
   1.164 -  shows "list_rel R a b \<Longrightarrow> length a = length b"
   1.165 -  apply (induct a arbitrary: b)
   1.166 -  apply (simp add: list_rel_empty)
   1.167 -  apply (case_tac b)
   1.168 -  apply simp_all
   1.169 -  done
   1.170 -
   1.171  (* induct_tac doesn't accept 'arbitrary', so we manually 'spec' *)
   1.172  lemma foldl_rsp[quot_respect]:
   1.173    assumes q1: "Quotient R1 Abs1 Rep1"
   1.174    and     q2: "Quotient R2 Abs2 Rep2"
   1.175 -  shows "((R1 ===> R2 ===> R1) ===> R1 ===> list_rel R2 ===> R1) foldl foldl"
   1.176 +  shows "((R1 ===> R2 ===> R1) ===> R1 ===> list_all2 R2 ===> R1) foldl foldl"
   1.177    apply(auto)
   1.178 -  apply (subgoal_tac "R1 xa ya \<longrightarrow> list_rel R2 xb yb \<longrightarrow> R1 (foldl x xa xb) (foldl y ya yb)")
   1.179 +  apply (subgoal_tac "R1 xa ya \<longrightarrow> list_all2 R2 xb yb \<longrightarrow> R1 (foldl x xa xb) (foldl y ya yb)")
   1.180    apply simp
   1.181    apply (rule_tac x="xa" in spec)
   1.182    apply (rule_tac x="ya" in spec)
   1.183    apply (rule_tac xs="xb" and ys="yb" in list_induct2)
   1.184 -  apply (rule list_rel_len)
   1.185 +  apply (rule list_all2_lengthD)
   1.186    apply (simp_all)
   1.187    done
   1.188  
   1.189  lemma foldr_rsp[quot_respect]:
   1.190    assumes q1: "Quotient R1 Abs1 Rep1"
   1.191    and     q2: "Quotient R2 Abs2 Rep2"
   1.192 -  shows "((R1 ===> R2 ===> R2) ===> list_rel R1 ===> R2 ===> R2) foldr foldr"
   1.193 +  shows "((R1 ===> R2 ===> R2) ===> list_all2 R1 ===> R2 ===> R2) foldr foldr"
   1.194    apply auto
   1.195 -  apply(subgoal_tac "R2 xb yb \<longrightarrow> list_rel R1 xa ya \<longrightarrow> R2 (foldr x xa xb) (foldr y ya yb)")
   1.196 +  apply(subgoal_tac "R2 xb yb \<longrightarrow> list_all2 R1 xa ya \<longrightarrow> R2 (foldr x xa xb) (foldr y ya yb)")
   1.197    apply simp
   1.198    apply (rule_tac xs="xa" and ys="ya" in list_induct2)
   1.199 -  apply (rule list_rel_len)
   1.200 +  apply (rule list_all2_lengthD)
   1.201    apply (simp_all)
   1.202    done
   1.203  
   1.204 -lemma list_rel_rsp:
   1.205 +lemma list_all2_rsp:
   1.206    assumes r: "\<forall>x y. R x y \<longrightarrow> (\<forall>a b. R a b \<longrightarrow> S x a = T y b)"
   1.207 -  and l1: "list_rel R x y"
   1.208 -  and l2: "list_rel R a b"
   1.209 -  shows "list_rel S x a = list_rel T y b"
   1.210 +  and l1: "list_all2 R x y"
   1.211 +  and l2: "list_all2 R a b"
   1.212 +  shows "list_all2 S x a = list_all2 T y b"
   1.213    proof -
   1.214 -    have a: "length y = length x" by (rule list_rel_len[OF l1, symmetric])
   1.215 -    have c: "length a = length b" by (rule list_rel_len[OF l2])
   1.216 +    have a: "length y = length x" by (rule list_all2_lengthD[OF l1, symmetric])
   1.217 +    have c: "length a = length b" by (rule list_all2_lengthD[OF l2])
   1.218      show ?thesis proof (cases "length x = length a")
   1.219        case True
   1.220        have b: "length x = length a" by fact
   1.221 @@ -243,20 +217,20 @@
   1.222      next
   1.223        case False
   1.224        have d: "length x \<noteq> length a" by fact
   1.225 -      then have e: "\<not>list_rel S x a" using list_rel_len by auto
   1.226 +      then have e: "\<not>list_all2 S x a" using list_all2_lengthD by auto
   1.227        have "length y \<noteq> length b" using d a c by simp
   1.228 -      then have "\<not>list_rel T y b" using list_rel_len by auto
   1.229 +      then have "\<not>list_all2 T y b" using list_all2_lengthD by auto
   1.230        then show ?thesis using e by simp
   1.231      qed
   1.232    qed
   1.233  
   1.234  lemma[quot_respect]:
   1.235 -  "((R ===> R ===> op =) ===> list_rel R ===> list_rel R ===> op =) list_rel list_rel"
   1.236 -  by (simp add: list_rel_rsp)
   1.237 +  "((R ===> R ===> op =) ===> list_all2 R ===> list_all2 R ===> op =) list_all2 list_all2"
   1.238 +  by (simp add: list_all2_rsp)
   1.239  
   1.240  lemma[quot_preserve]:
   1.241    assumes a: "Quotient R abs1 rep1"
   1.242 -  shows "((abs1 ---> abs1 ---> id) ---> map rep1 ---> map rep1 ---> id) list_rel = list_rel"
   1.243 +  shows "((abs1 ---> abs1 ---> id) ---> map rep1 ---> map rep1 ---> id) list_all2 = list_all2"
   1.244    apply (simp add: expand_fun_eq)
   1.245    apply clarify
   1.246    apply (induct_tac xa xb rule: list_induct2')
   1.247 @@ -265,29 +239,29 @@
   1.248  
   1.249  lemma[quot_preserve]:
   1.250    assumes a: "Quotient R abs1 rep1"
   1.251 -  shows "(list_rel ((rep1 ---> rep1 ---> id) R) l m) = (l = m)"
   1.252 +  shows "(list_all2 ((rep1 ---> rep1 ---> id) R) l m) = (l = m)"
   1.253    by (induct l m rule: list_induct2') (simp_all add: Quotient_rel_rep[OF a])
   1.254  
   1.255 -lemma list_rel_eq[id_simps]:
   1.256 -  shows "(list_rel (op =)) = (op =)"
   1.257 +lemma list_all2_eq[id_simps]:
   1.258 +  shows "(list_all2 (op =)) = (op =)"
   1.259    unfolding expand_fun_eq
   1.260    apply(rule allI)+
   1.261    apply(induct_tac x xa rule: list_induct2')
   1.262    apply(simp_all)
   1.263    done
   1.264  
   1.265 -lemma list_rel_find_element:
   1.266 +lemma list_all2_find_element:
   1.267    assumes a: "x \<in> set a"
   1.268 -  and b: "list_rel R a b"
   1.269 +  and b: "list_all2 R a b"
   1.270    shows "\<exists>y. (y \<in> set b \<and> R x y)"
   1.271  proof -
   1.272 -  have "length a = length b" using b by (rule list_rel_len)
   1.273 +  have "length a = length b" using b by (rule list_all2_lengthD)
   1.274    then show ?thesis using a b by (induct a b rule: list_induct2) auto
   1.275  qed
   1.276  
   1.277 -lemma list_rel_refl:
   1.278 +lemma list_all2_refl:
   1.279    assumes a: "\<And>x y. R x y = (R x = R y)"
   1.280 -  shows "list_rel R x x"
   1.281 +  shows "list_all2 R x x"
   1.282    by (induct x) (auto simp add: a)
   1.283  
   1.284  end