Skip to main content

Find any nontrivial factor of a number

Project description

FindAFactor

Find any nontrivial factor of a number

PyPI Downloads

Copyright and license

(c) Daniel Strano and the Qrack contributors 2017-2025. All rights reserved.

Installation

From PyPi:

pip3 install FindAFactor

From Source: install pybind11, then

pip3 install .

in the root source directory (with setup.py).

Windows users might find Windows Subsystem Linux (WSL) to be the easier and preferred choice for installation.

Usage

from FindAFactor import find_a_factor, FactoringMethod

to_factor = 1000

factor = find_a_factor(
    to_factor,
    method=FactoringMethod.PRIME_SOLVER,
    node_count=1, node_id=0,
    gear_factorization_level=11,
    wheel_factorization_level=11,
    sieving_bound_multiplier=1.0,
    smoothness_bound_multiplier=1.0,
    gaussian_elimination_row_multiplier=1.2,
    check_small_factors=False
)

The find_a_factor() function should return any nontrivial factor of to_factor (that is, any factor besides 1 or to_factor) if it exists. If a nontrivial factor does not exist (i.e., the number to factor is prime), the function will return 1 or the original to_factor.

  • method (default value: PRIME_SOLVER/0): PRIME_SOLVER/0 will prove that a number is prime (by failing to find any factors with wheel and gear factorization). FACTOR_FINDER/1 is optimized for the assumption that the number has at least two nontrivial factors.
  • node_count (default value: 1): FindAFactor can perform factorization in a distributed manner, across nodes, without network communication! When node_count is set higher than 1, the search space for factors is segmented equally per node. If the number to factor is semiprime, and brute-force search is used instead of congruence of squares, for example, all nodes except the one that happens to contain the (unknown) prime factor less than the square root of to_factor will ultimately return 1, while one node will find and return this factor. For best performance, every node involved in factorization should have roughly the same CPU throughput capacity. For FACTOR_FINDER mode, this splits the sieving range between nodes, but it does not actually coordinate Gaussian elimination rows between nodes.
  • node_id (default value: 0): This is the identifier of this node, when performing distributed factorization with node_count higher than 1. node_id values start at 0 and go as high as (node_count - 1).
  • gear_factorization_level (default value: 1): This is the value up to which "wheel (and gear) factorization" are applied to "brute force." A value of 11 includes all prime factors of 11 and below and works well for PRIME_PROVER, though significantly higher might be preferred in certain cases.
  • wheel_factorization_level (default value: 1): "Wheel" vs. "gear" factorization balances two types of factorization wheel ("wheel" vs. "gear" design) that often work best when the "wheel" is only a few prime number levels lower than gear factorization. Optimized implementation for wheels is only available up to 13. The primes above "wheel" level, up to "gear" level, are the primes used specifically for "gear" factorization. Wheel factorization is also applied to "peturb" FACTOR_FINDER mode into non-multiples on the wheel, if the level is set above 1 (which might not actually work, but we leave it for your experimentation).
  • sieving_bound_multiplier (default value: 1.0): This controls the sieving bound and is calibrated such that it linearly multiplies the square root of the number to factor (for each 1.0 increment). While this might be a huge bound, remember that sieving termination is primarily controlled by when gaussian_elimination_row_multiplier is exactly satisfied.
  • smoothness_bound_multiplier (default value: 1.0): This controls smoothness bound and is calibrated such that it linearliy multiplies exp(0.5 * std::sqrt(log(N) * log(log(N)))) for N being the number to factor (for each 1.0 increment). This was a heuristic suggested by Elara (an OpenAI custom GPT).
  • gaussian_elimination_row_multiplier (default value: 1.2): This controls the number of rows sieved for Gaussian elimination before terminating the sieve and is calibrated such that it linearly multiplies the number of smooth prime columns in the Gaussian elimination matrix (for each 1.0 increment). So long as this setting is appropriately low enough, sieving_bound_multiplier can be set basically arbitrarily high.
  • check_small_factors (default value: False): True performs initial-phase trial division up to the smoothness bound, and False skips it.

All variables defaults can also be controlled by environment variables:

  • FINDAFACTOR_METHOD (integer value)
  • FINDAFACTOR_NODE_COUNT
  • FINDAFACTOR_NODE_ID
  • FINDAFACTOR_GEAR_FACTORIZATION_LEVEL
  • FINDAFACTOR_WHEEL_FACTORIZATION_LEVEL
  • FINDAFACTOR_SIEVING_BOUND_MULTIPLIER
  • FINDAFACTOR_SMOOTHNESS_BOUND_MULTIPLIER
  • FINDAFACTOR_GAUSSIAN_ELIMINATION_ROW_MULTIPLIER
  • FINDAFACTOR_CHECK_SMALL_FACTORS (True if set at all, otherwise False)

About

This library was originally called "Qimcifa" and demonstrated a (Shor's-like) "quantum-inspired" algorithm for integer factoring. It has since been developed into a general factoring algorithm and tool.

Special thanks to OpenAI GPT "Elara," for indicated region of contributed code!

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

findafactor-5.0.2.tar.gz (5.7 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

FindAFactor-5.0.2-cp313-cp313-macosx_15_0_arm64.whl (113.9 kB view details)

Uploaded CPython 3.13macOS 15.0+ ARM64

FindAFactor-5.0.2-cp313-cp313-macosx_14_0_arm64.whl (113.0 kB view details)

Uploaded CPython 3.13macOS 14.0+ ARM64

FindAFactor-5.0.2-cp313-cp313-macosx_13_0_x86_64.whl (127.7 kB view details)

Uploaded CPython 3.13macOS 13.0+ x86-64

FindAFactor-5.0.2-cp312-cp312-win_amd64.whl (149.7 kB view details)

Uploaded CPython 3.12Windows x86-64

FindAFactor-5.0.2-cp312-cp312-manylinux_2_39_x86_64.whl (138.6 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.39+ x86-64

FindAFactor-5.0.2-cp310-cp310-manylinux_2_35_x86_64.whl (146.0 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.35+ x86-64

FindAFactor-5.0.2-cp38-cp38-manylinux_2_31_x86_64.whl (138.5 kB view details)

Uploaded CPython 3.8manylinux: glibc 2.31+ x86-64

File details

Details for the file findafactor-5.0.2.tar.gz.

File metadata

  • Download URL: findafactor-5.0.2.tar.gz
  • Upload date:
  • Size: 5.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.12.3

File hashes

Hashes for findafactor-5.0.2.tar.gz
Algorithm Hash digest
SHA256 23bc8a6b69f8ce98eb28f96cfb730269ad3eb46415436bd6b1dbac10eeb5ec57
MD5 cb03abdd736fdf818fdfe9d31487ca66
BLAKE2b-256 28894b92a256f42661a5516f90002975ec6d61a0f083a20747a9db42ae9889d5

See more details on using hashes here.

File details

Details for the file FindAFactor-5.0.2-cp313-cp313-macosx_15_0_arm64.whl.

File metadata

File hashes

Hashes for FindAFactor-5.0.2-cp313-cp313-macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 7f8b4ca29516c0c975140e3fcb313bd404830bc19ed31ce3a1603efa4c76ea1c
MD5 a23c82dd504fb1a3d7f9603e217140ec
BLAKE2b-256 d994f60cc4315d8363ab7e3d1e9ba364545e6a368f551e0f59d0566549654cd5

See more details on using hashes here.

File details

Details for the file FindAFactor-5.0.2-cp313-cp313-macosx_14_0_arm64.whl.

File metadata

File hashes

Hashes for FindAFactor-5.0.2-cp313-cp313-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 fa97354e5f2e1e44dc0dc220ccedd98070c38057d8c84aeea24583dff5a4c0e4
MD5 6eb616a211ee6e6000bc2585e36bd4f7
BLAKE2b-256 2a3e38d41e3cda7adfb5c8b10a525dc9b58902ea4cbeb5311c2da4a7a83776a8

See more details on using hashes here.

File details

Details for the file FindAFactor-5.0.2-cp313-cp313-macosx_13_0_x86_64.whl.

File metadata

File hashes

Hashes for FindAFactor-5.0.2-cp313-cp313-macosx_13_0_x86_64.whl
Algorithm Hash digest
SHA256 ee2f820a6f32501cfbc7ac03ca7cd7de4b9dc34e914418baa1225daa333f4d22
MD5 3c26d6adc67b139149f4a088da658083
BLAKE2b-256 228715e769408e27b87bfd37101e1f058ceae2c9b7973c40e6877f15b6d5e305

See more details on using hashes here.

File details

Details for the file FindAFactor-5.0.2-cp312-cp312-win_amd64.whl.

File metadata

File hashes

Hashes for FindAFactor-5.0.2-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 6014ec3b24b94ce132c969af630282e8e9db10a6a608db54b2f2314a50ae9d50
MD5 c63b4c4ef10bd34a688147cbf12a3739
BLAKE2b-256 e9d8f53255f98db71c800bc52edeaa95fc65f26c6d1436cd7debd90ee05d0128

See more details on using hashes here.

File details

Details for the file FindAFactor-5.0.2-cp312-cp312-manylinux_2_39_x86_64.whl.

File metadata

File hashes

Hashes for FindAFactor-5.0.2-cp312-cp312-manylinux_2_39_x86_64.whl
Algorithm Hash digest
SHA256 e651cc3675b819fd915d2586b6087e88e7778df415bd2beb7073d2261ee18713
MD5 8ab44858f7813bf5a56878d32fa6efd2
BLAKE2b-256 0f911f05043ae4daf38a30b8055f63149ba704c14ffa6a6d1780759e797b48eb

See more details on using hashes here.

File details

Details for the file FindAFactor-5.0.2-cp310-cp310-manylinux_2_35_x86_64.whl.

File metadata

File hashes

Hashes for FindAFactor-5.0.2-cp310-cp310-manylinux_2_35_x86_64.whl
Algorithm Hash digest
SHA256 5b528de8db2d545c0f1df42778dc2e1a83b5aacab58a6926cd75bb92210e5844
MD5 6067730931855cf9979666a778aa01ef
BLAKE2b-256 88044d2d11f6dc97582b2c66e6105cc178b96eb3efa5c648e05f7de6c3942279

See more details on using hashes here.

File details

Details for the file FindAFactor-5.0.2-cp38-cp38-manylinux_2_31_x86_64.whl.

File metadata

File hashes

Hashes for FindAFactor-5.0.2-cp38-cp38-manylinux_2_31_x86_64.whl
Algorithm Hash digest
SHA256 2f80248b04c03848f41b9430b0be6b6d87fe847b88b47c1a1f57114b1547d5d2
MD5 fc927095dc1da7c9adabbd355ae5e727
BLAKE2b-256 f694939da43b92cdafb59ec55e0ffaa55ead6a18dee5515ea6f7b94b26a89aee

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page