ECM(1)
๐ ECM(1) ๐
okay bestie, sit DOWN, we're learning ecm โ and yes it's from the ECM(1) manual, April 22, 2003, and yes we're doing the whole thing, no skimming, no shortcuts, periodt. ๐
โจ NAME โจ
ecm โ integer factorization using ECM, P-1 or P+1 ๐ง
โจ SYNOPSIS โจ
ecm [options] B1 [B2min-B2max | B2]
โจ DESCRIPTION โจ
So ecm is an integer factoring program, and it's giving main character energy because it can do three whole methods: the Elliptic Curve Method (ECM), the P-1 method, or the P+1 method. ๐ธ
The sections below walk you through every parameter that matters for these algorithms. No gatekeeping here, we're going through all of it. ๐ซถ
โจ STEP 1 AND STEP 2 BOUND PARAMETERS โจ
๐ B1
B1 is the step 1 bound. It's mandatory, bestie, you literally cannot skip it. ๐ค
You can hand it over either as an integer (like 3000000) or in floating-point format (3000000.0 or 3e6, same vibe).
The biggest possible B1 value is 9007199254740996 for P-1, and for ECM and P+1 it's ULONG_MAX or 9007199254740996 โ whichever one is smaller.
Every single prime 2 <= p <= B1 gets processed in step 1. All of them. Slay. ๐ฅ
๐ B2
B2 is the step 2 bound, and it's optional โ if you dip out and don't provide it, a default value gets computed from B1, and ngl that default should be pretty close to optimal. โจ
Same deal as B1: integer or floating-point format, your call.
The largest possible B2 value is approximately 9e23, but lowkey it depends on the number of blocks k if you use the -k option.
Every prime B1 <= p <= B2 gets processed in step 2. And heads up: if B2 < B1, then there's no step 2 at all, it just doesn't happen. ๐
๐ B2min-B2max
Alternatively (yes there's an alternative, we love options ๐) you can use the B2min-B2max form, which means all primes B2min <= p <= B2max should be processed.
So basically, specifying just B2 alone corresponds to B1-B2.
The values of B2min and B2max can be arbitrarily large โ go off โ but their difference must not exceed approximately 9e23, and that's subject to the number of blocks k. ๐ฆ
โจ FACTORING METHOD โจ
-pm1โ Perform P-1 instead of the default method (which is ECM). Switch it up bestie ๐-pp1โ Perform P+1 instead of the default method (which is, again, ECM). โจ
โจ GROUP AND INITIAL POINT PARAMETERS โจ
-x0xโ[ECM, P-1, P+1]Usex(an arbitrary-precision integer or rational) as the initial point. For example,-x0 1/3is valid โ yes, a fraction, we love to see it. ๐ If you don't give it,xgets generated from the sigma value for ECM, or at random for P-1 and P+1.-sigmasโ[ECM]Uses(an arbitrary-precision integer) as the curve generator. If you skip it,sis generated at random. ๐ฒ-Aaโ[ECM]Usea(an arbitrary-precision integer) as the curve parameter. If you omit it, it gets generated from the sigma value. ๐-govalโ[ECM, P-1, P+1]Multiply the initial point byval, which can be any valid expression, and it might contain the special characterNas a placeholder for the current input number. Iconic. For example:
ecm -pp1 -go "N^2-1" 1e6 < composite2000
โจ STEP 2 PARAMETERS โจ
-kkโ[ECM, P-1, P+1]Performkblocks in step 2. For a givenB2value, increasingkdecreases the memory usage of step 2 โ at the cost of more CPU time. Trade-offs, bestie, it's giving balance โ๏ธ-treefilefileโ Stores some tables of data in disk files to reduce the amount of memory occupied in step 2, at the expense of disk I/O. Data will be written to filesfile.1,file.2etc. Heads up though: this does not work with fast stage 2 for P+1 and P-1. ๐ญ-powernโ[ECM]Usex^nfor Brent-Suyama's extension (-power 1disables Brent-Suyama's extension entirely). The default polynomial is chosen depending on the method andB2. ๐งฎ-dicksonnโ[ECM]Use degree-nDickson's polynomial for Brent-Suyama's extension. โจ-maxmemnโ Use at mostnmegabytes of memory in stage 2. Memory budget era ๐ธ-ntt,-no-nttโ Enable or disable the Number-Theoretic Transform code for polynomial arithmetic in stage 2. With NTT,dFis chosen to be a power of 2, and is limited by the number of suitable primes that fit in a machine word (which is a limitation only on 32-bit systems, so if you're on 64-bit, chill ๐ง). The-no-nttvariant uses more memory, but is faster than NTT with large input numbers. By default, NTT is used for P-1, P+1, and for ECM on numbers of size at most 30 machine words.
โจ OUTPUT โจ
-qโ Quiet mode. ๐คซ Found factorizations are printed on standard output, with factors separated by white spaces, one line per input number (and if no factor was found, the input number is simply copied). No drama, just facts.-vโ Verbose mode. More information gets printed, and more-voptions increase verbosity. With one-v, you get the kind of modular multiplication used, the initialx0value, step 2 parameters and progress, plus expected curves and time to find factors of different sizes for ECM. With-v -v, theAvalue for ECM and residues at the end of step 1 and step 2 get printed. More-vprints internal data for debugging. ๐ Spill the tea, honestly.-timestampโ Print a time stamp whenever a new ECM curve or P+1 or P-1 run is processed. โฐ
โจ MODULAR ARITHMETIC OPTIONS โจ
There are several algorithms available for modular multiplication, and the program tries to find the best one for each input. But if you want to be that girl and force a specific method, these are your options:
-mpzmodโ Use GMP'smpz_modfunction (sub-quadratic for large inputs, but it induces some overhead for small ones). ๐ซ-modmulnโ Use Montgomery's multiplication (quadratic version). Usually the best method for small input. ๐ฅ-redcโ Use Montgomery's multiplication (sub-quadratic version). Theoretically optimal for large input. ๐-nobase2โ Disable the special base-2 code (which is used when the input number is a large factor of2^n+1or2^n-1, see-v). ๐-base2nโ Force use of the special base-2 code. The input number must divide2^n+1ifn > 0, or2^|n|-1ifn < 0. โ ๏ธ
โจ FILE I/O โจ
These options let you perform step 1 and step 2 separately โ on different machines, at different times, or using different software. And bestie, specifically: George Woltman's Prime95/mprime program can produce step 1 output suitable for resuming with GMP-ECM. ๐ค It can also be useful to split step 2 into several runs, using the B2min-B2max option.
-inpfileโ Take input fromfileinstead of from standard input. ๐-savefileโ Save the result of step 1 infile. Iffilealready exists, an error is raised. Example: to perform only step 1 withB1=1000000on the composite number in the file"c155"and save its result in file"foo", use:
ecm -save foo 1e6 1 < c155
-saveafileโ Like-save, but it appends to existing files. ๐-resumefileโ Resume residues fromfile, and it reads from standard input iffileis"-". Example: to perform step 2 following the above step 1 computation, use:
ecm -resume foo 1e6
-chkpointfileโ Periodically write the current residue in stage 1 tofile. In case of a power failure, etc., the computation can be continued with the-resumeoption. ๐พ (surviving the chaos, we love to see it)
ecm -chkpnt foo -pm1 1e10 < largenumber.txt
โจ LOOP MODE โจ
The โloop modeโ (that's option -c n) lets you run several curves on each input number. The following options control how it behaves. ๐
-cnโ Performnruns on each input number (default is one). This option is mainly useful for P+1 (for example withn=3) or for ECM, wherencould be set to the expected number of curves needed to find a d-digit factor with a given step 1 bound. This option is incompatible with-resume,-sigma,-x0. Giving-c 0produces an infinite loop until a factor is found. ๐ตโ๐ซ (not me typing-c 0and forgetting about it, fr fr)-oneโ In loop mode, stop when a factor is found. The default is to continue until the cofactor is prime or the specified number of runs are done. โ-bโ Breadth-first processing: in loop mode, run one curve for each input number, then a second curve for each one, and so on. This is the default mode with-inp. ๐-dโ Depth-first processing: in loop mode, runncurves for the first number, thenncurves for the second one, and so on. This is the default mode with standard input. ๐ณ๏ธ-venโ In loop mode, in the second and following runs, output only expressions that have at mostncharacters. Default is-ve 0. โ๏ธ-inโ In loop mode, incrementB1bynafter each curve. ๐-Inโ In loop mode, multiplyB1by a factor depending onnafter each curve. Default is one, which should be optimal on one machine, while-I 10could be used when trying to factor the same number simultaneously on 10 identical machines. ๐ฅ๏ธ๐ฅ๏ธ๐ฅ๏ธ
โจ SHELL COMMAND EXECUTION โจ
These options (typo in the original, we keep it ๐ ) allow for executing shell commands to supplement functionality to GMP-ECM. Very collab of them. ๐ค
-prpcmdcmdโ Execute commandcmdto test primality of factors and cofactors, instead of GMP-ECM's own functions. The number to test is passed viastdin. An exit code of0is interpreted as โprobably primeโ, a non-zero exit code as โcompositeโ. ๐ต๏ธ-faccmdcmdโ Executes commandcmdwhenever a factor is found by P-1, P+1 or ECM. The input number, factor and cofactor are passed viastdin, each on a line. This could be used i.e. to mail new factors automatically:
ecm -faccmd 'mail -s โ$HOSTNAME found a factorโ
me@myaddress.com' 11e6 < cunningham.in
-idlecmdcmdโ Executes commandcmdbefore each ECM curve, P-1 or P+1 attempt on a number is started. If the exit status ofcmdis non-zero, GMP-ECM terminates immediately, otherwise it continues normally. GMP-ECM is stopped whilecmdruns, offering a way for letting GMP-ECM sleep for example while the system is otherwise busy. ๐ด (self-care for your CPU)
โจ MISCELLANEOUS โจ
-nโ Run the program in โniceโ mode (below normal priority). ๐-nnโ Run the program in โvery niceโ mode (idle priority). ๐ฅน (so polite)-B2scalefโ Multiply the default step 2 boundB2by the floating-point valuef. Example:-B2scale 0.5divides the defaultB2by 2. ๐ช-stage1timenโ Addnseconds to stage 1 time. This is useful to get correct expected time with-vif part of stage 1 was done in another run. โฑ๏ธ-cofdecโ Force cofactor output in decimal (even if expressions are used). ๐ข-h,--helpโ Display a short description ofecmusage, parameters and command line options. ๐-printconfigโ Prints configuration parameters used for the compilation and exits. ๐ ๏ธ
โจ INPUT SYNTAX โจ
The input numbers can have several forms, and honestly? The range. ๐
Raw decimal numbers like 123456789. Simple, clean, we love her.
Comments can be placed in the file: everything after โ//โ is ignored, up to the end of line. ๐ฌ
Line continuation: if a line ends with a backslash character โ\โ, it is considered to continue on the next line. โก๏ธ
Common arithmetic expressions can be used. Example: 3*5+(2+7)^10. ๐ง
Factorial: example 53!. โ
Multi-factorial: example 15!3 means 15*12*9*6*3. โโโ
Primorial: example 11# means 2*3*5*7*11. #๏ธโฃ
Reduced primorial: example 17#5 means 5*7*11*13*17. โ๏ธ
๐ Functions:
GCD(a,b): Greatest common divisor โ exampleGCD(120,28) = 4๐ซถPhi(n,x): n-th Cyclotomic Polynomial evaluated at x โ examplePhi(3,5) = 1 + x + x^2 = 31๐
and bestieโฆ there's more ๐ (this was only part 1, keep reading)
โจ EXIT STATUS โจ
okay bestie, when ecm finally logs off, its exit status is literally the receipts ๐งพ โ it reflects the result of the last ECM curve or P-1/P+1 attempt the program performed. The individual bits are giving very specific energy:
- Bit 0 โ
0if normal program termination,1if error occurred - Bit 1 โ
0if no proper factor was found,1otherwise - Bit 2 โ
0if factor is composite,1if factor is a probable prime - Bit 3 โ
0if cofactor is composite,1if cofactor is a probable prime
so thus, the following exit status values may occur:
0โ Normal program termination, no factor found1โ Error2โ Composite factor found, cofactor is composite6โ Probable prime factor found, cofactor is composite8โ Input number found10โ Composite factor found, cofactor is a probable prime14โ Probable prime factor found, cofactor is a probable prime
๐ BUGS ๐
Report bugs on <https://gitlab.inria.fr/zimmerma/ecm/>. fr fr, they wanna know ๐
๐ AUTHORS ๐
These absolute icons made ecm happen:
- Pierrick Gaudry
<gaudry at lix dot polytechnique dot fr>โ contributed efficient assembly code for combined mul/redc; - Jim Fougeron
<jfoug at cox dot net>โ contributed the expression parser and several command-line options; - Laurent Fousse
<laurent at komite dot net>โ contributed the middle product code, the autoconf/automake tools, and is the maintainer of the Debian package; - Alexander Kruppa
<(lastname)al@loria.fr>โ contributed estimates for probability of success for ECM, the new P+1 and P-1 stage 2 (with P.-L. Montgomery), new AMD64 asm mulredc code, and some other things; - Dave Newman
<david.(lastname)@jesus.ox.ac.uk>โ contributed the Kronecker-Schoenhage and NTT multiplication code; - Jason S. Papadopoulos โ contributed a speedup of the NTT code
- Paul Zimmermann
<zimmerma at loria dot fr>โ is the author of the first version of the program and chief maintainer of GMP-ECM.
Note: email addresses have been obscured, the required substitutions should be obvious.
this iconic manual page is ECM(1), page date 11/03/2023, and the footer also carries April 22, 2003 โ slay, we're done bestie ๐
โจ
๐ฆ where this page comes from
- fedora 43: gmp-ecm 7.0.6-4.fc43 ยท GPL-3.0-or-later
- fedora 43: gmp-ecm 7.0.7-1.fc43 ยท GPL-3.0-or-later
- fedora 44: gmp-ecm 7.0.6-5.fc44 ยท GPL-3.0-or-later
- fedora 44: gmp-ecm 7.0.7-1.fc44 ยท GPL-3.0-or-later
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms