| Crates.io | amari-flynn |
| lib.rs | amari-flynn |
| version | 0.17.0 |
| created_at | 2025-11-21 22:57:13.530479+00 |
| updated_at | 2026-01-11 22:40:16.620939+00 |
| description | Probabilistic contracts and verification - named after Kevin Flynn's acceptance of spontaneous perfection |
| homepage | |
| repository | https://github.com/justinelliottcobb/Amari |
| max_upload_size | |
| id | 1944436 |
| size | 57,260 |
Probabilistic contracts and verification - named after Kevin Flynn's acceptance of spontaneous perfection.
amari-flynn implements probabilistic verification, distinguishing between impossible, rare, and emergent events. Named after Kevin Flynn from Tron: Legacy, who discovered that spontaneous, imperfect emergence (the ISOs) represented a form of perfection beyond rigid determinism.
This library embodies that philosophy: formal verification should prove what's impossible while allowing rare, emergent possibilities.
#[prob_requires], #[prob_ensures], #[ensures_expected]Add to your Cargo.toml:
[dependencies]
amari-flynn = "0.12"
[dependencies]
# Default features
amari-flynn = "0.12"
# Minimal, no-std compatible
amari-flynn = { version = "0.12", default-features = false }
use amari_flynn::prelude::*;
// Create probabilistic values
let coin_flip = Prob::with_probability(0.5, true);
// Sample from distributions
let die_roll = Uniform::new(1, 6).sample();
// Track rare events
let miracle_shot = RareEvent::<()>::new(0.001, "critical_hit");
Flynn teaches us to distinguish between three categories:
Impossible (P=0): Formally proven to never occur
Rare (0 < P << 1): Bounded probability, tracked and verified
Emergent (P > 0): Possible but not prescribed
use amari_flynn::prelude::*;
use amari_flynn_macros::{prob_requires, prob_ensures};
// Precondition: x > 0 holds with P ≥ 0.95
#[prob_requires(x > 0.0, 0.95)]
fn compute(x: f64) -> f64 {
x.sqrt()
}
// Postcondition: result is non-negative with P ≥ 0.99
#[prob_ensures(result >= 0.0, 0.99)]
fn safe_compute(x: f64) -> f64 {
x.abs()
}
use amari_flynn::prelude::*;
// Create verifier with 10,000 samples
let verifier = MonteCarloVerifier::new(10_000);
// Verify a probability bound
let result = verifier.verify_probability_bound(
|| rand::random::<f64>() > 0.9, // Event: random > 0.9
0.15, // Should occur with P ≤ 0.15
);
match result {
VerificationResult::Verified { .. } => println!("Bound verified!"),
VerificationResult::Failed { .. } => println!("Bound violated!"),
_ => {}
}
Probabilistic values with associated probability:
use amari_flynn::prelude::*;
// Value with 70% probability
let likely = Prob::with_probability(0.7, "success");
// Sample the value
if likely.sample() {
println!("Got: {}", likely.value());
}
use amari_flynn::prelude::*;
// Uniform distribution over [1, 6]
let die = Uniform::new(1, 6);
// Normal distribution N(0, 1)
let standard_normal = Normal::new(0.0, 1.0);
// Bernoulli with P(true) = 0.3
let coin = Bernoulli::new(0.3);
// Exponential with rate λ = 2.0
let waiting_time = Exponential::new(2.0);
Track events that should occur rarely:
use amari_flynn::prelude::*;
// Critical hit with 1% chance
let crit = RareEvent::<()>::new(0.01, "critical_hit");
// Network timeout with 0.1% chance
let timeout = RareEvent::<String>::new(0.001, "network_timeout");
| Module | Description |
|---|---|
prob |
Core Prob |
distributions |
Statistical distributions |
contracts |
ProbabilisticContract, RareEvent, VerificationResult |
backend |
Verification backends (Monte Carlo) |
statistical |
Statistical analysis utilities |
use amari_flynn::prelude::*;
// Verify critical hit rate is bounded
let crit_rate = 0.15;
let crit_prob = Prob::with_probability(crit_rate, ());
// Statistical verification that P(crit) ≤ 0.20
// (leaving room for buffs/modifiers while maintaining balance)
let verifier = MonteCarloVerifier::new(50_000);
let result = verifier.verify_probability_bound(
|| rand::random::<f64>() < crit_rate,
0.20, // upper bound
);
"The ISOs, they were a miracle. They weren't meant to be - they just were."
- Kevin Flynn
Like the ISOs in Tron: Legacy, the most valuable behaviors in a system are often those that emerge spontaneously, unpredicted by design. Flynn enables you to prove safety boundaries while preserving space for emergence.
Licensed under either of Apache License, Version 2.0 or MIT License at your option.
This crate is part of the Amari mathematical computing library.