Skip to content

Commit 966a3ce

Browse files
committed
refactor(Dual): drop a DecidableEq assumption (#16109)
Split `DualBases.eval` into `eval_same` and `eval_of_ne` to avoid a `DecidableEq` assumption.
1 parent d6507ed commit 966a3ce

File tree

2 files changed

+17
-22
lines changed

2 files changed

+17
-22
lines changed

Archive/Sensitivity.lean

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,8 @@ open Classical in
227227
/-- `e` and `ε` are dual families of vectors. It implies that `e` is indeed a basis
228228
and `ε` computes coefficients of decompositions of vectors on that basis. -/
229229
theorem dualBases_e_ε (n : ℕ) : DualBases (@e n) (@ε n) where
230-
eval := duality
230+
eval_same := by simp [duality]
231+
eval_of_ne _ _ h := by simp [duality, h]
231232
total := @epsilon_total _
232233

233234
/-! We will now derive the dimension of `V`, first as a cardinal in `dim_V` and,

Mathlib/LinearAlgebra/Dual.lean

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -669,7 +669,7 @@ section DualBases
669669
open Module
670670

671671
variable {R M ι : Type*}
672-
variable [CommSemiring R] [AddCommMonoid M] [Module R M] [DecidableEq ι]
672+
variable [CommSemiring R] [AddCommMonoid M] [Module R M]
673673

674674
-- Porting note: replace use_finite_instance tactic
675675
open Lean.Elab.Tactic in
@@ -682,10 +682,10 @@ elab "use_finite_instance" : tactic => evalUseFiniteInstance
682682
/-- `e` and `ε` have characteristic properties of a basis and its dual -/
683683
-- @[nolint has_nonempty_instance] Porting note (#5171): removed
684684
structure Module.DualBases (e : ι → M) (ε : ι → Dual R M) : Prop where
685-
eval : ∀ i j : ι, ε i (e j) = if i = j then 1 else 0
685+
eval_same : ∀ i, ε i (e i) = 1
686+
eval_of_ne : Pairwise fun i j ↦ ε i (e j) = 0
686687
protected total : ∀ {m : M}, (∀ i, ε i m = 0) → m = 0
687-
protected finite : ∀ m : M, { i | ε i m ≠ 0 }.Finite := by
688-
use_finite_instance
688+
protected finite : ∀ m : M, {i | ε i m ≠ 0}.Finite := by use_finite_instance
689689

690690
end DualBases
691691

@@ -698,13 +698,13 @@ variable [CommRing R] [AddCommGroup M] [Module R M]
698698
variable {e : ι → M} {ε : ι → Dual R M}
699699

700700
/-- The coefficients of `v` on the basis `e` -/
701-
def coeffs [DecidableEq ι] (h : DualBases e ε) (m : M) : ι →₀ R where
701+
def coeffs (h : DualBases e ε) (m : M) : ι →₀ R where
702702
toFun i := ε i m
703703
support := (h.finite m).toFinset
704704
mem_support_toFun i := by rw [Set.Finite.mem_toFinset, Set.mem_setOf_eq]
705705

706706
@[simp]
707-
theorem coeffs_apply [DecidableEq ι] (h : DualBases e ε) (m : M) (i : ι) : h.coeffs m i = ε i m :=
707+
theorem coeffs_apply (h : DualBases e ε) (m : M) (i : ι) : h.coeffs m i = ε i m :=
708708
rfl
709709

710710
/-- linear combinations of elements of `e`.
@@ -717,16 +717,16 @@ theorem lc_def (e : ι → M) (l : ι →₀ R) : lc e l = Finsupp.total _ _ R e
717717

718718
open Module
719719

720-
variable [DecidableEq ι] (h : DualBases e ε)
720+
variable (h : DualBases e ε)
721721
include h
722722

723723
theorem dual_lc (l : ι →₀ R) (i : ι) : ε i (DualBases.lc e l) = l i := by
724724
rw [lc, _root_.map_finsupp_sum, Finsupp.sum_eq_single i (g := fun a b ↦ (ε i) (b • e a))]
725725
-- Porting note: cannot get at •
726726
-- simp only [h.eval, map_smul, smul_eq_mul]
727-
· simp [h.eval, smul_eq_mul]
727+
· simp [h.eval_same, smul_eq_mul]
728728
· intro q _ q_ne
729-
simp [q_ne.symm, h.eval, smul_eq_mul]
729+
simp [h.eval_of_ne q_ne.symm, smul_eq_mul]
730730
· simp
731731

732732
@[simp]
@@ -741,7 +741,7 @@ theorem lc_coeffs (m : M) : DualBases.lc e (h.coeffs m) = m := by
741741
simp [LinearMap.map_sub, h.dual_lc, sub_eq_zero]
742742

743743
/-- `(h : DualBases e ε).basis` shows the family of vectors `e` forms a basis. -/
744-
@[simps]
744+
@[simps repr_apply, simps (config := .lemmasOnly) repr_symm_apply]
745745
def basis : Basis ι R M :=
746746
Basis.ofRepr
747747
{ toFun := coeffs h
@@ -755,30 +755,24 @@ def basis : Basis ι R M :=
755755
ext i
756756
exact (ε i).map_smul c v }
757757

758-
-- Porting note: from simpNF the LHS simplifies; it yields lc_def.symm
759-
-- probably not a useful simp lemma; nolint simpNF since it cannot see this removal
760-
attribute [-simp, nolint simpNF] basis_repr_symm_apply
761-
762758
@[simp]
763759
theorem coe_basis : ⇑h.basis = e := by
764760
ext i
765761
rw [Basis.apply_eq_iff]
766762
ext j
767-
rw [h.basis_repr_apply, coeffs_apply, h.eval, Finsupp.single_apply]
768-
convert if_congr (eq_comm (a := j) (b := i)) rfl rfl
763+
rcases eq_or_ne i j with rfl | hne
764+
· simp [h.eval_same]
765+
· simp [hne, h.eval_of_ne hne.symm]
769766

770-
-- `convert` to get rid of a `DecidableEq` mismatch
771767
theorem mem_of_mem_span {H : Set ι} {x : M} (hmem : x ∈ Submodule.span R (e '' H)) :
772768
∀ i : ι, ε i x ≠ 0 → i ∈ H := by
773769
intro i hi
774770
rcases (Finsupp.mem_span_image_iff_total _).mp hmem with ⟨l, supp_l, rfl⟩
775771
apply not_imp_comm.mp ((Finsupp.mem_supported' _ _).mp supp_l i)
776772
rwa [← lc_def, h.dual_lc] at hi
777773

778-
theorem coe_dualBasis [_root_.Finite ι] : ⇑h.basis.dualBasis = ε :=
779-
funext fun i =>
780-
h.basis.ext fun j => by
781-
rw [h.basis.dualBasis_apply_self, h.coe_basis, h.eval, if_congr eq_comm rfl rfl]
774+
theorem coe_dualBasis [DecidableEq ι] [_root_.Finite ι] : ⇑h.basis.dualBasis = ε :=
775+
funext fun i => h.basis.ext fun j => by simp
782776

783777
end Module.DualBases
784778

0 commit comments

Comments
 (0)