Zulip Chat Archive
Stream: mathlib4
Topic: synthInstance after Mathlib import
Chase Norman (Jul 06 2025 at 01:04):
In the following code segment, the synthInstance call is successful:
import Mathlib.Data.ZMod.Basic
-- import Mathlib
open Lean Meta
#eval (do
let e : Expr := .app (.const `AddCommMagma [Level.zero])
(.app (.const `ZMod []) (← mkFreshExprMVar (some (.const `Nat []))))
dbg_trace (← synthInstance e)
)
However, if you uncomment import Mathlib the synthInstance call fails. Any advice?
Aaron Liu (Jul 06 2025 at 01:26):
confusion
Aaron Liu (Jul 06 2025 at 01:34):
it thinks it needs more stuff than it actually does
Aaron Liu (Jul 06 2025 at 01:34):
maybe I can figure this out after I learn how typeclass works
Eric Wieser (Jul 06 2025 at 09:22):
Maybe synthesis is willing to assign a metavariable if there is only one thing that unifies?
Aaron Liu (Jul 06 2025 at 14:30):
But I don't think that's what's happening here
Aaron Liu (Jul 06 2025 at 14:30):
assigning metavariables doesn't do anything
Robin Arnez (Jul 06 2025 at 17:23):
synthInstance fails if it thinks that it could succeed when more metavariables were assigned.
In this case, the instance docs#DirectSum.GradeZero.commRing which has type CommRing (A 0) makes it think that: if the metavariable would be assigned 0, then this instance could be used (it thinks); so it just fails and leaves it to the caller to delay the synthesization.
Robin Arnez (Jul 06 2025 at 17:25):
What you might be looking for is docs#Lean.Elab.Term.mkInstMVar; this function also takes on the responsibility of registering an instance metavariable as pending.
Chase Norman (Jul 06 2025 at 17:38):
Would that function succeed in generating an instance or fail in this case? Because my workaround was going to be replacing all metavariables with free variables, and then replacing them back with the metavariables when synthInstance is done. I want the metavariables to be treated just like meta-level variables.
Chase Norman (Jul 06 2025 at 17:39):
And this happens even if the metavariable is syntheticOpaque
Chase Norman (Jul 06 2025 at 17:58):
In short, the metavariable is _not_ pending and I do _not_ want synthInstance to consider potential assignments to it.
Bhavik Mehta (Jul 06 2025 at 20:58):
For what it's worth, you can see the same behaviour like this (which to me makes it clearer that something is weird here)
import Mathlib.Data.ZMod.Basic
-- import Mathlib
#synth AddCommMagma (ZMod _)
Last updated: Dec 20 2025 at 21:32 UTC