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/Positive): 1 small module folded into the file that imports it (−25.5%, measured)
Browse filesFold NavierStokes/PositiveTimeSignedLocalization.lean (108 lines, its only importer is NavierStokes/PositiveTimeSignedData.lean) into that file, text unchanged, under a heading naming it and in a section of its own; the file takes over its imports and the module is deleted. Plan in routes/s5-ns-positive-1/plan.json; docs/s5-folding brings the tool and the statements section as the rest of the series does. Co-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
ci/docs
Details
+117 −1 NavierStokes/PositiveTimeSignedData.lean View file
| @@ -1,6 +1,8 @@ | ||
| 1 | 1 | import NavierStokes.ActualSignedPhysicalData |
| 2 | 2 | import NavierStokes.PositiveTimeCopyFamily |
| 3 | -import NavierStokes.PositiveTimeSignedLocalization | |
| 3 | +import NavierStokes.ActualSignedPhysicalBinding | |
| 4 | +import NavierStokes.ActualWaveRegularityData | |
| 5 | +import NavierStokes.InitialPhysicalData | |
| 4 | 6 | import NavierStokes.ActualSignedNativeProfiles |
| 5 | 7 | |
| 6 | 8 | /-! |
| @@ -13,6 +15,120 @@ positive native time, while retaining the original masks, sources, and | ||
| 13 | 15 | carrier profiles on their genuine domains. |
| 14 | 16 | -/ |
| 15 | 17 | |
| 18 | +/-! ## From `NavierStokes/PositiveTimeSignedLocalization.lean` | |
| 19 | + | |
| 20 | +The text of `NavierStokes/PositiveTimeSignedLocalization.lean`, folded into this file, which was its only importer. -/ | |
| 21 | + | |
| 22 | +section | |
| 23 | + | |
| 24 | +/-! | |
| 25 | +# Localization of the actual signed inputs at positive native time | |
| 26 | + | |
| 27 | +The fixed primary's mask and target localize its native point. Positive | |
| 28 | +native time is an explicit premise; no support assertion is made for the | |
| 29 | +totalized formulas outside that domain. | |
| 30 | +-/ | |
| 31 | + | |
| 32 | +noncomputable section | |
| 33 | + | |
| 34 | +namespace NavierStokes.PositiveTimeSignedLocalization | |
| 35 | + | |
| 36 | +open Set Function | |
| 37 | +open CorrectionInitialization CorrectionInitialization.ActualPrimary | |
| 38 | + | |
| 39 | +abbrev Label := ActualSignedPhysicalBinding.Label | |
| 40 | +abbrev Native := ActualSignedPhysicalData.Native | |
| 41 | + | |
| 42 | +variable {B N0 : ℕ} | |
| 43 | + | |
| 44 | +theorem profileRadius_eq (y : Native) : | |
| 45 | + PrimaryTargetBounds.profileRadius h (ActualSignedPhysicalData.nativeSlow y) = | |
| 46 | + y.1 / Real.sqrt (SimilarityCoordinates.coordinateQ (2 * h) y.2.1) := by | |
| 47 | + rw [PrimaryTargetBounds.profileRadius, BaseChartJets.normalizedCoordinates_eq] | |
| 48 | + rfl | |
| 49 | + | |
| 50 | +/-- The actual dyadic mask is supported strictly inside its two endpoints. -/ | |
| 51 | +theorem mask_q_mem (l : Label B N0) (y : Native) | |
| 52 | + (hm : (ActualSignedPhysicalBinding.primary l).mask | |
| 53 | + (ActualSignedPhysicalBinding.reference l) (ActualSignedPhysicalData.nativeCylinder y) ≠ 0) : | |
| 54 | + SimilarityCoordinates.coordinateQ (2 * h) y.2.1 ∈ Ioo (1 / 2 : ℝ) 2 := by | |
| 55 | + exact spatialMask_q_range l.1 (ActualSignedPhysicalData.nativeSlow y) hm | |
| 56 | + | |
| 57 | +/-- Positivity comes from the same chosen prepared carrier, without an | |
| 58 | +additional nondegeneracy premise on the signed output. -/ | |
| 59 | +theorem mask_radius_pos (l : Label B N0) (y : Native) (hT : 0 < y.2.1.1) | |
| 60 | + (hm : (ActualSignedPhysicalBinding.primary l).mask | |
| 61 | + (ActualSignedPhysicalBinding.reference l) (ActualSignedPhysicalData.nativeCylinder y) ≠ 0) : | |
| 62 | + 0 < y.1 := by | |
| 63 | + exact (choice B N0).prepared.radius_pos l.1 (ActualSignedPhysicalData.nativeSlow y) | |
| 64 | + (spatialMask_carrier l.1 hT hm) | |
| 65 | + | |
| 66 | +/-- Nonzero actual target forces the normalized radius into the open | |
| 67 | +nominal active annulus. The endpoint zeros are used exactly. -/ | |
| 68 | +theorem normalized_radius_mem (l : Label B N0) (y : Native) (hT : 0 < y.2.1.1) | |
| 69 | + (hm : (ActualSignedPhysicalBinding.primary l).mask | |
| 70 | + (ActualSignedPhysicalBinding.reference l) (ActualSignedPhysicalData.nativeCylinder y) ≠ 0) | |
| 71 | + (ht : (ActualSignedPhysicalBinding.primary l).target | |
| 72 | + (ActualSignedPhysicalBinding.reference l) (ActualSignedPhysicalData.nativeCylinder y) ≠ 0) : | |
| 73 | + y.1 / Real.sqrt (SimilarityCoordinates.coordinateQ (2 * h) y.2.1) ∈ | |
| 74 | + Ioo (PrimaryTargetBounds.leftRadius nominal) (PrimaryTargetBounds.rightRadius nominal) := by | |
| 75 | + by_contra ho | |
| 76 | + have hz := ActualWaveRegularityData.target_zero_outside | |
| 77 | + (p := ActualSignedPhysicalData.nativeSlow y) hT (mask_radius_pos l y hT hm) | |
| 78 | + (by simpa only [profileRadius_eq] using ho) | |
| 79 | + apply ht | |
| 80 | + change (fun j => PrimaryTargetBounds.actualTarget modulation | |
| 81 | + (ActualSignedPhysicalData.nativeSlow y) j) = 0 | |
| 82 | + simp only [hz, WithLp.ofLp_zero, Pi.zero_apply] | |
| 83 | + rfl | |
| 84 | + | |
| 85 | +/-- The inequalities in the positive-time localization interface. -/ | |
| 86 | +theorem normalized_bounds (l : Label B N0) (y : Native) (hT : 0 < y.2.1.1) | |
| 87 | + (hm : (ActualSignedPhysicalBinding.primary l).mask | |
| 88 | + (ActualSignedPhysicalBinding.reference l) (ActualSignedPhysicalData.nativeCylinder y) ≠ 0) | |
| 89 | + (ht : (ActualSignedPhysicalBinding.primary l).target | |
| 90 | + (ActualSignedPhysicalBinding.reference l) (ActualSignedPhysicalData.nativeCylinder y) ≠ 0) : | |
| 91 | + 1 / 2 ≤ SimilarityCoordinates.coordinateQ (2 * h) y.2.1 ∧ | |
| 92 | + SimilarityCoordinates.coordinateQ (2 * h) y.2.1 ≤ 2 ∧ | |
| 93 | + PrimaryTargetBounds.leftRadius nominal ≤ | |
| 94 | + y.1 / Real.sqrt (SimilarityCoordinates.coordinateQ (2 * h) y.2.1) ∧ | |
| 95 | + y.1 / Real.sqrt (SimilarityCoordinates.coordinateQ (2 * h) y.2.1) ≤ | |
| 96 | + PrimaryTargetBounds.rightRadius nominal := | |
| 97 | + ⟨(mask_q_mem l y hm).1.le, (mask_q_mem l y hm).2.le, | |
| 98 | + (normalized_radius_mem l y hT hm ht).1.le, (normalized_radius_mem l y hT hm ht).2.le⟩ | |
| 99 | + | |
| 100 | +/-- Membership is in the actual moving strip, with the same fixed primary | |
| 101 | +annulus and slow region used by the native signed estimates. -/ | |
| 102 | +theorem native_mem_strip (l : Label B N0) (y : Native) (hT : 0 < y.2.1.1) | |
| 103 | + (hm : (ActualSignedPhysicalBinding.primary l).mask | |
| 104 | + (ActualSignedPhysicalBinding.reference l) (ActualSignedPhysicalData.nativeCylinder y) ≠ 0) | |
| 105 | + (ht : (ActualSignedPhysicalBinding.primary l).target | |
| 106 | + (ActualSignedPhysicalBinding.reference l) (ActualSignedPhysicalData.nativeCylinder y) ≠ 0) : | |
| 107 | + y ∈ ActualPrimaryBounds.strip.domain := by | |
| 108 | + apply (BaseContextAssembly.nativeStrip_mem nominal ActualPrimaryBounds.region y).mpr | |
| 109 | + refine ⟨⟨hT, mask_q_mem l y hm⟩, ?_⟩ | |
| 110 | + change PrimaryTargetBounds.profileRadius h (ActualSignedPhysicalData.nativeSlow y) ∈ _ | |
| 111 | + rw [profileRadius_eq] | |
| 112 | + exact normalized_radius_mem l y hT hm ht | |
| 113 | + | |
| 114 | +/-- The same selected mask pulls back to the literal physical label mask | |
| 115 | +at every preterminal Cartesian point. -/ | |
| 116 | +theorem mask_pullback (l : Label B N0) (w : ProblemStatement.SpaceTime) | |
| 117 | + (hw : w ∈ PhysicalWaveSum.preterminal) : | |
| 118 | + (ActualSignedPhysicalBinding.primary l).mask (ActualSignedPhysicalBinding.reference l) | |
| 119 | + (ActualSignedPhysicalData.cylinderZero | |
| 120 | + (PhysicalGraphBounds.physicalLift h (ActualSignedPhysicalBinding.reference l) w)) = | |
| 121 | + PhysicalWaveSum.physicalMask (CoordinateAlgebra.D h) | |
| 122 | + (ActualSignedPhysicalBinding.spatialLabel l) (PhysicalWaveSum.physicalParams h w) := by | |
| 123 | + have hm := InitialPhysicalData.spatialMask_physical (l.2, l.1) 0 hw | |
| 124 | + rw [ActualSignedPhysicalData.commonLift_zero] at hm | |
| 125 | + exact hm | |
| 126 | + | |
| 127 | +end NavierStokes.PositiveTimeSignedLocalization | |
| 128 | +end | |
| 129 | + | |
| 130 | +end | |
| 131 | + | |
| 16 | 132 | noncomputable section |
| 17 | 133 | |
| 18 | 134 | namespace NavierStokes.PositiveTimeSignedData |
+0 −108 NavierStokes/PositiveTimeSignedLocalization.lean deleted
| @@ -1,108 +0,0 @@ | ||
| 1 | -import NavierStokes.ActualSignedPhysicalBinding | |
| 2 | -import NavierStokes.ActualWaveRegularityData | |
| 3 | -import NavierStokes.InitialPhysicalData | |
| 4 | - | |
| 5 | -/-! | |
| 6 | -# Localization of the actual signed inputs at positive native time | |
| 7 | - | |
| 8 | -The fixed primary's mask and target localize its native point. Positive | |
| 9 | -native time is an explicit premise; no support assertion is made for the | |
| 10 | -totalized formulas outside that domain. | |
| 11 | --/ | |
| 12 | - | |
| 13 | -noncomputable section | |
| 14 | - | |
| 15 | -namespace NavierStokes.PositiveTimeSignedLocalization | |
| 16 | - | |
| 17 | -open Set Function | |
| 18 | -open CorrectionInitialization CorrectionInitialization.ActualPrimary | |
| 19 | - | |
| 20 | -abbrev Label := ActualSignedPhysicalBinding.Label | |
| 21 | -abbrev Native := ActualSignedPhysicalData.Native | |
| 22 | - | |
| 23 | -variable {B N0 : ℕ} | |
| 24 | - | |
| 25 | -theorem profileRadius_eq (y : Native) : | |
| 26 | - PrimaryTargetBounds.profileRadius h (ActualSignedPhysicalData.nativeSlow y) = | |
| 27 | - y.1 / Real.sqrt (SimilarityCoordinates.coordinateQ (2 * h) y.2.1) := by | |
| 28 | - rw [PrimaryTargetBounds.profileRadius, BaseChartJets.normalizedCoordinates_eq] | |
| 29 | - rfl | |
| 30 | - | |
| 31 | -/-- The actual dyadic mask is supported strictly inside its two endpoints. -/ | |
| 32 | -theorem mask_q_mem (l : Label B N0) (y : Native) | |
| 33 | - (hm : (ActualSignedPhysicalBinding.primary l).mask | |
| 34 | - (ActualSignedPhysicalBinding.reference l) (ActualSignedPhysicalData.nativeCylinder y) ≠ 0) : | |
| 35 | - SimilarityCoordinates.coordinateQ (2 * h) y.2.1 ∈ Ioo (1 / 2 : ℝ) 2 := by | |
| 36 | - exact spatialMask_q_range l.1 (ActualSignedPhysicalData.nativeSlow y) hm | |
| 37 | - | |
| 38 | -/-- Positivity comes from the same chosen prepared carrier, without an | |
| 39 | -additional nondegeneracy premise on the signed output. -/ | |
| 40 | -theorem mask_radius_pos (l : Label B N0) (y : Native) (hT : 0 < y.2.1.1) | |
| 41 | - (hm : (ActualSignedPhysicalBinding.primary l).mask | |
| 42 | - (ActualSignedPhysicalBinding.reference l) (ActualSignedPhysicalData.nativeCylinder y) ≠ 0) : | |
| 43 | - 0 < y.1 := by | |
| 44 | - exact (choice B N0).prepared.radius_pos l.1 (ActualSignedPhysicalData.nativeSlow y) | |
| 45 | - (spatialMask_carrier l.1 hT hm) | |
| 46 | - | |
| 47 | -/-- Nonzero actual target forces the normalized radius into the open | |
| 48 | -nominal active annulus. The endpoint zeros are used exactly. -/ | |
| 49 | -theorem normalized_radius_mem (l : Label B N0) (y : Native) (hT : 0 < y.2.1.1) | |
| 50 | - (hm : (ActualSignedPhysicalBinding.primary l).mask | |
| 51 | - (ActualSignedPhysicalBinding.reference l) (ActualSignedPhysicalData.nativeCylinder y) ≠ 0) | |
| 52 | - (ht : (ActualSignedPhysicalBinding.primary l).target | |
| 53 | - (ActualSignedPhysicalBinding.reference l) (ActualSignedPhysicalData.nativeCylinder y) ≠ 0) : | |
| 54 | - y.1 / Real.sqrt (SimilarityCoordinates.coordinateQ (2 * h) y.2.1) ∈ | |
| 55 | - Ioo (PrimaryTargetBounds.leftRadius nominal) (PrimaryTargetBounds.rightRadius nominal) := by | |
| 56 | - by_contra ho | |
| 57 | - have hz := ActualWaveRegularityData.target_zero_outside | |
| 58 | - (p := ActualSignedPhysicalData.nativeSlow y) hT (mask_radius_pos l y hT hm) | |
| 59 | - (by simpa only [profileRadius_eq] using ho) | |
| 60 | - apply ht | |
| 61 | - change (fun j => PrimaryTargetBounds.actualTarget modulation | |
| 62 | - (ActualSignedPhysicalData.nativeSlow y) j) = 0 | |
| 63 | - simp only [hz, WithLp.ofLp_zero, Pi.zero_apply] | |
| 64 | - rfl | |
| 65 | - | |
| 66 | -/-- The inequalities in the positive-time localization interface. -/ | |
| 67 | -theorem normalized_bounds (l : Label B N0) (y : Native) (hT : 0 < y.2.1.1) | |
| 68 | - (hm : (ActualSignedPhysicalBinding.primary l).mask | |
| 69 | - (ActualSignedPhysicalBinding.reference l) (ActualSignedPhysicalData.nativeCylinder y) ≠ 0) | |
| 70 | - (ht : (ActualSignedPhysicalBinding.primary l).target | |
| 71 | - (ActualSignedPhysicalBinding.reference l) (ActualSignedPhysicalData.nativeCylinder y) ≠ 0) : | |
| 72 | - 1 / 2 ≤ SimilarityCoordinates.coordinateQ (2 * h) y.2.1 ∧ | |
| 73 | - SimilarityCoordinates.coordinateQ (2 * h) y.2.1 ≤ 2 ∧ | |
| 74 | - PrimaryTargetBounds.leftRadius nominal ≤ | |
| 75 | - y.1 / Real.sqrt (SimilarityCoordinates.coordinateQ (2 * h) y.2.1) ∧ | |
| 76 | - y.1 / Real.sqrt (SimilarityCoordinates.coordinateQ (2 * h) y.2.1) ≤ | |
| 77 | - PrimaryTargetBounds.rightRadius nominal := | |
| 78 | - ⟨(mask_q_mem l y hm).1.le, (mask_q_mem l y hm).2.le, | |
| 79 | - (normalized_radius_mem l y hT hm ht).1.le, (normalized_radius_mem l y hT hm ht).2.le⟩ | |
| 80 | - | |
| 81 | -/-- Membership is in the actual moving strip, with the same fixed primary | |
| 82 | -annulus and slow region used by the native signed estimates. -/ | |
| 83 | -theorem native_mem_strip (l : Label B N0) (y : Native) (hT : 0 < y.2.1.1) | |
| 84 | - (hm : (ActualSignedPhysicalBinding.primary l).mask | |
| 85 | - (ActualSignedPhysicalBinding.reference l) (ActualSignedPhysicalData.nativeCylinder y) ≠ 0) | |
| 86 | - (ht : (ActualSignedPhysicalBinding.primary l).target | |
| 87 | - (ActualSignedPhysicalBinding.reference l) (ActualSignedPhysicalData.nativeCylinder y) ≠ 0) : | |
| 88 | - y ∈ ActualPrimaryBounds.strip.domain := by | |
| 89 | - apply (BaseContextAssembly.nativeStrip_mem nominal ActualPrimaryBounds.region y).mpr | |
| 90 | - refine ⟨⟨hT, mask_q_mem l y hm⟩, ?_⟩ | |
| 91 | - change PrimaryTargetBounds.profileRadius h (ActualSignedPhysicalData.nativeSlow y) ∈ _ | |
| 92 | - rw [profileRadius_eq] | |
| 93 | - exact normalized_radius_mem l y hT hm ht | |
| 94 | - | |
| 95 | -/-- The same selected mask pulls back to the literal physical label mask | |
| 96 | -at every preterminal Cartesian point. -/ | |
| 97 | -theorem mask_pullback (l : Label B N0) (w : ProblemStatement.SpaceTime) | |
| 98 | - (hw : w ∈ PhysicalWaveSum.preterminal) : | |
| 99 | - (ActualSignedPhysicalBinding.primary l).mask (ActualSignedPhysicalBinding.reference l) | |
| 100 | - (ActualSignedPhysicalData.cylinderZero | |
| 101 | - (PhysicalGraphBounds.physicalLift h (ActualSignedPhysicalBinding.reference l) w)) = | |
| 102 | - PhysicalWaveSum.physicalMask (CoordinateAlgebra.D h) | |
| 103 | - (ActualSignedPhysicalBinding.spatialLabel l) (PhysicalWaveSum.physicalParams h w) := by | |
| 104 | - have hm := InitialPhysicalData.spatialMask_physical (l.2, l.1) 0 hw | |
| 105 | - rw [ActualSignedPhysicalData.commonLift_zero] at hm | |
| 106 | - exact hm | |
| 107 | - | |
| 108 | -end NavierStokes.PositiveTimeSignedLocalization | |
+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-ns-positive-1/README.md added View file
| @@ -0,0 +1,11 @@ | ||
| 1 | +--- | |
| 2 | +issue: 14 | |
| 3 | +status: working | |
| 4 | +--- | |
| 5 | +# s5-ns-positive-1 | |
| 6 | + | |
| 7 | +One unit of S-5 (bring over a change from Lean Pool's cleaned copy), the "fewer modules" kind: fold a small module that exactly one file imports into that file, its text unchanged. The family is `NavierStokes/Positive*`: `NavierStokes/PositiveTimeSignedLocalization.lean` (108 lines, one importer) is folded into `NavierStokes/PositiveTimeSignedData.lean`. Its imports move to where its import line stood, its text sits under a heading naming it in a `section` of its own, and the module is deleted. Nothing else changes; the plan is `plan.json` beside this note. | |
| 8 | + | |
| 9 | +## Next | |
| 10 | + | |
| 11 | +Push `s5-ns-positive-1` and open the pull request into `main` with `Part of #14` in the description; then let `challenge` and `build` report. | |
+9 −0 routes/s5-ns-positive-1/plan.json added View file
| @@ -0,0 +1,9 @@ | ||
| 1 | +{ | |
| 2 | +"imports": "in place", | |
| 3 | +"folds": { | |
| 4 | +"NavierStokes/PositiveTimeSignedData.lean": [ | |
| 5 | +"NavierStokes/PositiveTimeSignedLocalization.lean", | |
| 6 | +"NavierStokes/PositiveTimeSignedData.lean" | |
| 7 | +] | |
| 8 | +} | |
| 9 | +} | |