Cover Image for PHP gmp_legendre() Function
189 views

PHP gmp_legendre() Function

As of my last update in September 2021, the gmp_legendre() function is available in PHP’s GMP (GNU Multiple Precision) extension. The gmp_legendre() function calculates the Legendre symbol for two given GMP numbers.

Here’s the syntax of the gmp_legendre() function:

int gmp_legendre ( GMP $a , GMP $p )

Parameters:

  • $a: The GMP number representing the integer for which you want to calculate the Legendre symbol.
  • $p: The GMP number representing the positive odd prime number that serves as the modulus for the Legendre symbol.

Return value:

  • The gmp_legendre() function returns an integer representing the Legendre symbol for $a and $p. The possible return values are:
  • 1: If the Legendre symbol is +1 (a is a quadratic residue modulo p).
  • 0: If the Legendre symbol is 0 (when $a is divisible by $p).
  • -1: If the Legendre symbol is -1 (a is a quadratic non-residue modulo p).

Example:

$a = gmp_init('10');
$p = gmp_init('13');

$legendreSymbol = gmp_legendre($a, $p);

echo "The Legendre symbol of 10 and 13 is: " . gmp_strval($legendreSymbol); // Output: -1

In this example, the gmp_legendre() function is used to calculate the Legendre symbol of the GMP number 10 with respect to the modulus 13. The Legendre symbol is -1, indicating that 10 is not a quadratic residue modulo 13.

The Legendre symbol is a mathematical function used in number theory to determine whether a given integer is a quadratic residue or quadratic non-residue modulo a prime number.

Please note that the GMP extension needs to be enabled in your PHP configuration to use this function. Additionally, the availability of functions may change in newer PHP versions, so always refer to the PHP manual for the specific version you are using.

YOU MAY ALSO LIKE...

The Tech Thunder

The Tech Thunder

The Tech Thunder


COMMENTS