-
Notifications
You must be signed in to change notification settings - Fork 62
doc: add and update doc for numbers.jl
#201
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
a1d5802 to
fd4f82d
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #201 +/- ##
=======================================
Coverage 97.17% 97.17%
=======================================
Files 8 8
Lines 813 813
=======================================
Hits 790 790
Misses 23 23 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR enhances the documentation for special number functions in numbers.jl by adding comprehensive docstrings with mathematical formulas, examples, and references, while also expanding test coverage.
Key changes:
- Added new documentation with examples and references for
bellnum,fibonaccinum,jacobisymbol,legendresymbol, andlucasnum - Updated documentation for
catalannum,lobbnum,narayana,lassallenum,stirlings1, andstirlings2with mathematical formulas, detailed examples, and DLMF/Wikipedia references - Expanded test coverage for
catalannum,fibonaccinum, andlassallenumwith additional test cases and edge cases - Improved error messages by adding descriptive text to
DomainErrorexceptions (e.g., "n must be nonnegative")
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 13 comments.
| File | Description |
|---|---|
| src/numbers.jl | Added comprehensive documentation for 5 functions and updated documentation for 6 existing functions with mathematical formulas, examples, and references; improved error messages with descriptive text |
| test/numbers.jl | Reorganized tests by moving bellnum tests to the beginning; added extensive test coverage for catalannum, fibonaccinum, and lassallenum with edge cases and large values |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| julia> n=9; stirlings1(n, 1) == factorial(n-1) | ||
| true | ||
| julia> n=233; stirlings1(n, n-1) == binomial(n,2) |
Copilot
AI
Dec 8, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing spaces around assignment operator. Should be n = 233 instead of n=233 to follow Julia style conventions.
| julia> n=9; stirlings1(n, 1) == factorial(n-1) | |
| true | |
| julia> n=233; stirlings1(n, n-1) == binomial(n,2) | |
| julia> n = 9; stirlings1(n, 1) == factorial(n-1) | |
| true | |
| julia> n = 233; stirlings1(n, n-1) == binomial(n,2) |
| julia> n=6; sum(stirlings2(6, k) for k in 0:6) == bellnum(n) | ||
| true | ||
| julia> [stirlings2(n,k) for n in 1:6, k in 1:6] |
Copilot
AI
Dec 8, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing spaces after commas in function call. Should be [stirlings2(n, k) for n in 1:6, k in 1:6] to be consistent with Julia style conventions.
| julia> [stirlings2(n,k) for n in 1:6, k in 1:6] | |
| julia> [stirlings2(n, k) for n in 1:6, k in 1:6] |
| julia> n=9; stirlings1(n, 1) == factorial(n-1) | ||
| true | ||
| julia> n=233; stirlings1(n, n-1) == binomial(n,2) |
Copilot
AI
Dec 8, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing space after comma in function call. Should be binomial(n, 2) to be consistent with Julia style conventions used elsewhere in the documentation.
| julia> n=233; stirlings1(n, n-1) == binomial(n,2) | |
| julia> n=233; stirlings1(n, n-1) == binomial(n, 2) |
| julia> stirlings2(0, 0) | ||
| 1 | ||
| julia> n=233; stirlings2(n, 0) == 0 # n > 0 |
Copilot
AI
Dec 8, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing spaces around assignment operator. Should be n = 233 instead of n=233 to follow Julia style conventions.
| julia> stirlings2(0, 1) | ||
| 0 | ||
| julia> n=13; stirlings2(n, 1) == stirlings2(n, n) == 1 # n > 0 |
Copilot
AI
Dec 8, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing spaces around assignment operator. Should be n = 13 instead of n=13 to follow Julia style conventions.
| end | ||
|
|
||
| """ | ||
| narayana(n,k) |
Copilot
AI
Dec 8, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing space after comma in function signature documentation. Should be narayana(n, k) to match the updated style used in other function signatures in this PR (e.g., lobbnum(m, n) on line 100).
| narayana(n,k) | |
| narayana(n, k) |
| n = BigInt(bn) | ||
| k = BigInt(bk) | ||
| end | ||
| div(binomial(n, k)*binomial(n, k - 1) , n) |
Copilot
AI
Dec 8, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Extra space before comma. Should be binomial(n, k - 1), n) (remove the space before the comma after k - 1).
| div(binomial(n, k)*binomial(n, k - 1) , n) | |
| div(binomial(n, k)*binomial(n, k - 1), n) |
| julia> stirlings1(6, 3, true) | ||
| -225 | ||
| julia> [stirlings1(n,k,true) for n in 1:6, k in 1:6] |
Copilot
AI
Dec 8, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing spaces after commas in function call. Should be [stirlings1(n, k, true) for n in 1:6, k in 1:6] to be consistent with Julia style conventions.
| julia> [stirlings1(n,k,true) for n in 1:6, k in 1:6] | |
| julia> [stirlings1(n, k, true) for n in 1:6, k in 1:6] |
|
|
||
| # lassalle | ||
| # https://oeis.org/A180874 | ||
| @test lassallenum.(1:10) == [1,1,5,56,1092,32670,1387815,79389310,5882844968,548129834616] |
Copilot
AI
Dec 8, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing spaces after commas in the array. Should be [1, 1, 5, 56, 1092, 32670, 1387815, 79389310, 5882844968, 548129834616] to be consistent with Julia style conventions and other tests in this file (e.g., line 24, 32).
| @test lassallenum.(1:10) == [1,1,5,56,1092,32670,1387815,79389310,5882844968,548129834616] | |
| @test lassallenum.(1:10) == [1, 1, 5, 56, 1092, 32670, 1387815, 79389310, 5882844968, 548129834616] |
| julia> stirlings1(5, 5) # s(n, n) = 1 | ||
| 1 | ||
| julia> n=9; stirlings1(n, 1) == factorial(n-1) |
Copilot
AI
Dec 8, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing space after semicolon in compound statement. Should be n=9; stirlings1(n, 1) == factorial(n-1) → n = 9; stirlings1(n, 1) == factorial(n-1) to follow Julia style conventions (spaces around assignment operators).
| julia> n=9; stirlings1(n, 1) == factorial(n-1) | |
| julia> n = 9; stirlings1(n, 1) == factorial(n-1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some small suggestions/options and a couple of questions.
I feel like I'm ignorant to how the end docstring gets rendered. Specifically, I don't know if double back-ticks is processed the same as $ in standard LaTeX. Also, the double backslash is new to me.
Any question in my review are genuine (rather than rhetorical), so please feel free to answer them if you have time since I'm interested in the answer.
As a final note: I went ahead an reran all the code examples and checked the links, with everything looking good on those two points.
| Compute the ``n``th Catalan number. | ||
| Compute the ``n``th Catalan number given by: | ||
| ```math | ||
| C_n = \\frac{1}{n+1} \\binom{2n}{n} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does the double backslash render the LaTeX properly? It doesn't here in GitHub markdown, and I'm not used to that when I use LaTeX, so I thought I'd mention it.
Double backslash:
Single backslash:
| Compute the Lobb number `L(m,n)`, or the generalised Catalan number given by: | ||
| ```math | ||
| L_{m,n} = \\frac{2m+1}{m+n+1} \\binom{2n}{m+n} | ||
| ``` | ||
| For `m = 0`, we get the ``n``-th Catalan number. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
L(m,n) could probably be excluded here, since it's not the name of the function and it is defined mathematically below using subscripts. If it's kept, maybe a space could be inserted to match function style: L(m, n)
Also: "generalised" is British English and "generalized" is American English (if there is a preference) and n-th Catalan number is written above in catalannum(n) as nth Catalan number (so minus the dash).
With the above changes, it could look like (using single backslashes):
Compute the Lobb number, aka the generalized Catalan number, given by:
For m = 0, we get the nth Catalan number.
| Compute the Narayana number `N(n,k)` given by ``\\frac{1}{n}\\binom{n}{k}\\binom{n}{k-1}`` | ||
| Wikipedia : https://en.wikipedia.org/wiki/Narayana_number | ||
| Compute the Narayana number `N(n,k)` given by ``\\frac{1}{n}\\binom{n}{k}\\binom{n}{k-1}``, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same comment concerning N(n,k) as above with L(m,n)
| stirlings1(n::Integer, k::Integer) | ||
| stirlings1(n::Integer, k::Integer, signed::Bool=false) | ||
| Compute the Stirling number of the first kind, ``s(n,k)``, for non-negative `n`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s(n,k) is in double back-ticks, whereas the other instances of functions like this have been in single back-ticks.
| stirlings2(n::Integer, k::Integer) | ||
| Compute the Stirling number of the second kind, `S(n,k)`. | ||
| Compute the Stirling number of the second kind, ``S(n,k)``, for non-negative `n`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mentioning the double back-ticks vs single back-ticks again.
| julia> n=13; stirlings2(n, 1) == stirlings2(n, n) == 1 # n > 0 | ||
| true | ||
| julia> n=6; [stirlings2(6, k) for k in 0:6] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
n is not used int the comprehension. Was it suppose to be:
julia> n=6; [stirlings2(n, k) for k in 0:6]
| 15 | ||
| 1 | ||
| julia> n=6; sum(stirlings2(6, k) for k in 0:6) == bellnum(n) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Again, unsure if the n should be used in stirlings2(n, k) while it is being used in bellnum(n).
| @test fibonaccinum(92) == big"7540113804746346429" | ||
| @test fibonaccinum(92) < typemax(Int64) < fibonaccinum(93) | ||
| @test fibonaccinum(101) == parse(BigInt, "573147844013817084101") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a reason the forms big"7540113804746346429" and parse(BigInt, "7540113804746346429") are being used?
I think the former might be more performant, but I'm unsure if there is some other reason for testing purposes to use both.
#187
Add new doc for
bellnumfibonaccinumjacobisymbollegendresymbollucasnumUpdate doc for
catalannumlobbnumnarayanalassallenumstirlings1stirlings2Add more tests for
catalannumfibonaccinumlassallenum