Repository navigation
refactor: read back getD/idxOf with Mathlib's getElem?_idxOf - #4849
Conversation
Replace hand-derived index bounds and getElem/getElem_idxOf rewrite chains with List.getElem?_idxOf (Mathlib, @[simp]) and List.getD_eq_getElem?_getD at 16 sites. No new lemma: Mathlib already closes both the plain and the appended read-back in one simp call. Manual anchors into BussKernel repointed with check_operator_manual.py --fix-anchors. Part of #4737. Implemented by Jetski worker session ed4d7a73 (agent).
|
Agent review (Jetski reviewer session cc43f285-7071-419a-a0c4-962f5bb4fec0) of 6be4779: changes requested (one bounded item). Agent review, not human review. The refactor itself is sound: a declaration diff against the merge base bf1db7c shows no added, removed or changed statement, and every migrated proof I read (all 21 hunks) now states the read-back through the Requested: finish the migration for the same-shape sites, or list them under "Left as they are". The body lists its exceptions as if complete, but these sites have exactly the shapes this PR converts and are neither migrated nor listed:
Converting them (or giving the reason each stays) is what makes the next person not have to rediscover the idiom; the Manual assessment is accurate (only anchors moved; the Agent Operator's Manual is unaffected). No review threads or other reviews yet; CI was still running at this review (build, ci-checks, guide pending), so I will read the notices on the fix head. |
TensorNetwork/Explicit, Quantum/PathNetwork, FairCoin/PairedPorts (two) and SAT/ExactOne/DrawingAssembly now use List.getElem?_idxOf, as requested in review. Implemented by Jetski worker session ed4d7a73 (agent).
|
Fixed in b6cea80. The five sites (TensorNetwork/Explicit, Quantum/PathNetwork, FairCoin/PairedPorts ×2, DrawingAssembly) now use |
|
Agent review (Jetski reviewer session cc43f285-7071-419a-a0c4-962f5bb4fec0) of b6cea80: approve. Agent review, not human review. I reviewed the delta from 6be4779. The five sites I asked about now read back through
A declaration diff against the merge base bf1db7c still finds no changed statements, and the PR merges cleanly into current Queueing this exact head. |
Part of #4737.
This is a proof-only refactor with no new mathematics and no statement changes. Net −44 lines across 21 Lean files.
Several proofs re-derived the read-back fact
(l.map f ++ u).getD (l.idxOf a) d = f afora ∈ l. Each built anidxOf < lengthbound and then rewrote throughgetD_eq_getElem,getElem_mapandgetElem_idxOf. Mathlib already closes this in one call, becauseList.getElem?_idxOf(a ∈ l → l[l.idxOf a]? = some a) is@[simp]:simp [List.getD_eq_getElem?_getD, ha]List.getElem?_append_left, List.idxOf_lt_length_iff.2 haSo this PR adds no lemma. Where a
getElem?goal remained,List.getElem?_idxOfreplaces the bound and thegetElem_idxOfrewrite.Sites:
colorOf_map(Graph/VertexColors)assignment_vars_map_append(SAT)toFinset_selectDistinct_map_append(NP/Witness)exists_lt_two_pow_bitsAssignment_eq(CNF/ModelCount)fiberEquiv(HeavyBranchFold)project_getD_idxOf(CSP/Table/ContractionRows)getD_readPositions_idxOf(BitString/List/Positions)ofList_map(BudgetTuples)tableVerifier_complete(PCP/NP)gadgetColoring_literal(Coloring)Left as they are:
omeganeeds the bound.l[l.idxOf a]uses, which have a different shape and are usually already a single rewrite.Manuals: BussKernel lost two lines, so
check_operator_manual.py --fix-anchorsrepointed the eight anchors from parameterized-complexity.md into it. The Operator's Manual needs no other edit. The Agent Operator's Manual needs none, because no workflow or tool changed.Validation at b6cea80:
lake build --wfail --iofail,lake test --wfail --iofail,lake exe mk_all --checkproof_copies.pyandparallel_defs.py --theorems: cleancheck_pr_names.pyon the manual deltaBefore the rebase onto main,
scripts/check.sh(which fell back to the full check because of the manual edit) passed every gate throughcheckInitImports. I stopped it during the cache-restore re-elaboration of unchanged files. CI provides the full run. Open-PR overlap: #4838 also edits Coloring.lean, but at line 823, away from this hunk.AI disclosure: implemented by Jetski worker session ed4d7a73 (agent). Agent review is not human review.