Zulip Chat Archive

Stream: mathlib4

Topic: norm_cast and ofNat


Yury G. Kudryashov (Nov 03 2023 at 18:01):

Should norm_cast recognize OfNat.ofNat as a coercion so that it can normalize expressions like ENNReall.ofReal (OfNat.ofNat n)?

Yury G. Kudryashov (Nov 03 2023 at 18:02):

In some sense, ofNat is a cast from nat literals to a type with OfNat instance.

Alex J. Best (Nov 03 2023 at 18:06):

Isn't the issue more that ENNReal.ofReal isn't a cast? Rather than it being ofNat or any other coercion to reals?

Alex J. Best (Nov 03 2023 at 18:06):

Like

import Mathlib


example (n : ) : ((n : ) : ) = x := by
  norm_cast -- gets rid of a cast

example (n : ) : (ENNReal.ofReal (n : ) : ENNReal) = x := by
  norm_cast -- does nothing


example (n : ) : (ENNReal.ofReal (n : ) : ENNReal) = x := by
  norm_cast  --- same

Yury G. Kudryashov (Nov 03 2023 at 18:07):

Second example works if you add @[norm_cast] to docs#ENNReal.ofReal_coe_nat (done locally)

Yury G. Kudryashov (Nov 03 2023 at 18:08):

And we don't have a lemma about ofReal and Rat.cast.

Yury G. Kudryashov (Nov 03 2023 at 18:09):

Because we don't have ENNReal.ofRat.

Alex J. Best (Nov 03 2023 at 18:17):

So if you add that attribute what goes wrong with ofNat? #mwe please

Yury G. Kudryashov (Nov 03 2023 at 18:19):

docs#ENNReal.ofReal_ofNat can't be a norm_cast lemma.

Alex J. Best (Nov 03 2023 at 18:20):

I still don't understand what isn't working that you think should be though?

Alex J. Best (Nov 03 2023 at 18:21):

Like this works fine

import Mathlib

attribute [norm_cast] ENNReal.ofReal_coe_nat
example (n : ) : (ENNReal.ofReal (7  : ) : ENNReal) = x := by
  norm_cast

Alex J. Best (Nov 03 2023 at 18:21):

If you have ofNats in the goal applied to anything other than nat literals then I don't know how they would get there

Yury G. Kudryashov (Nov 03 2023 at 18:23):

I was proving a generic lemma about OfNat.ofNat but probably you're right: all these lemmas should be done by defeq to a Nat.cast lemma.

Yury G. Kudryashov (Nov 03 2023 at 18:28):

I was working on #8163. I added norm_cast to ofReal_coe_nat, then tried the next lemma and failed.


Last updated: Dec 20 2023 at 11:08 UTC