Zulip Chat Archive

Stream: general

Topic: let


Michael Beeson (Aug 02 2023 at 03:31):

Once I have used let X:= something
and then I have a goal involving X, how do I get X replaced by the original something?

Scott Morrison (Aug 02 2023 at 03:32):

dsimp [X]

Michael Beeson (Aug 02 2023 at 03:35):

Yes, that worked! TYVM!

Michael Beeson (Aug 02 2023 at 03:35):

Was there a way other than Zulip for me to have learned that? Not mentioned in the manual where "let" is briefly discussed.

Niels Voss (Aug 02 2023 at 05:07):

There was a thread on this somewhat recently: https://leanprover.zulipchat.com/#narrow/stream/113488-general/topic/How.20to.20unwrap.20a.20let.20expression
There isn't really a good way to have found this information, but dsimp is not the only way to unfold the let expression

Niels Voss (Aug 02 2023 at 05:10):

The main difference between let and have is that when you do let X := something now X is definitionally equal to something so you can prove X = something with only rfl

Niels Voss (Aug 02 2023 at 05:13):

Sometimes you don't even need to unfold X, since if the goal is something = 37 then Lean will accept instead a proof that X = 37 (in practice unfolding X often makes things simpler). I do wish this was documented somewhere though.

Sophie Morel (Aug 02 2023 at 09:23):

You can also use set, as in set X := something with hX, then you will have a hypothesis hX in your context that says X = something and you can feed it to rw. In most cases simp and its friends will do the job, but this is still a useful trick sometimes.

Sophie Morel (Aug 02 2023 at 09:24):

Oops, this was already mentioned by Kevin in the linked thread. My bad.

Kyle Miller (Aug 02 2023 at 09:47):

If #5717 gets merged, then you'll be able to do unfold_let X (docstring in PR)

This is like dsimp but it unfolds X without touching anything else. dsimp can do other reductions too.


Last updated: Dec 20 2023 at 11:08 UTC