Bundled Query Runtimes #
This file packages concrete query implementations as explicit runtime objects.
HasQuery spec m is the right capability interface for constructions that only need to issue
queries. When we want to instrument, transport, or otherwise analyze that capability, we also need
an explicit QueryImpl spec m to work with. QueryRuntime spec m is the thin bundle that stores
that implementation without changing the capability layer.
The main use cases are:
- reifying an existing
HasQuerycapability as aQueryRuntime; - adding cost, counting, or logging layers to a runtime;
- instantiating a generic
HasQueryconstruction directly in an analysis monad.
Bundled implementation of the oracle family spec in the ambient monad m.
- impl : QueryImpl spec m
Concrete implementation of each query in the family
spec.
Instances For
View a bundled query runtime as the corresponding HasQuery capability.
Instances For
Repackage an existing HasQuery capability as an explicit query runtime.
Instances For
The canonical bundled runtime for the free oracle monad OracleComp spec.
Instances For
Instrument a query runtime with multiplicative/monoidal cost accumulation in a WriterT
layer.
Instances For
Instrument a query runtime with additive cost accumulation in an AddWriterT layer.
Instances For
Instrument a query runtime 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.
Instances For
Instantiate a generic HasQuery computation in the concrete runtime runtime.
Instances For
Instantiate a generic HasQuery computation in the additive-cost instrumented runtime
obtained from runtime.
Instances For
Instantiate a generic HasQuery computation in the unit-cost instrumented runtime obtained
from runtime.
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).