Zulip Chat Archive

Stream: mathlib4

Topic: rfl vs by rfl in instance diamonds


Eric Wieser (Aug 05 2023 at 23:19):

In #6391 (using instances only on that branch), I found an instance diamond which fails to unify with rfl but succeeds with by rfl:

example : StarOrderedRing.toStarRing = Complex.instStarRingComplexToNonUnitalSemiringToNonUnitalCommSemiringToNonUnitalCommRingCommRing :=
  by rfl  -- ok

example : StarOrderedRing.toStarRing = Complex.instStarRingComplexToNonUnitalSemiringToNonUnitalCommSemiringToNonUnitalCommRingCommRing :=
  rfl -- fails

Eric Wieser (Aug 05 2023 at 23:23):

Perhaps even more scarily, the term generated by by rfl doesn't appear to work if you try to use it directly

Eric Wieser (Aug 05 2023 at 23:24):

Is this a transitivity failure in defeq (which we know are possible) turning up in a place that we didn't expect?

Eric Wieser (Aug 06 2023 at 08:41):

Nevermind, the problem was between the chair and keyboard. This is still weird behavior, but not really something we care about:

def foo :  := 1
lemma bar :  := 1
example : foo = bar := rfl -- fails
example : foo = bar := by rfl -- ok

Eric Rodriguez (Aug 06 2023 at 14:09):

What do you mean the term that by rfl produces? Shouldn't that be rfl??

Kevin Buzzard (Aug 06 2023 at 14:11):

Just to be clear (it was a while before I spotted it) -- bar should be a def not a lemma.

Damiano Testa (Aug 06 2023 at 14:48):

@Eric Rodriguez, I think that Eric refers to this:

def foo :  := 1
lemma bar :  := 1
--example : foo = bar := rfl -- fails

theorem RFL : foo = 1 := rfl
theorem byRFL : foo = bar := by rfl

#print byRFL -- theorem byRFL : foo = bar := Eq.refl foo
#print RFL   -- theorem RFL : foo = 1 := rfl

byRFL produces Eq.refl foo.

Damiano Testa (Aug 06 2023 at 14:50):

... and the worrying part:

example : foo = bar := Eq.refl foo
/-
type mismatch
  Eq.refl foo
has type
  foo = foo : Prop
but is expected to have type
  foo = bar : Prop
-/

Kevin Buzzard (Aug 06 2023 at 14:51):

"worrying" only if you're going to make data with lemmas and then are interested in analysing why random stuff is now broken

Damiano Testa (Aug 06 2023 at 14:59):

Yes, I agree that it is not worrying, but the error message does not make it clear where the issue is, so it might be tricky to debug.


Last updated: Dec 20 2023 at 11:08 UTC