clasohm@1465: (* Title: HOL/List
clasohm@923: ID: $Id$
clasohm@1465: Author: Tobias Nipkow
clasohm@923: Copyright 1994 TU Muenchen
clasohm@923:
clasohm@923: List lemmas
clasohm@923: *)
clasohm@923:
nipkow@3011: goal thy "!x. xs ~= x#xs";
nipkow@3040: by (induct_tac "xs" 1);
clasohm@1264: by (ALLGOALS Asm_simp_tac);
nipkow@2608: qed_spec_mp "not_Cons_self";
nipkow@2512: Addsimps [not_Cons_self];
clasohm@923:
nipkow@3011: goal thy "(xs ~= []) = (? y ys. xs = y#ys)";
nipkow@3040: by (induct_tac "xs" 1);
clasohm@1264: by (Simp_tac 1);
clasohm@1264: by (Asm_simp_tac 1);
clasohm@923: qed "neq_Nil_conv";
clasohm@923:
clasohm@923:
paulson@3342: (** List operator over sets **)
paulson@3342:
paulson@3342: goalw thy lists.defs "!!A B. A<=B ==> lists A <= lists B";
paulson@3342: by (rtac lfp_mono 1);
paulson@3342: by (REPEAT (ares_tac basic_monos 1));
paulson@3342: qed "lists_mono";
paulson@3196:
paulson@3196:
nipkow@2608: (** list_case **)
nipkow@2608:
nipkow@3011: goal thy
nipkow@2608: "P(list_case a f xs) = ((xs=[] --> P(a)) & \
paulson@2891: \ (!y ys. xs=y#ys --> P(f y ys)))";
nipkow@3040: by (induct_tac "xs" 1);
nipkow@2608: by (ALLGOALS Asm_simp_tac);
paulson@2891: by (Blast_tac 1);
nipkow@2608: qed "expand_list_case";
nipkow@2608:
nipkow@3011: val prems = goal thy "[| P([]); !!x xs. P(x#xs) |] ==> P(xs)";
paulson@3457: by (induct_tac "xs" 1);
paulson@3457: by (REPEAT(resolve_tac prems 1));
nipkow@2608: qed "list_cases";
nipkow@2608:
nipkow@3011: goal thy "(xs=[] --> P([])) & (!y ys. xs=y#ys --> P(y#ys)) --> P(xs)";
nipkow@3040: by (induct_tac "xs" 1);
paulson@2891: by (Blast_tac 1);
paulson@2891: by (Blast_tac 1);
nipkow@2608: bind_thm("list_eq_cases",
nipkow@2608: impI RSN (2,allI RSN (2,allI RSN (2,impI RS (conjI RS (result() RS mp))))));
nipkow@2608:
nipkow@2608:
clasohm@923: (** @ - append **)
clasohm@923:
nipkow@3467: section "@ - append";
nipkow@3467:
nipkow@3011: goal thy "(xs@ys)@zs = xs@(ys@zs)";
nipkow@3040: by (induct_tac "xs" 1);
clasohm@1264: by (ALLGOALS Asm_simp_tac);
clasohm@923: qed "append_assoc";
nipkow@2512: Addsimps [append_assoc];
clasohm@923:
nipkow@3011: goal thy "xs @ [] = xs";
nipkow@3040: by (induct_tac "xs" 1);
clasohm@1264: by (ALLGOALS Asm_simp_tac);
clasohm@923: qed "append_Nil2";
nipkow@2512: Addsimps [append_Nil2];
clasohm@923:
nipkow@3011: goal thy "(xs@ys = []) = (xs=[] & ys=[])";
nipkow@3040: by (induct_tac "xs" 1);
clasohm@1264: by (ALLGOALS Asm_simp_tac);
nipkow@2608: qed "append_is_Nil_conv";
nipkow@2608: AddIffs [append_is_Nil_conv];
nipkow@2608:
nipkow@3011: goal thy "([] = xs@ys) = (xs=[] & ys=[])";
nipkow@3040: by (induct_tac "xs" 1);
nipkow@2608: by (ALLGOALS Asm_simp_tac);
paulson@3457: by (Blast_tac 1);
nipkow@2608: qed "Nil_is_append_conv";
nipkow@2608: AddIffs [Nil_is_append_conv];
clasohm@923:
nipkow@3011: goal thy "(xs @ ys = xs @ zs) = (ys=zs)";
nipkow@3040: by (induct_tac "xs" 1);
clasohm@1264: by (ALLGOALS Asm_simp_tac);
clasohm@923: qed "same_append_eq";
nipkow@2608: AddIffs [same_append_eq];
nipkow@2608:
nipkow@3011: goal thy "!ys. (xs @ [x] = ys @ [y]) = (xs = ys & x = y)";
paulson@3457: by (induct_tac "xs" 1);
paulson@3457: by (rtac allI 1);
paulson@3457: by (induct_tac "ys" 1);
paulson@3457: by (ALLGOALS Asm_simp_tac);
paulson@3457: by (rtac allI 1);
paulson@3457: by (induct_tac "ys" 1);
paulson@3457: by (ALLGOALS Asm_simp_tac);
nipkow@2608: qed_spec_mp "append1_eq_conv";
nipkow@2608: AddIffs [append1_eq_conv];
nipkow@2608:
nipkow@3011: goal thy "xs ~= [] --> hd xs # tl xs = xs";
paulson@3457: by (induct_tac "xs" 1);
paulson@3457: by (ALLGOALS Asm_simp_tac);
nipkow@2608: qed_spec_mp "hd_Cons_tl";
nipkow@2608: Addsimps [hd_Cons_tl];
clasohm@923:
nipkow@3011: goal thy "hd(xs@ys) = (if xs=[] then hd ys else hd xs)";
nipkow@3040: by (induct_tac "xs" 1);
nipkow@1327: by (ALLGOALS Asm_simp_tac);
nipkow@1327: qed "hd_append";
clasohm@923:
nipkow@3011: goal thy "tl(xs@ys) = (case xs of [] => tl(ys) | z#zs => zs@ys)";
paulson@3457: by (simp_tac (!simpset setloop(split_tac[expand_list_case])) 1);
nipkow@2608: qed "tl_append";
nipkow@2608:
nipkow@2608: (** map **)
nipkow@2608:
nipkow@3467: section "map";
nipkow@3467:
nipkow@3011: goal thy
nipkow@3465: "(!x. x : set xs --> f x = g x) --> map f xs = map g xs";
paulson@3457: by (induct_tac "xs" 1);
paulson@3457: by (ALLGOALS Asm_simp_tac);
nipkow@2608: bind_thm("map_ext", impI RS (allI RS (result() RS mp)));
nipkow@2608:
nipkow@3011: goal thy "map (%x.x) = (%xs.xs)";
nipkow@2608: by (rtac ext 1);
nipkow@3040: by (induct_tac "xs" 1);
nipkow@2608: by (ALLGOALS Asm_simp_tac);
nipkow@2608: qed "map_ident";
nipkow@2608: Addsimps[map_ident];
nipkow@2608:
nipkow@3011: goal thy "map f (xs@ys) = map f xs @ map f ys";
nipkow@3040: by (induct_tac "xs" 1);
nipkow@2608: by (ALLGOALS Asm_simp_tac);
nipkow@2608: qed "map_append";
nipkow@2608: Addsimps[map_append];
nipkow@2608:
nipkow@3011: goalw thy [o_def] "map (f o g) xs = map f (map g xs)";
nipkow@3040: by (induct_tac "xs" 1);
nipkow@2608: by (ALLGOALS Asm_simp_tac);
nipkow@2608: qed "map_compose";
nipkow@2608: Addsimps[map_compose];
nipkow@2608:
nipkow@3011: goal thy "rev(map f xs) = map f (rev xs)";
nipkow@3040: by (induct_tac "xs" 1);
nipkow@2608: by (ALLGOALS Asm_simp_tac);
nipkow@2608: qed "rev_map";
nipkow@2608:
lcp@1169: (** rev **)
lcp@1169:
nipkow@3467: section "rev";
nipkow@3467:
nipkow@3011: goal thy "rev(xs@ys) = rev(ys) @ rev(xs)";
nipkow@3040: by (induct_tac "xs" 1);
nipkow@2512: by (ALLGOALS Asm_simp_tac);
lcp@1169: qed "rev_append";
nipkow@2512: Addsimps[rev_append];
lcp@1169:
nipkow@3011: goal thy "rev(rev l) = l";
nipkow@3040: by (induct_tac "l" 1);
nipkow@2512: by (ALLGOALS Asm_simp_tac);
lcp@1169: qed "rev_rev_ident";
nipkow@2512: Addsimps[rev_rev_ident];
lcp@1169:
nipkow@2608:
clasohm@923: (** mem **)
clasohm@923:
nipkow@3467: section "mem";
nipkow@3467:
nipkow@3011: goal thy "x mem (xs@ys) = (x mem xs | x mem ys)";
nipkow@3040: by (induct_tac "xs" 1);
clasohm@1264: by (ALLGOALS (asm_simp_tac (!simpset setloop (split_tac [expand_if]))));
clasohm@923: qed "mem_append";
nipkow@2512: Addsimps[mem_append];
clasohm@923:
nipkow@3011: goal thy "x mem [x:xs.P(x)] = (x mem xs & P(x))";
nipkow@3040: by (induct_tac "xs" 1);
clasohm@1264: by (ALLGOALS (asm_simp_tac (!simpset setloop (split_tac [expand_if]))));
clasohm@923: qed "mem_filter";
nipkow@2512: Addsimps[mem_filter];
clasohm@923:
nipkow@3465: (** set **)
paulson@1812:
nipkow@3467: section "set";
nipkow@3467:
nipkow@3465: goal thy "set (xs@ys) = (set xs Un set ys)";
nipkow@3040: by (induct_tac "xs" 1);
paulson@1812: by (ALLGOALS Asm_simp_tac);
paulson@1908: qed "set_of_list_append";
nipkow@2512: Addsimps[set_of_list_append];
paulson@1812:
nipkow@3465: goal thy "(x mem xs) = (x: set xs)";
nipkow@3040: by (induct_tac "xs" 1);
paulson@1812: by (ALLGOALS (asm_simp_tac (!simpset setloop (split_tac [expand_if]))));
paulson@2891: by (Blast_tac 1);
paulson@1908: qed "set_of_list_mem_eq";
paulson@1812:
nipkow@3465: goal thy "set l <= set (x#l)";
paulson@1936: by (Simp_tac 1);
paulson@2891: by (Blast_tac 1);
paulson@1936: qed "set_of_list_subset_Cons";
paulson@1936:
nipkow@3465: goal thy "(set xs = {}) = (xs = [])";
paulson@3457: by (induct_tac "xs" 1);
paulson@3457: by (ALLGOALS Asm_simp_tac);
nipkow@2608: qed "set_of_list_empty";
nipkow@2608: Addsimps [set_of_list_empty];
nipkow@2608:
nipkow@3465: goal thy "set(rev xs) = set(xs)";
paulson@3457: by (induct_tac "xs" 1);
paulson@3457: by (ALLGOALS Asm_simp_tac);
nipkow@2608: qed "set_of_list_rev";
nipkow@2608: Addsimps [set_of_list_rev];
nipkow@2608:
nipkow@3465: goal thy "set(map f xs) = f``(set xs)";
paulson@3457: by (induct_tac "xs" 1);
paulson@3457: by (ALLGOALS Asm_simp_tac);
nipkow@2608: qed "set_of_list_map";
nipkow@2608: Addsimps [set_of_list_map];
nipkow@2608:
paulson@1812:
clasohm@923: (** list_all **)
clasohm@923:
nipkow@3467: section "list_all";
nipkow@3467:
nipkow@3011: goal thy "list_all (%x.True) xs = True";
nipkow@3040: by (induct_tac "xs" 1);
clasohm@1264: by (ALLGOALS Asm_simp_tac);
clasohm@923: qed "list_all_True";
nipkow@2512: Addsimps [list_all_True];
clasohm@923:
nipkow@3011: goal thy "list_all p (xs@ys) = (list_all p xs & list_all p ys)";
nipkow@3040: by (induct_tac "xs" 1);
clasohm@1264: by (ALLGOALS Asm_simp_tac);
nipkow@2512: qed "list_all_append";
nipkow@2512: Addsimps [list_all_append];
clasohm@923:
nipkow@3011: goal thy "list_all P xs = (!x. x mem xs --> P(x))";
nipkow@3040: by (induct_tac "xs" 1);
clasohm@1264: by (ALLGOALS (asm_simp_tac (!simpset setloop (split_tac [expand_if]))));
paulson@2891: by (Blast_tac 1);
clasohm@923: qed "list_all_mem_conv";
clasohm@923:
clasohm@923:
nipkow@2608: (** filter **)
clasohm@923:
nipkow@3467: section "filter";
nipkow@3467:
paulson@3383: goal thy "filter P (xs@ys) = filter P xs @ filter P ys";
paulson@3457: by (induct_tac "xs" 1);
paulson@3457: by (ALLGOALS (asm_simp_tac (!simpset setloop (split_tac [expand_if]))));
nipkow@2608: qed "filter_append";
nipkow@2608: Addsimps [filter_append];
nipkow@2608:
paulson@3383: goal thy "size (filter P xs) <= size xs";
paulson@3457: by (induct_tac "xs" 1);
paulson@3457: by (ALLGOALS (asm_simp_tac (!simpset setloop (split_tac [expand_if]))));
paulson@3383: qed "filter_size";
paulson@3383:
nipkow@2608:
nipkow@2608: (** concat **)
nipkow@2608:
nipkow@3467: section "concat";
nipkow@3467:
nipkow@3011: goal thy "concat(xs@ys) = concat(xs)@concat(ys)";
nipkow@3040: by (induct_tac "xs" 1);
clasohm@1264: by (ALLGOALS Asm_simp_tac);
nipkow@2608: qed"concat_append";
nipkow@2608: Addsimps [concat_append];
nipkow@2512:
nipkow@3467: goal thy "set(concat xs) = Union(set `` set xs)";
nipkow@3467: by (induct_tac "xs" 1);
nipkow@3467: by (ALLGOALS Asm_simp_tac);
nipkow@3467: qed"set_of_list_concat";
nipkow@3467: Addsimps [set_of_list_concat];
nipkow@3467:
nipkow@3467: goal thy "map f (concat xs) = concat (map (map f) xs)";
nipkow@3467: by (induct_tac "xs" 1);
nipkow@3467: by (ALLGOALS Asm_simp_tac);
nipkow@3467: qed "map_concat";
nipkow@3467:
nipkow@3467: goal thy "filter p (concat xs) = concat (map (filter p) xs)";
nipkow@3467: by (induct_tac "xs" 1);
nipkow@3467: by (ALLGOALS Asm_simp_tac);
nipkow@3467: qed"filter_concat";
nipkow@3467:
nipkow@3467: goal thy "rev(concat xs) = concat (map rev (rev xs))";
nipkow@3467: by (induct_tac "xs" 1);
nipkow@2512: by (ALLGOALS Asm_simp_tac);
nipkow@2608: qed "rev_concat";
clasohm@923:
nipkow@962: (** length **)
nipkow@962:
nipkow@3467: section "length";
nipkow@3467:
nipkow@3011: goal thy "length(xs@ys) = length(xs)+length(ys)";
nipkow@3040: by (induct_tac "xs" 1);
clasohm@1264: by (ALLGOALS Asm_simp_tac);
nipkow@962: qed"length_append";
nipkow@1301: Addsimps [length_append];
nipkow@1301:
nipkow@3011: goal thy "length (map f l) = length l";
nipkow@3040: by (induct_tac "l" 1);
nipkow@1301: by (ALLGOALS Simp_tac);
nipkow@1301: qed "length_map";
nipkow@1301: Addsimps [length_map];
nipkow@962:
nipkow@3011: goal thy "length(rev xs) = length(xs)";
nipkow@3040: by (induct_tac "xs" 1);
nipkow@1301: by (ALLGOALS Asm_simp_tac);
lcp@1169: qed "length_rev";
nipkow@1301: Addsimps [length_rev];
lcp@1169:
nipkow@3011: goal thy "(length xs = 0) = (xs = [])";
paulson@3457: by (induct_tac "xs" 1);
paulson@3457: by (ALLGOALS Asm_simp_tac);
nipkow@2608: qed "length_0_conv";
nipkow@2608: AddIffs [length_0_conv];
nipkow@2608:
nipkow@3011: goal thy "(0 < length xs) = (xs ~= [])";
paulson@3457: by (induct_tac "xs" 1);
paulson@3457: by (ALLGOALS Asm_simp_tac);
nipkow@2608: qed "length_greater_0_conv";
nipkow@2608: AddIffs [length_greater_0_conv];
nipkow@2608:
nipkow@2608:
clasohm@923: (** nth **)
clasohm@923:
nipkow@3467: section "nth";
nipkow@3467:
nipkow@3011: goal thy
nipkow@2608: "!xs. nth n (xs@ys) = \
nipkow@2608: \ (if n < length xs then nth n xs else nth (n - length xs) ys)";
paulson@3457: by (nat_ind_tac "n" 1);
paulson@3457: by (Asm_simp_tac 1);
paulson@3457: by (rtac allI 1);
paulson@3457: by (exhaust_tac "xs" 1);
paulson@3457: by (ALLGOALS Asm_simp_tac);
paulson@3457: by (rtac allI 1);
paulson@3457: by (exhaust_tac "xs" 1);
paulson@3457: by (ALLGOALS Asm_simp_tac);
nipkow@2608: qed_spec_mp "nth_append";
nipkow@2608:
nipkow@3011: goal thy "!n. n < length xs --> nth n (map f xs) = f (nth n xs)";
nipkow@3040: by (induct_tac "xs" 1);
nipkow@1301: (* case [] *)
nipkow@1301: by (Asm_full_simp_tac 1);
nipkow@1301: (* case x#xl *)
nipkow@1301: by (rtac allI 1);
nipkow@1301: by (nat_ind_tac "n" 1);
nipkow@1301: by (ALLGOALS Asm_full_simp_tac);
nipkow@1485: qed_spec_mp "nth_map";
nipkow@1301: Addsimps [nth_map];
nipkow@1301:
nipkow@3011: goal thy "!n. n < length xs --> list_all P xs --> P(nth n xs)";
nipkow@3040: by (induct_tac "xs" 1);
nipkow@1301: (* case [] *)
nipkow@1301: by (Simp_tac 1);
nipkow@1301: (* case x#xl *)
nipkow@1301: by (rtac allI 1);
nipkow@1301: by (nat_ind_tac "n" 1);
nipkow@1301: by (ALLGOALS Asm_full_simp_tac);
nipkow@1485: qed_spec_mp "list_all_nth";
nipkow@1301:
nipkow@3011: goal thy "!n. n < length xs --> (nth n xs) mem xs";
nipkow@3040: by (induct_tac "xs" 1);
nipkow@1301: (* case [] *)
nipkow@1301: by (Simp_tac 1);
nipkow@1301: (* case x#xl *)
nipkow@1301: by (rtac allI 1);
nipkow@1301: by (nat_ind_tac "n" 1);
nipkow@1301: (* case 0 *)
nipkow@1301: by (Asm_full_simp_tac 1);
nipkow@1301: (* case Suc x *)
nipkow@1301: by (asm_full_simp_tac (!simpset setloop (split_tac [expand_if])) 1);
nipkow@1485: qed_spec_mp "nth_mem";
nipkow@1301: Addsimps [nth_mem];
nipkow@1301:
nipkow@1327:
nipkow@2608: (** take & drop **)
nipkow@2608: section "take & drop";
nipkow@1327:
nipkow@1419: goal thy "take 0 xs = []";
nipkow@3040: by (induct_tac "xs" 1);
nipkow@1419: by (ALLGOALS Asm_simp_tac);
nipkow@1327: qed "take_0";
nipkow@1327:
nipkow@2608: goal thy "drop 0 xs = xs";
nipkow@3040: by (induct_tac "xs" 1);
nipkow@2608: by (ALLGOALS Asm_simp_tac);
nipkow@2608: qed "drop_0";
nipkow@2608:
nipkow@1419: goal thy "take (Suc n) (x#xs) = x # take n xs";
paulson@1552: by (Simp_tac 1);
nipkow@1419: qed "take_Suc_Cons";
nipkow@1327:
nipkow@2608: goal thy "drop (Suc n) (x#xs) = drop n xs";
nipkow@2608: by (Simp_tac 1);
nipkow@2608: qed "drop_Suc_Cons";
nipkow@2608:
nipkow@2608: Delsimps [take_Cons,drop_Cons];
nipkow@2608: Addsimps [take_0,take_Suc_Cons,drop_0,drop_Suc_Cons];
nipkow@2608:
nipkow@3011: goal thy "!xs. length(take n xs) = min (length xs) n";
paulson@3457: by (nat_ind_tac "n" 1);
paulson@3457: by (ALLGOALS Asm_simp_tac);
paulson@3457: by (rtac allI 1);
paulson@3457: by (exhaust_tac "xs" 1);
paulson@3457: by (ALLGOALS Asm_simp_tac);
nipkow@2608: qed_spec_mp "length_take";
nipkow@2608: Addsimps [length_take];
clasohm@923:
nipkow@3011: goal thy "!xs. length(drop n xs) = (length xs - n)";
paulson@3457: by (nat_ind_tac "n" 1);
paulson@3457: by (ALLGOALS Asm_simp_tac);
paulson@3457: by (rtac allI 1);
paulson@3457: by (exhaust_tac "xs" 1);
paulson@3457: by (ALLGOALS Asm_simp_tac);
nipkow@2608: qed_spec_mp "length_drop";
nipkow@2608: Addsimps [length_drop];
nipkow@2608:
nipkow@3011: goal thy "!xs. length xs <= n --> take n xs = xs";
paulson@3457: by (nat_ind_tac "n" 1);
paulson@3457: by (ALLGOALS Asm_simp_tac);
paulson@3457: by (rtac allI 1);
paulson@3457: by (exhaust_tac "xs" 1);
paulson@3457: by (ALLGOALS Asm_simp_tac);
nipkow@2608: qed_spec_mp "take_all";
clasohm@923:
nipkow@3011: goal thy "!xs. length xs <= n --> drop n xs = []";
paulson@3457: by (nat_ind_tac "n" 1);
paulson@3457: by (ALLGOALS Asm_simp_tac);
paulson@3457: by (rtac allI 1);
paulson@3457: by (exhaust_tac "xs" 1);
paulson@3457: by (ALLGOALS Asm_simp_tac);
nipkow@2608: qed_spec_mp "drop_all";
nipkow@2608:
nipkow@3011: goal thy
nipkow@2608: "!xs. take n (xs @ ys) = (take n xs @ take (n - length xs) ys)";
paulson@3457: by (nat_ind_tac "n" 1);
paulson@3457: by (ALLGOALS Asm_simp_tac);
paulson@3457: by (rtac allI 1);
paulson@3457: by (exhaust_tac "xs" 1);
paulson@3457: by (ALLGOALS Asm_simp_tac);
nipkow@2608: qed_spec_mp "take_append";
nipkow@2608: Addsimps [take_append];
nipkow@2608:
nipkow@3011: goal thy "!xs. drop n (xs@ys) = drop n xs @ drop (n - length xs) ys";
paulson@3457: by (nat_ind_tac "n" 1);
paulson@3457: by (ALLGOALS Asm_simp_tac);
paulson@3457: by (rtac allI 1);
paulson@3457: by (exhaust_tac "xs" 1);
paulson@3457: by (ALLGOALS Asm_simp_tac);
nipkow@2608: qed_spec_mp "drop_append";
nipkow@2608: Addsimps [drop_append];
nipkow@2608:
nipkow@3011: goal thy "!xs n. take n (take m xs) = take (min n m) xs";
paulson@3457: by (nat_ind_tac "m" 1);
paulson@3457: by (ALLGOALS Asm_simp_tac);
paulson@3457: by (rtac allI 1);
paulson@3457: by (exhaust_tac "xs" 1);
paulson@3457: by (ALLGOALS Asm_simp_tac);
paulson@3457: by (rtac allI 1);
paulson@3457: by (exhaust_tac "n" 1);
paulson@3457: by (ALLGOALS Asm_simp_tac);
nipkow@2608: qed_spec_mp "take_take";
nipkow@2608:
nipkow@3011: goal thy "!xs. drop n (drop m xs) = drop (n + m) xs";
paulson@3457: by (nat_ind_tac "m" 1);
paulson@3457: by (ALLGOALS Asm_simp_tac);
paulson@3457: by (rtac allI 1);
paulson@3457: by (exhaust_tac "xs" 1);
paulson@3457: by (ALLGOALS Asm_simp_tac);
nipkow@2608: qed_spec_mp "drop_drop";
clasohm@923:
nipkow@3011: goal thy "!xs n. take n (drop m xs) = drop m (take (n + m) xs)";
paulson@3457: by (nat_ind_tac "m" 1);
paulson@3457: by (ALLGOALS Asm_simp_tac);
paulson@3457: by (rtac allI 1);
paulson@3457: by (exhaust_tac "xs" 1);
paulson@3457: by (ALLGOALS Asm_simp_tac);
nipkow@2608: qed_spec_mp "take_drop";
nipkow@2608:
nipkow@3011: goal thy "!xs. take n (map f xs) = map f (take n xs)";
paulson@3457: by (nat_ind_tac "n" 1);
paulson@3457: by (ALLGOALS Asm_simp_tac);
paulson@3457: by (rtac allI 1);
paulson@3457: by (exhaust_tac "xs" 1);
paulson@3457: by (ALLGOALS Asm_simp_tac);
nipkow@2608: qed_spec_mp "take_map";
nipkow@2608:
nipkow@3011: goal thy "!xs. drop n (map f xs) = map f (drop n xs)";
paulson@3457: by (nat_ind_tac "n" 1);
paulson@3457: by (ALLGOALS Asm_simp_tac);
paulson@3457: by (rtac allI 1);
paulson@3457: by (exhaust_tac "xs" 1);
paulson@3457: by (ALLGOALS Asm_simp_tac);
nipkow@2608: qed_spec_mp "drop_map";
nipkow@2608:
nipkow@3283: goal thy "!n i. i < n --> nth i (take n xs) = nth i xs";
paulson@3457: by (induct_tac "xs" 1);
paulson@3457: by (ALLGOALS Asm_simp_tac);
paulson@3457: by (strip_tac 1);
paulson@3457: by (exhaust_tac "n" 1);
paulson@3457: by (Blast_tac 1);
paulson@3457: by (exhaust_tac "i" 1);
paulson@3457: by (ALLGOALS Asm_full_simp_tac);
nipkow@2608: qed_spec_mp "nth_take";
nipkow@2608: Addsimps [nth_take];
clasohm@923:
nipkow@3283: goal thy "!xs i. n + i < length xs --> nth i (drop n xs) = nth (n + i) xs";
paulson@3457: by (nat_ind_tac "n" 1);
paulson@3457: by (ALLGOALS Asm_simp_tac);
paulson@3457: by (rtac allI 1);
paulson@3457: by (exhaust_tac "xs" 1);
paulson@3457: by (ALLGOALS Asm_simp_tac);
nipkow@2608: qed_spec_mp "nth_drop";
nipkow@2608: Addsimps [nth_drop];
nipkow@2608:
nipkow@2608: (** takeWhile & dropWhile **)
nipkow@2608:
nipkow@3467: section "takeWhile & dropWhile";
nipkow@3467:
nipkow@3011: goal thy
nipkow@3465: "x:set xs & ~P(x) --> takeWhile P (xs @ ys) = takeWhile P xs";
paulson@3457: by (induct_tac "xs" 1);
paulson@3457: by (Simp_tac 1);
paulson@3457: by (asm_full_simp_tac (!simpset setloop (split_tac[expand_if])) 1);
paulson@3457: by (Blast_tac 1);
nipkow@2608: bind_thm("takeWhile_append1", conjI RS (result() RS mp));
nipkow@2608: Addsimps [takeWhile_append1];
clasohm@923:
nipkow@3011: goal thy
nipkow@3465: "(!x:set xs.P(x)) --> takeWhile P (xs @ ys) = xs @ takeWhile P ys";
paulson@3457: by (induct_tac "xs" 1);
paulson@3457: by (Simp_tac 1);
paulson@3457: by (asm_full_simp_tac (!simpset setloop (split_tac[expand_if])) 1);
nipkow@2608: bind_thm("takeWhile_append2", ballI RS (result() RS mp));
nipkow@2608: Addsimps [takeWhile_append2];
lcp@1169:
nipkow@3011: goal thy
nipkow@3465: "x:set xs & ~P(x) --> dropWhile P (xs @ ys) = (dropWhile P xs)@ys";
paulson@3457: by (induct_tac "xs" 1);
paulson@3457: by (Simp_tac 1);
paulson@3457: by (asm_full_simp_tac (!simpset setloop (split_tac[expand_if])) 1);
paulson@3457: by (Blast_tac 1);
nipkow@2608: bind_thm("dropWhile_append1", conjI RS (result() RS mp));
nipkow@2608: Addsimps [dropWhile_append1];
nipkow@2608:
nipkow@3011: goal thy
nipkow@3465: "(!x:set xs.P(x)) --> dropWhile P (xs @ ys) = dropWhile P ys";
paulson@3457: by (induct_tac "xs" 1);
paulson@3457: by (Simp_tac 1);
paulson@3457: by (asm_full_simp_tac (!simpset setloop (split_tac[expand_if])) 1);
nipkow@2608: bind_thm("dropWhile_append2", ballI RS (result() RS mp));
nipkow@2608: Addsimps [dropWhile_append2];
nipkow@2608:
nipkow@3465: goal thy "x:set(takeWhile P xs) --> x:set xs & P x";
paulson@3457: by (induct_tac "xs" 1);
paulson@3457: by (Simp_tac 1);
paulson@3457: by (asm_full_simp_tac (!simpset setloop (split_tac[expand_if])) 1);
nipkow@2608: qed_spec_mp"set_of_list_take_whileD";
nipkow@2608: