Zulip Chat Archive

Stream: lean4

Topic: Unification failure in simp


Tomas Skrivan (Aug 21 2024 at 02:31):

I'm having a trouble figuring out why one simp theorem is not being applied. There is unification failure and I'm having hard time reading the trace.

The main unification that fails is:

      [Meta.isDefEq]  fun (i : Fin 10 × Unit) =>
            (?inst : (i : (?I : Type))  NormedAddCommGroup ((?EI : (?I : Type)  Type) i))
              i.2 =?= fun (i : Fin 10 × Unit) => NonUnitalNormedRing.toNormedAddCommGroup

Here is the part of the trace corresponding to this failure

trace

Here is a minimized version of the unification itself

import Mathlib

open Lean Meta Qq in
#eval show MetaM Unit from do

  let I?  mkFreshExprMVarQ q(Type)
  let EI?  mkFreshExprMVarQ q($I?  Type)
  let inst?  mkFreshExprMVarQ q((i : $I?)  NormedAddCommGroup.{0} ($EI? i))
  let lhs :=
    Expr.lam `i q(Fin 10 × Unit) (inst?.app (Expr.app q(Prod.snd : Fin 10 × Unit  Unit) (.bvar 0))) default


  withLocalDeclQ `R default q(Type) fun R => do
  withLocalDeclQ `R .instImplicit q(RCLike $R) fun instR => do
  let rhsBody := q(inferInstance : NormedAddCommGroup $R)
  let rhs := q(fun (i : Fin 10 × Unit) => $rhsBody)

  -- I?.mvarId!.assignIfDefeq q(Unit)
  -- EI?.mvarId!.assignIfDefeq q(fun _ : Unit => $R)
  -- inst?.mvarId!.assignIfDefeq q(fun _ : Unit => $rhsBody)

  if  isDefEq lhs rhs then
    IO.println "unification succeeded"
  else
    throwError "unification failed"

If you uncomment all the assignIfDefeq i.e. assign the metavariables manually then the final defeq test succeeds.

I would like this unification to succeed. How can I achieve that? Can I write an unification hint?

Ideally I would not run into this problem at all, but I'm unable to minimize the simp call :( I'm thinking that reordering the simp theorem arguments might cause different unification order. Any other tip would be welcome.


Last updated: May 02 2025 at 03:31 UTC