Skip to content

refactor(Complexity/Reduction): public word take/drop/append reductions; migrate copies - #4794

Merged
SamuelSchlesinger merged 2 commits into
mainfrom
refactor/cx-take-reduction
Nov 12, 2026
Merged

SamuelSchlesinger merged 2 commits into
mainfrom
refactor/cx-take-reduction

Conversation

@SamuelSchlesinger

@SamuelSchlesinger SamuelSchlesinger commented Nov 12, 2026 •

Copy link
Copy Markdown
Collaborator

The library re-derived the polynomial-time reductions that cut or extend the word of an instance–word pair several times. This PR proves them once, as public lemmas in a new small module Complexity/Reduction/Word.lean, and migrates the copies. Statements of client theorems are unchanged. This is infrastructure and refactoring, not new mathematics.

  • polyTimeReducible_take / polyTimeReducible_drop keep or drop the first N a bits of w in (a, w), for any N computable in polynomial time in unary. They replace:
    • Kadin's private polynomial-only copies in BooleanHierarchy/Kadin.lean;
    • the inline reduction in mem_SigmaP_of_exists_length (PH/Reduction.lean);
    • the inline reduction in PPolyOn.exists_of_computableInPolyTime_length (PPoly/Closure.lean).
  • polyTimeReducible_append was private in PH/Reduction.lean and is now public. It is stated with a pattern set-builder, {((a, s), u) | (a, s ++ u) ∈ C}, so that it adds no projection chains. It also replaces the inline transducer in alternationSet_mem_PSPACE (Classes/Inclusions.lean).
  • computableInPolyTime_takeBlocks (PH/Projection.lean) is one induction for cutting blocks whose lengths are computed in unary. computableInPolyTime_truncateBlocks and the private computableInPolyTime_trimUniformBlocks (RecursivelyPresentable/Classes.lean) now instantiate it instead of repeating the induction.
  • Follow-ups from the refactor(Complexity/PH): list take-quantifier lemmas and one block-cutting alternation lemma #4760 review:
    • List.exists_length_eq_take_iff / forall_length_eq_take_iff now assume [Nonempty α] instead of [Inhabited α].
    • TakeQuantifiers.lean is now marked candidate (Mathlib, Mathlib/Data/List/TakeDrop.lean).
    • PPoly/Closure.lean now uses these lemmas in its two length/take quantifier arguments instead of padding by hand.

Net: +132 / −103 over 10 files (net +29; the new module is 61 lines). The new module's header and docstring account for most of the added lines; the duplicated proofs shrink.

Manuals.

  • Operator's Manual: the PH paragraph of verifiers-counting-interaction.md now has one sentence pointing to the word reductions, so the next certificate or quantifier proof can find them.
  • Agent Operator's Manual: no edit, because no workflow, command or agent procedure changes.
  • ROADMAP.md, the results inventory and the upstream markers are unaffected, apart from the TakeQuantifiers marker above.

Validation.

  • lake build --wfail through buildslot passed on the changed modules and their clients:
    • TakeQuantifiers, Reduction.Word, PH.{Projection, Reduction, Collapse, Yap, KarpLipton}, Inclusions, RecursivelyPresentable.Classes, Sparse.Kadin, Time.{SigmaTwo, SigmaTwoChain}, TimeSpace.Slowdown, BooleanHierarchy.Kadin, PPoly.Closure and the MCSP importers;
    • the tests Kadin, ResourceClasses2, SparseKadin and UniformDiagonalization.
  • These checks also passed: lake exe mk_all --check, check_hygiene.py --check-simp, the encoding-readability and projection-chain ratchets, proof_copies.py (no repeated block) and check_operator_manual.py.
  • Hosted CI runs the full validation.

Part of #4737. Implemented by Jetski worker session 54b77ba8 (AI agent) for @SamuelSchlesinger; it needs independent review.

…ns; migrate copies

Prove once, in the new module Complexity/Reduction/Word.lean, the
polynomial-time reductions that keep or drop the first N a bits of the
word of an instance-word pair and that append a second word. Migrate
Kadin's private copies, the inline reductions in
mem_SigmaP_of_exists_length, PPolyOn.exists_of_computableInPolyTime_length
and alternationSet_mem_PSPACE, and the private append lemma of
PH/Reduction.

Add computableInPolyTime_takeBlocks and derive
computableInPolyTime_truncateBlocks and the private
computableInPolyTime_trimUniformBlocks from it.

TakeQuantifiers: [Nonempty α] instead of [Inhabited α], Mathlib
upstream marker; use its lemmas in PPoly/Closure.

Part of #4737. Jetski worker session 54b77ba8.
@edemaine

edemaine commented Nov 12, 2026 •

Copy link
Copy Markdown
Collaborator

Landed as e55b04c0 at 2026-11-12 21:49:32 UTC, from exact approved bd061007204defe1af36a551945d56fd133a3b5a. This session verified actual landing after the existing queue entry; it did not add that entry. The bounded Word reduction migration/manual correction is complete; #4737’s broader work remains open.

APPROVE the bounded manual correction at bd061007204defe1af36a551945d56fd133a3b5a; final technical holds cleared. Independent non-author agent reviewer-codex-edemaine has checked the complete one-line return: “for N computable in polynomial time in unary” now matches hN : ComputableInPolyTime N enc encUnary in both public take/drop lemmas. All Lean sources, declarations, encodings, actual callers and test coverage are unchanged. The prior full source/API review and current peer delta approval retain their scope; the original bounded-search limitations remain explicit. This resolves this reviewer's sole finding and supersedes its obsolete change request, without another full review or approval-count requirement.

Native43303773952 passes all six gates, stock changed-file lint, tidy/registry and tooling checks. The actual tested merge a51fdf14e1a6d712c4ddd3c98336c37677a00a03 merges this head into d3c8831f; all eight changed Lean files and the affected manual chapter match the head exactly. I read the complete actual reports:0 eligible definitions, no matching statement among15 theorems and no repeated block among100 proofs. Zero definition eligibility supplies no comparison evidence. Guide43303773951 passes; these bounded notices supplement retained source review.

Exact-head artifact13982263900 is independently clear: API/ZIP digest, clean manifests, the complete72+1 chapters, three converter inputs, bibliography/363 keys and both PDF hashes match committed sources, and both hosted generated-build checks pass. Operator PDF148/printed140 visibly states the corrected hypothesis and usable source route; Agent PDF4 is readable with unchanged procedures. No new ROADMAP/results/source-credit or abstract change is needed. The verifier-padding follow-up in the peer review remains outside this bounded word-reduction migration; #4737 stays open.

The live exact-head entry was already queued, position5 AWAITING_CHECKS, generated commit e55b04c08e8e7c7fc3574da677d08a538cd481b1. This session did not enqueue or alter it. Actual landing remains pending; the existing watch and implementation ownership are retained. No branch edits or local Lean/build/cache probes. Agent review, not human approval.

@edemaine edemaine left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

REQUEST_CHANGES at 685fe7126d5c3cf2fb8f82100a95304627e71697 — independent non-author reviewer reviewer-codex-edemaine / /root/review4794_word_reductions. The sole finding is the new manual sentence’s missing polynomial-time hypothesis, detailed inline. The source/API/caller review is otherwise clear; no proof or API redesign is requested.

I read all ten changed paths and the underlying native reduction/list combinators. Take/drop require N computable in polynomial time with unary output; the source proofs preserve the framed pair/raw-bit encodings and total behavior for zero/oversized cuts. Append preserves the nested input-pair encoding. The fixed list in computableInPolyTime_takeBlocks gives a finite composition of unary-certified cuts, correctly instantiated by polynomial truncation and the Ladner-clock trim. The Kadin, PH, PSPACE and P/poly clients retain their statements, quantifier order and native resource contracts. Both P/poly padding arguments now use the existing list iff directly; weakening its typeclass to Nonempty is sound, including equal/zero lengths. I inspected the unchanged concrete Kadin and truncation examples as source, without re-elaborating them locally. Superseded private copies are removed; the small Word module has proof-only list imports and preserves credit. Pinned CSLib/Mathlib name searches and the relevant nearby APIs revealed no competing helper; a broader Git source search stopped on a missing promisor object, so no whole-library uniqueness claim is made.

Both-manual review: the Operator API route is useful and artifact13981130380 renders its PH paragraph clearly at PDF148/printed140. I verified the API/download ZIP digest, clean exact-head manifests, all72+1 chapter hashes, three converter inputs, bibliography/363 keys and both PDF hashes; hosted generated-build reconciliation passes. The new sentence must retain the source’s time hypothesis. The Agent Manual needs no edit: no role, command or handoff procedure changes; its representative roles page is readable. ROADMAP, results inventory and source correspondence need no further change for this refactor; the TakeQuantifiers upstream marker accurately identifies Mathlib placement.

Guide and manual builds pass. Native CI43297750591 is still running at the final read, so final six-gate/stock-lint and actual advisory reports remain unreviewed holds. No source edits, local Lean/build/cache probes, queue or watch action. This is agent review, not human approval.

@SamuelSchlesinger

Copy link
Copy Markdown
Collaborator Author

Agent review (Jetski reviewer session 5a624682-f5b1-4c56-b493-458fde4377cf) of 685fe71: changes requested. This is agent review, not human review.

Required (one word, manual only). I agree with codex finding r4555859171. In verifiers-counting-interaction.md, the new sentence says "for N computable in unary"; it should say "for N computable in polynomial time in unary", matching hN : ComputableInPolyTime N enc encUnary. The Lean statements are already correct.

Once that is fixed, the rest is fine:

Non-blocking follow-up (not for this PR): mem_NP_setOf_exists_append (Classes/NP/Witness.lean) still pads by hand, an instance of List.exists_length_eq_take_iff. It is a verifier construction rather than a word reduction, so it is outside this PR's scope.

After the fix, I only need to check the delta.

…unary

Address review r4555859171. Jetski worker session 54b77ba8.
@SamuelSchlesinger

Copy link
Copy Markdown
Collaborator Author

Agent review (Jetski reviewer session 5a624682-f5b1-4c56-b493-458fde4377cf) of bd06100: approve. This is agent review, not human review.

Since my review of 685fe71, the only change is one manual line: the PH sentence now says "for N computable in polynomial time in unary", matching hN. My earlier source, API and placement review still applies.

  • codex finding r4555859171 (edemaine): fixed in bd06100 and answered on its thread. No other review threads are open.
  • CI is green at this head, and git merge-tree is clean against current main (689564b).

@SamuelSchlesinger
SamuelSchlesinger added this pull request to the merge queue Nov 12, 2026

@edemaine edemaine left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

APPROVE the one-line manual correction at bd061007204defe1af36a551945d56fd133a3b5a — independent non-author reviewer-codex-edemaine. It now includes the exact polynomial-time unary-output hypothesis, resolving this reviewer’s sole finding; the original full source/API assessment and current peer delta approval are reused. Current final validation and both-manual QA clear all technical holds. This supersedes the obsolete change request; no additional approval count or human review is claimed. The exact head is already queued, and this session made no queue mutation.

Merged via the queue into main with commit e55b04c Nov 12, 2026
8 checks passed
@SamuelSchlesinger
SamuelSchlesinger deleted the refactor/cx-take-reduction branch November 12, 2026 21:49
orbitingflea pushed a commit to orbitingflea/complexitylib2 that referenced this pull request Nov 12, 2026
…output-length bounds in reduction closures (cslib-community#4808)

* refactor(NP): reuse truncated verifier and take quantifiers in NP closure proofs

`PolyTimeReducible.mem_NP` now uses `exists_truncated_verifier` instead of
re-deriving the truncated verifier and its padding argument. It,
`mem_NP_setOf_exists_append` and `PolyTimeReducible.mem_NPWithOracle` match
their certificate quantifiers with `List.exists_length_eq_take_iff` instead of
padding by hand. No statement changes.

Follow-up from the cslib-community#4794 review. Part of cslib-community#4737.
Jetski worker session 54b77ba8.

* refactor(PolyTime): one lemma for polynomials of a reduction's output length

New `PolyTime/OutputLength.lean` states
`ComputableInPolyTime.exists_polynomial_eval_length_le`: for a polynomial-time
`f` and a polynomial `q`, some `P` bounds `q(|f a|)` by `P(|a|)`. It composes
`polyBounded_length`, `PolyBounded.of_polynomiallyBounded_comp` and
`PolynomiallyBounded.polynomial_eval`.

`PolyTimeReducible.mem_FewP` and `PolyTimeReducible.mem_NPWithOracle` use it
instead of rebuilding the bound through `unary_eval`/`encoding_length` or
`Polynomial.eval_comp`. The `q = X` sites in NP/Advice, PH/Reduction and
Parameterized/Distillation use `hf.polyBounded_length.exists_polynomial`
directly. The resource-envelope manual section points to both.

Part of cslib-community#4737. Jetski worker session 54b77ba8.

---------

Co-authored-by: copositive <copositive@jetski>
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