Zulip Chat Archive

Stream: maths

Topic: zmod n to ℚ


Ashvni Narayanan (Nov 08 2021 at 20:57):

I don't understand why this is true :
example (n : ℕ) (a b : zmod n) : ((a * b) : ℚ) = (a : ℚ) * (b : ℚ) :=
The proof is refl. As far as I understand, the coercion to arises from the map to taking a : zmod n to a.val, which is not multiplicative..
Any help is appreciated, thank you!

Kevin Buzzard (Nov 08 2021 at 21:02):

The proof is refl because elaboration works from the outside in. Lean sees (a * b : ℚ) and its first thought is _not_ "oh, a and b are in zmod n, so that * must be multiplication in zmod n", it says "Oh OK, so the result of this multiplication is supposed to be in so that multiplication must definitely be rat.mul -- now let's elaborate further; oh look, a and b are in zmod n, we wanted things in rat so let's coerce." The result is that the two sides of the equality in your example are the same.

Ashvni Narayanan (Nov 08 2021 at 21:08):

I see, thank you!

Patrick Massot (Nov 08 2021 at 21:09):

Let me elaborate a bit since this is an important and tricky topic. First thing to notice is that the goal clearly shows the coercion arrows are not where you want them to be. Then you need to understand when Lean insert coercion arrows.

Kevin Buzzard (Nov 08 2021 at 21:13):

Oh yeah as Patrick says, if you look at your goal for the refl goal it's ⊢ ↑a * ↑b = ↑a * ↑b. The way to make the false goal is

example (n : ) (a b : zmod n) : ((a * b : zmod n) : ) = (a : ) * (b : ) := rfl -- fails

which gives you a goal ⊢ ↑(a * b) = ↑a * ↑b

Patrick Massot (Nov 08 2021 at 21:13):

Basically Lean works left to right, soliving constraints as soon as possible and inserts a coercion only when desperate. Here you need to remember that the infix notation is only a notation, so ((a * b) : ℚ) is really a has_mul.mul a b : ℚ. Given the type ascription, Lean knows the multiplication has to be multiplication of rational numbers. Then it moves to a. This is not a rational and there is nothing else to try so Lean inserts a coercion. Then the same happen with b.

Ashvni Narayanan (Nov 08 2021 at 22:25):

Oh I see, thank you!


Last updated: Dec 20 2023 at 11:08 UTC