src/HOL/Finite_Set.thy
changeset 24748 ee0a0eb6b738
parent 24728 e2b3a1065676
child 24853 aab5798e5a33
equal deleted inserted replaced
24747:6ded9235c2b6 24748:ee0a0eb6b738
  2004 
  2004 
  2005 
  2005 
  2006 subsubsection{* Semi-Lattices *}
  2006 subsubsection{* Semi-Lattices *}
  2007 
  2007 
  2008 locale ACIfSL = ord + ACIf +
  2008 locale ACIfSL = ord + ACIf +
  2009   assumes below_def: "x \<sqsubseteq> y \<longleftrightarrow> x \<cdot> y = x"
  2009   assumes below_def: "less_eq x y \<longleftrightarrow> x \<cdot> y = x"
  2010   and strict_below_def: "x \<sqsubset> y \<longleftrightarrow> x \<sqsubseteq> y \<and> x \<noteq> y"
  2010   and strict_below_def: "less x y \<longleftrightarrow> less_eq x y \<and> x \<noteq> y"
  2011 begin
  2011 begin
  2012 
  2012 
  2013 lemma below_refl [simp]: "x \<^loc>\<le> x"
  2013 lemma below_refl [simp]: "x \<^loc>\<le> x"
  2014   by (simp add: below_def idem)
  2014   by (simp add: below_def idem)
  2015 
  2015 
  2031   moreover from x_xy have "x \<cdot> z = x \<cdot> y \<cdot> z" by simp
  2031   moreover from x_xy have "x \<cdot> z = x \<cdot> y \<cdot> z" by simp
  2032   ultimately have "x \<cdot> z = x" by simp
  2032   ultimately have "x \<cdot> z = x" by simp
  2033   then show ?thesis by (simp add: below_def)
  2033   then show ?thesis by (simp add: below_def)
  2034 qed
  2034 qed
  2035 
  2035 
  2036 lemma below_f_conv [simp,noatp]: "x \<sqsubseteq> y \<cdot> z = (x \<sqsubseteq> y \<and> x \<sqsubseteq> z)"
  2036 lemma below_f_conv [simp,noatp]: "x \<^loc>\<le> y \<cdot> z = (x \<^loc>\<le> y \<and> x \<^loc>\<le> z)"
  2037 proof
  2037 proof
  2038   assume "x \<sqsubseteq> y \<cdot> z"
  2038   assume "x \<^loc>\<le> y \<cdot> z"
  2039   hence xyzx: "x \<cdot> (y \<cdot> z) = x"  by(simp add: below_def)
  2039   hence xyzx: "x \<cdot> (y \<cdot> z) = x"  by(simp add: below_def)
  2040   have "x \<cdot> y = x"
  2040   have "x \<cdot> y = x"
  2041   proof -
  2041   proof -
  2042     have "x \<cdot> y = (x \<cdot> (y \<cdot> z)) \<cdot> y" by(rule subst[OF xyzx], rule refl)
  2042     have "x \<cdot> y = (x \<cdot> (y \<cdot> z)) \<cdot> y" by(rule subst[OF xyzx], rule refl)
  2043     also have "\<dots> = x \<cdot> (y \<cdot> z)" by(simp add:ACI)
  2043     also have "\<dots> = x \<cdot> (y \<cdot> z)" by(simp add:ACI)
  2049     have "x \<cdot> z = (x \<cdot> (y \<cdot> z)) \<cdot> z" by(rule subst[OF xyzx], rule refl)
  2049     have "x \<cdot> z = (x \<cdot> (y \<cdot> z)) \<cdot> z" by(rule subst[OF xyzx], rule refl)
  2050     also have "\<dots> = x \<cdot> (y \<cdot> z)" by(simp add:ACI)
  2050     also have "\<dots> = x \<cdot> (y \<cdot> z)" by(simp add:ACI)
  2051     also have "\<dots> = x" by(rule xyzx)
  2051     also have "\<dots> = x" by(rule xyzx)
  2052     finally show ?thesis .
  2052     finally show ?thesis .
  2053   qed
  2053   qed
  2054   ultimately show "x \<sqsubseteq> y \<and> x \<sqsubseteq> z" by(simp add: below_def)
  2054   ultimately show "x \<^loc>\<le> y \<and> x \<^loc>\<le> z" by(simp add: below_def)
  2055 next
  2055 next
  2056   assume a: "x \<sqsubseteq> y \<and> x \<sqsubseteq> z"
  2056   assume a: "x \<^loc>\<le> y \<and> x \<^loc>\<le> z"
  2057   hence y: "x \<cdot> y = x" and z: "x \<cdot> z = x" by(simp_all add: below_def)
  2057   hence y: "x \<cdot> y = x" and z: "x \<cdot> z = x" by(simp_all add: below_def)
  2058   have "x \<cdot> (y \<cdot> z) = (x \<cdot> y) \<cdot> z" by(simp add:assoc)
  2058   have "x \<cdot> (y \<cdot> z) = (x \<cdot> y) \<cdot> z" by(simp add:assoc)
  2059   also have "x \<cdot> y = x" using a by(simp_all add: below_def)
  2059   also have "x \<cdot> y = x" using a by(simp_all add: below_def)
  2060   also have "x \<cdot> z = x" using a by(simp_all add: below_def)
  2060   also have "x \<cdot> z = x" using a by(simp_all add: below_def)
  2061   finally show "x \<sqsubseteq> y \<cdot> z" by(simp_all add: below_def)
  2061   finally show "x \<^loc>\<le> y \<cdot> z" by(simp_all add: below_def)
  2062 qed
  2062 qed
  2063 
  2063 
  2064 end
  2064 end
  2065 
  2065 
  2066 interpretation ACIfSL < order
  2066 interpretation ACIfSL < order
  2070 locale ACIfSLlin = ACIfSL +
  2070 locale ACIfSLlin = ACIfSL +
  2071   assumes lin: "x\<cdot>y \<in> {x,y}"
  2071   assumes lin: "x\<cdot>y \<in> {x,y}"
  2072 begin
  2072 begin
  2073 
  2073 
  2074 lemma above_f_conv:
  2074 lemma above_f_conv:
  2075  "x \<cdot> y \<sqsubseteq> z = (x \<sqsubseteq> z \<or> y \<sqsubseteq> z)"
  2075  "x \<cdot> y \<^loc>\<le> z = (x \<^loc>\<le> z \<or> y \<^loc>\<le> z)"
  2076 proof
  2076 proof
  2077   assume a: "x \<cdot> y \<sqsubseteq> z"
  2077   assume a: "x \<cdot> y \<^loc>\<le> z"
  2078   have "x \<cdot> y = x \<or> x \<cdot> y = y" using lin[of x y] by simp
  2078   have "x \<cdot> y = x \<or> x \<cdot> y = y" using lin[of x y] by simp
  2079   thus "x \<sqsubseteq> z \<or> y \<sqsubseteq> z"
  2079   thus "x \<^loc>\<le> z \<or> y \<^loc>\<le> z"
  2080   proof
  2080   proof
  2081     assume "x \<cdot> y = x" hence "x \<sqsubseteq> z" by(rule subst)(rule a) thus ?thesis ..
  2081     assume "x \<cdot> y = x" hence "x \<^loc>\<le> z" by(rule subst)(rule a) thus ?thesis ..
  2082   next
  2082   next
  2083     assume "x \<cdot> y = y" hence "y \<sqsubseteq> z" by(rule subst)(rule a) thus ?thesis ..
  2083     assume "x \<cdot> y = y" hence "y \<^loc>\<le> z" by(rule subst)(rule a) thus ?thesis ..
  2084   qed
  2084   qed
  2085 next
  2085 next
  2086   assume "x \<sqsubseteq> z \<or> y \<sqsubseteq> z"
  2086   assume "x \<^loc>\<le> z \<or> y \<^loc>\<le> z"
  2087   thus "x \<cdot> y \<sqsubseteq> z"
  2087   thus "x \<cdot> y \<^loc>\<le> z"
  2088   proof
  2088   proof
  2089     assume a: "x \<sqsubseteq> z"
  2089     assume a: "x \<^loc>\<le> z"
  2090     have "(x \<cdot> y) \<cdot> z = (x \<cdot> z) \<cdot> y" by(simp add:ACI)
  2090     have "(x \<cdot> y) \<cdot> z = (x \<cdot> z) \<cdot> y" by(simp add:ACI)
  2091     also have "x \<cdot> z = x" using a by(simp add:below_def)
  2091     also have "x \<cdot> z = x" using a by(simp add:below_def)
  2092     finally show "x \<cdot> y \<sqsubseteq> z" by(simp add:below_def)
  2092     finally show "x \<cdot> y \<^loc>\<le> z" by(simp add:below_def)
  2093   next
  2093   next
  2094     assume a: "y \<sqsubseteq> z"
  2094     assume a: "y \<^loc>\<le> z"
  2095     have "(x \<cdot> y) \<cdot> z = x \<cdot> (y \<cdot> z)" by(simp add:ACI)
  2095     have "(x \<cdot> y) \<cdot> z = x \<cdot> (y \<cdot> z)" by(simp add:ACI)
  2096     also have "y \<cdot> z = y" using a by(simp add:below_def)
  2096     also have "y \<cdot> z = y" using a by(simp add:below_def)
  2097     finally show "x \<cdot> y \<sqsubseteq> z" by(simp add:below_def)
  2097     finally show "x \<cdot> y \<^loc>\<le> z" by(simp add:below_def)
  2098   qed
  2098   qed
  2099 qed
  2099 qed
  2100 
  2100 
  2101 lemma strict_below_f_conv[simp,noatp]: "x \<sqsubset> y \<cdot> z = (x \<sqsubset> y \<and> x \<sqsubset> z)"
  2101 lemma strict_below_f_conv[simp,noatp]: "x \<^loc>< y \<cdot> z = (x \<^loc>< y \<and> x \<^loc>< z)"
  2102 apply(simp add: strict_below_def)
  2102 apply(simp add: strict_below_def)
  2103 using lin[of y z] by (auto simp:below_def ACI)
  2103 using lin[of y z] by (auto simp:below_def ACI)
  2104 
  2104 
  2105 lemma strict_above_f_conv:
  2105 lemma strict_above_f_conv:
  2106   "x \<cdot> y \<sqsubset> z = (x \<sqsubset> z \<or> y \<sqsubset> z)"
  2106   "x \<cdot> y \<^loc>< z = (x \<^loc>< z \<or> y \<^loc>< z)"
  2107 apply(simp add: strict_below_def above_f_conv)
  2107 apply(simp add: strict_below_def above_f_conv)
  2108 using lin[of y z] lin[of x z] by (auto simp:below_def ACI)
  2108 using lin[of y z] lin[of x z] by (auto simp:below_def ACI)
  2109 
  2109 
  2110 end
  2110 end
  2111 
  2111 
  2148   case insert thus ?case using elem by (force simp add:fold1_insert)
  2148   case insert thus ?case using elem by (force simp add:fold1_insert)
  2149 qed
  2149 qed
  2150 
  2150 
  2151 lemma (in ACIfSL) below_fold1_iff:
  2151 lemma (in ACIfSL) below_fold1_iff:
  2152 assumes A: "finite A" "A \<noteq> {}"
  2152 assumes A: "finite A" "A \<noteq> {}"
  2153 shows "x \<sqsubseteq> fold1 f A = (\<forall>a\<in>A. x \<sqsubseteq> a)"
  2153 shows "x \<^loc>\<le> fold1 f A = (\<forall>a\<in>A. x \<^loc>\<le> a)"
  2154 using A
  2154 using A
  2155 by(induct rule:finite_ne_induct) simp_all
  2155 by(induct rule:finite_ne_induct) simp_all
  2156 
  2156 
  2157 lemma (in ACIfSLlin) strict_below_fold1_iff:
  2157 lemma (in ACIfSLlin) strict_below_fold1_iff:
  2158   "finite A \<Longrightarrow> A \<noteq> {} \<Longrightarrow> x \<sqsubset> fold1 f A = (\<forall>a\<in>A. x \<sqsubset> a)"
  2158   "finite A \<Longrightarrow> A \<noteq> {} \<Longrightarrow> x \<^loc>< fold1 f A = (\<forall>a\<in>A. x \<^loc>< a)"
  2159 by(induct rule:finite_ne_induct) simp_all
  2159 by(induct rule:finite_ne_induct) simp_all
  2160 
  2160 
  2161 
  2161 
  2162 lemma (in ACIfSL) fold1_belowI:
  2162 lemma (in ACIfSL) fold1_belowI:
  2163 assumes A: "finite A" "A \<noteq> {}"
  2163 assumes A: "finite A" "A \<noteq> {}"
  2164 shows "a \<in> A \<Longrightarrow> fold1 f A \<sqsubseteq> a"
  2164 shows "a \<in> A \<Longrightarrow> fold1 f A \<^loc>\<le> a"
  2165 using A
  2165 using A
  2166 proof (induct rule:finite_ne_induct)
  2166 proof (induct rule:finite_ne_induct)
  2167   case singleton thus ?case by simp
  2167   case singleton thus ?case by simp
  2168 next
  2168 next
  2169   case (insert x F)
  2169   case (insert x F)
  2171   thus ?case
  2171   thus ?case
  2172   proof
  2172   proof
  2173     assume "a = x" thus ?thesis using insert by(simp add:below_def ACI)
  2173     assume "a = x" thus ?thesis using insert by(simp add:below_def ACI)
  2174   next
  2174   next
  2175     assume "a \<in> F"
  2175     assume "a \<in> F"
  2176     hence bel: "fold1 f F \<sqsubseteq> a" by(rule insert)
  2176     hence bel: "fold1 f F \<^loc>\<le> a" by(rule insert)
  2177     have "fold1 f (insert x F) \<cdot> a = x \<cdot> (fold1 f F \<cdot> a)"
  2177     have "fold1 f (insert x F) \<cdot> a = x \<cdot> (fold1 f F \<cdot> a)"
  2178       using insert by(simp add:below_def ACI)
  2178       using insert by(simp add:below_def ACI)
  2179     also have "fold1 f F \<cdot> a = fold1 f F"
  2179     also have "fold1 f F \<cdot> a = fold1 f F"
  2180       using bel  by(simp add:below_def ACI)
  2180       using bel  by(simp add:below_def ACI)
  2181     also have "x \<cdot> \<dots> = fold1 f (insert x F)"
  2181     also have "x \<cdot> \<dots> = fold1 f (insert x F)"
  2184   qed
  2184   qed
  2185 qed
  2185 qed
  2186 
  2186 
  2187 lemma (in ACIfSLlin) fold1_below_iff:
  2187 lemma (in ACIfSLlin) fold1_below_iff:
  2188 assumes A: "finite A" "A \<noteq> {}"
  2188 assumes A: "finite A" "A \<noteq> {}"
  2189 shows "fold1 f A \<sqsubseteq> x = (\<exists>a\<in>A. a \<sqsubseteq> x)"
  2189 shows "fold1 f A \<^loc>\<le> x = (\<exists>a\<in>A. a \<^loc>\<le> x)"
  2190 using A
  2190 using A
  2191 by(induct rule:finite_ne_induct)(simp_all add:above_f_conv)
  2191 by(induct rule:finite_ne_induct)(simp_all add:above_f_conv)
  2192 
  2192 
  2193 lemma (in ACIfSLlin) fold1_strict_below_iff:
  2193 lemma (in ACIfSLlin) fold1_strict_below_iff:
  2194 assumes A: "finite A" "A \<noteq> {}"
  2194 assumes A: "finite A" "A \<noteq> {}"
  2195 shows "fold1 f A \<sqsubset> x = (\<exists>a\<in>A. a \<sqsubset> x)"
  2195 shows "fold1 f A \<^loc>< x = (\<exists>a\<in>A. a \<^loc>< x)"
  2196 using A
  2196 using A
  2197 by(induct rule:finite_ne_induct)(simp_all add:strict_above_f_conv)
  2197 by(induct rule:finite_ne_induct)(simp_all add:strict_above_f_conv)
  2198 
  2198 
  2199 lemma (in ACIfSLlin) fold1_antimono:
  2199 lemma (in ACIfSLlin) fold1_antimono:
  2200 assumes "A \<noteq> {}" and "A \<subseteq> B" and "finite B"
  2200 assumes "A \<noteq> {}" and "A \<subseteq> B" and "finite B"
  2201 shows "fold1 f B \<sqsubseteq> fold1 f A"
  2201 shows "fold1 f B \<^loc>\<le> fold1 f A"
  2202 proof(cases)
  2202 proof(cases)
  2203   assume "A = B" thus ?thesis by simp
  2203   assume "A = B" thus ?thesis by simp
  2204 next
  2204 next
  2205   assume "A \<noteq> B"
  2205   assume "A \<noteq> B"
  2206   have B: "B = A \<union> (B-A)" using `A \<subseteq> B` by blast
  2206   have B: "B = A \<union> (B-A)" using `A \<subseteq> B` by blast
  2211     moreover have "finite(B-A)" by(rule finite_Diff[OF `finite B`]) (* by(blast intro:finite_Diff prems) fails *)
  2211     moreover have "finite(B-A)" by(rule finite_Diff[OF `finite B`]) (* by(blast intro:finite_Diff prems) fails *)
  2212     moreover have "(B-A) \<noteq> {}" using prems by blast
  2212     moreover have "(B-A) \<noteq> {}" using prems by blast
  2213     moreover have "A Int (B-A) = {}" using prems by blast
  2213     moreover have "A Int (B-A) = {}" using prems by blast
  2214     ultimately show ?thesis using `A \<noteq> {}` by(rule_tac fold1_Un)
  2214     ultimately show ?thesis using `A \<noteq> {}` by(rule_tac fold1_Un)
  2215   qed
  2215   qed
  2216   also have "\<dots> \<sqsubseteq> fold1 f A" by(simp add: above_f_conv)
  2216   also have "\<dots> \<^loc>\<le> fold1 f A" by(simp add: above_f_conv)
  2217   finally show ?thesis .
  2217   finally show ?thesis .
  2218 qed
  2218 qed
  2219 
  2219 
  2220 
  2220 
  2221 subsubsection {* Fold1 in lattices with @{const inf} and @{const sup} *}
  2221 subsubsection {* Fold1 in lattices with @{const inf} and @{const sup} *}
  2283 definition
  2283 definition
  2284   Sup_fin :: "'a set \<Rightarrow> 'a" ("\<Squnion>\<^bsub>fin\<^esub>_" [900] 900)
  2284   Sup_fin :: "'a set \<Rightarrow> 'a" ("\<Squnion>\<^bsub>fin\<^esub>_" [900] 900)
  2285 where
  2285 where
  2286   "Sup_fin = fold1 (op \<squnion>)"
  2286   "Sup_fin = fold1 (op \<squnion>)"
  2287 
  2287 
  2288 lemma Inf_le_Sup [simp]: "\<lbrakk> finite A; A \<noteq> {} \<rbrakk> \<Longrightarrow> \<Sqinter>\<^bsub>fin\<^esub>A \<sqsubseteq> \<Squnion>\<^bsub>fin\<^esub>A"
  2288 lemma Inf_le_Sup [simp]: "\<lbrakk> finite A; A \<noteq> {} \<rbrakk> \<Longrightarrow> \<Sqinter>\<^bsub>fin\<^esub>A \<^loc>\<le> \<Squnion>\<^bsub>fin\<^esub>A"
  2289 apply(unfold Sup_fin_def Inf_fin_def)
  2289 apply(unfold Sup_fin_def Inf_fin_def)
  2290 apply(subgoal_tac "EX a. a:A")
  2290 apply(subgoal_tac "EX a. a:A")
  2291 prefer 2 apply blast
  2291 prefer 2 apply blast
  2292 apply(erule exE)
  2292 apply(erule exE)
  2293 apply(rule order_trans)
  2293 apply(rule order_trans)