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

Commit d245165

Browse files
committed
refactor(algebra): add more facts about units
1 parent b4b05dd commit d245165

File tree

3 files changed

+50
-11
lines changed

3 files changed

+50
-11
lines changed

algebra/field.lean

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@ open set
99
universe u
1010
variables {α : Type u}
1111

12+
instance division_ring.to_domain [s : division_ring α] : domain α :=
13+
{ eq_zero_or_eq_zero_of_mul_eq_zero := λ a b h,
14+
classical.by_contradiction $ λ hn,
15+
division_ring.mul_ne_zero (mt or.inl hn) (mt or.inr hn) h
16+
..s }
17+
1218
namespace units
1319
variables [division_ring α] {a b : α}
1420

@@ -19,9 +25,6 @@ variables [division_ring α] {a b : α}
1925
def mk0 (a : α) (ha : a ≠ 0) : units α :=
2026
⟨a, a⁻¹, mul_inv_cancel ha, inv_mul_cancel ha⟩
2127

22-
@[simp] theorem ne_zero (u : units α) : (u : α) ≠ 0
23-
| h := by simpa [h] using inv_mul u
24-
2528
@[simp] theorem inv_eq_inv (u : units α) : (↑u⁻¹ : α) = u⁻¹ :=
2629
(mul_left_inj u).1 $ by simp
2730

@@ -35,12 +38,6 @@ section division_ring
3538
variables [s : division_ring α] {a b c : α}
3639
include s
3740

38-
instance division_ring.to_domain : domain α :=
39-
{ eq_zero_or_eq_zero_of_mul_eq_zero := λ a b h,
40-
classical.by_contradiction $ λ hn,
41-
division_ring.mul_ne_zero (mt or.inl hn) (mt or.inr hn) h
42-
..s }
43-
4441
lemma div_eq_mul_inv : a / b = a * b⁻¹ := rfl
4542

4643
attribute [simp] div_one zero_div div_self

algebra/group.lean

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,9 @@ units.ext begin
267267
simpa using nat.mul_le_mul_left u h'
268268
end
269269

270+
def units.mk_of_mul_eq_one [comm_monoid α] (a b : α) (hab : a * b = 1) : units α :=
271+
⟨a, b, hab, by rwa mul_comm a b at hab⟩
272+
270273
@[to_additive with_zero]
271274
def with_one (α) := option α
272275

algebra/ring.lean

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@ end
2121
namespace units
2222
variables [ring α] {a b : α}
2323

24-
instance : has_neg (units α) :=
25-
⟨λ u, ⟨-u.val, -u.inv, by simp [u.val_inv], by simp [u.inv_val]⟩⟩
24+
instance : has_neg (units α) := ⟨λu, ⟨-↑u, -↑u⁻¹, by simp, by simp⟩ ⟩
2625

2726
@[simp] protected theorem coe_neg (u : units α) : (↑-u : α) = -u := rfl
2827

@@ -83,6 +82,11 @@ instance comp {γ} [semiring γ] (g : β → γ) [is_semiring_hom g] :
8382

8483
end is_semiring_hom
8584

85+
@[simp] lemma zero_dvd_iff_eq_zero [comm_semiring α] (a : α) : 0 ∣ a ↔ a = 0 :=
86+
iff.intro
87+
eq_zero_of_zero_dvd
88+
(assume ha, ha ▸ dvd_refl a)
89+
8690
section
8791
variables [ring α] (a b c d e : α)
8892

@@ -232,3 +236,38 @@ section
232236
exists_congr $ λ d, by rw [mul_right_comm, domain.mul_right_inj hc]
233237

234238
end
239+
240+
/- units in various rings -/
241+
242+
namespace units
243+
244+
section comm_semiring
245+
variables [comm_semiring α] (a b : α) (u : units α)
246+
247+
@[simp] lemma coe_dvd : ↑u ∣ a := ⟨↑u⁻¹ * a, by simp⟩
248+
249+
@[simp] lemma dvd_coe_mul : a ∣ b * u ↔ a ∣ b :=
250+
iff.intro
251+
(assume ⟨c, eq⟩, ⟨c * ↑u⁻¹, by rw [← mul_assoc, ← eq, units.mul_inv_cancel_right]⟩)
252+
(assume ⟨c, eq⟩, eq.symm ▸ dvd_mul_of_dvd_left (dvd_mul_right _ _) _)
253+
254+
@[simp] lemma dvd_coe : a ∣ ↑u ↔ a ∣ 1 :=
255+
suffices a ∣ 1 * ↑u ↔ a ∣ 1, by simpa,
256+
dvd_coe_mul _ _ _
257+
258+
@[simp] lemma coe_mul_dvd : a * u ∣ b ↔ a ∣ b :=
259+
iff.intro
260+
(assume ⟨c, eq⟩, ⟨c * ↑u, eq.symm ▸ by ac_refl⟩)
261+
(assume h, suffices a * ↑u ∣ b * 1, by simpa, mul_dvd_mul h (coe_dvd _ _))
262+
263+
end comm_semiring
264+
265+
section domain
266+
variables [domain α]
267+
268+
@[simp] theorem ne_zero : ∀(u : units α), (↑u : α) ≠ 0
269+
| ⟨u, v, (huv : 0 * v = 1), hvu⟩ rfl := by simpa using huv
270+
271+
end domain
272+
273+
end units

0 commit comments

Comments
 (0)