pub struct Natural { /* private fields */ }Expand description
Natural number, specifically well-suited for counting satisfying assignments
When counting the number of satisfying assignments in a decision diagram, the numbers often have many trailing zeros (in binary representation). Based on this observation, we decompose numbers as m × 2^e with a mantissa m and an exponent e. We require that both m and e are natural numbers. Further, m is odd unless the represented number is zero, in which case both m and e are zero.
The exponent e is stored as a u64 and the mantissa m as an array of
u64 “digits.” In case m fits into a single u64 digit, m is
stored inline, i.e., without any heap allocation.
Conceptually, this type is similar to arbitrary precision floats. However, we do not require the user to choose the precision, instead we always represent numbers exactly.
To account for computation errors (e.g., an exponent that cannot be
represented as a u64). this type includes a NaN value. It is undefined
if this value is larger or smaller than actual natural numbers. Therefore,
this type does not implement Ord but only PartialOrd.
Also note that the implementation of Shr is tailored to the application
in counting satisfying assignments, where it is used as an exact division by
(a power of) two. If a 1-bit would get lost by a shift to the right, i.e.,
the division result would not be exact, the computation result is NaN to
make the error obvious. A context for such an error may be pretending that a
Boolean function has a smaller domain than it actually has.
Implementations§
Source§impl Natural
impl Natural
Sourcepub fn from_le_digits(digits: &[u64]) -> Self
pub fn from_le_digits(digits: &[u64]) -> Self
Create a Natural from a sequence of digits
Here, le stands for little endian, i.e., the first element of
digits is the least significant digit.
Trait Implementations§
impl Eq for Natural
Source§impl IsFloatingPoint for Natural
cbindgen:ignore
impl IsFloatingPoint for Natural
cbindgen:ignore
Source§const FLOATING_POINT: bool = false
const FLOATING_POINT: bool = false
true iff the underlying type is a floating point numberSource§const MIN_EXP: i32 = 0
const MIN_EXP: i32 = 0
f64::MIN_EXP for instance. 0 for integers