src/HOL/Analysis/Infinite_Set_Sum.thy
author Manuel Eberl <eberlm@in.tum.de>
Tue Dec 12 10:01:14 2017 +0100 (18 months ago)
changeset 67167 88d1c9d86f48
parent 66568 52b5cf533fd6
child 67268 bdf25939a550
permissions -rw-r--r--
Moved analysis material from AFP
eberlm@66480
     1
(*  
eberlm@66480
     2
  Title:    HOL/Analysis/Infinite_Set_Sum.thy
eberlm@66480
     3
  Author:   Manuel Eberl, TU M√ľnchen
eberlm@66480
     4
eberlm@66480
     5
  A theory of sums over possible infinite sets. (Only works for absolute summability)
eberlm@66480
     6
*)
eberlm@66480
     7
section \<open>Sums over infinite sets\<close>
eberlm@66480
     8
theory Infinite_Set_Sum
eberlm@66480
     9
  imports Set_Integral
eberlm@66480
    10
begin
eberlm@66480
    11
eberlm@66480
    12
(* TODO Move *)
eberlm@66480
    13
lemma sets_eq_countable:
eberlm@66480
    14
  assumes "countable A" "space M = A" "\<And>x. x \<in> A \<Longrightarrow> {x} \<in> sets M"
eberlm@66480
    15
  shows   "sets M = Pow A"
eberlm@66480
    16
proof (intro equalityI subsetI)
eberlm@66480
    17
  fix X assume "X \<in> Pow A"
eberlm@66480
    18
  hence "(\<Union>x\<in>X. {x}) \<in> sets M"
eberlm@66480
    19
    by (intro sets.countable_UN' countable_subset[OF _ assms(1)]) (auto intro!: assms(3))
eberlm@66480
    20
  also have "(\<Union>x\<in>X. {x}) = X" by auto
eberlm@66480
    21
  finally show "X \<in> sets M" .
eberlm@66480
    22
next
eberlm@66480
    23
  fix X assume "X \<in> sets M"
eberlm@66480
    24
  from sets.sets_into_space[OF this] and assms 
eberlm@66480
    25
    show "X \<in> Pow A" by simp
eberlm@66480
    26
qed
eberlm@66480
    27
eberlm@66480
    28
lemma measure_eqI_countable':
eberlm@66480
    29
  assumes spaces: "space M = A" "space N = A" 
eberlm@66480
    30
  assumes sets: "\<And>x. x \<in> A \<Longrightarrow> {x} \<in> sets M" "\<And>x. x \<in> A \<Longrightarrow> {x} \<in> sets N"
eberlm@66480
    31
  assumes A: "countable A"
eberlm@66480
    32
  assumes eq: "\<And>a. a \<in> A \<Longrightarrow> emeasure M {a} = emeasure N {a}"
eberlm@66480
    33
  shows "M = N"
eberlm@66480
    34
proof (rule measure_eqI_countable)
eberlm@66480
    35
  show "sets M = Pow A"
eberlm@66480
    36
    by (intro sets_eq_countable assms)
eberlm@66480
    37
  show "sets N = Pow A"
eberlm@66480
    38
    by (intro sets_eq_countable assms)
eberlm@66480
    39
qed fact+
eberlm@66480
    40
eberlm@66480
    41
lemma PiE_singleton: 
eberlm@66480
    42
  assumes "f \<in> extensional A"
eberlm@66480
    43
  shows   "PiE A (\<lambda>x. {f x}) = {f}"
eberlm@66480
    44
proof -
eberlm@66480
    45
  {
eberlm@66480
    46
    fix g assume "g \<in> PiE A (\<lambda>x. {f x})"
eberlm@66480
    47
    hence "g x = f x" for x
eberlm@66480
    48
      using assms by (cases "x \<in> A") (auto simp: extensional_def)
eberlm@66480
    49
    hence "g = f" by (simp add: fun_eq_iff)
eberlm@66480
    50
  }
eberlm@66480
    51
  thus ?thesis using assms by (auto simp: extensional_def)
eberlm@66480
    52
qed
eberlm@66480
    53
eberlm@66480
    54
lemma count_space_PiM_finite:
eberlm@66480
    55
  fixes B :: "'a \<Rightarrow> 'b set"
eberlm@66480
    56
  assumes "finite A" "\<And>i. countable (B i)"
eberlm@66480
    57
  shows   "PiM A (\<lambda>i. count_space (B i)) = count_space (PiE A B)"
eberlm@66480
    58
proof (rule measure_eqI_countable')
eberlm@66480
    59
  show "space (PiM A (\<lambda>i. count_space (B i))) = PiE A B" 
eberlm@66480
    60
    by (simp add: space_PiM)
eberlm@66480
    61
  show "space (count_space (PiE A B)) = PiE A B" by simp
eberlm@66480
    62
next
eberlm@66480
    63
  fix f assume f: "f \<in> PiE A B"
eberlm@66480
    64
  hence "PiE A (\<lambda>x. {f x}) \<in> sets (Pi\<^sub>M A (\<lambda>i. count_space (B i)))"
eberlm@66480
    65
    by (intro sets_PiM_I_finite assms) auto
eberlm@66480
    66
  also from f have "PiE A (\<lambda>x. {f x}) = {f}" 
eberlm@66480
    67
    by (intro PiE_singleton) (auto simp: PiE_def)
eberlm@66480
    68
  finally show "{f} \<in> sets (Pi\<^sub>M A (\<lambda>i. count_space (B i)))" .
eberlm@66480
    69
next
eberlm@66480
    70
  interpret product_sigma_finite "(\<lambda>i. count_space (B i))"
eberlm@66480
    71
    by (intro product_sigma_finite.intro sigma_finite_measure_count_space_countable assms)
eberlm@66480
    72
  thm sigma_finite_measure_count_space
eberlm@66480
    73
  fix f assume f: "f \<in> PiE A B"
eberlm@66480
    74
  hence "{f} = PiE A (\<lambda>x. {f x})"
eberlm@66480
    75
    by (intro PiE_singleton [symmetric]) (auto simp: PiE_def)
eberlm@66480
    76
  also have "emeasure (Pi\<^sub>M A (\<lambda>i. count_space (B i))) \<dots> = 
eberlm@66480
    77
               (\<Prod>i\<in>A. emeasure (count_space (B i)) {f i})"
eberlm@66480
    78
    using f assms by (subst emeasure_PiM) auto
eberlm@66480
    79
  also have "\<dots> = (\<Prod>i\<in>A. 1)"
eberlm@66480
    80
    by (intro prod.cong refl, subst emeasure_count_space_finite) (use f in auto)
eberlm@66480
    81
  also have "\<dots> = emeasure (count_space (PiE A B)) {f}"
eberlm@66480
    82
    using f by (subst emeasure_count_space_finite) auto
eberlm@66480
    83
  finally show "emeasure (Pi\<^sub>M A (\<lambda>i. count_space (B i))) {f} =
eberlm@66480
    84
                  emeasure (count_space (Pi\<^sub>E A B)) {f}" .
eberlm@66480
    85
qed (simp_all add: countable_PiE assms)
eberlm@66480
    86
eberlm@66480
    87
eberlm@66480
    88
eberlm@66480
    89
definition abs_summable_on ::
eberlm@66480
    90
    "('a \<Rightarrow> 'b :: {banach, second_countable_topology}) \<Rightarrow> 'a set \<Rightarrow> bool" 
eberlm@66480
    91
    (infix "abs'_summable'_on" 50)
eberlm@66480
    92
 where
eberlm@66480
    93
   "f abs_summable_on A \<longleftrightarrow> integrable (count_space A) f"
eberlm@66480
    94
eberlm@66480
    95
eberlm@66480
    96
definition infsetsum ::
eberlm@66480
    97
    "('a \<Rightarrow> 'b :: {banach, second_countable_topology}) \<Rightarrow> 'a set \<Rightarrow> 'b"
eberlm@66480
    98
 where
eberlm@66480
    99
   "infsetsum f A = lebesgue_integral (count_space A) f"
eberlm@66480
   100
eberlm@66480
   101
syntax (ASCII)
eberlm@66480
   102
  "_infsetsum" :: "pttrn \<Rightarrow> 'a set \<Rightarrow> 'b \<Rightarrow> 'b::{banach, second_countable_topology}" 
eberlm@66480
   103
  ("(3INFSETSUM _:_./ _)" [0, 51, 10] 10)
eberlm@66480
   104
syntax
eberlm@66480
   105
  "_infsetsum" :: "pttrn \<Rightarrow> 'a set \<Rightarrow> 'b \<Rightarrow> 'b::{banach, second_countable_topology}" 
eberlm@66480
   106
  ("(2\<Sum>\<^sub>a_\<in>_./ _)" [0, 51, 10] 10)
eberlm@66480
   107
translations \<comment> \<open>Beware of argument permutation!\<close>
eberlm@66480
   108
  "\<Sum>\<^sub>ai\<in>A. b" \<rightleftharpoons> "CONST infsetsum (\<lambda>i. b) A"
eberlm@66480
   109
eberlm@66480
   110
syntax (ASCII)
eberlm@66526
   111
  "_uinfsetsum" :: "pttrn \<Rightarrow> 'a set \<Rightarrow> 'b \<Rightarrow> 'b::{banach, second_countable_topology}" 
eberlm@66526
   112
  ("(3INFSETSUM _:_./ _)" [0, 51, 10] 10)
eberlm@66526
   113
syntax
eberlm@66526
   114
  "_uinfsetsum" :: "pttrn \<Rightarrow> 'b \<Rightarrow> 'b::{banach, second_countable_topology}" 
eberlm@66526
   115
  ("(2\<Sum>\<^sub>a_./ _)" [0, 10] 10)
eberlm@66526
   116
translations \<comment> \<open>Beware of argument permutation!\<close>
eberlm@66526
   117
  "\<Sum>\<^sub>ai. b" \<rightleftharpoons> "CONST infsetsum (\<lambda>i. b) (CONST UNIV)"
eberlm@66526
   118
eberlm@66526
   119
syntax (ASCII)
eberlm@66480
   120
  "_qinfsetsum" :: "pttrn \<Rightarrow> bool \<Rightarrow> 'a \<Rightarrow> 'a::{banach, second_countable_topology}" 
eberlm@66480
   121
  ("(3INFSETSUM _ |/ _./ _)" [0, 0, 10] 10)
eberlm@66480
   122
syntax
eberlm@66480
   123
  "_qinfsetsum" :: "pttrn \<Rightarrow> bool \<Rightarrow> 'a \<Rightarrow> 'a::{banach, second_countable_topology}" 
eberlm@66480
   124
  ("(2\<Sum>\<^sub>a_ | (_)./ _)" [0, 0, 10] 10)
eberlm@66480
   125
translations
eberlm@66480
   126
  "\<Sum>\<^sub>ax|P. t" => "CONST infsetsum (\<lambda>x. t) {x. P}"
eberlm@66480
   127
eberlm@66480
   128
print_translation \<open>
eberlm@66480
   129
let
eberlm@66480
   130
  fun sum_tr' [Abs (x, Tx, t), Const (@{const_syntax Collect}, _) $ Abs (y, Ty, P)] =
eberlm@66480
   131
        if x <> y then raise Match
eberlm@66480
   132
        else
eberlm@66480
   133
          let
eberlm@66480
   134
            val x' = Syntax_Trans.mark_bound_body (x, Tx);
eberlm@66480
   135
            val t' = subst_bound (x', t);
eberlm@66480
   136
            val P' = subst_bound (x', P);
eberlm@66480
   137
          in
eberlm@66480
   138
            Syntax.const @{syntax_const "_qinfsetsum"} $ Syntax_Trans.mark_bound_abs (x, Tx) $ P' $ t'
eberlm@66480
   139
          end
eberlm@66480
   140
    | sum_tr' _ = raise Match;
eberlm@66480
   141
in [(@{const_syntax infsetsum}, K sum_tr')] end
eberlm@66480
   142
\<close>
eberlm@66480
   143
eberlm@66480
   144
eberlm@66480
   145
eberlm@66480
   146
eberlm@66480
   147
lemma restrict_count_space_subset:
eberlm@66480
   148
  "A \<subseteq> B \<Longrightarrow> restrict_space (count_space B) A = count_space A"
eberlm@66480
   149
  by (subst restrict_count_space) (simp_all add: Int_absorb2)
eberlm@66480
   150
eberlm@66480
   151
lemma abs_summable_on_restrict:
eberlm@66480
   152
  fixes f :: "'a \<Rightarrow> 'b :: {banach, second_countable_topology}"
eberlm@66480
   153
  assumes "A \<subseteq> B"
eberlm@66480
   154
  shows   "f abs_summable_on A \<longleftrightarrow> (\<lambda>x. indicator A x *\<^sub>R f x) abs_summable_on B"
eberlm@66480
   155
proof -
eberlm@66480
   156
  have "count_space A = restrict_space (count_space B) A"
eberlm@66480
   157
    by (rule restrict_count_space_subset [symmetric]) fact+
eberlm@66480
   158
  also have "integrable \<dots> f \<longleftrightarrow> set_integrable (count_space B) A f"
eberlm@66480
   159
    by (subst integrable_restrict_space) auto
eberlm@66480
   160
  finally show ?thesis 
eberlm@66480
   161
    unfolding abs_summable_on_def .
eberlm@66480
   162
qed
eberlm@66480
   163
eberlm@66480
   164
lemma abs_summable_on_altdef: "f abs_summable_on A \<longleftrightarrow> set_integrable (count_space UNIV) A f"
eberlm@66480
   165
  by (subst abs_summable_on_restrict[of _ UNIV]) (auto simp: abs_summable_on_def)
eberlm@66480
   166
eberlm@66480
   167
lemma abs_summable_on_altdef': 
eberlm@66480
   168
  "A \<subseteq> B \<Longrightarrow> f abs_summable_on A \<longleftrightarrow> set_integrable (count_space B) A f"
eberlm@66480
   169
  by (subst abs_summable_on_restrict[of _ B]) (auto simp: abs_summable_on_def)
eberlm@66480
   170
eberlm@66526
   171
lemma abs_summable_on_norm_iff [simp]: 
eberlm@66526
   172
  "(\<lambda>x. norm (f x)) abs_summable_on A \<longleftrightarrow> f abs_summable_on A"
eberlm@66526
   173
  by (simp add: abs_summable_on_def integrable_norm_iff)
eberlm@66526
   174
eberlm@66526
   175
lemma abs_summable_on_normI: "f abs_summable_on A \<Longrightarrow> (\<lambda>x. norm (f x)) abs_summable_on A"
eberlm@66526
   176
  by simp
eberlm@66526
   177
eberlm@66526
   178
lemma abs_summable_on_comparison_test:
eberlm@66526
   179
  assumes "g abs_summable_on A"
eberlm@66526
   180
  assumes "\<And>x. x \<in> A \<Longrightarrow> norm (f x) \<le> norm (g x)"
eberlm@66526
   181
  shows   "f abs_summable_on A"
eberlm@66526
   182
  using assms Bochner_Integration.integrable_bound[of "count_space A" g f] 
eberlm@66526
   183
  unfolding abs_summable_on_def by (auto simp: AE_count_space)  
eberlm@66526
   184
eberlm@66526
   185
lemma abs_summable_on_comparison_test':
eberlm@66526
   186
  assumes "g abs_summable_on A"
eberlm@66526
   187
  assumes "\<And>x. x \<in> A \<Longrightarrow> norm (f x) \<le> g x"
eberlm@66526
   188
  shows   "f abs_summable_on A"
eberlm@66526
   189
proof (rule abs_summable_on_comparison_test[OF assms(1), of f])
eberlm@66526
   190
  fix x assume "x \<in> A"
eberlm@66526
   191
  with assms(2) have "norm (f x) \<le> g x" .
eberlm@66526
   192
  also have "\<dots> \<le> norm (g x)" by simp
eberlm@66526
   193
  finally show "norm (f x) \<le> norm (g x)" .
eberlm@66526
   194
qed
eberlm@66526
   195
eberlm@66480
   196
lemma abs_summable_on_cong [cong]:
eberlm@66480
   197
  "(\<And>x. x \<in> A \<Longrightarrow> f x = g x) \<Longrightarrow> A = B \<Longrightarrow> (f abs_summable_on A) \<longleftrightarrow> (g abs_summable_on B)"
eberlm@66480
   198
  unfolding abs_summable_on_def by (intro integrable_cong) auto
eberlm@66480
   199
eberlm@66480
   200
lemma abs_summable_on_cong_neutral:
eberlm@66480
   201
  assumes "\<And>x. x \<in> A - B \<Longrightarrow> f x = 0"
eberlm@66480
   202
  assumes "\<And>x. x \<in> B - A \<Longrightarrow> g x = 0"
eberlm@66480
   203
  assumes "\<And>x. x \<in> A \<inter> B \<Longrightarrow> f x = g x"
eberlm@66480
   204
  shows   "f abs_summable_on A \<longleftrightarrow> g abs_summable_on B"
eberlm@66480
   205
  unfolding abs_summable_on_altdef using assms
eberlm@66480
   206
  by (intro Bochner_Integration.integrable_cong refl)
eberlm@66480
   207
     (auto simp: indicator_def split: if_splits)
eberlm@66480
   208
eberlm@66480
   209
lemma abs_summable_on_restrict':
eberlm@66480
   210
  fixes f :: "'a \<Rightarrow> 'b :: {banach, second_countable_topology}"
eberlm@66480
   211
  assumes "A \<subseteq> B"
eberlm@66480
   212
  shows   "f abs_summable_on A \<longleftrightarrow> (\<lambda>x. if x \<in> A then f x else 0) abs_summable_on B"
eberlm@66480
   213
  by (subst abs_summable_on_restrict[OF assms]) (intro abs_summable_on_cong, auto)
eberlm@66480
   214
eberlm@66480
   215
lemma abs_summable_on_nat_iff:
eberlm@66480
   216
  "f abs_summable_on (A :: nat set) \<longleftrightarrow> summable (\<lambda>n. if n \<in> A then norm (f n) else 0)"
eberlm@66480
   217
proof -
eberlm@66480
   218
  have "f abs_summable_on A \<longleftrightarrow> summable (\<lambda>x. norm (if x \<in> A then f x else 0))"
eberlm@66480
   219
    by (subst abs_summable_on_restrict'[of _ UNIV]) 
eberlm@66480
   220
       (simp_all add: abs_summable_on_def integrable_count_space_nat_iff)
eberlm@66480
   221
  also have "(\<lambda>x. norm (if x \<in> A then f x else 0)) = (\<lambda>x. if x \<in> A then norm (f x) else 0)"
eberlm@66480
   222
    by auto
eberlm@66480
   223
  finally show ?thesis .
eberlm@66480
   224
qed
eberlm@66480
   225
eberlm@66480
   226
lemma abs_summable_on_nat_iff':
eberlm@66480
   227
  "f abs_summable_on (UNIV :: nat set) \<longleftrightarrow> summable (\<lambda>n. norm (f n))"
eberlm@66480
   228
  by (subst abs_summable_on_nat_iff) auto
eberlm@66480
   229
eberlm@66480
   230
lemma abs_summable_on_finite [simp]: "finite A \<Longrightarrow> f abs_summable_on A"
eberlm@66480
   231
  unfolding abs_summable_on_def by (rule integrable_count_space)
eberlm@66480
   232
eberlm@66480
   233
lemma abs_summable_on_empty [simp, intro]: "f abs_summable_on {}"
eberlm@66480
   234
  by simp
eberlm@66480
   235
eberlm@66480
   236
lemma abs_summable_on_subset:
eberlm@66480
   237
  assumes "f abs_summable_on B" and "A \<subseteq> B"
eberlm@66480
   238
  shows   "f abs_summable_on A"
eberlm@66480
   239
  unfolding abs_summable_on_altdef
eberlm@66480
   240
  by (rule set_integrable_subset) (insert assms, auto simp: abs_summable_on_altdef)
eberlm@66480
   241
eberlm@66480
   242
lemma abs_summable_on_union [intro]:
eberlm@66480
   243
  assumes "f abs_summable_on A" and "f abs_summable_on B"
eberlm@66480
   244
  shows   "f abs_summable_on (A \<union> B)"
eberlm@66480
   245
  using assms unfolding abs_summable_on_altdef by (intro set_integrable_Un) auto
eberlm@66480
   246
eberlm@66526
   247
lemma abs_summable_on_insert_iff [simp]:
eberlm@66526
   248
  "f abs_summable_on insert x A \<longleftrightarrow> f abs_summable_on A"
eberlm@66526
   249
proof safe
eberlm@66526
   250
  assume "f abs_summable_on insert x A"
eberlm@66526
   251
  thus "f abs_summable_on A"
eberlm@66526
   252
    by (rule abs_summable_on_subset) auto
eberlm@66526
   253
next
eberlm@66526
   254
  assume "f abs_summable_on A"
eberlm@66526
   255
  from abs_summable_on_union[OF this, of "{x}"]
eberlm@66526
   256
    show "f abs_summable_on insert x A" by simp
eberlm@66526
   257
qed
eberlm@66526
   258
eberlm@67167
   259
lemma abs_summable_sum: 
eberlm@67167
   260
  assumes "\<And>x. x \<in> A \<Longrightarrow> f x abs_summable_on B"
eberlm@67167
   261
  shows   "(\<lambda>y. \<Sum>x\<in>A. f x y) abs_summable_on B"
eberlm@67167
   262
  using assms unfolding abs_summable_on_def by (intro Bochner_Integration.integrable_sum)
eberlm@67167
   263
eberlm@67167
   264
lemma abs_summable_Re: "f abs_summable_on A \<Longrightarrow> (\<lambda>x. Re (f x)) abs_summable_on A"
eberlm@67167
   265
  by (simp add: abs_summable_on_def)
eberlm@67167
   266
eberlm@67167
   267
lemma abs_summable_Im: "f abs_summable_on A \<Longrightarrow> (\<lambda>x. Im (f x)) abs_summable_on A"
eberlm@67167
   268
  by (simp add: abs_summable_on_def)
eberlm@67167
   269
eberlm@67167
   270
lemma abs_summable_on_finite_diff:
eberlm@67167
   271
  assumes "f abs_summable_on A" "A \<subseteq> B" "finite (B - A)"
eberlm@67167
   272
  shows   "f abs_summable_on B"
eberlm@67167
   273
proof -
eberlm@67167
   274
  have "f abs_summable_on (A \<union> (B - A))"
eberlm@67167
   275
    by (intro abs_summable_on_union assms abs_summable_on_finite)
eberlm@67167
   276
  also from assms have "A \<union> (B - A) = B" by blast
eberlm@67167
   277
  finally show ?thesis .
eberlm@67167
   278
qed
eberlm@67167
   279
eberlm@66480
   280
lemma abs_summable_on_reindex_bij_betw:
eberlm@66480
   281
  assumes "bij_betw g A B"
eberlm@66480
   282
  shows   "(\<lambda>x. f (g x)) abs_summable_on A \<longleftrightarrow> f abs_summable_on B"
eberlm@66480
   283
proof -
eberlm@66480
   284
  have *: "count_space B = distr (count_space A) (count_space B) g"
eberlm@66480
   285
    by (rule distr_bij_count_space [symmetric]) fact
eberlm@66480
   286
  show ?thesis unfolding abs_summable_on_def
eberlm@66480
   287
    by (subst *, subst integrable_distr_eq[of _ _ "count_space B"]) 
eberlm@66480
   288
       (insert assms, auto simp: bij_betw_def)
eberlm@66480
   289
qed
eberlm@66480
   290
eberlm@66480
   291
lemma abs_summable_on_reindex:
eberlm@66480
   292
  assumes "(\<lambda>x. f (g x)) abs_summable_on A"
eberlm@66480
   293
  shows   "f abs_summable_on (g ` A)"
eberlm@66480
   294
proof -
eberlm@66480
   295
  define g' where "g' = inv_into A g"
eberlm@66480
   296
  from assms have "(\<lambda>x. f (g x)) abs_summable_on (g' ` g ` A)" 
eberlm@66480
   297
    by (rule abs_summable_on_subset) (auto simp: g'_def inv_into_into)
eberlm@66480
   298
  also have "?this \<longleftrightarrow> (\<lambda>x. f (g (g' x))) abs_summable_on (g ` A)" unfolding g'_def
eberlm@66480
   299
    by (intro abs_summable_on_reindex_bij_betw [symmetric] inj_on_imp_bij_betw inj_on_inv_into) auto
eberlm@66480
   300
  also have "\<dots> \<longleftrightarrow> f abs_summable_on (g ` A)"
eberlm@66480
   301
    by (intro abs_summable_on_cong refl) (auto simp: g'_def f_inv_into_f)
eberlm@66480
   302
  finally show ?thesis .
eberlm@66480
   303
qed
eberlm@66480
   304
eberlm@66526
   305
lemma abs_summable_on_reindex_iff: 
eberlm@66480
   306
  "inj_on g A \<Longrightarrow> (\<lambda>x. f (g x)) abs_summable_on A \<longleftrightarrow> f abs_summable_on (g ` A)"
eberlm@66480
   307
  by (intro abs_summable_on_reindex_bij_betw inj_on_imp_bij_betw)
eberlm@66480
   308
eberlm@66526
   309
lemma abs_summable_on_Sigma_project2:
eberlm@66480
   310
  fixes A :: "'a set" and B :: "'a \<Rightarrow> 'b set"
eberlm@66480
   311
  assumes "f abs_summable_on (Sigma A B)" "x \<in> A"
eberlm@66480
   312
  shows   "(\<lambda>y. f (x, y)) abs_summable_on (B x)"
eberlm@66480
   313
proof -
eberlm@66480
   314
  from assms(2) have "f abs_summable_on (Sigma {x} B)"
eberlm@66480
   315
    by (intro abs_summable_on_subset [OF assms(1)]) auto
eberlm@66480
   316
  also have "?this \<longleftrightarrow> (\<lambda>z. f (x, snd z)) abs_summable_on (Sigma {x} B)"
eberlm@66480
   317
    by (rule abs_summable_on_cong) auto
eberlm@66480
   318
  finally have "(\<lambda>y. f (x, y)) abs_summable_on (snd ` Sigma {x} B)"
eberlm@66480
   319
    by (rule abs_summable_on_reindex)
eberlm@66480
   320
  also have "snd ` Sigma {x} B = B x"
eberlm@66480
   321
    using assms by (auto simp: image_iff)
eberlm@66480
   322
  finally show ?thesis .
eberlm@66480
   323
qed
eberlm@66480
   324
eberlm@66480
   325
lemma abs_summable_on_Times_swap:
eberlm@66480
   326
  "f abs_summable_on A \<times> B \<longleftrightarrow> (\<lambda>(x,y). f (y,x)) abs_summable_on B \<times> A"
eberlm@66480
   327
proof -
eberlm@66480
   328
  have bij: "bij_betw (\<lambda>(x,y). (y,x)) (B \<times> A) (A \<times> B)"
eberlm@66480
   329
    by (auto simp: bij_betw_def inj_on_def)
eberlm@66480
   330
  show ?thesis
eberlm@66480
   331
    by (subst abs_summable_on_reindex_bij_betw[OF bij, of f, symmetric])
eberlm@66480
   332
       (simp_all add: case_prod_unfold)
eberlm@66480
   333
qed
eberlm@66480
   334
eberlm@66480
   335
lemma abs_summable_on_0 [simp, intro]: "(\<lambda>_. 0) abs_summable_on A"
eberlm@66480
   336
  by (simp add: abs_summable_on_def)
eberlm@66480
   337
eberlm@66480
   338
lemma abs_summable_on_uminus [intro]:
eberlm@66480
   339
  "f abs_summable_on A \<Longrightarrow> (\<lambda>x. -f x) abs_summable_on A"
eberlm@66480
   340
  unfolding abs_summable_on_def by (rule Bochner_Integration.integrable_minus)
eberlm@66480
   341
eberlm@66480
   342
lemma abs_summable_on_add [intro]:
eberlm@66480
   343
  assumes "f abs_summable_on A" and "g abs_summable_on A"
eberlm@66480
   344
  shows   "(\<lambda>x. f x + g x) abs_summable_on A"
eberlm@66480
   345
  using assms unfolding abs_summable_on_def by (rule Bochner_Integration.integrable_add)
eberlm@66480
   346
eberlm@66480
   347
lemma abs_summable_on_diff [intro]:
eberlm@66480
   348
  assumes "f abs_summable_on A" and "g abs_summable_on A"
eberlm@66480
   349
  shows   "(\<lambda>x. f x - g x) abs_summable_on A"
eberlm@66480
   350
  using assms unfolding abs_summable_on_def by (rule Bochner_Integration.integrable_diff)
eberlm@66480
   351
eberlm@66480
   352
lemma abs_summable_on_scaleR_left [intro]:
eberlm@66480
   353
  assumes "c \<noteq> 0 \<Longrightarrow> f abs_summable_on A"
eberlm@66480
   354
  shows   "(\<lambda>x. f x *\<^sub>R c) abs_summable_on A"
eberlm@66480
   355
  using assms unfolding abs_summable_on_def by (intro Bochner_Integration.integrable_scaleR_left)
eberlm@66480
   356
eberlm@66480
   357
lemma abs_summable_on_scaleR_right [intro]:
eberlm@66480
   358
  assumes "c \<noteq> 0 \<Longrightarrow> f abs_summable_on A"
eberlm@66480
   359
  shows   "(\<lambda>x. c *\<^sub>R f x) abs_summable_on A"
eberlm@66480
   360
  using assms unfolding abs_summable_on_def by (intro Bochner_Integration.integrable_scaleR_right)
eberlm@66480
   361
eberlm@66480
   362
lemma abs_summable_on_cmult_right [intro]:
eberlm@66480
   363
  fixes f :: "'a \<Rightarrow> 'b :: {banach, real_normed_algebra, second_countable_topology}"
eberlm@66480
   364
  assumes "c \<noteq> 0 \<Longrightarrow> f abs_summable_on A"
eberlm@66480
   365
  shows   "(\<lambda>x. c * f x) abs_summable_on A"
eberlm@66480
   366
  using assms unfolding abs_summable_on_def by (intro Bochner_Integration.integrable_mult_right)
eberlm@66480
   367
eberlm@66480
   368
lemma abs_summable_on_cmult_left [intro]:
eberlm@66480
   369
  fixes f :: "'a \<Rightarrow> 'b :: {banach, real_normed_algebra, second_countable_topology}"
eberlm@66480
   370
  assumes "c \<noteq> 0 \<Longrightarrow> f abs_summable_on A"
eberlm@66480
   371
  shows   "(\<lambda>x. f x * c) abs_summable_on A"
eberlm@66480
   372
  using assms unfolding abs_summable_on_def by (intro Bochner_Integration.integrable_mult_left)
eberlm@66480
   373
eberlm@66568
   374
lemma abs_summable_on_prod_PiE:
eberlm@66568
   375
  fixes f :: "'a \<Rightarrow> 'b \<Rightarrow> 'c :: {real_normed_field,banach,second_countable_topology}"
eberlm@66568
   376
  assumes finite: "finite A" and countable: "\<And>x. x \<in> A \<Longrightarrow> countable (B x)"
eberlm@66568
   377
  assumes summable: "\<And>x. x \<in> A \<Longrightarrow> f x abs_summable_on B x"
eberlm@66568
   378
  shows   "(\<lambda>g. \<Prod>x\<in>A. f x (g x)) abs_summable_on PiE A B"
eberlm@66568
   379
proof -
eberlm@66568
   380
  define B' where "B' = (\<lambda>x. if x \<in> A then B x else {})"
eberlm@66568
   381
  from assms have [simp]: "countable (B' x)" for x
eberlm@66568
   382
    by (auto simp: B'_def)
eberlm@66568
   383
  then interpret product_sigma_finite "count_space \<circ> B'"
eberlm@66568
   384
    unfolding o_def by (intro product_sigma_finite.intro sigma_finite_measure_count_space_countable)
eberlm@66568
   385
  from assms have "integrable (PiM A (count_space \<circ> B')) (\<lambda>g. \<Prod>x\<in>A. f x (g x))"
eberlm@66568
   386
    by (intro product_integrable_prod) (auto simp: abs_summable_on_def B'_def)
eberlm@66568
   387
  also have "PiM A (count_space \<circ> B') = count_space (PiE A B')"
eberlm@66568
   388
    unfolding o_def using finite by (intro count_space_PiM_finite) simp_all
eberlm@66568
   389
  also have "PiE A B' = PiE A B" by (intro PiE_cong) (simp_all add: B'_def)
eberlm@66568
   390
  finally show ?thesis by (simp add: abs_summable_on_def)
eberlm@66568
   391
qed
eberlm@66568
   392
eberlm@66480
   393
eberlm@66480
   394
eberlm@66480
   395
lemma not_summable_infsetsum_eq:
eberlm@66480
   396
  "\<not>f abs_summable_on A \<Longrightarrow> infsetsum f A = 0"
eberlm@66480
   397
  by (simp add: abs_summable_on_def infsetsum_def not_integrable_integral_eq)
eberlm@66480
   398
eberlm@66480
   399
lemma infsetsum_altdef:
eberlm@66480
   400
  "infsetsum f A = set_lebesgue_integral (count_space UNIV) A f"
eberlm@66480
   401
  by (subst integral_restrict_space [symmetric])
eberlm@66480
   402
     (auto simp: restrict_count_space_subset infsetsum_def)
eberlm@66480
   403
eberlm@66480
   404
lemma infsetsum_altdef':
eberlm@66480
   405
  "A \<subseteq> B \<Longrightarrow> infsetsum f A = set_lebesgue_integral (count_space B) A f"
eberlm@66480
   406
  by (subst integral_restrict_space [symmetric])
eberlm@66480
   407
     (auto simp: restrict_count_space_subset infsetsum_def)
eberlm@66480
   408
eberlm@66568
   409
lemma nn_integral_conv_infsetsum:
eberlm@66568
   410
  assumes "f abs_summable_on A" "\<And>x. x \<in> A \<Longrightarrow> f x \<ge> 0"
eberlm@66568
   411
  shows   "nn_integral (count_space A) f = ennreal (infsetsum f A)"
eberlm@66568
   412
  using assms unfolding infsetsum_def abs_summable_on_def
eberlm@66568
   413
  by (subst nn_integral_eq_integral) auto
eberlm@66568
   414
eberlm@66568
   415
lemma infsetsum_conv_nn_integral:
eberlm@66568
   416
  assumes "nn_integral (count_space A) f \<noteq> \<infinity>" "\<And>x. x \<in> A \<Longrightarrow> f x \<ge> 0"
eberlm@66568
   417
  shows   "infsetsum f A = enn2real (nn_integral (count_space A) f)"
eberlm@66568
   418
  unfolding infsetsum_def using assms
eberlm@66568
   419
  by (subst integral_eq_nn_integral) auto
eberlm@66568
   420
eberlm@66480
   421
lemma infsetsum_cong [cong]:
eberlm@66480
   422
  "(\<And>x. x \<in> A \<Longrightarrow> f x = g x) \<Longrightarrow> A = B \<Longrightarrow> infsetsum f A = infsetsum g B"
eberlm@66480
   423
  unfolding infsetsum_def by (intro Bochner_Integration.integral_cong) auto
eberlm@66480
   424
eberlm@66480
   425
lemma infsetsum_0 [simp]: "infsetsum (\<lambda>_. 0) A = 0"
eberlm@66480
   426
  by (simp add: infsetsum_def)
eberlm@66480
   427
eberlm@66480
   428
lemma infsetsum_all_0: "(\<And>x. x \<in> A \<Longrightarrow> f x = 0) \<Longrightarrow> infsetsum f A = 0"
eberlm@66480
   429
  by simp
eberlm@66480
   430
eberlm@67167
   431
lemma infsetsum_nonneg: "(\<And>x. x \<in> A \<Longrightarrow> f x \<ge> (0::real)) \<Longrightarrow> infsetsum f A \<ge> 0"
eberlm@67167
   432
  unfolding infsetsum_def by (rule Bochner_Integration.integral_nonneg) auto
eberlm@67167
   433
eberlm@67167
   434
lemma sum_infsetsum:
eberlm@67167
   435
  assumes "\<And>x. x \<in> A \<Longrightarrow> f x abs_summable_on B"
eberlm@67167
   436
  shows   "(\<Sum>x\<in>A. \<Sum>\<^sub>ay\<in>B. f x y) = (\<Sum>\<^sub>ay\<in>B. \<Sum>x\<in>A. f x y)"
eberlm@67167
   437
  using assms by (simp add: infsetsum_def abs_summable_on_def Bochner_Integration.integral_sum)
eberlm@67167
   438
eberlm@67167
   439
lemma Re_infsetsum: "f abs_summable_on A \<Longrightarrow> Re (infsetsum f A) = (\<Sum>\<^sub>ax\<in>A. Re (f x))"
eberlm@67167
   440
  by (simp add: infsetsum_def abs_summable_on_def)
eberlm@67167
   441
eberlm@67167
   442
lemma Im_infsetsum: "f abs_summable_on A \<Longrightarrow> Im (infsetsum f A) = (\<Sum>\<^sub>ax\<in>A. Im (f x))"
eberlm@67167
   443
  by (simp add: infsetsum_def abs_summable_on_def)
eberlm@67167
   444
eberlm@67167
   445
lemma infsetsum_of_real: 
eberlm@67167
   446
  shows "infsetsum (\<lambda>x. of_real (f x) 
eberlm@67167
   447
           :: 'a :: {real_normed_algebra_1,banach,second_countable_topology,real_inner}) A = 
eberlm@67167
   448
             of_real (infsetsum f A)"
eberlm@67167
   449
  unfolding infsetsum_def
eberlm@67167
   450
  by (rule integral_bounded_linear'[OF bounded_linear_of_real bounded_linear_inner_left[of 1]]) auto
eberlm@67167
   451
eberlm@66480
   452
lemma infsetsum_finite [simp]: "finite A \<Longrightarrow> infsetsum f A = (\<Sum>x\<in>A. f x)"
eberlm@66480
   453
  by (simp add: infsetsum_def lebesgue_integral_count_space_finite)
eberlm@66480
   454
eberlm@66480
   455
lemma infsetsum_nat: 
eberlm@66480
   456
  assumes "f abs_summable_on A"
eberlm@66480
   457
  shows   "infsetsum f A = (\<Sum>n. if n \<in> A then f n else 0)"
eberlm@66480
   458
proof -
eberlm@66480
   459
  from assms have "infsetsum f A = (\<Sum>n. indicator A n *\<^sub>R f n)"
eberlm@66480
   460
    unfolding infsetsum_altdef abs_summable_on_altdef by (subst integral_count_space_nat) auto
eberlm@66480
   461
  also have "(\<lambda>n. indicator A n *\<^sub>R f n) = (\<lambda>n. if n \<in> A then f n else 0)"
eberlm@66480
   462
    by auto
eberlm@66480
   463
  finally show ?thesis .
eberlm@66480
   464
qed
eberlm@66480
   465
eberlm@66480
   466
lemma infsetsum_nat': 
eberlm@66480
   467
  assumes "f abs_summable_on UNIV"
eberlm@66480
   468
  shows   "infsetsum f UNIV = (\<Sum>n. f n)"
eberlm@66480
   469
  using assms by (subst infsetsum_nat) auto
eberlm@66480
   470
eberlm@66480
   471
lemma sums_infsetsum_nat:
eberlm@66480
   472
  assumes "f abs_summable_on A"
eberlm@66480
   473
  shows   "(\<lambda>n. if n \<in> A then f n else 0) sums infsetsum f A"
eberlm@66480
   474
proof -
eberlm@66480
   475
  from assms have "summable (\<lambda>n. if n \<in> A then norm (f n) else 0)"
eberlm@66480
   476
    by (simp add: abs_summable_on_nat_iff)
eberlm@66480
   477
  also have "(\<lambda>n. if n \<in> A then norm (f n) else 0) = (\<lambda>n. norm (if n \<in> A then f n else 0))"
eberlm@66480
   478
    by auto
eberlm@66480
   479
  finally have "summable (\<lambda>n. if n \<in> A then f n else 0)"
eberlm@66480
   480
    by (rule summable_norm_cancel)
eberlm@66480
   481
  with assms show ?thesis
eberlm@66480
   482
    by (auto simp: sums_iff infsetsum_nat)
eberlm@66480
   483
qed
eberlm@66480
   484
eberlm@66480
   485
lemma sums_infsetsum_nat':
eberlm@66480
   486
  assumes "f abs_summable_on UNIV"
eberlm@66480
   487
  shows   "f sums infsetsum f UNIV"
eberlm@66480
   488
  using sums_infsetsum_nat [OF assms] by simp
eberlm@66480
   489
eberlm@66480
   490
lemma infsetsum_Un_disjoint:
eberlm@66480
   491
  assumes "f abs_summable_on A" "f abs_summable_on B" "A \<inter> B = {}"
eberlm@66480
   492
  shows   "infsetsum f (A \<union> B) = infsetsum f A + infsetsum f B"
eberlm@66480
   493
  using assms unfolding infsetsum_altdef abs_summable_on_altdef
eberlm@66480
   494
  by (subst set_integral_Un) auto
eberlm@66480
   495
eberlm@66480
   496
lemma infsetsum_Diff:
eberlm@66480
   497
  assumes "f abs_summable_on B" "A \<subseteq> B"
eberlm@66480
   498
  shows   "infsetsum f (B - A) = infsetsum f B - infsetsum f A"
eberlm@66480
   499
proof -
eberlm@66480
   500
  have "infsetsum f ((B - A) \<union> A) = infsetsum f (B - A) + infsetsum f A"
eberlm@66480
   501
    using assms(2) by (intro infsetsum_Un_disjoint abs_summable_on_subset[OF assms(1)]) auto
eberlm@66480
   502
  also from assms(2) have "(B - A) \<union> A = B"
eberlm@66480
   503
    by auto
eberlm@66480
   504
  ultimately show ?thesis
eberlm@66480
   505
    by (simp add: algebra_simps)
eberlm@66480
   506
qed
eberlm@66480
   507
eberlm@66480
   508
lemma infsetsum_Un_Int:
eberlm@66480
   509
  assumes "f abs_summable_on (A \<union> B)"
eberlm@66480
   510
  shows   "infsetsum f (A \<union> B) = infsetsum f A + infsetsum f B - infsetsum f (A \<inter> B)"
eberlm@66480
   511
proof -
eberlm@66480
   512
  have "A \<union> B = A \<union> (B - A \<inter> B)"
eberlm@66480
   513
    by auto
eberlm@66480
   514
  also have "infsetsum f \<dots> = infsetsum f A + infsetsum f (B - A \<inter> B)"
eberlm@66480
   515
    by (intro infsetsum_Un_disjoint abs_summable_on_subset[OF assms]) auto
eberlm@66480
   516
  also have "infsetsum f (B - A \<inter> B) = infsetsum f B - infsetsum f (A \<inter> B)"
eberlm@66480
   517
    by (intro infsetsum_Diff abs_summable_on_subset[OF assms]) auto
eberlm@66480
   518
  finally show ?thesis 
eberlm@66480
   519
    by (simp add: algebra_simps)
eberlm@66480
   520
qed
eberlm@66480
   521
eberlm@66480
   522
lemma infsetsum_reindex_bij_betw:
eberlm@66480
   523
  assumes "bij_betw g A B"
eberlm@66480
   524
  shows   "infsetsum (\<lambda>x. f (g x)) A = infsetsum f B"
eberlm@66480
   525
proof -
eberlm@66480
   526
  have *: "count_space B = distr (count_space A) (count_space B) g"
eberlm@66480
   527
    by (rule distr_bij_count_space [symmetric]) fact
eberlm@66480
   528
  show ?thesis unfolding infsetsum_def
eberlm@66480
   529
    by (subst *, subst integral_distr[of _ _ "count_space B"]) 
eberlm@66480
   530
       (insert assms, auto simp: bij_betw_def)    
eberlm@66480
   531
qed
eberlm@66480
   532
eberlm@66480
   533
lemma infsetsum_reindex:
eberlm@66480
   534
  assumes "inj_on g A"
eberlm@66480
   535
  shows   "infsetsum f (g ` A) = infsetsum (\<lambda>x. f (g x)) A"
eberlm@66480
   536
  by (intro infsetsum_reindex_bij_betw [symmetric] inj_on_imp_bij_betw assms)
eberlm@66480
   537
eberlm@66480
   538
lemma infsetsum_cong_neutral:
eberlm@66480
   539
  assumes "\<And>x. x \<in> A - B \<Longrightarrow> f x = 0"
eberlm@66480
   540
  assumes "\<And>x. x \<in> B - A \<Longrightarrow> g x = 0"
eberlm@66480
   541
  assumes "\<And>x. x \<in> A \<inter> B \<Longrightarrow> f x = g x"
eberlm@66480
   542
  shows   "infsetsum f A = infsetsum g B"
eberlm@66480
   543
  unfolding infsetsum_altdef using assms
eberlm@66480
   544
  by (intro Bochner_Integration.integral_cong refl)
eberlm@66480
   545
     (auto simp: indicator_def split: if_splits)
eberlm@66480
   546
eberlm@66526
   547
lemma infsetsum_mono_neutral:
eberlm@66526
   548
  fixes f g :: "'a \<Rightarrow> real"
eberlm@66526
   549
  assumes "f abs_summable_on A" and "g abs_summable_on B"
eberlm@66526
   550
  assumes "\<And>x. x \<in> A \<Longrightarrow> f x \<le> g x"
eberlm@66526
   551
  assumes "\<And>x. x \<in> A - B \<Longrightarrow> f x \<le> 0"
eberlm@66526
   552
  assumes "\<And>x. x \<in> B - A \<Longrightarrow> g x \<ge> 0"
eberlm@66526
   553
  shows   "infsetsum f A \<le> infsetsum g B"
eberlm@66526
   554
  using assms unfolding infsetsum_altdef abs_summable_on_altdef
eberlm@66526
   555
  by (intro Bochner_Integration.integral_mono) (auto simp: indicator_def)
eberlm@66526
   556
eberlm@66526
   557
lemma infsetsum_mono_neutral_left:
eberlm@66526
   558
  fixes f g :: "'a \<Rightarrow> real"
eberlm@66526
   559
  assumes "f abs_summable_on A" and "g abs_summable_on B"
eberlm@66526
   560
  assumes "\<And>x. x \<in> A \<Longrightarrow> f x \<le> g x"
eberlm@66526
   561
  assumes "A \<subseteq> B"
eberlm@66526
   562
  assumes "\<And>x. x \<in> B - A \<Longrightarrow> g x \<ge> 0"
eberlm@66526
   563
  shows   "infsetsum f A \<le> infsetsum g B"
eberlm@66526
   564
  using \<open>A \<subseteq> B\<close> by (intro infsetsum_mono_neutral assms) auto
eberlm@66526
   565
eberlm@66526
   566
lemma infsetsum_mono_neutral_right:
eberlm@66526
   567
  fixes f g :: "'a \<Rightarrow> real"
eberlm@66526
   568
  assumes "f abs_summable_on A" and "g abs_summable_on B"
eberlm@66526
   569
  assumes "\<And>x. x \<in> A \<Longrightarrow> f x \<le> g x"
eberlm@66526
   570
  assumes "B \<subseteq> A"
eberlm@66526
   571
  assumes "\<And>x. x \<in> A - B \<Longrightarrow> f x \<le> 0"
eberlm@66526
   572
  shows   "infsetsum f A \<le> infsetsum g B"
eberlm@66526
   573
  using \<open>B \<subseteq> A\<close> by (intro infsetsum_mono_neutral assms) auto
eberlm@66526
   574
eberlm@66526
   575
lemma infsetsum_mono:
eberlm@66526
   576
  fixes f g :: "'a \<Rightarrow> real"
eberlm@66526
   577
  assumes "f abs_summable_on A" and "g abs_summable_on A"
eberlm@66526
   578
  assumes "\<And>x. x \<in> A \<Longrightarrow> f x \<le> g x"
eberlm@66526
   579
  shows   "infsetsum f A \<le> infsetsum g A"
eberlm@66526
   580
  by (intro infsetsum_mono_neutral assms) auto
eberlm@66526
   581
eberlm@66526
   582
lemma norm_infsetsum_bound:
eberlm@66526
   583
  "norm (infsetsum f A) \<le> infsetsum (\<lambda>x. norm (f x)) A"
eberlm@66526
   584
  unfolding abs_summable_on_def infsetsum_def
eberlm@66526
   585
  by (rule Bochner_Integration.integral_norm_bound)
eberlm@66526
   586
eberlm@66480
   587
lemma infsetsum_Sigma:
eberlm@66480
   588
  fixes A :: "'a set" and B :: "'a \<Rightarrow> 'b set"
eberlm@66480
   589
  assumes [simp]: "countable A" and "\<And>i. countable (B i)"
eberlm@66480
   590
  assumes summable: "f abs_summable_on (Sigma A B)"
eberlm@66480
   591
  shows   "infsetsum f (Sigma A B) = infsetsum (\<lambda>x. infsetsum (\<lambda>y. f (x, y)) (B x)) A"
eberlm@66480
   592
proof -
eberlm@66480
   593
  define B' where "B' = (\<Union>i\<in>A. B i)"
eberlm@66480
   594
  have [simp]: "countable B'" 
eberlm@66480
   595
    unfolding B'_def by (intro countable_UN assms)
eberlm@66480
   596
  interpret pair_sigma_finite "count_space A" "count_space B'"
eberlm@66480
   597
    by (intro pair_sigma_finite.intro sigma_finite_measure_count_space_countable) fact+
eberlm@66480
   598
eberlm@66480
   599
  have "integrable (count_space (A \<times> B')) (\<lambda>z. indicator (Sigma A B) z *\<^sub>R f z)"
eberlm@66480
   600
    using summable by (subst abs_summable_on_altdef' [symmetric]) (auto simp: B'_def)
eberlm@66480
   601
  also have "?this \<longleftrightarrow> integrable (count_space A \<Otimes>\<^sub>M count_space B') (\<lambda>(x, y). indicator (B x) y *\<^sub>R f (x, y))"
eberlm@66480
   602
    by (intro Bochner_Integration.integrable_cong)
eberlm@66480
   603
       (auto simp: pair_measure_countable indicator_def split: if_splits)
eberlm@66480
   604
  finally have integrable: \<dots> .
eberlm@66480
   605
  
eberlm@66480
   606
  have "infsetsum (\<lambda>x. infsetsum (\<lambda>y. f (x, y)) (B x)) A =
eberlm@66480
   607
          (\<integral>x. infsetsum (\<lambda>y. f (x, y)) (B x) \<partial>count_space A)"
eberlm@66480
   608
    unfolding infsetsum_def by simp
eberlm@66480
   609
  also have "\<dots> = (\<integral>x. \<integral>y. indicator (B x) y *\<^sub>R f (x, y) \<partial>count_space B' \<partial>count_space A)"
eberlm@66480
   610
    by (intro Bochner_Integration.integral_cong infsetsum_altdef'[of _ B'] refl)
eberlm@66480
   611
       (auto simp: B'_def)
eberlm@66480
   612
  also have "\<dots> = (\<integral>(x,y). indicator (B x) y *\<^sub>R f (x, y) \<partial>(count_space A \<Otimes>\<^sub>M count_space B'))"
eberlm@66480
   613
    by (subst integral_fst [OF integrable]) auto
eberlm@66480
   614
  also have "\<dots> = (\<integral>z. indicator (Sigma A B) z *\<^sub>R f z \<partial>count_space (A \<times> B'))"
eberlm@66480
   615
    by (intro Bochner_Integration.integral_cong)
eberlm@66480
   616
       (auto simp: pair_measure_countable indicator_def split: if_splits)
eberlm@66480
   617
  also have "\<dots> = infsetsum f (Sigma A B)"
eberlm@66480
   618
    by (rule infsetsum_altdef' [symmetric]) (auto simp: B'_def)
eberlm@66480
   619
  finally show ?thesis ..
eberlm@66480
   620
qed
eberlm@66480
   621
eberlm@66526
   622
lemma infsetsum_Sigma':
eberlm@66526
   623
  fixes A :: "'a set" and B :: "'a \<Rightarrow> 'b set"
eberlm@66526
   624
  assumes [simp]: "countable A" and "\<And>i. countable (B i)"
eberlm@66526
   625
  assumes summable: "(\<lambda>(x,y). f x y) abs_summable_on (Sigma A B)"
eberlm@66526
   626
  shows   "infsetsum (\<lambda>x. infsetsum (\<lambda>y. f x y) (B x)) A = infsetsum (\<lambda>(x,y). f x y) (Sigma A B)"
eberlm@66526
   627
  using assms by (subst infsetsum_Sigma) auto
eberlm@66526
   628
eberlm@66480
   629
lemma infsetsum_Times:
eberlm@66480
   630
  fixes A :: "'a set" and B :: "'b set"
eberlm@66480
   631
  assumes [simp]: "countable A" and "countable B"
eberlm@66480
   632
  assumes summable: "f abs_summable_on (A \<times> B)"
eberlm@66480
   633
  shows   "infsetsum f (A \<times> B) = infsetsum (\<lambda>x. infsetsum (\<lambda>y. f (x, y)) B) A"
eberlm@66480
   634
  using assms by (subst infsetsum_Sigma) auto
eberlm@66480
   635
eberlm@66480
   636
lemma infsetsum_Times':
eberlm@66480
   637
  fixes A :: "'a set" and B :: "'b set"
eberlm@66480
   638
  fixes f :: "'a \<Rightarrow> 'b \<Rightarrow> 'c :: {banach, second_countable_topology}"
eberlm@66480
   639
  assumes [simp]: "countable A" and [simp]: "countable B"
eberlm@66480
   640
  assumes summable: "(\<lambda>(x,y). f x y) abs_summable_on (A \<times> B)"
eberlm@66480
   641
  shows   "infsetsum (\<lambda>x. infsetsum (\<lambda>y. f x y) B) A = infsetsum (\<lambda>(x,y). f x y) (A \<times> B)"
eberlm@66480
   642
  using assms by (subst infsetsum_Times) auto
eberlm@66480
   643
eberlm@66480
   644
lemma infsetsum_swap:
eberlm@66480
   645
  fixes A :: "'a set" and B :: "'b set"
eberlm@66480
   646
  fixes f :: "'a \<Rightarrow> 'b \<Rightarrow> 'c :: {banach, second_countable_topology}"
eberlm@66480
   647
  assumes [simp]: "countable A" and [simp]: "countable B"
eberlm@66480
   648
  assumes summable: "(\<lambda>(x,y). f x y) abs_summable_on A \<times> B"
eberlm@66480
   649
  shows   "infsetsum (\<lambda>x. infsetsum (\<lambda>y. f x y) B) A = infsetsum (\<lambda>y. infsetsum (\<lambda>x. f x y) A) B"
eberlm@66480
   650
proof -
eberlm@66480
   651
  from summable have summable': "(\<lambda>(x,y). f y x) abs_summable_on B \<times> A"
eberlm@66480
   652
    by (subst abs_summable_on_Times_swap) auto
eberlm@66480
   653
  have bij: "bij_betw (\<lambda>(x, y). (y, x)) (B \<times> A) (A \<times> B)"
eberlm@66480
   654
    by (auto simp: bij_betw_def inj_on_def)
eberlm@66480
   655
  have "infsetsum (\<lambda>x. infsetsum (\<lambda>y. f x y) B) A = infsetsum (\<lambda>(x,y). f x y) (A \<times> B)"
eberlm@66480
   656
    using summable by (subst infsetsum_Times) auto
eberlm@66480
   657
  also have "\<dots> = infsetsum (\<lambda>(x,y). f y x) (B \<times> A)"
eberlm@66480
   658
    by (subst infsetsum_reindex_bij_betw[OF bij, of "\<lambda>(x,y). f x y", symmetric])
eberlm@66480
   659
       (simp_all add: case_prod_unfold)
eberlm@66480
   660
  also have "\<dots> = infsetsum (\<lambda>y. infsetsum (\<lambda>x. f x y) A) B"
eberlm@66480
   661
    using summable' by (subst infsetsum_Times) auto
eberlm@66480
   662
  finally show ?thesis .
eberlm@66480
   663
qed
eberlm@66480
   664
eberlm@66526
   665
lemma abs_summable_on_Sigma_iff:
eberlm@66526
   666
  assumes [simp]: "countable A" and "\<And>x. x \<in> A \<Longrightarrow> countable (B x)"
eberlm@66526
   667
  shows   "f abs_summable_on Sigma A B \<longleftrightarrow> 
eberlm@66526
   668
             (\<forall>x\<in>A. (\<lambda>y. f (x, y)) abs_summable_on B x) \<and>
eberlm@66526
   669
             ((\<lambda>x. infsetsum (\<lambda>y. norm (f (x, y))) (B x)) abs_summable_on A)"
eberlm@66526
   670
proof safe
eberlm@66526
   671
  define B' where "B' = (\<Union>x\<in>A. B x)"
eberlm@66526
   672
  have [simp]: "countable B'" 
eberlm@66526
   673
    unfolding B'_def using assms by auto
eberlm@66526
   674
  interpret pair_sigma_finite "count_space A" "count_space B'"
eberlm@66526
   675
    by (intro pair_sigma_finite.intro sigma_finite_measure_count_space_countable) fact+
eberlm@66526
   676
eberlm@66526
   677
  {
eberlm@66526
   678
    assume *: "f abs_summable_on Sigma A B"
eberlm@66526
   679
    thus "(\<lambda>y. f (x, y)) abs_summable_on B x" if "x \<in> A" for x
eberlm@66526
   680
      using that by (rule abs_summable_on_Sigma_project2)
eberlm@66526
   681
eberlm@66526
   682
    have "set_integrable (count_space (A \<times> B')) (Sigma A B) (\<lambda>z. norm (f z))"
eberlm@66526
   683
      using abs_summable_on_normI[OF *]
eberlm@66526
   684
      by (subst abs_summable_on_altdef' [symmetric]) (auto simp: B'_def)
eberlm@66526
   685
    also have "count_space (A \<times> B') = count_space A \<Otimes>\<^sub>M count_space B'"
eberlm@66526
   686
      by (simp add: pair_measure_countable)
eberlm@66526
   687
    finally have "integrable (count_space A) 
eberlm@66526
   688
                    (\<lambda>x. lebesgue_integral (count_space B') 
eberlm@66526
   689
                      (\<lambda>y. indicator (Sigma A B) (x, y) *\<^sub>R norm (f (x, y))))"
eberlm@66526
   690
      by (rule integrable_fst')
eberlm@66526
   691
    also have "?this \<longleftrightarrow> integrable (count_space A)
eberlm@66526
   692
                    (\<lambda>x. lebesgue_integral (count_space B') 
eberlm@66526
   693
                      (\<lambda>y. indicator (B x) y *\<^sub>R norm (f (x, y))))"
eberlm@66526
   694
      by (intro integrable_cong refl) (simp_all add: indicator_def)
eberlm@66526
   695
    also have "\<dots> \<longleftrightarrow> integrable (count_space A) (\<lambda>x. infsetsum (\<lambda>y. norm (f (x, y))) (B x))"
eberlm@66526
   696
      by (intro integrable_cong refl infsetsum_altdef' [symmetric]) (auto simp: B'_def)
eberlm@66526
   697
    also have "\<dots> \<longleftrightarrow> (\<lambda>x. infsetsum (\<lambda>y. norm (f (x, y))) (B x)) abs_summable_on A"
eberlm@66526
   698
      by (simp add: abs_summable_on_def)
eberlm@66526
   699
    finally show \<dots> .
eberlm@66526
   700
  }
eberlm@66526
   701
eberlm@66526
   702
  {
eberlm@66526
   703
    assume *: "\<forall>x\<in>A. (\<lambda>y. f (x, y)) abs_summable_on B x"
eberlm@66526
   704
    assume "(\<lambda>x. \<Sum>\<^sub>ay\<in>B x. norm (f (x, y))) abs_summable_on A"
eberlm@66526
   705
    also have "?this \<longleftrightarrow> (\<lambda>x. \<integral>y\<in>B x. norm (f (x, y)) \<partial>count_space B') abs_summable_on A"
eberlm@66526
   706
      by (intro abs_summable_on_cong refl infsetsum_altdef') (auto simp: B'_def)
eberlm@66526
   707
    also have "\<dots> \<longleftrightarrow> (\<lambda>x. \<integral>y. indicator (Sigma A B) (x, y) *\<^sub>R norm (f (x, y)) \<partial>count_space B')
eberlm@66526
   708
                        abs_summable_on A" (is "_ \<longleftrightarrow> ?h abs_summable_on _")
eberlm@66526
   709
      by (intro abs_summable_on_cong) (auto simp: indicator_def)
eberlm@66526
   710
    also have "\<dots> \<longleftrightarrow> integrable (count_space A) ?h"
eberlm@66526
   711
      by (simp add: abs_summable_on_def)
eberlm@66526
   712
    finally have **: \<dots> .
eberlm@66526
   713
eberlm@66526
   714
    have "integrable (count_space A \<Otimes>\<^sub>M count_space B') (\<lambda>z. indicator (Sigma A B) z *\<^sub>R f z)"
eberlm@66526
   715
    proof (rule Fubini_integrable, goal_cases)
eberlm@66526
   716
      case 3
eberlm@66526
   717
      {
eberlm@66526
   718
        fix x assume x: "x \<in> A"
eberlm@66526
   719
        with * have "(\<lambda>y. f (x, y)) abs_summable_on B x"
eberlm@66526
   720
          by blast
eberlm@66526
   721
        also have "?this \<longleftrightarrow> integrable (count_space B') 
eberlm@66526
   722
                      (\<lambda>y. indicator (B x) y *\<^sub>R f (x, y))"
eberlm@66526
   723
          using x by (intro abs_summable_on_altdef') (auto simp: B'_def)
eberlm@66526
   724
        also have "(\<lambda>y. indicator (B x) y *\<^sub>R f (x, y)) = 
eberlm@66526
   725
                     (\<lambda>y. indicator (Sigma A B) (x, y) *\<^sub>R f (x, y))"
eberlm@66526
   726
          using x by (auto simp: indicator_def)
eberlm@66526
   727
        finally have "integrable (count_space B')
eberlm@66526
   728
                        (\<lambda>y. indicator (Sigma A B) (x, y) *\<^sub>R f (x, y))" .
eberlm@66526
   729
      }
eberlm@66526
   730
      thus ?case by (auto simp: AE_count_space)
eberlm@66526
   731
    qed (insert **, auto simp: pair_measure_countable)
eberlm@66526
   732
    also have "count_space A \<Otimes>\<^sub>M count_space B' = count_space (A \<times> B')"
eberlm@66526
   733
      by (simp add: pair_measure_countable)
eberlm@66526
   734
    also have "set_integrable (count_space (A \<times> B')) (Sigma A B) f \<longleftrightarrow>
eberlm@66526
   735
                 f abs_summable_on Sigma A B"
eberlm@66526
   736
      by (rule abs_summable_on_altdef' [symmetric]) (auto simp: B'_def)
eberlm@66526
   737
    finally show \<dots> .
eberlm@66526
   738
  }
eberlm@66526
   739
qed
eberlm@66526
   740
eberlm@66526
   741
lemma abs_summable_on_Sigma_project1:
eberlm@66526
   742
  assumes "(\<lambda>(x,y). f x y) abs_summable_on Sigma A B"
eberlm@66526
   743
  assumes [simp]: "countable A" and "\<And>x. x \<in> A \<Longrightarrow> countable (B x)"
eberlm@66526
   744
  shows   "(\<lambda>x. infsetsum (\<lambda>y. norm (f x y)) (B x)) abs_summable_on A"
eberlm@66526
   745
  using assms by (subst (asm) abs_summable_on_Sigma_iff) auto
eberlm@66526
   746
eberlm@66526
   747
lemma abs_summable_on_Sigma_project1':
eberlm@66526
   748
  assumes "(\<lambda>(x,y). f x y) abs_summable_on Sigma A B"
eberlm@66526
   749
  assumes [simp]: "countable A" and "\<And>x. x \<in> A \<Longrightarrow> countable (B x)"
eberlm@66526
   750
  shows   "(\<lambda>x. infsetsum (\<lambda>y. f x y) (B x)) abs_summable_on A"
eberlm@66526
   751
  by (intro abs_summable_on_comparison_test' [OF abs_summable_on_Sigma_project1[OF assms]]
eberlm@66526
   752
        norm_infsetsum_bound)
eberlm@66526
   753
eberlm@66480
   754
lemma infsetsum_prod_PiE:
eberlm@66480
   755
  fixes f :: "'a \<Rightarrow> 'b \<Rightarrow> 'c :: {real_normed_field,banach,second_countable_topology}"
eberlm@66480
   756
  assumes finite: "finite A" and countable: "\<And>x. x \<in> A \<Longrightarrow> countable (B x)"
eberlm@66480
   757
  assumes summable: "\<And>x. x \<in> A \<Longrightarrow> f x abs_summable_on B x"
eberlm@66480
   758
  shows   "infsetsum (\<lambda>g. \<Prod>x\<in>A. f x (g x)) (PiE A B) = (\<Prod>x\<in>A. infsetsum (f x) (B x))"
eberlm@66480
   759
proof -
eberlm@66480
   760
  define B' where "B' = (\<lambda>x. if x \<in> A then B x else {})"
eberlm@66480
   761
  from assms have [simp]: "countable (B' x)" for x
eberlm@66480
   762
    by (auto simp: B'_def)
eberlm@66480
   763
  then interpret product_sigma_finite "count_space \<circ> B'"
eberlm@66480
   764
    unfolding o_def by (intro product_sigma_finite.intro sigma_finite_measure_count_space_countable)
eberlm@66480
   765
  have "infsetsum (\<lambda>g. \<Prod>x\<in>A. f x (g x)) (PiE A B) =
eberlm@66480
   766
          (\<integral>g. (\<Prod>x\<in>A. f x (g x)) \<partial>count_space (PiE A B))"
eberlm@66480
   767
    by (simp add: infsetsum_def)
eberlm@66480
   768
  also have "PiE A B = PiE A B'"
eberlm@66480
   769
    by (intro PiE_cong) (simp_all add: B'_def)
eberlm@66480
   770
  hence "count_space (PiE A B) = count_space (PiE A B')"
eberlm@66480
   771
    by simp
eberlm@66480
   772
  also have "\<dots> = PiM A (count_space \<circ> B')"
eberlm@66480
   773
    unfolding o_def using finite by (intro count_space_PiM_finite [symmetric]) simp_all
eberlm@66480
   774
  also have "(\<integral>g. (\<Prod>x\<in>A. f x (g x)) \<partial>\<dots>) = (\<Prod>x\<in>A. infsetsum (f x) (B' x))"
eberlm@66480
   775
    by (subst product_integral_prod) 
eberlm@66480
   776
       (insert summable finite, simp_all add: infsetsum_def B'_def abs_summable_on_def)
eberlm@66480
   777
  also have "\<dots> = (\<Prod>x\<in>A. infsetsum (f x) (B x))"
eberlm@66480
   778
    by (intro prod.cong refl) (simp_all add: B'_def)
eberlm@66480
   779
  finally show ?thesis .
eberlm@66480
   780
qed
eberlm@66480
   781
eberlm@66480
   782
lemma infsetsum_uminus: "infsetsum (\<lambda>x. -f x) A = -infsetsum f A"
eberlm@66480
   783
  unfolding infsetsum_def abs_summable_on_def 
eberlm@66480
   784
  by (rule Bochner_Integration.integral_minus)
eberlm@66480
   785
eberlm@66480
   786
lemma infsetsum_add:
eberlm@66480
   787
  assumes "f abs_summable_on A" and "g abs_summable_on A"
eberlm@66480
   788
  shows   "infsetsum (\<lambda>x. f x + g x) A = infsetsum f A + infsetsum g A"
eberlm@66480
   789
  using assms unfolding infsetsum_def abs_summable_on_def 
eberlm@66480
   790
  by (rule Bochner_Integration.integral_add)
eberlm@66480
   791
eberlm@66480
   792
lemma infsetsum_diff:
eberlm@66480
   793
  assumes "f abs_summable_on A" and "g abs_summable_on A"
eberlm@66480
   794
  shows   "infsetsum (\<lambda>x. f x - g x) A = infsetsum f A - infsetsum g A"
eberlm@66480
   795
  using assms unfolding infsetsum_def abs_summable_on_def 
eberlm@66480
   796
  by (rule Bochner_Integration.integral_diff)
eberlm@66480
   797
eberlm@66480
   798
lemma infsetsum_scaleR_left:
eberlm@66480
   799
  assumes "c \<noteq> 0 \<Longrightarrow> f abs_summable_on A"
eberlm@66480
   800
  shows   "infsetsum (\<lambda>x. f x *\<^sub>R c) A = infsetsum f A *\<^sub>R c"
eberlm@66480
   801
  using assms unfolding infsetsum_def abs_summable_on_def 
eberlm@66480
   802
  by (rule Bochner_Integration.integral_scaleR_left)
eberlm@66480
   803
eberlm@66480
   804
lemma infsetsum_scaleR_right:
eberlm@66480
   805
  "infsetsum (\<lambda>x. c *\<^sub>R f x) A = c *\<^sub>R infsetsum f A"
eberlm@66480
   806
  unfolding infsetsum_def abs_summable_on_def 
eberlm@66480
   807
  by (subst Bochner_Integration.integral_scaleR_right) auto
eberlm@66480
   808
eberlm@66480
   809
lemma infsetsum_cmult_left:
eberlm@66480
   810
  fixes f :: "'a \<Rightarrow> 'b :: {banach, real_normed_algebra, second_countable_topology}"
eberlm@66480
   811
  assumes "c \<noteq> 0 \<Longrightarrow> f abs_summable_on A"
eberlm@66480
   812
  shows   "infsetsum (\<lambda>x. f x * c) A = infsetsum f A * c"
eberlm@66480
   813
  using assms unfolding infsetsum_def abs_summable_on_def 
eberlm@66480
   814
  by (rule Bochner_Integration.integral_mult_left)
eberlm@66480
   815
eberlm@66480
   816
lemma infsetsum_cmult_right:
eberlm@66480
   817
  fixes f :: "'a \<Rightarrow> 'b :: {banach, real_normed_algebra, second_countable_topology}"
eberlm@66480
   818
  assumes "c \<noteq> 0 \<Longrightarrow> f abs_summable_on A"
eberlm@66480
   819
  shows   "infsetsum (\<lambda>x. c * f x) A = c * infsetsum f A"
eberlm@66480
   820
  using assms unfolding infsetsum_def abs_summable_on_def 
eberlm@66480
   821
  by (rule Bochner_Integration.integral_mult_right)
eberlm@66480
   822
eberlm@66526
   823
lemma infsetsum_cdiv:
eberlm@66526
   824
  fixes f :: "'a \<Rightarrow> 'b :: {banach, real_normed_field, second_countable_topology}"
eberlm@66526
   825
  assumes "c \<noteq> 0 \<Longrightarrow> f abs_summable_on A"
eberlm@66526
   826
  shows   "infsetsum (\<lambda>x. f x / c) A = infsetsum f A / c"
eberlm@66526
   827
  using assms unfolding infsetsum_def abs_summable_on_def by auto
eberlm@66526
   828
eberlm@66526
   829
eberlm@66480
   830
(* TODO Generalise with bounded_linear *)
eberlm@66480
   831
eberlm@66526
   832
lemma
eberlm@66526
   833
  fixes f :: "'a \<Rightarrow> 'c :: {banach, real_normed_field, second_countable_topology}"
eberlm@66526
   834
  assumes [simp]: "countable A" and [simp]: "countable B"
eberlm@66526
   835
  assumes "f abs_summable_on A" and "g abs_summable_on B"
eberlm@66526
   836
  shows   abs_summable_on_product: "(\<lambda>(x,y). f x * g y) abs_summable_on A \<times> B"
eberlm@66526
   837
    and   infsetsum_product: "infsetsum (\<lambda>(x,y). f x * g y) (A \<times> B) =
eberlm@66526
   838
                                infsetsum f A * infsetsum g B"
eberlm@66526
   839
proof -
eberlm@66526
   840
  from assms show "(\<lambda>(x,y). f x * g y) abs_summable_on A \<times> B"
eberlm@66526
   841
    by (subst abs_summable_on_Sigma_iff)
eberlm@66526
   842
       (auto intro!: abs_summable_on_cmult_right simp: norm_mult infsetsum_cmult_right)
eberlm@66526
   843
  with assms show "infsetsum (\<lambda>(x,y). f x * g y) (A \<times> B) = infsetsum f A * infsetsum g B"
eberlm@66526
   844
    by (subst infsetsum_Sigma)
eberlm@66526
   845
       (auto simp: infsetsum_cmult_left infsetsum_cmult_right)
eberlm@66526
   846
qed
eberlm@66526
   847
eberlm@66480
   848
end