leanprover / lean4

Lean 4 programming language and theorem prover
https://lean-lang.org
Apache License 2.0
4.75k stars 427 forks source link

feat: add `Nat.mod_eq_sub` and fix dependencies from `Nat.sub_mul_eq_mod_of_lt_of_le` #6160

Closed luisacicolini closed 2 days ago

luisacicolini commented 1 week ago

This PR adds theorem mod_eq_sub, makes theorem sub_mul_eq_mod_of_lt_of_le not private anymore and moves its location within the rotate* section to use it in other proofs.

leanprover-community-bot commented 1 week ago

Mathlib CI status (docs):

luisacicolini commented 4 days ago

Thanks a lot @kim-em @bollu for the reviews! It took me some time to understand it, but the proof of mod_eq_sub_of_le_of_lt should now be okay.

luisacicolini commented 4 days ago

awaiting-reviews

luisacicolini commented 3 days ago

Actually, it looks like one such theorem exists already: Nat.sub_mul_eq_mod_of_lt_of_le so I guess this PR is not needed after all and I can use the other theorem. And maybe move the private theorem to Nat.

kim-em commented 3 days ago

Could we make sure

theorem mod_eq_sub (x w : Nat) : x % w = x - w * (x / w) := by
  conv => rhs; congr; rw [← mod_add_div x w]
  simp

makes it in? Either strip this PR down to just that, or close this PR and include it in a subsequent PR?

luisacicolini commented 3 days ago

I have fixed the dependencies from the existing theorem (which is now not private anymore and in a different location, otherwise I could not use it) and kept mod_eq_sub. Happy to split the PR into two if that is better.