Skip to content

Commit

Permalink
fix(ring_theory/ideal/basic): ideal.module_pi speedup (#9148)
Browse files Browse the repository at this point in the history
Eric and Yael were both complaining that `ideal.module_pi` would occasionally cause random timeouts on unrelated PRs. This PR (a) makes the `smul` proof obligation much tidier (factoring out a sublemma) and (b) replaces the `all_goals` trick by 6 slightly more refined proofs (making the new proof longer, but quicker). On my machine the profiler stats are:

```
ORIG

parsing took 74.1ms
elaboration of module_pi took 3.83s
type checking of module_pi took 424ms
decl post-processing of module_pi took 402ms

NEW

parsing took 136ms
elaboration of module_pi took 1.19s
type checking of module_pi took 82.8ms
decl post-processing of module_pi took 82.5ms
```
  • Loading branch information
kbuzzard committed Sep 12, 2021
1 parent b55483a commit 858e764
Showing 1 changed file with 42 additions and 19 deletions.
61 changes: 42 additions & 19 deletions src/ring_theory/ideal/basic.lean
Expand Up @@ -429,6 +429,13 @@ section comm_ring

namespace ideal

theorem mul_sub_mul_mem {R : Type*} [comm_ring R] (I : ideal R) {a b c d : R}
(h1 : a - b ∈ I) (h2 : c - d ∈ I) : a * c - b * d ∈ I :=
begin
rw (show a * c - b * d = (a - b) * c + b * (c - d), by {rw [sub_mul, mul_sub], abel}),
exact I.add_mem (I.mul_mem_right _ h1) (I.mul_mem_left _ h2),
end

variables [comm_ring α] (I : ideal α) {a b : α}

/-- The quotient `R/I` of a ring `R` by an ideal `I`.
Expand Down Expand Up @@ -629,27 +636,43 @@ variables (ι : Type v)

/-- `R^n/I^n` is a `R/I`-module. -/
instance module_pi : module (I.quotient) (I.pi ι).quotient :=
begin
refine { smul := λ c m, quotient.lift_on₂' c m (λ r m, submodule.quotient.mk $ r • m) _, .. },
{ intros c₁ m₁ c₂ m₂ hc hm,
change c₁ - c₂ ∈ I at hc,
change m₁ - m₂ ∈ (I.pi ι) at hm,
{ smul := λ c m, quotient.lift_on₂' c m (λ r m, submodule.quotient.mk $ r • m) begin
intros c₁ m₁ c₂ m₂ hc hm,
apply ideal.quotient.eq.2,
have : c₁ • (m₂ - m₁) ∈ I.pi ι,
{ rw ideal.mem_pi,
intro i,
simp only [smul_eq_mul, pi.smul_apply, pi.sub_apply],
apply ideal.mul_mem_left,
rw ←ideal.neg_mem_iff,
simpa only [neg_sub] using hm i },
rw [←ideal.add_mem_iff_left (I.pi ι) this, sub_eq_add_neg, add_comm, ←add_assoc, ←smul_add,
sub_add_cancel, ←sub_eq_add_neg, ←sub_smul, ideal.mem_pi],
exact λ i, I.mul_mem_right _ hc },
all_goals { rintro ⟨a⟩ ⟨b⟩ ⟨c⟩ <|> rintro ⟨a⟩,
simp only [(•), submodule.quotient.quot_mk_eq_mk, ideal.quotient.mk_eq_mk],
intro i,
exact I.mul_sub_mul_mem hc (hm i),
end,
one_smul := begin
rintro ⟨a⟩,
change ideal.quotient.mk _ _ = ideal.quotient.mk _ _,
congr' with i, simp [mul_assoc, mul_add, add_mul] }
end
congr' with i, exact one_mul (a i),
end,
mul_smul := begin
rintro ⟨a⟩ ⟨b⟩ ⟨c⟩,
change ideal.quotient.mk _ _ = ideal.quotient.mk _ _,
simp only [(•)],
congr' with i, exact mul_assoc a b (c i),
end,
smul_add := begin
rintro ⟨a⟩ ⟨b⟩ ⟨c⟩,
change ideal.quotient.mk _ _ = ideal.quotient.mk _ _,
congr' with i, exact mul_add a (b i) (c i),
end,
smul_zero := begin
rintro ⟨a⟩,
change ideal.quotient.mk _ _ = ideal.quotient.mk _ _,
congr' with i, exact mul_zero a,
end,
add_smul := begin
rintro ⟨a⟩ ⟨b⟩ ⟨c⟩,
change ideal.quotient.mk _ _ = ideal.quotient.mk _ _,
congr' with i, exact add_mul a b (c i),
end,
zero_smul := begin
rintro ⟨a⟩,
change ideal.quotient.mk _ _ = ideal.quotient.mk _ _,
congr' with i, exact zero_mul (a i),
end, }

/-- `R^n/I^n` is isomorphic to `(R/I)^n` as an `R/I`-module. -/
noncomputable def pi_quot_equiv : (I.pi ι).quotient ≃ₗ[I.quotient] (ι → I.quotient) :=
Expand Down

0 comments on commit 858e764

Please sign in to comment.