Datasets:
Tasks:
Text Generation
Modalities:
Text
Sub-tasks:
language-modeling
Languages:
English
Size:
100K - 1M
License:
/- | |
Copyright (c) 2021 Yury Kudryashov. All rights reserved. | |
Released under Apache 2.0 license as described in the file LICENSE. | |
Authors: Yury Kudryashov | |
-/ | |
import analysis.calculus.inverse | |
import linear_algebra.dual | |
/-! | |
# Lagrange multipliers | |
In this file we formalize the | |
[Lagrange multipliers](https://en.wikipedia.org/wiki/Lagrange_multiplier) method of solving | |
conditional extremum problems: if a function `Ο` has a local extremum at `xβ` on the set | |
`f β»ΒΉ' {f xβ}`, `f x = (fβ x, ..., fβββ x)`, then the differentials of `fβ` and `Ο` are linearly | |
dependent. First we formulate a geometric version of this theorem which does not rely on the | |
target space being `ββΏ`, then restate it in terms of coordinates. | |
## TODO | |
Formalize Karush-Kuhn-Tucker theorem | |
## Tags | |
lagrange multiplier, local extremum | |
-/ | |
open filter set | |
open_locale topological_space filter big_operators | |
variables {E F : Type*} [normed_add_comm_group E] [normed_space β E] [complete_space E] | |
[normed_add_comm_group F] [normed_space β F] [complete_space F] | |
{f : E β F} {Ο : E β β} {xβ : E} {f' : E βL[β] F} {Ο' : E βL[β] β} | |
/-- Lagrange multipliers theorem: if `Ο : E β β` has a local extremum on the set `{x | f x = f xβ}` | |
at `xβ`, both `f : E β F` and `Ο` are strictly differentiable at `xβ`, and the codomain of `f` is | |
a complete space, then the linear map `x β¦ (f' x, Ο' x)` is not surjective. -/ | |
lemma is_local_extr_on.range_ne_top_of_has_strict_fderiv_at | |
(hextr : is_local_extr_on Ο {x | f x = f xβ} xβ) (hf' : has_strict_fderiv_at f f' xβ) | |
(hΟ' : has_strict_fderiv_at Ο Ο' xβ) : | |
(f'.prod Ο').range β β€ := | |
begin | |
intro htop, | |
set fΟ := Ξ» x, (f x, Ο x), | |
have A : map Ο (π[f β»ΒΉ' {f xβ}] xβ) = π (Ο xβ), | |
{ change map (prod.snd β fΟ) (π[fΟ β»ΒΉ' {p | p.1 = f xβ}] xβ) = π (Ο xβ), | |
rw [β map_map, nhds_within, map_inf_principal_preimage, | |
(hf'.prod hΟ').map_nhds_eq_of_surj htop], | |
exact map_snd_nhds_within _ }, | |
exact hextr.not_nhds_le_map A.ge | |
end | |
/-- Lagrange multipliers theorem: if `Ο : E β β` has a local extremum on the set `{x | f x = f xβ}` | |
at `xβ`, both `f : E β F` and `Ο` are strictly differentiable at `xβ`, and the codomain of `f` is | |
a complete space, then there exist `Ξ : dual β F` and `Ξβ : β` such that `(Ξ, Ξβ) β 0` and | |
`Ξ (f' x) + Ξβ β’ Ο' x = 0` for all `x`. -/ | |
lemma is_local_extr_on.exists_linear_map_of_has_strict_fderiv_at | |
(hextr : is_local_extr_on Ο {x | f x = f xβ} xβ) (hf' : has_strict_fderiv_at f f' xβ) | |
(hΟ' : has_strict_fderiv_at Ο Ο' xβ) : | |
β (Ξ : module.dual β F) (Ξβ : β), (Ξ, Ξβ) β 0 β§ β x, Ξ (f' x) + Ξβ β’ Ο' x = 0 := | |
begin | |
rcases submodule.exists_le_ker_of_lt_top _ | |
(lt_top_iff_ne_top.2 $ hextr.range_ne_top_of_has_strict_fderiv_at hf' hΟ') with β¨Ξ', h0, hΞ'β©, | |
set e : ((F ββ[β] β) Γ β) ββ[β] (F Γ β ββ[β] β) := | |
((linear_equiv.refl β (F ββ[β] β)).prod (linear_map.ring_lmap_equiv_self β β β).symm).trans | |
(linear_map.coprod_equiv β), | |
rcases e.surjective Ξ' with β¨β¨Ξ, Ξββ©, rflβ©, | |
refine β¨Ξ, Ξβ, e.map_ne_zero_iff.1 h0, Ξ» x, _β©, | |
convert linear_map.congr_fun (linear_map.range_le_ker_iff.1 hΞ') x using 1, | |
-- squeezed `simp [mul_comm]` to speed up elaboration | |
simp only [linear_map.coprod_equiv_apply, linear_equiv.refl_apply, | |
linear_map.ring_lmap_equiv_self_symm_apply, linear_map.comp_apply, | |
continuous_linear_map.coe_coe, continuous_linear_map.prod_apply, | |
linear_equiv.trans_apply, linear_equiv.prod_apply, linear_map.coprod_apply, | |
linear_map.smul_right_apply, linear_map.one_apply, smul_eq_mul, mul_comm] | |
end | |
/-- Lagrange multipliers theorem: if `Ο : E β β` has a local extremum on the set `{x | f x = f xβ}` | |
at `xβ`, and both `f : E β β` and `Ο` are strictly differentiable at `xβ`, then there exist | |
`a b : β` such that `(a, b) β 0` and `a β’ f' + b β’ Ο' = 0`. -/ | |
lemma is_local_extr_on.exists_multipliers_of_has_strict_fderiv_at_1d | |
{f : E β β} {f' : E βL[β] β} | |
(hextr : is_local_extr_on Ο {x | f x = f xβ} xβ) (hf' : has_strict_fderiv_at f f' xβ) | |
(hΟ' : has_strict_fderiv_at Ο Ο' xβ) : | |
β (a b : β), (a, b) β 0 β§ a β’ f' + b β’ Ο' = 0 := | |
begin | |
obtain β¨Ξ, Ξβ, hΞ, hfΞβ© := hextr.exists_linear_map_of_has_strict_fderiv_at hf' hΟ', | |
refine β¨Ξ 1, Ξβ, _, _β©, | |
{ contrapose! hΞ, | |
simp only [prod.mk_eq_zero] at β’ hΞ, | |
refine β¨linear_map.ext (Ξ» x, _), hΞ.2β©, | |
simpa [hΞ.1] using Ξ.map_smul x 1 }, | |
{ ext x, | |
have Hβ : Ξ (f' x) = f' x * Ξ 1, | |
{ simpa only [mul_one, algebra.id.smul_eq_mul] using Ξ.map_smul (f' x) 1 }, | |
have Hβ : f' x * Ξ 1 + Ξβ * Ο' x = 0, | |
{ simpa only [algebra.id.smul_eq_mul, Hβ] using hfΞ x }, | |
simpa [mul_comm] using Hβ } | |
end | |
/-- Lagrange multipliers theorem, 1d version. Let `f : ΞΉ β E β β` be a finite family of functions. | |
Suppose that `Ο : E β β` has a local extremum on the set `{x | β i, f i x = f i xβ}` at `xβ`. | |
Suppose that all functions `f i` as well as `Ο` are strictly differentiable at `xβ`. | |
Then the derivatives `f' i : E β L[β] β` and `Ο' : E βL[β] β` are linearly dependent: | |
there exist `Ξ : ΞΉ β β` and `Ξβ : β`, `(Ξ, Ξβ) β 0`, such that `β i, Ξ i β’ f' i + Ξβ β’ Ο' = 0`. | |
See also `is_local_extr_on.linear_dependent_of_has_strict_fderiv_at` for a version that | |
states `Β¬linear_independent β _` instead of existence of `Ξ` and `Ξβ`. -/ | |
lemma is_local_extr_on.exists_multipliers_of_has_strict_fderiv_at {ΞΉ : Type*} [fintype ΞΉ] | |
{f : ΞΉ β E β β} {f' : ΞΉ β E βL[β] β} | |
(hextr : is_local_extr_on Ο {x | β i, f i x = f i xβ} xβ) | |
(hf' : β i, has_strict_fderiv_at (f i) (f' i) xβ) | |
(hΟ' : has_strict_fderiv_at Ο Ο' xβ) : | |
β (Ξ : ΞΉ β β) (Ξβ : β), (Ξ, Ξβ) β 0 β§ β i, Ξ i β’ f' i + Ξβ β’ Ο' = 0 := | |
begin | |
letI := classical.dec_eq ΞΉ, | |
replace hextr : is_local_extr_on Ο {x | (Ξ» i, f i x) = (Ξ» i, f i xβ)} xβ, | |
by simpa only [function.funext_iff] using hextr, | |
rcases hextr.exists_linear_map_of_has_strict_fderiv_at | |
(has_strict_fderiv_at_pi.2 (Ξ» i, hf' i)) hΟ' | |
with β¨Ξ, Ξβ, h0, hsumβ©, | |
rcases (linear_equiv.pi_ring β β ΞΉ β).symm.surjective Ξ with β¨Ξ, rflβ©, | |
refine β¨Ξ, Ξβ, _, _β©, | |
{ simpa only [ne.def, prod.ext_iff, linear_equiv.map_eq_zero_iff, prod.fst_zero] using h0 }, | |
{ ext x, simpa [mul_comm] using hsum x } | |
end | |
/-- Lagrange multipliers theorem. Let `f : ΞΉ β E β β` be a finite family of functions. | |
Suppose that `Ο : E β β` has a local extremum on the set `{x | β i, f i x = f i xβ}` at `xβ`. | |
Suppose that all functions `f i` as well as `Ο` are strictly differentiable at `xβ`. | |
Then the derivatives `f' i : E β L[β] β` and `Ο' : E βL[β] β` are linearly dependent. | |
See also `is_local_extr_on.exists_multipliers_of_has_strict_fderiv_at` for a version that | |
that states existence of Lagrange multipliers `Ξ` and `Ξβ` instead of using | |
`Β¬linear_independent β _` -/ | |
lemma is_local_extr_on.linear_dependent_of_has_strict_fderiv_at {ΞΉ : Type*} [fintype ΞΉ] | |
{f : ΞΉ β E β β} {f' : ΞΉ β E βL[β] β} | |
(hextr : is_local_extr_on Ο {x | β i, f i x = f i xβ} xβ) | |
(hf' : β i, has_strict_fderiv_at (f i) (f' i) xβ) | |
(hΟ' : has_strict_fderiv_at Ο Ο' xβ) : | |
Β¬linear_independent β (option.elim Ο' f' : option ΞΉ β E βL[β] β) := | |
begin | |
rw [fintype.linear_independent_iff], push_neg, | |
rcases hextr.exists_multipliers_of_has_strict_fderiv_at hf' hΟ' with β¨Ξ, Ξβ, hΞ, hΞfβ©, | |
refine β¨option.elim Ξβ Ξ, _, _β©, | |
{ simpa [add_comm] using hΞf }, | |
{ simpa [function.funext_iff, not_and_distrib, or_comm, option.exists] using hΞ } | |
end | |