Quellcodebibliothek Statistik Leitseite products/Sources/formale Sprachen/Lean/Mathlib/Mathlib/Analysis/Analytic/     Datei vom 15.10.2026 mit Größe 56 kB image not shown  

Quelle  Constructions.lean   Sprache: Lean

 

/-
Copyright (c) 2023 Geoffrey Irving. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: David Loeffler, Geoffrey Irving, Stefan Kebekus
-/

module

public import Mathlib.Analysis.Analytic.Composition
public import Mathlib.Analysis.Analytic.Linear
public import Mathlib.Analysis.Analytic.OfScalars
public import Mathlib.Analysis.Normed.Ring.Units

import Mathlib.Analysis.Normed.Operator.Mul

/-!
# Various ways to combine analytic functions

We show that the following are analytic:

1. Cartesian products of analytic functions
2. Arithmetic on analytic functions: `mul`, `smul`, `inv`, `div`
3. Finite sums and products: `Finset.sum`, `Finset.prod`
-/


@[expose] public section

noncomputable section

open scoped Topology Ring
open Filter Asymptotics ENNReal NNReal

variable {α : Type*}
variable {�� : Type*} [NontriviallyNormedField ��]
variable {E F G H : Type*} [NormedAddCommGroup E] [NormedSpace �� E] [NormedAddCommGroup F]
  [NormedSpace �� F] [NormedAddCommGroup G] [NormedSpace �� G] [NormedAddCommGroup H]
  [NormedSpace �� H]

variable {A : Type*} [NormedRing A] [NormedAlgebra �� A]
variable {�� : Type*} [NormedDivisionRing ��] [NormedAlgebra �� ��]

/-!
### Constants are analytic
-/


theorem hasFPowerSeriesOnBall_const {c : F} {e : E} :
    HasFPowerSeriesOnBall (fun _ => c) (constFormalMultilinearSeries �� E c) e ⊤ := by
  refine ⟨by simp, WithTop.top_pos, fun _ => hasSum_single 0 fun n hn => ?_⟩
  simp [constFormalMultilinearSeries_apply_of_ne_zero hn]

theorem hasFPowerSeriesAt_const {c : F} {e : E} :
    HasFPowerSeriesAt (fun _ => c) (constFormalMultilinearSeries �� E c) e :=
  ⟨⊤, hasFPowerSeriesOnBall_const⟩

@[fun_prop]
theorem analyticAt_const {v : F} {x : E} : AnalyticAt �� (fun _ => v) x :=
  ⟨constFormalMultilinearSeries �� E v, hasFPowerSeriesAt_const⟩

/-- Special case of `analyticAt_const`, required for `fun_prop` to work. -/
@[fun_prop] theorem analyticAt_zero {x : E} :
    AnalyticAt �� (0 : E → F) x := analyticAt_const

@[fun_prop]
theorem analyticOnNhd_const {v : F} {s : Set E} : AnalyticOnNhd �� (fun _ => v) s :=
  fun _ _ => analyticAt_const

theorem analyticWithinAt_const {v : F} {s : Set E} {x : E} : AnalyticWithinAt �� (fun _ => v) s x :=
  analyticAt_const.analyticWithinAt

theorem analyticOn_const {v : F} {s : Set E} : AnalyticOn �� (fun _ => v) s :=
  analyticOnNhd_const.analyticOn

/-!
### Addition, negation, subtraction, scalar multiplication
-/


section

variable {f g : E → F} {pf pg : FormalMultilinearSeries �� E F} {s : Set E} {x : E} {r : ℝ≥0∞}
  {R : Type*} [NormedRing R] [Module R F] [IsBoundedSMul R F] [SMulCommClass �� R F] {c : R}

theorem HasFPowerSeriesWithinOnBall.add (hf : HasFPowerSeriesWithinOnBall f pf s x r)
    (hg : HasFPowerSeriesWithinOnBall g pg s x r) :
    HasFPowerSeriesWithinOnBall (f + g) (pf + pg) s x r :=
  { r_le := le_trans (le_min_iff.2 ⟨hf.r_le, hg.r_le⟩) (pf.min_radius_le_radius_add pg)
    r_pos := hf.r_pos
    hasSum := fun hy h'y => (hf.hasSum hy h'y).add (hg.hasSum hy h'y) }

theorem HasFPowerSeriesOnBall.add (hf : HasFPowerSeriesOnBall f pf x r)
    (hg : HasFPowerSeriesOnBall g pg x r) : HasFPowerSeriesOnBall (f + g) (pf + pg) x r :=
  { r_le := le_trans (le_min_iff.2 ⟨hf.r_le, hg.r_le⟩) (pf.min_radius_le_radius_add pg)
    r_pos := hf.r_pos
    hasSum := fun hy => (hf.hasSum hy).add (hg.hasSum hy) }

theorem HasFPowerSeriesWithinAt.add
    (hf : HasFPowerSeriesWithinAt f pf s x) (hg : HasFPowerSeriesWithinAt g pg s x) :
    HasFPowerSeriesWithinAt (f + g) (pf + pg) s x := by
  rcases (hf.eventually.and hg.eventually).exists with ⟨r, hr⟩
  exact ⟨r, hr.1.add hr.2⟩

theorem HasFPowerSeriesAt.add (hf : HasFPowerSeriesAt f pf x) (hg : HasFPowerSeriesAt g pg x) :
    HasFPowerSeriesAt (f + g) (pf + pg) x := by
  rcases (hf.eventually.and hg.eventually).exists with ⟨r, hr⟩
  exact ⟨r, hr.1.add hr.2⟩

theorem AnalyticWithinAt.add (hf : AnalyticWithinAt �� f s x) (hg : AnalyticWithinAt �� g s x) :
    AnalyticWithinAt �� (f + g) s x :=
  let ⟨_, hpf⟩ := hf
  let ⟨_, hqf⟩ := hg
  (hpf.add hqf).analyticWithinAt

@[to_fun (attr := fun_prop)]
theorem AnalyticAt.add (hf : AnalyticAt �� f x) (hg : AnalyticAt �� g x) :
    AnalyticAt �� (f + g) x :=
  let ⟨_, hpf⟩ := hf
  let ⟨_, hqf⟩ := hg
  (hpf.add hqf).analyticAt

theorem AnalyticOn.add (hf : AnalyticOn �� f s) (hg : AnalyticOn �� g s) :
    AnalyticOn �� (f + g) s :=
  fun z hz => (hf z hz).add (hg z hz)

@[to_fun (attr := fun_prop)]
theorem AnalyticOnNhd.add (hf : AnalyticOnNhd �� f s) (hg : AnalyticOnNhd �� g s) :
    AnalyticOnNhd �� (f + g) s :=
  fun z hz => (hf z hz).add (hg z hz)

theorem HasFPowerSeriesWithinOnBall.neg (hf : HasFPowerSeriesWithinOnBall f pf s x r) :
    HasFPowerSeriesWithinOnBall (-f) (-pf) s x r :=
  { r_le := by
      rw [pf.radius_neg]
      exact hf.r_le
    r_pos := hf.r_pos
    hasSum := fun hy h'y => (hf.hasSum hy h'y).neg }

theorem HasFPowerSeriesOnBall.neg (hf : HasFPowerSeriesOnBall f pf x r) :
    HasFPowerSeriesOnBall (-f) (-pf) x r :=
  { r_le := by
      rw [pf.radius_neg]
      exact hf.r_le
    r_pos := hf.r_pos
    hasSum := fun hy => (hf.hasSum hy).neg }

theorem HasFPowerSeriesWithinAt.neg (hf : HasFPowerSeriesWithinAt f pf s x) :
    HasFPowerSeriesWithinAt (-f) (-pf) s x :=
  let ⟨_, hrf⟩ := hf
  hrf.neg.hasFPowerSeriesWithinAt

theorem HasFPowerSeriesAt.neg (hf : HasFPowerSeriesAt f pf x) : HasFPowerSeriesAt (-f) (-pf) x :=
  let ⟨_, hrf⟩ := hf
  hrf.neg.hasFPowerSeriesAt

theorem AnalyticWithinAt.neg (hf : AnalyticWithinAt �� f s x) : AnalyticWithinAt �� (-f) s x :=
  let ⟨_, hpf⟩ := hf
  hpf.neg.analyticWithinAt

@[to_fun (attr := fun_prop)]
theorem AnalyticAt.neg (hf : AnalyticAt �� f x) : AnalyticAt �� (-f) x :=
  let ⟨_, hpf⟩ := hf
  hpf.neg.analyticAt

@[simp] lemma analyticAt_neg : AnalyticAt �� (-f) x ↔ AnalyticAt �� f x where
  mp hf := by simpa using hf.neg
  mpr := .neg

theorem AnalyticOn.neg (hf : AnalyticOn �� f s) : AnalyticOn �� (-f) s :=
  fun z hz ↦ (hf z hz).neg

@[to_fun (attr := fun_prop)]
theorem AnalyticOnNhd.neg (hf : AnalyticOnNhd �� f s) : AnalyticOnNhd �� (-f) s :=
  fun z hz ↦ (hf z hz).neg

theorem HasFPowerSeriesWithinOnBall.sub (hf : HasFPowerSeriesWithinOnBall f pf s x r)
    (hg : HasFPowerSeriesWithinOnBall g pg s x r) :
    HasFPowerSeriesWithinOnBall (f - g) (pf - pg) s x r := by
  simpa only [sub_eq_add_neg] using hf.add hg.neg

theorem HasFPowerSeriesOnBall.sub (hf : HasFPowerSeriesOnBall f pf x r)
    (hg : HasFPowerSeriesOnBall g pg x r) : HasFPowerSeriesOnBall (f - g) (pf - pg) x r := by
  simpa only [sub_eq_add_neg] using hf.add hg.neg

theorem HasFPowerSeriesWithinAt.sub
    (hf : HasFPowerSeriesWithinAt f pf s x) (hg : HasFPowerSeriesWithinAt g pg s x) :
    HasFPowerSeriesWithinAt (f - g) (pf - pg) s x := by
  simpa only [sub_eq_add_neg] using hf.add hg.neg

theorem HasFPowerSeriesAt.sub (hf : HasFPowerSeriesAt f pf x) (hg : HasFPowerSeriesAt g pg x) :
    HasFPowerSeriesAt (f - g) (pf - pg) x := by
  simpa only [sub_eq_add_neg] using hf.add hg.neg

theorem AnalyticWithinAt.sub (hf : AnalyticWithinAt �� f s x) (hg : AnalyticWithinAt �� g s x) :
    AnalyticWithinAt �� (f - g) s x := by
  simpa only [sub_eq_add_neg] using hf.add hg.neg

@[to_fun (attr := fun_prop)]
theorem AnalyticAt.sub (hf : AnalyticAt �� f x) (hg : AnalyticAt �� g x) :
    AnalyticAt �� (f - g) x := by
  simpa only [sub_eq_add_neg] using hf.add hg.neg

theorem AnalyticOn.sub (hf : AnalyticOn �� f s) (hg : AnalyticOn �� g s) :
    AnalyticOn �� (f - g) s :=
  fun z hz => (hf z hz).sub (hg z hz)

@[to_fun (attr := fun_prop)]
theorem AnalyticOnNhd.sub (hf : AnalyticOnNhd �� f s) (hg : AnalyticOnNhd �� g s) :
    AnalyticOnNhd �� (f - g) s :=
  fun z hz => (hf z hz).sub (hg z hz)

theorem HasFPowerSeriesWithinOnBall.const_smul (hf : HasFPowerSeriesWithinOnBall f pf s x r) :
    HasFPowerSeriesWithinOnBall (c • f) (c • pf) s x r where
  r_le := le_trans hf.r_le pf.radius_le_smul
  r_pos := hf.r_pos
  hasSum := fun hy h'y => (hf.hasSum hy h'y).const_smul _

theorem HasFPowerSeriesOnBall.const_smul (hf : HasFPowerSeriesOnBall f pf x r) :
    HasFPowerSeriesOnBall (c • f) (c • pf) x r where
  r_le := le_trans hf.r_le pf.radius_le_smul
  r_pos := hf.r_pos
  hasSum := fun hy => (hf.hasSum hy).const_smul _

theorem HasFPowerSeriesWithinAt.const_smul (hf : HasFPowerSeriesWithinAt f pf s x) :
    HasFPowerSeriesWithinAt (c • f) (c • pf) s x :=
  let ⟨_, hrf⟩ := hf
  hrf.const_smul.hasFPowerSeriesWithinAt

theorem HasFPowerSeriesAt.const_smul (hf : HasFPowerSeriesAt f pf x) :
    HasFPowerSeriesAt (c • f) (c • pf) x :=
  let ⟨_, hrf⟩ := hf
  hrf.const_smul.hasFPowerSeriesAt

theorem AnalyticWithinAt.const_smul (hf : AnalyticWithinAt �� f s x) :
    AnalyticWithinAt �� (c • f) s x :=
  let ⟨_, hpf⟩ := hf
  hpf.const_smul.analyticWithinAt

@[to_fun (attr := fun_prop)]
theorem AnalyticAt.const_smul (hf : AnalyticAt �� f x) : AnalyticAt �� (c • f) x :=
  let ⟨_, hpf⟩ := hf
  hpf.const_smul.analyticAt

@[to_fun]
theorem AnalyticOn.const_smul (hf : AnalyticOn �� f s) : AnalyticOn �� (c • f) s :=
  fun x hx ↦ (hf x hx).const_smul

@[to_fun (attr := fun_prop)]
theorem AnalyticOnNhd.const_smul (hf : AnalyticOnNhd �� f s) : AnalyticOnNhd �� (c • f) s :=
  fun x hx ↦ (hf x hx).const_smul

lemma AnalyticWithinAt.div_const {f : E → ��} (hf : AnalyticWithinAt �� f s x) {c : ��} :
    AnalyticWithinAt �� (f · / c) s x := by
  simpa [div_eq_mul_inv] using! hf.const_smul (R := ��ᵐᵒᵖ)

@[fun_prop]
lemma AnalyticAt.div_const {f : E → ��} (hf : AnalyticAt �� f x) {c : ��} :
    AnalyticAt �� (f · / c) x := by
  simpa [div_eq_mul_inv] using! hf.const_smul (R := ��ᵐᵒᵖ)

lemma AnalyticOn.div_const {f : E → ��} (hf : AnalyticOn �� f s) {c : ��} :
    AnalyticOn �� (f · / c) s := by
  simpa [div_eq_mul_inv] using! hf.const_smul (R := ��ᵐᵒᵖ)

@[fun_prop]
lemma AnalyticOnNhd.div_const {f : E → ��} (hf : AnalyticOnNhd �� f s) {c : ��} :
    AnalyticOnNhd �� (f · / c) s := by
  simpa [div_eq_mul_inv] using! hf.const_smul (R := ��ᵐᵒᵖ)

end

/-!
### Cartesian products are analytic
-/


/-- The radius of the Cartesian product of two formal series is the minimum of their radii. -/
lemma FormalMultilinearSeries.radius_prod_eq_min
    (p : FormalMultilinearSeries �� E F) (q : FormalMultilinearSeries �� E G) :
    (p.prod q).radius = min p.radius q.radius := by
  apply le_antisymm
  · refine ENNReal.le_of_forall_nnreal_lt fun r hr => ?_
    rw [le_min_iff]
    have := (p.prod q).isLittleO_one_of_lt_radius hr
    constructor
    all_goals
      apply FormalMultilinearSeries.le_radius_of_isBigO
      refine (isBigO_of_le _ fun n ↦ ?_).trans this.isBigO
      rw [norm_mul, norm_norm, norm_mul, norm_norm]
      refine mul_le_mul_of_nonneg_right ?_ (norm_nonneg _)
      rw [FormalMultilinearSeries.prod, ContinuousMultilinearMap.opNorm_prod]
    · apply le_max_left
    · apply le_max_right
  · refine ENNReal.le_of_forall_nnreal_lt fun r hr => ?_
    rw [lt_min_iff] at hr
    have := ((p.isLittleO_one_of_lt_radius hr.1).add
      (q.isLittleO_one_of_lt_radius hr.2)).isBigO
    refine (p.prod q).le_radius_of_isBigO ((isBigO_of_le _ fun n ↦ ?_).trans this)
    rw [norm_mul, norm_norm, ← add_mul, norm_mul]
    refine mul_le_mul_of_nonneg_right ?_ (norm_nonneg _)
    rw [FormalMultilinearSeries.prod, ContinuousMultilinearMap.opNorm_prod]
    refine (max_le_add_of_nonneg (norm_nonneg _) (norm_nonneg _)).trans ?_
    apply Real.le_norm_self

lemma HasFPowerSeriesWithinOnBall.prod {e : E} {f : E → F} {g : E → G} {r s : ℝ≥0∞} {t : Set E}
    {p : FormalMultilinearSeries �� E F} {q : FormalMultilinearSeries �� E G}
    (hf : HasFPowerSeriesWithinOnBall f p t e r) (hg : HasFPowerSeriesWithinOnBall g q t e s) :
    HasFPowerSeriesWithinOnBall (fun x ↦ (f x, g x)) (p.prod q) t e (min r s) where
  r_le := by
    rw [p.radius_prod_eq_min]
    exact min_le_min hf.r_le hg.r_le
  r_pos := lt_min hf.r_pos hg.r_pos
  hasSum := by
    intro y h'y hy
    simp_rw [FormalMultilinearSeries.prod, ContinuousMultilinearMap.prod_apply]
    refine (hf.hasSum h'y ?_).prodMk (hg.hasSum h'y ?_)
    · exact Metric.mem_eball.mpr (lt_of_lt_of_le hy (min_le_left _ _))
    · exact Metric.mem_eball.mpr (lt_of_lt_of_le hy (min_le_right _ _))

lemma HasFPowerSeriesOnBall.prod {e : E} {f : E → F} {g : E → G} {r s : ℝ≥0∞}
    {p : FormalMultilinearSeries �� E F} {q : FormalMultilinearSeries �� E G}
    (hf : HasFPowerSeriesOnBall f p e r) (hg : HasFPowerSeriesOnBall g q e s) :
    HasFPowerSeriesOnBall (fun x ↦ (f x, g x)) (p.prod q) e (min r s) := by
  rw [← hasFPowerSeriesWithinOnBall_univ] at hf hg ⊢
  exact hf.prod hg

lemma HasFPowerSeriesWithinAt.prod {e : E} {f : E → F} {g : E → G} {s : Set E}
    {p : FormalMultilinearSeries �� E F} {q : FormalMultilinearSeries �� E G}
    (hf : HasFPowerSeriesWithinAt f p s e) (hg : HasFPowerSeriesWithinAt g q s e) :
    HasFPowerSeriesWithinAt (fun x ↦ (f x, g x)) (p.prod q) s e := by
  rcases hf with ⟨_, hf⟩
  rcases hg with ⟨_, hg⟩
  exact ⟨_, hf.prod hg⟩

lemma HasFPowerSeriesAt.prod {e : E} {f : E → F} {g : E → G}
    {p : FormalMultilinearSeries �� E F} {q : FormalMultilinearSeries �� E G}
    (hf : HasFPowerSeriesAt f p e) (hg : HasFPowerSeriesAt g q e) :
    HasFPowerSeriesAt (fun x ↦ (f x, g x)) (p.prod q) e := by
  rcases hf with ⟨_, hf⟩
  rcases hg with ⟨_, hg⟩
  exact ⟨_, hf.prod hg⟩

/-- The Cartesian product of analytic functions is analytic. -/
lemma AnalyticWithinAt.prod {e : E} {f : E → F} {g : E → G} {s : Set E}
    (hf : AnalyticWithinAt �� f s e) (hg : AnalyticWithinAt �� g s e) :
    AnalyticWithinAt �� (fun x ↦ (f x, g x)) s e := by
  rcases hf with ⟨_, hf⟩
  rcases hg with ⟨_, hg⟩
  exact ⟨_, hf.prod hg⟩

/-- The Cartesian product of analytic functions is analytic. -/
@[fun_prop]
lemma AnalyticAt.prod {e : E} {f : E → F} {g : E → G}
    (hf : AnalyticAt �� f e) (hg : AnalyticAt �� g e) :
    AnalyticAt �� (fun x ↦ (f x, g x)) e := by
  rcases hf with ⟨_, hf⟩
  rcases hg with ⟨_, hg⟩
  exact ⟨_, hf.prod hg⟩

/-- The Cartesian product of analytic functions within a set is analytic. -/
lemma AnalyticOn.prod {f : E → F} {g : E → G} {s : Set E}
    (hf : AnalyticOn �� f s) (hg : AnalyticOn �� g s) :
    AnalyticOn �� (fun x ↦ (f x, g x)) s :=
  fun x hx ↦ (hf x hx).prod (hg x hx)

/-- The Cartesian product of analytic functions is analytic. -/
@[fun_prop]
lemma AnalyticOnNhd.prod {f : E → F} {g : E → G} {s : Set E}
    (hf : AnalyticOnNhd �� f s) (hg : AnalyticOnNhd �� g s) :
    AnalyticOnNhd �� (fun x ↦ (f x, g x)) s :=
  fun x hx ↦ (hf x hx).prod (hg x hx)

/-- `AnalyticAt.comp` for functions on product spaces -/
theorem AnalyticAt.comp₂ {h : F × G → H} {f : E → F} {g : E → G} {x : E}
    (ha : AnalyticAt �� h (f x, g x)) (fa : AnalyticAt �� f x)
    (ga : AnalyticAt �� g x) :
    AnalyticAt �� (fun x ↦ h (f x, g x)) x :=
  AnalyticAt.comp ha (fa.prod ga)

/-- `AnalyticWithinAt.comp` for functions on product spaces -/
theorem AnalyticWithinAt.comp₂ {h : F × G → H} {f : E → F} {g : E → G} {s : Set (F × G)}
    {t : Set E} {x : E}
    (ha : AnalyticWithinAt �� h s (f x, g x)) (fa : AnalyticWithinAt �� f t x)
    (ga : AnalyticWithinAt �� g t x) (hf : Set.MapsTo (fun y ↦ (f y, g y)) t s) :
    AnalyticWithinAt �� (fun x ↦ h (f x, g x)) t x :=
  AnalyticWithinAt.comp ha (fa.prod ga) hf

/-- `AnalyticAt.comp_analyticWithinAt` for functions on product spaces -/
theorem AnalyticAt.comp₂_analyticWithinAt
    {h : F × G → H} {f : E → F} {g : E → G} {x : E} {s : Set E}
    (ha : AnalyticAt �� h (f x, g x)) (fa : AnalyticWithinAt �� f s x)
    (ga : AnalyticWithinAt �� g s x) :
    AnalyticWithinAt �� (fun x ↦ h (f x, g x)) s x :=
  AnalyticAt.comp_analyticWithinAt ha (fa.prod ga)

/-- `AnalyticOnNhd.comp` for functions on product spaces -/
theorem AnalyticOnNhd.comp₂ {h : F × G → H} {f : E → F} {g : E → G} {s : Set (F × G)} {t : Set E}
    (ha : AnalyticOnNhd �� h s) (fa : AnalyticOnNhd �� f t) (ga : AnalyticOnNhd �� g t)
    (m : ∀ x, x ∈ t → (f x, g x) ∈ s) : AnalyticOnNhd �� (fun x ↦ h (f x, g x)) t :=
  fun _ xt ↦ (ha _ (m _ xt)).comp₂ (fa _ xt) (ga _ xt)

/-- `AnalyticOn.comp` for functions on product spaces -/
theorem AnalyticOn.comp₂ {h : F × G → H} {f : E → F} {g : E → G} {s : Set (F × G)}
    {t : Set E}
    (ha : AnalyticOn �� h s) (fa : AnalyticOn �� f t)
    (ga : AnalyticOn �� g t) (m : Set.MapsTo (fun y ↦ (f y, g y)) t s) :
    AnalyticOn �� (fun x ↦ h (f x, g x)) t :=
  fun x hx ↦ (ha _ (m hx)).comp₂ (fa x hx) (ga x hx) m

/-- Analytic functions on products are analytic in the first coordinate -/
theorem AnalyticAt.curry_left {f : E × F → G} {p : E × F} (fa : AnalyticAt �� f p) :
    AnalyticAt �� (fun x ↦ f (x, p.2)) p.1 :=
  AnalyticAt.comp₂ fa analyticAt_id analyticAt_const
alias AnalyticAt.along_fst := AnalyticAt.curry_left

theorem AnalyticWithinAt.curry_left
    {f : E × F → G} {s : Set (E × F)} {p : E × F} (fa : AnalyticWithinAt �� f s p) :
    AnalyticWithinAt �� (fun x ↦ f (x, p.2)) {x | (x, p.2) ∈ s} p.1 :=
  AnalyticWithinAt.comp₂ fa analyticWithinAt_id analyticWithinAt_const (fun _ hx ↦ hx)

/-- Analytic functions on products are analytic in the second coordinate -/
theorem AnalyticAt.curry_right {f : E × F → G} {p : E × F} (fa : AnalyticAt �� f p) :
    AnalyticAt �� (fun y ↦ f (p.1, y)) p.2 :=
  AnalyticAt.comp₂ fa analyticAt_const analyticAt_id
alias AnalyticAt.along_snd := AnalyticAt.curry_right

theorem AnalyticWithinAt.curry_right
    {f : E × F → G} {s : Set (E × F)} {p : E × F} (fa : AnalyticWithinAt �� f s p) :
    AnalyticWithinAt �� (fun y ↦ f (p.1, y)) {y | (p.1, y) ∈ s} p.2 :=
  AnalyticWithinAt.comp₂ fa analyticWithinAt_const analyticWithinAt_id (fun _ hx ↦ hx)

/-- Analytic functions on products are analytic in the first coordinate -/
theorem AnalyticOnNhd.curry_left {f : E × F → G} {s : Set (E × F)} {y : F}
    (fa : AnalyticOnNhd �� f s) :
    AnalyticOnNhd �� (fun x ↦ f (x, y)) {x | (x, y) ∈ s} :=
  fun x m ↦ (fa (x, y) m).curry_left
alias AnalyticOnNhd.along_fst := AnalyticOnNhd.curry_left

theorem AnalyticOn.curry_left
    {f : E × F → G} {s : Set (E × F)} {y : F} (fa : AnalyticOn �� f s) :
    AnalyticOn �� (fun x ↦ f (x, y)) {x | (x, y) ∈ s} :=
  fun x m ↦ (fa (x, y) m).curry_left

/-- Analytic functions on products are analytic in the second coordinate -/
theorem AnalyticOnNhd.curry_right {f : E × F → G} {x : E} {s : Set (E × F)}
    (fa : AnalyticOnNhd �� f s) :
    AnalyticOnNhd �� (fun y ↦ f (x, y)) {y | (x, y) ∈ s} :=
  fun y m ↦ (fa (x, y) m).curry_right
alias AnalyticOnNhd.along_snd := AnalyticOnNhd.curry_right

theorem AnalyticOn.curry_right
    {f : E × F → G} {x : E} {s : Set (E × F)} (fa : AnalyticOn �� f s) :
    AnalyticOn �� (fun y ↦ f (x, y)) {y | (x, y) ∈ s} :=
  fun y m ↦ (fa (x, y) m).curry_right

/-!
### Analyticity in Pi spaces

In this section, `f : Π i, E → Fm i` is a family of functions, i.e., each `f i` is a function,
from `E` to a space `Fm i`. We discuss whether the family as a whole is analytic as a function
of `x : E`, i.e., whether `x ↦ (f 1 x, ..., f n x)` is analytic from `E` to the product space
`Π i, Fm i`. This function is denoted either by `fun x ↦ (fun i ↦ f i x)`, or `fun x i ↦ f i x`,
or `fun x ↦ (f ⬝ x)`. We use the latter spelling in the statements, for readability purposes.
-/


section

variable {ι : Type*} [Fintype ι] {e : E} {Fm : ι → Type*}
    [∀ i, NormedAddCommGroup (Fm i)] [∀ i, NormedSpace �� (Fm i)]
    {f : Π i, E → Fm i} {s : Set E} {r : ℝ≥0∞}
    {p : Π i, FormalMultilinearSeries �� E (Fm i)}

lemma FormalMultilinearSeries.radius_pi_le (p : Π i, FormalMultilinearSeries �� E (Fm i)) (i : ι) :
    (FormalMultilinearSeries.pi p).radius ≤ (p i).radius := by
  apply le_of_forall_nnreal_lt (fun r' hr' ↦ ?_)
  obtain ⟨C, -, hC⟩ : ∃ C > 0, ∀ n, ‖pi p n‖ * ↑r' ^ n ≤ C := norm_mul_pow_le_of_lt_radius _ hr'
  apply le_radius_of_bound _ C (fun n ↦ ?_)
  apply le_trans _ (hC n)
  gcongr
  rw [pi, ContinuousMultilinearMap.opNorm_pi]
  exact norm_le_pi_norm (fun i ↦ p i n) i

lemma FormalMultilinearSeries.le_radius_pi (h : ∀ i, r ≤ (p i).radius) :
    r ≤ (FormalMultilinearSeries.pi p).radius := by
  apply le_of_forall_nnreal_lt (fun r' hr' ↦ ?_)
  have I i : ∃ C > 0, ∀ n, ‖p i n‖ * (r' : ℝ) ^ n ≤ C :=
    norm_mul_pow_le_of_lt_radius _ (hr'.trans_le (h i))
  choose C C_pos hC using I
  obtain ⟨D, D_nonneg, hD⟩ : ∃ D ≥ 0, ∀ i, C i ≤ D :=
    ⟨∑ i, C i, Finset.sum_nonneg (fun i _ ↦ (C_pos i).le),
      fun i ↦ Finset.single_le_sum (fun j _ ↦ (C_pos j).le) (Finset.mem_univ _)⟩
  apply le_radius_of_bound _ D (fun n ↦ ?_)
  rcases le_or_gt ((r' : ℝ) ^ n) 0 with hr' | hr'
  · exact le_trans (mul_nonpos_of_nonneg_of_nonpos (by positivity) hr') D_nonneg
  · simp only [pi]
    rw [← le_div_iff₀ hr', ContinuousMultilinearMap.opNorm_pi,
      pi_norm_le_iff_of_nonneg (by positivity)]
    intro i
    exact (le_div_iff₀ hr').2 ((hC i n).trans (hD i))

lemma FormalMultilinearSeries.radius_pi_eq_iInf :
    (FormalMultilinearSeries.pi p).radius = ⨅ i, (p i).radius := by
  refine le_antisymm (by simp [radius_pi_le]) ?_
  apply le_of_forall_nnreal_lt (fun r' hr' ↦ ?_)
  exact le_radius_pi (fun i ↦ le_iInf_iff.1 hr'.le i)

/-- If each function in a finite family has a power series within a ball, then so does the
family as a whole. Note that the positivity assumption on the radius is only needed when
the family is empty. -/

lemma HasFPowerSeriesWithinOnBall.pi
    (hf : ∀ i, HasFPowerSeriesWithinOnBall (f i) (p i) s e r) (hr : 0 < r) :
    HasFPowerSeriesWithinOnBall (fun x ↦ (f · x)) (FormalMultilinearSeries.pi p) s e r where
  r_le := by
    apply FormalMultilinearSeries.le_radius_pi (fun i ↦ ?_)
    exact (hf i).r_le
  r_pos := hr
  hasSum {_} m hy := Pi.hasSum.2 (fun i ↦ (hf i).hasSum m hy)

lemma hasFPowerSeriesWithinOnBall_pi_iff (hr : 0 < r) :
    HasFPowerSeriesWithinOnBall (fun x ↦ (f · x)) (FormalMultilinearSeries.pi p) s e r ↔
      ∀ i, HasFPowerSeriesWithinOnBall (f i) (p i) s e r where
  mp h i :=
    ⟨h.r_le.trans (FormalMultilinearSeries.radius_pi_le _ _), hr,
      fun m hy ↦ Pi.hasSum.1 (h.hasSum m hy) i⟩
  mpr h := .pi h hr

lemma HasFPowerSeriesOnBall.pi
    (hf : ∀ i, HasFPowerSeriesOnBall (f i) (p i) e r) (hr : 0 < r) :
    HasFPowerSeriesOnBall (fun x ↦ (f · x)) (FormalMultilinearSeries.pi p) e r := by
  simp_rw [← hasFPowerSeriesWithinOnBall_univ] at hf ⊢
  exact HasFPowerSeriesWithinOnBall.pi hf hr

lemma hasFPowerSeriesOnBall_pi_iff (hr : 0 < r) :
    HasFPowerSeriesOnBall (fun x ↦ (f · x)) (FormalMultilinearSeries.pi p) e r ↔
      ∀ i, HasFPowerSeriesOnBall (f i) (p i) e r := by
  simp_rw [← hasFPowerSeriesWithinOnBall_univ]
  exact hasFPowerSeriesWithinOnBall_pi_iff hr

lemma HasFPowerSeriesWithinAt.pi
    (hf : ∀ i, HasFPowerSeriesWithinAt (f i) (p i) s e) :
    HasFPowerSeriesWithinAt (fun x ↦ (f · x)) (FormalMultilinearSeries.pi p) s e := by
  have : ∀ᶠ r in ��[>] 0, ∀ i, HasFPowerSeriesWithinOnBall (f i) (p i) s e r :=
    eventually_all.mpr (fun i ↦ (hf i).eventually)
  obtain ⟨r, hr, r_pos⟩ := (this.and self_mem_nhdsWithin).exists
  exact ⟨r, HasFPowerSeriesWithinOnBall.pi hr r_pos⟩

lemma hasFPowerSeriesWithinAt_pi_iff :
    HasFPowerSeriesWithinAt (fun x ↦ (f · x)) (FormalMultilinearSeries.pi p) s e ↔
      ∀ i, HasFPowerSeriesWithinAt (f i) (p i) s e := by
  refine ⟨fun h i ↦ ?_, fun h ↦ .pi h⟩
  obtain ⟨r, hr⟩ := h
  exact ⟨r, (hasFPowerSeriesWithinOnBall_pi_iff hr.r_pos).1 hr i⟩

lemma HasFPowerSeriesAt.pi
    (hf : ∀ i, HasFPowerSeriesAt (f i) (p i) e) :
    HasFPowerSeriesAt (fun x ↦ (f · x)) (FormalMultilinearSeries.pi p) e := by
  simp_rw [← hasFPowerSeriesWithinAt_univ] at hf ⊢
  exact HasFPowerSeriesWithinAt.pi hf

lemma hasFPowerSeriesAt_pi_iff :
    HasFPowerSeriesAt (fun x ↦ (f · x)) (FormalMultilinearSeries.pi p) e ↔
      ∀ i, HasFPowerSeriesAt (f i) (p i) e := by
  simp_rw [← hasFPowerSeriesWithinAt_univ]
  exact hasFPowerSeriesWithinAt_pi_iff

lemma AnalyticWithinAt.pi (hf : ∀ i, AnalyticWithinAt �� (f i) s e) :
    AnalyticWithinAt �� (fun x ↦ (f · x)) s e := by
  choose p hp using hf
  exact ⟨FormalMultilinearSeries.pi p, HasFPowerSeriesWithinAt.pi hp⟩

lemma analyticWithinAt_pi_iff :
    AnalyticWithinAt �� (fun x ↦ (f · x)) s e ↔ ∀ i, AnalyticWithinAt �� (f i) s e := by
  refine ⟨fun h i ↦ ?_, fun h ↦ .pi h⟩
  exact ((ContinuousLinearMap.proj (R := ��) i).analyticAt _).comp_analyticWithinAt h

lemma AnalyticAt.pi (hf : ∀ i, AnalyticAt �� (f i) e) :
    AnalyticAt �� (fun x ↦ (f · x)) e := by
  simp_rw [← analyticWithinAt_univ] at hf ⊢
  exact AnalyticWithinAt.pi hf

lemma analyticAt_pi_iff :
    AnalyticAt �� (fun x ↦ (f · x)) e ↔ ∀ i, AnalyticAt �� (f i) e := by
  simp_rw [← analyticWithinAt_univ]
  exact analyticWithinAt_pi_iff

lemma AnalyticOn.pi (hf : ∀ i, AnalyticOn �� (f i) s) :
    AnalyticOn �� (fun x ↦ (f · x)) s :=
  fun x hx ↦ AnalyticWithinAt.pi (fun i ↦ hf i x hx)

lemma analyticOn_pi_iff :
    AnalyticOn �� (fun x ↦ (f · x)) s ↔ ∀ i, AnalyticOn �� (f i) s :=
  ⟨fun h i x hx ↦ analyticWithinAt_pi_iff.1 (h x hx) i, fun h ↦ .pi h⟩

lemma AnalyticOnNhd.pi (hf : ∀ i, AnalyticOnNhd �� (f i) s) :
    AnalyticOnNhd �� (fun x ↦ (f · x)) s :=
  fun x hx ↦ AnalyticAt.pi (fun i ↦ hf i x hx)

lemma analyticOnNhd_pi_iff :
    AnalyticOnNhd �� (fun x ↦ (f · x)) s ↔ ∀ i, AnalyticOnNhd �� (f i) s :=
  ⟨fun h i x hx ↦ analyticAt_pi_iff.1 (h x hx) i, fun h ↦ .pi h⟩

end

/-!
### Arithmetic on analytic functions
-/


/-- Scalar multiplication is analytic (jointly in both variables). The statement is a little
pedantic to allow towers of field extensions. -/

@[fun_prop]
lemma analyticAt_smul [Module A E] [IsBoundedSMul A E] [IsScalarTower �� A E] (z : A × E) :
    AnalyticAt �� (fun x : A × E ↦ x.1 • x.2) z :=
  (ContinuousLinearMap.lsmul �� A).analyticAt_bilinear z

/-- Multiplication in a normed algebra over `��` is analytic. -/
@[fun_prop]
lemma analyticAt_mul (z : A × A) : AnalyticAt �� (fun x : A × A ↦ x.1 * x.2) z :=
  analyticAt_smul z

/-- Scalar multiplication of one analytic function by another. -/
lemma AnalyticWithinAt.smul [Module A F] [IsBoundedSMul A F] [IsScalarTower �� A F]
    {f : E → A} {g : E → F} {s : Set E} {z : E}
    (hf : AnalyticWithinAt �� f s z) (hg : AnalyticWithinAt �� g s z) :
    AnalyticWithinAt �� (fun x ↦ f x • g x) s z :=
  (analyticAt_smul _).comp₂_analyticWithinAt hf hg

/-- Scalar multiplication of one analytic function by another. -/
@[to_fun (attr := fun_prop)]
lemma AnalyticAt.smul [Module A F] [IsBoundedSMul A F] [IsScalarTower �� A F] {f : E → A}
    {g : E → F} {z : E} (hf : AnalyticAt �� f z) (hg : AnalyticAt �� g z) :
    AnalyticAt �� (f • g) z :=
  (analyticAt_smul _).comp₂ hf hg

/-- Scalar multiplication of one analytic function by another. -/
lemma AnalyticOn.smul [Module A F] [IsBoundedSMul A F] [IsScalarTower �� A F]
    {f : E → A} {g : E → F} {s : Set E}
    (hf : AnalyticOn �� f s) (hg : AnalyticOn �� g s) :
    AnalyticOn �� (fun x ↦ f x • g x) s :=
  fun _ m ↦ (hf _ m).smul (hg _ m)

/-- Scalar multiplication of one analytic function by another. -/
@[fun_prop]
lemma AnalyticOnNhd.smul [Module A F] [IsBoundedSMul A F] [IsScalarTower �� A F]
    {f : E → A} {g : E → F} {s : Set E} (hf : AnalyticOnNhd �� f s) (hg : AnalyticOnNhd �� g s) :
    AnalyticOnNhd �� (fun x ↦ f x • g x) s :=
  fun _ m ↦ (hf _ m).smul (hg _ m)

/-- Multiplication of analytic functions (valued in a normed `��`-algebra) is analytic. -/
lemma AnalyticWithinAt.mul {f g : E → A} {s : Set E} {z : E}
    (hf : AnalyticWithinAt �� f s z) (hg : AnalyticWithinAt �� g s z) :
    AnalyticWithinAt �� (fun x ↦ f x * g x) s z :=
  (analyticAt_mul _).comp₂_analyticWithinAt hf hg

/-- Multiplication of analytic functions (valued in a normed `��`-algebra) is analytic. -/
@[to_fun (attr := fun_prop)]
lemma AnalyticAt.mul {f g : E → A} {z : E} (hf : AnalyticAt �� f z) (hg : AnalyticAt �� g z) :
    AnalyticAt �� (f * g) z :=
  hf.smul hg

/-- Multiplication of analytic functions (valued in a normed `��`-algebra) is analytic. -/
lemma AnalyticOn.mul {f g : E → A} {s : Set E}
    (hf : AnalyticOn �� f s) (hg : AnalyticOn �� g s) :
    AnalyticOn �� (fun x ↦ f x * g x) s :=
  hf.smul hg

/-- Multiplication of analytic functions (valued in a normed `��`-algebra) is analytic. -/
@[fun_prop]
lemma AnalyticOnNhd.mul {f g : E → A} {s : Set E}
    (hf : AnalyticOnNhd �� f s) (hg : AnalyticOnNhd �� g s) :
    AnalyticOnNhd �� (fun x ↦ f x * g x) s :=
  hf.smul hg

/-- Powers of analytic functions (into a normed `��`-algebra) are analytic. -/
@[to_fun]
lemma AnalyticWithinAt.pow {f : E → A} {z : E} {s : Set E} (hf : AnalyticWithinAt �� f s z)
    (n : ℕ) :
    AnalyticWithinAt �� (f ^ n) s z := by
  induction n with
  | zero =>
    simp only [pow_zero]
    apply analyticWithinAt_const
  | succ m hm =>
    simp only [pow_succ]
    exact hm.mul hf

/-- Powers of analytic functions (into a normed `��`-algebra) are analytic. -/
@[to_fun (attr := fun_prop)]
lemma AnalyticAt.pow {f : E → A} {z : E} (hf : AnalyticAt �� f z) (n : ℕ) :
    AnalyticAt �� (f ^ n) z := by
  rw [← analyticWithinAt_univ] at hf ⊢
  exact hf.pow n

/-- Powers of analytic functions (into a normed `��`-algebra) are analytic. -/
@[to_fun]
lemma AnalyticOn.pow {f : E → A} {s : Set E} (hf : AnalyticOn �� f s) (n : ℕ) :
    AnalyticOn �� (f ^ n) s :=
  fun _ m ↦ (hf _ m).pow n

/-- Powers of analytic functions (into a normed `��`-algebra) are analytic. -/
@[to_fun (attr := fun_prop)]
lemma AnalyticOnNhd.pow {f : E → A} {s : Set E} (hf : AnalyticOnNhd �� f s) (n : ℕ) :
    AnalyticOnNhd �� (f ^ n) s :=
  fun _ m ↦ (hf _ m).pow n

/-- ZPowers of analytic functions (into a normed division algebra over `��`) are analytic if the
exponent is nonnegative. -/

@[to_fun]
lemma AnalyticWithinAt.zpow_nonneg {f : E → ��} {z : E} {s : Set E} {n : ℤ}
    (hf : AnalyticWithinAt �� f s z) (hn : 0 ≤ n) :
    AnalyticWithinAt �� (f ^ n) s z := by
  simpa [← zpow_natCast, hn] using hf.pow n.toNat

/-- ZPowers of analytic functions (into a normed division algebra over `��`) are analytic if the
exponent is nonnegative. -/

@[to_fun]
lemma AnalyticAt.zpow_nonneg {f : E → ��} {z : E} {n : ℤ} (hf : AnalyticAt �� f z) (hn : 0 ≤ n) :
    AnalyticAt �� (f ^ n) z := by
  simpa [← zpow_natCast, hn] using hf.pow n.toNat

/-- ZPowers of analytic functions (into a normed division algebra over `��`) are analytic if the
exponent is nonnegative. -/

@[to_fun]
lemma AnalyticOn.zpow_nonneg {f : E → ��} {s : Set E} {n : ℤ} (hf : AnalyticOn �� f s)
    (hn : 0 ≤ n) :
    AnalyticOn �� (f ^ n) s := by
  simpa [← zpow_natCast, hn] using hf.pow n.toNat

/-- ZPowers of analytic functions (into a normed division algebra over `��`) are analytic if the
exponent is nonnegative. -/

@[to_fun (attr := fun_prop)]
lemma AnalyticOnNhd.zpow_nonneg {f : E → ��} {s : Set E} {n : ℤ} (hf : AnalyticOnNhd �� f s)
    (hn : 0 ≤ n) :
    AnalyticOnNhd �� (f ^ n) s := by
  simp_rw [(Eq.symm (Int.toNat_of_nonneg hn) : n = OfNat.ofNat n.toNat), zpow_ofNat]
  apply pow hf

/-!
### Composition with a linear map
-/


section compContinuousLinearMap

variable {u : E →L[��] F} {f : F → G} {pf : FormalMultilinearSeries �� F G} {s : Set F} {x : E}
  {r : ℝ≥0∞}

theorem HasFPowerSeriesWithinOnBall.compContinuousLinearMap
    (hf : HasFPowerSeriesWithinOnBall f pf s (u x) r) :
    HasFPowerSeriesWithinOnBall (f ∘ u) (pf.compContinuousLinearMap u) (u ⁻¹' s) x (r / ‖u‖ₑ) where
  r_le := by
    calc
      _ ≤ pf.radius / ‖u‖ₑ := by
        gcongr
        exact hf.r_le
      _ ≤ _ := pf.div_le_radius_compContinuousLinearMap _
  r_pos := by
    simp only [ENNReal.div_pos_iff, ne_eq, eNorm_ne_top, not_false_eq_true, and_true]
    exact pos_iff_ne_zero.mp hf.r_pos
  hasSum hy1 hy2 := by
    convert! hf.hasSum _ _
    · simp
    · simp only [Set.mem_insert_iff, add_eq_left, Set.mem_preimage, map_add] at hy1 ⊢
      rcases hy1 with (hy1 | hy1) <;> simp [hy1]
    · simp only [Metric.eball, edist_zero_right, Set.mem_ofPred_eq] at hy2 ⊢
      exact lt_of_le_of_lt (ContinuousLinearMap.le_opENorm _ _) (mul_lt_of_lt_div' hy2)

theorem HasFPowerSeriesOnBall.compContinuousLinearMap (hf : HasFPowerSeriesOnBall f pf (u x) r) :
    HasFPowerSeriesOnBall (f ∘ u) (pf.compContinuousLinearMap u) x (r / ‖u‖ₑ) := by
  rw [← hasFPowerSeriesWithinOnBall_univ] at hf ⊢
  exact hf.compContinuousLinearMap

theorem HasFPowerSeriesAt.compContinuousLinearMap (hf : HasFPowerSeriesAt f pf (u x)) :
    HasFPowerSeriesAt (f ∘ u) (pf.compContinuousLinearMap u) x :=
  let ⟨r, hr⟩ := hf
  ⟨r / ‖u‖ₑ, hr.compContinuousLinearMap⟩

theorem HasFPowerSeriesWithinAt.compContinuousLinearMap
    (hf : HasFPowerSeriesWithinAt f pf s (u x)) :
    HasFPowerSeriesWithinAt (f ∘ u) (pf.compContinuousLinearMap u) (u ⁻¹' s) x :=
  let ⟨r, hr⟩ := hf
  ⟨r / ‖u‖ₑ, hr.compContinuousLinearMap⟩

theorem AnalyticAt.compContinuousLinearMap (hf : AnalyticAt �� f (u x)) :
    AnalyticAt �� (f ∘ u) x :=
  let ⟨p, hp⟩ := hf
  ⟨p.compContinuousLinearMap u, hp.compContinuousLinearMap⟩

theorem AnalyticAtWithin.compContinuousLinearMap (hf : AnalyticWithinAt �� f s (u x)) :
    AnalyticWithinAt �� (f ∘ u) (u ⁻¹' s) x :=
  let ⟨p, hp⟩ := hf
  ⟨p.compContinuousLinearMap u, hp.compContinuousLinearMap⟩

theorem AnalyticOn.compContinuousLinearMap (hf : AnalyticOn �� f s) :
    AnalyticOn �� (f ∘ u) (u ⁻¹' s) := fun x hx =>
  AnalyticAtWithin.compContinuousLinearMap (hf (u x) hx)

theorem AnalyticOnNhd.compContinuousLinearMap (hf : AnalyticOnNhd �� f s) :
    AnalyticOnNhd �� (f ∘ u) (u ⁻¹' s) := fun x hx =>
  AnalyticAt.compContinuousLinearMap (hf (u x) hx)

end compContinuousLinearMap

/-!
### Restriction of scalars
-/


section

variable {��' : Type*} [NontriviallyNormedField ��'] [NormedAlgebra �� ��']
  [NormedSpace ��' E] [IsScalarTower �� ��' E]
  [NormedSpace ��' F] [IsScalarTower �� ��' F]
  {f : E → F} {p : FormalMultilinearSeries ��' E F} {x : E} {s : Set E} {r : ℝ≥0∞}

lemma HasFPowerSeriesWithinOnBall.restrictScalars (hf : HasFPowerSeriesWithinOnBall f p s x r) :
    HasFPowerSeriesWithinOnBall f (p.restrictScalars ��) s x r :=
  ⟨hf.r_le.trans (FormalMultilinearSeries.radius_le_of_le (fun n ↦ by simp)), hf.r_pos, hf.hasSum⟩

lemma HasFPowerSeriesOnBall.restrictScalars (hf : HasFPowerSeriesOnBall f p x r) :
    HasFPowerSeriesOnBall f (p.restrictScalars ��) x r :=
  ⟨hf.r_le.trans (FormalMultilinearSeries.radius_le_of_le (fun n ↦ by simp)), hf.r_pos, hf.hasSum⟩

lemma HasFPowerSeriesWithinAt.restrictScalars (hf : HasFPowerSeriesWithinAt f p s x) :
    HasFPowerSeriesWithinAt f (p.restrictScalars ��) s x := by
  rcases hf with ⟨r, hr⟩
  exact ⟨r, hr.restrictScalars⟩

lemma HasFPowerSeriesAt.restrictScalars (hf : HasFPowerSeriesAt f p x) :
    HasFPowerSeriesAt f (p.restrictScalars ��) x := by
  rcases hf with ⟨r, hr⟩
  exact ⟨r, hr.restrictScalars⟩

lemma AnalyticWithinAt.restrictScalars (hf : AnalyticWithinAt ��' f s x) :
    AnalyticWithinAt �� f s x := by
  rcases hf with ⟨p, hp⟩
  exact ⟨p.restrictScalars ��, hp.restrictScalars⟩

lemma AnalyticAt.restrictScalars (hf : AnalyticAt ��' f x) :
    AnalyticAt �� f x := by
  rcases hf with ⟨p, hp⟩
  exact ⟨p.restrictScalars ��, hp.restrictScalars⟩

lemma AnalyticOn.restrictScalars (hf : AnalyticOn ��' f s) :
    AnalyticOn �� f s :=
  fun x hx ↦ (hf x hx).restrictScalars

lemma AnalyticOnNhd.restrictScalars (hf : AnalyticOnNhd ��' f s) :
    AnalyticOnNhd �� f s :=
  fun x hx ↦ (hf x hx).restrictScalars

end


/-!
### Inversion is analytic
-/


section Geometric
variable (�� A)

/-- The geometric series `1 + x + x ^ 2 + ...` as a `FormalMultilinearSeries`. -/
def formalMultilinearSeries_geometric : FormalMultilinearSeries �� A A :=
  fun n ↦ ContinuousMultilinearMap.mkPiAlgebraFin �� n A

/-- The geometric series as an `ofScalars` series. -/
theorem formalMultilinearSeries_geometric_eq_ofScalars :
    formalMultilinearSeries_geometric �� A =
      FormalMultilinearSeries.ofScalars A fun _ ↦ (1 : ��) := by
  simp_rw [FormalMultilinearSeries.ext_iff, FormalMultilinearSeries.ofScalars,
    formalMultilinearSeries_geometric, one_smul, implies_true]

lemma formalMultilinearSeries_geometric_apply_norm_le (n : ℕ) :
    ‖formalMultilinearSeries_geometric �� A n‖ ≤ max 1 ‖(1 : A)‖ :=
  ContinuousMultilinearMap.norm_mkPiAlgebraFin_le

lemma formalMultilinearSeries_geometric_apply_norm [NormOneClass A] (n : ℕ) :
    ‖formalMultilinearSeries_geometric �� A n‖ = 1 :=
  ContinuousMultilinearMap.norm_mkPiAlgebraFin

lemma one_le_formalMultilinearSeries_geometric_radius :
    1 ≤ (formalMultilinearSeries_geometric �� A).radius := by
  convert
    formalMultilinearSeries_geometric_eq_ofScalars �� A ▸
      FormalMultilinearSeries.inv_le_ofScalars_radius_of_tendsto A _ (r := 1) (by simp)
  simp

lemma formalMultilinearSeries_geometric_radius [NormOneClass A] :
    (formalMultilinearSeries_geometric �� A).radius = 1 :=
  formalMultilinearSeries_geometric_eq_ofScalars �� A ▸
    FormalMultilinearSeries.ofScalars_radius_eq_of_tendsto A _ one_ne_zero (by simp)

lemma hasFPowerSeriesOnBall_inverse_one_sub [HasSummableGeomSeries A] :
    HasFPowerSeriesOnBall (fun x : A ↦ (1 - x)⁻¹ʳ)
      (formalMultilinearSeries_geometric �� A) 0 1 := by
  constructor
  · exact one_le_formalMultilinearSeries_geometric_radius �� A
  · exact one_pos
  · intro y hy
    simp only [Metric.mem_eball, edist_dist, dist_zero_right, ofReal_lt_one] at hy
    simp only [zero_add, NormedRing.inverse_one_sub _ hy, Units.oneSub, Units.inv_mk,
      formalMultilinearSeries_geometric, ContinuousMultilinearMap.mkPiAlgebraFin_apply,
      List.ofFn_const, List.prod_replicate]
    exact (summable_geometric_of_norm_lt_one hy).hasSum

@[fun_prop]
lemma analyticAt_inverse_one_sub [HasSummableGeomSeries A] :
    AnalyticAt �� (fun x : A ↦ (1 - x)⁻¹ʳ) 0 :=
  ⟨_, ⟨_, hasFPowerSeriesOnBall_inverse_one_sub �� A⟩⟩

/-- The alternating geometric series `1 - x + x ^ 2 - ...` as a `FormalMultilinearSeries`. -/
def alternatingGeometricSeries : FormalMultilinearSeries �� A A :=
  .ofScalars A fun n ↦ (-1 : ��) ^ n

lemma alternatingGeometricSeries_eq_formalMultilinearSeries_geometric_comp_neg :
    alternatingGeometricSeries �� A =
    (formalMultilinearSeries_geometric �� A).compContinuousLinearMap
      (-ContinuousLinearMap.id �� A) := by
  simp [formalMultilinearSeries_geometric_eq_ofScalars, alternatingGeometricSeries,
    FormalMultilinearSeries.ofScalars_comp_neg_id]

lemma alternatingGeometricSeries_apply_norm_le (n : ℕ) :
    ‖alternatingGeometricSeries �� A n‖ ≤ max 1 ‖(1 : A)‖ := by
  simpa [alternatingGeometricSeries] using
    ContinuousMultilinearMap.norm_mkPiAlgebraFin_le

lemma alternatingGeometricSeries_apply_norm [NormOneClass A] (n : ℕ) :
    ‖alternatingGeometricSeries �� A n‖ = 1 := by
  simp [alternatingGeometricSeries]

lemma one_le_alternatingGeometricSeries_radius [Nontrivial A] :
    1 ≤ (alternatingGeometricSeries �� A).radius := by
  simpa only [FormalMultilinearSeries.radius_compNeg,
    alternatingGeometricSeries_eq_formalMultilinearSeries_geometric_comp_neg]
    using one_le_formalMultilinearSeries_geometric_radius �� A

lemma alternatingGeometricSeries_radius [NormOneClass A] :
    (alternatingGeometricSeries �� A).radius = 1 :=
  FormalMultilinearSeries.ofScalars_radius_eq_of_tendsto A _ one_ne_zero (by simp)

lemma hasFPowerSeriesOnBall_inverse_one_add [HasSummableGeomSeries A] [Nontrivial A] :
    HasFPowerSeriesOnBall (fun x : A ↦ Ring.inverse (1 + x))
      (alternatingGeometricSeries �� A) 0 1 := by
  rw [alternatingGeometricSeries_eq_formalMultilinearSeries_geometric_comp_neg]
  convert_to HasFPowerSeriesOnBall ((fun x ↦ Ring.inverse (1 - x)) ∘ (-ContinuousLinearMap.id �� A))
    ((formalMultilinearSeries_geometric �� A).compContinuousLinearMap (-ContinuousLinearMap.id �� A))
    0 1
  · ext; simp
  convert HasFPowerSeriesOnBall.compContinuousLinearMap _ (r := 1)
  · simp [← ofReal_norm]
  · simpa using (hasFPowerSeriesOnBall_inverse_one_sub �� A)

@[fun_prop]
lemma analyticAt_inverse_one_add [HasSummableGeomSeries A] [Nontrivial A] :
    AnalyticAt �� (fun x : A ↦ Ring.inverse (1 + x)) 0 :=
  ⟨_, ⟨_, hasFPowerSeriesOnBall_inverse_one_add �� A⟩⟩

end Geometric

/-- If `A` is a normed algebra over `��` with summable geometric series, then inversion on `A` is
analytic at any unit. -/

@[fun_prop]
lemma analyticAt_inverse [HasSummableGeomSeries A] (z : Aˣ) :
    AnalyticAt �� Ring.inverse (z : A) := by
  rcases subsingleton_or_nontrivial A with hA | hA
  · convert analyticAt_const (v := (0 : A))
  · let f1 : A → A := fun a ↦ a * z.inv
    let f2 : A → A := fun b ↦ (1 - b)⁻¹ʳ
    let f3 : A → A := fun c ↦ 1 - z.inv * c
    have feq : ∀ᶠ y in �� (z : A), (f1 ∘ f2 ∘ f3) y = y⁻¹ʳ := by
      have : Metric.ball (z : A) (‖(↑z⁻¹ : A)‖⁻¹) ∈ �� (z : A) := by
        apply Metric.ball_mem_nhds
        simp
      filter_upwards [this] with y hy
      simp only [Metric.mem_ball, dist_eq_norm] at hy
      have : y = Units.ofNearby z y hy := rfl
      rw [this, Eq.comm]
      simp only [Ring.inverse_unit, Function.comp_apply]
      simp only [Units.ofNearby, Units.add, mul_sub, Units.inv_mul, neg_sub, add_sub_cancel,
        mul_inv_rev, Units.val_mul, Units.val_inv_copy, Units.inv_eq_val_inv, Units.val_copy,
        _root_.sub_sub_cancel, Units.mul_left_inj, f1, f2, f3]
      rw [← Ring.inverse_unit]
      congr
      simp
    apply AnalyticAt.congr _ feq
    apply (analyticAt_id.mul analyticAt_const).comp
    apply AnalyticAt.comp
    · simp only [Units.inv_eq_val_inv, Units.inv_mul, sub_self, f2, f3]
      exact analyticAt_inverse_one_sub �� A
    · exact analyticAt_const.sub (analyticAt_const.mul analyticAt_id)

lemma analyticOnNhd_inverse [HasSummableGeomSeries A] :
    AnalyticOnNhd �� Ring.inverse {x : A | IsUnit x} :=
  fun _ hx ↦ analyticAt_inverse (IsUnit.unit hx)

variable (�� ��) in
lemma hasFPowerSeriesOnBall_inv_one_sub :
    HasFPowerSeriesOnBall (fun x : �� ↦ (1 - x)⁻¹) (formalMultilinearSeries_geometric �� ��) 0 1 := by
  convert! hasFPowerSeriesOnBall_inverse_one_sub �� ��
  exact Ring.inverse_eq_inv'.symm

variable (��) in
@[fun_prop]
lemma analyticAt_inv_one_sub : AnalyticAt �� (fun x : �� ↦ (1 - x)⁻¹) 0 :=
  ⟨_, ⟨_, hasFPowerSeriesOnBall_inv_one_sub �� ��⟩⟩

variable (�� ��) in
lemma hasFPowerSeriesOnBall_inv_one_add :
    HasFPowerSeriesOnBall (fun x : �� ↦ (1 + x)⁻¹) (alternatingGeometricSeries �� ��) 0 1 := by
  convert! hasFPowerSeriesOnBall_inverse_one_add �� ��
  exact Ring.inverse_eq_inv'.symm

variable (��) in
@[fun_prop]
lemma analyticAt_inv_one_add : AnalyticAt �� (fun x : �� ↦ (1 + x)⁻¹) 0 :=
  ⟨_, ⟨_, hasFPowerSeriesOnBall_inv_one_add �� ��⟩⟩

/-- If `��` is a normed field extension of `��`, then the inverse map `�� → ��` is `��`-analytic
away from 0. -/

@[fun_prop]
lemma analyticAt_inv {z : ��} (hz : z ≠ 0) : AnalyticAt �� Inv.inv z := by
  convert! analyticAt_inverse (�� := ��) (Units.mk0 _ hz)
  exact Ring.inverse_eq_inv'.symm

/-- `x⁻¹` is analytic away from zero -/
lemma analyticOnNhd_inv : AnalyticOnNhd �� (fun z ↦ z⁻¹) {z : �� | z ≠ 0} := by
  intro z m; exact analyticAt_inv m

lemma analyticOn_inv : AnalyticOn �� (fun z ↦ z⁻¹) {z : �� | z ≠ 0} :=
  analyticOnNhd_inv.analyticOn

/-- `(f x)⁻¹` is analytic away from `f x = 0` -/
@[to_fun]
theorem AnalyticWithinAt.inv {f : E → ��} {x : E} {s : Set E} (fa : AnalyticWithinAt �� f s x)
    (f0 : f x ≠ 0) :
    AnalyticWithinAt �� f⁻¹ s x :=
  (analyticAt_inv f0).comp_analyticWithinAt fa

/-- `(f x)⁻¹` is analytic away from `f x = 0` -/
@[to_fun (attr := fun_prop)]
theorem AnalyticAt.inv {f : E → ��} {x : E} (fa : AnalyticAt �� f x) (f0 : f x ≠ 0) :
    AnalyticAt �� f⁻¹ x :=
  (analyticAt_inv f0).comp fa

/-- `(f x)⁻¹` is analytic away from `f x = 0` -/
@[to_fun]
theorem AnalyticOn.inv {f : E → ��} {s : Set E} (fa : AnalyticOn �� f s) (f0 : ∀ x ∈ s, f x ≠ 0) :
    AnalyticOn �� f⁻¹ s :=
  fun x m ↦ (fa x m).inv (f0 x m)

/-- `(f x)⁻¹` is analytic away from `f x = 0` -/
@[to_fun (attr := fun_prop)]
theorem AnalyticOnNhd.inv {f : E → ��} {s : Set E} (fa : AnalyticOnNhd �� f s)
    (f0 : ∀ x ∈ s, f x ≠ 0) :
    AnalyticOnNhd �� f⁻¹ s :=
  fun x m ↦ (fa x m).inv (f0 x m)

/-- ZPowers of analytic functions (into a normed field over `��`) are analytic away from the zeros.
-/

@[to_fun]
lemma AnalyticWithinAt.zpow {f : E → ��} {z : E} {s : Set E} {n : ℤ}
    (h₁f : AnalyticWithinAt �� f s z) (h₂f : f z ≠ 0) :
    AnalyticWithinAt �� (f ^ n) s z := by
  by_cases hn : 0 ≤ n
  · exact zpow_nonneg h₁f hn
  · rw [(Int.eq_neg_comm.mp rfl : n = -(-n))]
    conv => arg 2; intro x; rw [zpow_neg]
    exact (h₁f.zpow_nonneg (by linarith)).inv (zpow_ne_zero (-n) h₂f)

/-- ZPowers of analytic functions (into a normed field over `��`) are analytic away from the zeros.
-/

@[to_fun]
lemma AnalyticAt.zpow {f : E → ��} {z : E} {n : ℤ} (h₁f : AnalyticAt �� f z) (h₂f : f z ≠ 0) :
    AnalyticAt �� (f ^ n) z := by
  by_cases hn : 0 ≤ n
  · exact zpow_nonneg h₁f hn
  · rw [(Int.eq_neg_comm.mp rfl : n = -(-n))]
    conv => arg 2; intro x; rw [zpow_neg]
    exact (h₁f.zpow_nonneg (by linarith)).inv (zpow_ne_zero (-n) h₂f)

/-- ZPowers of analytic functions (into a normed field over `��`) are analytic away from the zeros.
-/

@[to_fun]
lemma AnalyticOn.zpow {f : E → ��} {s : Set E} {n : ℤ} (h₁f : AnalyticOn �� f s)
    (h₂f : ∀ z ∈ s, f z ≠ 0) :
    AnalyticOn �� (f ^ n) s :=
  fun z hz ↦ (h₁f z hz).zpow (h₂f z hz)

/-- ZPowers of analytic functions (into a normed field over `��`) are analytic away from the zeros.
-/

@[to_fun (attr := fun_prop)]
lemma AnalyticOnNhd.zpow {f : E → ��} {s : Set E} {n : ℤ} (h₁f : AnalyticOnNhd �� f s)
    (h₂f : ∀ z ∈ s, f z ≠ 0) :
    AnalyticOnNhd �� (f ^ n) s :=
  fun z hz ↦ (h₁f z hz).zpow (h₂f z hz)

/-- A function is analytic at a point iff it is analytic after scalar
  multiplication with a non-vanishing analytic function. -/

theorem analyticAt_iff_analytic_fun_smul [Module �� F] [IsBoundedSMul �� F] [IsScalarTower �� �� F]
    {f : E → ��} {g : E → F} {z : E} (h₁f : AnalyticAt �� f z) (h₂f : f z ≠ 0) :
    AnalyticAt �� g z ↔ AnalyticAt �� (fun z ↦ f z • g z) z := by
  constructor
  · exact fun a ↦ h₁f.smul a
  · intro hprod
    rw [analyticAt_congr (g := (f⁻¹ • f) • g), smul_assoc]
    · exact (h₁f.inv h₂f).fun_smul hprod
    · filter_upwards [h₁f.continuousAt.preimage_mem_nhds (compl_singleton_mem_nhds_iff.2 h₂f)]
      intro y hy
      rw [Set.preimage_compl, Set.mem_compl_iff, Set.mem_preimage, Set.mem_singleton_iff] at hy
      simp [hy]

/-- A function is analytic at a point iff it is analytic after scalar
  multiplication with a non-vanishing analytic function. -/

theorem analyticAt_iff_analytic_smul [Module �� F] [IsBoundedSMul �� F] [IsScalarTower �� �� F]
    {f : E → ��} {g : E → F} {z : E} (h₁f : AnalyticAt �� f z) (h₂f : f z ≠ 0) :
    AnalyticAt �� g z ↔ AnalyticAt �� (f • g) z :=
  analyticAt_iff_analytic_fun_smul h₁f h₂f

/-- A function is analytic at a point iff it is analytic after multiplication
with a non-vanishing analytic function. -/

@[to_fun analyticAt_iff_analytic_fun_mul]
theorem analyticAt_iff_analytic_mul {f g : E → ��} {z : E} (h₁f : AnalyticAt �� f z)
    (h₂f : f z ≠ 0) :
    AnalyticAt �� g z ↔ AnalyticAt �� (f * g) z := by
  simp_rw [← smul_eq_mul]
  exact analyticAt_iff_analytic_smul h₁f h₂f

/-- `f x / g x` is analytic away from `g x = 0` -/
theorem AnalyticWithinAt.div {f g : E → ��} {s : Set E} {x : E}
    (fa : AnalyticWithinAt �� f s x) (ga : AnalyticWithinAt �� g s x) (g0 : g x ≠ 0) :
    AnalyticWithinAt �� (fun x ↦ f x / g x) s x := by
  simp_rw [div_eq_mul_inv]; exact fa.mul (ga.inv g0)

/-- `f x / g x` is analytic away from `g x = 0` -/
@[to_fun (attr := fun_prop)]
theorem AnalyticAt.div {f g : E → ��} {x : E}
    (fa : AnalyticAt �� f x) (ga : AnalyticAt �� g x) (g0 : g x ≠ 0) :
    AnalyticAt �� (f / g) x := by
  simp_rw [div_eq_mul_inv]; exact fa.mul (ga.inv g0)

/-- `f x / g x` is analytic away from `g x = 0` -/
theorem AnalyticOn.div {f g : E → ��} {s : Set E}
    (fa : AnalyticOn �� f s) (ga : AnalyticOn �� g s) (g0 : ∀ x ∈ s, g x ≠ 0) :
    AnalyticOn �� (fun x ↦ f x / g x) s := fun x m ↦
  (fa x m).div (ga x m) (g0 x m)

/-- `f x / g x` is analytic away from `g x = 0` -/
@[fun_prop]
theorem AnalyticOnNhd.div {f g : E → ��} {s : Set E}
    (fa : AnalyticOnNhd �� f s) (ga : AnalyticOnNhd �� g s) (g0 : ∀ x ∈ s, g x ≠ 0) :
    AnalyticOnNhd �� (fun x ↦ f x / g x) s := fun x m ↦
  (fa x m).div (ga x m) (g0 x m)

/-!
### Finite sums and products of analytic functions
-/


/-- Finite sums of analytic functions are analytic -/
@[to_fun Finset.analyticWithinAt_fun_sum]
theorem Finset.analyticWithinAt_sum {f : α → E → F} {c : E} {s : Set E}
    (N : Finset α) (h : ∀ n ∈ N, AnalyticWithinAt �� (f n) s c) :
    AnalyticWithinAt �� (∑ n ∈ N, f n) s c := by
  classical
  induction N using Finset.induction with
  | empty =>
    simp only [Finset.sum_empty]
    exact analyticWithinAt_const
  | insert a B aB hB =>
    simp_rw [Finset.sum_insert aB]
    simp only [Finset.mem_insert] at h
    exact (h a (Or.inl rfl)).add (hB fun b m ↦ h b (Or.inr m))

/-- Finite sums of analytic functions are analytic -/
@[to_fun (attr := fun_prop) Finset.analyticAt_fun_sum]
theorem Finset.analyticAt_sum {f : α → E → F} {c : E}
    (N : Finset α) (h : ∀ n ∈ N, AnalyticAt �� (f n) c) :
    AnalyticAt �� (∑ n ∈ N, f n) c := by
  simp_rw [← analyticWithinAt_univ] at h ⊢
  exact N.analyticWithinAt_sum h

/-- Finite sums of analytic functions are analytic -/
@[to_fun Finset.analyticOn_fun_sum]
theorem Finset.analyticOn_sum {f : α → E → F} {s : Set E}
    (N : Finset α) (h : ∀ n ∈ N, AnalyticOn �� (f n) s) :
    AnalyticOn �� (∑ n ∈ N, f n) s :=
  fun z zs ↦ N.analyticWithinAt_sum (fun n m ↦ h n m z zs)

/-- Finite sums of analytic functions are analytic -/
@[to_fun (attr := fun_prop) Finset.analyticOnNhd_fun_sum]
theorem Finset.analyticOnNhd_sum {f : α → E → F} {s : Set E}
    (N : Finset α) (h : ∀ n ∈ N, AnalyticOnNhd �� (f n) s) :
    AnalyticOnNhd �� (∑ n ∈ N, f n) s :=
  fun z zs ↦ N.analyticAt_sum (fun n m ↦ h n m z zs)

/-- Finite products of analytic functions are analytic -/
theorem Finset.analyticWithinAt_fun_prod {A : Type*} [NormedCommRing A] [NormedAlgebra �� A]
    {f : α → E → A} {c : E} {s : Set E} (N : Finset α) (h : ∀ n ∈ N, AnalyticWithinAt �� (f n) s c) :
    AnalyticWithinAt �� (fun z ↦ ∏ n ∈ N, f n z) s c := by
  classical
  induction N using Finset.induction with
  | empty =>
    simp only [Finset.prod_empty]
    exact analyticWithinAt_const
  | insert a B aB hB =>
    simp_rw [Finset.prod_insert aB]
    simp only [Finset.mem_insert] at h
    exact (h a (Or.inl rfl)).mul (hB fun b m ↦ h b (Or.inr m))

/-- Finite products of analytic functions are analytic -/
theorem Finset.analyticWithinAt_prod {A : Type*} [NormedCommRing A] [NormedAlgebra �� A]
    {f : α → E → A} {c : E} {s : Set E} (N : Finset α) (h : ∀ n ∈ N, AnalyticWithinAt �� (f n) s c) :
    AnalyticWithinAt �� (∏ n ∈ N, f n) s c := by
  convert! N.analyticWithinAt_fun_prod h
  simp

/-- Finite products of analytic functions are analytic -/
@[fun_prop]
theorem Finset.analyticAt_fun_prod {A : Type*} [NormedCommRing A] [NormedAlgebra �� A]
    {f : α → E → A} {c : E} (N : Finset α) (h : ∀ n ∈ N, AnalyticAt �� (f n) c) :
    AnalyticAt �� (fun z ↦ ∏ n ∈ N, f n z) c := by
  simp_rw [← analyticWithinAt_univ] at h ⊢
  exact N.analyticWithinAt_fun_prod h

/-- Finite products of analytic functions are analytic -/
@[fun_prop]
theorem Finset.analyticAt_prod {α : Type*} {A : Type*} [NormedCommRing A] [NormedAlgebra �� A]
    {f : α → E → A} {c : E} (N : Finset α) (h : ∀ n ∈ N, AnalyticAt �� (f n) c) :
    AnalyticAt �� (∏ n ∈ N, f n) c := by
  convert! N.analyticAt_fun_prod h
  simp

/-- Finite products of analytic functions are analytic -/
theorem Finset.analyticOn_fun_prod {A : Type*} [NormedCommRing A] [NormedAlgebra �� A]
    {f : α → E → A} {s : Set E} (N : Finset α) (h : ∀ n ∈ N, AnalyticOn �� (f n) s) :
    AnalyticOn �� (fun z ↦ ∏ n ∈ N, f n z) s :=
  fun z zs ↦ N.analyticWithinAt_fun_prod (fun n m ↦ h n m z zs)

/-- Finite products of analytic functions are analytic -/
theorem Finset.analyticOn_prod {A : Type*} [NormedCommRing A] [NormedAlgebra �� A]
    {f : α → E → A} {s : Set E} (N : Finset α) (h : ∀ n ∈ N, AnalyticOn �� (f n) s) :
    AnalyticOn �� (∏ n ∈ N, f n) s :=
  fun z zs ↦ N.analyticWithinAt_prod (fun n m ↦ h n m z zs)

/-- Finite products of analytic functions are analytic -/
@[fun_prop]
theorem Finset.analyticOnNhd_fun_prod {A : Type*} [NormedCommRing A] [NormedAlgebra �� A]
    {f : α → E → A} {s : Set E} (N : Finset α) (h : ∀ n ∈ N, AnalyticOnNhd �� (f n) s) :
    AnalyticOnNhd �� (fun z ↦ ∏ n ∈ N, f n z) s :=
  fun z zs ↦ N.analyticAt_fun_prod (fun n m ↦ h n m z zs)

/-- Finite products of analytic functions are analytic -/
@[fun_prop]
theorem Finset.analyticOnNhd_prod {A : Type*} [NormedCommRing A] [NormedAlgebra �� A]
    {f : α → E → A} {s : Set E} (N : Finset α) (h : ∀ n ∈ N, AnalyticOnNhd �� (f n) s) :
    AnalyticOnNhd �� (∏ n ∈ N, f n) s :=
  fun z zs ↦ N.analyticAt_prod (fun n m ↦ h n m z zs)

/-- Finproducts of analytic functions are analytic -/
@[fun_prop]
theorem analyticAt_finprod {α : Type*} {A : Type*} [NormedCommRing A] [NormedAlgebra �� A]
    {f : α → E → A} {c : E} (h : ∀ a, AnalyticAt �� (f a) c) :
    AnalyticAt �� (∏ᶠ n, f n) c := by
  by_cases hf : (Function.mulSupport f).Finite
  · simp_all [finprod_eq_prod _ hf, Finset.analyticAt_prod]
  · rw [finprod_of_infinite_mulSupport hf]
    apply analyticAt_const

/-!
### Unshifting
-/


section

variable {f : E → (E →L[��] F)} {pf : FormalMultilinearSeries �� E (E →L[��] F)} {s : Set E} {x : E}
  {r : ℝ≥0∞} {z : F}

theorem HasFPowerSeriesWithinOnBall.unshift (hf : HasFPowerSeriesWithinOnBall f pf s x r) :
    HasFPowerSeriesWithinOnBall (fun y ↦ z + f y (y - x)) (pf.unshift z) s x r where
  r_le := by
    rw [FormalMultilinearSeries.radius_unshift]
    exact hf.r_le
  r_pos := hf.r_pos
  hasSum := by
    intro y hy h'y
    apply HasSum.zero_add
    simp only [FormalMultilinearSeries.unshift, Nat.succ_eq_add_one,
      continuousMultilinearCurryRightEquiv_symm_apply', add_sub_cancel_left]
    exact (ContinuousLinearMap.apply �� F y).hasSum (hf.hasSum hy h'y)

theorem HasFPowerSeriesOnBall.unshift (hf : HasFPowerSeriesOnBall f pf x r) :
    HasFPowerSeriesOnBall (fun y ↦ z + f y (y - x)) (pf.unshift z) x r where
  r_le := by
    rw [FormalMultilinearSeries.radius_unshift]
    exact hf.r_le
  r_pos := hf.r_pos
  hasSum := by
    intro y hy
    apply HasSum.zero_add
    simp only [FormalMultilinearSeries.unshift, Nat.succ_eq_add_one,
      continuousMultilinearCurryRightEquiv_symm_apply', add_sub_cancel_left]
    exact (ContinuousLinearMap.apply �� F y).hasSum (hf.hasSum hy)

theorem HasFPowerSeriesWithinAt.unshift (hf : HasFPowerSeriesWithinAt f pf s x) :
    HasFPowerSeriesWithinAt (fun y ↦ z + f y (y - x)) (pf.unshift z) s x :=
  let ⟨_, hrf⟩ := hf
  hrf.unshift.hasFPowerSeriesWithinAt

end

Messung
CHZG
9310010097

¤ Dauer der Verarbeitung: 0.53 Sekunden  ¤

*© Formatika GbR, Deutschland