Repository navigation
Conversation
|
@antonio-rojas - thanks to codex 🤖 it was easy to fix. Please review |
|
Actually, it's a pure Pari/gp bug. Inverting matrices is hard :-) |
|
@orlitzky - see the description of the PR above (if only for fun) |
|
@antonio-rojas Karim fixed the bug that was holding it all up, at least that's what he says. We can drop patches and switch to Pari master - although I would rather wait for a release |
|
Yes, all tests in sage are fine now with cypari2 2.2.6 (and a patched pari 2.19) |
|
by patched pari, do you mean the current pari master? |
No, I mean with backports for the fixed bugs that affect sage. I assume git master is likely to cause more breakage due to new stuff. |
|
it looks like cypari2 is a good way to find pari bugs. I'd try using their master and see what news we get this way. Are there any changes in 2.2.6 needed for such a switch? |
|
I second trying to update to master regularly and reporting things that break! If you have time to do it, that is. Thanks! |
Follow up to #233: retain word-aligned working precision for
mateigenand add broader tests for numerical precision arguments.Passing exact bit counts to PARI 2.19 fixes the L-function stack overflow in #232, but exposes an eigenvector failure at 53-bit working precision:
Before this change, the call raises
PariError: impossible inverse in divrr: 0.E-32. Rounding the working precision to 64 bits restores the previous behavior. Apply this rounding to bothGen.mateigenandPari.mateigen; other wrappers retain #233's exact bit counts with PARI 2.19. This also fixes Sage'smatrix(RealField(53), [[0, 1], [-2., 0]]).eigenvalues(algorithm="pari")without a Sage change.For this matrix on a 64-bit host, raw PARI calls also fail at lower precisions (including 15, 32, and 48 bits) and at 63 bits. Calls at 64, 65, 66, and higher tested precisions succeed. This is a low-precision failure, not evidence that the algorithm requires word-aligned working precision. Restoring the historical rounding raises these low requests to 64 bits. The regression tests include 15, 32, and 48 bits as well as the boundary cases.
Add regression doctests and a numerical test suite at 53, 63, 64, 65, 127, 128, and 129 bits. The suite checks eigenvector and matrix-decomposition residuals, polynomial roots, 63 transcendental functions against 256-bit references, handwritten vector-returning calls, number-field embeddings/regulators, and elliptic-curve calculations. Run it through both
make checkand cibuildwheel testing.Validation with Python 3.14.7 and cysignals 1.13.0:
Further investigation traced the failure to PARI's shared Gaussian pivot code, rather than a word-alignment requirement in
mateigen. A direct GP reproducer is:It also reproduces on PARI development master
d1430f50b248e8a06a5fb67d9a197ae5a6aa2133. Gaussian elimination selects the complex residual5.421010862427522170 E-20 + 0.E-16*Ias a pivot:cx_approx0(p, 1)is false, although its squared norm is0.E-32. The nonzero real component has 64-bit stored precision; the zero imaginary component has only the requested accuracy. Inverting the pivot therefore raises the error beforemateigencan reach its existing higher-precision recovery path.The GP reproducer passes on PARI 2.17.1 (verified with a fresh source build) and 2.17.4. A git bisect identifies
567715f74ed1a4397fdbe1770254c1b4f08abe80("neutralize nbits2prec", committed 2026-09-22) as the first bad commit; its immediate parent110e2bfa61999dcf17322e8ac7cb34c25efa8110passes. The commit changesnbits2prec(53)from 64 to 53. At that point,get_localprec()still callsnbits2prec(get_localbitprec()), so the GP call starts passing exactly 53 bits tomateigen, exposing the latent numerical pivot defect.This also affects
matker,matrank,matimage, andmatindexrankon[-r,1;-2,-r], wherer=polroots(x^2+2)[1]computed atlocalbitprec(53). A candidate upstream change rejects complex pivots whose squared norm is zero at the available precision. It fixes these reproductions and the eigenvector example at every precision from 15 through 193; PARI'slinear,mat,real, androotsrealtests pass for both static and dynamic GP builds. Reported upstream as PARI bug #2708, with the reproducer, trace, bisect result, and candidate patch.A separate local test reproduces the failure with unpatched PARI 2.17.4: see the standalone GP reproducer and recorded result. This is a reproduction performed during this investigation, not a reference to a previously published bug report. The equivalent cypari2 call,
pari.matrix(2, 2, [0., 1., -2., 0.]).mateigen(flag=1, precision=64), raisesimpossible inverse in divrrwith both PARI 2.17.4 and 2.19.0; precision 128 succeeds. Applying the candidate pivot fix directly to the PARI 2.19.0 release tag makes this exact cypari2 call succeed, returning eigenvalues approximately+/-1.4142135623730950488*Iand corresponding eigenvectors. The loaded library path was checked to confirm that the patched 2.19.0 build was used. All nine cypari2 precision unit tests and PARI's four test suites above also pass with patched 2.19.0.The cypari2 rounding workaround (the current branch of this PR) remains temporary and does not address all manifestations of the shared pivot defect.