Skip to main content

Crate computable

Crate computable 

Source
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 usize variables and evaluates an arithmetic expression using checked arithmetic via Sane.

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 >= small using a lower bound and width.
Sane
Newtype for checked arithmetic on computation-size values.
UBinary
Unsigned binary number represented as mantissa * 2^exponent where mantissa >= 0.

Enums§

BinaryError
Errors that can occur during binary number operations.
ComputableError
Errors that can occur during computable operations and refinement.
IntervalError
UXBinary
Extended unsigned binary number: either a finite nonnegative value or +infinity.
XBinary
Extended binary number: either a finite value or positive/negative infinity.
XBinaryError
Errors that can occur during extended binary operations.
XUsize
A usize extended with positive infinity, analogous to UXBinary.

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::MAX on 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_bits bits 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.
FiniteBounds
Finite bounds on a value: lower and upper bounds as Binary values.