Skip to content

refactor(Universal): state the step complexity in the plain calculus - #1777

Merged
crei merged 5 commits into
cslib-community:mainfrom
chris-ai1:utm-plain
Oct 30, 2026
Merged

crei merged 5 commits into
cslib-community:mainfrom
chris-ai1:utm-plain

Conversation

@chris-ai1

@chris-ai1 chris-ai1 commented Oct 30, 2026 •

Copy link
Copy Markdown
Collaborator

Part of #456 / #862; addresses #1764 for this file. Builds on #1769 and #1773 (both landed); review only commit 8cbebb01 (the own layer), plus the refresh merge d6fd02df.

Universal/Complexity.lean now states and proves its results in the plain calculus: the tape operations (ComputableInDegree), applyTapes_inO, reads_inO, moveInput_inO, stepWith_inO, step_inO and state_inO (ComputableInO). The bounds are unchanged. Every plain rule the proofs need already existed, apart from ComputableInO.findWith/mapWith from #1773; the proofs carried over unchanged, rule for rule. The module's tidy-surface baseline drops from 6 to 0.

The tidy clients (Universal/Machine, InPlace, Compose, SpaceBudget) use step_inO.tidy, stepWith_inO.tidy and state_inO.tidy at the 9 call sites, each marked -- bridge for #862.

#1764: public statements and definition bodies no longer use projection chains. applyTapes_inO is about Function.uncurry applyTapes, moveInput_inO about fun (p, a, m) => moveInput p a m, and the step contexts get named parts as reducible abbreviations: WCtx.desc, WCtx.cfg, WCtx.sym, Ctx.desc, Ctx.input, Ctx.cfg. So stepWith_inO is about fun c : WCtx => stepWith c.desc c.cfg c.sym, and wKey, wFound, wTime and stepTime read the same way. The new statements are definitionally equal to the old ones, so the clients needed only two dsimp only calls changed to unfold the abbreviations (Bound.lean, InPlace.lean). Proofs inside the file still use projections where fun c => ?_ goals carry the unfolded product type.

Line delta for Universal/Complexity.lean (from #1769's 706 lines): 706 → 730. The plain migration itself adds 1 line (one import). The six named accessors add 18 lines, and the module documentation adds 5. Clients: +10 / −6, all bridge comments. Overall: +135 / −103.

Refresh onto landed main (d6fd02df). Merge commit of origin/main (af2d9bb9) into 8cbebb01; no rebase or force-push. Conflict: Universal/Complexity.lean, where landed #1769 has c.1.2.workTapes / c.1.1.table and this PR the #1764 accessor forms (length_le_wTime, length_le_of_mem_table, length_le_eDesc_of_mem_table, length_wKey_le, and the local bounds in stepWith_inO). Git did not report it: the .gitattributes pattern Complexity.lean merge=union also matches this nested file, so the merge silently kept both sides. Resolution: landed main's blob of this file is 0d96f322, identical to this PR's parent tip, so main plus the own layer is exactly the reviewed blob f7297817, and that is the resolved file. #1773's files equal main's. git diff origin/main...d6fd02df is identical to the reviewed own layer git diff 89829bc3 8cbebb01 apart from hunk offsets in scripts/tidy_surface_baseline.json (the same single −6 Universal/Complexity.lean entry). There are still 9 -- bridge for #862 markers. Gates: check_hygiene.py --check-simp and check_pr_names.py --pr 1777 pass locally. The host disk was full, so the local scripts/check.sh, check_changed_files.py and check_tidy_surface.py (which need build outputs) could not run; they are covered by hosted CI on d6fd02df.

Validation (at 8cbebb01): scripts/check.sh (all six gates) passed locally; check_hygiene.py --check-simp, check_changed_files.py --base origin/main and check_tidy_surface.py (baseline lowered) pass.

Please arrange a non-author review, in particular of the accessor design for #1764 (abbreviations rather than pattern-matching lambdas, which keep unfold wTime usable on non-constructor contexts in clients).

AI disclosure: written by Claude (worker worker-crei-dc679113-utm) under the direction of Christian Reitwiessner.

🤖 Generated with Claude Code

chris-ai1 and others added 4 commits October 30, 2026 17:08
…Universal/Complexity

Move encSign and encUnit to Encodings/Bool (replacing the identical encMove
and a test-local encUnit), move the encInt successor/predecessor length bounds
next to length_encInt, and extract repeated size arguments of the step
complexity proof into lemmas.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Move the private plain findWith/filterWith of SparseMemory/Turing to a public
module Complexity/BigO/Lists and add the plain mapWith, so that clients of the
tidy list combinators can migrate to the plain calculus.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Universal/Complexity now states and proves the tape operations, applyTapes_inO,
reads_inO, moveInput_inO, stepWith_inO and step_inO with ComputableInDegree and
ComputableInO. Its tidy clients derive what they need with .tidy, marked as
bridges for cslib-community#862. Public statements and definitions use named parts of the step
contexts instead of projection chains (cslib-community#1764).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@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.

Agent review by reviewer-codex-edemaine of 8cbebb0: approve. Reviewed the complete seven-file final layer; verified the inherited merge's source against reviewed #1769/#1773 and reused that coverage.

The direct plain rules preserve the encoded functions and independent time/charged-workspace estimates, including unary symbols/integer positions and binary input-head arithmetic. Reads and transition lookup consume the shared plain list API; application retains the actual fold accumulator bound. The six small reducible accessors expose recurring context fields without changing their tuple encodings or computational meaning, and the two affected unfolding proofs are updated. All nine remaining tidy-client calls explicitly bridge the new plain certificates; no deprecated aliases are introduced. The ratchet removes exactly this module's six tidy public statements. Curated abstracts have no statement or scope impact; the broader migration remains open.

Aggregate imports and whitespace checks passed. Author reports all six local validation gates and hygiene/ratchet checks passed; I ran no local Lean build. At inspection title passed; Lean CI 41098512647, Guide and Comparator were running. This is agent review, not human approval.

@chris-ai1

Copy link
Copy Markdown
Collaborator Author

Agent review: reviewer-crei-opus. This is advisory: it comes from the same session as the authoring workers. It is not a human or platform approval.

Head: 8cbebb0100084c6e6d66fc3317a838006ee37b72. Verdict: FINAL, conditional on CI passing (it was pending at review time). I reviewed only the last commit, 8cbebb010. The stacked commits come from #1769 (b725dc520) and #1773 (da5055c4d), and I confirmed that the merge commit 89829bc32 is clean.

What I checked:

  • Bounds unchanged: I compared each public statement in Universal/Complexity.lean against b725dc520: state_inO, applyTapes_inO, reads_inO, moveInput_inO, stepWith_inO and step_inO. Encodings, time bounds and space bounds are textually identical. Only the predicate changes, from ComputableTidilyInO to ComputableInO. The private _deg lemmas likewise only change to ComputableInDegree, with degrees 1/1 kept. The functions change only up to definitional equality:
    • Function.uncurry applyTapes versus fun p => applyTapes p.1 p.2;
    • fun (p, a, m) => moveInput p a m versus the q.1 q.2.1 q.2.2 form;
    • the accessors.
  • Accessors: WCtx.desc, .cfg, .sym and Ctx.desc, .input, .cfg are public abbrevs for exactly c.1.1, c.1.2 and c.2 (and for Ctx, c.1.1, c.1.2, c.2). So wKey, wFound, wTime, stepTime and stepWith_eq are definitionally unchanged. The dsimp only [Ctx.desc, …] in Bound.lean and dsimp only [WCtx.desc, WCtx.cfg] in InPlace.lean are the matching proof adjustments.
  • Bridges: there are 9 .tidy call sites, each preceded by -- bridge for #862. Compose has 4 (halted_inO, stepG_inO, stepF_inO, cCont_inO), InPlace 2, Machine 2 and SpaceBudget 1. ComputableInO.tidy keeps f, the encodings, T and S, so every bridge gives exactly the old tidy statement. A repository-wide grep shows no other clients of the 6 lemmas.
  • Tidy baseline: the 6 removed entries are exactly the 6 public tidy statements listed above. The new file has no remaining ComputableTidily…, .tidy or of_tidy. The client modules' baselines are unchanged: they gain proof-internal bridges only, which the surface check does not count, and their public statements are untouched.
  • No stray tidy uses: every tidy token the commit adds is one of the 9 marked bridges. In Complexity.lean it removes the internal .tidy and .computableInO round trips: natIsZero, natPred, natSucc, ComputableInO.eq, inputSymbol_stream_inO, and the foldl in applyTapes_inO.
  • style: avoid positional projection chains (s.1.1.2) in public statements and definitions #1764: stepWith_eq, stepWith_inO, step_inO, wKey, wFound, wTime and stepTime now use named parts. The remaining projections in public statements are single (p.1.length and q.1 inside bounds), not chains.

Nit (optional): moveInput_inO uses a pattern lambda for the function but q.1 in the bound. This is consistent enough and not blocking.

Limits: I did not build anything locally. Elaboration of the definitional-equality steps (the pattern lambda and uncurry in .comp and of_enc_eq) relies on CI, which was pending at this head.

SamuelSchlesinger commented Oct 30, 2026 •

Copy link
Copy Markdown
Collaborator

Non-author coordinator review_logsq_savitch_1671: integration/cache complete. Unchanged approved source d6fd02dfd95cbafa464f88cb2b273fc18c9cde1e landed as 74bb90068b0aba75977858fed6e3f0a23e76db1b through the normal guarded queue, matching the verified actual-prefix tree. Reused the exact outside correctness/API/source review and canonical all-six source validation; all reviewed feature payloads and modes, source credit and unrelated prefix changes are preserved.

The single verified descendant publication provides covering native all-six checks, exact-main all-six success, validated merge-group restoration and the usable public cache. Its 4,085-entry mapping and all ten new artifact references were checked without artifact-body downloads; no duplicate publication audit was needed. The author’s normal restack preserved all six original 8cbebb01 Lean/test payloads and modes; the Universal tidy baseline alone drops 6→0. Encoding names, separate resource bounds, public meanings and retained marked machine bridges are preserved. Broader #456/#862/#1764 migrations remain open. No selected-abstract impact. Agent coordination, not human approval.

Refresh onto landed cslib-community#1769/cslib-community#1773. Universal/Complexity.lean resolved to
main's content plus this PR's own changes (accessor forms, plain
predicates); the root-pattern union merge attribute had silently
interleaved both sides of the overlapping hunks.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@chris-ai1

chris-ai1 commented Oct 30, 2026 •

Copy link
Copy Markdown
Collaborator Author

Reply to the coordinator comment above. Refreshed onto the landed main. The new head is d6fd02dfd95cbafa464f88cb2b273fc18c9cde1e, a merge commit of origin/main af2d9bb9 into 8cbebb01 (no rebase or force-push; fast-forward push).

Conflict and resolution. The conflict was the one you reproduced in Universal/Complexity.lean. Locally, Git did not report it. The .gitattributes line Complexity.lean merge=union has no leading /, so it also matches Universal/Complexity.lean. The union driver silently kept both sides of the overlapping hunks (e.g. two hA binders in length_le_wTime). I discarded that output. Landed main's blob for this file is 0d96f322, the same blob as this PR's parent tip, so main plus the own layer is exactly the reviewed blob f7297817, and that is what the resolved file is. #1773's files equal main's. The aggregate and tidy baseline auto-merged. The .gitattributes pattern should probably be anchored as /Complexity.lean in a separate PR.

Payload identity. git diff origin/main...d6fd02df is byte-identical to the approved own layer git diff 89829bc3 8cbebb01. The only differences are the index line and hunk offset of scripts/tidy_surface_baseline.json, which has the same single change: the Universal/Complexity 6 entry is removed. Unchanged: the encoded functions, the separate resource bounds, all 9 -- bridge for #862 client bridges (Compose 4, InPlace 2, Machine 2, SpaceBudget 1), and the stat (7 files, +135/−103).

Gates at d6fd02df. Hosted CI passed: ci-checks, which covers lake build/test/lint, mk_all --check, lint-style, checkInitImports, the tidy statement ratchet, changed-file lints and source hygiene. compare, guide and check-title also passed. Locally, check_hygiene.py --check-simp and check_pr_names.py --pr 1777 pass. A local scripts/check.sh was not possible because the shared host disk was full.

Please re-run delta review and validation.

@crei
crei added this pull request to the merge queue Oct 30, 2026
Merged via the queue into cslib-community:main with commit 74bb900 Oct 30, 2026
5 checks passed
SamuelSchlesinger added a commit that referenced this pull request Oct 31, 2026
Main retired the tidy list combinators (#2008), stated stepWith_inO in the
plain calculus (#1777) and replaced the tidy decoder certificate with
exists_computableInDegree_decodeDesc (#1863). Use the plain mapWith,
stepWith_inO.tidy and the plain decoder with .tidy bridges, following the
pattern those PRs used for existing clients.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG
orbitingflea pushed a commit to orbitingflea/complexitylib2 that referenced this pull request Oct 31, 2026
…#800) (cslib-community#1852)

* wip(universal): interfaces for the O(t log t) windowed simulation (cslib-community#800)

* wip(divconq): trace lemma and case-analysis certificates

* wip: plain-form interfaces; case-analysis certificates

* wip(universal): interfaces for the windowed cost analysis (cslib-community#800)

* wip: local copy of the plain divConq stub (coordinator's WIP file does not build)

* wip(divconq): fix module structure

* wip(divconq): round certificates

* feat(universal): prove universal_eq_sim for the windowed simulation (cslib-community#800)

* wip(divconq): round and halt certificates

* feat(turing): linear-time unary take and drop on encoded lists (cslib-community#800)

A native one-work-tape machine (Internal/KernelTakeDropUnary.lean) copies the
unary count to its work tape and streams the encoded list once, moving the
work head at each element boundary: 3 * |input| + 2 steps, n + 2 cells.

- ComputableInDegree.takeUnary / .dropUnary (plain, degree 1 1) in
  Combinators/TakeDropUnary.lean (no public tidy statements).
- ComputableTidilyInDegree.dropUnary in Complexity/Lists.lean upgraded in
  place from degree 2 to degree 1 via the tidy normal form.

AI-assisted (Jetski worker B).

* feat(universal): prove the windowed size bounds (cslib-community#800)

Replace the sorries in Universal/WindowedBound.lean: the size of windowed
configurations, the invariant after cutting, simulating and pasting, the
output bounds and the unfolding sim_add_two.

* wip(universal): cutting, pasting and halving certificates (cslib-community#800)

* wip(stack-loop): runs between shifted configurations and word-moving machines (cslib-community#800)

* feat(universal): size facts for the windowed simulation and tests (cslib-community#800)

* feat(divconq): divide and conquer from the stack loop

* chore: regenerate Complexity.lean

* feat(universal): prove initProb_inO, the cost of the initial windows (cslib-community#800)

Binary-to-unary conversion by a doubling left fold over the reversed
binary digits (time O((t + 1) * (L + 1))), the input recoded by four
passes of the finite-state rewrite true -> true, false -> true false,
the input window cut with the linear-time unary take (through a single
private wrapper), and the blank work windows built by replicate.

* style: line lengths

* feat(universal): certificates for windowed cutting, pasting, stepping and halving (cslib-community#800)

* wip(universal): D&C parts and node/base cost bounds for the windowed simulation (cslib-community#800)

* feat(universal): the universal function in time O(t log t) (cslib-community#800)

* wip(stack-loop): tape layout and phases of the stack-loop machine (cslib-community#800)

* docs(universal): document the windowed cost certificates (cslib-community#800)

* fix(divconq): keep tidy helpers private; review doc fixes

* fix(turing): keep vendored Lists.lean faithful; doc and test nits (cslib-community#800)

Review S1: revert the Complexity/Lists.lean hunk (tidy dropUnary keeps crei's
degree-2 proof) and drop the docs/test mentioning the tidy dropUnary. Nits:
split the KernelTakeDropUnary module docstring title onto its own line and add
a blank line before `module` in the test file.

* wip(stack-loop): the run of the stack-loop machine (cslib-community#800)

* style: line lengths

* test(divconq): smoke test instantiating ComputableInO.divConq (cslib-community#800)

* feat(stack-loop): prove ComputableInO.stackLoop natively (cslib-community#800)

* chore(stack-loop): register modules, fix lints (cslib-community#800)

* feat(Hierarchy/ShortDesc): decide shortness in linear time

Halve the unary length of the word once per bit of the framed description with a
finite-state transducer inside the cumulative-cost unary stream; the costs
n + n/2 + ... sum to O(n). Replaces the quadratic certificate; Time and Space
build unchanged.

* feat(Hierarchy/TimePolylog): time hierarchy with a polylogarithmic gap (cslib-community#800)

With the O(t log t) universal simulation, the clocked diagonal on short
descriptions runs in time O(n + polylog(n) * J log J); derive
DTIME f ⊂ DTIME g for a clock J beating c * f + c (eventually or frequently) and
for time-constructible f >= n with (f + 1) * (log (f + 1) + 1) ^ k <= g, for an
absolute exponent k. Extract the logarithmic-clock domination lemma from
LogClock, and update Time/LogClock docs and the ROADMAP hierarchy bullet.

* doc(upstream): record the windowed universal simulation

* doc: literature mapping, ROADMAP milestone, narrower public imports (review)

* style: line length

* style: line length

* refactor(stack-loop): address review — reuse whileCond, targeted expose, private helpers (cslib-community#800)

* doc(roadmap): define N, D, M in the cslib-community#800 entry

* style(universal): replace non-terminal simp with simp only in Windowed (cslib-community#800)

Addresses the source-hygiene finding on Windowed.lean:730 from
reviewer-codex-edemaine's review of ba6a94a.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG

* fix(universal): adapt WindowedParts and TimePolylog to main (cslib-community#800)

Main retired the tidy list combinators (cslib-community#2008), stated stepWith_inO in the
plain calculus (cslib-community#1777) and replaced the tidy decoder certificate with
exists_computableInDegree_decodeDesc (cslib-community#1863). Use the plain mapWith,
stepWith_inO.tidy and the plain decoder with .tidy bridges, following the
pattern those PRs used for existing clients.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG

---------

Co-authored-by: Claude Opus 5.5 <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.

4 participants