author wenzelm Wed, 07 May 2014 14:44:07 +0200 changeset 56899 9b9f4abaaa7e parent 56898 ba507cc96473 child 56900 beea3ee118af
more symbols; tuned proofs;
```--- a/src/HOL/Library/Set_Algebras.thy	Wed May 07 14:05:17 2014 +0200
+++ b/src/HOL/Library/Set_Algebras.thy	Wed May 07 14:44:07 2014 +0200
@@ -9,7 +9,7 @@
begin

text {*
-  This library lifts operations like addition and muliplication to
+  This library lifts operations like addition and multiplication to
sets.  It was designed to support asymptotic calculations. See the
comments at the top of theory @{text BigO}.
*}
@@ -38,17 +38,17 @@
begin

definition
-  set_zero[simp]: "0::('a::zero)set == {0}"
+  set_zero[simp]: "(0::'a::zero set) = {0}"

instance ..

end
-
+
instantiation set :: (one) one
begin

definition
-  set_one[simp]: "1::('a::one)set == {1}"
+  set_one[simp]: "(1::'a::one set) = {1}"

instance ..

@@ -64,30 +64,30 @@
"x =o A \<equiv> x \<in> A"

+  by default (simp_all add: set_plus_def)

+  by default (simp_all add: set_plus_def)

instance set :: (semigroup_mult) semigroup_mult
-by default (force simp add: set_times_def mult.assoc)
+  by default (force simp add: set_times_def mult.assoc)

instance set :: (ab_semigroup_mult) ab_semigroup_mult
-by default (force simp add: set_times_def mult.commute)
+  by default (force simp add: set_times_def mult.commute)

instance set :: (monoid_mult) monoid_mult
+  by default (simp_all add: set_times_def)

instance set :: (comm_monoid_mult) comm_monoid_mult
+  by default (simp_all add: set_times_def)

-lemma set_plus_intro [intro]: "a : C ==> b : D ==> a + b : C + D"
+lemma set_plus_intro [intro]: "a \<in> C \<Longrightarrow> b \<in> D \<Longrightarrow> a + b \<in> C + D"

lemma set_plus_elim:
@@ -95,11 +95,11 @@
obtains a b where "x = a + b" and "a \<in> A" and "b \<in> B"
using assms unfolding set_plus_def by fast

-lemma set_plus_intro2 [intro]: "b : C ==> a + b : a +o C"
+lemma set_plus_intro2 [intro]: "b \<in> C \<Longrightarrow> a + b \<in> a +o C"

-lemma set_plus_rearrange: "((a::'a::comm_monoid_add) +o C) +
-    (b +o D) = (a + b) +o (C + D)"
+lemma set_plus_rearrange:
+  "((a::'a::comm_monoid_add) +o C) + (b +o D) = (a + b) +o (C + D)"
apply (rule_tac x = "ba + bb" in exI)
@@ -107,12 +107,10 @@
done

-lemma set_plus_rearrange2: "(a::'a::semigroup_add) +o (b +o C) =
-    (a + b) +o C"
+lemma set_plus_rearrange2: "(a::'a::semigroup_add) +o (b +o C) = (a + b) +o C"

-lemma set_plus_rearrange3: "((a::'a::semigroup_add) +o B) + C =
-    a +o (B + C)"
+lemma set_plus_rearrange3: "((a::'a::semigroup_add) +o B) + C = a +o (B + C)"
apply (auto simp add: elt_set_plus_def set_plus_def)
apply (rule_tac x = "a + aa" in exI)
@@ -123,8 +121,7 @@
done

-theorem set_plus_rearrange4: "C + ((a::'a::comm_monoid_add) +o D) =
-    a +o (C + D)"
+theorem set_plus_rearrange4: "C + ((a::'a::comm_monoid_add) +o D) = a +o (C + D)"
apply (rule_tac x = "aa + ba" in exI)
@@ -133,48 +130,43 @@
theorems set_plus_rearranges = set_plus_rearrange set_plus_rearrange2
set_plus_rearrange3 set_plus_rearrange4

-lemma set_plus_mono [intro!]: "C <= D ==> a +o C <= a +o D"
+lemma set_plus_mono [intro!]: "C \<subseteq> D \<Longrightarrow> a +o C \<subseteq> a +o D"

-lemma set_plus_mono2 [intro]: "(C::('a::plus) set) <= D ==> E <= F ==>
-    C + E <= D + F"
+lemma set_plus_mono2 [intro]: "(C::'a::plus set) \<subseteq> D \<Longrightarrow> E \<subseteq> F \<Longrightarrow> C + E \<subseteq> D + F"

-lemma set_plus_mono3 [intro]: "a : C ==> a +o D <= C + D"
+lemma set_plus_mono3 [intro]: "a \<in> C \<Longrightarrow> a +o D \<subseteq> C + D"
by (auto simp add: elt_set_plus_def set_plus_def)

-lemma set_plus_mono4 [intro]: "(a::'a::comm_monoid_add) : C ==>
-    a +o D <= D + C"
+lemma set_plus_mono4 [intro]: "(a::'a::comm_monoid_add) \<in> C \<Longrightarrow> a +o D \<subseteq> D + C"

-lemma set_plus_mono5: "a:C ==> B <= D ==> a +o B <= C + D"
-  apply (subgoal_tac "a +o B <= a +o D")
+lemma set_plus_mono5: "a \<in> C \<Longrightarrow> B \<subseteq> D \<Longrightarrow> a +o B \<subseteq> C + D"
+  apply (subgoal_tac "a +o B \<subseteq> a +o D")
apply (erule order_trans)
apply (erule set_plus_mono3)
apply (erule set_plus_mono)
done

-lemma set_plus_mono_b: "C <= D ==> x : a +o C
-    ==> x : a +o D"
+lemma set_plus_mono_b: "C \<subseteq> D \<Longrightarrow> x \<in> a +o C \<Longrightarrow> x \<in> a +o D"
apply (frule set_plus_mono)
apply auto
done

-lemma set_plus_mono2_b: "C <= D ==> E <= F ==> x : C + E ==>
-    x : D + F"
+lemma set_plus_mono2_b: "C \<subseteq> D \<Longrightarrow> E \<subseteq> F \<Longrightarrow> x \<in> C + E \<Longrightarrow> x \<in> D + F"
apply (frule set_plus_mono2)
prefer 2
apply force
apply assumption
done

-lemma set_plus_mono3_b: "a : C ==> x : a +o D ==> x : C + D"
+lemma set_plus_mono3_b: "a \<in> C \<Longrightarrow> x \<in> a +o D \<Longrightarrow> x \<in> C + D"
apply (frule set_plus_mono3)
apply auto
done

-lemma set_plus_mono4_b: "(a::'a::comm_monoid_add) : C ==>
-    x : a +o D ==> x : D + C"
+lemma set_plus_mono4_b: "(a::'a::comm_monoid_add) : C \<Longrightarrow> x \<in> a +o D \<Longrightarrow> x \<in> D + C"
apply (frule set_plus_mono4)
apply auto
done
@@ -182,28 +174,27 @@
lemma set_zero_plus [simp]: "(0::'a::comm_monoid_add) +o C = C"

-lemma set_zero_plus2: "(0::'a::comm_monoid_add) : A ==> B <= A + B"
+lemma set_zero_plus2: "(0::'a::comm_monoid_add) \<in> A \<Longrightarrow> B \<subseteq> A + B"
apply (rule_tac x = 0 in bexI)
apply (rule_tac x = x in bexI)
done

-lemma set_plus_imp_minus: "(a::'a::ab_group_add) : b +o C ==> (a - b) : C"
+lemma set_plus_imp_minus: "(a::'a::ab_group_add) : b +o C \<Longrightarrow> (a - b) \<in> C"

-lemma set_minus_imp_plus: "(a::'a::ab_group_add) - b : C ==> a : b +o C"
+lemma set_minus_imp_plus: "(a::'a::ab_group_add) - b : C \<Longrightarrow> a \<in> b +o C"
apply (subgoal_tac "a = (a + - b) + b")
apply (rule bexI, assumption)
done

-lemma set_minus_plus: "((a::'a::ab_group_add) - b : C) = (a : b +o C)"
-  by (rule iffI, rule set_minus_imp_plus, assumption, rule set_plus_imp_minus,
-    assumption)
+lemma set_minus_plus: "(a::'a::ab_group_add) - b \<in> C \<longleftrightarrow> a \<in> b +o C"
+  by (rule iffI, rule set_minus_imp_plus, assumption, rule set_plus_imp_minus)

-lemma set_times_intro [intro]: "a : C ==> b : D ==> a * b : C * D"
+lemma set_times_intro [intro]: "a \<in> C \<Longrightarrow> b \<in> D \<Longrightarrow> a * b \<in> C * D"

lemma set_times_elim:
@@ -211,11 +202,11 @@
obtains a b where "x = a * b" and "a \<in> A" and "b \<in> B"
using assms unfolding set_times_def by fast

-lemma set_times_intro2 [intro!]: "b : C ==> a * b : a *o C"
+lemma set_times_intro2 [intro!]: "b \<in> C \<Longrightarrow> a * b \<in> a *o C"

-lemma set_times_rearrange: "((a::'a::comm_monoid_mult) *o C) *
-    (b *o D) = (a * b) *o (C * D)"
+lemma set_times_rearrange:
+  "((a::'a::comm_monoid_mult) *o C) * (b *o D) = (a * b) *o (C * D)"
apply (auto simp add: elt_set_times_def set_times_def)
apply (rule_tac x = "ba * bb" in exI)
@@ -223,12 +214,12 @@
done

-lemma set_times_rearrange2: "(a::'a::semigroup_mult) *o (b *o C) =
-    (a * b) *o C"
+lemma set_times_rearrange2:
+  "(a::'a::semigroup_mult) *o (b *o C) = (a * b) *o C"
by (auto simp add: elt_set_times_def mult_assoc)

-lemma set_times_rearrange3: "((a::'a::semigroup_mult) *o B) * C =
-    a *o (B * C)"
+lemma set_times_rearrange3:
+  "((a::'a::semigroup_mult) *o B) * C = a *o (B * C)"
apply (auto simp add: elt_set_times_def set_times_def)
apply (blast intro: mult_ac)
apply (rule_tac x = "a * aa" in exI)
@@ -239,10 +230,9 @@
done

-theorem set_times_rearrange4: "C * ((a::'a::comm_monoid_mult) *o D) =
-    a *o (C * D)"
-  apply (auto simp add: elt_set_times_def set_times_def
-    mult_ac)
+theorem set_times_rearrange4:
+  "C * ((a::'a::comm_monoid_mult) *o D) = a *o (C * D)"
+  apply (auto simp add: elt_set_times_def set_times_def mult_ac)
apply (rule_tac x = "aa * ba" in exI)
done
@@ -250,48 +240,43 @@
theorems set_times_rearranges = set_times_rearrange set_times_rearrange2
set_times_rearrange3 set_times_rearrange4

-lemma set_times_mono [intro]: "C <= D ==> a *o C <= a *o D"
+lemma set_times_mono [intro]: "C \<subseteq> D \<Longrightarrow> a *o C \<subseteq> a *o D"

-lemma set_times_mono2 [intro]: "(C::('a::times) set) <= D ==> E <= F ==>
-    C * E <= D * F"
+lemma set_times_mono2 [intro]: "(C::'a::times set) \<subseteq> D \<Longrightarrow> E \<subseteq> F \<Longrightarrow> C * E \<subseteq> D * F"

-lemma set_times_mono3 [intro]: "a : C ==> a *o D <= C * D"
+lemma set_times_mono3 [intro]: "a \<in> C \<Longrightarrow> a *o D \<subseteq> C * D"
by (auto simp add: elt_set_times_def set_times_def)

-lemma set_times_mono4 [intro]: "(a::'a::comm_monoid_mult) : C ==>
-    a *o D <= D * C"
+lemma set_times_mono4 [intro]: "(a::'a::comm_monoid_mult) : C \<Longrightarrow> a *o D \<subseteq> D * C"
by (auto simp add: elt_set_times_def set_times_def mult_ac)

-lemma set_times_mono5: "a:C ==> B <= D ==> a *o B <= C * D"
-  apply (subgoal_tac "a *o B <= a *o D")
+lemma set_times_mono5: "a \<in> C \<Longrightarrow> B \<subseteq> D \<Longrightarrow> a *o B \<subseteq> C * D"
+  apply (subgoal_tac "a *o B \<subseteq> a *o D")
apply (erule order_trans)
apply (erule set_times_mono3)
apply (erule set_times_mono)
done

-lemma set_times_mono_b: "C <= D ==> x : a *o C
-    ==> x : a *o D"
+lemma set_times_mono_b: "C \<subseteq> D \<Longrightarrow> x \<in> a *o C \<Longrightarrow> x \<in> a *o D"
apply (frule set_times_mono)
apply auto
done

-lemma set_times_mono2_b: "C <= D ==> E <= F ==> x : C * E ==>
-    x : D * F"
+lemma set_times_mono2_b: "C \<subseteq> D \<Longrightarrow> E \<subseteq> F \<Longrightarrow> x \<in> C * E \<Longrightarrow> x \<in> D * F"
apply (frule set_times_mono2)
prefer 2
apply force
apply assumption
done

-lemma set_times_mono3_b: "a : C ==> x : a *o D ==> x : C * D"
+lemma set_times_mono3_b: "a \<in> C \<Longrightarrow> x \<in> a *o D \<Longrightarrow> x \<in> C * D"
apply (frule set_times_mono3)
apply auto
done

-lemma set_times_mono4_b: "(a::'a::comm_monoid_mult) : C ==>
-    x : a *o D ==> x : D * C"
+lemma set_times_mono4_b: "(a::'a::comm_monoid_mult) \<in> C \<Longrightarrow> x \<in> a *o D \<Longrightarrow> x \<in> D * C"
apply (frule set_times_mono4)
apply auto
done
@@ -299,20 +284,19 @@
lemma set_one_times [simp]: "(1::'a::comm_monoid_mult) *o C = C"

-lemma set_times_plus_distrib: "(a::'a::semiring) *o (b +o C)=
-    (a * b) +o (a *o C)"
+lemma set_times_plus_distrib:
+  "(a::'a::semiring) *o (b +o C) = (a * b) +o (a *o C)"
by (auto simp add: elt_set_plus_def elt_set_times_def ring_distribs)

-lemma set_times_plus_distrib2: "(a::'a::semiring) *o (B + C) =
-    (a *o B) + (a *o C)"
+lemma set_times_plus_distrib2:
+  "(a::'a::semiring) *o (B + C) = (a *o B) + (a *o C)"
apply (auto simp add: set_plus_def elt_set_times_def ring_distribs)
apply blast
apply (rule_tac x = "b + bb" in exI)
done

-lemma set_times_plus_distrib3: "((a::'a::semiring) +o C) * D <=
-    a *o D + C * D"
+lemma set_times_plus_distrib3: "((a::'a::semiring) +o C) * D \<subseteq> a *o D + C * D"
elt_set_plus_def elt_set_times_def set_times_def
set_plus_def ring_distribs)
@@ -323,12 +307,10 @@
set_times_plus_distrib
set_times_plus_distrib2

-lemma set_neg_intro: "(a::'a::ring_1) : (- 1) *o C ==>
-    - a : C"
+lemma set_neg_intro: "(a::'a::ring_1) \<in> (- 1) *o C \<Longrightarrow> - a \<in> C"

-lemma set_neg_intro2: "(a::'a::ring_1) : C ==>
-    - a : (- 1) *o C"
+lemma set_neg_intro2: "(a::'a::ring_1) \<in> C \<Longrightarrow> - a \<in> (- 1) *o C"

lemma set_plus_image: "S + T = (\<lambda>(x, y). x + y) ` (S \<times> T)"
@@ -337,53 +319,63 @@
lemma set_times_image: "S * T = (\<lambda>(x, y). x * y) ` (S \<times> T)"
unfolding set_times_def by (fastforce simp: image_iff)

-lemma finite_set_plus:
-  assumes "finite s" and "finite t" shows "finite (s + t)"
-  using assms unfolding set_plus_image by simp
+lemma finite_set_plus: "finite s \<Longrightarrow> finite t \<Longrightarrow> finite (s + t)"
+  unfolding set_plus_image by simp

-lemma finite_set_times:
-  assumes "finite s" and "finite t" shows "finite (s * t)"
-  using assms unfolding set_times_image by simp
+lemma finite_set_times: "finite s \<Longrightarrow> finite t \<Longrightarrow> finite (s * t)"
+  unfolding set_times_image by simp

lemma set_setsum_alt:
assumes fin: "finite I"
shows "setsum S I = {setsum s I |s. \<forall>i\<in>I. s i \<in> S i}"
(is "_ = ?setsum I")
-using fin proof induct
+  using fin
+proof induct
+  case empty
+  then show ?case by simp
+next
case (insert x F)
have "setsum S (insert x F) = S x + ?setsum F"
using insert.hyps by auto
-  also have "...= {s x + setsum s F |s. \<forall> i\<in>insert x F. s i \<in> S i}"
+  also have "\<dots> = {s x + setsum s F |s. \<forall> i\<in>insert x F. s i \<in> S i}"
unfolding set_plus_def
proof safe
-    fix y s assume "y \<in> S x" "\<forall>i\<in>F. s i \<in> S i"
+    fix y s
+    assume "y \<in> S x" "\<forall>i\<in>F. s i \<in> S i"
then show "\<exists>s'. y + setsum s F = s' x + setsum s' F \<and> (\<forall>i\<in>insert x F. s' i \<in> S i)"
using insert.hyps
by (intro exI[of _ "\<lambda>i. if i \<in> F then s i else y"]) (auto simp add: set_plus_def)
qed auto
finally show ?case
using insert.hyps by auto
-qed auto
+qed

lemma setsum_set_cond_linear:
assumes [intro!]: "\<And>A B. P A  \<Longrightarrow> P B  \<Longrightarrow> P (A + B)" "P {0}"
and f: "\<And>A B. P A  \<Longrightarrow> P B \<Longrightarrow> f (A + B) = f A + f B" "f {0} = {0}"
assumes all: "\<And>i. i \<in> I \<Longrightarrow> P (S i)"
shows "f (setsum S I) = setsum (f \<circ> S) I"
-proof cases
-  assume "finite I" from this all show ?thesis
+proof (cases "finite I")
+  case True
+  from this all show ?thesis
proof induct
+    case empty
+    then show ?case by (auto intro!: f)
+  next
case (insert x F)
from `finite F` `\<And>i. i \<in> insert x F \<Longrightarrow> P (S i)` have "P (setsum S F)"
by induct auto
with insert show ?case
by (simp, subst f) auto
-  qed (auto intro!: f)
-qed (auto intro!: f)
+  qed
+next
+  case False
+  then show ?thesis by (auto intro!: f)
+qed

lemma setsum_set_linear:
assumes "\<And>A B. f(A) + f(B) = f(A + B)" "f {0} = {0}"
shows "f (setsum S I) = setsum (f \<circ> S) I"
using setsum_set_cond_linear[of "\<lambda>x. True" f I S] assms by auto
@@ -391,11 +383,11 @@
lemma set_times_Un_distrib:
"A * (B \<union> C) = A * B \<union> A * C"
"(A \<union> B) * C = A * C \<union> B * C"
-by (auto simp: set_times_def)
+  by (auto simp: set_times_def)

lemma set_times_UNION_distrib:
-  "A * UNION I M = UNION I (%i. A * M i)"
-  "UNION I M * A = UNION I (%i. M i * A)"
-by (auto simp: set_times_def)
+  "A * UNION I M = (\<Union>i\<in>I. A * M i)"
+  "UNION I M * A = (\<Union>i\<in>I. M i * A)"
+  by (auto simp: set_times_def)

end```