Skip to content
This repository was archived by the owner on Jul 24, 2024. It is now read-only.

Commit df8ef37

Browse files
feat(data/int/basic algebra/associated): is_unit (a : ℤ) iff a = ±1 (#7058)
Besides the title lemma, this PR also moves lemma `is_unit_int` from `algebra/associated` to `data/int/basic`. Co-authored-by: Eric Wieser <wieser.eric@gmail.com> Co-authored-by: Ruben Van de Velde <65514131+Ruben-VandeVelde@users.noreply.github.com> Co-authored-by: Ruben-VandeVelde <65514131+Ruben-VandeVelde@users.noreply.github.com>
1 parent a6024f1 commit df8ef37

File tree

4 files changed

+22
-6
lines changed

4 files changed

+22
-6
lines changed

src/algebra/associated.lean

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,6 @@ theorem is_unit_of_dvd_unit {α} [comm_monoid α] {x y : α}
2525
(xy : x ∣ y) (hu : is_unit y) : is_unit x :=
2626
is_unit_iff_dvd_one.2 $ dvd_trans xy $ is_unit_iff_dvd_one.1 hu
2727

28-
theorem is_unit_int {n : ℤ} : is_unit n ↔ n.nat_abs = 1 :=
29-
begin rintro ⟨u, rfl⟩, exact (int.units_eq_one_or u).elim (by simp) (by simp) end,
30-
λ h, is_unit_iff_dvd_one.2 ⟨n, by rw [← int.nat_abs_mul_self, h]; refl⟩⟩
31-
3228
lemma is_unit_of_dvd_one [comm_monoid α] : ∀a ∣ 1, is_unit (a:α)
3329
| a ⟨b, eq⟩ := ⟨units.mk_of_mul_eq_one a b eq.symm, rfl⟩
3430

src/algebra/ring/basic.lean

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -606,6 +606,9 @@ protected theorem neg_eq_neg_one_mul (u : units α) : -u = -1 * u := by simp
606606

607607
end units
608608

609+
lemma is_unit.neg [ring α] {a : α} : is_unit a → is_unit (-a)
610+
| ⟨x, hx⟩ := hx ▸ (-x).is_unit
611+
609612
namespace ring_hom
610613

611614
/-- Ring homomorphisms preserve additive inverse. -/

src/data/int/basic.lean

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,9 @@ begin
272272
{ cases h; rw h, rw int.nat_abs_neg, },
273273
end
274274

275+
lemma nat_abs_eq_iff {a : ℤ} {n : ℕ} : a.nat_abs = n ↔ a = n ∨ a = -n :=
276+
by rw [←int.nat_abs_eq_nat_abs_iff, int.nat_abs_of_nat]
277+
275278
lemma nat_abs_eq_iff_mul_self_eq {a b : ℤ} : a.nat_abs = b.nat_abs ↔ a * a = b * b :=
276279
begin
277280
rw [← abs_eq_iff_mul_self_eq, abs_eq_nat_abs, abs_eq_nat_abs],
@@ -1069,6 +1072,20 @@ units.ext_iff.1 $ nat.units_eq_one ⟨nat_abs u, nat_abs ↑u⁻¹,
10691072
theorem units_eq_one_or (u : units ℤ) : u = 1 ∨ u = -1 :=
10701073
by simpa only [units.ext_iff, units_nat_abs] using nat_abs_eq u
10711074

1075+
lemma is_unit_eq_one_or {a : ℤ} : is_unit a → a = 1 ∨ a = -1
1076+
| ⟨x, hx⟩ := hx ▸ (units_eq_one_or _).imp (congr_arg coe) (congr_arg coe)
1077+
1078+
lemma is_unit_iff {a : ℤ} : is_unit a ↔ a = 1 ∨ a = -1 :=
1079+
begin
1080+
refine ⟨λ h, is_unit_eq_one_or h, λ h, _⟩,
1081+
rcases h with rfl | rfl,
1082+
{ exact is_unit_one },
1083+
{ exact is_unit_one.neg }
1084+
end
1085+
1086+
theorem is_unit_iff_nat_abs_eq {n : ℤ} : is_unit n ↔ n.nat_abs = 1 :=
1087+
by simp [nat_abs_eq_iff, is_unit_iff]
1088+
10721089
lemma units_inv_eq_self (u : units ℤ) : u⁻¹ = u :=
10731090
(units_eq_one_or u).elim (λ h, h.symm ▸ rfl) (λ h, h.symm ▸ rfl)
10741091

src/ring_theory/int/basic.lean

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ lemma exists_unit_of_abs (a : ℤ) : ∃ (u : ℤ) (h : is_unit u), (int.nat_abs
149149
begin
150150
cases (nat_abs_eq a) with h,
151151
{ use [1, is_unit_one], rw [← h, one_mul], },
152-
{ use [-1, is_unit_int.mpr rfl], rw [ ← neg_eq_iff_neg_eq.mp (eq.symm h)],
152+
{ use [-1, is_unit_one.neg], rw [ ← neg_eq_iff_neg_eq.mp (eq.symm h)],
153153
simp only [neg_mul_eq_neg_mul_symm, one_mul] }
154154
end
155155

@@ -233,7 +233,7 @@ lemma nat.prime_iff_prime {p : ℕ} : p.prime ↔ _root_.prime (p : ℕ) :=
233233
by rw [hpb, mul_comm, ← hab, hpb, mul_one]))⟩⟩
234234

235235
lemma nat.prime_iff_prime_int {p : ℕ} : p.prime ↔ _root_.prime (p : ℤ) :=
236-
⟨λ hp, ⟨int.coe_nat_ne_zero_iff_pos.2 hp.pos, mt is_unit_int.1 hp.ne_one,
236+
⟨λ hp, ⟨int.coe_nat_ne_zero_iff_pos.2 hp.pos, mt int.is_unit_iff_nat_abs_eq.1 hp.ne_one,
237237
λ a b h, by rw [← int.dvd_nat_abs, int.coe_nat_dvd, int.nat_abs_mul, hp.dvd_mul] at h;
238238
rwa [← int.dvd_nat_abs, int.coe_nat_dvd, ← int.dvd_nat_abs, int.coe_nat_dvd]⟩,
239239
λ hp, nat.prime_iff_prime.2 ⟨int.coe_nat_ne_zero.1 hp.1,

0 commit comments

Comments
 (0)