src/HOL/List.thy
author nipkow
Thu, 14 Feb 2002 11:50:52 +0100
changeset 12887 d25b43743e10
parent 12114 a8e860c86252
child 13114 f2b00262bdfc
permissions -rw-r--r--
nodups -> distinct
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
     1
(*  Title:      HOL/List.thy
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
     2
    ID:         $Id$
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
     3
    Author:     Tobias Nipkow
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
     4
    Copyright   1994 TU Muenchen
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
     5
2512
0231e4f467f2 Got rid of Alls in List.
nipkow
parents: 2369
diff changeset
     6
The datatype of finite lists.
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
     7
*)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
     8
8490
6e0f23304061 added HOL/PreLIst.thy;
wenzelm
parents: 8115
diff changeset
     9
List = PreList +
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    10
7224
e41e64476f9b 'a list: Nil, Cons;
wenzelm
parents: 7032
diff changeset
    11
datatype 'a list = Nil ("[]") | Cons 'a ('a list) (infixr "#" 65)
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    12
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    13
consts
1908
55d8e38262a8 Renamed setOfList to set_of_list
paulson
parents: 1898
diff changeset
    14
  "@"         :: ['a list, 'a list] => 'a list            (infixr 65)
55d8e38262a8 Renamed setOfList to set_of_list
paulson
parents: 1898
diff changeset
    15
  filter      :: ['a => bool, 'a list] => 'a list
2608
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents: 2512
diff changeset
    16
  concat      :: 'a list list => 'a list
1908
55d8e38262a8 Renamed setOfList to set_of_list
paulson
parents: 1898
diff changeset
    17
  foldl       :: [['b,'a] => 'b, 'b, 'a list] => 'b
8000
acafa0f15131 added foldr
paulson
parents: 7224
diff changeset
    18
  foldr       :: [['a,'b] => 'b, 'a list, 'b] => 'b
3896
ee8ebb74ec00 Various new lemmas. Improved conversion of equations to rewrite rules:
nipkow
parents: 3842
diff changeset
    19
  hd, last    :: 'a list => 'a
3465
e85c24717cad set_of_list -> set
nipkow
parents: 3437
diff changeset
    20
  set         :: 'a list => 'a set
5518
654ead0ba4f7 re-added mem and list_all
oheimb
parents: 5443
diff changeset
    21
  list_all    :: ('a => bool) => ('a list => bool)
8115
c802042066e8 Forgot to "call" MicroJava in makefile.
nipkow
parents: 8000
diff changeset
    22
  list_all2   :: ('a => 'b => bool) => 'a list => 'b list => bool
1908
55d8e38262a8 Renamed setOfList to set_of_list
paulson
parents: 1898
diff changeset
    23
  map         :: ('a=>'b) => ('a list => 'b list)
5518
654ead0ba4f7 re-added mem and list_all
oheimb
parents: 5443
diff changeset
    24
  mem         :: ['a, 'a list] => bool                    (infixl 55)
4502
337c073de95e nth -> !
nipkow
parents: 4151
diff changeset
    25
  nth         :: ['a list, nat] => 'a			  (infixl "!" 100)
5077
71043526295f * HOL/List: new function list_update written xs[i:=v] that updates the i-th
nipkow
parents: 4643
diff changeset
    26
  list_update :: 'a list => nat => 'a => 'a list
2608
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents: 2512
diff changeset
    27
  take, drop  :: [nat, 'a list] => 'a list
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents: 2512
diff changeset
    28
  takeWhile,
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents: 2512
diff changeset
    29
  dropWhile   :: ('a => bool) => 'a list => 'a list
3896
ee8ebb74ec00 Various new lemmas. Improved conversion of equations to rewrite rules:
nipkow
parents: 3842
diff changeset
    30
  tl, butlast :: 'a list => 'a list
1908
55d8e38262a8 Renamed setOfList to set_of_list
paulson
parents: 1898
diff changeset
    31
  rev         :: 'a list => 'a list
4132
daff3c9987cc added zip and nodup
oheimb
parents: 3896
diff changeset
    32
  zip	      :: "'a list => 'b list => ('a * 'b) list"
5427
26c9a7c0b36b Arith: less_diff_conv
nipkow
parents: 5425
diff changeset
    33
  upt         :: nat => nat => nat list                   ("(1[_../_'(])")
12887
d25b43743e10 nodups -> distinct
nipkow
parents: 12114
diff changeset
    34
  remdups     :: "'a list => 'a list"
d25b43743e10 nodups -> distinct
nipkow
parents: 12114
diff changeset
    35
  null, "distinct" :: "'a list => bool"
3589
244daa75f890 Added function `replicate' and lemmas map_cong and set_replicate.
nipkow
parents: 3584
diff changeset
    36
  replicate   :: nat => 'a => 'a list
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    37
5077
71043526295f * HOL/List: new function list_update written xs[i:=v] that updates the i-th
nipkow
parents: 4643
diff changeset
    38
nonterminals
71043526295f * HOL/List: new function list_update written xs[i:=v] that updates the i-th
nipkow
parents: 4643
diff changeset
    39
  lupdbinds  lupdbind
71043526295f * HOL/List: new function list_update written xs[i:=v] that updates the i-th
nipkow
parents: 4643
diff changeset
    40
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    41
syntax
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    42
  (* list Enumeration *)
2262
c7ee913746fd added symbols syntax;
wenzelm
parents: 1908
diff changeset
    43
  "@list"     :: args => 'a list                          ("[(_)]")
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    44
2512
0231e4f467f2 Got rid of Alls in List.
nipkow
parents: 2369
diff changeset
    45
  (* Special syntax for filter *)
9341
40bab6613000 tuned syntax
oheimb
parents: 9336
diff changeset
    46
  "@filter"   :: [pttrn, 'a list, bool] => 'a list        ("(1[_:_./ _])")
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    47
5077
71043526295f * HOL/List: new function list_update written xs[i:=v] that updates the i-th
nipkow
parents: 4643
diff changeset
    48
  (* list update *)
71043526295f * HOL/List: new function list_update written xs[i:=v] that updates the i-th
nipkow
parents: 4643
diff changeset
    49
  "_lupdbind"      :: ['a, 'a] => lupdbind            ("(2_ :=/ _)")
71043526295f * HOL/List: new function list_update written xs[i:=v] that updates the i-th
nipkow
parents: 4643
diff changeset
    50
  ""               :: lupdbind => lupdbinds           ("_")
71043526295f * HOL/List: new function list_update written xs[i:=v] that updates the i-th
nipkow
parents: 4643
diff changeset
    51
  "_lupdbinds"     :: [lupdbind, lupdbinds] => lupdbinds ("_,/ _")
71043526295f * HOL/List: new function list_update written xs[i:=v] that updates the i-th
nipkow
parents: 4643
diff changeset
    52
  "_LUpdate"       :: ['a, lupdbinds] => 'a           ("_/[(_)]" [900,0] 900)
71043526295f * HOL/List: new function list_update written xs[i:=v] that updates the i-th
nipkow
parents: 4643
diff changeset
    53
5427
26c9a7c0b36b Arith: less_diff_conv
nipkow
parents: 5425
diff changeset
    54
  upto        :: nat => nat => nat list                   ("(1[_../_])")
26c9a7c0b36b Arith: less_diff_conv
nipkow
parents: 5425
diff changeset
    55
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    56
translations
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    57
  "[x, xs]"     == "x#[xs]"
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    58
  "[x]"         == "x#[]"
3842
b55686a7b22c fixed dots;
wenzelm
parents: 3589
diff changeset
    59
  "[x:xs . P]"  == "filter (%x. P) xs"
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    60
5077
71043526295f * HOL/List: new function list_update written xs[i:=v] that updates the i-th
nipkow
parents: 4643
diff changeset
    61
  "_LUpdate xs (_lupdbinds b bs)"  == "_LUpdate (_LUpdate xs b) bs"
71043526295f * HOL/List: new function list_update written xs[i:=v] that updates the i-th
nipkow
parents: 4643
diff changeset
    62
  "xs[i:=x]"                       == "list_update xs i x"
71043526295f * HOL/List: new function list_update written xs[i:=v] that updates the i-th
nipkow
parents: 4643
diff changeset
    63
5427
26c9a7c0b36b Arith: less_diff_conv
nipkow
parents: 5425
diff changeset
    64
  "[i..j]" == "[i..(Suc j)(]"
26c9a7c0b36b Arith: less_diff_conv
nipkow
parents: 5425
diff changeset
    65
26c9a7c0b36b Arith: less_diff_conv
nipkow
parents: 5425
diff changeset
    66
12114
a8e860c86252 eliminated old "symbols" syntax, use "xsymbols" instead;
wenzelm
parents: 10832
diff changeset
    67
syntax (xsymbols)
5295
25fb5156e0d9 replaced idt by pttrn in @filter
oheimb
parents: 5281
diff changeset
    68
  "@filter"   :: [pttrn, 'a list, bool] => 'a list        ("(1[_\\<in>_ ./ _])")
2262
c7ee913746fd added symbols syntax;
wenzelm
parents: 1908
diff changeset
    69
c7ee913746fd added symbols syntax;
wenzelm
parents: 1908
diff changeset
    70
3342
ec3b55fcb165 New operator "lists" for formalizing sets of lists
paulson
parents: 3320
diff changeset
    71
consts
ec3b55fcb165 New operator "lists" for formalizing sets of lists
paulson
parents: 3320
diff changeset
    72
  lists        :: 'a set => 'a list set
ec3b55fcb165 New operator "lists" for formalizing sets of lists
paulson
parents: 3320
diff changeset
    73
ec3b55fcb165 New operator "lists" for formalizing sets of lists
paulson
parents: 3320
diff changeset
    74
  inductive "lists A"
ec3b55fcb165 New operator "lists" for formalizing sets of lists
paulson
parents: 3320
diff changeset
    75
  intrs
ec3b55fcb165 New operator "lists" for formalizing sets of lists
paulson
parents: 3320
diff changeset
    76
    Nil  "[]: lists A"
ec3b55fcb165 New operator "lists" for formalizing sets of lists
paulson
parents: 3320
diff changeset
    77
    Cons "[| a: A;  l: lists A |] ==> a#l : lists A"
ec3b55fcb165 New operator "lists" for formalizing sets of lists
paulson
parents: 3320
diff changeset
    78
ec3b55fcb165 New operator "lists" for formalizing sets of lists
paulson
parents: 3320
diff changeset
    79
3437
bea2faf1641d Replacing the primrec definition of "length" by a translation to the built-in
paulson
parents: 3401
diff changeset
    80
(*Function "size" is overloaded for all datatypes.  Users may refer to the
bea2faf1641d Replacing the primrec definition of "length" by a translation to the built-in
paulson
parents: 3401
diff changeset
    81
  list version as "length".*)
bea2faf1641d Replacing the primrec definition of "length" by a translation to the built-in
paulson
parents: 3401
diff changeset
    82
syntax   length :: 'a list => nat
3507
157be29ad5ba Improved length = size translation.
nipkow
parents: 3465
diff changeset
    83
translations  "length"  =>  "size:: _ list => nat"
3437
bea2faf1641d Replacing the primrec definition of "length" by a translation to the built-in
paulson
parents: 3401
diff changeset
    84
5183
89f162de39cf Adapted to new datatype package.
berghofe
parents: 5162
diff changeset
    85
primrec
1898
260a9711f507 Simplified primrec definitions.
berghofe
parents: 1824
diff changeset
    86
  "hd(x#xs) = x"
5183
89f162de39cf Adapted to new datatype package.
berghofe
parents: 5162
diff changeset
    87
primrec
8972
b734bdb6042d better indentation; declared function "null"
paulson
parents: 8873
diff changeset
    88
  "tl([])   = []"
1898
260a9711f507 Simplified primrec definitions.
berghofe
parents: 1824
diff changeset
    89
  "tl(x#xs) = xs"
5183
89f162de39cf Adapted to new datatype package.
berghofe
parents: 5162
diff changeset
    90
primrec
8972
b734bdb6042d better indentation; declared function "null"
paulson
parents: 8873
diff changeset
    91
  "null([])   = True"
b734bdb6042d better indentation; declared function "null"
paulson
parents: 8873
diff changeset
    92
  "null(x#xs) = False"
b734bdb6042d better indentation; declared function "null"
paulson
parents: 8873
diff changeset
    93
primrec
3896
ee8ebb74ec00 Various new lemmas. Improved conversion of equations to rewrite rules:
nipkow
parents: 3842
diff changeset
    94
  "last(x#xs) = (if xs=[] then x else last xs)"
5183
89f162de39cf Adapted to new datatype package.
berghofe
parents: 5162
diff changeset
    95
primrec
8972
b734bdb6042d better indentation; declared function "null"
paulson
parents: 8873
diff changeset
    96
  "butlast []    = []"
3896
ee8ebb74ec00 Various new lemmas. Improved conversion of equations to rewrite rules:
nipkow
parents: 3842
diff changeset
    97
  "butlast(x#xs) = (if xs=[] then [] else x#butlast xs)"
5183
89f162de39cf Adapted to new datatype package.
berghofe
parents: 5162
diff changeset
    98
primrec
8972
b734bdb6042d better indentation; declared function "null"
paulson
parents: 8873
diff changeset
    99
  "x mem []     = False"
5518
654ead0ba4f7 re-added mem and list_all
oheimb
parents: 5443
diff changeset
   100
  "x mem (y#ys) = (if y=x then True else x mem ys)"
654ead0ba4f7 re-added mem and list_all
oheimb
parents: 5443
diff changeset
   101
primrec
3465
e85c24717cad set_of_list -> set
nipkow
parents: 3437
diff changeset
   102
  "set [] = {}"
e85c24717cad set_of_list -> set
nipkow
parents: 3437
diff changeset
   103
  "set (x#xs) = insert x (set xs)"
5183
89f162de39cf Adapted to new datatype package.
berghofe
parents: 5162
diff changeset
   104
primrec
5518
654ead0ba4f7 re-added mem and list_all
oheimb
parents: 5443
diff changeset
   105
  list_all_Nil  "list_all P [] = True"
654ead0ba4f7 re-added mem and list_all
oheimb
parents: 5443
diff changeset
   106
  list_all_Cons "list_all P (x#xs) = (P(x) & list_all P xs)"
654ead0ba4f7 re-added mem and list_all
oheimb
parents: 5443
diff changeset
   107
primrec
8972
b734bdb6042d better indentation; declared function "null"
paulson
parents: 8873
diff changeset
   108
  "map f []     = []"
1898
260a9711f507 Simplified primrec definitions.
berghofe
parents: 1824
diff changeset
   109
  "map f (x#xs) = f(x)#map f xs"
5183
89f162de39cf Adapted to new datatype package.
berghofe
parents: 5162
diff changeset
   110
primrec
89f162de39cf Adapted to new datatype package.
berghofe
parents: 5162
diff changeset
   111
  append_Nil  "[]    @ys = ys"
89f162de39cf Adapted to new datatype package.
berghofe
parents: 5162
diff changeset
   112
  append_Cons "(x#xs)@ys = x#(xs@ys)"
89f162de39cf Adapted to new datatype package.
berghofe
parents: 5162
diff changeset
   113
primrec
8972
b734bdb6042d better indentation; declared function "null"
paulson
parents: 8873
diff changeset
   114
  "rev([])   = []"
1898
260a9711f507 Simplified primrec definitions.
berghofe
parents: 1824
diff changeset
   115
  "rev(x#xs) = rev(xs) @ [x]"
5183
89f162de39cf Adapted to new datatype package.
berghofe
parents: 5162
diff changeset
   116
primrec
8972
b734bdb6042d better indentation; declared function "null"
paulson
parents: 8873
diff changeset
   117
  "filter P []     = []"
1898
260a9711f507 Simplified primrec definitions.
berghofe
parents: 1824
diff changeset
   118
  "filter P (x#xs) = (if P x then x#filter P xs else filter P xs)"
5183
89f162de39cf Adapted to new datatype package.
berghofe
parents: 5162
diff changeset
   119
primrec
6141
a6922171b396 removal of the (thm list) argument of mk_cases
paulson
parents: 5518
diff changeset
   120
  foldl_Nil  "foldl f a [] = a"
a6922171b396 removal of the (thm list) argument of mk_cases
paulson
parents: 5518
diff changeset
   121
  foldl_Cons "foldl f a (x#xs) = foldl f (f a x) xs"
5183
89f162de39cf Adapted to new datatype package.
berghofe
parents: 5162
diff changeset
   122
primrec
8972
b734bdb6042d better indentation; declared function "null"
paulson
parents: 8873
diff changeset
   123
  "foldr f [] a     = a"
8000
acafa0f15131 added foldr
paulson
parents: 7224
diff changeset
   124
  "foldr f (x#xs) a = f x (foldr f xs a)"
acafa0f15131 added foldr
paulson
parents: 7224
diff changeset
   125
primrec
8972
b734bdb6042d better indentation; declared function "null"
paulson
parents: 8873
diff changeset
   126
  "concat([])   = []"
2608
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents: 2512
diff changeset
   127
  "concat(x#xs) = x @ concat(xs)"
5183
89f162de39cf Adapted to new datatype package.
berghofe
parents: 5162
diff changeset
   128
primrec
1419
a6a034a47a71 defined take/drop by induction over list rather than nat.
nipkow
parents: 1370
diff changeset
   129
  drop_Nil  "drop n [] = []"
a6a034a47a71 defined take/drop by induction over list rather than nat.
nipkow
parents: 1370
diff changeset
   130
  drop_Cons "drop n (x#xs) = (case n of 0 => x#xs | Suc(m) => drop m xs)"
6408
5b443d6331ed new definition for nth.
pusch
parents: 6306
diff changeset
   131
  (* Warning: simpset does not contain this definition but separate theorems 
5b443d6331ed new definition for nth.
pusch
parents: 6306
diff changeset
   132
     for n=0 / n=Suc k*)
5183
89f162de39cf Adapted to new datatype package.
berghofe
parents: 5162
diff changeset
   133
primrec
1419
a6a034a47a71 defined take/drop by induction over list rather than nat.
nipkow
parents: 1370
diff changeset
   134
  take_Nil  "take n [] = []"
a6a034a47a71 defined take/drop by induction over list rather than nat.
nipkow
parents: 1370
diff changeset
   135
  take_Cons "take n (x#xs) = (case n of 0 => [] | Suc(m) => x # take m xs)"
6408
5b443d6331ed new definition for nth.
pusch
parents: 6306
diff changeset
   136
  (* Warning: simpset does not contain this definition but separate theorems 
5b443d6331ed new definition for nth.
pusch
parents: 6306
diff changeset
   137
     for n=0 / n=Suc k*)
5b443d6331ed new definition for nth.
pusch
parents: 6306
diff changeset
   138
primrec 
5b443d6331ed new definition for nth.
pusch
parents: 6306
diff changeset
   139
  nth_Cons  "(x#xs)!n = (case n of 0 => x | (Suc k) => xs!k)"
5b443d6331ed new definition for nth.
pusch
parents: 6306
diff changeset
   140
  (* Warning: simpset does not contain this definition but separate theorems 
5b443d6331ed new definition for nth.
pusch
parents: 6306
diff changeset
   141
     for n=0 / n=Suc k*)
5183
89f162de39cf Adapted to new datatype package.
berghofe
parents: 5162
diff changeset
   142
primrec
5077
71043526295f * HOL/List: new function list_update written xs[i:=v] that updates the i-th
nipkow
parents: 4643
diff changeset
   143
 "    [][i:=v] = []"
71043526295f * HOL/List: new function list_update written xs[i:=v] that updates the i-th
nipkow
parents: 4643
diff changeset
   144
 "(x#xs)[i:=v] = (case i of 0     => v # xs 
71043526295f * HOL/List: new function list_update written xs[i:=v] that updates the i-th
nipkow
parents: 4643
diff changeset
   145
			  | Suc j => x # xs[j:=v])"
5183
89f162de39cf Adapted to new datatype package.
berghofe
parents: 5162
diff changeset
   146
primrec
8972
b734bdb6042d better indentation; declared function "null"
paulson
parents: 8873
diff changeset
   147
  "takeWhile P []     = []"
2608
450c9b682a92 New class "order" and accompanying changes.
nipkow
parents: 2512
diff changeset
   148
  "takeWhile P (x#xs) = (if P x then x#takeWhile P xs else [])"
5183
89f162de39cf Adapted to new datatype package.
berghofe
parents: 5162
diff changeset
   149
primrec
8972
b734bdb6042d better indentation; declared function "null"
paulson
parents: 8873
diff changeset
   150
  "dropWhile P []     = []"
3584
8f9ee0f79d9a Corected bug in def of dropWhile (also present in Haskell lib!)
nipkow
parents: 3507
diff changeset
   151
  "dropWhile P (x#xs) = (if P x then dropWhile P xs else x#xs)"
5183
89f162de39cf Adapted to new datatype package.
berghofe
parents: 5162
diff changeset
   152
primrec
4132
daff3c9987cc added zip and nodup
oheimb
parents: 3896
diff changeset
   153
  "zip xs []     = []"
6306
81e7fbf61db2 modified zip
nipkow
parents: 6141
diff changeset
   154
  "zip xs (y#ys) = (case xs of [] => [] | z#zs => (z,y)#zip zs ys)"
6408
5b443d6331ed new definition for nth.
pusch
parents: 6306
diff changeset
   155
  (* Warning: simpset does not contain this definition but separate theorems 
5b443d6331ed new definition for nth.
pusch
parents: 6306
diff changeset
   156
     for xs=[] / xs=z#zs *)
5427
26c9a7c0b36b Arith: less_diff_conv
nipkow
parents: 5425
diff changeset
   157
primrec
8983
15bd7d568fb2 named the primrec clauses of upt
paulson
parents: 8972
diff changeset
   158
  upt_0   "[i..0(] = []"
15bd7d568fb2 named the primrec clauses of upt
paulson
parents: 8972
diff changeset
   159
  upt_Suc "[i..(Suc j)(] = (if i <= j then [i..j(] @ [j] else [])"
5183
89f162de39cf Adapted to new datatype package.
berghofe
parents: 5162
diff changeset
   160
primrec
12887
d25b43743e10 nodups -> distinct
nipkow
parents: 12114
diff changeset
   161
  "distinct []     = True"
d25b43743e10 nodups -> distinct
nipkow
parents: 12114
diff changeset
   162
  "distinct (x#xs) = (x ~: set xs & distinct xs)"
5183
89f162de39cf Adapted to new datatype package.
berghofe
parents: 5162
diff changeset
   163
primrec
4605
579e0ef2df6b Added `remdups'
nipkow
parents: 4502
diff changeset
   164
  "remdups [] = []"
579e0ef2df6b Added `remdups'
nipkow
parents: 4502
diff changeset
   165
  "remdups (x#xs) = (if x : set xs then remdups xs else x # remdups xs)"
5183
89f162de39cf Adapted to new datatype package.
berghofe
parents: 5162
diff changeset
   166
primrec
5443
e2459d18ff47 changed constants mem and list_all to mere translations
oheimb
parents: 5427
diff changeset
   167
  replicate_0   "replicate  0      x = []"
5183
89f162de39cf Adapted to new datatype package.
berghofe
parents: 5162
diff changeset
   168
  replicate_Suc "replicate (Suc n) x = x # replicate n x"
8115
c802042066e8 Forgot to "call" MicroJava in makefile.
nipkow
parents: 8000
diff changeset
   169
defs
c802042066e8 Forgot to "call" MicroJava in makefile.
nipkow
parents: 8000
diff changeset
   170
 list_all2_def
c802042066e8 Forgot to "call" MicroJava in makefile.
nipkow
parents: 8000
diff changeset
   171
 "list_all2 P xs ys == length xs = length ys & (!(x,y):set(zip xs ys). P x y)"
c802042066e8 Forgot to "call" MicroJava in makefile.
nipkow
parents: 8000
diff changeset
   172
3196
c522bc46aea7 Added pred_list for TFL
paulson
parents: 2738
diff changeset
   173
6408
5b443d6331ed new definition for nth.
pusch
parents: 6306
diff changeset
   174
(** Lexicographic orderings on lists **)
5281
f4d16517b360 List now contains some lexicographic orderings.
nipkow
parents: 5183
diff changeset
   175
f4d16517b360 List now contains some lexicographic orderings.
nipkow
parents: 5183
diff changeset
   176
consts
f4d16517b360 List now contains some lexicographic orderings.
nipkow
parents: 5183
diff changeset
   177
 lexn :: "('a * 'a)set => nat => ('a list * 'a list)set"
f4d16517b360 List now contains some lexicographic orderings.
nipkow
parents: 5183
diff changeset
   178
primrec
f4d16517b360 List now contains some lexicographic orderings.
nipkow
parents: 5183
diff changeset
   179
"lexn r 0       = {}"
10832
e33b47e4246d `` -> and ``` -> ``
nipkow
parents: 9355
diff changeset
   180
"lexn r (Suc n) = (prod_fun (%(x,xs). x#xs) (%(x,xs). x#xs) ` (r <*lex*> lexn r n)) Int
5281
f4d16517b360 List now contains some lexicographic orderings.
nipkow
parents: 5183
diff changeset
   181
                  {(xs,ys). length xs = Suc n & length ys = Suc n}"
f4d16517b360 List now contains some lexicographic orderings.
nipkow
parents: 5183
diff changeset
   182
f4d16517b360 List now contains some lexicographic orderings.
nipkow
parents: 5183
diff changeset
   183
constdefs
9336
9ae89b9ce206 moved sublist from UNITY/AllocBase to List
paulson
parents: 8983
diff changeset
   184
  lex :: "('a * 'a)set => ('a list * 'a list)set"
9ae89b9ce206 moved sublist from UNITY/AllocBase to List
paulson
parents: 8983
diff changeset
   185
    "lex r == UN n. lexn r n"
5281
f4d16517b360 List now contains some lexicographic orderings.
nipkow
parents: 5183
diff changeset
   186
9336
9ae89b9ce206 moved sublist from UNITY/AllocBase to List
paulson
parents: 8983
diff changeset
   187
  lexico :: "('a * 'a)set => ('a list * 'a list)set"
9ae89b9ce206 moved sublist from UNITY/AllocBase to List
paulson
parents: 8983
diff changeset
   188
    "lexico r == inv_image (less_than <*lex*> lex r) (%xs. (length xs, xs))"
9ae89b9ce206 moved sublist from UNITY/AllocBase to List
paulson
parents: 8983
diff changeset
   189
9ae89b9ce206 moved sublist from UNITY/AllocBase to List
paulson
parents: 8983
diff changeset
   190
  sublist :: "['a list, nat set] => 'a list"
9ae89b9ce206 moved sublist from UNITY/AllocBase to List
paulson
parents: 8983
diff changeset
   191
    "sublist xs A == map fst (filter (%p. snd p : A) (zip xs [0..size xs(]))"
5281
f4d16517b360 List now contains some lexicographic orderings.
nipkow
parents: 5183
diff changeset
   192
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   193
end
3507
157be29ad5ba Improved length = size translation.
nipkow
parents: 3465
diff changeset
   194
157be29ad5ba Improved length = size translation.
nipkow
parents: 3465
diff changeset
   195
ML
157be29ad5ba Improved length = size translation.
nipkow
parents: 3465
diff changeset
   196
157be29ad5ba Improved length = size translation.
nipkow
parents: 3465
diff changeset
   197
local
157be29ad5ba Improved length = size translation.
nipkow
parents: 3465
diff changeset
   198
157be29ad5ba Improved length = size translation.
nipkow
parents: 3465
diff changeset
   199
(* translating size::list -> length *)
157be29ad5ba Improved length = size translation.
nipkow
parents: 3465
diff changeset
   200
4151
5c19cd418c33 adapted typed_print_translation;
wenzelm
parents: 4132
diff changeset
   201
fun size_tr' _ (Type ("fun", (Type ("list", _) :: _))) [t] =
3507
157be29ad5ba Improved length = size translation.
nipkow
parents: 3465
diff changeset
   202
      Syntax.const "length" $ t
4151
5c19cd418c33 adapted typed_print_translation;
wenzelm
parents: 4132
diff changeset
   203
  | size_tr' _ _ _ = raise Match;
3507
157be29ad5ba Improved length = size translation.
nipkow
parents: 3465
diff changeset
   204
157be29ad5ba Improved length = size translation.
nipkow
parents: 3465
diff changeset
   205
in
157be29ad5ba Improved length = size translation.
nipkow
parents: 3465
diff changeset
   206
157be29ad5ba Improved length = size translation.
nipkow
parents: 3465
diff changeset
   207
val typed_print_translation = [("size", size_tr')];
157be29ad5ba Improved length = size translation.
nipkow
parents: 3465
diff changeset
   208
157be29ad5ba Improved length = size translation.
nipkow
parents: 3465
diff changeset
   209
end;