You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add an integer-only Bareiss determinant path that operates entirely in BigInt arithmetic, eliminating denominator growth and rational normalization during elimination.
Current State
bareiss_det operates on BigRational values. Even though Bareiss is fraction-free, intermediate values still carry denominators (from the initial f64 → rational conversion), and every arithmetic operation may trigger GCD normalization.
The division is exact integer division (Bareiss guarantees divisibility)
The result is a BigInt determinant scaled by 2^(D × e_min)
To recover the BigRational determinant: det = det_int / 2^(D × (-e_min)) (or det_int × 2^(D × e_min) if e_min ≥ 0).
For det_sign_exact
Only the sign is needed — the scale factor is always positive, so det_sign = det_int.sign().
For gauss_solve
The solve path can also benefit from integer-only forward elimination, but the back-substitution produces rationals. Consider a hybrid: integer forward elimination + rational back-substitution.
Benefits
No denominator tracking or GCD reductions during the entire elimination
BigInt multiplication is faster than BigRational multiplication
Integer division (exact) is faster than rational division
Significant speedup for near-degenerate cases where BigRational denominators grow large
Implementation Notes
num-bigint provides BigInt which supports all required operations
Exact integer division: use / operator (Bareiss guarantees divisibility) or div_exact if available
Summary
Add an integer-only Bareiss determinant path that operates entirely in
BigIntarithmetic, eliminating denominator growth and rational normalization during elimination.Current State
bareiss_detoperates onBigRationalvalues. Even though Bareiss is fraction-free, intermediate values still carry denominators (from the initial f64 → rational conversion), and every arithmetic operation may trigger GCD normalization.Proposed Changes
Since every finite f64 is exactly
m × 2^e:(mantissa: BigInt, exponent: i16)using the IEEE 754 representation (reusing the decomposition from perf: custom f64 → BigRational conversion via mantissa/exponent decomposition #63)e_minacross allD²entriesBigInt:entry_int = mantissa × 2^(e - e_min)BigIntarithmetic:BigIntdeterminant scaled by2^(D × e_min)To recover the
BigRationaldeterminant:det = det_int / 2^(D × (-e_min))(ordet_int × 2^(D × e_min)ife_min ≥ 0).For
det_sign_exactOnly the sign is needed — the scale factor is always positive, so
det_sign = det_int.sign().For
gauss_solveThe solve path can also benefit from integer-only forward elimination, but the back-substitution produces rationals. Consider a hybrid: integer forward elimination + rational back-substitution.
Benefits
BigIntmultiplication is faster thanBigRationalmultiplicationImplementation Notes
num-bigintprovidesBigIntwhich supports all required operations/operator (Bareiss guarantees divisibility) ordiv_exactif available[[BigInt; D]; D]