Zulip Chat Archive

Stream: lean4

Topic: unfold and unfold_let


Jon Eugster (Apr 25 2024 at 15:08):

unfold_let and unfold seem to serve a very similar purpose, one for "local definitions" and the other one for "global" definitions.

Would it make sense to merge the two tactics to a single unfold that can handle both or are there good reasons why they should stay distinct? Is it a problem if Lean first has to figure out what the arguments provided are, fvars or global constants?

import Mathlib

example (A B : Type) (h : A = B) :
    let C := A
    C = B := by
  intro C
  /-
  AB: Type
  h: A = B
  C: Type := A
  ⊢ C = B
  -/
  unfold_let C
  rw [h]


def C := Nat

example (A B : Type) (h : Nat = B) :
    C = B := by
  unfold C
  rw [h]

Patrick Massot (Apr 25 2024 at 15:27):

I agree that this distinction looks like a historical accident that could be fixed now that everything is in core (I guess everything is core?).

Kyle Miller (Apr 25 2024 at 15:48):

unfold_let is a mathlib tactic, and it pre-dated being able to write dsimp only [C]

Patrick Massot (Apr 25 2024 at 15:50):

Can’t you simply merge it with unfold now? This is a really natural expectation for new users.

Ruben Van de Velde (Apr 25 2024 at 15:53):

I wonder if there's a clear explanation somewhere when you need unfold rather than dsimp or the other way around

Jon Eugster (Apr 25 2024 at 15:58):

ok, in that case I might give it a shot to merge the two at some point :+1:

Kyle Miller (Apr 25 2024 at 15:58):

@Patrick Massot It's on my list of things to look into

Jon Eugster (Apr 25 2024 at 16:00):

I'm not exactly sure, but I think dsimp [C] does just a little bit more than unfold . So far I've been using unfold as "plug in the definition but don't do anything else". Not aware of anything that unfold could do which dsimp does not

Kyle Miller (Apr 25 2024 at 16:53):

dsimp only [C] makes sure to not use dsimp lemmas (simp lemmas that are proved by rfl), but it also does some reductions, like beta reduction, etc.

Kyle Miller (May 07 2024 at 15:04):

RFC: lean4#4090


Last updated: May 02 2025 at 03:31 UTC