Zulip Chat Archive
Stream: mathlib4
Topic: A tensor B is an A-algebra and a B-algebra
Kevin Buzzard (May 13 2025 at 18:23):
OK so Lean has this thing where for and commutative -algebras, we have is an -algebra as an instance, but we're not allowed to have being a -algebra because of the stupid objection "if then there will be a diamond" which is (a) true and also (b) kind of dumb because 99% of the time is manifestly not equal to and rfl fails quickly.
But things are what they are, and the right algebra structure ( being a -algebra) exists as a def but not as an instance. Except that sometimes you really do want it to exist. For example if is a -algebra then you might want to make into an -algebra (it doesn't matter if you don't know what the adeles of is, all you need to know is that it's a commutative -algebra and its construction is functorial in ), and then if it turns out that you're trying to prove that (which we are) then you might want them to be isomorphic as -algebras or as -algebras because these statements have different content and are both useful. For me this example is a concrete proof that @Eric Wieser 's suggestion "just try to write your tensor products the right way around to ensure that you only need the left algebra instance" is not viable in practice, at least in the kind of mathematics we're doing over in FLT.
So what I find I'm doing in FLT is that I've basically fixed an order for things ("adeles on the right", as is traditional in the literature) and when I want to be an -algebra I just make docs#Algebra.TensorProduct.rightAlgebra a local instance, or I make into a -algebra explicitly using this definition. I've been working fine with this until recently.
Recently I've realised that actually we want things like "if is a finite -algebra then is a finite -algebra". For left algebra instances this is all in typeclass inference. For the right algebra theorem they're not instances because they can't be -- typeclass inference can't find the right algebra structure. So I'm having to not just remember Algebra.TensorProduct.rightAlgebra, I'm having to start remembering a list of declarations e.g. the FLT-specific Module.Finite.base_change_right which I need to make commutative algebra work painlessly.
Is there a way I can package everything up? So I can just type one line and all of a sudden is a -algebra, the system knows that if is finite as an -module then is finite as a -module, and maybe the system also even forgets that is an -algebra? Can I do this with a...erm...scope, for example? Or is this likely to explode in my face? Is switching off instances in the middle of a file a safe thing to do?
Yaël Dillies (May 13 2025 at 18:30):
Kevin Buzzard said:
For the right algebra theorem they're not instances because they can't be -- typeclass inference can't find the right algebra structure. So I'm having to not just remember
Algebra.TensorProduct.rightAlgebra, I'm having to start remembering a list of declarations e.g. the FLT-specificModule.Finite.base_change_rightwhich I need to make commutative algebra work painlessly.
They can, actually. Instances of Prop-valued mixins over referring to non-instances are not a problem
Eric Wieser (May 13 2025 at 18:32):
That was true in Lean 3, but it's no longer entirely clear to me if it's true in Lean 4. I think I remember this coming up in one of @Anne Baanen's PRs
Andrew Yang (May 13 2025 at 18:33):
The only concern is performace I think. And the only place we have in mathlib where this might be a problem is near the treacherous jacobi zariski.
Eric Wieser (May 13 2025 at 18:34):
Kevin Buzzard said:
if it turns out that you're trying to prove that (which we are) then you might want them to be isomorphic as -algebras or as -algebras because these statements have different content and are both useful. For me this example is a concrete proof that Eric Wieser 's suggestion "just try to write your tensor products the right way around to ensure that you only need the left algebra instance" is not viable in practice, at least in the kind of mathematics we're doing over in FLT.
I guess the extension of my suggestion is "passing through TensorProduct.comm repeatedly is better than fighting typeclass search", though that conjecture is unproven
Eric Wieser (May 13 2025 at 18:37):
Perhaps worth splitting this thread? (edit: done)
Junyan Xu (May 13 2025 at 19:23):
We could make rightAlgebra a scoped instance and put all instances referring to it within the same scope. I've adopted this approach here and here.
Notification Bot (May 13 2025 at 22:35):
13 messages were moved from this topic to #mathlib4 > Prop-valued instances in terms of non-canonical instances by Eric Wieser.
Last updated: Dec 20 2025 at 21:32 UTC