From 7ffc6ec82b48c17863e5b53cee49567442540b7d Mon Sep 17 00:00:00 2001 From: Martin Grenouilloux Date: Thu, 15 Aug 2024 17:01:57 +0200 Subject: [PATCH] Blazingly fast optimization by filtering primes with kronecker symbol --- .../elliptic_curves/ell_finite_field.py | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/sage/schemes/elliptic_curves/ell_finite_field.py b/src/sage/schemes/elliptic_curves/ell_finite_field.py index 259c00d9bb0..59776006e4c 100644 --- a/src/sage/schemes/elliptic_curves/ell_finite_field.py +++ b/src/sage/schemes/elliptic_curves/ell_finite_field.py @@ -2813,10 +2813,17 @@ def EllipticCurve_with_prime_order(N): sage: E.order() == N True - The execution time largely depends on the input:: + It works for large primes:: - sage: N = 125577861263605878504082476745517446213 - sage: E = EllipticCurve_with_prime_order(N) # Takes ~1 second. + sage: N = 0x6cbc824032974516623e732462f4b74b56c4ffbd984380d9 + sage: E = EllipticCurve_with_prime_order(N) + sage: E.order() == N + True + + But the execution time largely depends on the input:: + + sage: N = 200396817641911230625970463749415493753 + sage: E = EllipticCurve_with_prime_order(N) sage: E.order() == N True @@ -2862,7 +2869,7 @@ def EllipticCurve_with_prime_order(N): ALGORITHM: [BS2007]_, Algorithm 2.2 """ - from sage.arith.misc import is_prime + from sage.arith.misc import is_prime, kronecker from sage.combinat.subset import powerset from sage.functions.other import ceil from sage.misc.functional import symbolic_prod as product, log @@ -2884,7 +2891,8 @@ def EllipticCurve_with_prime_order(N): while True: # Iterating over the odd primes by chunks of size log(`N`). - S.extend(prime_range(prime_start, prime_end)) + S.extend(p for p in prime_range(prime_start, prime_end) + if kronecker(N, p) == 1) # Every possible products of distinct elements of `S`. # There probably is a more optimal way to compute all possible products