Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

faster comparison of elliptic-curve morphisms #38808

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 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,13 @@
if lx != rx:
return richcmp_not_equal(lx, rx, op)

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

if op == op_EQ or op == op_NE:
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 +1183,28 @@
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 1189 in src/sage/schemes/elliptic_curves/hom.py

View check run for this annotation

Codecov / codecov/patch

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

Added line #L1189 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
Loading