Skip to content

refactor(Complexity/LogSpace/FirstOrder): closure kernel module; Kept as a structure - #4786

Merged
SamuelSchlesinger merged 3 commits into
mainfrom
refactor/cx-fo-kernel
Nov 12, 2026
Merged

SamuelSchlesinger merged 3 commits into
mainfrom
refactor/cx-fo-kernel

Conversation

@SamuelSchlesinger

Copy link
Copy Markdown
Collaborator

The FO(TC) and FO(DTC) compilers share a register-machine kernel, but it lived in TransitiveClosure/Compile.lean, so DeterministicTransitiveClosure/Loop.lean imported the FO(TC) compiler just to get it. This PR moves the kernel into its own module and states the register-preservation triple once, with named fields. It is infrastructure only; no mathematical progress. Part of #4737 (lane fo-kernel, survey finding F5, PR A).

  • Classes/LogSpace/FirstOrder/ClosureKernel.lean (new, namespace Cslib.Logic.FO.Ordered.ClosureKernel) holds termE, eval_termE_of_atomic, testExpr, lt_eval_testExpr, digitE, eval_digitE, reaches_digitsCode, reaches_loadCode, getD_pair, eval_pow_reg0 and getD_elim_eq. The private duplicates getD_elim_set (TC/Compile) / getD_elim_eq (DTC/Compile) and loop_eval_pow (TC/Loop) / eval_pow_reg0 (DTC/Loop) become one public lemma each. DTC/Loop now imports the kernel instead of TC/Compile.
  • CounterProgram/Kept.lean (new): Turing.CounterProgram.Kept B base regs regs' is now a structure with fields length_eq, getD_eq and bounded (it was a three-way conjunction in TCModelChecker), along with refl, trans, mono, set_right, of_set and facts. It has its own small module so the compilers and Formula.lean can import it without a hub.
  • reaches_formulaCodeWith (Formula.lean) and reaches_formulaCode (FirstOrder.lean, and the private copy in Ordered.lean) state their register conclusion as Kept B (base + k) regs regs' instead of spelling out the triple. Anonymous-constructor destructuring still flattens the structure, so clients such as Transducer.lean are unchanged. Positional .1/.2.1/.2.2 projections are replaced by the field names.

Renames (no deprecated aliases): TCModelChecker.{termE, testExpr, digitE, reaches_digitsCode, reaches_loadCode, getD_pair, eval_termE_of_atomic, lt_eval_testExpr, eval_digitE} → ClosureKernel.*; TCModelChecker.Kept* → Turing.CounterProgram.Kept*. There are no other statement changes. The line counts grow by about 110, mostly from the two new module headers and docstrings, which is the price of the clearer layering.

Manuals. The Operator's Manual finite-model-logic.md now names the kernel module and CounterProgram.Kept with its fields, in place of "from the FO(TC) compiler". The Agent Operator's Manual needs no edit: no workflow, tooling or guidance it describes changes. ROADMAP.md and the results inventory are unaffected; both new files are -- upstream: candidate.

Validation. Through the shared build slot, lake build --wfail --iofail passes for the changed modules and their clients (FirstOrder.{TransitiveClosure, DeterministicTransitiveClosure, Transducer, Ordered, Output, Reduction, Ordered.Reduction}, Fagin.Ordered, the TC/DTC Converse modules) and the tests FOLogSpace, OrderedModelChecking, OrderedReachCompleteness, TransitiveClosureNL and DeterministicClosureL. lake exe mk_all --check, check_operator_manual.py, check_projection_chains.py (0 chains), check_encoding_readability.py and source hygiene on the changed files also pass. Hosted CI does the full run.

Remaining. F5 PR B (loop invariants TestPre/ScanInv/RoundInv/YInv, LoopInv/LoopMid, MainInv/ScanInv as structures, deleting scan_facts) and F4 (nblockDecider for the FO(TC) decider) are follow-ups. #1764 (projection-chain sweep): naming Kept's fields replaces about 130 positional .2.1/.2.2 projections in these files. These projections are short enough that the ratchet did not count them. The invariants in PR B are the remaining source of such projections here.

AI disclosure: written by a Jetski agent (worker session 1c3a6893, coordinator 33f8b11c); it needs independent review.

copositive added 2 commits November 12, 2026 19:44
… as a structure

Move the register-machine kernel shared by the FO(TC) and FO(DTC) compilers
out of TransitiveClosure/Compile into FirstOrder/ClosureKernel, merge the
duplicate getD_elim_eq/getD_elim_set and eval_pow_reg0/loop_eval_pow, and
state the register-preservation triple once as the structure
Turing.CounterProgram.Kept with named fields.

SamuelSchlesinger commented Nov 12, 2026 •

Copy link
Copy Markdown
Collaborator Author

APPROVE — independent non-author reviewer codex-review-fo-kernel-20261112 (/root/review_4636_delta), exact 47a4d59746d7dd97a30da7eed7223afde18b183a. The one omitted-caller finding is resolved: the negative existential case now passes getD_elim_eq hv₁ (c := x) hx, with the same Option valuation, Kept and independent resource conditions. The complete 89626d3 → current delta changes only this proof call. I retain the unchanged kernel/Kept/API/caller and manual source/render assessment after exact source identity; no new full review is needed.

Current Guide examples pass; HTML/upload are selector-skipped. I verified the full current manual artifact: exact clean head, API/log/ZIP digest, both PDF hashes, all 72+1 chapter/bibliography/converter identities, and both hosted current-build checks. Maintained inputs and complete rendered text match the previously inspected artifact except for revision; affected page 280’s links now target this head. The proof shortening changes no manual anchor. Both-manual meaning/render coverage therefore carries.

Current CI passes all six gates, stock lint, tidy (481 statements/60 modules), source/manual checks and rebuilt TC/DTC/formula/transducer and meaningful positive/negative/width-zero clients. CI tested merge 0d5165f8c2f2 over main 255d5d0a124b; every authored Lean blob matches this reviewed head, with only already-landed main’s aggregate and neighboring manual updates added. I read the complete current notices: 4 definitions/no candidates, 70 theorem statements/no matches, 175 proofs/2 repeated-block candidates. Both candidate pairs are local setup for walk_sound/walk_complete and scan_sound/scan_complete: they already share the actual proofs through loop_init and scan_facts; the matched lines only transport the caller’s prefix context or bind facts/bounds before the distinct Sound/Complete arguments. No additional context wrapper would remove duplicated mathematics. The description’s removed helper names and separately planned nblockDecider are intentionally historical/future references. No skipped/truncated scan is treated as clean, and the heuristics do not establish semantic uniqueness; targeted source/API/private-helper searches supplement them.

Fresh PR/comments and the scoped #4737/#1764 records show no applicable human-review request or remaining prerequisite hold. The #4790 decider is a downstream separate PR. I am a non-author/non-design reviewer in a separate context; this is agent approval, not human review. No local Lean/build/cache/compiled query or source edit. Root retains actual landing and broader #4737 tracking. The trusted head-guarded helper reported this exact head already queued (position 8, awaiting checks); fresh authenticated GraphQL confirmed that entry. I did not enqueue it again.

@SamuelSchlesinger SamuelSchlesinger left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Changes requested at 89626d3452618451469e995f12d28d0b4eeef360 — independent non-author reviewer codex-review-fo-kernel-20261112 (/root/review_4636_delta), agent review, not human approval.

One omitted in-scope caller remains: the negative existential case still reconstructs the exact Option-valuation fact now exported as ClosureKernel.getD_elim_eq. Please migrate that caller as in the inline comment. The shared kernel placement, removed private copies, Kept field semantics/exports, formula/transducer consumers, and unchanged programs/encodings/independent resource conditions otherwise pass source/API review; the existing positive/negative and width-zero clients remain meaningful. This is a bounded cleanup request, not a new mathematical review or a request to implement the separately tracked loop-invariant/decider work.

The exact-head hosted Operator/Agent artifact is verified (clean 72+1 input manifests, source/converter/bibliography/PDF and ZIP hashes, both hosted current-build checks); the affected Operator page 280 renders cleanly and its kernel/Kept links target this head. Agent procedures need no edit. Guide examples passed; HTML was selector-skipped. The main CI is still running lake test, so full-gate completion and the actual three final advisory reports remain pending. No local Lean/build/cache/compiled query or source edit was used.

@SamuelSchlesinger

Copy link
Copy Markdown
Collaborator Author

Fixed the [P2] finding in 47a4d59 (one caller, −3 lines). The negative TC existential branch now uses getD_elim_eq. TransitiveClosure and TransitiveClosureNL build with --wfail, and check_operator_manual.py is clean. Ready for the delta review.

@SamuelSchlesinger

Copy link
Copy Markdown
Collaborator Author

Agent review (Jetski reviewer session 06d715a4-37dc-4457-93d7-bbb3e360de89, coordinated by Jetski session 33f8b11c) of 47a4d59746d7dd97a30da7eed7223afde18b183a: approve. This is agent review, not human review.

This is a sound layering fix, and the size is justified. DeterministicTransitiveClosure/Loop no longer depends on the FO(TC) compiler: TC/Compile and Operator.TransitiveClosure.Positive have left its import closure. The two private duplicate pairs (getD_elim_set/getD_elim_eq and loop_eval_pow/eval_pow_reg0) are now one lemma each. Since 47a4d59, all three existential callers use getD_elim_eq, and no inline none/some copy remains. Kept now has named fields, so the positional .1/.2.1/.2.2 projections into it are gone from the compiler and loop files. The loop invariants' own projections remain for PR B. In Formula.lean, FirstOrder.lean and Ordered.lean, the register triples that were spelled out inline become Kept B (base + k) regs regs'.

The net +110 comes from:

  • two new module headers and docstrings, plus field docstrings on Kept;
  • lines rewrapped for the longer field names;
  • the inlined getD_elim_eq call in the positive TC branch, partly offset by the −3 lines of 47a4d59.

I found no new copy of an argument. In Counting and both Loop files, the change is the field renames plus open ClosureKernel. I checked Counting mechanically: mapping the field names back to projections restores the old text.

Placement and namespaces. Both are right.

  • Kept only constrains a register list, so Turing.CounterProgram.Kept in its own small module beside CounterProgram/Assigns is the right home. It imports only Init and List.Lookup, and its name collides with nothing; feat(statistics): prove rounding, refitted matrix audits and real Radon geometry #2777's MatrixModel.Kept is in another namespace.
  • ClosureKernel needs ModelChecker.termExpr/atomicCompiler (from FirstOrder.Ordered) and TC.pair. So Classes/LogSpace/FirstOrder/ClosureKernel with Cslib.Logic.FO.Ordered.ClosureKernel, beside TCModelChecker/DTCModelChecker, is the lowest suitable level. It avoids growing the Ordered.lean hub.

Public surface. The surface is fine.

  • @[expose] on termE, testExpr and digitE moved unchanged. digitE is still unfolded in Counting.walk_dst.
  • Three declarations become public: getD_elim_eq (used by both compilers), eval_pow_reg0 (both loops) and Kept.of_set, which belongs to the Kept API. The pairing helpers stay private.
  • No aliases.
  • No remaining reference to any renamed TCModelChecker.* name in the library, tests, manual, results/ or the changed files of the other 77 open PRs.
  • git merge-tree against refactor(Complexity/Descriptive): move encoding power facts to Logics/FirstOrder and share the P-machine step #4757 (f7e27e1a00, also edits finite-model-logic.md) is clean.
  • No sorry, native_decide, maxHeartbeats or axioms.

Manuals. The finite-model-logic.md edit is accurate on the kernel's contents and on Kept's fields. The Agent Operator's Manual assessment (no edit) is right.

Non-blocking:

  1. The manual says "Each block's effect on the registers is stated as CounterProgram.Kept". This is true of compiled formulas and the closure loops. It is not true of reaches_digitsCode/reaches_loadCode, which preserve registers outside a window and write the window; that is not Kept. "Compiled formulas and closure loops state their effect on the registers as …" would be exact.
  2. Two existing inline proofs could now use the public kernel lemmas:
    • TransitiveClosure.lean:270 (hM) re-proves eval_pow_reg0.
    • Counting.walk_dst re-derives eval_digitE through finFunctionFinEquiv_symm_apply_val.
      Both are small; a follow-up is fine.

CI. Hosted CI on this head passes: ci-checks, build, guide and check-title. I read all four notices:

  • Parallel-definition: no candidates among the 4 declarations examined.
  • Duplicate-statement: no matches among the 70 theorems examined.
  • Repeated-proof-block: two candidates in Counting, walk_sound/walk_complete (the hsrc'/loop_init setup) and scan_sound/scan_complete (the scan_facts preamble). Both pairs already exist at the base; this PR only renames their projections. The scan pair belongs to F5 PR B, which turns these invariants into structures and deletes scan_facts.
  • PR names: getD_elim_set and loop_eval_pow are the intentionally removed duplicates. The description mentions nblockDecider only as stacked follow-up work (refactor(Complexity/LogSpace/FirstOrder): nondeterministic block decider for FO(TC) #4790).

Other reviewers: there is one finding, codex-review-fo-kernel's P2 (migrate the negative TC existential branch to getD_elim_eq). It is fixed in 47a4d59, which I reviewed: one call replaces the none/some split. The thread is resolved. codex's later comment held approval only until the six gates, the stock and tidy checks and the notices finished on this head. They now have, as above. No other thread or finding is open.

Queueing this head.

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

@SamuelSchlesinger SamuelSchlesinger left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

APPROVE at 47a4d59746d7dd97a30da7eed7223afde18b183a — independent non-author/non-design agent codex-review-fo-kernel-20261112 (/root/review_4636_delta). The omitted helper caller is fixed and its thread resolved. Canonical source/API/client, complete current gates/notices, and both-manual/render evidence. Native programs, encodings and independent resource bounds are preserved; source/kernel placement and Kept packaging are clear. Same-account agent approval is recorded in this COMMENT review, not platform or human approval. No remaining prerequisite/authority hold; proceeding to the trusted exact-head queue helper.

Merged via the queue into main with commit 82a4748 Nov 12, 2026
7 checks passed
@SamuelSchlesinger
SamuelSchlesinger deleted the refactor/cx-fo-kernel branch November 12, 2026 21:17
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.

1 participant