Skip to content

Commit

Permalink
faster comparison of elliptic-curve morphisms
Browse files Browse the repository at this point in the history
  • Loading branch information
yyyyx4 committed Oct 12, 2024
1 parent 7726cd9 commit 35f3f88
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/sage/schemes/elliptic_curves/hom.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,12 @@ def _richcmp_(self, other, op):
if lx != rx:
return richcmp_not_equal(lx, rx, op)

# Check the Weierstraß scaling factor, too (should be fast)

lx, rx = self.scaling_factor(), other.scaling_factor()
if lx != rx:
return richcmp_not_equal(lx, rx, op)

# Do self or other have specialized comparison methods?

ret = self._comparison_impl(self, other, op)
Expand Down Expand Up @@ -1176,20 +1182,28 @@ def compare_via_evaluation(left, right):
F = E.base_ring()

if isinstance(F, finite_field_base.FiniteField):
# check at a random rational point first
P = E.random_point()
if left(P) != right(P):
return False

Check warning on line 1188 in src/sage/schemes/elliptic_curves/hom.py

View check run for this annotation

Codecov / codecov/patch

src/sage/schemes/elliptic_curves/hom.py#L1188

Added line #L1188 was not covered by tests

# then extend to a field with enough points to conclude
q = F.cardinality()
d = left.degree()
e = integer_floor(1 + 2 * (2*d.sqrt() + 1).log(q)) # from Hasse bound
e = next(i for i, n in enumerate(E.count_points(e+1), 1) if n > 4*d)
EE = E.base_extend(F.extension(e, 'U')) # named extension is faster
Ps = EE.gens()
return all(left._eval(P) == right._eval(P) for P in Ps)

elif isinstance(F, number_field_base.NumberField):
for _ in range(100):
P = E.lift_x(F.random_element(), extend=True)
if not P.has_finite_order():
return left._eval(P) == right._eval(P)
else:
assert False, "couldn't find a point of infinite order"

else:
raise NotImplementedError('not implemented for this base field')

Expand Down

0 comments on commit 35f3f88

Please sign in to comment.