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.0): This controls the number of rows sieved for Gaussian elimination before terminating the sieve and is calibrated such that it linearly multiplies one plus 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 help with 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.1.5.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.1.5-cp313-cp313-macosx_15_0_arm64.whl (118.2 kB view details)

Uploaded CPython 3.13macOS 15.0+ ARM64

FindAFactor-5.1.5-cp313-cp313-macosx_14_0_arm64.whl (117.8 kB view details)

Uploaded CPython 3.13macOS 14.0+ ARM64

FindAFactor-5.1.5-cp313-cp313-macosx_13_0_x86_64.whl (132.6 kB view details)

Uploaded CPython 3.13macOS 13.0+ x86-64

FindAFactor-5.1.5-cp312-cp312-win_amd64.whl (152.8 kB view details)

Uploaded CPython 3.12Windows x86-64

FindAFactor-5.1.5-cp312-cp312-manylinux_2_39_x86_64.whl (142.2 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.39+ x86-64

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

Uploaded CPython 3.10manylinux: glibc 2.35+ x86-64

FindAFactor-5.1.5-cp38-cp38-manylinux_2_31_x86_64.whl (139.7 kB view details)

Uploaded CPython 3.8manylinux: glibc 2.31+ x86-64

File details

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

File metadata

  • Download URL: findafactor-5.1.5.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.1.5.tar.gz
Algorithm Hash digest
SHA256 f9e23b39be0380f27056c7ac336cfaa00a6a12d19008a3a98a4a3b29bd4552b0
MD5 594e7d290f8d675bf4ef981716942df2
BLAKE2b-256 b06027cd8dbb69f91df6d1a99677c593bcdc10105c7e3164754602446b5f327a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for FindAFactor-5.1.5-cp313-cp313-macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 fa5839de3c8daab6d5d01f4542e8f0f3fbdf0b81131bc72227fd9563a2286ef7
MD5 589156e10a6cad1b0cc10e35f54843d4
BLAKE2b-256 252116b211267ff132ba7feceb1c4469db2a95a9676ebc7163fc6cec727ddbd4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for FindAFactor-5.1.5-cp313-cp313-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 3a87ba4d9838e4b2883231836b7ed8d261c34db35a9d35d0b2f70f1c724d2363
MD5 2d13ae6dde073b8d3bfadf118aa0ff44
BLAKE2b-256 aa527cb626ab6477e03861082e6ea7868cc7f4510224d95f250dd73489cc84f7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for FindAFactor-5.1.5-cp313-cp313-macosx_13_0_x86_64.whl
Algorithm Hash digest
SHA256 50cc156b259febfc46366a3e96076cf4e34033c696002ead72f1298a0b3c09fc
MD5 5bcc4c13303c106493f26463995b89f0
BLAKE2b-256 11ee6c0b86e2adc4c1a9c43be9d1bcb3770f65bca9fd5ee6918501fadf26a719

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for FindAFactor-5.1.5-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 0848f092be2f1bca452366c0dfc68e2c445bd26009d1281c3e0fe240873fd9f2
MD5 42167a90a03564740abda60f0f820b5f
BLAKE2b-256 c24851c8f40ca63e84b3ea490917387d942906bb4a22da231de2fb9be80689fd

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for FindAFactor-5.1.5-cp312-cp312-manylinux_2_39_x86_64.whl
Algorithm Hash digest
SHA256 eede315347da5e9de6b7f4561479630ab7b52d6413fe235b5e7116c3a31da2bb
MD5 637846fa3d3e2d86fa0ccdfd180e51f3
BLAKE2b-256 e3b97c566eec25af6ea7a87df2d26eb52a6ab9f2aa9838d66c6a7cffd532c1d9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for FindAFactor-5.1.5-cp310-cp310-manylinux_2_35_x86_64.whl
Algorithm Hash digest
SHA256 1efc3ebc3c1a6f5ecae314e67a8b95136901b4a2460c5a3e357d3a25a8fbfb03
MD5 4b28735b985df4f1e4e89b112904b0cb
BLAKE2b-256 cea6dccd9937dea74e11b0559e73e047594933677416f10d536e70b0a3472f85

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for FindAFactor-5.1.5-cp38-cp38-manylinux_2_31_x86_64.whl
Algorithm Hash digest
SHA256 3edd51505f13d0d65c1f8ab7fed08db4666df576fd496a191b784a1ccd71b765
MD5 39eac25b138b34a4c276e6da66aa97dc
BLAKE2b-256 1788554b073562e8d60532fbf0a855760801f2c2013eadb0670193c255a7904b

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