Zulip Chat Archive

Stream: lean4

Topic: tactics that have no effect


Kayla Thomas (Jun 14 2023 at 03:37):

Is Lean 4 different in that, for example, if simp finds no simplifications, it still succeeds? Is the only indication of this that the goal does not change and nothing in the goal is highlighted in green? Is it possible to have the tactic in the .lean file be highlighted in some way?

Mario Carneiro (Jun 14 2023 at 03:39):

you can wrap the tactic in fail_if_no_progress

Kayla Thomas (Jun 14 2023 at 03:41):

I see.

Mario Carneiro (Jun 14 2023 at 03:42):

(that is a workaround, I think we will probably make simp do this automatically at some point)

Kayla Thomas (Jun 14 2023 at 03:43):

Can the whole tactic proof be wrapped like that, or would it need to be wrapped around each tactic?

Kayla Thomas (Jun 14 2023 at 03:44):

(I am assuming that simp is not the only tactic that does this)

Mario Carneiro (Jun 14 2023 at 03:44):

Each tactic would have to be wrapped, or you can (should) make a macro which does the wrapping

Mario Carneiro (Jun 14 2023 at 03:45):

macro "simp" : tactic => `(tactic| fail_if_no_progress simp)

(untested, might loop)

Kayla Thomas (Jun 14 2023 at 03:45):

Ok. Thank you.

Kayla Thomas (Jun 14 2023 at 04:17):

Seems to work.

Kayla Thomas (Jun 14 2023 at 04:38):

Is there a way to have it also work with simp at?

Mario Carneiro (Jun 14 2023 at 04:44):

section
open Lean Parser Tactic
syntax (name := simp') "simp" (config)? (discharger)? (&" only")?
  (" [" withoutPosition((simpStar <|> simpErase <|> simpLemma),*) "]")? (location)? : tactic

macro_rules (kind := simp')
  | stx => `(tactic| fail_if_no_progress $(⟨stx.setKind ``Tactic.simp⟩))
end

Damiano Testa (Jun 14 2023 at 04:45):

I'm not at a computer right now, but rw and simp_rw have a similar behaviour... :upside_down:

Kayla Thomas (Jun 14 2023 at 04:47):

Mario Carneiro said:

section
open Lean Parser Tactic
syntax (name := simp') "simp" (config)? (discharger)? (&" only")?
  (" [" withoutPosition((simpStar <|> simpErase <|> simpLemma),*) "]")? (location)? : tactic

macro_rules (kind := simp')
  | stx => `(tactic| fail_if_no_progress $(⟨stx.setKind ``Tactic.simp⟩))
end

Thank you!

Mario Carneiro (Jun 14 2023 at 04:51):

I would argue that not erroring is the correct behavior for rw [], and also for rw [show 1 = 1 by rfl] on f 1

Mario Carneiro (Jun 14 2023 at 04:51):

rw [show 1 = 1 by rfl] on f 2 should error (and does error)

Damiano Testa (Jun 14 2023 at 05:06):

Mario, sure. However, sometimes (not just with rw) I am confused as to whether not seeing a change in the infoview is a consequence of a tactic having done nothing or of having no pretty-printed effect. It would be nice to have a flag to avoid "useless" tactics.

Damiano Testa (Jun 14 2023 at 05:07):

Ah, i remembered that congr also does nothing silently!

Scott Morrison (Jun 14 2023 at 06:32):

On the subject, !4#4774 has been sitting on the review queue for a while: it proposes making casesm fail if it doesn't do anything.

Mac Malone (Jun 18 2023 at 03:28):

Mario Carneiro said:

macro "simp" : tactic => `(tactic| fail_if_no_progress simp)

Would simp! be a good name for this tactic?

Mac Malone (Jun 18 2023 at 03:29):

Also, in general would it be reasonable to overload the ! suffix for these kind of actions?

Scott Morrison (Jun 18 2023 at 03:33):

I'd really prefer if the default behaviour on doing nothing is failure.

It is easier to do flow control in tactics that use these tactics as building blocks, it is more informative to the user, and in particular it gives better information as the behaviour of tactics in a committed proof change due to changes in the simp set, etc.

Scott Morrison (Jun 18 2023 at 03:34):

No one likes having to inspect the goal state carefully to see if it actually changed after calling simp.

Damiano Testa (Jun 18 2023 at 05:06):

A recent example where I would have liked this, is the change to push_neg. During the port, right after calls to push_neg there were simp [not_...] calls, to remove the ¬ that were left by the earlier tactic. These simps are now silently doing nothing.

Damiano Testa (Jun 18 2023 at 05:08):

An example with simp_rw instead of simp is the change in PartitionOfUnity in !4#5132.

Damiano Testa (Jun 18 2023 at 06:28):

Also, fail_if_no_progress tests isDefEq, whereas maybe actual term equality (or something in-between) might be better.


Last updated: Dec 20 2023 at 11:08 UTC