Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix documentation and random doctest failure for Cornacchia algorithm #35486

Merged
merged 2 commits into from
Dec 6, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading