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

Nat.add n 0 expressions appear when unfolding with simp (but not with rw) #3022

Closed
kmill opened this issue Dec 5, 2023 · 1 comment · Fixed by #3616
Closed

Nat.add n 0 expressions appear when unfolding with simp (but not with rw) #3022

kmill opened this issue Dec 5, 2023 · 1 comment · Fixed by #3616
Assignees
Labels
bug Something isn't working

Comments

@kmill
Copy link
Collaborator

kmill commented Dec 5, 2023

Description

When using unfold or simp to unfold a recursive function, the expression Nat.add n 0 appears inside the body of the unfolded function rather than n. In the following example, you can uncomment the unfold or simp lines to see the given goal state. In contrast, rw results in the wanted state.

def foo : Nat → Nat
  | 0 => 2
  | n + 1 => foo n

example (n : Nat) : foo (n + 1) = 2 := by
  --unfold foo      -- ⊢ foo (Nat.add n 0) = 2
  --simp only [foo] -- ⊢ foo (Nat.add n 0) = 2
  --rw [foo]        -- ⊢ foo n = 2
  sorry

Expected behavior: In each of these three commented out lines, the goal state becomes ⊢ foo n = 2.

Actual behavior: Only the rw tactic results in the expected goal state.

Context

When using a custom eliminator in the induction or cases tactic for Nat that uses 0 and n + 1 rather than Nat.zero and Nat.succ n, expressions such as foo (n + 1) occur. If this is a proof about foo, then it is natural to unfold it. However, using unfold or simp results in expressions with Nat.add n 0. Eliminating these requires further application of lemmas such as Nat.add_eq and add_zero to clean up the expression.

protected def Nat.recAux {motive : Nat → Sort _}
    (zero : motive 0) (succ : ∀ n, motive n → motive (n+1)) : (t : Nat) → motive t
  | 0 => zero
  | _+1 => succ _ (Nat.recAux zero succ _)

example (n : Nat) : foo n = 2 := by
  induction n using Nat.recAux with
  | zero => rfl
  | succ n ih =>
    --unfold foo      -- ⊢ foo (Nat.add n 0) = 2
    --simp only [foo] -- ⊢ foo (Nat.add n 0) = 2
    --rw [foo]        -- ⊢ foo n = 2
    exact ih

This is an obstruction to the "beautiful induction for Nat" project. We do not want users to see Nat.add expressions.

Versions

MacOS arm64

#eval Lean.versionString -- "4.4.0-rc1"

Additional Information

[Additional information, configuration or data that might be necessary to reproduce the issue]

Impact

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

@kmill kmill added the bug Something isn't working label Dec 5, 2023
@kmill kmill changed the title Get Nat.add n 0 expressions when unfolding with simp but not in rw Nat.add n 0 expressions appear when unfolding with simp (but not with rw) Dec 5, 2023
@kmill
Copy link
Collaborator Author

kmill commented Dec 5, 2023

@leodemoura This issue is an obstruction to moving forward with using nicer eliminators when doing Nat induction. Do you think it could be easily fixed?

leodemoura added a commit that referenced this issue Mar 6, 2024
closes #3022

With this commit, given the declaration
```
def foo : Nat → Nat
  | 0 => 2
  | n + 1 => foo n
```
when we unfold `foo (n+1)`, we now obtain `foo n` instead of
`foo (Nat.add n 0)`.
github-merge-queue bot pushed a commit that referenced this issue Mar 6, 2024
closes #3022

With this commit, given the declaration
```
def foo : Nat → Nat
  | 0 => 2
  | n + 1 => foo n
```
when we unfold `foo (n+1)`, we now obtain `foo n` instead of `foo
(Nat.add n 0)`.
tydeu pushed a commit to tydeu/lean4 that referenced this issue Mar 11, 2024
closes leanprover#3022

With this commit, given the declaration
```
def foo : Nat → Nat
  | 0 => 2
  | n + 1 => foo n
```
when we unfold `foo (n+1)`, we now obtain `foo n` instead of `foo
(Nat.add n 0)`.
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.

2 participants