Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Merged by Bors] - chore(QuadraticForm): Fintype -> Finite, DecidableEq #10462

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 6 additions & 3 deletions Mathlib/LinearAlgebra/QuadraticForm/Basic.lean
Original file line number Diff line number Diff line change
Expand Up @@ -1270,20 +1270,23 @@ open Finset BilinForm

variable [CommSemiring R] [AddCommMonoid M] [Module R M]

variable {ι : Type*} [Fintype ι] {v : Basis ι R M}
variable {ι : Type*}

/-- Given a quadratic form `Q` and a basis, `basisRepr` is the basis representation of `Q`. -/
noncomputable def basisRepr (Q : QuadraticForm R M) (v : Basis ι R M) : QuadraticForm R (ι → R) :=
noncomputable def basisRepr [Finite ι] (Q : QuadraticForm R M) (v : Basis ι R M) :
QuadraticForm R (ι → R) :=
Q.comp v.equivFun.symm
#align quadratic_form.basis_repr QuadraticForm.basisRepr

@[simp]
theorem basisRepr_apply (Q : QuadraticForm R M) (w : ι → R) :
theorem basisRepr_apply [Fintype ι] {v : Basis ι R M} (Q : QuadraticForm R M) (w : ι → R) :
Q.basisRepr v w = Q (∑ i : ι, w i • v i) := by
rw [← v.equivFun_symm_apply]
rfl
#align quadratic_form.basis_repr_apply QuadraticForm.basisRepr_apply

variable [Fintype ι] {v : Basis ι R M}

section

variable (R)
Expand Down
5 changes: 3 additions & 2 deletions Mathlib/LinearAlgebra/QuadraticForm/Complex.lean
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ variable {ι : Type*} [Fintype ι]

/-- The isometry between a weighted sum of squares on the complex numbers and the
sum of squares, i.e. `weightedSumSquares` with weights 1 or 0. -/
noncomputable def isometryEquivSumSquares [DecidableEq ι] (w' : ι → ℂ) :
noncomputable def isometryEquivSumSquares (w' : ι → ℂ) :
IsometryEquiv (weightedSumSquares ℂ w')
(weightedSumSquares ℂ (fun i => if w' i = 0 then 0 else 1 : ι → ℂ)) := by
let w i := if h : w' i = 0 then (1 : Units ℂ) else Units.mk0 (w' i) h
Expand All @@ -41,6 +41,7 @@ noncomputable def isometryEquivSumSquares [DecidableEq ι] (w' : ι → ℂ) :
refine' sum_congr rfl fun j hj => _
have hsum : (∑ i : ι, v i • ((isUnit_iff_ne_zero.2 <| hw' i).unit : ℂ) • (Pi.basisFun ℂ ι) i) j =
v j • w j ^ (-(1 / 2 : ℂ)) := by
classical
rw [Finset.sum_apply, sum_eq_single j, Pi.basisFun_apply, IsUnit.unit_spec,
LinearMap.stdBasis_apply, Pi.smul_apply, Pi.smul_apply, Function.update_same, smul_eq_mul,
smul_eq_mul, smul_eq_mul, mul_one]
Expand All @@ -64,7 +65,7 @@ noncomputable def isometryEquivSumSquares [DecidableEq ι] (w' : ι → ℂ) :

/-- The isometry between a weighted sum of squares on the complex numbers and the
sum of squares, i.e. `weightedSumSquares` with weight `fun (i : ι) => 1`. -/
noncomputable def isometryEquivSumSquaresUnits [DecidableEq ι] (w : ι → Units ℂ) :
noncomputable def isometryEquivSumSquaresUnits (w : ι → Units ℂ) :
IsometryEquiv (weightedSumSquares ℂ w) (weightedSumSquares ℂ (1 : ι → ℂ)) := by
simpa using isometryEquivSumSquares ((↑) ∘ w)
#align quadratic_form.isometry_sum_squares_units QuadraticForm.isometryEquivSumSquaresUnits
Expand Down
12 changes: 5 additions & 7 deletions Mathlib/LinearAlgebra/QuadraticForm/Real.lean
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ variable {ι : Type*} [Fintype ι]

/-- The isometry between a weighted sum of squares with weights `u` on the
(non-zero) real numbers and the weighted sum of squares with weights `sign ∘ u`. -/
noncomputable def isometryEquivSignWeightedSumSquares [DecidableEq ι] (w : ι → ℝ) :
noncomputable def isometryEquivSignWeightedSumSquares (w : ι → ℝ) :
IsometryEquiv (weightedSumSquares ℝ w) (weightedSumSquares ℝ (Real.sign ∘ w)) := by
let u i := if h : w i = 0 then (1 : ℝˣ) else Units.mk0 (w i) h
have hu' : ∀ i : ι, (Real.sign (u i) * u i) ^ (-(1 / 2 : ℝ)) ≠ 0 := by
Expand All @@ -47,6 +47,7 @@ noncomputable def isometryEquivSignWeightedSumSquares [DecidableEq ι] (w : ι
have hsum :
(∑ i : ι, v i • ((isUnit_iff_ne_zero.2 <| hu' i).unit : ℝ) • (Pi.basisFun ℝ ι) i) j =
v j • (Real.sign (u j) * u j) ^ (-(1 / 2 : ℝ)) := by
classical
rw [Finset.sum_apply, sum_eq_single j, Pi.basisFun_apply, IsUnit.unit_spec,
LinearMap.stdBasis_apply, Pi.smul_apply, Pi.smul_apply, Function.update_same, smul_eq_mul,
smul_eq_mul, smul_eq_mul, mul_one]
Expand All @@ -63,13 +64,10 @@ noncomputable def isometryEquivSignWeightedSumSquares [DecidableEq ι] (w : ι
have hwu : w j = u j := by simp only [dif_neg h, Units.val_mk0]
simp only [Units.val_mk0]
rw [hwu]
suffices
(u j : ℝ).sign * v j * v j =
suffices (u j : ℝ).sign * v j * v j =
(Real.sign (u j) * u j) ^ (-(1 / 2 : ℝ)) * (Real.sign (u j) * u j) ^ (-(1 / 2 : ℝ)) *
u j *
v j *
v j
by erw [← mul_assoc, this]; ring
u j * v j * v j by
erw [← mul_assoc, this]; ring
rw [← Real.rpow_add (sign_mul_pos_of_ne_zero _ <| Units.ne_zero _),
show -(1 / 2 : ℝ) + -(1 / 2) = -1 by ring, Real.rpow_neg_one, mul_inv, inv_sign,
mul_assoc (Real.sign (u j)) (u j)⁻¹, inv_mul_cancel (Units.ne_zero _), mul_one]
Expand Down