openAI-math-dataset / lean /OAI /Geometry /BallPacking /Moments /ExponentialMoment.lean
roseking's picture
Add lean source and binary files (part 65)
720fa25 verified
Raw History Blame Contribute Delete
23.5 kB
import Mathlib
import OAI.Geometry.BallPacking.Degree.ChartFormZeroExtension
namespace OAI
noncomputable section
namespace PackingSufficiencySupport.FiniteMoment
open scoped BigOperators Topology ContDiff
open Set Filter Function
section
variable {ι E : Type*} [Fintype ι] [Nonempty ι]
[NormedAddCommGroup E] [InnerProductSpace ℝ E]
def partition (w : ι → E) (a : ι → ℝ) (x : E) : ℝ :=
∑ i, a i * Real.exp (inner ℝ (w i) x)
def gradient (w : ι → E) (a : ι → ℝ) (x : E) : E :=
∑ i, (a i * Real.exp (inner ℝ (w i) x)) • w i
def moment (w : ι → E) (a : ι → ℝ) (x : E) : E :=
(partition w a x)⁻¹ • gradient w a x
def Surrounds (w : ι → E) (p : E) : Prop :=
∃ δ : ℝ, 0<δ ∧ ∀ v : E, ∃ i, δ*‖v‖≤ inner ℝ (w i-p) v
theorem partition_pos {w : ι → E} {a : ι → ℝ} (ha : ∀ i,0<a i) (x : E) :
0<partition w a x := by
apply Finset.sum_pos
· intro i _
exact mul_pos (ha i) (Real.exp_pos _)
· exact Finset.univ_nonempty
omit [Nonempty ι] in
theorem partition_contDiff (w : ι → E) (a : ι → ℝ) : ContDiff ℝ ∞ (partition w a) := by
apply ContDiff.sum
intro i _
exact contDiff_const.mul (((innerSL ℝ (w i)).contDiff).exp)
omit [Nonempty ι] in
theorem partition_hasFDerivAt (w : ι → E) (a : ι → ℝ) (x : E) :
HasFDerivAt (partition w a) (innerSL ℝ (gradient w a x)) x := by
have h := HasFDerivAt.sum (u := Finset.univ) (fun i _ =>
(((innerSL ℝ (w i)).hasFDerivAt (x := x)).exp).const_mul (a i))
convert! h using 1
· ext y
simp [partition]
· simp only [gradient,map_sum,map_smul,smul_smul,innerSL_apply_apply]
theorem partition_coercive [ProperSpace E] {w : ι → E} {a : ι → ℝ}
(ha : ∀ i,0<a i) {δ : ℝ} (hδ : 0<δ)
(hw : ∀ x : E,∃ i,δ*‖x‖≤ inner ℝ (w i) x) :
Tendsto (partition w a) (cocompact E) atTop := by
classical
obtain ⟨j,_,hj⟩ := Finset.exists_min_image Finset.univ a Finset.univ_nonempty
have hb (x : E) : a j*Real.exp (δ*‖x‖)≤partition w a x := by
obtain ⟨i,hi⟩ := hw x
calc
a j*Real.exp (δ*‖x‖)≤a i*Real.exp (inner ℝ (w i) x) :=
mul_le_mul (hj i (Finset.mem_univ i)) (Real.exp_le_exp.mpr hi)
(Real.exp_pos _).le (ha i).le
_≤partition w a x := by
exact Finset.single_le_sum
(fun k _ => (mul_pos (ha k) (Real.exp_pos (inner ℝ (w k) x))).le) (Finset.mem_univ i)
exact tendsto_atTop_mono hb ((Real.tendsto_exp_atTop.comp
(tendsto_norm_cocompact_atTop.const_mul_atTop hδ)).const_mul_atTop (ha j))
theorem exists_gradient_zero [ProperSpace E] {w : ι → E} {a : ι → ℝ}
(ha : ∀ i,0<a i) {δ : ℝ} (hδ : 0<δ)
(hw : ∀ x : E,∃ i,δ*‖x‖≤ inner ℝ (w i) x) :
∃ x : E,gradient w a x=0 := by
obtain ⟨x,hx⟩ := (partition_contDiff w a).continuous.exists_forall_le
(partition_coercive ha hδ hw)
refine ⟨x,?_⟩
have hm : IsLocalMin (partition w a) x := Filter.Eventually.of_forall hx
have hz := hm.hasFDerivAt_eq_zero (partition_hasFDerivAt w a x)
have he := congrArg (fun L : E →L[ℝ] ℝ => L (gradient w a x)) hz
change inner ℝ (gradient w a x) (gradient w a x)=0 at he
exact inner_self_eq_zero.mp he
theorem exp_difference_nonneg (u v : ℝ) :
0≤(Real.exp u-Real.exp v)*(u-v) := by
rcases le_total v u with h|h
· exact mul_nonneg (sub_nonneg.mpr (Real.exp_le_exp.mpr h)) (sub_nonneg.mpr h)
· exact mul_nonneg_of_nonpos_of_nonpos (sub_nonpos.mpr (Real.exp_le_exp.mpr h))
(sub_nonpos.mpr h)
theorem exp_difference_pos {u v : ℝ} (h : v<u) :
0<(Real.exp u-Real.exp v)*(u-v) :=
mul_pos (sub_pos.mpr (Real.exp_lt_exp.mpr h)) (sub_pos.mpr h)
omit [Nonempty ι] in
theorem gradient_zero_unique {w : ι → E} {a : ι → ℝ}
(ha : ∀ i,0<a i) {δ : ℝ} (hδ : 0<δ)
(hw : ∀ x : E,∃ i,δ*‖x‖≤ inner ℝ (w i) x) {x y : E}
(hx : gradient w a x=0) (hy : gradient w a y=0) : x=y := by
classical
by_contra hxy
have hd : 0<δ*‖x-y‖ := mul_pos hδ (norm_pos_iff.mpr (sub_ne_zero.mpr hxy))
obtain ⟨j,hj⟩ := hw (x-y)
have hjp : inner ℝ (w j) y< inner ℝ (w j) x := by
rw [inner_sub_right] at hj
linarith
have hs : 0< ∑ i,a i*((Real.exp (inner ℝ (w i) x)-Real.exp (inner ℝ (w i) y))*
(inner ℝ (w i) x-inner ℝ (w i) y)) := by
apply Finset.sum_pos'
· intro i _
exact mul_nonneg (ha i).le (exp_difference_nonneg _ _)
· exact ⟨j,Finset.mem_univ j,mul_pos (ha j) (exp_difference_pos hjp)⟩
have he : ∑ i,a i*((Real.exp (inner ℝ (w i) x)-Real.exp (inner ℝ (w i) y))*
(inner ℝ (w i) x-inner ℝ (w i) y))=
inner ℝ (gradient w a x-gradient w a y) (x-y) := by
simp only [gradient,inner_sub_left,sum_inner,real_inner_smul_left,inner_sub_right,←Finset.sum_sub_distrib]
apply Finset.sum_congr rfl
intro i _
ring
rw [he,hx,hy,sub_self,inner_zero_left] at hs
exact (lt_irrefl (0:ℝ)) hs
omit [Nonempty ι] in
theorem gradient_center (w : ι → E) (a : ι → ℝ) (p x : E) :
gradient (fun i => w i-p) a x = Real.exp (-inner ℝ p x) •
(gradient w a x-partition w a x • p) := by
have he (i : ι) : (a i * Real.exp (inner ℝ (w i-p) x)) • (w i-p) =
Real.exp (-inner ℝ p x) • ((a i*Real.exp (inner ℝ (w i) x)) • w i-
(a i*Real.exp (inner ℝ (w i) x)) • p) := by
rw [inner_sub_left,sub_eq_add_neg (inner ℝ (w i) x),Real.exp_add]
simp only [smul_sub,smul_smul]
congr 1 <;> congr 1 <;> ring
simp only [gradient,he,←Finset.smul_sum,Finset.sum_sub_distrib,←Finset.sum_smul,partition]
theorem moment_eq_iff_gradient_center_zero {w : ι → E} {a : ι → ℝ}
(ha : ∀ i,0<a i) (p x : E) :
moment w a x=p ↔ gradient (fun i => w i-p) a x=0 := by
rw [gradient_center,smul_eq_zero]
simp only [Real.exp_ne_zero,false_or,sub_eq_zero]
dsimp [moment]
rw [inv_smul_eq_iff₀ (partition_pos ha x).ne']
theorem exists_unique_moment [ProperSpace E] {w : ι → E} {a : ι → ℝ}
(ha : ∀ i,0<a i) {p : E} (hp : Surrounds w p) : ∃! x,moment w a x=p := by
obtain ⟨δ,hδ,hw⟩ := hp
obtain ⟨x,hx⟩ := exists_gradient_zero ha hδ hw
refine ⟨x,(moment_eq_iff_gradient_center_zero ha p x).mpr hx,?_⟩
intro y hy
exact gradient_zero_unique ha hδ hw ((moment_eq_iff_gradient_center_zero ha p y).mp hy) hx
omit [Fintype ι] in
theorem surrounds_of_interior {w : ι → E} {p : E}
(hp : p∈interior (convexHull ℝ (range w))) : Surrounds w p := by
obtain ⟨ε,hε,hball⟩ := Metric.mem_nhds_iff.mp (mem_interior_iff_mem_nhds.mp hp)
refine ⟨ε/2,half_pos hε,?_⟩
intro v
by_cases hv : v=0
· subst v
exact ⟨Classical.ofNonempty,by simp⟩
have hvp : 0<‖v‖ := norm_pos_iff.mpr hv
let z := p+((ε/2)/‖v‖) • v
have hz : z∈convexHull ℝ (range w) := by
apply hball
rw [Metric.mem_ball,dist_eq_norm]
dsimp [z]
rw [add_sub_cancel_left,norm_smul,Real.norm_eq_abs,abs_of_pos (div_pos (half_pos hε) hvp),
div_mul_cancel₀ _ hvp.ne']
linarith
obtain ⟨y,⟨i,rfl⟩,hi⟩ := ((innerSL ℝ v).toLinearMap.convexOn convex_univ).exists_ge_of_mem_convexHull
(subset_univ (range w)) hz
refine ⟨i,?_⟩
change inner ℝ v z≤ inner ℝ v (w i) at hi
have he : inner ℝ v z=inner ℝ v p+(ε/2)*‖v‖ := by
dsimp [z]
rw [inner_add_right,real_inner_smul_right,real_inner_self_eq_norm_sq]
field_simp
rw [he] at hi
rw [inner_sub_left,real_inner_comm v (w i),real_inner_comm v p]
linarith
omit [Fintype ι] [Nonempty ι] in
theorem surrounds_isOpen (w : ι → E) : IsOpen {p | Surrounds w p} := by
apply Metric.isOpen_iff.mpr
intro p hp
obtain ⟨δ,hδ,hw⟩ := hp
refine ⟨δ/2,half_pos hδ,?_⟩
intro q hq
refine ⟨δ/2,half_pos hδ,?_⟩
intro v
obtain ⟨i,hi⟩ := hw v
refine ⟨i,?_⟩
have hc := real_inner_le_norm (q-p) v
have hnorm : ‖q-p‖<δ/2 := by simpa only [Metric.mem_ball,dist_eq_norm] using hq
have hmul := mul_le_mul_of_nonneg_right hnorm.le (norm_nonneg v)
rw [inner_sub_left] at hi hc ⊢
linarith
theorem exists_unique_moment_interior [ProperSpace E] {w : ι → E} {a : ι → ℝ}
(ha : ∀ i,0<a i) {p : E} (hp : p∈interior (convexHull ℝ (range w))) :
∃! x,moment w a x=p := exists_unique_moment ha (surrounds_of_interior hp)
end
section
variable {ι E : Type*} [Fintype ι]
[NormedAddCommGroup E] [InnerProductSpace ℝ E]
def hessian (w : ι → E) (a : ι → ℝ) (x : E) : E →L[ℝ] E :=
∑ i, ((a i*Real.exp (inner ℝ (w i) x)) • innerSL ℝ (w i)).smulRight (w i)
theorem hessian_apply (w : ι → E) (a : ι → ℝ) (x v : E) :
hessian w a x v=∑ i, (a i*Real.exp (inner ℝ (w i) x)*inner ℝ (w i) v) • w i := by
simp [hessian]
theorem gradient_hasFDerivAt (w : ι → E) (a : ι → ℝ) (x : E) :
HasFDerivAt (gradient w a) (hessian w a x) x := by
have h := HasFDerivAt.sum (u := Finset.univ) (fun i _ =>
((((innerSL ℝ (w i)).hasFDerivAt (x := x)).exp).const_mul (a i)).smul_const (w i))
convert! h using 1
· ext y
simp [gradient]
· simp only [hessian,smul_smul,innerSL_apply_apply]
theorem hessian_inner (w : ι → E) (a : ι → ℝ) (x v : E) :
inner ℝ (hessian w a x v) v=
∑ i,(a i*Real.exp (inner ℝ (w i) x))*(inner ℝ (w i) v)^2 := by
rw [hessian_apply,sum_inner]
apply Finset.sum_congr rfl
intro i _
rw [real_inner_smul_left]
ring
theorem hessian_positive {w : ι → E} {a : ι → ℝ} (ha : ∀ i,0<a i)
(hw : ∀ v : E,v≠0 → ∃ i,inner ℝ (w i) v≠0) (x : E) {v : E} (hv : v≠0) :
0< inner ℝ (hessian w a x v) v := by
classical
rw [hessian_inner]
apply Finset.sum_pos'
· intro i _
exact mul_nonneg (mul_pos (ha i) (Real.exp_pos _)).le (sq_nonneg _)
· obtain ⟨i,hi⟩ := hw v hv
exact ⟨i,Finset.mem_univ i,mul_pos (mul_pos (ha i) (Real.exp_pos _)) (sq_pos_of_ne_zero hi)⟩
theorem hessian_isInvertible [FiniteDimensional ℝ E] {w : ι → E} {a : ι → ℝ}
(ha : ∀ i,0<a i) (hw : ∀ v : E,v≠0 → ∃ i,inner ℝ (w i) v≠0) (x : E) :
(hessian w a x).IsInvertible := by
have hi : Injective (hessian w a x) := by
intro v u h
by_contra hn
have hp := hessian_positive ha hw x (sub_ne_zero.mpr hn)
rw [map_sub,h,sub_self,inner_zero_left] at hp
exact (lt_irrefl (0:ℝ)) hp
let L := ContinuousLinearEquiv.ofBijective (hessian w a x)
(LinearMap.ker_eq_bot.mpr hi)
(LinearMap.range_eq_top.mpr (LinearMap.injective_iff_surjective.mp hi))
exact ⟨L,rfl⟩
omit [Fintype ι] in
theorem surrounds_separates {w : ι → E} {p : E} (hp : Surrounds w p)
{v : E} (hv : v≠0) : ∃ i,inner ℝ (w i-p) v≠0 := by
obtain ⟨δ,hδ,hw⟩ := hp
obtain ⟨i,hi⟩ := hw v
exact ⟨i,(lt_of_lt_of_le (mul_pos hδ (norm_pos_iff.mpr hv)) hi).ne'⟩
theorem centeredGradient_contDiff (w : ι → E) :
ContDiff ℝ ∞ (fun q : ((ι → ℝ) × E) × E => gradient (fun i => w i-q.1.2) q.1.1 q.2) := by
apply ContDiff.sum
intro i _
have ha : ContDiff ℝ ∞ (fun q : ((ι → ℝ) × E) × E => q.1.1 i) := by fun_prop
have hu : ContDiff ℝ ∞ (fun q : ((ι → ℝ) × E) × E => w i-q.1.2) := by fun_prop
exact (ha.mul ((hu.inner ℝ contDiff_snd).exp)).smul hu
end
variable {ι E : Type*} [Fintype ι] [Nonempty ι]
[NormedAddCommGroup E] [InnerProductSpace ℝ E] [FiniteDimensional ℝ E]
def inverse (w : ι → E) (a : ι → ℝ) (p : E) : E := invFun (moment w a) p
theorem inverse_spec {w : ι → E} {a : ι → ℝ} (ha : ∀ i,0<a i) {p : E}
(hp : Surrounds w p) : moment w a (inverse w a p)=p :=
invFun_eq (exists_unique_moment ha hp).exists
theorem inverse_unique {w : ι → E} {a : ι → ℝ} (ha : ∀ i,0<a i) {p : E}
(hp : Surrounds w p) {x : E} (hx : moment w a x=p) : x=inverse w a p :=
(exists_unique_moment ha hp).unique hx (inverse_spec ha hp)
omit [Nonempty ι] in
theorem positiveCoefficients_isOpen : IsOpen {a : ι → ℝ | ∀ i,0<a i} := by
have h : IsOpen (⋂ i : ι,{a : ι → ℝ | 0<a i}) :=
isOpen_iInter_of_finite (fun i => isOpen_lt continuous_const (continuous_apply i))
convert h using 1
ext a
simp
theorem inverse_contDiffAt {w : ι → E} {a : ι → ℝ} (ha : ∀ i,0<a i) {p : E}
(hp : Surrounds w p) : ContDiffAt ℝ ∞ (fun q : (ι → ℝ) × E => inverse w q.1 q.2) (a,p) := by
let q := (a,p)
let x := inverse w a p
let F : ((ι → ℝ) × E) × E → E :=
fun t => gradient (fun i => w i-t.1.2) t.1.1 t.2
have hF : ContDiff ℝ ∞ F := centeredGradient_contDiff w
have hpartial : (fderiv ℝ F (q,x)).comp (ContinuousLinearMap.inr ℝ ((ι → ℝ) × E) E)=
hessian (fun i => w i-p) a x := by
have hc := ((hF.differentiable (by simp) (q,x)).hasFDerivAt.comp x
((hasFDerivAt_const q x).prodMk (hasFDerivAt_id x)))
exact hc.unique (gradient_hasFDerivAt (fun i => w i-p) a x)
have hinv : (fderiv ℝ F (q,x) ∘L ContinuousLinearMap.inr ℝ ((ι → ℝ) × E) E).IsInvertible := by
rw [hpartial]
exact hessian_isInvertible ha (fun _ hv => surrounds_separates hp hv) x
have hzero : F (q,x)=0 :=
(moment_eq_iff_gradient_center_zero ha p x).mp (inverse_spec ha hp)
have hapos : ∀ᶠ t : (ι → ℝ) × E in 𝓝 q,∀ i,0<t.1 i := by
apply (positiveCoefficients_isOpen.preimage continuous_fst).mem_nhds
exact ha
have htpos : ∀ᶠ t : (ι → ℝ) × E in 𝓝 q,Surrounds w t.2 := by
apply ((surrounds_isOpen w).preimage continuous_snd).mem_nhds
exact hp
have hloc := hF.contDiffAt.contDiffAt_implicitFunction (by simp) hinv
apply hloc.congr_of_eventuallyEq
filter_upwards [hF.contDiffAt.eventually_apply_implicitFunction (by simp) hinv,hapos,htpos]
with t ht hta htp
rw [hzero] at ht
have hm := (moment_eq_iff_gradient_center_zero hta t.2 _).mpr ht
exact (inverse_unique hta htp hm).symm
theorem inverse_contDiffOn (w : ι → E) :
ContDiffOn ℝ ∞ (fun q : (ι → ℝ) × E => inverse w q.1 q.2)
{q | (∀ i,0<q.1 i) ∧ Surrounds w q.2} :=
fun _ hq => (inverse_contDiffAt hq.1 hq.2).contDiffWithinAt
end PackingSufficiencySupport.FiniteMoment
namespace PackingSufficiencySupport.FiniteMoment.Radial
open scoped BigOperators Topology ContDiff
open Set Filter Function
abbrev Plane := ℝ × ℝ
variable {ι : Type*} [Fintype ι]
def monomial (k : ℕ × ℕ) (r : Plane) : ℝ := r.1^k.1 * r.2^k.2
def polynomial (k : ι → ℕ × ℕ) (a : ι → ℝ) (r : Plane) : ℝ :=
∑ i, a i * monomial (k i) r
def numerator (k : ι → ℕ × ℕ) (a : ι → ℝ) (r : Plane) : Plane :=
(∑ i, ((k i).1:ℝ)*a i*monomial (k i) r,
∑ i, ((k i).2:ℝ)*a i*monomial (k i) r)
def moment (k : ι → ℕ × ℕ) (a : ι → ℝ) (r : Plane) : Plane :=
(polynomial k a r)⁻¹ • numerator k a r
def centered (k : ι → ℕ × ℕ) (a : ι → ℝ) (p r : Plane) : Plane :=
(∑ i, (((k i).1:ℝ)-p.1)*a i*monomial (k i) r,
∑ i, (((k i).2:ℝ)-p.2)*a i*monomial (k i) r)
theorem monomial_nonneg (k : ℕ × ℕ) {r : Plane} (hr : 0≤r.1 ∧ 0≤r.2) :
0 ≤ monomial k r := mul_nonneg (pow_nonneg hr.1 _) (pow_nonneg hr.2 _)
theorem polynomial_pos {k : ι → ℕ × ℕ} {a : ι → ℝ} (ha : ∀ i,0<a i)
(hzero : ∃ i,k i=(0,0)) {r : Plane} (hr : 0≤r.1 ∧ 0≤r.2) :
0<polynomial k a r := by
classical
apply Finset.sum_pos'
· intro i _
exact mul_nonneg (ha i).le (monomial_nonneg _ hr)
· obtain ⟨i,hi⟩ := hzero
refine ⟨i,Finset.mem_univ i,?_⟩
simpa [hi,monomial] using ha i
theorem polynomial_contDiff (k : ι → ℕ × ℕ) :
ContDiff ℝ ∞ (fun q : (ι → ℝ) × Plane => polynomial k q.1 q.2) := by
apply ContDiff.sum
intro i _
dsimp [monomial]
fun_prop
theorem centered_contDiff (k : ι → ℕ × ℕ) :
ContDiff ℝ ∞ (fun q : ((ι → ℝ) × Plane) × Plane => centered k q.1.1 q.1.2 q.2) := by
apply ContDiff.prodMk <;> apply ContDiff.sum <;> intro i _ <;> dsimp [monomial] <;> fun_prop
theorem centered_eq (k : ι → ℕ × ℕ) (a : ι → ℝ) (p r : Plane) :
centered k a p r=numerator k a r-polynomial k a r • p := by
apply Prod.ext
· change (∑ i, (((k i).1:ℝ)-p.1)*a i*monomial (k i) r)=
(∑ i, ((k i).1:ℝ)*a i*monomial (k i) r)-(∑ i,a i*monomial (k i) r)*p.1
rw [Finset.sum_mul,← Finset.sum_sub_distrib]
apply Finset.sum_congr rfl
intro i _
ring
· change (∑ i, (((k i).2:ℝ)-p.2)*a i*monomial (k i) r)=
(∑ i, ((k i).2:ℝ)*a i*monomial (k i) r)-(∑ i,a i*monomial (k i) r)*p.2
rw [Finset.sum_mul,← Finset.sum_sub_distrib]
apply Finset.sum_congr rfl
intro i _
ring
theorem centered_moment {k : ι → ℕ × ℕ} {a : ι → ℝ} {r : Plane}
(hP : polynomial k a r≠0) : centered k a (moment k a r) r=0 := by
rw [centered_eq,moment,smul_smul,mul_inv_cancel₀ hP,one_smul,sub_self]
def monomialDerivative (k : ℕ × ℕ) (r : Plane) : Plane →L[ℝ] ℝ :=
((k.1:ℝ)*r.1^(k.1-1)*r.2^k.2) • ContinuousLinearMap.fst ℝ ℝ ℝ +
(r.1^k.1*(k.2:ℝ)*r.2^(k.2-1)) • ContinuousLinearMap.snd ℝ ℝ ℝ
theorem monomial_hasFDerivAt (k : ℕ × ℕ) (r : Plane) :
HasFDerivAt (monomial k) (monomialDerivative k r) r := by
have h := (((ContinuousLinearMap.fst ℝ ℝ ℝ).hasFDerivAt (x:=r)).pow k.1).mul
(((ContinuousLinearMap.snd ℝ ℝ ℝ).hasFDerivAt (x:=r)).pow k.2)
convert! h using 1
apply ContinuousLinearMap.ext
intro v
simp [monomialDerivative]
ring
def centeredDerivative (k : ι → ℕ × ℕ) (a : ι → ℝ) (p r : Plane) : Plane →L[ℝ] Plane :=
(∑ i, ((((k i).1:ℝ)-p.1)*a i) • monomialDerivative (k i) r).prod
(∑ i, ((((k i).2:ℝ)-p.2)*a i) • monomialDerivative (k i) r)
theorem centered_hasFDerivAt (k : ι → ℕ × ℕ) (a : ι → ℝ) (p r : Plane) :
HasFDerivAt (centered k a p) (centeredDerivative k a p r) r := by
convert! (HasFDerivAt.sum (u := Finset.univ) (fun i _ => (monomial_hasFDerivAt (k i) r).const_mul
((((k i).1:ℝ)-p.1)*a i))).prodMk
(HasFDerivAt.sum (u := Finset.univ) (fun i _ => (monomial_hasFDerivAt (k i) r).const_mul
((((k i).2:ℝ)-p.2)*a i))) using 1
ext v <;> simp [centered]
theorem centeredDerivative_apply (k : ι → ℕ × ℕ) (a : ι → ℝ) (p r v : Plane) :
centeredDerivative k a p r v =
(∑ i, ((((k i).1:ℝ)-p.1)*a i)*
(((k i).1:ℝ)*r.1^((k i).1-1)*r.2^(k i).2*v.1+
r.1^(k i).1*((k i).2:ℝ)*r.2^((k i).2-1)*v.2),
∑ i, ((((k i).2:ℝ)-p.2)*a i)*
(((k i).1:ℝ)*r.1^((k i).1-1)*r.2^(k i).2*v.1+
r.1^(k i).1*((k i).2:ℝ)*r.2^((k i).2-1)*v.2)) := by
simp [centeredDerivative,monomialDerivative,mul_add,mul_assoc]
def faceMass (k : ℕ × ℕ) (a t : ℝ) : ℝ := if k.1=0 then a*t^k.2 else 0
def transverse (k : ι → ℕ × ℕ) (a : ι → ℝ) (t : ℝ) : ℝ :=
∑ i,if (k i).1=1 then a i*t^(k i).2 else 0
def active (k : ι → ℕ × ℕ) (a : ι → ℝ) (p t : ℝ) : ℝ :=
∑ i,if (k i).1=0 then (((k i).2:ℝ)-p)*a i*((k i).2:ℝ)*t^((k i).2-1) else 0
theorem zero_power_derivative (n : ℕ) :
(n:ℝ)*(0:ℝ)^(n-1)=if n=1 then 1 else 0 := by
rcases n with _|n
· simp
· rcases n with _|n
· simp
· simp
theorem monomial_axis (k : ℕ × ℕ) (t : ℝ) :
monomial k (0,t)=if k.1=0 then t^k.2 else 0 := by
by_cases h : k.1=0
· simp [monomial,h]
· simp [monomial,h,zero_pow h]
theorem monomialDerivative_axis (k : ℕ × ℕ) (t : ℝ) (v : Plane) :
monomialDerivative k (0,t) v=
(if k.1=1 then t^k.2 else 0)*v.1+
(if k.1=0 then (k.2:ℝ)*t^(k.2-1) else 0)*v.2 := by
simp only [monomialDerivative,add_apply,
smul_apply,
smul_eq_mul,zero_power_derivative]
by_cases h0 : k.1=0
· simp [h0]
· by_cases h1 : k.1=1
· simp [h1]
· simp [h0,h1,zero_pow h0]
theorem centered_axis_snd (k : ι → ℕ × ℕ) (a : ι → ℝ) (p : Plane) (t : ℝ) :
(centered k a p (0,t)).2=∑ i,(((k i).2:ℝ)-p.2)*faceMass (k i) (a i) t := by
apply Finset.sum_congr rfl
intro i _
rw [monomial_axis]
by_cases h : (k i).1=0 <;> simp [faceMass,h,mul_assoc]
theorem centeredDerivative_axis_fst (k : ι → ℕ × ℕ) (a : ι → ℝ) (p t : ℝ) (v : Plane) :
(centeredDerivative k a (0,p) (0,t) v).1=transverse k a t*v.1 := by
simp only [centeredDerivative,ContinuousLinearMap.prod_apply,
sum_apply,smul_apply,smul_eq_mul,
monomialDerivative_axis,sub_zero,transverse,Finset.sum_mul]
apply Finset.sum_congr rfl
intro i _
by_cases h0 : (k i).1=0
· simp [h0]
· by_cases h1 : (k i).1=1
· simp [h1,mul_assoc]
· simp [h0,h1]
theorem centeredDerivative_axis_snd (k : ι → ℕ × ℕ) (a : ι → ℝ) (p t u : ℝ) :
(centeredDerivative k a (0,p) (0,t) (0,u)).2=active k a p t*u := by
simp only [centeredDerivative,ContinuousLinearMap.prod_apply,
sum_apply,smul_apply,smul_eq_mul,
monomialDerivative_axis,mul_zero,zero_add,active,Finset.sum_mul]
apply Finset.sum_congr rfl
intro i _
by_cases h : (k i).1=0 <;> simp [h,mul_assoc]
theorem transverse_pos {k : ι → ℕ × ℕ} {a : ι → ℝ} (ha : ∀ i,0<a i)
(he : ∃ i,k i=(1,0)) {t : ℝ} (ht : 0≤t) : 0<transverse k a t := by
classical
apply Finset.sum_pos'
· intro i _
split_ifs
· exact mul_nonneg (ha i).le (pow_nonneg ht _)
· rfl
· obtain ⟨i,hi⟩ := he
exact ⟨i,Finset.mem_univ i,by simpa [hi] using ha i⟩
theorem nat_mul_power (n : ℕ) (t : ℝ) :
(n:ℝ)*t^(n-1)*t=(n:ℝ)*t^n := by
rcases n with _|n
· simp
· simp only [Nat.succ_sub_one,pow_succ]
ring
theorem active_variance (k : ι → ℕ × ℕ) (a : ι → ℝ) (p t : ℝ)
(hz : (centered k a (0,p) (0,t)).2=0) :
active k a p t*t=∑ i,(((k i).2:ℝ)-p)^2*faceMass (k i) (a i) t := by
rw [centered_axis_snd] at hz
have he : active k a p t*t =
(∑ i,(((k i).2:ℝ)-p)^2*faceMass (k i) (a i) t)+
p*(∑ i,(((k i).2:ℝ)-p)*faceMass (k i) (a i) t) := by
rw [active,Finset.sum_mul,Finset.mul_sum,← Finset.sum_add_distrib]
apply Finset.sum_congr rfl
intro i _
by_cases h : (k i).1=0
· simp only [ite_eq_left h,faceMass]
calc
(((k i).2:ℝ)-p)*a i*((k i).2:ℝ)*t^((k i).2-1)*t =
((((k i).2:ℝ)-p)*a i)*(((k i).2:ℝ)*t^((k i).2-1)*t) := by ring
_ = _ := by rw [nat_mul_power]; ring
· simp [h,faceMass]
simpa only [hz,mul_zero,add_zero] using he
theorem active_pos {k : ι → ℕ × ℕ} {a : ι → ℝ} (ha : ∀ i,0<a i)
(hzero : ∃ i,k i=(0,0)) (he : ∃ i,k i=(0,1)) {p t : ℝ} (ht : 0<t)
(hz : (centered k a (0,p) (0,t)).2=0) : 0<active k a p t := by
have hV : 0<∑ i,(((k i).2:ℝ)-p)^2*faceMass (k i) (a i) t := by
classical
apply Finset.sum_pos'
· intro i _
apply mul_nonneg (sq_nonneg _)
unfold faceMass
split_ifs
· exact mul_nonneg (ha i).le (pow_nonneg ht.le _)
· rfl
· by_cases hp : p=0
· obtain ⟨i,hi⟩ := he
exact ⟨i,Finset.mem_univ i,by simpa [faceMass,hi,hp] using mul_pos (ha i) ht⟩
· obtain ⟨i,hi⟩ := hzero
refine ⟨i,Finset.mem_univ i,?_⟩
simpa [faceMass,hi] using mul_pos (sq_pos_of_ne_zero hp) (ha i)
rw [← active_variance k a p t hz] at hV
exact (mul_pos_iff_of_pos_right ht).mp hV
end PackingSufficiencySupport.FiniteMoment.Radial
end
end OAI