Navier–Stokes: the Lean blow-up proof, cleaned up together
OpenAI's 2026 Lean proofs of blowup for forced Navier–Stokes and Euler, rerun by others, not refereed, no ruling from Clay; cleaned up together: more readable, faster to build

refactor(NavierStokes/Generic): fold 12 small modules into the files that import them #667
Open
+0 −62 NavierStokes/GenericAngularRecovery.lean deleted
| @@ -1,62 +0,0 @@ | ||
| 1 | -import NavierStokes.GenericSolenoidalRealization | |
| 2 | - | |
| 3 | -noncomputable section | |
| 4 | - | |
| 5 | -namespace NavierStokes.GenericSolenoidalRealization | |
| 6 | - | |
| 7 | -open Set Filter ProblemStatement AxisymmetricFields DirectAngularDiagonal | |
| 8 | -open scoped Topology ContDiff BigOperators | |
| 9 | - | |
| 10 | -private def radialFactor (w : SpaceTime) (p : ProfilePoint) : ℝ := | |
| 11 | - Real.sqrt (p.2.1 / radialEnergy w.2) | |
| 12 | - | |
| 13 | -/-- A local section of the cylindrical coordinate map through the given | |
| 14 | -off-axis Cartesian point, retaining its angular direction. -/ | |
| 15 | -private def radialSection (w : SpaceTime) (p : ProfilePoint) : SpaceTime := | |
| 16 | - (p.1, AxisymmetricResidual.pack (radialFactor w p * w.2 0) | |
| 17 | - (radialFactor w p * w.2 1) p.2.2) | |
| 18 | - | |
| 19 | -private theorem radialFactor_at {w : SpaceTime} (hw : 0 < radialEnergy w.2) : | |
| 20 | - radialFactor w (profilePoint w.1 w.2) = 1 := by | |
| 21 | - simp only [radialFactor, profilePoint, div_self hw.ne', Real.sqrt_one] | |
| 22 | - | |
| 23 | -private theorem radialSection_at {w : SpaceTime} (hw : 0 < radialEnergy w.2) : | |
| 24 | - radialSection w (profilePoint w.1 w.2) = w := by | |
| 25 | - refine Prod.ext ?_ ?_ | |
| 26 | - · rfl | |
| 27 | - ext i | |
| 28 | - fin_cases i <;> simp [radialSection, radialFactor, profilePoint, div_self hw.ne'] | |
| 29 | - | |
| 30 | -private theorem profile_radialSection {w : SpaceTime} (hw : 0 < radialEnergy w.2) | |
| 31 | - {p : ProfilePoint} (hp : 0 < p.2.1) : | |
| 32 | - profilePoint (radialSection w p).1 (radialSection w p).2 = p := by | |
| 33 | - have hs : radialFactor w p ^ 2 = p.2.1 / radialEnergy w.2 := | |
| 34 | - Real.sq_sqrt (div_pos hp hw).le | |
| 35 | - have he : radialEnergy (radialSection w p).2 = p.2.1 := by | |
| 36 | - simp only [radialEnergy, radialSection, AxisymmetricResidual.pack_zero, AxisymmetricResidual.pack_one] | |
| 37 | - calc | |
| 38 | - _ = radialFactor w p ^ 2 * radialEnergy w.2 := by unfold radialEnergy; ring | |
| 39 | - _ = p.2.1 := by rw [hs, div_mul_cancel₀ _ hw.ne'] | |
| 40 | - refine Prod.ext ?_ ?_ | |
| 41 | - · rfl | |
| 42 | - exact Prod.ext he (AxisymmetricResidual.pack_two _ _ _) | |
| 43 | - | |
| 44 | -private theorem radialFactor_smoothAt {w : SpaceTime} (hw : 0 < radialEnergy w.2) : | |
| 45 | - ContDiffAt ℝ ∞ (radialFactor w) (profilePoint w.1 w.2) := by | |
| 46 | - apply (contDiffAt_snd.fst.div_const (radialEnergy w.2)).sqrt | |
| 47 | - change (profilePoint w.1 w.2).2.1 / radialEnergy w.2 ≠ 0 | |
| 48 | - norm_num [profilePoint, div_self hw.ne'] | |
| 49 | - | |
| 50 | -private theorem radialSection_smoothAt {w : SpaceTime} (hw : 0 < radialEnergy w.2) : | |
| 51 | - ContDiffAt ℝ ∞ (radialSection w) (profilePoint w.1 w.2) := by | |
| 52 | - have hs := radialFactor_smoothAt hw | |
| 53 | - have hv : ContDiffAt ℝ ∞ (fun p : ProfilePoint => AxisymmetricResidual.pack | |
| 54 | - (radialFactor w p * w.2 0) (radialFactor w p * w.2 1) p.2.2) | |
| 55 | - (profilePoint w.1 w.2) := by | |
| 56 | - unfold AxisymmetricResidual.pack | |
| 57 | - exact (((hs.mul contDiffAt_const).smul contDiffAt_const).add | |
| 58 | - ((hs.mul contDiffAt_const).smul contDiffAt_const)).add | |
| 59 | - (contDiffAt_snd.snd.smul contDiffAt_const) | |
| 60 | - exact contDiffAt_fst.prodMk hv | |
| 61 | - | |
| 62 | -end NavierStokes.GenericSolenoidalRealization | |
+0 −26 NavierStokes/GenericDiagonalSchedule.lean deleted
| @@ -1,26 +0,0 @@ | ||
| 1 | -import NavierStokes.CutStageEstimates | |
| 2 | - | |
| 3 | -/-! | |
| 4 | -# A common diagonal schedule with arbitrary additional finite tests | |
| 5 | - | |
| 6 | -The same sequence of cutoff scales enforces all field jet estimates and any | |
| 7 | -prescribed finite family of positive-power logarithmic tests at each stage. | |
| 8 | -The bounds apply throughout the reciprocal interval, including its endpoint. | |
| 9 | --/ | |
| 10 | - | |
| 11 | -noncomputable section | |
| 12 | - | |
| 13 | -namespace NavierStokes.GenericDiagonalSchedule | |
| 14 | - | |
| 15 | -open Set Function Filter | |
| 16 | -open scoped Topology ContDiff BigOperators | |
| 17 | - | |
| 18 | -section Fields | |
| 19 | - | |
| 20 | -variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] | |
| 21 | -variable {ι : Type*} [Fintype ι] {W : ι → Type*} | |
| 22 | - [∀ i, NormedAddCommGroup (W i)] [∀ i, NormedSpace ℝ (W i)] | |
| 23 | - | |
| 24 | -end Fields | |
| 25 | - | |
| 26 | -end NavierStokes.GenericDiagonalSchedule | |
+0 −57 NavierStokes/GenericDifferentialPolynomial.lean deleted
| @@ -1,57 +0,0 @@ | ||
| 1 | -import NavierStokes.GenericJetRateAlgebra | |
| 2 | - | |
| 3 | -noncomputable section | |
| 4 | - | |
| 5 | -namespace NavierStokes.GenericDifferentialPolynomial | |
| 6 | - | |
| 7 | -open Set Filter DiagonalResidual | |
| 8 | -open scoped Topology ContDiff | |
| 9 | - | |
| 10 | -variable {D : Type*} [NormedAddCommGroup D] [NormedSpace ℝ D] | |
| 11 | - | |
| 12 | -/-- Quantitative approximation data. Constants may depend on the stage, while | |
| 13 | -the power losses and derivative thresholds are fixed functions of the jet order. -/ | |
| 14 | -structure ApproximationRates (l : Filter D) (q : D → ℝ) (gain : ℕ → ℝ) | |
| 15 | - (f : D → ℝ) (stage : ℕ → D → ℝ) where | |
| 16 | - growthLoss : ℕ → ℝ | |
| 17 | - tailLoss : ℕ → ℝ | |
| 18 | - threshold : ℕ → ℕ | |
| 19 | - stage_growth : ∀ J m, JetRate l q (stage J) m (-growthLoss m) | |
| 20 | - tail_rate : ∀ m J, threshold m ≤ J → | |
| 21 | - JetRate l q (fun x => f x - stage J x) m (gain J - tailLoss m) | |
| 22 | - | |
| 23 | -private def maxThreshold (M : ℕ → ℕ) (m : ℕ) : ℕ := | |
| 24 | - (Finset.range (m + 1)).sup M | |
| 25 | - | |
| 26 | -private theorem le_maxThreshold (M : ℕ → ℕ) {k m : ℕ} (hk : k ≤ m) : | |
| 27 | - M k ≤ maxThreshold M m := | |
| 28 | - Finset.le_sup (f := M) (Finset.mem_range.mpr (Nat.lt_succ_of_le hk)) | |
| 29 | - | |
| 30 | -variable {l : Filter D} {q : D → ℝ} {gain : ℕ → ℝ} {U : Set D} | |
| 31 | -variable {f g : D → ℝ} {fs gs : ℕ → D → ℝ} | |
| 32 | - | |
| 33 | -/-- A finite differential expression in scalar components with fixed variable | |
| 34 | -coefficients. Products, sums, and arbitrary fixed directional derivatives are | |
| 35 | -allowed at every node; consequently the order and polynomial degree are finite. -/ | |
| 36 | -inductive Expression (D ι κ : Type*) where | |
| 37 | - | input : ι → Expression D ι κ | |
| 38 | - | coeff : κ → Expression D ι κ | |
| 39 | - | add : Expression D ι κ → Expression D ι κ → Expression D ι κ | |
| 40 | - | mul : Expression D ι κ → Expression D ι κ → Expression D ι κ | |
| 41 | - | directional : D → Expression D ι κ → Expression D ι κ | |
| 42 | - | |
| 43 | -namespace Expression | |
| 44 | - | |
| 45 | -variable {ι κ : Type*} | |
| 46 | - | |
| 47 | -/-- Evaluation uses actual Fréchet derivatives, including at derivative nodes. -/ | |
| 48 | -def eval (c : κ → D → ℝ) (u : ι → D → ℝ) : Expression D ι κ → D → ℝ | |
| 49 | - | .input i => u i | |
| 50 | - | .coeff i => c i | |
| 51 | - | .add a b => fun x => eval c u a x + eval c u b x | |
| 52 | - | .mul a b => fun x => eval c u a x * eval c u b x | |
| 53 | - | .directional v a => fun x => fderiv ℝ (eval c u a) x v | |
| 54 | - | |
| 55 | -end Expression | |
| 56 | - | |
| 57 | -end NavierStokes.GenericDifferentialPolynomial | |
+0 −38 NavierStokes/GenericFactorSupport.lean deleted
| @@ -1,38 +0,0 @@ | ||
| 1 | -import NavierStokes.GenericSupportedPolynomial | |
| 2 | - | |
| 3 | -noncomputable section | |
| 4 | - | |
| 5 | -namespace NavierStokes.GenericDifferentialPolynomial | |
| 6 | - | |
| 7 | -open Set Filter | |
| 8 | -open scoped Topology ContDiff BigOperators | |
| 9 | - | |
| 10 | -variable {D ι : Type*} [NormedAddCommGroup D] [NormedSpace ℝ D] | |
| 11 | - | |
| 12 | -/-- A single Cartesian field factor. Coordinate vectors give the usual | |
| 13 | -multi-index derivatives; arbitrary fixed directions are also permitted. -/ | |
| 14 | -inductive FieldFactor (D ι : Type*) where | |
| 15 | - | input : ι → FieldFactor D ι | |
| 16 | - | directional : D → FieldFactor D ι → FieldFactor D ι | |
| 17 | - | |
| 18 | -def FieldFactor.expression : FieldFactor D ι → Expression D ι Empty | |
| 19 | - | .input i => .input i | |
| 20 | - | .directional v f => .directional v f.expression | |
| 21 | - | |
| 22 | -def FieldFactor.eval (f : FieldFactor D ι) (u : ι → D → ℝ) : D → ℝ := | |
| 23 | - f.expression.eval (fun k => Empty.elim k) u | |
| 24 | - | |
| 25 | -/-- Each leaf records the support of one differentiated field factor in the | |
| 26 | -base and every increment. Multiplication constructs arbitrary positive-degree | |
| 27 | -monomials without requiring undifferentiated components to share the support. -/ | |
| 28 | -inductive FactorSupportAt (base : ι → D → ℝ) (inc : ℕ → ι → D → ℝ) (x : D) : | |
| 29 | - Expression D ι Empty → Prop where | |
| 30 | - | factor (f : FieldFactor D ι) | |
| 31 | - (base_zero : f.eval base =ᶠ[𝓝 x] (fun _ => 0)) | |
| 32 | - (increment_zero : ∀ j, f.eval (inc j) =ᶠ[𝓝 x] (fun _ => 0)) : | |
| 33 | - FactorSupportAt base inc x f.expression | |
| 34 | - | mul {e f : Expression D ι Empty} : | |
| 35 | - FactorSupportAt base inc x e → FactorSupportAt base inc x f → | |
| 36 | - FactorSupportAt base inc x (.mul e f) | |
| 37 | - | |
| 38 | -end NavierStokes.GenericDifferentialPolynomial | |
+0 −16 NavierStokes/GenericJetRateAlgebra.lean deleted
| @@ -1,16 +0,0 @@ | ||
| 1 | -import NavierStokes.DiagonalResidual | |
| 2 | - | |
| 3 | -noncomputable section | |
| 4 | - | |
| 5 | -namespace NavierStokes.GenericDifferentialPolynomial | |
| 6 | - | |
| 7 | -open Set Filter DiagonalResidual | |
| 8 | -open scoped Topology ContDiff | |
| 9 | - | |
| 10 | -variable {D : Type*} [NormedAddCommGroup D] [NormedSpace ℝ D] | |
| 11 | -private local instance : NormedAddCommGroup ((D →L[ℝ] ℝ) →L[ℝ] ℝ) := inferInstance | |
| 12 | -private local instance : NormedSpace ℝ ((D →L[ℝ] ℝ) →L[ℝ] ℝ) := inferInstance | |
| 13 | - | |
| 14 | -variable {l : Filter D} {q : D → ℝ} {U : Set D} {f g : D → ℝ} | |
| 15 | - | |
| 16 | -end NavierStokes.GenericDifferentialPolynomial | |
+0 −52 NavierStokes/GenericRealization.lean deleted
| @@ -1,52 +0,0 @@ | ||
| 1 | -import NavierStokes.GenericDiagonalSchedule | |
| 2 | -import NavierStokes.GenericSupportedPolynomial | |
| 3 | - | |
| 4 | -/-! | |
| 5 | -# A single smooth diagonal realization with finite differential-polynomial tests | |
| 6 | - | |
| 7 | -All estimates are on the actual cutoff series. The same schedule supplies every | |
| 8 | -jet order and an arbitrary finite set of extra tests at each stage. Residual | |
| 9 | -transfer permits independently varying residual gains and coefficient growth | |
| 10 | -only on the common support of each nonconstant monomial. | |
| 11 | --/ | |
| 12 | - | |
| 13 | -noncomputable section | |
| 14 | - | |
| 15 | -namespace NavierStokes.GenericRealization | |
| 16 | - | |
| 17 | -open Set Filter DiagonalResidual GenericRealizationBounds GenericDifferentialPolynomial | |
| 18 | -open scoped Topology ContDiff BigOperators | |
| 19 | - | |
| 20 | -variable {D : Type*} | |
| 21 | - | |
| 22 | -/-- Approach the singular scale uniformly over the full prescribed domain. -/ | |
| 23 | -def scaleApproach (U : Set D) (q : D → ℝ) : Filter D := | |
| 24 | - comap q (𝓝[>] (0 : ℝ)) ⊓ 𝓟 U | |
| 25 | - | |
| 26 | -variable [NormedAddCommGroup D] [NormedSpace ℝ D] | |
| 27 | - | |
| 28 | -variable {ι : Type*} | |
| 29 | - | |
| 30 | -/-- Properties derived for one selected schedule, rather than new schedules | |
| 31 | -chosen after the derivative order or the polynomial has been supplied. -/ | |
| 32 | -structure Properties (U : Set D) (q : D → ℝ) (base : ι → D → ℝ) | |
| 33 | - (A : ι → ℕ → D → ℝ) (g L : ℕ → ℝ) (a : ℕ → ℕ) : Prop where | |
| 34 | - positive : ∀ j, 0 < a j | |
| 35 | - doubling : ∀ j, 2 * a j ≤ a (j + 1) | |
| 36 | - strictMono : StrictMono a | |
| 37 | - tends : Tendsto (fun j => (a j : ℝ)) atTop atTop | |
| 38 | - locallyFinite : ∀ i, LocallyFinite (fun j => | |
| 39 | - Function.support (fun x : U => SolenoidalDiagonal.cutStage (fun j => (a j : ℝ)) q | |
| 40 | - (CutStageEstimates.positiveStages (A i)) j x)) | |
| 41 | - smooth : ∀ i, ContDiffOn ℝ ∞ (realized (fun j => (a j : ℝ)) q (base i) (A i)) U | |
| 42 | - approximation : ∀ i, Nonempty (ApproximationRates (scaleApproach U q) q (fun J => g (J + 1) / 2) | |
| 43 | - (realized (fun j => (a j : ℝ)) q (base i) (A i)) (stage (base i) (A i))) | |
| 44 | - exact_tail : ∀ i x, x ∈ U → ∀ J m, m ≤ J + 3 → q x < 1 / (2 * (a J : ℝ)) → | |
| 45 | - ‖iteratedFDeriv ℝ m (fun y => realized (fun j => (a j : ℝ)) q (base i) (A i) y - | |
| 46 | - stage (base i) (A i) J y) x‖ ≤ | |
| 47 | - (1 / 2 : ℝ) ^ J * q x ^ (g (J + 1) / 2 - CutStageEstimates.cutLoss L m) | |
| 48 | - outer_zero : ∀ i x, ContinuousAt q x → 1 / (a 0 : ℝ) < q x → | |
| 49 | - SolenoidalDiagonal.potentialSum (fun j => (a j : ℝ)) q | |
| 50 | - (CutStageEstimates.positiveStages (A i)) =ᶠ[𝓝 x] (fun _ => 0) | |
| 51 | - | |
| 52 | -end NavierStokes.GenericRealization | |
+0 −31 NavierStokes/GenericRealizationBounds.lean deleted
| @@ -1,31 +0,0 @@ | ||
| 1 | -import NavierStokes.MixedFiniteBackground | |
| 2 | - | |
| 3 | -/-! | |
| 4 | -# Quantitative bounds for general diagonal realizations | |
| 5 | - | |
| 6 | -The base is retained without a cutoff. The positive corrections are actual | |
| 7 | -locally finite cutoff sums. Logarithmic losses are absorbed at each fixed | |
| 8 | -stage, while the resulting power loss is independent of the stage. | |
| 9 | --/ | |
| 10 | - | |
| 11 | -noncomputable section | |
| 12 | - | |
| 13 | -namespace NavierStokes.GenericRealizationBounds | |
| 14 | - | |
| 15 | -open Set Filter DiagonalResidual | |
| 16 | -open scoped Topology ContDiff BigOperators | |
| 17 | - | |
| 18 | -variable {E V : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] | |
| 19 | - [NormedAddCommGroup V] [NormedSpace ℝ V] | |
| 20 | - | |
| 21 | -/-- The uncut base plus the actual positive cutoff series. -/ | |
| 22 | -def realized (a : ℕ → ℝ) (q : E → ℝ) (base : E → V) (A : ℕ → E → V) : E → V := | |
| 23 | - fun x => base x + SolenoidalDiagonal.potentialSum a q | |
| 24 | - (CutStageEstimates.positiveStages A) x | |
| 25 | - | |
| 26 | -/-- The corresponding finite approximation, including exactly stages `1,…,J`. -/ | |
| 27 | -def stage (base : E → V) (A : ℕ → E → V) (J : ℕ) : E → V := | |
| 28 | - fun x => base x + DiagonalJetBounds.uncutPrefix | |
| 29 | - (CutStageEstimates.positiveStages A) (J + 1) x | |
| 30 | - | |
| 31 | -end NavierStokes.GenericRealizationBounds | |
+0 −23 NavierStokes/GenericSolenoidalRealization.lean deleted
| @@ -1,23 +0,0 @@ | ||
| 1 | -import NavierStokes.GenericRealization | |
| 2 | -import NavierStokes.DirectAngularDiagonal | |
| 3 | -import NavierStokes.MixedPeriodicAssembly | |
| 4 | - | |
| 5 | -noncomputable section | |
| 6 | - | |
| 7 | -namespace NavierStokes.GenericSolenoidalRealization | |
| 8 | - | |
| 9 | -open Set Filter ProblemStatement | |
| 10 | -open scoped Topology ContDiff BigOperators | |
| 11 | - | |
| 12 | -/-- Literal curl-after-cutoff realization, with a separate uncut base. -/ | |
| 13 | -def velocity (a : ℕ → ℝ) (q : SpaceTime → ℝ) (u0 : VelocityField) | |
| 14 | - (A B : ℕ → VelocityField) : VelocityField := | |
| 15 | - fun w => u0 w + SolenoidalDiagonal.velocitySum a q A w + | |
| 16 | - SolenoidalDiagonal.potentialSum a q B w | |
| 17 | - | |
| 18 | -/-- The manuscript's sum starts at stage one; the base is left uncut. -/ | |
| 19 | -def positiveVelocity (a : ℕ → ℝ) (q : SpaceTime → ℝ) (u0 : VelocityField) | |
| 20 | - (A B : ℕ → VelocityField) : VelocityField := | |
| 21 | - velocity a q u0 (CutStageEstimates.positiveStages A) (CutStageEstimates.positiveStages B) | |
| 22 | - | |
| 23 | -end NavierStokes.GenericSolenoidalRealization | |
+390 −2 NavierStokes/GenericSummationRealization.lean View file
| @@ -1,5 +1,393 @@ | ||
| 1 | -import NavierStokes.GenericTupleSupport | |
| 2 | -import NavierStokes.GenericAngularRecovery | |
| 1 | +import NavierStokes.CutStageEstimates | |
| 2 | +import NavierStokes.GenericSupportedPolynomial | |
| 3 | +import NavierStokes.DirectAngularDiagonal | |
| 4 | +import NavierStokes.MixedPeriodicAssembly | |
| 5 | + | |
| 6 | +/-! ## From `NavierStokes/GenericDiagonalSchedule.lean` | |
| 7 | + | |
| 8 | +The text of `NavierStokes/GenericDiagonalSchedule.lean`, folded into this file, which was its only importer. -/ | |
| 9 | + | |
| 10 | +section | |
| 11 | + | |
| 12 | +/-! | |
| 13 | +# A common diagonal schedule with arbitrary additional finite tests | |
| 14 | + | |
| 15 | +The same sequence of cutoff scales enforces all field jet estimates and any | |
| 16 | +prescribed finite family of positive-power logarithmic tests at each stage. | |
| 17 | +The bounds apply throughout the reciprocal interval, including its endpoint. | |
| 18 | +-/ | |
| 19 | + | |
| 20 | +noncomputable section | |
| 21 | + | |
| 22 | +namespace NavierStokes.GenericDiagonalSchedule | |
| 23 | + | |
| 24 | +open Set Function Filter | |
| 25 | +open scoped Topology ContDiff BigOperators | |
| 26 | + | |
| 27 | +section Fields | |
| 28 | + | |
| 29 | +variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] | |
| 30 | +variable {ι : Type*} [Fintype ι] {W : ι → Type*} | |
| 31 | + [∀ i, NormedAddCommGroup (W i)] [∀ i, NormedSpace ℝ (W i)] | |
| 32 | + | |
| 33 | +end Fields | |
| 34 | + | |
| 35 | +end NavierStokes.GenericDiagonalSchedule | |
| 36 | +end | |
| 37 | + | |
| 38 | +end | |
| 39 | + | |
| 40 | +/-! ## From `NavierStokes/GenericRealization.lean` | |
| 41 | + | |
| 42 | +The text of `NavierStokes/GenericRealization.lean`, folded into this file, which was its only importer. -/ | |
| 43 | + | |
| 44 | +section | |
| 45 | + | |
| 46 | +/-! | |
| 47 | +# A single smooth diagonal realization with finite differential-polynomial tests | |
| 48 | + | |
| 49 | +All estimates are on the actual cutoff series. The same schedule supplies every | |
| 50 | +jet order and an arbitrary finite set of extra tests at each stage. Residual | |
| 51 | +transfer permits independently varying residual gains and coefficient growth | |
| 52 | +only on the common support of each nonconstant monomial. | |
| 53 | +-/ | |
| 54 | + | |
| 55 | +noncomputable section | |
| 56 | + | |
| 57 | +namespace NavierStokes.GenericRealization | |
| 58 | + | |
| 59 | +open Set Filter DiagonalResidual GenericRealizationBounds GenericDifferentialPolynomial | |
| 60 | +open scoped Topology ContDiff BigOperators | |
| 61 | + | |
| 62 | +variable {D : Type*} | |
| 63 | + | |
| 64 | +/-- Approach the singular scale uniformly over the full prescribed domain. -/ | |
| 65 | +def scaleApproach (U : Set D) (q : D → ℝ) : Filter D := | |
| 66 | + comap q (𝓝[>] (0 : ℝ)) ⊓ 𝓟 U | |
| 67 | + | |
| 68 | +variable [NormedAddCommGroup D] [NormedSpace ℝ D] | |
| 69 | + | |
| 70 | +variable {ι : Type*} | |
| 71 | + | |
| 72 | +/-- Properties derived for one selected schedule, rather than new schedules | |
| 73 | +chosen after the derivative order or the polynomial has been supplied. -/ | |
| 74 | +structure Properties (U : Set D) (q : D → ℝ) (base : ι → D → ℝ) | |
| 75 | + (A : ι → ℕ → D → ℝ) (g L : ℕ → ℝ) (a : ℕ → ℕ) : Prop where | |
| 76 | + positive : ∀ j, 0 < a j | |
| 77 | + doubling : ∀ j, 2 * a j ≤ a (j + 1) | |
| 78 | + strictMono : StrictMono a | |
| 79 | + tends : Tendsto (fun j => (a j : ℝ)) atTop atTop | |
| 80 | + locallyFinite : ∀ i, LocallyFinite (fun j => | |
| 81 | + Function.support (fun x : U => SolenoidalDiagonal.cutStage (fun j => (a j : ℝ)) q | |
| 82 | + (CutStageEstimates.positiveStages (A i)) j x)) | |
| 83 | + smooth : ∀ i, ContDiffOn ℝ ∞ (realized (fun j => (a j : ℝ)) q (base i) (A i)) U | |
| 84 | + approximation : ∀ i, Nonempty (ApproximationRates (scaleApproach U q) q (fun J => g (J + 1) / 2) | |
| 85 | + (realized (fun j => (a j : ℝ)) q (base i) (A i)) (stage (base i) (A i))) | |
| 86 | + exact_tail : ∀ i x, x ∈ U → ∀ J m, m ≤ J + 3 → q x < 1 / (2 * (a J : ℝ)) → | |
| 87 | + ‖iteratedFDeriv ℝ m (fun y => realized (fun j => (a j : ℝ)) q (base i) (A i) y - | |
| 88 | + stage (base i) (A i) J y) x‖ ≤ | |
| 89 | + (1 / 2 : ℝ) ^ J * q x ^ (g (J + 1) / 2 - CutStageEstimates.cutLoss L m) | |
| 90 | + outer_zero : ∀ i x, ContinuousAt q x → 1 / (a 0 : ℝ) < q x → | |
| 91 | + SolenoidalDiagonal.potentialSum (fun j => (a j : ℝ)) q | |
| 92 | + (CutStageEstimates.positiveStages (A i)) =ᶠ[𝓝 x] (fun _ => 0) | |
| 93 | + | |
| 94 | +end NavierStokes.GenericRealization | |
| 95 | +end | |
| 96 | + | |
| 97 | +end | |
| 98 | + | |
| 99 | +/-! ## From `NavierStokes/GenericSolenoidalRealization.lean` | |
| 100 | + | |
| 101 | +The text of `NavierStokes/GenericSolenoidalRealization.lean`, folded into this file, which was its only importer. -/ | |
| 102 | + | |
| 103 | +section | |
| 104 | + | |
| 105 | +noncomputable section | |
| 106 | + | |
| 107 | +namespace NavierStokes.GenericSolenoidalRealization | |
| 108 | + | |
| 109 | +open Set Filter ProblemStatement | |
| 110 | +open scoped Topology ContDiff BigOperators | |
| 111 | + | |
| 112 | +/-- Literal curl-after-cutoff realization, with a separate uncut base. -/ | |
| 113 | +def velocity (a : ℕ → ℝ) (q : SpaceTime → ℝ) (u0 : VelocityField) | |
| 114 | + (A B : ℕ → VelocityField) : VelocityField := | |
| 115 | + fun w => u0 w + SolenoidalDiagonal.velocitySum a q A w + | |
| 116 | + SolenoidalDiagonal.potentialSum a q B w | |
| 117 | + | |
| 118 | +/-- The manuscript's sum starts at stage one; the base is left uncut. -/ | |
| 119 | +def positiveVelocity (a : ℕ → ℝ) (q : SpaceTime → ℝ) (u0 : VelocityField) | |
| 120 | + (A B : ℕ → VelocityField) : VelocityField := | |
| 121 | + velocity a q u0 (CutStageEstimates.positiveStages A) (CutStageEstimates.positiveStages B) | |
| 122 | + | |
| 123 | +end NavierStokes.GenericSolenoidalRealization | |
| 124 | +end | |
| 125 | + | |
| 126 | +end | |
| 127 | + | |
| 128 | +/-! ## From `NavierStokes/GenericVelocityRates.lean` | |
| 129 | + | |
| 130 | +The text of `NavierStokes/GenericVelocityRates.lean`, folded into this file, which was its only importer. -/ | |
| 131 | + | |
| 132 | +section | |
| 133 | + | |
| 134 | +noncomputable section | |
| 135 | + | |
| 136 | +namespace NavierStokes.GenericDifferentialPolynomial | |
| 137 | + | |
| 138 | +open Set Filter DiagonalResidual | |
| 139 | +open scoped Topology ContDiff | |
| 140 | + | |
| 141 | +variable {D V W : Type*} [NormedAddCommGroup D] [NormedSpace ℝ D] | |
| 142 | + [NormedAddCommGroup V] [NormedSpace ℝ V] [NormedAddCommGroup W] [NormedSpace ℝ W] | |
| 143 | + | |
| 144 | +end NavierStokes.GenericDifferentialPolynomial | |
| 145 | + | |
| 146 | +namespace NavierStokes.GenericSolenoidalRealization | |
| 147 | + | |
| 148 | +open Set Filter ProblemStatement DiagonalResidual GenericRealizationBounds GenericDifferentialPolynomial | |
| 149 | +open scoped Topology ContDiff BigOperators | |
| 150 | + | |
| 151 | +def positiveStage (u0 : VelocityField) (A B : ℕ → VelocityField) (J : ℕ) : VelocityField := | |
| 152 | + fun w => u0 w + MixedDiagonalResidual.uncutVelocity | |
| 153 | + (CutStageEstimates.positiveStages A) (CutStageEstimates.positiveStages B) J w | |
| 154 | + | |
| 155 | +end NavierStokes.GenericSolenoidalRealization | |
| 156 | +end | |
| 157 | + | |
| 158 | +end | |
| 159 | + | |
| 160 | +/-! ## From `NavierStokes/GenericTupleRealization.lean` | |
| 161 | + | |
| 162 | +The text of `NavierStokes/GenericTupleRealization.lean`, folded into this file, which was its only importer. -/ | |
| 163 | + | |
| 164 | +section | |
| 165 | + | |
| 166 | +noncomputable section | |
| 167 | + | |
| 168 | +namespace NavierStokes.GenericTupleRealization | |
| 169 | + | |
| 170 | +open Set Filter ProblemStatement DiagonalResidual GenericRealizationBounds GenericDifferentialPolynomial | |
| 171 | +open GenericSolenoidalRealization GenericRealization | |
| 172 | +open scoped Topology ContDiff BigOperators | |
| 173 | + | |
| 174 | +abbrev Entry (κ : Type*) := Bool ⊕ κ | |
| 175 | + | |
| 176 | +def Value {κ : Type*} : Entry κ → Type | |
| 177 | + | .inl _ => Space | |
| 178 | + | .inr _ => ℝ | |
| 179 | + | |
| 180 | +instance {κ : Type*} (e : Entry κ) : NormedAddCommGroup (Value e) := | |
| 181 | + match e with | |
| 182 | + | .inl _ => inferInstanceAs (NormedAddCommGroup Space) | |
| 183 | + | .inr _ => inferInstanceAs (NormedAddCommGroup ℝ) | |
| 184 | + | |
| 185 | +instance {κ : Type*} (e : Entry κ) : NormedSpace ℝ (Value e) := | |
| 186 | + match e with | |
| 187 | + | .inl _ => inferInstanceAs (NormedSpace ℝ Space) | |
| 188 | + | .inr _ => inferInstanceAs (NormedSpace ℝ ℝ) | |
| 189 | + | |
| 190 | +def representatives {κ : Type*} (A B : ℕ → VelocityField) (R : κ → ℕ → PressureField) : | |
| 191 | + ∀ e : Entry κ, ℕ → SpaceTime → Value e | |
| 192 | + | .inl false => A | |
| 193 | + | .inl true => B | |
| 194 | + | .inr k => R k | |
| 195 | + | |
| 196 | +/-- The optional scalar entries comprise pressure and any finite stress | |
| 197 | +components. Taking a singleton retains pressure alone. -/ | |
| 198 | +def components {κ : Type*} (a : ℕ → ℝ) (q : SpaceTime → ℝ) | |
| 199 | + (u0 : VelocityField) (s0 : κ → PressureField) | |
| 200 | + (A B : ℕ → VelocityField) (R : κ → ℕ → PressureField) : | |
| 201 | + Fin 3 ⊕ κ → PressureField | |
| 202 | + | .inl i => fun w => positiveVelocity a q u0 A B w i | |
| 203 | + | .inr k => realized a q (s0 k) (R k) | |
| 204 | + | |
| 205 | +def stageComponents {κ : Type*} (u0 : VelocityField) (s0 : κ → PressureField) | |
| 206 | + (A B : ℕ → VelocityField) (R : κ → ℕ → PressureField) (J : ℕ) : | |
| 207 | + Fin 3 ⊕ κ → PressureField | |
| 208 | + | .inl i => fun w => positiveStage u0 A B J w i | |
| 209 | + | .inr k => stage (s0 k) (R k) J | |
| 210 | + | |
| 211 | +structure Result {κ : Type*} (U : Set SpaceTime) (q : SpaceTime → ℝ) | |
| 212 | + (u0 : VelocityField) (s0 : κ → PressureField) | |
| 213 | + (A B : ℕ → VelocityField) (R : κ → ℕ → PressureField) | |
| 214 | + (g L : ℕ → ℝ) (a : ℕ → ℕ) : Prop where | |
| 215 | + positive : ∀ j, 0 < a j | |
| 216 | + doubling : ∀ j, 2 * a j ≤ a (j + 1) | |
| 217 | + monotone : StrictMono a | |
| 218 | + tends : Tendsto (fun j => (a j : ℝ)) atTop atTop | |
| 219 | + locallyFinite_representatives : ∀ e, LocallyFinite (fun j => Function.support | |
| 220 | + (fun w : U => SolenoidalDiagonal.cutStage (fun j => (a j : ℝ)) q | |
| 221 | + (CutStageEstimates.positiveStages (representatives A B R e)) j w)) | |
| 222 | + smooth_velocity : ContDiffOn ℝ ∞ (positiveVelocity (fun j => (a j : ℝ)) q u0 A B) U | |
| 223 | + smooth_scalars : ∀ k, ContDiffOn ℝ ∞ (realized (fun j => (a j : ℝ)) q (s0 k) (R k)) U | |
| 224 | + divergence : ∀ w ∈ U, spatialDivergence (positiveVelocity (fun j => (a j : ℝ)) q u0 A B) w.1 w.2 = 0 | |
| 225 | + approximation : ∀ i, Nonempty (ApproximationRates (scaleApproach U q) q (fun J => g (J + 1) / 2) | |
| 226 | + (components (fun j => (a j : ℝ)) q u0 s0 A B R i) (fun J => stageComponents u0 s0 A B R J i)) | |
| 227 | + tail_velocity : ∀ w ∈ U, ∀ J m, m ≤ J + 2 → q w < 1 / (2 * (a J : ℝ)) → | |
| 228 | + ‖iteratedFDeriv ℝ m (fun y => positiveVelocity (fun j => (a j : ℝ)) q u0 A B y - | |
| 229 | + positiveStage u0 A B J y) w‖ ≤ (1 / 2 : ℝ) ^ J * q w ^ | |
| 230 | + (g (J + 1) / 2 - (max (CutStageEstimates.cutLoss L (m + 1)) (CutStageEstimates.cutLoss L m) + 1)) | |
| 231 | + tail_scalars : ∀ k w, w ∈ U → ∀ J m, m ≤ J + 3 → q w < 1 / (2 * (a J : ℝ)) → | |
| 232 | + ‖iteratedFDeriv ℝ m (fun y => realized (fun j => (a j : ℝ)) q (s0 k) (R k) y - | |
| 233 | + stage (s0 k) (R k) J y) w‖ ≤ | |
| 234 | + (1 / 2 : ℝ) ^ J * q w ^ (g (J + 1) / 2 - CutStageEstimates.cutLoss L m) | |
| 235 | + outer_velocity : ∀ w, ContinuousAt q w → 1 / (a 0 : ℝ) < q w → | |
| 236 | + positiveVelocity (fun j => (a j : ℝ)) q u0 A B =ᶠ[𝓝 w] u0 | |
| 237 | + outer_scalars : ∀ k w, ContinuousAt q w → 1 / (a 0 : ℝ) < q w → | |
| 238 | + realized (fun j => (a j : ℝ)) q (s0 k) (R k) =ᶠ[𝓝 w] s0 k | |
| 239 | + | |
| 240 | +end NavierStokes.GenericTupleRealization | |
| 241 | +end | |
| 242 | + | |
| 243 | +end | |
| 244 | + | |
| 245 | +/-! ## From `NavierStokes/GenericAngularRecovery.lean` | |
| 246 | + | |
| 247 | +The text of `NavierStokes/GenericAngularRecovery.lean`, folded into this file, which was its only importer. -/ | |
| 248 | + | |
| 249 | +section | |
| 250 | + | |
| 251 | +noncomputable section | |
| 252 | + | |
| 253 | +namespace NavierStokes.GenericSolenoidalRealization | |
| 254 | + | |
| 255 | +open Set Filter ProblemStatement AxisymmetricFields DirectAngularDiagonal | |
| 256 | +open scoped Topology ContDiff BigOperators | |
| 257 | + | |
| 258 | +private def radialFactor (w : SpaceTime) (p : ProfilePoint) : ℝ := | |
| 259 | + Real.sqrt (p.2.1 / radialEnergy w.2) | |
| 260 | + | |
| 261 | +/-- A local section of the cylindrical coordinate map through the given | |
| 262 | +off-axis Cartesian point, retaining its angular direction. -/ | |
| 263 | +private def radialSection (w : SpaceTime) (p : ProfilePoint) : SpaceTime := | |
| 264 | + (p.1, AxisymmetricResidual.pack (radialFactor w p * w.2 0) | |
| 265 | + (radialFactor w p * w.2 1) p.2.2) | |
| 266 | + | |
| 267 | +private theorem radialFactor_at {w : SpaceTime} (hw : 0 < radialEnergy w.2) : | |
| 268 | + radialFactor w (profilePoint w.1 w.2) = 1 := by | |
| 269 | + simp only [radialFactor, profilePoint, div_self hw.ne', Real.sqrt_one] | |
| 270 | + | |
| 271 | +private theorem radialSection_at {w : SpaceTime} (hw : 0 < radialEnergy w.2) : | |
| 272 | + radialSection w (profilePoint w.1 w.2) = w := by | |
| 273 | + refine Prod.ext ?_ ?_ | |
| 274 | + · rfl | |
| 275 | + ext i | |
| 276 | + fin_cases i <;> simp [radialSection, radialFactor, profilePoint, div_self hw.ne'] | |
| 277 | + | |
| 278 | +private theorem profile_radialSection {w : SpaceTime} (hw : 0 < radialEnergy w.2) | |
| 279 | + {p : ProfilePoint} (hp : 0 < p.2.1) : | |
| 280 | + profilePoint (radialSection w p).1 (radialSection w p).2 = p := by | |
| 281 | + have hs : radialFactor w p ^ 2 = p.2.1 / radialEnergy w.2 := | |
| 282 | + Real.sq_sqrt (div_pos hp hw).le | |
| 283 | + have he : radialEnergy (radialSection w p).2 = p.2.1 := by | |
| 284 | + simp only [radialEnergy, radialSection, AxisymmetricResidual.pack_zero, AxisymmetricResidual.pack_one] | |
| 285 | + calc | |
| 286 | + _ = radialFactor w p ^ 2 * radialEnergy w.2 := by unfold radialEnergy; ring | |
| 287 | + _ = p.2.1 := by rw [hs, div_mul_cancel₀ _ hw.ne'] | |
| 288 | + refine Prod.ext ?_ ?_ | |
| 289 | + · rfl | |
| 290 | + exact Prod.ext he (AxisymmetricResidual.pack_two _ _ _) | |
| 291 | + | |
| 292 | +private theorem radialFactor_smoothAt {w : SpaceTime} (hw : 0 < radialEnergy w.2) : | |
| 293 | + ContDiffAt ℝ ∞ (radialFactor w) (profilePoint w.1 w.2) := by | |
| 294 | + apply (contDiffAt_snd.fst.div_const (radialEnergy w.2)).sqrt | |
| 295 | + change (profilePoint w.1 w.2).2.1 / radialEnergy w.2 ≠ 0 | |
| 296 | + norm_num [profilePoint, div_self hw.ne'] | |
| 297 | + | |
| 298 | +private theorem radialSection_smoothAt {w : SpaceTime} (hw : 0 < radialEnergy w.2) : | |
| 299 | + ContDiffAt ℝ ∞ (radialSection w) (profilePoint w.1 w.2) := by | |
| 300 | + have hs := radialFactor_smoothAt hw | |
| 301 | + have hv : ContDiffAt ℝ ∞ (fun p : ProfilePoint => AxisymmetricResidual.pack | |
| 302 | + (radialFactor w p * w.2 0) (radialFactor w p * w.2 1) p.2.2) | |
| 303 | + (profilePoint w.1 w.2) := by | |
| 304 | + unfold AxisymmetricResidual.pack | |
| 305 | + exact (((hs.mul contDiffAt_const).smul contDiffAt_const).add | |
| 306 | + ((hs.mul contDiffAt_const).smul contDiffAt_const)).add | |
| 307 | + (contDiffAt_snd.snd.smul contDiffAt_const) | |
| 308 | + exact contDiffAt_fst.prodMk hv | |
| 309 | + | |
| 310 | +end NavierStokes.GenericSolenoidalRealization | |
| 311 | +end | |
| 312 | + | |
| 313 | +end | |
| 314 | + | |
| 315 | +/-! ## From `NavierStokes/GenericFactorSupport.lean` | |
| 316 | + | |
| 317 | +The text of `NavierStokes/GenericFactorSupport.lean`, folded into this file, which was its only importer. -/ | |
| 318 | + | |
| 319 | +section | |
| 320 | + | |
| 321 | +noncomputable section | |
| 322 | + | |
| 323 | +namespace NavierStokes.GenericDifferentialPolynomial | |
| 324 | + | |
| 325 | +open Set Filter | |
| 326 | +open scoped Topology ContDiff BigOperators | |
| 327 | + | |
| 328 | +variable {D ι : Type*} [NormedAddCommGroup D] [NormedSpace ℝ D] | |
| 329 | + | |
| 330 | +/-- A single Cartesian field factor. Coordinate vectors give the usual | |
| 331 | +multi-index derivatives; arbitrary fixed directions are also permitted. -/ | |
| 332 | +inductive FieldFactor (D ι : Type*) where | |
| 333 | + | input : ι → FieldFactor D ι | |
| 334 | + | directional : D → FieldFactor D ι → FieldFactor D ι | |
| 335 | + | |
| 336 | +def FieldFactor.expression : FieldFactor D ι → Expression D ι Empty | |
| 337 | + | .input i => .input i | |
| 338 | + | .directional v f => .directional v f.expression | |
| 339 | + | |
| 340 | +def FieldFactor.eval (f : FieldFactor D ι) (u : ι → D → ℝ) : D → ℝ := | |
| 341 | + f.expression.eval (fun k => Empty.elim k) u | |
| 342 | + | |
| 343 | +/-- Each leaf records the support of one differentiated field factor in the | |
| 344 | +base and every increment. Multiplication constructs arbitrary positive-degree | |
| 345 | +monomials without requiring undifferentiated components to share the support. -/ | |
| 346 | +inductive FactorSupportAt (base : ι → D → ℝ) (inc : ℕ → ι → D → ℝ) (x : D) : | |
| 347 | + Expression D ι Empty → Prop where | |
| 348 | + | factor (f : FieldFactor D ι) | |
| 349 | + (base_zero : f.eval base =ᶠ[𝓝 x] (fun _ => 0)) | |
| 350 | + (increment_zero : ∀ j, f.eval (inc j) =ᶠ[𝓝 x] (fun _ => 0)) : | |
| 351 | + FactorSupportAt base inc x f.expression | |
| 352 | + | mul {e f : Expression D ι Empty} : | |
| 353 | + FactorSupportAt base inc x e → FactorSupportAt base inc x f → | |
| 354 | + FactorSupportAt base inc x (.mul e f) | |
| 355 | + | |
| 356 | +end NavierStokes.GenericDifferentialPolynomial | |
| 357 | +end | |
| 358 | + | |
| 359 | +end | |
| 360 | + | |
| 361 | +/-! ## From `NavierStokes/GenericTupleSupport.lean` | |
| 362 | + | |
| 363 | +The text of `NavierStokes/GenericTupleSupport.lean`, folded into this file, which was its only importer. -/ | |
| 364 | + | |
| 365 | +section | |
| 366 | + | |
| 367 | +noncomputable section | |
| 368 | + | |
| 369 | +namespace NavierStokes.GenericTupleRealization | |
| 370 | + | |
| 371 | +open Set Filter ProblemStatement GenericSolenoidalRealization GenericDifferentialPolynomial | |
| 372 | +open GenericRealizationBounds GenericRealization SolenoidalDiagonal | |
| 373 | +open scoped Topology ContDiff BigOperators | |
| 374 | + | |
| 375 | +private theorem spatialCurl_sum_on {U : Set SpaceTime} (hU : IsOpen U) | |
| 376 | + {A : ℕ → VelocityField} (hA : ∀ j, ContDiffOn ℝ ∞ (A j) U) | |
| 377 | + (N : ℕ) {w : SpaceTime} (hw : w ∈ U) : | |
| 378 | + SpatialCurl.spatialCurl (fun y => ∑ j ∈ Finset.range N, A j y) w = | |
| 379 | + ∑ j ∈ Finset.range N, SpatialCurl.spatialCurl (A j) w := by | |
| 380 | + have hd : ∀ j ∈ Finset.range N, DifferentiableAt ℝ (fun x : Space => A j (w.1, x)) w.2 := by | |
| 381 | + intro j _ | |
| 382 | + exact (((hA j).contDiffAt (hU.mem_nhds hw)).comp w.2 | |
| 383 | + (contDiffAt_const.prodMk contDiffAt_id)).differentiableAt (by simp) | |
| 384 | + simpa only [SpatialCurl.spatialCurl, SpatialCurl.curl, map_sum] using | |
| 385 | + congrArg SpatialCurl.curlLinear (fderiv_fun_sum hd) | |
| 386 | + | |
| 387 | +end NavierStokes.GenericTupleRealization | |
| 388 | +end | |
| 389 | + | |
| 390 | +end | |
| 3 | 391 | |
| 4 | 392 | noncomputable section |
| 5 | 393 | |
+0 −26 NavierStokes/GenericSupportLocalCoefficients.lean deleted
| @@ -1,26 +0,0 @@ | ||
| 1 | -import NavierStokes.GenericSupportedPolynomial | |
| 2 | - | |
| 3 | -/-! # Differential polynomials with coefficients smooth only on factor supports | |
| 4 | - | |
| 5 | -The literal coefficient is retained. At points outside the common factor | |
| 6 | -region the monomial has a zero germ, making its product smooth with every | |
| 7 | -jet zero even when the coefficient itself is singular or nonsmooth there. | |
| 8 | --/ | |
| 9 | - | |
| 10 | -noncomputable section | |
| 11 | - | |
| 12 | -namespace NavierStokes.GenericDifferentialPolynomial | |
| 13 | - | |
| 14 | -open Set Filter DiagonalResidual | |
| 15 | -open scoped Topology ContDiff BigOperators | |
| 16 | - | |
| 17 | -variable {D : Type*} [NormedAddCommGroup D] [NormedSpace ℝ D] | |
| 18 | -variable {l : Filter D} {q : D → ℝ} {U S : Set D} | |
| 19 | - | |
| 20 | -namespace SupportedPolynomial | |
| 21 | - | |
| 22 | -variable {ι : Type*} | |
| 23 | - | |
| 24 | -end SupportedPolynomial | |
| 25 | - | |
| 26 | -end NavierStokes.GenericDifferentialPolynomial | |
+35 −1 NavierStokes/GenericSupportLocalSummation.lean View file
| @@ -1,5 +1,5 @@ | ||
| 1 | 1 | import NavierStokes.GenericSummationRealization |
| 2 | -import NavierStokes.GenericSupportLocalCoefficients | |
| 2 | +import NavierStokes.GenericSupportedPolynomial | |
| 3 | 3 | |
| 4 | 4 | /-! # Actual summation residuals with support-local coefficient regularity |
| 5 | 5 | |
| @@ -8,6 +8,40 @@ coefficient functions. Smoothness and growth of a nonconstant coefficient | ||
| 8 | 8 | are only needed on its common differentiated-factor support region. |
| 9 | 9 | -/ |
| 10 | 10 | |
| 11 | +/-! ## From `NavierStokes/GenericSupportLocalCoefficients.lean` | |
| 12 | + | |
| 13 | +The text of `NavierStokes/GenericSupportLocalCoefficients.lean`, folded into this file, which was its only importer. -/ | |
| 14 | + | |
| 15 | +section | |
| 16 | + | |
| 17 | +/-! # Differential polynomials with coefficients smooth only on factor supports | |
| 18 | + | |
| 19 | +The literal coefficient is retained. At points outside the common factor | |
| 20 | +region the monomial has a zero germ, making its product smooth with every | |
| 21 | +jet zero even when the coefficient itself is singular or nonsmooth there. | |
| 22 | +-/ | |
| 23 | + | |
| 24 | +noncomputable section | |
| 25 | + | |
| 26 | +namespace NavierStokes.GenericDifferentialPolynomial | |
| 27 | + | |
| 28 | +open Set Filter DiagonalResidual | |
| 29 | +open scoped Topology ContDiff BigOperators | |
| 30 | + | |
| 31 | +variable {D : Type*} [NormedAddCommGroup D] [NormedSpace ℝ D] | |
| 32 | +variable {l : Filter D} {q : D → ℝ} {U S : Set D} | |
| 33 | + | |
| 34 | +namespace SupportedPolynomial | |
| 35 | + | |
| 36 | +variable {ι : Type*} | |
| 37 | + | |
| 38 | +end SupportedPolynomial | |
| 39 | + | |
| 40 | +end NavierStokes.GenericDifferentialPolynomial | |
| 41 | +end | |
| 42 | + | |
| 43 | +end | |
| 44 | + | |
| 11 | 45 | noncomputable section |
| 12 | 46 | |
| 13 | 47 | namespace NavierStokes.GenericTupleRealization |
+130 −2 NavierStokes/GenericSupportedPolynomial.lean View file
| @@ -1,5 +1,133 @@ | ||
| 1 | -import NavierStokes.GenericDifferentialPolynomial | |
| 2 | -import NavierStokes.GenericRealizationBounds | |
| 1 | +import NavierStokes.DiagonalResidual | |
| 2 | +import NavierStokes.MixedFiniteBackground | |
| 3 | + | |
| 4 | +/-! ## From `NavierStokes/GenericJetRateAlgebra.lean` | |
| 5 | + | |
| 6 | +The text of `NavierStokes/GenericJetRateAlgebra.lean`, folded into this file, which was its only importer. -/ | |
| 7 | + | |
| 8 | +section | |
| 9 | + | |
| 10 | +noncomputable section | |
| 11 | + | |
| 12 | +namespace NavierStokes.GenericDifferentialPolynomial | |
| 13 | + | |
| 14 | +open Set Filter DiagonalResidual | |
| 15 | +open scoped Topology ContDiff | |
| 16 | + | |
| 17 | +variable {D : Type*} [NormedAddCommGroup D] [NormedSpace ℝ D] | |
| 18 | +private local instance : NormedAddCommGroup ((D →L[ℝ] ℝ) →L[ℝ] ℝ) := inferInstance | |
| 19 | +private local instance : NormedSpace ℝ ((D →L[ℝ] ℝ) →L[ℝ] ℝ) := inferInstance | |
| 20 | + | |
| 21 | +variable {l : Filter D} {q : D → ℝ} {U : Set D} {f g : D → ℝ} | |
| 22 | + | |
| 23 | +end NavierStokes.GenericDifferentialPolynomial | |
| 24 | +end | |
| 25 | + | |
| 26 | +end | |
| 27 | + | |
| 28 | +/-! ## From `NavierStokes/GenericDifferentialPolynomial.lean` | |
| 29 | + | |
| 30 | +The text of `NavierStokes/GenericDifferentialPolynomial.lean`, folded into this file, which was its only importer. -/ | |
| 31 | + | |
| 32 | +section | |
| 33 | + | |
| 34 | +noncomputable section | |
| 35 | + | |
| 36 | +namespace NavierStokes.GenericDifferentialPolynomial | |
| 37 | + | |
| 38 | +open Set Filter DiagonalResidual | |
| 39 | +open scoped Topology ContDiff | |
| 40 | + | |
| 41 | +variable {D : Type*} [NormedAddCommGroup D] [NormedSpace ℝ D] | |
| 42 | + | |
| 43 | +/-- Quantitative approximation data. Constants may depend on the stage, while | |
| 44 | +the power losses and derivative thresholds are fixed functions of the jet order. -/ | |
| 45 | +structure ApproximationRates (l : Filter D) (q : D → ℝ) (gain : ℕ → ℝ) | |
| 46 | + (f : D → ℝ) (stage : ℕ → D → ℝ) where | |
| 47 | + growthLoss : ℕ → ℝ | |
| 48 | + tailLoss : ℕ → ℝ | |
| 49 | + threshold : ℕ → ℕ | |
| 50 | + stage_growth : ∀ J m, JetRate l q (stage J) m (-growthLoss m) | |
| 51 | + tail_rate : ∀ m J, threshold m ≤ J → | |
| 52 | + JetRate l q (fun x => f x - stage J x) m (gain J - tailLoss m) | |
| 53 | + | |
| 54 | +private def maxThreshold (M : ℕ → ℕ) (m : ℕ) : ℕ := | |
| 55 | + (Finset.range (m + 1)).sup M | |
| 56 | + | |
| 57 | +private theorem le_maxThreshold (M : ℕ → ℕ) {k m : ℕ} (hk : k ≤ m) : | |
| 58 | + M k ≤ maxThreshold M m := | |
| 59 | + Finset.le_sup (f := M) (Finset.mem_range.mpr (Nat.lt_succ_of_le hk)) | |
| 60 | + | |
| 61 | +variable {l : Filter D} {q : D → ℝ} {gain : ℕ → ℝ} {U : Set D} | |
| 62 | +variable {f g : D → ℝ} {fs gs : ℕ → D → ℝ} | |
| 63 | + | |
| 64 | +/-- A finite differential expression in scalar components with fixed variable | |
| 65 | +coefficients. Products, sums, and arbitrary fixed directional derivatives are | |
| 66 | +allowed at every node; consequently the order and polynomial degree are finite. -/ | |
| 67 | +inductive Expression (D ι κ : Type*) where | |
| 68 | + | input : ι → Expression D ι κ | |
| 69 | + | coeff : κ → Expression D ι κ | |
| 70 | + | add : Expression D ι κ → Expression D ι κ → Expression D ι κ | |
| 71 | + | mul : Expression D ι κ → Expression D ι κ → Expression D ι κ | |
| 72 | + | directional : D → Expression D ι κ → Expression D ι κ | |
| 73 | + | |
| 74 | +namespace Expression | |
| 75 | + | |
| 76 | +variable {ι κ : Type*} | |
| 77 | + | |
| 78 | +/-- Evaluation uses actual Fréchet derivatives, including at derivative nodes. -/ | |
| 79 | +def eval (c : κ → D → ℝ) (u : ι → D → ℝ) : Expression D ι κ → D → ℝ | |
| 80 | + | .input i => u i | |
| 81 | + | .coeff i => c i | |
| 82 | + | .add a b => fun x => eval c u a x + eval c u b x | |
| 83 | + | .mul a b => fun x => eval c u a x * eval c u b x | |
| 84 | + | .directional v a => fun x => fderiv ℝ (eval c u a) x v | |
| 85 | + | |
| 86 | +end Expression | |
| 87 | + | |
| 88 | +end NavierStokes.GenericDifferentialPolynomial | |
| 89 | +end | |
| 90 | + | |
| 91 | +end | |
| 92 | + | |
| 93 | +/-! ## From `NavierStokes/GenericRealizationBounds.lean` | |
| 94 | + | |
| 95 | +The text of `NavierStokes/GenericRealizationBounds.lean`, folded into this file, which was its only importer. -/ | |
| 96 | + | |
| 97 | +section | |
| 98 | + | |
| 99 | +/-! | |
| 100 | +# Quantitative bounds for general diagonal realizations | |
| 101 | + | |
| 102 | +The base is retained without a cutoff. The positive corrections are actual | |
| 103 | +locally finite cutoff sums. Logarithmic losses are absorbed at each fixed | |
| 104 | +stage, while the resulting power loss is independent of the stage. | |
| 105 | +-/ | |
| 106 | + | |
| 107 | +noncomputable section | |
| 108 | + | |
| 109 | +namespace NavierStokes.GenericRealizationBounds | |
| 110 | + | |
| 111 | +open Set Filter DiagonalResidual | |
| 112 | +open scoped Topology ContDiff BigOperators | |
| 113 | + | |
| 114 | +variable {E V : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] | |
| 115 | + [NormedAddCommGroup V] [NormedSpace ℝ V] | |
| 116 | + | |
| 117 | +/-- The uncut base plus the actual positive cutoff series. -/ | |
| 118 | +def realized (a : ℕ → ℝ) (q : E → ℝ) (base : E → V) (A : ℕ → E → V) : E → V := | |
| 119 | + fun x => base x + SolenoidalDiagonal.potentialSum a q | |
| 120 | + (CutStageEstimates.positiveStages A) x | |
| 121 | + | |
| 122 | +/-- The corresponding finite approximation, including exactly stages `1,…,J`. -/ | |
| 123 | +def stage (base : E → V) (A : ℕ → E → V) (J : ℕ) : E → V := | |
| 124 | + fun x => base x + DiagonalJetBounds.uncutPrefix | |
| 125 | + (CutStageEstimates.positiveStages A) (J + 1) x | |
| 126 | + | |
| 127 | +end NavierStokes.GenericRealizationBounds | |
| 128 | +end | |
| 129 | + | |
| 130 | +end | |
| 3 | 131 | |
| 4 | 132 | noncomputable section |
| 5 | 133 | |
+0 −77 NavierStokes/GenericTupleRealization.lean deleted
| @@ -1,77 +0,0 @@ | ||
| 1 | -import NavierStokes.GenericVelocityRates | |
| 2 | - | |
| 3 | -noncomputable section | |
| 4 | - | |
| 5 | -namespace NavierStokes.GenericTupleRealization | |
| 6 | - | |
| 7 | -open Set Filter ProblemStatement DiagonalResidual GenericRealizationBounds GenericDifferentialPolynomial | |
| 8 | -open GenericSolenoidalRealization GenericRealization | |
| 9 | -open scoped Topology ContDiff BigOperators | |
| 10 | - | |
| 11 | -abbrev Entry (κ : Type*) := Bool ⊕ κ | |
| 12 | - | |
| 13 | -def Value {κ : Type*} : Entry κ → Type | |
| 14 | - | .inl _ => Space | |
| 15 | - | .inr _ => ℝ | |
| 16 | - | |
| 17 | -instance {κ : Type*} (e : Entry κ) : NormedAddCommGroup (Value e) := | |
| 18 | - match e with | |
| 19 | - | .inl _ => inferInstanceAs (NormedAddCommGroup Space) | |
| 20 | - | .inr _ => inferInstanceAs (NormedAddCommGroup ℝ) | |
| 21 | - | |
| 22 | -instance {κ : Type*} (e : Entry κ) : NormedSpace ℝ (Value e) := | |
| 23 | - match e with | |
| 24 | - | .inl _ => inferInstanceAs (NormedSpace ℝ Space) | |
| 25 | - | .inr _ => inferInstanceAs (NormedSpace ℝ ℝ) | |
| 26 | - | |
| 27 | -def representatives {κ : Type*} (A B : ℕ → VelocityField) (R : κ → ℕ → PressureField) : | |
| 28 | - ∀ e : Entry κ, ℕ → SpaceTime → Value e | |
| 29 | - | .inl false => A | |
| 30 | - | .inl true => B | |
| 31 | - | .inr k => R k | |
| 32 | - | |
| 33 | -/-- The optional scalar entries comprise pressure and any finite stress | |
| 34 | -components. Taking a singleton retains pressure alone. -/ | |
| 35 | -def components {κ : Type*} (a : ℕ → ℝ) (q : SpaceTime → ℝ) | |
| 36 | - (u0 : VelocityField) (s0 : κ → PressureField) | |
| 37 | - (A B : ℕ → VelocityField) (R : κ → ℕ → PressureField) : | |
| 38 | - Fin 3 ⊕ κ → PressureField | |
| 39 | - | .inl i => fun w => positiveVelocity a q u0 A B w i | |
| 40 | - | .inr k => realized a q (s0 k) (R k) | |
| 41 | - | |
| 42 | -def stageComponents {κ : Type*} (u0 : VelocityField) (s0 : κ → PressureField) | |
| 43 | - (A B : ℕ → VelocityField) (R : κ → ℕ → PressureField) (J : ℕ) : | |
| 44 | - Fin 3 ⊕ κ → PressureField | |
| 45 | - | .inl i => fun w => positiveStage u0 A B J w i | |
| 46 | - | .inr k => stage (s0 k) (R k) J | |
| 47 | - | |
| 48 | -structure Result {κ : Type*} (U : Set SpaceTime) (q : SpaceTime → ℝ) | |
| 49 | - (u0 : VelocityField) (s0 : κ → PressureField) | |
| 50 | - (A B : ℕ → VelocityField) (R : κ → ℕ → PressureField) | |
| 51 | - (g L : ℕ → ℝ) (a : ℕ → ℕ) : Prop where | |
| 52 | - positive : ∀ j, 0 < a j | |
| 53 | - doubling : ∀ j, 2 * a j ≤ a (j + 1) | |
| 54 | - monotone : StrictMono a | |
| 55 | - tends : Tendsto (fun j => (a j : ℝ)) atTop atTop | |
| 56 | - locallyFinite_representatives : ∀ e, LocallyFinite (fun j => Function.support | |
| 57 | - (fun w : U => SolenoidalDiagonal.cutStage (fun j => (a j : ℝ)) q | |
| 58 | - (CutStageEstimates.positiveStages (representatives A B R e)) j w)) | |
| 59 | - smooth_velocity : ContDiffOn ℝ ∞ (positiveVelocity (fun j => (a j : ℝ)) q u0 A B) U | |
| 60 | - smooth_scalars : ∀ k, ContDiffOn ℝ ∞ (realized (fun j => (a j : ℝ)) q (s0 k) (R k)) U | |
| 61 | - divergence : ∀ w ∈ U, spatialDivergence (positiveVelocity (fun j => (a j : ℝ)) q u0 A B) w.1 w.2 = 0 | |
| 62 | - approximation : ∀ i, Nonempty (ApproximationRates (scaleApproach U q) q (fun J => g (J + 1) / 2) | |
| 63 | - (components (fun j => (a j : ℝ)) q u0 s0 A B R i) (fun J => stageComponents u0 s0 A B R J i)) | |
| 64 | - tail_velocity : ∀ w ∈ U, ∀ J m, m ≤ J + 2 → q w < 1 / (2 * (a J : ℝ)) → | |
| 65 | - ‖iteratedFDeriv ℝ m (fun y => positiveVelocity (fun j => (a j : ℝ)) q u0 A B y - | |
| 66 | - positiveStage u0 A B J y) w‖ ≤ (1 / 2 : ℝ) ^ J * q w ^ | |
| 67 | - (g (J + 1) / 2 - (max (CutStageEstimates.cutLoss L (m + 1)) (CutStageEstimates.cutLoss L m) + 1)) | |
| 68 | - tail_scalars : ∀ k w, w ∈ U → ∀ J m, m ≤ J + 3 → q w < 1 / (2 * (a J : ℝ)) → | |
| 69 | - ‖iteratedFDeriv ℝ m (fun y => realized (fun j => (a j : ℝ)) q (s0 k) (R k) y - | |
| 70 | - stage (s0 k) (R k) J y) w‖ ≤ | |
| 71 | - (1 / 2 : ℝ) ^ J * q w ^ (g (J + 1) / 2 - CutStageEstimates.cutLoss L m) | |
| 72 | - outer_velocity : ∀ w, ContinuousAt q w → 1 / (a 0 : ℝ) < q w → | |
| 73 | - positiveVelocity (fun j => (a j : ℝ)) q u0 A B =ᶠ[𝓝 w] u0 | |
| 74 | - outer_scalars : ∀ k w, ContinuousAt q w → 1 / (a 0 : ℝ) < q w → | |
| 75 | - realized (fun j => (a j : ℝ)) q (s0 k) (R k) =ᶠ[𝓝 w] s0 k | |
| 76 | - | |
| 77 | -end NavierStokes.GenericTupleRealization | |
+0 −24 NavierStokes/GenericTupleSupport.lean deleted
| @@ -1,24 +0,0 @@ | ||
| 1 | -import NavierStokes.GenericTupleRealization | |
| 2 | -import NavierStokes.GenericFactorSupport | |
| 3 | - | |
| 4 | -noncomputable section | |
| 5 | - | |
| 6 | -namespace NavierStokes.GenericTupleRealization | |
| 7 | - | |
| 8 | -open Set Filter ProblemStatement GenericSolenoidalRealization GenericDifferentialPolynomial | |
| 9 | -open GenericRealizationBounds GenericRealization SolenoidalDiagonal | |
| 10 | -open scoped Topology ContDiff BigOperators | |
| 11 | - | |
| 12 | -private theorem spatialCurl_sum_on {U : Set SpaceTime} (hU : IsOpen U) | |
| 13 | - {A : ℕ → VelocityField} (hA : ∀ j, ContDiffOn ℝ ∞ (A j) U) | |
| 14 | - (N : ℕ) {w : SpaceTime} (hw : w ∈ U) : | |
| 15 | - SpatialCurl.spatialCurl (fun y => ∑ j ∈ Finset.range N, A j y) w = | |
| 16 | - ∑ j ∈ Finset.range N, SpatialCurl.spatialCurl (A j) w := by | |
| 17 | - have hd : ∀ j ∈ Finset.range N, DifferentiableAt ℝ (fun x : Space => A j (w.1, x)) w.2 := by | |
| 18 | - intro j _ | |
| 19 | - exact (((hA j).contDiffAt (hU.mem_nhds hw)).comp w.2 | |
| 20 | - (contDiffAt_const.prodMk contDiffAt_id)).differentiableAt (by simp) | |
| 21 | - simpa only [SpatialCurl.spatialCurl, SpatialCurl.curl, map_sum] using | |
| 22 | - congrArg SpatialCurl.curlLinear (fderiv_fun_sum hd) | |
| 23 | - | |
| 24 | -end NavierStokes.GenericTupleRealization | |
+0 −24 NavierStokes/GenericVelocityRates.lean deleted
| @@ -1,24 +0,0 @@ | ||
| 1 | -import NavierStokes.GenericSolenoidalRealization | |
| 2 | - | |
| 3 | -noncomputable section | |
| 4 | - | |
| 5 | -namespace NavierStokes.GenericDifferentialPolynomial | |
| 6 | - | |
| 7 | -open Set Filter DiagonalResidual | |
| 8 | -open scoped Topology ContDiff | |
| 9 | - | |
| 10 | -variable {D V W : Type*} [NormedAddCommGroup D] [NormedSpace ℝ D] | |
| 11 | - [NormedAddCommGroup V] [NormedSpace ℝ V] [NormedAddCommGroup W] [NormedSpace ℝ W] | |
| 12 | - | |
| 13 | -end NavierStokes.GenericDifferentialPolynomial | |
| 14 | - | |
| 15 | -namespace NavierStokes.GenericSolenoidalRealization | |
| 16 | - | |
| 17 | -open Set Filter ProblemStatement DiagonalResidual GenericRealizationBounds GenericDifferentialPolynomial | |
| 18 | -open scoped Topology ContDiff BigOperators | |
| 19 | - | |
| 20 | -def positiveStage (u0 : VelocityField) (A B : ℕ → VelocityField) (J : ℕ) : VelocityField := | |
| 21 | - fun w => u0 w + MixedDiagonalResidual.uncutVelocity | |
| 22 | - (CutStageEstimates.positiveStages A) (CutStageEstimates.positiveStages B) J w | |
| 23 | - | |
| 24 | -end NavierStokes.GenericSolenoidalRealization | |
+103 −0 docs/s5-folding/README.md added View file
| @@ -0,0 +1,103 @@ | ||
| 1 | +# Folding small modules into their only importer | |
| 2 | + | |
| 3 | +Issue S-5 (#14). Measured on main at `ba4a037`: 582 modules fold into 343 files of 68 families, and the tree goes from 54.73 T instructions over 2,587 files to 50.94 T over 2,005 (−6.9%; T is 10¹²). | |
| 4 | + | |
| 5 | +## The rule | |
| 6 | + | |
| 7 | +A module is folded when exactly one file of the repository imports it, that file is in the same folder and the same family (first word of the file name), the module has at most 200 lines, the file that takes it stays within 600 lines, and neither states results (no file with `Comparator`, `Solution`, `Theorem`, `PaperResult`, `Results` or `Statement` in its name). The module's text goes into the file unchanged, under a heading that names it, in a `section` of its own, before the file's own text; the scopes it left open at its end are closed there; the file takes over its imports. Chains fold from the leaf up while the limits hold. | |
| 8 | + | |
| 9 | +## Why it is cheaper | |
| 10 | + | |
| 11 | +Every module loads what it imports before its first line is read. The cheapest modules of this tree cost about 4 G instructions with next to nothing in them, and the tree had 2,587 modules: that fixed cost is about a fifth of the whole. Lean Pool's copy of this proof went the same way (fewer modules, trimmed imports) and its benchmark found the gain there; Treant's `merge` stage folded 13 thin wrappers. The folds here were computed on this tree from its own import graph. | |
| 12 | + | |
| 13 | +## Doing it again | |
| 14 | + | |
| 15 | +```sh | |
| 16 | +python3 -I docs/s5-folding/fold.py self-test | |
| 17 | +python3 -I docs/s5-folding/fold.py plan . /tmp/plan.json --small 200 --cap 600 # what would fold on the tree as it stands | |
| 18 | +python3 -I docs/s5-folding/fold.py apply . /tmp/plan.json # do it | |
| 19 | +python3 -I docs/s5-folding/fold.py check . <a pull request's plan.json> # is the working tree main's text, folded? | |
| 20 | +``` | |
| 21 | + | |
| 22 | +Each pull request of the series keeps its plan in its route notes (`routes/<branch>/plan.json`). A fold whose file did not build was taken back before the count (0 files). | |
| 23 | + | |
| 24 | +## What is checked | |
| 25 | + | |
| 26 | +`fold.py check` makes every changed file again from main's text and compares byte for byte: a fold moves text and edits none. The `build` check compiles the result, and the four theorems Comparator judges are judged again on main after a merge, as for every change. | |
| 27 | + | |
| 28 | +## By family | |
| 29 | + | |
| 30 | +| family | files that take modules in | modules folded | saved | | |
| 31 | +|---|---|---|---| | |
| 32 | +| `Euler/Packet*` | 98 | 173 | 1,162.62 G | | |
| 33 | +| `Euler/Mean*` | 32 | 50 | 329.88 G | | |
| 34 | +| `Euler/Transverse*` | 26 | 41 | 265.61 G | | |
| 35 | +| `NavierStokes/R3` | 19 | 42 | 225.88 G | | |
| 36 | +| `Euler/Ordinary*` | 14 | 27 | 186.14 G | | |
| 37 | +| `Euler/Parent*` | 13 | 22 | 155.52 G | | |
| 38 | +| `Euler/Cylinder*` | 15 | 18 | 114.99 G | | |
| 39 | +| `Euler/Base*` | 8 | 14 | 100.25 G | | |
| 40 | +| `NavierStokes/Sharp*` | 3 | 15 | 87.29 G | | |
| 41 | +| `Euler/Smooth*` | 8 | 12 | 75.62 G | | |
| 42 | +| `Euler/Gevrey*` | 9 | 11 | 68.18 G | | |
| 43 | +| `NavierStokes/Generic*` | 3 | 12 | 67.72 G | | |
| 44 | +| `Euler/Source*` | 5 | 9 | 66.09 G | | |
| 45 | +| `Euler/Drift*` | 2 | 9 | 57.48 G | | |
| 46 | +| `Euler/Sobolev*` | 7 | 9 | 52.95 G | | |
| 47 | +| `Euler/Whole*` | 3 | 8 | 52.72 G | | |
| 48 | +| `Euler/All*` | 2 | 6 | 38.35 G | | |
| 49 | +| `Euler/Correction*` | 4 | 6 | 37.95 G | | |
| 50 | +| `Euler/Compact*` | 3 | 5 | 34.91 G | | |
| 51 | +| `NavierStokes/Whole*` | 3 | 6 | 34.28 G | | |
| 52 | +| `Euler/Lp*` | 5 | 5 | 32.77 G | | |
| 53 | +| `Euler/Parameter*` | 3 | 5 | 31.17 G | | |
| 54 | +| `Euler/Physical*` | 3 | 4 | 27.62 G | | |
| 55 | +| `NavierStokes/Local*` | 2 | 4 | 27.05 G | | |
| 56 | +| `Euler/Time*` | 2 | 4 | 25.92 G | | |
| 57 | +| `Euler/Static*` | 3 | 3 | 20.97 G | | |
| 58 | +| `Euler/Regularized*` | 2 | 3 | 19.87 G | | |
| 59 | +| `Euler/Field*` | 1 | 3 | 19.18 G | | |
| 60 | +| `Euler/Continuous*` | 3 | 3 | 18.81 G | | |
| 61 | +| `Euler/Stage*` | 1 | 3 | 18.09 G | | |
| 62 | +| `Euler/Heat*` | 1 | 2 | 17.33 G | | |
| 63 | +| `NavierStokes/Axis*` | 2 | 3 | 15.54 G | | |
| 64 | +| `Euler/Euler*` | 1 | 2 | 15.02 G | | |
| 65 | +| `Euler/Coefficient*` | 1 | 2 | 14.09 G | | |
| 66 | +| `Euler/Gaussian*` | 2 | 2 | 13.43 G | | |
| 67 | +| `Euler/Bounded*` | 1 | 2 | 13.15 G | | |
| 68 | +| `Euler/Linear*` | 1 | 2 | 12.58 G | | |
| 69 | +| `Euler/H6*` | 1 | 2 | 12.45 G | | |
| 70 | +| `Euler/Inviscid*` | 2 | 2 | 11.50 G | | |
| 71 | +| `NavierStokes/Particular*` | 1 | 2 | 11.14 G | | |
| 72 | +| `NavierStokes/Reference*` | 1 | 2 | 10.57 G | | |
| 73 | +| `NavierStokes/Periodic*` | 1 | 1 | 10.14 G | | |
| 74 | +| `Euler/Canonical*` | 1 | 1 | 7.72 G | | |
| 75 | +| `Euler/Lifted*` | 1 | 1 | 6.91 G | | |
| 76 | +| `Euler/Top*` | 1 | 1 | 6.70 G | | |
| 77 | +| `Euler/Mixed*` | 1 | 1 | 6.69 G | | |
| 78 | +| `Euler/H5*` | 1 | 1 | 6.56 G | | |
| 79 | +| `Euler/Fixed*` | 1 | 1 | 6.53 G | | |
| 80 | +| `Euler/Gained*` | 1 | 1 | 6.40 G | | |
| 81 | +| `Euler/Small*` | 1 | 1 | 6.39 G | | |
| 82 | +| `Euler/Projected*` | 1 | 1 | 6.35 G | | |
| 83 | +| `Euler/External*` | 1 | 1 | 6.34 G | | |
| 84 | +| `Euler/Terminal*` | 1 | 1 | 6.33 G | | |
| 85 | +| `Euler/Quadratic*` | 1 | 1 | 6.28 G | | |
| 86 | +| `Euler/Graph*` | 1 | 1 | 6.28 G | | |
| 87 | +| `Euler/Elapsed*` | 1 | 1 | 6.26 G | | |
| 88 | +| `Euler/Duhamel*` | 1 | 1 | 6.19 G | | |
| 89 | +| `Euler/Weighted*` | 1 | 1 | 6.17 G | | |
| 90 | +| `NavierStokes/Positive*` | 1 | 1 | 5.94 G | | |
| 91 | +| `NavierStokes/Actual*` | 1 | 1 | 5.85 G | | |
| 92 | +| `NavierStokes/Torus*` | 1 | 1 | 5.51 G | | |
| 93 | +| `NavierStokes/Within*` | 1 | 1 | 5.42 G | | |
| 94 | +| `NavierStokes/Smooth*` | 1 | 1 | 5.23 G | | |
| 95 | +| `NavierStokes/Moment*` | 1 | 1 | 5.03 G | | |
| 96 | +| `NavierStokes/Periodize*` | 1 | 1 | 4.94 G | | |
| 97 | +| `NavierStokes/Mean*` | 1 | 1 | 4.91 G | | |
| 98 | +| `NavierStokes/Valid*` | 1 | 1 | 4.89 G | | |
| 99 | +| `NavierStokes/Label*` | 1 | 1 | 4.33 G | | |
| 100 | + | |
| 101 | +## What this does not show | |
| 102 | + | |
| 103 | +The wall-clock time of a build on your machine; that every file is now in its best shape for reading (P-8 splits the large ones; nothing here grows past 600 lines). | |
+200 −0 docs/s5-folding/fold.py added View file
| @@ -0,0 +1,200 @@ | ||
| 1 | +#!/usr/bin/env python3 | |
| 2 | +"""Fold small modules into the one file that imports them (issue S-5: fewer modules, as in Lean Pool's copy). | |
| 3 | + | |
| 4 | + python3 -I fold.py plan <tree> <plan.json> [--small N] [--cap M] [--skip <file of hosts or parts, one a line>] | |
| 5 | + python3 -I fold.py apply <tree> <plan.json> # rewrites the tree in place | |
| 6 | + python3 -I fold.py check <clone> <plan.json> [rev] # is the working tree what `apply` makes of rev (origin/main)? | |
| 7 | + python3 -I fold.py self-test | |
| 8 | + | |
| 9 | +A module is folded when exactly one file of the repository imports it, that file is in the same folder and the same | |
| 10 | +family (first word of the file name), neither states results, the module has at most --small lines and the file that | |
| 11 | +takes it stays within --cap lines. Its text goes into the importer unchanged, in its own `section`, before the | |
| 12 | +importer's own text; the importer takes over its imports. No declaration, statement or proof line changes. | |
| 13 | +""" | |
| 14 | +import collections, json, os, re, subprocess, sys | |
| 15 | + | |
| 16 | +LIBS = ("NavierStokes/", "Euler/") | |
| 17 | +# files that state results or must match the challenge: they neither take a module nor are taken | |
| 18 | +PROTECTED = re.compile(r"(Comparator|PaperResult|Results|Theorem|Statement|Solution)") | |
| 19 | +IMPORT = re.compile(r"^import\s+(.+?)\s*(?:--.*)?$") | |
| 20 | + | |
| 21 | + | |
| 22 | +def fam(f): | |
| 23 | + d, n = f.rsplit("/", 1) | |
| 24 | + if f.startswith("NavierStokes/R3/"): return "NavierStokes/R3" | |
| 25 | + w = re.match(r"([A-Z][a-z0-9]+)", n) | |
| 26 | + return d + "/" + (w.group(1) if w else n[:-5]) + "*" | |
| 27 | + | |
| 28 | + | |
| 29 | +def read_tree(tree): | |
| 30 | + src = {} | |
| 31 | + for root, dirs, files in os.walk(tree): | |
| 32 | + dirs[:] = [d for d in dirs if d not in (".lake", ".git")] | |
| 33 | + for n in files: | |
| 34 | + if n.endswith(".lean"): | |
| 35 | + p = os.path.join(root, n) | |
| 36 | + src[os.path.relpath(p, tree)] = open(p, encoding="utf-8").read() | |
| 37 | + return src | |
| 38 | + | |
| 39 | + | |
| 40 | +def split(text): | |
| 41 | + """(what stands before the imports, the imported modules, the rest) of a file's text""" | |
| 42 | + lines = text.split("\n") | |
| 43 | + first = last = None | |
| 44 | + depth = 0 | |
| 45 | + for k, l in enumerate(lines): | |
| 46 | + if depth == 0 and IMPORT.match(l): | |
| 47 | + if first is None: first = k | |
| 48 | + last = k | |
| 49 | + elif depth == 0 and l.strip() and not l.lstrip().startswith("--") and not l.lstrip().startswith("/-") and first is not None: | |
| 50 | + break # the first command after the imports | |
| 51 | + depth = comment_depth(l, depth) | |
| 52 | + if first is None: return lines, [], [] | |
| 53 | + mods = [m for l in lines[first:last + 1] if IMPORT.match(l) for m in IMPORT.match(l).group(1).split()] | |
| 54 | + return lines[:first], mods, lines[last + 1:] | |
| 55 | + | |
| 56 | + | |
| 57 | +def comment_depth(line, depth): | |
| 58 | + """block-comment depth after this line (comments nest; a `--` line comment hides the rest of a line of code)""" | |
| 59 | + k = 0 | |
| 60 | + while k < len(line): | |
| 61 | + two = line[k:k + 2] | |
| 62 | + if two == "/-": depth += 1; k += 2 | |
| 63 | + elif two == "-/" and depth: depth -= 1; k += 2 | |
| 64 | + elif two == "--" and depth == 0: break | |
| 65 | + else: k += 1 | |
| 66 | + return depth | |
| 67 | + | |
| 68 | + | |
| 69 | +OPEN = re.compile(r"^\s*(?:(?:noncomputable|public|private|protected|@\[[^\]]*\])\s+)*(namespace|section|mutual)\b\s*([^\s-]*)") | |
| 70 | +END = re.compile(r"^\s*end\b\s*([^\s-]*)\s*(?:--.*)?$") | |
| 71 | + | |
| 72 | + | |
| 73 | +def unclosed(lines): | |
| 74 | + """the scopes a file's text leaves open at its end (Lean closes them at the end of a file; a section does not)""" | |
| 75 | + stack, depth = [], 0 | |
| 76 | + for l in lines: | |
| 77 | + if depth == 0: | |
| 78 | + m = OPEN.match(l) | |
| 79 | + if m: stack.append((m.group(1), m.group(2) if m.group(1) != "mutual" else "")) | |
| 80 | + elif END.match(l) and stack: stack.pop() | |
| 81 | + depth = comment_depth(l, depth) | |
| 82 | + return stack | |
| 83 | + | |
| 84 | + | |
| 85 | +def module(f): return f[:-5].replace("/", ".") | |
| 86 | + | |
| 87 | + | |
| 88 | +def plan(src, small, cap, skip=()): | |
| 89 | + imports = {f: [m.replace(".", "/") + ".lean" for m in split(t)[1]] for f, t in src.items()} | |
| 90 | + local = {f: [i for i in v if i in src] for f, v in imports.items()} | |
| 91 | + users = collections.defaultdict(set) | |
| 92 | + for f, v in local.items(): | |
| 93 | + for i in v: users[i].add(f) | |
| 94 | + size = {f: t.count("\n") for f, t in src.items()} | |
| 95 | + parts = {f: [f] for f in src} | |
| 96 | + gone = {} | |
| 97 | + ok = lambda f: f.startswith(LIBS) and not PROTECTED.search(f.rsplit("/", 1)[1]) and f not in skip | |
| 98 | + changed = True | |
| 99 | + while changed: | |
| 100 | + changed = False | |
| 101 | + for b in sorted(parts, key=lambda f: (size[f], f)): | |
| 102 | + if b not in parts or len(users[b]) != 1: continue | |
| 103 | + a = next(iter(users[b])) | |
| 104 | + if not (ok(a) and ok(b)) or fam(a) != fam(b) or a.rsplit("/", 1)[0] != b.rsplit("/", 1)[0]: continue | |
| 105 | + if size[b] > small or size[a] + size[b] > cap: continue | |
| 106 | + parts[a] = parts[b] + parts[a]; size[a] += size[b] | |
| 107 | + for i in local[b]: | |
| 108 | + users[i].discard(b); users[i].add(a) | |
| 109 | + local[a] = [i for i in local[a] if i != b] + [i for i in local[b] if i not in local[a]] | |
| 110 | + del parts[b], users[b]; gone[b] = a; changed = True | |
| 111 | + return {a: p for a, p in parts.items() if len(p) > 1} | |
| 112 | + | |
| 113 | + | |
| 114 | +def folded(src, host, parts): | |
| 115 | + """the host's new text""" | |
| 116 | + head, mods, body = split(src[host]) | |
| 117 | + inside = {module(p) for p in parts} | |
| 118 | + new = [m for m in mods if m not in inside] | |
| 119 | + out_parts = [] | |
| 120 | + for p in parts[:-1]: | |
| 121 | + h, pm, pb = split(src[p]) | |
| 122 | + new += [m for m in pm if m not in inside and m not in new] | |
| 123 | + text = h + pb | |
| 124 | + while text and not text[-1].strip(): text.pop() | |
| 125 | + while text and not text[0].strip(): text.pop(0) | |
| 126 | + close = [f"end {name}".rstrip() for kind, name in reversed(unclosed(text))] | |
| 127 | + out_parts.append([f"/-! ## From `{p}`", "", f"The text of `{p}`, folded into this file, which was its only importer. -/", "", "section", ""] + text + close + ["", "end", ""]) | |
| 128 | + # the host's own opening module docstring stays at the top | |
| 129 | + k = 0 | |
| 130 | + while k < len(body) and not body[k].strip(): k += 1 | |
| 131 | + lead = [] | |
| 132 | + if k < len(body) and body[k].startswith("/-!"): | |
| 133 | + depth, j = 0, k | |
| 134 | + while j < len(body): | |
| 135 | + depth = comment_depth(body[j], depth); j += 1 | |
| 136 | + if depth == 0: break | |
| 137 | + lead, body = body[k:j] + [""], body[j:] | |
| 138 | + out = head + [f"import {m}" for m in new] + [""] + lead | |
| 139 | + for part in out_parts: out += part | |
| 140 | + while body and not body[0].strip(): body = body[1:] | |
| 141 | + return "\n".join(out + body) | |
| 142 | + | |
| 143 | + | |
| 144 | +def apply(tree, pl): | |
| 145 | + src = read_tree(tree) | |
| 146 | + for host, parts in pl.items(): | |
| 147 | + text = folded(src, host, parts) | |
| 148 | + # every line of every folded file and of the host is still there (imports aside) | |
| 149 | + want = collections.Counter(l for p in parts for l in (lambda s: s[0] + s[2])(split(src[p])) if l.strip()) | |
| 150 | + have = collections.Counter(l for l in text.split("\n") if l.strip() and not IMPORT.match(l)) | |
| 151 | + assert not (want - have), (host, list((want - have).items())[:3]) | |
| 152 | + open(os.path.join(tree, host), "w", encoding="utf-8").write(text) | |
| 153 | + for p in parts[:-1]: os.remove(os.path.join(tree, p)) | |
| 154 | + | |
| 155 | + | |
| 156 | +def check(repo, pl, rev): | |
| 157 | + """the working tree against what `apply` makes of the revision's text: every changed file, byte for byte""" | |
| 158 | + show = lambda f: subprocess.run(["git", "-C", repo, "show", f"{rev}:{f}"], capture_output=True, text=True, check=True).stdout | |
| 159 | + bad = [] | |
| 160 | + for host, parts in pl.items(): | |
| 161 | + want = folded({p: show(p) for p in parts}, host, parts) | |
| 162 | + path = os.path.join(repo, host) | |
| 163 | + if not os.path.exists(path) or open(path, encoding="utf-8").read() != want: bad.append(f"{host} is not {rev}'s text folded") | |
| 164 | + bad += [f"{p} is still there" for p in parts[:-1] if os.path.exists(os.path.join(repo, p))] | |
| 165 | + print(f"ok: {len(pl)} files are {rev}'s text with {sum(len(p) - 1 for p in pl.values())} modules folded in, line for line" if not bad else "\n".join(bad)) | |
| 166 | + return 1 if bad else 0 | |
| 167 | + | |
| 168 | + | |
| 169 | +def self_test(): | |
| 170 | + src = {"Euler/FooA.lean": "import Mathlib.X\nimport Euler.FooB\nimport Euler.Bar\n\n/-! # A -/\n\nnoncomputable section\n\ntheorem a : True := trivial\n", | |
| 171 | + "Euler/FooB.lean": "import Mathlib.Y\nimport Euler.FooC\n\n/-! # B\nsection in a comment\n-/\nnoncomputable section\nopen Set\nnamespace Euler.B\ntheorem b : True := trivial\n", | |
| 172 | + "Euler/FooC.lean": "import Mathlib.X\n\ntheorem c : True := trivial\n", | |
| 173 | + "Euler/Bar.lean": "import Mathlib.X\n\ntheorem bar : True := trivial\n", | |
| 174 | + "Euler/FooSolution.lean": "import Euler.FooA\n"} | |
| 175 | + pl = plan(src, 100, 1000) | |
| 176 | + assert pl == {"Euler/FooA.lean": ["Euler/FooC.lean", "Euler/FooB.lean", "Euler/FooA.lean"]}, pl | |
| 177 | + t = folded(src, "Euler/FooA.lean", pl["Euler/FooA.lean"]) | |
| 178 | + assert t.startswith("import Mathlib.X\nimport Euler.Bar\nimport Mathlib.Y\n\n/-! # A -/\n"), t | |
| 179 | + assert "end Euler.B\nend\n\nend\n" in t and t.index("theorem c") < t.index("theorem b") < t.index("theorem a"), t | |
| 180 | + assert unclosed(src["Euler/FooB.lean"].split("\n")) == [("section", ""), ("namespace", "Euler.B")] | |
| 181 | + assert plan(src, 100, 1000, skip={"Euler/FooB.lean"}) == {} | |
| 182 | + assert plan(src, 2, 1000) == {}, plan(src, 2, 1000) | |
| 183 | + print("ok") | |
| 184 | + | |
| 185 | + | |
| 186 | +if __name__ == "__main__": | |
| 187 | + a = sys.argv[1:] | |
| 188 | + if a[:1] == ["self-test"]: self_test(); sys.exit(0) | |
| 189 | + opt = lambda n, d: (a[a.index(n) + 1] if n in a else d) | |
| 190 | + if a[0] == "plan": | |
| 191 | + src = read_tree(a[1]) | |
| 192 | + skip = set(open(opt("--skip", "")).read().split()) if "--skip" in a else set() | |
| 193 | + pl = plan(src, int(opt("--small", 200)), int(opt("--cap", 600)), skip) | |
| 194 | + json.dump(pl, open(a[2], "w"), indent=0) | |
| 195 | + n = sum(len(p) - 1 for p in pl.values()) | |
| 196 | + print(f"folds: {n} modules into {len(pl)} files in {len({fam(h) for h in pl})} families; largest file after: {max((sum(src[p].count(chr(10)) for p in ps), h) for h, ps in pl.items()) if pl else None}") | |
| 197 | + elif a[0] == "check": | |
| 198 | + sys.exit(check(a[1], json.load(open(a[2])), a[3] if len(a) > 3 else "origin/main")) | |
| 199 | + elif a[0] == "apply": | |
| 200 | + pl = json.load(open(a[2])); apply(a[1], pl); print("applied", sum(len(p) - 1 for p in pl.values()), "folds") | |
+11 −0 routes/s5-ns-generic-1/README.md added View file
| @@ -0,0 +1,11 @@ | ||
| 1 | +--- | |
| 2 | +issue: 14 | |
| 3 | +status: working | |
| 4 | +--- | |
| 5 | +# s5-ns-generic-1 | |
| 6 | + | |
| 7 | +One unit of S-5 (#14): the `NavierStokes/Generic*` family. Twelve small modules that exactly one file each imported are folded, text unchanged, into that file: `GenericSummationRealization.lean` takes eight, `GenericSupportLocalSummation.lean` one and `GenericSupportedPolynomial.lean` three. `plan.json` is here; the tool that does the fold and its pages are in `docs/s5-folding`. | |
| 8 | + | |
| 9 | +## Next | |
| 10 | + | |
| 11 | +The pull request is open. What comes next is the maintainer's verdict on whether this kind of change is wanted; the rest of the series' folds wait on it, one family per pull request. | |
+23 −0 routes/s5-ns-generic-1/plan.json added View file
| @@ -0,0 +1,23 @@ | ||
| 1 | +{ | |
| 2 | +"NavierStokes/GenericSummationRealization.lean": [ | |
| 3 | +"NavierStokes/GenericDiagonalSchedule.lean", | |
| 4 | +"NavierStokes/GenericRealization.lean", | |
| 5 | +"NavierStokes/GenericSolenoidalRealization.lean", | |
| 6 | +"NavierStokes/GenericVelocityRates.lean", | |
| 7 | +"NavierStokes/GenericTupleRealization.lean", | |
| 8 | +"NavierStokes/GenericAngularRecovery.lean", | |
| 9 | +"NavierStokes/GenericFactorSupport.lean", | |
| 10 | +"NavierStokes/GenericTupleSupport.lean", | |
| 11 | +"NavierStokes/GenericSummationRealization.lean" | |
| 12 | +], | |
| 13 | +"NavierStokes/GenericSupportLocalSummation.lean": [ | |
| 14 | +"NavierStokes/GenericSupportLocalCoefficients.lean", | |
| 15 | +"NavierStokes/GenericSupportLocalSummation.lean" | |
| 16 | +], | |
| 17 | +"NavierStokes/GenericSupportedPolynomial.lean": [ | |
| 18 | +"NavierStokes/GenericJetRateAlgebra.lean", | |
| 19 | +"NavierStokes/GenericDifferentialPolynomial.lean", | |
| 20 | +"NavierStokes/GenericRealizationBounds.lean", | |
| 21 | +"NavierStokes/GenericSupportedPolynomial.lean" | |
| 22 | +] | |
| 23 | +} | |