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

Quelle  Basic.lean   Sprache: Lean

 

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

module

public import Mathlib.Analysis.Analytic.Order
public import Mathlib.Analysis.Calculus.LogDeriv
public import Mathlib.MeasureTheory.Constructions.BorelSpace.Basic

/-!
# 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₀`.
-/


@[expose] public section

open Filter Metric Set

open scoped Pointwise Topology

variable {�� ��' : Type*} [NontriviallyNormedField ��] [NontriviallyNormedField ��']
  [NormedAlgebra �� ��'] {E : Type*} [NormedAddCommGroup E] [NormedSpace �� E]
variable {R : Type*} [NormedRing R] [Module R E] [IsBoundedSMul R 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 : ��}

@[to_fun (attr := 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)

@[to_fun (attr := fun_prop)]
lemma smul [NormedAlgebra �� R] [IsScalarTower �� R E]
    {f : �� → R} {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.smul hg with z
  rw [Pi.smul_apply', Pi.smul_apply', smul_smul_smul_comm, smul_eq_mul, pow_add]

@[to_fun (attr := fun_prop)]
lemma const_smul [SMulCommClass �� R E] {x : ��} {f : �� → E} (hf : MeromorphicAt f x) (c : R) :
    MeromorphicAt (c • f) x := by
  rcases hf with ⟨m, hf⟩
  exact ⟨m, by simpa [smul_comm _ c _] using hf.fun_const_smul⟩

@[to_fun (attr := fun_prop)]
lemma mul {f g : �� → ��'} (hf : MeromorphicAt f x) (hg : MeromorphicAt g x) :
    MeromorphicAt (f * g) x := by
  simpa using hf.smul hg

/-- Finite products of meromorphic functions are meromorphic. -/
@[fun_prop] -- TODO: to_fun generates an unreadable statement, see #32866
theorem prod (hf : ∀ σ ∈ s, MeromorphicAt (F σ) x) :
    MeromorphicAt (∏ i ∈ s, F i) x := by
  classical
  induction s using Finset.induction with
  | empty =>
    rw [Finset.prod_empty]
    apply MeromorphicAt.const
  | insert a s ha hs =>
    rw [Finset.prod_insert ha]
    apply (hf a (Finset.mem_insert_self a s)).mul
      (hs (fun i hi ↦ hf i (Finset.mem_insert_of_mem hi)))

/-- Finite products of meromorphic functions are meromorphic. -/
@[fun_prop]
theorem fun_prod (h : ∀ σ ∈ s, MeromorphicAt (F σ) x) :
    MeromorphicAt (fun z ↦ ∏ n ∈ s, F n z) x := by
  convert! prod h (s := s)
  simp

/-- Finprods of meromorphic functions are meromorphic. -/
@[fun_prop]
theorem finprod {x : ��} (hf : ∀ i, MeromorphicAt (F i) x) :
    MeromorphicAt (∏ᶠ i, F i) x := by
  by_cases h₂f : Function.HasFiniteMulSupport F
  · simpa [finprod_eq_prod F h₂f] using prod (by aesop)
  · exact finprod_of_not_hasFiniteMulSupport h₂f ▸ const (1 : ��') x

/-- Finite sums of meromorphic functions are meromorphic. -/
@[fun_prop] -- TODO: to_fun generates an unreadable statement, see #32866
theorem sum (h : ∀ σ ∈ s, 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σ]
    apply (h σ (Finset.mem_insert_self σ s)).add
      (hind (fun τ hτ ↦ h τ (Finset.mem_insert_of_mem hτ)))

/-- Finite sums of meromorphic functions are meromorphic. -/
@[fun_prop]
theorem fun_sum (h : ∀ σ ∈ s, MeromorphicAt (G σ) x) :
    MeromorphicAt (fun z ↦ ∑ n ∈ s, G n z) x := by
  convert! sum h (s := s)
  simp

/-- Finsums of meromorphic functions are meromorphic. -/
@[fun_prop]
theorem finsum (hF : ∀ i, MeromorphicAt (F i) x) :
    MeromorphicAt (∑ᶠ i, F i) x := by
  by_cases h₂f : Function.HasFiniteSupport F
  · simpa [finsum_eq_sum F h₂f] using sum (by aesop)
  · exact finsum_of_not_hasFiniteSupport h₂f ▸ const (0 : ��') x

@[to_fun (attr := fun_prop)]
lemma neg {f : �� → E} (hf : MeromorphicAt f x) : MeromorphicAt (-f) x := by
  convert (MeromorphicAt.const (-1 : ��) x).smul hf
  ext1 z
  simp only [Pi.neg_apply, Pi.smul_apply', neg_smul, one_smul]

@[simp]
lemma neg_iff {f : �� → E} :
    MeromorphicAt (-f) x ↔ MeromorphicAt f x :=
  ⟨fun h ↦ by simpa only [neg_neg] using h.neg, MeromorphicAt.neg⟩

@[to_fun (attr := 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
  ext1 z
  simp_rw [Pi.sub_apply, Pi.add_apply, Pi.neg_apply, sub_eq_add_neg]

/--
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 `f` is meromorphic at `x`, then `f + g` is meromorphic at `x` if and only if `g` is meromorphic
at `x`.
-/

lemma meromorphicAt_fun_add_iff_meromorphicAt₁ {f g : �� → E} (hf : MeromorphicAt f x) :
    MeromorphicAt (fun z ↦ f z + g z) x ↔ MeromorphicAt g x :=
  meromorphicAt_add_iff_meromorphicAt₁ hf

/--
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 `g` is meromorphic at `x`, then `f + g` is meromorphic at `x` if and only if `f` is meromorphic
at `x`.
-/

lemma meromorphicAt_fun_add_iff_meromorphicAt₂ {f g : �� → E} (hg : MeromorphicAt g x) :
    MeromorphicAt (fun z ↦ f z + g z) x ↔ MeromorphicAt f x :=
  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 `f` is meromorphic at `x`, then `f - g` is meromorphic at `x` if and only if `g` is meromorphic
at `x`.
-/

lemma meromorphicAt_fun_sub_iff_meromorphicAt₁ {f g : �� → E} (hf : MeromorphicAt f x) :
    MeromorphicAt (fun z ↦ f z - g z) x ↔ MeromorphicAt g x :=
  meromorphicAt_sub_iff_meromorphicAt₁ hf

/--
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⟩

/--
If `g` is meromorphic at `x`, then `f - g` is meromorphic at `x` if and only if `f` is meromorphic
at `x`.
-/

lemma meromorphicAt_fun_sub_iff_meromorphicAt₂ {f g : �� → E} (hg : MeromorphicAt g x) :
    MeromorphicAt (fun z ↦ f z - g z) x ↔ MeromorphicAt f x :=
  meromorphicAt_sub_iff_meromorphicAt₂ hg

/-- 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 := by fun_prop
  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

@[to_fun (attr := 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_ne_zero_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
    · replace hfg := congr($hfg⁻¹)
      simp only [smul_inv₀] at hfg
      rw [inv_smul_eq_iff₀ (pow_ne_zero m (sub_ne_zero.mpr hz_ne)), smul_comm,
        eq_inv_smul_iff₀ (pow_ne_zero n (sub_ne_zero.mpr hz_ne))] at hfg
      simp [pow_succ', mul_smul, hfg]

@[simp]
lemma inv_iff {f : �� → ��'} :
    MeromorphicAt f⁻¹ x ↔ MeromorphicAt f x :=
  ⟨fun h ↦ by simpa only [inv_inv] using h.inv, MeromorphicAt.inv⟩

@[to_fun (attr := 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)

@[to_fun (attr := 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

@[to_fun (attr := 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_natCast, zpow_natCast] using hf.pow m
  | negSucc m => simpa only [zpow_negSucc, inv_iff] using hf.pow (m + 1)

/-- 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

/--
Derivatives of meromorphic functions are meromorphic.
-/

@[fun_prop]
protected theorem deriv [CompleteSpace E] {f : �� → E} {x : ��} (h : MeromorphicAt f x) :
    MeromorphicAt (deriv f) x := by
  rw [MeromorphicAt.iff_eventuallyEq_zpow_smul_analyticAt] at h
  obtain ⟨n, g, h₁g, h₂g⟩ := h
  have : _root_.deriv (fun z ↦ (z - x) ^ n • g z)
      =ᶠ[��[≠] x] fun z ↦ (n * (z - x) ^ (n - 1)) • g z + (z - x) ^ n • _root_.deriv g z := by
    filter_upwards [eventually_nhdsWithin_of_eventually_nhds h₁g.eventually_analyticAt,
      eventually_nhdsWithin_of_forall fun _ a ↦ a] with z₀ h₁ h₂
    rw [deriv_fun_smul (DifferentiableAt.zpow (by fun_prop) (by simp_all [sub_ne_zero_of_ne h₂]))
      (by fun_prop), add_comm, deriv_comp_sub_const (f := (· ^ n))]
    aesop
  rw [MeromorphicAt.meromorphicAt_congr (Filter.EventuallyEq.nhdsNE_deriv h₂g),
    MeromorphicAt.meromorphicAt_congr this]
  fun_prop

/--
Iterated derivatives of meromorphic functions are meromorphic.
-/

@[fun_prop] theorem iterated_deriv [CompleteSpace E] {n : ℕ} {f : �� → E} {x : ��}
    (h : MeromorphicAt f x) :
    MeromorphicAt (_root_.deriv^[n] f) x := by
  induction n with
  | zero => exact h
  | succ n IH => simpa only [Function.iterate_succ', Function.comp_apply] using IH.deriv

/-- If `f` is meromorphic at a point, then so is its logarithmic derivative. -/
@[fun_prop] theorem logDeriv [CompleteSpace ��'] {f : �� → ��'} (hf : MeromorphicAt f x) :
    MeromorphicAt (logDeriv f) x := hf.deriv.div hf

end MeromorphicAt

section smul_iff

variable {g : �� → ��} {x : ��}

lemma meromorphicAt_smul_iff_of_ne_zero {f : �� → E} (hg : AnalyticAt �� g x) (hg' : g x ≠ 0) :
    MeromorphicAt (g • f) x ↔ MeromorphicAt f x := by
  refine ⟨fun hfg ↦ ?_, hg.meromorphicAt.smul⟩
  refine (hg.inv hg').meromorphicAt.smul hfg |>.congr ?_
  filter_upwards [(hg.continuousAt.mono_left nhdsWithin_le_nhds).eventually_ne hg'] with z hz
  simp [inv_smul_smul₀ hz]

lemma meromorphicAt_mul_iff_of_ne_zero {f : �� → ��} (hg : AnalyticAt �� g x) (hg' : g x ≠ 0) :
    MeromorphicAt (g * f) x ↔ MeromorphicAt f x :=
  meromorphicAt_smul_iff_of_ne_zero hg hg'

/-- `MeromorphicAt` is invariant under scaling. -/
@[to_fun (attr := simp) meromorphicAt_fun_const_smul_iff_meromorphicAt]
theorem meromorphicAt_const_smul_iff_meromorphicAt {f : �� → E} {s : ��} (hs : s ≠ 0) :
    MeromorphicAt (s • f) x ↔ MeromorphicAt f x := by
  constructor
  <;> intro hf
  · rw [((eq_inv_smul_iff₀ hs).mpr rfl : f = s⁻¹ • s • f)]
    fun_prop
  · fun_prop

end smul_iff

section composition
/-!
### Composition with an analytic function
-/


variable
  {F : Type*} [NormedAddCommGroup F] [NormedSpace �� F] [NormedSpace ��' F] [IsScalarTower �� ��' F]
  {x : ��}

/-- The composition of a meromorphic and an analytic function is meromorphic. -/
@[fun_prop]
lemma MeromorphicAt.comp_analyticAt {f : ��' → F} {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 i ↦ (h i)⁻¹ ^ r • j (g i)) x :=
      ((han.inv hne).pow r).smul (hr.restrictScalars.comp hg)
    refine ⟨n * r, this.congr ?_⟩
    filter_upwards [heq, han.continuousAt.tendsto.eventually_ne hne] with z hz hzne
    simp only [j, inv_pow, Function.comp_apply, inv_smul_eq_iff₀ (pow_ne_zero r hzne)]
    rw [hz, smul_comm, ← smul_assoc, pow_mul, smul_pow]

lemma meromorphicAt_comp_iff_of_deriv_ne_zero [CompleteSpace ��] [CharZero ��] {f : �� → E}
    {g : �� → ��} (hg : AnalyticAt �� g x) (hg' : deriv g x ≠ 0) :
    MeromorphicAt (f ∘ g) x ↔ MeromorphicAt f (g x) := by
  refine ⟨fun hf ↦ ?_, by fun_prop⟩
  let r := hg.hasStrictDerivAt.localInverse _ _ _ hg'
  have hra : AnalyticAt �� r (g x) := hg.analyticAt_localInverse hg'
  have : r (g x) = x := HasStrictFDerivAt.localInverse_apply_image ..
  rw [← this] at hf
  refine (hf.comp_analyticAt hra).congr (.filter_mono ?_ nhdsWithin_le_nhds)
  exact EventuallyEq.fun_comp (HasStrictDerivAt.eventually_right_inverse ..) f

/-- `MeromorphicAt` is invariant under translation. -/
@[to_fun meromorphicAt_fun_comp_add_const_iff_meromorphicAt]
theorem meromorphicAt_comp_add_const_iff_meromorphicAt {c : ��} {f : �� → E} :
    MeromorphicAt (f ∘ (· + c)) x ↔ MeromorphicAt f (x + c) := by
  refine ⟨fun h ↦ ?_, fun h ↦ ?_⟩
  · rw [show f = ((f ∘ fun x ↦ x + c) ∘ fun z ↦ z - c) by aesop]
    rw [show x = (x + c) - c by ring] at h
    exact h.comp_analyticAt (g := fun z ↦ z - c) (by fun_prop)
  · exact h.comp_analyticAt (g := fun z ↦ z + c) (by fun_prop)

/-- `MeromorphicAt` is invariant under translation. -/
@[to_fun meromorphicAt_fun_comp_sub_const_iff_meromorphicAt]
theorem meromorphicAt_comp_sub_const_iff_meromorphicAt {c : ��} {f : �� → E} :
    MeromorphicAt (f ∘ (· - c)) x ↔ MeromorphicAt f (x - c) := by
  simp_rw [sub_eq_add_neg, meromorphicAt_comp_add_const_iff_meromorphicAt]

end composition


/-- Meromorphy of a function on a set. -/
@[fun_prop]
def MeromorphicOn (f : �� → E) (U : Set ��) : Prop := ∀ x ∈ U, MeromorphicAt f x

@[fun_prop]
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_sdiff, Set.mem_ofPred_eq, not_and] at h₂a
  tauto

/--
If two functions differ only on a discrete set of an open, then one is meromorphic iff so is the
other.
-/

theorem _root_.meromorphicOn_congr_codiscreteWithin {f g : �� → E} (h₁ : f =ᶠ[codiscreteWithin U] g)
    (h₂ : IsOpen U) :
    MeromorphicOn f U ↔ MeromorphicOn g U :=
  ⟨(·.congr_codiscreteWithin h₁ h₂), (·.congr_codiscreteWithin h₁.symm h₂)⟩

@[fun_prop]
protected lemma id {U : Set ��} : MeromorphicOn id U := fun x _ ↦ .id x

@[fun_prop]
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
@[to_fun (attr := fun_prop)]
lemma add : MeromorphicOn (f + g) U := fun x hx ↦ (hf x hx).add (hg x hx)

include hf hg in
@[to_fun (attr := fun_prop)]
lemma sub : MeromorphicOn (f - g) U := fun x hx ↦ (hf x hx).sub (hg x hx)

include hf in
@[to_fun (attr := fun_prop)]
lemma neg : MeromorphicOn (-f) 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⟩

@[to_fun (attr := fun_prop)]
lemma smul [NormedAlgebra �� R] [IsScalarTower �� R E] {s : �� → R} (hs : MeromorphicOn s U)
    {f : �� → E} (hf : MeromorphicOn f U) :
    MeromorphicOn (s • f) U :=
  fun x hx ↦ (hs x hx).smul (hf x hx)

include hf in
@[to_fun (attr := fun_prop)]
lemma const_smul [SMulCommClass �� R E] (c : R) : MeromorphicOn (c • f) U :=
  fun x hx ↦ (hf x hx).const_smul c

/-- MeromorphicOn is invariant under scaling. -/
@[to_fun (attr := simp) meromorphicOn_fun_const_smul_iff_meromorphicOn]
theorem meromorphicOn_const_smul_iff_meromorphicOn {s : ��} (hs : s ≠ 0) :
    MeromorphicOn (s • f) U ↔ MeromorphicOn f U :=
  ⟨fun hf x hx ↦ (meromorphicAt_const_smul_iff_meromorphicAt hs).mp (hf x hx),
    fun hf x hx ↦ (meromorphicAt_const_smul_iff_meromorphicAt hs).mpr (hf x hx)⟩

include hs ht in
@[to_fun (attr := fun_prop)]
lemma mul : MeromorphicOn (s * t) U := fun x hx ↦ (hs x hx).mul (ht x hx)

/-- Finite products of meromorphic functions are meromorphic. -/
@[fun_prop]
lemma prod {U : Set ��} {ι : Type*} {s : Finset ι} {f : ι → �� → ��'}
    (h : ∀ σ ∈ s, MeromorphicOn (f σ) U) :
    MeromorphicOn (∏ n ∈ s, f n) U :=
  fun z hz ↦ MeromorphicAt.prod (h · · z hz)

/-- Finite products of meromorphic functions are meromorphic. -/
@[fun_prop]
lemma fun_prod {U : Set ��} {ι : Type*} {s : Finset ι} {f : ι → �� → ��'}
    (h : ∀ σ ∈ s, MeromorphicOn (f σ) U) :
    MeromorphicOn (fun z ↦ ∏ n ∈ s, f n z) U :=
  fun z hz ↦ MeromorphicAt.fun_prod (h · · z hz)

/-- Finprods of meromorphic functions are meromorphic. -/
@[fun_prop]
lemma finprod {U : Set ��} {ι : Type*} {f : ι → �� → ��'} (h : ∀ σ, MeromorphicOn (f σ) U) :
    MeromorphicOn (∏ᶠ n, f n) U :=
  fun z hz ↦ MeromorphicAt.finprod (h · z hz)

/-- Finite sums of meromorphic functions are meromorphic. -/
@[fun_prop]
lemma sum {U : Set ��} {ι : Type*} {s : Finset ι} {f : ι → �� → E}
    (h : ∀ σ ∈ s, MeromorphicOn (f σ) U) :
    MeromorphicOn (∑ n ∈ s, f n) U :=
  fun z hz ↦ MeromorphicAt.sum (h · · z hz)

/-- Finite sums of meromorphic functions are meromorphic. -/
@[fun_prop]
lemma fun_sum {U : Set ��} {ι : Type*} {s : Finset ι} {f : ι → �� → E}
    (h : ∀ σ ∈ s, MeromorphicOn (f σ) U) :
    MeromorphicOn (fun z ↦ ∑ n ∈ s, f n z) U :=
  fun z hz ↦ MeromorphicAt.fun_sum (fun σ hσ ↦ h σ hσ z hz)

/-- Finsums of meromorphic functions are meromorphic. -/
@[fun_prop]
lemma finsum {U : Set ��} {ι : Type*} {f : ι → �� → ��'} (h : ∀ σ, MeromorphicOn (f σ) U) :
    MeromorphicOn (∑ᶠ n, f n) U :=
  fun z hz ↦ MeromorphicAt.finsum (h · z hz)

include hs in
@[to_fun (attr := fun_prop)]
lemma inv : MeromorphicOn s⁻¹ 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
@[to_fun (attr := fun_prop)]
lemma div : MeromorphicOn (s / t) U := fun x hx ↦ (hs x hx).div (ht x hx)

include hs in
@[to_fun (attr := fun_prop)]
lemma pow (n : ℕ) : MeromorphicOn (s ^ n) U := fun x hx ↦ (hs x hx).pow _

include hs in
@[to_fun (attr := fun_prop)]
lemma zpow (n : ℤ) : MeromorphicOn (s ^ n) U := fun x hx ↦ (hs x hx).zpow _

include hf in
/-- Derivatives of meromorphic functions are meromorphic. -/
@[fun_prop]
protected theorem deriv [CompleteSpace E] : MeromorphicOn (deriv f) U := fun z hz ↦ (hf z hz).deriv

include hf in
/-- Iterated derivatives of meromorphic functions are meromorphic. -/
@[fun_prop]
theorem iterated_deriv [CompleteSpace E] {n : ℕ} : MeromorphicOn (deriv^[n] f) U :=
  fun z hz ↦ (hf z hz).iterated_deriv

/-- If `f` is meromorphic on a set, then so is its logarithmic derivative. -/
@[fun_prop]
protected theorem logDeriv [CompleteSpace ��'] {f : �� → ��'} (hf : MeromorphicOn f U) :
    MeromorphicOn (logDeriv f) U := hf.deriv.div hf

/-- `MeromorphicOn` is invariant under translation. -/
@[to_fun meromorphicOn_fun_comp_add_const_iff_meromorphicOn]
theorem meromorphicOn_comp_add_const_iff_meromorphicOn {c : ��} {U : Set ��} :
    MeromorphicOn (f ∘ (· + c)) U ↔ MeromorphicOn f (U + {c}) := by
  refine ⟨fun h y hy ↦ ?_, fun h y hy ↦ ?_⟩
  · rw [add_singleton, mem_image] at hy
    obtain ⟨x, h₁x, h₂x⟩ := hy
    simpa [← h₂x, ← meromorphicAt_comp_add_const_iff_meromorphicAt] using h x h₁x
  · rw [meromorphicAt_comp_add_const_iff_meromorphicAt]
    aesop

/-- `MeromorphicOn` is invariant under translation. -/
@[to_fun meromorphicOn_fun_comp_sub_const_iff_meromorphicOn]
theorem meromorphicOn_comp_sub_const_iff_meromorphicOn {c : ��} {U : Set ��} :
    MeromorphicOn (f ∘ (· - c)) U ↔ MeromorphicOn f (U - {c}) := by
  simp_rw [sub_eq_add_neg, meromorphicOn_comp_add_const_iff_meromorphicOn, neg_singleton]

/-- `MeromorphicOn` is invariant under translation, special case where the set is a ball. -/
@[to_fun (attr := simp) meromorphicOn_ball_fun_comp_sub_const_iff_meromorphicOn_ball]
theorem meromorphicOn_ball_comp_sub_const_iff_meromorphicOn_ball {c : ��} {R : ℝ} :
    MeromorphicOn (f ∘ (· - c)) (ball c R) ↔ MeromorphicOn f (ball 0 R) := by
  rw [meromorphicOn_comp_sub_const_iff_meromorphicOn, ball_sub_singleton, sub_self]

/-- `MeromorphicOn` is invariant under translation, special case where the set is a closed ball. -/
@[to_fun (attr := simp) meromorphicOn_closedBall_fun_comp_sub_const_iff_meromorphicOn_closedBall]
theorem meromorphicOn_closedBall_comp_sub_const_iff_meromorphicOn_closedBall {c : ��} {R : ℝ} :
    MeromorphicOn (f ∘ (· - c)) (closedBall c R) ↔ MeromorphicOn f (closedBall 0 R) := by
  rw [meromorphicOn_comp_sub_const_iff_meromorphicOn, closedBall_sub_singleton, sub_self]

/-- `MeromorphicOn` is invariant under translation, special case where the set is a sphere. -/
@[to_fun (attr := simp) meromorphicOn_sphere_fun_comp_sub_const_iff_meromorphicOn_sphere]
theorem meromorphicOn_sphere_comp_sub_const_iff_meromorphicOn_sphere {c : ��} {R : ℝ} :
    MeromorphicOn (f ∘ (· - c)) (sphere c R) ↔ MeromorphicOn f (sphere 0 R) := by
  rw [meromorphicOn_comp_sub_const_iff_meromorphicOn, sphere_sub_singleton, sub_self]

end arithmetic

section composition

variable {F : Type*} [NormedAddCommGroup F] [NormedSpace �� F] [NormedSpace ��' F]
  [IsScalarTower �� ��' F] {V : Set ��'}

/-- The composition of a meromorphic and an analytic function is meromorphic. -/
lemma comp_analyticOnNhd {f : ��' → F} {g : �� → ��'} (hf : MeromorphicOn f V)
    (hg : AnalyticOnNhd �� g U) (hUV : Set.MapsTo g U V) :
    MeromorphicOn (f ∘ g) U :=
  fun z hz ↦ (hf _ (hUV hz)).comp_analyticAt (hg z hz)

/-- Variant of `MeromorphicOn.comp_analyticOnNhd` which trades the `Set.MapsTo` hypothesis for a
smaller set. -/

@[fun_prop]
lemma comp_analyticOnNhd_inter {f : ��' → F} {g : �� → ��'} (hf : MeromorphicOn f V)
    (hg : AnalyticOnNhd �� g U) :
    MeromorphicOn (f ∘ g) (U ∩ g ⁻¹' V) :=
  hf.comp_analyticOnNhd (hg.mono inter_subset_left) inter_subset_right

end composition

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]

/--
The singular set of a meromorphic function is countable.
-/

theorem countable_compl_analyticAt_inter [SecondCountableTopology ��] [CompleteSpace E]
    (h : MeromorphicOn f U) :
    ({z | AnalyticAt �� f z}ᶜ ∩ U).Countable := by
  apply (HereditarilyLindelofSpace.isLindelof _).countable_of_isDiscrete
    (isDiscrete_of_codiscreteWithin _)
  simpa using! eventually_codiscreteWithin_analyticAt f h

end MeromorphicOn

/-- Meromorphy of a function on all of ��. -/
@[fun_prop]
def Meromorphic (f : �� → E) := ∀ x, MeromorphicAt f x

/-- A function is meromorphic iff it is meromorphic on Set.univ. -/
@[simp]
lemma meromorphicOn_univ {f : �� → E} : MeromorphicOn f Set.univ ↔ Meromorphic f := by tauto

namespace Meromorphic

variable
  {ι : Type*} {s : Finset ι}
  {f g : �� → E} {F : ι → �� → ��'} {G : ι → �� → E}

@[fun_prop]
lemma meromorphicAt {x : ��} (hf : Meromorphic f) : MeromorphicAt f x := hf x

@[fun_prop]
lemma meromorphicOn {s : Set ��} (hf : Meromorphic f) : MeromorphicOn f s := fun x _ ↦ hf x

section composition

variable {F : Type*} [NormedAddCommGroup F] [NormedSpace �� F] [NormedSpace ��' F]
  [IsScalarTower �� ��' F]

/-- The composition of a meromorphic and an analytic function is meromorphic. Compared to
`MeromorphicOn.comp_analyticOnNhd`, the outer function is meromorphic everywhere, so no
`Set.MapsTo` hypothesis is required. -/

@[fun_prop]
lemma comp_analyticOnNhd {f : ��' → F} {g : �� → ��'} {U : Set ��} (hf : Meromorphic f)
    (hg : AnalyticOnNhd �� g U) :
    MeromorphicOn (f ∘ g) U :=
  fun z hz ↦ (hf _).comp_analyticAt (hg z hz)

end composition

@[fun_prop]
protected lemma id : Meromorphic (id : �� → ��) := fun x ↦ .id x

@[fun_prop]
lemma const (x : E) : Meromorphic fun _ : �� ↦ x := fun _ ↦ .const _ _

@[to_fun (attr := fun_prop)]
lemma neg (hf : Meromorphic f) : Meromorphic (-f) := fun x ↦ (hf x).neg

@[to_fun (attr := fun_prop)]
lemma add (hf : Meromorphic f) (hg : Meromorphic g) :
    Meromorphic (f + g) := fun x ↦ (hf x).add (hg x)

@[to_fun (attr := fun_prop)]
theorem sum (h : ∀ σ ∈ s, Meromorphic (G σ)) :
    Meromorphic (∑ n ∈ s, G n) := fun x ↦ MeromorphicAt.sum (h · · x)

@[fun_prop]
theorem finsum (h : ∀ σ, Meromorphic (F σ)) :
    Meromorphic (∑ᶠ σ, F σ) := fun x ↦ MeromorphicAt.finsum (h · x)

@[to_fun (attr := fun_prop)]
lemma sub (hf : Meromorphic f) (hg : Meromorphic g) :
    Meromorphic (f - g) := fun x ↦ (hf x).sub (hg x)

@[to_fun (attr := fun_prop)]
lemma smul [NormedAlgebra �� R] [IsScalarTower �� R E] {f : �� → R} (hf : Meromorphic f)
    (hg : Meromorphic g) :
    Meromorphic (f • g) := fun x ↦ (hf x).smul (hg x)

@[to_fun (attr := fun_prop)]
lemma const_smul [SMulCommClass �� R E] (hf : Meromorphic f) (c : R) :
    Meromorphic (c • f) := fun x ↦ (hf x).const_smul c

/-- Meromorphic is invariant under scaling. -/
@[to_fun (attr := simp) _root_.meromorphic_fun_const_smul_iff_meromorphic]
theorem _root_.meromorphic_const_smul_iff_meromorphic {s : ��} (hs : s ≠ 0) :
    Meromorphic (s • f) ↔ Meromorphic f :=
  ⟨fun hf x ↦ (meromorphicAt_const_smul_iff_meromorphicAt hs).mp (hf x),
    fun hf x ↦ (meromorphicAt_const_smul_iff_meromorphicAt hs).mpr (hf x)⟩

@[to_fun (attr := fun_prop)]
lemma mul {f g : �� → ��'} (hf : Meromorphic f) (hg : Meromorphic g) :
    Meromorphic (f * g) := fun x ↦ (hf x).mul (hg x)

@[to_fun (attr := fun_prop)]
lemma inv {f : �� → ��'} (hf : Meromorphic f) : Meromorphic f⁻¹ := fun x ↦ (hf x).inv

@[to_fun (attr := fun_prop)]
theorem prod (h : ∀ σ ∈ s, Meromorphic (F σ)) :
    Meromorphic (∏ n ∈ s, F n) := fun x ↦ MeromorphicAt.prod (h · · x)

@[fun_prop]
theorem finprod (h : ∀ σ, Meromorphic (F σ)) :
    Meromorphic (∏ᶠ σ, F σ) := fun x ↦ MeromorphicAt.finprod (h · x)

@[to_fun (attr := fun_prop)]
lemma div {f g : �� → ��'} (hf : Meromorphic f) (hg : Meromorphic g) :
    Meromorphic (f / g) := fun x ↦ (hf x).div (hg x)

@[to_fun (attr := fun_prop)]
lemma pow {f : �� → ��'} {n : ℕ} (hf : Meromorphic f) : Meromorphic (f ^ n) := fun x ↦ (hf x).pow n

@[to_fun (attr := fun_prop)]
lemma zpow {f : �� → ��'} {n : ℤ} (hf : Meromorphic f) : Meromorphic (f ^ n) := fun x ↦ (hf x).zpow n

@[fun_prop]
protected lemma deriv [CompleteSpace E] (hf : Meromorphic f) : Meromorphic (deriv f) :=
  fun x ↦ (hf x).deriv

@[fun_prop]
lemma iterated_deriv [CompleteSpace E] {n : ℕ} (hf : Meromorphic f) :
    Meromorphic (deriv^[n] f) := fun x ↦ (hf x).iterated_deriv

/-- If `f` is meromorphic, then so is its logarithmic derivative. -/
@[fun_prop] protected theorem logDeriv [CompleteSpace ��'] {f : �� → ��'} (hf : Meromorphic f) :
    Meromorphic (logDeriv f) := hf.deriv.div hf

/--
If `f` is meromorphic, if `g` agrees with `f` on a codiscrete set, then `g` is also meromorphic.
-/

theorem congr_codiscrete (hf : Meromorphic f) (h₁ : f =ᶠ[codiscrete ��] g) :
    Meromorphic g := by
  rw [← meromorphicOn_univ] at *
  exact hf.congr_codiscreteWithin (eventuallyEq_of_mem h₁ fun ⦃x⦄ a ↦ a) isOpen_univ

/--
If two functions differ only on a discrete set, then one is meromorphic iff so is the other.
-/

theorem _root_.meromorphic_congr_codiscrete (h₁ : f =ᶠ[codiscrete ��] g) :
    Meromorphic f ↔ Meromorphic g :=
  ⟨(·.congr_codiscrete h₁), (·.congr_codiscrete h₁.symm)⟩

/--
The singular set of a meromorphic function is countable.
-/

theorem countable_compl_analyticAt [SecondCountableTopology ��] [CompleteSpace E]
    (h : Meromorphic f) :
    {z | AnalyticAt �� f z}ᶜ.Countable := by
  simpa using (h.meromorphicOn (s := univ)).countable_compl_analyticAt_inter

/--
Meromorphic functions are measurable.
-/

@[fun_prop] theorem measurable [MeasurableSpace ��] [SecondCountableTopology ��] [BorelSpace ��]
    [MeasurableSpace E] [CompleteSpace E] [BorelSpace E] (h : Meromorphic f) :
    Measurable f := by
  set s := {z : �� | AnalyticAt �� f z}
  have h₁ : sᶜ.Countable := by simpa using h.countable_compl_analyticAt
  have h₁' := h₁.to_subtype
  have h₂ : IsOpen s := isOpen_analyticAt �� f
  have h₃ : ContinuousOn f s := fun z hz ↦ hz.continuousAt.continuousWithinAt
  exact .of_union_range_cover (.subtype_coe h₂.measurableSet) (.subtype_coe h₁.measurableSet)
    (by simp [-mem_compl_iff]) h₃.domRestrict.measurable (measurable_of_countable _)

/-- `Meromorphic` is invariant under translation. -/
@[simp] theorem meromorphic_comp_add_const_iff_meromorphic {c : ��} :
    Meromorphic (f ∘ (· + c)) ↔ Meromorphic f := by
  rw [Meromorphic, Meromorphic, (Equiv.subRight c).surjective.forall]
  simp [meromorphicAt_comp_add_const_iff_meromorphicAt]

/-- `Meromorphic` is invariant under translation. -/
@[simp] theorem meromorphic_fun_comp_add_const_iff_meromorphic {c : ��} :
    Meromorphic (fun z ↦ f (z + c)) ↔ Meromorphic f :=
  meromorphic_comp_add_const_iff_meromorphic

/-- `Meromorphic` is invariant under translation. -/
@[simp] theorem meromorphic_comp_sub_const_iff_meromorphic {c : ��} :
    Meromorphic (f ∘ (· - c)) ↔ Meromorphic f := by
  nth_rw 2 [← meromorphic_comp_add_const_iff_meromorphic (c := -c)]
  simp_rw [sub_eq_add_neg]

/-- `Meromorphic` is invariant under translation. -/
@[simp] theorem meromorphic_fun_comp_sub_const_iff_meromorphic {c : ��} :
    Meromorphic (fun z ↦ f (z - c)) ↔ Meromorphic f :=
  meromorphic_comp_sub_const_iff_meromorphic

end Meromorphic

Messung
CHZG
9210010097

¤ Dauer der Verarbeitung: 0.36 Sekunden  ¤

*© Formatika GbR, Deutschland