Skip to content

chore: potential nontermination at simp#485

Merged
joehendrix merged 2 commits intomainfrom
simp_loop
Dec 28, 2023
Merged

chore: potential nontermination at simp#485
joehendrix merged 2 commits intomainfrom
simp_loop

Conversation

@leodemoura
Copy link
Copy Markdown
Contributor

Using simp [forIn] may cause nontermination with different simp reduction strategies. We have the following theorem

@[simp] theorem forIn_eq_forIn [Monad m] : @List.forIn α β m _ = forIn := rfl

Then, executing simp [forIn] in a term containing forIn iterating over a List may cause nontermination since the theorem above will fold it again.

Remark: the reduction strategy implemented
leanprover/lean4#3118 triggers the nontermination.

Using `simp [forIn]` may cause nontermination with different `simp`
reduction strategies. We have the following theorem
```
@[simp] theorem forIn_eq_forIn [Monad m] : @List.forIn α β m _ = forIn := rfl
```
Then, executing `simp [forIn]` in a term containing `forIn` iterating
over a `List` may cause nontermination since the theorem above will fold it again.

Remark: the reduction strategy implemented
leanprover/lean4#3118 triggers nontermination.
@digama0
Copy link
Copy Markdown
Member

digama0 commented Dec 27, 2023

Why wasn't this already nonterminating before?

@digama0
Copy link
Copy Markdown
Member

digama0 commented Dec 27, 2023

In general this seems like it will be a problem with any use of simp lemmas for re-folding an unfolded notation, e.g. Nat.add a b = a + b (which are important for cleaning up a goal state when these appear due to some other tactic). Is there something we can do with tagging them specially or detecting that they are the inverse of a definitional equation and turning them off when the user explicitly uses simp [(. + .)] or the like?

@joehendrix
Copy link
Copy Markdown
Contributor

I noticed these lemmas also had non-terminal simp, so I went ahead and cleaned that up.

I think there are a ways this could be improved. Ultimately, I think it'd be nice if we had some sort of simp modulo some limited equations so that, for example, Nat.add and @Add.add Nat instAddNat were equal for simp. That's a ways off though.

@joehendrix joehendrix added the will-merge-soon PR will be merged soon. Any concerns should be raised quickly. label Dec 27, 2023
@joehendrix joehendrix merged commit ae0f50b into main Dec 28, 2023
@joehendrix joehendrix deleted the simp_loop branch December 28, 2023 18:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

will-merge-soon PR will be merged soon. Any concerns should be raised quickly.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants