%mathpiper,def="IsQuadraticResidue"

// Algorithm adapted from:
// Elementary Number Theory, David M. Burton
// Theorem 9.1 p187
10 # IsQuadraticResidue(_a,_p) <--
[
        Check( IsInteger(a) And IsInteger(p) And p>2 And IsCoprime(a,p) And IsPrime(p),
                "Argument", "IsQuadraticResidue: Invalid arguments");
        If(a^((p-1)/2) % p = 1, True, False);
];

%/mathpiper



%mathpiper_docs,name="IsQuadraticResidue",categories="User Functions;Number Theory;Predicates"
*CMD IsQuadraticResidue --- functions related to finite groups
*STD
*CALL
	IsQuadraticResidue(m,n)

*PARMS
{m}, {n} -- integers, $n$ must be odd and positive

*DESC

A number $m$ is a "quadratic residue modulo $n$" if there exists a number $k$ such that $k^2:=Modulo(m,n)$.

*E.G.

In> IsQuadraticResidue(9,13)
Result: True;

*SEE Gcd, JacobiSymbol, LegendreSymbol
%/mathpiper_docs