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

Uploaded CPython 3.13macOS 15.0+ ARM64

FindAFactor-5.2.2-cp313-cp313-macosx_14_0_arm64.whl (117.7 kB view details)

Uploaded CPython 3.13macOS 14.0+ ARM64

FindAFactor-5.2.2-cp313-cp313-macosx_13_0_x86_64.whl (132.5 kB view details)

Uploaded CPython 3.13macOS 13.0+ x86-64

FindAFactor-5.2.2-cp312-cp312-win_amd64.whl (152.5 kB view details)

Uploaded CPython 3.12Windows x86-64

FindAFactor-5.2.2-cp312-cp312-manylinux_2_39_x86_64.whl (143.0 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.39+ x86-64

FindAFactor-5.2.2-cp310-cp310-manylinux_2_35_x86_64.whl (147.3 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.35+ x86-64

FindAFactor-5.2.2-cp38-cp38-manylinux_2_31_x86_64.whl (139.8 kB view details)

Uploaded CPython 3.8manylinux: glibc 2.31+ x86-64

File details

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

File metadata

  • Download URL: findafactor-5.2.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.2.2.tar.gz
Algorithm Hash digest
SHA256 b65697cb1647cae128cc9ef071dd5d6685b415600b11ee8e0b255effa742a5da
MD5 c29a0a947f96aefad6b04aa3867aeaa5
BLAKE2b-256 fc05062b6bda53d2477ded5e91aa6afcda4d6756dcbe66e346bc4437c7947cf4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for FindAFactor-5.2.2-cp313-cp313-macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 cbf6d70f040a9a2dfe3fe6b6577d4760b2e7a6cae833c0d40e07cea354e76e44
MD5 8b7380001caf3b2ac41c875b20f56e0c
BLAKE2b-256 11d3011f02beaef33c3bb8a181c1a3724e8dc941b96f024ee93f3f1077d4bc60

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for FindAFactor-5.2.2-cp313-cp313-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 d7ae4c35974f739bf80d4a92fbf06637e4f9a440d76fdf6ddd12a8b8cfcde674
MD5 91074a977118974d4dd185e6ab5d49ff
BLAKE2b-256 07098d4a368bd3feb2b95f0b5c2b1c18c17f018ce6c01161c775bac32460b869

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for FindAFactor-5.2.2-cp313-cp313-macosx_13_0_x86_64.whl
Algorithm Hash digest
SHA256 117d48aedeecae46ca8c0b4a9044e346dc739a1189d3761c1e4869fef4b0ec13
MD5 d10bca7120769b98d6f50a8c113005d1
BLAKE2b-256 85023e888288e8798815a1f8055532c7d684d8fee35c7abc6d4262bd044e47de

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for FindAFactor-5.2.2-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 629f091c3057d8be2bf38573a3667e39b2c967cff28fa1ff93a18b41bc0a9744
MD5 aadef44c6d95ba0a04f2e675e64fddee
BLAKE2b-256 c7d2c0a6a62822ab7e77ca00032395797833438bfb893045baf5924e7ba62f4a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for FindAFactor-5.2.2-cp312-cp312-manylinux_2_39_x86_64.whl
Algorithm Hash digest
SHA256 522413fec3d47990175b37f04e0a9e768fd0ca03f31e7582cd1b19ff04391563
MD5 30f3604fcdf86307c6f65f32bfabd3b3
BLAKE2b-256 947ef68518ba17b19d2c7a750ff3537b9c1b27190968c746364cfdaf03debadd

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for FindAFactor-5.2.2-cp310-cp310-manylinux_2_35_x86_64.whl
Algorithm Hash digest
SHA256 eb7adbbd8b34569af2dd9612af91ae424f75ca147ede9517a45c604c91860717
MD5 4bc4554865f70be0a85e71231c2caa01
BLAKE2b-256 5b8404579c713245430e53c3605591fdf48dcdcae130e6a1a9e09627636c6546

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for FindAFactor-5.2.2-cp38-cp38-manylinux_2_31_x86_64.whl
Algorithm Hash digest
SHA256 0deb95fa591eeb72b5a58f4706209f86b1d9e9b322ce501ce2298c09617a469e
MD5 ac9219e6ca626e8436417bf7285c617a
BLAKE2b-256 6c95e6bfb960b79ecd6d2c5bcc7737e904dfbcf8673bf5f945033577d656b0a2

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