Skip zero entries in fraction-free row elimination#4
Merged
Conversation
The exact-rational tableaux are 65-80% zero mid-solve (much sparser than the ~50% assumed when ff_eliminate was written): measured 55-67% of all inner-loop cell visits have both the row entry a.(j) and the pivot-row entry row.(j) equal to zero. For those cells the new value aj*p - ac*r is identically zero (and divexact 0 = 0), so the old code was spending two bignum multiplies, a subtraction and an exact division to recompute a zero. Short-circuit on a.(j) = 0 in every branch of ff_eliminate: - both a.(j) and row.(j) zero -> leave the cell zero, no work at all; - only a.(j) zero -> value is -ac*row.(j) (drop the aj*p product); - only row.(j) zero -> value is aj*p (unchanged fast path). Each simplified numerator is still the full Bareiss numerator for that cell, so the exact /dprev division stays valid and every result is bit-identical. dune runtest passes with no golden changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Short-circuit zero cells in
ff_eliminate(the fraction-free pivot inner loop).Why
I measured cell-level statistics for the inner loop on the benchmark corpus and found these exact-rational tableaux are 65–80% zero mid-solve — much sparser than the ~50% assumed when
ff_eliminatewas written. Concretely, 55–67% of all inner-loop cell visits have botha.(j)=0and the pivot-row entryrow.(j)=0. For those cells the new valuea.(j)*p - ac*row.(j)is identically zero (andZ.divexact 0 dprev = 0), yet the old code spent two bignum multiplies, a subtraction and an exact division to recompute a zero.How
Add an
a.(j)=0short-circuit to every branch offf_eliminate:a.(j)androw.(j)zero → leave the cell zero, no work at all (the dominant case);a.(j)zero → value is-ac*row.(j)(drop the vanishinga.(j)*pproduct);row.(j)zero → value isa.(j)*p(the existing fast path).Each simplified expression is still the full Bareiss numerator for that cell (the dropped term is provably zero), so the exact
/dprevdivision stays valid and every result is bit-identical.dune runtestpasses with no golden changes.Result
Benchmark harness (
bench/evaluate.py --baseline main --candidate <branch> --rule bland --trials 30), correctness-checked against the GLPK + Gurobi oracle consensus:rand_25x6016.5ms → 14.6ms; best instancedegen_141.31×This lands on top of the fraction-free + pricing + phase-1 work already merged in #2.