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.
Seleziona un sito web
Seleziona un sito web per visualizzare contenuto tradotto dove disponibile e vedere eventi e offerte locali. In base alla tua area geografica, ti consigliamo di selezionare: .
Puoi anche selezionare un sito web dal seguente elenco:
Come ottenere le migliori prestazioni del sito
Per ottenere le migliori prestazioni del sito, seleziona il sito cinese (in cinese o in inglese). I siti MathWorks per gli altri paesi non sono ottimizzati per essere visitati dalla tua area geografica.
Americhe
- América Latina (Español)
- Canada (English)
- United States (English)
Europa
- 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)