Documentation

GaudisCrypt.Examples.Dice4_6

A four-sided die from a six-sided one (EasyCrypt examples/Dice4_6.ec) #

Roll a six-sided die until it shows 1–4 (D6): each of 1–4 has probability 1/4 (prD6), as for a four-sided die (D4, prD4). The two are related (D4_D6) through EC's theory of rejection sampling, cloned as D4_6: D4 samples the restricted distribution (D4_Sample), D6 is the rejection loop (D6_Sample), and the theory relates the two (D4_6.sampleE_sampleWi, Lib/EC/WhileSamplingFixedTest.lean).

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

Translation:

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

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

Equations
Instances For
    theorem GaudisCrypt.Examples.Dice4_6.D4.sample.procedure.apply_simp (holeArgs✝ : HoleSigs.empty.Instantiation) :
    procedure.instantiate holeArgs✝ = proc () : ℤ { var r : ℤ; r <$ EC.dinter 1 4; return §r }

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

    @[simp]

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

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

    Equations
    Instances For

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

      Equations
      Instances For
        theorem GaudisCrypt.Examples.Dice4_6.prD4 (k : ℤ) (m : VariableAssignment) :
        Pr[ D4.sample () @ &m : §res = k ] = if 1 ≤ k ∧ k ≤ 4 then 1 / 4 else 0
        theorem GaudisCrypt.Examples.Dice4_6.D6.sample.procedure.apply_simp (holeArgs✝ : HoleSigs.empty.Instantiation) :
        procedure.instantiate holeArgs✝ = proc () : ℤ { var r : ℤ; r <- 5; while (decide (5 ≤ §r)) { r <$ EC.dinter 1 6; } return §r }

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

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

        Equations
        Instances For
          @[simp]

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

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

          Equations
          Instances For

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

            Equations
            Instances For
              theorem GaudisCrypt.Examples.Dice4_6.D4_Sample :
              equiv[ D4.sample ~ D4_6.SampleE.sample (i) : True ==> ={res} ]
              theorem GaudisCrypt.Examples.Dice4_6.D6_Sample :
              equiv[ D6.sample ~ D4_6.SampleWi.sample (i, r) : §r{2} = 5 ==> ={res} ]
              theorem GaudisCrypt.Examples.Dice4_6.D4_D6 (f finv : ℤ → ℤ) :
              (∀ (i : ℤ), 1 ≤ i ∧ i ≤ 4 ↔ 1 ≤ f i ∧ f i ≤ 4) → (∀ (i : ℤ), 1 ≤ i ∧ i ≤ 4 → f (finv i) = i ∧ finv (f i) = i) → equiv[ D4.sample ~ D6.sample : True ==> §res{1} = finv §res{2} ]
              theorem GaudisCrypt.Examples.Dice4_6.prD6 (k : ℤ) (m : VariableAssignment) :
              Pr[ D6.sample () @ &m : §res = k ] = if 1 ≤ k ∧ k ≤ 4 then 1 / 4 else 0