Skip to content

Commit

Permalink
feat: and Finset.expect (#17274)
Browse files Browse the repository at this point in the history
Make more arguments to `NNReal.coe_sum` explicit to match `NNReal.coe_expect`.

From LeanAPAP
  • Loading branch information
YaelDillies committed Oct 1, 2024
1 parent 0d57a34 commit 1fe4aec
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 26 deletions.
3 changes: 1 addition & 2 deletions Mathlib/Algebra/Order/BigOperators/Expect.lean
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,7 @@ end LinearOrderedAddCommMonoid
section LinearOrderedAddCommGroup
variable [LinearOrderedAddCommGroup α] [Module ℚ≥0 α] [PosSMulMono ℚ≥0 α]

-- TODO: Norm version
lemma abs_expect_le_expect_abs (s : Finset ι) (f : ι → α) : |𝔼 i ∈ s, f i| ≤ 𝔼 i ∈ s, |f i| :=
lemma abs_expect_le (s : Finset ι) (f : ι → α) : |𝔼 i ∈ s, f i| ≤ 𝔼 i ∈ s, |f i| :=
le_expect_of_subadditive abs_zero abs_add (fun _ ↦ abs_nnqsmul _)

end LinearOrderedAddCommGroup
Expand Down
2 changes: 1 addition & 1 deletion Mathlib/Analysis/Normed/Group/Basic.lean
Original file line number Diff line number Diff line change
Expand Up @@ -1129,7 +1129,7 @@ theorem nnnorm_prod_le (s : Finset ι) (f : ι → E) : ‖∏ a ∈ s, f a‖
@[to_additive]
theorem nnnorm_prod_le_of_le (s : Finset ι) {f : ι → E} {n : ι → ℝ≥0} (h : ∀ b ∈ s, ‖f b‖₊ ≤ n b) :
‖∏ b ∈ s, f b‖₊ ≤ ∑ b ∈ s, n b :=
(norm_prod_le_of_le s h).trans_eq NNReal.coe_sum.symm
(norm_prod_le_of_le s h).trans_eq (NNReal.coe_sum ..).symm

namespace Real

Expand Down
2 changes: 1 addition & 1 deletion Mathlib/Analysis/Normed/Group/Constructions.lean
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ lemma Pi.sum_norm_apply_le_norm' : ∑ i, ‖f i‖ ≤ Fintype.card ι • ‖f
@[to_additive Pi.sum_nnnorm_apply_le_nnnorm "The $L^1$ norm is less than the $L^\\infty$ norm
scaled by the cardinality."]
lemma Pi.sum_nnnorm_apply_le_nnnorm' : ∑ i, ‖f i‖₊ ≤ Fintype.card ι • ‖f‖₊ :=
NNReal.coe_sum.trans_le <| Pi.sum_norm_apply_le_norm' _
(NNReal.coe_sum ..).trans_le <| Pi.sum_norm_apply_le_norm' _

end SeminormedGroup

Expand Down
25 changes: 20 additions & 5 deletions Mathlib/Analysis/RCLike/Basic.lean
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Released under Apache 2.0 license as described in the file LICENSE.
Authors: Frédéric Dupuis
-/
import Mathlib.Algebra.Algebra.Field
import Mathlib.Algebra.Order.BigOperators.Expect
import Mathlib.Algebra.Order.Star.Basic
import Mathlib.Analysis.CStarAlgebra.Basic
import Mathlib.Analysis.Normed.Operator.ContinuousLinearMap
Expand Down Expand Up @@ -39,7 +40,7 @@ their counterparts in `Mathlib/Analysis/Complex/Basic.lean` (which causes linter
A few lemmas requiring heavier imports are in `Mathlib/Data/RCLike/Lemmas.lean`.
-/

open scoped ComplexConjugate
open scoped BigOperators ComplexConjugate

section

Expand Down Expand Up @@ -234,6 +235,10 @@ theorem norm_ofReal (r : ℝ) : ‖(r : K)‖ = |r| :=
instance (priority := 100) charZero_rclike : CharZero K :=
(RingHom.charZero_iff (algebraMap ℝ K).injective).1 inferInstance

@[rclike_simps, norm_cast]
lemma ofReal_expect {α : Type*} (s : Finset α) (f : α → ℝ) : 𝔼 i ∈ s, f i = 𝔼 i ∈ s, (f i : K) :=
map_expect (algebraMap ..) ..

/-! ### The imaginary unit, `I` -/

/-- The imaginary unit. -/
Expand Down Expand Up @@ -605,13 +610,23 @@ variable (K) in
lemma nnnorm_nsmul [NormedAddCommGroup E] [NormedSpace K E] (n : ℕ) (x : E) :
‖n • x‖₊ = n • ‖x‖₊ := by simpa [Nat.cast_smul_eq_nsmul] using nnnorm_smul (n : K) x

section NormedField
variable [NormedField E] [CharZero E] [NormedSpace K E]
include K

variable (K) in
lemma norm_nnqsmul [NormedField E] [CharZero E] [NormedSpace K E] (q : ℚ≥0) (x : E) :
‖q • x‖ = q • ‖x‖ := by simpa [NNRat.cast_smul_eq_nnqsmul] using norm_smul (q : K) x
lemma norm_nnqsmul (q : ℚ≥0) (x : E) : ‖q • x‖ = q • ‖x‖ := by
simpa [NNRat.cast_smul_eq_nnqsmul] using norm_smul (q : K) x

variable (K) in
lemma nnnorm_nnqsmul [NormedField E] [CharZero E] [NormedSpace K E] (q : ℚ≥0) (x : E) :
‖q • x‖₊ = q • ‖x‖₊ := by simpa [NNRat.cast_smul_eq_nnqsmul] using nnnorm_smul (q : K) x
lemma nnnorm_nnqsmul (q : ℚ≥0) (x : E) : ‖q • x‖₊ = q • ‖x‖₊ := by
simpa [NNRat.cast_smul_eq_nnqsmul] using nnnorm_smul (q : K) x

@[bound]
lemma norm_expect_le {ι : Type*} {s : Finset ι} {f : ι → E} : ‖𝔼 i ∈ s, f i‖ ≤ 𝔼 i ∈ s, ‖f i‖ :=
Finset.le_expect_of_subadditive norm_zero norm_add_le fun _ _ ↦ by rw [norm_nnqsmul K]

end NormedField

theorem mul_self_norm (z : K) : ‖z‖ * ‖z‖ = normSq z := by rw [normSq_eq_def', sq]

Expand Down
9 changes: 9 additions & 0 deletions Mathlib/Data/Complex/Basic.lean
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,15 @@ lemma re_ofNat (n : ℕ) [n.AtLeastTwo] : (no_index (OfNat.ofNat n) : ℂ).re =
@[simp, norm_cast] lemma ratCast_re (q : ℚ) : (q : ℂ).re = q := rfl
@[simp, norm_cast] lemma ratCast_im (q : ℚ) : (q : ℂ).im = 0 := rfl

lemma re_nsmul (n : ℕ) (z : ℂ) : (n • z).re = n • z.re := smul_re ..
lemma im_nsmul (n : ℕ) (z : ℂ) : (n • z).im = n • z.im := smul_im ..
lemma re_zsmul (n : ℤ) (z : ℂ) : (n • z).re = n • z.re := smul_re ..
lemma im_zsmul (n : ℤ) (z : ℂ) : (n • z).im = n • z.im := smul_im ..
@[simp] lemma re_nnqsmul (q : ℚ≥0) (z : ℂ) : (q • z).re = q • z.re := smul_re ..
@[simp] lemma im_nnqsmul (q : ℚ≥0) (z : ℂ) : (q • z).im = q • z.im := smul_im ..
@[simp] lemma re_qsmul (q : ℚ) (z : ℂ) : (q • z).re = q • z.re := smul_re ..
@[simp] lemma im_qsmul (q : ℚ) (z : ℂ) : (q • z).im = q • z.im := smul_im ..

@[deprecated (since := "2024-04-17")]
alias rat_cast_im := ratCast_im

Expand Down
17 changes: 15 additions & 2 deletions Mathlib/Data/Complex/BigOperators.lean
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@ Copyright (c) 2017 Kevin Buzzard. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kevin Buzzard, Mario Carneiro
-/
import Mathlib.Algebra.BigOperators.Group.Finset
import Mathlib.Algebra.BigOperators.Expect
import Mathlib.Data.Complex.Basic

/-!
# Finite sums and products of complex numbers
-/

open scoped BigOperators

namespace Complex

variable {α : Type*} (s : Finset α)
Expand All @@ -23,12 +24,24 @@ theorem ofReal_prod (f : α → ℝ) : ((∏ i ∈ s, f i : ℝ) : ℂ) = ∏ i
theorem ofReal_sum (f : α → ℝ) : ((∑ i ∈ s, f i : ℝ) : ℂ) = ∑ i ∈ s, (f i : ℂ) :=
map_sum ofReal _ _

@[simp, norm_cast]
lemma ofReal_expect (f : α → ℝ) : (𝔼 i ∈ s, f i : ℝ) = 𝔼 i ∈ s, (f i : ℂ) :=
map_expect ofReal ..

@[simp]
theorem re_sum (f : α → ℂ) : (∑ i ∈ s, f i).re = ∑ i ∈ s, (f i).re :=
map_sum reAddGroupHom f s

@[simp]
lemma re_expect (f : α → ℂ) : (𝔼 i ∈ s, f i).re = 𝔼 i ∈ s, (f i).re :=
map_expect (LinearMap.mk reAddGroupHom.toAddHom (by simp)) f s

@[simp]
theorem im_sum (f : α → ℂ) : (∑ i ∈ s, f i).im = ∑ i ∈ s, (f i).im :=
map_sum imAddGroupHom f s

@[simp]
lemma im_expect (f : α → ℂ) : (𝔼 i ∈ s, f i).im = 𝔼 i ∈ s, (f i).im :=
map_expect (LinearMap.mk imAddGroupHom.toAddHom (by simp)) f s

end Complex
24 changes: 13 additions & 11 deletions Mathlib/Data/NNReal/Basic.lean
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,13 @@ Copyright (c) 2018 Johan Commelin. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johan Commelin
-/
import Mathlib.Algebra.Algebra.Defs
import Mathlib.Algebra.BigOperators.Expect
import Mathlib.Algebra.Order.BigOperators.Ring.Finset
import Mathlib.Algebra.Order.Field.Canonical.Basic
import Mathlib.Algebra.Order.Nonneg.Field
import Mathlib.Algebra.Order.Nonneg.Floor
import Mathlib.Algebra.Ring.Regular
import Mathlib.Data.Real.Pointwise
import Mathlib.Order.ConditionallyCompleteLattice.Group
import Mathlib.Tactic.Bound.Attribute
import Mathlib.Tactic.GCongr.CoreAttrs
import Mathlib.Algebra.Ring.Regular

/-!
# Nonnegative real numbers
Expand Down Expand Up @@ -55,6 +52,7 @@ This file defines `ℝ≥0` as a localized notation for `NNReal`.
assert_not_exists Star

open Function
open scoped BigOperators

-- to ensure these instances are computable
/-- Nonnegative real numbers. -/
Expand Down Expand Up @@ -278,22 +276,26 @@ theorem coe_multiset_sum (s : Multiset ℝ≥0) : ((s.sum : ℝ≥0) : ℝ) = (s
theorem coe_multiset_prod (s : Multiset ℝ≥0) : ((s.prod : ℝ≥0) : ℝ) = (s.map (↑)).prod :=
map_multiset_prod toRealHom s

variable {ι : Type*} {s : Finset ι} {f : ι → ℝ}

@[simp, norm_cast]
theorem coe_sum {α} {s : Finset α} {f : α → ℝ≥0} : ↑(∑ a ∈ s, f a) = ∑ a ∈ s, (f a : ℝ) :=
theorem coe_sum (s : Finset ι) (f : ι → ℝ≥0) : ∑ i ∈ s, f i = ∑ i ∈ s, (f i : ℝ) :=
map_sum toRealHom _ _

theorem _root_.Real.toNNReal_sum_of_nonneg {α} {s : Finset α} {f : α → ℝ}
(hf : ∀ a, a ∈ s → 0 ≤ f a) :
@[simp, norm_cast]
lemma coe_expect (s : Finset ι) (f : ι → ℝ≥0) : 𝔼 i ∈ s, f i = 𝔼 i ∈ s, (f i : ℝ) :=
map_expect toRealHom ..

theorem _root_.Real.toNNReal_sum_of_nonneg (hf : ∀ i ∈ s, 0 ≤ f i) :
Real.toNNReal (∑ a ∈ s, f a) = ∑ a ∈ s, Real.toNNReal (f a) := by
rw [← coe_inj, NNReal.coe_sum, Real.coe_toNNReal _ (Finset.sum_nonneg hf)]
exact Finset.sum_congr rfl fun x hxs => by rw [Real.coe_toNNReal _ (hf x hxs)]

@[simp, norm_cast]
theorem coe_prod {α} {s : Finset α} {f : α → ℝ≥0} : ↑(∏ a ∈ s, f a) = ∏ a ∈ s, (f a : ℝ) :=
theorem coe_prod (s : Finset ι) (f : ι → ℝ≥0) : ↑(∏ a ∈ s, f a) = ∏ a ∈ s, (f a : ℝ) :=
map_prod toRealHom _ _

theorem _root_.Real.toNNReal_prod_of_nonneg {α} {s : Finset α} {f : α → ℝ}
(hf : ∀ a, a ∈ s → 0 ≤ f a) :
theorem _root_.Real.toNNReal_prod_of_nonneg (hf : ∀ a, a ∈ s → 0 ≤ f a) :
Real.toNNReal (∏ a ∈ s, f a) = ∏ a ∈ s, Real.toNNReal (f a) := by
rw [← coe_inj, NNReal.coe_prod, Real.coe_toNNReal _ (Finset.prod_nonneg hf)]
exact Finset.prod_congr rfl fun x hxs => by rw [Real.coe_toNNReal _ (hf x hxs)]
Expand Down
9 changes: 5 additions & 4 deletions Mathlib/Topology/Instances/Real.lean
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,17 @@ Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Mario Carneiro
-/
import Mathlib.Data.Real.Star
import Mathlib.Algebra.Algebra.Basic
import Mathlib.Algebra.Module.Rat
import Mathlib.Algebra.Module.Submodule.Lattice
import Mathlib.Algebra.Periodic
import Mathlib.Data.Real.Star
import Mathlib.Topology.Algebra.Order.Archimedean
import Mathlib.Topology.Algebra.Order.Field
import Mathlib.Topology.Algebra.UniformMulAction
import Mathlib.Topology.Algebra.Star
import Mathlib.Topology.Algebra.UniformMulAction
import Mathlib.Topology.Instances.Int
import Mathlib.Topology.Order.Bornology
import Mathlib.Topology.Metrizable.Basic
import Mathlib.Topology.Order.Bornology

/-!
# Topological properties of ℝ
Expand Down

0 comments on commit 1fe4aec

Please sign in to comment.