Riemann hypothesis: the Lean proof, cleaned up together
The 2026 Lean proof of the Riemann hypothesis and GRH, machine-checked by others, not refereed, no word from Clay; cleaned up together: more readable, faster to build, the theorems unchanged

chore(Guide): check glossary rows 1-20 against the code #47
Open
+75 −0 routes/p6-glossary-rows-1-20/README.md added View file
| @@ -0,0 +1,75 @@ | ||
| 1 | +--- | |
| 2 | +issue: 7 | |
| 3 | +status: done | |
| 4 | +--- | |
| 5 | +# p6-glossary-rows-1-20 | |
| 6 | + | |
| 7 | +Twenty rows of the glossary, `GUIDE.md` lines 62–81, from `a-place` to `seesaw`. For each row I | |
| 8 | +found the declarations it names and compared the row's words with the Lean definition and the | |
| 9 | +docstring next to it. This is one of the four units of #7: the three parts of section 2 and the | |
| 10 | +table of sizes of section 3. | |
| 11 | + | |
| 12 | +Run `python3 routes/p6-glossary-rows-1-20/check.py` from the project root to reproduce the list of | |
| 13 | +declarations: it reads the twenty rows, takes the names of the `Lean` column, and looks each one up | |
| 14 | +under `src` as a declaration, as a field of a structure, or as a name taken from a library by an | |
| 15 | +`open`/`export` line. It finds all 37 names. | |
| 16 | + | |
| 17 | +## The twenty rows | |
| 18 | + | |
| 19 | +Every name below is given with the file and line of its declaration. "Agrees" means that the words | |
| 20 | +of the row are what the declaration and its docstring say; where the row is terse I say what it | |
| 21 | +leaves out, and where a name is not in `src` I say where it comes from. | |
| 22 | + | |
| 23 | +| row | declarations checked | what the row says, and what the code says | | |
| 24 | +|---|---|---| | |
| 25 | +| a-place | `New.Data.aPlaces` `src/New/Reduction/Data/AdmissibleData.lean:256` | Agrees. `{τ : D.Φ \| placeClass … τ = 1}`; the docstring at `:255` says "the places ≡ 1 modulo q₀", and the row's "read in (ℤ/q₁)ˣ" is the `placeClass` of `:67`. | | |
| 26 | +| b-place, weight | `Data.bPlaces` `src/New/Reduction/Data/AdmissibleData.lean:137`, `New.Data.weight` `:181` | Agrees. `bPlaces` is a field of the structure `Data`, with `placeClass_of_mem_bPlaces : … = -1` at `:138`; `weight` is `natB` on `bPlaces` and `natX * natB / natX₁` off it (`weight_eq`, `:187`), which is `a/x` and `a/x₁`. | | |
| 27 | +| b-place, weight (the sparse set) | `New.Parameters.IsSparse` `src/New/Reduction/Data/AdmissibleData.lean:65`, used as `D.sparse` `:145` | Agrees, including the sizes: `D.sparse` is `P.IsSparse D.towerExp ((r + 1 - m) * (5 * r)) D.bPlaces`, and `(r + 1 - m) * 5r = k t`, which is the row's "primes ℓ ≤ kt"; the exponents are `0 < i < j < l₀` (`:66`), and the places are taken modulo the part of `q₁` prime to `ℓ` (`:67`). | | |
| 28 | +| b-place, weight (Behrend) | `src/New/Reduction/Data/Existence.lean:36`, `:50`, `:134`, `:209`, `:605` | Agrees. The row's "built after Behrend" is the construction of `Existence`: the b-places are `-g ^ e` with `g = 1 + 3 l₀ q₀` and `e` in a set of Behrend's type, from `TauCeti.exists_eq_and_eq_of_add_mul_modEq` (`:36`). The row names no declaration for this, and the set itself is not a definition of the development: it is the hypothesis `IsSparse`. | | |
| 29 | +| chosen place | `New.Data.IsChosen` `src/New/Derivatives/Field/ChosenPlaces.lean:74` | Agrees. `D.piM ∈ w.asIdeal`, with `piM` the conjugate of `D.piMBar` (`:70`), of norm `p₀p₁` (`piM_mul_star`, `:85`). "half of those above M" is `card_chosenPlace : card (D.ChosenPlace i) = D.f` (`src/New/UpperBound/Objects/LiftChains.lean:383`) for each `i`, against `2 f` places above `M`. | | |
| 30 | +| twist | `New.Data.Twist` `src/New/Reduction/Data/LevelAndTwists.lean:300`, `New.Data.MFoldTwist` `:391` | Agrees. `Twist` extends `TameChar` (`:279`) with `tamePart_ne_one` on `Q`; the fields of `TameChar` are `hasWeight : toAutChar.HasWeight 0 tamePart` (weight 0), `tamePart_eq_one` off `Q`, `star_notMem` (`Q` disjoint from its conjugate), `coprime : (D.M * D.N).Coprime (∏ w ∈ Q, w.q)` (prime to MN). `MFoldTwist.pow_ne_one` quantifies over `D.LiftIndex` (`:368`), which is `Icc 1 D.m`, so "its first m powers". The word "anticyclotomic" is the row's, not the code's: the code says weight 0 on `U(1)`. | | |
| 31 | +| height bound | `HeightLe` `src/New/Reduction/Lattices/Heights.lean:50` | Agrees, and the name is not declared under `src`: the line is `export TauCeti.PrimePadicIso (HeightLe)`, so `HeightLe` is Tau Ceti's. The row's definition is the file's head, `:18`–`:22`. `HeightLe.nonneg_of_one` is this project's, `:25` and `:60`-odd, stated in Tau Ceti's namespace for dot notation (`:54`). | | |
| 32 | +| twisted lattice | `TwistedLattice` `src/New/Reduction/Lattices/TwistedLattice.lean:123`, `New.Data.targetLattice` `src/New/Reduction/IntegralTargetForms.lean:70` | Agrees. `TwistedLattice` has `Space : T → Type`, `lift ξ : V →ₗ Space ξ`, `IsAllowed`, and `lattice ξ ι`; `targetLattice` is the target forms with `lift := D.Θ` and `IsAllowed l ϑ := l.Coprime ϑ.normQ`. | | |
| 33 | +| index, covolume | `TwistedLattice.IndexLe` `src/New/Reduction/Lattices/TwistedLattice.lean:176`, `TwistedLattice.CovolumeLe` `:278`, `TwistedLattice.integralVectors` `:163` | Agrees. `IndexLe y δ` gives `e : ℕ → ℝ` with `∑_{l ∈ U} e l * log l ≤ δ` and, for each `ι`, one matrix `u` with `ι.Carries u y (L.integralVectors ι) (e ι.prime)`; `integralVectors ι` is `∀ ξ, IsAllowed ι.prime ξ → L.lift ξ y ∈ L.lattice ξ ι` (`mem_integralVectors`, `:167`), which is the row's "the same for all twists of modulus prime to ℓ". `CovolumeLe` is the bound on `‖det (formGram … (conjCoord σ ∘ y))‖` at every `σ`. | | |
| 34 | +| main amount, remainder | `New.Data.mainAmount` `src/New/Reduction/PrimeSums.lean:68`, `New.Data.totalRemainder` `:79`, `New.Data.directionAmount` `src/New/Reduction/Data/AdmissibleData.lean:282` | Agrees. `mainAmount = D.m * D.k * D.directionAmount`; `totalRemainder = ∑ τ ∈ D.aPlaces, (D.primeSum D.a τ - D.mainPrimeSum)`. | | |
| 35 | +| prime sum, gain | `New.Data.primeSum` `src/New/Reduction/Data/AdmissibleData.lean:269`, `New.Data.localPrimeSum` `src/New/UpperBound/Size/ShortColumns.lean:89`, `New.Data.gain` `:100` | Agrees, including the factor 2: `primeSum` is `∑ ν ∈ Icc 1 D.a, Λ_K(ν) (y/ν - κ(-νσ))₊` with `Λ_K(ν) = Λ(ν)(1 - χ_K(ν))`, and the p-part of it is `2 * localPrimeSum p y σ * log p` (`primeSum_eq_sum_localPrimeSum`, used at `src/New/UpperBound/Size/Estimates.lean:157`–`:158` and `src/New/UpperBound/Size/ArchimedeanSize.lean:159`), so `localPrimeSum` is indeed "its part at p divided by 2 log p". `gain p = D.m * (∑ τ ∈ D.aPlaces, localPrimeSum p D.a τ + D.k * localPrimeSumTotal p)`. The row's third clause, "the exponent of p asked to divide the composite lift", is the real number `gain`; the integer exponent is `D.gainExponent` (`src/New/Reduction/ShortAndEnough.lean:59`, `⌊gain - allowedLoss⌋`), which row 95 names. | | |
| 36 | +| error unit, budget | `New.Data.errorUnit` `src/New/Reduction/Data/AdmissibleData.lean:273`, `New.Data.denominatorBudget` `src/New/Determinant/Twist/FitTwists.lean:162`, `Selmer.clearingBound` `src/New/Congruences/FirstOrder/TraceRelations.lean:143`, `New.Data.ClearsProjection` `src/New/Determinant/Twist/FitTwists.lean:173` | Agrees. `errorUnit = D.f * D.a * D.logB ^ 3`; `denominatorBudget = errorUnit / (D.m * D.k)`, and `sum_clearingBound_add_padicValNat_le` (`src/New/Congruences/FitTwistsExist.lean:244`) bounds `∑ l ∈ T, (clearingBound D l * log l + …)` by it; `ClearsProjection` is the determinant of ℓ-adic size `exp (-(finrank ℂ … * (D.r * β)))`. `clearingBound` is a sum of four local defects, `NNReal`. | | |
| 37 | +| source form | `New.Data.SourceForm` `src/New/UpperBound/Objects/Columns.lean:786`, `New.Data.ramifiedSourceForms` `src/New/UpperBound/Size/ShortColumns.lean:759`, `New.Data.levelX` `src/New/UpperBound/Objects/Columns.lean:655` | Agrees. `SourceForm` is `levelSpace (algFormRep D.columnCount (D.lastEntry 0)) (D.levelX 0)`, and `columnCount τ 1` is `D.a` on `D.aPlaces` and `0` elsewhere (`src/New/UpperBound/Objects/Weights.lean:58`–`:63`), with `lastEntry 0 = 0`: the weight is `(a, 0, …, 0)` at the a-places. `levelX` is the level principal at the chosen places with last row `≡ (0, …, 0, 1) mod π_N` (`:653`); `ramifiedSourceForms` is the intersection over `w : D.piNPlaces` of the kernels of `∑ i ∈ range (N - 1), centralRep (scalingGenerator w) ^ i` (`:757`). | | |
| 38 | +| target form | `New.Data.targetForms` `src/New/UpperBound/Objects/Rows.lean:292`, `New.Data.principalForms` `:277` | Agrees. `targetForms = D.goodForms (D.spaceY 0)`, and `principalForms` is `levelSpace (V.formRep (typeKernel D.paramW s)) (levelOf D.chosenPlace ⊥)`, which is principal at the chosen places and at no other place; `D.paramW` is built from `D.targetParameter` (`src/New/UpperBound/Objects/LabelsAndIndexTypes.lean:294`). | | |
| 39 | +| label | `IsLabel` `src/Lib/LocalGL/Green/TauFunctions.lean:153`, `labelIdem` `:186` | Agrees. `IsLabel : c.Monic ∧ Squarefree c ∧ c.natDegree = r ∧ c.coeff 0 ≠ 0`, over a finite field `k`; `labelIdem` is the idempotent of `MonoidAlgebra ℂ (GL n k)` that the label names. | | |
| 40 | +| good form | `New.Data.goodForms` `src/New/UpperBound/Objects/Rows.lean:288`, `New.Data.e₀` `src/New/UpperBound/Objects/LabelsAndIndexTypes.lean:373`, `New.goodTuples` `:146`, `New.Data.goodTupleFamilies` `:348`, `IsPrimitivePolynomial` `:57`, `IsAllowedPolynomial` `:125` | Agrees. `goodForms` is the range of `(D.principalRep V).asAlgebraHom D.e₀`; `e₀` sums `tupleIdem` over `goodTupleFamilies`, which by `mem_goodTupleFamilies` (`:361`) asks, for each `i : Fin 2`, that the labels above `p_i` lie in `goodTuples (P.q₂ D.towerExp) r`: every one allowed (`∀ x, x ^ M = 1 → ¬c.IsRoot x`) and **at least one primitive per `i`**, which is the row's "above each of p₀, p₁". `IsPrimitivePolynomial` is a label that is irreducible with a root of order `|k| ^ r - 1`. | | |
| 41 | +| setting of a lift | `Selmer.IsLiftSetting` `src/New/Congruences/GaloisRepresentations/SelmerHypotheses.lean:557` | Agrees as a summary. The structure's fields are `toLevelPlaces_eq`, `exists_tamePart_eq_chiMLocal_zpow_mul`, `odd`, `rank_le`, `isLabel`, `exists_primitive_or_one`, `not_isRoot_scaledTypePoly`; the row compresses them to "labels at the chosen places of a `DescentPair` to which the Selmer bounds of `New/Congruences` apply". | | |
| 42 | +| cut | `New.Floors.PlaceData.IsCut` `src/New/Spanning/Frames/Densities.lean:89` | Agrees, and is terser than the code: `IsCut` extends `P.IsBessel W F.levelUnit⁻¹` with `exists_mul_mem_box`, "zero at `x` unless `u x` lies in the box `F.boxSet` for some `u`" (`:87`–`:88`). The row's name is right; the declaration sits in `namespace New.Floors` in `Densities`, not in a file named after floors. | | |
| 43 | +| lift | `Space.lift` `src/Lib/Weil/DualPair/ThetaLiftConvergence.lean:293`, `Kernel.lift` `src/Lib/Weil/CompactLift/ThetaKernelDefs.lean:180`, `New.Data.lowerChain` `src/New/UpperBound/Objects/RowChain.lean:183`, `New.Data.goodLift` `src/New/Determinant/Twist/FitTwists.lean:117`, `Lift` `src/Lib/LocalGL/Shintani/CosetDescent.lean:118` | Agrees. `Space.lift φ y h = ∫ g, K.θ (K.ω (g, h) φ) * y g ∂S.quotMeasure` (adelic, by class sums); `Kernel.lift` is the archimedean map `AlgForm n κ e →ₗ AlgForm n' κ ea`; `lowerChain` is `Y₀ → Y_m` (`toAlgForm (D.spaceY D.m) … ∘ₗ lowerChainUpTo ϑ D.m`); `goodLift ϑ j` is `W_j → V_j`. The predicate `Lift` of `New/Congruences/Lifting` is not this row's `Lift`: the row says "the predicate `Lift` is Shintani lifting", and `Lift : Prop := ∀ m, HasCommonLift Z F F' (Fin m)` is in `Lib/LocalGL/Shintani`, which is Shintani descent; the folder `New/Congruences/Lifting` is the p-adic Hodge theory of the level primes. | | |
| 44 | +| string | `Grading` `src/Lib/Weil/Periods/Grading.lean:105`, `Selmer.HasLiftTrace` `src/New/Congruences/GaloisRepresentations/SelmerHypotheses.lean:585`, `New.Data.Y` / `spaceY_gram_eq` `src/New/UpperBound/Objects/LabelsAndIndexTypes.lean:267`, `src/New/UpperBound/Objects/Rows.lean:250` | Agrees, including the count: `Y_j` is `X_j` plus `2ϱ + 1 - j` further vectors, and `m = 2ϱ + 2` gives `m - 1 - j` (`GUIDE.md:149`, `spaceY_gram_eq`). The string's Gram is the identity on `X_j` and the antidiagonal on the string, `1` except `-N` at the middle, so "hyperbolic pairs, and a middle vector if their number is odd". `HasLiftTrace` is `∀ g, (u g).val.trace = ψ g * (R g).val.trace + ∑ e ∈ range t, cyclotomicInv … g ^ e`. | | |
| 45 | +| jet | `MvPolynomial.jetPairing` (not in `src`; opened at `src/Lib/General/Algebra/IntegralPowerSeries.lean:144` and `src/New/Derivatives/Sharpness/Couplings.lean:125`), `schurJet` `src/Lib/Weil/Construction/ThetaJets.lean:111` | Agrees on the first half: the row's `P(∂)F(0)` is the description of `MvPolynomial.jetPairing` in the head of `IntegralPowerSeries` (`:29`) and of `src/Lib/GLn/SchurModule/Basic.lean:27`. `schurJet` is `(LinearMap.mapMatrixLinear R ∘ₗ jetPairing.flip).flip (schur κ …)`. The second half, "for a monomial `P = X^α` this is `α!` times the coefficient", is a lemma of the library that declares `jetPairing` (`jetPairing_monomial`, used at `IntegralPowerSeries.lean:279` and `ThetaJets.lean:99`); I did not read it, because that library is not in the checkout. | | |
| 46 | +| seesaw | `New.Data.seesaw_identity` `src/New/UpperBound/Seesaw/SeesawIdentity.lean:655` | Agrees. `∃ c : ℂˣ, ∀ ϑ : D.Twist, ∃ Ψ : D.Translations →₀ ℂ, IsChainDatum ϑ Ψ ∧ ∀ φ : D.ramifiedSourceForms, lowerChain ϑ (D.poincareAt g t φ) = c • compositeLift ϑ Ψ φ`: one `c ≠ 0` for all twists, only on ramified source forms, and nothing about the right side being nonzero (the docstring says so at `:643`–`:654`). | | |
| 47 | + | |
| 48 | +## Where the row names no declaration | |
| 49 | + | |
| 50 | +None of the twenty rows lacks a name in its `Lean` column. Two names are not declared under `src`: | |
| 51 | +`HeightLe` (Tau Ceti's, exported at `src/New/Reduction/Lattices/Heights.lean:50`) and | |
| 52 | +`MvPolynomial.jetPairing` (declared in the `MvPolynomial` namespace of a library, and opened at the | |
| 53 | +two places above). For the second I cannot say which library: no `def jetPairing` occurs under | |
| 54 | +`src`, `ATTRIBUTION.md` does not mention it, and neither dependency is in the checkout (there is no | |
| 55 | +`.lake` here), so I did not open its statement. | |
| 56 | + | |
| 57 | +## What I changed | |
| 58 | + | |
| 59 | +Nothing in `GUIDE.md`. The twenty rows agree with the code, and I found no wording that the | |
| 60 | +declarations contradict. Where a row is terser than the code (the `cut`, `setting of a lift` and | |
| 61 | +`twist` rows, and the Behrend sentence of the `b-place` row) the words are still true of the | |
| 62 | +definition, and a longer row would be a change of style, not a correction. This note and | |
| 63 | +`check.py` are the change of this unit. | |
| 64 | + | |
| 65 | +## What this does not show | |
| 66 | + | |
| 67 | +That the rows are the ones a reader needs, or that the guide is complete: only that the twenty rows | |
| 68 | +report the code they name. The other three units of #7 — the other two parts of section 2 and the | |
| 69 | +table of sizes — are not checked here. | |
| 70 | + | |
| 71 | +## Next | |
| 72 | + | |
| 73 | +The next unit of #7 is the second part of the glossary, rows 82–101 (`filling` to `polar`), then | |
| 74 | +rows 102–107 and the table of sizes of section 3. Someone taking rows 82–101 can start from | |
| 75 | +`check.py` here by changing `FIRST` and `LAST`. | |
+136 −0 routes/p6-glossary-rows-1-20/check.py added View file
| @@ -0,0 +1,136 @@ | ||
| 1 | +#!/usr/bin/env python3 | |
| 2 | +"""Check that the names in GUIDE.md's glossary rows 62-81 exist in the Lean source. | |
| 3 | + | |
| 4 | +Run from the project root: python3 routes/p6-glossary-rows-1-20/check.py | |
| 5 | + | |
| 6 | +The script reads the twenty rows of the glossary (GUIDE.md lines 62-81), takes the names in the | |
| 7 | +`Lean` column, and looks each one up under `src`. A name is found as a declaration | |
| 8 | +(`def`, `lemma`, `theorem`, `abbrev`, `structure`, `class`, `inductive`, `instance`), as a field of | |
| 9 | +a structure (`bPlaces : Finset ...`), or as a name taken from a library by an `open`/`export` line | |
| 10 | +(for example `MvPolynomial.jetPairing`, which Mathlib declares). | |
| 11 | + | |
| 12 | +A name whose prefix is `D.` is a field of the data `D : Data P`, so its declaration is looked for | |
| 13 | +in a file that opens `namespace New.Data`; this keeps `D.gain` from matching another `gain`. | |
| 14 | + | |
| 15 | +The output is the audit table of `routes/p6-glossary-rows-1-20/README.md`. | |
| 16 | +""" | |
| 17 | + | |
| 18 | +import re | |
| 19 | +import subprocess | |
| 20 | +import sys | |
| 21 | + | |
| 22 | +sys.stdout.reconfigure(encoding="utf-8") | |
| 23 | + | |
| 24 | +GUIDE = "GUIDE.md" | |
| 25 | +FIRST, LAST = 62, 81 | |
| 26 | +SP = "[[:space:]]" | |
| 27 | +DECL = (f"({SP}*noncomputable{SP}+)?({SP}*protected{SP}+)?" | |
| 28 | + "(theorem|lemma|def|abbrev|structure|class|inductive|instance)") | |
| 29 | +SPLIT = re.compile(r"(?<!\\)\|") | |
| 30 | + | |
| 31 | +_namespace_cache = {} | |
| 32 | + | |
| 33 | + | |
| 34 | +def norm(s): | |
| 35 | + return " ".join(s.replace("`", "").split()) | |
| 36 | + | |
| 37 | + | |
| 38 | +def guide_rows(): | |
| 39 | + text = open(GUIDE, encoding="utf-8").read().split("\n") | |
| 40 | + rows = [] | |
| 41 | + for line in text[FIRST - 1:LAST]: | |
| 42 | + cells = [norm(c) for c in SPLIT.split(line)] | |
| 43 | + if len(cells) < 4: | |
| 44 | + continue | |
| 45 | + rows.append((cells[1], cells[2], cells[3])) | |
| 46 | + return rows | |
| 47 | + | |
| 48 | + | |
| 49 | +def names_in(ax): | |
| 50 | + """The names of the `Lean` column: backticked, and split on commas.""" | |
| 51 | + return [n.strip() for n in ax.replace("`", "").split(",") if n.strip()] | |
| 52 | + | |
| 53 | + | |
| 54 | +def last(name): | |
| 55 | + return name.split(".")[-1] | |
| 56 | + | |
| 57 | + | |
| 58 | +def grep(pattern, path="src"): | |
| 59 | + """`git grep -n -E` with a POSIX ERE pattern; returns matching lines.""" | |
| 60 | + r = subprocess.run(["git", "grep", "-n", "-E", "--", pattern, "--", path], | |
| 61 | + capture_output=True, text=True, encoding="utf-8") | |
| 62 | + if r.returncode not in (0, 1): | |
| 63 | + raise SystemExit(f"git grep failed on {pattern!r}: {r.stderr.strip()}") | |
| 64 | + return [l for l in r.stdout.splitlines() if l.strip()] | |
| 65 | + | |
| 66 | + | |
| 67 | +def where(line): | |
| 68 | + """`src/a/b.lean:123:...` -> `src/a/b.lean:123`.""" | |
| 69 | + return ":".join(line.split(":")[:2]) | |
| 70 | + | |
| 71 | + | |
| 72 | +def has_namespace(path, ns): | |
| 73 | + key = (path, ns) | |
| 74 | + if key not in _namespace_cache: | |
| 75 | + r = subprocess.run(["git", "grep", "-n", "-F", "--", f"namespace {ns}", "--", path], | |
| 76 | + capture_output=True, text=True, encoding="utf-8") | |
| 77 | + _namespace_cache[key] = bool(r.stdout.strip()) | |
| 78 | + return _namespace_cache[key] | |
| 79 | + | |
| 80 | + | |
| 81 | +def find(name): | |
| 82 | + """Return (kind, place) for a name, or (None, None). | |
| 83 | + | |
| 84 | + The patterns are POSIX ERE, as `git grep -E` takes them: no non-capturing groups, and | |
| 85 | + `[[:space:]]` for whitespace. | |
| 86 | + """ | |
| 87 | + leaf = last(name) | |
| 88 | + prefix = name[: -len(leaf)] # "D." / "Selmer." / "Space." / "" | |
| 89 | + tail = rf"({SP}|:|\(|\[|\{{|$)" | |
| 90 | + # 1. A declaration of the whole name, as written (`def Space.lift`). | |
| 91 | + if prefix: | |
| 92 | + hits = grep(rf"(^|[^A-Za-z0-9_.']){DECL}{SP}+{re.escape(prefix)}{re.escape(leaf)}{tail}") | |
| 93 | + if hits: | |
| 94 | + return "declaration", where(hits[0]) | |
| 95 | + # 2. A declaration of the leaf, with an optional dotted prefix (`structure PlaceData.IsCut`). | |
| 96 | + hits = grep(rf"(^|[^A-Za-z0-9_.']){DECL}{SP}+([A-Za-z0-9_']+\.)*{re.escape(leaf)}{tail}") | |
| 97 | + if prefix == "D.": | |
| 98 | + # `D` is the data, so the declaration is in a file of `namespace New.Data`. | |
| 99 | + hits = [h for h in hits if has_namespace(h.split(":")[0], "New.Data")] or hits | |
| 100 | + if hits: | |
| 101 | + return "declaration", where(hits[0]) | |
| 102 | + # 3. A field of a structure: `bPlaces : Finset (P.Φ towerExp)` on a line of its own. | |
| 103 | + hits = grep(rf"^{SP}+{re.escape(leaf)}{SP}*:") | |
| 104 | + if hits: | |
| 105 | + return "field", where(hits[0]) | |
| 106 | + # 4. A name taken from a library, by `open X (name ...)` or `export X (name ...)`. | |
| 107 | + hits = grep(rf"(open|export){SP}+[A-Za-z0-9_.']+{SP}+\([^)]*{re.escape(leaf)}") | |
| 108 | + if hits: | |
| 109 | + return "from a library (open/export)", where(hits[0]) | |
| 110 | + return None, None | |
| 111 | + | |
| 112 | + | |
| 113 | +def main(): | |
| 114 | + rows = guide_rows() | |
| 115 | + bad = [] | |
| 116 | + total = 0 | |
| 117 | + print("| row | name | found as | place |") | |
| 118 | + print("|---|---|---|---|") | |
| 119 | + for label, ax, _meaning in rows: | |
| 120 | + for n in names_in(ax): | |
| 121 | + total += 1 | |
| 122 | + kind, place = find(n) | |
| 123 | + if kind is None: | |
| 124 | + bad.append((label, n)) | |
| 125 | + print(f"| {label} | `{n}` | **not found** | |") | |
| 126 | + else: | |
| 127 | + print(f"| {label} | `{n}` | {kind} | `{place}` |") | |
| 128 | + print() | |
| 129 | + print(f"rows: {len(rows)}; names: {total}; not found: {len(bad)}") | |
| 130 | + for label, n in bad: | |
| 131 | + print(f" not found: {label}: `{n}`") | |
| 132 | + return 0 if not bad else 1 | |
| 133 | + | |
| 134 | + | |
| 135 | +if __name__ == "__main__": | |
| 136 | + sys.exit(main()) | |