Relational simulateQ Rules #
This file provides the highest-leverage theorems for game-hopping proofs: relational coupling through oracle simulation, and the "identical until bad" lemma.
Main results #
relTriple_simulateQ_run: If two stateful oracle implementations are related by a state invariant and produce equal outputs, then simulating a computation with either implementation preserves the invariant and output equality.relTriple_simulateQ_run': Projection that only asserts output equality.tvDist_simulateQ_le_probEvent_bad: "Identical until bad" — if two oracle implementations agree whenever a "bad" flag is unset, the TV distance between their simulations is bounded by the probability of bad being set.
Relational simulateQ rules #
Core relational simulateQ theorem with state invariant.
If two oracle implementations produce equal outputs and preserve a state invariant R_state,
then the full simulation also preserves the invariant and output equality.
Projection: relational simulateQ preserving only output equality.
Exact-distribution specialization of relTriple_simulateQ_run'.
If corresponding oracle calls have identical full (output, state) distributions whenever the
states are equal, then the simulated computations have identical output distributions. This
packages the common pattern "prove per-query evalDist equality, then use Eq as the state
invariant" into a single theorem.
WriterT analogue of relTriple_simulateQ_run.
If two writer-transformed oracle implementations produce outputs related by a reflexive-and-closed
relation R_writer on the accumulated logs, then the full simulation preserves output equality
together with the accumulated-log relation.
hR_one witnesses reflexivity at the empty accumulator (the run-start value), and hR_mul
closes R_writer under the monoid multiplication used by WriterT's bind. Together these make
R_writer a monoid congruence on the two writer spaces, which is precisely the structural
requirement for whole-program accumulation.
WriterT analogue of relTriple_simulateQ_run_of_impl_eq_preservesInv.
If two writer-transformed oracle implementations agree pointwise on
.run (i.e. every per-query increment is identical as an OracleComp),
then the whole simulations yield identical (output, accumulator)
distributions.
WriterT handlers are stateless (.run takes no argument), so the
hypothesis is a plain equality rather than an invariant-gated
implication. The postcondition is strict equality on α × ω.
Output-probability projection of
relTriple_simulateQ_run_writerT_of_impl_eq: two WriterT handlers with
pointwise-equal .run yield identical (output, accumulator) probability
distributions.
evalDist equality projection of
relTriple_simulateQ_run_writerT_of_impl_eq.
Projection of relTriple_simulateQ_run_writerT onto the output component.
If two stateful oracle implementations agree on every query while Inv holds, and the
second implementation preserves Inv, then the full simulations have identical (output, state)
distributions from any invariant-satisfying initial state.
Exact-equality specialization of relTriple_simulateQ_run_of_impl_eq_preservesInv.
This weakens the stronger invariant-carrying postcondition to plain equality on (output, state),
which is the shape consumed directly by probability-transport lemmas and theorem-driven
rvcgen steps.
Output-probability projection of
relTriple_simulateQ_run_of_impl_eq_preservesInv.
Query-bounded exact-output transport for simulateQ.
If oa satisfies a structural query bound IsQueryBound budget canQuery cost, the two
implementations agree on every query that the bound permits, and the second implementation
preserves a budget-indexed invariant Inv, then the full simulated computations have identical
output-state probabilities from any initial state satisfying Inv.
State-projection transport for simulateQ.run.
If each oracle call under impl₁ becomes the corresponding impl₂ call after mapping the state
with proj, then the full simulated runs agree under the same projection.
run' projection corollary of map_run_simulateQ_eq_of_query_map_eq.
Relational transport corollary of run'_simulateQ_eq_of_query_map_eq.
Generalized state-projection theorem: if applying proj to the state commutes with each
oracle step, then it commutes with the full simulation. Generalizes the ProbComp version
to any target spec.
run' projection corollary of map_run_simulateQ_eq_of_query_map_eq'.
"Identical until bad" fundamental lemma #
The fundamental lemma of game playing: if two oracle implementations agree whenever a "bad" flag is unset, then the total variation distance between the two simulations is bounded by the probability that bad gets set.
Both implementations must satisfy a monotonicity condition: once bad s holds, it must
remain true in all reachable successor states. Without this, the theorem is false — an
implementation could enter a bad state (where agreement is not required), diverge, and
then return to a non-bad state, producing different outputs with Pr[bad] = 0.
Monotonicity is needed on both sides because the proof establishes pointwise equality
Pr[= (x,s) | sim₁] = Pr[= (x,s) | sim₂] for all ¬bad s, which requires ruling out
bad-to-non-bad transitions in each implementation independently.
Distributional "identical until bad" #
The _dist variant weakens the agreement hypothesis from definitional equality
(impl₁ t).run s = (impl₂ t).run s) to distributional equality
(∀ p, Pr[= p | (impl₁ t).run s] = Pr[= p | (impl₂ t).run s]).
This is needed when the two implementations differ intensionally but agree on
output probabilities.
Distributional variant of tvDist_simulateQ_le_probEvent_bad:
weakens the agreement hypothesis from definitional equality to distributional equality
(pointwise equal output probabilities).
Given a StateT (σ × Q) ProbComp query implementation, fix the second state component
at q₀ and project to StateT σ ProbComp.
Instances For
If the Q-component of product state (σ × Q) is invariant under all oracle queries
starting from q₀, then the full simulateQ computation decomposes: running with (s, q₀)
produces the same result as running the projected implementation on s alone, with q₀
appended back.
This generalizes map_run_simulateQ_eq_of_query_map_eq from all-states commutativity
to support-based invariance.
run' projection corollary of simulateQ_run_eq_of_snd_invariant.