import OAI.Geometry.IsometricImmersion.Calculus.QuotientLowBounds namespace OAI noncomputable section open Set Filter open scoped ContDiff Topology namespace SmoothLocal.Geometry def CoordinateBound (f : Coord → ℝ) (U : Set Coord) (n : ℕ) (M : ℝ) : Prop := ∀ ds : List (Fin 2), ds.length ≤ n → ∀ p ∈ U, |iteratedCoordPartial ds f p| ≤ M namespace CoordinateBound theorem mono {f : Coord → ℝ} {U : Set Coord} {n m : ℕ} {M N : ℝ} (hf : CoordinateBound f U n M) (hm : m ≤ n) (hMN : M ≤ N) : CoordinateBound f U m N := fun ds hds p hp => (hf ds (hds.trans hm) p hp).trans hMN theorem iterated_append (ds es : List (Fin 2)) (f : Coord → ℝ) : iteratedCoordPartial (ds ++ es) f = iteratedCoordPartial ds (iteratedCoordPartial es f) := by induction ds with | nil => rfl | cons i ds ih => simp only [List.cons_append, iteratedCoordPartial, ih] theorem partial_bound {f : Coord → ℝ} {U : Set Coord} {n : ℕ} {M : ℝ} (hf : CoordinateBound f U (n + 1) M) (i : Fin 2) : CoordinateBound (coordPartial i f) U n M := by intro ds hds p hp have hh := hf (ds ++ [i]) (by simpa only [List.length_append, List.length_singleton] using Nat.add_le_add_right hds 1) p hp rw [iterated_append] at hh exact hh theorem iterated_add {f h : Coord → ℝ} {U : Set Coord} (hf : ContDiffOn ℝ ∞ f U) (hh : ContDiffOn ℝ ∞ h U) (hU : IsOpen U) (ds : List (Fin 2)) {p : Coord} (hp : p ∈ U) : iteratedCoordPartial ds (fun x => f x + h x) p = iteratedCoordPartial ds f p + iteratedCoordPartial ds h p := by induction ds generalizing p with | nil => rfl | cons i ds ih => have he : iteratedCoordPartial ds (fun x => f x + h x) =ᶠ[𝓝 p] (fun x => iteratedCoordPartial ds f x + iteratedCoordPartial ds h x) := by filter_upwards [hU.mem_nhds hp] with x hx exact ih hx change coordPartial i (iteratedCoordPartial ds (fun x => f x + h x)) p = _ rw [coordPartial_eq_of_eventuallyEq he i] exact HessianCalculus.coordPartial_add_at (LowQuotient.iterated_differentiableAt hf hU hp ds) (LowQuotient.iterated_differentiableAt hh hU hp ds) i theorem iterated_sub {f h : Coord → ℝ} {U : Set Coord} (hf : ContDiffOn ℝ ∞ f U) (hh : ContDiffOn ℝ ∞ h U) (hU : IsOpen U) (ds : List (Fin 2)) {p : Coord} (hp : p ∈ U) : iteratedCoordPartial ds (fun x => f x - h x) p = iteratedCoordPartial ds f p - iteratedCoordPartial ds h p := by induction ds generalizing p with | nil => rfl | cons i ds ih => have he : iteratedCoordPartial ds (fun x => f x - h x) =ᶠ[𝓝 p] (fun x => iteratedCoordPartial ds f x - iteratedCoordPartial ds h x) := by filter_upwards [hU.mem_nhds hp] with x hx exact ih hx change coordPartial i (iteratedCoordPartial ds (fun x => f x - h x)) p = _ rw [coordPartial_eq_of_eventuallyEq he i] exact HessianCalculus.coordPartial_sub_at (LowQuotient.iterated_differentiableAt hf hU hp ds) (LowQuotient.iterated_differentiableAt hh hU hp ds) i theorem iterated_const_mul {f : Coord → ℝ} {U : Set Coord} (hf : ContDiffOn ℝ ∞ f U) (hU : IsOpen U) (c : ℝ) (ds : List (Fin 2)) {p : Coord} (hp : p ∈ U) : iteratedCoordPartial ds (fun x => c * f x) p = c * iteratedCoordPartial ds f p := by induction ds generalizing p with | nil => rfl | cons i ds ih => have he : iteratedCoordPartial ds (fun x => c * f x) =ᶠ[𝓝 p] (fun x => c * iteratedCoordPartial ds f x) := by filter_upwards [hU.mem_nhds hp] with x hx exact ih hx change coordPartial i (iteratedCoordPartial ds (fun x => c * f x)) p = _ rw [coordPartial_eq_of_eventuallyEq he i, HessianCalculus.coordPartial_mul_at (f := fun _ : Coord => c) (h := iteratedCoordPartial ds f) (differentiableAt_const c) (LowQuotient.iterated_differentiableAt hf hU hp ds) i] simp [coordPartial, iteratedCoordPartial] theorem add {f h : Coord → ℝ} {U : Set Coord} {n : ℕ} {A B : ℝ} (hf : ContDiffOn ℝ ∞ f U) (hh : ContDiffOn ℝ ∞ h U) (hU : IsOpen U) (hfB : CoordinateBound f U n A) (hhB : CoordinateBound h U n B) : CoordinateBound (fun x => f x + h x) U n (A + B) := by intro ds hds p hp rw [iterated_add hf hh hU ds hp] exact (abs_add_le _ _).trans (add_le_add (hfB ds hds p hp) (hhB ds hds p hp)) theorem sub {f h : Coord → ℝ} {U : Set Coord} {n : ℕ} {A B : ℝ} (hf : ContDiffOn ℝ ∞ f U) (hh : ContDiffOn ℝ ∞ h U) (hU : IsOpen U) (hfB : CoordinateBound f U n A) (hhB : CoordinateBound h U n B) : CoordinateBound (fun x => f x - h x) U n (A + B) := by intro ds hds p hp rw [iterated_sub hf hh hU ds hp] exact (abs_sub _ _).trans (add_le_add (hfB ds hds p hp) (hhB ds hds p hp)) theorem const_mul {f : Coord → ℝ} {U : Set Coord} {n : ℕ} {A : ℝ} (hf : ContDiffOn ℝ ∞ f U) (hU : IsOpen U) (hfB : CoordinateBound f U n A) (c : ℝ) : CoordinateBound (fun x => c * f x) U n (|c| * A) := by intro ds hds p hp rw [iterated_const_mul hf hU c ds hp, abs_mul] exact mul_le_mul_of_nonneg_left (hfB ds hds p hp) (abs_nonneg c) theorem neg {f : Coord → ℝ} {U : Set Coord} {n : ℕ} {A : ℝ} (hf : ContDiffOn ℝ ∞ f U) (hU : IsOpen U) (hfB : CoordinateBound f U n A) : CoordinateBound (fun x => -f x) U n A := by simpa only [neg_one_mul, abs_neg, abs_one, one_mul] using const_mul hf hU hfB (-1) private theorem abs_add_bound {x y A B : ℝ} (hx : |x| ≤ A) (hy : |y| ≤ B) : |x + y| ≤ A + B := (abs_add_le x y).trans (add_le_add hx hy) theorem mul_through_three {f h : Coord → ℝ} {U : Set Coord} {A B : ℝ} (hf : ContDiffOn ℝ ∞ f U) (hh : ContDiffOn ℝ ∞ h U) (hU : IsOpen U) (hA : 0 ≤ A) (hB : 0 ≤ B) (hfB : CoordinateBound f U 3 A) (hhB : CoordinateBound h U 3 B) : CoordinateBound (fun x => f x * h x) U 3 (8 * A * B) := by intro ds hds p hp have hab (vs ws : List (Fin 2)) (hv : vs.length ≤ 3) (hw : ws.length ≤ 3) : |iteratedCoordPartial vs f p * iteratedCoordPartial ws h p| ≤ A * B := by rw [abs_mul] exact mul_le_mul (hfB vs hv p hp) (hhB ws hw p hp) (abs_nonneg _) hA have hAB : 0 ≤ A * B := mul_nonneg hA hB cases ds with | nil => exact (hab [] [] (by norm_num) (by norm_num)).trans (by nlinarith) | cons i ds => cases ds with | nil => rw [LowQuotient.product_one hf hh hU hp i] exact (abs_add_bound (hab [i] [] (by norm_num) (by norm_num)) (hab [] [i] (by norm_num) (by norm_num))).trans (by nlinarith) | cons j ds => cases ds with | nil => rw [LowQuotient.product_two hf hh hU hp i j] exact (abs_add_bound (abs_add_bound (abs_add_bound (hab [i, j] [] (by norm_num) (by norm_num)) (hab [j] [i] (by norm_num) (by norm_num))) (hab [i] [j] (by norm_num) (by norm_num))) (hab [] [i, j] (by norm_num) (by norm_num))).trans (by nlinarith) | cons k ds => cases ds with | nil => rw [LowQuotient.product_three hf hh hU hp i j k] have hsum := abs_add_bound (abs_add_bound (abs_add_bound (abs_add_bound (abs_add_bound (abs_add_bound (abs_add_bound (hab [i, j, k] [] (by norm_num) (by norm_num)) (hab [j, k] [i] (by norm_num) (by norm_num))) (hab [i, k] [j] (by norm_num) (by norm_num))) (hab [k] [i, j] (by norm_num) (by norm_num))) (hab [i, j] [k] (by norm_num) (by norm_num))) (hab [j] [i, k] (by norm_num) (by norm_num))) (hab [i] [j, k] (by norm_num) (by norm_num))) (hab [] [i, j, k] (by norm_num) (by norm_num)) convert hsum using 1 <;> first | rfl | ring | cons l ds => simp only [List.length_cons] at hds; omega end CoordinateBound end SmoothLocal.Geometry end end OAI