|
| 1 | +/- |
| 2 | +Copyright (c) 2024 Zhouhang Zhou. All rights reserved. |
| 3 | +Released under Apache 2.0 license as described in the file LICENSE. |
| 4 | +Authors: Zhouhang Zhou, Yaël Dillies |
| 5 | +-/ |
| 6 | +import Mathlib.Algebra.BigOperators.Basic |
| 7 | +import Mathlib.Algebra.Order.Ring.WithTop |
| 8 | + |
| 9 | +/-! |
| 10 | +# Sums in `WithTop` |
| 11 | +
|
| 12 | +This file proves results about finite sums over monoids extended by a bottom or top element. |
| 13 | +-/ |
| 14 | + |
| 15 | +open Finset |
| 16 | +open scoped BigOperators |
| 17 | + |
| 18 | +variable {ι α : Type*} |
| 19 | + |
| 20 | +namespace WithTop |
| 21 | +section AddCommMonoid |
| 22 | +variable [AddCommMonoid α] [LT α] {s : Finset ι} {f : ι → WithTop α} |
| 23 | + |
| 24 | +@[simp, norm_cast] lemma coe_sum (s : Finset ι) (f : ι → α) : |
| 25 | + ∑ i in s, f i = ∑ i in s, (f i : WithTop α) := map_sum addHom f s |
| 26 | + |
| 27 | +/-- A sum is infinite iff one term is infinite. -/ |
| 28 | +lemma sum_eq_top_iff : ∑ i in s, f i = ⊤ ↔ ∃ i ∈ s, f i = ⊤ := by |
| 29 | + induction s using Finset.cons_induction <;> simp [*] |
| 30 | +#align with_top.sum_eq_top_iff WithTop.sum_eq_top_iff |
| 31 | + |
| 32 | +/-- A sum is finite iff all terms are finite. -/ |
| 33 | +lemma sum_lt_top_iff : ∑ i in s, f i < ⊤ ↔ ∀ i ∈ s, f i < ⊤ := by |
| 34 | + simp only [WithTop.lt_top_iff_ne_top, ne_eq, sum_eq_top_iff, not_exists, not_and] |
| 35 | +#align with_top.sum_lt_top_iff WithTop.sum_lt_top_iff |
| 36 | + |
| 37 | +/-- A sum of finite terms is finite. -/ |
| 38 | +lemma sum_lt_top (h : ∀ i ∈ s, f i ≠ ⊤) : ∑ i in s, f i < ⊤ := |
| 39 | + sum_lt_top_iff.2 fun i hi ↦ WithTop.lt_top_iff_ne_top.2 (h i hi) |
| 40 | +#align with_top.sum_lt_top WithTop.sum_lt_top |
| 41 | + |
| 42 | +end AddCommMonoid |
| 43 | + |
| 44 | +/-- A product of finite terms is finite. -/ |
| 45 | +lemma prod_lt_top [CommMonoidWithZero α] [NoZeroDivisors α] [Nontrivial α] [DecidableEq α] [LT α] |
| 46 | + {s : Finset ι} {f : ι → WithTop α} (h : ∀ i ∈ s, f i ≠ ⊤) : ∏ i in s, f i < ⊤ := |
| 47 | + prod_induction f (· < ⊤) (fun _ _ h₁ h₂ ↦ mul_lt_top' h₁ h₂) (coe_lt_top 1) |
| 48 | + fun a ha ↦ WithTop.lt_top_iff_ne_top.2 (h a ha) |
| 49 | +#align with_top.prod_lt_top WithTop.prod_lt_top |
| 50 | + |
| 51 | +end WithTop |
| 52 | + |
| 53 | +namespace WithBot |
| 54 | +section AddCommMonoid |
| 55 | +variable [AddCommMonoid α] [LT α] {s : Finset ι} {f : ι → WithBot α} |
| 56 | + |
| 57 | +@[simp, norm_cast] lemma coe_sum (s : Finset ι) (f : ι → α) : |
| 58 | + ∑ i in s, f i = ∑ i in s, (f i : WithBot α) := map_sum addHom f s |
| 59 | + |
| 60 | +/-- A sum is infinite iff one term is infinite. -/ |
| 61 | +lemma sum_eq_bot_iff : ∑ i in s, f i = ⊥ ↔ ∃ i ∈ s, f i = ⊥ := by |
| 62 | + induction s using Finset.cons_induction <;> simp [*] |
| 63 | + |
| 64 | +/-- A sum is finite iff all terms are finite. -/ |
| 65 | +lemma bot_lt_sum_iff : ⊥ < ∑ i in s, f i ↔ ∀ i ∈ s, ⊥ < f i := by |
| 66 | + simp only [WithBot.bot_lt_iff_ne_bot, ne_eq, sum_eq_bot_iff, not_exists, not_and] |
| 67 | + |
| 68 | +/-- A sum of finite terms is finite. -/ |
| 69 | +lemma sum_lt_bot (h : ∀ i ∈ s, f i ≠ ⊥) : ⊥ < ∑ i in s, f i := |
| 70 | + bot_lt_sum_iff.2 fun i hi ↦ WithBot.bot_lt_iff_ne_bot.2 (h i hi) |
| 71 | +#align with_bot.sum_lt_bot WithBot.sum_lt_bot |
| 72 | + |
| 73 | +end AddCommMonoid |
| 74 | + |
| 75 | +/-- A product of finite terms is finite. -/ |
| 76 | +lemma prod_lt_bot [CommMonoidWithZero α] [NoZeroDivisors α] [Nontrivial α] [DecidableEq α] [LT α] |
| 77 | + {s : Finset ι} {f : ι → WithBot α} (h : ∀ i ∈ s, f i ≠ ⊥) : ⊥ < ∏ i in s, f i := |
| 78 | + prod_induction f (⊥ < ·) (fun _ _ h₁ h₂ ↦ bot_lt_mul' h₁ h₂) (bot_lt_coe 1) |
| 79 | + fun a ha ↦ WithBot.bot_lt_iff_ne_bot.2 (h a ha) |
| 80 | +#align with_bot.prod_lt_bot WithBot.prod_lt_bot |
| 81 | + |
| 82 | +end WithBot |
0 commit comments