Zulip Chat Archive

Stream: new members

Topic: Difficulty working with coe


Eric Wieser (Jul 02 2020 at 14:04):

I have in my proof a definition instance has_coe (r : ℤ) : has_coe (A r) G := { coe := to_fun }. However, for ar : A r, when I swap out (to_fun ar : G) in my lemmas for (ar : G), I can't work out how to unfold coe in my proofs.

The full code is self-contained, and at https://github.com/pygae/lean-ga/pull/5/files#. I've added some comments on the lines where coe is causing me difficulty.

Feedback would be very appreciated, and thanks all for all the help so far.

Mario Carneiro (Jul 02 2020 at 14:09):

That coe is a bad instance

Eric Wieser (Jul 02 2020 at 14:10):

How so?

Mario Carneiro (Jul 02 2020 at 14:10):

because neither A r nor G have any interesting structure to key on

Eric Wieser (Jul 02 2020 at 14:11):

Is it generally true that type-classes should never provide coe?

Mario Carneiro (Jul 02 2020 at 14:12):

When lean goes looking for a coe the right argument is unbound, so it's trying to see what A r can coerce to

Mario Carneiro (Jul 02 2020 at 14:13):

It can depend on typeclasses on A r but not on A and certainly not on G

Mario Carneiro (Jul 02 2020 at 14:14):

However, you can use a notation to avoid mentioning A r and G in the section

Eric Wieser (Jul 02 2020 at 14:21):

Presumably it does find my coe though, since the lemma statements are valid if I make the change - it's just my proofs which suffer

Eric Wieser (Jul 02 2020 at 15:39):

Local notation did the trick, thanks! (done in https://github.com/pygae/lean-ga/commit/9643c01d7f7a69da952ffeaccad6b6dca55b4cd6)

To make coe simplify, I had to add lemma coe_def {r : ℤ} (v : A r) : (v : G) = to_fun v := rfl

Eric Wieser (Jul 02 2020 at 15:39):

Is there any way to take existing notation and bind the inferred arguments without repeating the symbols and precedence?


Last updated: Dec 20 2023 at 11:08 UTC