NLA-lib Explorer

Example: stochastic rounding, as an operation with hidden randomness

Library · Source module

Example: stochastic rounding, as an operation with hidden randomness

At the level of an algorithm the stochastically rounded addition is srAdd [x, y] [z]: two operands, no random operand. Its contract (NLAlib.Ops.Examples.IsSrAdd, with the mathematics NLAlib.Ops.Examples.SrModel) is conditional on the history: the result is a function g of the two operands and of one entry of the tape that the operation reads for itself; for every pair of operands, over a fresh uniform draw, the result is within 2 u of the sum surely and has the sum as its mean.

Inside the implementation only, there is a primitive sraddXi [x, y, ξ] [z] that is given its random word: srAdd is implemented by "draw ξ into scratch; sraddXi". The scratch cell is freed at the end of the call; no cell of the algorithm ever holds ξ.

The algorithm is the stochastically rounded sum NLAlib.Ops.Examples.srsum.

Main results

* NLAlib.Ops.Examples.integral_dec_srsumF: the stochastically rounded sum is unbiased, 𝔼 ŝ = s, by the conditional law of each window given the past; with the sure bound NLAlib.Ops.Examples.abs_dec_srsumF_sub_le. Mathematics. * NLAlib.Ops.Examples.runsLaw_srsum: the abstract theorem, for every interpretation satisfying the contract of srAdd and every law of the tape: n calls, the workspace of one, the sure bound for every sample and 𝔼 ŝ = s. * NLAlib.Ops.Examples.sr_certifies: the certificate of the profile (contract by linking, counts, window by the window lemma). * NLAlib.Ops.Examples.runsLaw_srsum_link: the corollary for the program that draws, one application of Profile.Refines.runsLaw: n draws, n sraddXi, one scratch cell. * NLAlib.Ops.Examples.exists_isSrLo: the contracts can be met.

Declarations