Skip to content

Commit 5a7eb67

Browse files
committed
doc: add examples for narayana
1 parent 3e79e6d commit 5a7eb67

File tree

1 file changed

+31
-3
lines changed

1 file changed

+31
-3
lines changed

src/numbers.jl

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,12 +150,40 @@ end
150150
"""
151151
narayana(n,k)
152152
153-
Compute the Narayana number `N(n,k)` given by ``\\frac{1}{n}\\binom{n}{k}\\binom{n}{k-1}``
154-
Wikipedia : https://en.wikipedia.org/wiki/Narayana_number
153+
Compute the Narayana number `N(n,k)` given by ``\\frac{1}{n}\\binom{n}{k}\\binom{n}{k-1}``,
154+
where ``1 \\leq k \\leq n``.
155+
156+
# Examples
157+
```jldoctest
158+
julia> narayana(1, 1)
159+
1
160+
161+
julia> narayana(8, 5)
162+
490
163+
164+
julia> [ [narayana(n, k) for k in 1:n] for n in 1:6 ]
165+
6-element Vector{Vector{BigInt}}:
166+
[1]
167+
[1, 1]
168+
[1, 3, 1]
169+
[1, 6, 6, 1]
170+
[1, 10, 20, 10, 1]
171+
[1, 15, 50, 50, 15, 1]
172+
173+
julia> narayana(3, 4)
174+
ERROR: DomainError with (n = 3, k = 4):
175+
n and k must be 1 <= k <= n
176+
Stacktrace:
177+
[...]
178+
```
179+
180+
# References
181+
- [Narayana number - Wikipedia](https://en.wikipedia.org/wiki/Narayana_number)
182+
- [DLMF: §26.6 Narayana Number](https://dlmf.nist.gov/26.6#Px3)
155183
"""
156184
function narayana(bn::Integer,bk::Integer)
157185
if !(1 <= bk <= bn)
158-
throw(DomainError("Domain is 1 <= k <= n"))
186+
throw(DomainError((n=bn, k=bk), "n and k must be 1 <= k <= n"))
159187
else
160188
n = BigInt(bn)
161189
k = BigInt(bk)

0 commit comments

Comments
 (0)