Expand description
Compile and run Probl programs from Rust.
Probl is a small language for explicit random choices and weighted worlds:
a draw explores its outcomes, each in a world of its own, weighted by how
likely it is, and a report collects what the worlds say. This crate is
its supported API; the command line (probl-cli) and the playground are
built on it.
let source = "let a ~ d6\nlet b ~ d6\nreport a + b >= 10 as \"ten or more\"";
let program = probl::compile("dice.probl", source)?;
let outcome = program.run(&probl::Options::new())?;
let ten = outcome.report("ten or more").unwrap().groups()[0].probability().unwrap();
assert!((ten.point().unwrap() - 6.0 / 36.0).abs() < 1e-12);
assert!(ten.is_complete());
assert_eq!(outcome.text(), "enumerated\n\nten or more 16.67%\n");A run’s Outcome has its text, as probl run prints
it, and each report’s numbers, with what’s known about their accuracy:
whether unresolved weight affects them, their bounds, and when sampling,
their Monte Carlo error. A program that reads data has it loaded first,
with Program::load, from Files the host chooses.
The crates probl-syntax, probl-sema and probl-engine are internal:
their APIs change with every release.
Structs§
- Assertion
Result - Cancel
- Stops a run, or the loading of data, from another thread. Clones share the same switch.
- Confidence
Interval - Data
- A program’s data, read by
Program::load. It can be given to any number of runs of that program. - Data
Source - A file, or standard input, that was read: what results were computed from.
- Date
- A calendar date, from 0001-01-01 to 9999-12-31. It prints, and parses,
as
YYYY-MM-DD. - Date
Time - A calendar datetime with nanosecond precision, normalized to UTC when an input includes an offset. No timezone metadata is retained.
- Diagnostic
- An error or a warning about a place in a program. It keeps the program’s source, so it can render itself.
- Error
- A problem compiling a program, loading its data or running it.
- Estimate
- One reported quantity, such as a probability or a mean, with what’s known about its accuracy.
- Evidence
- The evidence: the probability (or density) of what the program observed, as a natural logarithm, so that tiny likelihoods don’t underflow.
- Exact
Updates - How one variable’s draws were delayed and updated exactly, over all the runs.
- Failed
Run - The sampled run in which a fault stopped the program.
- Failure
- The worlds of a partial run that failed at one place, with one kind of fault (docs/semantics.md, section 11).
- Fault
Context - What a fault that stopped a run says about itself: the failing
operation’s inputs, and how often it fails. Every part is optional: an
absent one couldn’t be established, which doesn’t mean zero. Its
Error’s diagnostic has the same as a note. - Fault
Input - An input of a failing operation, in a
FaultContext. - Group
- What a report saw for one key.
- Interval
- A range of numbers, both ends included.
- Limits
- Upper bounds on what a run, and the loading of its data, may do. A
program’s
@max_worldsand@max_iterationscan lower them, never raise them. The default is the command line’s; change a field to change one: - Local
Files - Local files, for someone running their own programs: the program is trusted, but not with anything but files.
- Local
Sources - Files on disk: a file imports another relative to its own directory.
A path must end in
.probl. A file’s identity is its canonical path, so a file reached through a link or by another relative path is the same file. LikeLocalFiles, this follows the local file system’s rules; it isn’t a sandbox. - Memory
Files - Files given as bytes, by the path a program reads them with. There’s no standard input.
- Memory
Sources - Files given as text, by their paths, with
/between directories. A file imports another relative to its own directory, as on disk. - Numeric
Summary - The summaries of real numbers, or of continuous values.
- Options
- How to run a program. Every setting is optional:
- Outcome
- What a run gives back.
- Parse
Date Error - A date that isn’t
YYYY-MM-DD, or is out of range. - Parse
Date Time Error - Program
- A compiled program. Cloning it is cheap, and it can run any number of times, from any thread.
- Quantile
Approximation - Retention/accuracy metadata, separate from Monte Carlo sampling uncertainty. Capacity controls space and measured accuracy, not a guaranteed rank error. More fields may be added, so it’s only constructed by Probl.
- Report
- One
report: what it saw, for each of its keys. - Report
Collection Error - A collection policy that doesn’t parse, or names an invalid capacity.
- Report
Summary - Checked, ordered summary columns. Empty selections, duplicates, more than 32 columns and nonfinite/out-of-range quantiles are rejected.
- Report
Summary Error - Sampling
- How a program was sampled.
- Sampling
Uncertainty - A sampled quantity’s Monte Carlo error.
- Snapshots
- Another
Files, keeping the bytes of everything it has read, so that reading it again gives the same data untilclear. The REPL keeps its data this way: it runs a session whose program changes with every input, and earlier bindings mustn’t change under it. - Source
Text - An imported file’s text, with its identity and the name diagnostics give it.
- Stats
- How much work the engine did.
- Test
Case - One independent test, including its compile error if only this test could not be compiled. Other tests in the suite remain executable.
- Test
Result - Test
Suite - Unresolved
- The weight that loops and limits cut off before it finished: an unnormalized bound, not a probability. When sampling, it’s per run.
Enums§
- Confidence
Method - Error
Kind - What kind of problem an
Erroris. - Evidence
Kind - What kind of number the evidence is.
- Failure
Mode - What a fault in one world, like a division by zero, does to the others (docs/semantics.md, section 11). The world that fails always stops there.
- Mode
- How a program runs: its
@mode, or whatOptionschoose instead. - Report
Collection - What a report retains. Exact collection is the default. More policies may be added, so matches outside this crate need a wildcard arm.
- Report
Statistic - One requested report column. A median uses midpoint ties; a quantile uses the weighted inverse CDF, including at level 0.5. More statistics may be added, so matches outside this crate need a wildcard arm.
- Sampling
Status - What’s known about a sampled quantity’s Monte Carlo error.
- Severity
- How serious a
Diagnosticis. - Summary
Error - Why
NumericSummary::quantilegave no quantile. - Test
Status
Constants§
- VERSION
- This version of Probl.
Traits§
- Files
- Where
read("…")finds data. A program only names paths: what they refer to, and whether they may be read at all, is the host’s to decide, and a program can’t widen it. - Sources
- Where the files a program imports come from. A program only names paths: what they refer to, and whether they may be read at all, is the host’s to decide.
Functions§
- compile
- Compile a program.
nameis what its diagnostics call it, such as its file’s name. Warnings come with the program; errors come instead of it, as an error of kindCompile. - compile_
tests - Compile explicit test syntax. Ordinary
compilenever enables it based on a filename. A suite owns its source snapshot; executing it doesn’t reload modules. - compile_
with - Compile a program that may import files, from
sources.nameis what its diagnostics call the entry file, and whatsourcesresolves its imports against. Each file the program imports is read once, and each diagnostic says whichfileit’s about.