Skip to content

Commit 3eb1a69

Browse files
committed
feat(Algebra/Divisibility/Basic): introduce right division (RightDvd)
1 parent 3dc6b88 commit 3eb1a69

1 file changed

Lines changed: 67 additions & 0 deletions

File tree

Mathlib/Algebra/Divisibility/Basic.lean

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,57 @@ theorem mul_dvd_mul_left (a : α) (h : b ∣ c) : a * b ∣ a * c := by
110110
theorem IsLeftRegular.dvd_cancel_left (h : IsLeftRegular a) : a * b ∣ a * c ↔ b ∣ c :=
111111
fun dvd ↦ have ⟨d, eq⟩ := dvd; ⟨d, h (eq.trans <| mul_assoc ..)⟩, mul_dvd_mul_left a⟩
112112

113+
/-- Right divisibility relation. `RightDvd a b` means `a` right-divides `b`,
114+
i.e., `∃ c, b = c * a`. -/
115+
def RightDvd (a b : α) : Prop := ∃ c, b = c * a
116+
117+
theorem RightDvd.intro (c : α) (h : c * a = b) : RightDvd a b :=
118+
Exists.intro c h.symm
119+
120+
alias rightDvd_of_mul_left_eq := RightDvd.intro
121+
122+
theorem exists_eq_mul_left_of_rightDvd (h : RightDvd a b) : ∃ c, b = c * a :=
123+
h
124+
125+
theorem rightDvd_def : RightDvd a b ↔ ∃ c, b = c * a :=
126+
Iff.rfl
127+
128+
alias rightDvd_iff_exists_eq_mul_left := rightDvd_def
129+
130+
theorem RightDvd.elim {P : Prop} {a b : α} (H₁ : RightDvd a b) (H₂ : ∀ c, b = c * a → P) : P :=
131+
Exists.elim H₁ H₂
132+
133+
@[trans]
134+
theorem rightDvd_trans : RightDvd a b → RightDvd b c → RightDvd a c
135+
| ⟨d, h₁⟩, ⟨e, h₂⟩ => ⟨e * d, h₁ ▸ h₂.trans <| (mul_assoc e d a).symm⟩
136+
137+
/-- Transitivity of `RightDvd` for use in `calc` blocks. -/
138+
instance : IsTrans α RightDvd :=
139+
fun _ _ _ => rightDvd_trans⟩
140+
141+
@[simp]
142+
theorem rightDvd_mul_left (a b : α) : RightDvd a (b * a) :=
143+
RightDvd.intro b rfl
144+
145+
theorem rightDvd_mul_of_rightDvd_right (h : RightDvd a b) (c : α) : RightDvd a (c * b) :=
146+
rightDvd_trans h (rightDvd_mul_left b c)
147+
148+
alias RightDvd.mul_left := rightDvd_mul_of_rightDvd_right
149+
150+
theorem rightDvd_of_mul_left_rightDvd (h : RightDvd (b * a) c) : RightDvd a c :=
151+
rightDvd_trans (rightDvd_mul_left a b) h
152+
153+
@[gcongr]
154+
theorem mul_rightDvd_mul_right (a : α) (h : RightDvd b c) : RightDvd (b * a) (c * a) := by
155+
obtain ⟨d, rfl⟩ := h
156+
use d
157+
rw [mul_assoc]
158+
159+
theorem IsRightRegular.rightDvd_cancel_right (h : IsRightRegular a) :
160+
RightDvd (b * a) (c * a) ↔ RightDvd b c :=
161+
fun dvd ↦ have ⟨d, eq⟩ := dvd
162+
⟨d, h (eq.trans <| (mul_assoc ..).symm)⟩, mul_rightDvd_mul_right a⟩
163+
113164
end Semigroup
114165

115166
section Monoid
@@ -143,6 +194,19 @@ alias Dvd.dvd.pow := dvd_pow
143194

144195
lemma dvd_pow_self (a : α) {n : ℕ} (hn : n ≠ 0) : a ∣ a ^ n := dvd_rfl.pow hn
145196

197+
@[refl, simp]
198+
theorem rightDvd_refl (a : α) : RightDvd a a :=
199+
RightDvd.intro 1 (one_mul a)
200+
201+
theorem rightDvd_rfl : ∀ {a : α}, RightDvd a a := fun {a} => rightDvd_refl a
202+
203+
instance : @Std.Refl α RightDvd :=
204+
⟨rightDvd_refl⟩
205+
206+
theorem rightDvd_of_eq (h : a = b) : RightDvd a b := by rw [h]
207+
208+
alias Eq.rightDvd := rightDvd_of_eq
209+
146210
end Monoid
147211

148212
section CommSemigroup
@@ -189,6 +253,9 @@ theorem dvd_mul [DecompositionMonoid α] {k m n : α} :
189253
rintro ⟨d₁, d₂, hy, hz, rfl⟩
190254
gcongr
191255

256+
theorem rightDvd_iff_dvd : RightDvd a b ↔ a ∣ b :=
257+
fun ⟨c, hc⟩ ↦ ⟨c, by rw [hc, mul_comm]⟩, fun ⟨c, hc⟩ ↦ ⟨c, by rw [hc, mul_comm]⟩⟩
258+
192259
end CommSemigroup
193260

194261
section CommMonoid

0 commit comments

Comments
 (0)