src/HOL/Induct/SList.thy
author paulson
Tue, 13 Nov 2001 16:12:25 +0100
changeset 12169 d4ed9802082a
parent 11481 c77e5401f2ff
child 13079 e7738aa7267f
permissions -rw-r--r--
new SList theory from Bu Wolff
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
12169
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
     1
(* *********************************************************************** *)
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
     2
(*                                                                         *)
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
     3
(* Title:      SList.thy (Extended List Theory)                            *)
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
     4
(* Based on:   $Id$       *)
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
     5
(* Author:     Lawrence C Paulson, Cambridge University Computer Laboratory*)
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
     6
(* Author:     B. Wolff, University of Bremen                              *)
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
     7
(* Purpose:    Enriched theory of lists                                    *)
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
     8
(*	       mutual indirect recursive data-types                        *)
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
     9
(*                                                                         *)
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
    10
(* *********************************************************************** *)
3120
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
    11
12169
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
    12
(* Definition of type 'a list (strict lists) by a least fixed point
3120
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
    13
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
    14
We use          list(A) == lfp(%Z. {NUMB(0)} <+> A <*> Z)
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
    15
and not         list    == lfp(%Z. {NUMB(0)} <+> range(Leaf) <*> Z)
12169
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
    16
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
    17
so that list can serve as a "functor" for defining other recursive types.
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
    18
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
    19
This enables the conservative construction of mutual recursive data-types
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
    20
such as
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
    21
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
    22
datatype 'a m = Node 'a * ('a m) list
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
    23
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
    24
Tidied by lcp.  Still needs removal of nat_rec.
3120
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
    25
*)
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
    26
12169
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
    27
SList = NatArith + Sexp + Hilbert_Choice (*gives us "inv"*) +
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
    28
(* *********************************************************************** *)
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
    29
(*                                                                         *)
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
    30
(* Building up data type                                                   *)
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
    31
(*                                                                         *)
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
    32
(* *********************************************************************** *)
3120
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
    33
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
    34
consts
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
    35
12169
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
    36
  list      :: "'a item set => 'a item set"
3120
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
    37
12169
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
    38
  NIL       :: "'a item"
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
    39
  CONS      :: "['a item, 'a item] => 'a item"
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
    40
  List_case :: "['b, ['a item, 'a item]=>'b, 'a item] => 'b"
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
    41
  List_rec  :: "['a item, 'b, ['a item, 'a item, 'b]=>'b] => 'b"
3120
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
    42
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
    43
defs
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
    44
  (* Defining the Concrete Constructors *)
12169
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
    45
  NIL_def           "NIL == In0(Numb(0))"
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
    46
  CONS_def          "CONS M N == In1(Scons M N)"
3120
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
    47
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
    48
inductive "list(A)"
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
    49
  intrs
12169
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
    50
    NIL_I           "NIL: list A"
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
    51
    CONS_I          "[| a: A;  M: list A |] ==> CONS a M : list A"
3120
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
    52
5977
9f0c8869cf71 tidied up list definitions, using type 'a option instead of
paulson
parents: 5191
diff changeset
    53
9f0c8869cf71 tidied up list definitions, using type 'a option instead of
paulson
parents: 5191
diff changeset
    54
typedef (List)
6382
8b0c9205da75 fixed typedef representing set;
wenzelm
parents: 5977
diff changeset
    55
  'a list = "list(range Leaf) :: 'a item set" (list.NIL_I)
5977
9f0c8869cf71 tidied up list definitions, using type 'a option instead of
paulson
parents: 5191
diff changeset
    56
12169
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
    57
defs
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
    58
  List_case_def     "List_case c d == Case(%x. c)(Split(d))"
5977
9f0c8869cf71 tidied up list definitions, using type 'a option instead of
paulson
parents: 5191
diff changeset
    59
  
3120
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
    60
  List_rec_def
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
    61
   "List_rec M c d == wfrec (trancl pred_sexp)
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
    62
                            (%g. List_case c (%x y. d x y (g y))) M"
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
    63
5977
9f0c8869cf71 tidied up list definitions, using type 'a option instead of
paulson
parents: 5191
diff changeset
    64
12169
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
    65
(* *********************************************************************** *)
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
    66
(*                                                                         *)
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
    67
(* Abstracting data type                                                   *)
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
    68
(*                                                                         *)
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
    69
(* *********************************************************************** *)
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
    70
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
    71
(*Declaring the abstract list constructors*)
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
    72
consts
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
    73
  Nil       :: "'a list"
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
    74
  "#"       :: "['a, 'a list] => 'a list"           (infixr 65)
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
    75
  list_case :: "['b, ['a, 'a list]=>'b, 'a list] => 'b"
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
    76
  list_rec  :: "['a list, 'b, ['a, 'a list, 'b]=>'b] => 'b"
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
    77
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
    78
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
    79
(* list Enumeration *)
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
    80
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
    81
  "[]"      :: "'a list"                            ("[]")
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
    82
  "@list"   :: "args => 'a list"                    ("[(_)]")
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
    83
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
    84
translations
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
    85
  "[x, xs]" == "x#[xs]"
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
    86
  "[x]"     == "x#[]"
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
    87
  "[]"      == "Nil"
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
    88
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
    89
  "case xs of Nil => a | y#ys => b" == "list_case(a, %y ys. b, xs)"
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
    90
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
    91
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
    92
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
    93
defs
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
    94
  (* Defining the Abstract Constructors *)
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
    95
  Nil_def           "Nil  == Abs_List(NIL)"
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
    96
  Cons_def          "x#xs == Abs_List(CONS (Leaf x)(Rep_List xs))"
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
    97
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
    98
  list_case_def     "list_case a f xs == list_rec xs a (%x xs r. f x xs)"
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
    99
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
   100
  (* list Recursion -- the trancl is Essential; see list.ML *)
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
   101
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
   102
  list_rec_def
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
   103
   "list_rec l c d ==                                              \
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
   104
   \   List_rec(Rep_List l) c (%x y r. d(inv Leaf x)(Abs_List y) r)"
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
   105
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
   106
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
   107
  
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
   108
(* *********************************************************************** *)
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
   109
(*                                                                         *)
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
   110
(* Generalized Map Functionals                                             *)
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
   111
(*                                                                         *)
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
   112
(* *********************************************************************** *)
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
   113
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
   114
  
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
   115
(* Generalized Map Functionals *)
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
   116
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
   117
consts
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
   118
  Rep_map   :: "('b => 'a item) => ('b list => 'a item)"
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
   119
  Abs_map   :: "('a item => 'b) => 'a item => 'b list"
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
   120
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
   121
defs
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
   122
  Rep_map_def "Rep_map f xs == list_rec xs  NIL(%x l r. CONS(f x) r)"
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
   123
  Abs_map_def "Abs_map g M  == List_rec M Nil (%N L r. g(N)#r)"
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
   124
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
   125
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
   126
(**** Function definitions ****)
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
   127
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
   128
constdefs
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
   129
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
   130
  null      :: "'a list => bool"
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
   131
  "null xs  == list_rec xs True (%x xs r. False)"
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
   132
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
   133
  hd        :: "'a list => 'a"
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
   134
  "hd xs    == list_rec xs (@x. True) (%x xs r. x)"
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
   135
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
   136
  tl        :: "'a list => 'a list"
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
   137
  "tl xs    == list_rec xs (@xs. True) (%x xs r. xs)"
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
   138
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
   139
  (* a total version of tl: *)
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
   140
  ttl       :: "'a list => 'a list"
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
   141
  "ttl xs   == list_rec xs [] (%x xs r. xs)"
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
   142
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
   143
  mem       :: "['a, 'a list] => bool"                              (infixl 55)
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
   144
  "x mem xs == list_rec xs False (%y ys r. if y=x then True else r)"
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
   145
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
   146
  list_all  :: "('a => bool) => ('a list => bool)"
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
   147
  "list_all P xs == list_rec xs True(%x l r. P(x) & r)"
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
   148
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
   149
  map       :: "('a=>'b) => ('a list => 'b list)"
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
   150
  "map f xs == list_rec xs [] (%x l r. f(x)#r)"
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
   151
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
   152
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
   153
consts
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
   154
  "@"       :: ['a list, 'a list] => 'a list                        (infixr 65)
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
   155
defs
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
   156
  append_def"xs@ys == list_rec xs ys (%x l r. x#r)"
5977
9f0c8869cf71 tidied up list definitions, using type 'a option instead of
paulson
parents: 5191
diff changeset
   157
9f0c8869cf71 tidied up list definitions, using type 'a option instead of
paulson
parents: 5191
diff changeset
   158
9f0c8869cf71 tidied up list definitions, using type 'a option instead of
paulson
parents: 5191
diff changeset
   159
constdefs
12169
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
   160
  filter    :: "['a => bool, 'a list] => 'a list"
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
   161
  "filter P xs == list_rec xs []  (%x xs r. if P(x)then x#r else r)"
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
   162
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
   163
  foldl     :: "[['b,'a] => 'b, 'b, 'a list] => 'b"
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
   164
  "foldl f a xs == list_rec xs (%a. a)(%x xs r.%a. r(f a x))(a)"
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
   165
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
   166
  foldr     :: "[['a,'b] => 'b, 'b, 'a list] => 'b"
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
   167
  "foldr f a xs     == list_rec xs a (%x xs r. (f x r))"
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
   168
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
   169
  length    :: "'a list => nat"
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
   170
  "length xs== list_rec xs 0 (%x xs r. Suc r)"
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
   171
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
   172
  drop      :: "['a list,nat] => 'a list"
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
   173
  "drop t n == (nat_rec(%x. x)(%m r xs. r(ttl xs)))(n)(t)"
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
   174
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
   175
  copy      :: "['a, nat] => 'a list"      (* make list of n copies of x *)
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
   176
  "copy t   == nat_rec [] (%m xs. t # xs)"
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
   177
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
   178
  flat      :: "'a list list => 'a list"
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
   179
  "flat     == foldr (op @) []"
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
   180
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
   181
  nth       :: "[nat, 'a list] => 'a"
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
   182
  "nth      == nat_rec hd (%m r xs. r(tl xs))"
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
   183
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
   184
  rev       :: "'a list => 'a list"
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
   185
  "rev xs   == list_rec xs [] (%x xs xsa. xsa @ [x])"
5977
9f0c8869cf71 tidied up list definitions, using type 'a option instead of
paulson
parents: 5191
diff changeset
   186
3120
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   187
12169
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
   188
(* miscellaneous definitions *)
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
   189
  zip       :: "'a list * 'b list => ('a*'b) list"
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
   190
  "zip      == zipWith  (%s. s)"
3120
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   191
12169
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
   192
  zipWith   :: "['a * 'b => 'c, 'a list * 'b list] => 'c list"
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
   193
  "zipWith f S == (list_rec (fst S)  (%T.[])
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
   194
                            (%x xs r. %T. if null T then [] 
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
   195
                                          else f(x,hd T) # r(tl T)))(snd(S))"
3120
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   196
12169
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
   197
  unzip     :: "('a*'b) list => ('a list * 'b list)"
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
   198
  "unzip    == foldr(% (a,b)(c,d).(a#c,b#d))([],[])"
5977
9f0c8869cf71 tidied up list definitions, using type 'a option instead of
paulson
parents: 5191
diff changeset
   199
9f0c8869cf71 tidied up list definitions, using type 'a option instead of
paulson
parents: 5191
diff changeset
   200
12169
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
   201
consts take      :: "['a list,nat] => 'a list"
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
   202
primrec
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
   203
  take_0  "take xs 0 = []"
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
   204
  take_Suc "take xs (Suc n) = list_case [] (%x l. x # take l n) xs"
3120
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   205
12169
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
   206
consts enum      :: "[nat,nat] => nat list"
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
   207
primrec
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
   208
  enum_0   "enum i 0 = []"
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
   209
  enum_Suc "enum i (Suc j) = (if i <= j then enum i j @ [j] else [])"
5977
9f0c8869cf71 tidied up list definitions, using type 'a option instead of
paulson
parents: 5191
diff changeset
   210
9f0c8869cf71 tidied up list definitions, using type 'a option instead of
paulson
parents: 5191
diff changeset
   211
12169
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
   212
syntax
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
   213
  (* Special syntax for list_all and filter *)
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
   214
  "@Alls"       :: "[idt, 'a list, bool] => bool"        ("(2Alls _:_./ _)" 10)
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
   215
  "@filter"     :: "[idt, 'a list, bool] => 'a list"        ("(1[_:_ ./ _])")
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
   216
5977
9f0c8869cf71 tidied up list definitions, using type 'a option instead of
paulson
parents: 5191
diff changeset
   217
translations
12169
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
   218
  "[x:xs. P]"   == "filter(%x. P) xs"
d4ed9802082a new SList theory from Bu Wolff
paulson
parents: 11481
diff changeset
   219
  "Alls x:xs. P"== "list_all(%x. P)xs"
5977
9f0c8869cf71 tidied up list definitions, using type 'a option instead of
paulson
parents: 5191
diff changeset
   220
3120
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   221
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   222
end