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