source
stringlengths
17
118
lean4
stringlengths
0
335k
.lake/packages/mathlib/Mathlib/Analysis/SpecialFunctions/Pow/Continuity.lean
import Mathlib.Analysis.SpecialFunctions.Pow.Asymptotics /-! # Continuity of power functions This file contains lemmas about continuity of the power functions on `β„‚`, `ℝ`, `ℝβ‰₯0`, and `ℝβ‰₯0∞`. -/ noncomputable section open Real Topology NNReal ENNReal Filter ComplexConjugate Finset Set section CpowLimits /-! ## Continuity for complex powers -/ open Complex variable {Ξ± : Type*} theorem zero_cpow_eq_nhds {b : β„‚} (hb : b β‰  0) : (fun x : β„‚ => (0 : β„‚) ^ x) =αΆ [𝓝 b] 0 := by suffices βˆ€αΆ  x : β„‚ in 𝓝 b, x β‰  0 from this.mono fun x hx ↦ by dsimp only rw [zero_cpow hx, Pi.zero_apply] exact IsOpen.eventually_mem isOpen_ne hb theorem cpow_eq_nhds {a b : β„‚} (ha : a β‰  0) : (fun x => x ^ b) =αΆ [𝓝 a] fun x => exp (log x * b) := by suffices βˆ€αΆ  x : β„‚ in 𝓝 a, x β‰  0 from this.mono fun x hx ↦ by dsimp only rw [cpow_def_of_ne_zero hx] exact IsOpen.eventually_mem isOpen_ne ha theorem cpow_eq_nhds' {p : β„‚ Γ— β„‚} (hp_fst : p.fst β‰  0) : (fun x => x.1 ^ x.2) =αΆ [𝓝 p] fun x => exp (log x.1 * x.2) := by suffices βˆ€αΆ  x : β„‚ Γ— β„‚ in 𝓝 p, x.1 β‰  0 from this.mono fun x hx ↦ by dsimp only rw [cpow_def_of_ne_zero hx] refine IsOpen.eventually_mem ?_ hp_fst change IsOpen { x : β„‚ Γ— β„‚ | x.1 = 0 }ᢜ rw [isOpen_compl_iff] exact isClosed_eq continuous_fst continuous_const -- Continuity of `fun x => a ^ x`: union of these two lemmas is optimal. theorem continuousAt_const_cpow {a b : β„‚} (ha : a β‰  0) : ContinuousAt (fun x : β„‚ => a ^ x) b := by have cpow_eq : (fun x : β„‚ => a ^ x) = fun x => exp (log a * x) := by ext1 b rw [cpow_def_of_ne_zero ha] rw [cpow_eq] exact continuous_exp.continuousAt.comp (ContinuousAt.mul continuousAt_const continuousAt_id) theorem continuousAt_const_cpow' {a b : β„‚} (h : b β‰  0) : ContinuousAt (fun x : β„‚ => a ^ x) b := by by_cases ha : a = 0 Β· rw [ha, continuousAt_congr (zero_cpow_eq_nhds h)] exact continuousAt_const Β· exact continuousAt_const_cpow ha /-- The function `z ^ w` is continuous in `(z, w)` provided that `z` does not belong to the interval `(-∞, 0]` on the real line. See also `Complex.continuousAt_cpow_zero_of_re_pos` for a version that works for `z = 0` but assumes `0 < re w`. -/ theorem continuousAt_cpow {p : β„‚ Γ— β„‚} (hp_fst : p.fst ∈ slitPlane) : ContinuousAt (fun x : β„‚ Γ— β„‚ => x.1 ^ x.2) p := by rw [continuousAt_congr (cpow_eq_nhds' <| slitPlane_ne_zero hp_fst)] refine continuous_exp.continuousAt.comp ?_ exact ContinuousAt.mul (ContinuousAt.comp (continuousAt_clog hp_fst) continuous_fst.continuousAt) continuous_snd.continuousAt theorem continuousAt_cpow_const {a b : β„‚} (ha : a ∈ slitPlane) : ContinuousAt (Β· ^ b) a := Tendsto.comp (@continuousAt_cpow (a, b) ha) (continuousAt_id.prodMk continuousAt_const) theorem Filter.Tendsto.cpow {l : Filter Ξ±} {f g : Ξ± β†’ β„‚} {a b : β„‚} (hf : Tendsto f l (𝓝 a)) (hg : Tendsto g l (𝓝 b)) (ha : a ∈ slitPlane) : Tendsto (fun x => f x ^ g x) l (𝓝 (a ^ b)) := (@continuousAt_cpow (a, b) ha).tendsto.comp (hf.prodMk_nhds hg) theorem Filter.Tendsto.const_cpow {l : Filter Ξ±} {f : Ξ± β†’ β„‚} {a b : β„‚} (hf : Tendsto f l (𝓝 b)) (h : a β‰  0 ∨ b β‰  0) : Tendsto (fun x => a ^ f x) l (𝓝 (a ^ b)) := by cases h with | inl h => exact (continuousAt_const_cpow h).tendsto.comp hf | inr h => exact (continuousAt_const_cpow' h).tendsto.comp hf variable [TopologicalSpace Ξ±] {f g : Ξ± β†’ β„‚} {s : Set Ξ±} {a : Ξ±} nonrec theorem ContinuousWithinAt.cpow (hf : ContinuousWithinAt f s a) (hg : ContinuousWithinAt g s a) (h0 : f a ∈ slitPlane) : ContinuousWithinAt (fun x => f x ^ g x) s a := hf.cpow hg h0 nonrec theorem ContinuousWithinAt.const_cpow {b : β„‚} (hf : ContinuousWithinAt f s a) (h : b β‰  0 ∨ f a β‰  0) : ContinuousWithinAt (fun x => b ^ f x) s a := hf.const_cpow h nonrec theorem ContinuousAt.cpow (hf : ContinuousAt f a) (hg : ContinuousAt g a) (h0 : f a ∈ slitPlane) : ContinuousAt (fun x => f x ^ g x) a := hf.cpow hg h0 nonrec theorem ContinuousAt.const_cpow {b : β„‚} (hf : ContinuousAt f a) (h : b β‰  0 ∨ f a β‰  0) : ContinuousAt (fun x => b ^ f x) a := hf.const_cpow h theorem ContinuousOn.cpow (hf : ContinuousOn f s) (hg : ContinuousOn g s) (h0 : βˆ€ a ∈ s, f a ∈ slitPlane) : ContinuousOn (fun x => f x ^ g x) s := fun a ha => (hf a ha).cpow (hg a ha) (h0 a ha) theorem ContinuousOn.const_cpow {b : β„‚} (hf : ContinuousOn f s) (h : b β‰  0 ∨ βˆ€ a ∈ s, f a β‰  0) : ContinuousOn (fun x => b ^ f x) s := fun a ha => (hf a ha).const_cpow (h.imp id fun h => h a ha) theorem Continuous.cpow (hf : Continuous f) (hg : Continuous g) (h0 : βˆ€ a, f a ∈ slitPlane) : Continuous fun x => f x ^ g x := continuous_iff_continuousAt.2 fun a => hf.continuousAt.cpow hg.continuousAt (h0 a) theorem Continuous.const_cpow {b : β„‚} (hf : Continuous f) (h : b β‰  0 ∨ βˆ€ a, f a β‰  0) : Continuous fun x => b ^ f x := continuous_iff_continuousAt.2 fun a => hf.continuousAt.const_cpow <| h.imp id fun h => h a theorem ContinuousOn.cpow_const {b : β„‚} (hf : ContinuousOn f s) (h : βˆ€ a : Ξ±, a ∈ s β†’ f a ∈ slitPlane) : ContinuousOn (fun x => f x ^ b) s := hf.cpow continuousOn_const h @[fun_prop] lemma continuous_const_cpow (z : β„‚) [NeZero z] : Continuous fun s : β„‚ ↦ z ^ s := continuous_id.const_cpow (.inl <| NeZero.ne z) end CpowLimits section RpowLimits /-! ## Continuity for real powers -/ namespace Real theorem continuousAt_const_rpow {a b : ℝ} (h : a β‰  0) : ContinuousAt (a ^ Β·) b := by simp only [rpow_def] refine Complex.continuous_re.continuousAt.comp ?_ refine (continuousAt_const_cpow ?_).comp Complex.continuous_ofReal.continuousAt norm_cast theorem continuousAt_const_rpow' {a b : ℝ} (h : b β‰  0) : ContinuousAt (a ^ Β·) b := by simp only [rpow_def] refine Complex.continuous_re.continuousAt.comp ?_ refine (continuousAt_const_cpow' ?_).comp Complex.continuous_ofReal.continuousAt norm_cast theorem rpow_eq_nhds_of_neg {p : ℝ Γ— ℝ} (hp_fst : p.fst < 0) : (fun x : ℝ Γ— ℝ => x.1 ^ x.2) =αΆ [𝓝 p] fun x => exp (log x.1 * x.2) * cos (x.2 * Ο€) := by suffices βˆ€αΆ  x : ℝ Γ— ℝ in 𝓝 p, x.1 < 0 from this.mono fun x hx ↦ by dsimp only rw [rpow_def_of_neg hx] exact IsOpen.eventually_mem (isOpen_lt continuous_fst continuous_const) hp_fst theorem rpow_eq_nhds_of_pos {p : ℝ Γ— ℝ} (hp_fst : 0 < p.fst) : (fun x : ℝ Γ— ℝ => x.1 ^ x.2) =αΆ [𝓝 p] fun x => exp (log x.1 * x.2) := by suffices βˆ€αΆ  x : ℝ Γ— ℝ in 𝓝 p, 0 < x.1 from this.mono fun x hx ↦ by dsimp only rw [rpow_def_of_pos hx] exact IsOpen.eventually_mem (isOpen_lt continuous_const continuous_fst) hp_fst theorem continuousAt_rpow_of_ne (p : ℝ Γ— ℝ) (hp : p.1 β‰  0) : ContinuousAt (fun p : ℝ Γ— ℝ => p.1 ^ p.2) p := by rw [ne_iff_lt_or_gt] at hp cases hp with | inl hp => rw [continuousAt_congr (rpow_eq_nhds_of_neg hp)] refine ContinuousAt.mul ?_ (continuous_cos.continuousAt.comp ?_) Β· refine continuous_exp.continuousAt.comp (ContinuousAt.mul ?_ continuous_snd.continuousAt) refine (continuousAt_log ?_).comp continuous_fst.continuousAt exact hp.ne Β· exact continuous_snd.continuousAt.mul continuousAt_const | inr hp => rw [continuousAt_congr (rpow_eq_nhds_of_pos hp)] refine continuous_exp.continuousAt.comp (ContinuousAt.mul ?_ continuous_snd.continuousAt) refine (continuousAt_log ?_).comp continuous_fst.continuousAt exact hp.ne' theorem continuousAt_rpow_of_pos (p : ℝ Γ— ℝ) (hp : 0 < p.2) : ContinuousAt (fun p : ℝ Γ— ℝ => p.1 ^ p.2) p := by obtain ⟨x, y⟩ := p dsimp only at hp obtain hx | rfl := ne_or_eq x 0 Β· exact continuousAt_rpow_of_ne (x, y) hx have A : Tendsto (fun p : ℝ Γ— ℝ => exp (log p.1 * p.2)) (𝓝[β‰ ] 0 Γ—Λ’ 𝓝 y) (𝓝 0) := tendsto_exp_atBot.comp ((tendsto_log_nhdsNE_zero.comp tendsto_fst).atBot_mul_pos hp tendsto_snd) have B : Tendsto (fun p : ℝ Γ— ℝ => p.1 ^ p.2) (𝓝[β‰ ] 0 Γ—Λ’ 𝓝 y) (𝓝 0) := squeeze_zero_norm (fun p => abs_rpow_le_exp_log_mul p.1 p.2) A have C : Tendsto (fun p : ℝ Γ— ℝ => p.1 ^ p.2) (𝓝[{0}] 0 Γ—Λ’ 𝓝 y) (pure 0) := by rw [nhdsWithin_singleton, tendsto_pure, pure_prod, eventually_map] exact (lt_mem_nhds hp).mono fun y hy => zero_rpow hy.ne' simpa only [← sup_prod, ← nhdsWithin_union, compl_union_self, nhdsWithin_univ, nhds_prod_eq, ContinuousAt, zero_rpow hp.ne'] using B.sup (C.mono_right (pure_le_nhds _)) theorem continuousAt_rpow (p : ℝ Γ— ℝ) (h : p.1 β‰  0 ∨ 0 < p.2) : ContinuousAt (fun p : ℝ Γ— ℝ => p.1 ^ p.2) p := h.elim (fun h => continuousAt_rpow_of_ne p h) fun h => continuousAt_rpow_of_pos p h @[fun_prop] theorem continuousAt_rpow_const (x : ℝ) (q : ℝ) (h : x β‰  0 ∨ 0 ≀ q) : ContinuousAt (fun x : ℝ => x ^ q) x := by rw [le_iff_lt_or_eq, ← or_assoc] at h obtain h|rfl := h Β· exact (continuousAt_rpow (x, q) h).compβ‚‚ continuousAt_id continuousAt_const Β· simp_rw [rpow_zero]; exact continuousAt_const @[fun_prop] theorem continuous_rpow_const {q : ℝ} (h : 0 ≀ q) : Continuous (fun x : ℝ => x ^ q) := continuous_iff_continuousAt.mpr fun x ↦ continuousAt_rpow_const x q (.inr h) @[fun_prop] lemma continuous_const_rpow {a : ℝ} (h : a β‰  0) : Continuous (fun x : ℝ ↦ a ^ x) := continuous_iff_continuousAt.mpr fun _ ↦ continuousAt_const_rpow h end Real section variable {Ξ± : Type*} theorem Filter.Tendsto.rpow {l : Filter Ξ±} {f g : Ξ± β†’ ℝ} {x y : ℝ} (hf : Tendsto f l (𝓝 x)) (hg : Tendsto g l (𝓝 y)) (h : x β‰  0 ∨ 0 < y) : Tendsto (fun t => f t ^ g t) l (𝓝 (x ^ y)) := (Real.continuousAt_rpow (x, y) h).tendsto.comp (hf.prodMk_nhds hg) theorem Filter.Tendsto.rpow_const {l : Filter Ξ±} {f : Ξ± β†’ ℝ} {x p : ℝ} (hf : Tendsto f l (𝓝 x)) (h : x β‰  0 ∨ 0 ≀ p) : Tendsto (fun a => f a ^ p) l (𝓝 (x ^ p)) := if h0 : 0 = p then h0 β–Έ by simp [tendsto_const_nhds] else hf.rpow tendsto_const_nhds (h.imp id fun h' => h'.lt_of_ne h0) variable [TopologicalSpace Ξ±] {f g : Ξ± β†’ ℝ} {s : Set Ξ±} {x : Ξ±} {p : ℝ} nonrec theorem ContinuousAt.rpow (hf : ContinuousAt f x) (hg : ContinuousAt g x) (h : f x β‰  0 ∨ 0 < g x) : ContinuousAt (fun t => f t ^ g t) x := hf.rpow hg h nonrec theorem ContinuousWithinAt.rpow (hf : ContinuousWithinAt f s x) (hg : ContinuousWithinAt g s x) (h : f x β‰  0 ∨ 0 < g x) : ContinuousWithinAt (fun t => f t ^ g t) s x := hf.rpow hg h theorem ContinuousOn.rpow (hf : ContinuousOn f s) (hg : ContinuousOn g s) (h : βˆ€ x ∈ s, f x β‰  0 ∨ 0 < g x) : ContinuousOn (fun t => f t ^ g t) s := fun t ht => (hf t ht).rpow (hg t ht) (h t ht) theorem Continuous.rpow (hf : Continuous f) (hg : Continuous g) (h : βˆ€ x, f x β‰  0 ∨ 0 < g x) : Continuous fun x => f x ^ g x := continuous_iff_continuousAt.2 fun x => hf.continuousAt.rpow hg.continuousAt (h x) nonrec theorem ContinuousWithinAt.rpow_const (hf : ContinuousWithinAt f s x) (h : f x β‰  0 ∨ 0 ≀ p) : ContinuousWithinAt (fun x => f x ^ p) s x := hf.rpow_const h nonrec theorem ContinuousAt.rpow_const (hf : ContinuousAt f x) (h : f x β‰  0 ∨ 0 ≀ p) : ContinuousAt (fun x => f x ^ p) x := hf.rpow_const h theorem ContinuousOn.rpow_const (hf : ContinuousOn f s) (h : βˆ€ x ∈ s, f x β‰  0 ∨ 0 ≀ p) : ContinuousOn (fun x => f x ^ p) s := fun x hx => (hf x hx).rpow_const (h x hx) theorem Continuous.rpow_const (hf : Continuous f) (h : βˆ€ x, f x β‰  0 ∨ 0 ≀ p) : Continuous fun x => f x ^ p := continuous_iff_continuousAt.2 fun x => hf.continuousAt.rpow_const (h x) end end RpowLimits /-! ## Continuity results for `cpow`, part II These results involve relating real and complex powers, so cannot be done higher up. -/ section CpowLimits2 namespace Complex /-- See also `continuousAt_cpow` and `Complex.continuousAt_cpow_of_re_pos`. -/ theorem continuousAt_cpow_zero_of_re_pos {z : β„‚} (hz : 0 < z.re) : ContinuousAt (fun x : β„‚ Γ— β„‚ => x.1 ^ x.2) (0, z) := by have hzβ‚€ : z β‰  0 := ne_of_apply_ne re hz.ne' rw [ContinuousAt, zero_cpow hzβ‚€, tendsto_zero_iff_norm_tendsto_zero] refine squeeze_zero (fun _ => norm_nonneg _) (fun _ => norm_cpow_le _ _) ?_ simp only [div_eq_mul_inv, ← Real.exp_neg] refine Tendsto.zero_mul_isBoundedUnder_le ?_ ?_ Β· convert (continuous_fst.norm.tendsto ((0 : β„‚), z)).rpow ((continuous_re.comp continuous_snd).tendsto _) _ <;> simp [hz, Real.zero_rpow hz.ne'] Β· simp only [Function.comp_def, Real.norm_eq_abs, abs_of_pos (Real.exp_pos _)] rcases exists_gt |im z| with ⟨C, hC⟩ refine ⟨Real.exp (Ο€ * C), eventually_map.2 ?_⟩ refine (((continuous_im.comp continuous_snd).abs.tendsto (_, z)).eventually (gt_mem_nhds hC)).mono fun z hz => Real.exp_le_exp.2 <| (neg_le_abs _).trans ?_ rw [_root_.abs_mul] exact mul_le_mul (abs_le.2 ⟨(neg_pi_lt_arg _).le, arg_le_pi _⟩) hz.le (_root_.abs_nonneg _) Real.pi_pos.le open ComplexOrder in /-- See also `continuousAt_cpow` for a version that assumes `p.1 β‰  0` but makes no assumptions about `p.2`. -/ theorem continuousAt_cpow_of_re_pos {p : β„‚ Γ— β„‚} (h₁ : 0 ≀ p.1.re ∨ p.1.im β‰  0) (hβ‚‚ : 0 < p.2.re) : ContinuousAt (fun x : β„‚ Γ— β„‚ => x.1 ^ x.2) p := by obtain ⟨z, w⟩ := p rw [← not_lt_zero_iff, lt_iff_le_and_ne, not_and_or, Ne, Classical.not_not, not_le_zero_iff] at h₁ rcases h₁ with (h₁ | (rfl : z = 0)) exacts [continuousAt_cpow h₁, continuousAt_cpow_zero_of_re_pos hβ‚‚] /-- See also `continuousAt_cpow_const` for a version that assumes `z β‰  0` but makes no assumptions about `w`. -/ theorem continuousAt_cpow_const_of_re_pos {z w : β„‚} (hz : 0 ≀ re z ∨ im z β‰  0) (hw : 0 < re w) : ContinuousAt (fun x => x ^ w) z := Tendsto.comp (@continuousAt_cpow_of_re_pos (z, w) hz hw) (continuousAt_id.prodMk continuousAt_const) /-- Continuity of `(x, y) ↦ x ^ y` as a function on `ℝ Γ— β„‚`. -/ theorem continuousAt_ofReal_cpow (x : ℝ) (y : β„‚) (h : 0 < y.re ∨ x β‰  0) : ContinuousAt (fun p => (p.1 : β„‚) ^ p.2 : ℝ Γ— β„‚ β†’ β„‚) (x, y) := by rcases lt_trichotomy (0 : ℝ) x with (hx | rfl | hx) Β· -- x > 0 : easy case have : ContinuousAt (fun p => βŸ¨β†‘p.1, p.2⟩ : ℝ Γ— β„‚ β†’ β„‚ Γ— β„‚) (x, y) := by fun_prop refine (continuousAt_cpow (Or.inl ?_)).comp this rwa [ofReal_re] Β· -- x = 0 : reduce to continuousAt_cpow_zero_of_re_pos have A : ContinuousAt (fun p => p.1 ^ p.2 : β„‚ Γ— β„‚ β†’ β„‚) βŸ¨β†‘(0 : ℝ), y⟩ := by rw [ofReal_zero] apply continuousAt_cpow_zero_of_re_pos tauto have B : ContinuousAt (fun p => βŸ¨β†‘p.1, p.2⟩ : ℝ Γ— β„‚ β†’ β„‚ Γ— β„‚) ⟨0, y⟩ := by fun_prop exact A.comp_of_eq B rfl Β· -- x < 0 : difficult case suffices ContinuousAt (fun p => (-(p.1 : β„‚)) ^ p.2 * exp (Ο€ * I * p.2) : ℝ Γ— β„‚ β†’ β„‚) (x, y) by refine this.congr (eventually_of_mem (prod_mem_nhds (Iio_mem_nhds hx) univ_mem) ?_) exact fun p hp => (ofReal_cpow_of_nonpos (le_of_lt hp.1) p.2).symm have A : ContinuousAt (fun p => ⟨-↑p.1, p.2⟩ : ℝ Γ— β„‚ β†’ β„‚ Γ— β„‚) (x, y) := by fun_prop apply ContinuousAt.mul Β· refine (continuousAt_cpow (Or.inl ?_)).comp A rwa [neg_re, ofReal_re, neg_pos] Β· exact (continuous_exp.comp (continuous_const.mul continuous_snd)).continuousAt theorem continuousAt_ofReal_cpow_const (x : ℝ) (y : β„‚) (h : 0 < y.re ∨ x β‰  0) : ContinuousAt (fun a => (a : β„‚) ^ y : ℝ β†’ β„‚) x := (continuousAt_ofReal_cpow x y h).compβ‚‚_of_eq (by fun_prop) (by fun_prop) rfl theorem continuous_ofReal_cpow_const {y : β„‚} (hs : 0 < y.re) : Continuous (fun x => (x : β„‚) ^ y : ℝ β†’ β„‚) := continuous_iff_continuousAt.mpr fun x => continuousAt_ofReal_cpow_const x y (Or.inl hs) end Complex end CpowLimits2 /-! ## Limits and continuity for `ℝβ‰₯0` powers -/ namespace NNReal theorem continuousAt_rpow {x : ℝβ‰₯0} {y : ℝ} (h : x β‰  0 ∨ 0 < y) : ContinuousAt (fun p : ℝβ‰₯0 Γ— ℝ => p.1 ^ p.2) (x, y) := by have : (fun p : ℝβ‰₯0 Γ— ℝ => p.1 ^ p.2) = Real.toNNReal ∘ (fun p : ℝ Γ— ℝ => p.1 ^ p.2) ∘ fun p : ℝβ‰₯0 Γ— ℝ => (p.1.1, p.2) := by ext p simp only [coe_rpow, val_eq_coe, Function.comp_apply, coe_toNNReal', left_eq_sup] exact_mod_cast zero_le (p.1 ^ p.2) rw [this] refine continuous_real_toNNReal.continuousAt.comp (ContinuousAt.comp ?_ ?_) Β· apply Real.continuousAt_rpow simpa using h Β· fun_prop theorem eventually_pow_one_div_le (x : ℝβ‰₯0) {y : ℝβ‰₯0} (hy : 1 < y) : βˆ€αΆ  n : β„• in atTop, x ^ (1 / n : ℝ) ≀ y := by obtain ⟨m, hm⟩ := add_one_pow_unbounded_of_pos x (tsub_pos_of_lt hy) rw [tsub_add_cancel_of_le hy.le] at hm refine eventually_atTop.2 ⟨m + 1, fun n hn => ?_⟩ simp only [one_div] simpa only [NNReal.rpow_inv_le_iff (Nat.cast_pos.2 <| m.succ_pos.trans_le hn), NNReal.rpow_natCast] using hm.le.trans (pow_right_monoβ‚€ hy.le (m.le_succ.trans hn)) end NNReal open Filter theorem Filter.Tendsto.nnrpow {Ξ± : Type*} {f : Filter Ξ±} {u : Ξ± β†’ ℝβ‰₯0} {v : Ξ± β†’ ℝ} {x : ℝβ‰₯0} {y : ℝ} (hx : Tendsto u f (𝓝 x)) (hy : Tendsto v f (𝓝 y)) (h : x β‰  0 ∨ 0 < y) : Tendsto (fun a => u a ^ v a) f (𝓝 (x ^ y)) := Tendsto.comp (NNReal.continuousAt_rpow h) (hx.prodMk_nhds hy) namespace NNReal theorem continuousAt_rpow_const {x : ℝβ‰₯0} {y : ℝ} (h : x β‰  0 ∨ 0 ≀ y) : ContinuousAt (fun z => z ^ y) x := h.elim (fun h => tendsto_id.nnrpow tendsto_const_nhds (Or.inl h)) fun h => h.eq_or_lt.elim (fun h => h β–Έ by simp only [rpow_zero, continuousAt_const]) fun h => tendsto_id.nnrpow tendsto_const_nhds (Or.inr h) @[fun_prop] theorem continuous_rpow_const {y : ℝ} (h : 0 ≀ y) : Continuous fun x : ℝβ‰₯0 => x ^ y := continuous_iff_continuousAt.2 fun _ => continuousAt_rpow_const (Or.inr h) @[fun_prop] theorem continuousOn_rpow_const_compl_zero {r : ℝ} : ContinuousOn (fun z : ℝβ‰₯0 => z ^ r) {0}ᢜ := fun _ h => ContinuousAt.continuousWithinAt <| NNReal.continuousAt_rpow_const (.inl h) -- even though this follows from `ContinuousOn.mono` and the previous lemma, we include it for -- automation purposes with `fun_prop`, because the side goal `0 βˆ‰ s ∨ 0 ≀ r` is often easy to check @[fun_prop] theorem continuousOn_rpow_const {r : ℝ} {s : Set ℝβ‰₯0} (h : 0 βˆ‰ s ∨ 0 ≀ r) : ContinuousOn (fun z : ℝβ‰₯0 => z ^ r) s := h.elim (fun _ ↦ ContinuousOn.mono (s := {0}ᢜ) (by fun_prop) (by simp_all)) (NNReal.continuous_rpow_const Β· |>.continuousOn) end NNReal /-! ## Continuity for `ℝβ‰₯0∞` powers -/ namespace ENNReal theorem eventually_pow_one_div_le {x : ℝβ‰₯0∞} (hx : x β‰  ∞) {y : ℝβ‰₯0∞} (hy : 1 < y) : βˆ€αΆ  n : β„• in atTop, x ^ (1 / n : ℝ) ≀ y := by lift x to ℝβ‰₯0 using hx by_cases h : y = ∞ Β· exact Eventually.of_forall fun n => h.symm β–Έ le_top Β· lift y to ℝβ‰₯0 using h have := NNReal.eventually_pow_one_div_le x (mod_cast hy : 1 < y) refine this.congr (Eventually.of_forall fun n => ?_) rw [← coe_rpow_of_nonneg x (by positivity : 0 ≀ (1 / n : ℝ)), coe_le_coe] private theorem continuousAt_rpow_const_of_pos {x : ℝβ‰₯0∞} {y : ℝ} (h : 0 < y) : ContinuousAt (fun a : ℝβ‰₯0∞ => a ^ y) x := by by_cases hx : x = ⊀ Β· rw [hx, ContinuousAt] convert ENNReal.tendsto_rpow_at_top h simp [h] lift x to ℝβ‰₯0 using hx rw [continuousAt_coe_iff] convert continuous_coe.continuousAt.comp (NNReal.continuousAt_rpow_const (Or.inr h.le)) using 1 ext1 x simp [← coe_rpow_of_nonneg _ h.le] @[continuity, fun_prop] theorem continuous_rpow_const {y : ℝ} : Continuous fun a : ℝβ‰₯0∞ => a ^ y := by refine continuous_iff_continuousAt.2 fun x => ?_ rcases lt_trichotomy (0 : ℝ) y with (hy | rfl | hy) Β· exact continuousAt_rpow_const_of_pos hy Β· simp only [rpow_zero] exact continuousAt_const Β· obtain ⟨z, hz⟩ : βˆƒ z, y = -z := ⟨-y, (neg_neg _).symm⟩ have z_pos : 0 < z := by simpa [hz] using hy simp_rw [hz, rpow_neg] exact continuous_inv.continuousAt.comp (continuousAt_rpow_const_of_pos z_pos) theorem tendsto_const_mul_rpow_nhds_zero_of_pos {c : ℝβ‰₯0∞} (hc : c β‰  ∞) {y : ℝ} (hy : 0 < y) : Tendsto (fun x : ℝβ‰₯0∞ => c * x ^ y) (𝓝 0) (𝓝 0) := by convert ENNReal.Tendsto.const_mul (ENNReal.continuous_rpow_const.tendsto 0) _ Β· simp [hy] Β· exact Or.inr hc end ENNReal theorem Filter.Tendsto.ennrpow_const {Ξ± : Type*} {f : Filter Ξ±} {m : Ξ± β†’ ℝβ‰₯0∞} {a : ℝβ‰₯0∞} (r : ℝ) (hm : Tendsto m f (𝓝 a)) : Tendsto (fun x => m x ^ r) f (𝓝 (a ^ r)) := (ENNReal.continuous_rpow_const.tendsto a).comp hm
.lake/packages/mathlib/Mathlib/Analysis/SpecialFunctions/Pow/Complex.lean
import Mathlib.Analysis.SpecialFunctions.Complex.Log /-! # Power function on `β„‚` We construct the power functions `x ^ y`, where `x` and `y` are complex numbers. -/ open Real Topology Filter ComplexConjugate Finset Set namespace Complex /-- The complex power function `x ^ y`, given by `x ^ y = exp(y log x)` (where `log` is the principal determination of the logarithm), unless `x = 0` where one sets `0 ^ 0 = 1` and `0 ^ y = 0` for `y β‰  0`. -/ noncomputable def cpow (x y : β„‚) : β„‚ := if x = 0 then if y = 0 then 1 else 0 else exp (log x * y) noncomputable instance : Pow β„‚ β„‚ := ⟨cpow⟩ @[simp] theorem cpow_eq_pow (x y : β„‚) : cpow x y = x ^ y := rfl theorem cpow_def (x y : β„‚) : x ^ y = if x = 0 then if y = 0 then 1 else 0 else exp (log x * y) := rfl theorem cpow_def_of_ne_zero {x : β„‚} (hx : x β‰  0) (y : β„‚) : x ^ y = exp (log x * y) := if_neg hx @[simp] theorem cpow_zero (x : β„‚) : x ^ (0 : β„‚) = 1 := by simp [cpow_def] @[simp] theorem cpow_eq_zero_iff (x y : β„‚) : x ^ y = 0 ↔ x = 0 ∧ y β‰  0 := by simp only [cpow_def] split_ifs <;> simp [*, exp_ne_zero] theorem cpow_ne_zero_iff {x y : β„‚} : x ^ y β‰  0 ↔ x β‰  0 ∨ y = 0 := by rw [ne_eq, cpow_eq_zero_iff, not_and_or, ne_eq, not_not] theorem cpow_ne_zero_iff_of_exponent_ne_zero {x y : β„‚} (hy : y β‰  0) : x ^ y β‰  0 ↔ x β‰  0 := by simp [hy] @[simp] theorem zero_cpow {x : β„‚} (h : x β‰  0) : (0 : β„‚) ^ x = 0 := by simp [cpow_def, *] theorem zero_cpow_eq_iff {x : β„‚} {a : β„‚} : (0 : β„‚) ^ x = a ↔ x β‰  0 ∧ a = 0 ∨ x = 0 ∧ a = 1 := by constructor Β· intro hyp simp only [cpow_def, if_true] at hyp grind Β· rintro (⟨h, rfl⟩ | ⟨rfl, rfl⟩) Β· exact zero_cpow h Β· exact cpow_zero _ theorem eq_zero_cpow_iff {x : β„‚} {a : β„‚} : a = (0 : β„‚) ^ x ↔ x β‰  0 ∧ a = 0 ∨ x = 0 ∧ a = 1 := by rw [← zero_cpow_eq_iff, eq_comm] @[simp] theorem cpow_one (x : β„‚) : x ^ (1 : β„‚) = x := if hx : x = 0 then by simp [hx, cpow_def] else by rw [cpow_def, if_neg (one_ne_zero : (1 : β„‚) β‰  0), if_neg hx, mul_one, exp_log hx] @[simp] theorem one_cpow (x : β„‚) : (1 : β„‚) ^ x = 1 := by rw [cpow_def] split_ifs <;> simp_all [one_ne_zero] theorem cpow_add {x : β„‚} (y z : β„‚) (hx : x β‰  0) : x ^ (y + z) = x ^ y * x ^ z := by simp only [cpow_def, ite_mul, mul_ite] simp_all [exp_add, mul_add] theorem cpow_mul {x y : β„‚} (z : β„‚) (h₁ : -Ο€ < (log x * y).im) (hβ‚‚ : (log x * y).im ≀ Ο€) : x ^ (y * z) = (x ^ y) ^ z := by simp only [cpow_def] split_ifs <;> simp_all [exp_ne_zero, log_exp h₁ hβ‚‚, mul_assoc] theorem cpow_neg (x y : β„‚) : x ^ (-y) = (x ^ y)⁻¹ := by simp only [cpow_def, neg_eq_zero, mul_neg] split_ifs <;> simp [exp_neg] theorem cpow_sub {x : β„‚} (y z : β„‚) (hx : x β‰  0) : x ^ (y - z) = x ^ y / x ^ z := by rw [sub_eq_add_neg, cpow_add _ _ hx, cpow_neg, div_eq_mul_inv] theorem cpow_neg_one (x : β„‚) : x ^ (-1 : β„‚) = x⁻¹ := by simpa using cpow_neg x 1 /-- See also `Complex.cpow_int_mul'`. -/ lemma cpow_int_mul (x : β„‚) (n : β„€) (y : β„‚) : x ^ (n * y) = (x ^ y) ^ n := by rcases eq_or_ne x 0 with rfl | hx Β· rcases eq_or_ne n 0 with rfl | hn Β· simp Β· rcases eq_or_ne y 0 with rfl | hy <;> simp [*, zero_zpow] Β· rw [cpow_def_of_ne_zero hx, cpow_def_of_ne_zero hx, mul_left_comm, exp_int_mul] lemma cpow_mul_int (x y : β„‚) (n : β„€) : x ^ (y * n) = (x ^ y) ^ n := by rw [mul_comm, cpow_int_mul] lemma cpow_nat_mul (x : β„‚) (n : β„•) (y : β„‚) : x ^ (n * y) = (x ^ y) ^ n := mod_cast cpow_int_mul x n y lemma cpow_ofNat_mul (x : β„‚) (n : β„•) [n.AtLeastTwo] (y : β„‚) : x ^ (ofNat(n) * y) = (x ^ y) ^ ofNat(n) := cpow_nat_mul x n y lemma cpow_mul_nat (x y : β„‚) (n : β„•) : x ^ (y * n) = (x ^ y) ^ n := by rw [mul_comm, cpow_nat_mul] lemma cpow_mul_ofNat (x y : β„‚) (n : β„•) [n.AtLeastTwo] : x ^ (y * ofNat(n)) = (x ^ y) ^ ofNat(n) := cpow_mul_nat x y n @[simp, norm_cast] theorem cpow_natCast (x : β„‚) (n : β„•) : x ^ (n : β„‚) = x ^ n := by simpa using cpow_nat_mul x n 1 @[simp] lemma cpow_ofNat (x : β„‚) (n : β„•) [n.AtLeastTwo] : x ^ (ofNat(n) : β„‚) = x ^ ofNat(n) := cpow_natCast x n theorem cpow_two (x : β„‚) : x ^ (2 : β„‚) = x ^ (2 : β„•) := cpow_ofNat x 2 @[simp, norm_cast] theorem cpow_intCast (x : β„‚) (n : β„€) : x ^ (n : β„‚) = x ^ n := by simpa using cpow_int_mul x n 1 @[simp] theorem cpow_nat_inv_pow (x : β„‚) {n : β„•} (hn : n β‰  0) : (x ^ (n⁻¹ : β„‚)) ^ n = x := by rw [← cpow_nat_mul, mul_inv_cancelβ‚€, cpow_one] assumption_mod_cast @[simp] lemma cpow_ofNat_inv_pow (x : β„‚) (n : β„•) [n.AtLeastTwo] : (x ^ ((ofNat(n) : β„‚)⁻¹)) ^ (ofNat(n) : β„•) = x := cpow_nat_inv_pow _ (NeZero.ne n) /-- A version of `Complex.cpow_int_mul` with RHS that matches `Complex.cpow_mul`. The assumptions on the arguments are needed because the equality fails, e.g., for `x = -I`, `n = 2`, `y = 1/2`. -/ lemma cpow_int_mul' {x : β„‚} {n : β„€} (hlt : -Ο€ < n * x.arg) (hle : n * x.arg ≀ Ο€) (y : β„‚) : x ^ (n * y) = (x ^ n) ^ y := by rw [mul_comm] at hlt hle rw [cpow_mul, cpow_intCast] <;> simpa [log_im] /-- A version of `Complex.cpow_nat_mul` with RHS that matches `Complex.cpow_mul`. The assumptions on the arguments are needed because the equality fails, e.g., for `x = -I`, `n = 2`, `y = 1/2`. -/ lemma cpow_nat_mul' {x : β„‚} {n : β„•} (hlt : -Ο€ < n * x.arg) (hle : n * x.arg ≀ Ο€) (y : β„‚) : x ^ (n * y) = (x ^ n) ^ y := cpow_int_mul' hlt hle y lemma cpow_ofNat_mul' {x : β„‚} {n : β„•} [n.AtLeastTwo] (hlt : -Ο€ < OfNat.ofNat n * x.arg) (hle : OfNat.ofNat n * x.arg ≀ Ο€) (y : β„‚) : x ^ (OfNat.ofNat n * y) = (x ^ ofNat(n)) ^ y := cpow_nat_mul' hlt hle y lemma pow_cpow_nat_inv {x : β„‚} {n : β„•} (hβ‚€ : n β‰  0) (hlt : -(Ο€ / n) < x.arg) (hle : x.arg ≀ Ο€ / n) : (x ^ n) ^ (n⁻¹ : β„‚) = x := by rw [← cpow_nat_mul', mul_inv_cancelβ‚€ (Nat.cast_ne_zero.2 hβ‚€), cpow_one] Β· rwa [← div_lt_iffβ‚€' (Nat.cast_pos.2 hβ‚€.bot_lt), neg_div] Β· rwa [← le_div_iffβ‚€' (Nat.cast_pos.2 hβ‚€.bot_lt)] lemma pow_cpow_ofNat_inv {x : β„‚} {n : β„•} [n.AtLeastTwo] (hlt : -(Ο€ / OfNat.ofNat n) < x.arg) (hle : x.arg ≀ Ο€ / OfNat.ofNat n) : (x ^ ofNat(n)) ^ ((OfNat.ofNat n : β„‚)⁻¹) = x := pow_cpow_nat_inv (NeZero.ne n) hlt hle /-- See also `Complex.pow_cpow_ofNat_inv` for a version that also works for `x * I`, `0 ≀ x`. -/ lemma sq_cpow_two_inv {x : β„‚} (hx : 0 < x.re) : (x ^ (2 : β„•)) ^ (2⁻¹ : β„‚) = x := pow_cpow_ofNat_inv (neg_pi_div_two_lt_arg_iff.2 <| .inl hx) (arg_le_pi_div_two_iff.2 <| .inl hx.le) @[simp] lemma isSquare (x : β„‚) : IsSquare x := ⟨x ^ (2⁻¹ : β„‚), by simp [← sq]⟩ theorem mul_cpow_ofReal_nonneg {a b : ℝ} (ha : 0 ≀ a) (hb : 0 ≀ b) (r : β„‚) : ((a : β„‚) * (b : β„‚)) ^ r = (a : β„‚) ^ r * (b : β„‚) ^ r := by rcases eq_or_ne r 0 with (rfl | hr) Β· simp only [cpow_zero, mul_one] rcases eq_or_lt_of_le ha with (rfl | ha') Β· rw [ofReal_zero, zero_mul, zero_cpow hr, zero_mul] rcases eq_or_lt_of_le hb with (rfl | hb') Β· rw [ofReal_zero, mul_zero, zero_cpow hr, mul_zero] have ha'' : (a : β„‚) β‰  0 := ofReal_ne_zero.mpr ha'.ne' have hb'' : (b : β„‚) β‰  0 := ofReal_ne_zero.mpr hb'.ne' rw [cpow_def_of_ne_zero (mul_ne_zero ha'' hb''), log_ofReal_mul ha' hb'', ofReal_log ha, add_mul, exp_add, ← cpow_def_of_ne_zero ha'', ← cpow_def_of_ne_zero hb''] lemma natCast_mul_natCast_cpow (m n : β„•) (s : β„‚) : (m * n : β„‚) ^ s = m ^ s * n ^ s := ofReal_natCast m β–Έ ofReal_natCast n β–Έ mul_cpow_ofReal_nonneg m.cast_nonneg n.cast_nonneg s lemma natCast_cpow_natCast_mul (n m : β„•) (z : β„‚) : (n : β„‚) ^ (m * z) = ((n : β„‚) ^ m) ^ z := by refine cpow_nat_mul' (x := n) (n := m) ?_ ?_ z Β· simp only [natCast_arg, mul_zero, Left.neg_neg_iff, pi_pos] Β· simp only [natCast_arg, mul_zero, pi_pos.le] theorem inv_cpow_eq_ite (x : β„‚) (n : β„‚) : x⁻¹ ^ n = if x.arg = Ο€ then conj (x ^ conj n)⁻¹ else (x ^ n)⁻¹ := by simp_rw [Complex.cpow_def, log_inv_eq_ite, inv_eq_zero, map_eq_zero, ite_mul, neg_mul, RCLike.conj_inv, apply_ite conj, apply_ite exp, apply_ite Inv.inv, map_zero, map_one, exp_neg, inv_one, inv_zero, ← exp_conj, map_mul, conj_conj] split_ifs with hx hn ha ha <;> rfl theorem inv_cpow (x : β„‚) (n : β„‚) (hx : x.arg β‰  Ο€) : x⁻¹ ^ n = (x ^ n)⁻¹ := by rw [inv_cpow_eq_ite, if_neg hx] /-- `Complex.inv_cpow_eq_ite` with the `ite` on the other side. -/ theorem inv_cpow_eq_ite' (x : β„‚) (n : β„‚) : (x ^ n)⁻¹ = if x.arg = Ο€ then conj (x⁻¹ ^ conj n) else x⁻¹ ^ n := by rw [inv_cpow_eq_ite, apply_ite conj, conj_conj, conj_conj] split_ifs with h Β· rfl Β· rw [inv_cpow _ _ h] theorem conj_cpow_eq_ite (x : β„‚) (n : β„‚) : conj x ^ n = if x.arg = Ο€ then x ^ n else conj (x ^ conj n) := by simp_rw [cpow_def, map_eq_zero, apply_ite conj, map_one, map_zero, ← exp_conj, map_mul, conj_conj, log_conj_eq_ite] split_ifs with hcx hn hx <;> rfl theorem conj_cpow (x : β„‚) (n : β„‚) (hx : x.arg β‰  Ο€) : conj x ^ n = conj (x ^ conj n) := by rw [conj_cpow_eq_ite, if_neg hx] theorem cpow_conj (x : β„‚) (n : β„‚) (hx : x.arg β‰  Ο€) : x ^ conj n = conj (conj x ^ n) := by rw [conj_cpow _ _ hx, conj_conj] lemma natCast_add_one_cpow_ne_zero (n : β„•) (z : β„‚) : (n + 1 : β„‚) ^ z β‰  0 := mt (cpow_eq_zero_iff ..).mp fun H ↦ by norm_cast at H; exact H.1 end Complex -- section Tactics -- /-! -- ## Tactic extensions for complex powers -- -/ -- namespace NormNum -- theorem cpow_pos (a b : β„‚) (b' : β„•) (c : β„‚) (hb : b = b') (h : a ^ b' = c) : a ^ b = c := by -- rw [← h, hb, Complex.cpow_natCast] -- theorem cpow_neg (a b : β„‚) (b' : β„•) (c c' : β„‚) (hb : b = b') (h : a ^ b' = c) (hc : c⁻¹ = c') : -- a ^ (-b) = c' := by rw [← hc, ← h, hb, Complex.cpow_neg, Complex.cpow_natCast] -- open Tactic -- /-- Generalized version of `prove_cpow`, `prove_nnrpow`, `prove_ennrpow`. -/ -- unsafe def prove_rpow' (pos neg zero : Name) (Ξ± Ξ² one a b : expr) : tactic (expr Γ— expr) := do -- let na ← a.to_rat -- let icΞ± ← mk_instance_cache Ξ± -- let icΞ² ← mk_instance_cache Ξ² -- match match_sign b with -- | Sum.inl b => do -- let nc ← mk_instance_cache q(β„•) -- let (icΞ², nc, b', hb) ← prove_nat_uncast icΞ² nc b -- let (icΞ±, c, h) ← prove_pow a na icΞ± b' -- let cr ← c -- let (icΞ±, c', hc) ← prove_inv icΞ± c cr -- pure (c', (expr.const neg []).mk_app [a, b, b', c, c', hb, h, hc]) -- | Sum.inr ff => pure (one, expr.const zero [] a) -- | Sum.inr tt => do -- let nc ← mk_instance_cache q(β„•) -- let (icΞ², nc, b', hb) ← prove_nat_uncast icΞ² nc b -- let (icΞ±, c, h) ← prove_pow a na icΞ± b' -- pure (c, (expr.const Pos []).mk_app [a, b, b', c, hb, h]) -- /-- Evaluate `Complex.cpow a b` where `a` is a rational numeral and `b` is an integer. -/ -- unsafe def prove_cpow : expr β†’ expr β†’ tactic (expr Γ— expr) := -- prove_rpow' `` cpow_pos `` cpow_neg `` Complex.cpow_zero q(β„‚) q(β„‚) q((1 : β„‚)) -- /-- Evaluates expressions of the form `cpow a b` and `a ^ b` in the special case where -- `b` is an integer and `a` is a positive rational (so it's really just a rational power). -/ -- @[norm_num] -- unsafe def eval_cpow : expr β†’ tactic (expr Γ— expr) -- | q(@Pow.pow _ _ Complex.hasPow $(a) $(b)) => b.to_int >> prove_cpow a b -- | q(Complex.cpow $(a) $(b)) => b.to_int >> prove_cpow a b -- | _ => tactic.failed -- end NormNum -- end Tactics
.lake/packages/mathlib/Mathlib/Analysis/SpecialFunctions/Pow/NNReal.lean
import Mathlib.Analysis.SpecialFunctions.Pow.Real /-! # Power function on `ℝβ‰₯0` and `ℝβ‰₯0∞` We construct the power functions `x ^ y` where * `x` is a nonnegative real number and `y` is a real number; * `x` is a number from `[0, +∞]` (a.k.a. `ℝβ‰₯0∞`) and `y` is a real number. We also prove basic properties of these functions. -/ noncomputable section open Real NNReal ENNReal ComplexConjugate Finset Function Set namespace NNReal variable {x : ℝβ‰₯0} {w y z : ℝ} /-- The nonnegative real power function `x^y`, defined for `x : ℝβ‰₯0` and `y : ℝ` as the restriction of the real power function. For `x > 0`, it is equal to `exp (y log x)`. For `x = 0`, one sets `0 ^ 0 = 1` and `0 ^ y = 0` for `y β‰  0`. -/ noncomputable def rpow (x : ℝβ‰₯0) (y : ℝ) : ℝβ‰₯0 := ⟨(x : ℝ) ^ y, Real.rpow_nonneg x.2 y⟩ noncomputable instance : Pow ℝβ‰₯0 ℝ := ⟨rpow⟩ @[simp] theorem rpow_eq_pow (x : ℝβ‰₯0) (y : ℝ) : rpow x y = x ^ y := rfl @[simp, norm_cast] theorem coe_rpow (x : ℝβ‰₯0) (y : ℝ) : ((x ^ y : ℝβ‰₯0) : ℝ) = (x : ℝ) ^ y := rfl @[simp] theorem rpow_zero (x : ℝβ‰₯0) : x ^ (0 : ℝ) = 1 := NNReal.eq <| Real.rpow_zero _ theorem rpow_zero_pos (x : ℝβ‰₯0) : 0 < x ^ (0 : ℝ) := by rw [rpow_zero]; exact one_pos @[simp] theorem rpow_eq_zero_iff {x : ℝβ‰₯0} {y : ℝ} : x ^ y = 0 ↔ x = 0 ∧ y β‰  0 := by rw [← NNReal.coe_inj, coe_rpow, ← NNReal.coe_eq_zero] exact Real.rpow_eq_zero_iff_of_nonneg x.2 lemma rpow_eq_zero (hy : y β‰  0) : x ^ y = 0 ↔ x = 0 := by simp [hy] @[simp] theorem zero_rpow {x : ℝ} (h : x β‰  0) : (0 : ℝβ‰₯0) ^ x = 0 := NNReal.eq <| Real.zero_rpow h @[simp] theorem rpow_one (x : ℝβ‰₯0) : x ^ (1 : ℝ) = x := NNReal.eq <| Real.rpow_one _ lemma rpow_neg (x : ℝβ‰₯0) (y : ℝ) : x ^ (-y) = (x ^ y)⁻¹ := NNReal.eq <| Real.rpow_neg x.2 _ @[simp, norm_cast] lemma rpow_natCast (x : ℝβ‰₯0) (n : β„•) : x ^ (n : ℝ) = x ^ n := NNReal.eq <| by simpa only [coe_rpow, coe_pow] using Real.rpow_natCast x n @[simp, norm_cast] lemma rpow_intCast (x : ℝβ‰₯0) (n : β„€) : x ^ (n : ℝ) = x ^ n := by cases n <;> simp only [Int.ofNat_eq_coe, Int.cast_natCast, rpow_natCast, zpow_natCast, Int.cast_negSucc, rpow_neg, zpow_negSucc] @[simp] theorem one_rpow (x : ℝ) : (1 : ℝβ‰₯0) ^ x = 1 := NNReal.eq <| Real.one_rpow _ theorem rpow_add {x : ℝβ‰₯0} (hx : x β‰  0) (y z : ℝ) : x ^ (y + z) = x ^ y * x ^ z := NNReal.eq <| Real.rpow_add ((NNReal.coe_pos.trans pos_iff_ne_zero).mpr hx) _ _ theorem rpow_add' (h : y + z β‰  0) (x : ℝβ‰₯0) : x ^ (y + z) = x ^ y * x ^ z := NNReal.eq <| Real.rpow_add' x.2 h lemma rpow_add_intCast (hx : x β‰  0) (y : ℝ) (n : β„€) : x ^ (y + n) = x ^ y * x ^ n := by ext; exact Real.rpow_add_intCast (mod_cast hx) _ _ lemma rpow_add_natCast (hx : x β‰  0) (y : ℝ) (n : β„•) : x ^ (y + n) = x ^ y * x ^ n := by ext; exact Real.rpow_add_natCast (mod_cast hx) _ _ lemma rpow_sub_intCast (hx : x β‰  0) (y : ℝ) (n : β„•) : x ^ (y - n) = x ^ y / x ^ n := by ext; exact Real.rpow_sub_intCast (mod_cast hx) _ _ lemma rpow_sub_natCast (hx : x β‰  0) (y : ℝ) (n : β„•) : x ^ (y - n) = x ^ y / x ^ n := by ext; exact Real.rpow_sub_natCast (mod_cast hx) _ _ lemma rpow_add_intCast' {n : β„€} (h : y + n β‰  0) (x : ℝβ‰₯0) : x ^ (y + n) = x ^ y * x ^ n := by ext; exact Real.rpow_add_intCast' (mod_cast x.2) h lemma rpow_add_natCast' {n : β„•} (h : y + n β‰  0) (x : ℝβ‰₯0) : x ^ (y + n) = x ^ y * x ^ n := by ext; exact Real.rpow_add_natCast' (mod_cast x.2) h lemma rpow_sub_intCast' {n : β„€} (h : y - n β‰  0) (x : ℝβ‰₯0) : x ^ (y - n) = x ^ y / x ^ n := by ext; exact Real.rpow_sub_intCast' (mod_cast x.2) h lemma rpow_sub_natCast' {n : β„•} (h : y - n β‰  0) (x : ℝβ‰₯0) : x ^ (y - n) = x ^ y / x ^ n := by ext; exact Real.rpow_sub_natCast' (mod_cast x.2) h lemma rpow_add_one (hx : x β‰  0) (y : ℝ) : x ^ (y + 1) = x ^ y * x := by simpa using rpow_add_natCast hx y 1 lemma rpow_sub_one (hx : x β‰  0) (y : ℝ) : x ^ (y - 1) = x ^ y / x := by simpa using rpow_sub_natCast hx y 1 lemma rpow_add_one' (h : y + 1 β‰  0) (x : ℝβ‰₯0) : x ^ (y + 1) = x ^ y * x := by rw [rpow_add' h, rpow_one] lemma rpow_one_add' (h : 1 + y β‰  0) (x : ℝβ‰₯0) : x ^ (1 + y) = x * x ^ y := by rw [rpow_add' h, rpow_one] theorem rpow_add_of_nonneg (x : ℝβ‰₯0) {y z : ℝ} (hy : 0 ≀ y) (hz : 0 ≀ z) : x ^ (y + z) = x ^ y * x ^ z := by ext; exact Real.rpow_add_of_nonneg x.2 hy hz /-- Variant of `NNReal.rpow_add'` that avoids having to prove `y + z = w` twice. -/ lemma rpow_of_add_eq (x : ℝβ‰₯0) (hw : w β‰  0) (h : y + z = w) : x ^ w = x ^ y * x ^ z := by rw [← h, rpow_add']; rwa [h] theorem rpow_mul (x : ℝβ‰₯0) (y z : ℝ) : x ^ (y * z) = (x ^ y) ^ z := NNReal.eq <| Real.rpow_mul x.2 y z lemma rpow_natCast_mul (x : ℝβ‰₯0) (n : β„•) (z : ℝ) : x ^ (n * z) = (x ^ n) ^ z := by rw [rpow_mul, rpow_natCast] lemma rpow_mul_natCast (x : ℝβ‰₯0) (y : ℝ) (n : β„•) : x ^ (y * n) = (x ^ y) ^ n := by rw [rpow_mul, rpow_natCast] lemma rpow_intCast_mul (x : ℝβ‰₯0) (n : β„€) (z : ℝ) : x ^ (n * z) = (x ^ n) ^ z := by rw [rpow_mul, rpow_intCast] lemma rpow_mul_intCast (x : ℝβ‰₯0) (y : ℝ) (n : β„€) : x ^ (y * n) = (x ^ y) ^ n := by rw [rpow_mul, rpow_intCast] theorem rpow_neg_one (x : ℝβ‰₯0) : x ^ (-1 : ℝ) = x⁻¹ := by simp [rpow_neg] theorem rpow_sub {x : ℝβ‰₯0} (hx : x β‰  0) (y z : ℝ) : x ^ (y - z) = x ^ y / x ^ z := NNReal.eq <| Real.rpow_sub ((NNReal.coe_pos.trans pos_iff_ne_zero).mpr hx) y z theorem rpow_sub' (h : y - z β‰  0) (x : ℝβ‰₯0) : x ^ (y - z) = x ^ y / x ^ z := NNReal.eq <| Real.rpow_sub' x.2 h lemma rpow_sub_one' (h : y - 1 β‰  0) (x : ℝβ‰₯0) : x ^ (y - 1) = x ^ y / x := by rw [rpow_sub' h, rpow_one] lemma rpow_one_sub' (h : 1 - y β‰  0) (x : ℝβ‰₯0) : x ^ (1 - y) = x / x ^ y := by rw [rpow_sub' h, rpow_one] theorem rpow_inv_rpow_self {y : ℝ} (hy : y β‰  0) (x : ℝβ‰₯0) : (x ^ y) ^ (1 / y) = x := by rw [← rpow_mul] field_simp simp theorem rpow_self_rpow_inv {y : ℝ} (hy : y β‰  0) (x : ℝβ‰₯0) : (x ^ (1 / y)) ^ y = x := by rw [← rpow_mul] field_simp simp theorem inv_rpow (x : ℝβ‰₯0) (y : ℝ) : x⁻¹ ^ y = (x ^ y)⁻¹ := NNReal.eq <| Real.inv_rpow x.2 y theorem div_rpow (x y : ℝβ‰₯0) (z : ℝ) : (x / y) ^ z = x ^ z / y ^ z := NNReal.eq <| Real.div_rpow x.2 y.2 z theorem sqrt_eq_rpow (x : ℝβ‰₯0) : sqrt x = x ^ (1 / (2 : ℝ)) := by refine NNReal.eq ?_ push_cast exact Real.sqrt_eq_rpow x.1 @[simp] lemma rpow_ofNat (x : ℝβ‰₯0) (n : β„•) [n.AtLeastTwo] : x ^ (ofNat(n) : ℝ) = x ^ (OfNat.ofNat n : β„•) := rpow_natCast x n theorem rpow_two (x : ℝβ‰₯0) : x ^ (2 : ℝ) = x ^ 2 := rpow_ofNat x 2 theorem mul_rpow {x y : ℝβ‰₯0} {z : ℝ} : (x * y) ^ z = x ^ z * y ^ z := NNReal.eq <| Real.mul_rpow x.2 y.2 /-- `rpow` as a `MonoidHom` -/ @[simps] def rpowMonoidHom (r : ℝ) : ℝβ‰₯0 β†’* ℝβ‰₯0 where toFun := (Β· ^ r) map_one' := one_rpow _ map_mul' _x _y := mul_rpow /-- `rpow` variant of `List.prod_map_pow` for `ℝβ‰₯0` -/ theorem list_prod_map_rpow (l : List ℝβ‰₯0) (r : ℝ) : (l.map (Β· ^ r)).prod = l.prod ^ r := l.prod_hom (rpowMonoidHom r) theorem list_prod_map_rpow' {ΞΉ} (l : List ΞΉ) (f : ΞΉ β†’ ℝβ‰₯0) (r : ℝ) : (l.map (f Β· ^ r)).prod = (l.map f).prod ^ r := by rw [← list_prod_map_rpow, List.map_map]; rfl /-- `rpow` version of `Multiset.prod_map_pow` for `ℝβ‰₯0`. -/ lemma multiset_prod_map_rpow {ΞΉ} (s : Multiset ΞΉ) (f : ΞΉ β†’ ℝβ‰₯0) (r : ℝ) : (s.map (f Β· ^ r)).prod = (s.map f).prod ^ r := s.prod_hom' (rpowMonoidHom r) _ /-- `rpow` version of `Finset.prod_pow` for `ℝβ‰₯0`. -/ lemma finset_prod_rpow {ΞΉ} (s : Finset ΞΉ) (f : ΞΉ β†’ ℝβ‰₯0) (r : ℝ) : (∏ i ∈ s, f i ^ r) = (∏ i ∈ s, f i) ^ r := multiset_prod_map_rpow _ _ _ -- note: these don't really belong here, but they're much easier to prove in terms of the above section Real /-- `rpow` version of `List.prod_map_pow` for `Real`. -/ theorem _root_.Real.list_prod_map_rpow (l : List ℝ) (hl : βˆ€ x ∈ l, (0 : ℝ) ≀ x) (r : ℝ) : (l.map (Β· ^ r)).prod = l.prod ^ r := by lift l to List ℝβ‰₯0 using hl have := congr_arg ((↑) : ℝβ‰₯0 β†’ ℝ) (NNReal.list_prod_map_rpow l r) push_cast at this rw [List.map_map] at this ⊒ exact mod_cast this theorem _root_.Real.list_prod_map_rpow' {ΞΉ} (l : List ΞΉ) (f : ΞΉ β†’ ℝ) (hl : βˆ€ i ∈ l, (0 : ℝ) ≀ f i) (r : ℝ) : (l.map (f Β· ^ r)).prod = (l.map f).prod ^ r := by rw [← Real.list_prod_map_rpow (l.map f) _ r, List.map_map] Β· rfl simpa using hl /-- `rpow` version of `Multiset.prod_map_pow`. -/ theorem _root_.Real.multiset_prod_map_rpow {ΞΉ} (s : Multiset ΞΉ) (f : ΞΉ β†’ ℝ) (hs : βˆ€ i ∈ s, (0 : ℝ) ≀ f i) (r : ℝ) : (s.map (f Β· ^ r)).prod = (s.map f).prod ^ r := by obtain ⟨l⟩ := s simpa using Real.list_prod_map_rpow' l f hs r /-- `rpow` version of `Finset.prod_pow`. -/ theorem _root_.Real.finset_prod_rpow {ΞΉ} (s : Finset ΞΉ) (f : ΞΉ β†’ ℝ) (hs : βˆ€ i ∈ s, 0 ≀ f i) (r : ℝ) : (∏ i ∈ s, f i ^ r) = (∏ i ∈ s, f i) ^ r := Real.multiset_prod_map_rpow s.val f hs r end Real @[gcongr] theorem rpow_le_rpow {x y : ℝβ‰₯0} {z : ℝ} (h₁ : x ≀ y) (hβ‚‚ : 0 ≀ z) : x ^ z ≀ y ^ z := Real.rpow_le_rpow x.2 h₁ hβ‚‚ @[gcongr] theorem rpow_lt_rpow {x y : ℝβ‰₯0} {z : ℝ} (h₁ : x < y) (hβ‚‚ : 0 < z) : x ^ z < y ^ z := Real.rpow_lt_rpow x.2 h₁ hβ‚‚ theorem rpow_lt_rpow_iff {x y : ℝβ‰₯0} {z : ℝ} (hz : 0 < z) : x ^ z < y ^ z ↔ x < y := Real.rpow_lt_rpow_iff x.2 y.2 hz theorem rpow_le_rpow_iff {x y : ℝβ‰₯0} {z : ℝ} (hz : 0 < z) : x ^ z ≀ y ^ z ↔ x ≀ y := Real.rpow_le_rpow_iff x.2 y.2 hz theorem le_rpow_inv_iff {x y : ℝβ‰₯0} {z : ℝ} (hz : 0 < z) : x ≀ y ^ z⁻¹ ↔ x ^ z ≀ y := by rw [← rpow_le_rpow_iff hz, ← one_div, rpow_self_rpow_inv hz.ne'] theorem rpow_inv_le_iff {x y : ℝβ‰₯0} {z : ℝ} (hz : 0 < z) : x ^ z⁻¹ ≀ y ↔ x ≀ y ^ z := by rw [← rpow_le_rpow_iff hz, ← one_div, rpow_self_rpow_inv hz.ne'] theorem lt_rpow_inv_iff {x y : ℝβ‰₯0} {z : ℝ} (hz : 0 < z) : x < y ^ z⁻¹ ↔ x ^z < y := by simp only [← not_le, rpow_inv_le_iff hz] theorem rpow_inv_lt_iff {x y : ℝβ‰₯0} {z : ℝ} (hz : 0 < z) : x ^ z⁻¹ < y ↔ x < y ^ z := by simp only [← not_le, le_rpow_inv_iff hz] section variable {y : ℝβ‰₯0} lemma rpow_lt_rpow_of_neg (hx : 0 < x) (hxy : x < y) (hz : z < 0) : y ^ z < x ^ z := Real.rpow_lt_rpow_of_neg hx hxy hz lemma rpow_le_rpow_of_nonpos (hx : 0 < x) (hxy : x ≀ y) (hz : z ≀ 0) : y ^ z ≀ x ^ z := Real.rpow_le_rpow_of_nonpos hx hxy hz lemma rpow_lt_rpow_iff_of_neg (hx : 0 < x) (hy : 0 < y) (hz : z < 0) : x ^ z < y ^ z ↔ y < x := Real.rpow_lt_rpow_iff_of_neg hx hy hz lemma rpow_le_rpow_iff_of_neg (hx : 0 < x) (hy : 0 < y) (hz : z < 0) : x ^ z ≀ y ^ z ↔ y ≀ x := Real.rpow_le_rpow_iff_of_neg hx hy hz lemma le_rpow_inv_iff_of_pos (hy : 0 ≀ y) (hz : 0 < z) (x : ℝβ‰₯0) : x ≀ y ^ z⁻¹ ↔ x ^ z ≀ y := Real.le_rpow_inv_iff_of_pos x.2 hy hz lemma rpow_inv_le_iff_of_pos (hy : 0 ≀ y) (hz : 0 < z) (x : ℝβ‰₯0) : x ^ z⁻¹ ≀ y ↔ x ≀ y ^ z := Real.rpow_inv_le_iff_of_pos x.2 hy hz lemma lt_rpow_inv_iff_of_pos (hy : 0 ≀ y) (hz : 0 < z) (x : ℝβ‰₯0) : x < y ^ z⁻¹ ↔ x ^ z < y := Real.lt_rpow_inv_iff_of_pos x.2 hy hz lemma rpow_inv_lt_iff_of_pos (hy : 0 ≀ y) (hz : 0 < z) (x : ℝβ‰₯0) : x ^ z⁻¹ < y ↔ x < y ^ z := Real.rpow_inv_lt_iff_of_pos x.2 hy hz lemma le_rpow_inv_iff_of_neg (hx : 0 < x) (hy : 0 < y) (hz : z < 0) : x ≀ y ^ z⁻¹ ↔ y ≀ x ^ z := Real.le_rpow_inv_iff_of_neg hx hy hz lemma lt_rpow_inv_iff_of_neg (hx : 0 < x) (hy : 0 < y) (hz : z < 0) : x < y ^ z⁻¹ ↔ y < x ^ z := Real.lt_rpow_inv_iff_of_neg hx hy hz lemma rpow_inv_lt_iff_of_neg (hx : 0 < x) (hy : 0 < y) (hz : z < 0) : x ^ z⁻¹ < y ↔ y ^ z < x := Real.rpow_inv_lt_iff_of_neg hx hy hz lemma rpow_inv_le_iff_of_neg (hx : 0 < x) (hy : 0 < y) (hz : z < 0) : x ^ z⁻¹ ≀ y ↔ y ^ z ≀ x := Real.rpow_inv_le_iff_of_neg hx hy hz end @[gcongr] theorem rpow_lt_rpow_of_exponent_lt {x : ℝβ‰₯0} {y z : ℝ} (hx : 1 < x) (hyz : y < z) : x ^ y < x ^ z := Real.rpow_lt_rpow_of_exponent_lt hx hyz @[gcongr] theorem rpow_le_rpow_of_exponent_le {x : ℝβ‰₯0} {y z : ℝ} (hx : 1 ≀ x) (hyz : y ≀ z) : x ^ y ≀ x ^ z := Real.rpow_le_rpow_of_exponent_le hx hyz theorem rpow_lt_rpow_of_exponent_gt {x : ℝβ‰₯0} {y z : ℝ} (hx0 : 0 < x) (hx1 : x < 1) (hyz : z < y) : x ^ y < x ^ z := Real.rpow_lt_rpow_of_exponent_gt hx0 hx1 hyz theorem rpow_le_rpow_of_exponent_ge {x : ℝβ‰₯0} {y z : ℝ} (hx0 : 0 < x) (hx1 : x ≀ 1) (hyz : z ≀ y) : x ^ y ≀ x ^ z := Real.rpow_le_rpow_of_exponent_ge hx0 hx1 hyz theorem rpow_pos {p : ℝ} {x : ℝβ‰₯0} (hx_pos : 0 < x) : 0 < x ^ p := by have rpow_pos_of_nonneg : βˆ€ {p : ℝ}, 0 < p β†’ 0 < x ^ p := by intro p hp_pos rw [← zero_rpow hp_pos.ne'] exact rpow_lt_rpow hx_pos hp_pos rcases lt_trichotomy (0 : ℝ) p with (hp_pos | rfl | hp_neg) Β· exact rpow_pos_of_nonneg hp_pos Β· simp only [zero_lt_one, rpow_zero] Β· rw [← neg_neg p, rpow_neg, inv_pos] exact rpow_pos_of_nonneg (neg_pos.mpr hp_neg) theorem rpow_lt_one {x : ℝβ‰₯0} {z : ℝ} (hx1 : x < 1) (hz : 0 < z) : x ^ z < 1 := Real.rpow_lt_one (coe_nonneg x) hx1 hz theorem rpow_le_one {x : ℝβ‰₯0} {z : ℝ} (hx2 : x ≀ 1) (hz : 0 ≀ z) : x ^ z ≀ 1 := Real.rpow_le_one x.2 hx2 hz theorem rpow_lt_one_of_one_lt_of_neg {x : ℝβ‰₯0} {z : ℝ} (hx : 1 < x) (hz : z < 0) : x ^ z < 1 := Real.rpow_lt_one_of_one_lt_of_neg hx hz theorem rpow_le_one_of_one_le_of_nonpos {x : ℝβ‰₯0} {z : ℝ} (hx : 1 ≀ x) (hz : z ≀ 0) : x ^ z ≀ 1 := Real.rpow_le_one_of_one_le_of_nonpos hx hz theorem one_lt_rpow {x : ℝβ‰₯0} {z : ℝ} (hx : 1 < x) (hz : 0 < z) : 1 < x ^ z := Real.one_lt_rpow hx hz theorem one_le_rpow {x : ℝβ‰₯0} {z : ℝ} (h : 1 ≀ x) (h₁ : 0 ≀ z) : 1 ≀ x ^ z := Real.one_le_rpow h h₁ theorem one_lt_rpow_of_pos_of_lt_one_of_neg {x : ℝβ‰₯0} {z : ℝ} (hx1 : 0 < x) (hx2 : x < 1) (hz : z < 0) : 1 < x ^ z := Real.one_lt_rpow_of_pos_of_lt_one_of_neg hx1 hx2 hz theorem one_le_rpow_of_pos_of_le_one_of_nonpos {x : ℝβ‰₯0} {z : ℝ} (hx1 : 0 < x) (hx2 : x ≀ 1) (hz : z ≀ 0) : 1 ≀ x ^ z := Real.one_le_rpow_of_pos_of_le_one_of_nonpos hx1 hx2 hz theorem rpow_le_self_of_le_one {x : ℝβ‰₯0} {z : ℝ} (hx : x ≀ 1) (h_one_le : 1 ≀ z) : x ^ z ≀ x := by rcases eq_bot_or_bot_lt x with (rfl | (h : 0 < x)) Β· have : z β‰  0 := by linarith simp [this] nth_rw 2 [← NNReal.rpow_one x] exact NNReal.rpow_le_rpow_of_exponent_ge h hx h_one_le theorem rpow_left_injective {x : ℝ} (hx : x β‰  0) : Function.Injective fun y : ℝβ‰₯0 => y ^ x := fun y z hyz => by simpa only [rpow_inv_rpow_self hx] using congr_arg (fun y => y ^ (1 / x)) hyz theorem rpow_eq_rpow_iff {x y : ℝβ‰₯0} {z : ℝ} (hz : z β‰  0) : x ^ z = y ^ z ↔ x = y := (rpow_left_injective hz).eq_iff theorem rpow_left_surjective {x : ℝ} (hx : x β‰  0) : Function.Surjective fun y : ℝβ‰₯0 => y ^ x := fun y => ⟨y ^ x⁻¹, by simp_rw [← rpow_mul, inv_mul_cancelβ‚€ hx, rpow_one]⟩ theorem rpow_left_bijective {x : ℝ} (hx : x β‰  0) : Function.Bijective fun y : ℝβ‰₯0 => y ^ x := ⟨rpow_left_injective hx, rpow_left_surjective hx⟩ theorem eq_rpow_inv_iff {x y : ℝβ‰₯0} {z : ℝ} (hz : z β‰  0) : x = y ^ z⁻¹ ↔ x ^ z = y := by rw [← rpow_eq_rpow_iff hz, ← one_div, rpow_self_rpow_inv hz] theorem rpow_inv_eq_iff {x y : ℝβ‰₯0} {z : ℝ} (hz : z β‰  0) : x ^ z⁻¹ = y ↔ x = y ^ z := by rw [← rpow_eq_rpow_iff hz, ← one_div, rpow_self_rpow_inv hz] @[simp] lemma rpow_rpow_inv {y : ℝ} (hy : y β‰  0) (x : ℝβ‰₯0) : (x ^ y) ^ y⁻¹ = x := by rw [← rpow_mul, mul_inv_cancelβ‚€ hy, rpow_one] @[simp] lemma rpow_inv_rpow {y : ℝ} (hy : y β‰  0) (x : ℝβ‰₯0) : (x ^ y⁻¹) ^ y = x := by rw [← rpow_mul, inv_mul_cancelβ‚€ hy, rpow_one] theorem pow_rpow_inv_natCast (x : ℝβ‰₯0) {n : β„•} (hn : n β‰  0) : (x ^ n) ^ (n⁻¹ : ℝ) = x := by rw [← NNReal.coe_inj, coe_rpow, NNReal.coe_pow] exact Real.pow_rpow_inv_natCast x.2 hn theorem rpow_inv_natCast_pow (x : ℝβ‰₯0) {n : β„•} (hn : n β‰  0) : (x ^ (n⁻¹ : ℝ)) ^ n = x := by rw [← NNReal.coe_inj, NNReal.coe_pow, coe_rpow] exact Real.rpow_inv_natCast_pow x.2 hn theorem _root_.Real.toNNReal_rpow_of_nonneg {x y : ℝ} (hx : 0 ≀ x) : Real.toNNReal (x ^ y) = Real.toNNReal x ^ y := by nth_rw 1 [← Real.coe_toNNReal x hx] rw [← NNReal.coe_rpow, Real.toNNReal_coe] theorem strictMono_rpow_of_pos {z : ℝ} (h : 0 < z) : StrictMono fun x : ℝβ‰₯0 => x ^ z := fun x y hxy => by simp only [NNReal.rpow_lt_rpow hxy h] theorem monotone_rpow_of_nonneg {z : ℝ} (h : 0 ≀ z) : Monotone fun x : ℝβ‰₯0 => x ^ z := h.eq_or_lt.elim (fun h0 => h0 β–Έ by simp only [rpow_zero, monotone_const]) fun h0 => (strictMono_rpow_of_pos h0).monotone /-- Bundles `fun x : ℝβ‰₯0 => x ^ y` into an order isomorphism when `y : ℝ` is positive, where the inverse is `fun x : ℝβ‰₯0 => x ^ (1 / y)`. -/ @[simps! apply] def orderIsoRpow (y : ℝ) (hy : 0 < y) : ℝβ‰₯0 ≃o ℝβ‰₯0 := (strictMono_rpow_of_pos hy).orderIsoOfRightInverse (fun x => x ^ y) (fun x => x ^ (1 / y)) fun x => by dsimp rw [← rpow_mul, one_div_mul_cancel hy.ne.symm, rpow_one] theorem orderIsoRpow_symm_eq (y : ℝ) (hy : 0 < y) : (orderIsoRpow y hy).symm = orderIsoRpow (1 / y) (one_div_pos.2 hy) := by simp only [orderIsoRpow, one_div_one_div]; rfl theorem _root_.Real.nnnorm_rpow_of_nonneg {x y : ℝ} (hx : 0 ≀ x) : β€–x ^ yβ€–β‚Š = β€–xβ€–β‚Š ^ y := by ext; exact Real.norm_rpow_of_nonneg hx end NNReal namespace ENNReal /-- The real power function `x^y` on extended nonnegative reals, defined for `x : ℝβ‰₯0∞` and `y : ℝ` as the restriction of the real power function if `0 < x < ⊀`, and with the natural values for `0` and `⊀` (i.e., `0 ^ x = 0` for `x > 0`, `1` for `x = 0` and `⊀` for `x < 0`, and `⊀ ^ x = 1 / 0 ^ x`). -/ noncomputable def rpow : ℝβ‰₯0∞ β†’ ℝ β†’ ℝβ‰₯0∞ | some x, y => if x = 0 ∧ y < 0 then ⊀ else (x ^ y : ℝβ‰₯0) | none, y => if 0 < y then ⊀ else if y = 0 then 1 else 0 noncomputable instance : Pow ℝβ‰₯0∞ ℝ := ⟨rpow⟩ @[simp] theorem rpow_eq_pow (x : ℝβ‰₯0∞) (y : ℝ) : rpow x y = x ^ y := rfl @[simp] theorem rpow_zero {x : ℝβ‰₯0∞} : x ^ (0 : ℝ) = 1 := by cases x <;> Β· dsimp only [(Β· ^ Β·), Pow.pow, rpow] simp theorem rpow_zero_pos (x : ℝβ‰₯0∞) : 0 < x ^ (0 : ℝ) := by rw [rpow_zero]; exact one_pos theorem top_rpow_def (y : ℝ) : (⊀ : ℝβ‰₯0∞) ^ y = if 0 < y then ⊀ else if y = 0 then 1 else 0 := rfl @[simp] theorem top_rpow_of_pos {y : ℝ} (h : 0 < y) : (⊀ : ℝβ‰₯0∞) ^ y = ⊀ := by simp [top_rpow_def, h] @[simp] theorem top_rpow_of_neg {y : ℝ} (h : y < 0) : (⊀ : ℝβ‰₯0∞) ^ y = 0 := by simp [top_rpow_def, asymm h, ne_of_lt h] @[simp] theorem zero_rpow_of_pos {y : ℝ} (h : 0 < y) : (0 : ℝβ‰₯0∞) ^ y = 0 := by rw [← ENNReal.coe_zero, ← ENNReal.some_eq_coe] dsimp only [(Β· ^ Β·), rpow, Pow.pow] simp [asymm h, ne_of_gt h] @[simp] theorem zero_rpow_of_neg {y : ℝ} (h : y < 0) : (0 : ℝβ‰₯0∞) ^ y = ⊀ := by rw [← ENNReal.coe_zero, ← ENNReal.some_eq_coe] dsimp only [(Β· ^ Β·), rpow, Pow.pow] simp [h] theorem zero_rpow_def (y : ℝ) : (0 : ℝβ‰₯0∞) ^ y = if 0 < y then 0 else if y = 0 then 1 else ⊀ := by rcases lt_trichotomy (0 : ℝ) y with (H | rfl | H) Β· simp [H, zero_rpow_of_pos] Β· simp Β· simp [H, asymm H, ne_of_lt, zero_rpow_of_neg] @[simp] theorem zero_rpow_mul_self (y : ℝ) : (0 : ℝβ‰₯0∞) ^ y * (0 : ℝβ‰₯0∞) ^ y = (0 : ℝβ‰₯0∞) ^ y := by rw [zero_rpow_def] split_ifs exacts [zero_mul _, one_mul _, top_mul_top] @[norm_cast] theorem coe_rpow_of_ne_zero {x : ℝβ‰₯0} (h : x β‰  0) (y : ℝ) : (↑(x ^ y) : ℝβ‰₯0∞) = x ^ y := by rw [← ENNReal.some_eq_coe] dsimp only [(Β· ^ Β·), Pow.pow, rpow] simp [h] @[norm_cast] theorem coe_rpow_of_nonneg (x : ℝβ‰₯0) {y : ℝ} (h : 0 ≀ y) : ↑(x ^ y) = (x : ℝβ‰₯0∞) ^ y := by by_cases hx : x = 0 Β· rcases le_iff_eq_or_lt.1 h with (H | H) Β· simp [hx, H.symm] Β· simp [hx, zero_rpow_of_pos H, NNReal.zero_rpow (ne_of_gt H)] Β· exact coe_rpow_of_ne_zero hx _ theorem coe_rpow_def (x : ℝβ‰₯0) (y : ℝ) : (x : ℝβ‰₯0∞) ^ y = if x = 0 ∧ y < 0 then ⊀ else ↑(x ^ y) := rfl theorem rpow_ofNNReal {M : ℝβ‰₯0} {P : ℝ} (hP : 0 ≀ P) : (M : ℝβ‰₯0∞) ^ P = ↑(M ^ P) := by rw [ENNReal.coe_rpow_of_nonneg _ hP, ← ENNReal.rpow_eq_pow] @[simp] theorem rpow_one (x : ℝβ‰₯0∞) : x ^ (1 : ℝ) = x := by cases x Β· exact dif_pos zero_lt_one Β· change ite _ _ _ = _ simp only [NNReal.rpow_one, ite_eq_right_iff, top_ne_coe, and_imp] exact fun _ => zero_le_one.not_gt @[simp] theorem one_rpow (x : ℝ) : (1 : ℝβ‰₯0∞) ^ x = 1 := by rw [← coe_one, ← coe_rpow_of_ne_zero one_ne_zero] simp @[simp] theorem rpow_eq_zero_iff {x : ℝβ‰₯0∞} {y : ℝ} : x ^ y = 0 ↔ x = 0 ∧ 0 < y ∨ x = ⊀ ∧ y < 0 := by cases x with | top => rcases lt_trichotomy y 0 with (H | H | H) <;> simp [H, top_rpow_of_neg, top_rpow_of_pos, le_of_lt] | coe x => by_cases h : x = 0 Β· rcases lt_trichotomy y 0 with (H | H | H) <;> simp [h, H, zero_rpow_of_neg, zero_rpow_of_pos, le_of_lt] Β· simp [← coe_rpow_of_ne_zero h, h] lemma rpow_eq_zero_iff_of_pos {x : ℝβ‰₯0∞} {y : ℝ} (hy : 0 < y) : x ^ y = 0 ↔ x = 0 := by simp [hy, hy.not_gt] @[simp] theorem rpow_eq_top_iff {x : ℝβ‰₯0∞} {y : ℝ} : x ^ y = ⊀ ↔ x = 0 ∧ y < 0 ∨ x = ⊀ ∧ 0 < y := by cases x with | top => rcases lt_trichotomy y 0 with (H | H | H) <;> simp [H, top_rpow_of_neg, top_rpow_of_pos, le_of_lt] | coe x => by_cases h : x = 0 Β· rcases lt_trichotomy y 0 with (H | H | H) <;> simp [h, H, zero_rpow_of_neg, zero_rpow_of_pos, le_of_lt] Β· simp [← coe_rpow_of_ne_zero h, h] theorem rpow_eq_top_iff_of_pos {x : ℝβ‰₯0∞} {y : ℝ} (hy : 0 < y) : x ^ y = ⊀ ↔ x = ⊀ := by simp [rpow_eq_top_iff, hy, asymm hy] lemma rpow_lt_top_iff_of_pos {x : ℝβ‰₯0∞} {y : ℝ} (hy : 0 < y) : x ^ y < ∞ ↔ x < ∞ := by simp only [lt_top_iff_ne_top, Ne, rpow_eq_top_iff_of_pos hy] theorem rpow_eq_top_of_nonneg (x : ℝβ‰₯0∞) {y : ℝ} (hy0 : 0 ≀ y) : x ^ y = ⊀ β†’ x = ⊀ := by simp +contextual [ENNReal.rpow_eq_top_iff, hy0.not_gt] -- This is an unsafe rule since we want to try `rpow_ne_top_of_ne_zero` if `y < 0`. @[aesop (rule_sets := [finiteness]) unsafe apply] theorem rpow_ne_top_of_nonneg {x : ℝβ‰₯0∞} {y : ℝ} (hy0 : 0 ≀ y) (h : x β‰  ⊀) : x ^ y β‰  ⊀ := mt (ENNReal.rpow_eq_top_of_nonneg x hy0) h -- This is an unsafe rule since we want to try `rpow_ne_top_of_nonneg'` if `x = 0`. @[aesop (rule_sets := [finiteness]) unsafe apply] theorem rpow_ne_top_of_nonneg' {y : ℝ} {x : ℝβ‰₯0∞} (hx : 0 < x) (hx' : x β‰  ⊀) : x ^ y β‰  ⊀ := fun h ↦ by simp [rpow_eq_top_iff, hx.ne', hx'] at h theorem rpow_lt_top_of_nonneg {x : ℝβ‰₯0∞} {y : ℝ} (hy0 : 0 ≀ y) (h : x β‰  ⊀) : x ^ y < ⊀ := lt_top_iff_ne_top.mpr (ENNReal.rpow_ne_top_of_nonneg hy0 h) -- This is an unsafe rule since we want to try `rpow_ne_top_of_nonneg` if `x = 0`. @[aesop (rule_sets := [finiteness]) unsafe apply] theorem rpow_ne_top_of_ne_zero {x : ℝβ‰₯0∞} {y : ℝ} (hx : x β‰  0) (hx' : x β‰  ⊀) : x ^ y β‰  ⊀ := by simp [rpow_eq_top_iff, hx, hx'] theorem rpow_add {x : ℝβ‰₯0∞} (y z : ℝ) (hx : x β‰  0) (h'x : x β‰  ⊀) : x ^ (y + z) = x ^ y * x ^ z := by cases x with | top => exact (h'x rfl).elim | coe x => have : x β‰  0 := fun h => by simp [h] at hx simp [← coe_rpow_of_ne_zero this, NNReal.rpow_add this] theorem rpow_add_of_nonneg {x : ℝβ‰₯0∞} (y z : ℝ) (hy : 0 ≀ y) (hz : 0 ≀ z) : x ^ (y + z) = x ^ y * x ^ z := by induction x using recTopCoe Β· rcases hy.eq_or_lt with rfl | hy Β· rw [rpow_zero, one_mul, zero_add] rcases hz.eq_or_lt with rfl | hz Β· rw [rpow_zero, mul_one, add_zero] simp [top_rpow_of_pos, hy, hz, add_pos hy hz] simp [← coe_rpow_of_nonneg, hy, hz, add_nonneg hy hz, NNReal.rpow_add_of_nonneg _ hy hz] lemma rpow_add_of_add_pos {x : ℝβ‰₯0∞} (hx : x β‰  ⊀) (y z : ℝ) (hyz : 0 < y + z) : x ^ (y + z) = x ^ y * x ^ z := by obtain (rfl | hx') := eq_or_ne x 0 Β· by_cases hy' : 0 < y Β· simp [ENNReal.zero_rpow_of_pos hyz, ENNReal.zero_rpow_of_pos hy'] Β· have hz' : 0 < z := by linarith simp [ENNReal.zero_rpow_of_pos hyz, ENNReal.zero_rpow_of_pos hz'] Β· rw [ENNReal.rpow_add _ _ hx' hx] theorem rpow_neg (x : ℝβ‰₯0∞) (y : ℝ) : x ^ (-y) = (x ^ y)⁻¹ := by cases x with | top => rcases lt_trichotomy y 0 with (H | H | H) <;> simp [top_rpow_of_pos, top_rpow_of_neg, H, neg_pos.mpr] | coe x => by_cases h : x = 0 Β· rcases lt_trichotomy y 0 with (H | H | H) <;> simp [h, zero_rpow_of_pos, zero_rpow_of_neg, H, neg_pos.mpr] Β· have A : x ^ y β‰  0 := by simp [h] simp [← coe_rpow_of_ne_zero h, ← coe_inv A, NNReal.rpow_neg] theorem rpow_sub {x : ℝβ‰₯0∞} (y z : ℝ) (hx : x β‰  0) (h'x : x β‰  ⊀) : x ^ (y - z) = x ^ y / x ^ z := by rw [sub_eq_add_neg, rpow_add _ _ hx h'x, rpow_neg, div_eq_mul_inv] theorem rpow_neg_one (x : ℝβ‰₯0∞) : x ^ (-1 : ℝ) = x⁻¹ := by simp [rpow_neg] theorem rpow_mul (x : ℝβ‰₯0∞) (y z : ℝ) : x ^ (y * z) = (x ^ y) ^ z := by cases x with | top => rcases lt_trichotomy y 0 with (Hy | Hy | Hy) <;> rcases lt_trichotomy z 0 with (Hz | Hz | Hz) <;> simp [Hy, Hz, zero_rpow_of_neg, zero_rpow_of_pos, top_rpow_of_neg, top_rpow_of_pos, mul_pos_of_neg_of_neg, mul_neg_of_neg_of_pos, mul_neg_of_pos_of_neg] | coe x => by_cases h : x = 0 Β· rcases lt_trichotomy y 0 with (Hy | Hy | Hy) <;> rcases lt_trichotomy z 0 with (Hz | Hz | Hz) <;> simp [h, Hy, Hz, zero_rpow_of_neg, zero_rpow_of_pos, top_rpow_of_neg, top_rpow_of_pos, mul_pos_of_neg_of_neg, mul_neg_of_neg_of_pos, mul_neg_of_pos_of_neg] Β· have : x ^ y β‰  0 := by simp [h] simp [← coe_rpow_of_ne_zero, h, this, NNReal.rpow_mul] @[simp, norm_cast] theorem rpow_natCast (x : ℝβ‰₯0∞) (n : β„•) : x ^ (n : ℝ) = x ^ n := by cases x Β· cases n <;> simp [top_rpow_of_pos (Nat.cast_add_one_pos _), top_pow (Nat.succ_ne_zero _)] Β· simp [← coe_rpow_of_nonneg _ (Nat.cast_nonneg n)] @[simp] lemma rpow_ofNat (x : ℝβ‰₯0∞) (n : β„•) [n.AtLeastTwo] : x ^ (ofNat(n) : ℝ) = x ^ (OfNat.ofNat n) := rpow_natCast x n @[simp, norm_cast] lemma rpow_intCast (x : ℝβ‰₯0∞) (n : β„€) : x ^ (n : ℝ) = x ^ n := by cases n <;> simp only [Int.ofNat_eq_coe, Int.cast_natCast, rpow_natCast, zpow_natCast, Int.cast_negSucc, rpow_neg, zpow_negSucc] theorem rpow_two (x : ℝβ‰₯0∞) : x ^ (2 : ℝ) = x ^ 2 := rpow_ofNat x 2 theorem mul_rpow_eq_ite (x y : ℝβ‰₯0∞) (z : ℝ) : (x * y) ^ z = if (x = 0 ∧ y = ⊀ ∨ x = ⊀ ∧ y = 0) ∧ z < 0 then ⊀ else x ^ z * y ^ z := by rcases eq_or_ne z 0 with (rfl | hz); Β· simp replace hz := hz.lt_or_gt wlog hxy : x ≀ y Β· convert this y x z hz (le_of_not_ge hxy) using 2 <;> simp only [mul_comm, and_comm, or_comm] rcases eq_or_ne x 0 with (rfl | hx0) Β· induction y <;> rcases hz with hz | hz <;> simp [*, hz.not_gt] rcases eq_or_ne y 0 with (rfl | hy0) Β· exact (hx0 (bot_unique hxy)).elim induction x Β· rcases hz with hz | hz <;> simp [hz, top_unique hxy] induction y Β· rw [ne_eq, coe_eq_zero] at hx0 rcases hz with hz | hz <;> simp [*] simp only [*] norm_cast at * rw [← coe_rpow_of_ne_zero (mul_ne_zero hx0 hy0), NNReal.mul_rpow] norm_cast theorem mul_rpow_of_ne_top {x y : ℝβ‰₯0∞} (hx : x β‰  ⊀) (hy : y β‰  ⊀) (z : ℝ) : (x * y) ^ z = x ^ z * y ^ z := by simp [*, mul_rpow_eq_ite] @[norm_cast] theorem coe_mul_rpow (x y : ℝβ‰₯0) (z : ℝ) : ((x : ℝβ‰₯0∞) * y) ^ z = (x : ℝβ‰₯0∞) ^ z * (y : ℝβ‰₯0∞) ^ z := mul_rpow_of_ne_top coe_ne_top coe_ne_top z theorem prod_coe_rpow {ΞΉ} (s : Finset ΞΉ) (f : ΞΉ β†’ ℝβ‰₯0) (r : ℝ) : ∏ i ∈ s, (f i : ℝβ‰₯0∞) ^ r = ((∏ i ∈ s, f i : ℝβ‰₯0) : ℝβ‰₯0∞) ^ r := by classical induction s using Finset.induction with | empty => simp | insert _ _ hi ih => simp_rw [prod_insert hi, ih, ← coe_mul_rpow, coe_mul] theorem mul_rpow_of_ne_zero {x y : ℝβ‰₯0∞} (hx : x β‰  0) (hy : y β‰  0) (z : ℝ) : (x * y) ^ z = x ^ z * y ^ z := by simp [*, mul_rpow_eq_ite] theorem mul_rpow_of_nonneg (x y : ℝβ‰₯0∞) {z : ℝ} (hz : 0 ≀ z) : (x * y) ^ z = x ^ z * y ^ z := by simp [hz.not_gt, mul_rpow_eq_ite] theorem prod_rpow_of_ne_top {ΞΉ} {s : Finset ΞΉ} {f : ΞΉ β†’ ℝβ‰₯0∞} (hf : βˆ€ i ∈ s, f i β‰  ∞) (r : ℝ) : ∏ i ∈ s, f i ^ r = (∏ i ∈ s, f i) ^ r := by classical induction s using Finset.induction with | empty => simp | insert i s hi ih => have h2f : βˆ€ i ∈ s, f i β‰  ∞ := fun i hi ↦ hf i <| mem_insert_of_mem hi rw [prod_insert hi, prod_insert hi, ih h2f, ← mul_rpow_of_ne_top <| hf i <| mem_insert_self ..] apply prod_ne_top h2f theorem prod_rpow_of_nonneg {ΞΉ} {s : Finset ΞΉ} {f : ΞΉ β†’ ℝβ‰₯0∞} {r : ℝ} (hr : 0 ≀ r) : ∏ i ∈ s, f i ^ r = (∏ i ∈ s, f i) ^ r := by classical induction s using Finset.induction with | empty => simp | insert _ _ hi ih => simp_rw [prod_insert hi, ih, ← mul_rpow_of_nonneg _ _ hr] theorem inv_rpow (x : ℝβ‰₯0∞) (y : ℝ) : x⁻¹ ^ y = (x ^ y)⁻¹ := by rcases eq_or_ne y 0 with (rfl | hy); Β· simp only [rpow_zero, inv_one] replace hy := hy.lt_or_gt rcases eq_or_ne x 0 with (rfl | h0); Β· cases hy <;> simp [*] rcases eq_or_ne x ⊀ with (rfl | h_top); Β· cases hy <;> simp [*] apply ENNReal.eq_inv_of_mul_eq_one_left rw [← mul_rpow_of_ne_zero (ENNReal.inv_ne_zero.2 h_top) h0, ENNReal.inv_mul_cancel h0 h_top, one_rpow] theorem div_rpow_of_nonneg (x y : ℝβ‰₯0∞) {z : ℝ} (hz : 0 ≀ z) : (x / y) ^ z = x ^ z / y ^ z := by rw [div_eq_mul_inv, mul_rpow_of_nonneg _ _ hz, inv_rpow, div_eq_mul_inv] theorem strictMono_rpow_of_pos {z : ℝ} (h : 0 < z) : StrictMono fun x : ℝβ‰₯0∞ => x ^ z := by intro x y hxy lift x to ℝβ‰₯0 using ne_top_of_lt hxy rcases eq_or_ne y ∞ with (rfl | hy) Β· simp only [top_rpow_of_pos h, ← coe_rpow_of_nonneg _ h.le, coe_lt_top] Β· lift y to ℝβ‰₯0 using hy simp only [← coe_rpow_of_nonneg _ h.le, NNReal.rpow_lt_rpow (coe_lt_coe.1 hxy) h, coe_lt_coe] theorem monotone_rpow_of_nonneg {z : ℝ} (h : 0 ≀ z) : Monotone fun x : ℝβ‰₯0∞ => x ^ z := h.eq_or_lt.elim (fun h0 => h0 β–Έ by simp only [rpow_zero, monotone_const]) fun h0 => (strictMono_rpow_of_pos h0).monotone /-- Bundles `fun x : ℝβ‰₯0∞ => x ^ y` into an order isomorphism when `y : ℝ` is positive, where the inverse is `fun x : ℝβ‰₯0∞ => x ^ (1 / y)`. -/ @[simps! apply] def orderIsoRpow (y : ℝ) (hy : 0 < y) : ℝβ‰₯0∞ ≃o ℝβ‰₯0∞ := (strictMono_rpow_of_pos hy).orderIsoOfRightInverse (fun x => x ^ y) (fun x => x ^ (1 / y)) fun x => by dsimp rw [← rpow_mul, one_div_mul_cancel hy.ne.symm, rpow_one] theorem orderIsoRpow_symm_apply (y : ℝ) (hy : 0 < y) : (orderIsoRpow y hy).symm = orderIsoRpow (1 / y) (one_div_pos.2 hy) := by simp only [orderIsoRpow, one_div_one_div] rfl @[gcongr] theorem rpow_le_rpow {x y : ℝβ‰₯0∞} {z : ℝ} (h₁ : x ≀ y) (hβ‚‚ : 0 ≀ z) : x ^ z ≀ y ^ z := monotone_rpow_of_nonneg hβ‚‚ h₁ @[gcongr] theorem rpow_lt_rpow {x y : ℝβ‰₯0∞} {z : ℝ} (h₁ : x < y) (hβ‚‚ : 0 < z) : x ^ z < y ^ z := strictMono_rpow_of_pos hβ‚‚ h₁ theorem rpow_le_rpow_iff {x y : ℝβ‰₯0∞} {z : ℝ} (hz : 0 < z) : x ^ z ≀ y ^ z ↔ x ≀ y := (strictMono_rpow_of_pos hz).le_iff_le theorem rpow_lt_rpow_iff {x y : ℝβ‰₯0∞} {z : ℝ} (hz : 0 < z) : x ^ z < y ^ z ↔ x < y := (strictMono_rpow_of_pos hz).lt_iff_lt lemma max_rpow {x y : ℝβ‰₯0∞} {p : ℝ} (hp : 0 ≀ p) : max x y ^ p = max (x ^ p) (y ^ p) := by rcases le_total x y with hxy | hxy Β· rw [max_eq_right hxy, max_eq_right (rpow_le_rpow hxy hp)] Β· rw [max_eq_left hxy, max_eq_left (rpow_le_rpow hxy hp)] theorem le_rpow_inv_iff {x y : ℝβ‰₯0∞} {z : ℝ} (hz : 0 < z) : x ≀ y ^ z⁻¹ ↔ x ^ z ≀ y := by nth_rw 1 [← rpow_one x] nth_rw 1 [← @mul_inv_cancelβ‚€ _ _ z hz.ne'] rw [rpow_mul, @rpow_le_rpow_iff _ _ z⁻¹ (by simp [hz])] theorem rpow_inv_lt_iff {x y : ℝβ‰₯0∞} {z : ℝ} (hz : 0 < z) : x ^ z⁻¹ < y ↔ x < y ^ z := by simp only [← not_le, le_rpow_inv_iff hz] theorem lt_rpow_inv_iff {x y : ℝβ‰₯0∞} {z : ℝ} (hz : 0 < z) : x < y ^ z⁻¹ ↔ x ^ z < y := by nth_rw 1 [← rpow_one x] nth_rw 1 [← @mul_inv_cancelβ‚€ _ _ z (ne_of_lt hz).symm] rw [rpow_mul, @rpow_lt_rpow_iff _ _ z⁻¹ (by simp [hz])] theorem rpow_inv_le_iff {x y : ℝβ‰₯0∞} {z : ℝ} (hz : 0 < z) : x ^ z⁻¹ ≀ y ↔ x ≀ y ^ z := by nth_rw 1 [← ENNReal.rpow_one y] nth_rw 1 [← @mul_inv_cancelβ‚€ _ _ z hz.ne.symm] rw [ENNReal.rpow_mul, ENNReal.rpow_le_rpow_iff (inv_pos.2 hz)] @[gcongr] theorem rpow_lt_rpow_of_exponent_lt {x : ℝβ‰₯0∞} {y z : ℝ} (hx : 1 < x) (hx' : x β‰  ⊀) (hyz : y < z) : x ^ y < x ^ z := by lift x to ℝβ‰₯0 using hx' rw [one_lt_coe_iff] at hx simp [← coe_rpow_of_ne_zero (ne_of_gt (lt_trans zero_lt_one hx)), NNReal.rpow_lt_rpow_of_exponent_lt hx hyz] @[gcongr] theorem rpow_le_rpow_of_exponent_le {x : ℝβ‰₯0∞} {y z : ℝ} (hx : 1 ≀ x) (hyz : y ≀ z) : x ^ y ≀ x ^ z := by cases x Β· rcases lt_trichotomy y 0 with (Hy | Hy | Hy) <;> rcases lt_trichotomy z 0 with (Hz | Hz | Hz) <;> simp [Hy, Hz, top_rpow_of_neg, top_rpow_of_pos, le_refl] <;> linarith Β· simp only [one_le_coe_iff] at hx simp [← coe_rpow_of_ne_zero (ne_of_gt (lt_of_lt_of_le zero_lt_one hx)), NNReal.rpow_le_rpow_of_exponent_le hx hyz] theorem rpow_lt_rpow_of_exponent_gt {x : ℝβ‰₯0∞} {y z : ℝ} (hx0 : 0 < x) (hx1 : x < 1) (hyz : z < y) : x ^ y < x ^ z := by lift x to ℝβ‰₯0 using ne_of_lt (lt_of_lt_of_le hx1 le_top) simp only [coe_lt_one_iff, coe_pos] at hx0 hx1 simp [← coe_rpow_of_ne_zero (ne_of_gt hx0), NNReal.rpow_lt_rpow_of_exponent_gt hx0 hx1 hyz] theorem rpow_le_rpow_of_exponent_ge {x : ℝβ‰₯0∞} {y z : ℝ} (hx1 : x ≀ 1) (hyz : z ≀ y) : x ^ y ≀ x ^ z := by lift x to ℝβ‰₯0 using ne_of_lt (lt_of_le_of_lt hx1 coe_lt_top) by_cases h : x = 0 Β· rcases lt_trichotomy y 0 with (Hy | Hy | Hy) <;> rcases lt_trichotomy z 0 with (Hz | Hz | Hz) <;> simp [Hy, Hz, h, zero_rpow_of_neg, zero_rpow_of_pos, le_refl] <;> linarith Β· rw [coe_le_one_iff] at hx1 simp [← coe_rpow_of_ne_zero h, NNReal.rpow_le_rpow_of_exponent_ge (bot_lt_iff_ne_bot.mpr h) hx1 hyz] theorem rpow_le_self_of_le_one {x : ℝβ‰₯0∞} {z : ℝ} (hx : x ≀ 1) (h_one_le : 1 ≀ z) : x ^ z ≀ x := by nth_rw 2 [← ENNReal.rpow_one x] exact ENNReal.rpow_le_rpow_of_exponent_ge hx h_one_le theorem le_rpow_self_of_one_le {x : ℝβ‰₯0∞} {z : ℝ} (hx : 1 ≀ x) (h_one_le : 1 ≀ z) : x ≀ x ^ z := by nth_rw 1 [← ENNReal.rpow_one x] exact ENNReal.rpow_le_rpow_of_exponent_le hx h_one_le theorem rpow_pos_of_nonneg {p : ℝ} {x : ℝβ‰₯0∞} (hx_pos : 0 < x) (hp_nonneg : 0 ≀ p) : 0 < x ^ p := by by_cases hp_zero : p = 0 Β· simp [hp_zero, zero_lt_one] Β· rw [← Ne] at hp_zero have hp_pos := lt_of_le_of_ne hp_nonneg hp_zero.symm rw [← zero_rpow_of_pos hp_pos] exact rpow_lt_rpow hx_pos hp_pos theorem rpow_pos {p : ℝ} {x : ℝβ‰₯0∞} (hx_pos : 0 < x) (hx_ne_top : x β‰  ⊀) : 0 < x ^ p := by rcases lt_or_ge 0 p with hp_pos | hp_nonpos Β· exact rpow_pos_of_nonneg hx_pos (le_of_lt hp_pos) Β· rw [← neg_neg p, rpow_neg, ENNReal.inv_pos] exact rpow_ne_top_of_nonneg (Right.nonneg_neg_iff.mpr hp_nonpos) hx_ne_top theorem rpow_lt_one {x : ℝβ‰₯0∞} {z : ℝ} (hx : x < 1) (hz : 0 < z) : x ^ z < 1 := by lift x to ℝβ‰₯0 using ne_of_lt (lt_of_lt_of_le hx le_top) simp only [coe_lt_one_iff] at hx simp [← coe_rpow_of_nonneg _ (le_of_lt hz), NNReal.rpow_lt_one hx hz] theorem rpow_le_one {x : ℝβ‰₯0∞} {z : ℝ} (hx : x ≀ 1) (hz : 0 ≀ z) : x ^ z ≀ 1 := by lift x to ℝβ‰₯0 using ne_of_lt (lt_of_le_of_lt hx coe_lt_top) simp only [coe_le_one_iff] at hx simp [← coe_rpow_of_nonneg _ hz, NNReal.rpow_le_one hx hz] theorem rpow_lt_one_of_one_lt_of_neg {x : ℝβ‰₯0∞} {z : ℝ} (hx : 1 < x) (hz : z < 0) : x ^ z < 1 := by cases x Β· simp [top_rpow_of_neg hz, zero_lt_one] Β· simp only [one_lt_coe_iff] at hx simp [← coe_rpow_of_ne_zero (ne_of_gt (lt_trans zero_lt_one hx)), NNReal.rpow_lt_one_of_one_lt_of_neg hx hz] theorem rpow_le_one_of_one_le_of_neg {x : ℝβ‰₯0∞} {z : ℝ} (hx : 1 ≀ x) (hz : z < 0) : x ^ z ≀ 1 := by cases x Β· simp [top_rpow_of_neg hz] Β· simp only [one_le_coe_iff] at hx simp [← coe_rpow_of_ne_zero (ne_of_gt (lt_of_lt_of_le zero_lt_one hx)), NNReal.rpow_le_one_of_one_le_of_nonpos hx (le_of_lt hz)] theorem one_lt_rpow {x : ℝβ‰₯0∞} {z : ℝ} (hx : 1 < x) (hz : 0 < z) : 1 < x ^ z := by cases x Β· simp [top_rpow_of_pos hz] Β· simp only [one_lt_coe_iff] at hx simp [← coe_rpow_of_nonneg _ (le_of_lt hz), NNReal.one_lt_rpow hx hz] theorem one_le_rpow {x : ℝβ‰₯0∞} {z : ℝ} (hx : 1 ≀ x) (hz : 0 < z) : 1 ≀ x ^ z := by cases x Β· simp [top_rpow_of_pos hz] Β· simp only [one_le_coe_iff] at hx simp [← coe_rpow_of_nonneg _ (le_of_lt hz), NNReal.one_le_rpow hx (le_of_lt hz)] theorem one_lt_rpow_of_pos_of_lt_one_of_neg {x : ℝβ‰₯0∞} {z : ℝ} (hx1 : 0 < x) (hx2 : x < 1) (hz : z < 0) : 1 < x ^ z := by lift x to ℝβ‰₯0 using ne_of_lt (lt_of_lt_of_le hx2 le_top) simp only [coe_lt_one_iff, coe_pos] at hx1 hx2 ⊒ simp [← coe_rpow_of_ne_zero (ne_of_gt hx1), NNReal.one_lt_rpow_of_pos_of_lt_one_of_neg hx1 hx2 hz] theorem one_le_rpow_of_pos_of_le_one_of_neg {x : ℝβ‰₯0∞} {z : ℝ} (hx1 : 0 < x) (hx2 : x ≀ 1) (hz : z < 0) : 1 ≀ x ^ z := by lift x to ℝβ‰₯0 using ne_of_lt (lt_of_le_of_lt hx2 coe_lt_top) simp only [coe_le_one_iff, coe_pos] at hx1 hx2 ⊒ simp [← coe_rpow_of_ne_zero (ne_of_gt hx1), NNReal.one_le_rpow_of_pos_of_le_one_of_nonpos hx1 hx2 (le_of_lt hz)] @[simp] lemma toNNReal_rpow (x : ℝβ‰₯0∞) (z : ℝ) : (x ^ z).toNNReal = x.toNNReal ^ z := by rcases lt_trichotomy z 0 with (H | H | H) Β· cases x with | top => simp [H, ne_of_lt] | coe x => by_cases hx : x = 0 Β· simp [hx, H, ne_of_lt] Β· simp [← coe_rpow_of_ne_zero hx] Β· simp [H] Β· cases x Β· simp [H, ne_of_gt] simp [← coe_rpow_of_nonneg _ (le_of_lt H)] theorem toReal_rpow (x : ℝβ‰₯0∞) (z : ℝ) : x.toReal ^ z = (x ^ z).toReal := by rw [ENNReal.toReal, ENNReal.toReal, ← NNReal.coe_rpow, ENNReal.toNNReal_rpow] theorem ofReal_rpow_of_pos {x p : ℝ} (hx_pos : 0 < x) : ENNReal.ofReal x ^ p = ENNReal.ofReal (x ^ p) := by simp_rw [ENNReal.ofReal] rw [← coe_rpow_of_ne_zero, coe_inj, Real.toNNReal_rpow_of_nonneg hx_pos.le] simp [hx_pos] theorem ofReal_rpow_of_nonneg {x p : ℝ} (hx_nonneg : 0 ≀ x) (hp_nonneg : 0 ≀ p) : ENNReal.ofReal x ^ p = ENNReal.ofReal (x ^ p) := by by_cases hp0 : p = 0 Β· simp [hp0] by_cases hx0 : x = 0 Β· rw [← Ne] at hp0 have hp_pos : 0 < p := lt_of_le_of_ne hp_nonneg hp0.symm simp [hx0, hp_pos, hp_pos.ne.symm] rw [← Ne] at hx0 exact ofReal_rpow_of_pos (hx_nonneg.lt_of_ne hx0.symm) @[simp] lemma rpow_rpow_inv {y : ℝ} (hy : y β‰  0) (x : ℝβ‰₯0∞) : (x ^ y) ^ y⁻¹ = x := by rw [← rpow_mul, mul_inv_cancelβ‚€ hy, rpow_one] @[simp] lemma rpow_inv_rpow {y : ℝ} (hy : y β‰  0) (x : ℝβ‰₯0∞) : (x ^ y⁻¹) ^ y = x := by rw [← rpow_mul, inv_mul_cancelβ‚€ hy, rpow_one] lemma pow_rpow_inv_natCast {n : β„•} (hn : n β‰  0) (x : ℝβ‰₯0∞) : (x ^ n) ^ (n⁻¹ : ℝ) = x := by rw [← rpow_natCast, ← rpow_mul, mul_inv_cancelβ‚€ (by positivity), rpow_one] lemma rpow_inv_natCast_pow {n : β„•} (hn : n β‰  0) (x : ℝβ‰₯0∞) : (x ^ (n⁻¹ : ℝ)) ^ n = x := by rw [← rpow_natCast, ← rpow_mul, inv_mul_cancelβ‚€ (by positivity), rpow_one] lemma rpow_natCast_mul (x : ℝβ‰₯0∞) (n : β„•) (z : ℝ) : x ^ (n * z) = (x ^ n) ^ z := by rw [rpow_mul, rpow_natCast] lemma rpow_mul_natCast (x : ℝβ‰₯0∞) (y : ℝ) (n : β„•) : x ^ (y * n) = (x ^ y) ^ n := by rw [rpow_mul, rpow_natCast] lemma rpow_intCast_mul (x : ℝβ‰₯0∞) (n : β„€) (z : ℝ) : x ^ (n * z) = (x ^ n) ^ z := by rw [rpow_mul, rpow_intCast] lemma rpow_mul_intCast (x : ℝβ‰₯0∞) (y : ℝ) (n : β„€) : x ^ (y * n) = (x ^ y) ^ n := by rw [rpow_mul, rpow_intCast] lemma rpow_left_injective {x : ℝ} (hx : x β‰  0) : Injective fun y : ℝβ‰₯0∞ ↦ y ^ x := HasLeftInverse.injective ⟨fun y ↦ y ^ x⁻¹, rpow_rpow_inv hx⟩ theorem rpow_left_surjective {x : ℝ} (hx : x β‰  0) : Function.Surjective fun y : ℝβ‰₯0∞ => y ^ x := HasRightInverse.surjective ⟨fun y ↦ y ^ x⁻¹, rpow_inv_rpow hx⟩ theorem rpow_left_bijective {x : ℝ} (hx : x β‰  0) : Function.Bijective fun y : ℝβ‰₯0∞ => y ^ x := ⟨rpow_left_injective hx, rpow_left_surjective hx⟩ lemma _root_.Real.enorm_rpow_of_nonneg {x y : ℝ} (hx : 0 ≀ x) (hy : 0 ≀ y) : β€–x ^ yβ€–β‚‘ = β€–xβ€–β‚‘ ^ y := by simp [enorm, nnnorm_rpow_of_nonneg hx, coe_rpow_of_nonneg _ hy] lemma add_rpow_le_two_rpow_mul_rpow_add_rpow {p : ℝ} (a b : ℝβ‰₯0∞) (hp : 0 ≀ p) : (a + b) ^ p ≀ 2 ^ p * (a ^ p + b ^ p) := calc (a + b) ^ p ≀ (2 * max a b) ^ p := by rw [two_mul]; gcongr <;> simp _ = 2 ^ p * (max a b) ^ p := mul_rpow_of_nonneg _ _ hp _ = 2 ^ p * max (a ^ p) (b ^ p) := by rw [max_rpow hp] _ ≀ 2 ^ p * (a ^ p + b ^ p) := by gcongr; apply max_le_add_of_nonneg <;> simp end ENNReal -- Porting note(https://github.com/leanprover-community/mathlib4/issues/6038): restore -- section Tactics -- /-! -- ## Tactic extensions for powers on `ℝβ‰₯0` and `ℝβ‰₯0∞` -- -/ -- namespace NormNum -- theorem nnrpow_pos (a : ℝβ‰₯0) (b : ℝ) (b' : β„•) (c : ℝβ‰₯0) (hb : b = b') (h : a ^ b' = c) : -- a ^ b = c := by rw [← h, hb, NNReal.rpow_natCast] -- theorem nnrpow_neg (a : ℝβ‰₯0) (b : ℝ) (b' : β„•) (c c' : ℝβ‰₯0) (hb : b = b') (h : a ^ b' = c) -- (hc : c⁻¹ = c') : a ^ (-b) = c' := by -- rw [← hc, ← h, hb, NNReal.rpow_neg, NNReal.rpow_natCast] -- theorem ennrpow_pos (a : ℝβ‰₯0∞) (b : ℝ) (b' : β„•) (c : ℝβ‰₯0∞) (hb : b = b') (h : a ^ b' = c) : -- a ^ b = c := by rw [← h, hb, ENNReal.rpow_natCast] -- theorem ennrpow_neg (a : ℝβ‰₯0∞) (b : ℝ) (b' : β„•) (c c' : ℝβ‰₯0∞) (hb : b = b') (h : a ^ b' = c) -- (hc : c⁻¹ = c') : a ^ (-b) = c' := by -- rw [← hc, ← h, hb, ENNReal.rpow_neg, ENNReal.rpow_natCast] -- /-- Evaluate `NNReal.rpow a b` where `a` is a rational numeral and `b` is an integer. -/ -- unsafe def prove_nnrpow : expr β†’ expr β†’ tactic (expr Γ— expr) := -- prove_rpow' `` nnrpow_pos `` nnrpow_neg `` NNReal.rpow_zero q(ℝβ‰₯0) q(ℝ) q((1 : ℝβ‰₯0)) -- /-- Evaluate `ENNReal.rpow a b` where `a` is a rational numeral and `b` is an integer. -/ -- unsafe def prove_ennrpow : expr β†’ expr β†’ tactic (expr Γ— expr) := -- prove_rpow' `` ennrpow_pos `` ennrpow_neg `` ENNReal.rpow_zero q(ℝβ‰₯0∞) q(ℝ) q((1 : ℝβ‰₯0∞)) -- /-- Evaluates expressions of the form `rpow a b` and `a ^ b` in the special case where -- `b` is an integer and `a` is a positive rational (so it's really just a rational power). -/ -- @[norm_num] -- unsafe def eval_nnrpow_ennrpow : expr β†’ tactic (expr Γ— expr) -- | q(@Pow.pow _ _ NNReal.Real.hasPow $(a) $(b)) => b.to_int >> prove_nnrpow a b -- | q(NNReal.rpow $(a) $(b)) => b.to_int >> prove_nnrpow a b -- | q(@Pow.pow _ _ ENNReal.Real.hasPow $(a) $(b)) => b.to_int >> prove_ennrpow a b -- | q(ENNReal.rpow $(a) $(b)) => b.to_int >> prove_ennrpow a b -- | _ => tactic.failed -- end NormNum -- namespace Tactic -- namespace Positivity -- private theorem nnrpow_pos {a : ℝβ‰₯0} (ha : 0 < a) (b : ℝ) : 0 < a ^ b := -- NNReal.rpow_pos ha -- /-- Auxiliary definition for the `positivity` tactic to handle real powers of nonnegative reals. -- -/ -- unsafe def prove_nnrpow (a b : expr) : tactic strictness := do -- let strictness_a ← core a -- match strictness_a with -- | positive p => positive <$> mk_app `` nnrpow_pos [p, b] -- | _ => failed -- -- We already know `0 ≀ x` for all `x : ℝβ‰₯0` -- private theorem ennrpow_pos {a : ℝβ‰₯0∞} {b : ℝ} (ha : 0 < a) (hb : 0 < b) : 0 < a ^ b := -- ENNReal.rpow_pos_of_nonneg ha hb.le -- /-- Auxiliary definition for the `positivity` tactic to handle real powers of extended -- nonnegative reals. -/ -- unsafe def prove_ennrpow (a b : expr) : tactic strictness := do -- let strictness_a ← core a -- let strictness_b ← core b -- match strictness_a, strictness_b with -- | positive pa, positive pb => positive <$> mk_app `` ennrpow_pos [pa, pb] -- | positive pa, nonnegative pb => positive <$> mk_app `` ENNReal.rpow_pos_of_nonneg [pa, pb] -- | _, _ => failed -- -- We already know `0 ≀ x` for all `x : ℝβ‰₯0∞` -- end Positivity -- open Positivity -- /-- Extension for the `positivity` tactic: exponentiation by a real number is nonnegative when -- the base is nonnegative and positive when the base is positive. -/ -- @[positivity] -- unsafe def positivity_nnrpow_ennrpow : expr β†’ tactic strictness -- | q(@Pow.pow _ _ NNReal.Real.hasPow $(a) $(b)) => prove_nnrpow a b -- | q(NNReal.rpow $(a) $(b)) => prove_nnrpow a b -- | q(@Pow.pow _ _ ENNReal.Real.hasPow $(a) $(b)) => prove_ennrpow a b -- | q(ENNReal.rpow $(a) $(b)) => prove_ennrpow a b -- | _ => failed -- end Tactic -- end Tactics /-! ### Positivity extension -/ namespace Mathlib.Meta.Positivity open Lean Meta Qq /-- Extension for the `positivity` tactic: exponentiation by a real number is nonnegative when the base is nonnegative and positive when the base is positive. This is the `NNReal` analogue of `evalRpow` for `Real`. -/ @[positivity (_ : ℝβ‰₯0) ^ (_ : ℝ)] def evalNNRealRpow : PositivityExt where eval {u Ξ±} _ _ e := do match u, Ξ±, e with | 0, ~q(ℝβ‰₯0), ~q($a ^ (0 : ℝ)) => assertInstancesCommute pure (.positive q(NNReal.rpow_zero_pos $a)) | 0, ~q(ℝβ‰₯0), ~q($a ^ ($b : ℝ)) => let ra ← core q(inferInstance) q(inferInstance) a assertInstancesCommute match ra with | .positive pa => pure (.positive q(NNReal.rpow_pos $pa)) | _ => pure (.nonnegative q(zero_le $e)) | _, _, _ => throwError "not NNReal.rpow" private def isFiniteM? (x : Q(ℝβ‰₯0∞)) : MetaM (Option Q($x β‰  (⊀ : ℝβ‰₯0∞))) := do let mvar ← mkFreshExprMVar q($x β‰  (⊀ : ℝβ‰₯0∞)) let save ← saveState let (goals, _) ← Elab.runTactic mvar.mvarId! <|← `(tactic| finiteness) if goals.isEmpty then pure <| some <|← instantiateMVars mvar else restoreState save pure none /-- Extension for the `positivity` tactic: exponentiation by a real number is nonnegative when the base is nonnegative and positive when the base is positive. This is the `ENNReal` analogue of `evalRpow` for `Real`. -/ @[positivity (_ : ℝβ‰₯0∞) ^ (_ : ℝ)] def evalENNRealRpow : PositivityExt where eval {u Ξ±} _ _ e := do match u, Ξ±, e with | 0, ~q(ℝβ‰₯0∞), ~q($a ^ (0 : ℝ)) => assertInstancesCommute pure (.positive q(ENNReal.rpow_zero_pos $a)) | 0, ~q(ℝβ‰₯0∞), ~q($a ^ ($b : ℝ)) => let ra ← core q(inferInstance) q(inferInstance) a let rb ← catchNone <| core q(inferInstance) q(inferInstance) b assertInstancesCommute match ra, rb with | .positive pa, .positive pb => pure (.positive q(ENNReal.rpow_pos_of_nonneg $pa <| le_of_lt $pb)) | .positive pa, .nonnegative pb => pure (.positive q(ENNReal.rpow_pos_of_nonneg $pa $pb)) | .positive pa, _ => let some ha ← isFiniteM? a | pure <| .nonnegative q(zero_le $e) pure <| .positive q(ENNReal.rpow_pos $pa $ha) | _, _ => pure <| .nonnegative q(zero_le $e) | _, _, _ => throwError "not ENNReal.rpow" end Mathlib.Meta.Positivity
.lake/packages/mathlib/Mathlib/Analysis/SpecialFunctions/Pow/Real.lean
import Mathlib.Analysis.SpecialFunctions.Pow.Complex import Mathlib.Data.Nat.NthRoot.Defs import Qq /-! # Power function on `ℝ` We construct the power functions `x ^ y`, where `x` and `y` are real numbers. -/ noncomputable section open Real ComplexConjugate Finset Set /- ## Definitions -/ namespace Real variable {x y z : ℝ} /-- The real power function `x ^ y`, defined as the real part of the complex power function. For `x > 0`, it is equal to `exp (y log x)`. For `x = 0`, one sets `0 ^ 0=1` and `0 ^ y=0` for `y β‰  0`. For `x < 0`, the definition is somewhat arbitrary as it depends on the choice of a complex determination of the logarithm. With our conventions, it is equal to `exp (y log x) cos (Ο€ y)`. -/ noncomputable def rpow (x y : ℝ) := ((x : β„‚) ^ (y : β„‚)).re noncomputable instance : Pow ℝ ℝ := ⟨rpow⟩ @[simp] theorem rpow_eq_pow (x y : ℝ) : rpow x y = x ^ y := rfl theorem rpow_def (x y : ℝ) : x ^ y = ((x : β„‚) ^ (y : β„‚)).re := rfl theorem rpow_def_of_nonneg {x : ℝ} (hx : 0 ≀ x) (y : ℝ) : x ^ y = if x = 0 then if y = 0 then 1 else 0 else exp (log x * y) := by simp only [rpow_def, Complex.cpow_def]; split_ifs <;> simp_all [(Complex.ofReal_log hx).symm, -Complex.ofReal_mul, (Complex.ofReal_mul _ _).symm, Complex.exp_ofReal_re, Complex.ofReal_eq_zero] theorem rpow_def_of_pos {x : ℝ} (hx : 0 < x) (y : ℝ) : x ^ y = exp (log x * y) := by rw [rpow_def_of_nonneg (le_of_lt hx), if_neg (ne_of_gt hx)] theorem exp_mul (x y : ℝ) : exp (x * y) = exp x ^ y := by rw [rpow_def_of_pos (exp_pos _), log_exp] @[simp, norm_cast] theorem rpow_intCast (x : ℝ) (n : β„€) : x ^ (n : ℝ) = x ^ n := by simp only [rpow_def, ← Complex.ofReal_zpow, Complex.cpow_intCast, Complex.ofReal_intCast, Complex.ofReal_re] @[simp, norm_cast] theorem rpow_natCast (x : ℝ) (n : β„•) : x ^ (n : ℝ) = x ^ n := by simpa using rpow_intCast x n @[simp, norm_cast] theorem rpow_neg_natCast (x : ℝ) (n : β„•) : x ^ (-n : ℝ) = x ^ (-n : β„€) := by rw [← rpow_intCast, Int.cast_neg, Int.cast_natCast] @[simp] lemma rpow_ofNat (x : ℝ) (n : β„•) [n.AtLeastTwo] : x ^ (ofNat(n) : ℝ) = x ^ (ofNat(n) : β„•) := rpow_natCast x n @[simp] theorem rpow_neg_ofNat (x : ℝ) (n : β„•) [n.AtLeastTwo] : x ^ (-ofNat(n) : ℝ) = x ^ (-ofNat(n) : β„€) := rpow_neg_natCast _ _ @[simp] theorem exp_one_rpow (x : ℝ) : exp 1 ^ x = exp x := by rw [← exp_mul, one_mul] @[simp] lemma exp_one_pow (n : β„•) : exp 1 ^ n = exp n := by rw [← rpow_natCast, exp_one_rpow] theorem rpow_eq_zero_iff_of_nonneg (hx : 0 ≀ x) : x ^ y = 0 ↔ x = 0 ∧ y β‰  0 := by simp only [rpow_def_of_nonneg hx] split_ifs <;> simp [*, exp_ne_zero] @[simp] lemma rpow_eq_zero (hx : 0 ≀ x) (hy : y β‰  0) : x ^ y = 0 ↔ x = 0 := by simp [rpow_eq_zero_iff_of_nonneg, *] lemma rpow_ne_zero (hx : 0 ≀ x) (hy : y β‰  0) : x ^ y β‰  0 ↔ x β‰  0 := by simp [hx, hy] open Real theorem rpow_def_of_neg {x : ℝ} (hx : x < 0) (y : ℝ) : x ^ y = exp (log x * y) * cos (y * Ο€) := by rw [rpow_def, Complex.cpow_def, if_neg] Β· have : Complex.log x * y = ↑(log (-x) * y) + ↑(y * Ο€) * Complex.I := by simp only [Complex.log, Complex.norm_real, norm_eq_abs, abs_of_neg hx, log_neg_eq_log, Complex.arg_ofReal_of_neg hx, Complex.ofReal_mul] ring rw [this, Complex.exp_add_mul_I, ← Complex.ofReal_exp, ← Complex.ofReal_cos, ← Complex.ofReal_sin, mul_add, ← Complex.ofReal_mul, ← mul_assoc, ← Complex.ofReal_mul, Complex.add_re, Complex.ofReal_re, Complex.mul_re, Complex.I_re, Complex.ofReal_im, Real.log_neg_eq_log] ring Β· rw [Complex.ofReal_eq_zero] exact ne_of_lt hx theorem rpow_def_of_nonpos {x : ℝ} (hx : x ≀ 0) (y : ℝ) : x ^ y = if x = 0 then if y = 0 then 1 else 0 else exp (log x * y) * cos (y * Ο€) := by split_ifs with h <;> simp [rpow_def, *]; exact rpow_def_of_neg (lt_of_le_of_ne hx h) _ @[bound] theorem rpow_pos_of_pos {x : ℝ} (hx : 0 < x) (y : ℝ) : 0 < x ^ y := by rw [rpow_def_of_pos hx]; apply exp_pos @[simp] theorem rpow_zero (x : ℝ) : x ^ (0 : ℝ) = 1 := by simp [rpow_def] theorem rpow_zero_pos (x : ℝ) : 0 < x ^ (0 : ℝ) := by simp @[simp] theorem zero_rpow {x : ℝ} (h : x β‰  0) : (0 : ℝ) ^ x = 0 := by simp [rpow_def, *] theorem zero_rpow_eq_iff {x : ℝ} {a : ℝ} : 0 ^ x = a ↔ x β‰  0 ∧ a = 0 ∨ x = 0 ∧ a = 1 := by constructor Β· intro hyp simp only [rpow_def, Complex.ofReal_zero] at hyp by_cases h : x = 0 Β· subst h simp only [Complex.one_re, Complex.ofReal_zero, Complex.cpow_zero] at hyp exact Or.inr ⟨rfl, hyp.symm⟩ Β· rw [Complex.zero_cpow (Complex.ofReal_ne_zero.mpr h)] at hyp exact Or.inl ⟨h, hyp.symm⟩ Β· rintro (⟨h, rfl⟩ | ⟨rfl, rfl⟩) Β· exact zero_rpow h Β· exact rpow_zero _ theorem eq_zero_rpow_iff {x : ℝ} {a : ℝ} : a = 0 ^ x ↔ x β‰  0 ∧ a = 0 ∨ x = 0 ∧ a = 1 := by rw [← zero_rpow_eq_iff, eq_comm] @[simp] theorem rpow_one (x : ℝ) : x ^ (1 : ℝ) = x := by simp [rpow_def] @[simp] theorem one_rpow (x : ℝ) : (1 : ℝ) ^ x = 1 := by simp [rpow_def] theorem zero_rpow_le_one (x : ℝ) : (0 : ℝ) ^ x ≀ 1 := by by_cases h : x = 0 <;> simp [h, zero_le_one] theorem zero_rpow_nonneg (x : ℝ) : 0 ≀ (0 : ℝ) ^ x := by by_cases h : x = 0 <;> simp [h, zero_le_one] @[bound] theorem rpow_nonneg {x : ℝ} (hx : 0 ≀ x) (y : ℝ) : 0 ≀ x ^ y := by rw [rpow_def_of_nonneg hx]; split_ifs <;> simp only [zero_le_one, le_refl, le_of_lt (exp_pos _)] theorem abs_rpow_of_nonneg {x y : ℝ} (hx_nonneg : 0 ≀ x) : |x ^ y| = |x| ^ y := by have h_rpow_nonneg : 0 ≀ x ^ y := Real.rpow_nonneg hx_nonneg _ rw [abs_eq_self.mpr hx_nonneg, abs_eq_self.mpr h_rpow_nonneg] @[bound] theorem abs_rpow_le_abs_rpow (x y : ℝ) : |x ^ y| ≀ |x| ^ y := by rcases le_or_gt 0 x with hx | hx Β· rw [abs_rpow_of_nonneg hx] Β· rw [abs_of_neg hx, rpow_def_of_neg hx, rpow_def_of_pos (neg_pos.2 hx), log_neg_eq_log, abs_mul, abs_of_pos (exp_pos _)] exact mul_le_of_le_one_right (exp_pos _).le (abs_cos_le_one _) theorem abs_rpow_le_exp_log_mul (x y : ℝ) : |x ^ y| ≀ exp (log x * y) := by refine (abs_rpow_le_abs_rpow x y).trans ?_ by_cases hx : x = 0 Β· by_cases hy : y = 0 <;> simp [hx, hy, zero_le_one] Β· rw [rpow_def_of_pos (abs_pos.2 hx), log_abs] lemma rpow_inv_log (hxβ‚€ : 0 < x) (hx₁ : x β‰  1) : x ^ (log x)⁻¹ = exp 1 := by rw [rpow_def_of_pos hxβ‚€, mul_inv_cancelβ‚€] exact log_ne_zero.2 ⟨hxβ‚€.ne', hx₁, by bound⟩ /-- See `Real.rpow_inv_log` for the equality when `x β‰  1` is strictly positive. -/ lemma rpow_inv_log_le_exp_one : x ^ (log x)⁻¹ ≀ exp 1 := by calc _ ≀ |x ^ (log x)⁻¹| := le_abs_self _ _ ≀ |x| ^ (log x)⁻¹ := abs_rpow_le_abs_rpow .. rw [← log_abs] obtain hx | hx := (abs_nonneg x).eq_or_lt' Β· simp [hx] Β· rw [rpow_def_of_pos hx] gcongr exact mul_inv_le_one theorem norm_rpow_of_nonneg {x y : ℝ} (hx_nonneg : 0 ≀ x) : β€–x ^ yβ€– = β€–xβ€– ^ y := by simp_rw [Real.norm_eq_abs] exact abs_rpow_of_nonneg hx_nonneg variable {w x y z : ℝ} theorem rpow_add (hx : 0 < x) (y z : ℝ) : x ^ (y + z) = x ^ y * x ^ z := by simp only [rpow_def_of_pos hx, mul_add, exp_add] theorem rpow_add' (hx : 0 ≀ x) (h : y + z β‰  0) : x ^ (y + z) = x ^ y * x ^ z := by rcases hx.eq_or_lt with (rfl | pos) Β· rw [zero_rpow h, zero_eq_mul] have : y β‰  0 ∨ z β‰  0 := not_and_or.1 fun ⟨hy, hz⟩ => h <| hy.symm β–Έ hz.symm β–Έ zero_add 0 exact this.imp zero_rpow zero_rpow Β· exact rpow_add pos _ _ /-- Variant of `Real.rpow_add'` that avoids having to prove `y + z = w` twice. -/ lemma rpow_of_add_eq (hx : 0 ≀ x) (hw : w β‰  0) (h : y + z = w) : x ^ w = x ^ y * x ^ z := by rw [← h, rpow_add' hx]; rwa [h] theorem rpow_add_of_nonneg (hx : 0 ≀ x) (hy : 0 ≀ y) (hz : 0 ≀ z) : x ^ (y + z) = x ^ y * x ^ z := by rcases hy.eq_or_lt with (rfl | hy) Β· rw [zero_add, rpow_zero, one_mul] exact rpow_add' hx (ne_of_gt <| add_pos_of_pos_of_nonneg hy hz) /-- For `0 ≀ x`, the only problematic case in the equality `x ^ y * x ^ z = x ^ (y + z)` is for `x = 0` and `y + z = 0`, where the right-hand side is `1` while the left-hand side can vanish. The inequality is always true, though, and given in this lemma. -/ theorem le_rpow_add {x : ℝ} (hx : 0 ≀ x) (y z : ℝ) : x ^ y * x ^ z ≀ x ^ (y + z) := by rcases le_iff_eq_or_lt.1 hx with (H | pos) Β· by_cases h : y + z = 0 Β· simp only [H.symm, h, rpow_zero] calc (0 : ℝ) ^ y * 0 ^ z ≀ 1 * 1 := mul_le_mul (zero_rpow_le_one y) (zero_rpow_le_one z) (zero_rpow_nonneg z) zero_le_one _ = 1 := by simp Β· simp [rpow_add', ← H, h] Β· simp [rpow_add pos] theorem rpow_sum_of_pos {ΞΉ : Type*} {a : ℝ} (ha : 0 < a) (f : ΞΉ β†’ ℝ) (s : Finset ΞΉ) : (a ^ βˆ‘ x ∈ s, f x) = ∏ x ∈ s, a ^ f x := map_sum (⟨⟨fun (x : ℝ) => (a ^ x : ℝ), rpow_zero a⟩, rpow_add ha⟩ : ℝ β†’+ (Additive ℝ)) f s theorem rpow_sum_of_nonneg {ΞΉ : Type*} {a : ℝ} (ha : 0 ≀ a) {s : Finset ΞΉ} {f : ΞΉ β†’ ℝ} (h : βˆ€ x ∈ s, 0 ≀ f x) : (a ^ βˆ‘ x ∈ s, f x) = ∏ x ∈ s, a ^ f x := by induction s using Finset.cons_induction with | empty => rw [sum_empty, Finset.prod_empty, rpow_zero] | cons i s hi ihs => rw [forall_mem_cons] at h rw [sum_cons, prod_cons, ← ihs h.2, rpow_add_of_nonneg ha h.1 (sum_nonneg h.2)] /-- See also `rpow_neg` for a version with `(x ^ y)⁻¹` in the RHS. -/ theorem rpow_neg_eq_inv_rpow (x y : ℝ) : x ^ (-y) = x⁻¹ ^ y := by simp [rpow_def, Complex.cpow_neg, Complex.inv_cpow_eq_ite, apply_ite] /-- See also `rpow_neg_eq_inv_rpow` for a version with `x⁻¹ ^ y` in the RHS. -/ theorem rpow_neg {x : ℝ} (hx : 0 ≀ x) (y : ℝ) : x ^ (-y) = (x ^ y)⁻¹ := by simp only [rpow_def_of_nonneg hx]; split_ifs <;> simp_all [exp_neg] theorem rpow_sub {x : ℝ} (hx : 0 < x) (y z : ℝ) : x ^ (y - z) = x ^ y / x ^ z := by simp only [sub_eq_add_neg, rpow_add hx, rpow_neg (le_of_lt hx), div_eq_mul_inv] theorem rpow_sub' {x : ℝ} (hx : 0 ≀ x) {y z : ℝ} (h : y - z β‰  0) : x ^ (y - z) = x ^ y / x ^ z := by simp only [sub_eq_add_neg] at h ⊒ simp only [rpow_add' hx h, rpow_neg hx, div_eq_mul_inv] protected theorem _root_.HasCompactSupport.rpow_const {Ξ± : Type*} [TopologicalSpace Ξ±] {f : Ξ± β†’ ℝ} (hf : HasCompactSupport f) {r : ℝ} (hr : r β‰  0) : HasCompactSupport (fun x ↦ f x ^ r) := hf.comp_left (g := (Β· ^ r)) (Real.zero_rpow hr) end Real /-! ## Comparing real and complex powers -/ namespace Complex theorem ofReal_cpow {x : ℝ} (hx : 0 ≀ x) (y : ℝ) : ((x ^ y : ℝ) : β„‚) = (x : β„‚) ^ (y : β„‚) := by simp only [Real.rpow_def_of_nonneg hx, Complex.cpow_def, ofReal_eq_zero]; split_ifs <;> simp [Complex.ofReal_log hx] theorem ofReal_cpow_of_nonpos {x : ℝ} (hx : x ≀ 0) (y : β„‚) : (x : β„‚) ^ y = (-x : β„‚) ^ y * exp (Ο€ * I * y) := by rcases hx.eq_or_lt with (rfl | hlt) Β· rcases eq_or_ne y 0 with (rfl | hy) <;> simp [*] have hne : (x : β„‚) β‰  0 := ofReal_ne_zero.mpr hlt.ne rw [cpow_def_of_ne_zero hne, cpow_def_of_ne_zero (neg_ne_zero.2 hne), ← exp_add, ← add_mul, log, log, norm_neg, arg_ofReal_of_neg hlt, ← ofReal_neg, arg_ofReal_of_nonneg (neg_nonneg.2 hx), ofReal_zero, zero_mul, add_zero] lemma cpow_ofReal (x : β„‚) (y : ℝ) : x ^ (y : β„‚) = ↑(β€–xβ€– ^ y) * (Real.cos (arg x * y) + Real.sin (arg x * y) * I) := by rcases eq_or_ne x 0 with rfl | hx Β· simp [ofReal_cpow le_rfl] Β· rw [cpow_def_of_ne_zero hx, exp_eq_exp_re_mul_sin_add_cos, mul_comm (log x)] norm_cast rw [re_ofReal_mul, im_ofReal_mul, log_re, log_im, mul_comm y, mul_comm y, Real.exp_mul, Real.exp_log] rwa [norm_pos_iff] lemma cpow_ofReal_re (x : β„‚) (y : ℝ) : (x ^ (y : β„‚)).re = β€–xβ€– ^ y * Real.cos (arg x * y) := by rw [cpow_ofReal]; generalize arg x * y = z; simp [Real.cos] lemma cpow_ofReal_im (x : β„‚) (y : ℝ) : (x ^ (y : β„‚)).im = β€–xβ€– ^ y * Real.sin (arg x * y) := by rw [cpow_ofReal]; generalize arg x * y = z; simp [Real.sin] theorem norm_cpow_of_ne_zero {z : β„‚} (hz : z β‰  0) (w : β„‚) : β€–z ^ wβ€– = β€–zβ€– ^ w.re / Real.exp (arg z * im w) := by rw [cpow_def_of_ne_zero hz, norm_exp, mul_re, log_re, log_im, Real.exp_sub, Real.rpow_def_of_pos (norm_pos_iff.mpr hz)] theorem norm_cpow_of_imp {z w : β„‚} (h : z = 0 β†’ w.re = 0 β†’ w = 0) : β€–z ^ wβ€– = β€–zβ€– ^ w.re / Real.exp (arg z * im w) := by rcases ne_or_eq z 0 with (hz | rfl) <;> [exact norm_cpow_of_ne_zero hz w; rw [norm_zero]] rcases eq_or_ne w.re 0 with hw | hw Β· simp [h rfl hw] Β· rw [Real.zero_rpow hw, zero_div, zero_cpow, norm_zero] exact ne_of_apply_ne re hw theorem norm_cpow_le (z w : β„‚) : β€–z ^ wβ€– ≀ β€–zβ€– ^ w.re / Real.exp (arg z * im w) := by by_cases! h : z = 0 β†’ w.re = 0 β†’ w = 0 Β· exact (norm_cpow_of_imp h).le Β· simp [h] @[simp] theorem norm_cpow_real (x : β„‚) (y : ℝ) : β€–x ^ (y : β„‚)β€– = β€–xβ€– ^ y := by rw [norm_cpow_of_imp] <;> simp @[simp] theorem norm_cpow_inv_nat (x : β„‚) (n : β„•) : β€–x ^ (n⁻¹ : β„‚)β€– = β€–xβ€– ^ (n⁻¹ : ℝ) := by rw [← norm_cpow_real]; simp theorem norm_cpow_eq_rpow_re_of_pos {x : ℝ} (hx : 0 < x) (y : β„‚) : β€–(x : β„‚) ^ yβ€– = x ^ y.re := by rw [norm_cpow_of_ne_zero (ofReal_ne_zero.mpr hx.ne'), arg_ofReal_of_nonneg hx.le, zero_mul, Real.exp_zero, div_one, Complex.norm_of_nonneg hx.le] theorem norm_cpow_eq_rpow_re_of_nonneg {x : ℝ} (hx : 0 ≀ x) {y : β„‚} (hy : re y β‰  0) : β€–(x : β„‚) ^ yβ€– = x ^ re y := by rw [norm_cpow_of_imp] <;> simp [*, arg_ofReal_of_nonneg, abs_of_nonneg] open Filter in lemma norm_ofReal_cpow_eventually_eq_atTop (c : β„‚) : (fun t : ℝ ↦ β€–(t : β„‚) ^ cβ€–) =αΆ [atTop] fun t ↦ t ^ c.re := by filter_upwards [eventually_gt_atTop 0] with t ht rw [norm_cpow_eq_rpow_re_of_pos ht] lemma norm_natCast_cpow_of_re_ne_zero (n : β„•) {s : β„‚} (hs : s.re β‰  0) : β€–(n : β„‚) ^ sβ€– = (n : ℝ) ^ (s.re) := by rw [← ofReal_natCast, norm_cpow_eq_rpow_re_of_nonneg n.cast_nonneg hs] lemma norm_natCast_cpow_of_pos {n : β„•} (hn : 0 < n) (s : β„‚) : β€–(n : β„‚) ^ sβ€– = (n : ℝ) ^ (s.re) := by rw [← ofReal_natCast, norm_cpow_eq_rpow_re_of_pos (Nat.cast_pos.mpr hn) _] lemma norm_natCast_cpow_pos_of_pos {n : β„•} (hn : 0 < n) (s : β„‚) : 0 < β€–(n : β„‚) ^ sβ€– := (norm_natCast_cpow_of_pos hn _).symm β–Έ Real.rpow_pos_of_pos (Nat.cast_pos.mpr hn) _ theorem cpow_mul_ofReal_nonneg {x : ℝ} (hx : 0 ≀ x) (y : ℝ) (z : β„‚) : (x : β„‚) ^ (↑y * z) = (↑(x ^ y) : β„‚) ^ z := by rw [cpow_mul, ofReal_cpow hx] Β· rw [← ofReal_log hx, ← ofReal_mul, ofReal_im, neg_lt_zero]; exact Real.pi_pos Β· rw [← ofReal_log hx, ← ofReal_mul, ofReal_im]; exact Real.pi_pos.le end Complex /-! ### Positivity extension -/ namespace Mathlib.Meta.Positivity open Lean Meta Qq /-- Extension for the `positivity` tactic: exponentiation by a real number is positive (namely 1) when the exponent is zero. The other cases are done in `evalRpow`. -/ @[positivity (_ : ℝ) ^ (0 : ℝ)] def evalRpowZero : PositivityExt where eval {u Ξ±} _ _ e := do match u, Ξ±, e with | 0, ~q(ℝ), ~q($a ^ (0 : ℝ)) => assertInstancesCommute pure (.positive q(Real.rpow_zero_pos $a)) | _, _, _ => throwError "not Real.rpow" /-- Extension for the `positivity` tactic: exponentiation by a real number is nonnegative when the base is nonnegative and positive when the base is positive. -/ @[positivity (_ : ℝ) ^ (_ : ℝ)] def evalRpow : PositivityExt where eval {u Ξ±} _zΞ± _pΞ± e := do match u, Ξ±, e with | 0, ~q(ℝ), ~q($a ^ ($b : ℝ)) => let ra ← core q(inferInstance) q(inferInstance) a assertInstancesCommute match ra with | .positive pa => pure (.positive q(Real.rpow_pos_of_pos $pa $b)) | .nonnegative pa => pure (.nonnegative q(Real.rpow_nonneg $pa $b)) | _ => pure .none | _, _, _ => throwError "not Real.rpow" end Mathlib.Meta.Positivity /-! ## Further algebraic properties of `rpow` -/ namespace Real variable {x y z : ℝ} {n : β„•} theorem rpow_mul {x : ℝ} (hx : 0 ≀ x) (y z : ℝ) : x ^ (y * z) = (x ^ y) ^ z := by rw [← Complex.ofReal_inj, Complex.ofReal_cpow (rpow_nonneg hx _), Complex.ofReal_cpow hx, Complex.ofReal_mul, Complex.cpow_mul, Complex.ofReal_cpow hx] <;> simp only [(Complex.ofReal_mul _ _).symm, (Complex.ofReal_log hx).symm, Complex.ofReal_im, neg_lt_zero, pi_pos, le_of_lt pi_pos] lemma rpow_pow_comm {x : ℝ} (hx : 0 ≀ x) (y : ℝ) (n : β„•) : (x ^ y) ^ n = (x ^ n) ^ y := by simp_rw [← rpow_natCast, ← rpow_mul hx, mul_comm y] lemma rpow_zpow_comm {x : ℝ} (hx : 0 ≀ x) (y : ℝ) (n : β„€) : (x ^ y) ^ n = (x ^ n) ^ y := by simp_rw [← rpow_intCast, ← rpow_mul hx, mul_comm y] lemma rpow_add_intCast {x : ℝ} (hx : x β‰  0) (y : ℝ) (n : β„€) : x ^ (y + n) = x ^ y * x ^ n := by rw [rpow_def, rpow_def, Complex.ofReal_add, Complex.cpow_add _ _ (Complex.ofReal_ne_zero.mpr hx), Complex.ofReal_intCast, Complex.cpow_intCast, ← Complex.ofReal_zpow, mul_comm, Complex.re_ofReal_mul, mul_comm] lemma rpow_add_natCast {x : ℝ} (hx : x β‰  0) (y : ℝ) (n : β„•) : x ^ (y + n) = x ^ y * x ^ n := by simpa using rpow_add_intCast hx y n lemma rpow_sub_intCast {x : ℝ} (hx : x β‰  0) (y : ℝ) (n : β„€) : x ^ (y - n) = x ^ y / x ^ n := by simpa using rpow_add_intCast hx y (-n) lemma rpow_sub_natCast {x : ℝ} (hx : x β‰  0) (y : ℝ) (n : β„•) : x ^ (y - n) = x ^ y / x ^ n := by simpa using rpow_sub_intCast hx y n lemma rpow_add_intCast' (hx : 0 ≀ x) {n : β„€} (h : y + n β‰  0) : x ^ (y + n) = x ^ y * x ^ n := by rw [rpow_add' hx h, rpow_intCast] lemma rpow_add_natCast' (hx : 0 ≀ x) (h : y + n β‰  0) : x ^ (y + n) = x ^ y * x ^ n := by rw [rpow_add' hx h, rpow_natCast] lemma rpow_sub_intCast' (hx : 0 ≀ x) {n : β„€} (h : y - n β‰  0) : x ^ (y - n) = x ^ y / x ^ n := by rw [rpow_sub' hx h, rpow_intCast] lemma rpow_sub_natCast' (hx : 0 ≀ x) (h : y - n β‰  0) : x ^ (y - n) = x ^ y / x ^ n := by rw [rpow_sub' hx h, rpow_natCast] theorem rpow_add_one {x : ℝ} (hx : x β‰  0) (y : ℝ) : x ^ (y + 1) = x ^ y * x := by simpa using rpow_add_natCast hx y 1 theorem rpow_sub_one {x : ℝ} (hx : x β‰  0) (y : ℝ) : x ^ (y - 1) = x ^ y / x := by simpa using rpow_sub_natCast hx y 1 lemma rpow_add_one' (hx : 0 ≀ x) (h : y + 1 β‰  0) : x ^ (y + 1) = x ^ y * x := by rw [rpow_add' hx h, rpow_one] lemma rpow_one_add' (hx : 0 ≀ x) (h : 1 + y β‰  0) : x ^ (1 + y) = x * x ^ y := by rw [rpow_add' hx h, rpow_one] lemma rpow_sub_one' (hx : 0 ≀ x) (h : y - 1 β‰  0) : x ^ (y - 1) = x ^ y / x := by rw [rpow_sub' hx h, rpow_one] lemma rpow_one_sub' (hx : 0 ≀ x) (h : 1 - y β‰  0) : x ^ (1 - y) = x / x ^ y := by rw [rpow_sub' hx h, rpow_one] theorem rpow_two (x : ℝ) : x ^ (2 : ℝ) = x ^ 2 := by simp theorem rpow_neg_one (x : ℝ) : x ^ (-1 : ℝ) = x⁻¹ := by rw [rpow_neg_eq_inv_rpow, rpow_one] theorem mul_rpow (hx : 0 ≀ x) (hy : 0 ≀ y) : (x * y) ^ z = x ^ z * y ^ z := by iterate 2 rw [Real.rpow_def_of_nonneg]; split_ifs with h_ifs <;> simp_all Β· rw [log_mul β€Ή_β€Ί β€Ή_β€Ί, add_mul, exp_add, rpow_def_of_pos (hy.lt_of_ne' β€Ή_β€Ί)] all_goals positivity theorem inv_rpow (hx : 0 ≀ x) (y : ℝ) : x⁻¹ ^ y = (x ^ y)⁻¹ := by rw [← rpow_neg_eq_inv_rpow, rpow_neg hx] theorem div_rpow (hx : 0 ≀ x) (hy : 0 ≀ y) (z : ℝ) : (x / y) ^ z = x ^ z / y ^ z := by simp only [div_eq_mul_inv, mul_rpow hx (inv_nonneg.2 hy), inv_rpow hy] theorem log_rpow {x : ℝ} (hx : 0 < x) (y : ℝ) : log (x ^ y) = y * log x := by apply exp_injective rw [exp_log (rpow_pos_of_pos hx y), ← exp_log hx, mul_comm, rpow_def_of_pos (exp_pos (log x)) y] theorem mul_log_eq_log_iff {x y z : ℝ} (hx : 0 < x) (hz : 0 < z) : y * log x = log z ↔ x ^ y = z := ⟨fun h ↦ log_injOn_pos (rpow_pos_of_pos hx _) hz <| log_rpow hx _ |>.trans h, by rintro rfl; rw [log_rpow hx]⟩ @[simp] lemma rpow_rpow_inv (hx : 0 ≀ x) (hy : y β‰  0) : (x ^ y) ^ y⁻¹ = x := by rw [← rpow_mul hx, mul_inv_cancelβ‚€ hy, rpow_one] @[simp] lemma rpow_inv_rpow (hx : 0 ≀ x) (hy : y β‰  0) : (x ^ y⁻¹) ^ y = x := by rw [← rpow_mul hx, inv_mul_cancelβ‚€ hy, rpow_one] theorem pow_rpow_inv_natCast (hx : 0 ≀ x) (hn : n β‰  0) : (x ^ n) ^ (n⁻¹ : ℝ) = x := by have hn0 : (n : ℝ) β‰  0 := Nat.cast_ne_zero.2 hn rw [← rpow_natCast, ← rpow_mul hx, mul_inv_cancelβ‚€ hn0, rpow_one] theorem rpow_inv_natCast_pow (hx : 0 ≀ x) (hn : n β‰  0) : (x ^ (n⁻¹ : ℝ)) ^ n = x := by have hn0 : (n : ℝ) β‰  0 := Nat.cast_ne_zero.2 hn rw [← rpow_natCast, ← rpow_mul hx, inv_mul_cancelβ‚€ hn0, rpow_one] lemma rpow_natCast_mul (hx : 0 ≀ x) (n : β„•) (z : ℝ) : x ^ (n * z) = (x ^ n) ^ z := by rw [rpow_mul hx, rpow_natCast] lemma rpow_mul_natCast (hx : 0 ≀ x) (y : ℝ) (n : β„•) : x ^ (y * n) = (x ^ y) ^ n := by rw [rpow_mul hx, rpow_natCast] lemma rpow_intCast_mul (hx : 0 ≀ x) (n : β„€) (z : ℝ) : x ^ (n * z) = (x ^ n) ^ z := by rw [rpow_mul hx, rpow_intCast] lemma rpow_mul_intCast (hx : 0 ≀ x) (y : ℝ) (n : β„€) : x ^ (y * n) = (x ^ y) ^ n := by rw [rpow_mul hx, rpow_intCast] /-! Note: lemmas about `(∏ i ∈ s, f i ^ r)` such as `Real.finset_prod_rpow` are proved in `Mathlib/Analysis/SpecialFunctions/Pow/NNReal.lean` instead. -/ /-! ## Order and monotonicity -/ @[gcongr, bound] theorem rpow_lt_rpow (hx : 0 ≀ x) (hxy : x < y) (hz : 0 < z) : x ^ z < y ^ z := by rw [le_iff_eq_or_lt] at hx; rcases hx with hx | hx Β· rw [← hx, zero_rpow (ne_of_gt hz)] exact rpow_pos_of_pos (by rwa [← hx] at hxy) _ Β· rw [rpow_def_of_pos hx, rpow_def_of_pos (lt_trans hx hxy), exp_lt_exp] exact mul_lt_mul_of_pos_right (log_lt_log hx hxy) hz theorem strictMonoOn_rpow_Ici_of_exponent_pos {r : ℝ} (hr : 0 < r) : StrictMonoOn (fun (x : ℝ) => x ^ r) (Set.Ici 0) := fun _ ha _ _ hab => rpow_lt_rpow ha hab hr @[gcongr, bound] theorem rpow_le_rpow {x y z : ℝ} (h : 0 ≀ x) (h₁ : x ≀ y) (hβ‚‚ : 0 ≀ z) : x ^ z ≀ y ^ z := by rcases eq_or_lt_of_le h₁ with (rfl | h₁'); Β· rfl rcases eq_or_lt_of_le hβ‚‚ with (rfl | hβ‚‚'); Β· simp exact le_of_lt (rpow_lt_rpow h h₁' hβ‚‚') theorem monotoneOn_rpow_Ici_of_exponent_nonneg {r : ℝ} (hr : 0 ≀ r) : MonotoneOn (fun (x : ℝ) => x ^ r) (Set.Ici 0) := fun _ ha _ _ hab => rpow_le_rpow ha hab hr lemma rpow_lt_rpow_of_neg (hx : 0 < x) (hxy : x < y) (hz : z < 0) : y ^ z < x ^ z := by have := hx.trans hxy rw [← inv_lt_invβ‚€, ← rpow_neg, ← rpow_neg] on_goal 1 => refine rpow_lt_rpow ?_ hxy (neg_pos.2 hz) all_goals positivity lemma rpow_le_rpow_of_nonpos (hx : 0 < x) (hxy : x ≀ y) (hz : z ≀ 0) : y ^ z ≀ x ^ z := by have := hx.trans_le hxy rw [← inv_le_invβ‚€, ← rpow_neg, ← rpow_neg] on_goal 1 => refine rpow_le_rpow ?_ hxy (neg_nonneg.2 hz) all_goals positivity theorem rpow_lt_rpow_iff (hx : 0 ≀ x) (hy : 0 ≀ y) (hz : 0 < z) : x ^ z < y ^ z ↔ x < y := ⟨lt_imp_lt_of_le_imp_le fun h => rpow_le_rpow hy h (le_of_lt hz), fun h => rpow_lt_rpow hx h hz⟩ theorem rpow_le_rpow_iff (hx : 0 ≀ x) (hy : 0 ≀ y) (hz : 0 < z) : x ^ z ≀ y ^ z ↔ x ≀ y := le_iff_le_iff_lt_iff_lt.2 <| rpow_lt_rpow_iff hy hx hz lemma rpow_lt_rpow_iff_of_neg (hx : 0 < x) (hy : 0 < y) (hz : z < 0) : x ^ z < y ^ z ↔ y < x := ⟨lt_imp_lt_of_le_imp_le fun h ↦ rpow_le_rpow_of_nonpos hx h hz.le, fun h ↦ rpow_lt_rpow_of_neg hy h hz⟩ lemma rpow_le_rpow_iff_of_neg (hx : 0 < x) (hy : 0 < y) (hz : z < 0) : x ^ z ≀ y ^ z ↔ y ≀ x := le_iff_le_iff_lt_iff_lt.2 <| rpow_lt_rpow_iff_of_neg hy hx hz lemma le_rpow_inv_iff_of_pos (hx : 0 ≀ x) (hy : 0 ≀ y) (hz : 0 < z) : x ≀ y ^ z⁻¹ ↔ x ^ z ≀ y := by rw [← rpow_le_rpow_iff hx _ hz, rpow_inv_rpow] <;> positivity lemma rpow_inv_le_iff_of_pos (hx : 0 ≀ x) (hy : 0 ≀ y) (hz : 0 < z) : x ^ z⁻¹ ≀ y ↔ x ≀ y ^ z := by rw [← rpow_le_rpow_iff _ hy hz, rpow_inv_rpow] <;> positivity lemma lt_rpow_inv_iff_of_pos (hx : 0 ≀ x) (hy : 0 ≀ y) (hz : 0 < z) : x < y ^ z⁻¹ ↔ x ^ z < y := lt_iff_lt_of_le_iff_le <| rpow_inv_le_iff_of_pos hy hx hz lemma rpow_inv_lt_iff_of_pos (hx : 0 ≀ x) (hy : 0 ≀ y) (hz : 0 < z) : x ^ z⁻¹ < y ↔ x < y ^ z := lt_iff_lt_of_le_iff_le <| le_rpow_inv_iff_of_pos hy hx hz theorem le_rpow_inv_iff_of_neg (hx : 0 < x) (hy : 0 < y) (hz : z < 0) : x ≀ y ^ z⁻¹ ↔ y ≀ x ^ z := by rw [← rpow_le_rpow_iff_of_neg _ hx hz, rpow_inv_rpow _ hz.ne] <;> positivity theorem lt_rpow_inv_iff_of_neg (hx : 0 < x) (hy : 0 < y) (hz : z < 0) : x < y ^ z⁻¹ ↔ y < x ^ z := by rw [← rpow_lt_rpow_iff_of_neg _ hx hz, rpow_inv_rpow _ hz.ne] <;> positivity theorem rpow_inv_lt_iff_of_neg (hx : 0 < x) (hy : 0 < y) (hz : z < 0) : x ^ z⁻¹ < y ↔ y ^ z < x := by rw [← rpow_lt_rpow_iff_of_neg hy _ hz, rpow_inv_rpow _ hz.ne] <;> positivity theorem rpow_inv_le_iff_of_neg (hx : 0 < x) (hy : 0 < y) (hz : z < 0) : x ^ z⁻¹ ≀ y ↔ y ^ z ≀ x := by rw [← rpow_le_rpow_iff_of_neg hy _ hz, rpow_inv_rpow _ hz.ne] <;> positivity theorem rpow_lt_rpow_of_exponent_lt (hx : 1 < x) (hyz : y < z) : x ^ y < x ^ z := by repeat' rw [rpow_def_of_pos (lt_trans zero_lt_one hx)] rw [exp_lt_exp]; exact mul_lt_mul_of_pos_left hyz (log_pos hx) @[gcongr] theorem rpow_le_rpow_of_exponent_le (hx : 1 ≀ x) (hyz : y ≀ z) : x ^ y ≀ x ^ z := by repeat' rw [rpow_def_of_pos (lt_of_lt_of_le zero_lt_one hx)] rw [exp_le_exp]; exact mul_le_mul_of_nonneg_left hyz (log_nonneg hx) @[deprecated (since := "2025-10-28")] alias rpow_lt_rpow_of_exponent_neg := rpow_lt_rpow_of_neg theorem strictAntiOn_rpow_Ioi_of_exponent_neg {r : ℝ} (hr : r < 0) : StrictAntiOn (fun (x : ℝ) => x ^ r) (Set.Ioi 0) := fun _ ha _ _ hab => rpow_lt_rpow_of_neg ha hab hr @[deprecated (since := "2025-10-28")] alias rpow_le_rpow_of_exponent_nonpos := rpow_le_rpow_of_nonpos theorem antitoneOn_rpow_Ioi_of_exponent_nonpos {r : ℝ} (hr : r ≀ 0) : AntitoneOn (fun (x : ℝ) => x ^ r) (Set.Ioi 0) := fun _ ha _ _ hab => rpow_le_rpow_of_nonpos ha hab hr @[simp] theorem rpow_le_rpow_left_iff (hx : 1 < x) : x ^ y ≀ x ^ z ↔ y ≀ z := by have x_pos : 0 < x := lt_trans zero_lt_one hx rw [← log_le_log_iff (rpow_pos_of_pos x_pos y) (rpow_pos_of_pos x_pos z), log_rpow x_pos, log_rpow x_pos, mul_le_mul_iff_leftβ‚€ (log_pos hx)] @[simp] theorem rpow_lt_rpow_left_iff (hx : 1 < x) : x ^ y < x ^ z ↔ y < z := by rw [lt_iff_not_ge, rpow_le_rpow_left_iff hx, lt_iff_not_ge] theorem rpow_lt_rpow_of_exponent_gt (hx0 : 0 < x) (hx1 : x < 1) (hyz : z < y) : x ^ y < x ^ z := by repeat' rw [rpow_def_of_pos hx0] rw [exp_lt_exp]; exact mul_lt_mul_of_neg_left hyz (log_neg hx0 hx1) theorem rpow_le_rpow_of_exponent_ge (hx0 : 0 < x) (hx1 : x ≀ 1) (hyz : z ≀ y) : x ^ y ≀ x ^ z := by repeat' rw [rpow_def_of_pos hx0] rw [exp_le_exp]; exact mul_le_mul_of_nonpos_left hyz (log_nonpos (le_of_lt hx0) hx1) @[simp] theorem rpow_le_rpow_left_iff_of_base_lt_one (hx0 : 0 < x) (hx1 : x < 1) : x ^ y ≀ x ^ z ↔ z ≀ y := by rw [← log_le_log_iff (rpow_pos_of_pos hx0 y) (rpow_pos_of_pos hx0 z), log_rpow hx0, log_rpow hx0, mul_le_mul_right_of_neg (log_neg hx0 hx1)] @[simp] theorem rpow_lt_rpow_left_iff_of_base_lt_one (hx0 : 0 < x) (hx1 : x < 1) : x ^ y < x ^ z ↔ z < y := by rw [lt_iff_not_ge, rpow_le_rpow_left_iff_of_base_lt_one hx0 hx1, lt_iff_not_ge] theorem rpow_lt_one {x z : ℝ} (hx1 : 0 ≀ x) (hx2 : x < 1) (hz : 0 < z) : x ^ z < 1 := by rw [← one_rpow z] exact rpow_lt_rpow hx1 hx2 hz theorem rpow_le_one {x z : ℝ} (hx1 : 0 ≀ x) (hx2 : x ≀ 1) (hz : 0 ≀ z) : x ^ z ≀ 1 := by rw [← one_rpow z] exact rpow_le_rpow hx1 hx2 hz theorem rpow_lt_one_of_one_lt_of_neg {x z : ℝ} (hx : 1 < x) (hz : z < 0) : x ^ z < 1 := by convert rpow_lt_rpow_of_exponent_lt hx hz exact (rpow_zero x).symm theorem rpow_le_one_of_one_le_of_nonpos {x z : ℝ} (hx : 1 ≀ x) (hz : z ≀ 0) : x ^ z ≀ 1 := by convert rpow_le_rpow_of_exponent_le hx hz exact (rpow_zero x).symm theorem one_lt_rpow {x z : ℝ} (hx : 1 < x) (hz : 0 < z) : 1 < x ^ z := by rw [← one_rpow z] exact rpow_lt_rpow zero_le_one hx hz theorem one_le_rpow {x z : ℝ} (hx : 1 ≀ x) (hz : 0 ≀ z) : 1 ≀ x ^ z := by rw [← one_rpow z] exact rpow_le_rpow zero_le_one hx hz theorem one_lt_rpow_of_pos_of_lt_one_of_neg (hx1 : 0 < x) (hx2 : x < 1) (hz : z < 0) : 1 < x ^ z := by convert rpow_lt_rpow_of_exponent_gt hx1 hx2 hz exact (rpow_zero x).symm theorem one_le_rpow_of_pos_of_le_one_of_nonpos (hx1 : 0 < x) (hx2 : x ≀ 1) (hz : z ≀ 0) : 1 ≀ x ^ z := by convert rpow_le_rpow_of_exponent_ge hx1 hx2 hz exact (rpow_zero x).symm theorem rpow_lt_one_iff_of_pos (hx : 0 < x) : x ^ y < 1 ↔ 1 < x ∧ y < 0 ∨ x < 1 ∧ 0 < y := by rw [rpow_def_of_pos hx, exp_lt_one_iff, mul_neg_iff, log_pos_iff hx.le, log_neg_iff hx] theorem rpow_lt_one_iff (hx : 0 ≀ x) : x ^ y < 1 ↔ x = 0 ∧ y β‰  0 ∨ 1 < x ∧ y < 0 ∨ x < 1 ∧ 0 < y := by rcases hx.eq_or_lt with (rfl | hx) Β· rcases _root_.em (y = 0) with (rfl | hy) <;> simp [*, zero_lt_one] Β· simp [rpow_lt_one_iff_of_pos hx, hx.ne.symm] theorem rpow_lt_one_iff' {x y : ℝ} (hx : 0 ≀ x) (hy : 0 < y) : x ^ y < 1 ↔ x < 1 := by rw [← Real.rpow_lt_rpow_iff hx zero_le_one hy, Real.one_rpow] theorem one_lt_rpow_iff_of_pos (hx : 0 < x) : 1 < x ^ y ↔ 1 < x ∧ 0 < y ∨ x < 1 ∧ y < 0 := by rw [rpow_def_of_pos hx, one_lt_exp_iff, mul_pos_iff, log_pos_iff hx.le, log_neg_iff hx] theorem one_lt_rpow_iff (hx : 0 ≀ x) : 1 < x ^ y ↔ 1 < x ∧ 0 < y ∨ 0 < x ∧ x < 1 ∧ y < 0 := by rcases hx.eq_or_lt with (rfl | hx) Β· rcases _root_.em (y = 0) with (rfl | hy) <;> simp [*, (zero_lt_one' ℝ).not_gt] Β· simp [one_lt_rpow_iff_of_pos hx, hx] /-- This is a more general but less convenient version of `rpow_le_rpow_of_exponent_ge`. This version allows `x = 0`, so it explicitly forbids `x = y = 0`, `z β‰  0`. -/ theorem rpow_le_rpow_of_exponent_ge_of_imp (hx0 : 0 ≀ x) (hx1 : x ≀ 1) (hyz : z ≀ y) (h : x = 0 β†’ y = 0 β†’ z = 0) : x ^ y ≀ x ^ z := by rcases eq_or_lt_of_le hx0 with (rfl | hx0') Β· rcases eq_or_ne y 0 with rfl | hy0 Β· rw [h rfl rfl] Β· rw [zero_rpow hy0] apply zero_rpow_nonneg Β· exact rpow_le_rpow_of_exponent_ge hx0' hx1 hyz /-- This version of `rpow_le_rpow_of_exponent_ge` allows `x = 0` but requires `0 ≀ z`. See also `rpow_le_rpow_of_exponent_ge_of_imp` for the most general version. -/ theorem rpow_le_rpow_of_exponent_ge' (hx0 : 0 ≀ x) (hx1 : x ≀ 1) (hz : 0 ≀ z) (hyz : z ≀ y) : x ^ y ≀ x ^ z := rpow_le_rpow_of_exponent_ge_of_imp hx0 hx1 hyz fun _ hy ↦ le_antisymm (hyz.trans_eq hy) hz lemma rpow_max {x y p : ℝ} (hx : 0 ≀ x) (hy : 0 ≀ y) (hp : 0 ≀ p) : (max x y) ^ p = max (x ^ p) (y ^ p) := by rcases le_total x y with hxy | hxy Β· rw [max_eq_right hxy, max_eq_right (rpow_le_rpow hx hxy hp)] Β· rw [max_eq_left hxy, max_eq_left (rpow_le_rpow hy hxy hp)] theorem self_le_rpow_of_le_one (h₁ : 0 ≀ x) (hβ‚‚ : x ≀ 1) (h₃ : y ≀ 1) : x ≀ x ^ y := by simpa only [rpow_one] using rpow_le_rpow_of_exponent_ge_of_imp h₁ hβ‚‚ h₃ fun _ ↦ (absurd Β· one_ne_zero) theorem self_le_rpow_of_one_le (h₁ : 1 ≀ x) (hβ‚‚ : 1 ≀ y) : x ≀ x ^ y := by simpa only [rpow_one] using rpow_le_rpow_of_exponent_le h₁ hβ‚‚ theorem rpow_le_self_of_le_one (h₁ : 0 ≀ x) (hβ‚‚ : x ≀ 1) (h₃ : 1 ≀ y) : x ^ y ≀ x := by simpa only [rpow_one] using rpow_le_rpow_of_exponent_ge_of_imp h₁ hβ‚‚ h₃ fun _ ↦ (absurd Β· (one_pos.trans_le h₃).ne') theorem rpow_le_self_of_one_le (h₁ : 1 ≀ x) (hβ‚‚ : y ≀ 1) : x ^ y ≀ x := by simpa only [rpow_one] using rpow_le_rpow_of_exponent_le h₁ hβ‚‚ theorem self_lt_rpow_of_lt_one (h₁ : 0 < x) (hβ‚‚ : x < 1) (h₃ : y < 1) : x < x ^ y := by simpa only [rpow_one] using rpow_lt_rpow_of_exponent_gt h₁ hβ‚‚ h₃ theorem self_lt_rpow_of_one_lt (h₁ : 1 < x) (hβ‚‚ : 1 < y) : x < x ^ y := by simpa only [rpow_one] using rpow_lt_rpow_of_exponent_lt h₁ hβ‚‚ theorem rpow_lt_self_of_lt_one (h₁ : 0 < x) (hβ‚‚ : x < 1) (h₃ : 1 < y) : x ^ y < x := by simpa only [rpow_one] using rpow_lt_rpow_of_exponent_gt h₁ hβ‚‚ h₃ theorem rpow_lt_self_of_one_lt (h₁ : 1 < x) (hβ‚‚ : y < 1) : x ^ y < x := by simpa only [rpow_one] using rpow_lt_rpow_of_exponent_lt h₁ hβ‚‚ theorem rpow_left_injOn {x : ℝ} (hx : x β‰  0) : InjOn (fun y : ℝ => y ^ x) { y : ℝ | 0 ≀ y } := by rintro y hy z hz (hyz : y ^ x = z ^ x) rw [← rpow_one y, ← rpow_one z, ← mul_inv_cancelβ‚€ hx, rpow_mul hy, rpow_mul hz, hyz] lemma rpow_left_inj (hx : 0 ≀ x) (hy : 0 ≀ y) (hz : z β‰  0) : x ^ z = y ^ z ↔ x = y := (rpow_left_injOn hz).eq_iff hx hy lemma rpow_inv_eq (hx : 0 ≀ x) (hy : 0 ≀ y) (hz : z β‰  0) : x ^ z⁻¹ = y ↔ x = y ^ z := by rw [← rpow_left_inj _ hy hz, rpow_inv_rpow hx hz]; positivity lemma eq_rpow_inv (hx : 0 ≀ x) (hy : 0 ≀ y) (hz : z β‰  0) : x = y ^ z⁻¹ ↔ x ^ z = y := by rw [← rpow_left_inj hx _ hz, rpow_inv_rpow hy hz]; positivity theorem le_rpow_iff_log_le (hx : 0 < x) (hy : 0 < y) : x ≀ y ^ z ↔ log x ≀ z * log y := by rw [← log_le_log_iff hx (rpow_pos_of_pos hy z), log_rpow hy] lemma le_pow_iff_log_le (hx : 0 < x) (hy : 0 < y) : x ≀ y ^ n ↔ log x ≀ n * log y := rpow_natCast _ _ β–Έ le_rpow_iff_log_le hx hy lemma le_zpow_iff_log_le {n : β„€} (hx : 0 < x) (hy : 0 < y) : x ≀ y ^ n ↔ log x ≀ n * log y := rpow_intCast _ _ β–Έ le_rpow_iff_log_le hx hy lemma le_rpow_of_log_le (hy : 0 < y) (h : log x ≀ z * log y) : x ≀ y ^ z := by obtain hx | hx := le_or_gt x 0 Β· exact hx.trans (rpow_pos_of_pos hy _).le Β· exact (le_rpow_iff_log_le hx hy).2 h lemma le_pow_of_log_le (hy : 0 < y) (h : log x ≀ n * log y) : x ≀ y ^ n := rpow_natCast _ _ β–Έ le_rpow_of_log_le hy h lemma le_zpow_of_log_le {n : β„€} (hy : 0 < y) (h : log x ≀ n * log y) : x ≀ y ^ n := rpow_intCast _ _ β–Έ le_rpow_of_log_le hy h theorem lt_rpow_iff_log_lt (hx : 0 < x) (hy : 0 < y) : x < y ^ z ↔ log x < z * log y := by rw [← log_lt_log_iff hx (rpow_pos_of_pos hy z), log_rpow hy] lemma lt_pow_iff_log_lt (hx : 0 < x) (hy : 0 < y) : x < y ^ n ↔ log x < n * log y := rpow_natCast _ _ β–Έ lt_rpow_iff_log_lt hx hy lemma lt_zpow_iff_log_lt {n : β„€} (hx : 0 < x) (hy : 0 < y) : x < y ^ n ↔ log x < n * log y := rpow_intCast _ _ β–Έ lt_rpow_iff_log_lt hx hy lemma lt_rpow_of_log_lt (hy : 0 < y) (h : log x < z * log y) : x < y ^ z := by obtain hx | hx := le_or_gt x 0 Β· exact hx.trans_lt (rpow_pos_of_pos hy _) Β· exact (lt_rpow_iff_log_lt hx hy).2 h lemma lt_pow_of_log_lt (hy : 0 < y) (h : log x < n * log y) : x < y ^ n := rpow_natCast _ _ β–Έ lt_rpow_of_log_lt hy h lemma lt_zpow_of_log_lt {n : β„€} (hy : 0 < y) (h : log x < n * log y) : x < y ^ n := rpow_intCast _ _ β–Έ lt_rpow_of_log_lt hy h lemma rpow_le_iff_le_log (hx : 0 < x) (hy : 0 < y) : x ^ z ≀ y ↔ z * log x ≀ log y := by rw [← log_le_log_iff (rpow_pos_of_pos hx _) hy, log_rpow hx] lemma pow_le_iff_le_log (hx : 0 < x) (hy : 0 < y) : x ^ n ≀ y ↔ n * log x ≀ log y := by rw [← rpow_le_iff_le_log hx hy, rpow_natCast] lemma zpow_le_iff_le_log {n : β„€} (hx : 0 < x) (hy : 0 < y) : x ^ n ≀ y ↔ n * log x ≀ log y := by rw [← rpow_le_iff_le_log hx hy, rpow_intCast] lemma le_log_of_rpow_le (hx : 0 < x) (h : x ^ z ≀ y) : z * log x ≀ log y := log_rpow hx _ β–Έ log_le_log (by positivity) h lemma le_log_of_pow_le (hx : 0 < x) (h : x ^ n ≀ y) : n * log x ≀ log y := le_log_of_rpow_le hx (rpow_natCast _ _ β–Έ h) lemma le_log_of_zpow_le {n : β„€} (hx : 0 < x) (h : x ^ n ≀ y) : n * log x ≀ log y := le_log_of_rpow_le hx (rpow_intCast _ _ β–Έ h) lemma rpow_le_of_le_log (hy : 0 < y) (h : log x ≀ z * log y) : x ≀ y ^ z := by obtain hx | hx := le_or_gt x 0 Β· exact hx.trans (rpow_pos_of_pos hy _).le Β· exact (le_rpow_iff_log_le hx hy).2 h lemma pow_le_of_le_log (hy : 0 < y) (h : log x ≀ n * log y) : x ≀ y ^ n := rpow_natCast _ _ β–Έ rpow_le_of_le_log hy h lemma zpow_le_of_le_log {n : β„€} (hy : 0 < y) (h : log x ≀ n * log y) : x ≀ y ^ n := rpow_intCast _ _ β–Έ rpow_le_of_le_log hy h lemma rpow_lt_iff_lt_log (hx : 0 < x) (hy : 0 < y) : x ^ z < y ↔ z * log x < log y := by rw [← log_lt_log_iff (rpow_pos_of_pos hx _) hy, log_rpow hx] lemma pow_lt_iff_lt_log (hx : 0 < x) (hy : 0 < y) : x ^ n < y ↔ n * log x < log y := by rw [← rpow_lt_iff_lt_log hx hy, rpow_natCast] lemma zpow_lt_iff_lt_log {n : β„€} (hx : 0 < x) (hy : 0 < y) : x ^ n < y ↔ n * log x < log y := by rw [← rpow_lt_iff_lt_log hx hy, rpow_intCast] lemma lt_log_of_rpow_lt (hx : 0 < x) (h : x ^ z < y) : z * log x < log y := log_rpow hx _ β–Έ log_lt_log (by positivity) h lemma lt_log_of_pow_lt (hx : 0 < x) (h : x ^ n < y) : n * log x < log y := lt_log_of_rpow_lt hx (rpow_natCast _ _ β–Έ h) lemma lt_log_of_zpow_lt {n : β„€} (hx : 0 < x) (h : x ^ n < y) : n * log x < log y := lt_log_of_rpow_lt hx (rpow_intCast _ _ β–Έ h) lemma rpow_lt_of_lt_log (hy : 0 < y) (h : log x < z * log y) : x < y ^ z := by obtain hx | hx := le_or_gt x 0 Β· exact hx.trans_lt (rpow_pos_of_pos hy _) Β· exact (lt_rpow_iff_log_lt hx hy).2 h lemma pow_lt_of_lt_log (hy : 0 < y) (h : log x < n * log y) : x < y ^ n := rpow_natCast _ _ β–Έ rpow_lt_of_lt_log hy h lemma zpow_lt_of_lt_log {n : β„€} (hy : 0 < y) (h : log x < n * log y) : x < y ^ n := rpow_intCast _ _ β–Έ rpow_lt_of_lt_log hy h theorem rpow_le_one_iff_of_pos (hx : 0 < x) : x ^ y ≀ 1 ↔ 1 ≀ x ∧ y ≀ 0 ∨ x ≀ 1 ∧ 0 ≀ y := by rw [rpow_def_of_pos hx, exp_le_one_iff, mul_nonpos_iff, log_nonneg_iff hx, log_nonpos_iff hx.le] /-- Bound for `|log x * x ^ t|` in the interval `(0, 1]`, for positive real `t`. -/ theorem abs_log_mul_self_rpow_lt (x t : ℝ) (h1 : 0 < x) (h2 : x ≀ 1) (ht : 0 < t) : |log x * x ^ t| < 1 / t := by rw [lt_div_iffβ‚€ ht] have := abs_log_mul_self_lt (x ^ t) (rpow_pos_of_pos h1 t) (rpow_le_one h1.le h2 ht.le) rwa [log_rpow h1, mul_assoc, abs_mul, abs_of_pos ht, mul_comm] at this /-- `log x` is bounded above by a multiple of every power of `x` with positive exponent. -/ lemma log_le_rpow_div {x Ξ΅ : ℝ} (hx : 0 ≀ x) (hΞ΅ : 0 < Ξ΅) : log x ≀ x ^ Ξ΅ / Ξ΅ := by rcases hx.eq_or_lt with rfl | h Β· rw [log_zero, zero_rpow hΞ΅.ne', zero_div] rw [le_div_iffβ‚€' hΞ΅] exact (log_rpow h Ξ΅).symm.trans_le <| (log_le_sub_one_of_pos <| rpow_pos_of_pos h Ξ΅).trans (sub_one_lt _).le /-- The (real) logarithm of a natural number `n` is bounded by a multiple of every power of `n` with positive exponent. -/ lemma log_natCast_le_rpow_div (n : β„•) {Ξ΅ : ℝ} (hΞ΅ : 0 < Ξ΅) : log n ≀ n ^ Ξ΅ / Ξ΅ := log_le_rpow_div n.cast_nonneg hΞ΅ lemma strictMono_rpow_of_base_gt_one {b : ℝ} (hb : 1 < b) : StrictMono (b ^ Β· : ℝ β†’ ℝ) := by simp_rw [Real.rpow_def_of_pos (zero_lt_one.trans hb)] exact exp_strictMono.comp <| StrictMono.const_mul strictMono_id <| Real.log_pos hb lemma monotone_rpow_of_base_ge_one {b : ℝ} (hb : 1 ≀ b) : Monotone (b ^ Β· : ℝ β†’ ℝ) := by rcases lt_or_eq_of_le hb with hb | rfl case inl => exact (strictMono_rpow_of_base_gt_one hb).monotone case inr => intro _ _ _; simp lemma strictAnti_rpow_of_base_lt_one {b : ℝ} (hbβ‚€ : 0 < b) (hb₁ : b < 1) : StrictAnti (b ^ Β· : ℝ β†’ ℝ) := by simp_rw [Real.rpow_def_of_pos hbβ‚€] exact exp_strictMono.comp_strictAnti <| StrictMono.const_mul_of_neg strictMono_id <| Real.log_neg hbβ‚€ hb₁ lemma antitone_rpow_of_base_le_one {b : ℝ} (hbβ‚€ : 0 < b) (hb₁ : b ≀ 1) : Antitone (b ^ Β· : ℝ β†’ ℝ) := by rcases lt_or_eq_of_le hb₁ with hb₁ | rfl case inl => exact (strictAnti_rpow_of_base_lt_one hbβ‚€ hb₁).antitone case inr => intro _ _ _; simp lemma rpow_right_inj (hxβ‚€ : 0 < x) (hx₁ : x β‰  1) : x ^ y = x ^ z ↔ y = z := by refine ⟨fun H ↦ ?_, fun H ↦ by rw [H]⟩ rcases hx₁.lt_or_gt with h | h Β· exact (strictAnti_rpow_of_base_lt_one hxβ‚€ h).injective H Β· exact (strictMono_rpow_of_base_gt_one h).injective H /-- Guessing rule for the `bound` tactic: when trying to prove `x ^ y ≀ x ^ z`, we can either assume `1 ≀ x` or `0 < x ≀ 1`. -/ @[bound] lemma rpow_le_rpow_of_exponent_le_or_ge {x y z : ℝ} (h : 1 ≀ x ∧ y ≀ z ∨ 0 < x ∧ x ≀ 1 ∧ z ≀ y) : x ^ y ≀ x ^ z := by rcases h with ⟨x1, yz⟩ | ⟨x0, x1, zy⟩ Β· exact Real.rpow_le_rpow_of_exponent_le x1 yz Β· exact Real.rpow_le_rpow_of_exponent_ge x0 x1 zy end Real namespace Complex lemma norm_prime_cpow_le_one_half (p : Nat.Primes) {s : β„‚} (hs : 1 < s.re) : β€–(p : β„‚) ^ (-s)β€– ≀ 1 / 2 := by rw [norm_natCast_cpow_of_re_ne_zero p <| by rw [neg_re]; linarith only [hs]] refine (Real.rpow_le_rpow_of_nonpos zero_lt_two (Nat.cast_le.mpr p.prop.two_le) <| by rw [neg_re]; linarith only [hs]).trans ?_ rw [one_div, ← Real.rpow_neg_one] exact Real.rpow_le_rpow_of_exponent_le one_le_two <| (neg_lt_neg hs).le lemma one_sub_prime_cpow_ne_zero {p : β„•} (hp : p.Prime) {s : β„‚} (hs : 1 < s.re) : 1 - (p : β„‚) ^ (-s) β‰  0 := by refine sub_ne_zero_of_ne fun H ↦ ?_ have := norm_prime_cpow_le_one_half ⟨p, hp⟩ hs simp only at this rw [← H, norm_one] at this norm_num at this lemma norm_natCast_cpow_le_norm_natCast_cpow_of_pos {n : β„•} (hn : 0 < n) {w z : β„‚} (h : w.re ≀ z.re) : β€–(n : β„‚) ^ wβ€– ≀ β€–(n : β„‚) ^ zβ€– := by simp_rw [norm_natCast_cpow_of_pos hn] exact Real.rpow_le_rpow_of_exponent_le (by exact_mod_cast hn) h lemma norm_natCast_cpow_le_norm_natCast_cpow_iff {n : β„•} (hn : 1 < n) {w z : β„‚} : β€–(n : β„‚) ^ wβ€– ≀ β€–(n : β„‚) ^ zβ€– ↔ w.re ≀ z.re := by simp_rw [norm_natCast_cpow_of_pos (Nat.zero_lt_of_lt hn), Real.rpow_le_rpow_left_iff (Nat.one_lt_cast.mpr hn)] lemma norm_log_natCast_le_rpow_div (n : β„•) {Ξ΅ : ℝ} (hΞ΅ : 0 < Ξ΅) : β€–log nβ€– ≀ n ^ Ξ΅ / Ξ΅ := by rcases n.eq_zero_or_pos with rfl | h Β· rw [Nat.cast_zero, Nat.cast_zero, log_zero, norm_zero, Real.zero_rpow hΞ΅.ne', zero_div] rw [← natCast_log, norm_real, norm_of_nonneg <| Real.log_nonneg <| by exact_mod_cast Nat.one_le_of_lt h.lt] exact Real.log_natCast_le_rpow_div n hΞ΅ end Complex /-! ## Square roots of reals -/ namespace Real variable {z x y : ℝ} section Sqrt theorem sqrt_eq_rpow (x : ℝ) : √x = x ^ (1 / (2 : ℝ)) := by obtain h | h := le_or_gt 0 x Β· rw [← mul_self_inj_of_nonneg (sqrt_nonneg _) (rpow_nonneg h _), mul_self_sqrt h, ← sq, ← rpow_natCast, ← rpow_mul h] simp Β· have : 1 / (2 : ℝ) * Ο€ = Ο€ / (2 : ℝ) := by ring rw [sqrt_eq_zero_of_nonpos h.le, rpow_def_of_neg h, this, cos_pi_div_two, mul_zero] theorem rpow_div_two_eq_sqrt {x : ℝ} (r : ℝ) (hx : 0 ≀ x) : x ^ (r / 2) = √x ^ r := by rw [sqrt_eq_rpow, ← rpow_mul hx] congr ring end Sqrt end Real namespace Complex lemma cpow_inv_two_re (x : β„‚) : (x ^ (2⁻¹ : β„‚)).re = √((β€–xβ€– + x.re) / 2) := by rw [← ofReal_ofNat, ← ofReal_inv, cpow_ofReal_re, ← div_eq_mul_inv, ← one_div, ← Real.sqrt_eq_rpow, cos_half, ← sqrt_mul, ← mul_div_assoc, mul_add, mul_one, norm_mul_cos_arg] exacts [norm_nonneg _, (neg_pi_lt_arg _).le, arg_le_pi _] lemma cpow_inv_two_im_eq_sqrt {x : β„‚} (hx : 0 ≀ x.im) : (x ^ (2⁻¹ : β„‚)).im = √((β€–xβ€– - x.re) / 2) := by rw [← ofReal_ofNat, ← ofReal_inv, cpow_ofReal_im, ← div_eq_mul_inv, ← one_div, ← Real.sqrt_eq_rpow, sin_half_eq_sqrt, ← sqrt_mul (norm_nonneg _), ← mul_div_assoc, mul_sub, mul_one, norm_mul_cos_arg] Β· rwa [arg_nonneg_iff] Β· linarith [pi_pos, arg_le_pi x] lemma cpow_inv_two_im_eq_neg_sqrt {x : β„‚} (hx : x.im < 0) : (x ^ (2⁻¹ : β„‚)).im = -√((β€–xβ€– - x.re) / 2) := by rw [← ofReal_ofNat, ← ofReal_inv, cpow_ofReal_im, ← div_eq_mul_inv, ← one_div, ← Real.sqrt_eq_rpow, sin_half_eq_neg_sqrt, mul_neg, ← sqrt_mul (norm_nonneg _), ← mul_div_assoc, mul_sub, mul_one, norm_mul_cos_arg] Β· linarith [pi_pos, neg_pi_lt_arg x] Β· exact (arg_neg_iff.2 hx).le lemma abs_cpow_inv_two_im (x : β„‚) : |(x ^ (2⁻¹ : β„‚)).im| = √((β€–xβ€– - x.re) / 2) := by rw [← ofReal_ofNat, ← ofReal_inv, cpow_ofReal_im, ← div_eq_mul_inv, ← one_div, ← Real.sqrt_eq_rpow, abs_mul, abs_of_nonneg (sqrt_nonneg _), abs_sin_half, ← sqrt_mul (norm_nonneg _), ← mul_div_assoc, mul_sub, mul_one, norm_mul_cos_arg] open scoped ComplexOrder in lemma inv_natCast_cpow_ofReal_pos {n : β„•} (hn : n β‰  0) (x : ℝ) : 0 < ((n : β„‚) ^ (x : β„‚))⁻¹ := by refine RCLike.inv_pos_of_pos ?_ rw [show (n : β„‚) ^ (x : β„‚) = (n : ℝ) ^ (x : β„‚) from rfl, ← ofReal_cpow n.cast_nonneg'] positivity end Complex section Tactics /-! ## Tactic extensions for real powers -/ namespace Mathlib.Meta.NormNum open Lean.Meta Qq theorem IsNat.rpow_eq_pow {b : ℝ} {n : β„•} (h : IsNat b n) (a : ℝ) : a ^ b = a ^ n := by rw [h.1, Real.rpow_natCast] theorem IsInt.rpow_eq_inv_pow {b : ℝ} {n : β„•} (h : IsInt b (.negOfNat n)) (a : ℝ) : a ^ b = (a ^ n)⁻¹ := by rw [h.1, Real.rpow_intCast, Int.negOfNat_eq, zpow_neg, Int.ofNat_eq_coe, zpow_natCast] @[deprecated IsNat.rpow_eq_pow (since := "2025-10-21")] theorem isNat_rpow_pos {a b : ℝ} {nb ne : β„•} (pb : IsNat b nb) (pe' : IsNat (a ^ nb) ne) : IsNat (a ^ b) ne := by rwa [pb.out, rpow_natCast] @[deprecated IsInt.rpow_eq_inv_pow (since := "2025-10-21")] theorem isNat_rpow_neg {a b : ℝ} {nb ne : β„•} (pb : IsInt b (Int.negOfNat nb)) (pe' : IsNat (a ^ (Int.negOfNat nb)) ne) : IsNat (a ^ b) ne := by rwa [pb.out, Real.rpow_intCast] @[deprecated IsNat.rpow_eq_pow (since := "2025-10-21")] theorem isInt_rpow_pos {a b : ℝ} {nb ne : β„•} (pb : IsNat b nb) (pe' : IsInt (a ^ nb) (Int.negOfNat ne)) : IsInt (a ^ b) (Int.negOfNat ne) := by rwa [pb.out, rpow_natCast] @[deprecated IsInt.rpow_eq_inv_pow (since := "2025-10-21")] theorem isInt_rpow_neg {a b : ℝ} {nb ne : β„•} (pb : IsInt b (Int.negOfNat nb)) (pe' : IsInt (a ^ (Int.negOfNat nb)) (Int.negOfNat ne)) : IsInt (a ^ b) (Int.negOfNat ne) := by rwa [pb.out, Real.rpow_intCast] @[deprecated IsNat.rpow_eq_pow (since := "2025-10-21")] theorem isNNRat_rpow_pos {a b : ℝ} {nb : β„•} {num den : β„•} (pb : IsNat b nb) (pe' : IsNNRat (a ^ nb) num den) : IsNNRat (a ^ b) num den := by rwa [pb.out, rpow_natCast] @[deprecated IsNat.rpow_eq_pow (since := "2025-10-21")] theorem isRat_rpow_pos {a b : ℝ} {nb : β„•} {num : β„€} {den : β„•} (pb : IsNat b nb) (pe' : IsRat (a ^ nb) num den) : IsRat (a ^ b) num den := by rwa [pb.out, rpow_natCast] @[deprecated IsInt.rpow_eq_inv_pow (since := "2025-10-21")] theorem isNNRat_rpow_neg {a b : ℝ} {nb : β„•} {num den : β„•} (pb : IsInt b (Int.negOfNat nb)) (pe' : IsNNRat (a ^ (Int.negOfNat nb)) num den) : IsNNRat (a ^ b) num den := by rwa [pb.out, Real.rpow_intCast] @[deprecated IsInt.rpow_eq_inv_pow (since := "2025-10-21")] theorem isRat_rpow_neg {a b : ℝ} {nb : β„•} {num : β„€} {den : β„•} (pb : IsInt b (Int.negOfNat nb)) (pe' : IsRat (a ^ (Int.negOfNat nb)) num den) : IsRat (a ^ b) num den := by rwa [pb.out, Real.rpow_intCast] /-- Given proofs - that `a` is a natural number `m` - that `b` is a nonnegative rational number `n / d` - that `r ^ d = m ^ n` (written as `r ^ d = k`, `m ^ n = l`, `k = l`) prove that `a ^ b = r`. -/ theorem IsNat.rpow_isNNRat {a b : ℝ} {m n d r : β„•} (ha : IsNat a m) (hb : IsNNRat b n d) (k : β„•) (hr : r ^ d = k) (l : β„•) (hm : m ^ n = l) (hkl : k = l) : IsNat (a ^ b) r := by rcases ha with ⟨rfl⟩ constructor have : d β‰  0 := mod_cast hb.den_nz rw [hb.to_eq rfl rfl, div_eq_mul_inv, Real.rpow_natCast_mul, ← Nat.cast_pow, hm, ← hkl, ← hr, Nat.cast_pow, Real.pow_rpow_inv_natCast] <;> positivity theorem IsNNRat.rpow_isNNRat (a b : ℝ) (na da : β„•) (ha : IsNNRat a na da) (nr dr : β„•) (hnum : IsNat ((na : ℝ) ^ b) nr) (hden : IsNat ((da : ℝ) ^ b) dr) : IsNNRat (a ^ b) nr dr := by suffices IsNNRat (nr / dr : ℝ) nr dr by simpa [ha.to_eq, Real.div_rpow, hnum.1, hden.1] apply IsNNRat.of_raw rw [← hden.1] apply (Real.rpow_pos_of_pos _ _).ne' exact lt_of_le_of_ne' da.cast_nonneg ha.den_nz theorem rpow_isRat_eq_inv_rpow (a b : ℝ) (n d : β„•) (hb : IsRat b (Int.negOfNat n) d) : a ^ b = (a⁻¹) ^ (n / d : ℝ) := by rw [← Real.rpow_neg_eq_inv_rpow, hb.neg_to_eq rfl rfl] open Lean in /-- Given proofs - that `a` is a natural number `na`; - that `b` is a nonnegative rational number `nb / db`; returns a tuple of - a natural number `r` (result); - the same number, as an expression; - a proof that `a ^ b = r`. Fails if `na` is not a `db`th power of a natural number. -/ def proveIsNatRPowIsNNRat (a : Q(ℝ)) (na : Q(β„•)) (pa : Q(IsNat $a $na)) (b : Q(ℝ)) (nb db : Q(β„•)) (pb : Q(IsNNRat $b $nb $db)) : MetaM (β„• Γ— Ξ£ r : Q(β„•), Q(IsNat ($a ^ $b) $r)) := do let r := (Nat.nthRoot db.natLit! na.natLit!) ^ nb.natLit! have er : Q(β„•) := mkRawNatLit r -- avoid evaluating powers in kernel let .some ⟨c, pc⟩ ← liftM <| OptionT.run <| evalNatPow er db | failure let .some ⟨d, pd⟩ ← liftM <| OptionT.run <| evalNatPow na nb | failure guard (c.natLit! = d.natLit!) have hcd : Q($c = $d) := (q(Eq.refl $c) : Expr) return (r, ⟨er, q(IsNat.rpow_isNNRat $pa $pb $c $pc $d $pd $hcd)⟩) /-- Evaluates expressions of the form `a ^ b` when `a` and `b` are both reals. Works if `a`, `b`, and `a ^ b` are in fact rational numbers, except for the case `a < 0`, `b` isn't integer. TODO: simplify terms like `(-a : ℝ) ^ (b / 3 : ℝ)` and `(-a : ℝ) ^ (b / 2 : ℝ)` too, possibly after first considering changing the junk value. -/ @[norm_num (_ : ℝ) ^ (_ : ℝ)] def evalRPow : NormNumExt where eval {u Ξ±R} e := do match u, Ξ±R, e with | 0, ~q(ℝ), ~q(($a : ℝ)^($b : ℝ)) => match ← derive b with | .isNat sΞ² nb pb => assumeInstancesCommute return .eqTrans q(IsNat.rpow_eq_pow $pb _) (← derive q($a ^ $nb)) | .isNegNat sΞ² nb pb => assumeInstancesCommute return .eqTrans q(IsInt.rpow_eq_inv_pow $pb _) (← derive q(($a ^ $nb)⁻¹)) | .isNNRat _ qb nb db pb => do assumeInstancesCommute match ← derive a with | .isNat sa na pa => do let ⟨_, r, pr⟩ ← proveIsNatRPowIsNNRat a na pa b nb db pb return .isNat sa r pr | .isNNRat _ qΞ± na da pa => do assumeInstancesCommute let ⟨rnum, ernum, pnum⟩ ← proveIsNatRPowIsNNRat q(Nat.rawCast $na) na q(IsNat.of_raw _ _) b nb db pb let ⟨rden, erden, pden⟩ ← proveIsNatRPowIsNNRat q(Nat.rawCast $da) da q(IsNat.of_raw _ _) b nb db pb return .isNNRat q(inferInstance) (rnum / rden) ernum erden q(IsNNRat.rpow_isNNRat $a $b $na $da $pa $ernum $erden $pnum $pden) | _ => failure | .isNegNNRat _ qb nb db pb => do let r ← derive q(($a⁻¹) ^ ($nb / $db : ℝ)) assumeInstancesCommute return .eqTrans q(rpow_isRat_eq_inv_rpow $a $b $nb $db $pb) r | _ => failure | _ => failure end Mathlib.Meta.NormNum end Tactics
.lake/packages/mathlib/Mathlib/Analysis/SpecialFunctions/Gaussian/FourierTransform.lean
import Mathlib.Analysis.SpecialFunctions.Gaussian.GaussianIntegral import Mathlib.Analysis.Complex.CauchyIntegral import Mathlib.MeasureTheory.Integral.Pi import Mathlib.Analysis.Fourier.FourierTransform /-! # Fourier transform of the Gaussian We prove that the Fourier transform of the Gaussian function is another Gaussian: * `integral_cexp_quadratic`: general formula for `∫ (x : ℝ), exp (b * x ^ 2 + c * x + d)` * `fourierIntegral_gaussian`: for all complex `b` and `t` with `0 < re b`, we have `∫ x:ℝ, exp (I * t * x) * exp (-b * x^2) = (Ο€ / b) ^ (1 / 2) * exp (-t ^ 2 / (4 * b))`. * `fourierIntegral_gaussian_pi`: a variant with `b` and `t` scaled to give a more symmetric statement, and formulated in terms of the Fourier transform operator `𝓕`. We also give versions of these formulas in finite-dimensional inner product spaces, see `integral_cexp_neg_mul_sq_norm_add` and `fourierIntegral_gaussian_innerProductSpace`. -/ /-! ## Fourier integral of Gaussian functions -/ open Real Set MeasureTheory Filter Asymptotics intervalIntegral open scoped Real Topology FourierTransform RealInnerProductSpace open Complex hiding exp continuous_exp noncomputable section namespace GaussianFourier variable {b : β„‚} /-- The integral of the Gaussian function over the vertical edges of a rectangle with vertices at `(Β±T, 0)` and `(Β±T, c)`. -/ def verticalIntegral (b : β„‚) (c T : ℝ) : β„‚ := ∫ y : ℝ in (0 : ℝ)..c, I * (cexp (-b * (T + y * I) ^ 2) - cexp (-b * (T - y * I) ^ 2)) /-- Explicit formula for the norm of the Gaussian function along the vertical edges. -/ theorem norm_cexp_neg_mul_sq_add_mul_I (b : β„‚) (c T : ℝ) : β€–cexp (-b * (T + c * I) ^ 2)β€– = exp (-(b.re * T ^ 2 - 2 * b.im * c * T - b.re * c ^ 2)) := by rw [Complex.norm_exp, neg_mul, neg_re, ← re_add_im b] simp only [sq, re_add_im, mul_re, mul_im, add_re, add_im, ofReal_re, ofReal_im, I_re, I_im] ring_nf theorem norm_cexp_neg_mul_sq_add_mul_I' (hb : b.re β‰  0) (c T : ℝ) : β€–cexp (-b * (T + c * I) ^ 2)β€– = exp (-(b.re * (T - b.im * c / b.re) ^ 2 - c ^ 2 * (b.im ^ 2 / b.re + b.re))) := by have : b.re * T ^ 2 - 2 * b.im * c * T - b.re * c ^ 2 = b.re * (T - b.im * c / b.re) ^ 2 - c ^ 2 * (b.im ^ 2 / b.re + b.re) := by field rw [norm_cexp_neg_mul_sq_add_mul_I, this] theorem verticalIntegral_norm_le (hb : 0 < b.re) (c : ℝ) {T : ℝ} (hT : 0 ≀ T) : β€–verticalIntegral b c Tβ€– ≀ (2 : ℝ) * |c| * exp (-(b.re * T ^ 2 - (2 : ℝ) * |b.im| * |c| * T - b.re * c ^ 2)) := by -- first get uniform bound for integrand have vert_norm_bound : βˆ€ {T : ℝ}, 0 ≀ T β†’ βˆ€ {c y : ℝ}, |y| ≀ |c| β†’ β€–cexp (-b * (T + y * I) ^ 2)β€– ≀ exp (-(b.re * T ^ 2 - (2 : ℝ) * |b.im| * |c| * T - b.re * c ^ 2)) := by intro T hT c y hy rw [norm_cexp_neg_mul_sq_add_mul_I b] gcongr exp (-(_ - ?_ * _ - _ * ?_)) Β· (conv_lhs => rw [mul_assoc]); (conv_rhs => rw [mul_assoc]) gcongr _ * ?_ refine (le_abs_self _).trans ?_ rw [abs_mul] gcongr Β· rwa [sq_le_sq] -- now main proof apply (intervalIntegral.norm_integral_le_of_norm_le_const _).trans Β· rw [sub_zero] conv_lhs => simp only [mul_comm _ |c|] conv_rhs => conv => congr rw [mul_comm] rw [mul_assoc] Β· intro y hy have absy : |y| ≀ |c| := by rcases le_or_gt 0 c with (h | h) Β· rw [uIoc_of_le h] at hy rw [abs_of_nonneg h, abs_of_pos hy.1] exact hy.2 Β· rw [uIoc_of_ge h.le] at hy rw [abs_of_neg h, abs_of_nonpos hy.2, neg_le_neg_iff] exact hy.1.le rw [norm_mul, norm_I, one_mul, two_mul] refine (norm_sub_le _ _).trans (add_le_add (vert_norm_bound hT absy) ?_) rw [← abs_neg y] at absy simpa only [neg_mul, ofReal_neg] using vert_norm_bound hT absy theorem tendsto_verticalIntegral (hb : 0 < b.re) (c : ℝ) : Tendsto (verticalIntegral b c) atTop (𝓝 0) := by -- complete proof using squeeze theorem: rw [tendsto_zero_iff_norm_tendsto_zero] refine tendsto_of_tendsto_of_tendsto_of_le_of_le' tendsto_const_nhds ?_ (Eventually.of_forall fun _ => norm_nonneg _) ((eventually_ge_atTop (0 : ℝ)).mp (Eventually.of_forall fun T hT => verticalIntegral_norm_le hb c hT)) rw [(by ring : 0 = 2 * |c| * 0)] refine (tendsto_exp_atBot.comp (tendsto_neg_atTop_atBot.comp ?_)).const_mul _ apply tendsto_atTop_add_const_right simp_rw [sq, ← mul_assoc, ← sub_mul] refine Tendsto.atTop_mul_atTopβ‚€ (tendsto_atTop_add_const_right _ _ ?_) tendsto_id exact (tendsto_const_mul_atTop_of_pos hb).mpr tendsto_id theorem integrable_cexp_neg_mul_sq_add_real_mul_I (hb : 0 < b.re) (c : ℝ) : Integrable fun x : ℝ => cexp (-b * (x + c * I) ^ 2) := by refine ⟨(Complex.continuous_exp.comp (continuous_const.mul ((continuous_ofReal.add continuous_const).pow 2))).aestronglyMeasurable, ?_⟩ rw [← hasFiniteIntegral_norm_iff] simp_rw [norm_cexp_neg_mul_sq_add_mul_I' hb.ne', neg_sub _ (c ^ 2 * _), sub_eq_add_neg _ (b.re * _), Real.exp_add] suffices Integrable fun x : ℝ => exp (-(b.re * x ^ 2)) by exact (Integrable.comp_sub_right this (b.im * c / b.re)).hasFiniteIntegral.const_mul _ simp_rw [← neg_mul] apply integrable_exp_neg_mul_sq hb theorem integral_cexp_neg_mul_sq_add_real_mul_I (hb : 0 < b.re) (c : ℝ) : ∫ x : ℝ, cexp (-b * (x + c * I) ^ 2) = (Ο€ / b) ^ (1 / 2 : β„‚) := by refine tendsto_nhds_unique (intervalIntegral_tendsto_integral (integrable_cexp_neg_mul_sq_add_real_mul_I hb c) tendsto_neg_atTop_atBot tendsto_id) ?_ set I₁ := fun T => ∫ x : ℝ in -T..T, cexp (-b * (x + c * I) ^ 2) with HI₁ let Iβ‚‚ := fun T : ℝ => ∫ x : ℝ in -T..T, cexp (-b * (x : β„‚) ^ 2) let Iβ‚„ := fun T : ℝ => ∫ y : ℝ in (0 : ℝ)..c, cexp (-b * (T + y * I) ^ 2) let Iβ‚… := fun T : ℝ => ∫ y : ℝ in (0 : ℝ)..c, cexp (-b * (-T + y * I) ^ 2) have C : βˆ€ T : ℝ, Iβ‚‚ T - I₁ T + I * Iβ‚„ T - I * Iβ‚… T = 0 := by intro T have := integral_boundary_rect_eq_zero_of_differentiableOn (fun z => cexp (-b * z ^ 2)) (-T) (T + c * I) (by refine Differentiable.differentiableOn (Differentiable.const_mul ?_ _).cexp exact differentiable_pow 2) simpa only [neg_im, ofReal_im, neg_zero, ofReal_zero, zero_mul, add_zero, neg_re, ofReal_re, add_re, mul_re, I_re, mul_zero, I_im, tsub_zero, add_im, mul_im, mul_one, zero_add, Algebra.id.smul_eq_mul, ofReal_neg] using this simp_rw [id, ← HI₁] have : I₁ = fun T : ℝ => Iβ‚‚ T + verticalIntegral b c T := by ext1 T specialize C T rw [sub_eq_zero] at C unfold verticalIntegral rw [intervalIntegral.integral_const_mul, intervalIntegral.integral_sub] Β· simp_rw [(fun a b => by rw [sq]; ring_nf : βˆ€ a b : β„‚, (a - b * I) ^ 2 = (-a + b * I) ^ 2)] change I₁ T = Iβ‚‚ T + I * (Iβ‚„ T - Iβ‚… T) rw [mul_sub, ← C] abel all_goals apply Continuous.intervalIntegrable; continuity rw [this, ← add_zero ((Ο€ / b : β„‚) ^ (1 / 2 : β„‚)), ← integral_gaussian_complex hb] refine Tendsto.add ?_ (tendsto_verticalIntegral hb c) exact intervalIntegral_tendsto_integral (integrable_cexp_neg_mul_sq hb) tendsto_neg_atTop_atBot tendsto_id theorem _root_.integral_cexp_quadratic (hb : b.re < 0) (c d : β„‚) : ∫ x : ℝ, cexp (b * x ^ 2 + c * x + d) = (Ο€ / -b) ^ (1 / 2 : β„‚) * cexp (d - c ^ 2 / (4 * b)) := by have hb' : b β‰  0 := by contrapose! hb; rw [hb, zero_re] have h (x : ℝ) : cexp (b * x ^ 2 + c * x + d) = cexp (- -b * (x + c / (2 * b)) ^ 2) * cexp (d - c ^ 2 / (4 * b)) := by simp_rw [← Complex.exp_add] congr 1 field simp_rw [h, MeasureTheory.integral_mul_const] rw [← re_add_im (c / (2 * b))] simp_rw [← add_assoc, ← ofReal_add] rw [integral_add_right_eq_self fun a : ℝ ↦ cexp (- -b * (↑a + ↑(c / (2 * b)).im * I) ^ 2), integral_cexp_neg_mul_sq_add_real_mul_I ((neg_re b).symm β–Έ (neg_pos.mpr hb))] lemma _root_.integrable_cexp_quadratic' (hb : b.re < 0) (c d : β„‚) : Integrable (fun (x : ℝ) ↦ cexp (b * x ^ 2 + c * x + d)) := by have hb' : b β‰  0 := by contrapose! hb; rw [hb, zero_re] by_contra H simpa [hb', pi_ne_zero, Complex.exp_ne_zero, integral_undef H] using integral_cexp_quadratic hb c d lemma _root_.integrable_cexp_quadratic (hb : 0 < b.re) (c d : β„‚) : Integrable (fun (x : ℝ) ↦ cexp (-b * x ^ 2 + c * x + d)) := by have : (-b).re < 0 := by simpa using hb exact integrable_cexp_quadratic' this c d theorem _root_.fourierIntegral_gaussian (hb : 0 < b.re) (t : β„‚) : ∫ x : ℝ, cexp (I * t * x) * cexp (-b * x ^ 2) = (Ο€ / b) ^ (1 / 2 : β„‚) * cexp (-t ^ 2 / (4 * b)) := by conv => enter [1, 2, x]; rw [← Complex.exp_add, add_comm, ← add_zero (-b * x ^ 2 + I * t * x)] rw [integral_cexp_quadratic (show (-b).re < 0 by rwa [neg_re, neg_lt_zero]), neg_neg, zero_sub, mul_neg, div_neg, neg_neg, mul_pow, I_sq, neg_one_mul, mul_comm] theorem _root_.fourierIntegral_gaussian_pi' (hb : 0 < b.re) (c : β„‚) : (𝓕 fun x : ℝ => cexp (-Ο€ * b * x ^ 2 + 2 * Ο€ * c * x)) = fun t : ℝ => 1 / b ^ (1 / 2 : β„‚) * cexp (-Ο€ / b * (t + I * c) ^ 2) := by haveI : b β‰  0 := by contrapose! hb; rw [hb, zero_re] have h : (-↑π * b).re < 0 := by simpa only [neg_mul, neg_re, re_ofReal_mul, neg_lt_zero] using mul_pos pi_pos hb ext1 t simp_rw [fourierIntegral_real_eq_integral_exp_smul, smul_eq_mul, ← Complex.exp_add, ← add_assoc] have (x : ℝ) : ↑(-2 * Ο€ * x * t) * I + -Ο€ * b * x ^ 2 + 2 * Ο€ * c * x = -Ο€ * b * x ^ 2 + (-2 * Ο€ * I * t + 2 * Ο€ * c) * x + 0 := by push_cast; ring simp_rw [this, integral_cexp_quadratic h, neg_mul, neg_neg] congr 2 Β· rw [← div_div, div_self <| ofReal_ne_zero.mpr pi_ne_zero, one_div, inv_cpow, ← one_div] rw [Ne, arg_eq_pi_iff, not_and_or, not_lt] exact Or.inl hb.le Β· field_simp ring_nf simp only [I_sq] ring theorem _root_.fourierIntegral_gaussian_pi (hb : 0 < b.re) : (𝓕 fun (x : ℝ) ↦ cexp (-Ο€ * b * x ^ 2)) = fun t : ℝ ↦ 1 / b ^ (1 / 2 : β„‚) * cexp (-Ο€ / b * t ^ 2) := by simpa only [mul_zero, zero_mul, add_zero] using fourierIntegral_gaussian_pi' hb 0 section InnerProductSpace variable {V : Type*} [NormedAddCommGroup V] [InnerProductSpace ℝ V] [FiniteDimensional ℝ V] [MeasurableSpace V] [BorelSpace V] theorem integrable_cexp_neg_sum_mul_add {ΞΉ : Type*} [Fintype ΞΉ] {b : ΞΉ β†’ β„‚} (hb : βˆ€ i, 0 < (b i).re) (c : ΞΉ β†’ β„‚) : Integrable (fun (v : ΞΉ β†’ ℝ) ↦ cexp (-βˆ‘ i, b i * (v i : β„‚) ^ 2 + βˆ‘ i, c i * v i)) := by simp_rw [← Finset.sum_neg_distrib, ← Finset.sum_add_distrib, Complex.exp_sum, ← neg_mul] apply Integrable.fintype_prod (f := fun i (v : ℝ) ↦ cexp (-b i * v ^ 2 + c i * v)) (fun i ↦ ?_) convert integrable_cexp_quadratic (hb i) (c i) 0 using 3 with x simp only [add_zero] theorem integrable_cexp_neg_mul_sum_add {ΞΉ : Type*} [Fintype ΞΉ] (hb : 0 < b.re) (c : ΞΉ β†’ β„‚) : Integrable (fun (v : ΞΉ β†’ ℝ) ↦ cexp (-b * βˆ‘ i, (v i : β„‚) ^ 2 + βˆ‘ i, c i * v i)) := by simp_rw [neg_mul, Finset.mul_sum] exact integrable_cexp_neg_sum_mul_add (fun _ ↦ hb) c theorem integrable_cexp_neg_mul_sq_norm_add_of_euclideanSpace {ΞΉ : Type*} [Fintype ΞΉ] (hb : 0 < b.re) (c : β„‚) (w : EuclideanSpace ℝ ΞΉ) : Integrable (fun (v : EuclideanSpace ℝ ΞΉ) ↦ cexp (- b * β€–vβ€–^2 + c * βŸͺw, v⟫)) := by rw [← (PiLp.volume_preserving_toLp ΞΉ).integrable_comp_emb (MeasurableEquiv.toLp 2 _).measurableEmbedding] simp only [neg_mul, Function.comp_def] convert integrable_cexp_neg_mul_sum_add hb (fun i ↦ c * w i) using 3 with v simp only [EuclideanSpace.norm_eq, norm_eq_abs, sq_abs, PiLp.inner_apply, RCLike.inner_apply, conj_trivial, ofReal_sum, ofReal_mul, Finset.mul_sum, neg_mul, Finset.sum_neg_distrib, mul_assoc] norm_cast rw [sq_sqrt] Β· simp [Finset.mul_sum, mul_comm] Β· exact Finset.sum_nonneg (fun i _hi ↦ by positivity) /-- In a real inner product space, the complex exponential of minus the square of the norm plus a scalar product is integrable. Useful when discussing the Fourier transform of a Gaussian. -/ theorem integrable_cexp_neg_mul_sq_norm_add (hb : 0 < b.re) (c : β„‚) (w : V) : Integrable (fun (v : V) ↦ cexp (-b * β€–vβ€– ^ 2 + c * βŸͺw, v⟫)) := by let e := (stdOrthonormalBasis ℝ V).repr.symm rw [← e.measurePreserving.integrable_comp_emb e.toHomeomorph.measurableEmbedding] convert integrable_cexp_neg_mul_sq_norm_add_of_euclideanSpace hb c (e.symm w) with v simp only [neg_mul, Function.comp_apply, LinearIsometryEquiv.norm_map, LinearIsometryEquiv.symm_symm, LinearIsometryEquiv.inner_map_eq_flip] theorem integral_cexp_neg_sum_mul_add {ΞΉ : Type*} [Fintype ΞΉ] {b : ΞΉ β†’ β„‚} (hb : βˆ€ i, 0 < (b i).re) (c : ΞΉ β†’ β„‚) : ∫ v : ΞΉ β†’ ℝ, cexp (-βˆ‘ i, b i * (v i : β„‚) ^ 2 + βˆ‘ i, c i * v i) = ∏ i, (Ο€ / b i) ^ (1 / 2 : β„‚) * cexp (c i ^ 2 / (4 * b i)) := by simp_rw [← Finset.sum_neg_distrib, ← Finset.sum_add_distrib, Complex.exp_sum, ← neg_mul] rw [integral_fintype_prod_volume_eq_prod (f := fun i (v : ℝ) ↦ cexp (-b i * v ^ 2 + c i * v))] congr with i have : (-b i).re < 0 := by simpa using hb i convert integral_cexp_quadratic this (c i) 0 using 1 <;> simp [div_neg] theorem integral_cexp_neg_mul_sum_add {ΞΉ : Type*} [Fintype ΞΉ] (hb : 0 < b.re) (c : ΞΉ β†’ β„‚) : ∫ v : ΞΉ β†’ ℝ, cexp (-b * βˆ‘ i, (v i : β„‚) ^ 2 + βˆ‘ i, c i * v i) = (Ο€ / b) ^ (Fintype.card ΞΉ / 2 : β„‚) * cexp ((βˆ‘ i, c i ^ 2) / (4 * b)) := by simp_rw [neg_mul, Finset.mul_sum, integral_cexp_neg_sum_mul_add (fun _ ↦ hb) c, one_div, Finset.prod_mul_distrib, Finset.prod_const, ← cpow_nat_mul, ← Complex.exp_sum, Fintype.card, Finset.sum_div, div_eq_mul_inv] theorem integral_cexp_neg_mul_sq_norm_add_of_euclideanSpace {ΞΉ : Type*} [Fintype ΞΉ] (hb : 0 < b.re) (c : β„‚) (w : EuclideanSpace ℝ ΞΉ) : ∫ v : EuclideanSpace ℝ ΞΉ, cexp (- b * β€–vβ€–^2 + c * βŸͺw, v⟫) = (Ο€ / b) ^ (Fintype.card ΞΉ / 2 : β„‚) * cexp (c ^ 2 * β€–wβ€–^2 / (4 * b)) := by rw [← (PiLp.volume_preserving_toLp ΞΉ).integral_comp (MeasurableEquiv.toLp 2 _).measurableEmbedding] simp only [neg_mul] convert integral_cexp_neg_mul_sum_add hb (fun i ↦ c * w i) using 5 with _x y Β· simp only [EuclideanSpace.norm_eq, norm_eq_abs, sq_abs, neg_mul, neg_inj, mul_eq_mul_left_iff] norm_cast left rw [sq_sqrt] exact Finset.sum_nonneg (fun i _hi ↦ by positivity) Β· simp [PiLp.inner_apply, Finset.mul_sum, mul_assoc] simp_rw [mul_comm] Β· simp only [EuclideanSpace.norm_eq, Real.norm_eq_abs, sq_abs, mul_pow, ← Finset.mul_sum] congr norm_cast rw [sq_sqrt] exact Finset.sum_nonneg (fun i _hi ↦ by positivity) theorem integral_cexp_neg_mul_sq_norm_add (hb : 0 < b.re) (c : β„‚) (w : V) : ∫ v : V, cexp (-b * β€–vβ€– ^ 2 + c * βŸͺw, v⟫) = (Ο€ / b) ^ (Module.finrank ℝ V / 2 : β„‚) * cexp (c ^ 2 * β€–wβ€– ^ 2 / (4 * b)) := by let e := (stdOrthonormalBasis ℝ V).repr.symm rw [← e.measurePreserving.integral_comp e.toHomeomorph.measurableEmbedding] convert integral_cexp_neg_mul_sq_norm_add_of_euclideanSpace hb c (e.symm w) <;> simp [LinearIsometryEquiv.inner_map_eq_flip] theorem integral_cexp_neg_mul_sq_norm (hb : 0 < b.re) : ∫ v : V, cexp (-b * β€–vβ€– ^ 2) = (Ο€ / b) ^ (Module.finrank ℝ V / 2 : β„‚) := by simpa using integral_cexp_neg_mul_sq_norm_add hb 0 (0 : V) theorem integral_rexp_neg_mul_sq_norm {b : ℝ} (hb : 0 < b) : ∫ v : V, rexp (-b * β€–vβ€– ^ 2) = (Ο€ / b) ^ (Module.finrank ℝ V / 2 : ℝ) := by rw [← ofReal_inj] convert integral_cexp_neg_mul_sq_norm (show 0 < (b : β„‚).re from hb) (V := V) Β· change ofRealLI (∫ (v : V), rexp (-b * β€–vβ€– ^ 2)) = ∫ (v : V), cexp (-↑b * ↑‖vβ€– ^ 2) rw [← ofRealLI.integral_comp_comm] simp [ofRealLI] Β· rw [← ofReal_div, ofReal_cpow (by positivity)] simp theorem _root_.fourierIntegral_gaussian_innerProductSpace' (hb : 0 < b.re) (x w : V) : 𝓕 (fun v ↦ cexp (-b * β€–vβ€– ^ 2 + 2 * Ο€ * Complex.I * βŸͺx, v⟫)) w = (Ο€ / b) ^ (Module.finrank ℝ V / 2 : β„‚) * cexp (-Ο€ ^ 2 * β€–x - wβ€– ^ 2 / b) := by simp only [neg_mul, fourierIntegral_eq', ofReal_neg, ofReal_mul, ofReal_ofNat, smul_eq_mul, ← Complex.exp_add, real_inner_comm w] convert integral_cexp_neg_mul_sq_norm_add hb (2 * Ο€ * Complex.I) (x - w) using 3 with v Β· congr 1 simp [inner_sub_left] ring Β· have : b β‰  0 := by contrapose! hb; rw [hb, zero_re] simp [mul_pow] ring theorem _root_.fourierIntegral_gaussian_innerProductSpace (hb : 0 < b.re) (w : V) : 𝓕 (fun (v : V) ↦ cexp (-b * β€–vβ€– ^ 2)) w = (Ο€ / b) ^ (Module.finrank ℝ V / 2 : β„‚) * cexp (-Ο€ ^ 2 * β€–wβ€– ^ 2 / b) := by simpa using fourierIntegral_gaussian_innerProductSpace' hb 0 w end InnerProductSpace end GaussianFourier
.lake/packages/mathlib/Mathlib/Analysis/SpecialFunctions/Gaussian/PoissonSummation.lean
import Mathlib.Analysis.SpecialFunctions.Gaussian.FourierTransform import Mathlib.Analysis.Fourier.PoissonSummation /-! # Poisson summation applied to the Gaussian In `Real.tsum_exp_neg_mul_int_sq` and `Complex.tsum_exp_neg_mul_int_sq`, we use Poisson summation to prove the identity `βˆ‘' (n : β„€), exp (-Ο€ * a * n ^ 2) = 1 / a ^ (1 / 2) * βˆ‘' (n : β„€), exp (-Ο€ / a * n ^ 2)` for positive real `a`, or complex `a` with positive real part. (See also `NumberTheory.ModularForms.JacobiTheta`.) -/ open Real Set MeasureTheory Filter Asymptotics intervalIntegral open scoped Real Topology FourierTransform RealInnerProductSpace open Complex hiding exp continuous_exp noncomputable section section GaussianPoisson /-! First we show that Gaussian-type functions have rapid decay along `cocompact ℝ`. -/ lemma rexp_neg_quadratic_isLittleO_rpow_atTop {a : ℝ} (ha : a < 0) (b s : ℝ) : (fun x ↦ rexp (a * x ^ 2 + b * x)) =o[atTop] (Β· ^ s) := by suffices (fun x ↦ rexp (a * x ^ 2 + b * x)) =o[atTop] (fun x ↦ rexp (-x)) by refine this.trans ?_ simpa only [neg_one_mul] using isLittleO_exp_neg_mul_rpow_atTop zero_lt_one s rw [isLittleO_exp_comp_exp_comp] have : (fun x ↦ -x - (a * x ^ 2 + b * x)) = fun x ↦ x * (-a * x - (b + 1)) := by ext1 x; ring_nf rw [this] exact tendsto_id.atTop_mul_atTopβ‚€ <| tendsto_atTop_add_const_right _ _ <| tendsto_id.const_mul_atTop (neg_pos.mpr ha) lemma cexp_neg_quadratic_isLittleO_rpow_atTop {a : β„‚} (ha : a.re < 0) (b : β„‚) (s : ℝ) : (fun x : ℝ ↦ cexp (a * x ^ 2 + b * x)) =o[atTop] (Β· ^ s) := by apply Asymptotics.IsLittleO.of_norm_left convert rexp_neg_quadratic_isLittleO_rpow_atTop ha b.re s with x simp_rw [Complex.norm_exp, add_re, ← ofReal_pow, mul_comm (_ : β„‚) ↑(_ : ℝ), re_ofReal_mul, mul_comm _ (re _)] lemma cexp_neg_quadratic_isLittleO_abs_rpow_cocompact {a : β„‚} (ha : a.re < 0) (b : β„‚) (s : ℝ) : (fun x : ℝ ↦ cexp (a * x ^ 2 + b * x)) =o[cocompact ℝ] (|Β·| ^ s) := by rw [cocompact_eq_atBot_atTop, isLittleO_sup] constructor Β· refine ((cexp_neg_quadratic_isLittleO_rpow_atTop ha (-b) s).comp_tendsto Filter.tendsto_neg_atBot_atTop).congr' (Eventually.of_forall fun x ↦ ?_) ?_ Β· simp only [neg_mul, Function.comp_apply, ofReal_neg, neg_sq, mul_neg, neg_neg] Β· refine (eventually_lt_atBot 0).mp (Eventually.of_forall fun x hx ↦ ?_) simp only [Function.comp_apply, abs_of_neg hx] Β· refine (cexp_neg_quadratic_isLittleO_rpow_atTop ha b s).congr' EventuallyEq.rfl ?_ refine (eventually_gt_atTop 0).mp (Eventually.of_forall fun x hx ↦ ?_) simp_rw [abs_of_pos hx] theorem tendsto_rpow_abs_mul_exp_neg_mul_sq_cocompact {a : ℝ} (ha : 0 < a) (s : ℝ) : Tendsto (fun x : ℝ => |x| ^ s * rexp (-a * x ^ 2)) (cocompact ℝ) (𝓝 0) := by conv in rexp _ => rw [← sq_abs] rw [cocompact_eq_atBot_atTop, ← comap_abs_atTop] erw [tendsto_comap'_iff (m := fun y => y ^ s * rexp (-a * y ^ 2)) (mem_atTop_sets.mpr ⟨0, fun b hb => ⟨b, abs_of_nonneg hb⟩⟩)] exact (rpow_mul_exp_neg_mul_sq_isLittleO_exp_neg ha s).tendsto_zero_of_tendsto (tendsto_exp_atBot.comp <| tendsto_id.const_mul_atTop_of_neg (neg_lt_zero.mpr one_half_pos)) theorem isLittleO_exp_neg_mul_sq_cocompact {a : β„‚} (ha : 0 < a.re) (s : ℝ) : (fun x : ℝ => Complex.exp (-a * x ^ 2)) =o[cocompact ℝ] fun x : ℝ => |x| ^ s := by convert cexp_neg_quadratic_isLittleO_abs_rpow_cocompact (?_ : (-a).re < 0) 0 s using 1 Β· simp_rw [zero_mul, add_zero] Β· rwa [neg_re, neg_lt_zero] /-- Jacobi's theta-function transformation formula for the sum of `exp -Q(x)`, where `Q` is a negative definite quadratic form. -/ theorem Complex.tsum_exp_neg_quadratic {a : β„‚} (ha : 0 < a.re) (b : β„‚) : (βˆ‘' n : β„€, cexp (-Ο€ * a * n ^ 2 + 2 * Ο€ * b * n)) = 1 / a ^ (1 / 2 : β„‚) * βˆ‘' n : β„€, cexp (-Ο€ / a * (n + I * b) ^ 2) := by let f : ℝ β†’ β„‚ := fun x ↦ cexp (-Ο€ * a * x ^ 2 + 2 * Ο€ * b * x) have hCf : Continuous f := by refine Complex.continuous_exp.comp (Continuous.add ?_ ?_) Β· exact continuous_const.mul (Complex.continuous_ofReal.pow 2) Β· exact continuous_const.mul Complex.continuous_ofReal have hFf : 𝓕 f = fun x : ℝ ↦ 1 / a ^ (1 / 2 : β„‚) * cexp (-Ο€ / a * (x + I * b) ^ 2) := fourierIntegral_gaussian_pi' ha b have h1 : 0 < (↑π * a).re := by rw [re_ofReal_mul] exact mul_pos pi_pos ha have h2 : 0 < (↑π / a).re := by rw [div_eq_mul_inv, re_ofReal_mul, inv_re] refine mul_pos pi_pos (div_pos ha <| normSq_pos.mpr ?_) contrapose! ha rw [ha, zero_re] have f_bd : f =O[cocompact ℝ] (fun x => |x| ^ (-2 : ℝ)) := by convert (cexp_neg_quadratic_isLittleO_abs_rpow_cocompact ?_ _ (-2)).isBigO rwa [neg_mul, neg_re, neg_lt_zero] have Ff_bd : (𝓕 f) =O[cocompact ℝ] (fun x => |x| ^ (-2 : ℝ)) := by rw [hFf] have : βˆ€ (x : ℝ), -↑π / a * (↑x + I * b) ^ 2 = -↑π / a * x ^ 2 + (-2 * Ο€ * I * b) / a * x + Ο€ * b ^ 2 / a := by intro x; ring_nf; rw [I_sq]; ring simp_rw [this] conv => enter [2, x]; rw [Complex.exp_add, ← mul_assoc _ _ (Complex.exp _), mul_comm] refine ((cexp_neg_quadratic_isLittleO_abs_rpow_cocompact (?_) (-2 * ↑π * I * b / a) (-2)).isBigO.const_mul_left _).const_mul_left _ rwa [neg_div, neg_re, neg_lt_zero] convert Real.tsum_eq_tsum_fourierIntegral_of_rpow_decay hCf one_lt_two f_bd Ff_bd 0 using 1 Β· simp only [f, zero_add, ofReal_intCast] Β· rw [← tsum_mul_left] simp only [QuotientAddGroup.mk_zero, fourier_eval_zero, mul_one, hFf, ofReal_intCast] theorem Complex.tsum_exp_neg_mul_int_sq {a : β„‚} (ha : 0 < a.re) : (βˆ‘' n : β„€, cexp (-Ο€ * a * (n : β„‚) ^ 2)) = 1 / a ^ (1 / 2 : β„‚) * βˆ‘' n : β„€, cexp (-Ο€ / a * (n : β„‚) ^ 2) := by simpa only [mul_zero, zero_mul, add_zero] using Complex.tsum_exp_neg_quadratic ha 0 theorem Real.tsum_exp_neg_mul_int_sq {a : ℝ} (ha : 0 < a) : (βˆ‘' n : β„€, exp (-Ο€ * a * (n : ℝ) ^ 2)) = (1 : ℝ) / a ^ (1 / 2 : ℝ) * (βˆ‘' n : β„€, exp (-Ο€ / a * (n : ℝ) ^ 2)) := by simpa only [← ofReal_inj, ofReal_tsum, ofReal_exp, ofReal_mul, ofReal_neg, ofReal_pow, ofReal_intCast, ofReal_div, ofReal_one, ofReal_cpow ha.le, ofReal_ofNat, mul_zero, zero_mul, add_zero] using Complex.tsum_exp_neg_quadratic (by rwa [ofReal_re] : 0 < (a : β„‚).re) 0 end GaussianPoisson
.lake/packages/mathlib/Mathlib/Analysis/SpecialFunctions/Gaussian/GaussianIntegral.lean
import Mathlib.Analysis.SpecialFunctions.Gamma.Basic import Mathlib.Analysis.SpecialFunctions.PolarCoord import Mathlib.Analysis.Complex.Convex import Mathlib.Data.Nat.Factorial.DoubleFactorial /-! # Gaussian integral We prove various versions of the formula for the Gaussian integral: * `integral_gaussian`: for real `b` we have `∫ x:ℝ, exp (-b * x^2) = √(Ο€ / b)`. * `integral_gaussian_complex`: for complex `b` with `0 < re b` we have `∫ x:ℝ, exp (-b * x^2) = (Ο€ / b) ^ (1 / 2)`. * `integral_gaussian_Ioi` and `integral_gaussian_complex_Ioi`: variants for integrals over `Ioi 0`. * `Complex.Gamma_one_half_eq`: the formula `Ξ“ (1 / 2) = βˆšΟ€`. -/ noncomputable section open Real Set MeasureTheory Filter Asymptotics open scoped Real Topology open Complex hiding exp theorem exp_neg_mul_rpow_isLittleO_exp_neg {p b : ℝ} (hb : 0 < b) (hp : 1 < p) : (fun x : ℝ => exp (- b * x ^ p)) =o[atTop] fun x : ℝ => exp (-x) := by rw [isLittleO_exp_comp_exp_comp] suffices Tendsto (fun x => x * (b * x ^ (p - 1) + -1)) atTop atTop by refine Tendsto.congr' ?_ this refine eventuallyEq_of_mem (Ioi_mem_atTop (0 : ℝ)) (fun x hx => ?_) rw [mem_Ioi] at hx rw [rpow_sub_one hx.ne'] field apply tendsto_id.atTop_mul_atTopβ‚€ refine tendsto_atTop_add_const_right atTop (-1 : ℝ) ?_ exact Tendsto.const_mul_atTop hb (tendsto_rpow_atTop (by linarith)) theorem exp_neg_mul_sq_isLittleO_exp_neg {b : ℝ} (hb : 0 < b) : (fun x : ℝ => exp (-b * x ^ 2)) =o[atTop] fun x : ℝ => exp (-x) := by simp_rw [← rpow_two] exact exp_neg_mul_rpow_isLittleO_exp_neg hb one_lt_two theorem rpow_mul_exp_neg_mul_rpow_isLittleO_exp_neg (s : ℝ) {b p : ℝ} (hp : 1 < p) (hb : 0 < b) : (fun x : ℝ => x ^ s * exp (- b * x ^ p)) =o[atTop] fun x : ℝ => exp (-(1 / 2) * x) := by apply ((isBigO_refl (fun x : ℝ => x ^ s) atTop).mul_isLittleO (exp_neg_mul_rpow_isLittleO_exp_neg hb hp)).trans simpa only [mul_comm] using Real.Gamma_integrand_isLittleO s theorem rpow_mul_exp_neg_mul_sq_isLittleO_exp_neg {b : ℝ} (hb : 0 < b) (s : ℝ) : (fun x : ℝ => x ^ s * exp (-b * x ^ 2)) =o[atTop] fun x : ℝ => exp (-(1 / 2) * x) := by simp_rw [← rpow_two] exact rpow_mul_exp_neg_mul_rpow_isLittleO_exp_neg s one_lt_two hb theorem integrableOn_rpow_mul_exp_neg_rpow {p s : ℝ} (hs : -1 < s) (hp : 1 ≀ p) : IntegrableOn (fun x : ℝ => x ^ s * exp (- x ^ p)) (Ioi 0) := by obtain hp | hp := le_iff_lt_or_eq.mp hp Β· have h_exp : βˆ€ x, ContinuousAt (fun x => exp (- x)) x := fun x => continuousAt_neg.rexp rw [← Ioc_union_Ioi_eq_Ioi zero_le_one, integrableOn_union] constructor Β· rw [← integrableOn_Icc_iff_integrableOn_Ioc] refine IntegrableOn.mul_continuousOn ?_ ?_ isCompact_Icc Β· refine (intervalIntegrable_iff_integrableOn_Icc_of_le zero_le_one).mp ?_ exact intervalIntegral.intervalIntegrable_rpow' hs Β· intro x _ change ContinuousWithinAt ((fun x => exp (- x)) ∘ (fun x => x ^ p)) (Icc 0 1) x refine ContinuousAt.comp_continuousWithinAt (h_exp _) ?_ exact continuousWithinAt_id.rpow_const (Or.inr (le_of_lt (lt_trans zero_lt_one hp))) Β· have h_rpow : βˆ€ (x r : ℝ), x ∈ Ici 1 β†’ ContinuousWithinAt (fun x => x ^ r) (Ici 1) x := by intro _ _ hx refine continuousWithinAt_id.rpow_const (Or.inl ?_) exact ne_of_gt (lt_of_lt_of_le zero_lt_one hx) refine integrable_of_isBigO_exp_neg (by simp : (0 : ℝ) < 1 / 2) (ContinuousOn.mul (fun x hx => h_rpow x s hx) (fun x hx => ?_)) (IsLittleO.isBigO ?_) Β· change ContinuousWithinAt ((fun x => exp (- x)) ∘ (fun x => x ^ p)) (Ici 1) x exact ContinuousAt.comp_continuousWithinAt (h_exp _) (h_rpow x p hx) Β· convert rpow_mul_exp_neg_mul_rpow_isLittleO_exp_neg s hp (by simp : (0 : ℝ) < 1) using 3 rw [neg_mul, one_mul] Β· simp_rw [← hp, Real.rpow_one] convert Real.GammaIntegral_convergent (by linarith : 0 < s + 1) using 2 rw [add_sub_cancel_right, mul_comm] theorem integrableOn_rpow_mul_exp_neg_mul_rpow {p s b : ℝ} (hs : -1 < s) (hp : 1 ≀ p) (hb : 0 < b) : IntegrableOn (fun x : ℝ => x ^ s * exp (- b * x ^ p)) (Ioi 0) := by have hib : 0 < b ^ (-p⁻¹) := rpow_pos_of_pos hb _ suffices IntegrableOn (fun x ↦ (b ^ (-p⁻¹)) ^ s * (x ^ s * exp (-x ^ p))) (Ioi 0) by rw [show 0 = b ^ (-p⁻¹) * 0 by rw [mul_zero], ← integrableOn_Ioi_comp_mul_left_iff _ _ hib] refine this.congr_fun (fun _ hx => ?_) measurableSet_Ioi rw [← mul_assoc, mul_rpow, mul_rpow, ← rpow_mul (z := p), neg_mul, neg_mul, inv_mul_cancelβ‚€, rpow_neg_one, mul_inv_cancel_leftβ‚€] all_goals linarith [mem_Ioi.mp hx] refine Integrable.const_mul ?_ _ rw [← IntegrableOn] exact integrableOn_rpow_mul_exp_neg_rpow hs hp theorem integrableOn_rpow_mul_exp_neg_mul_sq {b : ℝ} (hb : 0 < b) {s : ℝ} (hs : -1 < s) : IntegrableOn (fun x : ℝ => x ^ s * exp (-b * x ^ 2)) (Ioi 0) := by simp_rw [← rpow_two] exact integrableOn_rpow_mul_exp_neg_mul_rpow hs one_le_two hb theorem integrable_rpow_mul_exp_neg_mul_sq {b : ℝ} (hb : 0 < b) {s : ℝ} (hs : -1 < s) : Integrable fun x : ℝ => x ^ s * exp (-b * x ^ 2) := by rw [← integrableOn_univ, ← @Iio_union_Ici _ _ (0 : ℝ), integrableOn_union, integrableOn_Ici_iff_integrableOn_Ioi] refine ⟨?_, integrableOn_rpow_mul_exp_neg_mul_sq hb hs⟩ rw [← (Measure.measurePreserving_neg (volume : Measure ℝ)).integrableOn_comp_preimage (Homeomorph.neg ℝ).measurableEmbedding] simp only [Function.comp_def, neg_sq, neg_preimage, neg_Iio, neg_zero] apply Integrable.mono' (integrableOn_rpow_mul_exp_neg_mul_sq hb hs) Β· apply Measurable.aestronglyMeasurable exact (measurable_id'.neg.pow measurable_const).mul ((measurable_id'.pow measurable_const).const_mul (-b)).exp Β· have : MeasurableSet (Ioi (0 : ℝ)) := measurableSet_Ioi filter_upwards [ae_restrict_mem this] with x hx have h'x : 0 ≀ x := le_of_lt hx rw [Real.norm_eq_abs, abs_mul, abs_of_nonneg (exp_pos _).le] apply mul_le_mul_of_nonneg_right _ (exp_pos _).le simpa [abs_of_nonneg h'x] using abs_rpow_le_abs_rpow (-x) s theorem integrable_exp_neg_mul_sq {b : ℝ} (hb : 0 < b) : Integrable fun x : ℝ => exp (-b * x ^ 2) := by simpa using integrable_rpow_mul_exp_neg_mul_sq hb (by simp : (-1 : ℝ) < 0) theorem integrableOn_Ioi_exp_neg_mul_sq_iff {b : ℝ} : IntegrableOn (fun x : ℝ => exp (-b * x ^ 2)) (Ioi 0) ↔ 0 < b := by refine ⟨fun h => ?_, fun h => (integrable_exp_neg_mul_sq h).integrableOn⟩ by_contra! hb have : ∫⁻ _ : ℝ in Ioi 0, 1 ≀ ∫⁻ x : ℝ in Ioi 0, β€–exp (-b * x ^ 2)β€–β‚Š := by apply lintegral_mono (fun x ↦ _) simp only [neg_mul, ENNReal.one_le_coe_iff, ← toNNReal_one, toNNReal_le_iff_le_coe, Real.norm_of_nonneg (exp_pos _).le, coe_nnnorm, one_le_exp_iff, Right.nonneg_neg_iff] exact fun x ↦ mul_nonpos_of_nonpos_of_nonneg hb (sq_nonneg x) simpa using this.trans_lt h.2 theorem integrable_exp_neg_mul_sq_iff {b : ℝ} : (Integrable fun x : ℝ => exp (-b * x ^ 2)) ↔ 0 < b := ⟨fun h => integrableOn_Ioi_exp_neg_mul_sq_iff.mp h.integrableOn, integrable_exp_neg_mul_sq⟩ theorem integrable_mul_exp_neg_mul_sq {b : ℝ} (hb : 0 < b) : Integrable fun x : ℝ => x * exp (-b * x ^ 2) := by simpa using integrable_rpow_mul_exp_neg_mul_sq hb (by simp : (-1 : ℝ) < 1) theorem norm_cexp_neg_mul_sq (b : β„‚) (x : ℝ) : β€–Complex.exp (-b * (x : β„‚) ^ 2)β€– = exp (-b.re * x ^ 2) := by rw [norm_exp, ← ofReal_pow, mul_comm (-b) _, re_ofReal_mul, neg_re, mul_comm] theorem integrable_cexp_neg_mul_sq {b : β„‚} (hb : 0 < b.re) : Integrable fun x : ℝ => cexp (-b * (x : β„‚) ^ 2) := by refine ⟨(Complex.continuous_exp.comp (continuous_const.mul (continuous_ofReal.pow 2))).aestronglyMeasurable, ?_⟩ rw [← hasFiniteIntegral_norm_iff] simp_rw [norm_cexp_neg_mul_sq] exact (integrable_exp_neg_mul_sq hb).2 theorem integrable_mul_cexp_neg_mul_sq {b : β„‚} (hb : 0 < b.re) : Integrable fun x : ℝ => ↑x * cexp (-b * (x : β„‚) ^ 2) := by refine ⟨(continuous_ofReal.mul (Complex.continuous_exp.comp ?_)).aestronglyMeasurable, ?_⟩ Β· exact continuous_const.mul (continuous_ofReal.pow 2) have := (integrable_mul_exp_neg_mul_sq hb).hasFiniteIntegral rw [← hasFiniteIntegral_norm_iff] at this ⊒ convert this rw [norm_mul, norm_mul, norm_cexp_neg_mul_sq b, norm_real, norm_of_nonneg (exp_pos _).le] theorem integral_mul_cexp_neg_mul_sq {b : β„‚} (hb : 0 < b.re) : ∫ r : ℝ in Ioi 0, (r : β„‚) * cexp (-b * (r : β„‚) ^ 2) = (2 * b)⁻¹ := by have hb' : b β‰  0 := by contrapose! hb; rw [hb, zero_re] have A : βˆ€ x : β„‚, HasDerivAt (fun x => -(2 * b)⁻¹ * cexp (-b * x ^ 2)) (x * cexp (-b * x ^ 2)) x := by intro x convert ((hasDerivAt_pow 2 x).const_mul (-b)).cexp.const_mul (-(2 * b)⁻¹) using 1 field have B : Tendsto (fun y : ℝ ↦ -(2 * b)⁻¹ * cexp (-b * (y : β„‚) ^ 2)) atTop (𝓝 (-(2 * b)⁻¹ * 0)) := by refine Tendsto.const_mul _ (tendsto_zero_iff_norm_tendsto_zero.mpr ?_) simp_rw [norm_cexp_neg_mul_sq b] exact tendsto_exp_atBot.comp ((tendsto_pow_atTop two_ne_zero).const_mul_atTop_of_neg (neg_lt_zero.2 hb)) convert integral_Ioi_of_hasDerivAt_of_tendsto' (fun x _ => (A ↑x).comp_ofReal) (integrable_mul_cexp_neg_mul_sq hb).integrableOn B using 1 simp only [mul_zero, ofReal_zero, zero_pow, Ne, not_false_iff, Complex.exp_zero, mul_one, sub_neg_eq_add, zero_add, reduceCtorEq] /-- The *square* of the Gaussian integral `∫ x:ℝ, exp (-b * x^2)` is equal to `Ο€ / b`. -/ theorem integral_gaussian_sq_complex {b : β„‚} (hb : 0 < b.re) : (∫ x : ℝ, cexp (-b * (x : β„‚) ^ 2)) ^ 2 = Ο€ / b := by /- We compute `(∫ exp (-b x^2))^2` as an integral over `ℝ^2`, and then make a polar change of coordinates. We are left with `∫ r * exp (-b r^2)`, which has been computed in `integral_mul_cexp_neg_mul_sq` using the fact that this function has an obvious primitive. -/ calc (∫ x : ℝ, cexp (-b * (x : β„‚) ^ 2)) ^ 2 = ∫ p : ℝ Γ— ℝ, cexp (-b * (p.1 : β„‚) ^ 2) * cexp (-b * (p.2 : β„‚) ^ 2) := by rw [pow_two, ← integral_prod_mul]; rfl _ = ∫ p : ℝ Γ— ℝ, cexp (-b * ((p.1 : β„‚)^ 2 + (p.2 : β„‚) ^ 2)) := by congr ext1 p rw [← Complex.exp_add, mul_add] _ = ∫ p in polarCoord.target, p.1 β€’ cexp (-b * ((p.1 * Complex.cos p.2) ^ 2 + (p.1 * Complex.sin p.2) ^ 2)) := by rw [← integral_comp_polarCoord_symm] simp only [polarCoord_symm_apply, ofReal_mul, ofReal_cos, ofReal_sin] _ = (∫ r in Ioi (0 : ℝ), r * cexp (-b * (r : β„‚) ^ 2)) * ∫ ΞΈ in Ioo (-Ο€) Ο€, 1 := by rw [← setIntegral_prod_mul] congr with p : 1 rw [mul_one] congr conv_rhs => rw [← one_mul ((p.1 : β„‚) ^ 2), ← sin_sq_add_cos_sq (p.2 : β„‚)] ring _ = ↑π / b := by simp only [integral_const, MeasurableSet.univ, measureReal_restrict_apply, univ_inter, real_smul, mul_one, integral_mul_cexp_neg_mul_sq hb] rw [volume_real_Ioo_of_le (by linarith [pi_nonneg])] simp ring theorem integral_gaussian (b : ℝ) : ∫ x : ℝ, exp (-b * x ^ 2) = √(Ο€ / b) := by -- First we deal with the crazy case where `b ≀ 0`: then both sides vanish. rcases le_or_gt b 0 with (hb | hb) Β· rw [integral_undef, sqrt_eq_zero_of_nonpos] Β· exact div_nonpos_of_nonneg_of_nonpos pi_pos.le hb Β· simpa only [not_lt, integrable_exp_neg_mul_sq_iff] using hb -- Assume now `b > 0`. Then both sides are non-negative and their squares agree. refine (sq_eq_sqβ‚€ (by positivity) (by positivity)).1 ?_ rw [← ofReal_inj, ofReal_pow, ← coe_algebraMap, RCLike.algebraMap_eq_ofReal, ← integral_ofReal, sq_sqrt (div_pos pi_pos hb).le, ← RCLike.algebraMap_eq_ofReal, coe_algebraMap, ofReal_div] convert integral_gaussian_sq_complex (by rwa [ofReal_re] : 0 < (b : β„‚).re) with _ x rw [ofReal_exp, ofReal_mul, ofReal_pow, ofReal_neg] theorem continuousAt_gaussian_integral (b : β„‚) (hb : 0 < re b) : ContinuousAt (fun c : β„‚ => ∫ x : ℝ, cexp (-c * (x : β„‚) ^ 2)) b := by let f : β„‚ β†’ ℝ β†’ β„‚ := fun (c : β„‚) (x : ℝ) => cexp (-c * (x : β„‚) ^ 2) obtain ⟨d, hd, hd'⟩ := exists_between hb have f_meas : βˆ€ c : β„‚, AEStronglyMeasurable (f c) volume := fun c => by apply Continuous.aestronglyMeasurable exact Complex.continuous_exp.comp (continuous_const.mul (continuous_ofReal.pow 2)) have f_cts : βˆ€ x : ℝ, ContinuousAt (fun c => f c x) b := fun x => (Complex.continuous_exp.comp (continuous_id'.neg.mul continuous_const)).continuousAt have f_le_bd : βˆ€αΆ  c : β„‚ in 𝓝 b, βˆ€α΅ x : ℝ, β€–f c xβ€– ≀ exp (-d * x ^ 2) := by refine eventually_of_mem ((continuous_re.isOpen_preimage _ isOpen_Ioi).mem_nhds hd') ?_ intro c hc; filter_upwards with x rw [norm_cexp_neg_mul_sq] gcongr exact le_of_lt hc exact continuousAt_of_dominated (Eventually.of_forall f_meas) f_le_bd (integrable_exp_neg_mul_sq hd) (ae_of_all _ f_cts) theorem integral_gaussian_complex {b : β„‚} (hb : 0 < re b) : ∫ x : ℝ, cexp (-b * (x : β„‚) ^ 2) = (Ο€ / b) ^ (1 / 2 : β„‚) := by have nv : βˆ€ {b : β„‚}, 0 < re b β†’ b β‰  0 := by intro b hb; contrapose! hb; rw [hb]; simp apply (convex_halfSpace_re_gt 0).isPreconnected.eq_of_sq_eq ?_ ?_ (fun c hc => ?_) (fun {c} hc => ?_) (by simp : 0 < re (1 : β„‚)) ?_ hb Β· -- integral is continuous exact continuousOn_of_forall_continuousAt continuousAt_gaussian_integral Β· -- `(Ο€ / b) ^ (1 / 2 : β„‚)` is continuous refine continuousOn_of_forall_continuousAt fun b hb => (continuousAt_cpow_const (Or.inl ?_)).comp (continuousAt_const.div continuousAt_id (nv hb)) rw [div_re, ofReal_im, ofReal_re, zero_mul, zero_div, add_zero] exact div_pos (mul_pos pi_pos hb) (normSq_pos.mpr (nv hb)) Β· -- equality at 1 have : βˆ€ x : ℝ, cexp (-(1 : β„‚) * (x : β„‚) ^ 2) = exp (-(1 : ℝ) * x ^ 2) := by intro x simp only [ofReal_exp, neg_mul, one_mul, ofReal_neg, ofReal_pow] simp_rw [this, ← coe_algebraMap, RCLike.algebraMap_eq_ofReal, integral_ofReal, ← RCLike.algebraMap_eq_ofReal, coe_algebraMap] conv_rhs => congr Β· rw [← ofReal_one, ← ofReal_div] Β· rw [← ofReal_one, ← ofReal_ofNat, ← ofReal_div] rw [← ofReal_cpow, ofReal_inj] Β· convert integral_gaussian (1 : ℝ) using 1 rw [sqrt_eq_rpow] Β· rw [div_one]; exact pi_pos.le Β· -- squares of both sides agree dsimp only [Pi.pow_apply] rw [integral_gaussian_sq_complex hc, sq] conv_lhs => rw [← cpow_one (↑π / c)] rw [← cpow_add _ _ (div_ne_zero (ofReal_ne_zero.mpr pi_ne_zero) (nv hc))] norm_num Β· -- RHS doesn't vanish rw [Ne, cpow_eq_zero_iff, not_and_or] exact Or.inl (div_ne_zero (ofReal_ne_zero.mpr pi_ne_zero) (nv hc)) -- The Gaussian integral on the half-line, `∫ x in Ioi 0, exp (-b * x^2)`, for complex `b`. theorem integral_gaussian_complex_Ioi {b : β„‚} (hb : 0 < re b) : ∫ x : ℝ in Ioi 0, cexp (-b * (x : β„‚) ^ 2) = (Ο€ / b) ^ (1 / 2 : β„‚) / 2 := by have full_integral := integral_gaussian_complex hb have : MeasurableSet (Ioi (0 : ℝ)) := measurableSet_Ioi rw [← integral_add_compl this (integrable_cexp_neg_mul_sq hb), compl_Ioi] at full_integral suffices ∫ x : ℝ in Iic 0, cexp (-b * (x : β„‚) ^ 2) = ∫ x : ℝ in Ioi 0, cexp (-b * (x : β„‚) ^ 2) by rw [this, ← mul_two] at full_integral rwa [eq_div_iff]; exact two_ne_zero have : βˆ€ c : ℝ, ∫ x in (0 : ℝ)..c, cexp (-b * (x : β„‚) ^ 2) = ∫ x in -c..0, cexp (-b * (x : β„‚) ^ 2) := by intro c have := intervalIntegral.integral_comp_sub_left (a := 0) (b := c) (fun x => cexp (-b * (x : β„‚) ^ 2)) 0 simpa [zero_sub, neg_sq, neg_zero] using this have t1 := intervalIntegral_tendsto_integral_Ioi 0 (integrable_cexp_neg_mul_sq hb).integrableOn tendsto_id have t2 : Tendsto (fun c : ℝ => ∫ x : ℝ in (0 : ℝ)..c, cexp (-b * (x : β„‚) ^ 2)) atTop (𝓝 (∫ x : ℝ in Iic 0, cexp (-b * (x : β„‚) ^ 2))) := by simp_rw [this] refine intervalIntegral_tendsto_integral_Iic _ ?_ tendsto_neg_atTop_atBot apply (integrable_cexp_neg_mul_sq hb).integrableOn exact tendsto_nhds_unique t2 t1 -- The Gaussian integral on the half-line, `∫ x in Ioi 0, exp (-b * x^2)`, for real `b`. theorem integral_gaussian_Ioi (b : ℝ) : ∫ x in Ioi (0 : ℝ), exp (-b * x ^ 2) = √(Ο€ / b) / 2 := by rcases le_or_gt b 0 with (hb | hb) Β· rw [integral_undef, sqrt_eq_zero_of_nonpos, zero_div] Β· exact div_nonpos_of_nonneg_of_nonpos pi_pos.le hb Β· rwa [← IntegrableOn, integrableOn_Ioi_exp_neg_mul_sq_iff, not_lt] rw [← RCLike.ofReal_inj (K := β„‚), ← integral_ofReal, ← RCLike.algebraMap_eq_ofReal, coe_algebraMap] convert integral_gaussian_complex_Ioi (by rwa [ofReal_re] : 0 < (b : β„‚).re) Β· simp Β· rw [sqrt_eq_rpow, ← ofReal_div, ofReal_div, ofReal_cpow] Β· simp Β· exact (div_pos pi_pos hb).le -- see https://github.com/leanprover-community/mathlib4/issues/29041 set_option linter.unusedSimpArgs false in /-- The special-value formula `Ξ“(1/2) = βˆšΟ€`, which is equivalent to the Gaussian integral. -/ theorem Real.Gamma_one_half_eq : Real.Gamma (1 / 2) = βˆšΟ€ := by rw [Gamma_eq_integral one_half_pos, ← integral_comp_rpow_Ioi_of_pos zero_lt_two] convert congr_arg (fun x : ℝ => 2 * x) (integral_gaussian_Ioi 1) using 1 Β· rw [← integral_const_mul] refine setIntegral_congr_fun measurableSet_Ioi fun x hx => ?_ dsimp only have : (x ^ (2 : ℝ)) ^ (1 / (2 : ℝ) - 1) = x⁻¹ := by rw [← rpow_mul (le_of_lt hx)] norm_num rw [rpow_neg (le_of_lt hx), rpow_one] rw [smul_eq_mul, this] simp [field, (ne_of_lt (show 0 < x from hx)).symm] norm_num Β· rw [div_one, ← mul_div_assoc, mul_comm, mul_div_cancel_rightβ‚€ _ (two_ne_zero' ℝ)] /-- The special-value formula `Ξ“(1/2) = βˆšΟ€`, which is equivalent to the Gaussian integral. -/ theorem Complex.Gamma_one_half_eq : Complex.Gamma (1 / 2) = (Ο€ : β„‚) ^ (1 / 2 : β„‚) := by convert congr_arg ((↑) : ℝ β†’ β„‚) Real.Gamma_one_half_eq Β· simpa only [one_div, ofReal_inv, ofReal_ofNat] using Gamma_ofReal (1 / 2) Β· rw [sqrt_eq_rpow, ofReal_cpow pi_pos.le, ofReal_div, ofReal_ofNat, ofReal_one] open scoped Nat in /-- The special-value formula `Ξ“(k + 1 + 1/2) = (2 * k + 1)β€Ό * βˆšΟ€ / (2 ^ (k + 1))` for half-integer values of the gamma function in terms of `Nat.doubleFactorial`. -/ lemma Real.Gamma_nat_add_one_add_half (k : β„•) : Gamma (k + 1 + 1 / 2) = (2 * k + 1 : β„•)β€Ό * βˆšΟ€ / (2 ^ (k + 1)) := by induction k with | zero => simp [-one_div, add_comm (1 : ℝ), Gamma_add_one, Gamma_one_half_eq]; ring | succ k ih => rw [add_right_comm, Gamma_add_one (by positivity), Nat.cast_add, Nat.cast_one, ih, Nat.mul_add] simp ring open scoped Nat in /-- The special-value formula `Ξ“(k + 1/2) = (2 * k - 1)β€Ό * βˆšΟ€ / (2 ^ k))` for half-integer values of the gamma function in terms of `Nat.doubleFactorial`. -/ lemma Real.Gamma_nat_add_half (k : β„•) : Gamma (k + 1 / 2) = (2 * k - 1 : β„•)β€Ό * βˆšΟ€ / (2 ^ k) := by cases k with | zero => simp [- one_div, Gamma_one_half_eq] | succ k => simpa [-one_div, mul_add] using Gamma_nat_add_one_add_half k
.lake/packages/mathlib/Mathlib/Analysis/SpecialFunctions/Trigonometric/Inverse.lean
import Mathlib.Analysis.SpecialFunctions.Trigonometric.Basic import Mathlib.Topology.Order.ProjIcc /-! # Inverse trigonometric functions. See also `Analysis.SpecialFunctions.Trigonometric.Arctan` for the inverse tan function. (This is delayed as it is easier to set up after developing complex trigonometric functions.) Basic inequalities on trigonometric functions. -/ noncomputable section open Topology Filter Set Filter Real namespace Real variable {x y : ℝ} /-- Inverse of the `sin` function, returns values in the range `-Ο€ / 2 ≀ arcsin x ≀ Ο€ / 2`. It defaults to `-Ο€ / 2` on `(-∞, -1)` and to `Ο€ / 2` to `(1, ∞)`. -/ @[pp_nodot] noncomputable def arcsin : ℝ β†’ ℝ := Subtype.val ∘ IccExtend (neg_le_self zero_le_one) sinOrderIso.symm theorem arcsin_mem_Icc (x : ℝ) : arcsin x ∈ Icc (-(Ο€ / 2)) (Ο€ / 2) := Subtype.coe_prop _ @[simp] theorem range_arcsin : range arcsin = Icc (-(Ο€ / 2)) (Ο€ / 2) := by rw [arcsin, range_comp Subtype.val] simp [Icc] theorem arcsin_le_pi_div_two (x : ℝ) : arcsin x ≀ Ο€ / 2 := (arcsin_mem_Icc x).2 theorem neg_pi_div_two_le_arcsin (x : ℝ) : -(Ο€ / 2) ≀ arcsin x := (arcsin_mem_Icc x).1 theorem arcsin_projIcc (x : ℝ) : arcsin (projIcc (-1) 1 (neg_le_self zero_le_one) x) = arcsin x := by rw [arcsin, Function.comp_apply, IccExtend_val, Function.comp_apply, IccExtend, Function.comp_apply] theorem sin_arcsin' {x : ℝ} (hx : x ∈ Icc (-1 : ℝ) 1) : sin (arcsin x) = x := by simpa [arcsin, IccExtend_of_mem _ _ hx, -OrderIso.apply_symm_apply] using Subtype.ext_iff.1 (sinOrderIso.apply_symm_apply ⟨x, hx⟩) theorem sin_arcsin {x : ℝ} (hx₁ : -1 ≀ x) (hxβ‚‚ : x ≀ 1) : sin (arcsin x) = x := sin_arcsin' ⟨hx₁, hxβ‚‚βŸ© theorem arcsin_sin' {x : ℝ} (hx : x ∈ Icc (-(Ο€ / 2)) (Ο€ / 2)) : arcsin (sin x) = x := injOn_sin (arcsin_mem_Icc _) hx <| by rw [sin_arcsin (neg_one_le_sin _) (sin_le_one _)] theorem arcsin_sin {x : ℝ} (hx₁ : -(Ο€ / 2) ≀ x) (hxβ‚‚ : x ≀ Ο€ / 2) : arcsin (sin x) = x := arcsin_sin' ⟨hx₁, hxβ‚‚βŸ© theorem strictMonoOn_arcsin : StrictMonoOn arcsin (Icc (-1) 1) := (Subtype.strictMono_coe _).comp_strictMonoOn <| sinOrderIso.symm.strictMono.strictMonoOn_IccExtend _ @[gcongr] theorem arcsin_lt_arcsin {x y : ℝ} (hx : -1 ≀ x) (hlt : x < y) (hy : y ≀ 1) : arcsin x < arcsin y := strictMonoOn_arcsin ⟨hx, hlt.le.trans hy⟩ ⟨hx.trans hlt.le, hy⟩ hlt theorem monotone_arcsin : Monotone arcsin := (Subtype.mono_coe _).comp <| sinOrderIso.symm.monotone.IccExtend _ @[gcongr] theorem arcsin_le_arcsin {x y : ℝ} (h : x ≀ y) : arcsin x ≀ arcsin y := monotone_arcsin h theorem injOn_arcsin : InjOn arcsin (Icc (-1) 1) := strictMonoOn_arcsin.injOn theorem arcsin_inj {x y : ℝ} (hx₁ : -1 ≀ x) (hxβ‚‚ : x ≀ 1) (hy₁ : -1 ≀ y) (hyβ‚‚ : y ≀ 1) : arcsin x = arcsin y ↔ x = y := injOn_arcsin.eq_iff ⟨hx₁, hxβ‚‚βŸ© ⟨hy₁, hyβ‚‚βŸ© @[continuity, fun_prop] theorem continuous_arcsin : Continuous arcsin := continuous_subtype_val.comp sinOrderIso.symm.continuous.Icc_extend' @[fun_prop] theorem continuousAt_arcsin {x : ℝ} : ContinuousAt arcsin x := continuous_arcsin.continuousAt theorem arcsin_eq_of_sin_eq {x y : ℝ} (h₁ : sin x = y) (hβ‚‚ : x ∈ Icc (-(Ο€ / 2)) (Ο€ / 2)) : arcsin y = x := by subst y exact injOn_sin (arcsin_mem_Icc _) hβ‚‚ (sin_arcsin' (sin_mem_Icc x)) @[simp] theorem arcsin_zero : arcsin 0 = 0 := arcsin_eq_of_sin_eq sin_zero ⟨neg_nonpos.2 pi_div_two_pos.le, pi_div_two_pos.le⟩ @[simp] theorem arcsin_one : arcsin 1 = Ο€ / 2 := arcsin_eq_of_sin_eq sin_pi_div_two <| right_mem_Icc.2 (neg_le_self pi_div_two_pos.le) theorem arcsin_of_one_le {x : ℝ} (hx : 1 ≀ x) : arcsin x = Ο€ / 2 := by rw [← arcsin_projIcc, projIcc_of_right_le _ hx, Subtype.coe_mk, arcsin_one] theorem arcsin_neg_one : arcsin (-1) = -(Ο€ / 2) := arcsin_eq_of_sin_eq (by rw [sin_neg, sin_pi_div_two]) <| left_mem_Icc.2 (neg_le_self pi_div_two_pos.le) theorem arcsin_of_le_neg_one {x : ℝ} (hx : x ≀ -1) : arcsin x = -(Ο€ / 2) := by rw [← arcsin_projIcc, projIcc_of_le_left _ hx, Subtype.coe_mk, arcsin_neg_one] @[simp] theorem arcsin_neg (x : ℝ) : arcsin (-x) = -arcsin x := by rcases le_total x (-1) with hx₁ | hx₁ Β· rw [arcsin_of_le_neg_one hx₁, neg_neg, arcsin_of_one_le (le_neg.2 hx₁)] rcases le_total 1 x with hxβ‚‚ | hxβ‚‚ Β· rw [arcsin_of_one_le hxβ‚‚, arcsin_of_le_neg_one (neg_le_neg hxβ‚‚)] refine arcsin_eq_of_sin_eq ?_ ?_ Β· rw [sin_neg, sin_arcsin hx₁ hxβ‚‚] Β· exact ⟨neg_le_neg (arcsin_le_pi_div_two _), neg_le.2 (neg_pi_div_two_le_arcsin _)⟩ theorem arcsin_le_iff_le_sin {x y : ℝ} (hx : x ∈ Icc (-1 : ℝ) 1) (hy : y ∈ Icc (-(Ο€ / 2)) (Ο€ / 2)) : arcsin x ≀ y ↔ x ≀ sin y := by rw [← arcsin_sin' hy, strictMonoOn_arcsin.le_iff_le hx (sin_mem_Icc _), arcsin_sin' hy] theorem arcsin_le_iff_le_sin' {x y : ℝ} (hy : y ∈ Ico (-(Ο€ / 2)) (Ο€ / 2)) : arcsin x ≀ y ↔ x ≀ sin y := by rcases le_total x (-1) with hx₁ | hx₁ Β· simp [arcsin_of_le_neg_one hx₁, hy.1, hx₁.trans (neg_one_le_sin _)] rcases lt_or_ge 1 x with hxβ‚‚ | hxβ‚‚ Β· simp [arcsin_of_one_le hxβ‚‚.le, hy.2.not_ge, (sin_le_one y).trans_lt hxβ‚‚] exact arcsin_le_iff_le_sin ⟨hx₁, hxβ‚‚βŸ© (mem_Icc_of_Ico hy) theorem le_arcsin_iff_sin_le {x y : ℝ} (hx : x ∈ Icc (-(Ο€ / 2)) (Ο€ / 2)) (hy : y ∈ Icc (-1 : ℝ) 1) : x ≀ arcsin y ↔ sin x ≀ y := by rw [← neg_le_neg_iff, ← arcsin_neg, arcsin_le_iff_le_sin ⟨neg_le_neg hy.2, neg_le.2 hy.1⟩ ⟨neg_le_neg hx.2, neg_le.2 hx.1⟩, sin_neg, neg_le_neg_iff] theorem le_arcsin_iff_sin_le' {x y : ℝ} (hx : x ∈ Ioc (-(Ο€ / 2)) (Ο€ / 2)) : x ≀ arcsin y ↔ sin x ≀ y := by rw [← neg_le_neg_iff, ← arcsin_neg, arcsin_le_iff_le_sin' ⟨neg_le_neg hx.2, neg_lt.2 hx.1⟩, sin_neg, neg_le_neg_iff] theorem arcsin_lt_iff_lt_sin {x y : ℝ} (hx : x ∈ Icc (-1 : ℝ) 1) (hy : y ∈ Icc (-(Ο€ / 2)) (Ο€ / 2)) : arcsin x < y ↔ x < sin y := not_le.symm.trans <| (not_congr <| le_arcsin_iff_sin_le hy hx).trans not_le theorem arcsin_lt_iff_lt_sin' {x y : ℝ} (hy : y ∈ Ioc (-(Ο€ / 2)) (Ο€ / 2)) : arcsin x < y ↔ x < sin y := not_le.symm.trans <| (not_congr <| le_arcsin_iff_sin_le' hy).trans not_le theorem lt_arcsin_iff_sin_lt {x y : ℝ} (hx : x ∈ Icc (-(Ο€ / 2)) (Ο€ / 2)) (hy : y ∈ Icc (-1 : ℝ) 1) : x < arcsin y ↔ sin x < y := not_le.symm.trans <| (not_congr <| arcsin_le_iff_le_sin hy hx).trans not_le theorem lt_arcsin_iff_sin_lt' {x y : ℝ} (hx : x ∈ Ico (-(Ο€ / 2)) (Ο€ / 2)) : x < arcsin y ↔ sin x < y := not_le.symm.trans <| (not_congr <| arcsin_le_iff_le_sin' hx).trans not_le theorem arcsin_eq_iff_eq_sin {x y : ℝ} (hy : y ∈ Ioo (-(Ο€ / 2)) (Ο€ / 2)) : arcsin x = y ↔ x = sin y := by simp only [le_antisymm_iff, arcsin_le_iff_le_sin' (mem_Ico_of_Ioo hy), le_arcsin_iff_sin_le' (mem_Ioc_of_Ioo hy)] @[simp] theorem arcsin_nonneg {x : ℝ} : 0 ≀ arcsin x ↔ 0 ≀ x := (le_arcsin_iff_sin_le' ⟨neg_lt_zero.2 pi_div_two_pos, pi_div_two_pos.le⟩).trans <| by rw [sin_zero] @[simp] theorem arcsin_nonpos {x : ℝ} : arcsin x ≀ 0 ↔ x ≀ 0 := neg_nonneg.symm.trans <| arcsin_neg x β–Έ arcsin_nonneg.trans neg_nonneg @[simp] theorem arcsin_eq_zero_iff {x : ℝ} : arcsin x = 0 ↔ x = 0 := by simp [le_antisymm_iff] @[simp] theorem zero_eq_arcsin_iff {x} : 0 = arcsin x ↔ x = 0 := eq_comm.trans arcsin_eq_zero_iff @[simp] theorem arcsin_pos {x : ℝ} : 0 < arcsin x ↔ 0 < x := lt_iff_lt_of_le_iff_le arcsin_nonpos @[simp] theorem arcsin_lt_zero {x : ℝ} : arcsin x < 0 ↔ x < 0 := lt_iff_lt_of_le_iff_le arcsin_nonneg @[simp] theorem arcsin_lt_pi_div_two {x : ℝ} : arcsin x < Ο€ / 2 ↔ x < 1 := (arcsin_lt_iff_lt_sin' (right_mem_Ioc.2 <| neg_lt_self pi_div_two_pos)).trans <| by rw [sin_pi_div_two] @[simp] theorem neg_pi_div_two_lt_arcsin {x : ℝ} : -(Ο€ / 2) < arcsin x ↔ -1 < x := (lt_arcsin_iff_sin_lt' <| left_mem_Ico.2 <| neg_lt_self pi_div_two_pos).trans <| by rw [sin_neg, sin_pi_div_two] @[simp] theorem arcsin_eq_pi_div_two {x : ℝ} : arcsin x = Ο€ / 2 ↔ 1 ≀ x := ⟨fun h => not_lt.1 fun h' => (arcsin_lt_pi_div_two.2 h').ne h, arcsin_of_one_le⟩ @[simp] theorem pi_div_two_eq_arcsin {x} : Ο€ / 2 = arcsin x ↔ 1 ≀ x := eq_comm.trans arcsin_eq_pi_div_two @[simp] theorem pi_div_two_le_arcsin {x} : Ο€ / 2 ≀ arcsin x ↔ 1 ≀ x := (arcsin_le_pi_div_two x).ge_iff_eq'.trans pi_div_two_eq_arcsin @[simp] theorem arcsin_eq_neg_pi_div_two {x : ℝ} : arcsin x = -(Ο€ / 2) ↔ x ≀ -1 := ⟨fun h => not_lt.1 fun h' => (neg_pi_div_two_lt_arcsin.2 h').ne' h, arcsin_of_le_neg_one⟩ @[simp] theorem neg_pi_div_two_eq_arcsin {x} : -(Ο€ / 2) = arcsin x ↔ x ≀ -1 := eq_comm.trans arcsin_eq_neg_pi_div_two @[simp] theorem arcsin_le_neg_pi_div_two {x} : arcsin x ≀ -(Ο€ / 2) ↔ x ≀ -1 := (neg_pi_div_two_le_arcsin x).ge_iff_eq'.trans arcsin_eq_neg_pi_div_two @[simp] theorem pi_div_four_le_arcsin {x} : Ο€ / 4 ≀ arcsin x ↔ √2 / 2 ≀ x := by rw [← sin_pi_div_four, le_arcsin_iff_sin_le'] have := pi_pos constructor <;> linarith theorem mapsTo_sin_Ioo : MapsTo sin (Ioo (-(Ο€ / 2)) (Ο€ / 2)) (Ioo (-1) 1) := fun x h => by rwa [mem_Ioo, ← arcsin_lt_pi_div_two, ← neg_pi_div_two_lt_arcsin, arcsin_sin h.1.le h.2.le] /-- `Real.sin` as an `OpenPartialHomeomorph` between `(-Ο€ / 2, Ο€ / 2)` and `(-1, 1)`. -/ @[simp] def sinPartialHomeomorph : OpenPartialHomeomorph ℝ ℝ where toFun := sin invFun := arcsin source := Ioo (-(Ο€ / 2)) (Ο€ / 2) target := Ioo (-1) 1 map_source' := mapsTo_sin_Ioo map_target' _ hy := ⟨neg_pi_div_two_lt_arcsin.2 hy.1, arcsin_lt_pi_div_two.2 hy.2⟩ left_inv' _ hx := arcsin_sin hx.1.le hx.2.le right_inv' _ hy := sin_arcsin hy.1.le hy.2.le open_source := isOpen_Ioo open_target := isOpen_Ioo continuousOn_toFun := continuous_sin.continuousOn continuousOn_invFun := continuous_arcsin.continuousOn theorem cos_arcsin_nonneg (x : ℝ) : 0 ≀ cos (arcsin x) := cos_nonneg_of_mem_Icc ⟨neg_pi_div_two_le_arcsin _, arcsin_le_pi_div_two _⟩ -- The junk values for `arcsin` and `sqrt` make this true even outside `[-1, 1]`. theorem cos_arcsin (x : ℝ) : cos (arcsin x) = √(1 - x ^ 2) := by by_cases hx₁ : -1 ≀ x; swap Β· rw [not_le] at hx₁ rw [arcsin_of_le_neg_one hx₁.le, cos_neg, cos_pi_div_two, sqrt_eq_zero_of_nonpos] nlinarith by_cases hxβ‚‚ : x ≀ 1; swap Β· rw [not_le] at hxβ‚‚ rw [arcsin_of_one_le hxβ‚‚.le, cos_pi_div_two, sqrt_eq_zero_of_nonpos] nlinarith have : sin (arcsin x) ^ 2 + cos (arcsin x) ^ 2 = 1 := sin_sq_add_cos_sq (arcsin x) rw [← eq_sub_iff_add_eq', ← sqrt_inj (sq_nonneg _) (sub_nonneg.2 (sin_sq_le_one (arcsin x))), sq, sqrt_mul_self (cos_arcsin_nonneg _)] at this rw [this, sin_arcsin hx₁ hxβ‚‚] -- The junk values for `arcsin` and `sqrt` make this true even outside `[-1, 1]`. theorem tan_arcsin (x : ℝ) : tan (arcsin x) = x / √(1 - x ^ 2) := by rw [tan_eq_sin_div_cos, cos_arcsin] by_cases hx₁ : -1 ≀ x; swap Β· have h : √(1 - x ^ 2) = 0 := sqrt_eq_zero_of_nonpos (by nlinarith) rw [h] simp by_cases hxβ‚‚ : x ≀ 1; swap Β· have h : √(1 - x ^ 2) = 0 := sqrt_eq_zero_of_nonpos (by nlinarith) rw [h] simp rw [sin_arcsin hx₁ hxβ‚‚] /-- Inverse of the `cos` function, returns values in the range `0 ≀ arccos x` and `arccos x ≀ Ο€`. It defaults to `Ο€` on `(-∞, -1)` and to `0` to `(1, ∞)`. -/ @[pp_nodot] noncomputable def arccos (x : ℝ) : ℝ := Ο€ / 2 - arcsin x theorem arccos_eq_pi_div_two_sub_arcsin (x : ℝ) : arccos x = Ο€ / 2 - arcsin x := rfl theorem arcsin_eq_pi_div_two_sub_arccos (x : ℝ) : arcsin x = Ο€ / 2 - arccos x := by simp [arccos] theorem arccos_le_pi (x : ℝ) : arccos x ≀ Ο€ := by unfold arccos; linarith [neg_pi_div_two_le_arcsin x] theorem arccos_nonneg (x : ℝ) : 0 ≀ arccos x := by unfold arccos; linarith [arcsin_le_pi_div_two x] @[simp] theorem arccos_pos {x : ℝ} : 0 < arccos x ↔ x < 1 := by simp [arccos] theorem cos_arccos {x : ℝ} (hx₁ : -1 ≀ x) (hxβ‚‚ : x ≀ 1) : cos (arccos x) = x := by rw [arccos, cos_pi_div_two_sub, sin_arcsin hx₁ hxβ‚‚] theorem arccos_cos {x : ℝ} (hx₁ : 0 ≀ x) (hxβ‚‚ : x ≀ Ο€) : arccos (cos x) = x := by rw [arccos, ← sin_pi_div_two_sub, arcsin_sin] <;> simp [sub_eq_add_neg] <;> linarith lemma arccos_eq_of_eq_cos (hyβ‚€ : 0 ≀ y) (hy₁ : y ≀ Ο€) (hxy : x = cos y) : arccos x = y := by rw [hxy, arccos_cos hyβ‚€ hy₁] theorem strictAntiOn_arccos : StrictAntiOn arccos (Icc (-1) 1) := fun _ hx _ hy h => sub_lt_sub_left (strictMonoOn_arcsin hx hy h) _ @[gcongr] lemma arccos_lt_arccos {x y : ℝ} (hx : -1 ≀ x) (hlt : x < y) (hy : y ≀ 1) : arccos y < arccos x := by unfold arccos; gcongr <;> assumption @[gcongr] lemma arccos_le_arccos {x y : ℝ} (hlt : x ≀ y) : arccos y ≀ arccos x := by unfold arccos; gcongr theorem antitone_arccos : Antitone arccos := fun _ _ ↦ arccos_le_arccos theorem arccos_injOn : InjOn arccos (Icc (-1) 1) := strictAntiOn_arccos.injOn theorem arccos_inj {x y : ℝ} (hx₁ : -1 ≀ x) (hxβ‚‚ : x ≀ 1) (hy₁ : -1 ≀ y) (hyβ‚‚ : y ≀ 1) : arccos x = arccos y ↔ x = y := arccos_injOn.eq_iff ⟨hx₁, hxβ‚‚βŸ© ⟨hy₁, hyβ‚‚βŸ© @[simp] theorem arccos_zero : arccos 0 = Ο€ / 2 := by simp [arccos] @[simp] theorem arccos_one : arccos 1 = 0 := by simp [arccos] @[simp] theorem arccos_neg_one : arccos (-1) = Ο€ := by simp [arccos, add_halves] @[simp] theorem arccos_eq_zero {x} : arccos x = 0 ↔ 1 ≀ x := by simp [arccos, sub_eq_zero] @[simp] theorem arccos_eq_pi_div_two {x} : arccos x = Ο€ / 2 ↔ x = 0 := by simp [arccos] @[simp] theorem arccos_eq_pi {x} : arccos x = Ο€ ↔ x ≀ -1 := by rw [arccos, sub_eq_iff_eq_add, ← sub_eq_iff_eq_add', div_two_sub_self, neg_pi_div_two_eq_arcsin] theorem arccos_neg (x : ℝ) : arccos (-x) = Ο€ - arccos x := by rw [← add_halves Ο€, arccos, arcsin_neg, arccos, add_sub_assoc, sub_sub_self, sub_neg_eq_add] theorem arccos_of_one_le {x : ℝ} (hx : 1 ≀ x) : arccos x = 0 := by rw [arccos, arcsin_of_one_le hx, sub_self] theorem arccos_of_le_neg_one {x : ℝ} (hx : x ≀ -1) : arccos x = Ο€ := by rw [arccos, arcsin_of_le_neg_one hx, sub_neg_eq_add, add_halves] -- The junk values for `arccos` and `sqrt` make this true even outside `[-1, 1]`. theorem sin_arccos (x : ℝ) : sin (arccos x) = √(1 - x ^ 2) := by by_cases hx₁ : -1 ≀ x; swap Β· rw [not_le] at hx₁ rw [arccos_of_le_neg_one hx₁.le, sin_pi, sqrt_eq_zero_of_nonpos] nlinarith by_cases hxβ‚‚ : x ≀ 1; swap Β· rw [not_le] at hxβ‚‚ rw [arccos_of_one_le hxβ‚‚.le, sin_zero, sqrt_eq_zero_of_nonpos] nlinarith rw [arccos_eq_pi_div_two_sub_arcsin, sin_pi_div_two_sub, cos_arcsin] @[simp] theorem arccos_le_pi_div_two {x} : arccos x ≀ Ο€ / 2 ↔ 0 ≀ x := by simp [arccos] @[simp] theorem arccos_lt_pi_div_two {x : ℝ} : arccos x < Ο€ / 2 ↔ 0 < x := by simp [arccos] @[simp] theorem arccos_le_pi_div_four {x} : arccos x ≀ Ο€ / 4 ↔ √2 / 2 ≀ x := by rw [arccos, ← pi_div_four_le_arcsin] constructor <;> Β· intro linarith @[continuity, fun_prop] theorem continuous_arccos : Continuous arccos := continuous_const.sub continuous_arcsin -- The junk values for `arccos` and `sqrt` make this true even outside `[-1, 1]`. theorem tan_arccos (x : ℝ) : tan (arccos x) = √(1 - x ^ 2) / x := by rw [arccos, tan_pi_div_two_sub, tan_arcsin, inv_div] -- The junk values for `arccos` and `sqrt` make this true even for `1 < x`. theorem arccos_eq_arcsin {x : ℝ} (h : 0 ≀ x) : arccos x = arcsin (√(1 - x ^ 2)) := (arcsin_eq_of_sin_eq (sin_arccos _) ⟨(Left.neg_nonpos_iff.2 (div_nonneg pi_pos.le (by simp))).trans (arccos_nonneg _), arccos_le_pi_div_two.2 h⟩).symm -- The junk values for `arcsin` and `sqrt` make this true even for `1 < x`. theorem arcsin_eq_arccos {x : ℝ} (h : 0 ≀ x) : arcsin x = arccos (√(1 - x ^ 2)) := by rw [eq_comm, ← cos_arcsin] exact arccos_cos (arcsin_nonneg.2 h) ((arcsin_le_pi_div_two _).trans (div_le_self pi_pos.le one_le_two)) end Real open Real /-! ### Convenience dot notation lemmas -/ namespace Filter.Tendsto variable {Ξ± : Type*} {l : Filter Ξ±} {x : ℝ} {f : Ξ± β†’ ℝ} protected theorem arcsin (h : Tendsto f l (𝓝 x)) : Tendsto (arcsin <| f Β·) l (𝓝 (arcsin x)) := (continuous_arcsin.tendsto _).comp h theorem arcsin_nhdsLE (h : Tendsto f l (𝓝[≀] x)) : Tendsto (arcsin <| f Β·) l (𝓝[≀] (arcsin x)) := by refine ((continuous_arcsin.tendsto _).inf <| MapsTo.tendsto fun y hy ↦ ?_).comp h exact monotone_arcsin hy theorem arcsin_nhdsGE (h : Tendsto f l (𝓝[β‰₯] x)) : Tendsto (arcsin <| f Β·) l (𝓝[β‰₯] (arcsin x)) := ((continuous_arcsin.tendsto _).inf <| MapsTo.tendsto fun _ ↦ arcsin_le_arcsin).comp h protected theorem arccos (h : Tendsto f l (𝓝 x)) : Tendsto (arccos <| f Β·) l (𝓝 (arccos x)) := (continuous_arccos.tendsto _).comp h theorem arccos_nhdsLE (h : Tendsto f l (𝓝[≀] x)) : Tendsto (arccos <| f Β·) l (𝓝[β‰₯] (arccos x)) := ((continuous_arccos.tendsto _).inf <| MapsTo.tendsto fun _ ↦ arccos_le_arccos).comp h theorem arccos_nhdsGE (h : Tendsto f l (𝓝[β‰₯] x)) : Tendsto (arccos <| f Β·) l (𝓝[≀] (arccos x)) := by refine ((continuous_arccos.tendsto _).inf <| MapsTo.tendsto fun y hy ↦ ?_).comp h simp only [mem_Ici, mem_Iic] at hy ⊒ exact antitone_arccos hy end Filter.Tendsto variable {X : Type*} [TopologicalSpace X] {f : X β†’ ℝ} {s : Set X} {x : X} protected nonrec theorem ContinuousWithinAt.arcsin (h : ContinuousWithinAt f s x) : ContinuousWithinAt (arcsin <| f Β·) s x := h.arcsin protected nonrec theorem ContinuousWithinAt.arccos (h : ContinuousWithinAt f s x) : ContinuousWithinAt (arccos <| f Β·) s x := h.arccos protected nonrec theorem ContinuousAt.arcsin (h : ContinuousAt f x) : ContinuousAt (arcsin <| f Β·) x := h.arcsin protected nonrec theorem ContinuousAt.arccos (h : ContinuousAt f x) : ContinuousAt (arccos <| f Β·) x := h.arccos protected theorem ContinuousOn.arcsin (h : ContinuousOn f s) : ContinuousOn (arcsin <| f Β·) s := fun x hx ↦ (h x hx).arcsin protected theorem ContinuousOn.arccos (h : ContinuousOn f s) : ContinuousOn (arccos <| f Β·) s := fun x hx ↦ (h x hx).arccos protected theorem Continuous.arcsin (h : Continuous f) : Continuous (arcsin <| f Β·) := continuous_arcsin.comp h protected theorem Continuous.arccos (h : Continuous f) : Continuous (arccos <| f Β·) := continuous_arccos.comp h
.lake/packages/mathlib/Mathlib/Analysis/SpecialFunctions/Trigonometric/Arctan.lean
import Mathlib.Analysis.SpecialFunctions.Trigonometric.Complex /-! # The `arctan` function. Inequalities, identities and `Real.tan` as an `OpenPartialHomeomorph` between `(-(Ο€ / 2), Ο€ / 2)` and the whole line. The result of `arctan x + arctan y` is given by `arctan_add`, `arctan_add_eq_add_pi` or `arctan_add_eq_sub_pi` depending on whether `x * y < 1` and `0 < x`. As an application of `arctan_add` we give four Machin-like formulas (linear combinations of arctangents equal to `Ο€ / 4 = arctan 1`), including John Machin's original one at `four_mul_arctan_inv_5_sub_arctan_inv_239`. -/ noncomputable section open Set Filter open scoped Topology namespace Real variable {x y : ℝ} theorem tan_add (h : ((βˆ€ k : β„€, x β‰  (2 * k + 1) * Ο€ / 2) ∧ βˆ€ l : β„€, y β‰  (2 * l + 1) * Ο€ / 2) ∨ (βˆƒ k : β„€, x = (2 * k + 1) * Ο€ / 2) ∧ βˆƒ l : β„€, y = (2 * l + 1) * Ο€ / 2) : tan (x + y) = (tan x + tan y) / (1 - tan x * tan y) := by simpa only [← Complex.ofReal_inj, Complex.ofReal_sub, Complex.ofReal_add, Complex.ofReal_div, Complex.ofReal_mul, Complex.ofReal_tan] using @Complex.tan_add (x : β„‚) (y : β„‚) (by convert h <;> norm_cast) theorem tan_add' (h : (βˆ€ k : β„€, x β‰  (2 * k + 1) * Ο€ / 2) ∧ βˆ€ l : β„€, y β‰  (2 * l + 1) * Ο€ / 2) : tan (x + y) = (tan x + tan y) / (1 - tan x * tan y) := tan_add (Or.inl h) theorem tan_sub {x y : ℝ} (h : ((βˆ€ k : β„€, x β‰  (2 * k + 1) * Ο€ / 2) ∧ βˆ€ l : β„€, y β‰  (2 * l + 1) * Ο€ / 2) ∨ (βˆƒ k : β„€, x = (2 * k + 1) * Ο€ / 2) ∧ βˆƒ l : β„€, y = (2 * l + 1) * Ο€ / 2) : tan (x - y) = (tan x - tan y) / (1 + tan x * tan y) := by simpa only [← Complex.ofReal_inj, Complex.ofReal_sub, Complex.ofReal_add, Complex.ofReal_div, Complex.ofReal_mul, Complex.ofReal_tan] using @Complex.tan_sub (x : β„‚) (y : β„‚) (by convert h <;> norm_cast) theorem tan_sub' {x y : ℝ} (h : (βˆ€ k : β„€, x β‰  (2 * k + 1) * Ο€ / 2) ∧ βˆ€ l : β„€, y β‰  (2 * l + 1) * Ο€ / 2) : tan (x - y) = (tan x - tan y) / (1 + tan x * tan y) := tan_sub (Or.inl h) theorem tan_two_mul : tan (2 * x) = 2 * tan x / (1 - tan x ^ 2) := by have := @Complex.tan_two_mul x norm_cast at * theorem tan_int_mul_pi_div_two (n : β„€) : tan (n * Ο€ / 2) = 0 := tan_eq_zero_iff.mpr (by use n) theorem continuousOn_tan : ContinuousOn tan {x | cos x β‰  0} := by suffices ContinuousOn (fun x => sin x / cos x) {x | cos x β‰  0} by have h_eq : (fun x => sin x / cos x) = tan := by ext1 x; rw [tan_eq_sin_div_cos] rwa [h_eq] at this exact continuousOn_sin.div continuousOn_cos fun x => id @[continuity] theorem continuous_tan : Continuous fun x : {x | cos x β‰  0} => tan x := continuousOn_iff_continuous_restrict.1 continuousOn_tan theorem continuousOn_tan_Ioo : ContinuousOn tan (Ioo (-(Ο€ / 2)) (Ο€ / 2)) := by refine ContinuousOn.mono continuousOn_tan fun x => ?_ simp only [and_imp, mem_Ioo, mem_setOf_eq, Ne] rw [cos_eq_zero_iff] rintro hx_gt hx_lt ⟨r, hxr_eq⟩ rcases le_or_gt 0 r with h | h Β· rw [lt_iff_not_ge] at hx_lt refine hx_lt ?_ rw [hxr_eq, ← one_mul (Ο€ / 2), mul_div_assoc, mul_le_mul_iff_leftβ‚€ (half_pos pi_pos)] simp [h] Β· rw [lt_iff_not_ge] at hx_gt refine hx_gt ?_ rw [hxr_eq, ← one_mul (Ο€ / 2), mul_div_assoc, neg_mul_eq_neg_mul, mul_le_mul_iff_leftβ‚€ (half_pos pi_pos)] have hr_le : r ≀ -1 := by rwa [Int.lt_iff_add_one_le, ← le_neg_iff_add_nonpos_right] at h rw [← le_sub_iff_add_le, mul_comm, ← le_div_iffβ‚€] Β· norm_num assumption_mod_cast Β· exact zero_lt_two theorem surjOn_tan : SurjOn tan (Ioo (-(Ο€ / 2)) (Ο€ / 2)) univ := have := neg_lt_self pi_div_two_pos continuousOn_tan_Ioo.surjOn_of_tendsto (nonempty_Ioo.2 this) (by rw [tendsto_comp_coe_Ioo_atBot this]; exact tendsto_tan_neg_pi_div_two) (by rw [tendsto_comp_coe_Ioo_atTop this]; exact tendsto_tan_pi_div_two) theorem tan_surjective : Function.Surjective tan := fun _ => surjOn_tan.subset_range trivial theorem image_tan_Ioo : tan '' Ioo (-(Ο€ / 2)) (Ο€ / 2) = univ := univ_subset_iff.1 surjOn_tan /-- `Real.tan` as an `OrderIso` between `(-(Ο€ / 2), Ο€ / 2)` and `ℝ`. -/ def tanOrderIso : Ioo (-(Ο€ / 2)) (Ο€ / 2) ≃o ℝ := (strictMonoOn_tan.orderIso _ _).trans <| (OrderIso.setCongr _ _ image_tan_Ioo).trans OrderIso.Set.univ /-- Inverse of the `tan` function, returns values in the range `-Ο€ / 2 < arctan x` and `arctan x < Ο€ / 2` -/ @[pp_nodot] noncomputable def arctan (x : ℝ) : ℝ := tanOrderIso.symm x @[simp] theorem tan_arctan (x : ℝ) : tan (arctan x) = x := tanOrderIso.apply_symm_apply x theorem arctan_mem_Ioo (x : ℝ) : arctan x ∈ Ioo (-(Ο€ / 2)) (Ο€ / 2) := Subtype.coe_prop _ @[simp] theorem range_arctan : range arctan = Ioo (-(Ο€ / 2)) (Ο€ / 2) := ((EquivLike.surjective _).range_comp _).trans Subtype.range_coe theorem arctan_tan (hx₁ : -(Ο€ / 2) < x) (hxβ‚‚ : x < Ο€ / 2) : arctan (tan x) = x := Subtype.ext_iff.1 <| tanOrderIso.symm_apply_apply ⟨x, hx₁, hxβ‚‚βŸ© theorem cos_arctan_pos (x : ℝ) : 0 < cos (arctan x) := cos_pos_of_mem_Ioo <| arctan_mem_Ioo x theorem cos_sq_arctan (x : ℝ) : cos (arctan x) ^ 2 = 1 / (1 + x ^ 2) := by rw_mod_cast [one_div, ← inv_one_add_tan_sq (cos_arctan_pos x).ne', tan_arctan] theorem sin_arctan (x : ℝ) : sin (arctan x) = x / √(1 + x ^ 2) := by rw_mod_cast [← tan_div_sqrt_one_add_tan_sq (cos_arctan_pos x), tan_arctan] theorem cos_arctan (x : ℝ) : cos (arctan x) = 1 / √(1 + x ^ 2) := by rw_mod_cast [one_div, ← inv_sqrt_one_add_tan_sq (cos_arctan_pos x), tan_arctan] theorem arctan_lt_pi_div_two (x : ℝ) : arctan x < Ο€ / 2 := (arctan_mem_Ioo x).2 theorem neg_pi_div_two_lt_arctan (x : ℝ) : -(Ο€ / 2) < arctan x := (arctan_mem_Ioo x).1 theorem arctan_eq_arcsin (x : ℝ) : arctan x = arcsin (x / √(1 + x ^ 2)) := Eq.symm <| arcsin_eq_of_sin_eq (sin_arctan x) (mem_Icc_of_Ioo <| arctan_mem_Ioo x) theorem arcsin_eq_arctan (h : x ∈ Ioo (-(1 : ℝ)) 1) : arcsin x = arctan (x / √(1 - x ^ 2)) := by rw_mod_cast [arctan_eq_arcsin, div_pow, sq_sqrt, one_add_div, div_div, ← sqrt_mul, mul_div_cancelβ‚€, sub_add_cancel, sqrt_one, div_one] <;> simp at h <;> nlinarith [h.1, h.2] @[simp] theorem arctan_zero : arctan 0 = 0 := by simp [arctan_eq_arcsin] @[gcongr, mono] theorem arctan_strictMono : StrictMono arctan := tanOrderIso.symm.strictMono @[gcongr] theorem arctan_mono : Monotone arctan := arctan_strictMono.monotone @[deprecated arctan_strictMono (since := "2025-10-20")] lemma arctan_lt_arctan (hxy : x < y) : arctan x < arctan y := arctan_strictMono hxy @[simp] theorem arctan_lt_arctan_iff : arctan x < arctan y ↔ x < y := arctan_strictMono.lt_iff_lt @[deprecated arctan_mono (since := "2025-10-20")] lemma arctan_le_arctan (hxy : x ≀ y) : arctan x ≀ arctan y := arctan_strictMono.monotone hxy @[simp] theorem arctan_le_arctan_iff : arctan x ≀ arctan y ↔ x ≀ y := arctan_strictMono.le_iff_le theorem arctan_injective : arctan.Injective := arctan_strictMono.injective @[simp] theorem arctan_inj : arctan x = arctan y ↔ x = y := arctan_injective.eq_iff @[simp] theorem arctan_eq_zero_iff : arctan x = 0 ↔ x = 0 := .trans (by rw [arctan_zero]) arctan_injective.eq_iff theorem tendsto_arctan_atTop : Tendsto arctan atTop (𝓝[<] (Ο€ / 2)) := tendsto_Ioo_atTop.mp tanOrderIso.symm.tendsto_atTop theorem tendsto_arctan_atBot : Tendsto arctan atBot (𝓝[>] (-(Ο€ / 2))) := tendsto_Ioo_atBot.mp tanOrderIso.symm.tendsto_atBot theorem arctan_eq_of_tan_eq (h : tan x = y) (hx : x ∈ Ioo (-(Ο€ / 2)) (Ο€ / 2)) : arctan y = x := injOn_tan (arctan_mem_Ioo _) hx (by rw [tan_arctan, h]) @[simp] theorem arctan_one : arctan 1 = Ο€ / 4 := arctan_eq_of_tan_eq tan_pi_div_four <| by constructor <;> linarith [pi_pos] @[simp] theorem arctan_eq_pi_div_four : arctan x = Ο€ / 4 ↔ x = 1 := arctan_injective.eq_iff' arctan_one @[simp] theorem arctan_neg (x : ℝ) : arctan (-x) = -arctan x := by simp [arctan_eq_arcsin, neg_div] @[simp] theorem arctan_eq_neg_pi_div_four : arctan x = -(Ο€ / 4) ↔ x = -1 := arctan_injective.eq_iff' <| by rw [arctan_neg, arctan_one] @[simp] theorem arctan_pos : 0 < arctan x ↔ 0 < x := by simpa only [arctan_zero] using arctan_lt_arctan_iff (x := 0) @[simp] theorem arctan_lt_zero : arctan x < 0 ↔ x < 0 := by simpa only [arctan_zero] using arctan_lt_arctan_iff (y := 0) @[simp] theorem arctan_nonneg : 0 ≀ arctan x ↔ 0 ≀ x := by simpa only [arctan_zero] using arctan_le_arctan_iff (x := 0) @[simp] theorem arctan_le_zero : arctan x ≀ 0 ↔ x ≀ 0 := by simpa only [arctan_zero] using arctan_le_arctan_iff (y := 0) theorem arctan_eq_arccos (h : 0 ≀ x) : arctan x = arccos (√(1 + x ^ 2))⁻¹ := by rw [arctan_eq_arcsin, arccos_eq_arcsin]; swap; Β· exact inv_nonneg.2 (sqrt_nonneg _) congr 1 rw_mod_cast [← sqrt_inv, sq_sqrt, ← one_div, one_sub_div, add_sub_cancel_left, sqrt_div, sqrt_sq h] all_goals positivity -- The junk values for `arccos` and `sqrt` make this true even for `1 < x`. theorem arccos_eq_arctan (h : 0 < x) : arccos x = arctan (√(1 - x ^ 2) / x) := by rw [arccos, eq_comm] refine arctan_eq_of_tan_eq ?_ ⟨?_, ?_⟩ Β· rw_mod_cast [tan_pi_div_two_sub, tan_arcsin, inv_div] Β· linarith only [arcsin_le_pi_div_two x, pi_pos] Β· linarith only [arcsin_pos.2 h] theorem arctan_inv_of_pos (h : 0 < x) : arctan x⁻¹ = Ο€ / 2 - arctan x := by rw [← arctan_tan (x := _ - _), tan_pi_div_two_sub, tan_arctan] Β· norm_num exact (arctan_lt_pi_div_two x).trans (half_lt_self_iff.mpr pi_pos) Β· rw [sub_lt_self_iff, ← arctan_zero] exact tanOrderIso.symm.strictMono h theorem arctan_inv_of_neg (h : x < 0) : arctan x⁻¹ = -(Ο€ / 2) - arctan x := by have := arctan_inv_of_pos (neg_pos.mpr h) rwa [inv_neg, arctan_neg, neg_eq_iff_eq_neg, neg_sub', arctan_neg, neg_neg] at this section ArctanAdd lemma arctan_ne_mul_pi_div_two : βˆ€ (k : β„€), arctan x β‰  (2 * k + 1) * Ο€ / 2 := by by_contra! obtain ⟨k, h⟩ := this obtain ⟨lb, ub⟩ := arctan_mem_Ioo x rw [h, neg_eq_neg_one_mul, mul_div_assoc, mul_lt_mul_iff_leftβ‚€ (by positivity)] at lb rw [h, ← one_mul (Ο€ / 2), mul_div_assoc, mul_lt_mul_iff_leftβ‚€ (by positivity)] at ub norm_cast at lb ub; change -1 < _ at lb; cutsat lemma arctan_add_arctan_lt_pi_div_two (h : x * y < 1) : arctan x + arctan y < Ο€ / 2 := by rcases le_or_gt y 0 with hy | hy Β· rw [← add_zero (Ο€ / 2), ← arctan_zero] exact add_lt_add_of_lt_of_le (arctan_lt_pi_div_two _) (tanOrderIso.symm.monotone hy) Β· rw [← lt_div_iffβ‚€ hy, ← inv_eq_one_div] at h replace h : arctan x < arctan y⁻¹ := tanOrderIso.symm.strictMono h rwa [arctan_inv_of_pos hy, lt_tsub_iff_right] at h theorem arctan_add (h : x * y < 1) : arctan x + arctan y = arctan ((x + y) / (1 - x * y)) := by rw [← arctan_tan (x := _ + _)] Β· congr conv_rhs => rw [← tan_arctan x, ← tan_arctan y] exact tan_add' ⟨arctan_ne_mul_pi_div_two, arctan_ne_mul_pi_div_two⟩ Β· rw [neg_lt, neg_add, ← arctan_neg, ← arctan_neg] rw [← neg_mul_neg] at h exact arctan_add_arctan_lt_pi_div_two h Β· exact arctan_add_arctan_lt_pi_div_two h theorem arctan_add_eq_add_pi (h : 1 < x * y) (hx : 0 < x) : arctan x + arctan y = arctan ((x + y) / (1 - x * y)) + Ο€ := by have hy : 0 < y := by have := mul_pos_iff.mp (zero_lt_one.trans h) simpa [hx, hx.asymm] have k := arctan_add (mul_inv x y β–Έ inv_lt_one_of_one_ltβ‚€ h) rw [arctan_inv_of_pos hx, arctan_inv_of_pos hy, show _ + _ = Ο€ - (arctan x + arctan y) by ring, sub_eq_iff_eq_add, ← sub_eq_iff_eq_add', sub_eq_add_neg, ← arctan_neg, add_comm] at k grind theorem arctan_add_eq_sub_pi (h : 1 < x * y) (hx : x < 0) : arctan x + arctan y = arctan ((x + y) / (1 - x * y)) - Ο€ := by rw [← neg_mul_neg] at h have k := arctan_add_eq_add_pi h (neg_pos.mpr hx) rw [show _ / _ = -((x + y) / (1 - x * y)) by ring, ← neg_inj] at k simp only [arctan_neg, neg_add, neg_neg, ← sub_eq_add_neg _ Ο€] at k exact k theorem two_mul_arctan (h₁ : -1 < x) (hβ‚‚ : x < 1) : 2 * arctan x = arctan (2 * x / (1 - x ^ 2)) := by rw [two_mul, arctan_add (by nlinarith)]; congr 1; ring theorem two_mul_arctan_add_pi (h : 1 < x) : 2 * arctan x = arctan (2 * x / (1 - x ^ 2)) + Ο€ := by rw [two_mul, arctan_add_eq_add_pi (by nlinarith) (by linarith)]; congr 2; ring theorem two_mul_arctan_sub_pi (h : x < -1) : 2 * arctan x = arctan (2 * x / (1 - x ^ 2)) - Ο€ := by rw [two_mul, arctan_add_eq_sub_pi (by nlinarith) (by linarith)]; congr 2; ring theorem arctan_inv_2_add_arctan_inv_3 : arctan 2⁻¹ + arctan 3⁻¹ = Ο€ / 4 := by rw [arctan_add] <;> norm_num theorem two_mul_arctan_inv_2_sub_arctan_inv_7 : 2 * arctan 2⁻¹ - arctan 7⁻¹ = Ο€ / 4 := by rw [two_mul_arctan, ← arctan_one, sub_eq_iff_eq_add, arctan_add] <;> norm_num theorem two_mul_arctan_inv_3_add_arctan_inv_7 : 2 * arctan 3⁻¹ + arctan 7⁻¹ = Ο€ / 4 := by rw [two_mul_arctan, arctan_add] <;> norm_num /-- **John Machin's 1706 formula**, which he used to compute Ο€ to 100 decimal places. -/ theorem four_mul_arctan_inv_5_sub_arctan_inv_239 : 4 * arctan 5⁻¹ - arctan 239⁻¹ = Ο€ / 4 := by rw [show 4 * arctan _ = 2 * (2 * _) by ring, two_mul_arctan, two_mul_arctan, ← arctan_one, sub_eq_iff_eq_add, arctan_add] <;> norm_num end ArctanAdd theorem sin_arctan_strictMono : StrictMono (sin <| arctan Β·) := fun x y h ↦ strictMonoOn_sin (Ioo_subset_Icc_self <| arctan_mem_Ioo x) (Ioo_subset_Icc_self <| arctan_mem_Ioo y) (arctan_strictMono h) @[simp] theorem sin_arctan_pos : 0 < sin (arctan x) ↔ 0 < x := by simpa using sin_arctan_strictMono.lt_iff_lt (a := 0) @[simp] theorem sin_arctan_lt_zero : sin (arctan x) < 0 ↔ x < 0 := by simpa using sin_arctan_strictMono.lt_iff_lt (b := 0) @[simp] theorem sin_arctan_eq_zero : sin (arctan x) = 0 ↔ x = 0 := sin_arctan_strictMono.injective.eq_iff' <| by simp @[simp] theorem sin_arctan_nonneg : 0 ≀ sin (arctan x) ↔ 0 ≀ x := by simpa using sin_arctan_strictMono.le_iff_le (a := 0) @[simp] theorem sin_arctan_le_zero : sin (arctan x) ≀ 0 ↔ x ≀ 0 := by simpa using sin_arctan_strictMono.le_iff_le (b := 0) @[continuity] theorem continuous_arctan : Continuous arctan := continuous_subtype_val.comp tanOrderIso.toHomeomorph.continuous_invFun theorem continuousAt_arctan : ContinuousAt arctan x := continuous_arctan.continuousAt /-- `Real.tan` as an `OpenPartialHomeomorph` between `(-(Ο€ / 2), Ο€ / 2)` and the whole line. -/ def tanPartialHomeomorph : OpenPartialHomeomorph ℝ ℝ where toFun := tan invFun := arctan source := Ioo (-(Ο€ / 2)) (Ο€ / 2) target := univ map_source' := mapsTo_univ _ _ map_target' y _ := arctan_mem_Ioo y left_inv' _ hx := arctan_tan hx.1 hx.2 right_inv' y _ := tan_arctan y open_source := isOpen_Ioo open_target := isOpen_univ continuousOn_toFun := continuousOn_tan_Ioo continuousOn_invFun := continuous_arctan.continuousOn @[simp] theorem coe_tanPartialHomeomorph : ⇑tanPartialHomeomorph = tan := rfl @[simp] theorem coe_tanPartialHomeomorph_symm : ⇑tanPartialHomeomorph.symm = arctan := rfl end Real namespace Mathlib.Meta.Positivity open Lean Meta Qq /-- Extension for `Real.arctan`. -/ @[positivity Real.arctan _] def evalRealArctan : PositivityExt where eval {u Ξ±} z p e := do match u, Ξ±, e with | 0, ~q(ℝ), ~q(Real.arctan $a) => let ra ← core z p a assumeInstancesCommute match ra with | .positive pa => return .positive q(Real.arctan_pos.mpr $pa) | .nonnegative na => return .nonnegative q(Real.arctan_nonneg.mpr $na) | .nonzero na => return .nonzero q(mt Real.arctan_eq_zero_iff.mp $na) | .none => return .none | _ => throwError "not Real.arctan" /-- Extension for `Real.cos (Real.arctan _)`. -/ @[positivity Real.cos (Real.arctan _)] def evalRealCosArctan : PositivityExt where eval {u Ξ±} _ _ e := do match u, Ξ±, e with | 0, ~q(ℝ), ~q(Real.cos (Real.arctan $a)) => assumeInstancesCommute return .positive q(Real.cos_arctan_pos _) | _ => throwError "not Real.cos (Real.arctan _)" /-- Extension for `Real.sin (Real.arctan _)`. -/ @[positivity Real.sin (Real.arctan _)] def evalRealSinArctan : PositivityExt where eval {u Ξ±} z p e := do match u, Ξ±, e with | 0, ~q(ℝ), ~q(Real.sin (Real.arctan $a)) => assumeInstancesCommute match ← core z p a with | .positive pa => return .positive q(Real.sin_arctan_pos.mpr $pa) | .nonnegative na => return .nonnegative q(Real.sin_arctan_nonneg.mpr $na) | .nonzero na => return .nonzero q(mt Real.sin_arctan_eq_zero.mp $na) | .none => return .none | _ => throwError "not Real.sin (Real.arctan _)" end Mathlib.Meta.Positivity
.lake/packages/mathlib/Mathlib/Analysis/SpecialFunctions/Trigonometric/Series.lean
import Mathlib.Analysis.Complex.Trigonometric import Mathlib.Analysis.SpecialFunctions.Exponential /-! # Trigonometric functions as sums of infinite series In this file we express trigonometric functions in terms of their series expansion. ## Main results * `Complex.hasSum_cos`, `Complex.cos_eq_tsum`: `Complex.cos` as the sum of an infinite series. * `Real.hasSum_cos`, `Real.cos_eq_tsum`: `Real.cos` as the sum of an infinite series. * `Complex.hasSum_sin`, `Complex.sin_eq_tsum`: `Complex.sin` as the sum of an infinite series. * `Real.hasSum_sin`, `Real.sin_eq_tsum`: `Real.sin` as the sum of an infinite series. -/ open NormedSpace open scoped Nat /-! ### `cos` and `sin` for `ℝ` and `β„‚` -/ section SinCos theorem Complex.hasSum_cos' (z : β„‚) : HasSum (fun n : β„• => (z * Complex.I) ^ (2 * n) / ↑(2 * n)!) (Complex.cos z) := by rw [Complex.cos, Complex.exp_eq_exp_β„‚] have := ((expSeries_div_hasSum_exp β„‚ (z * Complex.I)).add (expSeries_div_hasSum_exp β„‚ (-z * Complex.I))).div_const 2 replace := (Nat.divModEquiv 2).symm.hasSum_iff.mpr this dsimp [Function.comp_def] at this simp_rw [← mul_comm 2 _] at this refine this.prod_fiberwise fun k => ?_ dsimp only convert hasSum_fintype (_ : Fin 2 β†’ β„‚) using 1 rw [Fin.sum_univ_two] simp_rw [Fin.val_zero, Fin.val_one, add_zero, pow_succ, pow_mul, mul_pow, neg_sq, ← two_mul, neg_mul, mul_neg, neg_div, add_neg_cancel, zero_div, add_zero, mul_div_cancel_leftβ‚€ _ (two_ne_zero : (2 : β„‚) β‰  0)] theorem Complex.hasSum_sin' (z : β„‚) : HasSum (fun n : β„• => (z * Complex.I) ^ (2 * n + 1) / ↑(2 * n + 1)! / Complex.I) (Complex.sin z) := by rw [Complex.sin, Complex.exp_eq_exp_β„‚] have := (((expSeries_div_hasSum_exp β„‚ (-z * Complex.I)).sub (expSeries_div_hasSum_exp β„‚ (z * Complex.I))).mul_right Complex.I).div_const 2 replace := (Nat.divModEquiv 2).symm.hasSum_iff.mpr this dsimp [Function.comp_def] at this simp_rw [← mul_comm 2 _] at this refine this.prod_fiberwise fun k => ?_ dsimp only convert hasSum_fintype (_ : Fin 2 β†’ β„‚) using 1 rw [Fin.sum_univ_two] simp_rw [Fin.val_zero, Fin.val_one, add_zero, pow_succ, pow_mul, mul_pow, neg_sq, sub_self, zero_mul, zero_div, zero_add, neg_mul, mul_neg, neg_div, ← neg_add', ← two_mul, neg_mul, neg_div, mul_assoc, mul_div_cancel_leftβ‚€ _ (two_ne_zero : (2 : β„‚) β‰  0), Complex.div_I] /-- The power series expansion of `Complex.cos`. -/ theorem Complex.hasSum_cos (z : β„‚) : HasSum (fun n : β„• => (-1) ^ n * z ^ (2 * n) / ↑(2 * n)!) (Complex.cos z) := by convert Complex.hasSum_cos' z using 1 simp_rw [mul_pow, pow_mul, Complex.I_sq, mul_comm] /-- The power series expansion of `Complex.sin`. -/ theorem Complex.hasSum_sin (z : β„‚) : HasSum (fun n : β„• => (-1) ^ n * z ^ (2 * n + 1) / ↑(2 * n + 1)!) (Complex.sin z) := by convert Complex.hasSum_sin' z using 1 simp_rw [mul_pow, pow_succ, pow_mul, Complex.I_sq, ← mul_assoc, mul_div_assoc, div_right_comm, div_self Complex.I_ne_zero, mul_comm _ ((-1 : β„‚) ^ _), mul_one_div, mul_div_assoc, mul_assoc] theorem Complex.cos_eq_tsum' (z : β„‚) : Complex.cos z = βˆ‘' n : β„•, (z * Complex.I) ^ (2 * n) / ↑(2 * n)! := (Complex.hasSum_cos' z).tsum_eq.symm theorem Complex.sin_eq_tsum' (z : β„‚) : Complex.sin z = βˆ‘' n : β„•, (z * Complex.I) ^ (2 * n + 1) / ↑(2 * n + 1)! / Complex.I := (Complex.hasSum_sin' z).tsum_eq.symm theorem Complex.cos_eq_tsum (z : β„‚) : Complex.cos z = βˆ‘' n : β„•, (-1) ^ n * z ^ (2 * n) / ↑(2 * n)! := (Complex.hasSum_cos z).tsum_eq.symm theorem Complex.sin_eq_tsum (z : β„‚) : Complex.sin z = βˆ‘' n : β„•, (-1) ^ n * z ^ (2 * n + 1) / ↑(2 * n + 1)! := (Complex.hasSum_sin z).tsum_eq.symm /-- The power series expansion of `Real.cos`. -/ theorem Real.hasSum_cos (r : ℝ) : HasSum (fun n : β„• => (-1) ^ n * r ^ (2 * n) / ↑(2 * n)!) (Real.cos r) := mod_cast Complex.hasSum_cos r /-- The power series expansion of `Real.sin`. -/ theorem Real.hasSum_sin (r : ℝ) : HasSum (fun n : β„• => (-1) ^ n * r ^ (2 * n + 1) / ↑(2 * n + 1)!) (Real.sin r) := mod_cast Complex.hasSum_sin r theorem Real.cos_eq_tsum (r : ℝ) : Real.cos r = βˆ‘' n : β„•, (-1) ^ n * r ^ (2 * n) / ↑(2 * n)! := (Real.hasSum_cos r).tsum_eq.symm theorem Real.sin_eq_tsum (r : ℝ) : Real.sin r = βˆ‘' n : β„•, (-1) ^ n * r ^ (2 * n + 1) / ↑(2 * n + 1)! := (Real.hasSum_sin r).tsum_eq.symm end SinCos /-! ### `cosh` and `sinh` for `ℝ` and `β„‚` -/ section SinhCosh namespace Complex /-- The power series expansion of `Complex.cosh`. -/ lemma hasSum_cosh (z : β„‚) : HasSum (fun n ↦ z ^ (2 * n) / ↑(2 * n)!) (cosh z) := by simpa [mul_assoc, cos_mul_I] using hasSum_cos' (z * I) /-- The power series expansion of `Complex.sinh`. -/ lemma hasSum_sinh (z : β„‚) : HasSum (fun n ↦ z ^ (2 * n + 1) / ↑(2 * n + 1)!) (sinh z) := by simpa [mul_assoc, sin_mul_I, neg_pow z, pow_add, pow_mul, neg_mul, neg_div] using (hasSum_sin' (z * I)).mul_right (-I) lemma cosh_eq_tsum (z : β„‚) : cosh z = βˆ‘' n, z ^ (2 * n) / ↑(2 * n)! := z.hasSum_cosh.tsum_eq.symm lemma sinh_eq_tsum (z : β„‚) : sinh z = βˆ‘' n, z ^ (2 * n + 1) / ↑(2 * n + 1)! := z.hasSum_sinh.tsum_eq.symm end Complex namespace Real /-- The power series expansion of `Real.cosh`. -/ lemma hasSum_cosh (r : ℝ) : HasSum (fun n ↦ r ^ (2 * n) / ↑(2 * n)!) (cosh r) := mod_cast Complex.hasSum_cosh r /-- The power series expansion of `Real.sinh`. -/ lemma hasSum_sinh (r : ℝ) : HasSum (fun n ↦ r ^ (2 * n + 1) / ↑(2 * n + 1)!) (sinh r) := mod_cast Complex.hasSum_sinh r lemma cosh_eq_tsum (r : ℝ) : cosh r = βˆ‘' n, r ^ (2 * n) / ↑(2 * n)! := r.hasSum_cosh.tsum_eq.symm lemma sinh_eq_tsum (r : ℝ) : sinh r = βˆ‘' n, r ^ (2 * n + 1) / ↑(2 * n + 1)! := r.hasSum_sinh.tsum_eq.symm lemma cosh_le_exp_half_sq (x : ℝ) : cosh x ≀ exp (x ^ 2 / 2) := by rw [cosh_eq_tsum, exp_eq_exp_ℝ, exp_eq_tsum] refine x.hasSum_cosh.summable.tsum_le_tsum (fun i ↦ ?_) <| expSeries_summable' (x ^ 2 / 2) simp only [div_pow, pow_mul, smul_eq_mul, inv_mul_eq_div, div_div] gcongr norm_cast exact Nat.two_pow_mul_factorial_le_factorial_two_mul _ end Real end SinhCosh
.lake/packages/mathlib/Mathlib/Analysis/SpecialFunctions/Trigonometric/Angle.lean
import Mathlib.Analysis.SpecialFunctions.Trigonometric.Basic import Mathlib.Analysis.Normed.Group.AddCircle import Mathlib.Algebra.CharZero.Quotient import Mathlib.Topology.Instances.Sign /-! # The type of angles In this file we define `Real.Angle` to be the quotient group `ℝ/2Ο€β„€` and prove a few simple lemmas about trigonometric functions and angles. -/ open Real noncomputable section namespace Real /-- The type of angles -/ def Angle : Type := AddCircle (2 * Ο€) deriving NormedAddCommGroup, Inhabited namespace Angle /-- The canonical map from `ℝ` to the quotient `Angle`. -/ @[coe] protected def coe (r : ℝ) : Angle := QuotientAddGroup.mk r instance : Coe ℝ Angle := ⟨Angle.coe⟩ instance : CircularOrder Real.Angle := QuotientAddGroup.circularOrder (hp' := ⟨by simp [pi_pos]⟩) @[continuity] theorem continuous_coe : Continuous ((↑) : ℝ β†’ Angle) := continuous_quotient_mk' /-- Coercion `ℝ β†’ Angle` as an additive homomorphism. -/ def coeHom : ℝ β†’+ Angle := QuotientAddGroup.mk' _ @[simp] theorem coe_coeHom : (coeHom : ℝ β†’ Angle) = ((↑) : ℝ β†’ Angle) := rfl /-- An induction principle to deduce results for `Angle` from those for `ℝ`, used with `induction ΞΈ using Real.Angle.induction_on`. -/ @[elab_as_elim] protected theorem induction_on {p : Angle β†’ Prop} (ΞΈ : Angle) (h : βˆ€ x : ℝ, p x) : p ΞΈ := Quotient.inductionOn' ΞΈ h @[simp] theorem coe_zero : ↑(0 : ℝ) = (0 : Angle) := rfl @[simp] theorem coe_add (x y : ℝ) : ↑(x + y : ℝ) = (↑x + ↑y : Angle) := rfl @[simp] theorem coe_neg (x : ℝ) : ↑(-x : ℝ) = -(↑x : Angle) := rfl @[simp] theorem coe_sub (x y : ℝ) : ↑(x - y : ℝ) = (↑x - ↑y : Angle) := rfl theorem coe_nsmul (n : β„•) (x : ℝ) : ↑(n β€’ x : ℝ) = n β€’ (↑x : Angle) := rfl theorem coe_zsmul (z : β„€) (x : ℝ) : ↑(z β€’ x : ℝ) = z β€’ (↑x : Angle) := rfl theorem coe_eq_zero_iff {x : ℝ} : (x : Angle) = 0 ↔ βˆƒ n : β„€, n β€’ (2 * Ο€) = x := AddCircle.coe_eq_zero_iff (2 * Ο€) @[simp, norm_cast] theorem natCast_mul_eq_nsmul (x : ℝ) (n : β„•) : ↑((n : ℝ) * x) = n β€’ (↑x : Angle) := by simpa only [nsmul_eq_mul] using coeHom.map_nsmul x n @[simp, norm_cast] theorem intCast_mul_eq_zsmul (x : ℝ) (n : β„€) : ↑((n : ℝ) * x : ℝ) = n β€’ (↑x : Angle) := by simpa only [zsmul_eq_mul] using coeHom.map_zsmul x n theorem angle_eq_iff_two_pi_dvd_sub {ψ ΞΈ : ℝ} : (ΞΈ : Angle) = ψ ↔ βˆƒ k : β„€, ΞΈ - ψ = 2 * Ο€ * k := by simp only [eq_comm] rw [Angle.coe, Angle.coe, QuotientAddGroup.eq] simp only [AddSubgroup.zmultiples_eq_closure, AddSubgroup.mem_closure_singleton, zsmul_eq_mul', (sub_eq_neg_add _ _).symm, eq_comm] @[simp] theorem coe_two_pi : ↑(2 * Ο€ : ℝ) = (0 : Angle) := angle_eq_iff_two_pi_dvd_sub.2 ⟨1, by rw [sub_zero, Int.cast_one, mul_one]⟩ @[simp] theorem neg_coe_pi : -(Ο€ : Angle) = Ο€ := by rw [← coe_neg, angle_eq_iff_two_pi_dvd_sub] use -1 simp [two_mul, sub_eq_add_neg] @[simp] theorem two_nsmul_coe_div_two (ΞΈ : ℝ) : (2 : β„•) β€’ (↑(ΞΈ / 2) : Angle) = ΞΈ := by rw [← coe_nsmul, two_nsmul, add_halves] @[simp] theorem two_zsmul_coe_div_two (ΞΈ : ℝ) : (2 : β„€) β€’ (↑(ΞΈ / 2) : Angle) = ΞΈ := by rw [← coe_zsmul, two_zsmul, add_halves] theorem two_nsmul_neg_pi_div_two : (2 : β„•) β€’ (↑(-Ο€ / 2) : Angle) = Ο€ := by rw [two_nsmul_coe_div_two, coe_neg, neg_coe_pi] theorem two_zsmul_neg_pi_div_two : (2 : β„€) β€’ (↑(-Ο€ / 2) : Angle) = Ο€ := by rw [two_zsmul, ← two_nsmul, two_nsmul_neg_pi_div_two] theorem sub_coe_pi_eq_add_coe_pi (ΞΈ : Angle) : ΞΈ - Ο€ = ΞΈ + Ο€ := by rw [sub_eq_add_neg, neg_coe_pi] @[simp] theorem two_nsmul_coe_pi : (2 : β„•) β€’ (Ο€ : Angle) = 0 := by simp [← natCast_mul_eq_nsmul] @[simp] theorem two_zsmul_coe_pi : (2 : β„€) β€’ (Ο€ : Angle) = 0 := by simp [← intCast_mul_eq_zsmul] @[simp] theorem coe_pi_add_coe_pi : (Ο€ : Real.Angle) + Ο€ = 0 := by rw [← two_nsmul, two_nsmul_coe_pi] theorem zsmul_eq_iff {ψ ΞΈ : Angle} {z : β„€} (hz : z β‰  0) : z β€’ ψ = z β€’ ΞΈ ↔ βˆƒ k : Fin z.natAbs, ψ = ΞΈ + (k : β„•) β€’ (2 * Ο€ / z : ℝ) := QuotientAddGroup.zmultiples_zsmul_eq_zsmul_iff hz theorem nsmul_eq_iff {ψ ΞΈ : Angle} {n : β„•} (hz : n β‰  0) : n β€’ ψ = n β€’ ΞΈ ↔ βˆƒ k : Fin n, ψ = ΞΈ + (k : β„•) β€’ (2 * Ο€ / n : ℝ) := QuotientAddGroup.zmultiples_nsmul_eq_nsmul_iff hz theorem two_zsmul_eq_iff {ψ ΞΈ : Angle} : (2 : β„€) β€’ ψ = (2 : β„€) β€’ ΞΈ ↔ ψ = ΞΈ ∨ ψ = ΞΈ + ↑π := by have : Int.natAbs 2 = 2 := rfl rw [zsmul_eq_iff two_ne_zero, this, Fin.exists_fin_two, Fin.val_zero, Fin.val_one, zero_smul, add_zero, one_smul, Int.cast_two, mul_div_cancel_leftβ‚€ (_ : ℝ) two_ne_zero] theorem two_nsmul_eq_iff {ψ ΞΈ : Angle} : (2 : β„•) β€’ ψ = (2 : β„•) β€’ ΞΈ ↔ ψ = ΞΈ ∨ ψ = ΞΈ + ↑π := by simp_rw [← natCast_zsmul, Nat.cast_ofNat, two_zsmul_eq_iff] theorem two_nsmul_eq_zero_iff {ΞΈ : Angle} : (2 : β„•) β€’ ΞΈ = 0 ↔ ΞΈ = 0 ∨ ΞΈ = Ο€ := by convert two_nsmul_eq_iff <;> simp theorem two_nsmul_ne_zero_iff {ΞΈ : Angle} : (2 : β„•) β€’ ΞΈ β‰  0 ↔ ΞΈ β‰  0 ∧ ΞΈ β‰  Ο€ := by rw [← not_or, ← two_nsmul_eq_zero_iff] theorem two_zsmul_eq_zero_iff {ΞΈ : Angle} : (2 : β„€) β€’ ΞΈ = 0 ↔ ΞΈ = 0 ∨ ΞΈ = Ο€ := by simp_rw [two_zsmul, ← two_nsmul, two_nsmul_eq_zero_iff] theorem two_zsmul_ne_zero_iff {ΞΈ : Angle} : (2 : β„€) β€’ ΞΈ β‰  0 ↔ ΞΈ β‰  0 ∧ ΞΈ β‰  Ο€ := by rw [← not_or, ← two_zsmul_eq_zero_iff] theorem eq_neg_self_iff {ΞΈ : Angle} : ΞΈ = -ΞΈ ↔ ΞΈ = 0 ∨ ΞΈ = Ο€ := by rw [← add_eq_zero_iff_eq_neg, ← two_nsmul, two_nsmul_eq_zero_iff] theorem ne_neg_self_iff {ΞΈ : Angle} : ΞΈ β‰  -ΞΈ ↔ ΞΈ β‰  0 ∧ ΞΈ β‰  Ο€ := by rw [← not_or, ← eq_neg_self_iff.not] theorem neg_eq_self_iff {ΞΈ : Angle} : -ΞΈ = ΞΈ ↔ ΞΈ = 0 ∨ ΞΈ = Ο€ := by rw [eq_comm, eq_neg_self_iff] theorem neg_ne_self_iff {ΞΈ : Angle} : -ΞΈ β‰  ΞΈ ↔ ΞΈ β‰  0 ∧ ΞΈ β‰  Ο€ := by rw [← not_or, ← neg_eq_self_iff.not] theorem two_nsmul_eq_pi_iff {ΞΈ : Angle} : (2 : β„•) β€’ ΞΈ = Ο€ ↔ ΞΈ = (Ο€ / 2 : ℝ) ∨ ΞΈ = (-Ο€ / 2 : ℝ) := by have h : (Ο€ : Angle) = ((2 : β„•) β€’ (Ο€ / 2 : ℝ):) := by rw [two_nsmul, add_halves] nth_rw 1 [h] rw [coe_nsmul, two_nsmul_eq_iff] apply iff_of_eq -- `congr` only works on `Eq`, so rewrite from `Iff` to `Eq`. congr rw [add_comm, ← coe_add, ← sub_eq_zero, ← coe_sub, neg_div, sub_neg_eq_add, add_assoc, add_halves, ← two_mul, coe_two_pi] theorem two_zsmul_eq_pi_iff {ΞΈ : Angle} : (2 : β„€) β€’ ΞΈ = Ο€ ↔ ΞΈ = (Ο€ / 2 : ℝ) ∨ ΞΈ = (-Ο€ / 2 : ℝ) := by rw [two_zsmul, ← two_nsmul, two_nsmul_eq_pi_iff] theorem cos_eq_iff_coe_eq_or_eq_neg {ΞΈ ψ : ℝ} : cos ΞΈ = cos ψ ↔ (ΞΈ : Angle) = ψ ∨ (ΞΈ : Angle) = -ψ := by constructor Β· intro Hcos rw [← sub_eq_zero, cos_sub_cos, mul_eq_zero, mul_eq_zero, neg_eq_zero, eq_false (two_ne_zero' ℝ), false_or, sin_eq_zero_iff, sin_eq_zero_iff] at Hcos rcases Hcos with (⟨n, hn⟩ | ⟨n, hn⟩) Β· right rw [eq_div_iff_mul_eq (two_ne_zero' ℝ), ← sub_eq_iff_eq_add] at hn rw [← hn, coe_sub, eq_neg_iff_add_eq_zero, sub_add_cancel, mul_assoc, intCast_mul_eq_zsmul, mul_comm, coe_two_pi, zsmul_zero] Β· left rw [eq_div_iff_mul_eq (two_ne_zero' ℝ), eq_sub_iff_add_eq] at hn rw [← hn, coe_add, mul_assoc, intCast_mul_eq_zsmul, mul_comm, coe_two_pi, zsmul_zero, zero_add] Β· rw [angle_eq_iff_two_pi_dvd_sub, ← coe_neg, angle_eq_iff_two_pi_dvd_sub] rintro (⟨k, H⟩ | ⟨k, H⟩) Β· rw [← sub_eq_zero, cos_sub_cos, H, mul_assoc 2 Ο€ k, mul_div_cancel_leftβ‚€ _ (two_ne_zero' ℝ), mul_comm Ο€ _, sin_int_mul_pi, mul_zero] rw [← sub_eq_zero, cos_sub_cos, ← sub_neg_eq_add, H, mul_assoc 2 Ο€ k, mul_div_cancel_leftβ‚€ _ (two_ne_zero' ℝ), mul_comm Ο€ _, sin_int_mul_pi, mul_zero, zero_mul] theorem sin_eq_iff_coe_eq_or_add_eq_pi {ΞΈ ψ : ℝ} : sin ΞΈ = sin ψ ↔ (ΞΈ : Angle) = ψ ∨ (ΞΈ : Angle) + ψ = Ο€ := by constructor Β· intro Hsin rw [← cos_pi_div_two_sub, ← cos_pi_div_two_sub] at Hsin rcases cos_eq_iff_coe_eq_or_eq_neg.mp Hsin with h | h Β· left rw [coe_sub, coe_sub] at h exact sub_right_inj.1 h right rw [coe_sub, coe_sub, eq_neg_iff_add_eq_zero, add_sub, sub_add_eq_add_sub, ← coe_add, add_halves, sub_sub, sub_eq_zero] at h exact h.symm Β· rw [angle_eq_iff_two_pi_dvd_sub, ← eq_sub_iff_add_eq, ← coe_sub, angle_eq_iff_two_pi_dvd_sub] rintro (⟨k, H⟩ | ⟨k, H⟩) Β· rw [← sub_eq_zero, sin_sub_sin, H, mul_assoc 2 Ο€ k, mul_div_cancel_leftβ‚€ _ (two_ne_zero' ℝ), mul_comm Ο€ _, sin_int_mul_pi, mul_zero, zero_mul] have H' : ΞΈ + ψ = 2 * k * Ο€ + Ο€ := by rwa [← sub_add, sub_add_eq_add_sub, sub_eq_iff_eq_add, mul_assoc, mul_comm Ο€ _, ← mul_assoc] at H rw [← sub_eq_zero, sin_sub_sin, H', add_div, mul_assoc 2 _ Ο€, mul_div_cancel_leftβ‚€ _ (two_ne_zero' ℝ), cos_add_pi_div_two, sin_int_mul_pi, neg_zero, mul_zero] theorem cos_sin_inj {ΞΈ ψ : ℝ} (Hcos : cos ΞΈ = cos ψ) (Hsin : sin ΞΈ = sin ψ) : (ΞΈ : Angle) = ψ := by rcases cos_eq_iff_coe_eq_or_eq_neg.mp Hcos with hc | hc; Β· exact hc rcases sin_eq_iff_coe_eq_or_add_eq_pi.mp Hsin with hs | hs; Β· exact hs rw [eq_neg_iff_add_eq_zero, hs] at hc obtain ⟨n, hn⟩ : βˆƒ n, n β€’ _ = _ := QuotientAddGroup.leftRel_apply.mp (Quotient.exact' hc) rw [← neg_one_mul, add_zero, ← sub_eq_zero, zsmul_eq_mul, ← mul_assoc, ← sub_mul, mul_eq_zero, eq_false (ne_of_gt pi_pos), or_false, sub_neg_eq_add, ← Int.cast_zero, ← Int.cast_one, ← Int.cast_ofNat, ← Int.cast_mul, ← Int.cast_add, Int.cast_inj] at hn have : (n * 2 + 1) % (2 : β„€) = 0 % (2 : β„€) := congr_arg (Β· % (2 : β„€)) hn rw [add_comm, Int.add_mul_emod_self_right] at this exact absurd this one_ne_zero /-- The sine of a `Real.Angle`. -/ def sin (ΞΈ : Angle) : ℝ := sin_periodic.lift ΞΈ @[simp] theorem sin_coe (x : ℝ) : sin (x : Angle) = Real.sin x := rfl @[continuity] theorem continuous_sin : Continuous sin := Real.continuous_sin.quotient_liftOn' _ /-- The cosine of a `Real.Angle`. -/ def cos (ΞΈ : Angle) : ℝ := cos_periodic.lift ΞΈ @[simp] theorem cos_coe (x : ℝ) : cos (x : Angle) = Real.cos x := rfl @[continuity] theorem continuous_cos : Continuous cos := Real.continuous_cos.quotient_liftOn' _ theorem cos_eq_real_cos_iff_eq_or_eq_neg {ΞΈ : Angle} {ψ : ℝ} : cos ΞΈ = Real.cos ψ ↔ ΞΈ = ψ ∨ ΞΈ = -ψ := by induction ΞΈ using Real.Angle.induction_on exact cos_eq_iff_coe_eq_or_eq_neg theorem cos_eq_iff_eq_or_eq_neg {ΞΈ ψ : Angle} : cos ΞΈ = cos ψ ↔ ΞΈ = ψ ∨ ΞΈ = -ψ := by induction ψ using Real.Angle.induction_on exact cos_eq_real_cos_iff_eq_or_eq_neg theorem sin_eq_real_sin_iff_eq_or_add_eq_pi {ΞΈ : Angle} {ψ : ℝ} : sin ΞΈ = Real.sin ψ ↔ ΞΈ = ψ ∨ ΞΈ + ψ = Ο€ := by induction ΞΈ using Real.Angle.induction_on exact sin_eq_iff_coe_eq_or_add_eq_pi theorem sin_eq_iff_eq_or_add_eq_pi {ΞΈ ψ : Angle} : sin ΞΈ = sin ψ ↔ ΞΈ = ψ ∨ ΞΈ + ψ = Ο€ := by induction ψ using Real.Angle.induction_on exact sin_eq_real_sin_iff_eq_or_add_eq_pi @[simp] theorem sin_zero : sin (0 : Angle) = 0 := by rw [← coe_zero, sin_coe, Real.sin_zero] theorem sin_coe_pi : sin (Ο€ : Angle) = 0 := by rw [sin_coe, Real.sin_pi] theorem sin_eq_zero_iff {ΞΈ : Angle} : sin ΞΈ = 0 ↔ ΞΈ = 0 ∨ ΞΈ = Ο€ := by nth_rw 1 [← sin_zero] rw [sin_eq_iff_eq_or_add_eq_pi] simp theorem sin_ne_zero_iff {ΞΈ : Angle} : sin ΞΈ β‰  0 ↔ ΞΈ β‰  0 ∧ ΞΈ β‰  Ο€ := by rw [← not_or, ← sin_eq_zero_iff] @[simp] theorem sin_neg (ΞΈ : Angle) : sin (-ΞΈ) = -sin ΞΈ := by induction ΞΈ using Real.Angle.induction_on exact Real.sin_neg _ theorem sin_antiperiodic : Function.Antiperiodic sin (Ο€ : Angle) := by intro ΞΈ induction ΞΈ using Real.Angle.induction_on exact Real.sin_antiperiodic _ @[simp] theorem sin_add_pi (ΞΈ : Angle) : sin (ΞΈ + Ο€) = -sin ΞΈ := sin_antiperiodic ΞΈ @[simp] theorem sin_sub_pi (ΞΈ : Angle) : sin (ΞΈ - Ο€) = -sin ΞΈ := sin_antiperiodic.sub_eq ΞΈ @[simp] theorem cos_zero : cos (0 : Angle) = 1 := by rw [← coe_zero, cos_coe, Real.cos_zero] theorem cos_coe_pi : cos (Ο€ : Angle) = -1 := by rw [cos_coe, Real.cos_pi] @[simp] theorem cos_neg (ΞΈ : Angle) : cos (-ΞΈ) = cos ΞΈ := by induction ΞΈ using Real.Angle.induction_on exact Real.cos_neg _ theorem cos_antiperiodic : Function.Antiperiodic cos (Ο€ : Angle) := by intro ΞΈ induction ΞΈ using Real.Angle.induction_on exact Real.cos_antiperiodic _ @[simp] theorem cos_add_pi (ΞΈ : Angle) : cos (ΞΈ + Ο€) = -cos ΞΈ := cos_antiperiodic ΞΈ @[simp] theorem cos_sub_pi (ΞΈ : Angle) : cos (ΞΈ - Ο€) = -cos ΞΈ := cos_antiperiodic.sub_eq ΞΈ theorem cos_eq_zero_iff {ΞΈ : Angle} : cos ΞΈ = 0 ↔ ΞΈ = (Ο€ / 2 : ℝ) ∨ ΞΈ = (-Ο€ / 2 : ℝ) := by rw [← cos_pi_div_two, ← cos_coe, cos_eq_iff_eq_or_eq_neg, ← coe_neg, ← neg_div] theorem sin_add (θ₁ ΞΈβ‚‚ : Real.Angle) : sin (θ₁ + ΞΈβ‚‚) = sin θ₁ * cos ΞΈβ‚‚ + cos θ₁ * sin ΞΈβ‚‚ := by induction θ₁ using Real.Angle.induction_on induction ΞΈβ‚‚ using Real.Angle.induction_on exact Real.sin_add _ _ theorem cos_add (θ₁ ΞΈβ‚‚ : Real.Angle) : cos (θ₁ + ΞΈβ‚‚) = cos θ₁ * cos ΞΈβ‚‚ - sin θ₁ * sin ΞΈβ‚‚ := by induction ΞΈβ‚‚ using Real.Angle.induction_on induction θ₁ using Real.Angle.induction_on exact Real.cos_add _ _ @[simp] theorem cos_sq_add_sin_sq (ΞΈ : Real.Angle) : cos ΞΈ ^ 2 + sin ΞΈ ^ 2 = 1 := by induction ΞΈ using Real.Angle.induction_on exact Real.cos_sq_add_sin_sq _ theorem sin_add_pi_div_two (ΞΈ : Angle) : sin (ΞΈ + ↑(Ο€ / 2)) = cos ΞΈ := by induction ΞΈ using Real.Angle.induction_on exact Real.sin_add_pi_div_two _ theorem sin_sub_pi_div_two (ΞΈ : Angle) : sin (ΞΈ - ↑(Ο€ / 2)) = -cos ΞΈ := by induction ΞΈ using Real.Angle.induction_on exact Real.sin_sub_pi_div_two _ theorem sin_pi_div_two_sub (ΞΈ : Angle) : sin (↑(Ο€ / 2) - ΞΈ) = cos ΞΈ := by induction ΞΈ using Real.Angle.induction_on exact Real.sin_pi_div_two_sub _ theorem cos_add_pi_div_two (ΞΈ : Angle) : cos (ΞΈ + ↑(Ο€ / 2)) = -sin ΞΈ := by induction ΞΈ using Real.Angle.induction_on exact Real.cos_add_pi_div_two _ theorem cos_sub_pi_div_two (ΞΈ : Angle) : cos (ΞΈ - ↑(Ο€ / 2)) = sin ΞΈ := by induction ΞΈ using Real.Angle.induction_on exact Real.cos_sub_pi_div_two _ theorem cos_pi_div_two_sub (ΞΈ : Angle) : cos (↑(Ο€ / 2) - ΞΈ) = sin ΞΈ := by induction ΞΈ using Real.Angle.induction_on exact Real.cos_pi_div_two_sub _ theorem abs_sin_eq_of_two_nsmul_eq {ΞΈ ψ : Angle} (h : (2 : β„•) β€’ ΞΈ = (2 : β„•) β€’ ψ) : |sin ΞΈ| = |sin ψ| := by rw [two_nsmul_eq_iff] at h rcases h with (rfl | rfl) Β· rfl Β· rw [sin_add_pi, abs_neg] theorem abs_sin_eq_of_two_zsmul_eq {ΞΈ ψ : Angle} (h : (2 : β„€) β€’ ΞΈ = (2 : β„€) β€’ ψ) : |sin ΞΈ| = |sin ψ| := by simp_rw [two_zsmul, ← two_nsmul] at h exact abs_sin_eq_of_two_nsmul_eq h theorem abs_cos_eq_of_two_nsmul_eq {ΞΈ ψ : Angle} (h : (2 : β„•) β€’ ΞΈ = (2 : β„•) β€’ ψ) : |cos ΞΈ| = |cos ψ| := by rw [two_nsmul_eq_iff] at h rcases h with (rfl | rfl) Β· rfl Β· rw [cos_add_pi, abs_neg] theorem abs_cos_eq_of_two_zsmul_eq {ΞΈ ψ : Angle} (h : (2 : β„€) β€’ ΞΈ = (2 : β„€) β€’ ψ) : |cos ΞΈ| = |cos ψ| := by simp_rw [two_zsmul, ← two_nsmul] at h exact abs_cos_eq_of_two_nsmul_eq h @[simp] theorem coe_toIcoMod (ΞΈ ψ : ℝ) : ↑(toIcoMod two_pi_pos ψ ΞΈ) = (ΞΈ : Angle) := by rw [angle_eq_iff_two_pi_dvd_sub] refine ⟨-toIcoDiv two_pi_pos ψ ΞΈ, ?_⟩ rw [toIcoMod_sub_self, zsmul_eq_mul, mul_comm] @[simp] theorem coe_toIocMod (ΞΈ ψ : ℝ) : ↑(toIocMod two_pi_pos ψ ΞΈ) = (ΞΈ : Angle) := by rw [angle_eq_iff_two_pi_dvd_sub] refine ⟨-toIocDiv two_pi_pos ψ ΞΈ, ?_⟩ rw [toIocMod_sub_self, zsmul_eq_mul, mul_comm] /-- Convert a `Real.Angle` to a real number in the interval `Ioc (-Ο€) Ο€`. -/ def toReal (ΞΈ : Angle) : ℝ := (toIocMod_periodic two_pi_pos (-Ο€)).lift ΞΈ theorem toReal_coe (ΞΈ : ℝ) : (ΞΈ : Angle).toReal = toIocMod two_pi_pos (-Ο€) ΞΈ := rfl theorem toReal_coe_eq_self_iff {ΞΈ : ℝ} : (ΞΈ : Angle).toReal = ΞΈ ↔ -Ο€ < ΞΈ ∧ ΞΈ ≀ Ο€ := by rw [toReal_coe, toIocMod_eq_self two_pi_pos] ring_nf rfl theorem toReal_coe_eq_self_iff_mem_Ioc {ΞΈ : ℝ} : (ΞΈ : Angle).toReal = ΞΈ ↔ ΞΈ ∈ Set.Ioc (-Ο€) Ο€ := by rw [toReal_coe_eq_self_iff, ← Set.mem_Ioc] theorem toReal_injective : Function.Injective toReal := by intro ΞΈ ψ h induction ΞΈ using Real.Angle.induction_on induction ψ using Real.Angle.induction_on simpa [toReal_coe, toIocMod_eq_toIocMod, zsmul_eq_mul, mul_comm _ (2 * Ο€), ← angle_eq_iff_two_pi_dvd_sub, eq_comm] using h @[simp] theorem toReal_inj {ΞΈ ψ : Angle} : ΞΈ.toReal = ψ.toReal ↔ ΞΈ = ψ := toReal_injective.eq_iff @[simp] theorem coe_toReal (ΞΈ : Angle) : (ΞΈ.toReal : Angle) = ΞΈ := by induction ΞΈ using Real.Angle.induction_on exact coe_toIocMod _ _ theorem neg_pi_lt_toReal (ΞΈ : Angle) : -Ο€ < ΞΈ.toReal := by induction ΞΈ using Real.Angle.induction_on exact left_lt_toIocMod _ _ _ theorem toReal_le_pi (ΞΈ : Angle) : ΞΈ.toReal ≀ Ο€ := by induction ΞΈ using Real.Angle.induction_on convert toIocMod_le_right two_pi_pos _ _ ring theorem abs_toReal_le_pi (ΞΈ : Angle) : |ΞΈ.toReal| ≀ Ο€ := abs_le.2 ⟨(neg_pi_lt_toReal _).le, toReal_le_pi _⟩ theorem toReal_mem_Ioc (ΞΈ : Angle) : ΞΈ.toReal ∈ Set.Ioc (-Ο€) Ο€ := ⟨neg_pi_lt_toReal _, toReal_le_pi _⟩ @[simp] theorem toIocMod_toReal (ΞΈ : Angle) : toIocMod two_pi_pos (-Ο€) ΞΈ.toReal = ΞΈ.toReal := by induction ΞΈ using Real.Angle.induction_on rw [toReal_coe] exact toIocMod_toIocMod _ _ _ _ @[simp] theorem toReal_zero : (0 : Angle).toReal = 0 := by rw [← coe_zero, toReal_coe_eq_self_iff] exact ⟨Left.neg_neg_iff.2 Real.pi_pos, Real.pi_pos.le⟩ @[simp] theorem toReal_eq_zero_iff {ΞΈ : Angle} : ΞΈ.toReal = 0 ↔ ΞΈ = 0 := by nth_rw 1 [← toReal_zero] exact toReal_inj @[simp] theorem toReal_pi : (Ο€ : Angle).toReal = Ο€ := by rw [toReal_coe_eq_self_iff] exact ⟨Left.neg_lt_self Real.pi_pos, le_refl _⟩ @[simp] theorem toReal_eq_pi_iff {ΞΈ : Angle} : ΞΈ.toReal = Ο€ ↔ ΞΈ = Ο€ := by rw [← toReal_inj, toReal_pi] lemma toReal_neg_eq_neg_toReal_iff {ΞΈ : Angle} : (-ΞΈ).toReal = -(ΞΈ.toReal) ↔ ΞΈ β‰  Ο€ := by nth_rw 1 [← coe_toReal ΞΈ, ← coe_neg, toReal_coe_eq_self_iff] constructor Β· rintro ⟨h, h'⟩ rfl simp at h Β· intro h rw [neg_lt_neg_iff] have h' : ΞΈ.toReal β‰  Ο€ := by simp [h] exact ⟨(toReal_le_pi ΞΈ).lt_of_ne h', by linarith [neg_pi_lt_toReal ΞΈ]⟩ theorem pi_ne_zero : (Ο€ : Angle) β‰  0 := by rw [← toReal_injective.ne_iff, toReal_pi, toReal_zero] exact Real.pi_ne_zero @[simp] theorem toReal_pi_div_two : ((Ο€ / 2 : ℝ) : Angle).toReal = Ο€ / 2 := toReal_coe_eq_self_iff.2 <| by constructor <;> linarith [pi_pos] @[simp] theorem toReal_eq_pi_div_two_iff {ΞΈ : Angle} : ΞΈ.toReal = Ο€ / 2 ↔ ΞΈ = (Ο€ / 2 : ℝ) := by rw [← toReal_inj, toReal_pi_div_two] @[simp] theorem toReal_neg_pi_div_two : ((-Ο€ / 2 : ℝ) : Angle).toReal = -Ο€ / 2 := toReal_coe_eq_self_iff.2 <| by constructor <;> linarith [pi_pos] @[simp] theorem toReal_eq_neg_pi_div_two_iff {ΞΈ : Angle} : ΞΈ.toReal = -Ο€ / 2 ↔ ΞΈ = (-Ο€ / 2 : ℝ) := by rw [← toReal_inj, toReal_neg_pi_div_two] theorem pi_div_two_ne_zero : ((Ο€ / 2 : ℝ) : Angle) β‰  0 := by rw [← toReal_injective.ne_iff, toReal_pi_div_two, toReal_zero] exact div_ne_zero Real.pi_ne_zero two_ne_zero theorem neg_pi_div_two_ne_zero : ((-Ο€ / 2 : ℝ) : Angle) β‰  0 := by rw [← toReal_injective.ne_iff, toReal_neg_pi_div_two, toReal_zero] exact div_ne_zero (neg_ne_zero.2 Real.pi_ne_zero) two_ne_zero theorem abs_toReal_coe_eq_self_iff {ΞΈ : ℝ} : |(ΞΈ : Angle).toReal| = ΞΈ ↔ 0 ≀ ΞΈ ∧ ΞΈ ≀ Ο€ := ⟨fun h => h β–Έ ⟨abs_nonneg _, abs_toReal_le_pi _⟩, fun h => (toReal_coe_eq_self_iff.2 ⟨(Left.neg_neg_iff.2 Real.pi_pos).trans_le h.1, h.2⟩).symm β–Έ abs_eq_self.2 h.1⟩ theorem abs_toReal_neg_coe_eq_self_iff {ΞΈ : ℝ} : |(-ΞΈ : Angle).toReal| = ΞΈ ↔ 0 ≀ ΞΈ ∧ ΞΈ ≀ Ο€ := by refine ⟨fun h => h β–Έ ⟨abs_nonneg _, abs_toReal_le_pi _⟩, fun h => ?_⟩ by_cases hnegpi : ΞΈ = Ο€; Β· simp [hnegpi, Real.pi_pos.le] rw [← coe_neg, toReal_coe_eq_self_iff.2 ⟨neg_lt_neg (lt_of_le_of_ne h.2 hnegpi), (neg_nonpos.2 h.1).trans Real.pi_pos.le⟩, abs_neg, abs_eq_self.2 h.1] theorem abs_toReal_eq_pi_div_two_iff {ΞΈ : Angle} : |ΞΈ.toReal| = Ο€ / 2 ↔ ΞΈ = (Ο€ / 2 : ℝ) ∨ ΞΈ = (-Ο€ / 2 : ℝ) := by rw [abs_eq (div_nonneg Real.pi_pos.le two_pos.le), ← neg_div, toReal_eq_pi_div_two_iff, toReal_eq_neg_pi_div_two_iff] theorem nsmul_toReal_eq_mul {n : β„•} (h : n β‰  0) {ΞΈ : Angle} : (n β€’ ΞΈ).toReal = n * ΞΈ.toReal ↔ ΞΈ.toReal ∈ Set.Ioc (-Ο€ / n) (Ο€ / n) := by nth_rw 1 [← coe_toReal ΞΈ] have h' : 0 < (n : ℝ) := mod_cast Nat.pos_of_ne_zero h rw [← coe_nsmul, nsmul_eq_mul, toReal_coe_eq_self_iff, Set.mem_Ioc, div_lt_iffβ‚€' h', le_div_iffβ‚€' h'] theorem two_nsmul_toReal_eq_two_mul {ΞΈ : Angle} : ((2 : β„•) β€’ ΞΈ).toReal = 2 * ΞΈ.toReal ↔ ΞΈ.toReal ∈ Set.Ioc (-Ο€ / 2) (Ο€ / 2) := mod_cast nsmul_toReal_eq_mul two_ne_zero theorem two_zsmul_toReal_eq_two_mul {ΞΈ : Angle} : ((2 : β„€) β€’ ΞΈ).toReal = 2 * ΞΈ.toReal ↔ ΞΈ.toReal ∈ Set.Ioc (-Ο€ / 2) (Ο€ / 2) := by rw [two_zsmul, ← two_nsmul, two_nsmul_toReal_eq_two_mul] theorem toReal_coe_eq_self_sub_two_mul_int_mul_pi_iff {ΞΈ : ℝ} {k : β„€} : (ΞΈ : Angle).toReal = ΞΈ - 2 * k * Ο€ ↔ ΞΈ ∈ Set.Ioc ((2 * k - 1 : ℝ) * Ο€) ((2 * k + 1) * Ο€) := by rw [← sub_zero (ΞΈ : Angle), ← zsmul_zero k, ← coe_two_pi, ← coe_zsmul, ← coe_sub, zsmul_eq_mul, ← mul_assoc, mul_comm (k : ℝ), toReal_coe_eq_self_iff, Set.mem_Ioc] exact ⟨fun h => ⟨by linarith, by linarith⟩, fun h => ⟨by linarith, by linarith⟩⟩ theorem toReal_coe_eq_self_sub_two_pi_iff {ΞΈ : ℝ} : (ΞΈ : Angle).toReal = ΞΈ - 2 * Ο€ ↔ ΞΈ ∈ Set.Ioc Ο€ (3 * Ο€) := by convert @toReal_coe_eq_self_sub_two_mul_int_mul_pi_iff ΞΈ 1 <;> norm_num theorem toReal_coe_eq_self_add_two_pi_iff {ΞΈ : ℝ} : (ΞΈ : Angle).toReal = ΞΈ + 2 * Ο€ ↔ ΞΈ ∈ Set.Ioc (-3 * Ο€) (-Ο€) := by convert @toReal_coe_eq_self_sub_two_mul_int_mul_pi_iff ΞΈ (-1) using 2 <;> norm_num theorem two_nsmul_toReal_eq_two_mul_sub_two_pi {ΞΈ : Angle} : ((2 : β„•) β€’ ΞΈ).toReal = 2 * ΞΈ.toReal - 2 * Ο€ ↔ Ο€ / 2 < ΞΈ.toReal := by nth_rw 1 [← coe_toReal ΞΈ] rw [← coe_nsmul, two_nsmul, ← two_mul, toReal_coe_eq_self_sub_two_pi_iff, Set.mem_Ioc] exact ⟨fun h => by linarith, fun h => ⟨(div_lt_iffβ‚€' (zero_lt_two' ℝ)).1 h, by linarith [pi_pos, toReal_le_pi ΞΈ]⟩⟩ theorem two_zsmul_toReal_eq_two_mul_sub_two_pi {ΞΈ : Angle} : ((2 : β„€) β€’ ΞΈ).toReal = 2 * ΞΈ.toReal - 2 * Ο€ ↔ Ο€ / 2 < ΞΈ.toReal := by rw [two_zsmul, ← two_nsmul, two_nsmul_toReal_eq_two_mul_sub_two_pi] theorem two_nsmul_toReal_eq_two_mul_add_two_pi {ΞΈ : Angle} : ((2 : β„•) β€’ ΞΈ).toReal = 2 * ΞΈ.toReal + 2 * Ο€ ↔ ΞΈ.toReal ≀ -Ο€ / 2 := by nth_rw 1 [← coe_toReal ΞΈ] rw [← coe_nsmul, two_nsmul, ← two_mul, toReal_coe_eq_self_add_two_pi_iff, Set.mem_Ioc] refine ⟨fun h => by linarith, fun h => ⟨by linarith [pi_pos, neg_pi_lt_toReal ΞΈ], (le_div_iffβ‚€' (zero_lt_two' ℝ)).1 h⟩⟩ theorem two_zsmul_toReal_eq_two_mul_add_two_pi {ΞΈ : Angle} : ((2 : β„€) β€’ ΞΈ).toReal = 2 * ΞΈ.toReal + 2 * Ο€ ↔ ΞΈ.toReal ≀ -Ο€ / 2 := by rw [two_zsmul, ← two_nsmul, two_nsmul_toReal_eq_two_mul_add_two_pi] lemma two_nsmul_eq_iff_eq_of_abs_toReal_lt_pi_div_two {ΞΈ ψ : Angle} (hΞΈ : |ΞΈ.toReal| < Ο€ / 2) (hψ : |ψ.toReal| < Ο€ / 2) : (2 : β„•) β€’ ΞΈ = (2 : β„•) β€’ ψ ↔ ΞΈ = ψ := by constructor Β· intro h rw [two_nsmul_eq_iff] at h rcases h with rfl | rfl Β· rfl Β· rw [abs_lt] at hψ hΞΈ rw [← coe_toReal ψ, ← coe_add] at hΞΈ by_cases hψ' : ψ.toReal ≀ 0 Β· have hψt : -Ο€ < ψ.toReal + Ο€ ∧ ψ.toReal + Ο€ ≀ Ο€ := ⟨by linarith, by linarith⟩ rw [toReal_coe_eq_self_iff.2 hψt] at hΞΈ linarith Β· have hψt : Ο€ < ψ.toReal + Ο€ ∧ ψ.toReal + Ο€ ≀ 3 * Ο€ := ⟨by linarith, by linarith⟩ rw [toReal_coe_eq_self_sub_two_pi_iff.2 hψt] at hΞΈ linarith Β· rintro rfl rfl lemma two_zsmul_eq_iff_eq_of_abs_toReal_lt_pi_div_two {ΞΈ ψ : Angle} (hΞΈ : |ΞΈ.toReal| < Ο€ / 2) (hψ : |ψ.toReal| < Ο€ / 2) : (2 : β„€) β€’ ΞΈ = (2 : β„€) β€’ ψ ↔ ΞΈ = ψ := by simp_rw [two_zsmul, ← two_nsmul, two_nsmul_eq_iff_eq_of_abs_toReal_lt_pi_div_two hΞΈ hψ] @[simp] theorem sin_toReal (ΞΈ : Angle) : Real.sin ΞΈ.toReal = sin ΞΈ := by conv_rhs => rw [← coe_toReal ΞΈ, sin_coe] @[simp] theorem cos_toReal (ΞΈ : Angle) : Real.cos ΞΈ.toReal = cos ΞΈ := by conv_rhs => rw [← coe_toReal ΞΈ, cos_coe] theorem cos_nonneg_iff_abs_toReal_le_pi_div_two {ΞΈ : Angle} : 0 ≀ cos ΞΈ ↔ |ΞΈ.toReal| ≀ Ο€ / 2 := by nth_rw 1 [← coe_toReal ΞΈ] rw [abs_le, cos_coe] refine ⟨fun h => ?_, cos_nonneg_of_mem_Icc⟩ by_contra hn rw [not_and_or, not_le, not_le] at hn refine (not_lt.2 h) ?_ rcases hn with (hn | hn) Β· rw [← Real.cos_neg] refine cos_neg_of_pi_div_two_lt_of_lt (by linarith) ?_ linarith [neg_pi_lt_toReal ΞΈ] Β· refine cos_neg_of_pi_div_two_lt_of_lt hn ?_ linarith [toReal_le_pi ΞΈ] theorem cos_pos_iff_abs_toReal_lt_pi_div_two {ΞΈ : Angle} : 0 < cos ΞΈ ↔ |ΞΈ.toReal| < Ο€ / 2 := by rw [lt_iff_le_and_ne, lt_iff_le_and_ne, cos_nonneg_iff_abs_toReal_le_pi_div_two, ← and_congr_right] rintro - rw [Ne, Ne, not_iff_not, @eq_comm ℝ 0, abs_toReal_eq_pi_div_two_iff, cos_eq_zero_iff] theorem cos_neg_iff_pi_div_two_lt_abs_toReal {ΞΈ : Angle} : cos ΞΈ < 0 ↔ Ο€ / 2 < |ΞΈ.toReal| := by rw [← not_le, ← not_le, not_iff_not, cos_nonneg_iff_abs_toReal_le_pi_div_two] theorem abs_cos_eq_abs_sin_of_two_nsmul_add_two_nsmul_eq_pi {ΞΈ ψ : Angle} (h : (2 : β„•) β€’ ΞΈ + (2 : β„•) β€’ ψ = Ο€) : |cos ΞΈ| = |sin ψ| := by rw [← eq_sub_iff_add_eq, ← two_nsmul_coe_div_two, ← nsmul_sub, two_nsmul_eq_iff] at h rcases h with (rfl | rfl) <;> simp [cos_pi_div_two_sub] theorem abs_cos_eq_abs_sin_of_two_zsmul_add_two_zsmul_eq_pi {ΞΈ ψ : Angle} (h : (2 : β„€) β€’ ΞΈ + (2 : β„€) β€’ ψ = Ο€) : |cos ΞΈ| = |sin ψ| := by simp_rw [two_zsmul, ← two_nsmul] at h exact abs_cos_eq_abs_sin_of_two_nsmul_add_two_nsmul_eq_pi h /-- The tangent of a `Real.Angle`. -/ def tan (ΞΈ : Angle) : ℝ := sin ΞΈ / cos ΞΈ theorem tan_eq_sin_div_cos (ΞΈ : Angle) : tan ΞΈ = sin ΞΈ / cos ΞΈ := rfl @[simp] theorem tan_coe (x : ℝ) : tan (x : Angle) = Real.tan x := by rw [tan, sin_coe, cos_coe, Real.tan_eq_sin_div_cos] @[simp] theorem tan_zero : tan (0 : Angle) = 0 := by rw [← coe_zero, tan_coe, Real.tan_zero] theorem tan_coe_pi : tan (Ο€ : Angle) = 0 := by rw [tan_coe, Real.tan_pi] theorem tan_periodic : Function.Periodic tan (Ο€ : Angle) := by intro ΞΈ induction ΞΈ using Real.Angle.induction_on rw [← coe_add, tan_coe, tan_coe] exact Real.tan_periodic _ @[simp] theorem tan_add_pi (ΞΈ : Angle) : tan (ΞΈ + Ο€) = tan ΞΈ := tan_periodic ΞΈ @[simp] theorem tan_sub_pi (ΞΈ : Angle) : tan (ΞΈ - Ο€) = tan ΞΈ := tan_periodic.sub_eq ΞΈ @[simp] theorem tan_toReal (ΞΈ : Angle) : Real.tan ΞΈ.toReal = tan ΞΈ := by conv_rhs => rw [← coe_toReal ΞΈ, tan_coe] theorem tan_eq_of_two_nsmul_eq {ΞΈ ψ : Angle} (h : (2 : β„•) β€’ ΞΈ = (2 : β„•) β€’ ψ) : tan ΞΈ = tan ψ := by rw [two_nsmul_eq_iff] at h rcases h with (rfl | rfl) Β· rfl Β· exact tan_add_pi _ theorem tan_eq_of_two_zsmul_eq {ΞΈ ψ : Angle} (h : (2 : β„€) β€’ ΞΈ = (2 : β„€) β€’ ψ) : tan ΞΈ = tan ψ := by simp_rw [two_zsmul, ← two_nsmul] at h exact tan_eq_of_two_nsmul_eq h theorem tan_eq_inv_of_two_nsmul_add_two_nsmul_eq_pi {ΞΈ ψ : Angle} (h : (2 : β„•) β€’ ΞΈ + (2 : β„•) β€’ ψ = Ο€) : tan ψ = (tan ΞΈ)⁻¹ := by induction ΞΈ using Real.Angle.induction_on induction ψ using Real.Angle.induction_on rw [← smul_add, ← coe_add, ← coe_nsmul, two_nsmul, ← two_mul, angle_eq_iff_two_pi_dvd_sub] at h rcases h with ⟨k, h⟩ rw [sub_eq_iff_eq_add, ← mul_inv_cancel_leftβ‚€ two_ne_zero Ο€, mul_assoc, ← mul_add, mul_right_inj' (two_ne_zero' ℝ), ← eq_sub_iff_add_eq', mul_inv_cancel_leftβ‚€ two_ne_zero Ο€, inv_mul_eq_div, mul_comm] at h rw [tan_coe, tan_coe, ← tan_pi_div_two_sub, h, add_sub_assoc, add_comm] exact Real.tan_periodic.int_mul _ _ theorem tan_eq_inv_of_two_zsmul_add_two_zsmul_eq_pi {ΞΈ ψ : Angle} (h : (2 : β„€) β€’ ΞΈ + (2 : β„€) β€’ ψ = Ο€) : tan ψ = (tan ΞΈ)⁻¹ := by simp_rw [two_zsmul, ← two_nsmul] at h exact tan_eq_inv_of_two_nsmul_add_two_nsmul_eq_pi h /-- The sign of a `Real.Angle` is `0` if the angle is `0` or `Ο€`, `1` if the angle is strictly between `0` and `Ο€` and `-1` is the angle is strictly between `-Ο€` and `0`. It is defined as the sign of the sine of the angle. -/ def sign (ΞΈ : Angle) : SignType := SignType.sign (sin ΞΈ) @[simp] theorem sign_zero : (0 : Angle).sign = 0 := by rw [sign, sin_zero, _root_.sign_zero] @[simp] theorem sign_coe_pi : (Ο€ : Angle).sign = 0 := by rw [sign, sin_coe_pi, _root_.sign_zero] @[simp] theorem sign_neg (ΞΈ : Angle) : (-ΞΈ).sign = -ΞΈ.sign := by simp_rw [sign, sin_neg, Left.sign_neg] theorem sign_antiperiodic : Function.Antiperiodic sign (Ο€ : Angle) := fun ΞΈ => by rw [sign, sign, sin_add_pi, Left.sign_neg] @[simp] theorem sign_add_pi (ΞΈ : Angle) : (ΞΈ + Ο€).sign = -ΞΈ.sign := sign_antiperiodic ΞΈ @[simp] theorem sign_pi_add (ΞΈ : Angle) : ((Ο€ : Angle) + ΞΈ).sign = -ΞΈ.sign := by rw [add_comm, sign_add_pi] @[simp] theorem sign_sub_pi (ΞΈ : Angle) : (ΞΈ - Ο€).sign = -ΞΈ.sign := sign_antiperiodic.sub_eq ΞΈ @[simp] theorem sign_pi_sub (ΞΈ : Angle) : ((Ο€ : Angle) - ΞΈ).sign = ΞΈ.sign := by simp [sign_antiperiodic.sub_eq'] theorem sign_eq_zero_iff {ΞΈ : Angle} : ΞΈ.sign = 0 ↔ ΞΈ = 0 ∨ ΞΈ = Ο€ := by rw [sign, _root_.sign_eq_zero_iff, sin_eq_zero_iff] theorem sign_ne_zero_iff {ΞΈ : Angle} : ΞΈ.sign β‰  0 ↔ ΞΈ β‰  0 ∧ ΞΈ β‰  Ο€ := by rw [← not_or, ← sign_eq_zero_iff] theorem toReal_neg_iff_sign_neg {ΞΈ : Angle} : ΞΈ.toReal < 0 ↔ ΞΈ.sign = -1 := by rw [sign, ← sin_toReal, sign_eq_neg_one_iff] rcases lt_trichotomy ΞΈ.toReal 0 with (h | h | h) Β· exact ⟨fun _ => Real.sin_neg_of_neg_of_neg_pi_lt h (neg_pi_lt_toReal ΞΈ), fun _ => h⟩ Β· simp [h] Β· exact ⟨fun hn => False.elim (h.asymm hn), fun hn => False.elim (hn.not_ge (sin_nonneg_of_nonneg_of_le_pi h.le (toReal_le_pi ΞΈ)))⟩ theorem toReal_nonneg_iff_sign_nonneg {ΞΈ : Angle} : 0 ≀ ΞΈ.toReal ↔ 0 ≀ ΞΈ.sign := by rcases lt_trichotomy ΞΈ.toReal 0 with (h | h | h) Β· refine ⟨fun hn => False.elim (h.not_ge hn), fun hn => ?_⟩ rw [toReal_neg_iff_sign_neg.1 h] at hn exact False.elim (hn.not_gt (by decide)) Β· simp [h, sign, ← sin_toReal] Β· refine ⟨fun _ => ?_, fun _ => h.le⟩ rw [sign, ← sin_toReal, sign_nonneg_iff] exact sin_nonneg_of_nonneg_of_le_pi h.le (toReal_le_pi ΞΈ) @[simp] theorem sign_toReal {ΞΈ : Angle} (h : ΞΈ β‰  Ο€) : SignType.sign ΞΈ.toReal = ΞΈ.sign := by rcases lt_trichotomy ΞΈ.toReal 0 with (ht | ht | ht) Β· simp [ht, toReal_neg_iff_sign_neg.1 ht] Β· simp [sign, ht, ← sin_toReal] Β· rw [sign, ← sin_toReal, sign_pos ht, sign_pos (sin_pos_of_pos_of_lt_pi ht ((toReal_le_pi ΞΈ).lt_of_ne (toReal_eq_pi_iff.not.2 h)))] theorem coe_abs_toReal_of_sign_nonneg {ΞΈ : Angle} (h : 0 ≀ ΞΈ.sign) : ↑|ΞΈ.toReal| = ΞΈ := by rw [abs_eq_self.2 (toReal_nonneg_iff_sign_nonneg.2 h), coe_toReal] theorem neg_coe_abs_toReal_of_sign_nonpos {ΞΈ : Angle} (h : ΞΈ.sign ≀ 0) : -↑|ΞΈ.toReal| = ΞΈ := by rw [SignType.nonpos_iff] at h rcases h with (h | h) Β· rw [abs_of_neg (toReal_neg_iff_sign_neg.2 h), coe_neg, neg_neg, coe_toReal] Β· rw [sign_eq_zero_iff] at h rcases h with (rfl | rfl) <;> simp [abs_of_pos Real.pi_pos] theorem eq_iff_sign_eq_and_abs_toReal_eq {ΞΈ ψ : Angle} : ΞΈ = ψ ↔ ΞΈ.sign = ψ.sign ∧ |ΞΈ.toReal| = |ψ.toReal| := by refine ⟨?_, fun h => ?_⟩ Β· rintro rfl exact ⟨rfl, rfl⟩ rcases h with ⟨hs, hr⟩ rw [abs_eq_abs] at hr rcases hr with (hr | hr) Β· exact toReal_injective hr Β· by_cases h : ΞΈ = Ο€ Β· rw [h, toReal_pi, ← neg_eq_iff_eq_neg] at hr exact False.elim ((neg_pi_lt_toReal ψ).ne hr) Β· by_cases h' : ψ = Ο€ Β· rw [h', toReal_pi] at hr exact False.elim ((neg_pi_lt_toReal ΞΈ).ne hr.symm) Β· rw [← sign_toReal h, ← sign_toReal h', hr, Left.sign_neg, SignType.neg_eq_self_iff, _root_.sign_eq_zero_iff, toReal_eq_zero_iff] at hs rw [hs, toReal_zero, neg_zero, toReal_eq_zero_iff] at hr rw [hr, hs] theorem eq_iff_abs_toReal_eq_of_sign_eq {ΞΈ ψ : Angle} (h : ΞΈ.sign = ψ.sign) : ΞΈ = ψ ↔ |ΞΈ.toReal| = |ψ.toReal| := by simpa [h] using @eq_iff_sign_eq_and_abs_toReal_eq ΞΈ ψ @[simp] theorem sign_coe_pi_div_two : (↑(Ο€ / 2) : Angle).sign = 1 := by rw [sign, sin_coe, sin_pi_div_two, sign_one] @[simp] theorem sign_coe_neg_pi_div_two : (↑(-Ο€ / 2) : Angle).sign = -1 := by rw [sign, sin_coe, neg_div, Real.sin_neg, sin_pi_div_two, Left.sign_neg, sign_one] theorem sign_coe_nonneg_of_nonneg_of_le_pi {ΞΈ : ℝ} (h0 : 0 ≀ ΞΈ) (hpi : ΞΈ ≀ Ο€) : 0 ≀ (ΞΈ : Angle).sign := by rw [sign, sign_nonneg_iff] exact sin_nonneg_of_nonneg_of_le_pi h0 hpi theorem sign_neg_coe_nonpos_of_nonneg_of_le_pi {ΞΈ : ℝ} (h0 : 0 ≀ ΞΈ) (hpi : ΞΈ ≀ Ο€) : (-ΞΈ : Angle).sign ≀ 0 := by rw [sign, sign_nonpos_iff, sin_neg, Left.neg_nonpos_iff] exact sin_nonneg_of_nonneg_of_le_pi h0 hpi theorem sign_two_nsmul_eq_sign_iff {ΞΈ : Angle} : ((2 : β„•) β€’ ΞΈ).sign = ΞΈ.sign ↔ ΞΈ = Ο€ ∨ |ΞΈ.toReal| < Ο€ / 2 := by by_cases hpi : ΞΈ = Ο€; Β· simp [hpi] rw [or_iff_right hpi] refine ⟨fun h => ?_, fun h => ?_⟩ Β· by_contra hle rw [not_lt, le_abs, le_neg] at hle have hpi' : ΞΈ.toReal β‰  Ο€ := by simpa using hpi rcases hle with (hle | hle) <;> rcases hle.eq_or_lt with (heq | hlt) Β· rw [← coe_toReal ΞΈ, ← heq] at h simp at h Β· rw [← sign_toReal hpi, sign_pos (pi_div_two_pos.trans hlt), ← sign_toReal, two_nsmul_toReal_eq_two_mul_sub_two_pi.2 hlt, _root_.sign_neg] at h Β· simp at h Β· rw [← mul_sub] exact mul_neg_of_pos_of_neg two_pos (sub_neg.2 ((toReal_le_pi _).lt_of_ne hpi')) Β· intro he simp [he] at h Β· rw [← coe_toReal ΞΈ, heq] at h simp at h Β· rw [← sign_toReal hpi, _root_.sign_neg (hlt.trans (Left.neg_neg_iff.2 pi_div_two_pos)), ← sign_toReal] at h swap Β· intro he simp [he] at h rw [← neg_div] at hlt rw [two_nsmul_toReal_eq_two_mul_add_two_pi.2 hlt.le, sign_pos] at h Β· simp at h Β· linarith [neg_pi_lt_toReal ΞΈ] Β· have hpi' : (2 : β„•) β€’ ΞΈ β‰  Ο€ := by rw [Ne, two_nsmul_eq_pi_iff, not_or] constructor Β· rintro rfl simp [pi_pos, abs_of_pos] at h Β· rintro rfl rw [toReal_neg_pi_div_two] at h simp [pi_pos, neg_div, abs_of_pos] at h rw [abs_lt, ← neg_div] at h rw [← sign_toReal hpi, ← sign_toReal hpi', two_nsmul_toReal_eq_two_mul.2 ⟨h.1, h.2.le⟩, sign_mul, sign_pos (zero_lt_two' ℝ), one_mul] theorem sign_two_zsmul_eq_sign_iff {ΞΈ : Angle} : ((2 : β„€) β€’ ΞΈ).sign = ΞΈ.sign ↔ ΞΈ = Ο€ ∨ |ΞΈ.toReal| < Ο€ / 2 := by rw [two_zsmul, ← two_nsmul, sign_two_nsmul_eq_sign_iff] lemma abs_toReal_add_abs_toReal_eq_pi_of_two_nsmul_add_eq_zero_of_sign_eq {ΞΈ ψ : Angle} (h : (2 : β„•) β€’ (ΞΈ + ψ) = 0) (hs : ΞΈ.sign = ψ.sign) (h0 : ΞΈ.sign β‰  0) : |ΞΈ.toReal| + |ψ.toReal| = Ο€ := by rcases two_nsmul_eq_zero_iff.mp h with h | h Β· simp_all [add_eq_zero_iff_eq_neg.mp h] rw [← coe_toReal ΞΈ, ← coe_toReal ψ, ← coe_add] at h suffices |ΞΈ.toReal + ψ.toReal| = Ο€ by rw [← this, eq_comm, abs_add_eq_add_abs_iff] have hΞΈ := sign_toReal (sign_ne_zero_iff.1 h0).2 have hψ := sign_toReal (sign_ne_zero_iff.1 (hs β–Έ h0)).2 obtain hΞΈs | hΞΈs : ΞΈ.sign = -1 ∨ ΞΈ.sign = 1 := by simpa [h0] using ΞΈ.sign.trichotomy Β· rw [hΞΈs, eq_comm, ← toReal_neg_iff_sign_neg] at hs exact .inr ⟨(toReal_neg_iff_sign_neg.mpr hΞΈs).le, hs.le⟩ Β· simp [toReal_nonneg_iff_sign_nonneg, hs.symm, hΞΈs] rw [abs_eq pi_nonneg] rcases angle_eq_iff_two_pi_dvd_sub.mp h with ⟨k, hk⟩ rw [sub_eq_iff_eq_add] at hk have hu : ΞΈ.toReal + ψ.toReal ≀ 2 * Ο€ := by linarith [toReal_le_pi ΞΈ, toReal_le_pi ψ] have hn : -2 * Ο€ < ΞΈ.toReal + ψ.toReal := by linarith [neg_pi_lt_toReal ΞΈ, neg_pi_lt_toReal ψ] rw [hk] at hu hn have hk0 : k ≀ 0 := by by_contra hk1 grw [← show 1 ≀ k by cutsat] at hu simp only [Int.cast_one] at hu linarith [pi_pos] have hkn1 : -1 ≀ k := by by_contra hkn2 grw [show k ≀ -2 by cutsat] at hn simp only [Int.cast_neg, Int.cast_ofNat] at hn linarith [pi_pos] obtain rfl | rfl : k = -1 ∨ k = 0 := (by cutsat) <;> grind lemma abs_toReal_add_abs_toReal_eq_pi_of_two_zsmul_add_eq_zero_of_sign_eq {ΞΈ ψ : Angle} (h : (2 : β„€) β€’ (ΞΈ + ψ) = 0) (hs : ΞΈ.sign = ψ.sign) (h0 : ΞΈ.sign β‰  0) : |ΞΈ.toReal| + |ψ.toReal| = Ο€ := by rw [two_zsmul, ← two_nsmul] at h exact abs_toReal_add_abs_toReal_eq_pi_of_two_nsmul_add_eq_zero_of_sign_eq h hs h0 theorem continuousAt_sign {ΞΈ : Angle} (h0 : ΞΈ β‰  0) (hpi : ΞΈ β‰  Ο€) : ContinuousAt sign ΞΈ := (continuousAt_sign_of_ne_zero (sin_ne_zero_iff.2 ⟨h0, hpi⟩)).comp continuous_sin.continuousAt theorem _root_.ContinuousOn.angle_sign_comp {Ξ± : Type*} [TopologicalSpace Ξ±] {f : Ξ± β†’ Angle} {s : Set Ξ±} (hf : ContinuousOn f s) (hs : βˆ€ z ∈ s, f z β‰  0 ∧ f z β‰  Ο€) : ContinuousOn (sign ∘ f) s := by refine (continuousOn_of_forall_continuousAt fun ΞΈ hΞΈ => ?_).comp hf (Set.mapsTo_image f s) obtain ⟨z, hz, rfl⟩ := hΞΈ exact continuousAt_sign (hs _ hz).1 (hs _ hz).2 /-- Suppose a function to angles is continuous on a connected set and never takes the values `0` or `Ο€` on that set. Then the values of the function on that set all have the same sign. -/ theorem sign_eq_of_continuousOn {Ξ± : Type*} [TopologicalSpace Ξ±] {f : Ξ± β†’ Angle} {s : Set Ξ±} {x y : Ξ±} (hc : IsConnected s) (hf : ContinuousOn f s) (hs : βˆ€ z ∈ s, f z β‰  0 ∧ f z β‰  Ο€) (hx : x ∈ s) (hy : y ∈ s) : (f y).sign = (f x).sign := (hc.image _ (hf.angle_sign_comp hs)).isPreconnected.subsingleton (Set.mem_image_of_mem _ hy) (Set.mem_image_of_mem _ hx) end Angle end Real
.lake/packages/mathlib/Mathlib/Analysis/SpecialFunctions/Trigonometric/Deriv.lean
import Mathlib.Order.Monotone.Odd import Mathlib.Analysis.Calculus.LogDeriv import Mathlib.Analysis.SpecialFunctions.ExpDeriv import Mathlib.Analysis.SpecialFunctions.Trigonometric.Basic import Mathlib.Analysis.Calculus.Deriv.MeanValue /-! # Differentiability of trigonometric functions ## Main statements The differentiability of the usual trigonometric functions is proved, and their derivatives are computed. ## Tags sin, cos, tan, angle -/ noncomputable section open scoped Asymptotics Topology Filter open Set namespace Complex /-- The complex sine function is everywhere strictly differentiable, with the derivative `cos x`. -/ theorem hasStrictDerivAt_sin (x : β„‚) : HasStrictDerivAt sin (cos x) x := by simp only [cos, div_eq_mul_inv] convert ((((hasStrictDerivAt_id x).fun_neg.mul_const I).cexp.sub ((hasStrictDerivAt_id x).mul_const I).cexp).mul_const I).mul_const (2 : β„‚)⁻¹ using 1 simp only [id] rw [sub_mul, mul_assoc, mul_assoc, I_mul_I, neg_one_mul, neg_neg, mul_one, one_mul, mul_assoc, I_mul_I, mul_neg_one, sub_neg_eq_add, add_comm] /-- The complex sine function is everywhere differentiable, with the derivative `cos x`. -/ theorem hasDerivAt_sin (x : β„‚) : HasDerivAt sin (cos x) x := (hasStrictDerivAt_sin x).hasDerivAt theorem isEquivalent_sin : sin ~[𝓝 0] id := by simpa using (hasDerivAt_sin 0).isLittleO @[fun_prop] theorem contDiff_sin {n} : ContDiff β„‚ n sin := (((contDiff_neg.mul contDiff_const).cexp.sub (contDiff_id.mul contDiff_const).cexp).mul contDiff_const).div_const _ @[simp] theorem differentiable_sin : Differentiable β„‚ sin := fun x => (hasDerivAt_sin x).differentiableAt @[simp] theorem differentiableAt_sin {x : β„‚} : DifferentiableAt β„‚ sin x := differentiable_sin x /-- The function `Complex.sin` is complex analytic. -/ @[fun_prop] lemma analyticAt_sin {x : β„‚} : AnalyticAt β„‚ sin x := contDiff_sin.contDiffAt.analyticAt /-- The function `Complex.sin` is complex analytic. -/ lemma analyticWithinAt_sin {x : β„‚} {s : Set β„‚} : AnalyticWithinAt β„‚ sin s x := contDiff_sin.contDiffWithinAt.analyticWithinAt /-- The function `Complex.sin` is complex analytic. -/ theorem analyticOnNhd_sin {s : Set β„‚} : AnalyticOnNhd β„‚ sin s := fun _ _ ↦ analyticAt_sin /-- The function `Complex.sin` is complex analytic. -/ lemma analyticOn_sin {s : Set β„‚} : AnalyticOn β„‚ sin s := contDiff_sin.contDiffOn.analyticOn @[simp] theorem deriv_sin : deriv sin = cos := funext fun x => (hasDerivAt_sin x).deriv /-- The complex cosine function is everywhere strictly differentiable, with the derivative `-sin x`. -/ theorem hasStrictDerivAt_cos (x : β„‚) : HasStrictDerivAt cos (-sin x) x := by simp only [sin, div_eq_mul_inv, neg_mul_eq_neg_mul] convert (((hasStrictDerivAt_id x).mul_const I).cexp.add ((hasStrictDerivAt_id x).fun_neg.mul_const I).cexp).mul_const (2 : β„‚)⁻¹ using 1 simp only [id] ring /-- The complex cosine function is everywhere differentiable, with the derivative `-sin x`. -/ theorem hasDerivAt_cos (x : β„‚) : HasDerivAt cos (-sin x) x := (hasStrictDerivAt_cos x).hasDerivAt @[fun_prop] theorem contDiff_cos {n} : ContDiff β„‚ n cos := ((contDiff_id.mul contDiff_const).cexp.add (contDiff_neg.mul contDiff_const).cexp).div_const _ @[simp] theorem differentiable_cos : Differentiable β„‚ cos := fun x => (hasDerivAt_cos x).differentiableAt @[simp] theorem differentiableAt_cos {x : β„‚} : DifferentiableAt β„‚ cos x := differentiable_cos x /-- The function `Complex.cos` is complex analytic. -/ @[fun_prop] lemma analyticAt_cos {x : β„‚} : AnalyticAt β„‚ cos x := contDiff_cos.contDiffAt.analyticAt /-- The function `Complex.cos` is complex analytic. -/ lemma analyticWithinAt_cos {x : β„‚} {s : Set β„‚} : AnalyticWithinAt β„‚ cos s x := contDiff_cos.contDiffWithinAt.analyticWithinAt /-- The function `Complex.cos` is complex analytic. -/ theorem analyticOnNhd_cos {s : Set β„‚} : AnalyticOnNhd β„‚ cos s := fun _ _ ↦ analyticAt_cos /-- The function `Complex.cos` is complex analytic. -/ lemma analyticOn_cos {s : Set β„‚} : AnalyticOn β„‚ cos s := contDiff_cos.contDiffOn.analyticOn theorem deriv_cos {x : β„‚} : deriv cos x = -sin x := (hasDerivAt_cos x).deriv @[simp] theorem deriv_cos' : deriv cos = fun x => -sin x := funext fun _ => deriv_cos /-- The complex hyperbolic sine function is everywhere strictly differentiable, with the derivative `cosh x`. -/ theorem hasStrictDerivAt_sinh (x : β„‚) : HasStrictDerivAt sinh (cosh x) x := by simp only [cosh, div_eq_mul_inv] convert ((hasStrictDerivAt_exp x).sub (hasStrictDerivAt_id x).fun_neg.cexp).mul_const (2 : β„‚)⁻¹ using 1 rw [id, mul_neg_one, sub_eq_add_neg, neg_neg] /-- The complex hyperbolic sine function is everywhere differentiable, with the derivative `cosh x`. -/ theorem hasDerivAt_sinh (x : β„‚) : HasDerivAt sinh (cosh x) x := (hasStrictDerivAt_sinh x).hasDerivAt theorem isEquivalent_sinh : sinh ~[𝓝 0] id := by simpa using (hasDerivAt_sinh 0).isLittleO @[fun_prop] theorem contDiff_sinh {n} : ContDiff β„‚ n sinh := (contDiff_exp.sub contDiff_neg.cexp).div_const _ @[simp] theorem differentiable_sinh : Differentiable β„‚ sinh := fun x => (hasDerivAt_sinh x).differentiableAt @[simp] theorem differentiableAt_sinh {x : β„‚} : DifferentiableAt β„‚ sinh x := differentiable_sinh x /-- The function `Complex.sinh` is complex analytic. -/ @[fun_prop] lemma analyticAt_sinh {x : β„‚} : AnalyticAt β„‚ sinh x := contDiff_sinh.contDiffAt.analyticAt /-- The function `Complex.sinh` is complex analytic. -/ lemma analyticWithinAt_sinh {x : β„‚} {s : Set β„‚} : AnalyticWithinAt β„‚ sinh s x := contDiff_sinh.contDiffWithinAt.analyticWithinAt /-- The function `Complex.sinh` is complex analytic. -/ theorem analyticOnNhd_sinh {s : Set β„‚} : AnalyticOnNhd β„‚ sinh s := fun _ _ ↦ analyticAt_sinh /-- The function `Complex.sinh` is complex analytic. -/ lemma analyticOn_sinh {s : Set β„‚} : AnalyticOn β„‚ sinh s := contDiff_sinh.contDiffOn.analyticOn @[simp] theorem deriv_sinh : deriv sinh = cosh := funext fun x => (hasDerivAt_sinh x).deriv /-- The complex hyperbolic cosine function is everywhere strictly differentiable, with the derivative `sinh x`. -/ theorem hasStrictDerivAt_cosh (x : β„‚) : HasStrictDerivAt cosh (sinh x) x := by simp only [sinh, div_eq_mul_inv] convert ((hasStrictDerivAt_exp x).add (hasStrictDerivAt_id x).fun_neg.cexp).mul_const (2 : β„‚)⁻¹ using 1 rw [id, mul_neg_one, sub_eq_add_neg] /-- The complex hyperbolic cosine function is everywhere differentiable, with the derivative `sinh x`. -/ theorem hasDerivAt_cosh (x : β„‚) : HasDerivAt cosh (sinh x) x := (hasStrictDerivAt_cosh x).hasDerivAt @[fun_prop] theorem contDiff_cosh {n} : ContDiff β„‚ n cosh := (contDiff_exp.add contDiff_neg.cexp).div_const _ @[simp] theorem differentiable_cosh : Differentiable β„‚ cosh := fun x => (hasDerivAt_cosh x).differentiableAt @[simp] theorem differentiableAt_cosh {x : β„‚} : DifferentiableAt β„‚ cosh x := differentiable_cosh x /-- The function `Complex.cosh` is complex analytic. -/ @[fun_prop] lemma analyticAt_cosh {x : β„‚} : AnalyticAt β„‚ cosh x := contDiff_cosh.contDiffAt.analyticAt /-- The function `Complex.cosh` is complex analytic. -/ lemma analyticWithinAt_cosh {x : β„‚} {s : Set β„‚} : AnalyticWithinAt β„‚ cosh s x := contDiff_cosh.contDiffWithinAt.analyticWithinAt /-- The function `Complex.cosh` is complex analytic. -/ theorem analyticOnNhd_cosh {s : Set β„‚} : AnalyticOnNhd β„‚ cosh s := fun _ _ ↦ analyticAt_cosh /-- The function `Complex.cosh` is complex analytic. -/ lemma analyticOn_cosh {s : Set β„‚} : AnalyticOn β„‚ cosh s := contDiff_cosh.contDiffOn.analyticOn @[simp] theorem deriv_cosh : deriv cosh = sinh := funext fun x => (hasDerivAt_cosh x).deriv end Complex section /-! ### Simp lemmas for derivatives of `fun x => Complex.cos (f x)` etc., `f : β„‚ β†’ β„‚` -/ variable {f : β„‚ β†’ β„‚} {f' x : β„‚} {s : Set β„‚} /-! #### `Complex.cos` -/ theorem HasStrictDerivAt.ccos (hf : HasStrictDerivAt f f' x) : HasStrictDerivAt (fun x => Complex.cos (f x)) (-Complex.sin (f x) * f') x := (Complex.hasStrictDerivAt_cos (f x)).comp x hf theorem HasDerivAt.ccos (hf : HasDerivAt f f' x) : HasDerivAt (fun x => Complex.cos (f x)) (-Complex.sin (f x) * f') x := (Complex.hasDerivAt_cos (f x)).comp x hf theorem HasDerivWithinAt.ccos (hf : HasDerivWithinAt f f' s x) : HasDerivWithinAt (fun x => Complex.cos (f x)) (-Complex.sin (f x) * f') s x := (Complex.hasDerivAt_cos (f x)).comp_hasDerivWithinAt x hf theorem derivWithin_ccos (hf : DifferentiableWithinAt β„‚ f s x) (hxs : UniqueDiffWithinAt β„‚ s x) : derivWithin (fun x => Complex.cos (f x)) s x = -Complex.sin (f x) * derivWithin f s x := hf.hasDerivWithinAt.ccos.derivWithin hxs @[simp] theorem deriv_ccos (hc : DifferentiableAt β„‚ f x) : deriv (fun x => Complex.cos (f x)) x = -Complex.sin (f x) * deriv f x := hc.hasDerivAt.ccos.deriv /-! #### `Complex.sin` -/ theorem HasStrictDerivAt.csin (hf : HasStrictDerivAt f f' x) : HasStrictDerivAt (fun x => Complex.sin (f x)) (Complex.cos (f x) * f') x := (Complex.hasStrictDerivAt_sin (f x)).comp x hf theorem HasDerivAt.csin (hf : HasDerivAt f f' x) : HasDerivAt (fun x => Complex.sin (f x)) (Complex.cos (f x) * f') x := (Complex.hasDerivAt_sin (f x)).comp x hf theorem HasDerivWithinAt.csin (hf : HasDerivWithinAt f f' s x) : HasDerivWithinAt (fun x => Complex.sin (f x)) (Complex.cos (f x) * f') s x := (Complex.hasDerivAt_sin (f x)).comp_hasDerivWithinAt x hf theorem derivWithin_csin (hf : DifferentiableWithinAt β„‚ f s x) (hxs : UniqueDiffWithinAt β„‚ s x) : derivWithin (fun x => Complex.sin (f x)) s x = Complex.cos (f x) * derivWithin f s x := hf.hasDerivWithinAt.csin.derivWithin hxs @[simp] theorem deriv_csin (hc : DifferentiableAt β„‚ f x) : deriv (fun x => Complex.sin (f x)) x = Complex.cos (f x) * deriv f x := hc.hasDerivAt.csin.deriv /-! #### `Complex.cosh` -/ theorem HasStrictDerivAt.ccosh (hf : HasStrictDerivAt f f' x) : HasStrictDerivAt (fun x => Complex.cosh (f x)) (Complex.sinh (f x) * f') x := (Complex.hasStrictDerivAt_cosh (f x)).comp x hf theorem HasDerivAt.ccosh (hf : HasDerivAt f f' x) : HasDerivAt (fun x => Complex.cosh (f x)) (Complex.sinh (f x) * f') x := (Complex.hasDerivAt_cosh (f x)).comp x hf theorem HasDerivWithinAt.ccosh (hf : HasDerivWithinAt f f' s x) : HasDerivWithinAt (fun x => Complex.cosh (f x)) (Complex.sinh (f x) * f') s x := (Complex.hasDerivAt_cosh (f x)).comp_hasDerivWithinAt x hf theorem derivWithin_ccosh (hf : DifferentiableWithinAt β„‚ f s x) (hxs : UniqueDiffWithinAt β„‚ s x) : derivWithin (fun x => Complex.cosh (f x)) s x = Complex.sinh (f x) * derivWithin f s x := hf.hasDerivWithinAt.ccosh.derivWithin hxs @[simp] theorem deriv_ccosh (hc : DifferentiableAt β„‚ f x) : deriv (fun x => Complex.cosh (f x)) x = Complex.sinh (f x) * deriv f x := hc.hasDerivAt.ccosh.deriv /-! #### `Complex.sinh` -/ theorem HasStrictDerivAt.csinh (hf : HasStrictDerivAt f f' x) : HasStrictDerivAt (fun x => Complex.sinh (f x)) (Complex.cosh (f x) * f') x := (Complex.hasStrictDerivAt_sinh (f x)).comp x hf theorem HasDerivAt.csinh (hf : HasDerivAt f f' x) : HasDerivAt (fun x => Complex.sinh (f x)) (Complex.cosh (f x) * f') x := (Complex.hasDerivAt_sinh (f x)).comp x hf theorem HasDerivWithinAt.csinh (hf : HasDerivWithinAt f f' s x) : HasDerivWithinAt (fun x => Complex.sinh (f x)) (Complex.cosh (f x) * f') s x := (Complex.hasDerivAt_sinh (f x)).comp_hasDerivWithinAt x hf theorem derivWithin_csinh (hf : DifferentiableWithinAt β„‚ f s x) (hxs : UniqueDiffWithinAt β„‚ s x) : derivWithin (fun x => Complex.sinh (f x)) s x = Complex.cosh (f x) * derivWithin f s x := hf.hasDerivWithinAt.csinh.derivWithin hxs @[simp] theorem deriv_csinh (hc : DifferentiableAt β„‚ f x) : deriv (fun x => Complex.sinh (f x)) x = Complex.cosh (f x) * deriv f x := hc.hasDerivAt.csinh.deriv end section /-! ### Simp lemmas for derivatives of `fun x => Complex.cos (f x)` etc., `f : E β†’ β„‚` -/ variable {E : Type*} [NormedAddCommGroup E] [NormedSpace β„‚ E] {f : E β†’ β„‚} {f' : StrongDual β„‚ E} {x : E} {s : Set E} /-! #### `Complex.cos` -/ theorem HasStrictFDerivAt.ccos (hf : HasStrictFDerivAt f f' x) : HasStrictFDerivAt (fun x => Complex.cos (f x)) (-Complex.sin (f x) β€’ f') x := (Complex.hasStrictDerivAt_cos (f x)).comp_hasStrictFDerivAt x hf theorem HasFDerivAt.ccos (hf : HasFDerivAt f f' x) : HasFDerivAt (fun x => Complex.cos (f x)) (-Complex.sin (f x) β€’ f') x := (Complex.hasDerivAt_cos (f x)).comp_hasFDerivAt x hf theorem HasFDerivWithinAt.ccos (hf : HasFDerivWithinAt f f' s x) : HasFDerivWithinAt (fun x => Complex.cos (f x)) (-Complex.sin (f x) β€’ f') s x := (Complex.hasDerivAt_cos (f x)).comp_hasFDerivWithinAt x hf theorem DifferentiableWithinAt.ccos (hf : DifferentiableWithinAt β„‚ f s x) : DifferentiableWithinAt β„‚ (fun x => Complex.cos (f x)) s x := hf.hasFDerivWithinAt.ccos.differentiableWithinAt @[simp, fun_prop] theorem DifferentiableAt.ccos (hc : DifferentiableAt β„‚ f x) : DifferentiableAt β„‚ (fun x => Complex.cos (f x)) x := hc.hasFDerivAt.ccos.differentiableAt theorem DifferentiableOn.ccos (hc : DifferentiableOn β„‚ f s) : DifferentiableOn β„‚ (fun x => Complex.cos (f x)) s := fun x h => (hc x h).ccos @[simp, fun_prop] theorem Differentiable.ccos (hc : Differentiable β„‚ f) : Differentiable β„‚ fun x => Complex.cos (f x) := fun x => (hc x).ccos theorem fderivWithin_ccos (hf : DifferentiableWithinAt β„‚ f s x) (hxs : UniqueDiffWithinAt β„‚ s x) : fderivWithin β„‚ (fun x => Complex.cos (f x)) s x = -Complex.sin (f x) β€’ fderivWithin β„‚ f s x := hf.hasFDerivWithinAt.ccos.fderivWithin hxs @[simp] theorem fderiv_ccos (hc : DifferentiableAt β„‚ f x) : fderiv β„‚ (fun x => Complex.cos (f x)) x = -Complex.sin (f x) β€’ fderiv β„‚ f x := hc.hasFDerivAt.ccos.fderiv theorem ContDiff.ccos {n} (h : ContDiff β„‚ n f) : ContDiff β„‚ n fun x => Complex.cos (f x) := Complex.contDiff_cos.comp h theorem ContDiffAt.ccos {n} (hf : ContDiffAt β„‚ n f x) : ContDiffAt β„‚ n (fun x => Complex.cos (f x)) x := Complex.contDiff_cos.contDiffAt.comp x hf theorem ContDiffOn.ccos {n} (hf : ContDiffOn β„‚ n f s) : ContDiffOn β„‚ n (fun x => Complex.cos (f x)) s := Complex.contDiff_cos.comp_contDiffOn hf theorem ContDiffWithinAt.ccos {n} (hf : ContDiffWithinAt β„‚ n f s x) : ContDiffWithinAt β„‚ n (fun x => Complex.cos (f x)) s x := Complex.contDiff_cos.contDiffAt.comp_contDiffWithinAt x hf /-! #### `Complex.sin` -/ theorem HasStrictFDerivAt.csin (hf : HasStrictFDerivAt f f' x) : HasStrictFDerivAt (fun x => Complex.sin (f x)) (Complex.cos (f x) β€’ f') x := (Complex.hasStrictDerivAt_sin (f x)).comp_hasStrictFDerivAt x hf theorem HasFDerivAt.csin (hf : HasFDerivAt f f' x) : HasFDerivAt (fun x => Complex.sin (f x)) (Complex.cos (f x) β€’ f') x := (Complex.hasDerivAt_sin (f x)).comp_hasFDerivAt x hf theorem HasFDerivWithinAt.csin (hf : HasFDerivWithinAt f f' s x) : HasFDerivWithinAt (fun x => Complex.sin (f x)) (Complex.cos (f x) β€’ f') s x := (Complex.hasDerivAt_sin (f x)).comp_hasFDerivWithinAt x hf theorem DifferentiableWithinAt.csin (hf : DifferentiableWithinAt β„‚ f s x) : DifferentiableWithinAt β„‚ (fun x => Complex.sin (f x)) s x := hf.hasFDerivWithinAt.csin.differentiableWithinAt @[simp, fun_prop] theorem DifferentiableAt.csin (hc : DifferentiableAt β„‚ f x) : DifferentiableAt β„‚ (fun x => Complex.sin (f x)) x := hc.hasFDerivAt.csin.differentiableAt theorem DifferentiableOn.csin (hc : DifferentiableOn β„‚ f s) : DifferentiableOn β„‚ (fun x => Complex.sin (f x)) s := fun x h => (hc x h).csin @[simp, fun_prop] theorem Differentiable.csin (hc : Differentiable β„‚ f) : Differentiable β„‚ fun x => Complex.sin (f x) := fun x => (hc x).csin theorem fderivWithin_csin (hf : DifferentiableWithinAt β„‚ f s x) (hxs : UniqueDiffWithinAt β„‚ s x) : fderivWithin β„‚ (fun x => Complex.sin (f x)) s x = Complex.cos (f x) β€’ fderivWithin β„‚ f s x := hf.hasFDerivWithinAt.csin.fderivWithin hxs @[simp] theorem fderiv_csin (hc : DifferentiableAt β„‚ f x) : fderiv β„‚ (fun x => Complex.sin (f x)) x = Complex.cos (f x) β€’ fderiv β„‚ f x := hc.hasFDerivAt.csin.fderiv theorem ContDiff.csin {n} (h : ContDiff β„‚ n f) : ContDiff β„‚ n fun x => Complex.sin (f x) := Complex.contDiff_sin.comp h theorem ContDiffAt.csin {n} (hf : ContDiffAt β„‚ n f x) : ContDiffAt β„‚ n (fun x => Complex.sin (f x)) x := Complex.contDiff_sin.contDiffAt.comp x hf theorem ContDiffOn.csin {n} (hf : ContDiffOn β„‚ n f s) : ContDiffOn β„‚ n (fun x => Complex.sin (f x)) s := Complex.contDiff_sin.comp_contDiffOn hf theorem ContDiffWithinAt.csin {n} (hf : ContDiffWithinAt β„‚ n f s x) : ContDiffWithinAt β„‚ n (fun x => Complex.sin (f x)) s x := Complex.contDiff_sin.contDiffAt.comp_contDiffWithinAt x hf /-! #### `Complex.cosh` -/ theorem HasStrictFDerivAt.ccosh (hf : HasStrictFDerivAt f f' x) : HasStrictFDerivAt (fun x => Complex.cosh (f x)) (Complex.sinh (f x) β€’ f') x := (Complex.hasStrictDerivAt_cosh (f x)).comp_hasStrictFDerivAt x hf theorem HasFDerivAt.ccosh (hf : HasFDerivAt f f' x) : HasFDerivAt (fun x => Complex.cosh (f x)) (Complex.sinh (f x) β€’ f') x := (Complex.hasDerivAt_cosh (f x)).comp_hasFDerivAt x hf theorem HasFDerivWithinAt.ccosh (hf : HasFDerivWithinAt f f' s x) : HasFDerivWithinAt (fun x => Complex.cosh (f x)) (Complex.sinh (f x) β€’ f') s x := (Complex.hasDerivAt_cosh (f x)).comp_hasFDerivWithinAt x hf theorem DifferentiableWithinAt.ccosh (hf : DifferentiableWithinAt β„‚ f s x) : DifferentiableWithinAt β„‚ (fun x => Complex.cosh (f x)) s x := hf.hasFDerivWithinAt.ccosh.differentiableWithinAt @[simp, fun_prop] theorem DifferentiableAt.ccosh (hc : DifferentiableAt β„‚ f x) : DifferentiableAt β„‚ (fun x => Complex.cosh (f x)) x := hc.hasFDerivAt.ccosh.differentiableAt theorem DifferentiableOn.ccosh (hc : DifferentiableOn β„‚ f s) : DifferentiableOn β„‚ (fun x => Complex.cosh (f x)) s := fun x h => (hc x h).ccosh @[simp, fun_prop] theorem Differentiable.ccosh (hc : Differentiable β„‚ f) : Differentiable β„‚ fun x => Complex.cosh (f x) := fun x => (hc x).ccosh theorem fderivWithin_ccosh (hf : DifferentiableWithinAt β„‚ f s x) (hxs : UniqueDiffWithinAt β„‚ s x) : fderivWithin β„‚ (fun x => Complex.cosh (f x)) s x = Complex.sinh (f x) β€’ fderivWithin β„‚ f s x := hf.hasFDerivWithinAt.ccosh.fderivWithin hxs @[simp] theorem fderiv_ccosh (hc : DifferentiableAt β„‚ f x) : fderiv β„‚ (fun x => Complex.cosh (f x)) x = Complex.sinh (f x) β€’ fderiv β„‚ f x := hc.hasFDerivAt.ccosh.fderiv theorem ContDiff.ccosh {n} (h : ContDiff β„‚ n f) : ContDiff β„‚ n fun x => Complex.cosh (f x) := Complex.contDiff_cosh.comp h theorem ContDiffAt.ccosh {n} (hf : ContDiffAt β„‚ n f x) : ContDiffAt β„‚ n (fun x => Complex.cosh (f x)) x := Complex.contDiff_cosh.contDiffAt.comp x hf theorem ContDiffOn.ccosh {n} (hf : ContDiffOn β„‚ n f s) : ContDiffOn β„‚ n (fun x => Complex.cosh (f x)) s := Complex.contDiff_cosh.comp_contDiffOn hf theorem ContDiffWithinAt.ccosh {n} (hf : ContDiffWithinAt β„‚ n f s x) : ContDiffWithinAt β„‚ n (fun x => Complex.cosh (f x)) s x := Complex.contDiff_cosh.contDiffAt.comp_contDiffWithinAt x hf /-! #### `Complex.sinh` -/ theorem HasStrictFDerivAt.csinh (hf : HasStrictFDerivAt f f' x) : HasStrictFDerivAt (fun x => Complex.sinh (f x)) (Complex.cosh (f x) β€’ f') x := (Complex.hasStrictDerivAt_sinh (f x)).comp_hasStrictFDerivAt x hf theorem HasFDerivAt.csinh (hf : HasFDerivAt f f' x) : HasFDerivAt (fun x => Complex.sinh (f x)) (Complex.cosh (f x) β€’ f') x := (Complex.hasDerivAt_sinh (f x)).comp_hasFDerivAt x hf theorem HasFDerivWithinAt.csinh (hf : HasFDerivWithinAt f f' s x) : HasFDerivWithinAt (fun x => Complex.sinh (f x)) (Complex.cosh (f x) β€’ f') s x := (Complex.hasDerivAt_sinh (f x)).comp_hasFDerivWithinAt x hf theorem DifferentiableWithinAt.csinh (hf : DifferentiableWithinAt β„‚ f s x) : DifferentiableWithinAt β„‚ (fun x => Complex.sinh (f x)) s x := hf.hasFDerivWithinAt.csinh.differentiableWithinAt @[simp, fun_prop] theorem DifferentiableAt.csinh (hc : DifferentiableAt β„‚ f x) : DifferentiableAt β„‚ (fun x => Complex.sinh (f x)) x := hc.hasFDerivAt.csinh.differentiableAt theorem DifferentiableOn.csinh (hc : DifferentiableOn β„‚ f s) : DifferentiableOn β„‚ (fun x => Complex.sinh (f x)) s := fun x h => (hc x h).csinh @[simp, fun_prop] theorem Differentiable.csinh (hc : Differentiable β„‚ f) : Differentiable β„‚ fun x => Complex.sinh (f x) := fun x => (hc x).csinh theorem fderivWithin_csinh (hf : DifferentiableWithinAt β„‚ f s x) (hxs : UniqueDiffWithinAt β„‚ s x) : fderivWithin β„‚ (fun x => Complex.sinh (f x)) s x = Complex.cosh (f x) β€’ fderivWithin β„‚ f s x := hf.hasFDerivWithinAt.csinh.fderivWithin hxs @[simp] theorem fderiv_csinh (hc : DifferentiableAt β„‚ f x) : fderiv β„‚ (fun x => Complex.sinh (f x)) x = Complex.cosh (f x) β€’ fderiv β„‚ f x := hc.hasFDerivAt.csinh.fderiv theorem ContDiff.csinh {n} (h : ContDiff β„‚ n f) : ContDiff β„‚ n fun x => Complex.sinh (f x) := Complex.contDiff_sinh.comp h theorem ContDiffAt.csinh {n} (hf : ContDiffAt β„‚ n f x) : ContDiffAt β„‚ n (fun x => Complex.sinh (f x)) x := Complex.contDiff_sinh.contDiffAt.comp x hf theorem ContDiffOn.csinh {n} (hf : ContDiffOn β„‚ n f s) : ContDiffOn β„‚ n (fun x => Complex.sinh (f x)) s := Complex.contDiff_sinh.comp_contDiffOn hf theorem ContDiffWithinAt.csinh {n} (hf : ContDiffWithinAt β„‚ n f s x) : ContDiffWithinAt β„‚ n (fun x => Complex.sinh (f x)) s x := Complex.contDiff_sinh.contDiffAt.comp_contDiffWithinAt x hf end namespace Real variable {x y z : ℝ} theorem hasStrictDerivAt_sin (x : ℝ) : HasStrictDerivAt sin (cos x) x := (Complex.hasStrictDerivAt_sin x).real_of_complex theorem hasDerivAt_sin (x : ℝ) : HasDerivAt sin (cos x) x := (hasStrictDerivAt_sin x).hasDerivAt theorem isEquivalent_sin : sin ~[𝓝 0] id := by simpa using (hasDerivAt_sin 0).isLittleO @[fun_prop] theorem contDiff_sin {n} : ContDiff ℝ n sin := Complex.contDiff_sin.real_of_complex @[simp] theorem differentiable_sin : Differentiable ℝ sin := fun x => (hasDerivAt_sin x).differentiableAt @[simp] theorem differentiableAt_sin : DifferentiableAt ℝ sin x := differentiable_sin x /-- The function `Real.sin` is real analytic. -/ @[fun_prop] lemma analyticAt_sin : AnalyticAt ℝ sin x := contDiff_sin.contDiffAt.analyticAt /-- The function `Real.sin` is real analytic. -/ lemma analyticWithinAt_sin {s : Set ℝ} : AnalyticWithinAt ℝ sin s x := contDiff_sin.contDiffWithinAt.analyticWithinAt /-- The function `Real.sin` is real analytic. -/ theorem analyticOnNhd_sin {s : Set ℝ} : AnalyticOnNhd ℝ sin s := fun _ _ ↦ analyticAt_sin /-- The function `Real.sin` is real analytic. -/ lemma analyticOn_sin {s : Set ℝ} : AnalyticOn ℝ sin s := contDiff_sin.contDiffOn.analyticOn @[simp] theorem deriv_sin : deriv sin = cos := funext fun x => (hasDerivAt_sin x).deriv theorem hasStrictDerivAt_cos (x : ℝ) : HasStrictDerivAt cos (-sin x) x := (Complex.hasStrictDerivAt_cos x).real_of_complex theorem hasDerivAt_cos (x : ℝ) : HasDerivAt cos (-sin x) x := (Complex.hasDerivAt_cos x).real_of_complex @[fun_prop] theorem contDiff_cos {n} : ContDiff ℝ n cos := Complex.contDiff_cos.real_of_complex @[simp] theorem differentiable_cos : Differentiable ℝ cos := fun x => (hasDerivAt_cos x).differentiableAt @[simp] theorem differentiableAt_cos : DifferentiableAt ℝ cos x := differentiable_cos x /-- The function `Real.cos` is real analytic. -/ @[fun_prop] lemma analyticAt_cos : AnalyticAt ℝ cos x := contDiff_cos.contDiffAt.analyticAt /-- The function `Real.cos` is real analytic. -/ lemma analyticWithinAt_cos {s : Set ℝ} : AnalyticWithinAt ℝ cos s x := contDiff_cos.contDiffWithinAt.analyticWithinAt /-- The function `Real.cos` is real analytic. -/ theorem analyticOnNhd_cos {s : Set ℝ} : AnalyticOnNhd ℝ cos s := fun _ _ ↦ analyticAt_cos /-- The function `Real.cos` is real analytic. -/ lemma analyticOn_cos {s : Set ℝ} : AnalyticOn ℝ cos s := contDiff_cos.contDiffOn.analyticOn theorem deriv_cos : deriv cos x = -sin x := (hasDerivAt_cos x).deriv @[simp] theorem deriv_cos' : deriv cos = fun x => -sin x := funext fun _ => deriv_cos theorem hasStrictDerivAt_sinh (x : ℝ) : HasStrictDerivAt sinh (cosh x) x := (Complex.hasStrictDerivAt_sinh x).real_of_complex theorem hasDerivAt_sinh (x : ℝ) : HasDerivAt sinh (cosh x) x := (Complex.hasDerivAt_sinh x).real_of_complex theorem isEquivalent_sinh : sinh ~[𝓝 0] id := by simpa using (hasDerivAt_sinh 0).isLittleO @[fun_prop] theorem contDiff_sinh {n} : ContDiff ℝ n sinh := Complex.contDiff_sinh.real_of_complex @[simp] theorem differentiable_sinh : Differentiable ℝ sinh := fun x => (hasDerivAt_sinh x).differentiableAt @[simp] theorem differentiableAt_sinh : DifferentiableAt ℝ sinh x := differentiable_sinh x /-- The function `Real.sinh` is real analytic. -/ @[fun_prop] lemma analyticAt_sinh : AnalyticAt ℝ sinh x := contDiff_sinh.contDiffAt.analyticAt /-- The function `Real.sinh` is real analytic. -/ lemma analyticWithinAt_sinh {s : Set ℝ} : AnalyticWithinAt ℝ sinh s x := contDiff_sinh.contDiffWithinAt.analyticWithinAt /-- The function `Real.sinh` is real analytic. -/ theorem analyticOnNhd_sinh {s : Set ℝ} : AnalyticOnNhd ℝ sinh s := fun _ _ ↦ analyticAt_sinh /-- The function `Real.sinh` is real analytic. -/ lemma analyticOn_sinh {s : Set ℝ} : AnalyticOn ℝ sinh s := contDiff_sinh.contDiffOn.analyticOn @[simp] theorem deriv_sinh : deriv sinh = cosh := funext fun x => (hasDerivAt_sinh x).deriv theorem hasStrictDerivAt_cosh (x : ℝ) : HasStrictDerivAt cosh (sinh x) x := (Complex.hasStrictDerivAt_cosh x).real_of_complex theorem hasDerivAt_cosh (x : ℝ) : HasDerivAt cosh (sinh x) x := (Complex.hasDerivAt_cosh x).real_of_complex @[fun_prop] theorem contDiff_cosh {n} : ContDiff ℝ n cosh := Complex.contDiff_cosh.real_of_complex @[simp] theorem differentiable_cosh : Differentiable ℝ cosh := fun x => (hasDerivAt_cosh x).differentiableAt @[simp] theorem differentiableAt_cosh : DifferentiableAt ℝ cosh x := differentiable_cosh x /-- The function `Real.cosh` is real analytic. -/ @[fun_prop] lemma analyticAt_cosh : AnalyticAt ℝ cosh x := contDiff_cosh.contDiffAt.analyticAt /-- The function `Real.cosh` is real analytic. -/ lemma analyticWithinAt_cosh {s : Set ℝ} : AnalyticWithinAt ℝ cosh s x := contDiff_cosh.contDiffWithinAt.analyticWithinAt /-- The function `Real.cosh` is real analytic. -/ theorem analyticOnNhd_cosh {s : Set ℝ} : AnalyticOnNhd ℝ cosh s := fun _ _ ↦ analyticAt_cosh /-- The function `Real.cosh` is real analytic. -/ lemma analyticOn_cosh {s : Set ℝ} : AnalyticOn ℝ cosh s := contDiff_cosh.contDiffOn.analyticOn @[simp] theorem deriv_cosh : deriv cosh = sinh := funext fun x => (hasDerivAt_cosh x).deriv /-- `sinh` is strictly monotone. -/ theorem sinh_strictMono : StrictMono sinh := strictMono_of_deriv_pos <| by rw [Real.deriv_sinh]; exact cosh_pos /-- `sinh` is injective, `βˆ€ a b, sinh a = sinh b β†’ a = b`. -/ theorem sinh_injective : Function.Injective sinh := sinh_strictMono.injective @[simp] theorem sinh_inj : sinh x = sinh y ↔ x = y := sinh_injective.eq_iff @[simp] theorem sinh_le_sinh : sinh x ≀ sinh y ↔ x ≀ y := sinh_strictMono.le_iff_le @[simp] theorem sinh_lt_sinh : sinh x < sinh y ↔ x < y := sinh_strictMono.lt_iff_lt @[simp] lemma sinh_eq_zero : sinh x = 0 ↔ x = 0 := by rw [← @sinh_inj x, sinh_zero] lemma sinh_ne_zero : sinh x β‰  0 ↔ x β‰  0 := sinh_eq_zero.not @[simp] theorem sinh_pos_iff : 0 < sinh x ↔ 0 < x := by simpa only [sinh_zero] using @sinh_lt_sinh 0 x @[simp] theorem sinh_nonpos_iff : sinh x ≀ 0 ↔ x ≀ 0 := by simpa only [sinh_zero] using @sinh_le_sinh x 0 @[simp] theorem sinh_neg_iff : sinh x < 0 ↔ x < 0 := by simpa only [sinh_zero] using @sinh_lt_sinh x 0 @[simp] theorem sinh_nonneg_iff : 0 ≀ sinh x ↔ 0 ≀ x := by simpa only [sinh_zero] using @sinh_le_sinh 0 x theorem abs_sinh (x : ℝ) : |sinh x| = sinh |x| := by cases le_total x 0 <;> simp [abs_of_nonneg, abs_of_nonpos, *] theorem cosh_strictMonoOn : StrictMonoOn cosh (Ici 0) := strictMonoOn_of_deriv_pos (convex_Ici _) continuous_cosh.continuousOn fun x hx => by rw [interior_Ici, mem_Ioi] at hx; rwa [deriv_cosh, sinh_pos_iff] @[simp] theorem cosh_le_cosh : cosh x ≀ cosh y ↔ |x| ≀ |y| := cosh_abs x β–Έ cosh_abs y β–Έ cosh_strictMonoOn.le_iff_le (abs_nonneg x) (abs_nonneg y) @[simp] theorem cosh_lt_cosh : cosh x < cosh y ↔ |x| < |y| := lt_iff_lt_of_le_iff_le cosh_le_cosh @[simp] theorem one_le_cosh (x : ℝ) : 1 ≀ cosh x := cosh_zero β–Έ cosh_le_cosh.2 (by simp only [_root_.abs_zero, _root_.abs_nonneg]) @[simp] theorem one_lt_cosh : 1 < cosh x ↔ x β‰  0 := cosh_zero β–Έ cosh_lt_cosh.trans (by simp only [_root_.abs_zero, abs_pos]) theorem sinh_sub_id_strictMono : StrictMono fun x => sinh x - x := by refine strictMono_of_odd_strictMonoOn_nonneg (fun x => by simp; abel) ?_ refine strictMonoOn_of_deriv_pos (convex_Ici _) ?_ fun x hx => ?_ Β· exact (continuous_sinh.sub continuous_id).continuousOn Β· rw [interior_Ici, mem_Ioi] at hx rw [deriv_fun_sub, deriv_sinh, deriv_id'', sub_pos, one_lt_cosh] exacts [hx.ne', differentiableAt_sinh, differentiableAt_id] @[simp] theorem self_le_sinh_iff : x ≀ sinh x ↔ 0 ≀ x := calc x ≀ sinh x ↔ sinh 0 - 0 ≀ sinh x - x := by simp _ ↔ 0 ≀ x := sinh_sub_id_strictMono.le_iff_le @[simp] theorem sinh_le_self_iff : sinh x ≀ x ↔ x ≀ 0 := calc sinh x ≀ x ↔ sinh x - x ≀ sinh 0 - 0 := by simp _ ↔ x ≀ 0 := sinh_sub_id_strictMono.le_iff_le @[simp] theorem self_lt_sinh_iff : x < sinh x ↔ 0 < x := lt_iff_lt_of_le_iff_le sinh_le_self_iff @[simp] theorem sinh_lt_self_iff : sinh x < x ↔ x < 0 := lt_iff_lt_of_le_iff_le self_le_sinh_iff end Real section iteratedDeriv /-! ### Simp lemmas for iterated derivatives of `sin` and `cos`. -/ namespace Complex @[simp] theorem iteratedDeriv_add_one_sin (n : β„•) : iteratedDeriv (n + 1) sin = iteratedDeriv n cos := by induction n with | zero => simp | succ n ih => rw [iteratedDeriv_succ, ih, iteratedDeriv_succ] @[simp] theorem iteratedDeriv_add_one_cos (n : β„•) : iteratedDeriv (n + 1) cos = - iteratedDeriv n sin := by induction n with | zero => ext; simp | succ n ih => rw [iteratedDeriv_succ, ih, iteratedDeriv_succ, deriv.neg'] ext x simp @[simp] theorem iteratedDeriv_even_sin (n : β„•) : iteratedDeriv (2 * n) sin = (-1) ^ n * sin := by induction n with | zero => simp | succ n ih => simp_all [mul_add, pow_succ] @[simp] theorem iteratedDeriv_even_cos (n : β„•) : iteratedDeriv (2 * n) cos = (-1) ^ n * cos := by induction n with | zero => simp | succ n ih => simp_all [mul_add, pow_succ] theorem iteratedDeriv_odd_sin (n : β„•) : iteratedDeriv (2 * n + 1) sin = (-1) ^ n * cos := by simp theorem iteratedDeriv_odd_cos (n : β„•) : iteratedDeriv (2 * n + 1) cos = (-1) ^ (n + 1) * sin := by simp [pow_succ] theorem differentiable_iteratedDeriv_sin (n : β„•) : Differentiable β„‚ (iteratedDeriv n sin) := match n with | 0 => by simp | 1 => by simp | n + 2 => by simp [differentiable_iteratedDeriv_sin] theorem differentiable_iteratedDeriv_cos (n : β„•) : Differentiable β„‚ (iteratedDeriv n cos) := match n with | 0 => by simp | 1 => by simp | n + 2 => by simp [differentiable_iteratedDeriv_cos] @[simp] theorem iteratedDeriv_add_one_sinh (n : β„•) : iteratedDeriv (n + 1) sinh = iteratedDeriv n cosh := by induction n with | zero => simp | succ n ih => rw [iteratedDeriv_succ, ih, iteratedDeriv_succ] @[simp] theorem iteratedDeriv_add_one_cosh (n : β„•) : iteratedDeriv (n + 1) cosh = iteratedDeriv n sinh := by induction n with | zero => ext; simp | succ n ih => rw [iteratedDeriv_succ, ih, iteratedDeriv_succ] @[simp] theorem iteratedDeriv_even_sinh (n : β„•) : iteratedDeriv (2 * n) sinh = sinh := by induction n with | zero => simp | succ n ih => simp_all [mul_add] @[simp] theorem iteratedDeriv_even_cosh (n : β„•) : iteratedDeriv (2 * n) cosh = cosh := by induction n with | zero => simp | succ n ih => simp_all [mul_add] theorem iteratedDeriv_odd_sinh (n : β„•) : iteratedDeriv (2 * n + 1) sinh = cosh := by simp theorem iteratedDeriv_odd_cosh (n : β„•) : iteratedDeriv (2 * n + 1) cosh = sinh := by simp theorem differentiable_iteratedDeriv_sinh (n : β„•) : Differentiable β„‚ (iteratedDeriv n sinh) := match n with | 0 => by simp | 1 => by simp | n + 2 => by simp [differentiable_iteratedDeriv_sinh] theorem differentiable_iteratedDeriv_cosh (n : β„•) : Differentiable β„‚ (iteratedDeriv n cosh) := match n with | 0 => by simp | 1 => by simp | n + 2 => by simp [differentiable_iteratedDeriv_cosh] end Complex namespace Real @[simp] theorem iteratedDeriv_add_one_sin (n : β„•) : iteratedDeriv (n + 1) sin = iteratedDeriv n cos := by induction n with | zero => simp | succ n ih => rw [iteratedDeriv_succ, ih, iteratedDeriv_succ] @[simp] theorem iteratedDeriv_add_one_cos (n : β„•) : iteratedDeriv (n + 1) cos = - iteratedDeriv n sin := by induction n with | zero => ext; simp | succ n ih => rw [iteratedDeriv_succ, ih, iteratedDeriv_succ, deriv.neg'] ext x simp @[simp] theorem iteratedDeriv_even_sin (n : β„•) : iteratedDeriv (2 * n) sin = (-1) ^ n * sin := by induction n with | zero => simp | succ n ih => simp_all [mul_add, pow_succ] @[simp] theorem iteratedDeriv_even_cos (n : β„•) : iteratedDeriv (2 * n) cos = (-1) ^ n * cos := by induction n with | zero => simp | succ n ih => simp_all [mul_add, pow_succ] theorem iteratedDeriv_odd_sin (n : β„•) : iteratedDeriv (2 * n + 1) sin = (-1) ^ n * cos := by simp theorem iteratedDeriv_odd_cos (n : β„•) : iteratedDeriv (2 * n + 1) cos = (-1) ^ (n + 1) * sin := by simp [pow_succ] theorem differentiable_iteratedDeriv_sin (n : β„•) : Differentiable ℝ (iteratedDeriv n sin) := match n with | 0 => by simp | 1 => by simp | n + 2 => by simp [differentiable_iteratedDeriv_sin] theorem differentiable_iteratedDeriv_cos (n : β„•) : Differentiable ℝ (iteratedDeriv n cos) := match n with | 0 => by simp | 1 => by simp | n + 2 => by simp [differentiable_iteratedDeriv_cos] theorem abs_iteratedDeriv_sin_le_one (n : β„•) (x : ℝ) : |iteratedDeriv n sin x| ≀ 1 := match n with | 0 => by simpa using Real.abs_sin_le_one x | 1 => by simpa using Real.abs_cos_le_one x | n + 2 => by simpa using abs_iteratedDeriv_sin_le_one n x theorem abs_iteratedDeriv_cos_le_one (n : β„•) (x : ℝ) : |iteratedDeriv n cos x| ≀ 1 := match n with | 0 => by simpa using Real.abs_cos_le_one x | 1 => by simpa using Real.abs_sin_le_one x | n + 2 => by simpa using abs_iteratedDeriv_cos_le_one n x @[simp] theorem iteratedDeriv_add_one_sinh (n : β„•) : iteratedDeriv (n + 1) sinh = iteratedDeriv n cosh := by induction n with | zero => simp | succ n ih => rw [iteratedDeriv_succ, ih, iteratedDeriv_succ] @[simp] theorem iteratedDeriv_add_one_cosh (n : β„•) : iteratedDeriv (n + 1) cosh = iteratedDeriv n sinh := by induction n with | zero => ext; simp | succ n ih => rw [iteratedDeriv_succ, ih, iteratedDeriv_succ] @[simp] theorem iteratedDeriv_even_sinh (n : β„•) : iteratedDeriv (2 * n) sinh = sinh := by induction n with | zero => simp | succ n ih => simp_all [mul_add] @[simp] theorem iteratedDeriv_even_cosh (n : β„•) : iteratedDeriv (2 * n) cosh = cosh := by induction n with | zero => simp | succ n ih => simp_all [mul_add] theorem iteratedDeriv_odd_sinh (n : β„•) : iteratedDeriv (2 * n + 1) sinh = cosh := by simp theorem iteratedDeriv_odd_cosh (n : β„•) : iteratedDeriv (2 * n + 1) cosh = sinh := by simp theorem differentiable_iteratedDeriv_sinh (n : β„•) : Differentiable ℝ (iteratedDeriv n sinh) := match n with | 0 => by simp | 1 => by simp | n + 2 => by simp [differentiable_iteratedDeriv_sinh] theorem differentiable_iteratedDeriv_cosh (n : β„•) : Differentiable ℝ (iteratedDeriv n cosh) := match n with | 0 => by simp | 1 => by simp | n + 2 => by simp [differentiable_iteratedDeriv_cosh] @[simp] theorem iteratedDerivWithin_sin_Icc (n : β„•) {a b : ℝ} (h : a < b) {x : ℝ} (hx : x ∈ Icc a b) : iteratedDerivWithin n sin (Icc a b) x = iteratedDeriv n sin x := iteratedDerivWithin_eq_iteratedDeriv (uniqueDiffOn_Icc h) contDiff_sin.contDiffAt hx @[simp] theorem iteratedDerivWithin_cos_Icc (n : β„•) {a b : ℝ} (h : a < b) {x : ℝ} (hx : x ∈ Icc a b) : iteratedDerivWithin n cos (Icc a b) x = iteratedDeriv n cos x := iteratedDerivWithin_eq_iteratedDeriv (uniqueDiffOn_Icc h) contDiff_cos.contDiffAt hx @[simp] theorem iteratedDerivWithin_sinh_Icc (n : β„•) {a b : ℝ} (h : a < b) {x : ℝ} (hx : x ∈ Icc a b) : iteratedDerivWithin n sinh (Icc a b) x = iteratedDeriv n sinh x := iteratedDerivWithin_eq_iteratedDeriv (uniqueDiffOn_Icc h) contDiff_sinh.contDiffAt hx @[simp] theorem iteratedDerivWithin_cosh_Icc (n : β„•) {a b : ℝ} (h : a < b) {x : ℝ} (hx : x ∈ Icc a b) : iteratedDerivWithin n cosh (Icc a b) x = iteratedDeriv n cosh x := iteratedDerivWithin_eq_iteratedDeriv (uniqueDiffOn_Icc h) contDiff_cosh.contDiffAt hx @[simp] theorem iteratedDerivWithin_sin_Ioo (n : β„•) {a b x : ℝ} (hx : x ∈ Ioo a b) : iteratedDerivWithin n sin (Ioo a b) x = iteratedDeriv n sin x := iteratedDerivWithin_eq_iteratedDeriv (uniqueDiffOn_Ioo a b) contDiff_sin.contDiffAt hx @[simp] theorem iteratedDerivWithin_cos_Ioo (n : β„•) {a b x : ℝ} (hx : x ∈ Ioo a b) : iteratedDerivWithin n cos (Ioo a b) x = iteratedDeriv n cos x := iteratedDerivWithin_eq_iteratedDeriv (uniqueDiffOn_Ioo a b) contDiff_cos.contDiffAt hx @[simp] theorem iteratedDerivWithin_sinh_Ioo (n : β„•) {a b x : ℝ} (hx : x ∈ Ioo a b) : iteratedDerivWithin n sinh (Ioo a b) x = iteratedDeriv n sinh x := iteratedDerivWithin_eq_iteratedDeriv (uniqueDiffOn_Ioo a b) contDiff_sinh.contDiffAt hx @[simp] theorem iteratedDerivWithin_cosh_Ioo (n : β„•) {a b x : ℝ} (hx : x ∈ Ioo a b) : iteratedDerivWithin n cosh (Ioo a b) x = iteratedDeriv n cosh x := iteratedDerivWithin_eq_iteratedDeriv (uniqueDiffOn_Ioo a b) contDiff_cosh.contDiffAt hx end Real end iteratedDeriv section /-! ### Simp lemmas for derivatives of `fun x => Real.cos (f x)` etc., `f : ℝ β†’ ℝ` -/ variable {f : ℝ β†’ ℝ} {f' x : ℝ} {s : Set ℝ} /-! #### `Real.cos` -/ theorem HasStrictDerivAt.cos (hf : HasStrictDerivAt f f' x) : HasStrictDerivAt (fun x => Real.cos (f x)) (-Real.sin (f x) * f') x := (Real.hasStrictDerivAt_cos (f x)).comp x hf theorem HasDerivAt.cos (hf : HasDerivAt f f' x) : HasDerivAt (fun x => Real.cos (f x)) (-Real.sin (f x) * f') x := (Real.hasDerivAt_cos (f x)).comp x hf theorem HasDerivWithinAt.cos (hf : HasDerivWithinAt f f' s x) : HasDerivWithinAt (fun x => Real.cos (f x)) (-Real.sin (f x) * f') s x := (Real.hasDerivAt_cos (f x)).comp_hasDerivWithinAt x hf theorem derivWithin_cos (hf : DifferentiableWithinAt ℝ f s x) (hxs : UniqueDiffWithinAt ℝ s x) : derivWithin (fun x => Real.cos (f x)) s x = -Real.sin (f x) * derivWithin f s x := hf.hasDerivWithinAt.cos.derivWithin hxs @[simp] theorem deriv_cos (hc : DifferentiableAt ℝ f x) : deriv (fun x => Real.cos (f x)) x = -Real.sin (f x) * deriv f x := hc.hasDerivAt.cos.deriv /-! #### `Real.sin` -/ theorem HasStrictDerivAt.sin (hf : HasStrictDerivAt f f' x) : HasStrictDerivAt (fun x => Real.sin (f x)) (Real.cos (f x) * f') x := (Real.hasStrictDerivAt_sin (f x)).comp x hf theorem HasDerivAt.sin (hf : HasDerivAt f f' x) : HasDerivAt (fun x => Real.sin (f x)) (Real.cos (f x) * f') x := (Real.hasDerivAt_sin (f x)).comp x hf theorem HasDerivWithinAt.sin (hf : HasDerivWithinAt f f' s x) : HasDerivWithinAt (fun x => Real.sin (f x)) (Real.cos (f x) * f') s x := (Real.hasDerivAt_sin (f x)).comp_hasDerivWithinAt x hf theorem derivWithin_sin (hf : DifferentiableWithinAt ℝ f s x) (hxs : UniqueDiffWithinAt ℝ s x) : derivWithin (fun x => Real.sin (f x)) s x = Real.cos (f x) * derivWithin f s x := hf.hasDerivWithinAt.sin.derivWithin hxs @[simp] theorem deriv_sin (hc : DifferentiableAt ℝ f x) : deriv (fun x => Real.sin (f x)) x = Real.cos (f x) * deriv f x := hc.hasDerivAt.sin.deriv /-! #### `Real.cosh` -/ theorem HasStrictDerivAt.cosh (hf : HasStrictDerivAt f f' x) : HasStrictDerivAt (fun x => Real.cosh (f x)) (Real.sinh (f x) * f') x := (Real.hasStrictDerivAt_cosh (f x)).comp x hf theorem HasDerivAt.cosh (hf : HasDerivAt f f' x) : HasDerivAt (fun x => Real.cosh (f x)) (Real.sinh (f x) * f') x := (Real.hasDerivAt_cosh (f x)).comp x hf theorem HasDerivWithinAt.cosh (hf : HasDerivWithinAt f f' s x) : HasDerivWithinAt (fun x => Real.cosh (f x)) (Real.sinh (f x) * f') s x := (Real.hasDerivAt_cosh (f x)).comp_hasDerivWithinAt x hf theorem derivWithin_cosh (hf : DifferentiableWithinAt ℝ f s x) (hxs : UniqueDiffWithinAt ℝ s x) : derivWithin (fun x => Real.cosh (f x)) s x = Real.sinh (f x) * derivWithin f s x := hf.hasDerivWithinAt.cosh.derivWithin hxs @[simp] theorem deriv_cosh (hc : DifferentiableAt ℝ f x) : deriv (fun x => Real.cosh (f x)) x = Real.sinh (f x) * deriv f x := hc.hasDerivAt.cosh.deriv /-! #### `Real.sinh` -/ theorem HasStrictDerivAt.sinh (hf : HasStrictDerivAt f f' x) : HasStrictDerivAt (fun x => Real.sinh (f x)) (Real.cosh (f x) * f') x := (Real.hasStrictDerivAt_sinh (f x)).comp x hf theorem HasDerivAt.sinh (hf : HasDerivAt f f' x) : HasDerivAt (fun x => Real.sinh (f x)) (Real.cosh (f x) * f') x := (Real.hasDerivAt_sinh (f x)).comp x hf theorem HasDerivWithinAt.sinh (hf : HasDerivWithinAt f f' s x) : HasDerivWithinAt (fun x => Real.sinh (f x)) (Real.cosh (f x) * f') s x := (Real.hasDerivAt_sinh (f x)).comp_hasDerivWithinAt x hf theorem derivWithin_sinh (hf : DifferentiableWithinAt ℝ f s x) (hxs : UniqueDiffWithinAt ℝ s x) : derivWithin (fun x => Real.sinh (f x)) s x = Real.cosh (f x) * derivWithin f s x := hf.hasDerivWithinAt.sinh.derivWithin hxs @[simp] theorem deriv_sinh (hc : DifferentiableAt ℝ f x) : deriv (fun x => Real.sinh (f x)) x = Real.cosh (f x) * deriv f x := hc.hasDerivAt.sinh.deriv end section /-! ### Simp lemmas for derivatives of `fun x => Real.cos (f x)` etc., `f : E β†’ ℝ` -/ variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] {f : E β†’ ℝ} {f' : StrongDual ℝ E} {x : E} {s : Set E} /-! #### `Real.cos` -/ theorem HasStrictFDerivAt.cos (hf : HasStrictFDerivAt f f' x) : HasStrictFDerivAt (fun x => Real.cos (f x)) (-Real.sin (f x) β€’ f') x := (Real.hasStrictDerivAt_cos (f x)).comp_hasStrictFDerivAt x hf theorem HasFDerivAt.cos (hf : HasFDerivAt f f' x) : HasFDerivAt (fun x => Real.cos (f x)) (-Real.sin (f x) β€’ f') x := (Real.hasDerivAt_cos (f x)).comp_hasFDerivAt x hf theorem HasFDerivWithinAt.cos (hf : HasFDerivWithinAt f f' s x) : HasFDerivWithinAt (fun x => Real.cos (f x)) (-Real.sin (f x) β€’ f') s x := (Real.hasDerivAt_cos (f x)).comp_hasFDerivWithinAt x hf theorem DifferentiableWithinAt.cos (hf : DifferentiableWithinAt ℝ f s x) : DifferentiableWithinAt ℝ (fun x => Real.cos (f x)) s x := hf.hasFDerivWithinAt.cos.differentiableWithinAt @[simp, fun_prop] theorem DifferentiableAt.cos (hc : DifferentiableAt ℝ f x) : DifferentiableAt ℝ (fun x => Real.cos (f x)) x := hc.hasFDerivAt.cos.differentiableAt theorem DifferentiableOn.cos (hc : DifferentiableOn ℝ f s) : DifferentiableOn ℝ (fun x => Real.cos (f x)) s := fun x h => (hc x h).cos @[simp, fun_prop] theorem Differentiable.cos (hc : Differentiable ℝ f) : Differentiable ℝ fun x => Real.cos (f x) := fun x => (hc x).cos theorem fderivWithin_cos (hf : DifferentiableWithinAt ℝ f s x) (hxs : UniqueDiffWithinAt ℝ s x) : fderivWithin ℝ (fun x => Real.cos (f x)) s x = -Real.sin (f x) β€’ fderivWithin ℝ f s x := hf.hasFDerivWithinAt.cos.fderivWithin hxs @[simp] theorem fderiv_cos (hc : DifferentiableAt ℝ f x) : fderiv ℝ (fun x => Real.cos (f x)) x = -Real.sin (f x) β€’ fderiv ℝ f x := hc.hasFDerivAt.cos.fderiv theorem ContDiff.cos {n} (h : ContDiff ℝ n f) : ContDiff ℝ n fun x => Real.cos (f x) := Real.contDiff_cos.comp h theorem ContDiffAt.cos {n} (hf : ContDiffAt ℝ n f x) : ContDiffAt ℝ n (fun x => Real.cos (f x)) x := Real.contDiff_cos.contDiffAt.comp x hf theorem ContDiffOn.cos {n} (hf : ContDiffOn ℝ n f s) : ContDiffOn ℝ n (fun x => Real.cos (f x)) s := Real.contDiff_cos.comp_contDiffOn hf theorem ContDiffWithinAt.cos {n} (hf : ContDiffWithinAt ℝ n f s x) : ContDiffWithinAt ℝ n (fun x => Real.cos (f x)) s x := Real.contDiff_cos.contDiffAt.comp_contDiffWithinAt x hf /-! #### `Real.sin` -/ theorem HasStrictFDerivAt.sin (hf : HasStrictFDerivAt f f' x) : HasStrictFDerivAt (fun x => Real.sin (f x)) (Real.cos (f x) β€’ f') x := (Real.hasStrictDerivAt_sin (f x)).comp_hasStrictFDerivAt x hf theorem HasFDerivAt.sin (hf : HasFDerivAt f f' x) : HasFDerivAt (fun x => Real.sin (f x)) (Real.cos (f x) β€’ f') x := (Real.hasDerivAt_sin (f x)).comp_hasFDerivAt x hf theorem HasFDerivWithinAt.sin (hf : HasFDerivWithinAt f f' s x) : HasFDerivWithinAt (fun x => Real.sin (f x)) (Real.cos (f x) β€’ f') s x := (Real.hasDerivAt_sin (f x)).comp_hasFDerivWithinAt x hf theorem DifferentiableWithinAt.sin (hf : DifferentiableWithinAt ℝ f s x) : DifferentiableWithinAt ℝ (fun x => Real.sin (f x)) s x := hf.hasFDerivWithinAt.sin.differentiableWithinAt @[simp, fun_prop] theorem DifferentiableAt.sin (hc : DifferentiableAt ℝ f x) : DifferentiableAt ℝ (fun x => Real.sin (f x)) x := hc.hasFDerivAt.sin.differentiableAt theorem DifferentiableOn.sin (hc : DifferentiableOn ℝ f s) : DifferentiableOn ℝ (fun x => Real.sin (f x)) s := fun x h => (hc x h).sin @[simp, fun_prop] theorem Differentiable.sin (hc : Differentiable ℝ f) : Differentiable ℝ fun x => Real.sin (f x) := fun x => (hc x).sin theorem fderivWithin_sin (hf : DifferentiableWithinAt ℝ f s x) (hxs : UniqueDiffWithinAt ℝ s x) : fderivWithin ℝ (fun x => Real.sin (f x)) s x = Real.cos (f x) β€’ fderivWithin ℝ f s x := hf.hasFDerivWithinAt.sin.fderivWithin hxs @[simp] theorem fderiv_sin (hc : DifferentiableAt ℝ f x) : fderiv ℝ (fun x => Real.sin (f x)) x = Real.cos (f x) β€’ fderiv ℝ f x := hc.hasFDerivAt.sin.fderiv theorem ContDiff.sin {n} (h : ContDiff ℝ n f) : ContDiff ℝ n fun x => Real.sin (f x) := Real.contDiff_sin.comp h theorem ContDiffAt.sin {n} (hf : ContDiffAt ℝ n f x) : ContDiffAt ℝ n (fun x => Real.sin (f x)) x := Real.contDiff_sin.contDiffAt.comp x hf theorem ContDiffOn.sin {n} (hf : ContDiffOn ℝ n f s) : ContDiffOn ℝ n (fun x => Real.sin (f x)) s := Real.contDiff_sin.comp_contDiffOn hf theorem ContDiffWithinAt.sin {n} (hf : ContDiffWithinAt ℝ n f s x) : ContDiffWithinAt ℝ n (fun x => Real.sin (f x)) s x := Real.contDiff_sin.contDiffAt.comp_contDiffWithinAt x hf /-! #### `Real.cosh` -/ theorem HasStrictFDerivAt.cosh (hf : HasStrictFDerivAt f f' x) : HasStrictFDerivAt (fun x => Real.cosh (f x)) (Real.sinh (f x) β€’ f') x := (Real.hasStrictDerivAt_cosh (f x)).comp_hasStrictFDerivAt x hf theorem HasFDerivAt.cosh (hf : HasFDerivAt f f' x) : HasFDerivAt (fun x => Real.cosh (f x)) (Real.sinh (f x) β€’ f') x := (Real.hasDerivAt_cosh (f x)).comp_hasFDerivAt x hf theorem HasFDerivWithinAt.cosh (hf : HasFDerivWithinAt f f' s x) : HasFDerivWithinAt (fun x => Real.cosh (f x)) (Real.sinh (f x) β€’ f') s x := (Real.hasDerivAt_cosh (f x)).comp_hasFDerivWithinAt x hf theorem DifferentiableWithinAt.cosh (hf : DifferentiableWithinAt ℝ f s x) : DifferentiableWithinAt ℝ (fun x => Real.cosh (f x)) s x := hf.hasFDerivWithinAt.cosh.differentiableWithinAt @[simp, fun_prop] theorem DifferentiableAt.cosh (hc : DifferentiableAt ℝ f x) : DifferentiableAt ℝ (fun x => Real.cosh (f x)) x := hc.hasFDerivAt.cosh.differentiableAt theorem DifferentiableOn.cosh (hc : DifferentiableOn ℝ f s) : DifferentiableOn ℝ (fun x => Real.cosh (f x)) s := fun x h => (hc x h).cosh @[simp, fun_prop] theorem Differentiable.cosh (hc : Differentiable ℝ f) : Differentiable ℝ fun x => Real.cosh (f x) := fun x => (hc x).cosh theorem fderivWithin_cosh (hf : DifferentiableWithinAt ℝ f s x) (hxs : UniqueDiffWithinAt ℝ s x) : fderivWithin ℝ (fun x => Real.cosh (f x)) s x = Real.sinh (f x) β€’ fderivWithin ℝ f s x := hf.hasFDerivWithinAt.cosh.fderivWithin hxs @[simp] theorem fderiv_cosh (hc : DifferentiableAt ℝ f x) : fderiv ℝ (fun x => Real.cosh (f x)) x = Real.sinh (f x) β€’ fderiv ℝ f x := hc.hasFDerivAt.cosh.fderiv theorem ContDiff.cosh {n} (h : ContDiff ℝ n f) : ContDiff ℝ n fun x => Real.cosh (f x) := Real.contDiff_cosh.comp h theorem ContDiffAt.cosh {n} (hf : ContDiffAt ℝ n f x) : ContDiffAt ℝ n (fun x => Real.cosh (f x)) x := Real.contDiff_cosh.contDiffAt.comp x hf theorem ContDiffOn.cosh {n} (hf : ContDiffOn ℝ n f s) : ContDiffOn ℝ n (fun x => Real.cosh (f x)) s := Real.contDiff_cosh.comp_contDiffOn hf theorem ContDiffWithinAt.cosh {n} (hf : ContDiffWithinAt ℝ n f s x) : ContDiffWithinAt ℝ n (fun x => Real.cosh (f x)) s x := Real.contDiff_cosh.contDiffAt.comp_contDiffWithinAt x hf /-! #### `Real.sinh` -/ theorem HasStrictFDerivAt.sinh (hf : HasStrictFDerivAt f f' x) : HasStrictFDerivAt (fun x => Real.sinh (f x)) (Real.cosh (f x) β€’ f') x := (Real.hasStrictDerivAt_sinh (f x)).comp_hasStrictFDerivAt x hf theorem HasFDerivAt.sinh (hf : HasFDerivAt f f' x) : HasFDerivAt (fun x => Real.sinh (f x)) (Real.cosh (f x) β€’ f') x := (Real.hasDerivAt_sinh (f x)).comp_hasFDerivAt x hf theorem HasFDerivWithinAt.sinh (hf : HasFDerivWithinAt f f' s x) : HasFDerivWithinAt (fun x => Real.sinh (f x)) (Real.cosh (f x) β€’ f') s x := (Real.hasDerivAt_sinh (f x)).comp_hasFDerivWithinAt x hf theorem DifferentiableWithinAt.sinh (hf : DifferentiableWithinAt ℝ f s x) : DifferentiableWithinAt ℝ (fun x => Real.sinh (f x)) s x := hf.hasFDerivWithinAt.sinh.differentiableWithinAt @[simp, fun_prop] theorem DifferentiableAt.sinh (hc : DifferentiableAt ℝ f x) : DifferentiableAt ℝ (fun x => Real.sinh (f x)) x := hc.hasFDerivAt.sinh.differentiableAt theorem DifferentiableOn.sinh (hc : DifferentiableOn ℝ f s) : DifferentiableOn ℝ (fun x => Real.sinh (f x)) s := fun x h => (hc x h).sinh @[simp, fun_prop] theorem Differentiable.sinh (hc : Differentiable ℝ f) : Differentiable ℝ fun x => Real.sinh (f x) := fun x => (hc x).sinh theorem fderivWithin_sinh (hf : DifferentiableWithinAt ℝ f s x) (hxs : UniqueDiffWithinAt ℝ s x) : fderivWithin ℝ (fun x => Real.sinh (f x)) s x = Real.cosh (f x) β€’ fderivWithin ℝ f s x := hf.hasFDerivWithinAt.sinh.fderivWithin hxs @[simp] theorem fderiv_sinh (hc : DifferentiableAt ℝ f x) : fderiv ℝ (fun x => Real.sinh (f x)) x = Real.cosh (f x) β€’ fderiv ℝ f x := hc.hasFDerivAt.sinh.fderiv theorem ContDiff.sinh {n} (h : ContDiff ℝ n f) : ContDiff ℝ n fun x => Real.sinh (f x) := Real.contDiff_sinh.comp h theorem ContDiffAt.sinh {n} (hf : ContDiffAt ℝ n f x) : ContDiffAt ℝ n (fun x => Real.sinh (f x)) x := Real.contDiff_sinh.contDiffAt.comp x hf theorem ContDiffOn.sinh {n} (hf : ContDiffOn ℝ n f s) : ContDiffOn ℝ n (fun x => Real.sinh (f x)) s := Real.contDiff_sinh.comp_contDiffOn hf theorem ContDiffWithinAt.sinh {n} (hf : ContDiffWithinAt ℝ n f s x) : ContDiffWithinAt ℝ n (fun x => Real.sinh (f x)) s x := Real.contDiff_sinh.contDiffAt.comp_contDiffWithinAt x hf section LogDeriv @[simp] theorem Complex.logDeriv_sin : logDeriv (Complex.sin) = Complex.cot := by ext rw [logDeriv, Complex.deriv_sin, Pi.div_apply, Complex.cot] @[simp] theorem Real.logDeriv_sin : logDeriv (Real.sin) = Real.cot := by ext rw [logDeriv, Real.deriv_sin, Pi.div_apply, Real.cot_eq_cos_div_sin] @[simp] theorem Complex.logDeriv_cos : logDeriv (Complex.cos) = -Complex.tan := by ext rw [logDeriv, Complex.deriv_cos', Pi.div_apply, Pi.neg_apply, Complex.tan, neg_div] @[simp] theorem Real.logDeriv_cos : logDeriv (Real.cos) = -Real.tan := by ext rw [logDeriv, Real.deriv_cos', Pi.div_apply, Pi.neg_apply, neg_div, Real.tan_eq_sin_div_cos ] @[simp] theorem Complex.logDeriv_cosh : logDeriv (Complex.cosh) = Complex.tanh := by ext rw [logDeriv, Complex.deriv_cosh, Pi.div_apply, Complex.tanh] @[simp] theorem Real.logDeriv_cosh : logDeriv (Real.cosh) = Real.tanh := by ext rw [logDeriv, Real.deriv_cosh, Pi.div_apply, Real.tanh_eq_sinh_div_cosh] @[simp] theorem Complex.LogDeriv_exp : logDeriv (Complex.exp) = 1 := by ext rw [logDeriv, Complex.deriv_exp, Pi.div_apply, ← exp_sub, sub_self, exp_zero, Pi.one_apply] @[simp] theorem Real.LogDeriv_exp : logDeriv (Real.exp) = 1 := by ext rw [logDeriv, Real.deriv_exp, Pi.div_apply, ← exp_sub, sub_self, exp_zero, Pi.one_apply] end LogDeriv end namespace Mathlib.Meta.Positivity open Lean Meta Qq private alias ⟨_, sinh_pos_of_pos⟩ := Real.sinh_pos_iff private alias ⟨_, sinh_nonneg_of_nonneg⟩ := Real.sinh_nonneg_iff private alias ⟨_, sinh_ne_zero_of_ne_zero⟩ := Real.sinh_ne_zero /-- Extension for the `positivity` tactic: `Real.sinh` is positive/nonnegative/nonzero if its input is. -/ @[positivity Real.sinh _] def evalSinh : PositivityExt where eval {u Ξ±} _ _ e := do let zΞ± : Q(Zero ℝ) := q(inferInstance) let pΞ± : Q(PartialOrder ℝ) := q(inferInstance) match u, Ξ±, e with | 0, ~q(ℝ), ~q(Real.sinh $a) => assumeInstancesCommute match ← core zΞ± pΞ± a with | .positive pa => return .positive q(sinh_pos_of_pos $pa) | .nonnegative pa => return .nonnegative q(sinh_nonneg_of_nonneg $pa) | .nonzero pa => return .nonzero q(sinh_ne_zero_of_ne_zero $pa) | _ => return .none | _, _, _ => throwError "not Real.sinh" example (x : ℝ) (hx : 0 < x) : 0 < x.sinh := by positivity example (x : ℝ) (hx : 0 ≀ x) : 0 ≀ x.sinh := by positivity example (x : ℝ) (hx : x β‰  0) : x.sinh β‰  0 := by positivity end Mathlib.Meta.Positivity
.lake/packages/mathlib/Mathlib/Analysis/SpecialFunctions/Trigonometric/InverseDeriv.lean
import Mathlib.Analysis.SpecialFunctions.Trigonometric.Inverse import Mathlib.Analysis.SpecialFunctions.Trigonometric.Deriv /-! # derivatives of the inverse trigonometric functions Derivatives of `arcsin` and `arccos`. -/ noncomputable section open scoped Topology Filter Real ContDiff open Set namespace Real section Arcsin theorem deriv_arcsin_aux {x : ℝ} (h₁ : x β‰  -1) (hβ‚‚ : x β‰  1) : HasStrictDerivAt arcsin (1 / √(1 - x ^ 2)) x ∧ ContDiffAt ℝ Ο‰ arcsin x := by rcases h₁.lt_or_gt with h₁ | h₁ Β· have : 1 - x ^ 2 < 0 := by nlinarith [h₁] rw [sqrt_eq_zero'.2 this.le, div_zero] have : arcsin =αΆ [𝓝 x] fun _ => -(Ο€ / 2) := (gt_mem_nhds h₁).mono fun y hy => arcsin_of_le_neg_one hy.le exact ⟨(hasStrictDerivAt_const x _).congr_of_eventuallyEq this.symm, contDiffAt_const.congr_of_eventuallyEq this⟩ rcases hβ‚‚.lt_or_gt with hβ‚‚ | hβ‚‚ Β· have : 0 < √(1 - x ^ 2) := sqrt_pos.2 (by nlinarith [h₁, hβ‚‚]) simp only [← cos_arcsin, one_div] at this ⊒ exact ⟨sinPartialHomeomorph.hasStrictDerivAt_symm ⟨h₁, hβ‚‚βŸ© this.ne' (hasStrictDerivAt_sin _), sinPartialHomeomorph.contDiffAt_symm_deriv this.ne' ⟨h₁, hβ‚‚βŸ© (hasDerivAt_sin _) contDiff_sin.contDiffAt⟩ Β· have : 1 - x ^ 2 < 0 := by nlinarith [hβ‚‚] rw [sqrt_eq_zero'.2 this.le, div_zero] have : arcsin =αΆ [𝓝 x] fun _ => Ο€ / 2 := (lt_mem_nhds hβ‚‚).mono fun y hy => arcsin_of_one_le hy.le exact ⟨(hasStrictDerivAt_const x _).congr_of_eventuallyEq this.symm, contDiffAt_const.congr_of_eventuallyEq this⟩ theorem hasStrictDerivAt_arcsin {x : ℝ} (h₁ : x β‰  -1) (hβ‚‚ : x β‰  1) : HasStrictDerivAt arcsin (1 / √(1 - x ^ 2)) x := (deriv_arcsin_aux h₁ hβ‚‚).1 theorem hasDerivAt_arcsin {x : ℝ} (h₁ : x β‰  -1) (hβ‚‚ : x β‰  1) : HasDerivAt arcsin (1 / √(1 - x ^ 2)) x := (hasStrictDerivAt_arcsin h₁ hβ‚‚).hasDerivAt theorem contDiffAt_arcsin {x : ℝ} (h₁ : x β‰  -1) (hβ‚‚ : x β‰  1) {n : WithTop β„•βˆž} : ContDiffAt ℝ n arcsin x := (deriv_arcsin_aux h₁ hβ‚‚).2.of_le le_top theorem hasDerivWithinAt_arcsin_Ici {x : ℝ} (h : x β‰  -1) : HasDerivWithinAt arcsin (1 / √(1 - x ^ 2)) (Ici x) x := by rcases eq_or_ne x 1 with (rfl | h') Β· convert (hasDerivWithinAt_const (1 : ℝ) _ (Ο€ / 2)).congr _ _ <;> simp +contextual [arcsin_of_one_le] Β· exact (hasDerivAt_arcsin h h').hasDerivWithinAt theorem hasDerivWithinAt_arcsin_Iic {x : ℝ} (h : x β‰  1) : HasDerivWithinAt arcsin (1 / √(1 - x ^ 2)) (Iic x) x := by rcases em (x = -1) with (rfl | h') Β· convert (hasDerivWithinAt_const (-1 : ℝ) _ (-(Ο€ / 2))).congr _ _ <;> simp +contextual [arcsin_of_le_neg_one] Β· exact (hasDerivAt_arcsin h' h).hasDerivWithinAt theorem differentiableWithinAt_arcsin_Ici {x : ℝ} : DifferentiableWithinAt ℝ arcsin (Ici x) x ↔ x β‰  -1 := by refine ⟨?_, fun h => (hasDerivWithinAt_arcsin_Ici h).differentiableWithinAt⟩ rintro h rfl have : sin ∘ arcsin =αΆ [𝓝[β‰₯] (-1 : ℝ)] id := by filter_upwards [Icc_mem_nhdsGE (neg_lt_self zero_lt_one)] with x using sin_arcsin' have := h.hasDerivWithinAt.sin.congr_of_eventuallyEq this.symm (by simp) simpa using (uniqueDiffOn_Ici _ _ left_mem_Ici).eq_deriv _ this (hasDerivWithinAt_id _ _) theorem differentiableWithinAt_arcsin_Iic {x : ℝ} : DifferentiableWithinAt ℝ arcsin (Iic x) x ↔ x β‰  1 := by refine ⟨fun h => ?_, fun h => (hasDerivWithinAt_arcsin_Iic h).differentiableWithinAt⟩ rw [← neg_neg x, ← image_neg_Ici] at h have := (h.comp (-x) differentiableWithinAt_id.fun_neg (mapsTo_image _ _)).fun_neg simpa [(Β· ∘ Β·), differentiableWithinAt_arcsin_Ici] using this theorem differentiableAt_arcsin {x : ℝ} : DifferentiableAt ℝ arcsin x ↔ x β‰  -1 ∧ x β‰  1 := ⟨fun h => ⟨differentiableWithinAt_arcsin_Ici.1 h.differentiableWithinAt, differentiableWithinAt_arcsin_Iic.1 h.differentiableWithinAt⟩, fun h => (hasDerivAt_arcsin h.1 h.2).differentiableAt⟩ @[simp] theorem deriv_arcsin : deriv arcsin = fun x => 1 / √(1 - x ^ 2) := by funext x by_cases h : x β‰  -1 ∧ x β‰  1 Β· exact (hasDerivAt_arcsin h.1 h.2).deriv Β· rw [deriv_zero_of_not_differentiableAt (mt differentiableAt_arcsin.1 h)] simp only [not_and_or, Ne, Classical.not_not] at h rcases h with (rfl | rfl) <;> simp theorem differentiableOn_arcsin : DifferentiableOn ℝ arcsin {-1, 1}ᢜ := fun _x hx => (differentiableAt_arcsin.2 ⟨fun h => hx (Or.inl h), fun h => hx (Or.inr h)⟩).differentiableWithinAt theorem contDiffOn_arcsin {n : WithTop β„•βˆž} : ContDiffOn ℝ n arcsin {-1, 1}ᢜ := fun _x hx => (contDiffAt_arcsin (mt Or.inl hx) (mt Or.inr hx)).contDiffWithinAt theorem contDiffAt_arcsin_iff {x : ℝ} {n : WithTop β„•βˆž} : ContDiffAt ℝ n arcsin x ↔ n = 0 ∨ x β‰  -1 ∧ x β‰  1 := ⟨fun h => or_iff_not_imp_left.2 fun hn => differentiableAt_arcsin.1 <| h.differentiableAt <| ENat.one_le_iff_ne_zero_withTop.mpr hn, fun h => h.elim (fun hn => hn.symm β–Έ (contDiff_zero.2 continuous_arcsin).contDiffAt) fun hx => contDiffAt_arcsin hx.1 hx.2⟩ end Arcsin section Arccos theorem hasStrictDerivAt_arccos {x : ℝ} (h₁ : x β‰  -1) (hβ‚‚ : x β‰  1) : HasStrictDerivAt arccos (-(1 / √(1 - x ^ 2))) x := (hasStrictDerivAt_arcsin h₁ hβ‚‚).const_sub (Ο€ / 2) theorem hasDerivAt_arccos {x : ℝ} (h₁ : x β‰  -1) (hβ‚‚ : x β‰  1) : HasDerivAt arccos (-(1 / √(1 - x ^ 2))) x := (hasDerivAt_arcsin h₁ hβ‚‚).const_sub (Ο€ / 2) theorem contDiffAt_arccos {x : ℝ} (h₁ : x β‰  -1) (hβ‚‚ : x β‰  1) {n : WithTop β„•βˆž} : ContDiffAt ℝ n arccos x := contDiffAt_const.sub (contDiffAt_arcsin h₁ hβ‚‚) theorem hasDerivWithinAt_arccos_Ici {x : ℝ} (h : x β‰  -1) : HasDerivWithinAt arccos (-(1 / √(1 - x ^ 2))) (Ici x) x := (hasDerivWithinAt_arcsin_Ici h).const_sub _ theorem hasDerivWithinAt_arccos_Iic {x : ℝ} (h : x β‰  1) : HasDerivWithinAt arccos (-(1 / √(1 - x ^ 2))) (Iic x) x := (hasDerivWithinAt_arcsin_Iic h).const_sub _ theorem differentiableWithinAt_arccos_Ici {x : ℝ} : DifferentiableWithinAt ℝ arccos (Ici x) x ↔ x β‰  -1 := (differentiableWithinAt_const_sub_iff _).trans differentiableWithinAt_arcsin_Ici theorem differentiableWithinAt_arccos_Iic {x : ℝ} : DifferentiableWithinAt ℝ arccos (Iic x) x ↔ x β‰  1 := (differentiableWithinAt_const_sub_iff _).trans differentiableWithinAt_arcsin_Iic theorem differentiableAt_arccos {x : ℝ} : DifferentiableAt ℝ arccos x ↔ x β‰  -1 ∧ x β‰  1 := (differentiableAt_const _).sub_iff_right.trans differentiableAt_arcsin @[simp] theorem deriv_arccos : deriv arccos = fun x => -(1 / √(1 - x ^ 2)) := funext fun x => (deriv_const_sub _).trans <| by simp only [deriv_arcsin] theorem differentiableOn_arccos : DifferentiableOn ℝ arccos {-1, 1}ᢜ := differentiableOn_arcsin.const_sub _ theorem contDiffOn_arccos {n : WithTop β„•βˆž} : ContDiffOn ℝ n arccos {-1, 1}ᢜ := contDiffOn_const.sub contDiffOn_arcsin theorem contDiffAt_arccos_iff {x : ℝ} {n : WithTop β„•βˆž} : ContDiffAt ℝ n arccos x ↔ n = 0 ∨ x β‰  -1 ∧ x β‰  1 := by refine Iff.trans ⟨fun h => ?_, fun h => ?_⟩ contDiffAt_arcsin_iff <;> simpa [arccos] using (contDiffAt_const (c := Ο€ / 2)).sub h end Arccos end Real
.lake/packages/mathlib/Mathlib/Analysis/SpecialFunctions/Trigonometric/Basic.lean
import Mathlib.Algebra.Field.NegOnePow import Mathlib.Algebra.Field.Periodic import Mathlib.Algebra.QuadraticDiscriminant import Mathlib.Analysis.SpecialFunctions.Exp /-! # Trigonometric functions ## Main definitions This file contains the definition of `Ο€`. See also `Analysis.SpecialFunctions.Trigonometric.Inverse` and `Analysis.SpecialFunctions.Trigonometric.Arctan` for the inverse trigonometric functions. See also `Analysis.SpecialFunctions.Complex.Arg` and `Analysis.SpecialFunctions.Complex.Log` for the complex argument function and the complex logarithm. ## Main statements Many basic inequalities on the real trigonometric functions are established. The continuity of the usual trigonometric functions is proved. Several facts about the real trigonometric functions have the proofs deferred to `Analysis.SpecialFunctions.Trigonometric.Complex`, as they are most easily proved by appealing to the corresponding fact for complex trigonometric functions. See also `Analysis.SpecialFunctions.Trigonometric.Chebyshev` for the multiple angle formulas in terms of Chebyshev polynomials. ## Tags sin, cos, tan, angle -/ noncomputable section open Topology Filter Set namespace Complex @[continuity, fun_prop] theorem continuous_sin : Continuous sin := by change Continuous fun z => (exp (-z * I) - exp (z * I)) * I / 2 fun_prop @[fun_prop] theorem continuousOn_sin {s : Set β„‚} : ContinuousOn sin s := continuous_sin.continuousOn @[continuity, fun_prop] theorem continuous_cos : Continuous cos := by change Continuous fun z => (exp (z * I) + exp (-z * I)) / 2 fun_prop @[fun_prop] theorem continuousOn_cos {s : Set β„‚} : ContinuousOn cos s := continuous_cos.continuousOn @[continuity, fun_prop] theorem continuous_sinh : Continuous sinh := by change Continuous fun z => (exp z - exp (-z)) / 2 fun_prop @[continuity, fun_prop] theorem continuous_cosh : Continuous cosh := by change Continuous fun z => (exp z + exp (-z)) / 2 fun_prop end Complex namespace Real variable {x y z : ℝ} @[continuity, fun_prop] theorem continuous_sin : Continuous sin := Complex.continuous_re.comp (Complex.continuous_sin.comp Complex.continuous_ofReal) @[fun_prop] theorem continuousOn_sin {s} : ContinuousOn sin s := continuous_sin.continuousOn @[continuity, fun_prop] theorem continuous_cos : Continuous cos := Complex.continuous_re.comp (Complex.continuous_cos.comp Complex.continuous_ofReal) @[fun_prop] theorem continuousOn_cos {s} : ContinuousOn cos s := continuous_cos.continuousOn @[continuity, fun_prop] theorem continuous_sinh : Continuous sinh := Complex.continuous_re.comp (Complex.continuous_sinh.comp Complex.continuous_ofReal) @[continuity, fun_prop] theorem continuous_cosh : Continuous cosh := Complex.continuous_re.comp (Complex.continuous_cosh.comp Complex.continuous_ofReal) end Real namespace Real theorem exists_cos_eq_zero : 0 ∈ cos '' Icc (1 : ℝ) 2 := intermediate_value_Icc' (by simp) continuousOn_cos ⟨le_of_lt cos_two_neg, le_of_lt cos_one_pos⟩ /-- The number Ο€ = 3.14159265... Defined here using choice as twice a zero of cos in [1,2], from which one can derive all its properties. For explicit bounds on Ο€, see `Mathlib/Analysis/Real/Pi/Bounds.lean`. Denoted `Ο€`, once the `Real` namespace is opened. -/ protected noncomputable def pi : ℝ := 2 * Classical.choose exists_cos_eq_zero @[inherit_doc] scoped notation "Ο€" => Real.pi @[simp] theorem cos_pi_div_two : cos (Ο€ / 2) = 0 := by rw [Real.pi, mul_div_cancel_leftβ‚€ _ two_ne_zero] exact (Classical.choose_spec exists_cos_eq_zero).2 theorem one_le_pi_div_two : (1 : ℝ) ≀ Ο€ / 2 := by rw [Real.pi, mul_div_cancel_leftβ‚€ _ two_ne_zero] exact (Classical.choose_spec exists_cos_eq_zero).1.1 theorem pi_div_two_le_two : Ο€ / 2 ≀ 2 := by rw [Real.pi, mul_div_cancel_leftβ‚€ _ two_ne_zero] exact (Classical.choose_spec exists_cos_eq_zero).1.2 theorem two_le_pi : (2 : ℝ) ≀ Ο€ := (div_le_div_iff_of_pos_right zero_lt_two).1 (by rw [div_self two_ne_zero]; exact one_le_pi_div_two) theorem pi_le_four : Ο€ ≀ 4 := (div_le_div_iff_of_pos_right zero_lt_two).1 (calc Ο€ / 2 ≀ 2 := pi_div_two_le_two _ = 4 / 2 := by norm_num) @[bound] theorem pi_pos : 0 < Ο€ := lt_of_lt_of_le (by simp) two_le_pi @[bound] theorem pi_nonneg : 0 ≀ Ο€ := pi_pos.le @[simp] theorem pi_ne_zero : Ο€ β‰  0 := pi_pos.ne' theorem pi_div_two_pos : 0 < Ο€ / 2 := half_pos pi_pos theorem two_pi_pos : 0 < 2 * Ο€ := by linarith [pi_pos] end Real namespace Mathlib.Meta.Positivity open Lean.Meta Qq /-- Extension for the `positivity` tactic: `Ο€` is always positive. -/ @[positivity Real.pi] def evalRealPi : PositivityExt where eval {u Ξ±} _zΞ± _pΞ± e := do match u, Ξ±, e with | 0, ~q(ℝ), ~q(Real.pi) => assertInstancesCommute pure (.positive q(Real.pi_pos)) | _, _, _ => throwError "not Real.pi" end Mathlib.Meta.Positivity namespace NNReal open Real open Real NNReal /-- `Ο€` considered as a nonnegative real. -/ noncomputable def pi : ℝβ‰₯0 := βŸ¨Ο€, Real.pi_pos.le⟩ @[simp] theorem coe_real_pi : (pi : ℝ) = Ο€ := rfl theorem pi_pos : 0 < pi := mod_cast Real.pi_pos theorem pi_ne_zero : pi β‰  0 := pi_pos.ne' end NNReal namespace Real @[simp] theorem sin_pi : sin Ο€ = 0 := by rw [← mul_div_cancel_leftβ‚€ Ο€ two_ne_zero, two_mul, add_div, sin_add, cos_pi_div_two]; simp @[simp] theorem cos_pi : cos Ο€ = -1 := by rw [← mul_div_cancel_leftβ‚€ Ο€ two_ne_zero, mul_div_assoc, cos_two_mul, cos_pi_div_two] norm_num @[simp] theorem sin_two_pi : sin (2 * Ο€) = 0 := by simp [two_mul, sin_add] @[simp] theorem cos_two_pi : cos (2 * Ο€) = 1 := by simp [two_mul, cos_add] theorem sin_antiperiodic : Function.Antiperiodic sin Ο€ := by simp [sin_add] theorem sin_periodic : Function.Periodic sin (2 * Ο€) := sin_antiperiodic.periodic_two_mul @[simp] theorem sin_add_pi (x : ℝ) : sin (x + Ο€) = -sin x := sin_antiperiodic x @[simp] theorem sin_add_two_pi (x : ℝ) : sin (x + 2 * Ο€) = sin x := sin_periodic x @[simp] theorem sin_sub_pi (x : ℝ) : sin (x - Ο€) = -sin x := sin_antiperiodic.sub_eq x @[simp] theorem sin_sub_two_pi (x : ℝ) : sin (x - 2 * Ο€) = sin x := sin_periodic.sub_eq x @[simp] theorem sin_pi_sub (x : ℝ) : sin (Ο€ - x) = sin x := neg_neg (sin x) β–Έ sin_neg x β–Έ sin_antiperiodic.sub_eq' @[simp] theorem sin_two_pi_sub (x : ℝ) : sin (2 * Ο€ - x) = -sin x := sin_neg x β–Έ sin_periodic.sub_eq' @[simp] theorem sin_nat_mul_pi (n : β„•) : sin (n * Ο€) = 0 := sin_antiperiodic.nat_mul_eq_of_eq_zero sin_zero n @[simp] theorem sin_int_mul_pi (n : β„€) : sin (n * Ο€) = 0 := sin_antiperiodic.int_mul_eq_of_eq_zero sin_zero n @[simp] theorem sin_add_nat_mul_two_pi (x : ℝ) (n : β„•) : sin (x + n * (2 * Ο€)) = sin x := sin_periodic.nat_mul n x @[simp] theorem sin_add_int_mul_two_pi (x : ℝ) (n : β„€) : sin (x + n * (2 * Ο€)) = sin x := sin_periodic.int_mul n x @[simp] theorem sin_sub_nat_mul_two_pi (x : ℝ) (n : β„•) : sin (x - n * (2 * Ο€)) = sin x := sin_periodic.sub_nat_mul_eq n @[simp] theorem sin_sub_int_mul_two_pi (x : ℝ) (n : β„€) : sin (x - n * (2 * Ο€)) = sin x := sin_periodic.sub_int_mul_eq n @[simp] theorem sin_nat_mul_two_pi_sub (x : ℝ) (n : β„•) : sin (n * (2 * Ο€) - x) = -sin x := sin_neg x β–Έ sin_periodic.nat_mul_sub_eq n @[simp] theorem sin_int_mul_two_pi_sub (x : ℝ) (n : β„€) : sin (n * (2 * Ο€) - x) = -sin x := sin_neg x β–Έ sin_periodic.int_mul_sub_eq n theorem sin_add_int_mul_pi (x : ℝ) (n : β„€) : sin (x + n * Ο€) = (-1) ^ n * sin x := n.cast_negOnePow ℝ β–Έ sin_antiperiodic.add_int_mul_eq n theorem sin_add_nat_mul_pi (x : ℝ) (n : β„•) : sin (x + n * Ο€) = (-1) ^ n * sin x := sin_antiperiodic.add_nat_mul_eq n theorem sin_sub_int_mul_pi (x : ℝ) (n : β„€) : sin (x - n * Ο€) = (-1) ^ n * sin x := n.cast_negOnePow ℝ β–Έ sin_antiperiodic.sub_int_mul_eq n theorem sin_sub_nat_mul_pi (x : ℝ) (n : β„•) : sin (x - n * Ο€) = (-1) ^ n * sin x := sin_antiperiodic.sub_nat_mul_eq n theorem sin_int_mul_pi_sub (x : ℝ) (n : β„€) : sin (n * Ο€ - x) = -((-1) ^ n * sin x) := by simpa only [sin_neg, mul_neg, Int.cast_negOnePow] using sin_antiperiodic.int_mul_sub_eq n theorem sin_nat_mul_pi_sub (x : ℝ) (n : β„•) : sin (n * Ο€ - x) = -((-1) ^ n * sin x) := by simpa only [sin_neg, mul_neg] using sin_antiperiodic.nat_mul_sub_eq n theorem cos_antiperiodic : Function.Antiperiodic cos Ο€ := by simp [cos_add] theorem cos_periodic : Function.Periodic cos (2 * Ο€) := cos_antiperiodic.periodic_two_mul @[simp] theorem abs_cos_int_mul_pi (k : β„€) : |cos (k * Ο€)| = 1 := by simp [abs_cos_eq_sqrt_one_sub_sin_sq] @[simp] theorem cos_add_pi (x : ℝ) : cos (x + Ο€) = -cos x := cos_antiperiodic x @[simp] theorem cos_add_two_pi (x : ℝ) : cos (x + 2 * Ο€) = cos x := cos_periodic x @[simp] theorem cos_sub_pi (x : ℝ) : cos (x - Ο€) = -cos x := cos_antiperiodic.sub_eq x @[simp] theorem cos_sub_two_pi (x : ℝ) : cos (x - 2 * Ο€) = cos x := cos_periodic.sub_eq x @[simp] theorem cos_pi_sub (x : ℝ) : cos (Ο€ - x) = -cos x := cos_neg x β–Έ cos_antiperiodic.sub_eq' @[simp] theorem cos_two_pi_sub (x : ℝ) : cos (2 * Ο€ - x) = cos x := cos_neg x β–Έ cos_periodic.sub_eq' @[simp] theorem cos_nat_mul_two_pi (n : β„•) : cos (n * (2 * Ο€)) = 1 := (cos_periodic.nat_mul_eq n).trans cos_zero @[simp] theorem cos_int_mul_two_pi (n : β„€) : cos (n * (2 * Ο€)) = 1 := (cos_periodic.int_mul_eq n).trans cos_zero @[simp] theorem cos_add_nat_mul_two_pi (x : ℝ) (n : β„•) : cos (x + n * (2 * Ο€)) = cos x := cos_periodic.nat_mul n x @[simp] theorem cos_add_int_mul_two_pi (x : ℝ) (n : β„€) : cos (x + n * (2 * Ο€)) = cos x := cos_periodic.int_mul n x @[simp] theorem cos_sub_nat_mul_two_pi (x : ℝ) (n : β„•) : cos (x - n * (2 * Ο€)) = cos x := cos_periodic.sub_nat_mul_eq n @[simp] theorem cos_sub_int_mul_two_pi (x : ℝ) (n : β„€) : cos (x - n * (2 * Ο€)) = cos x := cos_periodic.sub_int_mul_eq n @[simp] theorem cos_nat_mul_two_pi_sub (x : ℝ) (n : β„•) : cos (n * (2 * Ο€) - x) = cos x := cos_neg x β–Έ cos_periodic.nat_mul_sub_eq n @[simp] theorem cos_int_mul_two_pi_sub (x : ℝ) (n : β„€) : cos (n * (2 * Ο€) - x) = cos x := cos_neg x β–Έ cos_periodic.int_mul_sub_eq n theorem cos_add_int_mul_pi (x : ℝ) (n : β„€) : cos (x + n * Ο€) = (-1) ^ n * cos x := n.cast_negOnePow ℝ β–Έ cos_antiperiodic.add_int_mul_eq n theorem cos_add_nat_mul_pi (x : ℝ) (n : β„•) : cos (x + n * Ο€) = (-1) ^ n * cos x := cos_antiperiodic.add_nat_mul_eq n theorem cos_sub_int_mul_pi (x : ℝ) (n : β„€) : cos (x - n * Ο€) = (-1) ^ n * cos x := n.cast_negOnePow ℝ β–Έ cos_antiperiodic.sub_int_mul_eq n theorem cos_sub_nat_mul_pi (x : ℝ) (n : β„•) : cos (x - n * Ο€) = (-1) ^ n * cos x := cos_antiperiodic.sub_nat_mul_eq n theorem cos_int_mul_pi_sub (x : ℝ) (n : β„€) : cos (n * Ο€ - x) = (-1) ^ n * cos x := n.cast_negOnePow ℝ β–Έ cos_neg x β–Έ cos_antiperiodic.int_mul_sub_eq n theorem cos_nat_mul_pi_sub (x : ℝ) (n : β„•) : cos (n * Ο€ - x) = (-1) ^ n * cos x := cos_neg x β–Έ cos_antiperiodic.nat_mul_sub_eq n theorem cos_nat_mul_two_pi_add_pi (n : β„•) : cos (n * (2 * Ο€) + Ο€) = -1 := by simpa only [cos_zero] using (cos_periodic.nat_mul n).add_antiperiod_eq cos_antiperiodic theorem cos_int_mul_two_pi_add_pi (n : β„€) : cos (n * (2 * Ο€) + Ο€) = -1 := by simpa only [cos_zero] using (cos_periodic.int_mul n).add_antiperiod_eq cos_antiperiodic theorem cos_nat_mul_two_pi_sub_pi (n : β„•) : cos (n * (2 * Ο€) - Ο€) = -1 := by simpa only [cos_zero] using (cos_periodic.nat_mul n).sub_antiperiod_eq cos_antiperiodic theorem cos_int_mul_two_pi_sub_pi (n : β„€) : cos (n * (2 * Ο€) - Ο€) = -1 := by simpa only [cos_zero] using (cos_periodic.int_mul n).sub_antiperiod_eq cos_antiperiodic theorem sin_pos_of_pos_of_lt_pi {x : ℝ} (h0x : 0 < x) (hxp : x < Ο€) : 0 < sin x := if hx2 : x ≀ 2 then sin_pos_of_pos_of_le_two h0x hx2 else sin_pi_sub x β–Έ sin_pos_of_pos_of_le_two (sub_pos.2 hxp) (by linarith [pi_le_four]) theorem sin_pos_of_mem_Ioo {x : ℝ} (hx : x ∈ Ioo 0 Ο€) : 0 < sin x := sin_pos_of_pos_of_lt_pi hx.1 hx.2 theorem sin_nonneg_of_mem_Icc {x : ℝ} (hx : x ∈ Icc 0 Ο€) : 0 ≀ sin x := by rw [← closure_Ioo pi_ne_zero.symm] at hx exact closure_lt_subset_le continuous_const continuous_sin (closure_mono (fun y => sin_pos_of_mem_Ioo) hx) theorem sin_nonneg_of_nonneg_of_le_pi {x : ℝ} (h0x : 0 ≀ x) (hxp : x ≀ Ο€) : 0 ≀ sin x := sin_nonneg_of_mem_Icc ⟨h0x, hxp⟩ theorem sin_neg_of_neg_of_neg_pi_lt {x : ℝ} (hx0 : x < 0) (hpx : -Ο€ < x) : sin x < 0 := neg_pos.1 <| sin_neg x β–Έ sin_pos_of_pos_of_lt_pi (neg_pos.2 hx0) (neg_lt.1 hpx) theorem sin_nonpos_of_nonpos_of_neg_pi_le {x : ℝ} (hx0 : x ≀ 0) (hpx : -Ο€ ≀ x) : sin x ≀ 0 := neg_nonneg.1 <| sin_neg x β–Έ sin_nonneg_of_nonneg_of_le_pi (neg_nonneg.2 hx0) (neg_le.1 hpx) @[deprecated (since := "2025-07-27")] alias sin_nonpos_of_nonnpos_of_neg_pi_le := sin_nonpos_of_nonpos_of_neg_pi_le @[simp] theorem sin_pi_div_two : sin (Ο€ / 2) = 1 := have : sin (Ο€ / 2) = 1 ∨ sin (Ο€ / 2) = -1 := by simpa [sq, mul_self_eq_one_iff] using sin_sq_add_cos_sq (Ο€ / 2) this.resolve_right fun h => show Β¬(0 : ℝ) < -1 by simp <| h β–Έ sin_pos_of_pos_of_lt_pi pi_div_two_pos (half_lt_self pi_pos) theorem sin_add_pi_div_two (x : ℝ) : sin (x + Ο€ / 2) = cos x := by simp [sin_add] theorem sin_sub_pi_div_two (x : ℝ) : sin (x - Ο€ / 2) = -cos x := by simp [sub_eq_add_neg, sin_add] theorem sin_pi_div_two_sub (x : ℝ) : sin (Ο€ / 2 - x) = cos x := by simp [sub_eq_add_neg, sin_add] theorem cos_add_pi_div_two (x : ℝ) : cos (x + Ο€ / 2) = -sin x := by simp [cos_add] theorem cos_sub_pi_div_two (x : ℝ) : cos (x - Ο€ / 2) = sin x := by simp [sub_eq_add_neg, cos_add] theorem cos_pi_div_two_sub (x : ℝ) : cos (Ο€ / 2 - x) = sin x := by rw [← cos_neg, neg_sub, cos_sub_pi_div_two] theorem cos_pos_of_mem_Ioo {x : ℝ} (hx : x ∈ Ioo (-(Ο€ / 2)) (Ο€ / 2)) : 0 < cos x := sin_add_pi_div_two x β–Έ sin_pos_of_mem_Ioo ⟨by linarith [hx.1], by linarith [hx.2]⟩ theorem cos_nonneg_of_mem_Icc {x : ℝ} (hx : x ∈ Icc (-(Ο€ / 2)) (Ο€ / 2)) : 0 ≀ cos x := sin_add_pi_div_two x β–Έ sin_nonneg_of_mem_Icc ⟨by linarith [hx.1], by linarith [hx.2]⟩ theorem cos_nonneg_of_neg_pi_div_two_le_of_le {x : ℝ} (hl : -(Ο€ / 2) ≀ x) (hu : x ≀ Ο€ / 2) : 0 ≀ cos x := cos_nonneg_of_mem_Icc ⟨hl, hu⟩ theorem cos_neg_of_pi_div_two_lt_of_lt {x : ℝ} (hx₁ : Ο€ / 2 < x) (hxβ‚‚ : x < Ο€ + Ο€ / 2) : cos x < 0 := neg_pos.1 <| cos_pi_sub x β–Έ cos_pos_of_mem_Ioo ⟨by linarith, by linarith⟩ theorem cos_nonpos_of_pi_div_two_le_of_le {x : ℝ} (hx₁ : Ο€ / 2 ≀ x) (hxβ‚‚ : x ≀ Ο€ + Ο€ / 2) : cos x ≀ 0 := neg_nonneg.1 <| cos_pi_sub x β–Έ cos_nonneg_of_mem_Icc ⟨by linarith, by linarith⟩ theorem sin_eq_sqrt_one_sub_cos_sq {x : ℝ} (hl : 0 ≀ x) (hu : x ≀ Ο€) : sin x = √(1 - cos x ^ 2) := by rw [← abs_sin_eq_sqrt_one_sub_cos_sq, abs_of_nonneg (sin_nonneg_of_nonneg_of_le_pi hl hu)] theorem cos_eq_sqrt_one_sub_sin_sq {x : ℝ} (hl : -(Ο€ / 2) ≀ x) (hu : x ≀ Ο€ / 2) : cos x = √(1 - sin x ^ 2) := by rw [← abs_cos_eq_sqrt_one_sub_sin_sq, abs_of_nonneg (cos_nonneg_of_mem_Icc ⟨hl, hu⟩)] lemma cos_half {x : ℝ} (hl : -Ο€ ≀ x) (hr : x ≀ Ο€) : cos (x / 2) = √((1 + cos x) / 2) := by have : 0 ≀ cos (x / 2) := cos_nonneg_of_mem_Icc <| by constructor <;> linarith rw [← sqrt_sq this, cos_sq, add_div, two_mul, add_halves] lemma abs_sin_half (x : ℝ) : |sin (x / 2)| = √((1 - cos x) / 2) := by rw [← sqrt_sq_eq_abs, sin_sq_eq_half_sub, two_mul, add_halves, sub_div] lemma sin_half_eq_sqrt {x : ℝ} (hl : 0 ≀ x) (hr : x ≀ 2 * Ο€) : sin (x / 2) = √((1 - cos x) / 2) := by rw [← abs_sin_half, abs_of_nonneg] apply sin_nonneg_of_nonneg_of_le_pi <;> linarith lemma sin_half_eq_neg_sqrt {x : ℝ} (hl : -(2 * Ο€) ≀ x) (hr : x ≀ 0) : sin (x / 2) = -√((1 - cos x) / 2) := by rw [← abs_sin_half, abs_of_nonpos, neg_neg] apply sin_nonpos_of_nonpos_of_neg_pi_le <;> linarith theorem sin_eq_zero_iff_of_lt_of_lt {x : ℝ} (hx₁ : -Ο€ < x) (hxβ‚‚ : x < Ο€) : sin x = 0 ↔ x = 0 := ⟨fun h => by contrapose! h cases h.lt_or_gt with | inl h0 => exact (sin_neg_of_neg_of_neg_pi_lt h0 hx₁).ne | inr h0 => exact (sin_pos_of_pos_of_lt_pi h0 hxβ‚‚).ne', fun h => by simp [h]⟩ theorem sin_eq_zero_iff {x : ℝ} : sin x = 0 ↔ βˆƒ n : β„€, (n : ℝ) * Ο€ = x := ⟨fun h => ⟨⌊x / Ο€βŒ‹, le_antisymm (sub_nonneg.1 (Int.sub_floor_div_mul_nonneg _ pi_pos)) (sub_nonpos.1 <| le_of_not_gt fun h₃ => (sin_pos_of_pos_of_lt_pi h₃ (Int.sub_floor_div_mul_lt _ pi_pos)).ne (by simp [sub_eq_add_neg, sin_add, h, sin_int_mul_pi]))⟩, fun ⟨_, hn⟩ => hn β–Έ sin_int_mul_pi _⟩ theorem sin_ne_zero_iff {x : ℝ} : sin x β‰  0 ↔ βˆ€ n : β„€, (n : ℝ) * Ο€ β‰  x := by rw [← not_exists, not_iff_not, sin_eq_zero_iff] theorem sin_eq_zero_iff_cos_eq {x : ℝ} : sin x = 0 ↔ cos x = 1 ∨ cos x = -1 := by rw [← mul_self_eq_one_iff, ← sin_sq_add_cos_sq, sq, sq, right_eq_add, mul_eq_zero, or_self] theorem cos_eq_zero_iff_sin_eq {x : ℝ} : cos x = 0 ↔ sin x = 1 ∨ sin x = -1 := by rw [← mul_self_eq_one_iff, ← sin_sq_add_cos_sq, sq, sq, left_eq_add, mul_eq_zero, or_self] theorem cos_eq_one_iff (x : ℝ) : cos x = 1 ↔ βˆƒ n : β„€, (n : ℝ) * (2 * Ο€) = x := ⟨fun h => let ⟨n, hn⟩ := sin_eq_zero_iff.1 (sin_eq_zero_iff_cos_eq.2 (Or.inl h)) ⟨n / 2, (Int.emod_two_eq_zero_or_one n).elim (fun hn0 => by rwa [← mul_assoc, ← @Int.cast_two ℝ, ← Int.cast_mul, Int.ediv_mul_cancel (Int.dvd_iff_emod_eq_zero.2 hn0)]) fun hn1 => by rw [← Int.emod_add_mul_ediv n 2, hn1, Int.cast_add, Int.cast_one, add_mul, one_mul, add_comm, mul_comm (2 : β„€), Int.cast_mul, mul_assoc, Int.cast_two] at hn rw [← hn, cos_int_mul_two_pi_add_pi] at h exact absurd h (by norm_num)⟩, fun ⟨_, hn⟩ => hn β–Έ cos_int_mul_two_pi _⟩ theorem cos_eq_one_iff_of_lt_of_lt {x : ℝ} (hx₁ : -(2 * Ο€) < x) (hxβ‚‚ : x < 2 * Ο€) : cos x = 1 ↔ x = 0 := ⟨fun h => by rcases (cos_eq_one_iff _).1 h with ⟨n, rfl⟩ rw [mul_lt_iff_lt_one_left two_pi_pos] at hxβ‚‚ rw [neg_lt, neg_mul_eq_neg_mul, mul_lt_iff_lt_one_left two_pi_pos] at hx₁ norm_cast at hx₁ hxβ‚‚ obtain rfl : n = 0 := le_antisymm (by cutsat) (by cutsat) simp, fun h => by simp [h]⟩ theorem sin_lt_sin_of_lt_of_le_pi_div_two {x y : ℝ} (hx₁ : -(Ο€ / 2) ≀ x) (hyβ‚‚ : y ≀ Ο€ / 2) (hxy : x < y) : sin x < sin y := by rw [← sub_pos, sin_sub_sin] have : 0 < sin ((y - x) / 2) := by apply sin_pos_of_pos_of_lt_pi <;> linarith have : 0 < cos ((y + x) / 2) := by refine cos_pos_of_mem_Ioo ⟨?_, ?_⟩ <;> linarith positivity theorem strictMonoOn_sin : StrictMonoOn sin (Icc (-(Ο€ / 2)) (Ο€ / 2)) := fun _ hx _ hy hxy => sin_lt_sin_of_lt_of_le_pi_div_two hx.1 hy.2 hxy theorem monotoneOn_sin : MonotoneOn sin (Set.Icc (-(Ο€ / 2)) (Ο€ / 2)) := strictMonoOn_sin.monotoneOn theorem cos_lt_cos_of_nonneg_of_le_pi {x y : ℝ} (hx₁ : 0 ≀ x) (hyβ‚‚ : y ≀ Ο€) (hxy : x < y) : cos y < cos x := by rw [← sin_pi_div_two_sub, ← sin_pi_div_two_sub] apply sin_lt_sin_of_lt_of_le_pi_div_two <;> linarith theorem cos_lt_cos_of_nonneg_of_le_pi_div_two {x y : ℝ} (hx₁ : 0 ≀ x) (hyβ‚‚ : y ≀ Ο€ / 2) (hxy : x < y) : cos y < cos x := cos_lt_cos_of_nonneg_of_le_pi hx₁ (hyβ‚‚.trans (by linarith)) hxy theorem strictAntiOn_cos : StrictAntiOn cos (Icc 0 Ο€) := fun _ hx _ hy hxy => cos_lt_cos_of_nonneg_of_le_pi hx.1 hy.2 hxy theorem antitoneOn_cos : AntitoneOn cos (Set.Icc 0 Ο€) := strictAntiOn_cos.antitoneOn theorem cos_le_cos_of_nonneg_of_le_pi {x y : ℝ} (hx₁ : 0 ≀ x) (hyβ‚‚ : y ≀ Ο€) (hxy : x ≀ y) : cos y ≀ cos x := (strictAntiOn_cos.le_iff_ge ⟨hx₁.trans hxy, hyβ‚‚βŸ© ⟨hx₁, hxy.trans hyβ‚‚βŸ©).2 hxy theorem sin_le_sin_of_le_of_le_pi_div_two {x y : ℝ} (hx₁ : -(Ο€ / 2) ≀ x) (hyβ‚‚ : y ≀ Ο€ / 2) (hxy : x ≀ y) : sin x ≀ sin y := (strictMonoOn_sin.le_iff_le ⟨hx₁, hxy.trans hyβ‚‚βŸ© ⟨hx₁.trans hxy, hyβ‚‚βŸ©).2 hxy theorem injOn_sin : InjOn sin (Icc (-(Ο€ / 2)) (Ο€ / 2)) := strictMonoOn_sin.injOn theorem injOn_cos : InjOn cos (Icc 0 Ο€) := strictAntiOn_cos.injOn theorem surjOn_sin : SurjOn sin (Icc (-(Ο€ / 2)) (Ο€ / 2)) (Icc (-1) 1) := by simpa only [sin_neg, sin_pi_div_two] using intermediate_value_Icc (neg_le_self pi_div_two_pos.le) continuous_sin.continuousOn theorem surjOn_cos : SurjOn cos (Icc 0 Ο€) (Icc (-1) 1) := by simpa only [cos_zero, cos_pi] using intermediate_value_Icc' pi_pos.le continuous_cos.continuousOn theorem sin_mem_Icc (x : ℝ) : sin x ∈ Icc (-1 : ℝ) 1 := ⟨neg_one_le_sin x, sin_le_one x⟩ theorem cos_mem_Icc (x : ℝ) : cos x ∈ Icc (-1 : ℝ) 1 := ⟨neg_one_le_cos x, cos_le_one x⟩ theorem mapsTo_sin (s : Set ℝ) : MapsTo sin s (Icc (-1 : ℝ) 1) := fun x _ => sin_mem_Icc x theorem mapsTo_cos (s : Set ℝ) : MapsTo cos s (Icc (-1 : ℝ) 1) := fun x _ => cos_mem_Icc x theorem bijOn_sin : BijOn sin (Icc (-(Ο€ / 2)) (Ο€ / 2)) (Icc (-1) 1) := ⟨mapsTo_sin _, injOn_sin, surjOn_sin⟩ theorem bijOn_cos : BijOn cos (Icc 0 Ο€) (Icc (-1) 1) := ⟨mapsTo_cos _, injOn_cos, surjOn_cos⟩ @[simp] theorem range_cos : range cos = (Icc (-1) 1 : Set ℝ) := Subset.antisymm (range_subset_iff.2 cos_mem_Icc) surjOn_cos.subset_range @[simp] theorem range_sin : range sin = (Icc (-1) 1 : Set ℝ) := Subset.antisymm (range_subset_iff.2 sin_mem_Icc) surjOn_sin.subset_range theorem range_cos_infinite : (range Real.cos).Infinite := by rw [Real.range_cos] exact Icc_infinite (by simp) theorem range_sin_infinite : (range Real.sin).Infinite := by rw [Real.range_sin] exact Icc_infinite (by simp) section CosDivSq variable (x : ℝ) /-- the series `sqrtTwoAddSeries x n` is `sqrt(2 + sqrt(2 + ... ))` with `n` square roots, starting with `x`. We define it here because `cos (pi / 2 ^ (n+1)) = sqrtTwoAddSeries 0 n / 2` -/ @[simp] noncomputable def sqrtTwoAddSeries (x : ℝ) : β„• β†’ ℝ | 0 => x | n + 1 => √(2 + sqrtTwoAddSeries x n) theorem sqrtTwoAddSeries_zero : sqrtTwoAddSeries x 0 = x := by simp theorem sqrtTwoAddSeries_one : sqrtTwoAddSeries 0 1 = √2 := by simp theorem sqrtTwoAddSeries_two : sqrtTwoAddSeries 0 2 = √(2 + √2) := by simp theorem sqrtTwoAddSeries_zero_nonneg : βˆ€ n : β„•, 0 ≀ sqrtTwoAddSeries 0 n | 0 => le_refl 0 | _ + 1 => sqrt_nonneg _ theorem sqrtTwoAddSeries_nonneg {x : ℝ} (h : 0 ≀ x) : βˆ€ n : β„•, 0 ≀ sqrtTwoAddSeries x n | 0 => h | _ + 1 => sqrt_nonneg _ theorem sqrtTwoAddSeries_lt_two : βˆ€ n : β„•, sqrtTwoAddSeries 0 n < 2 | 0 => by simp | n + 1 => by refine lt_of_lt_of_le ?_ (sqrt_sq zero_lt_two.le).le rw [sqrtTwoAddSeries, sqrt_lt_sqrt_iff, ← lt_sub_iff_add_lt'] Β· refine (sqrtTwoAddSeries_lt_two n).trans_le ?_ norm_num Β· exact add_nonneg zero_le_two (sqrtTwoAddSeries_zero_nonneg n) theorem sqrtTwoAddSeries_succ (x : ℝ) : βˆ€ n : β„•, sqrtTwoAddSeries x (n + 1) = sqrtTwoAddSeries (√(2 + x)) n | 0 => rfl | n + 1 => by rw [sqrtTwoAddSeries, sqrtTwoAddSeries_succ _ _, sqrtTwoAddSeries] @[gcongr] theorem sqrtTwoAddSeries_monotone_left {x y : ℝ} (h : x ≀ y) : βˆ€ n : β„•, sqrtTwoAddSeries x n ≀ sqrtTwoAddSeries y n | 0 => h | n + 1 => by rw [sqrtTwoAddSeries, sqrtTwoAddSeries]; gcongr; exact sqrtTwoAddSeries_monotone_left h _ @[simp] theorem cos_pi_over_two_pow : βˆ€ n : β„•, cos (Ο€ / 2 ^ (n + 1)) = sqrtTwoAddSeries 0 n / 2 | 0 => by simp | n + 1 => by have A : (1 : ℝ) < 2 ^ (n + 1) := one_lt_powβ‚€ one_lt_two n.succ_ne_zero have B : Ο€ / 2 ^ (n + 1) < Ο€ := div_lt_self pi_pos A have C : 0 < Ο€ / 2 ^ (n + 1) := by positivity rw [pow_succ, div_mul_eq_div_div, cos_half, cos_pi_over_two_pow n, sqrtTwoAddSeries, add_div_eq_mul_add_div, one_mul, ← div_mul_eq_div_div, sqrt_div, sqrt_mul_self] <;> linarith [sqrtTwoAddSeries_nonneg le_rfl n] theorem sin_sq_pi_over_two_pow (n : β„•) : sin (Ο€ / 2 ^ (n + 1)) ^ 2 = 1 - (sqrtTwoAddSeries 0 n / 2) ^ 2 := by rw [sin_sq, cos_pi_over_two_pow] theorem sin_sq_pi_over_two_pow_succ (n : β„•) : sin (Ο€ / 2 ^ (n + 2)) ^ 2 = 1 / 2 - sqrtTwoAddSeries 0 n / 4 := by rw [sin_sq_pi_over_two_pow, sqrtTwoAddSeries, div_pow, sq_sqrt, add_div, ← sub_sub] Β· congr Β· norm_num Β· norm_num Β· exact add_nonneg two_pos.le (sqrtTwoAddSeries_zero_nonneg _) @[simp] theorem sin_pi_over_two_pow_succ (n : β„•) : sin (Ο€ / 2 ^ (n + 2)) = √(2 - sqrtTwoAddSeries 0 n) / 2 := by rw [eq_div_iff_mul_eq two_ne_zero, eq_comm, sqrt_eq_iff_eq_sq, mul_pow, sin_sq_pi_over_two_pow_succ, sub_mul] Β· congr <;> norm_num Β· rw [sub_nonneg] exact (sqrtTwoAddSeries_lt_two _).le refine mul_nonneg (sin_nonneg_of_nonneg_of_le_pi ?_ ?_) zero_le_two Β· positivity Β· exact div_le_self pi_pos.le <| one_le_powβ‚€ one_le_two @[simp] theorem cos_pi_div_four : cos (Ο€ / 4) = √2 / 2 := by trans cos (Ο€ / 2 ^ 2) Β· congr norm_num Β· simp @[simp] theorem sin_pi_div_four : sin (Ο€ / 4) = √2 / 2 := by trans sin (Ο€ / 2 ^ 2) Β· congr norm_num Β· simp @[simp] theorem cos_pi_div_eight : cos (Ο€ / 8) = √(2 + √2) / 2 := by trans cos (Ο€ / 2 ^ 3) Β· congr norm_num Β· simp @[simp] theorem sin_pi_div_eight : sin (Ο€ / 8) = √(2 - √2) / 2 := by trans sin (Ο€ / 2 ^ 3) Β· congr norm_num Β· simp @[simp] theorem cos_pi_div_sixteen : cos (Ο€ / 16) = √(2 + √(2 + √2)) / 2 := by trans cos (Ο€ / 2 ^ 4) Β· congr norm_num Β· simp @[simp] theorem sin_pi_div_sixteen : sin (Ο€ / 16) = √(2 - √(2 + √2)) / 2 := by trans sin (Ο€ / 2 ^ 4) Β· congr norm_num Β· simp @[simp] theorem cos_pi_div_thirty_two : cos (Ο€ / 32) = √(2 + √(2 + √(2 + √2))) / 2 := by trans cos (Ο€ / 2 ^ 5) Β· congr norm_num Β· simp @[simp] theorem sin_pi_div_thirty_two : sin (Ο€ / 32) = √(2 - √(2 + √(2 + √2))) / 2 := by trans sin (Ο€ / 2 ^ 5) Β· congr norm_num Β· simp -- This section is also a convenient location for other explicit values of `sin` and `cos`. /-- The cosine of `Ο€ / 3` is `1 / 2`. -/ @[simp] theorem cos_pi_div_three : cos (Ο€ / 3) = 1 / 2 := by have h₁ : (2 * cos (Ο€ / 3) - 1) ^ 2 * (2 * cos (Ο€ / 3) + 2) = 0 := by have : cos (3 * (Ο€ / 3)) = cos Ο€ := by congr 1 ring linarith [cos_pi, cos_three_mul (Ο€ / 3)] rcases mul_eq_zero.mp h₁ with h | h Β· linarith [eq_zero_of_pow_eq_zero h] Β· have : cos Ο€ < cos (Ο€ / 3) := by refine cos_lt_cos_of_nonneg_of_le_pi ?_ le_rfl ?_ <;> linarith [pi_pos] linarith [cos_pi] /-- The cosine of `Ο€ / 6` is `√3 / 2`. -/ @[simp] theorem cos_pi_div_six : cos (Ο€ / 6) = √3 / 2 := by rw [show (6 : ℝ) = 3 * 2 by norm_num, div_mul_eq_div_div, cos_half, cos_pi_div_three, one_add_div, ← div_mul_eq_div_div, two_add_one_eq_three, sqrt_div, sqrt_mul_self] <;> linarith [pi_pos] /-- The square of the cosine of `Ο€ / 6` is `3 / 4` (this is sometimes more convenient than the result for cosine itself). -/ theorem sq_cos_pi_div_six : cos (Ο€ / 6) ^ 2 = 3 / 4 := by rw [cos_pi_div_six, div_pow, sq_sqrt] <;> norm_num /-- The sine of `Ο€ / 6` is `1 / 2`. -/ @[simp] theorem sin_pi_div_six : sin (Ο€ / 6) = 1 / 2 := by rw [← cos_pi_div_two_sub, ← cos_pi_div_three] congr ring /-- The square of the sine of `Ο€ / 3` is `3 / 4` (this is sometimes more convenient than the result for cosine itself). -/ theorem sq_sin_pi_div_three : sin (Ο€ / 3) ^ 2 = 3 / 4 := by rw [← cos_pi_div_two_sub, ← sq_cos_pi_div_six] congr ring /-- The sine of `Ο€ / 3` is `√3 / 2`. -/ @[simp] theorem sin_pi_div_three : sin (Ο€ / 3) = √3 / 2 := by rw [← cos_pi_div_two_sub, ← cos_pi_div_six] congr ring theorem quadratic_root_cos_pi_div_five : letI c := cos (Ο€ / 5) 4 * c ^ 2 - 2 * c - 1 = 0 := by set ΞΈ := Ο€ / 5 with hΞΈ set c := cos ΞΈ set s := sin ΞΈ suffices 2 * c = 4 * c ^ 2 - 1 by simp [this] have hs : s β‰  0 := by rw [ne_eq, sin_eq_zero_iff, hΞΈ] push_neg intro n hn replace hn : n * 5 = 1 := by field_simp at hn; norm_cast at hn omega suffices s * (2 * c) = s * (4 * c ^ 2 - 1) from mul_left_cancelβ‚€ hs this calc s * (2 * c) = 2 * s * c := by rw [← mul_assoc, mul_comm 2] _ = sin (2 * ΞΈ) := by rw [sin_two_mul] _ = sin (Ο€ - 2 * ΞΈ) := by rw [sin_pi_sub] _ = sin (2 * ΞΈ + ΞΈ) := by congr; linarith _ = sin (2 * ΞΈ) * c + cos (2 * ΞΈ) * s := sin_add (2 * ΞΈ) ΞΈ _ = 2 * s * c * c + cos (2 * ΞΈ) * s := by rw [sin_two_mul] _ = 2 * s * c * c + (2 * c ^ 2 - 1) * s := by rw [cos_two_mul] _ = s * (2 * c * c) + s * (2 * c ^ 2 - 1) := by linarith _ = s * (4 * c ^ 2 - 1) := by linarith open Polynomial in theorem Polynomial.isRoot_cos_pi_div_five : (4 β€’ X ^ 2 - 2 β€’ X - C 1 : ℝ[X]).IsRoot (cos (Ο€ / 5)) := by simpa using quadratic_root_cos_pi_div_five /-- The cosine of `Ο€ / 5` is `(1 + √5) / 4`. -/ @[simp] theorem cos_pi_div_five : cos (Ο€ / 5) = (1 + √5) / 4 := by set c := cos (Ο€ / 5) have : 4 * (c * c) + (-2) * c + (-1) = 0 := by rw [← sq, neg_mul, ← sub_eq_add_neg, ← sub_eq_add_neg] exact quadratic_root_cos_pi_div_five have hd : discrim 4 (-2) (-1) = (2 * √5) * (2 * √5) := by norm_num [discrim, mul_mul_mul_comm] rcases (quadratic_eq_zero_iff (by simp) hd c).mp this with h | h Β· simp [h]; linarith Β· absurd (show 0 ≀ c from cos_nonneg_of_mem_Icc <| by constructor <;> linarith [pi_pos.le]) rw [not_le, h] exact div_neg_of_neg_of_pos (by norm_num [lt_sqrt]) (by positivity) end CosDivSq /-- `Real.sin` as an `OrderIso` between `[-(Ο€ / 2), Ο€ / 2]` and `[-1, 1]`. -/ def sinOrderIso : Icc (-(Ο€ / 2)) (Ο€ / 2) ≃o Icc (-1 : ℝ) 1 := (strictMonoOn_sin.orderIso _ _).trans <| OrderIso.setCongr _ _ bijOn_sin.image_eq @[simp] theorem coe_sinOrderIso_apply (x : Icc (-(Ο€ / 2)) (Ο€ / 2)) : (sinOrderIso x : ℝ) = sin x := rfl theorem sinOrderIso_apply (x : Icc (-(Ο€ / 2)) (Ο€ / 2)) : sinOrderIso x = ⟨sin x, sin_mem_Icc x⟩ := rfl @[simp] theorem tan_pi_div_four : tan (Ο€ / 4) = 1 := by rw [tan_eq_sin_div_cos, cos_pi_div_four, sin_pi_div_four] have h : √2 / 2 > 0 := by positivity exact div_self (ne_of_gt h) @[simp] theorem tan_pi_div_two : tan (Ο€ / 2) = 0 := by simp [tan_eq_sin_div_cos] @[simp] theorem tan_pi_div_six : tan (Ο€ / 6) = 1 / √3 := by rw [tan_eq_sin_div_cos, sin_pi_div_six, cos_pi_div_six] ring @[simp] theorem tan_pi_div_three : tan (Ο€ / 3) = √3 := by rw [tan_eq_sin_div_cos, sin_pi_div_three, cos_pi_div_three] ring theorem tan_pos_of_pos_of_lt_pi_div_two {x : ℝ} (h0x : 0 < x) (hxp : x < Ο€ / 2) : 0 < tan x := by rw [tan_eq_sin_div_cos] exact div_pos (sin_pos_of_pos_of_lt_pi h0x (by linarith)) (cos_pos_of_mem_Ioo ⟨by linarith, hxp⟩) theorem tan_nonneg_of_nonneg_of_le_pi_div_two {x : ℝ} (h0x : 0 ≀ x) (hxp : x ≀ Ο€ / 2) : 0 ≀ tan x := match lt_or_eq_of_le h0x, lt_or_eq_of_le hxp with | Or.inl hx0, Or.inl hxp => le_of_lt (tan_pos_of_pos_of_lt_pi_div_two hx0 hxp) | Or.inl _, Or.inr hxp => by simp [hxp, tan_eq_sin_div_cos] | Or.inr hx0, _ => by simp [hx0.symm] theorem tan_neg_of_neg_of_pi_div_two_lt {x : ℝ} (hx0 : x < 0) (hpx : -(Ο€ / 2) < x) : tan x < 0 := neg_pos.1 (tan_neg x β–Έ tan_pos_of_pos_of_lt_pi_div_two (by linarith) (by linarith [pi_pos])) theorem tan_nonpos_of_nonpos_of_neg_pi_div_two_le {x : ℝ} (hx0 : x ≀ 0) (hpx : -(Ο€ / 2) ≀ x) : tan x ≀ 0 := neg_nonneg.1 (tan_neg x β–Έ tan_nonneg_of_nonneg_of_le_pi_div_two (by linarith) (by linarith)) theorem strictMonoOn_tan : StrictMonoOn tan (Ioo (-(Ο€ / 2)) (Ο€ / 2)) := by rintro x hx y hy hlt rw [tan_eq_sin_div_cos, tan_eq_sin_div_cos, div_lt_div_iffβ‚€ (cos_pos_of_mem_Ioo hx) (cos_pos_of_mem_Ioo hy), mul_comm, ← sub_pos, ← sin_sub] exact sin_pos_of_pos_of_lt_pi (sub_pos.2 hlt) <| by linarith [hx.1, hy.2] theorem tan_lt_tan_of_lt_of_lt_pi_div_two {x y : ℝ} (hx₁ : -(Ο€ / 2) < x) (hyβ‚‚ : y < Ο€ / 2) (hxy : x < y) : tan x < tan y := strictMonoOn_tan ⟨hx₁, hxy.trans hyβ‚‚βŸ© ⟨hx₁.trans hxy, hyβ‚‚βŸ© hxy theorem tan_lt_tan_of_nonneg_of_lt_pi_div_two {x y : ℝ} (hx₁ : 0 ≀ x) (hyβ‚‚ : y < Ο€ / 2) (hxy : x < y) : tan x < tan y := tan_lt_tan_of_lt_of_lt_pi_div_two (by linarith) hyβ‚‚ hxy theorem injOn_tan : InjOn tan (Ioo (-(Ο€ / 2)) (Ο€ / 2)) := strictMonoOn_tan.injOn theorem tan_inj_of_lt_of_lt_pi_div_two {x y : ℝ} (hx₁ : -(Ο€ / 2) < x) (hxβ‚‚ : x < Ο€ / 2) (hy₁ : -(Ο€ / 2) < y) (hyβ‚‚ : y < Ο€ / 2) (hxy : tan x = tan y) : x = y := injOn_tan ⟨hx₁, hxβ‚‚βŸ© ⟨hy₁, hyβ‚‚βŸ© hxy theorem tan_periodic : Function.Periodic tan Ο€ := by simpa only [Function.Periodic, tan_eq_sin_div_cos] using sin_antiperiodic.div cos_antiperiodic @[simp] theorem tan_pi : tan Ο€ = 0 := by rw [tan_periodic.eq, tan_zero] theorem tan_add_pi (x : ℝ) : tan (x + Ο€) = tan x := tan_periodic x theorem tan_sub_pi (x : ℝ) : tan (x - Ο€) = tan x := tan_periodic.sub_eq x theorem tan_pi_sub (x : ℝ) : tan (Ο€ - x) = -tan x := tan_neg x β–Έ tan_periodic.sub_eq' theorem tan_pi_div_two_sub (x : ℝ) : tan (Ο€ / 2 - x) = (tan x)⁻¹ := by rw [tan_eq_sin_div_cos, tan_eq_sin_div_cos, inv_div, sin_pi_div_two_sub, cos_pi_div_two_sub] theorem tan_nat_mul_pi (n : β„•) : tan (n * Ο€) = 0 := tan_zero β–Έ tan_periodic.nat_mul_eq n theorem tan_int_mul_pi (n : β„€) : tan (n * Ο€) = 0 := tan_zero β–Έ tan_periodic.int_mul_eq n theorem tan_add_nat_mul_pi (x : ℝ) (n : β„•) : tan (x + n * Ο€) = tan x := tan_periodic.nat_mul n x theorem tan_add_int_mul_pi (x : ℝ) (n : β„€) : tan (x + n * Ο€) = tan x := tan_periodic.int_mul n x theorem tan_sub_nat_mul_pi (x : ℝ) (n : β„•) : tan (x - n * Ο€) = tan x := tan_periodic.sub_nat_mul_eq n theorem tan_sub_int_mul_pi (x : ℝ) (n : β„€) : tan (x - n * Ο€) = tan x := tan_periodic.sub_int_mul_eq n theorem tan_nat_mul_pi_sub (x : ℝ) (n : β„•) : tan (n * Ο€ - x) = -tan x := tan_neg x β–Έ tan_periodic.nat_mul_sub_eq n theorem tan_int_mul_pi_sub (x : ℝ) (n : β„€) : tan (n * Ο€ - x) = -tan x := tan_neg x β–Έ tan_periodic.int_mul_sub_eq n theorem tendsto_sin_pi_div_two : Tendsto sin (𝓝[<] (Ο€ / 2)) (𝓝 1) := by convert continuous_sin.continuousWithinAt.tendsto simp theorem tendsto_cos_pi_div_two : Tendsto cos (𝓝[<] (Ο€ / 2)) (𝓝[>] 0) := by apply tendsto_nhdsWithin_of_tendsto_nhds_of_eventually_within Β· convert continuous_cos.continuousWithinAt.tendsto simp Β· filter_upwards [Ioo_mem_nhdsLT (neg_lt_self pi_div_two_pos)] with x hx exact cos_pos_of_mem_Ioo hx theorem tendsto_tan_pi_div_two : Tendsto tan (𝓝[<] (Ο€ / 2)) atTop := by convert tendsto_cos_pi_div_two.inv_tendsto_nhdsGT_zero.atTop_mul_pos zero_lt_one tendsto_sin_pi_div_two using 1 simp only [Pi.inv_apply, ← div_eq_inv_mul, ← tan_eq_sin_div_cos] theorem tendsto_sin_neg_pi_div_two : Tendsto sin (𝓝[>] (-(Ο€ / 2))) (𝓝 (-1)) := by convert continuous_sin.continuousWithinAt.tendsto using 2 simp theorem tendsto_cos_neg_pi_div_two : Tendsto cos (𝓝[>] (-(Ο€ / 2))) (𝓝[>] 0) := by apply tendsto_nhdsWithin_of_tendsto_nhds_of_eventually_within Β· convert continuous_cos.continuousWithinAt.tendsto simp Β· filter_upwards [Ioo_mem_nhdsGT (neg_lt_self pi_div_two_pos)] with x hx exact cos_pos_of_mem_Ioo hx theorem tendsto_tan_neg_pi_div_two : Tendsto tan (𝓝[>] (-(Ο€ / 2))) atBot := by convert tendsto_cos_neg_pi_div_two.inv_tendsto_nhdsGT_zero.atTop_mul_neg (by simp) tendsto_sin_neg_pi_div_two using 1 simp only [Pi.inv_apply, ← div_eq_inv_mul, ← tan_eq_sin_div_cos] end Real namespace Complex open Real theorem sin_eq_zero_iff_cos_eq {z : β„‚} : sin z = 0 ↔ cos z = 1 ∨ cos z = -1 := by rw [← mul_self_eq_one_iff, ← sin_sq_add_cos_sq, sq, sq, right_eq_add, mul_eq_zero, or_self] theorem cos_eq_zero_iff_sin_eq {z : β„‚} : cos z = 0 ↔ sin z = 1 ∨ sin z = -1 := by rw [← mul_self_eq_one_iff, ← sin_sq_add_cos_sq, sq, sq, left_eq_add, mul_eq_zero, or_self] @[simp] theorem cos_pi_div_two : cos (Ο€ / 2) = 0 := calc cos (Ο€ / 2) = Real.cos (Ο€ / 2) := by rw [ofReal_cos]; simp _ = 0 := by simp @[simp] theorem sin_pi_div_two : sin (Ο€ / 2) = 1 := calc sin (Ο€ / 2) = Real.sin (Ο€ / 2) := by rw [ofReal_sin]; simp _ = 1 := by simp @[simp] theorem sin_pi : sin Ο€ = 0 := by rw [← ofReal_sin, Real.sin_pi]; simp @[simp] theorem cos_pi : cos Ο€ = -1 := by rw [← ofReal_cos, Real.cos_pi]; simp @[simp] theorem sin_two_pi : sin (2 * Ο€) = 0 := by simp [two_mul, sin_add] @[simp] theorem cos_two_pi : cos (2 * Ο€) = 1 := by simp [two_mul, cos_add] theorem sin_antiperiodic : Function.Antiperiodic sin Ο€ := by simp [sin_add] theorem sin_periodic : Function.Periodic sin (2 * Ο€) := sin_antiperiodic.periodic_two_mul theorem sin_add_pi (x : β„‚) : sin (x + Ο€) = -sin x := sin_antiperiodic x theorem sin_add_two_pi (x : β„‚) : sin (x + 2 * Ο€) = sin x := sin_periodic x theorem sin_sub_pi (x : β„‚) : sin (x - Ο€) = -sin x := sin_antiperiodic.sub_eq x theorem sin_sub_two_pi (x : β„‚) : sin (x - 2 * Ο€) = sin x := sin_periodic.sub_eq x theorem sin_pi_sub (x : β„‚) : sin (Ο€ - x) = sin x := neg_neg (sin x) β–Έ sin_neg x β–Έ sin_antiperiodic.sub_eq' theorem sin_two_pi_sub (x : β„‚) : sin (2 * Ο€ - x) = -sin x := sin_neg x β–Έ sin_periodic.sub_eq' theorem sin_nat_mul_pi (n : β„•) : sin (n * Ο€) = 0 := sin_antiperiodic.nat_mul_eq_of_eq_zero sin_zero n theorem sin_int_mul_pi (n : β„€) : sin (n * Ο€) = 0 := sin_antiperiodic.int_mul_eq_of_eq_zero sin_zero n theorem sin_add_nat_mul_two_pi (x : β„‚) (n : β„•) : sin (x + n * (2 * Ο€)) = sin x := sin_periodic.nat_mul n x theorem sin_add_int_mul_two_pi (x : β„‚) (n : β„€) : sin (x + n * (2 * Ο€)) = sin x := sin_periodic.int_mul n x theorem sin_sub_nat_mul_two_pi (x : β„‚) (n : β„•) : sin (x - n * (2 * Ο€)) = sin x := sin_periodic.sub_nat_mul_eq n theorem sin_sub_int_mul_two_pi (x : β„‚) (n : β„€) : sin (x - n * (2 * Ο€)) = sin x := sin_periodic.sub_int_mul_eq n theorem sin_nat_mul_two_pi_sub (x : β„‚) (n : β„•) : sin (n * (2 * Ο€) - x) = -sin x := sin_neg x β–Έ sin_periodic.nat_mul_sub_eq n theorem sin_int_mul_two_pi_sub (x : β„‚) (n : β„€) : sin (n * (2 * Ο€) - x) = -sin x := sin_neg x β–Έ sin_periodic.int_mul_sub_eq n theorem cos_antiperiodic : Function.Antiperiodic cos Ο€ := by simp [cos_add] theorem cos_periodic : Function.Periodic cos (2 * Ο€) := cos_antiperiodic.periodic_two_mul theorem cos_add_pi (x : β„‚) : cos (x + Ο€) = -cos x := cos_antiperiodic x theorem cos_add_two_pi (x : β„‚) : cos (x + 2 * Ο€) = cos x := cos_periodic x theorem cos_sub_pi (x : β„‚) : cos (x - Ο€) = -cos x := cos_antiperiodic.sub_eq x theorem cos_sub_two_pi (x : β„‚) : cos (x - 2 * Ο€) = cos x := cos_periodic.sub_eq x theorem cos_pi_sub (x : β„‚) : cos (Ο€ - x) = -cos x := cos_neg x β–Έ cos_antiperiodic.sub_eq' theorem cos_two_pi_sub (x : β„‚) : cos (2 * Ο€ - x) = cos x := cos_neg x β–Έ cos_periodic.sub_eq' theorem cos_nat_mul_two_pi (n : β„•) : cos (n * (2 * Ο€)) = 1 := (cos_periodic.nat_mul_eq n).trans cos_zero theorem cos_int_mul_two_pi (n : β„€) : cos (n * (2 * Ο€)) = 1 := (cos_periodic.int_mul_eq n).trans cos_zero theorem cos_add_nat_mul_two_pi (x : β„‚) (n : β„•) : cos (x + n * (2 * Ο€)) = cos x := cos_periodic.nat_mul n x theorem cos_add_int_mul_two_pi (x : β„‚) (n : β„€) : cos (x + n * (2 * Ο€)) = cos x := cos_periodic.int_mul n x theorem cos_sub_nat_mul_two_pi (x : β„‚) (n : β„•) : cos (x - n * (2 * Ο€)) = cos x := cos_periodic.sub_nat_mul_eq n theorem cos_sub_int_mul_two_pi (x : β„‚) (n : β„€) : cos (x - n * (2 * Ο€)) = cos x := cos_periodic.sub_int_mul_eq n theorem cos_nat_mul_two_pi_sub (x : β„‚) (n : β„•) : cos (n * (2 * Ο€) - x) = cos x := cos_neg x β–Έ cos_periodic.nat_mul_sub_eq n theorem cos_int_mul_two_pi_sub (x : β„‚) (n : β„€) : cos (n * (2 * Ο€) - x) = cos x := cos_neg x β–Έ cos_periodic.int_mul_sub_eq n theorem cos_nat_mul_two_pi_add_pi (n : β„•) : cos (n * (2 * Ο€) + Ο€) = -1 := by simpa only [cos_zero] using (cos_periodic.nat_mul n).add_antiperiod_eq cos_antiperiodic theorem cos_int_mul_two_pi_add_pi (n : β„€) : cos (n * (2 * Ο€) + Ο€) = -1 := by simpa only [cos_zero] using (cos_periodic.int_mul n).add_antiperiod_eq cos_antiperiodic theorem cos_nat_mul_two_pi_sub_pi (n : β„•) : cos (n * (2 * Ο€) - Ο€) = -1 := by simpa only [cos_zero] using (cos_periodic.nat_mul n).sub_antiperiod_eq cos_antiperiodic theorem cos_int_mul_two_pi_sub_pi (n : β„€) : cos (n * (2 * Ο€) - Ο€) = -1 := by simpa only [cos_zero] using (cos_periodic.int_mul n).sub_antiperiod_eq cos_antiperiodic theorem sin_add_pi_div_two (x : β„‚) : sin (x + Ο€ / 2) = cos x := by simp [sin_add] theorem sin_sub_pi_div_two (x : β„‚) : sin (x - Ο€ / 2) = -cos x := by simp [sub_eq_add_neg, sin_add] theorem sin_pi_div_two_sub (x : β„‚) : sin (Ο€ / 2 - x) = cos x := by simp [sub_eq_add_neg, sin_add] theorem cos_add_pi_div_two (x : β„‚) : cos (x + Ο€ / 2) = -sin x := by simp [cos_add] theorem cos_sub_pi_div_two (x : β„‚) : cos (x - Ο€ / 2) = sin x := by simp [sub_eq_add_neg, cos_add] theorem cos_pi_div_two_sub (x : β„‚) : cos (Ο€ / 2 - x) = sin x := by rw [← cos_neg, neg_sub, cos_sub_pi_div_two] theorem tan_periodic : Function.Periodic tan Ο€ := by simpa only [tan_eq_sin_div_cos] using sin_antiperiodic.div cos_antiperiodic theorem tan_add_pi (x : β„‚) : tan (x + Ο€) = tan x := tan_periodic x theorem tan_sub_pi (x : β„‚) : tan (x - Ο€) = tan x := tan_periodic.sub_eq x theorem tan_pi_sub (x : β„‚) : tan (Ο€ - x) = -tan x := tan_neg x β–Έ tan_periodic.sub_eq' theorem tan_pi_div_two_sub (x : β„‚) : tan (Ο€ / 2 - x) = (tan x)⁻¹ := by rw [tan_eq_sin_div_cos, tan_eq_sin_div_cos, inv_div, sin_pi_div_two_sub, cos_pi_div_two_sub] theorem tan_nat_mul_pi (n : β„•) : tan (n * Ο€) = 0 := tan_zero β–Έ tan_periodic.nat_mul_eq n theorem tan_int_mul_pi (n : β„€) : tan (n * Ο€) = 0 := tan_zero β–Έ tan_periodic.int_mul_eq n theorem tan_add_nat_mul_pi (x : β„‚) (n : β„•) : tan (x + n * Ο€) = tan x := tan_periodic.nat_mul n x theorem tan_add_int_mul_pi (x : β„‚) (n : β„€) : tan (x + n * Ο€) = tan x := tan_periodic.int_mul n x theorem tan_sub_nat_mul_pi (x : β„‚) (n : β„•) : tan (x - n * Ο€) = tan x := tan_periodic.sub_nat_mul_eq n theorem tan_sub_int_mul_pi (x : β„‚) (n : β„€) : tan (x - n * Ο€) = tan x := tan_periodic.sub_int_mul_eq n theorem tan_nat_mul_pi_sub (x : β„‚) (n : β„•) : tan (n * Ο€ - x) = -tan x := tan_neg x β–Έ tan_periodic.nat_mul_sub_eq n theorem tan_int_mul_pi_sub (x : β„‚) (n : β„€) : tan (n * Ο€ - x) = -tan x := tan_neg x β–Έ tan_periodic.int_mul_sub_eq n theorem exp_antiperiodic : Function.Antiperiodic exp (Ο€ * I) := by simp [exp_add, exp_mul_I] theorem exp_periodic : Function.Periodic exp (2 * Ο€ * I) := (mul_assoc (2 : β„‚) Ο€ I).symm β–Έ exp_antiperiodic.periodic_two_mul theorem exp_mul_I_antiperiodic : Function.Antiperiodic (fun x => exp (x * I)) Ο€ := by simpa only [mul_inv_cancel_rightβ‚€ I_ne_zero] using exp_antiperiodic.mul_const I_ne_zero theorem exp_mul_I_periodic : Function.Periodic (fun x => exp (x * I)) (2 * Ο€) := exp_mul_I_antiperiodic.periodic_two_mul @[simp] theorem exp_pi_mul_I : exp (Ο€ * I) = -1 := exp_zero β–Έ exp_antiperiodic.eq @[simp] theorem exp_two_pi_mul_I : exp (2 * Ο€ * I) = 1 := exp_periodic.eq.trans exp_zero @[simp] lemma exp_pi_div_two_mul_I : exp (Ο€ / 2 * I) = I := by rw [← cos_add_sin_I, cos_pi_div_two, sin_pi_div_two, one_mul, zero_add] @[simp] lemma exp_neg_pi_div_two_mul_I : exp (-Ο€ / 2 * I) = -I := by rw [← cos_add_sin_I, neg_div, cos_neg, cos_pi_div_two, sin_neg, sin_pi_div_two, zero_add, neg_mul, one_mul] @[simp] theorem exp_nat_mul_two_pi_mul_I (n : β„•) : exp (n * (2 * Ο€ * I)) = 1 := (exp_periodic.nat_mul_eq n).trans exp_zero @[simp] theorem exp_int_mul_two_pi_mul_I (n : β„€) : exp (n * (2 * Ο€ * I)) = 1 := (exp_periodic.int_mul_eq n).trans exp_zero @[simp] theorem exp_add_pi_mul_I (z : β„‚) : exp (z + Ο€ * I) = -exp z := exp_antiperiodic z @[simp] theorem exp_sub_pi_mul_I (z : β„‚) : exp (z - Ο€ * I) = -exp z := exp_antiperiodic.sub_eq z /-- A supporting lemma for the **Phragmen-LindelΓΆf principle** in a horizontal strip. If `z : β„‚` belongs to a horizontal strip `|Complex.im z| ≀ b`, `b ≀ Ο€ / 2`, and `a ≀ 0`, then $$\left|exp^{a\left(e^{z}+e^{-z}\right)}\right| \le e^{a\cos b \exp^{|re z|}}.$$ -/ theorem norm_exp_mul_exp_add_exp_neg_le_of_abs_im_le {a b : ℝ} (ha : a ≀ 0) {z : β„‚} (hz : |z.im| ≀ b) (hb : b ≀ Ο€ / 2) : β€–exp (a * (exp z + exp (-z)))β€– ≀ Real.exp (a * Real.cos b * Real.exp |z.re|) := by simp only [norm_exp, Real.exp_le_exp, re_ofReal_mul, add_re, exp_re, neg_im, Real.cos_neg, ← add_mul, mul_assoc, mul_comm (Real.cos b), neg_re, ← Real.cos_abs z.im] have : Real.exp |z.re| ≀ Real.exp z.re + Real.exp (-z.re) := apply_abs_le_add_of_nonneg (fun x => (Real.exp_pos x).le) z.re refine mul_le_mul_of_nonpos_left (mul_le_mul this ?_ ?_ ((Real.exp_pos _).le.trans this)) ha Β· exact Real.cos_le_cos_of_nonneg_of_le_pi (_root_.abs_nonneg _) (hb.trans <| half_le_self <| Real.pi_pos.le) hz Β· refine Real.cos_nonneg_of_mem_Icc ⟨?_, hb⟩ exact (neg_nonpos.2 <| Real.pi_div_two_pos.le).trans ((_root_.abs_nonneg _).trans hz) end Complex
.lake/packages/mathlib/Mathlib/Analysis/SpecialFunctions/Trigonometric/Sinc.lean
import Mathlib.Analysis.SpecialFunctions.Trigonometric.Bounds import Mathlib.Analysis.Calculus.DSlope /-! # Sinc function This file contains the definition of the sinc function and some of its properties. ## Main definitions * `Real.sinc`: the (unnormalized) sinc function, defined as `sinc x = sin x / x` for `x β‰  0` and `1` for `x = 0`. ## Main statements * `continuous_sinc`: the sinc function is continuous. -/ open Filter open scoped Topology namespace Real variable {x : ℝ} /-- The function `sin x / x` modified to take the value 1 at 0, which makes it continuous. -/ @[pp_nodot] noncomputable def sinc (x : ℝ) : ℝ := if x = 0 then 1 else sin x / x lemma sinc_apply : sinc x = if x = 0 then 1 else sin x / x := rfl @[simp] lemma sinc_zero : sinc 0 = 1 := by simp [sinc] lemma sinc_of_ne_zero (hx : x β‰  0) : sinc x = sin x / x := by simp [sinc, hx] lemma sinc_eq_dslope : sinc = dslope sin 0 := by ext simp [dslope, Function.update_apply, sinc, slope, div_eq_inv_mul] @[simp] lemma sinc_neg (x : ℝ) : sinc (-x) = sinc x := by by_cases hx : x = 0 Β· simp [hx] Β· simp [sinc_of_ne_zero hx, sinc_of_ne_zero (neg_ne_zero.mpr hx)] lemma abs_sinc_le_one (x : ℝ) : |sinc x| ≀ 1 := by by_cases hx : x = 0 Β· simp [hx] rw [sinc_of_ne_zero hx, abs_div] refine div_le_of_le_mulβ‚€ (abs_nonneg _) zero_le_one ?_ rw [one_mul] exact abs_sin_le_abs lemma sinc_le_one (x : ℝ) : sinc x ≀ 1 := (abs_le.mp (abs_sinc_le_one x)).2 lemma neg_one_le_sinc (x : ℝ) : -1 ≀ sinc x := (abs_le.mp (abs_sinc_le_one x)).1 lemma sin_div_le_inv_abs (x : ℝ) : sin x / x ≀ |x|⁻¹ := by rcases lt_trichotomy x 0 with hx | rfl | hx Β· rw [abs_of_nonpos hx.le, ← one_div, le_div_iffβ‚€, div_eq_mul_inv] Β· ring_nf rw [mul_assoc, mul_inv_cancelβ‚€ hx.ne, mul_one, neg_le] exact neg_one_le_sin x Β· simpa using hx Β· simp Β· rw [abs_of_nonneg hx.le, div_eq_mul_inv, mul_inv_le_iffβ‚€ hx, inv_mul_cancelβ‚€ hx.ne'] exact sin_le_one x lemma sinc_le_inv_abs (hx : x β‰  0) : sinc x ≀ |x|⁻¹ := by rw [sinc_of_ne_zero hx] exact sin_div_le_inv_abs x /-- The function `sinc` is continuous. -/ @[fun_prop] lemma continuous_sinc : Continuous sinc := by refine continuous_iff_continuousAt.mpr fun x ↦ ?_ rw [sinc_eq_dslope] by_cases hx : x = 0 Β· simp [hx] Β· rw [continuousAt_dslope_of_ne hx] fun_prop end Real
.lake/packages/mathlib/Mathlib/Analysis/SpecialFunctions/Trigonometric/Complex.lean
import Mathlib.Algebra.QuadraticDiscriminant import Mathlib.Analysis.SpecialFunctions.Pow.Complex /-! # Complex trigonometric functions Basic facts and derivatives for the complex trigonometric functions. Several facts about the real trigonometric functions have the proofs deferred here, rather than `Analysis.SpecialFunctions.Trigonometric.Basic`, as they are most easily proved by appealing to the corresponding fact for complex trigonometric functions, or require additional imports which are not available in that file. -/ noncomputable section namespace Complex open Set Filter open scoped Real theorem cos_eq_zero_iff {ΞΈ : β„‚} : cos ΞΈ = 0 ↔ βˆƒ k : β„€, ΞΈ = (2 * k + 1) * Ο€ / 2 := by have h : (exp (ΞΈ * I) + exp (-ΞΈ * I)) / 2 = 0 ↔ exp (2 * ΞΈ * I) = -1 := by rw [@div_eq_iff _ _ (exp (ΞΈ * I) + exp (-ΞΈ * I)) 2 0 two_ne_zero, zero_mul, add_eq_zero_iff_eq_neg, neg_eq_neg_one_mul, ← div_eq_iff (exp_ne_zero _), ← exp_sub] ring_nf rw [cos, h, ← exp_pi_mul_I, exp_eq_exp_iff_exists_int, mul_right_comm] refine exists_congr fun x => ?_ refine (iff_of_eq <| congr_arg _ ?_).trans (mul_right_inj' <| mul_ne_zero two_ne_zero I_ne_zero) ring theorem cos_ne_zero_iff {ΞΈ : β„‚} : cos ΞΈ β‰  0 ↔ βˆ€ k : β„€, ΞΈ β‰  (2 * k + 1) * Ο€ / 2 := by rw [← not_exists, not_iff_not, cos_eq_zero_iff] theorem sin_eq_zero_iff {ΞΈ : β„‚} : sin ΞΈ = 0 ↔ βˆƒ k : β„€, ΞΈ = k * Ο€ := by rw [← Complex.cos_sub_pi_div_two, cos_eq_zero_iff] constructor Β· rintro ⟨k, hk⟩ use k + 1 simp [eq_add_of_sub_eq hk] ring Β· rintro ⟨k, rfl⟩ use k - 1 simp ring theorem sin_ne_zero_iff {ΞΈ : β„‚} : sin ΞΈ β‰  0 ↔ βˆ€ k : β„€, ΞΈ β‰  k * Ο€ := by rw [← not_exists, not_iff_not, sin_eq_zero_iff] /-- The tangent of a complex number is equal to zero iff this number is equal to `k * Ο€ / 2` for an integer `k`. Note that this lemma takes into account that we use zero as the junk value for division by zero. See also `Complex.tan_eq_zero_iff'`. -/ theorem tan_eq_zero_iff {ΞΈ : β„‚} : tan ΞΈ = 0 ↔ βˆƒ k : β„€, k * Ο€ / 2 = ΞΈ := by rw [tan, div_eq_zero_iff, ← mul_eq_zero, ← mul_right_inj' two_ne_zero, mul_zero, ← mul_assoc, ← sin_two_mul, sin_eq_zero_iff] simp [field, mul_comm, eq_comm] theorem tan_ne_zero_iff {ΞΈ : β„‚} : tan ΞΈ β‰  0 ↔ βˆ€ k : β„€, (k * Ο€ / 2 : β„‚) β‰  ΞΈ := by rw [← not_exists, not_iff_not, tan_eq_zero_iff] theorem tan_int_mul_pi_div_two (n : β„€) : tan (n * Ο€ / 2) = 0 := tan_eq_zero_iff.mpr (by use n) /-- If the tangent of a complex number is well-defined, then it is equal to zero iff the number is equal to `k * Ο€` for an integer `k`. See also `Complex.tan_eq_zero_iff` for a version that takes into account junk values of `ΞΈ`. -/ theorem tan_eq_zero_iff' {ΞΈ : β„‚} (hΞΈ : cos ΞΈ β‰  0) : tan ΞΈ = 0 ↔ βˆƒ k : β„€, k * Ο€ = ΞΈ := by simp only [tan, hΞΈ, div_eq_zero_iff, sin_eq_zero_iff]; simp [eq_comm] theorem cos_eq_cos_iff {x y : β„‚} : cos x = cos y ↔ βˆƒ k : β„€, y = 2 * k * Ο€ + x ∨ y = 2 * k * Ο€ - x := calc cos x = cos y ↔ cos x - cos y = 0 := sub_eq_zero.symm _ ↔ -2 * sin ((x + y) / 2) * sin ((x - y) / 2) = 0 := by rw [cos_sub_cos] _ ↔ sin ((x + y) / 2) = 0 ∨ sin ((x - y) / 2) = 0 := by simp [(by simp : (2 : β„‚) β‰  0)] _ ↔ sin ((x - y) / 2) = 0 ∨ sin ((x + y) / 2) = 0 := or_comm _ ↔ (βˆƒ k : β„€, y = 2 * k * Ο€ + x) ∨ βˆƒ k : β„€, y = 2 * k * Ο€ - x := by apply or_congr <;> simp [field, sin_eq_zero_iff, eq_sub_iff_add_eq', sub_eq_iff_eq_add, mul_comm (2 : β„‚), mul_right_comm _ (2 : β„‚)] constructor <;> Β· rintro ⟨k, rfl⟩; use -k; simp _ ↔ βˆƒ k : β„€, y = 2 * k * Ο€ + x ∨ y = 2 * k * Ο€ - x := exists_or.symm theorem sin_eq_sin_iff {x y : β„‚} : sin x = sin y ↔ βˆƒ k : β„€, y = 2 * k * Ο€ + x ∨ y = (2 * k + 1) * Ο€ - x := by simp only [← Complex.cos_sub_pi_div_two, cos_eq_cos_iff, sub_eq_iff_eq_add] refine exists_congr fun k => or_congr ?_ ?_ <;> refine Eq.congr rfl ?_ <;> simp [field] <;> ring theorem cos_eq_one_iff {x : β„‚} : cos x = 1 ↔ βˆƒ k : β„€, k * (2 * Ο€) = x := by rw [← cos_zero, eq_comm, cos_eq_cos_iff] simp [mul_assoc, mul_left_comm, eq_comm] theorem cos_eq_neg_one_iff {x : β„‚} : cos x = -1 ↔ βˆƒ k : β„€, Ο€ + k * (2 * Ο€) = x := by rw [← neg_eq_iff_eq_neg, ← cos_sub_pi, cos_eq_one_iff] simp only [eq_sub_iff_add_eq'] theorem sin_eq_one_iff {x : β„‚} : sin x = 1 ↔ βˆƒ k : β„€, Ο€ / 2 + k * (2 * Ο€) = x := by rw [← cos_sub_pi_div_two, cos_eq_one_iff] simp only [eq_sub_iff_add_eq'] theorem sin_eq_neg_one_iff {x : β„‚} : sin x = -1 ↔ βˆƒ k : β„€, -(Ο€ / 2) + k * (2 * Ο€) = x := by rw [← neg_eq_iff_eq_neg, ← cos_add_pi_div_two, cos_eq_one_iff] simp only [← sub_eq_neg_add, sub_eq_iff_eq_add] theorem tan_add {x y : β„‚} (h : ((βˆ€ k : β„€, x β‰  (2 * k + 1) * Ο€ / 2) ∧ βˆ€ l : β„€, y β‰  (2 * l + 1) * Ο€ / 2) ∨ (βˆƒ k : β„€, x = (2 * k + 1) * Ο€ / 2) ∧ βˆƒ l : β„€, y = (2 * l + 1) * Ο€ / 2) : tan (x + y) = (tan x + tan y) / (1 - tan x * tan y) := by rcases h with (⟨h1, h2⟩ | ⟨⟨k, rfl⟩, ⟨l, rfl⟩⟩) Β· rw [tan, sin_add, cos_add, ← div_div_div_cancel_rightβ‚€ (mul_ne_zero (cos_ne_zero_iff.mpr h1) (cos_ne_zero_iff.mpr h2)), add_div, sub_div] simp only [← div_mul_div_comm, tan, mul_one, one_mul, div_self (cos_ne_zero_iff.mpr h1), div_self (cos_ne_zero_iff.mpr h2)] Β· haveI t := tan_int_mul_pi_div_two obtain ⟨hx, hy, hxy⟩ := t (2 * k + 1), t (2 * l + 1), t (2 * k + 1 + (2 * l + 1)) simp only [Int.cast_add, Int.cast_two, Int.cast_mul, Int.cast_one] at hx hy hxy rw [hx, hy, add_zero, zero_div, mul_div_assoc, mul_div_assoc, ← add_mul (2 * (k : β„‚) + 1) (2 * l + 1) (Ο€ / 2), ← mul_div_assoc, hxy] theorem tan_add' {x y : β„‚} (h : (βˆ€ k : β„€, x β‰  (2 * k + 1) * Ο€ / 2) ∧ βˆ€ l : β„€, y β‰  (2 * l + 1) * Ο€ / 2) : tan (x + y) = (tan x + tan y) / (1 - tan x * tan y) := tan_add (Or.inl h) theorem tan_sub {x y : β„‚} (h : ((βˆ€ k : β„€, x β‰  (2 * k + 1) * Ο€ / 2) ∧ βˆ€ l : β„€, y β‰  (2 * l + 1) * Ο€ / 2) ∨ (βˆƒ k : β„€, x = (2 * k + 1) * Ο€ / 2) ∧ βˆƒ l : β„€, y = (2 * l + 1) * Ο€ / 2) : tan (x - y) = (tan x - tan y) / (1 + tan x * tan y) := by have := tan_add (x := x) (y := -y) <| by rcases h with ⟨x_ne, minus_y_ne⟩ | ⟨x_eq, minus_y_eq⟩ Β· refine .inl ⟨x_ne, fun l => ?_⟩ rw [Ne, neg_eq_iff_eq_neg] convert minus_y_ne (-l - 1) using 2 push_cast ring Β· refine .inr ⟨x_eq, ?_⟩ rcases minus_y_eq with ⟨l, rfl⟩ use -l - 1 push_cast ring rw [tan_neg] at this convert this using 2 ring theorem tan_sub' {x y : β„‚} (h : (βˆ€ k : β„€, x β‰  (2 * k + 1) * Ο€ / 2) ∧ βˆ€ l : β„€, y β‰  (2 * l + 1) * Ο€ / 2) : tan (x - y) = (tan x - tan y) / (1 + tan x * tan y) := tan_sub (Or.inl h) theorem tan_two_mul {z : β„‚} : tan (2 * z) = (2 : β„‚) * tan z / ((1 : β„‚) - tan z ^ 2) := by by_cases! h : βˆ€ k : β„€, z β‰  (2 * k + 1) * Ο€ / 2 Β· rw [two_mul, two_mul, sq, tan_add (Or.inl ⟨h, h⟩)] Β· rw [two_mul, two_mul, sq, tan_add (Or.inr ⟨h, h⟩)] theorem tan_add_mul_I {x y : β„‚} (h : ((βˆ€ k : β„€, x β‰  (2 * k + 1) * Ο€ / 2) ∧ βˆ€ l : β„€, y * I β‰  (2 * l + 1) * Ο€ / 2) ∨ (βˆƒ k : β„€, x = (2 * k + 1) * Ο€ / 2) ∧ βˆƒ l : β„€, y * I = (2 * l + 1) * Ο€ / 2) : tan (x + y * I) = (tan x + tanh y * I) / (1 - tan x * tanh y * I) := by rw [tan_add h, tan_mul_I, mul_assoc] theorem tan_eq {z : β„‚} (h : ((βˆ€ k : β„€, (z.re : β„‚) β‰  (2 * k + 1) * Ο€ / 2) ∧ βˆ€ l : β„€, (z.im : β„‚) * I β‰  (2 * l + 1) * Ο€ / 2) ∨ (βˆƒ k : β„€, (z.re : β„‚) = (2 * k + 1) * Ο€ / 2) ∧ βˆƒ l : β„€, (z.im : β„‚) * I = (2 * l + 1) * Ο€ / 2) : tan z = (tan z.re + tanh z.im * I) / (1 - tan z.re * tanh z.im * I) := by convert tan_add_mul_I h; exact (re_add_im z).symm /-- `tan x` takes the junk value `0` when `cos x = 0` -/ lemma tan_eq_zero_of_cos_eq_zero {x} (h : cos x = 0) : tan x = 0 := by obtain ⟨k, hxk⟩ := cos_eq_zero_iff.mp h exact tan_eq_zero_iff.mpr ⟨2 * k + 1, by simp [hxk]⟩ -- tangent half-angle substitution formulas theorem cos_eq_two_mul_tan_half_div_one_sub_tan_half_sq (x : β„‚) (h : cos x β‰  -1) : cos x = (1 - tan (x / 2) ^ 2) / (1 + tan (x / 2) ^ 2) := by conv_lhs => rw [← mul_div_cancelβ‚€ x two_ne_zero, cos_two_mul'] have : cos (x / 2) β‰  0 := by grind [cos_ne_zero_iff, cos_eq_neg_one_iff] rw [div_eq_mul_inv (1 - tan (x / 2) ^ 2) (1 + tan (x / 2) ^ 2), inv_one_add_tan_sq this, ← tan_mul_cos this] ring /-- `tan (x / 2)` takes the junk value `0` when `sin x = 0` so this always holds. -/ theorem sin_eq_two_mul_tan_half_div_one_add_tan_half_sq (x : β„‚) : sin x = (2 * tan (x / 2)) / (1 + tan (x / 2) ^ 2) := by conv_lhs => rw [← mul_div_cancelβ‚€ x two_ne_zero, sin_two_mul] by_cases h : cos (x / 2) = 0 Β· simp [h, tan_eq_zero_of_cos_eq_zero] Β· rw [div_eq_mul_inv (2 * tan (x / 2)) (1 + tan (x / 2) ^ 2), inv_one_add_tan_sq h, ← tan_mul_cos h] ring theorem tan_eq_one_sub_tan_half_sq_div_one_add_tan_half_sq (x : β„‚) : tan x = (2 * tan (x / 2)) / (1 - tan (x / 2) ^ 2) := by conv_lhs => rw [← mul_div_cancelβ‚€ x two_ne_zero, tan_two_mul] open scoped Topology theorem continuousOn_tan : ContinuousOn tan {x | cos x β‰  0} := continuousOn_sin.div continuousOn_cos fun _x => id @[continuity] theorem continuous_tan : Continuous fun x : {x | cos x β‰  0} => tan x := continuousOn_iff_continuous_restrict.1 continuousOn_tan theorem cos_eq_iff_quadratic {z w : β„‚} : cos z = w ↔ exp (z * I) ^ 2 - 2 * w * exp (z * I) + 1 = 0 := by rw [← sub_eq_zero] simpa [field, cos, exp_neg] using Eq.congr (by ring) rfl theorem cos_surjective : Function.Surjective cos := by intro x obtain ⟨w, wβ‚€, hw⟩ : βˆƒ w β‰  0, 1 * (w * w) + -2 * x * w + 1 = 0 := by rcases exists_quadratic_eq_zero one_ne_zero ⟨_, (cpow_nat_inv_pow _ two_ne_zero).symm.trans <| pow_two _⟩ with ⟨w, hw⟩ refine ⟨w, ?_, hw⟩ rintro rfl simp only [zero_add, one_ne_zero, mul_zero] at hw refine ⟨log w / I, cos_eq_iff_quadratic.2 ?_⟩ rw [div_mul_cancelβ‚€ _ I_ne_zero, exp_log wβ‚€] convert hw using 1 ring @[simp] theorem range_cos : Set.range cos = Set.univ := cos_surjective.range_eq theorem sin_surjective : Function.Surjective sin := by intro x rcases cos_surjective x with ⟨z, rfl⟩ exact ⟨z + Ο€ / 2, sin_add_pi_div_two z⟩ @[simp] theorem range_sin : Set.range sin = Set.univ := sin_surjective.range_eq end Complex namespace Real open scoped Real theorem cos_eq_zero_iff {ΞΈ : ℝ} : cos ΞΈ = 0 ↔ βˆƒ k : β„€, ΞΈ = (2 * k + 1) * Ο€ / 2 := mod_cast @Complex.cos_eq_zero_iff ΞΈ theorem cos_ne_zero_iff {ΞΈ : ℝ} : cos ΞΈ β‰  0 ↔ βˆ€ k : β„€, ΞΈ β‰  (2 * k + 1) * Ο€ / 2 := mod_cast @Complex.cos_ne_zero_iff ΞΈ theorem cos_eq_cos_iff {x y : ℝ} : cos x = cos y ↔ βˆƒ k : β„€, y = 2 * k * Ο€ + x ∨ y = 2 * k * Ο€ - x := mod_cast @Complex.cos_eq_cos_iff x y theorem sin_eq_sin_iff {x y : ℝ} : sin x = sin y ↔ βˆƒ k : β„€, y = 2 * k * Ο€ + x ∨ y = (2 * k + 1) * Ο€ - x := mod_cast @Complex.sin_eq_sin_iff x y theorem cos_eq_neg_one_iff {x : ℝ} : cos x = -1 ↔ βˆƒ k : β„€, Ο€ + k * (2 * Ο€) = x := mod_cast @Complex.cos_eq_neg_one_iff x theorem sin_eq_one_iff {x : ℝ} : sin x = 1 ↔ βˆƒ k : β„€, Ο€ / 2 + k * (2 * Ο€) = x := mod_cast @Complex.sin_eq_one_iff x theorem sin_eq_neg_one_iff {x : ℝ} : sin x = -1 ↔ βˆƒ k : β„€, -(Ο€ / 2) + k * (2 * Ο€) = x := mod_cast @Complex.sin_eq_neg_one_iff x theorem tan_eq_zero_iff {ΞΈ : ℝ} : tan ΞΈ = 0 ↔ βˆƒ k : β„€, k * Ο€ / 2 = ΞΈ := mod_cast @Complex.tan_eq_zero_iff ΞΈ theorem tan_eq_zero_iff' {ΞΈ : ℝ} (hΞΈ : cos ΞΈ β‰  0) : tan ΞΈ = 0 ↔ βˆƒ k : β„€, k * Ο€ = ΞΈ := by revert hΞΈ exact_mod_cast @Complex.tan_eq_zero_iff' ΞΈ theorem tan_ne_zero_iff {ΞΈ : ℝ} : tan ΞΈ β‰  0 ↔ βˆ€ k : β„€, k * Ο€ / 2 β‰  ΞΈ := mod_cast @Complex.tan_ne_zero_iff ΞΈ /-- `tan x` takes the junk value `0` when `cos x = 0` -/ lemma tan_eq_zero_of_cos_eq_zero {x} (h : cos x = 0) : tan x = 0 := mod_cast @Complex.tan_eq_zero_of_cos_eq_zero x (mod_cast h) -- tangent half-angle substitution formulas theorem cos_eq_two_mul_tan_half_div_one_sub_tan_half_sq (x : ℝ) (h : cos x β‰  -1) : cos x = (1 - tan (x / 2) ^ 2) / (1 + tan (x / 2) ^ 2) := mod_cast @Complex.cos_eq_two_mul_tan_half_div_one_sub_tan_half_sq x (mod_cast h) /-- `tan (x / 2)` takes the junk value `0` when `sin x = 0` so this always holds. -/ theorem sin_eq_two_mul_tan_half_div_one_add_tan_half_sq (x : ℝ) : sin x = (2 * tan (x / 2)) / (1 + tan (x / 2) ^ 2) := mod_cast @Complex.sin_eq_two_mul_tan_half_div_one_add_tan_half_sq x theorem tan_eq_one_sub_tan_half_sq_div_one_add_tan_half_sq (x : ℝ) : tan x = (2 * tan (x / 2)) / (1 - tan (x / 2) ^ 2) := mod_cast @Complex.tan_eq_one_sub_tan_half_sq_div_one_add_tan_half_sq x end Real
.lake/packages/mathlib/Mathlib/Analysis/SpecialFunctions/Trigonometric/ArctanDeriv.lean
import Mathlib.Analysis.SpecialFunctions.Trigonometric.Arctan import Mathlib.Analysis.SpecialFunctions.Trigonometric.ComplexDeriv /-! # Derivatives of the `tan` and `arctan` functions. Continuity and derivatives of the tangent and arctangent functions. -/ noncomputable section namespace Real open Set Filter open scoped Topology Real theorem hasStrictDerivAt_tan {x : ℝ} (h : cos x β‰  0) : HasStrictDerivAt tan (1 / cos x ^ 2) x := mod_cast (Complex.hasStrictDerivAt_tan (by exact mod_cast h)).real_of_complex theorem hasDerivAt_tan {x : ℝ} (h : cos x β‰  0) : HasDerivAt tan (1 / cos x ^ 2) x := mod_cast (Complex.hasDerivAt_tan (by exact mod_cast h)).real_of_complex theorem tendsto_abs_tan_of_cos_eq_zero {x : ℝ} (hx : cos x = 0) : Tendsto (fun x => abs (tan x)) (𝓝[β‰ ] x) atTop := by have hx : Complex.cos x = 0 := mod_cast hx simp only [← Real.norm_eq_abs, ← Complex.norm_real, Complex.ofReal_tan] refine (Complex.tendsto_norm_tan_of_cos_eq_zero hx).comp ?_ refine Tendsto.inf Complex.continuous_ofReal.continuousAt ?_ exact tendsto_principal_principal.2 fun y => mt Complex.ofReal_inj.1 theorem tendsto_abs_tan_atTop (k : β„€) : Tendsto (fun x => abs (tan x)) (𝓝[β‰ ] ((2 * k + 1) * Ο€ / 2)) atTop := tendsto_abs_tan_of_cos_eq_zero <| cos_eq_zero_iff.2 ⟨k, rfl⟩ theorem continuousAt_tan {x : ℝ} : ContinuousAt tan x ↔ cos x β‰  0 := by refine ⟨fun hc hβ‚€ => ?_, fun h => (hasDerivAt_tan h).continuousAt⟩ exact not_tendsto_nhds_of_tendsto_atTop (tendsto_abs_tan_of_cos_eq_zero hβ‚€) _ (hc.norm.tendsto.mono_left inf_le_left) theorem differentiableAt_tan {x : ℝ} : DifferentiableAt ℝ tan x ↔ cos x β‰  0 := ⟨fun h => continuousAt_tan.1 h.continuousAt, fun h => (hasDerivAt_tan h).differentiableAt⟩ @[simp] theorem deriv_tan (x : ℝ) : deriv tan x = 1 / cos x ^ 2 := if h : cos x = 0 then by have : Β¬DifferentiableAt ℝ tan x := mt differentiableAt_tan.1 (Classical.not_not.2 h) simp [deriv_zero_of_not_differentiableAt this, h, sq] else (hasDerivAt_tan h).deriv @[simp] theorem contDiffAt_tan {n : WithTop β„•βˆž} {x : ℝ} : ContDiffAt ℝ n tan x ↔ cos x β‰  0 := ⟨fun h => continuousAt_tan.1 h.continuousAt, fun h => (Complex.contDiffAt_tan.2 <| mod_cast h).real_of_complex⟩ theorem hasDerivAt_tan_of_mem_Ioo {x : ℝ} (h : x ∈ Ioo (-(Ο€ / 2) : ℝ) (Ο€ / 2)) : HasDerivAt tan (1 / cos x ^ 2) x := hasDerivAt_tan (cos_pos_of_mem_Ioo h).ne' theorem differentiableAt_tan_of_mem_Ioo {x : ℝ} (h : x ∈ Ioo (-(Ο€ / 2) : ℝ) (Ο€ / 2)) : DifferentiableAt ℝ tan x := (hasDerivAt_tan_of_mem_Ioo h).differentiableAt theorem hasStrictDerivAt_arctan (x : ℝ) : HasStrictDerivAt arctan (1 / (1 + x ^ 2)) x := by have A : cos (arctan x) β‰  0 := (cos_arctan_pos x).ne' simpa [cos_sq_arctan] using tanPartialHomeomorph.hasStrictDerivAt_symm trivial (by simpa) (hasStrictDerivAt_tan A) theorem hasDerivAt_arctan (x : ℝ) : HasDerivAt arctan (1 / (1 + x ^ 2)) x := (hasStrictDerivAt_arctan x).hasDerivAt theorem hasDerivAt_arctan' (x : ℝ) : HasDerivAt arctan (1 + x ^ 2)⁻¹ x := one_div (1 + x ^ 2) β–Έ hasDerivAt_arctan x theorem differentiableAt_arctan (x : ℝ) : DifferentiableAt ℝ arctan x := (hasDerivAt_arctan x).differentiableAt theorem differentiable_arctan : Differentiable ℝ arctan := differentiableAt_arctan @[simp] theorem deriv_arctan : deriv arctan = fun (x : ℝ) => 1 / (1 + x ^ 2) := funext fun x => (hasDerivAt_arctan x).deriv theorem contDiff_arctan {n : WithTop β„•βˆž} : ContDiff ℝ n arctan := contDiff_iff_contDiffAt.2 fun x => have : cos (arctan x) β‰  0 := (cos_arctan_pos x).ne' tanPartialHomeomorph.contDiffAt_symm_deriv (by simpa) trivial (hasDerivAt_tan this) (contDiffAt_tan.2 this) end Real section /-! ### Lemmas for derivatives of the composition of `Real.arctan` with a differentiable function In this section we register lemmas for the derivatives of the composition of `Real.arctan` with a differentiable function, for standalone use and use with `simp`. -/ open Real section deriv variable {f : ℝ β†’ ℝ} {f' x : ℝ} {s : Set ℝ} theorem HasStrictDerivAt.arctan (hf : HasStrictDerivAt f f' x) : HasStrictDerivAt (fun x => arctan (f x)) (1 / (1 + f x ^ 2) * f') x := (Real.hasStrictDerivAt_arctan (f x)).comp x hf theorem HasDerivAt.arctan (hf : HasDerivAt f f' x) : HasDerivAt (fun x => arctan (f x)) (1 / (1 + f x ^ 2) * f') x := (Real.hasDerivAt_arctan (f x)).comp x hf theorem HasDerivWithinAt.arctan (hf : HasDerivWithinAt f f' s x) : HasDerivWithinAt (fun x => arctan (f x)) (1 / (1 + f x ^ 2) * f') s x := (Real.hasDerivAt_arctan (f x)).comp_hasDerivWithinAt x hf theorem derivWithin_arctan (hf : DifferentiableWithinAt ℝ f s x) (hxs : UniqueDiffWithinAt ℝ s x) : derivWithin (fun x => arctan (f x)) s x = 1 / (1 + f x ^ 2) * derivWithin f s x := hf.hasDerivWithinAt.arctan.derivWithin hxs @[simp] theorem deriv_arctan (hc : DifferentiableAt ℝ f x) : deriv (fun x => arctan (f x)) x = 1 / (1 + f x ^ 2) * deriv f x := hc.hasDerivAt.arctan.deriv end deriv section fderiv variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] {f : E β†’ ℝ} {f' : StrongDual ℝ E} {x : E} {s : Set E} {n : β„•βˆž} theorem HasStrictFDerivAt.arctan (hf : HasStrictFDerivAt f f' x) : HasStrictFDerivAt (fun x => arctan (f x)) ((1 / (1 + f x ^ 2)) β€’ f') x := (hasStrictDerivAt_arctan (f x)).comp_hasStrictFDerivAt x hf theorem HasFDerivAt.arctan (hf : HasFDerivAt f f' x) : HasFDerivAt (fun x => arctan (f x)) ((1 / (1 + f x ^ 2)) β€’ f') x := (hasDerivAt_arctan (f x)).comp_hasFDerivAt x hf theorem HasFDerivWithinAt.arctan (hf : HasFDerivWithinAt f f' s x) : HasFDerivWithinAt (fun x => arctan (f x)) ((1 / (1 + f x ^ 2)) β€’ f') s x := (hasDerivAt_arctan (f x)).comp_hasFDerivWithinAt x hf theorem fderivWithin_arctan (hf : DifferentiableWithinAt ℝ f s x) (hxs : UniqueDiffWithinAt ℝ s x) : fderivWithin ℝ (fun x => arctan (f x)) s x = (1 / (1 + f x ^ 2)) β€’ fderivWithin ℝ f s x := hf.hasFDerivWithinAt.arctan.fderivWithin hxs @[simp] theorem fderiv_arctan (hc : DifferentiableAt ℝ f x) : fderiv ℝ (fun x => arctan (f x)) x = (1 / (1 + f x ^ 2)) β€’ fderiv ℝ f x := hc.hasFDerivAt.arctan.fderiv theorem DifferentiableWithinAt.arctan (hf : DifferentiableWithinAt ℝ f s x) : DifferentiableWithinAt ℝ (fun x => Real.arctan (f x)) s x := hf.hasFDerivWithinAt.arctan.differentiableWithinAt @[simp] theorem DifferentiableAt.arctan (hc : DifferentiableAt ℝ f x) : DifferentiableAt ℝ (fun x => arctan (f x)) x := hc.hasFDerivAt.arctan.differentiableAt theorem DifferentiableOn.arctan (hc : DifferentiableOn ℝ f s) : DifferentiableOn ℝ (fun x => arctan (f x)) s := fun x h => (hc x h).arctan @[simp] theorem Differentiable.arctan (hc : Differentiable ℝ f) : Differentiable ℝ fun x => arctan (f x) := fun x => (hc x).arctan theorem ContDiffAt.arctan (h : ContDiffAt ℝ n f x) : ContDiffAt ℝ n (fun x => arctan (f x)) x := contDiff_arctan.contDiffAt.comp x h theorem ContDiff.arctan (h : ContDiff ℝ n f) : ContDiff ℝ n fun x => arctan (f x) := contDiff_arctan.comp h theorem ContDiffWithinAt.arctan (h : ContDiffWithinAt ℝ n f s x) : ContDiffWithinAt ℝ n (fun x => arctan (f x)) s x := contDiff_arctan.comp_contDiffWithinAt h theorem ContDiffOn.arctan (h : ContDiffOn ℝ n f s) : ContDiffOn ℝ n (fun x => arctan (f x)) s := contDiff_arctan.comp_contDiffOn h end fderiv end
.lake/packages/mathlib/Mathlib/Analysis/SpecialFunctions/Trigonometric/Cotangent.lean
import Mathlib.Analysis.Calculus.IteratedDeriv.WithinZpow import Mathlib.Analysis.Complex.UpperHalfPlane.Exp import Mathlib.Analysis.Complex.IntegerCompl import Mathlib.Analysis.Complex.LocallyUniformLimit import Mathlib.Analysis.PSeries import Mathlib.Analysis.SpecialFunctions.Trigonometric.EulerSineProd import Mathlib.Analysis.NormedSpace.MultipliableUniformlyOn import Mathlib.NumberTheory.ModularForms.EisensteinSeries.Summable import Mathlib.Topology.Algebra.InfiniteSum.TsumUniformlyOn /-! # Cotangent This file contains lemmas about the cotangent function, including useful series expansions. In particular, we prove that `Ο€ * cot (Ο€ * z) = Ο€ * I - 2 * Ο€ * I * βˆ‘' n : β„•, Complex.exp (2 * Ο€ * I * z) ^ n` as well as the infinite sum representation of cotangent (also known as the Mittag-Leffler expansion): `Ο€ * cot (Ο€ * z) = 1 / z + βˆ‘' n : β„•+, (1 / (z - n) + 1 / (z + n))`. -/ open Real Complex open scoped UpperHalfPlane local notation "β„‚_β„€" => integerComplement local notation "ℍₒ" => UpperHalfPlane.upperHalfPlaneSet lemma Complex.cot_eq_exp_ratio (z : β„‚) : cot z = (Complex.exp (2 * I * z) + 1) / (I * (1 - Complex.exp (2 * I * z))) := by rw [Complex.cot, Complex.sin, Complex.cos] have h1 : exp (z * I) + exp (-z * I) = exp (-(z * I)) * (exp (2 * I * z) + 1) := by rw [mul_add, ← Complex.exp_add] ring_nf have h2 : (exp (-z * I) - exp (z * I)) = exp (-(z * I)) * ((1 - exp (2 * I * z))) := by ring_nf rw [mul_assoc, ← Complex.exp_add] ring_nf rw [h1, h2] field /- The version one probably wants to use more. -/ lemma Complex.cot_pi_eq_exp_ratio (z : β„‚) : cot (Ο€ * z) = (Complex.exp (2 * Ο€ * I * z) + 1) / (I * (1 - Complex.exp (2 * Ο€ * I * z))) := by rw [cot_eq_exp_ratio (Ο€ * z)] ring_nf /- This is the version one probably wants, which is why the pi's are there. -/ theorem pi_mul_cot_pi_q_exp (z : ℍ) : Ο€ * cot (Ο€ * z) = Ο€ * I - 2 * Ο€ * I * βˆ‘' n : β„•, Complex.exp (2 * Ο€ * I * z) ^ n := by have h1 : Ο€ * ((exp (2 * Ο€ * I * z) + 1) / (I * (1 - exp (2 * Ο€ * I * z)))) = -Ο€ * I * ((exp (2 * Ο€ * I * z) + 1) * (1 / (1 - exp (2 * Ο€ * I * z)))) := by simp only [div_mul_eq_div_mul_one_div, div_I, one_div, neg_mul, mul_neg, neg_inj] ring rw [cot_pi_eq_exp_ratio, h1, one_div, (tsum_geometric_of_norm_lt_one (UpperHalfPlane.norm_exp_two_pi_I_lt_one z)).symm, add_comm, geom_series_mul_one_add (Complex.exp (2 * Ο€ * I * (z : β„‚))) (UpperHalfPlane.norm_exp_two_pi_I_lt_one _)] ring section MittagLeffler open Filter Function open scoped Topology BigOperators Nat Complex variable {x : β„‚} {Z : Set β„‚} /-- The main term in the infinite product for sine. -/ noncomputable abbrev sineTerm (x : β„‚) (n : β„•) : β„‚ := -x ^ 2 / (n + 1) ^ 2 lemma sineTerm_ne_zero {x : β„‚} (hx : x ∈ β„‚_β„€) (n : β„•) : 1 + sineTerm x n β‰  0 := by simp only [sineTerm, ne_eq] rw [add_eq_zero_iff_eq_neg, neg_div', eq_div_iff] Β· have := (integerComplement_pow_two_ne_pow_two hx (n + 1 : β„€)) aesop Β· simp [Nat.cast_add_one_ne_zero n] lemma tendsto_euler_sin_prod' (h0 : x β‰  0) : Tendsto (fun n : β„• ↦ ∏ i ∈ Finset.range n, (1 + sineTerm x i)) atTop (𝓝 (sin (Ο€ * x) / (Ο€ * x))) := by rw [show (sin (Ο€ * x) / (Ο€ * x)) = sin (Ο€ * x) * (1 / (Ο€ * x)) by ring] apply (Filter.Tendsto.mul_const (b := 1 / (Ο€ * x)) (tendsto_euler_sin_prod x)).congr exact fun n ↦ by field_simp; rfl lemma multipliable_sineTerm (x : β„‚) : Multipliable fun i ↦ (1 + sineTerm x i) := by apply multipliable_one_add_of_summable have := summable_pow_div_add (x ^ 2) 2 1 Nat.one_lt_two simpa [sineTerm] using this lemma euler_sineTerm_tprod (hx : x ∈ β„‚_β„€) : ∏' i : β„•, (1 + sineTerm x i) = Complex.sin (Ο€ * x) / (Ο€ * x) := by rw [← Multipliable.hasProd_iff (multipliable_sineTerm x), Multipliable.hasProd_iff_tendsto_nat (multipliable_sineTerm x)] exact tendsto_euler_sin_prod' (integerComplement.ne_zero hx) private lemma sineTerm_bound_aux (hZ : IsCompact Z) : βˆƒ u : β„• β†’ ℝ, Summable u ∧ βˆ€ j z, z ∈ Z β†’ β€–sineTerm z jβ€– ≀ u j := by have hf : ContinuousOn (fun x : β„‚ => β€–-x ^ 2β€–) Z := by fun_prop obtain ⟨s, hs⟩ := bddAbove_def.mp (IsCompact.bddAbove_image hZ hf) refine ⟨fun n : β„• => β€–(s : β„‚) / (n + 1) ^ 2β€–, ?_, ?_⟩ Β· simpa using summable_pow_div_add (s : β„‚) 2 1 (Nat.one_lt_two) Β· simp only [norm_neg, norm_pow, Set.mem_image, forall_exists_index, and_imp, forall_apply_eq_imp_iffβ‚‚, sineTerm, norm_div, norm_real, norm_eq_abs] at * intro n x hx gcongr apply le_trans (hs x hx) (le_abs_self s) lemma multipliableUniformlyOn_euler_sin_prod_on_compact (hZC : IsCompact Z) : MultipliableUniformlyOn (fun n : β„• => fun z : β„‚ => (1 + sineTerm z n)) {Z} := by obtain ⟨u, hu, hu2⟩ := sineTerm_bound_aux hZC refine Summable.multipliableUniformlyOn_nat_one_add hZC hu ?_ ?_ Β· filter_upwards with n z hz using hu2 n z hz Β· fun_prop lemma HasProdUniformlyOn_sineTerm_prod_on_compact (hZ2 : Z βŠ† β„‚_β„€) (hZC : IsCompact Z) : HasProdUniformlyOn (fun n : β„• => fun z : β„‚ => (1 + sineTerm z n)) (fun x => (Complex.sin (↑π * x) / (↑π * x))) {Z} := by apply (multipliableUniformlyOn_euler_sin_prod_on_compact hZC).hasProdUniformlyOn.congr_right exact fun s hs x hx => euler_sineTerm_tprod (by aesop) lemma HasProdLocallyUniformlyOn_euler_sin_prod : HasProdLocallyUniformlyOn (fun n : β„• => fun z : β„‚ => (1 + sineTerm z n)) (fun x => (Complex.sin (Ο€ * x) / (Ο€ * x))) β„‚_β„€ := by apply hasProdLocallyUniformlyOn_of_forall_compact isOpen_compl_range_intCast exact fun _ hZ hZC => HasProdUniformlyOn_sineTerm_prod_on_compact hZ hZC /-- `sin Ο€ z` is non vanishing on the complement of the integers in `β„‚`. -/ theorem sin_pi_mul_ne_zero (hx : x ∈ β„‚_β„€) : Complex.sin (Ο€ * x) β‰  0 := by apply Complex.sin_ne_zero_iff.2 intro k nth_rw 2 [mul_comm] exact Injective.ne (mul_right_injectiveβ‚€ (ofReal_ne_zero.mpr Real.pi_ne_zero)) (by aesop) lemma cot_pi_mul_contDiffWithinAt (k : β„•βˆž) (hx : x ∈ β„‚_β„€) : ContDiffWithinAt β„‚ k (fun x ↦ (↑π * x).cot) ℍₒ x := by simp_rw [Complex.cot, Complex.cos, Complex.sin] exact ContDiffWithinAt.div (by fun_prop) (by fun_prop) (sin_pi_mul_ne_zero hx) lemma tendsto_logDeriv_euler_sin_div (hx : x ∈ β„‚_β„€) : Tendsto (fun n : β„• ↦ logDeriv (fun z ↦ ∏ j ∈ Finset.range n, (1 + sineTerm z j)) x) atTop (𝓝 <| logDeriv (fun t ↦ (Complex.sin (Ο€ * t) / (Ο€ * t))) x) := by refine logDeriv_tendsto (isOpen_compl_range_intCast) ⟨x, hx⟩ HasProdLocallyUniformlyOn_euler_sin_prod.tendstoLocallyUniformlyOn_finsetRange ?_ ?_ Β· filter_upwards with n using by fun_prop Β· simp only [ne_eq, div_eq_zero_iff, mul_eq_zero, ofReal_eq_zero, not_or] exact ⟨sin_pi_mul_ne_zero hx, Real.pi_ne_zero, integerComplement.ne_zero hx⟩ lemma logDeriv_sin_div_eq_cot (hz : x ∈ β„‚_β„€) : logDeriv (fun t ↦ (Complex.sin (Ο€ * t) / (Ο€ * t))) x = Ο€ * cot (Ο€ * x) - 1 / x := by have : (fun t ↦ (Complex.sin (Ο€ * t)/ (Ο€ * t))) = fun z ↦ (Complex.sin ∘ fun t ↦ Ο€ * t) z / (Ο€ * z) := by simp rw [this, logDeriv_div _ (by apply sin_pi_mul_ne_zero hz) ?_ (DifferentiableAt.comp _ (Complex.differentiableAt_sin) (by fun_prop)) (by fun_prop), logDeriv_comp (Complex.differentiableAt_sin) (by fun_prop), Complex.logDeriv_sin, deriv_const_mul _ (by fun_prop), deriv_id'', logDeriv_const_mul, logDeriv_id'] Β· ring Β· simp Β· simp only [ne_eq, mul_eq_zero, ofReal_eq_zero, not_or] exact ⟨Real.pi_ne_zero, integerComplement.ne_zero hz⟩ /-- The term in the infinite sum expansion of cot. -/ noncomputable abbrev cotTerm (x : β„‚) (n : β„•) : β„‚ := 1 / (x - (n + 1)) + 1 / (x + (n + 1)) lemma logDeriv_sineTerm_eq_cotTerm (hx : x ∈ β„‚_β„€) (i : β„•) : logDeriv (fun (z : β„‚) ↦ 1 + sineTerm z i) x = cotTerm x i := by have h1 := integerComplement_add_ne_zero hx (i + 1) have h2 : ((x : β„‚) - (i + 1)) β‰  0 := by simpa [sub_eq_add_neg] using integerComplement_add_ne_zero hx (-(i + 1)) have h3 : (i+1)^2 + -x^2 β‰  0 := by have := (integerComplement_pow_two_ne_pow_two hx ((i + 1) : β„€)) rw [← sub_eq_add_neg, sub_ne_zero] aesop simp only [Int.cast_add, Int.cast_natCast, Int.cast_one, ne_eq, sineTerm, logDeriv_apply, deriv_const_add', deriv_div_const, deriv.fun_neg', differentiableAt_fun_id, deriv_fun_pow, Nat.cast_ofNat, deriv_id'', cotTerm] at * field lemma logDeriv_prod_sineTerm_eq_sum_cotTerm (hx : x ∈ β„‚_β„€) (n : β„•) : logDeriv (fun (z : β„‚) ↦ ∏ j ∈ Finset.range n, (1 + sineTerm z j)) x = βˆ‘ j ∈ Finset.range n, cotTerm x j := by rw [logDeriv_prod] Β· simp_rw [logDeriv_sineTerm_eq_cotTerm hx] Β· exact fun i _ ↦ sineTerm_ne_zero hx i Β· fun_prop lemma tendsto_logDeriv_euler_cot_sub (hx : x ∈ β„‚_β„€) : Tendsto (fun n : β„• => βˆ‘ j ∈ Finset.range n, cotTerm x j) atTop (𝓝 <| Ο€ * cot (Ο€ * x)- 1 / x) := by simp_rw [← logDeriv_sin_div_eq_cot hx, ← logDeriv_prod_sineTerm_eq_sum_cotTerm hx] simpa using tendsto_logDeriv_euler_sin_div hx lemma cotTerm_identity (hz : x ∈ β„‚_β„€) (n : β„•) : cotTerm x n = 2 * x * (1 / ((x + (n + 1)) * (x - (n + 1)))) := by simp only [cotTerm] rw [one_div_add_one_div] Β· ring Β· simpa [sub_eq_add_neg] using integerComplement_add_ne_zero hz (-(n + 1) : β„€) Β· simpa using (integerComplement_add_ne_zero hz ((n : β„€) + 1)) lemma Summable_cotTerm (hz : x ∈ β„‚_β„€) : Summable fun n ↦ cotTerm x n := by rw [funext fun n ↦ cotTerm_identity hz n] apply Summable.mul_left suffices Summable fun i : β„• ↦ (x - (↑i : β„‚))⁻¹ * (x + (↑i : β„‚))⁻¹ by rw [← summable_nat_add_iff 1] at this simpa using this suffices Summable fun i : β„€ ↦ (x - (↑i : β„‚))⁻¹ * (x + (↑i : β„‚))⁻¹ by apply this.comp_injective CharZero.cast_injective apply (EisensteinSeries.summable_linear_sub_mul_linear_add x 1 1).congr simp [mul_comm] lemma cot_series_rep' (hz : x ∈ β„‚_β„€) : Ο€ * cot (Ο€ * x) - 1 / x = βˆ‘' n : β„•, (1 / (x - (n + 1)) + 1 / (x + (n + 1))) := by rw [HasSum.tsum_eq] apply (Summable.hasSum_iff_tendsto_nat (Summable_cotTerm hz)).mpr (tendsto_logDeriv_euler_cot_sub hz) /-- The cotangent infinite sum representation. -/ theorem cot_series_rep (hz : x ∈ β„‚_β„€) : Ο€ * cot (Ο€ * x) = 1 / x + βˆ‘' n : β„•+, (1 / (x - n) + 1 / (x + n)) := by have h0 := tsum_pnat_eq_tsum_succ (f := fun n ↦ 1 / (x - n) + 1 / (x + n)) have h1 := cot_series_rep' hz simp only [one_div, Nat.cast_add, Nat.cast_one] at * rw [h0, ← h1] ring end MittagLeffler section iteratedDeriv open Set UpperHalfPlane open scoped Nat variable (k : β„•) private lemma contDiffOn_inv_linear (d : β„€) : ContDiffOn β„‚ k (fun z : β„‚ ↦ 1 / (z + d)) β„‚_β„€ := by simpa using ContDiffOn.inv (by fun_prop) (fun x hx ↦ integerComplement_add_ne_zero hx d) lemma eqOn_iteratedDeriv_cotTerm (d : β„•) : EqOn (iteratedDeriv k (fun z ↦ cotTerm z d)) (fun z ↦ (-1)^ k * k ! * ((z + (d + 1))^ (-1 - k : β„€) + (z - (d + 1)) ^ (-1 - k : β„€))) β„‚_β„€ := by intro z hz rw [← Pi.add_def, iteratedDeriv_add] Β· have h2 := iter_deriv_inv_linear_sub k 1 ((d + 1 : β„‚)) have h3 := iter_deriv_inv_linear k 1 (d + 1 : β„‚) simp only [one_div, one_mul, one_pow, mul_one, Int.reduceNeg, iteratedDeriv_eq_iterate] at * rw [h2, h3] ring Β· simpa [sub_eq_add_neg] using (contDiffOn_inv_linear k (-(d + 1))).contDiffAt ((isOpen_compl_range_intCast).mem_nhds hz) Β· simpa using (contDiffOn_inv_linear k (d + 1)).contDiffAt ((isOpen_compl_range_intCast).mem_nhds hz) lemma eqOn_iteratedDerivWithin_cotTerm_integerComplement (d : β„•) : EqOn (iteratedDerivWithin k (fun z ↦ cotTerm z d) β„‚_β„€) (fun z ↦ (-1) ^ k * k ! * ((z + (d + 1)) ^ (-1 - k : β„€) + (z - (d + 1)) ^ (-1 - k : β„€))) β„‚_β„€ := by apply Set.EqOn.trans (iteratedDerivWithin_of_isOpen isOpen_compl_range_intCast) exact eqOn_iteratedDeriv_cotTerm .. lemma eqOn_iteratedDerivWithin_cotTerm_upperHalfPlaneSet (d : β„•) : EqOn (iteratedDerivWithin k (fun z ↦ cotTerm z d) ℍₒ) (fun z ↦ (-1) ^ k * k ! * ((z + (d + 1)) ^ (-1 - k : β„€) + (z - (d + 1)) ^ (-1 - k : β„€))) ℍₒ := by apply Set.EqOn.trans (upperHalfPlane_inter_integerComplement β–Έ iteratedDerivWithin_congr_right_of_isOpen (fun z ↦ cotTerm z d) k isOpen_upperHalfPlaneSet (isOpen_compl_range_intCast)) intro z hz simpa using eqOn_iteratedDerivWithin_cotTerm_integerComplement k d (coe_mem_integerComplement ⟨z, hz⟩) open EisensteinSeries in private noncomputable abbrev cotTermUpperBound (A B : ℝ) (hB : 0 < B) (a : β„•) := k ! * (2 * (r (⟨⟨A, B⟩, by simp [hB]⟩) ^ (-1 - k : β„€)) * β€–((a + 1) ^ (-1 - k : β„€) : ℝ)β€–) private lemma summable_cotTermUpperBound (A B : ℝ) (hB : 0 < B) {k : β„•} (hk : 1 ≀ k) : Summable fun a : β„• ↦ cotTermUpperBound k A B hB a := by simp_rw [← mul_assoc] apply Summable.mul_left conv => enter [1, n]; rw [show (-1 - k : β„€) = -(1 + k :) by cutsat, zpow_neg, zpow_natCast]; enter [1, 1, 1]; norm_cast rw [summable_norm_iff, summable_nat_add_iff (f := fun n : β„• ↦ ((n : ℝ) ^ (1 + k))⁻¹)] exact summable_nat_pow_inv.mpr <| by cutsat open EisensteinSeries in private lemma iteratedDerivWithin_cotTerm_bounded_uniformly {k : β„•} {K : Set β„‚} (hK : K βŠ† ℍₒ) (A B : ℝ) (hB : 0 < B) (HABK : inclusion hK '' univ βŠ† verticalStrip A B) (n : β„•) {a : β„‚} (ha : a ∈ K) : β€–iteratedDerivWithin k (fun z ↦ cotTerm z n) ℍₒ aβ€– ≀ cotTermUpperBound k A B hB n := by simp only [eqOn_iteratedDerivWithin_cotTerm_upperHalfPlaneSet k n (hK ha), Complex.norm_mul, norm_pow, norm_neg,norm_one, one_pow, Complex.norm_natCast, one_mul, cotTermUpperBound, Int.reduceNeg, norm_zpow, Real.norm_eq_abs, two_mul, add_mul] gcongr have h1 := summand_bound_of_mem_verticalStrip (k := k + 1) (by norm_cast; cutsat) ![1, n + 1] hB (z := ⟨a, (hK ha)⟩) (A := A) (by aesop) have h2 := abs_norm_eq_max_natAbs_neg n β–Έ (summand_bound_of_mem_verticalStrip (k := k + 1) (by norm_cast; cutsat) ![1, -(n + 1)] hB (z := ⟨a, (hK ha)⟩) (A := A) (by aesop)) simp only [Fin.isValue, Matrix.cons_val_zero, Int.cast_one, coe_mk_subtype, one_mul, Matrix.cons_val_one, Matrix.cons_val_fin_one, Int.cast_add, Int.cast_natCast, neg_add_rev, abs_norm_eq_max_natAbs, Int.reduceNeg, Int.cast_neg, sub_eq_add_neg, ge_iff_le] at h1 h2 ⊒ refine le_trans (norm_add_le _ _) (add_le_add ?_ ?_) <;> {simp only [Int.reduceNeg, norm_zpow]; norm_cast at h1 h2 ⊒} lemma summableLocallyUniformlyOn_iteratedDerivWithin_cotTerm {k : β„•} (hk : 1 ≀ k) : SummableLocallyUniformlyOn (fun n ↦ iteratedDerivWithin k (fun z ↦ cotTerm z n) ℍₒ) ℍₒ := by apply SummableLocallyUniformlyOn_of_locally_bounded isOpen_upperHalfPlaneSet intro K hK hKc obtain ⟨A, B, hB, HABK⟩ := subset_verticalStrip_of_isCompact ((isCompact_iff_isCompact_univ.mp hKc).image_of_continuousOn (continuous_inclusion hK |>.continuousOn)) exact ⟨cotTermUpperBound k A B hB, summable_cotTermUpperBound A B hB hk, iteratedDerivWithin_cotTerm_bounded_uniformly hK A B hB HABK⟩ lemma differentiableOn_iteratedDerivWithin_cotTerm (n l : β„•) : DifferentiableOn β„‚ (iteratedDerivWithin l (fun z ↦ cotTerm z n) ℍₒ) ℍₒ := by suffices DifferentiableOn β„‚ (fun z : β„‚ ↦ (-1) ^ l * l ! * ((z + (n + 1)) ^ (-1 - l : β„€) + (z - (n + 1)) ^ (-1 - l : β„€))) ℍₒ by exact this.congr fun z hz ↦ eqOn_iteratedDerivWithin_cotTerm_upperHalfPlaneSet l n hz apply DifferentiableOn.const_mul apply DifferentiableOn.add <;> refine DifferentiableOn.zpow (by fun_prop) <| .inl fun x hx ↦ ?_ Β· simpa [add_eq_zero_iff_neg_eq'] using (UpperHalfPlane.ne_int ⟨x, hx⟩ (-(n + 1))).symm Β· simpa [sub_eq_zero] using (UpperHalfPlane.ne_int ⟨x, hx⟩ (n + 1)) private lemma aux_summable_add {k : β„•} (hk : 1 ≀ k) (x : β„‚) : Summable fun (n : β„•) ↦ (x + (n + 1)) ^ (-1 - k : β„€) := by apply ((summable_nat_add_iff 1).mpr (summable_int_iff_summable_nat_and_neg.mp (EisensteinSeries.linear_right_summable x 1 (k := k + 1) (by cutsat))).1).congr simp [← zpow_neg, sub_eq_add_neg] private lemma aux_summable_sub {k : β„•} (hk : 1 ≀ k) (x : β„‚) : Summable fun (n : β„•) ↦ (x - (n + 1)) ^ (-1 - k : β„€) := by apply ((summable_nat_add_iff 1).mpr (summable_int_iff_summable_nat_and_neg.mp (EisensteinSeries.linear_right_summable x 1 (k := k + 1) (by cutsat))).2).congr simp [← zpow_neg, sub_eq_add_neg] variable {z : β„‚} -- We have this auxiliary ugly version on the lhs so the rhs looks nicer. private lemma aux_iteratedDeriv_tsum_cotTerm {k : β„•} (hk : 1 ≀ k) (hz : z ∈ ℍₒ) : (-1) ^ k * (k !) * z ^ (-1 - k : β„€) + iteratedDerivWithin k (fun z ↦ βˆ‘' n : β„•, cotTerm z n) ℍₒ z = (-1) ^ k * k ! * βˆ‘' n : β„€, (z + n) ^ (-1 - k : β„€) := by rw [iteratedDerivWithin_tsum k isOpen_upperHalfPlaneSet hz (fun t ht ↦ Summable_cotTerm (coe_mem_integerComplement ⟨t, ht⟩)) (fun l hl hl2 ↦ summableLocallyUniformlyOn_iteratedDerivWithin_cotTerm hl) (fun n l z hl hz ↦ (differentiableOn_iteratedDerivWithin_cotTerm n l).differentiableAt (isOpen_upperHalfPlaneSet.mem_nhds hz))] conv => enter [1, 2, 1, n] rw [eqOn_iteratedDerivWithin_cotTerm_upperHalfPlaneSet k n (by simp [hz])] rw [tsum_of_add_one_of_neg_add_one (by simpa using aux_summable_add hk z) (by simpa [sub_eq_add_neg] using aux_summable_sub hk z), tsum_mul_left, Summable.tsum_add (aux_summable_add hk z) (aux_summable_sub hk z)] push_cast ring_nf lemma iteratedDerivWithin_cot_sub_inv_eq_add_mul_tsum {k : β„•} (hk : 1 ≀ k) (hz : z ∈ ℍₒ) : iteratedDerivWithin k (fun x : β„‚ ↦ Ο€ * cot (Ο€ * x) - 1 / x) ℍₒ z = -(-1) ^ k * k ! * (z ^ (-1 - k : β„€)) + (-1) ^ k * k ! * βˆ‘' n : β„€, (z + n) ^ (-1 - k : β„€) := by simp only [← aux_iteratedDeriv_tsum_cotTerm hk hz, one_div, neg_mul, neg_add_cancel_left] refine iteratedDerivWithin_congr (fun z hz ↦ ?_) hz simpa [cotTerm] using (cot_series_rep' (UpperHalfPlane.coe_mem_integerComplement ⟨z, hz⟩)) private lemma iteratedDerivWithin_cot_pi_mul_sub_inv {z : β„‚} (hz : z ∈ ℍₒ) : iteratedDerivWithin k (fun x : β„‚ ↦ Ο€ * cot (Ο€ * x) - 1 / x) ℍₒ z = (iteratedDerivWithin k (fun x : β„‚ ↦ Ο€ * cot (Ο€ * x)) ℍₒ z) - (-1) ^ k * k ! * (z ^ (-1 - k : β„€)) := by simp_rw [sub_eq_add_neg] rw [iteratedDerivWithin_fun_add hz isOpen_upperHalfPlaneSet.uniqueDiffOn] Β· simpa [iteratedDerivWithin_fun_neg] using iteratedDerivWithin_one_div k isOpen_upperHalfPlaneSet hz Β· exact ContDiffWithinAt.smul (by fun_prop) (cot_pi_mul_contDiffWithinAt k (UpperHalfPlane.coe_mem_integerComplement ⟨z, hz⟩)) Β· simp only [one_div] apply ContDiffWithinAt.neg exact ContDiffWithinAt.inv (by fun_prop) (ne_zero ⟨z, hz⟩) lemma iteratedDerivWithin_cot_pi_mul_eq_mul_tsum_zpow {k : β„•} (hk : 1 ≀ k) {z : β„‚} (hz : z ∈ ℍₒ) : iteratedDerivWithin k (fun x : β„‚ ↦ Ο€ * cot (Ο€ * x)) ℍₒ z = (-1) ^ k * k ! * βˆ‘' n : β„€, (z + n) ^ (-1 - k : β„€):= by have h0 := iteratedDerivWithin_cot_pi_mul_sub_inv k hz rw [iteratedDerivWithin_cot_sub_inv_eq_add_mul_tsum hk hz, add_comm] at h0 rw [← add_left_inj (-(-1) ^ k * k ! * z ^ (-1 - k : β„€)), h0] ring /-- The series expansion of the iterated derivative of `Ο€ cot (Ο€ z)`. -/ theorem iteratedDerivWithin_cot_pi_mul_eq_mul_tsum_div_pow {k : β„•} (hk : 1 ≀ k) {z : β„‚} (hz : z ∈ ℍₒ) : iteratedDerivWithin k (fun x : β„‚ ↦ Ο€ * cot (Ο€ * x)) ℍₒ z = (-1) ^ k * k ! * βˆ‘' n : β„€, 1 / (z + n) ^ (k + 1) := by convert iteratedDerivWithin_cot_pi_mul_eq_mul_tsum_zpow hk hz with n rw [show (-1 - k : β„€) = -(k + 1 :) by norm_cast; cutsat, zpow_neg_coe_of_pos _ (by cutsat), one_div] end iteratedDeriv
.lake/packages/mathlib/Mathlib/Analysis/SpecialFunctions/Trigonometric/ComplexDeriv.lean
import Mathlib.Analysis.SpecialFunctions.Trigonometric.Complex import Mathlib.Analysis.SpecialFunctions.Trigonometric.Deriv /-! # Complex trigonometric functions Basic facts and derivatives for the complex trigonometric functions. -/ noncomputable section namespace Complex open Set Filter open scoped Real theorem hasStrictDerivAt_tan {x : β„‚} (h : cos x β‰  0) : HasStrictDerivAt tan (1 / cos x ^ 2) x := by convert (hasStrictDerivAt_sin x).div (hasStrictDerivAt_cos x) h using 1 rw_mod_cast [← sin_sq_add_cos_sq x] ring theorem hasDerivAt_tan {x : β„‚} (h : cos x β‰  0) : HasDerivAt tan (1 / cos x ^ 2) x := (hasStrictDerivAt_tan h).hasDerivAt open scoped Topology theorem tendsto_norm_tan_of_cos_eq_zero {x : β„‚} (hx : cos x = 0) : Tendsto (fun x => β€–tan xβ€–) (𝓝[β‰ ] x) atTop := by simp only [tan_eq_sin_div_cos, norm_div] have A : sin x β‰  0 := fun h => by simpa [*, sq] using sin_sq_add_cos_sq x have B : Tendsto cos (𝓝[β‰ ] x) (𝓝[β‰ ] 0) := hx β–Έ (hasDerivAt_cos x).tendsto_nhdsNE (neg_ne_zero.2 A) exact continuous_sin.continuousWithinAt.norm.pos_mul_atTop (norm_pos_iff.2 A) (tendsto_norm_nhdsNE_zero.comp B).inv_tendsto_nhdsGT_zero theorem tendsto_norm_tan_atTop (k : β„€) : Tendsto (fun x => β€–tan xβ€–) (𝓝[β‰ ] ((2 * k + 1) * Ο€ / 2 : β„‚)) atTop := tendsto_norm_tan_of_cos_eq_zero <| cos_eq_zero_iff.2 ⟨k, rfl⟩ @[simp] theorem continuousAt_tan {x : β„‚} : ContinuousAt tan x ↔ cos x β‰  0 := by refine ⟨fun hc hβ‚€ => ?_, fun h => (hasDerivAt_tan h).continuousAt⟩ exact not_tendsto_nhds_of_tendsto_atTop (tendsto_norm_tan_of_cos_eq_zero hβ‚€) _ (hc.norm.tendsto.mono_left inf_le_left) @[simp] theorem differentiableAt_tan {x : β„‚} : DifferentiableAt β„‚ tan x ↔ cos x β‰  0 := ⟨fun h => continuousAt_tan.1 h.continuousAt, fun h => (hasDerivAt_tan h).differentiableAt⟩ @[simp] theorem deriv_tan (x : β„‚) : deriv tan x = 1 / cos x ^ 2 := if h : cos x = 0 then by have : Β¬DifferentiableAt β„‚ tan x := mt differentiableAt_tan.1 (Classical.not_not.2 h) simp [deriv_zero_of_not_differentiableAt this, h, sq] else (hasDerivAt_tan h).deriv @[simp] theorem contDiffAt_tan {x : β„‚} {n : WithTop β„•βˆž} : ContDiffAt β„‚ n tan x ↔ cos x β‰  0 := ⟨fun h => continuousAt_tan.1 h.continuousAt, contDiff_sin.contDiffAt.div contDiff_cos.contDiffAt⟩ end Complex
.lake/packages/mathlib/Mathlib/Analysis/SpecialFunctions/Trigonometric/Chebyshev.lean
import Mathlib.Analysis.Complex.Trigonometric import Mathlib.LinearAlgebra.Complex.Module import Mathlib.RingTheory.Polynomial.Chebyshev /-! # Multiple angle formulas in terms of Chebyshev polynomials This file gives the trigonometric characterizations of Chebyshev polynomials, for the real (`Real.cos`) and complex (`Complex.cos`) cosine and the real (`Real.cosh`) and complex (`Complex.cosh`) hyperbolic cosine. -/ namespace Polynomial.Chebyshev open Polynomial variable {R A : Type*} [CommRing R] [CommRing A] [Algebra R A] @[simp, norm_cast] theorem complex_ofReal_eval_T : βˆ€ (x : ℝ) n, (((T ℝ n).eval x : ℝ) : β„‚) = (T β„‚ n).eval (x : β„‚) := @algebraMap_eval_T ℝ β„‚ _ _ _ @[simp, norm_cast] theorem complex_ofReal_eval_U : βˆ€ (x : ℝ) n, (((U ℝ n).eval x : ℝ) : β„‚) = (U β„‚ n).eval (x : β„‚) := @algebraMap_eval_U ℝ β„‚ _ _ _ @[simp, norm_cast] theorem complex_ofReal_eval_C : βˆ€ (x : ℝ) n, (((C ℝ n).eval x : ℝ) : β„‚) = (C β„‚ n).eval (x : β„‚) := @algebraMap_eval_C ℝ β„‚ _ _ _ @[simp, norm_cast] theorem complex_ofReal_eval_S : βˆ€ (x : ℝ) n, (((S ℝ n).eval x : ℝ) : β„‚) = (S β„‚ n).eval (x : β„‚) := @algebraMap_eval_S ℝ β„‚ _ _ _ /-! ### Complex versions -/ section Complex open Complex variable (ΞΈ : β„‚) /-- The `n`-th Chebyshev polynomial of the first kind evaluates on `cos ΞΈ` to the value `cos (n * ΞΈ)`. -/ @[simp] theorem T_complex_cos (n : β„€) : (T β„‚ n).eval (cos ΞΈ) = cos (n * ΞΈ) := by induction n using Polynomial.Chebyshev.induct with | zero => simp | one => simp | add_two n ih1 ih2 => simp only [T_add_two, eval_sub, eval_mul, eval_X, eval_ofNat, ih1, ih2, sub_eq_iff_eq_add, cos_add_cos] push_cast ring_nf | neg_add_one n ih1 ih2 => simp only [T_sub_one, eval_sub, eval_mul, eval_X, eval_ofNat, ih1, ih2, sub_eq_iff_eq_add', cos_add_cos] push_cast ring_nf /-- The `n`-th Chebyshev polynomial of the second kind evaluates on `cos ΞΈ` to the value `sin ((n + 1) * ΞΈ) / sin ΞΈ`. -/ @[simp] theorem U_complex_cos (n : β„€) : (U β„‚ n).eval (cos ΞΈ) * sin ΞΈ = sin ((n + 1) * ΞΈ) := by induction n using Polynomial.Chebyshev.induct with | zero => simp | one => simp [one_add_one_eq_two, sin_two_mul]; ring | add_two n ih1 ih2 => simp only [U_add_two, eval_sub, eval_mul, eval_X, eval_ofNat, sub_mul, mul_assoc, ih1, ih2, sub_eq_iff_eq_add, sin_add_sin] push_cast ring_nf | neg_add_one n ih1 ih2 => simp only [U_sub_one, eval_sub, eval_mul, eval_X, eval_ofNat, sub_mul, mul_assoc, ih1, ih2, sub_eq_iff_eq_add', sin_add_sin] push_cast ring_nf /-- The `n`-th rescaled Chebyshev polynomial of the first kind (Vieta–Lucas polynomial) evaluates on `2 * cos ΞΈ` to the value `2 * cos (n * ΞΈ)`. -/ @[simp] theorem C_two_mul_complex_cos (n : β„€) : (C β„‚ n).eval (2 * cos ΞΈ) = 2 * cos (n * ΞΈ) := by simp [C_eq_two_mul_T_comp_half_mul_X] /-- The `n`-th rescaled Chebyshev polynomial of the second kind (Vieta–Fibonacci polynomial) evaluates on `2 * cos ΞΈ` to the value `sin ((n + 1) * ΞΈ) / sin ΞΈ`. -/ @[simp] theorem S_two_mul_complex_cos (n : β„€) : (S β„‚ n).eval (2 * cos ΞΈ) * sin ΞΈ = sin ((n + 1) * ΞΈ) := by simp [S_eq_U_comp_half_mul_X] /-- The `n`-th Chebyshev polynomial of the first kind evaluates on `cosh ΞΈ` to the value `cosh (n * ΞΈ)`. -/ @[simp] theorem T_complex_cosh (n : β„€) : (T β„‚ n).eval (cosh ΞΈ) = cosh (n * ΞΈ) := calc (T β„‚ n).eval (cosh ΞΈ) _ = (T β„‚ n).eval (cos (ΞΈ * I)) := by rw [cos_mul_I] _ = cos (n * (ΞΈ * I)) := T_complex_cos (ΞΈ * I) n _ = cos (n * ΞΈ * I) := by rw [mul_assoc] _ = cosh (n * ΞΈ) := cos_mul_I (n * ΞΈ) /-- The `n`-th Chebyshev polynomial of the second kind evaluates on `cosh ΞΈ` to the value `sinh ((n + 1) * ΞΈ) / sinh ΞΈ`. -/ @[simp] theorem U_complex_cosh (n : β„€) : (U β„‚ n).eval (cosh ΞΈ) * sinh ΞΈ = sinh ((n + 1) * ΞΈ) := calc (U β„‚ n).eval (cosh ΞΈ) * sinh ΞΈ _ = (U β„‚ n).eval (cos (ΞΈ * I)) * sin (ΞΈ * I) * (-I) := by simp [cos_mul_I, sin_mul_I, mul_assoc] _ = sin ((n + 1) * (ΞΈ * I)) * (-I) := by rw [U_complex_cos] _ = sin ((n + 1) * ΞΈ * I) * (-I) := by rw [mul_assoc] _ = sinh ((n + 1) * ΞΈ) := by rw [sin_mul_I ((n + 1) * ΞΈ), mul_assoc, mul_neg, I_mul_I, neg_neg, mul_one] /-- The `n`-th rescaled Chebyshev polynomial of the first kind (Vieta–Lucas polynomial) evaluates on `2 * cosh ΞΈ` to the value `2 * cosh (n * ΞΈ)`. -/ @[simp] theorem C_two_mul_complex_cosh (n : β„€) : (C β„‚ n).eval (2 * cosh ΞΈ) = 2 * cosh (n * ΞΈ) := by simp [C_eq_two_mul_T_comp_half_mul_X] /-- The `n`-th rescaled Chebyshev polynomial of the second kind (Vieta–Fibonacci polynomial) evaluates on `2 * cosh ΞΈ` to the value `sinh ((n + 1) * ΞΈ) / sinh ΞΈ`. -/ @[simp] theorem S_two_mul_complex_cosh (n : β„€) : (S β„‚ n).eval (2 * cosh ΞΈ) * sinh ΞΈ = sinh ((n + 1) * ΞΈ) := by simp [S_eq_U_comp_half_mul_X] end Complex /-! ### Real versions -/ section Real open Real variable (ΞΈ : ℝ) (n : β„€) /-- The `n`-th Chebyshev polynomial of the first kind evaluates on `cos ΞΈ` to the value `cos (n * ΞΈ)`. -/ @[simp] theorem T_real_cos : (T ℝ n).eval (cos ΞΈ) = cos (n * ΞΈ) := mod_cast T_complex_cos ΞΈ n /-- The `n`-th Chebyshev polynomial of the second kind evaluates on `cos ΞΈ` to the value `sin ((n + 1) * ΞΈ) / sin ΞΈ`. -/ @[simp] theorem U_real_cos : (U ℝ n).eval (cos ΞΈ) * sin ΞΈ = sin ((n + 1) * ΞΈ) := mod_cast U_complex_cos ΞΈ n /-- The `n`-th rescaled Chebyshev polynomial of the first kind (Vieta–Lucas polynomial) evaluates on `2 * cos ΞΈ` to the value `2 * cos (n * ΞΈ)`. -/ @[simp] theorem C_two_mul_real_cos : (C ℝ n).eval (2 * cos ΞΈ) = 2 * cos (n * ΞΈ) := mod_cast C_two_mul_complex_cos ΞΈ n /-- The `n`-th rescaled Chebyshev polynomial of the second kind (Vieta–Fibonacci polynomial) evaluates on `2 * cos ΞΈ` to the value `sin ((n + 1) * ΞΈ) / sin ΞΈ`. -/ @[simp] theorem S_two_mul_real_cos : (S ℝ n).eval (2 * cos ΞΈ) * sin ΞΈ = sin ((n + 1) * ΞΈ) := mod_cast S_two_mul_complex_cos ΞΈ n /-- The `n`-th Chebyshev polynomial of the first kind evaluates on `cosh ΞΈ` to the value `cosh (n * ΞΈ)`. -/ @[simp] theorem T_real_cosh (n : β„€) : (T ℝ n).eval (cosh ΞΈ) = cosh (n * ΞΈ) := mod_cast T_complex_cosh ΞΈ n /-- The `n`-th Chebyshev polynomial of the second kind evaluates on `cosh ΞΈ` to the value `sinh ((n + 1) * ΞΈ) / sinh ΞΈ`. -/ @[simp] theorem U_real_cosh (n : β„€) : (U ℝ n).eval (cosh ΞΈ) * sinh ΞΈ = sinh ((n + 1) * ΞΈ) := mod_cast U_complex_cosh ΞΈ n /-- The `n`-th rescaled Chebyshev polynomial of the first kind (Vieta–Lucas polynomial) evaluates on `2 * cosh ΞΈ` to the value `2 * cosh (n * ΞΈ)`. -/ @[simp] theorem C_two_mul_real_cosh (n : β„€) : (C ℝ n).eval (2 * cosh ΞΈ) = 2 * cosh (n * ΞΈ) := mod_cast C_two_mul_complex_cosh ΞΈ n /-- The `n`-th rescaled Chebyshev polynomial of the second kind (Vieta–Fibonacci polynomial) evaluates on `2 * cosh ΞΈ` to the value `sinh ((n + 1) * ΞΈ) / sinh ΞΈ`. -/ @[simp] theorem S_two_mul_real_cosh (n : β„€) : (S ℝ n).eval (2 * cosh ΞΈ) * sinh ΞΈ = sinh ((n + 1) * ΞΈ) := mod_cast S_two_mul_complex_cosh ΞΈ n end Real end Polynomial.Chebyshev
.lake/packages/mathlib/Mathlib/Analysis/SpecialFunctions/Trigonometric/EulerSineProd.lean
import Mathlib.Analysis.SpecialFunctions.Integrals.Basic import Mathlib.MeasureTheory.Integral.PeakFunction /-! # Euler's infinite product for the sine function This file proves the infinite product formula $$ \sin \pi z = \pi z \prod_{n = 1}^\infty \left(1 - \frac{z ^ 2}{n ^ 2}\right) $$ for any real or complex `z`. Our proof closely follows the article [Salwinski, *Euler's Sine Product Formula: An Elementary Proof*][salwinski2018]: the basic strategy is to prove a recurrence relation for the integrals `∫ x in 0..Ο€/2, cos 2 z x * cos x ^ (2 * n)`, generalising the arguments used to prove Wallis' limit formula for `Ο€`. -/ open scoped Real Topology open Real Set Filter intervalIntegral MeasureTheory.MeasureSpace namespace EulerSine section IntegralRecursion /-! ## Recursion formula for the integral of `cos (2 * z * x) * cos x ^ n` We evaluate the integral of `cos (2 * z * x) * cos x ^ n`, for any complex `z` and even integers `n`, via repeated integration by parts. -/ variable {z : β„‚} {n : β„•} theorem antideriv_cos_comp_const_mul (hz : z β‰  0) (x : ℝ) : HasDerivAt (fun y : ℝ => Complex.sin (2 * z * y) / (2 * z)) (Complex.cos (2 * z * x)) x := by have a : HasDerivAt (fun y : β„‚ => y * (2 * z)) _ x := hasDerivAt_mul_const _ have b : HasDerivAt (Complex.sin ∘ fun y : β„‚ => (y * (2 * z))) _ x := HasDerivAt.comp (x : β„‚) (Complex.hasDerivAt_sin (x * (2 * z))) a have c := b.comp_ofReal.div_const (2 * z) field_simp at c; simp only [mul_rotate _ 2 z] at c exact c theorem antideriv_sin_comp_const_mul (hz : z β‰  0) (x : ℝ) : HasDerivAt (fun y : ℝ => -Complex.cos (2 * z * y) / (2 * z)) (Complex.sin (2 * z * x)) x := by have a : HasDerivAt (fun y : β„‚ => y * (2 * z)) _ x := hasDerivAt_mul_const _ have b : HasDerivAt (Complex.cos ∘ fun y : β„‚ => (y * (2 * z))) _ x := HasDerivAt.comp (x : β„‚) (Complex.hasDerivAt_cos (x * (2 * z))) a have c := (b.comp_ofReal.div_const (2 * z)).fun_neg simp at c ⊒; field_simp at c ⊒; simp only [mul_rotate _ 2 z] at c exact c theorem integral_cos_mul_cos_pow_aux (hn : 2 ≀ n) (hz : z β‰  0) : (∫ x in (0 : ℝ)..Ο€ / 2, Complex.cos (2 * z * x) * (cos x : β„‚) ^ n) = n / (2 * z) * ∫ x in (0 : ℝ)..Ο€ / 2, Complex.sin (2 * z * x) * sin x * (cos x : β„‚) ^ (n - 1) := by have der1 : βˆ€ x : ℝ, x ∈ uIcc 0 (Ο€ / 2) β†’ HasDerivAt (fun y : ℝ => (cos y : β„‚) ^ n) (-n * sin x * (cos x : β„‚) ^ (n - 1)) x := by intro x _ have b : HasDerivAt (fun y : ℝ => (cos y : β„‚)) (-sin x) x := by simpa using (hasDerivAt_cos x).ofReal_comp convert HasDerivAt.comp x (hasDerivAt_pow _ _) b using 1 ring convert (config := { sameFun := true }) integral_mul_deriv_eq_deriv_mul der1 (fun x _ => antideriv_cos_comp_const_mul hz x) _ _ using 2 Β· ext1 x; rw [mul_comm] Β· rw [Complex.ofReal_zero, mul_zero, Complex.sin_zero, zero_div, mul_zero, sub_zero, cos_pi_div_two, Complex.ofReal_zero, zero_pow (by positivity : n β‰  0), zero_mul, zero_sub, ← integral_neg, ← integral_const_mul] refine integral_congr fun x _ => ?_ ring Β· apply Continuous.intervalIntegrable exact (continuous_const.mul (Complex.continuous_ofReal.comp continuous_sin)).mul ((Complex.continuous_ofReal.comp continuous_cos).pow (n - 1)) Β· apply Continuous.intervalIntegrable exact Complex.continuous_cos.comp (continuous_const.mul Complex.continuous_ofReal) theorem integral_sin_mul_sin_mul_cos_pow_eq (hn : 2 ≀ n) (hz : z β‰  0) : (∫ x in (0 : ℝ)..Ο€ / 2, Complex.sin (2 * z * x) * sin x * (cos x : β„‚) ^ (n - 1)) = (n / (2 * z) * ∫ x in (0 : ℝ)..Ο€ / 2, Complex.cos (2 * z * x) * (cos x : β„‚) ^ n) - (n - 1) / (2 * z) * ∫ x in (0 : ℝ)..Ο€ / 2, Complex.cos (2 * z * x) * (cos x : β„‚) ^ (n - 2) := by have der1 : βˆ€ x : ℝ, x ∈ uIcc 0 (Ο€ / 2) β†’ HasDerivAt (fun y : ℝ => sin y * (cos y : β„‚) ^ (n - 1)) ((cos x : β„‚) ^ n - (n - 1) * (sin x : β„‚) ^ 2 * (cos x : β„‚) ^ (n - 2)) x := by intro x _ have c := HasDerivAt.comp (x : β„‚) (hasDerivAt_pow (n - 1) _) (Complex.hasDerivAt_cos x) convert ((Complex.hasDerivAt_sin x).fun_mul c).comp_ofReal using 1 Β· simp only [Complex.ofReal_sin, Complex.ofReal_cos, Function.comp] Β· simp only [Complex.ofReal_cos, Complex.ofReal_sin] rw [mul_neg, mul_neg, ← sub_eq_add_neg, Function.comp_apply] congr 1 Β· rw [← pow_succ', Nat.sub_add_cancel (by cutsat : 1 ≀ n)] Β· have : ((n - 1 : β„•) : β„‚) = (n : β„‚) - 1 := by rw [Nat.cast_sub (one_le_two.trans hn), Nat.cast_one] rw [Nat.sub_sub, this] ring convert integral_mul_deriv_eq_deriv_mul der1 (fun x _ => antideriv_sin_comp_const_mul hz x) _ _ using 1 Β· refine integral_congr fun x _ => ?_ ring_nf Β· -- now a tedious rearrangement of terms -- gather into a single integral, and deal with continuity subgoals: rw [sin_zero, cos_pi_div_two, Complex.ofReal_zero, zero_pow, zero_mul, mul_zero, zero_mul, zero_mul, sub_zero, zero_sub, ← integral_neg, ← integral_const_mul, ← integral_const_mul, ← integral_sub] rotate_left Β· apply Continuous.intervalIntegrable exact continuous_const.mul ((Complex.continuous_cos.comp (continuous_const.mul Complex.continuous_ofReal)).mul ((Complex.continuous_ofReal.comp continuous_cos).pow n)) Β· apply Continuous.intervalIntegrable exact continuous_const.mul ((Complex.continuous_cos.comp (continuous_const.mul Complex.continuous_ofReal)).mul ((Complex.continuous_ofReal.comp continuous_cos).pow (n - 2))) Β· exact Nat.sub_ne_zero_of_lt hn refine integral_congr fun x _ => ?_ dsimp only -- get rid of real trig functions and divisions by 2 * z: rw [Complex.ofReal_cos, Complex.ofReal_sin, Complex.sin_sq, ← mul_div_right_comm, ← mul_div_right_comm, ← sub_div, mul_div, ← neg_div] congr 1 have : Complex.cos x ^ n = Complex.cos x ^ (n - 2) * Complex.cos x ^ 2 := by conv_lhs => rw [← Nat.sub_add_cancel hn, pow_add] rw [this] ring Β· apply Continuous.intervalIntegrable exact ((Complex.continuous_ofReal.comp continuous_cos).pow n).sub ((continuous_const.mul ((Complex.continuous_ofReal.comp continuous_sin).pow 2)).mul ((Complex.continuous_ofReal.comp continuous_cos).pow (n - 2))) Β· apply Continuous.intervalIntegrable exact Complex.continuous_sin.comp (continuous_const.mul Complex.continuous_ofReal) /-- Note this also holds for `z = 0`, but we do not need this case for `sin_pi_mul_eq`. -/ theorem integral_cos_mul_cos_pow (hn : 2 ≀ n) (hz : z β‰  0) : (((1 : β„‚) - (4 : β„‚) * z ^ 2 / (n : β„‚) ^ 2) * ∫ x in (0 : ℝ)..Ο€ / 2, Complex.cos (2 * z * x) * (cos x : β„‚) ^ n) = (n - 1 : β„‚) / n * ∫ x in (0 : ℝ)..Ο€ / 2, Complex.cos (2 * z * x) * (cos x : β„‚) ^ (n - 2) := by have nne : (n : β„‚) β‰  0 := by contrapose! hn; rw [Nat.cast_eq_zero] at hn; rw [hn]; exact zero_lt_two have := integral_cos_mul_cos_pow_aux hn hz rw [integral_sin_mul_sin_mul_cos_pow_eq hn hz, sub_eq_neg_add, mul_add, ← sub_eq_iff_eq_add] at this convert congr_arg (fun u : β„‚ => -u * (2 * z) ^ 2 / n ^ 2) this using 1 <;> field /-- Note this also holds for `z = 0`, but we do not need this case for `sin_pi_mul_eq`. -/ theorem integral_cos_mul_cos_pow_even (n : β„•) (hz : z β‰  0) : (((1 : β„‚) - z ^ 2 / ((n : β„‚) + 1) ^ 2) * ∫ x in (0 : ℝ)..Ο€ / 2, Complex.cos (2 * z * x) * (cos x : β„‚) ^ (2 * n + 2)) = (2 * n + 1 : β„‚) / (2 * n + 2) * ∫ x in (0 : ℝ)..Ο€ / 2, Complex.cos (2 * z * x) * (cos x : β„‚) ^ (2 * n) := by convert integral_cos_mul_cos_pow (by cutsat : 2 ≀ 2 * n + 2) hz using 3 Β· simp only [Nat.cast_add, Nat.cast_mul, Nat.cast_two] nth_rw 2 [← mul_one (2 : β„‚)] rw [← mul_add, mul_pow, ← div_div] ring Β· push_cast; ring Β· push_cast; ring /-- Relate the integral `cos x ^ n` over `[0, Ο€/2]` to the integral of `sin x ^ n` over `[0, Ο€]`, which is studied in `Mathlib/Analysis/Real/Pi/Wallis.lean` and other places. -/ theorem integral_cos_pow_eq (n : β„•) : (∫ x in (0 : ℝ)..Ο€ / 2, cos x ^ n) = 1 / 2 * ∫ x in (0 : ℝ)..Ο€, sin x ^ n := by rw [mul_comm (1 / 2 : ℝ), ← div_eq_iff (one_div_ne_zero (two_ne_zero' ℝ)), ← div_mul, div_one, mul_two] have L : IntervalIntegrable _ volume 0 (Ο€ / 2) := (continuous_sin.pow n).intervalIntegrable _ _ have R : IntervalIntegrable _ volume (Ο€ / 2) Ο€ := (continuous_sin.pow n).intervalIntegrable _ _ rw [← integral_add_adjacent_intervals L R] congr 1 Β· nth_rw 1 [(by ring : 0 = Ο€ / 2 - Ο€ / 2)] nth_rw 3 [(by ring : Ο€ / 2 = Ο€ / 2 - 0)] rw [← integral_comp_sub_left] refine integral_congr fun x _ => ?_ rw [cos_pi_div_two_sub] Β· nth_rw 3 [(by ring : Ο€ = Ο€ / 2 + Ο€ / 2)] nth_rw 2 [(by ring : Ο€ / 2 = 0 + Ο€ / 2)] rw [← integral_comp_add_right] refine integral_congr fun x _ => ?_ rw [sin_add_pi_div_two] theorem integral_cos_pow_pos (n : β„•) : 0 < ∫ x in (0 : ℝ)..Ο€ / 2, cos x ^ n := (integral_cos_pow_eq n).symm β–Έ mul_pos one_half_pos (integral_sin_pow_pos _) /-- Finite form of Euler's sine product, with remainder term expressed as a ratio of cosine integrals. -/ theorem sin_pi_mul_eq (z : β„‚) (n : β„•) : Complex.sin (Ο€ * z) = ((Ο€ * z * ∏ j ∈ Finset.range n, ((1 : β„‚) - z ^ 2 / ((j : β„‚) + 1) ^ 2)) * ∫ x in (0 : ℝ)..Ο€ / 2, Complex.cos (2 * z * x) * (cos x : β„‚) ^ (2 * n)) / (∫ x in (0 : ℝ)..Ο€ / 2, cos x ^ (2 * n) : ℝ) := by rcases eq_or_ne z 0 with (rfl | hz) Β· simp induction n with | zero => simp_rw [mul_zero, pow_zero, mul_one, Finset.prod_range_zero, mul_one, integral_one, sub_zero] rw [integral_cos_mul_complex (mul_ne_zero two_ne_zero hz), Complex.ofReal_zero, mul_zero, Complex.sin_zero, zero_div, sub_zero, (by push_cast; ring : 2 * z * ↑(Ο€ / 2) = Ο€ * z)] simp [field] | succ n hn => rw [hn, Finset.prod_range_succ] set A := ∏ j ∈ Finset.range n, ((1 : β„‚) - z ^ 2 / ((j : β„‚) + 1) ^ 2) set B := ∫ x in (0 : ℝ)..Ο€ / 2, Complex.cos (2 * z * x) * (cos x : β„‚) ^ (2 * n) set C := ∫ x in (0 : ℝ)..Ο€ / 2, cos x ^ (2 * n) have aux' : 2 * n.succ = 2 * n + 2 := by rw [Nat.succ_eq_add_one, mul_add, mul_one] have : (∫ x in (0 : ℝ)..Ο€ / 2, cos x ^ (2 * n.succ)) = (2 * (n : ℝ) + 1) / (2 * n + 2) * C := by rw [integral_cos_pow_eq] dsimp only [C] rw [integral_cos_pow_eq, aux', integral_sin_pow, sin_zero, sin_pi, pow_succ', zero_mul, zero_mul, zero_mul, sub_zero, zero_div, zero_add, ← mul_assoc, ← mul_assoc, mul_comm (1 / 2 : ℝ) _, Nat.cast_mul, Nat.cast_ofNat] rw [this] change Ο€ * z * A * B / C = (Ο€ * z * (A * ((1 : β„‚) - z ^ 2 / ((n : β„‚) + 1) ^ 2)) * ∫ x in (0 : ℝ)..Ο€ / 2, Complex.cos (2 * z * x) * (cos x : β„‚) ^ (2 * n.succ)) / ((2 * n + 1) / (2 * n + 2) * C : ℝ) have : (Ο€ * z * (A * ((1 : β„‚) - z ^ 2 / ((n : β„‚) + 1) ^ 2)) * ∫ x in (0 : ℝ)..Ο€ / 2, Complex.cos (2 * z * x) * (cos x : β„‚) ^ (2 * n.succ)) = Ο€ * z * A * (((1 : β„‚) - z ^ 2 / (n.succ : β„‚) ^ 2) * ∫ x in (0 : ℝ)..Ο€ / 2, Complex.cos (2 * z * x) * (cos x : β„‚) ^ (2 * n.succ)) := by grind rw [this] suffices (((1 : β„‚) - z ^ 2 / (n.succ : β„‚) ^ 2) * ∫ x in (0 : ℝ)..Ο€ / 2, Complex.cos (2 * z * x) * (cos x : β„‚) ^ (2 * n.succ)) = (2 * n + 1) / (2 * n + 2) * B by rw [this, Complex.ofReal_mul, Complex.ofReal_div] have : (C : β„‚) β‰  0 := Complex.ofReal_ne_zero.mpr (integral_cos_pow_pos _).ne' have : 2 * (n : β„‚) + 1 β‰  0 := by convert (Nat.cast_add_one_ne_zero (2 * n) : (↑(2 * n) + 1 : β„‚) β‰  0) simp have : (n : β„‚) + 1 β‰  0 := Nat.cast_add_one_ne_zero n simp [field] convert integral_cos_mul_cos_pow_even n hz rw [Nat.cast_succ] end IntegralRecursion /-! ## Conclusion of the proof The main theorem `Complex.tendsto_euler_sin_prod`, and its real variant `Real.tendsto_euler_sin_prod`, now follow by combining `sin_pi_mul_eq` with a lemma stating that the sequence of measures on `[0, Ο€/2]` given by integration against `cos x ^ n` (suitably normalised) tends to the Dirac measure at 0, as a special case of the general result `tendsto_setIntegral_pow_smul_of_unique_maximum_of_isCompact_of_continuousOn`. -/ theorem tendsto_integral_cos_pow_mul_div {f : ℝ β†’ β„‚} (hf : ContinuousOn f (Icc 0 (Ο€ / 2))) : Tendsto (fun n : β„• => (∫ x in (0 : ℝ)..Ο€ / 2, (cos x : β„‚) ^ n * f x) / (∫ x in (0 : ℝ)..Ο€ / 2, cos x ^ n : ℝ)) atTop (𝓝 <| f 0) := by simp_rw [div_eq_inv_mul (Ξ± := β„‚), ← Complex.ofReal_inv, integral_of_le pi_div_two_pos.le, ← MeasureTheory.integral_Icc_eq_integral_Ioc, ← Complex.ofReal_pow, ← Complex.real_smul] have c_lt : βˆ€ y : ℝ, y ∈ Icc 0 (Ο€ / 2) β†’ y β‰  0 β†’ cos y < cos 0 := fun y hy hy' => cos_lt_cos_of_nonneg_of_le_pi_div_two (le_refl 0) hy.2 (lt_of_le_of_ne hy.1 hy'.symm) have c_nonneg : βˆ€ x : ℝ, x ∈ Icc 0 (Ο€ / 2) β†’ 0 ≀ cos x := fun x hx => cos_nonneg_of_mem_Icc ((Icc_subset_Icc_left (neg_nonpos_of_nonneg pi_div_two_pos.le)) hx) have c_zero_pos : 0 < cos 0 := by rw [cos_zero]; exact zero_lt_one have zero_mem : (0 : ℝ) ∈ closure (interior (Icc 0 (Ο€ / 2))) := by rw [interior_Icc, closure_Ioo pi_div_two_pos.ne, left_mem_Icc] exact pi_div_two_pos.le exact tendsto_setIntegral_pow_smul_of_unique_maximum_of_isCompact_of_continuousOn isCompact_Icc continuousOn_cos c_lt c_nonneg c_zero_pos zero_mem hf /-- Euler's infinite product formula for the complex sine function. -/ theorem _root_.Complex.tendsto_euler_sin_prod (z : β„‚) : Tendsto (fun n : β„• => Ο€ * z * ∏ j ∈ Finset.range n, ((1 : β„‚) - z ^ 2 / ((j : β„‚) + 1) ^ 2)) atTop (𝓝 <| Complex.sin (Ο€ * z)) := by have A : Tendsto (fun n : β„• => ((Ο€ * z * ∏ j ∈ Finset.range n, ((1 : β„‚) - z ^ 2 / ((j : β„‚) + 1) ^ 2)) * ∫ x in (0 : ℝ)..Ο€ / 2, Complex.cos (2 * z * x) * (cos x : β„‚) ^ (2 * n)) / (∫ x in (0 : ℝ)..Ο€ / 2, cos x ^ (2 * n) : ℝ)) atTop (𝓝 <| _) := Tendsto.congr (fun n => sin_pi_mul_eq z n) tendsto_const_nhds have : 𝓝 (Complex.sin (Ο€ * z)) = 𝓝 (Complex.sin (Ο€ * z) * 1) := by rw [mul_one] simp_rw [this, mul_div_assoc] at A convert (tendsto_mul_iff_of_ne_zero _ one_ne_zero).mp A suffices Tendsto (fun n : β„• => (∫ x in (0 : ℝ)..Ο€ / 2, Complex.cos (2 * z * x) * (cos x : β„‚) ^ n) / (∫ x in (0 : ℝ)..Ο€ / 2, cos x ^ n : ℝ)) atTop (𝓝 1) from this.comp (tendsto_id.const_mul_atTop' zero_lt_two) have : ContinuousOn (fun x : ℝ => Complex.cos (2 * z * x)) (Icc 0 (Ο€ / 2)) := (Complex.continuous_cos.comp (continuous_const.mul Complex.continuous_ofReal)).continuousOn convert tendsto_integral_cos_pow_mul_div this using 1 Β· ext1 n; congr 2 with x : 1; rw [mul_comm] Β· rw [Complex.ofReal_zero, mul_zero, Complex.cos_zero] /-- Euler's infinite product formula for the real sine function. -/ theorem _root_.Real.tendsto_euler_sin_prod (x : ℝ) : Tendsto (fun n : β„• => Ο€ * x * ∏ j ∈ Finset.range n, ((1 : ℝ) - x ^ 2 / ((j : ℝ) + 1) ^ 2)) atTop (𝓝 <| sin (Ο€ * x)) := by convert (Complex.continuous_re.tendsto _).comp (Complex.tendsto_euler_sin_prod x) using 1 Β· ext1 n rw [Function.comp_apply, ← Complex.ofReal_mul, Complex.re_ofReal_mul] suffices (∏ j ∈ Finset.range n, (1 - x ^ 2 / (j + 1) ^ 2) : β„‚) = (∏ j ∈ Finset.range n, (1 - x ^ 2 / (j + 1) ^ 2) : ℝ) by rw [this, Complex.ofReal_re] rw [Complex.ofReal_prod] refine Finset.prod_congr (by rfl) fun n _ => ?_ norm_cast Β· rw [← Complex.ofReal_mul, ← Complex.ofReal_sin, Complex.ofReal_re] end EulerSine
.lake/packages/mathlib/Mathlib/Analysis/SpecialFunctions/Trigonometric/Bounds.lean
import Mathlib.Analysis.Convex.SpecificFunctions.Deriv import Mathlib.Analysis.SpecialFunctions.Trigonometric.ArctanDeriv /-! # Polynomial bounds for trigonometric functions ## Main statements This file contains upper and lower bounds for real trigonometric functions in terms of polynomials. See `Trigonometric.Basic` for more elementary inequalities, establishing the ranges of these functions, and their monotonicity in suitable intervals. Here we prove the following: * `sin_lt`: for `x > 0` we have `sin x < x`. * `sin_gt_sub_cube`: For `0 < x ≀ 1` we have `x - x ^ 3 / 4 < sin x`. * `lt_tan`: for `0 < x < Ο€/2` we have `x < tan x`. * `cos_le_one_div_sqrt_sq_add_one` and `cos_lt_one_div_sqrt_sq_add_one`: for `-3 * Ο€ / 2 ≀ x ≀ 3 * Ο€ / 2`, we have `cos x ≀ 1 / sqrt (x ^ 2 + 1)`, with strict inequality if `x β‰  0`. (This bound is not quite optimal, but not far off) ## Tags sin, cos, tan, angle -/ open Set namespace Real variable {x : ℝ} /-- For 0 < x, we have sin x < x. -/ theorem sin_lt (h : 0 < x) : sin x < x := by rcases lt_or_ge 1 x with h' | h' Β· exact (sin_le_one x).trans_lt h' have hx : |x| = x := abs_of_nonneg h.le have := le_of_abs_le (sin_bound <| show |x| ≀ 1 by rwa [hx]) rw [sub_le_iff_le_add', hx] at this apply this.trans_lt rw [sub_add, sub_lt_self_iff, sub_pos, div_eq_mul_inv (x ^ 3)] refine mul_lt_mul' ?_ (by norm_num) (by norm_num) (pow_pos h 3) apply pow_le_pow_of_le_one h.le h' simp lemma sin_le (hx : 0 ≀ x) : sin x ≀ x := by obtain rfl | hx := hx.eq_or_lt Β· simp Β· exact (sin_lt hx).le lemma lt_sin (hx : x < 0) : x < sin x := by simpa using sin_lt <| neg_pos.2 hx lemma le_sin (hx : x ≀ 0) : x ≀ sin x := by simpa using sin_le <| neg_nonneg.2 hx theorem lt_sin_mul {x : ℝ} (hx : 0 < x) (hx' : x < 1) : x < sin (Ο€ / 2 * x) := by simpa [mul_comm x] using strictConcaveOn_sin_Icc.2 ⟨le_rfl, pi_pos.le⟩ ⟨pi_div_two_pos.le, half_le_self pi_pos.le⟩ pi_div_two_pos.ne (sub_pos.2 hx') hx theorem le_sin_mul {x : ℝ} (hx : 0 ≀ x) (hx' : x ≀ 1) : x ≀ sin (Ο€ / 2 * x) := by simpa [mul_comm x] using strictConcaveOn_sin_Icc.concaveOn.2 ⟨le_rfl, pi_pos.le⟩ ⟨pi_div_two_pos.le, half_le_self pi_pos.le⟩ (sub_nonneg.2 hx') hx theorem mul_lt_sin {x : ℝ} (hx : 0 < x) (hx' : x < Ο€ / 2) : 2 / Ο€ * x < sin x := by rw [← inv_div] simpa [-inv_div, mul_inv_cancel_leftβ‚€ pi_div_two_pos.ne'] using @lt_sin_mul ((Ο€ / 2)⁻¹ * x) (mul_pos (inv_pos.2 pi_div_two_pos) hx) (by rwa [← div_eq_inv_mul, div_lt_one pi_div_two_pos]) /-- One half of **Jordan's inequality**. In the range `[0, Ο€ / 2]`, we have a linear lower bound on `sin`. The other half is given by `Real.sin_le`. -/ theorem mul_le_sin {x : ℝ} (hx : 0 ≀ x) (hx' : x ≀ Ο€ / 2) : 2 / Ο€ * x ≀ sin x := by rw [← inv_div] simpa [-inv_div, mul_inv_cancel_leftβ‚€ pi_div_two_pos.ne'] using @le_sin_mul ((Ο€ / 2)⁻¹ * x) (mul_nonneg (inv_nonneg.2 pi_div_two_pos.le) hx) (by rwa [← div_eq_inv_mul, div_le_one pi_div_two_pos]) /-- Half of **Jordan's inequality** for negative values. -/ lemma sin_le_mul (hx : -(Ο€ / 2) ≀ x) (hxβ‚€ : x ≀ 0) : sin x ≀ 2 / Ο€ * x := by simpa using mul_le_sin (neg_nonneg.2 hxβ‚€) (neg_le.2 hx) /-- Half of **Jordan's inequality** for absolute values. -/ lemma mul_abs_le_abs_sin (hx : |x| ≀ Ο€ / 2) : 2 / Ο€ * |x| ≀ |sin x| := by wlog hxβ‚€ : 0 ≀ x case inr => simpa using this (by rwa [abs_neg]) <| neg_nonneg.2 <| le_of_not_ge hxβ‚€ rw [abs_of_nonneg hxβ‚€] at hx ⊒ exact (mul_le_sin hxβ‚€ hx).trans (le_abs_self _) lemma sin_sq_lt_sq (hx : x β‰  0) : sin x ^ 2 < x ^ 2 := by wlog hxβ‚€ : 0 < x case inr => simpa using this (neg_ne_zero.2 hx) <| neg_pos_of_neg <| hx.lt_of_le <| le_of_not_gt hxβ‚€ rcases le_or_gt x 1 with hxΟ€ | hxΟ€ case inl => exact pow_lt_pow_leftβ‚€ (sin_lt hxβ‚€) (sin_nonneg_of_nonneg_of_le_pi hxβ‚€.le (by linarith [two_le_pi])) (by simp) case inr => exact (sin_sq_le_one _).trans_lt (by rwa [one_lt_sq_iffβ‚€ hxβ‚€.le]) lemma sin_sq_le_sq : sin x ^ 2 ≀ x ^ 2 := by rcases eq_or_ne x 0 with rfl | hx case inl => simp case inr => exact (sin_sq_lt_sq hx).le lemma abs_sin_lt_abs (hx : x β‰  0) : |sin x| < |x| := sq_lt_sq.1 (sin_sq_lt_sq hx) lemma abs_sin_le_abs : |sin x| ≀ |x| := sq_le_sq.1 sin_sq_le_sq lemma one_sub_sq_div_two_lt_cos (hx : x β‰  0) : 1 - x ^ 2 / 2 < cos x := by have := (sin_sq_lt_sq (by positivity)).trans_eq' (sin_sq_eq_half_sub (x / 2)).symm ring_nf at this linarith lemma one_sub_sq_div_two_le_cos : 1 - x ^ 2 / 2 ≀ cos x := by rcases eq_or_ne x 0 with rfl | hx case inl => simp case inr => exact (one_sub_sq_div_two_lt_cos hx).le /-- Half of **Jordan's inequality** for `cos`. -/ lemma one_sub_mul_le_cos (hxβ‚€ : 0 ≀ x) (hx : x ≀ Ο€ / 2) : 1 - 2 / Ο€ * x ≀ cos x := by simpa [sin_pi_div_two_sub, mul_sub, div_mul_div_comm, mul_comm Ο€, pi_pos.ne'] using mul_le_sin (x := Ο€ / 2 - x) (by simpa) (by simpa) /-- Half of **Jordan's inequality** for `cos` and negative values. -/ lemma one_add_mul_le_cos (hxβ‚€ : -(Ο€ / 2) ≀ x) (hx : x ≀ 0) : 1 + 2 / Ο€ * x ≀ cos x := by simpa using one_sub_mul_le_cos (x := -x) (by linarith) (by linarith) lemma cos_le_one_sub_mul_cos_sq (hx : |x| ≀ Ο€) : cos x ≀ 1 - 2 / Ο€ ^ 2 * x ^ 2 := by wlog hxβ‚€ : 0 ≀ x case inr => simpa using this (by rwa [abs_neg]) <| neg_nonneg.2 <| le_of_not_ge hxβ‚€ rw [abs_of_nonneg hxβ‚€] at hx have : x / Ο€ ≀ sin (x / 2) := by simpa using mul_le_sin (x := x / 2) (by positivity) (by linarith) have := (pow_le_pow_leftβ‚€ (by positivity) this 2).trans_eq (sin_sq_eq_half_sub _) ring_nf at this ⊒ linarith /-- For 0 < x ≀ 1 we have x - x ^ 3 / 4 < sin x. This is also true for x > 1, but it's nontrivial for x just above 1. This inequality is not tight; the tighter inequality is sin x > x - x ^ 3 / 6 for all x > 0, but this inequality has a simpler proof. -/ theorem sin_gt_sub_cube {x : ℝ} (h : 0 < x) (h' : x ≀ 1) : x - x ^ 3 / 4 < sin x := by have hx : |x| = x := abs_of_nonneg h.le have := neg_le_of_abs_le (sin_bound <| show |x| ≀ 1 by rwa [hx]) rw [le_sub_iff_add_le, hx] at this refine lt_of_lt_of_le ?_ this have : x ^ 3 / ↑4 - x ^ 3 / ↑6 = x ^ 3 * 12⁻¹ := by norm_num [div_eq_mul_inv, ← mul_sub] rw [add_comm, sub_add, sub_neg_eq_add, sub_lt_sub_iff_left, ← lt_sub_iff_add_lt', this] refine mul_lt_mul' ?_ (by norm_num) (by norm_num) (pow_pos h 3) apply pow_le_pow_of_le_one h.le h' simp /-- The derivative of `tan x - x` is `1/(cos x)^2 - 1` away from the zeroes of cos. -/ theorem deriv_tan_sub_id (x : ℝ) (h : cos x β‰  0) : deriv (fun y : ℝ => tan y - y) x = 1 / cos x ^ 2 - 1 := HasDerivAt.deriv <| by simpa using (hasDerivAt_tan h).add (hasDerivAt_id x).neg /-- For all `0 < x < Ο€/2` we have `x < tan x`. This is proved by checking that the function `tan x - x` vanishes at zero and has non-negative derivative. -/ theorem lt_tan {x : ℝ} (h1 : 0 < x) (h2 : x < Ο€ / 2) : x < tan x := by let U := Ico 0 (Ο€ / 2) have intU : interior U = Ioo 0 (Ο€ / 2) := interior_Ico have half_pi_pos : 0 < Ο€ / 2 := div_pos pi_pos two_pos have cos_pos {y : ℝ} (hy : y ∈ U) : 0 < cos y := by exact cos_pos_of_mem_Ioo (Ico_subset_Ioo_left (neg_lt_zero.mpr half_pi_pos) hy) have sin_pos {y : ℝ} (hy : y ∈ interior U) : 0 < sin y := by rw [intU] at hy exact sin_pos_of_mem_Ioo (Ioo_subset_Ioo_right (div_le_self pi_pos.le one_le_two) hy) have tan_cts_U : ContinuousOn tan U := by apply ContinuousOn.mono continuousOn_tan intro z hz simp only [mem_setOf_eq] exact (cos_pos hz).ne' have tan_minus_id_cts : ContinuousOn (fun y : ℝ => tan y - y) U := tan_cts_U.sub continuousOn_id have deriv_pos (y : ℝ) (hy : y ∈ interior U) : 0 < deriv (fun y' : ℝ => tan y' - y') y := by have := cos_pos (interior_subset hy) simp only [deriv_tan_sub_id y this.ne', one_div, gt_iff_lt, sub_pos] norm_cast have bd2 : cos y ^ 2 < 1 := by apply lt_of_le_of_ne y.cos_sq_le_one rw [cos_sq'] simpa only [Ne, sub_eq_self, sq_eq_zero_iff] using (sin_pos hy).ne' rwa [lt_inv_commβ‚€, inv_one] Β· exact zero_lt_one simpa only [sq, mul_self_pos] using this.ne' have mono := strictMonoOn_of_deriv_pos (convex_Ico 0 (Ο€ / 2)) tan_minus_id_cts deriv_pos have zero_in_U : (0 : ℝ) ∈ U := by rwa [left_mem_Ico] have x_in_U : x ∈ U := ⟨h1.le, h2⟩ simpa only [tan_zero, sub_zero, sub_pos] using mono zero_in_U x_in_U h1 theorem le_tan {x : ℝ} (h1 : 0 ≀ x) (h2 : x < Ο€ / 2) : x ≀ tan x := by rcases eq_or_lt_of_le h1 with (rfl | h1') Β· rw [tan_zero] Β· exact le_of_lt (lt_tan h1' h2) theorem cos_lt_one_div_sqrt_sq_add_one {x : ℝ} (hx1 : -(3 * Ο€ / 2) ≀ x) (hx2 : x ≀ 3 * Ο€ / 2) (hx3 : x β‰  0) : cos x < (1 / √(x ^ 2 + 1) : ℝ) := by suffices βˆ€ {y : ℝ}, 0 < y β†’ y ≀ 3 * Ο€ / 2 β†’ cos y < 1 / √(y ^ 2 + 1) by rcases lt_or_lt_iff_ne.mpr hx3.symm with ⟨h⟩ Β· exact this h hx2 Β· convert this (by linarith : 0 < -x) (by linarith) using 1 Β· rw [cos_neg] Β· rw [neg_sq] intro y hy1 hy2 have hy3 : ↑0 < y ^ 2 + 1 := by linarith [sq_nonneg y] rcases lt_or_ge y (Ο€ / 2) with (hy2' | hy1') Β· -- Main case : `0 < y < Ο€ / 2` have hy4 : 0 < cos y := cos_pos_of_mem_Ioo ⟨by linarith, hy2'⟩ rw [← abs_of_nonneg (cos_nonneg_of_mem_Icc ⟨by linarith, hy2'.le⟩), ← abs_of_nonneg (one_div_nonneg.mpr (sqrt_nonneg _)), ← sq_lt_sq, div_pow, one_pow, sq_sqrt hy3.le, lt_one_div (pow_pos hy4 _) hy3, ← inv_one_add_tan_sq hy4.ne', one_div, inv_inv, add_comm, add_lt_add_iff_left, sq_lt_sq, abs_of_pos hy1, abs_of_nonneg (tan_nonneg_of_nonneg_of_le_pi_div_two hy1.le hy2'.le)] exact Real.lt_tan hy1 hy2' Β· -- Easy case : `Ο€ / 2 ≀ y ≀ 3 * Ο€ / 2` refine lt_of_le_of_lt ?_ (one_div_pos.mpr <| sqrt_pos_of_pos hy3) exact cos_nonpos_of_pi_div_two_le_of_le hy1' (by linarith [pi_pos]) theorem cos_le_one_div_sqrt_sq_add_one {x : ℝ} (hx1 : -(3 * Ο€ / 2) ≀ x) (hx2 : x ≀ 3 * Ο€ / 2) : cos x ≀ (1 : ℝ) / √(x ^ 2 + 1) := by rcases eq_or_ne x 0 with (rfl | hx3) Β· simp Β· exact (cos_lt_one_div_sqrt_sq_add_one hx1 hx2 hx3).le theorem norm_exp_I_mul_ofReal_sub_one_le {x : ℝ} : β€–.exp (.I * x) - (1 : β„‚)β€– ≀ β€–xβ€– := by rw [Complex.norm_exp_I_mul_ofReal_sub_one] calc _ = 2 * |Real.sin (x / 2)| := by simp _ ≀ 2 * |x / 2| := (mul_le_mul_iff_of_pos_left zero_lt_two).mpr Real.abs_sin_le_abs _ = _ := by rw [abs_div, Nat.abs_ofNat, Real.norm_eq_abs]; ring theorem enorm_exp_I_mul_ofReal_sub_one_le {x : ℝ} : β€–.exp (.I * x) - (1 : β„‚)β€–β‚‘ ≀ β€–xβ€–β‚‘ := by iterate 2 rw [← enorm_norm, Real.enorm_of_nonneg (norm_nonneg _)] exact ENNReal.ofReal_le_ofReal norm_exp_I_mul_ofReal_sub_one_le theorem nnnorm_exp_I_mul_ofReal_sub_one_le {x : ℝ} : β€–.exp (.I * x) - (1 : β„‚)β€–β‚Š ≀ β€–xβ€–β‚Š := by rw [← ENNReal.coe_le_coe]; exact enorm_exp_I_mul_ofReal_sub_one_le end Real
.lake/packages/mathlib/Mathlib/Analysis/SpecialFunctions/Complex/Analytic.lean
import Mathlib.Analysis.Analytic.Composition import Mathlib.Analysis.Analytic.Constructions import Mathlib.Analysis.Complex.CauchyIntegral import Mathlib.Analysis.SpecialFunctions.Complex.LogDeriv /-! # Various complex special functions are analytic `log`, and `cpow` are analytic, since they are differentiable. -/ open Complex Set open scoped Topology variable {E : Type} [NormedAddCommGroup E] [NormedSpace β„‚ E] variable {f g : E β†’ β„‚} {z : β„‚} {x : E} {s : Set E} /-- `log` is analytic away from nonpositive reals -/ @[fun_prop] theorem analyticAt_clog (m : z ∈ slitPlane) : AnalyticAt β„‚ log z := by rw [analyticAt_iff_eventually_differentiableAt] filter_upwards [isOpen_slitPlane.eventually_mem m] intro z m exact differentiableAt_id.clog m /-- `log` is analytic away from nonpositive reals -/ @[fun_prop] theorem AnalyticAt.clog (fa : AnalyticAt β„‚ f x) (m : f x ∈ slitPlane) : AnalyticAt β„‚ (fun z ↦ log (f z)) x := (analyticAt_clog m).comp fa theorem AnalyticWithinAt.clog (fa : AnalyticWithinAt β„‚ f s x) (m : f x ∈ slitPlane) : AnalyticWithinAt β„‚ (fun z ↦ log (f z)) s x := (analyticAt_clog m).comp_analyticWithinAt fa /-- `log` is analytic away from nonpositive reals -/ theorem AnalyticOnNhd.clog (fs : AnalyticOnNhd β„‚ f s) (m : βˆ€ z ∈ s, f z ∈ slitPlane) : AnalyticOnNhd β„‚ (fun z ↦ log (f z)) s := fun z n ↦ (analyticAt_clog (m z n)).comp (fs z n) theorem AnalyticOn.clog (fs : AnalyticOn β„‚ f s) (m : βˆ€ z ∈ s, f z ∈ slitPlane) : AnalyticOn β„‚ (fun z ↦ log (f z)) s := fun z n ↦ (analyticAt_clog (m z n)).analyticWithinAt.comp (fs z n) m /-- `f z ^ g z` is analytic if `f z` is not a nonpositive real -/ theorem AnalyticWithinAt.cpow (fa : AnalyticWithinAt β„‚ f s x) (ga : AnalyticWithinAt β„‚ g s x) (m : f x ∈ slitPlane) : AnalyticWithinAt β„‚ (fun z ↦ f z ^ g z) s x := by have e : (fun z ↦ f z ^ g z) =αΆ [𝓝[insert x s] x] fun z ↦ exp (log (f z) * g z) := by filter_upwards [(fa.continuousWithinAt_insert.eventually_ne (slitPlane_ne_zero m))] intro z fz simp only [fz, cpow_def, if_false] apply AnalyticWithinAt.congr_of_eventuallyEq_insert _ e exact ((fa.clog m).mul ga).cexp /-- `f z ^ g z` is analytic if `f z` is not a nonpositive real -/ @[fun_prop] theorem AnalyticAt.cpow (fa : AnalyticAt β„‚ f x) (ga : AnalyticAt β„‚ g x) (m : f x ∈ slitPlane) : AnalyticAt β„‚ (fun z ↦ f z ^ g z) x := by rw [← analyticWithinAt_univ] at fa ga ⊒ exact fa.cpow ga m /-- `f z ^ g z` is analytic if `f z` avoids nonpositive reals -/ theorem AnalyticOn.cpow (fs : AnalyticOn β„‚ f s) (gs : AnalyticOn β„‚ g s) (m : βˆ€ z ∈ s, f z ∈ slitPlane) : AnalyticOn β„‚ (fun z ↦ f z ^ g z) s := fun z n ↦ (fs z n).cpow (gs z n) (m z n) /-- `f z ^ g z` is analytic if `f z` avoids nonpositive reals -/ theorem AnalyticOnNhd.cpow (fs : AnalyticOnNhd β„‚ f s) (gs : AnalyticOnNhd β„‚ g s) (m : βˆ€ z ∈ s, f z ∈ slitPlane) : AnalyticOnNhd β„‚ (fun z ↦ f z ^ g z) s := fun z n ↦ (fs z n).cpow (gs z n) (m z n) section ReOfReal variable {f : β„‚ β†’ β„‚} {s : Set ℝ} {x : ℝ} @[fun_prop] lemma AnalyticAt.re_ofReal (hf : AnalyticAt β„‚ f x) : AnalyticAt ℝ (fun x : ℝ ↦ (f x).re) x := (Complex.reCLM.analyticAt _).comp (hf.restrictScalars.comp (Complex.ofRealCLM.analyticAt _)) @[fun_prop] lemma AnalyticAt.im_ofReal (hf : AnalyticAt β„‚ f x) : AnalyticAt ℝ (fun x : ℝ ↦ (f x).im) x := (Complex.imCLM.analyticAt _).comp (hf.restrictScalars.comp (Complex.ofRealCLM.analyticAt _)) lemma AnalyticWithinAt.re_ofReal (hf : AnalyticWithinAt β„‚ f (ofReal '' s) x) : AnalyticWithinAt ℝ (fun x : ℝ ↦ (f x).re) s x := ((Complex.reCLM.analyticWithinAt _ _).comp hf.restrictScalars (mapsTo_image f _)).comp (Complex.ofRealCLM.analyticWithinAt _ _) (mapsTo_image ofReal s) lemma AnalyticWithinAt.im_ofReal (hf : AnalyticWithinAt β„‚ f (ofReal '' s) x) : AnalyticWithinAt ℝ (fun x : ℝ ↦ (f x).im) s x := ((Complex.imCLM.analyticWithinAt _ _).comp hf.restrictScalars (mapsTo_image f _)).comp (Complex.ofRealCLM.analyticWithinAt _ _) (mapsTo_image ofReal s) lemma AnalyticOn.re_ofReal (hf : AnalyticOn β„‚ f (ofReal '' s)) : AnalyticOn ℝ (fun x : ℝ ↦ (f x).re) s := ((Complex.reCLM.analyticOn _).comp hf.restrictScalars (mapsTo_image f _)).comp (Complex.ofRealCLM.analyticOn _) (mapsTo_image ofReal s) lemma AnalyticOn.im_ofReal (hf : AnalyticOn β„‚ f (ofReal '' s)) : AnalyticOn ℝ (fun x : ℝ ↦ (f x).im) s := ((Complex.imCLM.analyticOn _).comp hf.restrictScalars (mapsTo_image f _)).comp (Complex.ofRealCLM.analyticOn _) (mapsTo_image ofReal s) lemma AnalyticOnNhd.re_ofReal (hf : AnalyticOnNhd β„‚ f (ofReal '' s)) : AnalyticOnNhd ℝ (fun x : ℝ ↦ (f x).re) s := ((Complex.reCLM.analyticOnNhd _).comp hf.restrictScalars (mapsTo_image f _)).comp (Complex.ofRealCLM.analyticOnNhd _) (mapsTo_image ofReal s) lemma AnalyticOnNhd.im_ofReal (hf : AnalyticOnNhd β„‚ f (ofReal '' s)) : AnalyticOnNhd ℝ (fun x : ℝ ↦ (f x).im) s := ((Complex.imCLM.analyticOnNhd _).comp hf.restrictScalars (mapsTo_image f _)).comp (Complex.ofRealCLM.analyticOnNhd _) (mapsTo_image ofReal s) end ReOfReal section Real variable {f : ℝ β†’ ℝ} {s : Set ℝ} {x : ℝ} @[fun_prop] lemma analyticAt_log (hx : 0 < x) : AnalyticAt ℝ Real.log x := by have : Real.log = fun x : ℝ ↦ (Complex.log x).re := by ext x; exact (Complex.log_ofReal_re x).symm rw [this] refine AnalyticAt.re_ofReal <| analyticAt_clog ?_ simp [hx] lemma analyticOnNhd_log : AnalyticOnNhd ℝ Real.log (Set.Ioi 0) := fun _ hx ↦ analyticAt_log hx lemma analyticOn_log : AnalyticOn ℝ Real.log (Set.Ioi 0) := analyticOnNhd_log.analyticOn @[fun_prop] lemma AnalyticAt.log (fa : AnalyticAt ℝ f x) (m : 0 < f x) : AnalyticAt ℝ (fun z ↦ Real.log (f z)) x := (analyticAt_log m).comp fa lemma AnalyticWithinAt.log (fa : AnalyticWithinAt ℝ f s x) (m : 0 < f x) : AnalyticWithinAt ℝ (fun z ↦ Real.log (f z)) s x := (analyticAt_log m).comp_analyticWithinAt fa lemma AnalyticOnNhd.log (fs : AnalyticOnNhd ℝ f s) (m : βˆ€ x ∈ s, 0 < f x) : AnalyticOnNhd ℝ (fun z ↦ Real.log (f z)) s := fun z n ↦ (analyticAt_log (m z n)).comp (fs z n) lemma AnalyticOn.log (fs : AnalyticOn ℝ f s) (m : βˆ€ x ∈ s, 0 < f x) : AnalyticOn ℝ (fun z ↦ Real.log (f z)) s := fun z n ↦ (analyticAt_log (m z n)).analyticWithinAt.comp (fs z n) m end Real
.lake/packages/mathlib/Mathlib/Analysis/SpecialFunctions/Complex/Arctan.lean
import Mathlib.Analysis.SpecialFunctions.Complex.LogBounds /-! # Complex arctangent This file defines the complex arctangent `Complex.arctan` as $$\arctan z = -\frac i2 \log \frac{1 + zi}{1 - zi}$$ and shows that it extends `Real.arctan` to the complex plane. Its Taylor series expansion $$\arctan z = \frac{(-1)^n}{2n + 1} z^{2n + 1},\ |z|<1$$ is proved in `Complex.hasSum_arctan`. -/ namespace Complex open scoped Real /-- The complex arctangent, defined via the complex logarithm. -/ noncomputable def arctan (z : β„‚) : β„‚ := -I / 2 * log ((1 + z * I) / (1 - z * I)) theorem tan_arctan {z : β„‚} (h₁ : z β‰  I) (hβ‚‚ : z β‰  -I) : tan (arctan z) = z := by unfold tan sin cos rw [div_div_eq_mul_div, div_mul_cancelβ‚€ _ two_ne_zero, ← div_mul_eq_mul_div, -- multiply top and bottom by `exp (arctan z * I)` ← mul_div_mul_right _ _ (exp_ne_zero (arctan z * I)), sub_mul, add_mul, ← exp_add, neg_mul, neg_add_cancel, exp_zero, ← exp_add, ← two_mul] have z₁ : 1 + z * I β‰  0 := by contrapose! h₁ rw [add_eq_zero_iff_neg_eq, ← div_eq_iff I_ne_zero, div_I, neg_one_mul, neg_neg] at h₁ exact h₁.symm have zβ‚‚ : 1 - z * I β‰  0 := by contrapose! hβ‚‚ rw [sub_eq_zero, ← div_eq_iff I_ne_zero, div_I, one_mul] at hβ‚‚ exact hβ‚‚.symm have key : exp (2 * (arctan z * I)) = (1 + z * I) / (1 - z * I) := by rw [arctan, ← mul_rotate, ← mul_assoc, show 2 * (I * (-I / 2)) = 1 by simp [field], one_mul, exp_log] Β· exact div_ne_zero z₁ zβ‚‚ -- multiply top and bottom by `1 - z * I` rw [key, ← mul_div_mul_right _ _ zβ‚‚, sub_mul, add_mul, div_mul_cancelβ‚€ _ zβ‚‚, one_mul, show _ / _ * I = -(I * I) * z by ring, I_mul_I, neg_neg, one_mul] /-- `cos z` is nonzero when the bounds in `arctan_tan` are met (`z` lies in the vertical strip `-Ο€ / 2 < z.re < Ο€ / 2` and `z β‰  Ο€ / 2`). -/ lemma cos_ne_zero_of_arctan_bounds {z : β„‚} (hβ‚€ : z β‰  Ο€ / 2) (h₁ : -(Ο€ / 2) < z.re) (hβ‚‚ : z.re ≀ Ο€ / 2) : cos z β‰  0 := by refine cos_ne_zero_iff.mpr (fun k ↦ ?_) rw [ne_eq, Complex.ext_iff, not_and_or] at hβ‚€ ⊒ norm_cast at hβ‚€ ⊒ rcases hβ‚€ with nr | ni Β· left; contrapose! nr rw [nr, mul_div_assoc, neg_eq_neg_one_mul, mul_lt_mul_iff_of_pos_right (by positivity)] at h₁ rw [nr, ← one_mul (Ο€ / 2), mul_div_assoc, mul_le_mul_iff_of_pos_right (by positivity)] at hβ‚‚ norm_cast at h₁ hβ‚‚ change -1 < _ at h₁ rwa [show 2 * k + 1 = 1 by cutsat, Int.cast_one, one_mul] at nr Β· exact Or.inr ni theorem arctan_tan {z : β„‚} (hβ‚€ : z β‰  Ο€ / 2) (h₁ : -(Ο€ / 2) < z.re) (hβ‚‚ : z.re ≀ Ο€ / 2) : arctan (tan z) = z := by have h := cos_ne_zero_of_arctan_bounds hβ‚€ h₁ hβ‚‚ unfold arctan tan -- multiply top and bottom by `cos z` rw [← mul_div_mul_right (1 + _) _ h, add_mul, sub_mul, one_mul, ← mul_rotate, mul_div_cancelβ‚€ _ h] conv_lhs => enter [2, 1, 2] rw [sub_eq_add_neg, ← neg_mul, ← sin_neg, ← cos_neg] rw [← exp_mul_I, ← exp_mul_I, ← exp_sub, show z * I - -z * I = 2 * (I * z) by ring, log_exp, show -I / 2 * (2 * (I * z)) = -(I * I) * z by ring, I_mul_I, neg_neg, one_mul] all_goals norm_num Β· rwa [← div_lt_iffβ‚€' two_pos, neg_div] Β· rwa [← le_div_iffβ‚€' two_pos] @[simp, norm_cast] theorem ofReal_arctan (x : ℝ) : (Real.arctan x : β„‚) = arctan x := by conv_rhs => rw [← Real.tan_arctan x] rw [ofReal_tan, arctan_tan] all_goals norm_cast Β· rw [← ne_eq]; exact (Real.arctan_lt_pi_div_two _).ne Β· exact Real.neg_pi_div_two_lt_arctan _ Β· exact (Real.arctan_lt_pi_div_two _).le /-- The argument of `1 + z` for `z` in the open unit disc is always in `(-Ο€ / 2, Ο€ / 2)`. -/ lemma arg_one_add_mem_Ioo {z : β„‚} (hz : β€–zβ€– < 1) : (1 + z).arg ∈ Set.Ioo (-(Ο€ / 2)) (Ο€ / 2) := by rw [Set.mem_Ioo, ← abs_lt, abs_arg_lt_pi_div_two_iff, add_re, one_re, ← neg_lt_iff_pos_add'] exact Or.inl (abs_lt.mp ((abs_re_le_norm z).trans_lt hz)).1 /-- We can combine the logs in `log (1 + z * I) + -log (1 - z * I)` into one. This is only used in `hasSum_arctan`. -/ lemma hasSum_arctan_aux {z : β„‚} (hz : β€–zβ€– < 1) : log (1 + z * I) + -log (1 - z * I) = log ((1 + z * I) / (1 - z * I)) := by have z₁ := mem_slitPlane_iff_arg.mp (mem_slitPlane_of_norm_lt_one (z := z * I) (by simpa)) have zβ‚‚ := mem_slitPlane_iff_arg.mp (mem_slitPlane_of_norm_lt_one (z := -(z * I)) (by simpa)) rw [← sub_eq_add_neg] at zβ‚‚ rw [← log_inv _ zβ‚‚.1, ← (log_mul_eq_add_log_iff z₁.2 (inv_eq_zero.ne.mpr zβ‚‚.2)).mpr, div_eq_mul_inv] -- `log_mul_eq_add_log_iff` requires a bound on `arg (1 + z * I) + arg (1 - z * I)⁻¹`. -- `arg_one_add_mem_Ioo` provides sufficiently tight bounds on both terms have b₁ := arg_one_add_mem_Ioo (z := z * I) (by simpa) have bβ‚‚ : arg (1 - z * I)⁻¹ ∈ Set.Ioo (-(Ο€ / 2)) (Ο€ / 2) := by simp_rw [arg_inv, zβ‚‚.1, ite_false, Set.neg_mem_Ioo_iff, neg_neg, sub_eq_add_neg] exact arg_one_add_mem_Ioo (by simpa) have c₁ := add_lt_add b₁.1 bβ‚‚.1 have cβ‚‚ := add_lt_add b₁.2 bβ‚‚.2 rw [show -(Ο€ / 2) + -(Ο€ / 2) = -Ο€ by ring] at c₁ rw [show Ο€ / 2 + Ο€ / 2 = Ο€ by ring] at cβ‚‚ exact ⟨c₁, cβ‚‚.le⟩ /-- The power series expansion of `Complex.arctan`, valid on the open unit disc. -/ theorem hasSum_arctan {z : β„‚} (hz : β€–zβ€– < 1) : HasSum (fun n : β„• ↦ (-1) ^ n * z ^ (2 * n + 1) / ↑(2 * n + 1)) (arctan z) := by have := ((hasSum_taylorSeries_log (z := z * I) (by simpa)).add (hasSum_taylorSeries_neg_log (z := z * I) (by simpa))).mul_left (-I / 2) simp_rw [← add_div, ← add_one_mul, hasSum_arctan_aux hz] at this replace := (Nat.divModEquiv 2).symm.hasSum_iff.mpr this dsimp [Function.comp_def] at this simp_rw [← mul_comm 2 _] at this refine this.prod_fiberwise fun k => ?_ dsimp only convert hasSum_fintype (_ : Fin 2 β†’ β„‚) using 1 rw [Fin.sum_univ_two, Fin.val_zero, Fin.val_one, Odd.neg_one_pow (n := 2 * k + 0 + 1) (by simp), neg_add_cancel, zero_mul, zero_div, mul_zero, zero_add, show 2 * k + 1 + 1 = 2 * (k + 1) by ring, Even.neg_one_pow (n := 2 * (k + 1)) (by simp), ← mul_div_assoc (_ / _), ← mul_assoc, show -I / 2 * (1 + 1) = -I by ring] congr 1 rw [mul_pow, pow_succ' I, pow_mul, I_sq, show -I * _ = -(I * I) * (-1) ^ k * z ^ (2 * k + 1) by ring, I_mul_I, neg_neg, one_mul] end Complex /-- The power series expansion of `Real.arctan`, valid on `-1 < x < 1`. -/ theorem Real.hasSum_arctan {x : ℝ} (hx : β€–xβ€– < 1) : HasSum (fun n : β„• => (-1) ^ n * x ^ (2 * n + 1) / ↑(2 * n + 1)) (arctan x) := mod_cast Complex.hasSum_arctan (z := x) (by simpa)
.lake/packages/mathlib/Mathlib/Analysis/SpecialFunctions/Complex/CircleMap.lean
import Mathlib.Analysis.SpecialFunctions.Complex.Log import Mathlib.Order.Interval.Set.Defs /-! # circleMap This file defines the circle map $ΞΈ ↦ c + R e^{ΞΈi}$, a parametrization of a circle. ## Main definitions * `circleMap c R`: the exponential map $ΞΈ ↦ c + R e^{ΞΈi}$. ## Tags -/ noncomputable section circleMap open Complex Function Metric Real /-- The exponential map $ΞΈ ↦ c + R e^{ΞΈi}$. The range of this map is the circle in `β„‚` with center `c` and radius `|R|`. -/ def circleMap (c : β„‚) (R : ℝ) : ℝ β†’ β„‚ := fun ΞΈ => c + R * exp (ΞΈ * I) @[simp] theorem circleMap_sub_center (c : β„‚) (R : ℝ) (ΞΈ : ℝ) : circleMap c R ΞΈ - c = circleMap 0 R ΞΈ := by simp [circleMap] theorem circleMap_zero (R ΞΈ : ℝ) : circleMap 0 R ΞΈ = R * exp (ΞΈ * I) := zero_add _ @[simp] theorem norm_circleMap_zero (R : ℝ) (ΞΈ : ℝ) : β€–circleMap 0 R ΞΈβ€– = |R| := by simp [circleMap] theorem circleMap_notMem_ball (c : β„‚) (R : ℝ) (ΞΈ : ℝ) : circleMap c R ΞΈ βˆ‰ ball c R := by simp [Complex.dist_eq, le_abs_self] @[deprecated (since := "2025-05-23")] alias circleMap_not_mem_ball := circleMap_notMem_ball theorem circleMap_ne_mem_ball {c : β„‚} {R : ℝ} {w : β„‚} (hw : w ∈ ball c R) (ΞΈ : ℝ) : circleMap c R ΞΈ β‰  w := (ne_of_mem_of_not_mem hw (circleMap_notMem_ball _ _ _)).symm theorem circleMap_mem_sphere' (c : β„‚) (R : ℝ) (ΞΈ : ℝ) : circleMap c R ΞΈ ∈ sphere c |R| := by simp theorem circleMap_mem_sphere (c : β„‚) {R : ℝ} (hR : 0 ≀ R) (ΞΈ : ℝ) : circleMap c R ΞΈ ∈ sphere c R := by simpa only [abs_of_nonneg hR] using circleMap_mem_sphere' c R ΞΈ theorem circleMap_mem_closedBall (c : β„‚) {R : ℝ} (hR : 0 ≀ R) (ΞΈ : ℝ) : circleMap c R ΞΈ ∈ closedBall c R := sphere_subset_closedBall (circleMap_mem_sphere c hR ΞΈ) @[simp] theorem circleMap_eq_center_iff {c : β„‚} {R : ℝ} {ΞΈ : ℝ} : circleMap c R ΞΈ = c ↔ R = 0 := by simp [circleMap, Complex.exp_ne_zero] @[simp] theorem circleMap_zero_radius (c : β„‚) : circleMap c 0 = const ℝ c := funext fun _ => circleMap_eq_center_iff.2 rfl theorem circleMap_ne_center {c : β„‚} {R : ℝ} (hR : R β‰  0) {ΞΈ : ℝ} : circleMap c R ΞΈ β‰  c := mt circleMap_eq_center_iff.1 hR lemma circleMap_zero_mul (R₁ Rβ‚‚ θ₁ ΞΈβ‚‚ : ℝ) : (circleMap 0 R₁ θ₁) * (circleMap 0 Rβ‚‚ ΞΈβ‚‚) = circleMap 0 (R₁ * Rβ‚‚) (θ₁ + ΞΈβ‚‚) := by simp only [circleMap_zero, ofReal_mul, ofReal_add, add_mul, Complex.exp_add] ring lemma circleMap_zero_div (R₁ Rβ‚‚ θ₁ ΞΈβ‚‚ : ℝ) : (circleMap 0 R₁ θ₁) / (circleMap 0 Rβ‚‚ ΞΈβ‚‚) = circleMap 0 (R₁ / Rβ‚‚) (θ₁ - ΞΈβ‚‚) := by simp only [circleMap_zero, ofReal_div, ofReal_sub, sub_mul, Complex.exp_sub] ring lemma circleMap_zero_inv (R ΞΈ : ℝ) : (circleMap 0 R ΞΈ)⁻¹ = circleMap 0 R⁻¹ (-ΞΈ) := by simp [circleMap_zero, Complex.exp_neg, mul_comm] lemma circleMap_zero_pow (n : β„•) (R ΞΈ : ℝ) : (circleMap 0 R ΞΈ) ^ n = circleMap 0 (R ^ n) (n * ΞΈ) := by simp [circleMap_zero, mul_pow, ← Complex.exp_nat_mul, ← mul_assoc] lemma circleMap_zero_zpow (n : β„€) (R ΞΈ : ℝ) : (circleMap 0 R ΞΈ) ^ n = circleMap 0 (R ^ n) (n * ΞΈ) := by simp [circleMap_zero, mul_zpow, ← exp_int_mul, ← mul_assoc] lemma circleMap_pi_div_two (c : β„‚) (R : ℝ) : circleMap c R (Ο€ / 2) = c + R * I := by simp only [circleMap, ofReal_div, ofReal_ofNat, exp_pi_div_two_mul_I] lemma circleMap_neg_pi_div_two (c : β„‚) (R : ℝ) : circleMap c R (-Ο€ / 2) = c - R * I := by simp only [circleMap, ofReal_div, ofReal_neg, ofReal_ofNat, exp_neg_pi_div_two_mul_I, mul_neg, sub_eq_add_neg] /-- `circleMap` is `2Ο€`-periodic. -/ theorem periodic_circleMap (c : β„‚) (R : ℝ) : Periodic (circleMap c R) (2 * Ο€) := fun ΞΈ => by simp [circleMap, add_mul, exp_periodic _] theorem Set.Countable.preimage_circleMap {s : Set β„‚} (hs : s.Countable) (c : β„‚) {R : ℝ} (hR : R β‰  0) : (circleMap c R ⁻¹' s).Countable := show (((↑) : ℝ β†’ β„‚) ⁻¹' ((Β· * I) ⁻¹' (exp ⁻¹' ((R * Β·) ⁻¹' ((c + Β·) ⁻¹' s))))).Countable from (((hs.preimage (add_right_injective _)).preimage <| mul_right_injectiveβ‚€ <| ofReal_ne_zero.2 hR).preimage_cexp.preimage <| mul_left_injectiveβ‚€ I_ne_zero).preimage ofReal_injective lemma circleMap_eq_circleMap_iff {a b R : ℝ} (c : β„‚) (h_R : R β‰  0) : circleMap c R a = circleMap c R b ↔ βˆƒ (n : β„€), a * I = b * I + n * (2 * Ο€ * I) := by have : circleMap c R a = circleMap c R b ↔ (exp (a * I)).arg = (exp (b * I)).arg := by simp [circleMap, ext_norm_arg_iff, h_R] simp [this, arg_eq_arg_iff, exp_eq_exp_iff_exists_int] lemma eq_of_circleMap_eq {a b R : ℝ} {c : β„‚} (h_R : R β‰  0) (h_dist : |a - b| < 2 * Ο€) (h : circleMap c R a = circleMap c R b) : a = b := by rw [circleMap_eq_circleMap_iff c h_R] at h obtain ⟨n, hn⟩ := h simp only [show n * (2 * Ο€ * I) = (n * 2 * Ο€) * I by ring, ← add_mul, mul_eq_mul_right_iff, I_ne_zero, or_false] at hn norm_cast at hn simp only [hn, Int.cast_mul, Int.cast_ofNat, mul_assoc, add_sub_cancel_left, abs_mul, Nat.abs_ofNat, abs_of_pos Real.pi_pos] at h_dist simp (disch := positivity) at h_dist norm_cast at h_dist simp [hn, Int.abs_lt_one_iff.mp h_dist] open scoped Interval in /-- `circleMap` is injective on `Ξ™ a b` if the distance between `a` and `b` is at most `2Ο€`. -/ theorem injOn_circleMap_of_abs_sub_le {a b R : ℝ} {c : β„‚} (h_R : R β‰  0) (_ : |a - b| ≀ 2 * Ο€) : (Ξ™ a b).InjOn (circleMap c R) := by rintro _ ⟨_, _⟩ _ ⟨_, _⟩ h apply eq_of_circleMap_eq h_R _ h rw [abs_lt] constructor <;> linarith [max_sub_min_eq_abs' a b] /-- `circleMap` is injective on `Ico a b` if the distance between `a` and `b` is at most `2Ο€`. -/ theorem injOn_circleMap_of_abs_sub_le' {a b R : ℝ} {c : β„‚} (h_R : R β‰  0) (_ : b - a ≀ 2 * Ο€) : (Set.Ico a b).InjOn (circleMap c R) := by rintro _ ⟨_, _⟩ _ ⟨_, _⟩ h apply eq_of_circleMap_eq h_R _ h rw [abs_lt] constructor <;> linarith end circleMap
.lake/packages/mathlib/Mathlib/Analysis/SpecialFunctions/Complex/Arg.lean
import Mathlib.Analysis.SpecialFunctions.Trigonometric.Angle import Mathlib.Analysis.SpecialFunctions.Trigonometric.Inverse /-! # The argument of a complex number. We define `arg : β„‚ β†’ ℝ`, returning a real number in the range (-Ο€, Ο€], such that for `x β‰  0`, `sin (arg x) = x.im / x.abs` and `cos (arg x) = x.re / x.abs`, while `arg 0` defaults to `0` -/ open Filter Metric Set open scoped ComplexConjugate Real Topology namespace Complex variable {a x z : β„‚} /-- `arg` returns values in the range (-Ο€, Ο€], such that for `x β‰  0`, `sin (arg x) = x.im / x.abs` and `cos (arg x) = x.re / x.abs`, `arg 0` defaults to `0` -/ noncomputable def arg (x : β„‚) : ℝ := if 0 ≀ x.re then Real.arcsin (x.im / β€–xβ€–) else if 0 ≀ x.im then Real.arcsin ((-x).im / β€–xβ€–) + Ο€ else Real.arcsin ((-x).im / β€–xβ€–) - Ο€ theorem sin_arg (x : β„‚) : Real.sin (arg x) = x.im / β€–xβ€– := by unfold arg; split_ifs <;> simp [sub_eq_add_neg, Real.sin_arcsin (abs_le.1 (abs_im_div_norm_le_one x)).1 (abs_le.1 (abs_im_div_norm_le_one x)).2, Real.sin_add, neg_div, Real.arcsin_neg, Real.sin_neg] theorem cos_arg {x : β„‚} (hx : x β‰  0) : Real.cos (arg x) = x.re / β€–xβ€– := by rw [arg] split_ifs with h₁ hβ‚‚ Β· rw [Real.cos_arcsin] field_simp simp [Real.sqrt_sq, (norm_pos_iff.mpr hx).le, *] field Β· rw [Real.cos_add_pi, Real.cos_arcsin] field_simp simp [Real.sqrt_div (sq_nonneg _), Real.sqrt_sq_eq_abs, _root_.abs_of_neg (not_le.1 h₁), *] field Β· rw [Real.cos_sub_pi, Real.cos_arcsin] field_simp simp [Real.sqrt_div (sq_nonneg _), Real.sqrt_sq_eq_abs, _root_.abs_of_neg (not_le.1 h₁), *] field @[simp] theorem norm_mul_exp_arg_mul_I (x : β„‚) : β€–xβ€– * exp (arg x * I) = x := by rcases eq_or_ne x 0 with (rfl | hx) Β· simp Β· have : β€–xβ€– β‰  0 := norm_ne_zero_iff.mpr hx apply Complex.ext <;> simp [sin_arg, cos_arg hx, this, mul_comm β€–xβ€–] @[simp] theorem norm_mul_cos_add_sin_mul_I (x : β„‚) : (β€–xβ€– * (cos (arg x) + sin (arg x) * I) : β„‚) = x := by rw [← exp_mul_I, norm_mul_exp_arg_mul_I] @[simp] lemma norm_mul_cos_arg (x : β„‚) : β€–xβ€– * Real.cos (arg x) = x.re := by simpa [-norm_mul_cos_add_sin_mul_I] using congr_arg re (norm_mul_cos_add_sin_mul_I x) @[simp] lemma norm_mul_sin_arg (x : β„‚) : β€–xβ€– * Real.sin (arg x) = x.im := by simpa [-norm_mul_cos_add_sin_mul_I] using congr_arg im (norm_mul_cos_add_sin_mul_I x) theorem norm_eq_one_iff (z : β„‚) : β€–zβ€– = 1 ↔ βˆƒ ΞΈ : ℝ, exp (ΞΈ * I) = z := by refine ⟨fun hz => ⟨arg z, ?_⟩, ?_⟩ Β· calc exp (arg z * I) = β€–zβ€– * exp (arg z * I) := by rw [hz, ofReal_one, one_mul] _ = z :=norm_mul_exp_arg_mul_I z Β· rintro ⟨θ, rfl⟩ exact Complex.norm_exp_ofReal_mul_I ΞΈ @[simp] theorem range_exp_mul_I : (Set.range fun x : ℝ => exp (x * I)) = Metric.sphere 0 1 := by ext x simp only [mem_sphere_zero_iff_norm, norm_eq_one_iff, Set.mem_range] theorem arg_mul_cos_add_sin_mul_I {r : ℝ} (hr : 0 < r) {ΞΈ : ℝ} (hΞΈ : ΞΈ ∈ Set.Ioc (-Ο€) Ο€) : arg (r * (cos ΞΈ + sin ΞΈ * I)) = ΞΈ := by simp only [arg, norm_mul, norm_cos_add_sin_mul_I, Complex.norm_of_nonneg hr.le, mul_one] simp only [re_ofReal_mul, im_ofReal_mul, neg_im, ← ofReal_cos, ← ofReal_sin, ← mk_eq_add_mul_I, neg_div, mul_div_cancel_leftβ‚€ _ hr.ne', mul_nonneg_iff_right_nonneg_of_pos hr] by_cases h₁ : ΞΈ ∈ Set.Icc (-(Ο€ / 2)) (Ο€ / 2) Β· rw [if_pos] exacts [Real.arcsin_sin' h₁, Real.cos_nonneg_of_mem_Icc h₁] Β· rw [Set.mem_Icc, not_and_or, not_le, not_le] at h₁ rcases h₁ with h₁ | h₁ Β· replace hΞΈ := hΞΈ.1 have hcos : Real.cos ΞΈ < 0 := by rw [← neg_pos, ← Real.cos_add_pi] refine Real.cos_pos_of_mem_Ioo ⟨?_, ?_⟩ <;> linarith have hsin : Real.sin ΞΈ < 0 := Real.sin_neg_of_neg_of_neg_pi_lt (by linarith) hΞΈ rw [if_neg, if_neg, ← Real.sin_add_pi, Real.arcsin_sin, add_sub_cancel_right] <;> [linarith; linarith; exact hsin.not_ge; exact hcos.not_ge] Β· replace hΞΈ := hΞΈ.2 have hcos : Real.cos ΞΈ < 0 := Real.cos_neg_of_pi_div_two_lt_of_lt h₁ (by linarith) have hsin : 0 ≀ Real.sin ΞΈ := Real.sin_nonneg_of_mem_Icc ⟨by linarith, hθ⟩ rw [if_neg, if_pos, ← Real.sin_sub_pi, Real.arcsin_sin, sub_add_cancel] <;> [linarith; linarith; exact hsin; exact hcos.not_ge] theorem arg_cos_add_sin_mul_I {ΞΈ : ℝ} (hΞΈ : ΞΈ ∈ Set.Ioc (-Ο€) Ο€) : arg (cos ΞΈ + sin ΞΈ * I) = ΞΈ := by rw [← one_mul (_ + _), ← ofReal_one, arg_mul_cos_add_sin_mul_I zero_lt_one hΞΈ] lemma arg_exp_mul_I (ΞΈ : ℝ) : arg (exp (ΞΈ * I)) = toIocMod (mul_pos two_pos Real.pi_pos) (-Ο€) ΞΈ := by convert arg_cos_add_sin_mul_I (ΞΈ := toIocMod (mul_pos two_pos Real.pi_pos) (-Ο€) ΞΈ) _ using 2 Β· rw [← exp_mul_I, eq_sub_of_add_eq <| toIocMod_add_toIocDiv_zsmul _ _ ΞΈ, ofReal_sub, ofReal_zsmul, ofReal_mul, ofReal_ofNat, exp_mul_I_periodic.sub_zsmul_eq] Β· convert toIocMod_mem_Ioc _ _ _ ring @[simp] theorem arg_zero : arg 0 = 0 := by simp [arg, le_refl] theorem ext_norm_arg {x y : β„‚} (h₁ : β€–xβ€– = β€–yβ€–) (hβ‚‚ : x.arg = y.arg) : x = y := by rw [← norm_mul_exp_arg_mul_I x, ← norm_mul_exp_arg_mul_I y, h₁, hβ‚‚] theorem ext_norm_arg_iff {x y : β„‚} : x = y ↔ β€–xβ€– = β€–yβ€– ∧ arg x = arg y := ⟨fun h => h β–Έ ⟨rfl, rfl⟩, and_imp.2 ext_norm_arg⟩ theorem arg_mem_Ioc (z : β„‚) : arg z ∈ Set.Ioc (-Ο€) Ο€ := by have hΟ€ : 0 < Ο€ := Real.pi_pos rcases eq_or_ne z 0 with (rfl | hz) Β· simp [hΟ€, hΟ€.le] rcases existsUnique_add_zsmul_mem_Ioc Real.two_pi_pos (arg z) (-Ο€) with ⟨N, hN, -⟩ rw [two_mul, neg_add_cancel_left, ← two_mul, zsmul_eq_mul] at hN rw [← norm_mul_cos_add_sin_mul_I z, ← cos_add_int_mul_two_pi _ N, ← sin_add_int_mul_two_pi _ N] have := arg_mul_cos_add_sin_mul_I (norm_pos_iff.mpr hz) hN push_cast at this rwa [this] @[simp] theorem range_arg : Set.range arg = Set.Ioc (-Ο€) Ο€ := (Set.range_subset_iff.2 arg_mem_Ioc).antisymm fun _ hx => ⟨_, arg_cos_add_sin_mul_I hx⟩ theorem arg_le_pi (x : β„‚) : arg x ≀ Ο€ := (arg_mem_Ioc x).2 theorem neg_pi_lt_arg (x : β„‚) : -Ο€ < arg x := (arg_mem_Ioc x).1 theorem abs_arg_le_pi (z : β„‚) : |arg z| ≀ Ο€ := abs_le.2 ⟨(neg_pi_lt_arg z).le, arg_le_pi z⟩ @[simp] theorem arg_nonneg_iff {z : β„‚} : 0 ≀ arg z ↔ 0 ≀ z.im := by rcases eq_or_ne z 0 with (rfl | hβ‚€); Β· simp calc 0 ≀ arg z ↔ 0 ≀ Real.sin (arg z) := ⟨fun h => Real.sin_nonneg_of_mem_Icc ⟨h, arg_le_pi z⟩, by contrapose! intro h exact Real.sin_neg_of_neg_of_neg_pi_lt h (neg_pi_lt_arg _)⟩ _ ↔ _ := by rw [sin_arg, le_div_iffβ‚€ (norm_pos_iff.mpr hβ‚€), zero_mul] @[simp] theorem arg_neg_iff {z : β„‚} : arg z < 0 ↔ z.im < 0 := lt_iff_lt_of_le_iff_le arg_nonneg_iff theorem arg_real_mul (x : β„‚) {r : ℝ} (hr : 0 < r) : arg (r * x) = arg x := by rcases eq_or_ne x 0 with (rfl | hx); Β· rw [mul_zero] conv_lhs => rw [← norm_mul_cos_add_sin_mul_I x, ← mul_assoc, ← ofReal_mul, arg_mul_cos_add_sin_mul_I (mul_pos hr (norm_pos_iff.mpr hx)) x.arg_mem_Ioc] theorem arg_mul_real {r : ℝ} (hr : 0 < r) (x : β„‚) : arg (x * r) = arg x := mul_comm x r β–Έ arg_real_mul x hr theorem arg_eq_arg_iff {x y : β„‚} (hx : x β‰  0) (hy : y β‰  0) : arg x = arg y ↔ (β€–yβ€– / β€–xβ€– : β„‚) * x = y := by simp only [ext_norm_arg_iff, norm_mul, norm_div, norm_real, norm_norm, div_mul_cancelβ‚€ _ (norm_ne_zero_iff.mpr hx), true_and] rw [← ofReal_div, arg_real_mul] exact div_pos (norm_pos_iff.mpr hy) (norm_pos_iff.mpr hx) @[simp] lemma arg_one : arg 1 = 0 := by simp [arg, zero_le_one] /-- This holds true for all `x : β„‚` because of the junk values `0 / 0 = 0` and `arg 0 = 0`. -/ @[simp] lemma arg_div_self (x : β„‚) : arg (x / x) = 0 := by obtain rfl | hx := eq_or_ne x 0 <;> simp [*] @[simp] theorem arg_neg_one : arg (-1) = Ο€ := by simp [arg, le_refl, not_le.2 (zero_lt_one' ℝ)] @[simp] theorem arg_I : arg I = Ο€ / 2 := by simp [arg, le_refl] @[simp] theorem arg_neg_I : arg (-I) = -(Ο€ / 2) := by simp [arg, le_refl] @[simp] theorem tan_arg (x : β„‚) : Real.tan (arg x) = x.im / x.re := by by_cases h : x = 0 Β· simp only [h, zero_div, Complex.zero_im, Complex.arg_zero, Real.tan_zero, Complex.zero_re] rw [Real.tan_eq_sin_div_cos, sin_arg, cos_arg h, div_div_div_cancel_rightβ‚€ (norm_ne_zero_iff.mpr h)] theorem arg_ofReal_of_nonneg {x : ℝ} (hx : 0 ≀ x) : arg x = 0 := by simp [arg, hx] @[simp, norm_cast] lemma natCast_arg {n : β„•} : arg n = 0 := ofReal_natCast n β–Έ arg_ofReal_of_nonneg n.cast_nonneg @[simp] lemma ofNat_arg {n : β„•} [n.AtLeastTwo] : arg ofNat(n) = 0 := natCast_arg theorem arg_eq_zero_iff {z : β„‚} : arg z = 0 ↔ 0 ≀ z.re ∧ z.im = 0 := by refine ⟨fun h => ?_, ?_⟩ Β· rw [← norm_mul_cos_add_sin_mul_I z, h] simp [norm_nonneg] Β· obtain ⟨x, y⟩ := z rintro ⟨h, rfl : y = 0⟩ exact arg_ofReal_of_nonneg h open ComplexOrder in lemma arg_eq_zero_iff_zero_le {z : β„‚} : arg z = 0 ↔ 0 ≀ z := by rw [arg_eq_zero_iff, eq_comm, nonneg_iff] theorem arg_eq_pi_iff {z : β„‚} : arg z = Ο€ ↔ z.re < 0 ∧ z.im = 0 := by by_cases hβ‚€ : z = 0 Β· simp [hβ‚€, Real.pi_ne_zero.symm] constructor Β· intro h rw [← norm_mul_cos_add_sin_mul_I z, h] simp [hβ‚€] Β· obtain ⟨x, y⟩ := z rintro ⟨h : x < 0, rfl : y = 0⟩ rw [← arg_neg_one, ← arg_real_mul (-1) (neg_pos.2 h)] simp [← ofReal_def] open ComplexOrder in lemma arg_eq_pi_iff_lt_zero {z : β„‚} : arg z = Ο€ ↔ z < 0 := arg_eq_pi_iff theorem arg_lt_pi_iff {z : β„‚} : arg z < Ο€ ↔ 0 ≀ z.re ∨ z.im β‰  0 := by rw [(arg_le_pi z).lt_iff_ne, not_iff_comm, not_or, not_le, Classical.not_not, arg_eq_pi_iff] theorem arg_ofReal_of_neg {x : ℝ} (hx : x < 0) : arg x = Ο€ := arg_eq_pi_iff.2 ⟨hx, rfl⟩ theorem arg_eq_pi_div_two_iff {z : β„‚} : arg z = Ο€ / 2 ↔ z.re = 0 ∧ 0 < z.im := by by_cases hβ‚€ : z = 0; Β· simp [hβ‚€, Real.pi_div_two_pos.ne] constructor Β· intro h rw [← norm_mul_cos_add_sin_mul_I z, h] simp [hβ‚€] Β· obtain ⟨x, y⟩ := z rintro ⟨rfl : x = 0, hy : 0 < y⟩ rw [← arg_I, ← arg_real_mul I hy, ofReal_mul', I_re, I_im, mul_zero, mul_one] theorem arg_eq_neg_pi_div_two_iff {z : β„‚} : arg z = -(Ο€ / 2) ↔ z.re = 0 ∧ z.im < 0 := by by_cases hβ‚€ : z = 0; Β· simp [hβ‚€, Real.pi_ne_zero] constructor Β· intro h rw [← norm_mul_cos_add_sin_mul_I z, h] simp [hβ‚€] Β· obtain ⟨x, y⟩ := z rintro ⟨rfl : x = 0, hy : y < 0⟩ rw [← arg_neg_I, ← arg_real_mul (-I) (neg_pos.2 hy), mk_eq_add_mul_I] simp theorem arg_of_re_nonneg {x : β„‚} (hx : 0 ≀ x.re) : arg x = Real.arcsin (x.im / β€–xβ€–) := if_pos hx theorem arg_of_re_neg_of_im_nonneg {x : β„‚} (hx_re : x.re < 0) (hx_im : 0 ≀ x.im) : arg x = Real.arcsin ((-x).im / β€–xβ€–) + Ο€ := by simp only [arg, hx_re.not_ge, hx_im, if_true, if_false] theorem arg_of_re_neg_of_im_neg {x : β„‚} (hx_re : x.re < 0) (hx_im : x.im < 0) : arg x = Real.arcsin ((-x).im / β€–xβ€–) - Ο€ := by simp only [arg, hx_re.not_ge, hx_im.not_ge, if_false] theorem arg_of_im_nonneg_of_ne_zero {z : β„‚} (h₁ : 0 ≀ z.im) (hβ‚‚ : z β‰  0) : arg z = Real.arccos (z.re / β€–zβ€–) := by rw [← cos_arg hβ‚‚, Real.arccos_cos (arg_nonneg_iff.2 h₁) (arg_le_pi _)] theorem arg_of_im_pos {z : β„‚} (hz : 0 < z.im) : arg z = Real.arccos (z.re / β€–zβ€–) := arg_of_im_nonneg_of_ne_zero hz.le fun h => hz.ne' <| h.symm β–Έ rfl theorem arg_of_im_neg {z : β„‚} (hz : z.im < 0) : arg z = -Real.arccos (z.re / β€–zβ€–) := by have hβ‚€ : z β‰  0 := mt (congr_arg im) hz.ne rw [← cos_arg hβ‚€, ← Real.cos_neg, Real.arccos_cos, neg_neg] exacts [neg_nonneg.2 (arg_neg_iff.2 hz).le, neg_le.2 (neg_pi_lt_arg z).le] theorem arg_conj (x : β„‚) : arg (conj x) = if arg x = Ο€ then Ο€ else -arg x := by simp_rw [arg_eq_pi_iff, arg, neg_im, conj_im, conj_re, norm_conj, neg_div, neg_neg, Real.arcsin_neg] rcases lt_trichotomy x.re 0 with (hr | hr | hr) <;> rcases lt_trichotomy x.im 0 with (hi | hi | hi) Β· simp [hr, hr.not_ge, hi.le, hi.ne, not_le.2 hi, add_comm] Β· simp [hr, hr.not_ge, hi] Β· simp [hr, hr.not_ge, hi.ne.symm, hi.le, not_le.2 hi, sub_eq_neg_add] Β· simp [hr] Β· simp [hr] Β· simp [hr] Β· simp [hr.le, hi.ne] Β· simp [hr.le, hr.le.not_gt] Β· simp [hr.le, hr.le.not_gt] theorem arg_inv (x : β„‚) : arg x⁻¹ = if arg x = Ο€ then Ο€ else -arg x := by rw [← arg_conj, inv_def, mul_comm] by_cases hx : x = 0 Β· simp [hx] Β· exact arg_real_mul (conj x) (by simp [hx]) @[simp] lemma abs_arg_inv (x : β„‚) : |x⁻¹.arg| = |x.arg| := by rw [arg_inv]; split_ifs <;> simp [*] -- TODO: Replace the next two lemmas by general facts about periodic functions lemma norm_eq_one_iff' : β€–xβ€– = 1 ↔ βˆƒ ΞΈ ∈ Set.Ioc (-Ο€) Ο€, exp (ΞΈ * I) = x := by rw [norm_eq_one_iff] constructor Β· rintro ⟨θ, rfl⟩ refine ⟨toIocMod (mul_pos two_pos Real.pi_pos) (-Ο€) ΞΈ, ?_, ?_⟩ Β· convert toIocMod_mem_Ioc _ _ _ ring Β· rw [eq_sub_of_add_eq <| toIocMod_add_toIocDiv_zsmul _ _ ΞΈ, ofReal_sub, ofReal_zsmul, ofReal_mul, ofReal_ofNat, exp_mul_I_periodic.sub_zsmul_eq] Β· rintro ⟨θ, _, rfl⟩ exact ⟨θ, rfl⟩ lemma image_exp_Ioc_eq_sphere : (fun ΞΈ : ℝ ↦ exp (ΞΈ * I)) '' Set.Ioc (-Ο€) Ο€ = sphere 0 1 := by ext; simpa using norm_eq_one_iff'.symm theorem arg_le_pi_div_two_iff {z : β„‚} : arg z ≀ Ο€ / 2 ↔ 0 ≀ re z ∨ im z < 0 := by rcases le_or_gt 0 (re z) with hre | hre Β· simp only [hre, arg_of_re_nonneg hre, Real.arcsin_le_pi_div_two, true_or] simp only [hre.not_ge, false_or] rcases le_or_gt 0 (im z) with him | him Β· simp only [him.not_gt] rw [iff_false, not_le, arg_of_re_neg_of_im_nonneg hre him, ← sub_lt_iff_lt_add, half_sub, Real.neg_pi_div_two_lt_arcsin, neg_im, neg_div, neg_lt_neg_iff, div_lt_one, ← abs_of_nonneg him, abs_im_lt_norm] exacts [hre.ne, norm_pos_iff.mpr <| ne_of_apply_ne re hre.ne] Β· simp only [him] rw [iff_true, arg_of_re_neg_of_im_neg hre him] exact (sub_le_self _ Real.pi_pos.le).trans (Real.arcsin_le_pi_div_two _) theorem neg_pi_div_two_le_arg_iff {z : β„‚} : -(Ο€ / 2) ≀ arg z ↔ 0 ≀ re z ∨ 0 ≀ im z := by rcases le_or_gt 0 (re z) with hre | hre Β· simp only [hre, arg_of_re_nonneg hre, Real.neg_pi_div_two_le_arcsin, true_or] simp only [hre.not_ge, false_or] rcases le_or_gt 0 (im z) with him | him Β· simp only [him] rw [iff_true, arg_of_re_neg_of_im_nonneg hre him] exact (Real.neg_pi_div_two_le_arcsin _).trans (le_add_of_nonneg_right Real.pi_pos.le) Β· simp only [him.not_ge] rw [iff_false, not_le, arg_of_re_neg_of_im_neg hre him, sub_lt_iff_lt_add', ← sub_eq_add_neg, sub_half, Real.arcsin_lt_pi_div_two, div_lt_one, neg_im, ← abs_of_neg him, abs_im_lt_norm] exacts [hre.ne, norm_pos_iff.mpr <| ne_of_apply_ne re hre.ne] lemma neg_pi_div_two_lt_arg_iff {z : β„‚} : -(Ο€ / 2) < arg z ↔ 0 < re z ∨ 0 ≀ im z := by rw [lt_iff_le_and_ne, neg_pi_div_two_le_arg_iff, ne_comm, Ne, arg_eq_neg_pi_div_two_iff] rcases lt_trichotomy z.re 0 with hre | hre | hre Β· simp [hre.ne, hre.not_ge, hre.not_gt] Β· simp [hre] Β· simp [hre, hre.le, hre.ne'] lemma arg_lt_pi_div_two_iff {z : β„‚} : arg z < Ο€ / 2 ↔ 0 < re z ∨ im z < 0 ∨ z = 0 := by rw [lt_iff_le_and_ne, arg_le_pi_div_two_iff, Ne, arg_eq_pi_div_two_iff] rcases lt_trichotomy z.re 0 with hre | hre | hre Β· have : z β‰  0 := by simp [Complex.ext_iff, hre.ne] simp [hre.ne, hre.not_ge, hre.not_gt, this] Β· have : z = 0 ↔ z.im = 0 := by simp [Complex.ext_iff, hre] simp [hre, this, or_comm, le_iff_eq_or_lt] Β· simp [hre, hre.le, hre.ne'] @[simp] theorem abs_arg_le_pi_div_two_iff {z : β„‚} : |arg z| ≀ Ο€ / 2 ↔ 0 ≀ re z := by rw [abs_le, arg_le_pi_div_two_iff, neg_pi_div_two_le_arg_iff, ← or_and_left, ← not_le, and_not_self_iff, or_false] @[simp] theorem abs_arg_lt_pi_div_two_iff {z : β„‚} : |arg z| < Ο€ / 2 ↔ 0 < re z ∨ z = 0 := by rw [abs_lt, arg_lt_pi_div_two_iff, neg_pi_div_two_lt_arg_iff, ← or_and_left] rcases eq_or_ne z 0 with hz | hz Β· simp [hz] Β· simp_rw [hz, or_false, ← not_lt, not_and_self_iff, or_false] @[simp] theorem arg_conj_coe_angle (x : β„‚) : (arg (conj x) : Real.Angle) = -arg x := by by_cases h : arg x = Ο€ <;> simp [arg_conj, h] @[simp] theorem arg_inv_coe_angle (x : β„‚) : (arg x⁻¹ : Real.Angle) = -arg x := by by_cases h : arg x = Ο€ <;> simp [arg_inv, h] theorem arg_neg_eq_arg_sub_pi_of_im_pos {x : β„‚} (hi : 0 < x.im) : arg (-x) = arg x - Ο€ := by rw [arg_of_im_pos hi, arg_of_im_neg (show (-x).im < 0 from Left.neg_neg_iff.2 hi)] simp [neg_div, Real.arccos_neg] theorem arg_neg_eq_arg_add_pi_of_im_neg {x : β„‚} (hi : x.im < 0) : arg (-x) = arg x + Ο€ := by rw [arg_of_im_neg hi, arg_of_im_pos (show 0 < (-x).im from Left.neg_pos_iff.2 hi)] simp [neg_div, Real.arccos_neg, add_comm, ← sub_eq_add_neg] theorem arg_neg_eq_arg_sub_pi_iff {x : β„‚} : arg (-x) = arg x - Ο€ ↔ 0 < x.im ∨ x.im = 0 ∧ x.re < 0 := by rcases lt_trichotomy x.im 0 with (hi | hi | hi) Β· simp [hi, hi.ne, hi.not_gt, arg_neg_eq_arg_add_pi_of_im_neg, sub_eq_add_neg, ← add_eq_zero_iff_eq_neg, Real.pi_ne_zero] Β· rw [(ext rfl hi : x = x.re)] rcases lt_trichotomy x.re 0 with (hr | hr | hr) Β· rw [arg_ofReal_of_neg hr, ← ofReal_neg, arg_ofReal_of_nonneg (Left.neg_pos_iff.2 hr).le] simp [hr] Β· simp [hr, Real.pi_ne_zero] Β· rw [arg_ofReal_of_nonneg hr.le, ← ofReal_neg, arg_ofReal_of_neg (Left.neg_neg_iff.2 hr)] simp [hr.not_gt, ← add_eq_zero_iff_eq_neg, Real.pi_ne_zero] Β· simp [hi, arg_neg_eq_arg_sub_pi_of_im_pos] theorem arg_neg_eq_arg_add_pi_iff {x : β„‚} : arg (-x) = arg x + Ο€ ↔ x.im < 0 ∨ x.im = 0 ∧ 0 < x.re := by rcases lt_trichotomy x.im 0 with (hi | hi | hi) Β· simp [hi, arg_neg_eq_arg_add_pi_of_im_neg] Β· rw [(ext rfl hi : x = x.re)] rcases lt_trichotomy x.re 0 with (hr | hr | hr) Β· rw [arg_ofReal_of_neg hr, ← ofReal_neg, arg_ofReal_of_nonneg (Left.neg_pos_iff.2 hr).le] simp [hr.not_gt, ← two_mul, Real.pi_ne_zero] Β· simp [hr, Real.pi_ne_zero.symm] Β· rw [arg_ofReal_of_nonneg hr.le, ← ofReal_neg, arg_ofReal_of_neg (Left.neg_neg_iff.2 hr)] simp [hr] Β· simp [hi, hi.ne.symm, hi.not_gt, arg_neg_eq_arg_sub_pi_of_im_pos, sub_eq_add_neg, ← add_eq_zero_iff_neg_eq, Real.pi_ne_zero] theorem arg_neg_coe_angle {x : β„‚} (hx : x β‰  0) : (arg (-x) : Real.Angle) = arg x + Ο€ := by rcases lt_trichotomy x.im 0 with (hi | hi | hi) Β· rw [arg_neg_eq_arg_add_pi_of_im_neg hi, Real.Angle.coe_add] Β· rw [(ext rfl hi : x = x.re)] rcases lt_trichotomy x.re 0 with (hr | hr | hr) Β· rw [arg_ofReal_of_neg hr, ← ofReal_neg, arg_ofReal_of_nonneg (Left.neg_pos_iff.2 hr).le, ← Real.Angle.coe_add, ← two_mul, Real.Angle.coe_two_pi, Real.Angle.coe_zero] Β· exact False.elim (hx (ext hr hi)) Β· rw [arg_ofReal_of_nonneg hr.le, ← ofReal_neg, arg_ofReal_of_neg (Left.neg_neg_iff.2 hr), Real.Angle.coe_zero, zero_add] Β· rw [arg_neg_eq_arg_sub_pi_of_im_pos hi, Real.Angle.coe_sub, Real.Angle.sub_coe_pi_eq_add_coe_pi] theorem arg_mul_cos_add_sin_mul_I_eq_toIocMod {r : ℝ} (hr : 0 < r) (ΞΈ : ℝ) : arg (r * (cos ΞΈ + sin ΞΈ * I)) = toIocMod Real.two_pi_pos (-Ο€) ΞΈ := by have hi : toIocMod Real.two_pi_pos (-Ο€) ΞΈ ∈ Set.Ioc (-Ο€) Ο€ := by convert toIocMod_mem_Ioc _ _ ΞΈ ring convert arg_mul_cos_add_sin_mul_I hr hi using 3 simp [toIocMod, cos_sub_int_mul_two_pi, sin_sub_int_mul_two_pi] theorem arg_cos_add_sin_mul_I_eq_toIocMod (ΞΈ : ℝ) : arg (cos ΞΈ + sin ΞΈ * I) = toIocMod Real.two_pi_pos (-Ο€) ΞΈ := by rw [← one_mul (_ + _), ← ofReal_one, arg_mul_cos_add_sin_mul_I_eq_toIocMod zero_lt_one] theorem arg_mul_cos_add_sin_mul_I_sub {r : ℝ} (hr : 0 < r) (ΞΈ : ℝ) : arg (r * (cos ΞΈ + sin ΞΈ * I)) - ΞΈ = 2 * Ο€ * ⌊(Ο€ - ΞΈ) / (2 * Ο€)βŒ‹ := by rw [arg_mul_cos_add_sin_mul_I_eq_toIocMod hr, toIocMod_sub_self, toIocDiv_eq_neg_floor, zsmul_eq_mul] ring_nf theorem arg_cos_add_sin_mul_I_sub (ΞΈ : ℝ) : arg (cos ΞΈ + sin ΞΈ * I) - ΞΈ = 2 * Ο€ * ⌊(Ο€ - ΞΈ) / (2 * Ο€)βŒ‹ := by rw [← one_mul (_ + _), ← ofReal_one, arg_mul_cos_add_sin_mul_I_sub zero_lt_one] theorem arg_mul_cos_add_sin_mul_I_coe_angle {r : ℝ} (hr : 0 < r) (ΞΈ : Real.Angle) : (arg (r * (Real.Angle.cos ΞΈ + Real.Angle.sin ΞΈ * I)) : Real.Angle) = ΞΈ := by induction ΞΈ using Real.Angle.induction_on with | _ ΞΈ rw [Real.Angle.cos_coe, Real.Angle.sin_coe, Real.Angle.angle_eq_iff_two_pi_dvd_sub] use ⌊(Ο€ - ΞΈ) / (2 * Ο€)βŒ‹ exact mod_cast arg_mul_cos_add_sin_mul_I_sub hr ΞΈ theorem arg_cos_add_sin_mul_I_coe_angle (ΞΈ : Real.Angle) : (arg (Real.Angle.cos ΞΈ + Real.Angle.sin ΞΈ * I) : Real.Angle) = ΞΈ := by rw [← one_mul (_ + _), ← ofReal_one, arg_mul_cos_add_sin_mul_I_coe_angle zero_lt_one] theorem arg_mul_coe_angle {x y : β„‚} (hx : x β‰  0) (hy : y β‰  0) : (arg (x * y) : Real.Angle) = arg x + arg y := by convert arg_mul_cos_add_sin_mul_I_coe_angle (mul_pos (norm_pos_iff.mpr hx) (norm_pos_iff.mpr hy)) (arg x + arg y : Real.Angle) using 3 simp_rw [← Real.Angle.coe_add, Real.Angle.sin_coe, Real.Angle.cos_coe, ofReal_cos, ofReal_sin, cos_add_sin_I, ofReal_add, add_mul, exp_add, ofReal_mul] rw [mul_assoc, mul_comm (exp _), ← mul_assoc (β€–yβ€– : β„‚), norm_mul_exp_arg_mul_I, mul_comm y, ← mul_assoc, norm_mul_exp_arg_mul_I] theorem arg_div_coe_angle {x y : β„‚} (hx : x β‰  0) (hy : y β‰  0) : (arg (x / y) : Real.Angle) = arg x - arg y := by rw [div_eq_mul_inv, arg_mul_coe_angle hx (inv_ne_zero hy), arg_inv_coe_angle, sub_eq_add_neg] theorem arg_pow_coe_angle (x : β„‚) (n : β„•) : (arg (x ^ n) : Real.Angle) = n β€’ (arg x : Real.Angle) := by obtain rfl | x0 := eq_or_ne x 0 Β· by_cases n0 : n = 0 <;> simp [n0] Β· induction n with | zero => simp | succ n ih => rw [pow_succ, arg_mul_coe_angle (pow_ne_zero n x0) x0, ih, succ_nsmul] theorem arg_zpow_coe_angle (x : β„‚) (n : β„€) : (arg (x ^ n) : Real.Angle) = n β€’ (arg x : Real.Angle) := by match n with | Int.ofNat m => simp [arg_pow_coe_angle] | Int.negSucc m => simp [arg_pow_coe_angle] @[simp] theorem arg_coe_angle_toReal_eq_arg (z : β„‚) : (arg z : Real.Angle).toReal = arg z := by rw [Real.Angle.toReal_coe_eq_self_iff_mem_Ioc] exact arg_mem_Ioc _ theorem arg_coe_angle_eq_iff_eq_toReal {z : β„‚} {ΞΈ : Real.Angle} : (arg z : Real.Angle) = ΞΈ ↔ arg z = ΞΈ.toReal := by rw [← Real.Angle.toReal_inj, arg_coe_angle_toReal_eq_arg] @[simp] theorem arg_coe_angle_eq_iff {x y : β„‚} : (arg x : Real.Angle) = arg y ↔ arg x = arg y := by simp_rw [← Real.Angle.toReal_inj, arg_coe_angle_toReal_eq_arg] lemma arg_mul_eq_add_arg_iff {x y : β„‚} (hxβ‚€ : x β‰  0) (hyβ‚€ : y β‰  0) : (x * y).arg = x.arg + y.arg ↔ arg x + arg y ∈ Set.Ioc (-Ο€) Ο€ := by rw [← arg_coe_angle_toReal_eq_arg, arg_mul_coe_angle hxβ‚€ hyβ‚€, ← Real.Angle.coe_add, Real.Angle.toReal_coe_eq_self_iff_mem_Ioc] alias ⟨_, arg_mul⟩ := arg_mul_eq_add_arg_iff section slitPlane open ComplexOrder in /-- An alternative description of the slit plane as consisting of nonzero complex numbers whose argument is not Ο€. -/ lemma mem_slitPlane_iff_arg {z : β„‚} : z ∈ slitPlane ↔ z.arg β‰  Ο€ ∧ z β‰  0 := by simp only [mem_slitPlane_iff_not_le_zero, le_iff_lt_or_eq, ne_eq, arg_eq_pi_iff_lt_zero, not_or] lemma slitPlane_arg_ne_pi {z : β„‚} (hz : z ∈ slitPlane) : z.arg β‰  Real.pi := (mem_slitPlane_iff_arg.mp hz).1 end slitPlane section Continuity theorem arg_eq_nhds_of_re_pos (hx : 0 < x.re) : arg =αΆ [𝓝 x] fun x => Real.arcsin (x.im / β€–xβ€–) := ((continuous_re.tendsto _).eventually (lt_mem_nhds hx)).mono fun _ hy => arg_of_re_nonneg hy.le theorem arg_eq_nhds_of_re_neg_of_im_pos (hx_re : x.re < 0) (hx_im : 0 < x.im) : arg =αΆ [𝓝 x] fun x => Real.arcsin ((-x).im / β€–xβ€–) + Ο€ := by suffices h_forall_nhds : βˆ€αΆ  y : β„‚ in 𝓝 x, y.re < 0 ∧ 0 < y.im from h_forall_nhds.mono fun y hy => arg_of_re_neg_of_im_nonneg hy.1 hy.2.le refine IsOpen.eventually_mem ?_ (⟨hx_re, hx_im⟩ : x.re < 0 ∧ 0 < x.im) exact IsOpen.and (isOpen_lt continuous_re continuous_zero) (isOpen_lt continuous_zero continuous_im) theorem arg_eq_nhds_of_re_neg_of_im_neg (hx_re : x.re < 0) (hx_im : x.im < 0) : arg =αΆ [𝓝 x] fun x => Real.arcsin ((-x).im / β€–xβ€–) - Ο€ := by suffices h_forall_nhds : βˆ€αΆ  y : β„‚ in 𝓝 x, y.re < 0 ∧ y.im < 0 from h_forall_nhds.mono fun y hy => arg_of_re_neg_of_im_neg hy.1 hy.2 refine IsOpen.eventually_mem ?_ (⟨hx_re, hx_im⟩ : x.re < 0 ∧ x.im < 0) exact IsOpen.and (isOpen_lt continuous_re continuous_zero) (isOpen_lt continuous_im continuous_zero) theorem arg_eq_nhds_of_im_pos (hz : 0 < im z) : arg =αΆ [𝓝 z] fun x => Real.arccos (x.re / β€–xβ€–) := ((continuous_im.tendsto _).eventually (lt_mem_nhds hz)).mono fun _ => arg_of_im_pos theorem arg_eq_nhds_of_im_neg (hz : im z < 0) : arg =αΆ [𝓝 z] fun x => -Real.arccos (x.re / β€–xβ€–) := ((continuous_im.tendsto _).eventually (gt_mem_nhds hz)).mono fun _ => arg_of_im_neg theorem continuousAt_arg (h : x ∈ slitPlane) : ContinuousAt arg x := by have hβ‚€ : β€–xβ€– β‰  0 := by rw [norm_ne_zero_iff] exact slitPlane_ne_zero h rw [mem_slitPlane_iff, ← lt_or_lt_iff_ne] at h rcases h with (hx_re | hx_im | hx_im) exacts [(Real.continuousAt_arcsin.comp (continuous_im.continuousAt.div continuous_norm.continuousAt hβ‚€)).congr (arg_eq_nhds_of_re_pos hx_re).symm, (Real.continuous_arccos.continuousAt.comp (continuous_re.continuousAt.div continuous_norm.continuousAt hβ‚€)).neg.congr (arg_eq_nhds_of_im_neg hx_im).symm, (Real.continuous_arccos.continuousAt.comp (continuous_re.continuousAt.div continuous_norm.continuousAt hβ‚€)).congr (arg_eq_nhds_of_im_pos hx_im).symm] @[fun_prop] theorem continuousOn_arg : ContinuousOn arg slitPlane := fun _ h ↦ continuousAt_arg h |>.continuousWithinAt theorem tendsto_arg_nhdsWithin_im_neg_of_re_neg_of_im_zero {z : β„‚} (hre : z.re < 0) (him : z.im = 0) : Tendsto arg (𝓝[{ z : β„‚ | z.im < 0 }] z) (𝓝 (-Ο€)) := by suffices H : Tendsto (fun x : β„‚ => Real.arcsin ((-x).im / β€–xβ€–) - Ο€) (𝓝[{ z : β„‚ | z.im < 0 }] z) (𝓝 (-Ο€)) by refine H.congr' ?_ have : βˆ€αΆ  x : β„‚ in 𝓝 z, x.re < 0 := continuous_re.tendsto z (gt_mem_nhds hre) filter_upwards [self_mem_nhdsWithin, mem_nhdsWithin_of_mem_nhds this] with _ him hre rw [arg, if_neg hre.not_ge, if_neg him.not_ge] convert (Real.continuousAt_arcsin.comp_continuousWithinAt ((continuous_im.continuousAt.comp_continuousWithinAt continuousWithinAt_neg).div continuous_norm.continuousWithinAt _) ).sub_const Ο€ using 1 Β· simp [him] Β· lift z to ℝ using him simpa using hre.ne theorem continuousWithinAt_arg_of_re_neg_of_im_zero {z : β„‚} (hre : z.re < 0) (him : z.im = 0) : ContinuousWithinAt arg { z : β„‚ | 0 ≀ z.im } z := by have : arg =αΆ [𝓝[{ z : β„‚ | 0 ≀ z.im }] z] fun x => Real.arcsin ((-x).im / β€–xβ€–) + Ο€ := by have : βˆ€αΆ  x : β„‚ in 𝓝 z, x.re < 0 := continuous_re.tendsto z (gt_mem_nhds hre) filter_upwards [self_mem_nhdsWithin (s := { z : β„‚ | 0 ≀ z.im }), mem_nhdsWithin_of_mem_nhds this] with _ him hre rw [arg, if_neg hre.not_ge, if_pos him] refine ContinuousWithinAt.congr_of_eventuallyEq ?_ this ?_ Β· refine (Real.continuousAt_arcsin.comp_continuousWithinAt ((continuous_im.continuousAt.comp_continuousWithinAt continuousWithinAt_neg).div continuous_norm.continuousWithinAt ?_)).add tendsto_const_nhds lift z to ℝ using him simpa using hre.ne Β· rw [arg, if_neg hre.not_ge, if_pos him.ge] theorem tendsto_arg_nhdsWithin_im_nonneg_of_re_neg_of_im_zero {z : β„‚} (hre : z.re < 0) (him : z.im = 0) : Tendsto arg (𝓝[{ z : β„‚ | 0 ≀ z.im }] z) (𝓝 Ο€) := by simpa only [arg_eq_pi_iff.2 ⟨hre, him⟩] using (continuousWithinAt_arg_of_re_neg_of_im_zero hre him).tendsto theorem continuousAt_arg_coe_angle (h : x β‰  0) : ContinuousAt ((↑) ∘ arg : β„‚ β†’ Real.Angle) x := by by_cases hs : x ∈ slitPlane Β· exact Real.Angle.continuous_coe.continuousAt.comp (continuousAt_arg hs) Β· rw [← Function.comp_id (((↑) : ℝ β†’ Real.Angle) ∘ arg), (funext_iff.2 fun _ => (neg_neg _).symm : (id : β„‚ β†’ β„‚) = Neg.neg ∘ Neg.neg), ← Function.comp_assoc] refine ContinuousAt.comp ?_ continuous_neg.continuousAt suffices ContinuousAt (Function.update (((↑) ∘ arg) ∘ Neg.neg : β„‚ β†’ Real.Angle) 0 Ο€) (-x) by rwa [continuousAt_update_of_ne (neg_ne_zero.2 h)] at this have ha : Function.update (((↑) ∘ arg) ∘ Neg.neg : β„‚ β†’ Real.Angle) 0 Ο€ = fun z => (arg z : Real.Angle) + Ο€ := by rw [Function.update_eq_iff] exact ⟨by simp, fun z hz => arg_neg_coe_angle hz⟩ rw [ha] replace hs := mem_slitPlane_iff.mpr.mt hs push_neg at hs refine (Real.Angle.continuous_coe.continuousAt.comp (continuousAt_arg (Or.inl ?_))).add continuousAt_const rw [neg_re, neg_pos] exact hs.1.lt_of_ne fun h0 => h (Complex.ext_iff.2 ⟨h0, hs.2⟩) end Continuity end Complex
.lake/packages/mathlib/Mathlib/Analysis/SpecialFunctions/Complex/LogBounds.lean
import Mathlib.Analysis.Complex.Convex import Mathlib.Analysis.SpecialFunctions.Integrals.Basic import Mathlib.Analysis.Calculus.Deriv.Shift import Mathlib.Analysis.SpecificLimits.RCLike /-! # Estimates for the complex logarithm We show that `log (1+z)` differs from its Taylor polynomial up to degree `n` by at most `β€–zβ€–^(n+1)/((n+1)*(1-β€–zβ€–))` when `β€–zβ€– < 1`; see `Complex.norm_log_sub_logTaylor_le`. To this end, we derive the representation of `log (1+z)` as the integral of `1/(1+tz)` over the unit interval (`Complex.log_eq_integral`) and introduce notation `Complex.logTaylor n` for the Taylor polynomial up to degree `n-1`. ## TODO Refactor using general Taylor series theory, once this exists in Mathlib. -/ namespace Complex /-! ### Integral representation of the complex log -/ lemma continuousOn_one_add_mul_inv {z : β„‚} (hz : 1 + z ∈ slitPlane) : ContinuousOn (fun t : ℝ ↦ (1 + t β€’ z)⁻¹) (Set.Icc 0 1) := ContinuousOn.invβ‚€ (by fun_prop) (fun _ ht ↦ slitPlane_ne_zero <| StarConvex.add_smul_mem starConvex_one_slitPlane hz ht.1 ht.2) open intervalIntegral in /-- Represent `log (1 + z)` as an integral over the unit interval -/ lemma log_eq_integral {z : β„‚} (hz : 1 + z ∈ slitPlane) : log (1 + z) = z * ∫ (t : ℝ) in (0 : ℝ)..1, (1 + t β€’ z)⁻¹ := by convert (integral_unitInterval_deriv_eq_sub (continuousOn_one_add_mul_inv hz) (fun _ ht ↦ hasDerivAt_log <| StarConvex.add_smul_mem starConvex_one_slitPlane hz ht.1 ht.2)).symm using 1 simp only [log_one, sub_zero] /-- Represent `log (1 - z)⁻¹` as an integral over the unit interval -/ lemma log_inv_eq_integral {z : β„‚} (hz : 1 - z ∈ slitPlane) : log (1 - z)⁻¹ = z * ∫ (t : ℝ) in (0 : ℝ)..1, (1 - t β€’ z)⁻¹ := by rw [sub_eq_add_neg 1 z] at hz ⊒ rw [log_inv _ <| slitPlane_arg_ne_pi hz, neg_eq_iff_eq_neg, ← neg_mul] convert log_eq_integral hz using 5 rw [sub_eq_add_neg, smul_neg] /-! ### The Taylor polynomials of the logarithm -/ /-- The `n`th Taylor polynomial of `log` at `1`, as a function `β„‚ β†’ β„‚` -/ noncomputable def logTaylor (n : β„•) : β„‚ β†’ β„‚ := fun z ↦ βˆ‘ j ∈ Finset.range n, (-1) ^ (j + 1) * z ^ j / j lemma logTaylor_zero : logTaylor 0 = fun _ ↦ 0 := by funext simp only [logTaylor, Finset.range_zero, Finset.sum_empty] lemma logTaylor_succ (n : β„•) : logTaylor (n + 1) = logTaylor n + (fun z : β„‚ ↦ (-1) ^ (n + 1) * z ^ n / n) := by funext simpa only [logTaylor] using Finset.sum_range_succ .. lemma logTaylor_at_zero (n : β„•) : logTaylor n 0 = 0 := by induction n with | zero => simp [logTaylor_zero] | succ n ih => simpa [logTaylor_succ, ih] using ne_or_eq n 0 lemma hasDerivAt_logTaylor (n : β„•) (z : β„‚) : HasDerivAt (logTaylor (n + 1)) (βˆ‘ j ∈ Finset.range n, (-1) ^ j * z ^ j) z := by induction n with | zero => simp [logTaylor_succ, logTaylor_zero, Pi.add_def, hasDerivAt_const] | succ n ih => rw [logTaylor_succ] simp only [Nat.cast_add, Nat.cast_one, Finset.sum_range_succ] refine HasDerivAt.add ih ?_ simp only [mul_div_assoc] have : HasDerivAt (fun x : β„‚ ↦ (x ^ (n + 1) / (n + 1))) (z ^ n) z := by simp_rw [div_eq_mul_inv] convert HasDerivAt.mul_const (hasDerivAt_pow (n + 1) z) (((n : β„‚) + 1)⁻¹) using 1 simp [field] convert HasDerivAt.const_mul _ this using 2 ring /-! ### Bounds for the difference between log and its Taylor polynomials -/ lemma hasDerivAt_log_sub_logTaylor (n : β„•) {z : β„‚} (hz : 1 + z ∈ slitPlane) : HasDerivAt (fun z : β„‚ ↦ log (1 + z) - logTaylor (n + 1) z) ((-z) ^ n * (1 + z)⁻¹) z := by convert ((hasDerivAt_log hz).comp_const_add 1 z).sub (hasDerivAt_logTaylor n z) using 1 have hz' : -z β‰  1 := by intro H rw [neg_eq_iff_eq_neg] at H simp only [H, add_neg_cancel] at hz exact slitPlane_ne_zero hz rfl simp_rw [← mul_pow, neg_one_mul, geom_sum_eq hz', ← neg_add', div_neg, add_comm z] simp [field] /-- Give a bound on `β€–(1 + t * z)⁻¹‖` for `0 ≀ t ≀ 1` and `β€–zβ€– < 1`. -/ lemma norm_one_add_mul_inv_le {t : ℝ} (ht : t ∈ Set.Icc 0 1) {z : β„‚} (hz : β€–zβ€– < 1) : β€–(1 + t * z)⁻¹‖ ≀ (1 - β€–zβ€–)⁻¹ := by rw [Set.mem_Icc] at ht rw [norm_inv] refine inv_antiβ‚€ (by linarith) ?_ calc 1 - β€–zβ€– _ ≀ 1 - t * β€–zβ€– := by nlinarith [norm_nonneg z] _ = 1 - β€–t * zβ€– := by rw [norm_mul, Complex.norm_of_nonneg ht.1] _ ≀ β€–1 + t * zβ€– := by rw [← norm_neg (t * z), ← sub_neg_eq_add] convert norm_sub_norm_le 1 (-(t * z)) exact norm_one.symm lemma integrable_pow_mul_norm_one_add_mul_inv (n : β„•) {z : β„‚} (hz : β€–zβ€– < 1) : IntervalIntegrable (fun t : ℝ ↦ t ^ n * β€–(1 + t * z)⁻¹‖) MeasureTheory.volume 0 1 := by have := continuousOn_one_add_mul_inv <| mem_slitPlane_of_norm_lt_one hz rw [← Set.uIcc_of_le zero_le_one] at this exact ContinuousOn.intervalIntegrable (by fun_prop) open intervalIntegral in /-- The difference of `log (1+z)` and its `(n+1)`st Taylor polynomial can be bounded in terms of `β€–zβ€–`. -/ lemma norm_log_sub_logTaylor_le (n : β„•) {z : β„‚} (hz : β€–zβ€– < 1) : β€–log (1 + z) - logTaylor (n + 1) zβ€– ≀ β€–zβ€– ^ (n + 1) * (1 - β€–zβ€–)⁻¹ / (n + 1) := by have help : IntervalIntegrable (fun t : ℝ ↦ t ^ n * (1 - β€–zβ€–)⁻¹) MeasureTheory.volume 0 1 := IntervalIntegrable.mul_const (Continuous.intervalIntegrable (by fun_prop) 0 1) (1 - β€–zβ€–)⁻¹ let f (z : β„‚) : β„‚ := log (1 + z) - logTaylor (n + 1) z let f' (z : β„‚) : β„‚ := (-z) ^ n * (1 + z)⁻¹ have hderiv : βˆ€ t ∈ Set.Icc (0 : ℝ) 1, HasDerivAt f (f' (0 + t * z)) (0 + t * z) := by intro t ht rw [zero_add] exact hasDerivAt_log_sub_logTaylor n <| StarConvex.add_smul_mem starConvex_one_slitPlane (mem_slitPlane_of_norm_lt_one hz) ht.1 ht.2 have hcont : ContinuousOn (fun t : ℝ ↦ f' (0 + t * z)) (Set.Icc 0 1) := by simp only [zero_add] exact (Continuous.continuousOn (by fun_prop)).mul <| continuousOn_one_add_mul_inv <| mem_slitPlane_of_norm_lt_one hz have H : f z = z * ∫ t in (0 : ℝ)..1, (-(t * z)) ^ n * (1 + t * z)⁻¹ := by convert (integral_unitInterval_deriv_eq_sub hcont hderiv).symm using 1 Β· simp only [f, zero_add, add_zero, log_one, logTaylor_at_zero, sub_self, sub_zero] Β· simp only [f', real_smul, zero_add, smul_eq_mul] unfold f at H simp only [H, norm_mul] simp_rw [neg_pow (_ * z) n, mul_assoc, intervalIntegral.integral_const_mul, mul_pow, mul_comm _ (z ^ n), mul_assoc, intervalIntegral.integral_const_mul, norm_mul, norm_pow, norm_neg, norm_one, one_pow, one_mul, ← mul_assoc, ← pow_succ', mul_div_assoc] gcongr _ * ?_ calc β€–βˆ« t in (0 : ℝ)..1, (t : β„‚) ^ n * (1 + t * z)⁻¹‖ _ ≀ ∫ t in (0 : ℝ)..1, t ^ n * (1 - β€–zβ€–)⁻¹ := by refine intervalIntegral.norm_integral_le_of_norm_le zero_le_one ?_ help filter_upwards with t ⟨htβ‚€, htβ‚βŸ© rw [norm_mul, norm_pow, Complex.norm_of_nonneg htβ‚€.le] gcongr exact norm_one_add_mul_inv_le ⟨htβ‚€.le, htβ‚βŸ© hz _ = (1 - β€–zβ€–)⁻¹ / (n + 1) := by rw [intervalIntegral.integral_mul_const, mul_comm, integral_pow] simp [field] /-- The difference `log (1+z) - z` is bounded by `β€–zβ€–^2/(2*(1-β€–zβ€–))` when `β€–zβ€– < 1`. -/ lemma norm_log_one_add_sub_self_le {z : β„‚} (hz : β€–zβ€– < 1) : β€–log (1 + z) - zβ€– ≀ β€–zβ€– ^ 2 * (1 - β€–zβ€–)⁻¹ / 2 := by convert norm_log_sub_logTaylor_le 1 hz using 2 Β· simp [logTaylor_succ, logTaylor_zero, sub_eq_add_neg] Β· norm_num open scoped Topology in lemma log_sub_logTaylor_isBigO (n : β„•) : (fun z ↦ log (1 + z) - logTaylor (n + 1) z) =O[𝓝 0] fun z ↦ z ^ (n + 1) := by rw [Asymptotics.isBigO_iff] use 2 / (n + 1) filter_upwards [ eventually_norm_sub_lt 0 one_pos, eventually_norm_sub_lt 0 (show 0 < 1 / 2 by simp)] with z hz1 hz12 rw [sub_zero] at hz1 hz12 have : (1 - β€–zβ€–)⁻¹ ≀ 2 := by rw [inv_le_commβ‚€ (sub_pos_of_lt hz1) two_pos]; linarith apply (norm_log_sub_logTaylor_le n hz1).trans rw [mul_div_assoc, mul_comm, norm_pow] gcongr open scoped Topology in lemma log_sub_self_isBigO : (fun z ↦ log (1 + z) - z) =O[𝓝 0] fun z ↦ z ^ 2 := by convert log_sub_logTaylor_isBigO 1 simp [logTaylor_succ, logTaylor_zero] lemma norm_log_one_add_le {z : β„‚} (hz : β€–zβ€– < 1) : β€–log (1 + z)β€– ≀ β€–zβ€– ^ 2 * (1 - β€–zβ€–)⁻¹ / 2 + β€–zβ€– := by rw [← sub_add_cancel (log (1 + z)) z] exact norm_add_le_of_le (Complex.norm_log_one_add_sub_self_le hz) le_rfl /-- For `β€–zβ€– ≀ 1/2`, the complex logarithm is bounded by `(3/2) * β€–zβ€–`. -/ lemma norm_log_one_add_half_le_self {z : β„‚} (hz : β€–zβ€– ≀ 1 / 2) : β€–log (1 + z)β€– ≀ (3/2) * β€–zβ€– := by apply le_trans (norm_log_one_add_le (lt_of_le_of_lt hz one_half_lt_one)) have hz3 : (1 - β€–zβ€–)⁻¹ ≀ 2 := by rw [inv_eq_one_div, div_le_iffβ‚€] Β· linarith Β· linarith have hz4 : β€–zβ€–^2 * (1 - β€–zβ€–)⁻¹ / 2 ≀ β€–zβ€–/2 * 2 / 2 := by gcongr Β· rw [inv_nonneg] linarith Β· rw [sq, div_eq_mul_one_div] gcongr simp only [isUnit_iff_ne_zero, ne_eq, OfNat.ofNat_ne_zero, not_false_eq_true, IsUnit.div_mul_cancel] at hz4 linarith /-- The difference of `log (1-z)⁻¹` and its `(n+1)`st Taylor polynomial can be bounded in terms of `β€–zβ€–`. -/ lemma norm_log_one_sub_inv_add_logTaylor_neg_le (n : β„•) {z : β„‚} (hz : β€–zβ€– < 1) : β€–log (1 - z)⁻¹ + logTaylor (n + 1) (-z)β€– ≀ β€–zβ€– ^ (n + 1) * (1 - β€–zβ€–)⁻¹ / (n + 1) := by rw [sub_eq_add_neg, log_inv _ <| slitPlane_arg_ne_pi <| mem_slitPlane_of_norm_lt_one <| (norm_neg z).symm β–Έ hz, ← sub_neg_eq_add, ← neg_sub', norm_neg] convert norm_log_sub_logTaylor_le n <| (norm_neg z).symm β–Έ hz using 4 <;> rw [norm_neg] /-- The difference `log (1-z)⁻¹ - z` is bounded by `β€–zβ€–^2/(2*(1-β€–zβ€–))` when `β€–zβ€– < 1`. -/ lemma norm_log_one_sub_inv_sub_self_le {z : β„‚} (hz : β€–zβ€– < 1) : β€–log (1 - z)⁻¹ - zβ€– ≀ β€–zβ€– ^ 2 * (1 - β€–zβ€–)⁻¹ / 2 := by convert norm_log_one_sub_inv_add_logTaylor_neg_le 1 hz using 2 Β· simp [logTaylor_succ, logTaylor_zero, sub_eq_add_neg] Β· norm_num open Filter Asymptotics in /-- The Taylor series of the complex logarithm at `1` converges to the logarithm in the open unit disk. -/ lemma hasSum_taylorSeries_log {z : β„‚} (hz : β€–zβ€– < 1) : HasSum (fun n : β„• ↦ (-1) ^ (n + 1) * z ^ n / n) (log (1 + z)) := by refine (hasSum_iff_tendsto_nat_of_summable_norm ?_).mpr ?_ Β· refine (summable_geometric_of_norm_lt_one hz).norm.of_nonneg_of_le (fun _ ↦ norm_nonneg _) ?_ intro n simp only [norm_div, norm_mul, norm_pow, norm_neg, norm_one, one_pow, one_mul, norm_natCast] rcases n.eq_zero_or_pos with rfl | hn Β· simp conv => enter [2]; rw [← div_one (β€–zβ€– ^ n)] gcongr norm_cast Β· rw [← tendsto_sub_nhds_zero_iff] conv => enter [1, x]; rw [← div_one (_ - _), ← logTaylor] rw [← isLittleO_iff_tendsto fun _ h ↦ (one_ne_zero h).elim] refine IsLittleO.trans_isBigO ?_ <| isBigO_const_one β„‚ (1 : ℝ) atTop have H : (fun n ↦ logTaylor n z - log (1 + z)) =O[atTop] (fun n : β„• ↦ β€–zβ€– ^ n) := by have (n : β„•) : β€–logTaylor n z - log (1 + z)β€– ≀ (max β€–log (1 + z)β€– (1 - β€–zβ€–)⁻¹) * β€–(β€–zβ€– ^ n)β€– := by rw [norm_sub_rev, norm_pow, norm_norm] cases n with | zero => simp [logTaylor_zero] | succ n => refine (norm_log_sub_logTaylor_le n hz).trans ?_ rw [mul_comm, ← div_one ((max _ _) * _)] gcongr Β· exact le_max_right .. Β· linarith exact (isBigOWith_of_le' atTop this).isBigO refine IsBigO.trans_isLittleO H ?_ convert isLittleO_pow_pow_of_lt_left (norm_nonneg z) hz exact (one_pow _).symm /-- The series `βˆ‘ z^n/n` converges to `-log (1-z)` on the open unit disk. -/ lemma hasSum_taylorSeries_neg_log {z : β„‚} (hz : β€–zβ€– < 1) : HasSum (fun n : β„• ↦ z ^ n / n) (-log (1 - z)) := by conv => enter [1, n]; rw [← neg_neg (z ^ n / n)] refine HasSum.neg ?_ convert hasSum_taylorSeries_log (z := -z) (norm_neg z β–Έ hz) using 2 with n rcases n.eq_zero_or_pos with rfl | hn Β· simp simp [field, pow_add, ← mul_pow] end Complex section Limits /-! Limits of functions of the form `(1 + t/x + o(1/x)) ^ x` as `x β†’ ∞`. -/ open Filter Asymptotics open scoped Topology namespace Complex /-- The limit of `x * log (1 + g x)` as `(x : ℝ) β†’ ∞` is `t`, where `t : β„‚` is the limit of `x * g x`. -/ lemma tendsto_mul_log_one_add_of_tendsto {g : ℝ β†’ β„‚} {t : β„‚} (hg : Tendsto (fun x ↦ x * g x) atTop (𝓝 t)) : Tendsto (fun x ↦ x * log (1 + g x)) atTop (𝓝 t) := by apply hg.congr_dist refine IsBigO.trans_tendsto ?_ tendsto_inv_atTop_zero.ofReal simp_rw [dist_comm (_ * g _), dist_eq, ← mul_sub, isBigO_norm_left] calc _ =O[atTop] fun x ↦ x * g x ^ 2 := by have hg0 := tendsto_zero_of_isBoundedUnder_smul_of_tendsto_cobounded hg.norm.isBoundedUnder_le (RCLike.tendsto_ofReal_atTop_cobounded β„‚) exact (isBigO_refl _ _).mul (log_sub_self_isBigO.comp_tendsto hg0) _ =αΆ [atTop] fun x ↦ (x * g x) ^ 2 * x⁻¹ := by filter_upwards [eventually_ne_atTop 0] with x hx0 rw [ofReal_inv, eq_mul_inv_iff_mul_eqβ‚€ (mod_cast hx0)] ring _ =O[atTop] _ := by simpa using isBigO_const_of_tendsto hg (one_ne_zero (Ξ± := β„‚)) |>.pow 2 |>.mul (isBigO_refl _ _) /-- The limit of `(1 + g x) ^ x` as `(x : ℝ) β†’ ∞` is `exp t`, where `t : β„‚` is the limit of `x * g x`. -/ lemma tendsto_one_add_cpow_exp_of_tendsto {g : ℝ β†’ β„‚} {t : β„‚} (hg : Tendsto (fun x ↦ x * g x) atTop (𝓝 t)) : Tendsto (fun x ↦ (1 + g x) ^ (x : β„‚)) atTop (𝓝 (exp t)) := by apply ((continuous_exp.tendsto _).comp (tendsto_mul_log_one_add_of_tendsto hg)).congr' have hg0 := tendsto_zero_of_isBoundedUnder_smul_of_tendsto_cobounded hg.norm.isBoundedUnder_le (RCLike.tendsto_ofReal_atTop_cobounded β„‚) filter_upwards [hg0.eventually_ne (show 0 β‰  -1 by simp)] with x hg1 dsimp rw [cpow_def_of_ne_zero, mul_comm] intro hg0 rw [← add_eq_zero_iff_neg_eq.mp hg0] at hg1 norm_num at hg1 /-- The limit of `(1 + t/x) ^ x` as `x β†’ ∞` is `exp t` for `t : β„‚`. -/ lemma tendsto_one_add_div_cpow_exp (t : β„‚) : Tendsto (fun x : ℝ ↦ (1 + t / x) ^ (x : β„‚)) atTop (𝓝 (exp t)) := by apply tendsto_one_add_cpow_exp_of_tendsto apply tendsto_nhds_of_eventually_eq filter_upwards [eventually_ne_atTop 0] with x hx0 exact mul_div_cancelβ‚€ t (mod_cast hx0) /-- The limit of `n * log (1 + g n)` as `(n : ℝ) β†’ ∞` is `t`, where `t : β„‚` is the limit of `n * g n`. -/ lemma tendsto_nat_mul_log_one_add_of_tendsto {g : β„• β†’ β„‚} {t : β„‚} (hg : Tendsto (fun n ↦ n * g n) atTop (𝓝 t)) : Tendsto (fun n ↦ n * log (1 + g n)) atTop (𝓝 t) := tendsto_mul_log_one_add_of_tendsto (tendsto_smul_comp_nat_floor_of_tendsto_mul hg) |>.comp tendsto_natCast_atTop_atTop |>.congr (by simp) /-- The limit of `(1 + g n) ^ n` as `(n : ℝ) β†’ ∞` is `exp t`, where `t : β„‚` is the limit of `n * g n`. -/ lemma tendsto_one_add_pow_exp_of_tendsto {g : β„• β†’ β„‚} {t : β„‚} (hg : Tendsto (fun n ↦ n * g n) atTop (𝓝 t)) : Tendsto (fun n ↦ (1 + g n) ^ n) atTop (𝓝 (exp t)) := tendsto_one_add_cpow_exp_of_tendsto (tendsto_smul_comp_nat_floor_of_tendsto_mul hg) |>.comp tendsto_natCast_atTop_atTop |>.congr (by simp) /-- The limit of `(1 + t/n) ^ n` as `n β†’ ∞` is `exp t` for `t : β„‚`. -/ lemma tendsto_one_add_div_pow_exp (t : β„‚) : Tendsto (fun n : β„• ↦ (1 + t / n) ^ n) atTop (𝓝 (exp t)) := tendsto_one_add_div_cpow_exp t |>.comp tendsto_natCast_atTop_atTop |>.congr (by simp) end Complex namespace Real /-- The limit of `x * log (1 + g x)` as `(x : ℝ) β†’ ∞` is `t`, where `t : ℝ` is the limit of `x * g x`. -/ lemma tendsto_mul_log_one_add_of_tendsto {g : ℝ β†’ ℝ} {t : ℝ} (hg : Tendsto (fun x ↦ x * g x) atTop (𝓝 t)) : Tendsto (fun x ↦ x * log (1 + g x)) atTop (𝓝 t) := by have hg0 := tendsto_zero_of_isBoundedUnder_smul_of_tendsto_cobounded hg.norm.isBoundedUnder_le (tendsto_id'.mpr (by simp)) rw [← tendsto_ofReal_iff] at hg ⊒ push_cast at hg ⊒ apply (Complex.tendsto_mul_log_one_add_of_tendsto hg).congr' filter_upwards [hg0.eventually_const_le (show (-1 : ℝ) < 0 by simp)] with x hg1 rw [Complex.ofReal_log (by linarith), Complex.ofReal_add, Complex.ofReal_one] theorem tendsto_mul_log_one_add_div_atTop (t : ℝ) : Tendsto (fun x => x * log (1 + t / x)) atTop (𝓝 t) := tendsto_mul_log_one_add_of_tendsto <| tendsto_const_nhds.congr' <| (EventuallyEq.div_mul_cancel_atTop tendsto_id).symm.trans <| .of_eq <| funext fun _ => mul_comm _ _ @[deprecated (since := "2025-05-22")] alias tendsto_mul_log_one_plus_div_atTop := tendsto_mul_log_one_add_div_atTop /-- The limit of `(1 + g x) ^ x` as `(x : ℝ) β†’ ∞` is `exp t`, where `t : ℝ` is the limit of `x * g x`. -/ lemma tendsto_one_add_rpow_exp_of_tendsto {g : ℝ β†’ ℝ} {t : ℝ} (hg : Tendsto (fun x ↦ x * g x) atTop (𝓝 t)) : Tendsto (fun x ↦ (1 + g x) ^ x) atTop (𝓝 (exp t)) := by have hg0 := tendsto_zero_of_isBoundedUnder_smul_of_tendsto_cobounded hg.norm.isBoundedUnder_le (tendsto_id'.mpr (by simp)) rw [← tendsto_ofReal_iff] at hg ⊒ push_cast at hg ⊒ apply (Complex.tendsto_one_add_cpow_exp_of_tendsto hg).congr' filter_upwards [hg0.eventually_const_le (show (-1 : ℝ) < 0 by simp)] with x hg1 rw [Complex.ofReal_cpow (by linarith), Complex.ofReal_add, Complex.ofReal_one] /-- The limit of `(1 + t/x) ^ x` as `x β†’ ∞` is `exp t` for `t : ℝ`. -/ lemma tendsto_one_add_div_rpow_exp (t : ℝ) : Tendsto (fun x : ℝ ↦ (1 + t / x) ^ x) atTop (𝓝 (exp t)) := by apply tendsto_one_add_rpow_exp_of_tendsto apply tendsto_nhds_of_eventually_eq filter_upwards [eventually_ne_atTop 0] with x hx0 exact mul_div_cancelβ‚€ t (mod_cast hx0) @[deprecated (since := "2025-05-22")] alias tendsto_one_plus_div_rpow_exp := tendsto_one_add_div_rpow_exp /-- The limit of `n * log (1 + g n)` as `(n : ℝ) β†’ ∞` is `t`, where `t : ℝ` is the limit of `n * g n`. -/ lemma tendsto_nat_mul_log_one_add_of_tendsto {g : β„• β†’ ℝ} {t : ℝ} (hg : Tendsto (fun n ↦ n * g n) atTop (𝓝 t)) : Tendsto (fun n ↦ n * log (1 + g n)) atTop (𝓝 t) := tendsto_mul_log_one_add_of_tendsto (tendsto_smul_comp_nat_floor_of_tendsto_mul hg) |>.comp tendsto_natCast_atTop_atTop |>.congr (by simp) /-- The limit of `(1 + g n) ^ n` as `(n : ℝ) β†’ ∞` is `exp t`, where `t : ℝ` is the limit of `n * g n`. -/ lemma tendsto_one_add_pow_exp_of_tendsto {g : β„• β†’ ℝ} {t : ℝ} (hg : Tendsto (fun n ↦ n * g n) atTop (𝓝 t)) : Tendsto (fun n ↦ (1 + g n) ^ n) atTop (𝓝 (exp t)) := tendsto_one_add_rpow_exp_of_tendsto (tendsto_smul_comp_nat_floor_of_tendsto_mul hg) |>.comp tendsto_natCast_atTop_atTop |>.congr (by simp) /-- The limit of `(1 + t/n) ^ n` as `n β†’ ∞` is `exp t` for `t : ℝ`. -/ lemma tendsto_one_add_div_pow_exp (t : ℝ) : Tendsto (fun n : β„• ↦ (1 + t / n) ^ n) atTop (𝓝 (exp t)) := tendsto_one_add_div_rpow_exp t |>.comp tendsto_natCast_atTop_atTop |>.congr (by simp) @[deprecated (since := "2025-05-22")] alias tendsto_one_plus_div_pow_exp := tendsto_one_add_div_pow_exp end Real end Limits
.lake/packages/mathlib/Mathlib/Analysis/SpecialFunctions/Complex/CircleAddChar.lean
import Mathlib.Analysis.SpecialFunctions.Complex.Circle import Mathlib.NumberTheory.LegendreSymbol.AddCharacter import Mathlib.RingTheory.RootsOfUnity.AlgebraicallyClosed import Mathlib.Topology.Instances.AddCircle.Real /-! # Additive characters valued in the unit circle This file defines additive characters, valued in the unit circle, from either * the ring `ZMod N` for any non-zero natural `N`, * the additive circle `ℝ / T ⬝ β„€`, for any real `T`. These results are separate from `Analysis.SpecialFunctions.Complex.Circle` in order to reduce the imports of that file. -/ open Complex Function open scoped Real /-- The canonical map from the additive to the multiplicative circle, as an `AddChar`. -/ noncomputable def AddCircle.toCircle_addChar {T : ℝ} : AddChar (AddCircle T) Circle where toFun := toCircle map_zero_eq_one' := toCircle_zero map_add_eq_mul' := toCircle_add open AddCircle namespace ZMod /-! ### Additive characters valued in the complex circle -/ open scoped Real variable {N : β„•} [NeZero N] /-- The additive character from `ZMod N` to the unit circle in `β„‚`, sending `j mod N` to `exp (2 * Ο€ * I * j / N)`. -/ noncomputable def toCircle : AddChar (ZMod N) Circle := toCircle_addChar.compAddMonoidHom toAddCircle lemma toCircle_intCast (j : β„€) : toCircle (j : ZMod N) = exp (2 * Ο€ * I * j / N) := by rw [toCircle, AddChar.compAddMonoidHom_apply, toCircle_addChar, AddChar.coe_mk, AddCircle.toCircle, toAddCircle_intCast, Function.Periodic.lift_coe, Circle.coe_exp] push_cast ring_nf lemma toCircle_natCast (j : β„•) : toCircle (j : ZMod N) = exp (2 * Ο€ * I * j / N) := by simpa using toCircle_intCast (N := N) j /-- Explicit formula for `toCircle j`. Note that this is "evil" because it uses `ZMod.val`. Where possible, it is recommended to lift `j` to `β„€` and use `toCircle_intCast` instead. -/ lemma toCircle_apply (j : ZMod N) : toCircle j = exp (2 * Ο€ * I * j.val / N) := by rw [← toCircle_natCast, natCast_zmod_val] lemma toCircle_eq_circleExp (j : ZMod N) : toCircle j = Circle.exp (2 * Ο€ * (j.val / N)) := by ext rw [toCircle_apply, Circle.coe_exp] push_cast congr; ring lemma injective_toCircle : Injective (toCircle : ZMod N β†’ Circle) := (AddCircle.injective_toCircle one_ne_zero).comp (toAddCircle_injective N) /-- The additive character from `ZMod N` to `β„‚`, sending `j mod N` to `exp (2 * Ο€ * I * j / N)`. -/ noncomputable def stdAddChar : AddChar (ZMod N) β„‚ := Circle.coeHom.compAddChar toCircle lemma stdAddChar_coe (j : β„€) : stdAddChar (j : ZMod N) = exp (2 * Ο€ * I * j / N) := by simp [stdAddChar, toCircle_intCast] lemma stdAddChar_apply (j : ZMod N) : stdAddChar j = ↑(toCircle j) := rfl lemma injective_stdAddChar : Injective (stdAddChar : AddChar (ZMod N) β„‚) := Subtype.coe_injective.comp injective_toCircle /-- The standard additive character `ZMod N β†’ β„‚` is primitive. -/ lemma isPrimitive_stdAddChar (N : β„•) [NeZero N] : (stdAddChar (N := N)).IsPrimitive := by refine AddChar.zmod_char_primitive_of_eq_one_only_at_zero _ _ (fun t ht ↦ ?_) rwa [← (stdAddChar (N := N)).map_zero_eq_one, injective_stdAddChar.eq_iff] at ht /-- `ZMod.toCircle` as an `AddChar` into `rootsOfUnity n Circle`. -/ noncomputable def rootsOfUnityAddChar (n : β„•) [NeZero n] : AddChar (ZMod n) (rootsOfUnity n Circle) where toFun x := ⟨toUnits (ZMod.toCircle x), by ext; simp [← AddChar.map_nsmul_eq_pow]⟩ map_zero_eq_one' := by simp map_add_eq_mul' _ _:= by ext; simp [AddChar.map_add_eq_mul] @[simp] lemma rootsOfUnityAddChar_val (n : β„•) [NeZero n] (x : ZMod n) : (rootsOfUnityAddChar n x).val = toCircle x := by rfl end ZMod variable (n : β„•) [NeZero n] /-- Interpret `n`-th roots of unity in `β„‚` as elements of the circle -/ noncomputable def rootsOfUnitytoCircle : (rootsOfUnity n β„‚) β†’* Circle where toFun := fun z => ⟨z.val.val, mem_sphere_zero_iff_norm.2 (Complex.norm_eq_one_of_mem_rootsOfUnity z.prop)⟩ map_one' := rfl map_mul' _ _ := rfl /-- Equivalence of the nth roots of unity of the Circle with nth roots of unity of the complex numbers -/ noncomputable def rootsOfUnityCircleEquiv : rootsOfUnity n Circle ≃* rootsOfUnity n β„‚ where __ := (rootsOfUnityUnitsMulEquiv β„‚ n).toMonoidHom.comp (restrictRootsOfUnity Circle.toUnits n) invFun z := ⟨(rootsOfUnitytoCircle n).toHomUnits z, by rw [mem_rootsOfUnity', MonoidHom.coe_toHomUnits, ← MonoidHom.map_pow, ← (rootsOfUnitytoCircle n).map_one] congr aesop⟩ left_inv _ := by aesop right_inv _ := by aesop instance : HasEnoughRootsOfUnity Circle n := (rootsOfUnityCircleEquiv n).symm.hasEnoughRootsOfUnity @[simp] lemma rootsOfUnityCircleEquiv_apply (w : rootsOfUnity n Circle) : ((rootsOfUnityCircleEquiv n w).val : β„‚) = ((w.val : Circle) : β„‚) := rfl open Real in lemma rootsOfUnityCircleEquiv_comp_rootsOfUnityAddChar_val (j : ZMod n) : (rootsOfUnityCircleEquiv n (ZMod.rootsOfUnityAddChar n j)).val = Complex.exp (2 * Ο€ * I * j.val / n) := by simp [← ZMod.toCircle_natCast, -ZMod.natCast_val, ZMod.natCast_zmod_val] theorem surjective_rootsOfUnityCircleEquiv_comp_rootsOfUnityAddChar (n : β„•) [NeZero n] : Surjective (rootsOfUnityCircleEquiv n ∘ ZMod.rootsOfUnityAddChar n) := fun ⟨w, hw⟩ ↦ by obtain ⟨j, hj1, hj2⟩ := (Complex.mem_rootsOfUnity n w).mp hw exact ⟨j, by simp [Units.ext_iff, Subtype.ext_iff, ← hj2, ZMod.toCircle_natCast, mul_div_assoc]⟩ lemma bijective_rootsOfUnityAddChar : Bijective (ZMod.rootsOfUnityAddChar n) where left _ _ := by simp [ZMod.rootsOfUnityAddChar, ZMod.injective_toCircle.eq_iff] right := (surjective_rootsOfUnityCircleEquiv_comp_rootsOfUnityAddChar n).of_comp_left (rootsOfUnityCircleEquiv n).injective
.lake/packages/mathlib/Mathlib/Analysis/SpecialFunctions/Complex/LogDeriv.lean
import Mathlib.Analysis.Calculus.InverseFunctionTheorem.Deriv import Mathlib.Analysis.Calculus.LogDeriv import Mathlib.Analysis.SpecialFunctions.Complex.Log import Mathlib.Analysis.SpecialFunctions.ExpDeriv /-! # Differentiability of the complex `log` function -/ assert_not_exists IsConformalMap Conformal open Set Filter open scoped Real Topology namespace Complex theorem isOpenMap_exp : IsOpenMap exp := isOpenMap_of_hasStrictDerivAt hasStrictDerivAt_exp exp_ne_zero /-- `Complex.exp` as an `OpenPartialHomeomorph` with `source = {z | -Ο€ < im z < Ο€}` and `target = {z | 0 < re z} βˆͺ {z | im z β‰  0}`. This definition is used to prove that `Complex.log` is complex differentiable at all points but the negative real semi-axis. -/ noncomputable def expPartialHomeomorph : OpenPartialHomeomorph β„‚ β„‚ := OpenPartialHomeomorph.ofContinuousOpen { toFun := exp invFun := log source := {z : β„‚ | z.im ∈ Ioo (-Ο€) Ο€} target := slitPlane map_source' := by rintro ⟨x, y⟩ ⟨h₁ : -Ο€ < y, hβ‚‚ : y < Ο€βŸ© refine (not_or_of_imp fun hz => ?_).symm obtain rfl : y = 0 := by rw [exp_im] at hz simpa [(Real.exp_pos _).ne', Real.sin_eq_zero_iff_of_lt_of_lt h₁ hβ‚‚] using hz rw [← ofReal_def, exp_ofReal_re] exact Real.exp_pos x map_target' := fun z h => by simp only [mem_setOf, log_im, mem_Ioo, neg_pi_lt_arg, arg_lt_pi_iff, true_and] exact h.imp_left le_of_lt left_inv' := fun _ hx => log_exp hx.1 (le_of_lt hx.2) right_inv' := fun _ hx => exp_log <| slitPlane_ne_zero hx } continuous_exp.continuousOn isOpenMap_exp (isOpen_Ioo.preimage continuous_im) theorem hasStrictDerivAt_log {x : β„‚} (h : x ∈ slitPlane) : HasStrictDerivAt log x⁻¹ x := have h0 : x β‰  0 := slitPlane_ne_zero h expPartialHomeomorph.hasStrictDerivAt_symm h h0 <| by simpa [exp_log h0] using hasStrictDerivAt_exp (log x) lemma hasDerivAt_log {z : β„‚} (hz : z ∈ slitPlane) : HasDerivAt log z⁻¹ z := HasStrictDerivAt.hasDerivAt <| hasStrictDerivAt_log hz @[fun_prop] lemma differentiableAt_log {z : β„‚} (hz : z ∈ slitPlane) : DifferentiableAt β„‚ log z := (hasDerivAt_log hz).differentiableAt @[fun_prop] theorem hasStrictFDerivAt_log_real {x : β„‚} (h : x ∈ slitPlane) : HasStrictFDerivAt log (x⁻¹ β€’ (1 : β„‚ β†’L[ℝ] β„‚)) x := (hasStrictDerivAt_log h).complexToReal_fderiv theorem contDiffAt_log {x : β„‚} (h : x ∈ slitPlane) {n : WithTop β„•βˆž} : ContDiffAt β„‚ n log x := expPartialHomeomorph.contDiffAt_symm_deriv (exp_ne_zero <| log x) h (hasDerivAt_exp _) contDiff_exp.contDiffAt end Complex section LogDeriv open Complex Filter open scoped Topology variable {Ξ± : Type*} [TopologicalSpace Ξ±] {E : Type*} [NormedAddCommGroup E] [NormedSpace β„‚ E] theorem HasStrictFDerivAt.clog {f : E β†’ β„‚} {f' : StrongDual β„‚ E} {x : E} (h₁ : HasStrictFDerivAt f f' x) (hβ‚‚ : f x ∈ slitPlane) : HasStrictFDerivAt (fun t => log (f t)) ((f x)⁻¹ β€’ f') x := (hasStrictDerivAt_log hβ‚‚).comp_hasStrictFDerivAt x h₁ theorem HasStrictDerivAt.clog {f : β„‚ β†’ β„‚} {f' x : β„‚} (h₁ : HasStrictDerivAt f f' x) (hβ‚‚ : f x ∈ slitPlane) : HasStrictDerivAt (fun t => log (f t)) (f' / f x) x := by rw [div_eq_inv_mul]; exact (hasStrictDerivAt_log hβ‚‚).comp x h₁ theorem HasStrictDerivAt.clog_real {f : ℝ β†’ β„‚} {x : ℝ} {f' : β„‚} (h₁ : HasStrictDerivAt f f' x) (hβ‚‚ : f x ∈ slitPlane) : HasStrictDerivAt (fun t => log (f t)) (f' / f x) x := by simpa only [div_eq_inv_mul] using (hasStrictFDerivAt_log_real hβ‚‚).comp_hasStrictDerivAt x h₁ theorem HasFDerivAt.clog {f : E β†’ β„‚} {f' : StrongDual β„‚ E} {x : E} (h₁ : HasFDerivAt f f' x) (hβ‚‚ : f x ∈ slitPlane) : HasFDerivAt (fun t => log (f t)) ((f x)⁻¹ β€’ f') x := (hasStrictDerivAt_log hβ‚‚).hasDerivAt.comp_hasFDerivAt x h₁ theorem HasDerivAt.clog {f : β„‚ β†’ β„‚} {f' x : β„‚} (h₁ : HasDerivAt f f' x) (hβ‚‚ : f x ∈ slitPlane) : HasDerivAt (fun t => log (f t)) (f' / f x) x := by rw [div_eq_inv_mul]; exact (hasStrictDerivAt_log hβ‚‚).hasDerivAt.comp x h₁ theorem HasDerivAt.clog_real {f : ℝ β†’ β„‚} {x : ℝ} {f' : β„‚} (h₁ : HasDerivAt f f' x) (hβ‚‚ : f x ∈ slitPlane) : HasDerivAt (fun t => log (f t)) (f' / f x) x := by simpa only [div_eq_inv_mul] using (hasStrictFDerivAt_log_real hβ‚‚).hasFDerivAt.comp_hasDerivAt x h₁ theorem DifferentiableAt.clog {f : E β†’ β„‚} {x : E} (h₁ : DifferentiableAt β„‚ f x) (hβ‚‚ : f x ∈ slitPlane) : DifferentiableAt β„‚ (fun t => log (f t)) x := (h₁.hasFDerivAt.clog hβ‚‚).differentiableAt theorem HasFDerivWithinAt.clog {f : E β†’ β„‚} {f' : StrongDual β„‚ E} {s : Set E} {x : E} (h₁ : HasFDerivWithinAt f f' s x) (hβ‚‚ : f x ∈ slitPlane) : HasFDerivWithinAt (fun t => log (f t)) ((f x)⁻¹ β€’ f') s x := (hasStrictDerivAt_log hβ‚‚).hasDerivAt.comp_hasFDerivWithinAt x h₁ theorem HasDerivWithinAt.clog {f : β„‚ β†’ β„‚} {f' x : β„‚} {s : Set β„‚} (h₁ : HasDerivWithinAt f f' s x) (hβ‚‚ : f x ∈ slitPlane) : HasDerivWithinAt (fun t => log (f t)) (f' / f x) s x := by rw [div_eq_inv_mul] exact (hasStrictDerivAt_log hβ‚‚).hasDerivAt.comp_hasDerivWithinAt x h₁ theorem HasDerivWithinAt.clog_real {f : ℝ β†’ β„‚} {s : Set ℝ} {x : ℝ} {f' : β„‚} (h₁ : HasDerivWithinAt f f' s x) (hβ‚‚ : f x ∈ slitPlane) : HasDerivWithinAt (fun t => log (f t)) (f' / f x) s x := by simpa only [div_eq_inv_mul] using (hasStrictFDerivAt_log_real hβ‚‚).hasFDerivAt.comp_hasDerivWithinAt x h₁ theorem DifferentiableWithinAt.clog {f : E β†’ β„‚} {s : Set E} {x : E} (h₁ : DifferentiableWithinAt β„‚ f s x) (hβ‚‚ : f x ∈ slitPlane) : DifferentiableWithinAt β„‚ (fun t => log (f t)) s x := (h₁.hasFDerivWithinAt.clog hβ‚‚).differentiableWithinAt theorem DifferentiableOn.clog {f : E β†’ β„‚} {s : Set E} (h₁ : DifferentiableOn β„‚ f s) (hβ‚‚ : βˆ€ x ∈ s, f x ∈ slitPlane) : DifferentiableOn β„‚ (fun t => log (f t)) s := fun x hx => (h₁ x hx).clog (hβ‚‚ x hx) theorem Differentiable.clog {f : E β†’ β„‚} (h₁ : Differentiable β„‚ f) (hβ‚‚ : βˆ€ x, f x ∈ slitPlane) : Differentiable β„‚ fun t => log (f t) := fun x => (h₁ x).clog (hβ‚‚ x) /-- The derivative of `log ∘ f` is the logarithmic derivative provided `f` is differentiable and we are on the slitPlane. -/ lemma Complex.deriv_log_comp_eq_logDeriv {f : β„‚ β†’ β„‚} {x : β„‚} (h₁ : DifferentiableAt β„‚ f x) (hβ‚‚ : f x ∈ Complex.slitPlane) : deriv (Complex.log ∘ f) x = logDeriv f x := by have A := (HasDerivAt.clog h₁.hasDerivAt hβ‚‚).deriv rw [← h₁.hasDerivAt.deriv] at A simp only [logDeriv, Pi.div_apply, ← A, Function.comp_def] end LogDeriv
.lake/packages/mathlib/Mathlib/Analysis/SpecialFunctions/Complex/Log.lean
import Mathlib.Analysis.SpecialFunctions.Complex.Arg import Mathlib.Analysis.SpecialFunctions.Log.Basic /-! # The complex `log` function Basic properties, relationship with `exp`. -/ noncomputable section namespace Complex open Set Filter Bornology open scoped Real Topology ComplexConjugate /-- Inverse of the `exp` function. Returns values such that `(log x).im > - Ο€` and `(log x).im ≀ Ο€`. `log 0 = 0` -/ @[pp_nodot] noncomputable def log (x : β„‚) : β„‚ := Real.log β€–xβ€– + arg x * I theorem log_re (x : β„‚) : x.log.re = Real.log β€–xβ€– := by simp [log] theorem log_im (x : β„‚) : x.log.im = x.arg := by simp [log] theorem neg_pi_lt_log_im (x : β„‚) : -Ο€ < (log x).im := by simp only [log_im, neg_pi_lt_arg] theorem log_im_le_pi (x : β„‚) : (log x).im ≀ Ο€ := by simp only [log_im, arg_le_pi] theorem exp_log {x : β„‚} (hx : x β‰  0) : exp (log x) = x := by rw [log, exp_add_mul_I, ← ofReal_sin, sin_arg, ← ofReal_cos, cos_arg hx, ← ofReal_exp, Real.exp_log (norm_pos_iff.mpr hx), mul_add, ofReal_div, ofReal_div, mul_div_cancelβ‚€ _ (ofReal_ne_zero.2 <| norm_ne_zero_iff.mpr hx), ← mul_assoc, mul_div_cancelβ‚€ _ (ofReal_ne_zero.2 <| norm_ne_zero_iff.mpr hx), re_add_im] @[simp] theorem range_exp : Set.range exp = {0}ᢜ := Set.ext fun x => ⟨by rintro ⟨x, rfl⟩ exact exp_ne_zero x, fun hx => ⟨log x, exp_log hx⟩⟩ theorem log_exp {x : β„‚} (hx₁ : -Ο€ < x.im) (hxβ‚‚ : x.im ≀ Ο€) : log (exp x) = x := by rw [log, norm_exp, Real.log_exp, exp_eq_exp_re_mul_sin_add_cos, ← ofReal_exp, arg_mul_cos_add_sin_mul_I (Real.exp_pos _) ⟨hx₁, hxβ‚‚βŸ©, re_add_im] theorem exp_inj_of_neg_pi_lt_of_le_pi {x y : β„‚} (hx₁ : -Ο€ < x.im) (hxβ‚‚ : x.im ≀ Ο€) (hy₁ : -Ο€ < y.im) (hyβ‚‚ : y.im ≀ Ο€) (hxy : exp x = exp y) : x = y := by rw [← log_exp hx₁ hxβ‚‚, ← log_exp hy₁ hyβ‚‚, hxy] theorem ofReal_log {x : ℝ} (hx : 0 ≀ x) : (x.log : β„‚) = log x := Complex.ext (by rw [log_re, ofReal_re, Complex.norm_of_nonneg hx]) (by rw [ofReal_im, log_im, arg_ofReal_of_nonneg hx]) @[simp, norm_cast] lemma natCast_log {n : β„•} : Real.log n = log n := ofReal_natCast n β–Έ ofReal_log n.cast_nonneg @[simp] lemma ofNat_log {n : β„•} [n.AtLeastTwo] : Real.log ofNat(n) = log (OfNat.ofNat n) := natCast_log theorem log_ofReal_re (x : ℝ) : (log (x : β„‚)).re = Real.log x := by simp [log_re] theorem log_ofReal_mul {r : ℝ} (hr : 0 < r) {x : β„‚} (hx : x β‰  0) : log (r * x) = Real.log r + log x := by replace hx := norm_ne_zero_iff.mpr hx simp_rw [log, norm_mul, norm_real, arg_real_mul _ hr, Real.norm_of_nonneg hr.le, Real.log_mul hr.ne' hx, ofReal_add, add_assoc] theorem log_mul_ofReal (r : ℝ) (hr : 0 < r) (x : β„‚) (hx : x β‰  0) : log (x * r) = Real.log r + log x := by rw [mul_comm, log_ofReal_mul hr hx] lemma log_mul_eq_add_log_iff {x y : β„‚} (hxβ‚€ : x β‰  0) (hyβ‚€ : y β‰  0) : log (x * y) = log x + log y ↔ arg x + arg y ∈ Set.Ioc (-Ο€) Ο€ := by refine Complex.ext_iff.trans <| Iff.trans ?_ <| arg_mul_eq_add_arg_iff hxβ‚€ hyβ‚€ simp_rw [add_re, add_im, log_re, log_im, norm_mul, Real.log_mul (norm_ne_zero_iff.mpr hxβ‚€) (norm_ne_zero_iff.mpr hyβ‚€), true_and] alias ⟨_, log_mul⟩ := log_mul_eq_add_log_iff @[simp] theorem log_zero : log 0 = 0 := by simp [log] @[simp] theorem log_one : log 1 = 0 := by simp [log] /-- This holds true for all `x : β„‚` because of the junk values `0 / 0 = 0` and `log 0 = 0`. -/ @[simp] lemma log_div_self (x : β„‚) : log (x / x) = 0 := by simp [log] theorem log_neg_one : log (-1) = Ο€ * I := by simp [log] theorem log_I : log I = Ο€ / 2 * I := by simp [log] theorem log_neg_I : log (-I) = -(Ο€ / 2) * I := by simp [log] theorem log_conj_eq_ite (x : β„‚) : log (conj x) = if x.arg = Ο€ then log x else conj (log x) := by simp_rw [log, norm_conj, arg_conj, map_add, map_mul, conj_ofReal] split_ifs with hx Β· rw [hx] simp_rw [ofReal_neg, conj_I, mul_neg, neg_mul] theorem log_conj (x : β„‚) (h : x.arg β‰  Ο€) : log (conj x) = conj (log x) := by rw [log_conj_eq_ite, if_neg h] theorem log_inv_eq_ite (x : β„‚) : log x⁻¹ = if x.arg = Ο€ then -conj (log x) else -log x := by by_cases hx : x = 0 Β· simp [hx] rw [inv_def, log_mul_ofReal, Real.log_inv, ofReal_neg, ← sub_eq_neg_add, log_conj_eq_ite] Β· simp_rw [log, map_add, map_mul, conj_ofReal, conj_I, normSq_eq_norm_sq, Real.log_pow, Nat.cast_two, ofReal_mul, neg_add, mul_neg, neg_neg] norm_num grind Β· rwa [inv_pos, Complex.normSq_pos] Β· rwa [map_ne_zero] theorem log_inv (x : β„‚) (hx : x.arg β‰  Ο€) : log x⁻¹ = -log x := by rw [log_inv_eq_ite, if_neg hx] theorem two_pi_I_ne_zero : (2 * Ο€ * I : β„‚) β‰  0 := by simp [Real.pi_ne_zero, I_ne_zero] theorem exp_eq_one_iff {x : β„‚} : exp x = 1 ↔ βˆƒ n : β„€, x = n * (2 * Ο€ * I) := by constructor Β· intro h rcases existsUnique_add_zsmul_mem_Ioc Real.two_pi_pos x.im (-Ο€) with ⟨n, hn, -⟩ use -n rw [Int.cast_neg, neg_mul, eq_neg_iff_add_eq_zero] have : (x + n * (2 * Ο€ * I)).im ∈ Set.Ioc (-Ο€) Ο€ := by simpa [two_mul, mul_add] using hn rw [← log_exp this.1 this.2, exp_periodic.int_mul n, h, log_one] Β· rintro ⟨n, rfl⟩ exact (exp_periodic.int_mul n).eq.trans exp_zero theorem exp_eq_exp_iff_exp_sub_eq_one {x y : β„‚} : exp x = exp y ↔ exp (x - y) = 1 := by rw [exp_sub, div_eq_one_iff_eq (exp_ne_zero _)] theorem exp_eq_exp_iff_exists_int {x y : β„‚} : exp x = exp y ↔ βˆƒ n : β„€, x = y + n * (2 * Ο€ * I) := by simp only [exp_eq_exp_iff_exp_sub_eq_one, exp_eq_one_iff, sub_eq_iff_eq_add'] theorem log_exp_exists (z : β„‚) : βˆƒ n : β„€, log (exp z) = z + n * (2 * Ο€ * I) := by rw [← exp_eq_exp_iff_exists_int, exp_log] exact exp_ne_zero z @[simp] theorem countable_preimage_exp {s : Set β„‚} : (exp ⁻¹' s).Countable ↔ s.Countable := by refine ⟨fun hs => ?_, fun hs => ?_⟩ Β· refine ((hs.image exp).insert 0).mono ?_ rw [Set.image_preimage_eq_inter_range, range_exp, ← Set.diff_eq, ← Set.union_singleton, Set.diff_union_self] exact Set.subset_union_left Β· rw [← Set.biUnion_preimage_singleton] refine hs.biUnion fun z hz => ?_ by_cases! h : βˆƒ w, exp w = z Β· rcases h with ⟨w, rfl⟩ simp only [Set.preimage, Set.mem_singleton_iff, exp_eq_exp_iff_exists_int, Set.setOf_exists] exact Set.countable_iUnion fun m => Set.countable_singleton _ Β· simp [Set.preimage, h] alias ⟨_, _root_.Set.Countable.preimage_cexp⟩ := countable_preimage_exp theorem tendsto_log_nhdsWithin_im_neg_of_re_neg_of_im_zero {z : β„‚} (hre : z.re < 0) (him : z.im = 0) : Tendsto log (𝓝[{ z : β„‚ | z.im < 0 }] z) (𝓝 <| Real.log β€–zβ€– - Ο€ * I) := by convert (continuous_ofReal.continuousAt.comp_continuousWithinAt (continuous_norm.continuousWithinAt.log _)).tendsto.add (((continuous_ofReal.tendsto _).comp <| tendsto_arg_nhdsWithin_im_neg_of_re_neg_of_im_zero hre him).mul tendsto_const_nhds) using 1 Β· simp [sub_eq_add_neg] Β· lift z to ℝ using him simpa using hre.ne theorem continuousWithinAt_log_of_re_neg_of_im_zero {z : β„‚} (hre : z.re < 0) (him : z.im = 0) : ContinuousWithinAt log { z : β„‚ | 0 ≀ z.im } z := by convert (continuous_ofReal.continuousAt.comp_continuousWithinAt (continuous_norm.continuousWithinAt.log _)).tendsto.add ((continuous_ofReal.continuousAt.comp_continuousWithinAt <| continuousWithinAt_arg_of_re_neg_of_im_zero hre him).mul tendsto_const_nhds) using 1 lift z to ℝ using him simpa using hre.ne theorem tendsto_log_nhdsWithin_im_nonneg_of_re_neg_of_im_zero {z : β„‚} (hre : z.re < 0) (him : z.im = 0) : Tendsto log (𝓝[{ z : β„‚ | 0 ≀ z.im }] z) (𝓝 <| Real.log β€–zβ€– + Ο€ * I) := by simpa only [log, arg_eq_pi_iff.2 ⟨hre, him⟩] using (continuousWithinAt_log_of_re_neg_of_im_zero hre him).tendsto @[simp] theorem map_exp_comap_re_atBot : map exp (comap re atBot) = 𝓝[β‰ ] 0 := by rw [← comap_exp_nhds_zero, map_comap, range_exp, nhdsWithin] @[simp] theorem map_exp_comap_re_atTop : map exp (comap re atTop) = cobounded β„‚ := by rw [← comap_exp_cobounded, map_comap, range_exp, inf_eq_left, le_principal_iff] exact eventually_ne_cobounded _ end Complex section LogDeriv open Complex Filter open Topology variable {Ξ± : Type*} theorem continuousAt_clog {x : β„‚} (h : x ∈ slitPlane) : ContinuousAt log x := by refine ContinuousAt.add ?_ ?_ Β· refine continuous_ofReal.continuousAt.comp ?_ refine (Real.continuousAt_log ?_).comp continuous_norm.continuousAt exact norm_ne_zero_iff.mpr <| slitPlane_ne_zero h Β· have h_cont_mul : Continuous fun x : β„‚ => x * I := continuous_id'.mul continuous_const refine h_cont_mul.continuousAt.comp (continuous_ofReal.continuousAt.comp ?_) exact continuousAt_arg h theorem _root_.Filter.Tendsto.clog {l : Filter Ξ±} {f : Ξ± β†’ β„‚} {x : β„‚} (h : Tendsto f l (𝓝 x)) (hx : x ∈ slitPlane) : Tendsto (fun t => log (f t)) l (𝓝 <| log x) := (continuousAt_clog hx).tendsto.comp h variable [TopologicalSpace Ξ±] nonrec theorem _root_.ContinuousAt.clog {f : Ξ± β†’ β„‚} {x : Ξ±} (h₁ : ContinuousAt f x) (hβ‚‚ : f x ∈ slitPlane) : ContinuousAt (fun t => log (f t)) x := h₁.clog hβ‚‚ nonrec theorem _root_.ContinuousWithinAt.clog {f : Ξ± β†’ β„‚} {s : Set Ξ±} {x : Ξ±} (h₁ : ContinuousWithinAt f s x) (hβ‚‚ : f x ∈ slitPlane) : ContinuousWithinAt (fun t => log (f t)) s x := h₁.clog hβ‚‚ nonrec theorem _root_.ContinuousOn.clog {f : Ξ± β†’ β„‚} {s : Set Ξ±} (h₁ : ContinuousOn f s) (hβ‚‚ : βˆ€ x ∈ s, f x ∈ slitPlane) : ContinuousOn (fun t => log (f t)) s := fun x hx => (h₁ x hx).clog (hβ‚‚ x hx) nonrec theorem _root_.Continuous.clog {f : Ξ± β†’ β„‚} (h₁ : Continuous f) (hβ‚‚ : βˆ€ x, f x ∈ slitPlane) : Continuous fun t => log (f t) := continuous_iff_continuousAt.2 fun x => h₁.continuousAt.clog (hβ‚‚ x) end LogDeriv
.lake/packages/mathlib/Mathlib/Analysis/SpecialFunctions/Complex/Circle.lean
import Mathlib.Analysis.Complex.Circle import Mathlib.Analysis.SpecialFunctions.Complex.Log /-! # Maps on the unit circle In this file we prove some basic lemmas about `expMapCircle` and the restriction of `Complex.arg` to the unit circle. These two maps define a partial equivalence between `circle` and `ℝ`, see `circle.argPartialEquiv` and `circle.argEquiv`, that sends the whole circle to `(-Ο€, Ο€]`. -/ open Complex Function Set open Real namespace Circle theorem injective_arg : Injective fun z : Circle => arg z := fun z w h => Subtype.ext <| ext_norm_arg (z.norm_coe.trans w.norm_coe.symm) h @[simp] theorem arg_eq_arg {z w : Circle} : arg z = arg w ↔ z = w := injective_arg.eq_iff theorem arg_exp {x : ℝ} (h₁ : -Ο€ < x) (hβ‚‚ : x ≀ Ο€) : arg (exp x) = x := by rw [coe_exp, exp_mul_I, arg_cos_add_sin_mul_I ⟨h₁, hβ‚‚βŸ©] @[simp] theorem exp_arg (z : Circle) : exp (arg z) = z := injective_arg <| arg_exp (neg_pi_lt_arg _) (arg_le_pi _) /-- `Complex.arg ∘ (↑)` and `expMapCircle` define a partial equivalence between `circle` and `ℝ` with `source = Set.univ` and `target = Set.Ioc (-Ο€) Ο€`. -/ @[simps -fullyApplied] noncomputable def argPartialEquiv : PartialEquiv Circle ℝ where toFun := arg ∘ (↑) invFun := exp source := univ target := Ioc (-Ο€) Ο€ map_source' _ _ := ⟨neg_pi_lt_arg _, arg_le_pi _⟩ map_target' := mapsTo_univ _ _ left_inv' z _ := exp_arg z right_inv' _ hx := arg_exp hx.1 hx.2 /-- `Complex.arg` and `expMapCircle` define an equivalence between `circle` and `(-Ο€, Ο€]`. -/ @[simps -fullyApplied] noncomputable def argEquiv : Circle ≃ Ioc (-Ο€) Ο€ where toFun z := ⟨arg z, neg_pi_lt_arg _, arg_le_pi _⟩ invFun := exp ∘ (↑) left_inv _ := argPartialEquiv.left_inv trivial right_inv x := Subtype.ext <| argPartialEquiv.right_inv x.2 lemma leftInverse_exp_arg : LeftInverse exp (arg ∘ (↑)) := exp_arg lemma invOn_arg_exp : InvOn (arg ∘ (↑)) exp (Ioc (-Ο€) Ο€) univ := argPartialEquiv.symm.invOn lemma surjOn_exp_neg_pi_pi : SurjOn exp (Ioc (-Ο€) Ο€) univ := argPartialEquiv.symm.surjOn lemma exp_eq_exp {x y : ℝ} : exp x = exp y ↔ βˆƒ m : β„€, x = y + m * (2 * Ο€) := by rw [Subtype.ext_iff, coe_exp, coe_exp, exp_eq_exp_iff_exists_int] refine exists_congr fun n => ?_ rw [← mul_assoc, ← add_mul, mul_left_inj' I_ne_zero] norm_cast lemma periodic_exp : Periodic exp (2 * Ο€) := fun z ↦ exp_eq_exp.2 ⟨1, by rw [Int.cast_one, one_mul]⟩ @[simp] lemma exp_two_pi : exp (2 * Ο€) = 1 := periodic_exp.eq.trans exp_zero lemma exp_int_mul_two_pi (n : β„€) : exp (n * (2 * Ο€)) = 1 := ext <| by simpa [mul_assoc] using Complex.exp_int_mul_two_pi_mul_I n lemma exp_two_pi_mul_int (n : β„€) : exp (2 * Ο€ * n) = 1 := by simpa only [mul_comm] using exp_int_mul_two_pi n lemma exp_eq_one {r : ℝ} : exp r = 1 ↔ βˆƒ n : β„€, r = n * (2 * Ο€) := by simp [Circle.ext_iff, Complex.exp_eq_one_iff, ← mul_assoc, Complex.I_ne_zero, ← Complex.ofReal_inj] lemma exp_inj {r s : ℝ} : exp r = exp s ↔ r ≑ s [PMOD (2 * Ο€)] := by simp [AddCommGroup.ModEq, ← exp_eq_one, div_eq_one, eq_comm (a := exp r)] lemma exp_sub_two_pi (x : ℝ) : exp (x - 2 * Ο€) = exp x := periodic_exp.sub_eq x lemma exp_add_two_pi (x : ℝ) : exp (x + 2 * Ο€) = exp x := periodic_exp x end Circle namespace Real.Angle /-- `Circle.exp`, applied to a `Real.Angle`. -/ noncomputable def toCircle (ΞΈ : Angle) : Circle := Circle.periodic_exp.lift ΞΈ @[simp] lemma toCircle_coe (x : ℝ) : toCircle x = .exp x := rfl lemma coe_toCircle (ΞΈ : Angle) : (ΞΈ.toCircle : β„‚) = ΞΈ.cos + ΞΈ.sin * I := by induction ΞΈ using Real.Angle.induction_on simp [exp_mul_I] @[simp] lemma toCircle_zero : toCircle 0 = 1 := by rw [← coe_zero, toCircle_coe, Circle.exp_zero] @[simp] lemma toCircle_neg (ΞΈ : Angle) : toCircle (-ΞΈ) = (toCircle ΞΈ)⁻¹ := by induction ΞΈ using Real.Angle.induction_on simp_rw [← coe_neg, toCircle_coe, Circle.exp_neg] @[simp] lemma toCircle_add (θ₁ ΞΈβ‚‚ : Angle) : toCircle (θ₁ + ΞΈβ‚‚) = toCircle θ₁ * toCircle ΞΈβ‚‚ := by induction θ₁ using Real.Angle.induction_on induction ΞΈβ‚‚ using Real.Angle.induction_on exact Circle.exp_add _ _ @[simp] lemma arg_toCircle (ΞΈ : Real.Angle) : (arg ΞΈ.toCircle : Angle) = ΞΈ := by induction ΞΈ using Real.Angle.induction_on rw [toCircle_coe, Circle.coe_exp, exp_mul_I, ← ofReal_cos, ← ofReal_sin, ← Real.Angle.cos_coe, ← Real.Angle.sin_coe, arg_cos_add_sin_mul_I_coe_angle] end Real.Angle namespace AddCircle variable {T : ℝ} /-! ### Map from `AddCircle` to `Circle` -/ theorem scaled_exp_map_periodic : Function.Periodic (fun x => Circle.exp (2 * Ο€ / T * x)) T := by -- The case T = 0 is not interesting, but it is true, so we prove it to save hypotheses rcases eq_or_ne T 0 with (rfl | hT) Β· simp Β· intro x; simp_rw [mul_add]; rw [div_mul_cancelβ‚€ _ hT, Circle.periodic_exp] /-- The canonical map `fun x => exp (2 Ο€ i x / T)` from `ℝ / β„€ β€’ T` to the unit circle in `β„‚`. If `T = 0` we understand this as the constant function 1. -/ noncomputable def toCircle : AddCircle T β†’ Circle := (@scaled_exp_map_periodic T).lift theorem toCircle_apply_mk (x : ℝ) : @toCircle T x = Circle.exp (2 * Ο€ / T * x) := rfl theorem toCircle_add (x : AddCircle T) (y : AddCircle T) : @toCircle T (x + y) = toCircle x * toCircle y := by induction x using QuotientAddGroup.induction_on induction y using QuotientAddGroup.induction_on simp_rw [← coe_add, toCircle_apply_mk, mul_add, Circle.exp_add] @[simp] lemma toCircle_zero : toCircle (0 : AddCircle T) = 1 := by rw [← QuotientAddGroup.mk_zero, toCircle_apply_mk, mul_zero, Circle.exp_zero] theorem continuous_toCircle : Continuous (@toCircle T) := continuous_coinduced_dom.mpr (Circle.exp.continuous.comp <| continuous_const.mul continuous_id') theorem injective_toCircle (hT : T β‰  0) : Function.Injective (@toCircle T) := by intro a b h induction a using QuotientAddGroup.induction_on induction b using QuotientAddGroup.induction_on simp_rw [toCircle_apply_mk] at h obtain ⟨m, hm⟩ := Circle.exp_eq_exp.mp h.symm rw [QuotientAddGroup.eq]; simp_rw [AddSubgroup.mem_zmultiples_iff, zsmul_eq_mul] use m field_simp at hm linarith /-- The homeomorphism between `AddCircle (2 * Ο€)` and `Circle`. -/ @[simps] noncomputable def homeomorphCircle' : AddCircle (2 * Ο€) β‰ƒβ‚œ Circle where toFun := Angle.toCircle invFun := fun x ↦ arg x left_inv := Angle.arg_toCircle right_inv := Circle.exp_arg continuous_toFun := continuous_coinduced_dom.mpr Circle.exp.continuous continuous_invFun := by rw [continuous_iff_continuousAt] intro x exact (continuousAt_arg_coe_angle x.coe_ne_zero).comp continuousAt_subtype_val theorem homeomorphCircle'_apply_mk (x : ℝ) : homeomorphCircle' x = Circle.exp x := rfl /-- The homeomorphism between `AddCircle` and `Circle`. -/ noncomputable def homeomorphCircle (hT : T β‰  0) : AddCircle T β‰ƒβ‚œ Circle := (homeomorphAddCircle T (2 * Ο€) hT (by positivity)).trans homeomorphCircle' theorem homeomorphCircle_apply (hT : T β‰  0) (x : AddCircle T) : homeomorphCircle hT x = toCircle x := by cases x using QuotientAddGroup.induction_on rw [homeomorphCircle, Homeomorph.trans_apply, homeomorphAddCircle_apply_mk, homeomorphCircle'_apply_mk, toCircle_apply_mk] ring_nf end AddCircle open AddCircle -- todo: upgrade this to `IsCoveringMap Circle.exp`. lemma isLocalHomeomorph_circleExp : IsLocalHomeomorph Circle.exp := by have : Fact (0 < 2 * Ο€) := ⟨by positivity⟩ exact homeomorphCircle'.isLocalHomeomorph.comp (isLocalHomeomorph_coe (2 * Ο€))
.lake/packages/mathlib/Mathlib/Analysis/SpecialFunctions/Integrability/Basic.lean
import Mathlib.Analysis.SpecialFunctions.Log.NegMulLog import Mathlib.Analysis.SpecialFunctions.NonIntegrable import Mathlib.Analysis.SpecialFunctions.Pow.Deriv /-! # Integrability of Special Functions This file establishes basic facts about the interval integrability of special functions, including powers and the logarithm. -/ open Interval MeasureTheory Real Set variable {a b c d : ℝ} (n : β„•) {f : ℝ β†’ ℝ} {ΞΌ : Measure ℝ} [IsLocallyFiniteMeasure ΞΌ] namespace intervalIntegral @[simp] theorem intervalIntegrable_pow : IntervalIntegrable (fun x => x ^ n) ΞΌ a b := (continuous_pow n).intervalIntegrable a b theorem intervalIntegrable_zpow {n : β„€} (h : 0 ≀ n ∨ (0 : ℝ) βˆ‰ [[a, b]]) : IntervalIntegrable (fun x => x ^ n) ΞΌ a b := (continuousOn_id.zpowβ‚€ n fun _ hx => h.symm.imp (ne_of_mem_of_not_mem hx) id).intervalIntegrable /-- See `intervalIntegrable_rpow'` for a version with a weaker hypothesis on `r`, but assuming the measure is volume. -/ theorem intervalIntegrable_rpow {r : ℝ} (h : 0 ≀ r ∨ (0 : ℝ) βˆ‰ [[a, b]]) : IntervalIntegrable (fun x => x ^ r) ΞΌ a b := (continuousOn_id.rpow_const fun _ hx => h.symm.imp (ne_of_mem_of_not_mem hx) id).intervalIntegrable /-- See `intervalIntegrable_rpow` for a version applying to any locally finite measure, but with a stronger hypothesis on `r`. -/ theorem intervalIntegrable_rpow' {r : ℝ} (h : -1 < r) : IntervalIntegrable (fun x => x ^ r) volume a b := by suffices βˆ€ c : ℝ, IntervalIntegrable (fun x => x ^ r) volume 0 c by exact IntervalIntegrable.trans (this a).symm (this b) have : βˆ€ c : ℝ, 0 ≀ c β†’ IntervalIntegrable (fun x => x ^ r) volume 0 c := by intro c hc rw [intervalIntegrable_iff, uIoc_of_le hc] have hderiv : βˆ€ x ∈ Ioo 0 c, HasDerivAt (fun x : ℝ => x ^ (r + 1) / (r + 1)) (x ^ r) x := by intro x hx convert (Real.hasDerivAt_rpow_const (p := r + 1) (Or.inl hx.1.ne')).div_const (r + 1) using 1 simp [(by linarith : r + 1 β‰  0)] apply integrableOn_deriv_of_nonneg _ hderiv Β· intro x hx; apply rpow_nonneg hx.1.le Β· refine (continuousOn_id.rpow_const ?_).div_const _; intro x _; right; linarith intro c; rcases le_total 0 c with (hc | hc) Β· exact this c hc Β· rw [IntervalIntegrable.iff_comp_neg, neg_zero] have m := (this (-c) (by linarith)).smul (cos (r * Ο€)) rw [intervalIntegrable_iff] at m ⊒ refine m.congr_fun ?_ measurableSet_Ioc; intro x hx rw [uIoc_of_le (by linarith : 0 ≀ -c)] at hx simp only [Pi.smul_apply, Algebra.id.smul_eq_mul, log_neg_eq_log, mul_comm, rpow_def_of_pos hx.1, rpow_def_of_neg (by linarith [hx.1] : -x < 0)] /-- The power function `x ↦ x^s` is integrable on `(0, t)` iff `-1 < s`. -/ lemma integrableOn_Ioo_rpow_iff {s t : ℝ} (ht : 0 < t) : IntegrableOn (fun x ↦ x ^ s) (Ioo (0 : ℝ) t) ↔ -1 < s := by refine ⟨fun h ↦ ?_, fun h ↦ ?_⟩ swap Β· rw [← intervalIntegrable_iff_integrableOn_Ioo_of_le ht.le] apply intervalIntegrable_rpow' h (a := 0) (b := t) contrapose! h intro H have I : 0 < min 1 t := lt_min zero_lt_one ht have H' : IntegrableOn (fun x ↦ x ^ s) (Ioo 0 (min 1 t)) := H.mono (Set.Ioo_subset_Ioo le_rfl (min_le_right _ _)) le_rfl have : IntegrableOn (fun x ↦ x⁻¹) (Ioo 0 (min 1 t)) := by apply H'.mono' measurable_inv.aestronglyMeasurable filter_upwards [ae_restrict_mem measurableSet_Ioo] with x hx simp only [norm_inv, Real.norm_eq_abs, abs_of_nonneg (le_of_lt hx.1)] rwa [← Real.rpow_neg_one x, Real.rpow_le_rpow_left_iff_of_base_lt_one hx.1] exact lt_of_lt_of_le hx.2 (min_le_left _ _) have : IntervalIntegrable (fun x ↦ x⁻¹) volume 0 (min 1 t) := by rwa [intervalIntegrable_iff_integrableOn_Ioo_of_le I.le] simp [intervalIntegrable_inv_iff, I.ne] at this /-- See `intervalIntegrable_cpow'` for a version with a weaker hypothesis on `r`, but assuming the measure is volume. -/ theorem intervalIntegrable_cpow {r : β„‚} (h : 0 ≀ r.re ∨ (0 : ℝ) βˆ‰ [[a, b]]) : IntervalIntegrable (fun x : ℝ => (x : β„‚) ^ r) ΞΌ a b := by by_cases h2 : (0 : ℝ) βˆ‰ [[a, b]] Β· -- Easy case #1: 0 βˆ‰ [a, b] -- use continuity. refine (continuousOn_of_forall_continuousAt fun x hx => ?_).intervalIntegrable exact Complex.continuousAt_ofReal_cpow_const _ _ (Or.inr <| ne_of_mem_of_not_mem hx h2) rw [eq_false h2, or_false] at h rcases lt_or_eq_of_le h with (h' | h') Β· -- Easy case #2: 0 < re r -- again use continuity exact (Complex.continuous_ofReal_cpow_const h').intervalIntegrable _ _ -- Now the hard case: re r = 0 and 0 is in the interval. refine (IntervalIntegrable.intervalIntegrable_norm_iff ?_).mp ?_ Β· refine (measurable_of_continuousOn_compl_singleton (0 : ℝ) ?_).aestronglyMeasurable exact continuousOn_of_forall_continuousAt fun x hx => Complex.continuousAt_ofReal_cpow_const x r (Or.inr hx) -- reduce to case of integral over `[0, c]` suffices βˆ€ c : ℝ, IntervalIntegrable (fun x : ℝ => β€–(x : β„‚) ^ rβ€–) ΞΌ 0 c from (this a).symm.trans (this b) intro c rcases le_or_gt 0 c with (hc | hc) Β· -- case `0 ≀ c`: integrand is identically 1 have : IntervalIntegrable (fun _ => 1 : ℝ β†’ ℝ) ΞΌ 0 c := intervalIntegrable_const rw [intervalIntegrable_iff_integrableOn_Ioc_of_le hc] at this ⊒ refine IntegrableOn.congr_fun this (fun x hx => ?_) measurableSet_Ioc dsimp only rw [Complex.norm_cpow_eq_rpow_re_of_pos hx.1, ← h', rpow_zero] Β· -- case `c < 0`: integrand is identically constant, *except* at `x = 0` if `r β‰  0`. apply IntervalIntegrable.symm rw [intervalIntegrable_iff_integrableOn_Ioc_of_le hc.le] rw [← Ioo_union_right hc, integrableOn_union, and_comm]; constructor Β· exact integrableOn_singleton (by simp) <| isFiniteMeasureOnCompacts_of_isLocallyFiniteMeasure.lt_top_of_isCompact isCompact_singleton Β· have : βˆ€ x : ℝ, x ∈ Ioo c 0 β†’ β€–Complex.exp (↑π * Complex.I * r)β€– = β€–(x : β„‚) ^ rβ€– := by intro x hx rw [Complex.ofReal_cpow_of_nonpos hx.2.le, norm_mul, ← Complex.ofReal_neg, Complex.norm_cpow_eq_rpow_re_of_pos (neg_pos.mpr hx.2), ← h', rpow_zero, one_mul] refine IntegrableOn.congr_fun ?_ this measurableSet_Ioo rw [integrableOn_const_iff] right refine (measure_mono Set.Ioo_subset_Icc_self).trans_lt ?_ exact isFiniteMeasureOnCompacts_of_isLocallyFiniteMeasure.lt_top_of_isCompact isCompact_Icc /-- See `intervalIntegrable_cpow` for a version applying to any locally finite measure, but with a stronger hypothesis on `r`. -/ theorem intervalIntegrable_cpow' {r : β„‚} (h : -1 < r.re) : IntervalIntegrable (fun x : ℝ => (x : β„‚) ^ r) volume a b := by suffices βˆ€ c : ℝ, IntervalIntegrable (fun x => (x : β„‚) ^ r) volume 0 c by exact IntervalIntegrable.trans (this a).symm (this b) have : βˆ€ c : ℝ, 0 ≀ c β†’ IntervalIntegrable (fun x => (x : β„‚) ^ r) volume 0 c := by intro c hc rw [← IntervalIntegrable.intervalIntegrable_norm_iff] Β· rw [intervalIntegrable_iff] apply IntegrableOn.congr_fun Β· rw [← intervalIntegrable_iff]; exact intervalIntegral.intervalIntegrable_rpow' h Β· intro x hx rw [uIoc_of_le hc] at hx dsimp only rw [Complex.norm_cpow_eq_rpow_re_of_pos hx.1] Β· exact measurableSet_uIoc Β· refine ContinuousOn.aestronglyMeasurable ?_ measurableSet_uIoc refine continuousOn_of_forall_continuousAt fun x hx => ?_ rw [uIoc_of_le hc] at hx refine (continuousAt_cpow_const (Or.inl ?_)).comp Complex.continuous_ofReal.continuousAt rw [Complex.ofReal_re] exact hx.1 intro c; rcases le_total 0 c with (hc | hc) Β· exact this c hc Β· rw [IntervalIntegrable.iff_comp_neg, neg_zero] have m := (this (-c) (by linarith)).const_mul (Complex.exp (Ο€ * Complex.I * r)) rw [intervalIntegrable_iff, uIoc_of_le (by linarith : 0 ≀ -c)] at m ⊒ refine m.congr_fun (fun x hx => ?_) measurableSet_Ioc dsimp only have : -x ≀ 0 := by linarith [hx.1] rw [Complex.ofReal_cpow_of_nonpos this, mul_comm] simp /-- The complex power function `x ↦ x^s` is integrable on `(0, t)` iff `-1 < s.re`. -/ theorem integrableOn_Ioo_cpow_iff {s : β„‚} {t : ℝ} (ht : 0 < t) : IntegrableOn (fun x : ℝ ↦ (x : β„‚) ^ s) (Ioo (0 : ℝ) t) ↔ -1 < s.re := by refine ⟨fun h ↦ ?_, fun h ↦ ?_⟩ swap Β· rw [← intervalIntegrable_iff_integrableOn_Ioo_of_le ht.le] exact intervalIntegrable_cpow' h (a := 0) (b := t) have B : IntegrableOn (fun a ↦ a ^ s.re) (Ioo 0 t) := by apply (integrableOn_congr_fun _ measurableSet_Ioo).1 h.norm intro a ha simp [Complex.norm_cpow_eq_rpow_re_of_pos ha.1] rwa [integrableOn_Ioo_rpow_iff ht] at B @[simp] theorem intervalIntegrable_id : IntervalIntegrable (fun x => x) ΞΌ a b := continuous_id.intervalIntegrable a b theorem intervalIntegrable_const : IntervalIntegrable (fun _ => c) ΞΌ a b := continuous_const.intervalIntegrable a b theorem intervalIntegrable_one_div (h : βˆ€ x : ℝ, x ∈ [[a, b]] β†’ f x β‰  0) (hf : ContinuousOn f [[a, b]]) : IntervalIntegrable (fun x => 1 / f x) ΞΌ a b := (continuousOn_const.div hf h).intervalIntegrable @[simp] theorem intervalIntegrable_inv (h : βˆ€ x : ℝ, x ∈ [[a, b]] β†’ f x β‰  0) (hf : ContinuousOn f [[a, b]]) : IntervalIntegrable (fun x => (f x)⁻¹) ΞΌ a b := by simpa only [one_div] using intervalIntegrable_one_div h hf @[simp] theorem intervalIntegrable_sin : IntervalIntegrable sin ΞΌ a b := continuous_sin.intervalIntegrable a b @[simp] theorem intervalIntegrable_cos : IntervalIntegrable cos ΞΌ a b := continuous_cos.intervalIntegrable a b @[simp] theorem intervalIntegrable_exp : IntervalIntegrable exp ΞΌ a b := continuous_exp.intervalIntegrable a b @[simp] theorem _root_.IntervalIntegrable.log (hf : ContinuousOn f [[a, b]]) (h : βˆ€ x : ℝ, x ∈ [[a, b]] β†’ f x β‰  0) : IntervalIntegrable (fun x => log (f x)) ΞΌ a b := (ContinuousOn.log hf h).intervalIntegrable /-- The real logarithm is interval integrable (with respect to every locally finite measure) over every interval that does not contain zero. See `intervalIntegrable_log'` for a version without any hypothesis on the interval, but assuming the measure is the volume. -/ @[simp] theorem intervalIntegrable_log (h : (0 : ℝ) βˆ‰ [[a, b]]) : IntervalIntegrable log ΞΌ a b := IntervalIntegrable.log continuousOn_id fun _ hx => ne_of_mem_of_not_mem hx h /-- The real logarithm is interval integrable (with respect to the volume measure) on every interval. See `intervalIntegrable_log` for a version applying to any locally finite measure, but with an additional hypothesis on the interval. -/ @[simp] theorem intervalIntegrable_log' : IntervalIntegrable log volume a b := by -- Log is even, so it suffices to consider the case 0 < a and b = 0 apply intervalIntegrable_of_even (log_neg_eq_log Β· |>.symm) intro x hx -- Split integral apply IntervalIntegrable.trans (b := 1) Β· -- Show integrability on [0…1] using non-negativity of the derivative rw [← neg_neg log] apply IntervalIntegrable.neg apply intervalIntegrable_deriv_of_nonneg (g := fun x ↦ -(x * log x - x)) Β· exact (continuous_mul_log.continuousOn.sub continuous_id.continuousOn).neg Β· intro s ⟨hs, _⟩ norm_num at * simpa using (hasDerivAt_id s).sub (hasDerivAt_mul_log hs.ne.symm) Β· intro s ⟨hs₁, hsβ‚‚βŸ© norm_num at * exact (log_nonpos_iff hs₁.le).mpr hsβ‚‚.le Β· -- Show integrability on [1…t] by continuity apply ContinuousOn.intervalIntegrable apply Real.continuousOn_log.mono apply Set.notMem_uIcc_of_lt zero_lt_one at hx simpa theorem intervalIntegrable_one_div_one_add_sq : IntervalIntegrable (fun x : ℝ => 1 / (↑1 + x ^ 2)) ΞΌ a b := by refine (continuous_const.div ?_ fun x => ?_).intervalIntegrable a b Β· fun_prop Β· nlinarith @[simp] theorem intervalIntegrable_inv_one_add_sq : IntervalIntegrable (fun x : ℝ => (↑1 + x ^ 2)⁻¹) ΞΌ a b := by simp [← one_div, intervalIntegrable_one_div_one_add_sq] end intervalIntegral
.lake/packages/mathlib/Mathlib/Analysis/SpecialFunctions/Integrability/LogMeromorphic.lean
import Mathlib.Analysis.Meromorphic.FactorizedRational import Mathlib.Analysis.NormedSpace.Connected import Mathlib.Analysis.SpecialFunctions.Integrability.Basic import Mathlib.Analysis.SpecialFunctions.Log.PosLog import Mathlib.LinearAlgebra.Complex.FiniteDimensional import Mathlib.MeasureTheory.Integral.CircleIntegral /-! # Integrability for Logarithms of Meromorphic Functions We establish integrability for functions of the form `log β€–meromorphicβ€–`. In the real setting, these functions are interval integrable over every interval of the real line. This implies in particular that logarithms of trigonometric functions are interval integrable. In the complex setting, the functions are circle integrable over every circle in the complex plane. -/ open Filter Interval MeasureTheory MeromorphicOn Metric Real /-! ## Interval Integrability for Logarithms of Real Meromorphic Functions -/ section IntervalIntegrable variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] {f : ℝ β†’ E} {a b : ℝ} /-- If `f` is real-meromorphic on a compact interval, then `log β€–f Β·β€–` is interval integrable on this interval. -/ theorem intervalIntegrable_log_norm_meromorphicOn (hf : MeromorphicOn f [[a, b]]) : IntervalIntegrable (log β€–f Β·β€–) volume a b := by by_cases tβ‚€ : βˆ€ u : [[a, b]], meromorphicOrderAt f u β‰  ⊀ Β· obtain ⟨g, h₁g, hβ‚‚g, h₃g⟩ := hf.extract_zeros_poles tβ‚€ ((MeromorphicOn.divisor f [[a, b]]).finiteSupport isCompact_uIcc) have hβ‚„g := MeromorphicOn.extract_zeros_poles_log hβ‚‚g h₃g rw [intervalIntegrable_congr_codiscreteWithin (hβ‚„g.filter_mono (Filter.codiscreteWithin.mono Set.uIoc_subset_uIcc))] apply IntervalIntegrable.add Β· apply IntervalIntegrable.finsum intro i apply IntervalIntegrable.const_mul rw [(by ring : a = ((a - i) + i)), (by ring : b = ((b - i) + i))] apply IntervalIntegrable.comp_sub_right (f := (log β€–Β·β€–)) _ i simp [norm_eq_abs, log_abs] Β· apply ContinuousOn.intervalIntegrable apply h₁g.continuousOn.norm.log simp_all Β· rw [← hf.exists_meromorphicOrderAt_ne_top_iff_forall (isConnected_Icc inf_le_sup)] at tβ‚€ push_neg at tβ‚€ have : (log β€–f Β·β€–) =αΆ [Filter.codiscreteWithin (Ξ™ a b)] 0 := by apply Filter.EventuallyEq.filter_mono _ (Filter.codiscreteWithin.mono Set.uIoc_subset_uIcc) filter_upwards [hf.meromorphicNFAt_mem_codiscreteWithin, Filter.self_mem_codiscreteWithin [[a, b]]] with x h₁x hβ‚‚x simp only [Pi.zero_apply, log_eq_zero, norm_eq_zero] left by_contra hCon simp_all [← h₁x.meromorphicOrderAt_eq_zero_iff, tβ‚€ ⟨x, hβ‚‚x⟩] rw [intervalIntegrable_congr_codiscreteWithin this] apply Iff.mpr _root_.intervalIntegrable_const_iff tauto /-- If `f` is real-meromorphic on a compact interval, then `log β€–f Β·β€–` is interval integrable on this interval. -/ theorem intervalIntegrable_posLog_norm_meromorphicOn (hf : MeromorphicOn f [[a, b]]) : IntervalIntegrable (log⁺ β€–f Β·β€–) volume a b := by simp_rw [← half_mul_log_add_log_abs, mul_add] apply IntervalIntegrable.add Β· apply (intervalIntegrable_log_norm_meromorphicOn hf).const_mul Β· apply (intervalIntegrable_log_norm_meromorphicOn hf).abs.const_mul /-- If `f` is real-meromorphic on a compact interval, then `log ∘ f` is interval integrable on this interval. -/ theorem _root_.MeromorphicOn.intervalIntegrable_log {f : ℝ β†’ ℝ} (hf : MeromorphicOn f [[a, b]]) : IntervalIntegrable (log ∘ f) volume a b := by rw [(by aesop : log ∘ f = (log β€–f Β·β€–))] exact intervalIntegrable_log_norm_meromorphicOn hf /-- Special case of `MeromorphicOn.intervalIntegrable_log`: The function `log ∘ sin` is interval integrable over every interval. -/ theorem intervalIntegrable_log_sin : IntervalIntegrable (log ∘ sin) volume a b := analyticOnNhd_sin.meromorphicOn.intervalIntegrable_log /-- Special case of `MeromorphicOn.intervalIntegrable_log`: The function `log ∘ cos` is interval integrable over every interval. -/ theorem intervalIntegrable_log_cos : IntervalIntegrable (log ∘ cos) volume a b := analyticOnNhd_cos.meromorphicOn.intervalIntegrable_log end IntervalIntegrable /-! ## Circle Integrability for Logarithms of Complex Meromorphic Functions -/ section CircleIntegrable variable {E : Type*} [NormedAddCommGroup E] [NormedSpace β„‚ E] {c : β„‚} {R : ℝ} {f : β„‚ β†’ E} /-- If `f` is complex meromorphic on a circle in the complex plane, then `log β€–f Β·β€–` is circle integrable over that circle. -/ theorem circleIntegrable_log_norm_meromorphicOn (hf : MeromorphicOn f (sphere c |R|)) : CircleIntegrable (log β€–f Β·β€–) c R := by by_cases tβ‚€ : βˆ€ u : (sphere c |R|), meromorphicOrderAt f u β‰  ⊀ Β· obtain ⟨g, h₁g, hβ‚‚g, h₃g⟩ := hf.extract_zeros_poles tβ‚€ ((divisor f (sphere c |R|)).finiteSupport (isCompact_sphere c |R|)) have hβ‚„g := MeromorphicOn.extract_zeros_poles_log hβ‚‚g h₃g apply CircleIntegrable.congr_codiscreteWithin hβ‚„g.symm apply CircleIntegrable.add Β· apply CircleIntegrable.finsum intro i apply IntervalIntegrable.const_mul apply intervalIntegrable_log_norm_meromorphicOn apply AnalyticOnNhd.meromorphicOn apply AnalyticOnNhd.sub _ analyticOnNhd_const apply (analyticOnNhd_circleMap c R).mono (by tauto) Β· apply ContinuousOn.intervalIntegrable apply ContinuousOn.log Β· apply ContinuousOn.norm apply h₁g.continuousOn.comp (t := sphere c |R|) (continuous_circleMap c R).continuousOn intro x hx simp Β· intro x hx rw [ne_eq, norm_eq_zero] apply hβ‚‚g ⟨circleMap c R x, circleMap_mem_sphere' c R x⟩ Β· rw [← hf.exists_meromorphicOrderAt_ne_top_iff_forall (isConnected_sphere (by simp) c (abs_nonneg R))] at tβ‚€ push_neg at tβ‚€ have : (log β€–f Β·β€–) =αΆ [codiscreteWithin (sphere c |R|)] 0 := by filter_upwards [hf.meromorphicNFAt_mem_codiscreteWithin, self_mem_codiscreteWithin (sphere c |R|)] with x h₁x hβ‚‚x simp only [Pi.zero_apply, log_eq_zero, norm_eq_zero] left by_contra hCon simp_all [← h₁x.meromorphicOrderAt_eq_zero_iff, tβ‚€ ⟨x, hβ‚‚x⟩] apply CircleIntegrable.congr_codiscreteWithin this.symm (circleIntegrable_const 0 c R) /-- Variant of `circleIntegrable_log_norm_meromorphicOn` for non-negative radii. -/ theorem circleIntegrable_log_norm_meromorphicOn_of_nonneg (hf : MeromorphicOn f (sphere c R)) (hR : 0 ≀ R) : CircleIntegrable (log β€–f Β·β€–) c R := by rw [← abs_of_nonneg hR] at hf exact circleIntegrable_log_norm_meromorphicOn hf /-- Variant of `circleIntegrable_log_norm_meromorphicOn` for factorized rational functions. -/ theorem circleIntegrable_log_norm_factorizedRational {R : ℝ} {c : β„‚} (D : β„‚ β†’ β„€) : CircleIntegrable (βˆ‘αΆ  u, ((D u) * log β€–Β· - uβ€–)) c R := CircleIntegrable.finsum (fun _ ↦ (circleIntegrable_log_norm_meromorphicOn (analyticOnNhd_id.sub analyticOnNhd_const).meromorphicOn).const_smul) /-- If `f` is complex meromorphic on a circle in the complex plane, then `log⁺ β€–f Β·β€–` is circle integrable over that circle. -/ theorem circleIntegrable_posLog_norm_meromorphicOn (hf : MeromorphicOn f (sphere c |R|)) : CircleIntegrable (log⁺ β€–f Β·β€–) c R := by simp_rw [← half_mul_log_add_log_abs, mul_add] apply CircleIntegrable.add Β· apply (circleIntegrable_log_norm_meromorphicOn hf).const_mul Β· apply (circleIntegrable_log_norm_meromorphicOn hf).abs.const_mul /-- Variant of `circleIntegrable_posLog_norm_meromorphicOn` for non-negative radii. -/ theorem circleIntegrable_posLog_norm_meromorphicOn_of_nonneg (hf : MeromorphicOn f (sphere c R)) (hR : 0 ≀ R) : CircleIntegrable (log⁺ β€–f Β·β€–) c R := by rw [← abs_of_nonneg hR] at hf exact circleIntegrable_posLog_norm_meromorphicOn hf end CircleIntegrable
.lake/packages/mathlib/Mathlib/Analysis/SpecialFunctions/Integrals/PosLogEqCircleAverage.lean
import Mathlib.Analysis.Complex.Harmonic.MeanValue import Mathlib.Analysis.InnerProductSpace.Harmonic.Constructions import Mathlib.Analysis.SpecialFunctions.Integrals.Basic import Mathlib.Analysis.SpecialFunctions.Integrals.LogTrigonometric import Mathlib.MeasureTheory.Integral.CircleAverage /-! # Representation of `log⁺` as a Circle Average If `a` is any complex number, `circleAverage_log_norm_sub_const_eq_posLog` represents `log⁺ a` as the circle average of `log β€–Β· - aβ€–` over the unit circle. -/ open Filter Interval intervalIntegral MeasureTheory Metric Real variable {a c : β„‚} {R : ℝ} /-! ## Circle Integrability -/ /-- If `a` is any complex number, the function `(log β€–Β· - aβ€–)` is circle integrable over every circle. -/ lemma circleIntegrable_log_norm_sub_const (r : ℝ) : CircleIntegrable (log β€–Β· - aβ€–) c r := circleIntegrable_log_norm_meromorphicOn (fun z hz ↦ by fun_prop) /-! ## Computing `circleAverage (log β€–Β· - aβ€–) 0 1` in case where `β€–aβ€– < 1`. -/ /-- If `a : β„‚` has norm smaller than one, then `circleAverage (log β€–Β· - aβ€–) 0 1` vanishes. -/ @[simp] theorem circleAverage_log_norm_sub_constβ‚€ (h : β€–aβ€– < 1) : circleAverage (log β€–Β· - aβ€–) 0 1 = 0 := by calc circleAverage (log β€–Β· - aβ€–) 0 1 _ = circleAverage (log β€–1 - ·⁻¹ * aβ€–) 0 1 := by apply circleAverage_congr_sphere intro z hz simp_all only [abs_one, mem_sphere_iff_norm, sub_zero] congr 1 have : z β‰  0 := fun h ↦ by simp [h] at hz calc β€–z - aβ€– _ = β€–z⁻¹ * (z - a)β€– := by simp [hz] _ = β€–1 - z⁻¹ * aβ€– := by field_simp _ = 0 := by rw [circleAverage_zero_one_congr_inv (f := fun x ↦ log β€–1 - x * aβ€–), HarmonicOnNhd.circleAverage_eq, zero_mul, sub_zero, CStarRing.norm_of_mem_unitary (unitary β„‚).one_mem, log_one] intro x hx have : β€–x * aβ€– < 1 := by calc β€–x * aβ€– _ = β€–xβ€– * β€–aβ€– := by simp _ ≀ β€–aβ€– := mul_le_of_le_one_left (norm_nonneg _) (by aesop) _ < 1 := h apply AnalyticAt.harmonicAt_log_norm (by fun_prop) rw [sub_ne_zero] by_contra! hCon rwa [← hCon, CStarRing.norm_of_mem_unitary (unitary β„‚).one_mem, lt_self_iff_false] at this /-! ## Computing `circleAverage (log β€–Β· - aβ€–) 0 1` in case where `β€–aβ€– = 1`. -/ -- Integral computation used in `circleAverage_log_norm_id_sub_const₁` private lemma circleAverage_log_norm_sub_const₁_integral : ∫ x in 0..(2 * Ο€), log (4 * sin (x / 2) ^ 2) / 2 = 0 := by calc ∫ x in 0..(2 * Ο€), log (4 * sin (x / 2) ^ 2) / 2 _ = ∫ (x : ℝ) in 0..Ο€, log (4 * sin x ^ 2) := by have {x : ℝ} : x / 2 = 2⁻¹ * x := by ring rw [intervalIntegral.integral_div, this, inv_mul_integral_comp_div (f := fun x ↦ log (4 * sin x ^ 2))] simp _ = ∫ (x : ℝ) in 0..Ο€, log 4 + 2 * log (sin x) := by apply integral_congr_codiscreteWithin apply codiscreteWithin.mono (by tauto : Ξ™ 0 Ο€ βŠ† Set.univ) have : AnalyticOnNhd ℝ (4 * sin Β· ^ 2) Set.univ := fun _ _ ↦ by fun_prop have := this.preimage_zero_mem_codiscrete (x := Ο€ / 2) simp only [sin_pi_div_two, one_pow, mul_one, ne_eq, OfNat.ofNat_ne_zero, not_false_eq_true, Set.preimage_compl, forall_const] at this filter_upwards [this] with a ha simp only [Set.mem_compl_iff, Set.mem_preimage, Set.mem_singleton_iff, mul_eq_zero, OfNat.ofNat_ne_zero, ne_eq, not_false_eq_true, pow_eq_zero_iff, false_or] at ha rw [log_mul (by simp) (by simp_all), log_pow, Nat.cast_ofNat] _ = (∫ (x : ℝ) in 0..Ο€, log 4) + 2 * ∫ (x : ℝ) in 0..Ο€, log (sin x) := by rw [integral_add _root_.intervalIntegrable_const (by apply intervalIntegrable_log_sin.const_mul 2), intervalIntegral.integral_const_mul] _ = 0 := by simp only [intervalIntegral.integral_const, sub_zero, smul_eq_mul, integral_log_sin_zero_pi, (by norm_num : (4 : ℝ) = 2 * 2), log_mul two_ne_zero two_ne_zero] ring /-- If `a : β„‚` has norm one, then the circle average `circleAverage (log β€–Β· - aβ€–) 0 1` vanishes. -/ theorem circleAverage_log_norm_sub_const₁ (h : β€–aβ€– = 1) : circleAverage (log β€–Β· - aβ€–) 0 1 = 0 := by -- Observing that the problem is rotation invariant, we rotate by an angle of `ΞΆ = - arg a` and -- reduce the problem to the case where `a = 1`. The integral can then be evaluated by a direct -- computation. simp only [circleAverage, mul_inv_rev, smul_eq_mul, mul_eq_zero, inv_eq_zero, OfNat.ofNat_ne_zero, or_false] right obtain ⟨΢, h΢⟩ : βˆƒ ΞΆ, a⁻¹ = circleMap 0 1 ΞΆ := by simp [Set.exists_range_iff.1, h] calc ∫ x in 0..(2 * Ο€), log β€–circleMap 0 1 x - aβ€– _ = ∫ x in 0..(2 * Ο€), log β€–(circleMap 0 1 ΞΆ) * (circleMap 0 1 x - a)β€– := by simp _ = ∫ x in 0..(2 * Ο€), log β€–circleMap 0 1 (ΞΆ + x) - (circleMap 0 1 ΞΆ) * aβ€– := by simp [mul_sub, circleMap, add_mul, Complex.exp_add] _ = ∫ x in 0..(2 * Ο€), log β€–circleMap 0 1 (ΞΆ + x) - 1β€– := by simp [← hΞΆ, inv_mul_cancelβ‚€ (by aesop : a β‰  0)] _ = ∫ x in 0..(2 * Ο€), log β€–circleMap 0 1 x - 1β€– := by have : Function.Periodic (log β€–circleMap 0 1 Β· - 1β€–) (2 * Ο€) := fun x ↦ by simp [periodic_circleMap 0 1 x] have := this.intervalIntegral_add_eq (t := 0) (s := ΞΆ) simp_all [integral_comp_add_left (log β€–circleMap 0 1 Β· - 1β€–)] _ = ∫ x in 0..(2 * Ο€), log (4 * sin (x / 2) ^ 2) / 2 := by apply integral_congr intro x hx simp only [] rw [Complex.norm_def, log_sqrt (circleMap 0 1 x - 1).normSq_nonneg] congr calc Complex.normSq (circleMap 0 1 x - 1) _ = (cos x - 1) * (cos x - 1) + sin x * sin x := by simp [circleMap, Complex.normSq_apply] _ = sin x ^ 2 + cos x ^ 2 + 1 - 2 * cos x := by ring _ = 2 - 2 * cos x := by rw [sin_sq_add_cos_sq] norm_num _ = 2 - 2 * cos (2 * (x / 2)) := by rw [← mul_div_assoc] simp _ = 4 - 4 * cos (x / 2) ^ 2 := by rw [cos_two_mul] ring _ = 4 * sin (x / 2) ^ 2 := by nth_rw 1 [← mul_one 4, ← sin_sq_add_cos_sq (x / 2)] ring _ = 0 := circleAverage_log_norm_sub_const₁_integral /-! ## Computing `circleAverage (log β€–Β· - aβ€–) 0 1` in case where `1 < β€–aβ€–`. -/ /-- If `a : β„‚` has norm greater than one, then `circleAverage (log β€–Β· - aβ€–) 0 1` equals `log β€–aβ€–`. -/ @[simp] theorem circleAverage_log_norm_sub_constβ‚‚ (h : 1 < β€–aβ€–) : circleAverage (log β€–Β· - aβ€–) 0 1 = log β€–aβ€– := by rw [HarmonicOnNhd.circleAverage_eq, zero_sub, norm_neg] intro x hx apply AnalyticAt.harmonicAt_log_norm (by fun_prop) rw [sub_ne_zero] by_contra! simp_all only [abs_one, Metric.mem_closedBall, dist_zero_right] linarith /-! ## Presentation of `log⁺` in Terms of Circle Averages -/ /-- The `circleAverage (log β€–Β· - aβ€–) 0 1` equals `log⁺ β€–aβ€–`. -/ @[simp] theorem circleAverage_log_norm_sub_const_eq_posLog : circleAverage (log β€–Β· - aβ€–) 0 1 = log⁺ β€–aβ€– := by rcases lt_trichotomy 1 β€–aβ€– with h | h | h Β· rw [circleAverage_log_norm_sub_constβ‚‚ h] apply (posLog_eq_log _).symm simp_all [le_of_lt h] Β· rw [eq_comm, circleAverage_log_norm_sub_const₁ h.symm, posLog_eq_zero_iff] simp_all Β· rw [eq_comm, circleAverage_log_norm_sub_constβ‚€ h, posLog_eq_zero_iff] simp_all [le_of_lt h] /-- The `circleAverage (log β€–Β· + aβ€–) 0 1` equals `log⁺ β€–aβ€–`. -/ @[simp] theorem circleAverage_log_norm_add_const_eq_posLog : circleAverage (log β€–Β· + aβ€–) 0 1 = log⁺ β€–aβ€– := by have : (log β€–Β· + aβ€–) = (log β€–Β· - -aβ€–) := by simp simp [this] /-- Generalization of `circleAverage_log_norm_sub_const_eq_posLog`: The `circleAverage (log β€–Β· - aβ€–) c R` equals `log R + log⁺ (|R|⁻¹ * β€–c - aβ€–)`. -/ theorem circleAverage_log_norm_sub_const_eq_log_radius_add_posLog (hR : R β‰  0) : circleAverage (log β€–Β· - aβ€–) c R = log R + log⁺ (R⁻¹ * β€–c - aβ€–) := by calc circleAverage (log β€–Β· - aβ€–) c R _ = circleAverage (fun z ↦ log β€–R * (z + R⁻¹ * (c - a))β€–) 0 1 := by rw [circleAverage_eq_circleAverage_zero_one] congr ext z congr rw [Complex.ofReal_inv R] field [Complex.ofReal_ne_zero.mpr hR] _ = circleAverage (fun z ↦ log β€–Rβ€– + log β€–z + R⁻¹ * (c - a)β€–) 0 1 := by apply circleAverage_congr_codiscreteWithin _ (zero_ne_one' ℝ).symm have : {z | β€–z + ↑R⁻¹ * (c - a)β€– β‰  0} ∈ codiscreteWithin (Metric.sphere (0 : β„‚) |1|) := by apply codiscreteWithin_iff_locallyFiniteComplementWithin.2 intro z hz use Set.univ simp only [univ_mem, abs_one, Complex.ofReal_inv, ne_eq, norm_eq_zero, Set.univ_inter, true_and] apply Set.Subsingleton.finite intro z₁ hz₁ zβ‚‚ hzβ‚‚ simp_all only [ne_eq, abs_one, mem_sphere_iff_norm, sub_zero, Set.mem_diff, Set.mem_setOf_eq, Decidable.not_not] rw [add_eq_zero_iff_eq_neg.1 hz₁.2, add_eq_zero_iff_eq_neg.1 hzβ‚‚.2] filter_upwards [this] with z hz rw [norm_mul, log_mul (norm_ne_zero_iff.2 (Complex.ofReal_ne_zero.mpr hR)) hz] simp _ = log R + log⁺ (|R|⁻¹ * β€–c - aβ€–) := by rw [← Pi.add_def, circleAverage_add (circleIntegrable_const (log β€–Rβ€–) 0 1) (circleIntegrable_log_norm_meromorphicOn (fun _ _ ↦ by fun_prop)), circleAverage_const] simp _ = log R + log⁺ (R⁻¹ * β€–c - aβ€–) := by congr 1 rcases hR.lt_or_gt with h | h Β· simp [abs_of_neg h] Β· rw [abs_of_pos h] /-- Trivial corollary of `circleAverage_log_norm_sub_const_eq_log_radius_add_posLog`: If `u : β„‚` lies within the closed ball with center `c` and radius `R`, then the circle average `circleAverage (log β€–Β· - uβ€–) c R` equals `log R`. -/ lemma circleAverage_log_norm_sub_const_of_mem_closedBall (hu : a ∈ closedBall c |R|) : circleAverage (log β€–Β· - aβ€–) c R = log R := by by_cases hR : R = 0 Β· simp_all rw [circleAverage_log_norm_sub_const_eq_log_radius_add_posLog hR, add_eq_left, posLog_eq_zero_iff, abs_mul, abs_inv, abs_of_nonneg (norm_nonneg (c - a))] rw [mem_closedBall, dist_eq_norm'] at hu apply inv_mul_le_one_of_leβ‚€ hu (abs_nonneg R)
.lake/packages/mathlib/Mathlib/Analysis/SpecialFunctions/Integrals/Basic.lean
import Mathlib.Analysis.SpecialFunctions.Log.NegMulLog import Mathlib.Analysis.SpecialFunctions.NonIntegrable import Mathlib.Analysis.SpecialFunctions.Pow.Deriv import Mathlib.Analysis.SpecialFunctions.Integrability.Basic import Mathlib.Analysis.SpecialFunctions.Trigonometric.Sinc import Mathlib.MeasureTheory.Integral.IntervalIntegral.IntegrationByParts /-! # Integration of specific interval integrals This file contains proofs of the integrals of various specific functions. This includes: * Integrals of simple functions, such as `id`, `pow`, `inv`, `exp`, `log` * Integrals of some trigonometric functions, such as `sin`, `cos`, `1 / (1 + x^2)` * The integral of `cos x ^ 2 - sin x ^ 2` * Reduction formulae for the integrals of `sin x ^ n` and `cos x ^ n` for `n β‰₯ 2` * The computation of `∫ x in 0..Ο€, sin x ^ n` as a product for even and odd `n` (used in proving the Wallis product for pi) * Integrals of the form `sin x ^ m * cos x ^ n` With these lemmas, many simple integrals can be computed by `simp` or `norm_num`. This file is still being developed. ## Tags integrate, integration, integrable -/ open Real Set Finset open scoped Real Interval variable {a b : ℝ} (n : β„•) namespace intervalIntegral open MeasureTheory variable {f : ℝ β†’ ℝ} {ΞΌ : Measure ℝ} [IsLocallyFiniteMeasure ΞΌ] (c d : ℝ) /-! ### Integrals of the form `c * ∫ x in a..b, f (c * x + d)` -/ section @[simp] theorem mul_integral_comp_mul_right : (c * ∫ x in a..b, f (x * c)) = ∫ x in a * c..b * c, f x := smul_integral_comp_mul_right f c @[simp] theorem mul_integral_comp_mul_left : (c * ∫ x in a..b, f (c * x)) = ∫ x in c * a..c * b, f x := smul_integral_comp_mul_left f c @[simp] theorem inv_mul_integral_comp_div : (c⁻¹ * ∫ x in a..b, f (x / c)) = ∫ x in a / c..b / c, f x := inv_smul_integral_comp_div f c @[simp] theorem mul_integral_comp_mul_add : (c * ∫ x in a..b, f (c * x + d)) = ∫ x in c * a + d..c * b + d, f x := smul_integral_comp_mul_add f c d @[simp] theorem mul_integral_comp_add_mul : (c * ∫ x in a..b, f (d + c * x)) = ∫ x in d + c * a..d + c * b, f x := smul_integral_comp_add_mul f c d @[simp] theorem inv_mul_integral_comp_div_add : (c⁻¹ * ∫ x in a..b, f (x / c + d)) = ∫ x in a / c + d..b / c + d, f x := inv_smul_integral_comp_div_add f c d @[simp] theorem inv_mul_integral_comp_add_div : (c⁻¹ * ∫ x in a..b, f (d + x / c)) = ∫ x in d + a / c..d + b / c, f x := inv_smul_integral_comp_add_div f c d @[simp] theorem mul_integral_comp_mul_sub : (c * ∫ x in a..b, f (c * x - d)) = ∫ x in c * a - d..c * b - d, f x := smul_integral_comp_mul_sub f c d @[simp] theorem mul_integral_comp_sub_mul : (c * ∫ x in a..b, f (d - c * x)) = ∫ x in d - c * b..d - c * a, f x := smul_integral_comp_sub_mul f c d @[simp] theorem inv_mul_integral_comp_div_sub : (c⁻¹ * ∫ x in a..b, f (x / c - d)) = ∫ x in a / c - d..b / c - d, f x := inv_smul_integral_comp_div_sub f c d @[simp] theorem inv_mul_integral_comp_sub_div : (c⁻¹ * ∫ x in a..b, f (d - x / c)) = ∫ x in d - b / c..d - a / c, f x := inv_smul_integral_comp_sub_div f c d end end intervalIntegral open intervalIntegral /-! ### Integrals of simple functions -/ theorem integral_cpow {r : β„‚} (h : -1 < r.re ∨ r β‰  -1 ∧ (0 : ℝ) βˆ‰ [[a, b]]) : (∫ x : ℝ in a..b, (x : β„‚) ^ r) = ((b : β„‚) ^ (r + 1) - (a : β„‚) ^ (r + 1)) / (r + 1) := by rw [sub_div] have hr : r + 1 β‰  0 := by rcases h with h | h Β· apply_fun Complex.re rw [Complex.add_re, Complex.one_re, Complex.zero_re, Ne, add_eq_zero_iff_eq_neg] exact h.ne' Β· rw [Ne, ← add_eq_zero_iff_eq_neg] at h; exact h.1 by_cases hab : (0 : ℝ) βˆ‰ [[a, b]] Β· apply integral_eq_sub_of_hasDerivAt (fun x hx => ?_) (intervalIntegrable_cpow (r := r) <| Or.inr hab) refine hasDerivAt_ofReal_cpow_const' (ne_of_mem_of_not_mem hx hab) ?_ contrapose! hr; rwa [add_eq_zero_iff_eq_neg] replace h : -1 < r.re := by tauto suffices βˆ€ c : ℝ, (∫ x : ℝ in 0..c, (x : β„‚) ^ r) = (c : β„‚) ^ (r + 1) / (r + 1) - (0 : β„‚) ^ (r + 1) / (r + 1) by rw [← integral_add_adjacent_intervals (@intervalIntegrable_cpow' a 0 r h) (@intervalIntegrable_cpow' 0 b r h), integral_symm, this a, this b, Complex.zero_cpow hr] ring intro c apply integral_eq_sub_of_hasDeriv_right Β· refine ((Complex.continuous_ofReal_cpow_const ?_).div_const _).continuousOn rwa [Complex.add_re, Complex.one_re, ← neg_lt_iff_pos_add] Β· refine fun x hx => (hasDerivAt_ofReal_cpow_const' ?_ ?_).hasDerivWithinAt Β· rcases le_total c 0 with (hc | hc) Β· rw [max_eq_left hc] at hx; exact hx.2.ne Β· rw [min_eq_left hc] at hx; exact hx.1.ne' Β· contrapose! hr; rw [hr]; ring Β· exact intervalIntegrable_cpow' h theorem integral_rpow {r : ℝ} (h : -1 < r ∨ r β‰  -1 ∧ (0 : ℝ) βˆ‰ [[a, b]]) : ∫ x in a..b, x ^ r = (b ^ (r + 1) - a ^ (r + 1)) / (r + 1) := by have h' : -1 < (r : β„‚).re ∨ (r : β„‚) β‰  -1 ∧ (0 : ℝ) βˆ‰ [[a, b]] := by cases h Β· left; rwa [Complex.ofReal_re] Β· right; rwa [← Complex.ofReal_one, ← Complex.ofReal_neg, Ne, Complex.ofReal_inj] have : (∫ x in a..b, (x : β„‚) ^ (r : β„‚)) = ((b : β„‚) ^ (r + 1 : β„‚) - (a : β„‚) ^ (r + 1 : β„‚)) / (r + 1) := integral_cpow h' apply_fun Complex.re at this; convert this Β· simp_rw [intervalIntegral_eq_integral_uIoc, Complex.real_smul, Complex.re_ofReal_mul, rpow_def, ← RCLike.re_eq_complex_re, smul_eq_mul] rw [integral_re] refine intervalIntegrable_iff.mp ?_ rcases h' with h' | h' Β· exact intervalIntegrable_cpow' h' Β· exact intervalIntegrable_cpow (Or.inr h'.2) Β· rw [(by push_cast; rfl : (r : β„‚) + 1 = ((r + 1 : ℝ) : β„‚))] simp_rw [div_eq_inv_mul, ← Complex.ofReal_inv, Complex.re_ofReal_mul, Complex.sub_re, rpow_def] theorem integral_zpow {n : β„€} (h : 0 ≀ n ∨ n β‰  -1 ∧ (0 : ℝ) βˆ‰ [[a, b]]) : ∫ x in a..b, x ^ n = (b ^ (n + 1) - a ^ (n + 1)) / (n + 1) := by replace h : -1 < (n : ℝ) ∨ (n : ℝ) β‰  -1 ∧ (0 : ℝ) βˆ‰ [[a, b]] := mod_cast h exact mod_cast integral_rpow h @[simp] theorem integral_pow : ∫ x in a..b, x ^ n = (b ^ (n + 1) - a ^ (n + 1)) / (n + 1) := by simpa only [← Int.natCast_succ, zpow_natCast] using integral_zpow (Or.inl n.cast_nonneg) /-- Integral of `|x - a| ^ n` over `Ξ™ a b`. This integral appears in the proof of the Picard-LindelΓΆf/Cauchy-Lipschitz theorem. -/ theorem integral_pow_abs_sub_uIoc : ∫ x in Ξ™ a b, |x - a| ^ n = |b - a| ^ (n + 1) / (n + 1) := by rcases le_or_gt a b with hab | hab Β· calc ∫ x in Ξ™ a b, |x - a| ^ n = ∫ x in a..b, |x - a| ^ n := by rw [uIoc_of_le hab, ← integral_of_le hab] _ = ∫ x in 0..(b - a), x ^ n := by simp only [integral_comp_sub_right fun x => |x| ^ n, sub_self] refine integral_congr fun x hx => congr_argβ‚‚ Pow.pow (abs_of_nonneg <| ?_) rfl rw [uIcc_of_le (sub_nonneg.2 hab)] at hx exact hx.1 _ = |b - a| ^ (n + 1) / (n + 1) := by simp [abs_of_nonneg (sub_nonneg.2 hab)] Β· calc ∫ x in Ξ™ a b, |x - a| ^ n = ∫ x in b..a, |x - a| ^ n := by rw [uIoc_of_ge hab.le, ← integral_of_le hab.le] _ = ∫ x in b - a..0, (-x) ^ n := by simp only [integral_comp_sub_right fun x => |x| ^ n, sub_self] refine integral_congr fun x hx => congr_argβ‚‚ Pow.pow (abs_of_nonpos <| ?_) rfl rw [uIcc_of_le (sub_nonpos.2 hab.le)] at hx exact hx.2 _ = |b - a| ^ (n + 1) / (n + 1) := by simp [integral_comp_neg fun x => x ^ n, abs_of_neg (sub_neg.2 hab)] @[simp] theorem integral_id : ∫ x in a..b, x = (b ^ 2 - a ^ 2) / 2 := by have := @integral_pow a b 1 norm_num at this exact this theorem integral_one : (∫ _ in a..b, (1 : ℝ)) = b - a := by simp only [mul_one, smul_eq_mul, integral_const] theorem integral_const_on_unit_interval : ∫ _ in a..a + 1, b = b := by simp @[simp] theorem integral_inv (h : (0 : ℝ) βˆ‰ [[a, b]]) : ∫ x in a..b, x⁻¹ = log (b / a) := by have h' := fun x (hx : x ∈ [[a, b]]) => ne_of_mem_of_not_mem hx h rw [integral_deriv_eq_sub' _ deriv_log' (fun x hx => differentiableAt_log (h' x hx)) (continuousOn_invβ‚€.mono <| subset_compl_singleton_iff.mpr h), log_div (h' b right_mem_uIcc) (h' a left_mem_uIcc)] @[simp] theorem integral_inv_of_pos (ha : 0 < a) (hb : 0 < b) : ∫ x in a..b, x⁻¹ = log (b / a) := integral_inv <| notMem_uIcc_of_lt ha hb @[simp] theorem integral_inv_of_neg (ha : a < 0) (hb : b < 0) : ∫ x in a..b, x⁻¹ = log (b / a) := integral_inv <| notMem_uIcc_of_gt ha hb theorem integral_one_div (h : (0 : ℝ) βˆ‰ [[a, b]]) : ∫ x : ℝ in a..b, 1 / x = log (b / a) := by simp only [one_div, integral_inv h] theorem integral_one_div_of_pos (ha : 0 < a) (hb : 0 < b) : ∫ x : ℝ in a..b, 1 / x = log (b / a) := by simp only [one_div, integral_inv_of_pos ha hb] theorem integral_one_div_of_neg (ha : a < 0) (hb : b < 0) : ∫ x : ℝ in a..b, 1 / x = log (b / a) := by simp only [one_div, integral_inv_of_neg ha hb] @[simp] theorem integral_exp : ∫ x in a..b, exp x = exp b - exp a := by rw [integral_deriv_eq_sub'] Β· simp Β· exact fun _ _ => differentiableAt_exp Β· exact continuousOn_exp theorem integral_exp_mul_complex {c : β„‚} (hc : c β‰  0) : (∫ x in a..b, Complex.exp (c * x)) = (Complex.exp (c * b) - Complex.exp (c * a)) / c := by have D : βˆ€ x : ℝ, HasDerivAt (fun y : ℝ => Complex.exp (c * y) / c) (Complex.exp (c * x)) x := by intro x conv => congr rw [← mul_div_cancel_rightβ‚€ (Complex.exp (c * x)) hc] apply ((Complex.hasDerivAt_exp _).comp x _).div_const c simpa only [mul_one] using ((hasDerivAt_id (x : β„‚)).const_mul _).comp_ofReal rw [integral_deriv_eq_sub' _ (funext fun x => (D x).deriv) fun x _ => (D x).differentiableAt] Β· ring Β· fun_prop lemma integral_exp_mul_I_eq_sin (r : ℝ) : ∫ t in -r..r, Complex.exp (t * Complex.I) = 2 * Real.sin r := calc ∫ t in -r..r, Complex.exp (t * Complex.I) _ = (Complex.exp (Complex.I * r) - Complex.exp (Complex.I * (-r))) / Complex.I := by simp_rw [mul_comm _ Complex.I] rw [integral_exp_mul_complex] Β· simp Β· simp _ = 2 * Real.sin r := by simp only [mul_comm Complex.I, Complex.exp_mul_I, Complex.cos_neg, Complex.sin_neg, add_sub_add_left_eq_sub, Complex.div_I, Complex.ofReal_sin] rw [sub_mul, mul_assoc, mul_assoc, two_mul] simp lemma integral_exp_mul_I_eq_sinc (r : ℝ) : ∫ t in -r..r, Complex.exp (t * Complex.I) = 2 * r * sinc r := by rw [integral_exp_mul_I_eq_sin] by_cases hr : r = 0 Β· simp [hr] rw [sinc_of_ne_zero hr] norm_cast field /-- Helper lemma for `integral_log`: case where `a = 0` and `b` is positive. -/ lemma integral_log_from_zero_of_pos (ht : 0 < b) : ∫ s in 0..b, log s = b * log b - b := by -- Compute the integral by giving a primitive and considering it limit as x approaches 0 from the -- right. The following lines were suggested by Gareth Ma on Zulip. rw [integral_eq_sub_of_hasDerivAt_of_tendsto (f := fun x ↦ x * log x - x) (fa := 0) (fb := b * log b - b) (hint := intervalIntegrable_log')] Β· abel Β· exact ht Β· intro s ⟨hs, _ ⟩ simpa using (hasDerivAt_mul_log hs.ne.symm).sub (hasDerivAt_id s) Β· simpa [mul_comm] using ((tendsto_log_mul_rpow_nhdsGT_zero zero_lt_one).sub (tendsto_nhdsWithin_of_tendsto_nhds Filter.tendsto_id)) Β· exact tendsto_nhdsWithin_of_tendsto_nhds (ContinuousAt.tendsto (by fun_prop)) /-- Helper lemma for `integral_log`: case where `a = 0`. -/ lemma integral_log_from_zero {b : ℝ} : ∫ s in 0..b, log s = b * log b - b := by rcases lt_trichotomy b 0 with h | h | h Β· -- If t is negative, use that log is an even function to reduce to the positive case. conv => arg 1; arg 1; intro t; rw [← log_neg_eq_log] rw [intervalIntegral.integral_comp_neg, intervalIntegral.integral_symm, neg_zero, integral_log_from_zero_of_pos (Left.neg_pos_iff.mpr h), log_neg_eq_log] ring Β· simp [h] Β· exact integral_log_from_zero_of_pos h @[simp] theorem integral_log : ∫ s in a..b, log s = b * log b - a * log a - b + a := by rw [← intervalIntegral.integral_add_adjacent_intervals (b := 0)] Β· rw [intervalIntegral.integral_symm, integral_log_from_zero, integral_log_from_zero] ring all_goals exact intervalIntegrable_log' @[simp] theorem integral_sin : ∫ x in a..b, sin x = cos a - cos b := by rw [integral_deriv_eq_sub' fun x => -cos x] Β· ring Β· simp Β· simp only [differentiableAt_fun_neg_iff, differentiableAt_cos, implies_true] Β· exact continuousOn_sin @[simp] theorem integral_cos : ∫ x in a..b, cos x = sin b - sin a := by rw [integral_deriv_eq_sub'] Β· simp Β· simp only [differentiableAt_sin, implies_true] Β· exact continuousOn_cos theorem integral_cos_mul_complex {z : β„‚} (hz : z β‰  0) (a b : ℝ) : (∫ x in a..b, Complex.cos (z * x)) = Complex.sin (z * b) / z - Complex.sin (z * a) / z := by apply integral_eq_sub_of_hasDerivAt swap Β· apply Continuous.intervalIntegrable exact Complex.continuous_cos.comp (continuous_const.mul Complex.continuous_ofReal) intro x _ have a := Complex.hasDerivAt_sin (↑x * z) have b : HasDerivAt (fun y => y * z : β„‚ β†’ β„‚) z ↑x := hasDerivAt_mul_const _ have c : HasDerivAt (Complex.sin ∘ fun y : β„‚ => (y * z)) _ ↑x := HasDerivAt.comp (π•œ := β„‚) x a b have d := HasDerivAt.comp_ofReal (c.div_const z) simp only [mul_comm] at d convert d using 1 conv_rhs => arg 1; rw [mul_comm] rw [mul_div_cancel_rightβ‚€ _ hz] theorem integral_cos_sq_sub_sin_sq : ∫ x in a..b, cos x ^ 2 - sin x ^ 2 = sin b * cos b - sin a * cos a := by simpa only [sq, sub_eq_add_neg, neg_mul_eq_mul_neg] using integral_deriv_mul_eq_sub (fun x _ => hasDerivAt_sin x) (fun x _ => hasDerivAt_cos x) continuousOn_cos.intervalIntegrable continuousOn_sin.neg.intervalIntegrable theorem integral_one_div_one_add_sq : (∫ x : ℝ in a..b, ↑1 / (↑1 + x ^ 2)) = arctan b - arctan a := by refine integral_deriv_eq_sub' _ Real.deriv_arctan (fun _ _ => differentiableAt_arctan _) (continuous_const.div ?_ fun x => ?_).continuousOn Β· fun_prop Β· nlinarith @[simp] theorem integral_inv_one_add_sq : (∫ x : ℝ in a..b, (↑1 + x ^ 2)⁻¹) = arctan b - arctan a := by simp only [← one_div, integral_one_div_one_add_sq] section RpowCpow open Complex theorem integral_mul_cpow_one_add_sq {t : β„‚} (ht : t β‰  -1) : (∫ x : ℝ in a..b, (x : β„‚) * ((1 : β„‚) + ↑x ^ 2) ^ t) = ((1 : β„‚) + (b : β„‚) ^ 2) ^ (t + 1) / (2 * (t + ↑1)) - ((1 : β„‚) + (a : β„‚) ^ 2) ^ (t + 1) / (2 * (t + ↑1)) := by have : t + 1 β‰  0 := by contrapose! ht; rwa [add_eq_zero_iff_eq_neg] at ht apply integral_eq_sub_of_hasDerivAt Β· intro x _ have f : HasDerivAt (fun y : β„‚ => 1 + y ^ 2) (2 * x : β„‚) x := by convert (hasDerivAt_pow 2 (x : β„‚)).const_add 1 simp have g : βˆ€ {z : β„‚}, 0 < z.re β†’ HasDerivAt (fun z => z ^ (t + 1) / (2 * (t + 1))) (z ^ t / 2) z := by intro z hz convert (HasDerivAt.cpow_const (c := t + 1) (hasDerivAt_id _) (Or.inl hz)).div_const (2 * (t + 1)) using 1 simp [field] convert (HasDerivAt.comp (↑x) (g _) f).comp_ofReal using 1 Β· ring Β· exact mod_cast add_pos_of_pos_of_nonneg zero_lt_one (sq_nonneg x) Β· apply Continuous.intervalIntegrable refine continuous_ofReal.mul ?_ apply Continuous.cpow Β· exact continuous_const.add (continuous_ofReal.pow 2) Β· exact continuous_const Β· intro a norm_cast exact ofReal_mem_slitPlane.2 <| add_pos_of_pos_of_nonneg one_pos <| sq_nonneg a theorem integral_mul_rpow_one_add_sq {t : ℝ} (ht : t β‰  -1) : (∫ x : ℝ in a..b, x * (↑1 + x ^ 2) ^ t) = (↑1 + b ^ 2) ^ (t + 1) / (↑2 * (t + ↑1)) - (↑1 + a ^ 2) ^ (t + 1) / (↑2 * (t + ↑1)) := by have : βˆ€ x s : ℝ, (((↑1 + x ^ 2) ^ s : ℝ) : β„‚) = (1 + (x : β„‚) ^ 2) ^ (s : β„‚) := by intro x s norm_cast rw [ofReal_cpow, ofReal_add, ofReal_pow, ofReal_one] exact add_nonneg zero_le_one (sq_nonneg x) rw [← ofReal_inj] convert integral_mul_cpow_one_add_sq (_ : (t : β„‚) β‰  -1) Β· rw [← intervalIntegral.integral_ofReal] congr with x : 1 rw [ofReal_mul, this x t] Β· simp_rw [ofReal_sub, ofReal_div, this a (t + 1), this b (t + 1)] push_cast; rfl Β· rw [← ofReal_one, ← ofReal_neg, Ne, ofReal_inj] exact ht end RpowCpow open Nat /-! ### Integral of `sin x ^ n` -/ theorem integral_sin_pow_aux : (∫ x in a..b, sin x ^ (n + 2)) = (sin a ^ (n + 1) * cos a - sin b ^ (n + 1) * cos b + (↑n + 1) * ∫ x in a..b, sin x ^ n) - (↑n + 1) * ∫ x in a..b, sin x ^ (n + 2) := by let C := sin a ^ (n + 1) * cos a - sin b ^ (n + 1) * cos b have h : βˆ€ Ξ± Ξ² Ξ³ : ℝ, Ξ² * Ξ± * Ξ³ * Ξ± = Ξ² * (Ξ± * Ξ± * Ξ³) := fun Ξ± Ξ² Ξ³ => by ring have hu : βˆ€ x ∈ [[a, b]], HasDerivAt (fun y => sin y ^ (n + 1)) ((n + 1 : β„•) * cos x * sin x ^ n) x := fun x _ => by simpa only [mul_right_comm] using (hasDerivAt_sin x).pow (n + 1) have hv : βˆ€ x ∈ [[a, b]], HasDerivAt (-cos) (sin x) x := fun x _ => by simpa only [neg_neg] using (hasDerivAt_cos x).neg have H := integral_mul_deriv_eq_deriv_mul hu hv ?_ ?_ Β· calc (∫ x in a..b, sin x ^ (n + 2)) = ∫ x in a..b, sin x ^ (n + 1) * sin x := by simp only [_root_.pow_succ] _ = C + (↑n + 1) * ∫ x in a..b, cos x ^ 2 * sin x ^ n := by simp [H, h, sq]; ring _ = C + (↑n + 1) * ∫ x in a..b, sin x ^ n - sin x ^ (n + 2) := by simp [cos_sq', sub_mul, ← pow_add, add_comm] _ = (C + (↑n + 1) * ∫ x in a..b, sin x ^ n) - (↑n + 1) * ∫ x in a..b, sin x ^ (n + 2) := by rw [integral_sub, mul_sub, add_sub_assoc] <;> apply Continuous.intervalIntegrable <;> fun_prop all_goals apply Continuous.intervalIntegrable; fun_prop /-- The reduction formula for the integral of `sin x ^ n` for any natural `n β‰₯ 2`. -/ theorem integral_sin_pow : (∫ x in a..b, sin x ^ (n + 2)) = (sin a ^ (n + 1) * cos a - sin b ^ (n + 1) * cos b) / (n + 2) + (n + 1) / (n + 2) * ∫ x in a..b, sin x ^ n := by field_simp convert eq_sub_iff_add_eq.mp (integral_sin_pow_aux n) using 1 ring @[simp] theorem integral_sin_sq : ∫ x in a..b, sin x ^ 2 = (sin a * cos a - sin b * cos b + b - a) / 2 := by simp [field, integral_sin_pow, add_sub_assoc] theorem integral_sin_pow_odd : (∫ x in 0..Ο€, sin x ^ (2 * n + 1)) = 2 * ∏ i ∈ range n, (2 * (i : ℝ) + 2) / (2 * i + 3) := by induction n with | zero => norm_num | succ k ih => rw [prod_range_succ_comm, mul_left_comm, ← ih, mul_succ, integral_sin_pow] norm_cast field_simp simp theorem integral_sin_pow_even : (∫ x in 0..Ο€, sin x ^ (2 * n)) = Ο€ * ∏ i ∈ range n, (2 * (i : ℝ) + 1) / (2 * i + 2) := by induction n with | zero => simp | succ k ih => rw [prod_range_succ_comm, mul_left_comm, ← ih, mul_succ, integral_sin_pow] norm_cast field_simp simp theorem integral_sin_pow_pos : 0 < ∫ x in 0..Ο€, sin x ^ n := by rcases even_or_odd' n with ⟨k, rfl | rfl⟩ <;> simp only [integral_sin_pow_even, integral_sin_pow_odd] <;> refine mul_pos (by simp [pi_pos]) (prod_pos fun n _ => div_pos ?_ ?_) <;> norm_cast <;> omega theorem integral_sin_pow_succ_le : (∫ x in 0..Ο€, sin x ^ (n + 1)) ≀ ∫ x in 0..Ο€, sin x ^ n := by let H x h := pow_le_pow_of_le_one (sin_nonneg_of_mem_Icc h) (sin_le_one x) (n.le_add_right 1) refine integral_mono_on pi_pos.le ?_ ?_ H <;> exact (continuous_sin.pow _).intervalIntegrable 0 Ο€ theorem integral_sin_pow_antitone : Antitone fun n : β„• => ∫ x in 0..Ο€, sin x ^ n := antitone_nat_of_succ_le integral_sin_pow_succ_le /-! ### Integral of `cos x ^ n` -/ theorem integral_cos_pow_aux : (∫ x in a..b, cos x ^ (n + 2)) = (cos b ^ (n + 1) * sin b - cos a ^ (n + 1) * sin a + (n + 1) * ∫ x in a..b, cos x ^ n) - (n + 1) * ∫ x in a..b, cos x ^ (n + 2) := by let C := cos b ^ (n + 1) * sin b - cos a ^ (n + 1) * sin a have h : βˆ€ Ξ± Ξ² Ξ³ : ℝ, Ξ² * Ξ± * Ξ³ * Ξ± = Ξ² * (Ξ± * Ξ± * Ξ³) := fun Ξ± Ξ² Ξ³ => by ring have hu : βˆ€ x ∈ [[a, b]], HasDerivAt (fun y => cos y ^ (n + 1)) (-(n + 1 : β„•) * sin x * cos x ^ n) x := fun x _ => by simpa only [mul_right_comm, neg_mul, mul_neg] using (hasDerivAt_cos x).pow (n + 1) have hv : βˆ€ x ∈ [[a, b]], HasDerivAt sin (cos x) x := fun x _ => hasDerivAt_sin x have H := integral_mul_deriv_eq_deriv_mul hu hv ?_ ?_ Β· calc (∫ x in a..b, cos x ^ (n + 2)) = ∫ x in a..b, cos x ^ (n + 1) * cos x := by simp only [_root_.pow_succ] _ = C + (n + 1) * ∫ x in a..b, sin x ^ 2 * cos x ^ n := by simp [C, H, h, sq, -neg_add_rev] _ = C + (n + 1) * ∫ x in a..b, cos x ^ n - cos x ^ (n + 2) := by simp [sin_sq, sub_mul, ← pow_add, add_comm] _ = (C + (n + 1) * ∫ x in a..b, cos x ^ n) - (n + 1) * ∫ x in a..b, cos x ^ (n + 2) := by rw [integral_sub, mul_sub, add_sub_assoc] <;> apply Continuous.intervalIntegrable <;> fun_prop all_goals apply Continuous.intervalIntegrable; fun_prop /-- The reduction formula for the integral of `cos x ^ n` for any natural `n β‰₯ 2`. -/ theorem integral_cos_pow : (∫ x in a..b, cos x ^ (n + 2)) = (cos b ^ (n + 1) * sin b - cos a ^ (n + 1) * sin a) / (n + 2) + (n + 1) / (n + 2) * ∫ x in a..b, cos x ^ n := by field_simp convert eq_sub_iff_add_eq.mp (integral_cos_pow_aux n) using 1 ring @[simp] theorem integral_cos_sq : ∫ x in a..b, cos x ^ 2 = (cos b * sin b - cos a * sin a + b - a) / 2 := by simp [field, integral_cos_pow, add_sub_assoc] /-! ### Integral of `sin x ^ m * cos x ^ n` -/ /-- Simplification of the integral of `sin x ^ m * cos x ^ n`, case `n` is odd. -/ theorem integral_sin_pow_mul_cos_pow_odd (m n : β„•) : (∫ x in a..b, sin x ^ m * cos x ^ (2 * n + 1)) = ∫ u in sin a..sin b, u^m * (↑1 - u ^ 2) ^ n := have hc : Continuous fun u : ℝ => u ^ m * (↑1 - u ^ 2) ^ n := by fun_prop calc (∫ x in a..b, sin x ^ m * cos x ^ (2 * n + 1)) = ∫ x in a..b, sin x ^ m * (↑1 - sin x ^ 2) ^ n * cos x := by simp only [_root_.pow_zero, _root_.pow_succ, mul_assoc, pow_mul, one_mul] congr! 5 rw [← sq, ← sq, cos_sq'] _ = ∫ u in sin a..sin b, u ^ m * (1 - u ^ 2) ^ n := integral_comp_mul_deriv (fun x _ => hasDerivAt_sin x) continuousOn_cos hc /-- The integral of `sin x * cos x`, given in terms of sinΒ². See `integral_sin_mul_cosβ‚‚` below for the integral given in terms of cosΒ². -/ @[simp] theorem integral_sin_mul_cos₁ : ∫ x in a..b, sin x * cos x = (sin b ^ 2 - sin a ^ 2) / 2 := by simpa using integral_sin_pow_mul_cos_pow_odd 1 0 @[simp] theorem integral_sin_sq_mul_cos : ∫ x in a..b, sin x ^ 2 * cos x = (sin b ^ 3 - sin a ^ 3) / 3 := by have := @integral_sin_pow_mul_cos_pow_odd a b 2 0 norm_num at this; exact this @[simp] theorem integral_cos_pow_three : ∫ x in a..b, cos x ^ 3 = sin b - sin a - (sin b ^ 3 - sin a ^ 3) / 3 := by have := @integral_sin_pow_mul_cos_pow_odd a b 0 1 norm_num at this; exact this /-- Simplification of the integral of `sin x ^ m * cos x ^ n`, case `m` is odd. -/ theorem integral_sin_pow_odd_mul_cos_pow (m n : β„•) : (∫ x in a..b, sin x ^ (2 * m + 1) * cos x ^ n) = ∫ u in cos b..cos a, u^n * (↑1 - u ^ 2) ^ m := have hc : Continuous fun u : ℝ => u ^ n * (↑1 - u ^ 2) ^ m := by fun_prop calc (∫ x in a..b, sin x ^ (2 * m + 1) * cos x ^ n) = -∫ x in b..a, sin x ^ (2 * m + 1) * cos x ^ n := by rw [integral_symm] _ = ∫ x in b..a, (↑1 - cos x ^ 2) ^ m * -sin x * cos x ^ n := by simp only [_root_.pow_succ, pow_mul, _root_.pow_zero, one_mul, mul_neg, neg_mul, integral_neg, neg_inj] congr! 5 rw [← sq, ← sq, sin_sq] _ = ∫ x in b..a, cos x ^ n * (↑1 - cos x ^ 2) ^ m * -sin x := by congr; ext; ring _ = ∫ u in cos b..cos a, u ^ n * (↑1 - u ^ 2) ^ m := integral_comp_mul_deriv (fun x _ => hasDerivAt_cos x) continuousOn_sin.neg hc /-- The integral of `sin x * cos x`, given in terms of cosΒ². See `integral_sin_mul_cos₁` above for the integral given in terms of sinΒ². -/ theorem integral_sin_mul_cosβ‚‚ : ∫ x in a..b, sin x * cos x = (cos a ^ 2 - cos b ^ 2) / 2 := by simpa using integral_sin_pow_odd_mul_cos_pow 0 1 @[simp] theorem integral_sin_mul_cos_sq : ∫ x in a..b, sin x * cos x ^ 2 = (cos a ^ 3 - cos b ^ 3) / 3 := by have := @integral_sin_pow_odd_mul_cos_pow a b 0 2 norm_num at this; exact this @[simp] theorem integral_sin_pow_three : ∫ x in a..b, sin x ^ 3 = cos a - cos b - (cos a ^ 3 - cos b ^ 3) / 3 := by have := @integral_sin_pow_odd_mul_cos_pow a b 1 0 norm_num at this; exact this /-- Simplification of the integral of `sin x ^ m * cos x ^ n`, case `m` and `n` are both even. -/ theorem integral_sin_pow_even_mul_cos_pow_even (m n : β„•) : (∫ x in a..b, sin x ^ (2 * m) * cos x ^ (2 * n)) = ∫ x in a..b, ((1 - cos (2 * x)) / 2) ^ m * ((1 + cos (2 * x)) / 2) ^ n := by simp [pow_mul, sin_sq, cos_sq, ← sub_sub] field_simp norm_num @[simp] theorem integral_sin_sq_mul_cos_sq : ∫ x in a..b, sin x ^ 2 * cos x ^ 2 = (b - a) / 8 - (sin (4 * b) - sin (4 * a)) / 32 := by convert integral_sin_pow_even_mul_cos_pow_even 1 1 using 1 have h1 : βˆ€ c : ℝ, (↑1 - c) / ↑2 * ((↑1 + c) / ↑2) = (↑1 - c ^ 2) / 4 := fun c => by ring have h2 : Continuous fun x => cos (2 * x) ^ 2 := by fun_prop have h3 : βˆ€ x, cos x * sin x = sin (2 * x) / 2 := by intro; rw [sin_two_mul]; ring have h4 : βˆ€ d : ℝ, 2 * (2 * d) = 4 * d := fun d => by ring simp [h1, h2.intervalIntegrable, integral_comp_mul_left fun x => cos x ^ 2, h3, h4] ring /-! ### Integral of miscellaneous functions -/ theorem integral_sqrt_one_sub_sq : ∫ x in (-1 : ℝ)..1, √(1 - x ^ 2 : ℝ) = Ο€ / 2 := calc _ = ∫ x in sin (-(Ο€ / 2)).. sin (Ο€ / 2), √(1 - x ^ 2 : ℝ) := by rw [sin_neg, sin_pi_div_two] _ = ∫ x in (-(Ο€ / 2))..(Ο€ / 2), √(1 - sin x ^ 2 : ℝ) * cos x := (integral_comp_mul_deriv (fun x _ => hasDerivAt_sin x) continuousOn_cos (by fun_prop)).symm _ = ∫ x in (-(Ο€ / 2))..(Ο€ / 2), cos x ^ 2 := by refine integral_congr_ae (MeasureTheory.ae_of_all _ fun _ h => ?_) rw [uIoc_of_le (neg_le_self (le_of_lt (half_pos Real.pi_pos))), Set.mem_Ioc] at h rw [← Real.cos_eq_sqrt_one_sub_sin_sq (le_of_lt h.1) h.2, pow_two] _ = Ο€ / 2 := by simp
.lake/packages/mathlib/Mathlib/Analysis/SpecialFunctions/Integrals/LogTrigonometric.lean
import Mathlib.Analysis.SpecialFunctions.Integrability.LogMeromorphic /-! # Integral of `log ∘ sin` This file computes special values of the integral of `log ∘ sin`. Given that the indefinite integral involves the dilogarithm, this can be seen as computing special values of `Liβ‚‚`. -/ open Filter Interval Real /- Helper lemma for `integral_log_sin_zero_pi_div_two`: The integral of `log ∘ sin` on `0 … Ο€` is double the integral on `0 … Ο€/2`. -/ private lemma integral_log_sin_zero_pi_eq_two_mul_integral_log_sin_zero_pi_div_two : ∫ x in 0..Ο€, log (sin x) = 2 * ∫ x in 0..(Ο€ / 2), log (sin x) := by rw [← intervalIntegral.integral_add_adjacent_intervals (a := 0) (b := Ο€ / 2) (c := Ο€) (by apply intervalIntegrable_log_sin) (by apply intervalIntegrable_log_sin)] conv => left; right; arg 1 intro x rw [← sin_pi_sub] rw [intervalIntegral.integral_comp_sub_left (fun x ↦ log (sin x)), sub_self, (by linarith : Ο€ - Ο€ / 2 = Ο€ / 2)] ring! /-- The integral of `log ∘ sin` on `0 … Ο€/2` equals `-log 2 * Ο€ / 2`. -/ theorem integral_log_sin_zero_pi_div_two : ∫ x in 0..(Ο€ / 2), log (sin x) = -log 2 * Ο€ / 2 := by calc ∫ x in 0..(Ο€ / 2), log (sin x) _ = ∫ x in 0..(Ο€ / 2), (log (sin (2 * x)) - log 2 - log (cos x)) := by apply intervalIntegral.integral_congr_codiscreteWithin apply Filter.codiscreteWithin.mono (by tauto : Ξ™ 0 (Ο€ / 2) βŠ† Set.univ) have tβ‚€ : sin ⁻¹' {0}ᢜ ∈ Filter.codiscrete ℝ := by apply analyticOnNhd_sin.preimage_zero_mem_codiscrete (x := Ο€ / 2) simp have t₁ : cos ⁻¹' {0}ᢜ ∈ Filter.codiscrete ℝ := by apply analyticOnNhd_cos.preimage_zero_mem_codiscrete (x := 0) simp filter_upwards [tβ‚€, t₁] with y h₁y hβ‚‚y simp_all only [Set.preimage_compl, Set.mem_compl_iff, Set.mem_preimage, Set.mem_singleton_iff, sin_two_mul, ne_eq, mul_eq_zero, OfNat.ofNat_ne_zero, or_self, not_false_eq_true, log_mul] ring _ = (∫ x in 0..(Ο€ / 2), log (sin (2 * x))) - Ο€ / 2 * log 2 - ∫ x in 0..(Ο€ / 2), log (cos x) := by rw [intervalIntegral.integral_sub _ _, intervalIntegral.integral_sub _ intervalIntegrable_const, intervalIntegral.integral_const] Β· simp Β· simpa using (intervalIntegrable_log_sin (a := 0) (b := Ο€)).comp_mul_left Β· apply IntervalIntegrable.sub _ intervalIntegrable_const simpa using (intervalIntegrable_log_sin (a := 0) (b := Ο€)).comp_mul_left Β· exact intervalIntegrable_log_cos _ = (∫ x in 0..(Ο€ / 2), log (sin (2 * x))) - Ο€ / 2 * log 2 - ∫ x in 0..(Ο€ / 2), log (sin x) := by simp [← sin_pi_div_two_sub, intervalIntegral.integral_comp_sub_left (fun x ↦ log (sin x)) (Ο€ / 2)] _ = -log 2 * Ο€ / 2 := by simp only [intervalIntegral.integral_comp_mul_left (f := fun x ↦ log (sin x)) two_ne_zero, mul_zero, (by linarith : 2 * (Ο€ / 2) = Ο€), integral_log_sin_zero_pi_eq_two_mul_integral_log_sin_zero_pi_div_two, smul_eq_mul, ne_eq, OfNat.ofNat_ne_zero, not_false_eq_true, inv_mul_cancel_leftβ‚€, sub_sub_cancel_left, neg_mul] linarith /-- The integral of `log ∘ sin` on `0 … Ο€` equals `-log 2 * Ο€`. -/ theorem integral_log_sin_zero_pi : ∫ x in 0..Ο€, log (sin x) = -log 2 * Ο€ := by rw [integral_log_sin_zero_pi_eq_two_mul_integral_log_sin_zero_pi_div_two, integral_log_sin_zero_pi_div_two] ring
.lake/packages/mathlib/Mathlib/Analysis/SpecialFunctions/ContinuousFunctionalCalculus/ExpLog.lean
import Mathlib.Analysis.SpecialFunctions.ContinuousFunctionalCalculus.ExpLog.Basic deprecated_module (since := "2025-11-15")
.lake/packages/mathlib/Mathlib/Analysis/SpecialFunctions/ContinuousFunctionalCalculus/Abs.lean
import Mathlib.Analysis.SpecialFunctions.ContinuousFunctionalCalculus.Rpow.Basic import Mathlib.Analysis.SpecialFunctions.ContinuousFunctionalCalculus.PosPart.Basic import Mathlib.Analysis.CStarAlgebra.ContinuousFunctionalCalculus.Commute /-! # Absolute value defined via the continuous functional calculus This file defines the absolute value via the non-unital continuous functional calculus and provides basic API. ## Main declarations + `CFC.abs`: The absolute value as `abs a := CFC.sqrt (star a * a)`. -/ variable {π•œ A : Type*} open scoped NNReal open CFC namespace CFC section NonUnital section Real variable [NonUnitalRing A] [StarRing A] [TopologicalSpace A] [Module ℝ A] [SMulCommClass ℝ A A] [IsScalarTower ℝ A A] [NonUnitalContinuousFunctionalCalculus ℝ A IsSelfAdjoint] [PartialOrder A] [StarOrderedRing A] [NonnegSpectrumClass ℝ A] /-- The absolute value defined via the non-unital continuous functional calculus. -/ noncomputable def abs (a : A) := sqrt (star a * a) @[simp, grind =] lemma abs_neg (a : A) : abs (-a) = abs a := by simp [abs] @[simp, grind ←] lemma abs_nonneg (a : A) : 0 ≀ abs a := sqrt_nonneg _ lemma abs_star (a : A) (ha : IsStarNormal a := by cfc_tac) : abs (star a) = abs a := by simp [abs, star_comm_self'] @[simp, grind =] lemma abs_zero : abs (0 : A) = 0 := by simp [abs] variable [IsTopologicalRing A] [T2Space A] lemma abs_mul_abs (a : A) : abs a * abs a = star a * a := sqrt_mul_sqrt_self _ <| star_mul_self_nonneg _ /- The hypotheses could be weakened to `Commute (star a * a) b`, but in that case one should simply use `Commute.cfcβ‚™_nnreal` directly. The point of this theorem is to have simpler hypotheses. -/ lemma _root_.Commute.cfcAbs_left {a b : A} (h₁ : Commute a b) (hβ‚‚ : Commute a (star b)) : Commute (abs a) b := .cfcβ‚™_nnreal (by simp_all [hβ‚‚.star_left]) _ /- The hypotheses could be weakened to `Commute (star a * a) b`, but in that case one should simply use `Commute.cfcβ‚™_nnreal` directly. The point of this theorem is to have simpler hypotheses. -/ lemma _root_.Commute.cfcAbs_right {a b : A} (h₁ : Commute a b) (hβ‚‚ : Commute a (star b)) : Commute b (abs a) := h₁.cfcAbs_left hβ‚‚ |>.symm /- The hypotheses could be weakened to `Commute (star a * a) (star b * b)`, but in that case one should simply use `Commute.cfcβ‚™_nnreal` (twice) directly. The point of this theorem is to have simpler hypotheses. -/ lemma _root_.Commute.cfcAbs_cfcAbs {a b : A} (h₁ : Commute a b) (hβ‚‚ : Commute a (star b)) : Commute (abs a) (abs b) := Commute.cfcβ‚™_nnreal (by simp_all [hβ‚‚.star_left]) _ |>.symm.cfcβ‚™_nnreal _ |>.symm /-- Normal elements commute with their absolute value. -/ lemma commute_abs_self (a : A) (ha : IsStarNormal a := by cfc_tac) : Commute (abs a) a := .cfcAbs_left (.refl a) ha.star_comm_self.symm lemma _root_.Commute.cfcAbs_mul_eq {a b : A} (h₁ : Commute a b) (hβ‚‚ : Commute a (star b)) : abs (a * b) = abs a * abs b := by have hab := h₁.cfcAbs_cfcAbs hβ‚‚ rw [abs, CFC.sqrt_eq_iff _ _ (star_mul_self_nonneg _) (hab.mul_nonneg (abs_nonneg a) (abs_nonneg b)), hab.eq, hab.mul_mul_mul_comm, abs_mul_abs, abs_mul_abs, star_mul, hβ‚‚.star_left.symm.mul_mul_mul_comm, h₁.eq] lemma abs_mul_self (a : A) (ha : IsStarNormal a := by cfc_tac) : abs (a * a) = star a * a := by rw [Commute.cfcAbs_mul_eq (.refl a) ha.star_comm_self.symm, abs_mul_abs] lemma abs_nnrpow_two (a : A) : abs a ^ (2 : ℝβ‰₯0) = star a * a := by simp only [abs_nonneg, nnrpow_two] apply abs_mul_abs lemma abs_nnrpow_two_mul (a : A) (x : ℝβ‰₯0) : abs a ^ (2 * x) = (star a * a) ^ x := by rw [← nnrpow_nnrpow, abs_nnrpow_two] lemma abs_nnrpow (a : A) (x : ℝβ‰₯0) : abs a ^ x = (star a * a) ^ (x / 2) := by simp only [← abs_nnrpow_two_mul, mul_div_left_comm, ne_eq, OfNat.ofNat_ne_zero, not_false_eq_true, div_self, mul_one] @[grind =] lemma abs_of_nonneg (a : A) (ha : 0 ≀ a := by cfc_tac) : abs a = a := by rw [abs, ha.star_eq, sqrt_mul_self a ha] lemma abs_of_nonpos (a : A) (ha : a ≀ 0 := by cfc_tac) : abs a = -a := by simpa using abs_of_nonneg (-a) lemma abs_eq_cfcβ‚™_norm (a : A) (ha : IsSelfAdjoint a := by cfc_tac) : abs a = cfcβ‚™ (β€–Β·β€–) a := by conv_lhs => rw [abs, ha.star_eq, sqrt_eq_real_sqrt .., ← cfcβ‚™_id' ℝ a, ← cfcβ‚™_mul .., ← cfcβ‚™_comp' ..] simp [← sq, Real.sqrt_sq_eq_abs] protected lemma posPart_add_negPart (a : A) (ha : IsSelfAdjoint a := by cfc_tac) : a⁺ + a⁻ = abs a := by rw [CFC.posPart_def, CFC.negPart_def, ← cfcβ‚™_add .., abs_eq_cfcβ‚™_norm a ha] exact cfcβ‚™_congr fun x hx ↦ posPart_add_negPart x lemma abs_sub_self (a : A) (ha : IsSelfAdjoint a := by cfc_tac) : abs a - a = 2 β€’ a⁻ := by simpa [two_smul] using congr($(CFC.posPart_add_negPart a) - $(CFC.posPart_sub_negPart a)).symm lemma abs_add_self (a : A) (ha : IsSelfAdjoint a := by cfc_tac) : abs a + a = 2 β€’ a⁺ := by simpa [two_smul] using congr($(CFC.posPart_add_negPart a) + $(CFC.posPart_sub_negPart a)).symm @[simp, grind =] lemma cfcAbs_cfcAbs (a : A) : abs (abs a) = abs a := abs_of_nonneg .. variable [StarModule ℝ A] @[simp, grind =] lemma abs_smul_nonneg {R : Type*} [Semiring R] [SMulWithZero R ℝβ‰₯0] [SMul R A] [IsScalarTower R ℝβ‰₯0 A] (r : R) (a : A) : abs (r β€’ a) = r β€’ abs a := by suffices βˆ€ r : ℝβ‰₯0, abs (r β€’ a) = r β€’ abs a by simpa using this (r β€’ 1) intro r rw [abs, sqrt_eq_iff _ _ (star_mul_self_nonneg _) (smul_nonneg (by positivity) (abs_nonneg _))] simp [mul_smul_comm, smul_mul_assoc, abs_mul_abs] end Real section RCLike variable {p : A β†’ Prop} [RCLike π•œ] [NonUnitalRing A] [TopologicalSpace A] [Module π•œ A] [StarRing A] [PartialOrder A] [StarOrderedRing A] [IsScalarTower π•œ A A] [SMulCommClass π•œ A A] [NonUnitalContinuousFunctionalCalculus π•œ A p] open ComplexOrder lemma _root_.cfcβ‚™_norm_sq_nonneg (f : π•œ β†’ π•œ) (a : A) : 0 ≀ cfcβ‚™ (fun z ↦ star (f z) * (f z)) a := cfcβ‚™_nonneg fun _ _ ↦ star_mul_self_nonneg _ lemma _root_.cfcβ‚™_norm_nonneg (f : π•œ β†’ π•œ) (a : A) : 0 ≀ cfcβ‚™ (β€–f Β·β€– : π•œ β†’ π•œ) a := cfcβ‚™_nonneg fun _ _ ↦ by simp variable [Module ℝ A] [SMulCommClass ℝ A A] [IsScalarTower ℝ A A] [NonnegSpectrumClass ℝ A] [IsTopologicalRing A] [T2Space A] [NonUnitalContinuousFunctionalCalculus ℝ A IsSelfAdjoint] variable [StarModule π•œ A] [StarModule ℝ A] [IsScalarTower ℝ π•œ A] in @[simp] lemma abs_smul (r : π•œ) (a : A) : abs (r β€’ a) = β€–rβ€– β€’ abs a := by trans abs (β€–rβ€– β€’ a) Β· simp only [abs, mul_smul_comm, smul_mul_assoc, star_smul, ← smul_assoc, RCLike.real_smul_eq_coe_smul (K := π•œ)] simp [-algebraMap_smul, ← smul_mul_assoc, ← mul_comm (starRingEnd _ _), RCLike.conj_mul, sq] Β· lift β€–rβ€– to ℝβ‰₯0 using norm_nonneg _ with r simp [← NNReal.smul_def] variable (π•œ) in lemma abs_eq_cfcβ‚™_coe_norm (a : A) (ha : p a := by cfc_tac) : abs a = cfcβ‚™ (fun z : π•œ ↦ (β€–zβ€– : π•œ)) a := by rw [abs, sqrt_eq_iff _ _ (hb := cfcβ‚™_norm_nonneg _ _), ← cfcβ‚™_mul ..] conv_rhs => rw [← cfcβ‚™_id' π•œ a, ← cfcβ‚™_star, ← cfcβ‚™_mul ..] simp [RCLike.conj_mul, sq] lemma _root_.cfcβ‚™_comp_norm (f : π•œ β†’ π•œ) (a : A) (ha : p a := by cfc_tac) (hf : ContinuousOn f ((fun z ↦ (β€–zβ€– : π•œ)) '' quasispectrum π•œ a) := by cfc_cont_tac) : cfcβ‚™ (f β€–Β·β€–) a = cfcβ‚™ f (abs a) := by obtain (hf0 | hf0) := em (f 0 = 0) Β· rw [cfcβ‚™_comp' f (β€–Β·β€–) a, ← abs_eq_cfcβ‚™_coe_norm _ a] Β· rw [cfcβ‚™_apply_of_not_map_zero _ hf0, cfcβ‚™_apply_of_not_map_zero _ (fun h ↦ (hf0 <| by simpa using h).elim)] lemma quasispectrum_abs (a : A) (ha : p a := by cfc_tac) : quasispectrum π•œ (abs a) = (fun z ↦ (β€–zβ€– : π•œ)) '' quasispectrum π•œ a := by rw [abs_eq_cfcβ‚™_coe_norm π•œ a ha, cfcβ‚™_map_quasispectrum ..] end RCLike end NonUnital section Unital section Real variable [Ring A] [StarRing A] [TopologicalSpace A] [Algebra ℝ A] [ContinuousFunctionalCalculus ℝ A IsSelfAdjoint] [PartialOrder A] [StarOrderedRing A] [NonnegSpectrumClass ℝ A] [IsTopologicalRing A] [T2Space A] lemma abs_eq_cfc_norm (a : A) (ha : IsSelfAdjoint a := by cfc_tac) : abs a = cfc (β€–Β·β€–) a := by rw [abs_eq_cfcβ‚™_norm _, cfcβ‚™_eq_cfc] @[simp] lemma abs_one : abs (1 : A) = 1 := by simp [abs] variable [StarModule ℝ A] @[simp] lemma abs_algebraMap_nnreal (x : ℝβ‰₯0) : abs (algebraMap ℝβ‰₯0 A x) = algebraMap ℝβ‰₯0 A x := by simp [Algebra.algebraMap_eq_smul_one] @[simp] lemma abs_natCast (n : β„•) : abs (n : A) = n := by simpa only [map_natCast, Nat.abs_cast] using abs_algebraMap_nnreal (n : ℝβ‰₯0) @[simp] lemma abs_ofNat (n : β„•) [n.AtLeastTwo] : abs (ofNat(n) : A) = ofNat(n) := by simpa using abs_natCast n @[simp] lemma abs_intCast (n : β„€) : abs (n : A) = |n| := by cases n with | ofNat _ => simp | negSucc n => rw [Int.cast_negSucc, abs_neg, abs_natCast, ← Int.cast_natCast] congr end Real section RCLike variable {p : A β†’ Prop} [RCLike π•œ] [Ring A] [TopologicalSpace A] [StarRing A] [PartialOrder A] [StarOrderedRing A] [Algebra π•œ A] [ContinuousFunctionalCalculus π•œ A p] [Algebra ℝ A] [NonnegSpectrumClass ℝ A] [IsTopologicalRing A] [T2Space A] [ContinuousFunctionalCalculus ℝ A IsSelfAdjoint] variable [StarModule π•œ A] [StarModule ℝ A] [IsScalarTower ℝ π•œ A] in @[simp] lemma abs_algebraMap (c : π•œ) : abs (algebraMap π•œ A c) = algebraMap ℝ A β€–cβ€– := by simp [Algebra.algebraMap_eq_smul_one] lemma _root_.cfc_comp_norm (f : π•œ β†’ π•œ) (a : A) (ha : p a := by cfc_tac) (hf : ContinuousOn f ((fun z ↦ (β€–zβ€– : π•œ)) '' spectrum π•œ a) := by cfc_cont_tac) : cfc (f β€–Β·β€–) a = cfc f (abs a) := by rw [abs_eq_cfcβ‚™_coe_norm π•œ a, cfcβ‚™_eq_cfc, ← cfc_comp' ..] lemma abs_sq (a : A) : (abs a) ^ 2 = star a * a := by rw [sq, abs_mul_abs] lemma spectrum_abs (a : A) (ha : p a := by cfc_tac) : spectrum π•œ (abs a) = (fun z ↦ (β€–zβ€– : π•œ)) '' spectrum π•œ a := by rw [abs_eq_cfcβ‚™_coe_norm π•œ a, cfcβ‚™_eq_cfc, cfc_map_spectrum ..] end RCLike end Unital section CStar /- This section requires `A` to be a `CStarRing` -/ variable [NonUnitalNormedRing A] [StarRing A] [CStarRing A] [NormedSpace ℝ A] [SMulCommClass ℝ A A] [IsScalarTower ℝ A A] [NonUnitalContinuousFunctionalCalculus ℝ A IsSelfAdjoint] [PartialOrder A] [StarOrderedRing A] [NonnegSpectrumClass ℝ A] open CFC @[simp, grind =] lemma abs_eq_zero_iff {a : A} : abs a = 0 ↔ a = 0 := by rw [CFC.abs, sqrt_eq_zero_iff _, CStarRing.star_mul_self_eq_zero_iff] @[simp, grind =] lemma norm_abs {a : A} : β€–abs aβ€– = β€–aβ€– := by rw [← sq_eq_sqβ‚€ (norm_nonneg _) (norm_nonneg _), sq, sq, ← CStarRing.norm_star_mul_self, (abs_nonneg _).star_eq, CFC.abs_mul_abs, CStarRing.norm_star_mul_self] end CStar end CFC
.lake/packages/mathlib/Mathlib/Analysis/SpecialFunctions/ContinuousFunctionalCalculus/ExpLog/Basic.lean
import Mathlib.Analysis.SpecialFunctions.Exponential import Mathlib.Analysis.CStarAlgebra.ContinuousFunctionalCalculus.Unique import Mathlib.Topology.ContinuousMap.ContinuousSqrt import Mathlib.Analysis.SpecialFunctions.Log.Basic /-! # The exponential and logarithm based on the continuous functional calculus This file defines the logarithm via the continuous functional calculus (CFC) and builds its API. This allows one to take logs of matrices, operators, elements of a C⋆-algebra, etc. It also shows that exponentials defined via the continuous functional calculus are equal to `NormedSpace.exp` (defined via power series) whenever the former are not junk values. ## Main declarations + `CFC.log`: the real log function based on the CFC, i.e. `cfc Real.log` + `CFC.exp_eq_normedSpace_exp`: exponentials based on the CFC are equal to exponentials based on power series. + `CFC.log_exp` and `CFC.exp_log`: `CFC.log` and `NormedSpace.exp ℝ` are inverses of each other. ## Implementation notes Since `cfc Real.exp` and `cfc Complex.exp` are strictly less general than `NormedSpace.exp` (defined via power series), we only give minimal API for these here in order to relate `NormedSpace.exp` to functions defined via the CFC. In particular, we don't give separate definitions for them. ## TODO + Show that `log (a * b) = log a + log b` whenever `a` and `b` commute (and the same for indexed products). + Relate `CFC.log` to `rpow`, `zpow`, `sqrt`, `inv`. -/ open NormedSpace section general_exponential variable {π•œ : Type*} {Ξ± : Type*} [RCLike π•œ] [TopologicalSpace Ξ±] [CompactSpace Ξ±] lemma NormedSpace.exp_continuousMap_eq (f : C(Ξ±, π•œ)) : exp π•œ f = (⟨exp π•œ ∘ f, exp_continuous.comp f.continuous⟩ : C(Ξ±, π•œ)) := by ext a simp only [NormedSpace.exp, FormalMultilinearSeries.sum] have h_sum := NormedSpace.expSeries_summable (𝕂 := π•œ) f simp_rw [← ContinuousMap.tsum_apply h_sum a, NormedSpace.expSeries_apply_eq] simp [NormedSpace.exp_eq_tsum] end general_exponential namespace CFC section RCLikeNormed variable {π•œ : Type*} {A : Type*} [RCLike π•œ] {p : A β†’ Prop} [NormedRing A] [StarRing A] [IsTopologicalRing A] [NormedAlgebra π•œ A] [ContinuousFunctionalCalculus π•œ A p] open scoped ContinuousFunctionalCalculus in lemma exp_eq_normedSpace_exp {a : A} (ha : p a := by cfc_tac) : cfc (exp π•œ : π•œ β†’ π•œ) a = exp π•œ a := by conv_rhs => rw [← cfc_id π•œ a ha, cfc_apply id a ha] have h := (cfcHom_isClosedEmbedding (R := π•œ) (show p a from ha)).continuous have _ : ContinuousOn (exp π•œ) (spectrum π•œ a) := exp_continuous.continuousOn simp_rw [← map_exp π•œ _ h, cfc_apply (exp π•œ) a ha] congr 1 ext simp [exp_continuousMap_eq] end RCLikeNormed section RealNormed variable {A : Type*} [NormedRing A] [StarRing A] [IsTopologicalRing A] [NormedAlgebra ℝ A] [ContinuousFunctionalCalculus ℝ A IsSelfAdjoint] lemma real_exp_eq_normedSpace_exp {a : A} (ha : IsSelfAdjoint a := by cfc_tac) : cfc Real.exp a = exp ℝ a := Real.exp_eq_exp_ℝ β–Έ exp_eq_normedSpace_exp ha @[aesop safe apply (rule_sets := [CStarAlgebra])] lemma _root_.IsSelfAdjoint.exp_nonneg {π•œ : Type*} [Field π•œ] [Algebra π•œ A] [PartialOrder A] [StarOrderedRing A] {a : A} (ha : IsSelfAdjoint a) : 0 ≀ exp π•œ a := by rw [exp_eq_exp π•œ ℝ, ← real_exp_eq_normedSpace_exp] exact cfc_nonneg fun x _ => Real.exp_nonneg x end RealNormed section ComplexNormed variable {A : Type*} {p : A β†’ Prop} [NormedRing A] [StarRing A] [NormedAlgebra β„‚ A] [ContinuousFunctionalCalculus β„‚ A p] lemma complex_exp_eq_normedSpace_exp {a : A} (ha : p a := by cfc_tac) : cfc Complex.exp a = exp β„‚ a := Complex.exp_eq_exp_β„‚ β–Έ exp_eq_normedSpace_exp ha end ComplexNormed section real_log open scoped ComplexOrder variable {A : Type*} [NormedRing A] [StarRing A] [NormedAlgebra ℝ A] [ContinuousFunctionalCalculus ℝ A IsSelfAdjoint] /-- The real logarithm, defined via the continuous functional calculus. This can be used on matrices, operators on a Hilbert space, elements of a C⋆-algebra, etc. -/ noncomputable def log (a : A) : A := cfc Real.log a @[simp, grind =>] protected lemma _root_.IsSelfAdjoint.log {a : A} : IsSelfAdjoint (log a) := cfc_predicate _ a @[simp, grind =] lemma log_zero : log (0 : A) = 0 := by simp [log] @[simp, grind =] lemma log_one : log (1 : A) = 0 := by simp [log] @[simp, grind =] lemma log_algebraMap {r : ℝ} : log (algebraMap ℝ A r) = algebraMap ℝ A (Real.log r) := by simp [log] lemma log_smul {r : ℝ} (a : A) (haβ‚‚ : βˆ€ x ∈ spectrum ℝ a, x β‰  0) (hr : r β‰  0) (ha₁ : IsSelfAdjoint a := by cfc_tac) : log (r β€’ a) = algebraMap ℝ A (Real.log r) + log a := by rw [log, ← cfc_smul_id (R := ℝ) r a, ← cfc_comp Real.log (r β€’ Β·) a, log] calc _ = cfc (fun z => Real.log r + Real.log z) a := cfc_congr (Real.log_mul hr <| haβ‚‚ Β· Β·) _ = _ := by rw [cfc_const_add _ _ _] @[grind =] lemma log_smul' [PartialOrder A] [StarOrderedRing A] [NonnegSpectrumClass ℝ A] {r : ℝ} (a : A) (hr : 0 < r) (ha : IsStrictlyPositive a := by cfc_tac) : log (r β€’ a) = algebraMap ℝ A (Real.log r) + log a := by grind [log_smul] lemma log_pow (n : β„•) (a : A) (haβ‚‚ : βˆ€ x ∈ spectrum ℝ a, x β‰  0) (ha₁ : IsSelfAdjoint a := by cfc_tac) : log (a ^ n) = n β€’ log a := by have haβ‚‚' : ContinuousOn Real.log (spectrum ℝ a) := by fun_prop (disch := assumption) have haβ‚‚'' : ContinuousOn Real.log ((Β· ^ n) '' spectrum ℝ a) := by fun_prop (disch := aesop) rw [log, ← cfc_pow_id (R := ℝ) a n ha₁, ← cfc_comp' Real.log (Β· ^ n) a haβ‚‚'', log] simp_rw [Real.log_pow, ← Nat.cast_smul_eq_nsmul ℝ n, cfc_const_mul (n : ℝ) Real.log a haβ‚‚'] @[grind =] lemma log_pow' [PartialOrder A] [StarOrderedRing A] [NonnegSpectrumClass ℝ A] (n : β„•) (a : A) (ha : IsStrictlyPositive a := by cfc_tac) : log (a ^ n) = n β€’ log a := by grind [log_pow] open NormedSpace in @[grind =] lemma log_exp (a : A) (ha : IsSelfAdjoint a := by cfc_tac) : log (exp ℝ a) = a := by have hcont : ContinuousOn Real.log (Real.exp '' spectrum ℝ a) := by fun_prop (disch := simp) rw [log, ← real_exp_eq_normedSpace_exp, ← cfc_comp' Real.log Real.exp a hcont] simp [cfc_id' (R := ℝ) a] open NormedSpace in @[grind =] lemma exp_log [PartialOrder A] [StarOrderedRing A] [NonnegSpectrumClass ℝ A] (a : A) (ha : IsStrictlyPositive a := by cfc_tac) : exp ℝ (log a) = a := by have haβ‚‚ : βˆ€ x ∈ spectrum ℝ a, x β‰  0 := by grind rw [← real_exp_eq_normedSpace_exp .log, log, ← cfc_comp' Real.exp Real.log a (by fun_prop)] conv_rhs => rw [← cfc_id (R := ℝ) a] refine cfc_congr fun x hx => ?_ grind [Real.exp_log] end real_log end CFC
.lake/packages/mathlib/Mathlib/Analysis/SpecialFunctions/ContinuousFunctionalCalculus/PosPart/Isometric.lean
import Mathlib.Analysis.SpecialFunctions.ContinuousFunctionalCalculus.PosPart.Basic import Mathlib.Analysis.CStarAlgebra.ContinuousFunctionalCalculus.Isometric /-! # Facts about `CFC.posPart` and `CFC.negPart` involving norms This file collects various facts about the positive and negative parts of elements of a C⋆-algebra that involve the norm. ## Main results * `CFC.norm_eq_max_norm_posPart_negPart`: states that `β€–aβ€– = max β€–a⁺‖ β€–a⁻‖` * `CFC.norm_posPart_le` and `CFC.norm_negPart_le`: state that `β€–a⁺‖ ≀ β€–aβ€–` and `β€–a⁻‖ ≀ β€–aβ€–` respectively. -/ variable {A : Type*} [NonUnitalNormedRing A] [NormedSpace ℝ A] [SMulCommClass ℝ A A] [IsScalarTower ℝ A A] [StarRing A] [NonUnitalIsometricContinuousFunctionalCalculus ℝ A IsSelfAdjoint] @[simp] lemma CStarAlgebra.norm_posPart_le (a : A) : β€–a⁺‖ ≀ β€–aβ€– := by by_cases ha : IsSelfAdjoint a case neg => simp [CFC.posPart_def, cfcβ‚™_apply_of_not_predicate a ha] refine norm_cfcβ‚™_le fun x hx ↦ ?_ obtain (h | h) := le_or_gt x 0 Β· simp [posPart_def, max_eq_right h] Β· simp only [posPart_def, max_eq_left h.le] exact NonUnitalIsometricContinuousFunctionalCalculus.norm_quasispectrum_le a hx ha @[simp] lemma CStarAlgebra.norm_negPart_le (a : A) : β€–a⁻‖ ≀ β€–aβ€– := by simpa [CFC.negPart_neg] using norm_posPart_le (-a) open CStarAlgebra in lemma IsSelfAdjoint.norm_eq_max_norm_posPart_negPart (a : A) (ha : IsSelfAdjoint a := by cfc_tac) : β€–aβ€– = max β€–a⁺‖ β€–a⁻‖ := by refine le_antisymm ?_ <| max_le (norm_posPart_le a) (norm_negPart_le a) conv_lhs => rw [← cfcβ‚™_id' ℝ a] rw [norm_cfcβ‚™_le_iff ..] intro x hx obtain (hx' | hx') := le_total 0 x Β· apply le_max_of_le_left refine le_of_eq_of_le ?_ <| norm_apply_le_norm_cfcβ‚™ _ a hx rw [posPart_eq_self.mpr hx'] Β· apply le_max_of_le_right refine le_of_eq_of_le ?_ <| norm_apply_le_norm_cfcβ‚™ _ a hx rw [negPart_eq_neg.mpr hx', norm_neg]
.lake/packages/mathlib/Mathlib/Analysis/SpecialFunctions/ContinuousFunctionalCalculus/PosPart/Basic.lean
import Mathlib.Analysis.CStarAlgebra.ContinuousFunctionalCalculus.Unique import Mathlib.Topology.ContinuousMap.ContinuousSqrt import Mathlib.Topology.ContinuousMap.StoneWeierstrass /-! # The positive (and negative) parts of a selfadjoint element in a C⋆-algebra This file defines the positive and negative parts of a selfadjoint element in a C⋆-algebra via the continuous functional calculus and develops the basic API, including the uniqueness of the positive and negative parts. -/ open scoped NNReal section NonUnital variable {A : Type*} [NonUnitalRing A] [Module ℝ A] [SMulCommClass ℝ A A] [IsScalarTower ℝ A A] variable [StarRing A] [TopologicalSpace A] variable [NonUnitalContinuousFunctionalCalculus ℝ A IsSelfAdjoint] namespace CStarAlgebra noncomputable instance : PosPart A where posPart := cfcβ‚™ (·⁺ : ℝ β†’ ℝ) noncomputable instance : NegPart A where negPart := cfcβ‚™ (·⁻ : ℝ β†’ ℝ) end CStarAlgebra namespace CFC lemma posPart_def (a : A) : a⁺ = cfcβ‚™ (·⁺ : ℝ β†’ ℝ) a := rfl lemma negPart_def (a : A) : a⁻ = cfcβ‚™ (·⁻ : ℝ β†’ ℝ) a := rfl @[simp] lemma posPart_zero : (0 : A)⁺ = 0 := by simp [posPart_def] @[simp] lemma negPart_zero : (0 : A)⁻ = 0 := by simp [negPart_def] lemma posPart_eq_zero_of_not_isSelfAdjoint {a : A} (ha : Β¬IsSelfAdjoint a) : a⁺ = 0 := cfcβ‚™_apply_of_not_predicate a ha lemma negPart_eq_zero_of_not_isSelfAdjoint {a : A} (ha : Β¬IsSelfAdjoint a) : a⁻ = 0 := cfcβ‚™_apply_of_not_predicate a ha @[simp] lemma posPart_mul_negPart (a : A) : a⁺ * a⁻ = 0 := by rw [posPart_def, negPart_def] by_cases ha : IsSelfAdjoint a Β· rw [← cfcβ‚™_mul _ _, ← cfcβ‚™_zero ℝ a] refine cfcβ‚™_congr (fun x _ ↦ ?_) simp only [_root_.posPart_def, _root_.negPart_def] simpa using le_total x 0 Β· simp [cfcβ‚™_apply_of_not_predicate a ha] @[simp] lemma negPart_mul_posPart (a : A) : a⁻ * a⁺ = 0 := by rw [posPart_def, negPart_def] by_cases ha : IsSelfAdjoint a Β· rw [← cfcβ‚™_mul _ _, ← cfcβ‚™_zero ℝ a] refine cfcβ‚™_congr (fun x _ ↦ ?_) simp only [_root_.posPart_def, _root_.negPart_def] simpa using le_total 0 x Β· simp [cfcβ‚™_apply_of_not_predicate a ha] lemma posPart_sub_negPart (a : A) (ha : IsSelfAdjoint a := by cfc_tac) : a⁺ - a⁻ = a := by rw [posPart_def, negPart_def] rw [← cfcβ‚™_sub _ _] conv_rhs => rw [← cfcβ‚™_id ℝ a] congr! 2 with exact _root_.posPart_sub_negPart _ section Unique variable [T2Space A] @[simp] lemma posPart_neg (a : A) : (-a)⁺ = a⁻ := by by_cases ha : IsSelfAdjoint a Β· rw [posPart_def, negPart_def, ← cfcβ‚™_comp_neg _ _] congr! 2 Β· have ha' : Β¬ IsSelfAdjoint (-a) := fun h ↦ ha (by simpa using h.neg) rw [posPart_def, negPart_def, cfcβ‚™_apply_of_not_predicate a ha, cfcβ‚™_apply_of_not_predicate _ ha'] @[simp] lemma negPart_neg (a : A) : (-a)⁻ = a⁺ := by rw [← eq_comm, ← sub_eq_zero, ← posPart_neg, neg_neg, sub_self] section SMul variable [StarModule ℝ A] @[simp] lemma posPart_smul {r : ℝβ‰₯0} {a : A} : (r β€’ a)⁺ = r β€’ a⁺ := by by_cases ha : IsSelfAdjoint a Β· simp only [CFC.posPart_def, NNReal.smul_def] rw [← cfcβ‚™_comp_smul .., ← cfcβ‚™_smul ..] refine cfcβ‚™_congr fun x hx ↦ ?_ simp [_root_.posPart_def, mul_max_of_nonneg] Β· obtain (rfl | hr) := eq_or_ne r 0 Β· simp Β· have := (not_iff_not.mpr <| (IsSelfAdjoint.all r).smul_iff hr.isUnit (x := a)) |>.mpr ha simp [CFC.posPart_def, cfcβ‚™_apply_of_not_predicate a ha, cfcβ‚™_apply_of_not_predicate _ this] @[simp] lemma negPart_smul {r : ℝβ‰₯0} {a : A} : (r β€’ a)⁻ = r β€’ a⁻ := by simpa using posPart_smul (r := r) (a := -a) lemma posPart_smul_of_nonneg {r : ℝ} (hr : 0 ≀ r) {a : A} : (r β€’ a)⁺ = r β€’ a⁺ := posPart_smul (r := ⟨r, hr⟩) lemma posPart_smul_of_nonpos {r : ℝ} (hr : r ≀ 0) {a : A} : (r β€’ a)⁺ = -r β€’ a⁻ := by nth_rw 1 [← neg_neg r] rw [neg_smul, ← smul_neg, posPart_smul_of_nonneg (neg_nonneg.mpr hr), posPart_neg] lemma negPart_smul_of_nonneg {r : ℝ} (hr : 0 ≀ r) {a : A} : (r β€’ a)⁻ = r β€’ a⁻ := by conv_lhs => rw [← neg_neg r, neg_smul, negPart_neg, posPart_smul_of_nonpos (by simpa), neg_neg] lemma negPart_smul_of_nonpos {r : ℝ} (hr : r ≀ 0) {a : A} : (r β€’ a)⁻ = -r β€’ a⁺ := by conv_lhs => rw [← neg_neg r, neg_smul, negPart_neg, posPart_smul_of_nonneg (by simpa)] end SMul end Unique variable [PartialOrder A] [StarOrderedRing A] @[aesop norm apply (rule_sets := [CStarAlgebra])] lemma posPart_nonneg (a : A) : 0 ≀ a⁺ := cfcβ‚™_nonneg (fun x _ ↦ by positivity) @[aesop norm apply (rule_sets := [CStarAlgebra])] lemma negPart_nonneg (a : A) : 0 ≀ a⁻ := cfcβ‚™_nonneg (fun x _ ↦ by positivity) lemma posPart_eq_of_eq_sub_negPart {a b : A} (hab : a = b - a⁻) (hb : 0 ≀ b := by cfc_tac) : a⁺ = b := by have ha := hab.symm β–Έ hb.isSelfAdjoint.sub (negPart_nonneg a).isSelfAdjoint nth_rw 1 [← posPart_sub_negPart a] at hab simpa using hab lemma negPart_eq_of_eq_PosPart_sub {a c : A} (hac : a = a⁺ - c) (hc : 0 ≀ c := by cfc_tac) : a⁻ = c := by have ha := hac.symm β–Έ (posPart_nonneg a).isSelfAdjoint.sub hc.isSelfAdjoint nth_rw 1 [← posPart_sub_negPart a] at hac simpa using hac lemma le_posPart {a : A} (ha : IsSelfAdjoint a := by cfc_tac) : a ≀ a⁺ := by simpa [posPart_sub_negPart a] using sub_le_self a⁺ (negPart_nonneg a) lemma neg_negPart_le {a : A} (ha : IsSelfAdjoint a := by cfc_tac) : -a⁻ ≀ a := by simpa only [posPart_sub_negPart a, ← sub_eq_add_neg] using le_add_of_nonneg_left (a := -a⁻) (posPart_nonneg a) variable [NonnegSpectrumClass ℝ A] lemma posPart_eq_self (a : A) : a⁺ = a ↔ 0 ≀ a := by refine ⟨fun ha ↦ ha β–Έ posPart_nonneg a, fun ha ↦ ?_⟩ conv_rhs => rw [← cfcβ‚™_id ℝ a] rw [posPart_def] refine cfcβ‚™_congr (fun x hx ↦ ?_) simpa [_root_.posPart_def] using quasispectrum_nonneg_of_nonneg a ha x hx lemma negPart_eq_zero_iff (a : A) (ha : IsSelfAdjoint a := by cfc_tac) : a⁻ = 0 ↔ 0 ≀ a := by rw [← posPart_eq_self, eq_comm (b := a)] nth_rw 2 [← posPart_sub_negPart a] simp lemma negPart_eq_neg (a : A) : a⁻ = -a ↔ a ≀ 0 := by rw [← neg_inj, neg_neg, eq_comm] refine ⟨fun ha ↦ by rw [ha, neg_nonpos]; exact negPart_nonneg a, fun ha ↦ ?_⟩ rw [← neg_nonneg] at ha rw [negPart_def, ← cfcβ‚™_neg] have _ : IsSelfAdjoint a := neg_neg a β–Έ (IsSelfAdjoint.neg <| .of_nonneg ha) conv_lhs => rw [← cfcβ‚™_id ℝ a] refine cfcβ‚™_congr fun x hx ↦ ?_ rw [Unitization.quasispectrum_eq_spectrum_inr ℝ, ← neg_neg x, ← Set.mem_neg, spectrum.neg_eq, ← Unitization.inr_neg, ← Unitization.quasispectrum_eq_spectrum_inr ℝ] at hx rw [← neg_eq_iff_eq_neg, eq_comm] simpa using quasispectrum_nonneg_of_nonneg _ ha _ hx lemma posPart_eq_zero_iff (a : A) (ha : IsSelfAdjoint a := by cfc_tac) : a⁺ = 0 ↔ a ≀ 0 := by rw [← negPart_eq_neg, eq_comm (b := -a)] nth_rw 2 [← posPart_sub_negPart a] simp local notation "Οƒβ‚™" => quasispectrum open ContinuousMapZero variable [IsTopologicalRing A] [T2Space A] open NonUnitalContinuousFunctionalCalculus in /-- The positive and negative parts of a selfadjoint element `a` are unique. That is, if `a = b - c` is the difference of nonnegative elements whose product is zero, then these are precisely `a⁺` and `a⁻`. -/ lemma posPart_negPart_unique {a b c : A} (habc : a = b - c) (hbc : b * c = 0) (hb : 0 ≀ b := by cfc_tac) (hc : 0 ≀ c := by cfc_tac) : a⁺ = b ∧ a⁻ = c := by /- The key idea is to show that `cfcβ‚™ f a = cfcβ‚™ f b + cfcβ‚™ f (-c)` for all real-valued `f` continuous on the union of the spectra of `a`, `b`, and `-c`. Then apply this to `f = (·⁺)`. The equality holds because both sides constitute star homomorphisms which agree on `f = id` since `a = b - c`. -/ /- `a`, `b`, `-c` are selfadjoint. -/ have hb' : IsSelfAdjoint b := .of_nonneg hb have hc' : IsSelfAdjoint (-c) := .neg <| .of_nonneg hc have ha : IsSelfAdjoint a := habc β–Έ hb'.sub <| .of_nonneg hc /- It suffices to show `b = a⁺` since `a⁺ - a⁻ = a = b - c` -/ rw [and_iff_left_of_imp ?of_b_eq] case of_b_eq => rintro rfl exact negPart_eq_of_eq_PosPart_sub habc hc /- `s := Οƒβ‚™ ℝ a βˆͺ Οƒβ‚™ ℝ b βˆͺ Οƒβ‚™ ℝ (-c)` is compact and each of these sets are subsets of `s`. Moreover, `0 ∈ s`. -/ let s := Οƒβ‚™ ℝ a βˆͺ Οƒβ‚™ ℝ b βˆͺ Οƒβ‚™ ℝ (-c) have hs : CompactSpace s := by refine isCompact_iff_compactSpace.mp <| (IsCompact.union ?_ ?_).union ?_ all_goals exact isCompact_quasispectrum _ obtain ⟨has, hbs, hcs⟩ : Οƒβ‚™ ℝ a βŠ† s ∧ Οƒβ‚™ ℝ b βŠ† s ∧ Οƒβ‚™ ℝ (-c) βŠ† s := by grind have : Fact (0 ∈ s) := ⟨by aesop⟩ /- The continuous functional calculi for functions `f g : C(s, ℝ)β‚€` applied to `b` and `(-c)` are orthogonal (i.e., the product is always zero). -/ have mul₁ (f g : C(s, ℝ)β‚€) : (cfcβ‚™HomSuperset hb' hbs f) * (cfcβ‚™HomSuperset hc' hcs g) = 0 := by refine f.nonUnitalStarAlgHom_apply_mul_eq_zero _ _ ?id ?star_id (cfcβ‚™HomSuperset_continuous hb' hbs) case' star_id => rw [star_trivial] all_goals refine g.mul_nonUnitalStarAlgHom_apply_eq_zero _ _ ?_ ?_ (cfcβ‚™HomSuperset_continuous hc' hcs) all_goals simp only [star_trivial, cfcβ‚™HomSuperset_id hb' hbs, cfcβ‚™HomSuperset_id hc' hcs, mul_neg, hbc, neg_zero] have mulβ‚‚ (f g : C(s, ℝ)β‚€) : (cfcβ‚™HomSuperset hc' hcs f) * (cfcβ‚™HomSuperset hb' hbs g) = 0 := by simpa only [star_mul, star_zero, ← map_star, star_trivial] using congr(star $(mul₁ g f)) /- `fun f ↦ cfcβ‚™ f b + cfcβ‚™ f (-c)` defines a star homomorphism `ψ : C(s, ℝ)β‚€ →⋆ₙₐ[ℝ] A` which agrees with the star homomorphism `cfcβ‚™ Β· a : C(s, ℝ)β‚€ →⋆ₙₐ[ℝ] A` since `cfcβ‚™ id a = a = b - c = cfcβ‚™ id b + cfcβ‚™ id (-c)`. -/ let ψ : C(s, ℝ)β‚€ →⋆ₙₐ[ℝ] A := { (cfcβ‚™HomSuperset hb' hbs : C(s, ℝ)β‚€ β†’β‚—[ℝ] A) + (cfcβ‚™HomSuperset hc' hcs : C(s, ℝ)β‚€ β†’β‚—[ℝ] A) with toFun := cfcβ‚™HomSuperset hb' hbs + cfcβ‚™HomSuperset hc' hcs map_zero' := by simp [-cfcβ‚™HomSuperset_apply] map_mul' := fun f g ↦ by simp only [Pi.add_apply, map_mul, mul_add, add_mul, mulβ‚‚, add_zero, mul₁, zero_add] map_star' := fun f ↦ by simp [← map_star] } have key : (cfcβ‚™HomSuperset ha has) = ψ := have : ContinuousMapZero.UniqueHom ℝ A := inferInstance ContinuousMapZero.UniqueHom.eq_of_continuous_of_map_id s (cfcβ‚™HomSuperset ha has) ψ (cfcβ‚™HomSuperset_continuous ha has) ((cfcβ‚™HomSuperset_continuous hb' hbs).add (cfcβ‚™HomSuperset_continuous hc' hcs)) (by simpa [ψ, -cfcβ‚™HomSuperset_apply, cfcβ‚™HomSuperset_id, sub_eq_add_neg] using habc) /- Applying the equality of star homomorphisms to the function `(·⁺ : ℝ β†’ ℝ)` we find that `b = cfcβ‚™ id b + cfcβ‚™ 0 (-c) = cfcβ‚™ (·⁺) b - cfcβ‚™ (·⁺) (-c) = cfcβ‚™ (·⁺) a = a⁺`, where the second equality follows because these functions are equal on the spectra of `b` and `-c`, respectively, since `0 ≀ b` and `-c ≀ 0`. -/ let f : C(s, ℝ)β‚€ := ⟨⟨(·⁺), by fun_prop⟩, by simp; exact le_rfl⟩ replace key := congr($key f) simp only [cfcβ‚™HomSuperset_apply, NonUnitalStarAlgHom.coe_mk', NonUnitalAlgHom.coe_mk, ψ, Pi.add_apply, cfcβ‚™Hom_eq_cfcβ‚™_extend (·⁺)] at key symm calc b = cfcβ‚™ (id : ℝ β†’ ℝ) b + cfcβ‚™ (0 : ℝ β†’ ℝ) (-c) := by simp [cfcβ‚™_id ℝ b] _ = _ := by congr! 1 all_goals refine cfcβ‚™_congr fun x hx ↦ Eq.symm ?_ lift x to Οƒβ‚™ ℝ _ using hx simp only [Subtype.val_injective.extend_apply, comp_apply, coe_mk, ContinuousMap.coe_mk, Subtype.map_coe, id_eq, _root_.posPart_eq_self, f, Pi.zero_apply, posPart_eq_zero] Β· exact quasispectrum_nonneg_of_nonneg b hb x.val x.property Β· obtain ⟨x, hx⟩ := x simp only [← neg_nonneg] rw [Unitization.quasispectrum_eq_spectrum_inr ℝ (-c), Unitization.inr_neg, ← spectrum.neg_eq, Set.mem_neg, ← Unitization.quasispectrum_eq_spectrum_inr ℝ c] at hx exact quasispectrum_nonneg_of_nonneg c hc _ hx _ = _ := key.symm _ = a⁺ := by refine cfcβ‚™_congr fun x hx ↦ ?_ lift x to Οƒβ‚™ ℝ a using hx simp [f] end CFC end NonUnital section Unital namespace CFC variable {A : Type*} [Ring A] [Algebra ℝ A] [StarRing A] [TopologicalSpace A] variable [ContinuousFunctionalCalculus ℝ A IsSelfAdjoint] variable [T2Space A] @[simp] lemma posPart_one : (1 : A)⁺ = 1 := by rw [CFC.posPart_def, cfcβ‚™_eq_cfc] simp @[simp] lemma negPart_one : (1 : A)⁻ = 0 := by rw [CFC.negPart_def, cfcβ‚™_eq_cfc] simp @[simp] lemma posPart_algebraMap (r : ℝ) : (algebraMap ℝ A r)⁺ = algebraMap ℝ A r⁺ := by rw [CFC.posPart_def, cfcβ‚™_eq_cfc] simp @[simp] lemma negPart_algebraMap (r : ℝ) : (algebraMap ℝ A r)⁻ = algebraMap ℝ A r⁻ := by rw [CFC.negPart_def, cfcβ‚™_eq_cfc] simp open NNReal in @[simp] lemma posPart_algebraMap_nnreal (r : ℝβ‰₯0) : (algebraMap ℝβ‰₯0 A r)⁺ = algebraMap ℝβ‰₯0 A r := by rw [CFC.posPart_def, cfcβ‚™_eq_cfc, IsScalarTower.algebraMap_apply ℝβ‰₯0 ℝ A] simp open NNReal in @[simp] lemma posPart_natCast (n : β„•) : (n : A)⁺ = n := by rw [← map_natCast (algebraMap ℝβ‰₯0 A), posPart_algebraMap_nnreal] end CFC end Unital section SpanNonneg variable {A : Type*} [NonUnitalRing A] [Module β„‚ A] [SMulCommClass β„‚ A A] [IsScalarTower β„‚ A A] variable [StarRing A] [TopologicalSpace A] [StarModule β„‚ A] variable [NonUnitalContinuousFunctionalCalculus ℝ A IsSelfAdjoint] open Submodule Complex open scoped ComplexStarModule lemma CStarAlgebra.linear_combination_nonneg (x : A) : ((β„œ x : A)⁺ - (β„œ x : A)⁻) + (I β€’ (β„‘ x : A)⁺ - I β€’ (β„‘ x : A)⁻) = x := by rw [CFC.posPart_sub_negPart _ (β„œ x).2, ← smul_sub, CFC.posPart_sub_negPart _ (β„‘ x).2, realPart_add_I_smul_imaginaryPart x] variable [PartialOrder A] [StarOrderedRing A] /-- A C⋆-algebra is spanned by its nonnegative elements. -/ lemma CStarAlgebra.span_nonneg : Submodule.span β„‚ {a : A | 0 ≀ a} = ⊀ := by refine eq_top_iff.mpr fun x _ => ?_ rw [← CStarAlgebra.linear_combination_nonneg x] apply_rules [sub_mem, Submodule.smul_mem, add_mem] all_goals refine subset_span ?_ first | apply CFC.negPart_nonneg | apply CFC.posPart_nonneg end SpanNonneg
.lake/packages/mathlib/Mathlib/Analysis/SpecialFunctions/ContinuousFunctionalCalculus/Rpow/Isometric.lean
import Mathlib.Analysis.SpecialFunctions.ContinuousFunctionalCalculus.Rpow.Basic import Mathlib.Analysis.CStarAlgebra.ContinuousFunctionalCalculus.Isometric /-! # Properties of `rpow` and `sqrt` over an algebra with an isometric CFC This file collects results about `CFC.rpow`, `CFC.nnrpow` and `CFC.sqrt` that use facts that rely on an isometric continuous functional calculus. ## Main theorems * Various versions of `β€–a ^ rβ€– = β€–aβ€– ^ r` and `β€–CFC.sqrt aβ€– = sqrt β€–aβ€–`. ## Tags continuous functional calculus, rpow, sqrt -/ open scoped NNReal namespace CFC section nonunital variable {A : Type*} [NonUnitalNormedRing A] [StarRing A] [NormedSpace ℝ A] [IsScalarTower ℝ A A] [SMulCommClass ℝ A A] [PartialOrder A] [StarOrderedRing A] [NonnegSpectrumClass ℝ A] [NonUnitalIsometricContinuousFunctionalCalculus ℝ A IsSelfAdjoint] lemma nnnorm_nnrpow (a : A) {r : ℝβ‰₯0} (hr : 0 < r) (ha : 0 ≀ a := by cfc_tac) : β€–a ^ rβ€–β‚Š = β€–aβ€–β‚Š ^ (r : ℝ) := NNReal.monotone_nnrpow_const r |>.monotoneOn _ |>.nnnorm_cfcβ‚™ _ _ lemma norm_nnrpow (a : A) {r : ℝβ‰₯0} (hr : 0 < r) (ha : 0 ≀ a := by cfc_tac) : β€–a ^ rβ€– = β€–aβ€– ^ (r : ℝ) := congr(NNReal.toReal $(nnnorm_nnrpow a hr ha)) lemma nnnorm_sqrt (a : A) (ha : 0 ≀ a := by cfc_tac) : β€–sqrt aβ€–β‚Š = NNReal.sqrt β€–aβ€–β‚Š := by rw [sqrt_eq_nnrpow, NNReal.sqrt_eq_rpow] exact nnnorm_nnrpow a (by simp) ha lemma norm_sqrt (a : A) (ha : 0 ≀ a := by cfc_tac) : β€–sqrt aβ€– = βˆšβ€–aβ€– := by simpa using congr(NNReal.toReal $(nnnorm_sqrt a ha)) end nonunital section unital variable {A : Type*} [NormedRing A] [StarRing A] [NormedAlgebra ℝ A] [PartialOrder A] [StarOrderedRing A] [NonnegSpectrumClass ℝ A] [IsometricContinuousFunctionalCalculus ℝ A IsSelfAdjoint] lemma nnnorm_rpow (a : A) {r : ℝ} (hr : 0 < r) (ha : 0 ≀ a := by cfc_tac) : β€–a ^ rβ€–β‚Š = β€–aβ€–β‚Š ^ r := by lift r to ℝβ‰₯0 using hr.le rw [← nnrpow_eq_rpow, ← nnnorm_nnrpow a] all_goals simpa lemma norm_rpow (a : A) {r : ℝ} (hr : 0 < r) (ha : 0 ≀ a := by cfc_tac) : β€–a ^ rβ€– = β€–aβ€– ^ r := congr(NNReal.toReal $(nnnorm_rpow a hr ha)) end unital end CFC
.lake/packages/mathlib/Mathlib/Analysis/SpecialFunctions/ContinuousFunctionalCalculus/Rpow/Basic.lean
import Mathlib.Algebra.Order.Star.Prod import Mathlib.Analysis.CStarAlgebra.ContinuousFunctionalCalculus.Instances import Mathlib.Analysis.CStarAlgebra.ContinuousFunctionalCalculus.Pi import Mathlib.Analysis.CStarAlgebra.ContinuousFunctionalCalculus.Unique import Mathlib.Analysis.SpecialFunctions.ContinuousFunctionalCalculus.PosPart.Basic import Mathlib.Analysis.SpecialFunctions.Pow.Continuity import Mathlib.Analysis.SpecialFunctions.Pow.Real import Mathlib.Topology.ContinuousMap.ContinuousSqrt /-! # Real powers defined via the continuous functional calculus This file defines real powers via the continuous functional calculus (CFC) and builds its API. This allows one to take real powers of matrices, operators, elements of a C⋆-algebra, etc. The square root is also defined via the non-unital CFC. ## Main declarations + `CFC.nnrpow`: the `ℝβ‰₯0` power function based on the non-unital CFC, i.e. `cfcβ‚™ NNReal.rpow` composed with `(↑) : ℝβ‰₯0 β†’ ℝ`. + `CFC.sqrt`: the square root function based on the non-unital CFC, i.e. `cfcβ‚™ NNReal.sqrt` + `CFC.rpow`: the real power function based on the unital CFC, i.e. `cfc NNReal.rpow` ## Implementation notes We define two separate versions `CFC.nnrpow` and `CFC.rpow` due to what happens at 0. Since `NNReal.rpow 0 0 = 1`, this means that this function does not map zero to zero when the exponent is zero, and hence `CFC.nnrpow a 0 = 0` whereas `CFC.rpow a 0 = 1`. Note that the non-unital version only makes sense for nonnegative exponents, and hence we define it such that the exponent is in `ℝβ‰₯0`. ## Notation + We define a `Pow A ℝ` instance for `CFC.rpow`, i.e `a ^ y` with `A` an operator and `y : ℝ` works as expected. Likewise, we define a `Pow A ℝβ‰₯0` instance for `CFC.nnrpow`. Note that these are low-priority instances, in order to avoid overriding instances such as `Pow ℝ ℝ`, `Pow (A Γ— B) ℝ` or `Pow (βˆ€ i, A i) ℝ`. ## TODO + Relate these to the log and exp functions + Lemmas about how these functions interact with commuting `a` and `b`. + Prove the order properties (operator monotonicity and concavity/convexity) -/ open scoped NNReal namespace NNReal /-- Taking a nonnegative power of a nonnegative number. This is defined as a standalone definition in order to speed up automation such as `cfc_cont_tac`. -/ noncomputable abbrev nnrpow (a : ℝβ‰₯0) (b : ℝβ‰₯0) : ℝβ‰₯0 := a ^ (b : ℝ) @[simp] lemma nnrpow_def (a b : ℝβ‰₯0) : nnrpow a b = a ^ (b : ℝ) := rfl @[fun_prop] lemma continuous_nnrpow_const (y : ℝβ‰₯0) : Continuous (nnrpow Β· y) := continuous_rpow_const zero_le_coe /- This is a "redeclaration" of the attribute to speed up the proofs in this file. -/ attribute [fun_prop] continuousOn_rpow_const lemma monotone_nnrpow_const (y : ℝβ‰₯0) : Monotone (nnrpow Β· y) := monotone_rpow_of_nonneg zero_le_coe end NNReal namespace CFC section NonUnital variable {A : Type*} [PartialOrder A] [NonUnitalRing A] [TopologicalSpace A] [StarRing A] [Module ℝ A] [SMulCommClass ℝ A A] [IsScalarTower ℝ A A] [StarOrderedRing A] [NonUnitalContinuousFunctionalCalculus ℝ A IsSelfAdjoint] [NonnegSpectrumClass ℝ A] /- ## `nnrpow` -/ /-- Real powers of operators, based on the non-unital continuous functional calculus. -/ noncomputable def nnrpow (a : A) (y : ℝβ‰₯0) : A := cfcβ‚™ (NNReal.nnrpow Β· y) a /-- Enable `a ^ y` notation for `CFC.nnrpow`. This is a low-priority instance to make sure it does not take priority over other instances when they are available. -/ noncomputable instance (priority := 100) : Pow A ℝβ‰₯0 where pow a y := nnrpow a y @[simp] lemma nnrpow_eq_pow {a : A} {y : ℝβ‰₯0} : nnrpow a y = a ^ y := rfl @[simp] lemma nnrpow_nonneg {a : A} {x : ℝβ‰₯0} : 0 ≀ a ^ x := cfcβ‚™_predicate _ a grind_pattern nnrpow_nonneg => NonnegSpectrumClass ℝ A, a ^ x lemma nnrpow_def {a : A} {y : ℝβ‰₯0} : a ^ y = cfcβ‚™ (NNReal.nnrpow Β· y) a := rfl lemma nnrpow_eq_cfcβ‚™_real [T2Space A] [IsTopologicalRing A] (a : A) (y : ℝβ‰₯0) (ha : 0 ≀ a := by cfc_tac) : a ^ y = cfcβ‚™ (fun x : ℝ => x ^ (y : ℝ)) a := by rw [nnrpow_def, cfcβ‚™_nnreal_eq_real ..] refine cfcβ‚™_congr ?_ intro x hx have : 0 ≀ x := by grind simp [this] lemma nnrpow_add {a : A} {x y : ℝβ‰₯0} (hx : 0 < x) (hy : 0 < y) : a ^ (x + y) = a ^ x * a ^ y := by simp only [nnrpow_def] rw [← cfcβ‚™_mul _ _ a] congr! 2 with z exact mod_cast z.rpow_add' <| ne_of_gt (add_pos hx hy) @[simp] lemma nnrpow_zero {a : A} : a ^ (0 : ℝβ‰₯0) = 0 := by simp [nnrpow_def, cfcβ‚™_apply_of_not_map_zero] lemma nnrpow_one (a : A) (ha : 0 ≀ a := by cfc_tac) : a ^ (1 : ℝβ‰₯0) = a := by simp only [nnrpow_def, NNReal.nnrpow_def, NNReal.coe_one, NNReal.rpow_one] change cfcβ‚™ (id : ℝβ‰₯0 β†’ ℝβ‰₯0) a = a rw [cfcβ‚™_id ℝβ‰₯0 a] lemma nnrpow_two (a : A) (ha : 0 ≀ a := by cfc_tac) : a ^ (2 : ℝβ‰₯0) = a * a := by simp only [nnrpow_def, NNReal.nnrpow_def, NNReal.coe_ofNat, NNReal.rpow_ofNat, pow_two] change cfcβ‚™ (fun z : ℝβ‰₯0 => id z * id z) a = a * a rw [cfcβ‚™_mul id id a, cfcβ‚™_id ℝβ‰₯0 a] lemma nnrpow_three (a : A) (ha : 0 ≀ a := by cfc_tac) : a ^ (3 : ℝβ‰₯0) = a * a * a := by simp only [nnrpow_def, NNReal.nnrpow_def, NNReal.coe_ofNat, NNReal.rpow_ofNat, pow_three] change cfcβ‚™ (fun z : ℝβ‰₯0 => id z * (id z * id z)) a = a * a * a rw [cfcβ‚™_mul id _ a, cfcβ‚™_mul id _ a, ← mul_assoc, cfcβ‚™_id ℝβ‰₯0 a] @[simp] lemma zero_nnrpow {x : ℝβ‰₯0} : (0 : A) ^ x = 0 := by simp [nnrpow_def] section Unique variable [IsTopologicalRing A] [T2Space A] @[simp] lemma nnrpow_nnrpow {a : A} {x y : ℝβ‰₯0} : (a ^ x) ^ y = a ^ (x * y) := by by_cases ha : 0 ≀ a case pos => obtain (rfl | hx) := eq_zero_or_pos x <;> obtain (rfl | hy) := eq_zero_or_pos y all_goals try simp simp only [nnrpow_def] rw [← cfcβ‚™_comp _ _ a] congr! 2 with u ext simp [Real.rpow_mul] case neg => simp [nnrpow_def, cfcβ‚™_apply_of_not_predicate a ha] lemma nnrpow_nnrpow_inv (a : A) {x : ℝβ‰₯0} (hx : x β‰  0) (ha : 0 ≀ a := by cfc_tac) : (a ^ x) ^ x⁻¹ = a := by simp [mul_inv_cancelβ‚€ hx, nnrpow_one _ ha] lemma nnrpow_inv_nnrpow (a : A) {x : ℝβ‰₯0} (hx : x β‰  0) (ha : 0 ≀ a := by cfc_tac) : (a ^ x⁻¹) ^ x = a := by simp [inv_mul_cancelβ‚€ hx, nnrpow_one _ ha] lemma nnrpow_inv_eq (a b : A) {x : ℝβ‰₯0} (hx : x β‰  0) (ha : 0 ≀ a := by cfc_tac) (hb : 0 ≀ b := by cfc_tac) : a ^ x⁻¹ = b ↔ b ^ x = a := ⟨fun h ↦ nnrpow_inv_nnrpow a hx β–Έ congr($(h) ^ x).symm, fun h ↦ nnrpow_nnrpow_inv b hx β–Έ congr($(h) ^ x⁻¹).symm⟩ section prod variable {B : Type*} [PartialOrder B] [NonUnitalRing B] [TopologicalSpace B] [StarRing B] [Module ℝ B] [SMulCommClass ℝ B B] [IsScalarTower ℝ B B] [NonUnitalContinuousFunctionalCalculus ℝ B IsSelfAdjoint] [NonUnitalContinuousFunctionalCalculus ℝ (A Γ— B) IsSelfAdjoint] [IsTopologicalRing B] [T2Space B] [NonnegSpectrumClass ℝ B] [NonnegSpectrumClass ℝ (A Γ— B)] [StarOrderedRing B] /- Note that there is higher-priority instance of `Pow (A Γ— B) ℝβ‰₯0` coming from the `Pow` instance for products, hence the direct use of `nnrpow` here. -/ lemma nnrpow_map_prod {a : A} {b : B} {x : ℝβ‰₯0} (ha : 0 ≀ a := by cfc_tac) (hb : 0 ≀ b := by cfc_tac) : nnrpow (a, b) x = (a ^ x, b ^ x) := by simp only [nnrpow_def] unfold nnrpow refine cfcβ‚™_map_prod (S := ℝ) _ a b (by fun_prop) ?_ rw [Prod.le_def] constructor <;> simp [ha, hb] lemma nnrpow_eq_nnrpow_prod {a : A} {b : B} {x : ℝβ‰₯0} (ha : 0 ≀ a := by cfc_tac) (hb : 0 ≀ b := by cfc_tac) : nnrpow (a, b) x = (a, b) ^ x := nnrpow_map_prod end prod section pi variable {ΞΉ : Type*} {C : ΞΉ β†’ Type*} [βˆ€ i, PartialOrder (C i)] [βˆ€ i, NonUnitalRing (C i)] [βˆ€ i, TopologicalSpace (C i)] [βˆ€ i, StarRing (C i)] [βˆ€ i, StarOrderedRing (C i)] [StarOrderedRing (βˆ€ i, C i)] [βˆ€ i, Module ℝ (C i)] [βˆ€ i, SMulCommClass ℝ (C i) (C i)] [βˆ€ i, IsScalarTower ℝ (C i) (C i)] [βˆ€ i, NonUnitalContinuousFunctionalCalculus ℝ (C i) IsSelfAdjoint] [NonUnitalContinuousFunctionalCalculus ℝ (βˆ€ i, C i) IsSelfAdjoint] [βˆ€ i, IsTopologicalRing (C i)] [βˆ€ i, T2Space (C i)] [NonnegSpectrumClass ℝ (βˆ€ i, C i)] [βˆ€ i, NonnegSpectrumClass ℝ (C i)] /- Note that there is higher-priority instance of `Pow (βˆ€ i, C i) ℝβ‰₯0` coming from the `Pow` instance for pi types, hence the direct use of `nnrpow` here. -/ lemma nnrpow_map_pi {c : βˆ€ i, C i} {x : ℝβ‰₯0} (hc : βˆ€ i, 0 ≀ c i := by cfc_tac) : nnrpow c x = fun i => (c i) ^ x := by simp only [nnrpow_def] unfold nnrpow exact cfcβ‚™_map_pi (S := ℝ) _ c lemma nnrpow_eq_nnrpow_pi {c : βˆ€ i, C i} {x : ℝβ‰₯0} (hc : βˆ€ i, 0 ≀ c i := by cfc_tac) : nnrpow c x = c ^ x := nnrpow_map_pi end pi end Unique /- ## `sqrt` -/ section sqrt /-- Square roots of operators, based on the non-unital continuous functional calculus. -/ noncomputable def sqrt (a : A) : A := cfcβ‚™ NNReal.sqrt a @[simp] lemma sqrt_nonneg (a : A) : 0 ≀ sqrt a := cfcβ‚™_predicate _ a grind_pattern sqrt_nonneg => NonnegSpectrumClass ℝ A, sqrt a lemma sqrt_eq_nnrpow (a : A) : sqrt a = a ^ (1 / 2 : ℝβ‰₯0) := by simp only [sqrt] congr ext exact_mod_cast NNReal.sqrt_eq_rpow _ @[simp] lemma sqrt_zero : sqrt (0 : A) = 0 := by simp [sqrt] variable [IsTopologicalRing A] [T2Space A] @[simp] lemma nnrpow_sqrt {a : A} {x : ℝβ‰₯0} : (sqrt a) ^ x = a ^ (x / 2) := by rw [sqrt_eq_nnrpow, nnrpow_nnrpow, one_div_mul_eq_div 2 x] lemma nnrpow_sqrt_two (a : A) (ha : 0 ≀ a := by cfc_tac) : (sqrt a) ^ (2 : ℝβ‰₯0) = a := by simp only [nnrpow_sqrt, ne_eq, OfNat.ofNat_ne_zero, not_false_eq_true, div_self] rw [nnrpow_one a] lemma sqrt_mul_sqrt_self (a : A) (ha : 0 ≀ a := by cfc_tac) : sqrt a * sqrt a = a := by rw [← nnrpow_two _, nnrpow_sqrt_two _] @[simp] lemma sqrt_nnrpow {a : A} {x : ℝβ‰₯0} : sqrt (a ^ x) = a ^ (x / 2) := by simp [sqrt_eq_nnrpow, div_eq_mul_inv] lemma sqrt_nnrpow_two (a : A) (ha : 0 ≀ a := by cfc_tac) : sqrt (a ^ (2 : ℝβ‰₯0)) = a := by simp only [sqrt_nnrpow, ne_eq, OfNat.ofNat_ne_zero, not_false_eq_true, div_self] rw [nnrpow_one _] lemma sqrt_mul_self (a : A) (ha : 0 ≀ a := by cfc_tac) : sqrt (a * a) = a := by rw [← nnrpow_two _, sqrt_nnrpow_two _] lemma mul_self_eq {a b : A} (h : sqrt a = b) (ha : 0 ≀ a := by cfc_tac) : b * b = a := h β–Έ sqrt_mul_sqrt_self _ ha lemma sqrt_unique {a b : A} (h : b * b = a) (hb : 0 ≀ b := by cfc_tac) : sqrt a = b := h β–Έ sqrt_mul_self b lemma sqrt_eq_iff (a b : A) (ha : 0 ≀ a := by cfc_tac) (hb : 0 ≀ b := by cfc_tac) : sqrt a = b ↔ b * b = a := ⟨(mul_self_eq Β·), (sqrt_unique Β·)⟩ lemma sqrt_eq_zero_iff (a : A) (ha : 0 ≀ a := by cfc_tac) : sqrt a = 0 ↔ a = 0 := by rw [sqrt_eq_iff a _, mul_zero, eq_comm] lemma mul_self_eq_mul_self_iff (a b : A) (ha : 0 ≀ a := by cfc_tac) (hb : 0 ≀ b := by cfc_tac) : a * a = b * b ↔ a = b := ⟨fun h => sqrt_mul_self a β–Έ sqrt_unique h.symm, fun h => h β–Έ rfl⟩ /-- Note that the hypothesis `0 ≀ a` is necessary because the continuous functional calculi over `ℝβ‰₯0` (for the left-hand side) and `ℝ` (for the right-hand side) use different predicates (i.e., `(0 ≀ Β·)` versus `IsSelfAdjoint`). Consequently, if `a` is selfadjoint but not nonnegative, then the left-hand side is zero, but the right-hand side is (provably equal to) `CFC.sqrt a⁺`. -/ lemma sqrt_eq_real_sqrt (a : A) (ha : 0 ≀ a := by cfc_tac) : CFC.sqrt a = cfcβ‚™ Real.sqrt a := by suffices cfcβ‚™ (fun x : ℝ ↦ √x * √x) a = cfcβ‚™ (fun x : ℝ ↦ x) a by rwa [cfcβ‚™_mul .., cfcβ‚™_id' .., ← sqrt_eq_iff _ (hb := cfcβ‚™_nonneg (fun x _ ↦ Real.sqrt_nonneg x))] at this exact cfcβ‚™_congr fun x hx ↦ Real.mul_self_sqrt <| quasispectrum_nonneg_of_nonneg a ha x hx section prod variable {B : Type*} [PartialOrder B] [NonUnitalRing B] [TopologicalSpace B] [StarRing B] [Module ℝ B] [SMulCommClass ℝ B B] [IsScalarTower ℝ B B] [StarOrderedRing B] [NonUnitalContinuousFunctionalCalculus ℝ B IsSelfAdjoint] [NonUnitalContinuousFunctionalCalculus ℝ (A Γ— B) IsSelfAdjoint] [IsTopologicalRing B] [T2Space B] [NonnegSpectrumClass ℝ B] [NonnegSpectrumClass ℝ (A Γ— B)] lemma sqrt_map_prod {a : A} {b : B} (ha : 0 ≀ a := by cfc_tac) (hb : 0 ≀ b := by cfc_tac) : sqrt (a, b) = (sqrt a, sqrt b) := by simp only [sqrt_eq_nnrpow] exact nnrpow_map_prod end prod section pi variable {ΞΉ : Type*} {C : ΞΉ β†’ Type*} [βˆ€ i, PartialOrder (C i)] [βˆ€ i, NonUnitalRing (C i)] [βˆ€ i, TopologicalSpace (C i)] [βˆ€ i, StarRing (C i)] [βˆ€ i, StarOrderedRing (C i)] [StarOrderedRing (βˆ€ i, C i)] [βˆ€ i, Module ℝ (C i)] [βˆ€ i, SMulCommClass ℝ (C i) (C i)] [βˆ€ i, IsScalarTower ℝ (C i) (C i)] [βˆ€ i, NonUnitalContinuousFunctionalCalculus ℝ (C i) IsSelfAdjoint] [NonUnitalContinuousFunctionalCalculus ℝ (βˆ€ i, C i) IsSelfAdjoint] [βˆ€ i, IsTopologicalRing (C i)] [βˆ€ i, T2Space (C i)] [NonnegSpectrumClass ℝ (βˆ€ i, C i)] [βˆ€ i, NonnegSpectrumClass ℝ (C i)] lemma sqrt_map_pi {c : βˆ€ i, C i} (hc : βˆ€ i, 0 ≀ c i := by cfc_tac) : sqrt c = fun i => sqrt (c i) := by simp only [sqrt_eq_nnrpow] exact nnrpow_map_pi end pi /-- For an element `a` in a C⋆-algebra, TFAE: 1. `0 ≀ a` 2. `a = sqrt a * sqrt a` 3. `a = b * b` for some nonnegative `b` 4. `a = b * b` for some self-adjoint `b` 5. `a = star b * b` for some `b` 6. `a = b * star b` for some `b` 7. `a = a⁺` 8. `a` is self-adjoint and `a⁻ = 0` 9. `a` is self-adjoint and has nonnegative spectrum -/ theorem _root_.CStarAlgebra.nonneg_TFAE {a : A} : [ 0 ≀ a, a = sqrt a * sqrt a, βˆƒ b : A, 0 ≀ b ∧ a = b * b, βˆƒ b : A, IsSelfAdjoint b ∧ a = b * b, βˆƒ b : A, a = star b * b, βˆƒ b : A, a = b * star b, a = a⁺, IsSelfAdjoint a ∧ a⁻ = 0, IsSelfAdjoint a ∧ QuasispectrumRestricts a ContinuousMap.realToNNReal ].TFAE := by tfae_have 1 ↔ 9 := nonneg_iff_isSelfAdjoint_and_quasispectrumRestricts tfae_have 1 ↔ 7 := eq_comm.eq β–Έ (CFC.posPart_eq_self a).symm tfae_have 1 ↔ 8 := ⟨fun h => ⟨h.isSelfAdjoint, negPart_eq_zero_iff a |>.mpr h⟩, fun h => negPart_eq_zero_iff a |>.mp h.2⟩ tfae_have 1 β†’ 2 := fun h => sqrt_mul_sqrt_self a |>.symm tfae_have 2 β†’ 3 := fun h => ⟨sqrt a, sqrt_nonneg a, h⟩ tfae_have 3 β†’ 4 := fun ⟨b, hb⟩ => ⟨b, hb.1.isSelfAdjoint, hb.2⟩ tfae_have 4 β†’ 5 := fun ⟨b, hb⟩ => ⟨b, hb.1.symm β–Έ hb.2⟩ tfae_have 5 β†’ 6 := fun ⟨b, hb⟩ => ⟨star b, star_star b |>.symm β–Έ hb⟩ tfae_have 6 β†’ 1 := fun ⟨b, hb⟩ => hb β–Έ mul_star_self_nonneg _ tfae_finish theorem _root_.CStarAlgebra.nonneg_iff_eq_sqrt_mul_sqrt {a : A} : 0 ≀ a ↔ a = sqrt a * sqrt a := CStarAlgebra.nonneg_TFAE.out 0 1 theorem _root_.CStarAlgebra.nonneg_iff_exists_nonneg_and_eq_mul_self {a : A} : 0 ≀ a ↔ βˆƒ b, 0 ≀ b ∧ a = b * b := CStarAlgebra.nonneg_TFAE.out 0 2 theorem _root_.CStarAlgebra.nonneg_iff_exists_isSelfAdjoint_and_eq_mul_self {a : A} : 0 ≀ a ↔ βˆƒ b, IsSelfAdjoint b ∧ a = b * b := CStarAlgebra.nonneg_TFAE.out 0 3 theorem _root_.CStarAlgebra.nonneg_iff_eq_star_mul_self {a : A} : 0 ≀ a ↔ βˆƒ b, a = star b * b := CStarAlgebra.nonneg_TFAE.out 0 4 theorem _root_.CStarAlgebra.nonneg_iff_eq_mul_star_self {a : A} : 0 ≀ a ↔ βˆƒ b, a = b * star b := CStarAlgebra.nonneg_TFAE.out 0 5 theorem _root_.CStarAlgebra.nonneg_iff_isSelfAdjoint_and_negPart_eq_zero {a : A} : 0 ≀ a ↔ IsSelfAdjoint a ∧ a⁻ = 0 := CStarAlgebra.nonneg_TFAE.out 0 7 end sqrt end NonUnital section Unital variable {A : Type*} [PartialOrder A] [Ring A] [StarRing A] [TopologicalSpace A] [StarOrderedRing A] [Algebra ℝ A] [ContinuousFunctionalCalculus ℝ A IsSelfAdjoint] [NonnegSpectrumClass ℝ A] /- ## `rpow` -/ /-- Real powers of operators, based on the unital continuous functional calculus. -/ noncomputable def rpow (a : A) (y : ℝ) : A := cfc (fun x : ℝβ‰₯0 => x ^ y) a /-- Enable `a ^ y` notation for `CFC.rpow`. This is a low-priority instance to make sure it does not take priority over other instances when they are available (such as `Pow ℝ ℝ`). -/ noncomputable instance (priority := 100) : Pow A ℝ where pow a y := rpow a y @[simp] lemma rpow_eq_pow {a : A} {y : ℝ} : rpow a y = a ^ y := rfl @[simp] lemma rpow_nonneg {a : A} {y : ℝ} : 0 ≀ a ^ y := cfc_predicate _ a grind_pattern rpow_nonneg => NonnegSpectrumClass ℝ A, a ^ y lemma rpow_def {a : A} {y : ℝ} : a ^ y = cfc (fun x : ℝβ‰₯0 => x ^ y) a := rfl lemma rpow_one (a : A) (ha : 0 ≀ a := by cfc_tac) : a ^ (1 : ℝ) = a := by simp only [rpow_def, NNReal.rpow_one, cfc_id' ℝβ‰₯0 a] @[simp] lemma one_rpow {x : ℝ} : (1 : A) ^ x = (1 : A) := by simp [rpow_def] lemma rpow_zero (a : A) (ha : 0 ≀ a := by cfc_tac) : a ^ (0 : ℝ) = 1 := by simp [rpow_def, cfc_const_one ℝβ‰₯0 a] lemma zero_rpow {x : ℝ} (hx : x β‰  0) : rpow (0 : A) x = 0 := by simp [rpow, NNReal.zero_rpow hx] lemma rpow_natCast (a : A) (n : β„•) (ha : 0 ≀ a := by cfc_tac) : a ^ (n : ℝ) = a ^ n := by rw [← cfc_pow_id (R := ℝβ‰₯0) a n, rpow_def] congr simp @[simp] lemma rpow_algebraMap {x : ℝβ‰₯0} {y : ℝ} : (algebraMap ℝβ‰₯0 A x) ^ y = algebraMap ℝβ‰₯0 A (x ^ y) := by rw [rpow_def, cfc_algebraMap ..] lemma rpow_add {a : A} {x y : ℝ} (ha : IsUnit a) : a ^ (x + y) = a ^ x * a ^ y := by have ha' : 0 βˆ‰ spectrum ℝβ‰₯0 a := spectrum.zero_notMem _ ha simp only [rpow_def] rw [← cfc_mul _ _ a] refine cfc_congr ?_ intro z hz have : z β‰  0 := by aesop simp [NNReal.rpow_add this _ _] lemma rpow_rpow [IsTopologicalRing A] [T2Space A] (a : A) (x y : ℝ) (ha₁ : IsUnit a) (hx : x β‰  0) (haβ‚‚ : 0 ≀ a := by cfc_tac) : (a ^ x) ^ y = a ^ (x * y) := by have ha₁' : 0 βˆ‰ spectrum ℝβ‰₯0 a := spectrum.zero_notMem _ ha₁ simp only [rpow_def] rw [← cfc_comp _ _ a haβ‚‚] refine cfc_congr fun _ _ => ?_ simp [NNReal.rpow_mul] lemma rpow_rpow_inv [IsTopologicalRing A] [T2Space A] (a : A) (x : ℝ) (ha₁ : IsUnit a) (hx : x β‰  0) (haβ‚‚ : 0 ≀ a := by cfc_tac) : (a ^ x) ^ x⁻¹ = a := by rw [rpow_rpow a x x⁻¹ ha₁ hx haβ‚‚, mul_inv_cancelβ‚€ hx, rpow_one a haβ‚‚] lemma rpow_inv_rpow [IsTopologicalRing A] [T2Space A] (a : A) (x : ℝ) (ha₁ : IsUnit a) (hx : x β‰  0) (haβ‚‚ : 0 ≀ a := by cfc_tac) : (a ^ x⁻¹) ^ x = a := by simpa using rpow_rpow_inv a x⁻¹ ha₁ (inv_ne_zero hx) haβ‚‚ lemma rpow_rpow_of_exponent_nonneg [IsTopologicalRing A] [T2Space A] (a : A) (x y : ℝ) (hx : 0 ≀ x) (hy : 0 ≀ y) (haβ‚‚ : 0 ≀ a := by cfc_tac) : (a ^ x) ^ y = a ^ (x * y) := by simp only [rpow_def] rw [← cfc_comp _ _ a] refine cfc_congr fun _ _ => ?_ simp [NNReal.rpow_mul] lemma rpow_mul_rpow_neg {a : A} (x : ℝ) (ha : IsUnit a) (ha' : 0 ≀ a := by cfc_tac) : a ^ x * a ^ (-x) = 1 := by rw [← rpow_add ha, add_neg_cancel, rpow_zero a] lemma rpow_neg_mul_rpow {a : A} (x : ℝ) (ha : IsUnit a) (ha' : 0 ≀ a := by cfc_tac) : a ^ (-x) * a ^ x = 1 := by rw [← rpow_add ha, neg_add_cancel, rpow_zero a] lemma rpow_neg_one_eq_inv (a : AΛ£) (ha : (0 : A) ≀ a := by cfc_tac) : a ^ (-1 : ℝ) = (↑a⁻¹ : A) := by refine a.inv_eq_of_mul_eq_one_left ?_ |>.symm simpa [rpow_one (a : A)] using rpow_neg_mul_rpow 1 a.isUnit lemma rpow_neg_one_eq_cfc_inv {A : Type*} [PartialOrder A] [NormedRing A] [StarRing A] [StarOrderedRing A] [NormedAlgebra ℝ A] [NonnegSpectrumClass ℝ A] [ContinuousFunctionalCalculus ℝ A IsSelfAdjoint] (a : A) : a ^ (-1 : ℝ) = cfc (·⁻¹ : ℝβ‰₯0 β†’ ℝβ‰₯0) a := cfc_congr fun x _ ↦ NNReal.rpow_neg_one x lemma rpow_neg [IsTopologicalRing A] [T2Space A] (a : AΛ£) (x : ℝ) (ha' : (0 : A) ≀ a := by cfc_tac) : (a : A) ^ (-x) = (↑a⁻¹ : A) ^ x := by suffices h₁ : ContinuousOn (fun z ↦ z ^ x) (Inv.inv '' (spectrum ℝβ‰₯0 (a : A))) by rw [← cfc_inv_id (R := ℝβ‰₯0) a, rpow_def, rpow_def, ← cfc_comp' (fun z => z ^ x) (Inv.inv : ℝβ‰₯0 β†’ ℝβ‰₯0) (a : A) h₁] refine cfc_congr fun _ _ => ?_ simp [NNReal.rpow_neg, NNReal.inv_rpow] refine NNReal.continuousOn_rpow_const (.inl ?_) rintro ⟨z, hz, hz'⟩ exact spectrum.zero_notMem ℝβ‰₯0 a.isUnit <| inv_eq_zero.mp hz' β–Έ hz lemma rpow_intCast (a : AΛ£) (n : β„€) (ha : (0 : A) ≀ a := by cfc_tac) : (a : A) ^ (n : ℝ) = (↑(a ^ n) : A) := by rw [← cfc_zpow (R := ℝβ‰₯0) a n, rpow_def] refine cfc_congr fun _ _ => ?_ simp /-- `a ^ x` bundled as an element of `AΛ£` for `a : AΛ£`. -/ @[simps] noncomputable def _root_.Units.cfcRpow (a : AΛ£) (x : ℝ) (ha : (0 : A) ≀ a := by cfc_tac) : AΛ£ := ⟨(a : A) ^ x, (a : A) ^ (-x), rpow_mul_rpow_neg x (by simp), rpow_neg_mul_rpow x (by simp)⟩ @[aesop safe apply, grind ←] lemma _root_.IsUnit.cfcRpow {a : A} (ha : IsUnit a) (x : ℝ) (ha_nonneg : 0 ≀ a := by cfc_tac) : IsUnit (a ^ x) := ha.unit.cfcRpow x |>.isUnit lemma spectrum_rpow (a : A) (x : ℝ) (h : ContinuousOn (Β· ^ x) (spectrum ℝβ‰₯0 a) := by cfc_cont_tac) (ha : 0 ≀ a := by cfc_tac) : spectrum ℝβ‰₯0 (a ^ x) = (Β· ^ x) '' spectrum ℝβ‰₯0 a := cfc_map_spectrum (Β· ^ x : ℝβ‰₯0 β†’ ℝβ‰₯0) a ha h @[grind =] lemma isUnit_rpow_iff (a : A) (y : ℝ) (hy : y β‰  0) (ha : 0 ≀ a := by cfc_tac) : IsUnit (a ^ y) ↔ IsUnit a := by nontriviality A refine ⟨fun h => ?_, fun h => h.cfcRpow y ha⟩ rw [rpow_def] at h by_cases hf : ContinuousOn (fun x : ℝβ‰₯0 => x ^ y) (spectrum ℝβ‰₯0 a) Β· rw [isUnit_cfc_iff _ a hf] at h refine spectrum.isUnit_of_zero_notMem ℝβ‰₯0 ?_ intro h0 specialize h 0 h0 simp only [ne_eq, NNReal.rpow_eq_zero_iff, true_and, Decidable.not_not] at h exact hy h Β· rw [cfc_apply_of_not_continuousOn a hf] at h exact False.elim <| not_isUnit_zero h section prod variable [IsTopologicalRing A] [T2Space A] variable {B : Type*} [PartialOrder B] [Ring B] [StarRing B] [TopologicalSpace B] [StarOrderedRing B] [Algebra ℝ B] [ContinuousFunctionalCalculus ℝ B IsSelfAdjoint] [ContinuousFunctionalCalculus ℝ (A Γ— B) IsSelfAdjoint] [IsTopologicalRing B] [T2Space B] [StarOrderedRing (A Γ— B)] [NonnegSpectrumClass ℝ B] [NonnegSpectrumClass ℝ (A Γ— B)] /- Note that there is higher-priority instance of `Pow (A Γ— B) ℝ` coming from the `Pow` instance for products, hence the direct use of `rpow` here. -/ lemma rpow_map_prod {a : A} {b : B} {x : ℝ} (ha : IsUnit a) (hb : IsUnit b) (ha' : 0 ≀ a := by cfc_tac) (hb' : 0 ≀ b := by cfc_tac) : rpow (a, b) x = (a ^ x, b ^ x) := by have ha'' : 0 βˆ‰ spectrum ℝβ‰₯0 a := spectrum.zero_notMem _ ha have hb'' : 0 βˆ‰ spectrum ℝβ‰₯0 b := spectrum.zero_notMem _ hb simp only [rpow_def] unfold rpow refine cfc_map_prod (R := ℝβ‰₯0) (S := ℝ) _ a b (by cfc_cont_tac) ?_ rw [Prod.le_def] constructor <;> simp [ha', hb'] lemma rpow_eq_rpow_prod {a : A} {b : B} {x : ℝ} (ha : IsUnit a) (hb : IsUnit b) (ha' : 0 ≀ a := by cfc_tac) (hb' : 0 ≀ b := by cfc_tac) : rpow (a, b) x = (a, b) ^ x := rpow_map_prod ha hb @[deprecated (since := "2025-05-13")] alias rpow_eq_rpow_rpod := rpow_eq_rpow_prod end prod section pi variable [IsTopologicalRing A] [T2Space A] variable {ΞΉ : Type*} {C : ΞΉ β†’ Type*} [βˆ€ i, PartialOrder (C i)] [βˆ€ i, Ring (C i)] [βˆ€ i, StarRing (C i)] [βˆ€ i, TopologicalSpace (C i)] [βˆ€ i, StarOrderedRing (C i)] [StarOrderedRing (βˆ€ i, C i)] [βˆ€ i, Algebra ℝ (C i)] [βˆ€ i, ContinuousFunctionalCalculus ℝ (C i) IsSelfAdjoint] [ContinuousFunctionalCalculus ℝ (βˆ€ i, C i) IsSelfAdjoint] [βˆ€ i, IsTopologicalRing (C i)] [βˆ€ i, T2Space (C i)] [NonnegSpectrumClass ℝ (βˆ€ i, C i)] [βˆ€ i, NonnegSpectrumClass ℝ (C i)] /- Note that there is a higher-priority instance of `Pow (βˆ€ i, B i) ℝ` coming from the `Pow` instance for pi types, hence the direct use of `rpow` here. -/ lemma rpow_map_pi {c : βˆ€ i, C i} {x : ℝ} (hc : βˆ€ i, IsUnit (c i)) (hc' : βˆ€ i, 0 ≀ c i := by cfc_tac) : rpow c x = fun i => (c i) ^ x := by have hc'' : βˆ€ i, 0 βˆ‰ spectrum ℝβ‰₯0 (c i) := fun i => spectrum.zero_notMem _ (hc i) simp only [rpow_def] unfold rpow exact cfc_map_pi (S := ℝ) _ c lemma rpow_eq_rpow_pi {c : βˆ€ i, C i} {x : ℝ} (hc : βˆ€ i, IsUnit (c i)) (hc' : βˆ€ i, 0 ≀ c i := by cfc_tac) : rpow c x = c ^ x := rpow_map_pi hc end pi section unital_vs_nonunital variable [IsTopologicalRing A] [T2Space A] -- provides instance `ContinuousFunctionalCalculus.compactSpace_spectrum` open scoped ContinuousFunctionalCalculus lemma nnrpow_eq_rpow {a : A} {x : ℝβ‰₯0} (hx : 0 < x) : a ^ x = a ^ (x : ℝ) := by rw [nnrpow_def (A := A), rpow_def, cfcβ‚™_eq_cfc] lemma sqrt_eq_rpow {a : A} : sqrt a = a ^ (1 / 2 : ℝ) := by have : a ^ (1 / 2 : ℝ) = a ^ ((1 / 2 : ℝβ‰₯0) : ℝ) := rfl rw [this, ← nnrpow_eq_rpow (by simp), sqrt_eq_nnrpow a] lemma sqrt_eq_cfc {a : A} : sqrt a = cfc NNReal.sqrt a := by unfold sqrt rw [cfcβ‚™_eq_cfc] lemma sqrt_sq (a : A) (ha : 0 ≀ a := by cfc_tac) : sqrt (a ^ 2) = a := by rw [pow_two, sqrt_mul_self (A := A) a] lemma sq_sqrt (a : A) (ha : 0 ≀ a := by cfc_tac) : (sqrt a) ^ 2 = a := by rw [pow_two, sqrt_mul_sqrt_self (A := A) a] lemma sq_eq_sq_iff (a b : A) (ha : 0 ≀ a := by cfc_tac) (hb : 0 ≀ b := by cfc_tac) : a ^ 2 = b ^ 2 ↔ a = b := by simp_rw [sq, mul_self_eq_mul_self_iff a b] @[simp] lemma sqrt_algebraMap {r : ℝβ‰₯0} : sqrt (algebraMap ℝβ‰₯0 A r) = algebraMap ℝβ‰₯0 A (NNReal.sqrt r) := by rw [sqrt_eq_cfc, cfc_algebraMap] @[simp] lemma sqrt_one : sqrt (1 : A) = 1 := by simp [sqrt_eq_cfc] lemma sqrt_eq_one_iff (a : A) (ha : 0 ≀ a := by cfc_tac) : sqrt a = 1 ↔ a = 1 := by rw [sqrt_eq_iff a _, mul_one, eq_comm] lemma sqrt_eq_one_iff' [Nontrivial A] (a : A) : sqrt a = 1 ↔ a = 1 := by refine ⟨fun h ↦ sqrt_eq_one_iff a ?_ |>.mp h, fun h ↦ h β–Έ sqrt_one⟩ rw [sqrt, cfcβ‚™] at h cfc_tac -- TODO: relate to a strict positivity condition lemma sqrt_rpow {a : A} {x : ℝ} (h : IsUnit a) (hx : x β‰  0) : sqrt (a ^ x) = a ^ (x / 2) := by by_cases hnonneg : 0 ≀ a case pos => simp only [sqrt_eq_rpow, div_eq_mul_inv, one_mul, rpow_rpow _ _ _ h hx] case neg => simp [sqrt_eq_cfc, rpow_def, cfc_apply_of_not_predicate a hnonneg] -- TODO: relate to a strict positivity condition lemma rpow_sqrt (a : A) (x : ℝ) (h : IsUnit a) (ha : 0 ≀ a := by cfc_tac) : (sqrt a) ^ x = a ^ (x / 2) := by rw [sqrt_eq_rpow, div_eq_mul_inv, one_mul, rpow_rpow _ _ _ h (by simp), inv_mul_eq_div] lemma sqrt_rpow_nnreal {a : A} {x : ℝβ‰₯0} : sqrt (a ^ (x : ℝ)) = a ^ (x / 2 : ℝ) := by by_cases htriv : 0 ≀ a case neg => simp [sqrt_eq_cfc, rpow_def, cfc_apply_of_not_predicate a htriv] case pos => cases eq_zero_or_pos x with | inl hx => simp [hx, rpow_zero _ htriv] | inr h₁ => have hβ‚‚ : (x : ℝ) / 2 = NNReal.toReal (x / 2) := by simp have h₃ : 0 < x / 2 := by positivity rw [← nnrpow_eq_rpow h₁, hβ‚‚, ← nnrpow_eq_rpow h₃, sqrt_nnrpow (A := A)] lemma rpow_sqrt_nnreal {a : A} {x : ℝβ‰₯0} (ha : 0 ≀ a := by cfc_tac) : (sqrt a) ^ (x : ℝ) = a ^ (x / 2 : ℝ) := by by_cases hx : x = 0 case pos => have ha' : 0 ≀ sqrt a := sqrt_nonneg _ simp [hx, rpow_zero _ ha', rpow_zero _ ha] case neg => have h₁ : 0 ≀ (x : ℝ) := NNReal.zero_le_coe rw [sqrt_eq_rpow, rpow_rpow_of_exponent_nonneg _ _ _ (by simp) h₁, one_div_mul_eq_div] @[grind =] lemma isUnit_nnrpow_iff (a : A) (y : ℝβ‰₯0) (hy : y β‰  0) (ha : 0 ≀ a := by cfc_tac) : IsUnit (a ^ y) ↔ IsUnit a := by rw [nnrpow_eq_rpow (pos_of_ne_zero hy)] refine isUnit_rpow_iff a y ?_ ha exact_mod_cast hy @[aesop safe apply] lemma _root_.IsUnit.cfcNNRpow (a : A) (y : ℝβ‰₯0) (ha_unit : IsUnit a) (hy : y β‰  0) (ha : 0 ≀ a := by cfc_tac) : IsUnit (a ^ y) := (isUnit_nnrpow_iff a y hy ha).mpr ha_unit @[grind =] lemma isUnit_sqrt_iff (a : A) (ha : 0 ≀ a := by cfc_tac) : IsUnit (sqrt a) ↔ IsUnit a := by rw [sqrt_eq_rpow] exact isUnit_rpow_iff a _ (by simp) ha @[aesop safe apply] lemma _root_.IsUnit.cfcSqrt (a : A) (ha_unit : IsUnit a) (ha : 0 ≀ a := by cfc_tac) : IsUnit (sqrt a) := (isUnit_sqrt_iff a ha).mpr ha_unit @[aesop safe apply] lemma _root_.IsStrictlyPositive.nnrpow {a : A} {y : ℝβ‰₯0} (ha : IsStrictlyPositive a) (hy : y β‰  0) : IsStrictlyPositive (a ^ y) := by grind @[aesop safe apply] lemma _root_.IsStrictlyPositive.sqrt {a : A} (ha : IsStrictlyPositive a) : IsStrictlyPositive (sqrt a) := by grind omit [T2Space A] [IsTopologicalRing A] in @[aesop safe apply] lemma _root_.IsStrictlyPositive.rpow {a : A} {y : ℝ} (ha : IsStrictlyPositive a) : IsStrictlyPositive (a ^ y) := by grind /-- For an element `a` in a C⋆-algebra, TFAE: 1. `a` is strictly positive, 2. `sqrt a` is strictly positive and `a = sqrt a * sqrt a`, 3. `sqrt a` is invertible and `a = sqrt a * sqrt a`, 4. `a = b * b` for some strictly positive `b`, 5. `a = b * b` for some self-adjoint and invertible `b`, 6. `a = star b * b` for some invertible `b`, 7. `a = b * star b` for some invertible `b`, 8. `0 ≀ a` and `a` is invertible, 9. `a` is self-adjoint and has positive spectrum. -/ theorem _root_.CStarAlgebra.isStrictlyPositive_TFAE {a : A} : [IsStrictlyPositive a, IsStrictlyPositive (sqrt a) ∧ a = sqrt a * sqrt a, IsUnit (sqrt a) ∧ a = sqrt a * sqrt a, βˆƒ b, IsStrictlyPositive b ∧ a = b * b, βˆƒ b, IsUnit b ∧ IsSelfAdjoint b ∧ a = b * b, βˆƒ b, IsUnit b ∧ a = star b * b, βˆƒ b, IsUnit b ∧ a = b * star b, 0 ≀ a ∧ IsUnit a, IsSelfAdjoint a ∧ βˆ€ x ∈ spectrum ℝ a, 0 < x].TFAE := by tfae_have 1 ↔ 8 := IsStrictlyPositive.iff_of_unital tfae_have 1 ↔ 9 := ⟨fun h => ⟨h.isSelfAdjoint, StarOrderedRing.isStrictlyPositive_iff_spectrum_pos a |>.mp h⟩, fun h => (StarOrderedRing.isStrictlyPositive_iff_spectrum_pos a).mpr h.2⟩ tfae_have 1 β†’ 2 := fun h => ⟨h.sqrt, sqrt_mul_sqrt_self a |>.symm⟩ tfae_have 2 β†’ 3 := fun h => ⟨h.1.isUnit, h.2⟩ tfae_have 3 β†’ 4 := fun h => ⟨sqrt a, h.1.isStrictlyPositive (sqrt_nonneg _), h.2⟩ tfae_have 4 β†’ 5 := fun ⟨b, hb, hab⟩ => ⟨b, hb.isUnit, hb.isSelfAdjoint, hab⟩ tfae_have 5 β†’ 6 := fun ⟨b, hb, hbsa, hab⟩ => ⟨b, hb, hbsa.symm β–Έ hab⟩ tfae_have 6 β†’ 7 := fun ⟨b, hb, hab⟩ => ⟨star b, hb.star, star_star b |>.symm β–Έ hab⟩ tfae_have 7 β†’ 8 := fun ⟨b, hb, hab⟩ => ⟨hab β–Έ mul_star_self_nonneg _, hab β–Έ hb.mul hb.star⟩ tfae_finish theorem _root_.CStarAlgebra.isStrictlyPositive_iff_isStrictlyPositive_sqrt_and_eq_sqrt_mul_sqrt {a : A} : IsStrictlyPositive a ↔ IsStrictlyPositive (sqrt a) ∧ a = sqrt a * sqrt a := CStarAlgebra.isStrictlyPositive_TFAE.out 0 1 theorem _root_.CStarAlgebra.isStrictlyPositive_iff_isUnit_sqrt_and_eq_sqrt_mul_sqrt {a : A} : IsStrictlyPositive a ↔ IsUnit (sqrt a) ∧ a = sqrt a * sqrt a := CStarAlgebra.isStrictlyPositive_TFAE.out 0 2 theorem _root_.CStarAlgebra.isStrictlyPositive_iff_exists_isStrictlyPositive_and_eq_mul_self {a : A} : IsStrictlyPositive a ↔ βˆƒ b, IsStrictlyPositive b ∧ a = b * b := CStarAlgebra.isStrictlyPositive_TFAE.out 0 3 theorem _root_.CStarAlgebra.isStrictlyPositive_iff_exists_isUnit_and_isSelfAdjoint_and_eq_mul_self {a : A} : IsStrictlyPositive a ↔ βˆƒ b, IsUnit b ∧ IsSelfAdjoint b ∧ a = b * b := CStarAlgebra.isStrictlyPositive_TFAE.out 0 4 theorem _root_.CStarAlgebra.isStrictlyPositive_iff_eq_star_mul_self {a : A} : IsStrictlyPositive a ↔ βˆƒ b, IsUnit b ∧ a = star b * b := CStarAlgebra.isStrictlyPositive_TFAE.out 0 5 theorem _root_.CStarAlgebra.isStrictlyPositive_iff_eq_mul_star_self {a : A} : IsStrictlyPositive a ↔ βˆƒ b, IsUnit b ∧ a = b * star b := CStarAlgebra.isStrictlyPositive_TFAE.out 0 6 theorem _root_.CStarAlgebra.isStrictlyPositive_iff_isSelfAdjoint_and_spectrum_pos {a : A} : IsStrictlyPositive a ↔ IsSelfAdjoint a ∧ βˆ€ x ∈ spectrum ℝ a, 0 < x := CStarAlgebra.isStrictlyPositive_TFAE.out 0 8 end unital_vs_nonunital end Unital end CFC
.lake/packages/mathlib/Mathlib/Analysis/SpecialFunctions/ContinuousFunctionalCalculus/Rpow/IntegralRepresentation.lean
import Mathlib.Analysis.SpecialFunctions.ImproperIntegrals import Mathlib.Analysis.CStarAlgebra.ContinuousFunctionalCalculus.Integral import Mathlib.Analysis.CStarAlgebra.ApproximateUnit /-! # Integral representations of `rpow` This file contains an integral representation of the `rpow` function between 0 and 1: we show that there exists a measure on ℝ such that `x ^ p = ∫ t, rpowIntegrand₀₁ p t x βˆ‚ΞΌ` for the integrand `rpowIntegrand₀₁ p t x := t ^ p * (t⁻¹ - (t + x)⁻¹)`. This representation is useful for showing that `rpow` is operator monotone and operator concave in this range; that is, `cfc rpow` is monotone/concave. The integrand can be shown to be operator monotone and concave through direct means, and this integral lifts these properties to `rpow`. ## Notes Here we only compute the integral up to a constant, even though the actual constant can be computed via contour integration. We chose to avoid this, as the constant is seldom if ever relevant in applications, and would needlessly complicate the proof. ## Main declarations + `rpowIntegrand₀₁ p t x := t ^ p * (t⁻¹ - (t + x)⁻¹)` + `exists_measure_rpow_eq_integral`: there exists a measure on `ℝ` such that `x ^ p = ∫ t, rpowIntegrand₀₁ p t x βˆ‚ΞΌ` + `CFC.exists_measure_nnrpow_eq_integral_cfcβ‚™_rpowIntegrand₀₁`: the corresponding statement where `x ^ p` is defined via the CFC. + `CFC.monotone_nnrpow`, `CFC.monotone_rpow`: `a ↦ a ^ p` is operator monotone for `p ∈ [0,1]` + `CFC.monotone_sqrt`: `CFC.sqrt` is operator monotone ## TODO + Show operator concavity of `rpow` over `Icc 0 1` + Give analogous representations for the ranges `Ioo (-1) 0` and `Ioo 1 2`. ## References + [carlen2010] Eric A. Carlen, "Trace inequalities and quantum entropies: An introductory course" (see Lemma 2.8) -/ open MeasureTheory Set Filter open scoped NNReal Topology namespace Real /-- Integrand for representing `x ↦ x ^ p` for `p ∈ (0,1)` -/ noncomputable def rpowIntegrand₀₁ (p t x : ℝ) : ℝ := t ^ p * (t⁻¹ - (t + x)⁻¹) variable {p t x : ℝ} @[simp] lemma rpowIntegrand₀₁_zero_right : rpowIntegrand₀₁ p t 0 = 0 := by simp [rpowIntegrand₀₁] lemma rpowIntegrand₀₁_zero_left (hp : 0 < p) : rpowIntegrand₀₁ p 0 x = 0 := by simp [rpowIntegrand₀₁, Real.zero_rpow hp.ne'] lemma rpowIntegrand₀₁_nonneg (hp : 0 < p) (ht : 0 ≀ t) (hx : 0 ≀ x) : 0 ≀ rpowIntegrand₀₁ p t x := by unfold rpowIntegrand₀₁ cases eq_or_lt_of_le' ht with | inl ht_zero => simp [ht_zero, Real.zero_rpow (ne_of_gt hp)] | inr ht_pos => refine mul_nonneg (by positivity) ?_ rw [sub_nonneg] gcongr linarith lemma rpowIntegrand₀₁_eq_pow_div (hp : p ∈ Ioo 0 1) (ht : 0 ≀ t) (hx : 0 ≀ x) : rpowIntegrand₀₁ p t x = t ^ (p - 1) * x / (t + x) := by by_cases ht' : t = 0 case neg => have hxt : t + x β‰  0 := by positivity calc _ = (t : ℝ) ^ p * (t⁻¹ - (t + x)⁻¹) := rfl _ = (t : ℝ) ^ p * ((t + x - t) / (t * (t + x))) := by simp only [inv_eq_one_div] rw [div_sub_div _ _ (by cutsat) (by cutsat)] simp _ = t ^ p / t * x / (t + x) := by simp [field] _ = t ^ (p - 1) * x / (t + x) := by congr; exact (Real.rpow_sub_one ht' p).symm case pos => simp only [mem_Ioo] at hp have hpβ‚‚ : p - 1 β‰  0 := by linarith simp [rpowIntegrand₀₁, ht', hp.1.ne', hpβ‚‚] lemma rpowIntegrand₀₁_eqOn_pow_div (hp : p ∈ Ioo 0 1) (hx : 0 ≀ x) : Set.EqOn (rpowIntegrand₀₁ p Β· x) (fun t => t ^ (p - 1) * x / (t + x)) (Ioi 0) := by intro t ht simp [rpowIntegrand₀₁_eq_pow_div hp (le_of_lt ht) hx] lemma rpowIntegrand₀₁_apply_mul (hp : p ∈ Ioo 0 1) (ht : 0 ≀ t) (hx : 0 ≀ x) : rpowIntegrand₀₁ p (x * t) x = (rpowIntegrand₀₁ p t 1) * x ^ (p - 1) := by have hxt : 0 ≀ x * t := by positivity rw [rpowIntegrand₀₁_eq_pow_div hp hxt hx, rpowIntegrand₀₁_eq_pow_div hp ht zero_le_one] by_cases hx_zero : x = 0 case neg => calc _ = x ^ (p - 1) * (t ^ (p - 1) * (x / (x * t + x))) := by rw [← mul_assoc, mul_div_assoc, Real.mul_rpow hx ht] _ = x ^ (p - 1) * (t ^ (p - 1) * 1 / (t + 1)) := by have : x * t + x = x * (t + 1) := by ring rw [mul_div_assoc, this, div_mul_eq_div_mul_one_div, div_self hx_zero, one_mul] _ = t ^ (p - 1) * 1 / (t + 1) * x ^ (p - 1) := by rw [mul_comm] case pos => rw [mem_Ioo] at hp simp [hx_zero, Real.zero_rpow (by linarith : p - 1 β‰  0)] lemma rpowIntegrand₀₁_apply_mul' (hp : p ∈ Ioo 0 1) (ht : 0 ≀ t) (hx : 0 ≀ x) : rpowIntegrand₀₁ p (x * t) x * x = (rpowIntegrand₀₁ p t 1) * x ^ p := by simp only [rpowIntegrand₀₁_apply_mul hp ht hx, mul_assoc] congr simpa using Eq.symm <| Real.rpow_add' hx (by aesop : (p - 1) + 1 β‰  0) lemma rpowIntegrand₀₁_apply_mul_eqOn_Ici (hp : p ∈ Ioo 0 1) (hx : 0 ≀ x) : (Ici 0).EqOn (fun t => rpowIntegrand₀₁ p (x * t) x * x) (fun t => (rpowIntegrand₀₁ p t 1) * x ^ p) := fun _ ht => rpowIntegrand₀₁_apply_mul' hp ht hx lemma continuousOn_rpowIntegrand₀₁ (hp : p ∈ Ioo 0 1) (hx : 0 ≀ x) : ContinuousOn (rpowIntegrand₀₁ p Β· x) (Ioi 0) := by refine ContinuousOn.congr ?_ <| rpowIntegrand₀₁_eqOn_pow_div hp hx have hβ‚€ : ContinuousOn (Β· ^ (p - 1) : ℝ β†’ ℝ) (Ioi 0) := .rpow_const (by fun_prop) <| fun t ht => .inl ht.ne' fun_prop (disch := intros; simp_all; positivity) lemma aestronglyMeasurable_rpowIntegrand₀₁ (hp : p ∈ Ioo 0 1) (hx : 0 ≀ x) : AEStronglyMeasurable (rpowIntegrand₀₁ p Β· x) (volume.restrict (Ioi 0)) := (continuousOn_rpowIntegrand₀₁ hp hx).aestronglyMeasurable measurableSet_Ioi lemma rpowIntegrand₀₁_monotoneOn (hp : p ∈ Ioo 0 1) (ht : 0 ≀ t) : MonotoneOn (rpowIntegrand₀₁ p t) (Ici 0) := by intro x hx y hy hxy by_cases h : x = 0 case pos => simpa [h, rpowIntegrand₀₁] using rpowIntegrand₀₁_nonneg hp.1 ht hy case neg => simp only [rpowIntegrand₀₁, mem_Ici] at hx h ⊒ gcongr lemma continuousOn_rpowIntegrand₀₁_uncurry (hp : p ∈ Ioo 0 1) (s : Set ℝ) (hs : s βŠ† Ici 0) : ContinuousOn (rpowIntegrand₀₁ p).uncurry (Ioi 0 Γ—Λ’ s) := by let g : ℝ Γ— ℝ β†’ ℝ := fun q => q.1 ^ (p - 1) * q.2 / (q.1 + q.2) refine ContinuousOn.congr (f := g) ?_ fun q => ?_ Β· simp only [g] refine ContinuousOn.mul ?_ ?_ Β· refine ContinuousOn.mul ?_ (by fun_prop) exact ContinuousOn.rpow_const (by fun_prop) (by grind) Β· exact ContinuousOn.invβ‚€ (by fun_prop) (by grind) Β· intro hq simp [Function.uncurry, g, rpowIntegrand₀₁_eq_pow_div hp (le_of_lt hq.1) (hs hq.2)] lemma continuousOn_rpowIntegrand₀₁_Ici (hp : p ∈ Ioo 0 1) (ht : 0 < t) : ContinuousOn (rpowIntegrand₀₁ p t) (Ici 0) := (continuousOn_rpowIntegrand₀₁_uncurry hp _ fun _ a => a).uncurry_left _ ht lemma rpowIntegrand₀₁_le_rpow_sub_two_mul_self (hp : p ∈ Ioo 0 1) (ht : 0 < t) (hx : 0 ≀ x) : rpowIntegrand₀₁ p t x ≀ t ^ (p - 2) * x := calc _ = t ^ (p - 1) * x / (t + x) := by rw [rpowIntegrand₀₁_eq_pow_div hp (le_of_lt ht) hx] _ ≀ t ^ (p - 1) * x / t := by gcongr; linarith _ = t ^ (p - 1) / t * x := by ring _ = t ^ (p - 2) * x := by congr rw [← Real.rpow_sub_one (by positivity)] congr 1 ring lemma rpowIntegrand₀₁_le_rpow_sub_one (hp : p ∈ Ioo 0 1) (ht : 0 ≀ t) (hx : 0 ≀ x) : rpowIntegrand₀₁ p t x ≀ t ^ (p - 1) := by by_cases hx_zero : x = 0 case pos => simp only [rpowIntegrand₀₁, hx_zero, add_zero, sub_self, mul_zero] positivity case neg => calc _ = t ^ (p - 1) * x / (t + x) := by rw [rpowIntegrand₀₁_eq_pow_div hp ht hx] _ ≀ t ^ (p - 1) * x / x := by gcongr; linarith _ = t ^ (p - 1) * (x / x) := by ring _ = t ^ (p - 1) * 1 := by congr; exact (div_eq_one_iff_eq hx_zero).mpr rfl _ = _ := by simp lemma rpowIntegrand₀₁_one_ge_rpow_sub_two (hp : p ∈ Ioo 0 1) (ht : 1 ≀ t) : (1 : ℝ) / 2 * t ^ (p - 2) ≀ rpowIntegrand₀₁ p t 1 := calc _ = t ^ (p - 1) * (1 / 2 * 1 / t) := by have : p - 2 = p - 1 - 1 := by ring rw [this, Real.rpow_sub (by linarith), Real.rpow_one] ring _ ≀ t ^ (p - 1) * (1 / (t + 1)) := by gcongr t ^ (p - 1) * ?_ rw [mul_div_assoc, one_div_mul_one_div, one_div_le_one_div (by positivity) (by positivity)] linarith _ = rpowIntegrand₀₁ p t 1 := by rw [rpowIntegrand₀₁_eq_pow_div hp (by linarith) zero_le_one, mul_div_assoc] lemma rpowIntegrand₀₁_eqOn_mul_rpowIntegrand₀₁_one (ht : 0 < t) : (Ici 0).EqOn (rpowIntegrand₀₁ p t) (fun x => t ^ (p - 1) * (rpowIntegrand₀₁ p 1 (t⁻¹ β€’ x))) := by intro x hx calc _ = t ^ p * (t⁻¹ - t⁻¹ * (1 + x * t⁻¹)⁻¹) := by simp [field, rpowIntegrand₀₁] _ = t ^ (p - 1) * (1 - (1 + x * t⁻¹)⁻¹) := by rw [Real.rpow_sub_one ht.ne'] ring _ = _ := by simp [mul_comm, smul_eq_mul, rpowIntegrand₀₁] /- This lemma is private because it is strictly weaker than `integrableOn_rpowIntegrand₀₁_Ioi` -/ private lemma integrableOn_rpowIntegrand₀₁_Ioc (hp : p ∈ Ioo 0 1) (hx : 0 ≀ x) : IntegrableOn (rpowIntegrand₀₁ p Β· x) (Ioc 0 1) := by refine IntegrableOn.congr_set_ae (t := Ioo 0 1) ?_ (Filter.EventuallyEq.symm Ioo_ae_eq_Ioc) refine ⟨?meas, ?finite⟩ case meas => refine ContinuousOn.aestronglyMeasurable ?_ measurableSet_Ioo exact ContinuousOn.mono (continuousOn_rpowIntegrand₀₁ hp hx) Ioo_subset_Ioi_self case finite => refine HasFiniteIntegral.mono' (g := fun t => t ^ (p - 1)) ?finitebound ?ae_le case finitebound => apply Integrable.hasFiniteIntegral rw [Set.mem_Ioo] at hp rw [← IntegrableOn, intervalIntegral.integrableOn_Ioo_rpow_iff] Β· linarith Β· exact zero_lt_one case ae_le => refine ae_restrict_of_forall_mem measurableSet_Ioo fun t ht => ?_ rw [Real.norm_of_nonneg (rpowIntegrand₀₁_nonneg hp.1 (le_of_lt ht.1) hx)] exact rpowIntegrand₀₁_le_rpow_sub_one hp (le_of_lt ht.1) hx /- This lemma is private because it is strictly weaker than `integrableOn_rpowIntegrand₀₁_Ioi` -/ private lemma integrableOn_rpowIntegrand₀₁_Ioi_one (hp : p ∈ Ioo 0 1) (hx : 0 ≀ x) : IntegrableOn (rpowIntegrand₀₁ p Β· x) (Ioi 1) := by refine ⟨?meas, ?finite⟩ case meas => refine ContinuousOn.aestronglyMeasurable ?_ measurableSet_Ioi exact continuousOn_rpowIntegrand₀₁ hp hx |>.mono (Set.Ioi_subset_Ioi zero_le_one) case finite => refine HasFiniteIntegral.mono' (g := fun t => t ^ (p - 2) * x) ?finitebound ?ae_le case finitebound => refine HasFiniteIntegral.mul_const ?_ _ apply Integrable.hasFiniteIntegral rw [Set.mem_Ioo] at hp refine integrableOn_Ioi_rpow_of_lt ?_ zero_lt_one linarith case ae_le => refine ae_restrict_of_forall_mem measurableSet_Ioi fun t (ht : 1 < t) => ?_ rw [Real.norm_of_nonneg (rpowIntegrand₀₁_nonneg hp.1 (by positivity) hx)] exact rpowIntegrand₀₁_le_rpow_sub_two_mul_self hp (by positivity) hx lemma integrableOn_rpowIntegrand₀₁_Ioi (hp : p ∈ Ioo 0 1) (hx : 0 ≀ x) : IntegrableOn (rpowIntegrand₀₁ p Β· x) (Ioi 0) := by /- The integral converges because it is `O(t ^ (p-1))` at the origin and `O(t ^ (p-2))` at infinity. Hence we break the integral into two parts. -/ rw [← Set.Ioc_union_Ioi_eq_Ioi zero_le_one] exact IntegrableOn.union (integrableOn_rpowIntegrand₀₁_Ioc hp hx) (integrableOn_rpowIntegrand₀₁_Ioi_one hp hx) lemma integrableOn_rpowIntegrand₀₁_Ici (hp : p ∈ Ioo 0 1) (hx : 0 ≀ x) : IntegrableOn (rpowIntegrand₀₁ p Β· x) (Ici 0) := integrableOn_rpowIntegrand₀₁_Ioi hp hx |>.congr_set_ae Ioi_ae_eq_Ici.symm lemma integral_rpowIntegrand₀₁_eq_rpow_mul_const (hp : p ∈ Ioo 0 1) (hx : 0 ≀ x) : (∫ t in Ioi 0, rpowIntegrand₀₁ p t x) = x ^ p * (∫ t in Ioi 0, rpowIntegrand₀₁ p t 1) := by -- We use the change of variables formula with `f t = x * t`. Here `g = rpowIntegrand₀₁ p Β· x`. obtain (rfl | hx) := hx.eq_or_lt Β· simp [rpowIntegrand₀₁, Real.zero_rpow hp.1.ne'] suffices ∫ t in Ioi 0, ((rpowIntegrand₀₁ p Β· x) ∘ (x * Β·)) t * x = x ^ p * (∫ t in Ioi 0, rpowIntegrand₀₁ p t 1) by rwa [integral_comp_mul_deriv_Ioi (by fun_prop), mul_zero] at this Β· exact tendsto_id.const_mul_atTop hx Β· simpa using fun t _ ↦ hasDerivWithinAt_id t (Ioi t) |>.const_mul x Β· simpa [Set.image_mul_left_Ioi hx] using continuousOn_rpowIntegrand₀₁ hp hx.le Β· simpa [Set.image_mul_left_Ici hx] using integrableOn_rpowIntegrand₀₁_Ici hp hx.le Β· simp only [Function.comp] rw [integrableOn_congr_fun (rpowIntegrand₀₁_apply_mul_eqOn_Ici hp hx.le) measurableSet_Ici] exact Integrable.mul_const (integrableOn_rpowIntegrand₀₁_Ici hp zero_le_one) _ have heqOn : EqOn (fun t => rpowIntegrand₀₁ p (x * t) x * x) (fun t => (rpowIntegrand₀₁ p t 1) * x ^ p) (Ioi 0) := EqOn.mono Ioi_subset_Ici_self (rpowIntegrand₀₁_apply_mul_eqOn_Ici hp hx.le) simp only [Function.comp, setIntegral_congr_fun measurableSet_Ioi heqOn, ← smul_eq_mul (b := x ^ p), integral_smul_const] rw [smul_eq_mul, mul_comm] lemma le_integral_rpowIntegrand₀₁_one (hp : p ∈ Ioo 0 1) : -1 / (2 * (p - 1)) ≀ ∫ t in Ioi 0, rpowIntegrand₀₁ p t 1 := calc _ = (1 / 2) * -((1 : ℝ) ^ (p - 1)) / (p - 1) := by rw [← div_div]; simp [neg_div] _ = ∫ t in Ioi 1, (1 / 2) * t ^ (p - 2) := by simp only [mem_Ioo] at hp rw [integral_const_mul, integral_Ioi_rpow_of_lt (by linarith) zero_lt_one] ring_nf -- ring alone succeeds but gives a warning _ ≀ ∫ t in Ioi 1, rpowIntegrand₀₁ p t 1 := by refine setIntegral_mono_on ?_ ?_ measurableSet_Ioi ?_ Β· refine Integrable.const_mul ?_ _ simp only [mem_Ioo] at hp exact integrableOn_Ioi_rpow_of_lt (by linarith) zero_lt_one Β· exact integrableOn_rpowIntegrand₀₁_Ioi_one hp zero_le_one Β· exact fun t ht => rpowIntegrand₀₁_one_ge_rpow_sub_two hp (le_of_lt ht) _ ≀ ∫ t in Ioi 0, rpowIntegrand₀₁ p t 1 := by refine setIntegral_mono_set (integrableOn_rpowIntegrand₀₁_Ioi hp zero_le_one) ?_ ?_ Β· refine ae_restrict_of_forall_mem measurableSet_Ioi fun t ht => ?_ exact rpowIntegrand₀₁_nonneg hp.1 (le_of_lt ht) zero_le_one Β· exact .of_forall <| Set.Ioi_subset_Ioi zero_le_one lemma integral_rpowIntegrand₀₁_one_pos (hp : p ∈ Ioo 0 1) : 0 < ∫ t in Ioi 0, rpowIntegrand₀₁ p t 1 := calc 0 < -1 / (2 * (p - 1)) := by rw [neg_div, neg_pos, one_div_neg] simp only [mem_Ioo] at hp linarith _ ≀ ∫ t in Ioi 0, rpowIntegrand₀₁ p t 1 := le_integral_rpowIntegrand₀₁_one hp /-- The integral representation of the function `x ↦ x^p` (where `p ∈ (0, 1)`) . -/ lemma rpow_eq_const_mul_integral (hp : p ∈ Ioo 0 1) (hx : 0 ≀ x) : x ^ p = (∫ t in Ioi 0, rpowIntegrand₀₁ p t 1)⁻¹ * ∫ t in Ioi 0, rpowIntegrand₀₁ p t x := by rcases eq_or_lt_of_le' hx with hx_zero|_ case inl => simp only [mem_Ioo] at hp simp [hx_zero, Real.zero_rpow (by linarith)] case inr => have : ∫ t in Ioi 0, rpowIntegrand₀₁ p t 1 β‰  0 := ne_of_gt <| integral_rpowIntegrand₀₁_one_pos hp rw [integral_rpowIntegrand₀₁_eq_rpow_mul_const hp hx, mul_comm, mul_assoc, mul_inv_cancelβ‚€ this, mul_one] /-- The integral representation of the function `x ↦ x ^ p` (where `p ∈ (0, 1)`) . -/ lemma exists_measure_rpow_eq_integral (hp : p ∈ Ioo 0 1) : βˆƒ ΞΌ : Measure ℝ, βˆ€ x ∈ Ici 0, (IntegrableOn (fun t => rpowIntegrand₀₁ p t x) (Ioi 0) ΞΌ) ∧ x ^ p = ∫ t in Ioi 0, rpowIntegrand₀₁ p t x βˆ‚ΞΌ := by let C : ℝβ‰₯0 := { val := (∫ t in Ioi 0, rpowIntegrand₀₁ p t 1)⁻¹ property := by rw [inv_nonneg] exact le_of_lt <| integral_rpowIntegrand₀₁_one_pos hp } refine ⟨C β€’ volume, fun x hx => ⟨?_, ?_⟩⟩ Β· unfold IntegrableOn rw [Measure.restrict_smul] exact Integrable.smul_measure_nnreal <| integrableOn_rpowIntegrand₀₁_Ioi hp hx Β· simp_rw [Measure.restrict_smul, integral_smul_nnreal_measure, rpow_eq_const_mul_integral hp hx, NNReal.smul_def, C, NNReal.coe_mk, smul_eq_mul] end Real namespace CFC open Real section NonUnitalCFC variable {A : Type*} [NonUnitalNormedRing A] [StarRing A] [NormedSpace ℝ A] [SMulCommClass ℝ A A] [IsScalarTower ℝ A A] [PartialOrder A] [StarOrderedRing A] [NonnegSpectrumClass ℝ A] [NonUnitalContinuousFunctionalCalculus ℝ A IsSelfAdjoint] lemma cfcβ‚™_rpowIntegrand₀₁_eq_cfcβ‚™_rpowIntegrand₀₁_one {p t : ℝ} (hp : p ∈ Ioo 0 1) (ht : 0 < t) (a : A) (ha : 0 ≀ a) : cfcβ‚™ (rpowIntegrand₀₁ p t) a = t ^ (p - 1) β€’ cfcβ‚™ (rpowIntegrand₀₁ p 1) (t⁻¹ β€’ a) := by have hspec : quasispectrum ℝ a βŠ† Ici 0 := by intro; grind have h_mapsTo : MapsTo (t⁻¹ β€’ Β· : ℝ β†’ ℝ) (Ici 0) (Ici 0) := by intro x hx simp only [mem_Ici, smul_eq_mul] at hx ⊒ positivity calc _ = cfcβ‚™ (fun x => t ^ ((p : ℝ) - 1) * (rpowIntegrand₀₁ p 1 (t⁻¹ β€’ x))) a := by refine cfcβ‚™_congr ?_ refine Set.EqOn.mono hspec (rpowIntegrand₀₁_eqOn_mul_rpowIntegrand₀₁_one ht) _ = t ^ ((p : ℝ) - 1) β€’ cfcβ‚™ (fun x => rpowIntegrand₀₁ p 1 (t⁻¹ β€’ x)) a := by refine cfcβ‚™_smul (R := ℝ) (t ^ ((p : ℝ) - 1)) _ a ?_ refine ContinuousOn.mono ?_ hspec have := continuousOn_rpowIntegrand₀₁_Ici hp zero_lt_one fun_prop (disch := assumption) _ = t ^ ((p : ℝ) - 1) β€’ cfcβ‚™ (rpowIntegrand₀₁ p 1) (t⁻¹ β€’ a) := by congr! 1 refine cfcβ‚™_comp_smul (R := ℝ) t⁻¹ (fun x => rpowIntegrand₀₁ p 1 x) a ?_ exact continuousOn_rpowIntegrand₀₁_Ici hp zero_lt_one |>.mono <| (h_mapsTo.mono_left hspec).image_subset variable (A) in /-- The integral representation of the function `x ↦ x ^ p` (where `p ∈ (0, 1)`). -/ lemma exists_measure_nnrpow_eq_integral_cfcβ‚™_rpowIntegrand₀₁ [CompleteSpace A] {p : ℝβ‰₯0} (hp : p ∈ Ioo 0 1) : βˆƒ ΞΌ : Measure ℝ, βˆ€ a ∈ Ici (0 : A), (IntegrableOn (fun t => cfcβ‚™ (rpowIntegrand₀₁ p t) a) (Ioi 0) ΞΌ) ∧ a ^ p = ∫ t in Ioi 0, cfcβ‚™ (rpowIntegrand₀₁ p t) a βˆ‚ΞΌ := by obtain ⟨μ, hμ⟩ := exists_measure_rpow_eq_integral hp refine ⟨μ, fun a (ha : 0 ≀ a) => ?_⟩ nontriviality A have p_pos : 0 < (p : ℝ) := by exact_mod_cast hp.1 let f t := rpowIntegrand₀₁ p t let maxr := sSup (quasispectrum ℝ a) have maxr_nonneg : 0 ≀ maxr := le_csSup_of_le (b := 0) (IsCompact.bddAbove (by grind)) (by simp) (by simp) let bound (t : ℝ) := β€–f t maxrβ€– have hf : ContinuousOn (Function.uncurry f) (Ioi (0 : ℝ) Γ—Λ’ quasispectrum ℝ a) := by refine continuousOn_rpowIntegrand₀₁_uncurry hp (quasispectrum ℝ a) ?_ grind have hbound : βˆ€α΅ t βˆ‚ΞΌ.restrict (Ioi 0), βˆ€ z ∈ quasispectrum ℝ a, β€–f t zβ€– ≀ bound t := by filter_upwards [ae_restrict_mem measurableSet_Ioi] with t ht intro z hz have hz' : 0 ≀ z := by grind unfold bound f rw [Real.norm_of_nonneg (rpowIntegrand₀₁_nonneg p_pos (le_of_lt ht) hz'), Real.norm_of_nonneg (rpowIntegrand₀₁_nonneg p_pos (le_of_lt ht) maxr_nonneg)] refine rpowIntegrand₀₁_monotoneOn hp (le_of_lt ht) hz' maxr_nonneg ?_ exact le_csSup (IsCompact.bddAbove (quasispectrum.isCompact _)) hz have hbound_finite_integral : HasFiniteIntegral bound (ΞΌ.restrict (Ioi 0)) := by rw [hasFiniteIntegral_norm_iff] exact (hΞΌ maxr maxr_nonneg).1.2 have hmapzero : βˆ€α΅ (x : ℝ) βˆ‚ΞΌ.restrict (Ioi 0), rpowIntegrand₀₁ p x 0 = 0 := by filter_upwards [ae_restrict_mem measurableSet_Ioi] simp refine ⟨?integrable, ?integral⟩ case integrable => exact integrableOn_cfcβ‚™ measurableSet_Ioi _ bound a hf hmapzero hbound hbound_finite_integral case integral => calc a ^ p = cfcβ‚™ (fun r => ∫ t in Ioi 0, rpowIntegrand₀₁ p t r βˆ‚ΞΌ) a := by rw [nnrpow_eq_cfcβ‚™_real _ _] exact cfcβ‚™_congr fun r _ ↦ (hΞΌ r (by grind)).2 _ = _ := cfcβ‚™_setIntegral measurableSet_Ioi _ bound a hf hmapzero hbound hbound_finite_integral ha.isSelfAdjoint end NonUnitalCFC section NonUnitalCStarAlgebra variable {A : Type*} [NonUnitalCStarAlgebra A] [PartialOrder A] [StarOrderedRing A] /-- `rpowIntegrand₀₁ p t` is operator monotone for all `p ∈ Ioo 0 1` and all `t ∈ Ioi 0`. -/ lemma monotoneOn_cfcβ‚™_rpowIntegrand₀₁ {p : ℝ} {t : ℝ} (hp : p ∈ Ioo 0 1) (ht : 0 < t) : MonotoneOn (cfcβ‚™ (rpowIntegrand₀₁ p t)) (Ici (0 : A)) := by intro a (ha : 0 ≀ a) b (hb : 0 ≀ b) hab calc _ = t ^ ((p : ℝ) - 1) β€’ cfcβ‚™ (rpowIntegrand₀₁ p 1) (t⁻¹ β€’ a) := by rw [cfcβ‚™_rpowIntegrand₀₁_eq_cfcβ‚™_rpowIntegrand₀₁_one hp ht a ha] _ ≀ t ^ ((p : ℝ) - 1) β€’ cfcβ‚™ (rpowIntegrand₀₁ p 1) (t⁻¹ β€’ b) := by gcongr unfold rpowIntegrand₀₁ simp only [Real.one_rpow, one_mul, inv_one] refine CFC.monotoneOn_one_sub_one_add_inv_real (?_ : 0 ≀ t⁻¹ β€’ a) (?_ : 0 ≀ t⁻¹ β€’ b) (by gcongr) all_goals positivity _ = cfcβ‚™ (rpowIntegrand₀₁ p t) b := by rw [cfcβ‚™_rpowIntegrand₀₁_eq_cfcβ‚™_rpowIntegrand₀₁_one hp ht b hb] /-- This is an intermediate result; use the more general `CFC.monotone_nnrpow` instead. -/ private lemma monotoneOn_nnrpow_Ioo {p : ℝβ‰₯0} (hp : p ∈ Ioo 0 1) : MonotoneOn (fun a : A => a ^ p) (Ici 0) := by obtain ⟨μ, hμ⟩ := exists_measure_nnrpow_eq_integral_cfcβ‚™_rpowIntegrand₀₁ A hp have h₃' : (Ici 0).EqOn (fun a : A => a ^ p) (fun a : A => ∫ t in Ioi 0, cfcβ‚™ (rpowIntegrand₀₁ p t) a βˆ‚ΞΌ) := fun a ha => (hΞΌ a ha).2 refine MonotoneOn.congr ?_ h₃'.symm refine integral_monotoneOn_of_integrand_ae ?_ fun a ha => (hΞΌ a ha).1 filter_upwards [ae_restrict_mem measurableSet_Ioi] with t ht exact monotoneOn_cfcβ‚™_rpowIntegrand₀₁ hp ht /-- `a ↦ a ^ p` is operator monotone for `p ∈ [0,1]`. -/ lemma monotone_nnrpow {p : ℝβ‰₯0} (hp : p ∈ Icc 0 1) : Monotone (fun a : A => a ^ p) := by intro a b hab by_cases ha : 0 ≀ a Β· have hb : 0 ≀ b := ha.trans hab have hIcc : Icc (0 : ℝβ‰₯0) 1 = Ioo 0 1 βˆͺ {0} βˆͺ {1} := by ext; simp rw [hIcc] at hp obtain (hp|hp)|hp := hp Β· exact monotoneOn_nnrpow_Ioo hp ha hb hab Β· simp_all [mem_singleton_iff] Β· simp_all [mem_singleton_iff, nnrpow_one a, nnrpow_one b] Β· have : a ^ p = 0 := cfcβ‚™_apply_of_not_predicate a ha simp [this] /-- `CFC.sqrt` is operator monotone. -/ lemma monotone_sqrt : Monotone (sqrt : A β†’ A) := by intro a b hab rw [CFC.sqrt_eq_nnrpow a, CFC.sqrt_eq_nnrpow b] refine (monotone_nnrpow (A := A) ?_) hab constructor <;> norm_num @[gcongr] lemma nnrpow_le_nnrpow {p : ℝβ‰₯0} (hp : p ∈ Icc 0 1) {a b : A} (hab : a ≀ b) : a ^ p ≀ b ^ p := monotone_nnrpow hp hab @[gcongr] lemma sqrt_le_sqrt (a b : A) (hab : a ≀ b) : sqrt a ≀ sqrt b := monotone_sqrt hab end NonUnitalCStarAlgebra section UnitalCStarAlgebra variable {A : Type*} [CStarAlgebra A] [PartialOrder A] [StarOrderedRing A] /-- `a ↦ a ^ p` is operator monotone for `p ∈ [0,1]`. -/ lemma monotone_rpow {p : ℝ} (hp : p ∈ Icc 0 1) : Monotone (fun a : A => a ^ p) := by let q : ℝβ‰₯0 := ⟨p, hp.1⟩ change Monotone (fun a : A => a ^ (q : ℝ)) cases (zero_le q).lt_or_eq' with | inl hq => simp_rw [← CFC.nnrpow_eq_rpow hq] exact monotone_nnrpow hp | inr hq => simp only [hq, NNReal.coe_zero] intro a b hab by_cases ha : 0 ≀ a Β· have hb : 0 ≀ b := ha.trans hab simp [CFC.rpow_zero a, CFC.rpow_zero b] Β· have : a ^ (0 : ℝ) = 0 := cfc_apply_of_not_predicate a ha simp [this] @[gcongr] lemma rpow_le_rpow {p : ℝ} (hp : p ∈ Icc 0 1) {a b : A} (hab : a ≀ b) : a ^ p ≀ b ^ p := monotone_rpow hp hab end UnitalCStarAlgebra end CFC
.lake/packages/mathlib/Mathlib/Analysis/SpecialFunctions/Log/Summable.lean
import Mathlib.Analysis.SpecialFunctions.Complex.LogBounds import Mathlib.Topology.Algebra.InfiniteSum.Field /-! # Summability of logarithms We give conditions under which the logarithms of a summble sequence is summable. We also use this to relate summability of `f` to multipliability of `1 + f`. -/ variable {ΞΉ : Type*} open Filter Topology NNReal SummationFilter namespace Complex variable {f : ΞΉ β†’ β„‚} {a : β„‚} lemma hasProd_of_hasSum_log (hfn : βˆ€ i, f i β‰  0) (hf : HasSum (fun i ↦ log (f i)) a) : HasProd f (exp a) := hf.cexp.congr (by simp [exp_log, hfn]) lemma multipliable_of_summable_log (hf : Summable fun i ↦ log (f i)) : Multipliable f := by by_cases! hfn : βˆƒ n, f n = 0 Β· exact multipliable_of_exists_eq_zero hfn Β· exact ⟨_, hasProd_of_hasSum_log hfn hf.hasSum⟩ /-- The exponential of a convergent sum of complex logs is the corresponding infinite product. -/ lemma cexp_tsum_eq_tprod (hfn : βˆ€ i, f i β‰  0) (hf : Summable fun i ↦ log (f i)) : cexp (βˆ‘' i, log (f i)) = ∏' i, f i := (hasProd_of_hasSum_log hfn hf.hasSum).tprod_eq.symm lemma summable_log_one_add_of_summable {f : ΞΉ β†’ β„‚} (hf : Summable f) : Summable (fun i ↦ log (1 + f i)) := by apply (hf.norm.mul_left (3 / 2)).of_norm_bounded_eventually filter_upwards [hf.norm.tendsto_cofinite_zero.eventually_le_const one_half_pos] with i hi using norm_log_one_add_half_le_self hi protected lemma multipliable_one_add_of_summable (hf : Summable f) : Multipliable (fun i ↦ 1 + f i) := multipliable_of_summable_log (summable_log_one_add_of_summable hf) end Complex namespace Real variable {f : ΞΉ β†’ ℝ} {a : ℝ} lemma hasProd_of_hasSum_log (hfn : βˆ€ i, 0 < f i) (hf : HasSum (fun i ↦ log (f i)) a) : HasProd f (rexp a) := hf.rexp.congr (by simp [exp_log, hfn]) lemma multipliable_of_summable_log (hfn : βˆ€ i, 0 < f i) (hf : Summable fun i ↦ log (f i)) : Multipliable f := ⟨_, hasProd_of_hasSum_log hfn hf.hasSum⟩ /-- Alternate version of `Real.multipliable_of_summable_log` assuming only that positivity holds eventually. -/ lemma multipliable_of_summable_log' (hfn : βˆ€αΆ  i in cofinite, 0 < f i) (hf : Summable fun i ↦ log (f i)) : Multipliable f := by have : Summable fun i ↦ log (if 0 < f i then f i else 1) := by apply hf.congr_cofinite filter_upwards [hfn] with i hi using by simp [hi] have : Multipliable fun i ↦ if 0 < f i then f i else 1 := by refine multipliable_of_summable_log (fun i ↦ ?_) this split_ifs with h <;> simp [h] refine this.congr_cofiniteβ‚€ (fun i ↦ ?_) ?_ Β· split_ifs with h <;> simp [h, ne_of_gt] Β· filter_upwards [hfn] with i hi using by simp [hi] /-- The exponential of a convergent sum of real logs is the corresponding infinite product. -/ lemma rexp_tsum_eq_tprod (hfn : βˆ€ i, 0 < f i) (hf : Summable fun i ↦ log (f i)) : rexp (βˆ‘' i, log (f i)) = ∏' i, f i := (hasProd_of_hasSum_log hfn hf.hasSum).tprod_eq.symm open Complex in lemma summable_log_one_add_of_summable (hf : Summable f) : Summable (fun i ↦ log (1 + f i)) := by rw [← summable_ofReal] apply (Complex.summable_log_one_add_of_summable (summable_ofReal.mpr hf)).congr_cofinite filter_upwards [hf.tendsto_cofinite_zero.eventually_const_le neg_one_lt_zero] with i hi rw [ofReal_log, ofReal_add, ofReal_one] linarith protected lemma multipliable_one_add_of_summable (hf : Summable f) : Multipliable (fun i ↦ 1 + f i) := by refine multipliable_of_summable_log' ?_ (summable_log_one_add_of_summable hf) filter_upwards [hf.tendsto_cofinite_zero.eventually_const_lt neg_one_lt_zero] with i hi linarith end Real section NormedRing lemma Multipliable.eventually_bounded_finset_prod {v : ΞΉ β†’ ℝ} (hv : Multipliable v) : βˆƒ r₁ > 0, βˆƒ s₁, βˆ€ t, s₁ βŠ† t β†’ ∏ i ∈ t, v i ≀ r₁ := by obtain ⟨r₁, hrβ‚βŸ© := exists_gt (max 0 <| ∏' i, v i) rw [max_lt_iff] at hr₁ have := hv.hasProd.eventually_le_const hr₁.2 rw [unconditional, eventually_atTop] at this exact ⟨r₁, hr₁.1, this⟩ variable {R : Type*} [NormedCommRing R] [NormOneClass R] {f : ΞΉ β†’ R} lemma multipliable_norm_one_add_of_summable_norm (hf : Summable fun i ↦ β€–f iβ€–) : Multipliable fun i ↦ β€–1 + f iβ€– := by conv => enter [1, i]; rw [← sub_add_cancel β€–1 + f iβ€– 1, add_comm] refine Real.multipliable_one_add_of_summable <| hf.of_norm_bounded (fun i ↦ ?_) simpa using abs_norm_sub_norm_le (1 + f i) 1 lemma Finset.norm_prod_one_add_sub_one_le (t : Finset ΞΉ) (f : ΞΉ β†’ R) : β€–βˆ i ∈ t, (1 + f i) - 1β€– ≀ Real.exp (βˆ‘ i ∈ t, β€–f iβ€–) - 1 := by classical induction t using Finset.induction_on with | empty => simp | insert x t hx IH => rw [Finset.prod_insert hx, Finset.sum_insert hx, Real.exp_add, show (1 + f x) * ∏ i ∈ t, (1 + f i) - 1 = (∏ i ∈ t, (1 + f i) - 1) + f x * ∏ x ∈ t, (1 + f x) by ring] refine (norm_add_le_of_le IH (norm_mul_le _ _)).trans ?_ generalize h : Real.exp (βˆ‘ i ∈ t, β€–f iβ€–) = A at ⊒ IH rw [sub_add_eq_add_sub, sub_le_sub_iff_right] transitivity A + β€–f xβ€– * A Β· grw [norm_le_norm_sub_add (∏ x ∈ t, (1 + f x)) 1, IH, norm_one, sub_add_cancel] rw [← one_add_mul, add_comm] exact mul_le_mul_of_nonneg_right (Real.add_one_le_exp _) (h β–Έ Real.exp_nonneg _) lemma prod_vanishing_of_summable_norm (hf : Summable fun i ↦ β€–f iβ€–) {Ξ΅ : ℝ} (hΞ΅ : 0 < Ξ΅) : βˆƒ sβ‚‚, βˆ€ t, Disjoint t sβ‚‚ β†’ β€–βˆ i ∈ t, (1 + f i) - 1β€– < Ξ΅ := by suffices βˆƒ s, βˆ€ t, Disjoint t s β†’ Real.exp (βˆ‘ i ∈ t, β€–f iβ€–) - 1 < Ξ΅ from this.imp fun s hs t ht ↦ (t.norm_prod_one_add_sub_one_le _).trans_lt (hs t ht) suffices {x | Real.exp x - 1 < Ξ΅} ∈ 𝓝 0 from hf.vanishing this let f (x) := Real.exp x - 1 have : Set.Iio Ξ΅ ∈ nhds (f 0) := by simpa [f] using Iio_mem_nhds hΞ΅ exact ContinuousAt.preimage_mem_nhds (by fun_prop) this open Finset in /-- In a complete normed ring, `∏' i, (1 + f i)` is convergent if the sum of real numbers `βˆ‘' i, β€–f iβ€–` is convergent. -/ lemma multipliable_one_add_of_summable [CompleteSpace R] (hf : Summable fun i ↦ β€–f iβ€–) : Multipliable fun i ↦ (1 + f i) := by classical refine CompleteSpace.complete <| Metric.cauchy_iff.mpr ⟨by infer_instance, fun Ξ΅ hΞ΅ ↦ ?_⟩ obtain ⟨r₁, hr₁, s₁, hsβ‚βŸ© := (multipliable_norm_one_add_of_summable_norm hf).eventually_bounded_finset_prod obtain ⟨sβ‚‚, hsβ‚‚βŸ© := prod_vanishing_of_summable_norm hf (show 0 < Ξ΅ / (2 * r₁) by positivity) simp only [unconditional, Filter.mem_map, mem_atTop_sets, ge_iff_le, le_eq_subset, Set.mem_preimage] let s := s₁ βˆͺ sβ‚‚ -- The idea here is that if `s` is a large enough finset, then the product over `s` is bounded -- by some `r`, and the product over finsets disjoint from `s` is within `Ξ΅ / (2 * r)` of 1. -- From this it follows that the products over any two finsets containing `s` are within `Ξ΅` of -- each other. -- Here `s₁ βŠ† s` guarantees that the product over `s` is bounded, and `sβ‚‚ βŠ† s` guarantees that -- the product over terms not in `s` is small. refine ⟨Metric.ball (∏ i ∈ s, (1 + f i)) (Ξ΅ / 2), ⟨s, fun b hb ↦ ?_⟩, ?_⟩ Β· rw [← union_sdiff_of_subset hb, prod_union sdiff_disjoint.symm, Metric.mem_ball, dist_eq_norm_sub, ← mul_sub_one, show Ξ΅ / 2 = r₁ * (Ξ΅ / (2 * r₁)) by field] apply (norm_mul_le _ _).trans_lt refine lt_of_le_of_lt (b := r₁ * β€–βˆ x ∈ b \ s, (1 + f x) - 1β€–) ?_ ?_ Β· refine mul_le_mul_of_nonneg_right ?_ (norm_nonneg _) exact (Finset.norm_prod_le _ _).trans (hs₁ _ subset_union_left) Β· refine mul_lt_mul_of_pos_left (hsβ‚‚ _ ?_) hr₁ simp [s, sdiff_union_distrib, disjoint_iff_inter_eq_empty] Β· intro x hx y hy exact (dist_triangle_right _ _ (∏ i ∈ s, (1 + f i))).trans_lt (add_halves Ξ΅ β–Έ add_lt_add hx hy) lemma Summable.summable_log_norm_one_add (hu : Summable fun n ↦ β€–f nβ€–) : Summable fun i ↦ Real.log β€–1 + f iβ€– := by suffices Summable (β€–1 + f Β·β€– - 1) from (Real.summable_log_one_add_of_summable this).congr (by simp) refine .of_norm (hu.of_nonneg_of_le (fun i ↦ by positivity) fun i ↦ ?_) simp only [Real.norm_eq_abs, abs_le] constructor Β· simpa using norm_add_le (1 + f i) (-f i) Β· simpa [add_comm] using norm_add_le (f i) 1 lemma tprod_one_add_ne_zero_of_summable [CompleteSpace R] [NormMulClass R] (hf : βˆ€ i, 1 + f i β‰  0) (hu : Summable (β€–f Β·β€–)) : ∏' i : ΞΉ, (1 + f i) β‰  0 := by rw [← norm_ne_zero_iff, Multipliable.norm_tprod] Β· rw [← Real.rexp_tsum_eq_tprod (fun i ↦ norm_pos_iff.mpr <| hf i) hu.summable_log_norm_one_add] apply Real.exp_ne_zero Β· exact multipliable_one_add_of_summable hu end NormedRing
.lake/packages/mathlib/Mathlib/Analysis/SpecialFunctions/Log/ERealExp.lean
import Mathlib.Analysis.Complex.Exponential import Mathlib.Data.EReal.Basic /-! # Extended Nonnegative Real Exponential We define `exp` as an extension of the exponential of a real to the extended reals `EReal`. The function takes values in the extended nonnegative reals `ℝβ‰₯0∞`, with `exp βŠ₯ = 0` and `exp ⊀ = ⊀`. ## Main Definitions - `EReal.exp`: The extension of the real exponential to `EReal`. ## Main Results - `EReal.exp_strictMono`: `exp` is increasing; - `EReal.exp_neg`, `EReal.exp_add`: `exp` satisfies the identities `exp (-x) = (exp x)⁻¹` and `exp (x + y) = exp x * exp y`. ## Tags ENNReal, EReal, exponential -/ namespace EReal open scoped ENNReal /-! ### Definition -/ section Definition /-- Exponential as a function from `EReal` to `ℝβ‰₯0∞`. -/ noncomputable def exp : EReal β†’ ℝβ‰₯0∞ | βŠ₯ => 0 | ⊀ => ∞ | (x : ℝ) => ENNReal.ofReal (Real.exp x) @[simp] lemma exp_bot : exp βŠ₯ = 0 := rfl @[simp] lemma exp_zero : exp 0 = 1 := by simp [exp] @[simp] lemma exp_top : exp ⊀ = ∞ := rfl @[simp] lemma exp_coe (x : ℝ) : exp x = ENNReal.ofReal (Real.exp x) := rfl @[simp] lemma exp_eq_zero_iff {x : EReal} : exp x = 0 ↔ x = βŠ₯ := by induction x <;> simp [Real.exp_pos] @[simp] lemma exp_eq_top_iff {x : EReal} : exp x = ∞ ↔ x = ⊀ := by induction x <;> simp end Definition /-! ### Monotonicity -/ section Monotonicity @[gcongr] lemma exp_strictMono : StrictMono exp := by intro x y h induction x Β· rw [exp_bot, pos_iff_ne_zero, ne_eq, exp_eq_zero_iff] exact h.ne' Β· induction y Β· simp at h Β· simp_rw [exp_coe] exact ENNReal.ofReal_lt_ofReal_iff'.mpr ⟨Real.exp_strictMono (mod_cast h), Real.exp_pos _⟩ Β· simp Β· exact (not_top_lt h).elim @[gcongr] lemma exp_monotone : Monotone exp := exp_strictMono.monotone @[simp] lemma exp_lt_exp_iff {a b : EReal} : exp a < exp b ↔ a < b := exp_strictMono.lt_iff_lt @[simp] lemma zero_lt_exp_iff {a : EReal} : 0 < exp a ↔ βŠ₯ < a := exp_bot β–Έ @exp_lt_exp_iff βŠ₯ a @[simp] lemma exp_lt_top_iff {a : EReal} : exp a < ⊀ ↔ a < ⊀ := exp_top β–Έ @exp_lt_exp_iff a ⊀ @[simp] lemma exp_lt_one_iff {a : EReal} : exp a < 1 ↔ a < 0 := exp_zero β–Έ @exp_lt_exp_iff a 0 @[simp] lemma one_lt_exp_iff {a : EReal} : 1 < exp a ↔ 0 < a := exp_zero β–Έ @exp_lt_exp_iff 0 a @[simp] lemma exp_le_exp_iff {a b : EReal} : exp a ≀ exp b ↔ a ≀ b := exp_strictMono.le_iff_le @[simp] lemma exp_le_one_iff {a : EReal} : exp a ≀ 1 ↔ a ≀ 0 := exp_zero β–Έ @exp_le_exp_iff a 0 @[simp] lemma one_le_exp_iff {a : EReal} : 1 ≀ exp a ↔ 0 ≀ a := exp_zero β–Έ @exp_le_exp_iff 0 a @[deprecated exp_monotone (since := "2025-10-20")] lemma exp_le_exp {a b : EReal} (h : a ≀ b) : exp a ≀ exp b := by simpa @[deprecated exp_strictMono (since := "2025-10-20")] lemma exp_lt_exp {a b : EReal} (h : a < b) : exp a < exp b := by simpa end Monotonicity /-! ### Algebraic properties -/ section Morphism lemma exp_neg (x : EReal) : exp (-x) = (exp x)⁻¹ := by induction x Β· simp Β· rw [exp_coe, ← EReal.coe_neg, exp_coe, ← ENNReal.ofReal_inv_of_pos (Real.exp_pos _), Real.exp_neg] Β· simp lemma exp_add (x y : EReal) : exp (x + y) = exp x * exp y := by induction x Β· simp Β· induction y Β· simp Β· simp only [← EReal.coe_add, exp_coe] rw [← ENNReal.ofReal_mul (Real.exp_nonneg _), Real.exp_add] Β· simp only [EReal.coe_add_top, exp_top, exp_coe] rw [ENNReal.mul_top] simp [Real.exp_pos] Β· induction y Β· simp Β· simp only [EReal.top_add_coe, exp_top, exp_coe] rw [ENNReal.top_mul] simp [Real.exp_pos] Β· simp end Morphism end EReal
.lake/packages/mathlib/Mathlib/Analysis/SpecialFunctions/Log/Deriv.lean
import Mathlib.Analysis.Calculus.Deriv.Pow import Mathlib.Analysis.Calculus.LogDeriv import Mathlib.Analysis.SpecialFunctions.Log.Basic import Mathlib.Analysis.SpecialFunctions.ExpDeriv import Mathlib.Tactic.AdaptationNote /-! # Derivative and series expansion of real logarithm In this file we prove that `Real.log` is infinitely smooth at all nonzero `x : ℝ`. We also prove that the series `βˆ‘' n : β„•, x ^ (n + 1) / (n + 1)` converges to `(-Real.log (1 - x))` for all `x : ℝ`, `|x| < 1`. ## Tags logarithm, derivative -/ open Filter Finset Set open scoped Topology ContDiff namespace Real variable {x : ℝ} theorem hasStrictDerivAt_log_of_pos (hx : 0 < x) : HasStrictDerivAt log x⁻¹ x := by have : HasStrictDerivAt log (exp <| log x)⁻¹ x := (hasStrictDerivAt_exp <| log x).of_local_left_inverse (continuousAt_log hx.ne') (ne_of_gt <| exp_pos _) <| Eventually.mono (lt_mem_nhds hx) @exp_log rwa [exp_log hx] at this theorem hasStrictDerivAt_log (hx : x β‰  0) : HasStrictDerivAt log x⁻¹ x := by rcases hx.lt_or_gt with hx | hx Β· convert (hasStrictDerivAt_log_of_pos (neg_pos.mpr hx)).comp x (hasStrictDerivAt_neg x) using 1 Β· ext y; exact (log_neg_eq_log y).symm Β· ring Β· exact hasStrictDerivAt_log_of_pos hx theorem hasDerivAt_log (hx : x β‰  0) : HasDerivAt log x⁻¹ x := (hasStrictDerivAt_log hx).hasDerivAt @[fun_prop] theorem differentiableAt_log (hx : x β‰  0) : DifferentiableAt ℝ log x := (hasDerivAt_log hx).differentiableAt theorem differentiableOn_log : DifferentiableOn ℝ log {0}ᢜ := fun _x hx => (differentiableAt_log hx).differentiableWithinAt @[simp] theorem differentiableAt_log_iff : DifferentiableAt ℝ log x ↔ x β‰  0 := ⟨fun h => continuousAt_log_iff.1 h.continuousAt, differentiableAt_log⟩ theorem deriv_log (x : ℝ) : deriv log x = x⁻¹ := if hx : x = 0 then by rw [deriv_zero_of_not_differentiableAt (differentiableAt_log_iff.not_left.2 hx), hx, inv_zero] else (hasDerivAt_log hx).deriv @[simp] theorem deriv_log' : deriv log = Inv.inv := funext deriv_log theorem contDiffAt_log {n : WithTop β„•βˆž} {x : ℝ} : ContDiffAt ℝ n log x ↔ x β‰  0 := by refine ⟨fun h ↦ continuousAt_log_iff.1 h.continuousAt, fun hx ↦ ?_⟩ have A y (hy : 0 < y) : ContDiffAt ℝ n log y := by apply expPartialHomeomorph.contDiffAt_symm_deriv (fβ‚€' := y) hy.ne' (by simpa) Β· convert hasDerivAt_exp (log y) rw [exp_log hy] Β· exact analyticAt_rexp.contDiffAt rcases hx.lt_or_gt with hx | hx Β· have : ContDiffAt ℝ n (log ∘ (fun y ↦ -y)) x := by apply ContDiffAt.comp Β· apply A _ (Left.neg_pos_iff.mpr hx) apply contDiffAt_id.neg convert this ext x simp Β· exact A x hx @[fun_prop] theorem contDiffOn_log {n : WithTop β„•βˆž} : ContDiffOn ℝ n log {0}ᢜ := by intro x hx simp only [mem_compl_iff, mem_singleton_iff] at hx exact (contDiffAt_log.2 hx).contDiffWithinAt end Real section LogDifferentiable open Real section deriv variable {f : ℝ β†’ ℝ} {x f' : ℝ} {s : Set ℝ} theorem HasDerivWithinAt.log (hf : HasDerivWithinAt f f' s x) (hx : f x β‰  0) : HasDerivWithinAt (fun y => log (f y)) (f' / f x) s x := by rw [div_eq_inv_mul] exact (hasDerivAt_log hx).comp_hasDerivWithinAt x hf theorem HasDerivAt.log (hf : HasDerivAt f f' x) (hx : f x β‰  0) : HasDerivAt (fun y => log (f y)) (f' / f x) x := by rw [← hasDerivWithinAt_univ] at * exact hf.log hx theorem HasStrictDerivAt.log (hf : HasStrictDerivAt f f' x) (hx : f x β‰  0) : HasStrictDerivAt (fun y => log (f y)) (f' / f x) x := by rw [div_eq_inv_mul] exact (hasStrictDerivAt_log hx).comp x hf theorem derivWithin.log (hf : DifferentiableWithinAt ℝ f s x) (hx : f x β‰  0) (hxs : UniqueDiffWithinAt ℝ s x) : derivWithin (fun x => log (f x)) s x = derivWithin f s x / f x := (hf.hasDerivWithinAt.log hx).derivWithin hxs @[simp] theorem deriv.log (hf : DifferentiableAt ℝ f x) (hx : f x β‰  0) : deriv (fun x => log (f x)) x = deriv f x / f x := (hf.hasDerivAt.log hx).deriv /-- The derivative of `log ∘ f` is the logarithmic derivative provided `f` is differentiable and `f x β‰  0`. -/ lemma Real.deriv_log_comp_eq_logDeriv {f : ℝ β†’ ℝ} {x : ℝ} (h₁ : DifferentiableAt ℝ f x) (hβ‚‚ : f x β‰  0) : deriv (log ∘ f) x = logDeriv f x := by simp only [logDeriv, Pi.div_apply, ← deriv.log h₁ hβ‚‚, Function.comp_def] end deriv section fderiv variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] {f : E β†’ ℝ} {x : E} {f' : StrongDual ℝ E} {s : Set E} theorem HasFDerivWithinAt.log (hf : HasFDerivWithinAt f f' s x) (hx : f x β‰  0) : HasFDerivWithinAt (fun x => log (f x)) ((f x)⁻¹ β€’ f') s x := (hasDerivAt_log hx).comp_hasFDerivWithinAt x hf theorem HasFDerivAt.log (hf : HasFDerivAt f f' x) (hx : f x β‰  0) : HasFDerivAt (fun x => log (f x)) ((f x)⁻¹ β€’ f') x := (hasDerivAt_log hx).comp_hasFDerivAt x hf theorem HasStrictFDerivAt.log (hf : HasStrictFDerivAt f f' x) (hx : f x β‰  0) : HasStrictFDerivAt (fun x => log (f x)) ((f x)⁻¹ β€’ f') x := (hasStrictDerivAt_log hx).comp_hasStrictFDerivAt x hf theorem DifferentiableWithinAt.log (hf : DifferentiableWithinAt ℝ f s x) (hx : f x β‰  0) : DifferentiableWithinAt ℝ (fun x => log (f x)) s x := (hf.hasFDerivWithinAt.log hx).differentiableWithinAt @[simp, fun_prop] theorem DifferentiableAt.log (hf : DifferentiableAt ℝ f x) (hx : f x β‰  0) : DifferentiableAt ℝ (fun x => log (f x)) x := (hf.hasFDerivAt.log hx).differentiableAt @[fun_prop] theorem ContDiffAt.log {n} (hf : ContDiffAt ℝ n f x) (hx : f x β‰  0) : ContDiffAt ℝ n (fun x => log (f x)) x := (contDiffAt_log.2 hx).comp x hf @[fun_prop] theorem ContDiffWithinAt.log {n} (hf : ContDiffWithinAt ℝ n f s x) (hx : f x β‰  0) : ContDiffWithinAt ℝ n (fun x => log (f x)) s x := (contDiffAt_log.2 hx).comp_contDiffWithinAt x hf @[fun_prop] theorem ContDiffOn.log {n} (hf : ContDiffOn ℝ n f s) (hs : βˆ€ x ∈ s, f x β‰  0) : ContDiffOn ℝ n (fun x => log (f x)) s := fun x hx => (hf x hx).log (hs x hx) @[fun_prop] theorem ContDiff.log {n} (hf : ContDiff ℝ n f) (h : βˆ€ x, f x β‰  0) : ContDiff ℝ n fun x => log (f x) := contDiff_iff_contDiffAt.2 fun x => hf.contDiffAt.log (h x) @[fun_prop] theorem DifferentiableOn.log (hf : DifferentiableOn ℝ f s) (hx : βˆ€ x ∈ s, f x β‰  0) : DifferentiableOn ℝ (fun x => log (f x)) s := fun x h => (hf x h).log (hx x h) @[simp, fun_prop] theorem Differentiable.log (hf : Differentiable ℝ f) (hx : βˆ€ x, f x β‰  0) : Differentiable ℝ fun x => log (f x) := fun x => (hf x).log (hx x) theorem fderivWithin.log (hf : DifferentiableWithinAt ℝ f s x) (hx : f x β‰  0) (hxs : UniqueDiffWithinAt ℝ s x) : fderivWithin ℝ (fun x => log (f x)) s x = (f x)⁻¹ β€’ fderivWithin ℝ f s x := (hf.hasFDerivWithinAt.log hx).fderivWithin hxs @[simp] theorem fderiv.log (hf : DifferentiableAt ℝ f x) (hx : f x β‰  0) : fderiv ℝ (fun x => log (f x)) x = (f x)⁻¹ β€’ fderiv ℝ f x := (hf.hasFDerivAt.log hx).fderiv end fderiv end LogDifferentiable namespace Real -- see https://github.com/leanprover-community/mathlib4/issues/29041 set_option linter.unusedSimpArgs false in /-- A crude lemma estimating the difference between `log (1-x)` and its Taylor series at `0`, where the main point of the bound is that it tends to `0`. The goal is to deduce the series expansion of the logarithm, in `hasSum_pow_div_log_of_abs_lt_1`. TODO: use one of generic theorems about Taylor's series to prove this estimate. -/ theorem abs_log_sub_add_sum_range_le {x : ℝ} (h : |x| < 1) (n : β„•) : |(βˆ‘ i ∈ range n, x ^ (i + 1) / (i + 1)) + log (1 - x)| ≀ |x| ^ (n + 1) / (1 - |x|) := by /- For the proof, we show that the derivative of the function to be estimated is small, and then apply the mean value inequality. -/ let F : ℝ β†’ ℝ := fun x => (βˆ‘ i ∈ range n, x ^ (i + 1) / (i + 1)) + log (1 - x) let F' : ℝ β†’ ℝ := fun x ↦ -x ^ n / (1 - x) -- Porting note: In `mathlib3`, the proof used `deriv`/`DifferentiableAt`. `simp` failed to -- compute `deriv`, so I changed the proof to use `HasDerivAt` instead -- First step: compute the derivative of `F` have A : βˆ€ y ∈ Ioo (-1 : ℝ) 1, HasDerivAt F (F' y) y := fun y hy ↦ by have : HasDerivAt F ((βˆ‘ i ∈ range n, ↑(i + 1) * y ^ i / (↑i + 1)) + (-1) / (1 - y)) y := .add (.fun_sum fun i _ ↦ (hasDerivAt_pow (i + 1) y).div_const ((i : ℝ) + 1)) (((hasDerivAt_id y).const_sub _).log <| sub_ne_zero.2 hy.2.ne') convert this using 1 calc -y ^ n / (1 - y) = βˆ‘ i ∈ Finset.range n, y ^ i + -1 / (1 - y) := by simp [field, geom_sum_eq hy.2.ne, sub_ne_zero.2 hy.2.ne, sub_ne_zero.2 hy.2.ne'] ring _ = βˆ‘ i ∈ Finset.range n, ↑(i + 1) * y ^ i / (↑i + 1) + -1 / (1 - y) := by congr with i rw [Nat.cast_succ, mul_div_cancel_leftβ‚€ _ (Nat.cast_add_one_pos i).ne'] -- second step: show that the derivative of `F` is small have B : βˆ€ y ∈ Icc (-|x|) |x|, |F' y| ≀ |x| ^ n / (1 - |x|) := fun y hy ↦ calc |F' y| = |y| ^ n / |1 - y| := by simp [F', abs_div] _ ≀ |x| ^ n / (1 - |x|) := by have : |y| ≀ |x| := abs_le.2 hy have : 1 - |x| ≀ |1 - y| := le_trans (by linarith [hy.2]) (le_abs_self _) gcongr exact sub_pos.2 h -- third step: apply the mean value inequality have C : β€–F x - F 0β€– ≀ |x| ^ n / (1 - |x|) * β€–x - 0β€– := by refine Convex.norm_image_sub_le_of_norm_hasDerivWithin_le (fun y hy ↦ (A _ ?_).hasDerivWithinAt) B (convex_Icc _ _) ?_ ?_ Β· exact Icc_subset_Ioo (neg_lt_neg h) h hy Β· simp Β· simp [le_abs_self x, neg_le.mp (neg_le_abs x)] -- fourth step: conclude by massaging the inequality of the third step simpa [F, div_mul_eq_mul_div, pow_succ] using C /-- Power series expansion of the logarithm around `1`. -/ theorem hasSum_pow_div_log_of_abs_lt_one {x : ℝ} (h : |x| < 1) : HasSum (fun n : β„• => x ^ (n + 1) / (n + 1)) (-log (1 - x)) := by rw [Summable.hasSum_iff_tendsto_nat] Β· show Tendsto (fun n : β„• => βˆ‘ i ∈ range n, x ^ (i + 1) / (i + 1)) atTop (𝓝 (-log (1 - x))) rw [tendsto_iff_norm_sub_tendsto_zero] simp only [norm_eq_abs, sub_neg_eq_add] refine squeeze_zero (fun n => abs_nonneg _) (abs_log_sub_add_sum_range_le h) ?_ suffices Tendsto (fun t : β„• => |x| ^ (t + 1) / (1 - |x|)) atTop (𝓝 (|x| * 0 / (1 - |x|))) by simpa simp only [pow_succ'] refine (tendsto_const_nhds.mul ?_).div_const _ exact tendsto_pow_atTop_nhds_zero_of_lt_one (abs_nonneg _) h show Summable fun n : β„• => x ^ (n + 1) / (n + 1) refine .of_norm_bounded (summable_geometric_of_lt_one (abs_nonneg _) h) fun i => ?_ calc β€–x ^ (i + 1) / (i + 1)β€– = |x| ^ (i + 1) / (i + 1) := by have : (0 : ℝ) ≀ i + 1 := le_of_lt (Nat.cast_add_one_pos i) rw [norm_eq_abs, abs_div, ← pow_abs, abs_of_nonneg this] _ ≀ |x| ^ (i + 1) / (0 + 1) := by gcongr exact i.cast_nonneg _ ≀ |x| ^ i := by simpa [pow_succ] using mul_le_of_le_one_right (pow_nonneg (abs_nonneg x) i) (le_of_lt h) /-- Power series expansion of `log(1 + x) - log(1 - x)` for `|x| < 1`. -/ theorem hasSum_log_sub_log_of_abs_lt_one {x : ℝ} (h : |x| < 1) : HasSum (fun k : β„• => (2 : ℝ) * (1 / (2 * k + 1)) * x ^ (2 * k + 1)) (log (1 + x) - log (1 - x)) := by set term := fun n : β„• => -1 * ((-x) ^ (n + 1) / ((n : ℝ) + 1)) + x ^ (n + 1) / (n + 1) have h_term_eq_goal : term ∘ (2 * Β·) = fun k : β„• => 2 * (1 / (2 * k + 1)) * x ^ (2 * k + 1) := by ext n dsimp only [term, (Β· ∘ Β·)] rw [Odd.neg_pow (⟨n, rfl⟩ : Odd (2 * n + 1)) x] push_cast ring_nf rw [← h_term_eq_goal, (mul_right_injectiveβ‚€ (two_ne_zero' β„•)).hasSum_iff] Β· have h₁ := (hasSum_pow_div_log_of_abs_lt_one (Eq.trans_lt (abs_neg x) h)).mul_left (-1) convert h₁.add (hasSum_pow_div_log_of_abs_lt_one h) using 1 ring_nf Β· intro m hm rw [range_two_mul, Set.mem_setOf_eq, ← Nat.even_add_one] at hm dsimp [term] rw [Even.neg_pow hm, neg_one_mul, neg_add_cancel] /-- Expansion of `log (1 + a⁻¹)` as a series in powers of `1 / (2 * a + 1)`. -/ theorem hasSum_log_one_add_inv {a : ℝ} (h : 0 < a) : HasSum (fun k : β„• => (2 : ℝ) * (1 / (2 * k + 1)) * (1 / (2 * a + 1)) ^ (2 * k + 1)) (log (1 + a⁻¹)) := by have h₁ : |1 / (2 * a + 1)| < 1 := by rw [abs_of_pos, div_lt_one] Β· linarith Β· linarith Β· exact div_pos one_pos (by linarith) convert hasSum_log_sub_log_of_abs_lt_one h₁ using 1 have hβ‚‚ : (2 : ℝ) * a + 1 β‰  0 := by linarith have h₃ := h.ne' rw [← log_div] Β· congr simp [field] ring Β· field_simp positivity Β· simp [field, h₃] /-- Expansion of `log (1 + a)` as a series in powers of `a / (a + 2)`. -/ theorem hasSum_log_one_add {a : ℝ} (h : 0 ≀ a) : HasSum (fun k : β„• => (2 : ℝ) * (1 / (2 * k + 1)) * (a / (a + 2)) ^ (2 * k + 1)) (log (1 + a)) := by obtain (rfl | ha0) := eq_or_ne a 0 Β· simp [hasSum_zero] Β· convert hasSum_log_one_add_inv (inv_pos.mpr (lt_of_le_of_ne h ha0.symm)) using 4 all_goals simp [field, add_comm] lemma le_log_one_add_of_nonneg {x : ℝ} (hx : 0 ≀ x) : 2 * x / (x + 2) ≀ log (1 + x) := by convert le_hasSum (hasSum_log_one_add hx) 0 (by intros; positivity) using 1 simp [field] lemma lt_log_one_add_of_pos {x : ℝ} (hx : 0 < x) : 2 * x / (x + 2) < log (1 + x) := by convert lt_hasSum (hasSum_log_one_add hx.le) 0 (by intros; positivity) 1 (by positivity) (by positivity) using 1 simp [field] end Real
.lake/packages/mathlib/Mathlib/Analysis/SpecialFunctions/Log/Base.lean
import Mathlib.Algebra.BigOperators.Field import Mathlib.Analysis.SpecialFunctions.Pow.Real import Mathlib.Data.Int.Log /-! # Real logarithm base `b` In this file we define `Real.logb` to be the logarithm of a real number in a given base `b`. We define this as the division of the natural logarithms of the argument and the base, so that we have a globally defined function with `logb b 0 = 0`, `logb b (-x) = logb b x` `logb 0 x = 0` and `logb (-b) x = logb b x`. We prove some basic properties of this function and its relation to `rpow`. ## Tags logarithm, continuity -/ open Set Filter Function open Topology noncomputable section namespace Real variable {b x y : ℝ} /-- The real logarithm in a given base. As with the natural logarithm, we define `logb b x` to be `logb b |x|` for `x < 0`, and `0` for `x = 0`. -/ @[pp_nodot] noncomputable def logb (b x : ℝ) : ℝ := log x / log b theorem log_div_log : log x / log b = logb b x := rfl @[simp] theorem logb_zero : logb b 0 = 0 := by simp [logb] @[simp] theorem logb_one : logb b 1 = 0 := by simp [logb] theorem logb_zero_left : logb 0 x = 0 := by simp only [← log_div_log, log_zero, div_zero] @[simp] theorem logb_zero_left_eq_zero : logb 0 = 0 := by ext; rw [logb_zero_left, Pi.zero_apply] theorem logb_one_left : logb 1 x = 0 := by simp only [← log_div_log, log_one, div_zero] @[simp] theorem logb_one_left_eq_zero : logb 1 = 0 := by ext; rw [logb_one_left, Pi.zero_apply] @[simp] lemma logb_self_eq_one (hb : 1 < b) : logb b b = 1 := div_self (log_pos hb).ne' lemma logb_self_eq_one_iff : logb b b = 1 ↔ b β‰  0 ∧ b β‰  1 ∧ b β‰  -1 := Iff.trans ⟨fun h h' => by simp [logb, h'] at h, div_self⟩ log_ne_zero @[simp] theorem logb_abs_base (b x : ℝ) : logb |b| x = logb b x := by rw [logb, logb, log_abs] @[simp] theorem logb_abs (b x : ℝ) : logb b |x| = logb b x := by rw [logb, logb, log_abs] @[simp] theorem logb_neg_base_eq_logb (b x : ℝ) : logb (-b) x = logb b x := by rw [← logb_abs_base b x, ← logb_abs_base (-b) x, abs_neg] @[simp] theorem logb_neg_eq_logb (b x : ℝ) : logb b (-x) = logb b x := by rw [← logb_abs b x, ← logb_abs b (-x), abs_neg] theorem logb_mul (hx : x β‰  0) (hy : y β‰  0) : logb b (x * y) = logb b x + logb b y := by simp_rw [logb, log_mul hx hy, add_div] theorem logb_div (hx : x β‰  0) (hy : y β‰  0) : logb b (x / y) = logb b x - logb b y := by simp_rw [logb, log_div hx hy, sub_div] @[simp] theorem logb_inv (b x : ℝ) : logb b x⁻¹ = -logb b x := by simp [logb, neg_div] @[simp] theorem logb_inv_base (b x : ℝ) : logb b⁻¹ x = -logb b x := by simp [logb, div_neg] theorem inv_logb (a b : ℝ) : (logb a b)⁻¹ = logb b a := by simp_rw [logb, inv_div] theorem inv_logb_mul_base {a b : ℝ} (h₁ : a β‰  0) (hβ‚‚ : b β‰  0) (c : ℝ) : (logb (a * b) c)⁻¹ = (logb a c)⁻¹ + (logb b c)⁻¹ := by simp_rw [inv_logb]; exact logb_mul h₁ hβ‚‚ theorem inv_logb_div_base {a b : ℝ} (h₁ : a β‰  0) (hβ‚‚ : b β‰  0) (c : ℝ) : (logb (a / b) c)⁻¹ = (logb a c)⁻¹ - (logb b c)⁻¹ := by simp_rw [inv_logb]; exact logb_div h₁ hβ‚‚ theorem logb_mul_base {a b : ℝ} (h₁ : a β‰  0) (hβ‚‚ : b β‰  0) (c : ℝ) : logb (a * b) c = ((logb a c)⁻¹ + (logb b c)⁻¹)⁻¹ := by rw [← inv_logb_mul_base h₁ hβ‚‚ c, inv_inv] theorem logb_div_base {a b : ℝ} (h₁ : a β‰  0) (hβ‚‚ : b β‰  0) (c : ℝ) : logb (a / b) c = ((logb a c)⁻¹ - (logb b c)⁻¹)⁻¹ := by rw [← inv_logb_div_base h₁ hβ‚‚ c, inv_inv] theorem mul_logb {a b c : ℝ} (h₁ : b β‰  0) (hβ‚‚ : b β‰  1) (h₃ : b β‰  -1) : logb a b * logb b c = logb a c := by unfold logb rw [mul_comm, div_mul_div_cancelβ‚€ (log_ne_zero.mpr ⟨h₁, hβ‚‚, hβ‚ƒβŸ©)] theorem div_logb {a b c : ℝ} (h₁ : c β‰  0) (hβ‚‚ : c β‰  1) (h₃ : c β‰  -1) : logb a c / logb b c = logb a b := div_div_div_cancel_left' _ _ <| log_ne_zero.mpr ⟨h₁, hβ‚‚, hβ‚ƒβŸ© theorem logb_rpow_eq_mul_logb_of_pos (hx : 0 < x) : logb b (x ^ y) = y * logb b x := by rw [logb, log_rpow hx, logb, mul_div_assoc] theorem logb_pow (b x : ℝ) (k : β„•) : logb b (x ^ k) = k * logb b x := by rw [logb, logb, log_pow, mul_div_assoc] section BPosAndNeOne variable (b_pos : 0 < b) (b_ne_one : b β‰  1) include b_pos b_ne_one @[simp] theorem logb_rpow : logb b (b ^ x) = x := by rw [logb, div_eq_iff, log_rpow b_pos] exact log_ne_zero_of_pos_of_ne_one b_pos b_ne_one theorem rpow_logb_eq_abs (hx : x β‰  0) : b ^ logb b x = |x| := by apply log_injOn_pos Β· simp only [Set.mem_Ioi] apply rpow_pos_of_pos b_pos Β· simp only [abs_pos, mem_Ioi, Ne, hx, not_false_iff] rw [log_rpow b_pos, logb, log_abs] field [log_ne_zero_of_pos_of_ne_one b_pos b_ne_one] @[simp] theorem rpow_logb (hx : 0 < x) : b ^ logb b x = x := by rw [rpow_logb_eq_abs b_pos b_ne_one hx.ne'] exact abs_of_pos hx theorem rpow_logb_of_neg (hx : x < 0) : b ^ logb b x = -x := by rw [rpow_logb_eq_abs b_pos b_ne_one (ne_of_lt hx)] exact abs_of_neg hx theorem logb_eq_iff_rpow_eq (hy : 0 < y) : logb b y = x ↔ b ^ x = y := by constructor <;> rintro rfl Β· exact rpow_logb b_pos b_ne_one hy Β· exact logb_rpow b_pos b_ne_one theorem surjOn_logb : SurjOn (logb b) (Ioi 0) univ := fun x _ => ⟨b ^ x, rpow_pos_of_pos b_pos x, logb_rpow b_pos b_ne_one⟩ theorem logb_surjective : Surjective (logb b) := fun x => ⟨b ^ x, logb_rpow b_pos b_ne_one⟩ @[simp] theorem range_logb : range (logb b) = univ := (logb_surjective b_pos b_ne_one).range_eq theorem surjOn_logb' : SurjOn (logb b) (Iio 0) univ := by intro x _ use -b ^ x constructor Β· simp only [Right.neg_neg_iff, Set.mem_Iio] apply rpow_pos_of_pos b_pos Β· rw [logb_neg_eq_logb, logb_rpow b_pos b_ne_one] end BPosAndNeOne section OneLtB variable (hb : 1 < b) include hb private theorem b_pos : 0 < b := by linarith -- Name has a prime added to avoid clashing with `b_ne_one` further down the file private theorem b_ne_one' : b β‰  1 := by linarith @[simp] theorem logb_le_logb (h : 0 < x) (h₁ : 0 < y) : logb b x ≀ logb b y ↔ x ≀ y := by rw [logb, logb, div_le_div_iff_of_pos_right (log_pos hb), log_le_log_iff h h₁] @[gcongr] theorem logb_le_logb_of_le (h : 0 < x) (hxy : x ≀ y) : logb b x ≀ logb b y := (logb_le_logb hb h (by linarith)).mpr hxy @[gcongr] theorem logb_lt_logb (hx : 0 < x) (hxy : x < y) : logb b x < logb b y := by rw [logb, logb, div_lt_div_iff_of_pos_right (log_pos hb)] exact log_lt_log hx hxy @[simp] theorem logb_lt_logb_iff (hx : 0 < x) (hy : 0 < y) : logb b x < logb b y ↔ x < y := by rw [logb, logb, div_lt_div_iff_of_pos_right (log_pos hb)] exact log_lt_log_iff hx hy theorem logb_le_iff_le_rpow (hx : 0 < x) : logb b x ≀ y ↔ x ≀ b ^ y := by rw [← rpow_le_rpow_left_iff hb, rpow_logb (b_pos hb) (b_ne_one' hb) hx] theorem logb_lt_iff_lt_rpow (hx : 0 < x) : logb b x < y ↔ x < b ^ y := by rw [← rpow_lt_rpow_left_iff hb, rpow_logb (b_pos hb) (b_ne_one' hb) hx] theorem le_logb_iff_rpow_le (hy : 0 < y) : x ≀ logb b y ↔ b ^ x ≀ y := by rw [← rpow_le_rpow_left_iff hb, rpow_logb (b_pos hb) (b_ne_one' hb) hy] theorem lt_logb_iff_rpow_lt (hy : 0 < y) : x < logb b y ↔ b ^ x < y := by rw [← rpow_lt_rpow_left_iff hb, rpow_logb (b_pos hb) (b_ne_one' hb) hy] theorem logb_pos_iff (hx : 0 < x) : 0 < logb b x ↔ 1 < x := by rw [← @logb_one b] rw [logb_lt_logb_iff hb zero_lt_one hx] theorem logb_pos (hx : 1 < x) : 0 < logb b x := by rw [logb_pos_iff hb (lt_trans zero_lt_one hx)] exact hx theorem logb_neg_iff (h : 0 < x) : logb b x < 0 ↔ x < 1 := by rw [← logb_one] exact logb_lt_logb_iff hb h zero_lt_one theorem logb_neg (h0 : 0 < x) (h1 : x < 1) : logb b x < 0 := (logb_neg_iff hb h0).2 h1 theorem logb_nonneg_iff (hx : 0 < x) : 0 ≀ logb b x ↔ 1 ≀ x := by rw [← not_lt, logb_neg_iff hb hx, not_lt] theorem logb_nonneg (hx : 1 ≀ x) : 0 ≀ logb b x := (logb_nonneg_iff hb (zero_lt_one.trans_le hx)).2 hx theorem logb_nonpos_iff (hx : 0 < x) : logb b x ≀ 0 ↔ x ≀ 1 := by rw [← not_lt, logb_pos_iff hb hx, not_lt] theorem logb_nonpos_iff' (hx : 0 ≀ x) : logb b x ≀ 0 ↔ x ≀ 1 := by rcases hx.eq_or_lt with (rfl | hx) Β· simp [le_refl, zero_le_one] exact logb_nonpos_iff hb hx theorem logb_nonpos (hx : 0 ≀ x) (h'x : x ≀ 1) : logb b x ≀ 0 := (logb_nonpos_iff' hb hx).2 h'x theorem strictMonoOn_logb : StrictMonoOn (logb b) (Set.Ioi 0) := fun _ hx _ _ hxy => logb_lt_logb hb hx hxy theorem strictAntiOn_logb : StrictAntiOn (logb b) (Set.Iio 0) := by rintro x (hx : x < 0) y (hy : y < 0) hxy rw [← logb_abs b y, ← logb_abs b x] refine logb_lt_logb hb (abs_pos.2 hy.ne) ?_ rwa [abs_of_neg hy, abs_of_neg hx, neg_lt_neg_iff] theorem logb_injOn_pos : Set.InjOn (logb b) (Set.Ioi 0) := (strictMonoOn_logb hb).injOn theorem eq_one_of_pos_of_logb_eq_zero (h₁ : 0 < x) (hβ‚‚ : logb b x = 0) : x = 1 := logb_injOn_pos hb (Set.mem_Ioi.2 h₁) (Set.mem_Ioi.2 zero_lt_one) (hβ‚‚.trans Real.logb_one.symm) theorem logb_ne_zero_of_pos_of_ne_one (hx_pos : 0 < x) (hx : x β‰  1) : logb b x β‰  0 := mt (eq_one_of_pos_of_logb_eq_zero hb hx_pos) hx theorem tendsto_logb_atTop : Tendsto (logb b) atTop atTop := Tendsto.atTop_div_const (log_pos hb) tendsto_log_atTop end OneLtB section BPosAndBLtOne variable (b_pos : 0 < b) (b_lt_one : b < 1) include b_lt_one private theorem b_ne_one : b β‰  1 := by linarith include b_pos @[simp] theorem logb_le_logb_of_base_lt_one (h : 0 < x) (h₁ : 0 < y) : logb b x ≀ logb b y ↔ y ≀ x := by rw [logb, logb, div_le_div_right_of_neg (log_neg b_pos b_lt_one), log_le_log_iff h₁ h] theorem logb_lt_logb_of_base_lt_one (hx : 0 < x) (hxy : x < y) : logb b y < logb b x := by rw [logb, logb, div_lt_div_right_of_neg (log_neg b_pos b_lt_one)] exact log_lt_log hx hxy @[simp] theorem logb_lt_logb_iff_of_base_lt_one (hx : 0 < x) (hy : 0 < y) : logb b x < logb b y ↔ y < x := by rw [logb, logb, div_lt_div_right_of_neg (log_neg b_pos b_lt_one)] exact log_lt_log_iff hy hx theorem logb_le_iff_le_rpow_of_base_lt_one (hx : 0 < x) : logb b x ≀ y ↔ b ^ y ≀ x := by rw [← rpow_le_rpow_left_iff_of_base_lt_one b_pos b_lt_one, rpow_logb b_pos (b_ne_one b_lt_one) hx] theorem logb_lt_iff_lt_rpow_of_base_lt_one (hx : 0 < x) : logb b x < y ↔ b ^ y < x := by rw [← rpow_lt_rpow_left_iff_of_base_lt_one b_pos b_lt_one, rpow_logb b_pos (b_ne_one b_lt_one) hx] theorem le_logb_iff_rpow_le_of_base_lt_one (hy : 0 < y) : x ≀ logb b y ↔ y ≀ b ^ x := by rw [← rpow_le_rpow_left_iff_of_base_lt_one b_pos b_lt_one, rpow_logb b_pos (b_ne_one b_lt_one) hy] theorem lt_logb_iff_rpow_lt_of_base_lt_one (hy : 0 < y) : x < logb b y ↔ y < b ^ x := by rw [← rpow_lt_rpow_left_iff_of_base_lt_one b_pos b_lt_one, rpow_logb b_pos (b_ne_one b_lt_one) hy] theorem logb_pos_iff_of_base_lt_one (hx : 0 < x) : 0 < logb b x ↔ x < 1 := by rw [← @logb_one b, logb_lt_logb_iff_of_base_lt_one b_pos b_lt_one zero_lt_one hx] theorem logb_pos_of_base_lt_one (hx : 0 < x) (hx' : x < 1) : 0 < logb b x := by rw [logb_pos_iff_of_base_lt_one b_pos b_lt_one hx] exact hx' theorem logb_neg_iff_of_base_lt_one (h : 0 < x) : logb b x < 0 ↔ 1 < x := by rw [← @logb_one b, logb_lt_logb_iff_of_base_lt_one b_pos b_lt_one h zero_lt_one] theorem logb_neg_of_base_lt_one (h1 : 1 < x) : logb b x < 0 := (logb_neg_iff_of_base_lt_one b_pos b_lt_one (lt_trans zero_lt_one h1)).2 h1 theorem logb_nonneg_iff_of_base_lt_one (hx : 0 < x) : 0 ≀ logb b x ↔ x ≀ 1 := by rw [← not_lt, logb_neg_iff_of_base_lt_one b_pos b_lt_one hx, not_lt] theorem logb_nonneg_of_base_lt_one (hx : 0 < x) (hx' : x ≀ 1) : 0 ≀ logb b x := by rw [logb_nonneg_iff_of_base_lt_one b_pos b_lt_one hx] exact hx' theorem logb_nonpos_iff_of_base_lt_one (hx : 0 < x) : logb b x ≀ 0 ↔ 1 ≀ x := by rw [← not_lt, logb_pos_iff_of_base_lt_one b_pos b_lt_one hx, not_lt] theorem strictAntiOn_logb_of_base_lt_one : StrictAntiOn (logb b) (Set.Ioi 0) := fun _ hx _ _ hxy => logb_lt_logb_of_base_lt_one b_pos b_lt_one hx hxy theorem strictMonoOn_logb_of_base_lt_one : StrictMonoOn (logb b) (Set.Iio 0) := by rintro x (hx : x < 0) y (hy : y < 0) hxy rw [← logb_abs b y, ← logb_abs b x] refine logb_lt_logb_of_base_lt_one b_pos b_lt_one (abs_pos.2 hy.ne) ?_ rwa [abs_of_neg hy, abs_of_neg hx, neg_lt_neg_iff] theorem logb_injOn_pos_of_base_lt_one : Set.InjOn (logb b) (Set.Ioi 0) := (strictAntiOn_logb_of_base_lt_one b_pos b_lt_one).injOn theorem eq_one_of_pos_of_logb_eq_zero_of_base_lt_one (h₁ : 0 < x) (hβ‚‚ : logb b x = 0) : x = 1 := logb_injOn_pos_of_base_lt_one b_pos b_lt_one (Set.mem_Ioi.2 h₁) (Set.mem_Ioi.2 zero_lt_one) (hβ‚‚.trans Real.logb_one.symm) theorem logb_ne_zero_of_pos_of_ne_one_of_base_lt_one (hx_pos : 0 < x) (hx : x β‰  1) : logb b x β‰  0 := mt (eq_one_of_pos_of_logb_eq_zero_of_base_lt_one b_pos b_lt_one hx_pos) hx theorem tendsto_logb_atTop_of_base_lt_one : Tendsto (logb b) atTop atBot := by rw [tendsto_atTop_atBot] intro e use 1 βŠ” b ^ e intro a simp only [and_imp, sup_le_iff] intro ha rw [logb_le_iff_le_rpow_of_base_lt_one b_pos b_lt_one] Β· tauto Β· exact lt_of_lt_of_le zero_lt_one ha end BPosAndBLtOne @[norm_cast] theorem floor_logb_natCast {b : β„•} {r : ℝ} (hr : 0 ≀ r) : ⌊logb b rβŒ‹ = Int.log b r := by obtain rfl | hr := hr.eq_or_lt Β· rw [logb_zero, Int.log_zero_right, Int.floor_zero] by_cases hb : 1 < b Β· have hb1' : 1 < (b : ℝ) := Nat.one_lt_cast.mpr hb apply le_antisymm Β· rw [← Int.zpow_le_iff_le_log hb hr, ← rpow_intCast b] refine le_of_le_of_eq ?_ (rpow_logb (zero_lt_one.trans hb1') hb1'.ne' hr) exact rpow_le_rpow_of_exponent_le hb1'.le (Int.floor_le _) Β· rw [Int.le_floor, le_logb_iff_rpow_le hb1' hr, rpow_intCast] exact Int.zpow_log_le_self hb hr Β· rw [Nat.one_lt_iff_ne_zero_and_ne_one, ← or_iff_not_and_not] at hb cases hb Β· simp_all only [CharP.cast_eq_zero, logb_zero_left, Int.floor_zero, Int.log_zero_left] Β· simp_all only [Nat.cast_one, logb_one_left, Int.floor_zero, Int.log_one_left] @[norm_cast] theorem ceil_logb_natCast {b : β„•} {r : ℝ} (hr : 0 ≀ r) : ⌈logb b rβŒ‰ = Int.clog b r := by obtain rfl | hr := hr.eq_or_lt Β· rw [logb_zero, Int.clog_zero_right, Int.ceil_zero] by_cases hb : 1 < b Β· have hb1' : 1 < (b : ℝ) := Nat.one_lt_cast.mpr hb apply le_antisymm Β· rw [Int.ceil_le, logb_le_iff_le_rpow hb1' hr, rpow_intCast] exact Int.self_le_zpow_clog hb r Β· rw [← Int.le_zpow_iff_clog_le hb hr, ← rpow_intCast b] refine (rpow_logb (zero_lt_one.trans hb1') hb1'.ne' hr).symm.trans_le ?_ exact rpow_le_rpow_of_exponent_le hb1'.le (Int.le_ceil _) Β· rw [Nat.one_lt_iff_ne_zero_and_ne_one, ← or_iff_not_and_not] at hb cases hb Β· simp_all only [CharP.cast_eq_zero, logb_zero_left, Int.ceil_zero, Int.clog_zero_left] Β· simp_all only [Nat.cast_one, logb_one_left, Int.ceil_zero, Int.clog_one_left] @[norm_cast] theorem natFloor_logb_natCast (b : β„•) (n : β„•) : ⌊logb b nβŒ‹β‚Š = Nat.log b n := by obtain _ | _ | b := b Β· simp [Real.logb] Β· simp [Real.logb] obtain rfl | hn := eq_or_ne n 0 Β· simp rw [← Nat.cast_inj (R := β„€), Int.natCast_floor_eq_floor, floor_logb_natCast (by simp), Int.log_natCast] exact logb_nonneg (by simp [Nat.cast_add_one_pos]) (Nat.one_le_cast.2 (by cutsat)) @[norm_cast] theorem natCeil_logb_natCast (b : β„•) (n : β„•) : ⌈logb b nβŒ‰β‚Š = Nat.clog b n := by obtain _ | _ | b := b Β· simp [Real.logb] Β· simp [Real.logb] obtain rfl | hn := eq_or_ne n 0 Β· simp rw [← Nat.cast_inj (R := β„€), Int.natCast_ceil_eq_ceil, ceil_logb_natCast (by simp), Int.clog_natCast] exact logb_nonneg (by simp [Nat.cast_add_one_pos]) (Nat.one_le_cast.2 (by cutsat)) lemma natLog_le_logb (a b : β„•) : Nat.log b a ≀ Real.logb b a := by apply le_trans _ (Int.floor_le ((b : ℝ).logb a)) rw [Real.floor_logb_natCast (Nat.cast_nonneg a), Int.log_natCast, Int.cast_natCast] lemma log2_le_logb (n : β„•) : Nat.log2 n ≀ Real.logb 2 n := by calc (Nat.log2 n : ℝ) = Nat.log 2 n := mod_cast Nat.log2_eq_log_two _ ≀ Real.logb 2 n := natLog_le_logb _ _ @[simp] theorem logb_eq_zero : logb b x = 0 ↔ b = 0 ∨ b = 1 ∨ b = -1 ∨ x = 0 ∨ x = 1 ∨ x = -1 := by simp_rw [logb, div_eq_zero_iff, log_eq_zero] tauto theorem tendsto_logb_nhdsNE_zero (hb : 1 < b) : Tendsto (logb b) (𝓝[β‰ ] 0) atBot := tendsto_log_nhdsNE_zero.atBot_div_const (log_pos hb) theorem tendsto_logb_nhdsNE_zero_of_base_lt_one (hbβ‚€ : 0 < b) (hb : b < 1) : Tendsto (logb b) (𝓝[β‰ ] 0) atTop := tendsto_log_nhdsNE_zero.atBot_mul_const_of_neg (inv_lt_zero.2 (log_neg hbβ‚€ hb)) lemma tendsto_logb_nhdsGT_zero (hb : 1 < b) : Tendsto (logb b) (𝓝[>] 0) atBot := tendsto_log_nhdsGT_zero.atBot_div_const (log_pos hb) lemma tendsto_logb_nhdsGT_zero_of_base_lt_one (hbβ‚€ : 0 < b) (hb : b < 1) : Tendsto (logb b) (𝓝[>] 0) atTop := tendsto_log_nhdsGT_zero.atBot_mul_const_of_neg (inv_lt_zero.2 (log_neg hbβ‚€ hb)) /-- The function `|logb b x|` tends to `+∞` as `x` tendsto `+∞`. See also `tendsto_logb_atTop` and `tendsto_logb_atTop_of_base_lt_one`. -/ lemma tendsto_abs_logb_atTop (hb : b β‰  -1 ∧ b β‰  0 ∧ b β‰  1) : Tendsto (|logb b Β·|) atTop atTop := by wlog hbβ‚€ : 0 < b generalizing b Β· exact (this (b := -b) (by simp [hb, neg_eq_iff_eq_neg]) (by linarith +splitNe)).congr (by simp) wlog hb₁ : 1 < b generalizing b Β· exact (this (b := b⁻¹) (by simp [hb, inv_eq_iff_eq_inv, inv_neg]) (by simpa) ((one_lt_invβ‚€ hbβ‚€).2 (by linarith +splitNe))).congr (by simp) refine (tendsto_logb_atTop hb₁).congr' ?_ filter_upwards [eventually_ge_atTop 1] with x hx₁ rw [abs_of_nonneg] exact logb_nonneg hb₁ hx₁ theorem continuousOn_logb : ContinuousOn (logb b) {0}ᢜ := continuousOn_log.div_const _ /-- The real logarithm base b is continuous as a function from nonzero reals. -/ @[fun_prop] theorem continuous_logb : Continuous fun x : { x : ℝ // x β‰  0 } => logb b x := continuous_log.div_const _ /-- The real logarithm base b is continuous as a function from positive reals. -/ @[fun_prop] theorem continuous_logb' : Continuous fun x : { x : ℝ // 0 < x } => logb b x := continuous_log'.div_const _ theorem continuousAt_logb (hx : x β‰  0) : ContinuousAt (logb b) x := (continuousAt_log hx).div_const _ @[simp] theorem continuousAt_logb_iff (hbβ‚€ : 0 < b) (hb : b β‰  1) : ContinuousAt (logb b) x ↔ x β‰  0 := by refine ⟨?_, continuousAt_logb⟩ rintro h rfl cases lt_or_gt_of_ne hb with | inl hb₁ => exact not_tendsto_nhds_of_tendsto_atTop (tendsto_logb_nhdsNE_zero_of_base_lt_one hbβ‚€ hb₁) _ (h.tendsto.mono_left inf_le_left) | inr hb₁ => exact not_tendsto_nhds_of_tendsto_atBot (tendsto_logb_nhdsNE_zero hb₁) _ (h.tendsto.mono_left inf_le_left) theorem logb_prod {Ξ± : Type*} (s : Finset Ξ±) (f : Ξ± β†’ ℝ) (hf : βˆ€ x ∈ s, f x β‰  0) : logb b (∏ i ∈ s, f i) = βˆ‘ i ∈ s, logb b (f i) := by induction s using Finset.cons_induction_on with | empty => simp | cons => simp_all [logb_mul, Finset.prod_ne_zero_iff] protected theorem _root_.Finsupp.logb_prod {Ξ± Ξ² : Type*} [Zero Ξ²] (f : Ξ± β†’β‚€ Ξ²) (g : Ξ± β†’ Ξ² β†’ ℝ) (hg : βˆ€ a, g a (f a) = 0 β†’ f a = 0) : logb b (f.prod g) = f.sum fun a c ↦ logb b (g a c) := logb_prod _ _ fun _x hx hβ‚€ ↦ Finsupp.mem_support_iff.1 hx <| hg _ hβ‚€ theorem logb_nat_eq_sum_factorization (n : β„•) : logb b n = n.factorization.sum fun p t => t * logb b p := by simp only [logb, mul_div_assoc', log_nat_eq_sum_factorization n, Finsupp.sum, Finset.sum_div] theorem tendsto_pow_logb_div_mul_add_atTop (a c : ℝ) (n : β„•) (ha : a β‰  0) : Tendsto (fun x => logb b x ^ n / (a * x + c)) atTop (𝓝 0) := by cases eq_or_ne (log b) 0 with | inl h => simpa [logb, h] using ((tendsto_mul_add_inv_atTop_nhds_zero _ _ ha).const_mul _) | inr h => apply (tendsto_pow_log_div_mul_add_atTop (a * (log b) ^ n) (c * (log b) ^ n) n (by positivity)).congr fun x ↦ by simp [field, div_pow, logb] theorem isLittleO_pow_logb_id_atTop {n : β„•} : (fun x => logb b x ^ n) =o[atTop] id := by rw [Asymptotics.isLittleO_iff_tendsto'] Β· simpa using tendsto_pow_logb_div_mul_add_atTop 1 0 n one_ne_zero Β· filter_upwards [eventually_ne_atTop (0 : ℝ)] with x h₁ hβ‚‚ using (h₁ hβ‚‚).elim theorem isLittleO_logb_id_atTop : logb b =o[atTop] id := isLittleO_pow_logb_id_atTop.congr_left fun _ => pow_one _ theorem isLittleO_const_logb_atTop {c : ℝ} (hb : b β‰  -1 ∧ b β‰  0 ∧ b β‰  1) : (fun _ => c) =o[atTop] logb b := by rw [Asymptotics.isLittleO_const_left, or_iff_not_imp_left] intro hc exact tendsto_abs_logb_atTop hb end Real section Continuity open Real variable {Ξ± : Type*} variable {b : ℝ} theorem Filter.Tendsto.logb {f : Ξ± β†’ ℝ} {l : Filter Ξ±} {x : ℝ} (h : Tendsto f l (𝓝 x)) (hx : x β‰  0) : Tendsto (fun y => logb b (f y)) l (𝓝 (logb b x)) := (continuousAt_logb hx).tendsto.comp h variable [TopologicalSpace Ξ±] {f : Ξ± β†’ ℝ} {s : Set Ξ±} {a : Ξ±} @[fun_prop] theorem Continuous.logb (hf : Continuous f) (hβ‚€ : βˆ€ x, f x β‰  0) : Continuous fun x => logb b (f x) := continuousOn_logb.comp_continuous hf hβ‚€ @[fun_prop] nonrec theorem ContinuousAt.logb (hf : ContinuousAt f a) (hβ‚€ : f a β‰  0) : ContinuousAt (fun x => logb b (f x)) a := hf.logb hβ‚€ nonrec theorem ContinuousWithinAt.logb (hf : ContinuousWithinAt f s a) (hβ‚€ : f a β‰  0) : ContinuousWithinAt (fun x => logb b (f x)) s a := hf.logb hβ‚€ @[fun_prop] theorem ContinuousOn.logb (hf : ContinuousOn f s) (hβ‚€ : βˆ€ x ∈ s, f x β‰  0) : ContinuousOn (fun x => logb b (f x)) s := fun x hx => (hf x hx).logb (hβ‚€ x hx) end Continuity section TendstoCompAddSub open Filter namespace Real variable {b : ℝ} theorem tendsto_logb_comp_add_sub_logb (y : ℝ) : Tendsto (fun x : ℝ => logb b (x + y) - logb b x) atTop (𝓝 0) := by simpa [sub_div] using (tendsto_log_comp_add_sub_log y).div_const (log b) theorem tendsto_logb_nat_add_one_sub_logb : Tendsto (fun k : β„• => logb b (k + 1) - logb b k) atTop (𝓝 0) := (tendsto_logb_comp_add_sub_logb 1).comp tendsto_natCast_atTop_atTop end Real end TendstoCompAddSub section Induction /-- Induction principle for intervals of real numbers: if a proposition `P` is true on `[xβ‚€, r * xβ‚€)` and if `P` for `[xβ‚€, r^n * xβ‚€)` implies `P` for `[r^n * xβ‚€, r^(n+1) * xβ‚€)`, then `P` is true for all `x β‰₯ xβ‚€`. -/ lemma Real.induction_Ico_mul {P : ℝ β†’ Prop} (xβ‚€ r : ℝ) (hr : 1 < r) (hxβ‚€ : 0 < xβ‚€) (base : βˆ€ x ∈ Set.Ico xβ‚€ (r * xβ‚€), P x) (step : βˆ€ n : β„•, n β‰₯ 1 β†’ (βˆ€ z ∈ Set.Ico xβ‚€ (r ^ n * xβ‚€), P z) β†’ (βˆ€ z ∈ Set.Ico (r ^ n * xβ‚€) (r ^ (n + 1) * xβ‚€), P z)) : βˆ€ x β‰₯ xβ‚€, P x := by suffices βˆ€ n : β„•, βˆ€ x ∈ Set.Ico xβ‚€ (r ^ (n + 1) * xβ‚€), P x by intro x hx have hx' : 0 < x / xβ‚€ := div_pos (hxβ‚€.trans_le hx) hxβ‚€ refine this ⌊logb r (x / xβ‚€)βŒ‹β‚Š x ?_ rw [mem_Ico, ← div_lt_iffβ‚€ hxβ‚€, ← rpow_natCast, ← logb_lt_iff_lt_rpow hr hx', Nat.cast_add, Nat.cast_one] exact ⟨hx, Nat.lt_floor_add_one _⟩ intro n induction n with | zero => simpa using base | succ n ih => exact fun x hx => (Ico_subset_Ico_union_Ico hx).elim (ih x) (step (n + 1) (by simp) ih _) end Induction
.lake/packages/mathlib/Mathlib/Analysis/SpecialFunctions/Log/ENNRealLog.lean
import Mathlib.Analysis.SpecialFunctions.Pow.NNReal import Mathlib.Data.EReal.Basic /-! # Extended Nonnegative Real Logarithm We define `log` as an extension of the logarithm of a positive real to the extended nonnegative reals `ℝβ‰₯0∞`. The function takes values in the extended reals `EReal`, with `log 0 = βŠ₯` and `log ⊀ = ⊀`. ## Main Definitions - `ENNReal.log`: The extension of the real logarithm to `ℝβ‰₯0∞`. ## Main Results - `ENNReal.log_strictMono`: `log` is increasing; - `ENNReal.log_injective`, `ENNReal.log_surjective`, `ENNReal.log_bijective`: `log` is injective, surjective, and bijective; - `ENNReal.log_mul_add`, `ENNReal.log_pow`, `ENNReal.log_rpow`: `log` satisfies the identities `log (x * y) = log x + log y` and `log (x ^ y) = y * log x` (with either `y ∈ β„•` or `y ∈ ℝ`). ## Tags ENNReal, EReal, logarithm -/ namespace ENNReal open scoped NNReal /-! ### Definition -/ section Definition /-- The logarithm function defined on the extended nonnegative reals `ℝβ‰₯0∞` to the extended reals `EReal`. Coincides with the usual logarithm function and with `Real.log` on positive reals, and takes values `log 0 = βŠ₯` and `log ⊀ = ⊀`. Conventions about multiplication in `ℝβ‰₯0∞` and addition in `EReal` make the identity `log (x * y) = log x + log y` unconditional. -/ noncomputable def log (x : ℝβ‰₯0∞) : EReal := if x = 0 then βŠ₯ else if x = ⊀ then ⊀ else Real.log x.toReal @[simp] lemma log_zero : log 0 = βŠ₯ := if_pos rfl @[simp] lemma log_one : log 1 = 0 := by simp [log] @[simp] lemma log_top : log ⊀ = ⊀ := rfl @[simp] lemma log_ofReal (x : ℝ) : log (ENNReal.ofReal x) = if x ≀ 0 then βŠ₯ else ↑(Real.log x) := by simp only [log, ENNReal.ofReal_ne_top, ENNReal.ofReal_eq_zero, if_false] split_ifs with h_nonpos Β· rfl Β· rw [ENNReal.toReal_ofReal (not_le.mp h_nonpos).le] lemma log_ofReal_of_pos {x : ℝ} (hx : 0 < x) : log (ENNReal.ofReal x) = Real.log x := by rw [log_ofReal, if_neg hx.not_ge] theorem log_pos_real {x : ℝβ‰₯0∞} (h : x β‰  0) (h' : x β‰  ⊀) : log x = Real.log (ENNReal.toReal x) := by simp [log, h, h'] theorem log_pos_real' {x : ℝβ‰₯0∞} (h : 0 < x.toReal) : log x = Real.log (ENNReal.toReal x) := by simp [log, (ENNReal.toReal_pos_iff.1 h).1.ne', (ENNReal.toReal_pos_iff.1 h).2.ne] theorem log_of_nnreal {x : ℝβ‰₯0} (h : x β‰  0) : log (x : ℝβ‰₯0∞) = Real.log x := by simp [log, h] end Definition /-! ### Monotonicity -/ section Monotonicity theorem log_strictMono : StrictMono log := by intro x y h unfold log split_ifs <;> simp_all [Real.log_lt_log, toReal_pos_iff, pos_iff_ne_zero, lt_top_iff_ne_top] theorem log_monotone : Monotone log := log_strictMono.monotone theorem log_injective : Function.Injective log := log_strictMono.injective theorem log_surjective : Function.Surjective log := by intro y cases y with | bot => use 0; simp | top => use ⊀; simp | coe y => use ENNReal.ofReal (Real.exp y); simp [Real.exp_pos] theorem log_bijective : Function.Bijective log := ⟨log_injective, log_surjective⟩ @[simp] theorem log_eq_iff {x y : ℝβ‰₯0∞} : log x = log y ↔ x = y := log_injective.eq_iff @[simp] theorem log_eq_bot_iff {x : ℝβ‰₯0∞} : log x = βŠ₯ ↔ x = 0 := log_zero β–Έ @log_eq_iff x 0 @[simp] theorem log_eq_one_iff {x : ℝβ‰₯0∞} : log x = 0 ↔ x = 1 := log_one β–Έ @log_eq_iff x 1 @[simp] theorem log_eq_top_iff {x : ℝβ‰₯0∞} : log x = ⊀ ↔ x = ⊀ := log_top β–Έ @log_eq_iff x ⊀ @[simp] lemma log_lt_log_iff {x y : ℝβ‰₯0∞} : log x < log y ↔ x < y := log_strictMono.lt_iff_lt @[simp] lemma bot_lt_log_iff {x : ℝβ‰₯0∞} : βŠ₯ < log x ↔ 0 < x := log_zero β–Έ @log_lt_log_iff 0 x @[simp] lemma log_lt_top_iff {x : ℝβ‰₯0∞} : log x < ⊀ ↔ x < ⊀ := log_top β–Έ @log_lt_log_iff x ⊀ @[simp] lemma log_lt_zero_iff {x : ℝβ‰₯0∞} : log x < 0 ↔ x < 1 := log_one β–Έ @log_lt_log_iff x 1 @[simp] lemma zero_lt_log_iff {x : ℝβ‰₯0∞} : 0 < log x ↔ 1 < x := log_one β–Έ @log_lt_log_iff 1 x @[simp] lemma log_le_log_iff {x y : ℝβ‰₯0∞} : log x ≀ log y ↔ x ≀ y := log_strictMono.le_iff_le @[simp] lemma log_le_zero_iff {x : ℝβ‰₯0∞} : log x ≀ 0 ↔ x ≀ 1 := log_one β–Έ @log_le_log_iff x 1 @[simp] lemma zero_le_log_iff {x : ℝβ‰₯0∞} : 0 ≀ log x ↔ 1 ≀ x := log_one β–Έ @log_le_log_iff 1 x @[gcongr] lemma log_le_log {x y : ℝβ‰₯0∞} (h : x ≀ y) : log x ≀ log y := log_monotone h @[gcongr] lemma log_lt_log {x y : ℝβ‰₯0∞} (h : x < y) : log x < log y := log_strictMono h end Monotonicity /-! ### Algebraic properties -/ section Morphism theorem log_mul_add {x y : ℝβ‰₯0∞} : log (x * y) = log x + log y := by rcases ENNReal.trichotomy x with (rfl | rfl | x_real) Β· simp Β· rw [log_top] rcases ENNReal.trichotomy y with (rfl | rfl | y_real) Β· rw [mul_zero, log_zero, EReal.add_bot] Β· simp Β· rw [log_pos_real' y_real, ENNReal.top_mul', EReal.top_add_coe, log_eq_top_iff] simp only [ite_eq_right_iff, zero_ne_top, imp_false] exact (ENNReal.toReal_pos_iff.1 y_real).1.ne' Β· rw [log_pos_real' x_real] rcases ENNReal.trichotomy y with (rfl | rfl | y_real) Β· simp Β· simp [(ENNReal.toReal_pos_iff.1 x_real).1.ne'] Β· rw_mod_cast [log_pos_real', log_pos_real' y_real, ENNReal.toReal_mul] Β· exact Real.log_mul x_real.ne' y_real.ne' rw [toReal_mul] positivity theorem log_rpow {x : ℝβ‰₯0∞} {y : ℝ} : log (x ^ y) = y * log x := by rcases lt_trichotomy y 0 with (y_neg | rfl | y_pos) Β· rcases ENNReal.trichotomy x with (rfl | rfl | x_real) Β· simp only [ENNReal.zero_rpow_def y, not_lt_of_gt y_neg, y_neg.ne, if_false, log_top, log_zero, EReal.coe_mul_bot_of_neg y_neg] Β· rw [ENNReal.top_rpow_of_neg y_neg, log_zero, log_top, EReal.coe_mul_top_of_neg y_neg] Β· have x_ne_zero := (ENNReal.toReal_pos_iff.1 x_real).1.ne' have x_ne_top := (ENNReal.toReal_pos_iff.1 x_real).2.ne simp only [log, rpow_eq_zero_iff, x_ne_zero, false_and, x_ne_top, or_self, ↓reduceIte, rpow_eq_top_iff] norm_cast exact ENNReal.toReal_rpow x y β–Έ Real.log_rpow x_real y Β· simp Β· rcases ENNReal.trichotomy x with (rfl | rfl | x_real) Β· rw [ENNReal.zero_rpow_of_pos y_pos, log_zero, EReal.mul_bot_of_pos]; norm_cast Β· rw [ENNReal.top_rpow_of_pos y_pos, log_top, EReal.mul_top_of_pos]; norm_cast Β· have x_ne_zero := (ENNReal.toReal_pos_iff.1 x_real).1.ne' have x_ne_top := (ENNReal.toReal_pos_iff.1 x_real).2.ne simp only [log, rpow_eq_zero_iff, x_ne_zero, false_and, x_ne_top, or_self, ↓reduceIte, rpow_eq_top_iff] norm_cast exact ENNReal.toReal_rpow x y β–Έ Real.log_rpow x_real y theorem log_pow {x : ℝβ‰₯0∞} {n : β„•} : log (x ^ n) = n * log x := by rw [← rpow_natCast, log_rpow, EReal.coe_natCast] lemma log_inv {x : ℝβ‰₯0∞} : log x⁻¹ = - log x := by simp [← rpow_neg_one, log_rpow] end Morphism end ENNReal
.lake/packages/mathlib/Mathlib/Analysis/SpecialFunctions/Log/Basic.lean
import Mathlib.Analysis.SpecialFunctions.Exp import Mathlib.Data.Nat.Factorization.Defs import Mathlib.Analysis.Normed.Module.RCLike.Real import Mathlib.Data.Rat.Cast.CharZero /-! # Real logarithm In this file we define `Real.log` to be the logarithm of a real number. As usual, we extend it from its domain `(0, +∞)` to a globally defined function. We choose to do it so that `log 0 = 0` and `log (-x) = log x`. We prove some basic properties of this function and show that it is continuous. ## Tags logarithm, continuity -/ open Set Filter Function open Topology noncomputable section namespace Real variable {x y : ℝ} /-- The real logarithm function, equal to the inverse of the exponential for `x > 0`, to `log |x|` for `x < 0`, and to `0` for `0`. We use this unconventional extension to `(-∞, 0]` as it gives the formula `log (x * y) = log x + log y` for all nonzero `x` and `y`, and the derivative of `log` is `1/x` away from `0`. -/ @[pp_nodot] noncomputable def log (x : ℝ) : ℝ := if hx : x = 0 then 0 else expOrderIso.symm ⟨|x|, abs_pos.2 hx⟩ theorem log_of_ne_zero (hx : x β‰  0) : log x = expOrderIso.symm ⟨|x|, abs_pos.2 hx⟩ := dif_neg hx theorem log_of_pos (hx : 0 < x) : log x = expOrderIso.symm ⟨x, hx⟩ := by rw [log_of_ne_zero hx.ne'] congr exact abs_of_pos hx theorem exp_log_eq_abs (hx : x β‰  0) : exp (log x) = |x| := by rw [log_of_ne_zero hx, ← coe_expOrderIso_apply, OrderIso.apply_symm_apply, Subtype.coe_mk] theorem exp_log (hx : 0 < x) : exp (log x) = x := by rw [exp_log_eq_abs hx.ne'] exact abs_of_pos hx theorem exp_log_of_neg (hx : x < 0) : exp (log x) = -x := by rw [exp_log_eq_abs (ne_of_lt hx)] exact abs_of_neg hx theorem le_exp_log (x : ℝ) : x ≀ exp (log x) := by by_cases h_zero : x = 0 Β· rw [h_zero, log, dif_pos rfl, exp_zero] exact zero_le_one Β· rw [exp_log_eq_abs h_zero] exact le_abs_self _ @[simp] theorem log_exp (x : ℝ) : log (exp x) = x := exp_injective <| exp_log (exp_pos x) theorem exp_one_mul_le_exp {x : ℝ} : exp 1 * x ≀ exp x := by by_cases hx0 : x ≀ 0 Β· apply le_trans (mul_nonpos_of_nonneg_of_nonpos (exp_pos 1).le hx0) (exp_nonneg x) Β· have h := add_one_le_exp (log x) rwa [← exp_le_exp, exp_add, exp_log (lt_of_not_ge hx0), mul_comm] at h theorem two_mul_le_exp {x : ℝ} : 2 * x ≀ exp x := by by_cases hx0 : x < 0 Β· exact le_trans (mul_nonpos_of_nonneg_of_nonpos (by simp only [Nat.ofNat_nonneg]) hx0.le) (exp_nonneg x) Β· apply le_trans (mul_le_mul_of_nonneg_right _ (le_of_not_gt hx0)) exp_one_mul_le_exp have := Real.add_one_le_exp 1 rwa [one_add_one_eq_two] at this theorem surjOn_log : SurjOn log (Ioi 0) univ := fun x _ => ⟨exp x, exp_pos x, log_exp x⟩ theorem log_surjective : Surjective log := fun x => ⟨exp x, log_exp x⟩ @[simp] theorem range_log : range log = univ := log_surjective.range_eq @[simp] theorem log_zero : log 0 = 0 := dif_pos rfl @[simp] theorem log_one : log 1 = 0 := exp_injective <| by rw [exp_log zero_lt_one, exp_zero] /-- This holds true for all `x : ℝ` because of the junk values `0 / 0 = 0` and `log 0 = 0`. -/ @[simp] lemma log_div_self (x : ℝ) : log (x / x) = 0 := by obtain rfl | hx := eq_or_ne x 0 <;> simp [*] @[simp] theorem log_abs (x : ℝ) : log |x| = log x := by by_cases h : x = 0 Β· simp [h] Β· rw [← exp_eq_exp, exp_log_eq_abs h, exp_log_eq_abs (abs_pos.2 h).ne', abs_abs] @[simp] theorem log_neg_eq_log (x : ℝ) : log (-x) = log x := by rw [← log_abs x, ← log_abs (-x), abs_neg] theorem sinh_log {x : ℝ} (hx : 0 < x) : sinh (log x) = (x - x⁻¹) / 2 := by rw [sinh_eq, exp_neg, exp_log hx] theorem cosh_log {x : ℝ} (hx : 0 < x) : cosh (log x) = (x + x⁻¹) / 2 := by rw [cosh_eq, exp_neg, exp_log hx] theorem surjOn_log' : SurjOn log (Iio 0) univ := fun x _ => ⟨-exp x, neg_lt_zero.2 <| exp_pos x, by rw [log_neg_eq_log, log_exp]⟩ theorem log_mul (hx : x β‰  0) (hy : y β‰  0) : log (x * y) = log x + log y := exp_injective <| by rw [exp_log_eq_abs (mul_ne_zero hx hy), exp_add, exp_log_eq_abs hx, exp_log_eq_abs hy, abs_mul] theorem log_div (hx : x β‰  0) (hy : y β‰  0) : log (x / y) = log x - log y := exp_injective <| by rw [exp_log_eq_abs (div_ne_zero hx hy), exp_sub, exp_log_eq_abs hx, exp_log_eq_abs hy, abs_div] @[simp] theorem log_inv (x : ℝ) : log x⁻¹ = -log x := by by_cases hx : x = 0; Β· simp [hx] rw [← exp_eq_exp, exp_log_eq_abs (inv_ne_zero hx), exp_neg, exp_log_eq_abs hx, abs_inv] theorem log_le_log_iff (h : 0 < x) (h₁ : 0 < y) : log x ≀ log y ↔ x ≀ y := by rw [← exp_le_exp, exp_log h, exp_log h₁] @[gcongr, bound] lemma log_le_log (hx : 0 < x) (hxy : x ≀ y) : log x ≀ log y := (log_le_log_iff hx (hx.trans_le hxy)).2 hxy @[gcongr, bound] theorem log_lt_log (hx : 0 < x) (h : x < y) : log x < log y := by rwa [← exp_lt_exp, exp_log hx, exp_log (lt_trans hx h)] theorem log_lt_log_iff (hx : 0 < x) (hy : 0 < y) : log x < log y ↔ x < y := by rw [← exp_lt_exp, exp_log hx, exp_log hy] theorem log_le_iff_le_exp (hx : 0 < x) : log x ≀ y ↔ x ≀ exp y := by rw [← exp_le_exp, exp_log hx] theorem log_lt_iff_lt_exp (hx : 0 < x) : log x < y ↔ x < exp y := by rw [← exp_lt_exp, exp_log hx] theorem le_log_iff_exp_le (hy : 0 < y) : x ≀ log y ↔ exp x ≀ y := by rw [← exp_le_exp, exp_log hy] theorem lt_log_iff_exp_lt (hy : 0 < y) : x < log y ↔ exp x < y := by rw [← exp_lt_exp, exp_log hy] theorem log_pos_iff (hx : 0 ≀ x) : 0 < log x ↔ 1 < x := by rcases hx.eq_or_lt with (rfl | hx) Β· simp [zero_le_one] rw [← log_one] exact log_lt_log_iff zero_lt_one hx @[bound] theorem log_pos (hx : 1 < x) : 0 < log x := (log_pos_iff (lt_trans zero_lt_one hx).le).2 hx theorem log_pos_of_lt_neg_one (hx : x < -1) : 0 < log x := by rw [← neg_neg x, log_neg_eq_log] have : 1 < -x := by linarith exact log_pos this theorem log_neg_iff (h : 0 < x) : log x < 0 ↔ x < 1 := by rw [← log_one] exact log_lt_log_iff h zero_lt_one @[bound] theorem log_neg (h0 : 0 < x) (h1 : x < 1) : log x < 0 := (log_neg_iff h0).2 h1 theorem log_neg_of_lt_zero (h0 : x < 0) (h1 : -1 < x) : log x < 0 := by rw [← neg_neg x, log_neg_eq_log] have h0' : 0 < -x := by linarith have h1' : -x < 1 := by linarith exact log_neg h0' h1' theorem log_nonneg_iff (hx : 0 < x) : 0 ≀ log x ↔ 1 ≀ x := by rw [← not_lt, log_neg_iff hx, not_lt] @[bound] theorem log_nonneg (hx : 1 ≀ x) : 0 ≀ log x := (log_nonneg_iff (zero_lt_one.trans_le hx)).2 hx theorem log_nonpos_iff (hx : 0 ≀ x) : log x ≀ 0 ↔ x ≀ 1 := by rcases hx.eq_or_lt with (rfl | hx) Β· simp [le_refl, zero_le_one] rw [← not_lt, log_pos_iff hx.le, not_lt] @[bound] theorem log_nonpos (hx : 0 ≀ x) (h'x : x ≀ 1) : log x ≀ 0 := (log_nonpos_iff hx).2 h'x theorem log_natCast_nonneg (n : β„•) : 0 ≀ log n := by if hn : n = 0 then simp [hn] else have : (1 : ℝ) ≀ n := mod_cast Nat.one_le_of_lt <| Nat.pos_of_ne_zero hn exact log_nonneg this theorem log_neg_natCast_nonneg (n : β„•) : 0 ≀ log (-n) := by rw [← log_neg_eq_log, neg_neg] exact log_natCast_nonneg _ theorem log_intCast_nonneg (n : β„€) : 0 ≀ log n := by cases lt_trichotomy 0 n with | inl hn => have : (1 : ℝ) ≀ n := mod_cast hn exact log_nonneg this | inr hn => cases hn with | inl hn => simp [hn.symm] | inr hn => have : (1 : ℝ) ≀ -n := by rw [← neg_zero, ← lt_neg] at hn; exact mod_cast hn rw [← log_neg_eq_log] exact log_nonneg this theorem strictMonoOn_log : StrictMonoOn log (Set.Ioi 0) := fun _ hx _ _ hxy => log_lt_log hx hxy theorem strictAntiOn_log : StrictAntiOn log (Set.Iio 0) := by rintro x (hx : x < 0) y (hy : y < 0) hxy rw [← log_abs y, ← log_abs x] refine log_lt_log (abs_pos.2 hy.ne) ?_ rwa [abs_of_neg hy, abs_of_neg hx, neg_lt_neg_iff] theorem log_injOn_pos : Set.InjOn log (Set.Ioi 0) := strictMonoOn_log.injOn theorem log_lt_sub_one_of_pos (hx1 : 0 < x) (hx2 : x β‰  1) : log x < x - 1 := by have h : log x β‰  0 := by rwa [← log_one, log_injOn_pos.ne_iff hx1] exact mem_Ioi.mpr zero_lt_one linarith [add_one_lt_exp h, exp_log hx1] theorem eq_one_of_pos_of_log_eq_zero {x : ℝ} (h₁ : 0 < x) (hβ‚‚ : log x = 0) : x = 1 := log_injOn_pos (Set.mem_Ioi.2 h₁) (Set.mem_Ioi.2 zero_lt_one) (hβ‚‚.trans Real.log_one.symm) theorem log_ne_zero_of_pos_of_ne_one {x : ℝ} (hx_pos : 0 < x) (hx : x β‰  1) : log x β‰  0 := mt (eq_one_of_pos_of_log_eq_zero hx_pos) hx @[simp] theorem log_eq_zero {x : ℝ} : log x = 0 ↔ x = 0 ∨ x = 1 ∨ x = -1 := by constructor Β· intro h rcases lt_trichotomy x 0 with (x_lt_zero | rfl | x_gt_zero) Β· refine Or.inr (Or.inr (neg_eq_iff_eq_neg.mp ?_)) rw [← log_neg_eq_log x] at h exact eq_one_of_pos_of_log_eq_zero (neg_pos.mpr x_lt_zero) h Β· exact Or.inl rfl Β· exact Or.inr (Or.inl (eq_one_of_pos_of_log_eq_zero x_gt_zero h)) Β· rintro (rfl | rfl | rfl) <;> simp only [log_one, log_zero, log_neg_eq_log] theorem log_ne_zero {x : ℝ} : log x β‰  0 ↔ x β‰  0 ∧ x β‰  1 ∧ x β‰  -1 := by simpa only [not_or] using log_eq_zero.not @[simp] theorem log_pow (x : ℝ) (n : β„•) : log (x ^ n) = n * log x := by induction n with | zero => simp | succ n ih => rcases eq_or_ne x 0 with (rfl | hx) Β· simp Β· rw [pow_succ, log_mul (pow_ne_zero _ hx) hx, ih, Nat.cast_succ, add_mul, one_mul] @[simp] theorem log_zpow (x : ℝ) (n : β„€) : log (x ^ n) = n * log x := by cases n Β· rw [Int.ofNat_eq_coe, zpow_natCast, log_pow, Int.cast_natCast] Β· rw [zpow_negSucc, log_inv, log_pow, Int.cast_negSucc, Nat.cast_add_one, neg_mul_eq_neg_mul] theorem log_sqrt {x : ℝ} (hx : 0 ≀ x) : log (√x) = log x / 2 := by rw [eq_div_iff, mul_comm, ← Nat.cast_two, ← log_pow, sq_sqrt hx] exact two_ne_zero theorem log_le_sub_one_of_pos {x : ℝ} (hx : 0 < x) : log x ≀ x - 1 := by rw [le_sub_iff_add_le] convert add_one_le_exp (log x) rw [exp_log hx] lemma one_sub_inv_le_log_of_pos (hx : 0 < x) : 1 - x⁻¹ ≀ log x := by simpa [add_comm] using log_le_sub_one_of_pos (inv_pos.2 hx) /-- See `Real.log_le_sub_one_of_pos` for the stronger version when `x β‰  0`. -/ lemma log_le_self (hx : 0 ≀ x) : log x ≀ x := by obtain rfl | hx := hx.eq_or_lt Β· simp Β· exact (log_le_sub_one_of_pos hx).trans (by linarith) /-- See `Real.one_sub_inv_le_log_of_pos` for the stronger version when `x β‰  0`. -/ lemma neg_inv_le_log (hx : 0 ≀ x) : -x⁻¹ ≀ log x := by rw [neg_le, ← log_inv]; exact log_le_self <| inv_nonneg.2 hx /-- Bound for `|log x * x|` in the interval `(0, 1]`. -/ theorem abs_log_mul_self_lt (x : ℝ) (h1 : 0 < x) (h2 : x ≀ 1) : |log x * x| < 1 := by have : 0 < 1 / x := by simpa only [one_div, inv_pos] using h1 replace := log_le_sub_one_of_pos this replace : log (1 / x) < 1 / x := by linarith rw [log_div one_ne_zero h1.ne', log_one, zero_sub, lt_div_iffβ‚€ h1] at this have aux : 0 ≀ -log x * x := by refine mul_nonneg ?_ h1.le rw [← log_inv] apply log_nonneg rw [← le_inv_commβ‚€ h1 zero_lt_one, inv_one] exact h2 rw [← abs_of_nonneg aux, neg_mul, abs_neg] at this exact this /-- The real logarithm function tends to `+∞` at `+∞`. -/ theorem tendsto_log_atTop : Tendsto log atTop atTop := tendsto_comp_exp_atTop.1 <| by simpa only [log_exp] using tendsto_id lemma tendsto_log_nhdsGT_zero : Tendsto log (𝓝[>] 0) atBot := by simpa [← tendsto_comp_exp_atBot] using tendsto_id theorem tendsto_log_nhdsNE_zero : Tendsto log (𝓝[β‰ ] 0) atBot := by simpa [comp_def] using tendsto_log_nhdsGT_zero.comp tendsto_abs_nhdsNE_zero lemma tendsto_log_nhdsLT_zero : Tendsto log (𝓝[<] 0) atBot := tendsto_log_nhdsNE_zero.mono_left <| nhdsWithin_mono _ fun _ h ↦ ne_of_lt h theorem continuousOn_log : ContinuousOn log {0}ᢜ := by simp +unfoldPartialApp only [continuousOn_iff_continuous_restrict, restrict] conv in log _ => rw [log_of_ne_zero (show (x : ℝ) β‰  0 from x.2)] exact expOrderIso.symm.continuous.comp (continuous_subtype_val.norm.subtype_mk _) /-- The real logarithm is continuous as a function from nonzero reals. -/ @[fun_prop] theorem continuous_log : Continuous fun x : { x : ℝ // x β‰  0 } => log x := continuousOn_iff_continuous_restrict.1 <| continuousOn_log.mono fun _ => id /-- The real logarithm is continuous as a function from positive reals. -/ @[fun_prop] theorem continuous_log' : Continuous fun x : { x : ℝ // 0 < x } => log x := continuousOn_iff_continuous_restrict.1 <| continuousOn_log.mono fun _ hx => ne_of_gt hx theorem continuousAt_log (hx : x β‰  0) : ContinuousAt log x := (continuousOn_log x hx).continuousAt <| isOpen_compl_singleton.mem_nhds hx @[simp] theorem continuousAt_log_iff : ContinuousAt log x ↔ x β‰  0 := by refine ⟨?_, continuousAt_log⟩ rintro h rfl exact not_tendsto_nhds_of_tendsto_atBot tendsto_log_nhdsNE_zero _ <| h.tendsto.mono_left nhdsWithin_le_nhds open List in lemma log_list_prod {l : List ℝ} (h : βˆ€ x ∈ l, x β‰  0) : log l.prod = (l.map (fun x ↦ log x)).sum := by induction l with | nil => simp | cons a l ih => simp_all only [ne_eq, mem_cons, or_true, not_false_eq_true, forall_const, forall_eq_or_imp, prod_cons, map_cons, sum_cons] have : l.prod β‰  0 := by grind [prod_ne_zero] rw [log_mul h.1 this, add_right_inj, ih] open Multiset in lemma log_multiset_prod {s : Multiset ℝ} (h : βˆ€ x ∈ s, x β‰  0) : log s.prod = (s.map (fun x ↦ log x)).sum := by rw [← prod_toList, log_list_prod (by simp_all), sum_map_toList] open Finset in theorem log_prod {Ξ± : Type*} {s : Finset Ξ±} {f : Ξ± β†’ ℝ} (hf : βˆ€ x ∈ s, f x β‰  0) : log (∏ i ∈ s, f i) = βˆ‘ i ∈ s, log (f i) := by rw [← prod_map_toList, log_list_prod (by simp_all)] simp protected theorem _root_.Finsupp.log_prod {Ξ± Ξ² : Type*} [Zero Ξ²] (f : Ξ± β†’β‚€ Ξ²) (g : Ξ± β†’ Ξ² β†’ ℝ) (hg : βˆ€ a, g a (f a) = 0 β†’ f a = 0) : log (f.prod g) = f.sum fun a b ↦ log (g a b) := log_prod fun _x hx hβ‚€ ↦ Finsupp.mem_support_iff.1 hx <| hg _ hβ‚€ theorem log_nat_eq_sum_factorization (n : β„•) : log n = n.factorization.sum fun p t => t * log p := by rcases eq_or_ne n 0 with (rfl | hn) Β· simp -- relies on junk values of `log` and `Nat.factorization` Β· simp only [← log_pow, ← Nat.cast_pow] rw [← Finsupp.log_prod, ← Nat.cast_finsuppProd, Nat.factorization_prod_pow_eq_self hn] intro p hp rw [eq_zero_of_pow_eq_zero (Nat.cast_eq_zero.1 hp), Nat.factorization_zero_right] theorem tendsto_pow_log_div_mul_add_atTop (a b : ℝ) (n : β„•) (ha : a β‰  0) : Tendsto (fun x => log x ^ n / (a * x + b)) atTop (𝓝 0) := ((tendsto_div_pow_mul_exp_add_atTop a b n ha.symm).comp tendsto_log_atTop).congr' <| by filter_upwards [eventually_gt_atTop (0 : ℝ)] with x hx using by simp [exp_log hx] theorem isLittleO_pow_log_id_atTop {n : β„•} : (fun x => log x ^ n) =o[atTop] id := by rw [Asymptotics.isLittleO_iff_tendsto'] Β· simpa using tendsto_pow_log_div_mul_add_atTop 1 0 n one_ne_zero filter_upwards [eventually_ne_atTop (0 : ℝ)] with x h₁ hβ‚‚ using (h₁ hβ‚‚).elim theorem isLittleO_log_id_atTop : log =o[atTop] id := isLittleO_pow_log_id_atTop.congr_left fun _ => pow_one _ theorem isLittleO_const_log_atTop {c : ℝ} : (fun _ => c) =o[atTop] log := by refine Asymptotics.isLittleO_of_tendsto' ?_ <| Tendsto.div_atTop (a := c) (by simp) tendsto_log_atTop filter_upwards [eventually_gt_atTop 1] with x hx aesop (add safe forward log_pos) /-- `Real.exp` as an `OpenPartialHomeomorph` with `source = univ` and `target = {z | 0 < z}`. -/ @[simps] noncomputable def expPartialHomeomorph : OpenPartialHomeomorph ℝ ℝ where toFun := Real.exp invFun := Real.log source := univ target := Ioi (0 : ℝ) map_source' x _ := exp_pos x map_target' _ _ := mem_univ _ left_inv' _ _ := by simp right_inv' _ hx := exp_log hx open_source := isOpen_univ open_target := isOpen_Ioi continuousOn_toFun := continuousOn_exp continuousOn_invFun x hx := (continuousAt_log (ne_of_gt hx)).continuousWithinAt end Real section Continuity open Real variable {Ξ± : Type*} theorem Filter.Tendsto.log {f : Ξ± β†’ ℝ} {l : Filter Ξ±} {x : ℝ} (h : Tendsto f l (𝓝 x)) (hx : x β‰  0) : Tendsto (fun x => log (f x)) l (𝓝 (log x)) := (continuousAt_log hx).tendsto.comp h variable [TopologicalSpace Ξ±] {f : Ξ± β†’ ℝ} {s : Set Ξ±} {a : Ξ±} @[fun_prop] theorem Continuous.log (hf : Continuous f) (hβ‚€ : βˆ€ x, f x β‰  0) : Continuous fun x => log (f x) := continuousOn_log.comp_continuous hf hβ‚€ @[fun_prop] nonrec theorem ContinuousAt.log (hf : ContinuousAt f a) (hβ‚€ : f a β‰  0) : ContinuousAt (fun x => log (f x)) a := hf.log hβ‚€ nonrec theorem ContinuousWithinAt.log (hf : ContinuousWithinAt f s a) (hβ‚€ : f a β‰  0) : ContinuousWithinAt (fun x => log (f x)) s a := hf.log hβ‚€ @[fun_prop] theorem ContinuousOn.log (hf : ContinuousOn f s) (hβ‚€ : βˆ€ x ∈ s, f x β‰  0) : ContinuousOn (fun x => log (f x)) s := fun x hx => (hf x hx).log (hβ‚€ x hx) end Continuity section TendstoCompAddSub open Filter namespace Real theorem tendsto_log_comp_add_sub_log (y : ℝ) : Tendsto (fun x : ℝ => log (x + y) - log x) atTop (𝓝 0) := by have : Tendsto (fun x ↦ 1 + y / x) atTop (𝓝 (1 + 0)) := tendsto_const_nhds.add (tendsto_const_nhds.div_atTop tendsto_id) rw [← comap_exp_nhds_exp, exp_zero, tendsto_comap_iff, ← add_zero (1 : ℝ)] refine this.congr' ?_ filter_upwards [eventually_gt_atTop (0 : ℝ), eventually_gt_atTop (-y)] with x hxβ‚€ hxy rw [comp_apply, exp_sub, exp_log, exp_log, one_add_div] <;> linarith theorem tendsto_log_nat_add_one_sub_log : Tendsto (fun k : β„• => log (k + 1) - log k) atTop (𝓝 0) := (tendsto_log_comp_add_sub_log 1).comp tendsto_natCast_atTop_atTop end Real end TendstoCompAddSub namespace Mathlib.Meta.Positivity open Lean.Meta Qq variable {e : ℝ} {d : β„•} lemma log_nonneg_of_isNat {n : β„•} (h : NormNum.IsNat e n) : 0 ≀ Real.log (e : ℝ) := by rw [NormNum.IsNat.to_eq h rfl] exact Real.log_natCast_nonneg _ lemma log_pos_of_isNat {n : β„•} (h : NormNum.IsNat e n) (w : Nat.blt 1 n = true) : 0 < Real.log (e : ℝ) := by rw [NormNum.IsNat.to_eq h rfl] apply Real.log_pos simpa using w lemma log_nonneg_of_isNegNat {n : β„•} (h : NormNum.IsInt e (.negOfNat n)) : 0 ≀ Real.log (e : ℝ) := by rw [NormNum.IsInt.neg_to_eq h rfl] exact Real.log_neg_natCast_nonneg _ lemma log_pos_of_isNegNat {n : β„•} (h : NormNum.IsInt e (.negOfNat n)) (w : Nat.blt 1 n = true) : 0 < Real.log (e : ℝ) := by rw [NormNum.IsInt.neg_to_eq h rfl] rw [Real.log_neg_eq_log] apply Real.log_pos simpa using w lemma log_pos_of_isNNRat {n : β„•} : (NormNum.IsNNRat e n d) β†’ (decide ((1 : β„š) < n / d)) β†’ (0 < Real.log (e : ℝ)) | ⟨inv, eq⟩, h => by rw [eq, invOf_eq_inv, ← div_eq_mul_inv] have : 1 < (n : ℝ) / d := by simpa using (Rat.cast_lt (K := ℝ)).2 (of_decide_eq_true h) exact Real.log_pos this lemma log_pos_of_isRat_neg {n : β„€} : (NormNum.IsRat e n d) β†’ (decide (n / d < (-1 : β„š))) β†’ (0 < Real.log (e : ℝ)) | ⟨inv, eq⟩, h => by rw [eq, invOf_eq_inv, ← div_eq_mul_inv] have : (n : ℝ) / d < -1 := by exact_mod_cast of_decide_eq_true h exact Real.log_pos_of_lt_neg_one this lemma log_nz_of_isNNRat {n : β„•} : (NormNum.IsNNRat e n d) β†’ (decide ((0 : β„š) < n / d)) β†’ (decide (n / d < (1 : β„š))) β†’ (Real.log (e : ℝ) β‰  0) | ⟨inv, eq⟩, h₁, hβ‚‚ => by rw [eq, invOf_eq_inv, ← div_eq_mul_inv] have h₁' : 0 < (n : ℝ) / d := by simpa using (Rat.cast_pos (K := ℝ)).2 (of_decide_eq_true h₁) have hβ‚‚' : (n : ℝ) / d < 1 := by simpa using (Rat.cast_lt (K := ℝ)).2 (of_decide_eq_true hβ‚‚) exact ne_of_lt <| Real.log_neg h₁' hβ‚‚' lemma log_nz_of_isRat_neg {n : β„€} : (NormNum.IsRat e n d) β†’ (decide (n / d < (0 : β„š))) β†’ (decide ((-1 : β„š) < n / d)) β†’ (Real.log (e : ℝ) β‰  0) | ⟨inv, eq⟩, h₁, hβ‚‚ => by rw [eq, invOf_eq_inv, ← div_eq_mul_inv] have h₁' : (n : ℝ) / d < 0 := by exact_mod_cast of_decide_eq_true h₁ have hβ‚‚' : -1 < (n : ℝ) / d := by exact_mod_cast of_decide_eq_true hβ‚‚ exact ne_of_lt <| Real.log_neg_of_lt_zero h₁' hβ‚‚' /-- Extension for the `positivity` tactic: `Real.log` of a natural number is always nonnegative. -/ @[positivity Real.log (Nat.cast _)] def evalLogNatCast : PositivityExt where eval {u Ξ±} _zΞ± _pΞ± e := do match u, Ξ±, e with | 0, ~q(ℝ), ~q(Real.log (Nat.cast $a)) => assertInstancesCommute pure (.nonnegative q(Real.log_natCast_nonneg $a)) | _, _, _ => throwError "not Real.log" /-- Extension for the `positivity` tactic: `Real.log` of an integer is always nonnegative. -/ @[positivity Real.log (Int.cast _)] def evalLogIntCast : PositivityExt where eval {u Ξ±} _zΞ± _pΞ± e := do match u, Ξ±, e with | 0, ~q(ℝ), ~q(Real.log (Int.cast $a)) => assertInstancesCommute pure (.nonnegative q(Real.log_intCast_nonneg $a)) | _, _, _ => throwError "not Real.log" /-- Extension for the `positivity` tactic: `Real.log` of a numeric literal. -/ @[positivity Real.log _] def evalLogNatLit : PositivityExt where eval {u Ξ±} _ _ e := do match u, Ξ±, e with | 0, ~q(ℝ), ~q(Real.log $a) => match ← NormNum.derive a with | .isNat (_ : Q(AddMonoidWithOne ℝ)) lit p => assumeInstancesCommute have p : Q(NormNum.IsNat $a $lit) := p if 1 < lit.natLit! then let p' : Q(Nat.blt 1 $lit = true) := (q(Eq.refl true) : Lean.Expr) pure (.positive q(log_pos_of_isNat $p $p')) else pure (.nonnegative q(log_nonneg_of_isNat $p)) | .isNegNat _ lit p => assumeInstancesCommute have p : Q(NormNum.IsInt $a (Int.negOfNat $lit)) := p if 1 < lit.natLit! then let p' : Q(Nat.blt 1 $lit = true) := (q(Eq.refl true) : Lean.Expr) pure (.positive q(log_pos_of_isNegNat $p $p')) else pure (.nonnegative q(log_nonneg_of_isNegNat $p)) | .isNNRat _ q n d p => assumeInstancesCommute if q < 1 then let w₁ : Q(decide ((0 : β„š) < $n / $d) = true) := (q(Eq.refl true) : Lean.Expr) let wβ‚‚ : Q(decide ($n / $d < (1 : β„š)) = true) := (q(Eq.refl true) : Lean.Expr) pure (.nonzero q(log_nz_of_isNNRat $p $w₁ $wβ‚‚)) else if 1 < q then let w : Q(decide ((1 : β„š) < $n / $d) = true) := (q(Eq.refl true) : Lean.Expr) pure (.positive q(log_pos_of_isNNRat $p $w)) else failure | .isNegNNRat _ q n d p => assumeInstancesCommute if -1 < q then let w₁ : Q(decide ((Int.negOfNat $n) / $d < (0 : β„š)) = true) := (q(Eq.refl true) : Lean.Expr) let wβ‚‚ : Q(decide ((-1 : β„š) < (Int.negOfNat $n) / $d) = true) := (q(Eq.refl true) : Lean.Expr) pure (.nonzero q(log_nz_of_isRat_neg $p $w₁ $wβ‚‚)) else if q < -1 then let w : Q(decide ((Int.negOfNat $n) / $d < (-1 : β„š)) = true) := (q(Eq.refl true) : Lean.Expr) pure (.positive q(log_pos_of_isRat_neg $p $w)) else failure | _ => failure | _, _, _ => throwError "not Real.log" end Mathlib.Meta.Positivity
.lake/packages/mathlib/Mathlib/Analysis/SpecialFunctions/Log/ENNRealLogExp.lean
import Mathlib.Analysis.SpecialFunctions.Log.ERealExp import Mathlib.Analysis.SpecialFunctions.Log.ENNRealLog import Mathlib.MeasureTheory.Constructions.BorelSpace.Basic import Mathlib.Topology.MetricSpace.Polish /-! # Properties of the extended logarithm and exponential We prove that `log` and `exp` define order isomorphisms between `ℝβ‰₯0∞` and `EReal`. ## Main DefinitionsP - `ENNReal.logOrderIso`: The order isomorphism between `ℝβ‰₯0∞` and `EReal` defined by `log` and `exp`. - `EReal.expOrderIso`: The order isomorphism between `EReal` and `ℝβ‰₯0∞` defined by `exp` and `log`. - `ENNReal.logHomeomorph`: `log` as a homeomorphism. - `EReal.expHomeomorph`: `exp` as a homeomorphism. ## Main Results - `EReal.log_exp`, `ENNReal.exp_log`: `log` and `exp` are inverses of each other. - `EReal.exp_nmul`, `EReal.exp_mul`: `exp` satisfies the identities `exp (n * x) = (exp x) ^ n` and `exp (x * y) = (exp x) ^ y`. - `EReal` is a Polish space. ## Tags ENNReal, EReal, logarithm, exponential -/ open EReal ENNReal Topology section LogExp @[simp] lemma EReal.log_exp (x : EReal) : log (exp x) = x := by induction x Β· simp Β· rw [exp_coe, log_ofReal, if_neg (not_le.mpr (Real.exp_pos _)), Real.log_exp] Β· simp @[simp] lemma ENNReal.exp_log (x : ℝβ‰₯0∞) : exp (log x) = x := by by_cases hx_top : x = ∞ Β· simp [hx_top] by_cases hx_zero : x = 0 Β· simp [hx_zero] have hx_pos : 0 < x.toReal := ENNReal.toReal_pos hx_zero hx_top rw [← ENNReal.ofReal_toReal hx_top, log_ofReal_of_pos hx_pos, exp_coe, Real.exp_log hx_pos] end LogExp section Exp namespace EReal lemma exp_nmul (x : EReal) (n : β„•) : exp (n * x) = (exp x) ^ n := by simp_rw [← log_eq_iff, log_pow, log_exp] lemma exp_mul (x : EReal) (y : ℝ) : exp (x * y) = (exp x) ^ y := by rw [← log_eq_iff, log_rpow, log_exp, log_exp, mul_comm] lemma ENNReal.rpow_eq_exp_mul_log (x : ℝβ‰₯0∞) (y : ℝ) : x ^ y = exp (y * log x) := by rw [mul_comm, EReal.exp_mul, exp_log] end EReal end Exp namespace ENNReal section OrderIso /-- `ENNReal.log` and its inverse `EReal.exp` are an order isomorphism between `ℝβ‰₯0∞` and `EReal`. -/ noncomputable def logOrderIso : ℝβ‰₯0∞ ≃o EReal where toFun := log invFun := exp left_inv x := exp_log x right_inv x := log_exp x map_rel_iff' := by simp only [Equiv.coe_fn_mk, log_le_log_iff, forall_const] @[simp] lemma logOrderIso_apply (x : ℝβ‰₯0∞) : logOrderIso x = log x := rfl /-- `EReal.exp` and its inverse `ENNReal.log` are an order isomorphism between `EReal` and `ℝβ‰₯0∞`. -/ noncomputable def _root_.EReal.expOrderIso := logOrderIso.symm @[simp] lemma _root_.EReal.expOrderIso_apply (x : EReal) : expOrderIso x = exp x := rfl @[simp] lemma logOrderIso_symm : logOrderIso.symm = expOrderIso := rfl @[simp] lemma _root_.EReal.expOrderIso_symm : expOrderIso.symm = logOrderIso := rfl end OrderIso section Continuity /-- `log` as a homeomorphism. -/ noncomputable def logHomeomorph : ℝβ‰₯0∞ β‰ƒβ‚œ EReal := logOrderIso.toHomeomorph @[simp] lemma logHomeomorph_apply (x : ℝβ‰₯0∞) : logHomeomorph x = log x := rfl /-- `exp` as a homeomorphism. -/ noncomputable def _root_.EReal.expHomeomorph : EReal β‰ƒβ‚œ ℝβ‰₯0∞ := expOrderIso.toHomeomorph @[simp] lemma _root_.EReal.expHomeomorph_apply (x : EReal) : expHomeomorph x = exp x := rfl @[simp] lemma logHomeomorph_symm : logHomeomorph.symm = expHomeomorph := rfl @[simp] lemma _root_.EReal.expHomeomorph_symm : expHomeomorph.symm = logHomeomorph := rfl @[continuity, fun_prop] lemma continuous_log : Continuous log := logOrderIso.continuous @[continuity, fun_prop] lemma continuous_exp : Continuous exp := expOrderIso.continuous lemma _root_.EReal.tendsto_exp_nhds_top_nhds_top : Filter.Tendsto exp (𝓝 ⊀) (𝓝 ⊀) := continuous_exp.tendsto ⊀ lemma _root_.EReal.tendsto_exp_nhds_zero_nhds_one : Filter.Tendsto exp (𝓝 0) (𝓝 1) := by convert continuous_exp.tendsto 0 simp lemma _root_.EReal.tendsto_exp_nhds_bot_nhds_zero : Filter.Tendsto exp (𝓝 βŠ₯) (𝓝 0) := continuous_exp.tendsto βŠ₯ lemma tendsto_rpow_atTop_of_one_lt_base {b : ℝβ‰₯0∞} (hb : 1 < b) : Filter.Tendsto (b ^ Β· : ℝ β†’ ℝβ‰₯0∞) Filter.atTop (𝓝 ⊀) := by simp_rw [ENNReal.rpow_eq_exp_mul_log] refine EReal.tendsto_exp_nhds_top_nhds_top.comp ?_ convert EReal.Tendsto.mul_const tendsto_coe_atTop _ _ Β· rw [EReal.top_mul_of_pos (zero_lt_log_iff.2 hb)] all_goals simp lemma tendsto_rpow_atTop_of_base_lt_one {b : ℝβ‰₯0∞} (hb : b < 1) : Filter.Tendsto (b ^ Β· : ℝ β†’ ℝβ‰₯0∞) Filter.atTop (𝓝 0) := by simp_rw [ENNReal.rpow_eq_exp_mul_log] refine EReal.tendsto_exp_nhds_bot_nhds_zero.comp ?_ convert EReal.Tendsto.mul_const tendsto_coe_atTop _ _ Β· rw [EReal.top_mul_of_neg (log_lt_zero_iff.2 hb)] all_goals simp lemma tendsto_rpow_atBot_of_one_lt_base {b : ℝβ‰₯0∞} (hb : 1 < b) : Filter.Tendsto (b ^ Β· : ℝ β†’ ℝβ‰₯0∞) Filter.atBot (𝓝 0) := by simp_rw [ENNReal.rpow_eq_exp_mul_log] refine EReal.tendsto_exp_nhds_bot_nhds_zero.comp ?_ convert EReal.Tendsto.mul_const tendsto_coe_atBot _ _ Β· rw [EReal.bot_mul_of_pos (zero_lt_log_iff.2 hb)] all_goals simp lemma tendsto_rpow_atBot_of_base_lt_one {b : ℝβ‰₯0∞} (hb : b < 1) : Filter.Tendsto (b ^ Β· : ℝ β†’ ℝβ‰₯0∞) Filter.atBot (𝓝 ⊀) := by simp_rw [ENNReal.rpow_eq_exp_mul_log] refine EReal.tendsto_exp_nhds_top_nhds_top.comp ?_ convert EReal.Tendsto.mul_const tendsto_coe_atBot _ _ Β· rw [EReal.bot_mul_of_neg (log_lt_zero_iff.2 hb)] all_goals simp end Continuity section Measurability @[measurability, fun_prop] lemma measurable_log : Measurable log := continuous_log.measurable @[measurability, fun_prop] lemma _root_.EReal.measurable_exp : Measurable exp := continuous_exp.measurable @[measurability, fun_prop] lemma _root_.Measurable.ennreal_log {Ξ± : Type*} {_ : MeasurableSpace Ξ±} {f : Ξ± β†’ ℝβ‰₯0∞} (hf : Measurable f) : Measurable fun x ↦ log (f x) := measurable_log.comp hf @[measurability, fun_prop] lemma _root_.Measurable.ereal_exp {Ξ± : Type*} {_ : MeasurableSpace Ξ±} {f : Ξ± β†’ EReal} (hf : Measurable f) : Measurable fun x ↦ exp (f x) := measurable_exp.comp hf end Measurability end ENNReal instance : PolishSpace EReal := ENNReal.logOrderIso.symm.toHomeomorph.isClosedEmbedding.polishSpace
.lake/packages/mathlib/Mathlib/Analysis/SpecialFunctions/Log/PosLog.lean
import Mathlib.Analysis.SpecialFunctions.Log.Basic /-! # The Positive Part of the Logarithm This file defines the function `Real.posLog = r ↦ max 0 (log r)` and introduces the notation `log⁺`. For a finite length-`n` sequence `f i` of reals, it establishes the following standard estimates. - `theorem posLog_prod : log⁺ (∏ i, f i) ≀ βˆ‘ i, log⁺ (f i)` - `theorem posLog_sum : log⁺ (βˆ‘ i, f i) ≀ log n + βˆ‘ i, log⁺ (f i)` See `Mathlib/Analysis/SpecialFunctions/Integrals/PosLogEqCircleAverage.lean` for the presentation of `log⁺` as a Circle Average. -/ namespace Real variable {x y : ℝ} /-! ## Definition, Notation and Reformulations -/ /-- Definition: the positive part of the logarithm. -/ noncomputable def posLog : ℝ β†’ ℝ := fun r ↦ max 0 (log r) /-- Notation `log⁺` for the positive part of the logarithm. -/ scoped notation "log⁺" => posLog /-- Definition of the positive part of the logarithm, formulated as a theorem. -/ theorem posLog_def : log⁺ x = max 0 (log x) := rfl /-! ## Elementary Properties -/ /-- Presentation of `log` in terms of its positive part. -/ theorem posLog_sub_posLog_inv : log⁺ x - log⁺ x⁻¹ = log x := by rw [posLog_def, posLog_def, log_inv] by_cases! h : 0 ≀ log x Β· simp [h] Β· simp [neg_nonneg.1 (Left.nonneg_neg_iff.2 h.le)] /-- Presentation of `log⁺` in terms of `log`. -/ theorem half_mul_log_add_log_abs : 2⁻¹ * (log x + |log x|) = log⁺ x := by by_cases! hr : 0 ≀ log x Β· simp [posLog, hr, abs_of_nonneg] ring Β· simp [posLog, hr.le, abs_of_nonpos] @[simp] lemma posLog_zero : log⁺ 0 = 0 := by simp [posLog] @[simp] lemma posLog_one : log⁺ 1 = 0 := by simp [posLog] /-- The positive part of `log` is never negative. -/ theorem posLog_nonneg : 0 ≀ log⁺ x := by simp [posLog] /-- The function `log⁺` is even. -/ @[simp] theorem posLog_neg (x : ℝ) : log⁺ (-x) = log⁺ x := by simp [posLog] /-- The function `log⁺` is even. -/ @[simp] theorem posLog_abs (x : ℝ) : log⁺ |x| = log⁺ x := by simp [posLog] /-- The function `log⁺` is zero in the interval [-1,1]. -/ theorem posLog_eq_zero_iff (x : ℝ) : log⁺ x = 0 ↔ |x| ≀ 1 := by rw [← posLog_abs, ← log_nonpos_iff (abs_nonneg x)] simp [posLog] /-- The function `log⁺` equals `log` outside of the interval (-1,1). -/ theorem posLog_eq_log (hx : 1 ≀ |x|) : log⁺ x = log x := by simp only [posLog, sup_eq_right] rw [← log_abs] apply log_nonneg hx /-- The function `log⁺` equals `log` for all natural numbers. -/ theorem log_of_nat_eq_posLog {n : β„•} : log⁺ n = log n := by by_cases hn : n = 0 Β· simp [hn, posLog] Β· simp [posLog_eq_log, Nat.one_le_iff_ne_zero.2 hn] /-- The function `log⁺` equals `log (max 1 _)` for non-negative real numbers. -/ theorem posLog_eq_log_max_one (hx : 0 ≀ x) : log⁺ x = log (max 1 x) := by grind [le_abs, posLog_eq_log, log_one, max_eq_left, log_nonpos, posLog_def] /-- The function `log⁺` is monotone on the positive axis. -/ theorem monotoneOn_posLog : MonotoneOn log⁺ (Set.Ici 0) := by intro x hx y hy hxy simp only [posLog, le_sup_iff, sup_le_iff, le_refl, true_and] by_cases! h : log x ≀ 0 Β· tauto Β· right have := log_le_log (lt_trans Real.zero_lt_one ((log_pos_iff hx).1 h)) hxy simp only [this, and_true, ge_iff_le] linarith @[gcongr] lemma posLog_le_posLog (hx : 0 ≀ x) (hxy : x ≀ y) : log⁺ x ≀ log⁺ y := monotoneOn_posLog hx (hx.trans hxy) hxy /-- The function `log⁺` commutes with taking powers. -/ @[simp] lemma posLog_pow (n : β„•) (x : ℝ) : log⁺ (x ^ n) = n * log⁺ x := by by_cases hn : n = 0 Β· simp_all by_cases hx : |x| ≀ 1 Β· simp_all [pow_le_oneβ‚€, (posLog_eq_zero_iff _).2] rw [not_le] at hx have : 1 ≀ |x ^ n| := by simp_all [one_le_powβ‚€, hx.le] simp [posLog_eq_log this, posLog_eq_log hx.le] /-! ## Estimates for Products -/ /-- Estimate for `log⁺` of a product. See `Real.posLog_prod` for a variant involving multiple factors. -/ theorem posLog_mul : log⁺ (x * y) ≀ log⁺ x + log⁺ y := by by_cases ha : x = 0 Β· simp [ha, posLog] by_cases hb : y = 0 Β· simp [hb, posLog] unfold posLog nth_rw 1 [← add_zero 0, log_mul ha hb] exact max_add_add_le_max_add_max /-- Estimate for `log⁺` of a product. Special case of `Real.posLog_mul` where one of the factors is a natural number. -/ theorem posLog_nat_mul {n : β„•} : log⁺ (n * x) ≀ log n + log⁺ x := by rw [← log_of_nat_eq_posLog] exact posLog_mul /-- Estimate for `log⁺` of a product. See `Real.posLog_mul` for a variant with only two factors. -/ theorem posLog_prod {Ξ± : Type*} (s : Finset Ξ±) (f : Ξ± β†’ ℝ) : log⁺ (∏ t ∈ s, f t) ≀ βˆ‘ t ∈ s, log⁺ (f t) := by classical induction s using Finset.induction with | empty => simp [posLog] | insert a s ha hs => calc log⁺ (∏ t ∈ insert a s, f t) _ = log⁺ (f a * ∏ t ∈ s, f t) := by rw [Finset.prod_insert ha] _ ≀ log⁺ (f a) + log⁺ (∏ t ∈ s, f t) := posLog_mul _ ≀ log⁺ (f a) + βˆ‘ t ∈ s, log⁺ (f t) := add_le_add (by rfl) hs _ = βˆ‘ t ∈ insert a s, log⁺ (f t) := by rw [Finset.sum_insert ha] /-! ## Estimates for Sums -/ /-- Estimate for `log⁺` of a sum. See `Real.posLog_add` for a variant involving just two summands. -/ theorem posLog_sum {Ξ± : Type*} (s : Finset Ξ±) (f : Ξ± β†’ ℝ) : log⁺ (βˆ‘ t ∈ s, f t) ≀ log (s.card) + βˆ‘ t ∈ s, log⁺ (f t) := by -- Trivial case: empty sum by_cases hs : s = βˆ… Β· simp [hs, posLog] -- Nontrivial case: Obtain maximal element… obtain ⟨t_max, ht_max⟩ := s.exists_max_image (fun t ↦ |f t|) (Finset.nonempty_iff_ne_empty.mpr hs) -- …then calculate calc log⁺ (βˆ‘ t ∈ s, f t) _ = log⁺ |βˆ‘ t ∈ s, f t| := by rw [Real.posLog_abs] _ ≀ log⁺ (βˆ‘ t ∈ s, |f t|) := by apply monotoneOn_posLog (by simp) (by simp [Finset.sum_nonneg]) simp [Finset.abs_sum_le_sum_abs] _ ≀ log⁺ (βˆ‘ t ∈ s, |f t_max|) := by apply monotoneOn_posLog (by simp [Finset.sum_nonneg]) (by simp; positivity) apply Finset.sum_le_sum (fun i ih ↦ ht_max.2 i ih) _ = log⁺ (s.card * |f t_max|) := by simp [Finset.sum_const] _ ≀ log s.card + log⁺ |f t_max| := posLog_nat_mul _ ≀ log s.card + βˆ‘ t ∈ s, log⁺ (f t) := by gcongr rw [posLog_abs] apply Finset.single_le_sum (fun _ _ ↦ posLog_nonneg) ht_max.1 /-- Variant of `posLog_sum` for norms of elements in normed additive commutative groups, using monotonicity of `log⁺` and the triangle inequality. -/ lemma posLog_norm_sum_le {E : Type*} [SeminormedAddCommGroup E] {Ξ± : Type*} (s : Finset Ξ±) (f : Ξ± β†’ E) : log⁺ β€–βˆ‘ t ∈ s, f tβ€– ≀ log s.card + βˆ‘ t ∈ s, log⁺ β€–f tβ€– := by grw [norm_sum_le, posLog_sum] /-- Estimate for `log⁺` of a sum. See `Real.posLog_sum` for a variant involving multiple summands. -/ theorem posLog_add : log⁺ (x + y) ≀ log 2 + log⁺ x + log⁺ y := by convert posLog_sum Finset.univ ![x, y] using 1 <;> simp [add_assoc] /-- Variant of `posLog_add` for norms of elements in normed additive commutative groups, using monotonicity of `log⁺` and the triangle inequality. -/ lemma posLog_norm_add_le {E : Type*} [SeminormedAddCommGroup E] (a b : E) : log⁺ β€–a + bβ€– ≀ log⁺ β€–aβ€– + log⁺ β€–bβ€– + log 2 := by grw [norm_add_le, posLog_add, add_rotate] end Real
.lake/packages/mathlib/Mathlib/Analysis/SpecialFunctions/Log/Monotone.lean
import Mathlib.Analysis.SpecialFunctions.Pow.Real /-! # Logarithm Tonality In this file we describe the tonality of the logarithm function when multiplied by functions of the form `x ^ a`. ## Tags logarithm, tonality -/ open Set Filter Function open Topology noncomputable section namespace Real theorem log_mul_self_monotoneOn : MonotoneOn (fun x : ℝ => log x * x) { x | 1 ≀ x } := by -- TODO: can be strengthened to exp (-1) ≀ x simp only [MonotoneOn, mem_setOf_eq] intro x hex y hey hxy have y_pos : 0 < y := lt_of_lt_of_le zero_lt_one hey gcongr rwa [le_log_iff_exp_le y_pos, Real.exp_zero] theorem log_div_self_antitoneOn : AntitoneOn (fun x : ℝ => log x / x) { x | exp 1 ≀ x } := by simp only [AntitoneOn, mem_setOf_eq] intro x hex y hey hxy have x_pos : 0 < x := (exp_pos 1).trans_le hex have y_pos : 0 < y := (exp_pos 1).trans_le hey have hlogx : 1 ≀ log x := by rwa [le_log_iff_exp_le x_pos] have hyx : 0 ≀ y / x - 1 := by rwa [le_sub_iff_add_le, le_div_iffβ‚€ x_pos, zero_add, one_mul] rw [div_le_iffβ‚€ y_pos, ← sub_le_sub_iff_right (log x)] calc log y - log x = log (y / x) := by rw [log_div y_pos.ne' x_pos.ne'] _ ≀ y / x - 1 := log_le_sub_one_of_pos (div_pos y_pos x_pos) _ ≀ log x * (y / x - 1) := le_mul_of_one_le_left hyx hlogx _ = log x / x * y - log x := by ring theorem log_div_self_rpow_antitoneOn {a : ℝ} (ha : 0 < a) : AntitoneOn (fun x : ℝ => log x / x ^ a) { x | exp (1 / a) ≀ x } := by simp only [AntitoneOn, mem_setOf_eq] intro x hex y _ hxy have x_pos : 0 < x := lt_of_lt_of_le (exp_pos (1 / a)) hex have y_pos : 0 < y := by linarith nth_rw 1 [← rpow_one y] nth_rw 1 [← rpow_one x] rw [← div_self (ne_of_lt ha).symm, div_eq_mul_one_div a a, rpow_mul y_pos.le, rpow_mul x_pos.le, log_rpow (rpow_pos_of_pos y_pos a), log_rpow (rpow_pos_of_pos x_pos a), mul_div_assoc, mul_div_assoc, mul_le_mul_iff_rightβ‚€ (one_div_pos.mpr ha)] refine log_div_self_antitoneOn ?_ ?_ ?_ Β· simp only [Set.mem_setOf_eq] convert rpow_le_rpow _ hex (le_of_lt ha) using 1 Β· rw [← exp_mul] simp only [Real.exp_eq_exp] field positivity Β· simp only [Set.mem_setOf_eq] convert rpow_le_rpow _ (_root_.trans hex hxy) (le_of_lt ha) using 1 Β· rw [← exp_mul] simp only [Real.exp_eq_exp] field positivity gcongr theorem log_div_sqrt_antitoneOn : AntitoneOn (fun x : ℝ => log x / √x) { x | exp 2 ≀ x } := by simp_rw [sqrt_eq_rpow] convert log_div_self_rpow_antitoneOn one_half_pos norm_num end Real
.lake/packages/mathlib/Mathlib/Analysis/SpecialFunctions/Log/NegMulLog.lean
import Mathlib.Analysis.SpecialFunctions.Log.Deriv import Mathlib.Analysis.SpecialFunctions.Pow.Asymptotics import Mathlib.Analysis.Convex.Deriv /-! # The function `x ↦ - x * log x` The purpose of this file is to record basic analytic properties of the function `x ↦ - x * log x`, which is notably used in the theory of Shannon entropy. ## Main definitions * `negMulLog`: the function `x ↦ - x * log x` from `ℝ` to `ℝ`. -/ open scoped Topology namespace Real @[fun_prop] lemma continuous_mul_log : Continuous fun x ↦ x * log x := by rw [continuous_iff_continuousAt] intro x obtain hx | rfl := ne_or_eq x 0 Β· exact (continuous_id'.continuousAt).mul (continuousAt_log hx) rw [ContinuousAt, zero_mul] simp_rw [mul_comm _ (log _)] nth_rewrite 1 [← nhdsWithin_univ] have : (Set.univ : Set ℝ) = Set.Iio 0 βˆͺ Set.Ioi 0 βˆͺ {0} := by ext; simp [em] rw [this, nhdsWithin_union, nhdsWithin_union] simp only [nhdsWithin_singleton, Filter.tendsto_sup] refine ⟨⟨tendsto_log_mul_self_nhdsLT_zero, ?_⟩, ?_⟩ Β· simpa only [rpow_one] using tendsto_log_mul_rpow_nhdsGT_zero zero_lt_one Β· convert tendsto_pure_nhds (fun x ↦ log x * x) 0 simp @[fun_prop] lemma Continuous.mul_log {Ξ± : Type*} [TopologicalSpace Ξ±] {f : Ξ± β†’ ℝ} (hf : Continuous f) : Continuous fun a ↦ f a * log (f a) := continuous_mul_log.comp hf lemma differentiableOn_mul_log : DifferentiableOn ℝ (fun x ↦ x * log x) {0}ᢜ := differentiable_id.differentiableOn.mul differentiableOn_log lemma deriv_mul_log {x : ℝ} (hx : x β‰  0) : deriv (fun x ↦ x * log x) x = log x + 1 := by simp [hx] lemma hasDerivAt_mul_log {x : ℝ} (hx : x β‰  0) : HasDerivAt (fun x ↦ x * log x) (log x + 1) x := by rw [← deriv_mul_log hx, hasDerivAt_deriv_iff] refine DifferentiableOn.differentiableAt differentiableOn_mul_log ?_ simp [hx] @[simp] lemma rightDeriv_mul_log {x : ℝ} (hx : x β‰  0) : derivWithin (fun x ↦ x * log x) (Set.Ioi x) x = log x + 1 := (hasDerivAt_mul_log hx).hasDerivWithinAt.derivWithin (uniqueDiffWithinAt_Ioi x) @[simp] lemma leftDeriv_mul_log {x : ℝ} (hx : x β‰  0) : derivWithin (fun x ↦ x * log x) (Set.Iio x) x = log x + 1 := (hasDerivAt_mul_log hx).hasDerivWithinAt.derivWithin (uniqueDiffWithinAt_Iio x) open Filter in private lemma tendsto_deriv_mul_log_nhdsWithin_zero : Tendsto (deriv (fun x ↦ x * log x)) (𝓝[>] 0) atBot := by have : (deriv (fun x ↦ x * log x)) =αΆ [𝓝[>] 0] (fun x ↦ log x + 1) := by apply eventuallyEq_nhdsWithin_of_eqOn intro x hx rw [Set.mem_Ioi] at hx exact deriv_mul_log hx.ne' simp only [tendsto_congr' this, tendsto_atBot_add_const_right, tendsto_log_nhdsGT_zero] open Filter in lemma tendsto_deriv_mul_log_atTop : Tendsto (fun x ↦ deriv (fun x ↦ x * log x) x) atTop atTop := by refine (tendsto_congr' ?_).mpr (tendsto_log_atTop.atTop_add (tendsto_const_nhds (x := 1))) rw [EventuallyEq, eventually_atTop] exact ⟨1, fun _ hx ↦ deriv_mul_log (zero_lt_one.trans_le hx).ne'⟩ open Filter in lemma tendsto_rightDeriv_mul_log_atTop : Tendsto (fun x ↦ derivWithin (fun x ↦ x * log x) (Set.Ioi x) x) atTop atTop := by refine (tendsto_congr' ?_).mpr (tendsto_log_atTop.atTop_add (tendsto_const_nhds (x := 1))) rw [EventuallyEq, eventually_atTop] exact ⟨1, fun _ hx ↦ rightDeriv_mul_log (zero_lt_one.trans_le hx).ne'⟩ /-- At `x=0`, `(fun x ↦ x * log x)` is not differentiable (but note that it is continuous, see `continuous_mul_log`). -/ lemma not_DifferentiableAt_log_mul_zero : Β¬ DifferentiableAt ℝ (fun x ↦ x * log x) 0 := fun h ↦ (not_differentiableWithinAt_of_deriv_tendsto_atBot_Ioi (fun x : ℝ ↦ x * log x) (a := 0)) tendsto_deriv_mul_log_nhdsWithin_zero (h.differentiableWithinAt (s := Set.Ioi 0)) /-- Not differentiable, hence `deriv` has junk value zero. -/ lemma deriv_mul_log_zero : deriv (fun x ↦ x * log x) 0 = 0 := deriv_zero_of_not_differentiableAt not_DifferentiableAt_log_mul_zero lemma not_continuousAt_deriv_mul_log_zero : Β¬ ContinuousAt (deriv (fun (x : ℝ) ↦ x * log x)) 0 := not_continuousAt_of_tendsto tendsto_deriv_mul_log_nhdsWithin_zero nhdsWithin_le_nhds (by simp) lemma deriv2_mul_log (x : ℝ) : deriv^[2] (fun x ↦ x * log x) x = x⁻¹ := by simp only [Function.iterate_succ, Function.iterate_zero, Function.id_comp, Function.comp_apply] by_cases hx : x = 0 Β· rw [hx, inv_zero] exact deriv_zero_of_not_differentiableAt (fun h ↦ not_continuousAt_deriv_mul_log_zero h.continuousAt) Β· suffices βˆ€αΆ  y in (𝓝 x), deriv (fun x ↦ x * log x) y = log y + 1 by refine (Filter.EventuallyEq.deriv_eq this).trans ?_ rw [deriv_add_const, deriv_log x] filter_upwards [eventually_ne_nhds hx] with y hy using deriv_mul_log hy lemma strictConvexOn_mul_log : StrictConvexOn ℝ (Set.Ici (0 : ℝ)) (fun x ↦ x * log x) := by refine strictConvexOn_of_deriv2_pos (convex_Ici 0) (continuous_mul_log.continuousOn) ?_ intro x hx simp only [Set.nonempty_Iio, interior_Ici', Set.mem_Ioi] at hx rw [deriv2_mul_log] positivity lemma convexOn_mul_log : ConvexOn ℝ (Set.Ici (0 : ℝ)) (fun x ↦ x * log x) := strictConvexOn_mul_log.convexOn lemma mul_log_nonneg {x : ℝ} (hx : 1 ≀ x) : 0 ≀ x * log x := mul_nonneg (zero_le_one.trans hx) (log_nonneg hx) lemma mul_log_nonpos {x : ℝ} (hxβ‚€ : 0 ≀ x) (hx₁ : x ≀ 1) : x * log x ≀ 0 := mul_nonpos_of_nonneg_of_nonpos hxβ‚€ (log_nonpos hxβ‚€ hx₁) section negMulLog /-- The function `x ↦ - x * log x` from `ℝ` to `ℝ`. -/ noncomputable def negMulLog (x : ℝ) : ℝ := - x * log x lemma negMulLog_def : negMulLog = fun x ↦ - x * log x := rfl lemma negMulLog_eq_neg : negMulLog = fun x ↦ - (x * log x) := by simp [negMulLog_def] @[simp] lemma negMulLog_zero : negMulLog (0 : ℝ) = 0 := by simp [negMulLog] @[simp] lemma negMulLog_one : negMulLog (1 : ℝ) = 0 := by simp [negMulLog] lemma negMulLog_nonneg {x : ℝ} (h1 : 0 ≀ x) (h2 : x ≀ 1) : 0 ≀ negMulLog x := by simpa only [negMulLog_eq_neg, neg_nonneg] using mul_log_nonpos h1 h2 lemma negMulLog_mul (x y : ℝ) : negMulLog (x * y) = y * negMulLog x + x * negMulLog y := by simp only [negMulLog, neg_mul] by_cases hx : x = 0 Β· simp [hx] by_cases hy : y = 0 Β· simp [hy] rw [log_mul hx hy] ring @[fun_prop] lemma continuous_negMulLog : Continuous negMulLog := by simpa only [negMulLog_eq_neg] using continuous_mul_log.neg lemma differentiableOn_negMulLog : DifferentiableOn ℝ negMulLog {0}ᢜ := by simpa only [negMulLog_eq_neg] using differentiableOn_mul_log.neg lemma differentiableAt_negMulLog_iff {x : ℝ} : DifferentiableAt ℝ negMulLog x ↔ x β‰  0 := by constructor Β· unfold negMulLog intro h eq0 simp only [neg_mul, differentiableAt_fun_neg_iff, eq0] at h exact not_DifferentiableAt_log_mul_zero h Β· intro hx have : x ∈ ({0} : Set ℝ)ᢜ := by simp_all only [ne_eq, Set.mem_compl_iff, Set.mem_singleton_iff, not_false_eq_true] have := differentiableOn_negMulLog x this apply DifferentiableWithinAt.differentiableAt (s := {0}ᢜ) <;> simp_all only [ne_eq, Set.mem_compl_iff, Set.mem_singleton_iff, not_false_eq_true, compl_singleton_mem_nhds_iff] @[fun_prop] alias ⟨_, differentiableAt_negMulLog⟩ := differentiableAt_negMulLog_iff lemma deriv_negMulLog {x : ℝ} (hx : x β‰  0) : deriv negMulLog x = - log x - 1 := by rw [negMulLog_eq_neg, deriv.fun_neg, deriv_mul_log hx] ring lemma hasDerivAt_negMulLog {x : ℝ} (hx : x β‰  0) : HasDerivAt negMulLog (- log x - 1) x := by rw [← deriv_negMulLog hx, hasDerivAt_deriv_iff] refine DifferentiableOn.differentiableAt differentiableOn_negMulLog ?_ simp [hx] lemma deriv2_negMulLog (x : ℝ) : deriv^[2] negMulLog x = - x⁻¹ := by rw [negMulLog_eq_neg] have h := deriv2_mul_log simp only [Function.iterate_succ, Function.iterate_zero, Function.id_comp, deriv.fun_neg', Function.comp_apply] at h ⊒ rw [h] lemma strictConcaveOn_negMulLog : StrictConcaveOn ℝ (Set.Ici (0 : ℝ)) negMulLog := by simpa only [negMulLog_eq_neg] using strictConvexOn_mul_log.neg lemma concaveOn_negMulLog : ConcaveOn ℝ (Set.Ici (0 : ℝ)) negMulLog := strictConcaveOn_negMulLog.concaveOn end negMulLog end Real
.lake/packages/mathlib/Mathlib/Analysis/SpecificLimits/RCLike.lean
import Mathlib.Analysis.SpecificLimits.Basic import Mathlib.Analysis.RCLike.Basic /-! # A collection of specific limit computations for `RCLike` -/ open Set Algebra Filter open scoped Topology namespace RCLike variable (π•œ : Type*) [RCLike π•œ] theorem tendsto_ofReal_cobounded_cobounded : Tendsto ofReal (Bornology.cobounded ℝ) (Bornology.cobounded π•œ) := tendsto_norm_atTop_iff_cobounded.mp (mod_cast tendsto_norm_cobounded_atTop) theorem tendsto_ofReal_atTop_cobounded : Tendsto ofReal atTop (Bornology.cobounded π•œ) := tendsto_norm_atTop_iff_cobounded.mp (mod_cast tendsto_abs_atTop_atTop) theorem tendsto_ofReal_atBot_cobounded : Tendsto ofReal atBot (Bornology.cobounded π•œ) := tendsto_norm_atTop_iff_cobounded.mp (mod_cast tendsto_abs_atBot_atTop) end RCLike @[deprecated (since := "2025-10-27")] alias RCLike.tendsto_inverse_atTop_nhds_zero_nat := tendsto_inv_atTop_nhds_zero_nat @[deprecated (since := "2025-10-27")] alias RCLike.tendsto_add_mul_div_add_mul_atTop_nhds := tendsto_add_mul_div_add_mul_atTop_nhds
.lake/packages/mathlib/Mathlib/Analysis/SpecificLimits/Normed.lean
import Mathlib.Algebra.BigOperators.Module import Mathlib.Algebra.Order.Field.Power import Mathlib.Algebra.Polynomial.Monic import Mathlib.Analysis.Asymptotics.Lemmas import Mathlib.Analysis.Normed.Ring.InfiniteSum import Mathlib.Analysis.Normed.Module.Basic import Mathlib.Analysis.Normed.Order.Lattice import Mathlib.Analysis.SpecificLimits.Basic import Mathlib.Data.List.TFAE import Mathlib.Data.Nat.Choose.Bounds import Mathlib.Order.Filter.AtTopBot.ModEq import Mathlib.RingTheory.Polynomial.Pochhammer import Mathlib.Tactic.NoncommRing /-! # A collection of specific limit computations This file contains important specific limit computations in (semi-)normed groups/rings/spaces, as well as such computations in `ℝ` when the natural proof passes through a fact about normed spaces. -/ noncomputable section open Set Function Filter Finset Metric Asymptotics Topology Nat NNReal ENNReal variable {Ξ± : Type*} theorem tendsto_natCast_atTop_cobounded [NormedRing Ξ±] [NormSMulClass β„€ Ξ±] [Nontrivial Ξ±] : Tendsto Nat.cast atTop (Bornology.cobounded Ξ±) := by rw [← tendsto_norm_atTop_iff_cobounded] simpa [norm_natCast_eq_mul_norm_one] using tendsto_natCast_atTop_atTop |>.atTop_mul_const (norm_pos_iff.mpr one_ne_zero) theorem tendsto_intCast_atBot_sup_atTop_cobounded [NormedRing Ξ±] [NormSMulClass β„€ Ξ±] [Nontrivial Ξ±] : Tendsto Int.cast (atBot βŠ” atTop) (Bornology.cobounded Ξ±) := by rw [← tendsto_norm_atTop_iff_cobounded] simpa [norm_intCast_eq_abs_mul_norm_one] using tendsto_intCast_atTop_atTop |>.comp (tendsto_abs_atBot_atTop.sup tendsto_abs_atTop_atTop) |>.atTop_mul_const (norm_pos_iff.mpr one_ne_zero) theorem tendsto_intCast_atBot_cobounded [NormedRing Ξ±] [NormSMulClass β„€ Ξ±] [Nontrivial Ξ±] : Tendsto Int.cast atBot (Bornology.cobounded Ξ±) := tendsto_intCast_atBot_sup_atTop_cobounded.mono_left le_sup_left theorem tendsto_intCast_atTop_cobounded [NormedRing Ξ±] [NormSMulClass β„€ Ξ±] [Nontrivial Ξ±] : Tendsto Int.cast atTop (Bornology.cobounded Ξ±) := tendsto_intCast_atBot_sup_atTop_cobounded.mono_left le_sup_right /-! ### Powers -/ theorem isLittleO_pow_pow_of_lt_left {r₁ rβ‚‚ : ℝ} (h₁ : 0 ≀ r₁) (hβ‚‚ : r₁ < rβ‚‚) : (fun n : β„• ↦ r₁ ^ n) =o[atTop] fun n ↦ rβ‚‚ ^ n := have H : 0 < rβ‚‚ := h₁.trans_lt hβ‚‚ (isLittleO_of_tendsto fun _ hn ↦ False.elim <| H.ne' <| eq_zero_of_pow_eq_zero hn) <| (tendsto_pow_atTop_nhds_zero_of_lt_one (div_nonneg h₁ (h₁.trans hβ‚‚.le)) ((div_lt_one H).2 hβ‚‚)).congr fun _ ↦ div_pow _ _ _ theorem isBigO_pow_pow_of_le_left {r₁ rβ‚‚ : ℝ} (h₁ : 0 ≀ r₁) (hβ‚‚ : r₁ ≀ rβ‚‚) : (fun n : β„• ↦ r₁ ^ n) =O[atTop] fun n ↦ rβ‚‚ ^ n := hβ‚‚.eq_or_lt.elim (fun h ↦ h β–Έ isBigO_refl _ _) fun h ↦ (isLittleO_pow_pow_of_lt_left h₁ h).isBigO theorem isLittleO_pow_pow_of_abs_lt_left {r₁ rβ‚‚ : ℝ} (h : |r₁| < |rβ‚‚|) : (fun n : β„• ↦ r₁ ^ n) =o[atTop] fun n ↦ rβ‚‚ ^ n := by refine (IsLittleO.of_norm_left ?_).of_norm_right exact (isLittleO_pow_pow_of_lt_left (abs_nonneg r₁) h).congr (pow_abs r₁) (pow_abs rβ‚‚) open List in /-- Various statements equivalent to the fact that `f n` grows exponentially slower than `R ^ n`. * 0: $f n = o(a ^ n)$ for some $-R < a < R$; * 1: $f n = o(a ^ n)$ for some $0 < a < R$; * 2: $f n = O(a ^ n)$ for some $-R < a < R$; * 3: $f n = O(a ^ n)$ for some $0 < a < R$; * 4: there exist `a < R` and `C` such that one of `C` and `R` is positive and $|f n| ≀ Ca^n$ for all `n`; * 5: there exists `0 < a < R` and a positive `C` such that $|f n| ≀ Ca^n$ for all `n`; * 6: there exists `a < R` such that $|f n| ≀ a ^ n$ for sufficiently large `n`; * 7: there exists `0 < a < R` such that $|f n| ≀ a ^ n$ for sufficiently large `n`. NB: For backwards compatibility, if you add more items to the list, please append them at the end of the list. -/ theorem TFAE_exists_lt_isLittleO_pow (f : β„• β†’ ℝ) (R : ℝ) : TFAE [βˆƒ a ∈ Ioo (-R) R, f =o[atTop] (a ^ Β·), βˆƒ a ∈ Ioo 0 R, f =o[atTop] (a ^ Β·), βˆƒ a ∈ Ioo (-R) R, f =O[atTop] (a ^ Β·), βˆƒ a ∈ Ioo 0 R, f =O[atTop] (a ^ Β·), βˆƒ a < R, βˆƒ C : ℝ, (0 < C ∨ 0 < R) ∧ βˆ€ n, |f n| ≀ C * a ^ n, βˆƒ a ∈ Ioo 0 R, βˆƒ C > 0, βˆ€ n, |f n| ≀ C * a ^ n, βˆƒ a < R, βˆ€αΆ  n in atTop, |f n| ≀ a ^ n, βˆƒ a ∈ Ioo 0 R, βˆ€αΆ  n in atTop, |f n| ≀ a ^ n] := by have A : Ico 0 R βŠ† Ioo (-R) R := fun x hx ↦ ⟨(neg_lt_zero.2 (hx.1.trans_lt hx.2)).trans_le hx.1, hx.2⟩ have B : Ioo 0 R βŠ† Ioo (-R) R := Subset.trans Ioo_subset_Ico_self A -- First we prove that 1-4 are equivalent using 2 β†’ 3 β†’ 4, 1 β†’ 3, and 2 β†’ 1 tfae_have 1 β†’ 3 := fun ⟨a, ha, H⟩ ↦ ⟨a, ha, H.isBigO⟩ tfae_have 2 β†’ 1 := fun ⟨a, ha, H⟩ ↦ ⟨a, B ha, H⟩ tfae_have 3 β†’ 2 | ⟨a, ha, H⟩ => by rcases exists_between (abs_lt.2 ha) with ⟨b, hab, hbR⟩ exact ⟨b, ⟨(abs_nonneg a).trans_lt hab, hbR⟩, H.trans_isLittleO (isLittleO_pow_pow_of_abs_lt_left (hab.trans_le (le_abs_self b)))⟩ tfae_have 2 β†’ 4 := fun ⟨a, ha, H⟩ ↦ ⟨a, ha, H.isBigO⟩ tfae_have 4 β†’ 3 := fun ⟨a, ha, H⟩ ↦ ⟨a, B ha, H⟩ -- Add 5 and 6 using 4 β†’ 6 β†’ 5 β†’ 3 tfae_have 4 β†’ 6 | ⟨a, ha, H⟩ => by rcases bound_of_isBigO_nat_atTop H with ⟨C, hCβ‚€, hC⟩ refine ⟨a, ha, C, hCβ‚€, fun n ↦ ?_⟩ simpa only [Real.norm_eq_abs, abs_pow, abs_of_nonneg ha.1.le] using hC (pow_ne_zero n ha.1.ne') tfae_have 6 β†’ 5 := fun ⟨a, ha, C, Hβ‚€, H⟩ ↦ ⟨a, ha.2, C, Or.inl Hβ‚€, H⟩ tfae_have 5 β†’ 3 | ⟨a, ha, C, hβ‚€, H⟩ => by rcases sign_cases_of_C_mul_pow_nonneg fun n ↦ (abs_nonneg _).trans (H n) with (rfl | ⟨hCβ‚€, haβ‚€βŸ©) Β· obtain rfl : f = 0 := by ext n simpa using H n simp only [lt_irrefl, false_or] at hβ‚€ exact ⟨0, ⟨neg_lt_zero.2 hβ‚€, hβ‚€βŸ©, isBigO_zero _ _⟩ exact ⟨a, A ⟨haβ‚€, ha⟩, isBigO_of_le' _ fun n ↦ (H n).trans <| mul_le_mul_of_nonneg_left (le_abs_self _) hCβ‚€.le⟩ -- Add 7 and 8 using 2 β†’ 8 β†’ 7 β†’ 3 tfae_have 2 β†’ 8 | ⟨a, ha, H⟩ => by refine ⟨a, ha, (H.def zero_lt_one).mono fun n hn ↦ ?_⟩ rwa [Real.norm_eq_abs, Real.norm_eq_abs, one_mul, abs_pow, abs_of_pos ha.1] at hn tfae_have 8 β†’ 7 := fun ⟨a, ha, H⟩ ↦ ⟨a, ha.2, H⟩ tfae_have 7 β†’ 3 | ⟨a, ha, H⟩ => by refine ⟨a, A ⟨?_, ha⟩, .of_norm_eventuallyLE H⟩ exact nonneg_of_eventually_pow_nonneg (H.mono fun n ↦ (abs_nonneg _).trans) tfae_finish /-- For any natural `k` and a real `r > 1` we have `n ^ k = o(r ^ n)` as `n β†’ ∞`. -/ theorem isLittleO_pow_const_const_pow_of_one_lt {R : Type*} [NormedRing R] (k : β„•) {r : ℝ} (hr : 1 < r) : (fun n ↦ (n : R) ^ k : β„• β†’ R) =o[atTop] fun n ↦ r ^ n := by have : Tendsto (fun x : ℝ ↦ x ^ k) (𝓝[>] 1) (𝓝 1) := ((continuous_id.pow k).tendsto' (1 : ℝ) 1 (one_pow _)).mono_left inf_le_left obtain ⟨r' : ℝ, hr' : r' ^ k < r, h1 : 1 < r'⟩ := ((this.eventually (gt_mem_nhds hr)).and self_mem_nhdsWithin).exists have h0 : 0 ≀ r' := zero_le_one.trans h1.le suffices (fun n ↦ (n : R) ^ k : β„• β†’ R) =O[atTop] fun n : β„• ↦ (r' ^ k) ^ n from this.trans_isLittleO (isLittleO_pow_pow_of_lt_left (pow_nonneg h0 _) hr') conv in (r' ^ _) ^ _ => rw [← pow_mul, mul_comm, pow_mul] suffices βˆ€ n : β„•, β€–(n : R)β€– ≀ (r' - 1)⁻¹ * β€–(1 : R)β€– * β€–r' ^ nβ€– from (isBigO_of_le' _ this).pow _ intro n rw [mul_right_comm] refine n.norm_cast_le.trans (mul_le_mul_of_nonneg_right ?_ (norm_nonneg _)) simpa [_root_.div_eq_inv_mul, Real.norm_eq_abs, abs_of_nonneg h0] using n.cast_le_pow_div_sub h1 /-- For a real `r > 1` we have `n = o(r ^ n)` as `n β†’ ∞`. -/ theorem isLittleO_coe_const_pow_of_one_lt {R : Type*} [NormedRing R] {r : ℝ} (hr : 1 < r) : ((↑) : β„• β†’ R) =o[atTop] fun n ↦ r ^ n := by simpa only [pow_one] using @isLittleO_pow_const_const_pow_of_one_lt R _ 1 _ hr /-- If `β€–r₁‖ < rβ‚‚`, then for any natural `k` we have `n ^ k r₁ ^ n = o (rβ‚‚ ^ n)` as `n β†’ ∞`. -/ theorem isLittleO_pow_const_mul_const_pow_const_pow_of_norm_lt {R : Type*} [NormedRing R] (k : β„•) {r₁ : R} {rβ‚‚ : ℝ} (h : β€–r₁‖ < rβ‚‚) : (fun n ↦ (n : R) ^ k * r₁ ^ n : β„• β†’ R) =o[atTop] fun n ↦ rβ‚‚ ^ n := by by_cases h0 : r₁ = 0 Β· refine (isLittleO_zero _ _).congr' (mem_atTop_sets.2 <| ⟨1, fun n hn ↦ ?_⟩) EventuallyEq.rfl simp [zero_pow (one_le_iff_ne_zero.1 hn), h0] rw [← Ne, ← norm_pos_iff] at h0 have A : (fun n ↦ (n : R) ^ k : β„• β†’ R) =o[atTop] fun n ↦ (rβ‚‚ / β€–r₁‖) ^ n := isLittleO_pow_const_const_pow_of_one_lt k ((one_lt_div h0).2 h) suffices (fun n ↦ r₁ ^ n) =O[atTop] fun n ↦ β€–r₁‖ ^ n by simpa [div_mul_cancelβ‚€ _ (pow_pos h0 _).ne', div_pow] using A.mul_isBigO this exact .of_norm_eventuallyLE <| eventually_norm_pow_le r₁ theorem tendsto_pow_const_div_const_pow_of_one_lt (k : β„•) {r : ℝ} (hr : 1 < r) : Tendsto (fun n ↦ (n : ℝ) ^ k / r ^ n : β„• β†’ ℝ) atTop (𝓝 0) := (isLittleO_pow_const_const_pow_of_one_lt k hr).tendsto_div_nhds_zero /-- If `|r| < 1`, then `n ^ k r ^ n` tends to zero for any natural `k`. -/ theorem tendsto_pow_const_mul_const_pow_of_abs_lt_one (k : β„•) {r : ℝ} (hr : |r| < 1) : Tendsto (fun n ↦ (n : ℝ) ^ k * r ^ n : β„• β†’ ℝ) atTop (𝓝 0) := by by_cases h0 : r = 0 Β· exact tendsto_const_nhds.congr' (mem_atTop_sets.2 ⟨1, fun n hn ↦ by simp [zero_lt_one.trans_le hn |>.ne', h0]⟩) have hr' : 1 < |r|⁻¹ := (one_lt_invβ‚€ (abs_pos.2 h0)).2 hr rw [tendsto_zero_iff_norm_tendsto_zero] simpa [div_eq_mul_inv] using tendsto_pow_const_div_const_pow_of_one_lt k hr' /-- For `k β‰  0` and a constant `r` the function `r / n ^ k` tends to zero. -/ lemma tendsto_const_div_pow (r : ℝ) (k : β„•) (hk : k β‰  0) : Tendsto (fun n : β„• => r / n ^ k) atTop (𝓝 0) := by simpa using Filter.Tendsto.const_div_atTop (tendsto_natCast_atTop_atTop (R := ℝ).comp (tendsto_pow_atTop hk) ) r /-- If `0 ≀ r < 1`, then `n ^ k r ^ n` tends to zero for any natural `k`. This is a specialized version of `tendsto_pow_const_mul_const_pow_of_abs_lt_one`, singled out for ease of application. -/ theorem tendsto_pow_const_mul_const_pow_of_lt_one (k : β„•) {r : ℝ} (hr : 0 ≀ r) (h'r : r < 1) : Tendsto (fun n ↦ (n : ℝ) ^ k * r ^ n : β„• β†’ ℝ) atTop (𝓝 0) := tendsto_pow_const_mul_const_pow_of_abs_lt_one k (abs_lt.2 ⟨neg_one_lt_zero.trans_le hr, h'r⟩) /-- If `|r| < 1`, then `n * r ^ n` tends to zero. -/ theorem tendsto_self_mul_const_pow_of_abs_lt_one {r : ℝ} (hr : |r| < 1) : Tendsto (fun n ↦ n * r ^ n : β„• β†’ ℝ) atTop (𝓝 0) := by simpa only [pow_one] using tendsto_pow_const_mul_const_pow_of_abs_lt_one 1 hr /-- If `0 ≀ r < 1`, then `n * r ^ n` tends to zero. This is a specialized version of `tendsto_self_mul_const_pow_of_abs_lt_one`, singled out for ease of application. -/ theorem tendsto_self_mul_const_pow_of_lt_one {r : ℝ} (hr : 0 ≀ r) (h'r : r < 1) : Tendsto (fun n ↦ n * r ^ n : β„• β†’ ℝ) atTop (𝓝 0) := by simpa only [pow_one] using tendsto_pow_const_mul_const_pow_of_lt_one 1 hr h'r /-- In a normed ring, the powers of an element x with `β€–xβ€– < 1` tend to zero. -/ theorem tendsto_pow_atTop_nhds_zero_of_norm_lt_one {R : Type*} [SeminormedRing R] {x : R} (h : β€–xβ€– < 1) : Tendsto (fun n : β„• ↦ x ^ n) atTop (𝓝 0) := by apply squeeze_zero_norm' (eventually_norm_pow_le x) exact tendsto_pow_atTop_nhds_zero_of_lt_one (norm_nonneg _) h theorem tendsto_pow_atTop_nhds_zero_of_abs_lt_one {r : ℝ} (h : |r| < 1) : Tendsto (fun n : β„• ↦ r ^ n) atTop (𝓝 0) := tendsto_pow_atTop_nhds_zero_of_norm_lt_one h lemma tendsto_pow_atTop_nhds_zero_iff_norm_lt_one {R : Type*} [SeminormedRing R] [NormMulClass R] {x : R} : Tendsto (fun n : β„• ↦ x ^ n) atTop (𝓝 0) ↔ β€–xβ€– < 1 := by -- this proof is slightly fiddly since `β€–x ^ nβ€– = β€–xβ€– ^ n` might not hold for `n = 0` refine ⟨?_, tendsto_pow_atTop_nhds_zero_of_norm_lt_one⟩ rw [← abs_of_nonneg (norm_nonneg _), ← tendsto_pow_atTop_nhds_zero_iff, tendsto_zero_iff_norm_tendsto_zero] apply Tendsto.congr' filter_upwards [eventually_ge_atTop 1] with n hn induction n, hn using Nat.le_induction with | base => simp | succ n hn IH => simp [pow_succ, IH] variable {R S : Type*} [Field R] [Field S] [LinearOrder S] {v w : AbsoluteValue R S} [TopologicalSpace S] [IsStrictOrderedRing S] [Archimedean S] [_i : OrderTopology S] /-- `v (1 / (1 + a ^n))` tends to `1` for all `v : AbsoluteValue R S` for fields `R` and `S`, provided `v a < 1`. -/ theorem AbsoluteValue.tendsto_div_one_add_pow_nhds_one {v : AbsoluteValue R S} {a : R} (ha : v a < 1) : atTop.Tendsto (fun (n : β„•) ↦ v (1 / (1 + a ^ n))) (𝓝 1) := by simp_rw [map_divβ‚€ v, v.map_one] apply one_div_one (G := S) β–Έ Tendsto.div tendsto_const_nhds _ one_ne_zero have h_add := (tendsto_pow_atTop_nhds_zero_of_lt_one (v.nonneg _) ha).const_add 1 have h_sub := (tendsto_pow_atTop_nhds_zero_of_lt_one (v.nonneg _) ha).const_sub 1 exact tendsto_of_tendsto_of_tendsto_of_le_of_le (by simpa using h_sub) (by simpa using h_add) (fun n ↦ le_trans (by simp) (v.le_add _ _)) (fun n ↦ le_trans (v.add_le _ _) (by simp)) /-- `v (1 / (1 + a ^n))` tends to `0` whenever `v : AbsoluteValue R S` for fields `R` and `S`, provided `1 < v a`. -/ theorem AbsoluteValue.tendsto_div_one_add_pow_nhds_zero {v : AbsoluteValue R S} {a : R} (ha : 1 < v a) : Filter.Tendsto (fun (n : β„•) ↦ v (1 / (1 + a ^ n))) Filter.atTop (𝓝 0) := by simp_rw [div_eq_mul_inv, one_mul, map_invβ‚€, fun n ↦ add_comm 1 (a ^ n)] refine (tendsto_atTop_mono (fun n ↦ v.le_add _ _) ?_).inv_tendsto_atTop simpa using (tendsto_atTop_add_right_of_le _ _ (tendsto_pow_atTop_atTop_of_one_lt ha) (fun _ ↦ le_rfl)).congr fun n ↦ (sub_eq_add_neg (v a ^ n) 1).symm /-! ### Geometric series -/ /-- A normed ring has summable geometric series if, for all `ΞΎ` of norm `< 1`, the geometric series `βˆ‘ ΞΎ ^ n` converges. This holds both in complete normed rings and in normed fields, providing a convenient abstraction of these two classes to avoid repeating the same proofs. -/ class HasSummableGeomSeries (K : Type*) [NormedRing K] : Prop where summable_geometric_of_norm_lt_one : βˆ€ (ΞΎ : K), β€–ΞΎβ€– < 1 β†’ Summable (fun n ↦ ΞΎ ^ n) lemma summable_geometric_of_norm_lt_one {K : Type*} [NormedRing K] [HasSummableGeomSeries K] {x : K} (h : β€–xβ€– < 1) : Summable (fun n ↦ x ^ n) := HasSummableGeomSeries.summable_geometric_of_norm_lt_one x h instance {R : Type*} [NormedRing R] [CompleteSpace R] : HasSummableGeomSeries R := by constructor intro x hx have h1 : Summable fun n : β„• ↦ β€–xβ€– ^ n := summable_geometric_of_lt_one (norm_nonneg _) hx exact h1.of_norm_bounded_eventually_nat (eventually_norm_pow_le x) section HasSummableGeometricSeries variable {R : Type*} [NormedRing R] open NormedSpace /-- Bound for the sum of a geometric series in a normed ring. This formula does not assume that the normed ring satisfies the axiom `β€–1β€– = 1`. -/ theorem tsum_geometric_le_of_norm_lt_one (x : R) (h : β€–xβ€– < 1) : β€–βˆ‘' n : β„•, x ^ nβ€– ≀ β€–(1 : R)β€– - 1 + (1 - β€–xβ€–)⁻¹ := by by_cases hx : Summable (fun n ↦ x ^ n) Β· rw [hx.tsum_eq_zero_add] simp only [_root_.pow_zero] refine le_trans (norm_add_le _ _) ?_ have : β€–βˆ‘' b : β„•, (fun n ↦ x ^ (n + 1)) bβ€– ≀ (1 - β€–xβ€–)⁻¹ - 1 := by refine tsum_of_norm_bounded ?_ fun b ↦ norm_pow_le' _ (Nat.succ_pos b) convert (hasSum_nat_add_iff' 1).mpr (hasSum_geometric_of_lt_one (norm_nonneg x) h) simp linarith Β· simp only [tsum_eq_zero_of_not_summable hx, norm_zero] nontriviality R have : 1 ≀ β€–(1 : R)β€– := one_le_norm_one R have : 0 ≀ (1 - β€–xβ€–) ⁻¹ := inv_nonneg.2 (by linarith) linarith variable [HasSummableGeomSeries R] theorem geom_series_mul_neg (x : R) (h : β€–xβ€– < 1) : (βˆ‘' i : β„•, x ^ i) * (1 - x) = 1 := (summable_geometric_of_norm_lt_one h).tsum_pow_mul_one_sub theorem mul_neg_geom_series (x : R) (h : β€–xβ€– < 1) : (1 - x) * βˆ‘' i : β„•, x ^ i = 1 := (summable_geometric_of_norm_lt_one h).one_sub_mul_tsum_pow theorem geom_series_succ (x : R) (h : β€–xβ€– < 1) : βˆ‘' i : β„•, x ^ (i + 1) = βˆ‘' i : β„•, x ^ i - 1 := by rw [eq_sub_iff_add_eq, (summable_geometric_of_norm_lt_one h).tsum_eq_zero_add, pow_zero, add_comm] theorem geom_series_mul_shift (x : R) (h : β€–xβ€– < 1) : x * βˆ‘' i : β„•, x ^ i = βˆ‘' i : β„•, x ^ (i + 1) := by simp_rw [← (summable_geometric_of_norm_lt_one h).tsum_mul_left, ← _root_.pow_succ'] theorem geom_series_mul_one_add (x : R) (h : β€–xβ€– < 1) : (1 + x) * βˆ‘' i : β„•, x ^ i = 2 * βˆ‘' i : β„•, x ^ i - 1 := by rw [add_mul, one_mul, geom_series_mul_shift x h, geom_series_succ x h, two_mul, add_sub_assoc] /-- In a normed ring with summable geometric series, a perturbation of `1` by an element `t` of distance less than `1` from `1` is a unit. Here we construct its `Units` structure. -/ @[simps val] def Units.oneSub (t : R) (h : β€–tβ€– < 1) : RΛ£ where val := 1 - t inv := βˆ‘' n : β„•, t ^ n val_inv := mul_neg_geom_series t h inv_val := geom_series_mul_neg t h theorem geom_series_eq_inverse (x : R) (h : β€–xβ€– < 1) : βˆ‘' i, x ^ i = Ring.inverse (1 - x) := by change (Units.oneSub x h) ⁻¹ = Ring.inverse (1 - x) rw [← Ring.inverse_unit] rfl theorem hasSum_geom_series_inverse (x : R) (h : β€–xβ€– < 1) : HasSum (fun i ↦ x ^ i) (Ring.inverse (1 - x)) := by convert (summable_geometric_of_norm_lt_one h).hasSum exact (geom_series_eq_inverse x h).symm lemma isUnit_one_sub_of_norm_lt_one {x : R} (h : β€–xβ€– < 1) : IsUnit (1 - x) := ⟨Units.oneSub x h, rfl⟩ end HasSummableGeometricSeries section Geometric variable {K : Type*} [NormedDivisionRing K] {ΞΎ : K} theorem hasSum_geometric_of_norm_lt_one (h : β€–ΞΎβ€– < 1) : HasSum (fun n : β„• ↦ ΞΎ ^ n) (1 - ΞΎ)⁻¹ := by have xi_ne_one : ΞΎ β‰  1 := by contrapose! h simp [h] have A : Tendsto (fun n ↦ (ΞΎ ^ n - 1) * (ΞΎ - 1)⁻¹) atTop (𝓝 ((0 - 1) * (ΞΎ - 1)⁻¹)) := ((tendsto_pow_atTop_nhds_zero_of_norm_lt_one h).sub tendsto_const_nhds).mul tendsto_const_nhds rw [hasSum_iff_tendsto_nat_of_summable_norm] Β· simpa [geom_sum_eq, xi_ne_one, neg_inv, div_eq_mul_inv] using A Β· simp [norm_pow, summable_geometric_of_lt_one (norm_nonneg _) h] instance : HasSummableGeomSeries K := ⟨fun _ h ↦ (hasSum_geometric_of_norm_lt_one h).summable⟩ theorem tsum_geometric_of_norm_lt_one (h : β€–ΞΎβ€– < 1) : βˆ‘' n : β„•, ΞΎ ^ n = (1 - ΞΎ)⁻¹ := (hasSum_geometric_of_norm_lt_one h).tsum_eq theorem hasSum_geometric_of_abs_lt_one {r : ℝ} (h : |r| < 1) : HasSum (fun n : β„• ↦ r ^ n) (1 - r)⁻¹ := hasSum_geometric_of_norm_lt_one h theorem summable_geometric_of_abs_lt_one {r : ℝ} (h : |r| < 1) : Summable fun n : β„• ↦ r ^ n := summable_geometric_of_norm_lt_one h theorem tsum_geometric_of_abs_lt_one {r : ℝ} (h : |r| < 1) : βˆ‘' n : β„•, r ^ n = (1 - r)⁻¹ := tsum_geometric_of_norm_lt_one h /-- A geometric series in a normed field is summable iff the norm of the common ratio is less than one. -/ @[simp] theorem summable_geometric_iff_norm_lt_one : (Summable fun n : β„• ↦ ΞΎ ^ n) ↔ β€–ΞΎβ€– < 1 := by refine ⟨fun h ↦ ?_, summable_geometric_of_norm_lt_one⟩ obtain ⟨k : β„•, hk : dist (ΞΎ ^ k) 0 < 1⟩ := (h.tendsto_cofinite_zero.eventually (ball_mem_nhds _ zero_lt_one)).exists simp only [norm_pow, dist_zero_right] at hk rw [← one_pow k] at hk exact lt_of_pow_lt_pow_leftβ‚€ _ zero_le_one hk end Geometric section MulGeometric variable {R : Type*} [NormedRing R] {π•œ : Type*} [NormedDivisionRing π•œ] theorem summable_norm_mul_geometric_of_norm_lt_one {k : β„•} {r : R} (hr : β€–rβ€– < 1) {u : β„• β†’ β„•} (hu : (fun n ↦ (u n : ℝ)) =O[atTop] (fun n ↦ (↑(n ^ k) : ℝ))) : Summable fun n : β„• ↦ β€–(u n * r ^ n : R)β€– := by rcases exists_between hr with ⟨r', hrr', h⟩ rw [← norm_norm] at hrr' apply summable_of_isBigO_nat (summable_geometric_of_lt_one ((norm_nonneg _).trans hrr'.le) h) calc fun n ↦ ‖↑(u n) * r ^ nβ€– _ =O[atTop] fun n ↦ u n * β€–rβ€– ^ n := by apply (IsBigOWith.of_bound (c := β€–(1 : R)β€–) ?_).isBigO filter_upwards [eventually_norm_pow_le r] with n hn simp only [norm_mul, Real.norm_eq_abs, abs_cast, norm_pow, abs_norm] apply (norm_mul_le _ _).trans have : β€–(u n : R)β€– * β€–r ^ nβ€– ≀ (u n * β€–(1 : R)β€–) * β€–rβ€– ^ n := by gcongr; exact norm_cast_le (u n) exact this.trans (le_of_eq (by ring)) _ =O[atTop] fun n ↦ ↑(n ^ k) * β€–rβ€– ^ n := hu.mul (isBigO_refl _ _) _ =O[atTop] fun n ↦ r' ^ n := by simp only [cast_pow] exact (isLittleO_pow_const_mul_const_pow_const_pow_of_norm_lt k hrr').isBigO theorem summable_norm_pow_mul_geometric_of_norm_lt_one (k : β„•) {r : R} (hr : β€–rβ€– < 1) : Summable fun n : β„• ↦ β€–((n : R) ^ k * r ^ n : R)β€– := by simp only [← cast_pow] exact summable_norm_mul_geometric_of_norm_lt_one (k := k) (u := fun n ↦ n ^ k) hr (isBigO_refl _ _) theorem summable_norm_geometric_of_norm_lt_one {r : R} (hr : β€–rβ€– < 1) : Summable fun n : β„• ↦ β€–(r ^ n : R)β€– := by simpa using summable_norm_pow_mul_geometric_of_norm_lt_one 0 hr variable [HasSummableGeomSeries R] lemma hasSum_choose_mul_geometric_of_norm_lt_one' (k : β„•) {r : R} (hr : β€–rβ€– < 1) : HasSum (fun n ↦ (n + k).choose k * r ^ n) (Ring.inverse (1 - r) ^ (k + 1)) := by induction k with | zero => simpa using hasSum_geom_series_inverse r hr | succ k ih => have I1 : Summable (fun (n : β„•) ↦ β€–(n + k).choose k * r ^ nβ€–) := by apply summable_norm_mul_geometric_of_norm_lt_one (k := k) hr apply isBigO_iff.2 ⟨2 ^ k, ?_⟩ filter_upwards [Ioi_mem_atTop k] with n (hn : k < n) simp only [Real.norm_eq_abs, abs_cast, cast_pow, norm_pow] norm_cast calc (n + k).choose k _ ≀ (2 * n).choose k := choose_le_choose k (by cutsat) _ ≀ (2 * n) ^ k := Nat.choose_le_pow _ _ _ = 2 ^ k * n ^ k := Nat.mul_pow 2 n k convert hasSum_sum_range_mul_of_summable_norm' I1 ih.summable (summable_norm_geometric_of_norm_lt_one hr) (summable_geometric_of_norm_lt_one hr) with n Β· have : βˆ‘ i ∈ Finset.range (n + 1), ↑((i + k).choose k) * r ^ i * r ^ (n - i) = βˆ‘ i ∈ Finset.range (n + 1), ↑((i + k).choose k) * r ^ n := by apply Finset.sum_congr rfl (fun i hi ↦ ?_) simp only [Finset.mem_range] at hi rw [mul_assoc, ← pow_add, show i + (n - i) = n by cutsat] simp [this, ← sum_mul, ← Nat.cast_sum, sum_range_add_choose n k, add_assoc] Β· rw [ih.tsum_eq, (hasSum_geom_series_inverse r hr).tsum_eq, pow_succ] lemma summable_choose_mul_geometric_of_norm_lt_one (k : β„•) {r : R} (hr : β€–rβ€– < 1) : Summable (fun n ↦ (n + k).choose k * r ^ n) := (hasSum_choose_mul_geometric_of_norm_lt_one' k hr).summable lemma tsum_choose_mul_geometric_of_norm_lt_one' (k : β„•) {r : R} (hr : β€–rβ€– < 1) : βˆ‘' n, (n + k).choose k * r ^ n = (Ring.inverse (1 - r)) ^ (k + 1) := (hasSum_choose_mul_geometric_of_norm_lt_one' k hr).tsum_eq lemma hasSum_choose_mul_geometric_of_norm_lt_one (k : β„•) {r : π•œ} (hr : β€–rβ€– < 1) : HasSum (fun n ↦ (n + k).choose k * r ^ n) (1 / (1 - r) ^ (k + 1)) := by convert hasSum_choose_mul_geometric_of_norm_lt_one' k hr simp lemma tsum_choose_mul_geometric_of_norm_lt_one (k : β„•) {r : π•œ} (hr : β€–rβ€– < 1) : βˆ‘' n, (n + k).choose k * r ^ n = 1/ (1 - r) ^ (k + 1) := (hasSum_choose_mul_geometric_of_norm_lt_one k hr).tsum_eq lemma summable_descFactorial_mul_geometric_of_norm_lt_one (k : β„•) {r : R} (hr : β€–rβ€– < 1) : Summable (fun n ↦ (n + k).descFactorial k * r ^ n) := by convert (summable_choose_mul_geometric_of_norm_lt_one k hr).mul_left (k.factorial : R) using 2 with n simp [← mul_assoc, descFactorial_eq_factorial_mul_choose (n + k) k] open Polynomial in theorem summable_pow_mul_geometric_of_norm_lt_one (k : β„•) {r : R} (hr : β€–rβ€– < 1) : Summable (fun n ↦ (n : R) ^ k * r ^ n : β„• β†’ R) := by refine Nat.strong_induction_on k fun k hk => ?_ obtain ⟨a, ha⟩ : βˆƒ (a : β„• β†’ β„•), βˆ€ n, (n + k).descFactorial k = n ^ k + βˆ‘ i ∈ range k, a i * n ^ i := by let P : Polynomial β„• := (ascPochhammer β„• k).comp (Polynomial.X + C 1) refine ⟨fun i ↦ P.coeff i, fun n ↦ ?_⟩ have mP : Monic P := Monic.comp_X_add_C (monic_ascPochhammer β„• k) _ have dP : P.natDegree = k := by simp only [P, natDegree_comp, ascPochhammer_natDegree, mul_one, natDegree_X_add_C] have A : (n + k).descFactorial k = P.eval n := by have : n + 1 + k - 1 = n + k := by omega simp [P, ascPochhammer_nat_eq_descFactorial, this] conv_lhs => rw [A, mP.as_sum, dP] simp [eval_finset_sum] have : Summable (fun n ↦ (n + k).descFactorial k * r ^ n - βˆ‘ i ∈ range k, a i * n ^ (i : β„•) * r ^ n) := by apply (summable_descFactorial_mul_geometric_of_norm_lt_one k hr).sub apply summable_sum (fun i hi ↦ ?_) simp_rw [mul_assoc] simp only [Finset.mem_range] at hi exact (hk _ hi).mul_left _ convert this using 1 ext n simp [ha n, add_mul, sum_mul] /-- If `β€–rβ€– < 1`, then `βˆ‘' n : β„•, n * r ^ n = r / (1 - r) ^ 2`, `HasSum` version in a general ring with summable geometric series. For a version in a field, using division instead of `Ring.inverse`, see `hasSum_coe_mul_geometric_of_norm_lt_one`. -/ theorem hasSum_coe_mul_geometric_of_norm_lt_one' {x : R} (h : β€–xβ€– < 1) : HasSum (fun n ↦ n * x ^ n : β„• β†’ R) (x * (Ring.inverse (1 - x)) ^ 2) := by have A : HasSum (fun (n : β„•) ↦ (n + 1) * x ^ n) (Ring.inverse (1 - x) ^ 2) := by convert hasSum_choose_mul_geometric_of_norm_lt_one' 1 h with n simp have B : HasSum (fun (n : β„•) ↦ x ^ n) (Ring.inverse (1 - x)) := hasSum_geom_series_inverse x h convert A.sub B using 1 Β· ext n simp [add_mul] Β· symm calc Ring.inverse (1 - x) ^ 2 - Ring.inverse (1 - x) _ = Ring.inverse (1 - x) ^ 2 - ((1 - x) * Ring.inverse (1 - x)) * Ring.inverse (1 - x) := by simp [Ring.mul_inverse_cancel (1 - x) (isUnit_one_sub_of_norm_lt_one h)] _ = x * Ring.inverse (1 - x) ^ 2 := by noncomm_ring /-- If `β€–rβ€– < 1`, then `βˆ‘' n : β„•, n * r ^ n = r / (1 - r) ^ 2`, version in a general ring with summable geometric series. For a version in a field, using division instead of `Ring.inverse`, see `tsum_coe_mul_geometric_of_norm_lt_one`. -/ theorem tsum_coe_mul_geometric_of_norm_lt_one' {r : π•œ} (hr : β€–rβ€– < 1) : (βˆ‘' n : β„•, n * r ^ n : π•œ) = r * Ring.inverse (1 - r) ^ 2 := (hasSum_coe_mul_geometric_of_norm_lt_one' hr).tsum_eq /-- If `β€–rβ€– < 1`, then `βˆ‘' n : β„•, n * r ^ n = r / (1 - r) ^ 2`, `HasSum` version. -/ theorem hasSum_coe_mul_geometric_of_norm_lt_one {r : π•œ} (hr : β€–rβ€– < 1) : HasSum (fun n ↦ n * r ^ n : β„• β†’ π•œ) (r / (1 - r) ^ 2) := by convert hasSum_coe_mul_geometric_of_norm_lt_one' hr using 1 simp [div_eq_mul_inv] /-- If `β€–rβ€– < 1`, then `βˆ‘' n : β„•, n * r ^ n = r / (1 - r) ^ 2`. -/ theorem tsum_coe_mul_geometric_of_norm_lt_one {r : π•œ} (hr : β€–rβ€– < 1) : (βˆ‘' n : β„•, n * r ^ n : π•œ) = r / (1 - r) ^ 2 := (hasSum_coe_mul_geometric_of_norm_lt_one hr).tsum_eq end MulGeometric section SummableLeGeometric variable [SeminormedAddCommGroup Ξ±] {r C : ℝ} {f : β„• β†’ Ξ±} nonrec theorem SeminormedAddCommGroup.cauchySeq_of_le_geometric {C : ℝ} {r : ℝ} (hr : r < 1) {u : β„• β†’ Ξ±} (h : βˆ€ n, β€–u n - u (n + 1)β€– ≀ C * r ^ n) : CauchySeq u := cauchySeq_of_le_geometric r C hr (by simpa [dist_eq_norm] using h) theorem dist_partial_sum_le_of_le_geometric (hf : βˆ€ n, β€–f nβ€– ≀ C * r ^ n) (n : β„•) : dist (βˆ‘ i ∈ range n, f i) (βˆ‘ i ∈ range (n + 1), f i) ≀ C * r ^ n := by rw [sum_range_succ, dist_eq_norm, ← norm_neg, neg_sub, add_sub_cancel_left] exact hf n /-- If `β€–f nβ€– ≀ C * r ^ n` for all `n : β„•` and some `r < 1`, then the partial sums of `f` form a Cauchy sequence. This lemma does not assume `0 ≀ r` or `0 ≀ C`. -/ theorem cauchySeq_finset_of_geometric_bound (hr : r < 1) (hf : βˆ€ n, β€–f nβ€– ≀ C * r ^ n) : CauchySeq fun s : Finset β„• ↦ βˆ‘ x ∈ s, f x := cauchySeq_finset_of_norm_bounded (aux_hasSum_of_le_geometric hr (dist_partial_sum_le_of_le_geometric hf)).summable hf /-- If `β€–f nβ€– ≀ C * r ^ n` for all `n : β„•` and some `r < 1`, then the partial sums of `f` are within distance `C * r ^ n / (1 - r)` of the sum of the series. This lemma does not assume `0 ≀ r` or `0 ≀ C`. -/ theorem norm_sub_le_of_geometric_bound_of_hasSum (hr : r < 1) (hf : βˆ€ n, β€–f nβ€– ≀ C * r ^ n) {a : Ξ±} (ha : HasSum f a) (n : β„•) : β€–(βˆ‘ x ∈ Finset.range n, f x) - aβ€– ≀ C * r ^ n / (1 - r) := by rw [← dist_eq_norm] apply dist_le_of_le_geometric_of_tendsto r C hr (dist_partial_sum_le_of_le_geometric hf) exact ha.tendsto_sum_nat @[simp] theorem dist_partial_sum (u : β„• β†’ Ξ±) (n : β„•) : dist (βˆ‘ k ∈ range (n + 1), u k) (βˆ‘ k ∈ range n, u k) = β€–u nβ€– := by simp [dist_eq_norm, sum_range_succ] @[simp] theorem dist_partial_sum' (u : β„• β†’ Ξ±) (n : β„•) : dist (βˆ‘ k ∈ range n, u k) (βˆ‘ k ∈ range (n + 1), u k) = β€–u nβ€– := by simp [dist_eq_norm', sum_range_succ] theorem cauchy_series_of_le_geometric {C : ℝ} {u : β„• β†’ Ξ±} {r : ℝ} (hr : r < 1) (h : βˆ€ n, β€–u nβ€– ≀ C * r ^ n) : CauchySeq fun n ↦ βˆ‘ k ∈ range n, u k := cauchySeq_of_le_geometric r C hr (by simp [h]) theorem NormedAddCommGroup.cauchy_series_of_le_geometric' {C : ℝ} {u : β„• β†’ Ξ±} {r : ℝ} (hr : r < 1) (h : βˆ€ n, β€–u nβ€– ≀ C * r ^ n) : CauchySeq fun n ↦ βˆ‘ k ∈ range (n + 1), u k := (cauchy_series_of_le_geometric hr h).comp_tendsto <| tendsto_add_atTop_nat 1 theorem NormedAddCommGroup.cauchy_series_of_le_geometric'' {C : ℝ} {u : β„• β†’ Ξ±} {N : β„•} {r : ℝ} (hrβ‚€ : 0 < r) (hr₁ : r < 1) (h : βˆ€ n β‰₯ N, β€–u nβ€– ≀ C * r ^ n) : CauchySeq fun n ↦ βˆ‘ k ∈ range (n + 1), u k := by set v : β„• β†’ Ξ± := fun n ↦ if n < N then 0 else u n have hC : 0 ≀ C := (mul_nonneg_iff_of_pos_right <| pow_pos hrβ‚€ N).mp ((norm_nonneg _).trans <| h N <| le_refl N) have : βˆ€ n β‰₯ N, u n = v n := by intro n hn simp [v, if_neg (not_lt.mpr hn)] apply cauchySeq_sum_of_eventually_eq this (NormedAddCommGroup.cauchy_series_of_le_geometric' hr₁ _) Β· exact C intro n simp only [v] split_ifs with H Β· rw [norm_zero] exact mul_nonneg hC (pow_nonneg hrβ‚€.le _) Β· push_neg at H exact h _ H /-- The term norms of any convergent series are bounded by a constant. -/ lemma exists_norm_le_of_cauchySeq (h : CauchySeq fun n ↦ βˆ‘ k ∈ range n, f k) : βˆƒ C, βˆ€ n, β€–f nβ€– ≀ C := by obtain ⟨b, ⟨_, key, _⟩⟩ := cauchySeq_iff_le_tendsto_0.mp h refine ⟨b 0, fun n ↦ ?_⟩ simpa only [dist_partial_sum'] using key n (n + 1) 0 (_root_.zero_le _) (_root_.zero_le _) end SummableLeGeometric /-! ### Summability tests based on comparison with geometric series -/ theorem summable_of_ratio_norm_eventually_le {Ξ± : Type*} [SeminormedAddCommGroup Ξ±] [CompleteSpace Ξ±] {f : β„• β†’ Ξ±} {r : ℝ} (hr₁ : r < 1) (h : βˆ€αΆ  n in atTop, β€–f (n + 1)β€– ≀ r * β€–f nβ€–) : Summable f := by by_cases! hrβ‚€ : 0 ≀ r Β· rw [eventually_atTop] at h rcases h with ⟨N, hN⟩ rw [← @summable_nat_add_iff Ξ± _ _ _ _ N] refine .of_norm_bounded (g := fun n ↦ β€–f Nβ€– * r ^ n) (Summable.mul_left _ <| summable_geometric_of_lt_one hrβ‚€ hr₁) fun n ↦ ?_ simp only conv_rhs => rw [mul_comm, ← zero_add N] refine le_geom (u := fun n ↦ β€–f (n + N)β€–) hrβ‚€ n fun i _ ↦ ?_ convert hN (i + N) (N.le_add_left i) using 3 ac_rfl Β· refine .of_norm_bounded_eventually_nat summable_zero ?_ filter_upwards [h] with _ hn by_contra! h exact not_lt.mpr (norm_nonneg _) (lt_of_le_of_lt hn <| mul_neg_of_neg_of_pos hrβ‚€ h) theorem summable_of_ratio_test_tendsto_lt_one {Ξ± : Type*} [NormedAddCommGroup Ξ±] [CompleteSpace Ξ±] {f : β„• β†’ Ξ±} {l : ℝ} (hl₁ : l < 1) (hf : βˆ€αΆ  n in atTop, f n β‰  0) (h : Tendsto (fun n ↦ β€–f (n + 1)β€– / β€–f nβ€–) atTop (𝓝 l)) : Summable f := by rcases exists_between hl₁ with ⟨r, hrβ‚€, hrβ‚βŸ© refine summable_of_ratio_norm_eventually_le hr₁ ?_ filter_upwards [h.eventually_le_const hrβ‚€, hf] with _ _ h₁ rwa [← div_le_iffβ‚€ (norm_pos_iff.mpr h₁)] theorem not_summable_of_ratio_norm_eventually_ge {Ξ± : Type*} [SeminormedAddCommGroup Ξ±] {f : β„• β†’ Ξ±} {r : ℝ} (hr : 1 < r) (hf : βˆƒαΆ  n in atTop, β€–f nβ€– β‰  0) (h : βˆ€αΆ  n in atTop, r * β€–f nβ€– ≀ β€–f (n + 1)β€–) : Β¬Summable f := by rw [eventually_atTop] at h rcases h with ⟨Nβ‚€, hNβ‚€βŸ© rw [frequently_atTop] at hf rcases hf Nβ‚€ with ⟨N, hNNβ‚€ : Nβ‚€ ≀ N, hN⟩ rw [← @summable_nat_add_iff Ξ± _ _ _ _ N] refine mt Summable.tendsto_atTop_zero fun h' ↦ not_tendsto_atTop_of_tendsto_nhds (tendsto_norm_zero.comp h') ?_ convert tendsto_atTop_of_geom_le _ hr _ Β· refine lt_of_le_of_ne (norm_nonneg _) ?_ intro h'' specialize hNβ‚€ N hNNβ‚€ simp only [comp_apply, zero_add] at h'' exact hN h''.symm Β· grind theorem not_summable_of_ratio_test_tendsto_gt_one {Ξ± : Type*} [SeminormedAddCommGroup Ξ±] {f : β„• β†’ Ξ±} {l : ℝ} (hl : 1 < l) (h : Tendsto (fun n ↦ β€–f (n + 1)β€– / β€–f nβ€–) atTop (𝓝 l)) : Β¬Summable f := by have key : βˆ€αΆ  n in atTop, β€–f nβ€– β‰  0 := by filter_upwards [h.eventually_const_le hl] with _ hn hc rw [hc, _root_.div_zero] at hn linarith rcases exists_between hl with ⟨r, hrβ‚€, hrβ‚βŸ© refine not_summable_of_ratio_norm_eventually_ge hrβ‚€ key.frequently ?_ filter_upwards [h.eventually_const_le hr₁, key] with _ _ h₁ rwa [← le_div_iffβ‚€ (lt_of_le_of_ne (norm_nonneg _) h₁.symm)] section NormedDivisionRing variable [NormedDivisionRing Ξ±] [CompleteSpace Ξ±] {f : β„• β†’ Ξ±} /-- If a power series converges at `w`, it converges absolutely at all `z` of smaller norm. -/ theorem summable_powerSeries_of_norm_lt {w z : Ξ±} (h : CauchySeq fun n ↦ βˆ‘ i ∈ range n, f i * w ^ i) (hz : β€–zβ€– < β€–wβ€–) : Summable fun n ↦ f n * z ^ n := by have hw : 0 < β€–wβ€– := (norm_nonneg z).trans_lt hz obtain ⟨C, hC⟩ := exists_norm_le_of_cauchySeq h rw [summable_iff_cauchySeq_finset] refine cauchySeq_finset_of_geometric_bound (r := β€–zβ€– / β€–wβ€–) (C := C) ((div_lt_one hw).mpr hz) (fun n ↦ ?_) rw [norm_mul, norm_pow, div_pow, ← mul_comm_div] conv at hC => enter [n]; rw [norm_mul, norm_pow, ← _root_.le_div_iffβ‚€ (by positivity)] exact mul_le_mul_of_nonneg_right (hC n) (pow_nonneg (norm_nonneg z) n) /-- If a power series converges at 1, it converges absolutely at all `z` of smaller norm. -/ theorem summable_powerSeries_of_norm_lt_one {z : Ξ±} (h : CauchySeq fun n ↦ βˆ‘ i ∈ range n, f i) (hz : β€–zβ€– < 1) : Summable fun n ↦ f n * z ^ n := summable_powerSeries_of_norm_lt (w := 1) (by simp [h]) (by simp [hz]) end NormedDivisionRing section /-! ### Dirichlet and alternating series tests -/ variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] variable {b : ℝ} {f : β„• β†’ ℝ} {z : β„• β†’ E} /-- **Dirichlet's test** for monotone sequences. -/ theorem Monotone.cauchySeq_series_mul_of_tendsto_zero_of_bounded (hfa : Monotone f) (hf0 : Tendsto f atTop (𝓝 0)) (hgb : βˆ€ n, β€–βˆ‘ i ∈ range n, z iβ€– ≀ b) : CauchySeq fun n ↦ βˆ‘ i ∈ range n, f i β€’ z i := by rw [← cauchySeq_shift 1] simp_rw [Finset.sum_range_by_parts _ _ (Nat.succ _), sub_eq_add_neg, Nat.succ_sub_succ_eq_sub, tsub_zero] apply (NormedField.tendsto_zero_smul_of_tendsto_zero_of_bounded hf0 ⟨b, eventually_map.mpr <| Eventually.of_forall fun n ↦ hgb <| n + 1⟩).cauchySeq.add refine CauchySeq.neg ?_ refine cauchySeq_range_of_norm_bounded ?_ (fun n ↦ ?_ : βˆ€ n, β€–(f (n + 1) + -f n) β€’ (Finset.range (n + 1)).sum zβ€– ≀ b * |f (n + 1) - f n|) Β· simp_rw [abs_of_nonneg (sub_nonneg_of_le (hfa (Nat.le_succ _))), ← mul_sum] apply Real.uniformContinuous_const_mul.comp_cauchySeq simp_rw [sum_range_sub, sub_eq_add_neg] exact (Tendsto.cauchySeq hf0).add_const Β· rw [norm_smul, mul_comm] exact mul_le_mul_of_nonneg_right (hgb _) (abs_nonneg _) /-- **Dirichlet's test** for antitone sequences. -/ theorem Antitone.cauchySeq_series_mul_of_tendsto_zero_of_bounded (hfa : Antitone f) (hf0 : Tendsto f atTop (𝓝 0)) (hzb : βˆ€ n, β€–βˆ‘ i ∈ range n, z iβ€– ≀ b) : CauchySeq fun n ↦ βˆ‘ i ∈ range n, f i β€’ z i := by have hfa' : Monotone fun n ↦ -f n := fun _ _ hab ↦ neg_le_neg <| hfa hab have hf0' : Tendsto (fun n ↦ -f n) atTop (𝓝 0) := by convert hf0.neg simp convert (hfa'.cauchySeq_series_mul_of_tendsto_zero_of_bounded hf0' hzb).neg simp theorem norm_sum_neg_one_pow_le (n : β„•) : β€–βˆ‘ i ∈ range n, (-1 : ℝ) ^ iβ€– ≀ 1 := by rw [neg_one_geom_sum] split_ifs <;> norm_num /-- The **alternating series test** for monotone sequences. See also `Monotone.tendsto_alternating_series_of_tendsto_zero`. -/ theorem Monotone.cauchySeq_alternating_series_of_tendsto_zero (hfa : Monotone f) (hf0 : Tendsto f atTop (𝓝 0)) : CauchySeq fun n ↦ βˆ‘ i ∈ range n, (-1) ^ i * f i := by simp_rw [mul_comm] exact hfa.cauchySeq_series_mul_of_tendsto_zero_of_bounded hf0 norm_sum_neg_one_pow_le /-- The **alternating series test** for monotone sequences. -/ theorem Monotone.tendsto_alternating_series_of_tendsto_zero (hfa : Monotone f) (hf0 : Tendsto f atTop (𝓝 0)) : βˆƒ l, Tendsto (fun n ↦ βˆ‘ i ∈ range n, (-1) ^ i * f i) atTop (𝓝 l) := cauchySeq_tendsto_of_complete <| hfa.cauchySeq_alternating_series_of_tendsto_zero hf0 /-- The **alternating series test** for antitone sequences. See also `Antitone.tendsto_alternating_series_of_tendsto_zero`. -/ theorem Antitone.cauchySeq_alternating_series_of_tendsto_zero (hfa : Antitone f) (hf0 : Tendsto f atTop (𝓝 0)) : CauchySeq fun n ↦ βˆ‘ i ∈ range n, (-1) ^ i * f i := by simp_rw [mul_comm] exact hfa.cauchySeq_series_mul_of_tendsto_zero_of_bounded hf0 norm_sum_neg_one_pow_le /-- The **alternating series test** for antitone sequences. -/ theorem Antitone.tendsto_alternating_series_of_tendsto_zero (hfa : Antitone f) (hf0 : Tendsto f atTop (𝓝 0)) : βˆƒ l, Tendsto (fun n ↦ βˆ‘ i ∈ range n, (-1) ^ i * f i) atTop (𝓝 l) := cauchySeq_tendsto_of_complete <| hfa.cauchySeq_alternating_series_of_tendsto_zero hf0 end /-! ### Partial sum bounds on alternating convergent series -/ section variable {E : Type*} [Ring E] [PartialOrder E] [IsOrderedRing E] [TopologicalSpace E] [OrderClosedTopology E] {l : E} {f : β„• β†’ E} /-- Partial sums of an alternating monotone series with an even number of terms provide upper bounds on the limit. -/ theorem Monotone.tendsto_le_alternating_series (hfl : Tendsto (fun n ↦ βˆ‘ i ∈ range n, (-1) ^ i * f i) atTop (𝓝 l)) (hfm : Monotone f) (k : β„•) : l ≀ βˆ‘ i ∈ range (2 * k), (-1) ^ i * f i := by have ha : Antitone (fun n ↦ βˆ‘ i ∈ range (2 * n), (-1) ^ i * f i) := by refine antitone_nat_of_succ_le (fun n ↦ ?_) rw [show 2 * (n + 1) = 2 * n + 1 + 1 by ring, sum_range_succ, sum_range_succ] simp_rw [_root_.pow_succ', show (-1 : E) ^ (2 * n) = 1 by simp, neg_one_mul, one_mul, ← sub_eq_add_neg, sub_le_iff_le_add] gcongr exact hfm (by cutsat) exact ha.le_of_tendsto (hfl.comp (tendsto_atTop_mono (fun n ↦ by dsimp; cutsat) tendsto_id)) _ /-- Partial sums of an alternating monotone series with an odd number of terms provide lower bounds on the limit. -/ theorem Monotone.alternating_series_le_tendsto (hfl : Tendsto (fun n ↦ βˆ‘ i ∈ range n, (-1) ^ i * f i) atTop (𝓝 l)) (hfm : Monotone f) (k : β„•) : βˆ‘ i ∈ range (2 * k + 1), (-1) ^ i * f i ≀ l := by have hm : Monotone (fun n ↦ βˆ‘ i ∈ range (2 * n + 1), (-1) ^ i * f i) := by refine monotone_nat_of_le_succ (fun n ↦ ?_) rw [show 2 * (n + 1) = 2 * n + 1 + 1 by ring, sum_range_succ _ (2 * n + 1 + 1), sum_range_succ _ (2 * n + 1)] simp_rw [_root_.pow_succ', show (-1 : E) ^ (2 * n) = 1 by simp, neg_one_mul, neg_neg, one_mul, ← sub_eq_add_neg, sub_add_eq_add_sub, le_sub_iff_add_le] gcongr exact hfm (by cutsat) exact hm.ge_of_tendsto (hfl.comp (tendsto_atTop_mono (fun n ↦ by dsimp; cutsat) tendsto_id)) _ /-- Partial sums of an alternating antitone series with an even number of terms provide lower bounds on the limit. -/ theorem Antitone.alternating_series_le_tendsto (hfl : Tendsto (fun n ↦ βˆ‘ i ∈ range n, (-1) ^ i * f i) atTop (𝓝 l)) (hfa : Antitone f) (k : β„•) : βˆ‘ i ∈ range (2 * k), (-1) ^ i * f i ≀ l := by have hm : Monotone (fun n ↦ βˆ‘ i ∈ range (2 * n), (-1) ^ i * f i) := by refine monotone_nat_of_le_succ (fun n ↦ ?_) rw [show 2 * (n + 1) = 2 * n + 1 + 1 by ring, sum_range_succ, sum_range_succ] simp_rw [_root_.pow_succ', show (-1 : E) ^ (2 * n) = 1 by simp, neg_one_mul, one_mul, ← sub_eq_add_neg, le_sub_iff_add_le] gcongr exact hfa (by cutsat) exact hm.ge_of_tendsto (hfl.comp (tendsto_atTop_mono (fun n ↦ by dsimp; cutsat) tendsto_id)) _ /-- Partial sums of an alternating antitone series with an odd number of terms provide upper bounds on the limit. -/ theorem Antitone.tendsto_le_alternating_series (hfl : Tendsto (fun n ↦ βˆ‘ i ∈ range n, (-1) ^ i * f i) atTop (𝓝 l)) (hfa : Antitone f) (k : β„•) : l ≀ βˆ‘ i ∈ range (2 * k + 1), (-1) ^ i * f i := by have ha : Antitone (fun n ↦ βˆ‘ i ∈ range (2 * n + 1), (-1) ^ i * f i) := by refine antitone_nat_of_succ_le (fun n ↦ ?_) rw [show 2 * (n + 1) = 2 * n + 1 + 1 by ring, sum_range_succ, sum_range_succ] simp_rw [_root_.pow_succ', show (-1 : E) ^ (2 * n) = 1 by simp, neg_one_mul, neg_neg, one_mul, ← sub_eq_add_neg, sub_add_eq_add_sub, sub_le_iff_le_add] gcongr exact hfa (by cutsat) exact ha.le_of_tendsto (hfl.comp (tendsto_atTop_mono (fun n ↦ by dsimp; cutsat) tendsto_id)) _ theorem Summable.tendsto_alternating_series_tsum {E} [Ring E] [UniformSpace E] [IsUniformAddGroup E] [CompleteSpace E] {f : β„• β†’ E} (hfs : Summable f) : Tendsto (fun n => (βˆ‘ i ∈ range n, (-1) ^ i * f i)) atTop (𝓝 (βˆ‘' i : β„•, (-1) ^ i * f i)) := Summable.tendsto_sum_tsum_nat hfs.alternating -- TODO: generalize to conditionally-convergent sums -- see https://github.com/leanprover-community/mathlib4/pull/29577#discussion_r2343447344 theorem alternating_series_error_bound {E} [Ring E] [LinearOrder E] [IsOrderedRing E] [UniformSpace E] [IsUniformAddGroup E] [CompleteSpace E] [OrderClosedTopology E] (f : β„• β†’ E) (hfa : Antitone f) (hfs : Summable f) (n : β„•) : |(βˆ‘' i : β„•, (-1) ^ i * f i) - (βˆ‘ i ∈ range n, (-1) ^ i * f i)| ≀ f n := by obtain h := hfs.tendsto_alternating_series_tsum have upper := hfa.alternating_series_le_tendsto h have lower := hfa.tendsto_le_alternating_series h have I (n : β„•) : 0 ≀ f n := by apply le_of_tendsto hfs.tendsto_atTop_zero filter_upwards [Ici_mem_atTop n] with m hm using hfa hm obtain (h | h) := even_or_odd n Β· obtain ⟨n, rfl⟩ := even_iff_exists_two_mul.mp h specialize upper n specialize lower n simp only [sum_range_succ, even_two, Even.mul_right, Even.neg_pow, one_pow, one_mul] at lower rw [abs_sub_le_iff] constructor Β· rwa [sub_le_iff_le_add, add_comm] Β· rw [sub_le_iff_le_add, add_comm] exact upper.trans (le_add_of_nonneg_right (I (2 * n))) Β· obtain ⟨n, rfl⟩ := odd_iff_exists_bit1.mp h specialize upper (n + 1) specialize lower n rw [Nat.mul_add, Finset.sum_range_succ] at upper rw [abs_sub_le_iff] constructor Β· rw [sub_le_iff_le_add, add_comm] exact lower.trans (le_add_of_nonneg_right (I (2 * n + 1))) Β· simpa [Finset.sum_range_succ, add_comm, pow_add] using upper end /-! ### Factorial -/ /-- The series `βˆ‘' n, x ^ n / n!` is summable of any `x : ℝ`. See also `expSeries_div_summable` for a version that also works in `β„‚`, and `NormedSpace.expSeries_summable'` for a version that works in any normed algebra over `ℝ` or `β„‚`. -/ theorem Real.summable_pow_div_factorial (x : ℝ) : Summable (fun n ↦ x ^ n / n ! : β„• β†’ ℝ) := by -- We start with trivial estimates have A : (0 : ℝ) < βŒŠβ€–xβ€–βŒ‹β‚Š + 1 := zero_lt_one.trans_le (by simp) have B : β€–xβ€– / (βŒŠβ€–xβ€–βŒ‹β‚Š + 1) < 1 := (div_lt_one A).2 (Nat.lt_floor_add_one _) -- Then we apply the ratio test. The estimate works for `n β‰₯ βŒŠβ€–xβ€–βŒ‹β‚Š`. suffices βˆ€ n β‰₯ βŒŠβ€–xβ€–βŒ‹β‚Š, β€–x ^ (n + 1) / (n + 1)!β€– ≀ β€–xβ€– / (βŒŠβ€–xβ€–βŒ‹β‚Š + 1) * β€–x ^ n / ↑n !β€– from summable_of_ratio_norm_eventually_le B (eventually_atTop.2 βŸ¨βŒŠβ€–xβ€–βŒ‹β‚Š, this⟩) -- Finally, we prove the upper estimate intro n hn calc β€–x ^ (n + 1) / (n + 1)!β€– = β€–xβ€– / (n + 1) * β€–x ^ n / (n !)β€– := by rw [_root_.pow_succ', Nat.factorial_succ, Nat.cast_mul, ← _root_.div_mul_div_comm, norm_mul, norm_div, Real.norm_natCast, Nat.cast_succ] _ ≀ β€–xβ€– / (βŒŠβ€–xβ€–βŒ‹β‚Š + 1) * β€–x ^ n / (n !)β€– := by gcongr section /-! Limits when `f x * g x` is bounded or convergent and `f` tends to the `cobounded` filter. -/ open Bornology variable {R K : Type*} lemma tendsto_zero_of_isBoundedUnder_smul_of_tendsto_cobounded [NormedAddGroup K] [NormedAddGroup R] [SMulWithZero K R] [NoZeroSMulDivisors K R] [NormSMulClass K R] {f : Ξ± β†’ K} {g : Ξ± β†’ R} {l : Filter Ξ±} (hmul : IsBoundedUnder (Β· ≀ Β·) l fun x ↦ β€–f x β€’ g xβ€–) (hf : Tendsto f l (cobounded K)) : Tendsto g l (𝓝 0) := by obtain ⟨c, hc⟩ := hmul.eventually_le refine Metric.nhds_basis_closedBall.tendsto_right_iff.mpr fun Ξ΅ hΞ΅0 ↦ ?_ filter_upwards [hc, hasBasis_cobounded_norm.tendsto_right_iff.mp hf (c / Ξ΅) trivial, hf.eventually_ne_cobounded 0] with x hfgc hΞ΅f hf0 rcases eq_or_lt_of_le ((norm_nonneg _).trans hfgc) with rfl | hc0 Β· simpa [(smul_eq_zero_iff_right hf0).mp (norm_le_zero_iff.mp hfgc)] using hΞ΅0.le calc _ = β€–g xβ€– := by simp _ ≀ c / β€–f xβ€– := by rwa [norm_smul, ← le_div_iffβ‚€' (by positivity)] at hfgc _ ≀ c / (c / Ξ΅) := by gcongr _ = Ξ΅ := div_div_cancelβ‚€ hc0.ne' section variable [NormedRing K] [NormedAddCommGroup R] variable [Module K R] [NoZeroSMulDivisors K R] [NormSMulClass K R] lemma tendsto_smul_congr_of_tendsto_left_cobounded_of_isBoundedUnder {f₁ fβ‚‚ : Ξ± β†’ K} {g : Ξ± β†’ R} {t : R} {l : Filter Ξ±} (hmul : Tendsto (fun x ↦ f₁ x β€’ g x) l (𝓝 t)) (hf₁ : Tendsto f₁ l (cobounded K)) (hbdd : IsBoundedUnder (Β· ≀ Β·) l fun x ↦ β€–f₁ x - fβ‚‚ xβ€–) : Tendsto (fun x ↦ fβ‚‚ x β€’ g x) l (𝓝 t) := by apply hmul.congr_dist dsimp simp_rw [dist_eq_norm, ← sub_smul, norm_smul] apply isBoundedUnder_le_mul_tendsto_zero Β· change IsBoundedUnder _ _ fun _ ↦ _ simpa using hbdd Β· rw [← tendsto_zero_iff_norm_tendsto_zero] exact tendsto_zero_of_isBoundedUnder_smul_of_tendsto_cobounded hmul.norm.isBoundedUnder_le hf₁ -- The use case in mind for this is when `K = ℝ`, and `R = ℝ` or `β„‚` lemma tendsto_smul_comp_nat_floor_of_tendsto_nsmul [NormSMulClass β„€ K] [LinearOrder K] [IsStrictOrderedRing K] [FloorSemiring K] [HasSolidNorm K] {g : β„• β†’ R} {t : R} (hg : Tendsto (fun n : β„• ↦ n β€’ g n) atTop (𝓝 t)) : Tendsto (fun x : K ↦ x β€’ g ⌊xβŒ‹β‚Š) atTop (𝓝 t) := by replace hg : Tendsto (fun n : β„• ↦ (n : K) β€’ g n) atTop (𝓝 t) := mod_cast hg apply tendsto_smul_congr_of_tendsto_left_cobounded_of_isBoundedUnder (hg.comp tendsto_nat_floor_atTop) Β· exact tendsto_natCast_atTop_cobounded.comp tendsto_nat_floor_atTop Β· apply isBoundedUnder_of_eventually_le (a := β€–(1 : K)β€–) apply Eventually.mono _ (fun x h ↦ norm_le_norm_of_abs_le_abs h) simpa using ⟨0, fun _ h ↦ mod_cast Nat.abs_floor_sub_le h⟩ end lemma tendsto_smul_comp_nat_floor_of_tendsto_mul [NormedRing K] [NormedRing R] [Module K R] [NoZeroSMulDivisors K R] [NormSMulClass K R] [NormSMulClass β„€ K] [LinearOrder K] [IsStrictOrderedRing K] [FloorSemiring K] [HasSolidNorm K] {g : β„• β†’ R} {t : R} (hg : Tendsto (fun n : β„• ↦ (n : R) * g n) atTop (𝓝 t)) : Tendsto (fun x : K ↦ x β€’ g ⌊xβŒ‹β‚Š) atTop (𝓝 t) := tendsto_smul_comp_nat_floor_of_tendsto_nsmul (by simpa only [nsmul_eq_mul] using hg) end
.lake/packages/mathlib/Mathlib/Analysis/SpecificLimits/Fibonacci.lean
import Mathlib.Analysis.SpecificLimits.Normed import Mathlib.NumberTheory.Real.GoldenRatio /-! # The ratio of consecutive Fibonacci numbers We prove that the ratio of consecutive Fibonacci numbers tends to the golden ratio. -/ open Nat Real Filter Tendsto open scoped Topology goldenRatio /-- The limit of `fib (n + 1) / fib n` as `n β†’ ∞` is the golden ratio. -/ theorem tendsto_fib_succ_div_fib_atTop : Tendsto (fun n ↦ (fib (n + 1) / fib n : ℝ)) atTop (𝓝 Ο†) := by have h₁ n : (fib (n + 1) / fib n : ℝ) = (Ο† - ψ * (ψ / Ο†) ^ n) / (1 - (ψ / Ο†) ^ n) := by simp only [coe_fib_eq, pow_succ, div_pow] field have hβ‚‚ := tendsto_pow_atTop_nhds_zero_of_abs_lt_one (r := ψ / Ο†) <| by rw [abs_div, div_lt_one <| by positivity, abs_of_pos goldenRatio_pos, abs_lt] ring_nf bound rw [show Ο† = (Ο† - ψ * 0) / (1 - 0) by ring, funext h₁] exact const_sub _ (const_mul _ hβ‚‚) |>.div (const_sub _ hβ‚‚) <| by simp /-- The limit of `fib n / fib (n + 1)` as `n β†’ ∞` is the negative conjugate of the golden ratio. -/ theorem tendsto_fib_div_fib_succ_atTop : Tendsto (fun n ↦ (fib n / fib (n + 1) : ℝ)) atTop (𝓝 (-ψ)) := by convert tendsto_fib_succ_div_fib_atTop.invβ‚€ (by positivity) using 2 Β· rw [inv_div] Β· rw [inv_goldenRatio]
.lake/packages/mathlib/Mathlib/Analysis/SpecificLimits/Basic.lean
import Mathlib.Algebra.Field.GeomSum import Mathlib.Data.Nat.Factorial.BigOperators import Mathlib.Order.Filter.AtTopBot.Archimedean import Mathlib.Order.Iterate import Mathlib.Topology.Algebra.Algebra import Mathlib.Topology.Algebra.InfiniteSum.Real import Mathlib.Topology.Instances.EReal.Lemmas import Mathlib.Topology.Instances.Rat /-! # A collection of specific limit computations This file, by design, is independent of `NormedSpace` in the import hierarchy. It contains important specific limit computations in metric spaces, in ordered rings/fields, and in specific instances of these such as `ℝ`, `ℝβ‰₯0` and `ℝβ‰₯0∞`. -/ assert_not_exists Module.Basis NormedSpace noncomputable section open Set Function Filter Finset Metric Topology Nat uniformity NNReal ENNReal variable {Ξ± : Type*} {Ξ² : Type*} {ΞΉ : Type*} theorem NNRat.tendsto_inv_atTop_nhds_zero_nat : Tendsto (fun n : β„• ↦ (n : β„šβ‰₯0)⁻¹) atTop (𝓝 0) := tendsto_inv_atTop_zero.comp tendsto_natCast_atTop_atTop theorem NNRat.tendsto_algebraMap_inv_atTop_nhds_zero_nat (π•œ : Type*) [Semiring π•œ] [Algebra β„šβ‰₯0 π•œ] [TopologicalSpace π•œ] [ContinuousSMul β„šβ‰₯0 π•œ] : Tendsto (algebraMap β„šβ‰₯0 π•œ ∘ fun n : β„• ↦ (n : β„šβ‰₯0)⁻¹) atTop (𝓝 0) := by convert (continuous_algebraMap β„šβ‰₯0 π•œ).continuousAt.tendsto.comp tendsto_inv_atTop_nhds_zero_nat rw [map_zero] theorem tendsto_inv_atTop_nhds_zero_nat {π•œ : Type*} [DivisionSemiring π•œ] [CharZero π•œ] [TopologicalSpace π•œ] [ContinuousSMul β„šβ‰₯0 π•œ] : Tendsto (fun n : β„• ↦ (n : π•œ)⁻¹) atTop (𝓝 0) := by convert NNRat.tendsto_algebraMap_inv_atTop_nhds_zero_nat π•œ simp theorem tendsto_const_div_atTop_nhds_zero_nat {π•œ : Type*} [DivisionSemiring π•œ] [CharZero π•œ] [TopologicalSpace π•œ] [ContinuousSMul β„šβ‰₯0 π•œ] [ContinuousMul π•œ] (C : π•œ) : Tendsto (fun n : β„• ↦ C / n) atTop (𝓝 0) := by simpa only [mul_zero, div_eq_mul_inv] using (tendsto_const_nhds (x := C)).mul tendsto_inv_atTop_nhds_zero_nat theorem tendsto_one_div_atTop_nhds_zero_nat {π•œ : Type*} [DivisionSemiring π•œ] [CharZero π•œ] [TopologicalSpace π•œ] [ContinuousSMul β„šβ‰₯0 π•œ] : Tendsto (fun n : β„• ↦ 1 / (n : π•œ)) atTop (𝓝 0) := by simp [tendsto_inv_atTop_nhds_zero_nat] theorem EReal.tendsto_const_div_atTop_nhds_zero_nat {C : EReal} (h : C β‰  βŠ₯) (h' : C β‰  ⊀) : Tendsto (fun n : β„• ↦ C / n) atTop (𝓝 0) := by have : (fun n : β„• ↦ C / n) = fun n : β„• ↦ ((C.toReal / n : ℝ) : EReal) := by ext n nth_rw 1 [← coe_toReal h' h, ← coe_coe_eq_natCast n, ← coe_div C.toReal n] rw [this, ← coe_zero, tendsto_coe] exact _root_.tendsto_const_div_atTop_nhds_zero_nat C.toReal theorem tendsto_one_div_add_atTop_nhds_zero_nat {π•œ : Type*} [DivisionSemiring π•œ] [CharZero π•œ] [TopologicalSpace π•œ] [ContinuousSMul β„šβ‰₯0 π•œ] : Tendsto (fun n : β„• ↦ 1 / ((n : π•œ) + 1)) atTop (𝓝 0) := suffices Tendsto (fun n : β„• ↦ 1 / (↑(n + 1) : π•œ)) atTop (𝓝 0) by simpa (tendsto_add_atTop_iff_nat 1).2 tendsto_one_div_atTop_nhds_zero_nat theorem tendsto_algebraMap_inv_atTop_nhds_zero_nat {π•œ : Type*} (A : Type*) [Semifield π•œ] [CharZero π•œ] [TopologicalSpace π•œ] [ContinuousSMul β„šβ‰₯0 π•œ] [Semiring A] [Algebra π•œ A] [TopologicalSpace A] [ContinuousSMul π•œ A] : Tendsto (algebraMap π•œ A ∘ fun n : β„• ↦ (n : π•œ)⁻¹) atTop (𝓝 0) := by convert (continuous_algebraMap π•œ A).continuousAt.tendsto.comp tendsto_inv_atTop_nhds_zero_nat rw [map_zero] /-- The limit of `n / (n + x)` is 1, for any constant `x` (valid in `ℝ` or any topological division algebra over `β„šβ‰₯0`, e.g., `β„‚`). -/ theorem tendsto_natCast_div_add_atTop {π•œ : Type*} [DivisionSemiring π•œ] [TopologicalSpace π•œ] [CharZero π•œ] [ContinuousSMul β„šβ‰₯0 π•œ] [IsTopologicalSemiring π•œ] [ContinuousInvβ‚€ π•œ] (x : π•œ) : Tendsto (fun n : β„• ↦ (n : π•œ) / (n + x)) atTop (𝓝 1) := by convert Tendsto.congr' ((eventually_ne_atTop 0).mp (Eventually.of_forall fun n hn ↦ _)) _ Β· exact fun n : β„• ↦ 1 / (1 + x / n) Β· simp [Nat.cast_ne_zero.mpr hn, add_div'] Β· have : 𝓝 (1 : π•œ) = 𝓝 (1 / (1 + x * (0 : π•œ))) := by rw [mul_zero, add_zero, div_one] rw [this] refine tendsto_const_nhds.div (tendsto_const_nhds.add ?_) (by simp) simp_rw [div_eq_mul_inv] refine tendsto_const_nhds.mul ?_ have := ((continuous_algebraMap β„šβ‰₯0 π•œ).tendsto _).comp tendsto_inv_atTop_nhds_zero_nat rw [map_zero, Filter.tendsto_atTop'] at this refine Iff.mpr tendsto_atTop' ?_ intros simp_all only [comp_apply, map_invβ‚€, map_natCast] theorem tendsto_add_mul_div_add_mul_atTop_nhds {π•œ : Type*} [Semifield π•œ] [CharZero π•œ] [TopologicalSpace π•œ] [ContinuousSMul β„šβ‰₯0 π•œ] [IsTopologicalSemiring π•œ] [ContinuousInvβ‚€ π•œ] (a b c : π•œ) {d : π•œ} (hd : d β‰  0) : Tendsto (fun k : β„• ↦ (a + c * k) / (b + d * k)) atTop (𝓝 (c / d)) := by apply Filter.Tendsto.congr' case f₁ => exact fun k ↦ (a * (↑k)⁻¹ + c) / (b * (↑k)⁻¹ + d) Β· refine (eventually_ne_atTop 0).mp (Eventually.of_forall ?_) intro h hx dsimp field (discharger := norm_cast) Β· apply Filter.Tendsto.div _ _ hd all_goals apply zero_add (_ : π•œ) β–Έ Filter.Tendsto.add_const _ _ apply mul_zero (_ : π•œ) β–Έ Filter.Tendsto.const_mul _ _ exact tendsto_inv_atTop_nhds_zero_nat /-- For any positive `m : β„•`, `((n % m : β„•) : ℝ) / (n : ℝ)` tends to `0` as `n` tends to `∞`. -/ theorem tendsto_mod_div_atTop_nhds_zero_nat {m : β„•} (hm : 0 < m) : Tendsto (fun n : β„• => ((n % m : β„•) : ℝ) / (n : ℝ)) atTop (𝓝 0) := by have h0 : βˆ€αΆ  n : β„• in atTop, 0 ≀ (fun n : β„• => ((n % m : β„•) : ℝ)) n := by aesop exact tendsto_bdd_div_atTop_nhds_zero h0 (.of_forall (fun n ↦ cast_le.mpr (mod_lt n hm).le)) tendsto_natCast_atTop_atTop /-- If `a β‰  0`, `(a * x + c)⁻¹` tends to `0` as `x` tends to `∞`. -/ theorem tendsto_mul_add_inv_atTop_nhds_zero (a c : ℝ) (ha : a β‰  0) : Tendsto (fun x => (a * x + c)⁻¹) atTop (𝓝 0) := by obtain ha' | ha' := lt_or_gt_of_ne ha Β· exact tendsto_inv_atBot_zero.comp (tendsto_atBot_add_const_right _ c (tendsto_id.const_mul_atTop_of_neg ha')) Β· exact tendsto_inv_atTop_zero.comp (tendsto_atTop_add_const_right _ c (tendsto_id.const_mul_atTop ha')) theorem Filter.EventuallyEq.div_mul_cancel {Ξ± G : Type*} [GroupWithZero G] {f g : Ξ± β†’ G} {l : Filter Ξ±} (hg : Tendsto g l (π“Ÿ {0}ᢜ)) : (fun x ↦ f x / g x * g x) =αΆ [l] fun x ↦ f x := by filter_upwards [hg.le_comap <| preimage_mem_comap (m := g) (mem_principal_self {0}ᢜ)] with x hx simp_all /-- If `g` tends to `∞`, then eventually for all `x` we have `(f x / g x) * g x = f x`. -/ theorem Filter.EventuallyEq.div_mul_cancel_atTop {Ξ± K : Type*} [DivisionSemiring K] [LinearOrder K] [IsStrictOrderedRing K] {f g : Ξ± β†’ K} {l : Filter Ξ±} (hg : Tendsto g l atTop) : (fun x ↦ f x / g x * g x) =αΆ [l] fun x ↦ f x := div_mul_cancel <| hg.mono_right <| le_principal_iff.mpr <| mem_of_superset (Ioi_mem_atTop 0) <| by simp /-- If when `x` tends to `∞`, `g` tends to `∞` and `f x / g x` tends to a positive constant, then `f` tends to `∞`. -/ theorem Filter.Tendsto.num {Ξ± K : Type*} [Field K] [LinearOrder K] [IsStrictOrderedRing K] [TopologicalSpace K] [OrderTopology K] {f g : Ξ± β†’ K} {l : Filter Ξ±} (hg : Tendsto g l atTop) {a : K} (ha : 0 < a) (hlim : Tendsto (fun x => f x / g x) l (𝓝 a)) : Tendsto f l atTop := (hlim.pos_mul_atTop ha hg).congr' (EventuallyEq.div_mul_cancel_atTop hg) /-- If when `x` tends to `∞`, `g` tends to `∞` and `f x / g x` tends to a positive constant, then `f` tends to `∞`. -/ theorem Filter.Tendsto.den {Ξ± K : Type*} [Field K] [LinearOrder K] [IsStrictOrderedRing K] [TopologicalSpace K] [OrderTopology K] [ContinuousInv K] {f g : Ξ± β†’ K} {l : Filter Ξ±} (hf : Tendsto f l atTop) {a : K} (ha : 0 < a) (hlim : Tendsto (fun x => f x / g x) l (𝓝 a)) : Tendsto g l atTop := have hlim' : Tendsto (fun x => g x / f x) l (𝓝 a⁻¹) := by simp_rw [← inv_div (f _)] exact Filter.Tendsto.inv (f := fun x => f x / g x) hlim (hlim'.pos_mul_atTop (inv_pos_of_pos ha) hf).congr' (.div_mul_cancel_atTop hf) /-- If when `x` tends to `∞`, `f x / g x` tends to a positive constant, then `f` tends to `∞` if and only if `g` tends to `∞`. -/ theorem Filter.Tendsto.num_atTop_iff_den_atTop {Ξ± K : Type*} [Field K] [LinearOrder K] [IsStrictOrderedRing K] [TopologicalSpace K] [OrderTopology K] [ContinuousInv K] {f g : Ξ± β†’ K} {l : Filter Ξ±} {a : K} (ha : 0 < a) (hlim : Tendsto (fun x => f x / g x) l (𝓝 a)) : Tendsto f l atTop ↔ Tendsto g l atTop := ⟨fun hf ↦ hf.den ha hlim, fun hg ↦ hg.num ha hlim⟩ /-! ### Powers -/ theorem tendsto_add_one_pow_atTop_atTop_of_pos [Semiring Ξ±] [LinearOrder Ξ±] [IsStrictOrderedRing Ξ±] [Archimedean Ξ±] {r : Ξ±} (h : 0 < r) : Tendsto (fun n : β„• ↦ (r + 1) ^ n) atTop atTop := tendsto_atTop_atTop_of_monotone' (pow_right_monoβ‚€ <| le_add_of_nonneg_left h.le) <| not_bddAbove_iff.2 fun _ ↦ Set.exists_range_iff.2 <| add_one_pow_unbounded_of_pos _ h theorem tendsto_pow_atTop_atTop_of_one_lt [Semiring Ξ±] [LinearOrder Ξ±] [IsStrictOrderedRing Ξ±] [ExistsAddOfLE Ξ±] [Archimedean Ξ±] {r : Ξ±} (h : 1 < r) : Tendsto (fun n : β„• ↦ r ^ n) atTop atTop := by obtain ⟨r, r0, rfl⟩ := exists_pos_add_of_lt' h rw [add_comm] exact tendsto_add_one_pow_atTop_atTop_of_pos r0 theorem tendsto_pow_atTop_nhds_zero_of_lt_one {π•œ : Type*} [Semifield π•œ] [LinearOrder π•œ] [IsStrictOrderedRing π•œ] [ExistsAddOfLE π•œ] [Archimedean π•œ] [TopologicalSpace π•œ] [OrderTopology π•œ] {r : π•œ} (h₁ : 0 ≀ r) (hβ‚‚ : r < 1) : Tendsto (fun n : β„• ↦ r ^ n) atTop (𝓝 0) := h₁.eq_or_lt.elim (fun hr ↦ (tendsto_add_atTop_iff_nat 1).mp <| by simp [_root_.pow_succ, ← hr]) (fun hr ↦ have := (one_lt_invβ‚€ hr).2 hβ‚‚ |> tendsto_pow_atTop_atTop_of_one_lt (tendsto_inv_atTop_zero.comp this).congr fun n ↦ by simp) @[simp] theorem tendsto_pow_atTop_nhds_zero_iff {π•œ : Type*} [Field π•œ] [LinearOrder π•œ] [IsStrictOrderedRing π•œ] [Archimedean π•œ] [TopologicalSpace π•œ] [OrderTopology π•œ] {r : π•œ} : Tendsto (fun n : β„• ↦ r ^ n) atTop (𝓝 0) ↔ |r| < 1 := by rw [tendsto_zero_iff_abs_tendsto_zero] refine ⟨fun h ↦ by_contra (fun hr_le ↦ ?_), fun h ↦ ?_⟩ Β· by_cases hr : 1 = |r| Β· replace h : Tendsto (fun n : β„• ↦ |r| ^ n) atTop (𝓝 0) := by simpa only [← abs_pow, h] simp only [hr.symm, one_pow] at h exact zero_ne_one <| tendsto_nhds_unique h tendsto_const_nhds Β· apply @not_tendsto_nhds_of_tendsto_atTop π•œ β„• _ _ _ _ atTop _ (fun n ↦ |r| ^ n) _ 0 _ Β· refine (pow_right_strictMonoβ‚€ <| lt_of_le_of_ne (le_of_not_gt hr_le) hr).monotone.tendsto_atTop_atTop (fun b ↦ ?_) obtain ⟨n, hn⟩ := (pow_unbounded_of_one_lt b (lt_of_le_of_ne (le_of_not_gt hr_le) hr)) exact ⟨n, le_of_lt hn⟩ Β· simpa only [← abs_pow] Β· simpa only [← abs_pow] using (tendsto_pow_atTop_nhds_zero_of_lt_one (abs_nonneg r)) h theorem tendsto_pow_atTop_nhdsWithin_zero_of_lt_one {π•œ : Type*} [Semifield π•œ] [LinearOrder π•œ] [IsStrictOrderedRing π•œ] [ExistsAddOfLE π•œ] [Archimedean π•œ] [TopologicalSpace π•œ] [OrderTopology π•œ] {r : π•œ} (h₁ : 0 < r) (hβ‚‚ : r < 1) : Tendsto (fun n : β„• ↦ r ^ n) atTop (𝓝[>] 0) := tendsto_inf.2 ⟨tendsto_pow_atTop_nhds_zero_of_lt_one h₁.le hβ‚‚, tendsto_principal.2 <| Eventually.of_forall fun _ ↦ pow_pos h₁ _⟩ theorem uniformity_basis_dist_pow_of_lt_one {Ξ± : Type*} [PseudoMetricSpace Ξ±] {r : ℝ} (hβ‚€ : 0 < r) (h₁ : r < 1) : (uniformity Ξ±).HasBasis (fun _ : β„• ↦ True) fun k ↦ { p : Ξ± Γ— Ξ± | dist p.1 p.2 < r ^ k } := Metric.mk_uniformity_basis (fun _ _ ↦ pow_pos hβ‚€ _) fun _ Ξ΅0 ↦ (exists_pow_lt_of_lt_one Ξ΅0 h₁).imp fun _ hk ↦ ⟨trivial, hk.le⟩ theorem geom_lt {u : β„• β†’ ℝ} {c : ℝ} (hc : 0 ≀ c) {n : β„•} (hn : 0 < n) (h : βˆ€ k < n, c * u k < u (k + 1)) : c ^ n * u 0 < u n := by apply (monotone_mul_left_of_nonneg hc).seq_pos_lt_seq_of_le_of_lt hn _ _ h Β· simp Β· simp [_root_.pow_succ', mul_assoc, le_refl] theorem geom_le {u : β„• β†’ ℝ} {c : ℝ} (hc : 0 ≀ c) (n : β„•) (h : βˆ€ k < n, c * u k ≀ u (k + 1)) : c ^ n * u 0 ≀ u n := by apply (monotone_mul_left_of_nonneg hc).seq_le_seq n _ _ h <;> simp [_root_.pow_succ', mul_assoc, le_refl] theorem lt_geom {u : β„• β†’ ℝ} {c : ℝ} (hc : 0 ≀ c) {n : β„•} (hn : 0 < n) (h : βˆ€ k < n, u (k + 1) < c * u k) : u n < c ^ n * u 0 := by apply (monotone_mul_left_of_nonneg hc).seq_pos_lt_seq_of_lt_of_le hn _ h _ Β· simp Β· simp [_root_.pow_succ', mul_assoc, le_refl] theorem le_geom {u : β„• β†’ ℝ} {c : ℝ} (hc : 0 ≀ c) (n : β„•) (h : βˆ€ k < n, u (k + 1) ≀ c * u k) : u n ≀ c ^ n * u 0 := by apply (monotone_mul_left_of_nonneg hc).seq_le_seq n _ h _ <;> simp [_root_.pow_succ', mul_assoc, le_refl] /-- If a sequence `v` of real numbers satisfies `k * v n ≀ v (n+1)` with `1 < k`, then it goes to +∞. -/ theorem tendsto_atTop_of_geom_le {v : β„• β†’ ℝ} {c : ℝ} (hβ‚€ : 0 < v 0) (hc : 1 < c) (hu : βˆ€ n, c * v n ≀ v (n + 1)) : Tendsto v atTop atTop := (tendsto_atTop_mono fun n ↦ geom_le (zero_le_one.trans hc.le) n fun k _ ↦ hu k) <| (tendsto_pow_atTop_atTop_of_one_lt hc).atTop_mul_const hβ‚€ theorem NNReal.tendsto_pow_atTop_nhds_zero_of_lt_one {r : ℝβ‰₯0} (hr : r < 1) : Tendsto (fun n : β„• ↦ r ^ n) atTop (𝓝 0) := NNReal.tendsto_coe.1 <| by simp only [NNReal.coe_pow, NNReal.coe_zero, _root_.tendsto_pow_atTop_nhds_zero_of_lt_one r.coe_nonneg hr] @[simp] protected theorem NNReal.tendsto_pow_atTop_nhds_zero_iff {r : ℝβ‰₯0} : Tendsto (fun n : β„• => r ^ n) atTop (𝓝 0) ↔ r < 1 := ⟨fun h => by simpa [coe_pow, coe_zero, abs_eq, coe_lt_one, val_eq_coe] using tendsto_pow_atTop_nhds_zero_iff.mp <| tendsto_coe.mpr h, tendsto_pow_atTop_nhds_zero_of_lt_one⟩ theorem ENNReal.tendsto_pow_atTop_nhds_zero_of_lt_one {r : ℝβ‰₯0∞} (hr : r < 1) : Tendsto (fun n : β„• ↦ r ^ n) atTop (𝓝 0) := by rcases ENNReal.lt_iff_exists_coe.1 hr with ⟨r, rfl, hr'⟩ rw [← ENNReal.coe_zero] norm_cast at * apply NNReal.tendsto_pow_atTop_nhds_zero_of_lt_one hr @[simp] protected theorem ENNReal.tendsto_pow_atTop_nhds_zero_iff {r : ℝβ‰₯0∞} : Tendsto (fun n : β„• => r ^ n) atTop (𝓝 0) ↔ r < 1 := by refine ⟨fun h ↦ ?_, tendsto_pow_atTop_nhds_zero_of_lt_one⟩ lift r to NNReal Β· refine fun hr ↦ top_ne_zero (tendsto_nhds_unique (EventuallyEq.tendsto ?_) (hr β–Έ h)) exact eventually_atTop.mpr ⟨1, fun _ hn ↦ pow_eq_top_iff.mpr ⟨rfl, Nat.pos_iff_ne_zero.mp hn⟩⟩ rw [← coe_zero] at h norm_cast at h ⊒ exact NNReal.tendsto_pow_atTop_nhds_zero_iff.mp h @[simp] protected theorem ENNReal.tendsto_pow_atTop_nhds_top_iff {r : ℝβ‰₯0∞} : Tendsto (fun n ↦ r ^ n) atTop (𝓝 ∞) ↔ 1 < r := by refine ⟨?_, ?_⟩ Β· contrapose! intro r_le_one h_tends specialize h_tends (Ioi_mem_nhds one_lt_top) simp only [Filter.mem_map, mem_atTop_sets, ge_iff_le, Set.mem_preimage, Set.mem_Ioi] at h_tends obtain ⟨n, hn⟩ := h_tends exact lt_irrefl _ <| lt_of_lt_of_le (hn n le_rfl) <| pow_le_oneβ‚€ (zero_le _) r_le_one Β· intro r_gt_one have obs := @Tendsto.inv ℝβ‰₯0∞ β„• _ _ _ (fun n ↦ (r⁻¹) ^ n) atTop 0 simp only [ENNReal.tendsto_pow_atTop_nhds_zero_iff, inv_zero] at obs simpa [← ENNReal.inv_pow] using obs <| ENNReal.inv_lt_one.mpr r_gt_one lemma ENNReal.eq_zero_of_le_mul_pow {x r : ℝβ‰₯0∞} {Ξ΅ : ℝβ‰₯0} (hr : r < 1) (h : βˆ€ n : β„•, x ≀ Ξ΅ * r ^ n) : x = 0 := by rw [← nonpos_iff_eq_zero] refine ge_of_tendsto' (f := fun (n : β„•) ↦ Ξ΅ * r ^ n) (x := atTop) ?_ h rw [← mul_zero (Mβ‚€ := ℝβ‰₯0∞) (a := Ξ΅)] exact Tendsto.const_mul (tendsto_pow_atTop_nhds_zero_of_lt_one hr) (Or.inr coe_ne_top) /-! ### Geometric series -/ section Geometric theorem hasSum_geometric_of_lt_one {r : ℝ} (h₁ : 0 ≀ r) (hβ‚‚ : r < 1) : HasSum (fun n : β„• ↦ r ^ n) (1 - r)⁻¹ := have : r β‰  1 := ne_of_lt hβ‚‚ have : Tendsto (fun n ↦ (r ^ n - 1) * (r - 1)⁻¹) atTop (𝓝 ((0 - 1) * (r - 1)⁻¹)) := ((tendsto_pow_atTop_nhds_zero_of_lt_one h₁ hβ‚‚).sub tendsto_const_nhds).mul tendsto_const_nhds (hasSum_iff_tendsto_nat_of_nonneg (pow_nonneg h₁) _).mpr <| by simp_all [neg_inv, geom_sum_eq, div_eq_mul_inv] theorem summable_geometric_of_lt_one {r : ℝ} (h₁ : 0 ≀ r) (hβ‚‚ : r < 1) : Summable fun n : β„• ↦ r ^ n := ⟨_, hasSum_geometric_of_lt_one h₁ hβ‚‚βŸ© theorem tsum_geometric_of_lt_one {r : ℝ} (h₁ : 0 ≀ r) (hβ‚‚ : r < 1) : βˆ‘' n : β„•, r ^ n = (1 - r)⁻¹ := (hasSum_geometric_of_lt_one h₁ hβ‚‚).tsum_eq theorem hasSum_geometric_two : HasSum (fun n : β„• ↦ ((1 : ℝ) / 2) ^ n) 2 := by convert hasSum_geometric_of_lt_one _ _ <;> norm_num theorem summable_geometric_two : Summable fun n : β„• ↦ ((1 : ℝ) / 2) ^ n := ⟨_, hasSum_geometric_two⟩ theorem summable_geometric_two_encode {ΞΉ : Type*} [Encodable ΞΉ] : Summable fun i : ΞΉ ↦ (1 / 2 : ℝ) ^ Encodable.encode i := summable_geometric_two.comp_injective Encodable.encode_injective theorem tsum_geometric_two : (βˆ‘' n : β„•, ((1 : ℝ) / 2) ^ n) = 2 := hasSum_geometric_two.tsum_eq theorem sum_geometric_two_le (n : β„•) : (βˆ‘ i ∈ range n, (1 / (2 : ℝ)) ^ i) ≀ 2 := by have : βˆ€ i, 0 ≀ (1 / (2 : ℝ)) ^ i := by intro i apply pow_nonneg norm_num convert summable_geometric_two.sum_le_tsum (range n) (fun i _ ↦ this i) exact tsum_geometric_two.symm theorem tsum_geometric_inv_two : (βˆ‘' n : β„•, (2 : ℝ)⁻¹ ^ n) = 2 := (inv_eq_one_div (2 : ℝ)).symm β–Έ tsum_geometric_two /-- The sum of `2⁻¹ ^ i` for `n ≀ i` equals `2 * 2⁻¹ ^ n`. -/ theorem tsum_geometric_inv_two_ge (n : β„•) : (βˆ‘' i, ite (n ≀ i) ((2 : ℝ)⁻¹ ^ i) 0) = 2 * 2⁻¹ ^ n := by have A : Summable fun i : β„• ↦ ite (n ≀ i) ((2⁻¹ : ℝ) ^ i) 0 := by simpa only [← piecewise_eq_indicator, one_div] using summable_geometric_two.indicator {i | n ≀ i} have B : ((Finset.range n).sum fun i : β„• ↦ ite (n ≀ i) ((2⁻¹ : ℝ) ^ i) 0) = 0 := Finset.sum_eq_zero fun i hi ↦ ite_eq_right_iff.2 fun h ↦ (lt_irrefl _ ((Finset.mem_range.1 hi).trans_le h)).elim simp only [← Summable.sum_add_tsum_nat_add n A, B, if_true, zero_add, zero_le', le_add_iff_nonneg_left, pow_add, _root_.tsum_mul_right, tsum_geometric_inv_two] theorem hasSum_geometric_two' (a : ℝ) : HasSum (fun n : β„• ↦ a / 2 / 2 ^ n) a := by convert HasSum.mul_left (a / 2) (hasSum_geometric_of_lt_one (le_of_lt one_half_pos) one_half_lt_one) using 1 Β· funext n simp only [one_div, inv_pow] rfl Β· norm_num theorem summable_geometric_two' (a : ℝ) : Summable fun n : β„• ↦ a / 2 / 2 ^ n := ⟨a, hasSum_geometric_two' a⟩ theorem tsum_geometric_two' (a : ℝ) : βˆ‘' n : β„•, a / 2 / 2 ^ n = a := (hasSum_geometric_two' a).tsum_eq /-- **Sum of a Geometric Series** -/ theorem NNReal.hasSum_geometric {r : ℝβ‰₯0} (hr : r < 1) : HasSum (fun n : β„• ↦ r ^ n) (1 - r)⁻¹ := by apply NNReal.hasSum_coe.1 push_cast rw [NNReal.coe_sub (le_of_lt hr)] exact hasSum_geometric_of_lt_one r.coe_nonneg hr theorem NNReal.summable_geometric {r : ℝβ‰₯0} (hr : r < 1) : Summable fun n : β„• ↦ r ^ n := ⟨_, NNReal.hasSum_geometric hr⟩ theorem tsum_geometric_nnreal {r : ℝβ‰₯0} (hr : r < 1) : βˆ‘' n : β„•, r ^ n = (1 - r)⁻¹ := (NNReal.hasSum_geometric hr).tsum_eq /-- The series `pow r` converges to `(1-r)⁻¹`. For `r < 1` the RHS is a finite number, and for `1 ≀ r` the RHS equals `∞`. -/ @[simp] theorem ENNReal.tsum_geometric (r : ℝβ‰₯0∞) : βˆ‘' n : β„•, r ^ n = (1 - r)⁻¹ := by rcases lt_or_ge r 1 with hr | hr Β· rcases ENNReal.lt_iff_exists_coe.1 hr with ⟨r, rfl, hr'⟩ norm_cast at * convert ENNReal.tsum_coe_eq (NNReal.hasSum_geometric hr) rw [ENNReal.coe_inv <| ne_of_gt <| tsub_pos_iff_lt.2 hr, coe_sub, coe_one] Β· rw [tsub_eq_zero_iff_le.mpr hr, ENNReal.inv_zero, ENNReal.tsum_eq_iSup_nat, iSup_eq_top] refine fun a ha ↦ (ENNReal.exists_nat_gt (lt_top_iff_ne_top.1 ha)).imp fun n hn ↦ lt_of_lt_of_le hn ?_ calc (n : ℝβ‰₯0∞) = βˆ‘ i ∈ range n, 1 := by rw [sum_const, nsmul_one, card_range] _ ≀ βˆ‘ i ∈ range n, r ^ i := by gcongr; apply one_le_powβ‚€ hr theorem ENNReal.tsum_geometric_add_one (r : ℝβ‰₯0∞) : βˆ‘' n : β„•, r ^ (n + 1) = r * (1 - r)⁻¹ := by simp only [_root_.pow_succ', ENNReal.tsum_mul_left, ENNReal.tsum_geometric] lemma ENNReal.tsum_two_zpow_neg_add_one : βˆ‘' m : β„•, 2 ^ (-1 - m : β„€) = (1 : ℝβ‰₯0∞) := by simp_rw [neg_sub_left, ENNReal.zpow_neg, ← Nat.cast_one (R := β„€), ← Nat.cast_add, zpow_natCast, ENNReal.inv_pow, ENNReal.tsum_geometric_add_one, one_sub_inv_two, inv_inv] exact ENNReal.inv_mul_cancel (Ne.symm (NeZero.ne' 2)) (Ne.symm top_ne_ofNat) open Encodable protected lemma ENNReal.tsum_geometric_two : βˆ‘' n, (2⁻¹ : ℝβ‰₯0∞) ^ n = 2 := by simp lemma ENNReal.tsum_geometric_two_encode_le_two {ΞΉ : Type*} [Encodable ΞΉ] : βˆ‘' i : ΞΉ, (2⁻¹ : ℝβ‰₯0∞) ^ encode i ≀ 2 := (ENNReal.tsum_comp_le_tsum_of_injective encode_injective _).trans_eq ENNReal.tsum_geometric_two lemma tsum_geometric_lt_top {r : ℝβ‰₯0∞} : βˆ‘' n, r ^ n < ∞ ↔ r < 1 := by simp lemma tsum_geometric_encode_lt_top {r : ℝβ‰₯0∞} (hr : r < 1) {ΞΉ : Type*} [Encodable ΞΉ] : βˆ‘' i : ΞΉ, (r : ℝβ‰₯0∞) ^ encode i < ∞ := (ENNReal.tsum_comp_le_tsum_of_injective encode_injective _).trans_lt <| by simpa end Geometric /-! ### Sequences with geometrically decaying distance in metric spaces In this paragraph, we discuss sequences in metric spaces or emetric spaces for which the distance between two consecutive terms decays geometrically. We show that such sequences are Cauchy sequences, and bound their distances to the limit. We also discuss series with geometrically decaying terms. -/ section EdistLeGeometric variable [PseudoEMetricSpace Ξ±] (r C : ℝβ‰₯0∞) (hr : r < 1) (hC : C β‰  ⊀) {f : β„• β†’ Ξ±} (hu : βˆ€ n, edist (f n) (f (n + 1)) ≀ C * r ^ n) include hr hC hu in /-- If `edist (f n) (f (n+1))` is bounded by `C * r^n`, `C β‰  ∞`, `r < 1`, then `f` is a Cauchy sequence. -/ theorem cauchySeq_of_edist_le_geometric : CauchySeq f := by refine cauchySeq_of_edist_le_of_tsum_ne_top _ hu ?_ rw [ENNReal.tsum_mul_left, ENNReal.tsum_geometric] have := (tsub_pos_iff_lt.2 hr).ne' finiteness include hu in /-- If `edist (f n) (f (n+1))` is bounded by `C * r^n`, then the distance from `f n` to the limit of `f` is bounded above by `C * r^n / (1 - r)`. -/ theorem edist_le_of_edist_le_geometric_of_tendsto {a : Ξ±} (ha : Tendsto f atTop (𝓝 a)) (n : β„•) : edist (f n) a ≀ C * r ^ n / (1 - r) := by convert edist_le_tsum_of_edist_le_of_tendsto _ hu ha _ simp only [pow_add, ENNReal.tsum_mul_left, ENNReal.tsum_geometric, div_eq_mul_inv, mul_assoc] include hu in /-- If `edist (f n) (f (n+1))` is bounded by `C * r^n`, then the distance from `f 0` to the limit of `f` is bounded above by `C / (1 - r)`. -/ theorem edist_le_of_edist_le_geometric_of_tendstoβ‚€ {a : Ξ±} (ha : Tendsto f atTop (𝓝 a)) : edist (f 0) a ≀ C / (1 - r) := by simpa only [_root_.pow_zero, mul_one] using edist_le_of_edist_le_geometric_of_tendsto r C hu ha 0 end EdistLeGeometric section EdistLeGeometricTwo variable [PseudoEMetricSpace Ξ±] (C : ℝβ‰₯0∞) (hC : C β‰  ⊀) {f : β„• β†’ Ξ±} (hu : βˆ€ n, edist (f n) (f (n + 1)) ≀ C / 2 ^ n) {a : Ξ±} (ha : Tendsto f atTop (𝓝 a)) include hC hu in /-- If `edist (f n) (f (n+1))` is bounded by `C * 2^-n`, then `f` is a Cauchy sequence. -/ theorem cauchySeq_of_edist_le_geometric_two : CauchySeq f := by simp only [div_eq_mul_inv, ENNReal.inv_pow] at hu refine cauchySeq_of_edist_le_geometric 2⁻¹ C ?_ hC hu simp include hu ha in /-- If `edist (f n) (f (n+1))` is bounded by `C * 2^-n`, then the distance from `f n` to the limit of `f` is bounded above by `2 * C * 2^-n`. -/ theorem edist_le_of_edist_le_geometric_two_of_tendsto (n : β„•) : edist (f n) a ≀ 2 * C / 2 ^ n := by simp only [div_eq_mul_inv, ENNReal.inv_pow] at * rw [mul_assoc, mul_comm] convert edist_le_of_edist_le_geometric_of_tendsto 2⁻¹ C hu ha n using 1 rw [ENNReal.one_sub_inv_two, div_eq_mul_inv, inv_inv] include hu ha in /-- If `edist (f n) (f (n+1))` is bounded by `C * 2^-n`, then the distance from `f 0` to the limit of `f` is bounded above by `2 * C`. -/ theorem edist_le_of_edist_le_geometric_two_of_tendstoβ‚€ : edist (f 0) a ≀ 2 * C := by simpa only [_root_.pow_zero, div_eq_mul_inv, inv_one, mul_one] using edist_le_of_edist_le_geometric_two_of_tendsto C hu ha 0 end EdistLeGeometricTwo section LeGeometric variable [PseudoMetricSpace Ξ±] {r C : ℝ} {f : β„• β†’ Ξ±} section variable (hr : r < 1) (hu : βˆ€ n, dist (f n) (f (n + 1)) ≀ C * r ^ n) include hr hu /-- If `dist (f n) (f (n+1))` is bounded by `C * r^n`, `r < 1`, then `f` is a Cauchy sequence. -/ theorem aux_hasSum_of_le_geometric : HasSum (fun n : β„• ↦ C * r ^ n) (C / (1 - r)) := by rcases sign_cases_of_C_mul_pow_nonneg fun n ↦ dist_nonneg.trans (hu n) with (rfl | ⟨_, rβ‚€βŸ©) Β· simp [hasSum_zero] Β· refine HasSum.mul_left C ?_ simpa using hasSum_geometric_of_lt_one rβ‚€ hr variable (r C) /-- If `dist (f n) (f (n+1))` is bounded by `C * r^n`, `r < 1`, then `f` is a Cauchy sequence. Note that this lemma does not assume `0 ≀ C` or `0 ≀ r`. -/ theorem cauchySeq_of_le_geometric : CauchySeq f := cauchySeq_of_dist_le_of_summable _ hu ⟨_, aux_hasSum_of_le_geometric hr hu⟩ /-- If `dist (f n) (f (n+1))` is bounded by `C * r^n`, `r < 1`, then the distance from `f n` to the limit of `f` is bounded above by `C * r^n / (1 - r)`. -/ theorem dist_le_of_le_geometric_of_tendstoβ‚€ {a : Ξ±} (ha : Tendsto f atTop (𝓝 a)) : dist (f 0) a ≀ C / (1 - r) := (aux_hasSum_of_le_geometric hr hu).tsum_eq β–Έ dist_le_tsum_of_dist_le_of_tendstoβ‚€ _ hu ⟨_, aux_hasSum_of_le_geometric hr hu⟩ ha /-- If `dist (f n) (f (n+1))` is bounded by `C * r^n`, `r < 1`, then the distance from `f 0` to the limit of `f` is bounded above by `C / (1 - r)`. -/ theorem dist_le_of_le_geometric_of_tendsto {a : Ξ±} (ha : Tendsto f atTop (𝓝 a)) (n : β„•) : dist (f n) a ≀ C * r ^ n / (1 - r) := by have := aux_hasSum_of_le_geometric hr hu convert dist_le_tsum_of_dist_le_of_tendsto _ hu ⟨_, this⟩ ha n simp only [pow_add, mul_left_comm C, mul_div_right_comm] rw [mul_comm] exact (this.mul_left _).tsum_eq.symm end variable (huβ‚‚ : βˆ€ n, dist (f n) (f (n + 1)) ≀ C / 2 / 2 ^ n) include huβ‚‚ /-- If `dist (f n) (f (n+1))` is bounded by `(C / 2) / 2^n`, then `f` is a Cauchy sequence. -/ theorem cauchySeq_of_le_geometric_two : CauchySeq f := cauchySeq_of_dist_le_of_summable _ huβ‚‚ <| ⟨_, hasSum_geometric_two' C⟩ /-- If `dist (f n) (f (n+1))` is bounded by `(C / 2) / 2^n`, then the distance from `f 0` to the limit of `f` is bounded above by `C`. -/ theorem dist_le_of_le_geometric_two_of_tendstoβ‚€ {a : Ξ±} (ha : Tendsto f atTop (𝓝 a)) : dist (f 0) a ≀ C := tsum_geometric_two' C β–Έ dist_le_tsum_of_dist_le_of_tendstoβ‚€ _ huβ‚‚ (summable_geometric_two' C) ha /-- If `dist (f n) (f (n+1))` is bounded by `(C / 2) / 2^n`, then the distance from `f n` to the limit of `f` is bounded above by `C / 2^n`. -/ theorem dist_le_of_le_geometric_two_of_tendsto {a : Ξ±} (ha : Tendsto f atTop (𝓝 a)) (n : β„•) : dist (f n) a ≀ C / 2 ^ n := by convert dist_le_tsum_of_dist_le_of_tendsto _ huβ‚‚ (summable_geometric_two' C) ha n simp only [add_comm n, pow_add, ← div_div] symm exact ((hasSum_geometric_two' C).div_const _).tsum_eq end LeGeometric /-! ### Summability tests based on comparison with geometric series -/ /-- A series whose terms are bounded by the terms of a converging geometric series converges. -/ theorem summable_one_div_pow_of_le {m : ℝ} {f : β„• β†’ β„•} (hm : 1 < m) (fi : βˆ€ i, i ≀ f i) : Summable fun i ↦ 1 / m ^ f i := by refine .of_nonneg_of_le (fun a ↦ by positivity) (fun a ↦ ?_) (summable_geometric_of_lt_one (one_div_nonneg.mpr (zero_le_one.trans hm.le)) ((one_div_lt (zero_lt_one.trans hm) zero_lt_one).mpr (one_div_one.le.trans_lt hm))) rw [div_pow, one_pow] refine (one_div_le_one_div ?_ ?_).mpr (pow_right_monoβ‚€ hm.le (fi a)) <;> exact pow_pos (zero_lt_one.trans hm) _ /-! ### Positive sequences with small sums on countable types -/ /-- For any positive `Ξ΅`, define on an encodable type a positive sequence with sum less than `Ξ΅` -/ def posSumOfEncodable {Ξ΅ : ℝ} (hΞ΅ : 0 < Ξ΅) (ΞΉ) [Encodable ΞΉ] : { Ξ΅' : ΞΉ β†’ ℝ // (βˆ€ i, 0 < Ξ΅' i) ∧ βˆƒ c, HasSum Ξ΅' c ∧ c ≀ Ξ΅ } := by let f n := Ξ΅ / 2 / 2 ^ n have hf : HasSum f Ξ΅ := hasSum_geometric_two' _ have f0 : βˆ€ n, 0 < f n := fun n ↦ div_pos (half_pos hΞ΅) (pow_pos zero_lt_two _) refine ⟨f ∘ Encodable.encode, fun i ↦ f0 _, ?_⟩ rcases hf.summable.comp_injective (@Encodable.encode_injective ΞΉ _) with ⟨c, hg⟩ refine ⟨c, hg, hasSum_le_inj _ (@Encodable.encode_injective ΞΉ _) ?_ ?_ hg hf⟩ Β· intro i _ exact le_of_lt (f0 _) Β· intro n exact le_rfl theorem Set.Countable.exists_pos_hasSum_le {ΞΉ : Type*} {s : Set ΞΉ} (hs : s.Countable) {Ξ΅ : ℝ} (hΞ΅ : 0 < Ξ΅) : βˆƒ Ξ΅' : ΞΉ β†’ ℝ, (βˆ€ i, 0 < Ξ΅' i) ∧ βˆƒ c, HasSum (fun i : s ↦ Ξ΅' i) c ∧ c ≀ Ξ΅ := by classical haveI := hs.toEncodable rcases posSumOfEncodable hΞ΅ s with ⟨f, hf0, ⟨c, hfc, hcΡ⟩⟩ refine ⟨fun i ↦ if h : i ∈ s then f ⟨i, h⟩ else 1, fun i ↦ ?_, ⟨c, ?_, hcΡ⟩⟩ Β· conv_rhs => simp split_ifs exacts [hf0 _, zero_lt_one] Β· simpa only [Subtype.coe_prop, dif_pos, Subtype.coe_eta] theorem Set.Countable.exists_pos_forall_sum_le {ΞΉ : Type*} {s : Set ΞΉ} (hs : s.Countable) {Ξ΅ : ℝ} (hΞ΅ : 0 < Ξ΅) : βˆƒ Ξ΅' : ΞΉ β†’ ℝ, (βˆ€ i, 0 < Ξ΅' i) ∧ βˆ€ t : Finset ΞΉ, ↑t βŠ† s β†’ βˆ‘ i ∈ t, Ξ΅' i ≀ Ξ΅ := by classical rcases hs.exists_pos_hasSum_le hΞ΅ with ⟨Ρ', hpos, c, hΞ΅'c, hcΡ⟩ refine ⟨Ρ', hpos, fun t ht ↦ ?_⟩ rw [← sum_subtype_of_mem _ ht] refine (sum_le_hasSum _ ?_ hΞ΅'c).trans hcΞ΅ exact fun _ _ ↦ (hpos _).le namespace NNReal theorem exists_pos_sum_of_countable {Ξ΅ : ℝβ‰₯0} (hΞ΅ : Ξ΅ β‰  0) (ΞΉ) [Countable ΞΉ] : βˆƒ Ξ΅' : ΞΉ β†’ ℝβ‰₯0, (βˆ€ i, 0 < Ξ΅' i) ∧ βˆƒ c, HasSum Ξ΅' c ∧ c < Ξ΅ := by cases nonempty_encodable ΞΉ obtain ⟨a, a0, aΡ⟩ := exists_between (pos_iff_ne_zero.2 hΞ΅) obtain ⟨Ρ', hΞ΅', c, hc, hcΡ⟩ := posSumOfEncodable a0 ΞΉ exact ⟨fun i ↦ ⟨Ρ' i, (hΞ΅' i).le⟩, fun i ↦ NNReal.coe_lt_coe.1 <| hΞ΅' i, ⟨c, hasSum_le (fun i ↦ (hΞ΅' i).le) hasSum_zero hc⟩, NNReal.hasSum_coe.1 hc, aΞ΅.trans_le' <| NNReal.coe_le_coe.1 hcΡ⟩ end NNReal namespace ENNReal theorem exists_pos_sum_of_countable {Ξ΅ : ℝβ‰₯0∞} (hΞ΅ : Ξ΅ β‰  0) (ΞΉ) [Countable ΞΉ] : βˆƒ Ξ΅' : ΞΉ β†’ ℝβ‰₯0, (βˆ€ i, 0 < Ξ΅' i) ∧ (βˆ‘' i, (Ξ΅' i : ℝβ‰₯0∞)) < Ξ΅ := by rcases exists_between (pos_iff_ne_zero.2 hΞ΅) with ⟨r, h0r, hrΡ⟩ rcases lt_iff_exists_coe.1 hrΞ΅ with ⟨x, rfl, _⟩ rcases NNReal.exists_pos_sum_of_countable (coe_pos.1 h0r).ne' ΞΉ with ⟨Ρ', hp, c, hc, hcr⟩ exact ⟨Ρ', hp, (ENNReal.tsum_coe_eq hc).symm β–Έ lt_trans (coe_lt_coe.2 hcr) hrΡ⟩ theorem exists_pos_sum_of_countable' {Ξ΅ : ℝβ‰₯0∞} (hΞ΅ : Ξ΅ β‰  0) (ΞΉ) [Countable ΞΉ] : βˆƒ Ξ΅' : ΞΉ β†’ ℝβ‰₯0∞, (βˆ€ i, 0 < Ξ΅' i) ∧ βˆ‘' i, Ξ΅' i < Ξ΅ := let ⟨δ, Ξ΄pos, hδ⟩ := exists_pos_sum_of_countable hΞ΅ ΞΉ ⟨fun i ↦ Ξ΄ i, fun i ↦ ENNReal.coe_pos.2 (Ξ΄pos i), hδ⟩ theorem exists_pos_tsum_mul_lt_of_countable {Ξ΅ : ℝβ‰₯0∞} (hΞ΅ : Ξ΅ β‰  0) {ΞΉ} [Countable ΞΉ] (w : ΞΉ β†’ ℝβ‰₯0∞) (hw : βˆ€ i, w i β‰  ∞) : βˆƒ Ξ΄ : ΞΉ β†’ ℝβ‰₯0, (βˆ€ i, 0 < Ξ΄ i) ∧ (βˆ‘' i, (w i * Ξ΄ i : ℝβ‰₯0∞)) < Ξ΅ := by lift w to ΞΉ β†’ ℝβ‰₯0 using hw rcases exists_pos_sum_of_countable hΞ΅ ΞΉ with ⟨δ', Hpos, Hsum⟩ have : βˆ€ i, 0 < max 1 (w i) := fun i ↦ zero_lt_one.trans_le (le_max_left _ _) refine ⟨fun i ↦ Ξ΄' i / max 1 (w i), fun i ↦ div_pos (Hpos _) (this i), ?_⟩ refine lt_of_le_of_lt (ENNReal.tsum_le_tsum fun i ↦ ?_) Hsum rw [coe_div (this i).ne'] refine mul_le_of_le_div' ?_ grw [← le_max_right] end ENNReal /-! ### Factorial -/ theorem factorial_tendsto_atTop : Tendsto Nat.factorial atTop atTop := tendsto_atTop_atTop_of_monotone (fun _ _ ↦ Nat.factorial_le) fun n ↦ ⟨n, n.self_le_factorial⟩ theorem tendsto_factorial_div_pow_self_atTop : Tendsto (fun n ↦ n ! / (n : ℝ) ^ n : β„• β†’ ℝ) atTop (𝓝 0) := tendsto_of_tendsto_of_tendsto_of_le_of_le' tendsto_const_nhds (tendsto_const_div_atTop_nhds_zero_nat 1) (Eventually.of_forall fun n ↦ div_nonneg (mod_cast n.factorial_pos.le) (pow_nonneg (mod_cast n.zero_le) _)) (by refine (eventually_gt_atTop 0).mono fun n hn ↦ ?_ rcases Nat.exists_eq_succ_of_ne_zero hn.ne.symm with ⟨k, rfl⟩ rw [factorial_eq_prod_range_add_one, pow_eq_prod_const, div_eq_mul_inv, ← inv_eq_one_div, prod_natCast, Nat.cast_succ, ← Finset.prod_inv_distrib, ← prod_mul_distrib, Finset.prod_range_succ'] simp only [one_mul, Nat.cast_add, zero_add, Nat.cast_one] refine mul_le_of_le_one_left (inv_nonneg.mpr <| mod_cast hn.le) (prod_le_one ?_ ?_) <;> intro x hx <;> rw [Finset.mem_range] at hx Β· positivity Β· refine (div_le_one <| mod_cast hn).mpr ?_ norm_cast cutsat) /-! ### Ceil and floor -/ section theorem tendsto_nat_floor_atTop {Ξ± : Type*} [Semiring Ξ±] [LinearOrder Ξ±] [IsStrictOrderedRing Ξ±] [FloorSemiring Ξ±] : Tendsto (fun x : Ξ± ↦ ⌊xβŒ‹β‚Š) atTop atTop := Nat.floor_mono.tendsto_atTop_atTop fun x ↦ ⟨max 0 (x + 1), by simp [Nat.le_floor_iff]⟩ lemma tendsto_nat_ceil_atTop {Ξ± : Type*} [Semiring Ξ±] [LinearOrder Ξ±] [IsStrictOrderedRing Ξ±] [FloorSemiring Ξ±] : Tendsto (fun x : Ξ± ↦ ⌈xβŒ‰β‚Š) atTop atTop := by refine Nat.ceil_mono.tendsto_atTop_atTop (fun x ↦ ⟨x, ?_⟩) simp only [Nat.ceil_natCast, le_refl] lemma tendsto_nat_floor_mul_atTop {Ξ± : Type _} [Semifield Ξ±] [LinearOrder Ξ±] [IsStrictOrderedRing Ξ±] [FloorSemiring Ξ±] [Archimedean Ξ±] (a : Ξ±) (ha : 0 < a) : Tendsto (fun (x : β„•) => ⌊a * xβŒ‹β‚Š) atTop atTop := Tendsto.comp tendsto_nat_floor_atTop <| Tendsto.const_mul_atTop ha tendsto_natCast_atTop_atTop variable {R : Type*} [TopologicalSpace R] [Field R] [LinearOrder R] [IsStrictOrderedRing R] [OrderTopology R] [FloorRing R] theorem tendsto_nat_floor_mul_div_atTop {a : R} (ha : 0 ≀ a) : Tendsto (fun x ↦ (⌊a * xβŒ‹β‚Š : R) / x) atTop (𝓝 a) := by have A : Tendsto (fun x : R ↦ a - x⁻¹) atTop (𝓝 (a - 0)) := tendsto_const_nhds.sub tendsto_inv_atTop_zero rw [sub_zero] at A apply tendsto_of_tendsto_of_tendsto_of_le_of_le' A tendsto_const_nhds Β· refine eventually_atTop.2 ⟨1, fun x hx ↦ ?_⟩ simp only [le_div_iffβ‚€ (zero_lt_one.trans_le hx), _root_.sub_mul, inv_mul_cancelβ‚€ (zero_lt_one.trans_le hx).ne'] have := Nat.lt_floor_add_one (a * x) linarith Β· refine eventually_atTop.2 ⟨1, fun x hx ↦ ?_⟩ rw [div_le_iffβ‚€ (zero_lt_one.trans_le hx)] simp [Nat.floor_le (mul_nonneg ha (zero_le_one.trans hx))] theorem tendsto_nat_floor_div_atTop : Tendsto (fun x ↦ (⌊xβŒ‹β‚Š : R) / x) atTop (𝓝 1) := by simpa using tendsto_nat_floor_mul_div_atTop (zero_le_one' R) theorem tendsto_nat_ceil_mul_div_atTop {a : R} (ha : 0 ≀ a) : Tendsto (fun x ↦ (⌈a * xβŒ‰β‚Š : R) / x) atTop (𝓝 a) := by have A : Tendsto (fun x : R ↦ a + x⁻¹) atTop (𝓝 (a + 0)) := tendsto_const_nhds.add tendsto_inv_atTop_zero rw [add_zero] at A apply tendsto_of_tendsto_of_tendsto_of_le_of_le' tendsto_const_nhds A Β· refine eventually_atTop.2 ⟨1, fun x hx ↦ ?_⟩ rw [le_div_iffβ‚€ (zero_lt_one.trans_le hx)] exact Nat.le_ceil _ Β· refine eventually_atTop.2 ⟨1, fun x hx ↦ ?_⟩ simp [div_le_iffβ‚€ (zero_lt_one.trans_le hx), inv_mul_cancelβ‚€ (zero_lt_one.trans_le hx).ne', (Nat.ceil_lt_add_one (mul_nonneg ha (zero_le_one.trans hx))).le, add_mul] theorem tendsto_nat_ceil_div_atTop : Tendsto (fun x ↦ (⌈xβŒ‰β‚Š : R) / x) atTop (𝓝 1) := by simpa using tendsto_nat_ceil_mul_div_atTop (zero_le_one' R) lemma Nat.tendsto_div_const_atTop {n : β„•} (hn : n β‰  0) : Tendsto (Β· / n) atTop atTop := by rw [Tendsto, map_div_atTop_eq_nat n hn.bot_lt] end @[deprecated (since := "2025-10-27")] alias tendsto_inverse_atTop_nhds_zero_nat := tendsto_inv_atTop_nhds_zero_nat @[deprecated (since := "2025-10-27")] alias NNReal.tendsto_inverse_atTop_nhds_zero_nat := tendsto_inv_atTop_nhds_zero_nat @[deprecated (since := "2025-10-27")] alias NNReal.tendsto_const_div_atTop_nhds_zero_nat := tendsto_const_div_atTop_nhds_zero_nat @[deprecated (since := "2025-10-27")] alias NNReal.tendsto_algebraMap_inverse_atTop_nhds_zero_nat := tendsto_algebraMap_inv_atTop_nhds_zero_nat @[deprecated (since := "2025-10-27")] alias tendsto_algebraMap_inverse_atTop_nhds_zero_nat := tendsto_algebraMap_inv_atTop_nhds_zero_nat @[deprecated (since := "2025-10-27")] protected alias Nat.tendsto_pow_atTop_atTop_of_one_lt := tendsto_pow_atTop_atTop_of_one_lt
.lake/packages/mathlib/Mathlib/Analysis/SpecificLimits/ArithmeticGeometric.lean
import Mathlib.Analysis.SpecificLimits.Basic /-! # Arithmetic-geometric sequences An arithmetic-geometric sequence is a sequence defined by the recurrence relation `u (n + 1) = a * u n + b`. ## Main definitions * `arithGeom a b uβ‚€`: arithmetic-geometric sequence with starting value `uβ‚€` and recurrence relation `u (n + 1) = a * u n + b`. ## Main statements * `arithGeom_eq`: for `a β‰  1`, `arithGeom a b uβ‚€ n = a ^ n * (uβ‚€ - (b / (1 - a))) + b / (1 - a)` * `tendsto_arithGeom_atTop_of_one_lt`: if `1 < a` and `b / (1 - a) < uβ‚€`, then `arithGeom a b uβ‚€ n` tends to `+∞` as `n` tends to `+∞`. `tendsto_arithGeom_nhds_of_lt_one`: if `0 ≀ a < 1`, then `arithGeom a b uβ‚€ n` tends to `b / (1 - a)` as `n` tends to `+∞`. * `arithGeom_strictMono`: if `1 < a` and `b / (1 - a) < uβ‚€`, then `arithGeom a b uβ‚€` is strictly monotone. -/ open Filter Topology variable {R : Type*} {a b uβ‚€ : R} /-- Arithmetic-geometric sequence with starting value `uβ‚€` and recurrence relation `u (n + 1) = a * u n + b`. -/ def arithGeom [Mul R] [Add R] (a b uβ‚€ : R) : β„• β†’ R | 0 => uβ‚€ | n + 1 => a * arithGeom a b uβ‚€ n + b @[simp] lemma arithGeom_zero [Mul R] [Add R] : arithGeom a b uβ‚€ 0 = uβ‚€ := rfl lemma arithGeom_succ [Mul R] [Add R] (n : β„•) : arithGeom a b uβ‚€ (n + 1) = a * arithGeom a b uβ‚€ n + b := rfl lemma arithGeom_eq_add_sum [CommSemiring R] (n : β„•) : arithGeom a b uβ‚€ n = a ^ n * uβ‚€ + b * βˆ‘ k ∈ Finset.range n, a ^ k := by induction n with | zero => simp | succ n hn => rw [arithGeom_succ, hn, mul_add, ← mul_assoc, add_comm n, pow_add, pow_one, add_assoc] congr rw [add_comm _ n, Finset.sum_range_succ', Finset.mul_sum, pow_zero, mul_add, mul_one, Finset.mul_sum, Finset.mul_sum] congr with k ring lemma arithGeom_same_eq_sum [CommSemiring R] (n : β„•) : arithGeom a b b n = b * βˆ‘ k ∈ Finset.range (n + 1), a ^ k := by rw [arithGeom_eq_add_sum, Finset.sum_range_succ, mul_add, add_comm, mul_comm _ b] lemma arithGeom_zero_eq_sum [CommSemiring R] (n : β„•) : arithGeom a b 0 n = b * βˆ‘ k ∈ Finset.range n, a ^ k := by simp [arithGeom_eq_add_sum] variable [Field R] lemma arithGeom_eq (ha : a β‰  1) (n : β„•) : arithGeom a b uβ‚€ n = a ^ n * (uβ‚€ - (b / (1 - a))) + b / (1 - a) := by induction n with | zero => simp | succ n hn => unfold arithGeom; grind lemma arithGeom_eq' (ha : a β‰  1) : arithGeom a b uβ‚€ = fun n ↦ a ^ n * (uβ‚€ - (b / (1 - a))) + b / (1 - a) := by ext exact arithGeom_eq ha _ lemma arithGeom_same_eq_mul_div' (ha : a β‰  1) (n : β„•) : arithGeom a b b n = b * (1 - a ^ (n + 1)) / (1 - a) := by rw [arithGeom_eq ha n] field [sub_ne_zero.mpr ha.symm] lemma arithGeom_same_eq_mul_div (ha : a β‰  1) (n : β„•) : arithGeom a b b n = b * (a ^ (n + 1) - 1) / (a - 1) := by rw [arithGeom_same_eq_mul_div' ha n, ← neg_sub _ a, div_neg, ← neg_sub _ (a ^ (n + 1)), mul_neg, neg_div, neg_neg] lemma arithGeom_zero_eq_mul_div' (ha : a β‰  1) (n : β„•) : arithGeom a b 0 n = b * (1 - a ^ n) / (1 - a) := by rw [arithGeom_eq ha n] ring lemma arithGeom_zero_eq_mul_div (ha : a β‰  1) (n : β„•) : arithGeom a b 0 n = b * (a ^ n - 1) / (a - 1) := by rw [arithGeom_zero_eq_mul_div' ha n, ← neg_sub _ a, div_neg, ← neg_sub _ (a ^ n), mul_neg, neg_div, neg_neg] variable [LinearOrder R] [IsStrictOrderedRing R] lemma div_lt_arithGeom (ha_pos : 0 < a) (ha_ne : a β‰  1) (h0 : b / (1 - a) < uβ‚€) (n : β„•) : b / (1 - a) < arithGeom a b uβ‚€ n := by induction n with | zero => exact h0 | succ n hn => calc b / (1 - a) _ = a * (b / (1 - a)) + b := by grind _ < a * arithGeom a b uβ‚€ n + b := by gcongr lemma arithGeom_strictMono (ha : 1 < a) (h0 : b / (1 - a) < uβ‚€) : StrictMono (arithGeom a b uβ‚€) := by refine strictMono_nat_of_lt_succ fun n ↦ ?_ have h_lt : b / (1 - a) < arithGeom a b uβ‚€ n := div_lt_arithGeom (by positivity) ha.ne' h0 n rw [div_lt_iff_of_neg (sub_neg.mpr ha)] at h_lt rw [arithGeom_succ] linarith lemma tendsto_arithGeom_atTop_of_one_lt [Archimedean R] (ha : 1 < a) (h0 : b / (1 - a) < uβ‚€) : Tendsto (arithGeom a b uβ‚€) atTop atTop := by rw [arithGeom_eq' ha.ne'] refine tendsto_atTop_add_const_right _ _ ?_ refine Tendsto.atTop_mul_const (sub_pos.mpr h0) ?_ exact tendsto_pow_atTop_atTop_of_one_lt ha lemma tendsto_arithGeom_nhds_of_lt_one [Archimedean R] [TopologicalSpace R] [OrderTopology R] (ha_pos : 0 ≀ a) (ha : a < 1) : Tendsto (arithGeom a b uβ‚€) atTop (𝓝 (b / (1 - a))) := by rw [arithGeom_eq' ha.ne] conv_rhs => rw [← zero_add (b / (1 - a))] refine Tendsto.add ?_ tendsto_const_nhds conv_rhs => rw [← zero_mul (uβ‚€ - (b / (1 - a)))] exact (tendsto_pow_atTop_nhds_zero_of_lt_one ha_pos ha).mul_const _
.lake/packages/mathlib/Mathlib/Analysis/SpecificLimits/FloorPow.lean
import Mathlib.Algebra.Order.Field.GeomSum import Mathlib.Analysis.SpecificLimits.Basic import Mathlib.Analysis.SpecialFunctions.Pow.Real /-! # Results on discretized exponentials We state several auxiliary results pertaining to sequences of the form `⌊c^nβŒ‹β‚Š`. * `tendsto_div_of_monotone_of_tendsto_div_floor_pow`: If a monotone sequence `u` is such that `u ⌊c^nβŒ‹β‚Š / ⌊c^nβŒ‹β‚Š` converges to a limit `l` for all `c > 1`, then `u n / n` tends to `l`. * `sum_div_nat_floor_pow_sq_le_div_sq`: The sum of `1/⌊c^iβŒ‹β‚Š^2` above a threshold `j` is comparable to `1/j^2`, up to a multiplicative constant. -/ open Filter Finset open Topology /-- If a monotone sequence `u` is such that `u n / n` tends to a limit `l` along subsequences with exponential growth rate arbitrarily close to `1`, then `u n / n` tends to `l`. -/ theorem tendsto_div_of_monotone_of_exists_subseq_tendsto_div (u : β„• β†’ ℝ) (l : ℝ) (hmono : Monotone u) (hlim : βˆ€ a : ℝ, 1 < a β†’ βˆƒ c : β„• β†’ β„•, (βˆ€αΆ  n in atTop, (c (n + 1) : ℝ) ≀ a * c n) ∧ Tendsto c atTop atTop ∧ Tendsto (fun n => u (c n) / c n) atTop (𝓝 l)) : Tendsto (fun n => u n / n) atTop (𝓝 l) := by /- To check the result up to some `Ξ΅ > 0`, we use a sequence `c` for which the ratio `c (N+1) / c N` is bounded by `1 + Ξ΅`. Sandwiching a given `n` between two consecutive values of `c`, say `c N` and `c (N+1)`, one can then bound `u n / n` from above by `u (c N) / c (N - 1)` and from below by `u (c (N - 1)) / c N` (using that `u` is monotone), which are both comparable to the limit `l` up to `1 + Ξ΅`. We give a version of this proof by clearing out denominators first, to avoid discussing the sign of different quantities. -/ have lnonneg : 0 ≀ l := by rcases hlim 2 one_lt_two with ⟨c, _, ctop, clim⟩ have : Tendsto (fun n => u 0 / c n) atTop (𝓝 0) := tendsto_const_nhds.div_atTop (tendsto_natCast_atTop_iff.2 ctop) apply le_of_tendsto_of_tendsto' this clim fun n => ?_ gcongr exact hmono (zero_le _) have A : βˆ€ Ξ΅ : ℝ, 0 < Ξ΅ β†’ βˆ€αΆ  n in atTop, u n - n * l ≀ Ξ΅ * (1 + Ξ΅ + l) * n := by intro Ξ΅ Ξ΅pos rcases hlim (1 + Ξ΅) ((lt_add_iff_pos_right _).2 Ξ΅pos) with ⟨c, cgrowth, ctop, clim⟩ have L : βˆ€αΆ  n in atTop, u (c n) - c n * l ≀ Ξ΅ * c n := by rw [← tendsto_sub_nhds_zero_iff, ← Asymptotics.isLittleO_one_iff ℝ, Asymptotics.isLittleO_iff] at clim filter_upwards [clim Ξ΅pos, ctop (Ioi_mem_atTop 0)] with n hn cnpos' have cnpos : 0 < c n := cnpos' calc u (c n) - c n * l = (u (c n) / c n - l) * c n := by field _ ≀ Ξ΅ * c n := by gcongr refine (le_abs_self _).trans ?_ simpa using hn obtain ⟨a, ha⟩ : βˆƒ a : β„•, βˆ€ b : β„•, a ≀ b β†’ (c (b + 1) : ℝ) ≀ (1 + Ξ΅) * c b ∧ u (c b) - c b * l ≀ Ξ΅ * c b := eventually_atTop.1 (cgrowth.and L) let M := ((Finset.range (a + 1)).image fun i => c i).max' (by simp) filter_upwards [Ici_mem_atTop M] with n hn have exN : βˆƒ N, n < c N := by rcases (tendsto_atTop.1 ctop (n + 1)).exists with ⟨N, hN⟩ exact ⟨N, by cutsat⟩ let N := Nat.find exN have ncN : n < c N := Nat.find_spec exN have aN : a + 1 ≀ N := by by_contra! h have cNM : c N ≀ M := by apply le_max' apply mem_image_of_mem exact mem_range.2 h exact lt_irrefl _ ((cNM.trans hn).trans_lt ncN) have Npos : 0 < N := lt_of_lt_of_le Nat.succ_pos' aN have cNn : c (N - 1) ≀ n := by have : N - 1 < N := Nat.pred_lt Npos.ne' simpa only [not_lt] using Nat.find_min exN this have IcN : (c N : ℝ) ≀ (1 + Ξ΅) * c (N - 1) := by have A : a ≀ N - 1 := by apply @Nat.le_of_add_le_add_right a 1 (N - 1) rw [Nat.sub_add_cancel Npos] exact aN have B : N - 1 + 1 = N := Nat.succ_pred_eq_of_pos Npos have := (ha _ A).1 rwa [B] at this calc u n - n * l ≀ u (c N) - c (N - 1) * l := by gcongr; exact hmono ncN.le _ = u (c N) - c N * l + (c N - c (N - 1)) * l := by ring _ ≀ Ξ΅ * c N + Ξ΅ * c (N - 1) * l := by gcongr Β· exact (ha N (a.le_succ.trans aN)).2 Β· linarith only [IcN] _ ≀ Ξ΅ * ((1 + Ξ΅) * c (N - 1)) + Ξ΅ * c (N - 1) * l := by gcongr _ = Ξ΅ * (1 + Ξ΅ + l) * c (N - 1) := by ring _ ≀ Ξ΅ * (1 + Ξ΅ + l) * n := by gcongr have B : βˆ€ Ξ΅ : ℝ, 0 < Ξ΅ β†’ βˆ€αΆ  n : β„• in atTop, (n : ℝ) * l - u n ≀ Ξ΅ * (1 + l) * n := by intro Ξ΅ Ξ΅pos rcases hlim (1 + Ξ΅) ((lt_add_iff_pos_right _).2 Ξ΅pos) with ⟨c, cgrowth, ctop, clim⟩ have L : βˆ€αΆ  n : β„• in atTop, (c n : ℝ) * l - u (c n) ≀ Ξ΅ * c n := by rw [← tendsto_sub_nhds_zero_iff, ← Asymptotics.isLittleO_one_iff ℝ, Asymptotics.isLittleO_iff] at clim filter_upwards [clim Ξ΅pos, ctop (Ioi_mem_atTop 0)] with n hn cnpos' have cnpos : 0 < c n := cnpos' calc (c n : ℝ) * l - u (c n) = -(u (c n) / c n - l) * c n := by field _ ≀ Ξ΅ * c n := by gcongr refine le_trans (neg_le_abs _) ?_ simpa using hn obtain ⟨a, ha⟩ : βˆƒ a : β„•, βˆ€ b : β„•, a ≀ b β†’ (c (b + 1) : ℝ) ≀ (1 + Ξ΅) * c b ∧ (c b : ℝ) * l - u (c b) ≀ Ξ΅ * c b := eventually_atTop.1 (cgrowth.and L) let M := ((Finset.range (a + 1)).image fun i => c i).max' (by simp) filter_upwards [Ici_mem_atTop M] with n hn have exN : βˆƒ N, n < c N := by rcases (tendsto_atTop.1 ctop (n + 1)).exists with ⟨N, hN⟩ exact ⟨N, by cutsat⟩ let N := Nat.find exN have ncN : n < c N := Nat.find_spec exN have aN : a + 1 ≀ N := by by_contra! h have cNM : c N ≀ M := by apply le_max' apply mem_image_of_mem exact mem_range.2 h exact lt_irrefl _ ((cNM.trans hn).trans_lt ncN) have Npos : 0 < N := lt_of_lt_of_le Nat.succ_pos' aN have aN' : a ≀ N - 1 := by apply @Nat.le_of_add_le_add_right a 1 (N - 1) rw [Nat.sub_add_cancel Npos] exact aN have cNn : c (N - 1) ≀ n := by have : N - 1 < N := Nat.pred_lt Npos.ne' simpa only [not_lt] using Nat.find_min exN this calc (n : ℝ) * l - u n ≀ c N * l - u (c (N - 1)) := by gcongr exact hmono cNn _ ≀ (1 + Ξ΅) * c (N - 1) * l - u (c (N - 1)) := by gcongr have B : N - 1 + 1 = N := Nat.succ_pred_eq_of_pos Npos simpa [B] using (ha _ aN').1 _ = c (N - 1) * l - u (c (N - 1)) + Ξ΅ * c (N - 1) * l := by ring _ ≀ Ξ΅ * c (N - 1) + Ξ΅ * c (N - 1) * l := add_le_add (ha _ aN').2 le_rfl _ = Ξ΅ * (1 + l) * c (N - 1) := by ring _ ≀ Ξ΅ * (1 + l) * n := by gcongr refine tendsto_order.2 ⟨fun d hd => ?_, fun d hd => ?_⟩ Β· obtain ⟨Ρ, hΞ΅, Ξ΅pos⟩ : βˆƒ Ξ΅ : ℝ, d + Ξ΅ * (1 + l) < l ∧ 0 < Ξ΅ := by have L : Tendsto (fun Ξ΅ => d + Ξ΅ * (1 + l)) (𝓝[>] 0) (𝓝 (d + 0 * (1 + l))) := by apply Tendsto.mono_left _ nhdsWithin_le_nhds exact tendsto_const_nhds.add (tendsto_id.mul tendsto_const_nhds) simp only [zero_mul, add_zero] at L exact (((tendsto_order.1 L).2 l hd).and self_mem_nhdsWithin).exists filter_upwards [B Ξ΅ Ξ΅pos, Ioi_mem_atTop 0] with n hn npos simp_rw [div_eq_inv_mul] calc d < (n : ℝ)⁻¹ * n * (l - Ξ΅ * (1 + l)) := by rw [inv_mul_cancelβ‚€, one_mul] Β· linarith only [hΞ΅] Β· exact Nat.cast_ne_zero.2 (ne_of_gt npos) _ = (n : ℝ)⁻¹ * (n * l - Ξ΅ * (1 + l) * n) := by ring _ ≀ (n : ℝ)⁻¹ * u n := by gcongr; linarith only [hn] Β· obtain ⟨Ρ, hΞ΅, Ξ΅pos⟩ : βˆƒ Ξ΅ : ℝ, l + Ξ΅ * (1 + Ξ΅ + l) < d ∧ 0 < Ξ΅ := by have L : Tendsto (fun Ξ΅ => l + Ξ΅ * (1 + Ξ΅ + l)) (𝓝[>] 0) (𝓝 (l + 0 * (1 + 0 + l))) := by apply Tendsto.mono_left _ nhdsWithin_le_nhds exact tendsto_const_nhds.add (tendsto_id.mul ((tendsto_const_nhds.add tendsto_id).add tendsto_const_nhds)) simp only [zero_mul, add_zero] at L exact (((tendsto_order.1 L).2 d hd).and self_mem_nhdsWithin).exists filter_upwards [A Ξ΅ Ξ΅pos, Ioi_mem_atTop 0] with n hn (npos : 0 < n) calc u n / n ≀ (n * l + Ξ΅ * (1 + Ξ΅ + l) * n) / n := by gcongr; linarith only [hn] _ = (l + Ξ΅ * (1 + Ξ΅ + l)) := by field _ < d := hΞ΅ /-- If a monotone sequence `u` is such that `u ⌊c^nβŒ‹β‚Š / ⌊c^nβŒ‹β‚Š` converges to a limit `l` for all `c > 1`, then `u n / n` tends to `l`. It is even enough to have the assumption for a sequence of `c`s converging to `1`. -/ theorem tendsto_div_of_monotone_of_tendsto_div_floor_pow (u : β„• β†’ ℝ) (l : ℝ) (hmono : Monotone u) (c : β„• β†’ ℝ) (cone : βˆ€ k, 1 < c k) (clim : Tendsto c atTop (𝓝 1)) (hc : βˆ€ k, Tendsto (fun n : β„• => u ⌊c k ^ nβŒ‹β‚Š / ⌊c k ^ nβŒ‹β‚Š) atTop (𝓝 l)) : Tendsto (fun n => u n / n) atTop (𝓝 l) := by apply tendsto_div_of_monotone_of_exists_subseq_tendsto_div u l hmono intro a ha obtain ⟨k, hk⟩ : βˆƒ k, c k < a := ((tendsto_order.1 clim).2 a ha).exists refine ⟨fun n => ⌊c k ^ nβŒ‹β‚Š, ?_, (tendsto_nat_floor_atTop (Ξ± := ℝ)).comp (tendsto_pow_atTop_atTop_of_one_lt (cone k)), hc k⟩ have H : βˆ€ n : β„•, (0 : ℝ) < ⌊c k ^ nβŒ‹β‚Š := by intro n refine zero_lt_one.trans_le ?_ simp only [Nat.one_le_cast, Nat.one_le_floor_iff, one_le_powβ‚€ (cone k).le] have A : Tendsto (fun n : β„• => (⌊c k ^ (n + 1)βŒ‹β‚Š : ℝ) / c k ^ (n + 1) * c k / (⌊c k ^ nβŒ‹β‚Š / c k ^ n)) atTop (𝓝 (1 * c k / 1)) := by refine Tendsto.div (Tendsto.mul ?_ tendsto_const_nhds) ?_ one_ne_zero Β· refine tendsto_nat_floor_div_atTop.comp ?_ exact (tendsto_pow_atTop_atTop_of_one_lt (cone k)).comp (tendsto_add_atTop_nat 1) Β· refine tendsto_nat_floor_div_atTop.comp ?_ exact tendsto_pow_atTop_atTop_of_one_lt (cone k) have B : Tendsto (fun n : β„• => (⌊c k ^ (n + 1)βŒ‹β‚Š : ℝ) / ⌊c k ^ nβŒ‹β‚Š) atTop (𝓝 (c k)) := by simp only [one_mul, div_one] at A convert A using 1 ext1 n field [(zero_lt_one.trans (cone k)).ne'] filter_upwards [(tendsto_order.1 B).2 a hk] with n hn exact (div_le_iffβ‚€ (H n)).1 hn.le /-- The sum of `1/(c^i)^2` above a threshold `j` is comparable to `1/j^2`, up to a multiplicative constant. -/ theorem sum_div_pow_sq_le_div_sq (N : β„•) {j : ℝ} (hj : 0 < j) {c : ℝ} (hc : 1 < c) : (βˆ‘ i ∈ range N with j < c ^ i, (1 : ℝ) / (c ^ i) ^ 2) ≀ c ^ 3 * (c - 1)⁻¹ / j ^ 2 := by have cpos : 0 < c := zero_lt_one.trans hc have A : (0 : ℝ) < c⁻¹ ^ 2 := sq_pos_of_pos (inv_pos.2 cpos) have B : c ^ 2 * ((1 : ℝ) - c⁻¹ ^ 2)⁻¹ ≀ c ^ 3 * (c - 1)⁻¹ := by rw [← div_eq_mul_inv, ← div_eq_mul_inv, div_le_div_iffβ‚€ _ (sub_pos.2 hc)] swap Β· exact sub_pos.2 (pow_lt_oneβ‚€ (inv_nonneg.2 cpos.le) (inv_lt_one_of_one_ltβ‚€ hc) two_ne_zero) have : c ^ 3 = c ^ 2 * c := by ring simp only [mul_sub, this, mul_one, inv_pow, sub_le_sub_iff_left] rw [mul_assoc, mul_comm c, ← mul_assoc, mul_inv_cancelβ‚€ (sq_pos_of_pos cpos).ne', one_mul] simpa using pow_right_monoβ‚€ hc.le one_le_two have C : c⁻¹ ^ 2 < 1 := pow_lt_oneβ‚€ (inv_nonneg.2 cpos.le) (inv_lt_one_of_one_ltβ‚€ hc) two_ne_zero calc (βˆ‘ i ∈ range N with j < c ^ i, (1 : ℝ) / (c ^ i) ^ 2) ≀ βˆ‘ i ∈ Ico ⌊Real.log j / Real.log cβŒ‹β‚Š N, (1 : ℝ) / (c ^ i) ^ 2 := by gcongr intro i hi simp only [mem_filter, mem_range] at hi simp only [hi.1, mem_Ico, and_true] apply Nat.floor_le_of_le apply le_of_lt rw [div_lt_iffβ‚€ (Real.log_pos hc), ← Real.log_pow] exact Real.log_lt_log hj hi.2 _ = βˆ‘ i ∈ Ico ⌊Real.log j / Real.log cβŒ‹β‚Š N, (c⁻¹ ^ 2) ^ i := by simp [← pow_mul, mul_comm] _ ≀ (c⁻¹ ^ 2) ^ ⌊Real.log j / Real.log cβŒ‹β‚Š / ((1 : ℝ) - c⁻¹ ^ 2) := geom_sum_Ico_le_of_lt_one (sq_nonneg _) C _ ≀ (c⁻¹ ^ 2) ^ (Real.log j / Real.log c - 1) / ((1 : ℝ) - c⁻¹ ^ 2) := by gcongr Β· exact sub_nonneg.2 C.le Β· rw [← Real.rpow_natCast] exact Real.rpow_le_rpow_of_exponent_ge A C.le (Nat.sub_one_lt_floor _).le _ = c ^ 2 * ((1 : ℝ) - c⁻¹ ^ 2)⁻¹ / j ^ 2 := by have I : (c⁻¹ ^ 2) ^ (Real.log j / Real.log c) = (1 : ℝ) / j ^ 2 := by apply Real.log_injOn_pos (Real.rpow_pos_of_pos A _) Β· rw [Set.mem_Ioi]; positivity rw [Real.log_rpow A] simp only [one_div, Real.log_inv, Real.log_pow, mul_neg, neg_inj] field [(Real.log_pos hc).ne'] rw [Real.rpow_sub A, I] simp ring _ ≀ c ^ 3 * (c - 1)⁻¹ / j ^ 2 := by gcongr theorem mul_pow_le_nat_floor_pow {c : ℝ} (hc : 1 < c) (i : β„•) : (1 - c⁻¹) * c ^ i ≀ ⌊c ^ iβŒ‹β‚Š := by have cpos : 0 < c := zero_lt_one.trans hc rcases eq_or_ne i 0 with (rfl | hi) Β· simp only [pow_zero, Nat.floor_one, Nat.cast_one, mul_one, sub_le_self_iff, inv_nonneg, cpos.le] calc (1 - c⁻¹) * c ^ i = c ^ i - c ^ i * c⁻¹ := by ring _ ≀ c ^ i - 1 := by gcongr simpa only [← div_eq_mul_inv, one_le_div cpos, pow_one] using le_self_powβ‚€ hc.le hi _ ≀ ⌊c ^ iβŒ‹β‚Š := (Nat.sub_one_lt_floor _).le /-- The sum of `1/⌊c^iβŒ‹β‚Š^2` above a threshold `j` is comparable to `1/j^2`, up to a multiplicative constant. -/ theorem sum_div_nat_floor_pow_sq_le_div_sq (N : β„•) {j : ℝ} (hj : 0 < j) {c : ℝ} (hc : 1 < c) : (βˆ‘ i ∈ range N with j < ⌊c ^ iβŒ‹β‚Š, (1 : ℝ) / (⌊c ^ iβŒ‹β‚Š : ℝ) ^ 2) ≀ c ^ 5 * (c - 1)⁻¹ ^ 3 / j ^ 2 := by have cpos : 0 < c := zero_lt_one.trans hc have A : 0 < 1 - c⁻¹ := sub_pos.2 (inv_lt_one_of_one_ltβ‚€ hc) calc (βˆ‘ i ∈ range N with j < ⌊c ^ iβŒ‹β‚Š, (1 : ℝ) / (⌊c ^ iβŒ‹β‚Š : ℝ) ^ 2) ≀ βˆ‘ i ∈ range N with j < c ^ i, (1 : ℝ) / (⌊c ^ iβŒ‹β‚Š : ℝ) ^ 2 := by gcongr with k hk; exact Nat.floor_le (by positivity) _ ≀ βˆ‘ i ∈ range N with j < c ^ i, (1 - c⁻¹)⁻¹ ^ 2 * ((1 : ℝ) / (c ^ i) ^ 2) := by gcongr with i rw [mul_div_assoc', mul_one, div_le_div_iffβ‚€]; rotate_left Β· apply sq_pos_of_pos refine zero_lt_one.trans_le ?_ simp only [Nat.le_floor, one_le_powβ‚€, hc.le, Nat.one_le_cast, Nat.cast_one] Β· exact sq_pos_of_pos (pow_pos cpos _) rw [one_mul, ← mul_pow] gcongr rw [← div_eq_inv_mul, le_div_iffβ‚€ A, mul_comm] exact mul_pow_le_nat_floor_pow hc i _ ≀ (1 - c⁻¹)⁻¹ ^ 2 * (c ^ 3 * (c - 1)⁻¹) / j ^ 2 := by rw [← mul_sum, ← mul_div_assoc'] gcongr exact sum_div_pow_sq_le_div_sq N hj hc _ = c ^ 5 * (c - 1)⁻¹ ^ 3 / j ^ 2 := by congr 1 field
.lake/packages/mathlib/Mathlib/Analysis/AbsoluteValue/Equivalence.lean
import Mathlib.Analysis.SpecialFunctions.Pow.Real import Mathlib.Analysis.Normed.Field.WithAbs /-! # Equivalence of real-valued absolute values Two absolute values `v₁, vβ‚‚ : AbsoluteValue R ℝ` are *equivalent* if there exists a positive real number `c` such that `v₁ x ^ c = vβ‚‚ x` for all `x : R`. -/ namespace AbsoluteValue section OrderedSemiring variable {R : Type*} [Semiring R] {S : Type*} [Semiring S] [PartialOrder S] (v w : AbsoluteValue R S) /-- Two absolute values `v` and `w` are *equivalent* if `v x ≀ v y` precisely when `w x ≀ w y`. Note that for real absolute values this condition is equivalent to the existence of a positive real number `c` such that `v x ^ c = w x` for all `x`. See `AbsoluteValue.isEquiv_iff_exists_rpow_eq`. -/ def IsEquiv : Prop := βˆ€ x y, v x ≀ v y ↔ w x ≀ w y theorem IsEquiv.refl : v.IsEquiv v := fun _ _ ↦ .rfl variable {v w} theorem IsEquiv.rfl : v.IsEquiv v := fun _ _ ↦ .rfl theorem IsEquiv.symm (h : v.IsEquiv w) : w.IsEquiv v := fun _ _ ↦ (h _ _).symm theorem IsEquiv.trans {u : AbsoluteValue R S} (h₁ : v.IsEquiv w) (hβ‚‚ : w.IsEquiv u) : v.IsEquiv u := fun _ _ ↦ (h₁ _ _).trans (hβ‚‚ _ _) @[deprecated (since := "2025-09-12")] alias isEquiv_refl := IsEquiv.refl @[deprecated (since := "2025-09-12")] alias isEquiv_symm := IsEquiv.symm @[deprecated (since := "2025-09-12")] alias isEquiv_trans := IsEquiv.trans instance : Setoid (AbsoluteValue R S) where r := IsEquiv iseqv := { refl := .refl symm := .symm trans := .trans } theorem IsEquiv.le_iff_le (h : v.IsEquiv w) {x y : R} : v x ≀ v y ↔ w x ≀ w y := h .. theorem IsEquiv.lt_iff_lt (h : v.IsEquiv w) {x y : R} : v x < v y ↔ w x < w y := lt_iff_lt_of_le_iff_le' (h y x) (h x y) theorem IsEquiv.eq_iff_eq (h : v.IsEquiv w) {x y : R} : v x = v y ↔ w x = w y := by simp [le_antisymm_iff, h x y, h y x] variable [IsDomain S] [Nontrivial R] theorem IsEquiv.lt_one_iff (h : v.IsEquiv w) {x : R} : v x < 1 ↔ w x < 1 := by simpa only [map_one] using h.lt_iff_lt (y := 1) theorem IsEquiv.one_lt_iff (h : v.IsEquiv w) {x : R} : 1 < v x ↔ 1 < w x := by simpa only [map_one] using h.lt_iff_lt (x := 1) theorem IsEquiv.le_one_iff (h : v.IsEquiv w) {x : R} : v x ≀ 1 ↔ w x ≀ 1 := by simpa only [map_one] using h x 1 theorem IsEquiv.one_le_iff (h : v.IsEquiv w) {x : R} : 1 ≀ v x ↔ 1 ≀ w x := by simpa only [map_one] using h 1 x theorem IsEquiv.eq_one_iff (h : v.IsEquiv w) {x : R} : v x = 1 ↔ w x = 1 := by simpa only [map_one] using h.eq_iff_eq (x := x) (y := 1) theorem IsEquiv.isNontrivial_congr {w : AbsoluteValue R S} (h : v.IsEquiv w) : v.IsNontrivial ↔ w.IsNontrivial := not_iff_not.1 <| by aesop (add simp [not_isNontrivial_iff, h.eq_one_iff]) alias ⟨IsEquiv.isNontrivial, _⟩ := IsEquiv.isNontrivial_congr end OrderedSemiring section LinearOrderedSemifield variable {R S : Type*} [Field R] [Semifield S] [LinearOrder S] {v w : AbsoluteValue R S} /-- An absolute value is equivalent to the trivial iff it is trivial itself. -/ @[simp] lemma isEquiv_trivial_iff_eq_trivial [DecidablePred fun x : R ↦ x = 0] [NoZeroDivisors R] [IsStrictOrderedRing S] {f : AbsoluteValue R S} : f.IsEquiv .trivial ↔ f = .trivial := ⟨fun h ↦ by aesop (add simp [h.eq_one_iff, AbsoluteValue.trivial]), fun h ↦ h β–Έ .rfl⟩ @[deprecated (since := "2025-09-12")] alias eq_trivial_of_isEquiv_trivial := isEquiv_trivial_iff_eq_trivial variable [IsStrictOrderedRing S] theorem isEquiv_iff_lt_one_iff : v.IsEquiv w ↔ βˆ€ x, v x < 1 ↔ w x < 1 := by refine ⟨fun h _ ↦ h.lt_one_iff, fun h x y ↦ ?_⟩ rcases eq_or_ne (v x) 0 with (_ | hyβ‚€) <;> simp_all rw [le_iff_le_iff_lt_iff_lt, ← one_mul (v x), ← mul_inv_lt_iffβ‚€ (by simp_all), ← one_mul (w x), ← mul_inv_lt_iffβ‚€ (by simp_all), ← map_invβ‚€, ← map_mul, ← map_invβ‚€, ← map_mul] exact h _ variable [Archimedean S] [ExistsAddOfLE S] theorem isEquiv_of_lt_one_imp (hv : v.IsNontrivial) (h : βˆ€ x, v x < 1 β†’ w x < 1) : v.IsEquiv w := by refine isEquiv_iff_lt_one_iff.2 fun a ↦ ?_ rcases eq_or_ne a 0 with (rfl | haβ‚€) Β· simp refine ⟨h a, fun hw ↦ ?_⟩ let ⟨xβ‚€, hxβ‚€βŸ© := hv.exists_abv_lt_one have hpow (n : β„•) (hv : 1 ≀ v a) : w xβ‚€ < w a ^ n := by rw [← one_mul (_ ^ _), ← mul_inv_lt_iffβ‚€ (pow_pos (by simp_all) _), ← map_pow, ← map_invβ‚€, ← map_mul] apply h rw [map_mul, map_invβ‚€, map_pow, mul_inv_lt_iffβ‚€ (pow_pos (by simp [haβ‚€]) _), one_mul] exact lt_of_lt_of_le hxβ‚€.2 <| one_le_powβ‚€ hv obtain ⟨n, hn⟩ := exists_pow_lt_of_lt_one (w.pos hxβ‚€.1) hw exact not_le.1 <| mt (hpow n) <| not_lt.2 hn.le /-- If `v` and `w` are inequivalent absolute values and `v` is non-trivial, then we can find an `a : R` such that `v a < 1` while `1 ≀ w a`. -/ theorem exists_lt_one_one_le_of_not_isEquiv {v w : AbsoluteValue R S} (hv : v.IsNontrivial) (h : Β¬v.IsEquiv w) : βˆƒ a : R, v a < 1 ∧ 1 ≀ w a := by contrapose! h exact isEquiv_of_lt_one_imp hv h /-- If `v` and `w` are two non-trivial and inequivalent absolute values then we can find an `a : R` such that `1 < v a` while `w a < 1`. -/ theorem exists_one_lt_lt_one_of_not_isEquiv {v w : AbsoluteValue R S} (hv : v.IsNontrivial) (hw : w.IsNontrivial) (h : Β¬v.IsEquiv w) : βˆƒ a : R, 1 < v a ∧ w a < 1 := by let ⟨a, hva, hwa⟩ := exists_lt_one_one_le_of_not_isEquiv hv h let ⟨b, hwb, hvb⟩ := exists_lt_one_one_le_of_not_isEquiv hw (mt .symm h) exact ⟨b / a, by simp [w.pos_iff.1 (lt_of_lt_of_le zero_lt_one hwa), one_lt_div, div_lt_one, lt_of_le_of_lt' hvb hva, lt_of_le_of_lt' hwa hwb]⟩ end LinearOrderedSemifield section LinearOrderedField open Filter open scoped Topology variable {R S : Type*} [Field R] [Field S] [LinearOrder S] {v w : AbsoluteValue R S} [TopologicalSpace S] [IsStrictOrderedRing S] [Archimedean S] [OrderTopology S] {ΞΉ : Type*} [Fintype ΞΉ] [DecidableEq ΞΉ] {v : ΞΉ β†’ AbsoluteValue R S} {w : AbsoluteValue R S} {a b : R} {i : ΞΉ} /-- Suppose that - `v i` and `w` are absolute values on a field `R`. - `v i` is inequivalent to `v j` for all `j β‰  i` via the divergent point `a : R`. - `v i` is inequivalent to `w` via the divergent point `b : R`. - `w a = 1`. Then there is a common divergent point `k` causing both `v i` and `w` to be inequivalent to each `v j` for `j β‰  i`. -/ private theorem exists_one_lt_lt_one_pi_of_eq_one (ha : 1 < v i a) (haj : βˆ€ j β‰  i, v j a < 1) (haw : w a = 1) (hb : 1 < v i b) (hbw : w b < 1) : βˆƒ k : R, 1 < v i k ∧ (βˆ€ j β‰  i, v j k < 1) ∧ w k < 1 := by let c : β„• β†’ R := fun n ↦ a ^ n * b have hcα΅’ : Tendsto (fun n ↦ (v i) (c n)) atTop atTop := by simpa [c] using Tendsto.atTop_mul_const (by linarith) (tendsto_pow_atTop_atTop_of_one_lt ha) have hcβ±Ό (j : ΞΉ) (hj : j β‰  i) : Tendsto (fun n ↦ (v j) (c n)) atTop (𝓝 0) := by simpa [c] using (tendsto_pow_atTop_nhds_zero_of_lt_one ((v j).nonneg _) (haj j hj)).mul_const _ simp_rw [OrderTopology.topology_eq_generate_intervals, TopologicalSpace.tendsto_nhds_generateFrom_iff, mem_atTop_sets, Set.mem_preimage] at hcβ±Ό choose r₁ hr₁ using tendsto_atTop_atTop.1 hcα΅’ 2 choose rβ‚™ hrβ‚™ using fun j hj ↦ hcβ±Ό j hj (.Iio 1) (by simpa using ⟨1, .inr rfl⟩) (by simp) let r := Finset.univ.sup fun j ↦ if h : j = i then r₁ else rβ‚™ j h refine ⟨c r, lt_of_lt_of_le (by linarith) (hr₁ r ?_), fun j hj ↦ ?_, by simpa [c, haw]⟩ Β· exact Finset.le_sup_dite_pos (p := fun j ↦ j = i) (f := fun _ _ ↦ r₁) (Finset.mem_univ _) rfl Β· simpa using hrβ‚™ j hj _ <| Finset.le_sup_dite_neg (fun j ↦ j = i) (Finset.mem_univ j) _ /-- Suppose that - `v i` and `w` are absolute values on a field `R`. - `v i` is inequivalent to `v j` for all `j β‰  i` via the divergent point `a : R`. - `v i` is inequivalent to `w` via the divergent point `b : R`. - `1 < w a`. Then there is a common divergent point `k : R` causing both `v i` and `w` to be inequivalent to each `v j` for `j β‰  i`. -/ private theorem exists_one_lt_lt_one_pi_of_one_lt (ha : 1 < v i a) (haj : βˆ€ j β‰  i, v j a < 1) (haw : 1 < w a) (hb : 1 < v i b) (hbw : w b < 1) : βˆƒ k : R, 1 < v i k ∧ (βˆ€ j β‰  i, v j k < 1) ∧ w k < 1 := by let c : β„• β†’ R := fun n ↦ 1 / (1 + a⁻¹ ^ n) * b have hcα΅’ : Tendsto (fun n ↦ v i (c n)) atTop (𝓝 (v i b)) := by have : v i a⁻¹ < 1 := map_invβ‚€ (v i) a β–Έ inv_lt_one_of_one_ltβ‚€ ha simpa [c] using (tendsto_div_one_add_pow_nhds_one this).mul_const (v i b) have hcβ±Ό (j : ΞΉ) (hj : j β‰  i) : atTop.Tendsto (fun n ↦ v j (c n)) (𝓝 0) := by have : 1 < v j a⁻¹ := map_invβ‚€ (v j) _ β–Έ (one_lt_invβ‚€ <| (v j).pos fun h ↦ by linarith [map_zero (v _) β–Έ h β–Έ ha]).2 (haj j hj) simpa [c] using (tendsto_div_one_add_pow_nhds_zero this).mul_const _ have hcβ‚™ : atTop.Tendsto (fun n ↦ w (c n)) (𝓝 (w b)) := by have : w a⁻¹ < 1 := map_invβ‚€ w _ β–Έ inv_lt_one_of_one_ltβ‚€ haw simpa [c] using (tendsto_div_one_add_pow_nhds_one this).mul_const (w b) simp_rw [OrderTopology.topology_eq_generate_intervals, TopologicalSpace.tendsto_nhds_generateFrom_iff, mem_atTop_sets, Set.mem_preimage] at hcβ±Ό choose r₁ hr₁ using Filter.eventually_atTop.1 <| Filter.Tendsto.eventually_const_lt hb hcα΅’ choose rβ‚™ hrβ‚™ using fun j hj ↦ hcβ±Ό j hj (.Iio 1) (by simpa using ⟨1, .inr rfl⟩) (by simp) choose rN hrN using Filter.eventually_atTop.1 <| Filter.Tendsto.eventually_lt_const hbw hcβ‚™ let r := max (Finset.univ.sup fun j ↦ if h : j = i then r₁ else rβ‚™ j h) rN refine ⟨c r, hr₁ r ?_, fun j hj ↦ ?_, ?_⟩ Β· exact le_max_iff.2 <| .inl <| Finset.le_sup_dite_pos (p := fun j ↦ j = i) (f := fun _ _ ↦ r₁) (Finset.mem_univ _) rfl Β· exact hrβ‚™ j hj _ <| le_max_iff.2 <| .inl <| Finset.le_sup_dite_neg (fun j ↦ j = i) (Finset.mem_univ j) _ Β· exact hrN _ <| le_max_iff.2 (.inr le_rfl) open Fintype Subtype in /-- If `v : ΞΉ β†’ AbsoluteValue R S` is a finite collection of non-trivial and pairwise inequivalent absolute values, then for any `i` there is some `a : R` such that `1 < v i a` and `v j a < 1` for all `j β‰  i`. -/ theorem exists_one_lt_lt_one_pi_of_not_isEquiv (h : βˆ€ i, (v i).IsNontrivial) (hv : Pairwise fun i j ↦ Β¬(v i).IsEquiv (v j)) : βˆ€ i, βˆƒ (a : R), 1 < v i a ∧ βˆ€ j β‰  i, v j a < 1 := by let P (ΞΉ : Type _) [Fintype ΞΉ] : Prop := [DecidableEq ΞΉ] β†’ βˆ€ v : ΞΉ β†’ AbsoluteValue R S, (βˆ€ i, (v i).IsNontrivial) β†’ (Pairwise fun i j ↦ Β¬(v i).IsEquiv (v j)) β†’ βˆ€ i, βˆƒ (a : R), 1 < v i a ∧ βˆ€ j β‰  i, v j a < 1 -- Use strong induction on the index. revert hv h; refine induction_subsingleton_or_nontrivial (P := P) ΞΉ (fun ΞΉ _ _ _ v h hv i ↦ ?_) (fun ΞΉ _ _ ih _ v h hv i ↦ ?_) v Β· -- If `ΞΉ` is trivial this follows immediately from `(v i).IsNontrivial`. let ⟨a, ha⟩ := (h i).exists_abv_gt_one exact ⟨a, ha, fun j hij ↦ absurd (Subsingleton.elim i j) hij.symm⟩ Β· rcases eq_or_ne (card ΞΉ) 2 with (hc | hc) Β· -- If `ΞΉ` has two elements this is `exists_one_lt_lt_one_of_not_isEquiv`. let ⟨j, hj⟩ := (Nat.card_eq_two_iff' i).1 <| card_eq_nat_card β–Έ hc let ⟨a, ha⟩ := (v i).exists_one_lt_lt_one_of_not_isEquiv (h i) (h j) (hv hj.1.symm) exact ⟨a, ha.1, fun _ h ↦ hj.2 _ h β–Έ ha.2⟩ have hlt : 2 < card ΞΉ := Nat.lt_of_le_of_ne (one_lt_card_iff_nontrivial.2 β€Ή_β€Ί) hc.symm -- Otherwise, choose another distinguished index `j β‰  i`. let ⟨j, hj⟩ := exists_ne i -- Apply induction first on the subcollection `v i` for `i β‰  j` to get `a : K` let ⟨a, ha⟩ := ih {k : ΞΉ // k β‰  j} (card_subtype_lt fun a ↦ a rfl) (restrict _ v) (fun i ↦ h _) (hv.comp_of_injective val_injective) ⟨i, hj.symm⟩ -- Then apply induction next to the subcollection `{v i, v j}` to get `b : K`. let ⟨b, hb⟩ := ih {k : ΞΉ // k = i ∨ k = j} (by linarith [card_subtype_eq_or_eq_of_ne hj.symm]) (restrict _ v) (fun _ ↦ h _) (hv.comp_of_injective val_injective) ⟨i, .inl rfl⟩ rcases eq_or_ne (v j a) 1 with (ha₁ | ha₁) Β· -- If `v j a = 1` then take a large enough value from the sequence `a ^ n * b`. let ⟨c, hc⟩ := exists_one_lt_lt_one_pi_of_eq_one ha.1 ha.2 ha₁ hb.1 (hb.2 ⟨j, .inr rfl⟩ (by grind)) refine ⟨c, hc.1, fun k hk ↦ ?_⟩ rcases eq_or_ne k j with (rfl | h); try exact hc.2.2; exact hc.2.1 ⟨k, h⟩ (by grind) rcases ha₁.lt_or_gt with (ha_lt | ha_gt) Β· -- If `v j a < 1` then `a` works as the divergent point. refine ⟨a, ha.1, fun k hk ↦ ?_⟩ rcases eq_or_ne k j with (rfl | h); try exact ha_lt; exact ha.2 ⟨k, h⟩ (by grind) Β· -- If `1 < v j a` then take a large enough value from the sequence `b / (1 + a ^ (-n))`. let ⟨c, hc⟩ := exists_one_lt_lt_one_pi_of_one_lt ha.1 ha.2 ha_gt hb.1 (hb.2 ⟨j, .inr rfl⟩ (by grind)) refine ⟨c, hc.1, fun k hk ↦ ?_⟩ rcases eq_or_ne k j with (rfl | h); try exact hc.2.2; exact hc.2.1 ⟨k, h⟩ (by grind) end LinearOrderedField section Real open Real Topology variable {F : Type*} [Field F] {v w : AbsoluteValue F ℝ} theorem IsEquiv.log_div_log_pos (h : v.IsEquiv w) {a : F} (haβ‚€ : a β‰  0) (ha₁ : w a β‰  1) : 0 < (w a).log / (v a).log := by rcases ha₁.lt_or_gt with hwa | hwa Β· simpa using div_pos (neg_pos_of_neg <| log_neg (w.pos haβ‚€) (hwa)) (neg_pos_of_neg <| log_neg (v.pos haβ‚€) (h.lt_one_iff.2 hwa)) Β· exact div_pos (log_pos <| hwa) (log_pos (h.one_lt_iff.2 hwa)) /-- If $v$ and $w$ are two real absolute values on a field $F$, equivalent in the sense that $v(x) \leq v(y)$ if and only if $w(x) \leq w(y)$, then $\frac{\log (v(a))}{\log (w(a))}$ is constant for all $0 \neq a\in F$ with $v(a) \neq 1$. -/ theorem IsEquiv.log_div_log_eq_log_div_log (h : v.IsEquiv w) {a : F} (haβ‚€ : a β‰  0) (ha₁ : v a β‰  1) {b : F} (hbβ‚€ : b β‰  0) (hb₁ : v b β‰  1) : (v b).log / (w b).log = (v a).log / (w a).log := by by_contra! h_ne wlog ha : 1 < v a generalizing a b Β· apply this (inv_ne_zero haβ‚€) (by simpa) hbβ‚€ hb₁ (by simpa) simpa using one_lt_inv_iffβ‚€.2 ⟨v.pos haβ‚€, ha₁.lt_of_le (not_lt.1 ha)⟩ wlog hb : 1 < v b generalizing a b Β· apply this haβ‚€ ha₁ (inv_ne_zero hbβ‚€) (by simpa) (by simpa) ha simpa using one_lt_inv_iffβ‚€.2 ⟨v.pos hbβ‚€, hb₁.lt_of_le (not_lt.1 hb)⟩ wlog h_lt : (v b).log / (w b).log < (v a).log / (w a).log generalizing a b Β· exact this hbβ‚€ hb₁ haβ‚€ ha₁ h_ne.symm hb ha <| lt_of_le_of_ne (not_lt.1 h_lt) h_ne.symm have hwa := h.one_lt_iff.1 ha have hwb := h.one_lt_iff.1 hb rw [div_lt_div_iffβ‚€ (log_pos hwb) (log_pos hwa), mul_comm (v a).log, ← div_lt_div_iffβ‚€ (log_pos ha) (log_pos hwa)] at h_lt let ⟨q, ⟨hq₁, hqβ‚‚βŸ©βŸ© := exists_rat_btwn h_lt rw [← Rat.num_div_den q, Rat.cast_div, Rat.cast_intCast, Rat.cast_natCast] at hq₁ hqβ‚‚ rw [div_lt_div_iffβ‚€ (log_pos ha) (by simp [q.den_pos]), mul_comm, ← log_pow, ← log_zpow, log_lt_log_iff (pow_pos (by linarith) _) (zpow_pos (by linarith) _), ← div_lt_one (zpow_pos (by linarith) _), ← map_pow, ← map_zpowβ‚€, ← map_divβ‚€] at hq₁ rw [div_lt_div_iffβ‚€ (by simp [q.den_pos]) (log_pos hwa), mul_comm (w _).log, ← log_pow, ← log_zpow, log_lt_log_iff (zpow_pos (by linarith) _) (pow_pos (by linarith) _), ← one_lt_div (zpow_pos (by linarith) _), ← map_pow, ← map_zpowβ‚€, ← map_divβ‚€] at hqβ‚‚ exact not_lt_of_gt (h.lt_one_iff.1 hq₁) hqβ‚‚ /-- If `v` and `w` are two real absolute values on a field `F`, then `v` and `w` are equivalent if and only if there exists a positive real constant `c` such that for all `x : R`, `(f x)^c = g x`. -/ theorem isEquiv_iff_exists_rpow_eq {v w : AbsoluteValue F ℝ} : v.IsEquiv w ↔ βˆƒ c : ℝ, 0 < c ∧ (v Β· ^ c) = w := by refine ⟨fun h ↦ ?_, fun ⟨t, ht, h⟩ ↦ isEquiv_iff_lt_one_iff.2 fun x ↦ h β–Έ (rpow_lt_one_iff' (v.nonneg x) ht).symm⟩ by_cases hw : w.IsNontrivial Β· let ⟨a, haβ‚€, haβ‚βŸ© := hw refine ⟨(w a).log / (v a).log, h.log_div_log_pos haβ‚€ ha₁, funext fun b ↦ ?_⟩ rcases eq_or_ne b 0 with rfl | hbβ‚€; Β· simp [zero_rpow (by linarith [h.log_div_log_pos haβ‚€ ha₁])] rcases eq_or_ne (w b) 1 with hb₁ | hb₁; Β· simp [hb₁, h.eq_one_iff.2 hb₁] rw [← h.symm.log_div_log_eq_log_div_log haβ‚€ ha₁ hbβ‚€ hb₁, div_eq_inv_mul, rpow_mul (v.nonneg _), rpow_inv_log (v.pos hbβ‚€) (h.eq_one_iff.not.2 hb₁), exp_one_rpow, exp_log (w.pos hbβ‚€)] Β· exact ⟨1, zero_lt_one, funext fun x ↦ by rcases eq_or_ne x 0 with rfl | hβ‚€ <;> aesop (add simp [h.isNontrivial_congr])⟩ theorem IsEquiv.equivWithAbs_image_mem_nhds_zero (h : v.IsEquiv w) {U : Set (WithAbs v)} (hU : U ∈ 𝓝 0) : WithAbs.equivWithAbs v w '' U ∈ 𝓝 0 := by rw [Metric.mem_nhds_iff] at hU ⊒ obtain ⟨Ρ, hΞ΅, hU⟩ := hU obtain ⟨c, hc, hvw⟩ := isEquiv_iff_exists_rpow_eq.1 h refine ⟨Ρ ^ c, rpow_pos_of_pos hΞ΅ _, fun x hx ↦ ?_⟩ rw [← RingEquiv.apply_symm_apply (WithAbs.equivWithAbs v w) x] refine Set.mem_image_of_mem _ (hU ?_) rw [Metric.mem_ball, dist_zero_right, WithAbs.norm_eq_abv, ← funext_iff.1 hvw, rpow_lt_rpow_iff (v.nonneg _) hΞ΅.le hc] at hx simpa [WithAbs.norm_eq_abv] open Topology IsTopologicalAddGroup in theorem IsEquiv.isEmbedding_equivWithAbs (h : v.IsEquiv w) : IsEmbedding (WithAbs.equivWithAbs v w) := by refine IsInducing.isEmbedding <| isInducing_iff_nhds_zero.2 <| Filter.ext fun U ↦ ⟨fun hU ↦ ?_, fun hU ↦ ?_⟩ Β· exact ⟨WithAbs.equivWithAbs v w '' U, h.equivWithAbs_image_mem_nhds_zero hU, by simp [RingEquiv.image_eq_preimage_symm, Set.preimage_preimage]⟩ Β· rw [← RingEquiv.coe_toEquiv, ← Filter.map_equiv_symm] at hU obtain ⟨s, hs, hss⟩ := Filter.mem_map_iff_exists_image.1 hU rw [← RingEquiv.coe_toEquiv_symm, WithAbs.equivWithAbs_symm] at hss exact Filter.mem_of_superset (h.symm.equivWithAbs_image_mem_nhds_zero hs) hss theorem isEquiv_iff_isHomeomorph (v w : AbsoluteValue F ℝ) : v.IsEquiv w ↔ IsHomeomorph (WithAbs.equivWithAbs v w) := by rw [isHomeomorph_iff_isEmbedding_surjective] refine ⟨fun h ↦ ⟨h.isEmbedding_equivWithAbs, RingEquiv.surjective _⟩, fun ⟨hi, _⟩ ↦ ?_⟩ refine isEquiv_iff_lt_one_iff.2 fun x ↦ ?_ conv_lhs => rw [← (WithAbs.equiv v).apply_symm_apply x] conv_rhs => rw [← (WithAbs.equiv w).apply_symm_apply x] simp_rw [← WithAbs.norm_eq_abv, ← tendsto_pow_atTop_nhds_zero_iff_norm_lt_one] exact ⟨fun h ↦ by simpa [Function.comp_def] using (hi.continuous.tendsto 0).comp h, fun h ↦ by simpa [Function.comp_def] using (hi.continuous_iff (f := (WithAbs.equivWithAbs v w).symm)).2 continuous_id |>.tendsto 0 |>.comp h ⟩ end Real end AbsoluteValue
.lake/packages/mathlib/Mathlib/Analysis/ODE/PicardLindelof.lean
import Mathlib.Analysis.SpecialFunctions.Integrals.Basic import Mathlib.Topology.Algebra.Order.Floor import Mathlib.Topology.MetricSpace.Contracting /-! # Picard-LindelΓΆf (Cauchy-Lipschitz) Theorem We prove the (local) existence of integral curves and flows to time-dependent vector fields. Let `f : ℝ β†’ E β†’ E` be a time-dependent (local) vector field on a Banach space, and let `tβ‚€ : ℝ` and `xβ‚€ : E`. If `f` is Lipschitz continuous in `x` within a closed ball around `xβ‚€` of radius `a β‰₯ 0` at every `t` and continuous in `t` at every `x`, then there exists a (local) solution `Ξ± : ℝ β†’ E` to the initial value problem `Ξ± tβ‚€ = xβ‚€` and `deriv Ξ± t = f t (Ξ± t)` for all `t ∈ Icc tmin tmax`, where `L * max (tmax - tβ‚€) (tβ‚€ - tmin) ≀ a`. We actually prove a more general version of this theorem for the existence of local flows. If there is some `r β‰₯ 0` such that `L * max (tmax - tβ‚€) (tβ‚€ - tmin) ≀ a - r`, then for every `x ∈ closedBall xβ‚€ r`, there exists a (local) solution `Ξ± x` with the initial condition `Ξ± tβ‚€ = x`. In other words, there exists a local flow `Ξ± : E β†’ ℝ β†’ E` defined on `closedBall xβ‚€ r` and `Icc tmin tmax`. The proof relies on demonstrating the existence of a solution `Ξ±` to the following integral equation: $$\alpha(t) = x_0 + \int_{t_0}^t f(\tau, \alpha(\tau))\,\mathrm{d}\tau.$$ This is done via the contraction mapping theorem, applied to the space of Lipschitz continuous functions from a closed interval to a Banach space. The needed contraction map is constructed by repeated applications of the right-hand side of this equation. ## Main definitions and results * `picard f tβ‚€ xβ‚€ Ξ± t`: the Picard iteration, applied to the curve `Ξ±` * `IsPicardLindelof`: the structure holding the assumptions of the Picard-LindelΓΆf theorem * `IsPicardLindelof.exists_eq_forall_mem_Icc_hasDerivWithinAt`: the existence theorem for local solutions to time-dependent ODEs * `IsPicardLindelof.exists_forall_mem_closedBall_eq_forall_mem_Icc_hasDerivWithinAt`: the existence theorem for local flows to time-dependent vector fields * `IsPicardLindelof.exists_forall_mem_closedBall_eq_hasDerivWithinAt_lipschitzOnWith`: there exists a local flow to time-dependent vector fields, and it is Lipschitz-continuous with respect to the starting point. ## Implementation notes * The structure `FunSpace` and theorems within this namespace are implementation details of the proof of the Picard-LindelΓΆf theorem and are not intended to be used outside of this file. * Some sources, such as Lang, define `FunSpace` as the space of continuous functions from a closed interval to a closed ball. We instead define `FunSpace` here as the space of Lipschitz continuous functions from a closed interval. This slightly stronger condition allows us to postpone the usage of the completeness condition on the space `E` until the application of the contraction mapping theorem. * We have chosen to formalise many of the real constants as `ℝβ‰₯0`, so that the non-negativity of certain quantities constructed from them can be shown more easily. When subtraction is involved, especially note whether it is the usual subtraction between two reals or the truncated subtraction between two non-negative reals. * In this file, We only prove the existence of a solution. For uniqueness, see `ODE_solution_unique` and related theorems in `Mathlib/Analysis/ODE/Gronwall.lean`. ## Tags differential equation, dynamical system, initial value problem, Picard-LindelΓΆf theorem, Cauchy-Lipschitz theorem -/ open Function intervalIntegral MeasureTheory Metric Set open scoped Nat NNReal Topology /-! ## Assumptions of the Picard-LindelΓΆf theorem-/ /-- Prop structure holding the assumptions of the Picard-LindelΓΆf theorem. `IsPicardLindelof f tβ‚€ xβ‚€ a r L K`, where `tβ‚€ ∈ Icc tmin tmax`, means that the time-dependent vector field `f` satisfies the conditions to admit an integral curve `Ξ± : ℝ β†’ E` to `f` defined on `Icc tmin tmax` with the initial condition `Ξ± tβ‚€ = x`, where `β€–x - xβ‚€β€– ≀ r`. Note that the initial point `x` is allowed to differ from the point `xβ‚€` about which the conditions on `f` are stated. -/ structure IsPicardLindelof {E : Type*} [NormedAddCommGroup E] (f : ℝ β†’ E β†’ E) {tmin tmax : ℝ} (tβ‚€ : Icc tmin tmax) (xβ‚€ : E) (a r L K : ℝβ‰₯0) : Prop where /-- The vector field at any time is Lipschitz with constant `K` within a closed ball. -/ lipschitzOnWith : βˆ€ t ∈ Icc tmin tmax, LipschitzOnWith K (f t) (closedBall xβ‚€ a) /-- The vector field is continuous in time within a closed ball. -/ continuousOn : βˆ€ x ∈ closedBall xβ‚€ a, ContinuousOn (f Β· x) (Icc tmin tmax) /-- `L` is an upper bound of the norm of the vector field. -/ norm_le : βˆ€ t ∈ Icc tmin tmax, βˆ€ x ∈ closedBall xβ‚€ a, β€–f t xβ€– ≀ L /-- The time interval of validity -/ mul_max_le : L * max (tmax - tβ‚€) (tβ‚€ - tmin) ≀ a - r namespace ODE /-! ## Integral equation For any time-dependent vector field `f : ℝ β†’ E β†’ E`, we define an integral equation that is equivalent to the initial value problem defined by `f`. -/ section variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] {f : ℝ β†’ E β†’ E} {Ξ± : ℝ β†’ E} {s : Set ℝ} {u : Set E} {tβ‚€ tmin tmax : ℝ} /-- The Picard iteration. It will be shown that if `Ξ± : ℝ β†’ E` and `picard f tβ‚€ xβ‚€ Ξ±` agree on an interval containing `tβ‚€`, then `Ξ±` is a solution to `f` with `Ξ± tβ‚€ = xβ‚€` on this interval. -/ noncomputable def picard (f : ℝ β†’ E β†’ E) (tβ‚€ : ℝ) (xβ‚€ : E) (Ξ± : ℝ β†’ E) : ℝ β†’ E := fun t ↦ xβ‚€ + ∫ Ο„ in tβ‚€..t, f Ο„ (Ξ± Ο„) @[simp] lemma picard_apply {xβ‚€ : E} {t : ℝ} : picard f tβ‚€ xβ‚€ Ξ± t = xβ‚€ + ∫ Ο„ in tβ‚€..t, f Ο„ (Ξ± Ο„) := rfl lemma picard_applyβ‚€ {xβ‚€ : E} : picard f tβ‚€ xβ‚€ Ξ± tβ‚€ = xβ‚€ := by simp /-- Given a $C^n$ time-dependent vector field `f` and a $C^n$ curve `Ξ±`, the composition `f t (Ξ± t)` is $C^n$ in `t`. -/ lemma contDiffOn_comp {n : WithTop β„•βˆž} (hf : ContDiffOn ℝ n (uncurry f) (s Γ—Λ’ u)) (hΞ± : ContDiffOn ℝ n Ξ± s) (hmem : βˆ€ t ∈ s, Ξ± t ∈ u) : ContDiffOn ℝ n (fun t ↦ f t (Ξ± t)) s := by have : (fun t ↦ f t (Ξ± t)) = (uncurry f) ∘ fun t ↦ (t, Ξ± t) := rfl rw [this] apply hf.comp (by fun_prop) intro _ ht rw [mem_prod] exact ⟨ht, hmem _ ht⟩ /-- Given a continuous time-dependent vector field `f` and a continuous curve `Ξ±`, the composition `f t (Ξ± t)` is continuous in `t`. -/ lemma continuousOn_comp (hf : ContinuousOn (uncurry f) (s Γ—Λ’ u)) (hΞ± : ContinuousOn Ξ± s) (hmem : MapsTo Ξ± s u) : ContinuousOn (fun t ↦ f t (Ξ± t)) s := contDiffOn_zero.mp <| (contDiffOn_comp (contDiffOn_zero.mpr hf) (contDiffOn_zero.mpr hΞ±) hmem) end /-! ## Space of Lipschitz functions on a closed interval We define the space of Lipschitz continuous functions from a closed interval. This will be shown to be a complete metric space on which `picard` is a contracting map, leading to a fixed point that will serve as the solution to the ODE. The domain is a closed interval in order to easily inherit the sup metric from continuous maps on compact spaces. We cannot use functions `ℝ β†’ E` with junk values outside the domain, as the supremum within a closed interval will only be a pseudo-metric, and the contracting map will fail to have a fixed point. In order to accommodate flows, we do not require a specific initial condition. Rather, `FunSpace` contains curves whose initial condition is within a closed ball. -/ /-- The space of `L`-Lipschitz functions `Ξ± : Icc tmin tmax β†’ E` -/ structure FunSpace {E : Type*} [NormedAddCommGroup E] {tmin tmax : ℝ} (tβ‚€ : Icc tmin tmax) (xβ‚€ : E) (r L : ℝβ‰₯0) where /-- The domain is `Icc tmin tmax`. -/ toFun : Icc tmin tmax β†’ E lipschitzWith : LipschitzWith L toFun mem_closedBallβ‚€ : toFun tβ‚€ ∈ closedBall xβ‚€ r namespace FunSpace variable {E : Type*} [NormedAddCommGroup E] section variable {tmin tmax : ℝ} {tβ‚€ : Icc tmin tmax} {xβ‚€ : E} {a r L : ℝβ‰₯0} instance : CoeFun (FunSpace tβ‚€ xβ‚€ r L) fun _ ↦ Icc tmin tmax β†’ E := ⟨fun Ξ± ↦ Ξ±.toFun⟩ /-- `FunSpace tβ‚€ xβ‚€ r L` contains the constant map at `xβ‚€`. -/ instance : Inhabited (FunSpace tβ‚€ xβ‚€ r L) := ⟨fun _ ↦ xβ‚€, (LipschitzWith.const _).weaken (zero_le _), mem_closedBall_self r.2⟩ protected lemma continuous (Ξ± : FunSpace tβ‚€ xβ‚€ L r) : Continuous Ξ± := Ξ±.lipschitzWith.continuous /-- The embedding of `FunSpace` into the space of continuous maps -/ def toContinuousMap : FunSpace tβ‚€ xβ‚€ r L β†ͺ C(Icc tmin tmax, E) := ⟨fun Ξ± ↦ ⟨α, Ξ±.continuous⟩, fun Ξ± Ξ² h ↦ by cases Ξ±; cases Ξ²; simpa using h⟩ @[simp] lemma toContinuousMap_apply_eq_apply (Ξ± : FunSpace tβ‚€ xβ‚€ r L) (t : Icc tmin tmax) : Ξ±.toContinuousMap t = Ξ± t := rfl /-- The metric between two curves `Ξ±` and `Ξ²` is the supremum of the metric between `Ξ± t` and `Ξ² t` over all `t` in the domain. This is finite when the domain is compact, such as a closed interval in our case. -/ noncomputable instance : MetricSpace (FunSpace tβ‚€ xβ‚€ r L) := MetricSpace.induced toContinuousMap toContinuousMap.injective inferInstance lemma isUniformInducing_toContinuousMap : IsUniformInducing fun Ξ± : FunSpace tβ‚€ xβ‚€ r L ↦ Ξ±.toContinuousMap := ⟨rfl⟩ lemma range_toContinuousMap : range (fun Ξ± : FunSpace tβ‚€ xβ‚€ r L ↦ Ξ±.toContinuousMap) = { Ξ± : C(Icc tmin tmax, E) | LipschitzWith L Ξ± ∧ Ξ± tβ‚€ ∈ closedBall xβ‚€ r } := by ext Ξ± constructor Β· rintro ⟨⟨α, hΞ±1, hΞ±2⟩, rfl⟩ exact ⟨hΞ±1, hΞ±2⟩ Β· rintro ⟨hΞ±1, hΞ±2⟩ exact ⟨⟨α, hΞ±1, hΞ±2⟩, rfl⟩ /-- We show that `FunSpace` is complete in order to apply the contraction mapping theorem. -/ instance [CompleteSpace E] : CompleteSpace (FunSpace tβ‚€ xβ‚€ r L) := by rw [completeSpace_iff_isComplete_range isUniformInducing_toContinuousMap] apply IsClosed.isComplete rw [range_toContinuousMap, setOf_and] apply isClosed_setOf_lipschitzWith L |>.preimage continuous_coeFun |>.inter simp_rw [mem_closedBall_iff_norm] exact isClosed_le (by fun_prop) continuous_const /-- Extend the domain of `Ξ±` from `Icc tmin tmax` to `ℝ` such that `Ξ± t = Ξ± tmin` for all `t ≀ tmin` and `Ξ± t = Ξ± tmax` for all `t β‰₯ tmax`. -/ noncomputable def compProj (Ξ± : FunSpace tβ‚€ xβ‚€ r L) (t : ℝ) : E := Ξ± <| projIcc tmin tmax (le_trans tβ‚€.2.1 tβ‚€.2.2) t @[simp] lemma compProj_apply {Ξ± : FunSpace tβ‚€ xβ‚€ r L} {t : ℝ} : Ξ±.compProj t = Ξ± (projIcc tmin tmax (le_trans tβ‚€.2.1 tβ‚€.2.2) t) := rfl lemma compProj_val {Ξ± : FunSpace tβ‚€ xβ‚€ r L} {t : Icc tmin tmax} : Ξ±.compProj t = Ξ± t := by simp only [compProj_apply, projIcc_val] lemma compProj_of_mem {Ξ± : FunSpace tβ‚€ xβ‚€ r L} {t : ℝ} (ht : t ∈ Icc tmin tmax) : Ξ±.compProj t = Ξ± ⟨t, ht⟩ := by rw [compProj_apply, projIcc_of_mem] @[continuity, fun_prop] lemma continuous_compProj (Ξ± : FunSpace tβ‚€ xβ‚€ r L) : Continuous Ξ±.compProj := Ξ±.continuous.comp continuous_projIcc /-- The image of a function in `FunSpace` is contained within a closed ball. -/ protected lemma mem_closedBall {Ξ± : FunSpace tβ‚€ xβ‚€ r L} (h : L * max (tmax - tβ‚€) (tβ‚€ - tmin) ≀ a - r) {t : Icc tmin tmax} : Ξ± t ∈ closedBall xβ‚€ a := by rw [mem_closedBall, dist_eq_norm] calc β€–Ξ± t - xβ‚€β€– ≀ β€–Ξ± t - Ξ± tβ‚€β€– + β€–Ξ± tβ‚€ - xβ‚€β€– := norm_sub_le_norm_sub_add_norm_sub .. _ ≀ L * |t.1 - tβ‚€.1| + r := by apply add_le_add _ <| mem_closedBall_iff_norm.mp Ξ±.mem_closedBallβ‚€ rw [← dist_eq_norm] exact Ξ±.lipschitzWith.dist_le_mul t tβ‚€ _ ≀ L * max (tmax - tβ‚€) (tβ‚€ - tmin) + r := by gcongr exact abs_sub_le_max_sub t.2.1 t.2.2 _ _ ≀ a - r + r := by gcongr _ = a := sub_add_cancel _ _ lemma compProj_mem_closedBall (Ξ± : FunSpace tβ‚€ xβ‚€ r L) (h : L * max (tmax - tβ‚€) (tβ‚€ - tmin) ≀ a - r) {t : ℝ} : Ξ±.compProj t ∈ closedBall xβ‚€ a := by rw [compProj_apply] exact Ξ±.mem_closedBall h end /-! ## Contracting map on the space of Lipschitz functions -/ section variable [NormedSpace ℝ E] {f : ℝ β†’ E β†’ E} {tmin tmax : ℝ} {tβ‚€ : Icc tmin tmax} {xβ‚€ x y : E} {a r L K : ℝβ‰₯0} /-- The integrand in `next` is continuous. -/ lemma continuousOn_comp_compProj (hf : IsPicardLindelof f tβ‚€ xβ‚€ a r L K) (Ξ± : FunSpace tβ‚€ xβ‚€ r L) : ContinuousOn (fun t' ↦ f t' (Ξ±.compProj t')) (Icc tmin tmax) := continuousOn_comp (continuousOn_prod_of_continuousOn_lipschitzOnWith' (uncurry f) K hf.lipschitzOnWith hf.continuousOn) Ξ±.continuous_compProj.continuousOn fun _ _ ↦ Ξ±.mem_closedBall hf.mul_max_le /-- The integrand in `next` is integrable. -/ lemma intervalIntegrable_comp_compProj (hf : IsPicardLindelof f tβ‚€ xβ‚€ a r L K) (Ξ± : FunSpace tβ‚€ xβ‚€ r L) (t : Icc tmin tmax) : IntervalIntegrable (fun t' ↦ f t' (Ξ±.compProj t')) volume tβ‚€ t := by apply ContinuousOn.intervalIntegrable apply Ξ±.continuousOn_comp_compProj hf |>.mono exact uIcc_subset_Icc tβ‚€.2 t.2 /-- The map on `FunSpace` defined by `picard`, some `n`-th iterate of which will be a contracting map -/ noncomputable def next (hf : IsPicardLindelof f tβ‚€ xβ‚€ a r L K) (hx : x ∈ closedBall xβ‚€ r) (Ξ± : FunSpace tβ‚€ xβ‚€ r L) : FunSpace tβ‚€ xβ‚€ r L where toFun t := picard f tβ‚€ x Ξ±.compProj t lipschitzWith := LipschitzWith.of_dist_le_mul fun t₁ tβ‚‚ ↦ by rw [dist_eq_norm, picard_apply, picard_apply, add_sub_add_left_eq_sub, integral_interval_sub_left (intervalIntegrable_comp_compProj hf _ t₁) (intervalIntegrable_comp_compProj hf _ tβ‚‚), Subtype.dist_eq, Real.dist_eq] apply intervalIntegral.norm_integral_le_of_norm_le_const intro t ht -- Can `grind` do this in the future? have ht : t ∈ Icc tmin tmax := subset_trans uIoc_subset_uIcc (uIcc_subset_Icc tβ‚‚.2 t₁.2) ht exact hf.norm_le _ ht _ <| Ξ±.mem_closedBall hf.mul_max_le mem_closedBallβ‚€ := by simp [hx] @[simp] lemma next_apply (hf : IsPicardLindelof f tβ‚€ xβ‚€ a r L K) (hx : x ∈ closedBall xβ‚€ r) (Ξ± : FunSpace tβ‚€ xβ‚€ r L) {t : Icc tmin tmax} : next hf hx Ξ± t = picard f tβ‚€ x Ξ±.compProj t := rfl lemma next_applyβ‚€ (hf : IsPicardLindelof f tβ‚€ xβ‚€ a r L K) (hx : x ∈ closedBall xβ‚€ r) (Ξ± : FunSpace tβ‚€ xβ‚€ r L) : next hf hx Ξ± tβ‚€ = x := by simp /-- A key step in the inductive case of `dist_iterate_next_apply_le` -/ lemma dist_comp_iterate_next_le (hf : IsPicardLindelof f tβ‚€ xβ‚€ a r L K) (hx : x ∈ closedBall xβ‚€ r) (n : β„•) (t : Icc tmin tmax) {Ξ± Ξ² : FunSpace tβ‚€ xβ‚€ r L} (h : dist ((next hf hx)^[n] Ξ± t) ((next hf hx)^[n] Ξ² t) ≀ (K * |t - tβ‚€.1|) ^ n / n ! * dist Ξ± Ξ²) : dist (f t ((next hf hx)^[n] Ξ± t)) (f t ((next hf hx)^[n] Ξ² t)) ≀ K ^ (n + 1) * |t - tβ‚€.1| ^ n / n ! * dist Ξ± Ξ² := calc _ ≀ K * dist ((next hf hx)^[n] Ξ± t) ((next hf hx)^[n] Ξ² t) := hf.lipschitzOnWith t.1 t.2 |>.dist_le_mul _ (FunSpace.mem_closedBall hf.mul_max_le) _ (FunSpace.mem_closedBall hf.mul_max_le) _ ≀ K ^ (n + 1) * |t - tβ‚€.1| ^ n / n ! * dist Ξ± Ξ² := by rw [pow_succ', mul_assoc, mul_div_assoc, mul_assoc] gcongr rwa [← mul_pow] /-- A time-dependent bound on the distance between the `n`-th iterates of `next` on two curves -/ lemma dist_iterate_next_apply_le (hf : IsPicardLindelof f tβ‚€ xβ‚€ a r L K) (hx : x ∈ closedBall xβ‚€ r) (Ξ± Ξ² : FunSpace tβ‚€ xβ‚€ r L) (n : β„•) (t : Icc tmin tmax) : dist ((next hf hx)^[n] Ξ± t) ((next hf hx)^[n] Ξ² t) ≀ (K * |t.1 - tβ‚€.1|) ^ n / n ! * dist Ξ± Ξ² := by induction n generalizing t with | zero => simpa using ContinuousMap.dist_apply_le_dist (f := toContinuousMap Ξ±) (g := toContinuousMap Ξ²) _ | succ n hn => rw [iterate_succ_apply', iterate_succ_apply', dist_eq_norm, next_apply, next_apply, picard_apply, picard_apply, add_sub_add_left_eq_sub, ← intervalIntegral.integral_sub (intervalIntegrable_comp_compProj hf _ t) (intervalIntegrable_comp_compProj hf _ t)] calc _ ≀ ∫ Ο„ in uIoc tβ‚€.1 t.1, K ^ (n + 1) * |Ο„ - tβ‚€| ^ n / n ! * dist Ξ± Ξ² := by rw [intervalIntegral.norm_intervalIntegral_eq] apply MeasureTheory.norm_integral_le_of_norm_le (Continuous.integrableOn_uIoc (by fun_prop)) apply ae_restrict_mem measurableSet_Ioc |>.mono intro t' ht' -- Can `grind` do this in the future? have ht' : t' ∈ Icc tmin tmax := subset_trans uIoc_subset_uIcc (uIcc_subset_Icc tβ‚€.2 t.2) ht' rw [← dist_eq_norm, compProj_of_mem, compProj_of_mem] exact dist_comp_iterate_next_le hf hx _ ⟨t', ht'⟩ (hn _) _ ≀ (K * |t.1 - tβ‚€.1|) ^ (n + 1) / (n + 1) ! * dist Ξ± Ξ² := by apply le_of_abs_le -- critical: `integral_pow_abs_sub_uIoc` rw [← intervalIntegral.abs_intervalIntegral_eq, intervalIntegral.integral_mul_const, intervalIntegral.integral_div, intervalIntegral.integral_const_mul, abs_mul, abs_div, abs_mul, intervalIntegral.abs_intervalIntegral_eq, integral_pow_abs_sub_uIoc, abs_div, abs_pow, abs_pow, abs_dist, NNReal.abs_eq, abs_abs, mul_div, div_div, ← abs_mul, ← Nat.cast_succ, ← Nat.cast_mul, ← Nat.factorial_succ, Nat.abs_cast, ← mul_pow] /-- The `n`-th iterate of `next` is Lipschitz continuous with respect to `FunSpace`, with constant $(K \max(t_{\mathrm{max}}, t_{\mathrm{min}})^n / n!$. -/ lemma dist_iterate_next_iterate_next_le (hf : IsPicardLindelof f tβ‚€ xβ‚€ a r L K) (hx : x ∈ closedBall xβ‚€ r) (Ξ± Ξ² : FunSpace tβ‚€ xβ‚€ r L) (n : β„•) : dist ((next hf hx)^[n] Ξ±) ((next hf hx)^[n] Ξ²) ≀ (K * max (tmax - tβ‚€) (tβ‚€ - tmin)) ^ n / n ! * dist Ξ± Ξ² := by rw [← MetricSpace.isometry_induced FunSpace.toContinuousMap FunSpace.toContinuousMap.injective |>.dist_eq, ContinuousMap.dist_le] Β· intro t apply le_trans <| dist_iterate_next_apply_le hf hx Ξ± Ξ² n t gcongr exact abs_sub_le_max_sub t.2.1 t.2.2 _ Β· have : 0 ≀ max (tmax - tβ‚€) (tβ‚€ - tmin) := le_max_of_le_left <| sub_nonneg_of_le tβ‚€.2.2 positivity /-- Some `n`-th iterate of `next` is a contracting map, and its associated Lipschitz constant is independent of the initial point. -/ lemma exists_contractingWith_iterate_next (hf : IsPicardLindelof f tβ‚€ xβ‚€ a r L K) : βˆƒ (n : β„•) (C : ℝβ‰₯0), βˆ€ (x : E) (hx : x ∈ closedBall xβ‚€ r), ContractingWith C (next hf hx)^[n] := by obtain ⟨n, hn⟩ := FloorSemiring.tendsto_pow_div_factorial_atTop (K * max (tmax - tβ‚€) (tβ‚€ - tmin)) |>.eventually (gt_mem_nhds zero_lt_one) |>.exists have : (0 : ℝ) ≀ (K * max (tmax - tβ‚€) (tβ‚€ - tmin)) ^ n / n ! := by have : 0 ≀ max (tmax - tβ‚€) (tβ‚€ - tmin) := le_max_of_le_left <| sub_nonneg_of_le tβ‚€.2.2 positivity refine ⟨n, ⟨_, this⟩, fun x hx ↦ ?_⟩ exact ⟨hn, LipschitzWith.of_dist_le_mul fun Ξ± Ξ² ↦ dist_iterate_next_iterate_next_le hf hx Ξ± Ξ² n⟩ /-- The map `next` has a fixed point in the space of curves. This will be used to construct a solution `Ξ± : ℝ β†’ E` to the ODE. -/ lemma exists_isFixedPt_next [CompleteSpace E] (hf : IsPicardLindelof f tβ‚€ xβ‚€ a r L K) (hx : x ∈ closedBall xβ‚€ r) : βˆƒ Ξ± : FunSpace tβ‚€ xβ‚€ r L, IsFixedPt (next hf hx) Ξ± := let ⟨_, _, h⟩ := exists_contractingWith_iterate_next hf ⟨_, h x hx |>.isFixedPt_fixedPoint_iterate⟩ /-! ## Lipschitz continuity of the solution with respect to the initial condition The proof relies on the fact that the repeated application of `next` to any curve `Ξ±` converges to the fixed point of `next`, so it suffices to bound the distance between `Ξ±` and `next^[n] Ξ±`. Since there is some `m : β„•` such that `next^[m]` is a contracting map, it further suffices to bound the distance between `Ξ±` and `next^[m]^[n] Ξ±`. -/ /-- A key step in the base case of `exists_forall_closedBall_funSpace_dist_le_mul` -/ lemma dist_next_next (hf : IsPicardLindelof f tβ‚€ xβ‚€ a r L K) (hx : x ∈ closedBall xβ‚€ r) (hy : y ∈ closedBall xβ‚€ r) (Ξ± : FunSpace tβ‚€ xβ‚€ r L) : dist (next hf hx Ξ±) (next hf hy Ξ±) = dist x y := by have : Nonempty (Icc tmin tmax) := ⟨tβ‚€βŸ© -- needed for `ciSup_const` rw [← MetricSpace.isometry_induced FunSpace.toContinuousMap FunSpace.toContinuousMap.injective |>.dist_eq, dist_eq_norm, ContinuousMap.norm_eq_iSup_norm] simp [add_sub_add_right_eq_sub, dist_eq_norm] lemma dist_iterate_next_le (hf : IsPicardLindelof f tβ‚€ xβ‚€ a r L K) (hx : x ∈ closedBall xβ‚€ r) (Ξ± : FunSpace tβ‚€ xβ‚€ r L) (n : β„•) : dist Ξ± ((next hf hx)^[n] Ξ±) ≀ (βˆ‘ i ∈ Finset.range n, (K * max (tmax - tβ‚€) (tβ‚€ - tmin)) ^ i / i !) * dist Ξ± (next hf hx Ξ±) := by nth_rw 1 [← iterate_zero_apply (next hf hx) Ξ±] rw [Finset.sum_mul] apply dist_le_range_sum_of_dist_le (f := fun i ↦ (next hf hx)^[i] Ξ±) intro i hi rw [iterate_succ_apply] exact dist_iterate_next_iterate_next_le hf hx _ _ i lemma dist_iterate_iterate_next_le_of_lipschitzWith (hf : IsPicardLindelof f tβ‚€ xβ‚€ a r L K) (hx : x ∈ closedBall xβ‚€ r) (Ξ± : FunSpace tβ‚€ xβ‚€ r L) {m : β„•} {C : ℝβ‰₯0} (hm : LipschitzWith C (next hf hx)^[m]) (n : β„•) : dist Ξ± ((next hf hx)^[m]^[n] Ξ±) ≀ (βˆ‘ i ∈ Finset.range m, (K * max (tmax - tβ‚€) (tβ‚€ - tmin)) ^ i / i !) * (βˆ‘ i ∈ Finset.range n, (C : ℝ) ^ i) * dist Ξ± (next hf hx Ξ±) := by nth_rw 1 [← iterate_zero_apply (next hf hx) Ξ±] rw [Finset.mul_sum, Finset.sum_mul] apply dist_le_range_sum_of_dist_le (f := fun i ↦ (next hf hx)^[m]^[i] Ξ±) intro i hi rw [iterate_succ_apply] apply le_trans <| hm.dist_iterate_succ_le_geometric Ξ± i rw [mul_assoc, mul_comm ((C : ℝ) ^ i), ← mul_assoc] gcongr exact dist_iterate_next_le hf hx Ξ± m /-- The pointwise distance between any two integral curves `Ξ±` and `Ξ²` over their domains is bounded by a constant `L'` times the distance between their respective initial points. This is the result of taking the limit of `dist_iterate_iterate_next_le_of_lipschitzWith` as `n β†’ ∞`. This implies that the local solution of a vector field is Lipschitz continuous in the initial condition. -/ lemma exists_forall_closedBall_funSpace_dist_le_mul [CompleteSpace E] (hf : IsPicardLindelof f tβ‚€ xβ‚€ a r L K) : βˆƒ L' : ℝβ‰₯0, βˆ€ (x y : E) (hx : x ∈ closedBall xβ‚€ r) (hy : y ∈ closedBall xβ‚€ r) (Ξ± Ξ² : FunSpace tβ‚€ xβ‚€ r L) (_ : IsFixedPt (next hf hx) Ξ±) (_ : IsFixedPt (next hf hy) Ξ²), dist Ξ± Ξ² ≀ L' * dist x y := by obtain ⟨m, C, h⟩ := exists_contractingWith_iterate_next hf let L' := (βˆ‘ i ∈ Finset.range m, (K * max (tmax - tβ‚€) (tβ‚€ - tmin)) ^ i / i !) * (1 - C)⁻¹ have hL' : 0 ≀ L' := by have : 0 ≀ max (tmax - tβ‚€) (tβ‚€ - tmin) := le_max_of_le_left <| sub_nonneg_of_le tβ‚€.2.2 positivity refine ⟨⟨L', hL'⟩, fun x y hx hy Ξ± Ξ² hΞ± hΞ² ↦ ?_⟩ rw [NNReal.coe_mk] apply le_of_tendsto_of_tendsto' (b := Filter.atTop) _ _ <| dist_iterate_iterate_next_le_of_lipschitzWith hf hy Ξ± (h y hy).2 Β· apply Filter.Tendsto.comp (y := 𝓝 Ξ²) (tendsto_const_nhds.dist Filter.tendsto_id) rw [h y hy |>.fixedPoint_unique (hΞ².iterate m)] exact h y hy |>.tendsto_iterate_fixedPoint Ξ± Β· nth_rw 1 [← hΞ±, dist_next_next] apply Filter.Tendsto.mul_const apply Filter.Tendsto.const_mul convert hasSum_geometric_of_lt_one C.2 (h y hy).1 |>.tendsto_sum_nat simp [NNReal.coe_sub <| le_of_lt (h y hy).1, NNReal.coe_one] end end FunSpace /-! ## Properties of the integral equation -/ section variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] [CompleteSpace E] {f : ℝ β†’ E β†’ E} {Ξ± : ℝ β†’ E} {s : Set ℝ} {u : Set E} {tβ‚€ tmin tmax : ℝ} -- TODO: generalise to open sets and `Ici` and `Iic` /-- If the time-dependent vector field `f` and the curve `Ξ±` are continuous, then `f t (Ξ± t)` is the derivative of `picard f tβ‚€ xβ‚€ Ξ±`. -/ lemma hasDerivWithinAt_picard_Icc (htβ‚€ : tβ‚€ ∈ Icc tmin tmax) (hf : ContinuousOn (uncurry f) ((Icc tmin tmax) Γ—Λ’ u)) (hΞ± : ContinuousOn Ξ± (Icc tmin tmax)) (hmem : βˆ€ t ∈ Icc tmin tmax, Ξ± t ∈ u) (xβ‚€ : E) {t : ℝ} (ht : t ∈ Icc tmin tmax) : HasDerivWithinAt (picard f tβ‚€ xβ‚€ Ξ±) (f t (Ξ± t)) (Icc tmin tmax) t := by apply HasDerivWithinAt.const_add have : Fact (t ∈ Icc tmin tmax) := ⟨ht⟩ -- needed to synthesise `FTCFilter` for `Icc` apply intervalIntegral.integral_hasDerivWithinAt_right _ -- need `CompleteSpace E` and `Icc` (continuousOn_comp hf hΞ± hmem |>.stronglyMeasurableAtFilter_nhdsWithin measurableSet_Icc t) (continuousOn_comp hf hΞ± hmem _ ht) apply ContinuousOn.intervalIntegrable apply continuousOn_comp hf hΞ± hmem |>.mono by_cases! h : t < tβ‚€ Β· rw [uIcc_of_gt h] exact Icc_subset_Icc ht.1 htβ‚€.2 Β· rw [uIcc_of_le h] exact Icc_subset_Icc htβ‚€.1 ht.2 /-- Converse of `hasDerivWithinAt_picard_Icc`: if `f` is the derivative along `Ξ±`, then `Ξ±` satisfies the integral equation. -/ lemma picard_eq_of_hasDerivAt {t : ℝ} (hf : ContinuousOn (uncurry f) ((uIcc tβ‚€ t) Γ—Λ’ u)) (hΞ± : βˆ€ t' ∈ uIcc tβ‚€ t, HasDerivWithinAt Ξ± (f t' (Ξ± t')) (uIcc tβ‚€ t) t') (hmap : MapsTo Ξ± (uIcc tβ‚€ t) u) : picard f tβ‚€ (Ξ± tβ‚€) Ξ± t = Ξ± t := by rw [← add_sub_cancel (Ξ± tβ‚€) (Ξ± t), picard_apply, integral_eq_sub_of_hasDeriv_right (HasDerivWithinAt.continuousOn hΞ±) _ (continuousOn_comp hf (HasDerivWithinAt.continuousOn hΞ±) hmap |>.intervalIntegrable)] intro t' ht' apply HasDerivAt.hasDerivWithinAt exact hΞ± t' (Ioo_subset_Icc_self ht') |>.hasDerivAt <| Icc_mem_nhds ht'.1 ht'.2 /-- If the time-dependent vector field `f` is $C^n$ and the curve `Ξ±` is continuous, then `picard f tβ‚€ xβ‚€ Ξ±` is also $C^n$. This version works for `n : β„•`. -/ lemma contDiffOn_nat_picard_Icc (htβ‚€ : tβ‚€ ∈ Icc tmin tmax) {n : β„•} (hf : ContDiffOn ℝ n (uncurry f) ((Icc tmin tmax) Γ—Λ’ u)) (hΞ± : ContinuousOn Ξ± (Icc tmin tmax)) (hmem : βˆ€ t ∈ Icc tmin tmax, Ξ± t ∈ u) (xβ‚€ : E) (heqon : βˆ€ t ∈ Icc tmin tmax, Ξ± t = picard f tβ‚€ xβ‚€ Ξ± t) : ContDiffOn ℝ n (picard f tβ‚€ xβ‚€ Ξ±) (Icc tmin tmax) := by by_cases hlt : tmin < tmax Β· have (t) (ht : t ∈ Icc tmin tmax) := hasDerivWithinAt_picard_Icc htβ‚€ hf.continuousOn hΞ± hmem xβ‚€ ht induction n with | zero => simp only [Nat.cast_zero, contDiffOn_zero] at * exact HasDerivWithinAt.continuousOn this | succ n hn => simp only [Nat.cast_add, Nat.cast_one] at * rw [contDiffOn_succ_iff_derivWithin <| uniqueDiffOn_Icc hlt] refine ⟨fun t ht ↦ HasDerivWithinAt.differentiableWithinAt (this t ht), by simp, ?_⟩ apply contDiffOn_comp hf.of_succ (ContDiffOn.congr (hn hf.of_succ) heqon) hmem |>.congr intro t ht exact HasDerivWithinAt.derivWithin (this t ht) <| (uniqueDiffOn_Icc hlt).uniqueDiffWithinAt ht Β· rw [(subsingleton_Icc_of_ge (not_lt.mp hlt)).eq_singleton_of_mem htβ‚€] intro t ht rw [eq_of_mem_singleton ht] exact contDiffWithinAt_singleton /-- If the time-dependent vector field `f` is $C^n$ and the curve `Ξ±` is continuous, then `picard f tβ‚€ xβ‚€ Ξ±` is also $C^n$. This version works for `n : β„•βˆž`. TODO: Extend to the analytic `n = ⊀` case. -/ lemma contDiffOn_enat_picard_Icc (htβ‚€ : tβ‚€ ∈ Icc tmin tmax) {n : β„•βˆž} (hf : ContDiffOn ℝ n (uncurry f) ((Icc tmin tmax) Γ—Λ’ u)) (hΞ± : ContinuousOn Ξ± (Icc tmin tmax)) (hmem : βˆ€ t ∈ Icc tmin tmax, Ξ± t ∈ u) (xβ‚€ : E) (heqon : βˆ€ t ∈ Icc tmin tmax, Ξ± t = picard f tβ‚€ xβ‚€ Ξ± t) : ContDiffOn ℝ n (picard f tβ‚€ xβ‚€ Ξ±) (Icc tmin tmax) := by induction n with | top => rw [contDiffOn_infty] at * exact fun k ↦ contDiffOn_nat_picard_Icc htβ‚€ (hf k) hΞ± hmem xβ‚€ heqon | coe n => simp only [WithTop.coe_natCast] at * exact contDiffOn_nat_picard_Icc htβ‚€ hf hΞ± hmem xβ‚€ heqon /-- Solutions to ODEs defined by $C^n$ vector fields are also $C^n$. -/ theorem contDiffOn_enat_Icc_of_hasDerivWithinAt {n : β„•βˆž} (hf : ContDiffOn ℝ n (uncurry f) ((Icc tmin tmax) Γ—Λ’ u)) (hΞ± : βˆ€ t ∈ Icc tmin tmax, HasDerivWithinAt Ξ± (f t (Ξ± t)) (Icc tmin tmax) t) (hmem : MapsTo Ξ± (Icc tmin tmax) u) : ContDiffOn ℝ n Ξ± (Icc tmin tmax) := by by_cases hlt : tmin < tmax Β· set tβ‚€ := (tmin + tmax) / 2 with h have htβ‚€ : tβ‚€ ∈ Icc tmin tmax := ⟨by linarith, by linarith⟩ have : βˆ€ t ∈ Icc tmin tmax, Ξ± t = picard f tβ‚€ (Ξ± tβ‚€) Ξ± t := by intro t ht have : uIcc tβ‚€ t βŠ† Icc tmin tmax := uIcc_subset_Icc htβ‚€ ht rw [picard_eq_of_hasDerivAt (hf.continuousOn.mono (prod_subset_prod_left this)) (fun t' ht' ↦ hΞ± t' (this ht') |>.mono this) (hmem.mono_left this)] exact contDiffOn_enat_picard_Icc htβ‚€ hf (HasDerivWithinAt.continuousOn hΞ±) hmem (Ξ± tβ‚€) this |>.congr this Β· rw [not_lt, le_iff_lt_or_eq] at hlt cases hlt with | inl h => intro _ ht rw [Icc_eq_empty (not_le.mpr h)] at ht exfalso exact notMem_empty _ ht | inr h => rw [h, Icc_self] intro _ ht rw [eq_of_mem_singleton ht] exact contDiffWithinAt_singleton end end ODE namespace IsPicardLindelof /-! ## Properties of `IsPicardLindelof` -/ section variable {E : Type*} [NormedAddCommGroup E] {f : ℝ β†’ E β†’ E} {tmin tmax : ℝ} {tβ‚€ : Icc tmin tmax} {xβ‚€ x : E} {a r L K : ℝβ‰₯0} lemma continuousOn_uncurry (hf : IsPicardLindelof f tβ‚€ xβ‚€ a r L K) : ContinuousOn (uncurry f) ((Icc tmin tmax) Γ—Λ’ (closedBall xβ‚€ a)) := continuousOn_prod_of_continuousOn_lipschitzOnWith' _ K hf.lipschitzOnWith hf.continuousOn /-- The special case where the vector field is independent of time -/ lemma of_time_independent {f : E β†’ E} {tmin tmax : ℝ} {tβ‚€ : Icc tmin tmax} {xβ‚€ : E} {a r L K : ℝβ‰₯0} (hb : βˆ€ x ∈ closedBall xβ‚€ a, β€–f xβ€– ≀ L) (hl : LipschitzOnWith K f (closedBall xβ‚€ a)) (hm : L * max (tmax - tβ‚€) (tβ‚€ - tmin) ≀ a - r) : (IsPicardLindelof (fun _ ↦ f) tβ‚€ xβ‚€ a r L K) where lipschitzOnWith := fun _ _ ↦ hl continuousOn := fun _ _ ↦ continuousOn_const norm_le := fun _ _ ↦ hb mul_max_le := hm /-- A time-independent, continuously differentiable ODE satisfies the hypotheses of the Picard-LindelΓΆf theorem. -/ lemma of_contDiffAt_one [NormedSpace ℝ E] {f : E β†’ E} {xβ‚€ : E} (hf : ContDiffAt ℝ 1 f xβ‚€) (tβ‚€ : ℝ) : βˆƒ (Ξ΅ : ℝ) (hΞ΅ : 0 < Ξ΅) (a r L K : ℝβ‰₯0) (_ : 0 < r), IsPicardLindelof (fun _ ↦ f) (tmin := tβ‚€ - Ξ΅) (tmax := tβ‚€ + Ξ΅) ⟨tβ‚€, (by simp [le_of_lt hΞ΅])⟩ xβ‚€ a r L K := by -- Obtain ball of radius `a` within the domain in which f is `K`-lipschitz obtain ⟨K, s, hs, hl⟩ := hf.exists_lipschitzOnWith obtain ⟨a, ha : 0 < a, has⟩ := Metric.mem_nhds_iff.mp hs set L := K * a + β€–f xβ‚€β€– + 1 with hL have hL0 : 0 < L := by positivity have hb (x : E) (hx : x ∈ closedBall xβ‚€ (a / 2)) : β€–f xβ€– ≀ L := by rw [hL] calc β€–f xβ€– ≀ β€–f x - f xβ‚€β€– + β€–f xβ‚€β€– := norm_le_norm_sub_add _ _ _ ≀ K * β€–x - xβ‚€β€– + β€–f xβ‚€β€– := by gcongr rw [← dist_eq_norm, ← dist_eq_norm] apply hl.dist_le_mul x _ xβ‚€ (mem_of_mem_nhds hs) apply subset_trans _ has hx exact closedBall_subset_ball <| half_lt_self ha -- this is where we need `a / 2` _ ≀ K * a + β€–f xβ‚€β€– := by gcongr rw [← mem_closedBall_iff_norm] exact closedBall_subset_closedBall (half_le_self (le_of_lt ha)) hx _ ≀ L := le_add_of_nonneg_right zero_le_one let Ξ΅ := a / L / 2 / 2 have hΞ΅0 : 0 < Ξ΅ := by positivity refine ⟨Ρ, hΞ΅0, ⟨a / 2, le_of_lt <| half_pos ha⟩, ⟨a / 2, le_of_lt <| half_pos ha⟩ / 2, ⟨L, le_of_lt hL0⟩, K, half_pos <| half_pos ha, ?_⟩ apply of_time_independent hb <| hl.mono <| subset_trans (closedBall_subset_ball (half_lt_self ha)) has rw [NNReal.coe_mk, add_sub_cancel_left, sub_sub_cancel, max_self, NNReal.coe_div, NNReal.coe_two, NNReal.coe_mk, mul_comm, ← le_div_iffβ‚€ hL0, sub_half, div_right_comm (a / 2), div_right_comm a] end /-! ## Existence of solutions to ODEs -/ open ODE variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] [CompleteSpace E] {f : ℝ β†’ E β†’ E} {tmin tmax : ℝ} {tβ‚€ : Icc tmin tmax} {xβ‚€ x : E} {a r L K : ℝβ‰₯0} /-- **Picard-LindelΓΆf (Cauchy-Lipschitz) theorem**, integral form. This version shows the existence of a local solution whose initial point `x` may be different from the centre `xβ‚€` of the closed ball within which the properties of the vector field hold. -/ theorem exists_eq_forall_mem_Icc_eq_picard (hf : IsPicardLindelof f tβ‚€ xβ‚€ a r L K) (hx : x ∈ closedBall xβ‚€ r) : βˆƒ Ξ± : ℝ β†’ E, Ξ± tβ‚€ = x ∧ βˆ€ t ∈ Icc tmin tmax, Ξ± t = ODE.picard f tβ‚€ x Ξ± t := by obtain ⟨α, hα⟩ := FunSpace.exists_isFixedPt_next hf hx refine ⟨(FunSpace.next hf hx Ξ±).compProj, by simp, fun t ht ↦ ?_⟩ rw [FunSpace.compProj_apply, FunSpace.next_apply, hΞ±, projIcc_of_mem _ ht] /-- **Picard-LindelΓΆf (Cauchy-Lipschitz) theorem**, differential form. This version shows the existence of a local solution whose initial point `x` may be different from the centre `xβ‚€` of the closed ball within which the properties of the vector field hold. -/ theorem exists_eq_forall_mem_Icc_hasDerivWithinAt (hf : IsPicardLindelof f tβ‚€ xβ‚€ a r L K) (hx : x ∈ closedBall xβ‚€ r) : βˆƒ Ξ± : ℝ β†’ E, Ξ± tβ‚€ = x ∧ βˆ€ t ∈ Icc tmin tmax, HasDerivWithinAt Ξ± (f t (Ξ± t)) (Icc tmin tmax) t := by obtain ⟨α, hα⟩ := FunSpace.exists_isFixedPt_next hf hx refine ⟨α.compProj, by rw [FunSpace.compProj_val, ← hΞ±, FunSpace.next_applyβ‚€], fun t ht ↦ ?_⟩ apply hasDerivWithinAt_picard_Icc tβ‚€.2 hf.continuousOn_uncurry Ξ±.continuous_compProj.continuousOn (fun _ ht' ↦ Ξ±.compProj_mem_closedBall hf.mul_max_le) x ht |>.congr_of_mem _ ht intro t' ht' nth_rw 1 [← hΞ±] rw [FunSpace.compProj_of_mem ht', FunSpace.next_apply] /-- **Picard-LindelΓΆf (Cauchy-Lipschitz) theorem**, differential form. -/ theorem exists_eq_forall_mem_Icc_hasDerivWithinAtβ‚€ (hf : IsPicardLindelof f tβ‚€ xβ‚€ a 0 L K) : βˆƒ Ξ± : ℝ β†’ E, Ξ± tβ‚€ = xβ‚€ ∧ βˆ€ t ∈ Icc tmin tmax, HasDerivWithinAt Ξ± (f t (Ξ± t)) (Icc tmin tmax) t := exists_eq_forall_mem_Icc_hasDerivWithinAt hf (mem_closedBall_self le_rfl) @[deprecated (since := "2025-06-24")] alias exists_forall_hasDerivWithinAt_Icc_eq := exists_eq_forall_mem_Icc_hasDerivWithinAtβ‚€ open Classical in /-- **Picard-LindelΓΆf (Cauchy-Lipschitz) theorem**, differential form. This version shows the existence of a local flow and that it is Lipschitz continuous in the initial point. -/ theorem exists_forall_mem_closedBall_eq_hasDerivWithinAt_lipschitzOnWith (hf : IsPicardLindelof f tβ‚€ xβ‚€ a r L K) : βˆƒ Ξ± : E β†’ ℝ β†’ E, (βˆ€ x ∈ closedBall xβ‚€ r, Ξ± x tβ‚€ = x ∧ βˆ€ t ∈ Icc tmin tmax, HasDerivWithinAt (Ξ± x) (f t (Ξ± x t)) (Icc tmin tmax) t) ∧ βˆƒ L' : ℝβ‰₯0, βˆ€ t ∈ Icc tmin tmax, LipschitzOnWith L' (Ξ± Β· t) (closedBall xβ‚€ r) := by have (x) (hx : x ∈ closedBall xβ‚€ r) := FunSpace.exists_isFixedPt_next hf hx choose Ξ± hΞ± using this set Ξ±' := fun (x : E) ↦ if hx : x ∈ closedBall xβ‚€ r then Ξ± x hx |>.compProj else 0 with hΞ±' refine ⟨α', fun x hx ↦ ⟨?_, fun t ht ↦ ?_⟩, ?_⟩ Β· rw [hΞ±'] beta_reduce rw [dif_pos hx, FunSpace.compProj_val, ← hΞ±, FunSpace.next_applyβ‚€] Β· rw [hΞ±'] beta_reduce rw [dif_pos hx, FunSpace.compProj_apply] apply hasDerivWithinAt_picard_Icc tβ‚€.2 hf.continuousOn_uncurry (Ξ± x hx |>.continuous_compProj.continuousOn) (fun _ ht' ↦ Ξ± x hx |>.compProj_mem_closedBall hf.mul_max_le) x ht |>.congr_of_mem _ ht intro t' ht' nth_rw 1 [← hΞ±] rw [FunSpace.compProj_of_mem ht', FunSpace.next_apply] Β· obtain ⟨L', h⟩ := FunSpace.exists_forall_closedBall_funSpace_dist_le_mul hf refine ⟨L', fun t ht ↦ LipschitzOnWith.of_dist_le_mul fun x hx y hy ↦ ?_⟩ simp_rw [hΞ±'] rw [dif_pos hx, dif_pos hy, FunSpace.compProj_apply, FunSpace.compProj_apply, ← FunSpace.toContinuousMap_apply_eq_apply, ← FunSpace.toContinuousMap_apply_eq_apply] have : Nonempty (Icc tmin tmax) := ⟨tβ‚€βŸ© apply ContinuousMap.dist_le_iff_of_nonempty.mp exact h x y hx hy (Ξ± x hx) (Ξ± y hy) (hΞ± x hx) (hΞ± y hy) /-- **Picard-LindelΓΆf (Cauchy-Lipschitz) theorem**, differential form. This version shows the existence of a local flow and that it is continuous on its domain as a (partial) map `E Γ— ℝ β†’ E`. -/ theorem exists_forall_mem_closedBall_eq_hasDerivWithinAt_continuousOn (hf : IsPicardLindelof f tβ‚€ xβ‚€ a r L K) : βˆƒ Ξ± : E Γ— ℝ β†’ E, (βˆ€ x ∈ closedBall xβ‚€ r, Ξ± ⟨x, tβ‚€βŸ© = x ∧ βˆ€ t ∈ Icc tmin tmax, HasDerivWithinAt (Ξ± ⟨x, ·⟩) (f t (Ξ± ⟨x, t⟩)) (Icc tmin tmax) t) ∧ ContinuousOn Ξ± (closedBall xβ‚€ r Γ—Λ’ Icc tmin tmax) := by obtain ⟨α, hΞ±1, L', hΞ±2⟩ := hf.exists_forall_mem_closedBall_eq_hasDerivWithinAt_lipschitzOnWith refine ⟨uncurry Ξ±, hΞ±1, ?_⟩ apply continuousOn_prod_of_continuousOn_lipschitzOnWith _ L' _ hΞ±2 exact fun x hx ↦ HasDerivWithinAt.continuousOn (hΞ±1 x hx).2 /-- **Picard-LindelΓΆf (Cauchy-Lipschitz) theorem**, differential form. This version shows the existence of a local flow. -/ theorem exists_forall_mem_closedBall_eq_forall_mem_Icc_hasDerivWithinAt (hf : IsPicardLindelof f tβ‚€ xβ‚€ a r L K) : βˆƒ Ξ± : E β†’ ℝ β†’ E, βˆ€ x ∈ closedBall xβ‚€ r, Ξ± x tβ‚€ = x ∧ βˆ€ t ∈ Icc tmin tmax, HasDerivWithinAt (Ξ± x) (f t (Ξ± x t)) (Icc tmin tmax) t := have ⟨α, hα⟩ := exists_forall_mem_closedBall_eq_hasDerivWithinAt_lipschitzOnWith hf ⟨α, hΞ±.1⟩ end IsPicardLindelof /-! ## $C^1$ vector field -/ namespace ContDiffAt variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] [CompleteSpace E] {f : E β†’ E} {xβ‚€ : E} /-- If a vector field `f : E β†’ E` is continuously differentiable at `xβ‚€ : E`, then it admits an integral curve `Ξ± : ℝ β†’ E` defined on an open interval, with initial condition `Ξ± tβ‚€ = x`, where `x` may be different from `xβ‚€`. -/ theorem exists_forall_mem_closedBall_exists_eq_forall_mem_Ioo_hasDerivAt (hf : ContDiffAt ℝ 1 f xβ‚€) (tβ‚€ : ℝ) : βˆƒ r > (0 : ℝ), βˆƒ Ξ΅ > (0 : ℝ), βˆ€ x ∈ closedBall xβ‚€ r, βˆƒ Ξ± : ℝ β†’ E, Ξ± tβ‚€ = x ∧ βˆ€ t ∈ Ioo (tβ‚€ - Ξ΅) (tβ‚€ + Ξ΅), HasDerivAt Ξ± (f (Ξ± t)) t := by have ⟨Ρ, hΞ΅, a, r, _, _, hr, hpl⟩ := IsPicardLindelof.of_contDiffAt_one hf tβ‚€ refine ⟨r, hr, Ξ΅, hΞ΅, fun x hx ↦ ?_⟩ have ⟨α, hΞ±1, hΞ±2⟩ := hpl.exists_eq_forall_mem_Icc_hasDerivWithinAt hx refine ⟨α, hΞ±1, fun t ht ↦ ?_⟩ exact hΞ±2 t (Ioo_subset_Icc_self ht) |>.hasDerivAt (Icc_mem_nhds ht.1 ht.2) /-- If a vector field `f : E β†’ E` is continuously differentiable at `xβ‚€ : E`, then it admits an integral curve `Ξ± : ℝ β†’ E` defined on an open interval, with initial condition `Ξ± tβ‚€ = xβ‚€`. -/ theorem exists_forall_mem_closedBall_exists_eq_forall_mem_Ioo_hasDerivAtβ‚€ (hf : ContDiffAt ℝ 1 f xβ‚€) (tβ‚€ : ℝ) : βˆƒ Ξ± : ℝ β†’ E, Ξ± tβ‚€ = xβ‚€ ∧ βˆƒ Ξ΅ > (0 : ℝ), βˆ€ t ∈ Ioo (tβ‚€ - Ξ΅) (tβ‚€ + Ξ΅), HasDerivAt Ξ± (f (Ξ± t)) t := have ⟨_, hr, Ξ΅, hΞ΅, H⟩ := exists_forall_mem_closedBall_exists_eq_forall_mem_Ioo_hasDerivAt hf tβ‚€ have ⟨α, hΞ±1, hΞ±2⟩ := H xβ‚€ (mem_closedBall_self (le_of_lt hr)) ⟨α, hΞ±1, Ξ΅, hΞ΅, hΞ±2⟩ @[deprecated (since := "2025-06-24")] alias exists_forall_hasDerivAt_Ioo_eq_of_contDiffAt := exists_forall_mem_closedBall_exists_eq_forall_mem_Ioo_hasDerivAtβ‚€ open Classical in /-- If a vector field `f : E β†’ E` is continuously differentiable at `xβ‚€ : E`, then it admits a flow `Ξ± : E β†’ ℝ β†’ E` defined on an open domain, with initial condition `Ξ± x tβ‚€ = x` for all `x` within the domain. -/ theorem exists_eventually_eq_hasDerivAt (hf : ContDiffAt ℝ 1 f xβ‚€) (tβ‚€ : ℝ) : βˆƒ Ξ± : E β†’ ℝ β†’ E, βˆ€αΆ  xt in 𝓝 xβ‚€ Γ—Λ’ 𝓝 tβ‚€, Ξ± xt.1 tβ‚€ = xt.1 ∧ HasDerivAt (Ξ± xt.1) (f (Ξ± xt.1 xt.2)) xt.2 := by obtain ⟨r, hr, Ξ΅, hΞ΅, H⟩ := exists_forall_mem_closedBall_exists_eq_forall_mem_Ioo_hasDerivAt hf tβ‚€ choose Ξ± hΞ± using H refine ⟨fun (x : E) ↦ if hx : x ∈ closedBall xβ‚€ r then Ξ± x hx else 0, ?_⟩ rw [Filter.eventually_iff_exists_mem] refine ⟨closedBall xβ‚€ r Γ—Λ’ Ioo (tβ‚€ - Ξ΅) (tβ‚€ + Ξ΅), ?_, ?_⟩ Β· rw [Filter.prod_mem_prod_iff] exact ⟨closedBall_mem_nhds xβ‚€ hr, Ioo_mem_nhds (by linarith) (by linarith)⟩ Β· grind end ContDiffAt
.lake/packages/mathlib/Mathlib/Analysis/ODE/Gronwall.lean
import Mathlib.Analysis.SpecialFunctions.ExpDeriv /-! # GrΓΆnwall's inequality The main technical result of this file is the GrΓΆnwall-like inequality `norm_le_gronwallBound_of_norm_deriv_right_le`. It states that if `f : ℝ β†’ E` satisfies `β€–f aβ€– ≀ Ξ΄` and `βˆ€ x ∈ [a, b), β€–f' xβ€– ≀ K * β€–f xβ€– + Ξ΅`, then for all `x ∈ [a, b]` we have `β€–f xβ€– ≀ Ξ΄ * exp (K * x) + (Ξ΅ / K) * (exp (K * x) - 1)`. Then we use this inequality to prove some estimates on the possible rate of growth of the distance between two approximate or exact solutions of an ordinary differential equation. The proofs are based on [Hubbard and West, *Differential Equations: A Dynamical Systems Approach*, Sec. 4.5][HubbardWest-ode], where `norm_le_gronwallBound_of_norm_deriv_right_le` is called β€œFundamental Inequality”. ## TODO - Once we have FTC, prove an inequality for a function satisfying `β€–f' xβ€– ≀ K x * β€–f xβ€– + Ξ΅`, or more generally `liminf_{yβ†’x+0} (f y - f x)/(y - x) ≀ K x * f x + Ξ΅` with any sign of `K x` and `f x`. -/ open Metric Set Asymptotics Filter Real open scoped Topology NNReal variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] /-! ### Technical lemmas about `gronwallBound` -/ /-- Upper bound used in several GrΓΆnwall-like inequalities. -/ noncomputable def gronwallBound (Ξ΄ K Ξ΅ x : ℝ) : ℝ := if K = 0 then Ξ΄ + Ξ΅ * x else Ξ΄ * exp (K * x) + Ξ΅ / K * (exp (K * x) - 1) theorem gronwallBound_K0 (Ξ΄ Ξ΅ : ℝ) : gronwallBound Ξ΄ 0 Ξ΅ = fun x => Ξ΄ + Ξ΅ * x := funext fun _ => if_pos rfl theorem gronwallBound_of_K_ne_0 {Ξ΄ K Ξ΅ : ℝ} (hK : K β‰  0) : gronwallBound Ξ΄ K Ξ΅ = fun x => Ξ΄ * exp (K * x) + Ξ΅ / K * (exp (K * x) - 1) := funext fun _ => if_neg hK theorem hasDerivAt_gronwallBound (Ξ΄ K Ξ΅ x : ℝ) : HasDerivAt (gronwallBound Ξ΄ K Ξ΅) (K * gronwallBound Ξ΄ K Ξ΅ x + Ξ΅) x := by by_cases hK : K = 0 Β· subst K simp only [gronwallBound_K0, zero_mul, zero_add] convert ((hasDerivAt_id x).const_mul Ξ΅).const_add Ξ΄ rw [mul_one] Β· simp only [gronwallBound_of_K_ne_0 hK] convert (((hasDerivAt_id x).const_mul K).exp.const_mul Ξ΄).add ((((hasDerivAt_id x).const_mul K).exp.sub_const 1).const_mul (Ξ΅ / K)) using 1 simp only [id, mul_add, (mul_assoc _ _ _).symm, mul_comm _ K, mul_div_cancelβ‚€ _ hK] ring theorem hasDerivAt_gronwallBound_shift (Ξ΄ K Ξ΅ x a : ℝ) : HasDerivAt (fun y => gronwallBound Ξ΄ K Ξ΅ (y - a)) (K * gronwallBound Ξ΄ K Ξ΅ (x - a) + Ξ΅) x := by convert (hasDerivAt_gronwallBound Ξ΄ K Ξ΅ _).comp x ((hasDerivAt_id x).sub_const a) using 1 rw [id, mul_one] theorem gronwallBound_x0 (Ξ΄ K Ξ΅ : ℝ) : gronwallBound Ξ΄ K Ξ΅ 0 = Ξ΄ := by by_cases hK : K = 0 Β· simp only [gronwallBound, if_pos hK, mul_zero, add_zero] Β· simp only [gronwallBound, if_neg hK, mul_zero, exp_zero, sub_self, mul_one, add_zero] theorem gronwallBound_Ξ΅0 (Ξ΄ K x : ℝ) : gronwallBound Ξ΄ K 0 x = Ξ΄ * exp (K * x) := by by_cases hK : K = 0 Β· simp only [gronwallBound_K0, hK, zero_mul, exp_zero, add_zero, mul_one] Β· simp only [gronwallBound_of_K_ne_0 hK, zero_div, zero_mul, add_zero] theorem gronwallBound_Ξ΅0_Ξ΄0 (K x : ℝ) : gronwallBound 0 K 0 x = 0 := by simp only [gronwallBound_Ξ΅0, zero_mul] theorem gronwallBound_continuous_Ξ΅ (Ξ΄ K x : ℝ) : Continuous fun Ξ΅ => gronwallBound Ξ΄ K Ξ΅ x := by by_cases hK : K = 0 Β· simp only [gronwallBound_K0, hK] exact continuous_const.add (continuous_id.mul continuous_const) Β· simp only [gronwallBound_of_K_ne_0 hK] exact continuous_const.add ((continuous_id.mul continuous_const).mul continuous_const) /-! ### Inequality and corollaries -/ /-- A GrΓΆnwall-like inequality: if `f : ℝ β†’ ℝ` is continuous on `[a, b]` and satisfies the inequalities `f a ≀ Ξ΄` and `βˆ€ x ∈ [a, b), liminf_{zβ†’x+0} (f z - f x)/(z - x) ≀ K * (f x) + Ξ΅`, then `f x` is bounded by `gronwallBound Ξ΄ K Ξ΅ (x - a)` on `[a, b]`. See also `norm_le_gronwallBound_of_norm_deriv_right_le` for a version bounding `β€–f xβ€–`, `f : ℝ β†’ E`. -/ theorem le_gronwallBound_of_liminf_deriv_right_le {f f' : ℝ β†’ ℝ} {Ξ΄ K Ξ΅ : ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, (z - x)⁻¹ * (f z - f x) < r) (ha : f a ≀ Ξ΄) (bound : βˆ€ x ∈ Ico a b, f' x ≀ K * f x + Ξ΅) : βˆ€ x ∈ Icc a b, f x ≀ gronwallBound Ξ΄ K Ξ΅ (x - a) := by have H : βˆ€ x ∈ Icc a b, βˆ€ Ξ΅' ∈ Ioi Ξ΅, f x ≀ gronwallBound Ξ΄ K Ξ΅' (x - a) := by intro x hx Ξ΅' (hΞ΅' : Ξ΅ < Ξ΅') apply image_le_of_liminf_slope_right_lt_deriv_boundary hf hf' Β· rwa [sub_self, gronwallBound_x0] Β· exact fun x => hasDerivAt_gronwallBound_shift Ξ΄ K Ξ΅' x a Β· intro x hx hfB grw [← hfB, bound x hx] gcongr Β· exact hx intro x hx change f x ≀ (fun Ξ΅' => gronwallBound Ξ΄ K Ξ΅' (x - a)) Ξ΅ convert continuousWithinAt_const.closure_le _ _ (H x hx) Β· simp only [closure_Ioi, left_mem_Ici] exact (gronwallBound_continuous_Ξ΅ Ξ΄ K (x - a)).continuousWithinAt /-- A GrΓΆnwall-like inequality: if `f : ℝ β†’ E` is continuous on `[a, b]`, has right derivative `f' x` at every point `x ∈ [a, b)`, and satisfies the inequalities `β€–f aβ€– ≀ Ξ΄`, `βˆ€ x ∈ [a, b), β€–f' xβ€– ≀ K * β€–f xβ€– + Ξ΅`, then `β€–f xβ€–` is bounded by `gronwallBound Ξ΄ K Ξ΅ (x - a)` on `[a, b]`. -/ theorem norm_le_gronwallBound_of_norm_deriv_right_le {f f' : ℝ β†’ E} {Ξ΄ K Ξ΅ : ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) (ha : β€–f aβ€– ≀ Ξ΄) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ K * β€–f xβ€– + Ξ΅) : βˆ€ x ∈ Icc a b, β€–f xβ€– ≀ gronwallBound Ξ΄ K Ξ΅ (x - a) := le_gronwallBound_of_liminf_deriv_right_le (continuous_norm.comp_continuousOn hf) (fun x hx _r hr => (hf' x hx).liminf_right_slope_norm_le hr) ha bound /-- Let `f : [a, b] β†’ E` be a differentiable function such that `f a = 0` and `β€–f'(x)β€– ≀ K β€–f(x)β€–` for some constant `K`. Then `f = 0` on `[a, b]`. -/ theorem eq_zero_of_abs_deriv_le_mul_abs_self_of_eq_zero_right {f f' : ℝ β†’ E} {K a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) (ha : f a = 0) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ K * β€–f xβ€–) : βˆ€ x ∈ Set.Icc a b, f x = 0 := by intro x hx apply norm_le_zero_iff.mp calc β€–f xβ€– _ ≀ gronwallBound 0 K 0 (x - a) := norm_le_gronwallBound_of_norm_deriv_right_le hf hf' (by simp [ha]) (by simpa using bound) _ hx _ = 0 := by rw [gronwallBound_Ξ΅0_Ξ΄0] variable {v : ℝ β†’ E β†’ E} {s : ℝ β†’ Set E} {K : ℝβ‰₯0} {f g f' g' : ℝ β†’ E} {a b tβ‚€ : ℝ} {Ξ΅f Ξ΅g Ξ΄ : ℝ} /-- If `f` and `g` are two approximate solutions of the same ODE, then the distance between them can't grow faster than exponentially. This is a simple corollary of GrΓΆnwall's inequality, and some people call this GrΓΆnwall's inequality too. This version assumes all inequalities to be true in some time-dependent set `s t`, and assumes that the solutions never leave this set. -/ theorem dist_le_of_approx_trajectories_ODE_of_mem (hv : βˆ€ t ∈ Ico a b, LipschitzOnWith K (v t) (s t)) (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ t ∈ Ico a b, HasDerivWithinAt f (f' t) (Ici t) t) (f_bound : βˆ€ t ∈ Ico a b, dist (f' t) (v t (f t)) ≀ Ξ΅f) (hfs : βˆ€ t ∈ Ico a b, f t ∈ s t) (hg : ContinuousOn g (Icc a b)) (hg' : βˆ€ t ∈ Ico a b, HasDerivWithinAt g (g' t) (Ici t) t) (g_bound : βˆ€ t ∈ Ico a b, dist (g' t) (v t (g t)) ≀ Ξ΅g) (hgs : βˆ€ t ∈ Ico a b, g t ∈ s t) (ha : dist (f a) (g a) ≀ Ξ΄) : βˆ€ t ∈ Icc a b, dist (f t) (g t) ≀ gronwallBound Ξ΄ K (Ξ΅f + Ξ΅g) (t - a) := by simp only [dist_eq_norm] at ha ⊒ have h_deriv : βˆ€ t ∈ Ico a b, HasDerivWithinAt (fun t => f t - g t) (f' t - g' t) (Ici t) t := fun t ht => (hf' t ht).sub (hg' t ht) apply norm_le_gronwallBound_of_norm_deriv_right_le (hf.sub hg) h_deriv ha intro t ht have := dist_triangle4_right (f' t) (g' t) (v t (f t)) (v t (g t)) have hv := (hv t ht).dist_le_mul _ (hfs t ht) _ (hgs t ht) rw [← dist_eq_norm, ← dist_eq_norm] refine this.trans ((add_le_add (add_le_add (f_bound t ht) (g_bound t ht)) hv).trans ?_) rw [add_comm] /-- If `f` and `g` are two approximate solutions of the same ODE, then the distance between them can't grow faster than exponentially. This is a simple corollary of GrΓΆnwall's inequality, and some people call this GrΓΆnwall's inequality too. This version assumes all inequalities to be true in the whole space. -/ theorem dist_le_of_approx_trajectories_ODE (hv : βˆ€ t, LipschitzWith K (v t)) (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ t ∈ Ico a b, HasDerivWithinAt f (f' t) (Ici t) t) (f_bound : βˆ€ t ∈ Ico a b, dist (f' t) (v t (f t)) ≀ Ξ΅f) (hg : ContinuousOn g (Icc a b)) (hg' : βˆ€ t ∈ Ico a b, HasDerivWithinAt g (g' t) (Ici t) t) (g_bound : βˆ€ t ∈ Ico a b, dist (g' t) (v t (g t)) ≀ Ξ΅g) (ha : dist (f a) (g a) ≀ Ξ΄) : βˆ€ t ∈ Icc a b, dist (f t) (g t) ≀ gronwallBound Ξ΄ K (Ξ΅f + Ξ΅g) (t - a) := have hfs : βˆ€ t ∈ Ico a b, f t ∈ @univ E := fun _ _ => trivial dist_le_of_approx_trajectories_ODE_of_mem (fun t _ => (hv t).lipschitzOnWith) hf hf' f_bound hfs hg hg' g_bound (fun _ _ => trivial) ha /-- If `f` and `g` are two exact solutions of the same ODE, then the distance between them can't grow faster than exponentially. This is a simple corollary of GrΓΆnwall's inequality, and some people call this GrΓΆnwall's inequality too. This version assumes all inequalities to be true in some time-dependent set `s t`, and assumes that the solutions never leave this set. -/ theorem dist_le_of_trajectories_ODE_of_mem (hv : βˆ€ t ∈ Ico a b, LipschitzOnWith K (v t) (s t)) (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ t ∈ Ico a b, HasDerivWithinAt f (v t (f t)) (Ici t) t) (hfs : βˆ€ t ∈ Ico a b, f t ∈ s t) (hg : ContinuousOn g (Icc a b)) (hg' : βˆ€ t ∈ Ico a b, HasDerivWithinAt g (v t (g t)) (Ici t) t) (hgs : βˆ€ t ∈ Ico a b, g t ∈ s t) (ha : dist (f a) (g a) ≀ Ξ΄) : βˆ€ t ∈ Icc a b, dist (f t) (g t) ≀ Ξ΄ * exp (K * (t - a)) := by have f_bound : βˆ€ t ∈ Ico a b, dist (v t (f t)) (v t (f t)) ≀ 0 := by intros; rw [dist_self] have g_bound : βˆ€ t ∈ Ico a b, dist (v t (g t)) (v t (g t)) ≀ 0 := by intros; rw [dist_self] intro t ht have := dist_le_of_approx_trajectories_ODE_of_mem hv hf hf' f_bound hfs hg hg' g_bound hgs ha t ht rwa [zero_add, gronwallBound_Ξ΅0] at this /-- If `f` and `g` are two exact solutions of the same ODE, then the distance between them can't grow faster than exponentially. This is a simple corollary of GrΓΆnwall's inequality, and some people call this GrΓΆnwall's inequality too. This version assumes all inequalities to be true in the whole space. -/ theorem dist_le_of_trajectories_ODE (hv : βˆ€ t, LipschitzWith K (v t)) (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ t ∈ Ico a b, HasDerivWithinAt f (v t (f t)) (Ici t) t) (hg : ContinuousOn g (Icc a b)) (hg' : βˆ€ t ∈ Ico a b, HasDerivWithinAt g (v t (g t)) (Ici t) t) (ha : dist (f a) (g a) ≀ Ξ΄) : βˆ€ t ∈ Icc a b, dist (f t) (g t) ≀ Ξ΄ * exp (K * (t - a)) := have hfs : βˆ€ t ∈ Ico a b, f t ∈ @univ E := fun _ _ => trivial dist_le_of_trajectories_ODE_of_mem (fun t _ => (hv t).lipschitzOnWith) hf hf' hfs hg hg' (fun _ _ => trivial) ha /-- There exists only one solution of an ODE \(\dot x=v(t, x)\) in a set `s βŠ† ℝ Γ— E` with a given initial value provided that the RHS is Lipschitz continuous in `x` within `s`, and we consider only solutions included in `s`. This version shows uniqueness in a closed interval `Icc a b`, where `a` is the initial time. -/ theorem ODE_solution_unique_of_mem_Icc_right (hv : βˆ€ t ∈ Ico a b, LipschitzOnWith K (v t) (s t)) (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ t ∈ Ico a b, HasDerivWithinAt f (v t (f t)) (Ici t) t) (hfs : βˆ€ t ∈ Ico a b, f t ∈ s t) (hg : ContinuousOn g (Icc a b)) (hg' : βˆ€ t ∈ Ico a b, HasDerivWithinAt g (v t (g t)) (Ici t) t) (hgs : βˆ€ t ∈ Ico a b, g t ∈ s t) (ha : f a = g a) : EqOn f g (Icc a b) := fun t ht ↦ by have := dist_le_of_trajectories_ODE_of_mem hv hf hf' hfs hg hg' hgs (dist_le_zero.2 ha) t ht rwa [zero_mul, dist_le_zero] at this /-- A time-reversed version of `ODE_solution_unique_of_mem_Icc_right`. Uniqueness is shown in a closed interval `Icc a b`, where `b` is the "initial" time. -/ theorem ODE_solution_unique_of_mem_Icc_left (hv : βˆ€ t ∈ Ioc a b, LipschitzOnWith K (v t) (s t)) (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ t ∈ Ioc a b, HasDerivWithinAt f (v t (f t)) (Iic t) t) (hfs : βˆ€ t ∈ Ioc a b, f t ∈ s t) (hg : ContinuousOn g (Icc a b)) (hg' : βˆ€ t ∈ Ioc a b, HasDerivWithinAt g (v t (g t)) (Iic t) t) (hgs : βˆ€ t ∈ Ioc a b, g t ∈ s t) (hb : f b = g b) : EqOn f g (Icc a b) := by have hv' : βˆ€ t ∈ Ico (-b) (-a), LipschitzOnWith K (Neg.neg ∘ (v (-t))) (s (-t)) := by intro t ht replace ht : -t ∈ Ioc a b := by simp only [mem_Ico, mem_Ioc] at ht ⊒ constructor <;> linarith rw [← one_mul K] exact LipschitzWith.id.neg.comp_lipschitzOnWith (hv _ ht) have hmt1 : MapsTo Neg.neg (Icc (-b) (-a)) (Icc a b) := fun _ ht ↦ ⟨le_neg.mp ht.2, neg_le.mp ht.1⟩ have hmt2 : MapsTo Neg.neg (Ico (-b) (-a)) (Ioc a b) := fun _ ht ↦ ⟨lt_neg.mp ht.2, neg_le.mp ht.1⟩ have hmt3 (t : ℝ) : MapsTo Neg.neg (Ici t) (Iic (-t)) := fun _ ht' ↦ mem_Iic.mpr <| neg_le_neg ht' suffices EqOn (f ∘ Neg.neg) (g ∘ Neg.neg) (Icc (-b) (-a)) by rw [eqOn_comp_right_iff] at this convert this simp apply ODE_solution_unique_of_mem_Icc_right hv' (hf.comp continuousOn_neg hmt1) _ (fun _ ht ↦ hfs _ (hmt2 ht)) (hg.comp continuousOn_neg hmt1) _ (fun _ ht ↦ hgs _ (hmt2 ht)) (by simp [hb]) Β· intro t ht convert HasFDerivWithinAt.comp_hasDerivWithinAt t (hf' (-t) (hmt2 ht)) (hasDerivAt_neg t).hasDerivWithinAt (hmt3 t) simp Β· intro t ht convert HasFDerivWithinAt.comp_hasDerivWithinAt t (hg' (-t) (hmt2 ht)) (hasDerivAt_neg t).hasDerivWithinAt (hmt3 t) simp /-- A version of `ODE_solution_unique_of_mem_Icc_right` for uniqueness in a closed interval whose interior contains the initial time. -/ theorem ODE_solution_unique_of_mem_Icc (hv : βˆ€ t ∈ Ioo a b, LipschitzOnWith K (v t) (s t)) (ht : tβ‚€ ∈ Ioo a b) (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ t ∈ Ioo a b, HasDerivAt f (v t (f t)) t) (hfs : βˆ€ t ∈ Ioo a b, f t ∈ s t) (hg : ContinuousOn g (Icc a b)) (hg' : βˆ€ t ∈ Ioo a b, HasDerivAt g (v t (g t)) t) (hgs : βˆ€ t ∈ Ioo a b, g t ∈ s t) (heq : f tβ‚€ = g tβ‚€) : EqOn f g (Icc a b) := by rw [← Icc_union_Icc_eq_Icc (le_of_lt ht.1) (le_of_lt ht.2)] apply EqOn.union Β· have hss : Ioc a tβ‚€ βŠ† Ioo a b := Ioc_subset_Ioo_right ht.2 exact ODE_solution_unique_of_mem_Icc_left (fun t ht ↦ hv t (hss ht)) (hf.mono <| Icc_subset_Icc_right <| le_of_lt ht.2) (fun _ ht' ↦ (hf' _ (hss ht')).hasDerivWithinAt) (fun _ ht' ↦ (hfs _ (hss ht'))) (hg.mono <| Icc_subset_Icc_right <| le_of_lt ht.2) (fun _ ht' ↦ (hg' _ (hss ht')).hasDerivWithinAt) (fun _ ht' ↦ (hgs _ (hss ht'))) heq Β· have hss : Ico tβ‚€ b βŠ† Ioo a b := Ico_subset_Ioo_left ht.1 exact ODE_solution_unique_of_mem_Icc_right (fun t ht ↦ hv t (hss ht)) (hf.mono <| Icc_subset_Icc_left <| le_of_lt ht.1) (fun _ ht' ↦ (hf' _ (hss ht')).hasDerivWithinAt) (fun _ ht' ↦ (hfs _ (hss ht'))) (hg.mono <| Icc_subset_Icc_left <| le_of_lt ht.1) (fun _ ht' ↦ (hg' _ (hss ht')).hasDerivWithinAt) (fun _ ht' ↦ (hgs _ (hss ht'))) heq /-- A version of `ODE_solution_unique_of_mem_Icc` for uniqueness in an open interval. -/ theorem ODE_solution_unique_of_mem_Ioo (hv : βˆ€ t ∈ Ioo a b, LipschitzOnWith K (v t) (s t)) (ht : tβ‚€ ∈ Ioo a b) (hf : βˆ€ t ∈ Ioo a b, HasDerivAt f (v t (f t)) t ∧ f t ∈ s t) (hg : βˆ€ t ∈ Ioo a b, HasDerivAt g (v t (g t)) t ∧ g t ∈ s t) (heq : f tβ‚€ = g tβ‚€) : EqOn f g (Ioo a b) := by intro t' ht' rcases lt_or_ge t' tβ‚€ with (h | h) Β· have hss : Icc t' tβ‚€ βŠ† Ioo a b := fun _ ht'' ↦ ⟨lt_of_lt_of_le ht'.1 ht''.1, lt_of_le_of_lt ht''.2 ht.2⟩ exact ODE_solution_unique_of_mem_Icc_left (fun t'' ht'' ↦ hv t'' ((Ioc_subset_Icc_self.trans hss) ht'')) (HasDerivAt.continuousOn fun _ ht'' ↦ (hf _ <| hss ht'').1) (fun _ ht'' ↦ (hf _ <| hss <| Ioc_subset_Icc_self ht'').1.hasDerivWithinAt) (fun _ ht'' ↦ (hf _ <| hss <| Ioc_subset_Icc_self ht'').2) (HasDerivAt.continuousOn fun _ ht'' ↦ (hg _ <| hss ht'').1) (fun _ ht'' ↦ (hg _ <| hss <| Ioc_subset_Icc_self ht'').1.hasDerivWithinAt) (fun _ ht'' ↦ (hg _ <| hss <| Ioc_subset_Icc_self ht'').2) heq ⟨le_rfl, le_of_lt h⟩ Β· have hss : Icc tβ‚€ t' βŠ† Ioo a b := fun _ ht'' ↦ ⟨lt_of_lt_of_le ht.1 ht''.1, lt_of_le_of_lt ht''.2 ht'.2⟩ exact ODE_solution_unique_of_mem_Icc_right (fun t'' ht'' ↦ hv t'' ((Ico_subset_Icc_self.trans hss) ht'')) (HasDerivAt.continuousOn fun _ ht'' ↦ (hf _ <| hss ht'').1) (fun _ ht'' ↦ (hf _ <| hss <| Ico_subset_Icc_self ht'').1.hasDerivWithinAt) (fun _ ht'' ↦ (hf _ <| hss <| Ico_subset_Icc_self ht'').2) (HasDerivAt.continuousOn fun _ ht'' ↦ (hg _ <| hss ht'').1) (fun _ ht'' ↦ (hg _ <| hss <| Ico_subset_Icc_self ht'').1.hasDerivWithinAt) (fun _ ht'' ↦ (hg _ <| hss <| Ico_subset_Icc_self ht'').2) heq ⟨h, le_rfl⟩ /-- Local uniqueness of ODE solutions. -/ theorem ODE_solution_unique_of_eventually (hv : βˆ€αΆ  t in 𝓝 tβ‚€, LipschitzOnWith K (v t) (s t)) (hf : βˆ€αΆ  t in 𝓝 tβ‚€, HasDerivAt f (v t (f t)) t ∧ f t ∈ s t) (hg : βˆ€αΆ  t in 𝓝 tβ‚€, HasDerivAt g (v t (g t)) t ∧ g t ∈ s t) (heq : f tβ‚€ = g tβ‚€) : f =αΆ [𝓝 tβ‚€] g := by obtain ⟨Ρ, hΞ΅, h⟩ := eventually_nhds_iff_ball.mp (hv.and (hf.and hg)) rw [Filter.eventuallyEq_iff_exists_mem] refine ⟨ball tβ‚€ Ξ΅, ball_mem_nhds _ hΞ΅, ?_⟩ simp_rw [Real.ball_eq_Ioo] at * apply ODE_solution_unique_of_mem_Ioo (fun _ ht ↦ (h _ ht).1) (Real.ball_eq_Ioo tβ‚€ Ξ΅ β–Έ mem_ball_self hΞ΅) (fun _ ht ↦ (h _ ht).2.1) (fun _ ht ↦ (h _ ht).2.2) heq /-- There exists only one solution of an ODE \(\dot x=v(t, x)\) with a given initial value provided that the RHS is Lipschitz continuous in `x`. -/ theorem ODE_solution_unique (hv : βˆ€ t, LipschitzWith K (v t)) (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ t ∈ Ico a b, HasDerivWithinAt f (v t (f t)) (Ici t) t) (hg : ContinuousOn g (Icc a b)) (hg' : βˆ€ t ∈ Ico a b, HasDerivWithinAt g (v t (g t)) (Ici t) t) (ha : f a = g a) : EqOn f g (Icc a b) := have hfs : βˆ€ t ∈ Ico a b, f t ∈ univ := fun _ _ => trivial ODE_solution_unique_of_mem_Icc_right (fun t _ => (hv t).lipschitzOnWith) hf hf' hfs hg hg' (fun _ _ => trivial) ha /-- There exists only one global solution to an ODE \(\dot x=v(t, x\) with a given initial value provided that the RHS is Lipschitz continuous. -/ theorem ODE_solution_unique_univ (hv : βˆ€ t, LipschitzOnWith K (v t) (s t)) (hf : βˆ€ t, HasDerivAt f (v t (f t)) t ∧ f t ∈ s t) (hg : βˆ€ t, HasDerivAt g (v t (g t)) t ∧ g t ∈ s t) (heq : f tβ‚€ = g tβ‚€) : f = g := by ext t obtain ⟨A, B, Ht, Htβ‚€βŸ© : βˆƒ A B, t ∈ Set.Ioo A B ∧ tβ‚€ ∈ Set.Ioo A B := by use (min (-|t|) (-|tβ‚€|) - 1), (max |t| |tβ‚€| + 1) rw [Set.mem_Ioo, Set.mem_Ioo] refine ⟨⟨?_, ?_⟩, ?_, ?_⟩ Β· exact sub_one_lt _ |>.trans_le <| min_le_left _ _ |>.trans <| neg_abs_le t Β· exact le_abs_self _ |>.trans_lt <| le_max_left _ _ |>.trans_lt <| lt_add_one _ Β· exact sub_one_lt _ |>.trans_le <| min_le_right _ _ |>.trans <| neg_abs_le tβ‚€ Β· exact le_abs_self _ |>.trans_lt <| le_max_right _ _ |>.trans_lt <| lt_add_one _ exact ODE_solution_unique_of_mem_Ioo (fun t _ => hv t) Htβ‚€ (fun t _ => hf t) (fun t _ => hg t) heq Ht
.lake/packages/mathlib/Mathlib/Analysis/BoxIntegral/Integrability.lean
import Mathlib.Analysis.BoxIntegral.Basic import Mathlib.MeasureTheory.Integral.Bochner.Set import Mathlib.Tactic.Generalize /-! # McShane integrability vs Bochner integrability In this file we prove that any Bochner integrable function is McShane integrable (hence, it is Henstock and `GP` integrable) with the same integral. The proof is based on [Russel A. Gordon, *The integrals of Lebesgue, Denjoy, Perron, and Henstock*][Gordon55]. We deduce that the same is true for the Riemann integral for continuous functions. ## Tags integral, McShane integral, Bochner integral -/ open scoped NNReal ENNReal Topology universe u v variable {ΞΉ : Type u} {E : Type v} [Fintype ΞΉ] [NormedAddCommGroup E] [NormedSpace ℝ E] open MeasureTheory Metric Set Finset Filter BoxIntegral namespace BoxIntegral /-- The indicator function of a measurable set is McShane integrable with respect to any locally-finite measure. -/ theorem hasIntegralIndicatorConst (l : IntegrationParams) (hl : l.bRiemann = false) {s : Set (ΞΉ β†’ ℝ)} (hs : MeasurableSet s) (I : Box ΞΉ) (y : E) (ΞΌ : Measure (ΞΉ β†’ ℝ)) [IsLocallyFiniteMeasure ΞΌ] : HasIntegral.{u, v, v} I l (s.indicator fun _ => y) ΞΌ.toBoxAdditive.toSMul (ΞΌ.real (s ∩ I) β€’ y) := by refine HasIntegral.of_mul β€–yβ€– fun Ξ΅ Ξ΅0 => ?_ lift Ξ΅ to ℝβ‰₯0 using Ξ΅0.le; rw [NNReal.coe_pos] at Ξ΅0 /- First we choose a closed set `F βŠ† s ∩ I.Icc` and an open set `U βŠ‡ s` such that both `(s ∩ I.Icc) \ F` and `U \ s` have measure less than `Ξ΅`. -/ have A : ΞΌ (s ∩ Box.Icc I) β‰  ∞ := ((measure_mono Set.inter_subset_right).trans_lt (I.measure_Icc_lt_top ΞΌ)).ne have B : ΞΌ (s ∩ I) β‰  ∞ := ((measure_mono Set.inter_subset_right).trans_lt (I.measure_coe_lt_top ΞΌ)).ne obtain ⟨F, hFs, hFc, hΞΌF⟩ : βˆƒ F, F βŠ† s ∩ Box.Icc I ∧ IsClosed F ∧ ΞΌ ((s ∩ Box.Icc I) \ F) < Ξ΅ := (hs.inter I.measurableSet_Icc).exists_isClosed_diff_lt A (ENNReal.coe_pos.2 Ξ΅0).ne' obtain ⟨U, hsU, hUo, hUt, hΞΌU⟩ : βˆƒ U, s ∩ Box.Icc I βŠ† U ∧ IsOpen U ∧ ΞΌ U < ∞ ∧ ΞΌ (U \ (s ∩ Box.Icc I)) < Ξ΅ := (hs.inter I.measurableSet_Icc).exists_isOpen_diff_lt A (ENNReal.coe_pos.2 Ξ΅0).ne' /- Then we choose `r` so that `closed_ball x (r x) βŠ† U` whenever `x ∈ s ∩ I.Icc` and `closed_ball x (r x)` is disjoint with `F` otherwise. -/ have : βˆ€ x ∈ s ∩ Box.Icc I, βˆƒ r : Ioi (0 : ℝ), closedBall x r βŠ† U := fun x hx => by rcases nhds_basis_closedBall.mem_iff.1 (hUo.mem_nhds <| hsU hx) with ⟨r, hrβ‚€, hr⟩ exact ⟨⟨r, hrβ‚€βŸ©, hr⟩ choose! rs hrsU using this have : βˆ€ x ∈ Box.Icc I \ s, βˆƒ r : Ioi (0 : ℝ), closedBall x r βŠ† Fᢜ := fun x hx => by obtain ⟨r, hrβ‚€, hr⟩ := nhds_basis_closedBall.mem_iff.1 (hFc.isOpen_compl.mem_nhds fun hx' => hx.2 (hFs hx').1) exact ⟨⟨r, hrβ‚€βŸ©, hr⟩ choose! rs' hrs'F using this classical set r : (ΞΉ β†’ ℝ) β†’ Ioi (0 : ℝ) := s.piecewise rs rs' refine ⟨fun _ => r, fun c => l.rCond_of_bRiemann_eq_false hl, fun c Ο€ hΟ€ hΟ€p => ?_⟩; rw [mul_comm] /- Then the union of boxes `J ∈ Ο€` such that `Ο€.tag ∈ s` includes `F` and is included by `U`, hence its measure is `Ξ΅`-close to the measure of `s`. -/ dsimp [integralSum] simp only [dist_eq_norm, ← indicator_const_smul_apply, sum_indicator_eq_sum_filter, ← sum_smul, ← sub_smul, norm_smul, Real.norm_eq_abs, ← Prepartition.filter_boxes, ← Prepartition.measure_iUnion_toReal] gcongr set t := (Ο€.filter (Ο€.tag Β· ∈ s)).iUnion change abs (ΞΌ.real t - ΞΌ.real (s ∩ I)) ≀ Ξ΅ have htU : t βŠ† U ∩ I := by simp only [t, TaggedPrepartition.iUnion_def, iUnion_subset_iff, TaggedPrepartition.mem_filter, and_imp] refine fun J hJ hJs x hx => ⟨hrsU _ ⟨hJs, Ο€.tag_mem_Icc J⟩ ?_, Ο€.le_of_mem' J hJ hx⟩ simpa only [r, s.piecewise_eq_of_mem _ _ hJs] using hΟ€.1 J hJ (Box.coe_subset_Icc hx) refine abs_sub_le_iff.2 ⟨?_, ?_⟩ Β· refine (ENNReal.le_toReal_sub B).trans (ENNReal.toReal_le_coe_of_le_coe ?_) refine (tsub_le_tsub (measure_mono htU) le_rfl).trans (le_measure_diff.trans ?_) refine (measure_mono fun x hx => ?_).trans hΞΌU.le exact ⟨hx.1.1, fun hx' => hx.2 ⟨hx'.1, hx.1.2⟩⟩ Β· have hΞΌt : ΞΌ t β‰  ∞ := ((measure_mono (htU.trans inter_subset_left)).trans_lt hUt).ne refine (ENNReal.le_toReal_sub hΞΌt).trans (ENNReal.toReal_le_coe_of_le_coe ?_) refine le_measure_diff.trans ((measure_mono ?_).trans hΞΌF.le) rintro x ⟨⟨hxs, hxI⟩, hxt⟩ refine ⟨⟨hxs, Box.coe_subset_Icc hxI⟩, fun hxF => hxt ?_⟩ simp only [t, TaggedPrepartition.iUnion_def, TaggedPrepartition.mem_filter, Set.mem_iUnion] rcases hΟ€p x hxI with ⟨J, hJΟ€, hxJ⟩ refine ⟨J, ⟨hJΟ€, ?_⟩, hxJ⟩ contrapose hxF refine hrs'F _ βŸ¨Ο€.tag_mem_Icc J, hxF⟩ ?_ simpa only [r, s.piecewise_eq_of_notMem _ _ hxF] using hΟ€.1 J hJΟ€ (Box.coe_subset_Icc hxJ) /-- If `f` is a.e. equal to zero on a rectangular box, then it has McShane integral zero on this box. -/ theorem HasIntegral.of_aeEq_zero {l : IntegrationParams} {I : Box ΞΉ} {f : (ΞΉ β†’ ℝ) β†’ E} {ΞΌ : Measure (ΞΉ β†’ ℝ)} [IsLocallyFiniteMeasure ΞΌ] (hf : f =ᡐ[ΞΌ.restrict I] 0) (hl : l.bRiemann = false) : HasIntegral.{u, v, v} I l f ΞΌ.toBoxAdditive.toSMul 0 := by /- Each set `{x | n < β€–f xβ€– ≀ n + 1}`, `n : β„•`, has measure zero. We cover it by an open set of measure less than `Ξ΅ / 2 ^ n / (n + 1)`. Then the norm of the integral sum is less than `Ξ΅`. -/ refine hasIntegral_iff.2 fun Ξ΅ Ξ΅0 => ?_ lift Ξ΅ to ℝβ‰₯0 using Ξ΅0.lt.le; rw [gt_iff_lt, NNReal.coe_pos] at Ξ΅0 rcases NNReal.exists_pos_sum_of_countable Ξ΅0.ne' β„• with ⟨δ, Ξ΄0, c, hΞ΄c, hcΡ⟩ haveI := Fact.mk (I.measure_coe_lt_top ΞΌ) change ΞΌ.restrict I {x | f x β‰  0} = 0 at hf set N : (ΞΉ β†’ ℝ) β†’ β„• := fun x => βŒˆβ€–f xβ€–βŒ‰β‚Š have N0 : βˆ€ {x}, N x = 0 ↔ f x = 0 := by simp [N] have : βˆ€ n, βˆƒ U, N ⁻¹' {n} βŠ† U ∧ IsOpen U ∧ ΞΌ.restrict I U < Ξ΄ n / n := fun n ↦ by refine (N ⁻¹' {n}).exists_isOpen_lt_of_lt _ ?_ rcases n with - | n Β· simp [ENNReal.div_zero (ENNReal.coe_pos.2 (Ξ΄0 _)).ne'] Β· refine (measure_mono_null ?_ hf).le.trans_lt ?_ Β· exact fun x hxN hxf => n.succ_ne_zero ((Eq.symm hxN).trans <| N0.2 hxf) Β· simp [(Ξ΄0 _).ne'] choose U hNU hUo hΞΌU using this have : βˆ€ x, βˆƒ r : Ioi (0 : ℝ), closedBall x r βŠ† U (N x) := fun x => by obtain ⟨r, hrβ‚€, hr⟩ := nhds_basis_closedBall.mem_iff.1 ((hUo _).mem_nhds (hNU _ rfl)) exact ⟨⟨r, hrβ‚€βŸ©, hr⟩ choose r hrU using this refine ⟨fun _ => r, fun c => l.rCond_of_bRiemann_eq_false hl, fun c Ο€ hΟ€ _ => ?_⟩ rw [dist_eq_norm, sub_zero, ← integralSum_fiberwise fun J => N (Ο€.tag J)] grw [← hcΞ΅, ← sum_le_hasSum _ (fun n _ => (Ξ΄ n).2) (NNReal.hasSum_coe.2 hΞ΄c)] apply norm_sum_le_of_le rintro n - dsimp [integralSum] have : βˆ€ J ∈ Ο€.filter fun J => N (Ο€.tag J) = n, β€–ΞΌ.real ↑J β€’ f (Ο€.tag J)β€– ≀ ΞΌ.real J * n := fun J hJ ↦ by rw [TaggedPrepartition.mem_filter] at hJ rw [norm_smul, Real.norm_eq_abs, abs_of_nonneg measureReal_nonneg] gcongr exact hJ.2 β–Έ Nat.le_ceil _ refine (norm_sum_le_of_le _ this).trans ?_; clear this rw [← sum_mul, ← Prepartition.measure_iUnion_toReal] let m := ΞΌ (Ο€.filter fun J => N (Ο€.tag J) = n).iUnion change m.toReal * ↑n ≀ ↑(Ξ΄ n) have : m < Ξ΄ n / n := by simp only [Measure.restrict_apply (hUo _).measurableSet] at hΞΌU refine (measure_mono ?_).trans_lt (hΞΌU _) simp only [Set.subset_def, TaggedPrepartition.mem_iUnion, TaggedPrepartition.mem_filter] rintro x ⟨J, ⟨hJ, rfl⟩, hx⟩ exact ⟨hrU _ (hΟ€.1 _ hJ (Box.coe_subset_Icc hx)), Ο€.le_of_mem' J hJ hx⟩ clear_value m lift m to ℝβ‰₯0 using ne_top_of_lt this grw [ENNReal.coe_toReal, ← NNReal.coe_natCast, ← NNReal.coe_mul, NNReal.coe_le_coe, ← ENNReal.coe_le_coe, ENNReal.coe_mul, ENNReal.coe_natCast, mul_comm, this, ENNReal.mul_div_le] /-- If `f` has integral `y` on a box `I` with respect to a locally finite measure `ΞΌ` and `g` is a.e. equal to `f` on `I`, then `g` has the same integral on `I`. -/ theorem HasIntegral.congr_ae {l : IntegrationParams} {I : Box ΞΉ} {y : E} {f g : (ΞΉ β†’ ℝ) β†’ E} {ΞΌ : Measure (ΞΉ β†’ ℝ)} [IsLocallyFiniteMeasure ΞΌ] (hf : HasIntegral.{u, v, v} I l f ΞΌ.toBoxAdditive.toSMul y) (hfg : f =ᡐ[ΞΌ.restrict I] g) (hl : l.bRiemann = false) : HasIntegral.{u, v, v} I l g ΞΌ.toBoxAdditive.toSMul y := by have : g - f =ᡐ[ΞΌ.restrict I] 0 := hfg.mono fun x hx => sub_eq_zero.2 hx.symm simpa using hf.add (HasIntegral.of_aeEq_zero this hl) end BoxIntegral namespace MeasureTheory namespace SimpleFunc /-- A simple function is McShane integrable w.r.t. any locally finite measure. -/ theorem hasBoxIntegral (f : SimpleFunc (ΞΉ β†’ ℝ) E) (ΞΌ : Measure (ΞΉ β†’ ℝ)) [IsLocallyFiniteMeasure ΞΌ] (I : Box ΞΉ) (l : IntegrationParams) (hl : l.bRiemann = false) : HasIntegral.{u, v, v} I l f ΞΌ.toBoxAdditive.toSMul (f.integral (ΞΌ.restrict I)) := by induction f using MeasureTheory.SimpleFunc.induction with | @const y s hs => simpa [hs] using BoxIntegral.hasIntegralIndicatorConst l hl hs I y ΞΌ | @add f g _ hfi hgi => borelize E; haveI := Fact.mk (I.measure_coe_lt_top ΞΌ) rw [integral_add] exacts [hfi.add hgi, integrable_iff.2 fun _ _ => measure_lt_top _ _, integrable_iff.2 fun _ _ => measure_lt_top _ _] /-- For a simple function, its McShane (or Henstock, or `βŠ₯`) box integral is equal to its integral in the sense of `MeasureTheory.SimpleFunc.integral`. -/ theorem box_integral_eq_integral (f : SimpleFunc (ΞΉ β†’ ℝ) E) (ΞΌ : Measure (ΞΉ β†’ ℝ)) [IsLocallyFiniteMeasure ΞΌ] (I : Box ΞΉ) (l : IntegrationParams) (hl : l.bRiemann = false) : BoxIntegral.integral.{u, v, v} I l f ΞΌ.toBoxAdditive.toSMul = f.integral (ΞΌ.restrict I) := (f.hasBoxIntegral ΞΌ I l hl).integral_eq end SimpleFunc open TopologicalSpace /-- If `f : ℝⁿ β†’ E` is Bochner integrable w.r.t. a locally finite measure `ΞΌ` on a rectangular box `I`, then it is McShane integrable on `I` with the same integral. -/ theorem IntegrableOn.hasBoxIntegral [CompleteSpace E] {f : (ΞΉ β†’ ℝ) β†’ E} {ΞΌ : Measure (ΞΉ β†’ ℝ)} [IsLocallyFiniteMeasure ΞΌ] {I : Box ΞΉ} (hf : IntegrableOn f I ΞΌ) (l : IntegrationParams) (hl : l.bRiemann = false) : HasIntegral.{u, v, v} I l f ΞΌ.toBoxAdditive.toSMul (∫ x in I, f x βˆ‚ΞΌ) := by borelize E -- First we replace an `ae_strongly_measurable` function by a measurable one. rcases hf.aestronglyMeasurable with ⟨g, hg, hfg⟩ haveI : SeparableSpace (range g βˆͺ {0} : Set E) := hg.separableSpace_range_union_singleton rw [integral_congr_ae hfg]; have hgi : IntegrableOn g I ΞΌ := (integrable_congr hfg).1 hf refine BoxIntegral.HasIntegral.congr_ae ?_ hfg.symm hl clear! f /- Now consider the sequence of simple functions `SimpleFunc.approxOn g hg.measurable (range g βˆͺ {0}) 0 (by simp)` approximating `g`. Recall some properties of this sequence. -/ set f : β„• β†’ SimpleFunc (ΞΉ β†’ ℝ) E := SimpleFunc.approxOn g hg.measurable (range g βˆͺ {0}) 0 (by simp) have hfi : βˆ€ n, IntegrableOn (f n) I ΞΌ := SimpleFunc.integrable_approxOn_range hg.measurable hgi have hfi' := fun n => ((f n).hasBoxIntegral ΞΌ I l hl).integrable have hfg_mono : βˆ€ (x) {m n}, m ≀ n β†’ β€–f n x - g xβ€– ≀ β€–f m x - g xβ€– := by intro x m n hmn rw [← dist_eq_norm, ← dist_eq_norm, dist_nndist, dist_nndist, NNReal.coe_le_coe, ← ENNReal.coe_le_coe, ← edist_nndist, ← edist_nndist] exact SimpleFunc.edist_approxOn_mono hg.measurable _ x hmn /- Now consider `Ξ΅ > 0`. We need to find `r` such that for any tagged partition subordinate to `r`, the integral sum is `(ΞΌ I + 1 + 1) * Ξ΅`-close to the Bochner integral. -/ refine HasIntegral.of_mul (ΞΌ.real I + 1 + 1) fun Ξ΅ Ξ΅0 => ?_ lift Ξ΅ to ℝβ‰₯0 using Ξ΅0.le; rw [NNReal.coe_pos] at Ξ΅0; have Ξ΅0' := ENNReal.coe_pos.2 Ξ΅0 -- Choose `N` such that the integral of `β€–f N x - g xβ€–` is less than or equal to `Ξ΅`. obtain ⟨Nβ‚€, hNβ‚€βŸ© : βˆƒ N : β„•, ∫ x in I, β€–f N x - g xβ€– βˆ‚ΞΌ ≀ Ξ΅ := by have : Tendsto (fun n => ∫⁻ x in I, β€–f n x - g xβ€–β‚Š βˆ‚ΞΌ) atTop (𝓝 0) := SimpleFunc.tendsto_approxOn_range_L1_enorm hg.measurable hgi refine (this.eventually (ge_mem_nhds Ξ΅0')).exists.imp fun N hN => ?_ exact integral_coe_le_of_lintegral_coe_le hN -- For each `x`, we choose `Nx x β‰₯ Nβ‚€` such that `dist (f Nx x) (g x) ≀ Ξ΅`. have : βˆ€ x, βˆƒ N₁, Nβ‚€ ≀ N₁ ∧ dist (f N₁ x) (g x) ≀ Ξ΅ := fun x ↦ by have : Tendsto (f Β· x) atTop (𝓝 <| g x) := SimpleFunc.tendsto_approxOn hg.measurable _ (subset_closure (by simp)) exact ((eventually_ge_atTop Nβ‚€).and <| this <| closedBall_mem_nhds _ Ξ΅0).exists choose Nx hNx hNxΞ΅ using this -- We also choose a convergent series with `βˆ‘' i : β„•, Ξ΄ i < Ξ΅`. rcases NNReal.exists_pos_sum_of_countable Ξ΅0.ne' β„• with ⟨δ, Ξ΄0, c, hΞ΄c, hcΡ⟩ /- Since each simple function `fα΅’` is integrable, there exists `rα΅’ : ℝⁿ β†’ (0, ∞)` such that the integral sum of `f` over any tagged prepartition is `Ξ΄α΅’`-close to the sum of integrals of `fα΅’` over the boxes of this prepartition. For each `x`, we choose `r (Nx x)` as the radius at `x`. -/ set r : ℝβ‰₯0 β†’ (ΞΉ β†’ ℝ) β†’ Ioi (0 : ℝ) := fun c x => (hfi' <| Nx x).convergenceR (Ξ΄ <| Nx x) c x refine ⟨r, fun c => l.rCond_of_bRiemann_eq_false hl, fun c Ο€ hΟ€ hΟ€p => ?_⟩ /- Now we prove the estimate in 3 "jumps": first we replace `g x` in the formula for the integral sum by `f (Nx x)`; then we replace each `ΞΌ J β€’ f (Nx (Ο€.tag J)) (Ο€.tag J)` by the Bochner integral of `f (Nx (Ο€.tag J)) x` over `J`, then we jump to the Bochner integral of `g`. -/ refine (dist_triangle4 _ (βˆ‘ J ∈ Ο€.boxes, ΞΌ.real J β€’ f (Nx <| Ο€.tag J) (Ο€.tag J)) (βˆ‘ J ∈ Ο€.boxes, ∫ x in J, f (Nx <| Ο€.tag J) x βˆ‚ΞΌ) _).trans ?_ rw [add_mul, add_mul, one_mul] refine add_le_add_three ?_ ?_ ?_ Β· /- Since each `f (Nx <| Ο€.tag J)` is `Ξ΅`-close to `g (Ο€.tag J)`, replacing the latter with the former in the formula for the integral sum changes the sum at most by `ΞΌ I * Ξ΅`. -/ rw [← hΟ€p.iUnion_eq, Ο€.measure_iUnion_toReal, sum_mul, integralSum] refine dist_sum_sum_le_of_le _ fun J _ => ?_; dsimp rw [dist_eq_norm, ← smul_sub, norm_smul, Real.norm_eq_abs, abs_of_nonneg measureReal_nonneg] gcongr rw [← dist_eq_norm']; exact hNxΞ΅ _ Β· /- We group the terms of both sums by the values of `Nx (Ο€.tag J)`. For each `N`, the sum of Bochner integrals over the boxes is equal to the sum of box integrals, and the sum of box integrals is `Ξ΄α΅’`-close to the corresponding integral sum due to the Henstock-Sacks inequality. -/ rw [← Ο€.sum_fiberwise fun J => Nx (Ο€.tag J), ← Ο€.sum_fiberwise fun J => Nx (Ο€.tag J)] grw [← hcΞ΅] refine (dist_sum_sum_le_of_le _ fun n hn => ?_).trans (sum_le_hasSum _ (fun n _ => (Ξ΄ n).2) (NNReal.hasSum_coe.2 hΞ΄c)) have hNxn : βˆ€ J ∈ Ο€.filter fun J => Nx (Ο€.tag J) = n, Nx (Ο€.tag J) = n := fun J hJ => (Ο€.mem_filter.1 hJ).2 have hrn : βˆ€ J ∈ Ο€.filter fun J => Nx (Ο€.tag J) = n, r c (Ο€.tag J) = (hfi' n).convergenceR (Ξ΄ n) c (Ο€.tag J) := fun J hJ ↦ by obtain rfl := hNxn J hJ rfl have : l.MemBaseSet I c ((hfi' n).convergenceR (Ξ΄ n) c) (Ο€.filter fun J => Nx (Ο€.tag J) = n) := (hΟ€.filter _).mono' _ le_rfl le_rfl fun J hJ => (hrn J hJ).le convert (hfi' n).dist_integralSum_sum_integral_le_of_memBaseSet (Ξ΄0 _) this using 2 Β· refine sum_congr rfl fun J hJ => ?_ simp [hNxn J hJ] Β· refine sum_congr rfl fun J hJ => ?_ rw [← SimpleFunc.integral_eq_integral, SimpleFunc.box_integral_eq_integral _ _ _ _ hl, hNxn J hJ] exact (hfi _).mono_set (Prepartition.le_of_mem _ hJ) Β· /- For the last jump, we use the fact that the distance between `f (Nx x) x` and `g x` is less than or equal to the distance between `f Nβ‚€ x` and `g x` and the integral of `β€–f Nβ‚€ x - g xβ€–` is less than or equal to `Ξ΅`. -/ refine le_trans ?_ hNβ‚€ have hfi : βˆ€ (n), βˆ€ J ∈ Ο€, IntegrableOn (f n) (↑J) ΞΌ := fun n J hJ => (hfi n).mono_set (Ο€.le_of_mem' J hJ) have hgi : βˆ€ J ∈ Ο€, IntegrableOn g (↑J) ΞΌ := fun J hJ => hgi.mono_set (Ο€.le_of_mem' J hJ) have hfgi : βˆ€ (n), βˆ€ J ∈ Ο€, IntegrableOn (fun x => β€–f n x - g xβ€–) J ΞΌ := fun n J hJ => ((hfi n J hJ).sub (hgi J hJ)).norm rw [← hΟ€p.iUnion_eq, Prepartition.iUnion_def', integral_biUnion_finset Ο€.boxes (fun J _ => J.measurableSet_coe) Ο€.pairwiseDisjoint hgi, integral_biUnion_finset Ο€.boxes (fun J _ => J.measurableSet_coe) Ο€.pairwiseDisjoint (hfgi _)] refine dist_sum_sum_le_of_le _ fun J hJ => ?_ rw [dist_eq_norm, ← integral_sub (hfi _ J hJ) (hgi J hJ)] refine norm_integral_le_of_norm_le (hfgi _ J hJ) (Eventually.of_forall fun x => ?_) exact hfg_mono x (hNx (Ο€.tag J)) /-- If `f : ℝⁿ β†’ E` is continuous on a rectangular box `I`, then it is Box integrable on `I` w.r.t. a locally finite measure `ΞΌ` with the same integral. -/ theorem ContinuousOn.hasBoxIntegral [CompleteSpace E] {f : (ΞΉ β†’ ℝ) β†’ E} (ΞΌ : Measure (ΞΉ β†’ ℝ)) [IsLocallyFiniteMeasure ΞΌ] {I : Box ΞΉ} (hc : ContinuousOn f (Box.Icc I)) (l : IntegrationParams) : HasIntegral.{u, v, v} I l f ΞΌ.toBoxAdditive.toSMul (∫ x in I, f x βˆ‚ΞΌ) := by obtain ⟨y, hy⟩ := BoxIntegral.integrable_of_continuousOn l hc ΞΌ convert hy have : IntegrableOn f I ΞΌ := IntegrableOn.mono_set (hc.integrableOn_compact I.isCompact_Icc) Box.coe_subset_Icc exact HasIntegral.unique (IntegrableOn.hasBoxIntegral this βŠ₯ rfl) (HasIntegral.mono hy bot_le) /-- If `f : ℝⁿ β†’ E` is a.e. continuous and bounded on a rectangular box `I`, then it is Box integrable on `I` w.r.t. a locally finite measure `ΞΌ` with the same integral. -/ theorem AEContinuous.hasBoxIntegral [CompleteSpace E] {f : (ΞΉ β†’ ℝ) β†’ E} (ΞΌ : Measure (ΞΉ β†’ ℝ)) [IsLocallyFiniteMeasure ΞΌ] {I : Box ΞΉ} (hb : βˆƒ C : ℝ, βˆ€ x ∈ Box.Icc I, β€–f xβ€– ≀ C) (hc : βˆ€α΅ x βˆ‚ΞΌ, ContinuousAt f x) (l : IntegrationParams) : HasIntegral.{u, v, v} I l f ΞΌ.toBoxAdditive.toSMul (∫ x in I, f x βˆ‚ΞΌ) := by obtain ⟨y, hy⟩ := integrable_of_bounded_and_ae_continuous l hb ΞΌ hc convert hy refine HasIntegral.unique (IntegrableOn.hasBoxIntegral ?_ βŠ₯ rfl) (HasIntegral.mono hy bot_le) constructor Β· let v := {x : (ΞΉ β†’ ℝ) | ContinuousAt f x} have : AEStronglyMeasurable f (ΞΌ.restrict v) := (continuousOn_of_forall_continuousAt fun _ h ↦ h).aestronglyMeasurable (measurableSet_of_continuousAt f) refine this.mono_measure (Measure.le_iff.2 fun s hs ↦ ?_) repeat rw [ΞΌ.restrict_apply hs] apply le_of_le_of_eq <| ΞΌ.mono s.inter_subset_left refine measure_eq_measure_of_null_diff s.inter_subset_left ?_ |>.symm rw [diff_self_inter, Set.diff_eq] refine (le_antisymm (zero_le (ΞΌ (s ∩ vᢜ))) ?_).symm exact le_trans (ΞΌ.mono s.inter_subset_right) (nonpos_iff_eq_zero.2 hc) Β· have : IsFiniteMeasure (ΞΌ.restrict (Box.Icc I)) := { measure_univ_lt_top := by simp [I.isCompact_Icc.measure_lt_top (ΞΌ := ΞΌ)] } have : IsFiniteMeasure (ΞΌ.restrict I) := isFiniteMeasure_of_le (ΞΌ.restrict (Box.Icc I)) (ΞΌ.restrict_mono Box.coe_subset_Icc (le_refl ΞΌ)) obtain ⟨C, hC⟩ := hb refine .of_bounded (C := C) (Filter.eventually_iff_exists_mem.2 ?_) use I, self_mem_ae_restrict I.measurableSet_coe, fun y hy ↦ hC y (I.coe_subset_Icc hy) end MeasureTheory
.lake/packages/mathlib/Mathlib/Analysis/BoxIntegral/UnitPartition.lean
import Mathlib.Algebra.Module.ZLattice.Basic import Mathlib.Analysis.BoxIntegral.Integrability import Mathlib.Analysis.BoxIntegral.Partition.Measure import Mathlib.Analysis.BoxIntegral.Partition.Tagged /-! # Unit Partition Fix `n` a positive integer. `BoxIntegral.unitPartition.box` are boxes in `ΞΉ β†’ ℝ` obtained by dividing the unit box uniformly into boxes of side length `1 / n` and translating the boxes by vectors `Ξ½ : ΞΉ β†’ β„€`. Let `B` be a `BoxIntegral`. A `unitPartition.box` is admissible for `B` (more precisely its index is admissible) if it is contained in `B`. There are finitely many admissible `unitPartition.box` for `B` and thus we can form the corresponding tagged prepartition, see `BoxIntegral.unitPartition.prepartition` (note that each `unitPartition.box` comes with its tag situated at its "upper most" vertex). If `B` satisfies `hasIntegralVertices`, that is its vertices are in `ΞΉ β†’ β„€`, then the corresponding prepartition is actually a partition. ## Main definitions and results * `BoxIntegral.hasIntegralVertices`: a `Prop` that states that the vertices of the box have coordinates in `β„€` * `BoxIntegral.unitPartition.box`: a `BoxIntegral`, indexed by `Ξ½ : ΞΉ β†’ β„€`, with vertices `Ξ½ i / n` and of side length `1 / n`. * `BoxIntegral.unitPartition.admissibleIndex`: For `B : BoxIntegral.Box`, the set of indices of `unitPartition.box` that are subsets of `B`. This is a finite set. * `BoxIntegral.unitPartition.prepartition_isPartition`: For `B : BoxIntegral.Box`, if `B` has integral vertices, then the prepartition of `unitPartition.box` admissible for `B` is a partition of `B`. * `tendsto_tsum_div_pow_atTop_integral`: let `s` be a bounded, measurable set of `ΞΉ β†’ ℝ` whose frontier has zero volume and let `F` be a continuous function. Then the limit as `n β†’ ∞` of `βˆ‘ F x / n ^ card ΞΉ`, where the sum is over the points in `s ∩ n⁻¹ β€’ (ΞΉ β†’ β„€)`, tends to the integral of `F` over `s`. * `tendsto_card_div_pow_atTop_volume`: let `s` be a bounded, measurable set of `ΞΉ β†’ ℝ` whose frontier has zero volume. Then the limit as `n β†’ ∞` of `card (s ∩ n⁻¹ β€’ (ΞΉ β†’ β„€)) / n ^ card ΞΉ` tends to the volume of `s`. * `tendsto_card_div_pow_atTop_volume'`: a version of `tendsto_card_div_pow_atTop_volume` where we assume in addition that `x β€’ s βŠ† y β€’ s` whenever `0 < x ≀ y`. Then we get the same limit `card (s ∩ x⁻¹ β€’ (ΞΉ β†’ β„€)) / x ^ card ΞΉ β†’ volume s` but the limit is over a real variable `x`. -/ noncomputable section variable {ΞΉ : Type*} open scoped Topology section hasIntegralVertices open Bornology /-- A `BoxIntegral.Box` has integral vertices if its vertices have coordinates in `β„€`. -/ def BoxIntegral.hasIntegralVertices (B : Box ΞΉ) : Prop := βˆƒ l u : ΞΉ β†’ β„€, (βˆ€ i, B.lower i = l i) ∧ (βˆ€ i, B.upper i = u i) /-- Any bounded set is contained in a `BoxIntegral.Box` with integral vertices. -/ theorem BoxIntegral.le_hasIntegralVertices_of_isBounded [Finite ΞΉ] {s : Set (ΞΉ β†’ ℝ)} (h : IsBounded s) : βˆƒ B : BoxIntegral.Box ΞΉ, hasIntegralVertices B ∧ s ≀ B := by have := Fintype.ofFinite ΞΉ obtain ⟨R, hR₁, hRβ‚‚βŸ© := IsBounded.subset_ball_lt h 0 0 let C : β„• := ⌈RβŒ‰β‚Š have hC := Nat.ceil_pos.mpr hR₁ let I : Box ΞΉ := Box.mk (fun _ ↦ - C) (fun _ ↦ C ) (fun _ ↦ by simp [C, neg_lt_self_iff, Nat.cast_pos, hC]) refine ⟨I, ⟨fun _ ↦ - C, fun _ ↦ C, fun i ↦ (Int.cast_neg_natCast C).symm, fun _ ↦ rfl⟩, le_trans hRβ‚‚ ?_⟩ suffices Metric.ball (0 : ΞΉ β†’ ℝ) C ≀ I from le_trans (Metric.ball_subset_ball (Nat.le_ceil R)) this intro x hx simp_rw [C, mem_ball_zero_iff, pi_norm_lt_iff (Nat.cast_pos.mpr hC), Real.norm_eq_abs, abs_lt] at hx exact fun i ↦ ⟨(hx i).1, le_of_lt (hx i).2⟩ end hasIntegralVertices namespace BoxIntegral.unitPartition open Bornology MeasureTheory Fintype BoxIntegral variable (n : β„•) /-- A `BoxIntegral`, indexed by a positive integer `n` and `Ξ½ : ΞΉ β†’ β„€`, with corners `Ξ½ i / n` and of side length `1 / n`. -/ def box [NeZero n] (Ξ½ : ΞΉ β†’ β„€) : Box ΞΉ where lower := fun i ↦ Ξ½ i / n upper := fun i ↦ (Ξ½ i + 1) / n lower_lt_upper := fun _ ↦ by simp [add_div, n.pos_of_neZero] @[simp] theorem box_lower [NeZero n] (Ξ½ : ΞΉ β†’ β„€) : (box n Ξ½).lower = fun i ↦ (Ξ½ i / n : ℝ) := rfl @[simp] theorem box_upper [NeZero n] (Ξ½ : ΞΉ β†’ β„€) : (box n Ξ½).upper = fun i ↦ ((Ξ½ i + 1) / n : ℝ) := rfl variable {n} in @[simp] theorem mem_box_iff [NeZero n] {Ξ½ : ΞΉ β†’ β„€} {x : ΞΉ β†’ ℝ} : x ∈ box n Ξ½ ↔ βˆ€ i, Ξ½ i / n < x i ∧ x i ≀ (Ξ½ i + 1) / n := by simp_rw [Box.mem_def, box, Set.mem_Ioc] variable {n} in theorem mem_box_iff' [NeZero n] {Ξ½ : ΞΉ β†’ β„€} {x : ΞΉ β†’ ℝ} : x ∈ box n Ξ½ ↔ βˆ€ i, Ξ½ i < n * x i ∧ n * x i ≀ Ξ½ i + 1 := by have h : 0 < (n : ℝ) := Nat.cast_pos.mpr <| n.pos_of_neZero simp_rw [mem_box_iff, ← _root_.le_div_iffβ‚€' h, ← div_lt_iffβ‚€' h] /-- The tag of (the index of) a `unitPartition.box`. -/ abbrev tag (Ξ½ : ΞΉ β†’ β„€) : ΞΉ β†’ ℝ := fun i ↦ (Ξ½ i + 1) / n @[simp] theorem tag_apply (Ξ½ : ΞΉ β†’ β„€) (i : ΞΉ) : tag n Ξ½ i = (Ξ½ i + 1) / n := rfl variable [NeZero n] theorem tag_injective : Function.Injective (fun Ξ½ : ΞΉ β†’ β„€ ↦ tag n Ξ½) := by refine fun _ _ h ↦ funext_iff.mpr fun i ↦ ?_ have := congr_arg (fun x ↦ x i) h simp_rw [tag_apply, div_left_inj' (c := (n : ℝ)) (Nat.cast_ne_zero.mpr (NeZero.ne n)), add_left_inj, Int.cast_inj] at this exact this theorem tag_mem (Ξ½ : ΞΉ β†’ β„€) : tag n Ξ½ ∈ box n Ξ½ := by refine mem_box_iff.mpr fun _ ↦ ?_ rw [tag, add_div] have h : 0 < (n : ℝ) := Nat.cast_pos.mpr <| n.pos_of_neZero exact ⟨lt_add_of_pos_right _ (by positivity), le_rfl⟩ /-- For `x : ΞΉ β†’ ℝ`, its index is the index of the unique `unitPartition.box` to which it belongs. -/ def index (x : ΞΉ β†’ ℝ) (i : ΞΉ) : β„€ := ⌈n * x iβŒ‰ - 1 @[simp] theorem index_apply (m : β„•) {x : ΞΉ β†’ ℝ} (i : ΞΉ) : index m x i = ⌈m * x iβŒ‰ - 1 := rfl variable {n} in theorem mem_box_iff_index {x : ΞΉ β†’ ℝ} {Ξ½ : ΞΉ β†’ β„€} : x ∈ box n Ξ½ ↔ index n x = Ξ½ := by simp_rw [mem_box_iff', funext_iff, index_apply, sub_eq_iff_eq_add, Int.ceil_eq_iff, Int.cast_add, Int.cast_one, add_sub_cancel_right] @[simp] theorem index_tag (Ξ½ : ΞΉ β†’ β„€) : index n (tag n Ξ½) = Ξ½ := mem_box_iff_index.mp (tag_mem n Ξ½) variable {n} in theorem disjoint {Ξ½ Ξ½' : ΞΉ β†’ β„€} : Ξ½ β‰  Ξ½' ↔ Disjoint (box n Ξ½).toSet (box n Ξ½').toSet := by rw [not_iff_comm, Set.not_disjoint_iff] refine ⟨fun ⟨x, hx, hx'⟩ ↦ ?_, fun h ↦ ⟨tag n Ξ½, tag_mem n Ξ½, h β–Έ tag_mem n ν⟩⟩ rw [← mem_box_iff_index.mp hx, ← mem_box_iff_index.mp hx'] theorem box_injective : Function.Injective (fun Ξ½ : ΞΉ β†’ β„€ ↦ box n Ξ½) := by intro _ _ h contrapose! h exact Box.ne_of_disjoint_coe (disjoint.mp h) lemma box.upper_sub_lower (Ξ½ : ΞΉ β†’ β„€) (i : ΞΉ) : (box n Ξ½ ).upper i - (box n Ξ½).lower i = 1 / n := by simp_rw [box, add_div, add_sub_cancel_left] variable [Fintype ΞΉ] theorem diam_boxIcc (Ξ½ : ΞΉ β†’ β„€) : Metric.diam (Box.Icc (box n Ξ½)) ≀ 1 / n := by rw [BoxIntegral.Box.Icc_eq_pi] refine ENNReal.toReal_le_of_le_ofReal (by positivity) <| EMetric.diam_pi_le_of_le (fun i ↦ ?_) simp_rw [Real.ediam_Icc, box.upper_sub_lower, le_rfl] @[simp] theorem volume_box (Ξ½ : ΞΉ β†’ β„€) : volume (box n Ξ½ : Set (ΞΉ β†’ ℝ)) = 1 / n ^ card ΞΉ := by simp_rw [volume_pi, BoxIntegral.Box.coe_eq_pi, Measure.pi_pi, Real.volume_Ioc, box.upper_sub_lower, Finset.prod_const, ENNReal.ofReal_div_of_pos (Nat.cast_pos.mpr n.pos_of_neZero), ENNReal.ofReal_one, ENNReal.ofReal_natCast, one_div, ENNReal.inv_pow, Finset.card_univ] theorem setFinite_index {s : Set (ΞΉ β†’ ℝ)} (hs₁ : NullMeasurableSet s) (hsβ‚‚ : volume s β‰  ⊀) : Set.Finite {Ξ½ : ΞΉ β†’ β„€ | ↑(box n Ξ½) βŠ† s} := by refine (Measure.finite_const_le_meas_of_disjoint_iUnionβ‚€ volume (Ξ΅ := 1 / n ^ card ΞΉ) (by simp) (As := fun Ξ½ : ΞΉ β†’ β„€ ↦ (box n Ξ½) ∩ s) (fun Ξ½ ↦ ?_) (fun _ _ h ↦ ?_) ?_).subset (fun _ hΞ½ ↦ ?_) Β· refine NullMeasurableSet.inter ?_ hs₁ exact (box n Ξ½).measurableSet_coe.nullMeasurableSet Β· exact ((Disjoint.inter_right _ (disjoint.mp h)).inter_left _ ).aedisjoint Β· exact lt_top_iff_ne_top.mp <| measure_lt_top_of_subset (by simp only [Set.iUnion_subset_iff, Set.inter_subset_right, implies_true]) hsβ‚‚ Β· rw [Set.mem_setOf, Set.inter_eq_self_of_subset_left hΞ½, volume_box] /-- For `B : BoxIntegral.Box`, the set of indices of `unitPartition.box` that are subsets of `B`. This is a finite set. These boxes cover `B` if it has integral vertices, see `unitPartition.prepartition_isPartition`. -/ def admissibleIndex (B : Box ΞΉ) : Finset (ΞΉ β†’ β„€) := by refine (setFinite_index n B.measurableSet_coe.nullMeasurableSet ?_).toFinset exact lt_top_iff_ne_top.mp (IsBounded.measure_lt_top B.isBounded) variable {n} in theorem mem_admissibleIndex_iff {B : Box ΞΉ} {Ξ½ : ΞΉ β†’ β„€} : Ξ½ ∈ admissibleIndex n B ↔ box n Ξ½ ≀ B := by rw [admissibleIndex, Set.Finite.mem_toFinset, Set.mem_setOf_eq, Box.coe_subset_coe] open Classical in /-- For `B : BoxIntegral.Box`, the `TaggedPrepartition` formed by the set of all `unitPartition.box` whose index is `B`-admissible. -/ def prepartition (B : Box ΞΉ) : TaggedPrepartition B where boxes := Finset.image (fun Ξ½ ↦ box n Ξ½) (admissibleIndex n B) le_of_mem' _ hI := by obtain ⟨_, hΞ½, rfl⟩ := Finset.mem_image.mp hI exact mem_admissibleIndex_iff.mp hΞ½ pairwiseDisjoint _ hI₁ _ hIβ‚‚ h := by obtain ⟨_, _, rfl⟩ := Finset.mem_image.mp hI₁ obtain ⟨_, _, rfl⟩ := Finset.mem_image.mp hIβ‚‚ exact disjoint.mp fun x ↦ h (congrArg (box n) x) tag I := if hI : βˆƒ Ξ½ ∈ admissibleIndex n B, I = box n Ξ½ then tag n hI.choose else B.exists_mem.choose tag_mem_Icc I := by by_cases hI : βˆƒ Ξ½ ∈ admissibleIndex n B, I = box n Ξ½ Β· simp_rw [dif_pos hI] exact Box.coe_subset_Icc <| (mem_admissibleIndex_iff.mp hI.choose_spec.1) (tag_mem n _) Β· simp_rw [dif_neg hI] exact Box.coe_subset_Icc B.exists_mem.choose_spec variable {n} in @[simp] theorem mem_prepartition_iff {B I : Box ΞΉ} : I ∈ prepartition n B ↔ βˆƒ Ξ½ ∈ admissibleIndex n B, box n Ξ½ = I := by classical rw [prepartition, TaggedPrepartition.mem_mk, Prepartition.mem_mk, Finset.mem_image] variable {n} in theorem mem_prepartition_boxes_iff {B I : Box ΞΉ} : I ∈ (prepartition n B).boxes ↔ βˆƒ Ξ½ ∈ admissibleIndex n B, box n Ξ½ = I := mem_prepartition_iff theorem prepartition_tag {Ξ½ : ΞΉ β†’ β„€} {B : Box ΞΉ} (hΞ½ : Ξ½ ∈ admissibleIndex n B) : (prepartition n B).tag (box n Ξ½) = tag n Ξ½ := by dsimp only [prepartition] have h : βˆƒ Ξ½' ∈ admissibleIndex n B, box n Ξ½ = box n Ξ½' := ⟨ν, hΞ½, rfl⟩ rw [dif_pos h, (tag_injective n).eq_iff, ← (box_injective n).eq_iff] exact h.choose_spec.2.symm theorem box_index_tag_eq_self {B I : Box ΞΉ} (hI : I ∈ (prepartition n B).boxes) : box n (index n ((prepartition n B).tag I)) = I := by obtain ⟨ν, hΞ½, rfl⟩ := mem_prepartition_boxes_iff.mp hI rw [prepartition_tag n hΞ½, index_tag] theorem prepartition_isHenstock (B : Box ΞΉ) : (prepartition n B).IsHenstock := by intro _ hI obtain ⟨ν, hΞ½, rfl⟩ := mem_prepartition_iff.mp hI rw [prepartition_tag n hΞ½] exact Box.coe_subset_Icc (tag_mem _ _) theorem prepartition_isSubordinate (B : Box ΞΉ) {r : ℝ} (hr : 0 < r) (hn : 1 / n ≀ r) : (prepartition n B).IsSubordinate (fun _ ↦ ⟨r, hr⟩) := by intro _ hI obtain ⟨ν, hΞ½, rfl⟩ := mem_prepartition_iff.mp hI refine fun _ h ↦ le_trans (Metric.dist_le_diam_of_mem (Box.isBounded_Icc _) h ?_) ?_ Β· rw [prepartition_tag n hΞ½] exact Box.coe_subset_Icc (tag_mem _ _) Β· exact le_trans (diam_boxIcc n Ξ½) hn private theorem mem_admissibleIndex_of_mem_box_aux₁ (x : ℝ) (a : β„€) : a < x ↔ a ≀ (⌈n * xβŒ‰ - 1) / (n : ℝ) := by have h : 0 < (n : ℝ) := Nat.cast_pos.mpr <| n.pos_of_neZero rw [le_div_iffβ‚€' h, le_sub_iff_add_le, show (n : ℝ) * a + 1 = (n * a + 1 : β„€) by norm_cast, Int.cast_le, Int.add_one_le_ceil_iff, Int.cast_mul, Int.cast_natCast, mul_lt_mul_iff_rightβ‚€ h] private theorem mem_admissibleIndex_of_mem_box_auxβ‚‚ (x : ℝ) (a : β„€) : x ≀ a ↔ (⌈n * xβŒ‰ - 1 + 1) / (n : ℝ) ≀ a := by have h : 0 < (n : ℝ) := Nat.cast_pos.mpr <| n.pos_of_neZero rw [sub_add_cancel, div_le_iffβ‚€' h, show (n : ℝ) * a = (n * a : β„€) by norm_cast, Int.cast_le, Int.ceil_le, Int.cast_mul, Int.cast_natCast, mul_le_mul_iff_rightβ‚€ h] /-- If `B : BoxIntegral.Box` has integral vertices and contains the point `x`, then the index of `x` is admissible for `B`. -/ theorem mem_admissibleIndex_of_mem_box {B : Box ΞΉ} (hB : hasIntegralVertices B) {x : ΞΉ β†’ ℝ} (hx : x ∈ B) : index n x ∈ admissibleIndex n B := by obtain ⟨l, u, hl, hu⟩ := hB simp_rw [mem_admissibleIndex_iff, Box.le_iff_bounds, box_lower, box_upper, Pi.le_def, index_apply, hl, hu, ← forall_and] push_cast refine fun i ↦ ⟨?_, ?_⟩ Β· exact (mem_admissibleIndex_of_mem_box_aux₁ n (x i) (l i)).mp ((hl i) β–Έ (hx i).1) Β· exact (mem_admissibleIndex_of_mem_box_auxβ‚‚ n (x i) (u i)).mp ((hu i) β–Έ (hx i).2) /-- If `B : BoxIntegral.Box` has integral vertices, then `prepartition n B` is a partition of `B`. -/ theorem prepartition_isPartition {B : Box ΞΉ} (hB : hasIntegralVertices B) : (prepartition n B).IsPartition := by refine fun x hx ↦ ⟨box n (index n x), ?_, mem_box_iff_index.mpr rfl⟩ rw [TaggedPrepartition.mem_toPrepartition, mem_prepartition_iff] exact ⟨index n x, mem_admissibleIndex_of_mem_box n hB hx, rfl⟩ open Submodule Pointwise BigOperators open scoped Pointwise variable (c : ℝ) (s : Set (ΞΉ β†’ ℝ)) (F : (ΞΉ β†’ ℝ) β†’ ℝ) -- The image of `ΞΉ β†’ β„€` inside `ΞΉ β†’ ℝ` local notation "L" => span β„€ (Set.range (Pi.basisFun ℝ ΞΉ)) variable {n} in theorem mem_smul_span_iff {v : ΞΉ β†’ ℝ} : v ∈ (n : ℝ)⁻¹ β€’ L ↔ βˆ€ i, n * v i ∈ Set.range (algebraMap β„€ ℝ) := by rw [ZSpan.smul _ (inv_ne_zero (NeZero.ne _)), Module.Basis.mem_span_iff_repr_mem] simp_rw [Module.Basis.repr_isUnitSMul, Pi.basisFun_repr, Units.smul_def, Units.val_inv_eq_inv_val, IsUnit.unit_spec, inv_inv, smul_eq_mul] theorem tag_mem_smul_span (Ξ½ : ΞΉ β†’ β„€) : tag n Ξ½ ∈ (n : ℝ)⁻¹ β€’ L := by refine mem_smul_span_iff.mpr fun i ↦ ⟨ν i + 1, ?_⟩ rw [tag_apply, div_eq_inv_mul, ← mul_assoc, mul_inv_cancel_of_invertible, one_mul, map_add, map_one, eq_intCast] theorem tag_index_eq_self_of_mem_smul_span {x : ΞΉ β†’ ℝ} (hx : x ∈ (n : ℝ)⁻¹ β€’ L) : tag n (index n x) = x := by rw [mem_smul_span_iff] at hx ext i obtain ⟨a, ha⟩ : βˆƒ a : β„€, a = n * x i := hx i rwa [tag_apply, index_apply, Int.cast_sub, Int.cast_one, sub_add_cancel, ← ha, Int.ceil_intCast, div_eq_iff (NeZero.ne _), mul_comm] theorem eq_of_mem_smul_span_of_index_eq_index {x y : ΞΉ β†’ ℝ} (hx : x ∈ (n : ℝ)⁻¹ β€’ L) (hy : y ∈ (n : ℝ)⁻¹ β€’ L) (h : index n x = index n y) : x = y := by rw [← tag_index_eq_self_of_mem_smul_span n hx, ← tag_index_eq_self_of_mem_smul_span n hy, h] theorem integralSum_eq_tsum_div {B : Box ΞΉ} (hB : hasIntegralVertices B) (hsβ‚€ : s ≀ B) : integralSum (Set.indicator s F) (BoxAdditiveMap.toSMul (Measure.toBoxAdditive volume)) (prepartition n B) = (βˆ‘' x : ↑(s ∩ (n : ℝ)⁻¹ β€’ L), F x) / n ^ card ΞΉ := by classical unfold integralSum have : Fintype ↑(s ∩ (n : ℝ)⁻¹ β€’ L) := by apply Set.Finite.fintype rw [← coe_pointwise_smul, ZSpan.smul _ (inv_ne_zero (NeZero.ne _))] exact ZSpan.setFinite_inter _ (B.isBounded.subset hsβ‚€) rw [tsum_fintype, Finset.sum_set_coe, Finset.sum_div, eq_comm] simp_rw [Set.indicator_apply, apply_ite, BoxAdditiveMap.toSMul_apply, Measure.toBoxAdditive_apply, smul_eq_mul, mul_zero, Finset.sum_ite, Finset.sum_const_zero, add_zero] refine Finset.sum_bij (fun x _ ↦ box n (index n x)) (fun _ hx ↦ Finset.mem_filter.mpr ?_) (fun _ hx _ hy h ↦ ?_) (fun I hI ↦ ?_) (fun _ hx ↦ ?_) Β· rw [Set.mem_toFinset] at hx refine ⟨mem_prepartition_boxes_iff.mpr ⟨index n _, mem_admissibleIndex_of_mem_box n hB (hsβ‚€ hx.1), rfl⟩, ?_⟩ simp_rw [prepartition_tag n (mem_admissibleIndex_of_mem_box n hB (hsβ‚€ hx.1)), tag_index_eq_self_of_mem_smul_span n hx.2, hx.1] Β· rw [Set.mem_toFinset] at hx hy exact eq_of_mem_smul_span_of_index_eq_index n hx.2 hy.2 (box_injective n h) Β· rw [Finset.mem_filter] at hI refine ⟨(prepartition n B).tag I, Set.mem_toFinset.mpr ⟨hI.2, ?_⟩, box_index_tag_eq_self n hI.1⟩ rw [← box_index_tag_eq_self n hI.1, prepartition_tag n (mem_admissibleIndex_of_mem_box n hB (hsβ‚€ hI.2))] exact tag_mem_smul_span _ _ Β· rw [Set.mem_toFinset] at hx rw [measureReal_def, volume_box, prepartition_tag n (mem_admissibleIndex_of_mem_box n hB (hsβ‚€ hx.1)), tag_index_eq_self_of_mem_smul_span n hx.2, ENNReal.toReal_div, ENNReal.toReal_one, ENNReal.toReal_pow, ENNReal.toReal_natCast, mul_comm_div, one_mul] open Filter /-- Let `s` be a bounded, measurable set of `ΞΉ β†’ ℝ` whose frontier has zero volume and let `F` be a continuous function. Then the limit as `n β†’ ∞` of `βˆ‘ F x / n ^ card ΞΉ`, where the sum is over the points in `s ∩ n⁻¹ β€’ (ΞΉ β†’ β„€)`, tends to the integral of `F` over `s`. -/ theorem _root_.tendsto_tsum_div_pow_atTop_integral (hF : Continuous F) (hs₁ : IsBounded s) (hsβ‚‚ : MeasurableSet s) (hs₃ : volume (frontier s) = 0) : Tendsto (fun n : β„• ↦ (βˆ‘' x : ↑(s ∩ (n : ℝ)⁻¹ β€’ L), F x) / n ^ card ΞΉ) atTop (nhds (∫ x in s, F x)) := by obtain ⟨B, hB, hsβ‚€βŸ© := le_hasIntegralVertices_of_isBounded hs₁ refine Metric.tendsto_atTop.mpr fun Ξ΅ hΞ΅ ↦ ?_ have h₁ : βˆƒ C, βˆ€ x ∈ Box.Icc B, β€–Set.indicator s F xβ€– ≀ C := by obtain ⟨Cβ‚€, hβ‚€βŸ© := (Box.isCompact_Icc B).exists_bound_of_continuousOn hF.continuousOn refine ⟨max 0 Cβ‚€, fun x hx ↦ ?_⟩ rw [Set.indicator] split_ifs with hs Β· exact le_max_of_le_right (hβ‚€ x hx) Β· exact norm_zero.trans_le <|le_max_left 0 _ have hβ‚‚ : βˆ€α΅ x, ContinuousAt (s.indicator F) x := by filter_upwards [compl_mem_ae_iff.mpr hs₃] with _ h using (hF.continuousOn).continuousAt_indicator h obtain ⟨r, hr₁, hrβ‚‚βŸ© := (hasIntegral_iff.mp <| AEContinuous.hasBoxIntegral (volume : Measure (ΞΉ β†’ ℝ)) h₁ hβ‚‚ IntegrationParams.Riemann) (Ξ΅ / 2) (half_pos hΞ΅) refine ⟨⌈(r 0 0 : ℝ)β»ΒΉβŒ‰β‚Š, fun n hn ↦ lt_of_le_of_lt ?_ (half_lt_self_iff.mpr hΞ΅)⟩ have : NeZero n := ⟨Nat.ne_zero_iff_zero_lt.mpr <| (Nat.ceil_pos.mpr (inv_pos.mpr (r 0 0).prop)).trans_le hn⟩ rw [← integralSum_eq_tsum_div _ s F hB hsβ‚€, ← Measure.restrict_restrict_of_subset hsβ‚€, ← integral_indicator hsβ‚‚] refine hrβ‚‚ 0 _ ⟨?_, fun _ ↦ ?_, fun h ↦ ?_, fun h ↦ ?_⟩ (prepartition_isPartition _ hB) Β· rw [show r 0 = fun _ ↦ r 0 0 from funext_iff.mpr (hr₁ 0 rfl)] apply prepartition_isSubordinate n B rw [one_div, inv_le_commβ‚€ (mod_cast (Nat.pos_of_neZero n)) (r 0 0).prop] exact le_trans (Nat.le_ceil _) (Nat.cast_le.mpr hn) Β· exact prepartition_isHenstock n B Β· simp only [IntegrationParams.Riemann, Bool.false_eq_true] at h Β· simp only [IntegrationParams.Riemann, Bool.false_eq_true] at h /-- Let `s` be a bounded, measurable set of `ΞΉ β†’ ℝ` whose frontier has zero volume. Then the limit as `n β†’ ∞` of `card (s ∩ n⁻¹ β€’ (ΞΉ β†’ β„€)) / n ^ card ΞΉ` tends to the volume of `s`. This is a special case of `tendsto_card_div_pow` with `F = 1`. -/ theorem _root_.tendsto_card_div_pow_atTop_volume (hs₁ : IsBounded s) (hsβ‚‚ : MeasurableSet s) (hs₃ : volume (frontier s) = 0) : Tendsto (fun n : β„• ↦ (Nat.card ↑(s ∩ (n : ℝ)⁻¹ β€’ L) : ℝ) / n ^ card ΞΉ) atTop (𝓝 (volume.real s)) := by convert tendsto_tsum_div_pow_atTop_integral s (fun _ ↦ 1) continuous_const hs₁ hsβ‚‚ hs₃ Β· rw [tsum_const, nsmul_eq_mul, mul_one, Nat.cast_inj] Β· rw [setIntegral_const, smul_eq_mul, mul_one] private def tendsto_card_div_pow₁ {c : ℝ} (hc : c β‰  0) : ↑(s ∩ c⁻¹ β€’ L) ≃ ↑(c β€’ s ∩ L) := Equiv.subtypeEquiv (Equiv.smulRight hc) (fun x ↦ by simp_rw [Set.mem_inter_iff, Equiv.smulRight_apply, Set.smul_mem_smul_set_iffβ‚€ hc, ← Set.mem_inv_smul_set_iffβ‚€ hc]) private theorem tendsto_card_div_powβ‚‚ (hs₁ : IsBounded s) (hsβ‚„ : βˆ€ ⦃x y : ℝ⦄, 0 < x β†’ x ≀ y β†’ x β€’ s βŠ† y β€’ s) {x y : ℝ} (hx : 0 < x) (hy : x ≀ y) : Nat.card ↑(s ∩ x⁻¹ β€’ L) ≀ Nat.card ↑(s ∩ y⁻¹ β€’ L) := by rw [Nat.card_congr (tendsto_card_div_pow₁ s hx.ne'), Nat.card_congr (tendsto_card_div_pow₁ s (hx.trans_le hy).ne')] refine Nat.card_mono ?_ ?_ Β· exact ZSpan.setFinite_inter _ (IsBounded.smulβ‚€ hs₁ y) Β· exact Set.inter_subset_inter_left _ <| hsβ‚„ hx hy private theorem tendsto_card_div_pow₃ (hs₁ : IsBounded s) (hsβ‚„ : βˆ€ ⦃x y : ℝ⦄, 0 < x β†’ x ≀ y β†’ x β€’ s βŠ† y β€’ s) : βˆ€αΆ  x : ℝ in atTop, (Nat.card ↑(s ∩ (⌊xβŒ‹β‚Š : ℝ)⁻¹ β€’ L) : ℝ) / x ^ card ΞΉ ≀ (Nat.card ↑(s ∩ x⁻¹ β€’ L) : ℝ) / x ^ card ΞΉ := by filter_upwards [eventually_ge_atTop 1] with x hx gcongr exact tendsto_card_div_powβ‚‚ s hs₁ hsβ‚„ (Nat.cast_pos.mpr (Nat.floor_pos.mpr hx)) (Nat.floor_le (zero_le_one.trans hx)) private theorem tendsto_card_div_powβ‚„ (hs₁ : IsBounded s) (hsβ‚„ : βˆ€ ⦃x y : ℝ⦄, 0 < x β†’ x ≀ y β†’ x β€’ s βŠ† y β€’ s) : βˆ€αΆ  x : ℝ in atTop, (Nat.card ↑(s ∩ x⁻¹ β€’ L) : ℝ) / x ^ card ΞΉ ≀ (Nat.card ↑(s ∩ (⌈xβŒ‰β‚Š : ℝ)⁻¹ β€’ L) : ℝ) / x ^ card ΞΉ := by filter_upwards [eventually_gt_atTop 0] with x hx gcongr exact tendsto_card_div_powβ‚‚ s hs₁ hsβ‚„ hx (Nat.le_ceil _) private theorem tendsto_card_div_powβ‚… : (fun x ↦ (Nat.card ↑(s ∩ (⌊xβŒ‹β‚Š : ℝ)⁻¹ β€’ L) : ℝ) / ⌊xβŒ‹β‚Š ^ card ΞΉ * (⌊xβŒ‹β‚Š / x) ^ card ΞΉ) =αΆ [atTop] (fun x ↦ (Nat.card ↑(s ∩ (⌊xβŒ‹β‚Š : ℝ)⁻¹ β€’ L) : ℝ) / x ^ card ΞΉ) := by filter_upwards [eventually_ge_atTop 1] with x hx have : 0 < ⌊xβŒ‹β‚Š := Nat.floor_pos.mpr hx rw [div_pow, mul_div, div_mul_cancelβ‚€ _ (by positivity)] private theorem tendsto_card_div_pow₆ : (fun x ↦ (Nat.card ↑(s ∩ (⌈xβŒ‰β‚Š : ℝ)⁻¹ β€’ L) : ℝ) / ⌈xβŒ‰β‚Š ^ card ΞΉ * (⌈xβŒ‰β‚Š / x) ^ card ΞΉ) =αΆ [atTop] (fun x ↦ (Nat.card ↑(s ∩ (⌈xβŒ‰β‚Š : ℝ)⁻¹ β€’ L) : ℝ) / x ^ card ΞΉ) := by filter_upwards [eventually_ge_atTop 1] with x hx rw [div_pow, mul_div, div_mul_cancelβ‚€ _ (by positivity)] /-- A version of `tendsto_card_div_pow_atTop_volume` for a real variable. -/ theorem _root_.tendsto_card_div_pow_atTop_volume' (hs₁ : IsBounded s) (hsβ‚‚ : MeasurableSet s) (hs₃ : volume (frontier s) = 0) (hsβ‚„ : βˆ€ ⦃x y : ℝ⦄, 0 < x β†’ x ≀ y β†’ x β€’ s βŠ† y β€’ s) : Tendsto (fun x : ℝ ↦ (Nat.card ↑(s ∩ x⁻¹ β€’ L) : ℝ) / x ^ card ΞΉ) atTop (𝓝 (volume.real s)) := by rw [show volume.real s = volume.real s * 1 ^ card ΞΉ by ring] refine tendsto_of_tendsto_of_tendsto_of_le_of_le' ?_ ?_ (tendsto_card_div_pow₃ s hs₁ hsβ‚„) (tendsto_card_div_powβ‚„ s hs₁ hsβ‚„) Β· refine Tendsto.congr' (tendsto_card_div_powβ‚… s) (Tendsto.mul ?_ (Tendsto.pow ?_ _)) Β· exact Tendsto.comp (tendsto_card_div_pow_atTop_volume s hs₁ hsβ‚‚ hs₃) tendsto_nat_floor_atTop Β· exact tendsto_nat_floor_div_atTop Β· refine Tendsto.congr' (tendsto_card_div_pow₆ s) (Tendsto.mul ?_ (Tendsto.pow ?_ _)) Β· exact Tendsto.comp (tendsto_card_div_pow_atTop_volume s hs₁ hsβ‚‚ hs₃) tendsto_nat_ceil_atTop Β· exact tendsto_nat_ceil_div_atTop end BoxIntegral.unitPartition
.lake/packages/mathlib/Mathlib/Analysis/BoxIntegral/Basic.lean
import Mathlib.Analysis.BoxIntegral.Partition.Filter import Mathlib.Analysis.BoxIntegral.Partition.Measure import Mathlib.Analysis.Oscillation import Mathlib.Data.Bool.Basic import Mathlib.MeasureTheory.Measure.Real import Mathlib.Topology.UniformSpace.Compact /-! # Integrals of Riemann, Henstock-Kurzweil, and McShane In this file we define the integral of a function over a box in `ℝⁿ`. The same definition works for Riemann, Henstock-Kurzweil, and McShane integrals. As usual, we represent `ℝⁿ` as the type of functions `ΞΉ β†’ ℝ` for some finite type `ΞΉ`. A rectangular box `(l, u]` in `ℝⁿ` is defined to be the set `{x : ΞΉ β†’ ℝ | βˆ€ i, l i < x i ∧ x i ≀ u i}`, see `BoxIntegral.Box`. Let `vol` be a box-additive function on boxes in `ℝⁿ` with codomain `E β†’L[ℝ] F`. Given a function `f : ℝⁿ β†’ E`, a box `I` and a tagged partition `Ο€` of this box, the *integral sum* of `f` over `Ο€` with respect to the volume `vol` is the sum of `vol J (f (Ο€.tag J))` over all boxes of `Ο€`. Here `Ο€.tag J` is the point (tag) in `ℝⁿ` associated with the box `J`. The integral is defined as the limit of integral sums along a filter. Different filters correspond to different integration theories. In order to avoid code duplication, all our definitions and theorems take an argument `l : BoxIntegral.IntegrationParams`. This is a type that holds three Boolean values, and encodes eight filters including those corresponding to Riemann, Henstock-Kurzweil, and McShane integrals. Following the design of infinite sums (see `hasSum` and `tsum`), we define a predicate `BoxIntegral.HasIntegral` and a function `BoxIntegral.integral` that returns a vector satisfying the predicate or zero if the function is not integrable. Then we prove some basic properties of box integrals (linearity, a formula for the integral of a constant). We also prove a version of the Henstock-Sacks inequality (see `BoxIntegral.Integrable.dist_integralSum_le_of_memBaseSet` and `BoxIntegral.Integrable.dist_integralSum_sum_integral_le_of_memBaseSet_of_iUnion_eq`), prove integrability of continuous functions, and provide a criterion for integrability w.r.t. a non-Riemann filter (e.g., Henstock-Kurzweil and McShane). ## Notation - `ℝⁿ`: local notation for `ΞΉ β†’ ℝ` ## Tags integral -/ open scoped Topology NNReal Filter Uniformity BoxIntegral open Set Finset Function Filter Metric BoxIntegral.IntegrationParams noncomputable section namespace BoxIntegral universe u v w variable {ΞΉ : Type u} {E : Type v} {F : Type w} [NormedAddCommGroup E] [NormedSpace ℝ E] [NormedAddCommGroup F] [NormedSpace ℝ F] {I J : Box ΞΉ} {Ο€ : TaggedPrepartition I} open TaggedPrepartition local notation "ℝⁿ" => ΞΉ β†’ ℝ /-! ### Integral sum and its basic properties -/ /-- The integral sum of `f : ℝⁿ β†’ E` over a tagged prepartition `Ο€` w.r.t. box-additive volume `vol` with codomain `E β†’L[ℝ] F` is the sum of `vol J (f (Ο€.tag J))` over all boxes of `Ο€`. -/ def integralSum (f : ℝⁿ β†’ E) (vol : ΞΉ →ᡇᡃ E β†’L[ℝ] F) (Ο€ : TaggedPrepartition I) : F := βˆ‘ J ∈ Ο€.boxes, vol J (f (Ο€.tag J)) theorem integralSum_biUnionTagged (f : ℝⁿ β†’ E) (vol : ΞΉ →ᡇᡃ E β†’L[ℝ] F) (Ο€ : Prepartition I) (Ο€i : βˆ€ J, TaggedPrepartition J) : integralSum f vol (Ο€.biUnionTagged Ο€i) = βˆ‘ J ∈ Ο€.boxes, integralSum f vol (Ο€i J) := by refine (Ο€.sum_biUnion_boxes _ _).trans <| sum_congr rfl fun J hJ => sum_congr rfl fun J' hJ' => ?_ rw [Ο€.tag_biUnionTagged hJ hJ'] theorem integralSum_biUnion_partition (f : ℝⁿ β†’ E) (vol : ΞΉ →ᡇᡃ E β†’L[ℝ] F) (Ο€ : TaggedPrepartition I) (Ο€i : βˆ€ J, Prepartition J) (hΟ€i : βˆ€ J ∈ Ο€, (Ο€i J).IsPartition) : integralSum f vol (Ο€.biUnionPrepartition Ο€i) = integralSum f vol Ο€ := by refine (Ο€.sum_biUnion_boxes _ _).trans (sum_congr rfl fun J hJ => ?_) calc (βˆ‘ J' ∈ (Ο€i J).boxes, vol J' (f (Ο€.tag <| Ο€.toPrepartition.biUnionIndex Ο€i J'))) = βˆ‘ J' ∈ (Ο€i J).boxes, vol J' (f (Ο€.tag J)) := sum_congr rfl fun J' hJ' => by rw [Prepartition.biUnionIndex_of_mem _ hJ hJ'] _ = vol J (f (Ο€.tag J)) := (vol.map ⟨⟨fun g : E β†’L[ℝ] F => g (f (Ο€.tag J)), rfl⟩, fun _ _ => rfl⟩).sum_partition_boxes le_top (hΟ€i J hJ) theorem integralSum_inf_partition (f : ℝⁿ β†’ E) (vol : ΞΉ →ᡇᡃ E β†’L[ℝ] F) (Ο€ : TaggedPrepartition I) {Ο€' : Prepartition I} (h : Ο€'.IsPartition) : integralSum f vol (Ο€.infPrepartition Ο€') = integralSum f vol Ο€ := integralSum_biUnion_partition f vol Ο€ _ fun _J hJ => h.restrict (Prepartition.le_of_mem _ hJ) open Classical in theorem integralSum_fiberwise {Ξ±} (g : Box ΞΉ β†’ Ξ±) (f : ℝⁿ β†’ E) (vol : ΞΉ →ᡇᡃ E β†’L[ℝ] F) (Ο€ : TaggedPrepartition I) : (βˆ‘ y ∈ Ο€.boxes.image g, integralSum f vol (Ο€.filter (g Β· = y))) = integralSum f vol Ο€ := Ο€.sum_fiberwise g fun J => vol J (f <| Ο€.tag J) theorem integralSum_sub_partitions (f : ℝⁿ β†’ E) (vol : ΞΉ →ᡇᡃ E β†’L[ℝ] F) {π₁ Ο€β‚‚ : TaggedPrepartition I} (h₁ : π₁.IsPartition) (hβ‚‚ : Ο€β‚‚.IsPartition) : integralSum f vol π₁ - integralSum f vol Ο€β‚‚ = βˆ‘ J ∈ (π₁.toPrepartition βŠ“ Ο€β‚‚.toPrepartition).boxes, (vol J (f <| (π₁.infPrepartition Ο€β‚‚.toPrepartition).tag J) - vol J (f <| (Ο€β‚‚.infPrepartition π₁.toPrepartition).tag J)) := by rw [← integralSum_inf_partition f vol π₁ hβ‚‚, ← integralSum_inf_partition f vol Ο€β‚‚ h₁, integralSum, integralSum, Finset.sum_sub_distrib] simp only [infPrepartition_toPrepartition, inf_comm] @[simp] theorem integralSum_disjUnion (f : ℝⁿ β†’ E) (vol : ΞΉ →ᡇᡃ E β†’L[ℝ] F) {π₁ Ο€β‚‚ : TaggedPrepartition I} (h : Disjoint π₁.iUnion Ο€β‚‚.iUnion) : integralSum f vol (π₁.disjUnion Ο€β‚‚ h) = integralSum f vol π₁ + integralSum f vol Ο€β‚‚ := by refine (Prepartition.sum_disj_union_boxes h _).trans (congr_argβ‚‚ (Β· + Β·) (sum_congr rfl fun J hJ => ?_) (sum_congr rfl fun J hJ => ?_)) Β· rw [disjUnion_tag_of_mem_left _ hJ] Β· rw [disjUnion_tag_of_mem_right _ hJ] @[simp] theorem integralSum_add (f g : ℝⁿ β†’ E) (vol : ΞΉ →ᡇᡃ E β†’L[ℝ] F) (Ο€ : TaggedPrepartition I) : integralSum (f + g) vol Ο€ = integralSum f vol Ο€ + integralSum g vol Ο€ := by simp only [integralSum, Pi.add_apply, (vol _).map_add, Finset.sum_add_distrib] @[simp] theorem integralSum_neg (f : ℝⁿ β†’ E) (vol : ΞΉ →ᡇᡃ E β†’L[ℝ] F) (Ο€ : TaggedPrepartition I) : integralSum (-f) vol Ο€ = -integralSum f vol Ο€ := by simp only [integralSum, Pi.neg_apply, (vol _).map_neg, Finset.sum_neg_distrib] @[simp] theorem integralSum_smul (c : ℝ) (f : ℝⁿ β†’ E) (vol : ΞΉ →ᡇᡃ E β†’L[ℝ] F) (Ο€ : TaggedPrepartition I) : integralSum (c β€’ f) vol Ο€ = c β€’ integralSum f vol Ο€ := by simp only [integralSum, Finset.smul_sum, Pi.smul_apply, ContinuousLinearMap.map_smul] variable [Fintype ΞΉ] /-! ### Basic integrability theory -/ /-- The predicate `HasIntegral I l f vol y` says that `y` is the integral of `f` over `I` along `l` w.r.t. volume `vol`. This means that integral sums of `f` tend to `𝓝 y` along `BoxIntegral.IntegrationParams.toFilteriUnion I ⊀`. -/ def HasIntegral (I : Box ΞΉ) (l : IntegrationParams) (f : ℝⁿ β†’ E) (vol : ΞΉ →ᡇᡃ E β†’L[ℝ] F) (y : F) : Prop := Tendsto (integralSum f vol) (l.toFilteriUnion I ⊀) (𝓝 y) /-- A function is integrable if there exists a vector that satisfies the `HasIntegral` predicate. -/ def Integrable (I : Box ΞΉ) (l : IntegrationParams) (f : ℝⁿ β†’ E) (vol : ΞΉ →ᡇᡃ E β†’L[ℝ] F) := βˆƒ y, HasIntegral I l f vol y open Classical in /-- The integral of a function `f` over a box `I` along a filter `l` w.r.t. a volume `vol`. Returns zero on non-integrable functions. -/ def integral (I : Box ΞΉ) (l : IntegrationParams) (f : ℝⁿ β†’ E) (vol : ΞΉ →ᡇᡃ E β†’L[ℝ] F) := if h : Integrable I l f vol then h.choose else 0 -- Porting note: using the above notation ℝⁿ here causes the theorem below to be silently ignored -- see https://leanprover.zulipchat.com/#narrow/stream/287929-mathlib4/topic/Lean.204.20doesn't.20add.20lemma.20to.20the.20environment/near/363764522 -- and https://github.com/leanprover/lean4/issues/2257 variable {l : IntegrationParams} {f g : (ΞΉ β†’ ℝ) β†’ E} {vol : ΞΉ →ᡇᡃ E β†’L[ℝ] F} {y y' : F} /-- Reinterpret `BoxIntegral.HasIntegral` as `Filter.Tendsto`, e.g., dot-notation theorems that are shadowed in the `BoxIntegral.HasIntegral` namespace. -/ theorem HasIntegral.tendsto (h : HasIntegral I l f vol y) : Tendsto (integralSum f vol) (l.toFilteriUnion I ⊀) (𝓝 y) := h /-- The `Ξ΅`-`Ξ΄` definition of `BoxIntegral.HasIntegral`. -/ theorem hasIntegral_iff : HasIntegral I l f vol y ↔ βˆ€ Ξ΅ > (0 : ℝ), βˆƒ r : ℝβ‰₯0 β†’ ℝⁿ β†’ Ioi (0 : ℝ), (βˆ€ c, l.RCond (r c)) ∧ βˆ€ c Ο€, l.MemBaseSet I c (r c) Ο€ β†’ IsPartition Ο€ β†’ dist (integralSum f vol Ο€) y ≀ Ξ΅ := ((l.hasBasis_toFilteriUnion_top I).tendsto_iff nhds_basis_closedBall).trans <| by simp [@forall_swap ℝβ‰₯0 (TaggedPrepartition I)] /-- Quite often it is more natural to prove an estimate of the form `a * Ξ΅`, not `Ξ΅` in the RHS of `BoxIntegral.hasIntegral_iff`, so we provide this auxiliary lemma. -/ theorem HasIntegral.of_mul (a : ℝ) (h : βˆ€ Ξ΅ : ℝ, 0 < Ξ΅ β†’ βˆƒ r : ℝβ‰₯0 β†’ ℝⁿ β†’ Ioi (0 : ℝ), (βˆ€ c, l.RCond (r c)) ∧ βˆ€ c Ο€, l.MemBaseSet I c (r c) Ο€ β†’ IsPartition Ο€ β†’ dist (integralSum f vol Ο€) y ≀ a * Ξ΅) : HasIntegral I l f vol y := by refine hasIntegral_iff.2 fun Ξ΅ hΞ΅ => ?_ rcases exists_pos_mul_lt hΞ΅ a with ⟨Ρ', hΞ΅', ha⟩ rcases h Ξ΅' hΞ΅' with ⟨r, hr, H⟩ exact ⟨r, hr, fun c Ο€ hΟ€ hΟ€p => (H c Ο€ hΟ€ hΟ€p).trans ha.le⟩ theorem integrable_iff_cauchy [CompleteSpace F] : Integrable I l f vol ↔ Cauchy ((l.toFilteriUnion I ⊀).map (integralSum f vol)) := cauchy_map_iff_exists_tendsto.symm /-- In a complete space, a function is integrable if and only if its integral sums form a Cauchy net. Here we restate this fact in terms of `βˆ€ Ξ΅ > 0, βˆƒ r, ...`. -/ theorem integrable_iff_cauchy_basis [CompleteSpace F] : Integrable I l f vol ↔ βˆ€ Ξ΅ > (0 : ℝ), βˆƒ r : ℝβ‰₯0 β†’ ℝⁿ β†’ Ioi (0 : ℝ), (βˆ€ c, l.RCond (r c)) ∧ βˆ€ c₁ cβ‚‚ π₁ Ο€β‚‚, l.MemBaseSet I c₁ (r c₁) π₁ β†’ π₁.IsPartition β†’ l.MemBaseSet I cβ‚‚ (r cβ‚‚) Ο€β‚‚ β†’ Ο€β‚‚.IsPartition β†’ dist (integralSum f vol π₁) (integralSum f vol Ο€β‚‚) ≀ Ξ΅ := by rw [integrable_iff_cauchy, cauchy_map_iff', (l.hasBasis_toFilteriUnion_top _).prod_self.tendsto_iff uniformity_basis_dist_le] refine forallβ‚‚_congr fun Ξ΅ _ => exists_congr fun r => ?_ simp only [Prod.forall, exists_imp, prodMk_mem_set_prod_eq, and_imp, mem_setOf_eq] exact and_congr Iff.rfl ⟨fun H c₁ cβ‚‚ π₁ Ο€β‚‚ h₁ hU₁ hβ‚‚ hUβ‚‚ => H π₁ Ο€β‚‚ c₁ h₁ hU₁ cβ‚‚ hβ‚‚ hUβ‚‚, fun H π₁ Ο€β‚‚ c₁ h₁ hU₁ cβ‚‚ hβ‚‚ hUβ‚‚ => H c₁ cβ‚‚ π₁ Ο€β‚‚ h₁ hU₁ hβ‚‚ hUβ‚‚βŸ© theorem HasIntegral.mono {l₁ lβ‚‚ : IntegrationParams} (h : HasIntegral I l₁ f vol y) (hl : lβ‚‚ ≀ l₁) : HasIntegral I lβ‚‚ f vol y := h.mono_left <| IntegrationParams.toFilteriUnion_mono _ hl _ protected theorem Integrable.hasIntegral (h : Integrable I l f vol) : HasIntegral I l f vol (integral I l f vol) := by rw [integral, dif_pos h] exact Classical.choose_spec h theorem Integrable.mono {l'} (h : Integrable I l f vol) (hle : l' ≀ l) : Integrable I l' f vol := ⟨_, h.hasIntegral.mono hle⟩ theorem HasIntegral.unique (h : HasIntegral I l f vol y) (h' : HasIntegral I l f vol y') : y = y' := tendsto_nhds_unique h h' theorem HasIntegral.integrable (h : HasIntegral I l f vol y) : Integrable I l f vol := ⟨_, h⟩ theorem HasIntegral.integral_eq (h : HasIntegral I l f vol y) : integral I l f vol = y := h.integrable.hasIntegral.unique h nonrec theorem HasIntegral.add (h : HasIntegral I l f vol y) (h' : HasIntegral I l g vol y') : HasIntegral I l (f + g) vol (y + y') := by simpa only [HasIntegral, ← integralSum_add] using h.add h' theorem Integrable.add (hf : Integrable I l f vol) (hg : Integrable I l g vol) : Integrable I l (f + g) vol := (hf.hasIntegral.add hg.hasIntegral).integrable theorem integral_add (hf : Integrable I l f vol) (hg : Integrable I l g vol) : integral I l (f + g) vol = integral I l f vol + integral I l g vol := (hf.hasIntegral.add hg.hasIntegral).integral_eq nonrec theorem HasIntegral.neg (hf : HasIntegral I l f vol y) : HasIntegral I l (-f) vol (-y) := by simpa only [HasIntegral, ← integralSum_neg] using hf.neg theorem Integrable.neg (hf : Integrable I l f vol) : Integrable I l (-f) vol := hf.hasIntegral.neg.integrable theorem Integrable.of_neg (hf : Integrable I l (-f) vol) : Integrable I l f vol := neg_neg f β–Έ hf.neg @[simp] theorem integrable_neg : Integrable I l (-f) vol ↔ Integrable I l f vol := ⟨fun h => h.of_neg, fun h => h.neg⟩ @[simp] theorem integral_neg : integral I l (-f) vol = -integral I l f vol := by classical exact if h : Integrable I l f vol then h.hasIntegral.neg.integral_eq else by rw [integral, integral, dif_neg h, dif_neg (mt Integrable.of_neg h), neg_zero] theorem HasIntegral.sub (h : HasIntegral I l f vol y) (h' : HasIntegral I l g vol y') : HasIntegral I l (f - g) vol (y - y') := by simpa only [sub_eq_add_neg] using h.add h'.neg theorem Integrable.sub (hf : Integrable I l f vol) (hg : Integrable I l g vol) : Integrable I l (f - g) vol := (hf.hasIntegral.sub hg.hasIntegral).integrable theorem integral_sub (hf : Integrable I l f vol) (hg : Integrable I l g vol) : integral I l (f - g) vol = integral I l f vol - integral I l g vol := (hf.hasIntegral.sub hg.hasIntegral).integral_eq theorem hasIntegral_const (c : E) : HasIntegral I l (fun _ => c) vol (vol I c) := tendsto_const_nhds.congr' <| (l.eventually_isPartition I).mono fun _Ο€ hΟ€ => Eq.symm <| (vol.map ⟨⟨fun g : E β†’L[ℝ] F ↦ g c, rfl⟩, fun _ _ ↦ rfl⟩).sum_partition_boxes le_top hΟ€ @[simp] theorem integral_const (c : E) : integral I l (fun _ => c) vol = vol I c := (hasIntegral_const c).integral_eq theorem integrable_const (c : E) : Integrable I l (fun _ => c) vol := ⟨_, hasIntegral_const c⟩ theorem hasIntegral_zero : HasIntegral I l (fun _ => (0 : E)) vol 0 := by simpa only [← (vol I).map_zero] using hasIntegral_const (0 : E) theorem integrable_zero : Integrable I l (fun _ => (0 : E)) vol := ⟨0, hasIntegral_zero⟩ theorem integral_zero : integral I l (fun _ => (0 : E)) vol = 0 := hasIntegral_zero.integral_eq theorem HasIntegral.sum {Ξ± : Type*} {s : Finset Ξ±} {f : Ξ± β†’ ℝⁿ β†’ E} {g : Ξ± β†’ F} (h : βˆ€ i ∈ s, HasIntegral I l (f i) vol (g i)) : HasIntegral I l (fun x => βˆ‘ i ∈ s, f i x) vol (βˆ‘ i ∈ s, g i) := by classical induction s using Finset.induction_on with | empty => simp [hasIntegral_zero] | insert a s ha ihs => simp only [Finset.sum_insert ha]; rw [Finset.forall_mem_insert] at h exact h.1.add (ihs h.2) theorem HasIntegral.smul (hf : HasIntegral I l f vol y) (c : ℝ) : HasIntegral I l (c β€’ f) vol (c β€’ y) := by simpa only [HasIntegral, ← integralSum_smul] using (tendsto_const_nhds : Tendsto _ _ (𝓝 c)).smul hf theorem Integrable.smul (hf : Integrable I l f vol) (c : ℝ) : Integrable I l (c β€’ f) vol := (hf.hasIntegral.smul c).integrable theorem Integrable.of_smul {c : ℝ} (hf : Integrable I l (c β€’ f) vol) (hc : c β‰  0) : Integrable I l f vol := by simpa [inv_smul_smulβ‚€ hc] using hf.smul c⁻¹ @[simp] theorem integral_smul (c : ℝ) : integral I l (fun x => c β€’ f x) vol = c β€’ integral I l f vol := by rcases eq_or_ne c 0 with (rfl | hc); Β· simp only [zero_smul, integral_zero] by_cases hf : Integrable I l f vol Β· exact (hf.hasIntegral.smul c).integral_eq Β· have : Β¬Integrable I l (fun x => c β€’ f x) vol := mt (fun h => h.of_smul hc) hf rw [integral, integral, dif_neg hf, dif_neg this, smul_zero] open MeasureTheory /-- The integral of a nonnegative function w.r.t. a volume generated by a locally-finite measure is nonnegative. -/ theorem integral_nonneg {g : ℝⁿ β†’ ℝ} (hg : βˆ€ x ∈ Box.Icc I, 0 ≀ g x) (ΞΌ : Measure ℝⁿ) [IsLocallyFiniteMeasure ΞΌ] : 0 ≀ integral I l g ΞΌ.toBoxAdditive.toSMul := by by_cases hgi : Integrable I l g ΞΌ.toBoxAdditive.toSMul Β· refine ge_of_tendsto' hgi.hasIntegral fun Ο€ => sum_nonneg fun J _ => ?_ exact mul_nonneg ENNReal.toReal_nonneg (hg _ <| Ο€.tag_mem_Icc _) Β· rw [integral, dif_neg hgi] /-- If `β€–f xβ€– ≀ g x` on `[l, u]` and `g` is integrable, then the norm of the integral of `f` is less than or equal to the integral of `g`. -/ theorem norm_integral_le_of_norm_le {g : ℝⁿ β†’ ℝ} (hle : βˆ€ x ∈ Box.Icc I, β€–f xβ€– ≀ g x) (ΞΌ : Measure ℝⁿ) [IsLocallyFiniteMeasure ΞΌ] (hg : Integrable I l g ΞΌ.toBoxAdditive.toSMul) : β€–(integral I l f ΞΌ.toBoxAdditive.toSMul : E)β€– ≀ integral I l g ΞΌ.toBoxAdditive.toSMul := by by_cases hfi : Integrable.{u, v, v} I l f ΞΌ.toBoxAdditive.toSMul Β· refine le_of_tendsto_of_tendsto' hfi.hasIntegral.norm hg.hasIntegral fun Ο€ => ?_ refine norm_sum_le_of_le _ fun J _ => ?_ simp only [BoxAdditiveMap.toSMul_apply, norm_smul, smul_eq_mul, Real.norm_eq_abs, ΞΌ.toBoxAdditive_apply, abs_of_nonneg measureReal_nonneg] gcongr exact hle _ <| Ο€.tag_mem_Icc _ Β· rw [integral, dif_neg hfi, norm_zero] exact integral_nonneg (fun x hx => (norm_nonneg _).trans (hle x hx)) ΞΌ theorem norm_integral_le_of_le_const {c : ℝ} (hc : βˆ€ x ∈ Box.Icc I, β€–f xβ€– ≀ c) (ΞΌ : Measure ℝⁿ) [IsLocallyFiniteMeasure ΞΌ] : β€–(integral I l f ΞΌ.toBoxAdditive.toSMul : E)β€– ≀ ΞΌ.real I * c := by simpa only [integral_const] using norm_integral_le_of_norm_le hc ΞΌ (integrable_const c) /-! ### Henstock-Sacks inequality and integrability on subboxes Henstock-Sacks inequality for Henstock-Kurzweil integral says the following. Let `f` be a function integrable on a box `I`; let `r : ℝⁿ β†’ (0, ∞)` be a function such that for any tagged partition of `I` subordinate to `r`, the integral sum over this partition is `Ξ΅`-close to the integral. Then for any tagged prepartition (i.e. a finite collections of pairwise disjoint subboxes of `I` with tagged points) `Ο€`, the integral sum over `Ο€` differs from the integral of `f` over the part of `I` covered by `Ο€` by at most `Ξ΅`. The actual statement in the library is a bit more complicated to make it work for any `BoxIntegral.IntegrationParams`. We formalize several versions of this inequality in `BoxIntegral.Integrable.dist_integralSum_le_of_memBaseSet`, `BoxIntegral.Integrable.dist_integralSum_sum_integral_le_of_memBaseSet_of_iUnion_eq`, and `BoxIntegral.Integrable.dist_integralSum_sum_integral_le_of_memBaseSet`. Instead of using predicate assumptions on `r`, we define `BoxIntegral.Integrable.convergenceR (h : integrable I l f vol) (Ξ΅ : ℝ) (c : ℝβ‰₯0) : ℝⁿ β†’ (0, ∞)` to be a function `r` such that - if `l.bRiemann`, then `r` is a constant; - if `Ξ΅ > 0`, then for any tagged partition `Ο€` of `I` subordinate to `r` (more precisely, satisfying the predicate `l.mem_base_set I c r`), the integral sum of `f` over `Ο€` differs from the integral of `f` over `I` by at most `Ξ΅`. The proof is mostly based on [Russel A. Gordon, *The integrals of Lebesgue, Denjoy, Perron, and Henstock*][Gordon55]. -/ namespace Integrable /-- If `Ξ΅ > 0`, then `BoxIntegral.Integrable.convergenceR` is a function `r : ℝβ‰₯0 β†’ ℝⁿ β†’ (0, ∞)` such that for every `c : ℝβ‰₯0`, for every tagged partition `Ο€` subordinate to `r` (and satisfying additional distortion estimates if `BoxIntegral.IntegrationParams.bDistortion l = true`), the corresponding integral sum is `Ξ΅`-close to the integral. If `BoxIntegral.IntegrationParams.bRiemann = true`, then `r c x` does not depend on `x`. If `Ξ΅ ≀ 0`, then we use `r c x = 1`. -/ def convergenceR (h : Integrable I l f vol) (Ξ΅ : ℝ) : ℝβ‰₯0 β†’ ℝⁿ β†’ Ioi (0 : ℝ) := if hΞ΅ : 0 < Ξ΅ then (hasIntegral_iff.1 h.hasIntegral Ξ΅ hΞ΅).choose else fun _ _ => ⟨1, Set.mem_Ioi.2 zero_lt_one⟩ variable {c c₁ cβ‚‚ : ℝβ‰₯0} {Ξ΅ Ρ₁ Ξ΅β‚‚ : ℝ} {π₁ Ο€β‚‚ : TaggedPrepartition I} theorem convergenceR_cond (h : Integrable I l f vol) (Ξ΅ : ℝ) (c : ℝβ‰₯0) : l.RCond (h.convergenceR Ξ΅ c) := by rw [convergenceR]; split_ifs with hβ‚€ exacts [(hasIntegral_iff.1 h.hasIntegral Ξ΅ hβ‚€).choose_spec.1 _, fun _ x => rfl] theorem dist_integralSum_integral_le_of_memBaseSet (h : Integrable I l f vol) (hβ‚€ : 0 < Ξ΅) (hΟ€ : l.MemBaseSet I c (h.convergenceR Ξ΅ c) Ο€) (hΟ€p : Ο€.IsPartition) : dist (integralSum f vol Ο€) (integral I l f vol) ≀ Ξ΅ := by rw [convergenceR, dif_pos hβ‚€] at hΟ€ exact (hasIntegral_iff.1 h.hasIntegral Ξ΅ hβ‚€).choose_spec.2 c _ hΟ€ hΟ€p /-- **Henstock-Sacks inequality**. Let `r₁ rβ‚‚ : ℝⁿ β†’ (0, ∞)` be a function such that for any tagged *partition* of `I` subordinate to `rβ‚–`, `k=1,2`, the integral sum of `f` over this partition differs from the integral of `f` by at most `Ξ΅β‚–`. Then for any two tagged *prepartition* `π₁ Ο€β‚‚` subordinate to `r₁` and `rβ‚‚` respectively and covering the same part of `I`, the integral sums of `f` over these prepartitions differ from each other by at most `Ρ₁ + Ξ΅β‚‚`. The actual statement - uses `BoxIntegral.Integrable.convergenceR` instead of a predicate assumption on `r`; - uses `BoxIntegral.IntegrationParams.MemBaseSet` instead of β€œsubordinate to `r`” to account for additional requirements like being a Henstock partition or having a bounded distortion. See also `BoxIntegral.Integrable.dist_integralSum_sum_integral_le_of_memBaseSet_of_iUnion_eq` and `BoxIntegral.Integrable.dist_integralSum_sum_integral_le_of_memBaseSet`. -/ theorem dist_integralSum_le_of_memBaseSet (h : Integrable I l f vol) (hpos₁ : 0 < Ρ₁) (hposβ‚‚ : 0 < Ξ΅β‚‚) (h₁ : l.MemBaseSet I c₁ (h.convergenceR Ρ₁ c₁) π₁) (hβ‚‚ : l.MemBaseSet I cβ‚‚ (h.convergenceR Ξ΅β‚‚ cβ‚‚) Ο€β‚‚) (HU : π₁.iUnion = Ο€β‚‚.iUnion) : dist (integralSum f vol π₁) (integralSum f vol Ο€β‚‚) ≀ Ρ₁ + Ξ΅β‚‚ := by rcases h₁.exists_common_compl hβ‚‚ HU with βŸ¨Ο€, hΟ€U, hΟ€c₁, hΟ€cβ‚‚βŸ© set r : ℝⁿ β†’ Ioi (0 : ℝ) := fun x => min (h.convergenceR Ρ₁ c₁ x) (h.convergenceR Ξ΅β‚‚ cβ‚‚ x) set Ο€r := Ο€.toSubordinate r have H₁ : dist (integralSum f vol (π₁.unionComplToSubordinate Ο€ hΟ€U r)) (integral I l f vol) ≀ Ρ₁ := h.dist_integralSum_integral_le_of_memBaseSet hpos₁ (h₁.unionComplToSubordinate (fun _ _ => min_le_left _ _) hΟ€U hΟ€c₁) (isPartition_unionComplToSubordinate _ _ _ _) rw [HU] at hΟ€U have Hβ‚‚ : dist (integralSum f vol (Ο€β‚‚.unionComplToSubordinate Ο€ hΟ€U r)) (integral I l f vol) ≀ Ξ΅β‚‚ := h.dist_integralSum_integral_le_of_memBaseSet hposβ‚‚ (hβ‚‚.unionComplToSubordinate (fun _ _ => min_le_right _ _) hΟ€U hΟ€cβ‚‚) (isPartition_unionComplToSubordinate _ _ _ _) simpa [unionComplToSubordinate] using (dist_triangle_right _ _ _).trans (add_le_add H₁ Hβ‚‚) /-- If `f` is integrable on `I` along `l`, then for two sufficiently fine tagged prepartitions (in the sense of the filter `BoxIntegral.IntegrationParams.toFilter l I`) such that they cover the same part of `I`, the integral sums of `f` over `π₁` and `Ο€β‚‚` are very close to each other. -/ theorem tendsto_integralSum_toFilter_prod_self_inf_iUnion_eq_uniformity (h : Integrable I l f vol) : Tendsto (fun Ο€ : TaggedPrepartition I Γ— TaggedPrepartition I => (integralSum f vol Ο€.1, integralSum f vol Ο€.2)) ((l.toFilter I Γ—Λ’ l.toFilter I) βŠ“ π“Ÿ {Ο€ | Ο€.1.iUnion = Ο€.2.iUnion}) (𝓀 F) := by refine (((l.hasBasis_toFilter I).prod_self.inf_principal _).tendsto_iff uniformity_basis_dist_le).2 fun Ξ΅ Ξ΅0 => ?_ replace Ξ΅0 := half_pos Ξ΅0 use h.convergenceR (Ξ΅ / 2), h.convergenceR_cond (Ξ΅ / 2); rintro βŸ¨Ο€β‚, Ο€β‚‚βŸ© ⟨⟨h₁, hβ‚‚βŸ©, hU⟩ rw [← add_halves Ξ΅] exact h.dist_integralSum_le_of_memBaseSet Ξ΅0 Ξ΅0 h₁.choose_spec hβ‚‚.choose_spec hU /-- If `f` is integrable on a box `I` along `l`, then for any fixed subset `s` of `I` that can be represented as a finite union of boxes, the integral sums of `f` over tagged prepartitions that cover exactly `s` form a Cauchy β€œsequence” along `l`. -/ theorem cauchy_map_integralSum_toFilteriUnion (h : Integrable I l f vol) (Ο€β‚€ : Prepartition I) : Cauchy ((l.toFilteriUnion I Ο€β‚€).map (integralSum f vol)) := by refine ⟨inferInstance, ?_⟩ rw [prod_map_map_eq, ← toFilter_inf_iUnion_eq, ← prod_inf_prod, prod_principal_principal] exact h.tendsto_integralSum_toFilter_prod_self_inf_iUnion_eq_uniformity.mono_left (inf_le_inf_left _ <| principal_mono.2 fun Ο€ h => h.1.trans h.2.symm) variable [CompleteSpace F] theorem to_subbox_aux (h : Integrable I l f vol) (hJ : J ≀ I) : βˆƒ y : F, HasIntegral J l f vol y ∧ Tendsto (integralSum f vol) (l.toFilteriUnion I (Prepartition.single I J hJ)) (𝓝 y) := by refine (cauchy_map_iff_exists_tendsto.1 (h.cauchy_map_integralSum_toFilteriUnion (.single I J hJ))).imp fun y hy ↦ ⟨?_, hy⟩ convert hy.comp (l.tendsto_embedBox_toFilteriUnion_top hJ) -- faster than `exact` here /-- If `f` is integrable on a box `I`, then it is integrable on any subbox of `I`. -/ theorem to_subbox (h : Integrable I l f vol) (hJ : J ≀ I) : Integrable J l f vol := (h.to_subbox_aux hJ).imp fun _ => And.left /-- If `f` is integrable on a box `I`, then integral sums of `f` over tagged prepartitions that cover exactly a subbox `J ≀ I` tend to the integral of `f` over `J` along `l`. -/ theorem tendsto_integralSum_toFilteriUnion_single (h : Integrable I l f vol) (hJ : J ≀ I) : Tendsto (integralSum f vol) (l.toFilteriUnion I (Prepartition.single I J hJ)) (𝓝 <| integral J l f vol) := let ⟨_y, h₁, hβ‚‚βŸ© := h.to_subbox_aux hJ h₁.integral_eq.symm β–Έ hβ‚‚ /-- **Henstock-Sacks inequality**. Let `r : ℝⁿ β†’ (0, ∞)` be a function such that for any tagged *partition* of `I` subordinate to `r`, the integral sum of `f` over this partition differs from the integral of `f` by at most `Ξ΅`. Then for any tagged *prepartition* `Ο€` subordinate to `r`, the integral sum of `f` over this prepartition differs from the integral of `f` over the part of `I` covered by `Ο€` by at most `Ξ΅`. The actual statement - uses `BoxIntegral.Integrable.convergenceR` instead of a predicate assumption on `r`; - uses `BoxIntegral.IntegrationParams.MemBaseSet` instead of β€œsubordinate to `r`” to account for additional requirements like being a Henstock partition or having a bounded distortion; - takes an extra argument `Ο€β‚€ : prepartition I` and an assumption `Ο€.Union = Ο€β‚€.Union` instead of using `Ο€.to_prepartition`. -/ theorem dist_integralSum_sum_integral_le_of_memBaseSet_of_iUnion_eq (h : Integrable I l f vol) (h0 : 0 < Ξ΅) (hΟ€ : l.MemBaseSet I c (h.convergenceR Ξ΅ c) Ο€) {Ο€β‚€ : Prepartition I} (hU : Ο€.iUnion = Ο€β‚€.iUnion) : dist (integralSum f vol Ο€) (βˆ‘ J ∈ Ο€β‚€.boxes, integral J l f vol) ≀ Ξ΅ := by -- Let us prove that the distance is less than or equal to `Ξ΅ + Ξ΄` for all positive `Ξ΄`. refine le_of_forall_pos_le_add fun Ξ΄ Ξ΄0 => ?_ -- First we choose some constants. set Ξ΄' : ℝ := Ξ΄ / (#Ο€β‚€.boxes + 1) have H0 : 0 < (#Ο€β‚€.boxes + 1 : ℝ) := Nat.cast_add_one_pos _ have Ξ΄'0 : 0 < Ξ΄' := div_pos Ξ΄0 H0 set C := max Ο€β‚€.distortion Ο€β‚€.compl.distortion /- Next we choose a tagged partition of each `J ∈ Ο€β‚€` such that the integral sum of `f` over this partition is `Ξ΄'`-close to the integral of `f` over `J`. -/ have : βˆ€ J ∈ Ο€β‚€, βˆƒ Ο€i : TaggedPrepartition J, Ο€i.IsPartition ∧ dist (integralSum f vol Ο€i) (integral J l f vol) ≀ Ξ΄' ∧ l.MemBaseSet J C (h.convergenceR Ξ΄' C) Ο€i := by intro J hJ have Hle : J ≀ I := Ο€β‚€.le_of_mem hJ have HJi : Integrable J l f vol := h.to_subbox Hle set r := fun x => min (h.convergenceR Ξ΄' C x) (HJi.convergenceR Ξ΄' C x) have hJd : J.distortion ≀ C := le_trans (Finset.le_sup hJ) (le_max_left _ _) rcases l.exists_memBaseSet_isPartition J hJd r with βŸ¨Ο€J, hC, hp⟩ have hC₁ : l.MemBaseSet J C (HJi.convergenceR Ξ΄' C) Ο€J := by refine hC.mono J le_rfl le_rfl fun x _ => ?_; exact min_le_right _ _ have hCβ‚‚ : l.MemBaseSet J C (h.convergenceR Ξ΄' C) Ο€J := by refine hC.mono J le_rfl le_rfl fun x _ => ?_; exact min_le_left _ _ exact βŸ¨Ο€J, hp, HJi.dist_integralSum_integral_le_of_memBaseSet Ξ΄'0 hC₁ hp, hCβ‚‚βŸ© /- Now we combine these tagged partitions into a tagged prepartition of `I` that covers the same part of `I` as `Ο€β‚€` and apply `BoxIntegral.dist_integralSum_le_of_memBaseSet` to `Ο€` and this prepartition. -/ choose! Ο€i hΟ€ip hΟ€iΞ΄' hΟ€iC using this have : l.MemBaseSet I C (h.convergenceR Ξ΄' C) (Ο€β‚€.biUnionTagged Ο€i) := biUnionTagged_memBaseSet hΟ€iC hΟ€ip fun _ => le_max_right _ _ have hU' : Ο€.iUnion = (Ο€β‚€.biUnionTagged Ο€i).iUnion := hU.trans (Prepartition.iUnion_biUnion_partition _ hΟ€ip).symm have := h.dist_integralSum_le_of_memBaseSet h0 Ξ΄'0 hΟ€ this hU' rw [integralSum_biUnionTagged] at this calc dist (integralSum f vol Ο€) (βˆ‘ J ∈ Ο€β‚€.boxes, integral J l f vol) ≀ dist (integralSum f vol Ο€) (βˆ‘ J ∈ Ο€β‚€.boxes, integralSum f vol (Ο€i J)) + dist (βˆ‘ J ∈ Ο€β‚€.boxes, integralSum f vol (Ο€i J)) (βˆ‘ J ∈ Ο€β‚€.boxes, integral J l f vol) := dist_triangle _ _ _ _ ≀ Ξ΅ + Ξ΄' + βˆ‘ _J ∈ Ο€β‚€.boxes, Ξ΄' := add_le_add this (dist_sum_sum_le_of_le _ hΟ€iΞ΄') _ = Ξ΅ + Ξ΄ := by simp [field, Ξ΄']; ring /-- **Henstock-Sacks inequality**. Let `r : ℝⁿ β†’ (0, ∞)` be a function such that for any tagged *partition* of `I` subordinate to `r`, the integral sum of `f` over this partition differs from the integral of `f` by at most `Ξ΅`. Then for any tagged *prepartition* `Ο€` subordinate to `r`, the integral sum of `f` over this prepartition differs from the integral of `f` over the part of `I` covered by `Ο€` by at most `Ξ΅`. The actual statement - uses `BoxIntegral.Integrable.convergenceR` instead of a predicate assumption on `r`; - uses `BoxIntegral.IntegrationParams.MemBaseSet` instead of β€œsubordinate to `r`” to account for additional requirements like being a Henstock partition or having a bounded distortion; -/ theorem dist_integralSum_sum_integral_le_of_memBaseSet (h : Integrable I l f vol) (h0 : 0 < Ξ΅) (hΟ€ : l.MemBaseSet I c (h.convergenceR Ξ΅ c) Ο€) : dist (integralSum f vol Ο€) (βˆ‘ J ∈ Ο€.boxes, integral J l f vol) ≀ Ξ΅ := h.dist_integralSum_sum_integral_le_of_memBaseSet_of_iUnion_eq h0 hΟ€ rfl /-- Integral sum of `f` over a tagged prepartition `Ο€` such that `Ο€.Union = Ο€β‚€.Union` tends to the sum of integrals of `f` over the boxes of `Ο€β‚€`. -/ theorem tendsto_integralSum_sum_integral (h : Integrable I l f vol) (Ο€β‚€ : Prepartition I) : Tendsto (integralSum f vol) (l.toFilteriUnion I Ο€β‚€) (𝓝 <| βˆ‘ J ∈ Ο€β‚€.boxes, integral J l f vol) := by refine ((l.hasBasis_toFilteriUnion I Ο€β‚€).tendsto_iff nhds_basis_closedBall).2 fun Ξ΅ Ξ΅0 => ?_ refine ⟨h.convergenceR Ξ΅, h.convergenceR_cond Ξ΅, ?_⟩ simp only [mem_setOf_eq] rintro Ο€ ⟨c, hc, hU⟩ exact h.dist_integralSum_sum_integral_le_of_memBaseSet_of_iUnion_eq Ξ΅0 hc hU /-- If `f` is integrable on `I`, then `fun J ↦ integral J l f vol` is box-additive on subboxes of `I`: if `π₁`, `Ο€β‚‚` are two prepartitions of `I` covering the same part of `I`, the sum of integrals of `f` over the boxes of `π₁` is equal to the sum of integrals of `f` over the boxes of `Ο€β‚‚`. See also `BoxIntegral.Integrable.toBoxAdditive` for a bundled version. -/ theorem sum_integral_congr (h : Integrable I l f vol) {π₁ Ο€β‚‚ : Prepartition I} (hU : π₁.iUnion = Ο€β‚‚.iUnion) : βˆ‘ J ∈ π₁.boxes, integral J l f vol = βˆ‘ J ∈ Ο€β‚‚.boxes, integral J l f vol := by refine tendsto_nhds_unique (h.tendsto_integralSum_sum_integral π₁) ?_ rw [l.toFilteriUnion_congr _ hU] exact h.tendsto_integralSum_sum_integral Ο€β‚‚ /-- If `f` is integrable on `I`, then `fun J ↦ integral J l f vol` is box-additive on subboxes of `I`: if `π₁`, `Ο€β‚‚` are two prepartitions of `I` covering the same part of `I`, the sum of integrals of `f` over the boxes of `π₁` is equal to the sum of integrals of `f` over the boxes of `Ο€β‚‚`. See also `BoxIntegral.Integrable.sum_integral_congr` for an unbundled version. -/ @[simps] def toBoxAdditive (h : Integrable I l f vol) : ΞΉ →ᡇᡃ[I] F where toFun J := integral J l f vol sum_partition_boxes' J hJ Ο€ hΟ€ := by replace hΟ€ := hΟ€.iUnion_eq; rw [← Prepartition.iUnion_top] at hΟ€ rw [(h.to_subbox (WithTop.coe_le_coe.1 hJ)).sum_integral_congr hΟ€, Prepartition.top_boxes, sum_singleton] end Integrable open MeasureTheory /-! ### Integrability conditions -/ open Prepartition EMetric ENNReal BoxAdditiveMap Finset Metric TaggedPrepartition variable (l) /-- A function that is bounded and a.e. continuous on a box `I` is integrable on `I`. -/ theorem integrable_of_bounded_and_ae_continuousWithinAt [CompleteSpace E] {I : Box ΞΉ} {f : ℝⁿ β†’ E} (hb : βˆƒ C : ℝ, βˆ€ x ∈ Box.Icc I, β€–f xβ€– ≀ C) (ΞΌ : Measure ℝⁿ) [IsLocallyFiniteMeasure ΞΌ] (hc : βˆ€α΅ x βˆ‚(ΞΌ.restrict (Box.Icc I)), ContinuousWithinAt f (Box.Icc I) x) : Integrable I l f ΞΌ.toBoxAdditive.toSMul := by /- We prove that f is integrable by proving that we can ensure that the integrals over any two tagged prepartitions π₁ and Ο€β‚‚ can be made Ξ΅-close by making the partitions sufficiently fine. Start by defining some constants C, Ρ₁, Ξ΅β‚‚ that will be useful later. -/ refine integrable_iff_cauchy_basis.2 fun Ξ΅ Ξ΅0 ↦ ?_ rcases exists_pos_mul_lt Ξ΅0 (2 * ΞΌ.toBoxAdditive I) with βŸ¨Ξ΅β‚, Ρ₁0, hΞ΅β‚βŸ© rcases hb with ⟨C, hC⟩ have C0 : 0 ≀ C := by obtain ⟨x, hx⟩ := BoxIntegral.Box.nonempty_coe I exact le_trans (norm_nonneg (f x)) <| hC x (I.coe_subset_Icc hx) rcases exists_pos_mul_lt Ξ΅0 (4 * C) with βŸ¨Ξ΅β‚‚, Ξ΅β‚‚0, hΞ΅β‚‚βŸ© have Ξ΅β‚‚0' : ENNReal.ofReal Ξ΅β‚‚ β‰  0 := ne_of_gt <| ofReal_pos.2 Ξ΅β‚‚0 -- The set of discontinuities of f is contained in an open set U with ΞΌ U < Ξ΅β‚‚. let D := { x ∈ Box.Icc I | Β¬ ContinuousWithinAt f (Box.Icc I) x } let ΞΌ' := ΞΌ.restrict (Box.Icc I) have ΞΌ'D : ΞΌ' D = 0 := by rcases eventually_iff_exists_mem.1 hc with ⟨V, ae, hV⟩ exact eq_of_le_of_not_lt (mem_ae_iff.1 ae β–Έ (ΞΌ'.mono <| fun x h xV ↦ h.2 (hV x xV))) not_lt_zero obtain ⟨U, UD, Uopen, hU⟩ := Set.exists_isOpen_lt_add D (show ΞΌ' D β‰  ⊀ by simp [ΞΌ'D]) Ξ΅β‚‚0' rw [ΞΌ'D, zero_add] at hU /- Box.Icc I \ U is compact and avoids discontinuities of f, so there exists r > 0 such that for every x ∈ Box.Icc I \ U, the oscillation (within Box.Icc I) of f on the ball of radius r centered at x is ≀ Ρ₁ -/ have comp : IsCompact (Box.Icc I \ U) := I.isCompact_Icc.of_isClosed_subset (I.isCompact_Icc.isClosed.sdiff Uopen) Set.diff_subset have : βˆ€ x ∈ (Box.Icc I \ U), oscillationWithin f (Box.Icc I) x < (ENNReal.ofReal Ρ₁) := by intro x hx suffices oscillationWithin f (Box.Icc I) x = 0 by rw [this]; exact ofReal_pos.2 Ρ₁0 simpa [OscillationWithin.eq_zero_iff_continuousWithinAt, D, hx.1] using hx.2 ∘ (fun a ↦ UD a) rcases comp.uniform_oscillationWithin this with ⟨r, r0, hr⟩ /- We prove the claim for partitions π₁ and Ο€β‚‚ subordinate to r/2, by writing the difference as an integralSum over π₁ βŠ“ Ο€β‚‚ and considering separately the boxes of π₁ βŠ“ Ο€β‚‚ which are/aren't fully contained within U. -/ refine ⟨fun _ _ ↦ ⟨r / 2, half_pos r0⟩, fun _ _ _ ↦ rfl, fun c₁ cβ‚‚ π₁ Ο€β‚‚ h₁ h₁p hβ‚‚ hβ‚‚p ↦ ?_⟩ simp only [dist_eq_norm, integralSum_sub_partitions _ _ h₁p hβ‚‚p, toSMul_apply, ← smul_sub] have ΞΌI : ΞΌ I < ⊀ := lt_of_le_of_lt (ΞΌ.mono I.coe_subset_Icc) I.isCompact_Icc.measure_lt_top let t₁ (J : Box ΞΉ) : ℝⁿ := (π₁.infPrepartition Ο€β‚‚.toPrepartition).tag J let tβ‚‚ (J : Box ΞΉ) : ℝⁿ := (Ο€β‚‚.infPrepartition π₁.toPrepartition).tag J let B := (π₁.toPrepartition βŠ“ Ο€β‚‚.toPrepartition).boxes classical let B' := {J ∈ B | J.toSet βŠ† U} have hB' : B' βŠ† B := B.filter_subset (fun J ↦ J.toSet βŠ† U) have ΞΌJ_ne_top : βˆ€ J ∈ B, ΞΌ J β‰  ⊀ := fun J hJ ↦ lt_top_iff_ne_top.1 <| lt_of_le_of_lt (ΞΌ.mono (Prepartition.le_of_mem' _ J hJ)) ΞΌI have un : βˆ€ S βŠ† B, ⋃ J ∈ S, J.toSet βŠ† I.toSet := fun S hS ↦ iUnion_subset_iff.2 (fun J ↦ iUnion_subset_iff.2 fun hJ ↦ le_of_mem' _ J (hS hJ)) rw [← sum_sdiff hB', ← add_halves Ξ΅] apply le_trans (norm_add_le _ _) (add_le_add ?_ ?_) /- If a box J is not contained within U, then the oscillation of f on J is small, which bounds the contribution of J to the overall sum. -/ Β· have : βˆ€ J ∈ B \ B', β€–ΞΌ.toBoxAdditive J β€’ (f (t₁ J) - f (tβ‚‚ J))β€– ≀ ΞΌ.toBoxAdditive J * Ρ₁ := by intro J hJ rw [mem_sdiff, B.mem_filter, not_and] at hJ rw [norm_smul, ΞΌ.toBoxAdditive_apply, Real.norm_of_nonneg measureReal_nonneg] gcongr _ * ?_ obtain ⟨x, xJ, xnU⟩ : βˆƒ x ∈ J, x βˆ‰ U := Set.not_subset.1 (hJ.2 hJ.1) have hx : x ∈ Box.Icc I \ U := ⟨Box.coe_subset_Icc ((le_of_mem' _ J hJ.1) xJ), xnU⟩ have ineq : edist (f (t₁ J)) (f (tβ‚‚ J)) ≀ EMetric.diam (f '' (ball x r ∩ (Box.Icc I))) := by apply edist_le_diam_of_mem <;> refine Set.mem_image_of_mem f ⟨?_, tag_mem_Icc _ J⟩ <;> refine closedBall_subset_ball (div_two_lt_of_pos r0) <| mem_closedBall_comm.1 ?_ Β· exact h₁.isSubordinate.infPrepartition Ο€β‚‚.toPrepartition J hJ.1 (Box.coe_subset_Icc xJ) Β· exact hβ‚‚.isSubordinate.infPrepartition π₁.toPrepartition J ((π₁.mem_infPrepartition_comm).1 hJ.1) (Box.coe_subset_Icc xJ) rw [← emetric_ball] at ineq simpa only [edist_le_ofReal (le_of_lt Ρ₁0), dist_eq_norm, hJ.1] using ineq.trans (hr x hx) refine (norm_sum_le _ _).trans <| (sum_le_sum this).trans ?_ rw [← sum_mul] trans ΞΌ.toBoxAdditive I * Ρ₁; swap Β· linarith simp_rw [mul_le_mul_iff_leftβ‚€ Ρ₁0, ΞΌ.toBoxAdditive_apply] refine le_trans ?_ <| toReal_mono (lt_top_iff_ne_top.1 ΞΌI) <| ΞΌ.mono <| un (B \ B') sdiff_subset simp_rw [measureReal_def] rw [← toReal_sum (fun J hJ ↦ ΞΌJ_ne_top J (mem_sdiff.1 hJ).1), ← Finset.tsum_subtype] refine (toReal_mono <| ne_of_lt <| lt_of_le_of_lt (ΞΌ.mono <| un (B \ B') sdiff_subset) ΞΌI) ?_ refine le_of_eq (measure_biUnion (countable_toSet _) ?_ (fun J _ ↦ J.measurableSet_coe)).symm exact fun J hJ J' hJ' hJJ' ↦ pairwiseDisjoint _ (mem_sdiff.1 hJ).1 (mem_sdiff.1 hJ').1 hJJ' -- The contribution of the boxes contained within U is bounded because f is bounded and ΞΌ U < Ξ΅β‚‚. Β· have : βˆ€ J ∈ B', β€–ΞΌ.toBoxAdditive J β€’ (f (t₁ J) - f (tβ‚‚ J))β€– ≀ ΞΌ.toBoxAdditive J * (2 * C) := by intro J _ rw [norm_smul, ΞΌ.toBoxAdditive_apply, Real.norm_of_nonneg measureReal_nonneg, two_mul] gcongr apply norm_sub_le_of_le <;> exact hC _ (TaggedPrepartition.tag_mem_Icc _ J) apply (norm_sum_le_of_le B' this).trans simp_rw [← sum_mul, ΞΌ.toBoxAdditive_apply, measureReal_def, ← toReal_sum (fun J hJ ↦ ΞΌJ_ne_top J (hB' hJ))] suffices (βˆ‘ J ∈ B', ΞΌ J).toReal ≀ Ξ΅β‚‚ by linarith [mul_le_mul_of_nonneg_right this <| (mul_nonneg_iff_of_pos_left two_pos).2 C0] rw [← toReal_ofReal (le_of_lt Ξ΅β‚‚0)] refine toReal_mono ofReal_ne_top (le_trans ?_ (le_of_lt hU)) trans ΞΌ' (⋃ J ∈ B', J) Β· simp only [ΞΌ', ΞΌ.restrict_eq_self <| (un _ hB').trans I.coe_subset_Icc] exact le_of_eq <| Eq.symm <| measure_biUnion_finset (fun J hJ K hK hJK ↦ pairwiseDisjoint _ (hB' hJ) (hB' hK) hJK) fun J _ ↦ J.measurableSet_coe Β· apply ΞΌ'.mono simp_rw [iUnion_subset_iff] exact fun J hJ ↦ (mem_filter.1 hJ).2 /-- A function that is bounded on a box `I` and a.e. continuous is integrable on `I`. This is a version of `integrable_of_bounded_and_ae_continuousWithinAt` with a stronger continuity assumption so that the user does not need to specialize the continuity assumption to each box on which the theorem is to be applied. -/ theorem integrable_of_bounded_and_ae_continuous [CompleteSpace E] {I : Box ΞΉ} {f : ℝⁿ β†’ E} (hb : βˆƒ C : ℝ, βˆ€ x ∈ Box.Icc I, β€–f xβ€– ≀ C) (ΞΌ : Measure ℝⁿ) [IsLocallyFiniteMeasure ΞΌ] (hc : βˆ€α΅ x βˆ‚ΞΌ, ContinuousAt f x) : Integrable I l f ΞΌ.toBoxAdditive.toSMul := integrable_of_bounded_and_ae_continuousWithinAt l hb ΞΌ <| Eventually.filter_mono (ae_mono ΞΌ.restrict_le_self) (hc.mono fun _ h ↦ h.continuousWithinAt) /-- A continuous function is box-integrable with respect to any locally finite measure. This is true for any volume with bounded variation. -/ theorem integrable_of_continuousOn [CompleteSpace E] {I : Box ΞΉ} {f : ℝⁿ β†’ E} (hc : ContinuousOn f (Box.Icc I)) (ΞΌ : Measure ℝⁿ) [IsLocallyFiniteMeasure ΞΌ] : Integrable.{u, v, v} I l f ΞΌ.toBoxAdditive.toSMul := by apply integrable_of_bounded_and_ae_continuousWithinAt Β· obtain ⟨C, hC⟩ := (NormedSpace.isBounded_iff_subset_smul_closedBall ℝ).1 (I.isCompact_Icc.image_of_continuousOn hc).isBounded use β€–Cβ€–, fun x hx ↦ by simpa only [smul_unitClosedBall, mem_closedBall_zero_iff] using hC (Set.mem_image_of_mem f hx) Β· refine eventually_of_mem ?_ (fun x hx ↦ hc.continuousWithinAt hx) rw [mem_ae_iff, ΞΌ.restrict_apply] <;> simp [MeasurableSet.compl_iff.2 I.measurableSet_Icc] variable {l} /-- This is an auxiliary lemma used to prove two statements at once. Use one of the next two lemmas instead. -/ theorem HasIntegral.of_bRiemann_eq_false_of_forall_isLittleO (hl : l.bRiemann = false) (B : ΞΉ →ᡇᡃ[I] ℝ) (hB0 : βˆ€ J, 0 ≀ B J) (g : ΞΉ →ᡇᡃ[I] F) (s : Set ℝⁿ) (hs : s.Countable) (hlH : s.Nonempty β†’ l.bHenstock = true) (H₁ : βˆ€ (c : ℝβ‰₯0), βˆ€ x ∈ Box.Icc I ∩ s, βˆ€ Ξ΅ > (0 : ℝ), βˆƒ Ξ΄ > 0, βˆ€ J ≀ I, Box.Icc J βŠ† Metric.closedBall x Ξ΄ β†’ x ∈ Box.Icc J β†’ (l.bDistortion β†’ J.distortion ≀ c) β†’ dist (vol J (f x)) (g J) ≀ Ξ΅) (Hβ‚‚ : βˆ€ (c : ℝβ‰₯0), βˆ€ x ∈ Box.Icc I \ s, βˆ€ Ξ΅ > (0 : ℝ), βˆƒ Ξ΄ > 0, βˆ€ J ≀ I, Box.Icc J βŠ† Metric.closedBall x Ξ΄ β†’ (l.bHenstock β†’ x ∈ Box.Icc J) β†’ (l.bDistortion β†’ J.distortion ≀ c) β†’ dist (vol J (f x)) (g J) ≀ Ξ΅ * B J) : HasIntegral I l f vol (g I) := by /- We choose `r x` differently for `x ∈ s` and `x βˆ‰ s`. For `x ∈ s`, we choose `Ξ΅s` such that `βˆ‘' x : s, Ξ΅s x < Ξ΅ / 2 / 2 ^ #ΞΉ`, then choose `r x` so that `dist (vol J (f x)) (g J) ≀ Ξ΅s x` for `J` in the `r x`-neighborhood of `x`. This guarantees that the sum of these distances over boxes `J` such that `Ο€.tag J ∈ s` is less than `Ξ΅ / 2`. We need an additional multiplier `2 ^ #ΞΉ` because different boxes can have the same tag. For `x βˆ‰ s`, we choose `r x` so that `dist (vol (J (f x))) (g J) ≀ (Ξ΅ / 2 / B I) * B J` for a box `J` in the `Ξ΄`-neighborhood of `x`. -/ refine ((l.hasBasis_toFilteriUnion_top _).tendsto_iff Metric.nhds_basis_closedBall).2 ?_ intro Ξ΅ Ξ΅0 simp only [← exists_prop, gt_iff_lt, Subtype.exists'] at H₁ Hβ‚‚ choose! δ₁ Hδ₁ using H₁ choose! Ξ΄β‚‚ HΞ΄β‚‚ using Hβ‚‚ have Ξ΅0' := half_pos Ξ΅0; have H0 : 0 < (2 : ℝ) ^ Fintype.card ΞΉ := pow_pos zero_lt_two _ rcases hs.exists_pos_forall_sum_le (div_pos Ξ΅0' H0) with ⟨Ρs, hΞ΅s0, hΞ΅s⟩ simp only [le_div_iffβ‚€' H0, mul_sum] at hΞ΅s rcases exists_pos_mul_lt Ξ΅0' (B I) with ⟨Ρ', Ξ΅'0, hΞ΅I⟩ classical set Ξ΄ : ℝβ‰₯0 β†’ ℝⁿ β†’ Ioi (0 : ℝ) := fun c x => if x ∈ s then δ₁ c x (Ξ΅s x) else (Ξ΄β‚‚ c) x Ξ΅' refine ⟨δ, fun c => l.rCond_of_bRiemann_eq_false hl, ?_⟩ simp only [mem_setOf_eq] rintro Ο€ ⟨c, hπδ, hΟ€p⟩ -- Now we split the sum into two parts based on whether `Ο€.tag J` belongs to `s` or not. rw [← g.sum_partition_boxes le_rfl hΟ€p, Metric.mem_closedBall, integralSum, ← sum_filter_add_sum_filter_not Ο€.boxes fun J => Ο€.tag J ∈ s, ← sum_filter_add_sum_filter_not Ο€.boxes fun J => Ο€.tag J ∈ s, ← add_halves Ξ΅] refine dist_add_add_le_of_le ?_ ?_ Β· rcases s.eq_empty_or_nonempty with (rfl | hsne); Β· simp [Ξ΅0'.le] /- For the boxes such that `Ο€.tag J ∈ s`, we use the fact that at most `2 ^ #ΞΉ` boxes have the same tag. -/ specialize hlH hsne have : βˆ€ J ∈ {J ∈ Ο€.boxes | Ο€.tag J ∈ s}, dist (vol J (f <| Ο€.tag J)) (g J) ≀ Ξ΅s (Ο€.tag J) := fun J hJ ↦ by rw [Finset.mem_filter] at hJ; obtain ⟨hJ, hJs⟩ := hJ refine Hδ₁ c _ βŸ¨Ο€.tag_mem_Icc _, hJs⟩ _ (hΞ΅s0 _) _ (Ο€.le_of_mem' _ hJ) ?_ (hπδ.2 hlH J hJ) fun hD => (Finset.le_sup hJ).trans (hπδ.3 hD) convert hπδ.1 J hJ using 3; exact (if_pos hJs).symm refine (dist_sum_sum_le_of_le _ this).trans ?_ rw [sum_comp] refine (sum_le_sum ?_).trans (hΞ΅s _ ?_) Β· rintro b - rw [← Nat.cast_two, ← Nat.cast_pow, ← nsmul_eq_mul] refine nsmul_le_nsmul_left (hΞ΅s0 _).le ?_ refine (Finset.card_le_card ?_).trans ((hπδ.isHenstock hlH).card_filter_tag_eq_le b) exact filter_subset_filter _ (filter_subset _ _) Β· rw [Finset.coe_image, Set.image_subset_iff] exact fun J hJ => (Finset.mem_filter.1 hJ).2 /- Now we deal with boxes such that `Ο€.tag J βˆ‰ s`. In this case the estimate is straightforward. -/ calc dist (βˆ‘ J ∈ Ο€.boxes with tag Ο€ J βˆ‰ s, vol J (f (tag Ο€ J))) (βˆ‘ J ∈ Ο€.boxes with tag Ο€ J βˆ‰ s, g J) ≀ βˆ‘ J ∈ Ο€.boxes with tag Ο€ J βˆ‰ s, Ξ΅' * B J := dist_sum_sum_le_of_le _ fun J hJ ↦ by rw [Finset.mem_filter] at hJ; obtain ⟨hJ, hJs⟩ := hJ refine HΞ΄β‚‚ c _ βŸ¨Ο€.tag_mem_Icc _, hJs⟩ _ Ξ΅'0 _ (Ο€.le_of_mem' _ hJ) ?_ (fun hH => hπδ.2 hH J hJ) fun hD => (Finset.le_sup hJ).trans (hπδ.3 hD) convert hπδ.1 J hJ using 3; exact (if_neg hJs).symm _ ≀ βˆ‘ J ∈ Ο€.boxes, Ξ΅' * B J := by gcongr Β· exact fun _ _ _ ↦ mul_nonneg Ξ΅'0.le (hB0 _) Β· apply filter_subset _ = B I * Ξ΅' := by rw [← mul_sum, B.sum_partition_boxes le_rfl hΟ€p, mul_comm] _ ≀ Ξ΅ / 2 := hΞ΅I.le /-- A function `f` has Henstock (or `βŠ₯`) integral over `I` is equal to the value of a box-additive function `g` on `I` provided that `vol J (f x)` is sufficiently close to `g J` for sufficiently small boxes `J βˆ‹ x`. This lemma is useful to prove, e.g., to prove the Divergence theorem for integral along `βŠ₯`. Let `l` be either `BoxIntegral.IntegrationParams.Henstock` or `βŠ₯`. Let `g` a box-additive function on subboxes of `I`. Suppose that there exists a nonnegative box-additive function `B` and a countable set `s` with the following property. For every `c : ℝβ‰₯0`, a point `x ∈ I.Icc`, and a positive `Ξ΅` there exists `Ξ΄ > 0` such that for any box `J ≀ I` such that - `x ∈ J.Icc βŠ† Metric.closedBall x Ξ΄`; - if `l.bDistortion` (i.e., `l = βŠ₯`), then the distortion of `J` is less than or equal to `c`, the distance between the term `vol J (f x)` of an integral sum corresponding to `J` and `g J` is less than or equal to `Ξ΅` if `x ∈ s` and is less than or equal to `Ξ΅ * B J` otherwise. Then `f` is integrable on `I` along `l` with integral `g I`. -/ theorem HasIntegral.of_le_Henstock_of_forall_isLittleO (hl : l ≀ Henstock) (B : ΞΉ →ᡇᡃ[I] ℝ) (hB0 : βˆ€ J, 0 ≀ B J) (g : ΞΉ →ᡇᡃ[I] F) (s : Set ℝⁿ) (hs : s.Countable) (H₁ : βˆ€ (c : ℝβ‰₯0), βˆ€ x ∈ Box.Icc I ∩ s, βˆ€ Ξ΅ > (0 : ℝ), βˆƒ Ξ΄ > 0, βˆ€ J ≀ I, Box.Icc J βŠ† Metric.closedBall x Ξ΄ β†’ x ∈ Box.Icc J β†’ (l.bDistortion β†’ J.distortion ≀ c) β†’ dist (vol J (f x)) (g J) ≀ Ξ΅) (Hβ‚‚ : βˆ€ (c : ℝβ‰₯0), βˆ€ x ∈ Box.Icc I \ s, βˆ€ Ξ΅ > (0 : ℝ), βˆƒ Ξ΄ > 0, βˆ€ J ≀ I, Box.Icc J βŠ† Metric.closedBall x Ξ΄ β†’ x ∈ Box.Icc J β†’ (l.bDistortion β†’ J.distortion ≀ c) β†’ dist (vol J (f x)) (g J) ≀ Ξ΅ * B J) : HasIntegral I l f vol (g I) := have A : l.bHenstock := Bool.eq_true_of_true_le hl.2.1 HasIntegral.of_bRiemann_eq_false_of_forall_isLittleO (Bool.eq_false_of_le_false hl.1) B hB0 _ s hs (fun _ => A) H₁ <| by simpa only [A, true_imp_iff] using Hβ‚‚ /-- Suppose that there exists a nonnegative box-additive function `B` with the following property. For every `c : ℝβ‰₯0`, a point `x ∈ I.Icc`, and a positive `Ξ΅` there exists `Ξ΄ > 0` such that for any box `J ≀ I` such that - `J.Icc βŠ† Metric.closedBall x Ξ΄`; - if `l.bDistortion` (i.e., `l = βŠ₯`), then the distortion of `J` is less than or equal to `c`, the distance between the term `vol J (f x)` of an integral sum corresponding to `J` and `g J` is less than or equal to `Ξ΅ * B J`. Then `f` is McShane integrable on `I` with integral `g I`. -/ theorem HasIntegral.mcShane_of_forall_isLittleO (B : ΞΉ →ᡇᡃ[I] ℝ) (hB0 : βˆ€ J, 0 ≀ B J) (g : ΞΉ →ᡇᡃ[I] F) (H : βˆ€ (_ : ℝβ‰₯0), βˆ€ x ∈ Box.Icc I, βˆ€ Ξ΅ > (0 : ℝ), βˆƒ Ξ΄ > 0, βˆ€ J ≀ I, Box.Icc J βŠ† Metric.closedBall x Ξ΄ β†’ dist (vol J (f x)) (g J) ≀ Ξ΅ * B J) : HasIntegral I McShane f vol (g I) := (HasIntegral.of_bRiemann_eq_false_of_forall_isLittleO (l := McShane) rfl B hB0 g βˆ… countable_empty (fun ⟨_x, hx⟩ => hx.elim) fun _ _ hx => hx.2.elim) <| by simpa only [McShane, Bool.coe_sort_false, false_imp_iff, true_imp_iff, diff_empty] using H end BoxIntegral
.lake/packages/mathlib/Mathlib/Analysis/BoxIntegral/DivergenceTheorem.lean
import Mathlib.Analysis.BoxIntegral.Basic import Mathlib.Analysis.BoxIntegral.Partition.Additive import Mathlib.Analysis.Calculus.FDeriv.Prod /-! # Divergence integral for Henstock-Kurzweil integral In this file we prove the Divergence Theorem for a Henstock-Kurzweil style integral. The theorem says the following. Let `f : ℝⁿ β†’ Eⁿ` be a function differentiable on a closed rectangular box `I` with derivative `f' x : ℝⁿ β†’L[ℝ] Eⁿ` at `x ∈ I`. Then the divergence `fun x ↦ βˆ‘ k, f' x eβ‚– k`, where `eβ‚– = Pi.single k 1` is the `k`-th basis vector, is integrable on `I`, and its integral is equal to the sum of integrals of `f` over the faces of `I` taken with appropriate signs. To make the proof work, we had to ban tagged partitions with β€œlong and thin” boxes. More precisely, we use the following generalization of one-dimensional Henstock-Kurzweil integral to functions defined on a box in `ℝⁿ` (it corresponds to the value `BoxIntegral.IntegrationParams.GP = βŠ₯` of `BoxIntegral.IntegrationParams` in the definition of `BoxIntegral.HasIntegral`). We say that `f : ℝⁿ β†’ E` has integral `y : E` over a box `I βŠ† ℝⁿ` if for an arbitrarily small positive `Ξ΅` and an arbitrarily large `c`, there exists a function `r : ℝⁿ β†’ (0, ∞)` such that for any tagged partition `Ο€` of `I` such that * `Ο€` is a Henstock partition, i.e., each tag belongs to its box; * `Ο€` is subordinate to `r`; * for every box of `Ο€`, the maximum of the ratios of its sides is less than or equal to `c`, the integral sum of `f` over `Ο€` is `Ξ΅`-close to `y`. In case of dimension one, the last condition trivially holds for any `c β‰₯ 1`, so this definition is equivalent to the standard definition of Henstock-Kurzweil integral. ## Tags Henstock-Kurzweil integral, integral, Stokes theorem, divergence theorem -/ open scoped NNReal ENNReal Topology BoxIntegral open ContinuousLinearMap (lsmul) open Filter Set Finset Metric open BoxIntegral.IntegrationParams (GP gp_le) noncomputable section universe u variable {E : Type u} [NormedAddCommGroup E] [NormedSpace ℝ E] {n : β„•} namespace BoxIntegral variable [CompleteSpace E] (I : Box (Fin (n + 1))) {i : Fin (n + 1)} open MeasureTheory /-- Auxiliary lemma for the divergence theorem. -/ theorem norm_volume_sub_integral_face_upper_sub_lower_smul_le {f : (Fin (n + 1) β†’ ℝ) β†’ E} {f' : (Fin (n + 1) β†’ ℝ) β†’L[ℝ] E} (hfc : ContinuousOn f (Box.Icc I)) {x : Fin (n + 1) β†’ ℝ} (hxI : x ∈ (Box.Icc I)) {a : E} {Ξ΅ : ℝ} (h0 : 0 < Ξ΅) (hΞ΅ : βˆ€ y ∈ (Box.Icc I), β€–f y - a - f' (y - x)β€– ≀ Ξ΅ * β€–y - xβ€–) {c : ℝβ‰₯0} (hc : I.distortion ≀ c) : β€–(∏ j, (I.upper j - I.lower j)) β€’ f' (Pi.single i 1) - (integral (I.face i) βŠ₯ (f ∘ i.insertNth (Ξ± := fun _ ↦ ℝ) (I.upper i)) BoxAdditiveMap.volume - integral (I.face i) βŠ₯ (f ∘ i.insertNth (Ξ± := fun _ ↦ ℝ) (I.lower i)) BoxAdditiveMap.volume)β€– ≀ 2 * Ξ΅ * c * ∏ j, (I.upper j - I.lower j) := by -- Porting note: Lean fails to find `Ξ±` in the next line set e : ℝ β†’ (Fin n β†’ ℝ) β†’ (Fin (n + 1) β†’ ℝ) := i.insertNth (Ξ± := fun _ ↦ ℝ) /- **Plan of the proof**. The difference of the integrals of the affine function `fun y ↦ a + f' (y - x)` over the faces `x i = I.upper i` and `x i = I.lower i` is equal to the volume of `I` multiplied by `f' (Pi.single i 1)`, so it suffices to show that the integral of `f y - a - f' (y - x)` over each of these faces is less than or equal to `Ξ΅ * c * vol I`. We integrate a function of the norm `≀ Ξ΅ * diam I.Icc` over a box of volume `∏ j β‰  i, (I.upper j - I.lower j)`. Since `diam I.Icc ≀ c * (I.upper i - I.lower i)`, we get the required estimate. -/ have Hl : I.lower i ∈ Icc (I.lower i) (I.upper i) := Set.left_mem_Icc.2 (I.lower_le_upper i) have Hu : I.upper i ∈ Icc (I.lower i) (I.upper i) := Set.right_mem_Icc.2 (I.lower_le_upper i) have Hi : βˆ€ x ∈ Icc (I.lower i) (I.upper i), Integrable.{0, u, u} (I.face i) βŠ₯ (f ∘ e x) BoxAdditiveMap.volume := fun x hx => integrable_of_continuousOn _ (Box.continuousOn_face_Icc hfc hx) volume /- We start with an estimate: the difference of the values of `f` at the corresponding points of the faces `x i = I.lower i` and `x i = I.upper i` is `(2 * Ξ΅ * diam I.Icc)`-close to the value of `f'` on `Pi.single i (I.upper i - I.lower i) = lα΅’ β€’ eα΅’`, where `lα΅’ = I.upper i - I.lower i` is the length of `i`-th edge of `I` and `eα΅’ = Pi.single i 1` is the `i`-th unit vector. -/ have : βˆ€ y ∈ Box.Icc (I.face i), β€–f' (Pi.single i (I.upper i - I.lower i)) - (f (e (I.upper i) y) - f (e (I.lower i) y))β€– ≀ 2 * Ξ΅ * diam (Box.Icc I) := fun y hy ↦ by set g := fun y => f y - a - f' (y - x) with hg change βˆ€ y ∈ (Box.Icc I), β€–g yβ€– ≀ Ξ΅ * β€–y - xβ€– at hΞ΅ clear_value g; obtain rfl : f = fun y => a + f' (y - x) + g y := by simp [hg] convert_to β€–g (e (I.lower i) y) - g (e (I.upper i) y)β€– ≀ _ Β· congr 1 have := Fin.insertNth_sub_same (Ξ± := fun _ ↦ ℝ) i (I.upper i) (I.lower i) y simp only [← this, f'.map_sub]; abel Β· have : βˆ€ z ∈ Icc (I.lower i) (I.upper i), e z y ∈ (Box.Icc I) := fun z hz => I.mapsTo_insertNth_face_Icc hz hy replace hΞ΅ : βˆ€ y ∈ (Box.Icc I), β€–g yβ€– ≀ Ξ΅ * diam (Box.Icc I) := by intro y hy refine (hΞ΅ y hy).trans (mul_le_mul_of_nonneg_left ?_ h0.le) rw [← dist_eq_norm] exact dist_le_diam_of_mem I.isCompact_Icc.isBounded hy hxI rw [two_mul, add_mul] exact norm_sub_le_of_le (hΞ΅ _ (this _ Hl)) (hΞ΅ _ (this _ Hu)) calc β€–(∏ j, (I.upper j - I.lower j)) β€’ f' (Pi.single i 1) - (integral (I.face i) βŠ₯ (f ∘ e (I.upper i)) BoxAdditiveMap.volume - integral (I.face i) βŠ₯ (f ∘ e (I.lower i)) BoxAdditiveMap.volume)β€– = β€–integral.{0, u, u} (I.face i) βŠ₯ (fun x : Fin n β†’ ℝ => f' (Pi.single i (I.upper i - I.lower i)) - (f (e (I.upper i) x) - f (e (I.lower i) x))) BoxAdditiveMap.volumeβ€– := by rw [← integral_sub (Hi _ Hu) (Hi _ Hl), ← Box.volume_face_mul i, mul_smul, ← Box.volume_apply, ← BoxAdditiveMap.toSMul_apply, ← integral_const, ← BoxAdditiveMap.volume, ← integral_sub (integrable_const _) ((Hi _ Hu).sub (Hi _ Hl))] simp only [(Β· ∘ Β·), Pi.sub_def, ← f'.map_smul, ← Pi.single_smul', smul_eq_mul, mul_one] _ ≀ (volume (I.face i : Set (Fin n β†’ ℝ))).toReal * (2 * Ξ΅ * c * (I.upper i - I.lower i)) := by -- The hard part of the estimate was done above, here we just replace `diam I.Icc` -- with `c * (I.upper i - I.lower i)` refine norm_integral_le_of_le_const (fun y hy => (this y hy).trans ?_) volume rw [mul_assoc (2 * Ξ΅)] gcongr exact I.diam_Icc_le_of_distortion_le i hc _ = 2 * Ξ΅ * c * ∏ j, (I.upper j - I.lower j) := by rw [← measureReal_def, ← Measure.toBoxAdditive_apply, Box.volume_apply, ← I.volume_face_mul i] ac_rfl /-- If `f : ℝⁿ⁺¹ β†’ E` is differentiable on a closed rectangular box `I` with derivative `f'`, then the partial derivative `fun x ↦ f' x (Pi.single i 1)` is Henstock-Kurzweil integrable with integral equal to the difference of integrals of `f` over the faces `x i = I.upper i` and `x i = I.lower i`. More precisely, we use a non-standard generalization of the Henstock-Kurzweil integral and we allow `f` to be non-differentiable (but still continuous) at a countable set of points. TODO: If `n > 0`, then the condition at `x ∈ s` can be replaced by a much weaker estimate but this requires either better integrability theorems, or usage of a filter depending on the countable set `s` (we need to ensure that none of the faces of a partition contain a point from `s`). -/ theorem hasIntegral_GP_pderiv (f : (Fin (n + 1) β†’ ℝ) β†’ E) (f' : (Fin (n + 1) β†’ ℝ) β†’ (Fin (n + 1) β†’ ℝ) β†’L[ℝ] E) (s : Set (Fin (n + 1) β†’ ℝ)) (hs : s.Countable) (Hs : βˆ€ x ∈ s, ContinuousWithinAt f (Box.Icc I) x) (Hd : βˆ€ x ∈ (Box.Icc I) \ s, HasFDerivWithinAt f (f' x) (Box.Icc I) x) (i : Fin (n + 1)) : HasIntegral.{0, u, u} I GP (fun x => f' x (Pi.single i 1)) BoxAdditiveMap.volume (integral.{0, u, u} (I.face i) GP (fun x => f (i.insertNth (I.upper i) x)) BoxAdditiveMap.volume - integral.{0, u, u} (I.face i) GP (fun x => f (i.insertNth (I.lower i) x)) BoxAdditiveMap.volume) := by /- Note that `f` is continuous on `I.Icc`, hence it is integrable on the faces of all boxes `J ≀ I`, thus the difference of integrals over `x i = J.upper i` and `x i = J.lower i` is a box-additive function of `J ≀ I`. -/ have Hc : ContinuousOn f (Box.Icc I) := fun x hx ↦ by by_cases hxs : x ∈ s exacts [Hs x hxs, (Hd x ⟨hx, hxs⟩).continuousWithinAt] set fI : ℝ β†’ Box (Fin n) β†’ E := fun y J => integral.{0, u, u} J GP (fun x => f (i.insertNth y x)) BoxAdditiveMap.volume set fb : Icc (I.lower i) (I.upper i) β†’ Fin n →ᡇᡃ[↑(I.face i)] E := fun x => (integrable_of_continuousOn GP (Box.continuousOn_face_Icc Hc x.2) volume).toBoxAdditive set F : Fin (n + 1) →ᡇᡃ[I] E := BoxAdditiveMap.upperSubLower I i fI fb fun x _ J => rfl -- Thus our statement follows from some local estimates. change HasIntegral I GP (fun x => f' x (Pi.single i 1)) _ (F I) refine HasIntegral.of_le_Henstock_of_forall_isLittleO gp_le ?_ ?_ _ s hs ?_ ?_ Β·-- We use the volume as an upper estimate. exact (volume : Measure (Fin (n + 1) β†’ ℝ)).toBoxAdditive.restrict _ le_top Β· exact fun J => ENNReal.toReal_nonneg Β· intro c x hx Ξ΅ Ξ΅0 /- Near `x ∈ s` we choose `Ξ΄` so that both vectors are small. `volume J β€’ eα΅’` is small because `volume J ≀ (2 * Ξ΄) ^ (n + 1)` is small, and the difference of the integrals is small because each of the integrals is close to `volume (J.face i) β€’ f x`. TODO: there should be a shorter and more readable way to formalize this simple proof. -/ have : βˆ€αΆ  Ξ΄ in 𝓝[>] (0 : ℝ), Ξ΄ ∈ Ioc (0 : ℝ) (1 / 2) ∧ (βˆ€α΅‰ (y₁ ∈ closedBall x Ξ΄ ∩ (Box.Icc I)) (yβ‚‚ ∈ closedBall x Ξ΄ ∩ (Box.Icc I)), β€–f y₁ - f yβ‚‚β€– ≀ Ξ΅ / 2) ∧ (2 * Ξ΄) ^ (n + 1) * β€–f' x (Pi.single i 1)β€– ≀ Ξ΅ / 2 := by refine .and (Ioc_mem_nhdsGT one_half_pos) (.and ?_ ?_) Β· rcases ((nhdsWithin_hasBasis nhds_basis_closedBall _).tendsto_iff nhds_basis_closedBall).1 (Hs x hx.2) _ (half_pos <| half_pos Ξ΅0) with βŸ¨Ξ΄β‚, δ₁0, hΞ΄β‚βŸ© filter_upwards [Ioc_mem_nhdsGT δ₁0] with Ξ΄ hΞ΄ y₁ hy₁ yβ‚‚ hyβ‚‚ have : closedBall x Ξ΄ ∩ (Box.Icc I) βŠ† closedBall x δ₁ ∩ (Box.Icc I) := by gcongr; exact hΞ΄.2 rw [← dist_eq_norm] calc dist (f y₁) (f yβ‚‚) ≀ dist (f y₁) (f x) + dist (f yβ‚‚) (f x) := dist_triangle_right _ _ _ _ ≀ Ξ΅ / 2 / 2 + Ξ΅ / 2 / 2 := add_le_add (hδ₁ _ <| this hy₁) (hδ₁ _ <| this hyβ‚‚) _ = Ξ΅ / 2 := add_halves _ Β· have : ContinuousWithinAt (fun Ξ΄ : ℝ => (2 * Ξ΄) ^ (n + 1) * β€–f' x (Pi.single i 1)β€–) (Ioi 0) 0 := ((continuousWithinAt_id.const_mul _).pow _).mul_const _ refine this.eventually (ge_mem_nhds ?_) simpa using half_pos Ξ΅0 rcases this.exists with ⟨δ, ⟨hΞ΄0, hΞ΄12⟩, hdfΞ΄, hδ⟩ refine ⟨δ, hΞ΄0, fun J hJI hJΞ΄ _ _ => add_halves Ξ΅ β–Έ ?_⟩ have Hl : J.lower i ∈ Icc (J.lower i) (J.upper i) := Set.left_mem_Icc.2 (J.lower_le_upper i) have Hu : J.upper i ∈ Icc (J.lower i) (J.upper i) := Set.right_mem_Icc.2 (J.lower_le_upper i) have Hi : βˆ€ x ∈ Icc (J.lower i) (J.upper i), Integrable.{0, u, u} (J.face i) GP (fun y => f (i.insertNth x y)) BoxAdditiveMap.volume := fun x hx => integrable_of_continuousOn _ (Box.continuousOn_face_Icc (Hc.mono <| Box.le_iff_Icc.1 hJI) hx) volume have hJΞ΄' : Box.Icc J βŠ† closedBall x Ξ΄ ∩ (Box.Icc I) := subset_inter hJΞ΄ (Box.le_iff_Icc.1 hJI) have Hmaps : βˆ€ z ∈ Icc (J.lower i) (J.upper i), MapsTo (i.insertNth z) (Box.Icc (J.face i)) (closedBall x Ξ΄ ∩ (Box.Icc I)) := fun z hz => (J.mapsTo_insertNth_face_Icc hz).mono Subset.rfl hJΞ΄' simp only [dist_eq_norm]; dsimp [F] rw [← integral_sub (Hi _ Hu) (Hi _ Hl)] refine (norm_sub_le _ _).trans (add_le_add ?_ ?_) Β· simp_rw [BoxAdditiveMap.volume_apply, norm_smul, Real.norm_eq_abs, abs_prod] refine (mul_le_mul_of_nonneg_right ?_ <| norm_nonneg _).trans hΞ΄ have : βˆ€ j, |J.upper j - J.lower j| ≀ 2 * Ξ΄ := fun j ↦ calc dist (J.upper j) (J.lower j) ≀ dist J.upper J.lower := dist_le_pi_dist _ _ _ _ ≀ dist J.upper x + dist J.lower x := dist_triangle_right _ _ _ _ ≀ Ξ΄ + Ξ΄ := add_le_add (hJΞ΄ J.upper_mem_Icc) (hJΞ΄ J.lower_mem_Icc) _ = 2 * Ξ΄ := (two_mul Ξ΄).symm calc ∏ j, |J.upper j - J.lower j| ≀ ∏ j : Fin (n + 1), 2 * Ξ΄ := prod_le_prod (fun _ _ => abs_nonneg _) fun j _ => this j _ = (2 * Ξ΄) ^ (n + 1) := by simp Β· refine (norm_integral_le_of_le_const (fun y hy => hdfΞ΄ _ (Hmaps _ Hu hy) _ (Hmaps _ Hl hy)) volume).trans ?_ refine (mul_le_mul_of_nonneg_right ?_ (half_pos Ξ΅0).le).trans_eq (one_mul _) rw [Box.coe_eq_pi, measureReal_def, Real.volume_pi_Ioc_toReal (Box.lower_le_upper _)] refine prod_le_one (fun _ _ => sub_nonneg.2 <| Box.lower_le_upper _ _) fun j _ => ?_ calc J.upper (i.succAbove j) - J.lower (i.succAbove j) ≀ dist (J.upper (i.succAbove j)) (J.lower (i.succAbove j)) := le_abs_self _ _ ≀ dist J.upper J.lower := dist_le_pi_dist J.upper J.lower (i.succAbove j) _ ≀ dist J.upper x + dist J.lower x := dist_triangle_right _ _ _ _ ≀ Ξ΄ + Ξ΄ := add_le_add (hJΞ΄ J.upper_mem_Icc) (hJΞ΄ J.lower_mem_Icc) _ ≀ 1 / 2 + 1 / 2 := by gcongr _ = 1 := add_halves 1 Β· intro c x hx Ξ΅ Ξ΅0 /- At a point `x βˆ‰ s`, we unfold the definition of FrΓ©chet differentiability, then use an estimate we proved earlier in this file. -/ rcases exists_pos_mul_lt Ξ΅0 (2 * c) with ⟨Ρ', Ξ΅'0, hlt⟩ rcases (nhdsWithin_hasBasis nhds_basis_closedBall _).mem_iff.1 ((Hd x hx).isLittleO.def Ξ΅'0) with ⟨δ, Ξ΄0, Hδ⟩ refine ⟨δ, Ξ΄0, fun J hle hJΞ΄ hxJ hJc => ?_⟩ simp only [BoxAdditiveMap.volume_apply, dist_eq_norm] refine (norm_volume_sub_integral_face_upper_sub_lower_smul_le _ (Hc.mono <| Box.le_iff_Icc.1 hle) hxJ Ξ΅'0 (fun y hy => HΞ΄ ?_) (hJc rfl)).trans ?_ Β· exact ⟨hJΞ΄ hy, Box.le_iff_Icc.1 hle hy⟩ Β· rw [mul_right_comm (2 : ℝ), ← Box.volume_apply] exact mul_le_mul_of_nonneg_right hlt.le ENNReal.toReal_nonneg /-- Divergence theorem for a Henstock-Kurzweil style integral. If `f : ℝⁿ⁺¹ β†’ Eⁿ⁺¹` is differentiable on a closed rectangular box `I` with derivative `f'`, then the divergence `βˆ‘ i, f' x (Pi.single i 1) i` is Henstock-Kurzweil integrable with integral equal to the sum of integrals of `f` over the faces of `I` taken with appropriate signs. More precisely, we use a non-standard generalization of the Henstock-Kurzweil integral and we allow `f` to be non-differentiable (but still continuous) at a countable set of points. -/ theorem hasIntegral_GP_divergence_of_forall_hasDerivWithinAt (f : (Fin (n + 1) β†’ ℝ) β†’ Fin (n + 1) β†’ E) (f' : (Fin (n + 1) β†’ ℝ) β†’ (Fin (n + 1) β†’ ℝ) β†’L[ℝ] (Fin (n + 1) β†’ E)) (s : Set (Fin (n + 1) β†’ ℝ)) (hs : s.Countable) (Hs : βˆ€ x ∈ s, ContinuousWithinAt f (Box.Icc I) x) (Hd : βˆ€ x ∈ (Box.Icc I) \ s, HasFDerivWithinAt f (f' x) (Box.Icc I) x) : HasIntegral.{0, u, u} I GP (fun x => βˆ‘ i, f' x (Pi.single i 1) i) BoxAdditiveMap.volume (βˆ‘ i, (integral.{0, u, u} (I.face i) GP (fun x => f (i.insertNth (I.upper i) x) i) BoxAdditiveMap.volume - integral.{0, u, u} (I.face i) GP (fun x => f (i.insertNth (I.lower i) x) i) BoxAdditiveMap.volume)) := by refine HasIntegral.sum fun i _ => ?_ simp only [hasFDerivWithinAt_pi', continuousWithinAt_pi] at Hd Hs exact hasIntegral_GP_pderiv I _ _ s hs (fun x hx => Hs x hx i) (fun x hx => Hd x hx i) i end BoxIntegral
.lake/packages/mathlib/Mathlib/Analysis/BoxIntegral/Box/Basic.lean
import Mathlib.Data.NNReal.Basic import Mathlib.Order.Fin.Tuple import Mathlib.Order.Interval.Set.Monotone import Mathlib.Topology.MetricSpace.Basic import Mathlib.Topology.MetricSpace.Bounded import Mathlib.Topology.MetricSpace.Pseudo.Real import Mathlib.Topology.Order.MonotoneConvergence /-! # Rectangular boxes in `ℝⁿ` In this file we define rectangular boxes in `ℝⁿ`. As usual, we represent `ℝⁿ` as the type of functions `ΞΉ β†’ ℝ` (usually `ΞΉ = Fin n` for some `n`). When we need to interpret a box `[l, u]` as a set, we use the product `{x | βˆ€ i, l i < x i ∧ x i ≀ u i}` of half-open intervals `(l i, u i]`. We exclude `l i` because this way boxes of a partition are disjoint as sets in `ℝⁿ`. Currently, the only use cases for these constructions are the definitions of Riemann-style integrals (Riemann, Henstock-Kurzweil, McShane). ## Main definitions We use the same structure `BoxIntegral.Box` both for ambient boxes and for elements of a partition. Each box is stored as two points `lower upper : ΞΉ β†’ ℝ` and a proof of `βˆ€ i, lower i < upper i`. We define instances `Membership (ΞΉ β†’ ℝ) (Box ΞΉ)` and `CoeTC (Box ΞΉ) (Set <| ΞΉ β†’ ℝ)` so that each box is interpreted as the set `{x | βˆ€ i, x i ∈ Set.Ioc (I.lower i) (I.upper i)}`. This way boxes of a partition are pairwise disjoint and their union is exactly the original box. We require boxes to be nonempty, because this way coercion to sets is injective. The empty box can be represented as `βŠ₯ : WithBot (BoxIntegral.Box ΞΉ)`. We define the following operations on boxes: * coercion to `Set (ΞΉ β†’ ℝ)` and `Membership (ΞΉ β†’ ℝ) (BoxIntegral.Box ΞΉ)` as described above; * `PartialOrder` and `SemilatticeSup` instances such that `I ≀ J` is equivalent to `(I : Set (ΞΉ β†’ ℝ)) βŠ† J`; * `Lattice` instances on `WithBot (BoxIntegral.Box ΞΉ)`; * `BoxIntegral.Box.Icc`: the closed box `Set.Icc I.lower I.upper`; defined as a bundled monotone map from `Box ΞΉ` to `Set (ΞΉ β†’ ℝ)`; * `BoxIntegral.Box.face I i : Box (Fin n)`: a hyperface of `I : BoxIntegral.Box (Fin (n + 1))`; * `BoxIntegral.Box.distortion`: the maximal ratio of two lengths of edges of a box; defined as the supremum of `nndist I.lower I.upper / nndist (I.lower i) (I.upper i)`. We also provide a convenience constructor `BoxIntegral.Box.mk' (l u : ΞΉ β†’ ℝ) : WithBot (Box ΞΉ)` that returns the box `⟨l, u, _⟩` if it is nonempty and `βŠ₯` otherwise. ## Tags rectangular box -/ open Set Function Metric Filter noncomputable section open scoped NNReal Topology namespace BoxIntegral variable {ΞΉ : Type*} /-! ### Rectangular box: definition and partial order -/ /-- A nontrivial rectangular box in `ΞΉ β†’ ℝ` with corners `lower` and `upper`. Represents the product of half-open intervals `(lower i, upper i]`. -/ structure Box (ΞΉ : Type*) where /-- coordinates of the lower and upper corners of the box -/ (lower upper : ΞΉ β†’ ℝ) /-- Each lower coordinate is less than its upper coordinate: i.e., the box is non-empty -/ lower_lt_upper : βˆ€ i, lower i < upper i attribute [simp] Box.lower_lt_upper namespace Box variable (I J : Box ΞΉ) {x y : ΞΉ β†’ ℝ} instance : Inhabited (Box ΞΉ) := ⟨⟨0, 1, fun _ ↦ zero_lt_one⟩⟩ theorem lower_le_upper : I.lower ≀ I.upper := fun i ↦ (I.lower_lt_upper i).le theorem lower_ne_upper (i) : I.lower i β‰  I.upper i := (I.lower_lt_upper i).ne instance : Membership (ΞΉ β†’ ℝ) (Box ΞΉ) := ⟨fun I x ↦ βˆ€ i, x i ∈ Ioc (I.lower i) (I.upper i)⟩ /-- The set of points in this box: this is the product of half-open intervals `(lower i, upper i]`, where `lower` and `upper` are this box' corners. -/ @[coe] def toSet (I : Box ΞΉ) : Set (ΞΉ β†’ ℝ) := { x | x ∈ I } instance : CoeTC (Box ΞΉ) (Set <| ΞΉ β†’ ℝ) := ⟨toSet⟩ @[simp] theorem mem_mk {l u x : ΞΉ β†’ ℝ} {H} : x ∈ mk l u H ↔ βˆ€ i, x i ∈ Ioc (l i) (u i) := Iff.rfl @[simp, norm_cast] theorem mem_coe : x ∈ (I : Set (ΞΉ β†’ ℝ)) ↔ x ∈ I := Iff.rfl theorem mem_def : x ∈ I ↔ βˆ€ i, x i ∈ Ioc (I.lower i) (I.upper i) := Iff.rfl theorem mem_univ_Ioc {I : Box ΞΉ} : (x ∈ pi univ fun i ↦ Ioc (I.lower i) (I.upper i)) ↔ x ∈ I := mem_univ_pi theorem coe_eq_pi : (I : Set (ΞΉ β†’ ℝ)) = pi univ fun i ↦ Ioc (I.lower i) (I.upper i) := Set.ext fun _ ↦ mem_univ_Ioc.symm @[simp] theorem upper_mem : I.upper ∈ I := fun i ↦ right_mem_Ioc.2 <| I.lower_lt_upper i theorem exists_mem : βˆƒ x, x ∈ I := ⟨_, I.upper_mem⟩ theorem nonempty_coe : Set.Nonempty (I : Set (ΞΉ β†’ ℝ)) := I.exists_mem @[simp] theorem coe_ne_empty : (I : Set (ΞΉ β†’ ℝ)) β‰  βˆ… := I.nonempty_coe.ne_empty @[simp] theorem empty_ne_coe : βˆ… β‰  (I : Set (ΞΉ β†’ ℝ)) := I.coe_ne_empty.symm instance : LE (Box ΞΉ) := ⟨fun I J ↦ βˆ€ ⦃x⦄, x ∈ I β†’ x ∈ J⟩ theorem le_def : I ≀ J ↔ βˆ€ x ∈ I, x ∈ J := Iff.rfl theorem le_TFAE : List.TFAE [I ≀ J, (I : Set (ΞΉ β†’ ℝ)) βŠ† J, Icc I.lower I.upper βŠ† Icc J.lower J.upper, J.lower ≀ I.lower ∧ I.upper ≀ J.upper] := by tfae_have 1 ↔ 2 := Iff.rfl tfae_have 2 β†’ 3 | h => by simpa [coe_eq_pi, closure_pi_set, lower_ne_upper] using closure_mono h tfae_have 3 ↔ 4 := Icc_subset_Icc_iff I.lower_le_upper tfae_have 4 β†’ 2 | h, x, hx, i => Ioc_subset_Ioc (h.1 i) (h.2 i) (hx i) tfae_finish variable {I J} @[simp, norm_cast] theorem coe_subset_coe : (I : Set (ΞΉ β†’ ℝ)) βŠ† J ↔ I ≀ J := Iff.rfl theorem le_iff_bounds : I ≀ J ↔ J.lower ≀ I.lower ∧ I.upper ≀ J.upper := (le_TFAE I J).out 0 3 theorem injective_coe : Injective ((↑) : Box ΞΉ β†’ Set (ΞΉ β†’ ℝ)) := by rintro ⟨l₁, u₁, hβ‚βŸ© ⟨lβ‚‚, uβ‚‚, hβ‚‚βŸ© h simp only [Subset.antisymm_iff, coe_subset_coe, le_iff_bounds] at h congr exacts [le_antisymm h.2.1 h.1.1, le_antisymm h.1.2 h.2.2] @[simp, norm_cast] theorem coe_inj : (I : Set (ΞΉ β†’ ℝ)) = J ↔ I = J := injective_coe.eq_iff @[ext] theorem ext (H : βˆ€ x, x ∈ I ↔ x ∈ J) : I = J := injective_coe <| Set.ext H theorem ne_of_disjoint_coe (h : Disjoint (I : Set (ΞΉ β†’ ℝ)) J) : I β‰  J := mt coe_inj.2 <| h.ne I.coe_ne_empty instance : PartialOrder (Box ΞΉ) := { PartialOrder.lift ((↑) : Box ΞΉ β†’ Set (ΞΉ β†’ ℝ)) injective_coe with le := (Β· ≀ Β·) } /-- Closed box corresponding to `I : BoxIntegral.Box ΞΉ`. -/ protected def Icc : Box ΞΉ β†ͺo Set (ΞΉ β†’ ℝ) := OrderEmbedding.ofMapLEIff (fun I : Box ΞΉ ↦ Icc I.lower I.upper) fun I J ↦ (le_TFAE I J).out 2 0 theorem Icc_def : Box.Icc I = Icc I.lower I.upper := rfl @[simp] theorem upper_mem_Icc (I : Box ΞΉ) : I.upper ∈ Box.Icc I := right_mem_Icc.2 I.lower_le_upper @[simp] theorem lower_mem_Icc (I : Box ΞΉ) : I.lower ∈ Box.Icc I := left_mem_Icc.2 I.lower_le_upper protected theorem isCompact_Icc (I : Box ΞΉ) : IsCompact (Box.Icc I) := isCompact_Icc theorem Icc_eq_pi : Box.Icc I = pi univ fun i ↦ Icc (I.lower i) (I.upper i) := (pi_univ_Icc _ _).symm theorem le_iff_Icc : I ≀ J ↔ Box.Icc I βŠ† Box.Icc J := (le_TFAE I J).out 0 2 theorem antitone_lower : Antitone fun I : Box ΞΉ ↦ I.lower := fun _ _ H ↦ (le_iff_bounds.1 H).1 theorem monotone_upper : Monotone fun I : Box ΞΉ ↦ I.upper := fun _ _ H ↦ (le_iff_bounds.1 H).2 theorem coe_subset_Icc : ↑I βŠ† Box.Icc I := fun _ hx ↦ ⟨fun i ↦ (hx i).1.le, fun i ↦ (hx i).2⟩ theorem isBounded_Icc [Finite ΞΉ] (I : Box ΞΉ) : Bornology.IsBounded (Box.Icc I) := by cases nonempty_fintype ΞΉ exact Metric.isBounded_Icc _ _ theorem isBounded [Finite ΞΉ] (I : Box ΞΉ) : Bornology.IsBounded I.toSet := Bornology.IsBounded.subset I.isBounded_Icc coe_subset_Icc /-! ### Supremum of two boxes -/ /-- `I βŠ” J` is the least box that includes both `I` and `J`. Since `↑I βˆͺ ↑J` is usually not a box, `↑(I βŠ” J)` is larger than `↑I βˆͺ ↑J`. -/ instance : SemilatticeSup (Box ΞΉ) := { sup := fun I J ↦ ⟨I.lower βŠ“ J.lower, I.upper βŠ” J.upper, fun i ↦ (min_le_left _ _).trans_lt <| (I.lower_lt_upper i).trans_le (le_max_left _ _)⟩ le_sup_left := fun _ _ ↦ le_iff_bounds.2 ⟨inf_le_left, le_sup_left⟩ le_sup_right := fun _ _ ↦ le_iff_bounds.2 ⟨inf_le_right, le_sup_right⟩ sup_le := fun _ _ _ h₁ hβ‚‚ ↦ le_iff_bounds.2 ⟨le_inf (antitone_lower h₁) (antitone_lower hβ‚‚), sup_le (monotone_upper h₁) (monotone_upper hβ‚‚)⟩ } /-! ### `WithBot (Box ΞΉ)` In this section we define coercion from `WithBot (Box ΞΉ)` to `Set (ΞΉ β†’ ℝ)` by sending `βŠ₯` to `βˆ…`. -/ /-- The set underlying this box: `βŠ₯` is mapped to `βˆ…`. -/ @[coe] def withBotToSet (o : WithBot (Box ΞΉ)) : Set (ΞΉ β†’ ℝ) := o.elim βˆ… (↑) instance withBotCoe : CoeTC (WithBot (Box ΞΉ)) (Set (ΞΉ β†’ ℝ)) := ⟨withBotToSet⟩ @[simp, norm_cast] theorem coe_bot : ((βŠ₯ : WithBot (Box ΞΉ)) : Set (ΞΉ β†’ ℝ)) = βˆ… := rfl @[simp, norm_cast] theorem coe_coe : ((I : WithBot (Box ΞΉ)) : Set (ΞΉ β†’ ℝ)) = I := rfl theorem isSome_iff : βˆ€ {I : WithBot (Box ΞΉ)}, I.isSome ↔ (I : Set (ΞΉ β†’ ℝ)).Nonempty | βŠ₯ => by unfold Option.isSome simp | (I : Box ΞΉ) => by unfold Option.isSome simp [I.nonempty_coe] theorem biUnion_coe_eq_coe (I : WithBot (Box ΞΉ)) : ⋃ (J : Box ΞΉ) (_ : ↑J = I), (J : Set (ΞΉ β†’ ℝ)) = I := by induction I <;> simp @[simp, norm_cast] theorem withBotCoe_subset_iff {I J : WithBot (Box ΞΉ)} : (I : Set (ΞΉ β†’ ℝ)) βŠ† J ↔ I ≀ J := by induction I; Β· simp induction J; Β· simp [subset_empty_iff] simp [le_def] @[simp, norm_cast] theorem withBotCoe_inj {I J : WithBot (Box ΞΉ)} : (I : Set (ΞΉ β†’ ℝ)) = J ↔ I = J := by simp only [Subset.antisymm_iff, ← le_antisymm_iff, withBotCoe_subset_iff] open scoped Classical in /-- Make a `WithBot (Box ΞΉ)` from a pair of corners `l u : ΞΉ β†’ ℝ`. If `l i < u i` for all `i`, then the result is `⟨l, u, _⟩ : Box ΞΉ`, otherwise it is `βŠ₯`. In any case, the result interpreted as a set in `ΞΉ β†’ ℝ` is the set `{x : ΞΉ β†’ ℝ | βˆ€ i, x i ∈ Ioc (l i) (u i)}`. -/ def mk' (l u : ΞΉ β†’ ℝ) : WithBot (Box ΞΉ) := if h : βˆ€ i, l i < u i then ↑(⟨l, u, h⟩ : Box ΞΉ) else βŠ₯ @[simp] theorem mk'_eq_bot {l u : ΞΉ β†’ ℝ} : mk' l u = βŠ₯ ↔ βˆƒ i, u i ≀ l i := by rw [mk'] split_ifs with h <;> simpa using h @[simp] theorem mk'_eq_coe {l u : ΞΉ β†’ ℝ} : mk' l u = I ↔ l = I.lower ∧ u = I.upper := by obtain ⟨lI, uI, hI⟩ := I; rw [mk']; split_ifs with h Β· simp Β· suffices l = lI β†’ u β‰  uI by simpa rintro rfl rfl exact h hI @[simp] theorem coe_mk' (l u : ΞΉ β†’ ℝ) : (mk' l u : Set (ΞΉ β†’ ℝ)) = pi univ fun i ↦ Ioc (l i) (u i) := by rw [mk']; split_ifs with h Β· exact coe_eq_pi _ Β· rcases not_forall.mp h with ⟨i, hi⟩ rw [coe_bot, univ_pi_eq_empty] exact Ioc_eq_empty hi instance WithBot.inf : Min (WithBot (Box ΞΉ)) := ⟨fun I ↦ WithBot.recBotCoe (fun _ ↦ βŠ₯) (fun I J ↦ WithBot.recBotCoe βŠ₯ (fun J ↦ mk' (I.lower βŠ” J.lower) (I.upper βŠ“ J.upper)) J) I⟩ @[simp] theorem coe_inf (I J : WithBot (Box ΞΉ)) : (↑(I βŠ“ J) : Set (ΞΉ β†’ ℝ)) = (I : Set _) ∩ J := by induction I Β· change βˆ… = _ simp induction J Β· change βˆ… = _ simp change ((mk' _ _ : WithBot (Box ΞΉ)) : Set (ΞΉ β†’ ℝ)) = _ simp only [coe_eq_pi, ← pi_inter_distrib, Ioc_inter_Ioc, Pi.sup_apply, Pi.inf_apply, coe_mk', coe_coe] instance : Lattice (WithBot (Box ΞΉ)) := { inf := min inf_le_left := fun I J ↦ by rw [← withBotCoe_subset_iff, coe_inf] exact inter_subset_left inf_le_right := fun I J ↦ by rw [← withBotCoe_subset_iff, coe_inf] exact inter_subset_right le_inf := fun I J₁ Jβ‚‚ h₁ hβ‚‚ ↦ by simp only [← withBotCoe_subset_iff, coe_inf] at * exact subset_inter h₁ hβ‚‚ } @[simp, norm_cast] theorem disjoint_withBotCoe {I J : WithBot (Box ΞΉ)} : Disjoint (I : Set (ΞΉ β†’ ℝ)) J ↔ Disjoint I J := by simp only [disjoint_iff_inf_le, ← withBotCoe_subset_iff, coe_inf] rfl theorem disjoint_coe : Disjoint (I : WithBot (Box ΞΉ)) J ↔ Disjoint (I : Set (ΞΉ β†’ ℝ)) J := disjoint_withBotCoe.symm theorem not_disjoint_coe_iff_nonempty_inter : Β¬Disjoint (I : WithBot (Box ΞΉ)) J ↔ (I ∩ J : Set (ΞΉ β†’ ℝ)).Nonempty := by rw [disjoint_coe, Set.not_disjoint_iff_nonempty_inter] /-! ### Hyperface of a box in `ℝⁿ⁺¹ = Fin (n + 1) β†’ ℝ` -/ /-- Face of a box in `ℝⁿ⁺¹ = Fin (n + 1) β†’ ℝ`: the box in `ℝⁿ = Fin n β†’ ℝ` with corners at `I.lower ∘ Fin.succAbove i` and `I.upper ∘ Fin.succAbove i`. -/ @[simps +simpRhs] def face {n} (I : Box (Fin (n + 1))) (i : Fin (n + 1)) : Box (Fin n) := ⟨I.lower ∘ Fin.succAbove i, I.upper ∘ Fin.succAbove i, fun _ ↦ I.lower_lt_upper _⟩ @[simp] theorem face_mk {n} (l u : Fin (n + 1) β†’ ℝ) (h : βˆ€ i, l i < u i) (i : Fin (n + 1)) : face ⟨l, u, h⟩ i = ⟨l ∘ Fin.succAbove i, u ∘ Fin.succAbove i, fun _ ↦ h _⟩ := rfl @[gcongr, mono] theorem face_mono {n} {I J : Box (Fin (n + 1))} (h : I ≀ J) (i : Fin (n + 1)) : face I i ≀ face J i := fun _ hx _ ↦ Ioc_subset_Ioc ((le_iff_bounds.1 h).1 _) ((le_iff_bounds.1 h).2 _) (hx _) theorem monotone_face {n} (i : Fin (n + 1)) : Monotone fun I ↦ face I i := fun _ _ h ↦ face_mono h i theorem mapsTo_insertNth_face_Icc {n} (I : Box (Fin (n + 1))) {i : Fin (n + 1)} {x : ℝ} (hx : x ∈ Icc (I.lower i) (I.upper i)) : MapsTo (i.insertNth x) (Box.Icc (I.face i)) (Box.Icc I) := fun _ hy ↦ Fin.insertNth_mem_Icc.2 ⟨hx, hy⟩ theorem mapsTo_insertNth_face {n} (I : Box (Fin (n + 1))) {i : Fin (n + 1)} {x : ℝ} (hx : x ∈ Ioc (I.lower i) (I.upper i)) : MapsTo (i.insertNth x) (I.face i : Set (_ β†’ _)) (I : Set (_ β†’ _)) := by intro y hy simp_rw [mem_coe, mem_def, i.forall_iff_succAbove, Fin.insertNth_apply_same, Fin.insertNth_apply_succAbove] exact ⟨hx, hy⟩ theorem continuousOn_face_Icc {X} [TopologicalSpace X] {n} {f : (Fin (n + 1) β†’ ℝ) β†’ X} {I : Box (Fin (n + 1))} (h : ContinuousOn f (Box.Icc I)) {i : Fin (n + 1)} {x : ℝ} (hx : x ∈ Icc (I.lower i) (I.upper i)) : ContinuousOn (f ∘ i.insertNth x) (Box.Icc (I.face i)) := h.comp (continuousOn_const.finInsertNth i continuousOn_id) (I.mapsTo_insertNth_face_Icc hx) /-! ### Covering of the interior of a box by a monotone sequence of smaller boxes -/ /-- The interior of a box. -/ protected def Ioo : Box ΞΉ β†’o Set (ΞΉ β†’ ℝ) where toFun I := pi univ fun i ↦ Ioo (I.lower i) (I.upper i) monotone' _ _ h := pi_mono fun i _ ↦ Ioo_subset_Ioo ((le_iff_bounds.1 h).1 i) ((le_iff_bounds.1 h).2 i) theorem Ioo_subset_coe (I : Box ΞΉ) : Box.Ioo I βŠ† I := fun _ hx i ↦ Ioo_subset_Ioc_self (hx i trivial) protected theorem Ioo_subset_Icc (I : Box ΞΉ) : Box.Ioo I βŠ† Box.Icc I := I.Ioo_subset_coe.trans coe_subset_Icc theorem iUnion_Ioo_of_tendsto [Finite ΞΉ] {I : Box ΞΉ} {J : β„• β†’ Box ΞΉ} (hJ : Monotone J) (hl : Tendsto (lower ∘ J) atTop (𝓝 I.lower)) (hu : Tendsto (upper ∘ J) atTop (𝓝 I.upper)) : ⋃ n, Box.Ioo (J n) = Box.Ioo I := have hl' : βˆ€ i, Antitone fun n ↦ (J n).lower i := fun i ↦ (monotone_eval i).comp_antitone (antitone_lower.comp_monotone hJ) have hu' : βˆ€ i, Monotone fun n ↦ (J n).upper i := fun i ↦ (monotone_eval i).comp (monotone_upper.comp hJ) calc ⋃ n, Box.Ioo (J n) = pi univ fun i ↦ ⋃ n, Ioo ((J n).lower i) ((J n).upper i) := iUnion_univ_pi_of_monotone fun i ↦ (hl' i).Ioo (hu' i) _ = Box.Ioo I := pi_congr rfl fun i _ ↦ iUnion_Ioo_of_mono_of_isGLB_of_isLUB (hl' i) (hu' i) (isGLB_of_tendsto_atTop (hl' i) (tendsto_pi_nhds.1 hl _)) (isLUB_of_tendsto_atTop (hu' i) (tendsto_pi_nhds.1 hu _)) theorem exists_seq_mono_tendsto (I : Box ΞΉ) : βˆƒ J : β„• β†’o Box ΞΉ, (βˆ€ n, Box.Icc (J n) βŠ† Box.Ioo I) ∧ Tendsto (lower ∘ J) atTop (𝓝 I.lower) ∧ Tendsto (upper ∘ J) atTop (𝓝 I.upper) := by choose a b ha_anti hb_mono ha_mem hb_mem hab ha_tendsto hb_tendsto using fun i ↦ exists_seq_strictAnti_strictMono_tendsto (I.lower_lt_upper i) exact ⟨⟨fun k ↦ ⟨flip a k, flip b k, fun i ↦ hab _ _ _⟩, fun k l hkl ↦ le_iff_bounds.2 ⟨fun i ↦ (ha_anti i).antitone hkl, fun i ↦ (hb_mono i).monotone hkl⟩⟩, fun n x hx i _ ↦ ⟨(ha_mem _ _).1.trans_le (hx.1 _), (hx.2 _).trans_lt (hb_mem _ _).2⟩, tendsto_pi_nhds.2 ha_tendsto, tendsto_pi_nhds.2 hb_tendsto⟩ section Distortion variable [Fintype ΞΉ] /-- The distortion of a box `I` is the maximum of the ratios of the lengths of its edges. It is defined as the maximum of the ratios `nndist I.lower I.upper / nndist (I.lower i) (I.upper i)`. -/ def distortion (I : Box ΞΉ) : ℝβ‰₯0 := Finset.univ.sup fun i : ΞΉ ↦ nndist I.lower I.upper / nndist (I.lower i) (I.upper i) theorem distortion_eq_of_sub_eq_div {I J : Box ΞΉ} {r : ℝ} (h : βˆ€ i, I.upper i - I.lower i = (J.upper i - J.lower i) / r) : distortion I = distortion J := by simp only [distortion, nndist_pi_def, Real.nndist_eq', h, map_divβ‚€] congr 1 with i have : 0 < r := by by_contra hr have := div_nonpos_of_nonneg_of_nonpos (sub_nonneg.2 <| J.lower_le_upper i) (not_lt.1 hr) rw [← h] at this exact this.not_gt (sub_pos.2 <| I.lower_lt_upper i) have hn0 := (map_ne_zero Real.nnabs).2 this.ne' simp_rw [NNReal.finset_sup_div, div_div_div_cancel_rightβ‚€ hn0] theorem nndist_le_distortion_mul (I : Box ΞΉ) (i : ΞΉ) : nndist I.lower I.upper ≀ I.distortion * nndist (I.lower i) (I.upper i) := calc nndist I.lower I.upper = nndist I.lower I.upper / nndist (I.lower i) (I.upper i) * nndist (I.lower i) (I.upper i) := (div_mul_cancelβ‚€ _ <| mt nndist_eq_zero.1 (I.lower_lt_upper i).ne).symm _ ≀ I.distortion * nndist (I.lower i) (I.upper i) := by grw [distortion, ← Finset.le_sup (Finset.mem_univ i)] theorem dist_le_distortion_mul (I : Box ΞΉ) (i : ΞΉ) : dist I.lower I.upper ≀ I.distortion * (I.upper i - I.lower i) := by have A : I.lower i - I.upper i < 0 := sub_neg.2 (I.lower_lt_upper i) simpa only [← NNReal.coe_le_coe, ← dist_nndist, NNReal.coe_mul, Real.dist_eq, abs_of_neg A, neg_sub] using I.nndist_le_distortion_mul i theorem diam_Icc_le_of_distortion_le (I : Box ΞΉ) (i : ΞΉ) {c : ℝβ‰₯0} (h : I.distortion ≀ c) : diam (Box.Icc I) ≀ c * (I.upper i - I.lower i) := have : (0 : ℝ) ≀ c * (I.upper i - I.lower i) := mul_nonneg c.coe_nonneg (sub_nonneg.2 <| I.lower_le_upper _) diam_le_of_forall_dist_le this fun x hx y hy ↦ calc dist x y ≀ dist I.lower I.upper := Real.dist_le_of_mem_pi_Icc hx hy _ ≀ I.distortion * (I.upper i - I.lower i) := I.dist_le_distortion_mul i _ ≀ c * (I.upper i - I.lower i) := by gcongr; exact sub_nonneg.2 (I.lower_le_upper i) end Distortion end Box end BoxIntegral
.lake/packages/mathlib/Mathlib/Analysis/BoxIntegral/Box/SubboxInduction.lean
import Mathlib.Analysis.BoxIntegral.Box.Basic import Mathlib.Analysis.SpecificLimits.Basic /-! # Induction on subboxes In this file we prove the following induction principle for `BoxIntegral.Box`, see `BoxIntegral.Box.subbox_induction_on`. Let `p` be a predicate on `BoxIntegral.Box ΞΉ`, let `I` be a box. Suppose that the following two properties hold true. * Consider a smaller box `J ≀ I`. The hyperplanes passing through the center of `J` split it into `2 ^ n` boxes. If `p` holds true on each of these boxes, then it is true on `J`. * For each `z` in the closed box `I.Icc` there exists a neighborhood `U` of `z` within `I.Icc` such that for every box `J ≀ I` such that `z ∈ J.Icc βŠ† U`, if `J` is homothetic to `I` with a coefficient of the form `1 / 2 ^ m`, then `p` is true on `J`. Then `p I` is true. ## Tags rectangular box, induction -/ open Set Function Filter Topology noncomputable section namespace BoxIntegral namespace Box variable {ΞΉ : Type*} {I J : Box ΞΉ} open Classical in /-- For a box `I`, the hyperplanes passing through its center split `I` into `2 ^ card ΞΉ` boxes. `BoxIntegral.Box.splitCenterBox I s` is one of these boxes. See also `BoxIntegral.Partition.splitCenter` for the corresponding `BoxIntegral.Partition`. -/ def splitCenterBox (I : Box ΞΉ) (s : Set ΞΉ) : Box ΞΉ where lower := s.piecewise (fun i ↦ (I.lower i + I.upper i) / 2) I.lower upper := s.piecewise I.upper fun i ↦ (I.lower i + I.upper i) / 2 lower_lt_upper i := by dsimp only [Set.piecewise] split_ifs <;> simp only [left_lt_add_div_two, add_div_two_lt_right, I.lower_lt_upper] theorem mem_splitCenterBox {s : Set ΞΉ} {y : ΞΉ β†’ ℝ} : y ∈ I.splitCenterBox s ↔ y ∈ I ∧ βˆ€ i, (I.lower i + I.upper i) / 2 < y i ↔ i ∈ s := by simp only [splitCenterBox, mem_def, ← forall_and] refine forall_congr' fun i ↦ ?_ dsimp only [Set.piecewise] split_ifs with hs <;> simp only [hs, iff_true, iff_false, not_lt] exacts [⟨fun H ↦ ⟨⟨(left_lt_add_div_two.2 (I.lower_lt_upper i)).trans H.1, H.2⟩, H.1⟩, fun H ↦ ⟨H.2, H.1.2⟩⟩, ⟨fun H ↦ ⟨⟨H.1, H.2.trans (add_div_two_lt_right.2 (I.lower_lt_upper i)).le⟩, H.2⟩, fun H ↦ ⟨H.1.1, H.2⟩⟩] theorem splitCenterBox_le (I : Box ΞΉ) (s : Set ΞΉ) : I.splitCenterBox s ≀ I := fun _ hx ↦ (mem_splitCenterBox.1 hx).1 theorem disjoint_splitCenterBox (I : Box ΞΉ) {s t : Set ΞΉ} (h : s β‰  t) : Disjoint (I.splitCenterBox s : Set (ΞΉ β†’ ℝ)) (I.splitCenterBox t) := by rw [disjoint_iff_inf_le] rintro y ⟨hs, ht⟩; apply h ext i rw [mem_coe, mem_splitCenterBox] at hs ht rw [← hs.2, ← ht.2] theorem injective_splitCenterBox (I : Box ΞΉ) : Injective I.splitCenterBox := fun _ _ H ↦ by_contra fun Hne ↦ (I.disjoint_splitCenterBox Hne).ne (nonempty_coe _).ne_empty (H β–Έ rfl) @[simp] theorem exists_mem_splitCenterBox {I : Box ΞΉ} {x : ΞΉ β†’ ℝ} : (βˆƒ s, x ∈ I.splitCenterBox s) ↔ x ∈ I := ⟨fun ⟨s, hs⟩ ↦ I.splitCenterBox_le s hs, fun hx ↦ ⟨{ i | (I.lower i + I.upper i) / 2 < x i }, mem_splitCenterBox.2 ⟨hx, fun _ ↦ Iff.rfl⟩⟩⟩ /-- `BoxIntegral.Box.splitCenterBox` bundled as a `Function.Embedding`. -/ @[simps] def splitCenterBoxEmb (I : Box ΞΉ) : Set ΞΉ β†ͺ Box ΞΉ := ⟨splitCenterBox I, injective_splitCenterBox I⟩ @[simp] theorem iUnion_coe_splitCenterBox (I : Box ΞΉ) : ⋃ s, (I.splitCenterBox s : Set (ΞΉ β†’ ℝ)) = I := by ext x simp @[simp] theorem upper_sub_lower_splitCenterBox (I : Box ΞΉ) (s : Set ΞΉ) (i : ΞΉ) : (I.splitCenterBox s).upper i - (I.splitCenterBox s).lower i = (I.upper i - I.lower i) / 2 := by by_cases i ∈ s <;> simp [field, splitCenterBox, *] <;> ring /-- Let `p` be a predicate on `Box ΞΉ`, let `I` be a box. Suppose that the following two properties hold true. * `H_ind` : Consider a smaller box `J ≀ I`. The hyperplanes passing through the center of `J` split it into `2 ^ n` boxes. If `p` holds true on each of these boxes, then it true on `J`. * `H_nhds` : For each `z` in the closed box `I.Icc` there exists a neighborhood `U` of `z` within `I.Icc` such that for every box `J ≀ I` such that `z ∈ J.Icc βŠ† U`, if `J` is homothetic to `I` with a coefficient of the form `1 / 2 ^ m`, then `p` is true on `J`. Then `p I` is true. See also `BoxIntegral.Box.subbox_induction_on` for a version using `BoxIntegral.Prepartition.splitCenter` instead of `BoxIntegral.Box.splitCenterBox`. The proof still works if we assume `H_ind` only for subboxes `J ≀ I` that are homothetic to `I` with a coefficient of the form `2⁻ᡐ` but we do not need this generalization yet. -/ @[elab_as_elim] theorem subbox_induction_on' {p : Box ΞΉ β†’ Prop} (I : Box ΞΉ) (H_ind : βˆ€ J ≀ I, (βˆ€ s, p (splitCenterBox J s)) β†’ p J) (H_nhds : βˆ€ z ∈ Box.Icc I, βˆƒ U ∈ 𝓝[Box.Icc I] z, βˆ€ J ≀ I, βˆ€ (m : β„•), z ∈ Box.Icc J β†’ Box.Icc J βŠ† U β†’ (βˆ€ i, J.upper i - J.lower i = (I.upper i - I.lower i) / 2 ^ m) β†’ p J) : p I := by by_contra hpI -- First we use `H_ind` to construct a decreasing sequence of boxes such that `βˆ€ m, Β¬p (J m)`. replace H_ind := fun J hJ ↦ not_imp_not.2 (H_ind J hJ) simp only [not_forall] at H_ind choose! s hs using H_ind set J : β„• β†’ Box ΞΉ := fun m ↦ (fun J ↦ splitCenterBox J (s J))^[m] I have J_succ : βˆ€ m, J (m + 1) = splitCenterBox (J m) (s <| J m) := fun m ↦ iterate_succ_apply' _ _ _ -- Now we prove some properties of `J` have hJmono : Antitone J := antitone_nat_of_succ_le fun n ↦ by simpa [J_succ] using splitCenterBox_le _ _ have hJle (m) : J m ≀ I := hJmono (zero_le m) have hJp (m) : Β¬p (J m) := Nat.recOn m hpI fun m ↦ by simpa only [J_succ] using hs (J m) (hJle m) have hJsub (m i) : (J m).upper i - (J m).lower i = (I.upper i - I.lower i) / 2 ^ m := by induction m with | zero => simp [J] | succ m ihm => simp only [pow_succ, J_succ, upper_sub_lower_splitCenterBox, ihm, div_div] have h0 : J 0 = I := rfl clear_value J clear hpI hs J_succ s -- Let `z` be the unique common point of all `(J m).Icc`. Then `H_nhds` proves `p (J m)` for -- sufficiently large `m`. This contradicts `hJp`. set z : ΞΉ β†’ ℝ := ⨆ m, (J m).lower have hzJ : βˆ€ m, z ∈ Box.Icc (J m) := mem_iInter.1 (ciSup_mem_iInter_Icc_of_antitone_Icc ((@Box.Icc ΞΉ).monotone.comp_antitone hJmono) fun m ↦ (J m).lower_le_upper) have hJl_mem : βˆ€ m, (J m).lower ∈ Box.Icc I := fun m ↦ le_iff_Icc.1 (hJle m) (J m).lower_mem_Icc have hJu_mem : βˆ€ m, (J m).upper ∈ Box.Icc I := fun m ↦ le_iff_Icc.1 (hJle m) (J m).upper_mem_Icc have hJlz : Tendsto (fun m ↦ (J m).lower) atTop (𝓝 z) := tendsto_atTop_ciSup (antitone_lower.comp hJmono) ⟨I.upper, fun x ⟨m, hm⟩ ↦ hm β–Έ (hJl_mem m).2⟩ have hJuz : Tendsto (fun m ↦ (J m).upper) atTop (𝓝 z) := by suffices Tendsto (fun m ↦ (J m).upper - (J m).lower) atTop (𝓝 0) by simpa using hJlz.add this refine tendsto_pi_nhds.2 fun i ↦ ?_ simpa [hJsub] using tendsto_const_nhds.div_atTop (tendsto_pow_atTop_atTop_of_one_lt _root_.one_lt_two) replace hJlz : Tendsto (fun m ↦ (J m).lower) atTop (𝓝[Icc I.lower I.upper] z) := tendsto_nhdsWithin_of_tendsto_nhds_of_eventually_within _ hJlz (Eventually.of_forall hJl_mem) replace hJuz : Tendsto (fun m ↦ (J m).upper) atTop (𝓝[Icc I.lower I.upper] z) := tendsto_nhdsWithin_of_tendsto_nhds_of_eventually_within _ hJuz (Eventually.of_forall hJu_mem) rcases H_nhds z (h0 β–Έ hzJ 0) with ⟨U, hUz, hU⟩ rcases (tendsto_lift'.1 (hJlz.Icc hJuz) U hUz).exists with ⟨m, hUm⟩ exact hJp m (hU (J m) (hJle m) m (hzJ m) hUm (hJsub m)) end Box end BoxIntegral
.lake/packages/mathlib/Mathlib/Analysis/BoxIntegral/Partition/Tagged.lean
import Mathlib.Analysis.BoxIntegral.Partition.Basic /-! # Tagged partitions A tagged (pre)partition is a (pre)partition `Ο€` enriched with a tagged point for each box of `Ο€`. For simplicity we require that the function `BoxIntegral.TaggedPrepartition.tag` is defined on all boxes `J : Box ΞΉ` but use its values only on boxes of the partition. Given `Ο€ : BoxIntegral.TaggedPrepartition I`, we require that each `BoxIntegral.TaggedPrepartition Ο€ J` belongs to `BoxIntegral.Box.Icc I`. If for every `J ∈ Ο€`, `Ο€.tag J` belongs to `J.Icc`, then `Ο€` is called a *Henstock* partition. We do not include this assumption into the definition of a tagged (pre)partition because McShane integral is defined as a limit along tagged partitions without this requirement. ## Tags rectangular box, box partition -/ noncomputable section open Finset Function ENNReal NNReal Set namespace BoxIntegral variable {ΞΉ : Type*} /-- A tagged prepartition is a prepartition enriched with a tagged point for each box of the prepartition. For simplicity we require that `tag` is defined for all boxes in `ΞΉ β†’ ℝ` but we will use only the values of `tag` on the boxes of the partition. -/ structure TaggedPrepartition (I : Box ΞΉ) extends Prepartition I where /-- Choice of tagged point of each box in this prepartition: we extend this to a total function, on all boxes in `ΞΉ β†’ ℝ`. -/ tag : Box ΞΉ β†’ ΞΉ β†’ ℝ /-- Each tagged point belongs to `I` -/ tag_mem_Icc : βˆ€ J, tag J ∈ Box.Icc I namespace TaggedPrepartition variable {I J J₁ Jβ‚‚ : Box ΞΉ} (Ο€ : TaggedPrepartition I) {x : ΞΉ β†’ ℝ} instance : Membership (Box ΞΉ) (TaggedPrepartition I) := ⟨fun Ο€ J => J ∈ Ο€.boxes⟩ @[simp] theorem mem_toPrepartition {Ο€ : TaggedPrepartition I} : J ∈ Ο€.toPrepartition ↔ J ∈ Ο€ := Iff.rfl @[simp] theorem mem_mk (Ο€ : Prepartition I) (f h) : J ∈ mk Ο€ f h ↔ J ∈ Ο€ := Iff.rfl /-- Union of all boxes of a tagged prepartition. -/ def iUnion : Set (ΞΉ β†’ ℝ) := Ο€.toPrepartition.iUnion theorem iUnion_def : Ο€.iUnion = ⋃ J ∈ Ο€, ↑J := rfl @[simp] theorem iUnion_mk (Ο€ : Prepartition I) (f h) : (mk Ο€ f h).iUnion = Ο€.iUnion := rfl @[simp] theorem iUnion_toPrepartition : Ο€.toPrepartition.iUnion = Ο€.iUnion := rfl @[simp] theorem mem_iUnion : x ∈ Ο€.iUnion ↔ βˆƒ J ∈ Ο€, x ∈ J := by convert Set.mem_iUnionβ‚‚ rw [Box.mem_coe, mem_toPrepartition, exists_prop] theorem subset_iUnion (h : J ∈ Ο€) : ↑J βŠ† Ο€.iUnion := subset_biUnion_of_mem h theorem iUnion_subset : Ο€.iUnion βŠ† I := iUnionβ‚‚_subset Ο€.le_of_mem' /-- A tagged prepartition is a partition if it covers the whole box. -/ def IsPartition := Ο€.toPrepartition.IsPartition theorem isPartition_iff_iUnion_eq : IsPartition Ο€ ↔ Ο€.iUnion = I := Prepartition.isPartition_iff_iUnion_eq /-- The tagged partition made of boxes of `Ο€` that satisfy predicate `p`. -/ @[simps! -fullyApplied] def filter (p : Box ΞΉ β†’ Prop) : TaggedPrepartition I := βŸ¨Ο€.1.filter p, Ο€.2, Ο€.3⟩ @[simp] theorem mem_filter {p : Box ΞΉ β†’ Prop} : J ∈ Ο€.filter p ↔ J ∈ Ο€ ∧ p J := by classical exact Finset.mem_filter @[simp] theorem iUnion_filter_not (Ο€ : TaggedPrepartition I) (p : Box ΞΉ β†’ Prop) : (Ο€.filter fun J => Β¬p J).iUnion = Ο€.iUnion \ (Ο€.filter p).iUnion := Ο€.toPrepartition.iUnion_filter_not p end TaggedPrepartition namespace Prepartition variable {I J : Box ΞΉ} /-- Given a partition `Ο€` of `I : BoxIntegral.Box ΞΉ` and a collection of tagged partitions `Ο€i J` of all boxes `J ∈ Ο€`, returns the tagged partition of `I` into all the boxes of `Ο€i J` with tags coming from `(Ο€i J).tag`. -/ def biUnionTagged (Ο€ : Prepartition I) (Ο€i : βˆ€ J : Box ΞΉ, TaggedPrepartition J) : TaggedPrepartition I where toPrepartition := Ο€.biUnion fun J => (Ο€i J).toPrepartition tag J := (Ο€i (Ο€.biUnionIndex (fun J => (Ο€i J).toPrepartition) J)).tag J tag_mem_Icc _ := Box.le_iff_Icc.1 (Ο€.biUnionIndex_le _ _) ((Ο€i _).tag_mem_Icc _) @[simp] theorem mem_biUnionTagged (Ο€ : Prepartition I) {Ο€i : βˆ€ J, TaggedPrepartition J} : J ∈ Ο€.biUnionTagged Ο€i ↔ βˆƒ J' ∈ Ο€, J ∈ Ο€i J' := Ο€.mem_biUnion theorem tag_biUnionTagged (Ο€ : Prepartition I) {Ο€i : βˆ€ J, TaggedPrepartition J} (hJ : J ∈ Ο€) {J'} (hJ' : J' ∈ Ο€i J) : (Ο€.biUnionTagged Ο€i).tag J' = (Ο€i J).tag J' := by rw [← Ο€.biUnionIndex_of_mem (Ο€i := fun J => (Ο€i J).toPrepartition) hJ hJ'] rfl @[simp] theorem iUnion_biUnionTagged (Ο€ : Prepartition I) (Ο€i : βˆ€ J, TaggedPrepartition J) : (Ο€.biUnionTagged Ο€i).iUnion = ⋃ J ∈ Ο€, (Ο€i J).iUnion := iUnion_biUnion _ _ theorem forall_biUnionTagged (p : (ΞΉ β†’ ℝ) β†’ Box ΞΉ β†’ Prop) (Ο€ : Prepartition I) (Ο€i : βˆ€ J, TaggedPrepartition J) : (βˆ€ J ∈ Ο€.biUnionTagged Ο€i, p ((Ο€.biUnionTagged Ο€i).tag J) J) ↔ βˆ€ J ∈ Ο€, βˆ€ J' ∈ Ο€i J, p ((Ο€i J).tag J') J' := by simp only [mem_biUnionTagged] refine ⟨fun H J hJ J' hJ' => ?_, fun H J' ⟨J, hJ, hJ'⟩ => ?_⟩ Β· rw [← Ο€.tag_biUnionTagged hJ hJ'] exact H J' ⟨J, hJ, hJ'⟩ Β· rw [Ο€.tag_biUnionTagged hJ hJ'] exact H J hJ J' hJ' theorem IsPartition.biUnionTagged {Ο€ : Prepartition I} (h : IsPartition Ο€) {Ο€i : βˆ€ J, TaggedPrepartition J} (hi : βˆ€ J ∈ Ο€, (Ο€i J).IsPartition) : (Ο€.biUnionTagged Ο€i).IsPartition := h.biUnion hi end Prepartition namespace TaggedPrepartition variable {I J : Box ΞΉ} {Ο€ π₁ Ο€β‚‚ : TaggedPrepartition I} {x : ΞΉ β†’ ℝ} /-- Given a tagged partition `Ο€` of `I` and a (not tagged) partition `Ο€i J hJ` of each `J ∈ Ο€`, returns the tagged partition of `I` into all the boxes of all `Ο€i J hJ`. The tag of a box `J` is defined to be the `Ο€.tag` of the box of the partition `Ο€` that includes `J`. Note that usually the result is not a Henstock partition. -/ @[simps -fullyApplied tag] def biUnionPrepartition (Ο€ : TaggedPrepartition I) (Ο€i : βˆ€ J : Box ΞΉ, Prepartition J) : TaggedPrepartition I where toPrepartition := Ο€.toPrepartition.biUnion Ο€i tag J := Ο€.tag (Ο€.toPrepartition.biUnionIndex Ο€i J) tag_mem_Icc _ := Ο€.tag_mem_Icc _ theorem IsPartition.biUnionPrepartition {Ο€ : TaggedPrepartition I} (h : IsPartition Ο€) {Ο€i : βˆ€ J, Prepartition J} (hi : βˆ€ J ∈ Ο€, (Ο€i J).IsPartition) : (Ο€.biUnionPrepartition Ο€i).IsPartition := h.biUnion hi /-- Given two partitions `π₁` and `π₁`, one of them tagged and the other is not, returns the tagged partition with `toPrepartition = π₁.toPrepartition βŠ“ Ο€β‚‚` and tags coming from `π₁`. Note that usually the result is not a Henstock partition. -/ def infPrepartition (Ο€ : TaggedPrepartition I) (Ο€' : Prepartition I) : TaggedPrepartition I := Ο€.biUnionPrepartition fun J => Ο€'.restrict J @[simp] theorem infPrepartition_toPrepartition (Ο€ : TaggedPrepartition I) (Ο€' : Prepartition I) : (Ο€.infPrepartition Ο€').toPrepartition = Ο€.toPrepartition βŠ“ Ο€' := rfl theorem mem_infPrepartition_comm : J ∈ π₁.infPrepartition Ο€β‚‚.toPrepartition ↔ J ∈ Ο€β‚‚.infPrepartition π₁.toPrepartition := by simp only [← mem_toPrepartition, infPrepartition_toPrepartition, inf_comm] theorem IsPartition.infPrepartition (h₁ : π₁.IsPartition) {Ο€β‚‚ : Prepartition I} (hβ‚‚ : Ο€β‚‚.IsPartition) : (π₁.infPrepartition Ο€β‚‚).IsPartition := h₁.inf hβ‚‚ open Metric /-- A tagged partition is said to be a Henstock partition if for each `J ∈ Ο€`, the tag of `J` belongs to `J.Icc`. -/ def IsHenstock (Ο€ : TaggedPrepartition I) : Prop := βˆ€ J ∈ Ο€, Ο€.tag J ∈ Box.Icc J @[simp] theorem isHenstock_biUnionTagged {Ο€ : Prepartition I} {Ο€i : βˆ€ J, TaggedPrepartition J} : IsHenstock (Ο€.biUnionTagged Ο€i) ↔ βˆ€ J ∈ Ο€, (Ο€i J).IsHenstock := Ο€.forall_biUnionTagged (fun x J => x ∈ Box.Icc J) Ο€i /-- In a Henstock prepartition, there are at most `2 ^ Fintype.card ΞΉ` boxes with a given tag. -/ theorem IsHenstock.card_filter_tag_eq_le [Fintype ΞΉ] (h : Ο€.IsHenstock) (x : ΞΉ β†’ ℝ) : #{J ∈ Ο€.boxes | Ο€.tag J = x} ≀ 2 ^ Fintype.card ΞΉ := by classical calc #{J ∈ Ο€.boxes | Ο€.tag J = x} ≀ #{J ∈ Ο€.boxes | x ∈ Box.Icc J} := by refine Finset.card_le_card fun J hJ => ?_ rw [Finset.mem_filter] at hJ ⊒; rcases hJ with ⟨hJ, rfl⟩ exact ⟨hJ, h J hJ⟩ _ ≀ 2 ^ Fintype.card ΞΉ := Ο€.toPrepartition.card_filter_mem_Icc_le x /-- A tagged partition `Ο€` is subordinate to `r : (ΞΉ β†’ ℝ) β†’ ℝ` if each box `J ∈ Ο€` is included in the closed ball with center `Ο€.tag J` and radius `r (Ο€.tag J)`. -/ def IsSubordinate [Fintype ΞΉ] (Ο€ : TaggedPrepartition I) (r : (ΞΉ β†’ ℝ) β†’ Ioi (0 : ℝ)) : Prop := βˆ€ J ∈ Ο€, Box.Icc J βŠ† closedBall (Ο€.tag J) (r <| Ο€.tag J) variable {r r₁ rβ‚‚ : (ΞΉ β†’ ℝ) β†’ Ioi (0 : ℝ)} @[simp] theorem isSubordinate_biUnionTagged [Fintype ΞΉ] {Ο€ : Prepartition I} {Ο€i : βˆ€ J, TaggedPrepartition J} : IsSubordinate (Ο€.biUnionTagged Ο€i) r ↔ βˆ€ J ∈ Ο€, (Ο€i J).IsSubordinate r := Ο€.forall_biUnionTagged (fun x J => Box.Icc J βŠ† closedBall x (r x)) Ο€i theorem IsSubordinate.biUnionPrepartition [Fintype ΞΉ] (h : IsSubordinate Ο€ r) (Ο€i : βˆ€ J, Prepartition J) : IsSubordinate (Ο€.biUnionPrepartition Ο€i) r := fun _ hJ => Subset.trans (Box.le_iff_Icc.1 <| Ο€.toPrepartition.le_biUnionIndex hJ) <| h _ <| Ο€.toPrepartition.biUnionIndex_mem hJ theorem IsSubordinate.infPrepartition [Fintype ΞΉ] (h : IsSubordinate Ο€ r) (Ο€' : Prepartition I) : IsSubordinate (Ο€.infPrepartition Ο€') r := h.biUnionPrepartition _ theorem IsSubordinate.mono' [Fintype ΞΉ] {Ο€ : TaggedPrepartition I} (hr₁ : Ο€.IsSubordinate r₁) (h : βˆ€ J ∈ Ο€, r₁ (Ο€.tag J) ≀ rβ‚‚ (Ο€.tag J)) : Ο€.IsSubordinate rβ‚‚ := fun _ hJ _ hx => closedBall_subset_closedBall (h _ hJ) (hr₁ _ hJ hx) theorem IsSubordinate.mono [Fintype ΞΉ] {Ο€ : TaggedPrepartition I} (hr₁ : Ο€.IsSubordinate r₁) (h : βˆ€ x ∈ Box.Icc I, r₁ x ≀ rβ‚‚ x) : Ο€.IsSubordinate rβ‚‚ := hr₁.mono' fun J _ => h _ <| Ο€.tag_mem_Icc J theorem IsSubordinate.diam_le [Fintype ΞΉ] {Ο€ : TaggedPrepartition I} (h : Ο€.IsSubordinate r) (hJ : J ∈ Ο€.boxes) : diam (Box.Icc J) ≀ 2 * r (Ο€.tag J) := calc diam (Box.Icc J) ≀ diam (closedBall (Ο€.tag J) (r <| Ο€.tag J)) := diam_mono (h J hJ) isBounded_closedBall _ ≀ 2 * r (Ο€.tag J) := diam_closedBall (le_of_lt (r _).2) /-- Tagged prepartition with single box and prescribed tag. -/ @[simps! -fullyApplied] def single (I J : Box ΞΉ) (hJ : J ≀ I) (x : ΞΉ β†’ ℝ) (h : x ∈ Box.Icc I) : TaggedPrepartition I := ⟨Prepartition.single I J hJ, fun _ => x, fun _ => h⟩ @[simp] theorem mem_single {J'} (hJ : J ≀ I) (h : x ∈ Box.Icc I) : J' ∈ single I J hJ x h ↔ J' = J := Finset.mem_singleton instance (I : Box ΞΉ) : Inhabited (TaggedPrepartition I) := ⟨single I I le_rfl I.upper I.upper_mem_Icc⟩ theorem isPartition_single_iff (hJ : J ≀ I) (h : x ∈ Box.Icc I) : (single I J hJ x h).IsPartition ↔ J = I := Prepartition.isPartition_single_iff hJ theorem isPartition_single (h : x ∈ Box.Icc I) : (single I I le_rfl x h).IsPartition := Prepartition.isPartitionTop I theorem forall_mem_single (p : (ΞΉ β†’ ℝ) β†’ Box ΞΉ β†’ Prop) (hJ : J ≀ I) (h : x ∈ Box.Icc I) : (βˆ€ J' ∈ single I J hJ x h, p ((single I J hJ x h).tag J') J') ↔ p x J := by simp @[simp] theorem isHenstock_single_iff (hJ : J ≀ I) (h : x ∈ Box.Icc I) : IsHenstock (single I J hJ x h) ↔ x ∈ Box.Icc J := forall_mem_single (fun x J => x ∈ Box.Icc J) hJ h theorem isHenstock_single (h : x ∈ Box.Icc I) : IsHenstock (single I I le_rfl x h) := (isHenstock_single_iff (le_refl I) h).2 h @[simp] theorem isSubordinate_single [Fintype ΞΉ] (hJ : J ≀ I) (h : x ∈ Box.Icc I) : IsSubordinate (single I J hJ x h) r ↔ Box.Icc J βŠ† closedBall x (r x) := forall_mem_single (fun x J => Box.Icc J βŠ† closedBall x (r x)) hJ h @[simp] theorem iUnion_single (hJ : J ≀ I) (h : x ∈ Box.Icc I) : (single I J hJ x h).iUnion = J := Prepartition.iUnion_single hJ open scoped Classical in /-- Union of two tagged prepartitions with disjoint unions of boxes. -/ def disjUnion (π₁ Ο€β‚‚ : TaggedPrepartition I) (h : Disjoint π₁.iUnion Ο€β‚‚.iUnion) : TaggedPrepartition I where toPrepartition := π₁.toPrepartition.disjUnion Ο€β‚‚.toPrepartition h tag := π₁.boxes.piecewise π₁.tag Ο€β‚‚.tag tag_mem_Icc J := by dsimp only [Finset.piecewise] split_ifs exacts [π₁.tag_mem_Icc J, Ο€β‚‚.tag_mem_Icc J] open scoped Classical in @[simp] theorem disjUnion_boxes (h : Disjoint π₁.iUnion Ο€β‚‚.iUnion) : (π₁.disjUnion Ο€β‚‚ h).boxes = π₁.boxes βˆͺ Ο€β‚‚.boxes := rfl @[simp] theorem mem_disjUnion (h : Disjoint π₁.iUnion Ο€β‚‚.iUnion) : J ∈ π₁.disjUnion Ο€β‚‚ h ↔ J ∈ π₁ ∨ J ∈ Ο€β‚‚ := by classical exact Finset.mem_union @[simp] theorem iUnion_disjUnion (h : Disjoint π₁.iUnion Ο€β‚‚.iUnion) : (π₁.disjUnion Ο€β‚‚ h).iUnion = π₁.iUnion βˆͺ Ο€β‚‚.iUnion := Prepartition.iUnion_disjUnion h theorem disjUnion_tag_of_mem_left (h : Disjoint π₁.iUnion Ο€β‚‚.iUnion) (hJ : J ∈ π₁) : (π₁.disjUnion Ο€β‚‚ h).tag J = π₁.tag J := dif_pos hJ theorem disjUnion_tag_of_mem_right (h : Disjoint π₁.iUnion Ο€β‚‚.iUnion) (hJ : J ∈ Ο€β‚‚) : (π₁.disjUnion Ο€β‚‚ h).tag J = Ο€β‚‚.tag J := dif_neg fun h₁ => h.le_bot βŸ¨Ο€β‚.subset_iUnion h₁ J.upper_mem, Ο€β‚‚.subset_iUnion hJ J.upper_mem⟩ theorem IsSubordinate.disjUnion [Fintype ΞΉ] (h₁ : IsSubordinate π₁ r) (hβ‚‚ : IsSubordinate Ο€β‚‚ r) (h : Disjoint π₁.iUnion Ο€β‚‚.iUnion) : IsSubordinate (π₁.disjUnion Ο€β‚‚ h) r := by classical refine fun J hJ => (Finset.mem_union.1 hJ).elim (fun hJ => ?_) fun hJ => ?_ Β· rw [disjUnion_tag_of_mem_left _ hJ] exact h₁ _ hJ Β· rw [disjUnion_tag_of_mem_right _ hJ] exact hβ‚‚ _ hJ theorem IsHenstock.disjUnion (h₁ : IsHenstock π₁) (hβ‚‚ : IsHenstock Ο€β‚‚) (h : Disjoint π₁.iUnion Ο€β‚‚.iUnion) : IsHenstock (π₁.disjUnion Ο€β‚‚ h) := by classical refine fun J hJ => (Finset.mem_union.1 hJ).elim (fun hJ => ?_) fun hJ => ?_ Β· rw [disjUnion_tag_of_mem_left _ hJ] exact h₁ _ hJ Β· rw [disjUnion_tag_of_mem_right _ hJ] exact hβ‚‚ _ hJ /-- If `I ≀ J`, then every tagged prepartition of `I` is a tagged prepartition of `J`. -/ def embedBox (I J : Box ΞΉ) (h : I ≀ J) : TaggedPrepartition I β†ͺ TaggedPrepartition J where toFun Ο€ := { Ο€ with le_of_mem' := fun J' hJ' => (Ο€.le_of_mem' J' hJ').trans h tag_mem_Icc := fun J => Box.le_iff_Icc.1 h (Ο€.tag_mem_Icc J) } inj' := by rintro ⟨⟨b₁, h₁le, h₁d⟩, t₁, htβ‚βŸ© ⟨⟨bβ‚‚, hβ‚‚le, hβ‚‚d⟩, tβ‚‚, htβ‚‚βŸ© H simpa using H section Distortion variable [Fintype ΞΉ] (Ο€) open Finset /-- The distortion of a tagged prepartition is the maximum of distortions of its boxes. -/ def distortion : ℝβ‰₯0 := Ο€.toPrepartition.distortion theorem distortion_le_of_mem (h : J ∈ Ο€) : J.distortion ≀ Ο€.distortion := le_sup h theorem distortion_le_iff {c : ℝβ‰₯0} : Ο€.distortion ≀ c ↔ βˆ€ J ∈ Ο€, Box.distortion J ≀ c := Finset.sup_le_iff @[simp] theorem _root_.BoxIntegral.Prepartition.distortion_biUnionTagged (Ο€ : Prepartition I) (Ο€i : βˆ€ J, TaggedPrepartition J) : (Ο€.biUnionTagged Ο€i).distortion = Ο€.boxes.sup fun J => (Ο€i J).distortion := by classical exact sup_biUnion _ _ @[simp] theorem distortion_biUnionPrepartition (Ο€ : TaggedPrepartition I) (Ο€i : βˆ€ J, Prepartition J) : (Ο€.biUnionPrepartition Ο€i).distortion = Ο€.boxes.sup fun J => (Ο€i J).distortion := by classical exact sup_biUnion _ _ @[simp] theorem distortion_disjUnion (h : Disjoint π₁.iUnion Ο€β‚‚.iUnion) : (π₁.disjUnion Ο€β‚‚ h).distortion = max π₁.distortion Ο€β‚‚.distortion := by classical exact sup_union theorem distortion_of_const {c} (h₁ : Ο€.boxes.Nonempty) (hβ‚‚ : βˆ€ J ∈ Ο€, Box.distortion J = c) : Ο€.distortion = c := (sup_congr rfl hβ‚‚).trans (sup_const h₁ _) @[simp] theorem distortion_single (hJ : J ≀ I) (h : x ∈ Box.Icc I) : distortion (single I J hJ x h) = J.distortion := sup_singleton theorem distortion_filter_le (p : Box ΞΉ β†’ Prop) : (Ο€.filter p).distortion ≀ Ο€.distortion := by classical exact sup_mono (filter_subset _ _) end Distortion end TaggedPrepartition end BoxIntegral
.lake/packages/mathlib/Mathlib/Analysis/BoxIntegral/Partition/Additive.lean
import Mathlib.Analysis.BoxIntegral.Partition.Split import Mathlib.Analysis.Normed.Operator.Mul /-! # Box additive functions We say that a function `f : Box ΞΉ β†’ M` from boxes in `ℝⁿ` to a commutative additive monoid `M` is *box additive* on subboxes of `Iβ‚€ : WithTop (Box ΞΉ)` if for any box `J`, `↑J ≀ Iβ‚€`, and a partition `Ο€` of `J`, `f J = βˆ‘ J' ∈ Ο€.boxes, f J'`. We use `Iβ‚€ : WithTop (Box ΞΉ)` instead of `Iβ‚€ : Box ΞΉ` to use the same definition for functions box additive on subboxes of a box and for functions box additive on all boxes. Examples of box-additive functions include the measure of a box and the integral of a fixed integrable function over a box. In this file we define box-additive functions and prove that a function such that `f J = f (J ∩ {x | x i < y}) + f (J ∩ {x | y ≀ x i})` is box-additive. ## Tags rectangular box, additive function -/ noncomputable section open Function Set namespace BoxIntegral variable {ΞΉ M : Type*} {n : β„•} /-- A function on `Box ΞΉ` is called box additive if for every box `J` and a partition `Ο€` of `J` we have `f J = βˆ‘ Ji ∈ Ο€.boxes, f Ji`. A function is called box additive on subboxes of `I : Box ΞΉ` if the same property holds for `J ≀ I`. We formalize these two notions in the same definition using `I : WithBot (Box ΞΉ)`: the value `I = ⊀` corresponds to functions box additive on the whole space. -/ structure BoxAdditiveMap (ΞΉ M : Type*) [AddCommMonoid M] (I : WithTop (Box ΞΉ)) where /-- The function underlying this additive map. -/ toFun : Box ΞΉ β†’ M sum_partition_boxes' : βˆ€ J : Box ΞΉ, ↑J ≀ I β†’ βˆ€ Ο€ : Prepartition J, Ο€.IsPartition β†’ βˆ‘ Ji ∈ Ο€.boxes, toFun Ji = toFun J /-- A function on `Box ΞΉ` is called box additive if for every box `J` and a partition `Ο€` of `J` we have `f J = βˆ‘ Ji ∈ Ο€.boxes, f Ji`. -/ scoped notation:25 ΞΉ " →ᡇᡃ " M => BoxIntegral.BoxAdditiveMap ΞΉ M ⊀ @[inherit_doc] scoped notation:25 ΞΉ " →ᡇᡃ[" I "] " M => BoxIntegral.BoxAdditiveMap ΞΉ M I namespace BoxAdditiveMap open Box Prepartition Finset variable {N : Type*} [AddCommMonoid M] [AddCommMonoid N] {Iβ‚€ : WithTop (Box ΞΉ)} {I : Box ΞΉ} {i : ΞΉ} instance : FunLike (ΞΉ →ᡇᡃ[Iβ‚€] M) (Box ΞΉ) M where coe := toFun coe_injective' f g h := by cases f; cases g; congr initialize_simps_projections BoxIntegral.BoxAdditiveMap (toFun β†’ apply) @[simp] theorem coe_mk (f h) : ⇑(mk f h : ΞΉ →ᡇᡃ[Iβ‚€] M) = f := rfl theorem coe_injective : Injective fun (f : ΞΉ →ᡇᡃ[Iβ‚€] M) x => f x := DFunLike.coe_injective theorem coe_inj {f g : ΞΉ →ᡇᡃ[Iβ‚€] M} : (f : Box ΞΉ β†’ M) = g ↔ f = g := DFunLike.coe_fn_eq theorem sum_partition_boxes (f : ΞΉ →ᡇᡃ[Iβ‚€] M) (hI : ↑I ≀ Iβ‚€) {Ο€ : Prepartition I} (h : Ο€.IsPartition) : βˆ‘ J ∈ Ο€.boxes, f J = f I := f.sum_partition_boxes' I hI Ο€ h @[simps -fullyApplied] instance : Zero (ΞΉ →ᡇᡃ[Iβ‚€] M) := ⟨⟨0, fun _ _ _ _ => sum_const_zero⟩⟩ instance : Inhabited (ΞΉ →ᡇᡃ[Iβ‚€] M) := ⟨0⟩ instance : Add (ΞΉ →ᡇᡃ[Iβ‚€] M) := ⟨fun f g => ⟨f + g, fun I hI Ο€ hΟ€ => by simp only [Pi.add_apply, sum_add_distrib, sum_partition_boxes _ hI hΟ€]⟩⟩ instance {R} [Monoid R] [DistribMulAction R M] : SMul R (ΞΉ →ᡇᡃ[Iβ‚€] M) := ⟨fun r f => ⟨r β€’ (f : Box ΞΉ β†’ M), fun I hI Ο€ hΟ€ => by simp only [Pi.smul_apply, ← smul_sum, sum_partition_boxes _ hI hΟ€]⟩⟩ instance : AddCommMonoid (ΞΉ →ᡇᡃ[Iβ‚€] M) := Function.Injective.addCommMonoid _ coe_injective rfl (fun _ _ => rfl) fun _ _ => rfl @[simp] theorem map_split_add (f : ΞΉ →ᡇᡃ[Iβ‚€] M) (hI : ↑I ≀ Iβ‚€) (i : ΞΉ) (x : ℝ) : (I.splitLower i x).elim' 0 f + (I.splitUpper i x).elim' 0 f = f I := by rw [← f.sum_partition_boxes hI (isPartitionSplit I i x), sum_split_boxes] /-- If `f` is box-additive on subboxes of `Iβ‚€`, then it is box-additive on subboxes of any `I ≀ Iβ‚€`. -/ @[simps] def restrict (f : ΞΉ →ᡇᡃ[Iβ‚€] M) (I : WithTop (Box ΞΉ)) (hI : I ≀ Iβ‚€) : ΞΉ →ᡇᡃ[I] M := ⟨f, fun J hJ => f.2 J (hJ.trans hI)⟩ /-- If `f : Box ΞΉ β†’ M` is box additive on partitions of the form `split I i x`, then it is box additive. -/ def ofMapSplitAdd [Finite ΞΉ] (f : Box ΞΉ β†’ M) (Iβ‚€ : WithTop (Box ΞΉ)) (hf : βˆ€ I : Box ΞΉ, ↑I ≀ Iβ‚€ β†’ βˆ€ {i x}, x ∈ Ioo (I.lower i) (I.upper i) β†’ (I.splitLower i x).elim' 0 f + (I.splitUpper i x).elim' 0 f = f I) : ΞΉ →ᡇᡃ[Iβ‚€] M := by classical refine ⟨f, ?_⟩ replace hf (I : Box ΞΉ) (hI : ↑I ≀ Iβ‚€) (s) : βˆ‘ J ∈ (splitMany I s).boxes, f J = f I := by induction s using Finset.induction_on with | empty => simp | insert a s _ ihs => rw [splitMany_insert, inf_split, ← ihs, biUnion_boxes, sum_biUnion_boxes] refine Finset.sum_congr rfl fun J' hJ' => ?_ by_cases h : a.2 ∈ Ioo (J'.lower a.1) (J'.upper a.1) Β· rw [sum_split_boxes] exact hf _ ((WithTop.coe_le_coe.2 <| le_of_mem _ hJ').trans hI) h Β· rw [split_of_notMem_Ioo h, top_boxes, Finset.sum_singleton] intro I hI Ο€ hΟ€ have Hle : βˆ€ J ∈ Ο€, ↑J ≀ Iβ‚€ := fun J hJ => (WithTop.coe_le_coe.2 <| Ο€.le_of_mem hJ).trans hI rcases hΟ€.exists_splitMany_le with ⟨s, hs⟩ rw [← hf _ hI, ← inf_of_le_right hs, inf_splitMany, biUnion_boxes, sum_biUnion_boxes] exact Finset.sum_congr rfl fun J hJ => (hf _ (Hle _ hJ) _).symm /-- If `g : M β†’ N` is an additive map and `f` is a box additive map, then `g ∘ f` is a box additive map. -/ @[simps -fullyApplied] def map (f : ΞΉ →ᡇᡃ[Iβ‚€] M) (g : M β†’+ N) : ΞΉ →ᡇᡃ[Iβ‚€] N where toFun := g ∘ f sum_partition_boxes' I hI Ο€ hΟ€ := by simp_rw [comp, ← map_sum, f.sum_partition_boxes hI hΟ€] /-- If `f` is a box additive function on subboxes of `I` and `π₁`, `Ο€β‚‚` are two prepartitions of `I` that cover the same part of `I`, then `βˆ‘ J ∈ π₁.boxes, f J = βˆ‘ J ∈ Ο€β‚‚.boxes, f J`. -/ theorem sum_boxes_congr [Finite ΞΉ] (f : ΞΉ →ᡇᡃ[Iβ‚€] M) (hI : ↑I ≀ Iβ‚€) {π₁ Ο€β‚‚ : Prepartition I} (h : π₁.iUnion = Ο€β‚‚.iUnion) : βˆ‘ J ∈ π₁.boxes, f J = βˆ‘ J ∈ Ο€β‚‚.boxes, f J := by rcases exists_splitMany_inf_eq_filter_of_finite {π₁, Ο€β‚‚} ((finite_singleton _).insert _) with ⟨s, hs⟩ simp only [inf_splitMany] at hs rcases hs _ (Or.inl rfl), hs _ (Or.inr rfl) with ⟨h₁, hβ‚‚βŸ©; clear hs rw [h] at h₁ calc βˆ‘ J ∈ π₁.boxes, f J = βˆ‘ J ∈ π₁.boxes, βˆ‘ J' ∈ (splitMany J s).boxes, f J' := Finset.sum_congr rfl fun J hJ => (f.sum_partition_boxes ?_ (isPartition_splitMany _ _)).symm _ = βˆ‘ J ∈ (π₁.biUnion fun J => splitMany J s).boxes, f J := (sum_biUnion_boxes _ _ _).symm _ = βˆ‘ J ∈ (Ο€β‚‚.biUnion fun J => splitMany J s).boxes, f J := by rw [h₁, hβ‚‚] _ = βˆ‘ J ∈ Ο€β‚‚.boxes, βˆ‘ J' ∈ (splitMany J s).boxes, f J' := sum_biUnion_boxes _ _ _ _ = βˆ‘ J ∈ Ο€β‚‚.boxes, f J := Finset.sum_congr rfl fun J hJ => f.sum_partition_boxes ?_ (isPartition_splitMany _ _) exacts [(WithTop.coe_le_coe.2 <| π₁.le_of_mem hJ).trans hI, (WithTop.coe_le_coe.2 <| Ο€β‚‚.le_of_mem hJ).trans hI] section ToSMul variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] /-- If `f` is a box-additive map, then so is the map sending `I` to the scalar multiplication by `f I` as a continuous linear map from `E` to itself. -/ def toSMul (f : ΞΉ →ᡇᡃ[Iβ‚€] ℝ) : ΞΉ →ᡇᡃ[Iβ‚€] E β†’L[ℝ] E := f.map (ContinuousLinearMap.lsmul ℝ ℝ).toLinearMap.toAddMonoidHom @[simp] theorem toSMul_apply (f : ΞΉ →ᡇᡃ[Iβ‚€] ℝ) (I : Box ΞΉ) (x : E) : f.toSMul I x = f I β€’ x := rfl end ToSMul /-- Given a box `Iβ‚€` in `ℝⁿ⁺¹`, `f x : Box (Fin n) β†’ G` is a family of functions indexed by a real `x` and for `x ∈ [Iβ‚€.lower i, Iβ‚€.upper i]`, `f x` is box-additive on subboxes of the `i`-th face of `Iβ‚€`, then `fun J ↦ f (J.upper i) (J.face i) - f (J.lower i) (J.face i)` is box-additive on subboxes of `Iβ‚€`. -/ @[simps!] def upperSubLower.{u} {G : Type u} [AddCommGroup G] (Iβ‚€ : Box (Fin (n + 1))) (i : Fin (n + 1)) (f : ℝ β†’ Box (Fin n) β†’ G) (fb : Icc (Iβ‚€.lower i) (Iβ‚€.upper i) β†’ Fin n →ᡇᡃ[Iβ‚€.face i] G) (hf : βˆ€ (x) (hx : x ∈ Icc (Iβ‚€.lower i) (Iβ‚€.upper i)) (J), f x J = fb ⟨x, hx⟩ J) : Fin (n + 1) →ᡇᡃ[Iβ‚€] G := ofMapSplitAdd (fun J : Box (Fin (n + 1)) => f (J.upper i) (J.face i) - f (J.lower i) (J.face i)) Iβ‚€ (by intro J hJ j x rw [WithTop.coe_le_coe] at hJ refine i.succAboveCases (fun hx => ?_) (fun j hx => ?_) j Β· simp only [Box.splitLower_def hx, Box.splitUpper_def hx, update_self, ← WithBot.some_eq_coe, Option.elim', Box.face, Function.comp_def, update_of_ne (Fin.succAbove_ne _ _)] abel Β· have : (J.face i : WithTop (Box (Fin n))) ≀ Iβ‚€.face i := WithTop.coe_le_coe.2 (face_mono hJ i) rw [le_iff_Icc, @Box.Icc_eq_pi _ Iβ‚€] at hJ simp only rw [hf _ (hJ J.upper_mem_Icc _ trivial), hf _ (hJ J.lower_mem_Icc _ trivial), ← (fb _).map_split_add this j x, ← (fb _).map_split_add this j x] have hx' : x ∈ Ioo ((J.face i).lower j) ((J.face i).upper j) := hx simp only [Box.splitLower_def hx, Box.splitUpper_def hx, Box.splitLower_def hx', Box.splitUpper_def hx', ← WithBot.some_eq_coe, Option.elim', Box.face_mk, update_of_ne (Fin.succAbove_ne _ _).symm, sub_add_sub_comm, update_comp_eq_of_injective _ (Fin.strictMono_succAbove i).injective j x, ← hf] simp only [Box.face]) end BoxAdditiveMap end BoxIntegral
.lake/packages/mathlib/Mathlib/Analysis/BoxIntegral/Partition/Split.lean
import Mathlib.Analysis.BoxIntegral.Partition.Basic /-! # Split a box along one or more hyperplanes ## Main definitions A hyperplane `{x : ΞΉ β†’ ℝ | x i = a}` splits a rectangular box `I : BoxIntegral.Box ΞΉ` into two smaller boxes. If `a βˆ‰ Ioo (I.lower i, I.upper i)`, then one of these boxes is empty, so it is not a box in the sense of `BoxIntegral.Box`. We introduce the following definitions. * `BoxIntegral.Box.splitLower I i a` and `BoxIntegral.Box.splitUpper I i a` are these boxes (as `WithBot (BoxIntegral.Box ΞΉ)`); * `BoxIntegral.Prepartition.split I i a` is the partition of `I` made of these two boxes (or of one box `I` if one of these boxes is empty); * `BoxIntegral.Prepartition.splitMany I s`, where `s : Finset (ΞΉ Γ— ℝ)` is a finite set of hyperplanes `{x : ΞΉ β†’ ℝ | x i = a}` encoded as pairs `(i, a)`, is the partition of `I` made by cutting it along all the hyperplanes in `s`. ## Main results The main result `BoxIntegral.Prepartition.exists_iUnion_eq_diff` says that any prepartition `Ο€` of `I` admits a prepartition `Ο€'` of `I` that covers exactly `I \ Ο€.iUnion`. One of these prepartitions is available as `BoxIntegral.Prepartition.compl`. ## Tags rectangular box, partition, hyperplane -/ noncomputable section open Function Set Filter namespace BoxIntegral variable {ΞΉ M : Type*} {n : β„•} namespace Box variable {I : Box ΞΉ} {i : ΞΉ} {x : ℝ} {y : ΞΉ β†’ ℝ} open scoped Classical in /-- Given a box `I` and `x ∈ (I.lower i, I.upper i)`, the hyperplane `{y : ΞΉ β†’ ℝ | y i = x}` splits `I` into two boxes. `BoxIntegral.Box.splitLower I i x` is the box `I ∩ {y | y i ≀ x}` (if it is nonempty). As usual, we represent a box that may be empty as `WithBot (BoxIntegral.Box ΞΉ)`. -/ def splitLower (I : Box ΞΉ) (i : ΞΉ) (x : ℝ) : WithBot (Box ΞΉ) := mk' I.lower (update I.upper i (min x (I.upper i))) @[simp] theorem coe_splitLower : (splitLower I i x : Set (ΞΉ β†’ ℝ)) = ↑I ∩ { y | y i ≀ x } := by rw [splitLower, coe_mk'] ext y simp only [mem_univ_pi, mem_Ioc, mem_inter_iff, mem_coe, mem_setOf_eq, forall_and, ← Pi.le_def, le_update_iff, le_min_iff, and_assoc, and_forall_ne (p := fun j => y j ≀ upper I j) i, mem_def] rw [and_comm (a := y i ≀ x)] theorem splitLower_le : I.splitLower i x ≀ I := withBotCoe_subset_iff.1 <| by simp @[simp] theorem splitLower_eq_bot {i x} : I.splitLower i x = βŠ₯ ↔ x ≀ I.lower i := by classical rw [splitLower, mk'_eq_bot, exists_update_iff I.upper fun j y => y ≀ I.lower j] simp [(I.lower_lt_upper _).not_ge] @[simp] theorem splitLower_eq_self : I.splitLower i x = I ↔ I.upper i ≀ x := by simp [splitLower] theorem splitLower_def [DecidableEq ΞΉ] {i x} (h : x ∈ Ioo (I.lower i) (I.upper i)) (h' : βˆ€ j, I.lower j < update I.upper i x j := (forall_update_iff I.upper fun j y => I.lower j < y).2 ⟨h.1, fun _ _ => I.lower_lt_upper _⟩) : I.splitLower i x = (⟨I.lower, update I.upper i x, h'⟩ : Box ΞΉ) := by simp +unfoldPartialApp only [splitLower, mk'_eq_coe, min_eq_left h.2.le, update, and_self] open scoped Classical in /-- Given a box `I` and `x ∈ (I.lower i, I.upper i)`, the hyperplane `{y : ΞΉ β†’ ℝ | y i = x}` splits `I` into two boxes. `BoxIntegral.Box.splitUpper I i x` is the box `I ∩ {y | x < y i}` (if it is nonempty). As usual, we represent a box that may be empty as `WithBot (BoxIntegral.Box ΞΉ)`. -/ def splitUpper (I : Box ΞΉ) (i : ΞΉ) (x : ℝ) : WithBot (Box ΞΉ) := mk' (update I.lower i (max x (I.lower i))) I.upper @[simp] theorem coe_splitUpper : (splitUpper I i x : Set (ΞΉ β†’ ℝ)) = ↑I ∩ { y | x < y i } := by classical rw [splitUpper, coe_mk'] ext y simp only [mem_univ_pi, mem_Ioc, mem_inter_iff, mem_coe, mem_setOf_eq, forall_and, forall_update_iff I.lower fun j z => z < y j, max_lt_iff, and_assoc (a := x < y i), and_forall_ne (p := fun j => lower I j < y j) i, mem_def] exact and_comm theorem splitUpper_le : I.splitUpper i x ≀ I := withBotCoe_subset_iff.1 <| by simp @[simp] theorem splitUpper_eq_bot {i x} : I.splitUpper i x = βŠ₯ ↔ I.upper i ≀ x := by classical rw [splitUpper, mk'_eq_bot, exists_update_iff I.lower fun j y => I.upper j ≀ y] simp [(I.lower_lt_upper _).not_ge] @[simp] theorem splitUpper_eq_self : I.splitUpper i x = I ↔ x ≀ I.lower i := by simp [splitUpper] theorem splitUpper_def [DecidableEq ΞΉ] {i x} (h : x ∈ Ioo (I.lower i) (I.upper i)) (h' : βˆ€ j, update I.lower i x j < I.upper j := (forall_update_iff I.lower fun j y => y < I.upper j).2 ⟨h.2, fun _ _ => I.lower_lt_upper _⟩) : I.splitUpper i x = (⟨update I.lower i x, I.upper, h'⟩ : Box ΞΉ) := by simp +unfoldPartialApp only [splitUpper, mk'_eq_coe, max_eq_left h.1.le, update, and_self] theorem disjoint_splitLower_splitUpper (I : Box ΞΉ) (i : ΞΉ) (x : ℝ) : Disjoint (I.splitLower i x) (I.splitUpper i x) := by rw [← disjoint_withBotCoe, coe_splitLower, coe_splitUpper] refine (Disjoint.inf_left' _ ?_).inf_right' _ rw [Set.disjoint_left] exact fun y (hle : y i ≀ x) hlt => not_lt_of_ge hle hlt theorem splitLower_ne_splitUpper (I : Box ΞΉ) (i : ΞΉ) (x : ℝ) : I.splitLower i x β‰  I.splitUpper i x := by rcases le_or_gt x (I.lower i) with h | _ Β· rw [splitUpper_eq_self.2 h, splitLower_eq_bot.2 h] exact WithBot.bot_ne_coe Β· refine (disjoint_splitLower_splitUpper I i x).ne ?_ rwa [Ne, splitLower_eq_bot, not_le] end Box namespace Prepartition variable {I J : Box ΞΉ} {i : ΞΉ} {x : ℝ} open scoped Classical in /-- The partition of `I : Box ΞΉ` into the boxes `I ∩ {y | y ≀ x i}` and `I ∩ {y | x i < y}`. One of these boxes can be empty, then this partition is just the single-box partition `⊀`. -/ def split (I : Box ΞΉ) (i : ΞΉ) (x : ℝ) : Prepartition I := ofWithBot {I.splitLower i x, I.splitUpper i x} (by simp only [Finset.mem_insert, Finset.mem_singleton] rintro J (rfl | rfl) exacts [Box.splitLower_le, Box.splitUpper_le]) (by simp only [Finset.coe_insert, Finset.coe_singleton, true_and, Set.mem_singleton_iff, pairwise_insert_of_symmetric symmetric_disjoint, pairwise_singleton] rintro J rfl - exact I.disjoint_splitLower_splitUpper i x) @[simp] theorem mem_split_iff : J ∈ split I i x ↔ ↑J = I.splitLower i x ∨ ↑J = I.splitUpper i x := by simp [split] theorem mem_split_iff' : J ∈ split I i x ↔ (J : Set (ΞΉ β†’ ℝ)) = ↑I ∩ { y | y i ≀ x } ∨ (J : Set (ΞΉ β†’ ℝ)) = ↑I ∩ { y | x < y i } := by simp [mem_split_iff, ← Box.withBotCoe_inj] @[simp] theorem iUnion_split (I : Box ΞΉ) (i : ΞΉ) (x : ℝ) : (split I i x).iUnion = I := by simp [split, ← inter_union_distrib_left, ← setOf_or, le_or_gt] theorem isPartitionSplit (I : Box ΞΉ) (i : ΞΉ) (x : ℝ) : IsPartition (split I i x) := isPartition_iff_iUnion_eq.2 <| iUnion_split I i x theorem sum_split_boxes {M : Type*} [AddCommMonoid M] (I : Box ΞΉ) (i : ΞΉ) (x : ℝ) (f : Box ΞΉ β†’ M) : (βˆ‘ J ∈ (split I i x).boxes, f J) = (I.splitLower i x).elim' 0 f + (I.splitUpper i x).elim' 0 f := by classical rw [split, sum_ofWithBot, Finset.sum_pair (I.splitLower_ne_splitUpper i x)] /-- If `x βˆ‰ (I.lower i, I.upper i)`, then the hyperplane `{y | y i = x}` does not split `I`. -/ theorem split_of_notMem_Ioo (h : x βˆ‰ Ioo (I.lower i) (I.upper i)) : split I i x = ⊀ := by refine ((isPartitionTop I).eq_of_boxes_subset fun J hJ => ?_).symm rcases mem_top.1 hJ with rfl; clear hJ rw [mem_boxes, mem_split_iff] rw [mem_Ioo, not_and_or, not_lt, not_lt] at h cases h <;> [right; left] Β· rwa [eq_comm, Box.splitUpper_eq_self] Β· rwa [eq_comm, Box.splitLower_eq_self] @[deprecated (since := "2025-05-23")] alias split_of_not_mem_Ioo := split_of_notMem_Ioo theorem coe_eq_of_mem_split_of_mem_le {y : ΞΉ β†’ ℝ} (h₁ : J ∈ split I i x) (hβ‚‚ : y ∈ J) (h₃ : y i ≀ x) : (J : Set (ΞΉ β†’ ℝ)) = ↑I ∩ { y | y i ≀ x } := by refine (mem_split_iff'.1 h₁).resolve_right fun H => ?_ rw [← Box.mem_coe, H] at hβ‚‚ exact h₃.not_gt hβ‚‚.2 theorem coe_eq_of_mem_split_of_lt_mem {y : ΞΉ β†’ ℝ} (h₁ : J ∈ split I i x) (hβ‚‚ : y ∈ J) (h₃ : x < y i) : (J : Set (ΞΉ β†’ ℝ)) = ↑I ∩ { y | x < y i } := by refine (mem_split_iff'.1 h₁).resolve_left fun H => ?_ rw [← Box.mem_coe, H] at hβ‚‚ exact h₃.not_ge hβ‚‚.2 @[simp] theorem restrict_split (h : I ≀ J) (i : ΞΉ) (x : ℝ) : (split J i x).restrict I = split I i x := by refine ((isPartitionSplit J i x).restrict h).eq_of_boxes_subset ?_ simp only [Finset.subset_iff, mem_boxes, mem_restrict', mem_split_iff'] have : βˆ€ s, (I ∩ s : Set (ΞΉ β†’ ℝ)) βŠ† J := fun s => inter_subset_left.trans h rintro J₁ ⟨Jβ‚‚, Hβ‚‚ | Hβ‚‚, Hβ‚βŸ© <;> [left; right] <;> simp [H₁, Hβ‚‚, inter_left_comm (I : Set (ΞΉ β†’ ℝ)), this] theorem inf_split (Ο€ : Prepartition I) (i : ΞΉ) (x : ℝ) : Ο€ βŠ“ split I i x = Ο€.biUnion fun J => split J i x := biUnion_congr_of_le rfl fun _ hJ => restrict_split hJ i x /-- Split a box along many hyperplanes `{y | y i = x}`; each hyperplane is given by the pair `(i x)`. -/ def splitMany (I : Box ΞΉ) (s : Finset (ΞΉ Γ— ℝ)) : Prepartition I := s.inf fun p => split I p.1 p.2 @[simp] theorem splitMany_empty (I : Box ΞΉ) : splitMany I βˆ… = ⊀ := rfl open scoped Classical in @[simp] theorem splitMany_insert (I : Box ΞΉ) (s : Finset (ΞΉ Γ— ℝ)) (p : ΞΉ Γ— ℝ) : splitMany I (insert p s) = splitMany I s βŠ“ split I p.1 p.2 := by rw [splitMany, Finset.inf_insert, inf_comm, splitMany] theorem splitMany_le_split (I : Box ΞΉ) {s : Finset (ΞΉ Γ— ℝ)} {p : ΞΉ Γ— ℝ} (hp : p ∈ s) : splitMany I s ≀ split I p.1 p.2 := Finset.inf_le hp theorem isPartition_splitMany (I : Box ΞΉ) (s : Finset (ΞΉ Γ— ℝ)) : IsPartition (splitMany I s) := by classical exact Finset.induction_on s (by simp only [splitMany_empty, isPartitionTop]) fun a s _ hs => by simpa only [splitMany_insert, inf_split] using hs.biUnion fun J _ => isPartitionSplit _ _ _ @[simp] theorem iUnion_splitMany (I : Box ΞΉ) (s : Finset (ΞΉ Γ— ℝ)) : (splitMany I s).iUnion = I := (isPartition_splitMany I s).iUnion_eq theorem inf_splitMany {I : Box ΞΉ} (Ο€ : Prepartition I) (s : Finset (ΞΉ Γ— ℝ)) : Ο€ βŠ“ splitMany I s = Ο€.biUnion fun J => splitMany J s := by classical induction s using Finset.induction_on with | empty => simp | insert p s _ ihp => simp_rw [splitMany_insert, ← inf_assoc, ihp, inf_split, biUnion_assoc] open scoped Classical in /-- Let `s : Finset (ΞΉ Γ— ℝ)` be a set of hyperplanes `{x : ΞΉ β†’ ℝ | x i = r}` in `ΞΉ β†’ ℝ` encoded as pairs `(i, r)`. Suppose that this set contains all faces of a box `J`. The hyperplanes of `s` split a box `I` into subboxes. Let `Js` be one of them. If `J` and `Js` have nonempty intersection, then `Js` is a subbox of `J`. -/ theorem not_disjoint_imp_le_of_subset_of_mem_splitMany {I J Js : Box ΞΉ} {s : Finset (ΞΉ Γ— ℝ)} (H : βˆ€ i, {(i, J.lower i), (i, J.upper i)} βŠ† s) (HJs : Js ∈ splitMany I s) (Hn : Β¬Disjoint (J : WithBot (Box ΞΉ)) Js) : Js ≀ J := by simp only [Finset.insert_subset_iff, Finset.singleton_subset_iff] at H rcases Box.not_disjoint_coe_iff_nonempty_inter.mp Hn with ⟨x, hx, hxs⟩ refine fun y hy i => ⟨?_, ?_⟩ Β· rcases splitMany_le_split I (H i).1 HJs with ⟨Jl, Hmem : Jl ∈ split I i (J.lower i), Hle⟩ have := Hle hxs rw [← Box.coe_subset_coe, coe_eq_of_mem_split_of_lt_mem Hmem this (hx i).1] at Hle exact (Hle hy).2 Β· rcases splitMany_le_split I (H i).2 HJs with ⟨Jl, Hmem : Jl ∈ split I i (J.upper i), Hle⟩ have := Hle hxs rw [← Box.coe_subset_coe, coe_eq_of_mem_split_of_mem_le Hmem this (hx i).2] at Hle exact (Hle hy).2 section Finite variable [Finite ΞΉ] /-- Let `s` be a finite set of boxes in `ℝⁿ = ΞΉ β†’ ℝ`. Then there exists a finite set `tβ‚€` of hyperplanes (namely, the set of all hyperfaces of boxes in `s`) such that for any `t βŠ‡ tβ‚€` and any box `I` in `ℝⁿ` the following holds. The hyperplanes from `t` split `I` into subboxes. Let `J'` be one of them, and let `J` be one of the boxes in `s`. If these boxes have a nonempty intersection, then `J' ≀ J`. -/ theorem eventually_not_disjoint_imp_le_of_mem_splitMany (s : Finset (Box ΞΉ)) : βˆ€αΆ  t : Finset (ΞΉ Γ— ℝ) in atTop, βˆ€ (I : Box ΞΉ), βˆ€ J ∈ s, βˆ€ J' ∈ splitMany I t, Β¬Disjoint (J : WithBot (Box ΞΉ)) J' β†’ J' ≀ J := by classical cases nonempty_fintype ΞΉ refine eventually_atTop.2 ⟨s.biUnion fun J => Finset.univ.biUnion fun i => {(i, J.lower i), (i, J.upper i)}, fun t ht I J hJ J' hJ' => not_disjoint_imp_le_of_subset_of_mem_splitMany (fun i => ?_) hJ'⟩ exact fun p hp => ht (Finset.mem_biUnion.2 ⟨J, hJ, Finset.mem_biUnion.2 ⟨i, Finset.mem_univ _, hp⟩⟩) theorem eventually_splitMany_inf_eq_filter (Ο€ : Prepartition I) : βˆ€αΆ  t : Finset (ΞΉ Γ— ℝ) in atTop, Ο€ βŠ“ splitMany I t = (splitMany I t).filter fun J => ↑J βŠ† Ο€.iUnion := by refine (eventually_not_disjoint_imp_le_of_mem_splitMany Ο€.boxes).mono fun t ht => ?_ refine le_antisymm ((biUnion_le_iff _).2 fun J hJ => ?_) (le_inf (fun J hJ => ?_) (filter_le _ _)) Β· refine ofWithBot_mono ?_ simp only [Finset.mem_image, mem_boxes, mem_filter] rintro _ ⟨J₁, h₁, rfl⟩ hne refine ⟨_, ⟨J₁, ⟨h₁, Subset.trans ?_ (Ο€.subset_iUnion hJ)⟩, rfl⟩, le_rfl⟩ exact ht I J hJ J₁ h₁ (mt disjoint_iff.1 hne) Β· rw [mem_filter] at hJ rcases Set.mem_iUnionβ‚‚.1 (hJ.2 J.upper_mem) with ⟨J', hJ', hmem⟩ refine ⟨J', hJ', ht I _ hJ' _ hJ.1 <| Box.not_disjoint_coe_iff_nonempty_inter.2 ?_⟩ exact ⟨J.upper, hmem, J.upper_mem⟩ theorem exists_splitMany_inf_eq_filter_of_finite (s : Set (Prepartition I)) (hs : s.Finite) : βˆƒ t : Finset (ΞΉ Γ— ℝ), βˆ€ Ο€ ∈ s, Ο€ βŠ“ splitMany I t = (splitMany I t).filter fun J => ↑J βŠ† Ο€.iUnion := haveI := fun Ο€ (_ : Ο€ ∈ s) => eventually_splitMany_inf_eq_filter Ο€ (hs.eventually_all.2 this).exists /-- If `Ο€` is a partition of `I`, then there exists a finite set `s` of hyperplanes such that `splitMany I s ≀ Ο€`. -/ theorem IsPartition.exists_splitMany_le {I : Box ΞΉ} {Ο€ : Prepartition I} (h : IsPartition Ο€) : βˆƒ s, splitMany I s ≀ Ο€ := by refine (eventually_splitMany_inf_eq_filter Ο€).exists.imp fun s hs => ?_ rwa [h.iUnion_eq, filter_of_true, inf_eq_right] at hs exact fun J hJ => le_of_mem _ hJ /-- For every prepartition `Ο€` of `I` there exists a prepartition that covers exactly `I \ Ο€.iUnion`. -/ theorem exists_iUnion_eq_diff (Ο€ : Prepartition I) : βˆƒ Ο€' : Prepartition I, Ο€'.iUnion = ↑I \ Ο€.iUnion := by rcases Ο€.eventually_splitMany_inf_eq_filter.exists with ⟨s, hs⟩ use (splitMany I s).filter fun J => Β¬(J : Set (ΞΉ β†’ ℝ)) βŠ† Ο€.iUnion simp [← hs] /-- If `Ο€` is a prepartition of `I`, then `Ο€.compl` is a prepartition of `I` such that `Ο€.compl.iUnion = I \ Ο€.iUnion`. -/ def compl (Ο€ : Prepartition I) : Prepartition I := Ο€.exists_iUnion_eq_diff.choose @[simp] theorem iUnion_compl (Ο€ : Prepartition I) : Ο€.compl.iUnion = ↑I \ Ο€.iUnion := Ο€.exists_iUnion_eq_diff.choose_spec /-- Since the definition of `BoxIntegral.Prepartition.compl` uses `Exists.choose`, the result depends only on `Ο€.iUnion`. -/ theorem compl_congr {π₁ Ο€β‚‚ : Prepartition I} (h : π₁.iUnion = Ο€β‚‚.iUnion) : π₁.compl = Ο€β‚‚.compl := by dsimp only [compl] congr 1 rw [h] theorem IsPartition.compl_eq_bot {Ο€ : Prepartition I} (h : IsPartition Ο€) : Ο€.compl = βŠ₯ := by rw [← iUnion_eq_empty, iUnion_compl, h.iUnion_eq, diff_self] @[simp] theorem compl_top : (⊀ : Prepartition I).compl = βŠ₯ := (isPartitionTop I).compl_eq_bot end Finite end Prepartition end BoxIntegral
.lake/packages/mathlib/Mathlib/Analysis/BoxIntegral/Partition/Basic.lean
import Mathlib.Algebra.BigOperators.Option import Mathlib.Analysis.BoxIntegral.Box.Basic import Mathlib.Data.Set.Pairwise.Lattice /-! # Partitions of rectangular boxes in `ℝⁿ` In this file we define (pre)partitions of rectangular boxes in `ℝⁿ`. A partition of a box `I` in `ℝⁿ` (see `BoxIntegral.Prepartition` and `BoxIntegral.Prepartition.IsPartition`) is a finite set of pairwise disjoint boxes such that their union is exactly `I`. We use `boxes : Finset (Box ΞΉ)` to store the set of boxes. Many lemmas about box integrals deal with pairwise disjoint collections of subboxes, so we define a structure `BoxIntegral.Prepartition (I : BoxIntegral.Box ΞΉ)` that stores a collection of boxes such that * each box `J ∈ boxes` is a subbox of `I`; * the boxes are pairwise disjoint as sets in `ℝⁿ`. Then we define a predicate `BoxIntegral.Prepartition.IsPartition`; `Ο€.IsPartition` means that the boxes of `Ο€` actually cover the whole `I`. We also define some operations on prepartitions: * `BoxIntegral.Prepartition.biUnion`: split each box of a partition into smaller boxes; * `BoxIntegral.Prepartition.restrict`: restrict a partition to a smaller box. We also define a `SemilatticeInf` structure on `BoxIntegral.Prepartition I` for all `I : BoxIntegral.Box ΞΉ`. ## Tags rectangular box, partition -/ open Set Finset Function open scoped NNReal noncomputable section namespace BoxIntegral variable {ΞΉ : Type*} /-- A prepartition of `I : BoxIntegral.Box ΞΉ` is a finite set of pairwise disjoint subboxes of `I`. -/ structure Prepartition (I : Box ΞΉ) where /-- The underlying set of boxes -/ boxes : Finset (Box ΞΉ) /-- Each box is a sub-box of `I` -/ le_of_mem' : βˆ€ J ∈ boxes, J ≀ I /-- The boxes in a prepartition are pairwise disjoint. -/ pairwiseDisjoint : Set.Pairwise (↑boxes) (Disjoint on ((↑) : Box ΞΉ β†’ Set (ΞΉ β†’ ℝ))) namespace Prepartition variable {I J J₁ Jβ‚‚ : Box ΞΉ} (Ο€ : Prepartition I) {π₁ Ο€β‚‚ : Prepartition I} {x : ΞΉ β†’ ℝ} instance : Membership (Box ΞΉ) (Prepartition I) := ⟨fun Ο€ J => J ∈ Ο€.boxes⟩ @[simp] theorem mem_boxes : J ∈ Ο€.boxes ↔ J ∈ Ο€ := Iff.rfl @[simp] theorem mem_mk {s h₁ hβ‚‚} : J ∈ (mk s h₁ hβ‚‚ : Prepartition I) ↔ J ∈ s := Iff.rfl theorem disjoint_coe_of_mem (h₁ : J₁ ∈ Ο€) (hβ‚‚ : Jβ‚‚ ∈ Ο€) (h : J₁ β‰  Jβ‚‚) : Disjoint (J₁ : Set (ΞΉ β†’ ℝ)) Jβ‚‚ := Ο€.pairwiseDisjoint h₁ hβ‚‚ h theorem eq_of_mem_of_mem (h₁ : J₁ ∈ Ο€) (hβ‚‚ : Jβ‚‚ ∈ Ο€) (hx₁ : x ∈ J₁) (hxβ‚‚ : x ∈ Jβ‚‚) : J₁ = Jβ‚‚ := by_contra fun H => (Ο€.disjoint_coe_of_mem h₁ hβ‚‚ H).le_bot ⟨hx₁, hxβ‚‚βŸ© theorem eq_of_le_of_le (h₁ : J₁ ∈ Ο€) (hβ‚‚ : Jβ‚‚ ∈ Ο€) (hle₁ : J ≀ J₁) (hleβ‚‚ : J ≀ Jβ‚‚) : J₁ = Jβ‚‚ := Ο€.eq_of_mem_of_mem h₁ hβ‚‚ (hle₁ J.upper_mem) (hleβ‚‚ J.upper_mem) theorem eq_of_le (h₁ : J₁ ∈ Ο€) (hβ‚‚ : Jβ‚‚ ∈ Ο€) (hle : J₁ ≀ Jβ‚‚) : J₁ = Jβ‚‚ := Ο€.eq_of_le_of_le h₁ hβ‚‚ le_rfl hle theorem le_of_mem (hJ : J ∈ Ο€) : J ≀ I := Ο€.le_of_mem' J hJ theorem lower_le_lower (hJ : J ∈ Ο€) : I.lower ≀ J.lower := Box.antitone_lower (Ο€.le_of_mem hJ) theorem upper_le_upper (hJ : J ∈ Ο€) : J.upper ≀ I.upper := Box.monotone_upper (Ο€.le_of_mem hJ) theorem injective_boxes : Function.Injective (boxes : Prepartition I β†’ Finset (Box ΞΉ)) := by rintro ⟨s₁, h₁, h₁'⟩ ⟨sβ‚‚, hβ‚‚, hβ‚‚'⟩ (rfl : s₁ = sβ‚‚) rfl @[ext] theorem ext (h : βˆ€ J, J ∈ π₁ ↔ J ∈ Ο€β‚‚) : π₁ = Ο€β‚‚ := injective_boxes <| Finset.ext h /-- The singleton prepartition `{J}`, `J ≀ I`. -/ @[simps] def single (I J : Box ΞΉ) (h : J ≀ I) : Prepartition I := ⟨{J}, by simpa, by simp⟩ @[simp] theorem mem_single {J'} (h : J ≀ I) : J' ∈ single I J h ↔ J' = J := mem_singleton /-- We say that `Ο€ ≀ Ο€'` if each box of `Ο€` is a subbox of some box of `Ο€'`. -/ instance : LE (Prepartition I) := ⟨fun Ο€ Ο€' => βˆ€ ⦃I⦄, I ∈ Ο€ β†’ βˆƒ I' ∈ Ο€', I ≀ I'⟩ instance partialOrder : PartialOrder (Prepartition I) where le_refl _ I hI := ⟨I, hI, le_rfl⟩ le_trans _ _ _ h₁₂ h₂₃ _ hI₁ := let ⟨_, hIβ‚‚, hIβ‚β‚‚βŸ© := h₁₂ hI₁ let ⟨I₃, hI₃, hIβ‚‚β‚ƒβŸ© := h₂₃ hIβ‚‚ ⟨I₃, hI₃, hI₁₂.trans hIβ‚‚β‚ƒβŸ© le_antisymm := by suffices βˆ€ {π₁ Ο€β‚‚ : Prepartition I}, π₁ ≀ Ο€β‚‚ β†’ Ο€β‚‚ ≀ π₁ β†’ π₁.boxes βŠ† Ο€β‚‚.boxes from fun π₁ Ο€β‚‚ h₁ hβ‚‚ => injective_boxes (Subset.antisymm (this h₁ hβ‚‚) (this hβ‚‚ h₁)) intro π₁ Ο€β‚‚ h₁ hβ‚‚ J hJ rcases h₁ hJ with ⟨J', hJ', hle⟩; rcases hβ‚‚ hJ' with ⟨J'', hJ'', hle'⟩ obtain rfl : J = J'' := π₁.eq_of_le hJ hJ'' (hle.trans hle') obtain rfl : J' = J := le_antisymm β€Ή_β€Ί β€Ή_β€Ί assumption instance : OrderTop (Prepartition I) where top := single I I le_rfl le_top Ο€ _ hJ := ⟨I, by simp, Ο€.le_of_mem hJ⟩ instance : OrderBot (Prepartition I) where bot := βŸ¨βˆ…, fun _ hJ => (Finset.notMem_empty _ hJ).elim, fun _ hJ => (Set.notMem_empty _ <| Finset.coe_empty β–Έ hJ).elim⟩ bot_le _ _ hJ := (Finset.notMem_empty _ hJ).elim instance : Inhabited (Prepartition I) := ⟨⊀⟩ theorem le_def : π₁ ≀ Ο€β‚‚ ↔ βˆ€ J ∈ π₁, βˆƒ J' ∈ Ο€β‚‚, J ≀ J' := Iff.rfl @[simp] theorem mem_top : J ∈ (⊀ : Prepartition I) ↔ J = I := mem_singleton @[simp] theorem top_boxes : (⊀ : Prepartition I).boxes = {I} := rfl @[simp] theorem notMem_bot : J βˆ‰ (βŠ₯ : Prepartition I) := Finset.notMem_empty _ @[deprecated (since := "2025-05-23")] alias not_mem_bot := notMem_bot @[simp] theorem bot_boxes : (βŠ₯ : Prepartition I).boxes = βˆ… := rfl /-- An auxiliary lemma used to prove that the same point can't belong to more than `2 ^ Fintype.card ΞΉ` closed boxes of a prepartition. -/ theorem injOn_setOf_mem_Icc_setOf_lower_eq (x : ΞΉ β†’ ℝ) : InjOn (fun J : Box ΞΉ => { i | J.lower i = x i }) { J | J ∈ Ο€ ∧ x ∈ Box.Icc J } := by rintro J₁ ⟨h₁, hxβ‚βŸ© Jβ‚‚ ⟨hβ‚‚, hxβ‚‚βŸ© (H : { i | J₁.lower i = x i } = { i | Jβ‚‚.lower i = x i }) suffices βˆ€ i, (Ioc (J₁.lower i) (J₁.upper i) ∩ Ioc (Jβ‚‚.lower i) (Jβ‚‚.upper i)).Nonempty by choose y hy₁ hyβ‚‚ using this exact Ο€.eq_of_mem_of_mem h₁ hβ‚‚ hy₁ hyβ‚‚ intro i simp only [Set.ext_iff, mem_setOf] at H rcases (hx₁.1 i).eq_or_lt with hi₁ | hi₁ Β· have hiβ‚‚ : Jβ‚‚.lower i = x i := (H _).1 hi₁ have H₁ : x i < J₁.upper i := by simpa only [hi₁] using J₁.lower_lt_upper i have Hβ‚‚ : x i < Jβ‚‚.upper i := by simpa only [hiβ‚‚] using Jβ‚‚.lower_lt_upper i rw [Set.Ioc_inter_Ioc, hi₁, hiβ‚‚, sup_idem, Set.nonempty_Ioc] exact lt_min H₁ Hβ‚‚ Β· have hiβ‚‚ : Jβ‚‚.lower i < x i := (hxβ‚‚.1 i).lt_of_ne (mt (H _).2 hi₁.ne) exact ⟨x i, ⟨hi₁, hx₁.2 i⟩, ⟨hiβ‚‚, hxβ‚‚.2 i⟩⟩ open scoped Classical in /-- The set of boxes of a prepartition that contain `x` in their closures has cardinality at most `2 ^ Fintype.card ΞΉ`. -/ theorem card_filter_mem_Icc_le [Fintype ΞΉ] (x : ΞΉ β†’ ℝ) : #{J ∈ Ο€.boxes | x ∈ Box.Icc J} ≀ 2 ^ Fintype.card ΞΉ := by rw [← Fintype.card_set] refine Finset.card_le_card_of_injOn (fun J : Box ΞΉ => { i | J.lower i = x i }) (fun _ _ => Finset.mem_univ _) ?_ simpa using Ο€.injOn_setOf_mem_Icc_setOf_lower_eq x /-- Given a prepartition `Ο€ : BoxIntegral.Prepartition I`, `Ο€.iUnion` is the part of `I` covered by the boxes of `Ο€`. -/ protected def iUnion : Set (ΞΉ β†’ ℝ) := ⋃ J ∈ Ο€, ↑J theorem iUnion_def : Ο€.iUnion = ⋃ J ∈ Ο€, ↑J := rfl theorem iUnion_def' : Ο€.iUnion = ⋃ J ∈ Ο€.boxes, ↑J := rfl @[simp] theorem mem_iUnion : x ∈ Ο€.iUnion ↔ βˆƒ J ∈ Ο€, x ∈ J := by convert Set.mem_iUnionβ‚‚ rw [Box.mem_coe, exists_prop] @[simp] theorem iUnion_single (h : J ≀ I) : (single I J h).iUnion = J := by simp [iUnion_def] @[simp] theorem iUnion_top : (⊀ : Prepartition I).iUnion = I := by simp [Prepartition.iUnion] @[simp] theorem iUnion_eq_empty : π₁.iUnion = βˆ… ↔ π₁ = βŠ₯ := by simp [← injective_boxes.eq_iff, Finset.ext_iff, Prepartition.iUnion, imp_false] @[simp] theorem iUnion_bot : (βŠ₯ : Prepartition I).iUnion = βˆ… := iUnion_eq_empty.2 rfl theorem subset_iUnion (h : J ∈ Ο€) : ↑J βŠ† Ο€.iUnion := subset_biUnion_of_mem h theorem iUnion_subset : Ο€.iUnion βŠ† I := iUnionβ‚‚_subset Ο€.le_of_mem' @[mono] theorem iUnion_mono (h : π₁ ≀ Ο€β‚‚) : π₁.iUnion βŠ† Ο€β‚‚.iUnion := fun _ hx => let ⟨_, hJ₁, hx⟩ := π₁.mem_iUnion.1 hx let ⟨Jβ‚‚, hJβ‚‚, hle⟩ := h hJ₁ Ο€β‚‚.mem_iUnion.2 ⟨Jβ‚‚, hJβ‚‚, hle hx⟩ theorem disjoint_boxes_of_disjoint_iUnion (h : Disjoint π₁.iUnion Ο€β‚‚.iUnion) : Disjoint π₁.boxes Ο€β‚‚.boxes := Finset.disjoint_left.2 fun J h₁ hβ‚‚ => Disjoint.le_bot (h.mono (π₁.subset_iUnion h₁) (Ο€β‚‚.subset_iUnion hβ‚‚)) ⟨J.upper_mem, J.upper_mem⟩ theorem le_iff_nonempty_imp_le_and_iUnion_subset : π₁ ≀ Ο€β‚‚ ↔ (βˆ€ J ∈ π₁, βˆ€ J' ∈ Ο€β‚‚, (J ∩ J' : Set (ΞΉ β†’ ℝ)).Nonempty β†’ J ≀ J') ∧ π₁.iUnion βŠ† Ο€β‚‚.iUnion := by constructor Β· refine fun H => ⟨fun J hJ J' hJ' Hne => ?_, iUnion_mono H⟩ rcases H hJ with ⟨J'', hJ'', Hle⟩ rcases Hne with ⟨x, hx, hx'⟩ rwa [Ο€β‚‚.eq_of_mem_of_mem hJ' hJ'' hx' (Hle hx)] Β· rintro ⟨H, HU⟩ J hJ simp only [Set.subset_def, mem_iUnion] at HU rcases HU J.upper ⟨J, hJ, J.upper_mem⟩ with ⟨Jβ‚‚, hJβ‚‚, hx⟩ exact ⟨Jβ‚‚, hJβ‚‚, H _ hJ _ hJβ‚‚ ⟨_, J.upper_mem, hx⟩⟩ theorem eq_of_boxes_subset_iUnion_superset (h₁ : π₁.boxes βŠ† Ο€β‚‚.boxes) (hβ‚‚ : Ο€β‚‚.iUnion βŠ† π₁.iUnion) : π₁ = Ο€β‚‚ := le_antisymm (fun J hJ => ⟨J, h₁ hJ, le_rfl⟩) <| le_iff_nonempty_imp_le_and_iUnion_subset.2 ⟨fun _ hJ₁ _ hJβ‚‚ Hne => (Ο€β‚‚.eq_of_mem_of_mem hJ₁ (h₁ hJβ‚‚) Hne.choose_spec.1 Hne.choose_spec.2).le, hβ‚‚βŸ© open scoped Classical in /-- Given a prepartition `Ο€` of a box `I` and a collection of prepartitions `Ο€i J` of all boxes `J ∈ Ο€`, returns the prepartition of `I` into the union of the boxes of all `Ο€i J`. Though we only use the values of `Ο€i` on the boxes of `Ο€`, we require `Ο€i` to be a globally defined function. -/ @[simps] def biUnion (Ο€i : βˆ€ J : Box ΞΉ, Prepartition J) : Prepartition I where boxes := Ο€.boxes.biUnion fun J => (Ο€i J).boxes le_of_mem' J hJ := by simp only [Finset.mem_biUnion, mem_boxes] at hJ rcases hJ with ⟨J', hJ', hJ⟩ exact ((Ο€i J').le_of_mem hJ).trans (Ο€.le_of_mem hJ') pairwiseDisjoint := by simp only [Set.Pairwise, Finset.mem_coe, Finset.mem_biUnion] rintro J₁' ⟨J₁, hJ₁, hJ₁'⟩ Jβ‚‚' ⟨Jβ‚‚, hJβ‚‚, hJβ‚‚'⟩ Hne rw [Function.onFun, Set.disjoint_left] rintro x hx₁ hxβ‚‚; apply Hne obtain rfl : J₁ = Jβ‚‚ := Ο€.eq_of_mem_of_mem hJ₁ hJβ‚‚ ((Ο€i J₁).le_of_mem hJ₁' hx₁) ((Ο€i Jβ‚‚).le_of_mem hJβ‚‚' hxβ‚‚) exact (Ο€i J₁).eq_of_mem_of_mem hJ₁' hJβ‚‚' hx₁ hxβ‚‚ variable {Ο€i Ο€i₁ Ο€iβ‚‚ : βˆ€ J : Box ΞΉ, Prepartition J} @[simp] theorem mem_biUnion : J ∈ Ο€.biUnion Ο€i ↔ βˆƒ J' ∈ Ο€, J ∈ Ο€i J' := by simp [biUnion] theorem biUnion_le (Ο€i : βˆ€ J, Prepartition J) : Ο€.biUnion Ο€i ≀ Ο€ := fun _ hJ => let ⟨J', hJ', hJ⟩ := Ο€.mem_biUnion.1 hJ ⟨J', hJ', (Ο€i J').le_of_mem hJ⟩ @[simp] theorem biUnion_top : (Ο€.biUnion fun _ => ⊀) = Ο€ := by ext simp @[congr] theorem biUnion_congr (h : π₁ = Ο€β‚‚) (hi : βˆ€ J ∈ π₁, Ο€i₁ J = Ο€iβ‚‚ J) : π₁.biUnion Ο€i₁ = Ο€β‚‚.biUnion Ο€iβ‚‚ := by subst Ο€β‚‚ ext J simp only [mem_biUnion] constructor <;> exact fun ⟨J', h₁, hβ‚‚βŸ© => ⟨J', h₁, hi J' h₁ β–Έ hβ‚‚βŸ© theorem biUnion_congr_of_le (h : π₁ = Ο€β‚‚) (hi : βˆ€ J ≀ I, Ο€i₁ J = Ο€iβ‚‚ J) : π₁.biUnion Ο€i₁ = Ο€β‚‚.biUnion Ο€iβ‚‚ := biUnion_congr h fun J hJ => hi J (π₁.le_of_mem hJ) @[simp] theorem iUnion_biUnion (Ο€i : βˆ€ J : Box ΞΉ, Prepartition J) : (Ο€.biUnion Ο€i).iUnion = ⋃ J ∈ Ο€, (Ο€i J).iUnion := by simp [Prepartition.iUnion] open scoped Classical in @[simp] theorem sum_biUnion_boxes {M : Type*} [AddCommMonoid M] (Ο€ : Prepartition I) (Ο€i : βˆ€ J, Prepartition J) (f : Box ΞΉ β†’ M) : (βˆ‘ J ∈ Ο€.boxes.biUnion fun J => (Ο€i J).boxes, f J) = βˆ‘ J ∈ Ο€.boxes, βˆ‘ J' ∈ (Ο€i J).boxes, f J' := by refine Finset.sum_biUnion fun J₁ h₁ Jβ‚‚ hβ‚‚ hne => Finset.disjoint_left.2 fun J' h₁' hβ‚‚' => ?_ exact hne (Ο€.eq_of_le_of_le h₁ hβ‚‚ ((Ο€i J₁).le_of_mem h₁') ((Ο€i Jβ‚‚).le_of_mem hβ‚‚')) open scoped Classical in /-- Given a box `J ∈ Ο€.biUnion Ο€i`, returns the box `J' ∈ Ο€` such that `J ∈ Ο€i J'`. For `J βˆ‰ Ο€.biUnion Ο€i`, returns `I`. -/ def biUnionIndex (Ο€i : βˆ€ (J : Box ΞΉ), Prepartition J) (J : Box ΞΉ) : Box ΞΉ := if hJ : J ∈ Ο€.biUnion Ο€i then (Ο€.mem_biUnion.1 hJ).choose else I theorem biUnionIndex_mem (hJ : J ∈ Ο€.biUnion Ο€i) : Ο€.biUnionIndex Ο€i J ∈ Ο€ := by rw [biUnionIndex, dif_pos hJ] exact (Ο€.mem_biUnion.1 hJ).choose_spec.1 theorem biUnionIndex_le (Ο€i : βˆ€ J, Prepartition J) (J : Box ΞΉ) : Ο€.biUnionIndex Ο€i J ≀ I := by by_cases hJ : J ∈ Ο€.biUnion Ο€i Β· exact Ο€.le_of_mem (Ο€.biUnionIndex_mem hJ) Β· rw [biUnionIndex, dif_neg hJ] theorem mem_biUnionIndex (hJ : J ∈ Ο€.biUnion Ο€i) : J ∈ Ο€i (Ο€.biUnionIndex Ο€i J) := by convert (Ο€.mem_biUnion.1 hJ).choose_spec.2 <;> exact dif_pos hJ theorem le_biUnionIndex (hJ : J ∈ Ο€.biUnion Ο€i) : J ≀ Ο€.biUnionIndex Ο€i J := le_of_mem _ (Ο€.mem_biUnionIndex hJ) /-- Uniqueness property of `BoxIntegral.Prepartition.biUnionIndex`. -/ theorem biUnionIndex_of_mem (hJ : J ∈ Ο€) {J'} (hJ' : J' ∈ Ο€i J) : Ο€.biUnionIndex Ο€i J' = J := have : J' ∈ Ο€.biUnion Ο€i := Ο€.mem_biUnion.2 ⟨J, hJ, hJ'⟩ Ο€.eq_of_le_of_le (Ο€.biUnionIndex_mem this) hJ (Ο€.le_biUnionIndex this) (le_of_mem _ hJ') theorem biUnion_assoc (Ο€i : βˆ€ J, Prepartition J) (Ο€i' : Box ΞΉ β†’ βˆ€ J : Box ΞΉ, Prepartition J) : (Ο€.biUnion fun J => (Ο€i J).biUnion (Ο€i' J)) = (Ο€.biUnion Ο€i).biUnion fun J => Ο€i' (Ο€.biUnionIndex Ο€i J) J := by ext J simp only [mem_biUnion] constructor Β· rintro ⟨J₁, hJ₁, Jβ‚‚, hJβ‚‚, hJ⟩ refine ⟨Jβ‚‚, ⟨J₁, hJ₁, hJβ‚‚βŸ©, ?_⟩ rwa [Ο€.biUnionIndex_of_mem hJ₁ hJβ‚‚] Β· rintro ⟨J₁, ⟨Jβ‚‚, hJβ‚‚, hJβ‚βŸ©, hJ⟩ refine ⟨Jβ‚‚, hJβ‚‚, J₁, hJ₁, ?_⟩ rwa [Ο€.biUnionIndex_of_mem hJβ‚‚ hJ₁] at hJ /-- Create a `BoxIntegral.Prepartition` from a collection of possibly empty boxes by filtering out the empty one if it exists. -/ def ofWithBot (boxes : Finset (WithBot (Box ΞΉ))) (le_of_mem : βˆ€ J ∈ boxes, (J : WithBot (Box ΞΉ)) ≀ I) (pairwise_disjoint : Set.Pairwise (boxes : Set (WithBot (Box ΞΉ))) Disjoint) : Prepartition I where boxes := Finset.eraseNone boxes le_of_mem' J hJ := by rw [mem_eraseNone] at hJ simpa only [WithBot.some_eq_coe, WithBot.coe_le_coe] using le_of_mem _ hJ pairwiseDisjoint J₁ h₁ Jβ‚‚ hβ‚‚ hne := by simp only [mem_coe, mem_eraseNone] at h₁ hβ‚‚ exact Box.disjoint_coe.1 (pairwise_disjoint h₁ hβ‚‚ (mt Option.some_inj.1 hne)) @[simp] theorem mem_ofWithBot {boxes : Finset (WithBot (Box ΞΉ))} {h₁ hβ‚‚} : J ∈ (ofWithBot boxes h₁ hβ‚‚ : Prepartition I) ↔ (J : WithBot (Box ΞΉ)) ∈ boxes := mem_eraseNone @[simp] theorem iUnion_ofWithBot (boxes : Finset (WithBot (Box ΞΉ))) (le_of_mem : βˆ€ J ∈ boxes, (J : WithBot (Box ΞΉ)) ≀ I) (pairwise_disjoint : Set.Pairwise (boxes : Set (WithBot (Box ΞΉ))) Disjoint) : (ofWithBot boxes le_of_mem pairwise_disjoint).iUnion = ⋃ J ∈ boxes, ↑J := by suffices ⋃ (J : Box ΞΉ) (_ : ↑J ∈ boxes), ↑J = ⋃ J ∈ boxes, (J : Set (ΞΉ β†’ ℝ)) by simpa [ofWithBot, Prepartition.iUnion] simp only [← Box.biUnion_coe_eq_coe, @iUnion_comm _ _ (Box ΞΉ), @iUnion_comm _ _ (@Eq _ _ _), iUnion_iUnion_eq_right] theorem ofWithBot_le {boxes : Finset (WithBot (Box ΞΉ))} {le_of_mem : βˆ€ J ∈ boxes, (J : WithBot (Box ΞΉ)) ≀ I} {pairwise_disjoint : Set.Pairwise (boxes : Set (WithBot (Box ΞΉ))) Disjoint} (H : βˆ€ J ∈ boxes, J β‰  βŠ₯ β†’ βˆƒ J' ∈ Ο€, J ≀ ↑J') : ofWithBot boxes le_of_mem pairwise_disjoint ≀ Ο€ := by have : βˆ€ J : Box ΞΉ, ↑J ∈ boxes β†’ βˆƒ J' ∈ Ο€, J ≀ J' := fun J hJ => by simpa only [WithBot.coe_le_coe] using H J hJ WithBot.coe_ne_bot simpa [ofWithBot, le_def] theorem le_ofWithBot {boxes : Finset (WithBot (Box ΞΉ))} {le_of_mem : βˆ€ J ∈ boxes, (J : WithBot (Box ΞΉ)) ≀ I} {pairwise_disjoint : Set.Pairwise (boxes : Set (WithBot (Box ΞΉ))) Disjoint} (H : βˆ€ J ∈ Ο€, βˆƒ J' ∈ boxes, ↑J ≀ J') : Ο€ ≀ ofWithBot boxes le_of_mem pairwise_disjoint := by intro J hJ rcases H J hJ with ⟨J', J'mem, hle⟩ lift J' to Box ΞΉ using ne_bot_of_le_ne_bot WithBot.coe_ne_bot hle exact ⟨J', mem_ofWithBot.2 J'mem, WithBot.coe_le_coe.1 hle⟩ theorem ofWithBot_mono {boxes₁ : Finset (WithBot (Box ΞΉ))} {le_of_mem₁ : βˆ€ J ∈ boxes₁, (J : WithBot (Box ΞΉ)) ≀ I} {pairwise_disjoint₁ : Set.Pairwise (boxes₁ : Set (WithBot (Box ΞΉ))) Disjoint} {boxesβ‚‚ : Finset (WithBot (Box ΞΉ))} {le_of_memβ‚‚ : βˆ€ J ∈ boxesβ‚‚, (J : WithBot (Box ΞΉ)) ≀ I} {pairwise_disjointβ‚‚ : Set.Pairwise (boxesβ‚‚ : Set (WithBot (Box ΞΉ))) Disjoint} (H : βˆ€ J ∈ boxes₁, J β‰  βŠ₯ β†’ βˆƒ J' ∈ boxesβ‚‚, J ≀ J') : ofWithBot boxes₁ le_of_mem₁ pairwise_disjoint₁ ≀ ofWithBot boxesβ‚‚ le_of_memβ‚‚ pairwise_disjointβ‚‚ := le_ofWithBot _ fun J hJ => H J (mem_ofWithBot.1 hJ) WithBot.coe_ne_bot theorem sum_ofWithBot {M : Type*} [AddCommMonoid M] (boxes : Finset (WithBot (Box ΞΉ))) (le_of_mem : βˆ€ J ∈ boxes, (J : WithBot (Box ΞΉ)) ≀ I) (pairwise_disjoint : Set.Pairwise (boxes : Set (WithBot (Box ΞΉ))) Disjoint) (f : Box ΞΉ β†’ M) : (βˆ‘ J ∈ (ofWithBot boxes le_of_mem pairwise_disjoint).boxes, f J) = βˆ‘ J ∈ boxes, Option.elim' 0 f J := Finset.sum_eraseNone _ _ open scoped Classical in /-- Restrict a prepartition to a box. -/ def restrict (Ο€ : Prepartition I) (J : Box ΞΉ) : Prepartition J := ofWithBot (Ο€.boxes.image fun J' : Box ΞΉ => J βŠ“ J') (fun J' hJ' => by rcases Finset.mem_image.1 hJ' with ⟨J', -, rfl⟩ exact inf_le_left) (by simp only [Set.Pairwise, Finset.mem_coe, Finset.mem_image] rintro _ ⟨J₁, h₁, rfl⟩ _ ⟨Jβ‚‚, hβ‚‚, rfl⟩ Hne have : J₁ β‰  Jβ‚‚ := by rintro rfl exact Hne rfl exact ((Box.disjoint_coe.2 <| Ο€.disjoint_coe_of_mem h₁ hβ‚‚ this).inf_left' _).inf_right' _) @[simp] theorem mem_restrict : J₁ ∈ Ο€.restrict J ↔ βˆƒ J' ∈ Ο€, (J₁ : WithBot (Box ΞΉ)) = ↑J βŠ“ ↑J' := by simp [restrict, eq_comm] theorem mem_restrict' : J₁ ∈ Ο€.restrict J ↔ βˆƒ J' ∈ Ο€, (J₁ : Set (ΞΉ β†’ ℝ)) = ↑J ∩ ↑J' := by simp only [mem_restrict, ← Box.withBotCoe_inj, Box.coe_inf, Box.coe_coe] @[mono] theorem restrict_mono {π₁ Ο€β‚‚ : Prepartition I} (Hle : π₁ ≀ Ο€β‚‚) : π₁.restrict J ≀ Ο€β‚‚.restrict J := by classical refine ofWithBot_mono fun J₁ hJ₁ hne => ?_ rw [Finset.mem_image] at hJ₁; rcases hJ₁ with ⟨J₁, hJ₁, rfl⟩ rcases Hle hJ₁ with ⟨Jβ‚‚, hJβ‚‚, hle⟩ exact ⟨_, Finset.mem_image_of_mem _ hJβ‚‚, inf_le_inf_left _ <| WithBot.coe_le_coe.2 hle⟩ theorem monotone_restrict : Monotone fun Ο€ : Prepartition I => restrict Ο€ J := fun _ _ => restrict_mono /-- Restricting to a larger box does not change the set of boxes. We cannot claim equality of prepartitions because they have different types. -/ theorem restrict_boxes_of_le (Ο€ : Prepartition I) (h : I ≀ J) : (Ο€.restrict J).boxes = Ο€.boxes := by classical simp only [restrict, ofWithBot, eraseNone_eq_biUnion] refine Finset.image_biUnion.trans ?_ refine (Finset.biUnion_congr rfl ?_).trans Finset.biUnion_singleton_eq_self intro J' hJ' rw [inf_of_le_right, ← WithBot.some_eq_coe, Option.toFinset_some] exact WithBot.coe_le_coe.2 ((Ο€.le_of_mem hJ').trans h) @[simp] theorem restrict_self : Ο€.restrict I = Ο€ := injective_boxes <| restrict_boxes_of_le Ο€ le_rfl @[simp] theorem iUnion_restrict : (Ο€.restrict J).iUnion = (J : Set (ΞΉ β†’ ℝ)) ∩ (Ο€.iUnion) := by simp [restrict, ← inter_iUnion, ← iUnion_def] @[simp] theorem restrict_biUnion (Ο€i : βˆ€ J, Prepartition J) (hJ : J ∈ Ο€) : (Ο€.biUnion Ο€i).restrict J = Ο€i J := by refine (eq_of_boxes_subset_iUnion_superset (fun J₁ h₁ => ?_) ?_).symm Β· refine (mem_restrict _).2 ⟨J₁, Ο€.mem_biUnion.2 ⟨J, hJ, hβ‚βŸ©, (inf_of_le_right ?_).symm⟩ exact WithBot.coe_le_coe.2 (le_of_mem _ h₁) Β· simp only [iUnion_restrict, iUnion_biUnion, Set.subset_def, Set.mem_inter_iff, Set.mem_iUnion] rintro x ⟨hxJ, J₁, h₁, hx⟩ obtain rfl : J = J₁ := Ο€.eq_of_mem_of_mem hJ h₁ hxJ (iUnion_subset _ hx) exact hx theorem biUnion_le_iff {Ο€i : βˆ€ J, Prepartition J} {Ο€' : Prepartition I} : Ο€.biUnion Ο€i ≀ Ο€' ↔ βˆ€ J ∈ Ο€, Ο€i J ≀ Ο€'.restrict J := by constructor <;> intro H J hJ Β· rw [← Ο€.restrict_biUnion Ο€i hJ] exact restrict_mono H Β· rw [mem_biUnion] at hJ rcases hJ with ⟨J₁, h₁, hJ⟩ rcases H J₁ h₁ hJ with ⟨Jβ‚‚, hβ‚‚, Hle⟩ rcases Ο€'.mem_restrict.mp hβ‚‚ with ⟨J₃, h₃, H⟩ exact ⟨J₃, h₃, Hle.trans <| WithBot.coe_le_coe.1 <| H.trans_le inf_le_right⟩ theorem le_biUnion_iff {Ο€i : βˆ€ J, Prepartition J} {Ο€' : Prepartition I} : Ο€' ≀ Ο€.biUnion Ο€i ↔ Ο€' ≀ Ο€ ∧ βˆ€ J ∈ Ο€, Ο€'.restrict J ≀ Ο€i J := by refine ⟨fun H => ⟨H.trans (Ο€.biUnion_le Ο€i), fun J hJ => ?_⟩, ?_⟩ Β· rw [← Ο€.restrict_biUnion Ο€i hJ] exact restrict_mono H Β· rintro ⟨H, Hi⟩ J' hJ' rcases H hJ' with ⟨J, hJ, hle⟩ have : J' ∈ Ο€'.restrict J := Ο€'.mem_restrict.2 ⟨J', hJ', (inf_of_le_right <| WithBot.coe_le_coe.2 hle).symm⟩ rcases Hi J hJ this with ⟨Ji, hJi, hlei⟩ exact ⟨Ji, Ο€.mem_biUnion.2 ⟨J, hJ, hJi⟩, hlei⟩ instance : SemilatticeInf (Prepartition I) := { inf := fun π₁ Ο€β‚‚ => π₁.biUnion fun J => Ο€β‚‚.restrict J inf_le_left := fun π₁ _ => π₁.biUnion_le _ inf_le_right := fun _ _ => (biUnion_le_iff _).2 fun _ _ => le_rfl le_inf := fun _ π₁ _ h₁ hβ‚‚ => π₁.le_biUnion_iff.2 ⟨h₁, fun _ _ => restrict_mono hβ‚‚βŸ© } theorem inf_def (π₁ Ο€β‚‚ : Prepartition I) : π₁ βŠ“ Ο€β‚‚ = π₁.biUnion fun J => Ο€β‚‚.restrict J := rfl @[simp] theorem mem_inf {π₁ Ο€β‚‚ : Prepartition I} : J ∈ π₁ βŠ“ Ο€β‚‚ ↔ βˆƒ J₁ ∈ π₁, βˆƒ Jβ‚‚ ∈ Ο€β‚‚, (J : WithBot (Box ΞΉ)) = ↑J₁ βŠ“ ↑Jβ‚‚ := by simp only [inf_def, mem_biUnion, mem_restrict] @[simp] theorem iUnion_inf (π₁ Ο€β‚‚ : Prepartition I) : (π₁ βŠ“ Ο€β‚‚).iUnion = π₁.iUnion ∩ Ο€β‚‚.iUnion := by simp only [inf_def, iUnion_biUnion, iUnion_restrict, ← iUnion_inter, ← iUnion_def] open scoped Classical in /-- The prepartition with boxes `{J ∈ Ο€ | p J}`. -/ @[simps] def filter (Ο€ : Prepartition I) (p : Box ΞΉ β†’ Prop) : Prepartition I where boxes := {J ∈ Ο€.boxes | p J} le_of_mem' _ hJ := Ο€.le_of_mem (mem_filter.1 hJ).1 pairwiseDisjoint _ h₁ _ hβ‚‚ := Ο€.disjoint_coe_of_mem (mem_filter.1 h₁).1 (mem_filter.1 hβ‚‚).1 @[simp] theorem mem_filter {p : Box ΞΉ β†’ Prop} : J ∈ Ο€.filter p ↔ J ∈ Ο€ ∧ p J := by classical exact Finset.mem_filter theorem filter_le (Ο€ : Prepartition I) (p : Box ΞΉ β†’ Prop) : Ο€.filter p ≀ Ο€ := fun J hJ => let ⟨hΟ€, _⟩ := Ο€.mem_filter.1 hJ ⟨J, hΟ€, le_rfl⟩ theorem filter_of_true {p : Box ΞΉ β†’ Prop} (hp : βˆ€ J ∈ Ο€, p J) : Ο€.filter p = Ο€ := by ext J simpa using hp J @[simp] theorem filter_true : (Ο€.filter fun _ => True) = Ο€ := Ο€.filter_of_true fun _ _ => trivial @[simp] theorem iUnion_filter_not (Ο€ : Prepartition I) (p : Box ΞΉ β†’ Prop) : (Ο€.filter fun J => Β¬p J).iUnion = Ο€.iUnion \ (Ο€.filter p).iUnion := by simp only [Prepartition.iUnion] convert (@Set.biUnion_diff_biUnion_eq (ΞΉ β†’ ℝ) (Box ΞΉ) Ο€.boxes (Ο€.filter p).boxes (↑) _).symm using 4 Β· simp +contextual Β· rw [Set.PairwiseDisjoint] convert Ο€.pairwiseDisjoint rw [Set.union_eq_left, filter_boxes, coe_filter] exact fun _ ⟨h, _⟩ => h open scoped Classical in theorem sum_fiberwise {Ξ± M} [AddCommMonoid M] (Ο€ : Prepartition I) (f : Box ΞΉ β†’ Ξ±) (g : Box ΞΉ β†’ M) : (βˆ‘ y ∈ Ο€.boxes.image f, βˆ‘ J ∈ (Ο€.filter fun J => f J = y).boxes, g J) = βˆ‘ J ∈ Ο€.boxes, g J := by convert sum_fiberwise_of_maps_to (fun _ => Finset.mem_image_of_mem f) g open scoped Classical in /-- Union of two disjoint prepartitions. -/ @[simps] def disjUnion (π₁ Ο€β‚‚ : Prepartition I) (h : Disjoint π₁.iUnion Ο€β‚‚.iUnion) : Prepartition I where boxes := π₁.boxes βˆͺ Ο€β‚‚.boxes le_of_mem' _ hJ := (Finset.mem_union.1 hJ).elim π₁.le_of_mem Ο€β‚‚.le_of_mem pairwiseDisjoint := suffices βˆ€ J₁ ∈ π₁, βˆ€ Jβ‚‚ ∈ Ο€β‚‚, J₁ β‰  Jβ‚‚ β†’ Disjoint (J₁ : Set (ΞΉ β†’ ℝ)) Jβ‚‚ by simpa [pairwise_union_of_symmetric (symmetric_disjoint.comap _), pairwiseDisjoint] fun _ h₁ _ hβ‚‚ _ => h.mono (π₁.subset_iUnion h₁) (Ο€β‚‚.subset_iUnion hβ‚‚) @[simp] theorem mem_disjUnion (H : Disjoint π₁.iUnion Ο€β‚‚.iUnion) : J ∈ π₁.disjUnion Ο€β‚‚ H ↔ J ∈ π₁ ∨ J ∈ Ο€β‚‚ := by classical exact Finset.mem_union @[simp] theorem iUnion_disjUnion (h : Disjoint π₁.iUnion Ο€β‚‚.iUnion) : (π₁.disjUnion Ο€β‚‚ h).iUnion = π₁.iUnion βˆͺ Ο€β‚‚.iUnion := by simp [disjUnion, Prepartition.iUnion, iUnion_or, iUnion_union_distrib] open scoped Classical in @[simp] theorem sum_disj_union_boxes {M : Type*} [AddCommMonoid M] (h : Disjoint π₁.iUnion Ο€β‚‚.iUnion) (f : Box ΞΉ β†’ M) : βˆ‘ J ∈ π₁.boxes βˆͺ Ο€β‚‚.boxes, f J = (βˆ‘ J ∈ π₁.boxes, f J) + βˆ‘ J ∈ Ο€β‚‚.boxes, f J := sum_union <| disjoint_boxes_of_disjoint_iUnion h section Distortion variable [Fintype ΞΉ] /-- The distortion of a prepartition is the maximum of the distortions of the boxes of this prepartition. -/ def distortion : ℝβ‰₯0 := Ο€.boxes.sup Box.distortion theorem distortion_le_of_mem (h : J ∈ Ο€) : J.distortion ≀ Ο€.distortion := le_sup h theorem distortion_le_iff {c : ℝβ‰₯0} : Ο€.distortion ≀ c ↔ βˆ€ J ∈ Ο€, Box.distortion J ≀ c := Finset.sup_le_iff theorem distortion_biUnion (Ο€ : Prepartition I) (Ο€i : βˆ€ J, Prepartition J) : (Ο€.biUnion Ο€i).distortion = Ο€.boxes.sup fun J => (Ο€i J).distortion := by classical exact sup_biUnion _ _ @[simp] theorem distortion_disjUnion (h : Disjoint π₁.iUnion Ο€β‚‚.iUnion) : (π₁.disjUnion Ο€β‚‚ h).distortion = max π₁.distortion Ο€β‚‚.distortion := by classical exact sup_union theorem distortion_of_const {c} (h₁ : Ο€.boxes.Nonempty) (hβ‚‚ : βˆ€ J ∈ Ο€, Box.distortion J = c) : Ο€.distortion = c := (sup_congr rfl hβ‚‚).trans (sup_const h₁ _) @[simp] theorem distortion_top (I : Box ΞΉ) : distortion (⊀ : Prepartition I) = I.distortion := sup_singleton @[simp] theorem distortion_bot (I : Box ΞΉ) : distortion (βŠ₯ : Prepartition I) = 0 := sup_empty end Distortion /-- A prepartition `Ο€` of `I` is a partition if the boxes of `Ο€` cover the whole `I`. -/ def IsPartition (Ο€ : Prepartition I) := βˆ€ x ∈ I, βˆƒ J ∈ Ο€, x ∈ J theorem isPartition_iff_iUnion_eq {Ο€ : Prepartition I} : Ο€.IsPartition ↔ Ο€.iUnion = I := by simp_rw [IsPartition, Set.Subset.antisymm_iff, Ο€.iUnion_subset, true_and, Set.subset_def, mem_iUnion, Box.mem_coe] @[simp] theorem isPartition_single_iff (h : J ≀ I) : IsPartition (single I J h) ↔ J = I := by simp [isPartition_iff_iUnion_eq] theorem isPartitionTop (I : Box ΞΉ) : IsPartition (⊀ : Prepartition I) := fun _ hx => ⟨I, mem_top.2 rfl, hx⟩ namespace IsPartition variable {Ο€} theorem iUnion_eq (h : Ο€.IsPartition) : Ο€.iUnion = I := isPartition_iff_iUnion_eq.1 h theorem iUnion_subset (h : Ο€.IsPartition) (π₁ : Prepartition I) : π₁.iUnion βŠ† Ο€.iUnion := h.iUnion_eq.symm β–Έ π₁.iUnion_subset protected theorem existsUnique (h : Ο€.IsPartition) (hx : x ∈ I) : βˆƒ! J ∈ Ο€, x ∈ J := by rcases h x hx with ⟨J, h, hx⟩ exact ExistsUnique.intro J ⟨h, hx⟩ fun J' ⟨h', hx'⟩ => Ο€.eq_of_mem_of_mem h' h hx' hx theorem nonempty_boxes (h : Ο€.IsPartition) : Ο€.boxes.Nonempty := let ⟨J, hJ, _⟩ := h _ I.upper_mem ⟨J, hJ⟩ theorem eq_of_boxes_subset (h₁ : π₁.IsPartition) (hβ‚‚ : π₁.boxes βŠ† Ο€β‚‚.boxes) : π₁ = Ο€β‚‚ := eq_of_boxes_subset_iUnion_superset hβ‚‚ <| h₁.iUnion_subset _ theorem le_iff (h : Ο€β‚‚.IsPartition) : π₁ ≀ Ο€β‚‚ ↔ βˆ€ J ∈ π₁, βˆ€ J' ∈ Ο€β‚‚, (J ∩ J' : Set (ΞΉ β†’ ℝ)).Nonempty β†’ J ≀ J' := le_iff_nonempty_imp_le_and_iUnion_subset.trans <| and_iff_left <| h.iUnion_subset _ protected theorem biUnion (h : IsPartition Ο€) (hi : βˆ€ J ∈ Ο€, IsPartition (Ο€i J)) : IsPartition (Ο€.biUnion Ο€i) := fun x hx => let ⟨J, hJ, hxi⟩ := h x hx let ⟨Ji, hJi, hx⟩ := hi J hJ x hxi ⟨Ji, Ο€.mem_biUnion.2 ⟨J, hJ, hJi⟩, hx⟩ protected theorem restrict (h : IsPartition Ο€) (hJ : J ≀ I) : IsPartition (Ο€.restrict J) := isPartition_iff_iUnion_eq.2 <| by simp [h.iUnion_eq, hJ] protected theorem inf (h₁ : IsPartition π₁) (hβ‚‚ : IsPartition Ο€β‚‚) : IsPartition (π₁ βŠ“ Ο€β‚‚) := isPartition_iff_iUnion_eq.2 <| by simp [h₁.iUnion_eq, hβ‚‚.iUnion_eq] end IsPartition theorem iUnion_biUnion_partition (h : βˆ€ J ∈ Ο€, (Ο€i J).IsPartition) : (Ο€.biUnion Ο€i).iUnion = Ο€.iUnion := (iUnion_biUnion _ _).trans <| iUnion_congr_of_surjective id surjective_id fun J => iUnion_congr_of_surjective id surjective_id fun hJ => (h J hJ).iUnion_eq theorem isPartitionDisjUnionOfEqDiff (h : Ο€β‚‚.iUnion = ↑I \ π₁.iUnion) : IsPartition (π₁.disjUnion Ο€β‚‚ <| h.symm β–Έ disjoint_sdiff_self_right) := isPartition_iff_iUnion_eq.2 <| (iUnion_disjUnion _).trans <| by simp [h, π₁.iUnion_subset] end Prepartition end BoxIntegral
.lake/packages/mathlib/Mathlib/Analysis/BoxIntegral/Partition/Filter.lean
import Mathlib.Analysis.BoxIntegral.Partition.SubboxInduction import Mathlib.Analysis.BoxIntegral.Partition.Split /-! # Filters used in box-based integrals First we define a structure `BoxIntegral.IntegrationParams`. This structure will be used as an argument in the definition of `BoxIntegral.integral` in order to use the same definition for a few well-known definitions of integrals based on partitions of a rectangular box into subboxes (Riemann integral, Henstock-Kurzweil integral, and McShane integral). This structure holds three Boolean values (see below), and encodes eight different sets of parameters; only four of these values are used somewhere in `mathlib4`. Three of them correspond to the integration theories listed above, and one is a generalization of the one-dimensional Henstock-Kurzweil integral such that the divergence theorem works without additional integrability assumptions. Finally, for each set of parameters `l : BoxIntegral.IntegrationParams` and a rectangular box `I : BoxIntegral.Box ΞΉ`, we define several `Filter`s that will be used either in the definition of the corresponding integral, or in the proofs of its properties. We equip `BoxIntegral.IntegrationParams` with a `BoundedOrder` structure such that larger `IntegrationParams` produce larger filters. ## Main definitions ### Integration parameters The structure `BoxIntegral.IntegrationParams` has 3 Boolean fields with the following meaning: * `bRiemann`: the value `true` means that the filter corresponds to a Riemann-style integral, i.e. in the definition of integrability we require a constant upper estimate `r` on the size of boxes of a tagged partition; the value `false` means that the estimate may depend on the position of the tag. * `bHenstock`: the value `true` means that we require that each tag belongs to its own closed box; the value `false` means that we only require that tags belong to the ambient box. * `bDistortion`: the value `true` means that `r` can depend on the maximal ratio of sides of the same box of a partition. Presence of this case make quite a few proofs harder but we can prove the divergence theorem only for the filter `BoxIntegral.IntegrationParams.GP = βŠ₯ = {bRiemann := false, bHenstock := true, bDistortion := true}`. ### Well-known sets of parameters Out of eight possible values of `BoxIntegral.IntegrationParams`, the following four are used in the library. * `BoxIntegral.IntegrationParams.Riemann` (`bRiemann = true`, `bHenstock = true`, `bDistortion = false`): this value corresponds to the Riemann integral; in the corresponding filter, we require that the diameters of all boxes `J` of a tagged partition are bounded from above by a constant upper estimate that may not depend on the geometry of `J`, and each tag belongs to the corresponding closed box. * `BoxIntegral.IntegrationParams.Henstock` (`bRiemann = false`, `bHenstock = true`, `bDistortion = false`): this value corresponds to the most natural generalization of Henstock-Kurzweil integral to higher dimension; the only (but important!) difference between this theory and Riemann integral is that instead of a constant upper estimate on the size of all boxes of a partition, we require that the partition is *subordinate* to a possibly discontinuous function `r : (ΞΉ β†’ ℝ) β†’ {x : ℝ | 0 < x}`, i.e. each box `J` is included in a closed ball with center `Ο€.tag J` and radius `r J`. * `BoxIntegral.IntegrationParams.McShane` (`bRiemann = false`, `bHenstock = false`, `bDistortion = false`): this value corresponds to the McShane integral; the only difference with the Henstock integral is that we allow tags to be outside of their boxes; the tags still have to be in the ambient closed box, and the partition still has to be subordinate to a function. * `BoxIntegral.IntegrationParams.GP = βŠ₯` (`bRiemann = false`, `bHenstock = true`, `bDistortion = true`): this is the least integration theory in our list, i.e., all functions integrable in any other theory is integrable in this one as well. This is a non-standard generalization of the Henstock-Kurzweil integral to higher dimension. In dimension one, it generates the same filter as `Henstock`. In higher dimension, this generalization defines an integration theory such that the divergence of any FrΓ©chet differentiable function `f` is integrable, and its integral is equal to the sum of integrals of `f` over the faces of the box, taken with appropriate signs. A function `f` is `GP`-integrable if for any `Ξ΅ > 0` and `c : ℝβ‰₯0` there exists `r : (ΞΉ β†’ ℝ) β†’ {x : ℝ | 0 < x}` such that for any tagged partition `Ο€` subordinate to `r`, if each tag belongs to the corresponding closed box and for each box `J ∈ Ο€`, the maximal ratio of its sides is less than or equal to `c`, then the integral sum of `f` over `Ο€` is `Ξ΅`-close to the integral. ### Filters and predicates on `TaggedPrepartition I` For each value of `IntegrationParams` and a rectangular box `I`, we define a few filters on `TaggedPrepartition I`. First, we define a predicate ``` structure BoxIntegral.IntegrationParams.MemBaseSet (l : BoxIntegral.IntegrationParams) (I : BoxIntegral.Box ΞΉ) (c : ℝβ‰₯0) (r : (ΞΉ β†’ ℝ) β†’ Ioi (0 : ℝ)) (Ο€ : BoxIntegral.TaggedPrepartition I) : Prop where ``` This predicate says that * if `l.bHenstock`, then `Ο€` is a Henstock prepartition, i.e. each tag belongs to the corresponding closed box; * `Ο€` is subordinate to `r`; * if `l.bDistortion`, then the distortion of each box in `Ο€` is less than or equal to `c`; * if `l.bDistortion`, then there exists a prepartition `Ο€'` with distortion `≀ c` that covers exactly `I \ Ο€.iUnion`. The last condition is always true for `c > 1`, see TODO section for more details. Then we define a predicate `BoxIntegral.IntegrationParams.RCond` on functions `r : (ΞΉ β†’ ℝ) β†’ {x : ℝ | 0 < x}`. If `l.bRiemann`, then this predicate requires `r` to be a constant function, otherwise it imposes no restrictions on `r`. We introduce this definition to prove a few dot-notation lemmas: e.g., `BoxIntegral.IntegrationParams.RCond.min` says that the pointwise minimum of two functions that satisfy this condition satisfies this condition as well. Then we define four filters on `BoxIntegral.TaggedPrepartition I`. * `BoxIntegral.IntegrationParams.toFilterDistortion`: an auxiliary filter that takes parameters `(l : BoxIntegral.IntegrationParams) (I : BoxIntegral.Box ΞΉ) (c : ℝβ‰₯0)` and returns the filter generated by all sets `{Ο€ | MemBaseSet l I c r Ο€}`, where `r` is a function satisfying the predicate `BoxIntegral.IntegrationParams.RCond l`; * `BoxIntegral.IntegrationParams.toFilter l I`: the supremum of `l.toFilterDistortion I c` over all `c : ℝβ‰₯0`; * `BoxIntegral.IntegrationParams.toFilterDistortioniUnion l I c Ο€β‚€`, where `Ο€β‚€` is a prepartition of `I`: the infimum of `l.toFilterDistortion I c` and the principal filter generated by `{Ο€ | Ο€.iUnion = Ο€β‚€.iUnion}`; * `BoxIntegral.IntegrationParams.toFilteriUnion l I Ο€β‚€`: the supremum of `l.toFilterDistortioniUnion l I c Ο€β‚€` over all `c : ℝβ‰₯0`. This is the filter (in the case `Ο€β‚€ = ⊀` is the one-box partition of `I`) used in the definition of the integral of a function over a box. ## Implementation details * Later we define the integral of a function over a rectangular box as the limit (if it exists) of the integral sums along `BoxIntegral.IntegrationParams.toFilteriUnion l I ⊀`. While it is possible to define the integral with a general filter on `BoxIntegral.TaggedPrepartition I` as a parameter, many lemmas (e.g., Sacks-Henstock lemma and most results about integrability of functions) require the filter to have a predictable structure. So, instead of adding assumptions about the filter here and there, we define this auxiliary type that can encode all integration theories we need in practice. * While the definition of the integral only uses the filter `BoxIntegral.IntegrationParams.toFilteriUnion l I ⊀` and partitions of a box, some lemmas (e.g., the Henstock-Sacks lemmas) are best formulated in terms of the predicate `MemBaseSet` and other filters defined above. * We use `Bool` instead of `Prop` for the fields of `IntegrationParams` in order to have decidable equality and inequalities. ## TODO Currently, `BoxIntegral.IntegrationParams.MemBaseSet` explicitly requires that there exists a partition of the complement `I \ Ο€.iUnion` with distortion `≀ c`. For `c > 1`, this condition is always true but the proof of this fact requires more API about `BoxIntegral.Prepartition.splitMany`. We should formalize this fact, then either require `c > 1` everywhere, or replace `≀ c` with `< c` so that we automatically get `c > 1` for a non-trivial prepartition (and consider the special case `Ο€ = βŠ₯` separately if needed). ## Tags integral, rectangular box, partition, filter -/ open Set Function Filter Metric Finset Bool open scoped Topology Filter NNReal noncomputable section namespace BoxIntegral variable {ΞΉ : Type*} [Fintype ΞΉ] {I J : Box ΞΉ} {c c₁ cβ‚‚ : ℝβ‰₯0} open TaggedPrepartition /-- An `IntegrationParams` is a structure holding 3 Boolean values used to define a filter to be used in the definition of a box-integrable function. -/ @[ext] structure IntegrationParams : Type where /-- `true` if the filter corresponds to a Riemann-style integral, i.e. in the definition of integrability we require a constant upper estimate `r` on the size of boxes of a tagged partition; the value `false` means that the estimate may depend on the position of the tag. -/ (bRiemann : Bool) /-- `true` if we require that each tag belongs to its own closed box; the value `false` means that we only require that tags belong to the ambient box. -/ (bHenstock : Bool) /-- `true` if `r` can depend on the maximal ratio of sides of the same box of a partition. Presence of this case makes quite a few proofs harder but we can prove the divergence theorem only for the filter `BoxIntegral.IntegrationParams.GP = βŠ₯ = {bRiemann := false, bHenstock := true, bDistortion := true}`. -/ (bDistortion : Bool) variable {l l₁ lβ‚‚ : IntegrationParams} namespace IntegrationParams /-- Auxiliary equivalence with a product type used to lift an order. -/ def equivProd : IntegrationParams ≃ Bool Γ— Boolα΅’α΅ˆ Γ— Boolα΅’α΅ˆ where toFun l := ⟨l.1, OrderDual.toDual l.2, OrderDual.toDual l.3⟩ invFun l := ⟨l.1, OrderDual.ofDual l.2.1, OrderDual.ofDual l.2.2⟩ instance : PartialOrder IntegrationParams := PartialOrder.lift equivProd equivProd.injective /-- Auxiliary `OrderIso` with a product type used to lift a `BoundedOrder` structure. -/ def isoProd : IntegrationParams ≃o Bool Γ— Boolα΅’α΅ˆ Γ— Boolα΅’α΅ˆ := ⟨equivProd, Iff.rfl⟩ instance : BoundedOrder IntegrationParams := isoProd.symm.toGaloisInsertion.liftBoundedOrder /-- The value `BoxIntegral.IntegrationParams.GP = βŠ₯` (`bRiemann = false`, `bHenstock = true`, `bDistortion = true`) corresponds to a generalization of the Henstock integral such that the Divergence theorem holds true without additional integrability assumptions, see the module docstring for details. -/ instance : Inhabited IntegrationParams := ⟨βŠ₯⟩ instance : DecidableLE (IntegrationParams) := fun _ _ => inferInstanceAs (Decidable (_ ∧ _)) instance : DecidableEq IntegrationParams := fun _ _ => decidable_of_iff _ IntegrationParams.ext_iff.symm /-- The `BoxIntegral.IntegrationParams` corresponding to the Riemann integral. In the corresponding filter, we require that the diameters of all boxes `J` of a tagged partition are bounded from above by a constant upper estimate that may not depend on the geometry of `J`, and each tag belongs to the corresponding closed box. -/ def Riemann : IntegrationParams where bRiemann := true bHenstock := true bDistortion := false /-- The `BoxIntegral.IntegrationParams` corresponding to the Henstock-Kurzweil integral. In the corresponding filter, we require that the tagged partition is subordinate to a (possibly, discontinuous) positive function `r` and each tag belongs to the corresponding closed box. -/ def Henstock : IntegrationParams := ⟨false, true, false⟩ /-- The `BoxIntegral.IntegrationParams` corresponding to the McShane integral. In the corresponding filter, we require that the tagged partition is subordinate to a (possibly, discontinuous) positive function `r`; the tags may be outside of the corresponding closed box (but still inside the ambient closed box `I.Icc`). -/ def McShane : IntegrationParams := ⟨false, false, false⟩ /-- The `BoxIntegral.IntegrationParams` corresponding to the generalized Perron integral. In the corresponding filter, we require that the tagged partition is subordinate to a (possibly, discontinuous) positive function `r` and each tag belongs to the corresponding closed box. We also require an upper estimate on the distortion of all boxes of the partition. -/ def GP : IntegrationParams := βŠ₯ theorem henstock_le_riemann : Henstock ≀ Riemann := by trivial theorem henstock_le_mcShane : Henstock ≀ McShane := by trivial theorem gp_le : GP ≀ l := bot_le /-- The predicate corresponding to a base set of the filter defined by an `IntegrationParams`. It says that * if `l.bHenstock`, then `Ο€` is a Henstock prepartition, i.e. each tag belongs to the corresponding closed box; * `Ο€` is subordinate to `r`; * if `l.bDistortion`, then the distortion of each box in `Ο€` is less than or equal to `c`; * if `l.bDistortion`, then there exists a prepartition `Ο€'` with distortion `≀ c` that covers exactly `I \ Ο€.iUnion`. The last condition is automatically verified for partitions, and is used in the proof of the Sacks-Henstock inequality to compare two prepartitions covering the same part of the box. It is also automatically satisfied for any `c > 1`, see TODO section of the module docstring for details. -/ structure MemBaseSet (l : IntegrationParams) (I : Box ΞΉ) (c : ℝβ‰₯0) (r : (ΞΉ β†’ ℝ) β†’ Ioi (0 : ℝ)) (Ο€ : TaggedPrepartition I) : Prop where protected isSubordinate : Ο€.IsSubordinate r protected isHenstock : l.bHenstock β†’ Ο€.IsHenstock protected distortion_le : l.bDistortion β†’ Ο€.distortion ≀ c protected exists_compl : l.bDistortion β†’ βˆƒ Ο€' : Prepartition I, Ο€'.iUnion = ↑I \ Ο€.iUnion ∧ Ο€'.distortion ≀ c /-- A predicate saying that in case `l.bRiemann = true`, the function `r` is a constant. -/ def RCond {ΞΉ : Type*} (l : IntegrationParams) (r : (ΞΉ β†’ ℝ) β†’ Ioi (0 : ℝ)) : Prop := l.bRiemann β†’ βˆ€ x, r x = r 0 /-- A set `s : Set (TaggedPrepartition I)` belongs to `l.toFilterDistortion I c` if there exists a function `r : ℝⁿ β†’ (0, ∞)` (or a constant `r` if `l.bRiemann = true`) such that `s` contains each prepartition `Ο€` such that `l.MemBaseSet I c r Ο€`. -/ def toFilterDistortion (l : IntegrationParams) (I : Box ΞΉ) (c : ℝβ‰₯0) : Filter (TaggedPrepartition I) := β¨… (r : (ΞΉ β†’ ℝ) β†’ Ioi (0 : ℝ)) (_ : l.RCond r), π“Ÿ { Ο€ | l.MemBaseSet I c r Ο€ } /-- A set `s : Set (TaggedPrepartition I)` belongs to `l.toFilter I` if for any `c : ℝβ‰₯0` there exists a function `r : ℝⁿ β†’ (0, ∞)` (or a constant `r` if `l.bRiemann = true`) such that `s` contains each prepartition `Ο€` such that `l.MemBaseSet I c r Ο€`. -/ def toFilter (l : IntegrationParams) (I : Box ΞΉ) : Filter (TaggedPrepartition I) := ⨆ c : ℝβ‰₯0, l.toFilterDistortion I c /-- A set `s : Set (TaggedPrepartition I)` belongs to `l.toFilterDistortioniUnion I c Ο€β‚€` if there exists a function `r : ℝⁿ β†’ (0, ∞)` (or a constant `r` if `l.bRiemann = true`) such that `s` contains each prepartition `Ο€` such that `l.MemBaseSet I c r Ο€` and `Ο€.iUnion = Ο€β‚€.iUnion`. -/ def toFilterDistortioniUnion (l : IntegrationParams) (I : Box ΞΉ) (c : ℝβ‰₯0) (Ο€β‚€ : Prepartition I) := l.toFilterDistortion I c βŠ“ π“Ÿ { Ο€ | Ο€.iUnion = Ο€β‚€.iUnion } /-- A set `s : Set (TaggedPrepartition I)` belongs to `l.toFilteriUnion I Ο€β‚€` if for any `c : ℝβ‰₯0` there exists a function `r : ℝⁿ β†’ (0, ∞)` (or a constant `r` if `l.bRiemann = true`) such that `s` contains each prepartition `Ο€` such that `l.MemBaseSet I c r Ο€` and `Ο€.iUnion = Ο€β‚€.iUnion`. -/ def toFilteriUnion (I : Box ΞΉ) (Ο€β‚€ : Prepartition I) := ⨆ c : ℝβ‰₯0, l.toFilterDistortioniUnion I c Ο€β‚€ theorem rCond_of_bRiemann_eq_false {ΞΉ} (l : IntegrationParams) (hl : l.bRiemann = false) {r : (ΞΉ β†’ ℝ) β†’ Ioi (0 : ℝ)} : l.RCond r := by simp [RCond, hl] theorem toFilter_inf_iUnion_eq (l : IntegrationParams) (I : Box ΞΉ) (Ο€β‚€ : Prepartition I) : l.toFilter I βŠ“ π“Ÿ { Ο€ | Ο€.iUnion = Ο€β‚€.iUnion } = l.toFilteriUnion I Ο€β‚€ := (iSup_inf_principal _ _).symm variable {r₁ rβ‚‚ : (ΞΉ β†’ ℝ) β†’ Ioi (0 : ℝ)} {Ο€ π₁ Ο€β‚‚ : TaggedPrepartition I} variable (I) in theorem MemBaseSet.mono' (h : l₁ ≀ lβ‚‚) (hc : c₁ ≀ cβ‚‚) (hr : βˆ€ J ∈ Ο€, r₁ (Ο€.tag J) ≀ rβ‚‚ (Ο€.tag J)) (hΟ€ : l₁.MemBaseSet I c₁ r₁ Ο€) : lβ‚‚.MemBaseSet I cβ‚‚ rβ‚‚ Ο€ := ⟨hΟ€.1.mono' hr, fun hβ‚‚ => hΟ€.2 (le_iff_imp.1 h.2.1 hβ‚‚), fun hD => (hΟ€.3 (le_iff_imp.1 h.2.2 hD)).trans hc, fun hD => (hΟ€.4 (le_iff_imp.1 h.2.2 hD)).imp fun _ hΟ€ => ⟨hΟ€.1, hΟ€.2.trans hc⟩⟩ variable (I) in @[mono] theorem MemBaseSet.mono (h : l₁ ≀ lβ‚‚) (hc : c₁ ≀ cβ‚‚) (hr : βˆ€ x ∈ Box.Icc I, r₁ x ≀ rβ‚‚ x) (hΟ€ : l₁.MemBaseSet I c₁ r₁ Ο€) : lβ‚‚.MemBaseSet I cβ‚‚ rβ‚‚ Ο€ := hΟ€.mono' I h hc fun J _ => hr _ <| Ο€.tag_mem_Icc J theorem MemBaseSet.exists_common_compl (h₁ : l.MemBaseSet I c₁ r₁ π₁) (hβ‚‚ : l.MemBaseSet I cβ‚‚ rβ‚‚ Ο€β‚‚) (hU : π₁.iUnion = Ο€β‚‚.iUnion) : βˆƒ Ο€ : Prepartition I, Ο€.iUnion = ↑I \ π₁.iUnion ∧ (l.bDistortion β†’ Ο€.distortion ≀ c₁) ∧ (l.bDistortion β†’ Ο€.distortion ≀ cβ‚‚) := by wlog hc : c₁ ≀ cβ‚‚ with H Β· simpa [hU, _root_.and_comm] using @H _ _ I cβ‚‚ c₁ l rβ‚‚ r₁ Ο€β‚‚ π₁ hβ‚‚ h₁ hU.symm (le_of_not_ge hc) by_cases hD : (l.bDistortion : Prop) Β· rcases h₁.4 hD with βŸ¨Ο€, hΟ€U, hΟ€c⟩ exact βŸ¨Ο€, hΟ€U, fun _ => hΟ€c, fun _ => hΟ€c.trans hc⟩ Β· exact βŸ¨Ο€β‚.toPrepartition.compl, π₁.toPrepartition.iUnion_compl, fun h => (hD h).elim, fun h => (hD h).elim⟩ protected theorem MemBaseSet.unionComplToSubordinate (hπ₁ : l.MemBaseSet I c r₁ π₁) (hle : βˆ€ x ∈ Box.Icc I, rβ‚‚ x ≀ r₁ x) {Ο€β‚‚ : Prepartition I} (hU : Ο€β‚‚.iUnion = ↑I \ π₁.iUnion) (hc : l.bDistortion β†’ Ο€β‚‚.distortion ≀ c) : l.MemBaseSet I c r₁ (π₁.unionComplToSubordinate Ο€β‚‚ hU rβ‚‚) := ⟨hπ₁.1.disjUnion ((Ο€β‚‚.isSubordinate_toSubordinate rβ‚‚).mono hle) _, fun h => (hπ₁.2 h).disjUnion (Ο€β‚‚.isHenstock_toSubordinate _) _, fun h => (distortion_unionComplToSubordinate _ _ _ _).trans_le (max_le (hπ₁.3 h) (hc h)), fun _ => ⟨βŠ₯, by simp⟩⟩ variable {r : (ΞΉ β†’ ℝ) β†’ Ioi (0 : ℝ)} protected theorem MemBaseSet.filter (hΟ€ : l.MemBaseSet I c r Ο€) (p : Box ΞΉ β†’ Prop) : l.MemBaseSet I c r (Ο€.filter p) := by classical refine ⟨fun J hJ => hΟ€.1 J (Ο€.mem_filter.1 hJ).1, fun hH J hJ => hΟ€.2 hH J (Ο€.mem_filter.1 hJ).1, fun hD => (distortion_filter_le _ _).trans (hΟ€.3 hD), fun hD => ?_⟩ rcases hΟ€.4 hD with βŸ¨Ο€β‚, hπ₁U, hc⟩ set Ο€β‚‚ := Ο€.filter fun J => Β¬p J have : Disjoint π₁.iUnion Ο€β‚‚.iUnion := by simpa [Ο€β‚‚, hπ₁U] using disjoint_sdiff_self_left.mono_right sdiff_le refine βŸ¨Ο€β‚.disjUnion Ο€β‚‚.toPrepartition this, ?_, ?_⟩ Β· suffices ↑I \ Ο€.iUnion βˆͺ Ο€.iUnion \ (Ο€.filter p).iUnion = ↑I \ (Ο€.filter p).iUnion by simp [Ο€β‚‚, *] have h : (Ο€.filter p).iUnion βŠ† Ο€.iUnion := biUnion_subset_biUnion_left (Finset.filter_subset _ _) ext x fconstructor Β· rintro (⟨hxI, hxΟ€βŸ© | ⟨hxΟ€, hxp⟩) exacts [⟨hxI, mt (@h x) hxΟ€βŸ©, βŸ¨Ο€.iUnion_subset hxΟ€, hxp⟩] Β· rintro ⟨hxI, hxp⟩ by_cases hxΟ€ : x ∈ Ο€.iUnion exacts [Or.inr ⟨hxΟ€, hxp⟩, Or.inl ⟨hxI, hxΟ€βŸ©] Β· have : (Ο€.filter fun J => Β¬p J).distortion ≀ c := (distortion_filter_le _ _).trans (hΟ€.3 hD) simpa [hc] theorem biUnionTagged_memBaseSet {Ο€ : Prepartition I} {Ο€i : βˆ€ J, TaggedPrepartition J} (h : βˆ€ J ∈ Ο€, l.MemBaseSet J c r (Ο€i J)) (hp : βˆ€ J ∈ Ο€, (Ο€i J).IsPartition) (hc : l.bDistortion β†’ Ο€.compl.distortion ≀ c) : l.MemBaseSet I c r (Ο€.biUnionTagged Ο€i) := by refine ⟨TaggedPrepartition.isSubordinate_biUnionTagged.2 fun J hJ => (h J hJ).1, fun hH => TaggedPrepartition.isHenstock_biUnionTagged.2 fun J hJ => (h J hJ).2 hH, fun hD => ?_, fun hD => ?_⟩ Β· rw [Prepartition.distortion_biUnionTagged, Finset.sup_le_iff] exact fun J hJ => (h J hJ).3 hD Β· refine ⟨_, ?_, hc hD⟩ rw [Ο€.iUnion_compl, ← Ο€.iUnion_biUnion_partition hp] rfl @[mono] theorem RCond.mono {ΞΉ : Type*} {r : (ΞΉ β†’ ℝ) β†’ Ioi (0 : ℝ)} (h : l₁ ≀ lβ‚‚) (hr : lβ‚‚.RCond r) : l₁.RCond r := fun hR => hr (le_iff_imp.1 h.1 hR) nonrec theorem RCond.min {ΞΉ : Type*} {r₁ rβ‚‚ : (ΞΉ β†’ ℝ) β†’ Ioi (0 : ℝ)} (h₁ : l.RCond r₁) (hβ‚‚ : l.RCond rβ‚‚) : l.RCond fun x => min (r₁ x) (rβ‚‚ x) := fun hR x => congr_argβ‚‚ min (h₁ hR x) (hβ‚‚ hR x) @[gcongr, mono] theorem toFilterDistortion_mono (I : Box ΞΉ) (h : l₁ ≀ lβ‚‚) (hc : c₁ ≀ cβ‚‚) : l₁.toFilterDistortion I c₁ ≀ lβ‚‚.toFilterDistortion I cβ‚‚ := iInf_mono fun _ => iInf_mono' fun hr => ⟨hr.mono h, principal_mono.2 fun _ => MemBaseSet.mono I h hc fun _ _ => le_rfl⟩ @[gcongr, mono] theorem toFilter_mono (I : Box ΞΉ) {l₁ lβ‚‚ : IntegrationParams} (h : l₁ ≀ lβ‚‚) : l₁.toFilter I ≀ lβ‚‚.toFilter I := iSup_mono fun _ => toFilterDistortion_mono I h le_rfl @[gcongr, mono] theorem toFilteriUnion_mono (I : Box ΞΉ) {l₁ lβ‚‚ : IntegrationParams} (h : l₁ ≀ lβ‚‚) (Ο€β‚€ : Prepartition I) : l₁.toFilteriUnion I Ο€β‚€ ≀ lβ‚‚.toFilteriUnion I Ο€β‚€ := iSup_mono fun _ => inf_le_inf_right _ <| toFilterDistortion_mono _ h le_rfl theorem toFilteriUnion_congr (I : Box ΞΉ) (l : IntegrationParams) {π₁ Ο€β‚‚ : Prepartition I} (h : π₁.iUnion = Ο€β‚‚.iUnion) : l.toFilteriUnion I π₁ = l.toFilteriUnion I Ο€β‚‚ := by simp only [toFilteriUnion, toFilterDistortioniUnion, h] theorem hasBasis_toFilterDistortion (l : IntegrationParams) (I : Box ΞΉ) (c : ℝβ‰₯0) : (l.toFilterDistortion I c).HasBasis l.RCond fun r => { Ο€ | l.MemBaseSet I c r Ο€ } := hasBasis_biInf_principal' (fun _ hr₁ _ hrβ‚‚ => ⟨_, hr₁.min hrβ‚‚, fun _ => MemBaseSet.mono _ le_rfl le_rfl fun _ _ => min_le_left _ _, fun _ => MemBaseSet.mono _ le_rfl le_rfl fun _ _ => min_le_right _ _⟩) ⟨fun _ => ⟨1, Set.mem_Ioi.2 zero_lt_one⟩, fun _ _ => rfl⟩ theorem hasBasis_toFilterDistortioniUnion (l : IntegrationParams) (I : Box ΞΉ) (c : ℝβ‰₯0) (Ο€β‚€ : Prepartition I) : (l.toFilterDistortioniUnion I c Ο€β‚€).HasBasis l.RCond fun r => { Ο€ | l.MemBaseSet I c r Ο€ ∧ Ο€.iUnion = Ο€β‚€.iUnion } := (l.hasBasis_toFilterDistortion I c).inf_principal _ theorem hasBasis_toFilteriUnion (l : IntegrationParams) (I : Box ΞΉ) (Ο€β‚€ : Prepartition I) : (l.toFilteriUnion I Ο€β‚€).HasBasis (fun r : ℝβ‰₯0 β†’ (ΞΉ β†’ ℝ) β†’ Ioi (0 : ℝ) => βˆ€ c, l.RCond (r c)) fun r => { Ο€ | βˆƒ c, l.MemBaseSet I c (r c) Ο€ ∧ Ο€.iUnion = Ο€β‚€.iUnion } := by have := fun c => l.hasBasis_toFilterDistortioniUnion I c Ο€β‚€ simpa only [setOf_and, setOf_exists] using hasBasis_iSup this theorem hasBasis_toFilteriUnion_top (l : IntegrationParams) (I : Box ΞΉ) : (l.toFilteriUnion I ⊀).HasBasis (fun r : ℝβ‰₯0 β†’ (ΞΉ β†’ ℝ) β†’ Ioi (0 : ℝ) => βˆ€ c, l.RCond (r c)) fun r => { Ο€ | βˆƒ c, l.MemBaseSet I c (r c) Ο€ ∧ Ο€.IsPartition } := by simpa only [TaggedPrepartition.isPartition_iff_iUnion_eq, Prepartition.iUnion_top] using l.hasBasis_toFilteriUnion I ⊀ theorem hasBasis_toFilter (l : IntegrationParams) (I : Box ΞΉ) : (l.toFilter I).HasBasis (fun r : ℝβ‰₯0 β†’ (ΞΉ β†’ ℝ) β†’ Ioi (0 : ℝ) => βˆ€ c, l.RCond (r c)) fun r => { Ο€ | βˆƒ c, l.MemBaseSet I c (r c) Ο€ } := by simpa only [setOf_exists] using hasBasis_iSup (l.hasBasis_toFilterDistortion I) theorem tendsto_embedBox_toFilteriUnion_top (l : IntegrationParams) (h : I ≀ J) : Tendsto (TaggedPrepartition.embedBox I J h) (l.toFilteriUnion I ⊀) (l.toFilteriUnion J (Prepartition.single J I h)) := by simp only [toFilteriUnion, tendsto_iSup]; intro c set Ο€β‚€ := Prepartition.single J I h refine le_iSup_of_le (max c Ο€β‚€.compl.distortion) ?_ refine ((l.hasBasis_toFilterDistortioniUnion I c ⊀).tendsto_iff (l.hasBasis_toFilterDistortioniUnion J _ _)).2 fun r hr => ?_ refine ⟨r, hr, fun Ο€ hΟ€ => ?_⟩ rw [mem_setOf_eq, Prepartition.iUnion_top] at hΟ€ refine ⟨⟨hΟ€.1.1, hΟ€.1.2, fun hD => le_trans (hΟ€.1.3 hD) (le_max_left _ _), fun _ => ?_⟩, ?_⟩ Β· refine ⟨_, Ο€β‚€.iUnion_compl.trans ?_, le_max_right _ _⟩ congr 1 exact (Prepartition.iUnion_single h).trans hΟ€.2.symm Β· exact hΟ€.2.trans (Prepartition.iUnion_single _).symm theorem exists_memBaseSet_le_iUnion_eq (l : IntegrationParams) (Ο€β‚€ : Prepartition I) (hc₁ : Ο€β‚€.distortion ≀ c) (hcβ‚‚ : Ο€β‚€.compl.distortion ≀ c) (r : (ΞΉ β†’ ℝ) β†’ Ioi (0 : ℝ)) : βˆƒ Ο€, l.MemBaseSet I c r Ο€ ∧ Ο€.toPrepartition ≀ Ο€β‚€ ∧ Ο€.iUnion = Ο€β‚€.iUnion := by rcases Ο€β‚€.exists_tagged_le_isHenstock_isSubordinate_iUnion_eq r with βŸ¨Ο€, hle, hH, hr, hd, hU⟩ refine βŸ¨Ο€, ⟨hr, fun _ => hH, fun _ => hd.trans_le hc₁, fun _ => βŸ¨Ο€β‚€.compl, ?_, hcβ‚‚βŸ©βŸ©, ⟨hle, hU⟩⟩ exact Prepartition.compl_congr hU β–Έ Ο€.toPrepartition.iUnion_compl theorem exists_memBaseSet_isPartition (l : IntegrationParams) (I : Box ΞΉ) (hc : I.distortion ≀ c) (r : (ΞΉ β†’ ℝ) β†’ Ioi (0 : ℝ)) : βˆƒ Ο€, l.MemBaseSet I c r Ο€ ∧ Ο€.IsPartition := by rw [← Prepartition.distortion_top] at hc have hc' : (⊀ : Prepartition I).compl.distortion ≀ c := by simp simpa [isPartition_iff_iUnion_eq] using l.exists_memBaseSet_le_iUnion_eq ⊀ hc hc' r theorem toFilterDistortioniUnion_neBot (l : IntegrationParams) (I : Box ΞΉ) (Ο€β‚€ : Prepartition I) (hc₁ : Ο€β‚€.distortion ≀ c) (hcβ‚‚ : Ο€β‚€.compl.distortion ≀ c) : (l.toFilterDistortioniUnion I c Ο€β‚€).NeBot := ((l.hasBasis_toFilterDistortion I _).inf_principal _).neBot_iff.2 fun {r} _ => (l.exists_memBaseSet_le_iUnion_eq Ο€β‚€ hc₁ hcβ‚‚ r).imp fun _ hΟ€ => ⟨hΟ€.1, hΟ€.2.2⟩ instance toFilterDistortioniUnion_neBot' (l : IntegrationParams) (I : Box ΞΉ) (Ο€β‚€ : Prepartition I) : (l.toFilterDistortioniUnion I (max Ο€β‚€.distortion Ο€β‚€.compl.distortion) Ο€β‚€).NeBot := l.toFilterDistortioniUnion_neBot I Ο€β‚€ (le_max_left _ _) (le_max_right _ _) instance toFilterDistortion_neBot (l : IntegrationParams) (I : Box ΞΉ) : (l.toFilterDistortion I I.distortion).NeBot := by simpa using (l.toFilterDistortioniUnion_neBot' I ⊀).mono inf_le_left instance toFilter_neBot (l : IntegrationParams) (I : Box ΞΉ) : (l.toFilter I).NeBot := (l.toFilterDistortion_neBot I).mono <| le_iSup _ _ instance toFilteriUnion_neBot (l : IntegrationParams) (I : Box ΞΉ) (Ο€β‚€ : Prepartition I) : (l.toFilteriUnion I Ο€β‚€).NeBot := (l.toFilterDistortioniUnion_neBot' I Ο€β‚€).mono <| le_iSup (fun c => l.toFilterDistortioniUnion I c Ο€β‚€) _ theorem eventually_isPartition (l : IntegrationParams) (I : Box ΞΉ) : βˆ€αΆ  Ο€ in l.toFilteriUnion I ⊀, TaggedPrepartition.IsPartition Ο€ := eventually_iSup.2 fun _ => eventually_inf_principal.2 <| Eventually.of_forall fun Ο€ h => Ο€.isPartition_iff_iUnion_eq.2 (h.trans Prepartition.iUnion_top) end IntegrationParams end BoxIntegral
.lake/packages/mathlib/Mathlib/Analysis/BoxIntegral/Partition/SubboxInduction.lean
import Mathlib.Analysis.BoxIntegral.Box.SubboxInduction import Mathlib.Analysis.BoxIntegral.Partition.Tagged /-! # Induction on subboxes In this file we prove (see `BoxIntegral.Box.exists_taggedPartition_isHenstock_isSubordinate_homothetic`) that for every box `I` in `ℝⁿ` and a function `r : ℝⁿ β†’ ℝ` positive on `I` there exists a tagged partition `Ο€` of `I` such that * `Ο€` is a Henstock partition; * `Ο€` is subordinate to `r`; * each box in `Ο€` is homothetic to `I` with coefficient of the form `1 / 2 ^ n`. Later we will use this lemma to prove that the Henstock filter is nontrivial, hence the Henstock integral is well-defined. ## Tags partition, tagged partition, Henstock integral -/ namespace BoxIntegral open Set Metric open Topology noncomputable section variable {ΞΉ : Type*} [Fintype ΞΉ] {I J : Box ΞΉ} namespace Prepartition /-- Split a box in `ℝⁿ` into `2 ^ n` boxes by hyperplanes passing through its center. -/ def splitCenter (I : Box ΞΉ) : Prepartition I where boxes := Finset.univ.map (Box.splitCenterBoxEmb I) le_of_mem' := by simp [I.splitCenterBox_le] pairwiseDisjoint := by rw [Finset.coe_map, Finset.coe_univ, image_univ] rintro _ ⟨s, rfl⟩ _ ⟨t, rfl⟩ Hne exact I.disjoint_splitCenterBox (mt (congr_arg _) Hne) @[simp] theorem mem_splitCenter : J ∈ splitCenter I ↔ βˆƒ s, I.splitCenterBox s = J := by simp [splitCenter] theorem isPartition_splitCenter (I : Box ΞΉ) : IsPartition (splitCenter I) := fun x hx => by simp [hx] theorem upper_sub_lower_of_mem_splitCenter (h : J ∈ splitCenter I) (i : ΞΉ) : J.upper i - J.lower i = (I.upper i - I.lower i) / 2 := let ⟨s, hs⟩ := mem_splitCenter.1 h hs β–Έ I.upper_sub_lower_splitCenterBox s i end Prepartition namespace Box open Prepartition TaggedPrepartition /-- Let `p` be a predicate on `Box ΞΉ`, let `I` be a box. Suppose that the following two properties hold true. * Consider a smaller box `J ≀ I`. The hyperplanes passing through the center of `J` split it into `2 ^ n` boxes. If `p` holds true on each of these boxes, then it true on `J`. * For each `z` in the closed box `I.Icc` there exists a neighborhood `U` of `z` within `I.Icc` such that for every box `J ≀ I` such that `z ∈ J.Icc βŠ† U`, if `J` is homothetic to `I` with a coefficient of the form `1 / 2 ^ m`, then `p` is true on `J`. Then `p I` is true. See also `BoxIntegral.Box.subbox_induction_on'` for a version using `BoxIntegral.Box.splitCenterBox` instead of `BoxIntegral.Prepartition.splitCenter`. -/ @[elab_as_elim] theorem subbox_induction_on {p : Box ΞΉ β†’ Prop} (I : Box ΞΉ) (H_ind : βˆ€ J ≀ I, (βˆ€ J' ∈ splitCenter J, p J') β†’ p J) (H_nhds : βˆ€ z ∈ Box.Icc I, βˆƒ U ∈ 𝓝[Box.Icc I] z, βˆ€ J ≀ I, βˆ€ (m : β„•), z ∈ Box.Icc J β†’ Box.Icc J βŠ† U β†’ (βˆ€ i, J.upper i - J.lower i = (I.upper i - I.lower i) / 2 ^ m) β†’ p J) : p I := by refine subbox_induction_on' I (fun J hle hs => H_ind J hle fun J' h' => ?_) H_nhds rcases mem_splitCenter.1 h' with ⟨s, rfl⟩ exact hs s /-- Given a box `I` in `ℝⁿ` and a function `r : ℝⁿ β†’ (0, ∞)`, there exists a tagged partition `Ο€` of `I` such that * `Ο€` is a Henstock partition; * `Ο€` is subordinate to `r`; * each box in `Ο€` is homothetic to `I` with coefficient of the form `1 / 2 ^ m`. This lemma implies that the Henstock filter is nontrivial, hence the Henstock integral is well-defined. -/ theorem exists_taggedPartition_isHenstock_isSubordinate_homothetic (I : Box ΞΉ) (r : (ΞΉ β†’ ℝ) β†’ Ioi (0 : ℝ)) : βˆƒ Ο€ : TaggedPrepartition I, Ο€.IsPartition ∧ Ο€.IsHenstock ∧ Ο€.IsSubordinate r ∧ (βˆ€ J ∈ Ο€, βˆƒ m : β„•, βˆ€ i, (J :).upper i - J.lower i = (I.upper i - I.lower i) / 2 ^ m) ∧ Ο€.distortion = I.distortion := by refine subbox_induction_on I (fun J _ hJ => ?_) fun z _ => ?_ Β· choose! Ο€i hP hHen hr Hn _ using hJ choose! n hn using Hn have hP : ((splitCenter J).biUnionTagged Ο€i).IsPartition := (isPartition_splitCenter _).biUnionTagged hP have hsub : βˆ€ J' ∈ (splitCenter J).biUnionTagged Ο€i, βˆƒ n : β„•, βˆ€ i, (J' :).upper i - J'.lower i = (J.upper i - J.lower i) / 2 ^ n := by intro J' hJ' rcases (splitCenter J).mem_biUnionTagged.1 hJ' with ⟨J₁, h₁, hβ‚‚βŸ© refine ⟨n J₁ J' + 1, fun i => ?_⟩ simp only [hn J₁ h₁ J' hβ‚‚, upper_sub_lower_of_mem_splitCenter h₁, pow_succ', div_div] refine ⟨_, hP, isHenstock_biUnionTagged.2 hHen, isSubordinate_biUnionTagged.2 hr, hsub, ?_⟩ refine TaggedPrepartition.distortion_of_const _ hP.nonempty_boxes fun J' h' => ?_ rcases hsub J' h' with ⟨n, hn⟩ exact Box.distortion_eq_of_sub_eq_div hn Β· refine ⟨Box.Icc I ∩ closedBall z (r z), inter_mem_nhdsWithin _ (closedBall_mem_nhds _ (r z).coe_prop), ?_⟩ intro J _ n Hmem HIcc Hsub rw [Set.subset_inter_iff] at HIcc refine ⟨single _ _ le_rfl _ Hmem, isPartition_single _, isHenstock_single _, (isSubordinate_single _ _).2 HIcc.2, ?_, distortion_single _ _⟩ simp only [TaggedPrepartition.mem_single, forall_eq] refine ⟨0, fun i => ?_⟩ simp end Box namespace Prepartition open TaggedPrepartition Finset Function /-- Given a box `I` in `ℝⁿ`, a function `r : ℝⁿ β†’ (0, ∞)`, and a prepartition `Ο€` of `I`, there exists a tagged prepartition `Ο€'` of `I` such that * each box of `Ο€'` is included in some box of `Ο€`; * `Ο€'` is a Henstock partition; * `Ο€'` is subordinate to `r`; * `Ο€'` covers exactly the same part of `I` as `Ο€`; * the distortion of `Ο€'` is equal to the distortion of `Ο€`. -/ theorem exists_tagged_le_isHenstock_isSubordinate_iUnion_eq {I : Box ΞΉ} (r : (ΞΉ β†’ ℝ) β†’ Ioi (0 : ℝ)) (Ο€ : Prepartition I) : βˆƒ Ο€' : TaggedPrepartition I, Ο€'.toPrepartition ≀ Ο€ ∧ Ο€'.IsHenstock ∧ Ο€'.IsSubordinate r ∧ Ο€'.distortion = Ο€.distortion ∧ Ο€'.iUnion = Ο€.iUnion := by have := fun J => Box.exists_taggedPartition_isHenstock_isSubordinate_homothetic J r choose! Ο€i Ο€ip Ο€iH Ο€ir _ Ο€id using this refine βŸ¨Ο€.biUnionTagged Ο€i, biUnion_le _ _, isHenstock_biUnionTagged.2 fun J _ => Ο€iH J, isSubordinate_biUnionTagged.2 fun J _ => Ο€ir J, ?_, Ο€.iUnion_biUnion_partition fun J _ => Ο€ip J⟩ rw [distortion_biUnionTagged] exact sup_congr rfl fun J _ => Ο€id J /-- Given a prepartition `Ο€` of a box `I` and a function `r : ℝⁿ β†’ (0, ∞)`, `Ο€.toSubordinate r` is a tagged partition `Ο€'` such that * each box of `Ο€'` is included in some box of `Ο€`; * `Ο€'` is a Henstock partition; * `Ο€'` is subordinate to `r`; * `Ο€'` covers exactly the same part of `I` as `Ο€`; * the distortion of `Ο€'` is equal to the distortion of `Ο€`. -/ def toSubordinate (Ο€ : Prepartition I) (r : (ΞΉ β†’ ℝ) β†’ Ioi (0 : ℝ)) : TaggedPrepartition I := (Ο€.exists_tagged_le_isHenstock_isSubordinate_iUnion_eq r).choose theorem toSubordinate_toPrepartition_le (Ο€ : Prepartition I) (r : (ΞΉ β†’ ℝ) β†’ Ioi (0 : ℝ)) : (Ο€.toSubordinate r).toPrepartition ≀ Ο€ := (Ο€.exists_tagged_le_isHenstock_isSubordinate_iUnion_eq r).choose_spec.1 theorem isHenstock_toSubordinate (Ο€ : Prepartition I) (r : (ΞΉ β†’ ℝ) β†’ Ioi (0 : ℝ)) : (Ο€.toSubordinate r).IsHenstock := (Ο€.exists_tagged_le_isHenstock_isSubordinate_iUnion_eq r).choose_spec.2.1 theorem isSubordinate_toSubordinate (Ο€ : Prepartition I) (r : (ΞΉ β†’ ℝ) β†’ Ioi (0 : ℝ)) : (Ο€.toSubordinate r).IsSubordinate r := (Ο€.exists_tagged_le_isHenstock_isSubordinate_iUnion_eq r).choose_spec.2.2.1 @[simp] theorem distortion_toSubordinate (Ο€ : Prepartition I) (r : (ΞΉ β†’ ℝ) β†’ Ioi (0 : ℝ)) : (Ο€.toSubordinate r).distortion = Ο€.distortion := (Ο€.exists_tagged_le_isHenstock_isSubordinate_iUnion_eq r).choose_spec.2.2.2.1 @[simp] theorem iUnion_toSubordinate (Ο€ : Prepartition I) (r : (ΞΉ β†’ ℝ) β†’ Ioi (0 : ℝ)) : (Ο€.toSubordinate r).iUnion = Ο€.iUnion := (Ο€.exists_tagged_le_isHenstock_isSubordinate_iUnion_eq r).choose_spec.2.2.2.2 end Prepartition namespace TaggedPrepartition /-- Given a tagged prepartition `π₁`, a prepartition `Ο€β‚‚` that covers exactly `I \ π₁.iUnion`, and a function `r : ℝⁿ β†’ (0, ∞)`, returns the union of `π₁` and `Ο€β‚‚.toSubordinate r`. This partition `Ο€` has the following properties: * `Ο€` is a partition, i.e. it covers the whole `I`; * `π₁.boxes βŠ† Ο€.boxes`; * `Ο€.tag J = π₁.tag J` whenever `J ∈ π₁`; * `Ο€` is Henstock outside of `π₁`: `Ο€.tag J ∈ J.Icc` whenever `J ∈ Ο€`, `J βˆ‰ π₁`; * `Ο€` is subordinate to `r` outside of `π₁`; * the distortion of `Ο€` is equal to the maximum of the distortions of `π₁` and `Ο€β‚‚`. -/ def unionComplToSubordinate (π₁ : TaggedPrepartition I) (Ο€β‚‚ : Prepartition I) (hU : Ο€β‚‚.iUnion = ↑I \ π₁.iUnion) (r : (ΞΉ β†’ ℝ) β†’ Ioi (0 : ℝ)) : TaggedPrepartition I := π₁.disjUnion (Ο€β‚‚.toSubordinate r) (((Ο€β‚‚.iUnion_toSubordinate r).trans hU).symm β–Έ disjoint_sdiff_self_right) theorem isPartition_unionComplToSubordinate (π₁ : TaggedPrepartition I) (Ο€β‚‚ : Prepartition I) (hU : Ο€β‚‚.iUnion = ↑I \ π₁.iUnion) (r : (ΞΉ β†’ ℝ) β†’ Ioi (0 : ℝ)) : IsPartition (π₁.unionComplToSubordinate Ο€β‚‚ hU r) := Prepartition.isPartitionDisjUnionOfEqDiff ((Ο€β‚‚.iUnion_toSubordinate r).trans hU) open scoped Classical in @[simp] theorem unionComplToSubordinate_boxes (π₁ : TaggedPrepartition I) (Ο€β‚‚ : Prepartition I) (hU : Ο€β‚‚.iUnion = ↑I \ π₁.iUnion) (r : (ΞΉ β†’ ℝ) β†’ Ioi (0 : ℝ)) : (π₁.unionComplToSubordinate Ο€β‚‚ hU r).boxes = π₁.boxes βˆͺ (Ο€β‚‚.toSubordinate r).boxes := rfl @[simp] theorem iUnion_unionComplToSubordinate_boxes (π₁ : TaggedPrepartition I) (Ο€β‚‚ : Prepartition I) (hU : Ο€β‚‚.iUnion = ↑I \ π₁.iUnion) (r : (ΞΉ β†’ ℝ) β†’ Ioi (0 : ℝ)) : (π₁.unionComplToSubordinate Ο€β‚‚ hU r).iUnion = I := (isPartition_unionComplToSubordinate _ _ _ _).iUnion_eq @[simp] theorem distortion_unionComplToSubordinate (π₁ : TaggedPrepartition I) (Ο€β‚‚ : Prepartition I) (hU : Ο€β‚‚.iUnion = ↑I \ π₁.iUnion) (r : (ΞΉ β†’ ℝ) β†’ Ioi (0 : ℝ)) : (π₁.unionComplToSubordinate Ο€β‚‚ hU r).distortion = max π₁.distortion Ο€β‚‚.distortion := by simp [unionComplToSubordinate] end TaggedPrepartition end end BoxIntegral
.lake/packages/mathlib/Mathlib/Analysis/BoxIntegral/Partition/Measure.lean
import Mathlib.Analysis.BoxIntegral.Partition.Additive import Mathlib.MeasureTheory.Measure.Lebesgue.Basic /-! # Box-additive functions defined by measures In this file we prove a few simple facts about rectangular boxes, partitions, and measures: - given a box `I : Box ΞΉ`, its coercion to `Set (ΞΉ β†’ ℝ)` and `I.Icc` are measurable sets; - if `ΞΌ` is a locally finite measure, then `(I : Set (ΞΉ β†’ ℝ))` and `I.Icc` have finite measure; - if `ΞΌ` is a locally finite measure, then `fun J ↦ ΞΌ.real J` is a box additive function. For the last statement, we both prove it as a proposition and define a bundled `BoxIntegral.BoxAdditiveMap` function. ## Tags rectangular box, measure -/ open Set noncomputable section open scoped ENNReal BoxIntegral variable {ΞΉ : Type*} namespace BoxIntegral open MeasureTheory namespace Box variable (I : Box ΞΉ) theorem measure_Icc_lt_top (ΞΌ : Measure (ΞΉ β†’ ℝ)) [IsLocallyFiniteMeasure ΞΌ] : ΞΌ (Box.Icc I) < ∞ := show ΞΌ (Icc I.lower I.upper) < ∞ from I.isCompact_Icc.measure_lt_top theorem measure_coe_lt_top (ΞΌ : Measure (ΞΉ β†’ ℝ)) [IsLocallyFiniteMeasure ΞΌ] : ΞΌ I < ∞ := (measure_mono <| coe_subset_Icc).trans_lt (I.measure_Icc_lt_top ΞΌ) section Countable variable [Countable ΞΉ] theorem measurableSet_coe : MeasurableSet (I : Set (ΞΉ β†’ ℝ)) := by rw [coe_eq_pi] exact MeasurableSet.univ_pi fun i => measurableSet_Ioc theorem measurableSet_Icc : MeasurableSet (Box.Icc I) := _root_.measurableSet_Icc theorem measurableSet_Ioo : MeasurableSet (Box.Ioo I) := MeasurableSet.univ_pi fun _ => _root_.measurableSet_Ioo end Countable variable [Fintype ΞΉ] theorem coe_ae_eq_Icc : (I : Set (ΞΉ β†’ ℝ)) =ᡐ[volume] Box.Icc I := by rw [coe_eq_pi] exact Measure.univ_pi_Ioc_ae_eq_Icc theorem Ioo_ae_eq_Icc : Box.Ioo I =ᡐ[volume] Box.Icc I := Measure.univ_pi_Ioo_ae_eq_Icc end Box theorem Prepartition.measure_iUnion_toReal [Finite ΞΉ] {I : Box ΞΉ} (Ο€ : Prepartition I) (ΞΌ : Measure (ΞΉ β†’ ℝ)) [IsLocallyFiniteMeasure ΞΌ] : ΞΌ.real Ο€.iUnion = βˆ‘ J ∈ Ο€.boxes, ΞΌ.real J := by simp only [measureReal_def] rw [← ENNReal.toReal_sum (fun J _ => (J.measure_coe_lt_top ΞΌ).ne), Ο€.iUnion_def] simp only [← mem_boxes] rw [measure_biUnion_finset Ο€.pairwiseDisjoint] exact fun J _ => J.measurableSet_coe end BoxIntegral open BoxIntegral BoxIntegral.Box namespace MeasureTheory namespace Measure /-- If `ΞΌ` is a locally finite measure on `ℝⁿ`, then `fun J ↦ ΞΌ.real J` is a box-additive function. -/ @[simps] def toBoxAdditive [Finite ΞΉ] (ΞΌ : Measure (ΞΉ β†’ ℝ)) [IsLocallyFiniteMeasure ΞΌ] : ΞΉ →ᡇᡃ[⊀] ℝ where toFun J := ΞΌ.real J sum_partition_boxes' J _ Ο€ hΟ€ := by rw [← Ο€.measure_iUnion_toReal, hΟ€.iUnion_eq] end Measure end MeasureTheory namespace BoxIntegral open MeasureTheory namespace Box variable [Fintype ΞΉ] -- This is not a `simp` lemma because the left-hand side simplifies already. -- See `volume_apply'` for the relevant `simp` lemma. theorem volume_apply (I : Box ΞΉ) : (volume : Measure (ΞΉ β†’ ℝ)).toBoxAdditive I = ∏ i, (I.upper i - I.lower i) := by rw [Measure.toBoxAdditive_apply, coe_eq_pi, measureReal_def, Real.volume_pi_Ioc_toReal I.lower_le_upper] @[simp] theorem volume_apply' (I : Box ΞΉ) : ((volume : Measure (ΞΉ β†’ ℝ)) I).toReal = ∏ i, (I.upper i - I.lower i) := by rw [coe_eq_pi, Real.volume_pi_Ioc_toReal I.lower_le_upper] theorem volume_face_mul {n} (i : Fin (n + 1)) (I : Box (Fin (n + 1))) : (∏ j, ((I.face i).upper j - (I.face i).lower j)) * (I.upper i - I.lower i) = ∏ j, (I.upper j - I.lower j) := by simp only [face_lower, face_upper, Fin.prod_univ_succAbove _ i, mul_comm] end Box namespace BoxAdditiveMap variable [Fintype ΞΉ] /-- Box-additive map sending each box `I` to the continuous linear endomorphism `x ↦ (volume I).toReal β€’ x`. -/ protected def volume {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] : ΞΉ →ᡇᡃ E β†’L[ℝ] E := (volume : Measure (ΞΉ β†’ ℝ)).toBoxAdditive.toSMul theorem volume_apply {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] (I : Box ΞΉ) (x : E) : BoxAdditiveMap.volume I x = (∏ j, (I.upper j - I.lower j)) β€’ x := by rw [BoxAdditiveMap.volume, toSMul_apply] exact congr_argβ‚‚ (Β· β€’ Β·) I.volume_apply rfl end BoxAdditiveMap end BoxIntegral
.lake/packages/mathlib/Mathlib/Analysis/Meromorphic/FactorizedRational.lean
import Mathlib.Analysis.Meromorphic.Divisor import Mathlib.Analysis.Meromorphic.IsolatedZeros import Mathlib.Analysis.Meromorphic.NormalForm import Mathlib.Analysis.Meromorphic.TrailingCoefficient import Mathlib.Analysis.SpecialFunctions.Log.Basic /-! # Factorized Rational Functions This file discusses functions `π•œ β†’ π•œ` of the form `∏ᢠ u, (Β· - u) ^ d u`, where `d : π•œ β†’ β„€` is integer-valued. We show that these "factorized rational functions" are meromorphic in normal form, with divisor equal to `d`. Under suitable assumptions, we show that meromorphic functions are equivalent, modulo equality on codiscrete sets, to the product of a factorized rational function and an analytic function without zeros. Implementation Note: For consistency, we use `∏ᢠ u, (Β· - u) ^ d u` throughout. If the support of `d` is finite, then evaluation of functions commutes with finprod, and the helper lemma `Function.FactorizedRational.finprod_eval` asserts that `∏ᢠ u, (Β· - u) ^ d u` equals the function `fun x ↦ ∏ᢠ u, (x - u) ^ d u`. If `d` has infinite support, this equality is wrong in general. There are elementary examples of functions `d` where `∏ᢠ u, (Β· - u) ^ d u` is constant one, while `fun x ↦ ∏ᢠ u, (x - u) ^ d u` is not continuous. -/ variable {π•œ : Type*} [NontriviallyNormedField π•œ] {E : Type*} [NormedAddCommGroup E] [NormedSpace π•œ E] {U : Set π•œ} open Filter Function Real Set namespace Function.FactorizedRational /-! ## Elementary Properties of Factorized Rational Functions -/ /-- Helper Lemma: Identify the support of `d` as the mulsupport of the product defining the factorized rational function. -/ lemma mulSupport (d : π•œ β†’ β„€) : (fun u ↦ (Β· - u) ^ d u).mulSupport = d.support := by ext u constructor <;> intro h Β· simp_all only [mem_mulSupport, ne_eq, mem_support] by_contra hCon simp_all [zpow_zero] Β· simp_all only [mem_mulSupport, ne_eq, ne_iff] use u simp_all [zero_zpow_eq_oneβ‚€] /-- Helper Lemma: If the support of `d` is finite, then evaluation of functions commutes with finprod, and the function `∏ᢠ u, (Β· - u) ^ d u` equals `fun x ↦ ∏ᢠ u, (x - u) ^ d u`. -/ lemma finprod_eq_fun {d : π•œ β†’ β„€} (h : d.support.Finite) : (∏ᢠ u, (Β· - u) ^ d u) = fun x ↦ ∏ᢠ u, (x - u) ^ d u := by ext x rw [finprod_eq_prod_of_mulSupport_subset (s := h.toFinset), finprod_eq_prod_of_mulSupport_subset (s := h.toFinset)] Β· simp Β· intro u contrapose simp_all Β· simp [mulSupport d] /-- Factorized rational functions are analytic wherever the exponent is non-negative. -/ theorem analyticAt {d : π•œ β†’ β„€} {x : π•œ} (h : 0 ≀ d x) : AnalyticAt π•œ (∏ᢠ u, (Β· - u) ^ d u) x := by apply analyticAt_finprod intro u by_cases hβ‚‚ : x = u Β· apply AnalyticAt.fun_zpow_nonneg (by fun_prop) rwa [← hβ‚‚] Β· apply AnalyticAt.fun_zpow (by fun_prop) rwa [sub_ne_zero] /-- Factorized rational functions are non-zero wherever the exponent is zero. -/ theorem ne_zero {d : π•œ β†’ β„€} {x : π•œ} (h : d x = 0) : (∏ᢠ u, (Β· - u) ^ d u) x β‰  0 := by by_cases h₁ : (fun u ↦ (Β· - u) ^ d u).mulSupport.Finite Β· rw [finprod_eq_prod _ h₁, Finset.prod_apply, Finset.prod_ne_zero_iff] intro z hz simp only [Pi.pow_apply, ne_eq] by_cases hβ‚‚ : x = z <;> simp_all [zpow_ne_zero, sub_ne_zero] Β· simp [finprod_of_infinite_mulSupport h₁] open Classical in /-- Helper Lemma for Computations: Extract one factor out of a factorized rational function. -/ lemma extractFactor {d : π•œ β†’ β„€} (uβ‚€ : π•œ) (hd : d.support.Finite) : (∏ᢠ u, (Β· - u) ^ d u) = ((Β· - uβ‚€) ^ d uβ‚€) * (∏ᢠ u, (Β· - u) ^ (update d uβ‚€ 0 u)) := by by_cases h₁d : d uβ‚€ = 0 Β· simp [← eq_update_self_iff.2 h₁d, h₁d] Β· have : (fun u ↦ (fun x ↦ x - u) ^ d u).mulSupport βŠ† hd.toFinset := by simp [mulSupport] rw [finprod_eq_prod_of_mulSupport_subset _ this] have : uβ‚€ ∈ hd.toFinset := by simp_all rw [← Finset.mul_prod_erase hd.toFinset _ this] congr 1 have : (fun u ↦ (Β· - u) ^ (update d uβ‚€ 0 u)).mulSupport βŠ† hd.toFinset.erase uβ‚€ := by rw [mulSupport] intro x hx by_cases h₁x : x = uβ‚€ <;> simp_all simp_all [finprod_eq_prod_of_mulSupport_subset _ this, Finset.prod_congr rfl] /-- Factorized rational functions are meromorphic in normal form on `univ`. -/ theorem meromorphicNFOn_univ (d : π•œ β†’ β„€) : MeromorphicNFOn (∏ᢠ u, (Β· - u) ^ d u) univ := by classical by_cases hd : d.support.Finite Β· intro z hz rw [extractFactor z hd] right use d z, (∏ᢠ u, (Β· - u) ^ update d z 0 u) simp [analyticAt, ne_zero] Β· rw [← mulSupport d] at hd rw [finprod_of_infinite_mulSupport hd] exact AnalyticOnNhd.meromorphicNFOn analyticOnNhd_const /-- Factorized rational functions are meromorphic in normal form on arbitrary subsets of `π•œ`. -/ theorem meromorphicNFOn (d : π•œ β†’ β„€) (U : Set π•œ) : MeromorphicNFOn (∏ᢠ u, (Β· - u) ^ d u) U := fun _ _ ↦ meromorphicNFOn_univ d (trivial) /-! ## Orders and Divisors of Factorized Rational Functions -/ /-- The order of the factorized rational function `(∏ᢠ u, fun z ↦ (z - u) ^ d u)` at `z` equals `d z`. -/ theorem meromorphicOrderAt_eq {z : π•œ} (d : π•œ β†’ β„€) (h₁d : d.support.Finite) : meromorphicOrderAt (∏ᢠ u, (Β· - u) ^ d u) z = d z := by classical rw [meromorphicOrderAt_eq_int_iff ((meromorphicNFOn_univ d).meromorphicOn _ (mem_univ _))] use ∏ᢠ u, (Β· - u) ^ update d z 0 u simp only [update_self, le_refl, analyticAt, ne_eq, ne_zero, not_false_eq_true, smul_eq_mul, true_and] filter_upwards simp [extractFactor z h₁d] @[deprecated (since := "2025-05-22")] alias order := meromorphicOrderAt_eq /-- Factorized rational functions are nowhere locally constant zero. -/ theorem meromorphicOrderAt_ne_top {z : π•œ} (d : π•œ β†’ β„€) : meromorphicOrderAt (∏ᢠ u, (Β· - u) ^ d u) z β‰  ⊀ := by classical by_cases hd : d.support.Finite Β· simp [meromorphicOrderAt_eq d hd] Β· rw [← mulSupport] at hd simp [finprod_of_infinite_mulSupport hd] @[deprecated (since := "2025-05-22")] alias order_ne_top := meromorphicOrderAt_ne_top /-- If `D` is a divisor, then the divisor of the factorized rational function equals `D`. -/ theorem divisor {U : Set π•œ} {D : locallyFinsuppWithin U β„€} (hD : D.support.Finite) : MeromorphicOn.divisor (∏ᢠ u, (Β· - u) ^ D u) U = D := by ext z by_cases hz : z ∈ U <;> simp [(meromorphicNFOn D U).meromorphicOn, hz, meromorphicOrderAt_eq D hD] open Classical in private lemma mulSupport_update {d : π•œ β†’ β„€} {x : π•œ} (h : d.support.Finite) : (fun u ↦ (x - u) ^ Function.update d x 0 u).mulSupport βŠ† h.toFinset := by intro u contrapose simp only [mem_mulSupport, ne_eq, Decidable.not_not] by_cases h₁ : u = x Β· rw [h₁] simp Β· simp_all open Classical in /-- Compute the trailing coefficient of the factorized rational function associated with `d : π•œ β†’ β„€`. -/ /- Low-priority TODO: Using that non-trivially normed fields contain infinitely many elements that are no roots of unity, it might be possible to drop assumption `h` here and in some of the theorems below. -/ theorem meromorphicTrailingCoeffAt_factorizedRational {d : π•œ β†’ β„€} {x : π•œ} (h : d.support.Finite) : meromorphicTrailingCoeffAt (∏ᢠ u, (Β· - u) ^ d u) x = ∏ᢠ u, (x - u) ^ update d x 0 u := by have : (fun u ↦ (Β· - u) ^ d u).mulSupport βŠ† h.toFinset := by simp [Function.FactorizedRational.mulSupport] rw [finprod_eq_prod_of_mulSupport_subset _ this, meromorphicTrailingCoeffAt_prod (fun _ ↦ by fun_prop), finprod_eq_prod_of_mulSupport_subset _ (mulSupport_update h)] apply Finset.prod_congr rfl intro y hy rw [MeromorphicAt.meromorphicTrailingCoeffAt_zpow (by fun_prop)] by_cases hxy : x = y Β· rw [hxy, meromorphicTrailingCoeffAt_id_sub_const] simp_all Β· grind [meromorphicTrailingCoeffAt_id_sub_const] /-- Variant of `meromorphicTrailingCoeffAt_factorizedRational`: Compute the trailing coefficient of the factorized rational function associated with `d : π•œ β†’ β„€` at points outside the support of `d`. -/ theorem meromorphicTrailingCoeffAt_factorizedRational_off_support {d : π•œ β†’ β„€} {x : π•œ} (h₁ : d.support.Finite) (hβ‚‚ : x βˆ‰ d.support) : meromorphicTrailingCoeffAt (∏ᢠ u, (Β· - u) ^ d u) x = ∏ᢠ u, (x - u) ^ d u := by classical rw [meromorphicTrailingCoeffAt_factorizedRational h₁, finprod_eq_prod_of_mulSupport_subset _ (mulSupport_update h₁)] have : (fun u ↦ (x - u) ^ d u).mulSupport βŠ† h₁.toFinset := by intro u contrapose simp_all rw [finprod_eq_prod_of_mulSupport_subset _ this, Finset.prod_congr rfl] intro y hy congr apply Function.update_of_ne by_contra hCon simp_all /-- Variant of `meromorphicTrailingCoeffAt_factorizedRational`: Compute log of the norm of the trailing coefficient. The convention that `log 0 = 0` gives a closed formula easier than the one in `meromorphicTrailingCoeffAt_factorizedRational`. -/ theorem log_norm_meromorphicTrailingCoeffAt {d : π•œ β†’ β„€} {x : π•œ} (h : d.support.Finite) : log β€–meromorphicTrailingCoeffAt (∏ᢠ u, (Β· - u) ^ d u) xβ€– = βˆ‘αΆ  u, (d u) * log β€–x - uβ€– := by classical rw [meromorphicTrailingCoeffAt_factorizedRational h, finprod_eq_prod_of_mulSupport_subset _ (mulSupport_update h)] have : βˆ€ y ∈ h.toFinset, β€–(x - y) ^ update d x 0 yβ€– β‰  0 := by intro y _ by_cases h : x = y Β· rw [h] simp_all Β· simp_all [zpow_ne_zero, sub_ne_zero] rw [norm_prod, log_prod this] have : (fun u ↦ (d u) * log β€–x - uβ€–).support βŠ† h.toFinset := by intro u contrapose simp_all rw [finsum_eq_sum_of_support_subset _ this] apply Finset.sum_congr rfl intro y hy rw [norm_zpow, Real.log_zpow] by_cases h : x = y Β· simp [h] Β· rw [Function.update_of_ne (by tauto)] end Function.FactorizedRational open Function.FactorizedRational /-! ## Elimination of Zeros and Poles This section shows that every meromorphic function with finitely many zeros and poles is equivalent, modulo equality on codiscrete sets, to the product of a factorized rational function and an analytic function without zeros. We provide analogous results for functions of the form `log β€–meromorphicβ€–`. -/ /- TODO: Identify some of the terms that appear in the decomposition. -/ /-- If `f` is meromorphic on an open set `U`, if `f` is nowhere locally constant zero, and if the support of the divisor of `f` is finite, then there exists an analytic function `g` on `U` without zeros such that `f` is equivalent, modulo equality on codiscrete sets, to the product of `g` and the factorized rational function associated with the divisor of `f`. -/ theorem MeromorphicOn.extract_zeros_poles {f : π•œ β†’ E} (h₁f : MeromorphicOn f U) (hβ‚‚f : βˆ€ u : U, meromorphicOrderAt f u β‰  ⊀) (h₃f : (divisor f U).support.Finite) : βˆƒ g : π•œ β†’ E, AnalyticOnNhd π•œ g U ∧ (βˆ€ u : U, g u β‰  0) ∧ f =αΆ [codiscreteWithin U] (∏ᢠ u, (Β· - u) ^ divisor f U u) β€’ g := by -- Take `g` as the inverse of the Laurent polynomial defined below, converted to a meromorphic -- function in normal form. Then check all the properties. let Ο† := ∏ᢠ u, (Β· - u) ^ (divisor f U u) have hΟ† : MeromorphicOn Ο† U := (meromorphicNFOn (divisor f U) U).meromorphicOn let g := toMeromorphicNFOn (φ⁻¹ β€’ f) U have hg : MeromorphicNFOn g U := by apply meromorphicNFOn_toMeromorphicNFOn refine ⟨g, ?_, ?_, ?_⟩ Β· -- AnalyticOnNhd π•œ g U rw [← hg.divisor_nonneg_iff_analyticOnNhd, divisor_of_toMeromorphicNFOn (hΟ†.inv.smul h₁f), divisor_smul hΟ†.inv h₁f _ (fun z hz ↦ hβ‚‚f ⟨z, hz⟩), divisor_inv, Function.FactorizedRational.divisor h₃f, neg_add_cancel] intro z hz simpa [meromorphicOrderAt_inv] using meromorphicOrderAt_ne_top (divisor f U) Β· -- βˆ€ (u : ↑U), g ↑u β‰  0 intro ⟨u, hu⟩ rw [← (hg hu).meromorphicOrderAt_eq_zero_iff, ← meromorphicOrderAt_congr (toMeromorphicNFOn_eq_self_on_nhdsNE (hΟ†.inv.smul h₁f) hu).symm, meromorphicOrderAt_smul (hΟ† u hu).inv (h₁f u hu), meromorphicOrderAt_inv, meromorphicOrderAt_eq _ h₃f] simp only [h₁f, hu, divisor_apply] lift meromorphicOrderAt f u to β„€ using (hβ‚‚f ⟨u, hu⟩) with n hn rw [WithTop.untopβ‚€_coe, ← WithTop.LinearOrderedAddCommGroup.coe_neg, ← WithTop.coe_add] simp Β· -- f =αΆ [codiscreteWithin U] (∏ᢠ (u : π•œ), fun z ↦ (z - u) ^ (divisor f U) u) * g filter_upwards [(divisor f U).eq_zero_codiscreteWithin, (hΟ†.inv.smul h₁f).meromorphicNFAt_mem_codiscreteWithin, self_mem_codiscreteWithin U] with a hβ‚‚a h₃a hβ‚„a unfold g simp only [Pi.smul_apply', toMeromorphicNFOn_eq_toMeromorphicNFAt (hΟ†.inv.smul h₁f) hβ‚„a, toMeromorphicNFAt_eq_self.2 h₃a, Pi.inv_apply] rw [← smul_assoc, smul_eq_mul, mul_inv_cancelβ‚€ _, one_smul] rwa [← ((meromorphicNFOn_univ (divisor f U)) trivial).meromorphicOrderAt_eq_zero_iff, meromorphicOrderAt_eq, hβ‚‚a, Pi.zero_apply, WithTop.coe_zero] /-- In the setting of `MeromorphicOn.extract_zeros_poles`, the function `log β€–fβ€–` is equivalent, modulo equality on codiscrete subsets, to `βˆ‘αΆ  u, (divisor f U u * log β€–Β· - uβ€–) + log β€–g Β·β€–`. -/ theorem MeromorphicOn.extract_zeros_poles_log {f g : π•œ β†’ E} {D : Function.locallyFinsuppWithin U β„€} (hg : βˆ€ u : U, g u β‰  0) (h : f =αΆ [codiscreteWithin U] (∏ᢠ u, (Β· - u) ^ D u) β€’ g) : (log β€–f Β·β€–) =αΆ [codiscreteWithin U] βˆ‘αΆ  u, (D u * log β€–Β· - uβ€–) + (log β€–g Β·β€–) := by -- Identify support of the sum in the goal have t₁ : (fun u ↦ (D u * log β€–Β· - uβ€–)).support = D.support := by ext u rw [← not_iff_not] simp only [ne_eq, not_not, Function.mem_support] constructor <;> intro hx Β· obtain ⟨y, hy⟩ := NormedField.exists_one_lt_norm π•œ have := congrFun hx (y + u) simp only [add_sub_cancel_right, Pi.zero_apply, mul_eq_zero, Int.cast_eq_zero, log_eq_zero, norm_eq_zero] at this rcases this with h | h | h | h Β· assumption Β· simp only [h, norm_zero] at hy linarith Β· simp only [h, lt_self_iff_false] at hy Β· simp only [h, lt_neg_self_iff] at hy linarith Β· simp_all [Pi.zero_def] -- Trivial case: the support of D is infinite by_cases h₃f : D.support.Finite case neg => rw [finsum_of_infinite_support (by simpa [t₁] using h₃f)] rw [finprod_of_infinite_mulSupport (by simpa [FactorizedRational.mulSupport] using h₃f)] at h filter_upwards [h] with x hx simp [hx] -- General case filter_upwards [h, D.eq_zero_codiscreteWithin, self_mem_codiscreteWithin U] with z hz hβ‚‚z h₃z rw [Pi.zero_apply] at hβ‚‚z rw [hz, finprod_eq_prod_of_mulSupport_subset (s := h₃f.toFinset) _ (by simp_all [FactorizedRational.mulSupport]), finsum_eq_sum_of_support_subset (s := h₃f.toFinset) _ (by simp_all)] have : βˆ€ x ∈ h₃f.toFinset, β€–z - xβ€– ^ D x β‰  0 := by intro x hx rw [Finite.mem_toFinset, Function.mem_support] at hx rw [ne_eq, zpow_eq_zero_iff hx, norm_eq_zero, sub_eq_zero, eq_comm] apply ne_of_apply_ne D rwa [hβ‚‚z] simp only [Pi.smul_apply', Finset.prod_apply, Pi.pow_apply, norm_smul, norm_prod, norm_zpow] rw [log_mul (Finset.prod_ne_zero_iff.2 this) (by simp [hg ⟨z, h₃z⟩]), log_prod this] simp [log_zpow] open Classical in /-- In the setting of `MeromorphicOn.extract_zeros_poles`, compute the trailing coefficient of `f` in terms of `divisor f U` and `g x`. -/ theorem MeromorphicOn.meromorphicTrailingCoeffAt_extract_zeros_poles {x : π•œ} {f g : π•œ β†’ E} {D : π•œ β†’ β„€} (hD : D.support.Finite) (h₁x : x ∈ U) (hβ‚‚x : AccPt x (π“Ÿ U)) (hf : MeromorphicAt f x) (h₁g : AnalyticAt π•œ g x) (hβ‚‚g : g x β‰  0) (h : f =αΆ [codiscreteWithin U] (∏ᢠ u, (Β· - u) ^ D u) β€’ g) : meromorphicTrailingCoeffAt f x = (∏ᢠ u, (x - u) ^ Function.update D x 0 u) β€’ g x := by have tβ‚€ : MeromorphicAt (∏ᢠ u, (Β· - u) ^ D u) x := (FactorizedRational.meromorphicNFOn D U).meromorphicOn x h₁x rw [meromorphicTrailingCoeffAt_congr_nhdsNE (hf.eventuallyEq_nhdsNE_of_eventuallyEq_codiscreteWithin (by fun_prop) h₁x hβ‚‚x h), tβ‚€.meromorphicTrailingCoeffAt_smul h₁g.meromorphicAt, h₁g.meromorphicTrailingCoeffAt_of_ne_zero hβ‚‚g] simp [meromorphicTrailingCoeffAt_factorizedRational hD] /-- In the setting of `MeromorphicOn.extract_zeros_poles`, compute the log of the norm of the trailing coefficient of `f` in terms of `divisor f U` and `g x`. -/ theorem MeromorphicOn.log_norm_meromorphicTrailingCoeffAt_extract_zeros_poles {x : π•œ} {f g : π•œ β†’ E} {D : π•œ β†’ β„€} (hD : D.support.Finite) (h₁x : x ∈ U) (hβ‚‚x : AccPt x (π“Ÿ U)) (hf : MeromorphicAt f x) (h₁g : AnalyticAt π•œ g x) (hβ‚‚g : g x β‰  0) (h : f =αΆ [codiscreteWithin U] (∏ᢠ u, (Β· - u) ^ D u) β€’ g) : log β€–meromorphicTrailingCoeffAt f xβ€– = βˆ‘αΆ  u, (D u) * log β€–x - uβ€– + log β€–g xβ€– := by rw [meromorphicTrailingCoeffAt_congr_nhdsNE (hf.eventuallyEq_nhdsNE_of_eventuallyEq_codiscreteWithin (((FactorizedRational.meromorphicNFOn D U).meromorphicOn x h₁x).smul h₁g.meromorphicAt) h₁x hβ‚‚x h), ((FactorizedRational.meromorphicNFOn D U).meromorphicOn x h₁x).meromorphicTrailingCoeffAt_smul h₁g.meromorphicAt, h₁g.meromorphicTrailingCoeffAt_of_ne_zero hβ‚‚g, norm_smul, log_mul, log_norm_meromorphicTrailingCoeffAt hD] Β· simp only [ne_eq, norm_eq_zero] apply MeromorphicAt.meromorphicTrailingCoeffAt_ne_zero ((FactorizedRational.meromorphicNFOn D U).meromorphicOn x h₁x) apply FactorizedRational.meromorphicOrderAt_ne_top Β· simp_all
.lake/packages/mathlib/Mathlib/Analysis/Meromorphic/Order.lean
import Mathlib.Algebra.Order.WithTop.Untop0 import Mathlib.Analysis.Analytic.Order import Mathlib.Analysis.Meromorphic.Basic /-! # Orders of Meromorphic Functions This file defines the order of a meromorphic function `f` at a point `zβ‚€`, as an element of `β„€ βˆͺ {∞}`. We characterize the order being `< 0`, or `= 0`, or `> 0`, as the convergence of the function to infinity, resp. a nonzero constant, resp. zero. ## TODO Uniformize API between analytic and meromorphic functions -/ open Filter Set WithTop.LinearOrderedAddCommGroup open scoped Topology variable {π•œ : Type*} [NontriviallyNormedField π•œ] {E : Type*} [NormedAddCommGroup E] [NormedSpace π•œ E] {f f₁ fβ‚‚ : π•œ β†’ E} {x : π•œ} /-! ## Order at a Point: Definition and Characterization -/ open scoped Classical in /-- The order of a meromorphic function `f` at `zβ‚€`, as an element of `β„€ βˆͺ {∞}`. The order is defined to be `∞` if `f` is identically 0 on a neighbourhood of `zβ‚€`, and otherwise the unique `n` such that `f` can locally be written as `f z = (z - zβ‚€) ^ n β€’ g z`, where `g` is analytic and does not vanish at `zβ‚€`. See `MeromorphicAt.meromorphicOrderAt_eq_top_iff` and `MeromorphicAt.meromorphicOrderAt_eq_int_iff` for these equivalences. If the function is not meromorphic at `x`, we use the junk value `0`. -/ noncomputable def meromorphicOrderAt (f : π•œ β†’ E) (x : π•œ) : WithTop β„€ := if hf : MeromorphicAt f x then ((analyticOrderAt (fun z ↦ (z - x) ^ hf.choose β€’ f z) x).map (↑· : β„• β†’ β„€)) - hf.choose else 0 @[deprecated (since := "2025-05-22")] alias MeromorphicAt.order := meromorphicOrderAt @[simp] lemma meromorphicOrderAt_of_not_meromorphicAt (hf : Β¬ MeromorphicAt f x) : meromorphicOrderAt f x = 0 := dif_neg hf lemma meromorphicAt_of_meromorphicOrderAt_ne_zero (hf : meromorphicOrderAt f x β‰  0) : MeromorphicAt f x := by contrapose! hf simp [hf] /-- The order of a meromorphic function `f` at a `zβ‚€` is infinity iff `f` vanishes locally around `zβ‚€`. -/ lemma meromorphicOrderAt_eq_top_iff : meromorphicOrderAt f x = ⊀ ↔ βˆ€αΆ  z in 𝓝[β‰ ] x, f z = 0 := by by_cases hf : MeromorphicAt f x; swap Β· simp only [hf, not_false_eq_true, meromorphicOrderAt_of_not_meromorphicAt, WithTop.zero_ne_top, false_iff] contrapose! hf exact (MeromorphicAt.const 0 x).congr (EventuallyEq.symm hf) simp only [meromorphicOrderAt, hf, ↓reduceDIte, sub_eq_top_iff, ENat.map_eq_top_iff, WithTop.natCast_ne_top, or_false] by_cases h : analyticOrderAt (fun z ↦ (z - x) ^ hf.choose β€’ f z) x = ⊀ Β· simp only [h, eventually_nhdsWithin_iff, mem_compl_iff, mem_singleton_iff, true_iff] rw [analyticOrderAt_eq_top] at h filter_upwards [h] with z hf hz rwa [smul_eq_zero_iff_right <| pow_ne_zero _ (sub_ne_zero.mpr hz)] at hf Β· obtain ⟨m, hm⟩ := ENat.ne_top_iff_exists.mp h simp only [← hm, ENat.coe_ne_top, false_iff] contrapose! h rw [analyticOrderAt_eq_top] rw [← hf.choose_spec.frequently_eq_iff_eventually_eq analyticAt_const] apply Eventually.frequently filter_upwards [h] with z hfz rw [hfz, smul_zero] @[deprecated (since := "2025-05-22")] alias MeromorphicAt.order_eq_top_iff := meromorphicOrderAt_eq_top_iff /-- The order of a meromorphic function `f` at `zβ‚€` equals an integer `n` iff `f` can locally be written as `f z = (z - zβ‚€) ^ n β€’ g z`, where `g` is analytic and does not vanish at `zβ‚€`. -/ lemma meromorphicOrderAt_eq_int_iff {n : β„€} (hf : MeromorphicAt f x) : meromorphicOrderAt f x = n ↔ βˆƒ g : π•œ β†’ E, AnalyticAt π•œ g x ∧ g x β‰  0 ∧ βˆ€αΆ  z in 𝓝[β‰ ] x, f z = (z - x) ^ n β€’ g z := by simp only [meromorphicOrderAt, hf, ↓reduceDIte] by_cases h : analyticOrderAt (fun z ↦ (z - x) ^ hf.choose β€’ f z) x = ⊀ Β· rw [h, ENat.map_top, ← WithTop.coe_natCast, top_sub, eq_false_intro WithTop.top_ne_coe, false_iff] rw [analyticOrderAt_eq_top] at h refine fun ⟨g, hg_an, hg_ne, hg_eq⟩ ↦ hg_ne ?_ apply EventuallyEq.eq_of_nhds rw [EventuallyEq, ← AnalyticAt.frequently_eq_iff_eventually_eq hg_an analyticAt_const] apply Eventually.frequently rw [eventually_nhdsWithin_iff] at hg_eq ⊒ filter_upwards [h, hg_eq] with z hfz hfz_eq hz rwa [hfz_eq hz, ← mul_smul, smul_eq_zero_iff_right] at hfz exact mul_ne_zero (pow_ne_zero _ (sub_ne_zero.mpr hz)) (zpow_ne_zero _ (sub_ne_zero.mpr hz)) Β· obtain ⟨m, h⟩ := ENat.ne_top_iff_exists.mp h rw [← h, ENat.map_coe, ← WithTop.coe_natCast, ← coe_sub, WithTop.coe_inj] obtain ⟨g, hg_an, hg_ne, hg_eq⟩ := hf.choose_spec.analyticOrderAt_eq_natCast.mp h.symm replace hg_eq : βˆ€αΆ  (z : π•œ) in 𝓝[β‰ ] x, f z = (z - x) ^ (↑m - ↑hf.choose : β„€) β€’ g z := by rw [eventually_nhdsWithin_iff] filter_upwards [hg_eq] with z hg_eq hz rwa [← smul_right_inj <| zpow_ne_zero _ (sub_ne_zero.mpr hz), ← mul_smul, ← zpow_addβ‚€ (sub_ne_zero.mpr hz), ← add_sub_assoc, add_sub_cancel_left, zpow_natCast, zpow_natCast] exact ⟨fun h ↦ ⟨g, hg_an, hg_ne, h β–Έ hg_eq⟩, AnalyticAt.unique_eventuallyEq_zpow_smul_nonzero ⟨g, hg_an, hg_ne, hg_eq⟩⟩ @[deprecated (since := "2025-05-22")] alias MeromorphicAt.order_eq_inf_iff := meromorphicOrderAt_eq_int_iff /-- The order of a meromorphic function `f` at `zβ‚€` is finite iff `f` can locally be written as `f z = (z - zβ‚€) ^ order β€’ g z`, where `g` is analytic and does not vanish at `zβ‚€`. -/ theorem meromorphicOrderAt_ne_top_iff {f : π•œ β†’ E} {zβ‚€ : π•œ} (hf : MeromorphicAt f zβ‚€) : meromorphicOrderAt f zβ‚€ β‰  ⊀ ↔ βˆƒ (g : π•œ β†’ E), AnalyticAt π•œ g zβ‚€ ∧ g zβ‚€ β‰  0 ∧ f =αΆ [𝓝[β‰ ] zβ‚€] fun z ↦ (z - zβ‚€) ^ ((meromorphicOrderAt f zβ‚€).untopβ‚€) β€’ g z := ⟨fun h ↦ (meromorphicOrderAt_eq_int_iff hf).1 (WithTop.coe_untopβ‚€_of_ne_top h).symm, fun h ↦ Option.ne_none_iff_exists'.2 ⟨(meromorphicOrderAt f zβ‚€).untopD 0, (meromorphicOrderAt_eq_int_iff hf).2 h⟩⟩ @[deprecated (since := "2025-05-22")] alias MeromorphicAt.order_ne_top_iff := meromorphicOrderAt_ne_top_iff /-- The order of a meromorphic function `f` at `zβ‚€` is finite iff `f` does not have any zeros in a sufficiently small neighborhood of `zβ‚€`. -/ theorem meromorphicOrderAt_ne_top_iff_eventually_ne_zero {f : π•œ β†’ E} (hf : MeromorphicAt f x) : meromorphicOrderAt f x β‰  ⊀ ↔ βˆ€αΆ  x in 𝓝[β‰ ] x, f x β‰  0 := by constructor Β· intro h obtain ⟨g, h₁g, hβ‚‚g, h₃g⟩ := (meromorphicOrderAt_ne_top_iff hf).1 h filter_upwards [h₃g, self_mem_nhdsWithin, eventually_nhdsWithin_of_eventually_nhds ((h₁g.continuousAt.ne_iff_eventually_ne continuousAt_const).mp hβ‚‚g)] simp_all [zpow_ne_zero, sub_ne_zero] Β· simp_all [meromorphicOrderAt_eq_top_iff, Eventually.frequently] @[deprecated (since := "2025-05-22")] alias MeromorphicAt.order_ne_top_iff_eventually_ne_zero := meromorphicOrderAt_ne_top_iff_eventually_ne_zero /-- If the order of a meromorphic function is negative, then this function converges to infinity at this point. See also the iff version `tendsto_cobounded_iff_meromorphicOrderAt_neg`. -/ lemma tendsto_cobounded_of_meromorphicOrderAt_neg (ho : meromorphicOrderAt f x < 0) : Tendsto f (𝓝[β‰ ] x) (Bornology.cobounded E) := by have hf : MeromorphicAt f x := meromorphicAt_of_meromorphicOrderAt_ne_zero ho.ne simp only [← tendsto_norm_atTop_iff_cobounded] obtain ⟨m, hm⟩ := WithTop.ne_top_iff_exists.mp ho.ne_top have m_neg : m < 0 := by simpa [← hm] using ho rcases (meromorphicOrderAt_eq_int_iff hf).1 hm.symm with ⟨g, g_an, gx, hg⟩ have A : Tendsto (fun z ↦ β€–(z - x) ^ m β€’ g zβ€–) (𝓝[β‰ ] x) atTop := by simp only [norm_smul] apply Filter.Tendsto.atTop_mul_pos (C := β€–g xβ€–) (by simp [gx]) _ g_an.continuousAt.continuousWithinAt.tendsto.norm have : Tendsto (fun z ↦ z - x) (𝓝[β‰ ] x) (𝓝[β‰ ] 0) := by refine tendsto_nhdsWithin_iff.2 ⟨?_, ?_⟩ Β· have : ContinuousWithinAt (fun z ↦ z - x) ({x}ᢜ) x := ContinuousAt.continuousWithinAt (by fun_prop) simpa using this.tendsto Β· filter_upwards [self_mem_nhdsWithin] with y hy simpa [sub_eq_zero] using hy apply Tendsto.comp (NormedField.tendsto_norm_zpow_nhdsNE_zero_atTop m_neg) this apply A.congr' filter_upwards [hg] with z hz using by simp [hz] @[deprecated (since := "2025-05-22")] alias MeromorphicAt.tendsto_cobounded_of_order_neg := tendsto_cobounded_of_meromorphicOrderAt_neg /-- If the order of a meromorphic function is zero, then this function converges to a nonzero limit at this point. See also the iff version `tendsto_ne_zero_iff_meromorphicOrderAt_eq_zero`. -/ lemma tendsto_ne_zero_of_meromorphicOrderAt_eq_zero (hf : MeromorphicAt f x) (ho : meromorphicOrderAt f x = 0) : βˆƒ c β‰  0, Tendsto f (𝓝[β‰ ] x) (𝓝 c) := by rcases (meromorphicOrderAt_eq_int_iff hf).1 ho with ⟨g, g_an, gx, hg⟩ refine ⟨g x, gx, ?_⟩ apply g_an.continuousAt.continuousWithinAt.tendsto.congr' filter_upwards [hg] with y hy using by simp [hy] @[deprecated (since := "2025-05-22")] alias MeromorphicAt.tendsto_ne_zero_of_order_eq_zero := tendsto_ne_zero_of_meromorphicOrderAt_eq_zero /-- If the order of a meromorphic function is positive, then this function converges to zero at this point. See also the iff version `tendsto_zero_iff_meromorphicOrderAt_pos`. -/ lemma tendsto_zero_of_meromorphicOrderAt_pos (ho : 0 < meromorphicOrderAt f x) : Tendsto f (𝓝[β‰ ] x) (𝓝 0) := by have hf : MeromorphicAt f x := meromorphicAt_of_meromorphicOrderAt_ne_zero ho.ne' cases h'o : meromorphicOrderAt f x with | top => apply tendsto_const_nhds.congr' filter_upwards [meromorphicOrderAt_eq_top_iff.1 h'o] with y hy using hy.symm | coe n => rcases (meromorphicOrderAt_eq_int_iff hf).1 h'o with ⟨g, g_an, gx, hg⟩ lift n to β„• using by simpa [h'o] using ho.le have : (0 : E) = (x - x) ^ n β€’ g x := by have : 0 < n := by simpa [h'o] using ho simp [zero_pow_eq_zero.2 this.ne'] rw [this] have : ContinuousAt (fun z ↦ (z - x) ^ n β€’ g z) x := by fun_prop apply this.continuousWithinAt.tendsto.congr' filter_upwards [hg] with y hy using by simp [hy] @[deprecated (since := "2025-05-22")] alias MeromorphicAt.tendsto_zero_of_order_pos := tendsto_zero_of_meromorphicOrderAt_pos /-- If the order of a meromorphic function is nonnegative, then this function converges at this point. See also the iff version `tendsto_nhds_iff_meromorphicOrderAt_nonneg`. -/ lemma tendsto_nhds_of_meromorphicOrderAt_nonneg (hf : MeromorphicAt f x) (ho : 0 ≀ meromorphicOrderAt f x) : βˆƒ c, Tendsto f (𝓝[β‰ ] x) (𝓝 c) := by rcases ho.eq_or_lt with ho | ho Β· rcases tendsto_ne_zero_of_meromorphicOrderAt_eq_zero hf ho.symm with ⟨c, -, hc⟩ exact ⟨c, hc⟩ Β· exact ⟨0, tendsto_zero_of_meromorphicOrderAt_pos ho⟩ @[deprecated (since := "2025-05-22")] alias MeromorphicAt.tendsto_nhds_of_order_nonneg := tendsto_nhds_of_meromorphicOrderAt_nonneg /-- A meromorphic function converges to infinity iff its order is negative. -/ lemma tendsto_cobounded_iff_meromorphicOrderAt_neg (hf : MeromorphicAt f x) : Tendsto f (𝓝[β‰ ] x) (Bornology.cobounded E) ↔ meromorphicOrderAt f x < 0 := by rcases lt_or_ge (meromorphicOrderAt f x) 0 with ho | ho Β· simp [ho, tendsto_cobounded_of_meromorphicOrderAt_neg] Β· simp only [lt_iff_not_ge, ho, not_true_eq_false, iff_false, ← tendsto_norm_atTop_iff_cobounded] obtain ⟨c, hc⟩ := tendsto_nhds_of_meromorphicOrderAt_nonneg hf ho exact not_tendsto_atTop_of_tendsto_nhds hc.norm @[deprecated (since := "2025-05-22")] alias MeromorphicAt.tendsto_cobounded_iff_order_neg := tendsto_cobounded_iff_meromorphicOrderAt_neg /-- A meromorphic function converges to a limit iff its order is nonnegative. -/ lemma tendsto_nhds_iff_meromorphicOrderAt_nonneg (hf : MeromorphicAt f x) : (βˆƒ c, Tendsto f (𝓝[β‰ ] x) (𝓝 c)) ↔ 0 ≀ meromorphicOrderAt f x := by rcases lt_or_ge (meromorphicOrderAt f x) 0 with ho | ho Β· simp only [← not_lt, ho, not_true_eq_false, iff_false, not_exists] intro c hc apply not_tendsto_atTop_of_tendsto_nhds hc.norm rw [tendsto_norm_atTop_iff_cobounded] exact tendsto_cobounded_of_meromorphicOrderAt_neg ho Β· simp [ho, tendsto_nhds_of_meromorphicOrderAt_nonneg hf ho] @[deprecated (since := "2025-05-22")] alias MeromorphicAt.tendsto_nhds_iff_order_nonneg := tendsto_nhds_iff_meromorphicOrderAt_nonneg /-- A meromorphic function converges to a nonzero limit iff its order is zero. -/ lemma tendsto_ne_zero_iff_meromorphicOrderAt_eq_zero (hf : MeromorphicAt f x) : (βˆƒ c β‰  0, Tendsto f (𝓝[β‰ ] x) (𝓝 c)) ↔ meromorphicOrderAt f x = 0 := by rcases eq_or_ne (meromorphicOrderAt f x) 0 with ho | ho Β· simp [ho, tendsto_ne_zero_of_meromorphicOrderAt_eq_zero hf ho] simp only [ne_eq, ho, iff_false, not_exists, not_and] intro c c_ne hc rcases ho.lt_or_gt with ho | ho Β· apply not_tendsto_atTop_of_tendsto_nhds hc.norm rw [tendsto_norm_atTop_iff_cobounded] exact tendsto_cobounded_of_meromorphicOrderAt_neg ho Β· apply c_ne exact tendsto_nhds_unique hc (tendsto_zero_of_meromorphicOrderAt_pos ho) @[deprecated (since := "2025-05-22")] alias MeromorphicAt.tendsto_ne_zero_iff_order_eq_zero := tendsto_ne_zero_iff_meromorphicOrderAt_eq_zero /-- A meromorphic function converges to zero iff its order is positive. -/ lemma tendsto_zero_iff_meromorphicOrderAt_pos (hf : MeromorphicAt f x) : (Tendsto f (𝓝[β‰ ] x) (𝓝 0)) ↔ 0 < meromorphicOrderAt f x := by rcases lt_or_ge 0 (meromorphicOrderAt f x) with ho | ho Β· simp [ho, tendsto_zero_of_meromorphicOrderAt_pos ho] simp only [← not_le, ho, not_true_eq_false, iff_false] intro hc rcases ho.eq_or_lt with ho | ho Β· obtain ⟨c, c_ne, h'c⟩ := tendsto_ne_zero_of_meromorphicOrderAt_eq_zero hf ho apply c_ne exact tendsto_nhds_unique h'c hc Β· apply not_tendsto_atTop_of_tendsto_nhds hc.norm rw [tendsto_norm_atTop_iff_cobounded] exact tendsto_cobounded_of_meromorphicOrderAt_neg ho @[deprecated (since := "2025-05-22")] alias MeromorphicAt.tendsto_zero_iff_order_pos := tendsto_zero_iff_meromorphicOrderAt_pos /-- Meromorphic functions that agree in a punctured neighborhood of `zβ‚€` have the same order at `zβ‚€`. -/ theorem meromorphicOrderAt_congr (hf₁₂ : f₁ =αΆ [𝓝[β‰ ] x] fβ‚‚) : meromorphicOrderAt f₁ x = meromorphicOrderAt fβ‚‚ x := by by_cases hf₁ : MeromorphicAt f₁ x; swap Β· have : Β¬ MeromorphicAt fβ‚‚ x := by contrapose! hf₁ exact hf₁.congr hf₁₂.symm simp [hf₁, this] by_cases h₁f₁ : meromorphicOrderAt f₁ x = ⊀ Β· rw [h₁f₁, eq_comm] rw [meromorphicOrderAt_eq_top_iff] at h₁f₁ ⊒ exact EventuallyEq.rw h₁f₁ (fun x => Eq (fβ‚‚ x)) hf₁₂.symm Β· obtain ⟨n, hn : meromorphicOrderAt f₁ x = n⟩ := Option.ne_none_iff_exists'.mp h₁f₁ obtain ⟨g, h₁g, hβ‚‚g, h₃g⟩ := (meromorphicOrderAt_eq_int_iff hf₁).1 hn rw [hn, eq_comm, meromorphicOrderAt_eq_int_iff (hf₁.congr hf₁₂)] use g, h₁g, hβ‚‚g exact EventuallyEq.rw h₃g (fun x => Eq (fβ‚‚ x)) hf₁₂.symm @[deprecated (since := "2025-05-22")] alias MeromorphicAt.order_congr := meromorphicOrderAt_congr /-- Compatibility of notions of `order` for analytic and meromorphic functions. -/ lemma AnalyticAt.meromorphicOrderAt_eq (hf : AnalyticAt π•œ f x) : meromorphicOrderAt f x = (analyticOrderAt f x).map (↑) := by cases hn : analyticOrderAt f x Β· rw [ENat.map_top, meromorphicOrderAt_eq_top_iff] exact (analyticOrderAt_eq_top.mp hn).filter_mono nhdsWithin_le_nhds Β· simp_rw [ENat.map_coe, meromorphicOrderAt_eq_int_iff hf.meromorphicAt, zpow_natCast] rcases hf.analyticOrderAt_eq_natCast.mp hn with ⟨g, h1, h2, h3⟩ exact ⟨g, h1, h2, h3.filter_mono nhdsWithin_le_nhds⟩ @[deprecated (since := "2025-05-22")] alias AnalyticAt.meromorphicAt_order := AnalyticAt.meromorphicOrderAt_eq /-- When seen as meromorphic functions, analytic functions have nonnegative order. -/ theorem AnalyticAt.meromorphicOrderAt_nonneg (hf : AnalyticAt π•œ f x) : 0 ≀ meromorphicOrderAt f x := by simp [hf.meromorphicOrderAt_eq] @[deprecated (since := "2025-05-22")] alias AnalyticAt.meromorphicAt_order_nonneg := AnalyticAt.meromorphicOrderAt_nonneg /-- If a function is both meromorphic and continuous at a point, then it is analytic there. -/ protected theorem MeromorphicAt.analyticAt {f : π•œ β†’ E} {x : π•œ} (h : MeromorphicAt f x) (h' : ContinuousAt f x) : AnalyticAt π•œ f x := by cases ho : meromorphicOrderAt f x with | top => /- If the order is infinite, then `f` vanishes on a pointed neighborhood of `x`. By continuity, it also vanishes at `x`.-/ have : AnalyticAt π•œ (fun _ ↦ (0 : E)) x := analyticAt_const apply this.congr rw [← ContinuousAt.eventuallyEq_nhds_iff_eventuallyEq_nhdsNE continuousAt_const h'] filter_upwards [meromorphicOrderAt_eq_top_iff.1 ho] with y hy using by simp [hy] | coe n => /- If the order is finite, then the order has to be nonnegative, as otherwise the norm of `f` would tend to infinity at `x`. Then the local expression of `f` coming from its meromorphicity shows that it coincides with an analytic function close to `x`, except maybe at `x`. By continuity of `f`, the two functions also coincide at `x`. -/ rcases (meromorphicOrderAt_eq_int_iff h).1 ho with ⟨g, g_an, gx, hg⟩ have : 0 ≀ meromorphicOrderAt f x := by apply (tendsto_nhds_iff_meromorphicOrderAt_nonneg h).1 exact ⟨f x, h'.continuousWithinAt.tendsto⟩ lift n to β„• using by simpa [ho] using this have A : βˆ€αΆ  (z : π•œ) in 𝓝 x, (z - x) ^ n β€’ g z = f z := by apply (ContinuousAt.eventuallyEq_nhds_iff_eventuallyEq_nhdsNE (by fun_prop) h').1 filter_upwards [hg] with z hz using by simpa using hz.symm exact AnalyticAt.congr (by fun_prop) A /-- The order of a constant function is `⊀` if the constant is zero and `0` otherwise. -/ theorem meromorphicOrderAt_const (zβ‚€ : π•œ) (e : E) [Decidable (e = 0)] : meromorphicOrderAt (fun _ ↦ e) zβ‚€ = if e = 0 then ⊀ else (0 : WithTop β„€) := by split_ifs with he Β· simp [he, meromorphicOrderAt_eq_top_iff] Β· exact (meromorphicOrderAt_eq_int_iff (.const e zβ‚€)).2 ⟨fun _ ↦ e, by fun_prop, by simpa⟩ /-- The order of a constant function is `⊀` if the constant is zero and `0` otherwise. -/ theorem meromorphicOrderAt_const_intCast (zβ‚€ : π•œ) (n : β„€) [Decidable ((n : π•œ) = 0)] : meromorphicOrderAt (n : π•œ β†’ π•œ) zβ‚€ = if (n : π•œ) = 0 then ⊀ else (0 : WithTop β„€) := meromorphicOrderAt_const zβ‚€ (n : π•œ) /-- The order of a constant function is `⊀` if the constant is zero and `0` otherwise. -/ theorem meromorphicOrderAt_const_natCast (zβ‚€ : π•œ) (n : β„•) [Decidable ((n : π•œ) = 0)] : meromorphicOrderAt (n : π•œ β†’ π•œ) zβ‚€ = if (n : π•œ) = 0 then ⊀ else (0 : WithTop β„€) := meromorphicOrderAt_const zβ‚€ (n : π•œ) /-- The order of a constant function is `⊀` if the constant is zero and `0` otherwise. -/ @[simp] theorem meromorphicOrderAt_const_ofNat (zβ‚€ : π•œ) (n : β„•) [Decidable ((n : π•œ) = 0)] : meromorphicOrderAt (ofNat(n) : π•œ β†’ π•œ) zβ‚€ = if (n : π•œ) = 0 then ⊀ else (0 : WithTop β„€) := by convert meromorphicOrderAt_const zβ‚€ (n : π•œ) simp [Semiring.toGrindSemiring_ofNat π•œ n] /-! ## Order at a Point: Behaviour under Ring Operations We establish additivity of the order under multiplication and taking powers. -/ /-- The order is additive when multiplying scalar-valued and vector-valued meromorphic functions. -/ theorem meromorphicOrderAt_smul {f : π•œ β†’ π•œ} {g : π•œ β†’ E} (hf : MeromorphicAt f x) (hg : MeromorphicAt g x) : meromorphicOrderAt (f β€’ g) x = meromorphicOrderAt f x + meromorphicOrderAt g x := by -- Trivial cases: one of the functions vanishes around zβ‚€ cases hβ‚‚f : meromorphicOrderAt f x with | top => simp only [top_add, meromorphicOrderAt_eq_top_iff] at hβ‚‚f ⊒ filter_upwards [hβ‚‚f] with z hz using by simp [hz] | coe m => cases hβ‚‚g : meromorphicOrderAt g x with | top => simp only [add_top, meromorphicOrderAt_eq_top_iff] at hβ‚‚g ⊒ filter_upwards [hβ‚‚g] with z hz using by simp [hz] | coe n => -- Non-trivial case: both functions do not vanish around zβ‚€ rw [← WithTop.coe_add, meromorphicOrderAt_eq_int_iff (hf.smul hg)] obtain ⟨F, h₁F, hβ‚‚F, h₃F⟩ := (meromorphicOrderAt_eq_int_iff hf).1 hβ‚‚f obtain ⟨G, h₁G, hβ‚‚G, h₃G⟩ := (meromorphicOrderAt_eq_int_iff hg).1 hβ‚‚g use F β€’ G, h₁F.smul h₁G, by simp [hβ‚‚F, hβ‚‚G] filter_upwards [self_mem_nhdsWithin, h₃F, h₃G] with a ha hfa hga simp [hfa, hga, smul_comm (F a), zpow_addβ‚€ (sub_ne_zero.mpr ha), mul_smul] @[deprecated (since := "2025-05-22")] alias MeromorphicAt.order_smul := meromorphicOrderAt_smul /-- The order is additive when multiplying meromorphic functions. -/ theorem meromorphicOrderAt_mul {f g : π•œ β†’ π•œ} (hf : MeromorphicAt f x) (hg : MeromorphicAt g x) : meromorphicOrderAt (f * g) x = meromorphicOrderAt f x + meromorphicOrderAt g x := meromorphicOrderAt_smul hf hg @[deprecated (since := "2025-05-22")] alias MeromorphicAt.order_mul := meromorphicOrderAt_mul /-- The order multiplies by `n` when taking a meromorphic function to its `n`th power. -/ theorem meromorphicOrderAt_pow {f : π•œ β†’ π•œ} {x : π•œ} (hf : MeromorphicAt f x) {n : β„•} : meromorphicOrderAt (f ^ n) x = n * meromorphicOrderAt f x := by induction n case zero => simp only [pow_zero, CharP.cast_eq_zero, zero_mul] rw [← WithTop.coe_zero, meromorphicOrderAt_eq_int_iff] Β· exact ⟨1, analyticAt_const, by simp⟩ Β· apply MeromorphicAt.const case succ n hn => simp only [pow_add, pow_one, meromorphicOrderAt_mul (hf.pow n) hf, hn, Nat.cast_add, Nat.cast_one] cases meromorphicOrderAt f x Β· aesop Β· norm_cast simp only [Nat.cast_add, Nat.cast_one] ring @[deprecated (since := "2025-05-22")] alias MeromorphicAt.order_pow := meromorphicOrderAt_pow /-- The order multiplies by `n` when taking a meromorphic function to its `n`th power. -/ theorem meromorphicOrderAt_zpow {f : π•œ β†’ π•œ} {x : π•œ} (hf : MeromorphicAt f x) {n : β„€} : meromorphicOrderAt (f ^ n) x = n * meromorphicOrderAt f x := by -- Trivial case: n = 0 by_cases hn : n = 0 Β· simp only [hn, zpow_zero, WithTop.coe_zero, zero_mul] rw [← WithTop.coe_zero, meromorphicOrderAt_eq_int_iff] Β· exact ⟨1, analyticAt_const, by simp⟩ Β· apply MeromorphicAt.const -- Trivial case: f locally zero by_cases h : meromorphicOrderAt f x = ⊀ Β· simp only [h, ne_eq, WithTop.coe_eq_zero, hn, not_false_eq_true, WithTop.mul_top] rw [meromorphicOrderAt_eq_top_iff] at * filter_upwards [h] intro y hy simp [hy, zero_zpow n hn] -- General case obtain ⟨g, h₁g, hβ‚‚g, h₃g⟩ := (meromorphicOrderAt_ne_top_iff hf).1 h rw [← WithTop.coe_untopβ‚€_of_ne_top h, ← WithTop.coe_mul, meromorphicOrderAt_eq_int_iff (hf.zpow n)] use g ^ n, h₁g.zpow hβ‚‚g constructor Β· simp_all [zpow_eq_zero_iff hn] Β· filter_upwards [h₃g] intro y hy rw [Pi.pow_apply, hy, smul_eq_mul, mul_zpow] congr 1 rw [mul_comm, zpow_mul] @[deprecated (since := "2025-05-22")] alias MeromorphicAt.order_zpow := meromorphicOrderAt_zpow /-- The order of the inverse is the negative of the order. -/ theorem meromorphicOrderAt_inv {f : π•œ β†’ π•œ} : meromorphicOrderAt (f⁻¹) x = -meromorphicOrderAt f x := by by_cases hf : MeromorphicAt f x; swap Β· have : Β¬ MeromorphicAt (f⁻¹) x := by contrapose! hf simpa using hf.inv simp [hf, this] by_cases hβ‚‚f : meromorphicOrderAt f x = ⊀ Β· rw [hβ‚‚f, ← LinearOrderedAddCommGroupWithTop.neg_top, neg_neg] rw [meromorphicOrderAt_eq_top_iff] at * filter_upwards [hβ‚‚f] simp lift meromorphicOrderAt f x to β„€ using hβ‚‚f with a ha apply (meromorphicOrderAt_eq_int_iff hf.inv).2 obtain ⟨g, h₁g, hβ‚‚g, h₃g⟩ := (meromorphicOrderAt_eq_int_iff hf).1 ha.symm use g⁻¹, h₁g.inv hβ‚‚g, inv_eq_zero.not.2 hβ‚‚g rw [eventually_nhdsWithin_iff] at * filter_upwards [h₃g] intro _ h₁a hβ‚‚a simp only [Pi.inv_apply, h₁a hβ‚‚a, smul_eq_mul, mul_inv_rev, zpow_neg] ring @[deprecated (since := "2025-05-22")] alias MeromorphicAt.order_inv := meromorphicOrderAt_inv /-- The order of a sum is at least the minimum of the orders of the summands. -/ theorem meromorphicOrderAt_add (hf₁ : MeromorphicAt f₁ x) (hfβ‚‚ : MeromorphicAt fβ‚‚ x) : min (meromorphicOrderAt f₁ x) (meromorphicOrderAt fβ‚‚ x) ≀ meromorphicOrderAt (f₁ + fβ‚‚) x := by -- Handle the trivial cases where one of the orders equals ⊀ by_cases hβ‚‚f₁ : meromorphicOrderAt f₁ x = ⊀ Β· rw [hβ‚‚f₁, min_top_left, meromorphicOrderAt_congr] filter_upwards [meromorphicOrderAt_eq_top_iff.1 hβ‚‚f₁] simp by_cases hβ‚‚fβ‚‚ : meromorphicOrderAt fβ‚‚ x = ⊀ Β· simp only [hβ‚‚fβ‚‚, le_top, inf_of_le_left] rw [meromorphicOrderAt_congr] filter_upwards [meromorphicOrderAt_eq_top_iff.1 hβ‚‚fβ‚‚] simp -- General case lift meromorphicOrderAt f₁ x to β„€ using hβ‚‚f₁ with n₁ hn₁ lift meromorphicOrderAt fβ‚‚ x to β„€ using hβ‚‚fβ‚‚ with nβ‚‚ hnβ‚‚ obtain ⟨g₁, h₁g₁, hβ‚‚g₁, h₃gβ‚βŸ© := (meromorphicOrderAt_eq_int_iff hf₁).1 hn₁.symm obtain ⟨gβ‚‚, h₁gβ‚‚, hβ‚‚gβ‚‚, h₃gβ‚‚βŸ© := (meromorphicOrderAt_eq_int_iff hfβ‚‚).1 hnβ‚‚.symm let n := min n₁ nβ‚‚ let g := (fun z ↦ (z - x) ^ (n₁ - n)) β€’ g₁ + (fun z ↦ (z - x) ^ (nβ‚‚ - n)) β€’ gβ‚‚ have h₁g : AnalyticAt π•œ g x := by apply AnalyticAt.add Β· apply (AnalyticAt.zpow_nonneg (by fun_prop) (sub_nonneg.2 (min_le_left n₁ nβ‚‚))).smul h₁g₁ apply (AnalyticAt.zpow_nonneg (by fun_prop) (sub_nonneg.2 (min_le_right n₁ nβ‚‚))).smul h₁gβ‚‚ have : f₁ + fβ‚‚ =αΆ [𝓝[β‰ ] x] ((Β· - x) ^ n) β€’ g := by filter_upwards [h₃g₁, h₃gβ‚‚, self_mem_nhdsWithin] simp_all [g, ← smul_assoc, ← zpow_add', sub_ne_zero] have tβ‚€ : MeromorphicAt ((Β· - x) ^ n) x := by fun_prop have t₁ : meromorphicOrderAt ((Β· - x) ^ n) x = n := (meromorphicOrderAt_eq_int_iff tβ‚€).2 ⟨1, analyticAt_const, by simp⟩ rw [meromorphicOrderAt_congr this, meromorphicOrderAt_smul tβ‚€ h₁g.meromorphicAt, t₁] exact le_add_of_nonneg_right h₁g.meromorphicOrderAt_nonneg @[deprecated (since := "2025-05-22")] alias MeromorphicAt.order_add := meromorphicOrderAt_add /-- Helper lemma for meromorphicOrderAt_add_of_ne. -/ lemma meromorphicOrderAt_add_eq_left_of_lt (hfβ‚‚ : MeromorphicAt fβ‚‚ x) (h : meromorphicOrderAt f₁ x < meromorphicOrderAt fβ‚‚ x) : meromorphicOrderAt (f₁ + fβ‚‚) x = meromorphicOrderAt f₁ x := by by_cases hf₁ : MeromorphicAt f₁ x; swap Β· have : Β¬ (MeromorphicAt (f₁ + fβ‚‚) x) := by contrapose! hf₁ simpa using hf₁.sub hfβ‚‚ simp [this, hf₁] -- Trivial case: fβ‚‚ vanishes identically around zβ‚€ by_cases h₁fβ‚‚ : meromorphicOrderAt fβ‚‚ x = ⊀ Β· rw [meromorphicOrderAt_congr] filter_upwards [meromorphicOrderAt_eq_top_iff.1 h₁fβ‚‚] simp -- General case lift meromorphicOrderAt fβ‚‚ x to β„€ using h₁fβ‚‚ with nβ‚‚ hnβ‚‚ lift meromorphicOrderAt f₁ x to β„€ using h.ne_top with n₁ hn₁ obtain ⟨g₁, h₁g₁, hβ‚‚g₁, h₃gβ‚βŸ© := (meromorphicOrderAt_eq_int_iff hf₁).1 hn₁.symm obtain ⟨gβ‚‚, h₁gβ‚‚, hβ‚‚gβ‚‚, h₃gβ‚‚βŸ© := (meromorphicOrderAt_eq_int_iff hfβ‚‚).1 hnβ‚‚.symm rw [meromorphicOrderAt_eq_int_iff (hf₁.add hfβ‚‚)] refine ⟨g₁ + (Β· - x) ^ (nβ‚‚ - n₁) β€’ gβ‚‚, ?_, ?_, ?_⟩ Β· apply h₁g₁.add (AnalyticAt.smul _ h₁gβ‚‚) apply AnalyticAt.zpow_nonneg (by fun_prop) (sub_nonneg.2 (le_of_lt (WithTop.coe_lt_coe.1 h))) Β· simpa [zero_zpow _ <| sub_ne_zero.mpr (WithTop.coe_lt_coe.1 h).ne'] Β· filter_upwards [h₃g₁, h₃gβ‚‚, self_mem_nhdsWithin] simp_all [smul_add, ← smul_assoc, ← zpow_add', sub_ne_zero] @[deprecated (since := "2025-05-22")] alias MeromorphicAt.order_add_of_order_lt_order := meromorphicOrderAt_add_eq_left_of_lt /-- Helper lemma for meromorphicOrderAt_add_of_ne. -/ lemma meromorphicOrderAt_add_eq_right_of_lt (hf₁ : MeromorphicAt f₁ x) (h : meromorphicOrderAt fβ‚‚ x < meromorphicOrderAt f₁ x) : meromorphicOrderAt (f₁ + fβ‚‚) x = meromorphicOrderAt fβ‚‚ x := by rw [add_comm] exact meromorphicOrderAt_add_eq_left_of_lt hf₁ h /-- If two meromorphic functions have unequal orders, then the order of their sum is exactly the minimum of the orders of the summands. -/ theorem meromorphicOrderAt_add_of_ne (hf₁ : MeromorphicAt f₁ x) (hfβ‚‚ : MeromorphicAt fβ‚‚ x) (h : meromorphicOrderAt f₁ x β‰  meromorphicOrderAt fβ‚‚ x) : meromorphicOrderAt (f₁ + fβ‚‚) x = min (meromorphicOrderAt f₁ x) (meromorphicOrderAt fβ‚‚ x) := by rcases lt_or_lt_iff_ne.mpr h with h | h Β· simpa [h.le] using meromorphicOrderAt_add_eq_left_of_lt hfβ‚‚ h Β· simpa [h.le] using meromorphicOrderAt_add_eq_right_of_lt hf₁ h @[deprecated (since := "2025-05-22")] alias MeromorphicAt.order_add_of_order_ne := meromorphicOrderAt_add_of_ne @[deprecated (since := "2025-04-27")] alias MeromorphicAt.meromorphicOrderAt_add_of_unequal_order := meromorphicOrderAt_add_of_ne /-! ## Level Sets of the Order Function -/ namespace MeromorphicOn variable {U : Set π•œ} /-- The set where a meromorphic function has infinite order is clopen in its domain of meromorphy. -/ theorem isClopen_setOf_meromorphicOrderAt_eq_top (hf : MeromorphicOn f U) : IsClopen { u : U | meromorphicOrderAt f u = ⊀ } := by constructor Β· rw [← isOpen_compl_iff, isOpen_iff_forall_mem_open] intro z hz rcases (hf z.1 z.2).eventually_eq_zero_or_eventually_ne_zero with h | h Β· -- Case: f is locally zero in a punctured neighborhood of z rw [← meromorphicOrderAt_eq_top_iff] at h tauto Β· -- Case: f is locally nonzero in a punctured neighborhood of z obtain ⟨t', h₁t', hβ‚‚t', h₃t'⟩ := eventually_nhds_iff.1 (eventually_nhdsWithin_iff.1 h) use Subtype.val ⁻¹' t' constructor Β· intro w hw simp only [mem_compl_iff, mem_setOf_eq] by_cases h₁w : w = z Β· rwa [h₁w] Β· rw [meromorphicOrderAt_eq_top_iff, not_eventually] apply Filter.Eventually.frequently rw [eventually_nhdsWithin_iff, eventually_nhds_iff] use t' \ {z.1}, fun y h₁y hβ‚‚y ↦ h₁t' y h₁y.1 h₁y.2, hβ‚‚t'.sdiff isClosed_singleton, hw, mem_singleton_iff.not.2 (Subtype.coe_ne_coe.mpr h₁w) Β· exact ⟨isOpen_induced hβ‚‚t', h₃t'⟩ Β· apply isOpen_iff_forall_mem_open.mpr intro z hz conv => arg 1; intro; left; right; arg 1; intro rw [meromorphicOrderAt_eq_top_iff, eventually_nhdsWithin_iff, eventually_nhds_iff] simp only [mem_setOf_eq] at hz rw [meromorphicOrderAt_eq_top_iff, eventually_nhdsWithin_iff, eventually_nhds_iff] at hz obtain ⟨t', h₁t', hβ‚‚t', h₃t'⟩ := hz use Subtype.val ⁻¹' t' simp only [mem_compl_iff, mem_singleton_iff, isOpen_induced hβ‚‚t', mem_preimage, h₃t', and_self, and_true] intro w hw simp only [mem_setOf_eq] -- Trivial case: w = z by_cases h₁w : w = z Β· rw [h₁w] tauto -- Nontrivial case: w β‰  z use t' \ {z.1}, fun y h₁y _ ↦ h₁t' y (mem_of_mem_diff h₁y) (mem_of_mem_inter_right h₁y) constructor Β· exact hβ‚‚t'.sdiff isClosed_singleton Β· apply (mem_diff w).1 exact ⟨hw, mem_singleton_iff.not.1 (Subtype.coe_ne_coe.2 h₁w)⟩ @[deprecated (since := "2025-04-27")] alias isClopen_setOf_order_eq_top := isClopen_setOf_meromorphicOrderAt_eq_top /-- On a connected set, there exists a point where a meromorphic function `f` has finite order iff `f` has finite order at every point. -/ theorem exists_meromorphicOrderAt_ne_top_iff_forall (hf : MeromorphicOn f U) (hU : IsConnected U) : (βˆƒ u : U, meromorphicOrderAt f u β‰  ⊀) ↔ (βˆ€ u : U, meromorphicOrderAt f u β‰  ⊀) := by constructor Β· intro hβ‚‚f have := isPreconnected_iff_preconnectedSpace.1 hU.isPreconnected rcases isClopen_iff.1 hf.isClopen_setOf_meromorphicOrderAt_eq_top with h | h Β· intro u have : u βˆ‰ (βˆ… : Set U) := by exact fun a => a rw [← h] at this tauto Β· obtain ⟨u, hU⟩ := hβ‚‚f have : u ∈ univ := by trivial rw [← h] at this tauto Β· intro hβ‚‚f obtain ⟨v, hv⟩ := hU.nonempty use ⟨v, hv⟩, hβ‚‚f ⟨v, hv⟩ @[deprecated (since := "2025-04-27")] alias exists_order_ne_top_iff_forall := exists_meromorphicOrderAt_ne_top_iff_forall /-- On a preconnected set, a meromorphic function has finite order at one point if it has finite order at another point. -/ theorem meromorphicOrderAt_ne_top_of_isPreconnected (hf : MeromorphicOn f U) {y : π•œ} (hU : IsPreconnected U) (h₁x : x ∈ U) (hy : y ∈ U) (hβ‚‚x : meromorphicOrderAt f x β‰  ⊀) : meromorphicOrderAt f y β‰  ⊀ := (hf.exists_meromorphicOrderAt_ne_top_iff_forall ⟨nonempty_of_mem h₁x, hU⟩).1 (by use ⟨x, h₁x⟩) ⟨y, hy⟩ @[deprecated (since := "2025-04-27")] alias order_ne_top_of_isPreconnected := meromorphicOrderAt_ne_top_of_isPreconnected /-- If a function is meromorphic on a set `U`, then for each point in `U`, it is analytic at nearby points in `U`. When the target space is complete, this can be strengthened to analyticity at all nearby points, see `MeromorphicAt.eventually_analyticAt`. -/ theorem eventually_analyticAt (h : MeromorphicOn f U) (hx : x ∈ U) : βˆ€αΆ  y in 𝓝[U \ {x}] x, AnalyticAt π•œ f y := by /- At neighboring points in `U`, the function `f` is both meromorphic (by meromorphicity on `U`) and continuous (thanks to the formula for a meromorphic function around the point `x`), so it is analytic. -/ have : βˆ€αΆ  y in 𝓝[U \ {x}] x, ContinuousAt f y := by have : U \ {x} βŠ† {x}ᢜ := by simp exact nhdsWithin_mono _ this (h x hx).eventually_continuousAt filter_upwards [this, self_mem_nhdsWithin] with y hy h'y exact (h y h'y.1).analyticAt hy theorem eventually_analyticAt_or_mem_compl (h : MeromorphicOn f U) (hx : x ∈ U) : βˆ€αΆ  y in 𝓝[β‰ ] x, AnalyticAt π•œ f y ∨ y ∈ Uᢜ := by have : {x}ᢜ = (U \ {x}) βˆͺ Uᢜ := by aesop (add simp Classical.em) rw [this, nhdsWithin_union] simp only [mem_compl_iff, eventually_sup] refine ⟨?_, ?_⟩ Β· filter_upwards [h.eventually_analyticAt hx] with y hy using Or.inl hy Β· filter_upwards [self_mem_nhdsWithin] with y hy using Or.inr hy /-- Meromorphic functions on `U` are analytic on `U`, outside of a discrete subset. -/ theorem analyticAt_mem_codiscreteWithin (hf : MeromorphicOn f U) : { x | AnalyticAt π•œ f x } ∈ Filter.codiscreteWithin U := by rw [mem_codiscreteWithin] intro x hx rw [Filter.disjoint_principal_right, ← Filter.eventually_mem_set] filter_upwards [hf.eventually_analyticAt_or_mem_compl hx] with y hy simp tauto /-- The set where a meromorphic function has zero or infinite order is codiscrete within its domain of meromorphicity. -/ theorem codiscrete_setOf_meromorphicOrderAt_eq_zero_or_top (hf : MeromorphicOn f U) : {u : U | meromorphicOrderAt f u = 0 ∨ meromorphicOrderAt f u = ⊀} ∈ Filter.codiscrete U := by rw [mem_codiscrete_subtype_iff_mem_codiscreteWithin, mem_codiscreteWithin] intro x hx rw [Filter.disjoint_principal_right] rcases (hf x hx).eventually_eq_zero_or_eventually_ne_zero with h₁f | h₁f Β· filter_upwards [eventually_eventually_nhdsWithin.2 h₁f] with a h₁a suffices βˆ€αΆ  (z : π•œ) in 𝓝[β‰ ] a, f z = 0 by simp +contextual [meromorphicOrderAt_eq_top_iff, this] obtain rfl | hax := eq_or_ne a x Β· exact h₁a rw [eventually_nhdsWithin_iff, eventually_nhds_iff] at h₁a ⊒ obtain ⟨t, h₁t, hβ‚‚t, h₃t⟩ := h₁a use t \ {x}, fun y h₁y _ ↦ h₁t y h₁y.1 h₁y.2 exact ⟨hβ‚‚t.sdiff isClosed_singleton, Set.mem_diff_of_mem h₃t hax⟩ Β· filter_upwards [hf.eventually_analyticAt_or_mem_compl hx, h₁f] with a h₁a h'₁a simp only [mem_compl_iff, mem_diff, mem_image, mem_setOf_eq, Subtype.exists, exists_and_right, exists_eq_right, not_exists, not_or, not_and, not_forall, Decidable.not_not] rcases h₁a with h' | h' Β· simp +contextual [h'.meromorphicOrderAt_eq, h'.analyticOrderAt_eq_zero.2, h'₁a] Β· exact fun ha ↦ (h' ha).elim @[deprecated (since := "2025-04-27")] alias codiscrete_setOf_order_eq_zero_or_top := codiscrete_setOf_meromorphicOrderAt_eq_zero_or_top end MeromorphicOn lemma MeromorphicAt.comp_analyticAt {g : π•œ β†’ π•œ} (hf : MeromorphicAt f (g x)) (hg : AnalyticAt π•œ g x) : MeromorphicAt (f ∘ g) x := by obtain ⟨r, hr⟩ := hf by_cases hg' : analyticOrderAt (g Β· - g x) x = ⊀ Β· -- trivial case: `g` is locally constant near `x` refine .congr (.const (f (g x)) x) ?_ filter_upwards [nhdsWithin_le_nhds <| analyticOrderAt_eq_top.mp hg'] with z hz grind Β· -- interesting case: `g z - g x` looks like `(z - x) ^ n` times a non-vanishing function obtain ⟨n, hn⟩ := WithTop.ne_top_iff_exists.mp hg' obtain ⟨h, han, hne, heq⟩ := (hg.fun_sub analyticAt_const).analyticOrderAt_eq_natCast.mp hn.symm set j := fun z ↦ (z - g x) ^ r β€’ f z have : AnalyticAt π•œ (fun z ↦ (h z)⁻¹ ^ r β€’ j (g z)) x := by fun_prop (disch := assumption) refine ⟨n * r, this.congr ?_⟩ filter_upwards [heq, han.continuousAt.tendsto.eventually_ne hne] with z hz hzne simp only [inv_pow, Function.comp_apply, inv_smul_eq_iffβ‚€ (pow_ne_zero r hzne)] rw [← mul_smul (h z ^ r), mul_comm, pow_mul, ← mul_pow, ← smul_eq_mul, ← hz]
.lake/packages/mathlib/Mathlib/Analysis/Meromorphic/NormalForm.lean
import Mathlib.Analysis.Meromorphic.Divisor /-! # Normal form of meromorphic functions and continuous extension If a function `f` is meromorphic on `U` and if `g` differs from `f` only along a set that is codiscrete within `U`, then `g` is likewise meromorphic. The set of meromorphic functions is therefore huge, and `=αΆ [codiscreteWithin U]` defines an equivalence relation. This file implements continuous extension to provide an API that allows picking the 'unique best' representative of any given equivalence class, where 'best' means that the representative can locally near any point `x` be written 'in normal form', as `f =αΆ [𝓝 x] fun z ↦ (z - x) ^ n β€’ g` where `g` is analytic and does not vanish at `x`. The relevant notions are `MeromorphicNFAt` and `MeromorphicNFOn`; these guarantee normal form at a single point and along a set, respectively. -/ open Topology WithTop variable {π•œ : Type*} [NontriviallyNormedField π•œ] {E : Type*} [NormedAddCommGroup E] [NormedSpace π•œ E] {f : π•œ β†’ E} {g : π•œ β†’ π•œ} {x : π•œ} {U : Set π•œ} /-! ## Normal form of meromorphic functions at a given point ### Definition and characterizations -/ variable (f x) in /-- A function is 'meromorphic in normal form' at `x` if it vanishes around `x` or if it can locally be written as `fun z ↦ (z - x) ^ n β€’ g` where `g` is analytic and does not vanish at `x`. -/ def MeromorphicNFAt := f =αΆ [𝓝 x] 0 ∨ βˆƒ (n : β„€) (g : π•œ β†’ E), AnalyticAt π•œ g x ∧ g x β‰  0 ∧ f =αΆ [𝓝 x] (Β· - x) ^ n β€’ g /-- A meromorphic function has normal form at `x` iff it is either analytic there, or if it has a pole at `x` and takes the default value `0`. -/ theorem meromorphicNFAt_iff_analyticAt_or : MeromorphicNFAt f x ↔ AnalyticAt π•œ f x ∨ (MeromorphicAt f x ∧ meromorphicOrderAt f x < 0 ∧ f x = 0) := by constructor Β· rintro (h | ⟨n, g, h₁g, hβ‚‚g, h₃g⟩) Β· simp [(analyticAt_congr h).2 analyticAt_const] Β· have hf : MeromorphicAt f x := by apply MeromorphicAt.congr _ (h₃g.filter_mono nhdsWithin_le_nhds).symm fun_prop have : meromorphicOrderAt f x = n := by rw [meromorphicOrderAt_eq_int_iff hf] use g, h₁g, hβ‚‚g exact eventually_nhdsWithin_of_eventually_nhds h₃g by_cases! hn : 0 ≀ n Β· left rw [analyticAt_congr h₃g] apply (AnalyticAt.zpow_nonneg (by fun_prop) hn).smul h₁g Β· right use hf simp [this, WithTop.coe_lt_zero.2 hn, h₃g.eq_of_nhds, zero_zpow n hn.ne] Β· rintro (h | ⟨h₁, hβ‚‚, hβ‚ƒβŸ©) Β· by_cases hβ‚‚f : analyticOrderAt f x = ⊀ Β· rw [analyticOrderAt_eq_top] at hβ‚‚f tauto Β· right use analyticOrderNatAt f x have : analyticOrderAt f x β‰  ⊀ := hβ‚‚f rw [← ENat.coe_toNat_eq_self, eq_comm, h.analyticOrderAt_eq_natCast] at this obtain ⟨g, h₁g, hβ‚‚g, h₃g⟩ := this use g, h₁g, hβ‚‚g simpa Β· right lift meromorphicOrderAt f x to β„€ using LT.lt.ne_top hβ‚‚ with n hn obtain ⟨g, h₁g, hβ‚‚g, h₃g⟩ := (meromorphicOrderAt_eq_int_iff h₁).1 hn.symm use n, g, h₁g, hβ‚‚g filter_upwards [eventually_nhdsWithin_iff.1 h₃g] intro z hz by_cases h₁z : z = x Β· simp only [h₁z, Pi.smul_apply', Pi.pow_apply, sub_self] rw [h₃] apply (smul_eq_zero_of_left (zero_zpow n _) (g x)).symm by_contra hCon simp [hCon] at hβ‚‚ Β· exact hz h₁z /-! ### Relation to other properties of functions -/ /-- If a function is meromorphic in normal form at `x`, then it is meromorphic at `x`. -/ theorem MeromorphicNFAt.meromorphicAt (hf : MeromorphicNFAt f x) : MeromorphicAt f x := by rw [meromorphicNFAt_iff_analyticAt_or] at hf rcases hf with h | h Β· exact h.meromorphicAt Β· obtain ⟨hf, _⟩ := h exact hf /-- If a function is meromorphic in normal form at `x`, then it has non-negative order iff it is analytic. -/ theorem MeromorphicNFAt.meromorphicOrderAt_nonneg_iff_analyticAt (hf : MeromorphicNFAt f x) : 0 ≀ meromorphicOrderAt f x ↔ AnalyticAt π•œ f x := by constructor <;> intro hβ‚‚f Β· rw [meromorphicNFAt_iff_analyticAt_or] at hf rcases hf with h | ⟨_, h₃f, _⟩ Β· exact h Β· by_contra h' exact lt_irrefl 0 (lt_of_le_of_lt hβ‚‚f h₃f) Β· rw [hβ‚‚f.meromorphicOrderAt_eq] simp @[deprecated (since := "2025-05-22")] alias MeromorphicNFAt.order_nonneg_iff_analyticAt := MeromorphicNFAt.meromorphicOrderAt_nonneg_iff_analyticAt /-- Analytic functions are meromorphic in normal form. -/ theorem AnalyticAt.meromorphicNFAt (hf : AnalyticAt π•œ f x) : MeromorphicNFAt f x := by simp [meromorphicNFAt_iff_analyticAt_or, hf] /-- Meromorphic functions have normal form outside of a discrete subset in the domain of meromorphicity. -/ theorem MeromorphicOn.meromorphicNFAt_mem_codiscreteWithin {U : Set π•œ} (hf : MeromorphicOn f U) : { x | MeromorphicNFAt f x } ∈ Filter.codiscreteWithin U := by filter_upwards [hf.analyticAt_mem_codiscreteWithin] with _ ha exact ha.meromorphicNFAt /-! ### Vanishing and order -/ /-- If `f` is meromorphic in normal form at `x`, then `f` has order zero iff it does not vanish at `x`. See `AnalyticAt.order_eq_zero_iff` for an analogous statement about analytic functions. -/ theorem MeromorphicNFAt.meromorphicOrderAt_eq_zero_iff (hf : MeromorphicNFAt f x) : meromorphicOrderAt f x = 0 ↔ f x β‰  0 := by constructor Β· intro h₁f have hβ‚‚f := hf.meromorphicOrderAt_nonneg_iff_analyticAt.1 (le_of_eq h₁f.symm) rw [← hβ‚‚f.analyticOrderAt_eq_zero, ← ENat.map_natCast_eq_zero (Ξ± := β„€)] rwa [hβ‚‚f.meromorphicOrderAt_eq] at h₁f Β· intro h rcases id hf with h₁ | ⟨n, g, h₁g, hβ‚‚g, h₃g⟩ Β· have := h₁.eq_of_nhds tauto Β· have : n = 0 := by by_contra hContra have := h₃g.eq_of_nhds simp only [Pi.smul_apply', Pi.pow_apply, sub_self, zero_zpow n hContra, zero_smul] at this tauto simp only [this, zpow_zero] at h₃g apply (meromorphicOrderAt_eq_int_iff hf.meromorphicAt).2 use g, h₁g, hβ‚‚g simp only [zpow_zero] exact h₃g.filter_mono nhdsWithin_le_nhds @[deprecated (since := "2025-05-22")] alias MeromorphicNFAt.order_eq_zero_iff := MeromorphicNFAt.meromorphicOrderAt_eq_zero_iff /-! ### Local nature of the definition and local identity theorem -/ /-- **Local identity theorem**: two meromorphic functions in normal form agree in a neighborhood iff they agree in a pointed neighborhood. See `ContinuousAt.eventuallyEq_nhds_iff_eventuallyEq_nhdsNE` for the analogous statement for continuous functions. -/ theorem MeromorphicNFAt.eventuallyEq_nhdsNE_iff_eventuallyEq_nhds {g : π•œ β†’ E} (hf : MeromorphicNFAt f x) (hg : MeromorphicNFAt g x) : f =αΆ [𝓝[β‰ ] x] g ↔ f =αΆ [𝓝 x] g := by constructor Β· intro h have tβ‚€ := meromorphicOrderAt_congr h by_cases cs : meromorphicOrderAt f x = 0 Β· rw [cs] at tβ‚€ have Z := (hf.meromorphicOrderAt_nonneg_iff_analyticAt.1 (le_of_eq cs.symm)).continuousAt have W := (hg.meromorphicOrderAt_nonneg_iff_analyticAt.1 (le_of_eq tβ‚€)).continuousAt exact (Z.eventuallyEq_nhds_iff_eventuallyEq_nhdsNE W).1 h Β· apply eventuallyEq_nhds_of_eventuallyEq_nhdsNE h let h₁f := cs rw [hf.meromorphicOrderAt_eq_zero_iff] at h₁f let h₁g := cs rw [tβ‚€, hg.meromorphicOrderAt_eq_zero_iff] at h₁g simp only [not_not] at * rw [h₁f, h₁g] Β· exact (Filter.EventuallyEq.filter_mono Β· nhdsWithin_le_nhds) @[deprecated (since := "2025-05-22")] alias MeromorphicNFAt.eventuallyEq_nhdNE_iff_eventuallyEq_nhd := MeromorphicNFAt.eventuallyEq_nhdsNE_iff_eventuallyEq_nhds /-- Meromorphicity in normal form is a local property. -/ theorem meromorphicNFAt_congr {g : π•œ β†’ E} (hfg : f =αΆ [𝓝 x] g) : MeromorphicNFAt f x ↔ MeromorphicNFAt g x := by constructor Β· rintro (h | ⟨n, h, h₁h, hβ‚‚h, h₃h⟩) Β· exact .inl (hfg.symm.trans h) Β· exact .inr ⟨n, h, h₁h, hβ‚‚h, hfg.symm.trans h₃h⟩ Β· rintro (h | ⟨n, h, h₁h, hβ‚‚h, h₃h⟩) Β· exact .inl (hfg.trans h) Β· exact .inr ⟨n, h, h₁h, hβ‚‚h, hfg.trans h₃h⟩ /-! ### Criteria to guarantee normal form -/ /-- Helper lemma for `meromorphicNFAt_iff_meromorphicNFAt_of_smul_analytic`: if `f` is meromorphic in normal form at `x` and `g` is analytic without zero at `x`, then `g β€’ f` is meromorphic in normal form at `x`. -/ lemma MeromorphicNFAt.smul_analytic (hf : MeromorphicNFAt f x) (h₁g : AnalyticAt π•œ g x) (hβ‚‚g : g x β‰  0) : MeromorphicNFAt (g β€’ f) x := by rcases hf with h₁f | ⟨n, g_f, h₁g_f, hβ‚‚g_f, h₃g_f⟩ Β· left filter_upwards [h₁f] simp_all Β· right use n, g β€’ g_f, h₁g.smul h₁g_f constructor Β· simp [smul_ne_zero hβ‚‚g hβ‚‚g_f] Β· filter_upwards [h₃g_f] intro y hy simp only [Pi.smul_apply', hy, Pi.pow_apply] rw [smul_comm] /-- If `f` is any function and `g` is analytic without zero at `zβ‚€`, then `f` is meromorphic in normal form at `zβ‚€` iff `g β€’ f` is meromorphic in normal form at `zβ‚€`. -/ theorem meromorphicNFAt_smul_iff_right_of_analyticAt (h₁g : AnalyticAt π•œ g x) (hβ‚‚g : g x β‰  0) : MeromorphicNFAt (g β€’ f) x ↔ MeromorphicNFAt f x where mp hprod := by have : f =αΆ [𝓝 x] g⁻¹ β€’ g β€’ f := by filter_upwards [h₁g.continuousAt.preimage_mem_nhds (compl_singleton_mem_nhds_iff.mpr hβ‚‚g)] intro y hy rw [Set.preimage_compl, Set.mem_compl_iff, Set.mem_preimage, Set.mem_singleton_iff] at hy simp [hy] rw [meromorphicNFAt_congr this] exact hprod.smul_analytic (h₁g.inv hβ‚‚g) (inv_ne_zero hβ‚‚g) mpr hf := hf.smul_analytic h₁g hβ‚‚g /-- If `f` is any function and `g` is analytic without zero at `zβ‚€`, then `f` is meromorphic in normal form at `zβ‚€` iff `g * f` is meromorphic in normal form at `zβ‚€`. -/ theorem meromorphicNFAt_mul_iff_right {f : π•œ β†’ π•œ} (h₁g : AnalyticAt π•œ g x) (hβ‚‚g : g x β‰  0) : MeromorphicNFAt (g * f) x ↔ MeromorphicNFAt f x := meromorphicNFAt_smul_iff_right_of_analyticAt h₁g hβ‚‚g /-- If `f` is any function and `g` is analytic without zero at `zβ‚€`, then `f` is meromorphic in normal form at `zβ‚€` iff `f * g` is meromorphic in normal form at `zβ‚€`. -/ theorem meromorphicNFAt_mul_iff_left {f : π•œ β†’ π•œ} (h₁g : AnalyticAt π•œ g x) (hβ‚‚g : g x β‰  0) : MeromorphicNFAt (f * g) x ↔ MeromorphicNFAt f x := by rw [mul_comm, ← smul_eq_mul] exact meromorphicNFAt_smul_iff_right_of_analyticAt h₁g hβ‚‚g /-! ### Continuous extension and conversion to normal form -/ variable (f x) in /-- If `f` is meromorphic at `x`, convert `f` to normal form at `x` by changing its value at `x`. Otherwise, returns the 0 function. -/ noncomputable def toMeromorphicNFAt : π•œ β†’ E := by by_cases hf : MeromorphicAt f x Β· classical -- do not complain about decidability issues in Function.update apply Function.update f x by_cases h₁f : meromorphicOrderAt f x = (0 : β„€) Β· rw [meromorphicOrderAt_eq_int_iff hf] at h₁f exact (Classical.choose h₁f) x Β· exact 0 Β· exact 0 /-- Conversion to normal form at `x` changes the value only at x. -/ lemma MeromorphicAt.eqOn_compl_singleton_toMeromorphicNFAt (hf : MeromorphicAt f x) : Set.EqOn f (toMeromorphicNFAt f x) {x}ᢜ := fun _ _ ↦ by simp_all [toMeromorphicNFAt] @[deprecated (since := "2025-07-27")] alias MeromorphicAt.eqOn_compl_singleton_toMermomorphicNFAt := MeromorphicAt.eqOn_compl_singleton_toMeromorphicNFAt /-- If `f` is not meromorphic, conversion to normal form at `x` maps the function to `0`. -/ @[simp] lemma toMeromorphicNFAt_of_not_meromorphicAt (hf : Β¬MeromorphicAt f x) : toMeromorphicNFAt f x = 0 := by simp [toMeromorphicNFAt, hf] /-- Conversion to normal form at `x` changes the value only at x. -/ lemma MeromorphicAt.eq_nhdsNE_toMeromorphicNFAt (hf : MeromorphicAt f x) : f =αΆ [𝓝[β‰ ] x] toMeromorphicNFAt f x := eventually_nhdsWithin_of_forall (fun _ hz ↦ hf.eqOn_compl_singleton_toMeromorphicNFAt hz) @[deprecated (since := "2025-05-22")] alias MeromorphicAt.eq_nhdNE_toMeromorphicNFAt := MeromorphicAt.eq_nhdsNE_toMeromorphicNFAt /-- After conversion to normal form at `x`, the function has normal form. -/ theorem meromorphicNFAt_toMeromorphicNFAt : MeromorphicNFAt (toMeromorphicNFAt f x) x := by by_cases hf : MeromorphicAt f x Β· by_cases hβ‚‚f : meromorphicOrderAt f x = ⊀ Β· have : toMeromorphicNFAt f x =αΆ [𝓝 x] 0 := by apply eventuallyEq_nhds_of_eventuallyEq_nhdsNE Β· exact hf.eq_nhdsNE_toMeromorphicNFAt.symm.trans (meromorphicOrderAt_eq_top_iff.1 hβ‚‚f) Β· simp [hβ‚‚f, toMeromorphicNFAt, hf] apply AnalyticAt.meromorphicNFAt rw [analyticAt_congr this] exact analyticAt_const Β· lift meromorphicOrderAt f x to β„€ using hβ‚‚f with n hn obtain ⟨g, h₁g, hβ‚‚g, h₃g⟩ := (meromorphicOrderAt_eq_int_iff hf).1 hn.symm right use n, g, h₁g, hβ‚‚g apply eventuallyEq_nhds_of_eventuallyEq_nhdsNE (hf.eq_nhdsNE_toMeromorphicNFAt.symm.trans h₃g) simp only [toMeromorphicNFAt, hf, ↓reduceDIte, ← hn, WithTop.coe_zero, WithTop.coe_eq_zero, ne_eq, Function.update_self, sub_self] split_ifs with h₃f Β· obtain ⟨h₁G, _, h₃G⟩ := Classical.choose_spec ((meromorphicOrderAt_eq_int_iff hf).1 (h₃f β–Έ hn.symm)) apply Filter.EventuallyEq.eq_of_nhds apply (h₁G.continuousAt.eventuallyEq_nhds_iff_eventuallyEq_nhdsNE (by fun_prop)).1 filter_upwards [h₃g, h₃G] simp_all Β· simp [h₃f, zero_zpow] Β· simp only [toMeromorphicNFAt, hf, ↓reduceDIte] exact analyticAt_const.meromorphicNFAt /-- If `f` has normal form at `x`, then `f` equals `f.toNF`. -/ @[simp] theorem toMeromorphicNFAt_eq_self : toMeromorphicNFAt f x = f ↔ MeromorphicNFAt f x where mp hf := by rw [hf.symm] exact meromorphicNFAt_toMeromorphicNFAt mpr hf := by funext z by_cases hz : z = x Β· rw [hz] simp only [toMeromorphicNFAt, hf.meromorphicAt, WithTop.coe_zero, ne_eq] have hβ‚€f := hf rcases hf with h₁f | h₁f Β· simpa [meromorphicOrderAt_eq_top_iff.2 (h₁f.filter_mono nhdsWithin_le_nhds)] using h₁f.eq_of_nhds.symm Β· obtain ⟨n, g, h₁g, hβ‚‚g, h₃g⟩ := h₁f rw [Filter.EventuallyEq.eq_of_nhds h₃g] have : meromorphicOrderAt f x = n := by rw [meromorphicOrderAt_eq_int_iff hβ‚€f.meromorphicAt] use g, h₁g, hβ‚‚g exact eventually_nhdsWithin_of_eventually_nhds h₃g by_cases h₃f : meromorphicOrderAt f x = 0 Β· simp only [Pi.smul_apply', Pi.pow_apply, sub_self, h₃f, ↓reduceDIte] have hn : n = (0 : β„€) := by rw [h₃f] at this exact WithTop.coe_eq_zero.mp this.symm simp_rw [hn] simp only [zpow_zero, one_smul] have : g =αΆ [𝓝 x] Classical.choose ((meromorphicOrderAt_eq_int_iff hβ‚€f.meromorphicAt).1 h₃f) := by obtain ⟨hβ‚€, h₁, hβ‚‚βŸ© := Classical.choose_spec ((meromorphicOrderAt_eq_int_iff hβ‚€f.meromorphicAt).1 h₃f) rw [← h₁g.continuousAt.eventuallyEq_nhds_iff_eventuallyEq_nhdsNE hβ‚€.continuousAt] rw [hn] at h₃g simp only [zpow_zero, one_smul, ne_eq] at h₃g hβ‚‚ exact (h₃g.filter_mono nhdsWithin_le_nhds).symm.trans hβ‚‚ simp only [Function.update_self] exact Filter.EventuallyEq.eq_of_nhds this.symm Β· rw [eq_comm] simp only [Pi.smul_apply', Pi.pow_apply, sub_self, h₃f, ↓reduceDIte, smul_eq_zero, Function.update_self, smul_eq_zero] left apply zero_zpow n by_contra hn rw [hn] at this tauto Β· exact (hf.meromorphicAt.eqOn_compl_singleton_toMeromorphicNFAt hz).symm /-- If `f` is meromorphic in normal form, then so is its inverse. -/ theorem MeromorphicNFAt.inv {f : π•œ β†’ π•œ} (hf : MeromorphicNFAt f x) : MeromorphicNFAt f⁻¹ x := by rcases hf with h | ⟨n, g, h₁, hβ‚‚, hβ‚ƒβŸ© Β· left filter_upwards [h] with x hx simp [hx] Β· right use -n, g⁻¹, h₁.inv hβ‚‚, (by simp_all) filter_upwards [h₃] with y hy simp only [Pi.inv_apply, hy, Pi.smul_apply', Pi.pow_apply, smul_eq_mul, mul_inv_rev, zpow_neg] ring /-- A function to π•œ is meromorphic in normal form at a point iff its inverse is. -/ @[simp] theorem meromorphicNFAt_inv {f : π•œ β†’ π•œ} : MeromorphicNFAt f⁻¹ x ↔ MeromorphicNFAt f x where mp := by nth_rw 2 [← inv_inv f] exact .inv mpr hf := by simpa using hf.inv /-! ## Normal form of meromorphic functions on a given set ### Definition -/ /-- A function is 'meromorphic in normal form' on `U` if has normal form at every point of `U`. -/ def MeromorphicNFOn (f : π•œ β†’ E) (U : Set π•œ) := βˆ€ ⦃z⦄, z ∈ U β†’ MeromorphicNFAt f z /-! ### Relation to other properties of functions -/ /-- If a function is meromorphic in normal form on `U`, then it is meromorphic on `U`. -/ theorem MeromorphicNFOn.meromorphicOn (hf : MeromorphicNFOn f U) : MeromorphicOn f U := fun _ hz ↦ (hf hz).meromorphicAt /-- If a function is meromorphic in normal form on `U`, then its divisor is non-negative iff it is analytic. -/ theorem MeromorphicNFOn.divisor_nonneg_iff_analyticOnNhd (h₁f : MeromorphicNFOn f U) : 0 ≀ MeromorphicOn.divisor f U ↔ AnalyticOnNhd π•œ f U := by constructor <;> intro h x Β· intro hx rw [← (h₁f hx).meromorphicOrderAt_nonneg_iff_analyticAt] have := h x simp only [Function.locallyFinsuppWithin.coe_zero, Pi.zero_apply, h₁f.meromorphicOn, hx, MeromorphicOn.divisor_apply, untopβ‚€_nonneg] at this assumption Β· by_cases hx : x ∈ U Β· simp only [Function.locallyFinsuppWithin.coe_zero, Pi.zero_apply, h₁f.meromorphicOn, hx, MeromorphicOn.divisor_apply, untopβ‚€_nonneg] exact (h₁f hx).meromorphicOrderAt_nonneg_iff_analyticAt.2 (h x hx) Β· simp [hx] /-- Analytic functions are meromorphic in normal form. -/ theorem AnalyticOnNhd.meromorphicNFOn (h₁f : AnalyticOnNhd π•œ f U) : MeromorphicNFOn f U := fun z hz ↦ (h₁f z hz).meromorphicNFAt /-! ### Divisors and zeros of meromorphic functions in normal form. -/ /-- If `f` is meromorphic in normal form on `U` and nowhere locally constant zero, then its zero set equals the support of the associated divisor. -/ theorem MeromorphicNFOn.zero_set_eq_divisor_support (h₁f : MeromorphicNFOn f U) (hβ‚‚f : βˆ€ u : U, meromorphicOrderAt f u β‰  ⊀) : U ∩ f⁻¹' {0} = Function.support (MeromorphicOn.divisor f U) := by ext u constructor <;> intro hu Β· simp_all only [ne_eq, Subtype.forall, Set.mem_inter_iff, Set.mem_preimage, Set.mem_singleton_iff, Function.mem_support, h₁f.meromorphicOn, MeromorphicOn.divisor_apply, WithTop.untopβ‚€_eq_zero, (h₁f hu.1).meromorphicOrderAt_eq_zero_iff, not_true_eq_false, or_self, not_false_eq_true] Β· simp only [Function.mem_support, ne_eq] at hu constructor Β· exact (MeromorphicOn.divisor f U).supportWithinDomain hu Β· rw [Set.mem_preimage, Set.mem_singleton_iff] have := h₁f ((MeromorphicOn.divisor f U).supportWithinDomain hu) |>.meromorphicOrderAt_eq_zero_iff.not simp only [h₁f.meromorphicOn, (MeromorphicOn.divisor f U).supportWithinDomain hu, MeromorphicOn.divisor_apply, WithTop.untopβ‚€_eq_zero, not_or] at hu simp_all [hu.1] /-! ### Criteria to guarantee normal form -/ /-- If `f` is any function and `g` is analytic without zero on `U`, then `f` is meromorphic in normal form on `U` iff `g β€’ f` is meromorphic in normal form on `U`. -/ theorem meromorphicNFOn_smul_iff_right_of_analyticOnNhd {g : π•œ β†’ π•œ} (h₁g : AnalyticOnNhd π•œ g U) (hβ‚‚g : βˆ€ u ∈ U, g u β‰  0) : MeromorphicNFOn (g β€’ f) U ↔ MeromorphicNFOn f U := by constructor <;> intro h z hz Β· rw [← meromorphicNFAt_smul_iff_right_of_analyticAt (h₁g z hz) (hβ‚‚g z hz)] exact h hz Β· apply (h hz).smul_analytic (h₁g z hz) exact hβ‚‚g z hz /-- If `f` is any function and `g` is analytic without zero in `U`, then `f` is meromorphic in normal form on `U` iff `g * f` is meromorphic in normal form on `U`. -/ theorem meromorphicNFOn_mul_iff_right_of_analyticOnNhd {f g : π•œ β†’ π•œ} (h₁g : AnalyticOnNhd π•œ g U) (hβ‚‚g : βˆ€ u ∈ U, g u β‰  0) : MeromorphicNFOn (g * f) U ↔ MeromorphicNFOn f U := by rw [← smul_eq_mul] exact meromorphicNFOn_smul_iff_right_of_analyticOnNhd h₁g hβ‚‚g /-- If `f` is any function and `g` is analytic without zero in `U`, then `f` is meromorphic in normal form on `U` iff `f * g` is meromorphic in normal form on `U`. -/ theorem meromorphicNFOn_mul_iff_left_of_analyticOnNhd {f g : π•œ β†’ π•œ} (h₁g : AnalyticOnNhd π•œ g U) (hβ‚‚g : βˆ€ u ∈ U, g u β‰  0) : MeromorphicNFOn (f * g) U ↔ MeromorphicNFOn f U := by rw [mul_comm, ← smul_eq_mul] exact meromorphicNFOn_mul_iff_right_of_analyticOnNhd h₁g hβ‚‚g /-- A function to π•œ is meromorphic in normal form on `U` iff its inverse is. -/ theorem meromorphicNFOn_inv {f : π•œ β†’ π•œ} : MeromorphicNFOn f⁻¹ U ↔ MeromorphicNFOn f U where mp h _ hx := meromorphicNFAt_inv.1 (h hx) mpr h _ hx := meromorphicNFAt_inv.2 (h hx) /-! ### Continuous extension and conversion to normal form -/ variable (f U) in /-- If `f` is meromorphic on `U`, convert `f` to normal form on `U` by changing its values along a discrete subset within `U`. Otherwise, returns the 0 function. -/ noncomputable def toMeromorphicNFOn : π•œ β†’ E := by by_cases h₁f : MeromorphicOn f U Β· intro z by_cases hz : z ∈ U Β· exact toMeromorphicNFAt f z z Β· exact f z Β· exact 0 /-- If `f` is not meromorphic on `U`, conversion to normal form maps the function to `0`. -/ @[simp] lemma toMeromorphicNFOn_of_not_meromorphicOn (hf : Β¬MeromorphicOn f U) : toMeromorphicNFOn f U = 0 := by simp [toMeromorphicNFOn, hf] /-- Conversion to normal form on `U` does not change values outside of `U`. -/ @[simp] lemma toMeromorphicNFOn_eq_self_on_compl (hf : MeromorphicOn f U) : Set.EqOn (toMeromorphicNFOn f U) f Uᢜ := by intro x hx simp_all [toMeromorphicNFOn] /-- Conversion to normal form on `U` changes the value only along a discrete subset of `U`. -/ theorem toMeromorphicNFOn_eqOn_codiscrete (hf : MeromorphicOn f U) : f =αΆ [Filter.codiscreteWithin U] toMeromorphicNFOn f U := by have : U ∈ Filter.codiscreteWithin U := by simp [mem_codiscreteWithin.2] filter_upwards [hf.analyticAt_mem_codiscreteWithin, this] with a h₁a hβ‚‚a simp [toMeromorphicNFOn, hf, ← (toMeromorphicNFAt_eq_self.2 h₁a.meromorphicNFAt).symm] /-- If `f` is meromorphic on `U` and `x ∈ U`, then `f` and its conversion to normal form on `U` agree in a punctured neighborhood of `x`. -/ theorem MeromorphicOn.toMeromorphicNFOn_eq_self_on_nhdsNE (hf : MeromorphicOn f U) (hx : x ∈ U) : toMeromorphicNFOn f U =αΆ [𝓝[β‰ ] x] f := by filter_upwards [hf.eventually_analyticAt_or_mem_compl hx] with a ha rcases ha with ha | ha Β· simp [toMeromorphicNFOn, hf, ← (toMeromorphicNFAt_eq_self.2 ha.meromorphicNFAt).symm] Β· simp only [Set.mem_compl_iff] at ha simp [toMeromorphicNFOn, ha, hf] @[deprecated (since := "2025-05-22")] alias MeromorphicOn.toMeromorphicNFOn_eq_self_on_nhdNE := MeromorphicOn.toMeromorphicNFOn_eq_self_on_nhdsNE /-- If `f` is meromorphic on `U` and `x ∈ U`, then conversion to normal form at `x` and conversion to normal form on `U` agree in a neighborhood of `x`. -/ theorem toMeromorphicNFOn_eq_toMeromorphicNFAt_on_nhds (hf : MeromorphicOn f U) (hx : x ∈ U) : toMeromorphicNFOn f U =αΆ [𝓝 x] toMeromorphicNFAt f x := by apply eventuallyEq_nhds_of_eventuallyEq_nhdsNE Β· exact (hf.toMeromorphicNFOn_eq_self_on_nhdsNE hx).trans (hf x hx).eq_nhdsNE_toMeromorphicNFAt Β· simp [toMeromorphicNFOn, hf, hx] @[deprecated (since := "2025-05-22")] alias toMeromorphicNFOn_eq_toMeromorphicNFAt_on_nhd := toMeromorphicNFOn_eq_toMeromorphicNFAt_on_nhds /-- If `f` is meromorphic on `U` and `x ∈ U`, then conversion to normal form at `x` and conversion to normal form on `U` agree at `x`. -/ theorem toMeromorphicNFOn_eq_toMeromorphicNFAt (hf : MeromorphicOn f U) (hx : x ∈ U) : toMeromorphicNFOn f U x = toMeromorphicNFAt f x x := by apply Filter.EventuallyEq.eq_of_nhds (g := toMeromorphicNFAt f x) simp [(toMeromorphicNFOn_eq_toMeromorphicNFAt_on_nhds hf hx).trans] variable (f U) in /-- After conversion to normal form on `U`, the function has normal form. -/ theorem meromorphicNFOn_toMeromorphicNFOn : MeromorphicNFOn (toMeromorphicNFOn f U) U := by by_cases hf : MeromorphicOn f U Β· intro z hz rw [meromorphicNFAt_congr (toMeromorphicNFOn_eq_toMeromorphicNFAt_on_nhds hf hz)] exact meromorphicNFAt_toMeromorphicNFAt Β· simpa [hf] using analyticOnNhd_const.meromorphicNFOn /-- If `f` has normal form on `U`, then `f` equals `toMeromorphicNFOn f U`. -/ @[simp] theorem toMeromorphicNFOn_eq_self : toMeromorphicNFOn f U = f ↔ MeromorphicNFOn f U := by constructor <;> intro h Β· rw [h.symm] apply meromorphicNFOn_toMeromorphicNFOn Β· ext x by_cases hx : x ∈ U Β· simp only [toMeromorphicNFOn, h.meromorphicOn, ↓reduceDIte, hx] rw [toMeromorphicNFAt_eq_self.2 (h hx)] Β· simp [toMeromorphicNFOn, h.meromorphicOn, hx] /-- Conversion of normal form does not affect orders. -/ @[simp] theorem meromorphicOrderAt_toMeromorphicNFOn (hf : MeromorphicOn f U) (hx : x ∈ U) : meromorphicOrderAt (toMeromorphicNFOn f U) x = meromorphicOrderAt f x := by apply meromorphicOrderAt_congr exact hf.toMeromorphicNFOn_eq_self_on_nhdsNE hx @[deprecated (since := "2025-05-22")] alias order_toMeromorphicNFOn := meromorphicOrderAt_toMeromorphicNFOn /-- Conversion of normal form does not affect divisors. -/ @[simp] theorem MeromorphicOn.divisor_of_toMeromorphicNFOn (hf : MeromorphicOn f U) : divisor (toMeromorphicNFOn f U) U = divisor f U := by ext z by_cases hz : z ∈ U <;> simp [hf, (meromorphicNFOn_toMeromorphicNFOn f U).meromorphicOn, hz]
.lake/packages/mathlib/Mathlib/Analysis/Meromorphic/Basic.lean
import Mathlib.Analysis.Analytic.IsolatedZeros /-! # Meromorphic functions Main statements: * `MeromorphicAt`: definition of meromorphy at a point * `MeromorphicAt.iff_eventuallyEq_zpow_smul_analyticAt`: `f` is meromorphic at `zβ‚€` iff we have `f z = (z - zβ‚€) ^ n β€’ g z` on a punctured neighborhood of `zβ‚€`, for some `n : β„€` and `g` analytic at `zβ‚€`. -/ open Filter open scoped Topology variable {π•œ : Type*} [NontriviallyNormedField π•œ] {E : Type*} [NormedAddCommGroup E] [NormedSpace π•œ E] /-- Meromorphy of `f` at `x` (more precisely, on a punctured neighbourhood of `x`; the value at `x` itself is irrelevant). -/ @[fun_prop] def MeromorphicAt (f : π•œ β†’ E) (x : π•œ) := βˆƒ (n : β„•), AnalyticAt π•œ (fun z ↦ (z - x) ^ n β€’ f z) x @[fun_prop] lemma AnalyticAt.meromorphicAt {f : π•œ β†’ E} {x : π•œ} (hf : AnalyticAt π•œ f x) : MeromorphicAt f x := ⟨0, by simpa only [pow_zero, one_smul]⟩ /- Analogue of the principle of isolated zeros for an analytic function: if a function is meromorphic at `zβ‚€`, then either it is identically zero in a punctured neighborhood of `zβ‚€`, or it does not vanish there at all. -/ theorem MeromorphicAt.eventually_eq_zero_or_eventually_ne_zero {f : π•œ β†’ E} {zβ‚€ : π•œ} (hf : MeromorphicAt f zβ‚€) : (βˆ€αΆ  z in 𝓝[β‰ ] zβ‚€, f z = 0) ∨ (βˆ€αΆ  z in 𝓝[β‰ ] zβ‚€, f z β‰  0) := by obtain ⟨n, h⟩ := hf rcases h.eventually_eq_zero_or_eventually_ne_zero with h₁ | hβ‚‚ Β· left filter_upwards [nhdsWithin_le_nhds h₁, self_mem_nhdsWithin] with y h₁y hβ‚‚y rw [Set.mem_compl_iff, Set.mem_singleton_iff, ← sub_eq_zero] at hβ‚‚y exact smul_eq_zero_iff_right (pow_ne_zero n hβ‚‚y) |>.mp h₁y Β· right filter_upwards [hβ‚‚, self_mem_nhdsWithin] with y h₁y hβ‚‚y exact (smul_ne_zero_iff.1 h₁y).2 namespace MeromorphicAt variable {ΞΉ : Type*} {s : Finset ΞΉ} {F : ΞΉ β†’ π•œ β†’ π•œ} {G : ΞΉ β†’ π•œ β†’ E} @[fun_prop] lemma id (x : π•œ) : MeromorphicAt id x := analyticAt_id.meromorphicAt @[fun_prop, simp] lemma const (e : E) (x : π•œ) : MeromorphicAt (fun _ ↦ e) x := analyticAt_const.meromorphicAt variable {x : π•œ} @[fun_prop] lemma add {f g : π•œ β†’ E} (hf : MeromorphicAt f x) (hg : MeromorphicAt g x) : MeromorphicAt (f + g) x := by rcases hf with ⟨m, hf⟩ rcases hg with ⟨n, hg⟩ refine ⟨max m n, ?_⟩ have : (fun z ↦ (z - x) ^ max m n β€’ (f + g) z) = fun z ↦ (z - x) ^ (max m n - m) β€’ ((z - x) ^ m β€’ f z) + (z - x) ^ (max m n - n) β€’ ((z - x) ^ n β€’ g z) := by simp_rw [← mul_smul, ← pow_add, Nat.sub_add_cancel (Nat.le_max_left _ _), Nat.sub_add_cancel (Nat.le_max_right _ _), Pi.add_apply, smul_add] rw [this] exact (((analyticAt_id.sub analyticAt_const).pow _).smul hf).add (((analyticAt_id.sub analyticAt_const).pow _).smul hg) @[fun_prop] lemma fun_add {f g : π•œ β†’ E} (hf : MeromorphicAt f x) (hg : MeromorphicAt g x) : MeromorphicAt (fun z ↦ f z + g z) x := hf.add hg @[deprecated (since := "2025-05-09")] alias add' := fun_add @[fun_prop] lemma smul {f : π•œ β†’ π•œ} {g : π•œ β†’ E} (hf : MeromorphicAt f x) (hg : MeromorphicAt g x) : MeromorphicAt (f β€’ g) x := by rcases hf with ⟨m, hf⟩ rcases hg with ⟨n, hg⟩ refine ⟨m + n, ?_⟩ convert hf.fun_smul hg using 2 with z rw [Pi.smul_apply', smul_eq_mul] module @[fun_prop] lemma fun_smul {f : π•œ β†’ π•œ} {g : π•œ β†’ E} (hf : MeromorphicAt f x) (hg : MeromorphicAt g x) : MeromorphicAt (fun z ↦ f z β€’ g z) x := hf.smul hg @[deprecated (since := "2025-05-09")] alias smul' := fun_smul @[fun_prop] lemma mul {f g : π•œ β†’ π•œ} (hf : MeromorphicAt f x) (hg : MeromorphicAt g x) : MeromorphicAt (f * g) x := hf.smul hg @[fun_prop] lemma fun_mul {f g : π•œ β†’ π•œ} (hf : MeromorphicAt f x) (hg : MeromorphicAt g x) : MeromorphicAt (fun z ↦ f z * g z) x := hf.smul hg @[deprecated (since := "2025-05-09")] alias mul' := fun_mul /-- Finite products of meromorphic functions are meromorphic. -/ @[fun_prop] theorem prod (h : βˆ€ Οƒ, MeromorphicAt (F Οƒ) x) : MeromorphicAt (∏ n ∈ s, F n) x := by classical induction s using Finset.induction with | empty => rw [Finset.prod_empty] exact analyticAt_const.meromorphicAt | insert Οƒ s hΟƒ hind => rw [Finset.prod_insert hΟƒ] exact (h Οƒ).mul hind /-- Finite products of meromorphic functions are meromorphic. -/ @[fun_prop] theorem fun_prod (h : βˆ€ Οƒ, MeromorphicAt (F Οƒ) x) : MeromorphicAt (fun z ↦ ∏ n ∈ s, F n z) x := by convert prod h (s := s) simp /-- Finite sums of meromorphic functions are meromorphic. -/ @[fun_prop] theorem sum (h : βˆ€ Οƒ, MeromorphicAt (G Οƒ) x) : MeromorphicAt (βˆ‘ n ∈ s, G n) x := by classical induction s using Finset.induction with | empty => simp only [Finset.sum_empty] exact analyticAt_const.meromorphicAt | insert Οƒ s hΟƒ hind => rw [Finset.sum_insert hΟƒ] exact (h Οƒ).add hind /-- Finite sums of meromorphic functions are meromorphic. -/ @[fun_prop] theorem fun_sum (h : βˆ€ Οƒ, MeromorphicAt (G Οƒ) x) : MeromorphicAt (fun z ↦ βˆ‘ n ∈ s, G n z) x := by convert sum h (s := s) simp @[fun_prop] lemma neg {f : π•œ β†’ E} (hf : MeromorphicAt f x) : MeromorphicAt (-f) x := by convert (MeromorphicAt.const (-1 : π•œ) x).smul hf using 1 ext1 z simp only [Pi.neg_apply, Pi.smul_apply', neg_smul, one_smul] @[fun_prop] lemma fun_neg {f : π•œ β†’ E} (hf : MeromorphicAt f x) : MeromorphicAt (fun z ↦ -f z) x := hf.neg @[deprecated (since := "2025-05-09")] alias neg' := fun_neg @[simp] lemma neg_iff {f : π•œ β†’ E} : MeromorphicAt (-f) x ↔ MeromorphicAt f x := ⟨fun h ↦ by simpa only [neg_neg] using h.neg, MeromorphicAt.neg⟩ @[fun_prop] lemma sub {f g : π•œ β†’ E} (hf : MeromorphicAt f x) (hg : MeromorphicAt g x) : MeromorphicAt (f - g) x := by convert hf.add hg.neg using 1 ext1 z simp_rw [Pi.sub_apply, Pi.add_apply, Pi.neg_apply, sub_eq_add_neg] @[fun_prop] lemma fun_sub {f g : π•œ β†’ E} (hf : MeromorphicAt f x) (hg : MeromorphicAt g x) : MeromorphicAt (fun z ↦ f z - g z) x := hf.sub hg /-- If `f` is meromorphic at `x`, then `f + g` is meromorphic at `x` if and only if `g` is meromorphic at `x`. -/ lemma meromorphicAt_add_iff_meromorphicAt₁ {f g : π•œ β†’ E} (hf : MeromorphicAt f x) : MeromorphicAt (f + g) x ↔ MeromorphicAt g x := by exact ⟨fun h ↦ by simpa using h.sub hf, fun _ ↦ by fun_prop⟩ /-- If `g` is meromorphic at `x`, then `f + g` is meromorphic at `x` if and only if `f` is meromorphic at `x`. -/ lemma meromorphicAt_add_iff_meromorphicAtβ‚‚ {f g : π•œ β†’ E} (hg : MeromorphicAt g x) : MeromorphicAt (f + g) x ↔ MeromorphicAt f x := by rw [add_comm] exact meromorphicAt_add_iff_meromorphicAt₁ hg /-- If `f` is meromorphic at `x`, then `f - g` is meromorphic at `x` if and only if `g` is meromorphic at `x`. -/ lemma meromorphicAt_sub_iff_meromorphicAt₁ {f g : π•œ β†’ E} (hf : MeromorphicAt f x) : MeromorphicAt (f - g) x ↔ MeromorphicAt g x := by exact ⟨fun h ↦ by simpa using h.sub hf, fun _ ↦ by fun_prop⟩ /-- If `g` is meromorphic at `x`, then `f - g` is meromorphic at `x` if and only if `f` is meromorphic at `x`. -/ lemma meromorphicAt_sub_iff_meromorphicAtβ‚‚ {f g : π•œ β†’ E} (hg : MeromorphicAt g x) : MeromorphicAt (f - g) x ↔ MeromorphicAt f x := by exact ⟨fun h ↦ by simpa using h.add hg, fun _ ↦ by fun_prop⟩ @[deprecated (since := "2025-05-09")] alias sub' := fun_sub /-- With our definitions, `MeromorphicAt f x` depends only on the values of `f` on a punctured neighbourhood of `x` (not on `f x`) -/ lemma congr {f g : π•œ β†’ E} (hf : MeromorphicAt f x) (hfg : f =αΆ [𝓝[β‰ ] x] g) : MeromorphicAt g x := by rcases hf with ⟨m, hf⟩ refine ⟨m + 1, ?_⟩ have : AnalyticAt π•œ (fun z ↦ z - x) x := analyticAt_id.sub analyticAt_const refine (this.fun_smul hf).congr ?_ rw [eventuallyEq_nhdsWithin_iff] at hfg filter_upwards [hfg] with z hz rcases eq_or_ne z x with rfl | hn Β· simp Β· rw [hz (Set.mem_compl_singleton_iff.mp hn), pow_succ', mul_smul] /-- If two functions agree on a punctured neighborhood, then one is meromorphic iff the other is so. -/ lemma meromorphicAt_congr {f g : π•œ β†’ E} (h : f =αΆ [𝓝[β‰ ] x] g) : MeromorphicAt f x ↔ MeromorphicAt g x := ⟨fun hf ↦ hf.congr h, fun hg ↦ hg.congr h.symm⟩ @[simp] lemma update_iff [DecidableEq π•œ] {f : π•œ β†’ E} {z w : π•œ} {e : E} : MeromorphicAt (Function.update f w e) z ↔ MeromorphicAt f z := meromorphicAt_congr (Function.update_eventuallyEq_nhdsNE f w z e) @[fun_prop] lemma update [DecidableEq π•œ] {f : π•œ β†’ E} {z} (hf : MeromorphicAt f z) (w e) : MeromorphicAt (Function.update f w e) z := update_iff.mpr hf @[fun_prop] lemma inv {f : π•œ β†’ π•œ} (hf : MeromorphicAt f x) : MeromorphicAt f⁻¹ x := by rcases hf with ⟨m, hf⟩ by_cases h_eq : (fun z ↦ (z - x) ^ m β€’ f z) =αΆ [𝓝 x] 0 Β· -- silly case: f locally 0 near x refine (MeromorphicAt.const 0 x).congr ?_ rw [eventuallyEq_nhdsWithin_iff] filter_upwards [h_eq] with z hfz hz rw [Pi.inv_apply, (smul_eq_zero_iff_right <| pow_ne_zero _ (sub_ne_zero.mpr hz)).mp hfz, inv_zero] Β· -- interesting case: use local formula for `f` obtain ⟨n, g, hg_an, hg_ne, hg_eq⟩ := hf.exists_eventuallyEq_pow_smul_nonzero_iff.mpr h_eq have : AnalyticAt π•œ (fun z ↦ (z - x) ^ (m + 1)) x := (analyticAt_id.sub analyticAt_const).pow _ -- use `m + 1` rather than `m` to damp out any silly issues with the value at `z = x` refine ⟨n + 1, (this.fun_smul <| hg_an.inv hg_ne).congr ?_⟩ filter_upwards [hg_eq, hg_an.continuousAt.eventually_ne hg_ne] with z hfg hg_ne' rcases eq_or_ne z x with rfl | hz_ne Β· simp only [sub_self, pow_succ, mul_zero, zero_smul] Β· simp_rw [smul_eq_mul] at hfg ⊒ have aux1 : f z β‰  0 := by have : (z - x) ^ n * g z β‰  0 := mul_ne_zero (pow_ne_zero _ (sub_ne_zero.mpr hz_ne)) hg_ne' rw [← hfg, mul_ne_zero_iff] at this exact this.2 simp [field, pow_succ', mul_assoc, hfg] @[fun_prop] lemma fun_inv {f : π•œ β†’ π•œ} (hf : MeromorphicAt f x) : MeromorphicAt (fun z ↦ (f z)⁻¹) x := hf.inv @[deprecated (since := "2025-05-09")] alias inv' := fun_inv @[simp] lemma inv_iff {f : π•œ β†’ π•œ} : MeromorphicAt f⁻¹ x ↔ MeromorphicAt f x := ⟨fun h ↦ by simpa only [inv_inv] using h.inv, MeromorphicAt.inv⟩ @[fun_prop] lemma div {f g : π•œ β†’ π•œ} (hf : MeromorphicAt f x) (hg : MeromorphicAt g x) : MeromorphicAt (f / g) x := (div_eq_mul_inv f g).symm β–Έ (hf.mul hg.inv) @[fun_prop] lemma fun_div {f g : π•œ β†’ π•œ} (hf : MeromorphicAt f x) (hg : MeromorphicAt g x) : MeromorphicAt (fun z ↦ f z / g z) x := hf.div hg @[deprecated (since := "2025-05-09")] alias div' := fun_div @[fun_prop] lemma pow {f : π•œ β†’ π•œ} (hf : MeromorphicAt f x) (n : β„•) : MeromorphicAt (f ^ n) x := by induction n with | zero => simpa only [pow_zero] using MeromorphicAt.const 1 x | succ m hm => simpa only [pow_succ] using hm.mul hf @[fun_prop] lemma fun_pow {f : π•œ β†’ π•œ} (hf : MeromorphicAt f x) (n : β„•) : MeromorphicAt (fun z ↦ (f z) ^ n) x := hf.pow n @[deprecated (since := "2025-05-09")] alias pow' := fun_pow @[fun_prop] lemma zpow {f : π•œ β†’ π•œ} (hf : MeromorphicAt f x) (n : β„€) : MeromorphicAt (f ^ n) x := by cases n with | ofNat m => simpa only [Int.ofNat_eq_coe, zpow_natCast] using hf.pow m | negSucc m => simpa only [zpow_negSucc, inv_iff] using hf.pow (m + 1) @[fun_prop] lemma fun_zpow {f : π•œ β†’ π•œ} (hf : MeromorphicAt f x) (n : β„€) : MeromorphicAt (fun z ↦ (f z) ^ n) x := hf.zpow n @[deprecated (since := "2025-05-09")] alias zpow' := fun_zpow /-- If a function is meromorphic at a point, then it is continuous at nearby points. -/ theorem eventually_continuousAt {f : π•œ β†’ E} (h : MeromorphicAt f x) : βˆ€αΆ  y in 𝓝[β‰ ] x, ContinuousAt f y := by obtain ⟨n, h⟩ := h have : βˆ€αΆ  y in 𝓝[β‰ ] x, ContinuousAt (fun z ↦ (z - x) ^ n β€’ f z) y := nhdsWithin_le_nhds h.eventually_continuousAt filter_upwards [this, self_mem_nhdsWithin] with y hy h'y simp only [Set.mem_compl_iff, Set.mem_singleton_iff] at h'y have : ContinuousAt (fun z ↦ ((z - x) ^ n)⁻¹) y := ContinuousAt.invβ‚€ (by fun_prop) (by simp [sub_eq_zero, h'y]) apply (this.smul hy).congr filter_upwards [eventually_ne_nhds h'y] with z hz simp [smul_smul, hz, sub_eq_zero] /-- In a complete space, a function which is meromorphic at a point is analytic at all nearby points. The completeness assumption can be dispensed with if one assumes that `f` is meromorphic on a set around `x`, see `MeromorphicOn.eventually_analyticAt`. -/ theorem eventually_analyticAt [CompleteSpace E] {f : π•œ β†’ E} (h : MeromorphicAt f x) : βˆ€αΆ  y in 𝓝[β‰ ] x, AnalyticAt π•œ f y := by obtain ⟨n, h⟩ := h apply AnalyticAt.eventually_analyticAt at h refine (h.filter_mono ?_).mp ?_ Β· simp [nhdsWithin] Β· rw [eventually_nhdsWithin_iff] apply Filter.Eventually.of_forall intro y hy hf rw [Set.mem_compl_iff, Set.mem_singleton_iff] at hy have := ((analyticAt_id (π•œ := π•œ).sub analyticAt_const).pow n).inv (pow_ne_zero _ (sub_ne_zero_of_ne hy)) apply (this.smul hf).congr ∘ (eventually_ne_nhds hy).mono intro z hz simp [smul_smul, hz, sub_eq_zero] lemma iff_eventuallyEq_zpow_smul_analyticAt {f : π•œ β†’ E} : MeromorphicAt f x ↔ βˆƒ (n : β„€) (g : π•œ β†’ E), AnalyticAt π•œ g x ∧ βˆ€αΆ  z in 𝓝[β‰ ] x, f z = (z - x) ^ n β€’ g z := by refine ⟨fun ⟨n, hn⟩ ↦ ⟨-n, _, ⟨hn, eventually_nhdsWithin_iff.mpr ?_⟩⟩, ?_⟩ Β· filter_upwards with z hz match_scalars simp [sub_ne_zero.mpr hz] Β· refine fun ⟨n, g, hg_an, hg_eq⟩ ↦ MeromorphicAt.congr ?_ (EventuallyEq.symm hg_eq) exact (((MeromorphicAt.id x).sub (.const _ x)).zpow _).smul hg_an.meromorphicAt end MeromorphicAt /-- Meromorphy of a function on a set. -/ def MeromorphicOn (f : π•œ β†’ E) (U : Set π•œ) : Prop := βˆ€ x ∈ U, MeromorphicAt f x lemma AnalyticOnNhd.meromorphicOn {f : π•œ β†’ E} {U : Set π•œ} (hf : AnalyticOnNhd π•œ f U) : MeromorphicOn f U := fun x hx ↦ (hf x hx).meromorphicAt namespace MeromorphicOn variable {s t : π•œ β†’ π•œ} {f g : π•œ β†’ E} {U : Set π•œ} (hs : MeromorphicOn s U) (ht : MeromorphicOn t U) (hf : MeromorphicOn f U) (hg : MeromorphicOn g U) /-- If `f` is meromorphic on `U`, if `g` agrees with `f` on a codiscrete subset of `U` and outside of `U`, then `g` is also meromorphic on `U`. -/ theorem congr_codiscreteWithin_of_eqOn_compl (hf : MeromorphicOn f U) (h₁ : f =αΆ [codiscreteWithin U] g) (hβ‚‚ : Set.EqOn f g Uᢜ) : MeromorphicOn g U := by intro x hx apply (hf x hx).congr simp_rw [EventuallyEq, Filter.Eventually, mem_codiscreteWithin, disjoint_principal_right] at h₁ filter_upwards [h₁ x hx] with a ha simp at ha tauto /-- If `f` is meromorphic on an open set `U`, if `g` agrees with `f` on a codiscrete subset of `U`, then `g` is also meromorphic on `U`. -/ theorem congr_codiscreteWithin (hf : MeromorphicOn f U) (h₁ : f =αΆ [codiscreteWithin U] g) (hβ‚‚ : IsOpen U) : MeromorphicOn g U := by intro x hx apply (hf x hx).congr simp_rw [EventuallyEq, Filter.Eventually, mem_codiscreteWithin, disjoint_principal_right] at h₁ have : U ∈ 𝓝[β‰ ] x := by apply mem_nhdsWithin.mpr use U, hβ‚‚, hx, Set.inter_subset_left filter_upwards [this, h₁ x hx] with a h₁a hβ‚‚a simp only [Set.mem_compl_iff, Set.mem_diff, Set.mem_setOf_eq, not_and] at hβ‚‚a tauto lemma id {U : Set π•œ} : MeromorphicOn id U := fun x _ ↦ .id x lemma const (e : E) {U : Set π•œ} : MeromorphicOn (fun _ ↦ e) U := fun x _ ↦ .const e x section arithmetic include hf in lemma mono_set {V : Set π•œ} (hv : V βŠ† U) : MeromorphicOn f V := fun x hx ↦ hf x (hv hx) include hf hg in lemma add : MeromorphicOn (f + g) U := fun x hx ↦ (hf x hx).add (hg x hx) include hf hg in lemma fun_add : MeromorphicOn (fun z ↦ f z + g z) U := fun x hx ↦ (hf x hx).add (hg x hx) include hf hg in lemma sub : MeromorphicOn (f - g) U := fun x hx ↦ (hf x hx).sub (hg x hx) include hf hg in lemma fun_sub : MeromorphicOn (fun z ↦ f z - g z) U := fun x hx ↦ (hf x hx).sub (hg x hx) include hf in lemma neg : MeromorphicOn (-f) U := fun x hx ↦ (hf x hx).neg include hf in lemma fun_neg : MeromorphicOn (fun z ↦ -f z) U := fun x hx ↦ (hf x hx).neg @[simp] lemma neg_iff : MeromorphicOn (-f) U ↔ MeromorphicOn f U := ⟨fun h ↦ by simpa only [neg_neg] using h.neg, neg⟩ include hs hf in lemma smul : MeromorphicOn (s β€’ f) U := fun x hx ↦ (hs x hx).smul (hf x hx) include hs hf in lemma fun_smul : MeromorphicOn (fun z ↦ s z β€’ f z) U := fun x hx ↦ (hs x hx).smul (hf x hx) include hs ht in lemma mul : MeromorphicOn (s * t) U := fun x hx ↦ (hs x hx).mul (ht x hx) include hs ht in lemma fun_mul : MeromorphicOn (fun z ↦ s z * t z) U := fun x hx ↦ (hs x hx).mul (ht x hx) /-- Finite products of meromorphic functions are meromorphic. -/ lemma prod {U : Set π•œ} {ΞΉ : Type*} {s : Finset ΞΉ} {f : ΞΉ β†’ π•œ β†’ π•œ} (h : βˆ€ Οƒ, MeromorphicOn (f Οƒ) U) : MeromorphicOn (∏ n ∈ s, f n) U := fun z hz ↦ MeromorphicAt.prod (fun Οƒ ↦ h Οƒ z hz) /-- Finite products of meromorphic functions are meromorphic. -/ lemma fun_prod {U : Set π•œ} {ΞΉ : Type*} {s : Finset ΞΉ} {f : ΞΉ β†’ π•œ β†’ π•œ} (h : βˆ€ Οƒ, MeromorphicOn (f Οƒ) U) : MeromorphicOn (fun z ↦ ∏ n ∈ s, f n z) U := fun z hz ↦ MeromorphicAt.fun_prod (fun Οƒ ↦ h Οƒ z hz) /-- Finite sums of meromorphic functions are meromorphic. -/ lemma sum {U : Set π•œ} {ΞΉ : Type*} {s : Finset ΞΉ} {f : ΞΉ β†’ π•œ β†’ E} (h : βˆ€ Οƒ, MeromorphicOn (f Οƒ) U) : MeromorphicOn (βˆ‘ n ∈ s, f n) U := fun z hz ↦ MeromorphicAt.sum (fun Οƒ ↦ h Οƒ z hz) /-- Finite sums of meromorphic functions are meromorphic. -/ lemma fun_sum {U : Set π•œ} {ΞΉ : Type*} {s : Finset ΞΉ} {f : ΞΉ β†’ π•œ β†’ E} (h : βˆ€ Οƒ, MeromorphicOn (f Οƒ) U) : MeromorphicOn (fun z ↦ βˆ‘ n ∈ s, f n z) U := fun z hz ↦ MeromorphicAt.fun_sum (fun Οƒ ↦ h Οƒ z hz) include hs in lemma inv : MeromorphicOn s⁻¹ U := fun x hx ↦ (hs x hx).inv include hs in lemma fun_inv : MeromorphicOn (fun z ↦ s⁻¹ z) U := fun x hx ↦ (hs x hx).inv @[simp] lemma inv_iff : MeromorphicOn s⁻¹ U ↔ MeromorphicOn s U := ⟨fun h ↦ by simpa only [inv_inv] using h.inv, inv⟩ include hs ht in lemma div : MeromorphicOn (s / t) U := fun x hx ↦ (hs x hx).div (ht x hx) include hs ht in lemma fun_div : MeromorphicOn (fun z ↦ s z / t z) U := fun x hx ↦ (hs x hx).div (ht x hx) include hs in lemma pow (n : β„•) : MeromorphicOn (s ^ n) U := fun x hx ↦ (hs x hx).pow _ include hs in lemma fun_pow (n : β„•) : MeromorphicOn (fun z ↦ s z ^ n) U := fun x hx ↦ (hs x hx).pow _ include hs in lemma zpow (n : β„€) : MeromorphicOn (s ^ n) U := fun x hx ↦ (hs x hx).zpow _ include hs in lemma fun_zpow (n : β„€) : MeromorphicOn (fun z ↦ s z ^ n) U := fun x hx ↦ (hs x hx).zpow _ end arithmetic include hf in lemma congr (h_eq : Set.EqOn f g U) (hu : IsOpen U) : MeromorphicOn g U := by refine fun x hx ↦ (hf x hx).congr (EventuallyEq.filter_mono ?_ nhdsWithin_le_nhds) exact eventually_of_mem (hu.mem_nhds hx) h_eq theorem eventually_codiscreteWithin_analyticAt [CompleteSpace E] (f : π•œ β†’ E) (h : MeromorphicOn f U) : βˆ€αΆ  (y : π•œ) in codiscreteWithin U, AnalyticAt π•œ f y := by rw [eventually_iff, mem_codiscreteWithin] intro x hx rw [disjoint_principal_right] apply Filter.mem_of_superset ((h x hx).eventually_analyticAt) intro x hx simp [hx] end MeromorphicOn
.lake/packages/mathlib/Mathlib/Analysis/Meromorphic/TrailingCoefficient.lean
import Mathlib.Analysis.Meromorphic.Order /-! # The Trailing Coefficient of a Meromorphic Function This file defines the trailing coefficient of a meromorphic function. If `f` is meromorphic at a point `x`, the trailing coefficient is defined as the (unique!) value `g x` for a presentation of `f` in the form `(z - x) ^ order β€’ g z` with `g` analytic at `x`. The lemma `MeromorphicAt.tendsto_nhds_meromorphicTrailingCoeffAt` expresses the trailing coefficient as a limit. -/ variable {π•œ : Type*} [NontriviallyNormedField π•œ] {E : Type*} [NormedAddCommGroup E] [NormedSpace π•œ E] {f g : π•œ β†’ E} {x : π•œ} open Filter Topology variable (f x) in /-- If `f` is meromorphic of finite order at a point `x`, the trailing coefficient is defined as the (unique!) value `g x` for a presentation of `f` in the form `(z - x) ^ order β€’ g z` with `g` analytic at `x`. In all other cases, the trailing coefficient is defined to be zero. -/ noncomputable def meromorphicTrailingCoeffAt : E := by by_cases h₁ : MeromorphicAt f x Β· by_cases hβ‚‚ : meromorphicOrderAt f x = ⊀ Β· exact 0 Β· exact ((meromorphicOrderAt_ne_top_iff h₁).1 hβ‚‚).choose x Β· exact 0 /-- If `f` is not meromorphic at `x`, the trailing coefficient is zero by definition. -/ @[simp] lemma meromorphicTrailingCoeffAt_of_not_MeromorphicAt (h : Β¬MeromorphicAt f x) : meromorphicTrailingCoeffAt f x = 0 := by simp [meromorphicTrailingCoeffAt, h] /-- If `f` is meromorphic of infinite order at `x`, the trailing coefficient is zero by definition. -/ @[simp] lemma MeromorphicAt.meromorphicTrailingCoeffAt_of_order_eq_top (h : meromorphicOrderAt f x = ⊀) : meromorphicTrailingCoeffAt f x = 0 := by simp_all [meromorphicTrailingCoeffAt] /-! ## Characterization of the Trailing Coefficient -/ /-- Definition of the trailing coefficient in case where `f` is meromorphic and a presentation of the form `f = (z - x) ^ order β€’ g z` is given, with `g` analytic at `x`. -/ lemma AnalyticAt.meromorphicTrailingCoeffAt_of_eq_nhdsNE (h₁g : AnalyticAt π•œ g x) (h : f =αΆ [𝓝[β‰ ] x] fun z ↦ (z - x) ^ (meromorphicOrderAt f x).untopβ‚€ β€’ g z) : meromorphicTrailingCoeffAt f x = g x := by have h₁f : MeromorphicAt f x := by rw [MeromorphicAt.meromorphicAt_congr h] fun_prop by_cases h₃ : meromorphicOrderAt f x = ⊀ Β· simp only [h₃, WithTop.untopβ‚€_top, zpow_zero, one_smul, MeromorphicAt.meromorphicTrailingCoeffAt_of_order_eq_top] at ⊒ h apply EventuallyEq.eq_of_nhds (f := 0) rw [← ContinuousAt.eventuallyEq_nhds_iff_eventuallyEq_nhdsNE (by fun_prop) (by fun_prop)] apply (h.symm.trans (meromorphicOrderAt_eq_top_iff.1 h₃)).symm Β· unfold meromorphicTrailingCoeffAt simp only [h₁f, reduceDIte, h₃, ne_eq] obtain ⟨h'₁, h'β‚‚, h'β‚ƒβŸ© := ((meromorphicOrderAt_ne_top_iff h₁f).1 h₃).choose_spec apply Filter.EventuallyEq.eq_of_nhds rw [← h'₁.continuousAt.eventuallyEq_nhds_iff_eventuallyEq_nhdsNE h₁g.continuousAt] filter_upwards [h, h'₃, self_mem_nhdsWithin] with y h₁y hβ‚‚y h₃y rw [← sub_eq_zero] rwa [hβ‚‚y, ← sub_eq_zero, ← smul_sub, smul_eq_zero_iff_right] at h₁y simp_all [zpow_ne_zero, sub_ne_zero] /-- Variant of `meromorphicTrailingCoeffAt_of_order_eq_finite`: Definition of the trailing coefficient in case where `f` is meromorphic of finite order and a presentation is given. -/ lemma AnalyticAt.meromorphicTrailingCoeffAt_of_ne_zero_of_eq_nhdsNE {n : β„€} (h₁g : AnalyticAt π•œ g x) (hβ‚‚g : g x β‰  0) (h : f =αΆ [𝓝[β‰ ] x] fun z ↦ (z - x) ^ n β€’ g z) : meromorphicTrailingCoeffAt f x = g x := by have hβ‚„ : MeromorphicAt f x := by rw [MeromorphicAt.meromorphicAt_congr h] fun_prop have : meromorphicOrderAt f x = n := by simp only [meromorphicOrderAt_eq_int_iff hβ‚„, ne_eq] use g, h₁g, hβ‚‚g exact h simp_all [meromorphicTrailingCoeffAt_of_eq_nhdsNE h₁g] /-- If `f` is analytic and does not vanish at `x`, then the trailing coefficient of `f` at `x` is `f x`. -/ @[simp] lemma AnalyticAt.meromorphicTrailingCoeffAt_of_ne_zero (h₁ : AnalyticAt π•œ f x) (hβ‚‚ : f x β‰  0) : meromorphicTrailingCoeffAt f x = f x := by rw [h₁.meromorphicTrailingCoeffAt_of_ne_zero_of_eq_nhdsNE (n := 0) hβ‚‚] filter_upwards simp /-- If `f` is meromorphic at `x`, then the trailing coefficient of `f` at `x` is the limit of the function `(Β· - x) ^ (-order) β€’ f`. -/ lemma MeromorphicAt.tendsto_nhds_meromorphicTrailingCoeffAt (h : MeromorphicAt f x) : Tendsto ((Β· - x) ^ (-(meromorphicOrderAt f x).untopβ‚€) β€’ f) (𝓝[β‰ ] x) (𝓝 (meromorphicTrailingCoeffAt f x)) := by by_cases hβ‚‚ : meromorphicOrderAt f x = ⊀ Β· simp_all only [WithTop.untopβ‚€_top, neg_zero, zpow_zero, one_smul, meromorphicTrailingCoeffAt_of_order_eq_top] apply Tendsto.congr' (f₁ := 0) Β· filter_upwards [meromorphicOrderAt_eq_top_iff.1 hβ‚‚] with y hy simp_all Β· apply Tendsto.congr' (f₁ := 0) (by rfl) continuousWithinAt_const.tendsto obtain ⟨g, h₁g, hβ‚‚g, h₃g⟩ := (meromorphicOrderAt_ne_top_iff h).1 hβ‚‚ apply Tendsto.congr' (f₁ := g) Β· filter_upwards [h₃g, self_mem_nhdsWithin] with y h₁y hβ‚‚y rw [zpow_neg, Pi.smul_apply', Pi.inv_apply, Pi.pow_apply, h₁y, ← smul_assoc, smul_eq_mul, ← zpow_neg, ← zpow_add', neg_add_cancel, zpow_zero, one_smul] left simp_all [sub_ne_zero] Β· rw [h₁g.meromorphicTrailingCoeffAt_of_eq_nhdsNE h₃g] apply h₁g.continuousAt.continuousWithinAt /-! ## Elementary Properties -/ /-- If `f` is meromorphic of finite order at `x`, then the trailing coefficient is not zero. -/ lemma MeromorphicAt.meromorphicTrailingCoeffAt_ne_zero (h₁ : MeromorphicAt f x) (hβ‚‚ : meromorphicOrderAt f x β‰  ⊀) : meromorphicTrailingCoeffAt f x β‰  0 := by obtain ⟨g, h₁g, hβ‚‚g, h₃g⟩ := (meromorphicOrderAt_ne_top_iff h₁).1 hβ‚‚ simpa [h₁g.meromorphicTrailingCoeffAt_of_ne_zero_of_eq_nhdsNE hβ‚‚g h₃g] using hβ‚‚g /-- The trailing coefficient of a constant function is the constant. -/ @[simp] theorem meromorphicTrailingCoeffAt_const {x : π•œ} {e : π•œ} : meromorphicTrailingCoeffAt (fun _ ↦ e) x = e := by by_cases he : e = 0 Β· rw [he] apply MeromorphicAt.meromorphicTrailingCoeffAt_of_order_eq_top rw [meromorphicOrderAt_eq_top_iff] simp Β· exact analyticAt_const.meromorphicTrailingCoeffAt_of_ne_zero he /-- The trailing coefficient of `fun z ↦ z - constant` at `zβ‚€` equals one if `zβ‚€ = constant`, or else `zβ‚€ - constant`. -/ theorem meromorphicTrailingCoeffAt_id_sub_const [DecidableEq π•œ] {x y : π•œ} : meromorphicTrailingCoeffAt (Β· - y) x = if x = y then 1 else x - y := by by_cases h : x = y Β· simp_all only [sub_self, ite_true] apply AnalyticAt.meromorphicTrailingCoeffAt_of_ne_zero_of_eq_nhdsNE (n := 1) (by fun_prop) (by apply one_ne_zero) simp Β· simp_all only [ite_false] apply AnalyticAt.meromorphicTrailingCoeffAt_of_ne_zero (by fun_prop) simp_all [sub_ne_zero] /-! ## Congruence Lemma -/ /-- If two functions agree in a punctured neighborhood, then their trailing coefficients agree. -/ lemma meromorphicTrailingCoeffAt_congr_nhdsNE {f₁ fβ‚‚ : π•œ β†’ E} (h : f₁ =αΆ [𝓝[β‰ ] x] fβ‚‚) : meromorphicTrailingCoeffAt f₁ x = meromorphicTrailingCoeffAt fβ‚‚ x := by by_cases h₁ : Β¬MeromorphicAt f₁ x Β· simp [h₁, (MeromorphicAt.meromorphicAt_congr h).not.1 h₁] rw [not_not] at h₁ by_cases hβ‚‚ : meromorphicOrderAt f₁ x = ⊀ Β· simp_all [meromorphicOrderAt_congr h] obtain ⟨g, h₁g, hβ‚‚g, h₃g⟩ := (meromorphicOrderAt_ne_top_iff h₁).1 hβ‚‚ rw [h₁g.meromorphicTrailingCoeffAt_of_ne_zero_of_eq_nhdsNE hβ‚‚g h₃g, h₁g.meromorphicTrailingCoeffAt_of_ne_zero_of_eq_nhdsNE hβ‚‚g (h.symm.trans h₃g)] /-! ## Behavior under Arithmetic Operations -/ /-- If `f₁` and `fβ‚‚` have unequal order at `x`, then the trailing coefficient of `f₁ + fβ‚‚` at `x` is the trailing coefficient of the function with the lowest order. -/ theorem MeromorphicAt.meromorphicTrailingCoeffAt_add_eq_left_of_lt {f₁ fβ‚‚ : π•œ β†’ E} (hfβ‚‚ : MeromorphicAt fβ‚‚ x) (h : meromorphicOrderAt f₁ x < meromorphicOrderAt fβ‚‚ x) : meromorphicTrailingCoeffAt (f₁ + fβ‚‚) x = meromorphicTrailingCoeffAt f₁ x := by -- Trivial case: f₁ not meromorphic at x by_cases hf₁ : Β¬MeromorphicAt f₁ x Β· have : Β¬MeromorphicAt (f₁ + fβ‚‚) x := by rwa [add_comm, hfβ‚‚.meromorphicAt_add_iff_meromorphicAt₁] simp_all rw [not_not] at hf₁ -- Trivial case: fβ‚‚ vanishes locally around x by_cases h₁fβ‚‚ : meromorphicOrderAt fβ‚‚ x = ⊀ Β· apply meromorphicTrailingCoeffAt_congr_nhdsNE filter_upwards [meromorphicOrderAt_eq_top_iff.1 h₁fβ‚‚] simp -- General case lift meromorphicOrderAt fβ‚‚ x to β„€ using h₁fβ‚‚ with nβ‚‚ hnβ‚‚ obtain ⟨gβ‚‚, h₁gβ‚‚, hβ‚‚gβ‚‚, h₃gβ‚‚βŸ© := (meromorphicOrderAt_eq_int_iff hfβ‚‚).1 hnβ‚‚.symm lift meromorphicOrderAt f₁ x to β„€ using (by aesop) with n₁ hn₁ obtain ⟨g₁, h₁g₁, hβ‚‚g₁, h₃gβ‚βŸ© := (meromorphicOrderAt_eq_int_iff hf₁).1 hn₁.symm rw [WithTop.coe_lt_coe] at h have Ο„β‚€ : βˆ€αΆ  z in 𝓝[β‰ ] x, (f₁ + fβ‚‚) z = (z - x) ^ n₁ β€’ (g₁ + (z - x) ^ (nβ‚‚ - n₁) β€’ gβ‚‚) z := by filter_upwards [h₃g₁, h₃gβ‚‚, self_mem_nhdsWithin] with z h₁z hβ‚‚z h₃z simp only [Pi.add_apply, h₁z, hβ‚‚z, Pi.smul_apply, smul_add, ← smul_assoc, smul_eq_mul, add_right_inj] rw [← zpow_addβ‚€, add_sub_cancel] simp_all [sub_ne_zero] have τ₁ : AnalyticAt π•œ (fun z ↦ g₁ z + (z - x) ^ (nβ‚‚ - n₁) β€’ gβ‚‚ z) x := h₁g₁.fun_add (AnalyticAt.fun_smul (AnalyticAt.fun_zpow_nonneg (by fun_prop) (sub_nonneg_of_le h.le)) h₁gβ‚‚) have Ο„β‚‚ : g₁ x + (x - x) ^ (nβ‚‚ - n₁) β€’ gβ‚‚ x β‰  0 := by simp_all [zero_zpow _ (sub_ne_zero.2 (ne_of_lt h).symm)] rw [h₁g₁.meromorphicTrailingCoeffAt_of_ne_zero_of_eq_nhdsNE hβ‚‚g₁ h₃g₁, τ₁.meromorphicTrailingCoeffAt_of_ne_zero_of_eq_nhdsNE Ο„β‚‚ Ο„β‚€, sub_self, add_eq_left, smul_eq_zero, zero_zpow _ (sub_ne_zero.2 (ne_of_lt h).symm)] tauto /-- If `f₁` and `fβ‚‚` have equal order at `x` and if their trailing coefficients do not cancel, then the trailing coefficient of `f₁ + fβ‚‚` at `x` is the sum of the trailing coefficients. -/ theorem MeromorphicAt.meromorphicTrailingCoeffAt_add_eq_add {f₁ fβ‚‚ : π•œ β†’ E} (hf₁ : MeromorphicAt f₁ x) (hfβ‚‚ : MeromorphicAt fβ‚‚ x) (h₁ : meromorphicOrderAt f₁ x = meromorphicOrderAt fβ‚‚ x) (hβ‚‚ : meromorphicTrailingCoeffAt f₁ x + meromorphicTrailingCoeffAt fβ‚‚ x β‰  0) : meromorphicTrailingCoeffAt (f₁ + fβ‚‚) x = meromorphicTrailingCoeffAt f₁ x + meromorphicTrailingCoeffAt fβ‚‚ x := by -- Trivial case: f₁ vanishes locally around x by_cases h₁f₁ : meromorphicOrderAt f₁ x = ⊀ Β· rw [meromorphicTrailingCoeffAt_of_order_eq_top h₁f₁, zero_add] apply meromorphicTrailingCoeffAt_congr_nhdsNE filter_upwards [meromorphicOrderAt_eq_top_iff.1 h₁f₁] simp -- General case lift meromorphicOrderAt f₁ x to β„€ using (by aesop) with n₁ hn₁ obtain ⟨g₁, h₁g₁, hβ‚‚g₁, h₃gβ‚βŸ© := (meromorphicOrderAt_eq_int_iff hf₁).1 hn₁.symm lift meromorphicOrderAt fβ‚‚ x to β„€ using (by aesop) with nβ‚‚ hnβ‚‚ obtain ⟨gβ‚‚, h₁gβ‚‚, hβ‚‚gβ‚‚, h₃gβ‚‚βŸ© := (meromorphicOrderAt_eq_int_iff hfβ‚‚).1 hnβ‚‚.symm rw [WithTop.coe_eq_coe, h₁g₁.meromorphicTrailingCoeffAt_of_ne_zero_of_eq_nhdsNE hβ‚‚g₁ h₃g₁, h₁gβ‚‚.meromorphicTrailingCoeffAt_of_ne_zero_of_eq_nhdsNE hβ‚‚gβ‚‚ h₃gβ‚‚] at * have Ο„β‚€ : βˆ€αΆ  z in 𝓝[β‰ ] x, (f₁ + fβ‚‚) z = (z - x) ^ n₁ β€’ (g₁ + gβ‚‚) z := by filter_upwards [h₃g₁, h₃gβ‚‚, self_mem_nhdsWithin] with z h₁z hβ‚‚z h₃z simp_all simp [AnalyticAt.meromorphicTrailingCoeffAt_of_ne_zero_of_eq_nhdsNE (by fun_prop) (by simp_all) Ο„β‚€] /-- The trailing coefficient of a scalar product is the scalar product of the trailing coefficients. -/ lemma MeromorphicAt.meromorphicTrailingCoeffAt_smul {f₁ : π•œ β†’ π•œ} {fβ‚‚ : π•œ β†’ E} (hf₁ : MeromorphicAt f₁ x) (hfβ‚‚ : MeromorphicAt fβ‚‚ x) : meromorphicTrailingCoeffAt (f₁ β€’ fβ‚‚) x = (meromorphicTrailingCoeffAt f₁ x) β€’ (meromorphicTrailingCoeffAt fβ‚‚ x) := by by_cases h₁f₁ : meromorphicOrderAt f₁ x = ⊀ Β· simp_all [meromorphicOrderAt_smul hf₁ hfβ‚‚] by_cases h₁fβ‚‚ : meromorphicOrderAt fβ‚‚ x = ⊀ Β· simp_all [meromorphicOrderAt_smul hf₁ hfβ‚‚] obtain ⟨g₁, h₁g₁, hβ‚‚g₁, h₃gβ‚βŸ© := (meromorphicOrderAt_ne_top_iff hf₁).1 h₁f₁ obtain ⟨gβ‚‚, h₁gβ‚‚, hβ‚‚gβ‚‚, h₃gβ‚‚βŸ© := (meromorphicOrderAt_ne_top_iff hfβ‚‚).1 h₁fβ‚‚ have : f₁ β€’ fβ‚‚ =αΆ [𝓝[β‰ ] x] fun z ↦ (z - x) ^ (meromorphicOrderAt (f₁ β€’ fβ‚‚) x).untopβ‚€ β€’ (g₁ β€’ gβ‚‚) z := by filter_upwards [h₃g₁, h₃gβ‚‚, self_mem_nhdsWithin] with y h₁y hβ‚‚y h₃y simp_all [meromorphicOrderAt_smul hf₁ hfβ‚‚, zpow_addβ‚€ (sub_ne_zero.2 h₃y)] module rw [h₁g₁.meromorphicTrailingCoeffAt_of_ne_zero_of_eq_nhdsNE hβ‚‚g₁ h₃g₁, h₁gβ‚‚.meromorphicTrailingCoeffAt_of_ne_zero_of_eq_nhdsNE hβ‚‚gβ‚‚ h₃gβ‚‚, (h₁g₁.smul h₁gβ‚‚).meromorphicTrailingCoeffAt_of_eq_nhdsNE this] simp /-- The trailing coefficient of a product is the product of the trailing coefficients. -/ lemma MeromorphicAt.meromorphicTrailingCoeffAt_mul {f₁ fβ‚‚ : π•œ β†’ π•œ} (hf₁ : MeromorphicAt f₁ x) (hfβ‚‚ : MeromorphicAt fβ‚‚ x) : meromorphicTrailingCoeffAt (f₁ * fβ‚‚) x = (meromorphicTrailingCoeffAt f₁ x) * (meromorphicTrailingCoeffAt fβ‚‚ x) := meromorphicTrailingCoeffAt_smul hf₁ hfβ‚‚ /-- The trailing coefficient of a product is the product of the trailing coefficients. -/ theorem meromorphicTrailingCoeffAt_prod {ΞΉ : Type*} {s : Finset ΞΉ} {f : ΞΉ β†’ π•œ β†’ π•œ} {x : π•œ} (h : βˆ€ Οƒ, MeromorphicAt (f Οƒ) x) : meromorphicTrailingCoeffAt (∏ n ∈ s, f n) x = ∏ n ∈ s, meromorphicTrailingCoeffAt (f n) x := by classical induction s using Finset.induction with | empty => apply meromorphicTrailingCoeffAt_const | insert Οƒ s₁ hΟƒ hind => rw [Finset.prod_insert hΟƒ, Finset.prod_insert hΟƒ, (h Οƒ).meromorphicTrailingCoeffAt_mul (MeromorphicAt.prod h), hind] /-- The trailing coefficient of the inverse function is the inverse of the trailing coefficient. -/ lemma meromorphicTrailingCoeffAt_inv {f : π•œ β†’ π•œ} : meromorphicTrailingCoeffAt f⁻¹ x = (meromorphicTrailingCoeffAt f x)⁻¹ := by by_cases h₁ : MeromorphicAt f x Β· by_cases hβ‚‚ : meromorphicOrderAt f x = ⊀ Β· simp_all [meromorphicOrderAt_inv (f := f) (x := x)] have : f⁻¹ * f =αΆ [𝓝[β‰ ] x] 1 := by filter_upwards [(meromorphicOrderAt_ne_top_iff_eventually_ne_zero h₁).1 hβ‚‚] simp_all rw [← mul_eq_one_iff_eq_invβ‚€ (h₁.meromorphicTrailingCoeffAt_ne_zero hβ‚‚), ← h₁.inv.meromorphicTrailingCoeffAt_mul h₁, meromorphicTrailingCoeffAt_congr_nhdsNE this, analyticAt_const.meromorphicTrailingCoeffAt_of_ne_zero_of_eq_nhdsNE (n := 0)] Β· simp Β· simp only [zpow_zero, smul_eq_mul, mul_one] exact eventuallyEq_nhdsWithin_of_eqOn fun _ ↦ congrFun rfl Β· simp_all /-- The trailing coefficient of the power of a function is the power of the trailing coefficient. -/ lemma MeromorphicAt.meromorphicTrailingCoeffAt_zpow {n : β„€} {f : π•œ β†’ π•œ} (h₁ : MeromorphicAt f x) : meromorphicTrailingCoeffAt (f ^ n) x = (meromorphicTrailingCoeffAt f x) ^ n := by by_cases hβ‚‚ : meromorphicOrderAt f x = ⊀ Β· by_cases h₃ : n = 0 Β· simp only [h₃, zpow_zero] apply analyticAt_const.meromorphicTrailingCoeffAt_of_ne_zero (ne_zero_of_eq_one rfl) Β· simp_all [meromorphicOrderAt_zpow h₁, zero_zpow n h₃] Β· obtain ⟨g, h₁g, hβ‚‚g, h₃g⟩ := (meromorphicOrderAt_ne_top_iff h₁).1 hβ‚‚ rw [h₁g.meromorphicTrailingCoeffAt_of_ne_zero_of_eq_nhdsNE (n := (meromorphicOrderAt f x).untopβ‚€) hβ‚‚g h₃g, (h₁g.zpow hβ‚‚g (n := n)).meromorphicTrailingCoeffAt_of_ne_zero_of_eq_nhdsNE (n := (meromorphicOrderAt (f ^ n) x).untopβ‚€) (by simp_all [zpow_ne_zero])] Β· simp only [Pi.pow_apply] Β· filter_upwards [h₃g] with a ha simp_all [mul_zpow, ← zpow_mul, meromorphicOrderAt_zpow h₁, mul_comm] /-- The trailing coefficient of the power of a function is the power of the trailing coefficient. -/ lemma MeromorphicAt.meromorphicTrailingCoeffAt_pow {n : β„•} {f : π•œ β†’ π•œ} (h₁ : MeromorphicAt f x) : meromorphicTrailingCoeffAt (f ^ n) x = (meromorphicTrailingCoeffAt f x) ^ n := by convert h₁.meromorphicTrailingCoeffAt_zpow (n := n) <;> simp
.lake/packages/mathlib/Mathlib/Analysis/Meromorphic/Divisor.lean
import Mathlib.Algebra.Order.WithTop.Untop0 import Mathlib.Analysis.Meromorphic.Order import Mathlib.Topology.LocallyFinsupp /-! # The Divisor of a meromorphic function This file defines the divisor of a meromorphic function and proves the most basic lemmas about those divisors. The lemma `MeromorphicOn.divisor_restrict` guarantees compatibility between restrictions of divisors and of meromorphic functions to subsets of their domain of definition. -/ variable {π•œ : Type*} [NontriviallyNormedField π•œ] {U : Set π•œ} {z : π•œ} {E : Type*} [NormedAddCommGroup E] [NormedSpace π•œ E] open Filter Topology namespace MeromorphicOn /-! ## Definition of the Divisor -/ open Classical in /-- The divisor of a meromorphic function `f`, mapping a point `z` to the order of `f` at `z`, and to zero if the order is infinite. -/ noncomputable def divisor (f : π•œ β†’ E) (U : Set π•œ) : Function.locallyFinsuppWithin U β„€ where toFun := fun z ↦ if MeromorphicOn f U ∧ z ∈ U then (meromorphicOrderAt f z).untopβ‚€ else 0 supportWithinDomain' z hz := by by_contra hβ‚‚z simp [hβ‚‚z] at hz supportLocallyFiniteWithinDomain' := by simp_all only [Function.support_subset_iff, ne_eq, ite_eq_right_iff, WithTop.untopβ‚€_eq_zero, and_imp, Classical.not_imp, not_or, implies_true, ← supportDiscreteWithin_iff_locallyFiniteWithin] by_cases hf : MeromorphicOn f U Β· filter_upwards [mem_codiscrete_subtype_iff_mem_codiscreteWithin.1 hf.codiscrete_setOf_meromorphicOrderAt_eq_zero_or_top] simp only [Set.mem_image, Set.mem_setOf_eq, Subtype.exists, exists_and_left, exists_prop, exists_eq_right_right, Pi.ofNat_apply, ite_eq_right_iff, WithTop.untopβ‚€_eq_zero, and_imp] tauto Β· simp [hf, Pi.zero_def] open Classical in /-- Definition of the divisor -/ theorem divisor_def (f : π•œ β†’ E) (U : Set π•œ) : divisor f U z = if MeromorphicOn f U ∧ z ∈ U then (meromorphicOrderAt f z).untopβ‚€ else 0 := rfl /-- Simplifier lemma: on `U`, the divisor of a function `f` that is meromorphic on `U` evaluates to `order.untopβ‚€`. -/ @[simp] lemma divisor_apply {f : π•œ β†’ E} (hf : MeromorphicOn f U) (hz : z ∈ U) : divisor f U z = (meromorphicOrderAt f z).untopβ‚€ := by simp_all [MeromorphicOn.divisor_def] /-! ## Congruence Lemmas -/ /-- If `f₁` is meromorphic on `U`, if `fβ‚‚` agrees with `f₁` on a codiscrete subset of `U` and outside of `U`, then `f₁` and `fβ‚‚` induce the same divisors on `U`. -/ theorem divisor_congr_codiscreteWithin_of_eqOn_compl {f₁ fβ‚‚ : π•œ β†’ E} (hf₁ : MeromorphicOn f₁ U) (h₁ : f₁ =αΆ [Filter.codiscreteWithin U] fβ‚‚) (hβ‚‚ : Set.EqOn f₁ fβ‚‚ Uᢜ) : divisor f₁ U = divisor fβ‚‚ U := by ext x by_cases hx : x ∈ U Β· simp only [hf₁, hx, divisor_apply, hf₁.congr_codiscreteWithin_of_eqOn_compl h₁ hβ‚‚] congr 1 apply meromorphicOrderAt_congr simp_rw [EventuallyEq, Filter.Eventually, mem_codiscreteWithin, disjoint_principal_right] at h₁ filter_upwards [h₁ x hx] with a ha simp at ha tauto Β· simp [hx] /-- If `f₁` is meromorphic on an open set `U`, if `fβ‚‚` agrees with `f₁` on a codiscrete subset of `U`, then `f₁` and `fβ‚‚` induce the same divisors on`U`. -/ theorem divisor_congr_codiscreteWithin {f₁ fβ‚‚ : π•œ β†’ E} (hf₁ : MeromorphicOn f₁ U) (h₁ : f₁ =αΆ [Filter.codiscreteWithin U] fβ‚‚) (hβ‚‚ : IsOpen U) : divisor f₁ U = divisor fβ‚‚ U := by ext x by_cases hx : x ∈ U Β· simp only [hf₁, hx, divisor_apply, hf₁.congr_codiscreteWithin h₁ hβ‚‚] congr 1 apply meromorphicOrderAt_congr simp_rw [EventuallyEq, Filter.Eventually, mem_codiscreteWithin, disjoint_principal_right] at h₁ have : U ∈ 𝓝[β‰ ] x := by apply mem_nhdsWithin.mpr use U, hβ‚‚, hx, Set.inter_subset_left filter_upwards [this, h₁ x hx] with a h₁a hβ‚‚a simp only [Set.mem_compl_iff, Set.mem_diff, Set.mem_setOf_eq, not_and] at hβ‚‚a tauto Β· simp [hx] /-! ## Divisors of Analytic Functions -/ /-- Analytic functions have non-negative divisors. -/ theorem AnalyticOnNhd.divisor_nonneg {f : π•œ β†’ E} (hf : AnalyticOnNhd π•œ f U) : 0 ≀ MeromorphicOn.divisor f U := by intro x by_cases hx : x ∈ U Β· simp [hf.meromorphicOn, hx, (hf x hx).meromorphicOrderAt_nonneg] simp [hx] /-- The divisor of a constant function is `0`. -/ @[simp] theorem divisor_const (e : E) : divisor (fun _ ↦ e) U = 0 := by classical ext x simp only [divisor_def, meromorphicOrderAt_const, Function.locallyFinsuppWithin.coe_zero, Pi.zero_apply, ite_eq_right_iff, WithTop.untopβ‚€_eq_zero, LinearOrderedAddCommGroupWithTop.top_ne_zero, imp_false, ite_eq_left_iff, WithTop.zero_ne_top, Decidable.not_not, and_imp] tauto /-- The divisor of a constant function is `0`. -/ @[simp] theorem divisor_intCast (n : β„€) : divisor (n : π•œ β†’ π•œ) U = 0 := divisor_const (n : π•œ) /-- The divisor of a constant function is `0`. -/ @[simp] theorem divisor_natCast (n : β„•) : divisor (n : π•œ β†’ π•œ) U = 0 := divisor_const (n : π•œ) /-- The divisor of a constant function is `0`. -/ @[simp] theorem divisor_ofNat (n : β„•) : divisor (ofNat(n) : π•œ β†’ π•œ) U = 0 := by convert divisor_const (n : π•œ) simp [Semiring.toGrindSemiring_ofNat π•œ n] /-! ## Behavior under Standard Operations -/ /-- If orders are finite, the divisor of the scalar product of two meromorphic functions is the sum of the divisors. See `MeromorphicOn.exists_order_ne_top_iff_forall` and `MeromorphicOn.order_ne_top_of_isPreconnected` for two convenient criteria to guarantee conditions `hβ‚‚f₁` and `hβ‚‚fβ‚‚`. -/ theorem divisor_smul {f₁ : π•œ β†’ π•œ} {fβ‚‚ : π•œ β†’ E} (h₁f₁ : MeromorphicOn f₁ U) (h₁fβ‚‚ : MeromorphicOn fβ‚‚ U) (hβ‚‚f₁ : βˆ€ z ∈ U, meromorphicOrderAt f₁ z β‰  ⊀) (hβ‚‚fβ‚‚ : βˆ€ z ∈ U, meromorphicOrderAt fβ‚‚ z β‰  ⊀) : divisor (f₁ β€’ fβ‚‚) U = divisor f₁ U + divisor fβ‚‚ U := by ext z by_cases hz : z ∈ U Β· lift meromorphicOrderAt f₁ z to β„€ using (hβ‚‚f₁ z hz) with a₁ ha₁ lift meromorphicOrderAt fβ‚‚ z to β„€ using (hβ‚‚fβ‚‚ z hz) with aβ‚‚ haβ‚‚ simp [h₁f₁, h₁fβ‚‚, h₁f₁.smul h₁fβ‚‚, hz, meromorphicOrderAt_smul (h₁f₁ z hz) (h₁fβ‚‚ z hz), ← ha₁, ← haβ‚‚, ← WithTop.coe_add] Β· simp [hz] /-- If orders are finite, the divisor of the scalar product of two meromorphic functions is the sum of the divisors. -/ theorem divisor_fun_smul {f₁ : π•œ β†’ π•œ} {fβ‚‚ : π•œ β†’ E} (h₁f₁ : MeromorphicOn f₁ U) (h₁fβ‚‚ : MeromorphicOn fβ‚‚ U) (hβ‚‚f₁ : βˆ€ z ∈ U, meromorphicOrderAt f₁ z β‰  ⊀) (hβ‚‚fβ‚‚ : βˆ€ z ∈ U, meromorphicOrderAt fβ‚‚ z β‰  ⊀) : divisor (fun z ↦ f₁ z β€’ fβ‚‚ z) U = divisor f₁ U + divisor fβ‚‚ U := divisor_smul h₁f₁ h₁fβ‚‚ hβ‚‚f₁ hβ‚‚fβ‚‚ /-- If orders are finite, the divisor of the product of two meromorphic functions is the sum of the divisors. See `MeromorphicOn.exists_order_ne_top_iff_forall` and `MeromorphicOn.order_ne_top_of_isPreconnected` for two convenient criteria to guarantee conditions `hβ‚‚f₁` and `hβ‚‚fβ‚‚`. -/ theorem divisor_mul {f₁ fβ‚‚ : π•œ β†’ π•œ} (h₁f₁ : MeromorphicOn f₁ U) (h₁fβ‚‚ : MeromorphicOn fβ‚‚ U) (hβ‚‚f₁ : βˆ€ z ∈ U, meromorphicOrderAt f₁ z β‰  ⊀) (hβ‚‚fβ‚‚ : βˆ€ z ∈ U, meromorphicOrderAt fβ‚‚ z β‰  ⊀) : divisor (f₁ * fβ‚‚) U = divisor f₁ U + divisor fβ‚‚ U := divisor_smul h₁f₁ h₁fβ‚‚ hβ‚‚f₁ hβ‚‚fβ‚‚ /-- If orders are finite, the divisor of the product of two meromorphic functions is the sum of the divisors. -/ theorem divisor_fun_mul {f₁ fβ‚‚ : π•œ β†’ π•œ} (h₁f₁ : MeromorphicOn f₁ U) (h₁fβ‚‚ : MeromorphicOn fβ‚‚ U) (hβ‚‚f₁ : βˆ€ z ∈ U, meromorphicOrderAt f₁ z β‰  ⊀) (hβ‚‚fβ‚‚ : βˆ€ z ∈ U, meromorphicOrderAt fβ‚‚ z β‰  ⊀) : divisor (fun z ↦ f₁ z * fβ‚‚ z) U = divisor f₁ U + divisor fβ‚‚ U := divisor_smul h₁f₁ h₁fβ‚‚ hβ‚‚f₁ hβ‚‚fβ‚‚ /-- The divisor of the inverse is the negative of the divisor. -/ @[simp] theorem divisor_inv {f : π•œ β†’ π•œ} : divisor f⁻¹ U = -divisor f U := by ext z by_cases h : MeromorphicOn f U ∧ z ∈ U Β· simp [divisor_apply, h, meromorphicOrderAt_inv] Β· simp [divisor_def, h] /-- The divisor of the inverse is the negative of the divisor. -/ @[simp] theorem divisor_fun_inv {f : π•œ β†’ π•œ} : divisor (fun z ↦ (f z)⁻¹) U = -divisor f U := divisor_inv /-- If `f` is meromorphic, then the divisor of `f ^ n` is `n` times the divisor of `f`. -/ theorem divisor_pow {f : π•œ β†’ π•œ} (hf : MeromorphicOn f U) (n : β„•) : divisor (f ^ n) U = n β€’ divisor f U := by classical ext z by_cases hn : n = 0 Β· simp [hn] by_cases hz : z ∈ U Β· simp [hf.pow, divisor_apply, meromorphicOrderAt_pow (hf z hz), hf, hz] Β· simp [hz] /-- If `f` is meromorphic, then the divisor of `f ^ n` is `n` times the divisor of `f`. -/ theorem divisor_fun_pow {f : π•œ β†’ π•œ} (hf : MeromorphicOn f U) (n : β„•) : divisor (fun z ↦ f z ^ n) U = n β€’ divisor f U := divisor_pow hf n /-- If `f` is meromorphic, then the divisor of `f ^ n` is `n` times the divisor of `f`. -/ theorem divisor_zpow {f : π•œ β†’ π•œ} (hf : MeromorphicOn f U) (n : β„€) : divisor (f ^ n) U = n β€’ divisor f U := by classical ext z by_cases hn : n = 0 Β· simp [hn] by_cases hz : z ∈ U Β· simp [hf.zpow, divisor_apply, meromorphicOrderAt_zpow (hf z hz), hf, hz] Β· simp [hz] /-- If `f` is meromorphic, then the divisor of `f ^ n` is `n` times the divisor of `f`. -/ theorem divisor_fun_zpow {f : π•œ β†’ π•œ} (hf : MeromorphicOn f U) (n : β„€) : divisor (fun z ↦ f z ^ n) U = n β€’ divisor f U := divisor_zpow hf n /-- Taking the divisor of a meromorphic function commutes with restriction. -/ @[simp] theorem divisor_restrict {f : π•œ β†’ E} {V : Set π•œ} (hf : MeromorphicOn f U) (hV : V βŠ† U) : (divisor f U).restrict hV = divisor f V := by ext x by_cases hx : x ∈ V Β· rw [Function.locallyFinsuppWithin.restrict_apply] simp [hf, hx, hf.mono_set hV, hV hx] Β· simp [hx] /-- Adding an analytic function to a meromorphic one does not change the pole divisor. -/ theorem negPart_divisor_add_of_analyticNhdOn_right {f₁ fβ‚‚ : π•œ β†’ E} (hf₁ : MeromorphicOn f₁ U) (hfβ‚‚ : AnalyticOnNhd π•œ fβ‚‚ U) : (divisor (f₁ + fβ‚‚) U)⁻ = (divisor f₁ U)⁻ := by ext x by_cases hx : x ∈ U Β· suffices -(meromorphicOrderAt (f₁ + fβ‚‚) x).untopβ‚€ βŠ” 0 = -(meromorphicOrderAt f₁ x).untopβ‚€ βŠ” 0 by simpa [negPart_def, hx, hf₁, hf₁.add hfβ‚‚.meromorphicOn] by_cases h : 0 ≀ meromorphicOrderAt f₁ x Β· suffices 0 ≀ meromorphicOrderAt (f₁ + fβ‚‚) x by simp_all calc 0 _ ≀ min (meromorphicOrderAt f₁ x) (meromorphicOrderAt fβ‚‚ x) := le_inf h (hfβ‚‚ x hx).meromorphicOrderAt_nonneg _ ≀ meromorphicOrderAt (f₁ + fβ‚‚) x := meromorphicOrderAt_add (hf₁ x hx) (hfβ‚‚ x hx).meromorphicAt Β· suffices meromorphicOrderAt f₁ x < meromorphicOrderAt fβ‚‚ x by rwa [meromorphicOrderAt_add_eq_left_of_lt (hfβ‚‚.meromorphicOn x hx)] calc meromorphicOrderAt f₁ x _ < 0 := by simpa using h _ ≀ meromorphicOrderAt fβ‚‚ x := (hfβ‚‚ x hx).meromorphicOrderAt_nonneg simp [hx] /-- Adding an analytic function to a meromorphic one does not change the pole divisor. -/ theorem negPart_divisor_add_of_analyticNhdOn_left {f₁ fβ‚‚ : π•œ β†’ E} (hf₁ : AnalyticOnNhd π•œ f₁ U) (hfβ‚‚ : MeromorphicOn fβ‚‚ U) : (divisor (f₁ + fβ‚‚) U)⁻ = (divisor fβ‚‚ U)⁻ := by rw [add_comm] exact negPart_divisor_add_of_analyticNhdOn_right hfβ‚‚ hf₁ end MeromorphicOn
.lake/packages/mathlib/Mathlib/Analysis/Meromorphic/Complex.lean
import Mathlib.Analysis.Meromorphic.NormalForm import Mathlib.Analysis.SpecialFunctions.Gamma.Beta /-! # The Gamma function is meromorphic -/ open Set Complex lemma MeromorphicNFOn.Gamma : MeromorphicNFOn Gamma univ := meromorphicNFOn_inv.mp <| AnalyticOnNhd.meromorphicNFOn <| analyticOnNhd_univ_iff_differentiable.mpr differentiable_one_div_Gamma lemma MeromorphicOn.Gamma : MeromorphicOn Gamma univ := MeromorphicNFOn.Gamma.meromorphicOn
.lake/packages/mathlib/Mathlib/Analysis/Meromorphic/IsolatedZeros.lean
import Mathlib.Analysis.Meromorphic.Basic /-! # Principles of Isolated Zeros and Identity Principles for Meromorphic Functions In line with results in `Mathlib.Analysis.Analytic.IsolatedZeros` and `Mathlib.Analysis.Analytic.Uniqueness`, this file establishes principles of isolated zeros and identity principles for meromorphic functions. Compared to the results for analytic functions, the principles established here are a little more complicated to state. This is because meromorphic functions can be modified at will along discrete subsets and still remain meromorphic. -/ variable {π•œ : Type*} [NontriviallyNormedField π•œ] {E : Type*} [NormedAddCommGroup E] [NormedSpace π•œ E] {U : Set π•œ} {x : π•œ} {f g : π•œ β†’ E} open Filter Topology namespace MeromorphicAt /-! ## Principles of Isolated Zeros -/ /-- The principle of isolated zeros: If `f` is meromorphic at `x`, then `f` vanishes eventually in a punctured neighborhood of `x` iff it vanishes frequently in punctured neighborhoods. See `AnalyticAt.frequently_zero_iff_eventually_zero` for a stronger result in the analytic case. -/ theorem frequently_zero_iff_eventuallyEq_zero (hf : MeromorphicAt f x) : (βˆƒαΆ  z in 𝓝[β‰ ] x, f z = 0) ↔ f =αΆ [𝓝[β‰ ] x] 0 := ⟨hf.eventually_eq_zero_or_eventually_ne_zero.resolve_right, fun h ↦ h.frequently⟩ /-- Variant of the principle of isolated zeros: Let `U` be a subset of `π•œ` and assume that `x ∈ U` is not an isolated point of `U`. If a function `f` is meromorphic at `x` and vanishes along a subset that is codiscrete within `U`, then `f` vanishes in a punctured neighbourhood of `f`. For a typical application, let `U` be a path in the complex plane and let `x` be one of the end points. If `f` is meromorphic at `x` and vanishes on `U`, then it will vanish in a punctured neighbourhood of `x`, which intersects `U` non-trivially but is not contained in `U`. The assumption that `x` is not an isolated point of `U` is expressed as `AccPt x (π“Ÿ U)`. See `accPt_iff_frequently` and `accPt_iff_frequently_nhdsNE` for useful reformulations. -/ theorem eventuallyEq_zero_nhdsNE_of_eventuallyEq_zero_codiscreteWithin (hf : MeromorphicAt f x) (h₁x : x ∈ U) (hβ‚‚x : AccPt x (π“Ÿ U)) (h : f =αΆ [codiscreteWithin U] 0) : f =αΆ [𝓝[β‰ ] x] 0 := by rw [← hf.frequently_zero_iff_eventuallyEq_zero] apply ((accPt_iff_frequently_nhdsNE.1 hβ‚‚x).and_eventually (mem_codiscreteWithin_iff_forall_mem_nhdsNE.1 h x h₁x)).mp filter_upwards intro a simp_rw [Pi.zero_apply] rw [(by rfl : ({x | f x = 0} βˆͺ Uᢜ) a ↔ a ∈ {x | f x = 0} βˆͺ Uᢜ)] simp_all /-! ## Identity Principles -/ /-- Formulation of `MeromorphicAt.frequently_zero_iff_eventuallyEq_zero` as an identity principle: If `f` and `g` are meromorphic at `x`, then `f` and `g` agree eventually in a punctured neighborhood of `x` iff they agree at points arbitrarily close to (but different from) `x`. -/ theorem frequently_eq_iff_eventuallyEq (hf : MeromorphicAt f x) (hg : MeromorphicAt g x) : (βˆƒαΆ  z in 𝓝[β‰ ] x, f z = g z) ↔ f =αΆ [𝓝[β‰ ] x] g := by rw [eventuallyEq_iff_sub, ← (hf.sub hg).frequently_zero_iff_eventuallyEq_zero] simp_rw [Pi.sub_apply, sub_eq_zero] /-- Formulation of `MeromorphicAt.eventuallyEq_zero_nhdsNE_of_eventuallyEq_zero_codiscreteWithin` as an identity principle: Let `U` be a subset of `π•œ` and assume that `x ∈ U` is not an isolated point of `U`. If function `f` and `g` are meromorphic at `x` and agree along a subset that is codiscrete within `U`, then `f` and `g` agree in a punctured neighbourhood of `f`. -/ theorem eventuallyEq_nhdsNE_of_eventuallyEq_codiscreteWithin (hf : MeromorphicAt f x) (hg : MeromorphicAt g x) (h₁x : x ∈ U) (hβ‚‚x : AccPt x (π“Ÿ U)) (h : f =αΆ [codiscreteWithin U] g) : f =αΆ [𝓝[β‰ ] x] g := by rw [eventuallyEq_iff_sub] at * apply (hf.sub hg).eventuallyEq_zero_nhdsNE_of_eventuallyEq_zero_codiscreteWithin h₁x hβ‚‚x h end MeromorphicAt
.lake/packages/mathlib/Mathlib/Analysis/NormedSpace/RCLike.lean
import Mathlib.Analysis.Normed.Module.RCLike.Basic deprecated_module (since := "2025-09-02")
.lake/packages/mathlib/Mathlib/Analysis/NormedSpace/RieszLemma.lean
import Mathlib.Analysis.Normed.Module.RCLike.Real import Mathlib.Analysis.Seminorm import Mathlib.Topology.MetricSpace.HausdorffDistance /-! # Applications of the Hausdorff distance in normed spaces Riesz's lemma, stated for a normed space over a normed field: for any closed proper subspace `F` of `E`, there is a nonzero `x` such that `β€–x - Fβ€–` is at least `r * β€–xβ€–` for any `r < 1`. This is `riesz_lemma`. In a nontrivially normed field (with an element `c` of norm `> 1`) and any `R > β€–cβ€–`, one can guarantee `β€–xβ€– ≀ R` and `β€–x - yβ€– β‰₯ 1` for any `y` in `F`. This is `riesz_lemma_of_norm_lt`. A further lemma, `Metric.closedBall_infDist_compl_subset_closure`, finds a *closed* ball within the closure of a set `s` of optimal distance from a point in `x` to the frontier of `s`. -/ open Set Metric open Topology variable {π•œ : Type*} [NormedField π•œ] variable {E : Type*} [NormedAddCommGroup E] [NormedSpace π•œ E] variable {F : Type*} [SeminormedAddCommGroup F] [NormedSpace ℝ F] /-- Riesz's lemma, which usually states that it is possible to find a vector with norm 1 whose distance to a closed proper subspace is arbitrarily close to 1. The statement here is in terms of multiples of norms, since in general the existence of an element of norm exactly 1 is not guaranteed. For a variant giving an element with norm in `[1, R]`, see `riesz_lemma_of_norm_lt`. -/ theorem riesz_lemma {F : Subspace π•œ E} (hFc : IsClosed (F : Set E)) (hF : βˆƒ x : E, x βˆ‰ F) {r : ℝ} (hr : r < 1) : βˆƒ xβ‚€ : E, xβ‚€ βˆ‰ F ∧ βˆ€ y ∈ F, r * β€–xβ‚€β€– ≀ β€–xβ‚€ - yβ€– := by classical obtain ⟨x, hx⟩ : βˆƒ x : E, x βˆ‰ F := hF let d := Metric.infDist x F have hFn : (F : Set E).Nonempty := ⟨_, F.zero_mem⟩ have hdp : 0 < d := lt_of_le_of_ne Metric.infDist_nonneg fun heq => hx ((hFc.mem_iff_infDist_zero hFn).2 heq.symm) let r' := max r 2⁻¹ have hr' : r' < 1 := by simp only [r', max_lt_iff, hr, true_and] norm_num have hlt : 0 < r' := lt_of_lt_of_le (by simp) (le_max_right r 2⁻¹) have hdlt : d < d / r' := (lt_div_iffβ‚€ hlt).mpr ((mul_lt_iff_lt_one_right hdp).2 hr') obtain ⟨yβ‚€, hyβ‚€F, hxyβ‚€βŸ© : βˆƒ y ∈ F, dist x y < d / r' := (Metric.infDist_lt_iff hFn).mp hdlt have x_ne_yβ‚€ : x - yβ‚€ βˆ‰ F := by by_contra h have : x - yβ‚€ + yβ‚€ ∈ F := F.add_mem h hyβ‚€F simp only [neg_add_cancel_right, sub_eq_add_neg] at this exact hx this refine ⟨x - yβ‚€, x_ne_yβ‚€, fun y hy => le_of_lt ?_⟩ have hyβ‚€y : yβ‚€ + y ∈ F := F.add_mem hyβ‚€F hy calc r * β€–x - yβ‚€β€– ≀ r' * β€–x - yβ‚€β€– := by gcongr; apply le_max_left _ < d := by rw [← dist_eq_norm] exact (lt_div_iffβ‚€' hlt).1 hxyβ‚€ _ ≀ dist x (yβ‚€ + y) := Metric.infDist_le_dist_of_mem hyβ‚€y _ = β€–x - yβ‚€ - yβ€– := by rw [sub_sub, dist_eq_norm] /-- A version of Riesz lemma: given a strict closed subspace `F`, one may find an element of norm `≀ R` which is at distance at least `1` of every element of `F`. Here, `R` is any given constant strictly larger than the norm of an element of norm `> 1`. For a version without an `R`, see `riesz_lemma`. Since we are considering a general nontrivially normed field, there may be a gap in possible norms (for instance no element of norm in `(1,2)`). Hence, we cannot allow `R` arbitrarily close to `1`, and require `R > β€–cβ€–` for some `c : π•œ` with norm `> 1`. -/ theorem riesz_lemma_of_norm_lt {c : π•œ} (hc : 1 < β€–cβ€–) {R : ℝ} (hR : β€–cβ€– < R) {F : Subspace π•œ E} (hFc : IsClosed (F : Set E)) (hF : βˆƒ x : E, x βˆ‰ F) : βˆƒ xβ‚€ : E, β€–xβ‚€β€– ≀ R ∧ βˆ€ y ∈ F, 1 ≀ β€–xβ‚€ - yβ€– := by have Rpos : 0 < R := (norm_nonneg _).trans_lt hR have : β€–cβ€– / R < 1 := by rw [div_lt_iffβ‚€ Rpos] simpa using hR rcases riesz_lemma hFc hF this with ⟨x, xF, hx⟩ have x0 : x β‰  0 := fun H => by simp [H] at xF obtain ⟨d, d0, dxlt, ledx, -⟩ : βˆƒ d : π•œ, d β‰  0 ∧ β€–d β€’ xβ€– < R ∧ R / β€–cβ€– ≀ β€–d β€’ xβ€– ∧ β€–d‖⁻¹ ≀ R⁻¹ * β€–cβ€– * β€–xβ€– := rescale_to_shell hc Rpos x0 refine ⟨d β€’ x, dxlt.le, fun y hy => ?_⟩ set y' := d⁻¹ β€’ y have yy' : y = d β€’ y' := by simp [y', smul_smul, mul_inv_cancelβ‚€ d0] calc 1 = β€–cβ€– / R * (R / β€–cβ€–) := by field _ ≀ β€–cβ€– / R * β€–d β€’ xβ€– := by gcongr _ = β€–dβ€– * (β€–cβ€– / R * β€–xβ€–) := by simp only [norm_smul] ring _ ≀ β€–dβ€– * β€–x - y'β€– := by gcongr; exact hx y' (by simp [y', Submodule.smul_mem _ _ hy]) _ = β€–d β€’ x - yβ€– := by rw [yy', ← smul_sub, norm_smul] theorem Metric.closedBall_infDist_compl_subset_closure {x : F} {s : Set F} (hx : x ∈ s) : closedBall x (infDist x sᢜ) βŠ† closure s := by rcases eq_or_ne (infDist x sᢜ) 0 with hβ‚€ | hβ‚€ Β· rw [hβ‚€, closedBall_zero'] exact closure_mono (singleton_subset_iff.2 hx) Β· rw [← closure_ball x hβ‚€] exact closure_mono ball_infDist_compl_subset
.lake/packages/mathlib/Mathlib/Analysis/NormedSpace/Int.lean
import Mathlib.Analysis.Normed.Ring.Int deprecated_module (since := "2025-09-02")
.lake/packages/mathlib/Mathlib/Analysis/NormedSpace/Pointwise.lean
import Mathlib.Analysis.Normed.Module.Ball.Pointwise deprecated_module (since := "2025-09-02")
.lake/packages/mathlib/Mathlib/Analysis/NormedSpace/ENormedSpace.lean
import Mathlib.Analysis.Normed.Module.Basic import Mathlib.LinearAlgebra.Basis.VectorSpace /-! # Extended norm **ATTENTION.** This file is deprecated. Mathlib now has classes `ENormed(Add)(Comm)Monoid` for (additive) (commutative) monoids with an `ENorm`: this is very similar to this definition, but much more general. Should the need arise, an enormed version of a normed space can be added later: this will be different from this file. In this file we define a structure `ENormedSpace π•œ V` representing an extended norm (i.e., a norm that can take the value `∞`) on a vector space `V` over a normed field `π•œ`. We do not use `class` for an `ENormedSpace` because the same space can have more than one extended norm. For example, the space of measurable functions `f : Ξ± β†’ ℝ` has a family of `L_p` extended norms. We prove some basic inequalities, then define * `EMetricSpace` structure on `V` corresponding to `e : ENormedSpace π•œ V`; * the subspace of vectors with finite norm, called `e.finiteSubspace`; * a `NormedSpace` structure on this space. The last definition is an instance because the type involves `e`. ## Implementation notes We do not define extended normed groups. They can be added to the chain once someone will need them. ## Tags normed space, extended norm -/ noncomputable section open ENNReal /-- Extended norm on a vector space. As in the case of normed spaces, we require only `β€–c β€’ xβ€– ≀ β€–cβ€– * β€–xβ€–` in the definition, then prove an equality in `map_smul`. -/ @[deprecated "Use ENormedAddCommMonoid or talk to the Carleson project" (since := "2025-05-07")] structure ENormedSpace (π•œ : Type*) (V : Type*) [NormedField π•œ] [AddCommGroup V] [Module π•œ V] where /-- the norm of an ENormedSpace, taking values into `ℝβ‰₯0∞` -/ toFun : V β†’ ℝβ‰₯0∞ eq_zero' : βˆ€ x, toFun x = 0 β†’ x = 0 map_add_le' : βˆ€ x y : V, toFun (x + y) ≀ toFun x + toFun y map_smul_le' : βˆ€ (c : π•œ) (x : V), toFun (c β€’ x) ≀ β€–cβ€–β‚Š * toFun x set_option linter.deprecated false namespace ENormedSpace variable {π•œ : Type*} {V : Type*} [NormedField π•œ] [AddCommGroup V] [Module π•œ V] (e : ENormedSpace π•œ V) attribute [coe] ENormedSpace.toFun instance : CoeFun (ENormedSpace π•œ V) fun _ => V β†’ ℝβ‰₯0∞ := ⟨ENormedSpace.toFun⟩ @[deprecated "Use ENormedAddCommMonoid or talk to the Carleson project" (since := "2025-05-07")] theorem coeFn_injective : Function.Injective ((↑) : ENormedSpace π•œ V β†’ V β†’ ℝβ‰₯0∞) := by intro e₁ eβ‚‚ h cases e₁ cases eβ‚‚ congr @[deprecated "Use ENormedAddCommMonoid or talk to the Carleson project" (since := "2025-05-07"), ext] theorem ext {e₁ eβ‚‚ : ENormedSpace π•œ V} (h : βˆ€ x, e₁ x = eβ‚‚ x) : e₁ = eβ‚‚ := coeFn_injective <| funext h @[deprecated "Use ENormedAddCommMonoid or talk to the Carleson project" (since := "2025-05-07"), simp, norm_cast] theorem coe_inj {e₁ eβ‚‚ : ENormedSpace π•œ V} : (e₁ : V β†’ ℝβ‰₯0∞) = eβ‚‚ ↔ e₁ = eβ‚‚ := coeFn_injective.eq_iff @[deprecated "Use ENormedAddCommMonoid or talk to the Carleson project" (since := "2025-05-07"), simp] theorem map_smul (c : π•œ) (x : V) : e (c β€’ x) = β€–cβ€–β‚Š * e x := by apply le_antisymm (e.map_smul_le' c x) by_cases hc : c = 0 Β· simp [hc] calc (β€–cβ€–β‚Š : ℝβ‰₯0∞) * e x = β€–cβ€–β‚Š * e (c⁻¹ β€’ c β€’ x) := by rw [inv_smul_smulβ‚€ hc] _ ≀ β€–cβ€–β‚Š * (β€–cβ»ΒΉβ€–β‚Š * e (c β€’ x)) := by grw [e.map_smul_le'] _ = e (c β€’ x) := by rw [← mul_assoc, nnnorm_inv, ENNReal.coe_inv, ENNReal.mul_inv_cancel _ ENNReal.coe_ne_top, one_mul] <;> simp [hc] @[deprecated "Use ENormedAddCommMonoid or talk to the Carleson project" (since := "2025-05-07"), simp] theorem map_zero : e 0 = 0 := by rw [← zero_smul π•œ (0 : V), e.map_smul] simp @[deprecated "Use ENormedAddCommMonoid or talk to the Carleson project" (since := "2025-05-07"), simp] theorem eq_zero_iff {x : V} : e x = 0 ↔ x = 0 := ⟨e.eq_zero' x, fun h => h.symm β–Έ e.map_zero⟩ @[deprecated "Use ENormedAddCommMonoid or talk to the Carleson project" (since := "2025-05-07"), simp] theorem map_neg (x : V) : e (-x) = e x := calc e (-x) = β€–(-1 : π•œ)β€–β‚Š * e x := by rw [← map_smul, neg_one_smul] _ = e x := by simp @[deprecated "Use ENormedAddCommMonoid or talk to the Carleson project" (since := "2025-05-07")] theorem map_sub_rev (x y : V) : e (x - y) = e (y - x) := by rw [← neg_sub, e.map_neg] @[deprecated "Use ENormedAddCommMonoid or talk to the Carleson project" (since := "2025-05-07")] theorem map_add_le (x y : V) : e (x + y) ≀ e x + e y := e.map_add_le' x y @[deprecated "Use ENormedAddCommMonoid or talk to the Carleson project" (since := "2025-05-07")] theorem map_sub_le (x y : V) : e (x - y) ≀ e x + e y := calc e (x - y) = e (x + -y) := by rw [sub_eq_add_neg] _ ≀ e x + e (-y) := e.map_add_le x (-y) _ = e x + e y := by rw [e.map_neg] instance partialOrder : PartialOrder (ENormedSpace π•œ V) where le e₁ eβ‚‚ := βˆ€ x, e₁ x ≀ eβ‚‚ x le_refl _ _ := le_rfl le_trans _ _ _ h₁₂ h₂₃ x := le_trans (h₁₂ x) (h₂₃ x) le_antisymm _ _ h₁₂ h₂₁ := ext fun x => le_antisymm (h₁₂ x) (h₂₁ x) /-- The `ENormedSpace` sending each non-zero vector to infinity. -/ noncomputable instance : Top (ENormedSpace π•œ V) := ⟨{ toFun := fun x => open scoped Classical in if x = 0 then 0 else ⊀ eq_zero' := fun x => by split_ifs <;> simp [*] map_add_le' := fun x y => by split_ifs with hxy hx hy hy hx hy hy <;> try simp [*] simp [hx, hy] at hxy map_smul_le' := fun c x => by split_ifs with hcx hx hx <;> simp only [smul_eq_zero, not_or] at hcx Β· simp only [mul_zero, le_refl] Β· have : c = 0 := by tauto simp [this] Β· tauto Β· simpa [mul_top'] using hcx.1 }⟩ noncomputable instance : Inhabited (ENormedSpace π•œ V) := ⟨⊀⟩ @[deprecated "Use ENormedAddCommMonoid or talk to the Carleson project" (since := "2025-05-07")] theorem top_map {x : V} (hx : x β‰  0) : (⊀ : ENormedSpace π•œ V) x = ⊀ := if_neg hx noncomputable instance : OrderTop (ENormedSpace π•œ V) where le_top e x := by obtain h | h := eq_or_ne x 0 <;> simp [top_map, h] noncomputable instance : SemilatticeSup (ENormedSpace π•œ V) where sup := fun e₁ eβ‚‚ => { toFun := fun x => max (e₁ x) (eβ‚‚ x) eq_zero' := fun _ h => e₁.eq_zero_iff.1 (ENNReal.max_eq_zero_iff.1 h).1 map_add_le' := fun _ _ => max_le (le_trans (e₁.map_add_le _ _) <| add_le_add (le_max_left _ _) (le_max_left _ _)) (le_trans (eβ‚‚.map_add_le _ _) <| add_le_add (le_max_right _ _) (le_max_right _ _)) map_smul_le' := fun c x => le_of_eq <| by simp only [map_smul, mul_max] } le_sup_left := fun _ _ _ => le_max_left _ _ le_sup_right := fun _ _ _ => le_max_right _ _ sup_le := fun _ _ _ h₁ hβ‚‚ x => max_le (h₁ x) (hβ‚‚ x) @[deprecated "Use ENormedAddCommMonoid or talk to the Carleson project" (since := "2025-05-07"), simp, norm_cast] theorem coe_max (e₁ eβ‚‚ : ENormedSpace π•œ V) : ⇑(e₁ βŠ” eβ‚‚) = fun x => max (e₁ x) (eβ‚‚ x) := rfl @[deprecated "Use ENormedAddCommMonoid or talk to the Carleson project" (since := "2025-05-07"), norm_cast] theorem max_map (e₁ eβ‚‚ : ENormedSpace π•œ V) (x : V) : (e₁ βŠ” eβ‚‚) x = max (e₁ x) (eβ‚‚ x) := rfl /-- Structure of an `EMetricSpace` defined by an extended norm. -/ @[deprecated "Use ENormedAddCommMonoid or talk to the Carleson project" (since := "2025-05-07")] abbrev emetricSpace : EMetricSpace V where edist x y := e (x - y) edist_self x := by simp eq_of_edist_eq_zero {x y} := by simp [sub_eq_zero] edist_comm := e.map_sub_rev edist_triangle x y z := calc e (x - z) = e (x - y + (y - z)) := by rw [sub_add_sub_cancel] _ ≀ e (x - y) + e (y - z) := e.map_add_le (x - y) (y - z) /-- The subspace of vectors with finite ENormedSpace. -/ @[deprecated "Use ENormedAddCommMonoid or talk to the Carleson project" (since := "2025-05-07")] def finiteSubspace : Subspace π•œ V where carrier := { x | e x < ⊀ } zero_mem' := by simp add_mem' {x y} hx hy := lt_of_le_of_lt (e.map_add_le x y) (ENNReal.add_lt_top.2 ⟨hx, hy⟩) smul_mem' c x (hx : _ < _) := calc e (c β€’ x) = β€–cβ€–β‚Š * e x := e.map_smul c x _ < ⊀ := ENNReal.mul_lt_top ENNReal.coe_lt_top hx /-- Metric space structure on `e.finiteSubspace`. We use `EMetricSpace.toMetricSpace` to ensure that this definition agrees with `e.emetricSpace`. -/ instance metricSpace : MetricSpace e.finiteSubspace := by letI := e.emetricSpace refine EMetricSpace.toMetricSpace fun x y => ?_ change e (x - y) β‰  ⊀ exact ne_top_of_le_ne_top (ENNReal.add_lt_top.2 ⟨x.2, y.2⟩).ne (e.map_sub_le x y) @[deprecated "Use ENormedAddCommMonoid or talk to the Carleson project" (since := "2025-05-07")] theorem finite_dist_eq (x y : e.finiteSubspace) : dist x y = (e (x - y)).toReal := rfl @[deprecated "Use ENormedAddCommMonoid or talk to the Carleson project" (since := "2025-05-07")] theorem finite_edist_eq (x y : e.finiteSubspace) : edist x y = e (x - y) := rfl /-- Normed group instance on `e.finiteSubspace`. -/ instance normedAddCommGroup : NormedAddCommGroup e.finiteSubspace := { e.metricSpace with norm := fun x => (e x).toReal dist_eq := fun _ _ => rfl } @[deprecated "Use ENormedAddCommMonoid or talk to the Carleson project" (since := "2025-05-07")] theorem finite_norm_eq (x : e.finiteSubspace) : β€–xβ€– = (e x).toReal := rfl /-- Normed space instance on `e.finiteSubspace`. -/ instance normedSpace : NormedSpace π•œ e.finiteSubspace where norm_smul_le c x := le_of_eq <| by simp [finite_norm_eq, ENNReal.toReal_mul] end ENormedSpace
.lake/packages/mathlib/Mathlib/Analysis/NormedSpace/HomeomorphBall.lean
import Mathlib.Analysis.Normed.Module.Ball.Homeomorph deprecated_module (since := "2025-09-02")
.lake/packages/mathlib/Mathlib/Analysis/NormedSpace/ConformalLinearMap.lean
import Mathlib.Analysis.Normed.Operator.Conformal deprecated_module (since := "2025-09-16")
.lake/packages/mathlib/Mathlib/Analysis/NormedSpace/IndicatorFunction.lean
import Mathlib.Analysis.Normed.Group.Indicator deprecated_module (since := "2025-09-02")
.lake/packages/mathlib/Mathlib/Analysis/NormedSpace/Normalize.lean
import Mathlib.Analysis.RCLike.Basic import Mathlib.Data.Sign.Defs /-! # Normalized vector Function that returns unit length vector that points in the same direction (if the given vector is nonzero vector) or returns zero vector (if the given vector is zero vector). -/ variable {V : Type*} [NormedAddCommGroup V] [NormedSpace ℝ V] /-- For a nonzero vector `x`, `normalize x` is the unit-length vector that points in the same direction as `x`. If `x = 0`, then `normalize x = 0`. -/ noncomputable def NormedSpace.normalize (x : V) : V := β€–x‖⁻¹ β€’ x namespace NormedSpace @[simp] theorem normalize_zero_eq_zero : normalize (0 : V) = 0 := by simp [normalize] @[simp] theorem normalize_eq_zero_iff (x : V) : normalize x = 0 ↔ x = 0 := by by_cases hx : x = 0 <;> simp [normalize, hx] @[simp] theorem norm_smul_normalize (x : V) : β€–xβ€– β€’ normalize x = x := by by_cases hx : x = 0 <;> simp [normalize, hx] @[simp] lemma norm_normalize_eq_one_iff {x : V} : β€–normalize xβ€– = 1 ↔ x β‰  0 := by by_cases hx : x = 0 <;> simp [normalize, hx, norm_smul] alias ⟨_, norm_normalize⟩ := norm_normalize_eq_one_iff lemma normalize_eq_self_of_norm_eq_one {x : V} (h : β€–xβ€– = 1) : normalize x = x := by simp [normalize, h] @[simp] theorem normalize_normalize (x : V) : normalize (normalize x) = normalize x := by by_cases hx : x = 0 Β· simp [hx] Β· simp [normalize_eq_self_of_norm_eq_one, hx] @[simp] theorem normalize_neg (x : V) : normalize (- x) = - normalize x := by simp [normalize] theorem normalize_smul_of_pos {r : ℝ} (hr : 0 < r) (x : V) : normalize (r β€’ x) = normalize x := by simp [normalize, norm_smul, smul_smul, abs_of_pos hr, hr.ne'] theorem normalize_smul_of_neg {r : ℝ} (hr : r < 0) (x : V) : normalize (r β€’ x) = - normalize x := by simpa using normalize_smul_of_pos (show 0 < -r by linarith) (-x) theorem normalize_smul (r : ℝ) (x : V) : normalize (r β€’ x) = (SignType.sign r : ℝ) β€’ normalize x := by rcases lt_trichotomy 0 r with (h_pos | rfl | h_neg) Β· simp [normalize_smul_of_pos, h_pos] Β· simp Β· simp [normalize_smul_of_neg, h_neg] end NormedSpace
.lake/packages/mathlib/Mathlib/Analysis/NormedSpace/SphereNormEquiv.lean
import Mathlib.Analysis.Normed.Module.Ball.RadialEquiv deprecated_module (since := "2025-09-02")
.lake/packages/mathlib/Mathlib/Analysis/NormedSpace/BallAction.lean
import Mathlib.Analysis.Normed.Module.Ball.Action deprecated_module (since := "2025-09-02")
.lake/packages/mathlib/Mathlib/Analysis/NormedSpace/MStructure.lean
import Mathlib.Algebra.Ring.Idempotent import Mathlib.Analysis.Normed.Group.Basic import Mathlib.Order.Basic import Mathlib.Tactic.NoncommRing /-! # M-structure A projection P on a normed space X is said to be an L-projection (`IsLprojection`) if, for all `x` in `X`, $\|x\| = \|P x\| + \|(1 - P) x\|$. A projection P on a normed space X is said to be an M-projection if, for all `x` in `X`, $\|x\| = max(\|P x\|,\|(1 - P) x\|)$. The L-projections on `X` form a Boolean algebra (`IsLprojection.Subtype.BooleanAlgebra`). ## TODO (Motivational background) The M-projections on a normed space form a Boolean algebra. The range of an L-projection on a normed space `X` is said to be an L-summand of `X`. The range of an M-projection is said to be an M-summand of `X`. When `X` is a Banach space, the Boolean algebra of L-projections is complete. Let `X` be a normed space with dual `X^*`. A closed subspace `M` of `X` is said to be an M-ideal if the topological annihilator `M^∘` is an L-summand of `X^*`. M-ideal, M-summands and L-summands were introduced by Alfsen and Effros in [alfseneffros1972] to study the structure of general Banach spaces. When `A` is a JB*-triple, the M-ideals of `A` are exactly the norm-closed ideals of `A`. When `A` is a JBW*-triple with predual `X`, the M-summands of `A` are exactly the weak*-closed ideals, and their pre-duals can be identified with the L-summands of `X`. In the special case when `A` is a C*-algebra, the M-ideals are exactly the norm-closed two-sided ideals of `A`, when `A` is also a W*-algebra the M-summands are exactly the weak*-closed two-sided ideals of `A`. ## Implementation notes The approach to showing that the L-projections form a Boolean algebra is inspired by `MeasureTheory.MeasurableSpace`. Instead of using `P : X β†’L[π•œ] X` to represent projections, we use an arbitrary ring `M` with a faithful action on `X`. `ContinuousLinearMap.apply_module` can be used to recover the `X β†’L[π•œ] X` special case. ## References * [Behrends, M-structure and the Banach-Stone Theorem][behrends1979] * [Harmand, Werner, Werner, M-ideals in Banach spaces and Banach algebras][harmandwernerwerner1993] ## Tags M-summand, M-projection, L-summand, L-projection, M-ideal, M-structure -/ variable (X : Type*) [NormedAddCommGroup X] variable {M : Type*} [Ring M] [Module M X] /-- A projection on a normed space `X` is said to be an L-projection if, for all `x` in `X`, $\|x\| = \|P x\| + \|(1 - P) x\|$. Note that we write `P β€’ x` instead of `P x` for reasons described in the module docstring. -/ structure IsLprojection (P : M) : Prop where proj : IsIdempotentElem P Lnorm : βˆ€ x : X, β€–xβ€– = β€–P β€’ xβ€– + β€–(1 - P) β€’ xβ€– /-- A projection on a normed space `X` is said to be an M-projection if, for all `x` in `X`, $\|x\| = max(\|P x\|,\|(1 - P) x\|)$. Note that we write `P β€’ x` instead of `P x` for reasons described in the module docstring. -/ structure IsMprojection (P : M) : Prop where proj : IsIdempotentElem P Mnorm : βˆ€ x : X, β€–xβ€– = max β€–P β€’ xβ€– β€–(1 - P) β€’ xβ€– variable {X} namespace IsLprojection -- TODO: The literature always uses uppercase 'L' for L-projections theorem Lcomplement {P : M} (h : IsLprojection X P) : IsLprojection X (1 - P) := ⟨h.proj.one_sub, fun x => by rw [add_comm, sub_sub_cancel] exact h.Lnorm x⟩ theorem Lcomplement_iff (P : M) : IsLprojection X P ↔ IsLprojection X (1 - P) := ⟨Lcomplement, fun h => sub_sub_cancel 1 P β–Έ h.Lcomplement⟩ theorem commute [FaithfulSMul M X] {P Q : M} (h₁ : IsLprojection X P) (hβ‚‚ : IsLprojection X Q) : Commute P Q := by have PR_eq_RPR : βˆ€ R : M, IsLprojection X R β†’ P * R = R * P * R := fun R h₃ => by refine @eq_of_smul_eq_smul _ X _ _ _ _ fun x => by rw [← norm_sub_eq_zero_iff] have e1 : β€–R β€’ xβ€– β‰₯ β€–R β€’ xβ€– + 2 β€’ β€–(P * R) β€’ x - (R * P * R) β€’ xβ€– := calc β€–R β€’ xβ€– = β€–R β€’ P β€’ R β€’ xβ€– + β€–(1 - R) β€’ P β€’ R β€’ xβ€– + (β€–(R * R) β€’ x - R β€’ P β€’ R β€’ xβ€– + β€–(1 - R) β€’ (1 - P) β€’ R β€’ xβ€–) := by rw [h₁.Lnorm, h₃.Lnorm, h₃.Lnorm ((1 - P) β€’ R β€’ x), sub_smul 1 P, one_smul, smul_sub, mul_smul] _ = β€–R β€’ P β€’ R β€’ xβ€– + β€–(1 - R) β€’ P β€’ R β€’ xβ€– + (β€–R β€’ x - R β€’ P β€’ R β€’ xβ€– + β€–((1 - R) * R) β€’ x - (1 - R) β€’ P β€’ R β€’ xβ€–) := by rw [h₃.proj.eq, sub_smul 1 P, one_smul, smul_sub, mul_smul] _ = β€–R β€’ P β€’ R β€’ xβ€– + β€–(1 - R) β€’ P β€’ R β€’ xβ€– + (β€–R β€’ x - R β€’ P β€’ R β€’ xβ€– + β€–(1 - R) β€’ P β€’ R β€’ xβ€–) := by rw [sub_mul, h₃.proj.eq, one_mul, sub_self, zero_smul, zero_sub, norm_neg] _ = β€–R β€’ P β€’ R β€’ xβ€– + β€–R β€’ x - R β€’ P β€’ R β€’ xβ€– + 2 β€’ β€–(1 - R) β€’ P β€’ R β€’ xβ€– := by abel _ β‰₯ β€–R β€’ xβ€– + 2 β€’ β€–(P * R) β€’ x - (R * P * R) β€’ xβ€– := by rw [ge_iff_le] have := add_le_add_right (norm_le_insert' (R β€’ x) (R β€’ P β€’ R β€’ x)) (2 β€’ β€–(1 - R) β€’ P β€’ R β€’ xβ€–) simpa only [mul_smul, sub_smul, one_smul] using this rw [ge_iff_le] at e1 nth_rewrite 2 [← add_zero β€–R β€’ xβ€–] at e1 rw [add_le_add_iff_left, two_smul, ← two_mul] at e1 rw [le_antisymm_iff] refine ⟨?_, norm_nonneg _⟩ rwa [← mul_zero (2 : ℝ), mul_le_mul_iff_rightβ‚€ (show (0 : ℝ) < 2 by simp)] at e1 have QP_eq_QPQ : Q * P = Q * P * Q := by have e1 : P * (1 - Q) = P * (1 - Q) - (Q * P - Q * P * Q) := calc P * (1 - Q) = (1 - Q) * P * (1 - Q) := by rw [PR_eq_RPR (1 - Q) hβ‚‚.Lcomplement] _ = P * (1 - Q) - (Q * P - Q * P * Q) := by noncomm_ring rwa [eq_sub_iff_add_eq, add_eq_left, sub_eq_zero] at e1 change P * Q = Q * P rw [QP_eq_QPQ, PR_eq_RPR Q hβ‚‚] theorem mul [FaithfulSMul M X] {P Q : M} (h₁ : IsLprojection X P) (hβ‚‚ : IsLprojection X Q) : IsLprojection X (P * Q) := by refine ⟨IsIdempotentElem.mul_of_commute (h₁.commute hβ‚‚) h₁.proj hβ‚‚.proj, ?_⟩ intro x refine le_antisymm ?_ ?_ Β· calc β€–xβ€– = β€–(P * Q) β€’ x + (x - (P * Q) β€’ x)β€– := by rw [add_sub_cancel ((P * Q) β€’ x) x] _ ≀ β€–(P * Q) β€’ xβ€– + β€–x - (P * Q) β€’ xβ€– := by apply norm_add_le _ = β€–(P * Q) β€’ xβ€– + β€–(1 - P * Q) β€’ xβ€– := by rw [sub_smul, one_smul] Β· calc β€–xβ€– = β€–P β€’ Q β€’ xβ€– + (β€–Q β€’ x - P β€’ Q β€’ xβ€– + β€–x - Q β€’ xβ€–) := by rw [hβ‚‚.Lnorm x, h₁.Lnorm (Q β€’ x), sub_smul, one_smul, sub_smul, one_smul, add_assoc] _ β‰₯ β€–P β€’ Q β€’ xβ€– + β€–Q β€’ x - P β€’ Q β€’ x + (x - Q β€’ x)β€– := ((add_le_add_iff_left β€–P β€’ Q β€’ xβ€–).mpr (norm_add_le (Q β€’ x - P β€’ Q β€’ x) (x - Q β€’ x))) _ = β€–(P * Q) β€’ xβ€– + β€–(1 - P * Q) β€’ xβ€– := by rw [sub_add_sub_cancel', sub_smul, one_smul, mul_smul] theorem join [FaithfulSMul M X] {P Q : M} (h₁ : IsLprojection X P) (hβ‚‚ : IsLprojection X Q) : IsLprojection X (P + Q - P * Q) := by convert (Lcomplement_iff _).mp (h₁.Lcomplement.mul hβ‚‚.Lcomplement) using 1 noncomm_ring instance Subtype.hasCompl : HasCompl { f : M // IsLprojection X f } := ⟨fun P => ⟨1 - P, P.prop.Lcomplement⟩⟩ @[simp] theorem coe_compl (P : { P : M // IsLprojection X P }) : ↑Pᢜ = (1 : M) - ↑P := rfl instance Subtype.inf [FaithfulSMul M X] : Min { P : M // IsLprojection X P } := ⟨fun P Q => ⟨P * Q, P.prop.mul Q.prop⟩⟩ @[simp] theorem coe_inf [FaithfulSMul M X] (P Q : { P : M // IsLprojection X P }) : ↑(P βŠ“ Q) = (↑P : M) * ↑Q := rfl instance Subtype.sup [FaithfulSMul M X] : Max { P : M // IsLprojection X P } := ⟨fun P Q => ⟨P + Q - P * Q, P.prop.join Q.prop⟩⟩ @[simp] theorem coe_sup [FaithfulSMul M X] (P Q : { P : M // IsLprojection X P }) : ↑(P βŠ” Q) = (↑P : M) + ↑Q - ↑P * ↑Q := rfl instance Subtype.sdiff [FaithfulSMul M X] : SDiff { P : M // IsLprojection X P } := ⟨fun P Q => ⟨P * (1 - Q), P.prop.mul Q.prop.Lcomplement⟩⟩ @[simp] theorem coe_sdiff [FaithfulSMul M X] (P Q : { P : M // IsLprojection X P }) : ↑(P \ Q) = (↑P : M) * (1 - ↑Q) := rfl instance Subtype.partialOrder [FaithfulSMul M X] : PartialOrder { P : M // IsLprojection X P } where le P Q := (↑P : M) = ↑(P βŠ“ Q) le_refl P := by simpa only [coe_inf, ← sq] using P.prop.proj.eq.symm le_trans P Q R h₁ hβ‚‚ := by simp only [coe_inf] at h₁ hβ‚‚ ⊒ rw [h₁, mul_assoc, ← hβ‚‚] le_antisymm P Q h₁ hβ‚‚ := Subtype.eq (by convert (P.prop.commute Q.prop).eq) theorem le_def [FaithfulSMul M X] (P Q : { P : M // IsLprojection X P }) : P ≀ Q ↔ (P : M) = ↑(P βŠ“ Q) := Iff.rfl instance Subtype.zero : Zero { P : M // IsLprojection X P } := ⟨⟨0, ⟨by rw [IsIdempotentElem, zero_mul], fun x => by simp only [zero_smul, norm_zero, sub_zero, one_smul, zero_add]⟩⟩⟩ @[simp] theorem coe_zero : ↑(0 : { P : M // IsLprojection X P }) = (0 : M) := rfl instance Subtype.one : One { P : M // IsLprojection X P } := ⟨⟨1, sub_zero (1 : M) β–Έ (0 : { P : M // IsLprojection X P }).prop.Lcomplement⟩⟩ @[simp] theorem coe_one : ↑(1 : { P : M // IsLprojection X P }) = (1 : M) := rfl instance Subtype.boundedOrder [FaithfulSMul M X] : BoundedOrder { P : M // IsLprojection X P } where top := 1 le_top P := (mul_one (P : M)).symm bot := 0 bot_le P := (zero_mul (P : M)).symm @[simp] theorem coe_bot [FaithfulSMul M X] : ↑(BoundedOrder.toOrderBot.toBot.bot : { P : M // IsLprojection X P }) = (0 : M) := rfl @[simp] theorem coe_top [FaithfulSMul M X] : ↑(BoundedOrder.toOrderTop.toTop.top : { P : M // IsLprojection X P }) = (1 : M) := rfl theorem compl_mul {P : { P : M // IsLprojection X P }} {Q : M} : ↑Pᢜ * Q = Q - ↑P * Q := by rw [coe_compl, sub_mul, one_mul] theorem mul_compl_self {P : { P : M // IsLprojection X P }} : (↑P : M) * ↑Pᢜ = 0 := by rw [coe_compl, P.prop.proj.mul_one_sub_self] theorem distrib_lattice_lemma [FaithfulSMul M X] {P Q R : { P : M // IsLprojection X P }} : ((↑P : M) + ↑Pᢜ * R) * (↑P + ↑Q * ↑R * ↑Pᢜ) = ↑P + ↑Q * ↑R * ↑Pᢜ := by rw [add_mul, mul_add, mul_add, (mul_assoc _ (R : M) (↑Q * ↑R * ↑Pᢜ)), ← mul_assoc (R : M) (↑Q * ↑R) _, ← coe_inf Q, (Pᢜ.prop.commute R.prop).eq, ((Q βŠ“ R).prop.commute Pᢜ.prop).eq, (R.prop.commute (Q βŠ“ R).prop).eq, coe_inf Q, mul_assoc (Q : M), ← mul_assoc, mul_assoc (R : M), (Pᢜ.prop.commute P.prop).eq, mul_compl_self, zero_mul, mul_zero, zero_add, add_zero, ← mul_assoc, P.prop.proj.eq, R.prop.proj.eq, ← coe_inf Q, mul_assoc, ((Q βŠ“ R).prop.commute Pᢜ.prop).eq, ← mul_assoc, Pᢜ.prop.proj.eq] /- This instance was created as an auxiliary definition when defining `Subtype.distribLattice` all at once would cause a timeout. That is no longer the case. Keeping this as a useful shortcut. -/ instance [FaithfulSMul M X] : Lattice { P : M // IsLprojection X P } where sup := max inf := min le_sup_left P Q := by rw [le_def, coe_inf, coe_sup, ← add_sub, mul_add, mul_sub, ← mul_assoc, P.prop.proj.eq, sub_self, add_zero] le_sup_right P Q := by rw [le_def, coe_inf, coe_sup, ← add_sub, mul_add, mul_sub, (P.prop.commute Q.prop).eq, ← mul_assoc, Q.prop.proj.eq, add_sub_cancel] sup_le P Q R := by rw [le_def, le_def, le_def, coe_inf, coe_inf, coe_sup, coe_inf, coe_sup, ← add_sub, add_mul, sub_mul, mul_assoc] intro h₁ hβ‚‚ rw [← hβ‚‚, ← h₁] inf_le_left P Q := by rw [le_def, coe_inf, coe_inf, coe_inf, mul_assoc, (Q.prop.commute P.prop).eq, ← mul_assoc, P.prop.proj.eq] inf_le_right P Q := by rw [le_def, coe_inf, coe_inf, coe_inf, mul_assoc, Q.prop.proj.eq] le_inf P Q R := by rw [le_def, le_def, le_def, coe_inf, coe_inf, coe_inf, coe_inf, ← mul_assoc] intro h₁ hβ‚‚ rw [← h₁, ← hβ‚‚] instance Subtype.distribLattice [FaithfulSMul M X] : DistribLattice { P : M // IsLprojection X P } where le_sup_inf P Q R := by have e₁ : ↑((P βŠ” Q) βŠ“ (P βŠ” R)) = ↑P + ↑Q * (R : M) * ↑Pᢜ := by rw [coe_inf, coe_sup, coe_sup, ← add_sub, ← add_sub, ← compl_mul, ← compl_mul, add_mul, mul_add, (Pᢜ.prop.commute Q.prop).eq, mul_add, ← mul_assoc, mul_assoc (Q : M), (Pᢜ.prop.commute P.prop).eq, mul_compl_self, zero_mul, mul_zero, zero_add, add_zero, ← mul_assoc, mul_assoc (Q : M), P.prop.proj.eq, Pᢜ.prop.proj.eq, mul_assoc, (Pᢜ.prop.commute R.prop).eq, ← mul_assoc] have eβ‚‚ : ↑((P βŠ” Q) βŠ“ (P βŠ” R)) * ↑(P βŠ” Q βŠ“ R) = (P : M) + ↑Q * ↑R * ↑Pᢜ := by rw [coe_inf, coe_sup, coe_sup, coe_sup, ← add_sub, ← add_sub, ← add_sub, ← compl_mul, ← compl_mul, ← compl_mul, (Pᢜ.prop.commute (Q βŠ“ R).prop).eq, coe_inf, mul_assoc, distrib_lattice_lemma, (Q.prop.commute R.prop).eq, distrib_lattice_lemma] rw [le_def, e₁, coe_inf, eβ‚‚] instance Subtype.BooleanAlgebra [FaithfulSMul M X] : BooleanAlgebra { P : M // IsLprojection X P } := { IsLprojection.Subtype.hasCompl, IsLprojection.Subtype.sdiff, IsLprojection.Subtype.boundedOrder with inf_compl_le_bot := fun P => (Subtype.ext (by rw [coe_inf, coe_compl, coe_bot, ← coe_compl, mul_compl_self])).le top_le_sup_compl := fun P => (Subtype.ext (by rw [coe_top, coe_sup, coe_compl, add_sub_cancel, ← coe_compl, mul_compl_self, sub_zero])).le sdiff_eq := fun P Q => Subtype.ext <| by rw [coe_sdiff, ← coe_compl, coe_inf] } end IsLprojection
.lake/packages/mathlib/Mathlib/Analysis/NormedSpace/Connected.lean
import Mathlib.Analysis.Convex.Contractible import Mathlib.Analysis.Convex.Topology import Mathlib.Analysis.Normed.Module.Convex import Mathlib.LinearAlgebra.Dimension.DivisionRing import Mathlib.Topology.Algebra.Module.Cardinality /-! # Connectedness of subsets of vector spaces We show several results related to the (path)-connectedness of subsets of real vector spaces: * `Set.Countable.isPathConnected_compl_of_one_lt_rank` asserts that the complement of a countable set is path-connected in a space of dimension `> 1`. * `isPathConnected_compl_singleton_of_one_lt_rank` is the special case of the complement of a singleton. * `isPathConnected_sphere` shows that any sphere is path-connected in dimension `> 1`. * `isPathConnected_compl_of_one_lt_codim` shows that the complement of a subspace of codimension `> 1` is path-connected. Statements with connectedness instead of path-connectedness are also given. -/ assert_not_exists Subgroup.index Nat.divisors -- TODO assert_not_exists Cardinal open Convex Set Metric section TopologicalVectorSpace variable {E : Type*} [AddCommGroup E] [Module ℝ E] [TopologicalSpace E] [ContinuousAdd E] [ContinuousSMul ℝ E] /-- In a real vector space of dimension `> 1`, the complement of any countable set is path connected. -/ theorem Set.Countable.isPathConnected_compl_of_one_lt_rank (h : 1 < Module.rank ℝ E) {s : Set E} (hs : s.Countable) : IsPathConnected sᢜ := by have : Nontrivial E := (rank_pos_iff_nontrivial (R := ℝ)).1 (zero_lt_one.trans h) -- the set `sᢜ` is dense, therefore nonempty. Pick `a ∈ sᢜ`. We have to show that any -- `b ∈ sᢜ` can be joined to `a`. obtain ⟨a, ha⟩ : sᢜ.Nonempty := (hs.dense_compl ℝ).nonempty refine ⟨a, ha, ?_⟩ intro b hb rcases eq_or_ne a b with rfl | hab Β· exact JoinedIn.refl ha /- Assume `b β‰  a`. Write `a = c - x` and `b = c + x` for some nonzero `x`. Choose `y` which is linearly independent from `x`. Then the segments joining `a = c - x` to `c + ty` are pairwise disjoint for varying `t` (except for the endpoint `a`) so only countably many of them can intersect `s`. In the same way, there are countably many `t`s for which the segment from `b = c + x` to `c + ty` intersects `s`. Choosing `t` outside of these countable exceptions, one gets a path in the complement of `s` from `a` to `z = c + ty` and then to `b`. -/ let c := (2 : ℝ)⁻¹ β€’ (a + b) let x := (2 : ℝ)⁻¹ β€’ (b - a) have Ia : c - x = a := by simp only [c, x] module have Ib : c + x = b := by simp only [c, x] module have x_ne_zero : x β‰  0 := by simpa [x] using sub_ne_zero.2 hab.symm obtain ⟨y, hy⟩ : βˆƒ y, LinearIndependent ℝ ![x, y] := exists_linearIndependent_pair_of_one_lt_rank h x_ne_zero have A : Set.Countable {t : ℝ | ([c + x -[ℝ] c + t β€’ y] ∩ s).Nonempty} := by apply countable_setOf_nonempty_of_disjoint _ (fun t ↦ inter_subset_right) hs intro t t' htt' apply disjoint_iff_inter_eq_empty.2 have N : {c + x} ∩ s = βˆ… := by simpa only [singleton_inter_eq_empty, mem_compl_iff, Ib] using hb rw [inter_assoc, inter_comm s, inter_assoc, inter_self, ← inter_assoc, ← subset_empty_iff, ← N] apply inter_subset_inter_left apply Eq.subset apply segment_inter_eq_endpoint_of_linearIndependent_of_ne hy htt'.symm have B : Set.Countable {t : ℝ | ([c - x -[ℝ] c + t β€’ y] ∩ s).Nonempty} := by apply countable_setOf_nonempty_of_disjoint _ (fun t ↦ inter_subset_right) hs intro t t' htt' apply disjoint_iff_inter_eq_empty.2 have N : {c - x} ∩ s = βˆ… := by simpa only [singleton_inter_eq_empty, mem_compl_iff, Ia] using ha rw [inter_assoc, inter_comm s, inter_assoc, inter_self, ← inter_assoc, ← subset_empty_iff, ← N] apply inter_subset_inter_left rw [sub_eq_add_neg _ x] apply Eq.subset apply segment_inter_eq_endpoint_of_linearIndependent_of_ne _ htt'.symm convert hy.units_smul ![-1, 1] simp [← List.ofFn_inj] obtain ⟨t, ht⟩ : Set.Nonempty ({t : ℝ | ([c + x -[ℝ] c + t β€’ y] ∩ s).Nonempty} βˆͺ {t : ℝ | ([c - x -[ℝ] c + t β€’ y] ∩ s).Nonempty})ᢜ := ((A.union B).dense_compl ℝ).nonempty let z := c + t β€’ y simp only [compl_union, mem_inter_iff, mem_compl_iff, mem_setOf_eq, not_nonempty_iff_eq_empty] at ht have JA : JoinedIn sᢜ a z := by apply JoinedIn.of_segment_subset rw [subset_compl_iff_disjoint_right, disjoint_iff_inter_eq_empty] convert ht.2 exact Ia.symm have JB : JoinedIn sᢜ b z := by apply JoinedIn.of_segment_subset rw [subset_compl_iff_disjoint_right, disjoint_iff_inter_eq_empty] convert ht.1 exact Ib.symm exact JA.trans JB.symm /-- In a real vector space of dimension `> 1`, the complement of any countable set is connected. -/ theorem Set.Countable.isConnected_compl_of_one_lt_rank (h : 1 < Module.rank ℝ E) {s : Set E} (hs : s.Countable) : IsConnected sᢜ := (hs.isPathConnected_compl_of_one_lt_rank h).isConnected /-- In a real vector space of dimension `> 1`, the complement of any singleton is path-connected. -/ theorem isPathConnected_compl_singleton_of_one_lt_rank (h : 1 < Module.rank ℝ E) (x : E) : IsPathConnected {x}ᢜ := Set.Countable.isPathConnected_compl_of_one_lt_rank h (countable_singleton x) /-- In a real vector space of dimension `> 1`, the complement of a singleton is connected. -/ theorem isConnected_compl_singleton_of_one_lt_rank (h : 1 < Module.rank ℝ E) (x : E) : IsConnected {x}ᢜ := (isPathConnected_compl_singleton_of_one_lt_rank h x).isConnected end TopologicalVectorSpace section NormedSpace variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] section Ball namespace Metric theorem ball_contractible {x : E} {r : ℝ} (hr : 0 < r) : ContractibleSpace (ball x r) := Convex.contractibleSpace (convex_ball _ _) (by simpa) theorem eball_contractible {x : E} {r : ENNReal} (hr : 0 < r) : ContractibleSpace (EMetric.ball x r) := by cases r with | top => rw [eball_top_eq_univ, (Homeomorph.Set.univ E).contractibleSpace_iff] exact RealTopologicalVectorSpace.contractibleSpace | coe r => rw [emetric_ball_nnreal] apply ball_contractible simpa using hr theorem isPathConnected_ball {x : E} {r : ℝ} (hr : 0 < r) : IsPathConnected (ball x r) := by rw [isPathConnected_iff_pathConnectedSpace] exact @ContractibleSpace.instPathConnectedSpace _ _ (ball_contractible hr) theorem isPathConnected_eball {x : E} {r : ENNReal} (hr : 0 < r) : IsPathConnected (EMetric.ball x r) := by rw [isPathConnected_iff_pathConnectedSpace] exact @ContractibleSpace.instPathConnectedSpace _ _ (eball_contractible hr) theorem isConnected_ball {x : E} {r : ℝ} (hr : 0 < r) : IsConnected (ball x r) := (isPathConnected_ball hr).isConnected theorem isConnected_eball {x : E} {r : ENNReal} (hr : 0 < r) : IsConnected (EMetric.ball x r) := (isPathConnected_eball hr).isConnected end Metric end Ball /-- In a real vector space of dimension `> 1`, any sphere of nonnegative radius is path connected. -/ theorem isPathConnected_sphere (h : 1 < Module.rank ℝ E) (x : E) {r : ℝ} (hr : 0 ≀ r) : IsPathConnected (sphere x r) := by /- when `r > 0`, we write the sphere as the image of `{0}ᢜ` under the map `y ↦ x + (r * β€–y‖⁻¹) β€’ y`. Since the image under a continuous map of a path connected set is path connected, this concludes the proof. -/ rcases hr.eq_or_lt with rfl | rpos Β· simpa using isPathConnected_singleton x let f : E β†’ E := fun y ↦ x + (r * β€–y‖⁻¹) β€’ y have A : ContinuousOn f {0}ᢜ := by intro y hy apply (continuousAt_const.add _).continuousWithinAt apply (continuousAt_const.mul (ContinuousAt.invβ‚€ continuousAt_id.norm ?_)).smul continuousAt_id simpa using hy have B : IsPathConnected ({0}ᢜ : Set E) := isPathConnected_compl_singleton_of_one_lt_rank h 0 have C : IsPathConnected (f '' {0}ᢜ) := B.image' A have : f '' {0}ᢜ = sphere x r := by apply Subset.antisymm Β· rintro - ⟨y, hy, rfl⟩ have : β€–yβ€– β‰  0 := by simpa using hy simp [f, norm_smul, abs_of_nonneg hr, mul_assoc, inv_mul_cancelβ‚€ this] Β· intro y hy refine ⟨y - x, ?_, ?_⟩ Β· intro H simp only [mem_singleton_iff, sub_eq_zero] at H simp only [H, mem_sphere_iff_norm, sub_self, norm_zero] at hy exact rpos.ne hy Β· simp [f, mem_sphere_iff_norm.1 hy, mul_inv_cancelβ‚€ rpos.ne'] rwa [this] at C /-- In a real vector space of dimension `> 1`, any sphere of nonnegative radius is connected. -/ theorem isConnected_sphere (h : 1 < Module.rank ℝ E) (x : E) {r : ℝ} (hr : 0 ≀ r) : IsConnected (sphere x r) := (isPathConnected_sphere h x hr).isConnected /-- In a real vector space of dimension `> 1`, any sphere is preconnected. -/ theorem isPreconnected_sphere (h : 1 < Module.rank ℝ E) (x : E) (r : ℝ) : IsPreconnected (sphere x r) := by rcases le_or_gt 0 r with hr|hr Β· exact (isConnected_sphere h x hr).isPreconnected Β· simpa [hr] using isPreconnected_empty end NormedSpace section variable {F : Type*} [AddCommGroup F] [Module ℝ F] [TopologicalSpace F] [IsTopologicalAddGroup F] [ContinuousSMul ℝ F] /-- Let `E` be a linear subspace in a real vector space. If `E` has codimension at least two, its complement is path-connected. -/ theorem isPathConnected_compl_of_one_lt_codim {E : Submodule ℝ F} (hcodim : 1 < Module.rank ℝ (F β§Έ E)) : IsPathConnected (Eᢜ : Set F) := by rcases E.exists_isCompl with ⟨E', hE'⟩ refine isPathConnected_compl_of_isPathConnected_compl_zero hE'.symm (isPathConnected_compl_singleton_of_one_lt_rank ?_ 0) rwa [← (E.quotientEquivOfIsCompl E' hE').rank_eq] /-- Let `E` be a linear subspace in a real vector space. If `E` has codimension at least two, its complement is connected. -/ theorem isConnected_compl_of_one_lt_codim {E : Submodule ℝ F} (hcodim : 1 < Module.rank ℝ (F β§Έ E)) : IsConnected (Eᢜ : Set F) := (isPathConnected_compl_of_one_lt_codim hcodim).isConnected theorem Submodule.connectedComponentIn_eq_self_of_one_lt_codim (E : Submodule ℝ F) (hcodim : 1 < Module.rank ℝ (F β§Έ E)) {x : F} (hx : x βˆ‰ E) : connectedComponentIn ((E : Set F)ᢜ) x = (E : Set F)ᢜ := (isConnected_compl_of_one_lt_codim hcodim).2.connectedComponentIn hx end
.lake/packages/mathlib/Mathlib/Analysis/NormedSpace/FunctionSeries.lean
import Mathlib.Analysis.Normed.Group.FunctionSeries deprecated_module (since := "2025-09-02")
.lake/packages/mathlib/Mathlib/Analysis/NormedSpace/MultipliableUniformlyOn.lean
import Mathlib.Analysis.Normed.Group.FunctionSeries import Mathlib.Analysis.SpecialFunctions.Log.Summable import Mathlib.Topology.Algebra.InfiniteSum.UniformOn import Mathlib.Topology.Algebra.IsUniformGroup.Order /-! # Uniform convergence of products of functions We gather some results about the uniform convergence of infinite products, in particular those of the form `∏' i, (1 + f i x)` for a sequence `f` of complex-valued functions. -/ open Filter Function Complex Finset Topology variable {Ξ± ΞΉ : Type*} {𝔖 : Set (Set Ξ±)} {K : Set Ξ±} {u : ΞΉ β†’ ℝ} section Complex variable {f : ΞΉ β†’ Ξ± β†’ β„‚} lemma TendstoUniformlyOn.comp_cexp {p : Filter ΞΉ} {g : Ξ± β†’ β„‚} (hf : TendstoUniformlyOn f g p K) (hg : BddAbove <| (fun x ↦ (g x).re) '' K) : TendstoUniformlyOn (cexp ∘ f Β·) (cexp ∘ g) p K := by obtain ⟨v, hv⟩ : βˆƒ v, βˆ€ x ∈ K, (g x).re ≀ v := hg.imp <| by simp [mem_upperBounds] have : βˆ€αΆ  i in p, βˆ€ x ∈ K, (f i x).re ≀ v + 1 := hf.re.eventually_forall_le (lt_add_one v) hv refine (UniformContinuousOn.cexp _).comp_tendstoUniformlyOn_eventually (by simpa) ?_ hf exact fun x hx ↦ (hv x hx).trans (lt_add_one v).le lemma Summable.hasSumUniformlyOn_log_one_add (hu : Summable u) (h : βˆ€αΆ  i in cofinite, βˆ€ x ∈ K, β€–f i xβ€– ≀ u i) : HasSumUniformlyOn (fun i x ↦ log (1 + f i x)) (fun x ↦ βˆ‘' i, log (1 + f i x)) {K} := by simp only [hasSumUniformlyOn_iff_tendstoUniformlyOn, Set.mem_singleton_iff, forall_eq] apply tendstoUniformlyOn_tsum_of_cofinite_eventually <| hu.mul_left (3 / 2) filter_upwards [h, hu.tendsto_cofinite_zero.eventually_le_const one_half_pos] with i hi hi' x hx using (norm_log_one_add_half_le_self <| (hi x hx).trans hi').trans (by simpa using hi x hx) lemma Summable.tendstoUniformlyOn_tsum_nat_log_one_add {f : β„• β†’ Ξ± β†’ β„‚} {u : β„• β†’ ℝ} (hu : Summable u) (h : βˆ€αΆ  n in atTop, βˆ€ x ∈ K, β€–f n xβ€– ≀ u n) : TendstoUniformlyOn (fun n x ↦ βˆ‘ m ∈ Finset.range n, log (1 + f m x)) (fun x ↦ βˆ‘' n, log (1 + f n x)) atTop K := by rw [← Nat.cofinite_eq_atTop] at h exact (hu.hasSumUniformlyOn_log_one_add h).tendstoUniformlyOn_finsetRange rfl /-- If `x ↦ βˆ‘' i, log (f i x)` is uniformly convergent on `𝔖`, its sum has bounded-above real part on each set in `𝔖`, and the functions `f i x` have no zeroes, then `∏' i, f i x` is uniformly convergent on `𝔖`. Note that the non-vanishing assumption is really needed here: if this assumption is dropped then one obtains a counterexample if `ΞΉ = Ξ± = β„•` and `f i x` is `0` if `i = x` and `1` otherwise. -/ lemma hasProdUniformlyOn_of_clog (hf : SummableUniformlyOn (fun i x ↦ log (f i x)) 𝔖) (hfn : βˆ€ K ∈ 𝔖, βˆ€ x ∈ K, βˆ€ i, f i x β‰  0) (hg : βˆ€ K ∈ 𝔖, BddAbove <| (fun x ↦ (βˆ‘' i, log (f i x)).re) '' K) : HasProdUniformlyOn f (fun x ↦ ∏' i, f i x) 𝔖 := by simp only [hasProdUniformlyOn_iff_tendstoUniformlyOn] obtain ⟨r, hr⟩ := hf.exists intro K hK suffices H : TendstoUniformlyOn (fun s x ↦ ∏ i ∈ s, f i x) (cexp ∘ r) atTop K by refine H.congr_right ((hr.tsum_eqOn hK).comp_left.symm.trans ?_) exact fun x hx ↦ (cexp_tsum_eq_tprod (hfn K hK x hx) (hf.summable hK hx)) have h1 := hr.tsum_eqOn hK simp only [hasSumUniformlyOn_iff_tendstoUniformlyOn] at hr refine ((hr K hK).comp_cexp ?_).congr ?_ Β· simpa +contextual [← h1 _] using hg K hK Β· filter_upwards with s i hi using by simp [exp_sum, fun y ↦ exp_log (hfn K hK i hi y)] lemma multipliableUniformlyOn_of_clog (hf : SummableUniformlyOn (fun i x ↦ log (f i x)) 𝔖) (hfn : βˆ€ K ∈ 𝔖, βˆ€ x ∈ K, βˆ€ i, f i x β‰  0) (hg : βˆ€ K ∈ 𝔖, BddAbove <| (fun x ↦ (βˆ‘' i, log (f i x)).re) '' K) : MultipliableUniformlyOn f 𝔖 := ⟨_, hasProdUniformlyOn_of_clog hf hfn hg⟩ end Complex namespace Summable variable {R : Type*} [NormedCommRing R] [NormOneClass R] [CompleteSpace R] [TopologicalSpace Ξ±] {f : ΞΉ β†’ Ξ± β†’ R} /-- If a sequence of continuous functions `f i x` on an open compact `K` have norms eventually bounded by a summable function, then `∏' i, (1 + f i x)` is uniformly convergent on `K`. -/ lemma hasProdUniformlyOn_one_add (hK : IsCompact K) (hu : Summable u) (h : βˆ€αΆ  i in cofinite, βˆ€ x ∈ K, β€–f i xβ€– ≀ u i) (hcts : βˆ€ i, ContinuousOn (f i) K) : HasProdUniformlyOn (fun i x ↦ 1 + f i x) (fun x ↦ ∏' i, (1 + f i x)) {K} := by simp only [hasProdUniformlyOn_iff_tendstoUniformlyOn, Set.mem_singleton_iff, tendstoUniformlyOn_iff_tendstoUniformly_comp_coe, forall_eq] by_cases hKe : K = βˆ… Β· simp [TendstoUniformly, hKe] Β· haveI hCK : CompactSpace K := isCompact_iff_compactSpace.mp hK haveI hne : Nonempty K := by rwa [Set.nonempty_coe_sort, Set.nonempty_iff_ne_empty] let f' i : C(K, R) := ⟨_, continuousOn_iff_continuous_restrict.mp (hcts i)⟩ have hf'_bd : βˆ€αΆ  i in cofinite, β€–f' iβ€– ≀ u i := by simp only [ContinuousMap.norm_le_of_nonempty] filter_upwards [h] with i hi using fun x ↦ hi x x.2 have hM : Multipliable fun i ↦ 1 + f' i := multipliable_one_add_of_summable (hu.of_norm_bounded_eventually (by simpa using hf'_bd)) convert ContinuousMap.tendsto_iff_tendstoUniformly.mp hM.hasProd Β· simp [f'] Β· exact funext fun k ↦ ContinuousMap.tprod_apply hM k lemma multipliableUniformlyOn_one_add (hK : IsCompact K) (hu : Summable u) (h : βˆ€αΆ  i in cofinite, βˆ€ x ∈ K, β€–f i xβ€– ≀ u i) (hcts : βˆ€ i, ContinuousOn (f i) K) : MultipliableUniformlyOn (fun i x ↦ 1 + f i x) {K} := ⟨_, hasProdUniformlyOn_one_add hK hu h hcts⟩ /-- This is a version of `hasProdUniformlyOn_one_add` for sequences indexed by `β„•`. -/ lemma hasProdUniformlyOn_nat_one_add {f : β„• β†’ Ξ± β†’ R} (hK : IsCompact K) {u : β„• β†’ ℝ} (hu : Summable u) (h : βˆ€αΆ  n in atTop, βˆ€ x ∈ K, β€–f n xβ€– ≀ u n) (hcts : βˆ€ n, ContinuousOn (f n) K) : HasProdUniformlyOn (fun n x ↦ 1 + f n x) (fun x ↦ ∏' i, (1 + f i x)) {K} := hasProdUniformlyOn_one_add hK hu (Nat.cofinite_eq_atTop β–Έ h) hcts lemma multipliableUniformlyOn_nat_one_add {f : β„• β†’ Ξ± β†’ R} (hK : IsCompact K) {u : β„• β†’ ℝ} (hu : Summable u) (h : βˆ€αΆ  n in atTop, βˆ€ x ∈ K, β€–f n xβ€– ≀ u n) (hcts : βˆ€ n, ContinuousOn (f n) K) : MultipliableUniformlyOn (fun n x ↦ 1 + f n x) {K} := ⟨_, hasProdUniformlyOn_nat_one_add hK hu h hcts⟩ section LocallyCompactSpace variable [LocallyCompactSpace Ξ±] /-- If a sequence of continuous functions `f i x` on an open subset `K` have norms eventually bounded by a summable function, then `∏' i, (1 + f i x)` is locally uniformly convergent on `K`. -/ lemma hasProdLocallyUniformlyOn_one_add (hK : IsOpen K) (hu : Summable u) (h : βˆ€αΆ  i in cofinite, βˆ€ x ∈ K, β€–f i xβ€– ≀ u i) (hcts : βˆ€ i, ContinuousOn (f i) K) : HasProdLocallyUniformlyOn (fun i x ↦ 1 + f i x) (fun x ↦ ∏' i, (1 + f i x)) K := by apply hasProdLocallyUniformlyOn_of_forall_compact hK refine fun S hS hC ↦ hasProdUniformlyOn_one_add hC hu ?_ fun i ↦ (hcts i).mono hS filter_upwards [h] with i hi a ha using hi a (hS ha) lemma multipliableLocallyUniformlyOn_one_add (hK : IsOpen K) (hu : Summable u) (h : βˆ€αΆ  i in cofinite, βˆ€ x ∈ K, β€–f i xβ€– ≀ u i) (hcts : βˆ€ i, ContinuousOn (f i) K) : MultipliableLocallyUniformlyOn (fun i x ↦ 1 + f i x) K := ⟨_, hasProdLocallyUniformlyOn_one_add hK hu h hcts⟩ /-- This is a version of `hasProdLocallyUniformlyOn_one_add` for sequences indexed by `β„•`. -/ lemma hasProdLocallyUniformlyOn_nat_one_add {f : β„• β†’ Ξ± β†’ R} (hK : IsOpen K) {u : β„• β†’ ℝ} (hu : Summable u) (h : βˆ€αΆ  n in atTop, βˆ€ x ∈ K, β€–f n xβ€– ≀ u n) (hcts : βˆ€ n, ContinuousOn (f n) K) : HasProdLocallyUniformlyOn (fun n x ↦ 1 + f n x) (fun x ↦ ∏' i, (1 + f i x)) K := hasProdLocallyUniformlyOn_one_add hK hu (Nat.cofinite_eq_atTop β–Έ h) hcts lemma multipliableLocallyUniformlyOn_nat_one_add {f : β„• β†’ Ξ± β†’ R} (hK : IsOpen K) {u : β„• β†’ ℝ} (hu : Summable u) (h : βˆ€αΆ  n in atTop, βˆ€ x ∈ K, β€–f n xβ€– ≀ u n) (hcts : βˆ€ n, ContinuousOn (f n) K) : MultipliableLocallyUniformlyOn (fun n x ↦ 1 + f n x) K := ⟨_, hasProdLocallyUniformlyOn_nat_one_add hK hu h hcts⟩ end LocallyCompactSpace end Summable
.lake/packages/mathlib/Mathlib/Analysis/NormedSpace/Extend.lean
import Mathlib.Analysis.Normed.Module.RCLike.Extend deprecated_module (since := "2025-09-18")