| Crates.io | uncertain-rs |
| lib.rs | uncertain-rs |
| version | 0.2.0 |
| created_at | 2025-07-27 12:04:08.839448+00 |
| updated_at | 2025-09-24 18:46:24.471903+00 |
| description | A Rust library for uncertainty-aware programming, implementing the approach from 'Uncertain |
| homepage | https://github.com/minikin/uncertain-rs |
| repository | https://github.com/minikin/uncertain-rs |
| max_upload_size | |
| id | 1769967 |
| size | 367,380 |
A Rust library for uncertainty-aware programming, implementing the approach from
"Uncertain
Instead of treating uncertain data as exact values (which leads to bugs), this library uses evidence-based conditionals that account for uncertainty:
use uncertain_rs::Uncertain;
// Create uncertain values from probability distributions
let speed = Uncertain::normal(55.2, 5.0); // GPS reading with ±5 mph error
// Evidence-based conditional (returns Uncertain<bool>)
let speeding_evidence = speed.gt(60.0);
// Convert evidence to decision with confidence level
if speeding_evidence.probability_exceeds(0.95) {
// Only act if 95% confident
println!("Issue speeding ticket");
}
Add this to your Cargo.toml:
[dependencies]
uncertain-rs = "0.1.0"
use uncertain_rs::Uncertain;
fn main() {
// Create uncertain values
let x = Uncertain::normal(5.0, 1.0);
let y = Uncertain::normal(3.0, 0.5);
// Perform arithmetic operations
let sum = x.clone() + y.clone();
let product = x * y;
// Sample from the distributions
println!("Sum sample: {}", sum.sample());
println!("Product sample: {}", product.sample());
// Statistical analysis
println!("Sum mean: {}", sum.expected_value(1000));
println!("Sum std dev: {}", sum.standard_deviation(1000));
}
For more examples, see the examples directory.
The library includes a computation graph optimizer that can eliminate common subexpressions and improve performance:
use uncertain_rs::{Uncertain, computation::GraphOptimizer};
// Create an expression with common subexpressions
let x = Uncertain::normal(2.0, 0.1);
let y = Uncertain::normal(3.0, 0.1);
let z = Uncertain::normal(1.0, 0.1);
// Expression: (x + y) * (x + y) + (x + y) * z
// The subexpression (x + y) appears 3 times
let sum = x.clone() + y.clone();
let expr = (sum.clone() * sum.clone()) + (sum * z);
// Apply optimization to eliminate common subexpressions
let mut optimizer = GraphOptimizer::new();
let optimized = optimizer.eliminate_common_subexpressions(expr.into_computation_node());
// The optimized graph reuses the (x + y) subexpression
println!("Cache size: {}", optimizer.subexpression_cache.len());
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)This project takes security seriously. We run cargo audit to check for known vulnerabilities in dependencies:
just audit or cargo audit before submitting changescargo-audit, run cargo install cargo-auditThe security audit checks all dependencies against the RustSec Advisory Database.
Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the MIT License - see the LICENSE file for details.