src/HOL/List.thy
changeset 46424 b447318e5e1a
parent 46418 22bb415d7754
child 46439 2388be11cb50
equal deleted inserted replaced
46423:51259911b9fa 46424:b447318e5e1a
  5686 
  5686 
  5687 lemma setsum_code [code]:
  5687 lemma setsum_code [code]:
  5688   "setsum f (set xs) = listsum (map f (remdups xs))"
  5688   "setsum f (set xs) = listsum (map f (remdups xs))"
  5689 by (simp add: listsum_distinct_conv_setsum_set)
  5689 by (simp add: listsum_distinct_conv_setsum_set)
  5690 
  5690 
       
  5691 definition map_project :: "('a \<Rightarrow> 'b option) \<Rightarrow> 'a set \<Rightarrow> 'b set" where
       
  5692   "map_project f A = {b. \<exists> a \<in> A. f a = Some b}"
       
  5693 
       
  5694 lemma [code]:
       
  5695   "map_project f (set xs) = set (List.map_filter f xs)"
       
  5696 unfolding map_project_def map_filter_def
       
  5697 by auto (metis (lifting, mono_tags) CollectI image_eqI o_apply the.simps)
       
  5698 
       
  5699 hide_const (open) map_project
       
  5700 
  5691 text {* Operations on relations *}
  5701 text {* Operations on relations *}
  5692 
  5702 
  5693 lemma product_code [code]:
  5703 lemma product_code [code]:
  5694   "Product_Type.product (set xs) (set ys) = set [(x, y). x \<leftarrow> xs, y \<leftarrow> ys]"
  5704   "Product_Type.product (set xs) (set ys) = set [(x, y). x \<leftarrow> xs, y \<leftarrow> ys]"
  5695   by (auto simp add: Product_Type.product_def)
  5705   by (auto simp add: Product_Type.product_def)
  5696 
  5706 
  5697 lemma Id_on_set [code]:
  5707 lemma Id_on_set [code]:
  5698   "Id_on (set xs) = set [(x, x). x \<leftarrow> xs]"
  5708   "Id_on (set xs) = set [(x, x). x \<leftarrow> xs]"
  5699   by (auto simp add: Id_on_def)
  5709   by (auto simp add: Id_on_def)
  5700 
  5710 
       
  5711 lemma [code]:
       
  5712   "R `` S = List.map_project (%(x, y). if x : S then Some y else None) R"
       
  5713 unfolding map_project_def by (auto split: prod.split split_if_asm)
       
  5714 
  5701 lemma trancl_set_ntrancl [code]:
  5715 lemma trancl_set_ntrancl [code]:
  5702   "trancl (set xs) = ntrancl (card (set xs) - 1) (set xs)"
  5716   "trancl (set xs) = ntrancl (card (set xs) - 1) (set xs)"
  5703   by (simp add: finite_trancl_ntranl)
  5717   by (simp add: finite_trancl_ntranl)
  5704 
  5718 
  5705 lemma set_rel_comp [code]:
  5719 lemma set_rel_comp [code]: