src/HOL/List.thy
changeset 52379 7f864f2219a9
parent 52148 893b15200ec1
child 52380 3cc46b8cca5e
equal deleted inserted replaced
52378:08dbf9ff2140 52379:7f864f2219a9
  3513   hence "List.find Q ys = Some x" using assms
  3513   hence "List.find Q ys = Some x" using assms
  3514     by (auto simp add: find_Some_iff)
  3514     by (auto simp add: find_Some_iff)
  3515   thus ?thesis using Some by auto
  3515   thus ?thesis using Some by auto
  3516 qed
  3516 qed
  3517 
  3517 
       
  3518 lemma find_dropWhile:
       
  3519   "List.find P xs = (case dropWhile (Not \<circ> P) xs
       
  3520    of [] \<Rightarrow> None
       
  3521     | x # _ \<Rightarrow> Some x)"
       
  3522   by (induct xs) simp_all
       
  3523 
  3518 
  3524 
  3519 subsubsection {* @{const remove1} *}
  3525 subsubsection {* @{const remove1} *}
  3520 
  3526 
  3521 lemma remove1_append:
  3527 lemma remove1_append:
  3522   "remove1 x (xs @ ys) =
  3528   "remove1 x (xs @ ys) =
  3862 lemma enumerate_Suc_eq:
  3868 lemma enumerate_Suc_eq:
  3863   "enumerate (Suc n) xs = map (apfst Suc) (enumerate n xs)"
  3869   "enumerate (Suc n) xs = map (apfst Suc) (enumerate n xs)"
  3864   by (rule pair_list_eqI)
  3870   by (rule pair_list_eqI)
  3865     (simp_all add: not_le, simp del: map_map [simp del] add: map_Suc_upt map_map [symmetric])
  3871     (simp_all add: not_le, simp del: map_map [simp del] add: map_Suc_upt map_map [symmetric])
  3866 
  3872 
       
  3873 lemma distinct_enumerate [simp]:
       
  3874   "distinct (enumerate n xs)"
       
  3875   by (simp add: enumerate_eq_zip distinct_zipI1)
       
  3876 
  3867 
  3877 
  3868 subsubsection {* @{const rotate1} and @{const rotate} *}
  3878 subsubsection {* @{const rotate1} and @{const rotate} *}
  3869 
  3879 
  3870 lemma rotate0[simp]: "rotate 0 = id"
  3880 lemma rotate0[simp]: "rotate 0 = id"
  3871 by(simp add:rotate_def)
  3881 by(simp add:rotate_def)
  4690 lemma sorted_upto[simp]: "sorted[i..j]"
  4700 lemma sorted_upto[simp]: "sorted[i..j]"
  4691 apply(induct i j rule:upto.induct)
  4701 apply(induct i j rule:upto.induct)
  4692 apply(subst upto.simps)
  4702 apply(subst upto.simps)
  4693 apply(simp add:sorted_Cons)
  4703 apply(simp add:sorted_Cons)
  4694 done
  4704 done
       
  4705 
       
  4706 lemma sorted_find_Min:
       
  4707   assumes "sorted xs"
       
  4708   assumes "\<exists>x \<in> set xs. P x"
       
  4709   shows "List.find P xs = Some (Min {x\<in>set xs. P x})"
       
  4710 using assms proof (induct xs rule: sorted.induct)
       
  4711   case Nil then show ?case by simp
       
  4712 next
       
  4713   case (Cons xs x) show ?case proof (cases "P x")
       
  4714     case True with Cons show ?thesis by (auto intro: Min_eqI [symmetric])
       
  4715   next
       
  4716     case False then have "{y. (y = x \<or> y \<in> set xs) \<and> P y} = {y \<in> set xs. P y}"
       
  4717       by auto
       
  4718     with Cons False show ?thesis by simp_all
       
  4719   qed
       
  4720 qed
  4695 
  4721 
  4696 
  4722 
  4697 subsubsection {* @{const transpose} on sorted lists *}
  4723 subsubsection {* @{const transpose} on sorted lists *}
  4698 
  4724 
  4699 lemma sorted_transpose[simp]:
  4725 lemma sorted_transpose[simp]: