Cover Image for PHP gmp_jacobi() Function
174 views

PHP gmp_jacobi() Function

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

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

int gmp_jacobi ( GMP $a , GMP $p )

Parameters:

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

Return value:

  • The gmp_jacobi() function returns an integer representing the Jacobi symbol for $a and $p. The possible return values are:
  • 1: If the Jacobi symbol is +1.
  • 0: If the Jacobi symbol is 0 (when $a is divisible by $p).
  • -1: If the Jacobi symbol is -1.

Example:

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

$jacobiSymbol = gmp_jacobi($a, $p);

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

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

The Jacobi symbol is an extension of the Legendre symbol and is used in number theory and cryptographic algorithms, such as the Solovay-Strassen primality test and the Quadratic Sieve algorithm.

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