Ticket #9409 (closed defect: worksforme)

Opened 3 years ago

Last modified 3 years ago

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

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

Description (last modified by davidloeffler) (diff)

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

9409.sage Download (1.2 KB) - added by cremona 3 years ago.
Test script

Change History

comment:1 Changed 3 years ago by 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 3 years ago by adam

  • Keywords finite fields added
  • Description modified (diff)

comment:3 Changed 3 years ago by adam

  • Description modified (diff)

comment:4 follow-up: ↓ 5 Changed 3 years ago by cremona

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

Changed 3 years ago by cremona

Test script

comment:5 in reply to: ↑ 4 Changed 3 years ago by 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 3 years ago by cremona

  • Status changed from new to needs_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 3 years ago by davidloeffler

  • Description modified (diff)
  • Milestone set to sage-4.6

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

comment:8 Changed 3 years ago by davidloeffler

  • Status changed from needs_review to positive_review
  • Authors Adam Sorkin deleted

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

comment:9 Changed 3 years ago by mpatel

  • Status changed from positive_review to closed
  • Resolution set to worksforme
  • Milestone changed from sage-4.6 to sage-duplicate/invalid/wontfix
Note: See TracTickets for help on using tickets.