Query Cost Accounting #
This file defines the HasQuery-level accounting surface for direct-style query programs.
A direct-style program is evaluated against a concrete QueryImpl, and query-cost statements
are phrased by running that implementation through the writer-cost instrumentation from
WriterCost.lean.
A direct-style computation parameterized by an oracle-query capability.
Instances For
Evaluate a direct-style query program against a concrete implementation.
Instances For
Evaluate a direct-style query program against an additive-cost instrumentation of impl.
Instances For
Evaluate a direct-style query program against the unit-cost instrumentation of impl.
Instances For
A computation generic over a HasQuery spec m capability.
Instances For
Running oa in the additive-cost instrumentation of runtime yields an output-dependent
cost described by f.
Instances For
Running oa in the additive-cost instrumentation of runtime incurs constant cost w.
Instances For
Running oa in the additive-cost instrumentation of runtime incurs cost at most w on
every execution path. This is a semantic support bound, not merely an output-indexed cost
description.
Instances For
Running oa in the additive-cost instrumentation of runtime incurs cost at least w on
every execution path.
Instances For
Unit-cost specialization: every query contributes cost 1.
Instances For
Unit-cost specialization: every query contributes cost 1, with an upper bound.
Instances For
Unit-cost specialization: every query contributes cost 1, with a lower bound.
Instances For
The expected weighted query cost of oa, instantiated in runtime and instrumented by
costFn.
This is the primary expectation notion for generic HasQuery computations. It is computed from
the additive cost marginal in the base monad's subdistribution semantics, valued by val.
The unit-cost query-counting notion [HasQuery.expectedQueries] is a specialization of this
definition with costFn := fun _ ↦ 1 and val := fun n ↦ (n : ENNReal).
Instances For
The marginal distribution of weighted query costs induced by running oa in runtime with
query-cost function costFn.
Instances For
The marginal distribution of the unit-cost query count induced by running oa in runtime.
Instances For
Expected number of oracle queries made by oa when run in runtime, counting each query
with unit additive cost.
Instances For
Tail-sum formula for the expected number of oracle queries made by oa in runtime:
E[number of queries] = ∑ i, Pr[i < number of queries].
This is the generic HasQuery version of [AddWriterT.expectedCostNat_eq_tsum_tail_probs].
Tail domination bounds expected query count.
If Pr[i < number of queries] ≤ a i for every i, then
ExpectedQueries[ oa in runtime ] ≤ ∑ i, a i.
Finite tail-sum formula for expected query count under a pathwise upper bound.
If oa uses at most n oracle queries in every execution, then its expected query count is the
finite sum of the probabilities that the query count exceeds i, for i < n.
Queries[ oa in runtime ] = n means that the generic HasQuery computation oa makes
exactly n oracle queries when instantiated in runtime and instrumented with unit additive
cost per query.
The computation oa is written in direct HasQuery style. The notation elaborates it against
the unit-cost analysis monad induced by runtime, so statements can usually be written without
explicit monad annotations such as m := AddWriterT ℕ m.
Instances For
Queries[ oa in runtime ] ≤ n means that every execution path of oa makes at most n
oracle queries when run in the unit-cost instrumentation of runtime.
This packages the common cryptographic statement “the construction uses at most n queries” on
top of [HasQuery.UsesAtMostQueries].
Instances For
Queries[ oa in runtime ] ≥ n means that every execution of oa in the unit-cost
instrumentation of runtime incurs at least n query-cost units.
This is less common than the exact and upper-bound forms, but it is useful for statements saying that a construction must query the oracle at least a certain number of times.
Instances For
QueryCost[ oa in runtime ] = n is the unit-cost specialization of weighted query cost:
each oracle query contributes additive cost 1, so the total query cost is just the number of
queries made by oa.
Instances For
QueryCost[ oa in runtime by costFn ] = w means that oa, instantiated in runtime and
instrumented so that each query t contributes cost costFn t, has constant total query cost
w.
Use this when the cost model is not unit cost, for example when different query families or different query shapes carry different weights.
Instances For
QueryCost[ oa in runtime ] ≤ n is the unit-cost specialization of pathwise query-cost upper
bounds. It says that every execution of oa makes at most n oracle queries.
Instances For
QueryCost[ oa in runtime by costFn ] ≤ w means that every execution path of oa has total
query cost bounded above by w under the weighting function costFn.
This is the weighted analogue of [Queries[ oa in runtime ] ≤ n].
Instances For
QueryCost[ oa in runtime ] ≥ n is the unit-cost specialization of pathwise query-cost lower
bounds. It says that every execution of oa makes at least n oracle queries.
Instances For
QueryCost[ oa in runtime by costFn ] ≥ w means that every execution path of oa has total
query cost bounded below by w under the weighting function costFn.
This is the weighted analogue of [Queries[ oa in runtime ] ≥ n].
Instances For
ExpectedQueryCost[ oa in runtime ] is the expected number of oracle queries made by oa
when run in runtime, viewed as the unit-cost specialization of weighted expected query cost.
Instances For
ExpectedQueryCost[ oa in runtime by costFn via val ] is the expected weighted query cost of
oa when instantiated in runtime.
Each query t contributes additive cost costFn t, and the total cost is then valued by
val : ω → ENNReal before taking expectation. This is the primary expected-cost term for generic
HasQuery constructions.
Instances For
ExpectedQueries[ oa in runtime ] is the expected number of oracle queries made by oa when
run in runtime, with each query carrying unit additive cost.
The result is an ℝ≥0∞ expectation, so it can be compared directly against natural-number
bounds such as ExpectedQueries[ oa in runtime ] ≤ n.
This is the unit-cost specialization of
[ExpectedQueryCost[ oa in runtime by costFn via val ]], with costFn := fun _ ↦ 1 and
val := fun n ↦ (n : ENNReal).