[System] You are Leanstral, a Lean 4 proof assistant. Complete the task below using the provided Lean source context. The target mathlib commit is 5e932f97dd25535344f80f9dd8da3aab83df0fe6 (module Mathlib.Analysis.Analytic.Order).

[User]
Prove the following theorem. The retrieved context below may help.

```lean
lemma analyticOrderAt_deriv_of_pos {𝕜 : Type*} {E : Type*} [NontriviallyNormedField 𝕜] [CharZero 𝕜]
    [NormedAddCommGroup E] [NormedSpace 𝕜 E] [CompleteSpace E] {f : 𝕜 → E} {z₀ : 𝕜}
    (hf : AnalyticAt 𝕜 f z₀) {n : ℕ} (horder : analyticOrderAt f z₀ = n + 1) :
    analyticOrderAt (deriv f) z₀ = n
```

## Retrieved context
-- snippet 1
```lean
-- Mathlib.Analysis.Analytic.Order.analyticOrderAt_of_not_analyticAt (L65-L67)
lemma analyticOrderAt_of_not_analyticAt (hf : ¬ AnalyticAt 𝕜 f z₀) : analyticOrderAt f z₀ = 0 :=
dif_neg hf
```

-- snippet 2
```lean
-- Mathlib.Analysis.Analytic.Order.analyticOrderNatAt_of_not_analyticAt (L69-L71)
lemma analyticOrderNatAt_of_not_analyticAt (hf : ¬ AnalyticAt 𝕜 f z₀) :
    analyticOrderNatAt f z₀ = 0 := by simp [analyticOrderNatAt, hf]
```

-- snippet 3
```lean
-- Mathlib.Analysis.Analytic.Order.analyticOrderAt_eq_top (L76-L79)
lemma analyticOrderAt_eq_top : analyticOrderAt f z₀ = ⊤ ↔ ∀ᶠ z in 𝓝 z₀, f z = 0 where
  mp hf := by unfold analyticOrderAt at hf; split_ifs at hf with h <;> simp [*] at *
mpr hf := by unfold analyticOrderAt; simp [hf, analyticAt_congr hf, analyticAt_const]
```

-- snippet 4
```lean
-- Mathlib.Analysis.Analytic.Order.eventuallyConst_iff_analyticOrderAt_sub_eq_top (L80-L86)
lemma eventuallyConst_iff_analyticOrderAt_sub_eq_top :
    EventuallyConst f (𝓝 z₀) ↔ analyticOrderAt (f · - f z₀) z₀ = ⊤ := by
simpa [eventuallyConst_iff_exists_eventuallyEq, analyticOrderAt_eq_top, sub_eq_zero]
    using ⟨fun ⟨c, hc⟩ ↦ (show f z₀ = c from hc.self_of_nhds) ▸ hc, fun h ↦ ⟨_, h⟩⟩

/-- The order of an analytic function `f` at `z₀` equals a natural number `n` iff `f` can locally
be written as `f z = (z - z₀) ^ n • g z`, where `g` is analytic and does not vanish at `z₀`. -/
```

-- snippet 5
```lean
-- Mathlib.Analysis.Analytic.Order.AnalyticAt (L87-L101)
lemma AnalyticAt.analyticOrderAt_eq_natCast (hf : AnalyticAt 𝕜 f z₀) :
    analyticOrderAt f z₀ = n ↔
      ∃ (g : 𝕜 → E), AnalyticAt 𝕜 g z₀ ∧ g z₀ ≠ 0 ∧ ∀ᶠ z in 𝓝 z₀, f z = (z - z₀) ^ n • g z := by
unfold analyticOrderAt
  split_ifs with h
  · simp only [ENat.top_ne_coe, false_iff]
    contrapose h
    rw [← hf.exists_eventuallyEq_pow_smul_nonzero_iff]
    exact ⟨n, h⟩
  · rw [← hf.exists_eventuallyEq_pow_smul_nonzero_iff] at h
    refine ⟨fun hn ↦ (WithTop.coe_inj.mp hn : h.choose = n) ▸ h.choose_spec, fun h' ↦ ?_⟩
    rw [AnalyticAt.unique_eventuallyEq_pow_smul_nonzero h.choose_spec h']

/-- The order of an analytic function `f` at `z₀` equals a natural number `n` iff `f` can locally
be written as `f z = (z - z₀) ^ n • g z`, where `g` is analytic and does not vanish at `z₀`. -/
```

-- snippet 6
```lean
-- Mathlib.Analysis.Analytic.Order.AnalyticAt (L102-L113)
lemma AnalyticAt.analyticOrderNatAt_eq_iff (hf : AnalyticAt 𝕜 f z₀) (hf' : analyticOrderAt f z₀ ≠ ⊤)
    {n : ℕ} :
    analyticOrderNatAt f z₀ = n ↔
      ∃ (g : 𝕜 → E), AnalyticAt 𝕜 g z₀ ∧ g z₀ ≠ 0 ∧ ∀ᶠ z in 𝓝 z₀, f z = (z - z₀) ^ n • g z := by
simp [← Nat.cast_inj (R := ℕ∞), Nat.cast_analyticOrderNatAt hf', hf.analyticOrderAt_eq_natCast]

/-- The order of an analytic function `f` at `z₀` is finite iff `f` can locally be written as `f z =
  (z - z₀) ^ analyticOrderNatAt f z₀ • g z`, where `g` is analytic and does not vanish at `z₀`.

See `MeromorphicNFAt.order_eq_zero_iff` for an analogous statement about meromorphic functions in
normal form.
-/
```

-- snippet 7
```lean
-- Mathlib.Analysis.Analytic.Order.AnalyticAt (L114-L120)
lemma AnalyticAt.analyticOrderAt_ne_top (hf : AnalyticAt 𝕜 f z₀) :
    analyticOrderAt f z₀ ≠ ⊤ ↔
      ∃ (g : 𝕜 → E), AnalyticAt 𝕜 g z₀ ∧ g z₀ ≠ 0 ∧
        f =ᶠ[𝓝 z₀] fun z ↦ (z - z₀) ^ analyticOrderNatAt f z₀ • g z := by
simp only [← ENat.coe_toNat_eq_self, Eq.comm, EventuallyEq, ← hf.analyticOrderAt_eq_natCast,
    analyticOrderNatAt]
```

-- snippet 8
```lean
-- Mathlib.Analysis.Analytic.Order.analyticOrderAt_eq_zero (L121-L129)
lemma analyticOrderAt_eq_zero : analyticOrderAt f z₀ = 0 ↔ ¬ AnalyticAt 𝕜 f z₀ ∨ f z₀ ≠ 0 := by
by_cases hf : AnalyticAt 𝕜 f z₀
  · rw [← ENat.coe_zero, hf.analyticOrderAt_eq_natCast]
    constructor
    · intro ⟨g, _, _, hg⟩
      simpa [hf, hg.self_of_nhds]
    · exact fun hz ↦ ⟨f, hf, hz.resolve_left <| not_not_intro hf, by simp⟩
  · simp [hf]
```

-- snippet 9
```lean
-- Mathlib.Analysis.Analytic.Order.analyticOrderAt_ne_zero (L130-L141)
lemma analyticOrderAt_ne_zero : analyticOrderAt f z₀ ≠ 0 ↔ AnalyticAt 𝕜 f z₀ ∧ f z₀ = 0 := by
simp [analyticOrderAt_eq_zero]

/-- The order of an analytic function `f` at `z₀` is zero iff `f` does not vanish at `z₀`. -/
protected lemma AnalyticAt.analyticOrderAt_eq_zero (hf : AnalyticAt 𝕜 f z₀) :
    analyticOrderAt f z₀ = 0 ↔ f z₀ ≠ 0 := by simp [hf, analyticOrderAt_eq_zero]

/-- The order of an analytic function `f` at `z₀` is zero iff `f` does not vanish at `z₀`. -/
protected lemma AnalyticAt.analyticOrderAt_ne_zero (hf : AnalyticAt 𝕜 f z₀) :
    analyticOrderAt f z₀ ≠ 0 ↔ f z₀ = 0 := hf.analyticOrderAt_eq_zero.not_left

/-- A function vanishes at a point if its analytic order is nonzero in `ℕ∞`. -/
```

-- snippet 10
```lean
-- Mathlib.Analysis.Analytic.Order.apply_eq_zero_of_analyticOrderAt_ne_zero (L142-L146)
lemma apply_eq_zero_of_analyticOrderAt_ne_zero (hf : analyticOrderAt f z₀ ≠ 0) :
    f z₀ = 0 := by
by_cases hf' : AnalyticAt 𝕜 f z₀ <;> simp_all [analyticOrderAt_eq_zero]

/-- A function vanishes at a point if its analytic order is nonzero when converted to ℕ. -/
```

-- snippet 11
```lean
-- Mathlib.Analysis.Analytic.Order.apply_eq_zero_of_analyticOrderNatAt_ne_zero (L147-L152)
lemma apply_eq_zero_of_analyticOrderNatAt_ne_zero (hf : analyticOrderNatAt f z₀ ≠ 0) :
    f z₀ = 0 := by
by_cases hf' : AnalyticAt 𝕜 f z₀ <;> simp_all [analyticOrderNatAt, analyticOrderAt_eq_zero]

/-- Characterization of which natural numbers are `≤ hf.order`. Useful for avoiding case splits,
since it applies whether or not the order is `∞`. -/
```

-- snippet 12
```lean
-- Mathlib.Analysis.Analytic.Order.natCast_le_analyticOrderAt (L153-L175)
lemma natCast_le_analyticOrderAt (hf : AnalyticAt 𝕜 f z₀) {n : ℕ} :
    n ≤ analyticOrderAt f z₀ ↔
      ∃ g, AnalyticAt 𝕜 g z₀ ∧ ∀ᶠ z in 𝓝 z₀, f z = (z - z₀) ^ n • g z := by
unfold analyticOrderAt
  split_ifs with h
  · simpa using ⟨0, analyticAt_const .., by simpa⟩
  · let m := (hf.exists_eventuallyEq_pow_smul_nonzero_iff.mpr h).choose
    obtain ⟨g, hg, hg_ne, hm⟩ := (hf.exists_eventuallyEq_pow_smul_nonzero_iff.mpr h).choose_spec
    rw [ENat.coe_le_coe]
    refine ⟨fun hmn ↦ ⟨fun z ↦ (z - z₀) ^ (m - n) • g z, by fun_prop, ?_⟩, fun ⟨h, hh, hfh⟩ ↦ ?_⟩
    · filter_upwards [hm] with z hz using by rwa [← mul_smul, ← pow_add, Nat.add_sub_of_le hmn]
    · contrapose! hg_ne
      have : ContinuousAt (fun z ↦ (z - z₀) ^ (n - m) • h z) z₀ := by fun_prop
      rw [tendsto_nhds_unique_of_eventuallyEq (l := 𝓝[≠] z₀)
        hg.continuousAt.continuousWithinAt this.continuousWithinAt ?_]
      · simp [m, Nat.sub_ne_zero_of_lt hg_ne]
      · filter_upwards [self_mem_nhdsWithin, hm.filter_mono nhdsWithin_le_nhds,
          hfh.filter_mono nhdsWithin_le_nhds] with z hz hf' hf''
        rw [← inv_smul_eq_iff₀ (pow_ne_zero _ <| sub_ne_zero_of_ne hz), hf'', smul_comm,
          ← mul_smul] at hf'
        rw [pow_sub₀ _ (sub_ne_zero_of_ne hz) (by lia), ← hf']

/-- If two functions agree in a neighborhood of `z₀`, then their orders at `z₀` agree. -/
```

-- snippet 13
```lean
-- Mathlib.Analysis.Analytic.Order.analyticOrderAt_congr (L176-L185)
lemma analyticOrderAt_congr (hfg : f =ᶠ[𝓝 z₀] g) :
    analyticOrderAt f z₀ = analyticOrderAt g z₀ := by
by_cases hf : AnalyticAt 𝕜 f z₀
  · refine ENat.eq_of_forall_natCast_le_iff fun n ↦ ?_
    simp only [natCast_le_analyticOrderAt, hf, hf.congr hfg]
    congr! 3
    exact hfg.congr_left
  · rw [analyticOrderAt_of_not_analyticAt hf,
      analyticOrderAt_of_not_analyticAt fun hg ↦ hf <| hg.congr hfg.symm]
```

-- snippet 14
```lean
-- Mathlib.Analysis.Analytic.Order.le_analyticOrderAt_add (L198-L208)
theorem le_analyticOrderAt_add :
    min (analyticOrderAt f z₀) (analyticOrderAt g z₀) ≤ analyticOrderAt (f + g) z₀ := by
by_cases hf : AnalyticAt 𝕜 f z₀
  · by_cases hg : AnalyticAt 𝕜 g z₀
    · refine ENat.forall_natCast_le_iff_le.mp fun n ↦ ?_
      simp only [le_min_iff, natCast_le_analyticOrderAt, hf, hg, hf.add hg]
      refine fun ⟨⟨F, hF, hF'⟩, ⟨G, hG, hG'⟩⟩ ↦ ⟨F + G, hF.add hG, ?_⟩
      filter_upwards [hF', hG'] with z using by simp +contextual
    · simp [*]
  · simp [*]
```

-- snippet 15
```lean
-- Mathlib.Analysis.Analytic.Order.le_analyticOrderAt_sub (L209-L212)
lemma le_analyticOrderAt_sub :
    min (analyticOrderAt f z₀) (analyticOrderAt g z₀) ≤ analyticOrderAt (f - g) z₀ := by
simpa [sub_eq_add_neg] using le_analyticOrderAt_add (f := f) (g := -g)
```

-- snippet 16
```lean
-- Mathlib.Analysis.Analytic.Basic.ContinuousLinearMap (L546-L557)
theorem ContinuousLinearMap.comp_hasFPowerSeriesWithinOnBall (g : F →L[𝕜] G)
    (h : HasFPowerSeriesWithinOnBall f p s x r) :
    HasFPowerSeriesWithinOnBall (g ∘ f) (g.compFormalMultilinearSeries p) s x r where
  r_le := h.r_le.trans (p.radius_le_radius_continuousLinearMap_comp _)
r_pos := h.r_pos
  hasSum hy h'y := by
    simpa only [ContinuousLinearMap.compFormalMultilinearSeries_apply,
      ContinuousLinearMap.compContinuousMultilinearMap_coe, Function.comp_apply] using
      g.hasSum (h.hasSum hy h'y)

/-- If a function `f` has a power series `p` on a ball and `g` is linear, then `g ∘ f` has the
power series `g ∘ p` on the same ball. -/
```

-- snippet 17
```lean
-- Mathlib.Analysis.Analytic.Basic.AnalyticWithinAt (L113-L117)
def AnalyticWithinAt (f : E → F) (s : Set E) (x : E) : Prop :=
∃ p : FormalMultilinearSeries 𝕜 E F, HasFPowerSeriesWithinAt f p s x

/-- Given a function `f : E → F`, we say that `f` is analytic on a set `s` if it is analytic around
every point of `s`. -/
```

-- snippet 18
```lean
-- Mathlib.Analysis.Analytic.Basic.AnalyticOn (L123-L131)
def AnalyticOn (f : E → F) (s : Set E) : Prop :=
∀ x ∈ s, AnalyticWithinAt 𝕜 f s x

/-!
### `HasFPowerSeriesOnBall` and `HasFPowerSeriesWithinOnBall`
-/

variable {𝕜}
```

-- snippet 19
```lean
-- Mathlib.Analysis.Analytic.Basic.HasFPowerSeriesWithinAt (L98-L101)
def HasFPowerSeriesWithinAt (f : E → F) (p : FormalMultilinearSeries 𝕜 E F) (s : Set E) (x : E) :=
∃ r, HasFPowerSeriesWithinOnBall f p s x r

-- Teach the `bound` tactic that power series have positive radius
```

-- snippet 20
```lean
-- Mathlib.Analysis.Analytic.Binomial.binomialSeries_radius_eq_top_of_nat (L76-L82)
theorem binomialSeries_radius_eq_top_of_nat {𝕂 : Type v} [RCLike 𝕂] {𝔸 : Type u}
    [NormedDivisionRing 𝔸] [NormedAlgebra 𝕂 𝔸] {a : ℕ} :
    (binomialSeries 𝔸 (a : 𝕂)).radius = ⊤ := by
simp [binomialSeries_eq_ordinaryHypergeometricSeries (b := (1 : 𝕂)) (by norm_cast; simp),
    ordinaryHypergeometric_radius_top_of_neg_nat₁]

/-- The radius of convergence of `binomialSeries 𝔸 a` is `1`, when `a` is not natural. -/
```

-- snippet 21
```lean
-- Mathlib.Analysis.Analytic.Basic.hasFPowerSeriesAt_iff (L1106-L1127)
theorem hasFPowerSeriesAt_iff :
    HasFPowerSeriesAt f p z₀ ↔ ∀ᶠ z in 𝓝 0, HasSum (fun n => z ^ n • p.coeff n) (f (z₀ + z)) := by
refine ⟨fun ⟨r, _, r_pos, h⟩ =>
    eventually_of_mem (Metric.eball_mem_nhds 0 r_pos) fun _ => by simpa using h, ?_⟩
  simp only [Metric.eventually_nhds_iff]
  rintro ⟨r, r_pos, h⟩
  refine ⟨p.radius ⊓ r.toNNReal, by simp, ?_, ?_⟩
  · simp only [r_pos.lt, lt_inf_iff, ENNReal.coe_pos, Real.toNNReal_pos, and_true]
    obtain ⟨z, z_pos, le_z⟩ := NormedField.exists_norm_lt 𝕜 r_pos.lt
    have : (‖z‖₊ : ENNReal) ≤ p.radius := by
      simp only [dist_zero_right] at h
      apply FormalMultilinearSeries.le_radius_of_tendsto
      convert tendsto_norm.comp (h le_z).summable.tendsto_atTop_zero
      simp [norm_smul, mul_comm]
    refine lt_of_lt_of_le ?_ this
    simp only [ENNReal.coe_pos]
    exact zero_lt_iff.mpr (nnnorm_ne_zero_iff.mpr (norm_pos_iff.mp z_pos))
  · simp only [Metric.mem_eball, lt_inf_iff, edist_lt_coe, apply_eq_pow_smul_coeff, and_imp,
      dist_zero_right] at h ⊢
    refine fun {y} _ hyr => h ?_
    simpa [nndist_eq_nnnorm, Real.lt_toNNReal_iff_coe_lt] using hyr
```

-- snippet 22
```lean
-- Mathlib.Analysis.Analytic.Binomial.one_add_cpow_hasFPowerSeriesAt_zero (L152-L155)
theorem one_add_cpow_hasFPowerSeriesAt_zero {a : ℂ} :
    HasFPowerSeriesAt (fun x ↦ (1 + x) ^ a) (binomialSeries ℂ a) 0 :=
one_add_cpow_hasFPowerSeriesOnBall_zero.hasFPowerSeriesAt
```

-- snippet 23
```lean
-- Mathlib.Analysis.Analytic.Binomial.binomialSeries_apply (L54-L58)
theorem binomialSeries_apply {𝕂 : Type u} [Field 𝕂] [CharZero 𝕂] (𝔸 : Type v)
    [Ring 𝔸] [Algebra 𝕂 𝔸] [TopologicalSpace 𝔸] [IsTopologicalRing 𝔸] (a : 𝕂) {n} (v : Fin n → 𝔸) :
    binomialSeries 𝔸 a n v = Ring.choose a n • (List.ofFn v).prod := by
simp [binomialSeries, FormalMultilinearSeries.ofScalars]
```

-- snippet 24
```lean
-- Mathlib.Analysis.Analytic.Binomial.Complex (L41-L52)
lemma Complex.ofReal_choose (a : ℝ) (n : ℕ) :
    ↑(Ring.choose a n) = Ring.choose (a : ℂ) n :=
Ring.map_choose (algebraMap ℝ ℂ) _ _

/-- **Binomial series**: the (scalar) formal multilinear series with coefficients given
by `Ring.choose a`. The sum of this series is `fun x ↦ (1 + x) ^ a` within the radius
of convergence. -/
noncomputable def binomialSeries {𝕂 : Type u} [Field 𝕂] [CharZero 𝕂] (𝔸 : Type v)
    [Ring 𝔸] [Algebra 𝕂 𝔸] [TopologicalSpace 𝔸] [IsTopologicalRing 𝔸] (a : 𝕂) :
    FormalMultilinearSeries 𝕂 𝔸 𝔸 :=
  .ofScalars 𝔸 (Ring.choose a ·)
```

-- snippet 25
```lean
-- Mathlib.Analysis.Analytic.Binomial.binomialSeries_radius_ge_one (L90-L100)
theorem binomialSeries_radius_ge_one {𝕂 : Type*} [RCLike 𝕂] {𝔸 : Type*} [NormedDivisionRing 𝔸]
    [NormedAlgebra 𝕂 𝔸] {a : 𝕂} :
    1 ≤ (binomialSeries 𝔸 a).radius := by
by_cases ha : ∀ (k : ℕ), a ≠ k
  · rw [binomialSeries_radius_eq_one ha]
  · push Not at ha
    rcases ha with ⟨k, rfl⟩
    simp [binomialSeries_radius_eq_top_of_nat]

namespace Complex
```

-- snippet 26
```lean
-- Mathlib.Analysis.Analytic.Basic.AnalyticAt (L109-L112)
def AnalyticAt (f : E → F) (x : E) :=
∃ p : FormalMultilinearSeries 𝕜 E F, HasFPowerSeriesAt f p x

/-- `f` is analytic within `s` at `x` if it has a power series at `x` that converges on `𝓝[s] x` -/
```

-- snippet 27
```lean
-- Mathlib.Analysis.Analytic.Basic.analyticOnNhd_congr' (L506-L508)
theorem analyticOnNhd_congr' (h : f =ᶠ[𝓝ˢ s] g) : AnalyticOnNhd 𝕜 f s ↔ AnalyticOnNhd 𝕜 g s :=
⟨fun hf => hf.congr' h, fun hg => hg.congr' h.symm⟩
```

-- snippet 28
```lean
-- Mathlib.Analysis.Analytic.Basic.hasFPowerSeriesAt_iff' (L1128-L1132)
theorem hasFPowerSeriesAt_iff' :
    HasFPowerSeriesAt f p z₀ ↔ ∀ᶠ z in 𝓝 z₀, HasSum (fun n => (z - z₀) ^ n • p.coeff n) (f z) := by
rw [← map_add_left_nhds_zero, eventually_map, hasFPowerSeriesAt_iff]
  simp_rw [add_sub_cancel_left]
```

-- snippet 29
```lean
-- Mathlib.Analysis.Analytic.Binomial.one_div_one_sub_cpow_hasFPowerSeriesOnBall_zero (L159-L170)
theorem one_div_one_sub_cpow_hasFPowerSeriesOnBall_zero (a : ℂ) :
    HasFPowerSeriesOnBall (fun x ↦ 1 / (1 - x) ^ a)
      (.ofScalars ℂ fun n ↦ Ring.choose (a + n - 1) n) 0 1 := by
have H : ((binomialSeries ℂ (-a)).compContinuousLinearMap (-1)) =
      .ofScalars ℂ fun n ↦ Ring.choose (a + n - 1) n := by
    ext n; simp [FormalMultilinearSeries.compContinuousLinearMap, binomialSeries, Ring.choose_neg,
      Units.smul_def, ← pow_add, ← mul_assoc]
  have : HasFPowerSeriesOnBall (fun x ↦ (1 + x) ^ (-a)) (binomialSeries ℂ (-a : ℂ)) (-0) 1 := by
    simpa using one_add_cpow_hasFPowerSeriesOnBall_zero
  simpa [cpow_neg, Function.comp_def, ← sub_eq_add_neg, H] using
    this.compContinuousLinearMap (u := -1) (x := (0 : ℂ))
```

-- snippet 30
```lean
-- Mathlib.Analysis.Analytic.Binomial.one_add_cpow_hasFPowerSeriesOnBall_zero (L101-L148)
theorem one_add_cpow_hasFPowerSeriesOnBall_zero {a : ℂ} :
    HasFPowerSeriesOnBall (fun x ↦ (1 + x) ^ a) (binomialSeries ℂ a) 0 1 := by
suffices (binomialSeries ℂ a = FormalMultilinearSeries.ofScalars ℂ
      fun n ↦ iteratedDeriv n (fun (x : ℂ) ↦ (1 + x) ^ a) 0 / n !) by
    convert AnalyticOn.hasFPowerSeriesOnSubball _ _ _
    · norm_num
    · -- TODO: use `fun_prop` for this subgoal
      apply AnalyticOn.cpow (analyticOn_const.add analyticOn_id) analyticOn_const
      intro z hz
      apply Complex.mem_slitPlane_of_norm_lt_one
      rw [← ENNReal.ofReal_one, Metric.eball_ofReal] at hz
      simpa using hz
    · rw [← this]
      exact binomialSeries_radius_ge_one
  simp only [binomialSeries, FormalMultilinearSeries.ofScalars_series_eq_iff]
  ext n
  rw [eq_div_iff_mul_eq (by simp [Nat.factorial_ne_zero]), ← nsmul_eq_mul',
    ← Ring.descPochhammer_eq_factorial_smul_choose]
  let B := Metric.ball (0 : ℂ) 1
  suffices Set.EqOn (iteratedDerivWithin n (fun x ↦ (1 + x) ^ a) B)
      (fun x ↦ (descPochhammer ℤ n).smeval a * (1 + x) ^ (a - n)) B by
    specialize this (show 0 ∈ _ by simp [B])
    rw [iteratedDerivWithin_of_isOpen Metric.isOpen_ball (by simp)] at this
    symm
    simpa using this
  induction n with
  | zero => simp [Set.EqOn]
  | succ n ih =>
    have : iteratedDerivWithin (n + 1) (fun (x : ℂ) ↦ (1 + x) ^ a) B =
        derivWithin (iteratedDerivWithin n (fun x ↦ (1 + x) ^ a) B) B := by
      ext z
      rw [iteratedDerivWithin_succ]
    rw [this]
    have : Set.EqOn (derivWithin (iteratedDerivWithin n (fun (x : ℂ) ↦ (1 + x) ^ a) B) B)
        (derivWithin (fun x ↦ (descPochhammer ℤ n).smeval a * (1 + x) ^ (a - ↑n)) B) B := by
      intro z hz
      rw [derivWithin_congr (fun _ hz ↦ ih hz) (ih hz)]
    apply Set.EqOn.trans this
    intro z hz
    simp only [Nat.cast_add, Nat.cast_one, B, derivWithin_of_isOpen Metric.isOpen_ball hz,
      deriv_const_mul_field']
    rw [_root_.deriv_cpow_const (by fun_prop), deriv_const_add', deriv_id'', mul_one,
      show a - (n + 1) = a - n - 1 by ring, ← mul_assoc]
    · congr
      simp [descPochhammer_succ_right, Polynomial.smeval_mul, Polynomial.smeval_natCast]
    · apply Complex.mem_slitPlane_of_norm_lt_one
      simpa [B] using hz
```

-- snippet 31
```lean
-- Mathlib.Analysis.Analytic.Basic.analyticAt_congr (L495-L497)
theorem analyticAt_congr (h : f =ᶠ[𝓝 x] g) : AnalyticAt 𝕜 f x ↔ AnalyticAt 𝕜 g x :=
⟨fun hf ↦ hf.congr h, fun hg ↦ hg.congr h.symm⟩
```

-- snippet 32
```lean
-- Mathlib.Analysis.Analytic.Basic.HasFPowerSeriesAt (L94-L97)
def HasFPowerSeriesAt (f : E → F) (p : FormalMultilinearSeries 𝕜 E F) (x : E) :=
∃ r, HasFPowerSeriesOnBall f p x r

/-- Analogue of `HasFPowerSeriesAt` where convergence is required only on a set `s`. -/
```

-- snippet 33
```lean
-- Mathlib.Analysis.Analytic.Basic.analyticOn_congr (L488-L490)
lemma analyticOn_congr (hs : EqOn f g s) : AnalyticOn 𝕜 f s ↔ AnalyticOn 𝕜 g s :=
⟨fun h ↦ h.congr hs.symm, fun h ↦ h.congr hs⟩
```

-- snippet 34
```lean
-- Mathlib.Analysis.Analytic.Basic.analyticOnNhd_congr (L514-L516)
theorem analyticOnNhd_congr (hs : IsOpen s) (h : s.EqOn f g) : AnalyticOnNhd 𝕜 f s ↔
    AnalyticOnNhd 𝕜 g s := ⟨fun hf => hf.congr hs h, fun hg => hg.congr hs h.symm⟩
```

-- snippet 35
```lean
-- Mathlib.Analysis.Analytic.Binomial.binomialSeries_radius_eq_one (L83-L89)
theorem binomialSeries_radius_eq_one {𝕂 : Type v} [RCLike 𝕂] {𝔸 : Type u} [NormedDivisionRing 𝔸]
    [NormedAlgebra 𝕂 𝔸] {a : 𝕂} (ha : ∀ (k : ℕ), a ≠ k) : (binomialSeries 𝔸 a).radius = 1 := by
simp only [binomialSeries_eq_ordinaryHypergeometricSeries (b := (1 : 𝕂)) (by norm_cast; simp),
    FormalMultilinearSeries.radius_compNeg]
  conv at ha => ext; rw [ne_comm]
  exact ordinaryHypergeometricSeries_radius_eq_one _ _ _ _ (by norm_cast; grind)
```

-- snippet 36
```lean
-- Mathlib.Analysis.Analytic.Basic.AnalyticOnNhd (L118-L122)
def AnalyticOnNhd (f : E → F) (s : Set E) :=
∀ x, x ∈ s → AnalyticAt 𝕜 f x

/-- `f` is analytic within `s` if it is analytic within `s` at each point of `s`.  Note that
this is weaker than `AnalyticOnNhd 𝕜 f s`, as `f` is allowed to be arbitrary outside `s`. -/
```

-- snippet 37
```lean
-- Mathlib.Analysis.Analytic.Basic.hasFPowerSeriesWithinAt_iff_of_nhds (L391-L397)
lemma hasFPowerSeriesWithinAt_iff_of_nhds (f : E → F) (p : FormalMultilinearSeries 𝕜 E F)
    {U : Set E} (hU : U ∈ 𝓝 x) :
    HasFPowerSeriesWithinAt f p U x ↔ HasFPowerSeriesAt f p x := by
rw [← hasFPowerSeriesWithinAt_univ]
  exact ⟨fun h ↦ h.mono_of_mem_nhdsWithin (mem_nhdsWithin_of_mem_nhds hU),
    fun h ↦ h.mono (subset_univ _)⟩
```

-- snippet 38
```lean
-- Mathlib.Analysis.Analytic.Basic.HasFPowerSeriesOnBall (L132-L135)
theorem HasFPowerSeriesOnBall.hasFPowerSeriesAt (hf : HasFPowerSeriesOnBall f p x r) :
    HasFPowerSeriesAt f p x :=
⟨r, hf⟩
```

-- snippet 39
```lean
-- Mathlib.Analysis.Analytic.Basic.HasFPowerSeriesWithinOnBall (L142-L145)
theorem HasFPowerSeriesWithinOnBall.hasFPowerSeriesWithinAt
    (hf : HasFPowerSeriesWithinOnBall f p s x r) : HasFPowerSeriesWithinAt f p s x :=
⟨r, hf⟩
```

-- snippet 40
```lean
-- Mathlib.Analysis.Analytic.Binomial.binomialSeries_eq_ordinaryHypergeometricSeries (L59-L75)
theorem binomialSeries_eq_ordinaryHypergeometricSeries {𝕂 : Type u} [Field 𝕂] [CharZero 𝕂]
    {𝔸 : Type v} [Ring 𝔸] [Algebra 𝕂 𝔸] [TopologicalSpace 𝔸] [IsTopologicalRing 𝔸] {a b : 𝕂}
    (h : ∀ (k : ℕ), (k : 𝕂) ≠ -b) :
    binomialSeries 𝔸 a =
    (ordinaryHypergeometricSeries 𝔸 (-a) b b).compContinuousLinearMap (-(.id _ _)) := by
simp only [binomialSeries, ordinaryHypergeometricSeries,
    FormalMultilinearSeries.ofScalars_comp_neg_id]
  congr! with n
  rw [ordinaryHypergeometricCoefficient,
    mul_inv_cancel_right₀ (by simp [ascPochhammer_eval_eq_zero_iff]; grind)]
  simp only [Ring.choose_eq_smul, Polynomial.descPochhammer_smeval_eq_ascPochhammer,
    Polynomial.ascPochhammer_smeval_cast, Polynomial.ascPochhammer_smeval_eq_eval,
    ascPochhammer_eval_neg_eq_descPochhammer, descPochhammer_eval_eq_ascPochhammer]
  ring_nf
  simp

/-- The radius of convergence of `binomialSeries 𝔸 a` is `⊤` for natural `a`. -/
```

<s>[SYSTEM_PROMPT]You are Leanstral, a Lean 4 proof assistant. Complete the task below using the provided Lean source context. The target mathlib commit is 5e932f97dd25535344f80f9dd8da3aab83df0fe6 (module Mathlib.Analysis.Analytic.Order).[/SYSTEM_PROMPT][MODEL_SETTINGS]{"reasoning_effort": "none"}[/MODEL_SETTINGS][INST]Prove the following theorem. The retrieved context below may help.

```lean
lemma analyticOrderAt_deriv_of_pos {𝕜 : Type*} {E : Type*} [NontriviallyNormedField 𝕜] [CharZero 𝕜]
    [NormedAddCommGroup E] [NormedSpace 𝕜 E] [CompleteSpace E] {f : 𝕜 → E} {z₀ : 𝕜}
    (hf : AnalyticAt 𝕜 f z₀) {n : ℕ} (horder : analyticOrderAt f z₀ = n + 1) :
    analyticOrderAt (deriv f) z₀ = n
```

## Retrieved context
-- snippet 1
```lean
-- Mathlib.Analysis.Analytic.Order.analyticOrderAt_of_not_analyticAt (L65-L67)
lemma analyticOrderAt_of_not_analyticAt (hf : ¬ AnalyticAt 𝕜 f z₀) : analyticOrderAt f z₀ = 0 :=
dif_neg hf
```

-- snippet 2
```lean
-- Mathlib.Analysis.Analytic.Order.analyticOrderNatAt_of_not_analyticAt (L69-L71)
lemma analyticOrderNatAt_of_not_analyticAt (hf : ¬ AnalyticAt 𝕜 f z₀) :
    analyticOrderNatAt f z₀ = 0 := by simp [analyticOrderNatAt, hf]
```

-- snippet 3
```lean
-- Mathlib.Analysis.Analytic.Order.analyticOrderAt_eq_top (L76-L79)
lemma analyticOrderAt_eq_top : analyticOrderAt f z₀ = ⊤ ↔ ∀ᶠ z in 𝓝 z₀, f z = 0 where
  mp hf := by unfold analyticOrderAt at hf; split_ifs at hf with h <;> simp [*] at *
mpr hf := by unfold analyticOrderAt; simp [hf, analyticAt_congr hf, analyticAt_const]
```

-- snippet 4
```lean
-- Mathlib.Analysis.Analytic.Order.eventuallyConst_iff_analyticOrderAt_sub_eq_top (L80-L86)
lemma eventuallyConst_iff_analyticOrderAt_sub_eq_top :
    EventuallyConst f (𝓝 z₀) ↔ analyticOrderAt (f · - f z₀) z₀ = ⊤ := by
simpa [eventuallyConst_iff_exists_eventuallyEq, analyticOrderAt_eq_top, sub_eq_zero]
    using ⟨fun ⟨c, hc⟩ ↦ (show f z₀ = c from hc.self_of_nhds) ▸ hc, fun h ↦ ⟨_, h⟩⟩

/-- The order of an analytic function `f` at `z₀` equals a natural number `n` iff `f` can locally
be written as `f z = (z - z₀) ^ n • g z`, where `g` is analytic and does not vanish at `z₀`. -/
```

-- snippet 5
```lean
-- Mathlib.Analysis.Analytic.Order.AnalyticAt (L87-L101)
lemma AnalyticAt.analyticOrderAt_eq_natCast (hf : AnalyticAt 𝕜 f z₀) :
    analyticOrderAt f z₀ = n ↔
      ∃ (g : 𝕜 → E), AnalyticAt 𝕜 g z₀ ∧ g z₀ ≠ 0 ∧ ∀ᶠ z in 𝓝 z₀, f z = (z - z₀) ^ n • g z := by
unfold analyticOrderAt
  split_ifs with h
  · simp only [ENat.top_ne_coe, false_iff]
    contrapose h
    rw [← hf.exists_eventuallyEq_pow_smul_nonzero_iff]
    exact ⟨n, h⟩
  · rw [← hf.exists_eventuallyEq_pow_smul_nonzero_iff] at h
    refine ⟨fun hn ↦ (WithTop.coe_inj.mp hn : h.choose = n) ▸ h.choose_spec, fun h' ↦ ?_⟩
    rw [AnalyticAt.unique_eventuallyEq_pow_smul_nonzero h.choose_spec h']

/-- The order of an analytic function `f` at `z₀` equals a natural number `n` iff `f` can locally
be written as `f z = (z - z₀) ^ n • g z`, where `g` is analytic and does not vanish at `z₀`. -/
```

-- snippet 6
```lean
-- Mathlib.Analysis.Analytic.Order.AnalyticAt (L102-L113)
lemma AnalyticAt.analyticOrderNatAt_eq_iff (hf : AnalyticAt 𝕜 f z₀) (hf' : analyticOrderAt f z₀ ≠ ⊤)
    {n : ℕ} :
    analyticOrderNatAt f z₀ = n ↔
      ∃ (g : 𝕜 → E), AnalyticAt 𝕜 g z₀ ∧ g z₀ ≠ 0 ∧ ∀ᶠ z in 𝓝 z₀, f z = (z - z₀) ^ n • g z := by
simp [← Nat.cast_inj (R := ℕ∞), Nat.cast_analyticOrderNatAt hf', hf.analyticOrderAt_eq_natCast]

/-- The order of an analytic function `f` at `z₀` is finite iff `f` can locally be written as `f z =
  (z - z₀) ^ analyticOrderNatAt f z₀ • g z`, where `g` is analytic and does not vanish at `z₀`.

See `MeromorphicNFAt.order_eq_zero_iff` for an analogous statement about meromorphic functions in
normal form.
-/
```

-- snippet 7
```lean
-- Mathlib.Analysis.Analytic.Order.AnalyticAt (L114-L120)
lemma AnalyticAt.analyticOrderAt_ne_top (hf : AnalyticAt 𝕜 f z₀) :
    analyticOrderAt f z₀ ≠ ⊤ ↔
      ∃ (g : 𝕜 → E), AnalyticAt 𝕜 g z₀ ∧ g z₀ ≠ 0 ∧
        f =ᶠ[𝓝 z₀] fun z ↦ (z - z₀) ^ analyticOrderNatAt f z₀ • g z := by
simp only [← ENat.coe_toNat_eq_self, Eq.comm, EventuallyEq, ← hf.analyticOrderAt_eq_natCast,
    analyticOrderNatAt]
```

-- snippet 8
```lean
-- Mathlib.Analysis.Analytic.Order.analyticOrderAt_eq_zero (L121-L129)
lemma analyticOrderAt_eq_zero : analyticOrderAt f z₀ = 0 ↔ ¬ AnalyticAt 𝕜 f z₀ ∨ f z₀ ≠ 0 := by
by_cases hf : AnalyticAt 𝕜 f z₀
  · rw [← ENat.coe_zero, hf.analyticOrderAt_eq_natCast]
    constructor
    · intro ⟨g, _, _, hg⟩
      simpa [hf, hg.self_of_nhds]
    · exact fun hz ↦ ⟨f, hf, hz.resolve_left <| not_not_intro hf, by simp⟩
  · simp [hf]
```

-- snippet 9
```lean
-- Mathlib.Analysis.Analytic.Order.analyticOrderAt_ne_zero (L130-L141)
lemma analyticOrderAt_ne_zero : analyticOrderAt f z₀ ≠ 0 ↔ AnalyticAt 𝕜 f z₀ ∧ f z₀ = 0 := by
simp [analyticOrderAt_eq_zero]

/-- The order of an analytic function `f` at `z₀` is zero iff `f` does not vanish at `z₀`. -/
protected lemma AnalyticAt.analyticOrderAt_eq_zero (hf : AnalyticAt 𝕜 f z₀) :
    analyticOrderAt f z₀ = 0 ↔ f z₀ ≠ 0 := by simp [hf, analyticOrderAt_eq_zero]

/-- The order of an analytic function `f` at `z₀` is zero iff `f` does not vanish at `z₀`. -/
protected lemma AnalyticAt.analyticOrderAt_ne_zero (hf : AnalyticAt 𝕜 f z₀) :
    analyticOrderAt f z₀ ≠ 0 ↔ f z₀ = 0 := hf.analyticOrderAt_eq_zero.not_left

/-- A function vanishes at a point if its analytic order is nonzero in `ℕ∞`. -/
```

-- snippet 10
```lean
-- Mathlib.Analysis.Analytic.Order.apply_eq_zero_of_analyticOrderAt_ne_zero (L142-L146)
lemma apply_eq_zero_of_analyticOrderAt_ne_zero (hf : analyticOrderAt f z₀ ≠ 0) :
    f z₀ = 0 := by
by_cases hf' : AnalyticAt 𝕜 f z₀ <;> simp_all [analyticOrderAt_eq_zero]

/-- A function vanishes at a point if its analytic order is nonzero when converted to ℕ. -/
```

-- snippet 11
```lean
-- Mathlib.Analysis.Analytic.Order.apply_eq_zero_of_analyticOrderNatAt_ne_zero (L147-L152)
lemma apply_eq_zero_of_analyticOrderNatAt_ne_zero (hf : analyticOrderNatAt f z₀ ≠ 0) :
    f z₀ = 0 := by
by_cases hf' : AnalyticAt 𝕜 f z₀ <;> simp_all [analyticOrderNatAt, analyticOrderAt_eq_zero]

/-- Characterization of which natural numbers are `≤ hf.order`. Useful for avoiding case splits,
since it applies whether or not the order is `∞`. -/
```

-- snippet 12
```lean
-- Mathlib.Analysis.Analytic.Order.natCast_le_analyticOrderAt (L153-L175)
lemma natCast_le_analyticOrderAt (hf : AnalyticAt 𝕜 f z₀) {n : ℕ} :
    n ≤ analyticOrderAt f z₀ ↔
      ∃ g, AnalyticAt 𝕜 g z₀ ∧ ∀ᶠ z in 𝓝 z₀, f z = (z - z₀) ^ n • g z := by
unfold analyticOrderAt
  split_ifs with h
  · simpa using ⟨0, analyticAt_const .., by simpa⟩
  · let m := (hf.exists_eventuallyEq_pow_smul_nonzero_iff.mpr h).choose
    obtain ⟨g, hg, hg_ne, hm⟩ := (hf.exists_eventuallyEq_pow_smul_nonzero_iff.mpr h).choose_spec
    rw [ENat.coe_le_coe]
    refine ⟨fun hmn ↦ ⟨fun z ↦ (z - z₀) ^ (m - n) • g z, by fun_prop, ?_⟩, fun ⟨h, hh, hfh⟩ ↦ ?_⟩
    · filter_upwards [hm] with z hz using by rwa [← mul_smul, ← pow_add, Nat.add_sub_of_le hmn]
    · contrapose! hg_ne
      have : ContinuousAt (fun z ↦ (z - z₀) ^ (n - m) • h z) z₀ := by fun_prop
      rw [tendsto_nhds_unique_of_eventuallyEq (l := 𝓝[≠] z₀)
        hg.continuousAt.continuousWithinAt this.continuousWithinAt ?_]
      · simp [m, Nat.sub_ne_zero_of_lt hg_ne]
      · filter_upwards [self_mem_nhdsWithin, hm.filter_mono nhdsWithin_le_nhds,
          hfh.filter_mono nhdsWithin_le_nhds] with z hz hf' hf''
        rw [← inv_smul_eq_iff₀ (pow_ne_zero _ <| sub_ne_zero_of_ne hz), hf'', smul_comm,
          ← mul_smul] at hf'
        rw [pow_sub₀ _ (sub_ne_zero_of_ne hz) (by lia), ← hf']

/-- If two functions agree in a neighborhood of `z₀`, then their orders at `z₀` agree. -/
```

-- snippet 13
```lean
-- Mathlib.Analysis.Analytic.Order.analyticOrderAt_congr (L176-L185)
lemma analyticOrderAt_congr (hfg : f =ᶠ[𝓝 z₀] g) :
    analyticOrderAt f z₀ = analyticOrderAt g z₀ := by
by_cases hf : AnalyticAt 𝕜 f z₀
  · refine ENat.eq_of_forall_natCast_le_iff fun n ↦ ?_
    simp only [natCast_le_analyticOrderAt, hf, hf.congr hfg]
    congr! 3
    exact hfg.congr_left
  · rw [analyticOrderAt_of_not_analyticAt hf,
      analyticOrderAt_of_not_analyticAt fun hg ↦ hf <| hg.congr hfg.symm]
```

-- snippet 14
```lean
-- Mathlib.Analysis.Analytic.Order.le_analyticOrderAt_add (L198-L208)
theorem le_analyticOrderAt_add :
    min (analyticOrderAt f z₀) (analyticOrderAt g z₀) ≤ analyticOrderAt (f + g) z₀ := by
by_cases hf : AnalyticAt 𝕜 f z₀
  · by_cases hg : AnalyticAt 𝕜 g z₀
    · refine ENat.forall_natCast_le_iff_le.mp fun n ↦ ?_
      simp only [le_min_iff, natCast_le_analyticOrderAt, hf, hg, hf.add hg]
      refine fun ⟨⟨F, hF, hF'⟩, ⟨G, hG, hG'⟩⟩ ↦ ⟨F + G, hF.add hG, ?_⟩
      filter_upwards [hF', hG'] with z using by simp +contextual
    · simp [*]
  · simp [*]
```

-- snippet 15
```lean
-- Mathlib.Analysis.Analytic.Order.le_analyticOrderAt_sub (L209-L212)
lemma le_analyticOrderAt_sub :
    min (analyticOrderAt f z₀) (analyticOrderAt g z₀) ≤ analyticOrderAt (f - g) z₀ := by
simpa [sub_eq_add_neg] using le_analyticOrderAt_add (f := f) (g := -g)
```

-- snippet 16
```lean
-- Mathlib.Analysis.Analytic.Basic.ContinuousLinearMap (L546-L557)
theorem ContinuousLinearMap.comp_hasFPowerSeriesWithinOnBall (g : F →L[𝕜] G)
    (h : HasFPowerSeriesWithinOnBall f p s x r) :
    HasFPowerSeriesWithinOnBall (g ∘ f) (g.compFormalMultilinearSeries p) s x r where
  r_le := h.r_le.trans (p.radius_le_radius_continuousLinearMap_comp _)
r_pos := h.r_pos
  hasSum hy h'y := by
    simpa only [ContinuousLinearMap.compFormalMultilinearSeries_apply,
      ContinuousLinearMap.compContinuousMultilinearMap_coe, Function.comp_apply] using
      g.hasSum (h.hasSum hy h'y)

/-- If a function `f` has a power series `p` on a ball and `g` is linear, then `g ∘ f` has the
power series `g ∘ p` on the same ball. -/
```

-- snippet 17
```lean
-- Mathlib.Analysis.Analytic.Basic.AnalyticWithinAt (L113-L117)
def AnalyticWithinAt (f : E → F) (s : Set E) (x : E) : Prop :=
∃ p : FormalMultilinearSeries 𝕜 E F, HasFPowerSeriesWithinAt f p s x

/-- Given a function `f : E → F`, we say that `f` is analytic on a set `s` if it is analytic around
every point of `s`. -/
```

-- snippet 18
```lean
-- Mathlib.Analysis.Analytic.Basic.AnalyticOn (L123-L131)
def AnalyticOn (f : E → F) (s : Set E) : Prop :=
∀ x ∈ s, AnalyticWithinAt 𝕜 f s x

/-!
### `HasFPowerSeriesOnBall` and `HasFPowerSeriesWithinOnBall`
-/

variable {𝕜}
```

-- snippet 19
```lean
-- Mathlib.Analysis.Analytic.Basic.HasFPowerSeriesWithinAt (L98-L101)
def HasFPowerSeriesWithinAt (f : E → F) (p : FormalMultilinearSeries 𝕜 E F) (s : Set E) (x : E) :=
∃ r, HasFPowerSeriesWithinOnBall f p s x r

-- Teach the `bound` tactic that power series have positive radius
```

-- snippet 20
```lean
-- Mathlib.Analysis.Analytic.Binomial.binomialSeries_radius_eq_top_of_nat (L76-L82)
theorem binomialSeries_radius_eq_top_of_nat {𝕂 : Type v} [RCLike 𝕂] {𝔸 : Type u}
    [NormedDivisionRing 𝔸] [NormedAlgebra 𝕂 𝔸] {a : ℕ} :
    (binomialSeries 𝔸 (a : 𝕂)).radius = ⊤ := by
simp [binomialSeries_eq_ordinaryHypergeometricSeries (b := (1 : 𝕂)) (by norm_cast; simp),
    ordinaryHypergeometric_radius_top_of_neg_nat₁]

/-- The radius of convergence of `binomialSeries 𝔸 a` is `1`, when `a` is not natural. -/
```

-- snippet 21
```lean
-- Mathlib.Analysis.Analytic.Basic.hasFPowerSeriesAt_iff (L1106-L1127)
theorem hasFPowerSeriesAt_iff :
    HasFPowerSeriesAt f p z₀ ↔ ∀ᶠ z in 𝓝 0, HasSum (fun n => z ^ n • p.coeff n) (f (z₀ + z)) := by
refine ⟨fun ⟨r, _, r_pos, h⟩ =>
    eventually_of_mem (Metric.eball_mem_nhds 0 r_pos) fun _ => by simpa using h, ?_⟩
  simp only [Metric.eventually_nhds_iff]
  rintro ⟨r, r_pos, h⟩
  refine ⟨p.radius ⊓ r.toNNReal, by simp, ?_, ?_⟩
  · simp only [r_pos.lt, lt_inf_iff, ENNReal.coe_pos, Real.toNNReal_pos, and_true]
    obtain ⟨z, z_pos, le_z⟩ := NormedField.exists_norm_lt 𝕜 r_pos.lt
    have : (‖z‖₊ : ENNReal) ≤ p.radius := by
      simp only [dist_zero_right] at h
      apply FormalMultilinearSeries.le_radius_of_tendsto
      convert tendsto_norm.comp (h le_z).summable.tendsto_atTop_zero
      simp [norm_smul, mul_comm]
    refine lt_of_lt_of_le ?_ this
    simp only [ENNReal.coe_pos]
    exact zero_lt_iff.mpr (nnnorm_ne_zero_iff.mpr (norm_pos_iff.mp z_pos))
  · simp only [Metric.mem_eball, lt_inf_iff, edist_lt_coe, apply_eq_pow_smul_coeff, and_imp,
      dist_zero_right] at h ⊢
    refine fun {y} _ hyr => h ?_
    simpa [nndist_eq_nnnorm, Real.lt_toNNReal_iff_coe_lt] using hyr
```

-- snippet 22
```lean
-- Mathlib.Analysis.Analytic.Binomial.one_add_cpow_hasFPowerSeriesAt_zero (L152-L155)
theorem one_add_cpow_hasFPowerSeriesAt_zero {a : ℂ} :
    HasFPowerSeriesAt (fun x ↦ (1 + x) ^ a) (binomialSeries ℂ a) 0 :=
one_add_cpow_hasFPowerSeriesOnBall_zero.hasFPowerSeriesAt
```

-- snippet 23
```lean
-- Mathlib.Analysis.Analytic.Binomial.binomialSeries_apply (L54-L58)
theorem binomialSeries_apply {𝕂 : Type u} [Field 𝕂] [CharZero 𝕂] (𝔸 : Type v)
    [Ring 𝔸] [Algebra 𝕂 𝔸] [TopologicalSpace 𝔸] [IsTopologicalRing 𝔸] (a : 𝕂) {n} (v : Fin n → 𝔸) :
    binomialSeries 𝔸 a n v = Ring.choose a n • (List.ofFn v).prod := by
simp [binomialSeries, FormalMultilinearSeries.ofScalars]
```

-- snippet 24
```lean
-- Mathlib.Analysis.Analytic.Binomial.Complex (L41-L52)
lemma Complex.ofReal_choose (a : ℝ) (n : ℕ) :
    ↑(Ring.choose a n) = Ring.choose (a : ℂ) n :=
Ring.map_choose (algebraMap ℝ ℂ) _ _

/-- **Binomial series**: the (scalar) formal multilinear series with coefficients given
by `Ring.choose a`. The sum of this series is `fun x ↦ (1 + x) ^ a` within the radius
of convergence. -/
noncomputable def binomialSeries {𝕂 : Type u} [Field 𝕂] [CharZero 𝕂] (𝔸 : Type v)
    [Ring 𝔸] [Algebra 𝕂 𝔸] [TopologicalSpace 𝔸] [IsTopologicalRing 𝔸] (a : 𝕂) :
    FormalMultilinearSeries 𝕂 𝔸 𝔸 :=
  .ofScalars 𝔸 (Ring.choose a ·)
```

-- snippet 25
```lean
-- Mathlib.Analysis.Analytic.Binomial.binomialSeries_radius_ge_one (L90-L100)
theorem binomialSeries_radius_ge_one {𝕂 : Type*} [RCLike 𝕂] {𝔸 : Type*} [NormedDivisionRing 𝔸]
    [NormedAlgebra 𝕂 𝔸] {a : 𝕂} :
    1 ≤ (binomialSeries 𝔸 a).radius := by
by_cases ha : ∀ (k : ℕ), a ≠ k
  · rw [binomialSeries_radius_eq_one ha]
  · push Not at ha
    rcases ha with ⟨k, rfl⟩
    simp [binomialSeries_radius_eq_top_of_nat]

namespace Complex
```

-- snippet 26
```lean
-- Mathlib.Analysis.Analytic.Basic.AnalyticAt (L109-L112)
def AnalyticAt (f : E → F) (x : E) :=
∃ p : FormalMultilinearSeries 𝕜 E F, HasFPowerSeriesAt f p x

/-- `f` is analytic within `s` at `x` if it has a power series at `x` that converges on `𝓝[s] x` -/
```

-- snippet 27
```lean
-- Mathlib.Analysis.Analytic.Basic.analyticOnNhd_congr' (L506-L508)
theorem analyticOnNhd_congr' (h : f =ᶠ[𝓝ˢ s] g) : AnalyticOnNhd 𝕜 f s ↔ AnalyticOnNhd 𝕜 g s :=
⟨fun hf => hf.congr' h, fun hg => hg.congr' h.symm⟩
```

-- snippet 28
```lean
-- Mathlib.Analysis.Analytic.Basic.hasFPowerSeriesAt_iff' (L1128-L1132)
theorem hasFPowerSeriesAt_iff' :
    HasFPowerSeriesAt f p z₀ ↔ ∀ᶠ z in 𝓝 z₀, HasSum (fun n => (z - z₀) ^ n • p.coeff n) (f z) := by
rw [← map_add_left_nhds_zero, eventually_map, hasFPowerSeriesAt_iff]
  simp_rw [add_sub_cancel_left]
```

-- snippet 29
```lean
-- Mathlib.Analysis.Analytic.Binomial.one_div_one_sub_cpow_hasFPowerSeriesOnBall_zero (L159-L170)
theorem one_div_one_sub_cpow_hasFPowerSeriesOnBall_zero (a : ℂ) :
    HasFPowerSeriesOnBall (fun x ↦ 1 / (1 - x) ^ a)
      (.ofScalars ℂ fun n ↦ Ring.choose (a + n - 1) n) 0 1 := by
have H : ((binomialSeries ℂ (-a)).compContinuousLinearMap (-1)) =
      .ofScalars ℂ fun n ↦ Ring.choose (a + n - 1) n := by
    ext n; simp [FormalMultilinearSeries.compContinuousLinearMap, binomialSeries, Ring.choose_neg,
      Units.smul_def, ← pow_add, ← mul_assoc]
  have : HasFPowerSeriesOnBall (fun x ↦ (1 + x) ^ (-a)) (binomialSeries ℂ (-a : ℂ)) (-0) 1 := by
    simpa using one_add_cpow_hasFPowerSeriesOnBall_zero
  simpa [cpow_neg, Function.comp_def, ← sub_eq_add_neg, H] using
    this.compContinuousLinearMap (u := -1) (x := (0 : ℂ))
```

-- snippet 30
```lean
-- Mathlib.Analysis.Analytic.Binomial.one_add_cpow_hasFPowerSeriesOnBall_zero (L101-L148)
theorem one_add_cpow_hasFPowerSeriesOnBall_zero {a : ℂ} :
    HasFPowerSeriesOnBall (fun x ↦ (1 + x) ^ a) (binomialSeries ℂ a) 0 1 := by
suffices (binomialSeries ℂ a = FormalMultilinearSeries.ofScalars ℂ
      fun n ↦ iteratedDeriv n (fun (x : ℂ) ↦ (1 + x) ^ a) 0 / n !) by
    convert AnalyticOn.hasFPowerSeriesOnSubball _ _ _
    · norm_num
    · -- TODO: use `fun_prop` for this subgoal
      apply AnalyticOn.cpow (analyticOn_const.add analyticOn_id) analyticOn_const
      intro z hz
      apply Complex.mem_slitPlane_of_norm_lt_one
      rw [← ENNReal.ofReal_one, Metric.eball_ofReal] at hz
      simpa using hz
    · rw [← this]
      exact binomialSeries_radius_ge_one
  simp only [binomialSeries, FormalMultilinearSeries.ofScalars_series_eq_iff]
  ext n
  rw [eq_div_iff_mul_eq (by simp [Nat.factorial_ne_zero]), ← nsmul_eq_mul',
    ← Ring.descPochhammer_eq_factorial_smul_choose]
  let B := Metric.ball (0 : ℂ) 1
  suffices Set.EqOn (iteratedDerivWithin n (fun x ↦ (1 + x) ^ a) B)
      (fun x ↦ (descPochhammer ℤ n).smeval a * (1 + x) ^ (a - n)) B by
    specialize this (show 0 ∈ _ by simp [B])
    rw [iteratedDerivWithin_of_isOpen Metric.isOpen_ball (by simp)] at this
    symm
    simpa using this
  induction n with
  | zero => simp [Set.EqOn]
  | succ n ih =>
    have : iteratedDerivWithin (n + 1) (fun (x : ℂ) ↦ (1 + x) ^ a) B =
        derivWithin (iteratedDerivWithin n (fun x ↦ (1 + x) ^ a) B) B := by
      ext z
      rw [iteratedDerivWithin_succ]
    rw [this]
    have : Set.EqOn (derivWithin (iteratedDerivWithin n (fun (x : ℂ) ↦ (1 + x) ^ a) B) B)
        (derivWithin (fun x ↦ (descPochhammer ℤ n).smeval a * (1 + x) ^ (a - ↑n)) B) B := by
      intro z hz
      rw [derivWithin_congr (fun _ hz ↦ ih hz) (ih hz)]
    apply Set.EqOn.trans this
    intro z hz
    simp only [Nat.cast_add, Nat.cast_one, B, derivWithin_of_isOpen Metric.isOpen_ball hz,
      deriv_const_mul_field']
    rw [_root_.deriv_cpow_const (by fun_prop), deriv_const_add', deriv_id'', mul_one,
      show a - (n + 1) = a - n - 1 by ring, ← mul_assoc]
    · congr
      simp [descPochhammer_succ_right, Polynomial.smeval_mul, Polynomial.smeval_natCast]
    · apply Complex.mem_slitPlane_of_norm_lt_one
      simpa [B] using hz
```

-- snippet 31
```lean
-- Mathlib.Analysis.Analytic.Basic.analyticAt_congr (L495-L497)
theorem analyticAt_congr (h : f =ᶠ[𝓝 x] g) : AnalyticAt 𝕜 f x ↔ AnalyticAt 𝕜 g x :=
⟨fun hf ↦ hf.congr h, fun hg ↦ hg.congr h.symm⟩
```

-- snippet 32
```lean
-- Mathlib.Analysis.Analytic.Basic.HasFPowerSeriesAt (L94-L97)
def HasFPowerSeriesAt (f : E → F) (p : FormalMultilinearSeries 𝕜 E F) (x : E) :=
∃ r, HasFPowerSeriesOnBall f p x r

/-- Analogue of `HasFPowerSeriesAt` where convergence is required only on a set `s`. -/
```

-- snippet 33
```lean
-- Mathlib.Analysis.Analytic.Basic.analyticOn_congr (L488-L490)
lemma analyticOn_congr (hs : EqOn f g s) : AnalyticOn 𝕜 f s ↔ AnalyticOn 𝕜 g s :=
⟨fun h ↦ h.congr hs.symm, fun h ↦ h.congr hs⟩
```

-- snippet 34
```lean
-- Mathlib.Analysis.Analytic.Basic.analyticOnNhd_congr (L514-L516)
theorem analyticOnNhd_congr (hs : IsOpen s) (h : s.EqOn f g) : AnalyticOnNhd 𝕜 f s ↔
    AnalyticOnNhd 𝕜 g s := ⟨fun hf => hf.congr hs h, fun hg => hg.congr hs h.symm⟩
```

-- snippet 35
```lean
-- Mathlib.Analysis.Analytic.Binomial.binomialSeries_radius_eq_one (L83-L89)
theorem binomialSeries_radius_eq_one {𝕂 : Type v} [RCLike 𝕂] {𝔸 : Type u} [NormedDivisionRing 𝔸]
    [NormedAlgebra 𝕂 𝔸] {a : 𝕂} (ha : ∀ (k : ℕ), a ≠ k) : (binomialSeries 𝔸 a).radius = 1 := by
simp only [binomialSeries_eq_ordinaryHypergeometricSeries (b := (1 : 𝕂)) (by norm_cast; simp),
    FormalMultilinearSeries.radius_compNeg]
  conv at ha => ext; rw [ne_comm]
  exact ordinaryHypergeometricSeries_radius_eq_one _ _ _ _ (by norm_cast; grind)
```

-- snippet 36
```lean
-- Mathlib.Analysis.Analytic.Basic.AnalyticOnNhd (L118-L122)
def AnalyticOnNhd (f : E → F) (s : Set E) :=
∀ x, x ∈ s → AnalyticAt 𝕜 f x

/-- `f` is analytic within `s` if it is analytic within `s` at each point of `s`.  Note that
this is weaker than `AnalyticOnNhd 𝕜 f s`, as `f` is allowed to be arbitrary outside `s`. -/
```

-- snippet 37
```lean
-- Mathlib.Analysis.Analytic.Basic.hasFPowerSeriesWithinAt_iff_of_nhds (L391-L397)
lemma hasFPowerSeriesWithinAt_iff_of_nhds (f : E → F) (p : FormalMultilinearSeries 𝕜 E F)
    {U : Set E} (hU : U ∈ 𝓝 x) :
    HasFPowerSeriesWithinAt f p U x ↔ HasFPowerSeriesAt f p x := by
rw [← hasFPowerSeriesWithinAt_univ]
  exact ⟨fun h ↦ h.mono_of_mem_nhdsWithin (mem_nhdsWithin_of_mem_nhds hU),
    fun h ↦ h.mono (subset_univ _)⟩
```

-- snippet 38
```lean
-- Mathlib.Analysis.Analytic.Basic.HasFPowerSeriesOnBall (L132-L135)
theorem HasFPowerSeriesOnBall.hasFPowerSeriesAt (hf : HasFPowerSeriesOnBall f p x r) :
    HasFPowerSeriesAt f p x :=
⟨r, hf⟩
```

-- snippet 39
```lean
-- Mathlib.Analysis.Analytic.Basic.HasFPowerSeriesWithinOnBall (L142-L145)
theorem HasFPowerSeriesWithinOnBall.hasFPowerSeriesWithinAt
    (hf : HasFPowerSeriesWithinOnBall f p s x r) : HasFPowerSeriesWithinAt f p s x :=
⟨r, hf⟩
```

-- snippet 40
```lean
-- Mathlib.Analysis.Analytic.Binomial.binomialSeries_eq_ordinaryHypergeometricSeries (L59-L75)
theorem binomialSeries_eq_ordinaryHypergeometricSeries {𝕂 : Type u} [Field 𝕂] [CharZero 𝕂]
    {𝔸 : Type v} [Ring 𝔸] [Algebra 𝕂 𝔸] [TopologicalSpace 𝔸] [IsTopologicalRing 𝔸] {a b : 𝕂}
    (h : ∀ (k : ℕ), (k : 𝕂) ≠ -b) :
    binomialSeries 𝔸 a =
    (ordinaryHypergeometricSeries 𝔸 (-a) b b).compContinuousLinearMap (-(.id _ _)) := by
simp only [binomialSeries, ordinaryHypergeometricSeries,
    FormalMultilinearSeries.ofScalars_comp_neg_id]
  congr! with n
  rw [ordinaryHypergeometricCoefficient,
    mul_inv_cancel_right₀ (by simp [ascPochhammer_eval_eq_zero_iff]; grind)]
  simp only [Ring.choose_eq_smul, Polynomial.descPochhammer_smeval_eq_ascPochhammer,
    Polynomial.ascPochhammer_smeval_cast, Polynomial.ascPochhammer_smeval_eq_eval,
    ascPochhammer_eval_neg_eq_descPochhammer, descPochhammer_eval_eq_ascPochhammer]
  ring_nf
  simp

/-- The radius of convergence of `binomialSeries 𝔸 a` is `⊤` for natural `a`. -/
```
[/INST]


[System] You are Leanstral, a Lean 4 proof assistant. Complete the task below using the provided Lean source context. The target mathlib commit is 5e932f97dd25535344f80f9dd8da3aab83df0fe6 (module Mathlib.Algebra.Algebra.Subalgebra.Tower).

[User]
Prove the following theorem. The retrieved context below may help.

```lean
theorem restrictScalars_top : restrictScalars R (⊤ : Subalgebra S A) = ⊤
```

## Retrieved context
-- snippet 1
```lean
-- Mathlib.Algebra.Algebra.Subalgebra.Tower.lmul_algebraMap (L46-L57)
theorem lmul_algebraMap (x : R) : Algebra.lmul R A (algebraMap R A x) = Algebra.lsmul R R A x :=
Eq.symm <| LinearMap.ext <| smul_def x

end Algebra

namespace IsScalarTower

section Semiring

variable [CommSemiring R] [CommSemiring S] [Semiring A]
variable [Algebra R S] [Algebra S A]
```

-- snippet 2
```lean
-- Mathlib.Algebra.Algebra.Subalgebra.Tower.subalgebra (L58-L62)
instance subalgebra (S₀ : Subalgebra R S) : IsScalarTower S₀ S A :=
of_algebraMap_eq fun _ ↦ rfl

variable [Algebra R A] [IsScalarTower R S A]
```

-- snippet 3
```lean
-- Mathlib.Algebra.Algebra.Subalgebra.Tower.subalgebra' (L63-L82)
instance subalgebra' (S₀ : Subalgebra R S) : IsScalarTower R S₀ A :=
@IsScalarTower.of_algebraMap_eq R S₀ A _ _ _ _ _ _ fun _ ↦
    (IsScalarTower.algebraMap_apply R S A _ :)

end Semiring

end IsScalarTower

namespace Subalgebra

open IsScalarTower

section Semiring

variable {S A B} [CommSemiring R] [CommSemiring S] [Semiring A] [Semiring B]
variable [Algebra R S] [Algebra S A] [Algebra R A] [Algebra S B] [Algebra R B]
variable [IsScalarTower R S A] [IsScalarTower R S B]

/-- Given a tower `A / ↥U / S / R` of algebras, where `U` is an `S`-subalgebra of `A`, reinterpret
`U` as an `R`-subalgebra of `A`. -/
```

-- snippet 4
```lean
-- Mathlib.Algebra.Algebra.Subalgebra.Tower.restrictScalars (L83-L88)
def restrictScalars (U : Subalgebra S A) : Subalgebra R A :=
{ U with
    algebraMap_mem' := fun x ↦ by
      rw [IsScalarTower.algebraMap_apply R S A]
      exact U.algebraMap_mem _ }
```

-- snippet 5
```lean
-- Mathlib.Algebra.Algebra.Subalgebra.Tower.coe_restrictScalars (L90-L92)
theorem coe_restrictScalars {U : Subalgebra S A} : (restrictScalars R U : Set A) = (U : Set A) :=
rfl
```

-- snippet 6
```lean
-- Mathlib.Algebra.Algebra.Subalgebra.Tower.restrictScalars_toSubmodule (L100-L103)
theorem restrictScalars_toSubmodule {U : Subalgebra S A} :
    Subalgebra.toSubmodule (U.restrictScalars R) = U.toSubmodule.restrictScalars R :=
SetLike.coe_injective rfl
```

-- snippet 7
```lean
-- Mathlib.Algebra.Algebra.Subalgebra.Tower.mem_restrictScalars (L105-L107)
theorem mem_restrictScalars {U : Subalgebra S A} {x : A} : x ∈ restrictScalars R U ↔ x ∈ U :=
Iff.rfl
```

-- snippet 8
```lean
-- Mathlib.Algebra.Algebra.Subalgebra.Tower.restrictScalars_injective (L108-L114)
theorem restrictScalars_injective :
    Function.Injective (restrictScalars R : Subalgebra S A → Subalgebra R A) := fun U V H ↦
ext fun x ↦ by rw [← mem_restrictScalars R, H, mem_restrictScalars]

/-- Produces an `R`-algebra map from `U.restrictScalars R` given an `S`-algebra map from `U`.

This is a special case of `AlgHom.restrictScalars` that can be helpful in elaboration. -/
```

-- snippet 9
```lean
-- Mathlib.Algebra.Algebra.Subalgebra.Tower.ofRestrictScalars (L116-L122)
def ofRestrictScalars (U : Subalgebra S A) (f : U →ₐ[S] B) : U.restrictScalars R →ₐ[R] B :=
f.restrictScalars R

end Semiring

section CommSemiring
```

-- snippet 10
```lean
-- Mathlib.Algebra.Algebra.Subalgebra.Tower.range_isScalarTower_toAlgHom (L124-L140)
lemma range_isScalarTower_toAlgHom [CommSemiring R] [CommSemiring A]
    [Algebra R A] (S : Subalgebra R A) :
    LinearMap.range (IsScalarTower.toAlgHom R S A : S →ₗ[R] A) = Subalgebra.toSubmodule S := by
ext
  simp [algebraMap_eq]

end CommSemiring

end Subalgebra

namespace IsScalarTower

open Subalgebra

variable [CommSemiring R] [CommSemiring S] [CommSemiring A]
variable [Algebra R S] [Algebra S A] [Algebra R A] [IsScalarTower R S A]
```

-- snippet 11
```lean
-- Mathlib.Algebra.Algebra.Subalgebra.Tower.adjoin_range_toAlgHom (L141-L148)
theorem adjoin_range_toAlgHom (t : Set A) :
    (Algebra.adjoin (toAlgHom R S A).range t).restrictScalars R =
      (Algebra.adjoin S t).restrictScalars R :=
Subalgebra.ext fun z ↦
    show z ∈ Subsemiring.closure (Set.range (algebraMap (toAlgHom R S A).range A) ∪ t : Set A) ↔
         z ∈ Subsemiring.closure (Set.range (algebraMap S A) ∪ t : Set A) by simp

end IsScalarTower
```

-- snippet 12
```lean
-- Mathlib.Algebra.Algebra.Basic.map_algebraMap_mul (L263-L266)
theorem map_algebraMap_mul (f : A →ₗ[R] B) (a : A) (r : R) :
    f (algebraMap R A r * a) = algebraMap R B r * f a := by
rw [← Algebra.smul_def, ← Algebra.smul_def, map_smul]
```

-- snippet 13
```lean
-- Mathlib.Algebra.Algebra.Basic.algebraMap_ofSubring_apply (L130-L137)
theorem algebraMap_ofSubring_apply {R : Type*} [CommRing R] (S : Subring R) (x : S) :
    algebraMap S R x = x :=
rfl

end SubsemiringAlgebra

/-- Explicit characterization of the submonoid map in the case of an algebra.
`S` is made explicit to help with type inference -/
```

-- snippet 14
```lean
-- Mathlib.Algebra.Algebra.Basic.mem_algebraMapSubmonoid_of_mem (L141-L144)
theorem mem_algebraMapSubmonoid_of_mem {S : Type*} [Semiring S] [Algebra R S] {M : Submonoid R}
    (x : M) : algebraMap R S x ∈ algebraMapSubmonoid S M :=
Set.mem_image_of_mem (algebraMap R S) x.2
```

-- snippet 15
```lean
-- Mathlib.Algebra.Algebra.Basic.algebraMapSubmonoid (L138-L140)
def algebraMapSubmonoid (S : Type*) [Semiring S] [Algebra R S] (M : Submonoid R) : Submonoid S :=
M.map (algebraMap R S)
```

-- snippet 16
```lean
-- Mathlib.Algebra.Algebra.Basic.map_mul_algebraMap (L267-L280)
theorem map_mul_algebraMap (f : A →ₗ[R] B) (a : A) (r : R) :
    f (a * algebraMap R A r) = f a * algebraMap R B r := by
rw [← Algebra.commutes, ← Algebra.commutes, map_algebraMap_mul]

end LinearMap

section Nat

variable {R : Type*} [Semiring R]

-- Lower the priority so that `Algebra.id` is picked most of the time when working with
-- `ℕ`-algebras.
-- TODO: is this still needed?
/-- Semiring ⥤ ℕ-Alg -/
```

-- snippet 17
```lean
-- Mathlib.Algebra.Algebra.Basic.algebraMapSubmonoid_self (L146-L148)
lemma algebraMapSubmonoid_self (M : Submonoid R) : Algebra.algebraMapSubmonoid R M = M :=
Submonoid.map_id M
```

-- snippet 18
```lean
-- Mathlib.Algebra.Algebra.Basic.mul_sub_algebraMap_pow_commutes (L163-L175)
theorem mul_sub_algebraMap_pow_commutes [Ring A] [Algebra R A] (x : A) (r : R) (n : ℕ) :
    x * (x - algebraMap R A r) ^ n = (x - algebraMap R A r) ^ n * x := by
induction n with
  | zero => simp
  | succ n ih =>
    rw [pow_succ', ← mul_assoc, mul_sub_algebraMap_commutes, mul_assoc, ih, ← mul_assoc]

end CommSemiring

section Ring

/-- A `Semiring` that is an `Algebra` over a commutative ring carries a natural `Ring` structure.
See note [reducible non-instances]. -/
```

-- snippet 19
```lean
-- Mathlib.Algebra.Algebra.Basic.algebraMap_end_apply (L222-L224)
theorem algebraMap_end_apply (a : R) (m : M) : algebraMap R (End S M) a m = a • m :=
rfl
```

-- snippet 20
```lean
-- Mathlib.Algebra.Algebra.Basic.algebraMap_ofSubsemiring_apply (L113-L116)
theorem algebraMap_ofSubsemiring_apply (S : C) (x : S) : algebraMap S R x = x :=
rfl

/-- Algebra over a subring. This builds upon `Subring.module`. -/
```

-- snippet 21
```lean
-- Mathlib.Algebra.Algebra.Basic.algebraMap_comp_natCast (L290-L303)
lemma algebraMap_comp_natCast (R A : Type*) [CommSemiring R] [Semiring A] [Algebra R A] :
    algebraMap R A ∘ Nat.cast = Nat.cast := by
ext; simp

end Nat

section Int

variable (R : Type*) [Ring R]

-- Lower the priority so that `Algebra.id` is picked most of the time when working with
-- `ℤ`-algebras.
-- TODO: is this still needed?
/-- Ring ⥤ ℤ-Alg -/
```

-- snippet 22
```lean
-- Mathlib.Algebra.Algebra.Basic.algebraMap_int_eq (L311-L315)
theorem algebraMap_int_eq : algebraMap ℤ R = Int.castRingHom R :=
rfl

variable {R}
```

-- snippet 23
```lean
-- Mathlib.Algebra.Algebra.Basic.End (L212-L215)
instance End.instAlgebra : Algebra R (Module.End S M) :=
Algebra.ofModule smul_mul_assoc fun r f g => (smul_comm r f g).symm

-- to prove this is a special case of the above
```

-- snippet 24
```lean
-- Mathlib.Algebra.Algebra.Basic.semiringToRing (L176-L183)
abbrev semiringToRing (R : Type*) [CommRing R] [Semiring A] [Algebra R A] : Ring A :=
{ __ := (inferInstance : Semiring A)
    __ := Module.addCommMonoidToAddCommGroup R
    intCast := fun z => algebraMap R A z
    intCast_ofNat := fun z => by simp only [Int.cast_natCast, map_natCast]
    intCast_negSucc := fun z => by simp }

/-- The `CommRing` structure on a `CommSemiring` induced by a ring morphism from a `CommRing`. -/
```

-- snippet 25
```lean
-- Mathlib.Algebra.Algebra.Basic.nat_algebra_subsingleton (L286-L288)
instance nat_algebra_subsingleton : Subsingleton (Algebra ℕ R) :=
⟨fun P Q => by ext; simp⟩
```

-- snippet 26
```lean
-- Mathlib.Algebra.Algebra.Basic.coe_algebraMap_ofSubring (L125-L128)
theorem coe_algebraMap_ofSubring {R : Type*} [CommRing R] (S : Subring R) :
    (algebraMap S R : S → R) = Subtype.val :=
rfl
```

-- snippet 27
```lean
-- Mathlib.Algebra.Algebra.Basic.ofSubring (L117-L119)
instance ofSubring {R A : Type*} [CommRing R] [Ring A] [Algebra R A] (S : Subring R) :
    Algebra S A := inferInstance
```

-- snippet 28
```lean
-- Mathlib.Algebra.Algebra.Basic.ker_algebraMap_end (L226-L229)
theorem ker_algebraMap_end (K : Type u) (V : Type v) [Semifield K] [AddCommMonoid V] [Module K V]
    (a : K) (ha : a ≠ 0) : LinearMap.ker ((algebraMap K (End K V)) a) = ⊥ :=
LinearMap.ker_smul _ _ ha
```

-- snippet 29
```lean
-- Mathlib.Algebra.Algebra.Basic.algebraMap_ofSubsemiring (L106-L109)
theorem algebraMap_ofSubsemiring (S : Subsemiring R) :
    (algebraMap S R : S →+* R) = S.subtype :=
rfl
```

-- snippet 30
```lean
-- Mathlib.Algebra.Algebra.Basic.algebraMap_pUnit (L54-L60)
theorem algebraMap_pUnit (r : R) : algebraMap R PUnit r = PUnit.unit :=
rfl

end PUnit

section ULift
```

-- snippet 31
```lean
-- Mathlib.Algebra.Algebra.Basic.algebraMapSubmonoid_powers (L150-L159)
lemma algebraMapSubmonoid_powers {S : Type*} [Semiring S] [Algebra R S] (r : R) :
    Algebra.algebraMapSubmonoid S (.powers r) = Submonoid.powers (algebraMap R S r) := by
simp [Algebra.algebraMapSubmonoid]

end Semiring

section CommSemiring

variable [CommSemiring R]
```

-- snippet 32
```lean
-- Mathlib.Algebra.Algebra.Basic.coe_algebraMap_ofSubsemiring (L110-L112)
theorem coe_algebraMap_ofSubsemiring (S : C) : (algebraMap S R : S → R) = Subtype.val :=
rfl
```

-- snippet 33
```lean
-- Mathlib.Algebra.Algebra.Basic.int_algebra_subsingleton (L316-L318)
instance int_algebra_subsingleton : Subsingleton (Algebra ℤ R) :=
⟨fun P Q => Algebra.algebra_ext P Q <| RingHom.congr_fun <| Subsingleton.elim _ _⟩
```

-- snippet 34
```lean
-- Mathlib.Algebra.Algebra.Basic.algebraMap_end_eq_smul_id (L218-L220)
theorem algebraMap_end_eq_smul_id (a : R) : algebraMap R (End S M) a = a • LinearMap.id :=
rfl
```

-- snippet 35
```lean
-- Mathlib.Algebra.Algebra.Basic.mul_sub_algebraMap_commutes (L160-L162)
theorem mul_sub_algebraMap_commutes [Ring A] [Algebra R A] (x : A) (r : R) :
    x * (x - algebraMap R A r) = (x - algebraMap R A r) * x := by rw [mul_sub, ← commutes, sub_mul]
```

-- snippet 36
```lean
-- Mathlib.Algebra.Algebra.Basic.algebraMap_ofSubring (L120-L123)
theorem algebraMap_ofSubring {R : Type*} [CommRing R] (S : Subring R) :
    (algebraMap S R : S →+* R) = S.subtype :=
rfl
```

<s>[SYSTEM_PROMPT]You are Leanstral, a Lean 4 proof assistant. Complete the task below using the provided Lean source context. The target mathlib commit is 5e932f97dd25535344f80f9dd8da3aab83df0fe6 (module Mathlib.Algebra.Algebra.Subalgebra.Tower).[/SYSTEM_PROMPT][MODEL_SETTINGS]{"reasoning_effort": "none"}[/MODEL_SETTINGS][INST]Prove the following theorem. The retrieved context below may help.

```lean
theorem restrictScalars_top : restrictScalars R (⊤ : Subalgebra S A) = ⊤
```

## Retrieved context
-- snippet 1
```lean
-- Mathlib.Algebra.Algebra.Subalgebra.Tower.lmul_algebraMap (L46-L57)
theorem lmul_algebraMap (x : R) : Algebra.lmul R A (algebraMap R A x) = Algebra.lsmul R R A x :=
Eq.symm <| LinearMap.ext <| smul_def x

end Algebra

namespace IsScalarTower

section Semiring

variable [CommSemiring R] [CommSemiring S] [Semiring A]
variable [Algebra R S] [Algebra S A]
```

-- snippet 2
```lean
-- Mathlib.Algebra.Algebra.Subalgebra.Tower.subalgebra (L58-L62)
instance subalgebra (S₀ : Subalgebra R S) : IsScalarTower S₀ S A :=
of_algebraMap_eq fun _ ↦ rfl

variable [Algebra R A] [IsScalarTower R S A]
```

-- snippet 3
```lean
-- Mathlib.Algebra.Algebra.Subalgebra.Tower.subalgebra' (L63-L82)
instance subalgebra' (S₀ : Subalgebra R S) : IsScalarTower R S₀ A :=
@IsScalarTower.of_algebraMap_eq R S₀ A _ _ _ _ _ _ fun _ ↦
    (IsScalarTower.algebraMap_apply R S A _ :)

end Semiring

end IsScalarTower

namespace Subalgebra

open IsScalarTower

section Semiring

variable {S A B} [CommSemiring R] [CommSemiring S] [Semiring A] [Semiring B]
variable [Algebra R S] [Algebra S A] [Algebra R A] [Algebra S B] [Algebra R B]
variable [IsScalarTower R S A] [IsScalarTower R S B]

/-- Given a tower `A / ↥U / S / R` of algebras, where `U` is an `S`-subalgebra of `A`, reinterpret
`U` as an `R`-subalgebra of `A`. -/
```

-- snippet 4
```lean
-- Mathlib.Algebra.Algebra.Subalgebra.Tower.restrictScalars (L83-L88)
def restrictScalars (U : Subalgebra S A) : Subalgebra R A :=
{ U with
    algebraMap_mem' := fun x ↦ by
      rw [IsScalarTower.algebraMap_apply R S A]
      exact U.algebraMap_mem _ }
```

-- snippet 5
```lean
-- Mathlib.Algebra.Algebra.Subalgebra.Tower.coe_restrictScalars (L90-L92)
theorem coe_restrictScalars {U : Subalgebra S A} : (restrictScalars R U : Set A) = (U : Set A) :=
rfl
```

-- snippet 6
```lean
-- Mathlib.Algebra.Algebra.Subalgebra.Tower.restrictScalars_toSubmodule (L100-L103)
theorem restrictScalars_toSubmodule {U : Subalgebra S A} :
    Subalgebra.toSubmodule (U.restrictScalars R) = U.toSubmodule.restrictScalars R :=
SetLike.coe_injective rfl
```

-- snippet 7
```lean
-- Mathlib.Algebra.Algebra.Subalgebra.Tower.mem_restrictScalars (L105-L107)
theorem mem_restrictScalars {U : Subalgebra S A} {x : A} : x ∈ restrictScalars R U ↔ x ∈ U :=
Iff.rfl
```

-- snippet 8
```lean
-- Mathlib.Algebra.Algebra.Subalgebra.Tower.restrictScalars_injective (L108-L114)
theorem restrictScalars_injective :
    Function.Injective (restrictScalars R : Subalgebra S A → Subalgebra R A) := fun U V H ↦
ext fun x ↦ by rw [← mem_restrictScalars R, H, mem_restrictScalars]

/-- Produces an `R`-algebra map from `U.restrictScalars R` given an `S`-algebra map from `U`.

This is a special case of `AlgHom.restrictScalars` that can be helpful in elaboration. -/
```

-- snippet 9
```lean
-- Mathlib.Algebra.Algebra.Subalgebra.Tower.ofRestrictScalars (L116-L122)
def ofRestrictScalars (U : Subalgebra S A) (f : U →ₐ[S] B) : U.restrictScalars R →ₐ[R] B :=
f.restrictScalars R

end Semiring

section CommSemiring
```

-- snippet 10
```lean
-- Mathlib.Algebra.Algebra.Subalgebra.Tower.range_isScalarTower_toAlgHom (L124-L140)
lemma range_isScalarTower_toAlgHom [CommSemiring R] [CommSemiring A]
    [Algebra R A] (S : Subalgebra R A) :
    LinearMap.range (IsScalarTower.toAlgHom R S A : S →ₗ[R] A) = Subalgebra.toSubmodule S := by
ext
  simp [algebraMap_eq]

end CommSemiring

end Subalgebra

namespace IsScalarTower

open Subalgebra

variable [CommSemiring R] [CommSemiring S] [CommSemiring A]
variable [Algebra R S] [Algebra S A] [Algebra R A] [IsScalarTower R S A]
```

-- snippet 11
```lean
-- Mathlib.Algebra.Algebra.Subalgebra.Tower.adjoin_range_toAlgHom (L141-L148)
theorem adjoin_range_toAlgHom (t : Set A) :
    (Algebra.adjoin (toAlgHom R S A).range t).restrictScalars R =
      (Algebra.adjoin S t).restrictScalars R :=
Subalgebra.ext fun z ↦
    show z ∈ Subsemiring.closure (Set.range (algebraMap (toAlgHom R S A).range A) ∪ t : Set A) ↔
         z ∈ Subsemiring.closure (Set.range (algebraMap S A) ∪ t : Set A) by simp

end IsScalarTower
```

-- snippet 12
```lean
-- Mathlib.Algebra.Algebra.Basic.map_algebraMap_mul (L263-L266)
theorem map_algebraMap_mul (f : A →ₗ[R] B) (a : A) (r : R) :
    f (algebraMap R A r * a) = algebraMap R B r * f a := by
rw [← Algebra.smul_def, ← Algebra.smul_def, map_smul]
```

-- snippet 13
```lean
-- Mathlib.Algebra.Algebra.Basic.algebraMap_ofSubring_apply (L130-L137)
theorem algebraMap_ofSubring_apply {R : Type*} [CommRing R] (S : Subring R) (x : S) :
    algebraMap S R x = x :=
rfl

end SubsemiringAlgebra

/-- Explicit characterization of the submonoid map in the case of an algebra.
`S` is made explicit to help with type inference -/
```

-- snippet 14
```lean
-- Mathlib.Algebra.Algebra.Basic.mem_algebraMapSubmonoid_of_mem (L141-L144)
theorem mem_algebraMapSubmonoid_of_mem {S : Type*} [Semiring S] [Algebra R S] {M : Submonoid R}
    (x : M) : algebraMap R S x ∈ algebraMapSubmonoid S M :=
Set.mem_image_of_mem (algebraMap R S) x.2
```

-- snippet 15
```lean
-- Mathlib.Algebra.Algebra.Basic.algebraMapSubmonoid (L138-L140)
def algebraMapSubmonoid (S : Type*) [Semiring S] [Algebra R S] (M : Submonoid R) : Submonoid S :=
M.map (algebraMap R S)
```

-- snippet 16
```lean
-- Mathlib.Algebra.Algebra.Basic.map_mul_algebraMap (L267-L280)
theorem map_mul_algebraMap (f : A →ₗ[R] B) (a : A) (r : R) :
    f (a * algebraMap R A r) = f a * algebraMap R B r := by
rw [← Algebra.commutes, ← Algebra.commutes, map_algebraMap_mul]

end LinearMap

section Nat

variable {R : Type*} [Semiring R]

-- Lower the priority so that `Algebra.id` is picked most of the time when working with
-- `ℕ`-algebras.
-- TODO: is this still needed?
/-- Semiring ⥤ ℕ-Alg -/
```

-- snippet 17
```lean
-- Mathlib.Algebra.Algebra.Basic.algebraMapSubmonoid_self (L146-L148)
lemma algebraMapSubmonoid_self (M : Submonoid R) : Algebra.algebraMapSubmonoid R M = M :=
Submonoid.map_id M
```

-- snippet 18
```lean
-- Mathlib.Algebra.Algebra.Basic.mul_sub_algebraMap_pow_commutes (L163-L175)
theorem mul_sub_algebraMap_pow_commutes [Ring A] [Algebra R A] (x : A) (r : R) (n : ℕ) :
    x * (x - algebraMap R A r) ^ n = (x - algebraMap R A r) ^ n * x := by
induction n with
  | zero => simp
  | succ n ih =>
    rw [pow_succ', ← mul_assoc, mul_sub_algebraMap_commutes, mul_assoc, ih, ← mul_assoc]

end CommSemiring

section Ring

/-- A `Semiring` that is an `Algebra` over a commutative ring carries a natural `Ring` structure.
See note [reducible non-instances]. -/
```

-- snippet 19
```lean
-- Mathlib.Algebra.Algebra.Basic.algebraMap_end_apply (L222-L224)
theorem algebraMap_end_apply (a : R) (m : M) : algebraMap R (End S M) a m = a • m :=
rfl
```

-- snippet 20
```lean
-- Mathlib.Algebra.Algebra.Basic.algebraMap_ofSubsemiring_apply (L113-L116)
theorem algebraMap_ofSubsemiring_apply (S : C) (x : S) : algebraMap S R x = x :=
rfl

/-- Algebra over a subring. This builds upon `Subring.module`. -/
```

-- snippet 21
```lean
-- Mathlib.Algebra.Algebra.Basic.algebraMap_comp_natCast (L290-L303)
lemma algebraMap_comp_natCast (R A : Type*) [CommSemiring R] [Semiring A] [Algebra R A] :
    algebraMap R A ∘ Nat.cast = Nat.cast := by
ext; simp

end Nat

section Int

variable (R : Type*) [Ring R]

-- Lower the priority so that `Algebra.id` is picked most of the time when working with
-- `ℤ`-algebras.
-- TODO: is this still needed?
/-- Ring ⥤ ℤ-Alg -/
```

-- snippet 22
```lean
-- Mathlib.Algebra.Algebra.Basic.algebraMap_int_eq (L311-L315)
theorem algebraMap_int_eq : algebraMap ℤ R = Int.castRingHom R :=
rfl

variable {R}
```

-- snippet 23
```lean
-- Mathlib.Algebra.Algebra.Basic.End (L212-L215)
instance End.instAlgebra : Algebra R (Module.End S M) :=
Algebra.ofModule smul_mul_assoc fun r f g => (smul_comm r f g).symm

-- to prove this is a special case of the above
```

-- snippet 24
```lean
-- Mathlib.Algebra.Algebra.Basic.semiringToRing (L176-L183)
abbrev semiringToRing (R : Type*) [CommRing R] [Semiring A] [Algebra R A] : Ring A :=
{ __ := (inferInstance : Semiring A)
    __ := Module.addCommMonoidToAddCommGroup R
    intCast := fun z => algebraMap R A z
    intCast_ofNat := fun z => by simp only [Int.cast_natCast, map_natCast]
    intCast_negSucc := fun z => by simp }

/-- The `CommRing` structure on a `CommSemiring` induced by a ring morphism from a `CommRing`. -/
```

-- snippet 25
```lean
-- Mathlib.Algebra.Algebra.Basic.nat_algebra_subsingleton (L286-L288)
instance nat_algebra_subsingleton : Subsingleton (Algebra ℕ R) :=
⟨fun P Q => by ext; simp⟩
```

-- snippet 26
```lean
-- Mathlib.Algebra.Algebra.Basic.coe_algebraMap_ofSubring (L125-L128)
theorem coe_algebraMap_ofSubring {R : Type*} [CommRing R] (S : Subring R) :
    (algebraMap S R : S → R) = Subtype.val :=
rfl
```

-- snippet 27
```lean
-- Mathlib.Algebra.Algebra.Basic.ofSubring (L117-L119)
instance ofSubring {R A : Type*} [CommRing R] [Ring A] [Algebra R A] (S : Subring R) :
    Algebra S A := inferInstance
```

-- snippet 28
```lean
-- Mathlib.Algebra.Algebra.Basic.ker_algebraMap_end (L226-L229)
theorem ker_algebraMap_end (K : Type u) (V : Type v) [Semifield K] [AddCommMonoid V] [Module K V]
    (a : K) (ha : a ≠ 0) : LinearMap.ker ((algebraMap K (End K V)) a) = ⊥ :=
LinearMap.ker_smul _ _ ha
```

-- snippet 29
```lean
-- Mathlib.Algebra.Algebra.Basic.algebraMap_ofSubsemiring (L106-L109)
theorem algebraMap_ofSubsemiring (S : Subsemiring R) :
    (algebraMap S R : S →+* R) = S.subtype :=
rfl
```

-- snippet 30
```lean
-- Mathlib.Algebra.Algebra.Basic.algebraMap_pUnit (L54-L60)
theorem algebraMap_pUnit (r : R) : algebraMap R PUnit r = PUnit.unit :=
rfl

end PUnit

section ULift
```

-- snippet 31
```lean
-- Mathlib.Algebra.Algebra.Basic.algebraMapSubmonoid_powers (L150-L159)
lemma algebraMapSubmonoid_powers {S : Type*} [Semiring S] [Algebra R S] (r : R) :
    Algebra.algebraMapSubmonoid S (.powers r) = Submonoid.powers (algebraMap R S r) := by
simp [Algebra.algebraMapSubmonoid]

end Semiring

section CommSemiring

variable [CommSemiring R]
```

-- snippet 32
```lean
-- Mathlib.Algebra.Algebra.Basic.coe_algebraMap_ofSubsemiring (L110-L112)
theorem coe_algebraMap_ofSubsemiring (S : C) : (algebraMap S R : S → R) = Subtype.val :=
rfl
```

-- snippet 33
```lean
-- Mathlib.Algebra.Algebra.Basic.int_algebra_subsingleton (L316-L318)
instance int_algebra_subsingleton : Subsingleton (Algebra ℤ R) :=
⟨fun P Q => Algebra.algebra_ext P Q <| RingHom.congr_fun <| Subsingleton.elim _ _⟩
```

-- snippet 34
```lean
-- Mathlib.Algebra.Algebra.Basic.algebraMap_end_eq_smul_id (L218-L220)
theorem algebraMap_end_eq_smul_id (a : R) : algebraMap R (End S M) a = a • LinearMap.id :=
rfl
```

-- snippet 35
```lean
-- Mathlib.Algebra.Algebra.Basic.mul_sub_algebraMap_commutes (L160-L162)
theorem mul_sub_algebraMap_commutes [Ring A] [Algebra R A] (x : A) (r : R) :
    x * (x - algebraMap R A r) = (x - algebraMap R A r) * x := by rw [mul_sub, ← commutes, sub_mul]
```

-- snippet 36
```lean
-- Mathlib.Algebra.Algebra.Basic.algebraMap_ofSubring (L120-L123)
theorem algebraMap_ofSubring {R : Type*} [CommRing R] (S : Subring R) :
    (algebraMap S R : S →+* R) = S.subtype :=
rfl
```
[/INST]

mistral-common:Tekken v15 (Mistral chat template, [INST]/[SYSTEM_PROMPT])


[System] You are Leanstral, a Lean 4 proof assistant. Complete the task below using the provided Lean source context. The target mathlib commit is 5e932f97dd25535344f80f9dd8da3aab83df0fe6 (module Mathlib.Order.UpperLower.Basic).

[User]
Prove the following theorem. The retrieved context below may help.

```lean
theorem isLowerSet_setOf : IsLowerSet { a | p a } ↔ Antitone p
```

## Retrieved context
-- snippet 1
```lean
-- Mathlib.Order.UpperLower.Basic.isUpperSet_empty (L39-L40)
theorem isUpperSet_empty : IsUpperSet (∅ : Set α) := fun _ _ _ => id
```

-- snippet 2
```lean
-- Mathlib.Order.UpperLower.Basic.isUpperSet_univ (L42-L43)
theorem isUpperSet_univ : IsUpperSet (univ : Set α) := fun _ _ _ => id
```

-- snippet 3
```lean
-- Mathlib.Order.UpperLower.Basic.IsUpperSet (L45-L46)
theorem IsUpperSet.compl (hs : IsUpperSet s) : IsLowerSet sᶜ := fun _a _b h hb ha => hb <| hs h ha
```

-- snippet 4
```lean
-- Mathlib.Order.UpperLower.Basic.isUpperSet_compl (L48-L52)
theorem isUpperSet_compl : IsUpperSet sᶜ ↔ IsLowerSet s :=
⟨fun h => by
    convert h.compl
    rw [compl_compl], IsLowerSet.compl⟩
```

-- snippet 5
```lean
-- Mathlib.Order.UpperLower.Basic.IsUpperSet (L54-L56)
theorem IsUpperSet.union (hs : IsUpperSet s) (ht : IsUpperSet t) : IsUpperSet (s ∪ t) :=
fun _ _ h => Or.imp (hs h) (ht h)
```

-- snippet 6
```lean
-- Mathlib.Order.UpperLower.Basic.IsUpperSet (L58-L60)
theorem IsUpperSet.inter (hs : IsUpperSet s) (ht : IsUpperSet t) : IsUpperSet (s ∩ t) :=
fun _ _ h => And.imp (hs h) (ht h)
```

-- snippet 7
```lean
-- Mathlib.Order.UpperLower.Basic.isUpperSet_sUnion (L62-L64)
theorem isUpperSet_sUnion {S : Set (Set α)} (hf : ∀ s ∈ S, IsUpperSet s) : IsUpperSet (⋃₀ S) :=
fun _ _ h => Exists.imp fun _ hs => ⟨hs.1, hf _ hs.1 h hs.2⟩
```

-- snippet 8
```lean
-- Mathlib.Order.UpperLower.Basic.isUpperSet_iUnion (L66-L68)
theorem isUpperSet_iUnion {f : ι → Set α} (hf : ∀ i, IsUpperSet (f i)) : IsUpperSet (⋃ i, f i) :=
isUpperSet_sUnion <| forall_mem_range.2 hf
```

-- snippet 9
```lean
-- Mathlib.Order.UpperLower.Basic.isUpperSet_iUnion₂ (L70-L73)
theorem isUpperSet_iUnion₂ {f : ∀ i, κ i → Set α} (hf : ∀ i j, IsUpperSet (f i j)) :
    IsUpperSet (⋃ (i) (j), f i j) :=
isUpperSet_iUnion fun i => isUpperSet_iUnion <| hf i
```

-- snippet 10
```lean
-- Mathlib.Order.UpperLower.Basic.isUpperSet_sInter (L75-L77)
theorem isUpperSet_sInter {S : Set (Set α)} (hf : ∀ s ∈ S, IsUpperSet s) : IsUpperSet (⋂₀ S) :=
fun _ _ h => forall₂_imp fun s hs => hf s hs h
```

-- snippet 11
```lean
-- Mathlib.Order.UpperLower.Basic.isUpperSet_iInter (L79-L81)
theorem isUpperSet_iInter {f : ι → Set α} (hf : ∀ i, IsUpperSet (f i)) : IsUpperSet (⋂ i, f i) :=
isUpperSet_sInter <| forall_mem_range.2 hf
```

-- snippet 12
```lean
-- Mathlib.Order.UpperLower.Basic.isUpperSet_iInter₂ (L83-L86)
theorem isUpperSet_iInter₂ {f : ∀ i, κ i → Set α} (hf : ∀ i j, IsUpperSet (f i j)) :
    IsUpperSet (⋂ (i) (j), f i j) :=
isUpperSet_iInter fun i => isUpperSet_iInter <| hf i
```

-- snippet 13
```lean
-- Mathlib.Order.UpperLower.Basic.isUpperSet_preimage_ofDual_iff (L88-L90)
theorem isUpperSet_preimage_ofDual_iff : IsUpperSet (ofDual ⁻¹' s) ↔ IsLowerSet s :=
Iff.rfl
```

-- snippet 14
```lean
-- Mathlib.Order.UpperLower.Basic.isUpperSet_preimage_toDual_iff (L92-L94)
theorem isUpperSet_preimage_toDual_iff {s : Set αᵒᵈ} : IsUpperSet (toDual ⁻¹' s) ↔ IsLowerSet s :=
Iff.rfl
```

-- snippet 15
```lean
-- Mathlib.Order.UpperLower.Basic.IsUpperSet (L99-L101)
lemma IsUpperSet.isLowerSet_preimage_coe (hs : IsUpperSet s) :
    IsLowerSet ((↑) ⁻¹' t : Set s) ↔ ∀ b ∈ s, ∀ c ∈ t, b ≤ c → b ∈ t := by aesop
```

-- snippet 16
```lean
-- Mathlib.Order.UpperLower.Closure.subset_upperClosure (L54-L55)
theorem subset_upperClosure : s ⊆ upperClosure s := fun x hx => ⟨x, hx, le_rfl⟩
```

-- snippet 17
```lean
-- Mathlib.Order.UpperLower.Closure.upperClosure_univ (L128-L130)
theorem upperClosure_univ : upperClosure (univ : Set α) = ⊥ :=
bot_unique subset_upperClosure
```

-- snippet 18
```lean
-- Mathlib.Order.UpperLower.Closure.upperClosure_union (L131-L133)
theorem upperClosure_union (s t : Set α) : upperClosure (s ∪ t) = upperClosure s ⊓ upperClosure t :=
(@gc_upperClosure_coe α _).l_sup
```

-- snippet 19
```lean
-- Mathlib.Order.UpperLower.Closure.upperClosure_eq_top_iff (L115-L117)
theorem upperClosure_eq_top_iff : upperClosure s = ⊤ ↔ s = ∅ := by
rw [eq_top_iff, le_upperClosure]; simp
```

-- snippet 20
```lean
-- Mathlib.Order.UpperLower.Closure.upperClosure_sUnion (L146-L148)
theorem upperClosure_sUnion (S : Set (Set α)) : upperClosure (⋃₀ S) = ⨅ s ∈ S, upperClosure s := by
simp_rw [sUnion_eq_biUnion, upperClosure_iUnion]
```

-- snippet 21
```lean
-- Mathlib.Order.UpperLower.Closure.mem_upperClosure (L40-L43)
theorem mem_upperClosure : x ∈ upperClosure s ↔ ∃ a ∈ s, a ≤ x :=
Iff.rfl

-- We do not tag this as `simp` to respect the abstraction.
```

-- snippet 22
```lean
-- Mathlib.Order.UpperLower.Closure.upperClosure_singleton (L123-L126)
theorem upperClosure_singleton (a : α) : upperClosure ({a} : Set α) = UpperSet.Ici a := by
ext
  simp
```

-- snippet 23
```lean
-- Mathlib.Order.UpperLower.Closure.lowerClosure_mono (L111-L113)
theorem lowerClosure_mono : Monotone (lowerClosure : Set α → LowerSet α) :=
gc_lowerClosure_coe.monotone_l
```

-- snippet 24
```lean
-- Mathlib.Order.UpperLower.Closure.upperClosure_anti (L108-L110)
theorem upperClosure_anti : Antitone (upperClosure : Set α → UpperSet α) :=
gc_upperClosure_coe.monotone_l
```

-- snippet 25
```lean
-- Mathlib.Order.UpperLower.Closure.instDecidablePredMemUpperClosure (L50-L52)
instance instDecidablePredMemUpperClosure [DecidablePred (∃ a ∈ s, a ≤ ·)] :
    DecidablePred (· ∈ upperClosure s) := ‹DecidablePred _›
```

-- snippet 26
```lean
-- Mathlib.Order.UpperLower.Closure.upperClosure_empty (L119-L121)
theorem upperClosure_empty : upperClosure (∅ : Set α) = ⊤ :=
upperClosure_eq_top_iff.mpr rfl
```

-- snippet 27
```lean
-- Mathlib.Order.UpperLower.Closure.giLowerClosureCoe (L102-L107)
def giLowerClosureCoe : GaloisInsertion (lowerClosure : Set α → LowerSet α) (↑) where
  choice s hs := ⟨s, fun a _b hba ha => hs ⟨a, ha, hba⟩⟩
gc := gc_lowerClosure_coe
  le_l_u _ := subset_lowerClosure
  choice_eq _s hs := SetLike.coe_injective <| subset_lowerClosure.antisymm hs
```

-- snippet 28
```lean
-- Mathlib.Order.UpperLower.Closure.gc_lowerClosure_coe (L90-L93)
theorem gc_lowerClosure_coe :
    GaloisConnection (lowerClosure : Set α → LowerSet α) (↑) := fun _s _t ↦ lowerClosure_le
/-- `upperClosure` forms a reversed Galois insertion with the coercion from upper sets to sets. -/
```

-- snippet 29
```lean
-- Mathlib.Order.UpperLower.Closure.upperClosure (L36-L38)
def upperClosure (s : Set α) : UpperSet α :=
⟨{ x | ∃ a ∈ s, a ≤ x }, fun _ _ hle h => h.imp fun _x hx => ⟨hx.1, hx.2.trans hle⟩⟩
```

-- snippet 30
```lean
-- Mathlib.Order.UpperLower.Closure.UpperSet (L77-L80)
theorem UpperSet.iInf_Ici (s : Set α) : ⨅ a ∈ s, UpperSet.Ici a = upperClosure s := by
ext
  simp
```

-- snippet 31
```lean
-- Mathlib.Order.UpperLower.Closure.upperClosure_min (L57-L59)
theorem upperClosure_min (h : s ⊆ t) (ht : IsUpperSet t) : ↑(upperClosure s) ⊆ t :=
fun _a ⟨_b, hb, hba⟩ => ht hba <| h hb
```

-- snippet 32
```lean
-- Mathlib.Order.UpperLower.Closure.Set (L149-L153)
theorem Set.OrdConnected.upperClosure_inter_lowerClosure (h : s.OrdConnected) :
    ↑(upperClosure s) ∩ ↑(lowerClosure s) = s :=
(subset_inter subset_upperClosure subset_lowerClosure).antisymm'
    fun _a ⟨⟨_b, hb, hba⟩, _c, hc, hac⟩ => h.out hb hc ⟨hba, hac⟩
```

-- snippet 33
```lean
-- Mathlib.Order.UpperLower.Closure.gc_upperClosure_coe (L86-L89)
theorem gc_upperClosure_coe :
    GaloisConnection (toDual ∘ upperClosure : Set α → (UpperSet α)ᵒᵈ) ((↑) ∘ ofDual) :=
fun _s _t ↦ le_upperClosure
```

-- snippet 34
```lean
-- Mathlib.Order.UpperLower.Closure.upperClosure_iUnion (L138-L140)
theorem upperClosure_iUnion (f : ι → Set α) : upperClosure (⋃ i, f i) = ⨅ i, upperClosure (f i) :=
(@gc_upperClosure_coe α _).l_iSup
```

-- snippet 35
```lean
-- Mathlib.Order.UpperLower.Closure.lowerClosure_union (L135-L137)
theorem lowerClosure_union (s t : Set α) : lowerClosure (s ∪ t) = lowerClosure s ⊔ lowerClosure t :=
(@gc_lowerClosure_coe α _).l_sup
```

-- snippet 36
```lean
-- Mathlib.Order.UpperLower.Closure.giUpperClosureCoe (L94-L101)
def giUpperClosureCoe :
    GaloisInsertion (toDual ∘ upperClosure : Set α → (UpperSet α)ᵒᵈ) ((↑) ∘ ofDual) where
  choice s hs := toDual (⟨s, fun a _b hab ha => hs ⟨a, ha, hab⟩⟩ : UpperSet α)
gc := gc_upperClosure_coe
  le_l_u _ := subset_upperClosure
  choice_eq _s hs := ofDual.injective <| SetLike.coe_injective <| subset_upperClosure.antisymm hs

/-- `lowerClosure` forms a Galois insertion with the coercion from lower sets to sets. -/
```

-- snippet 37
```lean
-- Mathlib.Order.UpperLower.Closure.lowerClosure_iUnion (L142-L144)
theorem lowerClosure_iUnion (f : ι → Set α) : lowerClosure (⋃ i, f i) = ⨆ i, lowerClosure (f i) :=
(@gc_lowerClosure_coe α _).l_iSup
```

-- snippet 38
```lean
-- Mathlib.Order.UpperLower.Closure.lowerClosure_le (L82-L85)
lemma lowerClosure_le {t : LowerSet α} : lowerClosure s ≤ t ↔ s ⊆ t :=
⟨fun h ↦ subset_lowerClosure.trans <| LowerSet.coe_subset_coe.2 h,
    fun h ↦ lowerClosure_min h t.lower⟩
```

-- snippet 39
```lean
-- Mathlib.Order.UpperLower.Closure.upperClosure_image (L69-L75)
theorem upperClosure_image (f : α ≃o β) :
    upperClosure (f '' s) = UpperSet.map f (upperClosure s) := by
rw [← f.symm_symm, ← UpperSet.symm_map, f.symm_symm]
  ext
  simp only [SetLike.mem_coe]
  simp [f.le_symm_apply]
```

-- snippet 40
```lean
-- Mathlib.Order.UpperLower.Closure.coe_upperClosure (L45-L48)
theorem coe_upperClosure (s : Set α) : ↑(upperClosure s) = ⋃ a ∈ s, Ici a := by
ext
  simp
```

<s>[SYSTEM_PROMPT]You are Leanstral, a Lean 4 proof assistant. Complete the task below using the provided Lean source context. The target mathlib commit is 5e932f97dd25535344f80f9dd8da3aab83df0fe6 (module Mathlib.Order.UpperLower.Basic).[/SYSTEM_PROMPT][MODEL_SETTINGS]{"reasoning_effort": "none"}[/MODEL_SETTINGS][INST]Prove the following theorem. The retrieved context below may help.

```lean
theorem isLowerSet_setOf : IsLowerSet { a | p a } ↔ Antitone p
```

## Retrieved context
-- snippet 1
```lean
-- Mathlib.Order.UpperLower.Basic.isUpperSet_empty (L39-L40)
theorem isUpperSet_empty : IsUpperSet (∅ : Set α) := fun _ _ _ => id
```

-- snippet 2
```lean
-- Mathlib.Order.UpperLower.Basic.isUpperSet_univ (L42-L43)
theorem isUpperSet_univ : IsUpperSet (univ : Set α) := fun _ _ _ => id
```

-- snippet 3
```lean
-- Mathlib.Order.UpperLower.Basic.IsUpperSet (L45-L46)
theorem IsUpperSet.compl (hs : IsUpperSet s) : IsLowerSet sᶜ := fun _a _b h hb ha => hb <| hs h ha
```

-- snippet 4
```lean
-- Mathlib.Order.UpperLower.Basic.isUpperSet_compl (L48-L52)
theorem isUpperSet_compl : IsUpperSet sᶜ ↔ IsLowerSet s :=
⟨fun h => by
    convert h.compl
    rw [compl_compl], IsLowerSet.compl⟩
```

-- snippet 5
```lean
-- Mathlib.Order.UpperLower.Basic.IsUpperSet (L54-L56)
theorem IsUpperSet.union (hs : IsUpperSet s) (ht : IsUpperSet t) : IsUpperSet (s ∪ t) :=
fun _ _ h => Or.imp (hs h) (ht h)
```

-- snippet 6
```lean
-- Mathlib.Order.UpperLower.Basic.IsUpperSet (L58-L60)
theorem IsUpperSet.inter (hs : IsUpperSet s) (ht : IsUpperSet t) : IsUpperSet (s ∩ t) :=
fun _ _ h => And.imp (hs h) (ht h)
```

-- snippet 7
```lean
-- Mathlib.Order.UpperLower.Basic.isUpperSet_sUnion (L62-L64)
theorem isUpperSet_sUnion {S : Set (Set α)} (hf : ∀ s ∈ S, IsUpperSet s) : IsUpperSet (⋃₀ S) :=
fun _ _ h => Exists.imp fun _ hs => ⟨hs.1, hf _ hs.1 h hs.2⟩
```

-- snippet 8
```lean
-- Mathlib.Order.UpperLower.Basic.isUpperSet_iUnion (L66-L68)
theorem isUpperSet_iUnion {f : ι → Set α} (hf : ∀ i, IsUpperSet (f i)) : IsUpperSet (⋃ i, f i) :=
isUpperSet_sUnion <| forall_mem_range.2 hf
```

-- snippet 9
```lean
-- Mathlib.Order.UpperLower.Basic.isUpperSet_iUnion₂ (L70-L73)
theorem isUpperSet_iUnion₂ {f : ∀ i, κ i → Set α} (hf : ∀ i j, IsUpperSet (f i j)) :
    IsUpperSet (⋃ (i) (j), f i j) :=
isUpperSet_iUnion fun i => isUpperSet_iUnion <| hf i
```

-- snippet 10
```lean
-- Mathlib.Order.UpperLower.Basic.isUpperSet_sInter (L75-L77)
theorem isUpperSet_sInter {S : Set (Set α)} (hf : ∀ s ∈ S, IsUpperSet s) : IsUpperSet (⋂₀ S) :=
fun _ _ h => forall₂_imp fun s hs => hf s hs h
```

-- snippet 11
```lean
-- Mathlib.Order.UpperLower.Basic.isUpperSet_iInter (L79-L81)
theorem isUpperSet_iInter {f : ι → Set α} (hf : ∀ i, IsUpperSet (f i)) : IsUpperSet (⋂ i, f i) :=
isUpperSet_sInter <| forall_mem_range.2 hf
```

-- snippet 12
```lean
-- Mathlib.Order.UpperLower.Basic.isUpperSet_iInter₂ (L83-L86)
theorem isUpperSet_iInter₂ {f : ∀ i, κ i → Set α} (hf : ∀ i j, IsUpperSet (f i j)) :
    IsUpperSet (⋂ (i) (j), f i j) :=
isUpperSet_iInter fun i => isUpperSet_iInter <| hf i
```

-- snippet 13
```lean
-- Mathlib.Order.UpperLower.Basic.isUpperSet_preimage_ofDual_iff (L88-L90)
theorem isUpperSet_preimage_ofDual_iff : IsUpperSet (ofDual ⁻¹' s) ↔ IsLowerSet s :=
Iff.rfl
```

-- snippet 14
```lean
-- Mathlib.Order.UpperLower.Basic.isUpperSet_preimage_toDual_iff (L92-L94)
theorem isUpperSet_preimage_toDual_iff {s : Set αᵒᵈ} : IsUpperSet (toDual ⁻¹' s) ↔ IsLowerSet s :=
Iff.rfl
```

-- snippet 15
```lean
-- Mathlib.Order.UpperLower.Basic.IsUpperSet (L99-L101)
lemma IsUpperSet.isLowerSet_preimage_coe (hs : IsUpperSet s) :
    IsLowerSet ((↑) ⁻¹' t : Set s) ↔ ∀ b ∈ s, ∀ c ∈ t, b ≤ c → b ∈ t := by aesop
```

-- snippet 16
```lean
-- Mathlib.Order.UpperLower.Closure.subset_upperClosure (L54-L55)
theorem subset_upperClosure : s ⊆ upperClosure s := fun x hx => ⟨x, hx, le_rfl⟩
```

-- snippet 17
```lean
-- Mathlib.Order.UpperLower.Closure.upperClosure_univ (L128-L130)
theorem upperClosure_univ : upperClosure (univ : Set α) = ⊥ :=
bot_unique subset_upperClosure
```

-- snippet 18
```lean
-- Mathlib.Order.UpperLower.Closure.upperClosure_union (L131-L133)
theorem upperClosure_union (s t : Set α) : upperClosure (s ∪ t) = upperClosure s ⊓ upperClosure t :=
(@gc_upperClosure_coe α _).l_sup
```

-- snippet 19
```lean
-- Mathlib.Order.UpperLower.Closure.upperClosure_eq_top_iff (L115-L117)
theorem upperClosure_eq_top_iff : upperClosure s = ⊤ ↔ s = ∅ := by
rw [eq_top_iff, le_upperClosure]; simp
```

-- snippet 20
```lean
-- Mathlib.Order.UpperLower.Closure.upperClosure_sUnion (L146-L148)
theorem upperClosure_sUnion (S : Set (Set α)) : upperClosure (⋃₀ S) = ⨅ s ∈ S, upperClosure s := by
simp_rw [sUnion_eq_biUnion, upperClosure_iUnion]
```

-- snippet 21
```lean
-- Mathlib.Order.UpperLower.Closure.mem_upperClosure (L40-L43)
theorem mem_upperClosure : x ∈ upperClosure s ↔ ∃ a ∈ s, a ≤ x :=
Iff.rfl

-- We do not tag this as `simp` to respect the abstraction.
```

-- snippet 22
```lean
-- Mathlib.Order.UpperLower.Closure.upperClosure_singleton (L123-L126)
theorem upperClosure_singleton (a : α) : upperClosure ({a} : Set α) = UpperSet.Ici a := by
ext
  simp
```

-- snippet 23
```lean
-- Mathlib.Order.UpperLower.Closure.lowerClosure_mono (L111-L113)
theorem lowerClosure_mono : Monotone (lowerClosure : Set α → LowerSet α) :=
gc_lowerClosure_coe.monotone_l
```

-- snippet 24
```lean
-- Mathlib.Order.UpperLower.Closure.upperClosure_anti (L108-L110)
theorem upperClosure_anti : Antitone (upperClosure : Set α → UpperSet α) :=
gc_upperClosure_coe.monotone_l
```

-- snippet 25
```lean
-- Mathlib.Order.UpperLower.Closure.instDecidablePredMemUpperClosure (L50-L52)
instance instDecidablePredMemUpperClosure [DecidablePred (∃ a ∈ s, a ≤ ·)] :
    DecidablePred (· ∈ upperClosure s) := ‹DecidablePred _›
```

-- snippet 26
```lean
-- Mathlib.Order.UpperLower.Closure.upperClosure_empty (L119-L121)
theorem upperClosure_empty : upperClosure (∅ : Set α) = ⊤ :=
upperClosure_eq_top_iff.mpr rfl
```

-- snippet 27
```lean
-- Mathlib.Order.UpperLower.Closure.giLowerClosureCoe (L102-L107)
def giLowerClosureCoe : GaloisInsertion (lowerClosure : Set α → LowerSet α) (↑) where
  choice s hs := ⟨s, fun a _b hba ha => hs ⟨a, ha, hba⟩⟩
gc := gc_lowerClosure_coe
  le_l_u _ := subset_lowerClosure
  choice_eq _s hs := SetLike.coe_injective <| subset_lowerClosure.antisymm hs
```

-- snippet 28
```lean
-- Mathlib.Order.UpperLower.Closure.gc_lowerClosure_coe (L90-L93)
theorem gc_lowerClosure_coe :
    GaloisConnection (lowerClosure : Set α → LowerSet α) (↑) := fun _s _t ↦ lowerClosure_le
/-- `upperClosure` forms a reversed Galois insertion with the coercion from upper sets to sets. -/
```

-- snippet 29
```lean
-- Mathlib.Order.UpperLower.Closure.upperClosure (L36-L38)
def upperClosure (s : Set α) : UpperSet α :=
⟨{ x | ∃ a ∈ s, a ≤ x }, fun _ _ hle h => h.imp fun _x hx => ⟨hx.1, hx.2.trans hle⟩⟩
```

-- snippet 30
```lean
-- Mathlib.Order.UpperLower.Closure.UpperSet (L77-L80)
theorem UpperSet.iInf_Ici (s : Set α) : ⨅ a ∈ s, UpperSet.Ici a = upperClosure s := by
ext
  simp
```

-- snippet 31
```lean
-- Mathlib.Order.UpperLower.Closure.upperClosure_min (L57-L59)
theorem upperClosure_min (h : s ⊆ t) (ht : IsUpperSet t) : ↑(upperClosure s) ⊆ t :=
fun _a ⟨_b, hb, hba⟩ => ht hba <| h hb
```

-- snippet 32
```lean
-- Mathlib.Order.UpperLower.Closure.Set (L149-L153)
theorem Set.OrdConnected.upperClosure_inter_lowerClosure (h : s.OrdConnected) :
    ↑(upperClosure s) ∩ ↑(lowerClosure s) = s :=
(subset_inter subset_upperClosure subset_lowerClosure).antisymm'
    fun _a ⟨⟨_b, hb, hba⟩, _c, hc, hac⟩ => h.out hb hc ⟨hba, hac⟩
```

-- snippet 33
```lean
-- Mathlib.Order.UpperLower.Closure.gc_upperClosure_coe (L86-L89)
theorem gc_upperClosure_coe :
    GaloisConnection (toDual ∘ upperClosure : Set α → (UpperSet α)ᵒᵈ) ((↑) ∘ ofDual) :=
fun _s _t ↦ le_upperClosure
```

-- snippet 34
```lean
-- Mathlib.Order.UpperLower.Closure.upperClosure_iUnion (L138-L140)
theorem upperClosure_iUnion (f : ι → Set α) : upperClosure (⋃ i, f i) = ⨅ i, upperClosure (f i) :=
(@gc_upperClosure_coe α _).l_iSup
```

-- snippet 35
```lean
-- Mathlib.Order.UpperLower.Closure.lowerClosure_union (L135-L137)
theorem lowerClosure_union (s t : Set α) : lowerClosure (s ∪ t) = lowerClosure s ⊔ lowerClosure t :=
(@gc_lowerClosure_coe α _).l_sup
```

-- snippet 36
```lean
-- Mathlib.Order.UpperLower.Closure.giUpperClosureCoe (L94-L101)
def giUpperClosureCoe :
    GaloisInsertion (toDual ∘ upperClosure : Set α → (UpperSet α)ᵒᵈ) ((↑) ∘ ofDual) where
  choice s hs := toDual (⟨s, fun a _b hab ha => hs ⟨a, ha, hab⟩⟩ : UpperSet α)
gc := gc_upperClosure_coe
  le_l_u _ := subset_upperClosure
  choice_eq _s hs := ofDual.injective <| SetLike.coe_injective <| subset_upperClosure.antisymm hs

/-- `lowerClosure` forms a Galois insertion with the coercion from lower sets to sets. -/
```

-- snippet 37
```lean
-- Mathlib.Order.UpperLower.Closure.lowerClosure_iUnion (L142-L144)
theorem lowerClosure_iUnion (f : ι → Set α) : lowerClosure (⋃ i, f i) = ⨆ i, lowerClosure (f i) :=
(@gc_lowerClosure_coe α _).l_iSup
```

-- snippet 38
```lean
-- Mathlib.Order.UpperLower.Closure.lowerClosure_le (L82-L85)
lemma lowerClosure_le {t : LowerSet α} : lowerClosure s ≤ t ↔ s ⊆ t :=
⟨fun h ↦ subset_lowerClosure.trans <| LowerSet.coe_subset_coe.2 h,
    fun h ↦ lowerClosure_min h t.lower⟩
```

-- snippet 39
```lean
-- Mathlib.Order.UpperLower.Closure.upperClosure_image (L69-L75)
theorem upperClosure_image (f : α ≃o β) :
    upperClosure (f '' s) = UpperSet.map f (upperClosure s) := by
rw [← f.symm_symm, ← UpperSet.symm_map, f.symm_symm]
  ext
  simp only [SetLike.mem_coe]
  simp [f.le_symm_apply]
```

-- snippet 40
```lean
-- Mathlib.Order.UpperLower.Closure.coe_upperClosure (L45-L48)
theorem coe_upperClosure (s : Set α) : ↑(upperClosure s) = ⋃ a ∈ s, Ici a := by
ext
  simp
```
[/INST]