Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Dec 7, 2025

Formula generation was producing empty output for programs containing ROL operations in loops (e.g., A069195). The issue affected any program that generates a self-recursive formula like a(n) = a(n-k).

Root Cause

FormulaSimplify::replaceSimpleRecursiveRefs is designed to eliminate helper functions that are simple shifted references to other recursive functions (e.g., a(n) = b(n+1) where b is recursive). The helper function isSimpleRecursiveReference was incorrectly treating self-recursive definitions as simple references:

// Before: incorrectly matched both cases
a(n) = b(n+1)  // ✓ Simple reference to another function - should match
a(n) = a(n-7)  // ✗ Self-recursive definition - should NOT match

This caused the formula to be erased, resulting in empty output.

Changes

  • Added early return in isSimpleRecursiveReference when refFuncName == funcName
  • Self-recursive functions now correctly bypass the simplification logic

The fix is a 3-line guard placed immediately after extracting the referenced function name.

Original prompt

This section details on the original issue you should resolve

<issue_title>Empty formula generated for A069195</issue_title>
<issue_description>The generated formula for A069195 is an empty string:

./loda export -o formula A069195

Please fix this bug. If formula generation is supported for A069195, it must be a non-empty string.

The program for A069195 is:

; A069195: Order of first letter of English name of consecutive days of the week starting from a Monday.
; 13,20,23,20,6,19,19,13,20,23,20,6,19,19,13,20,23,20,6,19,19,13,20,23,20,6,19,19,13,20,23,20,6,19,19,13,20,23,20,6,19,19,13,20,23,20,6,19,19,13,20,23,20,6,19,19,13,20,23,20,6,19,19,13,20,23,20,6,19,19,13,20,23,20,6,19,19,13,20,23

mov $2,13
mov $3,20
mov $4,23
mov $5,20
mov $6,6
mov $7,19
mov $8,19
lpb $0
  rol $2,7
  sub $0,1
lpe
mov $0,$2
```</issue_description>

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

<comments>
</comments>


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 2 commits December 7, 2025 13:41
Fixed bug where formulas were incorrectly cleared for recursive functions that reference themselves. The replaceSimpleRecursiveRefs function was incorrectly treating self-recursive definitions (like a(n) = a(n-7)) as "simple references" when they are actually recursive definitions. Added a check to skip functions that reference themselves.

Co-authored-by: ckrause <840744+ckrause@users.noreply.github.com>
Moved self-reference check immediately after refFuncName assignment for better code readability and fail-fast behavior.

Co-authored-by: ckrause <840744+ckrause@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix empty formula generation for A069195 Fix empty formula generation for self-recursive functions Dec 7, 2025
Copilot AI requested a review from ckrause December 7, 2025 13:45
@ckrause ckrause marked this pull request as ready for review December 7, 2025 15:03
@ckrause ckrause merged commit ea41487 into main Dec 7, 2025
7 checks passed
@ckrause ckrause deleted the copilot/fix-empty-formula-a069195 branch December 7, 2025 15: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.

Empty formula generated for A069195

2 participants