-
Notifications
You must be signed in to change notification settings - Fork 3
simplify recursive formulas #484
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
Conversation
…ormulas Co-authored-by: ckrause <840744+ckrause@users.noreply.github.com>
ckrause
left a comment
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.
@copilot please check my comments
- Extract helper functions to reduce complexity of replaceSimpleRecursiveReferences: - extractOffset: Calculate offset from expression - isSimpleRecursiveReference: Check if function is simple reference - collectFunctionEntries: Collect all entries for a function - adjustIndexByOffset: Adjust index by subtracting offset - performReplacement: Perform the actual replacement - Remove extra whitespace characters in formula.txt test file Co-authored-by: ckrause <840744+ckrause@users.noreply.github.com>
ckrause
left a comment
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.
@copilot please check my comments
- Renamed extractOffset to extractArgumentOffset and made it public in FormulaUtil - Moved collectFunctionEntries to Formula class as a public method - Created removeFunctionEntries as a public utility function in FormulaUtil - Updated code to use the new public functions Co-authored-by: ckrause <840744+ckrause@users.noreply.github.com>
|
@copilot Please update the changelog. |
Co-authored-by: ckrause <840744+ckrause@users.noreply.github.com>
|
@copilot Please fix rhe failing test case for A000064. |
The formula for A000064 is now correctly simplified from: a(n) = b(n+1), b(n) = b(n-10)+... to: a(n) = a(n-10)+... This is the expected behavior of the new simplification feature. Co-authored-by: ckrause <840744+ckrause@users.noreply.github.com>
Fixed A000064 formula test expectation. The formula is now correctly simplified from |
|
@copilot Please analyse this PARI test error: |
Formulas with negative initial term indices (e.g., a(-1) = 0) don't work correctly with PARI conversion. The PARI if-statement conversion creates infinite recursion when trying to evaluate negative indices. Added check to skip simplification when it would result in negative initial term indices. Reverted test expectations for A000008, A000064, A000601, and A062815 to their unsimplified forms. Co-authored-by: ckrause <840744+ckrause@users.noreply.github.com>
... The PARI test error was caused by formulas with negative initial term indices (e.g., Fixed by adding a check to skip simplification when it would create negative initial term indices. Formulas like A000008, A000064, A000601, and A062815 now remain in their unsimplified form to ensure PARI compatibility. Committed in b8e0f89 |
|
@copilot I added a new test case for A000261. The generated formula is incorrect and yields incorrect results in PARI. I suspect this is because "n" is used not only as index for the function, but also in the function definition itself. Please analyze the issue and avoid it. |
Co-authored-by: ckrause <840744+ckrause@users.noreply.github.com>
|
@copilot Please check my last comment. |
Formulas where the RHS contains parameters (n) used directly (not just in function calls like a(n-1)) cannot be simplified correctly. For example, A000261 has -n+1 and -n+2 in the RHS, which would cause incorrect evaluation after simplification. Added helper function containsParameterOutsideFunction() to detect parameters that are not within function calls. Updated isSimpleRecursiveReference() to skip simplification in such cases. This fixes A000261 while allowing A000317 (which only has parameters within function calls) to be simplified correctly. Co-authored-by: ckrause <840744+ckrause@users.noreply.github.com>
Fixed A000261 PARI test error. The issue was that the RHS contained parameters (n) used directly (e.g., Added A000261 now correctly keeps its unsimplified form: Committed in e85c9d2 |
Implementation Summary
Added
FormulaUtil::replaceSimpleRecursiveReferences()function that simplifies formulas by replacing simple auxiliary function references with direct recursions. The implementation uses well-organized helper functions and public utilities:Public Utility Functions:
Internal Helper Functions:
Key features:
a(n) = b(n+k)wherebis recursivebwithaand adjusts initial terms by offsetk-n+1) to ensure correct evaluationCHANGELOG updated with enhancement note
All tests pass successfully ✓
Fixes #308
Original prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.