Skip zero entries in fraction-free row elimination#3
Closed
adelaett wants to merge 1 commit into
Closed
Conversation
Store the tableau as Z.t numerators over one positive shared denominator d (cell value = entry/d) and pivot with Edmonds' fraction-free rule (a.(j) <- (a.(j)*p - a.(x)*row.(j)) / dprev, exact Z.divexact). This replaces the Q.t array array tableau whose numerators/denominators blew up and paid a GCD on every arithmetic op. The change is behaviour-preserving: every cell value is exactly Q.make entry d, so the Bland/max pivot sequence, verbose intermediate tableaux, and final rational answers are byte-identical (dune runtest passes with no golden regeneration). Selection compares signs (Z.sign) and ratios (Q.make b pv), both denominator-invariant since d > 0.
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.