author | haftmann |
Fri, 06 Jan 2012 10:19:49 +0100 | |
changeset 46133 | d9fe85d3d2cd |
parent 46033 | 6fc579c917b8 |
child 46142 | 94479a979129 |
permissions | -rw-r--r-- |
45973 | 1 |
(* Author: Florian Haftmann, TU Muenchen *) |
37025 | 2 |
|
3 |
header {* Operations on lists beyond the standard List theory *} |
|
4 |
||
5 |
theory More_List |
|
45990
b7b905b23b2a
incorporated More_Set and More_List into the Main body -- to be consolidated later
haftmann
parents:
45973
diff
changeset
|
6 |
imports List |
37025 | 7 |
begin |
8 |
||
37028 | 9 |
text {* @{text nth_map} *} |
37025 | 10 |
|
11 |
definition nth_map :: "nat \<Rightarrow> ('a \<Rightarrow> 'a) \<Rightarrow> 'a list \<Rightarrow> 'a list" where |
|
12 |
"nth_map n f xs = (if n < length xs then |
|
13 |
take n xs @ [f (xs ! n)] @ drop (Suc n) xs |
|
14 |
else xs)" |
|
15 |
||
16 |
lemma nth_map_id: |
|
17 |
"n \<ge> length xs \<Longrightarrow> nth_map n f xs = xs" |
|
18 |
by (simp add: nth_map_def) |
|
19 |
||
20 |
lemma nth_map_unfold: |
|
21 |
"n < length xs \<Longrightarrow> nth_map n f xs = take n xs @ [f (xs ! n)] @ drop (Suc n) xs" |
|
22 |
by (simp add: nth_map_def) |
|
23 |
||
24 |
lemma nth_map_Nil [simp]: |
|
25 |
"nth_map n f [] = []" |
|
26 |
by (simp add: nth_map_def) |
|
27 |
||
28 |
lemma nth_map_zero [simp]: |
|
29 |
"nth_map 0 f (x # xs) = f x # xs" |
|
30 |
by (simp add: nth_map_def) |
|
31 |
||
32 |
lemma nth_map_Suc [simp]: |
|
33 |
"nth_map (Suc n) f (x # xs) = x # nth_map n f xs" |
|
34 |
by (simp add: nth_map_def) |
|
35 |
||
45145 | 36 |
|
37 |
text {* monad operation *} |
|
38 |
||
39 |
definition bind :: "'a list \<Rightarrow> ('a \<Rightarrow> 'b list) \<Rightarrow> 'b list" where |
|
40 |
"bind xs f = concat (map f xs)" |
|
41 |
||
42 |
lemma bind_simps [simp]: |
|
43 |
"bind [] f = []" |
|
44 |
"bind (x # xs) f = f x @ bind xs f" |
|
45 |
by (simp_all add: bind_def) |
|
46 |
||
37025 | 47 |
end |