Zulip Chat Archive

Stream: general

Topic: has_coe_to_fun instance of mv_polynomial


AHan (Feb 17 2019 at 09:34):

Although finsupp has the instance has_coe_to_fun, I don't understand why lean cannot infer that mv_polynomial also has the instance.

For example, in the following code, Unlike lemma three, there is a type error in lemma one, which says that "expected a function at p...", and I have to write it as lemma two instead.

How can I fix this?

import linear_algebra.multivariate_polynomial

section
variables {α : Type*} {σ : Type*} [comm_semiring α]

lemma one {p : mv_polynomial σ α} :  {a : σ  }, p a = p a := sorry
lemma two {p : mv_polynomial σ α} :  {a : σ  }, p.to_fun a = p.to_fun a := sorry

end

section
variables {α : Type*} {β : Type*} [has_zero β]

lemma three {f : α  β} :  {x}, f x = f x := sorry

end

Kenny Lau (Feb 17 2019 at 09:34):

because mv_polynomial isn't @[reducible]

Kenny Lau (Feb 17 2019 at 09:35):

so the instances don't transfer

Mario Carneiro (Feb 17 2019 at 09:35):

by which kenny means not that you should add @[reducible], but you should copy the instances

AHan (Feb 17 2019 at 09:39):

Ahh... I added @[reducibility] instead...
@Mario Carneiro Adding the attribute @[reducible] did work, but why should I copy the instances instead of adding the attribute?

Mario Carneiro (Feb 17 2019 at 09:56):

because one of the purposes of type synonyms is to isolate different kinds of typeclasses on the same type. In fact this is one such example: the coe_fn instance on finsupp makes sense as applying the finitely supported function on an argument, but the coe_fn instance we would expect of mv_polynomial is treating the polynomial as a function on the base ring, i.e. eval. The actual coe_fn instance inherited from finsupp is the coeff function

AHan (Feb 17 2019 at 10:11):

Then if I don't add the attribute @[reducible ], some lemmas like finsupp.support_zero won't be simplified under the type of mv_polynomial
I have to copy the lemma and prove it again instead. How can I fix this kind of problem?

Mario Carneiro (Feb 17 2019 at 10:12):

that's a feature not a bug

Mario Carneiro (Feb 17 2019 at 10:13):

you don't need to reprove it, but you do need to restate it

Mario Carneiro (Feb 17 2019 at 10:13):

and this makes you think about how your new interpretation of the type affects the meaning of the theorems

Mario Carneiro (Feb 17 2019 at 10:13):

some of them are no longer applicable, some new theorems may appear

AHan (Feb 17 2019 at 10:14):

Sorry, I don't mean it's a bug, I'm just thinking of if there's anyway to avoid to restate those lemmas.

AHan (Feb 17 2019 at 10:15):

OK, I understand! Thanks a lot for explanations!

Mario Carneiro (Feb 17 2019 at 10:15):

You can also try using the original theorems in the new context but YMMV


Last updated: Dec 20 2023 at 11:08 UTC