math / data /lean /OAI /Analysis /AllenCahn /Bernstein.lean
introvoyz045's picture
Migrated from GitHub
4a56cd6 verified
Raw History Blame Contribute Delete
20.8 kB
10
lemma diffuse_drift_commute {n : β„•} {v f r : Space n β†’ ℝ}
    (hv : ContDiff ℝ ∞ v) (hi : βˆ€ x, v x ∈ Set.Ioo (-1 : ℝ) 1)
    (hf : ContDiff ℝ ∞ f) (hr : ContDiff ℝ ∞ r)
    (heq : βˆ€ x, Laplacian.laplacian f x - fderiv ℝ f x (diffuseDrift v x) = r x)
    (k : Fin n) (x : Space n) :
    Laplacian.laplacian (coordDeriv f k) x - fderiv ℝ (coordDeriv f k) x (diffuseDrift v x) =
      coordDeriv r k x + βˆ‘ l : Fin n, coordDeriv (driftCoeff v l) k x * coordDeriv f l x := by
proof Β· 21 lines
  have hc (l : Fin n) := (tensorCoeff_smooth hv hi).2.2.2.2 l
  have hdc (l : Fin n) := (hc l).differentiable (by simp)
  have hdfl (l : Fin n) := (coordDeriv_smooth hf l).differentiable (by simp)
  have he : Laplacian.laplacian f = fun y => r y + βˆ‘ l : Fin n, driftCoeff v l y * coordDeriv f l y := by
    funext y
    have hh := heq y
    rw [fderiv_diffuseDrift_sum] at hh
    linarith
  rw [laplacian_coordDeriv hf, he, coordDeriv_add (g := fun y => βˆ‘ l : Fin n, driftCoeff v l y * coordDeriv f l y)
    (hr.differentiable (by simp))
    (Differentiable.fun_sum (fun l _ => (hdc l).fun_mul (hdfl l))),
    coordDeriv_sum (f := fun l y => driftCoeff v l y * coordDeriv f l y) _
      (fun l _ => (hdc l).fun_mul (hdfl l)), fderiv_diffuseDrift_sum]
  have hh (l : Fin n) : coordDeriv (fun y => driftCoeff v l y * coordDeriv f l y) k x =
      driftCoeff v l x * coordDeriv (coordDeriv f k) l x +
        coordDeriv (driftCoeff v l) k x * coordDeriv f l x := by
    rw [coordDeriv_mul (hdc l) (hdfl l), coordDeriv_comm (smooth_C2 hf) l k]
    ring
  simp_rw [hh]
  rw [Finset.sum_add_distrib]
  ring
39
lemma inverseHessian_deriv_drift_bound {n : β„•} {v : Space n β†’ ℝ}
    (hv : ContDiff ℝ ∞ v) (hi : βˆ€ x, v x ∈ Set.Ioo (-1 : ℝ) 1) (hAC : AllenCahn v)
    (i j k : Fin n) (x : Space n) :
    |Laplacian.laplacian (coordDeriv (inverseHessian v i j) k) x -
      fderiv ℝ (coordDeriv (inverseHessian v i j) k) x (diffuseDrift v x)| ≀
      tensorCoeffConstant n * (1 + 6 * n) *
        (diffuseDefect v x + Real.sqrt (hessianSquare v x) + Real.sqrt (tensorDerivativeSquare v x)) := by
proof Β· 23 lines
  rw [diffuse_drift_commute hv hi (inverseHessian_smooth hv hi i j) (tensorSource_smooth hv hi i j)
    (inverseHessian_drift_factored hv hi hAC i j)]
  let C := tensorCoeffConstant n
  let S := Real.sqrt (hessianSquare v x)
  let Q := Real.sqrt (tensorDerivativeSquare v x)
  have hC : 0 ≀ C := (tensorCoeffConstant_pos n).le
  have hD : 0 ≀ diffuseDefect v x := diffuseDefect_nonneg (smooth_C2 hv) hi hAC x
  have hS : 0 ≀ S := Real.sqrt_nonneg _
  have hQ : 0 ≀ Q := Real.sqrt_nonneg _
  have hh : |βˆ‘ l : Fin n, coordDeriv (driftCoeff v l) k x * coordDeriv (inverseHessian v i j) l x| ≀
      n * (C * Q) := by
    apply (Finset.abs_sum_le_sum_abs _ _).trans
    apply le_trans (Finset.sum_le_sum (fun (l : Fin n) (_ : l ∈ Finset.univ) => show
      |coordDeriv (driftCoeff v l) k x * coordDeriv (inverseHessian v i j) l x| ≀ C * Q by
        rw [abs_mul]
        exact mul_le_mul (((tensorCoeff_C1Bound hv hi hAC).2.2.2.2 l).2 k x)
          (inverseHessian_deriv_abs_le_sqrt v i j l x) (abs_nonneg _) hC))
    simp
  apply ((abs_add_le _ _).trans (add_le_add (tensorSource_coord_bound hv hi hAC i j k x) hh)).trans
  change C * (1 + 5 * n) * (diffuseDefect v x + S + Q) + n * (C * Q) ≀
    C * (1 + 6 * n) * (diffuseDefect v x + S + Q)
  have hpos : 0 ≀ C * n * (diffuseDefect v x + S) := by positivity
  nlinarith
70
lemma drift_sum_identity {n : β„•} {ΞΉ : Type*} (s : Finset ΞΉ) {f : ΞΉ β†’ Space n β†’ ℝ}
    (hf : βˆ€ i ∈ s, ContDiff ℝ 2 (f i)) (b : Space n β†’ Space n) (x : Space n) :
    Laplacian.laplacian (fun y => βˆ‘ i ∈ s, f i y) x -
      fderiv ℝ (fun y => βˆ‘ i ∈ s, f i y) x (b x) =
        βˆ‘ i ∈ s, (Laplacian.laplacian (f i) x - fderiv ℝ (f i) x (b x)) := by
proof Β· 3 lines
  rw [laplacian_sum s hf, fderiv_fun_sum (A := f)
    (fun i hi => (hf i hi).differentiable (by norm_num) x)]
  simp only [sum_apply, Finset.sum_sub_distrib]
79
lemma tensorDerivativeSquare_eq_sum {n : β„•} (v : Space n β†’ ℝ) (x : Space n) :
    tensorDerivativeSquare v x = βˆ‘ i : Fin n, βˆ‘ j : Fin n, βˆ‘ k : Fin n,
      coordDeriv (inverseHessian v i j) k x ^ 2 := by
proof Β· 1 line
  simp only [tensorDerivativeSquare, gradient_norm_sq]
84
lemma tensorDerivativeSquare_uniform {n : β„•} {v : Space n β†’ ℝ}
    (hv : ContDiff ℝ ∞ v) (hi : βˆ€ x, v x ∈ Set.Ioo (-1 : ℝ) 1) (hAC : AllenCahn v)
    (x : Space n) :
    tensorDerivativeSquare v x ≀ n ^ 3 * inverseJetConstant n ^ 2 := by
proof Β· 8 lines
  rw [tensorDerivativeSquare_eq_sum]
  have hh (i j k : Fin n) : coordDeriv (inverseHessian v i j) k x ^ 2 ≀ inverseJetConstant n ^ 2 := by
    rw [← sq_abs (coordDeriv (inverseHessian v i j) k x)]
    exact pow_le_pow_leftβ‚€ (abs_nonneg _) (((inverseJet_C1Bound hv hi hAC).2.2.2.2 i j).2 k x) 2
  apply (Finset.sum_le_sum (fun i _ => Finset.sum_le_sum (fun j _ =>
    Finset.sum_le_sum (fun k _ => hh i j k)))).trans
  simp only [Finset.sum_const, Finset.card_univ, Fintype.card_fin, nsmul_eq_mul]
  ring_nf; rfl
97
lemma tensorDerivativeSquare_drift_identity {n : β„•} {v : Space n β†’ ℝ}
    (hv : ContDiff ℝ ∞ v) (hi : βˆ€ x, v x ∈ Set.Ioo (-1 : ℝ) 1) (x : Space n) :
    Laplacian.laplacian (tensorDerivativeSquare v) x -
      fderiv ℝ (tensorDerivativeSquare v) x (diffuseDrift v x) =
    βˆ‘ i : Fin n, βˆ‘ j : Fin n, βˆ‘ k : Fin n,
      (2 * β€–gradient (coordDeriv (inverseHessian v i j) k) xβ€– ^ 2 +
        2 * coordDeriv (inverseHessian v i j) k x *
          (Laplacian.laplacian (coordDeriv (inverseHessian v i j) k) x -
            fderiv ℝ (coordDeriv (inverseHessian v i j) k) x (diffuseDrift v x))) := by
proof Β· 11 lines
  have hT (i j k : Fin n) := smooth_C2 (coordDeriv_smooth (inverseHessian_smooth hv hi i j) k)
  have he : tensorDerivativeSquare v = fun y => βˆ‘ i : Fin n, βˆ‘ j : Fin n, βˆ‘ k : Fin n,
      coordDeriv (inverseHessian v i j) k y ^ 2 := funext (tensorDerivativeSquare_eq_sum v)
  rw [he, drift_sum_identity _ (fun i _ => ContDiff.sum (fun j _ =>
    ContDiff.sum (fun k _ => (hT i j k).pow 2)))]
  apply Finset.sum_congr rfl; intro i _
  rw [drift_sum_identity _ (fun j _ => ContDiff.sum (fun k _ => (hT i j k).pow 2))]
  apply Finset.sum_congr rfl; intro j _
  rw [drift_sum_identity _ (fun k _ => (hT i j k).pow 2)]
  apply Finset.sum_congr rfl; intro k _
  exact drift_square_identity (hT i j k) (diffuseDrift v) x
118
def tensorSecondBernsteinConstant (n : β„•) : ℝ :=
body Β· 1 line
  1 + 3 * n ^ 3 * (tensorCoeffConstant n * (1 + 6 * n)) ^ 2 * (tensorBernsteinConstant n + 4)
121
lemma tensorSecondBernsteinConstant_pos (n : β„•) : 0 < tensorSecondBernsteinConstant n := by
proof Β· 1 line
  dsimp [tensorSecondBernsteinConstant, tensorBernsteinConstant]; positivity
124
lemma tensorDerivativeSquare_drift_lower {n : β„•} {v : Space n β†’ ℝ}
    (hv : ContDiff ℝ ∞ v) (hi : βˆ€ x, v x ∈ Set.Ioo (-1 : ℝ) 1) (hAC : AllenCahn v)
    (x : Space n) :
    -tensorSecondBernsteinConstant n * (tensorDerivativeSquare v x + diffuseDefect v x) ≀
      Laplacian.laplacian (tensorDerivativeSquare v) x -
        fderiv ℝ (tensorDerivativeSquare v) x (diffuseDrift v x) := by
proof Β· 51 lines
  let C := tensorCoeffConstant n * (1 + 6 * n)
  let S := Real.sqrt (hessianSquare v x)
  let Q := Real.sqrt (tensorDerivativeSquare v x)
  have hC : 0 ≀ C := mul_nonneg (tensorCoeffConstant_pos n).le (by positivity)
  have hD := diffuseDefect_nonneg (smooth_C2 hv) hi hAC x
  have hD1 := diffuseDefect_le_one v x
  have hD2 : diffuseDefect v x ^ 2 ≀ diffuseDefect v x := by nlinarith
  have hS : S ^ 2 = hessianSquare v x := Real.sq_sqrt (hessianSquare_nonneg v x)
  have hQ : Q ^ 2 = tensorDerivativeSquare v x := Real.sq_sqrt (tensorDerivativeSquare_nonneg v x)
  have hBs : 0 ≀ tensorBernsteinConstant n := by dsimp [tensorBernsteinConstant]; positivity
  have hpair (i j k : Fin n) :
      -(coordDeriv (inverseHessian v i j) k x ^ 2) -
        3 * C ^ 2 * (diffuseDefect v x + hessianSquare v x + tensorDerivativeSquare v x) ≀
      2 * β€–gradient (coordDeriv (inverseHessian v i j) k) xβ€– ^ 2 +
        2 * coordDeriv (inverseHessian v i j) k x *
          (Laplacian.laplacian (coordDeriv (inverseHessian v i j) k) x -
            fderiv ℝ (coordDeriv (inverseHessian v i j) k) x (diffuseDrift v x)) := by
    let R := Laplacian.laplacian (coordDeriv (inverseHessian v i j) k) x -
      fderiv ℝ (coordDeriv (inverseHessian v i j) k) x (diffuseDrift v x)
    have hR : |R| ≀ C * (diffuseDefect v x + S + Q) := inverseHessian_deriv_drift_bound hv hi hAC i j k x
    have hR2 : R ^ 2 ≀ 3 * C ^ 2 *
        (diffuseDefect v x + hessianSquare v x + tensorDerivativeSquare v x) := by
      calc R ^ 2 = |R| ^ 2 := (sq_abs R).symm
        _ ≀ (C * (diffuseDefect v x + S + Q)) ^ 2 := pow_le_pow_leftβ‚€ (abs_nonneg R) hR 2
        _ = C ^ 2 * (diffuseDefect v x + S + Q) ^ 2 := by ring
        _ ≀ C ^ 2 * (3 * (diffuseDefect v x + hessianSquare v x + tensorDerivativeSquare v x)) := by
          apply mul_le_mul_of_nonneg_left _ (sq_nonneg C)
          nlinarith [sq_nonneg (diffuseDefect v x - S), sq_nonneg (diffuseDefect v x - Q), sq_nonneg (S - Q)]
        _ = _ := by ring
    have hy := sq_nonneg (coordDeriv (inverseHessian v i j) k x + R)
    have hg := sq_nonneg β€–gradient (coordDeriv (inverseHessian v i j) k) xβ€–
    change _ ≀ 2 * β€–gradient (coordDeriv (inverseHessian v i j) k) xβ€– ^ 2 +
      2 * coordDeriv (inverseHessian v i j) k x * R
    nlinarith
  rw [tensorDerivativeSquare_drift_identity hv hi]
  have hsum := Finset.sum_le_sum (fun (i : Fin n) (_ : i ∈ Finset.univ) =>
    Finset.sum_le_sum (fun (j : Fin n) (_ : j ∈ Finset.univ) =>
      Finset.sum_le_sum (fun (k : Fin n) (_ : k ∈ Finset.univ) => hpair i j k)))
  apply le_trans _ hsum
  simp only [Finset.sum_sub_distrib, Finset.sum_neg_distrib, Finset.sum_const,
    Finset.card_univ, Fintype.card_fin, nsmul_eq_mul]
  rw [← tensorDerivativeSquare_eq_sum]
  have hFD := hessianSquare_le_defect hv hi hAC x
  have hE := tensorDerivativeSquare_nonneg v x
  have hbig : diffuseDefect v x + hessianSquare v x + tensorDerivativeSquare v x ≀
      (tensorBernsteinConstant n + 4) * (diffuseDefect v x + tensorDerivativeSquare v x) := by
    nlinarith [mul_nonneg hBs hE]
  have hscale := mul_le_mul_of_nonneg_left hbig (show 0 ≀ 3 * (n : ℝ) ^ 3 * C ^ 2 by positivity)
  dsimp only [tensorSecondBernsteinConstant]
  change -(1 + 3 * (n : ℝ) ^ 3 * C ^ 2 * (tensorBernsteinConstant n + 4)) * _ ≀ _
  nlinarith
182
lemma hessianSquare_drift_lower_refined {n : β„•} {v : Space n β†’ ℝ}
    (hv : ContDiff ℝ ∞ v) (hi : βˆ€ x, v x ∈ Set.Ioo (-1 : ℝ) 1) (hAC : AllenCahn v)
    (x : Space n) :
    2 * tensorDerivativeSquare v x - tensorBernsteinConstant n * (hessianSquare v x + diffuseDefect v x ^ 2) ≀
      Laplacian.laplacian (hessianSquare v) x - fderiv ℝ (hessianSquare v) x (diffuseDrift v x) := by
proof Β· 37 lines
  let C := tensorSystemConstant n
  let S := Real.sqrt (hessianSquare v x)
  have hC : 0 ≀ C := by dsimp [C, tensorSystemConstant]; positivity
  have hS : 0 ≀ S := Real.sqrt_nonneg _
  have hSsq : S ^ 2 = hessianSquare v x := Real.sq_sqrt (hessianSquare_nonneg v x)
  have hD : 0 ≀ diffuseDefect v x := diffuseDefect_nonneg (smooth_C2 hv) hi hAC x
  have hpair (i j : Fin n) :
      2 * β€–gradient (inverseHessian v i j) xβ€– ^ 2 - (inverseHessian v i j x ^ 2) - 2 * C ^ 2 * (hessianSquare v x + diffuseDefect v x ^ 2) ≀
        2 * β€–gradient (inverseHessian v i j) xβ€– ^ 2 +
        2 * inverseHessian v i j x * (Laplacian.laplacian (inverseHessian v i j) x -
          fderiv ℝ (inverseHessian v i j) x (diffuseDrift v x)) := by
    let R := Laplacian.laplacian (inverseHessian v i j) x - fderiv ℝ (inverseHessian v i j) x (diffuseDrift v x)
    have hR : |R| ≀ C * (diffuseDefect v x + S) := inverseHessian_drift_abs_bound hv hi hAC i j x
    have hR2 : R ^ 2 ≀ 2 * C ^ 2 * (hessianSquare v x + diffuseDefect v x ^ 2) := by
      calc R ^ 2 = |R| ^ 2 := (sq_abs R).symm
        _ ≀ (C * (diffuseDefect v x + S)) ^ 2 := pow_le_pow_leftβ‚€ (abs_nonneg R) hR 2
        _ = C ^ 2 * (diffuseDefect v x + S) ^ 2 := by ring
        _ ≀ C ^ 2 * (2 * (hessianSquare v x + diffuseDefect v x ^ 2)) := by
          apply mul_le_mul_of_nonneg_left _ (sq_nonneg C)
          nlinarith [sq_nonneg (diffuseDefect v x - S)]
        _ = _ := by ring
    have hy := sq_nonneg (inverseHessian v i j x + R)
    have hg := sq_nonneg β€–gradient (inverseHessian v i j) xβ€–
    change _ ≀ 2 * β€–gradient (inverseHessian v i j) xβ€– ^ 2 + 2 * inverseHessian v i j x * R
    nlinarith
  rw [hessianSquare_drift_identity hv hi]
  have hsum := Finset.sum_le_sum (fun (i : Fin n) (_ : i ∈ Finset.univ) =>
    Finset.sum_le_sum (fun (j : Fin n) (_ : j ∈ Finset.univ) => hpair i j))
  apply le_trans _ hsum
  simp only [Finset.sum_sub_distrib, Finset.sum_const,
    Finset.card_univ, Fintype.card_fin, nsmul_eq_mul, ← Finset.mul_sum]
  rw [← hessianSquare_eq_sum]
  change 2 * tensorDerivativeSquare v x - tensorBernsteinConstant n * _ ≀
    2 * tensorDerivativeSquare v x - hessianSquare v x - _
  dsimp only [tensorBernsteinConstant]
  change 2 * tensorDerivativeSquare v x - (1 + 2 * (n : ℝ) ^ 2 * C ^ 2) * _ ≀ _
  nlinarith [sq_nonneg (diffuseDefect v x)]
225
def carrierScale (n : β„•) : ℝ := 2 * (tensorBernsteinConstant n + 3) + 1
227
def defectCarrier {n : β„•} (v : Space n β†’ ℝ) (x : Space n) : ℝ :=
body Β· 1 line
  diffuseDefect v x - hessianSquare v x / carrierScale n
230
lemma carrierScale_pos (n : β„•) : 0 < carrierScale n := by
proof Β· 1 line
  dsimp [carrierScale, tensorBernsteinConstant]; positivity
233
lemma defectCarrier_smooth {n : β„•} {v : Space n β†’ ℝ}
    (hv : ContDiff ℝ ∞ v) (hi : βˆ€ x, v x ∈ Set.Ioo (-1 : ℝ) 1) :
    ContDiff ℝ ∞ (defectCarrier v) := (diffuseDefect_smooth hv hi).sub
proof Β· 1 line
      ((hessianSquare_smooth hv hi).div_const _)
238
lemma defectCarrier_bounds {n : β„•} {v : Space n β†’ ℝ}
    (hv : ContDiff ℝ ∞ v) (hi : βˆ€ x, v x ∈ Set.Ioo (-1 : ℝ) 1) (hAC : AllenCahn v)
    (x : Space n) : diffuseDefect v x / 2 ≀ defectCarrier v x ∧ defectCarrier v x ≀ diffuseDefect v x := by
proof Β· 10 lines
  have hF := hessianSquare_le_defect hv hi hAC x
  have hD := diffuseDefect_nonneg (smooth_C2 hv) hi hAC x
  have hscale := carrierScale_pos n
  have hFp := hessianSquare_nonneg v x
  have hquot : hessianSquare v x / carrierScale n ≀ diffuseDefect v x / 2 := by
    apply (div_le_iffβ‚€ hscale).mpr
    dsimp [carrierScale]
    nlinarith
  dsimp [defectCarrier]
  exact ⟨by linarith, sub_le_self _ (div_nonneg hFp hscale.le)⟩
252
lemma drift_const_mul {n : β„•} {f : Space n β†’ ℝ} (hf : ContDiff ℝ 2 f)
    (b : Space n β†’ Space n) (c : ℝ) (x : Space n) :
    Laplacian.laplacian (fun y => c * f y) x - fderiv ℝ (fun y => c * f y) x (b x) =
      c * (Laplacian.laplacian f x - fderiv ℝ f x (b x)) := by
proof Β· 3 lines
  rw [laplacian_fun_const_mul hf]
  rw [fderiv_const_mul (hf.differentiable (by norm_num) x)]
  simp only [smul_apply, smul_eq_mul]; ring
260
lemma drift_sub {n : β„•} {f g : Space n β†’ ℝ} (hf : ContDiff ℝ 2 f) (hg : ContDiff ℝ 2 g)
    (b : Space n β†’ Space n) (x : Space n) :
    Laplacian.laplacian (fun y => f y - g y) x - fderiv ℝ (fun y => f y - g y) x (b x) =
      (Laplacian.laplacian f x - fderiv ℝ f x (b x)) -
        (Laplacian.laplacian g x - fderiv ℝ g x (b x)) := by
proof Β· 3 lines
  rw [laplacian_fun_sub hf hg, fderiv_fun_sub (hf.differentiable (by norm_num) x)
    (hg.differentiable (by norm_num) x)]
  simp only [sub_apply]; ring
269
lemma defectCarrier_drift_upper {n : β„•} {v : Space n β†’ ℝ}
    (hv : ContDiff ℝ ∞ v) (hi : βˆ€ x, v x ∈ Set.Ioo (-1 : ℝ) 1) (hAC : AllenCahn v)
    (x : Space n) :
    Laplacian.laplacian (defectCarrier v) x - fderiv ℝ (defectCarrier v) x (diffuseDrift v x) ≀
      2 * (2 + tensorBernsteinConstant n * (tensorBernsteinConstant n + 4) / carrierScale n) *
        defectCarrier v x - 2 * (tensorDerivativeSquare v x / carrierScale n) := by
proof Β· 24 lines
  have hD := diffuseDefect_nonneg (smooth_C2 hv) hi hAC x
  have hD1 := diffuseDefect_le_one v x
  have hD2 : diffuseDefect v x ^ 2 ≀ diffuseDefect v x := by nlinarith
  have hF := hessianSquare_le_defect hv hi hAC x
  have hF0 := hessianSquare_nonneg v x
  have hBs : 0 ≀ tensorBernsteinConstant n := by dsimp [tensorBernsteinConstant]; positivity
  have hs := carrierScale_pos n
  have hCD := (defectCarrier_bounds hv hi hAC x).1
  have hUp := diffuseDefect_drift_upper hv hi hAC x
  have hLow := hessianSquare_drift_lower_refined hv hi hAC x
  have hlow' := div_le_div_of_nonneg_right hLow hs.le
  have hFd : hessianSquare v x + diffuseDefect v x ^ 2 ≀
      (tensorBernsteinConstant n + 4) * diffuseDefect v x := by linarith
  have hFd' := div_le_div_of_nonneg_right (mul_le_mul_of_nonneg_left hFd hBs) hs.le
  have hCD' := mul_le_mul_of_nonneg_left hCD
    (show 0 ≀ 2 * (2 + tensorBernsteinConstant n * (tensorBernsteinConstant n + 4) / carrierScale n) by positivity)
  have he : defectCarrier v = fun y => diffuseDefect v y -
      (carrierScale n)⁻¹ * hessianSquare v y := by funext y; simp [defectCarrier, div_eq_mul_inv, mul_comm]
  rw [he, drift_sub (smooth_C2 (diffuseDefect_smooth hv hi))
    (contDiff_const.mul (smooth_C2 (hessianSquare_smooth hv hi))),
    drift_const_mul (smooth_C2 (hessianSquare_smooth hv hi))]
  rw [he] at hCD'
  simp only [div_eq_mul_inv] at hlow' hFd' hCD' ⊒
  nlinarith
300
lemma C1Bound.sub {n : β„•} {f g : Space n β†’ ℝ} {C K : ℝ}
    (hf : Differentiable ℝ f) (hg : Differentiable ℝ g) (h : C1Bound f C) (h' : C1Bound g K) :
    C1Bound (fun x => f x - g x) (C + K) := by
proof Β· 6 lines
  constructor
  Β· intro x; exact (abs_sub (f x) (g x)).trans (add_le_add (h.1 x) (h'.1 x))
  Β· intro i x
    change |fderiv ℝ (fun y => f y - g y) x (basis n i)| ≀ _
    rw [fderiv_fun_sub (hf x) (hg x), sub_apply]
    exact (abs_sub _ _).trans (add_le_add (h.2 i x) (h'.2 i x))
310
lemma C1Bound.sum {n : β„•} {ΞΉ : Type*} (s : Finset ΞΉ) {f : ΞΉ β†’ Space n β†’ ℝ} {C : ΞΉ β†’ ℝ}
    (hf : βˆ€ i ∈ s, Differentiable ℝ (f i)) (h : βˆ€ i ∈ s, C1Bound (f i) (C i)) :
    C1Bound (fun x => βˆ‘ i ∈ s, f i x) (βˆ‘ i ∈ s, C i) := by
proof Β· 5 lines
  constructor
  Β· intro x; exact (Finset.abs_sum_le_sum_abs _ _).trans (Finset.sum_le_sum (fun i hi => (h i hi).1 x))
  Β· intro k x
    rw [coordDeriv_sum s hf]
    exact (Finset.abs_sum_le_sum_abs _ _).trans (Finset.sum_le_sum (fun i hi => (h i hi).2 k x))
319
lemma C1Bound.gradient_bound {n : β„•} {f : Space n β†’ ℝ} {C : ℝ} (h : C1Bound f C) (x : Space n) :
    β€–gradient f xβ€– ≀ n * C := by
proof Β· 2 lines
  apply (gradient_norm_le_sum_abs f x).trans
  exact (Finset.sum_le_sum (fun k _ => h.2 k x)).trans_eq (by simp)
324
lemma hessianSquare_C1Bound {n : β„•} {v : Space n β†’ ℝ}
    (hv : ContDiff ℝ ∞ v) (hi : βˆ€ x, v x ∈ Set.Ioo (-1 : ℝ) 1) (hAC : AllenCahn v) :
    C1Bound (hessianSquare v) (2 * n ^ 2 * inverseJetConstant n ^ 2) := by
proof Β· 12 lines
  have hJ : 0 ≀ inverseJetConstant n := (by norm_num : (0 : ℝ) ≀ 1).trans (inverseJetConstant_one_le n)
  have hT (i j : Fin n) := (inverseHessian_smooth hv hi i j).differentiable (by simp)
  have hb (i j : Fin n) := (inverseJet_C1Bound hv hi hAC).2.2.2.2 i j
  have hp (i j : Fin n) := (hb i j).mul (hT i j) (hT i j) hJ hJ (hb i j)
  have hh := C1Bound.sum Finset.univ
    (fun i _ => Differentiable.fun_sum (fun j _ => (hT i j).fun_mul (hT i j)))
    (fun i _ => C1Bound.sum Finset.univ (fun j _ => (hT i j).fun_mul (hT i j)) (fun j _ => hp i j))
  have he : (fun y => βˆ‘ i : Fin n, βˆ‘ j : Fin n, inverseHessian v i j y * inverseHessian v i j y) =
      hessianSquare v := by funext y; simp only [← pow_two, ← hessianSquare_eq_sum]
  rw [he] at hh
  convert hh using 1
  simp only [Finset.sum_const, Finset.card_univ, Fintype.card_fin, nsmul_eq_mul]; ring
340
lemma defectCarrier_gradient_bound {n : β„•} {v : Space n β†’ ℝ}
    (hv : ContDiff ℝ ∞ v) (hi : βˆ€ x, v x ∈ Set.Ioo (-1 : ℝ) 1) (hAC : AllenCahn v)
    (x : Space n) :
    β€–gradient (defectCarrier v) xβ€– ≀
      n * (inverseJetConstant n + (carrierScale n)⁻¹ * (2 * n ^ 2 * inverseJetConstant n ^ 2)) := by
proof Β· 9 lines
  have hF := hessianSquare_C1Bound hv hi hAC
  have hD := (inverseJet_C1Bound hv hi hAC).2.2.1
  have hdF := (hessianSquare_smooth hv hi).differentiable (by simp)
  have hdD := (diffuseDefect_smooth hv hi).differentiable (by simp)
  have hh := hD.sub hdD (hdF.const_mul _) (hF.const_mul hdF (by positivity) (carrierScale n)⁻¹)
  have he : (fun y => diffuseDefect v y - (carrierScale n)⁻¹ * hessianSquare v y) = defectCarrier v := by
    funext y; simp [defectCarrier, div_eq_mul_inv, mul_comm]
  rw [he, abs_of_pos (inv_pos.mpr (carrierScale_pos n))] at hh
  exact hh.gradient_bound x