Zulip Chat Archive

Stream: Is there code for X?

Topic: Modulo characterization for Nat


Siddharth Bhat (Jul 31 2024 at 14:19):

example (m k : Nat) : m % k = m - k * (m / k) := by
  rw [Nat.sub_eq_of_eq_add]
  apply (Nat.mod_add_div _ _).symm

Does this exist in the library someplace? I tried loogling and looking, but failed to come up with anything. For Int, it's called Int.emod_def, and for ordinal, as Ordinal.mod_def. What should I name the Nat lemma?

Siddharth Bhat (Jul 31 2024 at 14:19):

I am tempted to call it Nat.mod_def.

Ralf Stephan (Jul 31 2024 at 15:17):

Somewhere in Data/Nat/ModEq?

Ralf Stephan (Jul 31 2024 at 16:06):

Term mode:

example (m k : Nat) : m % k = m - k * (m / k) :=
  Eq.symm (Nat.sub_eq_of_eq_add (Eq.symm (Nat.mod_add_div m k)))

Ralf Stephan (Jul 31 2024 at 16:21):

Better:

example (m k : Nat) : m % k = m - k * (m / k) :=
  Eq.symm <| Nat.sub_eq_of_eq_add <| Eq.symm <| Nat.mod_add_div m k

Michael Stoll (Jul 31 2024 at 18:27):

Or, using dot notation,

example (m k : Nat) : m % k = m - k * (m / k) :=
  (Nat.sub_eq_of_eq_add (Nat.mod_add_div m k).symm).symm

Last updated: May 02 2025 at 03:31 UTC