Skip to content

add lenstra eliptic curve factoring#104

Open
oscardssmith wants to merge 3 commits into
JuliaMath:mainfrom
oscardssmith:Lenstra-elliptic-curve
Open

add lenstra eliptic curve factoring#104
oscardssmith wants to merge 3 commits into
JuliaMath:mainfrom
oscardssmith:Lenstra-elliptic-curve

Conversation

@oscardssmith

Copy link
Copy Markdown
Member

heavily inspired by @trizen, but refactored a little to make it more reliable.

@oscardssmith

Copy link
Copy Markdown
Member Author

some benchmarks:

x = prod(nextprime(big(2)^30, i) for i in 1:2)
@time Primes.pollardfactors!(x, Dict{BigInt,Int}())
  0.028354 seconds (1.13 M allocations: 22.163 MiB)
@time lenstrafactors!(x, Dict{BigInt,Int}())
  0.110741 seconds (1.65 M allocations: 30.821 MiB, 26.82% gc time)

x = prod(nextprime(big(2)^30, i) for i in 1:20)
@time Primes.pollardfactors!(x, Dict{BigInt,Int}());
  0.830832 seconds (14.86 M allocations: 346.059 MiB, 21.69% gc time)
@time lenstrafactors!(x, Dict{BigInt,Int}());
  0.375128 seconds (3.62 M allocations: 114.038 MiB, 11.86% gc time)

x = prod(nextprime(big(2)^50, i) for i in 1:2)
@time lenstrafactors!(x, Dict{BigInt,Int}())
 18.921172 seconds (296.05 M allocations: 6.041 GiB, 14.56% gc time)
@time Primes.pollardfactors!(x, Dict{BigInt,Int}())
  56.697309 seconds (1.12 G allocations: 21.651 GiB, 20.29% gc time)

These are the bad cases for ecm (when all the factors are of similar size). That said, ecm tends to do a bunch better for larger inputs, and for numbers with a few smaller factors. This implementation is not especially optimized, but I think it is a good baseline for future improvements.

@oscardssmith oscardssmith force-pushed the Lenstra-elliptic-curve branch from 63fe1a0 to 0f17131 Compare January 14, 2022 18:51
@oscardssmith oscardssmith force-pushed the Lenstra-elliptic-curve branch 2 times, most recently from 7dc85ad to afb4498 Compare December 11, 2024 19:19
@oscardssmith oscardssmith force-pushed the Lenstra-elliptic-curve branch from afb4498 to 42f0316 Compare July 4, 2026 01:17
@codecov

codecov Bot commented Jul 4, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 97.11538% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 94.97%. Comparing base (b2fca94) to head (42f0316).

Files with missing lines Patch % Lines
src/Primes.jl 97.11% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #104      +/-   ##
==========================================
+ Coverage   93.52%   94.97%   +1.45%     
==========================================
  Files           2        2              
  Lines         463      517      +54     
==========================================
+ Hits          433      491      +58     
+ Misses         30       26       -4     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@oscardssmith

Copy link
Copy Markdown
Member Author

With a little help from claude, I now have this working a lot faster (due to a better basis for curve and adding stage 2).

min factor pollard lenstra stage-1-only lenstra full stage-2 speedup
20-bit 36 µs 121 µs 149 µs 0.81×
25-bit 159 µs 281 µs 385 µs 0.73×
30-bit 950 µs 350 µs 518 µs 0.68×
35-bit 425 ms 139 ms 65 ms 2.15×
40-bit 1.67 s 107 ms 60 ms 1.76×
45-bit 995 ms 265 ms 3.76×
50-bit 2.81 s 680 ms 4.13×
55-bit 4.86 s 2.00 s 2.43×

@oscardssmith

Copy link
Copy Markdown
Member Author

@s-celles tagging you here cause I figure you may be interested.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant