author | paulson |
Fri, 30 May 1997 15:16:44 +0200 | |
changeset 3367 | 832c245d967c |
parent 3342 | ec3b55fcb165 |
child 3401 | 862e153afc12 |
permissions | -rw-r--r-- |
923 | 1 |
(* Title: HOL/List.thy |
2 |
ID: $Id$ |
|
3 |
Author: Tobias Nipkow |
|
4 |
Copyright 1994 TU Muenchen |
|
5 |
||
2512 | 6 |
The datatype of finite lists. |
923 | 7 |
*) |
8 |
||
3367 | 9 |
List = Divides + |
923 | 10 |
|
977
5d57287e5e1e
changed syntax of datatype declarations (curried types for constructor
clasohm
parents:
965
diff
changeset
|
11 |
datatype 'a list = "[]" ("[]") | "#" 'a ('a list) (infixr 65) |
923 | 12 |
|
13 |
consts |
|
3196 | 14 |
pred_list :: "('a list * 'a list) set" |
1908 | 15 |
"@" :: ['a list, 'a list] => 'a list (infixr 65) |
16 |
filter :: ['a => bool, 'a list] => 'a list |
|
2608 | 17 |
concat :: 'a list list => 'a list |
1908 | 18 |
foldl :: [['b,'a] => 'b, 'b, 'a list] => 'b |
19 |
hd :: 'a list => 'a |
|
20 |
length :: 'a list => nat |
|
2608 | 21 |
set_of_list :: 'a list => 'a set |
1908 | 22 |
list_all :: ('a => bool) => ('a list => bool) |
23 |
map :: ('a=>'b) => ('a list => 'b list) |
|
24 |
mem :: ['a, 'a list] => bool (infixl 55) |
|
25 |
nth :: [nat, 'a list] => 'a |
|
2608 | 26 |
take, drop :: [nat, 'a list] => 'a list |
27 |
takeWhile, |
|
28 |
dropWhile :: ('a => bool) => 'a list => 'a list |
|
1908 | 29 |
tl,ttl :: 'a list => 'a list |
30 |
rev :: 'a list => 'a list |
|
923 | 31 |
|
32 |
syntax |
|
33 |
(* list Enumeration *) |
|
2262 | 34 |
"@list" :: args => 'a list ("[(_)]") |
923 | 35 |
|
2512 | 36 |
(* Special syntax for filter *) |
2262 | 37 |
"@filter" :: [idt, 'a list, bool] => 'a list ("(1[_:_ ./ _])") |
923 | 38 |
|
39 |
translations |
|
40 |
"[x, xs]" == "x#[xs]" |
|
41 |
"[x]" == "x#[]" |
|
1475 | 42 |
"[x:xs . P]" == "filter (%x.P) xs" |
923 | 43 |
|
2262 | 44 |
syntax (symbols) |
45 |
"@filter" :: [idt, 'a list, bool] => 'a list ("(1[_\\<in>_ ./ _])") |
|
46 |
||
47 |
||
3342
ec3b55fcb165
New operator "lists" for formalizing sets of lists
paulson
parents:
3320
diff
changeset
|
48 |
consts |
ec3b55fcb165
New operator "lists" for formalizing sets of lists
paulson
parents:
3320
diff
changeset
|
49 |
lists :: 'a set => 'a list set |
ec3b55fcb165
New operator "lists" for formalizing sets of lists
paulson
parents:
3320
diff
changeset
|
50 |
|
ec3b55fcb165
New operator "lists" for formalizing sets of lists
paulson
parents:
3320
diff
changeset
|
51 |
inductive "lists A" |
ec3b55fcb165
New operator "lists" for formalizing sets of lists
paulson
parents:
3320
diff
changeset
|
52 |
intrs |
ec3b55fcb165
New operator "lists" for formalizing sets of lists
paulson
parents:
3320
diff
changeset
|
53 |
Nil "[]: lists A" |
ec3b55fcb165
New operator "lists" for formalizing sets of lists
paulson
parents:
3320
diff
changeset
|
54 |
Cons "[| a: A; l: lists A |] ==> a#l : lists A" |
ec3b55fcb165
New operator "lists" for formalizing sets of lists
paulson
parents:
3320
diff
changeset
|
55 |
|
ec3b55fcb165
New operator "lists" for formalizing sets of lists
paulson
parents:
3320
diff
changeset
|
56 |
|
3196 | 57 |
rules |
58 |
pred_list_def "pred_list == {(x,y). ? h. y = h#x}" |
|
59 |
||
923 | 60 |
primrec hd list |
3320 | 61 |
"hd([]) = arbitrary" |
1898 | 62 |
"hd(x#xs) = x" |
923 | 63 |
primrec tl list |
3320 | 64 |
"tl([]) = arbitrary" |
1898 | 65 |
"tl(x#xs) = xs" |
923 | 66 |
primrec ttl list |
67 |
(* a "total" version of tl: *) |
|
1898 | 68 |
"ttl([]) = []" |
69 |
"ttl(x#xs) = xs" |
|
923 | 70 |
primrec "op mem" list |
1898 | 71 |
"x mem [] = False" |
72 |
"x mem (y#ys) = (if y=x then True else x mem ys)" |
|
1908 | 73 |
primrec set_of_list list |
74 |
"set_of_list [] = {}" |
|
75 |
"set_of_list (x#xs) = insert x (set_of_list xs)" |
|
923 | 76 |
primrec list_all list |
77 |
list_all_Nil "list_all P [] = True" |
|
78 |
list_all_Cons "list_all P (x#xs) = (P(x) & list_all P xs)" |
|
79 |
primrec map list |
|
1898 | 80 |
"map f [] = []" |
81 |
"map f (x#xs) = f(x)#map f xs" |
|
923 | 82 |
primrec "op @" list |
1898 | 83 |
"[] @ ys = ys" |
84 |
"(x#xs)@ys = x#(xs@ys)" |
|
1169 | 85 |
primrec rev list |
1898 | 86 |
"rev([]) = []" |
87 |
"rev(x#xs) = rev(xs) @ [x]" |
|
923 | 88 |
primrec filter list |
1898 | 89 |
"filter P [] = []" |
90 |
"filter P (x#xs) = (if P x then x#filter P xs else filter P xs)" |
|
923 | 91 |
primrec foldl list |
1898 | 92 |
"foldl f a [] = a" |
93 |
"foldl f a (x#xs) = foldl f (f a x) xs" |
|
923 | 94 |
primrec length list |
1898 | 95 |
"length([]) = 0" |
96 |
"length(x#xs) = Suc(length(xs))" |
|
2608 | 97 |
primrec concat list |
98 |
"concat([]) = []" |
|
99 |
"concat(x#xs) = x @ concat(xs)" |
|
1419
a6a034a47a71
defined take/drop by induction over list rather than nat.
nipkow
parents:
1370
diff
changeset
|
100 |
primrec drop list |
a6a034a47a71
defined take/drop by induction over list rather than nat.
nipkow
parents:
1370
diff
changeset
|
101 |
drop_Nil "drop n [] = []" |
a6a034a47a71
defined take/drop by induction over list rather than nat.
nipkow
parents:
1370
diff
changeset
|
102 |
drop_Cons "drop n (x#xs) = (case n of 0 => x#xs | Suc(m) => drop m xs)" |
a6a034a47a71
defined take/drop by induction over list rather than nat.
nipkow
parents:
1370
diff
changeset
|
103 |
primrec take list |
a6a034a47a71
defined take/drop by induction over list rather than nat.
nipkow
parents:
1370
diff
changeset
|
104 |
take_Nil "take n [] = []" |
a6a034a47a71
defined take/drop by induction over list rather than nat.
nipkow
parents:
1370
diff
changeset
|
105 |
take_Cons "take n (x#xs) = (case n of 0 => [] | Suc(m) => x # take m xs)" |
2738 | 106 |
primrec nth nat |
107 |
"nth 0 xs = hd xs" |
|
108 |
"nth (Suc n) xs = nth n (tl xs)" |
|
2608 | 109 |
primrec takeWhile list |
110 |
"takeWhile P [] = []" |
|
111 |
"takeWhile P (x#xs) = (if P x then x#takeWhile P xs else [])" |
|
112 |
primrec dropWhile list |
|
113 |
"dropWhile P [] = []" |
|
114 |
"dropWhile P (x#xs) = (if P x then dropWhile P xs else xs)" |
|
3196 | 115 |
|
923 | 116 |
end |