Jacques Gélinas on Tue, 16 Feb 2021 23:37:26 +0100


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Re: jacobi symbol


/*	Jacobi symbol, defined as the product of the Legendre symbols for prime factors of n
        following a Lua program from http://en.wikipedia.org/wiki/Jacobi_symbol
        (with arguments permuted!! as downloaded on 2021-02-16)
*/

{addhelp(jacobisb, "jacobisb(k,n): jacobi symbol (k/n) = 
   product L(k/p)^np of Legendre symbols for prime factors p^np of n");

jacobisb(k,n) = { my(r,t=1);
  if( !(k>0 && k%2), error());
  n = n%k; 
  while(n, while( !(n%2), n/=2; r=k%8; if(r==3||r==5, t=-t));
        r=n;n=k;k=r; if( n%4==3 && k%4==3, t=-t); n=n%k );
  return( if(k==1,t,0) );
}

/* Verify table from Wikipedia */
PASS(e) = if(!e,error() );

PASS( apply( k->jacobisb(1,k),[1..5]) == [1, 1, 1, 1, 1] );
PASS( apply( k->jacobisb(3,k),[1..5]) == [1,-1, 0, 1,-1] );
PASS( apply( k->jacobisb(5,k),[1..5]) == [1,-1,-1, 1, 0] );
PASS( apply( k->jacobisb(7,k),[1..5]) == [1, 1,-1, 1,-1] );
PASS( apply( k->jacobisb(9,k),[1..5]) == [1, 1, 0, 1, 1] );
PASS( apply( k->jacobisb(59,k),[1..16]) == [1,-1,1,1,1,-1,1,-1,1,-1,-1,1,-1,-1,1,1] );

Jacques Gélinas


De : jean-pierre Cherdieu <jpcherdi@gmail.com>
Envoyé : 16 février 2021 15:59
À : pari-users@pari.math.u-bordeaux.fr <pari-users@pari.math.u-bordeaux.fr>
Objet : jacobi symbol 
 
hi every body,
does someone know if there is a command to compute the jacobi symbol.
sincerely,

-- 
Jean-Pierre Cherdieu