Zulip Chat Archive

Stream: mathlib4

Topic: set tactic doesn't work with dependent functions


Floris van Doorn (Jun 07 2024 at 18:32):

The set tactic doesn't work well with dependent functions:

import Mathlib.Tactic.Set

example {ι : Type} {α : ι  Type} {i i' : ι} (h : α i = α i') (x : α i) (y : α i') :
    (cast h x, i) = (y, i) := by
  set j := i -- duplicates hypothesis `h` and `x` and doesn't replace i in the goal

The reason is that set internally uses rw, which is problematic. It would be much better to use dsimp.

However, I have also no idea how to use simp or dsimp to do this without duplicating hypotheses:

set_option trace.Meta.Tactic.simp true
example {ι : Type} {α : ι  Type} {i i' : ι} (h : α i = α i') (x : α i) (y : α i') :
    cast h x = y := by
  let j := i
  dsimp only [show i = j from rfl] at h -- dsimp made no progress
  simp only [show i = j from rfl] at h -- succeeds, but duplicates the hypothesis h.

simp duplicates hypotheses, and dsimp doesn't fire, presumably because it doesn't recognize show i = j from rfl as a rfl-proof.

Kyle Miller (Jun 07 2024 at 19:44):

Maybe this would be a good use of the un-merged refold_let tactic? #12745

Floris van Doorn (Jun 07 2024 at 19:47):

Ohh, that looks good. We should definitely use that to improve the set tactic.

Floris van Doorn (Jun 07 2024 at 19:54):

However, we need a version of refold_let that is willing to reorder hypotheses so that it can fold more lets.

Kyle Miller (Jun 07 2024 at 20:01):

Could you give an example of what this variation on refold_let should do to support set?

Kyle Miller (Jun 07 2024 at 21:38):

Maybe there needs to be a variant of let that defines something as early as possible?

Floris van Doorn (Jun 07 2024 at 22:16):

It should be able to handle the examples above, i.e. something like

example {ι : Type} {α : ι  Type} {i i' : ι} (h : α i = α i') (x : α i) (y : α i') :
    (cast h x, i) = (y, i) := by
  let j := i
  refold_let j at *

Floris van Doorn (Oct 03 2024 at 10:14):

@Kyle Miller I see that #12745 has been merged. It would be great if it were used in the set tactic!

Floris van Doorn (Feb 19 2025 at 17:23):

In the Carleson project there is an occurrence of the set tactic that takes >1 second to compile (because of the internal rws it's using). So I'm still hoping for this new set tactic :smile:


Last updated: May 02 2025 at 03:31 UTC