merge: invariants docs

This commit is contained in:
NunoSempere 2022-04-12 20:32:24 -04:00
commit f3a73a9147
6 changed files with 47 additions and 42 deletions

View File

@ -7,11 +7,10 @@ nix-build
o result/property-tests.pdf
```
Without `nix`, you can install `pandoc` yourself and run
```sh
pandoc -s property-tests.md -o property-tests.pdf
```
Without `nix`, you can install `pandoc` and `pdflatex` yourself and see `make.sh` for the rendering command.
## _Details_
The `property-tests.pdf` document is _normative and aspirational_. It does not document tests as they exist in the codebase, but somewhat represents how we think squiggle ought to be tested.
The `invariants.pdf` document is _normative and aspirational_. It does not document tests as they exist in the codebase, but represents how we think squiggle ought to be tested.
We are partially bottlenecked by the rescript ecosystem's maturity with respect to property-based testing.

View File

@ -3,31 +3,24 @@
}:
# Style sheets https://github.com/citation-style-language/styles/
with pkgs;
let deps = [
# (texlive.combine
# { inherit (texlive)
# scheme-small thmtools datetime xpatch fmtcount;
# }
# )
haskellPackages.pandoc
];
in
stdenv.mkDerivation {
name = "render_squiggle_properties";
src = ./.;
buildInputs = deps;
buildPhase = ''
echo rendering...
pandoc \
--from markdown \
--to latex \
--out properties.pdf \
--pdf-engine xelatex \
properties.md \
echo rendered.
pandoc
(texlive.combine
{ inherit (texlive) scheme-small datetime; }
)
]; in
stdenv.mkDerivation {
name = "render_squiggle_properties";
src = ./.;
buildInputs = deps;
buildPhase = ''
echo rendering...
pandoc -s invariants.md -o invariants.pdf
echo rendered.
'';
installPhase = ''
mkdir -p $out
cp invariants.pdf $out/invariants.pdf
'';
installPhase = ''
mkdir -p $out
cp properties.pdf $out/properties.pdf
'';
}
}

View File

@ -1,38 +1,51 @@
# Property tests for squiggle
# Squiggle invariants
Here are some property tests for squiggle. I am testing mostly for the mean and the standard deviation. I know that squiggle doesn't yet have functions for the standard deviation, but they could be added.
The keywords to search for are "[algebra of random variables](https://wikiless.org/wiki/Algebra_of_random_variables?lang=en)".
## Sums
## Means and standard deviations
### Sums
$$ mean(f+g) = mean(f) + mean(g) $$
$$ Std(f+g) = sqrt(std(f)^2 + std(g)^2) $$
$$ std(f+g) = \sqrt{std(f)^2 + std(g)^2} $$
In the case of normal distributions,
$$ normal(a,b) + normal(c,d) = normal(a+c, sqrt(b^2 + d^2) $$
$$ mean(normal(a,b) + normal(c,d)) = mean(normal(a+c, \sqrt{b^2 + d^2})) $$
## Substractions
### Subtractions
$$ mean(f-g) = mean(f) - mean(g) $$
$$ std(f-g) = sqrt(std(f)^2 + std(g)^2) $$
$$ std(f-g) = \sqrt{std(f)^2 + std(g)^2} $$
## Multiplications
### Multiplications
$$ mean(f \cdot g) = mean(f) \cdot mean(g) $$
$$ std(f \cdot g) = sqrt( (std(f)^2 + mean(f)) \cdot (std(g)^2 + mean(g)) - (mean(f) \cdot mean(y))^2) $$
$$ std(f \cdot g) = \sqrt{ (std(f)^2 + mean(f)) \cdot (std(g)^2 + mean(g)) - (mean(f) \cdot mean(g))^2} $$
## Divisions
### Divisions
Divisions are tricky, and in general we don't have good expressions to characterize properties of ratios. In particular, the ratio of two normals is a Cauchy distribution, which doesn't have to have a mean.
## To do:
# To do:
- Provide sources or derivations, useful as this document becomes more complicated
- Provide definitions for the probability density function, exponential, inverse, log, etc.
- Provide at least some tests for division
- See if playing around with characteristic functions turns out anything useful
## Probability density functions
TODO
## Cumulative density functions
TODO
## Inverse cumulative density functions
TODO

View File

@ -1 +1 @@
pandoc -s property-tests.md -o property-tests.pdf
pandoc -s invariants.md -o invariants.pdf