Zulip Chat Archive

Stream: lean4

Topic: Introduce a let in a subexpression


Bolton Bailey (Apr 13 2024 at 01:18):

How do I introduce i to the context here?

example : (let i := 2; i + 3) = 5 := by
  intro i -- fails

Bolton Bailey (Apr 13 2024 at 01:19):

I have a large number of let statements and I'd like to introduce them all

example : (let i := 2; let j := 1; let k := 2; i + j + k) = 5 := by
  intros i j k

Richard Osborn (Apr 13 2024 at 02:15):

Something like this?

import Mathlib

example : (let i := 2; let j := 1; let k := 2; i + j + k) = 5 := by
  lift_lets
  extract_lets i j
  dsimp [i,j]

Leni Aniva (Apr 15 2024 at 17:48):

Is there a way to solve this without using mathlib?

Kyle Miller (Apr 15 2024 at 18:45):

Not really. The lift_lets tactic is hard to reproduce with other tactics.

You can replace extract_lets i j with intro i j however.

Leni Aniva (Apr 15 2024 at 18:57):

I hope lift_lets can be included included in the prelude then

Kim Morrison (Apr 17 2024 at 03:17):

@Leni Aniva, it looks like this would be easy to do, and I agree it would be reasonable. Currently Mathlib/Tactic/LiftLets imports Mathlib/Tactic/Basic, but it seems that can be replaced with import Lean (but should be replaced with something finer).

If you wanted to make a PR moving this to the lean4 repository (I'm sure Kyle, the author, won't object), I could help clean it up and turn it into a built-in tactic. Otherwise we can try to get to it later.

Kyle Miller (Apr 17 2024 at 03:24):

I'd be happy to upstream these tactics myself if core wants them.

Kim Morrison (Apr 17 2024 at 03:28):

I think it's reasonable. They are fundamental tactics that you inevitably need once you're dealing with let, there's no need for them to be in Mathlib, and we have evidence above that they are wanted outside Mathlib.

Kim Morrison (Apr 17 2024 at 03:28):

I guess extract_lets uses some other stuff in Mathlib still.

Kim Morrison (Apr 17 2024 at 03:29):

Oh, maybe just letDepth, which is trivial to upstream.


Last updated: May 02 2025 at 03:31 UTC