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

Commit 2a7ceb0

Browse files
committed
perf(linear_algebra): speed up graded_algebra instances (#14967)
Reduce `elaboration of graded_algebra` in: + `exterior_algebra.graded_algebra` from ~20s to 3s- + `tensor_algebra.graded_algebra` from 7s+ to 2s- + `clifford_algebra.graded_algebra` from 14s+ to 4s- (These numbers were before `lift_ι` and `lift_ι_eq` were extracted from `exterior_algebra.graded_algebra` and `lift_ι_eq` was extracted from `clifford_algebra.graded_algebra` in #12182.) Fix [timeout reported on Zulip](https://leanprover.zulipchat.com/#narrow/stream/113488-general/topic/deterministic.20timeout/near/286996731) Also shorten the statements of the first two without reducing clarity (I think).
1 parent a5a6865 commit 2a7ceb0

3 files changed

Lines changed: 22 additions & 20 deletions

File tree

src/linear_algebra/clifford_algebra/grading.lean

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -78,12 +78,12 @@ rfl
7878
lemma graded_algebra.ι_sq_scalar (m : M) :
7979
graded_algebra.ι Q m * graded_algebra.ι Q m = algebra_map R _ (Q m) :=
8080
begin
81-
rw [graded_algebra.ι_apply, direct_sum.of_mul_of, direct_sum.algebra_map_apply],
81+
rw [graded_algebra.ι_apply Q, direct_sum.of_mul_of, direct_sum.algebra_map_apply],
8282
refine direct_sum.of_eq_of_graded_monoid_eq (sigma.subtype_ext rfl $ ι_sq_scalar _ _),
8383
end
8484

8585
lemma graded_algebra.lift_ι_eq (i' : zmod 2) (x' : even_odd Q i') :
86-
lift Q ⟨graded_algebra.ι Q, graded_algebra.ι_sq_scalar Q⟩ x' =
86+
lift Q ⟨by apply graded_algebra.ι Q, graded_algebra.ι_sq_scalar Q⟩ x' =
8787
direct_sum.of (λ i, even_odd Q i) i' x' :=
8888
begin
8989
cases x' with x' hx',
@@ -96,7 +96,7 @@ begin
9696
{ rw [alg_hom.commutes, direct_sum.algebra_map_apply], refl },
9797
{ rw [alg_hom.map_add, ihx, ihy, ←map_add], refl },
9898
{ obtain ⟨_, rfl⟩ := hm,
99-
rw [alg_hom.map_mul, ih, lift_ι_apply, graded_algebra.ι_apply, direct_sum.of_mul_of],
99+
rw [alg_hom.map_mul, ih, lift_ι_apply, graded_algebra.ι_apply Q, direct_sum.of_mul_of],
100100
refine direct_sum.of_eq_of_graded_monoid_eq (sigma.subtype_ext _ _);
101101
dsimp only [graded_monoid.mk, subtype.coe_mk],
102102
{ rw [nat.succ_eq_add_one, add_comm, nat.cast_add, nat.cast_one] },
@@ -110,16 +110,17 @@ end
110110
/-- The clifford algebra is graded by the even and odd parts. -/
111111
instance graded_algebra : graded_algebra (even_odd Q) :=
112112
graded_algebra.of_alg_hom (even_odd Q)
113-
(lift _ ⟨graded_algebra.ι Q, graded_algebra.ι_sq_scalar Q⟩)
113+
-- while not necessary, the `by apply` makes this elaborate faster
114+
(lift Q ⟨by apply graded_algebra.ι Q, graded_algebra.ι_sq_scalar Q⟩)
114115
-- the proof from here onward is mostly similar to the `tensor_algebra` case, with some extra
115116
-- handling for the `supr` in `even_odd`.
116117
(begin
117118
ext m,
118119
dsimp only [linear_map.comp_apply, alg_hom.to_linear_map_apply, alg_hom.comp_apply,
119120
alg_hom.id_apply],
120-
rw [lift_ι_apply, graded_algebra.ι_apply, direct_sum.coe_alg_hom_of, subtype.coe_mk],
121+
rw [lift_ι_apply, graded_algebra.ι_apply Q, direct_sum.coe_alg_hom_of, subtype.coe_mk],
121122
end)
122-
(by exact graded_algebra.lift_ι_eq Q)
123+
(by apply graded_algebra.lift_ι_eq Q)
123124

124125
lemma supr_ι_range_eq_top : (⨆ i : ℕ, (ι Q).range ^ i) = ⊤ :=
125126
begin

src/linear_algebra/exterior_algebra/grading.lean

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,14 @@ end
4242
primarily an auxiliary construction used to provide `exterior_algebra.graded_algebra`. -/
4343
def graded_algebra.lift_ι : exterior_algebra R M →ₐ[R]
4444
⨁ (i : ℕ), ↥((ι R).range ^ i : submodule R (exterior_algebra R M)) :=
45-
lift R ⟨graded_algebra.ι R M, graded_algebra.ι_sq_zero R M⟩
45+
lift R ⟨by apply graded_algebra.ι R M, graded_algebra.ι_sq_zero R M⟩
4646

47-
variables {R M}
47+
variables (R M)
4848

4949
lemma graded_algebra.lift_ι_eq (i : ℕ)
5050
(x : ((ι R).range ^ i : submodule R (exterior_algebra R M))) :
5151
graded_algebra.lift_ι R M x =
52-
direct_sum.of (λ i, (((ι R).range ^ i : submodule R (exterior_algebra R M)) : Type*)) i x :=
52+
direct_sum.of (λ i, ↥((ι R).range ^ i : submodule R (exterior_algebra R M))) i x :=
5353
begin
5454
cases x with x hx,
5555
dsimp only [subtype.coe_mk, direct_sum.lof_eq_of],
@@ -58,23 +58,24 @@ begin
5858
{ rw [alg_hom.commutes, direct_sum.algebra_map_apply], refl },
5959
{ rw [alg_hom.map_add, ihx, ihy, ←map_add], refl },
6060
{ obtain ⟨_, rfl⟩ := hm,
61-
rw [alg_hom.map_mul, ih, graded_algebra.lift_ι, lift_ι_apply, graded_algebra.ι_apply,
62-
direct_sum.of_mul_of],
63-
exact direct_sum.of_eq_of_graded_monoid_eq (sigma.subtype_ext (add_comm _ _) rfl) }
61+
rw [alg_hom.map_mul, ih, graded_algebra.lift_ι, lift_ι_apply,
62+
graded_algebra.ι_apply R M, direct_sum.of_mul_of],
63+
exact direct_sum.of_eq_of_graded_monoid_eq (sigma.subtype_ext (add_comm _ _) rfl) },
6464
end
6565

6666
/-- The exterior algebra is graded by the powers of the submodule `(exterior_algebra.ι R).range`. -/
6767
instance graded_algebra :
68-
graded_algebra
69-
((^) (ι R : M →ₗ[R] exterior_algebra R M).range : ℕ → submodule R (exterior_algebra R M)) :=
70-
graded_algebra.of_alg_hom _ (graded_algebra.lift_ι R M)
68+
graded_algebra ((^) (ι R : M →ₗ[R] exterior_algebra R M).range : ℕ → submodule R _) :=
69+
graded_algebra.of_alg_hom _
70+
-- while not necessary, the `by apply` makes this elaborate faster
71+
(by apply graded_algebra.lift_ι R M)
7172
-- the proof from here onward is identical to the `tensor_algebra` case
7273
(begin
7374
ext m,
7475
dsimp only [linear_map.comp_apply, alg_hom.to_linear_map_apply, alg_hom.comp_apply,
7576
alg_hom.id_apply, graded_algebra.lift_ι],
76-
rw [lift_ι_apply, graded_algebra.ι_apply, direct_sum.coe_alg_hom_of, subtype.coe_mk],
77+
rw [lift_ι_apply, graded_algebra.ι_apply R M, direct_sum.coe_alg_hom_of, subtype.coe_mk],
7778
end)
78-
(by exact graded_algebra.lift_ι_eq)
79+
(by apply graded_algebra.lift_ι_eq R M)
7980

8081
end exterior_algebra

src/linear_algebra/tensor_algebra/grading.lean

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,12 @@ variables {R M}
3737
instance graded_algebra :
3838
graded_algebra ((^) (ι R : M →ₗ[R] tensor_algebra R M).range : ℕ → submodule R _) :=
3939
graded_algebra.of_alg_hom _
40-
(lift _ $ graded_algebra.ι R M)
40+
(lift R $ graded_algebra.ι R M)
4141
(begin
4242
ext m,
4343
dsimp only [linear_map.comp_apply, alg_hom.to_linear_map_apply, alg_hom.comp_apply,
4444
alg_hom.id_apply],
45-
rw [lift_ι_apply, graded_algebra.ι_apply, direct_sum.coe_alg_hom_of, subtype.coe_mk],
45+
rw [lift_ι_apply, graded_algebra.ι_apply R M, direct_sum.coe_alg_hom_of, subtype.coe_mk],
4646
end)
4747
(λ i x, begin
4848
cases x with x hx,
@@ -52,7 +52,7 @@ graded_algebra.of_alg_hom _
5252
{ rw [alg_hom.commutes, direct_sum.algebra_map_apply], refl },
5353
{ rw [alg_hom.map_add, ihx, ihy, ←map_add], refl },
5454
{ obtain ⟨_, rfl⟩ := hm,
55-
rw [alg_hom.map_mul, ih, lift_ι_apply, graded_algebra.ι_apply, direct_sum.of_mul_of],
55+
rw [alg_hom.map_mul, ih, lift_ι_apply, graded_algebra.ι_apply R M, direct_sum.of_mul_of],
5656
exact direct_sum.of_eq_of_graded_monoid_eq (sigma.subtype_ext (add_comm _ _) rfl) }
5757
end)
5858

0 commit comments

Comments
 (0)