Message Boards Message Boards

0
|
953 Views
|
3 Replies
|
2 Total Likes
View groups...
Share
Share this post:

Using JacobiSymbol vs KroneckerSymbol

Posted 7 months ago

Hello all,

from my understanding, both JacobiSymbol(n,m) and KroneckerSymbol(n,m) return the same values when their arguments are integer, even though JacobiSymbol is about 6 X faster (and even though, mathematically, the Jacobi symbol should only be defined for odd positive m).

nn=1000;

a=Table[KroneckerSymbol[ n,m], {n, -nn, nn},{m,-nn,nn}]; // AbsoluteTiming

b=Table[JacobiSymbol[ n,m], {n, -nn, nn},{m,-nn,nn}]; // AbsoluteTiming

a==b (* True *)

So, is it safe to use JacobiSymbol instead of KroneckerSymbol?

Thank you in advance.

POSTED BY: Paolo Xausa
3 Replies

ChatGPT AI says:

Yes, in the Wolfram Language, it is generally safe to use JacobiSymbol instead of KroneckerSymbol when dealing with integer arguments, with a few considerations:

  1. Definition and Generality:
  • The JacobiSymbol[n, m] is a generalization of the Legendre symbol, traditionally defined for odd positive ( m ). However, in computational contexts like Wolfram Language, it has been extended to handle all integer values of ( m ).
  • The KroneckerSymbol[n, m] is a further generalization that extends the Jacobi symbol to all integer values of ( m ), including even values and 0, thereby making it equivalent to the Jacobi symbol for all integer arguments in practical computation.
  1. Performance:
  • As you've noted, JacobiSymbol is approximately 6 times faster than KroneckerSymbol. This performance difference can be significant in large computations or algorithms that require numerous symbol evaluations.
  1. Practical Equivalence:
  • For all integer arguments, JacobiSymbol[n, m] and KroneckerSymbol[n, m] return the same values in the Wolfram Language. This means you can use JacobiSymbol safely in place of KroneckerSymbol for integer inputs, benefiting from the performance improvement without sacrificing correctness.
  1. Specific Cases:
  • Both symbols handle special cases such as ( m = 0 ), even though the traditional mathematical definition of the Jacobi symbol does not include this. The computational extension in Wolfram Language ensures that both symbols give the correct and expected results for these cases.

Conclusion

Given that: - JacobiSymbol and KroneckerSymbol produce the same results for all integer arguments in the Wolfram Language. - JacobiSymbol is significantly faster.

It is safe and beneficial to use JacobiSymbol in place of KroneckerSymbol for integer arguments, leveraging the improved performance without losing correctness. However, always ensure your specific use cases align with the described behavior and test thoroughly if you are implementing this in critical applications.

Gemini AI says:

You're right! In Wolfram Language, JacobiSymbol(n, m) can be a faster alternative to KroneckerSymbol(n, m) for integer arguments, even though they might seem like different functions. Here's the breakdown:

  • Kronecker Symbol (δ): This symbol is simply 1 if n and m are equal and 0 otherwise. It works for any integer arguments.
  • Jacobi Symbol (()): This symbol deals with residues modulo an odd positive integer (m). It returns 1 if n has a square root modulo m, -1 if it doesn't, and 0 if n is divisible by m.

Now, for integers:

  • When m is odd and positive, both symbols essentially check the same thing (square root modulo m). This is why JacobiSymbol is faster - it's specifically designed for this case.
  • When m is even or negative, the Jacobi symbol isn't mathematically defined. However, Wolfram Language seems to cleverly extend the behavior of the Jacobi symbol for these cases to match the Kronecker symbol (always 0 for even m and 1 for negative m).

So, is it safe to use JacobiSymbol?

Yes, in most cases, it's safe to use JacobiSymbol instead of KroneckerSymbol if you're only dealing with integers for n and m. It's generally faster and achieves the same result.

However, there are a few caveats:

  • Clarity: If your code needs to be mathematically rigorous or emphasizes the concept of divisibility (Kronecker symbol), using KroneckerSymbol might be clearer.
  • Non-Integer Arguments: If you plan to use non-integer arguments later, stick with KroneckerSymbol as it's defined for a wider range.

Summary:

For pure integer computations, JacobiSymbol is a good choice for speed. Just be aware of the mathematical definition limitations and use KroneckerSymbol if clarity or broader applicability is needed.

POSTED BY: Mariusz Iwaniuk
Posted 7 months ago

Yes, thank you, but JacobiSymbol[2,4] (for example) works and returns the correct value:

JacobiSymbol[2,4] == KroneckerSymbol[2,4]

I can't find any difference between the two functions (with the added bonus that JacobiSymbol is faster).

POSTED BY: Paolo Xausa

From help pages of KroneckerSymbol:

KroneckerSymbol is the generalization of the Jacobi symbol for all integers

  jacobi[n_, m_] := KroneckerSymbol[n, m] /; (OddQ[m] && Positive[m]);
  Table[jacobi[2, m], {m, 1, 9}]

  (*{1, jacobi[2, 2], -1, jacobi[2, 4], -1, jacobi[2, 6], 1, jacobi[2, 8], 1}*)

Regards M.I.

POSTED BY: Mariusz Iwaniuk
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract