TheAlgorithms/Python · warning · ValueError

Warning: upper bound of deterministic test is exceeded. Pass

Error message

Warning: upper bound of deterministic test is exceeded. Pass allow_probable=True to allow probabilistic test. A return value of True indicates a probable prime.

What it means

Raised by the deterministic Miller-Rabin primality test in ciphers/deterministic_miller_rabin.py when n exceeds 3,317,044,064,679,887,385,961,981 — the largest range for which the fixed witness set is proven deterministic. Without allow_probable=True the library refuses to give a possibly-wrong 'prime' answer.

Source

Thrown at ciphers/deterministic_miller_rabin.py:38

    allow_probable: bool, default False
        Whether or not to test n above the upper bound of the deterministic test.

    Raises
    ------
    ValueError

    Reference
    ---------
    https://en.wikipedia.org/wiki/Miller%E2%80%93Rabin_primality_test
    """
    if n == 2:
        return True
    if not n % 2 or n < 2:
        return False
    if n > 5 and n % 10 not in (1, 3, 7, 9):  # can quickly check last digit
        return False
    if n > 3_317_044_064_679_887_385_961_981 and not allow_probable:
        raise ValueError(
            "Warning: upper bound of deterministic test is exceeded. "
            "Pass allow_probable=True to allow probabilistic test. "
            "A return value of True indicates a probable prime."
        )
    # array bounds provided by analysis
    bounds = [
        2_047,
        1_373_653,
        25_326_001,
        3_215_031_751,
        2_152_302_898_747,
        3_474_749_660_383,
        341_550_071_728_321,
        1,
        3_825_123_056_546_413_051,
        1,
        1,
        318_665_857_834_031_151_167_461,

View on GitHub (pinned to f5988cc097)

Solutions

  1. Pass allow_probable=True if a probabilistic answer is acceptable for your use case
  2. Use a primality test designed for arbitrary sizes (e.g. stdlib-free sympy.isprime or your own random-witness Miller-Rabin with enough rounds)
  3. Keep n at or below the bound for a guaranteed deterministic result

Example fix

# before
is_prime = miller_rabin(huge_number)

# after
is_prime = miller_rabin(huge_number, allow_probable=True)  # probabilistic for n > bound
Defensive patterns

Strategy: validation

Validate before calling

DETERMINISTIC_BOUND = 3_317_044_064_679_887_385_961_981
allow_probable = n > DETERMINISTIC_BOUND  # opt in only when required

Try / catch

try:
    prime = miller_rabin(n)
except ValueError:
    prime = miller_rabin(n, allow_probable=True)  # acceptable for crypto-size candidates

Prevention

When it happens

Trigger: Calling miller_rabin(n) (or the module's test function) with n above ~3.3e24 and the default allow_probable=False; primality checks on 256-bit-plus cryptographic candidates.

Common situations: RSA/diffie-hellman key generation with modern key sizes (2048+ bit candidates); benchmarking the test with very large numbers; upgrading inputs from 64-bit experiments to big-int territory.


AI-assisted analysis of TheAlgorithms/Python@f5988cc097 (2026-08-14). Data as JSON: /api/errors/97e5e18ff8b97596. Report an issue: GitHub.