Documentation

GaudisCrypt.Examples.VonNeumann

Von Neumann's trick (EasyCrypt examples/vonNeumann.eca) #

EC: "In this theory, we illustrate some reasoning on distributions on Von Neumann's trick to simulate a fair coin toss using only a biased coin (of unknown bias)." Two flips of the biased coin are repeated until they differ, and the first is returned: Simulate.sample returns each bit with the probability of a fair coin (Simulate_is_Fair).

EC's file, declaration by declaration and script line by line. All of EC's lemmas are proven.

Translation:

Gap list (what keeps the file from reading as EC's):

@[simp]

@[simp]: Fair.sample = Module.proc Fair.sample.procedure — true by definition, proc sample using no module parameter and so having no holes to fill.

The module declared by module Fair: the record of its procedures Fair.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 Fair.apply_simp to apply it with.

Equations
Instances For

    proc sample of module Fair as a module: Module.proc Fair.sample.procedure, of type Module.Proc (procsig …). It uses no module parameter, so it is not a function — Fair.sample.apply_simp says exactly that.

    Equations
    Instances For
      theorem GaudisCrypt.Examples.VonNeumann.Fair.sample.procedure.apply_simp (holeArgs✝ : HoleSigs.empty.Instantiation) :
      procedure.instantiate holeArgs✝ = proc () : Bool { var b : Bool; b <$ EC.dbool; return §b }

      Instantiating the holes of Fair.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 [Fair.sample.procedure.apply_simp]).

      The body of proc sample of module Fair, 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 Fair.sample.procedure.apply_simp) rather than run. Use Fair.sample for this procedure as a module.

      Equations
      Instances For

        EC's op p : { real | 0%r < p < 1%r } as in01_p.

        Instances

          The module declared by module Simulate: the record of its procedures Simulate.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 Simulate.apply_simp to apply it with.

          Equations
          Instances For
            @[simp]

            @[simp]: Simulate.sample = Module.proc Simulate.sample.procedure — true by definition, proc sample using no module parameter and so having no holes to fill.

            theorem GaudisCrypt.Examples.VonNeumann.Simulate.sample.procedure.apply_simp [Params] (holeArgs✝ : HoleSigs.empty.Instantiation) :
            procedure.instantiate holeArgs✝ = proc () : Bool { var b : Bool, b' : Bool; b <- true; b' <- true; while (decide (§b = §b')) { b <$ Biased.dbiased; b' <$ Biased.dbiased; } return §b }

            Instantiating the holes of Simulate.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 [Simulate.sample.procedure.apply_simp]).

            The body of proc sample of module Simulate, 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 Simulate.sample.procedure.apply_simp) rather than run. Use Simulate.sample for this procedure as a module.

            Equations
            • One or more equations did not get rendered due to their size.
            Instances For

              proc sample of module Simulate as a module: Module.proc Simulate.sample.procedure, of type Module.Proc (procsig …). It uses no module parameter, so it is not a function — Simulate.sample.apply_simp says exactly that.

              Equations
              Instances For

                The module declared by module SamplePair: the record of its procedures SamplePair.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 SamplePair.apply_simp to apply it with.

                Equations
                Instances For

                  proc sample of module SamplePair as a module: Module.proc SamplePair.sample.procedure, of type Module.Proc (procsig …). It uses no module parameter, so it is not a function — SamplePair.sample.apply_simp says exactly that.

                  Equations
                  Instances For

                    The body of proc sample of module SamplePair, 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 SamplePair.sample.procedure.apply_simp) rather than run. Use SamplePair.sample for this procedure as a module.

                    Equations
                    Instances For
                      @[simp]

                      @[simp]: SamplePair.sample = Module.proc SamplePair.sample.procedure — true by definition, proc sample using no module parameter and so having no holes to fill.

                      theorem GaudisCrypt.Examples.VonNeumann.SamplePair.sample.procedure.apply_simp [Params] (holeArgs✝ : HoleSigs.empty.Instantiation) :
                      procedure.instantiate holeArgs✝ = proc () : Bool { var b : Bool, b' : Bool; b, b' <$ dvn; return §b }

                      Instantiating the holes of SamplePair.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 [SamplePair.sample.procedure.apply_simp]).

                      Each value of the first coin has probability 1/2 under dvn (EC proves it where it is used: rewrite vnE; pose c := count _ _; …, rewrite !vnE /svn …).

                      We can now prove that sampling a pair in the restricted distribution and flipping two coins independently until they are distinct, returning the first one, are equivalent.