Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Nov 15, 2025

Formula generation failed slowly (~37 seconds) for A000033 and similar programs using ROL operations on many cells. The program uses rol $2,8, creating 8 stateful cells. After variant simplification, the formula generator required 15 initial terms, exceeding the limit of 10.

Changes

  • src/form/formula_gen.cpp: Added early failure detection before expensive variant simplification
  • CHANGELOG.md: Documented enhancement

Implementation

Added an early check that rejects programs when base initial terms count exceeds 70% of the limit (7 out of 10). This check occurs before calling the expensive simplifyFormulaUsingVariants function, providing immediate feedback instead of waiting for the full processing.

Threshold Logic

The 70% threshold accounts for the fact that variant simplification typically increases the initial terms count by 30-70%. Programs with ≤7 base terms can proceed to variant simplification, while those with ≥8 base terms are rejected early.

Performance Results

  • A000033: Now fails in ~0.08s (previously ~37s) - 460x faster
  • 8-cell ROL: Fails in ~0.07s (fast rejection)
  • 7-cell ROL: Still succeeds ✅ (~0.02s)
  • 4-cell ROL: Still succeeds ✅ (~0.004s)

The program continues to be correctly rejected, but users now receive immediate feedback rather than waiting half a minute for an error.

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
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