MyNixOS website logo
Description

Factoring integers and polynomials.

This package contains a reference implementation library of factoring algorithms for integers and univariate polynomials

The factor package is a Haskell library for factoring integers and polynomials, implementing the following algorithms:

  • Number field sieve (NFS) for factoring arbitrary integers
  • Elliptic curve method (ECM) for finding "small" factors of integers
  • Miller-Rabin probabilistic primality test for integers
  • Berlekamp-Zassenhaus algorithm for factoring integer polynomials
  • Berlekamp algorithm for factoring polynomials over GF(p) (for small primes p)
  • Cantor–Zassenhaus algorithm for factoring polynomials over GF(p) (for arbitrary odd primes p)

This software is released under the MIT License.

Install

Installing the factor package requires cabal:

git clone https://github.com/gilith/factor.git
cd factor
cabal install --enable-tests

The factor package contains an executable called factor, which is run as follows:

Usage: factor [options] "expression to factor"
      --trial=N       Set trial division maximum to N
      --ecm-primes=N  Limit ECM to first N primes (use - for no limit)
      --nfs-chars=N   Use N quadratic characters in NFS
      --nfs-verbose   Show complete lists in NFS verbose messages
  -v  --verbose       Enable verbose messages
  -t  --timestamp     Prepend verbose messages with timestamp
      --version       Print version
  -h  --help          Show help

Example input expressions:

  2047               Concrete integer
  2^2^7 + 1          Integer expression
  N[100]             Random 100-bit positive integer
  P[50] * P[50]      Product of random 50-bit primes
  x^4 - 10*x^2 + 1   Polynomial over the integers
  x^5^2 - x (mod 5)  Polynomial over GF(5)

Let expressions are supported: let p = P[4] in x^p - x (mod p)
Multivariate polynomials (e.g., y^2 - x^3 - a*x - b) are not supported

Test and Profile

Use cabal to run the test suite:

cabal test

Profiles of the time and memory requirements for factoring inputs of various sizes:

The following recipe can be used to visualize the dynamic memory usage of the number field sieve:

cabal clean
cabal configure --enable-profiling
cabal build
factor +RTS -hc -RTS -v --ecm-primes 0 'P[35] * P[35]'
hp2ps -e8in -c factor.hp
gm convert -density 180 factor.ps factor.png
xview factor.png

References

Comments in the code contain references to descriptions of the specific implemented algorithms, and the following references helped with general understanding of the number field sieve:

Metadata

Version

1.6

License

Executables (1)

  • bin/factor

Platforms (75)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-darwin
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-darwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows