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

implemented_by unexpectedly sees _unary and fails #2899

Closed
1 task done
Junology opened this issue Nov 17, 2023 · 0 comments · Fixed by #4508
Closed
1 task done

implemented_by unexpectedly sees _unary and fails #2899

Junology opened this issue Nov 17, 2023 · 0 comments · Fixed by #4508
Labels
bug Something isn't working

Comments

@Junology
Copy link

Prerequisites

  • Put an X between the brackets on this line if you have done all of the following:
    • Check that your issue is not already filed.
    • Reduce the issue to a minimal, self-contained, reproducible test case. Avoid dependencies to mathlib4 or std4.

Description

If a function f is defined using well-founded recursion, then implemented_by attribute looks f._unary instead of f.
As a result, it causes a type error if more than one arguments are involved in the termination proof.

Context

Discussed in Zulip

Steps to Reproduce

MWE:

def myfunUnsafe (x : Array α) (i : Fin x.size) : Array α :=
  sorry

/-
Error:
> invalid 'implemented_by' argument 'myfunUnsafe', 'myfunUnsafe' has type
>   {α : Type u_1} → (x : Array α) → Fin (Array.size x) → Array α
> but 'myfun._unary' has type
>   {α : Type u_1} → (x : Array α) ×' Fin (Array.size x) → Array α
-/
@[implemented_by myfunUnsafe]
def myfun (x : Array α) (i : Fin x.size) : Array α :=
  let next := 2*i.1 + 1
  if h : next < x.size then
      have : x.size - next < x.size - i.1 := sorry
      myfun (x.swap i ⟨next,h⟩) ⟨next, (x.size_swap _ _).symm ▸ h⟩
  else
    x
termination_by _ => x.size - i.1

Versions

Lean version: 4.3.0-rc1

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

Successfully merging a pull request may close this issue.

1 participant