# Ticket #3111: sage-3111.patch

File sage-3111.patch, 5.8 KB (added by cremona, 13 years ago)
• ## sage/schemes/elliptic_curves/ell_finite_field.py

```# HG changeset patch
# User John Cremona <john.cremona@gmail.com>
# Date 1210153923 -3600
# Node ID 6be71336769080d20026f30bbbc803bb481ba9b0
# Parent  9f576faa0dca242727807fda6fae98c7cfc513b6
#3111: 2 bug fixes -- Hasse_bounds() and abelian_group()

diff -r 9f576faa0dca -r 6be713367690 sage/schemes/elliptic_curves/ell_finite_field.py```
 a class EllipticCurve_finite_field(Ellipti if debug: "Getting a new random point" Q = self.random_point() while Q.is_zero(): Q = self.random_point() npts += 1 if debug: print "Q = ",Q,":", class EllipticCurve_finite_field(Ellipti if Q1.is_zero() and npts>=10: # then P1,n1 will not change but we may increase n2 if debug: print "Case 2: n2 may increase" n1a = 1; n1b = n1 P1a = P1 if group_order_known: n1a=n1.prime_to_m_part(N//n1) Q = n1a*Q a,m = generic.linear_relation(n1a*P1,Q,operation='+') n1a = n1.prime_to_m_part(N//n1) n1b = n1//n1a Q = n1a*Q       # has order | n1b P1a = n1a*P1    # has order = n1b if debug: print "n1a=",n1a a = None for m in (N//n1).divisors(): try: a = generic.bsgs(m*P1a,m*Q,(0,(n1b//m)-1),operation='+') break except ValueError: pass assert a != None a *= (m*n1a) if debug: print "linear relation gives m=",m,", a=",a assert m*Q==a*P1 if m>1: # else Q is in Q=Q-(a//m)*P1; # has order m and is disjoint from P1 if debug: assert Q.order()==m Q._order=m if n2==1: # this is our first nontrivial P2 P2=Q class EllipticCurve_finite_field(Ellipti else:     # we must merge P2 and Q: oldn2=n2 # holds old value P2,n2=generic.merge_points((P2,n2),(Q,m),operation='+'); if debug: assert P2.order()==n2 P2._order=n2 if debug: if n2>oldn2: print "Replacing second generator by ",P2, print " of order ",n2, "  gaining index ",n2//a print " of order ",n2, "  gaining index ",n2//oldn2 print "Group order now ",n1*n2,"=",n1,"*",n2 elif not Q1.is_zero(): # Q1 nonzero: n1 will increase if debug:  print "Case 1: n1 may increase" oldn1=n1 if n2>1: P3=(n1//n2)*P1  # so P2,P3 are a basis for n2-torsion if debug: assert P3.order()==n2 P3._order=n2 if debug: print "storing generator ",P3," of ",n2,"-torsion" m = generic.order_from_bounds(Q,bounds,n1,operation='+') P1,n1=generic.merge_points((P1,n1),(Q,m)) if debug: assert P1.order()==n1 P1._order=n1 if debug: print "Replacing first  generator by ",P1," of order ", class EllipticCurve_finite_field(Ellipti a,m = generic.linear_relation(P1,P3,operation='+') if debug: print "linear relation gives m=",m,", a=",a P3=P3-(a//m)*P1 if debug: assert P3.order()==m P3._order=m if debug: print "First  P2 component =",P3 if m==n2: class EllipticCurve_finite_field(Ellipti a,m = generic.linear_relation(P1,P2,operation='+') if debug: print "linear relation gives m=",m,", a=",a P2=P2-(a//m)*P1; if debug: assert P2.order()==m P2._order=m if debug: print "Second  P2 component =",P2 P2,n2=generic.merge_points((P2,n2),(P3,m)) if debug: assert P2.order()==n2 P2._order=n2 if debug: print "Combined P2 component =",P2 class EllipticCurve_finite_field(Ellipti print " and not ",n2 raise ValueError if n2>1: print "P1=",P1," of order ",P1.order(),"=",n1 print "P2=",P2," of order ",P2.order(),"=",n2 if generic.linear_relation(P1,P2,operation='+')[1]!=n2: print "Generators not independent!" raise ValueError
• ## sage/schemes/elliptic_curves/ell_generic.py

`diff -r 9f576faa0dca -r 6be713367690 sage/schemes/elliptic_curves/ell_generic.py`
 a def Hasse_bounds(q, genus=1): sage: Hasse_bounds(next_prime(10^30)) (999999999999998000000000000058, 1000000000000002000000000000058) """ rq = 2*genus*q.isqrt() if genus==1: rq = (4*q).isqrt() else: rq = (4*(genus**2)*q).isqrt() return (q+1-rq,q+1+rq)