Zulip Chat Archive

Stream: mathlib4

Topic: simp loop


Kevin Buzzard (Sep 09 2023 at 15:52):

import Mathlib.Data.Int.Basic

-- in `std` and tagged @[simp]
#check Int.ofNat_add_ofNat
/-
Int.ofNat_add_ofNat (m n : ℕ) : ↑m + ↑n = ↑(m + n)
-/
-- in `mathlib` and tagged @[simp]
#check Nat.cast_add
/-
Nat.cast_add.{u_1} {R : Type u_1} [inst✝ : AddMonoidWithOne R] (m n : ℕ) : ↑(m + n) = ↑m + ↑n
-/

example (a b : ) : (a : ) + (b : ) = 37 := by simp -- hangs

Kevin Buzzard (Sep 09 2023 at 15:54):

(credit to @Bhavik Mehta who ran into this on the train from Duessoldorf and now has a flat laptop battery)

Kevin Buzzard (Sep 09 2023 at 16:48):

@Mario Carneiro Nat.cast_add was simp in Lean 3. Should simp be removed from Int.ofNat_add_ofNat?

Yaël Dillies (Sep 09 2023 at 16:51):

Or maybe the lemma should simply be turned around?

Joachim Breitner (Sep 09 2023 at 16:59):

Usually with simp lemmas, you want more primitive and unary operations to moved inside of less primitive and nary operations. So turning it around seems the right call, I'd say

Kevin Buzzard (Sep 09 2023 at 17:04):

My understanding that with lemmas like this, the simplifier is in fact ill-equipped to deal with the problem. Sometimes you want to push casts in and sometimes out. This is why we have norm_cast and push_cast. Because of this I've never quite known what to do with simp and lemmas like this. What works for one application might not work for another.

Bhavik Mehta (Sep 09 2023 at 19:01):

Just to be clear, is the suggestion to turn Int.ofNat_add_ofNat around, or Nat.cast_add? My vote is to turn the former around, and keep the latter as it is, and keep it simp

Yaël Dillies (Sep 09 2023 at 19:02):

Turn Int.ofNat_add_ofNat around. It's a distributivity lemma, and distributivity lemmas should have their RHS distributed.

Bhavik Mehta (Sep 09 2023 at 19:07):

Then we're in agreement :)

Mario Carneiro (Sep 10 2023 at 18:30):

The reason ofNat_add_ofNat is in the order it is is because this is one of four equational lemmas for Int.add

Mario Carneiro (Sep 10 2023 at 18:30):

so it should probably just be @[local simp]

Jireh Loreaux (Sep 10 2023 at 18:58):

What does local simp mean? Only until the current scope ends I guess (section, namespace or file)?

Scott Morrison (Sep 14 2023 at 01:22):

Haha, I had not read this thread, but had just independently decided to put local simp there, and just searched zulip thinking "surely someone has wanted this previously".

Scott Morrison (Sep 14 2023 at 01:46):

This gets done, amongst other things, in std4#261, with mathlib bump #7141

Kevin Buzzard (Sep 14 2023 at 08:52):

Thanks Scott! I was thinking of making a Std PR but realised I had no idea how to actually do this and also realised that even if I could make a change and get std compiling, this was no guarantee that I'd not broken mathlib. This and the imminent start of term stopped me from working on this...


Last updated: Dec 20 2023 at 11:08 UTC