Skip to content

feat(pfunctor): extend expected charge to unbounded resumptions - #487

Merged
dtumad merged 6 commits into
mainfrom
dtumad/resumption-expected-charge
Nov 26, 2026
Merged

dtumad merged 6 commits into
mainfrom
dtumad/resumption-expected-charge

Conversation

@dtumad

@dtumad dtumad commented Nov 18, 2026 •

Copy link
Copy Markdown
Collaborator

An infinite sequence of requests can incur a finite cost. If only the first request costs one, the total is one. Against a handler that always answers, charging one for every request makes the same client’s total infinite. Both equations hold for every terminal payoff because the client never returns.

PFunctor.Resumption.expectedCharge takes the supremum of the charges of finite prefixes. A return earns its terminal payoff. A prefix cut off at a pending request receives zero terminal credit. Each request incurs its price before the joint kernel samples the answer and successor state.

  • expectedCharge_query and expectedCharge_bind give the equations for one request and for sequencing. expectedCharge_toResumption recovers the fold on finite programs. These laws assume countable answers with measurable singletons and state-measurable prices and terminal payoffs.
  • expectedCharge_le_of_potential lifts the finite amortized bound to every prefix using a measurable potential, a local price inequality and an almost-sure invariant. The state may have any measurable space.
  • Resumption.MeasurableExpectation packages nonnegative measurable functions of the private state. Its two order instances provide bottom and suprema of increasing sequences for the existing continuous-algebra interpretation.

Builds on merged #486. Refs #387.

Review and validation

At b46e02cf, which includes main at 6c9cf976, ./scripts/validate.sh --lint --test --axioms passed, including the documentation and Parliament consumer packages. The sweep found zero sorry or nonstandard-axiom dependencies across 22,519 declarations in 635 modules. #print axioms for the finite-agreement, query, bind, potential and continuous-algebra theorems reported only propext, Classical.choice and Quot.sound.

The regressions distinguish one-time and recurring charges on a client that never returns. A zero-mass request costs seven even with infinite terminal credit, and a request answered with mass one half pays in full and earns half its credit. A finite program receives its terminal credit in the state where it returns. A one-unit potential pays for the setup of every client, and the client that never returns attains the bound. A second potential bound holds in the state its invariant describes and fails in the state it excludes. An adaptive client prices its second request in the state left by its first, so it pays two, then three. A well-founded program without a depth bound, over answers without measurable singletons, has a fold of one and an expected charge of zero, so that hypothesis cannot be dropped from expectedCharge_toResumption. An ordinary-import consumer bounds a finite setup followed by a potentially divergent service.

Mutated copies of the statements fail these tests: credit at cutoffs, a single prefix in place of the supremum, a query equation without its price, with the old state, or with an essential supremum, a bind equation without its continuation, finite agreement without terminal credit, and a potential bound without either credit term.

The result measures incurred cost on visible requests. Almost-sure termination and the law of returned values require separate arguments.

@dtumad
dtumad added this pull request to stack #488 November 18, 2026 02:25
@dtumad
dtumad force-pushed the dtumad/resumption-expected-charge branch from a0f6986 to dd86db2 Compare November 18, 2026 03:49
Base automatically changed from dtumad/finite-stateful-expected-charge to main November 18, 2026 15:15
@dtumad
dtumad force-pushed the dtumad/resumption-expected-charge branch from dd86db2 to ff64cbe Compare November 18, 2026 15:15
@dtumad
dtumad marked this pull request as ready for review November 18, 2026 19:29
Take the supremum over finite query prefixes with zero credit at cutoffs. Use the continuous query algebra to prove sequencing, agreement with finite programs, and transfer of potential bounds.

Co-Authored-By: Codex <noreply@openai.com>
@dtumad
dtumad force-pushed the dtumad/resumption-expected-charge branch from ff64cbe to cc09351 Compare November 20, 2026 07:11
dtumad and others added 5 commits November 25, 2026 16:31
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The statements about expected charges of resumptions use continuous algebras and truncations. The
fusion and approximation theorems occur only in proofs.

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

Attain the potential bound on a client that never returns, price an adaptive client's second
request in the state left by its first, and refute agreement with the finite fold over answers
without measurable singletons.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…te or exact

An infinite total needs a handler that keeps answering, since the zero kernel stops the same client
after one charge. The step equation and agreement with finite folds need measurability conditions.

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

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@dtumad
dtumad added this pull request to the merge queue Nov 26, 2026
Merged via the queue into main with commit e688823 Nov 26, 2026
11 checks passed
@dtumad
dtumad deleted the dtumad/resumption-expected-charge branch November 26, 2026 01:16
dtumad added a commit that referenced this pull request Nov 26, 2026
Resolve docs/guides/cost.md (keep the retry section under #487's renamed
"Layers and costed implementations" heading) and docs/reference/repo-map.md
(keep #487's finite-kernel link and add the retry module).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
dtumad added a commit that referenced this pull request Nov 26, 2026
#487 landed on main as squash e688823, which carries the same tree as its
head b46e02c merged above. The conflicts in PolyFun.lean, cost.md,
repo-map.md and the documentation consumer were both sides adding #487's
text; keep this branch's text and add #510's lines.

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.

1 participant