Skip to content

Commit f7eed5f

Browse files
committed
doc: add doc and examples for legendresymbol
1 parent e874697 commit f7eed5f

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

src/numbers.jl

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,36 @@ function lassallenum(m::Integer)
267267
A[m]
268268
end
269269

270+
"""
271+
legendresymbol(a, p)
272+
273+
Compute the Legendre symbol ``\\left(\\tfrac{a}{p}\\right)`` for odd prime ``p``.
274+
Returns ``-1``, ``0``, or ``1``.
275+
276+
# Examples
277+
```jldoctest
278+
julia> legendresymbol.(6:8, 7)
279+
3-element Vector{Int32}:
280+
-1
281+
0
282+
1
283+
284+
julia> [ [legendresymbol.(a, n) for a in 0:(n-1)] for n in (1,3,5,7,9) ]
285+
5-element Vector{Vector{Int32}}:
286+
[1]
287+
[0, 1, -1]
288+
[0, 1, -1, -1, 1]
289+
[0, 1, 1, -1, 1, -1, -1]
290+
[0, 1, 1, 0, 1, 1, 0, 1, 1]
291+
292+
julia> legendresymbol(1001, 9907)
293+
-1
294+
```
295+
296+
# References
297+
- [Legendre symbol - Wikipedia](https://en.wikipedia.org/wiki/Legendre_symbol)
298+
- [DLMF: §27.9 Legendre symbol](https://dlmf.nist.gov/27.9)
299+
"""
270300
function legendresymbol(a::Integer, b::Integer)
271301
ba = Ref{BigInt}(a)
272302
bb = Ref{BigInt}(b)

0 commit comments

Comments
 (0)