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/Axis): 3 small modules folded into the file that imports them (−18.9%, measured) #714
Merged
+0 −79 NavierStokes/AxisAnalyticCoefficients.lean deleted
| @@ -1,79 +0,0 @@ | ||
| 1 | -import NavierStokes.AxisHolomorphic | |
| 2 | -import Mathlib.Analysis.Complex.LocallyUniformLimit | |
| 3 | - | |
| 4 | -/-! # Holomorphic radial coefficients with a common geometric bound -/ | |
| 5 | - | |
| 6 | -noncomputable section | |
| 7 | - | |
| 8 | -open Set Metric Filter Complex | |
| 9 | -open scoped Topology | |
| 10 | -open NavierStokes.AxisCoefficientSpace NavierStokes.AxisWeightEstimates | |
| 11 | -open NavierStokes.AxisEvaluation NavierStokes.AxisHolomorphic | |
| 12 | - | |
| 13 | -namespace NavierStokes.AxisJointAnalytic | |
| 14 | - | |
| 15 | -def coefficientJet (I : Window) (ε : ℝ) (A : AxisSpace I ε) (n m : ℕ) (x : ℝ) : ℝ := | |
| 16 | - jet I (weight ε) A.1 n m x / (m.factorial : ℝ) | |
| 17 | - | |
| 18 | -theorem coefficientJet_hasDerivAt (I : Window) {ε : ℝ} (_hε : 0 < ε) | |
| 19 | - (A : AxisSpace I ε) (n m : ℕ) {x : ℝ} (hx : x ∈ Ioo I.left I.right) : | |
| 20 | - HasDerivAt (coefficientJet I ε A n m) | |
| 21 | - (((m : ℝ) + 1) * coefficientJet I ε A n (m + 1) x) x := by | |
| 22 | - have hd := (hasDerivAt_jet_interior I (weight ε) A n m hx).div_const (m.factorial : ℝ) | |
| 23 | - convert! hd using 1 | |
| 24 | - unfold coefficientJet | |
| 25 | - rw [Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one] | |
| 26 | - have hm : (m.factorial : ℝ) ≠ 0 := by positivity | |
| 27 | - have hm1 : (m : ℝ) + 1 ≠ 0 := by positivity | |
| 28 | - field_simp | |
| 29 | - | |
| 30 | -theorem coefficientJet_bound (I : Window) {ε s : ℝ} (hε : 0 < ε) | |
| 31 | - (hs : (1 : ℝ) / 20 < s) (hs1 : s < 1) (A : AxisSpace I ε) | |
| 32 | - (n m : ℕ) (x : ℝ) : | |
| 33 | - ‖coefficientJet I ε A n m x‖ ≤ | |
| 34 | - (‖A‖ / (1 - s) * (1 / 20 / s) ^ n) * ((ε * (1 - s))⁻¹) ^ m := by | |
| 35 | - have hb := term_factorial_bound I hε (R := 1) (by rfl) hs hs1 A 0 m n | |
| 36 | - (p := (1, x)) (by norm_num) | |
| 37 | - simp only [term, polynomialJet, Nat.descFactorial_zero, Nat.cast_one, Nat.sub_zero, | |
| 38 | - one_pow, one_mul, pow_zero, mul_one] at hb | |
| 39 | - rw [coefficientJet, norm_div, Real.norm_natCast] | |
| 40 | - apply (div_le_iff₀ (by positivity : (0 : ℝ) < m.factorial)).mpr | |
| 41 | - calc | |
| 42 | - _ ≤ _ := hb | |
| 43 | - _ = _ := by ring | |
| 44 | - | |
| 45 | -/-- The actual vertical Taylor extension of radial coefficient `n`. -/ | |
| 46 | -def complexCoefficient (I : Window) (ε : ℝ) (A : AxisSpace I ε) (n : ℕ) : ℂ → ℂ := | |
| 47 | - verticalExtension (coefficientJet I ε A n) | |
| 48 | - | |
| 49 | -theorem complexCoefficient_ofReal (I : Window) (ε : ℝ) (A : AxisSpace I ε) | |
| 50 | - (n : ℕ) (x : ℝ) : | |
| 51 | - complexCoefficient I ε A n (x : ℂ) = (coefficient I (weight ε) A n x : ℂ) := by | |
| 52 | - rw [complexCoefficient, verticalExtension_ofReal] | |
| 53 | - simp [coefficientJet, coefficient] | |
| 54 | - | |
| 55 | -theorem complexCoefficient_analytic (I : Window) {ε s : ℝ} (hε : 0 < ε) | |
| 56 | - (hs : (1 : ℝ) / 20 < s) (hs1 : s < 1) (A : AxisSpace I ε) (n : ℕ) : | |
| 57 | - AnalyticOnNhd ℂ (complexCoefficient I ε A n) (parameterStrip I (ε * (1 - s))) := by | |
| 58 | - apply verticalExtension_analytic I (C := ‖A‖ / (1 - s) * (1 / 20 / s) ^ n) | |
| 59 | - (mul_nonneg (div_nonneg (norm_nonneg A) (by linarith)) (by positivity)) | |
| 60 | - (mul_pos hε (by linarith)) | |
| 61 | - · intro m x hx | |
| 62 | - exact coefficientJet_hasDerivAt I hε A n m hx | |
| 63 | - · intro m x _ | |
| 64 | - exact coefficientJet_bound I hε hs hs1 A n m x | |
| 65 | - | |
| 66 | -theorem complexCoefficient_bound (I : Window) {ε s : ℝ} (hε : 0 < ε) | |
| 67 | - (hs : (1 : ℝ) / 20 < s) (hs1 : s < 1) (A : AxisSpace I ε) (n : ℕ) | |
| 68 | - {z : ℂ} (hz : z ∈ parameterStrip I (ε * (1 - s))) : | |
| 69 | - ‖complexCoefficient I ε A n z‖ ≤ (2 * ‖A‖ / (1 - s)) * (1 / 20 / s) ^ n := by | |
| 70 | - have hb := verticalExtension_bound | |
| 71 | - (C := ‖A‖ / (1 - s) * (1 / 20 / s) ^ n) | |
| 72 | - (mul_nonneg (div_nonneg (norm_nonneg A) (by linarith)) (by positivity)) | |
| 73 | - (mul_pos hε (by linarith)) hz.2.le | |
| 74 | - (fun m => coefficientJet_bound I hε hs hs1 A n m z.re) | |
| 75 | - change ‖verticalExtension (coefficientJet I ε A n) z‖ ≤ _ | |
| 76 | - convert! hb using 1 | |
| 77 | - ring | |
| 78 | - | |
| 79 | -end NavierStokes.AxisJointAnalytic | |
+0 −87 NavierStokes/AxisAnalyticRadialSeries.lean deleted
| @@ -1,87 +0,0 @@ | ||
| 1 | -import NavierStokes.AxisAnalyticCoefficients | |
| 2 | -import NavierStokes.CauchyRestriction | |
| 3 | - | |
| 4 | -/-! # A convergent radial series in a Banach space of parameter-disk functions -/ | |
| 5 | - | |
| 6 | -noncomputable section | |
| 7 | - | |
| 8 | -open Set Metric Filter Complex | |
| 9 | -open scoped Topology | |
| 10 | -open NavierStokes.AxisCoefficientSpace NavierStokes.AxisWeightEstimates | |
| 11 | -open NavierStokes.AxisEvaluation NavierStokes.AxisHolomorphic NavierStokes.CauchyRestriction | |
| 12 | - | |
| 13 | -namespace NavierStokes.AxisJointAnalytic | |
| 14 | - | |
| 15 | -section Geometric | |
| 16 | - | |
| 17 | -variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℂ E] [CompleteSpace E] | |
| 18 | - | |
| 19 | -/-- Uniform geometric coefficient bounds yield a genuine Banach-valued | |
| 20 | -holomorphic radial sum throughout the indicated disk. -/ | |
| 21 | -theorem geometricSeries_analytic {a : ℕ → E} {C ρ R : ℝ} | |
| 22 | - (_hC : 0 ≤ C) (hρ : 0 ≤ ρ) (hR : 0 < R) (hq : R * ρ < 1) | |
| 23 | - (ha : ∀ n, ‖a n‖ ≤ C * ρ ^ n) : | |
| 24 | - AnalyticOnNhd ℂ (fun z : ℂ => ∑' n : ℕ, z ^ n • a n) (ball 0 R) := by | |
| 25 | - have hg : Summable (fun n : ℕ => C * (R * ρ) ^ n) := | |
| 26 | - (summable_geometric_of_norm_lt_one (by | |
| 27 | - rw [Real.norm_eq_abs, abs_of_nonneg (mul_nonneg hR.le hρ)] | |
| 28 | - exact hq)).mul_left C | |
| 29 | - apply (Complex.differentiableOn_tsum_of_summable_norm hg _ isOpen_ball _).analyticOnNhd isOpen_ball | |
| 30 | - · intro n | |
| 31 | - exact ((differentiable_id.pow n).smul_const (a n)).differentiableOn | |
| 32 | - · intro n z hz | |
| 33 | - have hzR : ‖z‖ ≤ R := (mem_ball_zero_iff.mp hz).le | |
| 34 | - rw [norm_smul, norm_pow] | |
| 35 | - calc | |
| 36 | - _ ≤ R ^ n * (C * ρ ^ n) := mul_le_mul (pow_le_pow_left₀ (norm_nonneg z) hzR n) | |
| 37 | - (ha n) (norm_nonneg _) (pow_nonneg hR.le n) | |
| 38 | - _ = _ := by rw [mul_pow]; ring | |
| 39 | - | |
| 40 | -theorem geometricSeries_summable {a : ℕ → E} {C ρ R : ℝ} | |
| 41 | - (_hC : 0 ≤ C) (hρ : 0 ≤ ρ) (hR : 0 < R) (hq : R * ρ < 1) | |
| 42 | - (ha : ∀ n, ‖a n‖ ≤ C * ρ ^ n) {z : ℂ} (hz : ‖z‖ ≤ R) : | |
| 43 | - Summable (fun n : ℕ => z ^ n • a n) := by | |
| 44 | - apply Summable.of_norm_bounded | |
| 45 | - ((summable_geometric_of_norm_lt_one (by | |
| 46 | - rw [Real.norm_eq_abs, abs_of_nonneg (mul_nonneg hR.le hρ)] | |
| 47 | - exact hq)).mul_left C) | |
| 48 | - intro n | |
| 49 | - rw [norm_smul, norm_pow] | |
| 50 | - calc | |
| 51 | - _ ≤ R ^ n * (C * ρ ^ n) := mul_le_mul (pow_le_pow_left₀ (norm_nonneg z) hz n) | |
| 52 | - (ha n) (norm_nonneg _) (pow_nonneg hR.le n) | |
| 53 | - _ = _ := by rw [mul_pow]; ring | |
| 54 | - | |
| 55 | -end Geometric | |
| 56 | - | |
| 57 | -/-- Each coefficient restricted to a closed disk inside the common strip. -/ | |
| 58 | -def diskCoefficient (I : Window) {ε s : ℝ} (hε : 0 < ε) | |
| 59 | - (hs : (1 : ℝ) / 20 < s) (hs1 : s < 1) (A : AxisSpace I ε) | |
| 60 | - (c : ℂ) (σ : ℝ) (hK : closedBall c σ ⊆ parameterStrip I (ε * (1 - s))) | |
| 61 | - (n : ℕ) : C(Disk c σ, ℂ) where | |
| 62 | - toFun z := complexCoefficient I ε A n z | |
| 63 | - continuous_toFun := (complexCoefficient_analytic I hε hs hs1 A n).continuousOn.comp_continuous | |
| 64 | - continuous_subtype_val (fun z => hK z.2) | |
| 65 | - | |
| 66 | -theorem diskCoefficient_bound (I : Window) {ε s : ℝ} (hε : 0 < ε) | |
| 67 | - (hs : (1 : ℝ) / 20 < s) (hs1 : s < 1) (A : AxisSpace I ε) | |
| 68 | - (c : ℂ) (σ : ℝ) (hK : closedBall c σ ⊆ parameterStrip I (ε * (1 - s))) (n : ℕ) : | |
| 69 | - ‖diskCoefficient I hε hs hs1 A c σ hK n‖ ≤ | |
| 70 | - (2 * ‖A‖ / (1 - s)) * (1 / 20 / s) ^ n := by | |
| 71 | - apply (ContinuousMap.norm_le _ (by positivity)).mpr | |
| 72 | - intro z | |
| 73 | - exact complexCoefficient_bound I hε hs hs1 A n (hK z.2) | |
| 74 | - | |
| 75 | -/-- The same coefficient series, evaluated at a real radius and a complex | |
| 76 | -parameter. Its real slice is the original constructed profile. -/ | |
| 77 | -def radialExtension (I : Window) (ε : ℝ) (A : AxisSpace I ε) (Y : ℝ) (z : ℂ) : ℂ := | |
| 78 | - ∑' n : ℕ, (Y : ℂ) ^ n * complexCoefficient I ε A n z | |
| 79 | - | |
| 80 | -theorem radialExtension_ofReal (I : Window) {ε : ℝ} (hε : 0 < ε) | |
| 81 | - (A : AxisSpace I ε) {Y : ℝ} (hY : |Y| < 20) (x : ℝ) : | |
| 82 | - radialExtension I ε A Y (x : ℂ) = (profile I ε A (Y, x) : ℂ) := by | |
| 83 | - unfold radialExtension profile | |
| 84 | - simp only [complexCoefficient_ofReal, ← Complex.ofReal_pow, ← Complex.ofReal_mul] | |
| 85 | - exact (Complex.ofRealCLM.map_tsum (profile_hasSum I hε A (p := (Y, x)) hY).summable).symm | |
| 86 | - | |
| 87 | -end NavierStokes.AxisJointAnalytic | |
+183 −1 NavierStokes/AxisJointAnalytic.lean View file
| @@ -1,4 +1,6 @@ | ||
| 1 | -import NavierStokes.AxisAnalyticRadialSeries | |
| 1 | +import NavierStokes.AxisHolomorphic | |
| 2 | +import Mathlib.Analysis.Complex.LocallyUniformLimit | |
| 3 | +import NavierStokes.CauchyRestriction | |
| 2 | 4 | import NavierStokes.HolomorphicFamilyAnalytic |
| 3 | 5 | |
| 4 | 6 | /-! # Joint real analyticity of the actual evaluated axis profiles |
| @@ -8,6 +10,186 @@ holomorphic parameter-disk functions. Fixed-contour Cauchy evaluation gives | ||
| 8 | 10 | joint analyticity; termwise real agreement identifies the constructed profile. |
| 9 | 11 | -/ |
| 10 | 12 | |
| 13 | +/-! ## From `NavierStokes/AxisAnalyticCoefficients.lean` | |
| 14 | + | |
| 15 | +The text of `NavierStokes/AxisAnalyticCoefficients.lean`, folded into this file, which was its only importer. -/ | |
| 16 | + | |
| 17 | +section | |
| 18 | + | |
| 19 | +/-! # Holomorphic radial coefficients with a common geometric bound -/ | |
| 20 | + | |
| 21 | +noncomputable section | |
| 22 | + | |
| 23 | +open Set Metric Filter Complex | |
| 24 | +open scoped Topology | |
| 25 | +open NavierStokes.AxisCoefficientSpace NavierStokes.AxisWeightEstimates | |
| 26 | +open NavierStokes.AxisEvaluation NavierStokes.AxisHolomorphic | |
| 27 | + | |
| 28 | +namespace NavierStokes.AxisJointAnalytic | |
| 29 | + | |
| 30 | +def coefficientJet (I : Window) (ε : ℝ) (A : AxisSpace I ε) (n m : ℕ) (x : ℝ) : ℝ := | |
| 31 | + jet I (weight ε) A.1 n m x / (m.factorial : ℝ) | |
| 32 | + | |
| 33 | +theorem coefficientJet_hasDerivAt (I : Window) {ε : ℝ} (_hε : 0 < ε) | |
| 34 | + (A : AxisSpace I ε) (n m : ℕ) {x : ℝ} (hx : x ∈ Ioo I.left I.right) : | |
| 35 | + HasDerivAt (coefficientJet I ε A n m) | |
| 36 | + (((m : ℝ) + 1) * coefficientJet I ε A n (m + 1) x) x := by | |
| 37 | + have hd := (hasDerivAt_jet_interior I (weight ε) A n m hx).div_const (m.factorial : ℝ) | |
| 38 | + convert! hd using 1 | |
| 39 | + unfold coefficientJet | |
| 40 | + rw [Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one] | |
| 41 | + have hm : (m.factorial : ℝ) ≠ 0 := by positivity | |
| 42 | + have hm1 : (m : ℝ) + 1 ≠ 0 := by positivity | |
| 43 | + field_simp | |
| 44 | + | |
| 45 | +theorem coefficientJet_bound (I : Window) {ε s : ℝ} (hε : 0 < ε) | |
| 46 | + (hs : (1 : ℝ) / 20 < s) (hs1 : s < 1) (A : AxisSpace I ε) | |
| 47 | + (n m : ℕ) (x : ℝ) : | |
| 48 | + ‖coefficientJet I ε A n m x‖ ≤ | |
| 49 | + (‖A‖ / (1 - s) * (1 / 20 / s) ^ n) * ((ε * (1 - s))⁻¹) ^ m := by | |
| 50 | + have hb := term_factorial_bound I hε (R := 1) (by rfl) hs hs1 A 0 m n | |
| 51 | + (p := (1, x)) (by norm_num) | |
| 52 | + simp only [term, polynomialJet, Nat.descFactorial_zero, Nat.cast_one, Nat.sub_zero, | |
| 53 | + one_pow, one_mul, pow_zero, mul_one] at hb | |
| 54 | + rw [coefficientJet, norm_div, Real.norm_natCast] | |
| 55 | + apply (div_le_iff₀ (by positivity : (0 : ℝ) < m.factorial)).mpr | |
| 56 | + calc | |
| 57 | + _ ≤ _ := hb | |
| 58 | + _ = _ := by ring | |
| 59 | + | |
| 60 | +/-- The actual vertical Taylor extension of radial coefficient `n`. -/ | |
| 61 | +def complexCoefficient (I : Window) (ε : ℝ) (A : AxisSpace I ε) (n : ℕ) : ℂ → ℂ := | |
| 62 | + verticalExtension (coefficientJet I ε A n) | |
| 63 | + | |
| 64 | +theorem complexCoefficient_ofReal (I : Window) (ε : ℝ) (A : AxisSpace I ε) | |
| 65 | + (n : ℕ) (x : ℝ) : | |
| 66 | + complexCoefficient I ε A n (x : ℂ) = (coefficient I (weight ε) A n x : ℂ) := by | |
| 67 | + rw [complexCoefficient, verticalExtension_ofReal] | |
| 68 | + simp [coefficientJet, coefficient] | |
| 69 | + | |
| 70 | +theorem complexCoefficient_analytic (I : Window) {ε s : ℝ} (hε : 0 < ε) | |
| 71 | + (hs : (1 : ℝ) / 20 < s) (hs1 : s < 1) (A : AxisSpace I ε) (n : ℕ) : | |
| 72 | + AnalyticOnNhd ℂ (complexCoefficient I ε A n) (parameterStrip I (ε * (1 - s))) := by | |
| 73 | + apply verticalExtension_analytic I (C := ‖A‖ / (1 - s) * (1 / 20 / s) ^ n) | |
| 74 | + (mul_nonneg (div_nonneg (norm_nonneg A) (by linarith)) (by positivity)) | |
| 75 | + (mul_pos hε (by linarith)) | |
| 76 | + · intro m x hx | |
| 77 | + exact coefficientJet_hasDerivAt I hε A n m hx | |
| 78 | + · intro m x _ | |
| 79 | + exact coefficientJet_bound I hε hs hs1 A n m x | |
| 80 | + | |
| 81 | +theorem complexCoefficient_bound (I : Window) {ε s : ℝ} (hε : 0 < ε) | |
| 82 | + (hs : (1 : ℝ) / 20 < s) (hs1 : s < 1) (A : AxisSpace I ε) (n : ℕ) | |
| 83 | + {z : ℂ} (hz : z ∈ parameterStrip I (ε * (1 - s))) : | |
| 84 | + ‖complexCoefficient I ε A n z‖ ≤ (2 * ‖A‖ / (1 - s)) * (1 / 20 / s) ^ n := by | |
| 85 | + have hb := verticalExtension_bound | |
| 86 | + (C := ‖A‖ / (1 - s) * (1 / 20 / s) ^ n) | |
| 87 | + (mul_nonneg (div_nonneg (norm_nonneg A) (by linarith)) (by positivity)) | |
| 88 | + (mul_pos hε (by linarith)) hz.2.le | |
| 89 | + (fun m => coefficientJet_bound I hε hs hs1 A n m z.re) | |
| 90 | + change ‖verticalExtension (coefficientJet I ε A n) z‖ ≤ _ | |
| 91 | + convert! hb using 1 | |
| 92 | + ring | |
| 93 | + | |
| 94 | +end NavierStokes.AxisJointAnalytic | |
| 95 | +end | |
| 96 | + | |
| 97 | +end | |
| 98 | + | |
| 99 | +/-! ## From `NavierStokes/AxisAnalyticRadialSeries.lean` | |
| 100 | + | |
| 101 | +The text of `NavierStokes/AxisAnalyticRadialSeries.lean`, folded into this file, which was its only importer. -/ | |
| 102 | + | |
| 103 | +section | |
| 104 | + | |
| 105 | +/-! # A convergent radial series in a Banach space of parameter-disk functions -/ | |
| 106 | + | |
| 107 | +noncomputable section | |
| 108 | + | |
| 109 | +open Set Metric Filter Complex | |
| 110 | +open scoped Topology | |
| 111 | +open NavierStokes.AxisCoefficientSpace NavierStokes.AxisWeightEstimates | |
| 112 | +open NavierStokes.AxisEvaluation NavierStokes.AxisHolomorphic NavierStokes.CauchyRestriction | |
| 113 | + | |
| 114 | +namespace NavierStokes.AxisJointAnalytic | |
| 115 | + | |
| 116 | +section Geometric | |
| 117 | + | |
| 118 | +variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℂ E] [CompleteSpace E] | |
| 119 | + | |
| 120 | +/-- Uniform geometric coefficient bounds yield a genuine Banach-valued | |
| 121 | +holomorphic radial sum throughout the indicated disk. -/ | |
| 122 | +theorem geometricSeries_analytic {a : ℕ → E} {C ρ R : ℝ} | |
| 123 | + (_hC : 0 ≤ C) (hρ : 0 ≤ ρ) (hR : 0 < R) (hq : R * ρ < 1) | |
| 124 | + (ha : ∀ n, ‖a n‖ ≤ C * ρ ^ n) : | |
| 125 | + AnalyticOnNhd ℂ (fun z : ℂ => ∑' n : ℕ, z ^ n • a n) (ball 0 R) := by | |
| 126 | + have hg : Summable (fun n : ℕ => C * (R * ρ) ^ n) := | |
| 127 | + (summable_geometric_of_norm_lt_one (by | |
| 128 | + rw [Real.norm_eq_abs, abs_of_nonneg (mul_nonneg hR.le hρ)] | |
| 129 | + exact hq)).mul_left C | |
| 130 | + apply (Complex.differentiableOn_tsum_of_summable_norm hg _ isOpen_ball _).analyticOnNhd isOpen_ball | |
| 131 | + · intro n | |
| 132 | + exact ((differentiable_id.pow n).smul_const (a n)).differentiableOn | |
| 133 | + · intro n z hz | |
| 134 | + have hzR : ‖z‖ ≤ R := (mem_ball_zero_iff.mp hz).le | |
| 135 | + rw [norm_smul, norm_pow] | |
| 136 | + calc | |
| 137 | + _ ≤ R ^ n * (C * ρ ^ n) := mul_le_mul (pow_le_pow_left₀ (norm_nonneg z) hzR n) | |
| 138 | + (ha n) (norm_nonneg _) (pow_nonneg hR.le n) | |
| 139 | + _ = _ := by rw [mul_pow]; ring | |
| 140 | + | |
| 141 | +theorem geometricSeries_summable {a : ℕ → E} {C ρ R : ℝ} | |
| 142 | + (_hC : 0 ≤ C) (hρ : 0 ≤ ρ) (hR : 0 < R) (hq : R * ρ < 1) | |
| 143 | + (ha : ∀ n, ‖a n‖ ≤ C * ρ ^ n) {z : ℂ} (hz : ‖z‖ ≤ R) : | |
| 144 | + Summable (fun n : ℕ => z ^ n • a n) := by | |
| 145 | + apply Summable.of_norm_bounded | |
| 146 | + ((summable_geometric_of_norm_lt_one (by | |
| 147 | + rw [Real.norm_eq_abs, abs_of_nonneg (mul_nonneg hR.le hρ)] | |
| 148 | + exact hq)).mul_left C) | |
| 149 | + intro n | |
| 150 | + rw [norm_smul, norm_pow] | |
| 151 | + calc | |
| 152 | + _ ≤ R ^ n * (C * ρ ^ n) := mul_le_mul (pow_le_pow_left₀ (norm_nonneg z) hz n) | |
| 153 | + (ha n) (norm_nonneg _) (pow_nonneg hR.le n) | |
| 154 | + _ = _ := by rw [mul_pow]; ring | |
| 155 | + | |
| 156 | +end Geometric | |
| 157 | + | |
| 158 | +/-- Each coefficient restricted to a closed disk inside the common strip. -/ | |
| 159 | +def diskCoefficient (I : Window) {ε s : ℝ} (hε : 0 < ε) | |
| 160 | + (hs : (1 : ℝ) / 20 < s) (hs1 : s < 1) (A : AxisSpace I ε) | |
| 161 | + (c : ℂ) (σ : ℝ) (hK : closedBall c σ ⊆ parameterStrip I (ε * (1 - s))) | |
| 162 | + (n : ℕ) : C(Disk c σ, ℂ) where | |
| 163 | + toFun z := complexCoefficient I ε A n z | |
| 164 | + continuous_toFun := (complexCoefficient_analytic I hε hs hs1 A n).continuousOn.comp_continuous | |
| 165 | + continuous_subtype_val (fun z => hK z.2) | |
| 166 | + | |
| 167 | +theorem diskCoefficient_bound (I : Window) {ε s : ℝ} (hε : 0 < ε) | |
| 168 | + (hs : (1 : ℝ) / 20 < s) (hs1 : s < 1) (A : AxisSpace I ε) | |
| 169 | + (c : ℂ) (σ : ℝ) (hK : closedBall c σ ⊆ parameterStrip I (ε * (1 - s))) (n : ℕ) : | |
| 170 | + ‖diskCoefficient I hε hs hs1 A c σ hK n‖ ≤ | |
| 171 | + (2 * ‖A‖ / (1 - s)) * (1 / 20 / s) ^ n := by | |
| 172 | + apply (ContinuousMap.norm_le _ (by positivity)).mpr | |
| 173 | + intro z | |
| 174 | + exact complexCoefficient_bound I hε hs hs1 A n (hK z.2) | |
| 175 | + | |
| 176 | +/-- The same coefficient series, evaluated at a real radius and a complex | |
| 177 | +parameter. Its real slice is the original constructed profile. -/ | |
| 178 | +def radialExtension (I : Window) (ε : ℝ) (A : AxisSpace I ε) (Y : ℝ) (z : ℂ) : ℂ := | |
| 179 | + ∑' n : ℕ, (Y : ℂ) ^ n * complexCoefficient I ε A n z | |
| 180 | + | |
| 181 | +theorem radialExtension_ofReal (I : Window) {ε : ℝ} (hε : 0 < ε) | |
| 182 | + (A : AxisSpace I ε) {Y : ℝ} (hY : |Y| < 20) (x : ℝ) : | |
| 183 | + radialExtension I ε A Y (x : ℂ) = (profile I ε A (Y, x) : ℂ) := by | |
| 184 | + unfold radialExtension profile | |
| 185 | + simp only [complexCoefficient_ofReal, ← Complex.ofReal_pow, ← Complex.ofReal_mul] | |
| 186 | + exact (Complex.ofRealCLM.map_tsum (profile_hasSum I hε A (p := (Y, x)) hY).summable).symm | |
| 187 | + | |
| 188 | +end NavierStokes.AxisJointAnalytic | |
| 189 | +end | |
| 190 | + | |
| 191 | +end | |
| 192 | + | |
| 11 | 193 | noncomputable section |
| 12 | 194 | |
| 13 | 195 | open Set Metric Filter Complex |
+0 −84 NavierStokes/AxisProfile.lean deleted
| @@ -1,84 +0,0 @@ | ||
| 1 | -import Mathlib.Analysis.Calculus.Deriv.Pow | |
| 2 | -import Mathlib.Analysis.Calculus.Deriv.Mul | |
| 3 | -import Mathlib.Data.Nat.Factorial.Basic | |
| 4 | -import Mathlib.Tactic.FieldSimp | |
| 5 | -import Mathlib.Tactic.Linarith | |
| 6 | -import Mathlib.Tactic.NormNum | |
| 7 | -import Mathlib.Tactic.Positivity | |
| 8 | -import Mathlib.Tactic.Ring | |
| 9 | - | |
| 10 | -/-! | |
| 11 | -# Algebraic checks for the natural axis profile | |
| 12 | - | |
| 13 | -These theorems concern the scaled leading equations and the two explicit | |
| 14 | -truncations in Proposition 5.1 of the candidate manuscript. They do not | |
| 15 | -establish convergence of a formal power series, the nonlinear remainder | |
| 16 | -estimates, the contraction argument, or the full profile's cone margin. | |
| 17 | --/ | |
| 18 | - | |
| 19 | -namespace NavierStokes.AxisProfile | |
| 20 | - | |
| 21 | -noncomputable section | |
| 22 | - | |
| 23 | -/-- The regular zero-datum formal inverse used in the scaled equations. -/ | |
| 24 | -def radialInverseCoeff (m : ℕ) (f : ℕ → ℝ) : ℕ → ℝ | |
| 25 | - | 0 => 0 | |
| 26 | - | n + 1 => f n / (((n : ℝ) + 1) * ((n : ℝ) + m)) | |
| 27 | - | |
| 28 | -@[simp] theorem radialInverseCoeff_zero (m : ℕ) (f : ℕ → ℝ) : | |
| 29 | - radialInverseCoeff m f 0 = 0 := rfl | |
| 30 | - | |
| 31 | -/-- The leading angular series coefficient from Proposition 5.1: | |
| 32 | -`(-χ/2)^n / (n! (n+1)!)`. -/ | |
| 33 | -def profileCoeff (χ : ℝ) (n : ℕ) : ℝ := | |
| 34 | - (-χ / 2) ^ n / ((n.factorial : ℝ) * ((n + 1).factorial : ℝ)) | |
| 35 | - | |
| 36 | -@[simp] theorem profileCoeff_zero (χ : ℝ) : profileCoeff χ 0 = 1 := by | |
| 37 | - norm_num [profileCoeff] | |
| 38 | - | |
| 39 | -/-- The cubic lower truncation in the manuscript, with `t = Yχ/2`. -/ | |
| 40 | -def cubicLower (t : ℝ) : ℝ := 1 - t / 2 + t ^ 2 / 12 - t ^ 3 / 144 | |
| 41 | - | |
| 42 | -/-- The quartic upper truncation for `f₀ + s f₀'`, in the variable `t=s/2`. -/ | |
| 43 | -def quarticUpper (t : ℝ) : ℝ := | |
| 44 | - 1 - t + t ^ 2 / 4 - t ^ 3 / 36 + t ^ 4 / 576 | |
| 45 | - | |
| 46 | -/-- A rational positivity certificate for the lower truncation on | |
| 47 | -`t ≤ 2.05`; the natural application also has `t ≥ 0`. -/ | |
| 48 | -theorem cubicLower_gt_quarter (t : ℝ) (ht : t ≤ 41 / 20) : | |
| 49 | - 1 / 4 < cubicLower t := by | |
| 50 | - have hd : 0 ≤ 41 / 20 - t := sub_nonneg.mpr ht | |
| 51 | - have h2 : 0 ≤ (41 / 20 - t) ^ 2 := sq_nonneg _ | |
| 52 | - have h3 : 0 ≤ (41 / 20 - t) ^ 3 := pow_nonneg hd _ | |
| 53 | - have hidentity : cubicLower t = | |
| 54 | - cubicLower (41 / 20) + | |
| 55 | - (1 / 2 - (41 / 20) / 6 + (41 / 20) ^ 2 / 48) * (41 / 20 - t) + | |
| 56 | - (1 / 12 - (41 / 20) / 48) * (41 / 20 - t) ^ 2 + | |
| 57 | - (41 / 20 - t) ^ 3 / 144 := by | |
| 58 | - unfold cubicLower | |
| 59 | - ring | |
| 60 | - norm_num [cubicLower] at hidentity | |
| 61 | - unfold cubicLower | |
| 62 | - linarith | |
| 63 | - | |
| 64 | -/-- A direct rational verification of the numerical strict inequality | |
| 65 | -used for the initial cone margin. -/ | |
| 66 | -theorem quarticUpper_lt_neg_eighteen_hundredths | |
| 67 | - (t : ℝ) (hlo : 99 / 50 ≤ t) (hhi : t ≤ 2) : | |
| 68 | - quarticUpper t < -(18 / 100) := by | |
| 69 | - have ht : 0 ≤ t := by linarith | |
| 70 | - have hsmall : 0 ≤ 1 - t / 2 := by linarith | |
| 71 | - have hsmall_le : 1 - t / 2 ≤ 1 / 100 := by linarith | |
| 72 | - have hsquare := pow_le_pow_left₀ hsmall hsmall_le 2 | |
| 73 | - have hcube := pow_le_pow_left₀ (show (0 : ℝ) ≤ 99 / 50 by norm_num) hlo 3 | |
| 74 | - have hfour := pow_le_pow_left₀ ht hhi 4 | |
| 75 | - norm_num at hsquare hcube hfour | |
| 76 | - unfold quarticUpper | |
| 77 | - linarith | |
| 78 | - | |
| 79 | -/-- The leading axial profile displayed in the scaled construction. -/ | |
| 80 | -def leadingAxial (Z L Y : ℝ) : ℝ := -Y * Z / (2 * L) | |
| 81 | - | |
| 82 | -end | |
| 83 | - | |
| 84 | -end NavierStokes.AxisProfile | |
+92 −1 NavierStokes/AxisSeries.lean View file
| @@ -1,4 +1,11 @@ | ||
| 1 | -import NavierStokes.AxisProfile | |
| 1 | +import Mathlib.Analysis.Calculus.Deriv.Pow | |
| 2 | +import Mathlib.Analysis.Calculus.Deriv.Mul | |
| 3 | +import Mathlib.Data.Nat.Factorial.Basic | |
| 4 | +import Mathlib.Tactic.FieldSimp | |
| 5 | +import Mathlib.Tactic.Linarith | |
| 6 | +import Mathlib.Tactic.NormNum | |
| 7 | +import Mathlib.Tactic.Positivity | |
| 8 | +import Mathlib.Tactic.Ring | |
| 2 | 9 | import Mathlib.Analysis.Calculus.SmoothSeries |
| 3 | 10 | import Mathlib.Analysis.SpecificLimits.Normed |
| 4 | 11 | import Mathlib.Topology.Algebra.InfiniteSum.NatInt |
| @@ -11,6 +18,90 @@ This module concerns the leading scaled linear equation of Proposition 5.1, | ||
| 11 | 18 | not the nonlinear perturbation or the claimed uniform remainder estimates. |
| 12 | 19 | -/ |
| 13 | 20 | |
| 21 | +/-! ## From `NavierStokes/AxisProfile.lean` | |
| 22 | + | |
| 23 | +The text of `NavierStokes/AxisProfile.lean`, folded into this file, which was its only importer. -/ | |
| 24 | + | |
| 25 | +section | |
| 26 | + | |
| 27 | +/-! | |
| 28 | +# Algebraic checks for the natural axis profile | |
| 29 | + | |
| 30 | +These theorems concern the scaled leading equations and the two explicit | |
| 31 | +truncations in Proposition 5.1 of the candidate manuscript. They do not | |
| 32 | +establish convergence of a formal power series, the nonlinear remainder | |
| 33 | +estimates, the contraction argument, or the full profile's cone margin. | |
| 34 | +-/ | |
| 35 | + | |
| 36 | +namespace NavierStokes.AxisProfile | |
| 37 | + | |
| 38 | +noncomputable section | |
| 39 | + | |
| 40 | +/-- The regular zero-datum formal inverse used in the scaled equations. -/ | |
| 41 | +def radialInverseCoeff (m : ℕ) (f : ℕ → ℝ) : ℕ → ℝ | |
| 42 | + | 0 => 0 | |
| 43 | + | n + 1 => f n / (((n : ℝ) + 1) * ((n : ℝ) + m)) | |
| 44 | + | |
| 45 | +@[simp] theorem radialInverseCoeff_zero (m : ℕ) (f : ℕ → ℝ) : | |
| 46 | + radialInverseCoeff m f 0 = 0 := rfl | |
| 47 | + | |
| 48 | +/-- The leading angular series coefficient from Proposition 5.1: | |
| 49 | +`(-χ/2)^n / (n! (n+1)!)`. -/ | |
| 50 | +def profileCoeff (χ : ℝ) (n : ℕ) : ℝ := | |
| 51 | + (-χ / 2) ^ n / ((n.factorial : ℝ) * ((n + 1).factorial : ℝ)) | |
| 52 | + | |
| 53 | +@[simp] theorem profileCoeff_zero (χ : ℝ) : profileCoeff χ 0 = 1 := by | |
| 54 | + norm_num [profileCoeff] | |
| 55 | + | |
| 56 | +/-- The cubic lower truncation in the manuscript, with `t = Yχ/2`. -/ | |
| 57 | +def cubicLower (t : ℝ) : ℝ := 1 - t / 2 + t ^ 2 / 12 - t ^ 3 / 144 | |
| 58 | + | |
| 59 | +/-- The quartic upper truncation for `f₀ + s f₀'`, in the variable `t=s/2`. -/ | |
| 60 | +def quarticUpper (t : ℝ) : ℝ := | |
| 61 | + 1 - t + t ^ 2 / 4 - t ^ 3 / 36 + t ^ 4 / 576 | |
| 62 | + | |
| 63 | +/-- A rational positivity certificate for the lower truncation on | |
| 64 | +`t ≤ 2.05`; the natural application also has `t ≥ 0`. -/ | |
| 65 | +theorem cubicLower_gt_quarter (t : ℝ) (ht : t ≤ 41 / 20) : | |
| 66 | + 1 / 4 < cubicLower t := by | |
| 67 | + have hd : 0 ≤ 41 / 20 - t := sub_nonneg.mpr ht | |
| 68 | + have h2 : 0 ≤ (41 / 20 - t) ^ 2 := sq_nonneg _ | |
| 69 | + have h3 : 0 ≤ (41 / 20 - t) ^ 3 := pow_nonneg hd _ | |
| 70 | + have hidentity : cubicLower t = | |
| 71 | + cubicLower (41 / 20) + | |
| 72 | + (1 / 2 - (41 / 20) / 6 + (41 / 20) ^ 2 / 48) * (41 / 20 - t) + | |
| 73 | + (1 / 12 - (41 / 20) / 48) * (41 / 20 - t) ^ 2 + | |
| 74 | + (41 / 20 - t) ^ 3 / 144 := by | |
| 75 | + unfold cubicLower | |
| 76 | + ring | |
| 77 | + norm_num [cubicLower] at hidentity | |
| 78 | + unfold cubicLower | |
| 79 | + linarith | |
| 80 | + | |
| 81 | +/-- A direct rational verification of the numerical strict inequality | |
| 82 | +used for the initial cone margin. -/ | |
| 83 | +theorem quarticUpper_lt_neg_eighteen_hundredths | |
| 84 | + (t : ℝ) (hlo : 99 / 50 ≤ t) (hhi : t ≤ 2) : | |
| 85 | + quarticUpper t < -(18 / 100) := by | |
| 86 | + have ht : 0 ≤ t := by linarith | |
| 87 | + have hsmall : 0 ≤ 1 - t / 2 := by linarith | |
| 88 | + have hsmall_le : 1 - t / 2 ≤ 1 / 100 := by linarith | |
| 89 | + have hsquare := pow_le_pow_left₀ hsmall hsmall_le 2 | |
| 90 | + have hcube := pow_le_pow_left₀ (show (0 : ℝ) ≤ 99 / 50 by norm_num) hlo 3 | |
| 91 | + have hfour := pow_le_pow_left₀ ht hhi 4 | |
| 92 | + norm_num at hsquare hcube hfour | |
| 93 | + unfold quarticUpper | |
| 94 | + linarith | |
| 95 | + | |
| 96 | +/-- The leading axial profile displayed in the scaled construction. -/ | |
| 97 | +def leadingAxial (Z L Y : ℝ) : ℝ := -Y * Z / (2 * L) | |
| 98 | + | |
| 99 | +end | |
| 100 | + | |
| 101 | +end NavierStokes.AxisProfile | |
| 102 | + | |
| 103 | +end | |
| 104 | + | |
| 14 | 105 | noncomputable section |
| 15 | 106 | |
| 16 | 107 | namespace NavierStokes.AxisSeries |
+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") | |
+18 −0 routes/s5-ns-axis-1/README.md added View file
| @@ -0,0 +1,18 @@ | ||
| 1 | +--- | |
| 2 | +issue: 14 | |
| 3 | +status: working | |
| 4 | +--- | |
| 5 | +# s5-ns-axis-1 | |
| 6 | + | |
| 7 | +The family `NavierStokes/Axis*`: `NavierStokes/AxisAnalyticCoefficients.lean` (79 lines) and | |
| 8 | +`NavierStokes/AxisAnalyticRadialSeries.lean` (87) are folded into their only importer | |
| 9 | +`NavierStokes/AxisJointAnalytic.lean`, and `NavierStokes/AxisProfile.lean` (84) into its only importer | |
| 10 | +`NavierStokes/AxisSeries.lean`. Each module's text moves in unchanged, under a heading that names it, in a | |
| 11 | +`section` of its own; the importer takes over its imports in place. `plan.json` is the plan and | |
| 12 | +`docs/s5-folding/fold.py check . routes/s5-ns-axis-1/plan.json` confirms the result line for line. No file | |
| 13 | +reads worse folded than the two did apart. | |
| 14 | + | |
| 15 | +## Next | |
| 16 | + | |
| 17 | +The pull request is open. What comes next is the maintainer's verdict on whether this kind of change is wanted; | |
| 18 | +the rest of the series' folds wait on it, one family per pull request. | |
+14 −0 routes/s5-ns-axis-1/plan.json added View file
| @@ -0,0 +1,14 @@ | ||
| 1 | +{ | |
| 2 | +"imports": "in place", | |
| 3 | +"folds": { | |
| 4 | +"NavierStokes/AxisJointAnalytic.lean": [ | |
| 5 | +"NavierStokes/AxisAnalyticCoefficients.lean", | |
| 6 | +"NavierStokes/AxisAnalyticRadialSeries.lean", | |
| 7 | +"NavierStokes/AxisJointAnalytic.lean" | |
| 8 | +], | |
| 9 | +"NavierStokes/AxisSeries.lean": [ | |
| 10 | +"NavierStokes/AxisProfile.lean", | |
| 11 | +"NavierStokes/AxisSeries.lean" | |
| 12 | +] | |
| 13 | +} | |
| 14 | +} | |