src/HOL/List.thy
changeset 63099 af0e964aad7b
parent 63092 a949b2a5f51d
child 63145 703edebd1d92
equal deleted inserted replaced
63097:ee8edbcbb4ad 63099:af0e964aad7b
  3296 
  3296 
  3297 lemma nth_eq_iff_index_eq:
  3297 lemma nth_eq_iff_index_eq:
  3298   "\<lbrakk> distinct xs; i < length xs; j < length xs \<rbrakk> \<Longrightarrow> (xs!i = xs!j) = (i = j)"
  3298   "\<lbrakk> distinct xs; i < length xs; j < length xs \<rbrakk> \<Longrightarrow> (xs!i = xs!j) = (i = j)"
  3299 by(auto simp: distinct_conv_nth)
  3299 by(auto simp: distinct_conv_nth)
  3300 
  3300 
       
  3301 lemma distinct_Ex1: 
       
  3302   "distinct xs \<Longrightarrow> x \<in> set xs \<Longrightarrow> (\<exists>!i. i < length xs \<and> xs ! i = x)"
       
  3303   by (auto simp: in_set_conv_nth nth_eq_iff_index_eq)
       
  3304 
  3301 lemma inj_on_nth: "distinct xs \<Longrightarrow> \<forall>i \<in> I. i < length xs \<Longrightarrow> inj_on (nth xs) I"
  3305 lemma inj_on_nth: "distinct xs \<Longrightarrow> \<forall>i \<in> I. i < length xs \<Longrightarrow> inj_on (nth xs) I"
  3302 by (rule inj_onI) (simp add: nth_eq_iff_index_eq)
  3306 by (rule inj_onI) (simp add: nth_eq_iff_index_eq)
       
  3307 
       
  3308 lemma bij_betw_nth:
       
  3309   assumes "distinct xs" "A = {..<length xs}" "B = set xs" 
       
  3310   shows   "bij_betw (op ! xs) A B"
       
  3311   using assms unfolding bij_betw_def
       
  3312   by (auto intro!: inj_on_nth simp: set_conv_nth)
  3303 
  3313 
  3304 lemma set_update_distinct: "\<lbrakk> distinct xs;  n < length xs \<rbrakk> \<Longrightarrow>
  3314 lemma set_update_distinct: "\<lbrakk> distinct xs;  n < length xs \<rbrakk> \<Longrightarrow>
  3305   set(xs[n := x]) = insert x (set xs - {xs!n})"
  3315   set(xs[n := x]) = insert x (set xs - {xs!n})"
  3306 by(auto simp: set_eq_iff in_set_conv_nth nth_list_update nth_eq_iff_index_eq)
  3316 by(auto simp: set_eq_iff in_set_conv_nth nth_list_update nth_eq_iff_index_eq)
  3307 
  3317 
  6173 lemma bind_simps [simp]:
  6183 lemma bind_simps [simp]:
  6174   "List.bind [] f = []"
  6184   "List.bind [] f = []"
  6175   "List.bind (x # xs) f = f x @ List.bind xs f"
  6185   "List.bind (x # xs) f = f x @ List.bind xs f"
  6176   by (simp_all add: bind_def)
  6186   by (simp_all add: bind_def)
  6177 
  6187 
       
  6188 lemma list_bind_cong [fundef_cong]:
       
  6189   assumes "xs = ys" "(\<And>x. x \<in> set xs \<Longrightarrow> f x = g x)"
       
  6190   shows   "List.bind xs f = List.bind ys g"
       
  6191 proof -
       
  6192   from assms(2) have "List.bind xs f = List.bind xs g"
       
  6193     by (induction xs) simp_all
       
  6194   with assms(1) show ?thesis by simp
       
  6195 qed
       
  6196 
       
  6197 lemma set_list_bind: "set (List.bind xs f) = (\<Union>x\<in>set xs. set (f x))"
       
  6198   by (induction xs) simp_all  
       
  6199 
  6178 
  6200 
  6179 subsection \<open>Transfer\<close>
  6201 subsection \<open>Transfer\<close>
  6180 
  6202 
  6181 definition embed_list :: "nat list \<Rightarrow> int list" where
  6203 definition embed_list :: "nat list \<Rightarrow> int list" where
  6182 "embed_list l = map int l"
  6204 "embed_list l = map int l"