src/HOL/List.thy
changeset 19390 6c7383f80ad1
parent 19363 667b5ea637dd
child 19487 d5e79a41bce0
equal deleted inserted replaced
19389:0d57259fea82 19390:6c7383f80ad1
    42   null:: "'a list => bool"
    42   null:: "'a list => bool"
    43   "distinct":: "'a list => bool"
    43   "distinct":: "'a list => bool"
    44   replicate :: "nat => 'a => 'a list"
    44   replicate :: "nat => 'a => 'a list"
    45   rotate1 :: "'a list \<Rightarrow> 'a list"
    45   rotate1 :: "'a list \<Rightarrow> 'a list"
    46   rotate :: "nat \<Rightarrow> 'a list \<Rightarrow> 'a list"
    46   rotate :: "nat \<Rightarrow> 'a list \<Rightarrow> 'a list"
       
    47   splice :: "'a list \<Rightarrow> 'a list \<Rightarrow> 'a list"
    47   sublist :: "'a list => nat set => 'a list"
    48   sublist :: "'a list => nat set => 'a list"
    48 (* For efficiency *)
    49 (* For efficiency *)
    49   mem :: "'a => 'a list => bool"    (infixl 55)
    50   mem :: "'a => 'a list => bool"    (infixl 55)
    50   list_inter :: "'a list \<Rightarrow> 'a list \<Rightarrow> 'a list"
    51   list_inter :: "'a list \<Rightarrow> 'a list \<Rightarrow> 'a list"
    51   list_ex :: "('a \<Rightarrow> bool) \<Rightarrow> 'a list \<Rightarrow> bool"
    52   list_ex :: "('a \<Rightarrow> bool) \<Rightarrow> 'a list \<Rightarrow> bool"
   210  "list_all2 P xs ys ==
   211  "list_all2 P xs ys ==
   211   length xs = length ys \<and> (\<forall>(x, y) \<in> set (zip xs ys). P x y)"
   212   length xs = length ys \<and> (\<forall>(x, y) \<in> set (zip xs ys). P x y)"
   212 
   213 
   213 sublist_def:
   214 sublist_def:
   214  "sublist xs A == map fst (filter (%p. snd p : A) (zip xs [0..<size xs]))"
   215  "sublist xs A == map fst (filter (%p. snd p : A) (zip xs [0..<size xs]))"
       
   216 
       
   217 primrec
       
   218 "splice [] ys = ys"
       
   219 "splice (x#xs) ys = (if ys=[] then x#xs else x # hd ys # splice xs (tl ys))"
       
   220   -- {*Warning: simpset does not contain the second eqn but a derived one. *}
   215 
   221 
   216 primrec
   222 primrec
   217   "x mem [] = False"
   223   "x mem [] = False"
   218   "x mem (y#ys) = (if y=x then True else x mem ys)"
   224   "x mem (y#ys) = (if y=x then True else x mem ys)"
   219 
   225 
  2148   moreover hence "!x. x: set xs \<longrightarrow> x \<noteq> a" by auto
  2154   moreover hence "!x. x: set xs \<longrightarrow> x \<noteq> a" by auto
  2149   ultimately show ?case by(simp add: sublist_Cons cong:filter_cong)
  2155   ultimately show ?case by(simp add: sublist_Cons cong:filter_cong)
  2150 qed
  2156 qed
  2151 
  2157 
  2152 
  2158 
       
  2159 subsubsection {* @{const splice} *}
       
  2160 
       
  2161 lemma splice_Nil2[simp]:
       
  2162  "splice xs [] = xs"
       
  2163 by (cases xs) simp_all
       
  2164 
       
  2165 lemma splice_Cons_Cons[simp]:
       
  2166  "splice (x#xs) (y#ys) = x # y # splice xs ys"
       
  2167 by simp
       
  2168 
       
  2169 declare splice.simps(2)[simp del]
       
  2170 
  2153 subsubsection{*Sets of Lists*}
  2171 subsubsection{*Sets of Lists*}
  2154 
  2172 
  2155 subsubsection {* @{text lists}: the list-forming operator over sets *}
  2173 subsubsection {* @{text lists}: the list-forming operator over sets *}
  2156 
  2174 
  2157 consts lists :: "'a set => 'a list set"
  2175 consts lists :: "'a set => 'a list set"