Skip to content

Commit f34cd07

Browse files
mattrobballkim-em
andcommitted
perf (CategoryTheory.ComposableArrows): swap out linarith for omega (#9594)
This file now has the lead in the number of CPU instructions amongst all of mathlib. The majority come from `linarith` being an `autoparam` for many definitions, often in multiple arguments. This uses `omega` in place of `linarith` to improve performance. Co-authored-by: Scott Morrison <scott.morrison@gmail.com>
1 parent e4eb07a commit f34cd07

File tree

3 files changed

+76
-74
lines changed

3 files changed

+76
-74
lines changed

Mathlib/Algebra/Homology/ExactSequence.lean

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -44,16 +44,16 @@ variable {n : ℕ} (S : ComposableArrows C n)
4444
two consecutive arrows are zero. -/
4545
structure IsComplex : Prop where
4646
/-- the composition of two consecutive arrows is zero -/
47-
zero (i : ℕ) (hi : i + 2 ≤ n := by linarith) :
47+
zero (i : ℕ) (hi : i + 2 ≤ n := by omega) :
4848
S.map' i (i + 1) ≫ S.map' (i + 1) (i + 2) = 0
4949

5050
attribute [reassoc] IsComplex.zero
5151

5252
variable {S}
5353

5454
@[reassoc]
55-
lemma IsComplex.zero' (hS : S.IsComplex) (i j k : ℕ) (hij : i + 1 = j := by linarith)
56-
(hjk : j + 1 = k := by linarith) (hk : k ≤ n := by linarith) :
55+
lemma IsComplex.zero' (hS : S.IsComplex) (i j k : ℕ) (hij : i + 1 = j := by omega)
56+
(hjk : j + 1 = k := by omega) (hk : k ≤ n := by omega) :
5757
S.map' i j ≫ S.map' j k = 0 := by
5858
subst hij hjk
5959
exact hS.zero i hk
@@ -75,42 +75,42 @@ lemma isComplex₀ (S : ComposableArrows C 0) : S.IsComplex where
7575
zero i hi := by simp (config := {decide := true}) at hi
7676

7777
lemma isComplex₁ (S : ComposableArrows C 1) : S.IsComplex where
78-
zero i hi := by exfalso; linarith
78+
zero i hi := by exfalso; omega
7979

8080
variable (S)
8181

8282
/-- The short complex consisting of maps `S.map' i j` and `S.map' j k` when we know
8383
that `S : ComposableArrows C n` satisfies `S.IsComplex`. -/
8484
@[reducible]
85-
def sc' (hS : S.IsComplex) (i j k : ℕ) (hij : i + 1 = j := by linarith)
86-
(hjk : j + 1 = k := by linarith) (hk : k ≤ n := by linarith) :
85+
def sc' (hS : S.IsComplex) (i j k : ℕ) (hij : i + 1 = j := by omega)
86+
(hjk : j + 1 = k := by omega) (hk : k ≤ n := by omega) :
8787
ShortComplex C :=
8888
ShortComplex.mk (S.map' i j) (S.map' j k) (hS.zero' i j k)
8989

9090
/-- The short complex consisting of maps `S.map' i (i + 1)` and `S.map' (i + 1) (i + 2)`
9191
when we know that `S : ComposableArrows C n` satisfies `S.IsComplex`. -/
92-
abbrev sc (hS : S.IsComplex) (i : ℕ) (hi : i + 2 ≤ n := by linarith) :
92+
abbrev sc (hS : S.IsComplex) (i : ℕ) (hi : i + 2 ≤ n := by omega) :
9393
ShortComplex C :=
9494
S.sc' hS i (i + 1) (i + 2)
9595

9696
/-- `F : ComposableArrows C n` is exact if it is a complex and that all short
9797
complexes consisting of two consecutive arrows are exact. -/
9898
structure Exact extends S.IsComplex : Prop where
99-
exact (i : ℕ) (hi : i + 2 ≤ n := by linarith) : (S.sc toIsComplex i).Exact
99+
exact (i : ℕ) (hi : i + 2 ≤ n := by omega) : (S.sc toIsComplex i).Exact
100100

101101
variable {S}
102102

103-
lemma Exact.exact' (hS : S.Exact) (i j k : ℕ) (hij : i + 1 = j := by linarith)
104-
(hjk : j + 1 = k := by linarith) (hk : k ≤ n := by linarith) :
103+
lemma Exact.exact' (hS : S.Exact) (i j k : ℕ) (hij : i + 1 = j := by omega)
104+
(hjk : j + 1 = k := by omega) (hk : k ≤ n := by omega) :
105105
(S.sc' hS.toIsComplex i j k).Exact := by
106106
subst hij hjk
107107
exact hS.exact i hk
108108

109109
/-- Functoriality maps for `ComposableArrows.sc'`. -/
110110
@[simps]
111111
def sc'Map {S₁ S₂ : ComposableArrows C n} (φ : S₁ ⟶ S₂) (h₁ : S₁.IsComplex) (h₂ : S₂.IsComplex)
112-
(i j k : ℕ) (hij : i + 1 = j := by linarith)
113-
(hjk : j + 1 = k := by linarith) (hk : k ≤ n := by linarith) :
112+
(i j k : ℕ) (hij : i + 1 = j := by omega)
113+
(hjk : j + 1 = k := by omega) (hk : k ≤ n := by omega) :
114114
S₁.sc' h₁ i j k ⟶ S₂.sc' h₂ i j k where
115115
τ₁ := φ.app _
116116
τ₂ := φ.app _
@@ -119,16 +119,16 @@ def sc'Map {S₁ S₂ : ComposableArrows C n} (φ : S₁ ⟶ S₂) (h₁ : S₁.
119119
/-- Functoriality maps for `ComposableArrows.sc`. -/
120120
@[simps!]
121121
def scMap {S₁ S₂ : ComposableArrows C n} (φ : S₁ ⟶ S₂) (h₁ : S₁.IsComplex) (h₂ : S₂.IsComplex)
122-
(i : ℕ) (hi : i + 2 ≤ n := by linarith) :
122+
(i : ℕ) (hi : i + 2 ≤ n := by omega) :
123123
S₁.sc h₁ i ⟶ S₂.sc h₂ i :=
124124
sc'Map φ h₁ h₂ i (i + 1) (i + 2)
125125

126126
/-- The isomorphism `S₁.sc' _ i j k ≅ S₂.sc' _ i j k` induced by an isomorphism `S₁ ≅ S₂`
127127
in `ComposableArrows C n`. -/
128128
@[simps]
129129
def sc'MapIso {S₁ S₂ : ComposableArrows C n} (e : S₁ ≅ S₂)
130-
(h₁ : S₁.IsComplex) (h₂ : S₂.IsComplex) (i j k : ℕ) (hij : i + 1 = j := by linarith)
131-
(hjk : j + 1 = k := by linarith) (hk : k ≤ n := by linarith) :
130+
(h₁ : S₁.IsComplex) (h₂ : S₂.IsComplex) (i j k : ℕ) (hij : i + 1 = j := by omega)
131+
(hjk : j + 1 = k := by omega) (hk : k ≤ n := by omega) :
132132
S₁.sc' h₁ i j k ≅ S₂.sc' h₂ i j k where
133133
hom := sc'Map e.hom h₁ h₂ i j k
134134
inv := sc'Map e.inv h₂ h₁ i j k
@@ -140,7 +140,7 @@ in `ComposableArrows C n`. -/
140140
@[simps]
141141
def scMapIso {S₁ S₂ : ComposableArrows C n} (e : S₁ ≅ S₂)
142142
(h₁ : S₁.IsComplex) (h₂ : S₂.IsComplex)
143-
(i : ℕ) (hi : i + 2 ≤ n := by linarith) :
143+
(i : ℕ) (hi : i + 2 ≤ n := by omega) :
144144
S₁.sc h₁ i ≅ S₂.sc h₂ i where
145145
hom := scMap e.hom h₁ h₂ i
146146
inv := scMap e.inv h₂ h₁ i
@@ -164,16 +164,16 @@ lemma exact₀ (S : ComposableArrows C 0) : S.Exact where
164164

165165
lemma exact₁ (S : ComposableArrows C 1) : S.Exact where
166166
toIsComplex := S.isComplex₁
167-
exact i hi := by exfalso; linarith
167+
exact i hi := by exfalso; omega
168168

169169
lemma isComplex₂_iff (S : ComposableArrows C 2) :
170170
S.IsComplex ↔ S.map' 0 1 ≫ S.map' 1 2 = 0 := by
171171
constructor
172172
· intro h
173-
exact h.zero 0 (by linarith)
173+
exact h.zero 0 (by omega)
174174
· intro h
175175
refine' IsComplex.mk (fun i hi => _)
176-
obtain rfl : i = 0 := by linarith
176+
obtain rfl : i = 0 := by omega
177177
exact h
178178

179179
lemma isComplex₂_mk (S : ComposableArrows C 2) (w : S.map' 0 1 ≫ S.map' 1 2 = 0) :
@@ -188,10 +188,10 @@ lemma exact₂_iff (S : ComposableArrows C 2) (hS : S.IsComplex) :
188188
S.Exact ↔ (S.sc' hS 0 1 2).Exact := by
189189
constructor
190190
· intro h
191-
exact h.exact 0 (by linarith)
191+
exact h.exact 0 (by omega)
192192
· intro h
193193
refine' Exact.mk hS (fun i hi => _)
194-
obtain rfl : i = 0 := by linarith
194+
obtain rfl : i = 0 := by omega
195195
exact h
196196

197197
lemma exact₂_mk (S : ComposableArrows C 2) (w : S.map' 0 1 ≫ S.map' 1 2 = 0)
@@ -216,7 +216,7 @@ lemma exact_iff_δ₀ (S : ComposableArrows C (n + 2)) :
216216
· rw [exact₂_iff]; swap
217217
· rw [isComplex₂_iff]
218218
exact h.toIsComplex.zero 0
219-
exact h.exact 0 (by linarith)
219+
exact h.exact 0 (by omega)
220220
· exact Exact.mk (IsComplex.mk (fun i hi => h.toIsComplex.zero (i + 1)))
221221
(fun i hi => h.exact (i + 1))
222222
· rintro ⟨h, h₀⟩
@@ -247,13 +247,13 @@ lemma exact_iff_δlast {n : ℕ} (S : ComposableArrows C (n + 2)) :
247247
· rw [exact₂_iff]; swap
248248
· rw [isComplex₂_iff]
249249
exact h.toIsComplex.zero n
250-
exact h.exact n (by linarith)
250+
exact h.exact n (by omega)
251251
· rintro ⟨h, h'⟩
252252
refine' Exact.mk (IsComplex.mk (fun i hi => _)) (fun i hi => _)
253-
· obtain hi | rfl := LE.le.lt_or_eq (show i ≤ n by linarith)
253+
· obtain hi | rfl := LE.le.lt_or_eq (show i ≤ n by omega)
254254
· exact h.toIsComplex.zero i
255255
· exact h'.toIsComplex.zero 0
256-
· obtain hi | rfl := LE.le.lt_or_eq (show i ≤ n by linarith)
256+
· obtain hi | rfl := LE.le.lt_or_eq (show i ≤ n by omega)
257257
· exact h.exact i
258258
· exact h'.exact 0
259259

Mathlib/CategoryTheory/Abelian/DiagramLemmas/Four.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ theorem epi_of_epi_of_epi_of_mono'
106106
← R₂.map'_comp 1 2 3, hR₂', comp_zero, comp_zero]
107107
obtain ⟨A₂, π₂, _, f₁, h₃⟩ := (hR₁.exact 0).exact_up_to_refinements _ h₂
108108
dsimp at f₁ h₃
109-
have h₄ : (π₂ ≫ π₁ ≫ g₁ - f₁ ≫ app' φ 1) ≫ R₂.map' 1 2 = 0 := by
109+
have h₄ : (π₂ ≫ π₁ ≫ g₁ - f₁ ≫ app' φ 1 _) ≫ R₂.map' 1 2 = 0 := by
110110
rw [sub_comp, assoc, assoc, assoc, ← NatTrans.naturality, ← reassoc_of% h₃, h₁, sub_self]
111111
obtain ⟨A₃, π₃, _, g₀, h₅⟩ := (hR₂.exact 0).exact_up_to_refinements _ h₄
112112
dsimp at g₀ h₅

0 commit comments

Comments
 (0)