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

Uploaded CPython 3.13macOS 15.0+ ARM64

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

Uploaded CPython 3.13macOS 14.0+ ARM64

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

Uploaded CPython 3.13macOS 13.0+ x86-64

FindAFactor-5.2.1-cp312-cp312-win_amd64.whl (152.7 kB view details)

Uploaded CPython 3.12Windows x86-64

FindAFactor-5.2.1-cp312-cp312-manylinux_2_39_x86_64.whl (142.5 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.39+ x86-64

FindAFactor-5.2.1-cp310-cp310-manylinux_2_35_x86_64.whl (146.7 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.35+ x86-64

FindAFactor-5.2.1-cp38-cp38-manylinux_2_31_x86_64.whl (138.7 kB view details)

Uploaded CPython 3.8manylinux: glibc 2.31+ x86-64

File details

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

File metadata

  • Download URL: findafactor-5.2.1.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.2.1.tar.gz
Algorithm Hash digest
SHA256 4a332c692c91ce361426cae3732518aa0e0f18d5498e66d8b62f7924203812ae
MD5 40a4869d6c299f1899000469333954cb
BLAKE2b-256 82b6e8abc379237b59709c99c688f6ea007f3009e9bde60b6224e981c0c831a1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for FindAFactor-5.2.1-cp313-cp313-macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 a4c6528c35ed2ea3a88372718ada585d9972dc391ae5ca8450ed9be10dfd4b46
MD5 78401eb6660682c2e01b24d18adb4f58
BLAKE2b-256 5defa779ed32bad47738010915186d7362e53974d7c6515aa097d381621092ea

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for FindAFactor-5.2.1-cp313-cp313-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 d5f3119312fd29f0cd872e32a46c4ba68592f6867f391cc70ea8875c26a5c028
MD5 6feafd99fbaffe0fed25b76ba7e87172
BLAKE2b-256 8fd9c0b3589aaaa8e081d4bc45dab4720c1e7bcb3ec70121661b55eec5b6867f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for FindAFactor-5.2.1-cp313-cp313-macosx_13_0_x86_64.whl
Algorithm Hash digest
SHA256 55634c82811e0f5fbd3eedbd2a20e495abf2f03b416e747f59d572105940c39d
MD5 e178af766286047dda8bf526454dccf6
BLAKE2b-256 65cb63f798e4ca6c318e2c47f14f9c3b3e6bbed150011bab5e6278af28064a3a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for FindAFactor-5.2.1-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 f27cef13e969e181ea385582abba1204a543bbe0949c74152c5a58b5933bde2a
MD5 e30347fed2ef78cdae1d6315358d8f4c
BLAKE2b-256 2943ca0a0a507256cd4041ba397729ae63a96857c939043437e8bf97ed0ad64a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for FindAFactor-5.2.1-cp312-cp312-manylinux_2_39_x86_64.whl
Algorithm Hash digest
SHA256 0c068b1663de8606518a384c69fed68ea42112942ea8ae4c4987a0bf8b9d8226
MD5 7ecf46f409c21c375ca41fa991f44f7d
BLAKE2b-256 62ecc8fa8f708ce2654e53b5e0b41ac0ff7ccf7a41c89b9ac9a4a7efce1658ae

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for FindAFactor-5.2.1-cp310-cp310-manylinux_2_35_x86_64.whl
Algorithm Hash digest
SHA256 f4bf399bb6a88dc7f8b6552809ea56b754bc72269fa5247b7ea35dc8ed7f6c32
MD5 afef775f4567861009b0f44e464c4cee
BLAKE2b-256 15326582de7424ae5497ea64b3f68de1d71b9ca52d8f8b5c1025d211986de5a5

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for FindAFactor-5.2.1-cp38-cp38-manylinux_2_31_x86_64.whl
Algorithm Hash digest
SHA256 d9ecb9754123399ac53c7b4cdee73d7a8652a6306b32e3186a3d91394f9a6956
MD5 cd0cd249b8c0ff71912512d6f05e51d9
BLAKE2b-256 0065ef1c060610f0e6b94b18f0164c6a2af1754f6705113ab7514edb8860b174

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