# On computation of Jacobi sum [closed]

I’m computing Jacobi sum of cubic residue symbol as follows:

N=3
x=polygen(ZZ,'x')
K.<z>=CyclotomicField(N)
p=-4-3*z
P = K.ideal(p)
sum([K(a).residue_symbol(P,N)*K(1-a).residue_symbol(P,N) for a in [2..P.norm()-1] if a not in P and 1-a not in P])


The output is -3*z - 4. This is correct.

But I wrote another equivalent code:

def Jacobi(P,l,j):
x=sum([K(a).residue_symbol(P,l)^j*K(1-a).residue_symbol(P,l)^j for a in range(2, P.norm()-1) if a not in P and 1-a not in P])
return x

N=3
x=polygen(ZZ,'x')
K.<z>=CyclotomicField(N)
p=-4-3*z
P = K.ideal(p)
Jacobi(P,N,1)


Then the output is -4*z - 4, this is odd. Where is wrong?

edit retag reopen merge delete

### Closed for the following reason the question is answered, right answer was accepted by Max Alekseyev close date 2023-11-02 14:52:33.195164

You have different summation ranges.

( 2023-11-02 12:19:12 +0200 )edit

range stops just before its upper bound

( 2023-11-02 13:25:38 +0200 )edit

Oh my goodness.Thank you.

( 2023-11-02 14:46:07 +0200 )edit

On a different note - there is no need to create a list to sum up its elements, that is, instead of sum([...]) you can do simply sum(...), which may save some memory when the number of terms is large.

( 2023-11-02 14:47:37 +0200 )edit

And same for [2..P.norm()-1] - there is no need to create a list here, generator (2..P.norm()-1) (or range()) is well sufficient for summation purposes.

( 2023-11-02 14:50:31 +0200 )edit