uncertain-rs
A Rust library for uncertainty-aware programming, implementing the approach from "Uncertain: A First-Order Type for Uncertain Data" by Bornholt, Mytkowicz, and McKinley.
Core Concept: Evidence-Based Conditionals
Instead of treating uncertain data as exact values (which leads to bugs), this library uses evidence-based conditionals that account for uncertainty:
use Uncertain;
// Create uncertain values from probability distributions
let speed = normal; // GPS reading with ±5 mph error
// Evidence-based conditional (returns Uncertain<bool>)
let speeding_evidence = speed.gt;
// Convert evidence to decision with confidence level
if speeding_evidence.probability_exceeds
Features
- Evidence-based conditionals: Comparisons return evidence, not boolean facts
- Uncertainty propagation: Arithmetic operations preserve uncertainty
- Lazy evaluation: Computation graphs built lazily for efficiency
- Graph optimization: Common subexpression elimination and caching for performance
- SPRT hypothesis testing: Sequential Probability Ratio Test for optimal sampling
- Rich distributions: Normal, uniform, exponential, binomial, categorical, etc.
- Statistical analysis: Mean, std dev, confidence intervals, CDF, etc.
Installation
Add this to your Cargo.toml:
[]
= "0.1.0"
Quick Start
use Uncertain;
For more examples, see the examples directory.
Advanced Features
Graph Optimization
The library includes a computation graph optimizer that can eliminate common subexpressions and improve performance:
use ;
// Create an expression with common subexpressions
let x = normal;
let y = normal;
let z = normal;
// Expression: (x + y) * (x + y) + (x + y) * z
// The subexpression (x + y) appears 3 times
let sum = x.clone + y.clone;
let expr = + ;
// Apply optimization to eliminate common subexpressions
let mut optimizer = new;
let optimized = optimizer.eliminate_common_subexpressions;
// The optimized graph reuses the (x + y) subexpression
println!;
Development Workflow
We use just as a task runner. Available commands:
just fmt- Format codejust lint- Run clippy lintingjust test- Run testsjust audit- Security audit (check for vulnerabilities)just dev- Run the full development workflow (format + lint + test + audit)
Security
This project takes security seriously. We run cargo audit to check for known vulnerabilities in dependencies:
- CI: Automated security audits run on every push and PR
- Local: Run
just auditorcargo auditbefore submitting changes - Installation: If you don't have
cargo-audit, runcargo install cargo-audit
The security audit checks all dependencies against the RustSec Advisory Database.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
This project is licensed under the MIT License - see the LICENSE file for details.