Zulip Chat Archive
Stream: lean4
Topic: revert and variable
Sven Manthe (Jun 18 2024 at 18:31):
@Floris van Doorn and me found a situation, where the tactic revert fails expectedly, but creates a not so nice error message. This also affects the extract_goal tactic of Mathlib, which just passes this message on.
--import Mathlib.Tactic.ExtractGoal
variable {P : Prop}
example
--{P : Prop} --uncommenting this line fixes the issue
(S : P → Prop) :
∃ (hx : P), S hx := by
apply Exists.intro
· --revert P
--extract_goal
sorry
· sorry
Sven Manthe (Jun 18 2024 at 18:34):
PS: I just realized that uncommenting the parameter line actually makes revert P succeed.
Joachim Breitner (Jun 18 2024 at 18:38):
For the benefit from away from the computer, whats the error message?
Floris van Doorn (Jun 18 2024 at 18:56):
tactic 'clear' failed, target depends on '_example'
Floris van Doorn (Jun 18 2024 at 18:58):
The issue has to do with the fact that the goal contains a metavariable, and this metavariable depends on an auxiliary local constant(?). It is interesting that the behavior changes depending on whether P
is an argument or a variable.
Joachim Breitner (Jun 18 2024 at 19:25):
I wonder if this _example
is the name for the current function in case you want to make it recursive. Can you produce this issue with def
as well?
Floris van Doorn (Jun 18 2024 at 19:28):
Yes, with theorem
it will give the same error message with the theorem name. It gives the same error message The same error message occurs when writing clear <thmname>
variable {P : Type}
theorem foo
-- {P : Type} --uncommenting this line fixes the issue
(S : P → Prop) :
∃ (hx : P), S hx := by
apply Exists.intro
revert P -- tactic 'clear' failed, target depends on 'foo'
-- clear foo -- gives same error message, but also fails with P as argument
Sven Manthe (Jun 18 2024 at 19:28):
Yes, it is the name of the current function (we used a def originally)
Joachim Breitner (Jun 18 2024 at 21:09):
I see. probably worth recording in an issue.
Damiano Testa (Jun 18 2024 at 21:27):
Just out of curiosity, what happens if you add nonrec
to the declaration? (I have a vague memory that _example
is what nonrec uses.)
Floris van Doorn (Jun 18 2024 at 21:31):
Then the revert succeeds and extract_goal
fails with the expected "extracted goal has metavariables" error.
Good point, I forgot about that modifier. That can at least be a workaround.
Damiano Testa (Jun 18 2024 at 21:36):
Actually, it seems more successful than what I hoped for!
Kyle Miller (Jun 19 2024 at 17:37):
Weird, I was tried to minimize, and for some unknown reason revert
is removing the second goal:
theorem foo (p : Prop) (h : p) : ∃ (n : Nat), p := by
apply Exists.intro
revert p
sorry
-- (kernel) declaration has metavariables 'foo'
(4.10.0, commit 0a1a855ba80e51515570439f3d73d3d9414ac053)
Sven Manthe (Jul 31 2024 at 17:57):
https://github.com/leanprover/lean4/issues/4886
Joachim Breitner (Aug 12 2024 at 16:06):
I added a bit more analysis to the issue
Last updated: May 02 2025 at 03:31 UTC