Fix PARI formula generation for rising factorial when base can be zero #615
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
(a+b-1)!/(a-1)!generates undefined(-1)!whena=0Number.asInt()to avoid exception for large numbersSummary
This PR fixes an issue with PARI/GP formula generation for sequences like A006430 where the rising factorial operation
fac a,b(b > 0) would generate an invalid factorial expression when the baseacould be zero.Problem
When generating PARI/GP formulas for rising factorials, the code would generate expressions like
(a+b-1)!/(a-1)!. For A006430, whenn=1, the base expression evaluates to 0, making the denominator(-1)!which is undefined in PARI/GP.Solution
The fix extends the product expansion approach (already used for small constant values of
b) to handle all cases wherebis within theMAX_PRODUCT_EXPANSIONthreshold (±10). This ensures that whenacan be zero, the formula uses an explicit product likea*(a+1)*(a+2)*(a+3)instead of the factorial division form(a+3)!/(a-1)!.Key changes
asInt()to avoid exceptionsOriginal prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.