Zulip Chat Archive
Stream: Is there code for X?
Topic: CharP R 2 ↔ 1 + 1 = 0
Violeta Hernández (Aug 23 2024 at 08:24):
What it says in the title. Can I show a monoid has characteristic 2 just by showing 1 + 1 = 0?
Yaël Dillies (Aug 23 2024 at 08:25):
No, because it could have characteristic one
Violeta Hernández (Aug 23 2024 at 08:26):
...with the extra 0 ≠ 1
assumption
Ruben Van de Velde (Aug 23 2024 at 08:38):
import Mathlib
example (R : Type u_6) [NonAssocRing R] (h1 : (1 : R) ≠ 0) (h2 : (1 : R) + 1 = 0) : CharP R 2 := by
convert CharP.addOrderOf_one R
symm
rw [addOrderOf_eq_iff two_pos]
constructor
· simpa [one_add_one_eq_two] using h2
· intro m hmr hml
interval_cases m
simpa
Ruben Van de Velde (Aug 23 2024 at 08:39):
interval_cases m
can also be obtain rfl : m = 1 := by omega
Violeta Hernández (Aug 23 2024 at 08:41):
Thanks! It'd be really nice to have this PR'd
Ruben Van de Velde (Aug 23 2024 at 08:42):
Go ahead :)
Violeta Hernández (Aug 23 2024 at 08:55):
Wait, does this require a ring? Surely you could do this with an arbitrary AddMonoidWithOne
Ruben Van de Velde (Aug 23 2024 at 09:08):
docs#CharP.addOrderOf_one uses docs#Nat.smul_one_eq_cast , I haven't thought about whether that's avoidable
Violeta Hernández (Aug 23 2024 at 09:08):
It should be. By induction, if n
is even then n = 0
, otherwise n = 1
. This follows from just the equations and the fact zero is neutral.
Violeta Hernández (Aug 23 2024 at 09:09):
(deleted)
Violeta Hernández (Aug 23 2024 at 09:11):
I'm having a bit of trouble proving this though, the API for Even
and Odd
seems very undercooked. Why would docs#Nat.even_add_one use ¬ Even n
instead of Odd n
? Why isn't there a Nat.odd_add_one
?
Yaël Dillies (Aug 23 2024 at 09:12):
The ¬ Even n
is an historical accident by this point. Please fix it. Nat.odd_add_one
doesn't need to exist since we have docs#Odd.add_odd
Violeta Hernández (Aug 23 2024 at 09:12):
Why does docs#Nat.not_even_iff use the n % 2 = 1
spelling? This is so frustrating
Yaël Dillies (Aug 23 2024 at 09:13):
Please fix, please fix :pray:
Violeta Hernández (Aug 23 2024 at 09:13):
Will do
Violeta Hernández (Aug 23 2024 at 09:15):
Oh wait, you have a PR related to that, don't you?
Violeta Hernández (Aug 23 2024 at 09:15):
Might be better to wait until that's merged
Yaël Dillies (Aug 23 2024 at 09:15):
Yes, #16024. Currently maintainer-merge
Violeta Hernández (Aug 23 2024 at 09:18):
Yaël Dillies said:
Nat.odd_add_one
doesn't need to exist since we have docs#Odd.add_odd
It's annoying that's not an iff though.
Violeta Hernández (Aug 23 2024 at 09:19):
Simp lemmas Even (n + 1) ↔ Odd n
and Odd (n + 1) ↔ Even n
would be really nice
Yaël Dillies (Aug 23 2024 at 09:19):
Feel free to add Odd.add_even_iff
, Odd.add_odd_iff
Johan Commelin (Aug 23 2024 at 09:30):
Yaël Dillies said:
Yes, #16024. Currently
maintainer-merge
borsified
Violeta Hernández (Aug 23 2024 at 09:31):
import Mathlib.Algebra.CharP.Defs
variable {R : Type*} [AddMonoidWithOne R]
theorem eq_zero_or_one_of_one_add_one (h : (1 : R) + 1 = 0) (n : ℕ):
(Even n → (n : R) = 0) ∧ (Odd n → (n : R) = 1) := by
induction n with
| zero => simp
| succ n IH =>
rw [Nat.even_add_one, ← Nat.odd_iff_not_even, Nat.odd_add]
simp only [Nat.cast_add, Nat.odd_iff_not_even.not, Nat.cast_one, Nat.not_even_one, iff_false,
Decidable.not_not, add_left_eq_self]
obtain hn | hn := Nat.even_or_odd n
· simp [hn, IH.1 hn]
· simpa [hn, Nat.odd_iff_not_even.1 hn, IH.2 hn] using h
theorem char_two_of_one_add_one (h₁ : (1 : R) ≠ 0) (h₂ : (1 : R) + 1 = 0) : CharP R 2 := by
constructor
intro n
obtain hn | hn := Nat.even_or_odd n
· simpa [hn.two_dvd] using (eq_zero_or_one_of_one_add_one h₂ n).1 hn
· simp [hn.not_two_dvd_nat]
rwa [(eq_zero_or_one_of_one_add_one h₂ n).2 hn]
Violeta Hernández (Aug 23 2024 at 09:31):
I've never felt more at "odds" with simp
Ruben Van de Velde (Aug 23 2024 at 09:40):
import Mathlib.Algebra.CharP.Defs
lemma Nat.odd_add_one {n : ℕ} : Odd (n + 1) ↔ ¬ Odd n := by
simp [Nat.even_add_one]
variable {R : Type*} [AddMonoidWithOne R]
theorem eq_zero_or_one_of_one_add_one (h : (1 : R) + 1 = 0) (n : ℕ):
(Even n → (n : R) = 0) ∧ (Odd n → (n : R) = 1) := by
induction n using Nat.twoStepInduction with
| H1 => simp
| H2 => simp
| H3 n IH1 IH2 =>
rw [one_add_one_eq_two] at h
simpa only [Nat.succ_eq_add_one, add_assoc, Nat.reduceAdd, Nat.cast_add, Nat.cast_ofNat,
Nat.even_add_one, Nat.odd_add_one, Decidable.not_not, h, add_zero]
Ruben Van de Velde (Aug 23 2024 at 09:41):
Or simpa [-Nat.odd_iff_not_even, add_assoc, Nat.even_add_one, Nat.odd_add_one, h]
Violeta Hernández (Aug 23 2024 at 09:42):
Nice!
Ruben Van de Velde (Aug 23 2024 at 09:42):
(Those arguments are poorly named)
Violeta Hernández (Oct 07 2024 at 09:32):
I opened #17483 which (among other things) proves this result
Last updated: May 02 2025 at 03:31 UTC