-
Notifications
You must be signed in to change notification settings - Fork 331
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add First Derivative Test from calculus (#16802)
Add proofs of the First Derivative Test, in max and min forms, using neighborhood filters. New branch due to merge conflict in the [old](https://github.com/leanprover-community/mathlib4/tree/bjoernkjoshanssen_firstderivativetest) branch.
- Loading branch information
1 parent
f375907
commit 45deead
Showing
5 changed files
with
222 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
/- | ||
Copyright (c) 2024 Bjørn Kjos-Hanssen. All rights reserved. | ||
Released under Apache 2.0 license as described in the file LICENSE. | ||
Authors: Bjørn Kjos-Hanssen, Patrick Massot, Floris van Doorn | ||
-/ | ||
import Mathlib.Analysis.Calculus.MeanValue | ||
import Mathlib.Topology.Order.OrderClosedExtr | ||
/-! | ||
# The First-Derivative Test | ||
We prove the first-derivative test in the strong form given on [Wikipedia](https://en.wikipedia.org/wiki/Derivative_test#First-derivative_test). | ||
The test is proved over the real numbers ℝ | ||
using `monotoneOn_of_deriv_nonneg` from [Mathlib.Analysis.Calculus.MeanValue]. | ||
## Main results | ||
* `isLocalMax_of_deriv_Ioo`: Suppose `f` is a real-valued function of a real variable | ||
defined on some interval containing the point `a`. | ||
Further suppose that `f` is continuous at `a` and differentiable on some open interval | ||
containing `a`, except possibly at `a` itself. | ||
If there exists a positive number `r > 0` such that for every `x` in `(a − r, a)` | ||
we have `f′(x) ≥ 0`, and for every `x` in `(a, a + r)` we have `f′(x) ≤ 0`, | ||
then `f` has a local maximum at `a`. | ||
* `isLocalMin_of_deriv_Ioo`: The dual of `first_derivative_max`, for minima. | ||
* `isLocalMax_of_deriv`: 1st derivative test for maxima using filters. | ||
* `isLocalMin_of_deriv`: 1st derivative test for minima using filters. | ||
## Tags | ||
derivative test, calculus | ||
-/ | ||
|
||
open Set Topology | ||
|
||
|
||
/-- The First-Derivative Test from calculus, maxima version. | ||
Suppose `a < b < c`, `f : ℝ → ℝ` is continuous at `b`, | ||
the derivative `f'` is nonnegative on `(a,b)`, and | ||
the derivative `f'` is nonpositive on `(b,c)`. Then `f` has a local maximum at `a`. -/ | ||
lemma isLocalMax_of_deriv_Ioo {f : ℝ → ℝ} {a b c : ℝ} (g₀ : a < b) (g₁ : b < c) | ||
(h : ContinuousAt f b) | ||
(hd₀ : DifferentiableOn ℝ f (Ioo a b)) | ||
(hd₁ : DifferentiableOn ℝ f (Ioo b c)) | ||
(h₀ : ∀ x ∈ Ioo a b, 0 ≤ deriv f x) | ||
(h₁ : ∀ x ∈ Ioo b c, deriv f x ≤ 0) : IsLocalMax f b := | ||
have hIoc : ContinuousOn f (Ioc a b) := | ||
Ioo_union_right g₀ ▸ hd₀.continuousOn.union_continuousAt (isOpen_Ioo (a := a) (b := b)) | ||
(by simp_all) | ||
have hIco : ContinuousOn f (Ico b c) := | ||
Ioo_union_left g₁ ▸ hd₁.continuousOn.union_continuousAt (isOpen_Ioo (a := b) (b := c)) | ||
(by simp_all) | ||
isLocalMax_of_mono_anti g₀ g₁ | ||
(monotoneOn_of_deriv_nonneg (convex_Ioc a b) hIoc (by simp_all) (by simp_all)) | ||
(antitoneOn_of_deriv_nonpos (convex_Ico b c) hIco (by simp_all) (by simp_all)) | ||
|
||
|
||
/-- The First-Derivative Test from calculus, minima version. -/ | ||
lemma isLocalMin_of_deriv_Ioo {f : ℝ → ℝ} {a b c : ℝ} | ||
(g₀ : a < b) (g₁ : b < c) (h : ContinuousAt f b) | ||
(hd₀ : DifferentiableOn ℝ f (Ioo a b)) (hd₁ : DifferentiableOn ℝ f (Ioo b c)) | ||
(h₀ : ∀ x ∈ Ioo a b, deriv f x ≤ 0) | ||
(h₁ : ∀ x ∈ Ioo b c, 0 ≤ deriv f x) : IsLocalMin f b := by | ||
have := isLocalMax_of_deriv_Ioo (f := -f) g₀ g₁ | ||
(by simp_all) hd₀.neg hd₁.neg | ||
(fun x hx => deriv.neg (f := f) ▸ Left.nonneg_neg_iff.mpr <|h₀ x hx) | ||
(fun x hx => deriv.neg (f := f) ▸ Left.neg_nonpos_iff.mpr <|h₁ x hx) | ||
exact (neg_neg f) ▸ IsLocalMax.neg this | ||
|
||
/-- The First-Derivative Test from calculus, maxima version, | ||
expressed in terms of left and right filters. -/ | ||
lemma isLocalMax_of_deriv' {f : ℝ → ℝ} {b : ℝ} (h : ContinuousAt f b) | ||
(hd₀ : ∀ᶠ x in 𝓝[<] b, DifferentiableAt ℝ f x) (hd₁ : ∀ᶠ x in 𝓝[>] b, DifferentiableAt ℝ f x) | ||
(h₀ : ∀ᶠ x in 𝓝[<] b, 0 ≤ deriv f x) (h₁ : ∀ᶠ x in 𝓝[>] b, deriv f x ≤ 0) : | ||
IsLocalMax f b := by | ||
obtain ⟨a,ha⟩ := (nhdsWithin_Iio_basis' ⟨b - 1, sub_one_lt b⟩).eventually_iff.mp <| hd₀.and h₀ | ||
obtain ⟨c,hc⟩ := (nhdsWithin_Ioi_basis' ⟨b + 1, lt_add_one b⟩).eventually_iff.mp <| hd₁.and h₁ | ||
exact isLocalMax_of_deriv_Ioo ha.1 hc.1 h | ||
(fun _ hx => (ha.2 hx).1.differentiableWithinAt) | ||
(fun _ hx => (hc.2 hx).1.differentiableWithinAt) | ||
(fun _ hx => (ha.2 hx).2) (fun x hx => (hc.2 hx).2) | ||
|
||
/-- The First-Derivative Test from calculus, minima version, | ||
expressed in terms of left and right filters. -/ | ||
lemma isLocalMin_of_deriv' {f : ℝ → ℝ} {b : ℝ} (h : ContinuousAt f b) | ||
(hd₀ : ∀ᶠ x in 𝓝[<] b, DifferentiableAt ℝ f x) (hd₁ : ∀ᶠ x in 𝓝[>] b, DifferentiableAt ℝ f x) | ||
(h₀ : ∀ᶠ x in 𝓝[<] b, deriv f x ≤ 0) (h₁ : ∀ᶠ x in 𝓝[>] b, deriv f x ≥ 0) : | ||
IsLocalMin f b := by | ||
obtain ⟨a,ha⟩ := (nhdsWithin_Iio_basis' ⟨b - 1, sub_one_lt b⟩).eventually_iff.mp <| hd₀.and h₀ | ||
obtain ⟨c,hc⟩ := (nhdsWithin_Ioi_basis' ⟨b + 1, lt_add_one b⟩).eventually_iff.mp <| hd₁.and h₁ | ||
exact isLocalMin_of_deriv_Ioo ha.1 hc.1 h | ||
(fun _ hx => (ha.2 hx).1.differentiableWithinAt) | ||
(fun _ hx => (hc.2 hx).1.differentiableWithinAt) | ||
(fun _ hx => (ha.2 hx).2) (fun x hx => (hc.2 hx).2) | ||
|
||
/-- The First Derivative test, maximum version. -/ | ||
theorem isLocalMax_of_deriv {f : ℝ → ℝ} {b : ℝ} (h : ContinuousAt f b) | ||
(hd : ∀ᶠ x in 𝓝[≠] b, DifferentiableAt ℝ f x) | ||
(h₀ : ∀ᶠ x in 𝓝[<] b, 0 ≤ deriv f x) (h₁ : ∀ᶠ x in 𝓝[>] b, deriv f x ≤ 0) : | ||
IsLocalMax f b := | ||
isLocalMax_of_deriv' h | ||
(nhds_left'_le_nhds_ne _ (by tauto)) (nhds_right'_le_nhds_ne _ (by tauto)) h₀ h₁ | ||
|
||
/-- The First Derivative test, minimum version. -/ | ||
theorem isLocalMin_of_deriv {f : ℝ → ℝ} {b : ℝ} (h : ContinuousAt f b) | ||
(hd : ∀ᶠ x in 𝓝[≠] b, DifferentiableAt ℝ f x) | ||
(h₀ : ∀ᶠ x in 𝓝[<] b, deriv f x ≤ 0) (h₁ : ∀ᶠ x in 𝓝[>] b, 0 ≤ deriv f x) : | ||
IsLocalMin f b := | ||
isLocalMin_of_deriv' h | ||
(nhds_left'_le_nhds_ne _ (by tauto)) (nhds_right'_le_nhds_ne _ (by tauto)) h₀ h₁ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/- | ||
Copyright (c) 2024 Bjørn Kjos-Hanssen. All rights reserved. | ||
Released under Apache 2.0 license as described in the file LICENSE. | ||
Authors: Bjørn Kjos-Hanssen, Patrick Massot | ||
-/ | ||
|
||
import Mathlib.Topology.Order.OrderClosed | ||
import Mathlib.Topology.Order.LocalExtr | ||
|
||
/-! | ||
# Local maxima from monotonicity and antitonicity | ||
In this file we prove a lemma that is useful for the First Derivative Test in calculus, | ||
and its dual. | ||
## Main statements | ||
* `isLocalMax_of_mono_anti` : if a function `f` is monotone to the left of `x` | ||
and antitone to the right of `x` then `f` has a local maximum at `x`. | ||
* `isLocalMin_of_anti_mono` : the dual statement for minima. | ||
* `isLocalMax_of_mono_anti'` : a version of `isLocalMax_of_mono_anti` for filters. | ||
* `isLocalMin_of_anti_mono'` : a version of `isLocalMax_of_mono_anti'` for minima. | ||
-/ | ||
|
||
open Set Topology Filter | ||
|
||
/-- If `f` is monotone on `(a,b]` and antitone on `[b,c)` then `f` has | ||
a local maximum at `b`. -/ | ||
lemma isLocalMax_of_mono_anti | ||
{α : Type*} [TopologicalSpace α] [LinearOrder α] [OrderClosedTopology α] | ||
{β : Type*} [Preorder β] | ||
{a b c : α} (g₀ : a < b) (g₁ : b < c) {f : α → β} | ||
(h₀ : MonotoneOn f (Ioc a b)) | ||
(h₁ : AntitoneOn f (Ico b c)) : IsLocalMax f b := | ||
isLocalMax_of_mono_anti' (Ioc_mem_nhdsWithin_Iic' g₀) (Ico_mem_nhdsWithin_Ici' g₁) h₀ h₁ | ||
|
||
|
||
|
||
/-- If `f` is antitone on `(a,b]` and monotone on `[b,c)` then `f` has | ||
a local minimum at `b`. -/ | ||
lemma isLocalMin_of_anti_mono | ||
{α : Type*} [TopologicalSpace α] [LinearOrder α] [OrderClosedTopology α] | ||
{β : Type*} [Preorder β] {a b c : α} (g₀ : a < b) (g₁ : b < c) {f : α → β} | ||
(h₀ : AntitoneOn f (Ioc a b)) (h₁ : MonotoneOn f (Ico b c)) : IsLocalMin f b := | ||
mem_of_superset (Ioo_mem_nhds g₀ g₁) (fun x hx => by rcases le_total x b <;> aesop) |