395 fixes xs :: "'a :: linorder list" |
395 fixes xs :: "'a :: linorder list" |
396 fixes M defines "M \<equiv> median (map median (chop 5 xs))" |
396 fixes M defines "M \<equiv> median (map median (chop 5 xs))" |
397 begin |
397 begin |
398 |
398 |
399 lemma size_median_of_medians_aux: |
399 lemma size_median_of_medians_aux: |
400 fixes R :: "'a :: linorder \<Rightarrow> 'a \<Rightarrow> bool" (infix "\<prec>" 50) |
400 fixes R :: "'a :: linorder \<Rightarrow> 'a \<Rightarrow> bool" (infix \<open>\<prec>\<close> 50) |
401 assumes R: "R \<in> {(<), (>)}" |
401 assumes R: "R \<in> {(<), (>)}" |
402 shows "size {#y \<in># mset xs. y \<prec> M#} \<le> nat \<lceil>0.7 * length xs + 3\<rceil>" |
402 shows "size {#y \<in># mset xs. y \<prec> M#} \<le> nat \<lceil>0.7 * length xs + 3\<rceil>" |
403 proof - |
403 proof - |
404 define n and m where [simp]: "n = length xs" and "m = length (chop 5 xs)" |
404 define n and m where [simp]: "n = length xs" and "m = length (chop 5 xs)" |
405 text \<open>We define an abbreviation for the multiset of all the chopped-up groups:\<close> |
405 text \<open>We define an abbreviation for the multiset of all the chopped-up groups:\<close> |
406 |
406 |
407 text \<open>We then split that multiset into those groups whose medians is less than @{term M} |
407 text \<open>We then split that multiset into those groups whose medians is less than @{term M} |
408 and the rest.\<close> |
408 and the rest.\<close> |
409 define Y_small ("Y\<^sub>\<prec>") where "Y\<^sub>\<prec> = filter_mset (\<lambda>ys. median ys \<prec> M) (mset (chop 5 xs))" |
409 define Y_small (\<open>Y\<^sub>\<prec>\<close>) where "Y\<^sub>\<prec> = filter_mset (\<lambda>ys. median ys \<prec> M) (mset (chop 5 xs))" |
410 define Y_big ("Y\<^sub>\<succeq>") where "Y\<^sub>\<succeq> = filter_mset (\<lambda>ys. \<not>(median ys \<prec> M)) (mset (chop 5 xs))" |
410 define Y_big (\<open>Y\<^sub>\<succeq>\<close>) where "Y\<^sub>\<succeq> = filter_mset (\<lambda>ys. \<not>(median ys \<prec> M)) (mset (chop 5 xs))" |
411 have "m = size (mset (chop 5 xs))" by (simp add: m_def) |
411 have "m = size (mset (chop 5 xs))" by (simp add: m_def) |
412 also have "mset (chop 5 xs) = Y\<^sub>\<prec> + Y\<^sub>\<succeq>" unfolding Y_small_def Y_big_def |
412 also have "mset (chop 5 xs) = Y\<^sub>\<prec> + Y\<^sub>\<succeq>" unfolding Y_small_def Y_big_def |
413 by (rule multiset_partition) |
413 by (rule multiset_partition) |
414 finally have m_eq: "m = size Y\<^sub>\<prec> + size Y\<^sub>\<succeq>" by simp |
414 finally have m_eq: "m = size Y\<^sub>\<prec> + size Y\<^sub>\<succeq>" by simp |
415 |
415 |