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 map the sieving intervale of FACTOR_FINDER mode onto non-multiples on the wheel, if the level is set above 1 (which might not actually pay dividends in practical complexity, but we leave it for your experimentation). In FACTOR_FINDER mode, wheel factorization multiples are systematically avoided by construction, while gear factorization multiples are just rejected after-the-fact, without special construction to avoid them. (It is possible in theory to implement handling for gear factorization by construction, though, and that might be added in a future release.)
  • 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.6.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.6-cp313-cp313-macosx_15_0_arm64.whl (118.0 kB view details)

Uploaded CPython 3.13macOS 15.0+ ARM64

FindAFactor-5.2.6-cp313-cp313-macosx_14_0_arm64.whl (117.4 kB view details)

Uploaded CPython 3.13macOS 14.0+ ARM64

FindAFactor-5.2.6-cp313-cp313-macosx_13_0_x86_64.whl (131.9 kB view details)

Uploaded CPython 3.13macOS 13.0+ x86-64

FindAFactor-5.2.6-cp312-cp312-win_amd64.whl (152.2 kB view details)

Uploaded CPython 3.12Windows x86-64

FindAFactor-5.2.6-cp312-cp312-manylinux_2_39_x86_64.whl (142.6 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.39+ x86-64

FindAFactor-5.2.6-cp310-cp310-manylinux_2_35_x86_64.whl (147.0 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.35+ x86-64

FindAFactor-5.2.6-cp38-cp38-manylinux_2_31_x86_64.whl (139.3 kB view details)

Uploaded CPython 3.8manylinux: glibc 2.31+ x86-64

File details

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

File metadata

  • Download URL: findafactor-5.2.6.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.6.tar.gz
Algorithm Hash digest
SHA256 808f2b4e5f9f6e9527b3b931a45167d74323532c91bc8aeda424e667066ab9b4
MD5 0297dab1c292b7de8d74286feffff30d
BLAKE2b-256 229a4d71163d5ba089d7887458ce9043477c7364d0460fb14aa878189229c14b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for FindAFactor-5.2.6-cp313-cp313-macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 cbbc1af9f05142bf5243d85f04ea2af7b91dc366b1b621c4ee4496e12436891f
MD5 33278ae24d931ec4d05dd2c856a2b21a
BLAKE2b-256 62e55411530e01395b655b81e3d5804ebc1b9a3ab12f77110c5756e53431a73a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for FindAFactor-5.2.6-cp313-cp313-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 68c0d35489e7d1fcc887919f5fa5b3062b8aa4b1d872381a4bd5b43cdc882a2a
MD5 3bdfe886e73a194cfd7ab23c34142d0f
BLAKE2b-256 6cac97b11edcfcfde6861cf6bd479ccb464da082c7219350e6516ef65bb111de

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for FindAFactor-5.2.6-cp313-cp313-macosx_13_0_x86_64.whl
Algorithm Hash digest
SHA256 725f603b92a4eda024d5d8604a95f1854b0ff13fd9c10bdbbb97aacd5cbb3de9
MD5 47d365f0e317d39582b11e5c92a4ac74
BLAKE2b-256 58cd34c499d90eb03317f11620c1a06ce7d346f435a142a0195c80b0471cca91

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for FindAFactor-5.2.6-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 3a00e0df9a570fe5fcab0968e971709152a0ba474024f3a1a6d46180c9c8de49
MD5 526f9760778fcd5c18b212cd8741ffcb
BLAKE2b-256 96b2db3d087b02f13df732c29500c92912647ef6b90fdeeea2d91709e54eb10b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for FindAFactor-5.2.6-cp312-cp312-manylinux_2_39_x86_64.whl
Algorithm Hash digest
SHA256 6b07b45b62deeef12444e5160f2815c3272f946700d17714d1a42be2a94e8a72
MD5 3244195cf4d938ea1239f030842ed5f8
BLAKE2b-256 6397f8d59b6014a16bc0ba4cb0c3327fdb4ad5d8e5a1de7a418bd0617b1e1866

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for FindAFactor-5.2.6-cp310-cp310-manylinux_2_35_x86_64.whl
Algorithm Hash digest
SHA256 e68140074f46790afe778c5e3b5f39fa41336e90ab5546af72f191b618761184
MD5 e8bf3e1f5a137a0b6a245d036d0d77fd
BLAKE2b-256 92925eb8ae46c6be21b8d91eb667551696e67f7b2ae38dc5fc0e8b27dd006059

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for FindAFactor-5.2.6-cp38-cp38-manylinux_2_31_x86_64.whl
Algorithm Hash digest
SHA256 f05b516fc8b7409f63232398c3cae95509c44cdcc96725d0b449006534aea465
MD5 5926f9b54cd14b50ae864aafeda4143b
BLAKE2b-256 f9137f01a3e08713e55adfa81409b60bd3b04a1a2b9787ac963868b6ebb6f540

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