gmp_legendre


gmp apg

COMPUTES the Legendre symbol of two GMP numbers.

Jacobi Symbol - from Wikipedia 

Legendre Symbol - from Wikipedia 





$num2 should be odd and must be positive.



<?php

int gmp_legendre 
( GMP|int|string $num1, 
                              
GMP|int|string $num2 )


where,

$num1 = The GMP number along top

$num2 
= The GMP number along left side

?>
 

$num1


The GMP number along top.



$num2


The GMP number along left side.



  1 EXERCISE   

<?php $pa01 = [ 1, 3, 5, 7, 9, 11, 13, 15, 17 ]; ?>
<table width="100%" cellspacing="5" cellpadding="5" border="1" 
align="center"><tbody><tr><td>p\a</span></td><td>0</td><td>1</td>
<td>2</td><td>3</td><td>4</td><td>5</td><td>6</td><td>7</td><td>8
</td><td>9</td><td>10</td><td>11</td><td>12</td><td>13</td><td>14
</td><td>15</td><td>16</td></tr>

<?php foreach ($pa01 as $p01)
{
echo 
'<tr>';
?>
<td>
<?php echo $p01; ?></td>
<?php

for($a01 = 0; $a01 <= 16; $a01++)
{

$j01 = gmp_legendre($a01, $p01);
    echo 
'<td>' . $j01 . '</td>';
}    
}

?>
</tr><tr><td colspan="19">ed48</td></tbody></tr></table>


 RESULT   

Legendre symbol
p\a012345678910111213141516
111111111111111111
301-101-101-101-101-101
501-1-1101-1-1101-1-1101
7011-11-1-1011-11-1-1011
901101101101101101
1101-1111-1-1-11-101-1111
1301-111-1-1-1-111-1101-11
150110100-1100-10-1-101
17011-11-1-1-111-1-1-11-111
ed48

  2 EXERCISE   

<?php

for ($i = -1; $i < 10; $i++) {
    
var_dump(gmp_strval(gmp_legendre(($i*$i)-1, 3)));
    echo 
'<br>';
}

var_dump(gmp_strval(gmp_legendre(7, 23)));
echo 
'<br>';
var_dump(gmp_strval(gmp_legendre("733535124", "1234123423434535623")));
echo 
'<br>';
var_dump(gmp_strval(gmp_legendre(3, "1234123423434535623")));
echo 
'<br>';

$n = "123123";
$n1 = "1231231";

var_dump(gmp_strval(gmp_legendre($n, $n1)));
echo 
'<br>';
var_dump(gmp_strval(gmp_legendre($n, 3)));
echo 
'<br>';
var_dump(gmp_strval(gmp_legendre(3, $n1)));
echo 
'<br>';

try {
    
var_dump(gmp_legendre(3, array()));
} catch (
\TypeError $e) {
    echo 
$e->getMessage() . "<br><br>";
}

try {
    
var_dump(gmp_legendre(array(), 3));
} catch (
\TypeError $e) {
    echo 
$e->getMessage() . "<br><br>";
}

try {
    
var_dump(gmp_legendre(array(), array()));
} catch (
\TypeError $e) {
    echo 
$e->getMessage() . "<br><br>";
}

?>