Skip to content

Commit 58a84aa

Browse files
committed
doc: add doc and examples for lucasnum
1 parent f7eed5f commit 58a84aa

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

src/numbers.jl

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,43 @@ function legendresymbol(a::Integer, b::Integer)
303303
return ccall((:__gmpz_legendre, :libgmp), Cint, (Ref{BigInt}, Ref{BigInt}), ba, bb)
304304
end
305305

306+
"""
307+
lucasnum(n)
308+
309+
Compute the ``n``th Lucas number, ``L_n``, given by:
310+
```math
311+
L_0 = 2
312+
\\\\
313+
L_1 = 1
314+
\\\\
315+
L_n = L_{n-1} + L_{n-2}
316+
```
317+
318+
# Examples
319+
```jldoctest
320+
julia> [ lucasnum(i) for i in 0:5 ]
321+
6-element Vector{BigInt}:
322+
2
323+
1
324+
3
325+
4
326+
7
327+
11
328+
329+
julia> lucasnum(10)
330+
123
331+
332+
julia> lucasnum(-1)
333+
ERROR: DomainError with -1:
334+
n must be nonnegative
335+
Stacktrace:
336+
[...]
337+
```
338+
339+
# References
340+
- [Lucas number - Wikipedia](https://en.wikipedia.org/wiki/Lucas_number)
341+
- [DLMF: §24.15 Lucas numbers](https://dlmf.nist.gov/24.15#iv.p1)
342+
"""
306343
function lucasnum(n::Integer)
307344
if n < 0
308345
throw(DomainError(n, "n must be nonnegative"))

0 commit comments

Comments
 (0)