Skip to content

Commit d5a4ef2

Browse files
mpenciakjoelrioukim-em
committed
feat: port Algebra.Divisibility.Units (#848)
Mathlib SHA: e574b1a4e891376b0ef974b926da39e05da12a06 - [x] depends on: #833 Co-authored-by: Matej Penciak <96667244+mpenciak@users.noreply.github.com> Co-authored-by: Joël Riou <joel.riou@universite-paris-saclay.fr> Co-authored-by: Scott Morrison <scott.morrison@gmail.com>
1 parent bc09bc5 commit d5a4ef2

File tree

2 files changed

+136
-0
lines changed

2 files changed

+136
-0
lines changed

Mathlib.lean

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import Mathlib.Algebra.Abs
22
import Mathlib.Algebra.CharZero.Defs
33
import Mathlib.Algebra.CovariantAndContravariant
44
import Mathlib.Algebra.Divisibility.Basic
5+
import Mathlib.Algebra.Divisibility.Units
56
import Mathlib.Algebra.Field.Defs
67
import Mathlib.Algebra.Group.Basic
78
import Mathlib.Algebra.Group.Commutator
Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
/-
2+
Copyright (c) 2014 Jeremy Avigad. All rights reserved.
3+
Released under Apache 2.0 license as described in the file LICENSE.
4+
Authors: Jeremy Avigad, Leonardo de Moura, Floris van Doorn, Amelia Livingston, Yury Kudryashov,
5+
Neil Strickland, Aaron Anderson
6+
Ported by: Joël Riou
7+
-/
8+
import Mathlib.Algebra.Divisibility.Basic
9+
import Mathlib.Algebra.Group.Units
10+
11+
/-!
12+
# Lemmas about divisibility and units
13+
-/
14+
15+
variable {α : Type _}
16+
17+
namespace Units
18+
19+
section Monoid
20+
21+
variable [Monoid α] {a b : α} {u : αˣ}
22+
23+
/-- Elements of the unit group of a monoid represented as elements of the monoid
24+
divide any element of the monoid. -/
25+
theorem coe_dvd : ↑u ∣ a :=
26+
⟨↑u⁻¹ * a, by simp⟩
27+
28+
/-- In a monoid, an element `a` divides an element `b` iff `a` divides all
29+
associates of `b`. -/
30+
theorem dvd_mul_right : a ∣ b * u ↔ a ∣ b :=
31+
Iff.intro (fun ⟨c, Eq⟩ ↦ ⟨c * ↑u⁻¹, by rw [← mul_assoc, ← Eq, Units.mul_inv_cancel_right]⟩)
32+
fun ⟨c, Eq⟩ ↦ Eq.symm ▸ (_root_.dvd_mul_right _ _).mul_right _
33+
34+
/-- In a monoid, an element `a` divides an element `b` iff all associates of `a` divide `b`. -/
35+
theorem mul_right_dvd : a * u ∣ b ↔ a ∣ b :=
36+
Iff.intro (fun ⟨c, Eq⟩ => ⟨↑u * c, Eq.trans (mul_assoc _ _ _)⟩) fun h =>
37+
dvd_trans (Dvd.intro (↑u⁻¹) (by rw [mul_assoc, u.mul_inv, mul_one])) h
38+
#align units.mul_right_dvd Units.mul_right_dvd
39+
40+
end Monoid
41+
42+
section CommMonoid
43+
44+
variable [CommMonoid α] {a b : α} {u : αˣ}
45+
46+
/-- In a commutative monoid, an element `a` divides an element `b` iff `a` divides all left
47+
associates of `b`. -/
48+
theorem dvd_mul_left : a ∣ u * b ↔ a ∣ b := by
49+
rw [mul_comm]
50+
apply dvd_mul_right
51+
#align units.dvd_mul_left Units.dvd_mul_left
52+
53+
/-- In a commutative monoid, an element `a` divides an element `b` iff all
54+
left associates of `a` divide `b`.-/
55+
theorem mul_left_dvd : ↑u * a ∣ b ↔ a ∣ b := by
56+
rw [mul_comm]
57+
apply mul_right_dvd
58+
#align units.mul_left_dvd Units.mul_left_dvd
59+
60+
end CommMonoid
61+
62+
end Units
63+
64+
namespace IsUnit
65+
66+
section Monoid
67+
68+
variable [Monoid α] {a b u : α} (hu : IsUnit u)
69+
70+
/-- Units of a monoid divide any element of the monoid. -/
71+
@[simp]
72+
theorem dvd : u ∣ a := by
73+
rcases hu with ⟨u, rfl⟩
74+
apply Units.coe_dvd
75+
76+
@[simp]
77+
theorem dvd_mul_right : a ∣ b * u ↔ a ∣ b := by
78+
rcases hu with ⟨u, rfl⟩
79+
apply Units.dvd_mul_right
80+
81+
/-- In a monoid, an element a divides an element b iff all associates of `a` divide `b`.-/
82+
@[simp]
83+
theorem mul_right_dvd : a * u ∣ b ↔ a ∣ b := by
84+
rcases hu with ⟨u, rfl⟩
85+
apply Units.mul_right_dvd
86+
87+
end Monoid
88+
89+
section CommMonoid
90+
91+
variable [CommMonoid α] (a b u : α) (hu : IsUnit u)
92+
93+
/-- In a commutative monoid, an element `a` divides an element `b` iff `a` divides all left
94+
associates of `b`. -/
95+
@[simp]
96+
theorem dvd_mul_left : a ∣ u * b ↔ a ∣ b := by
97+
rcases hu with ⟨u, rfl⟩
98+
apply Units.dvd_mul_left
99+
100+
/-- In a commutative monoid, an element `a` divides an element `b` iff all
101+
left associates of `a` divide `b`.-/
102+
@[simp]
103+
theorem mul_left_dvd : u * a ∣ b ↔ a ∣ b := by
104+
rcases hu with ⟨u, rfl⟩
105+
apply Units.mul_left_dvd
106+
107+
end CommMonoid
108+
109+
end IsUnit
110+
111+
section CommMonoid
112+
113+
variable [CommMonoid α]
114+
115+
theorem isUnit_iff_dvd_one {x : α} : IsUnit x ↔ x ∣ 1 :=
116+
⟨IsUnit.dvd, fun ⟨y, h⟩ => ⟨⟨x, y, h.symm, by rw [h, mul_comm]⟩, rfl⟩⟩
117+
#align is_unit_iff_dvd_one isUnit_iff_dvd_one
118+
119+
theorem isUnit_iff_forall_dvd {x : α} : IsUnit x ↔ ∀ y, x ∣ y :=
120+
isUnit_iff_dvd_one.trans ⟨fun h _ => h.trans (one_dvd _), fun h => h _⟩
121+
#align is_unit_iff_forall_dvd isUnit_iff_forall_dvd
122+
123+
theorem isUnit_of_dvd_unit {x y : α} (xy : x ∣ y) (hu : IsUnit y) : IsUnit x :=
124+
isUnit_iff_dvd_one.2 <| xy.trans <| isUnit_iff_dvd_one.1 hu
125+
#align is_unit_of_dvd_unit isUnit_of_dvd_unit
126+
127+
theorem isUnit_of_dvd_one {a : α} (h : a ∣ 1) : IsUnit (a : α) :=
128+
isUnit_iff_dvd_one.mpr h
129+
#align is_unit_of_dvd_one isUnit_of_dvd_one
130+
131+
theorem not_isUnit_of_not_isUnit_dvd {a b : α} (ha : ¬IsUnit a) (hb : a ∣ b) : ¬IsUnit b :=
132+
mt (isUnit_of_dvd_unit hb) ha
133+
#align not_is_unit_of_not_is_unit_dvd not_isUnit_of_not_isUnit_dvd
134+
135+
end CommMonoid

0 commit comments

Comments
 (0)