src/HOL/Set.thy
changeset 23878 bd651ecd4b8a
parent 23857 ad26287a9ccb
child 24280 c9867bdf2424
equal deleted inserted replaced
23877:307f75aaefca 23878:bd651ecd4b8a
     4 *)
     4 *)
     5 
     5 
     6 header {* Set theory for higher-order logic *}
     6 header {* Set theory for higher-order logic *}
     7 
     7 
     8 theory Set
     8 theory Set
     9 imports Lattices
     9 imports HOL
    10 begin
    10 begin
    11 
    11 
    12 text {* A set in HOL is simply a predicate. *}
    12 text {* A set in HOL is simply a predicate. *}
    13 
    13 
    14 
    14 
  1038 
  1038 
  1039 lemmas [symmetric, rulify] = atomize_ball
  1039 lemmas [symmetric, rulify] = atomize_ball
  1040   and [symmetric, defn] = atomize_ball
  1040   and [symmetric, defn] = atomize_ball
  1041 
  1041 
  1042 
  1042 
  1043 subsection {* Order on sets *}
       
  1044 
       
  1045 instance set :: (type) order
       
  1046   by (intro_classes,
       
  1047       (assumption | rule subset_refl subset_trans subset_antisym psubset_eq)+)
       
  1048 
       
  1049 
       
  1050 subsection {* Further set-theory lemmas *}
  1043 subsection {* Further set-theory lemmas *}
  1051 
  1044 
  1052 subsubsection {* Derived rules involving subsets. *}
  1045 subsubsection {* Derived rules involving subsets. *}
  1053 
  1046 
  1054 text {* @{text insert}. *}
  1047 text {* @{text insert}. *}
  1055 
  1048 
  1056 lemma subset_insertI: "B \<subseteq> insert a B"
  1049 lemma subset_insertI: "B \<subseteq> insert a B"
  1057   apply (rule subsetI)
  1050   by (rule subsetI) (erule insertI2)
  1058   apply (erule insertI2)
       
  1059   done
       
  1060 
  1051 
  1061 lemma subset_insertI2: "A \<subseteq> B \<Longrightarrow> A \<subseteq> insert b B"
  1052 lemma subset_insertI2: "A \<subseteq> B \<Longrightarrow> A \<subseteq> insert b B"
  1062 by blast
  1053   by blast
  1063 
  1054 
  1064 lemma subset_insert: "x \<notin> A ==> (A \<subseteq> insert x B) = (A \<subseteq> B)"
  1055 lemma subset_insert: "x \<notin> A ==> (A \<subseteq> insert x B) = (A \<subseteq> B)"
  1065   by blast
  1056   by blast
  1066 
  1057 
  1067 
  1058 
  1132   by blast
  1123   by blast
  1133 
  1124 
  1134 lemma Diff_subset_conv: "(A - B \<subseteq> C) = (A \<subseteq> B \<union> C)"
  1125 lemma Diff_subset_conv: "(A - B \<subseteq> C) = (A \<subseteq> B \<union> C)"
  1135 by blast
  1126 by blast
  1136 
  1127 
  1137 
       
  1138 text {* \medskip Monotonicity. *}
       
  1139 
       
  1140 lemma mono_Un: "mono f ==> f A \<union> f B \<subseteq> f (A \<union> B)"
       
  1141   by (auto simp add: mono_def)
       
  1142 
       
  1143 lemma mono_Int: "mono f ==> f (A \<inter> B) \<subseteq> f A \<inter> f B"
       
  1144   by (auto simp add: mono_def)
       
  1145 
  1128 
  1146 subsubsection {* Equalities involving union, intersection, inclusion, etc. *}
  1129 subsubsection {* Equalities involving union, intersection, inclusion, etc. *}
  1147 
  1130 
  1148 text {* @{text "{}"}. *}
  1131 text {* @{text "{}"}. *}
  1149 
  1132 
  2012   by iprover
  1995   by iprover
  2013 
  1996 
  2014 lemma eq_to_mono2: "a = b ==> c = d ==> ~ b --> ~ d ==> ~ a --> ~ c"
  1997 lemma eq_to_mono2: "a = b ==> c = d ==> ~ b --> ~ d ==> ~ a --> ~ c"
  2015   by iprover
  1998   by iprover
  2016 
  1999 
  2017 lemma Least_mono:
       
  2018   "mono (f::'a::order => 'b::order) ==> EX x:S. ALL y:S. x <= y
       
  2019     ==> (LEAST y. y : f ` S) = f (LEAST x. x : S)"
       
  2020     -- {* Courtesy of Stephan Merz *}
       
  2021   apply clarify
       
  2022   apply (erule_tac P = "%x. x : S" in LeastI2_order, fast)
       
  2023   apply (rule LeastI2_order)
       
  2024   apply (auto elim: monoD intro!: order_antisym)
       
  2025   done
       
  2026 
       
  2027 
  2000 
  2028 subsection {* Inverse image of a function *}
  2001 subsection {* Inverse image of a function *}
  2029 
  2002 
  2030 constdefs
  2003 constdefs
  2031   vimage :: "('a => 'b) => 'b set => 'a set"    (infixr "-`" 90)
  2004   vimage :: "('a => 'b) => 'b set => 'a set"    (infixr "-`" 90)
  2117 lemma set_rev_mp: "x:A ==> A \<subseteq> B ==> x:B"
  2090 lemma set_rev_mp: "x:A ==> A \<subseteq> B ==> x:B"
  2118   by (rule subsetD)
  2091   by (rule subsetD)
  2119 
  2092 
  2120 lemma set_mp: "A \<subseteq> B ==> x:A ==> x:B"
  2093 lemma set_mp: "A \<subseteq> B ==> x:A ==> x:B"
  2121   by (rule subsetD)
  2094   by (rule subsetD)
  2122 
       
  2123 lemmas basic_trans_rules [trans] =
       
  2124   order_trans_rules set_rev_mp set_mp
       
  2125 
       
  2126 
       
  2127 subsection {* Sets as lattice *}
       
  2128 
       
  2129 instance set :: (type) distrib_lattice
       
  2130   inf_set_eq: "inf A B \<equiv> A \<inter> B"
       
  2131   sup_set_eq: "sup A B \<equiv> A \<union> B"
       
  2132   by intro_classes (auto simp add: inf_set_eq sup_set_eq)
       
  2133 
       
  2134 lemmas [code func del] = inf_set_eq sup_set_eq
       
  2135 
  2095 
  2136 
  2096 
  2137 subsection {* Basic ML bindings *}
  2097 subsection {* Basic ML bindings *}
  2138 
  2098 
  2139 ML {*
  2099 ML {*