src/HOL/Library/More_Set.thy
author kuncar
Fri Dec 09 18:07:04 2011 +0100 (2011-12-09)
changeset 45802 b16f976db515
parent 45012 060f76635bfe
child 45974 2b043ed911ac
permissions -rw-r--r--
Quotient_Info stores only relation maps
     1 
     2 (* Author: Florian Haftmann, TU Muenchen *)
     3 
     4 header {* Relating (finite) sets and lists *}
     5 
     6 theory More_Set
     7 imports Main More_List
     8 begin
     9 
    10 subsection {* Various additional set functions *}
    11 
    12 definition is_empty :: "'a set \<Rightarrow> bool" where
    13   "is_empty A \<longleftrightarrow> A = {}"
    14 
    15 definition remove :: "'a \<Rightarrow> 'a set \<Rightarrow> 'a set" where
    16   "remove x A = A - {x}"
    17 
    18 lemma comp_fun_idem_remove:
    19   "comp_fun_idem remove"
    20 proof -
    21   have rem: "remove = (\<lambda>x A. A - {x})" by (simp add: fun_eq_iff remove_def)
    22   show ?thesis by (simp only: comp_fun_idem_remove rem)
    23 qed
    24 
    25 lemma minus_fold_remove:
    26   assumes "finite A"
    27   shows "B - A = Finite_Set.fold remove B A"
    28 proof -
    29   have rem: "remove = (\<lambda>x A. A - {x})" by (simp add: fun_eq_iff remove_def)
    30   show ?thesis by (simp only: rem assms minus_fold_remove)
    31 qed
    32 
    33 definition project :: "('a \<Rightarrow> bool) \<Rightarrow> 'a set \<Rightarrow> 'a set" where
    34   "project P A = {a \<in> A. P a}"
    35 
    36 lemma bounded_Collect_code [code_unfold_post]:
    37   "{x \<in> A. P x} = project P A"
    38   by (simp add: project_def)
    39 
    40 definition product :: "'a set \<Rightarrow> 'b set \<Rightarrow> ('a \<times> 'b) set" where
    41   "product A B = Sigma A (\<lambda>_. B)"
    42 
    43 hide_const (open) product
    44 
    45 lemma [code_unfold_post]:
    46   "Sigma A (\<lambda>_. B) = More_Set.product A B"
    47   by (simp add: product_def)
    48 
    49 
    50 subsection {* Basic set operations *}
    51 
    52 lemma is_empty_set:
    53   "is_empty (set xs) \<longleftrightarrow> List.null xs"
    54   by (simp add: is_empty_def null_def)
    55 
    56 lemma empty_set:
    57   "{} = set []"
    58   by simp
    59 
    60 lemma insert_set_compl:
    61   "insert x (- set xs) = - set (removeAll x xs)"
    62   by auto
    63 
    64 lemma remove_set_compl:
    65   "remove x (- set xs) = - set (List.insert x xs)"
    66   by (auto simp add: remove_def List.insert_def)
    67 
    68 lemma image_set:
    69   "image f (set xs) = set (map f xs)"
    70   by simp
    71 
    72 lemma project_set:
    73   "project P (set xs) = set (filter P xs)"
    74   by (auto simp add: project_def)
    75 
    76 
    77 subsection {* Functorial set operations *}
    78 
    79 lemma union_set:
    80   "set xs \<union> A = fold Set.insert xs A"
    81 proof -
    82   interpret comp_fun_idem Set.insert
    83     by (fact comp_fun_idem_insert)
    84   show ?thesis by (simp add: union_fold_insert fold_set)
    85 qed
    86 
    87 lemma union_set_foldr:
    88   "set xs \<union> A = foldr Set.insert xs A"
    89 proof -
    90   have "\<And>x y :: 'a. insert y \<circ> insert x = insert x \<circ> insert y"
    91     by auto
    92   then show ?thesis by (simp add: union_set foldr_fold)
    93 qed
    94 
    95 lemma minus_set:
    96   "A - set xs = fold remove xs A"
    97 proof -
    98   interpret comp_fun_idem remove
    99     by (fact comp_fun_idem_remove)
   100   show ?thesis
   101     by (simp add: minus_fold_remove [of _ A] fold_set)
   102 qed
   103 
   104 lemma minus_set_foldr:
   105   "A - set xs = foldr remove xs A"
   106 proof -
   107   have "\<And>x y :: 'a. remove y \<circ> remove x = remove x \<circ> remove y"
   108     by (auto simp add: remove_def)
   109   then show ?thesis by (simp add: minus_set foldr_fold)
   110 qed
   111 
   112 
   113 subsection {* Derived set operations *}
   114 
   115 lemma member:
   116   "a \<in> A \<longleftrightarrow> (\<exists>x\<in>A. a = x)"
   117   by simp
   118 
   119 lemma subset_eq:
   120   "A \<subseteq> B \<longleftrightarrow> (\<forall>x\<in>A. x \<in> B)"
   121   by (fact subset_eq)
   122 
   123 lemma subset:
   124   "A \<subset> B \<longleftrightarrow> A \<subseteq> B \<and> \<not> B \<subseteq> A"
   125   by (fact less_le_not_le)
   126 
   127 lemma set_eq:
   128   "A = B \<longleftrightarrow> A \<subseteq> B \<and> B \<subseteq> A"
   129   by (fact eq_iff)
   130 
   131 lemma inter:
   132   "A \<inter> B = project (\<lambda>x. x \<in> A) B"
   133   by (auto simp add: project_def)
   134 
   135 
   136 subsection {* Theorems on relations *}
   137 
   138 lemma product_code:
   139   "More_Set.product (set xs) (set ys) = set [(x, y). x \<leftarrow> xs, y \<leftarrow> ys]"
   140   by (auto simp add: product_def)
   141 
   142 lemma Id_on_set:
   143   "Id_on (set xs) = set [(x, x). x \<leftarrow> xs]"
   144   by (auto simp add: Id_on_def)
   145 
   146 lemma set_rel_comp:
   147   "set xys O set yzs = set ([(fst xy, snd yz). xy \<leftarrow> xys, yz \<leftarrow> yzs, snd xy = fst yz])"
   148   by (auto simp add: Bex_def)
   149 
   150 lemma wf_set:
   151   "wf (set xs) = acyclic (set xs)"
   152   by (simp add: wf_iff_acyclic_if_finite)
   153 
   154 end