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

make BinaryQF.solve_integer() work for square discriminants #33026

Closed
yyyyx4 opened this issue Dec 15, 2021 · 18 comments
Closed

make BinaryQF.solve_integer() work for square discriminants #33026

yyyyx4 opened this issue Dec 15, 2021 · 18 comments

Comments

@yyyyx4
Copy link
Member

yyyyx4 commented Dec 15, 2021

As reported in #32782 comment:8, PARI's qfbsolve() does not work with quadratic forms whose discriminant is a square integer.

This currently triggers failures in random testing, but it is not a regression: BinaryQF.solve_integer() used to reject all positive discriminants prior to #32782.

Depends on #33057

CC: @collares @slel @DaveWitteMorris

Component: quadratic forms

Author: Lorenz Panny

Branch/Commit: 5e8a2a3

Reviewer: Vincent Delecroix

Issue created by migration from https://trac.sagemath.org/ticket/33026

@yyyyx4 yyyyx4 added this to the sage-9.5 milestone Dec 15, 2021
@yyyyx4
Copy link
Member Author

yyyyx4 commented Dec 15, 2021

Branch: public/33026

@yyyyx4
Copy link
Member Author

yyyyx4 commented Dec 15, 2021

Author: Lorenz Panny

@yyyyx4
Copy link
Member Author

yyyyx4 commented Dec 15, 2021

Commit: ee4a650

@yyyyx4
Copy link
Member Author

yyyyx4 commented Dec 15, 2021

comment:1

Also fixed: The doctest was checking whether Q(*xy) == 0 rather than Q(*xy) == n.

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Dec 21, 2021

Changed commit from ee4a650 to 62a73ec

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Dec 21, 2021

Branch pushed to git repo; I updated commit sha1. This was a forced push. New commits:

ad491f6trac 33057 fix doctest
62a73ecmake BinaryQF.solve_integer() work for square discriminants

@yyyyx4
Copy link
Member Author

yyyyx4 commented Dec 21, 2021

Dependencies: #33057

@yyyyx4
Copy link
Member Author

yyyyx4 commented Dec 21, 2021

comment:3

Rebased onto #33057.

@mkoeppe mkoeppe modified the milestones: sage-9.5, sage-9.6 Dec 27, 2021
@videlec
Copy link
Contributor

videlec commented Dec 29, 2021

Reviewer: Vincent Delecroix

@videlec
Copy link
Contributor

videlec commented Dec 29, 2021

comment:5

Instead of

+                try:
+                    y = ZZ((n//x - Q._a*x) / Q._b)
+                except TypeError:
+                    continue
+                return tuple(row[0]*x + row[1]*y for row in M.rows())

you would better do

y_num = n // x - Q._a * x
if Q._b.divides(y_num):
    y = y_num // Q._b
    return tuple(row[0]*x + row[1]*y for row in M.rows())

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Dec 29, 2021

Changed commit from 62a73ec to 824056f

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Dec 29, 2021

Branch pushed to git repo; I updated commit sha1. New commits:

36afbd8Merge branch 'develop' into public/33026
824056fuse .divides and // instead of try-except and / and ZZ

@yyyyx4
Copy link
Member Author

yyyyx4 commented Dec 29, 2021

comment:7

Thanks, done.

@videlec
Copy link
Contributor

videlec commented Dec 30, 2021

comment:8

It is better to avoid the use multiple statements on the same line as

U.rescale_row(0, choice((+1,-1))); assert U.det() in (+1,-1)

See PEP8. (I don't understand why this is not checked by the patchbot.)

Since you have a special treatment for n=0, it would be reasonable to have a dedicated doctest.
Maybe, you could change

sage: n = randrange(-10^3, 10^3)
sage: Q = BinaryQF([n, randrange(-10^3, 10^3), 0][::(-1)**randrange(2)])
sage: U = random_matrix(ZZ, 2, 2, 'unimodular')
sage: U.rescale_row(0, choice((+1,-1))); assert U.det() in (+1,-1)
sage: Q = Q.matrix_action_right(U)
sage: Q.discriminant().is_square()
True
sage: xy = Q.solve_integer(n)
sage: Q(*xy) == n
True

to

sage: Q = BinaryQF([n, randrange(-10^3, 10^3), 0][::(-1)**randrange(2)])
sage: U = random_matrix(ZZ, 2, 2, 'unimodular')
sage: U.rescale_row(0, choice((+1,-1))); assert U.det() in (+1,-1)
sage: Q = Q.matrix_action_right(U)
sage: Q.discriminant().is_square()
True
sage: xy = Q.solve_integer(0)
sage: Q(*xy) == 0
True
sage: n = randrange(-10^3, 10^3)
sage: xy = Q.solve_integer(n)
sage: Q(*xy) == n
True

And I think this will be all my comments for this ticket.

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Dec 30, 2021

Changed commit from 824056f to 5e8a2a3

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Dec 30, 2021

Branch pushed to git repo; I updated commit sha1. New commits:

5e8a2a3add doctest; style tweak

@yyyyx4
Copy link
Member Author

yyyyx4 commented Dec 30, 2021

comment:10

Thank you! Done.

@vbraun
Copy link
Member

vbraun commented Feb 12, 2022

Changed branch from public/33026 to 5e8a2a3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants