Zulip Chat Archive
Stream: general
Topic: subtype simp normal form
Floris van Doorn (Jun 26 2020 at 03:14):
Is there a reason that when x
is an element of a subtype, neither x.1
nor ↑x
is in simp-normal-form?
example {α} {P : α → Prop} {x : subtype P} : x.1 = (x : α) :=
by { simp } -- fails
Johan Commelin (Jun 26 2020 at 03:16):
Clearly, we need to fix things here. The .ext
lemma etc are not following standard conventions either.
Floris van Doorn (Jun 26 2020 at 03:18):
Which one would we want to be simp-normal form? The coe?
Kevin Buzzard (Jun 26 2020 at 05:59):
This has bitten me before too. There is no subtype.ext_iff, and the ext tactic does not work for subtypes
Patrick Massot (Jun 26 2020 at 07:40):
I think having the coe as simp normal form would be more consistent with our other choices.
Reid Barton (Jun 26 2020 at 12:21):
Yes, at one point I tried adding the ext lemma for subtype
to @[ext]
, and it broke some things which were all avoided by phrasing it in terms of the coercion.
Reid Barton (Jun 26 2020 at 12:21):
(I'm still not sure whether it is actually a good idea to add it though.)
Johan Commelin (Jun 26 2020 at 12:22):
Why not?
Reid Barton (Jun 26 2020 at 12:28):
It can be too aggressive with things like nnreal
(I don't remember whether this is an actual example, but it might be) defined directly as subtype
where there currently is no ext
lemma and outside the nnreal
file itself you probably don't actually want to prove equalities of nnreal
by proving equalities of the underlying value. (Okay maybe this isn't a great example, because real
>> nnreal
, but imagine you also want to use some hypotheses which are in nnreal
language.)
Reid Barton (Jun 26 2020 at 12:30):
On the other hand I think it actually didn't break anything in mathlib at all, so maybe this isn't a real concern.
And if it is, one could argue that nnreal
should use a custom structure type anyways and not be a def
around subtype
.
Yury G. Kudryashov (Jun 26 2020 at 13:36):
Does ext
unfold definitions?
Scott Morrison (Jun 26 2020 at 13:36):
It does, although since it is using apply
under the hood we _could_ turn this off.
Scott Morrison (Jun 26 2020 at 13:36):
(This would surely break a lot.)
Reid Barton (Jun 26 2020 at 13:36):
It seems unafraid to apply lemmas even if it would need semireducible transparency to do so, yes
Scott Morrison (Jun 26 2020 at 13:37):
Maybe we want ext
and ext!
(with the current behaviour)?
Reid Barton (Jun 26 2020 at 13:37):
Probably the things it would be break could be fixed by adding more ext
lemmas, right?
Yury G. Kudryashov (Jun 26 2020 at 13:38):
I thought that ext
stores lemmas sorted by head type name in order to apply only a small set of lemmas.
Yury G. Kudryashov (Jun 26 2020 at 13:38):
But it applies option
ext lemma to ennreal
.
Yury G. Kudryashov (Jun 26 2020 at 13:38):
So I have to use ext1
in measure_theory
.
Yury G. Kudryashov (Jun 26 2020 at 13:39):
I think that applying only lemmas with the desired head symbol is the "least surprise" approach.
Reid Barton (Jun 26 2020 at 13:42):
I rely on the current behavior pretty heavily in lean-homotopy-theory to check whether two morphisms X \hom Y
in Top
are equal by function extensionality, and various other things like this, but I think I could add lemmas for these if ext
refused to apply funext
here.
Reid Barton (Jun 26 2020 at 13:43):
actually that might be a bad example, since that needs a separate extensionality lemma anyways.
Reid Barton (Jun 26 2020 at 13:44):
The other examples are things like checking equality of x y : Top.prod A B
where A B : Top
using ext
for prod
.
Yury G. Kudryashov (Jun 26 2020 at 13:44):
You can always use attribute [ext newtype] oldlemma
.
Reid Barton (Jun 26 2020 at 13:45):
Here Top.prod A B
is something whose underlying type will unfold to prod
of the underlying types of A
and B
Yury G. Kudryashov (Jun 26 2020 at 13:46):
Probably we should make an exception for the case "head symbol is coe_sort
".
Floris van Doorn (Jun 26 2020 at 16:47):
Yes, I've also noticed that ext
for option
is applied to ennreal
. It's not really a problem if you use ext1
instead.
(also, I regularly want to prove two nnreal
s equal and am sad that ext
doesn't work).
I will try to do some low level changes to subtype.
Floris van Doorn (Jun 26 2020 at 18:41):
Ok, I'm working on it now: https://github.com/leanprover-community/mathlib/tree/subtype
I'm adding @[ext]
for subtype
and simplify x.val
to ↑x
. There is a lot of damage, but so far most of it is fixed just by
- using the coercion more, instead of
subtype.val
- using
ext1
ifext
is too aggressive. - There are a couple of places where I have to add
-subtype.val_eq_coe
as argument to simp. This happens when a new type is defined as a subtype, so the coercion doesn't fire anymore, andsubtype.val
is still used to get the first component.
Please voice any concerns of this change ASAP.
Floris van Doorn (Jun 26 2020 at 18:42):
A version of ext
that doesn't unfold definitions (and making that the default version?) sounds useful as well!
Johan Commelin (Jun 26 2020 at 20:04):
So far, this sounds good to me! Thanks for battling through this
Last updated: Dec 20 2023 at 11:08 UTC