Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Nov 28, 2025

  • Investigate the issue with PARI formula for A006430
  • Identify the root cause: rising factorial formula (a+b-1)!/(a-1)! generates undefined (-1)! when a=0
  • Implement fix to use product expansion when the factorial denominator can be negative
  • Add test for A006430 PARI formula
  • Verify the fix with existing tests
  • Run code review and security checks
  • Add range check before Number.asInt() to avoid exception for large numbers
  • Simplify logic and improve comments based on code review feedback

Summary

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 base a could be zero.

Problem

When generating PARI/GP formulas for rising factorials, the code would generate expressions like (a+b-1)!/(a-1)!. For A006430, when n=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 where b is within the MAX_PRODUCT_EXPANSION threshold (±10). This ensures that when a can be zero, the formula uses an explicit product like a*(a+1)*(a+2)*(a+3) instead of the factorial division form (a+3)!/(a-1)!.

Key changes

  • Added range check in Number format before calling asInt() to avoid exceptions
  • Simplified the logic by removing redundant conditional
  • Updated comments to clarify the intent of the range check
Original prompt

This section details on the original issue you should resolve

<issue_title>Test PARI formula for A006430</issue_title>
<issue_description>It seems there is a problem with factorial usage in PARI for A006430. Please check.</issue_description>

Comments on the Issue (you are @copilot in this section)


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI changed the title [WIP] Fix factorial usage in PARI for A006430 Fix PARI formula generation for rising factorial when base can be zero Nov 28, 2025
Copilot AI requested a review from ckrause November 28, 2025 20:59
Copilot finished work on behalf of ckrause November 28, 2025 20:59
@ckrause
Copy link
Contributor

ckrause commented Nov 29, 2025

@copilot Number.asInt() throws an exception if the number is too large. Avoid this by first doing a range check in the Number format.

Copy link
Contributor Author

Copilot AI commented Nov 29, 2025

@copilot Number.asInt() throws an exception if the number is too large. Avoid this by first doing a range check in the Number format.

Added a range check using Number comparisons (b.value >= Number(-MAX_PRODUCT_EXPANSION) && b.value <= Number(MAX_PRODUCT_EXPANSION)) before calling asInt() in commit 94f1e1a.

Copilot finished work on behalf of ckrause November 29, 2025 15:49
@ckrause ckrause marked this pull request as ready for review November 29, 2025 15:50
@ckrause ckrause merged commit f2e32c7 into main Nov 29, 2025
7 checks passed
@ckrause ckrause deleted the copilot/fix-pari-factorial-usage branch November 29, 2025 15:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Test PARI formula for A006430

2 participants