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

Uploaded CPython 3.13macOS 15.0+ ARM64

FindAFactor-5.0.5-cp313-cp313-macosx_14_0_arm64.whl (112.4 kB view details)

Uploaded CPython 3.13macOS 14.0+ ARM64

FindAFactor-5.0.5-cp313-cp313-macosx_13_0_x86_64.whl (126.7 kB view details)

Uploaded CPython 3.13macOS 13.0+ x86-64

FindAFactor-5.0.5-cp312-cp312-win_amd64.whl (148.7 kB view details)

Uploaded CPython 3.12Windows x86-64

FindAFactor-5.0.5-cp312-cp312-manylinux_2_39_x86_64.whl (137.0 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.39+ x86-64

FindAFactor-5.0.5-cp310-cp310-manylinux_2_35_x86_64.whl (144.8 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.35+ x86-64

FindAFactor-5.0.5-cp38-cp38-manylinux_2_31_x86_64.whl (137.2 kB view details)

Uploaded CPython 3.8manylinux: glibc 2.31+ x86-64

File details

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

File metadata

  • Download URL: findafactor-5.0.5.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.5.tar.gz
Algorithm Hash digest
SHA256 4dc953ffb100cf4afc0b423e648d21fc746b3948a8fc771309e77cb4136d9e8d
MD5 0970cd097832b46e3013b980cdc43367
BLAKE2b-256 79c48e89ee63bf401d3aa5c34fe0a3d96f48980a1e100b1b98c18ccff3068738

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for FindAFactor-5.0.5-cp313-cp313-macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 c8a6125551f4cd88b65777b3bee3a71a075a85d4bfcd4a5581e5f054f1134688
MD5 5a8d54da7f0c37ee22457e9b6da355c4
BLAKE2b-256 064e0627ec8d268a0afedbb0c09b4a03eb2297d1c2e47cad68bc3fc621c6f56e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for FindAFactor-5.0.5-cp313-cp313-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 ae9245e0ffeae687c1dfa22c077e7bb68639cf00d1d90ed6b34a3e754c83cfa9
MD5 6c04f669054293ce530605bfd75a2066
BLAKE2b-256 c3e073a6424e9c9fab04fc97fa80d46e5ad40ed1ec901fdd14b1aa8a74a5420f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for FindAFactor-5.0.5-cp313-cp313-macosx_13_0_x86_64.whl
Algorithm Hash digest
SHA256 465d1efd59179de056ef173ced05c5b88be7f3398cfbef6efebafd244c837c9b
MD5 b217606f173abe6cd830c61f663efc93
BLAKE2b-256 fd674b4e10f7082df2d8ce3e65120447b644510d5036fb9fad7064106c981f1f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for FindAFactor-5.0.5-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 de57ee7379645a8eec3d6450c5a73ca197e1b4e01df2c708343466fd9c3fbb16
MD5 e48df15f1e9c65490f55d341e7e28bd2
BLAKE2b-256 abac8902780946eb631724c8146abf85fb56bce2845ba4d9fd82a9be73f0c57d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for FindAFactor-5.0.5-cp312-cp312-manylinux_2_39_x86_64.whl
Algorithm Hash digest
SHA256 df89b97693d2285dd3107b19333f6c975e09ea6362be8bc86d11985cd9a5e7f3
MD5 c0da4607bed7abbda055716935ca3be2
BLAKE2b-256 8b8c3671f3d5752b951d7c57aaff21a43c4d5e5d25e1e5e2b61422ba25ca47cd

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for FindAFactor-5.0.5-cp310-cp310-manylinux_2_35_x86_64.whl
Algorithm Hash digest
SHA256 0f86cfe94c83c6497e724b0c8db80ca9dc6d4fe2ddaad7743908054a2d545fde
MD5 39f79cb4c6327aaf5177a6b4261d1ccd
BLAKE2b-256 86e8f2c41fc62c8ecdfa306e24948eb2c983280a023d306b4bde277d00ac229f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for FindAFactor-5.0.5-cp38-cp38-manylinux_2_31_x86_64.whl
Algorithm Hash digest
SHA256 fcf82a0138271aa9a878d1f97ac8eb875bf9ac652273d3e0893d25094d2aa752
MD5 568757ce855ce1bf59671727b08d1a6a
BLAKE2b-256 d433981e536dbf2f9d41c75033f0502bcf5eeb1ea7dd7d9fc7356abbd793c7bd

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