Documentation

GaudisCrypt.Lib.EC.WhileSamplingFixedTest

EasyCrypt's WhileSamplingFixedTest (theories/distributions/Dexcepted.ec) #

Sampling from dt i \ test i (the distribution dt i conditioned on failing test i) and rejection sampling: SampleE samples the conditioned distribution, SampleWi resamples from dt i while the test holds. The theory's types and operators (type input, t, op dt : input -> t distr, op test : input -> t -> bool) are the class Params.

Only what ported developments use is here: the modules SampleE, SampleWi, and the lemmas pr_sampleE, pr_sampleWi, sampleE_sampleWi. The proofs are not EasyCrypt's (which go through its theories TwoStepSampling and WhileSampling): pr_sampleWi is the loop rule while I V k ε with the two-step identity dexcepted_indirect for the body. Names are EasyCrypt's.

theorem GaudisCrypt.phoareStmt_sample_seq {α : Type} {A I : ProgramState → Prop} {x : Setter α ProgramState} {e : Getter (SubProbability α) ProgramState} {w : Stmt} {Q r r' : ProgramState → ENNReal} (ih : phoare[ I CurrentState.state ==> Q CurrentState.state ] = (r' CurrentState.state) { stmt w; }) (hI : ∀ (σ : ProgramState), A σ → ∀ (a : α), I (x.set a σ)) (hr : ∀ (σ : ProgramState), A σ → ((e.get σ).expected fun (a : α) => r' (x.set a σ)) = r σ) :
phoare[ A CurrentState.state ==> Q CurrentState.state ] = (r CurrentState.state) { x <$ §e; stmt w; }

A sampling followed by a statement w, from a judgment about w whose bound is a function of the state: the bound is its expected value over the sampling.

theorem GaudisCrypt.EC.mu_eq_zero_of_forall_not {α : Type} (d : SubProbability α) (E : α → Prop) (h : ∀ (v : α), ¬E v) :
mu d E = 0

An event that never holds has probability 0.

theorem GaudisCrypt.EC.not_of_mem_support_of_mu_eq_zero {α : Type} (d : SubProbability α) (E : α → Prop) (h : mu d E = 0) (v : α) :
↑d {v} ≠ 0 → ¬E v

An event of probability 0 holds nowhere on the support.

theorem GaudisCrypt.EC.dexcepted_eq_bot {α : Type} (d : SubProbability α) (P : α → Prop) (h : ∀ (a : α), ¬P a → ↑d {a} = 0) :

d \ P is the null distribution when d gives no mass outside P.

theorem GaudisCrypt.EC.dexcepted_expected_step {α : Type} (d : SubProbability α) (X P : α → Prop) (hd : is_lossless d) :
(d.expected fun (a : α) => ENNReal.ofReal (if X a then mu (dexcepted d X) P else if P a then 1 else 0)) = ENNReal.ofReal (mu (dexcepted d X) P)

One round of rejection sampling: the expected value, over a draw from d, of "the probability of P under d \ X if the draw is in X, else whether the draw is in P", is the probability of P under d \ X (EC's TwoStepSampling, dexcepted_indirect).

The theory's parameters.

Instances
    noncomputable def GaudisCrypt.EC.WhileSamplingFixedTest.SampleE.init {input t : Type} [_gaudiParam0 : Inhabited input] [_gaudiParam1 : Inhabited t] [_gaudiParam2 : Params input t] :

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

    Equations
    Instances For
      noncomputable def GaudisCrypt.EC.WhileSamplingFixedTest.SampleE {input t : Type} [_gaudiParam0 : Inhabited input] [_gaudiParam1 : Inhabited t] [_gaudiParam2 : Params input t] :

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

      Equations
      Instances For
        noncomputable def GaudisCrypt.EC.WhileSamplingFixedTest.SampleE.init.procedure {input t : Type} [_gaudiParam0 : Inhabited input] [_gaudiParam1 : Inhabited t] [_gaudiParam2 : Params input t] :

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

        Equations
        Instances For
          noncomputable def GaudisCrypt.EC.WhileSamplingFixedTest.SampleE.sample {input t : Type} [_gaudiParam0 : Inhabited input] [_gaudiParam1 : Inhabited t] [_gaudiParam2 : Params input t] :

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

          Equations
          Instances For
            @[simp]
            theorem GaudisCrypt.EC.WhileSamplingFixedTest.SampleE.sample.apply_simp {input t : Type} [_gaudiParam0 : Inhabited input] [_gaudiParam1 : Inhabited t] [_gaudiParam2 : Params input t] :

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

            noncomputable def GaudisCrypt.EC.WhileSamplingFixedTest.SampleE.sample.procedure {input t : Type} [_gaudiParam0 : Inhabited input] [_gaudiParam1 : Inhabited t] [_gaudiParam2 : Params input t] :

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

            Equations
            • One or more equations did not get rendered due to their size.
            Instances For
              theorem GaudisCrypt.EC.WhileSamplingFixedTest.SampleE.sample.procedure.apply_simp {input t : Type} [_gaudiParam0 : Inhabited input] [_gaudiParam1 : Inhabited t] [_gaudiParam2 : Params input t] (holeArgs✝ : HoleSigs.empty.Instantiation) :
              procedure.instantiate holeArgs✝ = proc (i : input) : t { var r : t; r <$ dexcepted (dt §i) fun (v : t) => test (§i) v = true; return §r }

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

              @[simp]
              theorem GaudisCrypt.EC.WhileSamplingFixedTest.SampleE.init.apply_simp {input t : Type} [_gaudiParam0 : Inhabited input] [_gaudiParam1 : Inhabited t] [_gaudiParam2 : Params input t] :

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

              theorem GaudisCrypt.EC.WhileSamplingFixedTest.SampleE.init.procedure.apply_simp {input t : Type} [_gaudiParam0 : Inhabited input] [_gaudiParam1 : Inhabited t] [_gaudiParam2 : Params input t] (holeArgs✝ : HoleSigs.empty.Instantiation) :
              procedure.instantiate holeArgs✝ = proc () : Unit { skip; return () }

              Instantiating the holes of SampleE.init.procedure with a tuple holeArgs of procedures: the body of proc init 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 [SampleE.init.procedure.apply_simp]).

              noncomputable def GaudisCrypt.EC.WhileSamplingFixedTest.SampleWi {input t : Type} [_gaudiParam0 : Inhabited input] [_gaudiParam1 : Inhabited t] [_gaudiParam2 : Params input t] :

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

              Equations
              Instances For
                noncomputable def GaudisCrypt.EC.WhileSamplingFixedTest.SampleWi.sample.procedure {input t : Type} [_gaudiParam0 : Inhabited input] [_gaudiParam1 : Inhabited t] [_gaudiParam2 : Params input t] :

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

                Equations
                • One or more equations did not get rendered due to their size.
                Instances For
                  @[simp]
                  theorem GaudisCrypt.EC.WhileSamplingFixedTest.SampleWi.init.apply_simp {input t : Type} [_gaudiParam0 : Inhabited input] [_gaudiParam1 : Inhabited t] [_gaudiParam2 : Params input t] :

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

                  theorem GaudisCrypt.EC.WhileSamplingFixedTest.SampleWi.init.procedure.apply_simp {input t : Type} [_gaudiParam0 : Inhabited input] [_gaudiParam1 : Inhabited t] [_gaudiParam2 : Params input t] (holeArgs✝ : HoleSigs.empty.Instantiation) :
                  procedure.instantiate holeArgs✝ = proc () : Unit { skip; return () }

                  Instantiating the holes of SampleWi.init.procedure with a tuple holeArgs of procedures: the body of proc init 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 [SampleWi.init.procedure.apply_simp]).

                  noncomputable def GaudisCrypt.EC.WhileSamplingFixedTest.SampleWi.init {input t : Type} [_gaudiParam0 : Inhabited input] [_gaudiParam1 : Inhabited t] [_gaudiParam2 : Params input t] :

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

                  Equations
                  Instances For
                    noncomputable def GaudisCrypt.EC.WhileSamplingFixedTest.SampleWi.sample {input t : Type} [_gaudiParam0 : Inhabited input] [_gaudiParam1 : Inhabited t] [_gaudiParam2 : Params input t] :

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

                    Equations
                    Instances For
                      theorem GaudisCrypt.EC.WhileSamplingFixedTest.SampleWi.sample.procedure.apply_simp {input t : Type} [_gaudiParam0 : Inhabited input] [_gaudiParam1 : Inhabited t] [_gaudiParam2 : Params input t] (holeArgs✝ : HoleSigs.empty.Instantiation) :
                      procedure.instantiate holeArgs✝ = proc (i : input, r : t) : t { while (test §i §r) { r <$ dt §i; } return §r }

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

                      @[simp]
                      theorem GaudisCrypt.EC.WhileSamplingFixedTest.SampleWi.sample.apply_simp {input t : Type} [_gaudiParam0 : Inhabited input] [_gaudiParam1 : Inhabited t] [_gaudiParam2 : Params input t] :

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

                      noncomputable def GaudisCrypt.EC.WhileSamplingFixedTest.SampleWi.init.procedure {input t : Type} [_gaudiParam0 : Inhabited input] [_gaudiParam1 : Inhabited t] [_gaudiParam2 : Params input t] :

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

                      Equations
                      Instances For
                        theorem GaudisCrypt.EC.WhileSamplingFixedTest.pr_sampleE {input t : Type} [Inhabited input] [Inhabited t] [Params input t] (m : VariableAssignment) (x : input) (P : t → Prop) :
                        Pr[ SampleE.sample (x) @ &m : P §res ] = mu (dexcepted (dt x) fun (v : t) => test x v = true) P

                        lemma pr_sampleE.

                        theorem GaudisCrypt.EC.WhileSamplingFixedTest.test_of_mem_support {input t : Type} [Inhabited input] [Inhabited t] [Params input t] (x : input) (h : ¬0 < mu (dt x) fun (v : t) => test x v = false) (v : t) (hv : v ∈ (dt x).support) :
                        test x v = true

                        When dt x gives no mass to the values that fail the test, its support passes it.

                        theorem GaudisCrypt.EC.WhileSamplingFixedTest.pr_sampleWi {input t : Type} [Inhabited input] [Inhabited t] [Params input t] (m : VariableAssignment) (x : input) (y : t) (P : t → Prop) (dt_ll : is_lossless (dt x)) :
                        Pr[ SampleWi.sample (x, y) @ &m : P §res ] = if test x y = true then mu (dexcepted (dt x) fun (v : t) => test x v = true) P else if P y then 1 else 0

                        lemma pr_sampleWi.

                        theorem GaudisCrypt.EC.WhileSamplingFixedTest.sampleE_sampleWi {input t : Type} [Inhabited input] [Inhabited t] [Params input t] :
                        equiv[ SampleE.sample (i) ~ SampleWi.sample (i, r) : ={i} ∧ is_lossless (dt §i{1}) ∧ test §i{2} §r{2} = true ==> ={res} ]

                        equiv sampleE_sampleWi: sampling dt i \ test i, and resampling from dt i while the test holds (from a value that satisfies it), return the same result.