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