Zulip Chat Archive

Stream: mathlib4

Topic: inconsistency in matching


Ralf Stephan (Aug 04 2024 at 10:13):

Can someone explain please why the first example works but the second does not?

import Mathlib
open ZMod Nat

example (a p : ) (h : p  a) : a = (0 : ZMod p) := by
  apply (natCast_zmod_eq_zero_iff_dvd a p).mpr h

example  (a p : ) (h : p  a + 1) : a + 1 = (0 : ZMod p) := by
  apply (natCast_zmod_eq_zero_iff_dvd (a + 1) p).mpr h

Ralf Stephan (Aug 04 2024 at 10:27):

I needed norm_cast. Thanks.

Ruben Van de Velde (Aug 04 2024 at 10:47):

Probably one happens to be true by definition and the other doesn't

Eric Wieser (Aug 04 2024 at 10:49):

The second one is fine if you write

example  (a p : ) (h : p  a + 1) : (a + 1) = (0 : ZMod p) := by
  apply (natCast_zmod_eq_zero_iff_dvd (a + 1) p).mpr h

Ralf Stephan (Aug 04 2024 at 11:15):

The original does also not work with exact. I would have expected exact to apply norm_cast.

Damiano Testa (Aug 04 2024 at 11:17):

There is exact_mod_cast for that.

Mario Carneiro (Aug 04 2024 at 11:56):

I wonder if we should deprecate exact_mod_cast since it's just exact mod_cast

Kevin Buzzard (Aug 04 2024 at 11:57):

By the same argument we should deprecate simpa because "it's just exact simp" right?

Kevin Buzzard (Aug 04 2024 at 11:58):

@Ralf Stephan exact h succeeds when h is definitionally equal to the goal, exact isn't applying any cast tactics or anything, it's just applying the algorithm for rfl.

Eric Wieser (Aug 04 2024 at 12:00):

Kevin Buzzard said:

By the same argument we should deprecate simpa because "it's just exact simp" right?

Surely simp isn't legal in term mode?

Mario Carneiro (Aug 04 2024 at 12:02):

it's also the same number of characters and even the same words in the same order

Mario Carneiro (Aug 04 2024 at 12:02):

also simpa isn't just exact simp, it's simp at h; simp; exact h

Mario Carneiro (Aug 04 2024 at 12:02):

give or take some edge cases

Mario Carneiro (Aug 04 2024 at 12:05):

when I say it is just exact mod_cast I mean it literally; compare with simpa

Eric Wieser (Aug 04 2024 at 12:20):

They're not literally the same, right? Thanks to the extra parens, exact_mod_cast . is legal, but exact mod_cast . isn't.

Ralf Stephan (Aug 04 2024 at 13:18):

It would be helpful if hint would find it.

Mario Carneiro (Aug 04 2024 at 14:16):

Eric Wieser said:

They're not literally the same, right? Thanks to the extra parens, exact_mod_cast . is legal, but exact mod_cast . isn't.

no, . is extra magic, it applies before macro expansion so it doesn't work like that

Mario Carneiro (Aug 04 2024 at 14:16):

the extra parens presumably do something but as far as I know (e : _) is a no-op

Eric Wieser (Aug 04 2024 at 15:06):

Mario Carneiro said:

no, . is extra magic, it applies before macro expansion so it doesn't work like that

I agree it shouldn't work like that, but it does:

import Mathlib

example :    := by exact mod_cast · -- fails
example :    := by exact_mod_cast · -- ok

Eric Wieser (Aug 04 2024 at 15:06):

by use · is legal for the same reason, even though by exact · isn't


Last updated: May 02 2025 at 03:31 UTC