# 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?

You have different summation ranges.

`range`

stops just before its upper boundOh my goodness.Thank you.

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.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.