mathlib icon indicating copy to clipboard operation
mathlib copied to clipboard

Replace manually defined extensionality lemmas by `@[ext]`

Open robertylewis opened this issue 6 years ago • 8 comments

#1645 allows @[ext] to be applied to a structure to automatically derive the extensionality lemma. We should replace manually defined ext lemmas with the attribute. (The attribute should already be present on most of the lemmas themselves, so they'll be easy to find.)

I'm not sure how consistent we are overall with naming these sorts of things. ext, ext_iff, eq all show up, maybe more. We should make these consistent. (The attribute will help, obviously.)

robertylewis avatar Nov 06 '19 21:11 robertylewis

In fact, @[ext] could be extended to generate the iff versions as well as the -> ones.

robertylewis avatar Nov 06 '19 21:11 robertylewis

Indeed

cipher1024 avatar Nov 06 '19 21:11 cipher1024

Are there examples of structures where it is harmful if @[ext] is applied?

jcommelin avatar Nov 07 '19 06:11 jcommelin

I can't think of one. The only thing is that it might not be the right notion of extensionality for you

cipher1024 avatar Nov 07 '19 15:11 cipher1024

So in an alternative world the structure keyword would generate these by default, unless you prepend it with @[noext] to indicate that you want to write your own "right notion" of extensionality.

jcommelin avatar Nov 07 '19 15:11 jcommelin

If we could change the meaning of structure, I'd be in favor with redefining it the way you say but I don't want to start redefining basic structures for something that an attribute does perfectly well.

Also, having a new structure keyword asks you to remember to use a different keyword in order to get the ext declaration. It's not exactly what I'd call a default behavior.

cipher1024 avatar Nov 07 '19 15:11 cipher1024

Exactly: we don't live in that alternative world :grinning: I'm happy to use @[ext].

jcommelin avatar Nov 07 '19 15:11 jcommelin

Currently, e.g., monoid_hom.ext uses ⦃f g : M →* N⦄ as arguments. Do I understand correctly that the new @[ext] structure monoid_hom would generate a lemma with (f g : M →* N)? Another difference between the manually defined and autogenerated lemmas would be usage of to_fun vs coe_fn. BTW, do you require extensional or = equality on function fields?

urkud avatar Nov 17 '19 18:11 urkud