|
1 | | -# Random-do notation |
| 1 | +# Random-do notation |
| 2 | + |
| 3 | +RandomDo writes probabilistic algorithms in `rdo`. The same program can be interpreted as a |
| 4 | +mathematical measure for proofs or instantiated with an executable sampling backend. |
| 5 | + |
| 6 | +## Differential privacy |
| 7 | + |
| 8 | +Import `RandomDo` (or `RandomDo.DifferentialPrivacy`) and open `DifferentialPrivacy`. |
| 9 | + |
| 10 | +### The Gaussian `rdo` samplers |
| 11 | + |
| 12 | +The algorithms are in [`RandomDo/DifferentialPrivacy/Programs.lean`](RandomDo/DifferentialPrivacy/Programs.lean): |
| 13 | + |
| 14 | +- `gaussianProgram center σ` draws zero-mean Gaussian noise and returns `center + noise`. |
| 15 | +- `gaussianCoordinates center σ` does this independently for each coordinate. |
| 16 | +- `gaussianMeanRealProgram f D c n xs` computes the scalar empirical mean and adds noise. |
| 17 | +- `gaussianMeanProgram f D c n xs` computes the vector empirical mean and adds independent noise |
| 18 | + in each coordinate. |
| 19 | + |
| 20 | +The full scalar mean algorithm is: |
| 21 | + |
| 22 | +```lean |
| 23 | +def gaussianMeanRealProgram {α : Type*} {R V : Type} [Scalar R] [Scalar V] |
| 24 | + [HasGaussian m R V R] (f : α → R) (D c : V) (n : ℕ) (xs : Dataset α) : m R := rdo |
| 25 | + let center := meanValue f xs |
| 26 | + let σ := c * D / (n : V) |
| 27 | + let z ← gaussianProgram (m := m) center σ |
| 28 | + return z |
| 29 | +``` |
| 30 | + |
| 31 | +Here `m` is an arbitrary `MeasurableSpaceMonad`. `meanValue` is pure arithmetic, and |
| 32 | +`gaussianProgram` samples through `HasGaussian` in `rdo`. The vector version uses the same |
| 33 | +computation coordinatewise. There is one implementation of each algorithm. |
| 34 | + |
| 35 | +`D` is a public upper bound on the domain's ℓ₂ diameter, `n > 0` is a public lower bound on |
| 36 | +sample size, and `c` is a public noise multiplier. The standard deviation is `c * D / n`; |
| 37 | +`HasGaussian` takes **variance**, so the sampler passes its square. |
| 38 | + |
| 39 | +At `m := Measure`, `R := ℝ`, and `V := ℝ≥0`, the programs denote exact real distributions. |
| 40 | +The theorems `gaussianMeanRealProgram_eq_mechanism` and `gaussianMeanProgram_eq_mechanism` |
| 41 | +identify these complete programs with the Gaussian laws used in the privacy proofs. |
| 42 | +Choosing another interpretation runs these same definitions. The existing floating-point |
| 43 | +backend is exercised in `Test.DifferentialPrivacy`; its arithmetic and generator are not part |
| 44 | +of the exact-real privacy guarantee. |
| 45 | + |
| 46 | +### Privacy of the programs |
| 47 | + |
| 48 | +The following proves privacy of the actual vector `rdo` sampler under adding or removing one |
| 49 | +record. `Mechanism.ofMeasure` only pairs the program with its proof of total probability one. |
| 50 | + |
| 51 | +```lean |
| 52 | +import RandomDo |
| 53 | +
|
| 54 | +open DifferentialPrivacy MeasureTheory |
| 55 | +open scoped NNReal |
| 56 | +
|
| 57 | +example {α : Type*} {d : ℕ} (f : α → EuclideanSpace ℝ (Fin d)) |
| 58 | + {D ε δ : ℝ≥0} (hD : HasDiameter f D) |
| 59 | + (hε : 0 < ε) (hδ : 0 < δ) (hδ1 : δ ≤ 1) : |
| 60 | + ApproxDP (Dataset.AtLeast 10 Dataset.AddRemove) ε δ |
| 61 | + (Mechanism.ofMeasure |
| 62 | + (gaussianMeanProgram (m := Measure) (fun a ↦ ⇑(f a)) D |
| 63 | + (gaussianNoiseMultiplier ε δ) 10) (fun _ ↦ inferInstance)) := |
| 64 | + gaussianMeanProgram_approxDP_addRemove hD (by norm_num) hε hδ hδ1 |
| 65 | +``` |
| 66 | + |
| 67 | +`gaussianMeanProgram_approxDP_replaceOne` covers replacement. The corresponding scalar theorems |
| 68 | +are prefixed `gaussianMeanRealProgram_approxDP`. Zero diameter is supported and requires no noise. |
| 69 | + |
| 70 | +For `ε > 0` and `0 < δ ≤ 1`, `gaussianNoiseMultiplier ε δ` supplies the multiplier: |
| 71 | + |
| 72 | +```text |
| 73 | +t = sqrt(2 log(1/δ)) |
| 74 | +c = (t + sqrt(t² + 2ε)) / (2ε) |
| 75 | +σ = c * D / n |
| 76 | +``` |
| 77 | + |
| 78 | +This sufficient calibration follows from a Gaussian Chernoff bound and works for every positive |
| 79 | +`ε`. The proof establishes the joint density ratio, a dimension-independent directional tail |
| 80 | +bound, and the DP event inequality. See |
| 81 | +[Dwork and Roth, Appendix A](https://www.cis.upenn.edu/~aaroth/Papers/privacybook.pdf) for the |
| 82 | +Gaussian privacy-loss argument; this calibration solves the Chernoff inequality directly. |
| 83 | + |
| 84 | +### Theory and assumptions |
| 85 | + |
| 86 | +- `Dataset α` is `List α`: finite sequences of arbitrary length, allowing repeated records. |
| 87 | +- `Dataset.AddRemove` inserts or removes one record at any position; `Dataset.ReplaceOne` |
| 88 | + replaces one record while preserving length. |
| 89 | +- `Mechanism X Y` maps inputs to `ProbabilityMeasure Y`. |
| 90 | +- `PureDP adj ε M` means `P(M x ∈ A) ≤ exp(ε) P(M x' ∈ A)` for adjacent inputs and |
| 91 | + measurable output events. |
| 92 | +- `ApproxDP adj ε δ M` adds `δ` to the right-hand side. Nonconstant Gaussian releases generally |
| 93 | + require this approximate notion. |
| 94 | + |
| 95 | +The theory includes measurable deterministic postprocessing, restriction of adjacency, |
| 96 | +adjacency-preserving input transformations, and monotonicity in privacy budgets. |
| 97 | + |
| 98 | +`HasDiameter f D` bounds all pairs of records in the public domain. For vectors, use an embedding |
| 99 | +into `EuclideanSpace ℝ (Fin d)` to express the ℓ₂ norm. A bound on each coordinate alone is not an |
| 100 | +ℓ₂ diameter bound. If both datasets have at least `n > 0` records, the empirical mean has |
| 101 | +sensitivity at most `D / n` under either adjacency relation. Inserting into a nonempty dataset |
| 102 | +has the sharper bound `D / (length + 1)`. |
| 103 | + |
| 104 | +The programs accept their parameters directly; the privacy theorems state the conditions on |
| 105 | +those parameters and the inputs. `n` and `D` must be public. Choosing the variance from the |
| 106 | +private dataset size or its observed diameter is not justified by these theorems. The real mean |
| 107 | +of an empty list is defined as zero, but the mean privacy theorems require nonempty datasets. |
| 108 | + |
| 109 | +Run the library, proofs, and execution checks with `lake build RandomDo Test`. |
0 commit comments