Zulip Chat Archive

Stream: new members

Topic: How to unfold a coercion?


Darij Grinberg (Oct 24 2025 at 20:04):

I am having a goal that contains both ofNat and in it. From what I understand, the latter is just an alias of the former, but this suffices to confuse rw. I can use erw to break through this wall, but is there a way to just replace throughout the goal?

Kenny Lau (Oct 24 2025 at 20:09):

@Darij Grinberg they aren't literally the same, otherwise you would see the same result; the solution is that usually there are simp lemmas to convert a non-standard form to a standard form

Darij Grinberg (Oct 24 2025 at 20:10):

how can I find the one that unfolds a coercion? I'm not sure it's even a lemma; looks like it is the definition of the ↑ here

Kenny Lau (Oct 24 2025 at 20:10):

which ofNat are you looking at?

Kenny Lau (Oct 24 2025 at 20:10):

#mwe

Kenny Lau (Oct 24 2025 at 20:12):

if you don't have mwe (which you should, try extract_goal), can you at least post a screenshot after you click into the ofNat that appears in the goal

Darij Grinberg (Oct 24 2025 at 20:14):

Int.ofNat

Darij Grinberg (Oct 24 2025 at 20:15):

image.png

Darij Grinberg (Oct 24 2025 at 20:16):

the arrow is @Nat.cast ℤ instNatCastInt n : ℤ
the ofNat is ofNat : ℕ → ℤ

Kenny Lau (Oct 24 2025 at 20:16):

@Darij Grinberg the simmp lemma is Int.ofNat_eq_coe which is already tagged with simp

Darij Grinberg (Oct 24 2025 at 20:16):

ah thak you!

Kenny Lau (Oct 24 2025 at 20:17):

Darij Grinberg said:

how can I find the one that unfolds a coercion?

this is the wrong question, we keep getting into an #xy problem, you shouldn't "unfold coercion", the correct thing is to do it the other way

Darij Grinberg (Oct 24 2025 at 20:18):

oh lol, i see i can finish the proof with simp at that point

Kenny Lau (Oct 24 2025 at 20:18):

it's a beginners' trap to try to unfold everything, that is rarely the best way to do things

Darij Grinberg (Oct 24 2025 at 20:18):

i don't mind the coercion per se, i mind having two different forms of it :)

Darij Grinberg (Oct 24 2025 at 20:19):

which one should i be using in definitions?

Kenny Lau (Oct 24 2025 at 20:19):

what do you mean two different forms

Darij Grinberg (Oct 24 2025 at 20:19):

↑ and ofNat

Kenny Lau (Oct 24 2025 at 20:19):

and what do you mean use in definition

Kenny Lau (Oct 24 2025 at 20:19):

coercion only refers to the uparrow

Kenny Lau (Oct 24 2025 at 20:20):

Int.ofNat is just another random function from Nat to Int

Darij Grinberg (Oct 24 2025 at 20:20):

i have
def intfac (n : ℕ) := Int.ofNat (factorial n)
and i'm wondering if i should replace it by
def intfac (n : ℕ) := ↑(factorial n)

Kenny Lau (Oct 24 2025 at 20:20):

you shouldn't have it in the first place, what's the point of it

Darij Grinberg (Oct 24 2025 at 20:21):

i guess not much now that the arrow is so short

Kenny Lau (Oct 24 2025 at 20:21):

no, you should never type the arrow, that's another beginner's trap (some people have disagreed with me on this point, but I stand by it)

Darij Grinberg (Oct 24 2025 at 20:21):

OK. what is it i should be doing? I want n! as an integer, not as a nonnegative integer

Kenny Lau (Oct 24 2025 at 20:21):

the correct way is (factorial n : ℤ) (and not a separate definition)

Darij Grinberg (Oct 24 2025 at 20:22):

ah!

Darij Grinberg (Oct 24 2025 at 20:22):

yeah i guess it's pretty pointless given how simple this is

Kenny Lau (Oct 24 2025 at 20:23):

and btw n.factorial is more preferred

Darij Grinberg (Oct 24 2025 at 20:23):

because it's closer to the math notation?

Kenny Lau (Oct 24 2025 at 20:24):

no, dot notation is just preferred

Aaron Liu (Oct 24 2025 at 20:25):

Kenny Lau said:

no, dot notation is just preferred

how come I've never heard of this

Kenny Lau (Oct 24 2025 at 20:25):

sorry i meant I personally prefer it, I should have been clear

Darij Grinberg (Oct 24 2025 at 20:26):

:joy:


Last updated: Dec 20 2025 at 21:32 UTC