src/HOL/List.thy
changeset 67399 eab6ce8368fa
parent 67171 2f213405cc0e
child 67443 3abf6a722518
equal deleted inserted replaced
67398:5eb932e604a2 67399:eab6ce8368fa
   264 "splice (x#xs) (y#ys) = x # y # splice xs ys"
   264 "splice (x#xs) (y#ys) = x # y # splice xs ys"
   265 
   265 
   266 function shuffle where
   266 function shuffle where
   267   "shuffle [] ys = {ys}"
   267   "shuffle [] ys = {ys}"
   268 | "shuffle xs [] = {xs}"
   268 | "shuffle xs [] = {xs}"
   269 | "shuffle (x # xs) (y # ys) = op # x ` shuffle xs (y # ys) \<union> op # y ` shuffle (x # xs) ys"
   269 | "shuffle (x # xs) (y # ys) = (#) x ` shuffle xs (y # ys) \<union> (#) y ` shuffle (x # xs) ys"
   270   by pat_completeness simp_all
   270   by pat_completeness simp_all
   271 termination by lexicographic_order
   271 termination by lexicographic_order
   272 
   272 
   273 text\<open>Use only if you cannot use @{const Min} instead:\<close>
   273 text\<open>Use only if you cannot use @{const Min} instead:\<close>
   274 fun min_list :: "'a::ord list \<Rightarrow> 'a" where
   274 fun min_list :: "'a::ord list \<Rightarrow> 'a" where
   813 by(induction xs rule: induct_list012) auto
   813 by(induction xs rule: induct_list012) auto
   814 
   814 
   815 lemma inj_split_Cons: "inj_on (\<lambda>(xs, n). n#xs) X"
   815 lemma inj_split_Cons: "inj_on (\<lambda>(xs, n). n#xs) X"
   816   by (auto intro!: inj_onI)
   816   by (auto intro!: inj_onI)
   817 
   817 
   818 lemma inj_on_Cons1 [simp]: "inj_on (op # x) A"
   818 lemma inj_on_Cons1 [simp]: "inj_on ((#) x) A"
   819 by(simp add: inj_on_def)
   819 by(simp add: inj_on_def)
   820 
   820 
   821 subsubsection \<open>@{const length}\<close>
   821 subsubsection \<open>@{const length}\<close>
   822 
   822 
   823 text \<open>
   823 text \<open>
   935         val neq_len = HOLogic.mk_Trueprop (HOLogic.Not $ eq_len);
   935         val neq_len = HOLogic.mk_Trueprop (HOLogic.Not $ eq_len);
   936         val thm = Goal.prove ctxt [] [] neq_len
   936         val thm = Goal.prove ctxt [] [] neq_len
   937           (K (simp_tac (put_simpset ss ctxt) 1));
   937           (K (simp_tac (put_simpset ss ctxt) 1));
   938       in SOME (thm RS @{thm neq_if_length_neq}) end
   938       in SOME (thm RS @{thm neq_if_length_neq}) end
   939   in
   939   in
   940     if m < n andalso submultiset (op aconv) (ls,rs) orelse
   940     if m < n andalso submultiset (aconv) (ls,rs) orelse
   941        n < m andalso submultiset (op aconv) (rs,ls)
   941        n < m andalso submultiset (aconv) (rs,ls)
   942     then prove_neq() else NONE
   942     then prove_neq() else NONE
   943   end;
   943   end;
   944 in K list_neq end;
   944 in K list_neq end;
   945 \<close>
   945 \<close>
   946 
   946 
  2788 apply (induct xs arbitrary: ys, simp)
  2788 apply (induct xs arbitrary: ys, simp)
  2789 apply (case_tac ys, auto)
  2789 apply (case_tac ys, auto)
  2790 done
  2790 done
  2791 
  2791 
  2792 lemma list_all2_eq:
  2792 lemma list_all2_eq:
  2793   "xs = ys \<longleftrightarrow> list_all2 (op =) xs ys"
  2793   "xs = ys \<longleftrightarrow> list_all2 (=) xs ys"
  2794 by (induct xs ys rule: list_induct2') auto
  2794 by (induct xs ys rule: list_induct2') auto
  2795 
  2795 
  2796 lemma list_eq_iff_zip_eq:
  2796 lemma list_eq_iff_zip_eq:
  2797   "xs = ys \<longleftrightarrow> length xs = length ys \<and> (\<forall>(x,y) \<in> set (zip xs ys). x = y)"
  2797   "xs = ys \<longleftrightarrow> length xs = length ys \<and> (\<forall>(x,y) \<in> set (zip xs ys). x = y)"
  2798 by(auto simp add: set_zip list_all2_eq list_all2_conv_all_nth cong: conj_cong)
  2798 by(auto simp add: set_zip list_all2_eq list_all2_conv_all_nth cong: conj_cong)
  2800 lemma list_all2_same: "list_all2 P xs xs \<longleftrightarrow> (\<forall>x\<in>set xs. P x x)"
  2800 lemma list_all2_same: "list_all2 P xs xs \<longleftrightarrow> (\<forall>x\<in>set xs. P x x)"
  2801 by(auto simp add: list_all2_conv_all_nth set_conv_nth)
  2801 by(auto simp add: list_all2_conv_all_nth set_conv_nth)
  2802 
  2802 
  2803 lemma zip_assoc:
  2803 lemma zip_assoc:
  2804   "zip xs (zip ys zs) = map (\<lambda>((x, y), z). (x, y, z)) (zip (zip xs ys) zs)"
  2804   "zip xs (zip ys zs) = map (\<lambda>((x, y), z). (x, y, z)) (zip (zip xs ys) zs)"
  2805 by(rule list_all2_all_nthI[where P="op =", unfolded list.rel_eq]) simp_all
  2805 by(rule list_all2_all_nthI[where P="(=)", unfolded list.rel_eq]) simp_all
  2806 
  2806 
  2807 lemma zip_commute: "zip xs ys = map (\<lambda>(x, y). (y, x)) (zip ys xs)"
  2807 lemma zip_commute: "zip xs ys = map (\<lambda>(x, y). (y, x)) (zip ys xs)"
  2808 by(rule list_all2_all_nthI[where P="op =", unfolded list.rel_eq]) simp_all
  2808 by(rule list_all2_all_nthI[where P="(=)", unfolded list.rel_eq]) simp_all
  2809 
  2809 
  2810 lemma zip_left_commute:
  2810 lemma zip_left_commute:
  2811   "zip xs (zip ys zs) = map (\<lambda>(y, (x, z)). (x, y, z)) (zip ys (zip xs zs))"
  2811   "zip xs (zip ys zs) = map (\<lambda>(y, (x, z)). (x, y, z)) (zip ys (zip xs zs))"
  2812 by(rule list_all2_all_nthI[where P="op =", unfolded list.rel_eq]) simp_all
  2812 by(rule list_all2_all_nthI[where P="(=)", unfolded list.rel_eq]) simp_all
  2813 
  2813 
  2814 lemma zip_replicate2: "zip xs (replicate n y) = map (\<lambda>x. (x, y)) (take n xs)"
  2814 lemma zip_replicate2: "zip xs (replicate n y) = map (\<lambda>x. (x, y)) (take n xs)"
  2815 by(subst zip_commute)(simp add: zip_replicate1)
  2815 by(subst zip_commute)(simp add: zip_replicate1)
  2816 
  2816 
  2817 subsubsection \<open>@{const List.product} and @{const product_lists}\<close>
  2817 subsubsection \<open>@{const List.product} and @{const product_lists}\<close>
  3407 lemma inj_on_nth: "distinct xs \<Longrightarrow> \<forall>i \<in> I. i < length xs \<Longrightarrow> inj_on (nth xs) I"
  3407 lemma inj_on_nth: "distinct xs \<Longrightarrow> \<forall>i \<in> I. i < length xs \<Longrightarrow> inj_on (nth xs) I"
  3408 by (rule inj_onI) (simp add: nth_eq_iff_index_eq)
  3408 by (rule inj_onI) (simp add: nth_eq_iff_index_eq)
  3409 
  3409 
  3410 lemma bij_betw_nth:
  3410 lemma bij_betw_nth:
  3411   assumes "distinct xs" "A = {..<length xs}" "B = set xs"
  3411   assumes "distinct xs" "A = {..<length xs}" "B = set xs"
  3412   shows   "bij_betw (op ! xs) A B"
  3412   shows   "bij_betw ((!) xs) A B"
  3413   using assms unfolding bij_betw_def
  3413   using assms unfolding bij_betw_def
  3414   by (auto intro!: inj_on_nth simp: set_conv_nth)
  3414   by (auto intro!: inj_on_nth simp: set_conv_nth)
  3415 
  3415 
  3416 lemma set_update_distinct: "\<lbrakk> distinct xs;  n < length xs \<rbrakk> \<Longrightarrow>
  3416 lemma set_update_distinct: "\<lbrakk> distinct xs;  n < length xs \<rbrakk> \<Longrightarrow>
  3417   set(xs[n := x]) = insert x (set xs - {xs!n})"
  3417   set(xs[n := x]) = insert x (set xs - {xs!n})"
  3607         by (cases i) (auto simp: f0)
  3607         by (cases i) (auto simp: f0)
  3608     next
  3608     next
  3609       have id: "{0 ..< length (?x1 zs)} = insert 0 (?Succ ` {0 ..< length zs})"
  3609       have id: "{0 ..< length (?x1 zs)} = insert 0 (?Succ ` {0 ..< length zs})"
  3610         using zsne by (cases ?cond, auto)
  3610         using zsne by (cases ?cond, auto)
  3611       { fix i  assume "i < Suc (length xs)"
  3611       { fix i  assume "i < Suc (length xs)"
  3612         hence "Suc i \<in> {0..<Suc (Suc (length xs))} \<inter> Collect (op < 0)" by auto
  3612         hence "Suc i \<in> {0..<Suc (Suc (length xs))} \<inter> Collect ((<) 0)" by auto
  3613         from imageI[OF this, of "\<lambda>i. ?Succ (f (i - Suc 0))"]
  3613         from imageI[OF this, of "\<lambda>i. ?Succ (f (i - Suc 0))"]
  3614         have "?Succ (f i) \<in> (\<lambda>i. ?Succ (f (i - Suc 0))) ` ({0..<Suc (Suc (length xs))} \<inter> Collect (op < 0))" by auto
  3614         have "?Succ (f i) \<in> (\<lambda>i. ?Succ (f (i - Suc 0))) ` ({0..<Suc (Suc (length xs))} \<inter> Collect ((<) 0))" by auto
  3615       }
  3615       }
  3616       then show "?f ` {0 ..< length ?xs} = {0 ..< length (?x1  zs)}"
  3616       then show "?f ` {0 ..< length ?xs} = {0 ..< length (?x1  zs)}"
  3617         unfolding id f_xs_zs[symmetric] by auto
  3617         unfolding id f_xs_zs[symmetric] by auto
  3618     qed
  3618     qed
  3619   qed
  3619   qed
  4606 qed simp_all
  4606 qed simp_all
  4607 
  4607 
  4608 lemma shuffle_commutes: "shuffle xs ys = shuffle ys xs"
  4608 lemma shuffle_commutes: "shuffle xs ys = shuffle ys xs"
  4609   by (induction xs ys rule: shuffle.induct) (simp_all add: Un_commute)
  4609   by (induction xs ys rule: shuffle.induct) (simp_all add: Un_commute)
  4610 
  4610 
  4611 lemma Cons_shuffle_subset1: "op # x ` shuffle xs ys \<subseteq> shuffle (x # xs) ys"
  4611 lemma Cons_shuffle_subset1: "(#) x ` shuffle xs ys \<subseteq> shuffle (x # xs) ys"
  4612   by (cases ys) auto
  4612   by (cases ys) auto
  4613 
  4613 
  4614 lemma Cons_shuffle_subset2: "op # y ` shuffle xs ys \<subseteq> shuffle xs (y # ys)"
  4614 lemma Cons_shuffle_subset2: "(#) y ` shuffle xs ys \<subseteq> shuffle xs (y # ys)"
  4615   by (cases xs) auto
  4615   by (cases xs) auto
  4616 
  4616 
  4617 lemma filter_shuffle:
  4617 lemma filter_shuffle:
  4618   "filter P ` shuffle xs ys = shuffle (filter P xs) (filter P ys)"
  4618   "filter P ` shuffle xs ys = shuffle (filter P xs) (filter P ys)"
  4619 proof -
  4619 proof -
  4620   have *: "filter P ` op # x ` A = (if P x then op # x ` filter P ` A else filter P ` A)" for x A
  4620   have *: "filter P ` (#) x ` A = (if P x then (#) x ` filter P ` A else filter P ` A)" for x A
  4621     by (auto simp: image_image)
  4621     by (auto simp: image_image)
  4622   show ?thesis
  4622   show ?thesis
  4623   by (induction xs ys rule: shuffle.induct)
  4623   by (induction xs ys rule: shuffle.induct)
  4624      (simp_all split: if_splits add: image_Un * Un_absorb1 Un_absorb2
  4624      (simp_all split: if_splits add: image_Un * Un_absorb1 Un_absorb2
  4625            Cons_shuffle_subset1 Cons_shuffle_subset2)
  4625            Cons_shuffle_subset1 Cons_shuffle_subset2)
  4659 proof (induction xs)
  4659 proof (induction xs)
  4660   case (Cons x xs)
  4660   case (Cons x xs)
  4661   show ?case
  4661   show ?case
  4662   proof (cases "P x")
  4662   proof (cases "P x")
  4663     case True
  4663     case True
  4664     hence "x # xs \<in> op # x ` shuffle (filter P xs) (filter (\<lambda>x. \<not>P x) xs)"
  4664     hence "x # xs \<in> (#) x ` shuffle (filter P xs) (filter (\<lambda>x. \<not>P x) xs)"
  4665       by (intro imageI Cons.IH)
  4665       by (intro imageI Cons.IH)
  4666     also have "\<dots> \<subseteq> shuffle (filter P (x # xs)) (filter (\<lambda>x. \<not>P x) (x # xs))"
  4666     also have "\<dots> \<subseteq> shuffle (filter P (x # xs)) (filter (\<lambda>x. \<not>P x) (x # xs))"
  4667       by (simp add: True Cons_shuffle_subset1)
  4667       by (simp add: True Cons_shuffle_subset1)
  4668     finally show ?thesis .
  4668     finally show ?thesis .
  4669   next
  4669   next
  4670     case False
  4670     case False
  4671     hence "x # xs \<in> op # x ` shuffle (filter P xs) (filter (\<lambda>x. \<not>P x) xs)"
  4671     hence "x # xs \<in> (#) x ` shuffle (filter P xs) (filter (\<lambda>x. \<not>P x) xs)"
  4672       by (intro imageI Cons.IH)
  4672       by (intro imageI Cons.IH)
  4673     also have "\<dots> \<subseteq> shuffle (filter P (x # xs)) (filter (\<lambda>x. \<not>P x) (x # xs))"
  4673     also have "\<dots> \<subseteq> shuffle (filter P (x # xs)) (filter (\<lambda>x. \<not>P x) (x # xs))"
  4674       by (simp add: False Cons_shuffle_subset2)
  4674       by (simp add: False Cons_shuffle_subset2)
  4675     finally show ?thesis .
  4675     finally show ?thesis .
  4676   qed
  4676   qed
  4943   "(\<And>x y. P x y \<Longrightarrow> Q x y) \<Longrightarrow> sorted_wrt P xs \<Longrightarrow> sorted_wrt Q xs"
  4943   "(\<And>x y. P x y \<Longrightarrow> Q x y) \<Longrightarrow> sorted_wrt P xs \<Longrightarrow> sorted_wrt Q xs"
  4944 by(induction xs rule: induct_list012)(auto)
  4944 by(induction xs rule: induct_list012)(auto)
  4945 
  4945 
  4946 text \<open>Strictly Ascending Sequences of Natural Numbers\<close>
  4946 text \<open>Strictly Ascending Sequences of Natural Numbers\<close>
  4947 
  4947 
  4948 lemma sorted_wrt_upt[simp]: "sorted_wrt (op <) [0..<n]"
  4948 lemma sorted_wrt_upt[simp]: "sorted_wrt (<) [0..<n]"
  4949 by(induction n) (auto simp: sorted_wrt_append)
  4949 by(induction n) (auto simp: sorted_wrt_append)
  4950 
  4950 
  4951 text \<open>Each element is greater or equal to its index:\<close>
  4951 text \<open>Each element is greater or equal to its index:\<close>
  4952 
  4952 
  4953 lemma sorted_wrt_less_idx:
  4953 lemma sorted_wrt_less_idx:
  4954   "sorted_wrt (op <) ns \<Longrightarrow> i < length ns \<Longrightarrow> i \<le> ns!i"
  4954   "sorted_wrt (<) ns \<Longrightarrow> i < length ns \<Longrightarrow> i \<le> ns!i"
  4955 proof (induction ns arbitrary: i rule: rev_induct)
  4955 proof (induction ns arbitrary: i rule: rev_induct)
  4956   case Nil thus ?case by simp
  4956   case Nil thus ?case by simp
  4957 next
  4957 next
  4958   case snoc
  4958   case snoc
  4959   thus ?case
  4959   thus ?case
  4970 lemma sorted_Cons: "sorted (x#xs) = (sorted xs \<and> (\<forall>y \<in> set xs. x \<le> y))"
  4970 lemma sorted_Cons: "sorted (x#xs) = (sorted xs \<and> (\<forall>y \<in> set xs. x \<le> y))"
  4971 apply(induction xs arbitrary: x)
  4971 apply(induction xs arbitrary: x)
  4972  apply simp
  4972  apply simp
  4973 by simp (blast intro: order_trans)
  4973 by simp (blast intro: order_trans)
  4974 
  4974 
  4975 lemma sorted_iff_wrt: "sorted xs = sorted_wrt (op \<le>) xs"
  4975 lemma sorted_iff_wrt: "sorted xs = sorted_wrt (\<le>) xs"
  4976 proof
  4976 proof
  4977   assume "sorted xs" thus "sorted_wrt (op \<le>) xs"
  4977   assume "sorted xs" thus "sorted_wrt (\<le>) xs"
  4978   proof (induct xs rule: sorted.induct)
  4978   proof (induct xs rule: sorted.induct)
  4979     case (Cons xs x) thus ?case by (cases xs) simp_all
  4979     case (Cons xs x) thus ?case by (cases xs) simp_all
  4980   qed simp
  4980   qed simp
  4981 qed (induct xs rule: induct_list012, simp_all)
  4981 qed (induct xs rule: induct_list012, simp_all)
  4982 
  4982 
  5265 
  5265 
  5266 lemma insort_remove1:
  5266 lemma insort_remove1:
  5267   assumes "a \<in> set xs" and "sorted xs"
  5267   assumes "a \<in> set xs" and "sorted xs"
  5268   shows "insort a (remove1 a xs) = xs"
  5268   shows "insort a (remove1 a xs) = xs"
  5269 proof (rule insort_key_remove1)
  5269 proof (rule insort_key_remove1)
  5270   define n where "n = length (filter (op = a) xs) - 1"
  5270   define n where "n = length (filter ((=) a) xs) - 1"
  5271   from \<open>a \<in> set xs\<close> show "a \<in> set xs" .
  5271   from \<open>a \<in> set xs\<close> show "a \<in> set xs" .
  5272   from \<open>sorted xs\<close> show "sorted (map (\<lambda>x. x) xs)" by simp
  5272   from \<open>sorted xs\<close> show "sorted (map (\<lambda>x. x) xs)" by simp
  5273   from \<open>a \<in> set xs\<close> have "a \<in> set (filter (op = a) xs)" by auto
  5273   from \<open>a \<in> set xs\<close> have "a \<in> set (filter ((=) a) xs)" by auto
  5274   then have "set (filter (op = a) xs) \<noteq> {}" by auto
  5274   then have "set (filter ((=) a) xs) \<noteq> {}" by auto
  5275   then have "filter (op = a) xs \<noteq> []" by (auto simp only: set_empty)
  5275   then have "filter ((=) a) xs \<noteq> []" by (auto simp only: set_empty)
  5276   then have "length (filter (op = a) xs) > 0" by simp
  5276   then have "length (filter ((=) a) xs) > 0" by simp
  5277   then have n: "Suc n = length (filter (op = a) xs)" by (simp add: n_def)
  5277   then have n: "Suc n = length (filter ((=) a) xs)" by (simp add: n_def)
  5278   moreover have "replicate (Suc n) a = a # replicate n a"
  5278   moreover have "replicate (Suc n) a = a # replicate n a"
  5279     by simp
  5279     by simp
  5280   ultimately show "hd (filter (op = a) xs) = a" by (simp add: replicate_length_filter)
  5280   ultimately show "hd (filter ((=) a) xs) = a" by (simp add: replicate_length_filter)
  5281 qed
  5281 qed
  5282 
  5282 
  5283 lemma finite_sorted_distinct_unique:
  5283 lemma finite_sorted_distinct_unique:
  5284 shows "finite A \<Longrightarrow> \<exists>!xs. set xs = A \<and> sorted xs \<and> distinct xs"
  5284 shows "finite A \<Longrightarrow> \<exists>!xs. set xs = A \<and> sorted xs \<and> distinct xs"
  5285 apply(drule finite_distinct_list)
  5285 apply(drule finite_distinct_list)
  7053 
  7053 
  7054 
  7054 
  7055 subsubsection \<open>Use convenient predefined operations\<close>
  7055 subsubsection \<open>Use convenient predefined operations\<close>
  7056 
  7056 
  7057 code_printing
  7057 code_printing
  7058   constant "op @" \<rightharpoonup>
  7058   constant "(@)" \<rightharpoonup>
  7059     (SML) infixr 7 "@"
  7059     (SML) infixr 7 "@"
  7060     and (OCaml) infixr 6 "@"
  7060     and (OCaml) infixr 6 "@"
  7061     and (Haskell) infixr 5 "++"
  7061     and (Haskell) infixr 5 "++"
  7062     and (Scala) infixl 7 "++"
  7062     and (Scala) infixl 7 "++"
  7063 | constant map \<rightharpoonup>
  7063 | constant map \<rightharpoonup>
  7227 lemma rev_transfer [transfer_rule]:
  7227 lemma rev_transfer [transfer_rule]:
  7228   "(list_all2 A ===> list_all2 A) rev rev"
  7228   "(list_all2 A ===> list_all2 A) rev rev"
  7229   unfolding List.rev_def by transfer_prover
  7229   unfolding List.rev_def by transfer_prover
  7230 
  7230 
  7231 lemma filter_transfer [transfer_rule]:
  7231 lemma filter_transfer [transfer_rule]:
  7232   "((A ===> op =) ===> list_all2 A ===> list_all2 A) filter filter"
  7232   "((A ===> (=)) ===> list_all2 A ===> list_all2 A) filter filter"
  7233   unfolding List.filter_def by transfer_prover
  7233   unfolding List.filter_def by transfer_prover
  7234 
  7234 
  7235 lemma fold_transfer [transfer_rule]:
  7235 lemma fold_transfer [transfer_rule]:
  7236   "((A ===> B ===> B) ===> list_all2 A ===> B ===> B) fold fold"
  7236   "((A ===> B ===> B) ===> list_all2 A ===> B ===> B) fold fold"
  7237   unfolding List.fold_def by transfer_prover
  7237   unfolding List.fold_def by transfer_prover
  7247 lemma concat_transfer [transfer_rule]:
  7247 lemma concat_transfer [transfer_rule]:
  7248   "(list_all2 (list_all2 A) ===> list_all2 A) concat concat"
  7248   "(list_all2 (list_all2 A) ===> list_all2 A) concat concat"
  7249   unfolding List.concat_def by transfer_prover
  7249   unfolding List.concat_def by transfer_prover
  7250 
  7250 
  7251 lemma drop_transfer [transfer_rule]:
  7251 lemma drop_transfer [transfer_rule]:
  7252   "(op = ===> list_all2 A ===> list_all2 A) drop drop"
  7252   "((=) ===> list_all2 A ===> list_all2 A) drop drop"
  7253   unfolding List.drop_def by transfer_prover
  7253   unfolding List.drop_def by transfer_prover
  7254 
  7254 
  7255 lemma take_transfer [transfer_rule]:
  7255 lemma take_transfer [transfer_rule]:
  7256   "(op = ===> list_all2 A ===> list_all2 A) take take"
  7256   "((=) ===> list_all2 A ===> list_all2 A) take take"
  7257   unfolding List.take_def by transfer_prover
  7257   unfolding List.take_def by transfer_prover
  7258 
  7258 
  7259 lemma list_update_transfer [transfer_rule]:
  7259 lemma list_update_transfer [transfer_rule]:
  7260   "(list_all2 A ===> op = ===> A ===> list_all2 A) list_update list_update"
  7260   "(list_all2 A ===> (=) ===> A ===> list_all2 A) list_update list_update"
  7261   unfolding list_update_def by transfer_prover
  7261   unfolding list_update_def by transfer_prover
  7262 
  7262 
  7263 lemma takeWhile_transfer [transfer_rule]:
  7263 lemma takeWhile_transfer [transfer_rule]:
  7264   "((A ===> op =) ===> list_all2 A ===> list_all2 A) takeWhile takeWhile"
  7264   "((A ===> (=)) ===> list_all2 A ===> list_all2 A) takeWhile takeWhile"
  7265   unfolding takeWhile_def by transfer_prover
  7265   unfolding takeWhile_def by transfer_prover
  7266 
  7266 
  7267 lemma dropWhile_transfer [transfer_rule]:
  7267 lemma dropWhile_transfer [transfer_rule]:
  7268   "((A ===> op =) ===> list_all2 A ===> list_all2 A) dropWhile dropWhile"
  7268   "((A ===> (=)) ===> list_all2 A ===> list_all2 A) dropWhile dropWhile"
  7269   unfolding dropWhile_def by transfer_prover
  7269   unfolding dropWhile_def by transfer_prover
  7270 
  7270 
  7271 lemma zip_transfer [transfer_rule]:
  7271 lemma zip_transfer [transfer_rule]:
  7272   "(list_all2 A ===> list_all2 B ===> list_all2 (rel_prod A B)) zip zip"
  7272   "(list_all2 A ===> list_all2 B ===> list_all2 (rel_prod A B)) zip zip"
  7273   unfolding zip_def by transfer_prover
  7273   unfolding zip_def by transfer_prover
  7284   assumes [transfer_rule]: "bi_unique A"
  7284   assumes [transfer_rule]: "bi_unique A"
  7285   shows "(A ===> list_all2 A ===> list_all2 A) List.insert List.insert"
  7285   shows "(A ===> list_all2 A ===> list_all2 A) List.insert List.insert"
  7286   unfolding List.insert_def [abs_def] by transfer_prover
  7286   unfolding List.insert_def [abs_def] by transfer_prover
  7287 
  7287 
  7288 lemma find_transfer [transfer_rule]:
  7288 lemma find_transfer [transfer_rule]:
  7289   "((A ===> op =) ===> list_all2 A ===> rel_option A) List.find List.find"
  7289   "((A ===> (=)) ===> list_all2 A ===> rel_option A) List.find List.find"
  7290   unfolding List.find_def by transfer_prover
  7290   unfolding List.find_def by transfer_prover
  7291 
  7291 
  7292 lemma those_transfer [transfer_rule]:
  7292 lemma those_transfer [transfer_rule]:
  7293   "(list_all2 (rel_option P) ===> rel_option (list_all2 P)) those those"
  7293   "(list_all2 (rel_option P) ===> rel_option (list_all2 P)) those those"
  7294   unfolding List.those_def by transfer_prover
  7294   unfolding List.those_def by transfer_prover
  7303   shows "(A ===> list_all2 A ===> list_all2 A) removeAll removeAll"
  7303   shows "(A ===> list_all2 A ===> list_all2 A) removeAll removeAll"
  7304   unfolding removeAll_def by transfer_prover
  7304   unfolding removeAll_def by transfer_prover
  7305 
  7305 
  7306 lemma distinct_transfer [transfer_rule]:
  7306 lemma distinct_transfer [transfer_rule]:
  7307   assumes [transfer_rule]: "bi_unique A"
  7307   assumes [transfer_rule]: "bi_unique A"
  7308   shows "(list_all2 A ===> op =) distinct distinct"
  7308   shows "(list_all2 A ===> (=)) distinct distinct"
  7309   unfolding distinct_def by transfer_prover
  7309   unfolding distinct_def by transfer_prover
  7310 
  7310 
  7311 lemma remdups_transfer [transfer_rule]:
  7311 lemma remdups_transfer [transfer_rule]:
  7312   assumes [transfer_rule]: "bi_unique A"
  7312   assumes [transfer_rule]: "bi_unique A"
  7313   shows "(list_all2 A ===> list_all2 A) remdups remdups"
  7313   shows "(list_all2 A ===> list_all2 A) remdups remdups"
  7318   shows "(list_all2 A ===> list_all2 A) remdups_adj remdups_adj"
  7318   shows "(list_all2 A ===> list_all2 A) remdups_adj remdups_adj"
  7319   proof (rule rel_funI, erule list_all2_induct)
  7319   proof (rule rel_funI, erule list_all2_induct)
  7320   qed (auto simp: remdups_adj_Cons assms[unfolded bi_unique_def] split: list.splits)
  7320   qed (auto simp: remdups_adj_Cons assms[unfolded bi_unique_def] split: list.splits)
  7321 
  7321 
  7322 lemma replicate_transfer [transfer_rule]:
  7322 lemma replicate_transfer [transfer_rule]:
  7323   "(op = ===> A ===> list_all2 A) replicate replicate"
  7323   "((=) ===> A ===> list_all2 A) replicate replicate"
  7324   unfolding replicate_def by transfer_prover
  7324   unfolding replicate_def by transfer_prover
  7325 
  7325 
  7326 lemma length_transfer [transfer_rule]:
  7326 lemma length_transfer [transfer_rule]:
  7327   "(list_all2 A ===> op =) length length"
  7327   "(list_all2 A ===> (=)) length length"
  7328   unfolding size_list_overloaded_def size_list_def by transfer_prover
  7328   unfolding size_list_overloaded_def size_list_def by transfer_prover
  7329 
  7329 
  7330 lemma rotate1_transfer [transfer_rule]:
  7330 lemma rotate1_transfer [transfer_rule]:
  7331   "(list_all2 A ===> list_all2 A) rotate1 rotate1"
  7331   "(list_all2 A ===> list_all2 A) rotate1 rotate1"
  7332   unfolding rotate1_def by transfer_prover
  7332   unfolding rotate1_def by transfer_prover
  7333 
  7333 
  7334 lemma rotate_transfer [transfer_rule]:
  7334 lemma rotate_transfer [transfer_rule]:
  7335   "(op = ===> list_all2 A ===> list_all2 A) rotate rotate"
  7335   "((=) ===> list_all2 A ===> list_all2 A) rotate rotate"
  7336   unfolding rotate_def [abs_def] by transfer_prover
  7336   unfolding rotate_def [abs_def] by transfer_prover
  7337 
  7337 
  7338 lemma nths_transfer [transfer_rule]:
  7338 lemma nths_transfer [transfer_rule]:
  7339   "(list_all2 A ===> rel_set (op =) ===> list_all2 A) nths nths"
  7339   "(list_all2 A ===> rel_set (=) ===> list_all2 A) nths nths"
  7340   unfolding nths_def [abs_def] by transfer_prover
  7340   unfolding nths_def [abs_def] by transfer_prover
  7341 
  7341 
  7342 lemma subseqs_transfer [transfer_rule]:
  7342 lemma subseqs_transfer [transfer_rule]:
  7343   "(list_all2 A ===> list_all2 (list_all2 A)) subseqs subseqs"
  7343   "(list_all2 A ===> list_all2 (list_all2 A)) subseqs subseqs"
  7344   unfolding subseqs_def [abs_def] by transfer_prover
  7344   unfolding subseqs_def [abs_def] by transfer_prover
  7345 
  7345 
  7346 lemma partition_transfer [transfer_rule]:
  7346 lemma partition_transfer [transfer_rule]:
  7347   "((A ===> op =) ===> list_all2 A ===> rel_prod (list_all2 A) (list_all2 A))
  7347   "((A ===> (=)) ===> list_all2 A ===> rel_prod (list_all2 A) (list_all2 A))
  7348     partition partition"
  7348     partition partition"
  7349   unfolding partition_def by transfer_prover
  7349   unfolding partition_def by transfer_prover
  7350 
  7350 
  7351 lemma lists_transfer [transfer_rule]:
  7351 lemma lists_transfer [transfer_rule]:
  7352   "(rel_set A ===> rel_set (list_all2 A)) lists lists"
  7352   "(rel_set A ===> rel_set (list_all2 A)) lists lists"
  7369 lemma listset_transfer [transfer_rule]:
  7369 lemma listset_transfer [transfer_rule]:
  7370   "(list_all2 (rel_set A) ===> rel_set (list_all2 A)) listset listset"
  7370   "(list_all2 (rel_set A) ===> rel_set (list_all2 A)) listset listset"
  7371   unfolding listset_def by transfer_prover
  7371   unfolding listset_def by transfer_prover
  7372 
  7372 
  7373 lemma null_transfer [transfer_rule]:
  7373 lemma null_transfer [transfer_rule]:
  7374   "(list_all2 A ===> op =) List.null List.null"
  7374   "(list_all2 A ===> (=)) List.null List.null"
  7375   unfolding rel_fun_def List.null_def by auto
  7375   unfolding rel_fun_def List.null_def by auto
  7376 
  7376 
  7377 lemma list_all_transfer [transfer_rule]:
  7377 lemma list_all_transfer [transfer_rule]:
  7378   "((A ===> op =) ===> list_all2 A ===> op =) list_all list_all"
  7378   "((A ===> (=)) ===> list_all2 A ===> (=)) list_all list_all"
  7379   unfolding list_all_iff [abs_def] by transfer_prover
  7379   unfolding list_all_iff [abs_def] by transfer_prover
  7380 
  7380 
  7381 lemma list_ex_transfer [transfer_rule]:
  7381 lemma list_ex_transfer [transfer_rule]:
  7382   "((A ===> op =) ===> list_all2 A ===> op =) list_ex list_ex"
  7382   "((A ===> (=)) ===> list_all2 A ===> (=)) list_ex list_ex"
  7383   unfolding list_ex_iff [abs_def] by transfer_prover
  7383   unfolding list_ex_iff [abs_def] by transfer_prover
  7384 
  7384 
  7385 lemma splice_transfer [transfer_rule]:
  7385 lemma splice_transfer [transfer_rule]:
  7386   "(list_all2 A ===> list_all2 A ===> list_all2 A) splice splice"
  7386   "(list_all2 A ===> list_all2 A ===> list_all2 A) splice splice"
  7387   apply (rule rel_funI, erule list_all2_induct, simp add: rel_fun_def, simp)
  7387   apply (rule rel_funI, erule list_all2_induct, simp add: rel_fun_def, simp)
  7401     have [transfer_rule]: "A x x'" "A y y'" "list_all2 A xs xs''" "list_all2 A ys ys''"
  7401     have [transfer_rule]: "A x x'" "A y y'" "list_all2 A xs xs''" "list_all2 A ys ys''"
  7402       using "3.prems" by (simp_all add: xs' ys')
  7402       using "3.prems" by (simp_all add: xs' ys')
  7403     have [transfer_rule]: "rel_set (list_all2 A) (shuffle xs (y # ys)) (shuffle xs'' ys')" and
  7403     have [transfer_rule]: "rel_set (list_all2 A) (shuffle xs (y # ys)) (shuffle xs'' ys')" and
  7404          [transfer_rule]: "rel_set (list_all2 A) (shuffle (x # xs) ys) (shuffle xs' ys'')"
  7404          [transfer_rule]: "rel_set (list_all2 A) (shuffle (x # xs) ys) (shuffle xs' ys'')"
  7405       using "3.prems" by (auto intro!: "3.IH" simp: xs' ys')
  7405       using "3.prems" by (auto intro!: "3.IH" simp: xs' ys')
  7406     have "rel_set (list_all2 A) (op # x ` shuffle xs (y # ys) \<union> op # y ` shuffle (x # xs) ys)
  7406     have "rel_set (list_all2 A) ((#) x ` shuffle xs (y # ys) \<union> (#) y ` shuffle (x # xs) ys)
  7407                (op # x' ` shuffle xs'' ys' \<union> op # y' ` shuffle xs' ys'')" by transfer_prover
  7407                ((#) x' ` shuffle xs'' ys' \<union> (#) y' ` shuffle xs' ys'')" by transfer_prover
  7408     thus ?case by (simp add: xs' ys')
  7408     thus ?case by (simp add: xs' ys')
  7409   qed (auto simp: rel_set_def)
  7409   qed (auto simp: rel_set_def)
  7410 qed
  7410 qed
  7411 
  7411 
  7412 lemma rtrancl_parametric [transfer_rule]:
  7412 lemma rtrancl_parametric [transfer_rule]:
  7414   shows "(rel_set (rel_prod A A) ===> rel_set (rel_prod A A)) rtrancl rtrancl"
  7414   shows "(rel_set (rel_prod A A) ===> rel_set (rel_prod A A)) rtrancl rtrancl"
  7415 unfolding rtrancl_def by transfer_prover
  7415 unfolding rtrancl_def by transfer_prover
  7416 
  7416 
  7417 lemma monotone_parametric [transfer_rule]:
  7417 lemma monotone_parametric [transfer_rule]:
  7418   assumes [transfer_rule]: "bi_total A"
  7418   assumes [transfer_rule]: "bi_total A"
  7419   shows "((A ===> A ===> op =) ===> (B ===> B ===> op =) ===> (A ===> B) ===> op =) monotone monotone"
  7419   shows "((A ===> A ===> (=)) ===> (B ===> B ===> (=)) ===> (A ===> B) ===> (=)) monotone monotone"
  7420 unfolding monotone_def[abs_def] by transfer_prover
  7420 unfolding monotone_def[abs_def] by transfer_prover
  7421 
  7421 
  7422 lemma fun_ord_parametric [transfer_rule]:
  7422 lemma fun_ord_parametric [transfer_rule]:
  7423   assumes [transfer_rule]: "bi_total C"
  7423   assumes [transfer_rule]: "bi_total C"
  7424   shows "((A ===> B ===> op =) ===> (C ===> A) ===> (C ===> B) ===> op =) fun_ord fun_ord"
  7424   shows "((A ===> B ===> (=)) ===> (C ===> A) ===> (C ===> B) ===> (=)) fun_ord fun_ord"
  7425 unfolding fun_ord_def[abs_def] by transfer_prover
  7425 unfolding fun_ord_def[abs_def] by transfer_prover
  7426 
  7426 
  7427 lemma fun_lub_parametric [transfer_rule]:
  7427 lemma fun_lub_parametric [transfer_rule]:
  7428   assumes [transfer_rule]: "bi_total A"  "bi_unique A"
  7428   assumes [transfer_rule]: "bi_total A"  "bi_unique A"
  7429   shows "((rel_set A ===> B) ===> rel_set (C ===> A) ===> C ===> B) fun_lub fun_lub"
  7429   shows "((rel_set A ===> B) ===> rel_set (C ===> A) ===> C ===> B) fun_lub fun_lub"