Sampling until a test fails terminates (EasyCrypt examples/WhileSampling.ec) #
Draw from a lossless distribution until a test fails; if the test fails with positive
probability, the loop terminates with probability 1. EC's file, line by line; its one lemma,
Sample_lossless, is proven with EC's script.
Translation:
type t. op sample … axiom sample_ll … op test … axiom pr_ntestare the classParams(the file is its own theory).- EC's
while I V k εisphoare_while I V k ε(Logic/PHoareWhileRev.lean): the loop terminates because the integer variantV, at mostkand positive while the test passes, decreases in each round with probability at leastε.
Gap list:
- GAP 1: EC's
=> //afterseqandwhilecloses a goal that is a hypothesis (ih, the axiompr_ntest); hereexact ih,exact pr_ntest. - GAP 2 (goals as shown): the body goal of
phoare_whilehas EC's abstract statementw(the loop to come) as a variable of typeStmt; a judgment aboutwprints as a term (phoareStmt … w …), not asphoare[ … ].
EC's type t. op sample: t distr. axiom sample_ll: is_lossless sample. op test: t -> bool. axiom pr_ntest: 0%r < mu sample (predC test).
- sample : SubProbability t
- sample_ll : EC.is_lossless sample
- test : t → Bool
Instances
The module declared by module Sample: the record of its procedures Sample.sample.
The declaration has no parameter list, so no procedure of it can call one either and the module is not a function — it is the plain record itself, and there is no Sample.apply_simp to apply it with.
Equations
Instances For
proc sample of module Sample as a module: Module.proc Sample.sample.procedure, of type Module.Proc (procsig …). It uses no module parameter, so it is not a function — Sample.sample.apply_simp says exactly that.
Equations
Instances For
Instantiating the holes of Sample.sample.procedure with a tuple holeArgs of procedures: the body of proc sample as written, with each hole call replaced by the matching holeArgs.lookup (HoleIndex.zero being the first hole the body declared). True by rfl.
Deliberately not @[simp], unlike the other apply_simp lemmas: its right-hand side is the whole body written out, so letting it fire on its own would turn any goal mentioning an instantiated procedure into that body. Inlining a procedure is a step to ask for by name (simp [Sample.sample.procedure.apply_simp]).
The body of proc sample of module Sample, as a procedure of its own: it calls no module parameter, so it has no holes.
A hole stands for a call whose callee is not known here — a module parameter is supplied only when the module is applied — so the body is a ProcedureWithHoles, to be instantiated (see Sample.sample.procedure.apply_simp) rather than run. Use Sample.sample for this procedure as a module.
Equations
- One or more equations did not get rendered due to their size.
Instances For
@[simp]: Sample.sample = Module.proc Sample.sample.procedure — true by definition, proc sample using no module parameter and so having no holes to fill.
EC's lemma Sample_lossless: islossless Sample.sample.