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

Commit 20fe4a1

Browse files
committed
feat(algebra/euclidean_domain): some cleanup (#3752)
Lower the priority of simp-lemmas which have an equivalent version in `group_with_zero`, so that the version of `group_with_zero` is found by `squeeze_simp` for types that have both structures. Add docstrings Remove outdated comment
1 parent 490d3ce commit 20fe4a1

File tree

3 files changed

+20
-14
lines changed

3 files changed

+20
-14
lines changed

src/algebra/euclidean_domain.lean

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,24 +14,18 @@ universe u
1414
section prio
1515
set_option default_priority 100 -- see Note [default priority]
1616
set_option old_structure_cmd true
17+
/-- A Euclidean domain is an integral domain with quotient and remainder functions-/
1718
@[protect_proj without mul_left_not_lt r_well_founded]
1819
class euclidean_domain (α : Type u) extends comm_ring α, nontrivial α :=
1920
(quotient : α → α → α)
2021
(quotient_zero : ∀ a, quotient a 0 = 0)
2122
(remainder : α → α → α)
2223
-- This could be changed to the same order as int.mod_add_div.
23-
-- We normally write qb+r rather than r + qb though.
24+
-- We normally write `qb+r` rather than `r + qb` though.
2425
(quotient_mul_add_remainder_eq : ∀ a b, b * quotient a b + remainder a b = a)
2526
(r : α → α → Prop)
2627
(r_well_founded : well_founded r)
2728
(remainder_lt : ∀ a {b}, b ≠ 0 → r (remainder a b) b)
28-
/- `val_le_mul_left` is often not a required in definitions of a euclidean
29-
domain since given the other properties we can show there is a
30-
(noncomputable) euclidean domain α with the property `val_le_mul_left`.
31-
So potentially this definition could be split into two different ones
32-
(euclidean_domain_weak and euclidean_domain_strong) with a noncomputable
33-
function from weak to strong. I've currently divided the lemmas into
34-
strong and weak depending on whether they require `val_le_mul_left` or not. -/
3529
(mul_left_not_lt : ∀ a {b}, b ≠ 0 → ¬r (a * b) a)
3630
end prio
3731

@@ -104,15 +98,15 @@ mod_eq_zero.2 (one_dvd _)
10498
@[simp] lemma zero_mod (b : α) : 0 % b = 0 :=
10599
mod_eq_zero.2 (dvd_zero _)
106100

107-
@[simp] lemma div_zero (a : α) : a / 0 = 0 :=
101+
@[simp, priority 900] lemma div_zero (a : α) : a / 0 = 0 :=
108102
euclidean_domain.quotient_zero a
109103

110-
@[simp] lemma zero_div {a : α} : 0 / a = 0 :=
104+
@[simp, priority 900] lemma zero_div {a : α} : 0 / a = 0 :=
111105
classical.by_cases
112106
(λ a0 : a = 0, a0.symm ▸ div_zero 0)
113107
(λ a0, by simpa only [zero_mul] using mul_div_cancel 0 a0)
114108

115-
@[simp] lemma div_self {a : α} (a0 : a ≠ 0) : a / a = 1 :=
109+
@[simp, priority 900] lemma div_self {a : α} (a0 : a ≠ 0) : a / a = 1 :=
116110
by simpa only [one_mul] using mul_div_cancel 1 a0
117111

118112
lemma eq_div_of_mul_eq_left {a b c : α} (hb : b ≠ 0) (h : a * b = c) : a = c / b :=
@@ -148,6 +142,8 @@ end
148142
section gcd
149143
variable [decidable_eq α]
150144

145+
/-- The greatest common denominator of two elements of a Euclidean domain.
146+
It is defined using the Euclidean algorithm. -/
151147
def gcd : α → α → α
152148
| a := λ b, if a0 : a = 0 then b else
153149
have h:_ := mod_lt b a0,
@@ -195,6 +191,16 @@ gcd_eq_left.2 (one_dvd _)
195191
@[simp] theorem gcd_self (a : α) : gcd a a = a :=
196192
gcd_eq_left.2 (dvd_refl _)
197193

194+
/--
195+
An implementation of the extended GCD algorithm.
196+
At each step we are computing a triple `(r, s, t)`, where `r` is the next value of the GCD
197+
algorithm, to compute the greatest common divisor of the input (say `x` and `y`), and `s` and `t`
198+
are the coefficients in front of `x` and `y` to obtain `r` (i.e. `r = s * x + t * y`).
199+
The function `xgcd_aux` takes in two triples, and from these recursively computes the next triple:
200+
```
201+
xgcd_aux (r, s, t) (r', s', t') = xgcd_aux (r' % r, s' - (r' / r) * s, t' - (r' / r) * t) (r, s, t)
202+
```
203+
-/
198204
def xgcd_aux : α → α → α → α → α → α → α × α × α
199205
| r := λ s t r' s' t',
200206
if hr : r = 0 then (r', s', t')
@@ -261,6 +267,7 @@ end gcd
261267
section lcm
262268
variables [decidable_eq α]
263269

270+
/-- The least common multiple of two elements of a Euclidean domain. -/
264271
def lcm (x y : α) : α :=
265272
x * y / gcd x y
266273

src/analysis/special_functions/trigonometric.lean

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1408,8 +1408,7 @@ else
14081408
lemma tan_arg {x : ℂ} : real.tan (arg x) = x.im / x.re :=
14091409
begin
14101410
by_cases h : x = 0,
1411-
{ simp only [h, euclidean_domain.zero_div,
1412-
complex.zero_im, complex.arg_zero, real.tan_zero, complex.zero_re] },
1411+
{ simp only [h, zero_div, complex.zero_im, complex.arg_zero, real.tan_zero, complex.zero_re] },
14131412
rw [real.tan_eq_sin_div_cos, sin_arg, cos_arg h,
14141413
div_div_div_cancel_right _ (mt abs_eq_zero.1 h)]
14151414
end

src/analysis/specific_limits.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -697,7 +697,7 @@ lemma self_div_two_le_harmonic_two_pow (n : ℕ) : (n / 2 : ℝ) ≤ harmonic_se
697697
begin
698698
induction n with n hn,
699699
unfold harmonic_series,
700-
simp only [one_div, nat.cast_zero, euclidean_domain.zero_div, nat.cast_succ, sum_singleton,
700+
simp only [one_div, nat.cast_zero, zero_div, nat.cast_succ, sum_singleton,
701701
inv_one, zero_add, nat.pow_zero, range_one, zero_le_one],
702702
have : harmonic_series (2^n) + 1 / 2 ≤ harmonic_series (2^(n+1)),
703703
{ have := half_le_harmonic_double_sub_harmonic (2^n) (by {apply nat.pow_pos, linarith}),

0 commit comments

Comments
 (0)