Skip to content

Commit aee8cd5

Browse files
author
David Ledvinka
committed
slop prototype
1 parent 7d16e75 commit aee8cd5

11 files changed

Lines changed: 1530 additions & 11 deletions

File tree

‎README.md‎

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,49 @@
1-
# Random-do notation
1+
# Random-do notation
2+
3+
Write a probability program once using `rdo`, then interpret it in different measurable-space
4+
monads. `Measure` gives its distribution; `RandomM Ω P` samples from a probability source while
5+
preserving fresh source state. `SampleM Ω P` uses an infinite stream of independent `P` draws.
6+
7+
To relate the two interpretations, add `rdo_program` to a polymorphic definition:
8+
9+
```lean
10+
import RandomDo
11+
12+
open MeasureTheory
13+
universe v
14+
15+
def sumDraws {m : (α : Type) → [MeasurableSpace α] → Type v}
16+
[MeasurableSpaceMonad m] (coin : m Bool) : ℕ → m ℕ
17+
| 0 => rdo return 0
18+
| n + 1 => rdo
19+
let b ← coin
20+
let s ← sumDraws coin n
21+
return b.toNat + s
22+
23+
attribute [rdo_program] sumDraws
24+
25+
example {Ω : Type*} [MeasurableSpace Ω] {P : Measure Ω}
26+
[IsProbabilityMeasure P] (coin : RandomM Ω P Bool) (n : ℕ) :
27+
(sumDraws coin n).law = sumDraws (m := Measure) coin.law n :=
28+
sumDraws.law coin n
29+
```
30+
31+
The attribute leaves the original definition unchanged. It generates a recorded program
32+
(`.program`), a certificate (`.valid` and `.certified`), bridges to the original interpretations
33+
(`.sample_bridge` and `.measure_bridge`), and the resulting `.law` theorem. The proof uses
34+
`RDo.Program.Certified.law`, which holds for every certified program. The `rdo_valid` tactic can
35+
also construct certificates directly, leaving any unresolved measurability conditions as goals.
36+
37+
The current automation supports returns, binds, measurable conditionals, sampler arguments,
38+
and one-argument sampler families. A family argument adds a joint-measurability hypothesis to
39+
the generated certificate and law theorem. `SampleM.ofKernel` provides this property for Markov
40+
kernels; `SampleM.ofMeasure` supplies independent draws from probability measures on standard
41+
Borel spaces. Both constructors use a stream of uniform draws from the unit interval.
42+
43+
The attribute currently requires leading `{m} [MeasurableSpaceMonad m]` parameters and an
44+
independent universe parameter for the monad's output, as above. It attempts induction on the
45+
last explicit `Nat` argument. General recursion and loops need further support. Certification
46+
fails if a proof obligation remains; no global measurable-evaluation assumption is required.
47+
48+
See `Test/Program.lean` for continuous and kernel examples, and `Test/SampleM.lean` for independent
49+
draws and the proof that a sum of `n` Bernoulli samples has the binomial distribution.

‎RandomDo.lean‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ public import RandomDo.Monad.ForInInstances
66
public import RandomDo.Monad.Instances
77
public import RandomDo.Monad.MeasurableSpace
88
public import RandomDo.Monad.Notation
9+
public import RandomDo.Monad.Program
10+
public import RandomDo.Monad.Sample
911
public import RandomDo.NumLean.Distributions
1012
public import RandomDo.NumLean.PCG64
1113
public import RandomDo.NumLean.SeedSequence
@@ -16,3 +18,4 @@ public import RandomDo.Tactic.Elab
1618
public import RandomDo.Tactic.ForInStep
1719
public import RandomDo.Tactic.IsMarkov
1820
public import RandomDo.Tactic.Lemmas
21+
public import RandomDo.Tactic.Program

0 commit comments

Comments
 (0)