Zulip Chat Archive

Stream: new members

Topic: Type error tensor product


María Inés de Frutos Fernández (Dec 09 2021 at 18:20):

I don't understand what's going on in the following code:

import data.real.basic
import ring_theory.tensor_product

noncomputable theory
open_locale tensor_product

variables (K : Type) [ring K] [algebra  K]

instance : ring (K [] ) := algebra.tensor_product.tensor_product.ring --or infer_instance
instance : ring ( [] ) := algebra.tensor_product.tensor_product.ring --fails

The first instance works fine, but the second one gives me the error

  algebra.tensor_product.tensor_product.ring
has type
  ring (?m_3 ⊗ ?m_4) : Type (max ? ?)
but is expected to have type
  ring (ℚ ⊗ ℝ) : Type

However both (K ⊗[ℚ] ℝ) and (ℚ ⊗[ℚ] ℝ) have type Type. So why does the second one fail? I guess it has something to do with playing two different roles, but I don't see why that causes a problem.

Adam Topaz (Dec 09 2021 at 18:31):

Is lean able to infer a Q algebra structure on Q? (I hope it can...)

Reid Barton (Dec 09 2021 at 18:34):

If I write

instance : ring ( [] ) := begin
  convert @algebra.tensor_product.tensor_product.ring  _  _ _  _ _,
end

then I am left with

 semiring.to_module = algebra.to_module

María Inés de Frutos Fernández (Dec 09 2021 at 18:35):

Adam Topaz said:

Is lean able to infer a Q algebra structure on Q? (I hope it can...)

Yes, it can.

Reid Barton (Dec 09 2021 at 18:40):

so it seems like there is some disagreement about the module ℚ ℚ structure, however, from looking at the definitions I don't understand why: looks like both should be given by x \bub y = x * y

Eric Rodriguez (Dec 09 2021 at 18:41):

ext, congr gets the goal r = ⇑(rat.cast_hom ℚ) r, which doesn't seem to be true by refl :(

Adam Topaz (Dec 09 2021 at 18:43):

Ah I bet the algebra structure is obtained from some general instance for characteristic zero fields, and the module structure comes from the obvious module structure of a ring on itself

Reid Barton (Dec 09 2021 at 18:44):

oh yes you're right, local attribute [instance, priority 10000] algebra.id fixes it

Reid Barton (Dec 09 2021 at 18:45):

and otherwise it's finding docs#rat.algebra_rat

Reid Barton (Dec 09 2021 at 18:45):

Shouldn't that instance have some lower priority?

María Inés de Frutos Fernández (Dec 09 2021 at 18:45):

Thanks a lot!

Reid Barton (Dec 09 2021 at 18:52):

FWIW, these has type ?m, expected X errors usually mean that Lean already tried the obvious ?m = X but it failed for some reason generally having to do with type classes

Adam Topaz (Dec 09 2021 at 19:22):

Reid Barton said:

FWIW, these has type ?m, expected X errors usually mean that Lean already tried the obvious ?m = X but it failed for some reason generally having to do with type classes

The same error can sometimes pop up because of universe issues, but you can diagnose those by using set_option pp.universes true.

Eric Wieser (Dec 09 2021 at 19:24):

Reid Barton said:

Shouldn't that instance have some lower priority?

That doesn't really make the problem go away, it just makes it appear less often

Eric Wieser (Dec 09 2021 at 19:25):

There has been discussion in the past about how to fix the qsmul diamond in the same way we fixed nsmul and zsmul, but it never got implemented

Reid Barton (Dec 09 2021 at 19:26):

Problems appearing less often is good though, right? Like, we already have a linter for catch-all instances don't we?

Reid Barton (Dec 09 2021 at 19:29):

I assume it doesn't fire on this instance because it has multiple parameters and one of them is not a variable?

Eric Wieser (Dec 09 2021 at 19:49):

That linter is there to catch performance issues, not surprising instances

Eric Wieser (Dec 09 2021 at 19:51):

You still run into the same typeclass diamond if you have a lemma about a general [division_ring R] [char_zero R] that uses the "obvious" ℚ-action, then specialize it to R=ℚ.

Eric Wieser (Dec 09 2021 at 19:53):

The two solutions are either:

  • Add [module ℚ R] to all such lemmas (like we do with decidable) so that we never state anything about a specific instance.
  • Make the diamond defeq by adding data to division_ring (like we do with add_monoid.nsmul)

Reid Barton (Dec 09 2021 at 20:33):

  • Delete the instance

Reid Barton (Dec 09 2021 at 20:34):

Eric Wieser said:

That linter is there to catch performance issues, not surprising instances

Hmm, that itself comes as a surprise to me.

Eric Wieser (Dec 09 2021 at 20:38):

Yes, deleting or hiding in a locale would be part of the first bullet most likely

Eric Wieser (Dec 09 2021 at 20:40):

The priority linter is there to force a breadth-first search, and stop lean trying to solve semiring R by looking for field R before having exhausted all the direct instances


Last updated: Dec 20 2023 at 11:08 UTC