Skip to content

Commit ab52fda

Browse files
committed
refactor(Data/Int/Units): golf isUnit_eq_or_eq_neg (#6952)
This PR adds an `IsUnit` version of `units_ne_iff_eq_neg` and uses it to golf `isUnit_eq_or_eq_neg`.
1 parent 2532847 commit ab52fda

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

Mathlib/Data/Int/Units.lean

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ theorem units_ne_iff_eq_neg {u u' : ℤˣ} : u ≠ u' ↔ u = -u' := by
4242
rcases units_eq_one_or u' with rfl | rfl <;>
4343
decide
4444

45+
theorem isUnit_ne_iff_eq_neg {u u' : ℤ} (hu : IsUnit u) (hu' : IsUnit u') : u ≠ u' ↔ u = -u' := by
46+
simpa only [Ne, Units.ext_iff] using units_ne_iff_eq_neg (u := hu.unit) (u' := hu'.unit)
47+
4548
theorem isUnit_eq_one_or {a : ℤ} : IsUnit a → a = 1 ∨ a = -1
4649
| ⟨_, hx⟩ => hx ▸ (units_eq_one_or _).imp (congr_arg Units.val) (congr_arg Units.val)
4750
#align int.is_unit_eq_one_or Int.isUnit_eq_one_or
@@ -53,10 +56,8 @@ theorem isUnit_iff {a : ℤ} : IsUnit a ↔ a = 1 ∨ a = -1 := by
5356
· exact isUnit_one.neg
5457
#align int.is_unit_iff Int.isUnit_iff
5558

56-
theorem isUnit_eq_or_eq_neg {a b : ℤ} (ha : IsUnit a) (hb : IsUnit b) : a = b ∨ a = -b := by
57-
rcases isUnit_eq_one_or hb with (rfl | rfl)
58-
· exact isUnit_eq_one_or ha
59-
· rwa [or_comm, neg_neg, ← isUnit_iff]
59+
theorem isUnit_eq_or_eq_neg {a b : ℤ} (ha : IsUnit a) (hb : IsUnit b) : a = b ∨ a = -b :=
60+
or_iff_not_imp_left.mpr (isUnit_ne_iff_eq_neg ha hb).mp
6061
#align int.is_unit_eq_or_eq_neg Int.isUnit_eq_or_eq_neg
6162

6263
theorem eq_one_or_neg_one_of_mul_eq_one {z w : ℤ} (h : z * w = 1) : z = 1 ∨ z = -1 :=

0 commit comments

Comments
 (0)