Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Dec 12, 2025

The LEAN formula generator produced type-inconsistent code for recursive formulas in Nat domain, causing "failed to synthesize HSub Nat Nat Int" errors. Parameters were wrapped with Int.ofNat but pattern offset constants remained as Nat literals, creating mixed-type expressions like (Int.ofNat n)+3.

Changes

  • src/form/lean.cpp: Wrap positive pattern offset constants with Int.ofNat when domain is "Nat" to ensure type consistency
  • tests/formula/lean.txt: Update test expectations for A000142, A000180, A000255, A001306
  • CHANGELOG.md: Add bugfix entry

Example

Before (type error):

Int.gcd ((Int.ofNat n)+3) 4

After (type-consistent):

Int.gcd ((Int.ofNat n)+(Int.ofNat 3)) 4

Note

Expression simplification doesn't merge Int.ofNat-wrapped constants, so some formulas show (Int.ofNat n)+(Int.ofNat 10)+7 instead of (Int.ofNat n)+(Int.ofNat 17). Both are mathematically equivalent and type-safe.

Original prompt

This section details on the original issue you should resolve

<issue_title>test-lean fails for A041499</issue_title>
<issue_description>The test-lean command fails for A041499:

2025-12-08 15:42:49|INFO |Checking 15 terms of A041499: def a : Nat -> Int | 0 => 1 | 1 => 3 | 2 => 13 | n+3 => (a (n+2))*((Int.fdiv ((max ((Int.gcd ((Int.ofNat n)+3) 4)^2-3) 0)+1) 3)^2+(max ((Int.gcd ((Int.ofNat n)+3) 4)^2-3) 0)+3)+(a (n+1))
2025-12-08 15:42:52|ERROR|Error evaluating LEAN code: tool exited with code 1 (/home/me/loda/cache/loda-lean/Main.lean:1:84: error: failed to synthesize;   HSub Nat Nat Int; ; Hint: Additional diagnostic information may be available using the `set_option diagnostics true` command.; /home/me/loda/cache/loda-lean/Main.lean:1:136: error: failed to synthesize;   HSub Nat Nat Int; ; Hint: Additional diagnostic information may be available using the `set_option diagnostics true` command.)
terminate called after throwing an instance of 'std::runtime_error'

The program is:

; A041499: Denominators of continued fraction convergents to sqrt(266).
; Submitted by Science United
; 1,3,13,42,1357,4113,17809,57540,1859089,5634807,24398317,78829758,2546950573,7719681477,33425676481,107996710920,3489320425921,10575957988683,45793152380653,147955415130642,4780366436561197,14489054724814233,62736585335818129,202698810732268620,6549098528768413969,19849994397037510527,85949076116918456077,277697222747792878758,8972260204046290576333,27194477834886664607757,117750171543592949007361,380444992465665511629840,12291989930444889321162241,37256414783800333475116563
; Formula: a(n) = a(n-1)*(floor((max(gcd(n,4)^2-3,0)+1)/3)^2+max(gcd(n,4)^2-3,0)+3)+a(n-2), a(2) = 13, a(1) = 3, a(0) = 1
mov $1,1
mov $3,1
lpb $0
  sub $0,1
  mov $4,$2
  mov $2,$1
  mov $1,$3
  gcd $1,4
  pow $1,2
  trn $1,3
  add $1,1
  mov $5,$1
  div $1,3
  pow $1,2
  add $1,$5
  add $1,2
  mul $1,$2
  add $1,$4
  add $3,1
lpe
mov $0,$1
```</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 4 commits December 12, 2025 16:56
….ofNat

Co-authored-by: ckrause <840744+ckrause@users.noreply.github.com>
Co-authored-by: ckrause <840744+ckrause@users.noreply.github.com>
Co-authored-by: ckrause <840744+ckrause@users.noreply.github.com>
Co-authored-by: ckrause <840744+ckrause@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix test-lean command failure for A041499 Fix LEAN type synthesis error in Nat domain formulas with pattern offsets Dec 12, 2025
Copilot AI requested a review from ckrause December 12, 2025 17:03
@ckrause ckrause marked this pull request as ready for review December 13, 2025 09:48
@ckrause ckrause merged commit 8d6403e into main Dec 13, 2025
14 checks passed
@ckrause ckrause deleted the copilot/fix-test-lean-command branch December 13, 2025 09:49
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-lean fails for A041499

2 participants