src/HOL/List.thy
changeset 21404 eb85850d3eb7
parent 21211 5370cfbf3070
child 21455 b6be1d1b66c5
equal deleted inserted replaced
21403:dd58f13a8eb4 21404:eb85850d3eb7
    41   "distinct":: "'a list => bool"
    41   "distinct":: "'a list => bool"
    42   replicate :: "nat => 'a => 'a list"
    42   replicate :: "nat => 'a => 'a list"
    43   splice :: "'a list \<Rightarrow> 'a list \<Rightarrow> 'a list"
    43   splice :: "'a list \<Rightarrow> 'a list \<Rightarrow> 'a list"
    44 
    44 
    45 abbreviation
    45 abbreviation
    46   upto:: "nat => nat => nat list"    ("(1[_../_])")
    46   upto:: "nat => nat => nat list"  ("(1[_../_])") where
    47   "[i..j] == [i..<(Suc j)]"
    47   "[i..j] == [i..<(Suc j)]"
    48 
    48 
    49 
    49 
    50 nonterminals lupdbinds lupdbind
    50 nonterminals lupdbinds lupdbind
    51 
    51 
    80 text {*
    80 text {*
    81   Function @{text size} is overloaded for all datatypes. Users may
    81   Function @{text size} is overloaded for all datatypes. Users may
    82   refer to the list version as @{text length}. *}
    82   refer to the list version as @{text length}. *}
    83 
    83 
    84 abbreviation
    84 abbreviation
    85   length :: "'a list => nat"
    85   length :: "'a list => nat" where
    86   "length == size"
    86   "length == size"
    87 
    87 
    88 primrec
    88 primrec
    89   "hd(x#xs) = x"
    89   "hd(x#xs) = x"
    90 
    90 
   185 primrec
   185 primrec
   186   replicate_0: "replicate 0 x = []"
   186   replicate_0: "replicate 0 x = []"
   187   replicate_Suc: "replicate (Suc n) x = x # replicate n x"
   187   replicate_Suc: "replicate (Suc n) x = x # replicate n x"
   188 
   188 
   189 definition
   189 definition
   190   rotate1 :: "'a list \<Rightarrow> 'a list"
   190   rotate1 :: "'a list \<Rightarrow> 'a list" where
   191   rotate1_def: "rotate1 xs = (case xs of [] \<Rightarrow> [] | x#xs \<Rightarrow> xs @ [x])"
   191   "rotate1 xs = (case xs of [] \<Rightarrow> [] | x#xs \<Rightarrow> xs @ [x])"
   192   rotate :: "nat \<Rightarrow> 'a list \<Rightarrow> 'a list"
   192 
   193   rotate_def:  "rotate n = rotate1 ^ n"
   193 definition
   194   list_all2 :: "('a => 'b => bool) => 'a list => 'b list => bool"
   194   rotate :: "nat \<Rightarrow> 'a list \<Rightarrow> 'a list" where
   195   list_all2_def: "list_all2 P xs ys =
   195   "rotate n = rotate1 ^ n"
       
   196 
       
   197 definition
       
   198   list_all2 :: "('a => 'b => bool) => 'a list => 'b list => bool" where
       
   199   "list_all2 P xs ys =
   196     (length xs = length ys \<and> (\<forall>(x, y) \<in> set (zip xs ys). P x y))"
   200     (length xs = length ys \<and> (\<forall>(x, y) \<in> set (zip xs ys). P x y))"
   197   sublist :: "'a list => nat set => 'a list"
   201 
   198   sublist_def: "sublist xs A =
   202 definition
   199     map fst (filter (\<lambda>p. snd p \<in> A) (zip xs [0..<size xs]))"
   203   sublist :: "'a list => nat set => 'a list" where
       
   204   "sublist xs A = map fst (filter (\<lambda>p. snd p \<in> A) (zip xs [0..<size xs]))"
   200 
   205 
   201 primrec
   206 primrec
   202   "splice [] ys = ys"
   207   "splice [] ys = ys"
   203   "splice (x#xs) ys = (if ys=[] then x#xs else x # hd ys # splice xs (tl ys))"
   208   "splice (x#xs) ys = (if ys=[] then x#xs else x # hd ys # splice xs (tl ys))"
   204     -- {*Warning: simpset does not contain the second eqn but a derived one. *}
   209     -- {*Warning: simpset does not contain the second eqn but a derived one. *}