jacobiSymbol
Jacobi symbol
Syntax
Description
returns the value of the Jacobi symbol for
integer J
= jacobiSymbol(a
,n
)a
and positive odd integer n
.
Examples
Find the Jacobi symbol for and .
a = 1:9; n = 3; J = jacobiSymbol(a,n)
J = 1×9
1 -1 0 1 -1 0 1 -1 0
The Jacobi symbol is periodic with respect to its first argument, where if .
Find the Jacobi symbol for and .
J = jacobiSymbol(28,9)
J = 1
The Jacobi symbol is a completely multiplicative function, where the Jacobi symbol satisfies the relation for . Show that the Jacobi symbol follows this relation for .
Ja = jacobiSymbol(2,9)*jacobiSymbol(2,9)*jacobiSymbol(7,9)
Ja = 1
The Jacobi symbol also satisfies the relation for . Show that the Jacobi symbol follows this relation for .
Jb = jacobiSymbol(28,3)*jacobiSymbol(28,3)
Jb = 1
You can use the Jacobi symbol for the Solovay–Strassen primality test. If an odd integer is prime, then the congruence
must hold for all integers . If there is an integer in such that the congruence relation is not satisfied, then is not prime.
Check if is prime or not. Choose and perform the primality test. Compare the two values in the congruence relation.
First calculate the left side of the congruence relation using the Jacobi symbol.
n = 561; a = 14; J = jacobiSymbol(a,n)
J = 1
Calculate the right side of the congruence relation.
m = powermod(a,(n-1)/2,n)
m = 67
The integer is not prime since it does not satisfy the congruence relation for .
checkPrime = mod(J,n) == m
checkPrime = logical
0
Next, check if is prime or not. Choose and perform the primality test.
n = 557; a = 19; J = jacobiSymbol(a,n); m = powermod(a,(n-1)/2,n);
The integer is probably prime since it satisfies the congruence relation for .
checkPrime = mod(J,n) == m
checkPrime = logical
1
Perform the primality test for all in to confirm that the integer is indeed prime.
a = 1:n-1; J = jacobiSymbol(a,n); m = powermod(a,(n-1)/2,n); checkPrime = all(mod(J,n) == m)
checkPrime = logical
1
Verify the result with isprime
.
isprime(n)
ans = logical
1
Input Arguments
Input, specified as a number, vector, matrix, array, symbolic number, or symbolic
array. The elements of a
must be integers. a
and
n
must be the same size, or else one of them must be a
scalar.
Data Types: single
| double
| sym
Input, specified as a number, vector, matrix, array, symbolic number, or symbolic
array. The elements of n
must be positive odd integers.
a
and n
must be the same size, or else one of
them must be a scalar.
Data Types: single
| double
| sym
Output Arguments
Output value, returned as –1
, 0
, or
1
.
Data Types: single
| double
| sym
More About
The Jacobi symbol is defined as the product of the Legendre symbols
for an integer a and a positive odd integer n with prime factorization
The Legendre symbol for an integer a and an odd prime p is defined as
When n is an odd prime, the Jacobi symbol is equal to the Legendre symbol.
References
[1] Dietzfelbinger, M. Primality Testing in Polynomial Time: From Randomized Algorithms to "PRIMES Is in P". Springer, 2004.
Version History
Introduced in R2020a
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 MathWorks 사이트 방문이 최적화되지 않았습니다.
미주
- América Latina (Español)
- Canada (English)
- United States (English)
유럽
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)