Skip to content

Commit

Permalink
feat(algebra/group_power/basic): a^2 = b^2 ↔ a = b ∨ a = -b (#14431)
Browse files Browse the repository at this point in the history
Generalize `a ^ 2 = 1 ↔ a = 1 ∨ a = -1` to `ring` + `no_zero_divisors` and prove `a ^ 2 = b ^ 2 ↔ a = b ∨ a = -b` under `comm_ring` + `no_zero_divisors`.
  • Loading branch information
YaelDillies committed May 31, 2022
1 parent 8e522f8 commit 9dc4b8e
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 22 deletions.
44 changes: 29 additions & 15 deletions src/algebra/group_power/basic.lean
Expand Up @@ -399,7 +399,10 @@ alias neg_one_sq ← neg_one_pow_two
end has_distrib_neg

section ring
variable [ring R]
variables [ring R] {a b : R}

protected lemma commute.sq_sub_sq (h : commute a b) : a ^ 2 - b ^ 2 = (a + b) * (a - b) :=
by rw [sq, sq, h.mul_self_sub_mul_self_eq]

@[simp]
lemma neg_one_pow_mul_eq_zero_iff {n : ℕ} {r : R} : (-1)^n * r = 0 ↔ r = 0 :=
Expand All @@ -409,21 +412,26 @@ by rcases neg_one_pow_eq_or R n; simp [h]
lemma mul_neg_one_pow_eq_zero_iff {n : ℕ} {r : R} : r * (-1)^n = 0 ↔ r = 0 :=
by rcases neg_one_pow_eq_or R n; simp [h]

variables [no_zero_divisors R]

protected lemma commute.sq_eq_sq_iff_eq_or_eq_neg (h : commute a b) :
a ^ 2 = b ^ 2 ↔ a = b ∨ a = -b :=
by rw [←sub_eq_zero, h.sq_sub_sq, mul_eq_zero, add_eq_zero_iff_eq_neg, sub_eq_zero, or_comm]

@[simp] lemma sq_eq_one_iff : a^2 = 1 ↔ a = 1 ∨ a = -1 :=
by rw [←(commute.one_right a).sq_eq_sq_iff_eq_or_eq_neg, one_pow]

lemma sq_ne_one_iff : a^21 ↔ a ≠ 1 ∧ a ≠ -1 := sq_eq_one_iff.not.trans not_or_distrib

end ring

section comm_ring
variables [comm_ring R]

lemma sq_sub_sq (a b : R) : a ^ 2 - b ^ 2 = (a + b) * (a - b) :=
by rw [sq, sq, mul_self_sub_mul_self]
lemma sq_sub_sq (a b : R) : a ^ 2 - b ^ 2 = (a + b) * (a - b) := (commute.all a b).sq_sub_sq

alias sq_sub_sq ← pow_two_sub_pow_two

lemma eq_or_eq_neg_of_sq_eq_sq [no_zero_divisors R] (a b : R) (h : a ^ 2 = b ^ 2) :
a = b ∨ a = -b :=
by rwa [← add_eq_zero_iff_eq_neg, ← sub_eq_zero, or_comm, ← mul_eq_zero,
← sq_sub_sq a b, sub_eq_zero]

lemma sub_sq (a b : R) : (a - b) ^ 2 = a ^ 2 - 2 * a * b + b ^ 2 :=
by rw [sub_eq_add_neg, add_sq, neg_sq, mul_neg, ← sub_eq_add_neg]

Expand All @@ -432,16 +440,22 @@ alias sub_sq ← sub_pow_two
lemma sub_sq' (a b : R) : (a - b) ^ 2 = a ^ 2 + b ^ 2 - 2 * a * b :=
by rw [sub_eq_add_neg, add_sq', neg_sq, mul_neg, ← sub_eq_add_neg]

variables [no_zero_divisors R] {a b : R}

lemma sq_eq_sq_iff_eq_or_eq_neg : a ^ 2 = b ^ 2 ↔ a = b ∨ a = -b :=
(commute.all a b).sq_eq_sq_iff_eq_or_eq_neg

lemma eq_or_eq_neg_of_sq_eq_sq (a b : R) : a ^ 2 = b ^ 2 → a = b ∨ a = -b :=
sq_eq_sq_iff_eq_or_eq_neg.1

/- Copies of the above comm_ring lemmas for `units R`. -/
namespace units

lemma eq_or_eq_neg_of_sq_eq_sq [no_zero_divisors R] (a b : Rˣ) (h : a ^ 2 = b ^ 2) :
a = b ∨ a = -b :=
begin
refine (eq_or_eq_neg_of_sq_eq_sq _ _ _).imp (λ h, units.ext h) (λ h, units.ext h),
replace h := congr_arg (coe : Rˣ → R) h,
rwa [units.coe_pow, units.coe_pow] at h,
end
protected lemma sq_eq_sq_iff_eq_or_eq_neg {a b : Rˣ} : a ^ 2 = b ^ 2 ↔ a = b ∨ a = -b :=
by simp_rw [ext_iff, coe_pow, sq_eq_sq_iff_eq_or_eq_neg, units.coe_neg]

protected lemma eq_or_eq_neg_of_sq_eq_sq (a b : Rˣ) (h : a ^ 2 = b ^ 2) : a = b ∨ a = -b :=
units.sq_eq_sq_iff_eq_or_eq_neg.1 h

end units

Expand Down
6 changes: 0 additions & 6 deletions src/algebra/group_power/order.lean
Expand Up @@ -381,12 +381,6 @@ lemma sq_eq_sq_iff_abs_eq_abs (x y : R) : x^2 = y^2 ↔ |x| = |y| :=
⟨λ h, (abs_le_abs_of_sq_le_sq h.le).antisymm (abs_le_abs_of_sq_le_sq h.ge),
λ h, by rw [←sq_abs, h, sq_abs]⟩

@[simp] lemma sq_eq_one_iff (x : R) : x^2 = 1 ↔ x = 1 ∨ x = -1 :=
by rw [←abs_eq_abs, ←sq_eq_sq_iff_abs_eq_abs, one_pow]

lemma sq_ne_one_iff (x : R) : x^21 ↔ x ≠ 1 ∧ x ≠ -1 :=
(not_iff_not.2 (sq_eq_one_iff _)).trans not_or_distrib

@[simp] lemma sq_le_one_iff_abs_le_one (x : R) : x^21 ↔ |x| ≤ 1 :=
have t : x^21^2 ↔ |x| ≤ |1| := ⟨abs_le_abs_of_sq_le_sq, sq_le_sq⟩, by simpa using t

Expand Down
2 changes: 1 addition & 1 deletion src/number_theory/legendre_symbol/quadratic_char.lean
Expand Up @@ -142,7 +142,7 @@ by rwa [pow_two, ← quadratic_char_mul, ← pow_two, quadratic_char_sq_one']
/-- The quadratic character is `1` or `-1` on nonzero arguments. -/
lemma quadratic_char_dichotomy {a : F} (ha : a ≠ 0) :
quadratic_char F a = 1 ∨ quadratic_char F a = -1 :=
(sq_eq_one_iff (quadratic_char F a)).mp (quadratic_char_sq_one ha)
sq_eq_one_iff.1 $ quadratic_char_sq_one ha

/-- A variant -/
lemma quadratic_char_eq_neg_one_iff_not_one {a : F} (ha : a ≠ 0) :
Expand Down

0 comments on commit 9dc4b8e

Please sign in to comment.