Zulip Chat Archive

Stream: general

Topic: class instance unification fails


Yury G. Kudryashov (Apr 24 2020 at 07:19):

I tried to use the @... (multiplicative G) ... trick in data/monoid_algebra to get defs/proofs for add_monoid_algebra. Now polynomial.algebra fails, see https://github.com/leanprover-community/mathlib/pull/2492/checks?check_run_id=614475313

Yury G. Kudryashov (Apr 24 2020 at 07:25):

Here is the error message with set_option pp.all true:

/home/urkud/projects/mathlib/polynomial/src/data/polynomial.lean:31:39: error: type mismatch, term
  @add_monoid_algebra.algebra.{?l_1 ?l_2} ?m_3 ?m_4 ?m_5 ?m_6
has type
  @algebra.{?l_1 (max ?l_2 ?l_1)} ?m_3
    (@add_monoid_algebra.{?l_1 ?l_2} ?m_3 ?m_4 (@comm_semiring.to_semiring.{?l_1} ?m_3 ?m_5))
    ?m_5
    (@add_monoid_algebra.semiring.{?l_1 ?l_2} ?m_3 ?m_4 (@comm_semiring.to_semiring.{?l_1} ?m_3 ?m_5) ?m_6) : Type (max
        ?l_2
        ?l_1)
but is expected to have type
  @algebra.{u u} R (@polynomial.{u} R _inst_1) _inst_1
    (@comm_semiring.to_semiring.{u} (@polynomial.{u} R _inst_1) (@polynomial.comm_semiring.{u} R _inst_1)) : Type u

Yury G. Kudryashov (Apr 24 2020 at 07:26):

How can I debug failures like this one?

Scott Morrison (Apr 24 2020 at 08:56):

I think

instance : algebra R (polynomial R) :=
begin
   convert @add_monoid_algebra.algebra R  _ _,
end

helps.

Scott Morrison (Apr 24 2020 at 08:57):

That then fails with:

Scott Morrison (Apr 24 2020 at 08:57):

1 goal
R : Type u,
_inst_1 : comm_semiring.{u} R
 @eq.{u+1} (semiring.{u} (@polynomial.{u} R _inst_1))
    (@comm_semiring.to_semiring.{u} (@polynomial.{u} R _inst_1) (@polynomial.comm_semiring.{u} R _inst_1))
    (@add_monoid_algebra.semiring.{u 0} R nat (@comm_semiring.to_semiring.{u} R _inst_1) nat.add_monoid)

Scott Morrison (Apr 24 2020 at 08:59):

So we're ending up in semiring two different ways.

Chris Hughes (Apr 24 2020 at 09:04):

And they're not defeq?

Yury G. Kudryashov (Apr 24 2020 at 09:31):

Definition of comm_semiring is here: https://github.com/leanprover-community/mathlib/blob/polynomial-review/src/data/monoid_algebra.lean#L469

Yury G. Kudryashov (Apr 24 2020 at 09:32):

instance [comm_semiring k] [add_comm_monoid G] : comm_semiring (add_monoid_algebra k G) :=
{ .. add_monoid_algebra.semiring, .. @monoid_algebra.comm_semiring k (multiplicative G) _ _ }

I wonder why they're not defeq.

Yury G. Kudryashov (Apr 24 2020 at 09:41):

This works:

attribute [ext] semiring
instance : algebra R (polynomial R) :=
begin
   convert @add_monoid_algebra.algebra R  _ _,
   ext1; refl
end

Yury G. Kudryashov (Apr 24 2020 at 12:43):

If I prove all zero_mul etc as lemmas using the @ ... multiplicative trick, then feed them to instance : semiring (add_monoid_algebra k G), then polynomial.algebra works without any tricks. If I replace, e.g., one_mul := one_mul with one_mul := @one_mul (monoid_algebra k (multiplicative G)) _, then it doesn't work.

Scott Morrison (Apr 24 2020 at 20:36):

Adding instance : semiring (polynomial R) := add_monoid_algebra.semiring before instance comm_semiring ... solves the problem.

Yury G. Kudryashov (Apr 24 2020 at 23:12):

I'll try once lean will recompile mathlib (added a simp lemma to algebra/group/hom).


Last updated: Dec 20 2023 at 11:08 UTC