src/HOL/Library/Set_Algebras.thy
author haftmann
Fri Nov 01 18:51:14 2013 +0100 (2013-11-01)
changeset 54230 b1d955791529
parent 53596 d29d63460d84
child 56899 9b9f4abaaa7e
permissions -rw-r--r--
more simplification rules on unary and binary minus
haftmann@38622
     1
(*  Title:      HOL/Library/Set_Algebras.thy
haftmann@38622
     2
    Author:     Jeremy Avigad and Kevin Donnelly; Florian Haftmann, TUM
avigad@16908
     3
*)
avigad@16908
     4
haftmann@38622
     5
header {* Algebraic operations on sets *}
avigad@16908
     6
haftmann@38622
     7
theory Set_Algebras
haftmann@30738
     8
imports Main
avigad@16908
     9
begin
avigad@16908
    10
wenzelm@19736
    11
text {*
haftmann@38622
    12
  This library lifts operations like addition and muliplication to
haftmann@38622
    13
  sets.  It was designed to support asymptotic calculations. See the
haftmann@38622
    14
  comments at the top of theory @{text BigO}.
avigad@16908
    15
*}
avigad@16908
    16
krauss@47443
    17
instantiation set :: (plus) plus
krauss@47443
    18
begin
krauss@47443
    19
krauss@47443
    20
definition plus_set :: "'a::plus set \<Rightarrow> 'a set \<Rightarrow> 'a set" where
krauss@47443
    21
  set_plus_def: "A + B = {c. \<exists>a\<in>A. \<exists>b\<in>B. c = a + b}"
krauss@47443
    22
krauss@47443
    23
instance ..
krauss@47443
    24
krauss@47443
    25
end
krauss@47443
    26
krauss@47443
    27
instantiation set :: (times) times
krauss@47443
    28
begin
krauss@47443
    29
krauss@47443
    30
definition times_set :: "'a::times set \<Rightarrow> 'a set \<Rightarrow> 'a set" where
krauss@47443
    31
  set_times_def: "A * B = {c. \<exists>a\<in>A. \<exists>b\<in>B. c = a * b}"
krauss@47443
    32
krauss@47443
    33
instance ..
krauss@47443
    34
krauss@47443
    35
end
krauss@47443
    36
krauss@47443
    37
instantiation set :: (zero) zero
krauss@47443
    38
begin
krauss@47443
    39
krauss@47443
    40
definition
krauss@47443
    41
  set_zero[simp]: "0::('a::zero)set == {0}"
krauss@47443
    42
krauss@47443
    43
instance ..
krauss@47443
    44
krauss@47443
    45
end
krauss@47443
    46
 
krauss@47443
    47
instantiation set :: (one) one
krauss@47443
    48
begin
krauss@47443
    49
krauss@47443
    50
definition
krauss@47443
    51
  set_one[simp]: "1::('a::one)set == {1}"
krauss@47443
    52
krauss@47443
    53
instance ..
krauss@47443
    54
krauss@47443
    55
end
haftmann@25594
    56
haftmann@38622
    57
definition elt_set_plus :: "'a::plus \<Rightarrow> 'a set \<Rightarrow> 'a set"  (infixl "+o" 70) where
haftmann@38622
    58
  "a +o B = {c. \<exists>b\<in>B. c = a + b}"
avigad@16908
    59
haftmann@38622
    60
definition elt_set_times :: "'a::times \<Rightarrow> 'a set \<Rightarrow> 'a set"  (infixl "*o" 80) where
haftmann@38622
    61
  "a *o B = {c. \<exists>b\<in>B. c = a * b}"
haftmann@25594
    62
haftmann@38622
    63
abbreviation (input) elt_set_eq :: "'a \<Rightarrow> 'a set \<Rightarrow> bool"  (infix "=o" 50) where
haftmann@38622
    64
  "x =o A \<equiv> x \<in> A"
haftmann@25594
    65
krauss@47443
    66
instance set :: (semigroup_add) semigroup_add
krauss@47443
    67
by default (force simp add: set_plus_def add.assoc)
haftmann@25594
    68
krauss@47443
    69
instance set :: (ab_semigroup_add) ab_semigroup_add
krauss@47443
    70
by default (force simp add: set_plus_def add.commute)
haftmann@25594
    71
krauss@47443
    72
instance set :: (monoid_add) monoid_add
krauss@47443
    73
by default (simp_all add: set_plus_def)
haftmann@25594
    74
krauss@47443
    75
instance set :: (comm_monoid_add) comm_monoid_add
krauss@47443
    76
by default (simp_all add: set_plus_def)
avigad@16908
    77
krauss@47443
    78
instance set :: (semigroup_mult) semigroup_mult
krauss@47443
    79
by default (force simp add: set_times_def mult.assoc)
avigad@16908
    80
krauss@47443
    81
instance set :: (ab_semigroup_mult) ab_semigroup_mult
krauss@47443
    82
by default (force simp add: set_times_def mult.commute)
avigad@16908
    83
krauss@47443
    84
instance set :: (monoid_mult) monoid_mult
krauss@47443
    85
by default (simp_all add: set_times_def)
avigad@16908
    86
krauss@47443
    87
instance set :: (comm_monoid_mult) comm_monoid_mult
krauss@47443
    88
by default (simp_all add: set_times_def)
avigad@16908
    89
krauss@47445
    90
lemma set_plus_intro [intro]: "a : C ==> b : D ==> a + b : C + D"
berghofe@26814
    91
  by (auto simp add: set_plus_def)
avigad@16908
    92
huffman@53596
    93
lemma set_plus_elim:
huffman@53596
    94
  assumes "x \<in> A + B"
huffman@53596
    95
  obtains a b where "x = a + b" and "a \<in> A" and "b \<in> B"
huffman@53596
    96
  using assms unfolding set_plus_def by fast
huffman@53596
    97
avigad@16908
    98
lemma set_plus_intro2 [intro]: "b : C ==> a + b : a +o C"
wenzelm@19736
    99
  by (auto simp add: elt_set_plus_def)
avigad@16908
   100
krauss@47445
   101
lemma set_plus_rearrange: "((a::'a::comm_monoid_add) +o C) +
krauss@47445
   102
    (b +o D) = (a + b) +o (C + D)"
berghofe@26814
   103
  apply (auto simp add: elt_set_plus_def set_plus_def add_ac)
wenzelm@19736
   104
   apply (rule_tac x = "ba + bb" in exI)
avigad@16908
   105
  apply (auto simp add: add_ac)
avigad@16908
   106
  apply (rule_tac x = "aa + a" in exI)
avigad@16908
   107
  apply (auto simp add: add_ac)
wenzelm@19736
   108
  done
avigad@16908
   109
wenzelm@19736
   110
lemma set_plus_rearrange2: "(a::'a::semigroup_add) +o (b +o C) =
wenzelm@19736
   111
    (a + b) +o C"
wenzelm@19736
   112
  by (auto simp add: elt_set_plus_def add_assoc)
avigad@16908
   113
krauss@47445
   114
lemma set_plus_rearrange3: "((a::'a::semigroup_add) +o B) + C =
krauss@47445
   115
    a +o (B + C)"
berghofe@26814
   116
  apply (auto simp add: elt_set_plus_def set_plus_def)
wenzelm@19736
   117
   apply (blast intro: add_ac)
avigad@16908
   118
  apply (rule_tac x = "a + aa" in exI)
avigad@16908
   119
  apply (rule conjI)
wenzelm@19736
   120
   apply (rule_tac x = "aa" in bexI)
wenzelm@19736
   121
    apply auto
avigad@16908
   122
  apply (rule_tac x = "ba" in bexI)
wenzelm@19736
   123
   apply (auto simp add: add_ac)
wenzelm@19736
   124
  done
avigad@16908
   125
krauss@47445
   126
theorem set_plus_rearrange4: "C + ((a::'a::comm_monoid_add) +o D) =
krauss@47445
   127
    a +o (C + D)"
huffman@44142
   128
  apply (auto simp add: elt_set_plus_def set_plus_def add_ac)
wenzelm@19736
   129
   apply (rule_tac x = "aa + ba" in exI)
wenzelm@19736
   130
   apply (auto simp add: add_ac)
wenzelm@19736
   131
  done
avigad@16908
   132
avigad@16908
   133
theorems set_plus_rearranges = set_plus_rearrange set_plus_rearrange2
avigad@16908
   134
  set_plus_rearrange3 set_plus_rearrange4
avigad@16908
   135
avigad@16908
   136
lemma set_plus_mono [intro!]: "C <= D ==> a +o C <= a +o D"
wenzelm@19736
   137
  by (auto simp add: elt_set_plus_def)
avigad@16908
   138
wenzelm@19736
   139
lemma set_plus_mono2 [intro]: "(C::('a::plus) set) <= D ==> E <= F ==>
krauss@47445
   140
    C + E <= D + F"
berghofe@26814
   141
  by (auto simp add: set_plus_def)
avigad@16908
   142
krauss@47445
   143
lemma set_plus_mono3 [intro]: "a : C ==> a +o D <= C + D"
berghofe@26814
   144
  by (auto simp add: elt_set_plus_def set_plus_def)
avigad@16908
   145
wenzelm@19736
   146
lemma set_plus_mono4 [intro]: "(a::'a::comm_monoid_add) : C ==>
krauss@47445
   147
    a +o D <= D + C"
berghofe@26814
   148
  by (auto simp add: elt_set_plus_def set_plus_def add_ac)
avigad@16908
   149
krauss@47445
   150
lemma set_plus_mono5: "a:C ==> B <= D ==> a +o B <= C + D"
avigad@16908
   151
  apply (subgoal_tac "a +o B <= a +o D")
wenzelm@19736
   152
   apply (erule order_trans)
wenzelm@19736
   153
   apply (erule set_plus_mono3)
avigad@16908
   154
  apply (erule set_plus_mono)
wenzelm@19736
   155
  done
avigad@16908
   156
wenzelm@19736
   157
lemma set_plus_mono_b: "C <= D ==> x : a +o C
avigad@16908
   158
    ==> x : a +o D"
avigad@16908
   159
  apply (frule set_plus_mono)
avigad@16908
   160
  apply auto
wenzelm@19736
   161
  done
avigad@16908
   162
krauss@47445
   163
lemma set_plus_mono2_b: "C <= D ==> E <= F ==> x : C + E ==>
krauss@47445
   164
    x : D + F"
avigad@16908
   165
  apply (frule set_plus_mono2)
wenzelm@19736
   166
   prefer 2
wenzelm@19736
   167
   apply force
avigad@16908
   168
  apply assumption
wenzelm@19736
   169
  done
avigad@16908
   170
krauss@47445
   171
lemma set_plus_mono3_b: "a : C ==> x : a +o D ==> x : C + D"
avigad@16908
   172
  apply (frule set_plus_mono3)
avigad@16908
   173
  apply auto
wenzelm@19736
   174
  done
avigad@16908
   175
wenzelm@19736
   176
lemma set_plus_mono4_b: "(a::'a::comm_monoid_add) : C ==>
krauss@47445
   177
    x : a +o D ==> x : D + C"
avigad@16908
   178
  apply (frule set_plus_mono4)
avigad@16908
   179
  apply auto
wenzelm@19736
   180
  done
avigad@16908
   181
avigad@16908
   182
lemma set_zero_plus [simp]: "(0::'a::comm_monoid_add) +o C = C"
wenzelm@19736
   183
  by (auto simp add: elt_set_plus_def)
avigad@16908
   184
krauss@47445
   185
lemma set_zero_plus2: "(0::'a::comm_monoid_add) : A ==> B <= A + B"
huffman@44142
   186
  apply (auto simp add: set_plus_def)
avigad@16908
   187
  apply (rule_tac x = 0 in bexI)
wenzelm@19736
   188
   apply (rule_tac x = x in bexI)
wenzelm@19736
   189
    apply (auto simp add: add_ac)
wenzelm@19736
   190
  done
avigad@16908
   191
avigad@16908
   192
lemma set_plus_imp_minus: "(a::'a::ab_group_add) : b +o C ==> (a - b) : C"
haftmann@54230
   193
  by (auto simp add: elt_set_plus_def add_ac)
avigad@16908
   194
avigad@16908
   195
lemma set_minus_imp_plus: "(a::'a::ab_group_add) - b : C ==> a : b +o C"
haftmann@54230
   196
  apply (auto simp add: elt_set_plus_def add_ac)
avigad@16908
   197
  apply (subgoal_tac "a = (a + - b) + b")
haftmann@54230
   198
   apply (rule bexI, assumption)
avigad@16908
   199
  apply (auto simp add: add_ac)
wenzelm@19736
   200
  done
avigad@16908
   201
avigad@16908
   202
lemma set_minus_plus: "((a::'a::ab_group_add) - b : C) = (a : b +o C)"
wenzelm@19736
   203
  by (rule iffI, rule set_minus_imp_plus, assumption, rule set_plus_imp_minus,
avigad@16908
   204
    assumption)
avigad@16908
   205
krauss@47445
   206
lemma set_times_intro [intro]: "a : C ==> b : D ==> a * b : C * D"
berghofe@26814
   207
  by (auto simp add: set_times_def)
avigad@16908
   208
huffman@53596
   209
lemma set_times_elim:
huffman@53596
   210
  assumes "x \<in> A * B"
huffman@53596
   211
  obtains a b where "x = a * b" and "a \<in> A" and "b \<in> B"
huffman@53596
   212
  using assms unfolding set_times_def by fast
huffman@53596
   213
avigad@16908
   214
lemma set_times_intro2 [intro!]: "b : C ==> a * b : a *o C"
wenzelm@19736
   215
  by (auto simp add: elt_set_times_def)
avigad@16908
   216
krauss@47445
   217
lemma set_times_rearrange: "((a::'a::comm_monoid_mult) *o C) *
krauss@47445
   218
    (b *o D) = (a * b) *o (C * D)"
berghofe@26814
   219
  apply (auto simp add: elt_set_times_def set_times_def)
wenzelm@19736
   220
   apply (rule_tac x = "ba * bb" in exI)
wenzelm@19736
   221
   apply (auto simp add: mult_ac)
avigad@16908
   222
  apply (rule_tac x = "aa * a" in exI)
avigad@16908
   223
  apply (auto simp add: mult_ac)
wenzelm@19736
   224
  done
avigad@16908
   225
wenzelm@19736
   226
lemma set_times_rearrange2: "(a::'a::semigroup_mult) *o (b *o C) =
wenzelm@19736
   227
    (a * b) *o C"
wenzelm@19736
   228
  by (auto simp add: elt_set_times_def mult_assoc)
avigad@16908
   229
krauss@47445
   230
lemma set_times_rearrange3: "((a::'a::semigroup_mult) *o B) * C =
krauss@47445
   231
    a *o (B * C)"
berghofe@26814
   232
  apply (auto simp add: elt_set_times_def set_times_def)
wenzelm@19736
   233
   apply (blast intro: mult_ac)
avigad@16908
   234
  apply (rule_tac x = "a * aa" in exI)
avigad@16908
   235
  apply (rule conjI)
wenzelm@19736
   236
   apply (rule_tac x = "aa" in bexI)
wenzelm@19736
   237
    apply auto
avigad@16908
   238
  apply (rule_tac x = "ba" in bexI)
wenzelm@19736
   239
   apply (auto simp add: mult_ac)
wenzelm@19736
   240
  done
avigad@16908
   241
krauss@47445
   242
theorem set_times_rearrange4: "C * ((a::'a::comm_monoid_mult) *o D) =
krauss@47445
   243
    a *o (C * D)"
huffman@44142
   244
  apply (auto simp add: elt_set_times_def set_times_def
avigad@16908
   245
    mult_ac)
wenzelm@19736
   246
   apply (rule_tac x = "aa * ba" in exI)
wenzelm@19736
   247
   apply (auto simp add: mult_ac)
wenzelm@19736
   248
  done
avigad@16908
   249
avigad@16908
   250
theorems set_times_rearranges = set_times_rearrange set_times_rearrange2
avigad@16908
   251
  set_times_rearrange3 set_times_rearrange4
avigad@16908
   252
avigad@16908
   253
lemma set_times_mono [intro]: "C <= D ==> a *o C <= a *o D"
wenzelm@19736
   254
  by (auto simp add: elt_set_times_def)
avigad@16908
   255
wenzelm@19736
   256
lemma set_times_mono2 [intro]: "(C::('a::times) set) <= D ==> E <= F ==>
krauss@47445
   257
    C * E <= D * F"
berghofe@26814
   258
  by (auto simp add: set_times_def)
avigad@16908
   259
krauss@47445
   260
lemma set_times_mono3 [intro]: "a : C ==> a *o D <= C * D"
berghofe@26814
   261
  by (auto simp add: elt_set_times_def set_times_def)
avigad@16908
   262
wenzelm@19736
   263
lemma set_times_mono4 [intro]: "(a::'a::comm_monoid_mult) : C ==>
krauss@47445
   264
    a *o D <= D * C"
berghofe@26814
   265
  by (auto simp add: elt_set_times_def set_times_def mult_ac)
avigad@16908
   266
krauss@47445
   267
lemma set_times_mono5: "a:C ==> B <= D ==> a *o B <= C * D"
avigad@16908
   268
  apply (subgoal_tac "a *o B <= a *o D")
wenzelm@19736
   269
   apply (erule order_trans)
wenzelm@19736
   270
   apply (erule set_times_mono3)
avigad@16908
   271
  apply (erule set_times_mono)
wenzelm@19736
   272
  done
avigad@16908
   273
wenzelm@19736
   274
lemma set_times_mono_b: "C <= D ==> x : a *o C
avigad@16908
   275
    ==> x : a *o D"
avigad@16908
   276
  apply (frule set_times_mono)
avigad@16908
   277
  apply auto
wenzelm@19736
   278
  done
avigad@16908
   279
krauss@47445
   280
lemma set_times_mono2_b: "C <= D ==> E <= F ==> x : C * E ==>
krauss@47445
   281
    x : D * F"
avigad@16908
   282
  apply (frule set_times_mono2)
wenzelm@19736
   283
   prefer 2
wenzelm@19736
   284
   apply force
avigad@16908
   285
  apply assumption
wenzelm@19736
   286
  done
avigad@16908
   287
krauss@47445
   288
lemma set_times_mono3_b: "a : C ==> x : a *o D ==> x : C * D"
avigad@16908
   289
  apply (frule set_times_mono3)
avigad@16908
   290
  apply auto
wenzelm@19736
   291
  done
avigad@16908
   292
wenzelm@19736
   293
lemma set_times_mono4_b: "(a::'a::comm_monoid_mult) : C ==>
krauss@47445
   294
    x : a *o D ==> x : D * C"
avigad@16908
   295
  apply (frule set_times_mono4)
avigad@16908
   296
  apply auto
wenzelm@19736
   297
  done
avigad@16908
   298
avigad@16908
   299
lemma set_one_times [simp]: "(1::'a::comm_monoid_mult) *o C = C"
wenzelm@19736
   300
  by (auto simp add: elt_set_times_def)
avigad@16908
   301
wenzelm@19736
   302
lemma set_times_plus_distrib: "(a::'a::semiring) *o (b +o C)=
wenzelm@19736
   303
    (a * b) +o (a *o C)"
nipkow@23477
   304
  by (auto simp add: elt_set_plus_def elt_set_times_def ring_distribs)
avigad@16908
   305
krauss@47445
   306
lemma set_times_plus_distrib2: "(a::'a::semiring) *o (B + C) =
krauss@47445
   307
    (a *o B) + (a *o C)"
berghofe@26814
   308
  apply (auto simp add: set_plus_def elt_set_times_def ring_distribs)
wenzelm@19736
   309
   apply blast
avigad@16908
   310
  apply (rule_tac x = "b + bb" in exI)
nipkow@23477
   311
  apply (auto simp add: ring_distribs)
wenzelm@19736
   312
  done
avigad@16908
   313
krauss@47445
   314
lemma set_times_plus_distrib3: "((a::'a::semiring) +o C) * D <=
krauss@47445
   315
    a *o D + C * D"
huffman@44142
   316
  apply (auto simp add:
berghofe@26814
   317
    elt_set_plus_def elt_set_times_def set_times_def
berghofe@26814
   318
    set_plus_def ring_distribs)
avigad@16908
   319
  apply auto
wenzelm@19736
   320
  done
avigad@16908
   321
wenzelm@19380
   322
theorems set_times_plus_distribs =
wenzelm@19380
   323
  set_times_plus_distrib
avigad@16908
   324
  set_times_plus_distrib2
avigad@16908
   325
wenzelm@19736
   326
lemma set_neg_intro: "(a::'a::ring_1) : (- 1) *o C ==>
wenzelm@19736
   327
    - a : C"
wenzelm@19736
   328
  by (auto simp add: elt_set_times_def)
avigad@16908
   329
avigad@16908
   330
lemma set_neg_intro2: "(a::'a::ring_1) : C ==>
avigad@16908
   331
    - a : (- 1) *o C"
wenzelm@19736
   332
  by (auto simp add: elt_set_times_def)
wenzelm@19736
   333
huffman@53596
   334
lemma set_plus_image: "S + T = (\<lambda>(x, y). x + y) ` (S \<times> T)"
nipkow@44890
   335
  unfolding set_plus_def by (fastforce simp: image_iff)
hoelzl@40887
   336
huffman@53596
   337
lemma set_times_image: "S * T = (\<lambda>(x, y). x * y) ` (S \<times> T)"
huffman@53596
   338
  unfolding set_times_def by (fastforce simp: image_iff)
huffman@53596
   339
huffman@53596
   340
lemma finite_set_plus:
huffman@53596
   341
  assumes "finite s" and "finite t" shows "finite (s + t)"
huffman@53596
   342
  using assms unfolding set_plus_image by simp
huffman@53596
   343
huffman@53596
   344
lemma finite_set_times:
huffman@53596
   345
  assumes "finite s" and "finite t" shows "finite (s * t)"
huffman@53596
   346
  using assms unfolding set_times_image by simp
huffman@53596
   347
hoelzl@40887
   348
lemma set_setsum_alt:
hoelzl@40887
   349
  assumes fin: "finite I"
krauss@47444
   350
  shows "setsum S I = {setsum s I |s. \<forall>i\<in>I. s i \<in> S i}"
hoelzl@40887
   351
    (is "_ = ?setsum I")
hoelzl@40887
   352
using fin proof induct
hoelzl@40887
   353
  case (insert x F)
krauss@47445
   354
  have "setsum S (insert x F) = S x + ?setsum F"
hoelzl@40887
   355
    using insert.hyps by auto
hoelzl@40887
   356
  also have "...= {s x + setsum s F |s. \<forall> i\<in>insert x F. s i \<in> S i}"
hoelzl@40887
   357
    unfolding set_plus_def
hoelzl@40887
   358
  proof safe
hoelzl@40887
   359
    fix y s assume "y \<in> S x" "\<forall>i\<in>F. s i \<in> S i"
hoelzl@40887
   360
    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)"
hoelzl@40887
   361
      using insert.hyps
hoelzl@40887
   362
      by (intro exI[of _ "\<lambda>i. if i \<in> F then s i else y"]) (auto simp add: set_plus_def)
hoelzl@40887
   363
  qed auto
hoelzl@40887
   364
  finally show ?case
hoelzl@40887
   365
    using insert.hyps by auto
hoelzl@40887
   366
qed auto
hoelzl@40887
   367
hoelzl@40887
   368
lemma setsum_set_cond_linear:
hoelzl@40887
   369
  fixes f :: "('a::comm_monoid_add) set \<Rightarrow> ('b::comm_monoid_add) set"
krauss@47445
   370
  assumes [intro!]: "\<And>A B. P A  \<Longrightarrow> P B  \<Longrightarrow> P (A + B)" "P {0}"
krauss@47445
   371
    and f: "\<And>A B. P A  \<Longrightarrow> P B \<Longrightarrow> f (A + B) = f A + f B" "f {0} = {0}"
hoelzl@40887
   372
  assumes all: "\<And>i. i \<in> I \<Longrightarrow> P (S i)"
krauss@47444
   373
  shows "f (setsum S I) = setsum (f \<circ> S) I"
hoelzl@40887
   374
proof cases
hoelzl@40887
   375
  assume "finite I" from this all show ?thesis
hoelzl@40887
   376
  proof induct
hoelzl@40887
   377
    case (insert x F)
krauss@47444
   378
    from `finite F` `\<And>i. i \<in> insert x F \<Longrightarrow> P (S i)` have "P (setsum S F)"
hoelzl@40887
   379
      by induct auto
hoelzl@40887
   380
    with insert show ?case
hoelzl@40887
   381
      by (simp, subst f) auto
hoelzl@40887
   382
  qed (auto intro!: f)
hoelzl@40887
   383
qed (auto intro!: f)
hoelzl@40887
   384
hoelzl@40887
   385
lemma setsum_set_linear:
hoelzl@40887
   386
  fixes f :: "('a::comm_monoid_add) set => ('b::comm_monoid_add) set"
krauss@47445
   387
  assumes "\<And>A B. f(A) + f(B) = f(A + B)" "f {0} = {0}"
krauss@47444
   388
  shows "f (setsum S I) = setsum (f \<circ> S) I"
hoelzl@40887
   389
  using setsum_set_cond_linear[of "\<lambda>x. True" f I S] assms by auto
hoelzl@40887
   390
krauss@47446
   391
lemma set_times_Un_distrib:
krauss@47446
   392
  "A * (B \<union> C) = A * B \<union> A * C"
krauss@47446
   393
  "(A \<union> B) * C = A * C \<union> B * C"
krauss@47446
   394
by (auto simp: set_times_def)
krauss@47446
   395
krauss@47446
   396
lemma set_times_UNION_distrib:
krauss@47446
   397
  "A * UNION I M = UNION I (%i. A * M i)"
krauss@47446
   398
  "UNION I M * A = UNION I (%i. M i * A)"
krauss@47446
   399
by (auto simp: set_times_def)
krauss@47446
   400
avigad@16908
   401
end