Zulip Chat Archive

Stream: Is there code for X?

Topic: Merging duplicate goals


David Loeffler (Nov 28 2024 at 06:52):

Is there a goal-management tactic that can be used to recognise that two (or more) of the goals in the current goal list are identical, and merge them together, so you don't have to give two copies of the same sub-proof?

(I know about "all_goals", "any_goal" etc, which would allow you to only write the goal once; but it would still be getting processed multiple times. I want something which would halve the tactic compilation time, as well as the writing time.)

Edward van de Meent (Nov 28 2024 at 07:36):

I remember this being asked before, and then the answer was no, iirc

Damiano Testa (Nov 28 2024 at 07:42):

Are your goals "identical"? I.e. same local variables and same types?

Damiano Testa (Nov 28 2024 at 07:43):

(Internally, they will not be identical since, for instance, each metavariable has a new name, but I am wondering if they are identical for a human, at least.)

David Loeffler (Nov 28 2024 at 07:54):

The goals are literally identical up to naming of bound variables. (But they are quite lengthy to type, so I want to avoid have-ing them beforehand.)

Damiano Testa (Nov 28 2024 at 07:57):

Ok, I wonder if a tactic could create a new metavariable that is defeq to the current goal, use that to close all goals that it can and leave just the "new" metavariable as a remaining goal (plus whatever goals it was not able to solve automatically).

Damiano Testa (Nov 28 2024 at 07:58):

(I won't have time to actually think about this for a while, but it seems like a good metaprogramming task.)

David Loeffler (Nov 28 2024 at 07:59):

In lean 3 there was a hack resembling have foo := ?_; rotate that could push a goal whose type was an unconstrained meta variable, which you could use to close multiple proof branches; but that is not legal lean 4 syntax.

David Loeffler (Nov 28 2024 at 08:02):

Damiano Testa said:

Ok, I wonder if a tactic could create a new metavariable that is defeq to the current goal, use that to close all goals that it can and leave just the "new" metavariable as a remaining goal (plus whatever goals it was not able to solve automatically).

Possibly easier would be to take a list of goals as an argument - merge_goals 3 5 or something – rather than automating the search. I’m concerned about it taking a long time to fail on some goals that aren’t defeq.

Junyan Xu (Nov 28 2024 at 11:33):

Still possible in Lean 4, just make the type a metavariable too:

example : True := by
  have : ?_ := ?_
  · exact this
  · trivial

Last updated: May 02 2025 at 03:31 UTC