Skip to content

perf: integer-only Bareiss determinant (BigInt path) #64

@acgetchell

Description

@acgetchell

Summary

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.

Proposed Changes

Since every finite f64 is exactly m × 2^e:

  1. Decompose each matrix entry into (mantissa: BigInt, exponent: i16) using the IEEE 754 representation (reusing the decomposition from perf: custom f64 → BigRational conversion via mantissa/exponent decomposition #63)
  2. Find the minimum exponent e_min across all entries
  3. Scale all entries to BigInt: entry_int = mantissa × 2^(e - e_min)
  4. Run the Bareiss algorithm entirely in BigInt arithmetic:
    a[i][j] = (&a[k][k] * &a[i][j] - &a[i][k] * &a[k][j]) / &prev_pivot;
    The division is exact integer division (Bareiss guarantees divisibility)
  5. 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestperformancePerformance related issuesrustPull requests that update rust code

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions