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/Whole): 6 small modules folded into the file that imports them (−58.8%, measured)
Browse filesCo-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Checks
build Program · lake build and Comparator
Details
challenge Program · challenge files and build config
Details
+0 −24 NavierStokes/WholeDomainActualStageBounds.lean deleted
| @@ -1,24 +0,0 @@ | ||
| 1 | -import NavierStokes.WholeDomainStageBounds | |
| 2 | -import NavierStokes.ActualCandidateAssembly | |
| 3 | - | |
| 4 | -noncomputable section | |
| 5 | - | |
| 6 | -namespace NavierStokes.WholeDomainStageBounds | |
| 7 | - | |
| 8 | -open Set Function Filter ProblemStatement CorrectionInitialization | |
| 9 | -open CorrectionInitialization.ActualPrimary ActualCandidateAssembly PhysicalWaveSum | |
| 10 | -open scoped Topology ContDiff BigOperators | |
| 11 | - | |
| 12 | -/-- One common scale for every finite stage and every derivative order. -/ | |
| 13 | -noncomputable def commonQ (B N0 : ℕ) : ℝ := | |
| 14 | - ChartScales.Q (ActualCandidateConstruction.residualBand B N0) | |
| 15 | - | |
| 16 | -theorem commonQ_pos (B N0 : ℕ) : 0 < commonQ B N0 := ChartScales.Q_pos _ | |
| 17 | - | |
| 18 | -theorem commonQ_lt_original (B N0 : ℕ) : commonQ B N0 < ActualCandidateConstruction.qbig B N0 := by | |
| 19 | - have he := ActualCandidateConstruction.twice_residual_scale B N0 | |
| 20 | - have hp := commonQ_pos B N0 | |
| 21 | - change 2 * commonQ B N0 = _ at he | |
| 22 | - linarith | |
| 23 | - | |
| 24 | -end NavierStokes.WholeDomainStageBounds | |
+0 −71 NavierStokes/WholeDomainCompactBounds.lean deleted
| @@ -1,71 +0,0 @@ | ||
| 1 | -import NavierStokes.JointResidualLimits | |
| 2 | -import NavierStokes.DiagonalResidual | |
| 3 | -import Mathlib.Analysis.SpecialFunctions.Pow.Continuity | |
| 4 | - | |
| 5 | -/-! | |
| 6 | -# Uniform bounds on the common finite-stage domain | |
| 7 | - | |
| 8 | -Local endpoint estimates are upgraded on a fixed compact set without changing | |
| 9 | -the domain with the requested derivative order. The compactness argument uses | |
| 10 | -the actual derivatives, and allows a different local constant at every point. | |
| 11 | --/ | |
| 12 | - | |
| 13 | -noncomputable section | |
| 14 | - | |
| 15 | -namespace NavierStokes.WholeDomainStageBounds | |
| 16 | - | |
| 17 | -open Set Filter Function ProblemStatement | |
| 18 | -open scoped Topology ContDiff BigOperators | |
| 19 | - | |
| 20 | -section CompactBounds | |
| 21 | - | |
| 22 | -variable {D V : Type*} [NormedAddCommGroup D] [NormedSpace ℝ D] | |
| 23 | - [NormedAddCommGroup V] [NormedSpace ℝ V] | |
| 24 | - | |
| 25 | -end CompactBounds | |
| 26 | - | |
| 27 | -section LocalRates | |
| 28 | - | |
| 29 | -variable {D V : Type*} [NormedAddCommGroup D] [NormedSpace ℝ D] | |
| 30 | - [NormedAddCommGroup V] [NormedSpace ℝ V] | |
| 31 | - | |
| 32 | -/-- A finite jet limit at a positive limiting scale gives every power rate. -/ | |
| 33 | -theorem rate_of_jet_limit {l : Filter D} {f : D → V} {q : D → ℝ} {m : ℕ} | |
| 34 | - {J : D [×m]→L[ℝ] V} {q₀ : ℝ} (hJ : Tendsto (iteratedFDeriv ℝ m f) l (𝓝 J)) | |
| 35 | - (hq : Tendsto q l (𝓝 q₀)) (hq₀ : 0 < q₀) (r : ℝ) : | |
| 36 | - DiagonalResidual.JetRate l q f m r := by | |
| 37 | - have hb := (hJ.norm.mul (hq.rpow_const (Or.inl hq₀.ne'))).eventually | |
| 38 | - (gt_mem_nhds (lt_add_one (‖J‖ * q₀ ^ (-r)))) | |
| 39 | - refine ⟨‖J‖ * q₀ ^ (-r) + 1, by positivity, ?_⟩ | |
| 40 | - filter_upwards [hb, hq.eventually (lt_mem_nhds hq₀)] with x hx hqx | |
| 41 | - have he : (‖iteratedFDeriv ℝ m f x‖ * q x ^ (-r)) * q x ^ r = | |
| 42 | - ‖iteratedFDeriv ℝ m f x‖ := by | |
| 43 | - rw [mul_assoc, ← Real.rpow_add hqx, neg_add_cancel, Real.rpow_zero, mul_one] | |
| 44 | - exact he ▸ mul_le_mul_of_nonneg_right hx.le (Real.rpow_nonneg hqx.le r) | |
| 45 | - | |
| 46 | -end LocalRates | |
| 47 | - | |
| 48 | -/-- Smooth one-sided velocity and pressure extensions extend the actual | |
| 49 | -residual, including the derivatives occurring in its definition. -/ | |
| 50 | -noncomputable def residualExtension {u : VelocityField} {p : PressureField} {x : Space} | |
| 51 | - (U : JointResidualLimits.OneSidedExtension u x) | |
| 52 | - (P : JointResidualLimits.OneSidedExtension p x) : | |
| 53 | - JointResidualLimits.OneSidedExtension | |
| 54 | - (fun w => navierStokesResidual u p w.1 w.2) x where | |
| 55 | - value := fun w => navierStokesResidual U.value P.value w.1 w.2 | |
| 56 | - domain := U.domain ∩ P.domain | |
| 57 | - isOpen := U.isOpen.inter P.isOpen | |
| 58 | - mem := ⟨U.mem, P.mem⟩ | |
| 59 | - smooth := ResidualRegularity.contDiffOn_residual (U.isOpen.inter P.isOpen) | |
| 60 | - (U.smooth.mono inter_subset_left) (P.smooth.mono inter_subset_right) | |
| 61 | - agrees := by | |
| 62 | - intro w hw | |
| 63 | - have hU : U.value =ᶠ[𝓝 w] u := | |
| 64 | - Filter.eventuallyEq_of_mem ((U.isOpen.inter (SpacetimeEndpoint.openPast_isOpen 1)).mem_nhds | |
| 65 | - ⟨hw.1.1, hw.2⟩) U.agrees | |
| 66 | - have hP : P.value =ᶠ[𝓝 w] p := | |
| 67 | - Filter.eventuallyEq_of_mem ((P.isOpen.inter (SpacetimeEndpoint.openPast_isOpen 1)).mem_nhds | |
| 68 | - ⟨hw.1.2, hw.2⟩) P.agrees | |
| 69 | - exact (ResidualRegularity.residual_eventuallyEq hU hP).self_of_nhds | |
| 70 | - | |
| 71 | -end NavierStokes.WholeDomainStageBounds | |
+102 −2 NavierStokes/WholeDomainHeatBounds.lean View file
| @@ -1,5 +1,5 @@ | ||
| 1 | -import NavierStokes.WholeDomainHeatScaling | |
| 2 | -import NavierStokes.WholeDomainHeatCompact | |
| 1 | +import NavierStokes.WholeDomainPhysicalCompact | |
| 2 | +import NavierStokes.SlowBaseEndpoint | |
| 3 | 3 | |
| 4 | 4 | /-! # Whole-domain jet bounds for the actual exterior heat fields |
| 5 | 5 | |
| @@ -8,6 +8,106 @@ physical radial energy. Its image lies in one compact annulus, even when | ||
| 8 | 8 | the original radial coordinate is unbounded. |
| 9 | 9 | -/ |
| 10 | 10 | |
| 11 | +/-! ## From `NavierStokes/WholeDomainHeatGeometry.lean` | |
| 12 | + | |
| 13 | +The text of `NavierStokes/WholeDomainHeatGeometry.lean`, folded into this file, which was its only importer. -/ | |
| 14 | + | |
| 15 | +section | |
| 16 | + | |
| 17 | +/-! # Parabolic normalization of the entire exterior heat region -/ | |
| 18 | + | |
| 19 | +noncomputable section | |
| 20 | + | |
| 21 | +open Set Filter Function | |
| 22 | +open scoped Topology ContDiff BigOperators | |
| 23 | + | |
| 24 | +namespace NavierStokes.WholeDomainHeatBounds | |
| 25 | + | |
| 26 | +open ProblemStatement PhysicalWaveSum | |
| 27 | + | |
| 28 | +def parabolicLinear (a : ℝ) (ha : 0 < a) : SpaceTime ≃L[ℝ] SpaceTime where | |
| 29 | + toFun w := (a⁻¹ * w.1, (Real.sqrt a)⁻¹ • w.2) | |
| 30 | + invFun w := (a * w.1, Real.sqrt a • w.2) | |
| 31 | + left_inv w := by | |
| 32 | + ext <;> simp [ha.ne', (Real.sqrt_pos.mpr ha).ne', smul_smul] | |
| 33 | + right_inv w := by | |
| 34 | + ext <;> simp [ha.ne', (Real.sqrt_pos.mpr ha).ne', smul_smul] | |
| 35 | + map_add' u w := by ext <;> simp [mul_add, smul_add] | |
| 36 | + map_smul' c w := by ext <;> simp [smul_smul, mul_assoc, mul_comm] | |
| 37 | + continuous_toFun := by fun_prop | |
| 38 | + continuous_invFun := by fun_prop | |
| 39 | + | |
| 40 | +def rescaleOffset (a z : ℝ) : SpaceTime := | |
| 41 | + (1 - a⁻¹, -((Real.sqrt a)⁻¹ * z) • coordinateVector 2) | |
| 42 | + | |
| 43 | +def rescale (a : ℝ) (ha : 0 < a) (z : ℝ) (w : SpaceTime) : SpaceTime := | |
| 44 | + parabolicLinear a ha w + rescaleOffset a z | |
| 45 | + | |
| 46 | +@[simp] theorem rescale_time (a : ℝ) (ha : 0 < a) (z : ℝ) (w : SpaceTime) : | |
| 47 | + (rescale a ha z w).1 = 1 - (1 - w.1) / a := by | |
| 48 | + change a⁻¹ * w.1 + (1-a⁻¹) = _ | |
| 49 | + ring | |
| 50 | + | |
| 51 | +@[simp] theorem rescale_space (a : ℝ) (ha : 0 < a) (z : ℝ) (w : SpaceTime) : | |
| 52 | + (rescale a ha z w).2 = (Real.sqrt a)⁻¹ • (w.2 - z • coordinateVector 2) := by | |
| 53 | + change (Real.sqrt a)⁻¹ • w.2 + -((Real.sqrt a)⁻¹ * z) • coordinateVector 2 = _ | |
| 54 | + simp [smul_smul, sub_eq_add_neg] | |
| 55 | + | |
| 56 | +variable {V : Type*} [NormedAddCommGroup V] [NormedSpace ℝ V] | |
| 57 | + | |
| 58 | +end NavierStokes.WholeDomainHeatBounds | |
| 59 | +end | |
| 60 | + | |
| 61 | +end | |
| 62 | + | |
| 63 | +/-! ## From `NavierStokes/WholeDomainHeatCompact.lean` | |
| 64 | + | |
| 65 | +The text of `NavierStokes/WholeDomainHeatCompact.lean`, folded into this file, which was its only importer. -/ | |
| 66 | + | |
| 67 | +section | |
| 68 | + | |
| 69 | +/-! # Uniform heat jets on the normalized compact annulus -/ | |
| 70 | + | |
| 71 | +noncomputable section | |
| 72 | + | |
| 73 | +open Set Filter Function | |
| 74 | +open scoped Topology ContDiff BigOperators | |
| 75 | + | |
| 76 | +namespace NavierStokes.WholeDomainHeatBounds | |
| 77 | + | |
| 78 | +open ProblemStatement PhysicalWaveSum WholeDomainStageBounds | |
| 79 | + | |
| 80 | +variable {V : Type*} [NormedAddCommGroup V] [NormedSpace ℝ V] | |
| 81 | + | |
| 82 | +variable [CompleteSpace V] | |
| 83 | + | |
| 84 | +end NavierStokes.WholeDomainHeatBounds | |
| 85 | +end | |
| 86 | + | |
| 87 | +end | |
| 88 | + | |
| 89 | +/-! ## From `NavierStokes/WholeDomainHeatScaling.lean` | |
| 90 | + | |
| 91 | +The text of `NavierStokes/WholeDomainHeatScaling.lean`, folded into this file, which was its only importer. -/ | |
| 92 | + | |
| 93 | +section | |
| 94 | + | |
| 95 | +/-! # Exact scaling identities for the physical heat velocity and pressure -/ | |
| 96 | + | |
| 97 | +noncomputable section | |
| 98 | + | |
| 99 | +open Set Filter Function | |
| 100 | +open scoped Topology ContDiff BigOperators | |
| 101 | + | |
| 102 | +namespace NavierStokes.WholeDomainHeatBounds | |
| 103 | + | |
| 104 | +open ProblemStatement PhysicalWaveSum | |
| 105 | + | |
| 106 | +end NavierStokes.WholeDomainHeatBounds | |
| 107 | +end | |
| 108 | + | |
| 109 | +end | |
| 110 | + | |
| 11 | 111 | noncomputable section |
| 12 | 112 | |
| 13 | 113 | open Set Filter Function |
+0 −18 NavierStokes/WholeDomainHeatCompact.lean deleted
| @@ -1,18 +0,0 @@ | ||
| 1 | -import NavierStokes.WholeDomainHeatGeometry | |
| 2 | - | |
| 3 | -/-! # Uniform heat jets on the normalized compact annulus -/ | |
| 4 | - | |
| 5 | -noncomputable section | |
| 6 | - | |
| 7 | -open Set Filter Function | |
| 8 | -open scoped Topology ContDiff BigOperators | |
| 9 | - | |
| 10 | -namespace NavierStokes.WholeDomainHeatBounds | |
| 11 | - | |
| 12 | -open ProblemStatement PhysicalWaveSum WholeDomainStageBounds | |
| 13 | - | |
| 14 | -variable {V : Type*} [NormedAddCommGroup V] [NormedSpace ℝ V] | |
| 15 | - | |
| 16 | -variable [CompleteSpace V] | |
| 17 | - | |
| 18 | -end NavierStokes.WholeDomainHeatBounds | |
+0 −45 NavierStokes/WholeDomainHeatGeometry.lean deleted
| @@ -1,45 +0,0 @@ | ||
| 1 | -import NavierStokes.WholeDomainPhysicalCompact | |
| 2 | -import NavierStokes.SlowBaseEndpoint | |
| 3 | - | |
| 4 | -/-! # Parabolic normalization of the entire exterior heat region -/ | |
| 5 | - | |
| 6 | -noncomputable section | |
| 7 | - | |
| 8 | -open Set Filter Function | |
| 9 | -open scoped Topology ContDiff BigOperators | |
| 10 | - | |
| 11 | -namespace NavierStokes.WholeDomainHeatBounds | |
| 12 | - | |
| 13 | -open ProblemStatement PhysicalWaveSum | |
| 14 | - | |
| 15 | -def parabolicLinear (a : ℝ) (ha : 0 < a) : SpaceTime ≃L[ℝ] SpaceTime where | |
| 16 | - toFun w := (a⁻¹ * w.1, (Real.sqrt a)⁻¹ • w.2) | |
| 17 | - invFun w := (a * w.1, Real.sqrt a • w.2) | |
| 18 | - left_inv w := by | |
| 19 | - ext <;> simp [ha.ne', (Real.sqrt_pos.mpr ha).ne', smul_smul] | |
| 20 | - right_inv w := by | |
| 21 | - ext <;> simp [ha.ne', (Real.sqrt_pos.mpr ha).ne', smul_smul] | |
| 22 | - map_add' u w := by ext <;> simp [mul_add, smul_add] | |
| 23 | - map_smul' c w := by ext <;> simp [smul_smul, mul_assoc, mul_comm] | |
| 24 | - continuous_toFun := by fun_prop | |
| 25 | - continuous_invFun := by fun_prop | |
| 26 | - | |
| 27 | -def rescaleOffset (a z : ℝ) : SpaceTime := | |
| 28 | - (1 - a⁻¹, -((Real.sqrt a)⁻¹ * z) • coordinateVector 2) | |
| 29 | - | |
| 30 | -def rescale (a : ℝ) (ha : 0 < a) (z : ℝ) (w : SpaceTime) : SpaceTime := | |
| 31 | - parabolicLinear a ha w + rescaleOffset a z | |
| 32 | - | |
| 33 | -@[simp] theorem rescale_time (a : ℝ) (ha : 0 < a) (z : ℝ) (w : SpaceTime) : | |
| 34 | - (rescale a ha z w).1 = 1 - (1 - w.1) / a := by | |
| 35 | - change a⁻¹ * w.1 + (1-a⁻¹) = _ | |
| 36 | - ring | |
| 37 | - | |
| 38 | -@[simp] theorem rescale_space (a : ℝ) (ha : 0 < a) (z : ℝ) (w : SpaceTime) : | |
| 39 | - (rescale a ha z w).2 = (Real.sqrt a)⁻¹ • (w.2 - z • coordinateVector 2) := by | |
| 40 | - change (Real.sqrt a)⁻¹ • w.2 + -((Real.sqrt a)⁻¹ * z) • coordinateVector 2 = _ | |
| 41 | - simp [smul_smul, sub_eq_add_neg] | |
| 42 | - | |
| 43 | -variable {V : Type*} [NormedAddCommGroup V] [NormedSpace ℝ V] | |
| 44 | - | |
| 45 | -end NavierStokes.WholeDomainHeatBounds | |
+0 −14 NavierStokes/WholeDomainHeatScaling.lean deleted
| @@ -1,14 +0,0 @@ | ||
| 1 | -import NavierStokes.WholeDomainHeatGeometry | |
| 2 | - | |
| 3 | -/-! # Exact scaling identities for the physical heat velocity and pressure -/ | |
| 4 | - | |
| 5 | -noncomputable section | |
| 6 | - | |
| 7 | -open Set Filter Function | |
| 8 | -open scoped Topology ContDiff BigOperators | |
| 9 | - | |
| 10 | -namespace NavierStokes.WholeDomainHeatBounds | |
| 11 | - | |
| 12 | -open ProblemStatement PhysicalWaveSum | |
| 13 | - | |
| 14 | -end NavierStokes.WholeDomainHeatBounds | |
+144 −1 NavierStokes/WholeDomainInitializationBounds.lean View file
| @@ -1,6 +1,149 @@ | ||
| 1 | -import NavierStokes.WholeDomainActualStageBounds | |
| 1 | +import NavierStokes.WholeDomainPhysicalCompact | |
| 2 | +import NavierStokes.ActualCycleResidualBounds | |
| 3 | +import NavierStokes.PhysicalStageBounds | |
| 4 | +import NavierStokes.AnnularEndpoint | |
| 5 | +import NavierStokes.ActualCandidateAssembly | |
| 2 | 6 | import NavierStokes.SharpPhysicalLogBounds |
| 3 | 7 | |
| 8 | +/-! ## From `NavierStokes/WholeDomainStageBounds.lean` | |
| 9 | + | |
| 10 | +The text of `NavierStokes/WholeDomainStageBounds.lean`, folded into this file, which was its only importer. -/ | |
| 11 | + | |
| 12 | +section | |
| 13 | + | |
| 14 | +noncomputable section | |
| 15 | + | |
| 16 | +namespace NavierStokes.WholeDomainStageBounds | |
| 17 | + | |
| 18 | +open Set Filter Function ProblemStatement | |
| 19 | +open scoped Topology ContDiff BigOperators | |
| 20 | + | |
| 21 | +open PhysicalWaveSum | |
| 22 | + | |
| 23 | +section BaseResidual | |
| 24 | + | |
| 25 | +open CorrectionInitialization CorrectionInitialization.ActualPrimary ActualCycleResidualBounds | |
| 26 | + | |
| 27 | +private abbrev baseResidual (B : ℕ) : VelocityField := | |
| 28 | + PhysicalResidualJetBounds.residual (FinalSlowBase.velocity certificate modulation upper B) | |
| 29 | + (FinalSlowBase.pressure certificate modulation upper B) | |
| 30 | + | |
| 31 | +private def exteriorDomain : Set SpaceTime := | |
| 32 | + {w | w ∈ preterminal ∧ physicalQ h w ≤ 1 ∧ w ∉ active} | |
| 33 | + | |
| 34 | +private theorem exteriorDomain_past : exteriorDomain ⊆ SpacetimeEndpoint.openPast 1 := | |
| 35 | + fun _ hw => ⟨hw.1, Set.mem_univ _⟩ | |
| 36 | + | |
| 37 | +private theorem baseResidual_smooth (B : ℕ) : | |
| 38 | + ContDiffOn ℝ ∞ (baseResidual B) (SpacetimeEndpoint.openPast 1) := | |
| 39 | + ResidualRegularity.contDiffOn_residual (SpacetimeEndpoint.openPast_isOpen 1) | |
| 40 | + (FinalSlowBase.velocity_smooth certificate modulation upper B) | |
| 41 | + (FinalSlowBase.pressure_smooth certificate modulation upper B) | |
| 42 | + | |
| 43 | +/-- At nonzero limiting axial coordinate the genuine endpoint chart has | |
| 44 | +a positive limiting scale. -/ | |
| 45 | +theorem physicalQ_tendsto_offplane {x : Space} (hx : x 2 ≠ 0) : | |
| 46 | + Tendsto (physicalQ h) (𝓝[SpacetimeEndpoint.openPast 1] (1,x)) | |
| 47 | + (𝓝 ((EndpointCoordinates.cartesianExtension h (1,x)).1)) := by | |
| 48 | + have hc := (EndpointCoordinates.cartesianExtension_smoothAt outgoing.data.h_pos | |
| 49 | + outgoing.data.h_lt_half (EndpointCoordinates.cartesian_endpoint_mem | |
| 50 | + outgoing.data.h_pos outgoing.data.h_lt_half hx)).continuousAt.fst | |
| 51 | + apply (hc.tendsto.mono_left nhdsWithin_le_nhds).congr' | |
| 52 | + filter_upwards [self_mem_nhdsWithin] with w hw | |
| 53 | + exact congrArg Prod.fst (EndpointCoordinates.cartesianExtension_eq_physical | |
| 54 | + outgoing.data.h_pos outgoing.data.h_lt_half hw.1) | |
| 55 | + | |
| 56 | +private theorem baseResidual_local_rate (B m : ℕ) (r : ℝ) (w : SpaceTime) : | |
| 57 | + DiagonalResidual.JetRate (𝓝[exteriorDomain] w) (physicalQ h) (baseResidual B) m r := by | |
| 58 | + rcases w with ⟨t,x⟩ | |
| 59 | + rcases lt_trichotomy t 1 with ht | ht | ht | |
| 60 | + · have hs := (baseResidual_smooth B).contDiffAt | |
| 61 | + ((SpacetimeEndpoint.openPast_isOpen 1).mem_nhds | |
| 62 | + (show (t,x) ∈ SpacetimeEndpoint.openPast 1 from ⟨ht, mem_univ x⟩)) | |
| 63 | + have hj : ContDiffAt ℝ 0 (iteratedFDeriv ℝ m (baseResidual B)) (t,x) := | |
| 64 | + hs.iteratedFDeriv_right (by exact_mod_cast (le_top : 0 + (m : ℕ∞) ≤ ⊤)) | |
| 65 | + exact rate_of_jet_limit (hj.continuousAt.tendsto.mono_left nhdsWithin_le_nhds) | |
| 66 | + ((physicalQ_smoothAt outgoing.data.h_pos outgoing.data.h_lt_half ht).continuousAt.tendsto.mono_left | |
| 67 | + nhdsWithin_le_nhds) (physicalQ_pos outgoing.data.h_pos outgoing.data.h_lt_half ht) r | |
| 68 | + · subst t | |
| 69 | + have hmono : 𝓝[exteriorDomain] ((1:ℝ),x) ≤ | |
| 70 | + 𝓝[SpacetimeEndpoint.openPast 1] ((1:ℝ),x) := nhdsWithin_mono _ exteriorDomain_past | |
| 71 | + by_cases hz : x 2 = 0 | |
| 72 | + · have hcarrier : ∀ᶠ y in 𝓝[exteriorDomain] ((1:ℝ),x), | |
| 73 | + y ∈ Metric.closedBall ((1:ℝ),x) 1 := | |
| 74 | + nhdsWithin_le_nhds (Metric.closedBall_mem_nhds _ zero_lt_one) | |
| 75 | + have hpast : ∀ᶠ y in 𝓝[exteriorDomain] ((1:ℝ),x), y.1 < 1 := by | |
| 76 | + filter_upwards [self_mem_nhdsWithin] with y hy | |
| 77 | + exact hy.1 | |
| 78 | + have hscale := (AnnularEndpoint.physicalQ_tendsto_zero outgoing.data.h_pos | |
| 79 | + outgoing.data.h_lt_half hz).mono_left hmono | |
| 80 | + obtain ⟨C,hC,hb⟩ := GlobalBaseError.error_jetRate certificate modulation upper B | |
| 81 | + actual_upper_covers_exterior (isCompact_closedBall _ _) hcarrier hpast hscale | |
| 82 | + m (max r 0) (le_max_right _ _) | |
| 83 | + refine ⟨C,hC,?_⟩ | |
| 84 | + filter_upwards [hb,self_mem_nhdsWithin] with y hy hyS | |
| 85 | + rw [iteratedFDeriv_eq_of_eventuallyEq | |
| 86 | + (base_residual_germ B hyS.1 hyS.2.2) m] | |
| 87 | + exact hy.trans (mul_le_mul_of_nonneg_left | |
| 88 | + (Real.rpow_le_rpow_of_exponent_ge | |
| 89 | + (physicalQ_pos outgoing.data.h_pos outgoing.data.h_lt_half hyS.1) | |
| 90 | + hyS.2.1 (le_max_left _ _)) hC) | |
| 91 | + · let U := SlowBaseEndpoint.finalVelocityNonzeroAxial certificate modulation upper B hz | |
| 92 | + let P := SlowBaseEndpoint.finalPressureNonzeroAxial certificate modulation upper B hz | |
| 93 | + have hp := EndpointCoordinates.cartesianExtension_pos | |
| 94 | + (EndpointCoordinates.cartesian_endpoint_mem outgoing.data.h_pos outgoing.data.h_lt_half hz) | |
| 95 | + exact rate_of_jet_limit ((residualExtension U P).jet_tendsto m |>.mono_left hmono) | |
| 96 | + ((physicalQ_tendsto_offplane hz).mono_left hmono) hp r | |
| 97 | + · refine ⟨0,le_rfl,?_⟩ | |
| 98 | + have hn : {y : SpaceTime | 1 < y.1} ∈ 𝓝 ((t:ℝ),x) := | |
| 99 | + (isOpen_lt continuous_const continuous_fst).mem_nhds ht | |
| 100 | + filter_upwards [nhdsWithin_le_nhds hn,self_mem_nhdsWithin] with y hy hyS | |
| 101 | + exact False.elim (not_lt_of_ge hy.le hyS.1) | |
| 102 | + | |
| 103 | +end BaseResidual | |
| 104 | + | |
| 105 | +section ResidualAssembly | |
| 106 | + | |
| 107 | +open ActualCycleResidualBounds PhysicalResidualJetBounds CorrectionInitialization | |
| 108 | + | |
| 109 | +end ResidualAssembly | |
| 110 | + | |
| 111 | +end NavierStokes.WholeDomainStageBounds | |
| 112 | +end | |
| 113 | + | |
| 114 | +end | |
| 115 | + | |
| 116 | +/-! ## From `NavierStokes/WholeDomainActualStageBounds.lean` | |
| 117 | + | |
| 118 | +The text of `NavierStokes/WholeDomainActualStageBounds.lean`, folded into this file, which was its only importer. -/ | |
| 119 | + | |
| 120 | +section | |
| 121 | + | |
| 122 | +noncomputable section | |
| 123 | + | |
| 124 | +namespace NavierStokes.WholeDomainStageBounds | |
| 125 | + | |
| 126 | +open Set Function Filter ProblemStatement CorrectionInitialization | |
| 127 | +open CorrectionInitialization.ActualPrimary ActualCandidateAssembly PhysicalWaveSum | |
| 128 | +open scoped Topology ContDiff BigOperators | |
| 129 | + | |
| 130 | +/-- One common scale for every finite stage and every derivative order. -/ | |
| 131 | +noncomputable def commonQ (B N0 : ℕ) : ℝ := | |
| 132 | + ChartScales.Q (ActualCandidateConstruction.residualBand B N0) | |
| 133 | + | |
| 134 | +theorem commonQ_pos (B N0 : ℕ) : 0 < commonQ B N0 := ChartScales.Q_pos _ | |
| 135 | + | |
| 136 | +theorem commonQ_lt_original (B N0 : ℕ) : commonQ B N0 < ActualCandidateConstruction.qbig B N0 := by | |
| 137 | + have he := ActualCandidateConstruction.twice_residual_scale B N0 | |
| 138 | + have hp := commonQ_pos B N0 | |
| 139 | + change 2 * commonQ B N0 = _ at he | |
| 140 | + linarith | |
| 141 | + | |
| 142 | +end NavierStokes.WholeDomainStageBounds | |
| 143 | +end | |
| 144 | + | |
| 145 | +end | |
| 146 | + | |
| 4 | 147 | noncomputable section |
| 5 | 148 | |
| 6 | 149 | namespace NavierStokes.WholeDomainStageBounds |
+80 −1 NavierStokes/WholeDomainPhysicalCompact.lean View file
| @@ -1,6 +1,85 @@ | ||
| 1 | -import NavierStokes.WholeDomainCompactBounds | |
| 1 | +import NavierStokes.JointResidualLimits | |
| 2 | +import NavierStokes.DiagonalResidual | |
| 3 | +import Mathlib.Analysis.SpecialFunctions.Pow.Continuity | |
| 2 | 4 | import NavierStokes.PhysicalStageBounds |
| 3 | 5 | |
| 6 | +/-! ## From `NavierStokes/WholeDomainCompactBounds.lean` | |
| 7 | + | |
| 8 | +The text of `NavierStokes/WholeDomainCompactBounds.lean`, folded into this file, which was its only importer. -/ | |
| 9 | + | |
| 10 | +section | |
| 11 | + | |
| 12 | +/-! | |
| 13 | +# Uniform bounds on the common finite-stage domain | |
| 14 | + | |
| 15 | +Local endpoint estimates are upgraded on a fixed compact set without changing | |
| 16 | +the domain with the requested derivative order. The compactness argument uses | |
| 17 | +the actual derivatives, and allows a different local constant at every point. | |
| 18 | +-/ | |
| 19 | + | |
| 20 | +noncomputable section | |
| 21 | + | |
| 22 | +namespace NavierStokes.WholeDomainStageBounds | |
| 23 | + | |
| 24 | +open Set Filter Function ProblemStatement | |
| 25 | +open scoped Topology ContDiff BigOperators | |
| 26 | + | |
| 27 | +section CompactBounds | |
| 28 | + | |
| 29 | +variable {D V : Type*} [NormedAddCommGroup D] [NormedSpace ℝ D] | |
| 30 | + [NormedAddCommGroup V] [NormedSpace ℝ V] | |
| 31 | + | |
| 32 | +end CompactBounds | |
| 33 | + | |
| 34 | +section LocalRates | |
| 35 | + | |
| 36 | +variable {D V : Type*} [NormedAddCommGroup D] [NormedSpace ℝ D] | |
| 37 | + [NormedAddCommGroup V] [NormedSpace ℝ V] | |
| 38 | + | |
| 39 | +/-- A finite jet limit at a positive limiting scale gives every power rate. -/ | |
| 40 | +theorem rate_of_jet_limit {l : Filter D} {f : D → V} {q : D → ℝ} {m : ℕ} | |
| 41 | + {J : D [×m]→L[ℝ] V} {q₀ : ℝ} (hJ : Tendsto (iteratedFDeriv ℝ m f) l (𝓝 J)) | |
| 42 | + (hq : Tendsto q l (𝓝 q₀)) (hq₀ : 0 < q₀) (r : ℝ) : | |
| 43 | + DiagonalResidual.JetRate l q f m r := by | |
| 44 | + have hb := (hJ.norm.mul (hq.rpow_const (Or.inl hq₀.ne'))).eventually | |
| 45 | + (gt_mem_nhds (lt_add_one (‖J‖ * q₀ ^ (-r)))) | |
| 46 | + refine ⟨‖J‖ * q₀ ^ (-r) + 1, by positivity, ?_⟩ | |
| 47 | + filter_upwards [hb, hq.eventually (lt_mem_nhds hq₀)] with x hx hqx | |
| 48 | + have he : (‖iteratedFDeriv ℝ m f x‖ * q x ^ (-r)) * q x ^ r = | |
| 49 | + ‖iteratedFDeriv ℝ m f x‖ := by | |
| 50 | + rw [mul_assoc, ← Real.rpow_add hqx, neg_add_cancel, Real.rpow_zero, mul_one] | |
| 51 | + exact he ▸ mul_le_mul_of_nonneg_right hx.le (Real.rpow_nonneg hqx.le r) | |
| 52 | + | |
| 53 | +end LocalRates | |
| 54 | + | |
| 55 | +/-- Smooth one-sided velocity and pressure extensions extend the actual | |
| 56 | +residual, including the derivatives occurring in its definition. -/ | |
| 57 | +noncomputable def residualExtension {u : VelocityField} {p : PressureField} {x : Space} | |
| 58 | + (U : JointResidualLimits.OneSidedExtension u x) | |
| 59 | + (P : JointResidualLimits.OneSidedExtension p x) : | |
| 60 | + JointResidualLimits.OneSidedExtension | |
| 61 | + (fun w => navierStokesResidual u p w.1 w.2) x where | |
| 62 | + value := fun w => navierStokesResidual U.value P.value w.1 w.2 | |
| 63 | + domain := U.domain ∩ P.domain | |
| 64 | + isOpen := U.isOpen.inter P.isOpen | |
| 65 | + mem := ⟨U.mem, P.mem⟩ | |
| 66 | + smooth := ResidualRegularity.contDiffOn_residual (U.isOpen.inter P.isOpen) | |
| 67 | + (U.smooth.mono inter_subset_left) (P.smooth.mono inter_subset_right) | |
| 68 | + agrees := by | |
| 69 | + intro w hw | |
| 70 | + have hU : U.value =ᶠ[𝓝 w] u := | |
| 71 | + Filter.eventuallyEq_of_mem ((U.isOpen.inter (SpacetimeEndpoint.openPast_isOpen 1)).mem_nhds | |
| 72 | + ⟨hw.1.1, hw.2⟩) U.agrees | |
| 73 | + have hP : P.value =ᶠ[𝓝 w] p := | |
| 74 | + Filter.eventuallyEq_of_mem ((P.isOpen.inter (SpacetimeEndpoint.openPast_isOpen 1)).mem_nhds | |
| 75 | + ⟨hw.1.2, hw.2⟩) P.agrees | |
| 76 | + exact (ResidualRegularity.residual_eventuallyEq hU hP).self_of_nhds | |
| 77 | + | |
| 78 | +end NavierStokes.WholeDomainStageBounds | |
| 79 | +end | |
| 80 | + | |
| 81 | +end | |
| 82 | + | |
| 4 | 83 | noncomputable section |
| 5 | 84 | namespace NavierStokes.WholeDomainStageBounds |
| 6 | 85 | open Set Filter Function ProblemStatement |
+0 −103 NavierStokes/WholeDomainStageBounds.lean deleted
| @@ -1,103 +0,0 @@ | ||
| 1 | -import NavierStokes.WholeDomainPhysicalCompact | |
| 2 | -import NavierStokes.ActualCycleResidualBounds | |
| 3 | -import NavierStokes.PhysicalStageBounds | |
| 4 | -import NavierStokes.AnnularEndpoint | |
| 5 | - | |
| 6 | -noncomputable section | |
| 7 | - | |
| 8 | -namespace NavierStokes.WholeDomainStageBounds | |
| 9 | - | |
| 10 | -open Set Filter Function ProblemStatement | |
| 11 | -open scoped Topology ContDiff BigOperators | |
| 12 | - | |
| 13 | -open PhysicalWaveSum | |
| 14 | - | |
| 15 | -section BaseResidual | |
| 16 | - | |
| 17 | -open CorrectionInitialization CorrectionInitialization.ActualPrimary ActualCycleResidualBounds | |
| 18 | - | |
| 19 | -private abbrev baseResidual (B : ℕ) : VelocityField := | |
| 20 | - PhysicalResidualJetBounds.residual (FinalSlowBase.velocity certificate modulation upper B) | |
| 21 | - (FinalSlowBase.pressure certificate modulation upper B) | |
| 22 | - | |
| 23 | -private def exteriorDomain : Set SpaceTime := | |
| 24 | - {w | w ∈ preterminal ∧ physicalQ h w ≤ 1 ∧ w ∉ active} | |
| 25 | - | |
| 26 | -private theorem exteriorDomain_past : exteriorDomain ⊆ SpacetimeEndpoint.openPast 1 := | |
| 27 | - fun _ hw => ⟨hw.1, Set.mem_univ _⟩ | |
| 28 | - | |
| 29 | -private theorem baseResidual_smooth (B : ℕ) : | |
| 30 | - ContDiffOn ℝ ∞ (baseResidual B) (SpacetimeEndpoint.openPast 1) := | |
| 31 | - ResidualRegularity.contDiffOn_residual (SpacetimeEndpoint.openPast_isOpen 1) | |
| 32 | - (FinalSlowBase.velocity_smooth certificate modulation upper B) | |
| 33 | - (FinalSlowBase.pressure_smooth certificate modulation upper B) | |
| 34 | - | |
| 35 | -/-- At nonzero limiting axial coordinate the genuine endpoint chart has | |
| 36 | -a positive limiting scale. -/ | |
| 37 | -theorem physicalQ_tendsto_offplane {x : Space} (hx : x 2 ≠ 0) : | |
| 38 | - Tendsto (physicalQ h) (𝓝[SpacetimeEndpoint.openPast 1] (1,x)) | |
| 39 | - (𝓝 ((EndpointCoordinates.cartesianExtension h (1,x)).1)) := by | |
| 40 | - have hc := (EndpointCoordinates.cartesianExtension_smoothAt outgoing.data.h_pos | |
| 41 | - outgoing.data.h_lt_half (EndpointCoordinates.cartesian_endpoint_mem | |
| 42 | - outgoing.data.h_pos outgoing.data.h_lt_half hx)).continuousAt.fst | |
| 43 | - apply (hc.tendsto.mono_left nhdsWithin_le_nhds).congr' | |
| 44 | - filter_upwards [self_mem_nhdsWithin] with w hw | |
| 45 | - exact congrArg Prod.fst (EndpointCoordinates.cartesianExtension_eq_physical | |
| 46 | - outgoing.data.h_pos outgoing.data.h_lt_half hw.1) | |
| 47 | - | |
| 48 | -private theorem baseResidual_local_rate (B m : ℕ) (r : ℝ) (w : SpaceTime) : | |
| 49 | - DiagonalResidual.JetRate (𝓝[exteriorDomain] w) (physicalQ h) (baseResidual B) m r := by | |
| 50 | - rcases w with ⟨t,x⟩ | |
| 51 | - rcases lt_trichotomy t 1 with ht | ht | ht | |
| 52 | - · have hs := (baseResidual_smooth B).contDiffAt | |
| 53 | - ((SpacetimeEndpoint.openPast_isOpen 1).mem_nhds | |
| 54 | - (show (t,x) ∈ SpacetimeEndpoint.openPast 1 from ⟨ht, mem_univ x⟩)) | |
| 55 | - have hj : ContDiffAt ℝ 0 (iteratedFDeriv ℝ m (baseResidual B)) (t,x) := | |
| 56 | - hs.iteratedFDeriv_right (by exact_mod_cast (le_top : 0 + (m : ℕ∞) ≤ ⊤)) | |
| 57 | - exact rate_of_jet_limit (hj.continuousAt.tendsto.mono_left nhdsWithin_le_nhds) | |
| 58 | - ((physicalQ_smoothAt outgoing.data.h_pos outgoing.data.h_lt_half ht).continuousAt.tendsto.mono_left | |
| 59 | - nhdsWithin_le_nhds) (physicalQ_pos outgoing.data.h_pos outgoing.data.h_lt_half ht) r | |
| 60 | - · subst t | |
| 61 | - have hmono : 𝓝[exteriorDomain] ((1:ℝ),x) ≤ | |
| 62 | - 𝓝[SpacetimeEndpoint.openPast 1] ((1:ℝ),x) := nhdsWithin_mono _ exteriorDomain_past | |
| 63 | - by_cases hz : x 2 = 0 | |
| 64 | - · have hcarrier : ∀ᶠ y in 𝓝[exteriorDomain] ((1:ℝ),x), | |
| 65 | - y ∈ Metric.closedBall ((1:ℝ),x) 1 := | |
| 66 | - nhdsWithin_le_nhds (Metric.closedBall_mem_nhds _ zero_lt_one) | |
| 67 | - have hpast : ∀ᶠ y in 𝓝[exteriorDomain] ((1:ℝ),x), y.1 < 1 := by | |
| 68 | - filter_upwards [self_mem_nhdsWithin] with y hy | |
| 69 | - exact hy.1 | |
| 70 | - have hscale := (AnnularEndpoint.physicalQ_tendsto_zero outgoing.data.h_pos | |
| 71 | - outgoing.data.h_lt_half hz).mono_left hmono | |
| 72 | - obtain ⟨C,hC,hb⟩ := GlobalBaseError.error_jetRate certificate modulation upper B | |
| 73 | - actual_upper_covers_exterior (isCompact_closedBall _ _) hcarrier hpast hscale | |
| 74 | - m (max r 0) (le_max_right _ _) | |
| 75 | - refine ⟨C,hC,?_⟩ | |
| 76 | - filter_upwards [hb,self_mem_nhdsWithin] with y hy hyS | |
| 77 | - rw [iteratedFDeriv_eq_of_eventuallyEq | |
| 78 | - (base_residual_germ B hyS.1 hyS.2.2) m] | |
| 79 | - exact hy.trans (mul_le_mul_of_nonneg_left | |
| 80 | - (Real.rpow_le_rpow_of_exponent_ge | |
| 81 | - (physicalQ_pos outgoing.data.h_pos outgoing.data.h_lt_half hyS.1) | |
| 82 | - hyS.2.1 (le_max_left _ _)) hC) | |
| 83 | - · let U := SlowBaseEndpoint.finalVelocityNonzeroAxial certificate modulation upper B hz | |
| 84 | - let P := SlowBaseEndpoint.finalPressureNonzeroAxial certificate modulation upper B hz | |
| 85 | - have hp := EndpointCoordinates.cartesianExtension_pos | |
| 86 | - (EndpointCoordinates.cartesian_endpoint_mem outgoing.data.h_pos outgoing.data.h_lt_half hz) | |
| 87 | - exact rate_of_jet_limit ((residualExtension U P).jet_tendsto m |>.mono_left hmono) | |
| 88 | - ((physicalQ_tendsto_offplane hz).mono_left hmono) hp r | |
| 89 | - · refine ⟨0,le_rfl,?_⟩ | |
| 90 | - have hn : {y : SpaceTime | 1 < y.1} ∈ 𝓝 ((t:ℝ),x) := | |
| 91 | - (isOpen_lt continuous_const continuous_fst).mem_nhds ht | |
| 92 | - filter_upwards [nhdsWithin_le_nhds hn,self_mem_nhdsWithin] with y hy hyS | |
| 93 | - exact False.elim (not_lt_of_ge hy.le hyS.1) | |
| 94 | - | |
| 95 | -end BaseResidual | |
| 96 | - | |
| 97 | -section ResidualAssembly | |
| 98 | - | |
| 99 | -open ActualCycleResidualBounds PhysicalResidualJetBounds CorrectionInitialization | |
| 100 | - | |
| 101 | -end ResidualAssembly | |
| 102 | - | |
| 103 | -end NavierStokes.WholeDomainStageBounds | |
+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-whole-1/README.md added View file
| @@ -0,0 +1,18 @@ | ||
| 1 | +--- | |
| 2 | +issue: 14 | |
| 3 | +status: working | |
| 4 | +--- | |
| 5 | +# s5-ns-whole-1 | |
| 6 | + | |
| 7 | +One unit of S-5 (#14): the `NavierStokes/Whole*` family. The kind of change is Lean Pool's "fewer modules". Six small | |
| 8 | +modules that exactly one file each imported are folded, text unchanged, into that file: | |
| 9 | +`WholeDomainHeatGeometry`, `WholeDomainHeatCompact` and `WholeDomainHeatScaling` into | |
| 10 | +`NavierStokes/WholeDomainHeatBounds.lean`; `WholeDomainStageBounds` and `WholeDomainActualStageBounds` into | |
| 11 | +`NavierStokes/WholeDomainInitializationBounds.lean`; and `WholeDomainCompactBounds` into | |
| 12 | +`NavierStokes/WholeDomainPhysicalCompact.lean`. Each module's text sits under a heading that names where it came from | |
| 13 | +and in a `section` of its own, before the file's own text. `plan.json` is here; the tool that does the fold and its | |
| 14 | +pages are in `docs/s5-folding`. | |
| 15 | + | |
| 16 | +## Next | |
| 17 | + | |
| 18 | +The pull request is open; `challenge` and `build` judge it. Nothing is left to change by hand. | |
+20 −0 routes/s5-ns-whole-1/plan.json added View file
| @@ -0,0 +1,20 @@ | ||
| 1 | +{ | |
| 2 | +"imports": "in place", | |
| 3 | +"folds": { | |
| 4 | +"NavierStokes/WholeDomainHeatBounds.lean": [ | |
| 5 | +"NavierStokes/WholeDomainHeatGeometry.lean", | |
| 6 | +"NavierStokes/WholeDomainHeatCompact.lean", | |
| 7 | +"NavierStokes/WholeDomainHeatScaling.lean", | |
| 8 | +"NavierStokes/WholeDomainHeatBounds.lean" | |
| 9 | +], | |
| 10 | +"NavierStokes/WholeDomainInitializationBounds.lean": [ | |
| 11 | +"NavierStokes/WholeDomainStageBounds.lean", | |
| 12 | +"NavierStokes/WholeDomainActualStageBounds.lean", | |
| 13 | +"NavierStokes/WholeDomainInitializationBounds.lean" | |
| 14 | +], | |
| 15 | +"NavierStokes/WholeDomainPhysicalCompact.lean": [ | |
| 16 | +"NavierStokes/WholeDomainCompactBounds.lean", | |
| 17 | +"NavierStokes/WholeDomainPhysicalCompact.lean" | |
| 18 | +] | |
| 19 | +} | |
| 20 | +} | |