src/HOL/List.thy
author nipkow
Fri Jan 17 10:09:46 1997 +0100 (1997-01-17)
changeset 2512 0231e4f467f2
parent 2369 8100f00e8950
child 2608 450c9b682a92
permissions -rw-r--r--
Got rid of Alls in List.
Added Ball_insert and Ball_Un in equalities.ML.
clasohm@923
     1
(*  Title:      HOL/List.thy
clasohm@923
     2
    ID:         $Id$
clasohm@923
     3
    Author:     Tobias Nipkow
clasohm@923
     4
    Copyright   1994 TU Muenchen
clasohm@923
     5
nipkow@2512
     6
The datatype of finite lists.
clasohm@923
     7
*)
clasohm@923
     8
clasohm@923
     9
List = Arith +
clasohm@923
    10
clasohm@977
    11
datatype 'a list = "[]" ("[]") | "#" 'a ('a list) (infixr 65)
clasohm@923
    12
clasohm@923
    13
consts
clasohm@923
    14
paulson@1908
    15
  "@"         :: ['a list, 'a list] => 'a list            (infixr 65)
paulson@1908
    16
  drop        :: [nat, 'a list] => 'a list
paulson@1908
    17
  filter      :: ['a => bool, 'a list] => 'a list
paulson@1908
    18
  flat        :: 'a list list => 'a list
paulson@1908
    19
  foldl       :: [['b,'a] => 'b, 'b, 'a list] => 'b
paulson@1908
    20
  hd          :: 'a list => 'a
paulson@1908
    21
  length      :: 'a list => nat
paulson@1908
    22
  set_of_list :: ('a list => 'a set)
paulson@1908
    23
  list_all    :: ('a => bool) => ('a list => bool)
paulson@1908
    24
  map         :: ('a=>'b) => ('a list => 'b list)
paulson@1908
    25
  mem         :: ['a, 'a list] => bool                    (infixl 55)
paulson@1908
    26
  nth         :: [nat, 'a list] => 'a
paulson@1908
    27
  take        :: [nat, 'a list] => 'a list
paulson@1908
    28
  tl,ttl      :: 'a list => 'a list
paulson@1908
    29
  rev         :: 'a list => 'a list
clasohm@923
    30
clasohm@923
    31
syntax
clasohm@923
    32
  (* list Enumeration *)
wenzelm@2262
    33
  "@list"     :: args => 'a list                          ("[(_)]")
clasohm@923
    34
nipkow@2512
    35
  (* Special syntax for filter *)
wenzelm@2262
    36
  "@filter"   :: [idt, 'a list, bool] => 'a list          ("(1[_:_ ./ _])")
clasohm@923
    37
clasohm@923
    38
translations
clasohm@923
    39
  "[x, xs]"     == "x#[xs]"
clasohm@923
    40
  "[x]"         == "x#[]"
clasohm@1475
    41
  "[x:xs . P]"  == "filter (%x.P) xs"
clasohm@923
    42
wenzelm@2262
    43
syntax (symbols)
wenzelm@2262
    44
  "@filter"   :: [idt, 'a list, bool] => 'a list          ("(1[_\\<in>_ ./ _])")
wenzelm@2262
    45
wenzelm@2262
    46
clasohm@923
    47
primrec hd list
berghofe@1898
    48
  "hd([]) = (@x.False)"
berghofe@1898
    49
  "hd(x#xs) = x"
clasohm@923
    50
primrec tl list
berghofe@1898
    51
  "tl([]) = (@x.False)"
berghofe@1898
    52
  "tl(x#xs) = xs"
clasohm@923
    53
primrec ttl list
clasohm@923
    54
  (* a "total" version of tl: *)
berghofe@1898
    55
  "ttl([]) = []"
berghofe@1898
    56
  "ttl(x#xs) = xs"
clasohm@923
    57
primrec "op mem" list
berghofe@1898
    58
  "x mem [] = False"
berghofe@1898
    59
  "x mem (y#ys) = (if y=x then True else x mem ys)"
paulson@1908
    60
primrec set_of_list list
paulson@1908
    61
  "set_of_list [] = {}"
paulson@1908
    62
  "set_of_list (x#xs) = insert x (set_of_list xs)"
clasohm@923
    63
primrec list_all list
clasohm@923
    64
  list_all_Nil  "list_all P [] = True"
clasohm@923
    65
  list_all_Cons "list_all P (x#xs) = (P(x) & list_all P xs)"
clasohm@923
    66
primrec map list
berghofe@1898
    67
  "map f [] = []"
berghofe@1898
    68
  "map f (x#xs) = f(x)#map f xs"
clasohm@923
    69
primrec "op @" list
berghofe@1898
    70
  "[] @ ys = ys"
berghofe@1898
    71
  "(x#xs)@ys = x#(xs@ys)"
lcp@1169
    72
primrec rev list
berghofe@1898
    73
  "rev([]) = []"
berghofe@1898
    74
  "rev(x#xs) = rev(xs) @ [x]"
clasohm@923
    75
primrec filter list
berghofe@1898
    76
  "filter P [] = []"
berghofe@1898
    77
  "filter P (x#xs) = (if P x then x#filter P xs else filter P xs)"
clasohm@923
    78
primrec foldl list
berghofe@1898
    79
  "foldl f a [] = a"
berghofe@1898
    80
  "foldl f a (x#xs) = foldl f (f a x) xs"
clasohm@923
    81
primrec length list
berghofe@1898
    82
  "length([]) = 0"
berghofe@1898
    83
  "length(x#xs) = Suc(length(xs))"
clasohm@923
    84
primrec flat list
berghofe@1898
    85
  "flat([]) = []"
berghofe@1898
    86
  "flat(x#xs) = x @ flat(xs)"
nipkow@1419
    87
primrec drop list
nipkow@1419
    88
  drop_Nil  "drop n [] = []"
nipkow@1419
    89
  drop_Cons "drop n (x#xs) = (case n of 0 => x#xs | Suc(m) => drop m xs)"
nipkow@1419
    90
primrec take list
nipkow@1419
    91
  take_Nil  "take n [] = []"
nipkow@1419
    92
  take_Cons "take n (x#xs) = (case n of 0 => [] | Suc(m) => x # take m xs)"
clasohm@923
    93
defs
berghofe@1824
    94
  nth_def  "nth(n) == nat_rec hd (%m r xs. r(tl(xs))) n"
clasohm@923
    95
end