General stuff #
Equations
Instances For
Stateful programs #
A probabilistic program with state state and result a: from an initial state, a
sub-distribution over results and final states.
This is StateT state SubProbability a unfolded, and deliberately not defined as that:
StateT puts the state and the result in one universe, but a program's state lives in a higher
universe than its results (variables are indexed by VariableName, which contains a Type, so
VariableAssignment and ProgramState are in Type 1, while results are Unit, Bool, …).
The Monad instance below and the instances after the monad laws are
StateT's, written out. The state and the results have independent universes.
Equations
- GaudisCrypt.ProgramDenotation state a = (state → GaudisCrypt.SubProbability (a × state))
Instances For
Run a sub-probability as a program that leaves the state alone (StateT.lift). The bind is
SubProbability.hbind since a and a × s may live in different universes.
Instances For
Equations
Instances For
Equations
Instances For
Uniform subprobability over a nonempty finset.
Equations
Instances For
Uniform sampling over a nonempty finset (used e.g. for "sample without replacement" — uniform over the complement of the values seen so far).
Equations
Instances For
Equations
- prog.finalProb1 st x = prog.finalProb st {x}
Instances For
Equations
- One or more equations did not get rendered due to their size.
Equations
- One or more equations did not get rendered due to their size.
Equations
- One or more equations did not get rendered due to their size.
bind, applied to a state. (What StateT.bind unfolded to.)
Running a sub-probability as a program that leaves the state alone (StateT.lift).
Equations
- GaudisCrypt.instMonadLiftSubProbabilityProgramDenotation = { monadLift := fun {α : Type ?u.1} => GaudisCrypt.SubProbability.toProgramDenotation }
toProgramDenotation, applied to a state. (In one universe, SubProbability.hbind_eq_bind
turns the hbind into >>=.)
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- GaudisCrypt.while_loop cond body = GaudisCrypt.recursion (GaudisCrypt.while_iteration cond body) ()
Instances For
Instances For
Overwrite the whole state.
Instances For
ProgramDenotation.get/ProgramDenotation.set accept anything that forgets to a
Getter/Setter
— a Getter/Setter itself, or a full Lens/Variable. The value/state
types are outParams recovered from the argument, which sidesteps the Lean
4.30 coercion that no longer fires when the value type is a metavariable.
- toG : T → Getter a s
Instances
Equations
Equations
Equations
- GaudisCrypt.ProgramDenotation.set v x st = pure ((), (GaudisCrypt.AsSetter.toS v).set x st)
Instances For
Equations
- GaudisCrypt.ProgramDenotation.get v st = pure ((GaudisCrypt.AsGetter.toG v).get st, st)
Instances For
Equations
Instances For
Run p on the part of the state that lens selects. (s and t may live in different
universes, hence SubProbability.hbind.)
Equations
Instances For
Monad laws for ProgramDenotation s #
The monad laws. StateT would only have given this from a LawfulMonad SubProbability,
which does not exist; here it comes from the three laws proved above.
Reading and writing the whole state (get/set/modify in do notation). Lean's
MonadStateOf puts the state and the results in one universe, so this instance only exists for
results in the state's universe.
Equations
- One or more equations did not get rendered due to their size.