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

Uploaded CPython 3.13macOS 15.0+ ARM64

FindAFactor-5.1.1-cp313-cp313-macosx_14_0_arm64.whl (117.5 kB view details)

Uploaded CPython 3.13macOS 14.0+ ARM64

FindAFactor-5.1.1-cp313-cp313-macosx_13_0_x86_64.whl (132.7 kB view details)

Uploaded CPython 3.13macOS 13.0+ x86-64

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

Uploaded CPython 3.12Windows x86-64

FindAFactor-5.1.1-cp312-cp312-manylinux_2_39_x86_64.whl (142.0 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.39+ x86-64

FindAFactor-5.1.1-cp310-cp310-manylinux_2_35_x86_64.whl (145.8 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.35+ x86-64

FindAFactor-5.1.1-cp38-cp38-manylinux_2_31_x86_64.whl (140.0 kB view details)

Uploaded CPython 3.8manylinux: glibc 2.31+ x86-64

File details

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

File metadata

  • Download URL: findafactor-5.1.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.1.1.tar.gz
Algorithm Hash digest
SHA256 37972fb7b7ebfb716536ebb5ca782f9ba9d64b7ae3c2d95275463678d45bd505
MD5 34c4a5c4aa66c6b16524d79d3b94ee07
BLAKE2b-256 e0a3dce3d57be14c983c90fd7cb13ed072636f690326f1319d7a4dfd9ddc1d9f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for FindAFactor-5.1.1-cp313-cp313-macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 1f3a862aa4a5892cdcb60e07e2ae5750e2f383069a0fb0f7185a03d9927a3a03
MD5 cc5e9b8f7654fdd116ff44931b37f5f4
BLAKE2b-256 d004f14d661797a27fa20fd021ae3beb027d259df7f4f86160b5fc69fc4e54f7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for FindAFactor-5.1.1-cp313-cp313-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 f2bdfe5172f20dfe1da9e7b03e7227a63185fb21f52472cc4100568374b3d8da
MD5 ded48ca2758e76e7d4b3974bad804eb0
BLAKE2b-256 06d0aaddb9794e0c69452aafa18ed60ecd8f7e0cd72272e960ff596040841fae

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for FindAFactor-5.1.1-cp313-cp313-macosx_13_0_x86_64.whl
Algorithm Hash digest
SHA256 2707c899e4945a43bc436fd415c64e27d35af3f03b5e38785a04e2fe4fbb1c32
MD5 0da19c02dfac6a1e114bcc8aa50fea1e
BLAKE2b-256 ad08c190a73589c80a2357327e77052209a14dd9f610febae2cd151356aeb83e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for FindAFactor-5.1.1-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 ffa843edb3c245816785a756c97834068ad719699e3156048e721cbb910f5b25
MD5 4270e382768a0f6b2585fd75ee2e0e8a
BLAKE2b-256 3019ef6803ce4dce3096cc7c0889b1ecdca1332f862558a1f75e49731cb9b22b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for FindAFactor-5.1.1-cp312-cp312-manylinux_2_39_x86_64.whl
Algorithm Hash digest
SHA256 6252562d676fe700819aa8b564d0b62e633bcd0fc099306aa8169d6821899d3e
MD5 3768d8c484bcdd610dda70bf1169a592
BLAKE2b-256 94e3b1d357ec5ef27d48923fe4c45e9ef7e8bca644a5fcaffb4640d3d9730876

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for FindAFactor-5.1.1-cp310-cp310-manylinux_2_35_x86_64.whl
Algorithm Hash digest
SHA256 777593e34c6a4ce2f2dfbdb32d41850b2970b50da902c05f7f4fa01675d2cfee
MD5 a9c58f8a457e46a37af46f4aecfebb8d
BLAKE2b-256 5dd670f4cd5ee914996fe3483fdd4dd2965ae4f9e293db095d78f5fdef6f3fbd

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for FindAFactor-5.1.1-cp38-cp38-manylinux_2_31_x86_64.whl
Algorithm Hash digest
SHA256 31d1ab8a779f5eb1830af2579c4c4b1744c562b36906fdae7f727c5e80351392
MD5 4c48b56357e411f40a448ed80fcb6987
BLAKE2b-256 4ea3808949f6926e86b075013132276caff8c5e5387a8a2190c067182ec193b7

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