Skip to content
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

Termination proof failure in the presence of default arguments #6351

Open
3 tasks done
dupuisf opened this issue Dec 10, 2024 · 1 comment
Open
3 tasks done

Termination proof failure in the presence of default arguments #6351

dupuisf opened this issue Dec 10, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@dupuisf
Copy link

dupuisf commented Dec 10, 2024

Prerequisites

Please put an X between the brackets as you perform the following steps:

Description

When a termination_by statement depends on parameters with a default value, one can sometimes get the error The termination argument's type must not depend on the function's varying parameters.

The error disappears when the default values are removed.

Context

This error occurred when coding a solution to an Advent of Code problem, and was also brought up on the Lean Zulip

Steps to Reproduce

  1. Copy-paste the following code example above into an empty file (no imports required):
def foo (as : Array Nat) (i := 0) (j := as.size - 1) : Array Nat :=
  if j ≤ i then as
  else
    let newas := as.set! 0 0
    foo newas (i+1) (j-1)
termination_by j - i

Expected behavior: The termination_by statement is accepted and no error occurs.
Actual behavior: The termination_by statement produces the error

The termination argument's type must not depend on the function's varying parameters, but pack's termination argument does:
  (disk : Array (Option Nat)) → optParam Nat 0 → optParam Nat (disk.size - 1) → optParam Nat (disk.size - 1)
Try using `sizeOf` explicitly`

Versions

Lean 4.15.0-rc1 (locally, and also on live.lean-lang.org)
Target: x86_64-unknown-linux-gnu
Arch Linux x86_64, kernel 6.6.63-1-lts

Also tried Lean 4.16.0-nightly-2024-12-09 on live.lean-lang.org, the bug is also present there.

Impact

Add 👍 to issues you consider important. If others are impacted by this issue, please ask them to add 👍 to it.

@dupuisf dupuisf added the bug Something isn't working label Dec 10, 2024
@nomeata
Copy link
Collaborator

nomeata commented Dec 10, 2024

JFTR, another work-around is to write

termination_by @id Nat (j - i)

to infer a type without default arguments.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants