40 remdups :: "'a list => 'a list" |
40 remdups :: "'a list => 'a list" |
41 remove1 :: "'a => 'a list => 'a list" |
41 remove1 :: "'a => 'a list => 'a list" |
42 "distinct":: "'a list => bool" |
42 "distinct":: "'a list => bool" |
43 replicate :: "nat => 'a => 'a list" |
43 replicate :: "nat => 'a => 'a list" |
44 splice :: "'a list \<Rightarrow> 'a list \<Rightarrow> 'a list" |
44 splice :: "'a list \<Rightarrow> 'a list \<Rightarrow> 'a list" |
|
45 partition :: "('a \<Rightarrow> bool) \<Rightarrow>'a list \<Rightarrow> (('a list) \<times> ('a list))" |
45 allpairs :: "('a \<Rightarrow> 'b \<Rightarrow> 'c) \<Rightarrow> 'a list \<Rightarrow> 'b list \<Rightarrow> 'c list" |
46 allpairs :: "('a \<Rightarrow> 'b \<Rightarrow> 'c) \<Rightarrow> 'a list \<Rightarrow> 'b list \<Rightarrow> 'c list" |
46 partition :: "('a \<Rightarrow> bool) \<Rightarrow>'a list \<Rightarrow> (('a list) \<times> ('a list))" |
|
47 |
47 |
48 abbreviation |
48 abbreviation |
49 upto:: "nat => nat => nat list" ("(1[_../_])") where |
49 upto:: "nat => nat => nat list" ("(1[_../_])") where |
50 "[i..j] == [i..<(Suc j)]" |
50 "[i..j] == [i..<(Suc j)]" |
51 |
51 |
55 syntax |
55 syntax |
56 -- {* list Enumeration *} |
56 -- {* list Enumeration *} |
57 "@list" :: "args => 'a list" ("[(_)]") |
57 "@list" :: "args => 'a list" ("[(_)]") |
58 |
58 |
59 -- {* Special syntax for filter *} |
59 -- {* Special syntax for filter *} |
60 "@filter" :: "[pttrn, 'a list, bool] => 'a list" ("(1[_:_./ _])") |
60 "@filter" :: "[pttrn, 'a list, bool] => 'a list" ("(1[_<-_./ _])") |
61 |
61 |
62 -- {* list update *} |
62 -- {* list update *} |
63 "_lupdbind":: "['a, 'a] => lupdbind" ("(2_ :=/ _)") |
63 "_lupdbind":: "['a, 'a] => lupdbind" ("(2_ :=/ _)") |
64 "" :: "lupdbind => lupdbinds" ("_") |
64 "" :: "lupdbind => lupdbinds" ("_") |
65 "_lupdbinds" :: "[lupdbind, lupdbinds] => lupdbinds" ("_,/ _") |
65 "_lupdbinds" :: "[lupdbind, lupdbinds] => lupdbinds" ("_,/ _") |
66 "_LUpdate" :: "['a, lupdbinds] => 'a" ("_/[(_)]" [900,0] 900) |
66 "_LUpdate" :: "['a, lupdbinds] => 'a" ("_/[(_)]" [900,0] 900) |
67 |
67 |
68 translations |
68 translations |
69 "[x, xs]" == "x#[xs]" |
69 "[x, xs]" == "x#[xs]" |
70 "[x]" == "x#[]" |
70 "[x]" == "x#[]" |
71 "[x:xs . P]"== "filter (%x. P) xs" |
71 "[x<-xs . P]"== "filter (%x. P) xs" |
72 |
72 |
73 "_LUpdate xs (_lupdbinds b bs)"== "_LUpdate (_LUpdate xs b) bs" |
73 "_LUpdate xs (_lupdbinds b bs)"== "_LUpdate (_LUpdate xs b) bs" |
74 "xs[i:=x]" == "list_update xs i x" |
74 "xs[i:=x]" == "list_update xs i x" |
75 |
75 |
76 |
76 |
77 syntax (xsymbols) |
77 syntax (xsymbols) |
78 "@filter" :: "[pttrn, 'a list, bool] => 'a list"("(1[_\<in>_ ./ _])") |
78 "@filter" :: "[pttrn, 'a list, bool] => 'a list"("(1[_\<leftarrow>_ ./ _])") |
79 syntax (HTML output) |
79 syntax (HTML output) |
80 "@filter" :: "[pttrn, 'a list, bool] => 'a list"("(1[_\<in>_ ./ _])") |
80 "@filter" :: "[pttrn, 'a list, bool] => 'a list"("(1[_\<leftarrow>_ ./ _])") |
81 |
81 |
82 |
82 |
83 text {* |
83 text {* |
84 Function @{text size} is overloaded for all datatypes. Users may |
84 Function @{text size} is overloaded for all datatypes. Users may |
85 refer to the list version as @{text length}. *} |
85 refer to the list version as @{text length}. *} |
251 |
251 |
252 nonterminals lc_qual lc_quals |
252 nonterminals lc_qual lc_quals |
253 |
253 |
254 syntax |
254 syntax |
255 "_listcompr" :: "'a \<Rightarrow> lc_qual \<Rightarrow> lc_quals \<Rightarrow> 'a list" ("[_ . __") |
255 "_listcompr" :: "'a \<Rightarrow> lc_qual \<Rightarrow> lc_quals \<Rightarrow> 'a list" ("[_ . __") |
256 "_lc_gen" :: "pttrn \<Rightarrow> 'a list \<Rightarrow> lc_qual" ("_ \<leftarrow> _") |
|
257 "_lc_gen" :: "pttrn \<Rightarrow> 'a list \<Rightarrow> lc_qual" ("_ <- _") |
256 "_lc_gen" :: "pttrn \<Rightarrow> 'a list \<Rightarrow> lc_qual" ("_ <- _") |
258 "_lc_test" :: "bool \<Rightarrow> lc_qual" ("_") |
257 "_lc_test" :: "bool \<Rightarrow> lc_qual" ("_") |
259 "_lc_end" :: "lc_quals" ("]") |
258 "_lc_end" :: "lc_quals" ("]") |
260 "_lc_quals" :: "lc_qual \<Rightarrow> lc_quals \<Rightarrow> lc_quals" (", __") |
259 "_lc_quals" :: "lc_qual \<Rightarrow> lc_quals \<Rightarrow> lc_quals" (", __") |
261 |
260 |
262 translations |
261 translations |
263 "[e. p\<leftarrow>xs]" => "map (%p. e) xs" |
262 "[e. p<-xs]" => "map (%p. e) xs" |
264 "_listcompr e (_lc_gen p xs) (_lc_quals Q Qs)" |
263 "_listcompr e (_lc_gen p xs) (_lc_quals Q Qs)" |
265 => "concat (map (%p. _listcompr e Q Qs) xs)" |
264 => "concat (map (%p. _listcompr e Q Qs) xs)" |
266 "[e. P]" => "if P then [e] else []" |
265 "[e. P]" => "if P then [e] else []" |
267 "_listcompr e (_lc_test P) (_lc_quals Q Qs)" |
266 "_listcompr e (_lc_test P) (_lc_quals Q Qs)" |
268 => "if P then (_listcompr e Q Qs) else []" |
267 => "if P then (_listcompr e Q Qs) else []" |
|
268 |
|
269 syntax (xsymbols) |
|
270 "_lc_gen" :: "pttrn \<Rightarrow> 'a list \<Rightarrow> lc_qual" ("_ \<leftarrow> _") |
|
271 syntax (HTML output) |
|
272 "_lc_gen" :: "pttrn \<Rightarrow> 'a list \<Rightarrow> lc_qual" ("_ \<leftarrow> _") |
|
273 |
269 |
274 |
270 (* |
275 (* |
271 term "[(x,y,z). b]" |
276 term "[(x,y,z). b]" |
272 term "[(x,y,z). x \<leftarrow> xs]" |
277 term "[(x,y,z). x \<leftarrow> xs]" |
273 term "[(x,y,z). x<a, x>b]" |
278 term "[(x,y,z). x<a, x>b]" |
2268 apply simp |
2273 apply simp |
2269 apply simp |
2274 apply simp |
2270 done |
2275 done |
2271 |
2276 |
2272 lemma sublist_shift_lemma: |
2277 lemma sublist_shift_lemma: |
2273 "map fst [p:zip xs [i..<i + length xs] . snd p : A] = |
2278 "map fst [p<-zip xs [i..<i + length xs] . snd p : A] = |
2274 map fst [p:zip xs [0..<length xs] . snd p + i : A]" |
2279 map fst [p<-zip xs [0..<length xs] . snd p + i : A]" |
2275 by (induct xs rule: rev_induct) (simp_all add: add_commute) |
2280 by (induct xs rule: rev_induct) (simp_all add: add_commute) |
2276 |
2281 |
2277 lemma sublist_append: |
2282 lemma sublist_append: |
2278 "sublist (l @ l') A = sublist l A @ sublist l' {j. j + length l : A}" |
2283 "sublist (l @ l') A = sublist l A @ sublist l' {j. j + length l : A}" |
2279 apply (unfold sublist_def) |
2284 apply (unfold sublist_def) |
2351 apply(induct xs) apply simp |
2356 apply(induct xs) apply simp |
2352 apply(case_tac ys) |
2357 apply(case_tac ys) |
2353 apply auto |
2358 apply auto |
2354 done |
2359 done |
2355 |
2360 |
2356 |
|
2357 subsubsection {* @{const allpairs} *} |
2361 subsubsection {* @{const allpairs} *} |
2358 |
2362 |
2359 lemma allpairs_conv_concat: |
2363 lemma allpairs_conv_concat: |
2360 "allpairs f xs ys = concat(map (%x. map (f x) ys) xs)" |
2364 "allpairs f xs ys = concat(map (%x. map (f x) ys) xs)" |
2361 by(induct xs) auto |
2365 by(induct xs) auto |
2362 |
2366 |
2363 lemma allpairs_append: |
2367 lemma allpairs_append: |
2364 "allpairs f (xs @ ys) zs = allpairs f xs zs @ allpairs f ys zs" |
2368 "allpairs f (xs @ ys) zs = allpairs f xs zs @ allpairs f ys zs" |
2365 by(induct xs) auto |
2369 by(induct xs) auto |
2366 |
|
2367 |
|
2368 subsubsection{*Sets of Lists*} |
|
2369 |
2370 |
2370 subsubsection {* @{text lists}: the list-forming operator over sets *} |
2371 subsubsection {* @{text lists}: the list-forming operator over sets *} |
2371 |
2372 |
2372 inductive2 |
2373 inductive2 |
2373 listsp :: "('a \<Rightarrow> bool) \<Rightarrow> 'a list \<Rightarrow> bool" |
2374 listsp :: "('a \<Rightarrow> bool) \<Rightarrow> 'a list \<Rightarrow> bool" |