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

Commit cc2e1ec

Browse files
kckennylaudigama0
authored andcommitted
refactor(*): making mathlib faster again
1 parent 136ef25 commit cc2e1ec

22 files changed

+2499
-2216
lines changed

algebra/archimedean.lean

Lines changed: 24 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class floor_ring (α) extends linear_ordered_ring α :=
1616
(le_floor : ∀ (z : ℤ) (x : α), z ≤ floor x ↔ (z : α) ≤ x)
1717

1818
instance : floor_ring ℤ :=
19-
{ floor := id, le_floor := by simp,
19+
{ floor := id, le_floor := λ _ _, by rw int.cast_id; refl,
2020
..linear_ordered_comm_ring.to_linear_ordered_ring ℤ }
2121

2222
instance : floor_ring ℚ :=
@@ -40,13 +40,13 @@ theorem floor_le (x : α) : (⌊x⌋ : α) ≤ x :=
4040
le_floor.1 (le_refl _)
4141

4242
theorem floor_nonneg {x : α} : 0 ≤ ⌊x⌋ ↔ 0 ≤ x :=
43-
by simpa using @le_floor _ _ 0 x
43+
by rw [le_floor]; refl
4444

4545
theorem lt_succ_floor (x : α) : x < ⌊x⌋.succ :=
4646
floor_lt.1 $ int.lt_succ_self _
4747

4848
theorem lt_floor_add_one (x : α) : x < ⌊x⌋ + 1 :=
49-
by simpa [int.succ] using lt_succ_floor x
49+
by simpa only [int.succ, int.cast_add, int.cast_one] using lt_succ_floor x
5050

5151
theorem sub_one_lt_floor (x : α) : x - 1 < ⌊x⌋ :=
5252
sub_lt_iff_lt_add.2 (lt_floor_add_one x)
@@ -108,9 +108,7 @@ lemma ceil_pos {a : α} : 0 < ⌈a⌉ ↔ 0 < a :=
108108

109109
lemma ceil_nonneg [decidable_rel ((<) : α → α → Prop)] {q : α} (hq : q ≥ 0) : ⌈q⌉ ≥ 0 :=
110110
if h : q > 0 then le_of_lt $ ceil_pos.2 h
111-
else
112-
have h' : q = 0, from le_antisymm (le_of_not_lt h) hq,
113-
by simp [h']
111+
else by rw [le_antisymm (le_of_not_lt h) hq, ceil_zero]; trivial
114112

115113
end
116114

@@ -120,7 +118,7 @@ class archimedean (α) [ordered_comm_monoid α] : Prop :=
120118
theorem exists_nat_gt [linear_ordered_semiring α] [archimedean α]
121119
(x : α) : ∃ n : ℕ, x < n :=
122120
let ⟨n, h⟩ := archimedean.arch x zero_lt_one in
123-
⟨n+1, lt_of_le_of_lt (by simpa using h)
121+
⟨n+1, lt_of_le_of_lt (by rwa ← add_monoid.smul_one)
124122
(nat.cast_lt.2 (nat.lt_succ_self _))⟩
125123

126124
section linear_ordered_ring
@@ -135,10 +133,10 @@ let ⟨n, h⟩ := archimedean.arch x hy0 in
135133
... ≤ y ^ n : pow_ge_one_add_sub_mul (le_of_lt hy1) _⟩
136134

137135
theorem exists_int_gt (x : α) : ∃ n : ℤ, x < n :=
138-
let ⟨n, h⟩ := exists_nat_gt x in ⟨n, by simp [h]
136+
let ⟨n, h⟩ := exists_nat_gt x in ⟨n, by rwa ← coe_coe
139137

140138
theorem exists_int_lt (x : α) : ∃ n : ℤ, (n : α) < x :=
141-
let ⟨n, h⟩ := exists_int_gt (-x) in ⟨-n, by simp [neg_lt.1 h]
139+
let ⟨n, h⟩ := exists_int_gt (-x) in ⟨-n, by rw int.cast_neg; exact neg_lt.1 h⟩
142140

143141
theorem exists_floor (x : α) :
144142
∃ (fl : ℤ), ∀ (z : ℤ), z ≤ fl ↔ (z : α) ≤ x :=
@@ -157,15 +155,12 @@ end
157155
end linear_ordered_ring
158156

159157
instance : archimedean ℕ :=
160-
⟨λ n m m0, ⟨n, by simpa using nat.mul_le_mul_left n m0⟩⟩
158+
⟨λ n m m0, ⟨n, by simpa only [mul_one, nat.smul_eq_mul] using nat.mul_le_mul_left n m0⟩⟩
161159

162160
instance : archimedean ℤ :=
163-
⟨λ n m m0, ⟨n.to_nat, begin
164-
simp [add_monoid.smul_eq_mul],
165-
refine le_trans (int.le_to_nat _) _,
166-
simpa using mul_le_mul_of_nonneg_left
167-
(int.add_one_le_iff.2 m0) (int.coe_zero_le n.to_nat),
168-
end⟩⟩
161+
⟨λ n m m0, ⟨n.to_nat, le_trans (int.le_to_nat _) $
162+
by simpa only [add_monoid.smul_eq_mul, int.nat_cast_eq_coe_nat, zero_add, mul_one] using mul_le_mul_of_nonneg_left
163+
(int.add_one_le_iff.2 m0) (int.coe_zero_le n.to_nat)⟩⟩
169164

170165
noncomputable def archimedean.floor_ring (α)
171166
[linear_ordered_ring α] [archimedean α] : floor_ring α :=
@@ -189,15 +184,15 @@ archimedean_iff_nat_lt.trans
189184
lt_of_le_of_lt h (nat.cast_lt.2 (lt_add_one _))⟩⟩
190185

191186
theorem exists_rat_gt [archimedean α] (x : α) : ∃ q : ℚ, x < q :=
192-
let ⟨n, h⟩ := exists_nat_gt x in ⟨n, by simp [h]
187+
let ⟨n, h⟩ := exists_nat_gt x in ⟨n, by rwa rat.cast_coe_nat
193188

194189
theorem archimedean_iff_rat_lt :
195190
archimedean α ↔ ∀ x : α, ∃ q : ℚ, x < q :=
196191
⟨@exists_rat_gt α _,
197192
λ H, archimedean_iff_nat_lt.2 $ λ x,
198193
let ⟨q, h⟩ := H x in
199194
⟨rat.nat_ceil q, lt_of_lt_of_le h $
200-
by simpa using (@rat.cast_le α _ _ _).2 (rat.le_nat_ceil _)⟩⟩
195+
by simpa only [rat.cast_coe_nat] using (@rat.cast_le α _ _ _).2 (rat.le_nat_ceil _)⟩⟩
201196

202197
theorem archimedean_iff_rat_le :
203198
archimedean α ↔ ∀ x : α, ∃ q : ℚ, x ≤ q :=
@@ -209,30 +204,25 @@ archimedean_iff_rat_lt.trans
209204
variable [archimedean α]
210205

211206
theorem exists_rat_lt (x : α) : ∃ q : ℚ, (q : α) < x :=
212-
let ⟨n, h⟩ := exists_int_lt x in ⟨n, by simp [h]⟩
213-
214-
theorem exists_pos_rat_lt {x : α} (x0 : 0 < x) : ∃ q : ℚ, 0 < q ∧ (q : α) < x :=
215-
let ⟨n, h⟩ := exists_nat_gt x⁻¹ in begin
216-
have n0 := nat.cast_pos.1 (lt_trans (inv_pos x0) h),
217-
refine ⟨n⁻¹, inv_pos (nat.cast_pos.2 n0), _⟩,
218-
simpa [rat.cast_inv_of_ne_zero, ne_of_gt n0] using
219-
(inv_lt x0 (nat.cast_pos.2 n0)).1 h
220-
end
207+
let ⟨n, h⟩ := exists_int_lt x in ⟨n, by rwa rat.cast_coe_int⟩
221208

222209
theorem exists_rat_btwn {x y : α} (h : x < y) : ∃ q : ℚ, x < q ∧ (q:α) < y :=
223210
begin
224211
cases exists_nat_gt (y - x)⁻¹ with n nh,
225212
cases exists_floor (x * n) with z zh,
226213
refine ⟨(z + 1 : ℤ) / n, _⟩,
227214
have n0 := nat.cast_pos.1 (lt_trans (inv_pos (sub_pos.2 h)) nh),
228-
simp [rat.cast_div_of_ne_zero, -int.cast_add, ne_of_gt n0],
229215
have n0' := (@nat.cast_pos α _ _).2 n0,
216+
rw [rat.cast_div_of_ne_zero, rat.cast_coe_nat, rat.cast_coe_int, div_lt_iff n0'],
230217
refine ⟨(lt_div_iff n0').2 $
231218
(le_iff_le_iff_lt_iff_lt.1 (zh _)).1 (lt_add_one _), _⟩,
232-
simp [div_lt_iff n0', -add_comm],
219+
rw [int.cast_add, int.cast_one],
233220
refine lt_of_le_of_lt (add_le_add_right ((zh _).1 (le_refl _)) _) _,
234221
rwa [← lt_sub_iff_add_lt', ← sub_mul,
235-
← div_lt_iff' (sub_pos.2 h), one_div_eq_inv]
222+
← div_lt_iff' (sub_pos.2 h), one_div_eq_inv],
223+
{ rw [rat.coe_int_denom, nat.cast_one], exact one_ne_zero },
224+
{ intro H, rw [rat.coe_nat_num, ← coe_coe, nat.cast_eq_zero] at H, subst H, cases n0 },
225+
{ rw [rat.coe_nat_denom, nat.cast_one], exact one_ne_zero }
236226
end
237227

238228
theorem exists_nat_one_div_lt {ε : α} (hε : ε > 0) : ∃ n : ℕ, 1 / (n + 1: α) < ε :=
@@ -247,6 +237,9 @@ begin
247237
{ simp [zero_lt_one] }}
248238
end
249239

240+
theorem exists_pos_rat_lt {x : α} (x0 : 0 < x) : ∃ q : ℚ, 0 < q ∧ (q : α) < x :=
241+
by simpa only [rat.cast_pos] using exists_rat_btwn x0
242+
250243
include α
251244
@[simp] theorem rat.cast_floor (x : ℚ) :
252245
by haveI := archimedean.floor_ring α; exact ⌊(x:α)⌋ = ⌊x⌋ :=
@@ -273,4 +266,4 @@ let ⟨q, h₁, h₂⟩ := exists_rat_btwn $
273266
end
274267

275268
instance : archimedean ℚ :=
276-
archimedean_iff_rat_le.2 $ λ q, ⟨q, by simp
269+
archimedean_iff_rat_le.2 $ λ q, ⟨q, by rw rat.cast_id

0 commit comments

Comments
 (0)