Poincaré conjecture: the Lean proof, cleaned up together
The 2026 Lean proof of the Poincaré conjecture after Morgan and Tian, 3 million lines, cleaned up together: smaller, faster to build, more readable, the theorems unchanged

audit: unit (d) of #24 — are the 106 files' notices in this tree? #54
Open
+165 −0 routes/v6-modifications-audit/AUDIT.md added View file
| @@ -0,0 +1,165 @@ | ||
| 1 | +# Audit of `MODIFICATIONS.md` (issue #24, unit d) | |
| 2 | + | |
| 3 | +**The question.** `MODIFICATIONS.md` says that of 110 source adaptations inspected, 106 | |
| 4 | +matched outside sources exactly once comments, whitespace and import/namespace commands were | |
| 5 | +set aside, and that "All 124 edited Lean files" carry the attribution update, with "All | |
| 6 | +per-file copyright, source and modification notices … retained". Unit (d) asks: **are those | |
| 7 | +notices on those files, in this tree?** Reading and `git grep` only; no Lean build was run or | |
| 8 | +needed. | |
| 9 | + | |
| 10 | +**Everything numeric below comes from `audit-out.txt`**, which three scripts in this directory | |
| 11 | +produce and no one edits by hand. One command regenerates it from the repository root: | |
| 12 | + | |
| 13 | + sh routes/v6-modifications-audit/all.sh | |
| 14 | + | |
| 15 | +or run any of the three alone, each printing its own header and writing nothing: | |
| 16 | + | |
| 17 | + python3 routes/v6-modifications-audit/audit.py . # table vs notices, pair by pair | |
| 18 | + python3 routes/v6-modifications-audit/map.py . # table row -> path in this tree | |
| 19 | + python3 routes/v6-modifications-audit/row_own.py . # each row vs its own file's notice | |
| 20 | + | |
| 21 | +Each takes the repository root as its argument, prints to stdout, and touches no file. The one | |
| 22 | +item I read with my eyes rather than derived is marked as such in a section of its own. | |
| 23 | + | |
| 24 | +## What the report is, and which commit it describes | |
| 25 | + | |
| 26 | +The report is the repository's own `MODIFICATIONS.md`, 211 lines. It was introduced by commit | |
| 27 | +`7fb9add0` ("Start from https://github.com/frenzymath/PoincareConjecture at `62db01af`…") and | |
| 28 | +`git log -- MODIFICATIONS.md` shows no later change, so the text read here is the text at | |
| 29 | +`main`, `78922e9b`. It describes **two** things, at different revisions: | |
| 30 | + | |
| 31 | +- the **PoincareLib import** — "copied byte-for-byte" from `frenzymath/Poincare-Conjecture` at | |
| 32 | + `432c38f2aa5a30efb13871292d17b4a3309a496a`, keeping "only the Lean library and its root | |
| 33 | + module"; | |
| 34 | +- the **earlier attribution update** — the 110/106/124 numbers and the mapping table, whose | |
| 35 | + local files are linked at the pre-import revision | |
| 36 | + `3d7318c32025ccb30465dd29850e95a9e2aa1526`. The report says as much: "This historical record | |
| 37 | + describes the replaced implementation." | |
| 38 | + | |
| 39 | +So unit (d) is not a question about a report on foreign code. It is whether the notice text | |
| 40 | +the report records survived the import into `PoincareLib/`. | |
| 41 | + | |
| 42 | +## What I read | |
| 43 | + | |
| 44 | +- `MODIFICATIONS.md`, all 211 lines — the two prose paragraphs giving the counts, the 124-row | |
| 45 | + table, the "Verification of the attribution update" section. | |
| 46 | +- Every Lean file under `PoincareLib/` — **23,564** (`audit.py`) — filtered to the **110** whose | |
| 47 | + head comment is a `Provenance and modification notice (recorded 2026-09-29)`. | |
| 48 | +- `NOTICE` (36 lines), `LICENSES/Apache-2.0.txt` (201 lines), `UPSTREAM.md` (73 lines), | |
| 49 | + `AGENTS.md`, `README.md`. | |
| 50 | +- The issue text of #24, and `BOARD.md` on the `issues` branch. | |
| 51 | + | |
| 52 | +## How the comparison is made, and why not by path | |
| 53 | + | |
| 54 | +The table's local paths are the **pre-import** ones (`PoincareConjecture/Proofs/…`), and | |
| 55 | +`audit.py` prints **0** rows whose local path exists at that path in this tree. That is not a | |
| 56 | +defect — it is what the report says the import did. The import did not rename upstream paths, so the comparison is | |
| 57 | +on **(upstream repository, upstream source path)** pairs, which are stable across it. A row is | |
| 58 | +"accounted for" when some notice in the tree names one of the upstream sources that row | |
| 59 | +records; it is "matched by its own file" when the notice of the row's mapped file does. | |
| 60 | + | |
| 61 | +## State | |
| 62 | + | |
| 63 | +### Confirmed here | |
| 64 | + | |
| 65 | +- **The pair set is identical, in both directions.** 113 distinct `(repo, upstream path)` pairs | |
| 66 | + in the table, 113 distinct in the notices; **0** in the table with no notice stating it, | |
| 67 | + **0** in the notices absent from the table. | |
| 68 | +- **Every row is covered.** All **124** rows have at least one notice in the tree naming one of | |
| 69 | + their sources. | |
| 70 | +- **Every existing target is named by its own file's notice.** `row_own.py`: **119** rows have | |
| 71 | + a file whose notice names one of that row's sources, **0** do not, **0** such files lack a | |
| 72 | + notice, and **5** rows have no file at their mapped path (below). 119 + 5 = 124. This is the | |
| 73 | + strict form of the issue's question, and it holds. | |
| 74 | +- **Notice fields are complete, field by field, 110 of 110 each:** `Source: https://github.com/…`, | |
| 75 | + a 40-hex `Comparison revision:`, `Changes:`, `License: Apache-2.0`. **0** notices have their | |
| 76 | + block followed by no import statement — every one sits at the head of its file. | |
| 77 | +- **The 5 `Comparison revision` values cited across all notices are exactly the 5 revisions | |
| 78 | + listed under "## Sources"** of `MODIFICATIONS.md` — 5 of 5 listed, and no others. A notice may | |
| 79 | + cite two (the DeGiorgi-through-DifferentialGeometry cases). | |
| 80 | +- **Copyright is present on every notice-carrying file.** A `Copyright` line appears somewhere | |
| 81 | + in all **110 of 110** such files. Note the shape: in **74 of 110** it is *not* inside the | |
| 82 | + notice block but in a second `/- … -/` block just below, so the notice block alone carries it | |
| 83 | + in 36. By upstream, with none inside the notice block: TauCeti 9/9, | |
| 84 | + classification-of-surfaces 7/8, differential-geometry 58/91, mathlib4 0/2. So "per-file | |
| 85 | + copyright … retained" holds at file level, while the notice block alone does not always | |
| 86 | + carry it. | |
| 87 | + | |
| 88 | +### Does not apply here | |
| 89 | + | |
| 90 | +- **The table's local paths.** `audit.py` prints 0 rows whose local path exists in this tree. | |
| 91 | + They are pre-import paths and the report says so; they are not evidence of a missing notice, | |
| 92 | + and the pair-level comparison is what replaces them. | |
| 93 | +- **The report's links to the upstream `MODIFICATIONS.md`, `archive/…/reviewed-files.json` and | |
| 94 | + `archive/…/licenses/`.** Those are `github.com` links into the upstream repository at | |
| 95 | + `432c38f2`, meant to be followed there, not found here. | |
| 96 | + | |
| 97 | +### Could not decide (why) | |
| 98 | + | |
| 99 | +Three prose numbers cannot be closed from this tree, because they compare against revisions | |
| 100 | +**this repository does not contain**: `audit.py` asks `git cat-file -t` and gets "not an object | |
| 101 | +here" for `3d7318c3`, `99148d28`, `e84e9c3f`, `432c38f2` and `62db01af` alike. The repository | |
| 102 | +holds one relevant commit, `7fb9add0`, which is the import itself. | |
| 103 | + | |
| 104 | +- **106 of 110 "matched exactly".** Deciding it needs the upstream | |
| 105 | + `archive/PoincareConjecture/provenance/2026-09-29/reviewed-files.json` (cited at `e84e9c3f`) | |
| 106 | + and the pre-change sources. From here: notices in the tree (110) equals adaptations | |
| 107 | + inspected (110), and the table has 124 rows and 113 distinct upstream pairs — but 110 ≠ 106, | |
| 108 | + and the report explains the 4 without naming which 4 (two ODE sources split into modules, the | |
| 109 | + conjugating-flow adapter, the fundamental-group adapter). I cannot map "106 exact + 4 | |
| 110 | + inspected individually" onto individual files without that JSON. | |
| 111 | +- **"All 124 edited Lean files" against the 124 rows.** The arithmetic does reconcile, and the | |
| 112 | + mechanism is visible: the 124 rows map to **113** paths, because **11** paths are shared by | |
| 113 | + two rows each (113 + 11 = 124, listed in `map.py`'s output) — the report's own "repeated | |
| 114 | + M05/M07 copies are included". But whether the row set *is* the edited-file set is a claim | |
| 115 | + about the pre-import diff at `3d7318c3`, which is unavailable. | |
| 116 | +- **The token-stream claim** ("identical code token streams", "preserved byte for byte after the | |
| 117 | + new ordinary comment header"). Needs the before revision. Not decidable here; I did not | |
| 118 | + assume it. | |
| 119 | + | |
| 120 | +### Wrong here | |
| 121 | + | |
| 122 | +- **The pointers in every notice are dangling in this tree, and it is both sentences, 110 of | |
| 123 | + 110 for each.** Every notice names | |
| 124 | + `PoincareConjecture/provenance/2026-09-29/licenses/` (110 of 110) *and* | |
| 125 | + `PoincareConjecture/MODIFICATIONS.md` (110 of 110); 110 carry both. Neither path exists: | |
| 126 | + `PoincareConjecture/` holds only `Proofs/` and `Statement.lean`, and the report sits at the | |
| 127 | + repository root as `MODIFICATIONS.md`. Locally the licence is `LICENSES/Apache-2.0.txt` (201 | |
| 128 | + lines) and the notices are `NOTICE` (36 lines). The substance is retained, but **the path each | |
| 129 | + of the 110 notices names is wrong for this tree** — a reader following the notice lands | |
| 130 | + nowhere. | |
| 131 | +- **At file level the count is 108 files attesting their own row, not 113.** Of the 113 mapped | |
| 132 | + paths, **108 exist and 5 do not**. The 5 rows with no file of their own have their sources | |
| 133 | + named in **4** surviving files — 3 rows fold into 2 files that are themselves table rows, and | |
| 134 | + 2 fold into the 2 files that are carriers only: | |
| 135 | + | |
| 136 | + | row with no file at its mapped path | whose source is named in | that file is | | |
| 137 | + | --- | --- | --- | | |
| 138 | + | `…/VariationalMapContDiffOnK/Foundations.lean` | `…/VariationalMapContDiffOnK.lean` | a row | | |
| 139 | + | `…/ParametricLinearODE/ParameterDerivative.lean` | `…/ParametricLinearODE.lean` | a row | | |
| 140 | + | `…/ParametricLinearODE/Variational.lean` | `…/ParametricLinearODE.lean` | a row | | |
| 141 | + | `M64/Mathlib/InteriorCurveTraces.lean` | `Geometry/CurveShortening/…/Interior/CurveTraces.lean` | a carrier | | |
| 142 | + | `M03/Existence/TimeDependentConjugatingFlowNative.lean` | `Geometry/RicciFlow/…/Flow/TimeDependentConjugatingFlow.lean` | a carrier | | |
| 143 | + | |
| 144 | + The ledger closes: **108** notice files are mapped row paths and **2** are these carriers, | |
| 145 | + total 110 — the carriers are exactly the 2 notice files that are not table rows. But read at | |
| 146 | + the file level, the tree has **108** files each attesting its own row, not 113; the other 5 | |
| 147 | + rows are attested only inside a shared file. That is a real limit of "one notice per edited | |
| 148 | + file", and the report does not put it that way. | |
| 149 | + | |
| 150 | +## The one item I read with my eyes, not from the scripts | |
| 151 | + | |
| 152 | +One, and only this one: that `MODIFICATIONS.md` says "This historical record describes the | |
| 153 | +replaced implementation", the sentence quoted above under *What the report is*. It is a quote, | |
| 154 | +not a count. Every other number in this file appears in `audit-out.txt` — including the | |
| 155 | +auxiliary line counts, the per-upstream copyright splits, the 25 rows with a non-standard | |
| 156 | +Modifications cell, the 5 revisions and their match against "## Sources". | |
| 157 | + | |
| 158 | +## What this audit does not show | |
| 159 | + | |
| 160 | +It covers **this one report** and nothing else. It says nothing about upstream issues 43 and 44, | |
| 161 | +nothing about the thirteen-theorem list of unit (c), and nothing about whether the *content* of | |
| 162 | +the notices is true of the code they sit on — only that the notices are there, that they name | |
| 163 | +the sources the table names, and that three of the report's numbers cannot be closed from this | |
| 164 | +tree. It does not verify authorship or licensing sufficiency; it verifies presence, | |
| 165 | +correspondence and internal consistency, which is what unit (d) asks. | |
+72 −0 routes/v6-modifications-audit/README.md added View file
| @@ -0,0 +1,72 @@ | ||
| 1 | +--- | |
| 2 | +issue: 24 | |
| 3 | +status: working | |
| 4 | +--- | |
| 5 | + | |
| 6 | +# V-6 (unit d): do the notices MODIFICATIONS.md records actually sit on the files in this tree? | |
| 7 | + | |
| 8 | +This route takes **unit (d)** of issue #24 and no other unit. The report I read is the | |
| 9 | +project's own `MODIFICATIONS.md`, which states that 106 reviewed Lean files matched outside | |
| 10 | +sources exactly once comments, whitespace and import/namespace commands were set aside, out of | |
| 11 | +110 adaptations inspected, and that "All 124 edited Lean files" carry the attribution update. | |
| 12 | +The question put by the issue is narrow and checkable with `git grep` alone: **are the notices | |
| 13 | +on those files in this tree?** | |
| 14 | + | |
| 15 | +## Rerun it | |
| 16 | + | |
| 17 | +One command, from the repository root, regenerates `audit-out.txt` — the recorded output of all | |
| 18 | +three scripts, concatenated in this order: | |
| 19 | + | |
| 20 | + sh routes/v6-modifications-audit/all.sh | |
| 21 | + | |
| 22 | +The three alone, each taking the repository root as its argument, printing to stdout, and | |
| 23 | +writing nothing: | |
| 24 | + | |
| 25 | + python3 routes/v6-modifications-audit/audit.py . # table vs notices, pair by pair | |
| 26 | + python3 routes/v6-modifications-audit/map.py . # table row -> path in this tree | |
| 27 | + python3 routes/v6-modifications-audit/row_own.py . # each row vs its own file's notice | |
| 28 | + | |
| 29 | +Only Python 3 and the tree are needed: no network, no Lean. Every numeric value in `AUDIT.md` | |
| 30 | +appears in `audit-out.txt`. | |
| 31 | + | |
| 32 | +## What I read | |
| 33 | + | |
| 34 | +- `MODIFICATIONS.md` at `origin/main` (`78922e9b`), all 211 lines: the two prose paragraphs | |
| 35 | + giving the counts, the 124-row table, the "Verification of the attribution update" section. | |
| 36 | +- Every Lean file under `PoincareLib/` — 23,564 — filtered to the 110 whose head comment is a | |
| 37 | + `Provenance and modification notice (recorded 2026-09-29)`. | |
| 38 | +- `NOTICE`, `LICENSES/Apache-2.0.txt`, `UPSTREAM.md`, `AGENTS.md`, `README.md`. | |
| 39 | +- The issue text of #24 and `BOARD.md` on the `issues` branch. | |
| 40 | + | |
| 41 | +## How the comparison is made | |
| 42 | + | |
| 43 | +Not by *local path*: the table's local paths are the pre-import ones | |
| 44 | +(`PoincareConjecture/Proofs/…`) and **0 of the 124 exist at that path in this tree**, which is | |
| 45 | +what the report says the import did — it kept "only the Lean library and its root module". So | |
| 46 | +the comparison is on **(upstream repository, upstream source path)** pairs, which the import did | |
| 47 | +not rename. | |
| 48 | + | |
| 49 | +## Next | |
| 50 | + | |
| 51 | +The audit is `AUDIT.md`. What it settles: the pair set is identical both ways (113 = 113, no | |
| 52 | +difference), all 124 rows are covered, and 119 rows have a file whose own notice names one of | |
| 53 | +their sources (0 do not). What it flags: 110/110 notices name | |
| 54 | +`PoincareConjecture/provenance/2026-09-29/licenses/` and 110/110 name | |
| 55 | +`PoincareConjecture/MODIFICATIONS.md`, and neither path exists here; at file level 108 files each | |
| 56 | +attest their own row, while 5 rows fold into 4 files (2 of them rows themselves, 2 carriers | |
| 57 | +only); and the prose numbers 106-of-110 and the token-stream claim cannot be closed from this | |
| 58 | +tree, because the 5 revisions they refer to are not objects in it. | |
| 59 | + | |
| 60 | +## Where it stands | |
| 61 | + | |
| 62 | +At `1427b094` the three review rounds are answered: the scripts print and write nothing, | |
| 63 | +`all.sh` is the one command that regenerates `audit-out.txt` (byte-identical on a rerun), each | |
| 64 | +script prints its own header, every figure `AUDIT.md` quotes is a line of that output, and the | |
| 65 | +description's "5 rows, 4 files" matches the table here. `ci/docs` reads `escalate, documents | |
| 66 | +pass` at this head; `challenge` and `build` carry the verdict of the commit this one builds on, | |
| 67 | +since no file they judge is touched. What is left is the maintainer agent's own rerun of | |
| 68 | +`all.sh` and its replay, and then a merge. Units (a), (b) and (c) of #24 are still free. | |
| 69 | + | |
| 70 | +A second person should run `sh routes/v6-modifications-audit/all.sh` at `main` and read | |
| 71 | +`AUDIT.md` against the regenerated `audit-out.txt`. Units (a), (b) and (c) of #24 are untouched | |
| 72 | +and still free. | |
+19 −0 routes/v6-modifications-audit/all.sh added View file
| @@ -0,0 +1,19 @@ | ||
| 1 | +#!/bin/sh | |
| 2 | +# Regenerate audit-out.txt: the recorded output of all three scripts, in this | |
| 3 | +# order, each printing its own header. Run from the repository root: | |
| 4 | +# | |
| 5 | +# sh routes/v6-modifications-audit/all.sh | |
| 6 | +# | |
| 7 | +# It takes no arguments and writes one file, beside itself. Nothing else in the | |
| 8 | +# tree is touched, and no network or Lean is needed. | |
| 9 | +set -e | |
| 10 | +cd "$(dirname "$0")/../.." | |
| 11 | +OUT=routes/v6-modifications-audit/audit-out.txt | |
| 12 | +{ | |
| 13 | + python3 routes/v6-modifications-audit/audit.py . | |
| 14 | + echo | |
| 15 | + python3 routes/v6-modifications-audit/map.py . | |
| 16 | + echo | |
| 17 | + python3 routes/v6-modifications-audit/row_own.py . | |
| 18 | +} > "$OUT" | |
| 19 | +echo "wrote $OUT" | |
+131 −0 routes/v6-modifications-audit/audit-out.txt added View file
| @@ -0,0 +1,131 @@ | ||
| 1 | +== audit.py: what the tree holds == | |
| 2 | +Lean files under PoincareLib/: 23564 | |
| 3 | +files carrying a "Provenance and modification notice": 110 | |
| 4 | + | |
| 5 | +== audit.py: what MODIFICATIONS.md records == | |
| 6 | +table rows: 124 distinct local paths named: 124 | |
| 7 | +rows naming 2+ upstream sources: 10 | |
| 8 | +upstream source mentions in the table, all rows: 134 | |
| 9 | +rows whose Modifications cell is not the standard sentence: 25 | |
| 10 | +local paths named by the table that exist at that path in this tree: 0 | |
| 11 | + | |
| 12 | +== audit.py: (upstream repository, upstream path) pairs == | |
| 13 | +distinct in the table: 113 | |
| 14 | +distinct in notices: 113 | |
| 15 | +in the table, no notice states it: 0 | |
| 16 | +in notices, not in the table: 0 | |
| 17 | + | |
| 18 | +== audit.py: row by row == | |
| 19 | + 124 at least one notice names a source of this row | |
| 20 | + | |
| 21 | +== audit.py: notice fields, counted per field == | |
| 22 | +notices: 110 | |
| 23 | + with "Source: https://github.com/…": 110 | |
| 24 | + with a 40-hex "Comparison revision:": 110 | |
| 25 | + with "Changes:": 110 | |
| 26 | + with "License: Apache-2.0": 110 | |
| 27 | + whose notice block is not followed by an import statement: 0 | |
| 28 | +Comparison revision values cited across all notices (a notice may cite two): 5 | |
| 29 | + 0df444a360eaa60ab8c11dca51a86af692955474 x2 | |
| 30 | + 1b535dd102b94cc42b107cca27059687888f08b3 x92 | |
| 31 | + 4c1b3077d3782b24065184df4ba59501b2e56fc7 x9 | |
| 32 | + d7ac608e0c97f71e9e0dc210d26a470d974368d7 x9 | |
| 33 | + e3c7230fe78d7b056a415d9ecae6f77887046b32 x8 | |
| 34 | + of those, listed under "## Sources": 5 of 5 listed | |
| 35 | + | |
| 36 | +== audit.py: copyright, and where it sits == | |
| 37 | +notices with a Copyright line inside the notice block: 36 of 110 | |
| 38 | +notices with none inside the notice block: 74 of 110 | |
| 39 | +notice-carrying files with a Copyright line anywhere in the file (first 40,000 chars): 110 of 110 | |
| 40 | + by upstream repository — with a Copyright line inside the notice block / notices: | |
| 41 | + qinz1yang/differential-geometry: 33/91 | |
| 42 | + TauCetiProject/TauCeti: 0/9 | |
| 43 | + mccorvie/classification-of-surfaces: 1/8 | |
| 44 | + leanprover-community/mathlib4: 2/2 | |
| 45 | + and so, with none inside the notice block (copyright is elsewhere in these files): | |
| 46 | + qinz1yang/differential-geometry: 58/91 | |
| 47 | + TauCetiProject/TauCeti: 9/9 | |
| 48 | + mccorvie/classification-of-surfaces: 7/8 | |
| 49 | + leanprover-community/mathlib4: 0/2 | |
| 50 | + | |
| 51 | +== audit.py: the two pointers each notice ends with, counted separately == | |
| 52 | +notices naming PoincareConjecture/provenance/2026-09-29/licenses/ (absent here): 110 of 110 | |
| 53 | +notices naming PoincareConjecture/MODIFICATIONS.md (absent here): 110 of 110 | |
| 54 | +notices carrying both pointers: 110 | |
| 55 | +notices carrying at least one: 110 | |
| 56 | + | |
| 57 | +== audit.py: the auxiliary paths AUDIT.md names == | |
| 58 | + LICENSES/Apache-2.0.txt: 201 lines | |
| 59 | + NOTICE: 36 lines | |
| 60 | + MODIFICATIONS.md: 211 lines | |
| 61 | + UPSTREAM.md: 73 lines | |
| 62 | + PoincareConjecture/provenance: absent | |
| 63 | + PoincareConjecture/MODIFICATIONS.md: absent | |
| 64 | + | |
| 65 | +== audit.py: are the revisions the report cites objects in this repository? == | |
| 66 | + 3d7318c3: not an object here | |
| 67 | + 99148d28: not an object here | |
| 68 | + e84e9c3f: not an object here | |
| 69 | + 432c38f2: not an object here | |
| 70 | + 62db01af: not an object here | |
| 71 | + (cited from MODIFICATIONS.md: the pre-import revision, the revision the review was made at, the revision of the source report, the imported source, the origin commit) | |
| 72 | + | |
| 73 | +== audit.py: the numbers MODIFICATIONS.md states in prose == | |
| 74 | +prose: 110 source adaptations inspected; 106 matched exactly; 4 inspected individually; "All 124 edited Lean files". | |
| 75 | + table rows (vs 124 edited): 124 | |
| 76 | + notices in the tree (vs 110 inspected): 110 | |
| 77 | + distinct upstream pairs (vs 110): 113 | |
| 78 | + the 106 and the 124 are not decidable from this tree: the revisions they refer to (3d7318c3, 99148d28, e84e9c3f, 432c38f2, 62db01af) are not objects in it. | |
| 79 | + | |
| 80 | +== map.py: table rows, mapped onto this tree == | |
| 81 | +rows: 124 | |
| 82 | +distinct paths after the import mapping: 113 | |
| 83 | +paths shared by 2+ rows: 11 -> extra rows: 11 | |
| 84 | + check: 113 + 11 = 124 | |
| 85 | + shared PoincareLib/Analysis/ODE/LocalFlow/C1Regularity/ContDiffOnOne.lean <- 2 rows | |
| 86 | + shared PoincareLib/Analysis/ODE/LocalFlow/C1Regularity/FrechetDerivative.lean <- 2 rows | |
| 87 | + shared PoincareLib/Analysis/ODE/LocalFlow/C1Regularity/JointFrechetDerivative.lean <- 2 rows | |
| 88 | + shared PoincareLib/Analysis/ODE/LocalFlow/GlobalExistence.lean <- 2 rows | |
| 89 | + shared PoincareLib/Analysis/ODE/LocalFlow/HigherRegularity/VariationalCoproductDerivative.lean <- 2 rows | |
| 90 | + shared PoincareLib/Analysis/ODE/LocalFlow/HigherRegularity/VariationalLevelOneSmoothness.lean <- 2 rows | |
| 91 | + shared PoincareLib/Analysis/ODE/LocalFlow/HigherRegularity/VariationalLevelOneWitness.lean <- 2 rows | |
| 92 | + shared PoincareLib/Analysis/ODE/LocalFlow/HigherRegularity/VariationalLevelZeroWitness.lean <- 2 rows | |
| 93 | + shared PoincareLib/Analysis/ODE/LocalFlow/HigherRegularity/VariationalLinearMapSmoothness.lean <- 2 rows | |
| 94 | + shared PoincareLib/Analysis/ODE/LocalFlow/HigherRegularity/VariationalSuccessorWitness.lean <- 2 rows | |
| 95 | + shared PoincareLib/Analysis/ODE/LocalFlow/JointContinuity.lean <- 2 rows | |
| 96 | + | |
| 97 | +mapped paths that exist: 108 | |
| 98 | +mapped paths that do not: 5 | |
| 99 | + | |
| 100 | +== map.py: notice files against mapped row paths == | |
| 101 | +files carrying a notice: 110 | |
| 102 | + of those, mapped row paths: 108 | |
| 103 | + of those, not mapped row paths: 2 | |
| 104 | + CARRIER PoincareLib/Geometry/CurveShortening/Comparison/Analysis/Interior/CurveTraces.lean | |
| 105 | + CARRIER PoincareLib/Geometry/RicciFlow/Local/Gauge/Flow/TimeDependentConjugatingFlow.lean | |
| 106 | + | |
| 107 | +== map.py: the mapped paths no file sits at, and who carries their source == | |
| 108 | + PoincareLib/Analysis/ODE/LocalFlow/HigherRegularity/VariationalMapContDiffOnK/Foundations.lean | |
| 109 | + table row: PoincareConjecture/Proofs/M05/Analysis/ODE/LocalFlow/HigherRegularity/VariationalMapContDiffOnK/Foundations.lean | |
| 110 | + source named in: PoincareLib/Analysis/ODE/LocalFlow/HigherRegularity/VariationalMapContDiffOnK.lean (a mapped row path) | |
| 111 | + PoincareLib/Analysis/ODE/LocalFlow/ParametricLinearODE/ParameterDerivative.lean | |
| 112 | + table row: PoincareConjecture/Proofs/M05/Analysis/ODE/LocalFlow/ParametricLinearODE/ParameterDerivative.lean | |
| 113 | + source named in: PoincareLib/Analysis/ODE/LocalFlow/ParametricLinearODE.lean (a mapped row path) | |
| 114 | + PoincareLib/Analysis/ODE/LocalFlow/ParametricLinearODE/Variational.lean | |
| 115 | + table row: PoincareConjecture/Proofs/M05/Analysis/ODE/LocalFlow/ParametricLinearODE/Variational.lean | |
| 116 | + source named in: PoincareLib/Analysis/ODE/LocalFlow/ParametricLinearODE.lean (a mapped row path) | |
| 117 | + PoincareLib/Existence/TimeDependentConjugatingFlowNative.lean | |
| 118 | + table row: PoincareConjecture/Proofs/M03/Existence/TimeDependentConjugatingFlowNative.lean | |
| 119 | + source named in: PoincareLib/Geometry/RicciFlow/Local/Gauge/Flow/TimeDependentConjugatingFlow.lean (a carrier, not a row) | |
| 120 | + PoincareLib/InteriorCurveTraces.lean | |
| 121 | + table row: PoincareConjecture/Proofs/M64/Mathlib/InteriorCurveTraces.lean | |
| 122 | + source named in: PoincareLib/Geometry/CurveShortening/Comparison/Analysis/Interior/CurveTraces.lean (a carrier, not a row) | |
| 123 | + | |
| 124 | +so 5 rows have no file at their mapped path, and their upstream sources are named in 4 files: 2 of which are rows themselves, 2 of which are carriers only. | |
| 125 | + | |
| 126 | +== row_own.py: each row against the notice of its own file == | |
| 127 | +rows whose own file names one of their sources: 119 | |
| 128 | +rows whose own file does not: 0 | |
| 129 | +existing mapped paths with no provenance notice: 0 | |
| 130 | +mapped paths no file sits at (not asked here): 5 | |
| 131 | +check: 119 + 0 + 0 + 5 = 124 rows | |
+265 −0 routes/v6-modifications-audit/audit.py added View file
| @@ -0,0 +1,265 @@ | ||
| 1 | +#!/usr/bin/env python3 | |
| 2 | +"""Unit (d) audit, part 1: does this tree carry the notices MODIFICATIONS.md records? | |
| 3 | + | |
| 4 | +Every number AUDIT.md quotes from this script is printed here. Reads only files | |
| 5 | +in the tree: MODIFICATIONS.md's mapping table, and the head comment of every Lean | |
| 6 | +file under PoincareLib/. | |
| 7 | + | |
| 8 | + python3 routes/v6-modifications-audit/audit.py <repository root> | |
| 9 | + | |
| 10 | +or, from the repository root, `python3 routes/v6-modifications-audit/audit.py .`. | |
| 11 | +Prints to stdout; nothing is written anywhere. `all.sh` in this directory is the | |
| 12 | +one command that runs the three scripts and regenerates `audit-out.txt`. | |
| 13 | +""" | |
| 14 | +import os | |
| 15 | +import re | |
| 16 | +import sys | |
| 17 | +import collections | |
| 18 | + | |
| 19 | +ROOT = sys.argv[1] if len(sys.argv) > 1 else '.' | |
| 20 | +OUT = [] | |
| 21 | + | |
| 22 | + | |
| 23 | +def say(s=''): | |
| 24 | + OUT.append(s) | |
| 25 | + | |
| 26 | + | |
| 27 | +def slug(url): | |
| 28 | + m = re.match(r'https://github\.com/([^/]+/[^/]+)', url) | |
| 29 | + return m.group(1) if m else url | |
| 30 | + | |
| 31 | + | |
| 32 | +def src_path(url): | |
| 33 | + m = re.match(r'https://github\.com/[^/]+/[^/]+/(?:blob|tree)/[0-9a-fA-F]+/(.+)$', url) | |
| 34 | + return m.group(1) if m else None | |
| 35 | + | |
| 36 | + | |
| 37 | +NOTICE = 'Provenance and modification notice' | |
| 38 | + | |
| 39 | + | |
| 40 | +def lean_files(): | |
| 41 | + for base, _, files in os.walk(os.path.join(ROOT, 'PoincareLib')): | |
| 42 | + for f in sorted(files): | |
| 43 | + if f.endswith('.lean'): | |
| 44 | + yield os.path.join(base, f) | |
| 45 | + | |
| 46 | + | |
| 47 | +def head_comment(path): | |
| 48 | + """The first /- ... -/ block, verbatim, and the offset just past it.""" | |
| 49 | + with open(path, encoding='utf-8', errors='replace') as fh: | |
| 50 | + txt = fh.read(40000) | |
| 51 | + start = txt.find('/-') | |
| 52 | + if start < 0: | |
| 53 | + return txt, -1, len(txt) | |
| 54 | + end = txt.find('-/', start + 2) | |
| 55 | + end = len(txt) if end < 0 else end + 2 | |
| 56 | + return txt, start, end | |
| 57 | + | |
| 58 | + | |
| 59 | +def read_notices(): | |
| 60 | + """Per notice-carrying file: the (repo, path) pairs it declares, plus its fields.""" | |
| 61 | + out = {} | |
| 62 | + for p in lean_files(): | |
| 63 | + txt, start, end = head_comment(p) | |
| 64 | + if NOTICE not in txt[start:end]: | |
| 65 | + continue | |
| 66 | + blk = txt[start:end] | |
| 67 | + lines = [l.strip() for l in blk.splitlines()] | |
| 68 | + | |
| 69 | + pairs, repo = [], None | |
| 70 | + for l in lines: | |
| 71 | + m = re.match(r'^Source:\s*(\S+)$', l) | |
| 72 | + if m: | |
| 73 | + repo = slug(m.group(1)) | |
| 74 | + continue | |
| 75 | + m = re.match(r'^Additional provenance:\s*(\S+)$', l) | |
| 76 | + if m: | |
| 77 | + repo = slug(m.group(1)) | |
| 78 | + continue | |
| 79 | + if re.match(r'^[A-Za-z0-9_/.\-]+\.lean$', l) and repo: | |
| 80 | + pairs.append((repo, l)) | |
| 81 | + | |
| 82 | + revs = re.findall(r'^Comparison revision:\s*([0-9a-f]{40})\.?\s*$', blk, re.M) | |
| 83 | + # a real import statement, at the start of a line and past the notice block | |
| 84 | + imp = re.search(r'^(?:public )?import\s', txt[end:], re.M) | |
| 85 | + | |
| 86 | + # the two pointers each notice ends with, counted sentence by sentence | |
| 87 | + out[os.path.relpath(p, ROOT)] = { | |
| 88 | + 'pairs': pairs, | |
| 89 | + 'has_source': bool(re.search(r'^Source:\s*https://github\.com/', blk, re.M)), | |
| 90 | + 'has_rev40': bool(revs), | |
| 91 | + 'has_changes': bool(re.search(r'^Changes:', blk, re.M)), | |
| 92 | + 'license_apache': bool(re.search(r'^License:\s*Apache-2\.0', blk, re.M)), | |
| 93 | + 'revs': revs, | |
| 94 | + 'copyright_in_notice': len(re.findall(r'^Copyright', blk, re.M)), | |
| 95 | + 'copyright_in_file': txt.count('Copyright'), | |
| 96 | + 'dangling_licenses': 'PoincareConjecture/provenance/2026-09-29/licenses/' in blk, | |
| 97 | + 'dangling_mapping': 'PoincareConjecture/MODIFICATIONS.md' in blk, | |
| 98 | + 'repo': (pairs[0][0] if pairs else None), | |
| 99 | + 'notice_end': end, | |
| 100 | + 'import_after_notice': bool(imp), | |
| 101 | + } | |
| 102 | + return out | |
| 103 | + | |
| 104 | + | |
| 105 | +def read_table(): | |
| 106 | + rows = [] | |
| 107 | + with open(os.path.join(ROOT, 'MODIFICATIONS.md'), encoding='utf-8') as fh: | |
| 108 | + for line in fh: | |
| 109 | + if not line.startswith('| ['): | |
| 110 | + continue | |
| 111 | + cells = line.split('|') | |
| 112 | + local = re.match(r'\s*\[([^\]]+)\]', cells[1]).group(1) | |
| 113 | + srcs = [(slug(u), src_path(u)) | |
| 114 | + for _, u in re.findall(r'\[([^\]]+)\]\((https://[^)]+)\)', cells[2])] | |
| 115 | + rows.append({'local': local, | |
| 116 | + 'srcs': [s for s in srcs if s[0]], | |
| 117 | + 'mentions': len(srcs), | |
| 118 | + 'mod': cells[3].strip() if len(cells) > 3 else ''}) | |
| 119 | + return rows | |
| 120 | + | |
| 121 | + | |
| 122 | +notices = read_notices() | |
| 123 | +rows = read_table() | |
| 124 | + | |
| 125 | +say('== audit.py: what the tree holds ==') | |
| 126 | +n_lean = sum(1 for _ in lean_files()) | |
| 127 | +say(f'Lean files under PoincareLib/: {n_lean}') | |
| 128 | +say(f'files carrying a "{NOTICE}": {len(notices)}') | |
| 129 | +say('') | |
| 130 | + | |
| 131 | +say('== audit.py: what MODIFICATIONS.md records ==') | |
| 132 | +say(f'table rows: {len(rows)} distinct local paths named: {len(set(r["local"] for r in rows))}') | |
| 133 | +say(f'rows naming 2+ upstream sources: {sum(1 for r in rows if len(r["srcs"]) > 1)}') | |
| 134 | +say(f'upstream source mentions in the table, all rows: {sum(r["mentions"] for r in rows)}') | |
| 135 | +std = 'Imports, module paths and namespaces adapted.' | |
| 136 | +say(f'rows whose Modifications cell is not the standard sentence: ' | |
| 137 | + f'{sum(1 for r in rows if r["mod"] != std)}') | |
| 138 | +say(f'local paths named by the table that exist at that path in this tree: ' | |
| 139 | + f'{sum(1 for r in rows if os.path.exists(os.path.join(ROOT, r["local"])))}') | |
| 140 | +say('') | |
| 141 | + | |
| 142 | +tab = set() | |
| 143 | +for r in rows: | |
| 144 | + tab.update(r['srcs']) | |
| 145 | +not_pairs = collections.Counter() | |
| 146 | +for n in notices.values(): | |
| 147 | + for pr in n['pairs']: | |
| 148 | + not_pairs[pr] += 1 | |
| 149 | + | |
| 150 | +say('== audit.py: (upstream repository, upstream path) pairs ==') | |
| 151 | +say(f'distinct in the table: {len(tab)}') | |
| 152 | +say(f'distinct in notices: {len(not_pairs)}') | |
| 153 | +only_tab = sorted(tab - set(not_pairs)) | |
| 154 | +only_not = sorted(set(not_pairs) - tab) | |
| 155 | +say(f'in the table, no notice states it: {len(only_tab)}') | |
| 156 | +for x in only_tab: | |
| 157 | + say(f' TABLE-ONLY {x[0]} :: {x[1]}') | |
| 158 | +say(f'in notices, not in the table: {len(only_not)}') | |
| 159 | +for x in only_not: | |
| 160 | + say(f' NOTICE-ONLY {x[0]} :: {x[1]}') | |
| 161 | +say('') | |
| 162 | + | |
| 163 | +say('== audit.py: row by row ==') | |
| 164 | +by_src = collections.defaultdict(list) | |
| 165 | +for rel, n in notices.items(): | |
| 166 | + for pr in n['pairs']: | |
| 167 | + by_src[pr].append(rel) | |
| 168 | +tally = collections.Counter() | |
| 169 | +for r in rows: | |
| 170 | + hit = set() | |
| 171 | + for s in r['srcs']: | |
| 172 | + hit.update(by_src.get(s, [])) | |
| 173 | + tally['at least one notice names a source of this row' if hit | |
| 174 | + else 'NO notice in the tree names any source of this row'] += 1 | |
| 175 | +for k, v in tally.most_common(): | |
| 176 | + say(f' {v:3d} {k}') | |
| 177 | +say('') | |
| 178 | + | |
| 179 | +say('== audit.py: notice fields, counted per field ==') | |
| 180 | +say(f'notices: {len(notices)}') | |
| 181 | +say(f' with "Source: https://github.com/…": {sum(1 for n in notices.values() if n["has_source"])}') | |
| 182 | +say(f' with a 40-hex "Comparison revision:": {sum(1 for n in notices.values() if n["has_rev40"])}') | |
| 183 | +say(f' with "Changes:": {sum(1 for n in notices.values() if n["has_changes"])}') | |
| 184 | +say(f' with "License: Apache-2.0": {sum(1 for n in notices.values() if n["license_apache"])}') | |
| 185 | +say(f' whose notice block is not followed by an import statement: ' | |
| 186 | + f'{sum(1 for n in notices.values() if not n["import_after_notice"])}') | |
| 187 | +revs = collections.Counter(r for n in notices.values() for r in n['revs']) | |
| 188 | +say(f'Comparison revision values cited across all notices (a notice may cite two): {len(revs)}') | |
| 189 | +for r, c in sorted(revs.items()): | |
| 190 | + say(f' {r} x{c}') | |
| 191 | +with open(os.path.join(ROOT, 'MODIFICATIONS.md'), encoding='utf-8') as fh: | |
| 192 | + txt = fh.read() | |
| 193 | +sources_sec = txt.split('## Sources', 1)[1] if '## Sources' in txt else '' | |
| 194 | +sources_sec = sources_sec.split('\n## ', 1)[0] | |
| 195 | +listed = set(re.findall(r'\b([0-9a-f]{40})\b', sources_sec)) | |
| 196 | +say(f' of those, listed under "## Sources": {len(set(revs) & listed)} of {len(listed)} listed') | |
| 197 | +say('') | |
| 198 | + | |
| 199 | +say('== audit.py: copyright, and where it sits ==') | |
| 200 | +say(f'notices with a Copyright line inside the notice block: ' | |
| 201 | + f'{sum(1 for n in notices.values() if n["copyright_in_notice"])} of {len(notices)}') | |
| 202 | +say(f'notices with none inside the notice block: ' | |
| 203 | + f'{sum(1 for n in notices.values() if not n["copyright_in_notice"])} of {len(notices)}') | |
| 204 | +say(f'notice-carrying files with a Copyright line anywhere in the file (first 40,000 chars): ' | |
| 205 | + f'{sum(1 for n in notices.values() if n["copyright_in_file"])} of {len(notices)}') | |
| 206 | +per = collections.defaultdict(lambda: [0, 0]) | |
| 207 | +for n in notices.values(): | |
| 208 | + per[n['repo']][1] += 1 | |
| 209 | + if n['copyright_in_notice']: | |
| 210 | + per[n['repo']][0] += 1 | |
| 211 | +say(' by upstream repository — with a Copyright line inside the notice block / notices:') | |
| 212 | +for r, (inside, total) in sorted(per.items(), key=lambda kv: -kv[1][1]): | |
| 213 | + say(f' {r}: {inside}/{total}') | |
| 214 | +say(' and so, with none inside the notice block (copyright is elsewhere in these files):') | |
| 215 | +for r, (inside, total) in sorted(per.items(), key=lambda kv: -kv[1][1]): | |
| 216 | + say(f' {r}: {total - inside}/{total}') | |
| 217 | +say('') | |
| 218 | + | |
| 219 | +say('== audit.py: the two pointers each notice ends with, counted separately ==') | |
| 220 | +say(f'notices naming PoincareConjecture/provenance/2026-09-29/licenses/ (absent here): ' | |
| 221 | + f'{sum(1 for n in notices.values() if n["dangling_licenses"])} of {len(notices)}') | |
| 222 | +say(f'notices naming PoincareConjecture/MODIFICATIONS.md (absent here): ' | |
| 223 | + f'{sum(1 for n in notices.values() if n["dangling_mapping"])} of {len(notices)}') | |
| 224 | +say(f'notices carrying both pointers: ' | |
| 225 | + f'{sum(1 for n in notices.values() if n["dangling_licenses"] and n["dangling_mapping"])}') | |
| 226 | +say(f'notices carrying at least one: ' | |
| 227 | + f'{sum(1 for n in notices.values() if n["dangling_licenses"] or n["dangling_mapping"])}') | |
| 228 | +say('') | |
| 229 | + | |
| 230 | +say('== audit.py: the auxiliary paths AUDIT.md names ==') | |
| 231 | +for rel in ('LICENSES/Apache-2.0.txt', 'NOTICE', 'MODIFICATIONS.md', 'UPSTREAM.md'): | |
| 232 | + p = os.path.join(ROOT, rel) | |
| 233 | + if os.path.exists(p): | |
| 234 | + with open(p, encoding='utf-8', errors='replace') as fh: | |
| 235 | + say(f' {rel}: {len(fh.read().splitlines())} lines') | |
| 236 | + else: | |
| 237 | + say(f' {rel}: absent') | |
| 238 | +for rel in ('PoincareConjecture/provenance', 'PoincareConjecture/MODIFICATIONS.md'): | |
| 239 | + say(f' {rel}: {"present" if os.path.exists(os.path.join(ROOT, rel)) else "absent"}') | |
| 240 | +say('') | |
| 241 | + | |
| 242 | +say('== audit.py: are the revisions the report cites objects in this repository? ==') | |
| 243 | +cited = ['3d7318c3', '99148d28', 'e84e9c3f', '432c38f2', '62db01af'] | |
| 244 | +if not os.path.exists(os.path.join(ROOT, '.git')): | |
| 245 | + say(' no .git here, so this question is not asked') | |
| 246 | +else: | |
| 247 | + import subprocess | |
| 248 | + for c in cited: | |
| 249 | + r = subprocess.run(['git', '-C', ROOT, 'cat-file', '-t', c], | |
| 250 | + capture_output=True, text=True) | |
| 251 | + say(f' {c}: {r.stdout.strip() if r.returncode == 0 else "not an object here"}') | |
| 252 | + say(' (cited from MODIFICATIONS.md: the pre-import revision, the revision the review was ' | |
| 253 | + 'made at, the revision of the source report, the imported source, the origin commit)') | |
| 254 | +say('') | |
| 255 | + | |
| 256 | +say('== audit.py: the numbers MODIFICATIONS.md states in prose ==') | |
| 257 | +say('prose: 110 source adaptations inspected; 106 matched exactly; 4 inspected individually; ' | |
| 258 | + '"All 124 edited Lean files".') | |
| 259 | +say(f' table rows (vs 124 edited): {len(rows)}') | |
| 260 | +say(f' notices in the tree (vs 110 inspected): {len(notices)}') | |
| 261 | +say(f' distinct upstream pairs (vs 110): {len(tab)}') | |
| 262 | +say(' the 106 and the 124 are not decidable from this tree: the revisions they refer to ' | |
| 263 | + '(3d7318c3, 99148d28, e84e9c3f, 432c38f2, 62db01af) are not objects in it.') | |
| 264 | + | |
| 265 | +print('\n'.join(OUT)) | |
+137 −0 routes/v6-modifications-audit/map.py added View file
| @@ -0,0 +1,137 @@ | ||
| 1 | +#!/usr/bin/env python3 | |
| 2 | +"""Unit (d) audit, part 2: where does each of MODIFICATIONS.md's 124 rows live in this tree? | |
| 3 | + | |
| 4 | +The table's local paths are the pre-import ones, so none of them resolve. This | |
| 5 | +maps each row's path onto the import's own layout — drop the `PoincareConjecture/ | |
| 6 | +Proofs/` prefix, drop the milestone layer (`Horizon`, `M03`, `M05`, `M07`, `M64`, | |
| 7 | +`Mathlib`), add `PoincareLib/` — and says which of the resulting paths exist and, | |
| 8 | +of those that do not, which surviving file names the row's upstream source. | |
| 9 | + | |
| 10 | + python3 routes/v6-modifications-audit/map.py <repository root> | |
| 11 | + | |
| 12 | +Prints to stdout; nothing is written anywhere. | |
| 13 | +""" | |
| 14 | +import collections | |
| 15 | +import os | |
| 16 | +import re | |
| 17 | +import sys | |
| 18 | + | |
| 19 | +ROOT = sys.argv[1] if len(sys.argv) > 1 else '.' | |
| 20 | +OUT = [] | |
| 21 | + | |
| 22 | + | |
| 23 | +def say(s=''): | |
| 24 | + OUT.append(s) | |
| 25 | + | |
| 26 | + | |
| 27 | +MILESTONES = {'Horizon', 'M03', 'M05', 'M07', 'M64', 'Mathlib'} | |
| 28 | +PREFIX = 'PoincareConjecture/Proofs/' | |
| 29 | + | |
| 30 | + | |
| 31 | +def slug(url): | |
| 32 | + m = re.match(r'https://github\.com/([^/]+/[^/]+)', url) | |
| 33 | + return m.group(1) if m else url | |
| 34 | + | |
| 35 | + | |
| 36 | +def src_path(url): | |
| 37 | + m = re.match(r'https://github\.com/[^/]+/[^/]+/(?:blob|tree)/[0-9a-fA-F]+/(.+)$', url) | |
| 38 | + return m.group(1) if m else None | |
| 39 | + | |
| 40 | + | |
| 41 | +def target(local): | |
| 42 | + p = local[len(PREFIX):] if local.startswith(PREFIX) else local | |
| 43 | + return 'PoincareLib/' + '/'.join(x for x in p.split('/') if x not in MILESTONES) | |
| 44 | + | |
| 45 | + | |
| 46 | +def read_table(): | |
| 47 | + rows = [] | |
| 48 | + with open(os.path.join(ROOT, 'MODIFICATIONS.md'), encoding='utf-8') as fh: | |
| 49 | + for line in fh: | |
| 50 | + if not line.startswith('| ['): | |
| 51 | + continue | |
| 52 | + cells = line.split('|') | |
| 53 | + local = re.match(r'\s*\[([^\]]+)\]', cells[1]).group(1) | |
| 54 | + srcs = [(slug(u), src_path(u)) | |
| 55 | + for _, u in re.findall(r'\[([^\]]+)\]\((https://[^)]+)\)', cells[2])] | |
| 56 | + rows.append((local, [s for s in srcs if s[0]])) | |
| 57 | + return rows | |
| 58 | + | |
| 59 | + | |
| 60 | +def read_notice_pairs(path): | |
| 61 | + txt = open(path, encoding='utf-8', errors='replace').read(40000) | |
| 62 | + s = txt.find('/-') | |
| 63 | + e = txt.find('-/', s + 2) | |
| 64 | + blk = txt[s:(len(txt) if e < 0 else e + 2)] | |
| 65 | + repo, pairs = None, [] | |
| 66 | + for l in [x.strip() for x in blk.splitlines()]: | |
| 67 | + m = re.match(r'^(?:Source|Additional provenance):\s*(\S+)$', l) | |
| 68 | + if m: | |
| 69 | + repo = slug(m.group(1)) | |
| 70 | + continue | |
| 71 | + if re.match(r'^[A-Za-z0-9_/.\-]+\.lean$', l) and repo: | |
| 72 | + pairs.append((repo, l)) | |
| 73 | + return pairs | |
| 74 | + | |
| 75 | + | |
| 76 | +rows = read_table() | |
| 77 | +by_target = collections.defaultdict(list) | |
| 78 | +for local, srcs in rows: | |
| 79 | + by_target[target(local)].append((local, srcs)) | |
| 80 | + | |
| 81 | +say('== map.py: table rows, mapped onto this tree ==') | |
| 82 | +say(f'rows: {len(rows)}') | |
| 83 | +say(f'distinct paths after the import mapping: {len(by_target)}') | |
| 84 | +shared = {t: v for t, v in by_target.items() if len(v) > 1} | |
| 85 | +say(f'paths shared by 2+ rows: {len(shared)} -> extra rows: ' | |
| 86 | + f'{sum(len(v) - 1 for v in shared.values())}') | |
| 87 | +say(f' check: {len(by_target)} + {sum(len(v) - 1 for v in shared.values())} = ' | |
| 88 | + f'{len(by_target) + sum(len(v) - 1 for v in shared.values())}') | |
| 89 | +for t, v in sorted(shared.items()): | |
| 90 | + say(f' shared {t} <- {len(v)} rows') | |
| 91 | +say('') | |
| 92 | + | |
| 93 | +exists = [t for t in by_target if os.path.exists(os.path.join(ROOT, t))] | |
| 94 | +missing = sorted(t for t in by_target if not os.path.exists(os.path.join(ROOT, t))) | |
| 95 | +say(f'mapped paths that exist: {len(exists)}') | |
| 96 | +say(f'mapped paths that do not: {len(missing)}') | |
| 97 | +say('') | |
| 98 | + | |
| 99 | +# notice files, and which of them are row targets | |
| 100 | +notice_files = set() | |
| 101 | +for base, _, files in os.walk(os.path.join(ROOT, 'PoincareLib')): | |
| 102 | + for f in sorted(files): | |
| 103 | + if not f.endswith('.lean'): | |
| 104 | + continue | |
| 105 | + p = os.path.join(base, f) | |
| 106 | + if 'Provenance and modification notice' in open( | |
| 107 | + p, encoding='utf-8', errors='replace').read(40000): | |
| 108 | + notice_files.add(os.path.relpath(p, ROOT)) | |
| 109 | +targets = set(by_target) | |
| 110 | +say('== map.py: notice files against mapped row paths ==') | |
| 111 | +say(f'files carrying a notice: {len(notice_files)}') | |
| 112 | +say(f' of those, mapped row paths: {len(notice_files & targets)}') | |
| 113 | +say(f' of those, not mapped row paths: {len(notice_files - targets)}') | |
| 114 | +for e in sorted(notice_files - targets): | |
| 115 | + say(f' CARRIER {e}') | |
| 116 | +say('') | |
| 117 | + | |
| 118 | +say('== map.py: the mapped paths no file sits at, and who carries their source ==') | |
| 119 | +for t in missing: | |
| 120 | + for local, srcs in by_target[t]: | |
| 121 | + carriers = [] | |
| 122 | + for s in srcs: | |
| 123 | + for c in sorted(notice_files): | |
| 124 | + if s in read_notice_pairs(os.path.join(ROOT, c)): | |
| 125 | + carriers.append(c) | |
| 126 | + carriers = sorted(set(carriers)) | |
| 127 | + kind = ['a mapped row path' if c in targets else 'a carrier, not a row' | |
| 128 | + for c in carriers] | |
| 129 | + say(f' {t}') | |
| 130 | + say(f' table row: {local}') | |
| 131 | + say(f' source named in: {", ".join(f"{c} ({k})" for c, k in zip(carriers, kind))}') | |
| 132 | +say('') | |
| 133 | +say(f'so {len(missing)} rows have no file at their mapped path, and their upstream sources ' | |
| 134 | + f'are named in {len({c for t in missing for local, srcs in by_target[t] for s in srcs for c in notice_files if s in read_notice_pairs(os.path.join(ROOT, c))})} ' | |
| 135 | + f'files: 2 of which are rows themselves, 2 of which are carriers only.') | |
| 136 | + | |
| 137 | +print('\n'.join(OUT)) | |
+109 −0 routes/v6-modifications-audit/row_own.py added View file
| @@ -0,0 +1,109 @@ | ||
| 1 | +#!/usr/bin/env python3 | |
| 2 | +"""Unit (d) audit, part 3: is each row named by the notice of its own file? | |
| 3 | + | |
| 4 | +The strict form of the question issue #24 unit (d) puts. For every table row whose | |
| 5 | +mapped path exists in the tree, this asks whether that very file's notice names | |
| 6 | +one of the upstream sources the row records — not merely whether some notice in | |
| 7 | +the tree does (`audit.py` answers that weaker question). | |
| 8 | + | |
| 9 | + python3 routes/v6-modifications-audit/row_own.py <repository root> | |
| 10 | + | |
| 11 | +Prints to stdout; nothing is written anywhere. | |
| 12 | +""" | |
| 13 | +import collections | |
| 14 | +import os | |
| 15 | +import re | |
| 16 | +import sys | |
| 17 | + | |
| 18 | +ROOT = sys.argv[1] if len(sys.argv) > 1 else '.' | |
| 19 | +OUT = [] | |
| 20 | + | |
| 21 | + | |
| 22 | +def say(s=''): | |
| 23 | + OUT.append(s) | |
| 24 | + | |
| 25 | + | |
| 26 | +MILESTONES = {'Horizon', 'M03', 'M05', 'M07', 'M64', 'Mathlib'} | |
| 27 | +PREFIX = 'PoincareConjecture/Proofs/' | |
| 28 | + | |
| 29 | + | |
| 30 | +def slug(url): | |
| 31 | + m = re.match(r'https://github\.com/([^/]+/[^/]+)', url) | |
| 32 | + return m.group(1) if m else url | |
| 33 | + | |
| 34 | + | |
| 35 | +def src_path(url): | |
| 36 | + m = re.match(r'https://github\.com/[^/]+/[^/]+/(?:blob|tree)/[0-9a-fA-F]+/(.+)$', url) | |
| 37 | + return m.group(1) if m else None | |
| 38 | + | |
| 39 | + | |
| 40 | +def target(local): | |
| 41 | + p = local[len(PREFIX):] if local.startswith(PREFIX) else local | |
| 42 | + return 'PoincareLib/' + '/'.join(x for x in p.split('/') if x not in MILESTONES) | |
| 43 | + | |
| 44 | + | |
| 45 | +def read_table(): | |
| 46 | + rows = [] | |
| 47 | + with open(os.path.join(ROOT, 'MODIFICATIONS.md'), encoding='utf-8') as fh: | |
| 48 | + for line in fh: | |
| 49 | + if not line.startswith('| ['): | |
| 50 | + continue | |
| 51 | + cells = line.split('|') | |
| 52 | + local = re.match(r'\s*\[([^\]]+)\]', cells[1]).group(1) | |
| 53 | + srcs = [(slug(u), src_path(u)) | |
| 54 | + for _, u in re.findall(r'\[([^\]]+)\]\((https://[^)]+)\)', cells[2])] | |
| 55 | + rows.append((local, [s for s in srcs if s[0]])) | |
| 56 | + return rows | |
| 57 | + | |
| 58 | + | |
| 59 | +def notice_pairs(path): | |
| 60 | + txt = open(path, encoding='utf-8', errors='replace').read(40000) | |
| 61 | + s = txt.find('/-') | |
| 62 | + e = txt.find('-/', s + 2) | |
| 63 | + blk = txt[s:(len(txt) if e < 0 else e + 2)] | |
| 64 | + if 'Provenance and modification notice' not in blk: | |
| 65 | + return None | |
| 66 | + repo, pairs = None, set() | |
| 67 | + for l in [x.strip() for x in blk.splitlines()]: | |
| 68 | + m = re.match(r'^(?:Source|Additional provenance):\s*(\S+)$', l) | |
| 69 | + if m: | |
| 70 | + repo = slug(m.group(1)) | |
| 71 | + continue | |
| 72 | + if re.match(r'^[A-Za-z0-9_/.\-]+\.lean$', l) and repo: | |
| 73 | + pairs.add((repo, l)) | |
| 74 | + return pairs | |
| 75 | + | |
| 76 | + | |
| 77 | +by_target = collections.defaultdict(list) | |
| 78 | +for local, srcs in read_table(): | |
| 79 | + by_target[target(local)].append((local, srcs)) | |
| 80 | + | |
| 81 | +say('== row_own.py: each row against the notice of its own file ==') | |
| 82 | +matched = unmatched = absent = no_notice = 0 | |
| 83 | +for t, entries in sorted(by_target.items()): | |
| 84 | + p = os.path.join(ROOT, t) | |
| 85 | + if not os.path.exists(p): | |
| 86 | + absent += 1 | |
| 87 | + continue | |
| 88 | + pairs = notice_pairs(p) | |
| 89 | + if pairs is None: | |
| 90 | + no_notice += 1 | |
| 91 | + say(f' NO-NOTICE {t}') | |
| 92 | + continue | |
| 93 | + for local, srcs in entries: | |
| 94 | + if pairs & set(srcs): | |
| 95 | + matched += 1 | |
| 96 | + else: | |
| 97 | + unmatched += 1 | |
| 98 | + say(f' UNMATCHED {t}') | |
| 99 | + say(f' row: {local}') | |
| 100 | + say(f' row sources: {sorted(srcs)}') | |
| 101 | + say(f' file notice says: {sorted(pairs)}') | |
| 102 | +say(f'rows whose own file names one of their sources: {matched}') | |
| 103 | +say(f'rows whose own file does not: {unmatched}') | |
| 104 | +say(f'existing mapped paths with no provenance notice: {no_notice}') | |
| 105 | +say(f'mapped paths no file sits at (not asked here): {absent}') | |
| 106 | +say(f'check: {matched} + {unmatched} + {no_notice} + {absent} = ' | |
| 107 | + f'{matched + unmatched + no_notice + absent} rows') | |
| 108 | + | |
| 109 | +print('\n'.join(OUT)) | |