math / data /lean /OAI /Probability /LatticeSurface /Dynamics /ProjectionDerivative.lean
introvoyz045's picture
Migrated from GitHub
4a56cd6 verified
Raw History Blame Contribute Delete
5.13 kB
import Mathlib
import OAI.Probability.LatticeSurface.Dynamics.ProjectionFaces
namespace OAI
namespace ProjectionComparison
open Set
variable {V E : Type*} [Fintype V] [Fintype E]
omit [Fintype V] [Fintype E] in
lemma active_values_constant (S : System V E) (h d : V β†’ ℝ)
(he : βˆ€ e,h (S.left e)-h (S.right e)=S.cost e β†’ d (S.left e)=d (S.right e))
(x y : V) (hxy : (activeGraph S h).Reachable x y) : d x=d y := by
obtain ⟨p⟩ := hxy
induction p with
| nil => rfl
| @cons x z y hxz p ih =>
rcases hxz with ⟨_,e,heh,hor⟩
have hek := he e heh
have hxz : d x=d z := by
rcases hor with ⟨rfl,rfl⟩ | ⟨rfl,rfl⟩
Β· exact hek
Β· exact hek.symm
exact hxz.trans ih
omit [Fintype V] in
lemma active_eventually_subset (S : System V E) (H : ℝ β†’ V β†’ ℝ) (t : ℝ)
(hc : βˆ€ x,ContinuousAt (fun s => H s x) t) :
βˆ€αΆ  s in nhds t,βˆ€ e,H s (S.left e)-H s (S.right e)=S.cost e β†’ H t (S.left e)-H t (S.right e)=S.cost e := by
apply Filter.eventually_all.mpr
intro e
by_cases he : H t (S.left e)-H t (S.right e)=S.cost e
Β· exact Filter.Eventually.of_forall (fun _ _ => he)
Β· have hne := ((hc (S.left e)).sub (hc (S.right e))).eventually (isOpen_ne.mem_nhds he)
filter_upwards [hne] with s hs
exact fun h => (hs h).elim
end ProjectionComparison
namespace ProjectionComparison
open Set
variable {V E : Type*} [Fintype V] [Fintype E]
theorem projection_derivative (S : System V E) (B U H : ℝ β†’ V β†’ ℝ) (dB dU dH : V β†’ ℝ) (t : ℝ)
(hp : βˆ€αΆ  s in nhds t,IsProjection S (B s) (U s) (H s))
(hb : βˆ€ x,HasDerivAt (fun s => B s x) (dB x) t)
(hu : βˆ€ x,HasDerivAt (fun s => U s x) (dU x) t)
(hh : βˆ€ x,HasDerivAt (fun s => H s x) (dH x) t) :
(βˆ€ x p,p∈S.pins β†’ (activeGraph S (H t)).Reachable x p β†’ dH x=dB p) ∧
(βˆ€ x,(βˆ€ p∈S.pins,Β¬(activeGraph S (H t)).Reachable x p) β†’
dH x=(βˆ‘ y∈activeComponent S (H t) x,dU y)/(activeComponent S (H t) x).card) := by
classical
have hed (e : E) (he : H t (S.left e)-H t (S.right e)=S.cost e) : dH (S.left e)=dH (S.right e) := by
have hmax : IsLocalMax (fun s => H s (S.left e)-H s (S.right e)) t := by
filter_upwards [hp] with s hs
rw [he]
exact hs.1.1 e
exact sub_eq_zero.mp (hmax.hasDerivAt_eq_zero ((hh (S.left e)).sub (hh (S.right e))))
have hpin (p : V) (hp' : p∈S.pins) : dH p=dB p := by
have heq : (fun s => H s p)=αΆ [nhds t](fun s => B s p) := hp.mono (fun s hs => hs.1.2 p hp')
exact ((hh p).congr_of_eventuallyEq heq.symm).unique (hb p)
constructor
Β· intro x p hp' hxp
exact (active_values_constant S (H t) dH hed x p hxp).trans (hpin p hp')
Β· intro x hground
let w : V β†’ ℝ := fun y => if (activeGraph S (H t)).Reachable x y then 1 else 0
have hw : βˆ€ p∈S.pins,w p=0 := by intro p hp';exact ite_eq_right (hground p hp')
have hedge (e : E) (he : H t (S.left e)-H t (S.right e)=S.cost e) : w (S.left e)=w (S.right e) := by
have hr := active_edge_reachable S (H t) e he
have hi : (activeGraph S (H t)).Reachable x (S.left e) ↔ (activeGraph S (H t)).Reachable x (S.right e) :=
⟨fun hx => hx.trans hr,fun hx => hx.trans hr.symm⟩
simp only [w,hi]
have heq : (fun s => βˆ‘ y,(H s y-U s y)*w y)=αΆ [nhds t](fun _ => (0:ℝ)) := by
filter_upwards [hp,active_eventually_subset S H t (fun x => (hh x).continuousAt)] with s hs ha
exact tangent_balance S (B s) (U s) (H s) w hs hw (fun e he => hedge e (ha e he))
have hd : HasDerivAt (fun s => βˆ‘ y,(H s y-U s y)*w y) (βˆ‘ y,(dH y-dU y)*w y) t := by
apply HasDerivAt.fun_sum
intro y hy
exact ((hh y).sub (hu y)).mul_const (w y)
have hzero : (βˆ‘ y,(dH y-dU y)*w y)=0 := (hd.congr_of_eventuallyEq heq.symm).unique (hasDerivAt_const t 0)
have hbal : (βˆ‘ y∈activeComponent S (H t) x,(dH y-dU y))=0 := by
calc
_ = βˆ‘ y∈activeComponent S (H t) x,(dH y-dU y)*w y := by
apply Finset.sum_congr rfl
intro y hy
simp only [w,ite_eq_left ((mem_activeComponent S (H t) x y).mp hy),mul_one]
_ = βˆ‘ y,(dH y-dU y)*w y := by
apply Finset.sum_subset (Finset.subset_univ _)
intro y hy hn
have hn' : Β¬(activeGraph S (H t)).Reachable x y := by simpa only [mem_activeComponent] using hn
simp only [w,ite_eq_right hn',mul_zero]
_ = 0 := hzero
have hconst : (βˆ‘ y∈activeComponent S (H t) x,dH y)=(activeComponent S (H t) x).card*dH x := by
trans βˆ‘ _y∈activeComponent S (H t) x,dH x
Β· apply Finset.sum_congr rfl
intro y hy
exact (active_values_constant S (H t) dH hed x y ((mem_activeComponent S (H t) x y).mp hy)).symm
Β· simp only [Finset.sum_const,nsmul_eq_mul]
have hx : x∈activeComponent S (H t) x := (mem_activeComponent S (H t) x x).mpr (.refl x)
have hcard : (0:ℝ)<(activeComponent S (H t) x).card := Nat.cast_pos.mpr (Finset.card_pos.mpr ⟨x,hx⟩)
apply (eq_div_iff hcard.ne').mpr
rw [Finset.sum_sub_distrib,hconst] at hbal
linarith
end ProjectionComparison
end OAI