l3lab/ntp-mathlib huggingface dataset:
/-- Let `g : γ → β` be an injective function and `f : β → α` be a function from the codomain of `g`
to a commutative monoid. Suppose that `f x = 1` outside of the range of `g`. Then the filters
`atTop.map (fun s ↦ ∏ i in s, f (g i))` and `atTop.map (fun s ↦ ∏ i in s, f i)` coincide.

The additive version of this lemma is used to prove the equality `∑' x, f (g x) = ∑' y, f y` under
the same assumptions.-/
@[to_additive]
theorem Function.Injective.map_atTop_finset_prod_eq [CommMonoid α] {g : γ → β}
    (hg : Function.Injective g) {f : β → α} (hf : ∀ x, x ∉ Set.range g → f x = 1) :
    map (fun s => ∏ i in s, f (g i)) atTop = map (fun s => ∏ i in s, f i) atTop := by
  haveI := Classical.decEq β
  apply le_antisymm <;> refine' map_atTop_finset_prod_le_of_prod_eq fun s => _
  · refine' ⟨s.preimage g (hg.injOn _), fun t ht => _⟩
    refine' ⟨t.image g ∪ s, Finset.subset_union_right _ _, _⟩
    rw [← Finset.prod_image (hg.injOn _)]
    refine' (prod_subset (subset_union_left _ _) _).symm
    

Proof state:
case a
ι : Type u_1
ι' : Type u_2
α : Type u_3
β : Type u_4
γ : Type u_5
inst✝ : CommMonoid α
g : γ → β
hg : Injective g
f : β → α
hf : ∀ x ∉ Set.range g, f x = 1
this : DecidableEq β
s : Finset β
t : Finset γ
ht : Finset.preimage s g (_ : InjOn g (g ⁻¹' ↑s)) ⊆ t
⊢ ∀ x ∈ Finset.image g t ∪ s, x ∉ Finset.image g t → f x = 1

Next tactic:
simp only [Finset.mem_union, Finset.mem_image]
/-- Let `g : γ → β` be an injective function and `f : β → α` be a function from the codomain of `g`
to a commutative monoid. Suppose that `f x = 1` outside of the range of `g`. Then the filters
`atTop.map (fun s ↦ ∏ i in s, f (g i))` and `atTop.map (fun s ↦ ∏ i in s, f i)` coincide.

The additive version of this lemma is used to prove the equality `∑' x, f (g x) = ∑' y, f y` under
the same assumptions.-/
@[to_additive]
theorem Function.Injective.map_atTop_finset_prod_eq [CommMonoid α] {g : γ → β}
    (hg : Function.Injective g) {f : β → α} (hf : ∀ x, x ∉ Set.range g → f x = 1) :
    map (fun s => ∏ i in s, f (g i)) atTop = map (fun s => ∏ i in s, f i) atTop := by
  haveI := Classical.decEq β
  apply le_antisymm <;> refine' map_atTop_finset_prod_le_of_prod_eq fun s => _
  · refine' ⟨s.preimage g (hg.injOn _), fun t ht => _⟩
    refine' ⟨t.image g ∪ s, Finset.subset_union_right _ _, _⟩
    rw [← Finset.prod_image (hg.injOn _)]
    refine' (prod_subset (subset_union_left _ _) _).symm
    simp only [Finset.mem_union, Finset.mem_image]
    

Proof state:
case a
ι : Type u_1
ι' : Type u_2
α : Type u_3
β : Type u_4
γ : Type u_5
inst✝ : CommMonoid α
g : γ → β
hg : Injective g
f : β → α
hf : ∀ x ∉ Set.range g, f x = 1
this : DecidableEq β
s : Finset β
t : Finset γ
ht : Finset.preimage s g (_ : InjOn g (g ⁻¹' ↑s)) ⊆ t
⊢ ∀ (x : β), (∃ a ∈ t, g a = x) ∨ x ∈ s → (¬∃ a ∈ t, g a = x) → f x = 1

Next tactic:
refine' fun y hy hyt => hf y (mt _ hyt)
/-- Let `g : γ → β` be an injective function and `f : β → α` be a function from the codomain of `g`
to a commutative monoid. Suppose that `f x = 1` outside of the range of `g`. Then the filters
`atTop.map (fun s ↦ ∏ i in s, f (g i))` and `atTop.map (fun s ↦ ∏ i in s, f i)` coincide.

The additive version of this lemma is used to prove the equality `∑' x, f (g x) = ∑' y, f y` under
the same assumptions.-/
@[to_additive]
theorem Function.Injective.map_atTop_finset_prod_eq [CommMonoid α] {g : γ → β}
    (hg : Function.Injective g) {f : β → α} (hf : ∀ x, x ∉ Set.range g → f x = 1) :
    map (fun s => ∏ i in s, f (g i)) atTop = map (fun s => ∏ i in s, f i) atTop := by
  haveI := Classical.decEq β
  apply le_antisymm <;> refine' map_atTop_finset_prod_le_of_prod_eq fun s => _
  · refine' ⟨s.preimage g (hg.injOn _), fun t ht => _⟩
    refine' ⟨t.image g ∪ s, Finset.subset_union_right _ _, _⟩
    rw [← Finset.prod_image (hg.injOn _)]
    refine' (prod_subset (subset_union_left _ _) _).symm
    simp only [Finset.mem_union, Finset.mem_image]
    refine' fun y hy hyt => hf y (mt _ hyt)
    

Proof state:
case a
ι : Type u_1
ι' : Type u_2
α : Type u_3
β : Type u_4
γ : Type u_5
inst✝ : CommMonoid α
g : γ → β
hg : Injective g
f : β → α
hf : ∀ x ∉ Set.range g, f x = 1
this : DecidableEq β
s : Finset β
t : Finset γ
ht : Finset.preimage s g (_ : InjOn g (g ⁻¹' ↑s)) ⊆ t
y : β
hy : (∃ a ∈ t, g a = y) ∨ y ∈ s
hyt : ¬∃ a ∈ t, g a = y
⊢ y ∈ Set.range g → ∃ a ∈ t, g a = y

Next tactic:
rintro ⟨x, rfl⟩
/-- Let `g : γ → β` be an injective function and `f : β → α` be a function from the codomain of `g`
to a commutative monoid. Suppose that `f x = 1` outside of the range of `g`. Then the filters
`atTop.map (fun s ↦ ∏ i in s, f (g i))` and `atTop.map (fun s ↦ ∏ i in s, f i)` coincide.

The additive version of this lemma is used to prove the equality `∑' x, f (g x) = ∑' y, f y` under
the same assumptions.-/
@[to_additive]
theorem Function.Injective.map_atTop_finset_prod_eq [CommMonoid α] {g : γ → β}
    (hg : Function.Injective g) {f : β → α} (hf : ∀ x, x ∉ Set.range g → f x = 1) :
    map (fun s => ∏ i in s, f (g i)) atTop = map (fun s => ∏ i in s, f i) atTop := by
  haveI := Classical.decEq β
  apply le_antisymm <;> refine' map_atTop_finset_prod_le_of_prod_eq fun s => _
  · refine' ⟨s.preimage g (hg.injOn _), fun t ht => _⟩
    refine' ⟨t.image g ∪ s, Finset.subset_union_right _ _, _⟩
    rw [← Finset.prod_image (hg.injOn _)]
    refine' (prod_subset (subset_union_left _ _) _).symm
    simp only [Finset.mem_union, Finset.mem_image]
    refine' fun y hy hyt => hf y (mt _ hyt)
    rintro ⟨x, rfl⟩
    

Proof state:
case a.intro
ι : Type u_1
ι' : Type u_2
α : Type u_3
β : Type u_4
γ : Type u_5
inst✝ : CommMonoid α
g : γ → β
hg : Injective g
f : β → α
hf : ∀ x ∉ Set.range g, f x = 1
this : DecidableEq β
s : Finset β
t : Finset γ
ht : Finset.preimage s g (_ : InjOn g (g ⁻¹' ↑s)) ⊆ t
x : γ
hy : (∃ a ∈ t, g a = g x) ∨ g x ∈ s
hyt : ¬∃ a ∈ t, g a = g x
⊢ ∃ a ∈ t, g a = g x

Next tactic:
exact ⟨x, ht (Finset.mem_preimage.2 <| hy.resolve_left hyt), rfl⟩
/-- Let `g : γ → β` be an injective function and `f : β → α` be a function from the codomain of `g`
to a commutative monoid. Suppose that `f x = 1` outside of the range of `g`. Then the filters
`atTop.map (fun s ↦ ∏ i in s, f (g i))` and `atTop.map (fun s ↦ ∏ i in s, f i)` coincide.

The additive version of this lemma is used to prove the equality `∑' x, f (g x) = ∑' y, f y` under
the same assumptions.-/
@[to_additive]
theorem Function.Injective.map_atTop_finset_prod_eq [CommMonoid α] {g : γ → β}
    (hg : Function.Injective g) {f : β → α} (hf : ∀ x, x ∉ Set.range g → f x = 1) :
    map (fun s => ∏ i in s, f (g i)) atTop = map (fun s => ∏ i in s, f i) atTop := by
  haveI := Classical.decEq β
  apply le_antisymm <;> refine' map_atTop_finset_prod_le_of_prod_eq fun s => _
  · refine' ⟨s.preimage g (hg.injOn _), fun t ht => _⟩
    refine' ⟨t.image g ∪ s, Finset.subset_union_right _ _, _⟩
    rw [← Finset.prod_image (hg.injOn _)]
    refine' (prod_subset (subset_union_left _ _) _).symm
    simp only [Finset.mem_union, Finset.mem_image]
    refine' fun y hy hyt => hf y (mt _ hyt)
    rintro ⟨x, rfl⟩
    exact ⟨x, ht (Finset.mem_preimage.2 <| hy.resolve_left hyt), rfl⟩
  · 

Proof state:
case a
ι : Type u_1
ι' : Type u_2
α : Type u_3
β : Type u_4
γ : Type u_5
inst✝ : CommMonoid α
g : γ → β
hg : Injective g
f : β → α
hf : ∀ x ∉ Set.range g, f x = 1
this : DecidableEq β
s : Finset γ
⊢ ∃ v, ∀ (v' : Finset β), v ⊆ v' → ∃ u', s ⊆ u' ∧ ∏ x in u', f (g x) = ∏ b in v', f b

Next tactic:
refine' ⟨s.image g, fun t ht => _⟩
/-- Let `g : γ → β` be an injective function and `f : β → α` be a function from the codomain of `g`
to a commutative monoid. Suppose that `f x = 1` outside of the range of `g`. Then the filters
`atTop.map (fun s ↦ ∏ i in s, f (g i))` and `atTop.map (fun s ↦ ∏ i in s, f i)` coincide.

The additive version of this lemma is used to prove the equality `∑' x, f (g x) = ∑' y, f y` under
the same assumptions.-/
@[to_additive]
theorem Function.Injective.map_atTop_finset_prod_eq [CommMonoid α] {g : γ → β}
    (hg : Function.Injective g) {f : β → α} (hf : ∀ x, x ∉ Set.range g → f x = 1) :
    map (fun s => ∏ i in s, f (g i)) atTop = map (fun s => ∏ i in s, f i) atTop := by
  haveI := Classical.decEq β
  apply le_antisymm <;> refine' map_atTop_finset_prod_le_of_prod_eq fun s => _
  · refine' ⟨s.preimage g (hg.injOn _), fun t ht => _⟩
    refine' ⟨t.image g ∪ s, Finset.subset_union_right _ _, _⟩
    rw [← Finset.prod_image (hg.injOn _)]
    refine' (prod_subset (subset_union_left _ _) _).symm
    simp only [Finset.mem_union, Finset.mem_image]
    refine' fun y hy hyt => hf y (mt _ hyt)
    rintro ⟨x, rfl⟩
    exact ⟨x, ht (Finset.mem_preimage.2 <| hy.resolve_left hyt), rfl⟩
  · refine' ⟨s.image g, fun t ht => _⟩
    

Proof state:
case a
ι : Type u_1
ι' : Type u_2
α : Type u_3
β : Type u_4
γ : Type u_5
inst✝ : CommMonoid α
g : γ → β
hg : Injective g
f : β → α
hf : ∀ x ∉ Set.range g, f x = 1
this : DecidableEq β
s : Finset γ
t : Finset β
ht : Finset.image g s ⊆ t
⊢ ∃ u', s ⊆ u' ∧ ∏ x in u', f (g x) = ∏ b in t, f b

Next tactic:
simp only [← prod_preimage _ _ (hg.injOn _) _ fun x _ => hf x]
/-- Let `g : γ → β` be an injective function and `f : β → α` be a function from the codomain of `g`
to a commutative monoid. Suppose that `f x = 1` outside of the range of `g`. Then the filters
`atTop.map (fun s ↦ ∏ i in s, f (g i))` and `atTop.map (fun s ↦ ∏ i in s, f i)` coincide.

The additive version of this lemma is used to prove the equality `∑' x, f (g x) = ∑' y, f y` under
the same assumptions.-/
@[to_additive]
theorem Function.Injective.map_atTop_finset_prod_eq [CommMonoid α] {g : γ → β}
    (hg : Function.Injective g) {f : β → α} (hf : ∀ x, x ∉ Set.range g → f x = 1) :
    map (fun s => ∏ i in s, f (g i)) atTop = map (fun s => ∏ i in s, f i) atTop := by
  haveI := Classical.decEq β
  apply le_antisymm <;> refine' map_atTop_finset_prod_le_of_prod_eq fun s => _
  · refine' ⟨s.preimage g (hg.injOn _), fun t ht => _⟩
    refine' ⟨t.image g ∪ s, Finset.subset_union_right _ _, _⟩
    rw [← Finset.prod_image (hg.injOn _)]
    refine' (prod_subset (subset_union_left _ _) _).symm
    simp only [Finset.mem_union, Finset.mem_image]
    refine' fun y hy hyt => hf y (mt _ hyt)
    rintro ⟨x, rfl⟩
    exact ⟨x, ht (Finset.mem_preimage.2 <| hy.resolve_left hyt), rfl⟩
  · refine' ⟨s.image g, fun t ht => _⟩
    simp only [← prod_preimage _ _ (hg.injOn _) _ fun x _ => hf x]
    

Proof state:
case a
ι : Type u_1
ι' : Type u_2
α : Type u_3
β : Type u_4
γ : Type u_5
inst✝ : CommMonoid α
g : γ → β
hg : Injective g
f : β → α
hf : ∀ x ∉ Set.range g, f x = 1
this : DecidableEq β
s : Finset γ
t : Finset β
ht : Finset.image g s ⊆ t
⊢ ∃ u', s ⊆ u' ∧ ∏ x in u', f (g x) = ∏ x in Finset.preimage t g (_ : InjOn g (g ⁻¹' ↑t)), f (g x)

Next tactic:
exact ⟨_, (image_subset_iff_subset_preimage _).1 ht, rfl⟩
/-- If a function is `C^n` with `1 ≤ n` around a point, and its derivative at that point is given to
us as `f'`, then `f'` is also a strict derivative. -/
theorem ContDiffAt.hasStrictFDerivAt' {f : E' → F'} {f' : E' →L[𝕂] F'} {x : E'}
    (hf : ContDiffAt 𝕂 n f x) (hf' : HasFDerivAt f f' x) (hn : 1 ≤ n) :
    HasStrictFDerivAt f f' x := by
  

Proof state:
n : ℕ∞
𝕂 : Type u_1
inst✝⁴ : IsROrC 𝕂
E' : Type u_2
inst✝³ : NormedAddCommGroup E'
inst✝² : NormedSpace 𝕂 E'
F' : Type u_3
inst✝¹ : NormedAddCommGroup F'
inst✝ : NormedSpace 𝕂 F'
f : E' → F'
f' : E' →L[𝕂] F'
x : E'
hf : ContDiffAt 𝕂 n f x
hf' : HasFDerivAt f f' x
hn : 1 ≤ n
⊢ HasStrictFDerivAt f f' x

Next tactic:
rcases hf 1 hn with ⟨u, H, p, hp⟩
/-- If a function is `C^n` with `1 ≤ n` around a point, and its derivative at that point is given to
us as `f'`, then `f'` is also a strict derivative. -/
theorem ContDiffAt.hasStrictFDerivAt' {f : E' → F'} {f' : E' →L[𝕂] F'} {x : E'}
    (hf : ContDiffAt 𝕂 n f x) (hf' : HasFDerivAt f f' x) (hn : 1 ≤ n) :
    HasStrictFDerivAt f f' x := by
  rcases hf 1 hn with ⟨u, H, p, hp⟩
  

Proof state:
case intro.intro.intro
n : ℕ∞
𝕂 : Type u_1
inst✝⁴ : IsROrC 𝕂
E' : Type u_2
inst✝³ : NormedAddCommGroup E'
inst✝² : NormedSpace 𝕂 E'
F' : Type u_3
inst✝¹ : NormedAddCommGroup F'
inst✝ : NormedSpace 𝕂 F'
f : E' → F'
f' : E' →L[𝕂] F'
x : E'
hf : ContDiffAt 𝕂 n f x
hf' : HasFDerivAt f f' x
hn : 1 ≤ n
u : Set E'
H : u ∈ 𝓝[insert x univ] x
p : E' → FormalMultilinearSeries 𝕂 E' F'
hp : HasFTaylorSeriesUpToOn (↑1) f p u
⊢ HasStrictFDerivAt f f' x

Next tactic:
simp only [nhdsWithin_univ, mem_univ, insert_eq_of_mem] at H
/-- If a function is `C^n` with `1 ≤ n` around a point, and its derivative at that point is given to
us as `f'`, then `f'` is also a strict derivative. -/
theorem ContDiffAt.hasStrictFDerivAt' {f : E' → F'} {f' : E' →L[𝕂] F'} {x : E'}
    (hf : ContDiffAt 𝕂 n f x) (hf' : HasFDerivAt f f' x) (hn : 1 ≤ n) :
    HasStrictFDerivAt f f' x := by
  rcases hf 1 hn with ⟨u, H, p, hp⟩
  simp only [nhdsWithin_univ, mem_univ, insert_eq_of_mem] at H
  

Proof state:
case intro.intro.intro
n : ℕ∞
𝕂 : Type u_1
inst✝⁴ : IsROrC 𝕂
E' : Type u_2
inst✝³ : NormedAddCommGroup E'
inst✝² : NormedSpace 𝕂 E'
F' : Type u_3
inst✝¹ : NormedAddCommGroup F'
inst✝ : NormedSpace 𝕂 F'
f : E' → F'
f' : E' →L[𝕂] F'
x : E'
hf : ContDiffAt 𝕂 n f x
hf' : HasFDerivAt f f' x
hn : 1 ≤ n
u : Set E'
p : E' → FormalMultilinearSeries 𝕂 E' F'
hp : HasFTaylorSeriesUpToOn (↑1) f p u
H : u ∈ 𝓝 x
⊢ HasStrictFDerivAt f f' x

Next tactic:
have := hp.hasStrictFDerivAt le_rfl H
/-- If a function is `C^n` with `1 ≤ n` around a point, and its derivative at that point is given to
us as `f'`, then `f'` is also a strict derivative. -/
theorem ContDiffAt.hasStrictFDerivAt' {f : E' → F'} {f' : E' →L[𝕂] F'} {x : E'}
    (hf : ContDiffAt 𝕂 n f x) (hf' : HasFDerivAt f f' x) (hn : 1 ≤ n) :
    HasStrictFDerivAt f f' x := by
  rcases hf 1 hn with ⟨u, H, p, hp⟩
  simp only [nhdsWithin_univ, mem_univ, insert_eq_of_mem] at H
  have := hp.hasStrictFDerivAt le_rfl H
  

Proof state:
case intro.intro.intro
n : ℕ∞
𝕂 : Type u_1
inst✝⁴ : IsROrC 𝕂
E' : Type u_2
inst✝³ : NormedAddCommGroup E'
inst✝² : NormedSpace 𝕂 E'
F' : Type u_3
inst✝¹ : NormedAddCommGroup F'
inst✝ : NormedSpace 𝕂 F'
f : E' → F'
f' : E' →L[𝕂] F'
x : E'
hf : ContDiffAt 𝕂 n f x
hf' : HasFDerivAt f f' x
hn : 1 ≤ n
u : Set E'
p : E' → FormalMultilinearSeries 𝕂 E' F'
hp : HasFTaylorSeriesUpToOn (↑1) f p u
H : u ∈ 𝓝 x
this : HasStrictFDerivAt f ((continuousMultilinearCurryFin1 𝕂 E' F') (p x 1)) x
⊢ HasStrictFDerivAt f f' x

Next tactic:
rwa [hf'.unique this.hasFDerivAt]
/-- If `f` has a formal Taylor series `p` up to order `1` on `{x} ∪ s`, where `s` is a convex set,
and `‖p x 1‖₊ < K`, then `f` is `K`-Lipschitz in a neighborhood of `x` within `s`. -/
theorem HasFTaylorSeriesUpToOn.exists_lipschitzOnWith_of_nnnorm_lt {E F : Type*}
    [NormedAddCommGroup E] [NormedSpace ℝ E] [NormedAddCommGroup F] [NormedSpace ℝ F] {f : E → F}
    {p : E → FormalMultilinearSeries ℝ E F} {s : Set E} {x : E}
    (hf : HasFTaylorSeriesUpToOn 1 f p (insert x s)) (hs : Convex ℝ s) (K : ℝ≥0)
    (hK : ‖p x 1‖₊ < K) : ∃ t ∈ 𝓝[s] x, LipschitzOnWith K f t := by
  

Proof state:
n : ℕ∞
𝕂 : Type u_1
inst✝⁸ : IsROrC 𝕂
E' : Type u_2
inst✝⁷ : NormedAddCommGroup E'
inst✝⁶ : NormedSpace 𝕂 E'
F' : Type u_3
inst✝⁵ : NormedAddCommGroup F'
inst✝⁴ : NormedSpace 𝕂 F'
E : Type u_4
F : Type u_5
inst✝³ : NormedAddCommGroup E
inst✝² : NormedSpace ℝ E
inst✝¹ : NormedAddCommGroup F
inst✝ : NormedSpace ℝ F
f : E → F
p : E → FormalMultilinearSeries ℝ E F
s : Set E
x : E
hf : HasFTaylorSeriesUpToOn 1 f p (insert x s)
hs : Convex ℝ s
K : ℝ≥0
hK : ‖p x 1‖₊ < K
⊢ ∃ t ∈ 𝓝[s] x, LipschitzOnWith K f t

Next tactic:
set f' := fun y => continuousMultilinearCurryFin1 ℝ E F (p y 1)
/-- If `f` has a formal Taylor series `p` up to order `1` on `{x} ∪ s`, where `s` is a convex set,
and `‖p x 1‖₊ < K`, then `f` is `K`-Lipschitz in a neighborhood of `x` within `s`. -/
theorem HasFTaylorSeriesUpToOn.exists_lipschitzOnWith_of_nnnorm_lt {E F : Type*}
    [NormedAddCommGroup E] [NormedSpace ℝ E] [NormedAddCommGroup F] [NormedSpace ℝ F] {f : E → F}
    {p : E → FormalMultilinearSeries ℝ E F} {s : Set E} {x : E}
    (hf : HasFTaylorSeriesUpToOn 1 f p (insert x s)) (hs : Convex ℝ s) (K : ℝ≥0)
    (hK : ‖p x 1‖₊ < K) : ∃ t ∈ 𝓝[s] x, LipschitzOnWith K f t := by
  set f' := fun y => continuousMultilinearCurryFin1 ℝ E F (p y 1)
  

Proof state:
n : ℕ∞
𝕂 : Type u_1
inst✝⁸ : IsROrC 𝕂
E' : Type u_2
inst✝⁷ : NormedAddCommGroup E'
inst✝⁶ : NormedSpace 𝕂 E'
F' : Type u_3
inst✝⁵ : NormedAddCommGroup F'
inst✝⁴ : NormedSpace 𝕂 F'
E : Type u_4
F : Type u_5
inst✝³ : NormedAddCommGroup E
inst✝² : NormedSpace ℝ E
inst✝¹ : NormedAddCommGroup F
inst✝ : NormedSpace ℝ F
f : E → F
p : E → FormalMultilinearSeries ℝ E F
s : Set E
x : E
hf : HasFTaylorSeriesUpToOn 1 f p (insert x s)
hs : Convex ℝ s
K : ℝ≥0
hK : ‖p x 1‖₊ < K
f' : E → E →L[ℝ] F := fun y => (continuousMultilinearCurryFin1 ℝ E F) (p y 1)
⊢ ∃ t ∈ 𝓝[s] x, LipschitzOnWith K f t

Next tactic:
have hder : ∀ y ∈ s, HasFDerivWithinAt f (f' y) s y := fun y hy =>
    (hf.hasFDerivWithinAt le_rfl (subset_insert x s hy)).mono (subset_insert x s)
/-- If `f` has a formal Taylor series `p` up to order `1` on `{x} ∪ s`, where `s` is a convex set,
and `‖p x 1‖₊ < K`, then `f` is `K`-Lipschitz in a neighborhood of `x` within `s`. -/
theorem HasFTaylorSeriesUpToOn.exists_lipschitzOnWith_of_nnnorm_lt {E F : Type*}
    [NormedAddCommGroup E] [NormedSpace ℝ E] [NormedAddCommGroup F] [NormedSpace ℝ F] {f : E → F}
    {p : E → FormalMultilinearSeries ℝ E F} {s : Set E} {x : E}
    (hf : HasFTaylorSeriesUpToOn 1 f p (insert x s)) (hs : Convex ℝ s) (K : ℝ≥0)
    (hK : ‖p x 1‖₊ < K) : ∃ t ∈ 𝓝[s] x, LipschitzOnWith K f t := by
  set f' := fun y => continuousMultilinearCurryFin1 ℝ E F (p y 1)
  have hder : ∀ y ∈ s, HasFDerivWithinAt f (f' y) s y := fun y hy =>
    (hf.hasFDerivWithinAt le_rfl (subset_insert x s hy)).mono (subset_insert x s)
  

Proof state:
n : ℕ∞
𝕂 : Type u_1
inst✝⁸ : IsROrC 𝕂
E' : Type u_2
inst✝⁷ : NormedAddCommGroup E'
inst✝⁶ : NormedSpace 𝕂 E'
F' : Type u_3
inst✝⁵ : NormedAddCommGroup F'
inst✝⁴ : NormedSpace 𝕂 F'
E : Type u_4
F : Type u_5
inst✝³ : NormedAddCommGroup E
inst✝² : NormedSpace ℝ E
inst✝¹ : NormedAddCommGroup F
inst✝ : NormedSpace ℝ F
f : E → F
p : E → FormalMultilinearSeries ℝ E F
s : Set E
x : E
hf : HasFTaylorSeriesUpToOn 1 f p (insert x s)
hs : Convex ℝ s
K : ℝ≥0
hK : ‖p x 1‖₊ < K
f' : E → E →L[ℝ] F := fun y => (continuousMultilinearCurryFin1 ℝ E F) (p y 1)
hder : ∀ y ∈ s, HasFDerivWithinAt f (f' y) s y
⊢ ∃ t ∈ 𝓝[s] x, LipschitzOnWith K f t

Next tactic:
have hcont : ContinuousWithinAt f' s x :=
    (continuousMultilinearCurryFin1 ℝ E F).continuousAt.comp_continuousWithinAt
      ((hf.cont _ le_rfl _ (mem_insert _ _)).mono (subset_insert x s))
/-- If `f` has a formal Taylor series `p` up to order `1` on `{x} ∪ s`, where `s` is a convex set,
and `‖p x 1‖₊ < K`, then `f` is `K`-Lipschitz in a neighborhood of `x` within `s`. -/
theorem HasFTaylorSeriesUpToOn.exists_lipschitzOnWith_of_nnnorm_lt {E F : Type*}
    [NormedAddCommGroup E] [NormedSpace ℝ E] [NormedAddCommGroup F] [NormedSpace ℝ F] {f : E → F}
    {p : E → FormalMultilinearSeries ℝ E F} {s : Set E} {x : E}
    (hf : HasFTaylorSeriesUpToOn 1 f p (insert x s)) (hs : Convex ℝ s) (K : ℝ≥0)
    (hK : ‖p x 1‖₊ < K) : ∃ t ∈ 𝓝[s] x, LipschitzOnWith K f t := by
  set f' := fun y => continuousMultilinearCurryFin1 ℝ E F (p y 1)
  have hder : ∀ y ∈ s, HasFDerivWithinAt f (f' y) s y := fun y hy =>
    (hf.hasFDerivWithinAt le_rfl (subset_insert x s hy)).mono (subset_insert x s)
  have hcont : ContinuousWithinAt f' s x :=
    (continuousMultilinearCurryFin1 ℝ E F).continuousAt.comp_continuousWithinAt
      ((hf.cont _ le_rfl _ (mem_insert _ _)).mono (subset_insert x s))
  

Proof state:
n : ℕ∞
𝕂 : Type u_1
inst✝⁸ : IsROrC 𝕂
E' : Type u_2
inst✝⁷ : NormedAddCommGroup E'
inst✝⁶ : NormedSpace 𝕂 E'
F' : Type u_3
inst✝⁵ : NormedAddCommGroup F'
inst✝⁴ : NormedSpace 𝕂 F'
E : Type u_4
F : Type u_5
inst✝³ : NormedAddCommGroup E
inst✝² : NormedSpace ℝ E
inst✝¹ : NormedAddCommGroup F
inst✝ : NormedSpace ℝ F
f : E → F
p : E → FormalMultilinearSeries ℝ E F
s : Set E
x : E
hf : HasFTaylorSeriesUpToOn 1 f p (insert x s)
hs : Convex ℝ s
K : ℝ≥0
hK : ‖p x 1‖₊ < K
f' : E → E →L[ℝ] F := fun y => (continuousMultilinearCurryFin1 ℝ E F) (p y 1)
hder : ∀ y ∈ s, HasFDerivWithinAt f (f' y) s y
hcont : ContinuousWithinAt f' s x
⊢ ∃ t ∈ 𝓝[s] x, LipschitzOnWith K f t

Next tactic:
replace hK : ‖f' x‖₊ < K
/-- If `f` has a formal Taylor series `p` up to order `1` on `{x} ∪ s`, where `s` is a convex set,
and `‖p x 1‖₊ < K`, then `f` is `K`-Lipschitz in a neighborhood of `x` within `s`. -/
theorem HasFTaylorSeriesUpToOn.exists_lipschitzOnWith_of_nnnorm_lt {E F : Type*}
    [NormedAddCommGroup E] [NormedSpace ℝ E] [NormedAddCommGroup F] [NormedSpace ℝ F] {f : E → F}
    {p : E → FormalMultilinearSeries ℝ E F} {s : Set E} {x : E}
    (hf : HasFTaylorSeriesUpToOn 1 f p (insert x s)) (hs : Convex ℝ s) (K : ℝ≥0)
    (hK : ‖p x 1‖₊ < K) : ∃ t ∈ 𝓝[s] x, LipschitzOnWith K f t := by
  set f' := fun y => continuousMultilinearCurryFin1 ℝ E F (p y 1)
  have hder : ∀ y ∈ s, HasFDerivWithinAt f (f' y) s y := fun y hy =>
    (hf.hasFDerivWithinAt le_rfl (subset_insert x s hy)).mono (subset_insert x s)
  have hcont : ContinuousWithinAt f' s x :=
    (continuousMultilinearCurryFin1 ℝ E F).continuousAt.comp_continuousWithinAt
      ((hf.cont _ le_rfl _ (mem_insert _ _)).mono (subset_insert x s))
  replace hK : ‖f' x‖₊ < K; · 

Proof state:
case hK
n : ℕ∞
𝕂 : Type u_1
inst✝⁸ : IsROrC 𝕂
E' : Type u_2
inst✝⁷ : NormedAddCommGroup E'
inst✝⁶ : NormedSpace 𝕂 E'
F' : Type u_3
inst✝⁵ : NormedAddCommGroup F'
inst✝⁴ : NormedSpace 𝕂 F'
E : Type u_4
F : Type u_5
inst✝³ : NormedAddCommGroup E
inst✝² : NormedSpace ℝ E
inst✝¹ : NormedAddCommGroup F
inst✝ : NormedSpace ℝ F
f : E → F
p : E → FormalMultilinearSeries ℝ E F
s : Set E
x : E
hf : HasFTaylorSeriesUpToOn 1 f p (insert x s)
hs : Convex ℝ s
K : ℝ≥0
hK : ‖p x 1‖₊ < K
f' : E → E →L[ℝ] F := fun y => (continuousMultilinearCurryFin1 ℝ E F) (p y 1)
hder : ∀ y ∈ s, HasFDerivWithinAt f (f' y) s y
hcont : ContinuousWithinAt f' s x
⊢ ‖f' x‖₊ < K

Next tactic:
simpa only [LinearIsometryEquiv.nnnorm_map]
/-- If `f` has a formal Taylor series `p` up to order `1` on `{x} ∪ s`, where `s` is a convex set,
and `‖p x 1‖₊ < K`, then `f` is `K`-Lipschitz in a neighborhood of `x` within `s`. -/
theorem HasFTaylorSeriesUpToOn.exists_lipschitzOnWith_of_nnnorm_lt {E F : Type*}
    [NormedAddCommGroup E] [NormedSpace ℝ E] [NormedAddCommGroup F] [NormedSpace ℝ F] {f : E → F}
    {p : E → FormalMultilinearSeries ℝ E F} {s : Set E} {x : E}
    (hf : HasFTaylorSeriesUpToOn 1 f p (insert x s)) (hs : Convex ℝ s) (K : ℝ≥0)
    (hK : ‖p x 1‖₊ < K) : ∃ t ∈ 𝓝[s] x, LipschitzOnWith K f t := by
  set f' := fun y => continuousMultilinearCurryFin1 ℝ E F (p y 1)
  have hder : ∀ y ∈ s, HasFDerivWithinAt f (f' y) s y := fun y hy =>
    (hf.hasFDerivWithinAt le_rfl (subset_insert x s hy)).mono (subset_insert x s)
  have hcont : ContinuousWithinAt f' s x :=
    (continuousMultilinearCurryFin1 ℝ E F).continuousAt.comp_continuousWithinAt
      ((hf.cont _ le_rfl _ (mem_insert _ _)).mono (subset_insert x s))
  replace hK : ‖f' x‖₊ < K; · simpa only [LinearIsometryEquiv.nnnorm_map]
  

Proof state:
n : ℕ∞
𝕂 : Type u_1
inst✝⁸ : IsROrC 𝕂
E' : Type u_2
inst✝⁷ : NormedAddCommGroup E'
inst✝⁶ : NormedSpace 𝕂 E'
F' : Type u_3
inst✝⁵ : NormedAddCommGroup F'
inst✝⁴ : NormedSpace 𝕂 F'
E : Type u_4
F : Type u_5
inst✝³ : NormedAddCommGroup E
inst✝² : NormedSpace ℝ E
inst✝¹ : NormedAddCommGroup F
inst✝ : NormedSpace ℝ F
f : E → F
p : E → FormalMultilinearSeries ℝ E F
s : Set E
x : E
hf : HasFTaylorSeriesUpToOn 1 f p (insert x s)
hs : Convex ℝ s
K : ℝ≥0
f' : E → E →L[ℝ] F := fun y => (continuousMultilinearCurryFin1 ℝ E F) (p y 1)
hder : ∀ y ∈ s, HasFDerivWithinAt f (f' y) s y
hcont : ContinuousWithinAt f' s x
hK : ‖f' x‖₊ < K
⊢ ∃ t ∈ 𝓝[s] x, LipschitzOnWith K f t

Next tactic:
exact
    hs.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt_of_nnnorm_lt
      (eventually_nhdsWithin_iff.2 <| eventually_of_forall hder) hcont K hK