Zulip Chat Archive

Stream: mathlib4

Topic: Using finishing tactics inside aesop


Bhavik Mehta (Oct 12 2023 at 23:23):

Here's my example:

import Aesop
import Mathlib.Tactic.Linarith

example {a b : Nat} : a < b  a  b := by
  intro h
  aesop (add unsafe 1% linarith)

I expected this to succeed, since linarith closes the goal, and I was hoping that this could be a nice pattern to use in general (use aesop to make some logical steps, then linarith to close what's left). Why does this fail? And more generally, how could I have figured out myself why this fails?

Alex J. Best (Oct 12 2023 at 23:36):

seems you can do

import Aesop
import Mathlib.Tactic.Linarith

open Lean Elab Tactic
def myLin : TacticM Unit := do
  evalTactic $  `(tactic| linarith)
set_option trace.aesop true
example {a b : Nat} : a < b  a  b := by
  intro h
  aesop (add tactic unsafe myLin)

I guess https://github.com/JLimperg/aesop/issues/45 is what you are hoping for

Bhavik Mehta (Oct 12 2023 at 23:50):

That makes sense, thanks!

Bhavik Mehta (Oct 12 2023 at 23:51):

I can answer my two questions from earlier - it fails because I used the syntax wrongly, and I could have figured this out using the trace.aesop option.

Bhavik Mehta (Oct 12 2023 at 23:51):

But what did my (add unsafe 1% linarith) actually do, and should it have given an error?

Bhavik Mehta (Oct 12 2023 at 23:53):

And I agree that having some nicer syntax for this would be nice, but the linked issue does describe why a general solution is more tricky than it appears

Shreyas Srinivas (Oct 13 2023 at 00:03):

So when I use linarith as you have done (minus the 1%) directly instead of myLin in Alex's solution, the following error is thrown:

aesop: linarith was expected to be a tactic, i.e. to have one of these types:
  TacticM Unit
  SimpleRuleTac
  RuleTac
However, it has type
  Lean.ParserDescr

Shreyas Srinivas (Oct 13 2023 at 00:07):

Bhavik Mehta said:

But what did my (add unsafe 1% linarith) actually do, and should it have given an error?

I am responding to this message.

Alex J. Best (Oct 13 2023 at 00:11):

Bhavik Mehta said:

But what did my (add unsafe 1% linarith) actually do, and should it have given an error?

I think it tells aesop to use the statement named linarith (which does exist) as a rule, which is almost certainly junk, but not clearly wrong for type reasons

Jannis Limperg (Oct 13 2023 at 12:37):

What Alex says. Extending the rule grammar so that you can give tactics directly (as well as (add norm simp [<- foo, bar]) and (add safe apply foo x y z)) is fairly high up on the todo list, but I need to figure out how to integrate this nicely with the rest of the grammar.

Timo Carlin-Burns (Oct 13 2023 at 15:42):

Is unsafe 1% a reasonable configuration for an expensive finishing tactic like linarith? There is a sense in which it is vacuously safe because it never produces subgoals at all so can never produce unprovable ones..

Timo Carlin-Burns (Oct 13 2023 at 15:43):

I suppose part of the problem with marking it safe would be that it gets tried on every single goal, even the ones that aren't inequalities

Jannis Limperg (Oct 16 2023 at 11:02):

I have no strong intuition about this, so we'd have to try it. Perhaps a separate arith rule set where linarith is safe could make sense, so you'd be able to use it only when the goal actually needs arithmetic. (I have some ideas for a tighter, more performant integration of linarith and aesop, but it's entirely vapourware so far.)


Last updated: Dec 20 2023 at 11:08 UTC