equal
deleted
inserted
replaced
1175 by (blast dest!: set_update_subset_insert [THEN subsetD]) |
1175 by (blast dest!: set_update_subset_insert [THEN subsetD]) |
1176 |
1176 |
1177 lemma set_update_memI: "n < length xs \<Longrightarrow> x \<in> set (xs[n := x])" |
1177 lemma set_update_memI: "n < length xs \<Longrightarrow> x \<in> set (xs[n := x])" |
1178 by (induct xs arbitrary: n) (auto split:nat.splits) |
1178 by (induct xs arbitrary: n) (auto split:nat.splits) |
1179 |
1179 |
|
1180 lemma list_update_overwrite: |
|
1181 "xs [i := x, i := y] = xs [i := y]" |
|
1182 apply (induct xs arbitrary: i) |
|
1183 apply simp |
|
1184 apply (case_tac i) |
|
1185 apply simp_all |
|
1186 done |
|
1187 |
|
1188 lemma list_update_swap: |
|
1189 "i \<noteq> i' \<Longrightarrow> xs [i := x, i' := x'] = xs [i' := x', i := x]" |
|
1190 apply (induct xs arbitrary: i i') |
|
1191 apply simp |
|
1192 apply (case_tac i, case_tac i') |
|
1193 apply auto |
|
1194 apply (case_tac i') |
|
1195 apply auto |
|
1196 done |
|
1197 |
1180 |
1198 |
1181 subsubsection {* @{text last} and @{text butlast} *} |
1199 subsubsection {* @{text last} and @{text butlast} *} |
1182 |
1200 |
1183 lemma last_snoc [simp]: "last (xs @ [x]) = x" |
1201 lemma last_snoc [simp]: "last (xs @ [x]) = x" |
1184 by (induct xs) auto |
1202 by (induct xs) auto |
1234 apply (auto split:nat.split) |
1252 apply (auto split:nat.split) |
1235 done |
1253 done |
1236 |
1254 |
1237 lemma last_conv_nth: "xs\<noteq>[] \<Longrightarrow> last xs = xs!(length xs - 1)" |
1255 lemma last_conv_nth: "xs\<noteq>[] \<Longrightarrow> last xs = xs!(length xs - 1)" |
1238 by(induct xs)(auto simp:neq_Nil_conv) |
1256 by(induct xs)(auto simp:neq_Nil_conv) |
|
1257 |
1239 |
1258 |
1240 subsubsection {* @{text take} and @{text drop} *} |
1259 subsubsection {* @{text take} and @{text drop} *} |
1241 |
1260 |
1242 lemma take_0 [simp]: "take 0 xs = []" |
1261 lemma take_0 [simp]: "take 0 xs = []" |
1243 by (induct xs) auto |
1262 by (induct xs) auto |
1435 also have "\<dots> = take i xs @ a # drop (Suc i) xs" |
1454 also have "\<dots> = take i xs @ a # drop (Suc i) xs" |
1436 using i by (simp add: list_update_append) |
1455 using i by (simp add: list_update_append) |
1437 finally show ?thesis . |
1456 finally show ?thesis . |
1438 qed |
1457 qed |
1439 |
1458 |
|
1459 lemma nth_drop': |
|
1460 "i < length xs \<Longrightarrow> xs ! i # drop (Suc i) xs = drop i xs" |
|
1461 apply (induct i arbitrary: xs) |
|
1462 apply (simp add: neq_Nil_conv) |
|
1463 apply (erule exE)+ |
|
1464 apply simp |
|
1465 apply (case_tac xs) |
|
1466 apply simp_all |
|
1467 done |
|
1468 |
1440 |
1469 |
1441 subsubsection {* @{text takeWhile} and @{text dropWhile} *} |
1470 subsubsection {* @{text takeWhile} and @{text dropWhile} *} |
1442 |
1471 |
1443 lemma takeWhile_dropWhile_id [simp]: "takeWhile P xs @ dropWhile P xs = xs" |
1472 lemma takeWhile_dropWhile_id [simp]: "takeWhile P xs @ dropWhile P xs = xs" |
1444 by (induct xs) auto |
1473 by (induct xs) auto |
1979 lemma nth_equalityI: |
2008 lemma nth_equalityI: |
1980 "[| length xs = length ys; ALL i < length xs. xs!i = ys!i |] ==> xs = ys" |
2009 "[| length xs = length ys; ALL i < length xs. xs!i = ys!i |] ==> xs = ys" |
1981 apply (frule nth_take_lemma [OF le_refl eq_imp_le]) |
2010 apply (frule nth_take_lemma [OF le_refl eq_imp_le]) |
1982 apply (simp_all add: take_all) |
2011 apply (simp_all add: take_all) |
1983 done |
2012 done |
|
2013 |
|
2014 lemma map_nth: |
|
2015 "map (\<lambda>i. xs ! i) [0..<length xs] = xs" |
|
2016 by (rule nth_equalityI, auto) |
1984 |
2017 |
1985 (* needs nth_equalityI *) |
2018 (* needs nth_equalityI *) |
1986 lemma list_all2_antisym: |
2019 lemma list_all2_antisym: |
1987 "\<lbrakk> (\<And>x y. \<lbrakk>P x y; Q y x\<rbrakk> \<Longrightarrow> x = y); list_all2 P xs ys; list_all2 Q ys xs \<rbrakk> |
2020 "\<lbrakk> (\<And>x y. \<lbrakk>P x y; Q y x\<rbrakk> \<Longrightarrow> x = y); list_all2 P xs ys; list_all2 Q ys xs \<rbrakk> |
1988 \<Longrightarrow> xs = ys" |
2021 \<Longrightarrow> xs = ys" |
2266 lemma set_replicate_conv_if: "set (replicate n x) = (if n = 0 then {} else {x})" |
2299 lemma set_replicate_conv_if: "set (replicate n x) = (if n = 0 then {} else {x})" |
2267 by auto |
2300 by auto |
2268 |
2301 |
2269 lemma in_set_replicateD: "x : set (replicate n y) ==> x = y" |
2302 lemma in_set_replicateD: "x : set (replicate n y) ==> x = y" |
2270 by (simp add: set_replicate_conv_if split: split_if_asm) |
2303 by (simp add: set_replicate_conv_if split: split_if_asm) |
|
2304 |
|
2305 lemma replicate_append_same: |
|
2306 "replicate i x @ [x] = x # replicate i x" |
|
2307 by (induct i) simp_all |
|
2308 |
|
2309 lemma map_replicate_trivial: |
|
2310 "map (\<lambda>i. x) [0..<i] = replicate i x" |
|
2311 by (induct i) (simp_all add: replicate_append_same) |
2271 |
2312 |
2272 |
2313 |
2273 subsubsection{*@{text rotate1} and @{text rotate}*} |
2314 subsubsection{*@{text rotate1} and @{text rotate}*} |
2274 |
2315 |
2275 lemma rotate_simps[simp]: "rotate1 [] = [] \<and> rotate1 (x#xs) = xs @ [x]" |
2316 lemma rotate_simps[simp]: "rotate1 [] = [] \<and> rotate1 (x#xs) = xs @ [x]" |