Ticket #4120 (new enhancement)

Opened 3 months ago

Last modified 4 days ago

[with new patch, needs work] New code for binary quadratic forms

Reported by: justin Assigned to: justin
Priority: major Milestone: sage-3.2.2
Component: quadratic forms Keywords:
Cc: justin, jonhanke

Description

The code supporting binary quadratic forms, in quadratic_forms/binary_qf.py, is missing some functionality, and relies on Magma and Pari. The patch in this ticket provides the following changes:

  • tests for equivalence, normal, positive and negative definite, indefinite, primitive forms
  • normalize a form
  • action of matrix on a form
  • find content; factor indefinite forms

In addition:

  • reduce() no longer calls Pari
  • some cleanup: is_reduced() is rewritten; polynomial() replaced with an instance variable (poly)

Doctests are in place for the new code, so the file remains at 100% coverage.

Attachments

diff (22.7 kB) - added by justin on 09/14/2008 12:32:11 PM.
Context diff of new, old versions of quadratic_forms/binary_qf.py
sage-4120.patch (22.6 kB) - added by justin on 09/23/2008 07:56:05 PM.
sage-4120-2.patch (13.9 kB) - added by justin on 10/02/2008 11:06:51 PM.
To be applied on top of sage-4120.patch
sage-4120-3.patch (16.5 kB) - added by justin on 10/06/2008 09:23:12 PM.
To be applied on top of sage-4120-2.patch
sage-trac4120.new.patch (42.0 kB) - added by cremona on 10/28/2008 01:46:13 PM.
REPLACES earlier patches

Change History

09/14/2008 12:32:11 PM changed by justin

  • attachment diff added.

Context diff of new, old versions of quadratic_forms/binary_qf.py

09/14/2008 12:48:35 PM changed by mabshoff

  • milestone set to sage-3.1.3.

09/14/2008 12:59:39 PM changed by mabshoff

Justin,

the diff is inverse and you should also add an extension patch to the file.

Cheers,

Michael

09/23/2008 07:56:05 PM changed by justin

  • attachment sage-4120.patch added.

09/23/2008 07:59:01 PM changed by justin

Updated patch, works with 3.1.1 and 3.1.2. Needs review. And maybe testing :-} Also incorporated performance changes from Holdsworth's changes.

09/23/2008 09:42:49 PM changed by AlexGhitza

  • summary changed from New code for binary quadratic forms to [with patch, needs review] New code for binary quadratic forms.

09/24/2008 06:53:13 AM changed by cremona

I am planning to review this, which looks pretty good. First, some preliminary questions/comments:

  • I see that we now have some, but not all, support for indefinite forms. (e.g. no equivalence testing, no class number). Why not use pari interface for those, at least until we do our own? (I would have thought that pari was pretty efficient for these things).
  • Your action of 2x2 matrices is a left action. Do we want to allow users to use a right action (say, by having RMul and LMul with Mul an alias for one of them)?
  • Your action includes multiplication by det(A). Now there are lots of application for this code, some will like that and some will want something else. So why don't we have another parameter for Mul() which is the power of the determinant to be used. Personally I would set the default to 0 but if you wanted it to be 1 (as in your code) I could live with that.
  • I still think that quite a lot of the functionality could be factored out into a more general binary form class, but that can be done later by someone (e.g. me) who uses higher degree forms.

09/24/2008 02:01:55 PM changed by justin

The patch also works with 3.1.3.alpha1. Doctests succeed.

10/02/2008 11:05:57 PM changed by justin

Here's a second patch, to be applied on top of sage-4120.patch.

This one fixes some bugs and typos in the first, cleans up some code, and adds more support for indefinite forms (equivalence checking, in particular). Probably adds a few bugs as well, but that's just a by-product.

10/02/2008 11:06:51 PM changed by justin

  • attachment sage-4120-2.patch added.

To be applied on top of sage-4120.patch

10/06/2008 09:22:34 PM changed by justin

  • owner changed from tbd to justin.

This is a third patch, applied on sage-4120-2.patch.

This one extends support for indefinite forms and fixes a few bugs (both in code and in the Buchmann/Vollmer algorithms).

One change in particular deserves discussion: I have changed the normalization and reduction procedures to return both the form in question and the transformation matrix used to derive that form. This makes things a bit more awkward in the code, so there are two questions: is this really useful, and if yes, is there a better way to do it?

Also, I assigned this to me :-}.

10/06/2008 09:23:12 PM changed by justin

  • attachment sage-4120-3.patch added.

To be applied on top of sage-4120-2.patch

10/13/2008 09:31:21 PM changed by justin

Applied all three patches against 3.1.3.rc0, one at a time, running the doctests each time. All doctests succeeded. No problems noted.

10/28/2008 01:46:13 PM changed by cremona

  • attachment sage-trac4120.new.patch added.

REPLACES earlier patches

10/28/2008 01:53:02 PM changed by cremona

  • summary changed from [with patch, needs review] New code for binary quadratic forms to [with new patch, needs review] New code for binary quadratic forms.

My patch sage-trac4120new.patch combines the three earlier ones and adds the following:

  • Fixing various bugs and typos
  • Sorting out a lot of formatting issues in doctests
  • Adds some new functions
  • Renames Mul to __mul__ so one can say Q*M to apply matrix M to form Q

Regarding the latter I relented and removed the scale parameter; since the det is either +1 or -1 I am happy with multiplying (or dividing) by the determinant.

Issues do remain:

  • The various transform function which return a new form Q and a transform T really must satisfy self.T==Q, but they don't. Hence the commented out assertions.
  • We must decide whether we are talking about weak or strict equivalence (GL or SL(2,ZZ)). At the moment it is hard to tell which.
  • For indefinite forms there are several different notions of "reduced". OK to to stick to one, but we should make this explicit.
  • The class number function looks inefficient to me, it should be replaced by the fast code by Skoruppa to list reduced forms (in the definite case at least).

That's all I can remember, but this will need more work before it can go in.

11/08/2008 01:30:45 PM changed by mabshoff

See also #4470 for Jon Hanke's work on quadratic forms.

Cheers,

Michael

11/08/2008 01:32:23 PM changed by mabshoff

  • component changed from algebra to quadratic forms.

11/10/2008 04:18:35 PM changed by justin

  • cc set to justin.

11/28/2008 01:52:44 PM changed by was

  • summary changed from [with new patch, needs review] New code for binary quadratic forms to [with new patch, needs work] New code for binary quadratic forms.

11/28/2008 02:40:44 PM changed by mabshoff

  • cc changed from justin to justin, jonhanke.

To comment on the relationship with #4470:

AFAIK the binary quadratic forms are untouched by Jon's work. We
should rename the file to bring it more in line with what is coming
from Jon, i.e. all I have left to do to post a patch is to rename
various files to qf_ from quadratic_forms_, fix the imports and rebase
the extensions to module_list.py. All trivial, it just needs to be
done :p

Cheers,

Michael