Zulip Chat Archive

Stream: new members

Topic: seeing inferred arguments for a theorem application


Rado Kirov (Oct 25 2025 at 19:23):

When I write something like rw [add_comm] Lean implicitly infers the two arguments {a b} for add_comm and then applies the rewrite a + b = b + a for some a and b. Is there a way to see in the InfoView or other tool, what the inferred a and b precisely are. Kind hoped hovering over add_comm would do that, but it doesn't seem too.

I know that, of course, I can work those backwards from the resulting rewrite in the local goals, but it require a bit of extra work from me (imagine the theorem being {a b}: <some messy expression with a b> applied to an <even messier expression that contains the theorems messy subexpression>).

Ruben Van de Velde (Oct 25 2025 at 19:42):

If you put show_term before rw, you can probably find the answer in there

Alfredo Moreira-Rosa (Oct 25 2025 at 19:49):

Indeed, but it's really ugly. Would be nice if LSP could show what it inferred.
Another way i use sometimes is make the rw fail to show what it infers since error message show it.

Rado Kirov (Oct 25 2025 at 19:50):

That's great, didn't know about it! A bit more involved than hovering over, but good enough for now.

Also the simple

import Mathlib

example (x y: Nat) : x + y = y + x := by
  rw [add_comm]

turns into

example (x y: Nat) : x + y = y + x := by
  exact Eq.mpr (id (congrArg (fun _a => _a = y + x) (add_comm x y))) (Eq.refl (y + x))

wowza :) I expected add_comm x y only

Damiano Testa (Oct 25 2025 at 20:49):

It is not just add_comm, since rw "navigates" to the locations in the expression that should be changed. This is what the congrArg does.

Damiano Testa (Oct 25 2025 at 20:50):

In particular, rw is changing just the LHS, it is not unifying the whole goal with an application of the lemma.

Eric Paul (Oct 25 2025 at 22:57):

Just for fun, this shows the instantiated version of the theorem when you hover, although you lose the old hover. I could just logInfo the instantiated version but I wouldn't want the blue squiggles under everything.

The new version is rw' with your example at the bottom:

I just changed one line but had to copy everything over

Eric Paul (Oct 29 2025 at 20:25):

Learning that one could modify hover info like this was cool so I wrote a tiny blog post about it


Last updated: Dec 20 2025 at 21:32 UTC