Zulip Chat Archive

Stream: new members

Topic: Unfolding local function


Felipe (Nov 15 2022 at 03:36):

It seems when using let to declare a function in a block of tactics that rw/simp/unfold don’t work on it. Is there a different tactic needed for that? FWIW, I’m defining a local function to apply an induction principle and need to prove some properties of it. Also, it’s technically a closure

Junyan Xu (Nov 15 2022 at 03:39):

dsimp only [name_of_your_function] should work. I forgot whether simp only is supposed to work ...

Matt Diamond (Nov 15 2022 at 03:54):

simp_rw F might also work (where F is the name of your function)

Martin Dvořák (Nov 15 2022 at 09:50):

Which version of Lean is it for?

Riccardo Brasca (Nov 15 2022 at 09:52):

Unless it is explicitly said, we always talk about Lean 3 (except in the Lean4 stream of course).

Martin Dvořák (Nov 15 2022 at 09:54):

I was confused because I never saw simp_rw before.

Riccardo Brasca (Nov 15 2022 at 09:55):

Here it is.

Martin Dvořák (Nov 15 2022 at 09:56):

Oh! It looks delicious!

Riccardo Brasca (Nov 15 2022 at 09:58):

If rw gives the infamous "motive is not type correct" error, then simp_rw is the first thing to try.

Riccardo Brasca (Nov 15 2022 at 09:58):

It's also very useful to rewrite under binders.

Felipe (Nov 15 2022 at 10:06):

Thanks! Is there an equivalent in Lean4?

Alex J. Best (Nov 15 2022 at 10:08):

If you use mathlib4 there is a direct replacement https://leanprover-community.github.io/mathlib4_docs/Mathlib/Tactic/SimpRw.html#Mathlib.Tactic.tacticSimp_rw__

Felipe (Nov 15 2022 at 17:43):

Thanks. I'm still getting "invalid 'simp', proposition expected" when I do simp_rw [f] at X But I was able to work around by switching to term mode

Martin Dvořák (Nov 15 2022 at 18:08):

What is f and X in your context?

Jason Rute (Nov 16 2022 at 12:08):

Is this related to https://proofassistants.stackexchange.com/questions/1846/proving-with-non-structural-recursion-in-lean4? My answer hopefully will get you started, but this group might better help you complete your proof.

Felipe (Nov 18 2022 at 02:18):

Thank you! Your answer did indeed get me on the right track. Seeing the autogenerated lemmas helped me figure out the issue in the original recursive definition and I was able to fix

Suryansh Shrivastava (Aug 15 2023 at 21:10):

I have used unfold to expand a function that I have already made. I heard that it is a bad practice to use in the Lean code. So, I was wondering how does one not use unfold?

Martin Dvořák (Aug 16 2023 at 10:38):

I personally don't mind using unfold in my proofs, but if you want to avoid it, there are several things you can use instead:
show followed by a new goal (that has to be definitionally-equal to the old goal)
dsimp only
add a rfl lemma for your definition and use rw

Martin Dvořák (Aug 16 2023 at 10:46):

Apart from that, you can often notice that you do unfold and a next step, but if you remove unfold the next step still works.


Last updated: Dec 20 2023 at 11:08 UTC