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
Apply the integer-only Bareiss approach from #64 to the forward elimination phase of gauss_solve, while keeping rational back-substitution. This hybrid avoids BigRational GCD overhead during the most expensive phase of the solve.
Current State
gauss_solve operates entirely in BigRational: D² matrix entries + D RHS entries are converted via f64_to_bigrational, then standard Gaussian elimination with rational division + back-substitution produces the exact solution.
With #64 merged, the determinant path runs ~16–40x faster using pure BigInt. The solve path is unchanged (solve_exact benchmarks show 1.00x).
Proposed Changes
Hybrid integer/rational solve
Forward elimination in BigInt: decompose matrix and RHS into mantissa × 2^exponent, find e_min, scale to integers, run elimination with exact integer division (same approach as bareiss_det_int)
Back-substitution in BigRational: after forward elimination, convert the upper-triangular BigInt matrix + RHS back to BigRational for back-substitution (which inherently produces fractions)
Design considerations
The RHS vector has its own exponents — need to track a separate e_min_rhs or a unified minimum across matrix + RHS
Row swaps must keep the RHS in sync (same as current code)
The pivot division in forward elimination is factor = mat[i][k] / pivot — in the integer path this becomes the Bareiss-style (pivot * a[i][j] - a[i][k] * a[k][j]) / prev_pivot pattern
Back-substitution: x[i] = (rhs[i] - sum) / mat[i][i] — this division is generally not exact in integers, so BigRational is needed here
Benefits
Eliminates GCD normalization during forward elimination (the O(D³) phase)
Back-substitution is only O(D²) — rational overhead is acceptable there
Expected speedup: significant for D=4–5 where forward elimination dominates
Reuse f64_decompose and the exponent-scaling pattern from bareiss_det_int
The current gauss_solve uses standard Gaussian elimination (not Bareiss) — the hybrid would switch forward elimination to Bareiss-style fraction-free form
All existing solve_exact and solve_exact_f64 tests must continue to pass
Summary
Apply the integer-only Bareiss approach from #64 to the forward elimination phase of
gauss_solve, while keeping rational back-substitution. This hybrid avoidsBigRationalGCD overhead during the most expensive phase of the solve.Current State
gauss_solveoperates entirely inBigRational: D² matrix entries + D RHS entries are converted viaf64_to_bigrational, then standard Gaussian elimination with rational division + back-substitution produces the exact solution.With #64 merged, the determinant path runs ~16–40x faster using pure
BigInt. The solve path is unchanged (solve_exactbenchmarks show 1.00x).Proposed Changes
Hybrid integer/rational solve
BigInt: decompose matrix and RHS into mantissa × 2^exponent, finde_min, scale to integers, run elimination with exact integer division (same approach asbareiss_det_int)BigRational: after forward elimination, convert the upper-triangularBigIntmatrix + RHS back toBigRationalfor back-substitution (which inherently produces fractions)Design considerations
e_min_rhsor a unified minimum across matrix + RHSfactor = mat[i][k] / pivot— in the integer path this becomes the Bareiss-style(pivot * a[i][j] - a[i][k] * a[k][j]) / prev_pivotpatternx[i] = (rhs[i] - sum) / mat[i][i]— this division is generally not exact in integers, soBigRationalis needed hereBenefits
Implementation Notes
f64_decomposeand the exponent-scaling pattern frombareiss_det_intgauss_solveuses standard Gaussian elimination (not Bareiss) — the hybrid would switch forward elimination to Bareiss-style fraction-free formsolve_exactandsolve_exact_f64tests must continue to pass