Zulip Chat Archive

Stream: mathlib4

Topic: Bug in `ring1`?


Heather Macbeth (Mar 06 2023 at 00:31):

By the way, what is going on here? ring failed: not an equality

import Mathlib.Tactic.Ring

def f : Nat  Nat := sorry

example (a : Nat) : 1 * f a * 1 = f (a + 0) := by
  have ha : a + 0 = a := by ring
  rw [ha] -- goal is `1 * f a * 1 = f a`
  ring1 -- ring failed: not an equality

Notification Bot (Mar 06 2023 at 00:39):

A message was moved here from #mathlib4 > Bug in ring_nf? by Heather Macbeth.

Heather Macbeth (Mar 06 2023 at 00:47):

Adding a line

change _ = _

fixes it, so it seeems that the problem genuinely is the tactic's failure to identify the equality structure of the goal.

Thomas Murrills (Mar 06 2023 at 00:57):

Hmm, seems like ring relies on .eq? immediately after getting the type of the goal, which ultimately relies on boolean equality of names (i.e. there's no isDefEq check or whnf or the like)

Thomas Murrills (Mar 06 2023 at 01:00):

But that's weird. The goal does seem to be an Eq application.

Thomas Murrills (Mar 06 2023 at 01:09):

Ah! It's the mdata.

Thomas Murrills (Mar 06 2023 at 01:10):

Specifically, .mdata noImplicitLambda:1, as it shows up in pp.raw

Thomas Murrills (Mar 06 2023 at 01:14):

Replacing lines 1068-1069 in Ring.Basic with

  let some (α, e₁, e₂) := Expr.consumeMData ( instantiateMVars ( g.getType)) |>.eq?
    | throwError "ring failed: not an equality"

fixes it

Thomas Murrills (Mar 06 2023 at 01:16):

(But I’m not sure if we’d prefer just a whnf or something? (as well? Does whnf strip mdata?) Called away right now, so can’t explore further!)

Mario Carneiro (Mar 06 2023 at 01:22):

with whnfR instead of consumeMData that's exactly the same bugfix as I have applied to a small handful of other tactics

Mario Carneiro (Mar 06 2023 at 01:22):

it's a very common pitfall

Thomas Murrills (Mar 06 2023 at 02:23):

PR'd (whnfR version): !4#2677

Heather Macbeth (Mar 06 2023 at 05:16):

Mario Carneiro said:

with whnfR instead of consumeMData that's exactly the same bugfix as I have applied to a small handful of other tactics

One such bugfix by Mario from Feb 8 is still awaiting review, if any tactic experts get time: !4#2173

Mario Carneiro (Mar 06 2023 at 05:20):

Since as they say you won't recognize your code after coming back to it for a while, I've given it a proper independent review :) and hit the merge button


Last updated: Dec 20 2023 at 11:08 UTC