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

[Typo] Section 8.5 recursion on wrong var in Nat.plusR rhs #160

Open
mars0i opened this issue Sep 19, 2024 · 2 comments
Open

[Typo] Section 8.5 recursion on wrong var in Nat.plusR rhs #160

mars0i opened this issue Sep 19, 2024 · 2 comments
Labels
Typo Typographical or grammatical errors in the text

Comments

@mars0i
Copy link

mars0i commented Sep 19, 2024

def Nat.plusR : Nat → Nat → Nat
  | n, 0 => n
  | n, k + 1 => plusR n k + 1

The recursion doesn't reduce the size of either Nat and generates a "Failed to show termination" error. I believe the last line should be

  | n, k + 1 => plusRinbook (n + 1) k 

Full error text:

▶ 8:5-8:14: error:
fail to show termination for
  Nat.plusR
with errors
failed to infer structural recursion:
Cannot use parameter #1:
  failed to eliminate recursive application
    n.plusR (k + 1)
Cannot use parameter #2:
  failed to eliminate recursive application
    n.plusR (k + 1)

Could not find a decreasing measure.
The arguments relate at each recursive call as follows:
(<, ≤, =: relation proved, ? all proofs failed, _: no proof attempted)
            x1 x2
1) 10:16-31  =  =
Please use `termination_by` to specify a decreasing measure.
@mars0i mars0i added the Typo Typographical or grammatical errors in the text label Sep 19, 2024
@david-christiansen
Copy link
Collaborator

Thanks!

@mars0i
Copy link
Author

mars0i commented Oct 13, 2024

My report is incorrect. It's an embarrassing rookie mistake. I interpreted the code in FPIL,

def Nat.plusR : Nat -> Nat -> Nat
  | n, 0 => n
  | n, k + 1 => plusR n k + 1

as

def Nat.plusR : Nat -> Nat -> Nat
  | n, 0 => n
  | n, k + 1 => plusR n (k + 1)

which doesn't terminate, rather than

def Nat.plusR : Nat -> Nat -> Nat
  | n, 0 => n
  | n, k + 1 => (plusR n k) + 1

which does. I added the parentheses around k + 1 in my code, and then didn't copy the parentheses into this report. The original FPIL definition, without added parentheses, doesn't generate a termination error in Lean 4.13.0-rc3.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Typo Typographical or grammatical errors in the text
Projects
None yet
Development

No branches or pull requests

2 participants