equal
deleted
inserted
replaced
545 definition list_fast :: "'a tree \<Rightarrow> 'a list" where |
545 definition list_fast :: "'a tree \<Rightarrow> 'a list" where |
546 "list_fast t = list_fast_rec [t]" |
546 "list_fast t = list_fast_rec [t]" |
547 |
547 |
548 function t_list_fast_rec :: "'a tree list \<Rightarrow> nat" where |
548 function t_list_fast_rec :: "'a tree list \<Rightarrow> nat" where |
549 "t_list_fast_rec ts = (let us = filter (\<lambda>t. t \<noteq> Leaf) ts |
549 "t_list_fast_rec ts = (let us = filter (\<lambda>t. t \<noteq> Leaf) ts |
550 in if us = [] then 0 else |
550 in length ts + (if us = [] then 0 else |
551 length ts + 5 * length us + t_list_fast_rec (map left us @ map right us))" |
551 5 * length us + t_list_fast_rec (map left us @ map right us)))" |
552 by (pat_completeness, auto) |
552 by (pat_completeness, auto) |
553 |
553 |
554 termination |
554 termination |
555 apply (relation "measure (sum_list o map size)") |
555 apply (relation "measure (sum_list o map size)") |
556 apply simp |
556 apply simp |
633 case (less ts) |
633 case (less ts) |
634 let ?us = "filter (\<lambda>t. t \<noteq> Leaf) ts" |
634 let ?us = "filter (\<lambda>t. t \<noteq> Leaf) ts" |
635 show ?case |
635 show ?case |
636 proof cases |
636 proof cases |
637 assume "?us = []" |
637 assume "?us = []" |
638 thus ?thesis using t_list_fast_rec.simps[of ts] by(simp add: Let_def) |
638 thus ?thesis using t_list_fast_rec.simps[of ts] |
639 next |
639 by(simp add: Let_def sum_list_Suc) |
|
640 next |
640 assume "?us \<noteq> []" |
641 assume "?us \<noteq> []" |
641 let ?children = "map left ?us @ map right ?us" |
642 let ?children = "map left ?us @ map right ?us" |
642 have "t_list_fast_rec ts = t_list_fast_rec ?children + 5 * length ?us + length ts" |
643 have "t_list_fast_rec ts = t_list_fast_rec ?children + 5 * length ?us + length ts" |
643 using \<open>?us \<noteq> []\<close> t_list_fast_rec.simps[of ts] by(simp add: Let_def) |
644 using \<open>?us \<noteq> []\<close> t_list_fast_rec.simps[of ts] by(simp add: Let_def) |
644 also have "\<dots> \<le> (\<Sum>t\<leftarrow>?children. 7 * size t + 1) + 5 * length ?us + length ts" |
645 also have "\<dots> \<le> (\<Sum>t\<leftarrow>?children. 7 * size t + 1) + 5 * length ?us + length ts" |