Logging Queries Made by a Computation #
QueryImpl.withLogging records every query/response pair ⟨t, u⟩ to a
WriterT (QueryLog spec) writer layer. It is a response-dependent trace,
defined as a specialisation of QueryImpl.withTraceAppend (see
Tracing.lean): the log is appended after the underlying handler returns,
so a handler failure leaves no log entry for the failed query.
We use the Append-flavoured withTraceAppend (rather than the Monoid
flavoured withTrace) because QueryLog spec = List _ only carries an
[EmptyCollection, Append, LawfulAppend] structure, not a Monoid. This
matches the pre-existing Monad (WriterT (QueryLog spec) m) instance the
rest of WriterTBridge / mvcgen infrastructure already targets.
Push an outer oracle interpretation through the base monad of a
WriterT-valued query implementation.
Instances For
Running a WriterT handler and then interpreting its base oracle
computations is the same as first mapping the handler's base through the
outer interpreter.
Given that so implements the oracles in spec using the monad m,
withLogging so gives the same implementation in the extension WriterT (QueryLog spec) m,
by appending a single-entry log [⟨t, u⟩] after the handler returns response u.
This is the response-dependent specialisation of QueryImpl.withTraceAppend with the
trace function fun t u => [⟨t, u⟩] (a single-element list, the free-monoid
generator of QueryLog spec = List ((t : spec.Domain) × spec.Range t)).
Instances For
Logging preserves failure probability: for any base monad m with HasEvalSPMF,
wrapping an oracle implementation with withLogging does not change the probability of failure.
When m = OracleComp spec, both sides are 0 (trivially true). When m can genuinely fail
(e.g. OptionT (OracleComp spec)), this is a non-trivial faithfulness property.
Run an implementation and append each queried input to a StateT list.
This is the state-transformer analogue of withLogging when only the query
inputs are needed: responses are returned exactly as in the base
implementation, while the state records the input sequence in order.
Instances For
A WriterT query log can be replayed as a StateT input log.
For computations over a sum spec + loggedSpec, this theorem compares two
implementations:
- left queries in
specare forwarded unchanged; - right queries in
loggedSpecare either handled withwithLogging, producing aQueryLog loggedSpec, or withappendInputLog, appending just the queried inputs to a state list.
Mapping the WriterT result to (output, initialInputs ++ loggedInputs) yields
exactly the same base-monad computation as running the StateT
implementation from initialInputs.
Simulation oracle for tracking the quries in a QueryLog, without modifying the actual
behavior of the oracle. Requires decidable equality of the indexing set to determine
which list to update when queries come in.
Instances For
Specialization of QueryImpl.probFailure_run_simulateQ_withLogging to loggingOracle.
Specialization of QueryImpl.NeverFail_run_simulateQ_withLogging_iff to loggingOracle.
Bidirectional query-bound transfer for loggingOracle / withLogging #
The writer log overlay leaves the underlying query structure untouched, so all three
query-bound flavors transfer biconditionally via fst_map_run_simulateQ /
QueryImpl.fst_map_run_withLogging and isXQueryBound_iff_of_map_eq.
A total query bound controls the length of every loggingOracle trace in support:
if oa makes at most n queries, then every support point of
(simulateQ loggingOracle oa).run has log length at most n.
Add a query log to a computation using a logging oracle.