import NavierStokes.TangentODE import Mathlib.Analysis.Normed.Operator.Banach import Mathlib.Analysis.Calculus.ContDiff.Operations /-! # Smooth dependence of finite-interval linear ODE solutions The coefficient and forcing are elements of spaces of continuous paths with the supremum norm. The actual integral equation is solved by an invertible Volterra operator. Smooth inversion then gives parameter dependence without assuming smoothness of a pre-existing family of solutions. -/ namespace NavierStokes.ParametricODE noncomputable section open Set Function Filter Metric intervalIntegral MeasureTheory open scoped Topology NNReal Nat Interval ContDiff variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] [CompleteSpace E] abbrev Curve (a b : ℝ) (E : Type*) [TopologicalSpace E] := C(Icc a b, E) abbrev Coefficient (a b : ℝ) (E : Type*) [NormedAddCommGroup E] [NormedSpace ℝ E] := Curve a b (E →L[ℝ] E) variable {a b : ℝ} (hab : a ≤ b) def extend (f : Curve a b E) (t : ℝ) : E := f (projIcc a b hab t) omit [NormedSpace ℝ E] [CompleteSpace E] in theorem continuous_extend (f : Curve a b E) : Continuous (extend hab f) := f.continuous.comp continuous_projIcc omit [NormedSpace ℝ E] [CompleteSpace E] in theorem extend_coe (f : Curve a b E) (t : Icc a b) : extend hab f t = f t := by simp only [extend, projIcc_val] def integralPath (f : Curve a b E) : Curve a b E := ⟨fun t => ∫ s in a..t, extend hab f s, by have hd (t : ℝ) : HasDerivAt (fun t => ∫ s in a..t, extend hab f s) (extend hab f t) t := integral_hasDerivAt_right ((continuous_extend hab f).intervalIntegrable _ _) ((continuous_extend hab f).stronglyMeasurableAtFilter _ _) (continuous_extend hab f).continuousAt exact (continuous_iff_continuousAt.mpr (fun t => (hd t).continuousAt)).comp continuous_subtype_val⟩ theorem norm_integralPath_le (f : Curve a b E) : ‖integralPath hab f‖ ≤ (b - a) * ‖f‖ := by apply (ContinuousMap.norm_le _ (mul_nonneg (sub_nonneg.mpr hab) (norm_nonneg _))).mpr intro t change ‖∫ s in a..(t : ℝ), extend hab f s‖ ≤ _ calc _ ≤ ‖f‖ * |(t : ℝ) - a| := norm_integral_le_of_norm_le_const fun s _ => f.norm_coe_le_norm _ _ ≤ ‖f‖ * (b - a) := by apply mul_le_mul_of_nonneg_left _ (norm_nonneg _) rw [abs_of_nonneg (sub_nonneg.mpr t.2.1)] exact sub_le_sub_right t.2.2 a _ = _ := mul_comm _ _ def integrator : Curve a b E →L[ℝ] Curve a b E := LinearMap.mkContinuous { toFun := integralPath hab map_add' := by intro f g ext t exact integral_add ((continuous_extend hab f).intervalIntegrable _ _) ((continuous_extend hab g).intervalIntegrable _ _) map_smul' := by intro c f ext t exact integral_smul c (extend hab f) } (b - a) (norm_integralPath_le hab) theorem integrator_apply (f : Curve a b E) (t : Icc a b) : integrator hab f t = ∫ s in a..(t : ℝ), extend hab f s := rfl noncomputable def applyCoefficient (A : Coefficient a b E) (u : Curve a b E) : Curve a b E := ⟨fun t => A t (u t), A.continuous.clm_apply u.continuous⟩ omit [CompleteSpace E] in theorem norm_applyCoefficient_le (A : Coefficient a b E) (u : Curve a b E) : ‖applyCoefficient A u‖ ≤ ‖A‖ * ‖u‖ := by apply (ContinuousMap.norm_le (applyCoefficient A u) (mul_nonneg (norm_nonneg A) (norm_nonneg u))).mpr intro t exact ((A t).le_opNorm (u t)).trans (mul_le_mul (A.norm_coe_le_norm t) (u.norm_coe_le_norm t) (norm_nonneg _) (norm_nonneg _)) def coefficientLinear : Coefficient a b E →ₗ[ℝ] Curve a b E →ₗ[ℝ] Curve a b E where toFun A := { toFun := applyCoefficient A map_add' := by intro u w; ext t; exact map_add (A t) _ _ map_smul' := by intro c u; ext t; exact map_smul (A t) _ _ } map_add' := by intro A B; ext u t; rfl map_smul' := by intro c A; ext u t; rfl def coefficientAction : Coefficient a b E →L[ℝ] Curve a b E →L[ℝ] Curve a b E := (coefficientLinear (a := a) (b := b) (E := E)).mkContinuous₂ (𝕜 := ℝ) (𝕜₂ := ℝ) (𝕜₃ := ℝ) 1 (fun (A : Coefficient a b E) (u : Curve a b E) => by change ‖applyCoefficient A u‖ ≤ 1 * ‖A‖ * ‖u‖ simpa only [one_mul] using norm_applyCoefficient_le (E := E) A u) def volterra : Coefficient a b E →L[ℝ] Curve a b E →L[ℝ] Curve a b E := ((ContinuousLinearMap.compL ℝ (Curve a b E) (Curve a b E) (Curve a b E)) (integrator hab)).comp (coefficientAction (E := E)) def homogeneousSystem (A : Coefficient a b E) : TangentODE.IntervalSystem E := { left := a right := b ordered := hab initial := 0 field := fun t x => extend hab A t x lip := ‖A‖₊ lipschitz := fun t _ => (extend hab A t).lipschitzWith.weaken (A.norm_coe_le_norm _) continuous := by have he : Continuous (fun t : Icc a b => extend hab A t) := (continuous_extend hab A).comp continuous_subtype_val exact (he.comp continuous_fst).clm_apply continuous_snd } theorem volterra_eq_next (A : Coefficient a b E) : (volterra (E := E) hab A : Curve a b E → Curve a b E) = (homogeneousSystem hab A).next := by funext u ext t change (∫ s in a..(t : ℝ), extend hab A s (extend hab u s)) = 0 + ∫ s in a..(t : ℝ), extend hab A (projIcc a b hab s) (u (projIcc a b hab s)) simp only [zero_add, extend, projIcc_val] theorem volterra_contracting_iterate (A : Coefficient a b E) : ∃ (N : ℕ) (K : ℝ≥0), ContractingWith K (volterra (E := E) hab A)^[N] := by rw [volterra_eq_next] exact (homogeneousSystem hab A).exists_contracting_iterate section AbstractInverse variable {X : Type*} [NormedAddCommGroup X] [NormedSpace ℝ X] [CompleteSpace X] omit [CompleteSpace X] in theorem affine_iterate_sub (L : X →L[ℝ] X) (g : X) (n : ℕ) (u w : X) : (fun x => g + L x)^[n] u - (fun x => g + L x)^[n] w = L^[n] u - L^[n] w := by induction n with | zero => rfl | succ n ih => simp only [iterate_succ_apply', add_sub_add_left_eq_sub] rw [← L.map_sub, ih, L.map_sub] theorem id_sub_isInvertible (L : X →L[ℝ] X) (hL : ∃ (N : ℕ) (K : ℝ≥0), ContractingWith K L^[N]) : (ContinuousLinearMap.id ℝ X - L).IsInvertible := by obtain ⟨N, K, hK⟩ := hL have htrans (g : X) : ContractingWith K (fun x => g + L x)^[N] := by refine ⟨hK.1, LipschitzWith.of_dist_le_mul fun u w => ?_⟩ simpa only [dist_eq_norm, affine_iterate_sub] using hK.2.dist_le_mul u w have hsurj : Surjective (ContinuousLinearMap.id ℝ X - L) := by intro g let x := (htrans g).fixedPoint (fun x => g + L x)^[N] have hf : g + L x = x := (htrans g).isFixedPt_fixedPoint_iterate.eq refine ⟨x, ?_⟩ change x - L x = g exact sub_eq_iff_eq_add.mpr hf.symm have hinj : Injective (ContinuousLinearMap.id ℝ X - L) := by intro u w huv let g := (ContinuousLinearMap.id ℝ X - L) u have hu : IsFixedPt (fun x => g + L x) u := by change (u - L u) + L u = u exact sub_add_cancel _ _ have hw : IsFixedPt (fun x => g + L x) w := by change ((ContinuousLinearMap.id ℝ X - L) u) + L w = w rw [huv] exact sub_add_cancel _ _ exact (htrans g).fixedPoint_unique' (hu.iterate N) (hw.iterate N) exact ⟨ContinuousLinearEquiv.ofBijective _ (LinearMap.ker_eq_bot.mpr hinj) (LinearMap.range_eq_top.mpr hsurj), ContinuousLinearEquiv.coe_ofBijective _ _ _⟩ end AbstractInverse theorem contDiff_inverse_family {X Q : Type*} [NormedAddCommGroup X] [NormedSpace ℝ X] [CompleteSpace X] [NormedAddCommGroup Q] [NormedSpace ℝ Q] (L : Q → X →L[ℝ] X) (hL : ContDiff ℝ ∞ L) (hInv : ∀ q, (L q).IsInvertible) : ContDiff ℝ ∞ (fun q => (L q).inverse) := by rw [contDiff_iff_contDiffAt] intro q exact (hInv q).contDiffAt_map_inverse.comp q hL.contDiffAt def equationOperator (A : Coefficient a b E) : Curve a b E →L[ℝ] Curve a b E := ContinuousLinearMap.id ℝ (Curve a b E) - volterra (E := E) hab A theorem equationOperator_isInvertible (A : Coefficient a b E) : (equationOperator hab A).IsInvertible := id_sub_isInvertible _ (volterra_contracting_iterate hab A) /-- Resolvent of the actual Volterra integral equation on the full finite interval. -/ def resolvent (A : Coefficient a b E) : Curve a b E →L[ℝ] Curve a b E := (equationOperator hab A).inverse theorem contDiff_resolvent : ContDiff ℝ ∞ (resolvent (E := E) hab) := by change ContDiff ℝ ∞ (fun A : Coefficient a b E => (equationOperator hab A).inverse) apply contDiff_inverse_family (equationOperator (E := E) hab) · unfold equationOperator apply ContDiff.sub contDiff_const exact ContinuousLinearMap.contDiff (𝕜 := ℝ) (n := ∞) (E := Coefficient a b E) (F := Curve a b E →L[ℝ] Curve a b E) (volterra (E := E) hab) · exact equationOperator_isInvertible hab def constantCurve : E →L[ℝ] Curve a b E := LinearMap.mkContinuous { toFun := ContinuousMap.const (Icc a b) map_add' := by intros; rfl map_smul' := by intros; rfl } 1 (fun x => by change ‖ContinuousMap.const (Icc a b) x‖ ≤ 1 * ‖x‖ simpa only [one_mul] using (ContinuousMap.norm_le (ContinuousMap.const (Icc a b) x) (norm_nonneg x)).mpr (fun _ => le_rfl)) def source (x₀ : E) (f : Curve a b E) : Curve a b E := constantCurve x₀ + integrator hab f /-- The constructed solution as a continuous path, not an assumed solution family. -/ def solution (A : Coefficient a b E) (x₀ : E) (f : Curve a b E) : Curve a b E := resolvent hab A (source hab x₀ f) theorem resolvent_equation (A : Coefficient a b E) (g : Curve a b E) : equationOperator hab A (resolvent hab A g) = g := by exact ((equationOperator_isInvertible hab A).inverse_apply_eq.mp rfl).symm theorem solution_integralEquation (A : Coefficient a b E) (x₀ : E) (f : Curve a b E) : solution hab A x₀ f = constantCurve x₀ + integrator hab (applyCoefficient A (solution hab A x₀ f) + f) := by have h := resolvent_equation hab A (source hab x₀ f) change solution hab A x₀ f - volterra (E := E) hab A (solution hab A x₀ f) = source hab x₀ f at h rw [map_add] change solution hab A x₀ f = constantCurve x₀ + (volterra (E := E) hab A (solution hab A x₀ f) + integrator hab f) rw [sub_eq_iff_eq_add] at h calc _ = source hab x₀ f + volterra (E := E) hab A (solution hab A x₀ f) := h _ = _ := by unfold source; abel theorem solution_initial (A : Coefficient a b E) (x₀ : E) (f : Curve a b E) : solution hab A x₀ f ⟨a, le_rfl, hab⟩ = x₀ := by have h := congrArg (fun u : Curve a b E => u ⟨a, le_rfl, hab⟩) (solution_integralEquation hab A x₀ f) dsimp [constantCurve] at h simp only [integrator_apply, intervalIntegral.integral_same, add_zero] at h exact h def solutionExtension (A : Coefficient a b E) (x₀ : E) (f : Curve a b E) (t : ℝ) : E := x₀ + ∫ s in a..t, extend hab (applyCoefficient A (solution hab A x₀ f) + f) s theorem solutionExtension_coe (A : Coefficient a b E) (x₀ : E) (f : Curve a b E) (t : Icc a b) : solutionExtension hab A x₀ f t = solution hab A x₀ f t := by have h := congrArg (fun u : Curve a b E => u t) (solution_integralEquation hab A x₀ f) exact h.symm /-- The constructed path has a differentiable extension satisfying the actual ODE at every point of the prescribed interval. -/ theorem solutionExtension_hasDerivAt (A : Coefficient a b E) (x₀ : E) (f : Curve a b E) (t : Icc a b) : HasDerivAt (solutionExtension hab A x₀ f) (A t (solutionExtension hab A x₀ f t) + f t) t := by let g := applyCoefficient A (solution hab A x₀ f) + f have hd := (integral_hasDerivAt_right ((continuous_extend hab g).intervalIntegrable a t) ((continuous_extend hab g).stronglyMeasurableAtFilter _ _) (continuous_extend hab g).continuousAt).const_add x₀ rw [extend_coe] at hd rw [solutionExtension_coe] unfold solutionExtension simpa only [g, ContinuousMap.add_apply, applyCoefficient, ContinuousMap.coe_mk] using hd theorem solution_hasDerivWithinAt (A : Coefficient a b E) (x₀ : E) (f : Curve a b E) (t : Icc a b) : HasDerivWithinAt (extend hab (solution hab A x₀ f)) (A t (solution hab A x₀ f t) + f t) (Icc a b) t := by have hd := (solutionExtension_hasDerivAt hab A x₀ f t).hasDerivWithinAt (s := Icc a b) rw [solutionExtension_coe] at hd apply hd.congr_of_eventuallyEq_of_mem _ t.2 filter_upwards [self_mem_nhdsWithin] with s hs have h := solutionExtension_coe hab A x₀ f ⟨s, hs⟩ simpa only [extend, projIcc_of_mem hab hs] using h.symm variable {P : Type*} [NormedAddCommGroup P] [NormedSpace ℝ P] theorem contDiffOn_solution_family {s : Set P} (A : P → Coefficient a b E) (x₀ : P → E) (f : P → Curve a b E) (hA : ContDiffOn ℝ ∞ A s) (hx₀ : ContDiffOn ℝ ∞ x₀ s) (hf : ContDiffOn ℝ ∞ f s) : ContDiffOn ℝ ∞ (fun p => solution hab (A p) (x₀ p) (f p)) s := by change ContDiffOn ℝ ∞ (fun p => resolvent hab (A p) (constantCurve (a := a) (b := b) (x₀ p) + integrator hab (f p))) s exact ((contDiff_resolvent hab).comp_contDiffOn hA).clm_apply (((constantCurve (E := E) (a := a) (b := b)).contDiff.comp_contDiffOn hx₀).add ((integrator (E := E) hab).contDiff.comp_contDiffOn hf)) end end NavierStokes.ParametricODE