Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Nov 15, 2025

Improve formula generation performance by imposing tighter limits on variant simplification

Changes

Per feedback, reverted the early check for initial terms and instead imposed tighter limits in simplifyFormulaUsingVariants():

  • src/form/variant.cpp:
    • Reduced term limit from 500 to 200 per variant
    • Added limit of 20 variants per function to reduce O(n^4) complexity
    • Reduced total variants limit from 200 to 100
    • Added iteration limit of 50 to prevent excessive processing
  • src/form/formula_gen.cpp: Reverted to original state (removed early check)
  • CHANGELOG.md: Updated to reflect the change

Performance Results

  • A000033: Now completes in ~0.66s (previously ~37s) - 56x faster
  • All existing tests pass

The formula generation is still allowed to reject programs if they exceed the initial terms limit (10), but now the variant simplification phase itself is bounded to prevent excessive runtime.

Original prompt

This section details on the original issue you should resolve

<issue_title>Support formula generation for A000033</issue_title>
<issue_description>When trying to generate a formula for A000033, the formula generator takes quite long about 30 seconds and then return an error that it cannot generate a formula for this program. Find out whether it is indeed too complex and if we can enhance the formula generator to support it.

; A000033: Coefficients of ménage hit polynomials.

#offset 1

mov $3,2
mov $4,3
mov $5,4
mov $6,40
mov $7,210
mov $8,1477
mov $9,11672
sub $0,1
lpb $0
  mul $2,-2
  rol $2,8
  mov $11,$1
  mul $11,-2
  sub $11,1
  mov $10,$2
  mul $10,$11
  mov $11,$1
  mul $11,-3
  add $11,6
  add $9,$10
  mov $10,$3
  mul $10,$11
  mov $11,$1
  mul $11,3
  add $11,24
  add $9,$10
  mov $10,$4
  mul $10,$11
  mov $11,$1
  mul $11,10
  add $11,50
  add $9,$10
  mov $10,$5
  mul $10,$11
  mov $11,$1
  mul $11,11
  add $11,62
  add $9,$10
  mov $10,$6
  mul $10,$11
  mov $11,$1
  mul $11,7
  add $11,44
  add $9,$10
  mov $10,$7
  mul $10,$11
  mov $11,$1
  mul $11,2
  add $11,11
  add $9,$10
  mov $10,$8
  mul $10,$11
  add $9,$10
  div $9,2
  sub $0,1
  add $1,1
lpe
mov $0,$2
```</issue_description>

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

<comments>
</comments>


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

Co-authored-by: ckrause <840744+ckrause@users.noreply.github.com>
Copilot AI changed the title [WIP] Support formula generation for A000033 Increase maxInitialTerms limit to support formula generation for programs with many stateful cells Nov 15, 2025
Copilot AI requested a review from ckrause November 15, 2025 16:47
Copilot finished work on behalf of ckrause November 15, 2025 16:47
@ckrause
Copy link
Contributor

ckrause commented Nov 15, 2025

@copilot The max number of initial terms should remain at 10. We should continue to reject this program. However, it would be great if the formula generation could fail fast in such cases (it takes too long).

…erms

Co-authored-by: ckrause <840744+ckrause@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Nov 15, 2025

@copilot The max number of initial terms should remain at 10. We should continue to reject this program. However, it would be great if the formula generation could fail fast in such cases (it takes to...

Reverted maxInitialTerms to 10 and added early failure detection instead. The program now rejects A000033 but fails fast in ~0.08s instead of ~37s. The check triggers before the expensive variant simplification when base initial terms exceed 70% of the limit (commit b5a3f15).

Copilot AI changed the title Increase maxInitialTerms limit to support formula generation for programs with many stateful cells Add fast-fail detection for formula generation with excessive initial terms Nov 15, 2025
Copilot finished work on behalf of ckrause November 15, 2025 17:04
@ckrause
Copy link
Contributor

ckrause commented Nov 28, 2025

@copilot Revert the additional check for intial terms. Instead, impose stronger limits in simplifyFormulaUsingVariants() to reduce the execessive runtime of the formula generation for A000033.

…variant simplification

Co-authored-by: ckrause <840744+ckrause@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Nov 28, 2025

@copilot Revert the additional check for intial terms. Instead, impose stronger limits in simplifyFormulaUsingVariants() to reduce the execessive runtime of the formula generation for A000033.

Reverted the early check and instead imposed tighter limits in simplifyFormulaUsingVariants(): reduced term limit (500→200), added per-function variant limit (20), reduced total variants (200→100), and added iteration limit (50). A000033 now completes in ~0.66s instead of ~37s while all tests pass (commit 456c495).

Copilot finished work on behalf of ckrause November 28, 2025 19:52
@ckrause ckrause marked this pull request as ready for review November 28, 2025 20:07
@ckrause ckrause merged commit ebd9d9d into main Nov 28, 2025
7 checks passed
@ckrause ckrause deleted the copilot/enhance-formula-generator branch November 28, 2025 20:09
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.

Support formula generation for A000033

2 participants