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

Uploaded CPython 3.13macOS 15.0+ ARM64

FindAFactor-5.2.0-cp313-cp313-macosx_14_0_arm64.whl (118.6 kB view details)

Uploaded CPython 3.13macOS 14.0+ ARM64

FindAFactor-5.2.0-cp313-cp313-macosx_13_0_x86_64.whl (133.7 kB view details)

Uploaded CPython 3.13macOS 13.0+ x86-64

FindAFactor-5.2.0-cp312-cp312-win_amd64.whl (153.4 kB view details)

Uploaded CPython 3.12Windows x86-64

FindAFactor-5.2.0-cp312-cp312-manylinux_2_39_x86_64.whl (142.9 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.39+ x86-64

FindAFactor-5.2.0-cp310-cp310-manylinux_2_35_x86_64.whl (147.1 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.35+ x86-64

FindAFactor-5.2.0-cp38-cp38-manylinux_2_31_x86_64.whl (140.4 kB view details)

Uploaded CPython 3.8manylinux: glibc 2.31+ x86-64

File details

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

File metadata

  • Download URL: findafactor-5.2.0.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.0.tar.gz
Algorithm Hash digest
SHA256 0c49d8cb6d5872be91a63f0c578a7c47d8621e2c08d29e89d34c5d8ef93eef2a
MD5 cc5cb908dc11b72671cd9a93092b6044
BLAKE2b-256 5fb0e069c915ee9eebee6de3d4dc68f8d5ddeb3e0cf8cec708a9c7499188e5cd

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for FindAFactor-5.2.0-cp313-cp313-macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 9a56d8f4c4e7a1f23a43de0d1bad35e3775f6f70ccf1373ce895faea3d7a806d
MD5 17033e818c0d3323b15fb4365367623c
BLAKE2b-256 e60d7f69315db735c16d98ea2ac00943f281c878dc0c64aeb14800df1c55ba41

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for FindAFactor-5.2.0-cp313-cp313-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 5cfd7ddea8ff481b6e48f6ae3aec4e92762ba739d5bcac46787339ce6fb6a288
MD5 81197323c3076a3e654398374ddce8d8
BLAKE2b-256 9db6adea0f1f4f6d4c7d9a04c93604518aa59c1007ac8a415d1494b6ad18e7b7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for FindAFactor-5.2.0-cp313-cp313-macosx_13_0_x86_64.whl
Algorithm Hash digest
SHA256 4e6337551d7a72bfd84f53da0fb0063749a90790ea0f9ad5addff656e5287368
MD5 bcd8e809b4876f56f446a9abfa677bd5
BLAKE2b-256 4bfc1f311250510d68af102e84e729fcff545255c3b373586a4212a4815a36cd

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for FindAFactor-5.2.0-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 6194be3178de11f99cc9d164be57ac84a39b967d6a3e939618195adc8c7c9ced
MD5 5e2a9a0cc76f0a15ed09e4304189b06d
BLAKE2b-256 3657ba8ae3713728864c918adb1f8f58c25f986c9d319ed2ccc7ed1e811070d4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for FindAFactor-5.2.0-cp312-cp312-manylinux_2_39_x86_64.whl
Algorithm Hash digest
SHA256 d9c20450d7c6581dd90121aaf7c9bea196a076e70ad5d4eb579a3a3b7972140d
MD5 a5f7ee4a277fee475bbd7d4e98201a8a
BLAKE2b-256 efd523f03a51cb46ef3afecba98983ba0590cede5206ecb6e22bc1bb50d1decb

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for FindAFactor-5.2.0-cp310-cp310-manylinux_2_35_x86_64.whl
Algorithm Hash digest
SHA256 4bbe4d20a0bb8e8dfc22780cebe1b7050e0f793d502a992126602d864240b60f
MD5 d72b2b4cdce85ddc0e3ce1c9db4356d1
BLAKE2b-256 bd7c5e9d7b54aba0f3065810daf6aeac2c00f6cbcf9ad22d6c8d1e59b7f2dd03

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for FindAFactor-5.2.0-cp38-cp38-manylinux_2_31_x86_64.whl
Algorithm Hash digest
SHA256 f958bcf7d897ee0b59ada2c8361abec9e70fbb3382271f275b3a129e0f670592
MD5 8328a8f435718c73353d57bfe3de6198
BLAKE2b-256 798b62dad1783c1a04fbc07a65fced5f4ad2ce1f0cad13c8029a7ea342df8c43

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