Skip to content

Commit 63a79f3

Browse files
author
Release Manager
committed
sagemathgh-38808: faster comparison of elliptic-curve morphisms Here we add two fast checks to the generic comparison method for elliptic-curve morphisms that will quickly detect some pairs of unequal morphisms. In the context of sagemath#35949, this speeds up the following example from 5.9 seconds to 1.8 seconds: ```sage sage: E = EllipticCurve(GF((5, 2)), [0,1]) sage: %time _ = list(E.isogenies_degree(27)) ``` URL: sagemath#38808 Reported by: Lorenz Panny Reviewer(s): Sebastian A. Spindler
2 parents b342274 + 64236f9 commit 63a79f3

File tree

1 file changed

+15
-0
lines changed
  • src/sage/schemes/elliptic_curves

1 file changed

+15
-0
lines changed

src/sage/schemes/elliptic_curves/hom.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,13 @@ def _richcmp_(self, other, op):
270270
if lx != rx:
271271
return richcmp_not_equal(lx, rx, op)
272272

273+
# Check the Weierstraß scaling factor, too (should be fast)
274+
275+
if op == op_EQ or op == op_NE:
276+
lx, rx = self.scaling_factor(), other.scaling_factor()
277+
if lx != rx:
278+
return richcmp_not_equal(lx, rx, op)
279+
273280
# Do self or other have specialized comparison methods?
274281

275282
ret = self._comparison_impl(self, other, op)
@@ -1174,20 +1181,28 @@ def compare_via_evaluation(left, right):
11741181
F = E.base_ring()
11751182

11761183
if isinstance(F, finite_field_base.FiniteField):
1184+
# check at a random rational point first
1185+
P = E.random_point()
1186+
if left(P) != right(P):
1187+
return False
1188+
1189+
# then extend to a field with enough points to conclude
11771190
q = F.cardinality()
11781191
d = left.degree()
11791192
e = integer_floor(1 + 2 * (2*d.sqrt() + 1).log(q)) # from Hasse bound
11801193
e = next(i for i, n in enumerate(E.count_points(e+1), 1) if n > 4*d)
11811194
EE = E.base_extend(F.extension(e, 'U')) # named extension is faster
11821195
Ps = EE.gens()
11831196
return all(left._eval(P) == right._eval(P) for P in Ps)
1197+
11841198
elif isinstance(F, number_field_base.NumberField):
11851199
for _ in range(100):
11861200
P = E.lift_x(F.random_element(), extend=True)
11871201
if not P.has_finite_order():
11881202
return left._eval(P) == right._eval(P)
11891203
else:
11901204
assert False, "couldn't find a point of infinite order"
1205+
11911206
else:
11921207
raise NotImplementedError('not implemented for this base field')
11931208

0 commit comments

Comments
 (0)