Repository navigation
Speed up the lifting of rational parametrizations over QQ - #384
Open
mohabsafey wants to merge 9 commits into
Open
mohabsafey wants to merge 9 commits into
mohabsafey wants to merge 9 commits into
Conversation
Rational reconstruction in the lifting of rational parametrizations over QQ (linear forms, multiplication matrix witnesses, trace and determinant, eliminating polynomial and coordinates) now goes through FLINT's half-gcd based fmpq_reconstruct_fmpz_2 instead of the quadratic Euclidean algorithm, falling back to ratrecon/ratreconwden when the bounds do not satisfy 2ND < m. The wrappers introduced for the lifting of Groebner bases are moved from lifting-gb.c to lifting.c so that both liftings share them. Outputs are unchanged; the time spent in CRT and rational reconstruction decreases by 25 to 40% (kat11: 1.22s to 0.70s). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
When lifting rational parametrizations over QQ, rational reconstruction was called every nbdoit iterations, nbdoit being doubled whenever the reconstruction took more than 20% of the modular computations; the number of primes used thus depended on timings and on the machine load. As for the lifting of Groebner bases, the period is now rr primes, rr being the largest power of 2 <= nprimes/128, i.e. max(1, rr/nthrds) iterations, and the reconstruction is attempted once per iteration, after the last good prime, instead of after each prime of the iteration. Outputs are unchanged and the number of primes is now reproducible. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
When lifting rational parametrizations over QQ, every coefficient of the eliminating polynomial and of the coordinates was lifted by incremental CRT at each prime, which is quadratic in the number of primes, although these CRT images are only used once the trace and determinant witnesses are reconstructed and verified. The modular images of the parametrization are now stored for each prime (in chunks of 64 primes which are never moved), and FLINT's multi-CRT is applied to them only when a rational reconstruction is attempted, one coefficient at a time, right before this coefficient is reconstructed; no CRT is thus applied beyond the first failed reconstruction, and no array of CRT images is kept. The coordinates are lifted one at a time, trying in turn the three bounds which were tried before on all of them. The witnesses are still lifted by incremental CRT. Outputs and numbers of primes are unchanged on 38 benchmark systems (eco, kat, noon, cyclic, henrion, chandra, random, minrank, cp_d, crit and others). The time spent in CRT and rational reconstruction decreases by up to 4.2x (random2_9_9: 20.4s to 4.8s; chandra-11: 50.7s to 14.5s), the total time by up to 17% with one thread and by up to 32% with four, and peak memory is unchanged or slightly lower. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
As for the lifting of Groebner bases, the rational reconstruction bounds used when lifting parametrizations over QQ (witnesses, eliminating polynomial and coordinates) are now computed from modulus / 2^RR_MARGIN instead of the modulus, so that 2ND <= modulus / 2^16. This makes spurious reconstructions unlikely: on cyclic7, two spurious reconstructions of the eliminating polynomial, each rejected by the next prime, are avoided. Outputs are unchanged on 35 benchmark systems; the number of primes increases by 0 to 4 on all of them but random2_9_9 (2627 to 2643, the reconstruction period being 16 primes at that point) and cyclic7 (194 to 193). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
When lifting parametrizations over QQ, each coefficient of the eliminating polynomial and of the coordinates is now reconstructed by trying in turn the fixed bounds used so far (D = M^(1/16) for the eliminating polynomial; D = M^(1/32), balanced bounds and N = M^(1/16) for the coordinates, with M = modulus / 2^RR_MARGIN), then the bounds set from the denominator accumulated so far, g: D = sqrt(M / g) and N = M / D, as for the lifting of Groebner bases. CRT is applied only once per coefficient. Previously, each fixed bound had to succeed on a whole coordinate. Using only the bounds set from the guessed denominator increases the number of primes by up to 1.9x on several families (eco, noon, henrion, cyclic), whose numerators are much larger than their denominators; the fixed bounds are thus tried first. Outputs are unchanged on 35 benchmark systems and the number of primes never increases. It decreases on KLYZ22 (279 to 225, 18% faster), whose denominators are large, and on the smallest Katsura systems, where some coordinates were lifted later than the eliminating polynomial because no single fixed bound suited all their coefficients (kat8: 22 to 16, kat9: 40 to 31, about 20% faster). From kat10 to kat12 all coordinates are lifted together with the eliminating polynomial, which is the bottleneck, so the number of primes and timings are unchanged (kat12: 323 primes, 325s vs 321s); the same holds for eco8 to eco12, where the fixed bounds always succeed and the fallback is never used. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
mulmat_reconstruct allocated ncols integers for the row denominators but cleared only nrows of them, leaking ncols - nrows integers at each call when multiplication matrices are lifted (-L 1). Also remove twelve static functions of lifting.c which are no longer called: the former lifting of multiplication matrices (crt_mpz_matfglm_*, mpz_matfglm_*, mpq_matfglm_*, crt_lift_mat, rat_recon_matfglm, check_matrix_and_linear_forms), replaced by mulmat_reconstruct, as well as old_rat_recon_trace_det and check_linear_forms. The corresponding types are kept in msolve-data.h, which is installed. Outputs are unchanged, with and without -L 1. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…nator The coefficients of the monic eliminating polynomial share a common denominator (the leading coefficient of the primitive integer polynomial). On dense random, MinRank and critical point systems, this denominator is about as large as the numerators, so reconstructing a single witness coefficient (trace or determinant) needs about twice the number of bits of these numerators, and the eliminating polynomial cannot be attempted before. Four witness coefficients (the trace and determinant ones, and the first nonzero ones from degrees nsols/2 and nsols/4) are now also reconstructed simultaneously: a short vector (d, n_1, .., n_4) with n_j = d u_j mod m is computed by LLL (FLINT's fmpz_lll), which needs about bits(n) + bits(d) / 4 bits of modulus. The candidate is accepted when its entries are below 2^(4 bits(m) / 5 - RR_MARGIN) and when it matches the images of the next prime; d is then used as a guess for the eliminating polynomial, which can then be reconstructed with its usual bounds. As LLL is more expensive than rational reconstruction, it is tried only while no single witness is known, at 16 primes and then each time the number of primes grows by 5%. Outputs are unchanged on 35 benchmark systems. On the 18 dense random, MinRank, critical point (cp_d, crit) systems, the number of primes decreases by 32 to 38%, and the total time by 20 to 39% on those taking more than 0.3s (geometric mean speedup 1.44; random2_9_9: 2643 to 1651 primes, 81.7s to 56.1s; random3_6_6: 763 to 495 primes, 33.5s to 21.7s). On the other families the number of primes is unchanged and timings are within noise (+-3%), the LLL attempts made before a single witness is known costing a few hundredths of a second. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The eliminating polynomial is reconstructed from its highest degree down, carrying the lcm of the denominators already found, so most coefficients only bring a few new denominator bits and are bound by the size of their numerators. The bound D = M^(1/64) is now tried before D = M^(1/16), which lowers the number of primes needed by 2 to 5% on katsura and eco systems (kat12: 323 -> 313, eco13: 238 -> 231) with identical outputs. Random and minrank systems are unaffected. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
AddressSanitizer reports a few constant-size leaks in the multi-modular setup, independent of the number of primes. Free invalid_gens once the input is imported, free the per-thread copies of the linear-form data and of the current leading monomials in free_msolve_trace_qq_initial_data (zero-initializing the pointer arrays), free the monomial basis when initial_modular_step fails, and free the FGLM data of the first call before the second call in the non-shape-position case. Also free the parametrization on the failure paths of nmod_fglm_compute_trace_data, drop a name buffer that was immediately overwritten when adding a linear form, and count the terms of the added linear form in gens->nterms so their coefficients are cleared. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
This PR reworks the multi-modular lifting of rational parametrizations over QQ (
-P 1/-P 2), along the lines of what #383 did for Groebner bases. The goals are fewer primes, less time in CRT and rational reconstruction, and a number of primes that no longer depends on timings. Outputs are unchanged on every system tested.Changes
fmpq_reconstruct_fmpz_2. When2ND < mdoes not hold, the code falls back toratrecon/ratreconwden. The wrappers move fromlifting-gb.ctolifting.c, so both liftings share them.nbdoititerations, andnbdoitdoubled whenever reconstruction took more than 20% of the modular time, so the number of primes depended on the machine load. As for Groebner bases, the period is nowrrprimes, withrrthe largest power of 2 ≤ nprimes/128, and reconstruction is attempted once per iteration.modulus / 2^RR_MARGIN, as for Groebner bases, which makes spurious reconstructions unlikely.(d, n_1, .., n_4)found withfmpz_lll. This needs about bits(n) + bits(d)/4 bits of modulus, anddthen serves as a guess for the eliminating polynomial. LLL is tried only while no single witness is known.D = M^(1/64)is tried beforeD = M^(1/16). Coefficients are reconstructed from the highest degree down while carrying the lcm of the denominators already found, so most of them are bounded by their numerators.mulmat_reconstruct(-L 1) is fixed.lifting.c.msolve_trace_qqare fixed. AddressSanitizer is now clean on kat7, eco8, cyclic5 and random2_7_7 with 1 and 2 threads.Each commit message gives the measurements for that step.
Benchmarks
The setup is
-P 2 -t 1, release v0.11.0 against this branch. Systems where v0.11.0 takes under 1 s are excluded, and so are systems where this branch takes over 40 min. Seeds 1–5 are used when the branch takes under 300 s, seeds 1–2 otherwise. Times are means over the seeds.Outputs are identical on all 43 systems. The geometric-mean speedup is 1.48, and the total time drops from 18589 s to 12037 s (1.54).
The number of primes falls by 33–44% on the dense random, MinRank, cp_d and crit families. It falls by 1–6% on katsura, eco, noon, cyclic, henrion, chandra and sot1. KLYZ22 needs 19% fewer primes, zimmermann 48% fewer and phuoc1 29% fewer. bruno needs one more prime because of the 16-bit margin.
The v0.11.0 baseline does not include #383, which is now in master. The number of primes is set by the parametrization lifting changed here. The timings and peak memory also reflect the F4 changes of #383. The large memory drops on eco12 and eco13 (414 → 75 MB, 4710 → 259 MB) most likely come from #383 ("Fix per-prime leaks in F4 and avoid touching unused hash table memory").
Testing
make checkpasses (71/71).-P 2on kat7, eco8, cyclic5 and random2_7_7, with 1 and 2 threads, and on eco10 and kat9 with 2 threads.Parts of this PR were written with the assistance of generative AI (Claude Code). All changes were reviewed and benchmarked by the author.
Co-authored-by: Claude Opus 5.5 noreply@anthropic.com
🤖 Generated with Claude Code