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

Comparing changes
Choose two branches to see what changed, then open a pull request to bring the work across.
Able to merge. These branches can be merged automatically.
A pull request is already open: #686 refactor(Euler/Heat): 2 small modules folded into the file that imports them (−8.0%, measured)
1 commit
+0 −55 Euler/HeatGradientIntegral.lean deleted
| @@ -1,55 +0,0 @@ | ||
| 1 | -import Euler.HeatGradientEnergy | |
| 2 | - | |
| 3 | -/-! Integrated genuine heat gradient energy, with the source measured only in L². -/ | |
| 4 | - | |
| 5 | -noncomputable section | |
| 6 | - | |
| 7 | -namespace EulerHeatGradientEnergy | |
| 8 | - | |
| 9 | -open MeasureTheory Set EulerLiftedGradientSpace EulerCylinderSobolevSpace | |
| 10 | - EulerSobolevLaplacian EulerSobolevHeatGenerator | |
| 11 | -open scoped Topology | |
| 12 | - | |
| 13 | -variable (period : ℝ) [Fact (0 < period)] | |
| 14 | - | |
| 15 | -/-- The actual integrated heat energy gains the full Laplacian in L² time without a source derivative in the bound. -/ | |
| 16 | -theorem heat_laplacian_integral_bound (u : ℝ → SobolevSpace period 3) | |
| 17 | - (f : ℝ → SobolevSpace period 1) (ν s t : ℝ) (hν : 0 < ν) (hst : s ≤ t) | |
| 18 | - (hu : ContinuousOn u (Icc s t)) (hf : ContinuousOn f (Icc s t)) | |
| 19 | - (hd : ∀ r ∈ Ioo s t, ∀ i : Fin 4, | |
| 20 | - HasDerivAt (fun a => value period (derivativeOperator period 2 i (u a))) | |
| 21 | - (value period (derivativeOperator period 0 i (ν • laplacianOperator period 1 (u r) + f r))) r) : | |
| 22 | - ν * (∫ r in s..t, ‖laplacianEvaluation period 3 (by norm_num) (u r)‖^2) ≤ | |
| 23 | - gradientEnergy period (restrictOperator period (by norm_num : 1 ≤ 3) (u s)) + | |
| 24 | - ν⁻¹ * (∫ r in s..t, ‖value period (f r)‖^2) := by | |
| 25 | - let G := fun r => gradientEnergy period (restrictOperator period (by norm_num : 1 ≤ 3) (u r)) | |
| 26 | - let L := fun r => ‖laplacianEvaluation period 3 (by norm_num) (u r)‖^2 | |
| 27 | - let F := fun r => ‖value period (f r)‖^2 | |
| 28 | - have hG : ContinuousOn G (Icc s t) := | |
| 29 | - (gradientEnergy_continuous period).comp_continuousOn | |
| 30 | - ((restrictOperator period (by norm_num : 1 ≤ 3)).continuous.comp_continuousOn hu) | |
| 31 | - have hL : ContinuousOn L (Icc s t) := | |
| 32 | - (((laplacianEvaluation period 3 (by norm_num)).continuous.comp_continuousOn hu).norm).pow 2 | |
| 33 | - have hF : ContinuousOn F (Icc s t) := | |
| 34 | - (((valueOperator period 1).continuous.comp_continuousOn hf).norm).pow 2 | |
| 35 | - have hLi : IntervalIntegrable L volume s t := hL.intervalIntegrable_of_Icc hst | |
| 36 | - have hFi : IntervalIntegrable F volume s t := hF.intervalIntegrable_of_Icc hst | |
| 37 | - have hφ : IntegrableOn (fun r => -ν * L r + ν⁻¹ * F r) (Icc s t) := | |
| 38 | - ((hL.const_mul (-ν)).add (hF.const_mul ν⁻¹)).integrableOn_Icc | |
| 39 | - have hdiff : ∀ r ∈ Ioo s t, HasDerivAt G (deriv G r) r := by | |
| 40 | - intro r hr | |
| 41 | - exact (heat_gradient_energy_hasDerivAt period u (f r) ν r (hd r hr)).differentiableAt.hasDerivAt | |
| 42 | - have hb : ∀ r ∈ Ioo s t, deriv G r ≤ -ν * L r + ν⁻¹ * F r := by | |
| 43 | - intro r hr | |
| 44 | - exact heat_gradient_energy_bound period u (f r) ν r hν (hd r hr) | |
| 45 | - have hi := intervalIntegral.sub_le_integral_of_hasDeriv_right_of_le hst hG | |
| 46 | - (fun r hr => (hdiff r hr).hasDerivWithinAt) hφ hb | |
| 47 | - rw [intervalIntegral.integral_add (hLi.const_mul (-ν)) (hFi.const_mul ν⁻¹), | |
| 48 | - intervalIntegral.integral_const_mul, intervalIntegral.integral_const_mul] at hi | |
| 49 | - have hnonneg := gradientEnergy_nonneg period (restrictOperator period (by norm_num : 1 ≤ 3) (u t)) | |
| 50 | - change G t - G s ≤ -ν * (∫ r in s..t, L r) + ν⁻¹ * (∫ r in s..t, F r) at hi | |
| 51 | - change 0 ≤ G t at hnonneg | |
| 52 | - change ν * (∫ r in s..t, L r) ≤ G s + ν⁻¹ * (∫ r in s..t, F r) | |
| 53 | - linarith | |
| 54 | - | |
| 55 | -end EulerHeatGradientEnergy | |
+171 −1 Euler/HeatMaximalCauchy.lean View file
| @@ -1,8 +1,178 @@ | ||
| 1 | -import Euler.HeatMaximalEstimate | |
| 1 | +import Euler.HeatGradientEnergy | |
| 2 | +import Euler.SobolevEllipticBound | |
| 3 | +import Euler.TimeLp | |
| 2 | 4 | import Euler.QuadraticCauchy |
| 3 | 5 | |
| 4 | 6 | /-! Strong L²-time H² Cauchy convergence from genuine heat energy, avoiding weak compactness. -/ |
| 5 | 7 | |
| 8 | +/-! ## From `Euler/HeatGradientIntegral.lean` | |
| 9 | + | |
| 10 | +The text of `Euler/HeatGradientIntegral.lean`, folded into this file, which was its only importer. -/ | |
| 11 | + | |
| 12 | +section | |
| 13 | + | |
| 14 | +/-! Integrated genuine heat gradient energy, with the source measured only in L². -/ | |
| 15 | + | |
| 16 | +noncomputable section | |
| 17 | + | |
| 18 | +namespace EulerHeatGradientEnergy | |
| 19 | + | |
| 20 | +open MeasureTheory Set EulerLiftedGradientSpace EulerCylinderSobolevSpace | |
| 21 | + EulerSobolevLaplacian EulerSobolevHeatGenerator | |
| 22 | +open scoped Topology | |
| 23 | + | |
| 24 | +variable (period : ℝ) [Fact (0 < period)] | |
| 25 | + | |
| 26 | +/-- The actual integrated heat energy gains the full Laplacian in L² time without a source derivative in the bound. -/ | |
| 27 | +theorem heat_laplacian_integral_bound (u : ℝ → SobolevSpace period 3) | |
| 28 | + (f : ℝ → SobolevSpace period 1) (ν s t : ℝ) (hν : 0 < ν) (hst : s ≤ t) | |
| 29 | + (hu : ContinuousOn u (Icc s t)) (hf : ContinuousOn f (Icc s t)) | |
| 30 | + (hd : ∀ r ∈ Ioo s t, ∀ i : Fin 4, | |
| 31 | + HasDerivAt (fun a => value period (derivativeOperator period 2 i (u a))) | |
| 32 | + (value period (derivativeOperator period 0 i (ν • laplacianOperator period 1 (u r) + f r))) r) : | |
| 33 | + ν * (∫ r in s..t, ‖laplacianEvaluation period 3 (by norm_num) (u r)‖^2) ≤ | |
| 34 | + gradientEnergy period (restrictOperator period (by norm_num : 1 ≤ 3) (u s)) + | |
| 35 | + ν⁻¹ * (∫ r in s..t, ‖value period (f r)‖^2) := by | |
| 36 | + let G := fun r => gradientEnergy period (restrictOperator period (by norm_num : 1 ≤ 3) (u r)) | |
| 37 | + let L := fun r => ‖laplacianEvaluation period 3 (by norm_num) (u r)‖^2 | |
| 38 | + let F := fun r => ‖value period (f r)‖^2 | |
| 39 | + have hG : ContinuousOn G (Icc s t) := | |
| 40 | + (gradientEnergy_continuous period).comp_continuousOn | |
| 41 | + ((restrictOperator period (by norm_num : 1 ≤ 3)).continuous.comp_continuousOn hu) | |
| 42 | + have hL : ContinuousOn L (Icc s t) := | |
| 43 | + (((laplacianEvaluation period 3 (by norm_num)).continuous.comp_continuousOn hu).norm).pow 2 | |
| 44 | + have hF : ContinuousOn F (Icc s t) := | |
| 45 | + (((valueOperator period 1).continuous.comp_continuousOn hf).norm).pow 2 | |
| 46 | + have hLi : IntervalIntegrable L volume s t := hL.intervalIntegrable_of_Icc hst | |
| 47 | + have hFi : IntervalIntegrable F volume s t := hF.intervalIntegrable_of_Icc hst | |
| 48 | + have hφ : IntegrableOn (fun r => -ν * L r + ν⁻¹ * F r) (Icc s t) := | |
| 49 | + ((hL.const_mul (-ν)).add (hF.const_mul ν⁻¹)).integrableOn_Icc | |
| 50 | + have hdiff : ∀ r ∈ Ioo s t, HasDerivAt G (deriv G r) r := by | |
| 51 | + intro r hr | |
| 52 | + exact (heat_gradient_energy_hasDerivAt period u (f r) ν r (hd r hr)).differentiableAt.hasDerivAt | |
| 53 | + have hb : ∀ r ∈ Ioo s t, deriv G r ≤ -ν * L r + ν⁻¹ * F r := by | |
| 54 | + intro r hr | |
| 55 | + exact heat_gradient_energy_bound period u (f r) ν r hν (hd r hr) | |
| 56 | + have hi := intervalIntegral.sub_le_integral_of_hasDeriv_right_of_le hst hG | |
| 57 | + (fun r hr => (hdiff r hr).hasDerivWithinAt) hφ hb | |
| 58 | + rw [intervalIntegral.integral_add (hLi.const_mul (-ν)) (hFi.const_mul ν⁻¹), | |
| 59 | + intervalIntegral.integral_const_mul, intervalIntegral.integral_const_mul] at hi | |
| 60 | + have hnonneg := gradientEnergy_nonneg period (restrictOperator period (by norm_num : 1 ≤ 3) (u t)) | |
| 61 | + change G t - G s ≤ -ν * (∫ r in s..t, L r) + ν⁻¹ * (∫ r in s..t, F r) at hi | |
| 62 | + change 0 ≤ G t at hnonneg | |
| 63 | + change ν * (∫ r in s..t, L r) ≤ G s + ν⁻¹ * (∫ r in s..t, F r) | |
| 64 | + linarith | |
| 65 | + | |
| 66 | +end EulerHeatGradientEnergy | |
| 67 | +end | |
| 68 | + | |
| 69 | +end | |
| 70 | + | |
| 71 | +/-! ## From `Euler/HeatMaximalEstimate.lean` | |
| 72 | + | |
| 73 | +The text of `Euler/HeatMaximalEstimate.lean`, folded into this file, which was its only importer. -/ | |
| 74 | + | |
| 75 | +section | |
| 76 | + | |
| 77 | +/-! A genuine L²-time H² estimate for regularized heat solutions, with only L² forcing. -/ | |
| 78 | + | |
| 79 | +noncomputable section | |
| 80 | + | |
| 81 | +namespace EulerHeatMaximalEstimate | |
| 82 | + | |
| 83 | +open MeasureTheory Set EulerLiftedGradientSpace EulerCylinderSobolevSpace EulerSobolevLaplacian | |
| 84 | + EulerSobolevHeatGenerator EulerHeatGradientEnergy EulerSobolevEllipticBound EulerTimeLp | |
| 85 | + EulerVolterraConvolution | |
| 86 | +open scoped Topology | |
| 87 | + | |
| 88 | +variable (period : ℝ) [Fact (0 < period)] | |
| 89 | + | |
| 90 | +/-- The actual gradient energy is bounded by four times the complete H¹ norm squared. -/ | |
| 91 | +theorem gradientEnergy_bound (u : SobolevSpace period 1) : gradientEnergy period u ≤ 4*‖u‖^2 := by | |
| 92 | + unfold gradientEnergy | |
| 93 | + calc | |
| 94 | + _ ≤ ∑ _i : Fin 4, ‖u‖^2 := Finset.sum_le_sum fun i _ => by | |
| 95 | + have h := (value_norm_le period (derivativeOperator period 0 i u)).trans (derivativeOperator_bound period i u) | |
| 96 | + nlinarith [norm_nonneg (value period (derivativeOperator period 0 i u)), norm_nonneg u] | |
| 97 | + _ = _ := by simp | |
| 98 | + | |
| 99 | +omit [Fact (0 < period)] in | |
| 100 | +/-- Integrating a continuous scalar upper bound by a constant plus another continuous function. -/ | |
| 101 | +theorem integral_le_constant_add (f g : ℝ → ℝ) (c T : ℝ) (hT : 0 ≤ T) | |
| 102 | + (hf : Continuous f) (hg : Continuous g) (hfg : ∀ t ∈ Icc 0 T, f t ≤ c + g t) : | |
| 103 | + (∫ t in (0 : ℝ)..T, f t) ≤ T*c + ∫ t in (0 : ℝ)..T, g t := by | |
| 104 | + have h := intervalIntegral.integral_mono_on hT (hf.intervalIntegrable (μ := volume) 0 T) | |
| 105 | + (((continuous_const (y := c)).add hg).intervalIntegrable (μ := volume) 0 T) hfg | |
| 106 | + change (∫ t in (0 : ℝ)..T, f t) ≤ ∫ t in (0 : ℝ)..T, c + g t at h | |
| 107 | + rw [intervalIntegral.integral_add (intervalIntegrable_const) (hg.intervalIntegrable (μ := volume) 0 T), | |
| 108 | + intervalIntegral.integral_const] at h | |
| 109 | + simpa only [sub_zero, smul_eq_mul] using h | |
| 110 | + | |
| 111 | +/-- The actual pointwise elliptic estimate with the lower Sobolev path norm as a uniform bound. -/ | |
| 112 | +theorem path_H2_point_bound (T : ℝ) (hT : 0 ≤ T) (u : C(Icc (0 : ℝ) T, SobolevSpace period 3)) (t : ℝ) : | |
| 113 | + ‖truncateOperator period 2 (extendPath T hT u t)‖^2 ≤ | |
| 114 | + ‖(restrictOperator period (by norm_num : 1 ≤ 3)).compLeftContinuous ℝ (Icc (0 : ℝ) T) u‖^2 + | |
| 115 | + ‖laplacianEvaluation period 3 (by norm_num) (extendPath T hT u t)‖^2 := by | |
| 116 | + let low := (restrictOperator period (by norm_num : 1 ≤ 3)).compLeftContinuous ℝ (Icc (0 : ℝ) T) u | |
| 117 | + have h := H2_norm_sq_le_laplacian period (extendPath T hT u t) | |
| 118 | + have hl := extendPath_norm_le T hT low t | |
| 119 | + change ‖restrictOperator period (by norm_num : 1 ≤ 3) (extendPath T hT u t)‖ ≤ ‖low‖ at hl | |
| 120 | + change _ ≤ ‖low‖^2 + _ | |
| 121 | + nlinarith [norm_nonneg (restrictOperator period (by norm_num : 1 ≤ 3) (extendPath T hT u t)), norm_nonneg low] | |
| 122 | + | |
| 123 | +/-- The actual H² time norm is bounded by the H¹ path norm and the genuine Laplacian time integral. -/ | |
| 124 | +theorem time_H2_elliptic_bound (T : ℝ) (hT : 0 ≤ T) (u : C(Icc (0 : ℝ) T, SobolevSpace period 3)) : | |
| 125 | + ‖pathLp T hT ((truncateOperator period 2).compLeftContinuous ℝ (Icc (0 : ℝ) T) u)‖^2 ≤ | |
| 126 | + T * ‖(restrictOperator period (by norm_num : 1 ≤ 3)).compLeftContinuous ℝ (Icc (0 : ℝ) T) u‖^2 + | |
| 127 | + ∫ t in (0 : ℝ)..T, ‖laplacianEvaluation period 3 (by norm_num) (extendPath T hT u t)‖^2 := by | |
| 128 | + let high := (truncateOperator period 2).compLeftContinuous ℝ (Icc (0 : ℝ) T) u | |
| 129 | + have hhigh : Continuous (fun t => ‖extendPath T hT high t‖^2) := | |
| 130 | + ((extendPath_continuous T hT high).norm).pow 2 | |
| 131 | + have hLap : Continuous (fun t => ‖laplacianEvaluation period 3 (by norm_num) (extendPath T hT u t)‖^2) := | |
| 132 | + (((laplacianEvaluation period 3 (by norm_num)).continuous.comp (extendPath_continuous T hT u)).norm).pow 2 | |
| 133 | + rw [pathLp_norm_sq] | |
| 134 | + exact integral_le_constant_add _ _ _ T hT hhigh hLap (fun t _ => path_H2_point_bound period T hT u t) | |
| 135 | + | |
| 136 | +/-- The true heat PDE bounds the full L²-time H² norm by H¹ data and undifferentiated L² forcing. -/ | |
| 137 | +theorem heat_time_H2_bound (T : ℝ) (hT : 0 ≤ T) (ν : ℝ) (hν : 0 < ν) | |
| 138 | + (u : C(Icc (0 : ℝ) T, SobolevSpace period 3)) | |
| 139 | + (f : C(Icc (0 : ℝ) T, SobolevSpace period 1)) | |
| 140 | + (hd : ∀ t ∈ Ioo 0 T, ∀ i : Fin 4, | |
| 141 | + HasDerivAt (fun s => value period (derivativeOperator period 2 i (extendPath T hT u s))) | |
| 142 | + (value period (derivativeOperator period 0 i | |
| 143 | + (ν • laplacianOperator period 1 (extendPath T hT u t) + extendPath T hT f t))) t) : | |
| 144 | + ‖pathLp T hT ((truncateOperator period 2).compLeftContinuous ℝ (Icc (0 : ℝ) T) u)‖^2 ≤ | |
| 145 | + (T + 4*ν⁻¹) * ‖(restrictOperator period (by norm_num : 1 ≤ 3)).compLeftContinuous ℝ (Icc (0 : ℝ) T) u‖^2 + | |
| 146 | + (ν⁻¹)^2 * ‖pathLp T hT ((valueOperator period 1).compLeftContinuous ℝ (Icc (0 : ℝ) T) f)‖^2 := by | |
| 147 | + let low := (restrictOperator period (by norm_num : 1 ≤ 3)).compLeftContinuous ℝ (Icc (0 : ℝ) T) u | |
| 148 | + let source := (valueOperator period 1).compLeftContinuous ℝ (Icc (0 : ℝ) T) f | |
| 149 | + let L := ∫ t in (0 : ℝ)..T, ‖laplacianEvaluation period 3 (by norm_num) (extendPath T hT u t)‖^2 | |
| 150 | + have he := heat_laplacian_integral_bound period (extendPath T hT u) (extendPath T hT f) ν 0 T hν hT | |
| 151 | + (extendPath_continuous T hT u).continuousOn (extendPath_continuous T hT f).continuousOn hd | |
| 152 | + have hb := gradientEnergy_bound period (restrictOperator period (by norm_num : 1 ≤ 3) (extendPath T hT u 0)) | |
| 153 | + have hl := extendPath_norm_le T hT low 0 | |
| 154 | + change ‖restrictOperator period (by norm_num : 1 ≤ 3) (extendPath T hT u 0)‖ ≤ ‖low‖ at hl | |
| 155 | + have hinit : gradientEnergy period (restrictOperator period (by norm_num : 1 ≤ 3) (extendPath T hT u 0)) ≤ 4*‖low‖^2 := by | |
| 156 | + nlinarith [norm_nonneg (restrictOperator period (by norm_num : 1 ≤ 3) (extendPath T hT u 0)), norm_nonneg low] | |
| 157 | + have hs : (∫ t in (0 : ℝ)..T, ‖value period (extendPath T hT f t)‖^2) = ‖pathLp T hT source‖^2 := | |
| 158 | + (pathLp_norm_sq T hT source).symm | |
| 159 | + rw [hs] at he | |
| 160 | + have hL : L ≤ 4*ν⁻¹*‖low‖^2 + (ν⁻¹)^2*‖pathLp T hT source‖^2 := by | |
| 161 | + calc | |
| 162 | + L = ν⁻¹*(ν*L) := by rw [← mul_assoc, inv_mul_cancel₀ hν.ne', one_mul] | |
| 163 | + _ ≤ ν⁻¹*(4*‖low‖^2 + ν⁻¹*‖pathLp T hT source‖^2) := | |
| 164 | + mul_le_mul_of_nonneg_left (he.trans (add_le_add hinit le_rfl)) (inv_nonneg.mpr hν.le) | |
| 165 | + _ = _ := by ring | |
| 166 | + have hb2 := time_H2_elliptic_bound period T hT u | |
| 167 | + change _ ≤ T*‖low‖^2 + L at hb2 | |
| 168 | + change _ ≤ (T+4*ν⁻¹)*‖low‖^2 + (ν⁻¹)^2*‖pathLp T hT source‖^2 | |
| 169 | + linarith | |
| 170 | + | |
| 171 | +end EulerHeatMaximalEstimate | |
| 172 | +end | |
| 173 | + | |
| 174 | +end | |
| 175 | + | |
| 6 | 176 | noncomputable section |
| 7 | 177 | |
| 8 | 178 | namespace EulerHeatMaximalCauchy |
+0 −99 Euler/HeatMaximalEstimate.lean deleted
| @@ -1,99 +0,0 @@ | ||
| 1 | -import Euler.HeatGradientIntegral | |
| 2 | -import Euler.SobolevEllipticBound | |
| 3 | -import Euler.TimeLp | |
| 4 | - | |
| 5 | -/-! A genuine L²-time H² estimate for regularized heat solutions, with only L² forcing. -/ | |
| 6 | - | |
| 7 | -noncomputable section | |
| 8 | - | |
| 9 | -namespace EulerHeatMaximalEstimate | |
| 10 | - | |
| 11 | -open MeasureTheory Set EulerLiftedGradientSpace EulerCylinderSobolevSpace EulerSobolevLaplacian | |
| 12 | - EulerSobolevHeatGenerator EulerHeatGradientEnergy EulerSobolevEllipticBound EulerTimeLp | |
| 13 | - EulerVolterraConvolution | |
| 14 | -open scoped Topology | |
| 15 | - | |
| 16 | -variable (period : ℝ) [Fact (0 < period)] | |
| 17 | - | |
| 18 | -/-- The actual gradient energy is bounded by four times the complete H¹ norm squared. -/ | |
| 19 | -theorem gradientEnergy_bound (u : SobolevSpace period 1) : gradientEnergy period u ≤ 4*‖u‖^2 := by | |
| 20 | - unfold gradientEnergy | |
| 21 | - calc | |
| 22 | - _ ≤ ∑ _i : Fin 4, ‖u‖^2 := Finset.sum_le_sum fun i _ => by | |
| 23 | - have h := (value_norm_le period (derivativeOperator period 0 i u)).trans (derivativeOperator_bound period i u) | |
| 24 | - nlinarith [norm_nonneg (value period (derivativeOperator period 0 i u)), norm_nonneg u] | |
| 25 | - _ = _ := by simp | |
| 26 | - | |
| 27 | -omit [Fact (0 < period)] in | |
| 28 | -/-- Integrating a continuous scalar upper bound by a constant plus another continuous function. -/ | |
| 29 | -theorem integral_le_constant_add (f g : ℝ → ℝ) (c T : ℝ) (hT : 0 ≤ T) | |
| 30 | - (hf : Continuous f) (hg : Continuous g) (hfg : ∀ t ∈ Icc 0 T, f t ≤ c + g t) : | |
| 31 | - (∫ t in (0 : ℝ)..T, f t) ≤ T*c + ∫ t in (0 : ℝ)..T, g t := by | |
| 32 | - have h := intervalIntegral.integral_mono_on hT (hf.intervalIntegrable (μ := volume) 0 T) | |
| 33 | - (((continuous_const (y := c)).add hg).intervalIntegrable (μ := volume) 0 T) hfg | |
| 34 | - change (∫ t in (0 : ℝ)..T, f t) ≤ ∫ t in (0 : ℝ)..T, c + g t at h | |
| 35 | - rw [intervalIntegral.integral_add (intervalIntegrable_const) (hg.intervalIntegrable (μ := volume) 0 T), | |
| 36 | - intervalIntegral.integral_const] at h | |
| 37 | - simpa only [sub_zero, smul_eq_mul] using h | |
| 38 | - | |
| 39 | -/-- The actual pointwise elliptic estimate with the lower Sobolev path norm as a uniform bound. -/ | |
| 40 | -theorem path_H2_point_bound (T : ℝ) (hT : 0 ≤ T) (u : C(Icc (0 : ℝ) T, SobolevSpace period 3)) (t : ℝ) : | |
| 41 | - ‖truncateOperator period 2 (extendPath T hT u t)‖^2 ≤ | |
| 42 | - ‖(restrictOperator period (by norm_num : 1 ≤ 3)).compLeftContinuous ℝ (Icc (0 : ℝ) T) u‖^2 + | |
| 43 | - ‖laplacianEvaluation period 3 (by norm_num) (extendPath T hT u t)‖^2 := by | |
| 44 | - let low := (restrictOperator period (by norm_num : 1 ≤ 3)).compLeftContinuous ℝ (Icc (0 : ℝ) T) u | |
| 45 | - have h := H2_norm_sq_le_laplacian period (extendPath T hT u t) | |
| 46 | - have hl := extendPath_norm_le T hT low t | |
| 47 | - change ‖restrictOperator period (by norm_num : 1 ≤ 3) (extendPath T hT u t)‖ ≤ ‖low‖ at hl | |
| 48 | - change _ ≤ ‖low‖^2 + _ | |
| 49 | - nlinarith [norm_nonneg (restrictOperator period (by norm_num : 1 ≤ 3) (extendPath T hT u t)), norm_nonneg low] | |
| 50 | - | |
| 51 | -/-- The actual H² time norm is bounded by the H¹ path norm and the genuine Laplacian time integral. -/ | |
| 52 | -theorem time_H2_elliptic_bound (T : ℝ) (hT : 0 ≤ T) (u : C(Icc (0 : ℝ) T, SobolevSpace period 3)) : | |
| 53 | - ‖pathLp T hT ((truncateOperator period 2).compLeftContinuous ℝ (Icc (0 : ℝ) T) u)‖^2 ≤ | |
| 54 | - T * ‖(restrictOperator period (by norm_num : 1 ≤ 3)).compLeftContinuous ℝ (Icc (0 : ℝ) T) u‖^2 + | |
| 55 | - ∫ t in (0 : ℝ)..T, ‖laplacianEvaluation period 3 (by norm_num) (extendPath T hT u t)‖^2 := by | |
| 56 | - let high := (truncateOperator period 2).compLeftContinuous ℝ (Icc (0 : ℝ) T) u | |
| 57 | - have hhigh : Continuous (fun t => ‖extendPath T hT high t‖^2) := | |
| 58 | - ((extendPath_continuous T hT high).norm).pow 2 | |
| 59 | - have hLap : Continuous (fun t => ‖laplacianEvaluation period 3 (by norm_num) (extendPath T hT u t)‖^2) := | |
| 60 | - (((laplacianEvaluation period 3 (by norm_num)).continuous.comp (extendPath_continuous T hT u)).norm).pow 2 | |
| 61 | - rw [pathLp_norm_sq] | |
| 62 | - exact integral_le_constant_add _ _ _ T hT hhigh hLap (fun t _ => path_H2_point_bound period T hT u t) | |
| 63 | - | |
| 64 | -/-- The true heat PDE bounds the full L²-time H² norm by H¹ data and undifferentiated L² forcing. -/ | |
| 65 | -theorem heat_time_H2_bound (T : ℝ) (hT : 0 ≤ T) (ν : ℝ) (hν : 0 < ν) | |
| 66 | - (u : C(Icc (0 : ℝ) T, SobolevSpace period 3)) | |
| 67 | - (f : C(Icc (0 : ℝ) T, SobolevSpace period 1)) | |
| 68 | - (hd : ∀ t ∈ Ioo 0 T, ∀ i : Fin 4, | |
| 69 | - HasDerivAt (fun s => value period (derivativeOperator period 2 i (extendPath T hT u s))) | |
| 70 | - (value period (derivativeOperator period 0 i | |
| 71 | - (ν • laplacianOperator period 1 (extendPath T hT u t) + extendPath T hT f t))) t) : | |
| 72 | - ‖pathLp T hT ((truncateOperator period 2).compLeftContinuous ℝ (Icc (0 : ℝ) T) u)‖^2 ≤ | |
| 73 | - (T + 4*ν⁻¹) * ‖(restrictOperator period (by norm_num : 1 ≤ 3)).compLeftContinuous ℝ (Icc (0 : ℝ) T) u‖^2 + | |
| 74 | - (ν⁻¹)^2 * ‖pathLp T hT ((valueOperator period 1).compLeftContinuous ℝ (Icc (0 : ℝ) T) f)‖^2 := by | |
| 75 | - let low := (restrictOperator period (by norm_num : 1 ≤ 3)).compLeftContinuous ℝ (Icc (0 : ℝ) T) u | |
| 76 | - let source := (valueOperator period 1).compLeftContinuous ℝ (Icc (0 : ℝ) T) f | |
| 77 | - let L := ∫ t in (0 : ℝ)..T, ‖laplacianEvaluation period 3 (by norm_num) (extendPath T hT u t)‖^2 | |
| 78 | - have he := heat_laplacian_integral_bound period (extendPath T hT u) (extendPath T hT f) ν 0 T hν hT | |
| 79 | - (extendPath_continuous T hT u).continuousOn (extendPath_continuous T hT f).continuousOn hd | |
| 80 | - have hb := gradientEnergy_bound period (restrictOperator period (by norm_num : 1 ≤ 3) (extendPath T hT u 0)) | |
| 81 | - have hl := extendPath_norm_le T hT low 0 | |
| 82 | - change ‖restrictOperator period (by norm_num : 1 ≤ 3) (extendPath T hT u 0)‖ ≤ ‖low‖ at hl | |
| 83 | - have hinit : gradientEnergy period (restrictOperator period (by norm_num : 1 ≤ 3) (extendPath T hT u 0)) ≤ 4*‖low‖^2 := by | |
| 84 | - nlinarith [norm_nonneg (restrictOperator period (by norm_num : 1 ≤ 3) (extendPath T hT u 0)), norm_nonneg low] | |
| 85 | - have hs : (∫ t in (0 : ℝ)..T, ‖value period (extendPath T hT f t)‖^2) = ‖pathLp T hT source‖^2 := | |
| 86 | - (pathLp_norm_sq T hT source).symm | |
| 87 | - rw [hs] at he | |
| 88 | - have hL : L ≤ 4*ν⁻¹*‖low‖^2 + (ν⁻¹)^2*‖pathLp T hT source‖^2 := by | |
| 89 | - calc | |
| 90 | - L = ν⁻¹*(ν*L) := by rw [← mul_assoc, inv_mul_cancel₀ hν.ne', one_mul] | |
| 91 | - _ ≤ ν⁻¹*(4*‖low‖^2 + ν⁻¹*‖pathLp T hT source‖^2) := | |
| 92 | - mul_le_mul_of_nonneg_left (he.trans (add_le_add hinit le_rfl)) (inv_nonneg.mpr hν.le) | |
| 93 | - _ = _ := by ring | |
| 94 | - have hb2 := time_H2_elliptic_bound period T hT u | |
| 95 | - change _ ≤ T*‖low‖^2 + L at hb2 | |
| 96 | - change _ ≤ (T+4*ν⁻¹)*‖low‖^2 + (ν⁻¹)^2*‖pathLp T hT source‖^2 | |
| 97 | - linarith | |
| 98 | - | |
| 99 | -end EulerHeatMaximalEstimate | |
+75 −0 docs/s5-folding/ContentTail.lean added View file
| @@ -0,0 +1,75 @@ | ||
| 1 | + | |
| 2 | +-- Every named constant of the two libraries with a hash of its type (and of its value when it is a definition) in which | |
| 3 | +-- an auxiliary constant counts by what it is, not by what it is called: private declarations, nested-proof lemmas, | |
| 4 | +-- matchers and automatically named local instances get their names from the module and from the order of elaboration, | |
| 5 | +-- and a fold changes both. A theorem met inside a term counts by its statement alone. | |
| 6 | +open Lean | |
| 7 | + | |
| 8 | +namespace FoldCheck | |
| 9 | + | |
| 10 | +def isAux (n : Name) : Bool := | |
| 11 | + n.components.any fun c => match c with | |
| 12 | + | .str _ s => s.startsWith "_" || (s.startsWith "match_" && (s.drop 6).all Char.isDigit) || (s.startsWith "proof_" && (s.drop 6).all Char.isDigit) | |
| 13 | + | .num _ _ => true | |
| 14 | + | .anonymous => false | |
| 15 | + | |
| 16 | +def userName (n : Name) : Name := | |
| 17 | + if isPrivateName n then ((n.components.dropWhile fun c => !c.isNum).drop 1).foldl (· ++ ·) `_private else n | |
| 18 | + | |
| 19 | +abbrev M := StateM (Std.HashMap Name UInt64 × Std.HashSet Name) | |
| 20 | + | |
| 21 | +mutual | |
| 22 | + partial def constHash (env : Environment) (n : Name) : M UInt64 := do | |
| 23 | + if let some h := (← get).1[n]? then return h | |
| 24 | + if (← get).2.contains n then return hash (userName n) | |
| 25 | + let some ci := env.find? n | return hash (userName n) | |
| 26 | + modify fun (m, v) => (m, v.insert n) | |
| 27 | + let th ← exprHash env ci.type | |
| 28 | + let (k, vh) ← match ci with | |
| 29 | + | .thmInfo _ => pure ((1 : UInt64), (0 : UInt64)) | |
| 30 | + | .defnInfo d => do pure (2, ← exprHash env d.value) | |
| 31 | + | .opaqueInfo d => do pure (3, ← exprHash env d.value) | |
| 32 | + | .ctorInfo c => pure (4, c.cidx.toUInt64) | |
| 33 | + | .inductInfo _ => pure (5, 0) | |
| 34 | + | .recInfo _ => pure (6, 0) | |
| 35 | + | _ => pure (7, 0) | |
| 36 | + let h := mixHash k (mixHash th vh) | |
| 37 | + modify fun (m, v) => (m.insert n h, v.erase n) | |
| 38 | + return h | |
| 39 | + partial def exprHash (env : Environment) (e : Expr) : M UInt64 := do | |
| 40 | + for u in e.getUsedConstants do | |
| 41 | + if isAux u then discard <| constHash env u | |
| 42 | + let memo := (← get).1 | |
| 43 | + let e' := e.replace fun | |
| 44 | + | .const n ls => if isAux n then some (.const (Name.mkNum `_h (memo.getD n 0).toNat) ls) else none | |
| 45 | + | _ => none | |
| 46 | + return e'.hash | |
| 47 | +end | |
| 48 | + | |
| 49 | +end FoldCheck | |
| 50 | + | |
| 51 | +open FoldCheck in | |
| 52 | +#eval show CoreM Unit from do | |
| 53 | + let env ← getEnv | |
| 54 | + let mods := env.header.moduleNames | |
| 55 | + let proj (m : Name) : Bool := m.getRoot == `NavierStokes || m.getRoot == `Euler | |
| 56 | + let h ← IO.FS.Handle.mk "/out/content.tsv" IO.FS.Mode.write | |
| 57 | + let mut st : Std.HashMap Name UInt64 × Std.HashSet Name := ({}, {}) | |
| 58 | + let mut n := 0 | |
| 59 | + for (c, ci) in env.constants.map₁.toList do | |
| 60 | + let some idx := env.getModuleIdxFor? c | continue | |
| 61 | + unless proj mods[idx.toNat]! do continue | |
| 62 | + if isAux c then continue | |
| 63 | + let (th, st1) := (exprHash env ci.type).run st | |
| 64 | + st := st1 | |
| 65 | + let mut v := "-" | |
| 66 | + match ci with | |
| 67 | + | .defnInfo d => let (vh, st2) := (exprHash env d.value).run st; st := st2; v := toString vh | |
| 68 | + | .opaqueInfo d => let (vh, st2) := (exprHash env d.value).run st; st := st2; v := toString vh | |
| 69 | + | _ => pure () | |
| 70 | + let kind := match ci with | |
| 71 | + | .thmInfo _ => "theorem" | .defnInfo _ => "def" | .axiomInfo _ => "axiom" | .opaqueInfo _ => "opaque" | |
| 72 | + | .inductInfo _ => "inductive" | .ctorInfo _ => "ctor" | .recInfo _ => "rec" | .quotInfo _ => "quot" | |
| 73 | + h.putStrLn s!"{c}\t{kind}\t{th}\t{v}" | |
| 74 | + n := n + 1 | |
| 75 | + IO.println s!"{n} named constants written" | |
+12 −0 docs/s5-folding/README.md View file
| @@ -101,3 +101,15 @@ Each pull request of the series keeps its plan in its route notes (`routes/<bran | ||
| 101 | 101 | ## What this does not show |
| 102 | 102 | |
| 103 | 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). |
| 104 | + | |
| 105 | +## Statements, and the series as it was opened | |
| 106 | + | |
| 107 | +The first pull request of the series was cut from a plan of 582 folds. Before the others were opened, main and the folded tree were both built and every named constant of the two libraries was listed with a hash of its type and, for a definition, of its value (`ContentTail.lean`, after one `import` line a module). In that listing an auxiliary constant inside a term (a private declaration, a nested-proof lemma, an automatically named local instance) counts by what it is, not by its name, and a theorem by its statement: a fold changes the names of such constants and nothing else about them. | |
| 108 | + | |
| 109 | +The first plan did not pass. Of 53,802 named constants, 12 differed. In one, `Euler.ComparatorBridge.compactSolenoidalTests_representation`, the word `divergence` resolved to `Euler.divergence` in the folded file and to `EulerSmoothLimit.divergence` on main: once folded, the text saw more names. The build passed all the same. In the others an instance was found by another path (`NormedCommRing ℂ` through the C⋆-algebra instances, `DistribSMul ℝ` through the semiring), or a proof inside the statement differed. | |
| 110 | + | |
| 111 | +Two changes followed. `fold.py` now puts a folded module's imports where its import line stood, so that every other module is loaded in the order it was loaded before (a plan file says which way it was cut, and `check` follows it, so the first pull request still checks). And five files keep their modules: `Euler/CompactProjectedEulerLaw.lean`, `Euler/CylinderJetLpAlgebra.lean`, `Euler/MeanCutoffDifferenceBound.lean`, `NavierStokes/R3/CompactEnergy.lean`, `NavierStokes/R3/PressureRecovery.lean`. | |
| 112 | + | |
| 113 | +The series as opened is 575 folds into 338 files. On it the two listings are equal: 53,802 named constants, none missing, none with another type or value; the first pull request's twelve folds were checked alone and are equal too. The whole tree goes from 54.73 T instructions over 2,587 files to 50.97 T over 2,012 (−6.9%), in place of the figures at the top of this page. | |
| 114 | + | |
| 115 | +What the listing does not show: that two terms with different hashes mean different things (the twelve were read one by one), or anything about proofs, which are not listed. | |
+30 −11 docs/s5-folding/fold.py View file
| @@ -111,11 +111,21 @@ def plan(src, small, cap, skip=()): | ||
| 111 | 111 | return {a: p for a, p in parts.items() if len(p) > 1} |
| 112 | 112 | |
| 113 | 113 | |
| 114 | -def folded(src, host, parts): | |
| 115 | - """the host's new text""" | |
| 114 | +def folded(src, host, parts, inplace=False): | |
| 115 | + """the host's new text. `inplace`: a folded module's import line is replaced, where it stood, by that module's own | |
| 116 | + imports, so that every other module is loaded in the order it was loaded before (Lean breaks ties between instances | |
| 117 | + by that order); otherwise the folded modules' imports come after the host's own.""" | |
| 116 | 118 | 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 | + inside = {module(p): p for p in parts[:-1]} | |
| 120 | + if inplace: | |
| 121 | + new = [] | |
| 122 | + def take(ms): | |
| 123 | + for m in ms: | |
| 124 | + if m in inside: take(split(src[inside[m]])[1]) | |
| 125 | + elif m not in new: new.append(m) | |
| 126 | + take(mods) | |
| 127 | + else: | |
| 128 | + new = [m for m in mods if m not in inside] | |
| 119 | 129 | out_parts = [] |
| 120 | 130 | for p in parts[:-1]: |
| 121 | 131 | h, pm, pb = split(src[p]) |
| @@ -141,10 +151,16 @@ def folded(src, host, parts): | ||
| 141 | 151 | return "\n".join(out + body) |
| 142 | 152 | |
| 143 | 153 | |
| 144 | -def apply(tree, pl): | |
| 154 | +def load(path): | |
| 155 | + """(the folds, whether imports go in place) of a plan file; the first plans were a bare table of folds""" | |
| 156 | + d = json.load(open(path)) | |
| 157 | + return (d["folds"], d.get("imports") == "in place") if "folds" in d else (d, False) | |
| 158 | + | |
| 159 | + | |
| 160 | +def apply(tree, pl, inplace=False): | |
| 145 | 161 | src = read_tree(tree) |
| 146 | 162 | for host, parts in pl.items(): |
| 147 | - text = folded(src, host, parts) | |
| 163 | + text = folded(src, host, parts, inplace) | |
| 148 | 164 | # every line of every folded file and of the host is still there (imports aside) |
| 149 | 165 | want = collections.Counter(l for p in parts for l in (lambda s: s[0] + s[2])(split(src[p])) if l.strip()) |
| 150 | 166 | have = collections.Counter(l for l in text.split("\n") if l.strip() and not IMPORT.match(l)) |
| @@ -153,12 +169,12 @@ def apply(tree, pl): | ||
| 153 | 169 | for p in parts[:-1]: os.remove(os.path.join(tree, p)) |
| 154 | 170 | |
| 155 | 171 | |
| 156 | -def check(repo, pl, rev): | |
| 172 | +def check(repo, pl, rev, inplace=False): | |
| 157 | 173 | """the working tree against what `apply` makes of the revision's text: every changed file, byte for byte""" |
| 158 | 174 | show = lambda f: subprocess.run(["git", "-C", repo, "show", f"{rev}:{f}"], capture_output=True, text=True, check=True).stdout |
| 159 | 175 | bad = [] |
| 160 | 176 | for host, parts in pl.items(): |
| 161 | - want = folded({p: show(p) for p in parts}, host, parts) | |
| 177 | + want = folded({p: show(p) for p in parts}, host, parts, inplace) | |
| 162 | 178 | path = os.path.join(repo, host) |
| 163 | 179 | 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 | 180 | bad += [f"{p} is still there" for p in parts[:-1] if os.path.exists(os.path.join(repo, p))] |
| @@ -178,6 +194,9 @@ def self_test(): | ||
| 178 | 194 | assert t.startswith("import Mathlib.X\nimport Euler.Bar\nimport Mathlib.Y\n\n/-! # A -/\n"), t |
| 179 | 195 | 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 | 196 | assert unclosed(src["Euler/FooB.lean"].split("\n")) == [("section", ""), ("namespace", "Euler.B")] |
| 197 | + t2 = folded(src, "Euler/FooA.lean", pl["Euler/FooA.lean"], inplace=True) | |
| 198 | + assert t2.startswith("import Mathlib.X\nimport Mathlib.Y\nimport Euler.Bar\n\n/-! # A -/\n"), t2 | |
| 199 | + assert t2.split("\n\n", 1)[1] == t.split("\n\n", 1)[1] | |
| 181 | 200 | assert plan(src, 100, 1000, skip={"Euler/FooB.lean"}) == {} |
| 182 | 201 | assert plan(src, 2, 1000) == {}, plan(src, 2, 1000) |
| 183 | 202 | print("ok") |
| @@ -191,10 +210,10 @@ if __name__ == "__main__": | ||
| 191 | 210 | src = read_tree(a[1]) |
| 192 | 211 | skip = set(open(opt("--skip", "")).read().split()) if "--skip" in a else set() |
| 193 | 212 | pl = plan(src, int(opt("--small", 200)), int(opt("--cap", 600)), skip) |
| 194 | - json.dump(pl, open(a[2], "w"), indent=0) | |
| 213 | + json.dump({"imports": "in place", "folds": pl}, open(a[2], "w"), indent=0) | |
| 195 | 214 | n = sum(len(p) - 1 for p in pl.values()) |
| 196 | 215 | 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 | 216 | elif a[0] == "check": |
| 198 | - sys.exit(check(a[1], json.load(open(a[2])), a[3] if len(a) > 3 else "origin/main")) | |
| 217 | + pl, inplace = load(a[2]); sys.exit(check(a[1], pl, a[3] if len(a) > 3 else "origin/main", inplace)) | |
| 199 | 218 | 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") | |
| 219 | + pl, inplace = load(a[2]); apply(a[1], pl, inplace); print("applied", sum(len(p) - 1 for p in pl.values()), "folds") | |
+11 −0 routes/s5-euler-heat-1/README.md added View file
| @@ -0,0 +1,11 @@ | ||
| 1 | +--- | |
| 2 | +issue: 14 | |
| 3 | +status: working | |
| 4 | +--- | |
| 5 | +# s5-euler-heat-1 | |
| 6 | + | |
| 7 | +One unit of S-5 (#14): the `Euler/Heat*` family. Two small modules that exactly one file each imported are folded, text unchanged, into that file: `Euler/HeatMaximalCauchy.lean` takes `HeatGradientIntegral.lean` (55 lines) and `HeatMaximalEstimate.lean` (99), which was the only module that imported the first. Each module's text sits under a heading that names it, in a `section` of its own, before the file's own text; the file takes over their imports where their import lines stood. No statement, proof or docstring changes, and `fold.py check` makes the file again from `origin/main`'s text byte for byte. `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. It is the second of the series; the first, #667 on `NavierStokes/Generic`, was taken in, and the other families wait each on the maintainer's verdict for its own pull request. | |
+10 −0 routes/s5-euler-heat-1/plan.json added View file
| @@ -0,0 +1,10 @@ | ||
| 1 | +{ | |
| 2 | +"imports": "in place", | |
| 3 | +"folds": { | |
| 4 | +"Euler/HeatMaximalCauchy.lean": [ | |
| 5 | +"Euler/HeatGradientIntegral.lean", | |
| 6 | +"Euler/HeatMaximalEstimate.lean", | |
| 7 | +"Euler/HeatMaximalCauchy.lean" | |
| 8 | +] | |
| 9 | +} | |
| 10 | +} | |