import NavierStokes.WeightedQuotients import Mathlib.Analysis.Calculus.MeanValue noncomputable section namespace NavierStokes.ClosedIntervalJetAlgebra open Set open scoped ContDiff BigOperators abbrev J : Set ℝ := Icc (-1 : ℝ) 1 theorem uniqueDiff : UniqueDiffOn ℝ J := uniqueDiffOn_Icc (by norm_num) def Bound (k : ℕ) (f : ℝ → ℝ) (B : ℝ) : Prop := ∀ n ≤ k, ∀ η ∈ J, ‖iteratedFDerivWithin ℝ n f J η‖ ≤ B theorem Bound.mono {k : ℕ} {f : ℝ → ℝ} {B C : ℝ} (hf : Bound k f B) (hBC : B ≤ C) : Bound k f C := fun n hn η hη => (hf n hn η hη).trans hBC theorem Bound.nonneg {k : ℕ} {f : ℝ → ℝ} {B : ℝ} (hf : Bound k f B) : 0 ≤ B := (norm_nonneg _).trans (hf 0 (Nat.zero_le _) 0 (by constructor <;> norm_num)) theorem Bound.const (k : ℕ) (c : ℝ) : Bound k (fun _ => c) |c| := by intro n hn η hη by_cases hn0 : n = 0 · subst n; simp · rw [iteratedFDerivWithin_const_of_ne hn0] simpa only [Pi.zero_apply, norm_zero] using abs_nonneg c theorem Bound.sub {k : ℕ} {f g : ℝ → ℝ} {A B : ℝ} (hf : ContDiffOn ℝ ∞ f J) (hg : ContDiffOn ℝ ∞ g J) (ha : Bound k f A) (hb : Bound k g B) : Bound k (fun η => f η - g η) (A + B) := by intro n hn η hη rw [fun_iteratedFDerivWithin_sub_apply ((hf η hη).of_le (WeightedQuotients.nat_le_infty n)) ((hg η hη).of_le (WeightedQuotients.nat_le_infty n)) uniqueDiff hη] exact (norm_sub_le _ _).trans (add_le_add (ha n hn η hη) (hb n hn η hη)) theorem Bound.congr {k : ℕ} {f g : ℝ → ℝ} {B : ℝ} (hf : Bound k f B) (he : EqOn g f J) : Bound k g B := by intro n hn η hη rw [iteratedFDerivWithin_congr he hη] exact hf n hn η hη theorem Bound.mul {k : ℕ} {f g : ℝ → ℝ} {A B : ℝ} (hf : ContDiffOn ℝ ∞ f J) (hg : ContDiffOn ℝ ∞ g J) (ha : Bound k f A) (hb : Bound k g B) : Bound k (fun η => f η * g η) ((2 : ℝ)^k * A * B) := by intro n hn η hη refine (norm_iteratedFDerivWithin_mul_le hf hg uniqueDiff hη (WeightedQuotients.nat_le_infty n)).trans ?_ calc _ ≤ ∑ i ∈ Finset.range (n+1), (n.choose i : ℝ) * A * B := by apply Finset.sum_le_sum intro i hi have hin : i ≤ n := Nat.le_of_lt_succ (Finset.mem_range.mp hi) exact mul_le_mul (mul_le_mul_of_nonneg_left (ha i (hin.trans hn) η hη) (Nat.cast_nonneg _)) (hb (n-i) ((Nat.sub_le _ _).trans hn) η hη) (norm_nonneg _) (mul_nonneg (Nat.cast_nonneg _) ha.nonneg) _ = (2 : ℝ)^n * A * B := by rw [← Finset.sum_mul, ← Finset.sum_mul] congr 2 exact_mod_cast Nat.sum_range_choose n _ ≤ (2 : ℝ)^k * A * B := mul_le_mul_of_nonneg_right (mul_le_mul_of_nonneg_right (pow_le_pow_right₀ (by norm_num) hn) ha.nonneg) hb.nonneg /-- Uniform algebraic control of a pair and a linear bound for its difference. -/ structure PairBound (k : ℕ) (f g : ℝ → ℝ) (B C ε : ℝ) : Prop where smooth_left : ContDiffOn ℝ ∞ f J smooth_right : ContDiffOn ℝ ∞ g J left : Bound k f B right : Bound k g B difference : Bound k (fun η => g η - f η) (C * ε) namespace PairBound variable {k : ℕ} {f g u v : ℝ → ℝ} {A B C D ε : ℝ} theorem same (hf : ContDiffOn ℝ ∞ f J) (hb : Bound k f A) (ε : ℝ) : PairBound k f f A 0 ε := by refine ⟨hf, hf, hb, hb, ?_⟩ simpa only [sub_self, zero_mul, abs_zero] using Bound.const k 0 theorem inverse (h : PairBound k f g A C ε) {μ T : ℝ} (hμ : 0 < μ) (hf : ∀ η ∈ J, μ ≤ f η) (hg : ∀ η ∈ J, μ ≤ g η) (hb : ∀ z : ℝ → ℝ, ContDiffOn ℝ ∞ z J → (∀ η ∈ J, μ ≤ z η) → Bound k z A → Bound k (fun η => (z η)⁻¹) T) : PairBound k (fun η => (f η)⁻¹) (fun η => (g η)⁻¹) T ((2 : ℝ)^k*((2 : ℝ)^k*C*T)*T) ε := by have hfn : ∀ η ∈ J, f η ≠ 0 := fun η hη => (hμ.trans_le (hf η hη)).ne' have hgn : ∀ η ∈ J, g η ≠ 0 := fun η hη => (hμ.trans_le (hg η hη)).ne' have hfs := h.smooth_left.inv hfn have hgs := h.smooth_right.inv hgn have hfb := hb f h.smooth_left hf h.left have hgb := hb g h.smooth_right hg h.right refine ⟨hfs, hgs, hfb, hgb, ?_⟩ have hd := ((h.difference.mul (h.smooth_right.sub h.smooth_left) hgs hgb).mul ((h.smooth_right.sub h.smooth_left).mul hgs) hfs hfb) have hd' : Bound k (fun η => -((g η-f η)*(g η)⁻¹*(f η)⁻¹)) ((2 : ℝ)^k*((2 : ℝ)^k*C*T)*T*ε) := by have hz := (Bound.const k 0).sub contDiffOn_const (((h.smooth_right.sub h.smooth_left).mul hgs).mul hfs) hd convert hz using 1 <;> first | (ext η; simp) | ring exact hd'.congr (fun η hη => by field_simp [hfn η hη, hgn η hη]; ring) end PairBound theorem Bound.id (k : ℕ) : Bound k (fun η => η) 1 := by intro n hn η hη rw [norm_iteratedFDerivWithin_eq_norm_iteratedDerivWithin, iteratedDerivWithin_fun_id hη uniqueDiff] split_ifs <;> simp only [Real.norm_eq_abs, abs_one, abs_zero] · exact abs_le.mpr hη · exact le_rfl · norm_num /-- A finite expression made from the exact scalar additions and products. -/ inductive PolynomialExpression (ι : Type) | input : ι → PolynomialExpression ι | constant : ℝ → PolynomialExpression ι | add : PolynomialExpression ι → PolynomialExpression ι → PolynomialExpression ι | sub : PolynomialExpression ι → PolynomialExpression ι → PolynomialExpression ι | mul : PolynomialExpression ι → PolynomialExpression ι → PolynomialExpression ι namespace PolynomialExpression variable {ι : Type} end PolynomialExpression end NavierStokes.ClosedIntervalJetAlgebra