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.2): This controls the number of rows sieved for Gaussian elimination before terminating the sieve and is calibrated such that it linearly multiplies 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 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.0.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.0.1-cp313-cp313-macosx_15_0_arm64.whl (113.9 kB view details)

Uploaded CPython 3.13macOS 15.0+ ARM64

FindAFactor-5.0.1-cp313-cp313-macosx_14_0_arm64.whl (113.0 kB view details)

Uploaded CPython 3.13macOS 14.0+ ARM64

FindAFactor-5.0.1-cp313-cp313-macosx_13_0_x86_64.whl (127.8 kB view details)

Uploaded CPython 3.13macOS 13.0+ x86-64

FindAFactor-5.0.1-cp312-cp312-win_amd64.whl (149.8 kB view details)

Uploaded CPython 3.12Windows x86-64

FindAFactor-5.0.1-cp312-cp312-manylinux_2_39_x86_64.whl (138.5 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.39+ x86-64

FindAFactor-5.0.1-cp310-cp310-manylinux_2_35_x86_64.whl (146.0 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.35+ x86-64

FindAFactor-5.0.1-cp38-cp38-manylinux_2_31_x86_64.whl (138.4 kB view details)

Uploaded CPython 3.8manylinux: glibc 2.31+ x86-64

File details

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

File metadata

  • Download URL: findafactor-5.0.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.0.1.tar.gz
Algorithm Hash digest
SHA256 64fa7b6377b4064c244dfd4745f531264429d5204ec5dd0b89dd94c66399c80d
MD5 94efda00e40d746a36d0be354c6d24fd
BLAKE2b-256 9ee3336c5acf71a64ee0ddb2cf708c5b912f58b906b5a8e3bbe5d2f80ccd47ed

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for FindAFactor-5.0.1-cp313-cp313-macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 3b0deab9a727da8fcf1da9fee9eb84790ce18decd822dd9ce94dab748ff57399
MD5 208f402c20e65d789b597c4434a2569b
BLAKE2b-256 fa03f5f57f90e95919267eab6a8ccbbe16cfd9a10e6055c5cc94bd7f448aec98

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for FindAFactor-5.0.1-cp313-cp313-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 7eee8ed65518ed864a9dd7e42d2b115f096a51a7b12067bf848e8c0cf6656b98
MD5 d471b5c776f309b81c4d794ccd3110e1
BLAKE2b-256 137f1f8bd30857fcf087e91fb6e724a26c5aaa262b3aed1ff139c14df39f4928

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for FindAFactor-5.0.1-cp313-cp313-macosx_13_0_x86_64.whl
Algorithm Hash digest
SHA256 c055cc6b8ea32b62cbaa9147370e4c8ccb08859d7769e1f47422631646b3312e
MD5 1a2f086db3b7c3c5927c529fd4ed9618
BLAKE2b-256 0d318573a74473cef3b323f326f8e4d361ee61d0c107dbe85a8352d5af2c9d2e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for FindAFactor-5.0.1-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 c65e96da18f4893e4405e537b4a1ee8f0b0c2fb03f25fa7f399566c8da2db988
MD5 04d4f346fe547a5e8aed523148bac979
BLAKE2b-256 962a41251f92fe0de87049d3456cabc90de45c27ec939f1ea7cec833c5de04f0

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for FindAFactor-5.0.1-cp312-cp312-manylinux_2_39_x86_64.whl
Algorithm Hash digest
SHA256 6abdf32a4da93a1e6d8fc84e68204d405cb38a501fc80b980bcf21f684229a3a
MD5 c6ac723dedbd21ed47976fef428d9bb4
BLAKE2b-256 952e120592f6477034ead95abc8c9787185975fd33a130f79069cb3e03d8ea45

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for FindAFactor-5.0.1-cp310-cp310-manylinux_2_35_x86_64.whl
Algorithm Hash digest
SHA256 f4705e83ae576c6dde504e277384b190f809beb6e28bddd5839b683e37ed9e32
MD5 22fef72175c5488bcba47ba44f015b14
BLAKE2b-256 25ec298bc9d8108b0e1227065227c5cae086781c815f9b478ac117f70115bb2b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for FindAFactor-5.0.1-cp38-cp38-manylinux_2_31_x86_64.whl
Algorithm Hash digest
SHA256 2ebf7c7d1556c5114f62db1353a350e03ddcee46811e8009c06132440401934c
MD5 a3cb1c33cf3189b04f3006ced3232268
BLAKE2b-256 8e968d4bc20bde1e8adeea5eb00d61b9cd5cea51f48e6624c06c9a0f3ff8b11d

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