Zulip Chat Archive
Stream: mathlib4
Topic: Algebra.Periodic !4#1963
Yury G. Kudryashov (Feb 05 2023 at 11:52):
In !4#1963, Lean fails to find [Module α α]
in many lemmas. Why can it happen? How can I debug it?
Eric Wieser (Feb 05 2023 at 11:54):
My guess is that it's looking for @Module α α Ring.toSemiring _
but finds @Module α α CommSemiring.toSemiring _
or a more complex version thereof. What α
causes the issue?
Yury G. Kudryashov (Feb 05 2023 at 11:55):
It's a DivisionRing
Yury G. Kudryashov (Feb 05 2023 at 11:56):
The following works:
@Periodic.const_inv_smul₀ α β α f c _ _ Semiring.toModule h a
Yury G. Kudryashov (Feb 05 2023 at 11:56):
But it's a workaround
Eric Wieser (Feb 05 2023 at 11:56):
Does example [DivisionRing a] : Module a a := inferInstance
at least work?
Yury G. Kudryashov (Feb 05 2023 at 11:58):
No, it doesn't
Yury G. Kudryashov (Feb 05 2023 at 11:59):
example {α} [DivisionRing α] : Module α α := inferInstance -- fails
example {α} [DivisionRing α] : Module α α := Semiring.toModule -- works
Yury G. Kudryashov (Feb 05 2023 at 11:59):
(deleted)
Eric Wieser (Feb 05 2023 at 12:08):
Ouch
Eric Wieser (Feb 05 2023 at 12:11):
I think this confirms my "new-style structure" hunch
Eric Wieser (Feb 05 2023 at 12:11):
import Mathlib.Algebra.Module.Basic
example {α} [Ring α] : Module α α := inferInstance -- fails, needs
/-
@Module α α (@Ring.toSemiring α inst✝)
(@NonUnitalNonAssocSemiring.toAddCommMonoid α
(@NonUnitalNonAssocRing.toNonUnitalNonAssocSemiring α
(@NonAssocRing.toNonUnitalNonAssocRing α (@Ring.toNonAssocRing α inst✝))))
-/
example {α} [CommSemiring α] : Module α α := inferInstance -- works, needs
/-
@Module α α (@CommSemiring.toSemiring α inst✝)
(@NonUnitalNonAssocSemiring.toAddCommMonoid α
(@NonAssocSemiring.toNonUnitalNonAssocSemiring α
(@Semiring.toNonAssocSemiring α (@CommSemiring.toSemiring α inst✝))))
-/
#check Semiring.toModule
/-
Semiring.toModule.{u_1} {R : Type u_1} [inst✝ : Semiring R] :
@Module R R inst✝
(@NonUnitalNonAssocSemiring.toAddCommMonoid R
(@NonAssocSemiring.toNonUnitalNonAssocSemiring R (@Semiring.toNonAssocSemiring R inst✝)))
-/
Eric Wieser (Feb 05 2023 at 12:19):
The one that works is a syntactic match, the one that fails is only a match after unfolding
Kevin Buzzard (Feb 05 2023 at 13:11):
This could be related to lean4#2074
Kevin Buzzard (Feb 05 2023 at 13:12):
That also involved failure of a defeq equality which wasn't syntactic in ring theory
Eric Wieser (Feb 05 2023 at 13:35):
That looks almost certainly related
Kevin Buzzard (Feb 05 2023 at 13:55):
yeah, if you do
set_option pp.all true
set_option pp.universes false
set_option trace.Meta.synthInstance true
set_option trace.Meta.isDefEq true
then you can see the failure in the first example boils down to this failure :
[] ❌ @NonUnitalNonAssocSemiring.toAddCommMonoid α
(@NonUnitalNonAssocRing.toNonUnitalNonAssocSemiring α
(@NonAssocRing.toNonUnitalNonAssocRing α
(@Ring.toNonAssocRing α
inst✝))) =?= @NonUnitalNonAssocSemiring.toAddCommMonoid α
(@NonAssocSemiring.toNonUnitalNonAssocSemiring α
(@Semiring.toNonAssocSemiring α (@Ring.toSemiring α inst✝))) ▼
and this is true by rfl
.
Reid Barton (Feb 05 2023 at 17:11):
I added a comment on the issue.
Reid Barton (Feb 05 2023 at 17:14):
It seems like new-style structures would indeed have had the same issue in Lean 3
Yury G. Kudryashov (Feb 05 2023 at 17:15):
It seems that replacing DivisionRing
with DivisionSemiring
solves the problem.
Yury G. Kudryashov (Feb 05 2023 at 17:31):
It compiles.
Eric Wieser (Feb 05 2023 at 17:49):
While that change is reasonable in isolation, I think porting the rest of mathlib3 with workarounds for this issue in the remaining 70% of files would be a mistake. A lot of linear algebra and analysis is going to become very unpleasant, and removing the hacks later will likely be more work that just making problems like this as blocking and porting other things in the meantime
Yury G. Kudryashov (Feb 05 2023 at 18:03):
In this case, I generalized these lemmas, so while it's a workaround, it won't backfire later.
Reid Barton (Feb 05 2023 at 18:09):
You might have pushed off the problem to the users (if any) of whatever you changed, but I agree you probably didn't make anything worse.
Eric Wieser (Feb 05 2023 at 18:10):
I think writing Semiring.toModule
in a bunch of places would be a step too far
Yury G. Kudryashov (Feb 05 2023 at 18:17):
I think that generalizing these lemmas is the right thing to do anyway.
Eric Wieser (Feb 05 2023 at 19:47):
I think we should either backport that or wait till after the port though
Yury G. Kudryashov (Feb 05 2023 at 19:58):
Why? The new lemmas are backward compatible with the old ones.
Last updated: Dec 20 2023 at 11:08 UTC