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