Cost Models for Oracle Computations #
This file defines a general cost model for oracle computations, parametric over any
AddCommMonoid cost type. This supports natural numbers, extended non-negative reals,
per-oracle cost vectors, and custom multi-dimensional cost structures.
Uses AddWriterT (defined in ToMathlib.Control.WriterT) for additive cost accumulation.
Main Definitions #
instrumentedRun oa cm:oainterpreted in the canonical free runtime with additive cost tracking.addCostOracle costFn: the corresponding one-query instrumented oracle implementation.CostModel spec ω: Assigns costqueryCost t : ωto each oracle queryt.costDist oa cm: Joint distribution of(output, totalCost).expectedCost oa cm val: Expected total costE[val(cost)], computed viawp.WorstCaseCostBound,ExpectedCostBound: Cost bound predicates.WorstCasePolyTime,ExpectedPolyTime: Asymptotic polynomial-time predicates for computation families indexed by a security parameter.
Key Results #
fst_map_costDist: Cost instrumentation doesn't change the output distribution.expectedCost_pure: Expected cost of a pure computation is0.probEvent_cost_gt_le_expectedCost_div: Markov's inequality for cost distributions.WorstCasePolyTime.toExpectedPolyTime: Strict polynomial time implies expected polynomial time.
Cost Model, Cost Oracle, Cost Distribution #
All definitions below operate at Type (= Type 0), matching wp, support, and Pr[ ...]
which are defined for {α : Type} in the program logic.
Oracle that tracks additive cost. Wraps costOracle with Multiplicative
to get additive accumulation through the existing WriterT infrastructure.
Instances For
A cost model assigns a cost in ω to each oracle query.
The cost type ω can be ℕ, ℝ≥0∞, ι → ℕ (per-oracle), or any AddCommMonoid.
- queryCost : spec.Domain → ω
Instances For
The zero cost model: every query is free.
Instances For
Run oa in the canonical free OracleComp runtime instrumented by cm's additive
query-cost function. This is the semantic core of CostModel.
Instances For
The joint distribution of (output, totalCost) obtained by running oa with
additive cost tracking. Cost accumulates via + through AddWriterT.
Since Multiplicative ω and ω are definitionally equal, the second component
of the product can be used directly as ω.
Instances For
Cost instrumentation does not change the output distribution.
For OracleComp, AddWriterT.expectedCost is the weakest-precondition expectation of the
run semantics projected to the additive cost component.
Expected Cost #
The expected total cost of oa under cost model cm, valued by val : ω → ℝ≥0∞.
Computed as E[val(cost)] = ∑ (x, c), Pr[= (x, c) | costDist] * val(c).
The valuation val maps the abstract cost type to ℝ≥0∞ for expectation computation.
For ω = ℕ, use (↑·). For ω = ℝ≥0∞, use id. For multi-dimensional cost,
choose which dimension to analyze.
Instances For
Convenience: expected cost for ℕ-valued cost models.
Instances For
The CostModel.expectedCost facade agrees definitionally with the weakest-precondition
expectation of the instrumented costDist.
If val z.2 ≤ c for all z in the support of costDist, then expectedCost ≤ c.
This is the key bridge from worst-case (support) bounds to expected bounds.
Worst-Case Cost Bounds #
Every execution path of oa under cm has total cost at most bound.
Currently unused outside this file; retained as scaffolding for future asymptotic analyses.
Instances For
WorstCaseCostBound is equivalently a support bound over the old costDist view.
Cost Bounds #
The expected cost of oa under cm (valued by val) is at most bound.
Currently unused outside this file; retained as scaffolding for future asymptotic analyses.
Instances For
A strict cost bound implies an expected cost bound, provided the valuation val
is monotone with respect to ≤ on ω.
Markov's inequality for cost distributions (multiplication form).
The probability that the valued cost exceeds t, times t, is at most expectedCost.
Markov's inequality for cost distributions (division form).
Standard Cost Models #
Unit cost model: every oracle query costs 1. Total cost under this model equals total query count.
Instances For
A strict bound under the unit cost model yields a uniform per-index query bound:
if every execution uses at most bound total unit-cost steps, then each oracle index
is queried at most bound times.
If main makes at most qb i queries to each oracle i, then its total query count
(under the unit cost model) is at most ∑ i, qb i on every execution path.
Corollary: the expected total query count is also at most ∑ i, qb i. Follows from the
worst-case bound toWorstCaseCostBound_unit_sum.
Run a ProbComp with unit-cost instrumentation: each call to the uniform-selection oracle
is counted as cost 1.