File Exchange

image thumbnail

Jacobi and Legendre symbol

version (1.52 KB) by Petter
JACOBI computes the Jacobi symbol (m/n), a generalization of the Legendre symbol.

1 Download

Updated 09 Jul 2009

View License

For the Legendre symbol (m/p), p must be an odd prime. The Jacobi symbol (m/n) allows n to be any odd number.

Cite As

Petter (2021). Jacobi and Legendre symbol (, MATLAB Central File Exchange. Retrieved .

Comments and Ratings (2)

David Amirault

There is a serious bug in your implementation of the Jacobi symbol, which was already pointed out by Sean. Please fix

Sean McClintock

There are a couple of bugs in this program...

In line 36, we want to test if n=+/-1 mod8, however, since matlab will return a value from 0 to 7 for mod(n,8),

if abs(mod(n,8))==1 is not adequate,


if mod(n,8)==1
j = jacobi(m/2,n);
elseif mod(n,8)==7
j = jacobi(m/2,n);
etc would be better.

Also, I don't think this program deals with negative m.

MATLAB Release Compatibility
Created with R2007b
Compatible with any release
Platform Compatibility
Windows macOS Linux

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!