Skip to content

Commit e874697

Browse files
committed
doc: add doc and examples for jacobisymbol
1 parent ee909e2 commit e874697

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

src/numbers.jl

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,44 @@ function fibonaccinum(n::Integer)
210210
end
211211

212212

213+
"""
214+
jacobisymbol(a, b)
215+
216+
Compute the Jacobi symbol ``\\left(\\tfrac{a}{b}\\right)`` for odd ``b``.
217+
Returns ``-1``, ``0``, or ``1``.
218+
219+
# Examples
220+
```jldoctest
221+
julia> jacobisymbol.(2:4, 3)
222+
3-element Vector{Int32}:
223+
-1
224+
0
225+
1
226+
227+
julia> jacobisymbol.(-2:2, 1) # (a|1) = 1
228+
5-element Vector{Int32}:
229+
1
230+
1
231+
1
232+
1
233+
1
234+
235+
julia> [jacobisymbol(a, n) for n in (1,3,5,7,9), a in 1:9]
236+
5×9 Matrix{Int32}:
237+
1 1 1 1 1 1 1 1 1
238+
1 -1 0 1 -1 0 1 -1 0
239+
1 -1 -1 1 0 1 -1 -1 1
240+
1 1 -1 1 -1 -1 0 1 1
241+
1 1 0 1 1 0 1 1 0
242+
243+
julia> jacobisymbol(1001, 9907)
244+
-1
245+
```
246+
247+
# References
248+
- [Jacobi symbol - Wikipedia](https://en.wikipedia.org/wiki/Jacobi_symbol)
249+
- [DLMF: §27.9 Jacobi symbol](https://dlmf.nist.gov/27.9#p3)
250+
"""
213251
function jacobisymbol(a::Integer, b::Integer)
214252
ba = Ref{BigInt}(a)
215253
bb = Ref{BigInt}(b)

0 commit comments

Comments
 (0)