Writer Cost Accounting #
This file collects reusable AddWriterT facts for pathwise and expected cost reasoning.
It also equips QueryImpl with additive writer-cost instrumentation.
Instrument an implementation with additive cost accumulation in an AddWriterT layer.
Instances For
Instrument an implementation with unit additive cost for every query.
Instances For
Pathwise upper bound for an AddWriterT computation: every reachable execution result carries
additive cost at most w.
Instances For
Pathwise lower bound for an AddWriterT computation: every reachable execution result carries
additive cost at least w.
Instances For
Pathwise exactness on support for an AddWriterT computation: every reachable execution result
carries exactly the additive cost w.
This is the weak extensional notion of pathwise exactness. If oa.run has empty support, it holds
vacuously for every w. Use [AddWriterT.PathwiseHasCost] when the intended meaning is that oa
has an exact pathwise cost and admits at least one reachable execution.
Instances For
Pathwise exact cost for an AddWriterT computation: oa has at least one reachable execution,
and every reachable execution result carries exactly the additive cost w.
This is the strong semantic notion of exact cost over execution paths.
Unlike [AddWriterT.HasCost], it does not require cost to be recoverable
from the final output alone. Unlike
[AddWriterT.PathwiseCostEqOnSupport], it is not vacuous on computations with empty support.
Instances For
The expected additive cost of an AddWriterT computation, obtained by taking the expectation
of its cost marginal.
This expectation is computed over the base monad's subdistribution semantics on oa.costs. In
particular, if the underlying computation can fail, the missing mass contributes 0, exactly as
for other wp-style expectations in VCV-io.
Instances For
Convenience specialization of [AddWriterT.expectedCost] to natural-valued additive costs.
Instances For
Tail-sum formula for the natural-valued expected cost of an AddWriterT computation:
E[cost] = ∑ i, Pr[i < cost].
This is the standard discrete expectation identity specialized to the writer-cost marginal.
Tail domination bounds the expected natural-valued writer cost.
If the tail probability Pr[i < cost] is bounded by a i for every i, then
E[cost] ≤ ∑ i, a i.
Finite tail-sum formula for natural-valued writer cost under a pathwise upper bound.
If every execution path of oa incurs cost at most n, then the tail probabilities vanish above
n, so the infinite tail sum truncates to Finset.range n.
Pathwise upper bound for a unit-cost AddWriterT computation.
Instances For
Pathwise lower bound for a unit-cost AddWriterT computation.
Instances For
Pathwise exact cost for a unit-cost AddWriterT computation: every reachable execution
carries exactly n unit queries.