diff --git a/packages/squiggle-lang/__tests__/docs/README.md b/packages/squiggle-lang/__tests__/docs/README.md index 1dca1162..f3ef1041 100644 --- a/packages/squiggle-lang/__tests__/docs/README.md +++ b/packages/squiggle-lang/__tests__/docs/README.md @@ -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. diff --git a/packages/squiggle-lang/__tests__/docs/default.nix b/packages/squiggle-lang/__tests__/docs/default.nix index 5a18efd3..37a0e3aa 100644 --- a/packages/squiggle-lang/__tests__/docs/default.nix +++ b/packages/squiggle-lang/__tests__/docs/default.nix @@ -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 - ''; - } +} diff --git a/packages/squiggle-lang/__tests__/docs/invariants-apr12.pdf b/packages/squiggle-lang/__tests__/docs/invariants-apr12.pdf new file mode 100644 index 00000000..4077a490 Binary files /dev/null and b/packages/squiggle-lang/__tests__/docs/invariants-apr12.pdf differ diff --git a/packages/squiggle-lang/__tests__/docs/property-tests.md b/packages/squiggle-lang/__tests__/docs/invariants.md similarity index 65% rename from packages/squiggle-lang/__tests__/docs/property-tests.md rename to packages/squiggle-lang/__tests__/docs/invariants.md index aacf25fd..d9e95b5f 100644 --- a/packages/squiggle-lang/__tests__/docs/property-tests.md +++ b/packages/squiggle-lang/__tests__/docs/invariants.md @@ -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 \ No newline at end of file diff --git a/packages/squiggle-lang/__tests__/docs/make.sh b/packages/squiggle-lang/__tests__/docs/make.sh index 58fbc3aa..7d5a4333 100755 --- a/packages/squiggle-lang/__tests__/docs/make.sh +++ b/packages/squiggle-lang/__tests__/docs/make.sh @@ -1 +1 @@ - pandoc -s property-tests.md -o property-tests.pdf + pandoc -s invariants.md -o invariants.pdf diff --git a/packages/squiggle-lang/__tests__/docs/property-tests.pdf b/packages/squiggle-lang/__tests__/docs/property-tests.pdf deleted file mode 100644 index 3bca9795..00000000 Binary files a/packages/squiggle-lang/__tests__/docs/property-tests.pdf and /dev/null differ