2007 "i < length xs \<Longrightarrow> take (Suc i) xs = take i xs @ [xs!i]" |
2007 "i < length xs \<Longrightarrow> take (Suc i) xs = take i xs @ [xs!i]" |
2008 apply (induct xs arbitrary: i, simp) |
2008 apply (induct xs arbitrary: i, simp) |
2009 apply (case_tac i, auto) |
2009 apply (case_tac i, auto) |
2010 done |
2010 done |
2011 |
2011 |
2012 lemma drop_Suc_conv_tl: |
2012 lemma Cons_nth_drop_Suc: |
2013 "i < length xs \<Longrightarrow> (xs!i) # (drop (Suc i) xs) = drop i xs" |
2013 "i < length xs \<Longrightarrow> (xs!i) # (drop (Suc i) xs) = drop i xs" |
2014 apply (induct xs arbitrary: i, simp) |
2014 apply (induct xs arbitrary: i, simp) |
2015 apply (case_tac i, auto) |
2015 apply (case_tac i, auto) |
2016 done |
2016 done |
2017 |
2017 |
2197 by(rule arg_cong[OF id_take_nth_drop[OF i]]) |
2197 by(rule arg_cong[OF id_take_nth_drop[OF i]]) |
2198 also have "\<dots> = take i xs @ a # drop (Suc i) xs" |
2198 also have "\<dots> = take i xs @ a # drop (Suc i) xs" |
2199 using i by (simp add: list_update_append) |
2199 using i by (simp add: list_update_append) |
2200 finally show ?thesis . |
2200 finally show ?thesis . |
2201 qed |
2201 qed |
2202 |
|
2203 lemma nth_drop': |
|
2204 "i < length xs \<Longrightarrow> xs ! i # drop (Suc i) xs = drop i xs" |
|
2205 apply (induct i arbitrary: xs) |
|
2206 apply (simp add: neq_Nil_conv) |
|
2207 apply (erule exE)+ |
|
2208 apply simp |
|
2209 apply (case_tac xs) |
|
2210 apply simp_all |
|
2211 done |
|
2212 |
2202 |
2213 |
2203 |
2214 subsubsection {* @{const takeWhile} and @{const dropWhile} *} |
2204 subsubsection {* @{const takeWhile} and @{const dropWhile} *} |
2215 |
2205 |
2216 lemma length_takeWhile_le: "length (takeWhile P xs) \<le> length xs" |
2206 lemma length_takeWhile_le: "length (takeWhile P xs) \<le> length xs" |
5262 apply (rule_tac x ="length u" in exI, simp) |
5252 apply (rule_tac x ="length u" in exI, simp) |
5263 apply (rule_tac x ="take i x" in exI) |
5253 apply (rule_tac x ="take i x" in exI) |
5264 apply (rule_tac x ="x ! i" in exI) |
5254 apply (rule_tac x ="x ! i" in exI) |
5265 apply (rule_tac x ="y ! i" in exI, safe) |
5255 apply (rule_tac x ="y ! i" in exI, safe) |
5266 apply (rule_tac x="drop (Suc i) x" in exI) |
5256 apply (rule_tac x="drop (Suc i) x" in exI) |
5267 apply (drule sym, simp add: drop_Suc_conv_tl) |
5257 apply (drule sym, simp add: Cons_nth_drop_Suc) |
5268 apply (rule_tac x="drop (Suc i) y" in exI) |
5258 apply (rule_tac x="drop (Suc i) y" in exI) |
5269 by (simp add: drop_Suc_conv_tl) |
5259 by (simp add: Cons_nth_drop_Suc) |
5270 |
5260 |
5271 -- {* lexord is extension of partial ordering List.lex *} |
5261 -- {* lexord is extension of partial ordering List.lex *} |
5272 lemma lexord_lex: "(x,y) \<in> lex r = ((x,y) \<in> lexord r \<and> length x = length y)" |
5262 lemma lexord_lex: "(x,y) \<in> lex r = ((x,y) \<in> lexord r \<and> length x = length y)" |
5273 apply (rule_tac x = y in spec) |
5263 apply (rule_tac x = y in spec) |
5274 apply (induct_tac x, clarsimp) |
5264 apply (induct_tac x, clarsimp) |