Zulip Chat Archive

Stream: mathlib4

Topic: solve_aux


Scott Morrison (Oct 05 2022 at 23:50):

Do we already have a lean4 version of

/-- `solve_aux type tac` synthesize an element of 'type' using tactic 'tac' -/
meta def solve_aux {α : Type} (type : expr) (tac : tactic α) : tactic (α × expr) :=

somewhere? I remember this is something that had duplicates at various times in mathlib3, so I don't want to write yet another one in mathlib4. :-)

Mario Carneiro (Oct 05 2022 at 23:56):

I would guess no. But you can write one and put it in a well named location so no one else has to :)

Mario Carneiro (Oct 05 2022 at 23:57):

it's a bit awkward since while the input is a TacticM the output might be MetaM or TermElabM

Scott Morrison (Oct 06 2022 at 03:38):

Perhaps just

import Lean

open Lean Elab Tactic Meta

def solve_aux (type : Expr) (tac : TacticM Unit) : TermElabM Expr := do
  let m  mkFreshExprMVar type
  let _  run m.mvarId! tac
  return m

would do.

This differs slightly from the mathlib3 version, which captures the value produced by tac as well. Looking at how it is used, in 95% of cases this is just getting in the way. Options:

  1. reproduce the mathlib3 behaviour, which is simple enough by providing a variant of run.
  2. keep it simple, possibly backporting this change mathlib3 to avoid confusion.

While we're at it, can we have a better name than solve_aux? (I'd leave a comment so people can still find it.) Perhaps something like synthesizeUsing?

Mario Carneiro (Oct 06 2022 at 03:41):

I was never really a fan of the alphas, that was a late addition

Mario Carneiro (Oct 06 2022 at 03:41):

especially repeat returning a list of results seems like a bad idea

Mario Carneiro (Oct 06 2022 at 03:42):

you should return m.instantiateMVars though

Mario Carneiro (Oct 06 2022 at 03:43):

or at least m.getAssignment

Scott Morrison (Oct 06 2022 at 04:32):

mathlib4#452


Last updated: Dec 20 2023 at 11:08 UTC