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

Commit 565eb99

Browse files
committed
chore(*): remove after the fact attribute [irreducible] at several places (#18168)
Part of #18164
1 parent ec2dfca commit 565eb99

File tree

16 files changed

+284
-151
lines changed

16 files changed

+284
-151
lines changed

src/algebra/free_algebra.lean

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -179,9 +179,10 @@ variables {X}
179179
/--
180180
The canonical function `X → free_algebra R X`.
181181
-/
182-
def ι : X → free_algebra R X := λ m, quot.mk _ m
182+
@[irreducible] def ι : X → free_algebra R X := λ m, quot.mk _ m
183183

184-
@[simp] lemma quot_mk_eq_ι (m : X) : quot.mk (free_algebra.rel R X) m = ι R m := rfl
184+
@[simp] lemma quot_mk_eq_ι (m : X) : quot.mk (free_algebra.rel R X) m = ι R m :=
185+
by rw [ι]
185186

186187
variables {A : Type*} [semiring A] [algebra R A]
187188

@@ -230,16 +231,17 @@ private def lift_aux (f : X → A) : (free_algebra R X →ₐ[R] A) :=
230231
Given a function `f : X → A` where `A` is an `R`-algebra, `lift R f` is the unique lift
231232
of `f` to a morphism of `R`-algebras `free_algebra R X → A`.
232233
-/
233-
def lift : (X → A) ≃ (free_algebra R X →ₐ[R] A) :=
234+
@[irreducible] def lift : (X → A) ≃ (free_algebra R X →ₐ[R] A) :=
234235
{ to_fun := lift_aux R,
235236
inv_fun := λ F, F ∘ (ι R),
236-
left_inv := λ f, by {ext, refl},
237+
left_inv := λ f, by {ext, rw [ι], refl},
237238
right_inv := λ F, by
238239
{ ext x,
239240
rcases x,
240241
induction x,
241242
case pre.of :
242243
{ change ((F : free_algebra R X → A) ∘ (ι R)) _ = _,
244+
rw [ι],
243245
refl },
244246
case pre.of_scalar :
245247
{ change algebra_map _ _ x = F (algebra_map _ _ x),
@@ -251,36 +253,35 @@ def lift : (X → A) ≃ (free_algebra R X →ₐ[R] A) :=
251253
{ change lift_aux R (F ∘ ι R) (quot.mk _ _ * quot.mk _ _) = F (quot.mk _ _ * quot.mk _ _),
252254
rw [alg_hom.map_mul, alg_hom.map_mul, ha, hb], }, }, }
253255

254-
@[simp] lemma lift_aux_eq (f : X → A) : lift_aux R f = lift R f := rfl
256+
@[simp] lemma lift_aux_eq (f : X → A) : lift_aux R f = lift R f :=
257+
by { rw [lift], refl }
255258

256259
@[simp]
257-
lemma lift_symm_apply (F : free_algebra R X →ₐ[R] A) : (lift R).symm F = F ∘ (ι R) := rfl
260+
lemma lift_symm_apply (F : free_algebra R X →ₐ[R] A) : (lift R).symm F = F ∘ (ι R) :=
261+
by { rw [lift], refl }
258262

259263
variables {R X}
260264

261265
@[simp]
262266
theorem ι_comp_lift (f : X → A) :
263-
(lift R f : free_algebra R X → A) ∘ (ι R) = f := by {ext, refl}
267+
(lift R f : free_algebra R X → A) ∘ (ι R) = f :=
268+
by { ext, rw [ι, lift], refl }
264269

265270
@[simp]
266271
theorem lift_ι_apply (f : X → A) (x) :
267-
lift R f (ι R x) = f x := rfl
272+
lift R f (ι R x) = f x :=
273+
by { rw [ι, lift], refl }
268274

269275
@[simp]
270276
theorem lift_unique (f : X → A) (g : free_algebra R X →ₐ[R] A) :
271277
(g : free_algebra R X → A) ∘ (ι R) = f ↔ g = lift R f :=
272-
(lift R).symm_apply_eq
278+
by { rw [← (lift R).symm_apply_eq, lift], refl }
273279

274280
/-!
275-
At this stage we set the basic definitions as `@[irreducible]`, so from this point onwards one
281+
Since we have set the basic definitions as `@[irreducible]`, from this point onwards one
276282
should only use the universal properties of the free algebra, and consider the actual implementation
277-
as a quotient of an inductive type as completely hidden.
283+
as a quotient of an inductive type as completely hidden. -/
278284

279-
Of course, one still has the option to locally make these definitions `semireducible` if so desired,
280-
and Lean is still willing in some circumstances to do unification based on the underlying
281-
definition.
282-
-/
283-
attribute [irreducible] ι lift
284285
-- Marking `free_algebra` irreducible makes `ring` instances inaccessible on quotients.
285286
-- https://leanprover.zulipchat.com/#narrow/stream/113488-general/topic/algebra.2Esemiring_to_ring.20breaks.20semimodule.20typeclass.20lookup/near/212580241
286287
-- For now, we avoid this by not marking it irreducible.

src/algebra/ring_quot.lean

Lines changed: 44 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ instance [algebra S R] (r : R → R → Prop) : algebra S (ring_quot r) :=
182182
/--
183183
The quotient map from a ring to its quotient, as a homomorphism of rings.
184184
-/
185-
def mk_ring_hom (r : R → R → Prop) : R →+* ring_quot r :=
185+
@[irreducible] def mk_ring_hom (r : R → R → Prop) : R →+* ring_quot r :=
186186
{ to_fun := λ x, ⟨quot.mk _ x⟩,
187187
map_one' := by simp [← one_quot],
188188
map_mul' := by simp [mul_quot],
@@ -211,7 +211,7 @@ variables {T : Type u₄} [semiring T]
211211
Any ring homomorphism `f : R →+* T` which respects a relation `r : R → R → Prop`
212212
factors uniquely through a morphism `ring_quot r →+* T`.
213213
-/
214-
def lift {r : R → R → Prop} :
214+
@[irreducible] def lift {r : R → R → Prop} :
215215
{f : R →+* T // ∀ ⦃x y⦄, r x y → f x = f y} ≃ (ring_quot r →+* T) :=
216216
{ to_fun := λ f', let f := (f' : R →+* T) in
217217
{ to_fun := λ x, quot.lift f
@@ -228,13 +228,13 @@ def lift {r : R → R → Prop} :
228228
map_one' := by simp [← one_quot, f.map_one],
229229
map_mul' := by { rintros ⟨⟨x⟩⟩ ⟨⟨y⟩⟩, simp [mul_quot, f.map_mul x y] }, },
230230
inv_fun := λ F, ⟨F.comp (mk_ring_hom r), λ x y h, by { dsimp, rw mk_ring_hom_rel h, }⟩,
231-
left_inv := λ f, by { ext, simp, refl },
232-
right_inv := λ F, by { ext, simp, refl } }
231+
left_inv := λ f, by { ext, simp [mk_ring_hom] },
232+
right_inv := λ F, by { ext, simp [mk_ring_hom] } }
233233

234234
@[simp]
235235
lemma lift_mk_ring_hom_apply (f : R →+* T) {r : R → R → Prop} (w : ∀ ⦃x y⦄, r x y → f x = f y) (x) :
236236
lift ⟨f, w⟩ (mk_ring_hom r x) = f x :=
237-
rfl
237+
by { simp_rw [lift, mk_ring_hom], refl }
238238

239239
-- note this is essentially `lift.symm_apply_eq.mp h`
240240
lemma lift_unique (f : R →+* T) {r : R → R → Prop} (w : ∀ ⦃x y⦄, r x y → f x = f y)
@@ -243,7 +243,12 @@ by { ext, simp [h], }
243243

244244
lemma eq_lift_comp_mk_ring_hom {r : R → R → Prop} (f : ring_quot r →+* T) :
245245
f = lift ⟨f.comp (mk_ring_hom r), λ x y h, by { dsimp, rw mk_ring_hom_rel h, }⟩ :=
246-
(lift.apply_symm_apply f).symm
246+
begin
247+
conv_lhs { rw ← lift.apply_symm_apply f },
248+
rw lift,
249+
refl,
250+
end
251+
247252

248253
section comm_ring
249254
/-!
@@ -261,7 +266,11 @@ lift
261266
λ x y h, ideal.quotient.eq.2 $ submodule.mem_Inf.mpr (λ p w, w ⟨x, y, h, sub_add_cancel x y⟩)⟩
262267

263268
@[simp] lemma ring_quot_to_ideal_quotient_apply (r : B → B → Prop) (x : B) :
264-
ring_quot_to_ideal_quotient r (mk_ring_hom r x) = ideal.quotient.mk _ x := rfl
269+
ring_quot_to_ideal_quotient r (mk_ring_hom r x) = ideal.quotient.mk _ x :=
270+
begin
271+
simp_rw [ring_quot_to_ideal_quotient, lift, mk_ring_hom],
272+
refl
273+
end
265274

266275
/-- The universal ring homomorphism from `B ⧸ ideal.of_rel r` to `ring_quot r`. -/
267276
def ideal_quotient_to_ring_quot (r : B → B → Prop) :
@@ -287,7 +296,20 @@ The ring equivalence between `ring_quot r` and `(ideal.of_rel r).quotient`
287296
def ring_quot_equiv_ideal_quotient (r : B → B → Prop) :
288297
ring_quot r ≃+* B ⧸ ideal.of_rel r :=
289298
ring_equiv.of_hom_inv (ring_quot_to_ideal_quotient r) (ideal_quotient_to_ring_quot r)
290-
(by { ext, refl, }) (by { ext, refl, })
299+
(begin
300+
ext,
301+
simp_rw [ring_quot_to_ideal_quotient, lift, mk_ring_hom],
302+
dsimp,
303+
rw [mk_ring_hom],
304+
refl
305+
end)
306+
(begin
307+
ext,
308+
simp_rw [ring_quot_to_ideal_quotient, lift, mk_ring_hom],
309+
dsimp,
310+
rw [mk_ring_hom],
311+
refl
312+
end)
291313

292314
end comm_ring
293315

@@ -331,20 +353,20 @@ variables (S)
331353
/--
332354
The quotient map from an `S`-algebra to its quotient, as a homomorphism of `S`-algebras.
333355
-/
334-
def mk_alg_hom (s : A → A → Prop) : A →ₐ[S] ring_quot s :=
335-
{ commutes' := λ r, rfl,
356+
@[irreducible] def mk_alg_hom (s : A → A → Prop) : A →ₐ[S] ring_quot s :=
357+
{ commutes' := λ r, by { simp [mk_ring_hom], refl },
336358
..mk_ring_hom s }
337359

338360
@[simp]
339361
lemma mk_alg_hom_coe (s : A → A → Prop) : (mk_alg_hom S s : A →+* ring_quot s) = mk_ring_hom s :=
340-
rfl
362+
by { simp_rw [mk_alg_hom, mk_ring_hom], refl }
341363

342364
lemma mk_alg_hom_rel {s : A → A → Prop} {x y : A} (w : s x y) :
343365
mk_alg_hom S s x = mk_alg_hom S s y :=
344366
by simp [mk_alg_hom, mk_ring_hom, quot.sound (rel.of w)]
345367

346368
lemma mk_alg_hom_surjective (s : A → A → Prop) : function.surjective (mk_alg_hom S s) :=
347-
by { dsimp [mk_alg_hom], rintro ⟨⟨a⟩⟩, use a, refl, }
369+
by { dsimp [mk_alg_hom, mk_ring_hom], rintro ⟨⟨a⟩⟩, use a, refl, }
348370

349371
variables {B : Type u₄} [semiring B] [algebra S B]
350372

@@ -361,8 +383,8 @@ end
361383
Any `S`-algebra homomorphism `f : A →ₐ[S] B` which respects a relation `s : A → A → Prop`
362384
factors uniquely through a morphism `ring_quot s →ₐ[S] B`.
363385
-/
364-
def lift_alg_hom {s : A → A → Prop} :
365-
{ f : A →ₐ[S] B // ∀ ⦃x y⦄, s x y → f x = f y} ≃ (ring_quot s →ₐ[S] B) :=
386+
@[irreducible] def lift_alg_hom {s : A → A → Prop} :
387+
{f : A →ₐ[S] B // ∀ ⦃x y⦄, s x y → f x = f y} ≃ (ring_quot s →ₐ[S] B) :=
366388
{ to_fun := λ f', let f := (f' : A →ₐ[S] B) in
367389
{ to_fun := λ x, quot.lift f
368390
begin
@@ -379,14 +401,14 @@ def lift_alg_hom {s : A → A → Prop} :
379401
map_mul' := by { rintros ⟨⟨x⟩⟩ ⟨⟨y⟩⟩, simp [mul_quot, f.map_mul x y], },
380402
commutes' := by { rintros x, simp [← one_quot, smul_quot, algebra.algebra_map_eq_smul_one] } },
381403
inv_fun := λ F, ⟨F.comp (mk_alg_hom S s), λ _ _ h, by { dsimp, erw mk_alg_hom_rel S h }⟩,
382-
left_inv := λ f, by { ext, simp, refl },
383-
right_inv := λ F, by { ext, simp, refl } }
404+
left_inv := λ f, by { ext, simp [mk_alg_hom, mk_ring_hom] },
405+
right_inv := λ F, by { ext, simp [mk_alg_hom, mk_ring_hom] } }
384406

385407
@[simp]
386408
lemma lift_alg_hom_mk_alg_hom_apply (f : A →ₐ[S] B) {s : A → A → Prop}
387409
(w : ∀ ⦃x y⦄, s x y → f x = f y) (x) :
388410
(lift_alg_hom S ⟨f, w⟩) ((mk_alg_hom S s) x) = f x :=
389-
rfl
411+
by { simp_rw [lift_alg_hom, mk_alg_hom, mk_ring_hom], refl, }
390412

391413
-- note this is essentially `(lift_alg_hom S).symm_apply_eq.mp h`
392414
lemma lift_alg_hom_unique (f : A →ₐ[S] B) {s : A → A → Prop} (w : ∀ ⦃x y⦄, s x y → f x = f y)
@@ -395,10 +417,12 @@ by { ext, simp [h], }
395417

396418
lemma eq_lift_alg_hom_comp_mk_alg_hom {s : A → A → Prop} (f : ring_quot s →ₐ[S] B) :
397419
f = lift_alg_hom S ⟨f.comp (mk_alg_hom S s), λ x y h, by { dsimp, erw mk_alg_hom_rel S h, }⟩ :=
398-
((lift_alg_hom S).apply_symm_apply f).symm
420+
begin
421+
conv_lhs { rw ← ((lift_alg_hom S).apply_symm_apply f) },
422+
rw lift_alg_hom,
423+
refl,
424+
end
399425

400426
end algebra
401427

402-
attribute [irreducible] mk_ring_hom mk_alg_hom lift lift_alg_hom
403-
404428
end ring_quot

src/data/polynomial/eval.lean

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,11 @@ variables (f : R →+* S) (x : S)
3131

3232
/-- Evaluate a polynomial `p` given a ring hom `f` from the scalar ring
3333
to the target and a value `x` for the variable in the target -/
34-
def eval₂ (p : R[X]) : S :=
34+
@[irreducible] def eval₂ (p : R[X]) : S :=
3535
p.sum (λ e a, f a * x ^ e)
3636

37-
lemma eval₂_eq_sum {f : R →+* S} {x : S} : p.eval₂ f x = p.sum (λ e a, f a * x ^ e) := rfl
37+
lemma eval₂_eq_sum {f : R →+* S} {x : S} : p.eval₂ f x = p.sum (λ e a, f a * x ^ e) :=
38+
by rw eval₂
3839

3940
lemma eval₂_congr {R S : Type*} [semiring R] [semiring S]
4041
{f g : R →+* S} {s t : S} {φ ψ : R[X]} :
@@ -66,7 +67,7 @@ begin
6667
end
6768

6869
@[simp] lemma eval₂_add : (p + q).eval₂ f x = p.eval₂ f x + q.eval₂ f x :=
69-
by { apply sum_add_index; simp [add_mul] }
70+
by { simp only [eval₂_eq_sum], apply sum_add_index; simp [add_mul] }
7071

7172
@[simp] lemma eval₂_one : (1 : R[X]).eval₂ f x = 1 :=
7273
by rw [← C_1, eval₂_C, f.map_one]
@@ -256,7 +257,7 @@ variables {x : R}
256257
def eval : R → R[X] → R := eval₂ (ring_hom.id _)
257258

258259
lemma eval_eq_sum : p.eval x = p.sum (λ e a, a * x ^ e) :=
259-
rfl
260+
by { rw [eval, eval₂_eq_sum], refl }
260261

261262
lemma eval_eq_sum_range {p : R[X]} (x : R) :
262263
p.eval x = ∑ i in finset.range (p.nat_degree + 1), p.coeff i * x ^ i :=
@@ -382,8 +383,12 @@ lemma is_root.eq_zero (h : is_root p x) : eval x p = 0 := h
382383

383384
lemma coeff_zero_eq_eval_zero (p : R[X]) : coeff p 0 = p.eval 0 :=
384385
calc coeff p 0 = coeff p 0 * 0 ^ 0 : by simp
385-
... = p.eval 0 : eq.symm $
386-
finset.sum_eq_single _ (λ b _ hb, by simp [zero_pow (nat.pos_of_ne_zero hb)]) (by simp)
386+
... = p.eval 0 :
387+
begin
388+
symmetry,
389+
rw [eval_eq_sum],
390+
exact finset.sum_eq_single _ (λ b _ hb, by simp [zero_pow (nat.pos_of_ne_zero hb)]) (by simp)
391+
end
387392

388393
lemma zero_is_root_of_coeff_zero_eq_zero {p : R[X]} (hp : p.coeff 0 = 0) : is_root p 0 :=
389394
by rwa coeff_zero_eq_eval_zero at hp
@@ -401,7 +406,8 @@ section comp
401406
/-- The composition of polynomials as a polynomial. -/
402407
def comp (p q : R[X]) : R[X] := p.eval₂ C q
403408

404-
lemma comp_eq_sum_left : p.comp q = p.sum (λ e a, C a * q ^ e) := rfl
409+
lemma comp_eq_sum_left : p.comp q = p.sum (λ e a, C a * q ^ e) :=
410+
by rw [comp, eval₂_eq_sum]
405411

406412
@[simp] lemma comp_X : p.comp X = p :=
407413
begin
@@ -735,12 +741,10 @@ end
735741
end map
736742

737743
/-!
738-
After having set up the basic theory of `eval₂`, `eval`, `comp`, and `map`,
739-
we make `eval₂` irreducible.
744+
we have made `eval₂` irreducible from the start.
740745
741-
Perhaps we can make the others irreducible too?
746+
Perhaps we can make also `eval`, `comp`, and `map` irreducible too?
742747
-/
743-
attribute [irreducible] polynomial.eval₂
744748

745749
section hom_eval₂
746750

src/linear_algebra/determinant.lean

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ there is no good way to generalize over universe parameters, so we can't fully s
128128
type that it does not depend on the choice of basis. Instead you can use the `det_aux_def'` lemma,
129129
or avoid mentioning a basis at all using `linear_map.det`.
130130
-/
131-
def det_aux : trunc (basis ι A M) → (M →ₗ[A] M) →* A :=
131+
@[irreducible] def det_aux : trunc (basis ι A M) → (M →ₗ[A] M) →* A :=
132132
trunc.lift
133133
(λ b : basis ι A M,
134134
(det_monoid_hom).comp (to_matrix_alg_equiv b : (M →ₗ[A] M) →* matrix ι ι A))
@@ -140,10 +140,7 @@ See also `det_aux_def'` which allows you to vary the basis.
140140
-/
141141
lemma det_aux_def (b : basis ι A M) (f : M →ₗ[A] M) :
142142
linear_map.det_aux (trunc.mk b) f = matrix.det (linear_map.to_matrix b b f) :=
143-
rfl
144-
145-
-- Discourage the elaborator from unfolding `det_aux` and producing a huge term.
146-
attribute [irreducible] linear_map.det_aux
143+
by { rw [det_aux], refl }
147144

148145
lemma det_aux_def' {ι' : Type*} [fintype ι'] [decidable_eq ι']
149146
(tb : trunc $ basis ι A M) (b' : basis ι' A M) (f : M →ₗ[A] M) :

src/linear_algebra/dimension.lean

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ In particular this agrees with the usual notion of the dimension of a vector spa
105105
The definition is marked as protected to avoid conflicts with `_root_.rank`,
106106
the rank of a linear map.
107107
-/
108-
protected def module.rank : cardinal :=
108+
@[irreducible] protected def module.rank : cardinal :=
109109
⨆ ι : {s : set V // linear_independent K (coe : s → V)}, #ι.1
110110

111111
end
@@ -136,6 +136,7 @@ theorem dim_le {n : ℕ}
136136
(H : ∀ s : finset M, linear_independent R (λ i : s, (i : M)) → s.card ≤ n) :
137137
module.rank R M ≤ n :=
138138
begin
139+
rw module.rank,
139140
apply csupr_le',
140141
rintro ⟨s, li⟩,
141142
exact linear_independent_bounded_of_finset_linear_independent_bounded H _ li,
@@ -239,7 +240,7 @@ begin
239240
apply le_trans,
240241
{ exact cardinal.lift_mk_le.mpr
241242
⟨(equiv.of_injective _ hv.injective).to_embedding⟩, },
242-
{ simp only [cardinal.lift_le],
243+
{ simp only [cardinal.lift_le, module.rank],
243244
apply le_trans,
244245
swap,
245246
exact le_csupr (cardinal.bdd_above_range.{v v} _) ⟨range v, hv.coe_range⟩,
@@ -266,6 +267,7 @@ variables (R M)
266267
@[simp] lemma dim_punit : module.rank R punit = 0 :=
267268
begin
268269
apply le_bot_iff.mp,
270+
rw module.rank,
269271
apply csupr_le',
270272
rintro ⟨s, li⟩,
271273
apply le_bot_iff.mpr,
@@ -775,6 +777,7 @@ theorem basis.mk_eq_dim'' {ι : Type v} (v : basis ι R M) :
775777
#ι = module.rank R M :=
776778
begin
777779
haveI := nontrivial_of_invariant_basis_number R,
780+
rw module.rank,
778781
apply le_antisymm,
779782
{ transitivity,
780783
swap,
@@ -786,10 +789,6 @@ begin
786789
apply linear_independent_le_basis v _ li, },
787790
end
788791

789-
-- By this stage we want to have a complete API for `module.rank`,
790-
-- so we set it `irreducible` here, to keep ourselves honest.
791-
attribute [irreducible] module.rank
792-
793792
theorem basis.mk_range_eq_dim (v : basis ι R M) :
794793
#(range v) = module.rank R M :=
795794
v.reindex_range.mk_eq_dim''

0 commit comments

Comments
 (0)