# Correctness by construction for probabilistic programs

arXiv: https://arxiv.org/abs/2007.15246 · HTML: https://mlsanity.com/paper/2007.15246/

## Key facts

- Cited by 2 papers in the map (data through 14 Oct 2026).
- First posted on arXiv 30 Jul 2020.

## Built on by (most cited first, 2 of 2)

- [Mixed Nondeterministic-Probabilistic Automata: Blending graphical probabilistic models with nondeterminism](https://mlsanity.com/paper/2201.07474/) (2022)
- [Probabilistic unifying relations for modelling epistemic and aleatoric uncertainty: semantics and automated reasoning with theorem proving](https://mlsanity.com/paper/2303.09692/) (2023)

## Abstract (arXiv)

The "correct by construction" paradigm is an important component of modern Formal Methods, and here we use the probabilistic Guarded-Command Language mathitpGCL to illustrate its application to mathitprobabilistic programming. mathitpGCL extends Dijkstra's guarded-command language mathitGCL with probabilistic choice, and is equipped with a correctness-preserving refinement relation (sqsubseteq) that enables compact, abstract specifications of probabilistic properties to be transformed gradually to concrete, executable code by applying mathematical insights in a systematic and layered way. Characteristically for "correctness by construction", as far as possible the reasoning in each refinement-step layer does not depend on earlier layers, and does not affect later ones. We demonstrate the technique by deriving a fair-coin implementation of any given discrete probability distribution. In the special case of simulating a fair die, our correct-by-construction algorithm turns out to be "within spitting distance" of Knuth and Yao's optimal solution.
