Zulip Chat Archive

Stream: mathlib4

Topic: Potential Bug in symm tactic


zbatt (Jan 19 2023 at 14:58):

On line 166 of FinEnum.lean it used to say symm which I replaced with apply Eq.symm. I realized this morning that seemed off so I went and double checked. If you replace apply Eq.symm with symm you get an error

symmetry lemmas only apply to binary relations, not
  s = s \ {xs_hd}

Is this a bug?

Kevin Buzzard (Jan 19 2023 at 15:08):

Mathlib.Init.Core has attribute [symm] Eq.symm so this is indeed unexpected (to me, at least) behaviour.

Siddhartha Gadgil (Jan 19 2023 at 15:24):

I am investigating this.

zbatt (Jan 19 2023 at 15:25):

This is strange, logging the representation with logInfo (repr tgt) in Symm.lean tells us that the goal is Lean.Expr.mvar (Lean.Name.mkNum _uniq 45724), but if you first do suffices s = s\ {xs_hd} from this then the symm works fine

Kyle Miller (Jan 19 2023 at 15:27):

I'm not sure if this is relevant, but this reminded me that in the Lean 3 implementation there's a step where it instantiates the mvars of the target before proceeding.

Kevin Buzzard (Jan 19 2023 at 15:29):

I'm finding this really hard to minimise.

zbatt (Jan 19 2023 at 15:29):

@Kyle Miller
I just tried that locally and it didn't immediately work. That being said this is my first time doing anythin with tactic debugging so someone else should double check

Update: I'm realizing I put it in the wrong place, so I'm checking again now. Hopefully it'll fix this time.

Siddhartha Gadgil (Jan 19 2023 at 15:29):

@Kyle Miller I am testing if that is the solution here.

Siddhartha Gadgil (Jan 19 2023 at 15:31):

Last time I was debugging symm and trans I just made the errors much more verbose temporarily. I will try that again if the above does not work (the build is slow now so each step takes a while).

zbatt (Jan 19 2023 at 15:34):

yep it worked!

Siddhartha Gadgil (Jan 19 2023 at 15:34):

What is "it"?

zbatt (Jan 19 2023 at 15:35):

Specifcally, replace line 102 with g.symmAux (← instantiateMVars (← g.getType)) fun lem args body g => do

/-- Apply a symmetry lemma (i.e. marked with `@[symm]`) to a metavariable. -/
def symm (g : MVarId) : MetaM MVarId := do
  g.symmAux ( instantiateMVars ( g.getType)) fun lem args body g => do
    let .true  isDefEq ( g.getType) body | failure
    g.assign (mkAppN lem args)
    return args.back.mvarId!

zbatt (Jan 19 2023 at 15:37):

I don't know enough about tactics to know if this is correct to do, but I thought I should point out that the same lack of instantiateMVars appears on line 75. Should this be changed too?

Siddhartha Gadgil (Jan 19 2023 at 15:37):

I am trying a line inserted after line 37:

let targetTy  instantiateMVars targetTy

It is still building. Let me see if it works.

Siddhartha Gadgil (Jan 19 2023 at 15:40):

Actually my change probably fixes nothing as it is when the attribute is being added. I believe @zbatt is right on both counts: the correct fix here and the same should be done on line 75.

zbatt (Jan 19 2023 at 15:44):

should I PR these changes?

Siddhartha Gadgil (Jan 19 2023 at 15:44):

@zbatt maybe it is best if you make both changes, build everything and make a PR. Is that fine?

Siddhartha Gadgil (Jan 19 2023 at 15:44):

Our lines crossed.

zbatt (Jan 19 2023 at 15:44):

will do! (just give me a minute to submit some homework :p)

zbatt (Jan 19 2023 at 15:54):

PR'd

Siddhartha Gadgil (Jan 19 2023 at 15:59):

Just an alert - a lot of the code of ext is also common with symm and trans (my initial implementation of symm and transwas heavily modelled on ext). It may be worth checking if the same issue is there too.

Parth Shastri (Jan 19 2023 at 16:02):

ext it seems uses getType', which includes instantiateMVars.

zbatt (Jan 19 2023 at 19:58):

Also trans apppears to use getMainTarget so I don't think it should have the same issue.


Last updated: Dec 20 2023 at 11:08 UTC