Expand description
Computable real numbers with provable correctness.
This crate provides a framework for exact real arithmetic using interval refinement. Numbers are represented as computations that can be refined to arbitrary precision while maintaining provably correct bounds.
§Architecture
The crate is organized into the following modules:
- [
binary]: Arbitrary-precision binary numbers (mantissa + exponent representation) - [
ordered_pair]: Interval types with bounds checking (Bounds, Interval) - [
error]: Error types for computable operations - [
node]: Computation graph infrastructure (Node, NodeOp traits) - [
ops]: Arithmetic and transcendental operations (add, mul, inv, sin, etc.) - [
refinement]: Parallel refinement infrastructure - [
computable]: The main Computable type
§Example
use computable::{Computable, Binary};
use num_bigint::{BigInt, BigUint};
// Create a constant
let x = Computable::constant(Binary::new(BigInt::from(2), BigInt::from(0)));
// Arithmetic operations
let y = x.clone() + x.clone();
let z = y * x;
// Get current bounds
let bounds = z.bounds().unwrap();Modules§
- binary_
utils - Utility functions and algorithms for working with Binary numbers.
- pi
- Pi computation using Machin’s formula with provably correct bounds.
Macros§
- assert_
sane_ computation_ size - Asserts that a computation size parameter (precision bits, term count, bit length, etc.) is within reasonable bounds for memory.
- detected_
computable_ with_ infinite_ value - Macro to flag unexpected but potentially valid extended reals cases.
- detected_
computable_ would_ exhaust_ memory - Macro to flag operations that would exhaust memory if attempted.
- sane_
arithmetic - Guards one or more
usizevariables and evaluates an arithmetic expression using checked arithmetic viaSane.
Structs§
- Binary
- Exact binary number represented as
mantissa * 2^exponent. - Computable
- A computable number backed by a shared node graph.
- Interval
- Stores two values ordered so that
large >= smallusing a lower bound and width. - Sane
- Newtype for checked arithmetic on computation-size values.
- UBinary
- Unsigned binary number represented as
mantissa * 2^exponentwhere mantissa >= 0.
Enums§
- Binary
Error - Errors that can occur during binary number operations.
- Computable
Error - Errors that can occur during computable operations and refinement.
- Interval
Error - UXBinary
- Extended unsigned binary number: either a finite nonnegative value or +infinity.
- XBinary
- Extended binary number: either a finite value or positive/negative infinity.
- XBinary
Error - Errors that can occur during extended binary operations.
- XUsize
- A
usizeextended with positive infinity, analogous toUXBinary.
Constants§
- DEFAULT_
INV_ MAX_ REFINES - DEFAULT_
MAX_ REFINEMENT_ ITERATIONS - MAX_
COMPUTATION_ BITS - Maximum reasonable computation size in bits. A computation requiring more than
~2^32 bits of precision would need ~512 MB just to store one number, and intermediate
results would require far more. Guaranteed
<= usize::MAXon all platforms.
Functions§
- pi
- Returns pi as a Computable that can be refined to arbitrary precision.
- pi_
bounds_ at_ precision - Returns bounds on pi with at least
precision_bitsbits of accuracy.
Type Aliases§
- Bounds
- Bounds on a computable number: lower and upper bounds as XBinary values. The width is stored as UXBinary to guarantee non-negativity through the type system.
- Finite
Bounds - Finite bounds on a value: lower and upper bounds as Binary values.