ISQUADRES

This function determines whether the congruence x^2 \equiv a \pmod p has at least one solution.

In set form, it checks whether a \bmod p belongs to:

\{x^2 \bmod p : x = 0,1,\dots,p-1\}

The result is a boolean indicator often used before attempting modular square root computations.

Excel Usage

=ISQUADRES(a, p)
  • a (int, required): Value to test for quadratic residuosity.
  • p (int, required): Positive modulus.

Returns (bool): True if a is a quadratic residue modulo p, otherwise False.

Example 1: Quadratic residue true case with composite modulus

Inputs:

a p
21 100

Excel formula:

=ISQUADRES(21, 100)

Expected output:

true

Example 2: Quadratic residue false case with composite modulus

Inputs:

a p
21 120

Excel formula:

=ISQUADRES(21, 120)

Expected output:

false

Example 3: Quadratic residue true case modulo prime

Inputs:

a p
2 7

Excel formula:

=ISQUADRES(2, 7)

Expected output:

true

Example 4: Quadratic residue false case modulo prime

Inputs:

a p
3 7

Excel formula:

=ISQUADRES(3, 7)

Expected output:

false

Python Code

from sympy import is_quad_residue as sympy_is_quad_residue

def isquadres(a, p):
    """
    Check whether a value is a quadratic residue modulo p.

    See: https://docs.sympy.org/latest/modules/ntheory.html#sympy.ntheory.residue_ntheory.is_quad_residue

    This example function is provided as-is without any representation of accuracy.

    Args:
        a (int): Value to test for quadratic residuosity.
        p (int): Positive modulus.

    Returns:
        bool: True if a is a quadratic residue modulo p, otherwise False.
    """
    try:
        return bool(sympy_is_quad_residue(a, p))
    except Exception as e:
        return f"Error: {str(e)}"

Online Calculator

Value to test for quadratic residuosity.
Positive modulus.