Opened 12 years ago

Closed 12 years ago

#9409 closed defect (worksforme)

Bug in elliptic curves method .count_points() over finite fields

Reported by: Adam Sorkin Owned by: John Cremona
Priority: major Milestone: sage-duplicate/invalid/wontfix
Component: elliptic curves Keywords: Elliptic Curves .count_points() finite fields
Cc: Merged in:
Authors: Reviewers:
Report Upstream: N/A Work issues:
Branch: Commit:
Dependencies: Stopgaps:

Status badges

Description (last modified by David Loeffler)

There is some bug in the method .count_points() which belongs to elliptic curves defined over finite fields. This might be specific to EC defined over number fields - I only get this error when I take an EC over a number field, reduce at a good prime and then count points. In fact, I get the correct answer the first time, but if I define a second EC over a possibly different number field and count points at a good reduction, then the method .count_points() fails. I suspect this has to do with the cacheing...

If you want to reproduce the behavior, try the following code:

### this just runs through the method outlined above:

def test(curve, bound):
    for i in primes(bound):
        print "Checking primes over %d:        "%i
        factors = curve.base_field().ideal(i).factor()
        for j in range(len(factors)):
            if  curve.has_good_reduction(factors[j][0]):
                if factors[j][0].divides(curve.discriminant()):
                    print "Curve has good reduction, but this isn't not a minimal model",
                    print "at %s with %d points in the reduced curve"%(factors[j][0], curve.local_minimal_model(factors[j][0]).reduction(factors[j][0]).count_points() )
                else:                 
                    print "Curve has good reduction and is a minimal model"
                    print "at %s with %d points in the reduced curve"%(factors[j][0],  curve.reduction(factors[j][0]).count_points() )
            else:
                print "Curve has bad reduction over %s"%factors[j][0]
    return


### sample 1
K.<t> = NumberField(x^2 + 1); E = EllipticCurve(K, [0, 1, 0, -2*t - 2, 2*t]); E
### sample 2
L.<u> = NumberField(x^2 - 2); F = EllipticCurve(L, [0,2,0, 2*u +4, 2*u + 3]); F

test(E, 100)

## the above works fine; the next command will cause the error.



test(F, 100)


You will get the correct output for the first few primes, but the error message, which in the above case occurs above the prime ideal (67), is


Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "_sage_input_8.py", line 10, in <module>
    exec compile(u'open("___code___.py","w").write("# -*- coding: utf-8 -*-\\n" + _support_.preparse_worksheet_cell(base64.b64decode("dGVzdChGLCAxMDAp"),globals())+"\\n"); execfile(os.path.abspath("___code___.py"))
  File "", line 1, in <module>
    
  File "/tmp/tmpVYbgxh/___code___.py", line 3, in <module>
    exec compile(u'test(F, _sage_const_100 )
  File "", line 1, in <module>
    
  File "/tmp/tmptawaYw/___code___.py", line 14, in test
    print "at %s with %d points in the reduced curve"%(factors[j][_sage_const_0 ],  curve.reduction(factors[j][_sage_const_0 ]).count_points() )
  File "/usr/local/sage2/local/lib/python2.6/site-packages/sage/schemes/elliptic_curves/ell_finite_field.py", line 322, in count_points
    return self.cardinality()
  File "/usr/local/sage2/local/lib/python2.6/site-packages/sage/schemes/elliptic_curves/ell_finite_field.py", line 951, in cardinality
    self._order = self.cardinality_bsgs()
  File "/usr/local/sage2/local/lib/python2.6/site-packages/sage/schemes/elliptic_curves/ell_finite_field.py", line 1220, in cardinality_bsgs
    N1 = ZZ(2)**sum([e for P,e in E1._p_primary_torsion_basis(2)])
  File "/usr/local/sage2/local/lib/python2.6/site-packages/sage/schemes/elliptic_curves/ell_generic.py", line 2660, in _p_primary_torsion_basis
    Ep = self(0).division_points(p)
  File "/usr/local/sage2/local/lib/python2.6/site-packages/sage/schemes/elliptic_curves/ell_point.py", line 879, in division_points
    Q = E.lift_x(x)
  File "/usr/local/sage2/local/lib/python2.6/site-packages/sage/schemes/elliptic_curves/ell_generic.py", line 855, in lift_x
    raise ValueError, "No point with x-coordinate %s on %s"%(x, self)
ValueError: No point with x-coordinate 39*tbar + 11 on Elliptic Curve defined by y^2 = x^3 + 2*x^2 + (2*ubar+4)*x + (2*ubar+3) over Residue field in ubar of Fractional ideal (67)

Attachments (1)

9409.sage (1.2 KB) - added by John Cremona 12 years ago.
Test script

Download all attachments as: .zip

Change History (10)

comment:1 Changed 12 years ago by John Cremona

You do not actually say what the error is -- can you paste in the relevant part of the output?

This is one of a number of tickets which claim to be about elliptic curves but are almost certainly about the caching of finite fields (as you suggest). the trouble is that because of this, elliptic curves people (like me) look at the ticket and do nothing, while the finite fields people who need to fix code do not look at it!

comment:2 Changed 12 years ago by Adam Sorkin

Description: modified (diff)
Keywords: finite fields added

comment:3 Changed 12 years ago by Adam Sorkin

Description: modified (diff)

comment:4 Changed 12 years ago by John Cremona

This should be tested after #9315 is in as that may well fix it.

Changed 12 years ago by John Cremona

Attachment: 9409.sage added

Test script

comment:5 in reply to:  4 Changed 12 years ago by John Cremona

Replying to cremona:

This should be tested after #9315 is in as that may well fix it.

Unfortunately not. After loading the attached script, running either testE() or testF() in a fresh Sage (so no cached fields) works fine, but then running the other one fails (at p=59).

comment:6 Changed 12 years ago by John Cremona

Status: newneeds_review

This now seems to work fine (both functions testE() and testF() in the test script now run without errors) in 4.6.alpha2 (not alpha1!).

If the reviewer agrees, this can be set to fixed and the closed.

comment:7 Changed 12 years ago by David Loeffler

Description: modified (diff)
Milestone: sage-4.6

(Editing description because the entire ticket webpage appears stuck in a rogue <sup> tag!)

comment:8 Changed 12 years ago by David Loeffler

Authors: Adam Sorkin
Status: needs_reviewpositive_review

Looks fine to me. I'm flagging this as positive review so the release manager can close it as fixed.

comment:9 Changed 12 years ago by Mitesh Patel

Milestone: sage-4.6sage-duplicate/invalid/wontfix
Resolution: worksforme
Status: positive_reviewclosed
Note: See TracTickets for help on using tickets.