Zulip Chat Archive

Stream: Is there code for X?

Topic: data.nat.parity


Patrick Johnson (Jan 19 2022 at 13:43):

I very often use these theorems:

lemma add_div_eq_succ_div {n m : } (h : 0 < m) : (n + m) / m = n / m + 1
lemma pos_of_odd {n : } (h : odd n) : 0 < n
lemma even_div_2 {n : } (h : even n) : n / 2 * 2 = n
lemma odd_div_2 {n : } (h : odd n) : n / 2 * 2 + 1 = n
lemma odd_div_2' {n : } (h : odd n) : n / 2 * 2 = n - 1

All of them are easy to prove, but I'm wondering is it worth adding some of them to mathlib? Or maybe some of them already exists?

Yaël Dillies (Jan 19 2022 at 14:20):

The first one is docs#div_add_one. The second one should be called odd.pos and is true in a docs#canonically_ordered_comm_semiring.

Patrick Johnson (Jan 19 2022 at 17:10):

Ok, I may open a PR (except for the first lemma). Which of (n / 2 * 2 + 1 = n) and (n / 2 * 2 = n - 1) is preferred?

Yaël Dillies (Jan 19 2022 at 17:12):

The first

Oliver Nash (Jan 19 2022 at 17:12):

Yaël Dillies said:

The first one is docs#div_add_one. The second one should be called odd.pos and is true in a docs#canonically_ordered_comm_semiring.

I note we have docs#nat.odd_gt_zero which is badly named. Your PR could fix this too!

Yaël Dillies (Jan 19 2022 at 17:14):

And generalize it!

Patrick Johnson (Jan 20 2022 at 12:44):

The second one should be called odd.pos and is true in a docs#canonically_ordered_comm_semiring.

It doesn't seem to be true in any canonically ordered commutative semiring. I guess I need a nontrivial instance. Do I need some more instances on it?

Yaël Dillies (Jan 20 2022 at 14:29):

None I think

Yaël Dillies (Jan 20 2022 at 14:30):

Ah yes, you need docs#nontrivial

Ruben Van de Velde (Jan 20 2022 at 14:31):

Maybe odd.ne_zero would also be useful


Last updated: Dec 20 2023 at 11:08 UTC