798 by (induct xs) auto |
798 by (induct xs) auto |
799 |
799 |
800 lemma map_eq_conv[simp]: "(map f xs = map g xs) = (!x : set xs. f x = g x)" |
800 lemma map_eq_conv[simp]: "(map f xs = map g xs) = (!x : set xs. f x = g x)" |
801 by (induct xs) auto |
801 by (induct xs) auto |
802 |
802 |
803 lemma map_cong [fundef_cong, recdef_cong]: |
803 lemma map_cong [fundef_cong]: |
804 "xs = ys \<Longrightarrow> (\<And>x. x \<in> set ys \<Longrightarrow> f x = g x) \<Longrightarrow> map f xs = map g ys" |
804 "xs = ys \<Longrightarrow> (\<And>x. x \<in> set ys \<Longrightarrow> f x = g x) \<Longrightarrow> map f xs = map g ys" |
805 by simp |
805 by simp |
806 |
806 |
807 lemma map_is_Nil_conv [iff]: "(map f xs = []) = (xs = [])" |
807 lemma map_is_Nil_conv [iff]: "(map f xs = []) = (xs = [])" |
808 by (cases xs) auto |
808 by (cases xs) auto |
1235 lemma Cons_eq_filter_iff: |
1235 lemma Cons_eq_filter_iff: |
1236 "(x#xs = filter P ys) = |
1236 "(x#xs = filter P ys) = |
1237 (\<exists>us vs. ys = us @ x # vs \<and> (\<forall>u\<in>set us. \<not> P u) \<and> P x \<and> xs = filter P vs)" |
1237 (\<exists>us vs. ys = us @ x # vs \<and> (\<forall>u\<in>set us. \<not> P u) \<and> P x \<and> xs = filter P vs)" |
1238 by(auto dest:Cons_eq_filterD) |
1238 by(auto dest:Cons_eq_filterD) |
1239 |
1239 |
1240 lemma filter_cong[fundef_cong, recdef_cong]: |
1240 lemma filter_cong[fundef_cong]: |
1241 "xs = ys \<Longrightarrow> (\<And>x. x \<in> set ys \<Longrightarrow> P x = Q x) \<Longrightarrow> filter P xs = filter Q ys" |
1241 "xs = ys \<Longrightarrow> (\<And>x. x \<in> set ys \<Longrightarrow> P x = Q x) \<Longrightarrow> filter P xs = filter Q ys" |
1242 apply simp |
1242 apply simp |
1243 apply(erule thin_rl) |
1243 apply(erule thin_rl) |
1244 by (induct ys) simp_all |
1244 by (induct ys) simp_all |
1245 |
1245 |
2001 apply simp |
2001 apply simp |
2002 apply(case_tac xs) |
2002 apply(case_tac xs) |
2003 apply(auto) |
2003 apply(auto) |
2004 done |
2004 done |
2005 |
2005 |
2006 lemma takeWhile_cong [fundef_cong, recdef_cong]: |
2006 lemma takeWhile_cong [fundef_cong]: |
2007 "[| l = k; !!x. x : set l ==> P x = Q x |] |
2007 "[| l = k; !!x. x : set l ==> P x = Q x |] |
2008 ==> takeWhile P l = takeWhile Q k" |
2008 ==> takeWhile P l = takeWhile Q k" |
2009 by (induct k arbitrary: l) (simp_all) |
2009 by (induct k arbitrary: l) (simp_all) |
2010 |
2010 |
2011 lemma dropWhile_cong [fundef_cong, recdef_cong]: |
2011 lemma dropWhile_cong [fundef_cong]: |
2012 "[| l = k; !!x. x : set l ==> P x = Q x |] |
2012 "[| l = k; !!x. x : set l ==> P x = Q x |] |
2013 ==> dropWhile P l = dropWhile Q k" |
2013 ==> dropWhile P l = dropWhile Q k" |
2014 by (induct k arbitrary: l, simp_all) |
2014 by (induct k arbitrary: l, simp_all) |
2015 |
2015 |
2016 |
2016 |
2347 lemma foldl_apply: |
2347 lemma foldl_apply: |
2348 assumes "\<And>x. x \<in> set xs \<Longrightarrow> f x \<circ> h = h \<circ> g x" |
2348 assumes "\<And>x. x \<in> set xs \<Longrightarrow> f x \<circ> h = h \<circ> g x" |
2349 shows "foldl (\<lambda>s x. f x s) (h s) xs = h (foldl (\<lambda>s x. g x s) s xs)" |
2349 shows "foldl (\<lambda>s x. f x s) (h s) xs = h (foldl (\<lambda>s x. g x s) s xs)" |
2350 by (rule sym, insert assms, induct xs arbitrary: s) (simp_all add: fun_eq_iff) |
2350 by (rule sym, insert assms, induct xs arbitrary: s) (simp_all add: fun_eq_iff) |
2351 |
2351 |
2352 lemma foldl_cong [fundef_cong, recdef_cong]: |
2352 lemma foldl_cong [fundef_cong]: |
2353 "[| a = b; l = k; !!a x. x : set l ==> f a x = g a x |] |
2353 "[| a = b; l = k; !!a x. x : set l ==> f a x = g a x |] |
2354 ==> foldl f a l = foldl g b k" |
2354 ==> foldl f a l = foldl g b k" |
2355 by (induct k arbitrary: a b l) simp_all |
2355 by (induct k arbitrary: a b l) simp_all |
2356 |
2356 |
2357 lemma foldr_cong [fundef_cong, recdef_cong]: |
2357 lemma foldr_cong [fundef_cong]: |
2358 "[| a = b; l = k; !!a x. x : set l ==> f x a = g x a |] |
2358 "[| a = b; l = k; !!a x. x : set l ==> f x a = g x a |] |
2359 ==> foldr f l a = foldr g k b" |
2359 ==> foldr f l a = foldr g k b" |
2360 by (induct k arbitrary: a b l) simp_all |
2360 by (induct k arbitrary: a b l) simp_all |
2361 |
2361 |
2362 lemma foldl_fun_comm: |
2362 lemma foldl_fun_comm: |
4584 text {* These are useful for termination proofs *} |
4584 text {* These are useful for termination proofs *} |
4585 |
4585 |
4586 definition |
4586 definition |
4587 "measures fs = inv_image (lex less_than) (%a. map (%f. f a) fs)" |
4587 "measures fs = inv_image (lex less_than) (%a. map (%f. f a) fs)" |
4588 |
4588 |
4589 lemma wf_measures[recdef_wf, simp]: "wf (measures fs)" |
4589 lemma wf_measures[simp]: "wf (measures fs)" |
4590 unfolding measures_def |
4590 unfolding measures_def |
4591 by blast |
4591 by blast |
4592 |
4592 |
4593 lemma in_measures[simp]: |
4593 lemma in_measures[simp]: |
4594 "(x, y) \<in> measures [] = False" |
4594 "(x, y) \<in> measures [] = False" |