Skip to content

Commit

Permalink
sagemathgh-35486: fix documentation and random doctest failure for Co…
Browse files Browse the repository at this point in the history
…rnacchia algorithm

    
This patch should fix the random doctest failure pointed out in
sagemath#35292 (comment),
following an upstream documentation update that was applied to resolve
[PARI bug sagemath#2471](https://pari.math.u-bordeaux.fr/cgi-
bin/bugreport.cgi?bug=2471).
    
URL: sagemath#35486
Reported by: Lorenz Panny
Reviewer(s): Frédéric Chapoton, Lorenz Panny, Rémy Oudompheng
  • Loading branch information
Release Manager committed Dec 3, 2023
2 parents 2a9a426 + e53ce0d commit 4e31ef2
Showing 1 changed file with 26 additions and 11 deletions.
37 changes: 26 additions & 11 deletions src/sage/quadratic_forms/binary_qf.py
Original file line number Diff line number Diff line change
Expand Up @@ -1581,9 +1581,10 @@ def solve_integer(self, n, *, algorithm="general"):
sage: Q.solve_integer(773187972) # needs sage.libs.pari
(4919, 1337)
If `Q` is of the form `[1,0,c]` as above and `n` is a prime or
four times a prime, Cornacchia's algorithm can be used, which is
typically much faster than the general method::
If `Q` is of the form `[1,0,c]` as above and `n` is a prime
(or four times a prime whenever `c \equiv 3 \pmod 4`), then
Cornacchia's algorithm can be used, which is typically much
faster than the general method::
sage: Q = BinaryQF([1, 0, 12345])
sage: n = 2^99 + 5273
Expand Down Expand Up @@ -1622,16 +1623,30 @@ def solve_integer(self, n, *, algorithm="general"):
Also when using the ``"cornacchia"`` algorithm::
sage: # needs sage.libs.pari
sage: abc = [1, 0, randrange(1,10^3)]
sage: Q = BinaryQF(abc)
sage: n = random_prime(10^9)
sage: if randrange(2):
....: n *= 4
sage: xy1 = Q.solve_integer(n, algorithm='cornacchia')
sage: xy1 is None or Q(*xy1) == n
sage: c = randrange(1, 10^3)
sage: # needs sage.libs.pari
sage: Q1 = BinaryQF(1, 0, c)
sage: xy = Q1.solve_integer(n, algorithm='cornacchia')
sage: xy is None or Q1(*xy) == n
True
sage: (xy is None) == (Q1.solve_integer(n) is None)
True
sage: # needs sage.libs.pari
sage: Q3 = BinaryQF(1, 0, 4*c+3)
sage: xy = Q3.solve_integer(n, algorithm='cornacchia')
sage: xy is None or Q3(*xy) == n
True
sage: (xy is None) == (Q3.solve_integer(n) is None)
True
sage: # needs sage.libs.pari
sage: xy = Q3.solve_integer(4*n, algorithm='cornacchia')
sage: xy is None or Q3(*xy) == 4*n
True
sage: xy2 = Q.solve_integer(n)
sage: (xy1 is None) == (xy2 is None)
sage: (xy is None) == (Q3.solve_integer(4*n) is None)
True
Test for square discriminants specifically (:trac:`33026`)::
Expand Down

0 comments on commit 4e31ef2

Please sign in to comment.