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.4.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.4-cp313-cp313-macosx_15_0_arm64.whl (113.1 kB view details)

Uploaded CPython 3.13macOS 15.0+ ARM64

FindAFactor-5.0.4-cp313-cp313-macosx_14_0_arm64.whl (112.4 kB view details)

Uploaded CPython 3.13macOS 14.0+ ARM64

FindAFactor-5.0.4-cp313-cp313-macosx_13_0_x86_64.whl (126.8 kB view details)

Uploaded CPython 3.13macOS 13.0+ x86-64

FindAFactor-5.0.4-cp312-cp312-win_amd64.whl (148.8 kB view details)

Uploaded CPython 3.12Windows x86-64

FindAFactor-5.0.4-cp312-cp312-manylinux_2_39_x86_64.whl (137.6 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.39+ x86-64

FindAFactor-5.0.4-cp310-cp310-manylinux_2_35_x86_64.whl (145.0 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.35+ x86-64

FindAFactor-5.0.4-cp38-cp38-manylinux_2_31_x86_64.whl (137.7 kB view details)

Uploaded CPython 3.8manylinux: glibc 2.31+ x86-64

File details

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

File metadata

  • Download URL: findafactor-5.0.4.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.4.tar.gz
Algorithm Hash digest
SHA256 8404f447bb3958730ef8813c73f228f507c15a29c62fa429125b3ea64d40425b
MD5 d59d6e770c33f2f5ccb1e6e779552ea1
BLAKE2b-256 3681b160fe5fe7f79f69f8137ac02fbffbaefd8ae98c6e2d67af78ec40c4f243

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for FindAFactor-5.0.4-cp313-cp313-macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 f6f3d3dd24766b62d0499c3fea72d2737eef307a7bd2e014b2a844e868fc6338
MD5 e12583554fe8fe22a3621ee245b7a6fc
BLAKE2b-256 5ed9fbabfc17a8b19d97a06b1c5226e3fa2f126943f4ebd96c06b1696e2e3366

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for FindAFactor-5.0.4-cp313-cp313-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 7a1555ebeca0f6c1ac4b42cf609ab1268d291313f83e47513978233abfe7add2
MD5 4aa504d19d4cf619221179d610d36419
BLAKE2b-256 9841224883c75ac9a837ef519311e2c59ad836df9369b336ea8850dcfc4c411a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for FindAFactor-5.0.4-cp313-cp313-macosx_13_0_x86_64.whl
Algorithm Hash digest
SHA256 e0afc2612df4da67b0c60db8055e1ded91aa8933edb8af56e2607ba8d5e7b2a6
MD5 5646a4080c498cd1e4b73e01699f2200
BLAKE2b-256 ef96ffebb42e870a8736a071c5250de31243a1ec59f3916450f987df3ac4be8e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for FindAFactor-5.0.4-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 b50ac880e904382f9dc2fb60d063cde56f0803a40b7f8ae72d1a78db17f4ff92
MD5 86b6c6d656529a2ffe4f4ccff4203f99
BLAKE2b-256 8b3184d4b663564e445cf38a0a15c7b64e74dcb636466d6d8227d2e8eb0f3f4e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for FindAFactor-5.0.4-cp312-cp312-manylinux_2_39_x86_64.whl
Algorithm Hash digest
SHA256 2eff9fa9e892733e5eb7d218172c38192c208fc964f079297874765f9f7f0b8e
MD5 9a4a271b4cadb969e0380cc64b55f5a0
BLAKE2b-256 b4ea5b3b58e18a5119283c0e96d671e624f4c5eae88b4ba22e2c365b88780a9f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for FindAFactor-5.0.4-cp310-cp310-manylinux_2_35_x86_64.whl
Algorithm Hash digest
SHA256 aa2c29602f1e1fdcbceba570bc4056993332b4fdb23b61675d6000b1946e3921
MD5 a95ed58604530d96106c1fd2500a6164
BLAKE2b-256 0603f2ae6df5af3b03366486fb55e6d0b2993bbf035718e14550d73b0ec0a4f5

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for FindAFactor-5.0.4-cp38-cp38-manylinux_2_31_x86_64.whl
Algorithm Hash digest
SHA256 6b784000a84dda537993288810164d158654872bd462d0406a7ab641b161d798
MD5 0b8076db5ba7df63b3e3fc8768e2841b
BLAKE2b-256 4c40f2ff0ab58b16995f1374029733986c8d18ad0050fe69165c548092231c20

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