Skip to content

feat(persistence): executable F₂ grid representations and their Kan-extension ranks (#999) - #1000

Merged
t-uda merged 1 commit into
developfrom
ccr-eb669e62-a5kqoa
Nov 20, 2026
Merged

t-uda merged 1 commit into
developfrom
ccr-eb669e62-a5kqoa

Conversation

@t-uda

@t-uda t-uda commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

Closes #999

Summary

Second unit of #925 (finite-grid rank-erosion tests): executable F₂ data for a grid module, its validation, the actual module it defines, and an executable rank proved equal to the rank of the actual Kan extension.

  • New TDA/Persistence/F2GridRep.lean (namespace TDA.Persistence):
    • RatGrid n := Fin n → List ℚ: rational grid values used as finite sets; points, the real grid, ratPoint / pointOfRat between grid points and rational grid grades, and the executable hasLower, floorCoord, floor with ratPoint_floor (the executable floor is the rational grade of the real floor).
    • F2GridRep n: values, dim, map; the decidable Valid (identities on the diagonal, composition along comparable triples of grid grades); toModule for a valid representation with structureMapLinear_toModule, a finite-dimensionality instance and rankOfStructureMap_toModule.
    • rankAt x y, executable, with rankAt_eq and rankAt_eq_of_eq: it is the rank of R.grid.lan.obj (R.toModule h) between the real grades of x ≤ y.
  • New TDA/Persistence/F2GridRepExamples.lean, routed through TDA/Persistence/Examples.lean.
  • docs/api.md, docs/math/rank-erosion.md, CHANGELOG.md, pins.

The erosion test and its certificate (third unit of #925) are not part of this PR.

Branch lifecycle

Ordinary develop topic: based on develop 122de80cd8ed5f9d5548a5330d48aa3cb0560038, target develop, squash merge. Target scope: computation lane under #227 / #865 Package C (#925, part 2); release version undecided. Propagation: N/A.

Public declarations added / changed

Added in TDA.Persistence.RatGrid: realGrade, realGrade_apply, realGrade_le_iff, realGrade_injective, points, mem_points, grid, mem_grid, ratPoint, ratPoint_mem, ratPoint_cast, realGrade_ratPoint, ratPoint_mem_points, ratPoint_le_iff, pointOfRat, embedding_pointOfRat, ratPoint_pointOfRat, pointOfRat_ratPoint, hasLower, floorCoord, floor, floorCoord_spec, hasLower_iff, hasLowerPoint_realGrade_iff, floor_mem_points, ratPoint_floor; and the abbreviation TDA.Persistence.RatGrid.

Added in TDA.Persistence.F2GridRep: the structure, Valid with its Decidable instance, grid, toModule, toModule_obj, structureMapLinear_toModule, finiteDimensional_toModule_obj, rankOfStructureMap_toModule, rankAt, rankAt_eq, rankAt_eq_of_eq.

Added in TDA.Persistence.F2GridRepExamples: interval, messy, planeDim, plane, badComposition, badIdentity, noCoordinates, emptyGrid and 27 theorems about them.

No existing declaration changes.

Source ↔ Lean correspondence

Library-derived contract (#999); no paper statement is formalised. The signatures are those of the contract in #999. Deviation: the finite-dimensionality instance is named finiteDimensional_toModule_obj (the contract lists it as an anonymous instance), so that it can be pinned.

rankAt_eq is a statement about the actual Kan extension R.grid.lan.obj (R.toModule h) and the existing rankOfStructureMap. Nothing is claimed for an invalid representation or when x ≤ y fails.

Validation

Evaluated head d69b1c2d84385855ed051d0b1c94ef66c7ec5472, base 122de80cd8ed5f9d5548a5330d48aa3cb0560038.

  • Hosted check: success — run 44653220611 / job 136013000882 on this head: AXIOM AUDIT OK — 13548 declaration(s), PRIVATE AUDIT — 10503 private theorem root(s), COVERAGE OK — 10909 public theorems, all pinned, Comparator "Lean default kernel accepts the solution", CHECK OK. The docs job was skipped (manual dispatch only).
  • Local scripts/check.sh (full gate) on this head: exit 0, CHECK OK, the same three counts, Comparator accepted (1m47s, warm build).
  • Against the base's counts (13497 / 10502 / 10858): +51 audited declarations and +51 public theorems are the 51 appended pins (24 library theorems including the named instance, 27 example theorems); +1 private root is the private helper rank_map_congr.
  • A first local run of the gate on the unamended commit failed the coverage guard: the then anonymous finite-dimensionality instance was an unpinned public theorem. It was named and pinned, the local commit amended before any push, and the gate rerun on this head.
  • git push pre-push gate: passed.
  • The examples module, all of whose fixtures are decide +kernel, builds in about 7 s.
  • Not run: scripts/test-guards.sh, doc generation. No TauCeti search was made (not a dependency).

Remaining sorry / custom-axiom footprint

none

Independent review evidence

  • Pre-admission review of the contract is recorded in [Multi PH computation] Executable F₂ matrix representations on rational grids and their Kan-extension ranks (#925, part 2) #999 (no substantive finding; its advisory points were adopted before implementation).
  • Reviewed-by: comment on head d69b1c2: read-only reviewer in a session and model distinct from the implementer, digest-based; verdict pass, no substantive finding. Four non-substantive notes, not acted on in this PR and to be folded into the next change to these files: the digest says the data define a module "exactly when" Valid holds, while only the direction from Valid is formalised; dot notation on a RatGrid needs the type written as RatGrid n; the docstring of plane_rank_between describes the target grade only; the examples docstring does not name the zero-dimensional fiber case, which interval at grade 1 covers.
  • Codex review on head d69b1c2 (triggered by "PR opened"): completed with no findings, per its review summary comment.

🤖 Generated with Claude Code

https://claude.ai/code/session_01RfoZqCRSgoUin4otWc6fXL

…xtension ranks (#999)

Add RatGrid (rational grid values, their real coordinate grid, rational grades
of grid points and an executable floor) and F2GridRep (fiber dimensions and F₂
matrices with a decidable validity condition). A valid representation defines
the actual grid module, and the executable rankAt at rational grades is proved
equal to the rank of the actual Kan extension.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01RfoZqCRSgoUin4otWc6fXL
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 20, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-20T01:24:31.915160Z d69b1c2 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

t-uda commented Nov 20, 2026

Copy link
Copy Markdown
Contributor Author

Reviewed-by: claude-opus read-only reviewer (session distinct from the implementer)

Reviewed head: d69b1c2d84385855ed051d0b1c94ef66c7ec5472 (base develop 122de80cd8ed5f9d5548a5330d48aa3cb0560038), governed by #999.
Compiled: one scratch file .agents/scratch/review999.lean (deleted afterwards) importing TDA.Persistence.F2GridRepExamples, run with scripts/lean.sh lake env lean. It ran #eval on interval.rankAt [0] [1/2] (1), interval.rankAt [999/1000] [999/1000] (1), messy.rankAt [7] [7] (0), plane.rankAt [1/2, 0] [1/2, 3] (1), decide plane.Valid (true), decide badComposition.Valid (false) and messy.values.floor [7] ([1]); #print axioms on RatGrid.points/hasLower/floorCoord/floor, F2GridRep.rankAt, F2GridRep.instDecidableValid and F2Matrix.rank; a dot-notation probe; and decide +kernel of RatGrid.floor (fun _ => [3, 1, 3, 2]) [5/2] = [2] (accepted). No build or gate was run.
Comparison mode: digest-based, against the #999 contract and the existing library definitions; there is no primary paper source.

Verdict: pass. No substantive findings. Four non-substantive findings.

Findings

  1. NON-SUBSTANTIVE (overstated wording in the docs). docs/math/rank-erosion.md (new section, first paragraph) says the data "define a module on the real image of the grid exactly when" Valid holds. Lean proves only one direction: Valid gives toModule (F2GridRep.lean:198-209). The converse is true (pull the functor laws back along pointOfRat) but is not formalised. The module docstring (F2GridRep.lean:15-17) and docs/api.md state only the proved direction. Suggestion: write "when", or say that the converse is not formalised.
  2. NON-SUBSTANTIVE (API usability for the third unit of [Multi PH computation] Certify finite-grid rank-erosion tests #925). Dot notation works only when the type is literally RatGrid n. The scratch probe example (V : RatGrid 2) := V.points elaborates. example (V : Fin 2 → List ℚ) := V.points fails with Invalid field points: The environment does not contain Function.points. There is no clash: field notation never resolves to a wrong declaration. Inside the library, F2GridRep.values : RatGrid n makes R.values.points/floor/grid reliable. A breakpoint grid in the third unit must be ascribed RatGrid n, or the functions must be called as RatGrid.floor V x. This could be noted in the RatGrid docstring.
  3. NON-SUBSTANTIVE (fixture docstring). F2GridRepExamples.lean:106 says "A grade between grid values in one coordinate and above them in the other". That describes y = [1/2, 3] only; x = [1/2, 0] sits on the grid value 0 in its second coordinate. The value itself is correct: the floors are (0,0) and (0,1), and the matrix [1 1] has rank 1.
  4. NON-SUBSTANTIVE (fixture docstring). The module docstring of the examples (F2GridRepExamples.lean:16) lists the degenerate cases as "no coordinates, and an empty value list". The zero-dimensional fiber that [Multi PH computation] Executable F₂ matrix representations on rational grids and their Kan-extension ranks (#925, part 2) #999 also requires is present (interval at grade 1: interval_valid uses a 0×0 diagonal, and interval_rank_at_one/interval_rank_after are 0×0 ranks) but is not named there.

Risks

  1. Contract fidelity. Every contract name is present with the contract's signature: 18 RatGrid theorems, realGrade/points/grid/ratPoint/pointOfRat/hasLower/floorCoord/floor, the structure fields, Valid, the unnamed Decidable instance, grid (noncomputable abbrev), toModule, toModule_obj, structureMapLinear_toModule, rankOfStructureMap_toModule, rankAt, rankAt_eq and rankAt_eq_of_eq. There is one difference, the documented one: the FiniteDimensional instance is named finiteDimensional_toModule_obj (F2GridRep.lean:221). Docstrings and a private helper rank_map_congr (:237) were also added. The bodies of points (:58), grid (:64-65), Valid (:184-187), hasLower (:109), floorCoord (:113), floor (:116) and rankAt (:234-235) match the contract verbatim. No statement is weakened or specialised, and there are no extra hypotheses.
  2. Meaning. (a) Valid is exactly identity at every grid grade plus map b c * map a b = map a c for all grid grades with a ≤ b ≤ c, in the Pi (coordinatewise) order on Fin n → ℚ. (b) toModule has fibers Fin (dim (ratPoint p)) → ZMod 2 and, for p ≤ q, map equal to mulVecLin of R.map (ratPoint p) (ratPoint q) : Matrix (Fin (dim q')) (Fin (dim p')). That sends the fiber at p to the fiber at q, the right way round. map_id uses only h.1. map_comp uses only h.2 with ratPoint_le_iff and Matrix.mulVecLin_mul; (B*A).mulVecLin = B.mulVecLin ∘ A.mulVecLin matches f ≫ g. Neither proof uses any other assumption. (c) rankAt_eq has the actual R.grid.lan.obj (R.toModule h) and the existing rankOfStructureMap on its right-hand side, at realGrade x ≤ realGrade y. It requires both h : R.Valid and hxy : x ≤ y, so it says nothing otherwise. The proof splits on the real HasLowerPoint and uses rankOfStructureMap_lan/_lan_eq_zero. (d) ratPoint_floor identifies the classical real floor's rational grade with the list floor. Lists are read only through toFinset and ∈, so order and repetition are irrelevant; the scratch check on [3,1,3,2] confirms this. Grades below every listed value are excluded by the hypothesis, and hasLowerPoint_realGrade_iff makes both sides false there, as well as for an empty list.
  3. Executability. The only noncomputable declarations are RatGrid.grid (:64), ratPoint (:71), pointOfRat (:93), F2GridRep.grid (:194) and toModule (:198). realGrade is a plain def; it casts to ℝ but compares nothing and is not used by any executable definition. #print axioms: hasLower, floorCoord and floor depend on no axioms. points, rankAt, instDecidableValid and F2Matrix.rank list [propext, Classical.choice, Quot.sound]; these come from proof terms inside their bodies, not from the data path. Two facts show that: kernel decide +kernel reduces all 27 fixtures, which a Classical.choice on the data path would block, and #eval of rankAt and decide Valid compiled and ran.
  4. Examples. Hand computations agree with every stated value.
    • interval: [0] [1/2] gives floors 0,0, a 1×1 all-ones matrix, rank 1. [-1] has no lower value: 0. [1] [2] and [1] [1] use a 0×0 matrix: 0. [999/1000] has floor 0: rank 1. [1/2] [1] has floors 0 and 1, a 0×1 matrix: 0.
    • messy gives the same values. floor [7] = [1], which has fiber dimension 0. The value 0 would be 1 if the off-grid dim 7 = 5 were read, so the fixture discriminates.
    • plane is valid by hand: diagonals are I₂ or I₁; the origin is the minimum, so maps into it are never read; and [1] * [1 1] = [1 1] along origin ≤ b ≤ c, together with the identities, covers every comparable triple. It gives origin 2, origin→(1,0) rank 1, and floors (0,0)→(0,1) rank 1.
    • badComposition fails only composition (0→1→2 composes to 1·1 = 1, but the stored 0→2 matrix is 0; diagonals are 1). badIdentity fails only identity (diagonal 0; 0·0 = 0 composes).
    • noCoordinates: one grade, hasLower vacuously true, I₃ gives rank 3. emptyGrid: no points, so Valid holds vacuously, and rankAt is 0.
    • The three …_extension_rank_… theorems rewrite with ← rankAt_eq and close by the executed fixture, so they are genuine transfers to the actual Kan extension.
    • Every [Multi PH computation] Executable F₂ matrix representations on rational grids and their Kan-extension ranks (#925, part 2) #999 acceptance item is present. No fixture is vacuous or mislabelled beyond findings 3 and 4.
  5. Semantic and API quality. The module docstring, docs/api.md and the CHANGELOG claim no erosion test, no certificate, no polynomial cost and nothing for invalid data. "Exponential in the fiber dimension and the number of coordinates" is accurate: rank enumerates source vectors, and the number of grades is a product over coordinates. The overstatement is finding 1. The new code reuses hasLowerPoint_iff, le_floor_apply_iff, floor_le, hasLowerPoint_mono, rankOfStructureMap_lan(_eq_zero), F2Matrix.rank_eq_finrank_range, Rat.cast_le/injective and List.max?_mem/_le_iff; I found no duplicate. Hypotheses are natural: ratPoint_floor needs the real HasLowerPoint because grid.floor needs it, and floor_mem_points uses the Bool hasLower, consistent with rankAt. rankAt_eq_of_eq is the form the third unit needs. The anchor #executable-representations-over-the-two-element-field matches the new heading, and docs/math/finite-ph-map-dimensions.md exists. Dot notation: finding 2.
  6. Bookkeeping. There are 51 appended pins (24 library: 18 RatGrid, 6 F2GridRep including the named instance; 27 examples) for 51 public theorems, each pinned exactly once. The private rank_map_congr and the Decidable instance (data) are correctly unpinned. No existing pin line changed (no removed lines). TDA/Persistence.lean and TDA/Persistence/Examples.lean gain one import each and remain imports-only. No Lean line in the two new files exceeds 100 characters (counted in characters). The new pin lines are also within 100. The pin header (Issue #999) follows the file's existing 69-instance convention. There are no scratch artefacts or chronology in the library files or their docstrings.

Checks not performed

I did not rerun scripts/check.sh, the axiom audit or Comparator (gate evidence for this head was taken as given). I did not observe hosted CI check; the merge decision must confirm it succeeded on this head. I did not compare against a paper source (none applies). I did not measure performance.


Generated by Claude Code

@t-uda
t-uda merged commit fa2a892 into develop Nov 20, 2026
4 checks passed
t-uda pushed a commit that referenced this pull request Nov 20, 2026
…ations (#1001)

Add the rational breakpoint grid and F2GridRep.runErosion, which validates two
representations and a rational radius and returns invalid, pass, or a failed
inequality with its direction, grades and ranks. The three outcomes are proved
correct for RankErosion of the actual Kan extensions through the finite
criterion. Fold in the documentation notes from the review of #1000.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01RfoZqCRSgoUin4otWc6fXL
t-uda added a commit that referenced this pull request Nov 20, 2026
…ations (#1001) (#1002)

* feat(persistence): executable rank-erosion test for F₂ grid representations (#1001)

Add the rational breakpoint grid and F2GridRep.runErosion, which validates two
representations and a rational radius and returns invalid, pass, or a failed
inequality with its direction, grades and ranks. The three outcomes are proved
correct for RankErosion of the actual Kan extensions through the finite
criterion. Fold in the documentation notes from the review of #1000.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01RfoZqCRSgoUin4otWc6fXL

* feat(persistence): record breakpoint membership in the erosion certificate (#1001)

Deduplicate the rational breakpoint lists, state in runErosion_eq_fail that the
reported grades are breakpoint grades, and add fixtures for a failing
two-parameter comparison, a passing one between different modules and an empty
value list. State the breakpoint count in the documentation.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01RfoZqCRSgoUin4otWc6fXL

---------

Co-authored-by: Claude <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants