From 19dd5dafe9959355f0c0e0654bc8edfe1b0480f4 Mon Sep 17 00:00:00 2001 From: Lorenz Panny Date: Wed, 12 Apr 2023 17:55:50 +0800 Subject: [PATCH 1/2] fix documentation and doctest for qfbcornacchia() -- see #35292 --- src/sage/quadratic_forms/binary_qf.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/sage/quadratic_forms/binary_qf.py b/src/sage/quadratic_forms/binary_qf.py index 0f32bba92ba..b7ce0ed5ddb 100755 --- a/src/sage/quadratic_forms/binary_qf.py +++ b/src/sage/quadratic_forms/binary_qf.py @@ -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 @@ -1625,7 +1626,7 @@ def solve_integer(self, n, *, algorithm="general"): sage: abc = [1, 0, randrange(1,10^3)] sage: Q = BinaryQF(abc) sage: n = random_prime(10^9) - sage: if randrange(2): + sage: if Q[2] % 4 == 3 and randrange(2): ....: n *= 4 sage: xy1 = Q.solve_integer(n, algorithm='cornacchia') sage: xy1 is None or Q(*xy1) == n From e53ce0dd5263cbf9d1907b5463af2e56919223db Mon Sep 17 00:00:00 2001 From: Lorenz Panny Date: Thu, 13 Apr 2023 01:33:36 +0800 Subject: [PATCH 2/2] streamline test per reviewer feedback --- src/sage/quadratic_forms/binary_qf.py | 30 ++++++++++++++++++++------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/src/sage/quadratic_forms/binary_qf.py b/src/sage/quadratic_forms/binary_qf.py index b7ce0ed5ddb..d16438bf45b 100755 --- a/src/sage/quadratic_forms/binary_qf.py +++ b/src/sage/quadratic_forms/binary_qf.py @@ -1623,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 Q[2] % 4 == 3 and 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`)::