path stringlengths 11 71 | content stringlengths 75 124k |
|---|---|
LinearAlgebra\CliffordAlgebra\Fold.lean | /-
Copyright (c) 2022 Eric Wieser. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Eric Wieser
-/
import Mathlib.LinearAlgebra.CliffordAlgebra.Conjugation
/-!
# Recursive computation rules for the Clifford algebra
This file provides API for a special case `CliffordAlgebra.foldr` of the universal property
`CliffordAlgebra.lift` with `A = Module.End R N` for some arbitrary module `N`. This specialization
resembles the `list.foldr` operation, allowing a bilinear map to be "folded" along the generators.
For convenience, this file also provides `CliffordAlgebra.foldl`, implemented via
`CliffordAlgebra.reverse`
## Main definitions
* `CliffordAlgebra.foldr`: a computation rule for building linear maps out of the clifford
algebra starting on the right, analogous to using `list.foldr` on the generators.
* `CliffordAlgebra.foldl`: a computation rule for building linear maps out of the clifford
algebra starting on the left, analogous to using `list.foldl` on the generators.
## Main statements
* `CliffordAlgebra.right_induction`: an induction rule that adds generators from the right.
* `CliffordAlgebra.left_induction`: an induction rule that adds generators from the left.
-/
universe u1 u2 u3
variable {R M N : Type*}
variable [CommRing R] [AddCommGroup M] [AddCommGroup N]
variable [Module R M] [Module R N]
variable (Q : QuadraticForm R M)
namespace CliffordAlgebra
section Foldr
/-- Fold a bilinear map along the generators of a term of the clifford algebra, with the rule
given by `foldr Q f hf n (ι Q m * x) = f m (foldr Q f hf n x)`.
For example, `foldr f hf n (r • ι R u + ι R v * ι R w) = r • f u n + f v (f w n)`. -/
def foldr (f : M →ₗ[R] N →ₗ[R] N) (hf : ∀ m x, f m (f m x) = Q m • x) :
N →ₗ[R] CliffordAlgebra Q →ₗ[R] N :=
(CliffordAlgebra.lift Q ⟨f, fun v => LinearMap.ext <| hf v⟩).toLinearMap.flip
@[simp]
theorem foldr_ι (f : M →ₗ[R] N →ₗ[R] N) (hf) (n : N) (m : M) : foldr Q f hf n (ι Q m) = f m n :=
LinearMap.congr_fun (lift_ι_apply _ _ _) n
@[simp]
theorem foldr_algebraMap (f : M →ₗ[R] N →ₗ[R] N) (hf) (n : N) (r : R) :
foldr Q f hf n (algebraMap R _ r) = r • n :=
LinearMap.congr_fun (AlgHom.commutes _ r) n
@[simp]
theorem foldr_one (f : M →ₗ[R] N →ₗ[R] N) (hf) (n : N) : foldr Q f hf n 1 = n :=
LinearMap.congr_fun (map_one (lift Q _)) n
@[simp]
theorem foldr_mul (f : M →ₗ[R] N →ₗ[R] N) (hf) (n : N) (a b : CliffordAlgebra Q) :
foldr Q f hf n (a * b) = foldr Q f hf (foldr Q f hf n b) a :=
LinearMap.congr_fun (map_mul (lift Q _) _ _) n
/-- This lemma demonstrates the origin of the `foldr` name. -/
theorem foldr_prod_map_ι (l : List M) (f : M →ₗ[R] N →ₗ[R] N) (hf) (n : N) :
foldr Q f hf n (l.map <| ι Q).prod = List.foldr (fun m n => f m n) n l := by
induction' l with hd tl ih
· rw [List.map_nil, List.prod_nil, List.foldr_nil, foldr_one]
· rw [List.map_cons, List.prod_cons, List.foldr_cons, foldr_mul, foldr_ι, ih]
end Foldr
section Foldl
/-- Fold a bilinear map along the generators of a term of the clifford algebra, with the rule
given by `foldl Q f hf n (ι Q m * x) = f m (foldl Q f hf n x)`.
For example, `foldl f hf n (r • ι R u + ι R v * ι R w) = r • f u n + f v (f w n)`. -/
def foldl (f : M →ₗ[R] N →ₗ[R] N) (hf : ∀ m x, f m (f m x) = Q m • x) :
N →ₗ[R] CliffordAlgebra Q →ₗ[R] N :=
LinearMap.compl₂ (foldr Q f hf) reverse
@[simp]
theorem foldl_reverse (f : M →ₗ[R] N →ₗ[R] N) (hf) (n : N) (x : CliffordAlgebra Q) :
foldl Q f hf n (reverse x) = foldr Q f hf n x :=
DFunLike.congr_arg (foldr Q f hf n) <| reverse_reverse _
@[simp]
theorem foldr_reverse (f : M →ₗ[R] N →ₗ[R] N) (hf) (n : N) (x : CliffordAlgebra Q) :
foldr Q f hf n (reverse x) = foldl Q f hf n x :=
rfl
@[simp]
theorem foldl_ι (f : M →ₗ[R] N →ₗ[R] N) (hf) (n : N) (m : M) : foldl Q f hf n (ι Q m) = f m n := by
rw [← foldr_reverse, reverse_ι, foldr_ι]
@[simp]
theorem foldl_algebraMap (f : M →ₗ[R] N →ₗ[R] N) (hf) (n : N) (r : R) :
foldl Q f hf n (algebraMap R _ r) = r • n := by
rw [← foldr_reverse, reverse.commutes, foldr_algebraMap]
@[simp]
theorem foldl_one (f : M →ₗ[R] N →ₗ[R] N) (hf) (n : N) : foldl Q f hf n 1 = n := by
rw [← foldr_reverse, reverse.map_one, foldr_one]
@[simp]
theorem foldl_mul (f : M →ₗ[R] N →ₗ[R] N) (hf) (n : N) (a b : CliffordAlgebra Q) :
foldl Q f hf n (a * b) = foldl Q f hf (foldl Q f hf n a) b := by
rw [← foldr_reverse, ← foldr_reverse, ← foldr_reverse, reverse.map_mul, foldr_mul]
/-- This lemma demonstrates the origin of the `foldl` name. -/
theorem foldl_prod_map_ι (l : List M) (f : M →ₗ[R] N →ₗ[R] N) (hf) (n : N) :
foldl Q f hf n (l.map <| ι Q).prod = List.foldl (fun m n => f n m) n l := by
rw [← foldr_reverse, reverse_prod_map_ι, ← List.map_reverse, foldr_prod_map_ι, List.foldr_reverse]
end Foldl
@[elab_as_elim]
theorem right_induction {P : CliffordAlgebra Q → Prop} (algebraMap : ∀ r : R, P (algebraMap _ _ r))
(add : ∀ x y, P x → P y → P (x + y)) (mul_ι : ∀ m x, P x → P (x * ι Q m)) : ∀ x, P x := by
/- It would be neat if we could prove this via `foldr` like how we prove
`CliffordAlgebra.induction`, but going via the grading seems easier. -/
intro x
have : x ∈ ⊤ := Submodule.mem_top (R := R)
rw [← iSup_ι_range_eq_top] at this
induction this using Submodule.iSup_induction' with
| mem i x hx =>
induction hx using Submodule.pow_induction_on_right' with
| algebraMap r => exact algebraMap r
| add _x _y _i _ _ ihx ihy => exact add _ _ ihx ihy
| mul_mem _i x _hx px m hm =>
obtain ⟨m, rfl⟩ := hm
exact mul_ι _ _ px
| zero => simpa only [map_zero] using algebraMap 0
| add _x _y _ _ ihx ihy =>
exact add _ _ ihx ihy
@[elab_as_elim]
theorem left_induction {P : CliffordAlgebra Q → Prop} (algebraMap : ∀ r : R, P (algebraMap _ _ r))
(add : ∀ x y, P x → P y → P (x + y)) (ι_mul : ∀ x m, P x → P (ι Q m * x)) : ∀ x, P x := by
refine reverse_involutive.surjective.forall.2 ?_
intro x
induction' x using CliffordAlgebra.right_induction with r x y hx hy m x hx
· simpa only [reverse.commutes] using algebraMap r
· simpa only [map_add] using add _ _ hx hy
· simpa only [reverse.map_mul, reverse_ι] using ι_mul _ _ hx
/-! ### Versions with extra state -/
/-- Auxiliary definition for `CliffordAlgebra.foldr'` -/
def foldr'Aux (f : M →ₗ[R] CliffordAlgebra Q × N →ₗ[R] N) :
M →ₗ[R] Module.End R (CliffordAlgebra Q × N) := by
have v_mul := (Algebra.lmul R (CliffordAlgebra Q)).toLinearMap ∘ₗ ι Q
have l := v_mul.compl₂ (LinearMap.fst _ _ N)
exact
{ toFun := fun m => (l m).prod (f m)
map_add' := fun v₂ v₂ =>
LinearMap.ext fun x =>
Prod.ext (LinearMap.congr_fun (l.map_add _ _) x) (LinearMap.congr_fun (f.map_add _ _) x)
map_smul' := fun c v =>
LinearMap.ext fun x =>
Prod.ext (LinearMap.congr_fun (l.map_smul _ _) x)
(LinearMap.congr_fun (f.map_smul _ _) x) }
theorem foldr'Aux_apply_apply (f : M →ₗ[R] CliffordAlgebra Q × N →ₗ[R] N) (m : M) (x_fx) :
foldr'Aux Q f m x_fx = (ι Q m * x_fx.1, f m x_fx) :=
rfl
theorem foldr'Aux_foldr'Aux (f : M →ₗ[R] CliffordAlgebra Q × N →ₗ[R] N)
(hf : ∀ m x fx, f m (ι Q m * x, f m (x, fx)) = Q m • fx) (v : M) (x_fx) :
foldr'Aux Q f v (foldr'Aux Q f v x_fx) = Q v • x_fx := by
cases' x_fx with x fx
simp only [foldr'Aux_apply_apply]
rw [← mul_assoc, ι_sq_scalar, ← Algebra.smul_def, hf, Prod.smul_mk]
/-- Fold a bilinear map along the generators of a term of the clifford algebra, with the rule
given by `foldr' Q f hf n (ι Q m * x) = f m (x, foldr' Q f hf n x)`.
Note this is like `CliffordAlgebra.foldr`, but with an extra `x` argument.
Implement the recursion scheme `F[n0](m * x) = f(m, (x, F[n0](x)))`. -/
def foldr' (f : M →ₗ[R] CliffordAlgebra Q × N →ₗ[R] N)
(hf : ∀ m x fx, f m (ι Q m * x, f m (x, fx)) = Q m • fx) (n : N) : CliffordAlgebra Q →ₗ[R] N :=
LinearMap.snd _ _ _ ∘ₗ foldr Q (foldr'Aux Q f) (foldr'Aux_foldr'Aux Q _ hf) (1, n)
theorem foldr'_algebraMap (f : M →ₗ[R] CliffordAlgebra Q × N →ₗ[R] N)
(hf : ∀ m x fx, f m (ι Q m * x, f m (x, fx)) = Q m • fx) (n r) :
foldr' Q f hf n (algebraMap R _ r) = r • n :=
congr_arg Prod.snd (foldr_algebraMap _ _ _ _ _)
theorem foldr'_ι (f : M →ₗ[R] CliffordAlgebra Q × N →ₗ[R] N)
(hf : ∀ m x fx, f m (ι Q m * x, f m (x, fx)) = Q m • fx) (n m) :
foldr' Q f hf n (ι Q m) = f m (1, n) :=
congr_arg Prod.snd (foldr_ι _ _ _ _ _)
theorem foldr'_ι_mul (f : M →ₗ[R] CliffordAlgebra Q × N →ₗ[R] N)
(hf : ∀ m x fx, f m (ι Q m * x, f m (x, fx)) = Q m • fx) (n m) (x) :
foldr' Q f hf n (ι Q m * x) = f m (x, foldr' Q f hf n x) := by
dsimp [foldr']
rw [foldr_mul, foldr_ι, foldr'Aux_apply_apply]
refine congr_arg (f m) (Prod.mk.eta.symm.trans ?_)
congr 1
induction x using CliffordAlgebra.left_induction with
| algebraMap r => simp_rw [foldr_algebraMap, Prod.smul_mk, Algebra.algebraMap_eq_smul_one]
| add x y hx hy => rw [map_add, Prod.fst_add, hx, hy]
| ι_mul m x hx => rw [foldr_mul, foldr_ι, foldr'Aux_apply_apply, hx]
end CliffordAlgebra
|
LinearAlgebra\CliffordAlgebra\Grading.lean | /-
Copyright (c) 2021 Eric Wieser. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Eric Wieser
-/
import Mathlib.LinearAlgebra.CliffordAlgebra.Basic
import Mathlib.Data.ZMod.Basic
import Mathlib.RingTheory.GradedAlgebra.Basic
/-!
# Results about the grading structure of the clifford algebra
The main result is `CliffordAlgebra.gradedAlgebra`, which says that the clifford algebra is a
ℤ₂-graded algebra (or "superalgebra").
-/
namespace CliffordAlgebra
variable {R M : Type*} [CommRing R] [AddCommGroup M] [Module R M]
variable {Q : QuadraticForm R M}
open scoped DirectSum
variable (Q)
/-- The even or odd submodule, defined as the supremum of the even or odd powers of
`(ι Q).range`. `evenOdd 0` is the even submodule, and `evenOdd 1` is the odd submodule. -/
def evenOdd (i : ZMod 2) : Submodule R (CliffordAlgebra Q) :=
⨆ j : { n : ℕ // ↑n = i }, LinearMap.range (ι Q) ^ (j : ℕ)
theorem one_le_evenOdd_zero : 1 ≤ evenOdd Q 0 := by
refine le_trans ?_ (le_iSup _ ⟨0, Nat.cast_zero⟩)
exact (pow_zero _).ge
theorem range_ι_le_evenOdd_one : LinearMap.range (ι Q) ≤ evenOdd Q 1 := by
refine le_trans ?_ (le_iSup _ ⟨1, Nat.cast_one⟩)
exact (pow_one _).ge
theorem ι_mem_evenOdd_one (m : M) : ι Q m ∈ evenOdd Q 1 :=
range_ι_le_evenOdd_one Q <| LinearMap.mem_range_self _ m
theorem ι_mul_ι_mem_evenOdd_zero (m₁ m₂ : M) : ι Q m₁ * ι Q m₂ ∈ evenOdd Q 0 :=
Submodule.mem_iSup_of_mem ⟨2, rfl⟩
(by
rw [Subtype.coe_mk, pow_two]
exact
Submodule.mul_mem_mul (LinearMap.mem_range_self (ι Q) m₁)
(LinearMap.mem_range_self (ι Q) m₂))
theorem evenOdd_mul_le (i j : ZMod 2) : evenOdd Q i * evenOdd Q j ≤ evenOdd Q (i + j) := by
simp_rw [evenOdd, Submodule.iSup_eq_span, Submodule.span_mul_span]
apply Submodule.span_mono
simp_rw [Set.iUnion_mul, Set.mul_iUnion, Set.iUnion_subset_iff, Set.mul_subset_iff]
rintro ⟨xi, rfl⟩ ⟨yi, rfl⟩ x hx y hy
refine Set.mem_iUnion.mpr ⟨⟨xi + yi, Nat.cast_add _ _⟩, ?_⟩
simp only [Subtype.coe_mk, Nat.cast_add, pow_add]
exact Submodule.mul_mem_mul hx hy
instance evenOdd.gradedMonoid : SetLike.GradedMonoid (evenOdd Q) where
one_mem := Submodule.one_le.mp (one_le_evenOdd_zero Q)
mul_mem _i _j _p _q hp hq := Submodule.mul_le.mp (evenOdd_mul_le Q _ _) _ hp _ hq
/-- A version of `CliffordAlgebra.ι` that maps directly into the graded structure. This is
primarily an auxiliary construction used to provide `CliffordAlgebra.gradedAlgebra`. -/
-- Porting note: added `protected`
protected def GradedAlgebra.ι : M →ₗ[R] ⨁ i : ZMod 2, evenOdd Q i :=
DirectSum.lof R (ZMod 2) (fun i => ↥(evenOdd Q i)) 1 ∘ₗ (ι Q).codRestrict _ (ι_mem_evenOdd_one Q)
theorem GradedAlgebra.ι_apply (m : M) :
GradedAlgebra.ι Q m = DirectSum.of (fun i => ↥(evenOdd Q i)) 1 ⟨ι Q m, ι_mem_evenOdd_one Q m⟩ :=
rfl
nonrec theorem GradedAlgebra.ι_sq_scalar (m : M) :
GradedAlgebra.ι Q m * GradedAlgebra.ι Q m = algebraMap R _ (Q m) := by
rw [GradedAlgebra.ι_apply Q, DirectSum.of_mul_of, DirectSum.algebraMap_apply]
exact DirectSum.of_eq_of_gradedMonoid_eq (Sigma.subtype_ext rfl <| ι_sq_scalar _ _)
set_option linter.deprecated false in
theorem GradedAlgebra.lift_ι_eq (i' : ZMod 2) (x' : evenOdd Q i') :
-- Porting note: added a second `by apply`
lift Q ⟨by apply GradedAlgebra.ι Q, by apply GradedAlgebra.ι_sq_scalar Q⟩ x' =
DirectSum.of (fun i => evenOdd Q i) i' x' := by
cases' x' with x' hx'
dsimp only [Subtype.coe_mk, DirectSum.lof_eq_of]
induction hx' using Submodule.iSup_induction' with
| mem i x hx =>
obtain ⟨i, rfl⟩ := i
-- Porting note: `dsimp only [Subtype.coe_mk] at hx` doesn't work, use `change` instead
change x ∈ LinearMap.range (ι Q) ^ i at hx
induction hx using Submodule.pow_induction_on_left' with
| algebraMap r =>
rw [AlgHom.commutes, DirectSum.algebraMap_apply]; rfl
| add x y i hx hy ihx ihy =>
-- Note: in #8386 `map_add` had to be specialized to avoid a timeout
-- (the definition was already very slow)
rw [AlgHom.map_add, ihx, ihy, ← AddMonoidHom.map_add]
rfl
| mem_mul m hm i x hx ih =>
obtain ⟨_, rfl⟩ := hm
rw [AlgHom.map_mul, ih, lift_ι_apply, GradedAlgebra.ι_apply Q, DirectSum.of_mul_of]
refine DirectSum.of_eq_of_gradedMonoid_eq (Sigma.subtype_ext ?_ ?_) <;>
dsimp only [GradedMonoid.mk, Subtype.coe_mk]
· rw [Nat.succ_eq_add_one, add_comm, Nat.cast_add, Nat.cast_one]
rfl
| zero =>
rw [AlgHom.map_zero]
apply Eq.symm
apply DFinsupp.single_eq_zero.mpr; rfl
| add x y hx hy ihx ihy =>
rw [AlgHom.map_add, ihx, ihy, ← AddMonoidHom.map_add]; rfl
/-- The clifford algebra is graded by the even and odd parts. -/
instance gradedAlgebra : GradedAlgebra (evenOdd Q) :=
GradedAlgebra.ofAlgHom (evenOdd Q)
-- while not necessary, the `by apply` makes this elaborate faster
(lift Q ⟨by apply GradedAlgebra.ι Q, by apply GradedAlgebra.ι_sq_scalar Q⟩)
-- the proof from here onward is mostly similar to the `TensorAlgebra` case, with some extra
-- handling for the `iSup` in `evenOdd`.
(by
ext m
dsimp only [LinearMap.comp_apply, AlgHom.toLinearMap_apply, AlgHom.comp_apply,
AlgHom.id_apply]
rw [lift_ι_apply, GradedAlgebra.ι_apply Q, DirectSum.coeAlgHom_of, Subtype.coe_mk])
(by apply GradedAlgebra.lift_ι_eq Q)
theorem iSup_ι_range_eq_top : ⨆ i : ℕ, LinearMap.range (ι Q) ^ i = ⊤ := by
rw [← (DirectSum.Decomposition.isInternal (evenOdd Q)).submodule_iSup_eq_top, eq_comm]
calc
-- Porting note: needs extra annotations, no longer unifies against the goal in the face of
-- ambiguity
⨆ (i : ZMod 2) (j : { n : ℕ // ↑n = i }), LinearMap.range (ι Q) ^ (j : ℕ) =
⨆ i : Σ i : ZMod 2, { n : ℕ // ↑n = i }, LinearMap.range (ι Q) ^ (i.2 : ℕ) := by
rw [iSup_sigma]
_ = ⨆ i : ℕ, LinearMap.range (ι Q) ^ i :=
Function.Surjective.iSup_congr (fun i => i.2) (fun i => ⟨⟨_, i, rfl⟩, rfl⟩) fun _ => rfl
theorem evenOdd_isCompl : IsCompl (evenOdd Q 0) (evenOdd Q 1) :=
(DirectSum.Decomposition.isInternal (evenOdd Q)).isCompl zero_ne_one <| by
have : (Finset.univ : Finset (ZMod 2)) = {0, 1} := rfl
simpa using congr_arg ((↑) : Finset (ZMod 2) → Set (ZMod 2)) this
/-- To show a property is true on the even or odd part, it suffices to show it is true on the
scalars or vectors (respectively), closed under addition, and under left-multiplication by a pair
of vectors. -/
@[elab_as_elim]
theorem evenOdd_induction (n : ZMod 2) {motive : ∀ x, x ∈ evenOdd Q n → Prop}
(range_ι_pow : ∀ (v) (h : v ∈ LinearMap.range (ι Q) ^ n.val),
motive v (Submodule.mem_iSup_of_mem ⟨n.val, n.natCast_zmod_val⟩ h))
(add : ∀ x y hx hy, motive x hx → motive y hy → motive (x + y) (Submodule.add_mem _ hx hy))
(ι_mul_ι_mul :
∀ m₁ m₂ x hx,
motive x hx →
motive (ι Q m₁ * ι Q m₂ * x)
(zero_add n ▸ SetLike.mul_mem_graded (ι_mul_ι_mem_evenOdd_zero Q m₁ m₂) hx))
(x : CliffordAlgebra Q) (hx : x ∈ evenOdd Q n) : motive x hx := by
apply Submodule.iSup_induction' (C := motive) _ (range_ι_pow 0 (Submodule.zero_mem _)) add
refine Subtype.rec ?_
simp_rw [ZMod.natCast_eq_iff, add_comm n.val]
rintro n' ⟨k, rfl⟩ xv
simp_rw [pow_add, pow_mul]
intro hxv
induction hxv using Submodule.mul_induction_on' with
| mem_mul_mem a ha b hb =>
induction ha using Submodule.pow_induction_on_left' with
| algebraMap r =>
simp_rw [← Algebra.smul_def]
exact range_ι_pow _ (Submodule.smul_mem _ _ hb)
| add x y n hx hy ihx ihy =>
simp_rw [add_mul]
apply add _ _ _ _ ihx ihy
| mem_mul x hx n'' y hy ihy =>
revert hx
simp_rw [pow_two]
intro hx2
induction hx2 using Submodule.mul_induction_on' with
| mem_mul_mem m hm n hn =>
simp_rw [LinearMap.mem_range] at hm hn
obtain ⟨m₁, rfl⟩ := hm; obtain ⟨m₂, rfl⟩ := hn
simp_rw [mul_assoc _ y b]
exact ι_mul_ι_mul _ _ _ _ ihy
| add x hx y hy ihx ihy =>
simp_rw [add_mul]
apply add _ _ _ _ ihx ihy
| add x y hx hy ihx ihy =>
apply add _ _ _ _ ihx ihy
/-- To show a property is true on the even parts, it suffices to show it is true on the
scalars, closed under addition, and under left-multiplication by a pair of vectors. -/
@[elab_as_elim]
theorem even_induction {motive : ∀ x, x ∈ evenOdd Q 0 → Prop}
(algebraMap : ∀ r : R, motive (algebraMap _ _ r) (SetLike.algebraMap_mem_graded _ _))
(add : ∀ x y hx hy, motive x hx → motive y hy → motive (x + y) (Submodule.add_mem _ hx hy))
(ι_mul_ι_mul :
∀ m₁ m₂ x hx,
motive x hx →
motive (ι Q m₁ * ι Q m₂ * x)
(zero_add (0 : ZMod 2) ▸ SetLike.mul_mem_graded (ι_mul_ι_mem_evenOdd_zero Q m₁ m₂) hx))
(x : CliffordAlgebra Q) (hx : x ∈ evenOdd Q 0) : motive x hx := by
refine evenOdd_induction (motive := motive) (fun rx => ?_) add ι_mul_ι_mul x hx
rintro ⟨r, rfl⟩
exact algebraMap r
/-- To show a property is true on the odd parts, it suffices to show it is true on the
vectors, closed under addition, and under left-multiplication by a pair of vectors. -/
@[elab_as_elim]
theorem odd_induction {P : ∀ x, x ∈ evenOdd Q 1 → Prop}
(ι : ∀ v, P (ι Q v) (ι_mem_evenOdd_one _ _))
(add : ∀ x y hx hy, P x hx → P y hy → P (x + y) (Submodule.add_mem _ hx hy))
(ι_mul_ι_mul :
∀ m₁ m₂ x hx,
P x hx →
P (CliffordAlgebra.ι Q m₁ * CliffordAlgebra.ι Q m₂ * x)
(zero_add (1 : ZMod 2) ▸ SetLike.mul_mem_graded (ι_mul_ι_mem_evenOdd_zero Q m₁ m₂) hx))
(x : CliffordAlgebra Q) (hx : x ∈ evenOdd Q 1) : P x hx := by
refine evenOdd_induction (motive := P) (fun ιv => ?_) add ι_mul_ι_mul x hx
-- Porting note: was `simp_rw [ZMod.val_one, pow_one]`, lean4#1926
intro h; rw [ZMod.val_one, pow_one] at h; revert h
rintro ⟨v, rfl⟩
exact ι v
end CliffordAlgebra
|
LinearAlgebra\CliffordAlgebra\Inversion.lean | /-
Copyright (c) 2022 Eric Wieser. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Eric Wieser
-/
import Mathlib.LinearAlgebra.CliffordAlgebra.Contraction
/-! # Results about inverses in Clifford algebras
This contains some basic results about the inversion of vectors, related to the fact that
$ι(m)^{-1} = \frac{ι(m)}{Q(m)}$.
-/
variable {R M : Type*}
variable [CommRing R] [AddCommGroup M] [Module R M] {Q : QuadraticForm R M}
namespace CliffordAlgebra
variable (Q)
/-- If the quadratic form of a vector is invertible, then so is that vector. -/
def invertibleιOfInvertible (m : M) [Invertible (Q m)] : Invertible (ι Q m) where
invOf := ι Q (⅟ (Q m) • m)
invOf_mul_self := by
rw [map_smul, smul_mul_assoc, ι_sq_scalar, Algebra.smul_def, ← map_mul, invOf_mul_self, map_one]
mul_invOf_self := by
rw [map_smul, mul_smul_comm, ι_sq_scalar, Algebra.smul_def, ← map_mul, invOf_mul_self, map_one]
/-- For a vector with invertible quadratic form, $v^{-1} = \frac{v}{Q(v)}$ -/
theorem invOf_ι (m : M) [Invertible (Q m)] [Invertible (ι Q m)] :
⅟ (ι Q m) = ι Q (⅟ (Q m) • m) := by
letI := invertibleιOfInvertible Q m
convert (rfl : ⅟ (ι Q m) = _)
theorem isUnit_ι_of_isUnit {m : M} (h : IsUnit (Q m)) : IsUnit (ι Q m) := by
cases h.nonempty_invertible
letI := invertibleιOfInvertible Q m
exact isUnit_of_invertible (ι Q m)
/-- $aba^{-1}$ is a vector. -/
theorem ι_mul_ι_mul_invOf_ι (a b : M) [Invertible (ι Q a)] [Invertible (Q a)] :
ι Q a * ι Q b * ⅟ (ι Q a) = ι Q ((⅟ (Q a) * QuadraticMap.polar Q a b) • a - b) := by
rw [invOf_ι, map_smul, mul_smul_comm, ι_mul_ι_mul_ι, ← map_smul, smul_sub, smul_smul, smul_smul,
invOf_mul_self, one_smul]
/-- $a^{-1}ba$ is a vector. -/
theorem invOf_ι_mul_ι_mul_ι (a b : M) [Invertible (ι Q a)] [Invertible (Q a)] :
⅟ (ι Q a) * ι Q b * ι Q a = ι Q ((⅟ (Q a) * QuadraticMap.polar Q a b) • a - b) := by
rw [invOf_ι, map_smul, smul_mul_assoc, smul_mul_assoc, ι_mul_ι_mul_ι, ← map_smul, smul_sub,
smul_smul, smul_smul, invOf_mul_self, one_smul]
section
variable [Invertible (2 : R)]
/-- Over a ring where `2` is invertible, `Q m` is invertible whenever `ι Q m`. -/
def invertibleOfInvertibleι (m : M) [Invertible (ι Q m)] : Invertible (Q m) :=
ExteriorAlgebra.invertibleAlgebraMapEquiv M (Q m) <|
.algebraMapOfInvertibleAlgebraMap (equivExterior Q).toLinearMap (by simp) <|
.copy (.mul ‹Invertible (ι Q m)› ‹Invertible (ι Q m)›) _ (ι_sq_scalar _ _).symm
theorem isUnit_of_isUnit_ι {m : M} (h : IsUnit (ι Q m)) : IsUnit (Q m) := by
cases h.nonempty_invertible
letI := invertibleOfInvertibleι Q m
exact isUnit_of_invertible (Q m)
@[simp] theorem isUnit_ι_iff {m : M} : IsUnit (ι Q m) ↔ IsUnit (Q m) :=
⟨isUnit_of_isUnit_ι Q, isUnit_ι_of_isUnit Q⟩
end
end CliffordAlgebra
|
LinearAlgebra\CliffordAlgebra\Prod.lean | /-
Copyright (c) 2023 Eric Wieser. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Eric Wieser
-/
import Mathlib.LinearAlgebra.CliffordAlgebra.Grading
import Mathlib.LinearAlgebra.TensorProduct.Graded.Internal
import Mathlib.LinearAlgebra.QuadraticForm.Prod
/-!
# Clifford algebras of a direct sum of two vector spaces
We show that the Clifford algebra of a direct sum is the graded tensor product of the Clifford
algebras, as `CliffordAlgebra.equivProd`.
## Main definitions:
* `CliffordAlgebra.equivProd : CliffordAlgebra (Q₁.prod Q₂) ≃ₐ[R] (evenOdd Q₁ ᵍ⊗[R] evenOdd Q₂)`
## TODO
Introduce morphisms and equivalences of graded algebas, and upgrade `CliffordAlgebra.equivProd` to a
graded algebra equivalence.
-/
suppress_compilation
variable {R M₁ M₂ N : Type*}
variable [CommRing R] [AddCommGroup M₁] [AddCommGroup M₂] [AddCommGroup N]
variable [Module R M₁] [Module R M₂] [Module R N]
variable (Q₁ : QuadraticForm R M₁) (Q₂ : QuadraticForm R M₂) (Qₙ : QuadraticForm R N)
open scoped TensorProduct
namespace CliffordAlgebra
section map_mul_map
variable {Q₁ Q₂ Qₙ}
variable (f₁ : Q₁ →qᵢ Qₙ) (f₂ : Q₂ →qᵢ Qₙ) (hf : ∀ x y, Qₙ.IsOrtho (f₁ x) (f₂ y))
variable (m₁ : CliffordAlgebra Q₁) (m₂ : CliffordAlgebra Q₂)
/-- If `m₁` and `m₂` are both homogenous,
and the quadratic spaces `Q₁` and `Q₂` map into
orthogonal subspaces of `Qₙ` (for instance, when `Qₙ = Q₁.prod Q₂`),
then the product of the embedding in `CliffordAlgebra Q` commutes up to a sign factor. -/
nonrec theorem map_mul_map_of_isOrtho_of_mem_evenOdd
{i₁ i₂ : ZMod 2} (hm₁ : m₁ ∈ evenOdd Q₁ i₁) (hm₂ : m₂ ∈ evenOdd Q₂ i₂) :
map f₁ m₁ * map f₂ m₂ = (-1 : ℤˣ) ^ (i₂ * i₁) • (map f₂ m₂ * map f₁ m₁) := by
-- the strategy; for each variable, induct on powers of `ι`, then on the exponent of each
-- power.
induction hm₁ using Submodule.iSup_induction' with
| zero => rw [map_zero, zero_mul, mul_zero, smul_zero]
| add _ _ _ _ ihx ihy => rw [map_add, add_mul, mul_add, ihx, ihy, smul_add]
| mem i₁' m₁' hm₁ =>
obtain ⟨i₁n, rfl⟩ := i₁'
dsimp only at *
induction hm₁ using Submodule.pow_induction_on_left' with
| algebraMap =>
rw [AlgHom.commutes, Nat.cast_zero, mul_zero, uzpow_zero, one_smul, Algebra.commutes]
| add _ _ _ _ _ ihx ihy =>
rw [map_add, add_mul, mul_add, ihx, ihy, smul_add]
| mem_mul m₁ hm₁ i x₁ _hx₁ ih₁ =>
obtain ⟨v₁, rfl⟩ := hm₁
-- this is the first interesting goal
rw [map_mul, mul_assoc, ih₁, mul_smul_comm, map_apply_ι, Nat.cast_succ, mul_add_one,
uzpow_add, mul_smul, ← mul_assoc, ← mul_assoc, ← smul_mul_assoc ((-1) ^ i₂)]
clear ih₁
congr 2
induction hm₂ using Submodule.iSup_induction' with
| zero => rw [map_zero, zero_mul, mul_zero, smul_zero]
| add _ _ _ _ ihx ihy => rw [map_add, add_mul, mul_add, ihx, ihy, smul_add]
| mem i₂' m₂' hm₂ =>
clear m₂
obtain ⟨i₂n, rfl⟩ := i₂'
dsimp only at *
induction hm₂ using Submodule.pow_induction_on_left' with
| algebraMap =>
rw [AlgHom.commutes, Nat.cast_zero, uzpow_zero, one_smul, Algebra.commutes]
| add _ _ _ _ _ ihx ihy =>
rw [map_add, add_mul, mul_add, ihx, ihy, smul_add]
| mem_mul m₂ hm₂ i x₂ _hx₂ ih₂ =>
obtain ⟨v₂, rfl⟩ := hm₂
-- this is the second interesting goal
rw [map_mul, map_apply_ι, Nat.cast_succ, ← mul_assoc,
ι_mul_ι_comm_of_isOrtho (hf _ _), neg_mul, mul_assoc, ih₂, mul_smul_comm,
← mul_assoc, ← Units.neg_smul, uzpow_add, uzpow_one, mul_neg_one]
theorem commute_map_mul_map_of_isOrtho_of_mem_evenOdd_zero_left
{i₂ : ZMod 2} (hm₁ : m₁ ∈ evenOdd Q₁ 0) (hm₂ : m₂ ∈ evenOdd Q₂ i₂) :
Commute (map f₁ m₁) (map f₂ m₂) :=
(map_mul_map_of_isOrtho_of_mem_evenOdd _ _ hf _ _ hm₁ hm₂).trans <| by simp
theorem commute_map_mul_map_of_isOrtho_of_mem_evenOdd_zero_right
{i₁ : ZMod 2} (hm₁ : m₁ ∈ evenOdd Q₁ i₁) (hm₂ : m₂ ∈ evenOdd Q₂ 0) :
Commute (map f₁ m₁) (map f₂ m₂) :=
(map_mul_map_of_isOrtho_of_mem_evenOdd _ _ hf _ _ hm₁ hm₂).trans <| by simp
theorem map_mul_map_eq_neg_of_isOrtho_of_mem_evenOdd_one
(hm₁ : m₁ ∈ evenOdd Q₁ 1) (hm₂ : m₂ ∈ evenOdd Q₂ 1) :
map f₁ m₁ * map f₂ m₂ = - map f₂ m₂ * map f₁ m₁ := by
simp [map_mul_map_of_isOrtho_of_mem_evenOdd _ _ hf _ _ hm₁ hm₂]
end map_mul_map
/-- The forward direction of `CliffordAlgebra.prodEquiv`. -/
def ofProd : CliffordAlgebra (Q₁.prod Q₂) →ₐ[R] (evenOdd Q₁ ᵍ⊗[R] evenOdd Q₂) :=
lift _ ⟨
LinearMap.coprod
((GradedTensorProduct.includeLeft (evenOdd Q₁) (evenOdd Q₂)).toLinearMap
∘ₗ (evenOdd Q₁ 1).subtype ∘ₗ (ι Q₁).codRestrict _ (ι_mem_evenOdd_one Q₁))
((GradedTensorProduct.includeRight (evenOdd Q₁) (evenOdd Q₂)).toLinearMap
∘ₗ (evenOdd Q₂ 1).subtype ∘ₗ (ι Q₂).codRestrict _ (ι_mem_evenOdd_one Q₂)),
fun m => by
simp_rw [LinearMap.coprod_apply, LinearMap.coe_comp, Function.comp_apply,
AlgHom.toLinearMap_apply, QuadraticMap.prod_apply, Submodule.coeSubtype,
GradedTensorProduct.includeLeft_apply, GradedTensorProduct.includeRight_apply, map_add,
add_mul, mul_add, GradedTensorProduct.algebraMap_def,
GradedTensorProduct.tmul_one_mul_one_tmul, GradedTensorProduct.tmul_one_mul_coe_tmul,
GradedTensorProduct.tmul_coe_mul_one_tmul, GradedTensorProduct.tmul_coe_mul_coe_tmul,
LinearMap.codRestrict_apply, one_mul, uzpow_one, Units.neg_smul, one_smul, ι_sq_scalar,
mul_one, ← GradedTensorProduct.algebraMap_def, ← GradedTensorProduct.algebraMap_def']
abel⟩
@[simp]
lemma ofProd_ι_mk (m₁ : M₁) (m₂ : M₂) :
ofProd Q₁ Q₂ (ι _ (m₁, m₂)) = ι Q₁ m₁ ᵍ⊗ₜ 1 + 1 ᵍ⊗ₜ ι Q₂ m₂ := by
rw [ofProd, lift_ι_apply]
rfl
/-- The reverse direction of `CliffordAlgebra.prodEquiv`. -/
def toProd : evenOdd Q₁ ᵍ⊗[R] evenOdd Q₂ →ₐ[R] CliffordAlgebra (Q₁.prod Q₂) :=
GradedTensorProduct.lift _ _
(CliffordAlgebra.map <| .inl _ _)
(CliffordAlgebra.map <| .inr _ _)
fun _i₁ _i₂ x₁ x₂ => map_mul_map_of_isOrtho_of_mem_evenOdd _ _ (QuadraticMap.IsOrtho.inl_inr) _
_ x₁.prop x₂.prop
@[simp]
lemma toProd_ι_tmul_one (m₁ : M₁) : toProd Q₁ Q₂ (ι _ m₁ ᵍ⊗ₜ 1) = ι _ (m₁, 0) := by
rw [toProd, GradedTensorProduct.lift_tmul, map_one, mul_one, map_apply_ι,
QuadraticMap.Isometry.inl_apply]
@[simp]
lemma toProd_one_tmul_ι (m₂ : M₂) : toProd Q₁ Q₂ (1 ᵍ⊗ₜ ι _ m₂) = ι _ (0, m₂) := by
rw [toProd, GradedTensorProduct.lift_tmul, map_one, one_mul, map_apply_ι,
QuadraticMap.Isometry.inr_apply]
lemma toProd_comp_ofProd : (toProd Q₁ Q₂).comp (ofProd Q₁ Q₂) = AlgHom.id _ _ := by
ext m <;> dsimp
· rw [ofProd_ι_mk, map_add, toProd_one_tmul_ι, toProd_ι_tmul_one, ← Prod.zero_eq_mk,
LinearMap.map_zero, add_zero]
· rw [ofProd_ι_mk, map_add, toProd_one_tmul_ι, toProd_ι_tmul_one, ← Prod.zero_eq_mk,
LinearMap.map_zero, zero_add]
lemma ofProd_comp_toProd : (ofProd Q₁ Q₂).comp (toProd Q₁ Q₂) = AlgHom.id _ _ := by
ext <;> (dsimp; simp)
/-- The Clifford algebra over an orthogonal direct sum of quadratic vector spaces is isomorphic
as an algebra to the graded tensor product of the Clifford algebras of each space.
This is `CliffordAlgebra.toProd` and `CliffordAlgebra.ofProd` as an equivalence. -/
@[simps!]
def prodEquiv : CliffordAlgebra (Q₁.prod Q₂) ≃ₐ[R] (evenOdd Q₁ ᵍ⊗[R] evenOdd Q₂) :=
AlgEquiv.ofAlgHom (ofProd Q₁ Q₂) (toProd Q₁ Q₂) (ofProd_comp_toProd _ _) (toProd_comp_ofProd _ _)
end CliffordAlgebra
|
LinearAlgebra\CliffordAlgebra\Star.lean | /-
Copyright (c) 2022 Eric Wieser. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Eric Wieser
-/
import Mathlib.LinearAlgebra.CliffordAlgebra.Conjugation
/-!
# Star structure on `CliffordAlgebra`
This file defines the "clifford conjugation", equal to `reverse (involute x)`, and assigns it the
`star` notation.
This choice is somewhat non-canonical; a star structure is also possible under `reverse` alone.
However, defining it gives us access to constructions like `unitary`.
Most results about `star` can be obtained by unfolding it via `CliffordAlgebra.star_def`.
## Main definitions
* `CliffordAlgebra.instStarRing`
-/
variable {R : Type*} [CommRing R]
variable {M : Type*} [AddCommGroup M] [Module R M]
variable {Q : QuadraticForm R M}
namespace CliffordAlgebra
instance instStarRing : StarRing (CliffordAlgebra Q) where
star x := reverse (involute x)
star_involutive x := by
simp only [reverse_involute_commute.eq, reverse_reverse, involute_involute]
star_mul x y := by simp only [map_mul, reverse.map_mul]
star_add x y := by simp only [map_add]
theorem star_def (x : CliffordAlgebra Q) : star x = reverse (involute x) :=
rfl
theorem star_def' (x : CliffordAlgebra Q) : star x = involute (reverse x) :=
reverse_involute _
@[simp]
theorem star_ι (m : M) : star (ι Q m) = -ι Q m := by rw [star_def, involute_ι, map_neg, reverse_ι]
/-- Note that this not match the `star_smul` implied by `StarModule`; it certainly could if we
also conjugated all the scalars, but there appears to be nothing in the literature that advocates
doing this. -/
@[simp]
theorem star_smul (r : R) (x : CliffordAlgebra Q) : star (r • x) = r • star x := by
rw [star_def, star_def, map_smul, map_smul]
@[simp]
theorem star_algebraMap (r : R) :
star (algebraMap R (CliffordAlgebra Q) r) = algebraMap R (CliffordAlgebra Q) r := by
rw [star_def, involute.commutes, reverse.commutes]
end CliffordAlgebra
|
LinearAlgebra\Dimension\Basic.lean | /-
Copyright (c) 2018 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro, Johannes Hölzl, Sander Dahmen, Scott Morrison
-/
import Mathlib.LinearAlgebra.LinearIndependent
/-!
# Dimension of modules and vector spaces
## Main definitions
* The rank of a module is defined as `Module.rank : Cardinal`.
This is defined as the supremum of the cardinalities of linearly independent subsets.
## Main statements
* `LinearMap.rank_le_of_injective`: the source of an injective linear map has dimension
at most that of the target.
* `LinearMap.rank_le_of_surjective`: the target of a surjective linear map has dimension
at most that of that source.
## Implementation notes
Many theorems in this file are not universe-generic when they relate dimensions
in different universes. They should be as general as they can be without
inserting `lift`s. The types `M`, `M'`, ... all live in different universes,
and `M₁`, `M₂`, ... all live in the same universe.
-/
noncomputable section
universe w w' u u' v v'
variable {R : Type u} {R' : Type u'} {M M₁ : Type v} {M' : Type v'}
open Cardinal Submodule Function Set
section Module
section
variable [Semiring R] [AddCommMonoid M] [Module R M]
variable (R M)
/-- The rank of a module, defined as a term of type `Cardinal`.
We define this as the supremum of the cardinalities of linearly independent subsets.
For a free module over any ring satisfying the strong rank condition
(e.g. left-noetherian rings, commutative rings, and in particular division rings and fields),
this is the same as the dimension of the space (i.e. the cardinality of any basis).
In particular this agrees with the usual notion of the dimension of a vector space.
-/
protected irreducible_def Module.rank : Cardinal :=
⨆ ι : { s : Set M // LinearIndependent R ((↑) : s → M) }, (#ι.1)
theorem rank_le_card : Module.rank R M ≤ #M :=
(Module.rank_def _ _).trans_le (ciSup_le' fun _ ↦ mk_set_le _)
lemma nonempty_linearIndependent_set : Nonempty {s : Set M // LinearIndependent R ((↑) : s → M)} :=
⟨⟨∅, linearIndependent_empty _ _⟩⟩
end
namespace LinearIndependent
variable [Ring R] [AddCommGroup M] [Module R M]
variable [Nontrivial R]
theorem cardinal_lift_le_rank {ι : Type w} {v : ι → M}
(hv : LinearIndependent R v) :
Cardinal.lift.{v} #ι ≤ Cardinal.lift.{w} (Module.rank R M) := by
rw [Module.rank]
refine le_trans ?_ (lift_le.mpr <| le_ciSup (bddAbove_range.{v, v} _) ⟨_, hv.coe_range⟩)
exact lift_mk_le'.mpr ⟨(Equiv.ofInjective _ hv.injective).toEmbedding⟩
lemma aleph0_le_rank {ι : Type w} [Infinite ι] {v : ι → M}
(hv : LinearIndependent R v) : ℵ₀ ≤ Module.rank R M :=
aleph0_le_lift.mp <| (aleph0_le_lift.mpr <| aleph0_le_mk ι).trans hv.cardinal_lift_le_rank
theorem cardinal_le_rank {ι : Type v} {v : ι → M}
(hv : LinearIndependent R v) : #ι ≤ Module.rank R M := by
simpa using hv.cardinal_lift_le_rank
theorem cardinal_le_rank' {s : Set M}
(hs : LinearIndependent R (fun x => x : s → M)) : #s ≤ Module.rank R M :=
hs.cardinal_le_rank
end LinearIndependent
@[deprecated (since := "2023-12-27")]
alias cardinal_lift_le_rank_of_linearIndependent := LinearIndependent.cardinal_lift_le_rank
@[deprecated (since := "2023-12-27")]
alias cardinal_lift_le_rank_of_linearIndependent' := LinearIndependent.cardinal_lift_le_rank
@[deprecated (since := "2023-12-27")]
alias cardinal_le_rank_of_linearIndependent := LinearIndependent.cardinal_le_rank
@[deprecated (since := "2023-12-27")]
alias cardinal_le_rank_of_linearIndependent' := LinearIndependent.cardinal_le_rank'
section SurjectiveInjective
section Module
variable [Ring R] [AddCommGroup M] [Module R M] [Ring R']
section
variable [AddCommGroup M'] [Module R' M']
/-- If `M / R` and `M' / R'` are modules, `i : R' → R` is a map which sends non-zero elements to
non-zero elements, `j : M →+ M'` is an injective group homomorphism, such that the scalar
multiplications on `M` and `M'` are compatible, then the rank of `M / R` is smaller than or equal to
the rank of `M' / R'`. As a special case, taking `R = R'` it is
`LinearMap.lift_rank_le_of_injective`. -/
theorem lift_rank_le_of_injective_injective (i : R' → R) (j : M →+ M')
(hi : ∀ r, i r = 0 → r = 0) (hj : Injective j)
(hc : ∀ (r : R') (m : M), j (i r • m) = r • j m) :
lift.{v'} (Module.rank R M) ≤ lift.{v} (Module.rank R' M') := by
simp_rw [Module.rank, lift_iSup (bddAbove_range.{v', v'} _), lift_iSup (bddAbove_range.{v, v} _)]
exact ciSup_mono' (bddAbove_range.{v', v} _) fun ⟨s, h⟩ ↦ ⟨⟨j '' s,
(h.map_of_injective_injective i j hi (fun _ _ ↦ hj <| by rwa [j.map_zero]) hc).image⟩,
lift_mk_le'.mpr ⟨(Equiv.Set.image j s hj).toEmbedding⟩⟩
/-- If `M / R` and `M' / R'` are modules, `i : R → R'` is a surjective map which maps zero to zero,
`j : M →+ M'` is an injective group homomorphism, such that the scalar multiplications on `M` and
`M'` are compatible, then the rank of `M / R` is smaller than or equal to the rank of `M' / R'`.
As a special case, taking `R = R'` it is `LinearMap.lift_rank_le_of_injective`. -/
theorem lift_rank_le_of_surjective_injective (i : ZeroHom R R') (j : M →+ M')
(hi : Surjective i) (hj : Injective j) (hc : ∀ (r : R) (m : M), j (r • m) = i r • j m) :
lift.{v'} (Module.rank R M) ≤ lift.{v} (Module.rank R' M') := by
obtain ⟨i', hi'⟩ := hi.hasRightInverse
refine lift_rank_le_of_injective_injective i' j (fun _ h ↦ ?_) hj fun r m ↦ ?_
· apply_fun i at h
rwa [hi', i.map_zero] at h
rw [hc (i' r) m, hi']
/-- If `M / R` and `M' / R'` are modules, `i : R → R'` is a bijective map which maps zero to zero,
`j : M ≃+ M'` is a group isomorphism, such that the scalar multiplications on `M` and `M'` are
compatible, then the rank of `M / R` is equal to the rank of `M' / R'`.
As a special case, taking `R = R'` it is `LinearEquiv.lift_rank_eq`. -/
theorem lift_rank_eq_of_equiv_equiv (i : ZeroHom R R') (j : M ≃+ M')
(hi : Bijective i) (hc : ∀ (r : R) (m : M), j (r • m) = i r • j m) :
lift.{v'} (Module.rank R M) = lift.{v} (Module.rank R' M') :=
(lift_rank_le_of_surjective_injective i j hi.2 j.injective hc).antisymm <|
lift_rank_le_of_injective_injective i j.symm (fun _ _ ↦ hi.1 <| by rwa [i.map_zero])
j.symm.injective fun _ _ ↦ j.symm_apply_eq.2 <| by erw [hc, j.apply_symm_apply]
end
section
variable [AddCommGroup M₁] [Module R' M₁]
/-- The same-universe version of `lift_rank_le_of_injective_injective`. -/
theorem rank_le_of_injective_injective (i : R' → R) (j : M →+ M₁)
(hi : ∀ r, i r = 0 → r = 0) (hj : Injective j)
(hc : ∀ (r : R') (m : M), j (i r • m) = r • j m) :
Module.rank R M ≤ Module.rank R' M₁ := by
simpa only [lift_id] using lift_rank_le_of_injective_injective i j hi hj hc
/-- The same-universe version of `lift_rank_le_of_surjective_injective`. -/
theorem rank_le_of_surjective_injective (i : ZeroHom R R') (j : M →+ M₁)
(hi : Surjective i) (hj : Injective j)
(hc : ∀ (r : R) (m : M), j (r • m) = i r • j m) :
Module.rank R M ≤ Module.rank R' M₁ := by
simpa only [lift_id] using lift_rank_le_of_surjective_injective i j hi hj hc
/-- The same-universe version of `lift_rank_eq_of_equiv_equiv`. -/
theorem rank_eq_of_equiv_equiv (i : ZeroHom R R') (j : M ≃+ M₁)
(hi : Bijective i) (hc : ∀ (r : R) (m : M), j (r • m) = i r • j m) :
Module.rank R M = Module.rank R' M₁ := by
simpa only [lift_id] using lift_rank_eq_of_equiv_equiv i j hi hc
end
end Module
namespace Algebra
variable {R : Type w} {S : Type v} [CommRing R] [Ring S] [Algebra R S]
{R' : Type w'} {S' : Type v'} [CommRing R'] [Ring S'] [Algebra R' S']
/-- If `S / R` and `S' / R'` are algebras, `i : R' →+* R` and `j : S →+* S'` are injective ring
homomorphisms, such that `R' → R → S → S'` and `R' → S'` commute, then the rank of `S / R` is
smaller than or equal to the rank of `S' / R'`. -/
theorem lift_rank_le_of_injective_injective
(i : R' →+* R) (j : S →+* S') (hi : Injective i) (hj : Injective j)
(hc : (j.comp (algebraMap R S)).comp i = algebraMap R' S') :
lift.{v'} (Module.rank R S) ≤ lift.{v} (Module.rank R' S') := by
refine _root_.lift_rank_le_of_injective_injective i j
(fun _ _ ↦ hi <| by rwa [i.map_zero]) hj fun r _ ↦ ?_
have := congr($hc r)
simp only [RingHom.coe_comp, comp_apply] at this
simp_rw [smul_def, AddMonoidHom.coe_coe, map_mul, this]
/-- If `S / R` and `S' / R'` are algebras, `i : R →+* R'` is a surjective ring homomorphism,
`j : S →+* S'` is an injective ring homomorphism, such that `R → R' → S'` and `R → S → S'` commute,
then the rank of `S / R` is smaller than or equal to the rank of `S' / R'`. -/
theorem lift_rank_le_of_surjective_injective
(i : R →+* R') (j : S →+* S') (hi : Surjective i) (hj : Injective j)
(hc : (algebraMap R' S').comp i = j.comp (algebraMap R S)) :
lift.{v'} (Module.rank R S) ≤ lift.{v} (Module.rank R' S') := by
refine _root_.lift_rank_le_of_surjective_injective i j hi hj fun r _ ↦ ?_
have := congr($hc r)
simp only [RingHom.coe_comp, comp_apply] at this
simp only [smul_def, AddMonoidHom.coe_coe, map_mul, ZeroHom.coe_coe, this]
/-- If `S / R` and `S' / R'` are algebras, `i : R ≃+* R'` and `j : S ≃+* S'` are
ring isomorphisms, such that `R → R' → S'` and `R → S → S'` commute,
then the rank of `S / R` is equal to the rank of `S' / R'`. -/
theorem lift_rank_eq_of_equiv_equiv (i : R ≃+* R') (j : S ≃+* S')
(hc : (algebraMap R' S').comp i.toRingHom = j.toRingHom.comp (algebraMap R S)) :
lift.{v'} (Module.rank R S) = lift.{v} (Module.rank R' S') := by
refine _root_.lift_rank_eq_of_equiv_equiv i j i.bijective fun r _ ↦ ?_
have := congr($hc r)
simp only [RingEquiv.toRingHom_eq_coe, RingHom.coe_comp, RingHom.coe_coe, comp_apply] at this
simp only [smul_def, RingEquiv.coe_toAddEquiv, map_mul, ZeroHom.coe_coe, this]
variable {S' : Type v} [Ring S'] [Algebra R' S']
/-- The same-universe version of `Algebra.lift_rank_le_of_injective_injective`. -/
theorem rank_le_of_injective_injective
(i : R' →+* R) (j : S →+* S') (hi : Injective i) (hj : Injective j)
(hc : (j.comp (algebraMap R S)).comp i = algebraMap R' S') :
Module.rank R S ≤ Module.rank R' S' := by
simpa only [lift_id] using lift_rank_le_of_injective_injective i j hi hj hc
/-- The same-universe version of `Algebra.lift_rank_le_of_surjective_injective`. -/
theorem rank_le_of_surjective_injective
(i : R →+* R') (j : S →+* S') (hi : Surjective i) (hj : Injective j)
(hc : (algebraMap R' S').comp i = j.comp (algebraMap R S)) :
Module.rank R S ≤ Module.rank R' S' := by
simpa only [lift_id] using lift_rank_le_of_surjective_injective i j hi hj hc
/-- The same-universe version of `Algebra.lift_rank_eq_of_equiv_equiv`. -/
theorem rank_eq_of_equiv_equiv (i : R ≃+* R') (j : S ≃+* S')
(hc : (algebraMap R' S').comp i.toRingHom = j.toRingHom.comp (algebraMap R S)) :
Module.rank R S = Module.rank R' S' := by
simpa only [lift_id] using lift_rank_eq_of_equiv_equiv i j hc
end Algebra
end SurjectiveInjective
variable [Ring R] [AddCommGroup M] [Module R M]
[Ring R']
[AddCommGroup M'] [AddCommGroup M₁]
[Module R M'] [Module R M₁] [Module R' M'] [Module R' M₁]
section
theorem LinearMap.lift_rank_le_of_injective (f : M →ₗ[R] M') (i : Injective f) :
Cardinal.lift.{v'} (Module.rank R M) ≤ Cardinal.lift.{v} (Module.rank R M') :=
lift_rank_le_of_injective_injective (RingHom.id R) f (fun _ h ↦ h) i f.map_smul
theorem LinearMap.rank_le_of_injective (f : M →ₗ[R] M₁) (i : Injective f) :
Module.rank R M ≤ Module.rank R M₁ :=
Cardinal.lift_le.1 (f.lift_rank_le_of_injective i)
/-- The rank of the range of a linear map is at most the rank of the source. -/
-- The proof is: a free submodule of the range lifts to a free submodule of the
-- source, by arbitrarily lifting a basis.
theorem lift_rank_range_le (f : M →ₗ[R] M') : Cardinal.lift.{v}
(Module.rank R (LinearMap.range f)) ≤ Cardinal.lift.{v'} (Module.rank R M) := by
simp only [Module.rank_def]
rw [Cardinal.lift_iSup (Cardinal.bddAbove_range.{v', v'} _)]
apply ciSup_le'
rintro ⟨s, li⟩
apply le_trans
swap
· apply Cardinal.lift_le.mpr
refine le_ciSup (Cardinal.bddAbove_range.{v, v} _) ⟨rangeSplitting f '' s, ?_⟩
apply LinearIndependent.of_comp f.rangeRestrict
convert li.comp (Equiv.Set.rangeSplittingImageEquiv f s) (Equiv.injective _) using 1
· exact (Cardinal.lift_mk_eq'.mpr ⟨Equiv.Set.rangeSplittingImageEquiv f s⟩).ge
theorem rank_range_le (f : M →ₗ[R] M₁) : Module.rank R (LinearMap.range f) ≤ Module.rank R M := by
simpa using lift_rank_range_le f
theorem lift_rank_map_le (f : M →ₗ[R] M') (p : Submodule R M) :
Cardinal.lift.{v} (Module.rank R (p.map f)) ≤ Cardinal.lift.{v'} (Module.rank R p) := by
have h := lift_rank_range_le (f.comp (Submodule.subtype p))
rwa [LinearMap.range_comp, range_subtype] at h
theorem rank_map_le (f : M →ₗ[R] M₁) (p : Submodule R M) :
Module.rank R (p.map f) ≤ Module.rank R p := by simpa using lift_rank_map_le f p
theorem rank_le_of_submodule (s t : Submodule R M) (h : s ≤ t) :
Module.rank R s ≤ Module.rank R t :=
(Submodule.inclusion h).rank_le_of_injective fun ⟨x, _⟩ ⟨y, _⟩ eq =>
Subtype.eq <| show x = y from Subtype.ext_iff_val.1 eq
/-- Two linearly equivalent vector spaces have the same dimension, a version with different
universes. -/
theorem LinearEquiv.lift_rank_eq (f : M ≃ₗ[R] M') :
Cardinal.lift.{v'} (Module.rank R M) = Cardinal.lift.{v} (Module.rank R M') := by
apply le_antisymm
· exact f.toLinearMap.lift_rank_le_of_injective f.injective
· exact f.symm.toLinearMap.lift_rank_le_of_injective f.symm.injective
/-- Two linearly equivalent vector spaces have the same dimension. -/
theorem LinearEquiv.rank_eq (f : M ≃ₗ[R] M₁) : Module.rank R M = Module.rank R M₁ :=
Cardinal.lift_inj.1 f.lift_rank_eq
theorem lift_rank_range_of_injective (f : M →ₗ[R] M') (h : Injective f) :
lift.{v} (Module.rank R (LinearMap.range f)) = lift.{v'} (Module.rank R M) :=
(LinearEquiv.ofInjective f h).lift_rank_eq.symm
theorem rank_range_of_injective (f : M →ₗ[R] M₁) (h : Injective f) :
Module.rank R (LinearMap.range f) = Module.rank R M :=
(LinearEquiv.ofInjective f h).rank_eq.symm
theorem LinearEquiv.lift_rank_map_eq (f : M ≃ₗ[R] M') (p : Submodule R M) :
lift.{v} (Module.rank R (p.map (f : M →ₗ[R] M'))) = lift.{v'} (Module.rank R p) :=
(f.submoduleMap p).lift_rank_eq.symm
/-- Pushforwards of submodules along a `LinearEquiv` have the same dimension. -/
theorem LinearEquiv.rank_map_eq (f : M ≃ₗ[R] M₁) (p : Submodule R M) :
Module.rank R (p.map (f : M →ₗ[R] M₁)) = Module.rank R p :=
(f.submoduleMap p).rank_eq.symm
variable (R M)
@[simp]
theorem rank_top : Module.rank R (⊤ : Submodule R M) = Module.rank R M :=
(LinearEquiv.ofTop ⊤ rfl).rank_eq
variable {R M}
theorem rank_range_of_surjective (f : M →ₗ[R] M') (h : Surjective f) :
Module.rank R (LinearMap.range f) = Module.rank R M' := by
rw [LinearMap.range_eq_top.2 h, rank_top]
theorem rank_submodule_le (s : Submodule R M) : Module.rank R s ≤ Module.rank R M := by
rw [← rank_top R M]
exact rank_le_of_submodule _ _ le_top
theorem LinearMap.lift_rank_le_of_surjective (f : M →ₗ[R] M') (h : Surjective f) :
lift.{v} (Module.rank R M') ≤ lift.{v'} (Module.rank R M) := by
rw [← rank_range_of_surjective f h]
apply lift_rank_range_le
theorem LinearMap.rank_le_of_surjective (f : M →ₗ[R] M₁) (h : Surjective f) :
Module.rank R M₁ ≤ Module.rank R M := by
rw [← rank_range_of_surjective f h]
apply rank_range_le
@[nontriviality, simp]
theorem rank_subsingleton [Subsingleton R] : Module.rank R M = 1 := by
haveI := Module.subsingleton R M
have : Nonempty { s : Set M // LinearIndependent R ((↑) : s → M) } :=
⟨⟨∅, linearIndependent_empty _ _⟩⟩
rw [Module.rank_def, ciSup_eq_of_forall_le_of_forall_lt_exists_gt]
· rintro ⟨s, hs⟩
rw [Cardinal.mk_le_one_iff_set_subsingleton]
apply subsingleton_of_subsingleton
intro w hw
refine ⟨⟨{0}, ?_⟩, ?_⟩
· rw [linearIndependent_iff']
subsingleton
· exact hw.trans_eq (Cardinal.mk_singleton _).symm
end
end Module
|
LinearAlgebra\Dimension\Constructions.lean | /-
Copyright (c) 2018 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro, Johannes Hölzl, Sander Dahmen, Scott Morrison, Chris Hughes, Anne Baanen
-/
import Mathlib.LinearAlgebra.Dimension.Free
import Mathlib.Algebra.Module.Torsion
/-!
# Rank of various constructions
## Main statements
- `rank_quotient_add_rank_le` : `rank M/N + rank N ≤ rank M`.
- `lift_rank_add_lift_rank_le_rank_prod`: `rank M × N ≤ rank M + rank N`.
- `rank_span_le_of_finite`: `rank (span s) ≤ #s` for finite `s`.
For free modules, we have
- `rank_prod` : `rank M × N = rank M + rank N`.
- `rank_finsupp` : `rank (ι →₀ M) = #ι * rank M`
- `rank_directSum`: `rank (⨁ Mᵢ) = ∑ rank Mᵢ`
- `rank_tensorProduct`: `rank (M ⊗ N) = rank M * rank N`.
Lemmas for ranks of submodules and subalgebras are also provided.
We have finrank variants for most lemmas as well.
-/
noncomputable section
universe u v v' u₁' w w'
variable {R S : Type u} {M : Type v} {M' : Type v'} {M₁ : Type v}
variable {ι : Type w} {ι' : Type w'} {η : Type u₁'} {φ : η → Type*}
open Cardinal Basis Submodule Function Set FiniteDimensional DirectSum
variable [Ring R] [CommRing S] [AddCommGroup M] [AddCommGroup M'] [AddCommGroup M₁]
variable [Module R M]
section Quotient
theorem LinearIndependent.sum_elim_of_quotient
{M' : Submodule R M} {ι₁ ι₂} {f : ι₁ → M'} (hf : LinearIndependent R f) (g : ι₂ → M)
(hg : LinearIndependent R (Submodule.Quotient.mk (p := M') ∘ g)) :
LinearIndependent R (Sum.elim (f · : ι₁ → M) g) := by
refine .sum_type (hf.map' M'.subtype M'.ker_subtype) (.of_comp M'.mkQ hg) ?_
refine disjoint_def.mpr fun x h₁ h₂ ↦ ?_
have : x ∈ M' := span_le.mpr (Set.range_subset_iff.mpr fun i ↦ (f i).prop) h₁
obtain ⟨c, rfl⟩ := Finsupp.mem_span_range_iff_exists_finsupp.mp h₂
simp_rw [← Quotient.mk_eq_zero, ← mkQ_apply, map_finsupp_sum, map_smul, mkQ_apply] at this
rw [linearIndependent_iff.mp hg _ this, Finsupp.sum_zero_index]
theorem LinearIndependent.union_of_quotient
{M' : Submodule R M} {s : Set M} (hs : s ⊆ M') (hs' : LinearIndependent (ι := s) R Subtype.val)
{t : Set M} (ht : LinearIndependent (ι := t) R (Submodule.Quotient.mk (p := M') ∘ Subtype.val)) :
LinearIndependent (ι := (s ∪ t : _)) R Subtype.val := by
refine (LinearIndependent.sum_elim_of_quotient (f := Set.embeddingOfSubset s M' hs)
(of_comp M'.subtype (by simpa using hs')) Subtype.val ht).to_subtype_range' ?_
simp only [embeddingOfSubset_apply_coe, Sum.elim_range, Subtype.range_val]
theorem rank_quotient_add_rank_le [Nontrivial R] (M' : Submodule R M) :
Module.rank R (M ⧸ M') + Module.rank R M' ≤ Module.rank R M := by
conv_lhs => simp only [Module.rank_def]
have := nonempty_linearIndependent_set R (M ⧸ M')
have := nonempty_linearIndependent_set R M'
rw [Cardinal.ciSup_add_ciSup _ (bddAbove_range.{v, v} _) _ (bddAbove_range.{v, v} _)]
refine ciSup_le fun ⟨s, hs⟩ ↦ ciSup_le fun ⟨t, ht⟩ ↦ ?_
choose f hf using Quotient.mk_surjective M'
simpa [add_comm] using (LinearIndependent.sum_elim_of_quotient ht (fun (i : s) ↦ f i)
(by simpa [Function.comp, hf] using hs)).cardinal_le_rank
theorem rank_quotient_le (p : Submodule R M) : Module.rank R (M ⧸ p) ≤ Module.rank R M :=
(mkQ p).rank_le_of_surjective (surjective_quot_mk _)
theorem rank_quotient_eq_of_le_torsion {R M} [CommRing R] [AddCommGroup M] [Module R M]
{M' : Submodule R M} (hN : M' ≤ torsion R M) : Module.rank R (M ⧸ M') = Module.rank R M :=
(rank_quotient_le M').antisymm <| by
nontriviality R
rw [Module.rank]
have := nonempty_linearIndependent_set R M
refine ciSup_le fun ⟨s, hs⟩ ↦ LinearIndependent.cardinal_le_rank (v := (M'.mkQ ·)) ?_
rw [linearIndependent_iff'] at hs ⊢
simp_rw [← map_smul, ← map_sum, mkQ_apply, Quotient.mk_eq_zero]
intro t g hg i hi
obtain ⟨r, hg⟩ := hN hg
simp_rw [Finset.smul_sum, Submonoid.smul_def, smul_smul] at hg
exact r.prop _ (mul_comm (g i) r ▸ hs t _ hg i hi)
end Quotient
section ULift
@[simp]
theorem rank_ulift : Module.rank R (ULift.{w} M) = Cardinal.lift.{w} (Module.rank R M) :=
Cardinal.lift_injective.{v} <| Eq.symm <| (lift_lift _).trans ULift.moduleEquiv.symm.lift_rank_eq
@[simp]
theorem finrank_ulift : finrank R (ULift M) = finrank R M := by
simp_rw [finrank, rank_ulift, toNat_lift]
end ULift
section Prod
variable (R M M')
variable [Module R M₁] [Module R M']
open LinearMap in
theorem lift_rank_add_lift_rank_le_rank_prod [Nontrivial R] :
lift.{v'} (Module.rank R M) + lift.{v} (Module.rank R M') ≤ Module.rank R (M × M') := by
convert rank_quotient_add_rank_le (ker <| LinearMap.fst R M M')
· refine Eq.trans ?_ (lift_id'.{v, v'} _)
rw [(quotKerEquivRange _).lift_rank_eq,
rank_range_of_surjective _ fst_surjective, lift_umax.{v, v'}]
· refine Eq.trans ?_ (lift_id'.{v', v} _)
rw [ker_fst, ← (LinearEquiv.ofInjective _ <| inr_injective (M := M) (M₂ := M')).lift_rank_eq,
lift_umax.{v', v}]
theorem rank_add_rank_le_rank_prod [Nontrivial R] :
Module.rank R M + Module.rank R M₁ ≤ Module.rank R (M × M₁) := by
convert ← lift_rank_add_lift_rank_le_rank_prod R M M₁ <;> apply lift_id
variable {R M M'}
variable [StrongRankCondition R] [Module.Free R M] [Module.Free R M'] [Module.Free R M₁]
open Module.Free
/-- If `M` and `M'` are free, then the rank of `M × M'` is
`(Module.rank R M).lift + (Module.rank R M').lift`. -/
@[simp]
theorem rank_prod : Module.rank R (M × M') =
Cardinal.lift.{v'} (Module.rank R M) + Cardinal.lift.{v, v'} (Module.rank R M') := by
simpa [rank_eq_card_chooseBasisIndex R M, rank_eq_card_chooseBasisIndex R M', lift_umax,
lift_umax'] using ((chooseBasis R M).prod (chooseBasis R M')).mk_eq_rank.symm
/-- If `M` and `M'` are free (and lie in the same universe), the rank of `M × M'` is
`(Module.rank R M) + (Module.rank R M')`. -/
theorem rank_prod' : Module.rank R (M × M₁) = Module.rank R M + Module.rank R M₁ := by simp
/-- The finrank of `M × M'` is `(finrank R M) + (finrank R M')`. -/
@[simp]
theorem FiniteDimensional.finrank_prod [Module.Finite R M] [Module.Finite R M'] :
finrank R (M × M') = finrank R M + finrank R M' := by
simp [finrank, rank_lt_aleph0 R M, rank_lt_aleph0 R M']
end Prod
section Finsupp
variable (R M M')
variable [StrongRankCondition R] [Module.Free R M] [Module R M'] [Module.Free R M']
open Module.Free
@[simp]
theorem rank_finsupp (ι : Type w) :
Module.rank R (ι →₀ M) = Cardinal.lift.{v} #ι * Cardinal.lift.{w} (Module.rank R M) := by
obtain ⟨⟨_, bs⟩⟩ := Module.Free.exists_basis (R := R) (M := M)
rw [← bs.mk_eq_rank'', ← (Finsupp.basis fun _ : ι => bs).mk_eq_rank'', Cardinal.mk_sigma,
Cardinal.sum_const]
theorem rank_finsupp' (ι : Type v) : Module.rank R (ι →₀ M) = #ι * Module.rank R M := by
simp [rank_finsupp]
/-- The rank of `(ι →₀ R)` is `(#ι).lift`. -/
-- Porting note, this should not be `@[simp]`, as simp can prove it.
-- @[simp]
theorem rank_finsupp_self (ι : Type w) : Module.rank R (ι →₀ R) = Cardinal.lift.{u} #ι := by
simp [rank_finsupp]
/-- If `R` and `ι` lie in the same universe, the rank of `(ι →₀ R)` is `# ι`. -/
theorem rank_finsupp_self' {ι : Type u} : Module.rank R (ι →₀ R) = #ι := by simp
/-- The rank of the direct sum is the sum of the ranks. -/
@[simp]
theorem rank_directSum {ι : Type v} (M : ι → Type w) [∀ i : ι, AddCommGroup (M i)]
[∀ i : ι, Module R (M i)] [∀ i : ι, Module.Free R (M i)] :
Module.rank R (⨁ i, M i) = Cardinal.sum fun i => Module.rank R (M i) := by
let B i := chooseBasis R (M i)
let b : Basis _ R (⨁ i, M i) := DFinsupp.basis fun i => B i
simp [← b.mk_eq_rank'', fun i => (B i).mk_eq_rank'']
/-- If `m` and `n` are `Fintype`, the rank of `m × n` matrices is `(#m).lift * (#n).lift`. -/
@[simp]
theorem rank_matrix (m : Type v) (n : Type w) [Finite m] [Finite n] :
Module.rank R (Matrix m n R) =
Cardinal.lift.{max v w u, v} #m * Cardinal.lift.{max v w u, w} #n := by
cases nonempty_fintype m
cases nonempty_fintype n
have h := (Matrix.stdBasis R m n).mk_eq_rank
rw [← lift_lift.{max v w u, max v w}, lift_inj] at h
simpa using h.symm
/-- If `m` and `n` are `Fintype` that lie in the same universe, the rank of `m × n` matrices is
`(#n * #m).lift`. -/
@[simp high]
theorem rank_matrix' (m n : Type v) [Finite m] [Finite n] :
Module.rank R (Matrix m n R) = Cardinal.lift.{u} (#m * #n) := by
rw [rank_matrix, lift_mul, lift_umax.{v, u}]
/-- If `m` and `n` are `Fintype` that lie in the same universe as `R`, the rank of `m × n` matrices
is `# m * # n`. -/
-- @[simp] -- Porting note (#10618): simp can prove this
theorem rank_matrix'' (m n : Type u) [Finite m] [Finite n] :
Module.rank R (Matrix m n R) = #m * #n := by simp
open Fintype
namespace FiniteDimensional
@[simp]
theorem finrank_finsupp {ι : Type v} [Fintype ι] : finrank R (ι →₀ M) = card ι * finrank R M := by
rw [finrank, finrank, rank_finsupp, ← mk_toNat_eq_card, toNat_mul, toNat_lift, toNat_lift]
/-- The finrank of `(ι →₀ R)` is `Fintype.card ι`. -/
@[simp]
theorem finrank_finsupp_self {ι : Type v} [Fintype ι] : finrank R (ι →₀ R) = card ι := by
rw [finrank, rank_finsupp_self, ← mk_toNat_eq_card, toNat_lift]
/-- The finrank of the direct sum is the sum of the finranks. -/
@[simp]
theorem finrank_directSum {ι : Type v} [Fintype ι] (M : ι → Type w) [∀ i : ι, AddCommGroup (M i)]
[∀ i : ι, Module R (M i)] [∀ i : ι, Module.Free R (M i)] [∀ i : ι, Module.Finite R (M i)] :
finrank R (⨁ i, M i) = ∑ i, finrank R (M i) := by
letI := nontrivial_of_invariantBasisNumber R
simp only [finrank, fun i => rank_eq_card_chooseBasisIndex R (M i), rank_directSum, ← mk_sigma,
mk_toNat_eq_card, card_sigma]
/-- If `m` and `n` are `Fintype`, the finrank of `m × n` matrices is
`(Fintype.card m) * (Fintype.card n)`. -/
theorem finrank_matrix (m n : Type*) [Fintype m] [Fintype n] :
finrank R (Matrix m n R) = card m * card n := by simp [finrank]
end FiniteDimensional
end Finsupp
section Pi
variable [StrongRankCondition R] [Module.Free R M]
variable [∀ i, AddCommGroup (φ i)] [∀ i, Module R (φ i)] [∀ i, Module.Free R (φ i)]
open Module.Free
open LinearMap
/-- The rank of a finite product of free modules is the sum of the ranks. -/
-- this result is not true without the freeness assumption
@[simp]
theorem rank_pi [Finite η] : Module.rank R (∀ i, φ i) =
Cardinal.sum fun i => Module.rank R (φ i) := by
cases nonempty_fintype η
let B i := chooseBasis R (φ i)
let b : Basis _ R (∀ i, φ i) := Pi.basis fun i => B i
simp [← b.mk_eq_rank'', fun i => (B i).mk_eq_rank'']
variable (R)
/-- The finrank of `(ι → R)` is `Fintype.card ι`. -/
theorem FiniteDimensional.finrank_pi {ι : Type v} [Fintype ι] :
finrank R (ι → R) = Fintype.card ι := by
simp [finrank]
--TODO: this should follow from `LinearEquiv.finrank_eq`, that is over a field.
/-- The finrank of a finite product is the sum of the finranks. -/
theorem FiniteDimensional.finrank_pi_fintype
{ι : Type v} [Fintype ι] {M : ι → Type w} [∀ i : ι, AddCommGroup (M i)]
[∀ i : ι, Module R (M i)] [∀ i : ι, Module.Free R (M i)] [∀ i : ι, Module.Finite R (M i)] :
finrank R (∀ i, M i) = ∑ i, finrank R (M i) := by
letI := nontrivial_of_invariantBasisNumber R
simp only [finrank, fun i => rank_eq_card_chooseBasisIndex R (M i), rank_pi, ← mk_sigma,
mk_toNat_eq_card, Fintype.card_sigma]
variable {R}
variable [Fintype η]
theorem rank_fun {M η : Type u} [Fintype η] [AddCommGroup M] [Module R M] [Module.Free R M] :
Module.rank R (η → M) = Fintype.card η * Module.rank R M := by
rw [rank_pi, Cardinal.sum_const', Cardinal.mk_fintype]
theorem rank_fun_eq_lift_mul : Module.rank R (η → M) =
(Fintype.card η : Cardinal.{max u₁' v}) * Cardinal.lift.{u₁'} (Module.rank R M) := by
rw [rank_pi, Cardinal.sum_const, Cardinal.mk_fintype, Cardinal.lift_natCast]
theorem rank_fun' : Module.rank R (η → R) = Fintype.card η := by
rw [rank_fun_eq_lift_mul, rank_self, Cardinal.lift_one, mul_one]
theorem rank_fin_fun (n : ℕ) : Module.rank R (Fin n → R) = n := by simp [rank_fun']
variable (R)
/-- The vector space of functions on a `Fintype ι` has finrank equal to the cardinality of `ι`. -/
@[simp]
theorem FiniteDimensional.finrank_fintype_fun_eq_card : finrank R (η → R) = Fintype.card η :=
finrank_eq_of_rank_eq rank_fun'
/-- The vector space of functions on `Fin n` has finrank equal to `n`. -/
-- @[simp] -- Porting note (#10618): simp already proves this
theorem FiniteDimensional.finrank_fin_fun {n : ℕ} : finrank R (Fin n → R) = n := by simp
variable {R}
-- TODO: merge with the `Finrank` content
/-- An `n`-dimensional `R`-vector space is equivalent to `Fin n → R`. -/
def finDimVectorspaceEquiv (n : ℕ) (hn : Module.rank R M = n) : M ≃ₗ[R] Fin n → R := by
haveI := nontrivial_of_invariantBasisNumber R
have : Cardinal.lift.{u} (n : Cardinal.{v}) = Cardinal.lift.{v} (n : Cardinal.{u}) := by simp
have hn := Cardinal.lift_inj.{v, u}.2 hn
rw [this] at hn
rw [← @rank_fin_fun R _ _ n] at hn
haveI : Module.Free R (Fin n → R) := Module.Free.pi _ _
exact Classical.choice (nonempty_linearEquiv_of_lift_rank_eq hn)
end Pi
section TensorProduct
open TensorProduct
variable [StrongRankCondition R] [StrongRankCondition S]
variable [Module S M] [Module S M'] [Module.Free S M']
variable [Module S M₁] [Module.Free S M₁]
variable [Algebra S R] [IsScalarTower S R M] [Module.Free R M]
open Module.Free
/-- The `S`-rank of `M ⊗[R] M'` is `(Module.rank S M).lift * (Module.rank R M').lift`. -/
@[simp]
theorem rank_tensorProduct :
Module.rank R (M ⊗[S] M') =
Cardinal.lift.{v'} (Module.rank R M) * Cardinal.lift.{v} (Module.rank S M') := by
obtain ⟨⟨_, bM⟩⟩ := Module.Free.exists_basis (R := R) (M := M)
obtain ⟨⟨_, bN⟩⟩ := Module.Free.exists_basis (R := S) (M := M')
rw [← bM.mk_eq_rank'', ← bN.mk_eq_rank'', ← (bM.tensorProduct bN).mk_eq_rank'', Cardinal.mk_prod]
/-- If `M` and `M'` lie in the same universe, the `S`-rank of `M ⊗[R] M'` is
`(Module.rank S M) * (Module.rank R M')`. -/
theorem rank_tensorProduct' :
Module.rank R (M ⊗[S] M₁) = Module.rank R M * Module.rank S M₁ := by simp
/-- The `S`-finrank of `M ⊗[R] M'` is `(finrank S M) * (finrank R M')`. -/
@[simp]
theorem FiniteDimensional.finrank_tensorProduct :
finrank R (M ⊗[S] M') = finrank R M * finrank S M' := by simp [finrank]
end TensorProduct
section SubmoduleRank
section
open FiniteDimensional
namespace Submodule
theorem lt_of_le_of_finrank_lt_finrank {s t : Submodule R M} (le : s ≤ t)
(lt : finrank R s < finrank R t) : s < t :=
lt_of_le_of_ne le fun h => ne_of_lt lt (by rw [h])
theorem lt_top_of_finrank_lt_finrank {s : Submodule R M} (lt : finrank R s < finrank R M) :
s < ⊤ := by
rw [← finrank_top R M] at lt
exact lt_of_le_of_finrank_lt_finrank le_top lt
end Submodule
variable [StrongRankCondition R]
/-- The dimension of a submodule is bounded by the dimension of the ambient space. -/
theorem Submodule.finrank_le [Module.Finite R M] (s : Submodule R M) :
finrank R s ≤ finrank R M :=
toNat_le_toNat (rank_submodule_le s) (rank_lt_aleph0 _ _)
/-- The dimension of a quotient is bounded by the dimension of the ambient space. -/
theorem Submodule.finrank_quotient_le [Module.Finite R M] (s : Submodule R M) :
finrank R (M ⧸ s) ≤ finrank R M :=
toNat_le_toNat ((Submodule.mkQ s).rank_le_of_surjective (surjective_quot_mk _))
(rank_lt_aleph0 _ _)
/-- Pushforwards of finite submodules have a smaller finrank. -/
theorem Submodule.finrank_map_le
[Module R M'] (f : M →ₗ[R] M') (p : Submodule R M) [Module.Finite R p] :
finrank R (p.map f) ≤ finrank R p :=
finrank_le_finrank_of_rank_le_rank (lift_rank_map_le _ _) (rank_lt_aleph0 _ _)
theorem Submodule.finrank_le_finrank_of_le {s t : Submodule R M} [Module.Finite R t] (hst : s ≤ t) :
finrank R s ≤ finrank R t :=
calc
finrank R s = finrank R (s.comap t.subtype) :=
(Submodule.comapSubtypeEquivOfLe hst).finrank_eq.symm
_ ≤ finrank R t := Submodule.finrank_le _
end
end SubmoduleRank
section Span
variable [StrongRankCondition R]
theorem rank_span_le (s : Set M) : Module.rank R (span R s) ≤ #s := by
rw [Finsupp.span_eq_range_total, ← lift_strictMono.le_iff_le]
refine (lift_rank_range_le _).trans ?_
rw [rank_finsupp_self]
simp only [lift_lift, le_refl]
theorem rank_span_finset_le (s : Finset M) : Module.rank R (span R (s : Set M)) ≤ s.card := by
simpa using rank_span_le s.toSet
theorem rank_span_of_finset (s : Finset M) : Module.rank R (span R (s : Set M)) < ℵ₀ :=
(rank_span_finset_le s).trans_lt (Cardinal.nat_lt_aleph0 _)
open Submodule FiniteDimensional
variable (R)
/-- The rank of a set of vectors as a natural number. -/
protected noncomputable def Set.finrank (s : Set M) : ℕ :=
finrank R (span R s)
variable {R}
theorem finrank_span_le_card (s : Set M) [Fintype s] : finrank R (span R s) ≤ s.toFinset.card :=
finrank_le_of_rank_le (by simpa using rank_span_le (R := R) s)
theorem finrank_span_finset_le_card (s : Finset M) : (s : Set M).finrank R ≤ s.card :=
calc
(s : Set M).finrank R ≤ (s : Set M).toFinset.card := finrank_span_le_card (M := M) s
_ = s.card := by simp
theorem finrank_range_le_card {ι : Type*} [Fintype ι] (b : ι → M) :
(Set.range b).finrank R ≤ Fintype.card ι := by
classical
refine (finrank_span_le_card _).trans ?_
rw [Set.toFinset_range]
exact Finset.card_image_le
theorem finrank_span_eq_card [Nontrivial R] {ι : Type*} [Fintype ι] {b : ι → M}
(hb : LinearIndependent R b) :
finrank R (span R (Set.range b)) = Fintype.card ι :=
finrank_eq_of_rank_eq
(by
have : Module.rank R (span R (Set.range b)) = #(Set.range b) := rank_span hb
rwa [← lift_inj, mk_range_eq_of_injective hb.injective, Cardinal.mk_fintype, lift_natCast,
lift_eq_nat_iff] at this)
theorem finrank_span_set_eq_card {s : Set M} [Fintype s] (hs : LinearIndependent R ((↑) : s → M)) :
finrank R (span R s) = s.toFinset.card :=
finrank_eq_of_rank_eq
(by
have : Module.rank R (span R s) = #s := rank_span_set hs
rwa [Cardinal.mk_fintype, ← Set.toFinset_card] at this)
theorem finrank_span_finset_eq_card {s : Finset M} (hs : LinearIndependent R ((↑) : s → M)) :
finrank R (span R (s : Set M)) = s.card := by
convert finrank_span_set_eq_card (s := (s : Set M)) hs
ext
simp
theorem span_lt_of_subset_of_card_lt_finrank {s : Set M} [Fintype s] {t : Submodule R M}
(subset : s ⊆ t) (card_lt : s.toFinset.card < finrank R t) : span R s < t :=
lt_of_le_of_finrank_lt_finrank (span_le.mpr subset)
(lt_of_le_of_lt (finrank_span_le_card _) card_lt)
theorem span_lt_top_of_card_lt_finrank {s : Set M} [Fintype s]
(card_lt : s.toFinset.card < finrank R M) : span R s < ⊤ :=
lt_top_of_finrank_lt_finrank (lt_of_le_of_lt (finrank_span_le_card _) card_lt)
end Span
section SubalgebraRank
open Module
variable {F E : Type*} [CommRing F] [Ring E] [Algebra F E]
@[simp]
theorem Subalgebra.rank_toSubmodule (S : Subalgebra F E) :
Module.rank F (Subalgebra.toSubmodule S) = Module.rank F S :=
rfl
@[simp]
theorem Subalgebra.finrank_toSubmodule (S : Subalgebra F E) :
finrank F (Subalgebra.toSubmodule S) = finrank F S :=
rfl
theorem subalgebra_top_rank_eq_submodule_top_rank :
Module.rank F (⊤ : Subalgebra F E) = Module.rank F (⊤ : Submodule F E) := by
rw [← Algebra.top_toSubmodule]
rfl
theorem subalgebra_top_finrank_eq_submodule_top_finrank :
finrank F (⊤ : Subalgebra F E) = finrank F (⊤ : Submodule F E) := by
rw [← Algebra.top_toSubmodule]
rfl
theorem Subalgebra.rank_top : Module.rank F (⊤ : Subalgebra F E) = Module.rank F E := by
rw [subalgebra_top_rank_eq_submodule_top_rank]
exact _root_.rank_top F E
section
variable [StrongRankCondition F] [NoZeroSMulDivisors F E] [Nontrivial E]
@[simp]
theorem Subalgebra.rank_bot : Module.rank F (⊥ : Subalgebra F E) = 1 :=
(Subalgebra.toSubmoduleEquiv (⊥ : Subalgebra F E)).symm.rank_eq.trans <| by
rw [Algebra.toSubmodule_bot, one_eq_span, rank_span_set, mk_singleton _]
letI := Module.nontrivial F E
exact linearIndependent_singleton one_ne_zero
@[simp]
theorem Subalgebra.finrank_bot : finrank F (⊥ : Subalgebra F E) = 1 :=
finrank_eq_of_rank_eq (by simp)
end
end SubalgebraRank
|
LinearAlgebra\Dimension\DivisionRing.lean | /-
Copyright (c) 2018 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro, Johannes Hölzl, Sander Dahmen,
Scott Morrison, Chris Hughes, Anne Baanen, Junyan Xu
-/
import Mathlib.LinearAlgebra.Basis.VectorSpace
import Mathlib.LinearAlgebra.Dimension.Finite
import Mathlib.SetTheory.Cardinal.Subfield
import Mathlib.LinearAlgebra.Dimension.RankNullity
/-!
# Dimension of vector spaces
In this file we provide results about `Module.rank` and `FiniteDimensional.finrank` of vector spaces
over division rings.
## Main statements
For vector spaces (i.e. modules over a field), we have
* `rank_quotient_add_rank_of_divisionRing`: if `V₁` is a submodule of `V`, then
`Module.rank (V/V₁) + Module.rank V₁ = Module.rank V`.
* `rank_range_add_rank_ker`: the rank-nullity theorem.
* `rank_dual_eq_card_dual_of_aleph0_le_rank`: The **Erdős-Kaplansky Theorem** which says that
the dimension of an infinite-dimensional dual space over a division ring has dimension
equal to its cardinality.
-/
noncomputable section
universe u₀ u v v' v'' u₁' w w'
variable {K R : Type u} {V V₁ V₂ V₃ : Type v} {V' V'₁ : Type v'} {V'' : Type v''}
variable {ι : Type w} {ι' : Type w'} {η : Type u₁'} {φ : η → Type*}
open Cardinal Basis Submodule Function Set
section Module
section DivisionRing
variable [DivisionRing K]
variable [AddCommGroup V] [Module K V]
variable [AddCommGroup V'] [Module K V']
variable [AddCommGroup V₁] [Module K V₁]
/-- If a vector space has a finite dimension, the index set of `Basis.ofVectorSpace` is finite. -/
theorem Basis.finite_ofVectorSpaceIndex_of_rank_lt_aleph0 (h : Module.rank K V < ℵ₀) :
(Basis.ofVectorSpaceIndex K V).Finite :=
finite_def.2 <| (Basis.ofVectorSpace K V).nonempty_fintype_index_of_rank_lt_aleph0 h
/-- Also see `rank_quotient_add_rank`. -/
theorem rank_quotient_add_rank_of_divisionRing (p : Submodule K V) :
Module.rank K (V ⧸ p) + Module.rank K p = Module.rank K V := by
classical
let ⟨f⟩ := quotient_prod_linearEquiv p
exact rank_prod'.symm.trans f.rank_eq
instance DivisionRing.hasRankNullity : HasRankNullity.{u₀} K where
rank_quotient_add_rank := rank_quotient_add_rank_of_divisionRing
exists_set_linearIndependent V _ _ := by
let b := Module.Free.chooseBasis K V
refine ⟨range b, ?_, b.linearIndependent.to_subtype_range⟩
rw [← lift_injective.eq_iff, mk_range_eq_of_injective b.injective,
Module.Free.rank_eq_card_chooseBasisIndex]
section
variable [AddCommGroup V₂] [Module K V₂]
variable [AddCommGroup V₃] [Module K V₃]
open LinearMap
/-- This is mostly an auxiliary lemma for `Submodule.rank_sup_add_rank_inf_eq`. -/
theorem rank_add_rank_split (db : V₂ →ₗ[K] V) (eb : V₃ →ₗ[K] V) (cd : V₁ →ₗ[K] V₂)
(ce : V₁ →ₗ[K] V₃) (hde : ⊤ ≤ LinearMap.range db ⊔ LinearMap.range eb) (hgd : ker cd = ⊥)
(eq : db.comp cd = eb.comp ce) (eq₂ : ∀ d e, db d = eb e → ∃ c, cd c = d ∧ ce c = e) :
Module.rank K V + Module.rank K V₁ = Module.rank K V₂ + Module.rank K V₃ := by
have hf : Surjective (coprod db eb) := by rwa [← range_eq_top, range_coprod, eq_top_iff]
conv =>
rhs
rw [← rank_prod', rank_eq_of_surjective hf]
congr 1
apply LinearEquiv.rank_eq
let L : V₁ →ₗ[K] ker (coprod db eb) := by -- Porting note: this is needed to avoid a timeout
refine LinearMap.codRestrict _ (prod cd (-ce)) ?_
· intro c
simp only [add_eq_zero_iff_eq_neg, LinearMap.prod_apply, mem_ker, Pi.prod, coprod_apply,
neg_neg, map_neg, neg_apply]
exact LinearMap.ext_iff.1 eq c
refine LinearEquiv.ofBijective L ⟨?_, ?_⟩
· rw [← ker_eq_bot, ker_codRestrict, ker_prod, hgd, bot_inf_eq]
· rw [← range_eq_top, eq_top_iff, range_codRestrict, ← map_le_iff_le_comap, Submodule.map_top,
range_subtype]
rintro ⟨d, e⟩
have h := eq₂ d (-e)
simp only [add_eq_zero_iff_eq_neg, LinearMap.prod_apply, mem_ker, SetLike.mem_coe,
Prod.mk.inj_iff, coprod_apply, map_neg, neg_apply, LinearMap.mem_range, Pi.prod] at h ⊢
intro hde
rcases h hde with ⟨c, h₁, h₂⟩
refine ⟨c, h₁, ?_⟩
rw [h₂, _root_.neg_neg]
end
end DivisionRing
end Module
section Basis
open FiniteDimensional
variable [DivisionRing K] [AddCommGroup V] [Module K V]
theorem linearIndependent_of_top_le_span_of_card_eq_finrank {ι : Type*} [Fintype ι] {b : ι → V}
(spans : ⊤ ≤ span K (Set.range b)) (card_eq : Fintype.card ι = finrank K V) :
LinearIndependent K b :=
linearIndependent_iff'.mpr fun s g dependent i i_mem_s => by
classical
by_contra gx_ne_zero
-- We'll derive a contradiction by showing `b '' (univ \ {i})` of cardinality `n - 1`
-- spans a vector space of dimension `n`.
refine not_le_of_gt (span_lt_top_of_card_lt_finrank
(show (b '' (Set.univ \ {i})).toFinset.card < finrank K V from ?_)) ?_
· calc
(b '' (Set.univ \ {i})).toFinset.card = ((Set.univ \ {i}).toFinset.image b).card := by
rw [Set.toFinset_card, Fintype.card_ofFinset]
_ ≤ (Set.univ \ {i}).toFinset.card := Finset.card_image_le
_ = (Finset.univ.erase i).card := (congr_arg Finset.card (Finset.ext (by simp [and_comm])))
_ < Finset.univ.card := Finset.card_erase_lt_of_mem (Finset.mem_univ i)
_ = finrank K V := card_eq
-- We already have that `b '' univ` spans the whole space,
-- so we only need to show that the span of `b '' (univ \ {i})` contains each `b j`.
refine spans.trans (span_le.mpr ?_)
rintro _ ⟨j, rfl, rfl⟩
-- The case that `j ≠ i` is easy because `b j ∈ b '' (univ \ {i})`.
by_cases j_eq : j = i
swap
· refine subset_span ⟨j, (Set.mem_diff _).mpr ⟨Set.mem_univ _, ?_⟩, rfl⟩
exact mt Set.mem_singleton_iff.mp j_eq
-- To show `b i ∈ span (b '' (univ \ {i}))`, we use that it's a weighted sum
-- of the other `b j`s.
rw [j_eq, SetLike.mem_coe, show b i = -((g i)⁻¹ • (s.erase i).sum fun j => g j • b j) from _]
· refine neg_mem (smul_mem _ _ (sum_mem fun k hk => ?_))
obtain ⟨k_ne_i, _⟩ := Finset.mem_erase.mp hk
refine smul_mem _ _ (subset_span ⟨k, ?_, rfl⟩)
simp_all only [Set.mem_univ, Set.mem_diff, Set.mem_singleton_iff, and_self, not_false_eq_true]
-- To show `b i` is a weighted sum of the other `b j`s, we'll rewrite this sum
-- to have the form of the assumption `dependent`.
apply eq_neg_of_add_eq_zero_left
calc
(b i + (g i)⁻¹ • (s.erase i).sum fun j => g j • b j) =
(g i)⁻¹ • (g i • b i + (s.erase i).sum fun j => g j • b j) := by
rw [smul_add, ← mul_smul, inv_mul_cancel gx_ne_zero, one_smul]
_ = (g i)⁻¹ • (0 : V) := congr_arg _ ?_
_ = 0 := smul_zero _
-- And then it's just a bit of manipulation with finite sums.
rwa [← Finset.insert_erase i_mem_s, Finset.sum_insert (Finset.not_mem_erase _ _)] at dependent
/-- A finite family of vectors is linearly independent if and only if
its cardinality equals the dimension of its span. -/
theorem linearIndependent_iff_card_eq_finrank_span {ι : Type*} [Fintype ι] {b : ι → V} :
LinearIndependent K b ↔ Fintype.card ι = (Set.range b).finrank K := by
constructor
· intro h
exact (finrank_span_eq_card h).symm
· intro hc
let f := Submodule.subtype (span K (Set.range b))
let b' : ι → span K (Set.range b) := fun i =>
⟨b i, mem_span.2 fun p hp => hp (Set.mem_range_self _)⟩
have hs : ⊤ ≤ span K (Set.range b') := by
intro x
have h : span K (f '' Set.range b') = map f (span K (Set.range b')) := span_image f
have hf : f '' Set.range b' = Set.range b := by
ext x
simp [f, Set.mem_image, Set.mem_range]
rw [hf] at h
have hx : (x : V) ∈ span K (Set.range b) := x.property
conv at hx =>
arg 2
rw [h]
simpa [f, mem_map] using hx
have hi : LinearMap.ker f = ⊥ := ker_subtype _
convert (linearIndependent_of_top_le_span_of_card_eq_finrank hs hc).map' _ hi
theorem linearIndependent_iff_card_le_finrank_span {ι : Type*} [Fintype ι] {b : ι → V} :
LinearIndependent K b ↔ Fintype.card ι ≤ (Set.range b).finrank K := by
rw [linearIndependent_iff_card_eq_finrank_span, (finrank_range_le_card _).le_iff_eq]
/-- A family of `finrank K V` vectors forms a basis if they span the whole space. -/
noncomputable def basisOfTopLeSpanOfCardEqFinrank {ι : Type*} [Fintype ι] (b : ι → V)
(le_span : ⊤ ≤ span K (Set.range b)) (card_eq : Fintype.card ι = finrank K V) : Basis ι K V :=
Basis.mk (linearIndependent_of_top_le_span_of_card_eq_finrank le_span card_eq) le_span
@[simp]
theorem coe_basisOfTopLeSpanOfCardEqFinrank {ι : Type*} [Fintype ι] (b : ι → V)
(le_span : ⊤ ≤ span K (Set.range b)) (card_eq : Fintype.card ι = finrank K V) :
⇑(basisOfTopLeSpanOfCardEqFinrank b le_span card_eq) = b :=
Basis.coe_mk _ _
/-- A finset of `finrank K V` vectors forms a basis if they span the whole space. -/
@[simps! repr_apply]
noncomputable def finsetBasisOfTopLeSpanOfCardEqFinrank {s : Finset V}
(le_span : ⊤ ≤ span K (s : Set V)) (card_eq : s.card = finrank K V) : Basis {x // x ∈ s} K V :=
basisOfTopLeSpanOfCardEqFinrank ((↑) : ↥(s : Set V) → V)
((@Subtype.range_coe_subtype _ fun x => x ∈ s).symm ▸ le_span)
(_root_.trans (Fintype.card_coe _) card_eq)
/-- A set of `finrank K V` vectors forms a basis if they span the whole space. -/
@[simps! repr_apply]
noncomputable def setBasisOfTopLeSpanOfCardEqFinrank {s : Set V} [Fintype s]
(le_span : ⊤ ≤ span K s) (card_eq : s.toFinset.card = finrank K V) : Basis s K V :=
basisOfTopLeSpanOfCardEqFinrank ((↑) : s → V) ((@Subtype.range_coe_subtype _ s).symm ▸ le_span)
(_root_.trans s.toFinset_card.symm card_eq)
end Basis
section Cardinal
variable (K)
variable [DivisionRing K]
/-- Key lemma towards the Erdős-Kaplansky theorem from https://mathoverflow.net/a/168624 -/
theorem max_aleph0_card_le_rank_fun_nat : max ℵ₀ #K ≤ Module.rank K (ℕ → K) := by
have aleph0_le : ℵ₀ ≤ Module.rank K (ℕ → K) := (rank_finsupp_self K ℕ).symm.trans_le
(Finsupp.lcoeFun.rank_le_of_injective <| by exact DFunLike.coe_injective)
refine max_le aleph0_le ?_
obtain card_K | card_K := le_or_lt #K ℵ₀
· exact card_K.trans aleph0_le
by_contra!
obtain ⟨⟨ιK, bK⟩⟩ := Module.Free.exists_basis (R := K) (M := ℕ → K)
let L := Subfield.closure (Set.range (fun i : ιK × ℕ ↦ bK i.1 i.2))
have hLK : #L < #K := by
refine (Subfield.cardinal_mk_closure_le_max _).trans_lt
(max_lt_iff.mpr ⟨mk_range_le.trans_lt ?_, card_K⟩)
rwa [mk_prod, ← aleph0, lift_uzero, bK.mk_eq_rank'', mul_aleph0_eq aleph0_le]
letI := Module.compHom K (RingHom.op L.subtype)
obtain ⟨⟨ιL, bL⟩⟩ := Module.Free.exists_basis (R := Lᵐᵒᵖ) (M := K)
have card_ιL : ℵ₀ ≤ #ιL := by
contrapose! hLK
haveI := @Fintype.ofFinite _ (lt_aleph0_iff_finite.mp hLK)
rw [bL.repr.toEquiv.cardinal_eq, mk_finsupp_of_fintype,
← MulOpposite.opEquiv.cardinal_eq] at card_K ⊢
apply power_nat_le
contrapose! card_K
exact (power_lt_aleph0 card_K <| nat_lt_aleph0 _).le
obtain ⟨e⟩ := lift_mk_le'.mp (card_ιL.trans_eq (lift_uzero #ιL).symm)
have rep_e := bK.total_repr (bL ∘ e)
rw [Finsupp.total_apply, Finsupp.sum] at rep_e
set c := bK.repr (bL ∘ e)
set s := c.support
let f i (j : s) : L := ⟨bK j i, Subfield.subset_closure ⟨(j, i), rfl⟩⟩
have : ¬LinearIndependent Lᵐᵒᵖ f := fun h ↦ by
have := h.cardinal_lift_le_rank
rw [lift_uzero, (LinearEquiv.piCongrRight fun _ ↦ MulOpposite.opLinearEquiv Lᵐᵒᵖ).rank_eq,
rank_fun'] at this
exact (nat_lt_aleph0 _).not_le this
obtain ⟨t, g, eq0, i, hi, hgi⟩ := not_linearIndependent_iff.mp this
refine hgi (linearIndependent_iff'.mp (bL.linearIndependent.comp e e.injective) t g ?_ i hi)
clear_value c s
simp_rw [← rep_e, Finset.sum_apply, Pi.smul_apply, Finset.smul_sum]
rw [Finset.sum_comm]
refine Finset.sum_eq_zero fun i hi ↦ ?_
replace eq0 := congr_arg L.subtype (congr_fun eq0 ⟨i, hi⟩)
rw [Finset.sum_apply, map_sum] at eq0
have : SMulCommClass Lᵐᵒᵖ K K := ⟨fun _ _ _ ↦ mul_assoc _ _ _⟩
simp_rw [smul_comm _ (c i), ← Finset.smul_sum]
erw [eq0, smul_zero]
variable {K}
open Function in
theorem rank_fun_infinite {ι : Type v} [hι : Infinite ι] : Module.rank K (ι → K) = #(ι → K) := by
obtain ⟨⟨ιK, bK⟩⟩ := Module.Free.exists_basis (R := K) (M := ι → K)
obtain ⟨e⟩ := lift_mk_le'.mp ((aleph0_le_mk_iff.mpr hι).trans_eq (lift_uzero #ι).symm)
have := LinearMap.lift_rank_le_of_injective _ <|
LinearMap.funLeft_injective_of_surjective K K _ (invFun_surjective e.injective)
rw [lift_umax.{u,v}, lift_id'.{u,v}] at this
have key := (lift_le.{v}.mpr <| max_aleph0_card_le_rank_fun_nat K).trans this
rw [lift_max, lift_aleph0, max_le_iff] at key
haveI : Infinite ιK := by
rw [← aleph0_le_mk_iff, bK.mk_eq_rank'']; exact key.1
rw [bK.repr.toEquiv.cardinal_eq, mk_finsupp_lift_of_infinite,
lift_umax.{u,v}, lift_id'.{u,v}, bK.mk_eq_rank'', eq_comm, max_eq_left]
exact key.2
/-- The **Erdős-Kaplansky Theorem**: the dual of an infinite-dimensional vector space
over a division ring has dimension equal to its cardinality. -/
theorem rank_dual_eq_card_dual_of_aleph0_le_rank' {V : Type*} [AddCommGroup V] [Module K V]
(h : ℵ₀ ≤ Module.rank K V) : Module.rank Kᵐᵒᵖ (V →ₗ[K] K) = #(V →ₗ[K] K) := by
obtain ⟨⟨ι, b⟩⟩ := Module.Free.exists_basis (R := K) (M := V)
rw [← b.mk_eq_rank'', aleph0_le_mk_iff] at h
have e := (b.constr Kᵐᵒᵖ (M' := K)).symm.trans
(LinearEquiv.piCongrRight fun _ ↦ MulOpposite.opLinearEquiv Kᵐᵒᵖ)
rw [e.rank_eq, e.toEquiv.cardinal_eq]
apply rank_fun_infinite
/-- The **Erdős-Kaplansky Theorem** over a field. -/
theorem rank_dual_eq_card_dual_of_aleph0_le_rank {K V} [Field K] [AddCommGroup V] [Module K V]
(h : ℵ₀ ≤ Module.rank K V) : Module.rank K (V →ₗ[K] K) = #(V →ₗ[K] K) := by
obtain ⟨⟨ι, b⟩⟩ := Module.Free.exists_basis (R := K) (M := V)
rw [← b.mk_eq_rank'', aleph0_le_mk_iff] at h
have e := (b.constr K (M' := K)).symm
rw [e.rank_eq, e.toEquiv.cardinal_eq]
apply rank_fun_infinite
theorem lift_rank_lt_rank_dual' {V : Type v} [AddCommGroup V] [Module K V]
(h : ℵ₀ ≤ Module.rank K V) :
Cardinal.lift.{u} (Module.rank K V) < Module.rank Kᵐᵒᵖ (V →ₗ[K] K) := by
obtain ⟨⟨ι, b⟩⟩ := Module.Free.exists_basis (R := K) (M := V)
rw [← b.mk_eq_rank'', rank_dual_eq_card_dual_of_aleph0_le_rank' h,
← (b.constr ℕ (M' := K)).toEquiv.cardinal_eq, mk_arrow]
apply cantor'
erw [nat_lt_lift_iff, one_lt_iff_nontrivial]
infer_instance
theorem lift_rank_lt_rank_dual {K : Type u} {V : Type v} [Field K] [AddCommGroup V] [Module K V]
(h : ℵ₀ ≤ Module.rank K V) :
Cardinal.lift.{u} (Module.rank K V) < Module.rank K (V →ₗ[K] K) := by
rw [rank_dual_eq_card_dual_of_aleph0_le_rank h, ← rank_dual_eq_card_dual_of_aleph0_le_rank' h]
exact lift_rank_lt_rank_dual' h
theorem rank_lt_rank_dual' {V : Type u} [AddCommGroup V] [Module K V] (h : ℵ₀ ≤ Module.rank K V) :
Module.rank K V < Module.rank Kᵐᵒᵖ (V →ₗ[K] K) := by
convert lift_rank_lt_rank_dual' h; rw [lift_id]
theorem rank_lt_rank_dual {K V : Type u} [Field K] [AddCommGroup V] [Module K V]
(h : ℵ₀ ≤ Module.rank K V) : Module.rank K V < Module.rank K (V →ₗ[K] K) := by
convert lift_rank_lt_rank_dual h; rw [lift_id]
end Cardinal
|
LinearAlgebra\Dimension\Finite.lean | /-
Copyright (c) 2018 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro, Johannes Hölzl, Sander Dahmen, Scott Morrison
-/
import Mathlib.Algebra.Module.Torsion
import Mathlib.SetTheory.Cardinal.Cofinality
import Mathlib.LinearAlgebra.FreeModule.Finite.Basic
import Mathlib.LinearAlgebra.Dimension.StrongRankCondition
/-!
# Conditions for rank to be finite
Also contains characterization for when rank equals zero or rank equals one.
-/
noncomputable section
universe u v v' w
variable {R : Type u} {M M₁ : Type v} {M' : Type v'} {ι : Type w}
variable [Ring R] [AddCommGroup M] [AddCommGroup M'] [AddCommGroup M₁]
variable [Module R M] [Module R M'] [Module R M₁]
attribute [local instance] nontrivial_of_invariantBasisNumber
open Cardinal Basis Submodule Function Set FiniteDimensional
theorem rank_le {n : ℕ}
(H : ∀ s : Finset M, (LinearIndependent R fun i : s => (i : M)) → s.card ≤ n) :
Module.rank R M ≤ n := by
rw [Module.rank_def]
apply ciSup_le'
rintro ⟨s, li⟩
exact linearIndependent_bounded_of_finset_linearIndependent_bounded H _ li
section RankZero
/-- See `rank_zero_iff` for a stronger version with `NoZeroSMulDivisor R M`. -/
lemma rank_eq_zero_iff :
Module.rank R M = 0 ↔ ∀ x : M, ∃ a : R, a ≠ 0 ∧ a • x = 0 := by
nontriviality R
constructor
· contrapose!
rintro ⟨x, hx⟩
rw [← Cardinal.one_le_iff_ne_zero]
have : LinearIndependent R (fun _ : Unit ↦ x) :=
linearIndependent_iff.mpr (fun l hl ↦ Finsupp.unique_ext <| not_not.mp fun H ↦
hx _ H ((Finsupp.total_unique _ _ _).symm.trans hl))
simpa using this.cardinal_lift_le_rank
· intro h
rw [← le_zero_iff, Module.rank_def]
apply ciSup_le'
intro ⟨s, hs⟩
rw [nonpos_iff_eq_zero, Cardinal.mk_eq_zero_iff, ← not_nonempty_iff]
rintro ⟨i : s⟩
obtain ⟨a, ha, ha'⟩ := h i
apply ha
simpa using DFunLike.congr_fun (linearIndependent_iff.mp hs (Finsupp.single i a) (by simpa)) i
variable [Nontrivial R]
section
variable [NoZeroSMulDivisors R M]
theorem rank_zero_iff_forall_zero :
Module.rank R M = 0 ↔ ∀ x : M, x = 0 := by
simp_rw [rank_eq_zero_iff, smul_eq_zero, and_or_left, not_and_self_iff, false_or,
exists_and_right, and_iff_right (exists_ne (0 : R))]
/-- See `rank_subsingleton` for the reason that `Nontrivial R` is needed.
Also see `rank_eq_zero_iff` for the version without `NoZeroSMulDivisor R M`. -/
theorem rank_zero_iff : Module.rank R M = 0 ↔ Subsingleton M :=
rank_zero_iff_forall_zero.trans (subsingleton_iff_forall_eq 0).symm
theorem rank_pos_iff_exists_ne_zero : 0 < Module.rank R M ↔ ∃ x : M, x ≠ 0 := by
rw [← not_iff_not]
simpa using rank_zero_iff_forall_zero
theorem rank_pos_iff_nontrivial : 0 < Module.rank R M ↔ Nontrivial M :=
rank_pos_iff_exists_ne_zero.trans (nontrivial_iff_exists_ne 0).symm
theorem rank_pos [Nontrivial M] : 0 < Module.rank R M :=
rank_pos_iff_nontrivial.mpr ‹_›
end
lemma rank_eq_zero_iff_isTorsion {R M} [CommRing R] [IsDomain R] [AddCommGroup M] [Module R M] :
Module.rank R M = 0 ↔ Module.IsTorsion R M := by
rw [Module.IsTorsion, rank_eq_zero_iff]
simp [mem_nonZeroDivisors_iff_ne_zero]
variable (R M)
/-- See `rank_subsingleton` that assumes `Subsingleton R` instead. -/
theorem rank_subsingleton' [Subsingleton M] : Module.rank R M = 0 :=
rank_eq_zero_iff.mpr fun _ ↦ ⟨1, one_ne_zero, Subsingleton.elim _ _⟩
@[simp]
theorem rank_punit : Module.rank R PUnit = 0 := rank_subsingleton' _ _
@[simp]
theorem rank_bot : Module.rank R (⊥ : Submodule R M) = 0 := rank_subsingleton' _ _
variable {R M}
theorem exists_mem_ne_zero_of_rank_pos {s : Submodule R M} (h : 0 < Module.rank R s) :
∃ b : M, b ∈ s ∧ b ≠ 0 :=
exists_mem_ne_zero_of_ne_bot fun eq => by rw [eq, rank_bot] at h; exact lt_irrefl _ h
end RankZero
section Finite
theorem Module.finite_of_rank_eq_nat [Module.Free R M] {n : ℕ} (h : Module.rank R M = n) :
Module.Finite R M := by
nontriviality R
obtain ⟨⟨ι, b⟩⟩ := Module.Free.exists_basis (R := R) (M := M)
have := mk_lt_aleph0_iff.mp <|
b.linearIndependent.cardinal_le_rank |>.trans_eq h |>.trans_lt <| nat_lt_aleph0 n
exact Module.Finite.of_basis b
theorem Module.finite_of_rank_eq_zero [NoZeroSMulDivisors R M]
(h : Module.rank R M = 0) :
Module.Finite R M := by
nontriviality R
rw [rank_zero_iff] at h
infer_instance
theorem Module.finite_of_rank_eq_one [Module.Free R M] (h : Module.rank R M = 1) :
Module.Finite R M :=
Module.finite_of_rank_eq_nat <| h.trans Nat.cast_one.symm
section
variable [StrongRankCondition R]
/-- If a module has a finite dimension, all bases are indexed by a finite type. -/
theorem Basis.nonempty_fintype_index_of_rank_lt_aleph0 {ι : Type*} (b : Basis ι R M)
(h : Module.rank R M < ℵ₀) : Nonempty (Fintype ι) := by
rwa [← Cardinal.lift_lt, ← b.mk_eq_rank, Cardinal.lift_aleph0, Cardinal.lift_lt_aleph0,
Cardinal.lt_aleph0_iff_fintype] at h
/-- If a module has a finite dimension, all bases are indexed by a finite type. -/
noncomputable def Basis.fintypeIndexOfRankLtAleph0 {ι : Type*} (b : Basis ι R M)
(h : Module.rank R M < ℵ₀) : Fintype ι :=
Classical.choice (b.nonempty_fintype_index_of_rank_lt_aleph0 h)
/-- If a module has a finite dimension, all bases are indexed by a finite set. -/
theorem Basis.finite_index_of_rank_lt_aleph0 {ι : Type*} {s : Set ι} (b : Basis s R M)
(h : Module.rank R M < ℵ₀) : s.Finite :=
finite_def.2 (b.nonempty_fintype_index_of_rank_lt_aleph0 h)
end
namespace LinearIndependent
variable [StrongRankCondition R]
theorem cardinal_mk_le_finrank [Module.Finite R M]
{ι : Type w} {b : ι → M} (h : LinearIndependent R b) : #ι ≤ finrank R M := by
rw [← lift_le.{max v w}]
simpa only [← finrank_eq_rank, lift_natCast, lift_le_nat_iff] using h.cardinal_lift_le_rank
theorem fintype_card_le_finrank [Module.Finite R M]
{ι : Type*} [Fintype ι] {b : ι → M} (h : LinearIndependent R b) :
Fintype.card ι ≤ finrank R M := by
simpa using h.cardinal_mk_le_finrank
theorem finset_card_le_finrank [Module.Finite R M]
{b : Finset M} (h : LinearIndependent R (fun x => x : b → M)) :
b.card ≤ finrank R M := by
rw [← Fintype.card_coe]
exact h.fintype_card_le_finrank
theorem lt_aleph0_of_finite {ι : Type w}
[Module.Finite R M] {v : ι → M} (h : LinearIndependent R v) : #ι < ℵ₀ := by
apply Cardinal.lift_lt.1
apply lt_of_le_of_lt
· apply h.cardinal_lift_le_rank
· rw [← finrank_eq_rank, Cardinal.lift_aleph0, Cardinal.lift_natCast]
apply Cardinal.nat_lt_aleph0
theorem finite [Module.Finite R M] {ι : Type*} {f : ι → M}
(h : LinearIndependent R f) : Finite ι :=
Cardinal.lt_aleph0_iff_finite.1 <| h.lt_aleph0_of_finite
theorem setFinite [Module.Finite R M] {b : Set M}
(h : LinearIndependent R fun x : b => (x : M)) : b.Finite :=
Cardinal.lt_aleph0_iff_set_finite.mp h.lt_aleph0_of_finite
end LinearIndependent
@[deprecated (since := "2023-12-27")]
alias cardinal_mk_le_finrank_of_linearIndependent := LinearIndependent.cardinal_mk_le_finrank
@[deprecated (since := "2023-12-27")]
alias fintype_card_le_finrank_of_linearIndependent := LinearIndependent.fintype_card_le_finrank
@[deprecated (since := "2023-12-27")]
alias finset_card_le_finrank_of_linearIndependent := LinearIndependent.finset_card_le_finrank
@[deprecated (since := "2023-12-27")]
alias Module.Finite.lt_aleph0_of_linearIndependent := LinearIndependent.lt_aleph0_of_finite
lemma exists_set_linearIndependent_of_lt_rank {n : Cardinal} (hn : n < Module.rank R M) :
∃ s : Set M, #s = n ∧ LinearIndependent R ((↑) : s → M) := by
obtain ⟨⟨s, hs⟩, hs'⟩ := exists_lt_of_lt_ciSup' (hn.trans_eq (Module.rank_def R M))
obtain ⟨t, ht, ht'⟩ := le_mk_iff_exists_subset.mp hs'.le
exact ⟨t, ht', .mono ht hs⟩
lemma exists_finset_linearIndependent_of_le_rank {n : ℕ} (hn : n ≤ Module.rank R M) :
∃ s : Finset M, s.card = n ∧ LinearIndependent R ((↑) : s → M) := by
have := nonempty_linearIndependent_set
cases' hn.eq_or_lt with h h
· obtain ⟨⟨s, hs⟩, hs'⟩ := Cardinal.exists_eq_natCast_of_iSup_eq _
(Cardinal.bddAbove_range.{v, v} _) _ (h.trans (Module.rank_def R M)).symm
have : Finite s := lt_aleph0_iff_finite.mp (hs' ▸ nat_lt_aleph0 n)
cases nonempty_fintype s
exact ⟨s.toFinset, by simpa using hs', by convert hs <;> exact Set.mem_toFinset⟩
· obtain ⟨s, hs, hs'⟩ := exists_set_linearIndependent_of_lt_rank h
have : Finite s := lt_aleph0_iff_finite.mp (hs ▸ nat_lt_aleph0 n)
cases nonempty_fintype s
exact ⟨s.toFinset, by simpa using hs, by convert hs' <;> exact Set.mem_toFinset⟩
lemma exists_linearIndependent_of_le_rank {n : ℕ} (hn : n ≤ Module.rank R M) :
∃ f : Fin n → M, LinearIndependent R f :=
have ⟨_, hs, hs'⟩ := exists_finset_linearIndependent_of_le_rank hn
⟨_, (linearIndependent_equiv (Finset.equivFinOfCardEq hs).symm).mpr hs'⟩
lemma natCast_le_rank_iff [Nontrivial R] {n : ℕ} :
n ≤ Module.rank R M ↔ ∃ f : Fin n → M, LinearIndependent R f :=
⟨exists_linearIndependent_of_le_rank,
fun H ↦ by simpa using H.choose_spec.cardinal_lift_le_rank⟩
lemma natCast_le_rank_iff_finset [Nontrivial R] {n : ℕ} :
n ≤ Module.rank R M ↔ ∃ s : Finset M, s.card = n ∧ LinearIndependent R ((↑) : s → M) :=
⟨exists_finset_linearIndependent_of_le_rank,
fun ⟨s, h₁, h₂⟩ ↦ by simpa [h₁] using h₂.cardinal_le_rank⟩
lemma exists_finset_linearIndependent_of_le_finrank {n : ℕ} (hn : n ≤ finrank R M) :
∃ s : Finset M, s.card = n ∧ LinearIndependent R ((↑) : s → M) := by
by_cases h : finrank R M = 0
· rw [le_zero_iff.mp (hn.trans_eq h)]
exact ⟨∅, rfl, by convert linearIndependent_empty R M using 2 <;> aesop⟩
exact exists_finset_linearIndependent_of_le_rank
((natCast_le.mpr hn).trans_eq (cast_toNat_of_lt_aleph0 (toNat_ne_zero.mp h).2))
lemma exists_linearIndependent_of_le_finrank {n : ℕ} (hn : n ≤ finrank R M) :
∃ f : Fin n → M, LinearIndependent R f :=
have ⟨_, hs, hs'⟩ := exists_finset_linearIndependent_of_le_finrank hn
⟨_, (linearIndependent_equiv (Finset.equivFinOfCardEq hs).symm).mpr hs'⟩
variable [Module.Finite R M] [StrongRankCondition R] in
theorem Module.Finite.not_linearIndependent_of_infinite {ι : Type*} [Infinite ι]
(v : ι → M) : ¬LinearIndependent R v := mt LinearIndependent.finite <| @not_finite _ _
section
variable [NoZeroSMulDivisors R M]
theorem CompleteLattice.Independent.subtype_ne_bot_le_rank [Nontrivial R]
{V : ι → Submodule R M} (hV : CompleteLattice.Independent V) :
Cardinal.lift.{v} #{ i : ι // V i ≠ ⊥ } ≤ Cardinal.lift.{w} (Module.rank R M) := by
set I := { i : ι // V i ≠ ⊥ }
have hI : ∀ i : I, ∃ v ∈ V i, v ≠ (0 : M) := by
intro i
rw [← Submodule.ne_bot_iff]
exact i.prop
choose v hvV hv using hI
have : LinearIndependent R v := (hV.comp Subtype.coe_injective).linearIndependent _ hvV hv
exact this.cardinal_lift_le_rank
variable [Module.Finite R M] [StrongRankCondition R]
theorem CompleteLattice.Independent.subtype_ne_bot_le_finrank_aux
{p : ι → Submodule R M} (hp : CompleteLattice.Independent p) :
#{ i // p i ≠ ⊥ } ≤ (finrank R M : Cardinal.{w}) := by
suffices Cardinal.lift.{v} #{ i // p i ≠ ⊥ } ≤ Cardinal.lift.{v} (finrank R M : Cardinal.{w}) by
rwa [Cardinal.lift_le] at this
calc
Cardinal.lift.{v} #{ i // p i ≠ ⊥ } ≤ Cardinal.lift.{w} (Module.rank R M) :=
hp.subtype_ne_bot_le_rank
_ = Cardinal.lift.{w} (finrank R M : Cardinal.{v}) := by rw [finrank_eq_rank]
_ = Cardinal.lift.{v} (finrank R M : Cardinal.{w}) := by simp
/-- If `p` is an independent family of submodules of a `R`-finite module `M`, then the
number of nontrivial subspaces in the family `p` is finite. -/
noncomputable def CompleteLattice.Independent.fintypeNeBotOfFiniteDimensional
{p : ι → Submodule R M} (hp : CompleteLattice.Independent p) :
Fintype { i : ι // p i ≠ ⊥ } := by
suffices #{ i // p i ≠ ⊥ } < (ℵ₀ : Cardinal.{w}) by
rw [Cardinal.lt_aleph0_iff_fintype] at this
exact this.some
refine lt_of_le_of_lt hp.subtype_ne_bot_le_finrank_aux ?_
simp [Cardinal.nat_lt_aleph0]
/-- If `p` is an independent family of submodules of a `R`-finite module `M`, then the
number of nontrivial subspaces in the family `p` is bounded above by the dimension of `M`.
Note that the `Fintype` hypothesis required here can be provided by
`CompleteLattice.Independent.fintypeNeBotOfFiniteDimensional`. -/
theorem CompleteLattice.Independent.subtype_ne_bot_le_finrank
{p : ι → Submodule R M} (hp : CompleteLattice.Independent p) [Fintype { i // p i ≠ ⊥ }] :
Fintype.card { i // p i ≠ ⊥ } ≤ finrank R M := by simpa using hp.subtype_ne_bot_le_finrank_aux
end
variable [Module.Finite R M] [StrongRankCondition R]
section
open Finset
/-- If a finset has cardinality larger than the rank of a module,
then there is a nontrivial linear relation amongst its elements. -/
theorem Module.exists_nontrivial_relation_of_finrank_lt_card {t : Finset M}
(h : finrank R M < t.card) : ∃ f : M → R, ∑ e ∈ t, f e • e = 0 ∧ ∃ x ∈ t, f x ≠ 0 := by
obtain ⟨g, sum, z, nonzero⟩ := Fintype.not_linearIndependent_iff.mp
(mt LinearIndependent.finset_card_le_finrank h.not_le)
refine ⟨Subtype.val.extend g 0, ?_, z, z.2, by rwa [Subtype.val_injective.extend_apply]⟩
rw [← Finset.sum_finset_coe]; convert sum; apply Subtype.val_injective.extend_apply
/-- If a finset has cardinality larger than `finrank + 1`,
then there is a nontrivial linear relation amongst its elements,
such that the coefficients of the relation sum to zero. -/
theorem Module.exists_nontrivial_relation_sum_zero_of_finrank_succ_lt_card
{t : Finset M} (h : finrank R M + 1 < t.card) :
∃ f : M → R, ∑ e ∈ t, f e • e = 0 ∧ ∑ e ∈ t, f e = 0 ∧ ∃ x ∈ t, f x ≠ 0 := by
-- Pick an element x₀ ∈ t,
obtain ⟨x₀, x₀_mem⟩ := card_pos.1 ((Nat.succ_pos _).trans h)
-- and apply the previous lemma to the {xᵢ - x₀}
let shift : M ↪ M := ⟨(· - x₀), sub_left_injective⟩
classical
let t' := (t.erase x₀).map shift
have h' : finrank R M < t'.card := by
rw [card_map, card_erase_of_mem x₀_mem]
exact Nat.lt_pred_iff.mpr h
-- to obtain a function `g`.
obtain ⟨g, gsum, x₁, x₁_mem, nz⟩ := exists_nontrivial_relation_of_finrank_lt_card h'
-- Then obtain `f` by translating back by `x₀`,
-- and setting the value of `f` at `x₀` to ensure `∑ e ∈ t, f e = 0`.
let f : M → R := fun z ↦ if z = x₀ then -∑ z ∈ t.erase x₀, g (z - x₀) else g (z - x₀)
refine ⟨f, ?_, ?_, ?_⟩
-- After this, it's a matter of verifying the properties,
-- based on the corresponding properties for `g`.
· rw [sum_map, Embedding.coeFn_mk] at gsum
simp_rw [f, ← t.sum_erase_add _ x₀_mem, if_pos, neg_smul, sum_smul,
← sub_eq_add_neg, ← sum_sub_distrib, ← gsum, smul_sub]
refine sum_congr rfl fun x x_mem ↦ ?_
rw [if_neg (mem_erase.mp x_mem).1]
· simp_rw [f, ← t.sum_erase_add _ x₀_mem, if_pos, add_neg_eq_zero]
exact sum_congr rfl fun x x_mem ↦ if_neg (mem_erase.mp x_mem).1
· obtain ⟨x₁, x₁_mem', rfl⟩ := Finset.mem_map.mp x₁_mem
have := mem_erase.mp x₁_mem'
exact ⟨x₁, by
simpa only [f, Embedding.coeFn_mk, sub_add_cancel, this.2, true_and, if_neg this.1]⟩
end
end Finite
section FinrankZero
section
variable [Nontrivial R]
/-- A (finite dimensional) space that is a subsingleton has zero `finrank`. -/
@[nontriviality]
theorem FiniteDimensional.finrank_zero_of_subsingleton [Subsingleton M] :
finrank R M = 0 := by
rw [finrank, rank_subsingleton', _root_.map_zero]
lemma LinearIndependent.finrank_eq_zero_of_infinite {ι} [Infinite ι] {v : ι → M}
(hv : LinearIndependent R v) : finrank R M = 0 := toNat_eq_zero.mpr <| .inr hv.aleph0_le_rank
section
variable [NoZeroSMulDivisors R M]
/-- A finite dimensional space is nontrivial if it has positive `finrank`. -/
theorem FiniteDimensional.nontrivial_of_finrank_pos (h : 0 < finrank R M) : Nontrivial M :=
rank_pos_iff_nontrivial.mp (lt_rank_of_lt_finrank h)
/-- A finite dimensional space is nontrivial if it has `finrank` equal to the successor of a
natural number. -/
theorem FiniteDimensional.nontrivial_of_finrank_eq_succ {n : ℕ}
(hn : finrank R M = n.succ) : Nontrivial M :=
nontrivial_of_finrank_pos (by rw [hn]; exact n.succ_pos)
end
variable (R M)
@[simp]
theorem finrank_bot : finrank R (⊥ : Submodule R M) = 0 :=
finrank_eq_of_rank_eq (rank_bot _ _)
end
section StrongRankCondition
variable [StrongRankCondition R] [Module.Finite R M]
/-- A finite rank torsion-free module has positive `finrank` iff it has a nonzero element. -/
theorem FiniteDimensional.finrank_pos_iff_exists_ne_zero [NoZeroSMulDivisors R M] :
0 < finrank R M ↔ ∃ x : M, x ≠ 0 := by
rw [← @rank_pos_iff_exists_ne_zero R M, ← finrank_eq_rank]
norm_cast
/-- An `R`-finite torsion-free module has positive `finrank` iff it is nontrivial. -/
theorem FiniteDimensional.finrank_pos_iff [NoZeroSMulDivisors R M] :
0 < finrank R M ↔ Nontrivial M := by
rw [← rank_pos_iff_nontrivial (R := R), ← finrank_eq_rank]
norm_cast
/-- A nontrivial finite dimensional space has positive `finrank`. -/
theorem FiniteDimensional.finrank_pos [NoZeroSMulDivisors R M] [h : Nontrivial M] :
0 < finrank R M :=
finrank_pos_iff.mpr h
/-- See `FiniteDimensional.finrank_zero_iff`
for the stronger version with `NoZeroSMulDivisors R M`. -/
theorem FiniteDimensional.finrank_eq_zero_iff :
finrank R M = 0 ↔ ∀ x : M, ∃ a : R, a ≠ 0 ∧ a • x = 0 := by
rw [← rank_eq_zero_iff (R := R), ← finrank_eq_rank]
norm_cast
/-- The `StrongRankCondition` is automatic. See `commRing_strongRankCondition`. -/
theorem FiniteDimensional.finrank_eq_zero_iff_isTorsion {R} [CommRing R] [StrongRankCondition R]
[IsDomain R] [Module R M] [Module.Finite R M] :
finrank R M = 0 ↔ Module.IsTorsion R M := by
rw [← rank_eq_zero_iff_isTorsion (R := R), ← finrank_eq_rank]
norm_cast
/-- A finite dimensional space has zero `finrank` iff it is a subsingleton.
This is the `finrank` version of `rank_zero_iff`. -/
theorem FiniteDimensional.finrank_zero_iff [NoZeroSMulDivisors R M] :
finrank R M = 0 ↔ Subsingleton M := by
rw [← rank_zero_iff (R := R), ← finrank_eq_rank]
norm_cast
end StrongRankCondition
theorem FiniteDimensional.finrank_eq_zero_of_rank_eq_zero (h : Module.rank R M = 0) :
finrank R M = 0 := by
delta finrank
rw [h, zero_toNat]
theorem Submodule.bot_eq_top_of_rank_eq_zero [NoZeroSMulDivisors R M] (h : Module.rank R M = 0) :
(⊥ : Submodule R M) = ⊤ := by
nontriviality R
rw [rank_zero_iff] at h
subsingleton
/-- See `rank_subsingleton` for the reason that `Nontrivial R` is needed. -/
@[simp]
theorem Submodule.rank_eq_zero [Nontrivial R] [NoZeroSMulDivisors R M] {S : Submodule R M} :
Module.rank R S = 0 ↔ S = ⊥ :=
⟨fun h =>
(Submodule.eq_bot_iff _).2 fun x hx =>
congr_arg Subtype.val <|
((Submodule.eq_bot_iff _).1 <| Eq.symm <| Submodule.bot_eq_top_of_rank_eq_zero h) ⟨x, hx⟩
Submodule.mem_top,
fun h => by rw [h, rank_bot]⟩
@[simp]
theorem Submodule.finrank_eq_zero [StrongRankCondition R] [NoZeroSMulDivisors R M]
{S : Submodule R M} [Module.Finite R S] :
finrank R S = 0 ↔ S = ⊥ := by
rw [← Submodule.rank_eq_zero, ← finrank_eq_rank, ← @Nat.cast_zero Cardinal, Cardinal.natCast_inj]
@[simp]
lemma Submodule.one_le_finrank_iff [StrongRankCondition R] [NoZeroSMulDivisors R M]
{S : Submodule R M} [Module.Finite R S] :
1 ≤ finrank R S ↔ S ≠ ⊥ := by
simp [← not_iff_not]
variable [Module.Free R M]
theorem finrank_eq_zero_of_basis_imp_not_finite
(h : ∀ s : Set M, Basis.{v} (s : Set M) R M → ¬s.Finite) : finrank R M = 0 := by
cases subsingleton_or_nontrivial R
· have := Module.subsingleton R M
exact (h ∅ ⟨LinearEquiv.ofSubsingleton _ _⟩ Set.finite_empty).elim
obtain ⟨_, ⟨b⟩⟩ := (Module.free_iff_set R M).mp ‹_›
have := Set.Infinite.to_subtype (h _ b)
exact b.linearIndependent.finrank_eq_zero_of_infinite
theorem finrank_eq_zero_of_basis_imp_false (h : ∀ s : Finset M, Basis.{v} (s : Set M) R M → False) :
finrank R M = 0 :=
finrank_eq_zero_of_basis_imp_not_finite fun s b hs =>
h hs.toFinset
(by
convert b
simp)
theorem finrank_eq_zero_of_not_exists_basis
(h : ¬∃ s : Finset M, Nonempty (Basis (s : Set M) R M)) : finrank R M = 0 :=
finrank_eq_zero_of_basis_imp_false fun s b => h ⟨s, ⟨b⟩⟩
theorem finrank_eq_zero_of_not_exists_basis_finite
(h : ¬∃ (s : Set M) (_ : Basis.{v} (s : Set M) R M), s.Finite) : finrank R M = 0 :=
finrank_eq_zero_of_basis_imp_not_finite fun s b hs => h ⟨s, b, hs⟩
theorem finrank_eq_zero_of_not_exists_basis_finset (h : ¬∃ s : Finset M, Nonempty (Basis s R M)) :
finrank R M = 0 :=
finrank_eq_zero_of_basis_imp_false fun s b => h ⟨s, ⟨b⟩⟩
end FinrankZero
section RankOne
variable [NoZeroSMulDivisors R M] [StrongRankCondition R]
/-- If there is a nonzero vector and every other vector is a multiple of it,
then the module has dimension one. -/
theorem rank_eq_one (v : M) (n : v ≠ 0) (h : ∀ w : M, ∃ c : R, c • v = w) :
Module.rank R M = 1 := by
haveI := nontrivial_of_invariantBasisNumber R
obtain ⟨b⟩ := (Basis.basis_singleton_iff.{_, _, u} PUnit).mpr ⟨v, n, h⟩
rw [rank_eq_card_basis b, Fintype.card_punit, Nat.cast_one]
/-- If there is a nonzero vector and every other vector is a multiple of it,
then the module has dimension one. -/
theorem finrank_eq_one (v : M) (n : v ≠ 0) (h : ∀ w : M, ∃ c : R, c • v = w) : finrank R M = 1 :=
finrank_eq_of_rank_eq (rank_eq_one v n h)
/-- If every vector is a multiple of some `v : M`, then `M` has dimension at most one.
-/
theorem finrank_le_one (v : M) (h : ∀ w : M, ∃ c : R, c • v = w) : finrank R M ≤ 1 := by
haveI := nontrivial_of_invariantBasisNumber R
rcases eq_or_ne v 0 with (rfl | hn)
· haveI :=
_root_.subsingleton_of_forall_eq (0 : M) fun w => by
obtain ⟨c, rfl⟩ := h w
simp
rw [finrank_zero_of_subsingleton]
exact zero_le_one
· exact (finrank_eq_one v hn h).le
end RankOne
|
LinearAlgebra\Dimension\Finrank.lean | /-
Copyright (c) 2019 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes, Anne Baanen
-/
import Mathlib.LinearAlgebra.Dimension.Basic
import Mathlib.SetTheory.Cardinal.ToNat
/-!
# Finite dimension of vector spaces
Definition of the rank of a module, or dimension of a vector space, as a natural number.
## Main definitions
Defined is `FiniteDimensional.finrank`, the dimension of a finite dimensional space, returning a
`Nat`, as opposed to `Module.rank`, which returns a `Cardinal`. When the space has infinite
dimension, its `finrank` is by convention set to `0`.
The definition of `finrank` does not assume a `FiniteDimensional` instance, but lemmas might.
Import `LinearAlgebra.FiniteDimensional` to get access to these additional lemmas.
Formulas for the dimension are given for linear equivs, in `LinearEquiv.finrank_eq`.
## Implementation notes
Most results are deduced from the corresponding results for the general dimension (as a cardinal),
in `Dimension.lean`. Not all results have been ported yet.
You should not assume that there has been any effort to state lemmas as generally as possible.
-/
universe u v w
open Cardinal Submodule Module Function
variable {R : Type u} {M : Type v} {N : Type w}
variable [Ring R] [AddCommGroup M] [Module R M] [AddCommGroup N] [Module R N]
namespace FiniteDimensional
section Ring
/-- The rank of a module as a natural number.
Defined by convention to be `0` if the space has infinite rank.
For a vector space `M` over a field `R`, this is the same as the finite dimension
of `M` over `R`.
-/
noncomputable def finrank (R M : Type*) [Semiring R] [AddCommGroup M] [Module R M] : ℕ :=
Cardinal.toNat (Module.rank R M)
theorem finrank_eq_of_rank_eq {n : ℕ} (h : Module.rank R M = ↑n) : finrank R M = n := by
apply_fun toNat at h
rw [toNat_natCast] at h
exact mod_cast h
lemma rank_eq_one_iff_finrank_eq_one : Module.rank R M = 1 ↔ finrank R M = 1 :=
Cardinal.toNat_eq_one.symm
/-- This is like `rank_eq_one_iff_finrank_eq_one` but works for `2`, `3`, `4`, ... -/
lemma rank_eq_ofNat_iff_finrank_eq_ofNat (n : ℕ) [Nat.AtLeastTwo n] :
Module.rank R M = OfNat.ofNat n ↔ finrank R M = OfNat.ofNat n :=
Cardinal.toNat_eq_ofNat.symm
theorem finrank_le_of_rank_le {n : ℕ} (h : Module.rank R M ≤ ↑n) : finrank R M ≤ n := by
rwa [← Cardinal.toNat_le_iff_le_of_lt_aleph0, toNat_natCast] at h
· exact h.trans_lt (nat_lt_aleph0 n)
· exact nat_lt_aleph0 n
theorem finrank_lt_of_rank_lt {n : ℕ} (h : Module.rank R M < ↑n) : finrank R M < n := by
rwa [← Cardinal.toNat_lt_iff_lt_of_lt_aleph0, toNat_natCast] at h
· exact h.trans (nat_lt_aleph0 n)
· exact nat_lt_aleph0 n
theorem lt_rank_of_lt_finrank {n : ℕ} (h : n < finrank R M) : ↑n < Module.rank R M := by
rwa [← Cardinal.toNat_lt_iff_lt_of_lt_aleph0, toNat_natCast]
· exact nat_lt_aleph0 n
· contrapose! h
rw [finrank, Cardinal.toNat_apply_of_aleph0_le h]
exact n.zero_le
theorem one_lt_rank_of_one_lt_finrank (h : 1 < finrank R M) : 1 < Module.rank R M := by
simpa using lt_rank_of_lt_finrank h
theorem finrank_le_finrank_of_rank_le_rank
(h : lift.{w} (Module.rank R M) ≤ Cardinal.lift.{v} (Module.rank R N))
(h' : Module.rank R N < ℵ₀) : finrank R M ≤ finrank R N := by
simpa only [toNat_lift] using toNat_le_toNat h (lift_lt_aleph0.mpr h')
end Ring
end FiniteDimensional
open FiniteDimensional
namespace LinearEquiv
variable {R M M₂ : Type*} [Ring R] [AddCommGroup M] [AddCommGroup M₂]
variable [Module R M] [Module R M₂]
/-- The dimension of a finite dimensional space is preserved under linear equivalence. -/
theorem finrank_eq (f : M ≃ₗ[R] M₂) : finrank R M = finrank R M₂ := by
unfold finrank
rw [← Cardinal.toNat_lift, f.lift_rank_eq, Cardinal.toNat_lift]
/-- Pushforwards of finite-dimensional submodules along a `LinearEquiv` have the same finrank. -/
theorem finrank_map_eq (f : M ≃ₗ[R] M₂) (p : Submodule R M) :
finrank R (p.map (f : M →ₗ[R] M₂)) = finrank R p :=
(f.submoduleMap p).finrank_eq.symm
end LinearEquiv
/-- The dimensions of the domain and range of an injective linear map are equal. -/
theorem LinearMap.finrank_range_of_inj {f : M →ₗ[R] N} (hf : Function.Injective f) :
finrank R (LinearMap.range f) = finrank R M := by rw [(LinearEquiv.ofInjective f hf).finrank_eq]
@[simp]
theorem Submodule.finrank_map_subtype_eq (p : Submodule R M) (q : Submodule R p) :
finrank R (q.map p.subtype) = finrank R q :=
(Submodule.equivSubtypeMap p q).symm.finrank_eq
variable (R M)
@[simp]
theorem finrank_top : finrank R (⊤ : Submodule R M) = finrank R M := by
unfold finrank
simp [rank_top]
|
LinearAlgebra\Dimension\Free.lean | /-
Copyright (c) 2021 Riccardo Brasca. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Riccardo Brasca
-/
import Mathlib.LinearAlgebra.Dimension.StrongRankCondition
import Mathlib.LinearAlgebra.FreeModule.Basic
import Mathlib.LinearAlgebra.FreeModule.Finite.Basic
/-!
# Rank of free modules
## Main result
- `LinearEquiv.nonempty_equiv_iff_lift_rank_eq`:
Two free modules are isomorphic iff they have the same dimension.
- `FiniteDimensional.finBasis`:
An arbitrary basis of a finite free module indexed by `Fin n` given `finrank R M = n`.
-/
noncomputable section
universe u v v' w
open Cardinal Basis Submodule Function Set DirectSum FiniteDimensional
section Tower
variable (F : Type u) (K : Type v) (A : Type w)
variable [Ring F] [Ring K] [AddCommGroup A]
variable [Module F K] [Module K A] [Module F A] [IsScalarTower F K A]
variable [StrongRankCondition F] [StrongRankCondition K] [Module.Free F K] [Module.Free K A]
/-- Tower law: if `A` is a `K`-module and `K` is an extension of `F` then
$\operatorname{rank}_F(A) = \operatorname{rank}_F(K) * \operatorname{rank}_K(A)$.
The universe polymorphic version of `rank_mul_rank` below. -/
theorem lift_rank_mul_lift_rank :
Cardinal.lift.{w} (Module.rank F K) * Cardinal.lift.{v} (Module.rank K A) =
Cardinal.lift.{v} (Module.rank F A) := by
let b := Module.Free.chooseBasis F K
let c := Module.Free.chooseBasis K A
rw [← (Module.rank F K).lift_id, ← b.mk_eq_rank, ← (Module.rank K A).lift_id, ← c.mk_eq_rank,
← lift_umax.{w, v}, ← (b.smulTower c).mk_eq_rank, mk_prod, lift_mul, lift_lift, lift_lift,
lift_lift, lift_lift, lift_umax.{v, w}]
/-- Tower law: if `A` is a `K`-module and `K` is an extension of `F` then
$\operatorname{rank}_F(A) = \operatorname{rank}_F(K) * \operatorname{rank}_K(A)$.
This is a simpler version of `lift_rank_mul_lift_rank` with `K` and `A` in the same universe. -/
theorem rank_mul_rank (A : Type v) [AddCommGroup A]
[Module K A] [Module F A] [IsScalarTower F K A] [Module.Free K A] :
Module.rank F K * Module.rank K A = Module.rank F A := by
convert lift_rank_mul_lift_rank F K A <;> rw [lift_id]
/-- Tower law: if `A` is a `K`-module and `K` is an extension of `F` then
$\operatorname{rank}_F(A) = \operatorname{rank}_F(K) * \operatorname{rank}_K(A)$. -/
theorem FiniteDimensional.finrank_mul_finrank : finrank F K * finrank K A = finrank F A := by
simp_rw [finrank]
rw [← toNat_lift.{w} (Module.rank F K), ← toNat_lift.{v} (Module.rank K A), ← toNat_mul,
lift_rank_mul_lift_rank, toNat_lift]
end Tower
variable {R : Type u} {M M₁ : Type v} {M' : Type v'}
variable [Ring R] [StrongRankCondition R]
variable [AddCommGroup M] [Module R M] [Module.Free R M]
variable [AddCommGroup M'] [Module R M'] [Module.Free R M']
variable [AddCommGroup M₁] [Module R M₁] [Module.Free R M₁]
namespace Module.Free
variable (R M)
/-- The rank of a free module `M` over `R` is the cardinality of `ChooseBasisIndex R M`. -/
theorem rank_eq_card_chooseBasisIndex : Module.rank R M = #(ChooseBasisIndex R M) :=
(chooseBasis R M).mk_eq_rank''.symm
/-- The finrank of a free module `M` over `R` is the cardinality of `ChooseBasisIndex R M`. -/
theorem _root_.FiniteDimensional.finrank_eq_card_chooseBasisIndex [Module.Finite R M] :
finrank R M = Fintype.card (ChooseBasisIndex R M) := by
simp [finrank, rank_eq_card_chooseBasisIndex]
/-- The rank of a free module `M` over an infinite scalar ring `R` is the cardinality of `M`
whenever `#R < #M`. -/
lemma rank_eq_mk_of_infinite_lt [Infinite R] (h_lt : lift.{v} #R < lift.{u} #M) :
Module.rank R M = #M := by
have : Infinite M := infinite_iff.mpr <| lift_le.mp <| le_trans (by simp) h_lt.le
have h : lift #M = lift #(ChooseBasisIndex R M →₀ R) := lift_mk_eq'.mpr ⟨(chooseBasis R M).repr⟩
simp only [mk_finsupp_lift_of_infinite', lift_id', ← rank_eq_card_chooseBasisIndex, lift_max,
lift_lift] at h
refine lift_inj.mp ((max_eq_iff.mp h.symm).resolve_right <| not_and_of_not_left _ ?_).left
exact (lift_umax.{v, u}.symm ▸ h_lt).ne
end Module.Free
open Module.Free
open Cardinal
/-- Two vector spaces are isomorphic if they have the same dimension. -/
theorem nonempty_linearEquiv_of_lift_rank_eq
(cnd : Cardinal.lift.{v'} (Module.rank R M) = Cardinal.lift.{v} (Module.rank R M')) :
Nonempty (M ≃ₗ[R] M') := by
obtain ⟨⟨α, B⟩⟩ := Module.Free.exists_basis (R := R) (M := M)
obtain ⟨⟨β, B'⟩⟩ := Module.Free.exists_basis (R := R) (M := M')
have : Cardinal.lift.{v', v} #α = Cardinal.lift.{v, v'} #β := by
rw [B.mk_eq_rank'', cnd, B'.mk_eq_rank'']
exact (Cardinal.lift_mk_eq.{v, v', 0}.1 this).map (B.equiv B')
/-- Two vector spaces are isomorphic if they have the same dimension. -/
theorem nonempty_linearEquiv_of_rank_eq (cond : Module.rank R M = Module.rank R M₁) :
Nonempty (M ≃ₗ[R] M₁) :=
nonempty_linearEquiv_of_lift_rank_eq <| congr_arg _ cond
section
variable (M M' M₁)
/-- Two vector spaces are isomorphic if they have the same dimension. -/
def LinearEquiv.ofLiftRankEq
(cond : Cardinal.lift.{v'} (Module.rank R M) = Cardinal.lift.{v} (Module.rank R M')) :
M ≃ₗ[R] M' :=
Classical.choice (nonempty_linearEquiv_of_lift_rank_eq cond)
/-- Two vector spaces are isomorphic if they have the same dimension. -/
def LinearEquiv.ofRankEq (cond : Module.rank R M = Module.rank R M₁) : M ≃ₗ[R] M₁ :=
Classical.choice (nonempty_linearEquiv_of_rank_eq cond)
end
/-- Two vector spaces are isomorphic if and only if they have the same dimension. -/
theorem LinearEquiv.nonempty_equiv_iff_lift_rank_eq : Nonempty (M ≃ₗ[R] M') ↔
Cardinal.lift.{v'} (Module.rank R M) = Cardinal.lift.{v} (Module.rank R M') :=
⟨fun ⟨h⟩ => LinearEquiv.lift_rank_eq h, fun h => nonempty_linearEquiv_of_lift_rank_eq h⟩
/-- Two vector spaces are isomorphic if and only if they have the same dimension. -/
theorem LinearEquiv.nonempty_equiv_iff_rank_eq :
Nonempty (M ≃ₗ[R] M₁) ↔ Module.rank R M = Module.rank R M₁ :=
⟨fun ⟨h⟩ => LinearEquiv.rank_eq h, fun h => nonempty_linearEquiv_of_rank_eq h⟩
/-- Two finite and free modules are isomorphic if they have the same (finite) rank. -/
theorem FiniteDimensional.nonempty_linearEquiv_of_finrank_eq
[Module.Finite R M] [Module.Finite R M'] (cond : finrank R M = finrank R M') :
Nonempty (M ≃ₗ[R] M') :=
nonempty_linearEquiv_of_lift_rank_eq <| by simp only [← finrank_eq_rank, cond, lift_natCast]
/-- Two finite and free modules are isomorphic if and only if they have the same (finite) rank. -/
theorem FiniteDimensional.nonempty_linearEquiv_iff_finrank_eq [Module.Finite R M]
[Module.Finite R M'] : Nonempty (M ≃ₗ[R] M') ↔ finrank R M = finrank R M' :=
⟨fun ⟨h⟩ => h.finrank_eq, fun h => nonempty_linearEquiv_of_finrank_eq h⟩
variable (M M')
/-- Two finite and free modules are isomorphic if they have the same (finite) rank. -/
noncomputable def LinearEquiv.ofFinrankEq [Module.Finite R M] [Module.Finite R M']
(cond : finrank R M = finrank R M') : M ≃ₗ[R] M' :=
Classical.choice <| FiniteDimensional.nonempty_linearEquiv_of_finrank_eq cond
variable {M M'}
/-- See `rank_lt_aleph0` for the inverse direction without `Module.Free R M`. -/
lemma Module.rank_lt_alpeh0_iff :
Module.rank R M < ℵ₀ ↔ Module.Finite R M := by
rw [Free.rank_eq_card_chooseBasisIndex, mk_lt_aleph0_iff]
exact ⟨fun h ↦ Finite.of_basis (Free.chooseBasis R M),
fun I ↦ Finite.of_fintype (Free.ChooseBasisIndex R M)⟩
theorem FiniteDimensional.finrank_of_not_finite
(h : ¬Module.Finite R M) :
finrank R M = 0 := by
rw [finrank, toNat_eq_zero, ← not_lt, Module.rank_lt_alpeh0_iff]
exact .inr h
theorem Module.finite_of_finrank_pos (h : 0 < finrank R M) :
Module.Finite R M := by
contrapose h
simp [finrank_of_not_finite h]
theorem Module.finite_of_finrank_eq_succ {n : ℕ}
(hn : finrank R M = n.succ) : Module.Finite R M :=
Module.finite_of_finrank_pos <| by rw [hn]; exact n.succ_pos
theorem Module.finite_iff_of_rank_eq_nsmul {W} [AddCommGroup W]
[Module R W] [Module.Free R W] {n : ℕ} (hn : n ≠ 0)
(hVW : Module.rank R M = n • Module.rank R W) :
Module.Finite R M ↔ Module.Finite R W := by
simp only [← rank_lt_alpeh0_iff, hVW, nsmul_lt_aleph0_iff_of_ne_zero hn]
namespace FiniteDimensional
variable (R M)
/-- A finite rank free module has a basis indexed by `Fin (finrank R M)`. -/
noncomputable def finBasis [Module.Finite R M] :
Basis (Fin (finrank R M)) R M :=
(Module.Free.chooseBasis R M).reindex (Fintype.equivFinOfCardEq
(finrank_eq_card_chooseBasisIndex R M).symm)
/-- A rank `n` free module has a basis indexed by `Fin n`. -/
noncomputable def finBasisOfFinrankEq [Module.Finite R M] {n : ℕ} (hn : finrank R M = n) :
Basis (Fin n) R M := (finBasis R M).reindex (finCongr hn)
variable {R M}
/-- A free module with rank 1 has a basis with one element. -/
noncomputable def basisUnique (ι : Type*) [Unique ι]
(h : finrank R M = 1) :
Basis ι R M :=
haveI : Module.Finite R M :=
Module.finite_of_finrank_pos (_root_.zero_lt_one.trans_le h.symm.le)
(finBasisOfFinrankEq R M h).reindex (Equiv.equivOfUnique _ _)
@[simp]
theorem basisUnique_repr_eq_zero_iff {ι : Type*} [Unique ι]
{h : finrank R M = 1} {v : M} {i : ι} :
(basisUnique ι h).repr v i = 0 ↔ v = 0 :=
⟨fun hv =>
(basisUnique ι h).repr.map_eq_zero_iff.mp (Finsupp.ext fun j => Subsingleton.elim i j ▸ hv),
fun hv => by rw [hv, LinearEquiv.map_zero, Finsupp.zero_apply]⟩
end FiniteDimensional
|
LinearAlgebra\Dimension\FreeAndStrongRankCondition.lean | /-
Copyright (c) 2024 Jz Pan. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jz Pan
-/
import Mathlib.LinearAlgebra.Dimension.Finite
import Mathlib.LinearAlgebra.Dimension.Constructions
/-!
# Some results on free modules over rings satisfying strong rank condition
This file contains some results on free modules over rings satisfying strong rank condition.
Most of them are generalized from the same result assuming the base ring being division ring,
and are moved from the files `Mathlib/LinearAlgebra/Dimension/DivisionRing.lean`
and `Mathlib/LinearAlgebra/FiniteDimensional.lean`.
-/
open Cardinal Submodule Set FiniteDimensional
universe u v
section Module
variable {K : Type u} {V : Type v} [Ring K] [StrongRankCondition K] [AddCommGroup V] [Module K V]
/-- The `ι` indexed basis on `V`, where `ι` is an empty type and `V` is zero-dimensional.
See also `FiniteDimensional.finBasis`.
-/
noncomputable def Basis.ofRankEqZero [Module.Free K V] {ι : Type*} [IsEmpty ι]
(hV : Module.rank K V = 0) : Basis ι K V :=
haveI : Subsingleton V := by
obtain ⟨_, b⟩ := Module.Free.exists_basis (R := K) (M := V)
haveI := mk_eq_zero_iff.1 (hV ▸ b.mk_eq_rank'')
exact b.repr.toEquiv.subsingleton
Basis.empty _
@[simp]
theorem Basis.ofRankEqZero_apply [Module.Free K V] {ι : Type*} [IsEmpty ι]
(hV : Module.rank K V = 0) (i : ι) : Basis.ofRankEqZero hV i = 0 := rfl
theorem le_rank_iff_exists_linearIndependent [Module.Free K V] {c : Cardinal} :
c ≤ Module.rank K V ↔ ∃ s : Set V, #s = c ∧ LinearIndependent K ((↑) : s → V) := by
haveI := nontrivial_of_invariantBasisNumber K
constructor
· intro h
obtain ⟨κ, t'⟩ := Module.Free.exists_basis (R := K) (M := V)
let t := t'.reindexRange
have : LinearIndependent K ((↑) : Set.range t' → V) := by
convert t.linearIndependent
ext; exact (Basis.reindexRange_apply _ _).symm
rw [← t.mk_eq_rank'', le_mk_iff_exists_subset] at h
rcases h with ⟨s, hst, hsc⟩
exact ⟨s, hsc, this.mono hst⟩
· rintro ⟨s, rfl, si⟩
exact si.cardinal_le_rank
theorem le_rank_iff_exists_linearIndependent_finset
[Module.Free K V] {n : ℕ} : ↑n ≤ Module.rank K V ↔
∃ s : Finset V, s.card = n ∧ LinearIndependent K ((↑) : ↥(s : Set V) → V) := by
simp only [le_rank_iff_exists_linearIndependent, mk_set_eq_nat_iff_finset]
constructor
· rintro ⟨s, ⟨t, rfl, rfl⟩, si⟩
exact ⟨t, rfl, si⟩
· rintro ⟨s, rfl, si⟩
exact ⟨s, ⟨s, rfl, rfl⟩, si⟩
/-- A vector space has dimension at most `1` if and only if there is a
single vector of which all vectors are multiples. -/
theorem rank_le_one_iff [Module.Free K V] :
Module.rank K V ≤ 1 ↔ ∃ v₀ : V, ∀ v, ∃ r : K, r • v₀ = v := by
obtain ⟨κ, b⟩ := Module.Free.exists_basis (R := K) (M := V)
constructor
· intro hd
rw [← b.mk_eq_rank'', le_one_iff_subsingleton] at hd
rcases isEmpty_or_nonempty κ with hb | ⟨⟨i⟩⟩
· use 0
have h' : ∀ v : V, v = 0 := by
simpa [range_eq_empty, Submodule.eq_bot_iff] using b.span_eq.symm
intro v
simp [h' v]
· use b i
have h' : (K ∙ b i) = ⊤ :=
(subsingleton_range b).eq_singleton_of_mem (mem_range_self i) ▸ b.span_eq
intro v
have hv : v ∈ (⊤ : Submodule K V) := mem_top
rwa [← h', mem_span_singleton] at hv
· rintro ⟨v₀, hv₀⟩
have h : (K ∙ v₀) = ⊤ := by
ext
simp [mem_span_singleton, hv₀]
rw [← rank_top, ← h]
refine (rank_span_le _).trans_eq ?_
simp
/-- A vector space has dimension `1` if and only if there is a
single non-zero vector of which all vectors are multiples. -/
theorem rank_eq_one_iff [Module.Free K V] :
Module.rank K V = 1 ↔ ∃ v₀ : V, v₀ ≠ 0 ∧ ∀ v, ∃ r : K, r • v₀ = v := by
haveI := nontrivial_of_invariantBasisNumber K
refine ⟨fun h ↦ ?_, fun ⟨v₀, h, hv⟩ ↦ (rank_le_one_iff.2 ⟨v₀, hv⟩).antisymm ?_⟩
· obtain ⟨v₀, hv⟩ := rank_le_one_iff.1 h.le
refine ⟨v₀, fun hzero ↦ ?_, hv⟩
simp_rw [hzero, smul_zero, exists_const] at hv
haveI : Subsingleton V := .intro fun _ _ ↦ by simp_rw [← hv]
exact one_ne_zero (h ▸ rank_subsingleton' K V)
· by_contra H
rw [not_le, lt_one_iff_zero] at H
obtain ⟨κ, b⟩ := Module.Free.exists_basis (R := K) (M := V)
haveI := mk_eq_zero_iff.1 (H ▸ b.mk_eq_rank'')
haveI := b.repr.toEquiv.subsingleton
exact h (Subsingleton.elim _ _)
/-- A submodule has dimension at most `1` if and only if there is a
single vector in the submodule such that the submodule is contained in
its span. -/
theorem rank_submodule_le_one_iff (s : Submodule K V) [Module.Free K s] :
Module.rank K s ≤ 1 ↔ ∃ v₀ ∈ s, s ≤ K ∙ v₀ := by
simp_rw [rank_le_one_iff, le_span_singleton_iff]
constructor
· rintro ⟨⟨v₀, hv₀⟩, h⟩
use v₀, hv₀
intro v hv
obtain ⟨r, hr⟩ := h ⟨v, hv⟩
use r
rwa [Subtype.ext_iff, coe_smul] at hr
· rintro ⟨v₀, hv₀, h⟩
use ⟨v₀, hv₀⟩
rintro ⟨v, hv⟩
obtain ⟨r, hr⟩ := h v hv
use r
rwa [Subtype.ext_iff, coe_smul]
/-- A submodule has dimension `1` if and only if there is a
single non-zero vector in the submodule such that the submodule is contained in
its span. -/
theorem rank_submodule_eq_one_iff (s : Submodule K V) [Module.Free K s] :
Module.rank K s = 1 ↔ ∃ v₀ ∈ s, v₀ ≠ 0 ∧ s ≤ K ∙ v₀ := by
simp_rw [rank_eq_one_iff, le_span_singleton_iff]
refine ⟨fun ⟨⟨v₀, hv₀⟩, H, h⟩ ↦ ⟨v₀, hv₀, fun h' ↦ by simp [h'] at H, fun v hv ↦ ?_⟩,
fun ⟨v₀, hv₀, H, h⟩ ↦ ⟨⟨v₀, hv₀⟩, fun h' ↦ H (by simpa using h'), fun ⟨v, hv⟩ ↦ ?_⟩⟩
· obtain ⟨r, hr⟩ := h ⟨v, hv⟩
exact ⟨r, by rwa [Subtype.ext_iff, coe_smul] at hr⟩
· obtain ⟨r, hr⟩ := h v hv
exact ⟨r, by rwa [Subtype.ext_iff, coe_smul]⟩
/-- A submodule has dimension at most `1` if and only if there is a
single vector, not necessarily in the submodule, such that the
submodule is contained in its span. -/
theorem rank_submodule_le_one_iff' (s : Submodule K V) [Module.Free K s] :
Module.rank K s ≤ 1 ↔ ∃ v₀, s ≤ K ∙ v₀ := by
haveI := nontrivial_of_invariantBasisNumber K
constructor
· rw [rank_submodule_le_one_iff]
rintro ⟨v₀, _, h⟩
exact ⟨v₀, h⟩
· rintro ⟨v₀, h⟩
obtain ⟨κ, b⟩ := Module.Free.exists_basis (R := K) (M := s)
simpa [b.mk_eq_rank''] using b.linearIndependent.map' _ (ker_inclusion _ _ h)
|>.cardinal_le_rank.trans (rank_span_le {v₀})
theorem Submodule.rank_le_one_iff_isPrincipal (W : Submodule K V) [Module.Free K W] :
Module.rank K W ≤ 1 ↔ W.IsPrincipal := by
simp only [rank_le_one_iff, Submodule.isPrincipal_iff, le_antisymm_iff, le_span_singleton_iff,
span_singleton_le_iff_mem]
constructor
· rintro ⟨⟨m, hm⟩, hm'⟩
choose f hf using hm'
exact ⟨m, ⟨fun v hv => ⟨f ⟨v, hv⟩, congr_arg ((↑) : W → V) (hf ⟨v, hv⟩)⟩, hm⟩⟩
· rintro ⟨a, ⟨h, ha⟩⟩
choose f hf using h
exact ⟨⟨a, ha⟩, fun v => ⟨f v.1 v.2, Subtype.ext (hf v.1 v.2)⟩⟩
theorem Module.rank_le_one_iff_top_isPrincipal [Module.Free K V] :
Module.rank K V ≤ 1 ↔ (⊤ : Submodule K V).IsPrincipal := by
haveI := Module.Free.of_equiv (topEquiv (R := K) (M := V)).symm
rw [← Submodule.rank_le_one_iff_isPrincipal, rank_top]
/-- A module has dimension 1 iff there is some `v : V` so `{v}` is a basis.
-/
theorem finrank_eq_one_iff [Module.Free K V] (ι : Type*) [Unique ι] :
finrank K V = 1 ↔ Nonempty (Basis ι K V) := by
constructor
· intro h
exact ⟨basisUnique ι h⟩
· rintro ⟨b⟩
simpa using finrank_eq_card_basis b
/-- A module has dimension 1 iff there is some nonzero `v : V` so every vector is a multiple of `v`.
-/
theorem finrank_eq_one_iff' [Module.Free K V] :
finrank K V = 1 ↔ ∃ v ≠ 0, ∀ w : V, ∃ c : K, c • v = w := by
rw [← rank_eq_one_iff]
exact toNat_eq_iff one_ne_zero
/-- A finite dimensional module has dimension at most 1 iff
there is some `v : V` so every vector is a multiple of `v`.
-/
theorem finrank_le_one_iff [Module.Free K V] [Module.Finite K V] :
finrank K V ≤ 1 ↔ ∃ v : V, ∀ w : V, ∃ c : K, c • v = w := by
rw [← rank_le_one_iff, ← finrank_eq_rank, ← natCast_le, Nat.cast_one]
theorem Submodule.finrank_le_one_iff_isPrincipal
(W : Submodule K V) [Module.Free K W] [Module.Finite K W] :
finrank K W ≤ 1 ↔ W.IsPrincipal := by
rw [← W.rank_le_one_iff_isPrincipal, ← finrank_eq_rank, ← natCast_le, Nat.cast_one]
theorem Module.finrank_le_one_iff_top_isPrincipal [Module.Free K V] [Module.Finite K V] :
finrank K V ≤ 1 ↔ (⊤ : Submodule K V).IsPrincipal := by
rw [← Module.rank_le_one_iff_top_isPrincipal, ← finrank_eq_rank, ← natCast_le, Nat.cast_one]
variable (K V) in
theorem lift_cardinal_mk_eq_lift_cardinal_mk_field_pow_lift_rank [Module.Free K V]
[Module.Finite K V] : lift.{u} #V = lift.{v} #K ^ lift.{u} (Module.rank K V) := by
haveI := nontrivial_of_invariantBasisNumber K
obtain ⟨s, hs⟩ := Module.Free.exists_basis (R := K) (M := V)
-- `Module.Finite.finite_basis` is in a much later file, so we copy its proof to here
haveI : Finite s := by
obtain ⟨t, ht⟩ := ‹Module.Finite K V›
exact basis_finite_of_finite_spans _ t.finite_toSet ht hs
have := lift_mk_eq'.2 ⟨hs.repr.toEquiv⟩
rwa [Finsupp.equivFunOnFinite.cardinal_eq, mk_arrow, hs.mk_eq_rank'', lift_power, lift_lift,
lift_lift, lift_umax'] at this
theorem cardinal_mk_eq_cardinal_mk_field_pow_rank (K V : Type u) [Ring K] [StrongRankCondition K]
[AddCommGroup V] [Module K V] [Module.Free K V] [Module.Finite K V] :
#V = #K ^ Module.rank K V := by
simpa using lift_cardinal_mk_eq_lift_cardinal_mk_field_pow_lift_rank K V
variable (K V) in
theorem cardinal_lt_aleph0_of_finiteDimensional [Finite K] [Module.Free K V] [Module.Finite K V] :
#V < ℵ₀ := by
rw [← lift_lt_aleph0.{v, u}, lift_cardinal_mk_eq_lift_cardinal_mk_field_pow_lift_rank K V]
exact power_lt_aleph0 (lift_lt_aleph0.2 (lt_aleph0_of_finite K))
(lift_lt_aleph0.2 (rank_lt_aleph0 K V))
end Module
namespace Subalgebra
variable {F E : Type*} [CommRing F] [StrongRankCondition F] [Ring E] [Algebra F E]
{S : Subalgebra F E}
theorem eq_bot_of_rank_le_one (h : Module.rank F S ≤ 1) [Module.Free F S] : S = ⊥ := by
nontriviality E
obtain ⟨κ, b⟩ := Module.Free.exists_basis (R := F) (M := S)
by_cases h1 : Module.rank F S = 1
· refine bot_unique fun x hx ↦ Algebra.mem_bot.2 ?_
rw [← b.mk_eq_rank'', eq_one_iff_unique, ← unique_iff_subsingleton_and_nonempty] at h1
obtain ⟨h1⟩ := h1
obtain ⟨y, hy⟩ := (bijective_algebraMap_of_linearEquiv (b.repr ≪≫ₗ
Finsupp.LinearEquiv.finsuppUnique _ _ _).symm).surjective ⟨x, hx⟩
exact ⟨y, congr(Subtype.val $(hy))⟩
haveI := mk_eq_zero_iff.1 (b.mk_eq_rank''.symm ▸ lt_one_iff_zero.1 (h.lt_of_ne h1))
haveI := b.repr.toEquiv.subsingleton
exact False.elim <| one_ne_zero congr(S.val $(Subsingleton.elim 1 0))
theorem eq_bot_of_finrank_one (h : finrank F S = 1) [Module.Free F S] : S = ⊥ := by
refine Subalgebra.eq_bot_of_rank_le_one ?_
rw [finrank, toNat_eq_one] at h
rw [h]
@[simp]
theorem rank_eq_one_iff [Nontrivial E] [Module.Free F S] : Module.rank F S = 1 ↔ S = ⊥ := by
refine ⟨fun h ↦ Subalgebra.eq_bot_of_rank_le_one h.le, ?_⟩
rintro rfl
obtain ⟨κ, b⟩ := Module.Free.exists_basis (R := F) (M := (⊥ : Subalgebra F E))
refine le_antisymm ?_ ?_
· have := lift_rank_range_le (Algebra.linearMap F E)
rwa [← one_eq_range, rank_self, lift_one, lift_le_one_iff] at this
· by_contra H
rw [not_le, lt_one_iff_zero] at H
haveI := mk_eq_zero_iff.1 (H ▸ b.mk_eq_rank'')
haveI := b.repr.toEquiv.subsingleton
exact one_ne_zero congr((⊥ : Subalgebra F E).val $(Subsingleton.elim 1 0))
@[simp]
theorem finrank_eq_one_iff [Nontrivial E] [Module.Free F S] : finrank F S = 1 ↔ S = ⊥ := by
rw [← Subalgebra.rank_eq_one_iff]
exact toNat_eq_iff one_ne_zero
theorem bot_eq_top_iff_rank_eq_one [Nontrivial E] [Module.Free F E] :
(⊥ : Subalgebra F E) = ⊤ ↔ Module.rank F E = 1 := by
haveI := Module.Free.of_equiv (Subalgebra.topEquiv (R := F) (A := E)).toLinearEquiv.symm
-- Porting note: removed `subalgebra_top_rank_eq_submodule_top_rank`
rw [← rank_top, Subalgebra.rank_eq_one_iff, eq_comm]
theorem bot_eq_top_iff_finrank_eq_one [Nontrivial E] [Module.Free F E] :
(⊥ : Subalgebra F E) = ⊤ ↔ finrank F E = 1 := by
haveI := Module.Free.of_equiv (Subalgebra.topEquiv (R := F) (A := E)).toLinearEquiv.symm
rw [← finrank_top, ← subalgebra_top_finrank_eq_submodule_top_finrank,
Subalgebra.finrank_eq_one_iff, eq_comm]
alias ⟨_, bot_eq_top_of_rank_eq_one⟩ := bot_eq_top_iff_rank_eq_one
alias ⟨_, bot_eq_top_of_finrank_eq_one⟩ := bot_eq_top_iff_finrank_eq_one
attribute [simp] bot_eq_top_of_finrank_eq_one bot_eq_top_of_rank_eq_one
end Subalgebra
|
LinearAlgebra\Dimension\LinearMap.lean | /-
Copyright (c) 2019 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl
-/
import Mathlib.LinearAlgebra.Dimension.DivisionRing
import Mathlib.LinearAlgebra.Dimension.FreeAndStrongRankCondition
/-!
# The rank of a linear map
## Main Definition
- `LinearMap.rank`: The rank of a linear map.
-/
noncomputable section
universe u v v' v''
variable {K : Type u} {V V₁ : Type v} {V' V'₁ : Type v'} {V'' : Type v''}
open Cardinal Basis Submodule Function Set
namespace LinearMap
section Ring
variable [Ring K] [AddCommGroup V] [Module K V] [AddCommGroup V₁] [Module K V₁]
variable [AddCommGroup V'] [Module K V']
/-- `rank f` is the rank of a `LinearMap` `f`, defined as the dimension of `f.range`. -/
abbrev rank (f : V →ₗ[K] V') : Cardinal :=
Module.rank K (LinearMap.range f)
theorem rank_le_range (f : V →ₗ[K] V') : rank f ≤ Module.rank K V' :=
rank_submodule_le _
theorem rank_le_domain (f : V →ₗ[K] V₁) : rank f ≤ Module.rank K V :=
rank_range_le _
@[simp]
theorem rank_zero [Nontrivial K] : rank (0 : V →ₗ[K] V') = 0 := by
rw [rank, LinearMap.range_zero, rank_bot]
variable [AddCommGroup V''] [Module K V'']
theorem rank_comp_le_left (g : V →ₗ[K] V') (f : V' →ₗ[K] V'') : rank (f.comp g) ≤ rank f := by
refine rank_le_of_submodule _ _ ?_
rw [LinearMap.range_comp]
exact LinearMap.map_le_range
theorem lift_rank_comp_le_right (g : V →ₗ[K] V') (f : V' →ₗ[K] V'') :
Cardinal.lift.{v'} (rank (f.comp g)) ≤ Cardinal.lift.{v''} (rank g) := by
rw [rank, rank, LinearMap.range_comp]; exact lift_rank_map_le _ _
/-- The rank of the composition of two maps is less than the minimum of their ranks. -/
theorem lift_rank_comp_le (g : V →ₗ[K] V') (f : V' →ₗ[K] V'') :
Cardinal.lift.{v'} (rank (f.comp g)) ≤
min (Cardinal.lift.{v'} (rank f)) (Cardinal.lift.{v''} (rank g)) :=
le_min (Cardinal.lift_le.mpr <| rank_comp_le_left _ _) (lift_rank_comp_le_right _ _)
variable [AddCommGroup V'₁] [Module K V'₁]
theorem rank_comp_le_right (g : V →ₗ[K] V') (f : V' →ₗ[K] V'₁) : rank (f.comp g) ≤ rank g := by
simpa only [Cardinal.lift_id] using lift_rank_comp_le_right g f
/-- The rank of the composition of two maps is less than the minimum of their ranks.
See `lift_rank_comp_le` for the universe-polymorphic version. -/
theorem rank_comp_le (g : V →ₗ[K] V') (f : V' →ₗ[K] V'₁) :
rank (f.comp g) ≤ min (rank f) (rank g) := by
simpa only [Cardinal.lift_id] using lift_rank_comp_le g f
end Ring
section DivisionRing
variable [DivisionRing K] [AddCommGroup V] [Module K V] [AddCommGroup V₁] [Module K V₁]
variable [AddCommGroup V'] [Module K V']
theorem rank_add_le (f g : V →ₗ[K] V') : rank (f + g) ≤ rank f + rank g :=
calc
rank (f + g) ≤ Module.rank K (LinearMap.range f ⊔ LinearMap.range g : Submodule K V') := by
refine rank_le_of_submodule _ _ ?_
exact LinearMap.range_le_iff_comap.2 <| eq_top_iff'.2 fun x =>
show f x + g x ∈ (LinearMap.range f ⊔ LinearMap.range g : Submodule K V') from
mem_sup.2 ⟨_, ⟨x, rfl⟩, _, ⟨x, rfl⟩, rfl⟩
_ ≤ rank f + rank g := Submodule.rank_add_le_rank_add_rank _ _
theorem rank_finset_sum_le {η} (s : Finset η) (f : η → V →ₗ[K] V') :
rank (∑ d ∈ s, f d) ≤ ∑ d ∈ s, rank (f d) :=
@Finset.sum_hom_rel _ _ _ _ _ (fun a b => rank a ≤ b) f (fun d => rank (f d)) s
(le_of_eq rank_zero) fun _ _ _ h => le_trans (rank_add_le _ _) (add_le_add_left h _)
theorem le_rank_iff_exists_linearIndependent {c : Cardinal} {f : V →ₗ[K] V'} :
c ≤ rank f ↔ ∃ s : Set V,
Cardinal.lift.{v'} #s = Cardinal.lift.{v} c ∧ LinearIndependent K (fun x : s => f x) := by
rcases f.rangeRestrict.exists_rightInverse_of_surjective f.range_rangeRestrict with ⟨g, hg⟩
have fg : LeftInverse f.rangeRestrict g := LinearMap.congr_fun hg
refine ⟨fun h => ?_, ?_⟩
· rcases _root_.le_rank_iff_exists_linearIndependent.1 h with ⟨s, rfl, si⟩
refine ⟨g '' s, Cardinal.mk_image_eq_lift _ _ fg.injective, ?_⟩
replace fg : ∀ x, f (g x) = x := by
intro x
convert congr_arg Subtype.val (fg x)
replace si : LinearIndependent K fun x : s => f (g x) := by
simpa only [fg] using si.map' _ (ker_subtype _)
exact si.image_of_comp s g f
· rintro ⟨s, hsc, si⟩
have : LinearIndependent K fun x : s => f.rangeRestrict x :=
LinearIndependent.of_comp f.range.subtype (by convert si)
convert this.image.cardinal_le_rank
rw [← Cardinal.lift_inj, ← hsc, Cardinal.mk_image_eq_of_injOn_lift]
exact injOn_iff_injective.2 this.injective
theorem le_rank_iff_exists_linearIndependent_finset {n : ℕ} {f : V →ₗ[K] V'} :
↑n ≤ rank f ↔ ∃ s : Finset V, s.card = n ∧ LinearIndependent K fun x : (s : Set V) => f x := by
simp only [le_rank_iff_exists_linearIndependent, Cardinal.lift_natCast, Cardinal.lift_eq_nat_iff,
Cardinal.mk_set_eq_nat_iff_finset]
constructor
· rintro ⟨s, ⟨t, rfl, rfl⟩, si⟩
exact ⟨t, rfl, si⟩
· rintro ⟨s, rfl, si⟩
exact ⟨s, ⟨s, rfl, rfl⟩, si⟩
end DivisionRing
end LinearMap
|
LinearAlgebra\Dimension\Localization.lean | /-
Copyright (c) 2024 Andrew Yang. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Andrew Yang
-/
import Mathlib.Algebra.Module.Submodule.Localization
import Mathlib.LinearAlgebra.Dimension.DivisionRing
import Mathlib.RingTheory.Localization.FractionRing
import Mathlib.RingTheory.OreLocalization.OreSet
/-!
# Rank of localization
## Main statements
- `IsLocalizedModule.lift_rank_eq`: `rank_Rₚ Mₚ = rank R M`.
- `rank_quotient_add_rank_of_isDomain`: The **rank-nullity theorem** for commutative domains.
-/
open Cardinal nonZeroDivisors
section CommRing
universe u u' v v'
variable {R : Type u} (S : Type u') {M : Type v} {N : Type v'}
variable [CommRing R] [CommRing S] [AddCommGroup M] [AddCommGroup N]
variable [Module R M] [Module R N] [Algebra R S] [Module S N] [IsScalarTower R S N]
variable (p : Submonoid R) [IsLocalization p S] (f : M →ₗ[R] N) [IsLocalizedModule p f]
variable (hp : p ≤ R⁰)
variable {S} in
lemma IsLocalizedModule.linearIndependent_lift {ι} {v : ι → N} (hf : LinearIndependent S v) :
∃ w : ι → M, LinearIndependent R w := by
choose sec hsec using IsLocalizedModule.surj p f
use fun i ↦ (sec (v i)).1
rw [linearIndependent_iff'] at hf ⊢
intro t g hg i hit
apply hp (sec (v i)).2.prop
apply IsLocalization.injective S hp
rw [map_zero]
refine hf t (fun i ↦ algebraMap R S (g i * (sec (v i)).2)) ?_ _ hit
simp only [map_mul, mul_smul, algebraMap_smul, ← Submonoid.smul_def,
hsec, ← map_smul, ← map_sum, hg, map_zero]
lemma IsLocalizedModule.lift_rank_eq :
Cardinal.lift.{v} (Module.rank S N) = Cardinal.lift.{v'} (Module.rank R M) := by
cases' subsingleton_or_nontrivial R
· have := (algebraMap R S).codomain_trivial; simp only [rank_subsingleton, lift_one]
have := (IsLocalization.injective S hp).nontrivial
apply le_antisymm
· rw [Module.rank_def, lift_iSup (bddAbove_range.{v', v'} _)]
apply ciSup_le'
intro ⟨s, hs⟩
exact (IsLocalizedModule.linearIndependent_lift p f hp hs).choose_spec.cardinal_lift_le_rank
· rw [Module.rank_def, lift_iSup (bddAbove_range.{v, v} _)]
apply ciSup_le'
intro ⟨s, hs⟩
choose sec hsec using IsLocalization.surj p (S := S)
refine LinearIndependent.cardinal_lift_le_rank (ι := s) (v := fun i ↦ f i) ?_
rw [linearIndependent_iff'] at hs ⊢
intro t g hg i hit
apply (IsLocalization.map_units S (sec (g i)).2).mul_left_injective
classical
let u := fun (i : s) ↦ (t.erase i).prod (fun j ↦ (sec (g j)).2)
have : f (t.sum fun i ↦ u i • (sec (g i)).1 • i) = f 0 := by
convert congr_arg (t.prod (fun j ↦ (sec (g j)).2) • ·) hg
· simp only [map_sum, map_smul, Submonoid.smul_def, Finset.smul_sum]
apply Finset.sum_congr rfl
intro j hj
simp only [u, ← @IsScalarTower.algebraMap_smul R S N, Submonoid.coe_finset_prod, map_prod]
rw [← hsec, mul_comm (g j), mul_smul, ← mul_smul, Finset.prod_erase_mul (h := hj)]
rw [map_zero, smul_zero]
obtain ⟨c, hc⟩ := IsLocalizedModule.exists_of_eq (S := p) this
simp_rw [smul_zero, Finset.smul_sum, ← mul_smul, Submonoid.smul_def, ← mul_smul, mul_comm] at hc
simp only [hsec, zero_mul, map_eq_zero_iff (algebraMap R S) (IsLocalization.injective S hp)]
apply hp (c * u i).prop
exact hs t _ hc _ hit
lemma IsLocalizedModule.rank_eq {N : Type v} [AddCommGroup N]
[Module R N] [Module S N] [IsScalarTower R S N] (f : M →ₗ[R] N) [IsLocalizedModule p f] :
Module.rank S N = Module.rank R M := by simpa using IsLocalizedModule.lift_rank_eq S p f hp
variable (R M) in
theorem exists_set_linearIndependent_of_isDomain [IsDomain R] :
∃ s : Set M, #s = Module.rank R M ∧ LinearIndependent (ι := s) R Subtype.val := by
obtain ⟨w, hw⟩ :=
IsLocalizedModule.linearIndependent_lift R⁰ (LocalizedModule.mkLinearMap R⁰ M) le_rfl
(Module.Free.chooseBasis (FractionRing R) (LocalizedModule R⁰ M)).linearIndependent
refine ⟨Set.range w, ?_, (linearIndependent_subtype_range hw.injective).mpr hw⟩
apply Cardinal.lift_injective.{max u v}
rw [Cardinal.mk_range_eq_of_injective hw.injective, ← Module.Free.rank_eq_card_chooseBasisIndex,
IsLocalizedModule.lift_rank_eq (FractionRing R) R⁰ (LocalizedModule.mkLinearMap R⁰ M) le_rfl]
/-- The **rank-nullity theorem** for commutative domains. Also see `rank_quotient_add_rank`. -/
theorem rank_quotient_add_rank_of_isDomain [IsDomain R] (M' : Submodule R M) :
Module.rank R (M ⧸ M') + Module.rank R M' = Module.rank R M := by
apply lift_injective.{max u v}
rw [lift_add, ← IsLocalizedModule.lift_rank_eq (FractionRing R) R⁰ (M'.toLocalized R⁰) le_rfl,
← IsLocalizedModule.lift_rank_eq (FractionRing R) R⁰ (LocalizedModule.mkLinearMap R⁰ M) le_rfl,
← IsLocalizedModule.lift_rank_eq (FractionRing R) R⁰ (M'.toLocalizedQuotient R⁰) le_rfl,
← lift_add, rank_quotient_add_rank_of_divisionRing]
universe w in
instance IsDomain.hasRankNullity [IsDomain R] : HasRankNullity.{w} R where
rank_quotient_add_rank := rank_quotient_add_rank_of_isDomain
exists_set_linearIndependent M := exists_set_linearIndependent_of_isDomain R M
end CommRing
section Ring
variable {R} [Ring R] [IsDomain R] (S : Submonoid R)
/-- A domain that is not (left) Ore is of infinite rank.
See [cohn_1995] Proposition 1.3.6 -/
lemma aleph0_le_rank_of_isEmpty_oreSet (hS : IsEmpty (OreLocalization.OreSet R⁰)) :
ℵ₀ ≤ Module.rank R R := by
classical
rw [← not_nonempty_iff, OreLocalization.nonempty_oreSet_iff_of_noZeroDivisors] at hS
push_neg at hS
obtain ⟨r, s, h⟩ := hS
refine Cardinal.aleph0_le.mpr fun n ↦ ?_
suffices LinearIndependent R (fun (i : Fin n) ↦ r * s ^ (i : ℕ)) by
simpa using this.cardinal_lift_le_rank
suffices ∀ (g : ℕ → R) (x), (∑ i ∈ Finset.range n, g i • (r * s ^ (i + x))) = 0 →
∀ i < n, g i = 0 by
refine Fintype.linearIndependent_iff.mpr fun g hg i ↦ ?_
simpa only [dif_pos i.prop] using this (fun i ↦ if h : i < n then g ⟨i, h⟩ else 0) 0
(by simp [← Fin.sum_univ_eq_sum_range, ← hg]) i i.prop
intro g x hg i hin
induction' n with n IH generalizing g x i
· exact (hin.not_le (zero_le i)).elim
· rw [Finset.sum_range_succ'] at hg
by_cases hg0 : g 0 = 0
· simp only [hg0, zero_smul, add_zero, add_assoc] at hg
cases i; exacts [hg0, IH _ _ hg _ (Nat.succ_lt_succ_iff.mp hin)]
simp only [MulOpposite.smul_eq_mul_unop, zero_add, ← add_comm _ x, pow_add _ _ x,
← mul_assoc, pow_succ, ← Finset.sum_mul, pow_zero, one_mul, smul_eq_mul] at hg
rw [← neg_eq_iff_add_eq_zero, ← neg_mul, ← neg_mul] at hg
have := mul_right_cancel₀ (mem_nonZeroDivisors_iff_ne_zero.mp (s ^ x).prop) hg
exact (h _ ⟨(g 0), mem_nonZeroDivisors_iff_ne_zero.mpr (by simpa)⟩ this.symm).elim
-- TODO: Upgrade this to an iff. See [lam_1999] Exercise 10.21
lemma nonempty_oreSet_of_strongRankCondition [StrongRankCondition R] :
Nonempty (OreLocalization.OreSet R⁰) := by
by_contra h
have := aleph0_le_rank_of_isEmpty_oreSet (not_nonempty_iff.mp h)
rw [rank_self] at this
exact this.not_lt one_lt_aleph0
end Ring
|
LinearAlgebra\Dimension\RankNullity.lean | /-
Copyright (c) 2024 Andrew Yang. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Andrew Yang
-/
import Mathlib.LinearAlgebra.Dimension.Constructions
import Mathlib.LinearAlgebra.Dimension.Finite
/-!
# The rank nullity theorem
In this file we provide the rank nullity theorem as a typeclass, and prove various corollaries
of the theorem. The main definition is `HasRankNullity.{u} R`, which states that
1. Every `R`-module `M : Type u` has a linear independent subset of cardinality `Module.rank R M`.
2. `rank (M ⧸ N) + rank N = rank M` for every `R`-module `M : Type u` and every `N : Submodule R M`.
The following instances are provided in mathlib:
1. `DivisionRing.hasRankNullity` for division rings in `LinearAlgebra/Dimension/DivisionRing.lean`.
2. `IsDomain.hasRankNullity` for commutative domains in `LinearAlgebra/Dimension/Localization.lean`.
TODO: prove the rank-nullity theorem for `[Ring R] [IsDomain R] [StrongRankCondition R]`.
See `nonempty_oreSet_of_strongRankCondition` for a start.
-/
universe u v
open Function Set Cardinal
variable {R} {M M₁ M₂ M₃ : Type u} {M' : Type v} [Ring R]
variable [AddCommGroup M] [AddCommGroup M₁] [AddCommGroup M₂] [AddCommGroup M₃] [AddCommGroup M']
variable [Module R M] [Module R M₁] [Module R M₂] [Module R M₃] [Module R M']
/--
`HasRankNullity.{u}` is a class of rings satisfying
1. Every `R`-module `M : Type u` has a linear independent subset of cardinality `Module.rank R M`.
2. `rank (M ⧸ N) + rank N = rank M` for every `R`-module `M : Type u` and every `N : Submodule R M`.
Usually such a ring satisfies `HasRankNullity.{w}` for all universes `w`, and the universe
argument is there because of technical limitations to universe polymorphism.
See `DivisionRing.hasRankNullity` and `IsDomain.hasRankNullity`.
-/
@[pp_with_univ]
class HasRankNullity (R : Type v) [inst : Ring R] : Prop where
exists_set_linearIndependent : ∀ (M : Type u) [AddCommGroup M] [Module R M],
∃ s : Set M, #s = Module.rank R M ∧ LinearIndependent (ι := s) R Subtype.val
rank_quotient_add_rank : ∀ {M : Type u} [AddCommGroup M] [Module R M] (N : Submodule R M),
Module.rank R (M ⧸ N) + Module.rank R N = Module.rank R M
variable [HasRankNullity.{u} R]
lemma rank_quotient_add_rank (N : Submodule R M) :
Module.rank R (M ⧸ N) + Module.rank R N = Module.rank R M :=
HasRankNullity.rank_quotient_add_rank N
variable (R M) in
lemma exists_set_linearIndependent :
∃ s : Set M, #s = Module.rank R M ∧ LinearIndependent (ι := s) R Subtype.val :=
HasRankNullity.exists_set_linearIndependent M
variable (R) in
theorem nontrivial_of_hasRankNullity : Nontrivial R := by
refine (subsingleton_or_nontrivial R).resolve_left fun H ↦ ?_
have := rank_quotient_add_rank (R := R) (M := PUnit) ⊥
simp [one_add_one_eq_two] at this
attribute [local instance] nontrivial_of_hasRankNullity
theorem lift_rank_range_add_rank_ker (f : M →ₗ[R] M') :
lift.{u} (Module.rank R (LinearMap.range f)) + lift.{v} (Module.rank R (LinearMap.ker f)) =
lift.{v} (Module.rank R M) := by
haveI := fun p : Submodule R M => Classical.decEq (M ⧸ p)
rw [← f.quotKerEquivRange.lift_rank_eq, ← lift_add, rank_quotient_add_rank]
/-- The **rank-nullity theorem** -/
theorem rank_range_add_rank_ker (f : M →ₗ[R] M₁) :
Module.rank R (LinearMap.range f) + Module.rank R (LinearMap.ker f) = Module.rank R M := by
haveI := fun p : Submodule R M => Classical.decEq (M ⧸ p)
rw [← f.quotKerEquivRange.rank_eq, rank_quotient_add_rank]
theorem lift_rank_eq_of_surjective {f : M →ₗ[R] M'} (h : Surjective f) :
lift.{v} (Module.rank R M) =
lift.{u} (Module.rank R M') + lift.{v} (Module.rank R (LinearMap.ker f)) := by
rw [← lift_rank_range_add_rank_ker f, ← rank_range_of_surjective f h]
theorem rank_eq_of_surjective {f : M →ₗ[R] M₁} (h : Surjective f) :
Module.rank R M = Module.rank R M₁ + Module.rank R (LinearMap.ker f) := by
rw [← rank_range_add_rank_ker f, ← rank_range_of_surjective f h]
theorem exists_linearIndependent_of_lt_rank [StrongRankCondition R]
{s : Set M} (hs : LinearIndependent (ι := s) R Subtype.val) :
∃ t, s ⊆ t ∧ #t = Module.rank R M ∧ LinearIndependent (ι := t) R Subtype.val := by
obtain ⟨t, ht, ht'⟩ := exists_set_linearIndependent R (M ⧸ Submodule.span R s)
choose sec hsec using Submodule.Quotient.mk_surjective (Submodule.span R s)
have hsec' : Submodule.Quotient.mk ∘ sec = id := funext hsec
have hst : Disjoint s (sec '' t) := by
rw [Set.disjoint_iff]
rintro _ ⟨hxs, ⟨x, hxt, rfl⟩⟩
apply ht'.ne_zero ⟨x, hxt⟩
rw [Subtype.coe_mk, ← hsec x, Submodule.Quotient.mk_eq_zero]
exact Submodule.subset_span hxs
refine ⟨s ∪ sec '' t, subset_union_left, ?_, ?_⟩
· rw [Cardinal.mk_union_of_disjoint hst, Cardinal.mk_image_eq, ht,
← rank_quotient_add_rank (Submodule.span R s), add_comm, rank_span_set hs]
exact HasLeftInverse.injective ⟨Submodule.Quotient.mk, hsec⟩
· apply LinearIndependent.union_of_quotient Submodule.subset_span hs
rwa [Function.comp, linearIndependent_image (hsec'.symm ▸ injective_id).injOn.image_of_comp,
← image_comp, hsec', image_id]
/-- Given a family of `n` linearly independent vectors in a space of dimension `> n`, one may extend
the family by another vector while retaining linear independence. -/
theorem exists_linearIndependent_cons_of_lt_rank [StrongRankCondition R] {n : ℕ} {v : Fin n → M}
(hv : LinearIndependent R v) (h : n < Module.rank R M) :
∃ (x : M), LinearIndependent R (Fin.cons x v) := by
obtain ⟨t, h₁, h₂, h₃⟩ := exists_linearIndependent_of_lt_rank hv.to_subtype_range
have : range v ≠ t := by
refine fun e ↦ h.ne ?_
rw [← e, ← lift_injective.eq_iff, mk_range_eq_of_injective hv.injective] at h₂
simpa only [mk_fintype, Fintype.card_fin, lift_natCast, lift_id'] using h₂
obtain ⟨x, hx, hx'⟩ := nonempty_of_ssubset (h₁.ssubset_of_ne this)
exact ⟨x, (linearIndependent_subtype_range (Fin.cons_injective_iff.mpr ⟨hx', hv.injective⟩)).mp
(h₃.mono (Fin.range_cons x v ▸ insert_subset hx h₁))⟩
/-- Given a family of `n` linearly independent vectors in a space of dimension `> n`, one may extend
the family by another vector while retaining linear independence. -/
theorem exists_linearIndependent_snoc_of_lt_rank [StrongRankCondition R] {n : ℕ} {v : Fin n → M}
(hv : LinearIndependent R v) (h : n < Module.rank R M) :
∃ (x : M), LinearIndependent R (Fin.snoc v x) := by
simp only [Fin.snoc_eq_cons_rotate]
have ⟨x, hx⟩ := exists_linearIndependent_cons_of_lt_rank hv h
exact ⟨x, hx.comp _ (finRotate _).injective⟩
/-- Given a nonzero vector in a space of dimension `> 1`, one may find another vector linearly
independent of the first one. -/
theorem exists_linearIndependent_pair_of_one_lt_rank [StrongRankCondition R]
[NoZeroSMulDivisors R M] (h : 1 < Module.rank R M) {x : M} (hx : x ≠ 0) :
∃ y, LinearIndependent R ![x, y] := by
obtain ⟨y, hy⟩ := exists_linearIndependent_snoc_of_lt_rank (linearIndependent_unique ![x] hx) h
have : Fin.snoc ![x] y = ![x, y] := Iff.mp List.ofFn_inj rfl
rw [this] at hy
exact ⟨y, hy⟩
theorem exists_smul_not_mem_of_rank_lt {N : Submodule R M} (h : Module.rank R N < Module.rank R M) :
∃ m : M, ∀ r : R, r ≠ 0 → r • m ∉ N := by
have : Module.rank R (M ⧸ N) ≠ 0 := by
intro e
rw [← rank_quotient_add_rank N, e, zero_add] at h
exact h.ne rfl
rw [ne_eq, rank_eq_zero_iff, (Submodule.Quotient.mk_surjective N).forall] at this
push_neg at this
simp_rw [← N.mkQ_apply, ← map_smul, N.mkQ_apply, ne_eq, Submodule.Quotient.mk_eq_zero] at this
exact this
open Cardinal Basis Submodule Function Set LinearMap
theorem Submodule.rank_sup_add_rank_inf_eq (s t : Submodule R M) :
Module.rank R (s ⊔ t : Submodule R M) + Module.rank R (s ⊓ t : Submodule R M) =
Module.rank R s + Module.rank R t := by
conv_rhs => enter [2]; rw [show t = (s ⊔ t) ⊓ t by simp]
rw [← rank_quotient_add_rank ((s ⊓ t).comap s.subtype),
← rank_quotient_add_rank (t.comap (s ⊔ t).subtype),
(quotientInfEquivSupQuotient s t).rank_eq,
(equivSubtypeMap s (comap _ (s ⊓ t))).rank_eq, Submodule.map_comap_subtype,
(equivSubtypeMap (s ⊔ t) (comap _ t)).rank_eq, Submodule.map_comap_subtype,
← inf_assoc, inf_idem, add_right_comm]
theorem Submodule.rank_add_le_rank_add_rank (s t : Submodule R M) :
Module.rank R (s ⊔ t : Submodule R M) ≤ Module.rank R s + Module.rank R t := by
rw [← Submodule.rank_sup_add_rank_inf_eq]
exact self_le_add_right _ _
section Finrank
open Submodule FiniteDimensional
variable [StrongRankCondition R]
/-- Given a family of `n` linearly independent vectors in a finite-dimensional space of
dimension `> n`, one may extend the family by another vector while retaining linear independence. -/
theorem exists_linearIndependent_snoc_of_lt_finrank {n : ℕ} {v : Fin n → M}
(hv : LinearIndependent R v) (h : n < finrank R M) :
∃ (x : M), LinearIndependent R (Fin.snoc v x) :=
exists_linearIndependent_snoc_of_lt_rank hv (lt_rank_of_lt_finrank h)
/-- Given a family of `n` linearly independent vectors in a finite-dimensional space of
dimension `> n`, one may extend the family by another vector while retaining linear independence. -/
theorem exists_linearIndependent_cons_of_lt_finrank {n : ℕ} {v : Fin n → M}
(hv : LinearIndependent R v) (h : n < finrank R M) :
∃ (x : M), LinearIndependent R (Fin.cons x v) :=
exists_linearIndependent_cons_of_lt_rank hv (lt_rank_of_lt_finrank h)
/-- Given a nonzero vector in a finite-dimensional space of dimension `> 1`, one may find another
vector linearly independent of the first one. -/
theorem exists_linearIndependent_pair_of_one_lt_finrank [NoZeroSMulDivisors R M]
(h : 1 < finrank R M) {x : M} (hx : x ≠ 0) :
∃ y, LinearIndependent R ![x, y] :=
exists_linearIndependent_pair_of_one_lt_rank (one_lt_rank_of_one_lt_finrank h) hx
end Finrank
|
LinearAlgebra\Dimension\StrongRankCondition.lean | /-
Copyright (c) 2021 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison
-/
import Mathlib.LinearAlgebra.Dimension.Finrank
import Mathlib.LinearAlgebra.InvariantBasisNumber
/-!
# Lemmas about rank and finrank in rings satisfying strong rank condition.
## Main statements
For modules over rings satisfying the rank condition
* `Basis.le_span`:
the cardinality of a basis is bounded by the cardinality of any spanning set
For modules over rings satisfying the strong rank condition
* `linearIndependent_le_span`:
For any linearly independent family `v : ι → M`
and any finite spanning set `w : Set M`,
the cardinality of `ι` is bounded by the cardinality of `w`.
* `linearIndependent_le_basis`:
If `b` is a basis for a module `M`,
and `s` is a linearly independent set,
then the cardinality of `s` is bounded by the cardinality of `b`.
For modules over rings with invariant basis number
(including all commutative rings and all noetherian rings)
* `mk_eq_mk_of_basis`: the dimension theorem, any two bases of the same vector space have the same
cardinality.
-/
noncomputable section
universe u v w w'
variable {R : Type u} {M : Type v} [Ring R] [AddCommGroup M] [Module R M]
variable {ι : Type w} {ι' : Type w'}
open Cardinal Basis Submodule Function Set
attribute [local instance] nontrivial_of_invariantBasisNumber
section InvariantBasisNumber
variable [InvariantBasisNumber R]
/-- The dimension theorem: if `v` and `v'` are two bases, their index types
have the same cardinalities. -/
theorem mk_eq_mk_of_basis (v : Basis ι R M) (v' : Basis ι' R M) :
Cardinal.lift.{w'} #ι = Cardinal.lift.{w} #ι' := by
classical
haveI := nontrivial_of_invariantBasisNumber R
cases fintypeOrInfinite ι
· -- `v` is a finite basis, so by `basis_finite_of_finite_spans` so is `v'`.
-- haveI : Finite (range v) := Set.finite_range v
haveI := basis_finite_of_finite_spans _ (Set.finite_range v) v.span_eq v'
cases nonempty_fintype ι'
-- We clean up a little:
rw [Cardinal.mk_fintype, Cardinal.mk_fintype]
simp only [Cardinal.lift_natCast, Cardinal.natCast_inj]
-- Now we can use invariant basis number to show they have the same cardinality.
apply card_eq_of_linearEquiv R
exact
(Finsupp.linearEquivFunOnFinite R R ι).symm.trans v.repr.symm ≪≫ₗ v'.repr ≪≫ₗ
Finsupp.linearEquivFunOnFinite R R ι'
· -- `v` is an infinite basis,
-- so by `infinite_basis_le_maximal_linearIndependent`, `v'` is at least as big,
-- and then applying `infinite_basis_le_maximal_linearIndependent` again
-- we see they have the same cardinality.
have w₁ := infinite_basis_le_maximal_linearIndependent' v _ v'.linearIndependent v'.maximal
rcases Cardinal.lift_mk_le'.mp w₁ with ⟨f⟩
haveI : Infinite ι' := Infinite.of_injective f f.2
have w₂ := infinite_basis_le_maximal_linearIndependent' v' _ v.linearIndependent v.maximal
exact le_antisymm w₁ w₂
/-- Given two bases indexed by `ι` and `ι'` of an `R`-module, where `R` satisfies the invariant
basis number property, an equiv `ι ≃ ι'`. -/
def Basis.indexEquiv (v : Basis ι R M) (v' : Basis ι' R M) : ι ≃ ι' :=
(Cardinal.lift_mk_eq'.1 <| mk_eq_mk_of_basis v v').some
theorem mk_eq_mk_of_basis' {ι' : Type w} (v : Basis ι R M) (v' : Basis ι' R M) : #ι = #ι' :=
Cardinal.lift_inj.1 <| mk_eq_mk_of_basis v v'
end InvariantBasisNumber
section RankCondition
variable [RankCondition R]
/-- An auxiliary lemma for `Basis.le_span`.
If `R` satisfies the rank condition,
then for any finite basis `b : Basis ι R M`,
and any finite spanning set `w : Set M`,
the cardinality of `ι` is bounded by the cardinality of `w`.
-/
theorem Basis.le_span'' {ι : Type*} [Fintype ι] (b : Basis ι R M) {w : Set M} [Fintype w]
(s : span R w = ⊤) : Fintype.card ι ≤ Fintype.card w := by
-- We construct a surjective linear map `(w → R) →ₗ[R] (ι → R)`,
-- by expressing a linear combination in `w` as a linear combination in `ι`.
fapply card_le_of_surjective' R
· exact b.repr.toLinearMap.comp (Finsupp.total w M R (↑))
· apply Surjective.comp (g := b.repr.toLinearMap)
· apply LinearEquiv.surjective
rw [← LinearMap.range_eq_top, Finsupp.range_total]
simpa using s
/--
Another auxiliary lemma for `Basis.le_span`, which does not require assuming the basis is finite,
but still assumes we have a finite spanning set.
-/
theorem basis_le_span' {ι : Type*} (b : Basis ι R M) {w : Set M} [Fintype w] (s : span R w = ⊤) :
#ι ≤ Fintype.card w := by
haveI := nontrivial_of_invariantBasisNumber R
haveI := basis_finite_of_finite_spans w (toFinite _) s b
cases nonempty_fintype ι
rw [Cardinal.mk_fintype ι]
simp only [Cardinal.natCast_le]
exact Basis.le_span'' b s
-- Note that if `R` satisfies the strong rank condition,
-- this also follows from `linearIndependent_le_span` below.
/-- If `R` satisfies the rank condition,
then the cardinality of any basis is bounded by the cardinality of any spanning set.
-/
theorem Basis.le_span {J : Set M} (v : Basis ι R M) (hJ : span R J = ⊤) : #(range v) ≤ #J := by
haveI := nontrivial_of_invariantBasisNumber R
cases fintypeOrInfinite J
· rw [← Cardinal.lift_le, Cardinal.mk_range_eq_of_injective v.injective, Cardinal.mk_fintype J]
convert Cardinal.lift_le.{v}.2 (basis_le_span' v hJ)
simp
· let S : J → Set ι := fun j => ↑(v.repr j).support
let S' : J → Set M := fun j => v '' S j
have hs : range v ⊆ ⋃ j, S' j := by
intro b hb
rcases mem_range.1 hb with ⟨i, hi⟩
have : span R J ≤ comap v.repr.toLinearMap (Finsupp.supported R R (⋃ j, S j)) :=
span_le.2 fun j hj x hx => ⟨_, ⟨⟨j, hj⟩, rfl⟩, hx⟩
rw [hJ] at this
replace : v.repr (v i) ∈ Finsupp.supported R R (⋃ j, S j) := this trivial
rw [v.repr_self, Finsupp.mem_supported, Finsupp.support_single_ne_zero _ one_ne_zero] at this
· subst b
rcases mem_iUnion.1 (this (Finset.mem_singleton_self _)) with ⟨j, hj⟩
exact mem_iUnion.2 ⟨j, (mem_image _ _ _).2 ⟨i, hj, rfl⟩⟩
refine le_of_not_lt fun IJ => ?_
suffices #(⋃ j, S' j) < #(range v) by exact not_le_of_lt this ⟨Set.embeddingOfSubset _ _ hs⟩
refine lt_of_le_of_lt (le_trans Cardinal.mk_iUnion_le_sum_mk
(Cardinal.sum_le_sum _ (fun _ => ℵ₀) ?_)) ?_
· exact fun j => (Cardinal.lt_aleph0_of_finite _).le
· simpa
end RankCondition
section StrongRankCondition
variable [StrongRankCondition R]
open Submodule
-- An auxiliary lemma for `linearIndependent_le_span'`,
-- with the additional assumption that the linearly independent family is finite.
theorem linearIndependent_le_span_aux' {ι : Type*} [Fintype ι] (v : ι → M)
(i : LinearIndependent R v) (w : Set M) [Fintype w] (s : range v ≤ span R w) :
Fintype.card ι ≤ Fintype.card w := by
-- We construct an injective linear map `(ι → R) →ₗ[R] (w → R)`,
-- by thinking of `f : ι → R` as a linear combination of the finite family `v`,
-- and expressing that (using the axiom of choice) as a linear combination over `w`.
-- We can do this linearly by constructing the map on a basis.
fapply card_le_of_injective' R
· apply Finsupp.total
exact fun i => Span.repr R w ⟨v i, s (mem_range_self i)⟩
· intro f g h
apply_fun Finsupp.total w M R (↑) at h
simp only [Finsupp.total_total, Submodule.coe_mk, Span.finsupp_total_repr] at h
rw [← sub_eq_zero, ← LinearMap.map_sub] at h
exact sub_eq_zero.mp (linearIndependent_iff.mp i _ h)
/-- If `R` satisfies the strong rank condition,
then any linearly independent family `v : ι → M`
contained in the span of some finite `w : Set M`,
is itself finite.
-/
lemma LinearIndependent.finite_of_le_span_finite {ι : Type*} (v : ι → M) (i : LinearIndependent R v)
(w : Set M) [Finite w] (s : range v ≤ span R w) : Finite ι :=
letI := Fintype.ofFinite w
Fintype.finite <| fintypeOfFinsetCardLe (Fintype.card w) fun t => by
let v' := fun x : (t : Set ι) => v x
have i' : LinearIndependent R v' := i.comp _ Subtype.val_injective
have s' : range v' ≤ span R w := (range_comp_subset_range _ _).trans s
simpa using linearIndependent_le_span_aux' v' i' w s'
/-- If `R` satisfies the strong rank condition,
then for any linearly independent family `v : ι → M`
contained in the span of some finite `w : Set M`,
the cardinality of `ι` is bounded by the cardinality of `w`.
-/
theorem linearIndependent_le_span' {ι : Type*} (v : ι → M) (i : LinearIndependent R v) (w : Set M)
[Fintype w] (s : range v ≤ span R w) : #ι ≤ Fintype.card w := by
haveI : Finite ι := i.finite_of_le_span_finite v w s
letI := Fintype.ofFinite ι
rw [Cardinal.mk_fintype]
simp only [Cardinal.natCast_le]
exact linearIndependent_le_span_aux' v i w s
/-- If `R` satisfies the strong rank condition,
then for any linearly independent family `v : ι → M`
and any finite spanning set `w : Set M`,
the cardinality of `ι` is bounded by the cardinality of `w`.
-/
theorem linearIndependent_le_span {ι : Type*} (v : ι → M) (i : LinearIndependent R v) (w : Set M)
[Fintype w] (s : span R w = ⊤) : #ι ≤ Fintype.card w := by
apply linearIndependent_le_span' v i w
rw [s]
exact le_top
/-- A version of `linearIndependent_le_span` for `Finset`. -/
theorem linearIndependent_le_span_finset {ι : Type*} (v : ι → M) (i : LinearIndependent R v)
(w : Finset M) (s : span R (w : Set M) = ⊤) : #ι ≤ w.card := by
simpa only [Finset.coe_sort_coe, Fintype.card_coe] using linearIndependent_le_span v i w s
/-- An auxiliary lemma for `linearIndependent_le_basis`:
we handle the case where the basis `b` is infinite.
-/
theorem linearIndependent_le_infinite_basis {ι : Type w} (b : Basis ι R M) [Infinite ι] {κ : Type w}
(v : κ → M) (i : LinearIndependent R v) : #κ ≤ #ι := by
classical
by_contra h
rw [not_le, ← Cardinal.mk_finset_of_infinite ι] at h
let Φ := fun k : κ => (b.repr (v k)).support
obtain ⟨s, w : Infinite ↑(Φ ⁻¹' {s})⟩ := Cardinal.exists_infinite_fiber Φ h (by infer_instance)
let v' := fun k : Φ ⁻¹' {s} => v k
have i' : LinearIndependent R v' := i.comp _ Subtype.val_injective
have w' : Finite (Φ ⁻¹' {s}) := by
apply i'.finite_of_le_span_finite v' (s.image b)
rintro m ⟨⟨p, ⟨rfl⟩⟩, rfl⟩
simp only [SetLike.mem_coe, Subtype.coe_mk, Finset.coe_image]
apply Basis.mem_span_repr_support
exact w.false
/-- Over any ring `R` satisfying the strong rank condition,
if `b` is a basis for a module `M`,
and `s` is a linearly independent set,
then the cardinality of `s` is bounded by the cardinality of `b`.
-/
theorem linearIndependent_le_basis {ι : Type w} (b : Basis ι R M) {κ : Type w} (v : κ → M)
(i : LinearIndependent R v) : #κ ≤ #ι := by
classical
-- We split into cases depending on whether `ι` is infinite.
cases fintypeOrInfinite ι
· rw [Cardinal.mk_fintype ι] -- When `ι` is finite, we have `linearIndependent_le_span`,
haveI : Nontrivial R := nontrivial_of_invariantBasisNumber R
rw [Fintype.card_congr (Equiv.ofInjective b b.injective)]
exact linearIndependent_le_span v i (range b) b.span_eq
· -- and otherwise we have `linearIndependent_le_infinite_basis`.
exact linearIndependent_le_infinite_basis b v i
/-- Let `R` satisfy the strong rank condition. If `m` elements of a free rank `n` `R`-module are
linearly independent, then `m ≤ n`. -/
theorem Basis.card_le_card_of_linearIndependent_aux {R : Type*} [Ring R] [StrongRankCondition R]
(n : ℕ) {m : ℕ} (v : Fin m → Fin n → R) : LinearIndependent R v → m ≤ n := fun h => by
simpa using linearIndependent_le_basis (Pi.basisFun R (Fin n)) v h
-- When the basis is not infinite this need not be true!
/-- Over any ring `R` satisfying the strong rank condition,
if `b` is an infinite basis for a module `M`,
then every maximal linearly independent set has the same cardinality as `b`.
This proof (along with some of the lemmas above) comes from
[Les familles libres maximales d'un module ont-elles le meme cardinal?][lazarus1973]
-/
theorem maximal_linearIndependent_eq_infinite_basis {ι : Type w} (b : Basis ι R M) [Infinite ι]
{κ : Type w} (v : κ → M) (i : LinearIndependent R v) (m : i.Maximal) : #κ = #ι := by
apply le_antisymm
· exact linearIndependent_le_basis b v i
· haveI : Nontrivial R := nontrivial_of_invariantBasisNumber R
exact infinite_basis_le_maximal_linearIndependent b v i m
theorem Basis.mk_eq_rank'' {ι : Type v} (v : Basis ι R M) : #ι = Module.rank R M := by
haveI := nontrivial_of_invariantBasisNumber R
rw [Module.rank_def]
apply le_antisymm
· trans
swap
· apply le_ciSup (Cardinal.bddAbove_range.{v, v} _)
exact
⟨Set.range v, by
convert v.reindexRange.linearIndependent
ext
simp⟩
· exact (Cardinal.mk_range_eq v v.injective).ge
· apply ciSup_le'
rintro ⟨s, li⟩
apply linearIndependent_le_basis v _ li
theorem Basis.mk_range_eq_rank (v : Basis ι R M) : #(range v) = Module.rank R M :=
v.reindexRange.mk_eq_rank''
/-- If a vector space has a finite basis, then its dimension (seen as a cardinal) is equal to the
cardinality of the basis. -/
theorem rank_eq_card_basis {ι : Type w} [Fintype ι] (h : Basis ι R M) :
Module.rank R M = Fintype.card ι := by
classical
haveI := nontrivial_of_invariantBasisNumber R
rw [← h.mk_range_eq_rank, Cardinal.mk_fintype, Set.card_range_of_injective h.injective]
theorem Basis.card_le_card_of_linearIndependent {ι : Type*} [Fintype ι] (b : Basis ι R M)
{ι' : Type*} [Fintype ι'] {v : ι' → M} (hv : LinearIndependent R v) :
Fintype.card ι' ≤ Fintype.card ι := by
letI := nontrivial_of_invariantBasisNumber R
simpa [rank_eq_card_basis b, Cardinal.mk_fintype] using hv.cardinal_lift_le_rank
theorem Basis.card_le_card_of_submodule (N : Submodule R M) [Fintype ι] (b : Basis ι R M)
[Fintype ι'] (b' : Basis ι' R N) : Fintype.card ι' ≤ Fintype.card ι :=
b.card_le_card_of_linearIndependent (b'.linearIndependent.map' N.subtype N.ker_subtype)
theorem Basis.card_le_card_of_le {N O : Submodule R M} (hNO : N ≤ O) [Fintype ι] (b : Basis ι R O)
[Fintype ι'] (b' : Basis ι' R N) : Fintype.card ι' ≤ Fintype.card ι :=
b.card_le_card_of_linearIndependent
(b'.linearIndependent.map' (Submodule.inclusion hNO) (N.ker_inclusion O _))
theorem Basis.mk_eq_rank (v : Basis ι R M) :
Cardinal.lift.{v} #ι = Cardinal.lift.{w} (Module.rank R M) := by
haveI := nontrivial_of_invariantBasisNumber R
rw [← v.mk_range_eq_rank, Cardinal.mk_range_eq_of_injective v.injective]
theorem Basis.mk_eq_rank'.{m} (v : Basis ι R M) :
Cardinal.lift.{max v m} #ι = Cardinal.lift.{max w m} (Module.rank R M) :=
Cardinal.lift_umax_eq.{w, v, m}.mpr v.mk_eq_rank
theorem rank_span {v : ι → M} (hv : LinearIndependent R v) :
Module.rank R ↑(span R (range v)) = #(range v) := by
haveI := nontrivial_of_invariantBasisNumber R
rw [← Cardinal.lift_inj, ← (Basis.span hv).mk_eq_rank,
Cardinal.mk_range_eq_of_injective (@LinearIndependent.injective ι R M v _ _ _ _ hv)]
theorem rank_span_set {s : Set M} (hs : LinearIndependent R (fun x => x : s → M)) :
Module.rank R ↑(span R s) = #s := by
rw [← @setOf_mem_eq _ s, ← Subtype.range_coe_subtype]
exact rank_span hs
/-- An induction (and recursion) principle for proving results about all submodules of a fixed
finite free module `M`. A property is true for all submodules of `M` if it satisfies the following
"inductive step": the property is true for a submodule `N` if it's true for all submodules `N'`
of `N` with the property that there exists `0 ≠ x ∈ N` such that the sum `N' + Rx` is direct. -/
def Submodule.inductionOnRank [IsDomain R] [Finite ι] (b : Basis ι R M)
(P : Submodule R M → Sort*) (ih : ∀ N : Submodule R M,
(∀ N' ≤ N, ∀ x ∈ N, (∀ (c : R), ∀ y ∈ N', c • x + y = (0 : M) → c = 0) → P N') → P N)
(N : Submodule R M) : P N :=
letI := Fintype.ofFinite ι
Submodule.inductionOnRankAux b P ih (Fintype.card ι) N fun hs hli => by
simpa using b.card_le_card_of_linearIndependent hli
/-- If `S` a module-finite free `R`-algebra, then the `R`-rank of a nonzero `R`-free
ideal `I` of `S` is the same as the rank of `S`. -/
theorem Ideal.rank_eq {R S : Type*} [CommRing R] [StrongRankCondition R] [Ring S] [IsDomain S]
[Algebra R S] {n m : Type*} [Fintype n] [Fintype m] (b : Basis n R S) {I : Ideal S}
(hI : I ≠ ⊥) (c : Basis m R I) : Fintype.card m = Fintype.card n := by
obtain ⟨a, ha⟩ := Submodule.nonzero_mem_of_bot_lt (bot_lt_iff_ne_bot.mpr hI)
have : LinearIndependent R fun i => b i • a := by
have hb := b.linearIndependent
rw [Fintype.linearIndependent_iff] at hb ⊢
intro g hg
apply hb g
simp only [← smul_assoc, ← Finset.sum_smul, smul_eq_zero] at hg
exact hg.resolve_right ha
exact le_antisymm
(b.card_le_card_of_linearIndependent (c.linearIndependent.map' (Submodule.subtype I)
((LinearMap.ker_eq_bot (f := (Submodule.subtype I : I →ₗ[R] S))).mpr Subtype.coe_injective)))
(c.card_le_card_of_linearIndependent this)
open FiniteDimensional
theorem finrank_eq_nat_card_basis (h : Basis ι R M) :
finrank R M = Nat.card ι := by
rw [Nat.card, ← toNat_lift.{v}, h.mk_eq_rank, toNat_lift, finrank]
namespace FiniteDimensional
/-- If a vector space (or module) has a finite basis, then its dimension (or rank) is equal to the
cardinality of the basis. -/
theorem finrank_eq_card_basis {ι : Type w} [Fintype ι] (h : Basis ι R M) :
finrank R M = Fintype.card ι :=
finrank_eq_of_rank_eq (rank_eq_card_basis h)
/-- If a free module is of finite rank, then the cardinality of any basis is equal to its
`finrank`. -/
theorem _root_.Module.mk_finrank_eq_card_basis [Module.Finite R M]
{ι : Type w} (h : Basis ι R M) : (finrank R M : Cardinal.{w}) = #ι := by
cases @nonempty_fintype _ (Module.Finite.finite_basis h)
rw [Cardinal.mk_fintype, finrank_eq_card_basis h]
/-- If a vector space (or module) has a finite basis, then its dimension (or rank) is equal to the
cardinality of the basis. This lemma uses a `Finset` instead of indexed types. -/
theorem finrank_eq_card_finset_basis {ι : Type w} {b : Finset ι} (h : Basis b R M) :
finrank R M = Finset.card b := by rw [finrank_eq_card_basis h, Fintype.card_coe]
end FiniteDimensional
open FiniteDimensional
variable (R)
@[simp]
theorem rank_self : Module.rank R R = 1 := by
rw [← Cardinal.lift_inj, ← (Basis.singleton PUnit R).mk_eq_rank, Cardinal.mk_punit]
/-- A ring satisfying `StrongRankCondition` (such as a `DivisionRing`) is one-dimensional as a
module over itself. -/
@[simp]
theorem FiniteDimensional.finrank_self : finrank R R = 1 :=
finrank_eq_of_rank_eq (by simp)
/-- Given a basis of a ring over itself indexed by a type `ι`, then `ι` is `Unique`. -/
noncomputable def Basis.unique {ι : Type*} (b : Basis ι R R) : Unique ι := by
have A : Cardinal.mk ι = ↑(FiniteDimensional.finrank R R) :=
(Module.mk_finrank_eq_card_basis b).symm
-- Porting note: replace `algebraMap.coe_one` with `Nat.cast_one`
simp only [Cardinal.eq_one_iff_unique, FiniteDimensional.finrank_self, Nat.cast_one] at A
exact Nonempty.some ((unique_iff_subsingleton_and_nonempty _).2 A)
variable (M)
/-- The rank of a finite module is finite. -/
theorem rank_lt_aleph0 [Module.Finite R M] : Module.rank R M < ℵ₀ := by
simp only [Module.rank_def]
-- Porting note: can't use `‹_›` as that pulls the unused `N` into the context
obtain ⟨S, hS⟩ := Module.finite_def.mp ‹Module.Finite R M›
refine (ciSup_le' fun i => ?_).trans_lt (nat_lt_aleph0 S.card)
exact linearIndependent_le_span_finset _ i.prop S hS
@[deprecated (since := "2024-01-01")]
protected alias FiniteDimensional.rank_lt_aleph0 := rank_lt_aleph0
/-- If `M` is finite, `finrank M = rank M`. -/
@[simp]
theorem finrank_eq_rank [Module.Finite R M] :
↑(FiniteDimensional.finrank R M) = Module.rank R M := by
rw [FiniteDimensional.finrank, cast_toNat_of_lt_aleph0 (rank_lt_aleph0 R M)]
@[deprecated (since := "2024-01-01")]
protected alias FiniteDimensional.finrank_eq_rank := finrank_eq_rank
variable {R M}
variable {M'} [AddCommGroup M'] [Module R M']
theorem LinearMap.finrank_le_finrank_of_injective [Module.Finite R M'] {f : M →ₗ[R] M'}
(hf : Function.Injective f) : finrank R M ≤ finrank R M' :=
finrank_le_finrank_of_rank_le_rank (LinearMap.lift_rank_le_of_injective _ hf) (rank_lt_aleph0 _ _)
theorem LinearMap.finrank_range_le [Module.Finite R M] (f : M →ₗ[R] M') :
finrank R (LinearMap.range f) ≤ finrank R M :=
finrank_le_finrank_of_rank_le_rank (lift_rank_range_le f) (rank_lt_aleph0 _ _)
end StrongRankCondition
|
LinearAlgebra\DirectSum\Finsupp.lean | /-
Copyright (c) 2019 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Antoine Chambert-Loir
-/
import Mathlib.Algebra.DirectSum.Finsupp
import Mathlib.LinearAlgebra.Finsupp
import Mathlib.LinearAlgebra.DirectSum.TensorProduct
/-!
# Results on finitely supported functions.
* `TensorProduct.finsuppLeft`, the tensor product of `ι →₀ M` and `N`
is linearly equivalent to `ι →₀ M ⊗[R] N`
* `TensorProduct.finsuppScalarLeft`, the tensor product of `ι →₀ R` and `N`
is linearly equivalent to `ι →₀ N`
* `TensorProduct.finsuppRight`, the tensor product of `M` and `ι →₀ N`
is linearly equivalent to `ι →₀ M ⊗[R] N`
* `TensorProduct.finsuppScalarRight`, the tensor product of `M` and `ι →₀ R`
is linearly equivalent to `ι →₀ N`
* `TensorProduct.finsuppLeft'`, if `M` is an `S`-module,
then the tensor product of `ι →₀ M` and `N` is `S`-linearly equivalent
to `ι →₀ M ⊗[R] N`
* `finsuppTensorFinsupp`, the tensor product of `ι →₀ M` and `κ →₀ N`
is linearly equivalent to `(ι × κ) →₀ (M ⊗ N)`.
## Case of MvPolynomial
These functions apply to `MvPolynomial`, one can define
```
noncomputable def MvPolynomial.rTensor' :
MvPolynomial σ S ⊗[R] N ≃ₗ[S] (σ →₀ ℕ) →₀ (S ⊗[R] N) :=
TensorProduct.finsuppLeft'
noncomputable def MvPolynomial.rTensor :
MvPolynomial σ R ⊗[R] N ≃ₗ[R] (σ →₀ ℕ) →₀ N :=
TensorProduct.finsuppScalarLeft
```
However, to be actually usable, these definitions need lemmas to be given in companion PR.
## Case of `Polynomial`
`Polynomial` is a structure containing a `Finsupp`, so these functions
can't be applied directly to `Polynomial`.
Some linear equivs need to be added to mathlib for that.
This belongs to a companion PR.
## TODO
* generalize to `MonoidAlgebra`, `AlgHom `
* reprove `TensorProduct.finsuppLeft'` using existing heterobasic version of `TensorProduct.congr`
-/
noncomputable section
open DirectSum TensorProduct
open Set LinearMap Submodule
section TensorProduct
variable (R : Type*) [CommSemiring R]
(M : Type*) [AddCommMonoid M] [Module R M]
(N : Type*) [AddCommMonoid N] [Module R N]
namespace TensorProduct
variable (ι : Type*) [DecidableEq ι]
/-- The tensor product of `ι →₀ M` and `N` is linearly equivalent to `ι →₀ M ⊗[R] N` -/
noncomputable def finsuppLeft :
(ι →₀ M) ⊗[R] N ≃ₗ[R] ι →₀ M ⊗[R] N :=
congr (finsuppLEquivDirectSum R M ι) (.refl R N) ≪≫ₗ
directSumLeft R (fun _ ↦ M) N ≪≫ₗ (finsuppLEquivDirectSum R _ ι).symm
variable {R M N ι}
lemma finsuppLeft_apply_tmul (p : ι →₀ M) (n : N) :
finsuppLeft R M N ι (p ⊗ₜ[R] n) = p.sum fun i m ↦ Finsupp.single i (m ⊗ₜ[R] n) := by
apply p.induction_linear
· simp
· intros f g hf hg; simp [add_tmul, map_add, hf, hg, Finsupp.sum_add_index]
· simp [finsuppLeft]
@[simp]
lemma finsuppLeft_apply_tmul_apply (p : ι →₀ M) (n : N) (i : ι) :
finsuppLeft R M N ι (p ⊗ₜ[R] n) i = p i ⊗ₜ[R] n := by
rw [finsuppLeft_apply_tmul, Finsupp.sum_apply,
Finsupp.sum_eq_single i (fun _ _ ↦ Finsupp.single_eq_of_ne) (by simp), Finsupp.single_eq_same]
theorem finsuppLeft_apply (t : (ι →₀ M) ⊗[R] N) (i : ι) :
finsuppLeft R M N ι t i = rTensor N (Finsupp.lapply i) t := by
induction t with
| zero => simp
| tmul f n => simp only [finsuppLeft_apply_tmul_apply, rTensor_tmul, Finsupp.lapply_apply]
| add x y hx hy => simp [map_add, hx, hy]
@[simp]
lemma finsuppLeft_symm_apply_single (i : ι) (m : M) (n : N) :
(finsuppLeft R M N ι).symm (Finsupp.single i (m ⊗ₜ[R] n)) =
Finsupp.single i m ⊗ₜ[R] n := by
simp [finsuppLeft, Finsupp.lsum]
variable (R M N ι)
/-- The tensor product of `M` and `ι →₀ N` is linearly equivalent to `ι →₀ M ⊗[R] N` -/
noncomputable def finsuppRight :
M ⊗[R] (ι →₀ N) ≃ₗ[R] ι →₀ M ⊗[R] N :=
congr (.refl R M) (finsuppLEquivDirectSum R N ι) ≪≫ₗ
directSumRight R M (fun _ : ι ↦ N) ≪≫ₗ (finsuppLEquivDirectSum R _ ι).symm
variable {R M N ι}
lemma finsuppRight_apply_tmul (m : M) (p : ι →₀ N) :
finsuppRight R M N ι (m ⊗ₜ[R] p) = p.sum fun i n ↦ Finsupp.single i (m ⊗ₜ[R] n) := by
apply p.induction_linear
· simp
· intros f g hf hg; simp [tmul_add, map_add, hf, hg, Finsupp.sum_add_index]
· simp [finsuppRight]
@[simp]
lemma finsuppRight_apply_tmul_apply (m : M) (p : ι →₀ N) (i : ι) :
finsuppRight R M N ι (m ⊗ₜ[R] p) i = m ⊗ₜ[R] p i := by
rw [finsuppRight_apply_tmul, Finsupp.sum_apply,
Finsupp.sum_eq_single i (fun _ _ ↦ Finsupp.single_eq_of_ne) (by simp), Finsupp.single_eq_same]
theorem finsuppRight_apply (t : M ⊗[R] (ι →₀ N)) (i : ι) :
finsuppRight R M N ι t i = lTensor M (Finsupp.lapply i) t := by
induction t with
| zero => simp
| tmul m f => simp [finsuppRight_apply_tmul_apply]
| add x y hx hy => simp [map_add, hx, hy]
@[simp]
lemma finsuppRight_symm_apply_single (i : ι) (m : M) (n : N) :
(finsuppRight R M N ι).symm (Finsupp.single i (m ⊗ₜ[R] n)) =
m ⊗ₜ[R] Finsupp.single i n := by
simp [finsuppRight, Finsupp.lsum]
variable {S : Type*} [CommSemiring S] [Algebra R S]
[Module S M] [IsScalarTower R S M]
lemma finsuppLeft_smul' (s : S) (t : (ι →₀ M) ⊗[R] N) :
finsuppLeft R M N ι (s • t) = s • finsuppLeft R M N ι t := by
induction t with
| zero => simp
| add x y hx hy => simp [hx, hy]
| tmul p n => ext; simp [smul_tmul', finsuppLeft_apply_tmul_apply]
variable (R M N ι S)
/-- When `M` is also an `S`-module, then `TensorProduct.finsuppLeft R M N``
is an `S`-linear equiv -/
noncomputable def finsuppLeft' :
(ι →₀ M) ⊗[R] N ≃ₗ[S] ι →₀ M ⊗[R] N where
__ := finsuppLeft R M N ι
map_smul' := finsuppLeft_smul'
variable {R M N ι S}
lemma finsuppLeft'_apply (x : (ι →₀ M) ⊗[R] N) :
finsuppLeft' R M N ι S x = finsuppLeft R M N ι x := rfl
/- -- TODO : reprove using the existing heterobasic lemmas
noncomputable example :
(ι →₀ M) ⊗[R] N ≃ₗ[S] ι →₀ (M ⊗[R] N) := by
have f : (⨁ (i₁ : ι), M) ⊗[R] N ≃ₗ[S] ⨁ (i : ι), M ⊗[R] N := sorry
exact (AlgebraTensorModule.congr
(finsuppLEquivDirectSum S M ι) (.refl R N)).trans
(f.trans (finsuppLEquivDirectSum S (M ⊗[R] N) ι).symm) -/
variable (R M N ι)
/-- The tensor product of `ι →₀ R` and `N` is linearly equivalent to `ι →₀ N` -/
noncomputable def finsuppScalarLeft :
(ι →₀ R) ⊗[R] N ≃ₗ[R] ι →₀ N :=
finsuppLeft R R N ι ≪≫ₗ (Finsupp.mapRange.linearEquiv (TensorProduct.lid R N))
variable {R M N ι}
@[simp]
lemma finsuppScalarLeft_apply_tmul_apply (p : ι →₀ R) (n : N) (i : ι) :
finsuppScalarLeft R N ι (p ⊗ₜ[R] n) i = p i • n := by
simp [finsuppScalarLeft]
lemma finsuppScalarLeft_apply_tmul (p : ι →₀ R) (n : N) :
finsuppScalarLeft R N ι (p ⊗ₜ[R] n) = p.sum fun i m ↦ Finsupp.single i (m • n) := by
ext i
rw [finsuppScalarLeft_apply_tmul_apply, Finsupp.sum_apply,
Finsupp.sum_eq_single i (fun _ _ ↦ Finsupp.single_eq_of_ne) (by simp), Finsupp.single_eq_same]
lemma finsuppScalarLeft_apply (pn : (ι →₀ R) ⊗[R] N) (i : ι) :
finsuppScalarLeft R N ι pn i = TensorProduct.lid R N ((Finsupp.lapply i).rTensor N pn) := by
simp [finsuppScalarLeft, finsuppLeft_apply]
@[simp]
lemma finsuppScalarLeft_symm_apply_single (i : ι) (n : N) :
(finsuppScalarLeft R N ι).symm (Finsupp.single i n) =
(Finsupp.single i 1) ⊗ₜ[R] n := by
simp [finsuppScalarLeft, finsuppLeft_symm_apply_single]
variable (R M N ι)
/-- The tensor product of `M` and `ι →₀ R` is linearly equivalent to `ι →₀ N` -/
noncomputable def finsuppScalarRight :
M ⊗[R] (ι →₀ R) ≃ₗ[R] ι →₀ M :=
finsuppRight R M R ι ≪≫ₗ Finsupp.mapRange.linearEquiv (TensorProduct.rid R M)
variable {R M N ι}
@[simp]
lemma finsuppScalarRight_apply_tmul_apply (m : M) (p : ι →₀ R) (i : ι) :
finsuppScalarRight R M ι (m ⊗ₜ[R] p) i = p i • m := by
simp [finsuppScalarRight]
lemma finsuppScalarRight_apply_tmul (m : M) (p : ι →₀ R) :
finsuppScalarRight R M ι (m ⊗ₜ[R] p) = p.sum fun i n ↦ Finsupp.single i (n • m) := by
ext i
rw [finsuppScalarRight_apply_tmul_apply, Finsupp.sum_apply,
Finsupp.sum_eq_single i (fun _ _ ↦ Finsupp.single_eq_of_ne) (by simp), Finsupp.single_eq_same]
lemma finsuppScalarRight_apply (t : M ⊗[R] (ι →₀ R)) (i : ι) :
finsuppScalarRight R M ι t i = TensorProduct.rid R M ((Finsupp.lapply i).lTensor M t) := by
simp [finsuppScalarRight, finsuppRight_apply]
@[simp]
lemma finsuppScalarRight_symm_apply_single (i : ι) (m : M) :
(finsuppScalarRight R M ι).symm (Finsupp.single i m) =
m ⊗ₜ[R] (Finsupp.single i 1) := by
simp [finsuppScalarRight, finsuppRight_symm_apply_single]
end TensorProduct
end TensorProduct
variable (R S M N ι κ : Type*)
[CommSemiring R] [AddCommMonoid M] [Module R M] [AddCommMonoid N] [Module R N]
[Semiring S] [Algebra R S] [Module S M] [IsScalarTower R S M]
open scoped Classical in
/-- The tensor product of `ι →₀ M` and `κ →₀ N` is linearly equivalent to `(ι × κ) →₀ (M ⊗ N)`. -/
def finsuppTensorFinsupp : (ι →₀ M) ⊗[R] (κ →₀ N) ≃ₗ[S] ι × κ →₀ M ⊗[R] N :=
TensorProduct.AlgebraTensorModule.congr
(finsuppLEquivDirectSum S M ι) (finsuppLEquivDirectSum R N κ) ≪≫ₗ
((TensorProduct.directSum R S (fun _ : ι => M) fun _ : κ => N) ≪≫ₗ
(finsuppLEquivDirectSum S (M ⊗[R] N) (ι × κ)).symm)
@[simp]
theorem finsuppTensorFinsupp_single (i : ι) (m : M) (k : κ) (n : N) :
finsuppTensorFinsupp R S M N ι κ (Finsupp.single i m ⊗ₜ Finsupp.single k n) =
Finsupp.single (i, k) (m ⊗ₜ n) := by
simp [finsuppTensorFinsupp]
@[simp]
theorem finsuppTensorFinsupp_apply (f : ι →₀ M) (g : κ →₀ N) (i : ι) (k : κ) :
finsuppTensorFinsupp R S M N ι κ (f ⊗ₜ g) (i, k) = f i ⊗ₜ g k := by
apply Finsupp.induction_linear f
· simp
· intro f₁ f₂ hf₁ hf₂
simp [add_tmul, hf₁, hf₂]
intro i' m
apply Finsupp.induction_linear g
· simp
· intro g₁ g₂ hg₁ hg₂
simp [tmul_add, hg₁, hg₂]
intro k' n
classical
simp_rw [finsuppTensorFinsupp_single, Finsupp.single_apply, Prod.mk.inj_iff, ite_and]
split_ifs <;> simp
@[simp]
theorem finsuppTensorFinsupp_symm_single (i : ι × κ) (m : M) (n : N) :
(finsuppTensorFinsupp R S M N ι κ).symm (Finsupp.single i (m ⊗ₜ n)) =
Finsupp.single i.1 m ⊗ₜ Finsupp.single i.2 n :=
Prod.casesOn i fun _ _ =>
(LinearEquiv.symm_apply_eq _).2 (finsuppTensorFinsupp_single _ _ _ _ _ _ _ _ _ _).symm
/-- A variant of `finsuppTensorFinsupp` where the first module is the ground ring. -/
def finsuppTensorFinsuppLid : (ι →₀ R) ⊗[R] (κ →₀ N) ≃ₗ[R] ι × κ →₀ N :=
finsuppTensorFinsupp R R R N ι κ ≪≫ₗ Finsupp.lcongr (Equiv.refl _) (TensorProduct.lid R N)
@[simp]
theorem finsuppTensorFinsuppLid_apply_apply (f : ι →₀ R) (g : κ →₀ N) (a : ι) (b : κ) :
finsuppTensorFinsuppLid R N ι κ (f ⊗ₜ[R] g) (a, b) = f a • g b := by
simp [finsuppTensorFinsuppLid]
@[simp]
theorem finsuppTensorFinsuppLid_single_tmul_single (a : ι) (b : κ) (r : R) (n : N) :
finsuppTensorFinsuppLid R N ι κ (Finsupp.single a r ⊗ₜ[R] Finsupp.single b n) =
Finsupp.single (a, b) (r • n) := by
simp [finsuppTensorFinsuppLid]
@[simp]
theorem finsuppTensorFinsuppLid_symm_single_smul (i : ι × κ) (r : R) (n : N) :
(finsuppTensorFinsuppLid R N ι κ).symm (Finsupp.single i (r • n)) =
Finsupp.single i.1 r ⊗ₜ Finsupp.single i.2 n :=
Prod.casesOn i fun _ _ =>
(LinearEquiv.symm_apply_eq _).2 (finsuppTensorFinsuppLid_single_tmul_single ..).symm
/-- A variant of `finsuppTensorFinsupp` where the second module is the ground ring. -/
def finsuppTensorFinsuppRid : (ι →₀ M) ⊗[R] (κ →₀ R) ≃ₗ[R] ι × κ →₀ M :=
finsuppTensorFinsupp R R M R ι κ ≪≫ₗ Finsupp.lcongr (Equiv.refl _) (TensorProduct.rid R M)
@[simp]
theorem finsuppTensorFinsuppRid_apply_apply (f : ι →₀ M) (g : κ →₀ R) (a : ι) (b : κ) :
finsuppTensorFinsuppRid R M ι κ (f ⊗ₜ[R] g) (a, b) = g b • f a := by
simp [finsuppTensorFinsuppRid]
@[simp]
theorem finsuppTensorFinsuppRid_single_tmul_single (a : ι) (b : κ) (m : M) (r : R) :
finsuppTensorFinsuppRid R M ι κ (Finsupp.single a m ⊗ₜ[R] Finsupp.single b r) =
Finsupp.single (a, b) (r • m) := by
simp [finsuppTensorFinsuppRid]
@[simp]
theorem finsuppTensorFinsuppRid_symm_single_smul (i : ι × κ) (m : M) (r : R) :
(finsuppTensorFinsuppRid R M ι κ).symm (Finsupp.single i (r • m)) =
Finsupp.single i.1 m ⊗ₜ Finsupp.single i.2 r :=
Prod.casesOn i fun _ _ =>
(LinearEquiv.symm_apply_eq _).2 (finsuppTensorFinsuppRid_single_tmul_single ..).symm
/-- A variant of `finsuppTensorFinsupp` where both modules are the ground ring. -/
def finsuppTensorFinsupp' : (ι →₀ R) ⊗[R] (κ →₀ R) ≃ₗ[R] ι × κ →₀ R :=
finsuppTensorFinsuppLid R R ι κ
@[simp]
theorem finsuppTensorFinsupp'_apply_apply (f : ι →₀ R) (g : κ →₀ R) (a : ι) (b : κ) :
finsuppTensorFinsupp' R ι κ (f ⊗ₜ[R] g) (a, b) = f a * g b :=
finsuppTensorFinsuppLid_apply_apply R R ι κ f g a b
@[simp]
theorem finsuppTensorFinsupp'_single_tmul_single (a : ι) (b : κ) (r₁ r₂ : R) :
finsuppTensorFinsupp' R ι κ (Finsupp.single a r₁ ⊗ₜ[R] Finsupp.single b r₂) =
Finsupp.single (a, b) (r₁ * r₂) :=
finsuppTensorFinsuppLid_single_tmul_single R R ι κ a b r₁ r₂
theorem finsuppTensorFinsupp'_symm_single_mul (i : ι × κ) (r₁ r₂ : R) :
(finsuppTensorFinsupp' R ι κ).symm (Finsupp.single i (r₁ * r₂)) =
Finsupp.single i.1 r₁ ⊗ₜ Finsupp.single i.2 r₂ :=
finsuppTensorFinsuppLid_symm_single_smul R R ι κ i r₁ r₂
theorem finsuppTensorFinsupp'_symm_single_eq_single_one_tmul (i : ι × κ) (r : R) :
(finsuppTensorFinsupp' R ι κ).symm (Finsupp.single i r) =
Finsupp.single i.1 1 ⊗ₜ Finsupp.single i.2 r := by
nth_rw 1 [← one_mul r]
exact finsuppTensorFinsupp'_symm_single_mul R ι κ i _ _
theorem finsuppTensorFinsupp'_symm_single_eq_tmul_single_one (i : ι × κ) (r : R) :
(finsuppTensorFinsupp' R ι κ).symm (Finsupp.single i r) =
Finsupp.single i.1 r ⊗ₜ Finsupp.single i.2 1 := by
nth_rw 1 [← mul_one r]
exact finsuppTensorFinsupp'_symm_single_mul R ι κ i _ _
theorem finsuppTensorFinsuppLid_self :
finsuppTensorFinsuppLid R R ι κ = finsuppTensorFinsupp' R ι κ := rfl
theorem finsuppTensorFinsuppRid_self :
finsuppTensorFinsuppRid R R ι κ = finsuppTensorFinsupp' R ι κ := by
rw [finsuppTensorFinsupp', finsuppTensorFinsuppLid, finsuppTensorFinsuppRid,
TensorProduct.lid_eq_rid]
|
LinearAlgebra\DirectSum\TensorProduct.lean | /-
Copyright (c) 2018 Kenny Lau. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kenny Lau, Mario Carneiro, Eric Wieser
-/
import Mathlib.LinearAlgebra.TensorProduct.Tower
import Mathlib.Algebra.DirectSum.Module
/-!
# Tensor products of direct sums
This file shows that taking `TensorProduct`s commutes with taking `DirectSum`s in both arguments.
## Main results
* `TensorProduct.directSum`
* `TensorProduct.directSumLeft`
* `TensorProduct.directSumRight`
-/
suppress_compilation
universe u v₁ v₂ w₁ w₁' w₂ w₂'
section Ring
namespace TensorProduct
open TensorProduct
open DirectSum
open LinearMap
attribute [local ext] TensorProduct.ext
variable (R : Type u) [CommSemiring R] (S) [Semiring S] [Algebra R S]
variable {ι₁ : Type v₁} {ι₂ : Type v₂}
variable [DecidableEq ι₁] [DecidableEq ι₂]
variable (M₁ : ι₁ → Type w₁) (M₁' : Type w₁') (M₂ : ι₂ → Type w₂) (M₂' : Type w₂')
variable [∀ i₁, AddCommMonoid (M₁ i₁)] [AddCommMonoid M₁']
variable [∀ i₂, AddCommMonoid (M₂ i₂)] [AddCommMonoid M₂']
variable [∀ i₁, Module R (M₁ i₁)] [Module R M₁'] [∀ i₂, Module R (M₂ i₂)] [Module R M₂']
variable [∀ i₁, Module S (M₁ i₁)] [∀ i₁, IsScalarTower R S (M₁ i₁)]
/-- The linear equivalence `(⨁ i₁, M₁ i₁) ⊗ (⨁ i₂, M₂ i₂) ≃ (⨁ i₁, ⨁ i₂, M₁ i₁ ⊗ M₂ i₂)`, i.e.
"tensor product distributes over direct sum". -/
protected def directSum :
((⨁ i₁, M₁ i₁) ⊗[R] ⨁ i₂, M₂ i₂) ≃ₗ[S] ⨁ i : ι₁ × ι₂, M₁ i.1 ⊗[R] M₂ i.2 := by
-- Porting note: entirely rewritten to allow unification to happen one step at a time
refine LinearEquiv.ofLinear (R := S) (R₂ := S) ?toFun ?invFun ?left ?right
· refine AlgebraTensorModule.lift ?_
refine DirectSum.toModule S _ _ fun i₁ => ?_
refine LinearMap.flip ?_
refine DirectSum.toModule R _ _ fun i₂ => LinearMap.flip <| ?_
refine AlgebraTensorModule.curry ?_
exact DirectSum.lof S (ι₁ × ι₂) (fun i => M₁ i.1 ⊗[R] M₂ i.2) (i₁, i₂)
· refine DirectSum.toModule S _ _ fun i => ?_
exact AlgebraTensorModule.map (DirectSum.lof S _ M₁ i.1) (DirectSum.lof R _ M₂ i.2)
· refine DirectSum.linearMap_ext S fun ⟨i₁, i₂⟩ => ?_
refine TensorProduct.AlgebraTensorModule.ext fun m₁ m₂ => ?_
-- Porting note: seems much nicer than the `repeat` lean 3 proof.
simp only [coe_comp, Function.comp_apply, toModule_lof, AlgebraTensorModule.map_tmul,
AlgebraTensorModule.lift_apply, lift.tmul, coe_restrictScalars, flip_apply,
AlgebraTensorModule.curry_apply, curry_apply, id_comp]
· -- `(_)` prevents typeclass search timing out on problems that can be solved immediately by
-- unification
apply TensorProduct.AlgebraTensorModule.curry_injective
refine DirectSum.linearMap_ext _ fun i₁ => ?_
refine LinearMap.ext fun x₁ => ?_
refine DirectSum.linearMap_ext _ fun i₂ => ?_
refine LinearMap.ext fun x₂ => ?_
-- Porting note: seems much nicer than the `repeat` lean 3 proof.
simp only [coe_comp, Function.comp_apply, AlgebraTensorModule.curry_apply, curry_apply,
coe_restrictScalars, AlgebraTensorModule.lift_apply, lift.tmul, toModule_lof, flip_apply,
AlgebraTensorModule.map_tmul, id_coe, id_eq]
/- was:
refine'
LinearEquiv.ofLinear
(lift <|
DirectSum.toModule R _ _ fun i₁ => LinearMap.flip <| DirectSum.toModule R _ _ fun i₂ =>
LinearMap.flip <| curry <|
DirectSum.lof R (ι₁ × ι₂) (fun i => M₁ i.1 ⊗[R] M₂ i.2) (i₁, i₂))
(DirectSum.toModule R _ _ fun i => map (DirectSum.lof R _ _ _) (DirectSum.lof R _ _ _)) _
_ <;>
[ext ⟨i₁, i₂⟩ x₁ x₂ : 4, ext i₁ i₂ x₁ x₂ : 5]
repeat'
first
|rw [compr₂_apply]|rw [comp_apply]|rw [id_apply]|rw [mk_apply]|rw [DirectSum.toModule_lof]
|rw [map_tmul]|rw [lift.tmul]|rw [flip_apply]|rw [curry_apply]
-/
/- alternative with explicit types:
refine'
LinearEquiv.ofLinear
(lift <|
DirectSum.toModule
(R := R) (M := M₁) (N := (⨁ i₂, M₂ i₂) →ₗ[R] ⨁ i : ι₁ × ι₂, M₁ i.1 ⊗[R] M₂ i.2)
(φ := fun i₁ => LinearMap.flip <|
DirectSum.toModule (R := R) (M := M₂) (N := ⨁ i : ι₁ × ι₂, M₁ i.1 ⊗[R] M₂ i.2)
(φ := fun i₂ => LinearMap.flip <| curry <|
DirectSum.lof R (ι₁ × ι₂) (fun i => M₁ i.1 ⊗[R] M₂ i.2) (i₁, i₂))))
(DirectSum.toModule
(R := R)
(M := fun i : ι₁ × ι₂ => M₁ i.1 ⊗[R] M₂ i.2)
(N := (⨁ i₁, M₁ i₁) ⊗[R] ⨁ i₂, M₂ i₂)
(φ := fun i : ι₁ × ι₂ => map (DirectSum.lof R _ M₁ i.1) (DirectSum.lof R _ M₂ i.2))) _
_ <;>
[ext ⟨i₁, i₂⟩ x₁ x₂ : 4, ext i₁ i₂ x₁ x₂ : 5]
repeat'
first
|rw [compr₂_apply]|rw [comp_apply]|rw [id_apply]|rw [mk_apply]|rw [DirectSum.toModule_lof]
|rw [map_tmul]|rw [lift.tmul]|rw [flip_apply]|rw [curry_apply]
-/
/-- Tensor products distribute over a direct sum on the left . -/
def directSumLeft : (⨁ i₁, M₁ i₁) ⊗[R] M₂' ≃ₗ[R] ⨁ i, M₁ i ⊗[R] M₂' :=
LinearEquiv.ofLinear
(lift <|
DirectSum.toModule R _ _ fun i =>
(mk R _ _).compr₂ <| DirectSum.lof R ι₁ (fun i => M₁ i ⊗[R] M₂') _)
(DirectSum.toModule R _ _ fun i => rTensor _ (DirectSum.lof R ι₁ _ _))
(DirectSum.linearMap_ext R fun i =>
TensorProduct.ext <|
LinearMap.ext₂ fun m₁ m₂ => by
dsimp only [comp_apply, compr₂_apply, id_apply, mk_apply]
simp_rw [DirectSum.toModule_lof, rTensor_tmul, lift.tmul, DirectSum.toModule_lof,
compr₂_apply, mk_apply])
(TensorProduct.ext <|
DirectSum.linearMap_ext R fun i =>
LinearMap.ext₂ fun m₁ m₂ => by
dsimp only [comp_apply, compr₂_apply, id_apply, mk_apply]
simp_rw [lift.tmul, DirectSum.toModule_lof, compr₂_apply,
mk_apply, DirectSum.toModule_lof, rTensor_tmul])
/-- Tensor products distribute over a direct sum on the right. -/
def directSumRight : (M₁' ⊗[R] ⨁ i, M₂ i) ≃ₗ[R] ⨁ i, M₁' ⊗[R] M₂ i :=
TensorProduct.comm R _ _ ≪≫ₗ directSumLeft R M₂ M₁' ≪≫ₗ
DFinsupp.mapRange.linearEquiv fun _ => TensorProduct.comm R _ _
variable {M₁ M₁' M₂ M₂'}
@[simp]
theorem directSum_lof_tmul_lof (i₁ : ι₁) (m₁ : M₁ i₁) (i₂ : ι₂) (m₂ : M₂ i₂) :
TensorProduct.directSum R S M₁ M₂ (DirectSum.lof S ι₁ M₁ i₁ m₁ ⊗ₜ DirectSum.lof R ι₂ M₂ i₂ m₂) =
DirectSum.lof S (ι₁ × ι₂) (fun i => M₁ i.1 ⊗[R] M₂ i.2) (i₁, i₂) (m₁ ⊗ₜ m₂) := by
simp [TensorProduct.directSum]
@[simp]
theorem directSum_symm_lof_tmul (i₁ : ι₁) (m₁ : M₁ i₁) (i₂ : ι₂) (m₂ : M₂ i₂) :
(TensorProduct.directSum R S M₁ M₂).symm
(DirectSum.lof S (ι₁ × ι₂) (fun i => M₁ i.1 ⊗[R] M₂ i.2) (i₁, i₂) (m₁ ⊗ₜ m₂)) =
(DirectSum.lof S ι₁ M₁ i₁ m₁ ⊗ₜ DirectSum.lof R ι₂ M₂ i₂ m₂) := by
rw [LinearEquiv.symm_apply_eq, directSum_lof_tmul_lof]
@[simp]
theorem directSumLeft_tmul_lof (i : ι₁) (x : M₁ i) (y : M₂') :
directSumLeft R M₁ M₂' (DirectSum.lof R _ _ i x ⊗ₜ[R] y) =
DirectSum.lof R _ _ i (x ⊗ₜ[R] y) := by
dsimp only [directSumLeft, LinearEquiv.ofLinear_apply, lift.tmul]
rw [DirectSum.toModule_lof R i]
rfl
@[simp]
theorem directSumLeft_symm_lof_tmul (i : ι₁) (x : M₁ i) (y : M₂') :
(directSumLeft R M₁ M₂').symm (DirectSum.lof R _ _ i (x ⊗ₜ[R] y)) =
DirectSum.lof R _ _ i x ⊗ₜ[R] y := by
rw [LinearEquiv.symm_apply_eq, directSumLeft_tmul_lof]
@[simp]
theorem directSumRight_tmul_lof (x : M₁') (i : ι₂) (y : M₂ i) :
directSumRight R M₁' M₂ (x ⊗ₜ[R] DirectSum.lof R _ _ i y) =
DirectSum.lof R _ _ i (x ⊗ₜ[R] y) := by
dsimp only [directSumRight, LinearEquiv.trans_apply, TensorProduct.comm_tmul]
rw [directSumLeft_tmul_lof]
exact DFinsupp.mapRange_single (hf := fun _ => rfl)
@[simp]
theorem directSumRight_symm_lof_tmul (x : M₁') (i : ι₂) (y : M₂ i) :
(directSumRight R M₁' M₂).symm (DirectSum.lof R _ _ i (x ⊗ₜ[R] y)) =
x ⊗ₜ[R] DirectSum.lof R _ _ i y := by
rw [LinearEquiv.symm_apply_eq, directSumRight_tmul_lof]
end TensorProduct
end Ring
|
LinearAlgebra\Eigenspace\Basic.lean | /-
Copyright (c) 2020 Alexander Bentkamp. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Alexander Bentkamp
-/
import Mathlib.Algebra.Algebra.Spectrum
import Mathlib.Algebra.Module.LinearMap.Basic
import Mathlib.LinearAlgebra.GeneralLinearGroup
import Mathlib.LinearAlgebra.FiniteDimensional
import Mathlib.RingTheory.Nilpotent.Basic
/-!
# Eigenvectors and eigenvalues
This file defines eigenspaces, eigenvalues, and eigenvalues, as well as their generalized
counterparts. We follow Axler's approach [axler2015] because it allows us to derive many properties
without choosing a basis and without using matrices.
An eigenspace of a linear map `f` for a scalar `μ` is the kernel of the map `(f - μ • id)`. The
nonzero elements of an eigenspace are eigenvectors `x`. They have the property `f x = μ • x`. If
there are eigenvectors for a scalar `μ`, the scalar `μ` is called an eigenvalue.
There is no consensus in the literature whether `0` is an eigenvector. Our definition of
`HasEigenvector` permits only nonzero vectors. For an eigenvector `x` that may also be `0`, we
write `x ∈ f.eigenspace μ`.
A generalized eigenspace of a linear map `f` for a natural number `k` and a scalar `μ` is the kernel
of the map `(f - μ • id) ^ k`. The nonzero elements of a generalized eigenspace are generalized
eigenvectors `x`. If there are generalized eigenvectors for a natural number `k` and a scalar `μ`,
the scalar `μ` is called a generalized eigenvalue.
The fact that the eigenvalues are the roots of the minimal polynomial is proved in
`LinearAlgebra.Eigenspace.Minpoly`.
The existence of eigenvalues over an algebraically closed field
(and the fact that the generalized eigenspaces then span) is deferred to
`LinearAlgebra.Eigenspace.IsAlgClosed`.
## References
* [Sheldon Axler, *Linear Algebra Done Right*][axler2015]
* https://en.wikipedia.org/wiki/Eigenvalues_and_eigenvectors
## Tags
eigenspace, eigenvector, eigenvalue, eigen
-/
universe u v w
namespace Module
namespace End
open FiniteDimensional Set
variable {K R : Type v} {V M : Type w} [CommRing R] [AddCommGroup M] [Module R M] [Field K]
[AddCommGroup V] [Module K V]
/-- The submodule `eigenspace f μ` for a linear map `f` and a scalar `μ` consists of all vectors `x`
such that `f x = μ • x`. (Def 5.36 of [axler2015])-/
def eigenspace (f : End R M) (μ : R) : Submodule R M :=
LinearMap.ker (f - algebraMap R (End R M) μ)
@[simp]
theorem eigenspace_zero (f : End R M) : f.eigenspace 0 = LinearMap.ker f := by simp [eigenspace]
/-- A nonzero element of an eigenspace is an eigenvector. (Def 5.7 of [axler2015]) -/
def HasEigenvector (f : End R M) (μ : R) (x : M) : Prop :=
x ∈ eigenspace f μ ∧ x ≠ 0
/-- A scalar `μ` is an eigenvalue for a linear map `f` if there are nonzero vectors `x`
such that `f x = μ • x`. (Def 5.5 of [axler2015]) -/
def HasEigenvalue (f : End R M) (a : R) : Prop :=
eigenspace f a ≠ ⊥
/-- The eigenvalues of the endomorphism `f`, as a subtype of `R`. -/
def Eigenvalues (f : End R M) : Type _ :=
{ μ : R // f.HasEigenvalue μ }
@[coe]
def Eigenvalues.val (f : Module.End R M) : Eigenvalues f → R := Subtype.val
instance Eigenvalues.instCoeOut {f : Module.End R M} : CoeOut (Eigenvalues f) R where
coe := Eigenvalues.val f
instance Eigenvalues.instDecidableEq [DecidableEq R] (f : Module.End R M) :
DecidableEq (Eigenvalues f) :=
inferInstanceAs (DecidableEq (Subtype (fun x : R => HasEigenvalue f x)))
theorem hasEigenvalue_of_hasEigenvector {f : End R M} {μ : R} {x : M} (h : HasEigenvector f μ x) :
HasEigenvalue f μ := by
rw [HasEigenvalue, Submodule.ne_bot_iff]
use x; exact h
theorem mem_eigenspace_iff {f : End R M} {μ : R} {x : M} : x ∈ eigenspace f μ ↔ f x = μ • x := by
rw [eigenspace, LinearMap.mem_ker, LinearMap.sub_apply, algebraMap_end_apply, sub_eq_zero]
theorem HasEigenvector.apply_eq_smul {f : End R M} {μ : R} {x : M} (hx : f.HasEigenvector μ x) :
f x = μ • x :=
mem_eigenspace_iff.mp hx.1
theorem HasEigenvector.pow_apply {f : End R M} {μ : R} {v : M} (hv : f.HasEigenvector μ v) (n : ℕ) :
(f ^ n) v = μ ^ n • v := by
induction n <;> simp [*, pow_succ f, hv.apply_eq_smul, smul_smul, pow_succ' μ]
theorem HasEigenvalue.exists_hasEigenvector {f : End R M} {μ : R} (hμ : f.HasEigenvalue μ) :
∃ v, f.HasEigenvector μ v :=
Submodule.exists_mem_ne_zero_of_ne_bot hμ
lemma HasEigenvalue.pow {f : End R M} {μ : R} (h : f.HasEigenvalue μ) (n : ℕ) :
(f ^ n).HasEigenvalue (μ ^ n) := by
rw [HasEigenvalue, Submodule.ne_bot_iff]
obtain ⟨m : M, hm⟩ := h.exists_hasEigenvector
exact ⟨m, by simpa [mem_eigenspace_iff] using hm.pow_apply n, hm.2⟩
/-- A nilpotent endomorphism has nilpotent eigenvalues.
See also `LinearMap.isNilpotent_trace_of_isNilpotent`. -/
lemma HasEigenvalue.isNilpotent_of_isNilpotent [NoZeroSMulDivisors R M] {f : End R M}
(hfn : IsNilpotent f) {μ : R} (hf : f.HasEigenvalue μ) :
IsNilpotent μ := by
obtain ⟨m : M, hm⟩ := hf.exists_hasEigenvector
obtain ⟨n : ℕ, hn : f ^ n = 0⟩ := hfn
exact ⟨n, by simpa [hn, hm.2, eq_comm (a := (0 : M))] using hm.pow_apply n⟩
theorem HasEigenvalue.mem_spectrum {f : End R M} {μ : R} (hμ : HasEigenvalue f μ) :
μ ∈ spectrum R f := by
refine spectrum.mem_iff.mpr fun h_unit => ?_
set f' := LinearMap.GeneralLinearGroup.toLinearEquiv h_unit.unit
rcases hμ.exists_hasEigenvector with ⟨v, hv⟩
refine hv.2 ((LinearMap.ker_eq_bot'.mp f'.ker) v (?_ : μ • v - f v = 0))
rw [hv.apply_eq_smul, sub_self]
theorem hasEigenvalue_iff_mem_spectrum [FiniteDimensional K V] {f : End K V} {μ : K} :
f.HasEigenvalue μ ↔ μ ∈ spectrum K f := by
rw [spectrum.mem_iff, IsUnit.sub_iff, LinearMap.isUnit_iff_ker_eq_bot, HasEigenvalue, eigenspace]
alias ⟨_, HasEigenvalue.of_mem_spectrum⟩ := hasEigenvalue_iff_mem_spectrum
theorem eigenspace_div (f : End K V) (a b : K) (hb : b ≠ 0) :
eigenspace f (a / b) = LinearMap.ker (b • f - algebraMap K (End K V) a) :=
calc
eigenspace f (a / b) = eigenspace f (b⁻¹ * a) := by rw [div_eq_mul_inv, mul_comm]
_ = LinearMap.ker (f - (b⁻¹ * a) • LinearMap.id) := by rw [eigenspace]; rfl
_ = LinearMap.ker (f - b⁻¹ • a • LinearMap.id) := by rw [smul_smul]
_ = LinearMap.ker (f - b⁻¹ • algebraMap K (End K V) a) := rfl
_ = LinearMap.ker (b • (f - b⁻¹ • algebraMap K (End K V) a)) := by
rw [LinearMap.ker_smul _ b hb]
_ = LinearMap.ker (b • f - algebraMap K (End K V) a) := by rw [smul_sub, smul_inv_smul₀ hb]
/-- The generalized eigenspace for a linear map `f`, a scalar `μ`, and an exponent `k ∈ ℕ` is the
kernel of `(f - μ • id) ^ k`. (Def 8.10 of [axler2015]). Furthermore, a generalized eigenspace for
some exponent `k` is contained in the generalized eigenspace for exponents larger than `k`. -/
def genEigenspace (f : End R M) (μ : R) : ℕ →o Submodule R M where
toFun k := LinearMap.ker ((f - algebraMap R (End R M) μ) ^ k)
monotone' k m hm := by
simp only [← pow_sub_mul_pow _ hm]
exact
LinearMap.ker_le_ker_comp ((f - algebraMap R (End R M) μ) ^ k)
((f - algebraMap R (End R M) μ) ^ (m - k))
@[simp]
theorem mem_genEigenspace (f : End R M) (μ : R) (k : ℕ) (m : M) :
m ∈ f.genEigenspace μ k ↔ ((f - μ • (1 : End R M)) ^ k) m = 0 := Iff.rfl
@[simp]
theorem genEigenspace_zero (f : End R M) (k : ℕ) :
f.genEigenspace 0 k = LinearMap.ker (f ^ k) := by
simp [Module.End.genEigenspace]
/-- A nonzero element of a generalized eigenspace is a generalized eigenvector.
(Def 8.9 of [axler2015])-/
def HasGenEigenvector (f : End R M) (μ : R) (k : ℕ) (x : M) : Prop :=
x ≠ 0 ∧ x ∈ genEigenspace f μ k
/-- A scalar `μ` is a generalized eigenvalue for a linear map `f` and an exponent `k ∈ ℕ` if there
are generalized eigenvectors for `f`, `k`, and `μ`. -/
def HasGenEigenvalue (f : End R M) (μ : R) (k : ℕ) : Prop :=
genEigenspace f μ k ≠ ⊥
/-- The generalized eigenrange for a linear map `f`, a scalar `μ`, and an exponent `k ∈ ℕ` is the
range of `(f - μ • id) ^ k`. -/
def genEigenrange (f : End R M) (μ : R) (k : ℕ) : Submodule R M :=
LinearMap.range ((f - algebraMap R (End R M) μ) ^ k)
/-- The exponent of a generalized eigenvalue is never 0. -/
theorem exp_ne_zero_of_hasGenEigenvalue {f : End R M} {μ : R} {k : ℕ}
(h : f.HasGenEigenvalue μ k) : k ≠ 0 := by
rintro rfl
exact h LinearMap.ker_id
/-- The union of the kernels of `(f - μ • id) ^ k` over all `k`. -/
def maxGenEigenspace (f : End R M) (μ : R) : Submodule R M :=
⨆ k, f.genEigenspace μ k
theorem genEigenspace_le_maximal (f : End R M) (μ : R) (k : ℕ) :
f.genEigenspace μ k ≤ f.maxGenEigenspace μ :=
le_iSup _ _
@[simp]
theorem mem_maxGenEigenspace (f : End R M) (μ : R) (m : M) :
m ∈ f.maxGenEigenspace μ ↔ ∃ k : ℕ, ((f - μ • (1 : End R M)) ^ k) m = 0 := by
simp only [maxGenEigenspace, ← mem_genEigenspace, Submodule.mem_iSup_of_chain]
/-- If there exists a natural number `k` such that the kernel of `(f - μ • id) ^ k` is the
maximal generalized eigenspace, then this value is the least such `k`. If not, this value is not
meaningful. -/
noncomputable def maxGenEigenspaceIndex (f : End R M) (μ : R) :=
monotonicSequenceLimitIndex (f.genEigenspace μ)
/-- For an endomorphism of a Noetherian module, the maximal eigenspace is always of the form kernel
`(f - μ • id) ^ k` for some `k`. -/
theorem maxGenEigenspace_eq [h : IsNoetherian R M] (f : End R M) (μ : R) :
maxGenEigenspace f μ =
f.genEigenspace μ (maxGenEigenspaceIndex f μ) := by
rw [isNoetherian_iff_wellFounded] at h
exact (WellFounded.iSup_eq_monotonicSequenceLimit h (f.genEigenspace μ) : _)
/-- A generalized eigenvalue for some exponent `k` is also
a generalized eigenvalue for exponents larger than `k`. -/
theorem hasGenEigenvalue_of_hasGenEigenvalue_of_le {f : End R M} {μ : R} {k : ℕ}
{m : ℕ} (hm : k ≤ m) (hk : f.HasGenEigenvalue μ k) :
f.HasGenEigenvalue μ m := by
unfold HasGenEigenvalue at *
contrapose! hk
rw [← le_bot_iff, ← hk]
exact (f.genEigenspace μ).monotone hm
/-- The eigenspace is a subspace of the generalized eigenspace. -/
theorem eigenspace_le_genEigenspace {f : End R M} {μ : R} {k : ℕ} (hk : 0 < k) :
f.eigenspace μ ≤ f.genEigenspace μ k :=
(f.genEigenspace μ).monotone (Nat.succ_le_of_lt hk)
/-- All eigenvalues are generalized eigenvalues. -/
theorem hasGenEigenvalue_of_hasEigenvalue {f : End R M} {μ : R} {k : ℕ} (hk : 0 < k)
(hμ : f.HasEigenvalue μ) : f.HasGenEigenvalue μ k := by
apply hasGenEigenvalue_of_hasGenEigenvalue_of_le hk
rw [HasGenEigenvalue, genEigenspace, OrderHom.coe_mk, pow_one]
exact hμ
/-- All generalized eigenvalues are eigenvalues. -/
theorem hasEigenvalue_of_hasGenEigenvalue {f : End R M} {μ : R} {k : ℕ}
(hμ : f.HasGenEigenvalue μ k) : f.HasEigenvalue μ := by
intro contra; apply hμ
erw [LinearMap.ker_eq_bot] at contra ⊢; rw [LinearMap.coe_pow]
exact Function.Injective.iterate contra k
/-- Generalized eigenvalues are actually just eigenvalues. -/
@[simp]
theorem hasGenEigenvalue_iff_hasEigenvalue {f : End R M} {μ : R} {k : ℕ} (hk : 0 < k) :
f.HasGenEigenvalue μ k ↔ f.HasEigenvalue μ :=
⟨hasEigenvalue_of_hasGenEigenvalue, hasGenEigenvalue_of_hasEigenvalue hk⟩
/-- Every generalized eigenvector is a generalized eigenvector for exponent `finrank K V`.
(Lemma 8.11 of [axler2015]) -/
theorem genEigenspace_le_genEigenspace_finrank [FiniteDimensional K V] (f : End K V)
(μ : K) (k : ℕ) : f.genEigenspace μ k ≤ f.genEigenspace μ (finrank K V) :=
ker_pow_le_ker_pow_finrank _ _
@[simp] theorem iSup_genEigenspace_eq_genEigenspace_finrank
[FiniteDimensional K V] (f : End K V) (μ : K) :
⨆ k, f.genEigenspace μ k = f.genEigenspace μ (finrank K V) :=
le_antisymm (iSup_le (genEigenspace_le_genEigenspace_finrank f μ)) (le_iSup _ _)
/-- Generalized eigenspaces for exponents at least `finrank K V` are equal to each other. -/
theorem genEigenspace_eq_genEigenspace_finrank_of_le [FiniteDimensional K V]
(f : End K V) (μ : K) {k : ℕ} (hk : finrank K V ≤ k) :
f.genEigenspace μ k = f.genEigenspace μ (finrank K V) :=
ker_pow_eq_ker_pow_finrank_of_le hk
lemma mapsTo_genEigenspace_of_comm {f g : End R M} (h : Commute f g) (μ : R) (k : ℕ) :
MapsTo g (f.genEigenspace μ k) (f.genEigenspace μ k) := by
replace h : Commute ((f - μ • (1 : End R M)) ^ k) g :=
(h.sub_left <| Algebra.commute_algebraMap_left μ g).pow_left k
intro x hx
simp only [SetLike.mem_coe, mem_genEigenspace] at hx ⊢
rw [← LinearMap.comp_apply, ← LinearMap.mul_eq_comp, h.eq, LinearMap.mul_eq_comp,
LinearMap.comp_apply, hx, map_zero]
lemma mapsTo_iSup_genEigenspace_of_comm {f g : End R M} (h : Commute f g) (μ : R) :
MapsTo g ↑(⨆ k, f.genEigenspace μ k) ↑(⨆ k, f.genEigenspace μ k) := by
simp only [MapsTo, Submodule.coe_iSup_of_chain, mem_iUnion, SetLike.mem_coe]
rintro x ⟨k, hk⟩
exact ⟨k, f.mapsTo_genEigenspace_of_comm h μ k hk⟩
/-- The restriction of `f - μ • 1` to the `k`-fold generalized `μ`-eigenspace is nilpotent. -/
lemma isNilpotent_restrict_sub_algebraMap (f : End R M) (μ : R) (k : ℕ)
(h : MapsTo (f - algebraMap R (End R M) μ)
(f.genEigenspace μ k) (f.genEigenspace μ k) :=
mapsTo_genEigenspace_of_comm (Algebra.mul_sub_algebraMap_commutes f μ) μ k) :
IsNilpotent ((f - algebraMap R (End R M) μ).restrict h) := by
use k
ext
simp [LinearMap.restrict_apply, LinearMap.pow_restrict _]
/-- The restriction of `f - μ • 1` to the generalized `μ`-eigenspace is nilpotent. -/
lemma isNilpotent_restrict_iSup_sub_algebraMap [IsNoetherian R M] (f : End R M) (μ : R)
(h : MapsTo (f - algebraMap R (End R M) μ)
↑(⨆ k, f.genEigenspace μ k) ↑(⨆ k, f.genEigenspace μ k) :=
mapsTo_iSup_genEigenspace_of_comm (Algebra.mul_sub_algebraMap_commutes f μ) μ) :
IsNilpotent ((f - algebraMap R (End R M) μ).restrict h) := by
obtain ⟨l, hl⟩ : ∃ l, ⨆ k, f.genEigenspace μ k = f.genEigenspace μ l :=
⟨_, maxGenEigenspace_eq f μ⟩
use l
ext ⟨x, hx⟩
simpa [hl, LinearMap.restrict_apply, LinearMap.pow_restrict _] using hx
lemma disjoint_genEigenspace [NoZeroSMulDivisors R M]
(f : End R M) {μ₁ μ₂ : R} (hμ : μ₁ ≠ μ₂) (k l : ℕ) :
Disjoint (f.genEigenspace μ₁ k) (f.genEigenspace μ₂ l) := by
nontriviality M
have := NoZeroSMulDivisors.isReduced R M
rw [disjoint_iff]
set p := f.genEigenspace μ₁ k ⊓ f.genEigenspace μ₂ l
by_contra hp
replace hp : Nontrivial p := Submodule.nontrivial_iff_ne_bot.mpr hp
let f₁ : End R p := (f - algebraMap R (End R M) μ₁).restrict <| MapsTo.inter_inter
(mapsTo_genEigenspace_of_comm (Algebra.mul_sub_algebraMap_commutes f μ₁) μ₁ k)
(mapsTo_genEigenspace_of_comm (Algebra.mul_sub_algebraMap_commutes f μ₁) μ₂ l)
let f₂ : End R p := (f - algebraMap R (End R M) μ₂).restrict <| MapsTo.inter_inter
(mapsTo_genEigenspace_of_comm (Algebra.mul_sub_algebraMap_commutes f μ₂) μ₁ k)
(mapsTo_genEigenspace_of_comm (Algebra.mul_sub_algebraMap_commutes f μ₂) μ₂ l)
have : IsNilpotent (f₂ - f₁) := by
apply Commute.isNilpotent_sub (x := f₂) (y := f₁) _ ⟨l, ?_⟩ ⟨k, ?_⟩
· ext; simp [f₁, f₂, smul_sub, sub_sub, smul_comm μ₁, add_sub_left_comm]
all_goals ext ⟨x, _, _⟩; simpa [LinearMap.restrict_apply, LinearMap.pow_restrict _] using ‹_›
have hf₁₂ : f₂ - f₁ = algebraMap R (End R p) (μ₁ - μ₂) := by ext; simp [f₁, f₂, sub_smul]
rw [hf₁₂, IsNilpotent.map_iff (NoZeroSMulDivisors.algebraMap_injective R (End R p)),
isNilpotent_iff_eq_zero, sub_eq_zero] at this
contradiction
lemma disjoint_iSup_genEigenspace [NoZeroSMulDivisors R M]
(f : End R M) {μ₁ μ₂ : R} (hμ : μ₁ ≠ μ₂) :
Disjoint (⨆ k, f.genEigenspace μ₁ k) (⨆ k, f.genEigenspace μ₂ k) := by
simp_rw [(f.genEigenspace μ₁).mono.directed_le.disjoint_iSup_left,
(f.genEigenspace μ₂).mono.directed_le.disjoint_iSup_right]
exact disjoint_genEigenspace f hμ
lemma injOn_genEigenspace [NoZeroSMulDivisors R M] (f : End R M) :
InjOn (⨆ k, f.genEigenspace · k) {μ | ⨆ k, f.genEigenspace μ k ≠ ⊥} := by
rintro μ₁ _ μ₂ hμ₂ (hμ₁₂ : ⨆ k, f.genEigenspace μ₁ k = ⨆ k, f.genEigenspace μ₂ k)
by_contra contra
apply hμ₂
simpa only [hμ₁₂, disjoint_self] using f.disjoint_iSup_genEigenspace contra
theorem independent_genEigenspace [NoZeroSMulDivisors R M] (f : End R M) :
CompleteLattice.Independent (fun μ ↦ ⨆ k, f.genEigenspace μ k) := by
classical
suffices ∀ μ (s : Finset R), μ ∉ s → Disjoint (⨆ k, f.genEigenspace μ k)
(s.sup fun μ ↦ ⨆ k, f.genEigenspace μ k) by
simp_rw [CompleteLattice.independent_iff_supIndep_of_injOn f.injOn_genEigenspace,
Finset.supIndep_iff_disjoint_erase]
exact fun s μ _ ↦ this _ _ (s.not_mem_erase μ)
intro μ₁ s
induction' s using Finset.induction_on with μ₂ s _ ih
· simp
intro hμ₁₂
obtain ⟨hμ₁₂ : μ₁ ≠ μ₂, hμ₁ : μ₁ ∉ s⟩ := by rwa [Finset.mem_insert, not_or] at hμ₁₂
specialize ih hμ₁
rw [Finset.sup_insert, disjoint_iff, Submodule.eq_bot_iff]
rintro x ⟨hx, hx'⟩
simp only [SetLike.mem_coe] at hx hx'
suffices x ∈ ⨆ k, genEigenspace f μ₂ k by
rw [← Submodule.mem_bot (R := R), ← (f.disjoint_iSup_genEigenspace hμ₁₂).eq_bot]
exact ⟨hx, this⟩
obtain ⟨y, hy, z, hz, rfl⟩ := Submodule.mem_sup.mp hx'; clear hx'
let g := f - algebraMap R (End R M) μ₂
obtain ⟨k : ℕ, hk : (g ^ k) y = 0⟩ := by simpa using hy
have hyz : (g ^ k) (y + z) ∈
(⨆ k, genEigenspace f μ₁ k) ⊓ s.sup fun μ ↦ ⨆ k, f.genEigenspace μ k := by
refine ⟨f.mapsTo_iSup_genEigenspace_of_comm ?_ μ₁ hx, ?_⟩
· exact Algebra.mul_sub_algebraMap_pow_commutes f μ₂ k
· rw [SetLike.mem_coe, map_add, hk, zero_add]
suffices (s.sup fun μ ↦ ⨆ k, f.genEigenspace μ k).map (g ^ k) ≤
s.sup fun μ ↦ ⨆ k, f.genEigenspace μ k by exact this (Submodule.mem_map_of_mem hz)
simp_rw [Finset.sup_eq_iSup, Submodule.map_iSup (ι := R), Submodule.map_iSup (ι := _ ∈ s)]
refine iSup₂_mono fun μ _ ↦ ?_
rintro - ⟨u, hu, rfl⟩
refine f.mapsTo_iSup_genEigenspace_of_comm ?_ μ hu
exact Algebra.mul_sub_algebraMap_pow_commutes f μ₂ k
rw [ih.eq_bot, Submodule.mem_bot] at hyz
simp_rw [Submodule.mem_iSup_of_chain, mem_genEigenspace]
exact ⟨k, hyz⟩
/-- The eigenspaces of a linear operator form an independent family of subspaces of `M`. That is,
any eigenspace has trivial intersection with the span of all the other eigenspaces. -/
theorem eigenspaces_independent [NoZeroSMulDivisors R M] (f : End R M) :
CompleteLattice.Independent f.eigenspace :=
f.independent_genEigenspace.mono fun μ ↦ le_iSup (genEigenspace f μ) 1
/-- Eigenvectors corresponding to distinct eigenvalues of a linear operator are linearly
independent. -/
theorem eigenvectors_linearIndependent' {ι : Type*} [NoZeroSMulDivisors R M]
(f : End R M) (μ : ι → R) (hμ : Function.Injective μ) (v : ι → M)
(h_eigenvec : ∀ i, f.HasEigenvector (μ i) (v i)) : LinearIndependent R v :=
f.eigenspaces_independent.comp hμ |>.linearIndependent _
(fun i => h_eigenvec i |>.left) (fun i => h_eigenvec i |>.right)
/-- Eigenvectors corresponding to distinct eigenvalues of a linear operator are linearly
independent. (Lemma 5.10 of [axler2015])
We use the eigenvalues as indexing set to ensure that there is only one eigenvector for each
eigenvalue in the image of `xs`.
See `Module.End.eigenvectors_linearIndependent'` for an indexed variant. -/
theorem eigenvectors_linearIndependent [NoZeroSMulDivisors R M]
(f : End R M) (μs : Set R) (xs : μs → M)
(h_eigenvec : ∀ μ : μs, f.HasEigenvector μ (xs μ)) : LinearIndependent R xs :=
f.eigenvectors_linearIndependent' (fun μ : μs => μ) Subtype.coe_injective _ h_eigenvec
/-- If `f` maps a subspace `p` into itself, then the generalized eigenspace of the restriction
of `f` to `p` is the part of the generalized eigenspace of `f` that lies in `p`. -/
theorem genEigenspace_restrict (f : End R M) (p : Submodule R M) (k : ℕ) (μ : R)
(hfp : ∀ x : M, x ∈ p → f x ∈ p) :
genEigenspace (LinearMap.restrict f hfp) μ k =
Submodule.comap p.subtype (f.genEigenspace μ k) := by
simp only [genEigenspace, OrderHom.coe_mk, ← LinearMap.ker_comp]
induction' k with k ih
· rw [pow_zero, pow_zero, LinearMap.one_eq_id]
apply (Submodule.ker_subtype _).symm
· erw [pow_succ, pow_succ, LinearMap.ker_comp, LinearMap.ker_comp, ih, ← LinearMap.ker_comp,
LinearMap.comp_assoc]
lemma _root_.Submodule.inf_genEigenspace (f : End R M) (p : Submodule R M) {k : ℕ} {μ : R}
(hfp : ∀ x : M, x ∈ p → f x ∈ p) :
p ⊓ f.genEigenspace μ k =
(genEigenspace (LinearMap.restrict f hfp) μ k).map p.subtype := by
rw [f.genEigenspace_restrict _ _ _ hfp, Submodule.map_comap_eq, Submodule.range_subtype]
/-- If `p` is an invariant submodule of an endomorphism `f`, then the `μ`-eigenspace of the
restriction of `f` to `p` is a submodule of the `μ`-eigenspace of `f`. -/
theorem eigenspace_restrict_le_eigenspace (f : End R M) {p : Submodule R M} (hfp : ∀ x ∈ p, f x ∈ p)
(μ : R) : (eigenspace (f.restrict hfp) μ).map p.subtype ≤ f.eigenspace μ := by
rintro a ⟨x, hx, rfl⟩
simp only [SetLike.mem_coe, mem_eigenspace_iff, LinearMap.restrict_apply] at hx ⊢
exact congr_arg Subtype.val hx
/-- Generalized eigenrange and generalized eigenspace for exponent `finrank K V` are disjoint. -/
theorem generalized_eigenvec_disjoint_range_ker [FiniteDimensional K V] (f : End K V) (μ : K) :
Disjoint (f.genEigenrange μ (finrank K V))
(f.genEigenspace μ (finrank K V)) := by
have h :=
calc
Submodule.comap ((f - algebraMap _ _ μ) ^ finrank K V)
(f.genEigenspace μ (finrank K V)) =
LinearMap.ker ((f - algebraMap _ _ μ) ^ finrank K V *
(f - algebraMap K (End K V) μ) ^ finrank K V) := by
rw [genEigenspace, OrderHom.coe_mk, ← LinearMap.ker_comp]; rfl
_ = f.genEigenspace μ (finrank K V + finrank K V) := by rw [← pow_add]; rfl
_ = f.genEigenspace μ (finrank K V) := by
rw [genEigenspace_eq_genEigenspace_finrank_of_le]; omega
rw [disjoint_iff_inf_le, genEigenrange, LinearMap.range_eq_map,
Submodule.map_inf_eq_map_inf_comap, top_inf_eq, h]
apply Submodule.map_comap_le
/-- If an invariant subspace `p` of an endomorphism `f` is disjoint from the `μ`-eigenspace of `f`,
then the restriction of `f` to `p` has trivial `μ`-eigenspace. -/
theorem eigenspace_restrict_eq_bot {f : End R M} {p : Submodule R M} (hfp : ∀ x ∈ p, f x ∈ p)
{μ : R} (hμp : Disjoint (f.eigenspace μ) p) : eigenspace (f.restrict hfp) μ = ⊥ := by
rw [eq_bot_iff]
intro x hx
simpa using hμp.le_bot ⟨eigenspace_restrict_le_eigenspace f hfp μ ⟨x, hx, rfl⟩, x.prop⟩
/-- The generalized eigenspace of an eigenvalue has positive dimension for positive exponents. -/
theorem pos_finrank_genEigenspace_of_hasEigenvalue [FiniteDimensional K V] {f : End K V}
{k : ℕ} {μ : K} (hx : f.HasEigenvalue μ) (hk : 0 < k) :
0 < finrank K (f.genEigenspace μ k) :=
calc
0 = finrank K (⊥ : Submodule K V) := by rw [finrank_bot]
_ < finrank K (f.eigenspace μ) := Submodule.finrank_lt_finrank_of_lt (bot_lt_iff_ne_bot.2 hx)
_ ≤ finrank K (f.genEigenspace μ k) :=
Submodule.finrank_mono ((f.genEigenspace μ).monotone (Nat.succ_le_of_lt hk))
/-- A linear map maps a generalized eigenrange into itself. -/
theorem map_genEigenrange_le {f : End K V} {μ : K} {n : ℕ} :
Submodule.map f (f.genEigenrange μ n) ≤ f.genEigenrange μ n :=
calc
Submodule.map f (f.genEigenrange μ n) =
LinearMap.range (f * (f - algebraMap _ _ μ) ^ n) := by
rw [genEigenrange]; exact (LinearMap.range_comp _ _).symm
_ = LinearMap.range ((f - algebraMap _ _ μ) ^ n * f) := by
rw [Algebra.mul_sub_algebraMap_pow_commutes]
_ = Submodule.map ((f - algebraMap _ _ μ) ^ n) (LinearMap.range f) := LinearMap.range_comp _ _
_ ≤ f.genEigenrange μ n := LinearMap.map_le_range
lemma iSup_genEigenspace_le_smul (f : Module.End R M) (μ t : R) :
(⨆ k, f.genEigenspace μ k) ≤ ⨆ k, (t • f).genEigenspace (t * μ) k := by
intro m hm
simp only [Submodule.mem_iSup_of_chain, mem_genEigenspace] at hm ⊢
refine Exists.imp (fun k hk ↦ ?_) hm
rw [mul_smul, ← smul_sub, smul_pow, LinearMap.smul_apply, hk, smul_zero]
lemma iSup_genEigenspace_inf_le_add
(f₁ f₂ : End R M) (μ₁ μ₂ : R) (h : Commute f₁ f₂) :
(⨆ k, f₁.genEigenspace μ₁ k) ⊓ (⨆ k, f₂.genEigenspace μ₂ k) ≤
⨆ k, (f₁ + f₂).genEigenspace (μ₁ + μ₂) k := by
intro m hm
simp only [iSup_le_iff, Submodule.mem_inf, Submodule.mem_iSup_of_chain,
mem_genEigenspace] at hm ⊢
obtain ⟨⟨k₁, hk₁⟩, ⟨k₂, hk₂⟩⟩ := hm
use k₁ + k₂ - 1
have : f₁ + f₂ - (μ₁ + μ₂) • 1 = (f₁ - μ₁ • 1) + (f₂ - μ₂ • 1) := by
rw [add_smul]; exact add_sub_add_comm f₁ f₂ (μ₁ • 1) (μ₂ • 1)
replace h : Commute (f₁ - μ₁ • 1) (f₂ - μ₂ • 1) :=
(h.sub_right <| Algebra.commute_algebraMap_right μ₂ f₁).sub_left
(Algebra.commute_algebraMap_left μ₁ _)
rw [this, h.add_pow', LinearMap.coeFn_sum, Finset.sum_apply]
refine Finset.sum_eq_zero fun ⟨i, j⟩ hij ↦ ?_
suffices (((f₁ - μ₁ • 1) ^ i) * ((f₂ - μ₂ • 1) ^ j)) m = 0 by
rw [LinearMap.smul_apply, this, smul_zero]
cases' Nat.le_or_le_of_add_eq_add_pred (Finset.mem_antidiagonal.mp hij) with hi hj
· rw [(h.pow_pow i j).eq, LinearMap.mul_apply, LinearMap.pow_map_zero_of_le hi hk₁,
LinearMap.map_zero]
· rw [LinearMap.mul_apply, LinearMap.pow_map_zero_of_le hj hk₂, LinearMap.map_zero]
lemma map_smul_of_iInf_genEigenspace_ne_bot [NoZeroSMulDivisors R M]
{L F : Type*} [SMul R L] [FunLike F L (End R M)] [MulActionHomClass F R L (End R M)] (f : F)
(μ : L → R) (h_ne : ⨅ x, ⨆ k, (f x).genEigenspace (μ x) k ≠ ⊥)
(t : R) (x : L) :
μ (t • x) = t • μ x := by
by_contra contra
let g : L → Submodule R M := fun x ↦ ⨆ k, (f x).genEigenspace (μ x) k
have : ⨅ x, g x ≤ g x ⊓ g (t • x) := le_inf_iff.mpr ⟨iInf_le g x, iInf_le g (t • x)⟩
refine h_ne <| eq_bot_iff.mpr (le_trans this (disjoint_iff_inf_le.mp ?_))
apply Disjoint.mono_left (iSup_genEigenspace_le_smul (f x) (μ x) t)
simp only [g, map_smul]
exact disjoint_iSup_genEigenspace (t • f x) (Ne.symm contra)
lemma map_add_of_iInf_genEigenspace_ne_bot_of_commute [NoZeroSMulDivisors R M]
{L F : Type*} [Add L] [FunLike F L (End R M)] [AddHomClass F L (End R M)] (f : F)
(μ : L → R) (h_ne : ⨅ x, ⨆ k, (f x).genEigenspace (μ x) k ≠ ⊥)
(h : ∀ x y, Commute (f x) (f y)) (x y : L) :
μ (x + y) = μ x + μ y := by
by_contra contra
let g : L → Submodule R M := fun x ↦ ⨆ k, (f x).genEigenspace (μ x) k
have : ⨅ x, g x ≤ (g x ⊓ g y) ⊓ g (x + y) :=
le_inf_iff.mpr ⟨le_inf_iff.mpr ⟨iInf_le g x, iInf_le g y⟩, iInf_le g (x + y)⟩
refine h_ne <| eq_bot_iff.mpr (le_trans this (disjoint_iff_inf_le.mp ?_))
apply Disjoint.mono_left (iSup_genEigenspace_inf_le_add (f x) (f y) (μ x) (μ y) (h x y))
simp only [g, map_add]
exact disjoint_iSup_genEigenspace (f x + f y) (Ne.symm contra)
end End
end Module
|
LinearAlgebra\Eigenspace\Matrix.lean | /-
Copyright (c) 2024 Jon Bannon. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jon Bannon, Jireh Loreaux
-/
import Mathlib.LinearAlgebra.Eigenspace.Basic
/-!
# Eigenvalues, Eigenvectors and Spectrum for Matrices
This file collects results about eigenvectors, eigenvalues and spectrum specific to matrices
over a nontrivial commutative ring, nontrivial commutative ring without zero divisors, or field.
## Tags
eigenspace, eigenvector, eigenvalue, spectrum, matrix
-/
section SpectrumDiagonal
variable {R n M : Type*} [DecidableEq n] [Fintype n]
open Matrix
open Module.End
section NontrivialCommRing
variable [CommRing R] [Nontrivial R] [AddCommGroup M] [Module R M]
/-- Basis vectors are eigenvectors of associated diagonal linear operator. -/
lemma hasEigenvector_toLin_diagonal (d : n → R) (i : n) (b : Basis n R M) :
HasEigenvector (toLin b b (diagonal d)) (d i) (b i) :=
⟨mem_eigenspace_iff.mpr <| by simp [diagonal], Basis.ne_zero b i⟩
/-- Standard basis vectors are eigenvectors of any associated diagonal linear operator. -/
lemma hasEigenvector_toLin'_diagonal (d : n → R) (i : n) :
HasEigenvector (toLin' (diagonal d)) (d i) (Pi.basisFun R n i) :=
hasEigenvector_toLin_diagonal ..
/-- Eigenvalues of a diagonal linear operator are the diagonal entries. -/
lemma hasEigenvalue_toLin_diagonal_iff (d : n → R) {μ : R} [NoZeroSMulDivisors R M]
(b : Basis n R M) : HasEigenvalue (toLin b b (diagonal d)) μ ↔ ∃ i, d i = μ := by
have (i : n) : HasEigenvalue (toLin b b (diagonal d)) (d i) :=
hasEigenvalue_of_hasEigenvector <| hasEigenvector_toLin_diagonal d i b
constructor
· contrapose!
intro hμ h_eig
have h_iSup : ⨆ μ ∈ Set.range d, eigenspace (toLin b b (diagonal d)) μ = ⊤ := by
rw [eq_top_iff, ← b.span_eq, Submodule.span_le]
rintro - ⟨i, rfl⟩
simp only [SetLike.mem_coe]
apply Submodule.mem_iSup_of_mem (d i)
apply Submodule.mem_iSup_of_mem ⟨i, rfl⟩
rw [mem_eigenspace_iff]
exact (hasEigenvector_toLin_diagonal d i b).apply_eq_smul
have hμ_not_mem : μ ∉ Set.range d := by simpa using fun i ↦ (hμ i)
have := eigenspaces_independent (toLin b b (diagonal d)) |>.disjoint_biSup hμ_not_mem
rw [h_iSup, disjoint_top] at this
exact h_eig this
· rintro ⟨i, rfl⟩
exact this i
/-- Eigenvalues of a diagonal linear operator with respect to standard basis
are the diagonal entries. -/
lemma hasEigenvalue_toLin'_diagonal_iff [NoZeroDivisors R] (d : n → R) {μ : R} :
HasEigenvalue (toLin' (diagonal d)) μ ↔ (∃ i, d i = μ) :=
hasEigenvalue_toLin_diagonal_iff _ <| Pi.basisFun R n
end NontrivialCommRing
/-- The spectrum of the diagonal operator is the range of the diagonal viewed as a function. -/
lemma spectrum_diagonal [Field R] (d : n → R) :
spectrum R (diagonal d) = Set.range d := by
ext μ
rw [← AlgEquiv.spectrum_eq (toLinAlgEquiv <| Pi.basisFun R n), ← hasEigenvalue_iff_mem_spectrum]
exact hasEigenvalue_toLin'_diagonal_iff d
end SpectrumDiagonal
|
LinearAlgebra\Eigenspace\Minpoly.lean | /-
Copyright (c) 2020 Alexander Bentkamp. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Alexander Bentkamp
-/
import Mathlib.LinearAlgebra.Eigenspace.Basic
import Mathlib.FieldTheory.Minpoly.Field
/-!
# Eigenvalues are the roots of the minimal polynomial.
## Tags
eigenvalue, minimal polynomial
-/
universe u v w
namespace Module
namespace End
open Polynomial FiniteDimensional
open scoped Polynomial
variable {K : Type v} {V : Type w} [Field K] [AddCommGroup V] [Module K V]
theorem eigenspace_aeval_polynomial_degree_1 (f : End K V) (q : K[X]) (hq : degree q = 1) :
eigenspace f (-q.coeff 0 / q.leadingCoeff) = LinearMap.ker (aeval f q) :=
calc
eigenspace f (-q.coeff 0 / q.leadingCoeff)
_ = LinearMap.ker (q.leadingCoeff • f - algebraMap K (End K V) (-q.coeff 0)) := by
rw [eigenspace_div]
intro h
rw [leadingCoeff_eq_zero_iff_deg_eq_bot.1 h] at hq
cases hq
_ = LinearMap.ker (aeval f (C q.leadingCoeff * X + C (q.coeff 0))) := by
rw [C_mul', aeval_def]; simp [algebraMap, Algebra.toRingHom]
_ = LinearMap.ker (aeval f q) := by rwa [← eq_X_add_C_of_degree_eq_one]
theorem ker_aeval_ring_hom'_unit_polynomial (f : End K V) (c : K[X]ˣ) :
LinearMap.ker (aeval f (c : K[X])) = ⊥ := by
rw [Polynomial.eq_C_of_degree_eq_zero (degree_coe_units c)]
simp only [aeval_def, eval₂_C]
apply ker_algebraMap_end
apply coeff_coe_units_zero_ne_zero c
theorem aeval_apply_of_hasEigenvector {f : End K V} {p : K[X]} {μ : K} {x : V}
(h : f.HasEigenvector μ x) : aeval f p x = p.eval μ • x := by
refine p.induction_on ?_ ?_ ?_
· intro a; simp [Module.algebraMap_end_apply]
· intro p q hp hq; simp [hp, hq, add_smul]
· intro n a hna
rw [mul_comm, pow_succ', mul_assoc, map_mul, LinearMap.mul_apply, mul_comm, hna]
simp only [mem_eigenspace_iff.1 h.1, smul_smul, aeval_X, eval_mul, eval_C, eval_pow, eval_X,
LinearMap.map_smulₛₗ, RingHom.id_apply, mul_comm]
theorem isRoot_of_hasEigenvalue {f : End K V} {μ : K} (h : f.HasEigenvalue μ) :
(minpoly K f).IsRoot μ := by
rcases (Submodule.ne_bot_iff _).1 h with ⟨w, ⟨H, ne0⟩⟩
refine Or.resolve_right (smul_eq_zero.1 ?_) ne0
simp [← aeval_apply_of_hasEigenvector ⟨H, ne0⟩, minpoly.aeval K f]
variable [FiniteDimensional K V] (f : End K V)
variable {f} {μ : K}
theorem hasEigenvalue_of_isRoot (h : (minpoly K f).IsRoot μ) : f.HasEigenvalue μ := by
cases' dvd_iff_isRoot.2 h with p hp
rw [HasEigenvalue, eigenspace]
intro con
cases' (LinearMap.isUnit_iff_ker_eq_bot _).2 con with u hu
have p_ne_0 : p ≠ 0 := by
intro con
apply minpoly.ne_zero (Algebra.IsIntegral.isIntegral (R := K) f)
rw [hp, con, mul_zero]
have : (aeval f) p = 0 := by
have h_aeval := minpoly.aeval K f
revert h_aeval
simp [hp, ← hu]
have h_deg := minpoly.degree_le_of_ne_zero K f p_ne_0 this
rw [hp, degree_mul, degree_X_sub_C, Polynomial.degree_eq_natDegree p_ne_0] at h_deg
norm_cast at h_deg
omega
theorem hasEigenvalue_iff_isRoot : f.HasEigenvalue μ ↔ (minpoly K f).IsRoot μ :=
⟨isRoot_of_hasEigenvalue, hasEigenvalue_of_isRoot⟩
variable (f)
lemma finite_hasEigenvalue : Set.Finite f.HasEigenvalue := by
have h : minpoly K f ≠ 0 := minpoly.ne_zero (Algebra.IsIntegral.isIntegral (R := K) f)
convert (minpoly K f).rootSet_finite K
ext μ
change f.HasEigenvalue μ ↔ _
rw [hasEigenvalue_iff_isRoot, mem_rootSet_of_ne h, IsRoot, coe_aeval_eq_eval]
/-- An endomorphism of a finite-dimensional vector space has finitely many eigenvalues. -/
noncomputable instance : Fintype f.Eigenvalues :=
Set.Finite.fintype f.finite_hasEigenvalue
end End
end Module
section FiniteSpectrum
/-- An endomorphism of a finite-dimensional vector space has a finite spectrum. -/
theorem Module.End.finite_spectrum {K : Type v} {V : Type w} [Field K] [AddCommGroup V]
[Module K V] [FiniteDimensional K V] (f : Module.End K V) :
Set.Finite (spectrum K f) := by
convert f.finite_hasEigenvalue
ext f x
exact Module.End.hasEigenvalue_iff_mem_spectrum.symm
variable {n R : Type*} [Field R] [Fintype n] [DecidableEq n]
/-- An n x n matrix over a field has a finite spectrum. -/
theorem Matrix.finite_spectrum (A : Matrix n n R) : Set.Finite (spectrum R A) := by
rw [← AlgEquiv.spectrum_eq (Matrix.toLinAlgEquiv <| Pi.basisFun R n) A]
exact Module.End.finite_spectrum _
instance Matrix.instFiniteSpectrum (A : Matrix n n R) : Finite (spectrum R A) :=
Set.finite_coe_iff.mpr (Matrix.finite_spectrum A)
end FiniteSpectrum
|
LinearAlgebra\Eigenspace\Semisimple.lean | /-
Copyright (c) 2024 Oliver Nash. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Oliver Nash
-/
import Mathlib.LinearAlgebra.Eigenspace.Basic
import Mathlib.LinearAlgebra.Semisimple
/-!
# Eigenspaces of semisimple linear endomorphisms
This file contains basic results relevant to the study of eigenspaces of semisimple linear
endomorphisms.
## Main definitions / results
* `Module.End.IsSemisimple.genEigenspace_eq_eigenspace`: for a semisimple endomorphism,
a generalized eigenspace is an eigenspace.
-/
open Function Set
namespace Module.End
variable {R M : Type*} [CommRing R] [AddCommGroup M] [Module R M] {f g : End R M}
lemma apply_eq_of_mem_genEigenspace_of_comm_of_isSemisimple_of_isNilpotent_sub
{μ : R} {k : ℕ} {m : M} (hm : m ∈ f.genEigenspace μ k)
(hfg : Commute f g) (hss : g.IsSemisimple) (hnil : IsNilpotent (f - g)) :
g m = μ • m := by
set p := f.genEigenspace μ k
have h₁ : MapsTo g p p := mapsTo_genEigenspace_of_comm hfg μ k
have h₂ : MapsTo (g - algebraMap R (End R M) μ) p p :=
mapsTo_genEigenspace_of_comm (hfg.sub_right <| Algebra.commute_algebraMap_right μ f) μ k
have h₃ : MapsTo (f - g) p p :=
mapsTo_genEigenspace_of_comm (Commute.sub_right rfl hfg) μ k
have h₄ : MapsTo (f - algebraMap R (End R M) μ) p p :=
mapsTo_genEigenspace_of_comm (Algebra.mul_sub_algebraMap_commutes f μ) μ k
replace hfg : Commute (f - algebraMap R (End R M) μ) (f - g) :=
(Commute.sub_right rfl hfg).sub_left <| Algebra.commute_algebraMap_left μ (f - g)
suffices IsNilpotent ((g - algebraMap R (End R M) μ).restrict h₂) by
replace this : g.restrict h₁ - algebraMap R (End R p) μ = 0 :=
eq_zero_of_isNilpotent_isSemisimple this (by simpa using hss.restrict)
simpa [LinearMap.restrict_apply, sub_eq_zero] using LinearMap.congr_fun this ⟨m, hm⟩
simpa [LinearMap.restrict_sub h₄ h₃] using (LinearMap.restrict_commute hfg h₄ h₃).isNilpotent_sub
(f.isNilpotent_restrict_sub_algebraMap μ k) (Module.End.isNilpotent.restrict h₃ hnil)
lemma IsSemisimple.genEigenspace_eq_eigenspace
(hf : f.IsSemisimple) (μ : R) {k : ℕ} (hk : 0 < k) :
f.genEigenspace μ k = f.eigenspace μ := by
refine le_antisymm (fun m hm ↦ mem_eigenspace_iff.mpr ?_) (eigenspace_le_genEigenspace hk)
exact apply_eq_of_mem_genEigenspace_of_comm_of_isSemisimple_of_isNilpotent_sub hm rfl hf (by simp)
lemma IsSemisimple.maxGenEigenspace_eq_eigenspace
(hf : f.IsSemisimple) (μ : R) :
f.maxGenEigenspace μ = f.eigenspace μ := by
simp_rw [maxGenEigenspace, ← (f.genEigenspace μ).monotone.iSup_nat_add 1,
hf.genEigenspace_eq_eigenspace μ (Nat.zero_lt_succ _), ciSup_const]
end Module.End
|
LinearAlgebra\Eigenspace\Triangularizable.lean | /-
Copyright (c) 2020 Alexander Bentkamp. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Alexander Bentkamp
-/
import Mathlib.LinearAlgebra.Eigenspace.Basic
import Mathlib.FieldTheory.IsAlgClosed.Spectrum
/-!
# Triangularizable linear endomorphisms
This file contains basic results relevant to the triangularizability of linear endomorphisms.
## Main definitions / results
* `Module.End.exists_eigenvalue`: in finite dimensions, over an algebraically closed field, every
linear endomorphism has an eigenvalue.
* `Module.End.iSup_genEigenspace_eq_top`: in finite dimensions, over an algebraically
closed field, the generalized eigenspaces of any linear endomorphism span the whole space.
* `Module.End.iSup_genEigenspace_restrict_eq_top`: in finite dimensions, if the
generalized eigenspaces of a linear endomorphism span the whole space then the same is true of
its restriction to any invariant submodule.
## References
* [Sheldon Axler, *Linear Algebra Done Right*][axler2015]
* https://en.wikipedia.org/wiki/Eigenvalues_and_eigenvectors
## TODO
Define triangularizable endomorphisms (e.g., as existence of a maximal chain of invariant subspaces)
and prove that in finite dimensions over a field, this is equivalent to the property that the
generalized eigenspaces span the whole space.
## Tags
eigenspace, eigenvector, eigenvalue, eigen
-/
open Set Function Module FiniteDimensional
variable {K V : Type*} [Field K] [AddCommGroup V] [Module K V]
{R M : Type*} [CommRing R] [AddCommGroup M] [Module R M]
namespace Module.End
theorem exists_hasEigenvalue_of_iSup_genEigenspace_eq_top [Nontrivial M] {f : End R M}
(hf : ⨆ μ, ⨆ k, f.genEigenspace μ k = ⊤) :
∃ μ, f.HasEigenvalue μ := by
by_contra! contra
suffices ∀ μ, ⨆ k, f.genEigenspace μ k = ⊥ by simp [this] at hf
intro μ
replace contra : ∀ k, f.genEigenspace μ k = ⊥ := fun k ↦ by
have hk : ¬ f.HasGenEigenvalue μ k := fun hk ↦ contra μ (f.hasEigenvalue_of_hasGenEigenvalue hk)
rwa [HasGenEigenvalue, not_not] at hk
simp [contra]
-- This is Lemma 5.21 of [axler2015], although we are no longer following that proof.
/-- In finite dimensions, over an algebraically closed field, every linear endomorphism has an
eigenvalue. -/
theorem exists_eigenvalue [IsAlgClosed K] [FiniteDimensional K V] [Nontrivial V] (f : End K V) :
∃ c : K, f.HasEigenvalue c := by
simp_rw [hasEigenvalue_iff_mem_spectrum]
exact spectrum.nonempty_of_isAlgClosed_of_finiteDimensional K f
noncomputable instance [IsAlgClosed K] [FiniteDimensional K V] [Nontrivial V] (f : End K V) :
Inhabited f.Eigenvalues :=
⟨⟨f.exists_eigenvalue.choose, f.exists_eigenvalue.choose_spec⟩⟩
-- Lemma 8.21 of [axler2015]
/-- In finite dimensions, over an algebraically closed field, the generalized eigenspaces of any
linear endomorphism span the whole space. -/
theorem iSup_genEigenspace_eq_top [IsAlgClosed K] [FiniteDimensional K V] (f : End K V) :
⨆ (μ : K) (k : ℕ), f.genEigenspace μ k = ⊤ := by
-- We prove the claim by strong induction on the dimension of the vector space.
induction' h_dim : finrank K V using Nat.strong_induction_on with n ih generalizing V
cases' n with n
-- If the vector space is 0-dimensional, the result is trivial.
· rw [← top_le_iff]
simp only [Submodule.finrank_eq_zero.1 (Eq.trans (finrank_top _ _) h_dim), bot_le]
-- Otherwise the vector space is nontrivial.
· haveI : Nontrivial V := finrank_pos_iff.1 (by rw [h_dim]; apply Nat.zero_lt_succ)
-- Hence, `f` has an eigenvalue `μ₀`.
obtain ⟨μ₀, hμ₀⟩ : ∃ μ₀, f.HasEigenvalue μ₀ := exists_eigenvalue f
-- We define `ES` to be the generalized eigenspace
let ES := f.genEigenspace μ₀ (finrank K V)
-- and `ER` to be the generalized eigenrange.
let ER := f.genEigenrange μ₀ (finrank K V)
-- `f` maps `ER` into itself.
have h_f_ER : ∀ x : V, x ∈ ER → f x ∈ ER := fun x hx =>
map_genEigenrange_le (Submodule.mem_map_of_mem hx)
-- Therefore, we can define the restriction `f'` of `f` to `ER`.
let f' : End K ER := f.restrict h_f_ER
-- The dimension of `ES` is positive
have h_dim_ES_pos : 0 < finrank K ES := by
dsimp only [ES]
rw [h_dim]
apply pos_finrank_genEigenspace_of_hasEigenvalue hμ₀ (Nat.zero_lt_succ n)
-- and the dimensions of `ES` and `ER` add up to `finrank K V`.
have h_dim_add : finrank K ER + finrank K ES = finrank K V := by
apply LinearMap.finrank_range_add_finrank_ker
-- Therefore the dimension `ER` mus be smaller than `finrank K V`.
have h_dim_ER : finrank K ER < n.succ := by linarith
-- This allows us to apply the induction hypothesis on `ER`:
have ih_ER : ⨆ (μ : K) (k : ℕ), f'.genEigenspace μ k = ⊤ :=
ih (finrank K ER) h_dim_ER f' rfl
-- The induction hypothesis gives us a statement about subspaces of `ER`. We can transfer this
-- to a statement about subspaces of `V` via `Submodule.subtype`:
have ih_ER' : ⨆ (μ : K) (k : ℕ), (f'.genEigenspace μ k).map ER.subtype = ER := by
simp only [(Submodule.map_iSup _ _).symm, ih_ER, Submodule.map_subtype_top ER]
-- Moreover, every generalized eigenspace of `f'` is contained in the corresponding generalized
-- eigenspace of `f`.
have hff' :
∀ μ k, (f'.genEigenspace μ k).map ER.subtype ≤ f.genEigenspace μ k := by
intros
rw [genEigenspace_restrict]
apply Submodule.map_comap_le
-- It follows that `ER` is contained in the span of all generalized eigenvectors.
have hER : ER ≤ ⨆ (μ : K) (k : ℕ), f.genEigenspace μ k := by
rw [← ih_ER']
exact iSup₂_mono hff'
-- `ES` is contained in this span by definition.
have hES : ES ≤ ⨆ (μ : K) (k : ℕ), f.genEigenspace μ k :=
le_trans (le_iSup (fun k => f.genEigenspace μ₀ k) (finrank K V))
(le_iSup (fun μ : K => ⨆ k : ℕ, f.genEigenspace μ k) μ₀)
-- Moreover, we know that `ER` and `ES` are disjoint.
have h_disjoint : Disjoint ER ES := generalized_eigenvec_disjoint_range_ker f μ₀
-- Since the dimensions of `ER` and `ES` add up to the dimension of `V`, it follows that the
-- span of all generalized eigenvectors is all of `V`.
show ⨆ (μ : K) (k : ℕ), f.genEigenspace μ k = ⊤
rw [← top_le_iff, ← Submodule.eq_top_of_disjoint ER ES h_dim_add h_disjoint]
apply sup_le hER hES
end Module.End
namespace Submodule
variable {p : Submodule K V} {f : Module.End K V}
theorem inf_iSup_genEigenspace [FiniteDimensional K V] (h : ∀ x ∈ p, f x ∈ p) :
p ⊓ ⨆ μ, ⨆ k, f.genEigenspace μ k = ⨆ μ, ⨆ k, p ⊓ f.genEigenspace μ k := by
simp_rw [← (f.genEigenspace _).mono.directed_le.inf_iSup_eq]
refine le_antisymm (fun m hm ↦ ?_)
(le_inf_iff.mpr ⟨iSup_le fun μ ↦ inf_le_left, iSup_mono fun μ ↦ inf_le_right⟩)
classical
obtain ⟨hm₀ : m ∈ p, hm₁ : m ∈ ⨆ μ, ⨆ k, f.genEigenspace μ k⟩ := hm
obtain ⟨m, hm₂, rfl⟩ := (mem_iSup_iff_exists_finsupp _ _).mp hm₁
suffices ∀ μ, (m μ : V) ∈ p by
exact (mem_iSup_iff_exists_finsupp _ _).mpr ⟨m, fun μ ↦ mem_inf.mp ⟨this μ, hm₂ μ⟩, rfl⟩
intro μ
by_cases hμ : μ ∈ m.support; swap
· simp only [Finsupp.not_mem_support_iff.mp hμ, p.zero_mem]
have h_comm : ∀ (μ₁ μ₂ : K),
Commute ((f - algebraMap K (End K V) μ₁) ^ finrank K V)
((f - algebraMap K (End K V) μ₂) ^ finrank K V) := fun μ₁ μ₂ ↦
((Commute.sub_right rfl <| Algebra.commute_algebraMap_right _ _).sub_left
(Algebra.commute_algebraMap_left _ _)).pow_pow _ _
let g : End K V := (m.support.erase μ).noncommProd _ fun μ₁ _ μ₂ _ _ ↦ h_comm μ₁ μ₂
have hfg : Commute f g := Finset.noncommProd_commute _ _ _ _ fun μ' _ ↦
(Commute.sub_right rfl <| Algebra.commute_algebraMap_right _ _).pow_right _
have hg₀ : g (m.sum fun _μ mμ ↦ mμ) = g (m μ) := by
suffices ∀ μ' ∈ m.support, g (m μ') = if μ' = μ then g (m μ) else 0 by
rw [map_finsupp_sum, Finsupp.sum_congr (g2 := fun μ' _ ↦ if μ' = μ then g (m μ) else 0) this,
Finsupp.sum_ite_eq', if_pos hμ]
rintro μ' hμ'
split_ifs with hμμ'
· rw [hμμ']
replace hm₂ : ((f - algebraMap K (End K V) μ') ^ finrank K V) (m μ') = 0 := by
obtain ⟨k, hk⟩ := (mem_iSup_of_chain _ _).mp (hm₂ μ')
exact Module.End.genEigenspace_le_genEigenspace_finrank _ _ k hk
have : _ = g := (m.support.erase μ).noncommProd_erase_mul (Finset.mem_erase.mpr ⟨hμμ', hμ'⟩)
(fun μ ↦ (f - algebraMap K (End K V) μ) ^ finrank K V) (fun μ₁ _ μ₂ _ _ ↦ h_comm μ₁ μ₂)
rw [← this, LinearMap.mul_apply, hm₂, _root_.map_zero]
have hg₁ : MapsTo g p p := Finset.noncommProd_induction _ _ _ (fun g' : End K V ↦ MapsTo g' p p)
(fun f₁ f₂ ↦ MapsTo.comp) (mapsTo_id _) fun μ' _ ↦ by
suffices MapsTo (f - algebraMap K (End K V) μ') p p by
simp only [LinearMap.coe_pow]; exact this.iterate (finrank K V)
intro x hx
rw [LinearMap.sub_apply, algebraMap_end_apply]
exact p.sub_mem (h _ hx) (smul_mem p μ' hx)
have hg₂ : MapsTo g ↑(⨆ k, f.genEigenspace μ k) ↑(⨆ k, f.genEigenspace μ k) :=
f.mapsTo_iSup_genEigenspace_of_comm hfg μ
have hg₃ : InjOn g ↑(⨆ k, f.genEigenspace μ k) := by
apply LinearMap.injOn_of_disjoint_ker (subset_refl _)
have this := f.independent_genEigenspace
simp_rw [f.iSup_genEigenspace_eq_genEigenspace_finrank] at this ⊢
rw [LinearMap.ker_noncommProd_eq_of_supIndep_ker _ _ <| this.supIndep' (m.support.erase μ),
← Finset.sup_eq_iSup]
exact Finset.supIndep_iff_disjoint_erase.mp (this.supIndep' m.support) μ hμ
have hg₄ : SurjOn g
↑(p ⊓ ⨆ k, f.genEigenspace μ k) ↑(p ⊓ ⨆ k, f.genEigenspace μ k) := by
have : MapsTo g
↑(p ⊓ ⨆ k, f.genEigenspace μ k) ↑(p ⊓ ⨆ k, f.genEigenspace μ k) :=
hg₁.inter_inter hg₂
rw [← LinearMap.injOn_iff_surjOn this]
exact hg₃.mono inter_subset_right
specialize hm₂ μ
obtain ⟨y, ⟨hy₀ : y ∈ p, hy₁ : y ∈ ⨆ k, f.genEigenspace μ k⟩, hy₂ : g y = g (m μ)⟩ :=
hg₄ ⟨(hg₀ ▸ hg₁ hm₀), hg₂ hm₂⟩
rwa [← hg₃ hy₁ hm₂ hy₂]
theorem eq_iSup_inf_genEigenspace [FiniteDimensional K V]
(h : ∀ x ∈ p, f x ∈ p) (h' : ⨆ μ, ⨆ k, f.genEigenspace μ k = ⊤) :
p = ⨆ μ, ⨆ k, p ⊓ f.genEigenspace μ k := by
rw [← inf_iSup_genEigenspace h, h', inf_top_eq]
end Submodule
/-- In finite dimensions, if the generalized eigenspaces of a linear endomorphism span the whole
space then the same is true of its restriction to any invariant submodule. -/
theorem Module.End.iSup_genEigenspace_restrict_eq_top
{p : Submodule K V} {f : Module.End K V} [FiniteDimensional K V]
(h : ∀ x ∈ p, f x ∈ p) (h' : ⨆ μ, ⨆ k, f.genEigenspace μ k = ⊤) :
⨆ μ, ⨆ k, Module.End.genEigenspace (LinearMap.restrict f h) μ k = ⊤ := by
have := congr_arg (Submodule.comap p.subtype) (Submodule.eq_iSup_inf_genEigenspace h h')
have h_inj : Function.Injective p.subtype := Subtype.coe_injective
simp_rw [Submodule.inf_genEigenspace f p h, Submodule.comap_subtype_self,
← Submodule.map_iSup, Submodule.comap_map_eq_of_injective h_inj] at this
exact this.symm
|
LinearAlgebra\Eigenspace\Zero.lean | /-
Copyright (c) 2024 Johan Commelin. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johan Commelin
-/
import Mathlib.LinearAlgebra.Charpoly.ToMatrix
import Mathlib.LinearAlgebra.Determinant
import Mathlib.LinearAlgebra.Eigenspace.Minpoly
import Mathlib.LinearAlgebra.FreeModule.StrongRankCondition
import Mathlib.RingTheory.Artinian
/-!
# Results on the eigenvalue 0
In this file we provide equivalent characterizations of properties related to the eigenvalue 0,
such as being nilpotent, having determinant equal to 0, having a non-trivial kernel, etc...
## Main results
* `LinearMap.charpoly_nilpotent_tfae`:
equivalent characterizations of nilpotent endomorphisms
* `LinearMap.hasEigenvalue_zero_tfae`:
equivalent characterizations of endomorphisms with eigenvalue 0
* `LinearMap.not_hasEigenvalue_zero_tfae`:
endomorphisms without eigenvalue 0
* `LinearMap.finrank_maxGenEigenspace`:
the dimension of the maximal generalized eigenspace of an endomorphism
is the trailing degree of its characteristic polynomial
-/
variable {R K M : Type*} [CommRing R] [IsDomain R] [Field K] [AddCommGroup M]
variable [Module R M] [Module.Finite R M] [Module.Free R M]
variable [Module K M] [Module.Finite K M]
open FiniteDimensional Module.Free Polynomial
lemma IsNilpotent.charpoly_eq_X_pow_finrank (φ : Module.End R M) (h : IsNilpotent φ) :
φ.charpoly = X ^ finrank R M := by
rw [← sub_eq_zero]
apply IsNilpotent.eq_zero
rw [finrank_eq_card_chooseBasisIndex]
apply Matrix.isNilpotent_charpoly_sub_pow_of_isNilpotent
exact h.map (LinearMap.toMatrixAlgEquiv (chooseBasis R M))
namespace LinearMap
open Module.Free in
lemma charpoly_nilpotent_tfae [IsNoetherian R M] (φ : Module.End R M) :
List.TFAE [
IsNilpotent φ,
φ.charpoly = X ^ finrank R M,
∀ m : M, ∃ (n : ℕ), (φ ^ n) m = 0,
natTrailingDegree φ.charpoly = finrank R M ] := by
tfae_have 1 → 2
· apply IsNilpotent.charpoly_eq_X_pow_finrank
tfae_have 2 → 3
· intro h m
use finrank R M
suffices φ ^ finrank R M = 0 by simp only [this, LinearMap.zero_apply]
simpa only [h, map_pow, aeval_X] using φ.aeval_self_charpoly
tfae_have 3 → 1
· intro h
obtain ⟨n, hn⟩ := Filter.eventually_atTop.mp <| φ.eventually_iSup_ker_pow_eq
use n
ext x
rw [zero_apply, ← mem_ker, ← hn n le_rfl]
obtain ⟨k, hk⟩ := h x
rw [← mem_ker] at hk
exact Submodule.mem_iSup_of_mem _ hk
tfae_have 2 ↔ 4
· rw [← φ.charpoly_natDegree, φ.charpoly_monic.eq_X_pow_iff_natTrailingDegree_eq_natDegree]
tfae_finish
lemma charpoly_eq_X_pow_iff [IsNoetherian R M] (φ : Module.End R M) :
φ.charpoly = X ^ finrank R M ↔ ∀ m : M, ∃ (n : ℕ), (φ ^ n) m = 0 :=
(charpoly_nilpotent_tfae φ).out 1 2
open Module.Free in
lemma hasEigenvalue_zero_tfae (φ : Module.End K M) :
List.TFAE [
Module.End.HasEigenvalue φ 0,
IsRoot (minpoly K φ) 0,
constantCoeff φ.charpoly = 0,
LinearMap.det φ = 0,
⊥ < ker φ,
∃ (m : M), m ≠ 0 ∧ φ m = 0 ] := by
tfae_have 1 ↔ 2
· exact Module.End.hasEigenvalue_iff_isRoot
tfae_have 2 → 3
· obtain ⟨F, hF⟩ := minpoly_dvd_charpoly φ
simp only [IsRoot.def, constantCoeff_apply, coeff_zero_eq_eval_zero, hF, eval_mul]
intro h; rw [h, zero_mul]
tfae_have 3 → 4
· rw [← LinearMap.det_toMatrix (chooseBasis K M), Matrix.det_eq_sign_charpoly_coeff,
constantCoeff_apply, charpoly]
intro h; rw [h, mul_zero]
tfae_have 4 → 5
· exact bot_lt_ker_of_det_eq_zero
tfae_have 5 → 6
· contrapose!
simp only [not_bot_lt_iff, eq_bot_iff]
intro h x
simp only [mem_ker, Submodule.mem_bot]
contrapose!
apply h
tfae_have 6 → 1
· rintro ⟨x, h1, h2⟩
apply Module.End.hasEigenvalue_of_hasEigenvector ⟨_, h1⟩
simpa only [Module.End.eigenspace_zero, mem_ker] using h2
tfae_finish
lemma charpoly_constantCoeff_eq_zero_iff (φ : Module.End K M) :
constantCoeff φ.charpoly = 0 ↔ ∃ (m : M), m ≠ 0 ∧ φ m = 0 :=
(hasEigenvalue_zero_tfae φ).out 2 5
open Module.Free in
lemma not_hasEigenvalue_zero_tfae (φ : Module.End K M) :
List.TFAE [
¬ Module.End.HasEigenvalue φ 0,
¬ IsRoot (minpoly K φ) 0,
constantCoeff φ.charpoly ≠ 0,
LinearMap.det φ ≠ 0,
ker φ = ⊥,
∀ (m : M), φ m = 0 → m = 0 ] := by
have := (hasEigenvalue_zero_tfae φ).not
dsimp only [List.map] at this
push_neg at this
have aux₁ : ∀ m, (m ≠ 0 → φ m ≠ 0) ↔ (φ m = 0 → m = 0) := by intro m; apply not_imp_not
have aux₂ : ker φ = ⊥ ↔ ¬ ⊥ < ker φ := by rw [bot_lt_iff_ne_bot, not_not]
simpa only [aux₁, aux₂] using this
open Module.Free in
lemma finrank_maxGenEigenspace (φ : Module.End K M) :
finrank K (φ.maxGenEigenspace 0) = natTrailingDegree (φ.charpoly) := by
set V := φ.maxGenEigenspace 0
have hV : V = ⨆ (n : ℕ), ker (φ ^ n) := by
simp [V, Module.End.maxGenEigenspace, Module.End.genEigenspace]
let W := ⨅ (n : ℕ), LinearMap.range (φ ^ n)
have hVW : IsCompl V W := by
rw [hV]
exact LinearMap.isCompl_iSup_ker_pow_iInf_range_pow φ
have hφV : ∀ x ∈ V, φ x ∈ V := by
simp only [V, Module.End.mem_maxGenEigenspace, zero_smul, sub_zero,
forall_exists_index]
intro x n hx
use n
rw [← LinearMap.mul_apply, ← pow_succ, pow_succ', LinearMap.mul_apply, hx, map_zero]
have hφW : ∀ x ∈ W, φ x ∈ W := by
simp only [W, Submodule.mem_iInf, mem_range]
intro x H n
obtain ⟨y, rfl⟩ := H n
use φ y
rw [← LinearMap.mul_apply, ← pow_succ, pow_succ', LinearMap.mul_apply]
let F := φ.restrict hφV
let G := φ.restrict hφW
let ψ := F.prodMap G
let e := Submodule.prodEquivOfIsCompl V W hVW
let bV := chooseBasis K V
let bW := chooseBasis K W
let b := bV.prod bW
have hψ : ψ = e.symm.conj φ := by
apply b.ext
simp only [Basis.prod_apply, coe_inl, coe_inr, prodMap_apply, LinearEquiv.conj_apply,
LinearEquiv.symm_symm, Submodule.coe_prodEquivOfIsCompl, coe_comp, LinearEquiv.coe_coe,
Function.comp_apply, coprod_apply, Submodule.coeSubtype, map_add, Sum.forall, Sum.elim_inl,
map_zero, ZeroMemClass.coe_zero, add_zero, LinearEquiv.eq_symm_apply, and_self,
Submodule.coe_prodEquivOfIsCompl', restrict_coe_apply, implies_true, Sum.elim_inr, zero_add,
e, V, W, ψ, F, G, b]
rw [← e.symm.charpoly_conj φ, ← hψ, charpoly_prodMap,
natTrailingDegree_mul (charpoly_monic _).ne_zero (charpoly_monic _).ne_zero]
have hG : natTrailingDegree (charpoly G) = 0 := by
apply Polynomial.natTrailingDegree_eq_zero_of_constantCoeff_ne_zero
apply ((not_hasEigenvalue_zero_tfae G).out 2 5).mpr
intro x hx
apply Subtype.ext
suffices x.1 ∈ V ⊓ W by rwa [hVW.inf_eq_bot, Submodule.mem_bot] at this
suffices x.1 ∈ V from ⟨this, x.2⟩
simp only [Module.End.mem_maxGenEigenspace, zero_smul, sub_zero, V]
use 1
rw [pow_one]
rwa [Subtype.ext_iff] at hx
rw [hG, add_zero, eq_comm]
apply ((charpoly_nilpotent_tfae F).out 2 3).mp
simp only [Subtype.forall, Module.End.mem_maxGenEigenspace, zero_smul, sub_zero, V, F]
rintro x ⟨n, hx⟩
use n
apply Subtype.ext
rw [ZeroMemClass.coe_zero]
refine .trans ?_ hx
generalize_proofs h'
clear hx
induction n with
| zero => simp only [Nat.zero_eq, pow_zero, one_apply]
| succ n ih => simp only [pow_succ', LinearMap.mul_apply, ih, restrict_apply]
end LinearMap
|
LinearAlgebra\ExteriorAlgebra\Basic.lean | /-
Copyright (c) 2020 Adam Topaz. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Zhangir Azerbayev, Adam Topaz, Eric Wieser
-/
import Mathlib.LinearAlgebra.CliffordAlgebra.Basic
import Mathlib.LinearAlgebra.Alternating.Basic
/-!
# Exterior Algebras
We construct the exterior algebra of a module `M` over a commutative semiring `R`.
## Notation
The exterior algebra of the `R`-module `M` is denoted as `ExteriorAlgebra R M`.
It is endowed with the structure of an `R`-algebra.
The `n`th exterior power of the `R`-module `M` is denoted by `exteriorPower R n M`;
it is of type `Submodule R (ExteriorAlgebra R M)` and defined as
`LinearMap.range (ExteriorAlgebra.ι R : M →ₗ[R] ExteriorAlgebra R M) ^ n`.
We also introduce the notation `⋀[R]^n M` for `exteriorPower R n M`.
Given a linear morphism `f : M → A` from a module `M` to another `R`-algebra `A`, such that
`cond : ∀ m : M, f m * f m = 0`, there is a (unique) lift of `f` to an `R`-algebra morphism,
which is denoted `ExteriorAlgebra.lift R f cond`.
The canonical linear map `M → ExteriorAlgebra R M` is denoted `ExteriorAlgebra.ι R`.
## Theorems
The main theorems proved ensure that `ExteriorAlgebra R M` satisfies the universal property
of the exterior algebra.
1. `ι_comp_lift` is the fact that the composition of `ι R` with `lift R f cond` agrees with `f`.
2. `lift_unique` ensures the uniqueness of `lift R f cond` with respect to 1.
## Definitions
* `ιMulti` is the `AlternatingMap` corresponding to the wedge product of `ι R m` terms.
## Implementation details
The exterior algebra of `M` is constructed as simply `CliffordAlgebra (0 : QuadraticForm R M)`,
as this avoids us having to duplicate API.
-/
universe u1 u2 u3 u4 u5
variable (R : Type u1) [CommRing R]
variable (M : Type u2) [AddCommGroup M] [Module R M]
/-- The exterior algebra of an `R`-module `M`.
-/
abbrev ExteriorAlgebra :=
CliffordAlgebra (0 : QuadraticForm R M)
namespace ExteriorAlgebra
variable {M}
/-- The canonical linear map `M →ₗ[R] ExteriorAlgebra R M`.
-/
abbrev ι : M →ₗ[R] ExteriorAlgebra R M :=
CliffordAlgebra.ι _
section exteriorPower
-- New variables `n` and `M`, to get the correct order of variables in the notation.
variable (n : ℕ) (M : Type u2) [AddCommGroup M] [Module R M]
/-- Definition of the `n`th exterior power of a `R`-module `N`. We introduce the notation
`⋀[R]^n M` for `exteriorPower R n M`. -/
abbrev exteriorPower : Submodule R (ExteriorAlgebra R M) :=
LinearMap.range (ι R : M →ₗ[R] ExteriorAlgebra R M) ^ n
@[inherit_doc exteriorPower]
notation:max "⋀[" R "]^" n:arg => exteriorPower R n
end exteriorPower
variable {R}
/-- As well as being linear, `ι m` squares to zero. -/
-- @[simp] -- Porting note (#10618): simp can prove this
theorem ι_sq_zero (m : M) : ι R m * ι R m = 0 :=
(CliffordAlgebra.ι_sq_scalar _ m).trans <| map_zero _
variable {A : Type*} [Semiring A] [Algebra R A]
-- @[simp] -- Porting note (#10618): simp can prove this
theorem comp_ι_sq_zero (g : ExteriorAlgebra R M →ₐ[R] A) (m : M) : g (ι R m) * g (ι R m) = 0 := by
rw [← map_mul, ι_sq_zero, map_zero]
variable (R)
/-- Given a linear map `f : M →ₗ[R] A` into an `R`-algebra `A`, which satisfies the condition:
`cond : ∀ m : M, f m * f m = 0`, this is the canonical lift of `f` to a morphism of `R`-algebras
from `ExteriorAlgebra R M` to `A`.
-/
@[simps! symm_apply]
def lift : { f : M →ₗ[R] A // ∀ m, f m * f m = 0 } ≃ (ExteriorAlgebra R M →ₐ[R] A) :=
Equiv.trans (Equiv.subtypeEquiv (Equiv.refl _) <| by simp) <| CliffordAlgebra.lift _
@[simp]
theorem ι_comp_lift (f : M →ₗ[R] A) (cond : ∀ m, f m * f m = 0) :
(lift R ⟨f, cond⟩).toLinearMap.comp (ι R) = f :=
CliffordAlgebra.ι_comp_lift f _
@[simp]
theorem lift_ι_apply (f : M →ₗ[R] A) (cond : ∀ m, f m * f m = 0) (x) :
lift R ⟨f, cond⟩ (ι R x) = f x :=
CliffordAlgebra.lift_ι_apply f _ x
@[simp]
theorem lift_unique (f : M →ₗ[R] A) (cond : ∀ m, f m * f m = 0) (g : ExteriorAlgebra R M →ₐ[R] A) :
g.toLinearMap.comp (ι R) = f ↔ g = lift R ⟨f, cond⟩ :=
CliffordAlgebra.lift_unique f _ _
variable {R}
@[simp]
theorem lift_comp_ι (g : ExteriorAlgebra R M →ₐ[R] A) :
lift R ⟨g.toLinearMap.comp (ι R), comp_ι_sq_zero _⟩ = g :=
CliffordAlgebra.lift_comp_ι g
/-- See note [partially-applied ext lemmas]. -/
@[ext]
theorem hom_ext {f g : ExteriorAlgebra R M →ₐ[R] A}
(h : f.toLinearMap.comp (ι R) = g.toLinearMap.comp (ι R)) : f = g :=
CliffordAlgebra.hom_ext h
/-- If `C` holds for the `algebraMap` of `r : R` into `ExteriorAlgebra R M`, the `ι` of `x : M`,
and is preserved under addition and muliplication, then it holds for all of `ExteriorAlgebra R M`.
-/
@[elab_as_elim]
theorem induction {C : ExteriorAlgebra R M → Prop}
(algebraMap : ∀ r, C (algebraMap R (ExteriorAlgebra R M) r)) (ι : ∀ x, C (ι R x))
(mul : ∀ a b, C a → C b → C (a * b)) (add : ∀ a b, C a → C b → C (a + b))
(a : ExteriorAlgebra R M) : C a :=
CliffordAlgebra.induction algebraMap ι mul add a
/-- The left-inverse of `algebraMap`. -/
def algebraMapInv : ExteriorAlgebra R M →ₐ[R] R :=
ExteriorAlgebra.lift R ⟨(0 : M →ₗ[R] R), fun _ => by simp⟩
variable (M)
theorem algebraMap_leftInverse :
Function.LeftInverse algebraMapInv (algebraMap R <| ExteriorAlgebra R M) := fun x => by
simp [algebraMapInv]
@[simp]
theorem algebraMap_inj (x y : R) :
algebraMap R (ExteriorAlgebra R M) x = algebraMap R (ExteriorAlgebra R M) y ↔ x = y :=
(algebraMap_leftInverse M).injective.eq_iff
@[simp]
theorem algebraMap_eq_zero_iff (x : R) : algebraMap R (ExteriorAlgebra R M) x = 0 ↔ x = 0 :=
map_eq_zero_iff (algebraMap _ _) (algebraMap_leftInverse _).injective
@[simp]
theorem algebraMap_eq_one_iff (x : R) : algebraMap R (ExteriorAlgebra R M) x = 1 ↔ x = 1 :=
map_eq_one_iff (algebraMap _ _) (algebraMap_leftInverse _).injective
theorem isUnit_algebraMap (r : R) : IsUnit (algebraMap R (ExteriorAlgebra R M) r) ↔ IsUnit r :=
isUnit_map_of_leftInverse _ (algebraMap_leftInverse M)
/-- Invertibility in the exterior algebra is the same as invertibility of the base ring. -/
@[simps!]
def invertibleAlgebraMapEquiv (r : R) :
Invertible (algebraMap R (ExteriorAlgebra R M) r) ≃ Invertible r :=
invertibleEquivOfLeftInverse _ _ _ (algebraMap_leftInverse M)
variable {M}
/-- The canonical map from `ExteriorAlgebra R M` into `TrivSqZeroExt R M` that sends
`ExteriorAlgebra.ι` to `TrivSqZeroExt.inr`. -/
def toTrivSqZeroExt [Module Rᵐᵒᵖ M] [IsCentralScalar R M] :
ExteriorAlgebra R M →ₐ[R] TrivSqZeroExt R M :=
lift R ⟨TrivSqZeroExt.inrHom R M, fun m => TrivSqZeroExt.inr_mul_inr R m m⟩
@[simp]
theorem toTrivSqZeroExt_ι [Module Rᵐᵒᵖ M] [IsCentralScalar R M] (x : M) :
toTrivSqZeroExt (ι R x) = TrivSqZeroExt.inr x :=
lift_ι_apply _ _ _ _
/-- The left-inverse of `ι`.
As an implementation detail, we implement this using `TrivSqZeroExt` which has a suitable
algebra structure. -/
def ιInv : ExteriorAlgebra R M →ₗ[R] M := by
letI : Module Rᵐᵒᵖ M := Module.compHom _ ((RingHom.id R).fromOpposite mul_comm)
haveI : IsCentralScalar R M := ⟨fun r m => rfl⟩
exact (TrivSqZeroExt.sndHom R M).comp toTrivSqZeroExt.toLinearMap
theorem ι_leftInverse : Function.LeftInverse ιInv (ι R : M → ExteriorAlgebra R M) := fun x => by
-- Porting note: Original proof didn't have `letI` and `haveI`
letI : Module Rᵐᵒᵖ M := Module.compHom _ ((RingHom.id R).fromOpposite mul_comm)
haveI : IsCentralScalar R M := ⟨fun r m => rfl⟩
simp [ιInv]
variable (R)
@[simp]
theorem ι_inj (x y : M) : ι R x = ι R y ↔ x = y :=
ι_leftInverse.injective.eq_iff
variable {R}
@[simp]
theorem ι_eq_zero_iff (x : M) : ι R x = 0 ↔ x = 0 := by rw [← ι_inj R x 0, LinearMap.map_zero]
@[simp]
theorem ι_eq_algebraMap_iff (x : M) (r : R) : ι R x = algebraMap R _ r ↔ x = 0 ∧ r = 0 := by
refine ⟨fun h => ?_, ?_⟩
· letI : Module Rᵐᵒᵖ M := Module.compHom _ ((RingHom.id R).fromOpposite mul_comm)
haveI : IsCentralScalar R M := ⟨fun r m => rfl⟩
have hf0 : toTrivSqZeroExt (ι R x) = (0, x) := toTrivSqZeroExt_ι _
rw [h, AlgHom.commutes] at hf0
have : r = 0 ∧ 0 = x := Prod.ext_iff.1 hf0
exact this.symm.imp_left Eq.symm
· rintro ⟨rfl, rfl⟩
rw [LinearMap.map_zero, RingHom.map_zero]
@[simp]
theorem ι_ne_one [Nontrivial R] (x : M) : ι R x ≠ 1 := by
rw [← (algebraMap R (ExteriorAlgebra R M)).map_one, Ne, ι_eq_algebraMap_iff]
exact one_ne_zero ∘ And.right
/-- The generators of the exterior algebra are disjoint from its scalars. -/
theorem ι_range_disjoint_one :
Disjoint (LinearMap.range (ι R : M →ₗ[R] ExteriorAlgebra R M))
(1 : Submodule R (ExteriorAlgebra R M)) := by
rw [Submodule.disjoint_def]
rintro _ ⟨x, hx⟩ ⟨r, rfl : algebraMap R (ExteriorAlgebra R M) r = _⟩
rw [ι_eq_algebraMap_iff x] at hx
rw [hx.2, RingHom.map_zero]
@[simp]
theorem ι_add_mul_swap (x y : M) : ι R x * ι R y + ι R y * ι R x = 0 :=
CliffordAlgebra.ι_mul_ι_add_swap_of_isOrtho <| .all _ _
theorem ι_mul_prod_list {n : ℕ} (f : Fin n → M) (i : Fin n) :
(ι R <| f i) * (List.ofFn fun i => ι R <| f i).prod = 0 := by
induction' n with n hn
· exact i.elim0
· rw [List.ofFn_succ, List.prod_cons, ← mul_assoc]
by_cases h : i = 0
· rw [h, ι_sq_zero, zero_mul]
· replace hn :=
congr_arg (ι R (f 0) * ·) <| hn (fun i => f <| Fin.succ i) (i.pred h)
simp only at hn
rw [Fin.succ_pred, ← mul_assoc, mul_zero] at hn
refine (eq_zero_iff_eq_zero_of_add_eq_zero ?_).mp hn
rw [← add_mul, ι_add_mul_swap, zero_mul]
variable (R)
/-- The product of `n` terms of the form `ι R m` is an alternating map.
This is a special case of `MultilinearMap.mkPiAlgebraFin`, and the exterior algebra version of
`TensorAlgebra.tprod`. -/
def ιMulti (n : ℕ) : M [⋀^Fin n]→ₗ[R] ExteriorAlgebra R M :=
let F := (MultilinearMap.mkPiAlgebraFin R n (ExteriorAlgebra R M)).compLinearMap fun _ => ι R
{ F with
map_eq_zero_of_eq' := fun f x y hfxy hxy => by
dsimp [F]
clear F
wlog h : x < y
· exact this R (A := A) n f y x hfxy.symm hxy.symm (hxy.lt_or_lt.resolve_left h)
clear hxy
induction' n with n hn
· exact x.elim0
· rw [List.ofFn_succ, List.prod_cons]
by_cases hx : x = 0
-- one of the repeated terms is on the left
· rw [hx] at hfxy h
rw [hfxy, ← Fin.succ_pred y (ne_of_lt h).symm]
exact ι_mul_prod_list (f ∘ Fin.succ) _
-- ignore the left-most term and induct on the remaining ones, decrementing indices
· convert mul_zero (ι R (f 0))
refine
hn
(fun i => f <| Fin.succ i) (x.pred hx)
(y.pred (ne_of_lt <| lt_of_le_of_lt x.zero_le h).symm) ?_
(Fin.pred_lt_pred_iff.mpr h)
simp only [Fin.succ_pred]
exact hfxy
toFun := F }
variable {R}
theorem ιMulti_apply {n : ℕ} (v : Fin n → M) : ιMulti R n v = (List.ofFn fun i => ι R (v i)).prod :=
rfl
@[simp]
theorem ιMulti_zero_apply (v : Fin 0 → M) : ιMulti R 0 v = 1 :=
rfl
@[simp]
theorem ιMulti_succ_apply {n : ℕ} (v : Fin n.succ → M) :
ιMulti R _ v = ι R (v 0) * ιMulti R _ (Matrix.vecTail v) := by
simp [ιMulti, Matrix.vecTail]
theorem ιMulti_succ_curryLeft {n : ℕ} (m : M) :
(ιMulti R n.succ).curryLeft m = (LinearMap.mulLeft R (ι R m)).compAlternatingMap (ιMulti R n) :=
AlternatingMap.ext fun v =>
(ιMulti_succ_apply _).trans <| by
simp_rw [Matrix.tail_cons]
rfl
variable (R)
/-- The image of `ExteriorAlgebra.ιMulti R n` is contained in the `n`th exterior power. -/
lemma ιMulti_range (n : ℕ) :
Set.range (ιMulti R n (M := M)) ⊆ ↑(⋀[R]^n M) := by
rw [Set.range_subset_iff]
intro v
rw [ιMulti_apply]
apply Submodule.pow_subset_pow
rw [Set.mem_pow]
exact ⟨fun i => ⟨ι R (v i), LinearMap.mem_range_self _ _⟩, rfl⟩
/-- The image of `ExteriorAlgebra.ιMulti R n` spans the `n`th exterior power, as a submodule
of the exterior algebra. -/
lemma ιMulti_span_fixedDegree (n : ℕ) :
Submodule.span R (Set.range (ιMulti R n)) = ⋀[R]^n M := by
refine le_antisymm (Submodule.span_le.2 (ιMulti_range R n)) ?_
rw [exteriorPower, Submodule.pow_eq_span_pow_set, Submodule.span_le]
refine fun u hu ↦ Submodule.subset_span ?_
obtain ⟨f, rfl⟩ := Set.mem_pow.mp hu
refine ⟨fun i => ιInv (f i).1, ?_⟩
rw [ιMulti_apply]
congr with i
obtain ⟨v, hv⟩ := (f i).prop
rw [← hv, ι_leftInverse]
/-- Given a linearly ordered family `v` of vectors of `M` and a natural number `n`, produce the
family of `n`fold exterior products of elements of `v`, seen as members of the exterior algebra. -/
abbrev ιMulti_family (n : ℕ) {I : Type*} [LinearOrder I] (v : I → M)
(s : {s : Finset I // Finset.card s = n}) : ExteriorAlgebra R M :=
ιMulti R n fun i => v (Finset.orderIsoOfFin _ s.prop i)
variable {R}
/-- An `ExteriorAlgebra` over a nontrivial ring is nontrivial. -/
instance [Nontrivial R] : Nontrivial (ExteriorAlgebra R M) :=
(algebraMap_leftInverse M).injective.nontrivial
/-! Functoriality of the exterior algebra. -/
variable {N : Type u4} {N' : Type u5} [AddCommGroup N] [Module R N] [AddCommGroup N'] [Module R N']
/-- The morphism of exterior algebras induced by a linear map. -/
def map (f : M →ₗ[R] N) : ExteriorAlgebra R M →ₐ[R] ExteriorAlgebra R N :=
CliffordAlgebra.map { f with map_app' := fun _ => rfl }
@[simp]
theorem map_comp_ι (f : M →ₗ[R] N) : (map f).toLinearMap ∘ₗ ι R = ι R ∘ₗ f :=
CliffordAlgebra.map_comp_ι _
@[simp]
theorem map_apply_ι (f : M →ₗ[R] N) (m : M) : map f (ι R m) = ι R (f m) :=
CliffordAlgebra.map_apply_ι _ m
@[simp]
theorem map_apply_ιMulti {n : ℕ} (f : M →ₗ[R] N) (m : Fin n → M) :
map f (ιMulti R n m) = ιMulti R n (f ∘ m) := by
rw [ιMulti_apply, ιMulti_apply, map_list_prod]
simp only [List.map_ofFn, Function.comp, map_apply_ι]
@[simp]
theorem map_comp_ιMulti {n : ℕ} (f : M →ₗ[R] N) :
(map f).toLinearMap.compAlternatingMap (ιMulti R n (M := M)) =
(ιMulti R n (M := N)).compLinearMap f := by
ext m
exact map_apply_ιMulti _ _
@[simp]
theorem map_id :
map LinearMap.id = AlgHom.id R (ExteriorAlgebra R M) :=
CliffordAlgebra.map_id 0
@[simp]
theorem map_comp_map (f : M →ₗ[R] N) (g : N →ₗ[R] N') :
AlgHom.comp (map g) (map f) = map (LinearMap.comp g f) :=
CliffordAlgebra.map_comp_map _ _
@[simp]
theorem ι_range_map_map (f : M →ₗ[R] N) :
Submodule.map (AlgHom.toLinearMap (map f)) (LinearMap.range (ι R (M := M))) =
Submodule.map (ι R) (LinearMap.range f) :=
CliffordAlgebra.ι_range_map_map _
theorem toTrivSqZeroExt_comp_map [Module Rᵐᵒᵖ M] [IsCentralScalar R M] [Module Rᵐᵒᵖ N]
[IsCentralScalar R N] (f : M →ₗ[R] N) :
toTrivSqZeroExt.comp (map f) = (TrivSqZeroExt.map f).comp toTrivSqZeroExt := by
apply hom_ext
apply LinearMap.ext
simp only [AlgHom.comp_toLinearMap, LinearMap.coe_comp, Function.comp_apply,
AlgHom.toLinearMap_apply, map_apply_ι, toTrivSqZeroExt_ι, TrivSqZeroExt.map_inr, forall_const]
theorem ιInv_comp_map (f : M →ₗ[R] N) :
ιInv.comp (map f).toLinearMap = f.comp ιInv := by
letI : Module Rᵐᵒᵖ M := Module.compHom _ ((RingHom.id R).fromOpposite mul_comm)
haveI : IsCentralScalar R M := ⟨fun r m => rfl⟩
letI : Module Rᵐᵒᵖ N := Module.compHom _ ((RingHom.id R).fromOpposite mul_comm)
haveI : IsCentralScalar R N := ⟨fun r m => rfl⟩
unfold ιInv
conv_lhs => rw [LinearMap.comp_assoc, ← AlgHom.comp_toLinearMap, toTrivSqZeroExt_comp_map,
AlgHom.comp_toLinearMap, ← LinearMap.comp_assoc, TrivSqZeroExt.sndHom_comp_map]
rfl
open Function in
/-- For a linear map `f` from `M` to `N`,
`ExteriorAlgebra.map g` is a retraction of `ExteriorAlgebra.map f` iff
`g` is a retraction of `f`. -/
@[simp]
lemma leftInverse_map_iff {f : M →ₗ[R] N} {g : N →ₗ[R] M} :
LeftInverse (map g) (map f) ↔ LeftInverse g f := by
refine ⟨fun h x => ?_, fun h => CliffordAlgebra.leftInverse_map_of_leftInverse _ _ h⟩
simpa using h (ι _ x)
/-- A morphism of modules that admits a linear retraction induces an injective morphism of
exterior algebras. -/
lemma map_injective {f : M →ₗ[R] N} (hf : ∃ (g : N →ₗ[R] M), g.comp f = LinearMap.id) :
Function.Injective (map f) :=
let ⟨_, hgf⟩ := hf; (leftInverse_map_iff.mpr (DFunLike.congr_fun hgf)).injective
/-- A morphism of modules is surjective if and only the morphism of exterior algebras that it
induces is surjective. -/
@[simp]
lemma map_surjective_iff {f : M →ₗ[R] N} :
Function.Surjective (map f) ↔ Function.Surjective f := by
refine ⟨fun h y ↦ ?_, fun h ↦ CliffordAlgebra.map_surjective _ h⟩
obtain ⟨x, hx⟩ := h (ι R y)
existsi ιInv x
rw [← LinearMap.comp_apply, ← ιInv_comp_map, LinearMap.comp_apply]
erw [hx, ExteriorAlgebra.ι_leftInverse]
variable {K E F : Type*} [Field K] [AddCommGroup E]
[Module K E] [AddCommGroup F] [Module K F]
/-- An injective morphism of vector spaces induces an injective morphism of exterior algebras. -/
lemma map_injective_field {f : E →ₗ[K] F} (hf : LinearMap.ker f = ⊥) :
Function.Injective (map f) :=
map_injective (LinearMap.exists_leftInverse_of_injective f hf)
end ExteriorAlgebra
namespace TensorAlgebra
variable {R M}
/-- The canonical image of the `TensorAlgebra` in the `ExteriorAlgebra`, which maps
`TensorAlgebra.ι R x` to `ExteriorAlgebra.ι R x`. -/
def toExterior : TensorAlgebra R M →ₐ[R] ExteriorAlgebra R M :=
TensorAlgebra.lift R (ExteriorAlgebra.ι R : M →ₗ[R] ExteriorAlgebra R M)
@[simp]
theorem toExterior_ι (m : M) :
TensorAlgebra.toExterior (TensorAlgebra.ι R m) = ExteriorAlgebra.ι R m := by
simp [toExterior]
end TensorAlgebra
|
LinearAlgebra\ExteriorAlgebra\Grading.lean | /-
Copyright (c) 2021 Eric Wieser. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Eric Wieser
-/
import Mathlib.LinearAlgebra.ExteriorAlgebra.Basic
import Mathlib.RingTheory.GradedAlgebra.Basic
/-!
# Results about the grading structure of the exterior algebra
Many of these results are copied with minimal modification from the tensor algebra.
The main result is `ExteriorAlgebra.gradedAlgebra`, which says that the exterior algebra is a
ℕ-graded algebra.
-/
namespace ExteriorAlgebra
variable {R M : Type*} [CommRing R] [AddCommGroup M] [Module R M]
variable (R M)
open scoped DirectSum
/-- A version of `ExteriorAlgebra.ι` that maps directly into the graded structure. This is
primarily an auxiliary construction used to provide `ExteriorAlgebra.gradedAlgebra`. -/
-- Porting note: protected
protected def GradedAlgebra.ι :
M →ₗ[R] ⨁ i : ℕ, ⋀[R]^i M :=
DirectSum.lof R ℕ (fun i => ⋀[R]^i M) 1 ∘ₗ
(ι R).codRestrict _ fun m => by simpa only [pow_one] using LinearMap.mem_range_self _ m
theorem GradedAlgebra.ι_apply (m : M) :
GradedAlgebra.ι R M m =
DirectSum.of (fun i : ℕ => ⋀[R]^i M) 1
⟨ι R m, by simpa only [pow_one] using LinearMap.mem_range_self _ m⟩ :=
rfl
-- Defining this instance manually, because Lean doesn't seem to be able to synthesize it.
-- Strangely, this problem only appears when we use the abbreviation or notation for the
-- exterior powers.
instance : SetLike.GradedMonoid fun i : ℕ ↦ ⋀[R]^i M :=
Submodule.nat_power_gradedMonoid (LinearMap.range (ι R : M →ₗ[R] ExteriorAlgebra R M))
-- Porting note: Lean needs to be reminded of this instance otherwise it cannot
-- synthesize 0 in the next theorem
attribute [local instance 1100] MulZeroClass.toZero in
theorem GradedAlgebra.ι_sq_zero (m : M) : GradedAlgebra.ι R M m * GradedAlgebra.ι R M m = 0 := by
rw [GradedAlgebra.ι_apply, DirectSum.of_mul_of]
exact DFinsupp.single_eq_zero.mpr (Subtype.ext <| ExteriorAlgebra.ι_sq_zero _)
/-- `ExteriorAlgebra.GradedAlgebra.ι` lifted to exterior algebra. This is
primarily an auxiliary construction used to provide `ExteriorAlgebra.gradedAlgebra`. -/
def GradedAlgebra.liftι :
ExteriorAlgebra R M →ₐ[R] ⨁ i : ℕ, ⋀[R]^i M :=
lift R ⟨by apply GradedAlgebra.ι R M, GradedAlgebra.ι_sq_zero R M⟩
set_option linter.deprecated false in
theorem GradedAlgebra.liftι_eq (i : ℕ) (x : ⋀[R]^i M) :
GradedAlgebra.liftι R M x = DirectSum.of (fun i => ⋀[R]^i M) i x := by
cases' x with x hx
dsimp only [Subtype.coe_mk, DirectSum.lof_eq_of]
-- Porting note: original statement was
-- refine Submodule.pow_induction_on_left' _ (fun r => ?_) (fun x y i hx hy ihx ihy => ?_)
-- (fun m hm i x hx ih => ?_) hx
-- but it created invalid goals
induction hx using Submodule.pow_induction_on_left' with
| algebraMap => simp_rw [AlgHom.commutes, DirectSum.algebraMap_apply]; rfl
-- FIXME: specialized `map_add` to avoid a (whole-declaration) timeout
| add _ _ _ _ _ ihx ihy => simp_rw [AlgHom.map_add, ihx, ihy, ← AddMonoidHom.map_add]; rfl
| mem_mul _ hm _ _ _ ih =>
obtain ⟨_, rfl⟩ := hm
simp_rw [AlgHom.map_mul, ih, GradedAlgebra.liftι, lift_ι_apply, GradedAlgebra.ι_apply R M,
DirectSum.of_mul_of]
exact DirectSum.of_eq_of_gradedMonoid_eq (Sigma.subtype_ext (add_comm _ _) rfl)
/-- The exterior algebra is graded by the powers of the submodule `(ExteriorAlgebra.ι R).range`. -/
instance gradedAlgebra : GradedAlgebra (fun i : ℕ ↦ ⋀[R]^i M) :=
GradedAlgebra.ofAlgHom _
(-- while not necessary, the `by apply` makes this elaborate faster
by apply GradedAlgebra.liftι R M)
-- the proof from here onward is identical to the `TensorAlgebra` case
(by
ext m
dsimp only [LinearMap.comp_apply, AlgHom.toLinearMap_apply, AlgHom.comp_apply,
AlgHom.id_apply, GradedAlgebra.liftι]
rw [lift_ι_apply, GradedAlgebra.ι_apply R M, DirectSum.coeAlgHom_of, Subtype.coe_mk])
(by apply GradedAlgebra.liftι_eq R M)
/-- The union of the images of the maps `ExteriorAlgebra.ιMulti R n` for `n` running through
all natural numbers spans the exterior algebra. -/
lemma ιMulti_span :
Submodule.span R (Set.range fun x : Σ n, (Fin n → M) => ιMulti R x.1 x.2) = ⊤ := by
rw [Submodule.eq_top_iff']
intro x
induction x using DirectSum.Decomposition.inductionOn fun i => ⋀[R]^i M with
| h_zero => exact Submodule.zero_mem _
| h_add _ _ hm hm' => exact Submodule.add_mem _ hm hm'
| h_homogeneous hm =>
let ⟨m, hm⟩ := hm
apply Set.mem_of_mem_of_subset hm
rw [← ιMulti_span_fixedDegree]
refine Submodule.span_mono fun _ hx ↦ ?_
obtain ⟨y, rfl⟩ := hx
exact ⟨⟨_, y⟩, rfl⟩
end ExteriorAlgebra
|
LinearAlgebra\ExteriorAlgebra\OfAlternating.lean | /-
Copyright (c) 2022 Eric Wieser. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Eric Wieser
-/
import Mathlib.LinearAlgebra.CliffordAlgebra.Fold
import Mathlib.LinearAlgebra.ExteriorAlgebra.Basic
/-!
# Extending an alternating map to the exterior algebra
## Main definitions
* `ExteriorAlgebra.liftAlternating`: construct a linear map out of the exterior algebra
given alternating maps (corresponding to maps out of the exterior powers).
* `ExteriorAlgebra.liftAlternatingEquiv`: the above as a linear equivalence
## Main results
* `ExteriorAlgebra.lhom_ext`: linear maps from the exterior algebra agree if they agree on the
exterior powers.
-/
variable {R M N N' : Type*}
variable [CommRing R] [AddCommGroup M] [AddCommGroup N] [AddCommGroup N']
variable [Module R M] [Module R N] [Module R N']
-- This instance can't be found where it's needed if we don't remind lean that it exists.
instance AlternatingMap.instModuleAddCommGroup {ι : Type*} :
Module R (M [⋀^ι]→ₗ[R] N) := by
infer_instance
namespace ExteriorAlgebra
open CliffordAlgebra hiding ι
/-- Build a map out of the exterior algebra given a collection of alternating maps acting on each
exterior power -/
def liftAlternating : (∀ i, M [⋀^Fin i]→ₗ[R] N) →ₗ[R] ExteriorAlgebra R M →ₗ[R] N := by
suffices
(∀ i, M [⋀^Fin i]→ₗ[R] N) →ₗ[R]
ExteriorAlgebra R M →ₗ[R] ∀ i, M [⋀^Fin i]→ₗ[R] N by
refine LinearMap.compr₂ this ?_
refine (LinearEquiv.toLinearMap ?_).comp (LinearMap.proj 0)
exact AlternatingMap.constLinearEquivOfIsEmpty.symm
refine CliffordAlgebra.foldl _ ?_ ?_
· refine
LinearMap.mk₂ R (fun m f i => (f i.succ).curryLeft m) (fun m₁ m₂ f => ?_) (fun c m f => ?_)
(fun m f₁ f₂ => ?_) fun c m f => ?_
all_goals
ext i : 1
simp only [map_smul, map_add, Pi.add_apply, Pi.smul_apply, AlternatingMap.curryLeft_add,
AlternatingMap.curryLeft_smul, map_add, map_smul, LinearMap.add_apply, LinearMap.smul_apply]
· -- when applied twice with the same `m`, this recursive step produces 0
intro m x
ext
simp
@[simp]
theorem liftAlternating_ι (f : ∀ i, M [⋀^Fin i]→ₗ[R] N) (m : M) :
liftAlternating (R := R) (M := M) (N := N) f (ι R m) = f 1 ![m] := by
dsimp [liftAlternating]
rw [foldl_ι, LinearMap.mk₂_apply, AlternatingMap.curryLeft_apply_apply]
congr
-- Porting note: In Lean 3, `congr` could use the `[Subsingleton (Fin 0 → M)]` instance to finish
-- the proof. Here, the instance can be synthesized but `congr` does not use it so the following
-- line is provided.
rw [Matrix.zero_empty]
theorem liftAlternating_ι_mul (f : ∀ i, M [⋀^Fin i]→ₗ[R] N) (m : M)
(x : ExteriorAlgebra R M) :
liftAlternating (R := R) (M := M) (N := N) f (ι R m * x) =
liftAlternating (R := R) (M := M) (N := N) (fun i => (f i.succ).curryLeft m) x := by
dsimp [liftAlternating]
rw [foldl_mul, foldl_ι]
rfl
@[simp]
theorem liftAlternating_one (f : ∀ i, M [⋀^Fin i]→ₗ[R] N) :
liftAlternating (R := R) (M := M) (N := N) f (1 : ExteriorAlgebra R M) = f 0 0 := by
dsimp [liftAlternating]
rw [foldl_one]
@[simp]
theorem liftAlternating_algebraMap (f : ∀ i, M [⋀^Fin i]→ₗ[R] N) (r : R) :
liftAlternating (R := R) (M := M) (N := N) f (algebraMap _ (ExteriorAlgebra R M) r) =
r • f 0 0 := by
rw [Algebra.algebraMap_eq_smul_one, map_smul, liftAlternating_one]
@[simp]
theorem liftAlternating_apply_ιMulti {n : ℕ} (f : ∀ i, M [⋀^Fin i]→ₗ[R] N)
(v : Fin n → M) : liftAlternating (R := R) (M := M) (N := N) f (ιMulti R n v) = f n v := by
rw [ιMulti_apply]
-- Porting note: `v` is generalized automatically so it was removed from the next line
induction' n with n ih generalizing f
· -- Porting note: Lean does not automatically synthesize the instance
-- `[Subsingleton (Fin 0 → M)]` which is needed for `Subsingleton.elim 0 v` on line 114.
letI : Subsingleton (Fin 0 → M) := by infer_instance
rw [List.ofFn_zero, List.prod_nil, liftAlternating_one, Subsingleton.elim 0 v]
· rw [List.ofFn_succ, List.prod_cons, liftAlternating_ι_mul, ih,
AlternatingMap.curryLeft_apply_apply]
congr
exact Matrix.cons_head_tail _
@[simp]
theorem liftAlternating_comp_ιMulti {n : ℕ} (f : ∀ i, M [⋀^Fin i]→ₗ[R] N) :
(liftAlternating (R := R) (M := M) (N := N) f).compAlternatingMap (ιMulti R n) = f n :=
AlternatingMap.ext <| liftAlternating_apply_ιMulti f
@[simp]
theorem liftAlternating_comp (g : N →ₗ[R] N') (f : ∀ i, M [⋀^Fin i]→ₗ[R] N) :
(liftAlternating (R := R) (M := M) (N := N') fun i => g.compAlternatingMap (f i)) =
g ∘ₗ liftAlternating (R := R) (M := M) (N := N) f := by
ext v
rw [LinearMap.comp_apply]
induction' v using CliffordAlgebra.left_induction with r x y hx hy x m hx generalizing f
· rw [liftAlternating_algebraMap, liftAlternating_algebraMap, map_smul,
LinearMap.compAlternatingMap_apply]
· rw [map_add, map_add, map_add, hx, hy]
· rw [liftAlternating_ι_mul, liftAlternating_ι_mul, ← hx]
simp_rw [AlternatingMap.curryLeft_compAlternatingMap]
@[simp]
theorem liftAlternating_ιMulti :
liftAlternating (R := R) (M := M) (N := ExteriorAlgebra R M) (ιMulti R) =
(LinearMap.id : ExteriorAlgebra R M →ₗ[R] ExteriorAlgebra R M) := by
ext v
dsimp
induction' v using CliffordAlgebra.left_induction with r x y hx hy x m hx
· rw [liftAlternating_algebraMap, ιMulti_zero_apply, Algebra.algebraMap_eq_smul_one]
· rw [map_add, hx, hy]
· simp_rw [liftAlternating_ι_mul, ιMulti_succ_curryLeft, liftAlternating_comp,
LinearMap.comp_apply, LinearMap.mulLeft_apply, hx]
/-- `ExteriorAlgebra.liftAlternating` is an equivalence. -/
@[simps apply symm_apply]
def liftAlternatingEquiv : (∀ i, M [⋀^Fin i]→ₗ[R] N) ≃ₗ[R] ExteriorAlgebra R M →ₗ[R] N where
toFun := liftAlternating (R := R)
map_add' := map_add _
map_smul' := map_smul _
invFun F i := F.compAlternatingMap (ιMulti R i)
left_inv f := funext fun i => liftAlternating_comp_ιMulti _
right_inv F :=
(liftAlternating_comp _ _).trans <| by rw [liftAlternating_ιMulti, LinearMap.comp_id]
/-- To show that two linear maps from the exterior algebra agree, it suffices to show they agree on
the exterior powers.
See note [partially-applied ext lemmas] -/
@[ext]
theorem lhom_ext ⦃f g : ExteriorAlgebra R M →ₗ[R] N⦄
(h : ∀ i, f.compAlternatingMap (ιMulti R i) = g.compAlternatingMap (ιMulti R i)) : f = g :=
liftAlternatingEquiv.symm.injective <| funext h
end ExteriorAlgebra
|
LinearAlgebra\FiniteDimensional\Defs.lean | /-
Copyright (c) 2019 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes
-/
import Mathlib.FieldTheory.Finiteness
/-!
# Finite dimensional vector spaces
Definition and basic properties of finite dimensional vector spaces, of their dimensions, and
of linear maps on such spaces.
## Main definitions
Assume `V` is a vector space over a division ring `K`. There are (at least) three equivalent
definitions of finite-dimensionality of `V`:
- it admits a finite basis.
- it is finitely generated.
- it is noetherian, i.e., every subspace is finitely generated.
We introduce a typeclass `FiniteDimensional K V` capturing this property. For ease of transfer of
proof, it is defined using the second point of view, i.e., as `Module.Finite`. However, we prove
that all these points of view are equivalent, with the following lemmas
(in the namespace `FiniteDimensional`):
- `fintypeBasisIndex` states that a finite-dimensional
vector space has a finite basis
- `FiniteDimensional.finBasis` and `FiniteDimensional.finBasisOfFinrankEq`
are bases for finite dimensional vector spaces, where the index type
is `Fin` (in `Mathlib.LinearAlgebra.Dimension.Free`)
- `of_fintype_basis` states that the existence of a basis indexed by a
finite type implies finite-dimensionality
- `of_finite_basis` states that the existence of a basis indexed by a
finite set implies finite-dimensionality
- `IsNoetherian.iff_fg` states that the space is finite-dimensional if and only if
it is noetherian (in `Mathlib.FieldTheory.Finiteness`)
We make use of `finrank`, the dimension of a finite dimensional space, returning a `Nat`, as
opposed to `Module.rank`, which returns a `Cardinal`. When the space has infinite dimension, its
`finrank` is by convention set to `0`. `finrank` is not defined using `FiniteDimensional`.
For basic results that do not need the `FiniteDimensional` class, import
`Mathlib.LinearAlgebra.Finrank`.
Preservation of finite-dimensionality and formulas for the dimension are given for
- submodules (`FiniteDimensional.finiteDimensional_submodule`)
- quotients (for the dimension of a quotient, see `Submodule.finrank_quotient_add_finrank` in
`Mathlib.LinearAlgebra.FiniteDimensional`)
- linear equivs, in `LinearEquiv.finiteDimensional`
- image under a linear map (the rank-nullity formula is in `LinearMap.finrank_range_add_finrank_ker`
in `Mathlib.LinearAlgebra.FiniteDimensional`)
Basic properties of linear maps of a finite-dimensional vector space are given. Notably, the
equivalence of injectivity and surjectivity is proved in `LinearMap.injective_iff_surjective`,
and the equivalence between left-inverse and right-inverse in `LinearMap.mul_eq_one_comm`
and `LinearMap.comp_eq_id_comm`.
## Implementation notes
Most results are deduced from the corresponding results for the general dimension (as a cardinal),
in `Mathlib.LinearAlgebra.Dimension`. Not all results have been ported yet.
You should not assume that there has been any effort to state lemmas as generally as possible.
Plenty of the results hold for general fg modules or notherian modules, and they can be found in
`Mathlib.LinearAlgebra.FreeModule.Finite.Rank` and `Mathlib.RingTheory.Noetherian`.
-/
universe u v v' w
open Cardinal Submodule Module Function
/-- `FiniteDimensional` vector spaces are defined to be finite modules.
Use `FiniteDimensional.of_fintype_basis` to prove finite dimension from another definition. -/
abbrev FiniteDimensional (K V : Type*) [DivisionRing K] [AddCommGroup V] [Module K V] :=
Module.Finite K V
variable {K : Type u} {V : Type v}
namespace FiniteDimensional
open IsNoetherian
section DivisionRing
variable [DivisionRing K] [AddCommGroup V] [Module K V] {V₂ : Type v'} [AddCommGroup V₂]
[Module K V₂]
/-- If the codomain of an injective linear map is finite dimensional, the domain must be as well. -/
theorem of_injective (f : V →ₗ[K] V₂) (w : Function.Injective f) [FiniteDimensional K V₂] :
FiniteDimensional K V :=
have : IsNoetherian K V₂ := IsNoetherian.iff_fg.mpr ‹_›
Module.Finite.of_injective f w
/-- If the domain of a surjective linear map is finite dimensional, the codomain must be as well. -/
theorem of_surjective (f : V →ₗ[K] V₂) (w : Function.Surjective f) [FiniteDimensional K V] :
FiniteDimensional K V₂ :=
Module.Finite.of_surjective f w
variable (K V)
instance finiteDimensional_pi {ι : Type*} [Finite ι] : FiniteDimensional K (ι → K) :=
Finite.pi
instance finiteDimensional_pi' {ι : Type*} [Finite ι] (M : ι → Type*) [∀ i, AddCommGroup (M i)]
[∀ i, Module K (M i)] [∀ i, FiniteDimensional K (M i)] : FiniteDimensional K (∀ i, M i) :=
Finite.pi
/-- A finite dimensional vector space over a finite field is finite -/
noncomputable def fintypeOfFintype [Fintype K] [FiniteDimensional K V] : Fintype V :=
Module.fintypeOfFintype (@finsetBasis K V _ _ _ (iff_fg.2 inferInstance))
theorem finite_of_finite [Finite K] [FiniteDimensional K V] : Finite V := by
cases nonempty_fintype K
haveI := fintypeOfFintype K V
infer_instance
variable {K V}
/-- If a vector space has a finite basis, then it is finite-dimensional. -/
theorem of_fintype_basis {ι : Type w} [Finite ι] (h : Basis ι K V) : FiniteDimensional K V :=
Module.Finite.of_basis h
/-- If a vector space is `FiniteDimensional`, all bases are indexed by a finite type -/
noncomputable def fintypeBasisIndex {ι : Type*} [FiniteDimensional K V] (b : Basis ι K V) :
Fintype ι :=
@Fintype.ofFinite _ (Module.Finite.finite_basis b)
/-- If a vector space is `FiniteDimensional`, `Basis.ofVectorSpace` is indexed by
a finite type. -/
noncomputable instance [FiniteDimensional K V] : Fintype (Basis.ofVectorSpaceIndex K V) := by
letI : IsNoetherian K V := IsNoetherian.iff_fg.2 inferInstance
infer_instance
/-- If a vector space has a basis indexed by elements of a finite set, then it is
finite-dimensional. -/
theorem of_finite_basis {ι : Type w} {s : Set ι} (h : Basis s K V) (hs : Set.Finite s) :
FiniteDimensional K V :=
haveI := hs.fintype
of_fintype_basis h
/-- A subspace of a finite-dimensional space is also finite-dimensional. -/
instance finiteDimensional_submodule [FiniteDimensional K V] (S : Submodule K V) :
FiniteDimensional K S := by
letI : IsNoetherian K V := iff_fg.2 ?_
· exact
iff_fg.1
(IsNoetherian.iff_rank_lt_aleph0.2
(lt_of_le_of_lt (rank_submodule_le _) (_root_.rank_lt_aleph0 K V)))
· infer_instance
/-- A quotient of a finite-dimensional space is also finite-dimensional. -/
instance finiteDimensional_quotient [FiniteDimensional K V] (S : Submodule K V) :
FiniteDimensional K (V ⧸ S) :=
Module.Finite.quotient K S
variable (K V)
/-- In a finite-dimensional space, its dimension (seen as a cardinal) coincides with its
`finrank`. This is a copy of `finrank_eq_rank _ _` which creates easier typeclass searches. -/
theorem finrank_eq_rank' [FiniteDimensional K V] : (finrank K V : Cardinal.{v}) = Module.rank K V :=
finrank_eq_rank _ _
variable {K V}
theorem finrank_of_infinite_dimensional (h : ¬FiniteDimensional K V) : finrank K V = 0 :=
FiniteDimensional.finrank_of_not_finite h
theorem of_finrank_pos (h : 0 < finrank K V) : FiniteDimensional K V :=
Module.finite_of_finrank_pos h
theorem of_finrank_eq_succ {n : ℕ} (hn : finrank K V = n.succ) :
FiniteDimensional K V :=
Module.finite_of_finrank_eq_succ hn
/-- We can infer `FiniteDimensional K V` in the presence of `[Fact (finrank K V = n + 1)]`. Declare
this as a local instance where needed. -/
theorem of_fact_finrank_eq_succ (n : ℕ) [hn : Fact (finrank K V = n + 1)] :
FiniteDimensional K V :=
of_finrank_eq_succ hn.out
theorem finiteDimensional_iff_of_rank_eq_nsmul {W} [AddCommGroup W] [Module K W] {n : ℕ}
(hn : n ≠ 0) (hVW : Module.rank K V = n • Module.rank K W) :
FiniteDimensional K V ↔ FiniteDimensional K W :=
Module.finite_iff_of_rank_eq_nsmul hn hVW
/-- If a vector space is finite-dimensional, then the cardinality of any basis is equal to its
`finrank`. -/
theorem finrank_eq_card_basis' [FiniteDimensional K V] {ι : Type w} (h : Basis ι K V) :
(finrank K V : Cardinal.{w}) = #ι :=
Module.mk_finrank_eq_card_basis h
theorem _root_.LinearIndependent.lt_aleph0_of_finiteDimensional {ι : Type w} [FiniteDimensional K V]
{v : ι → V} (h : LinearIndependent K v) : #ι < ℵ₀ :=
h.lt_aleph0_of_finite
@[deprecated (since := "2023-12-27")]
alias lt_aleph0_of_linearIndependent := LinearIndependent.lt_aleph0_of_finiteDimensional
/-- If a submodule has maximal dimension in a finite dimensional space, then it is equal to the
whole space. -/
theorem _root_.Submodule.eq_top_of_finrank_eq [FiniteDimensional K V] {S : Submodule K V}
(h : finrank K S = finrank K V) : S = ⊤ := by
haveI : IsNoetherian K V := iff_fg.2 inferInstance
set bS := Basis.ofVectorSpace K S with bS_eq
have : LinearIndependent K ((↑) : ((↑) '' Basis.ofVectorSpaceIndex K S : Set V) → V) :=
LinearIndependent.image_subtype (f := Submodule.subtype S)
(by simpa [bS] using bS.linearIndependent) (by simp)
set b := Basis.extend this with b_eq
-- Porting note: `letI` now uses `this` so we need to give different names
letI i1 : Fintype (this.extend _) :=
(LinearIndependent.set_finite_of_isNoetherian (by simpa [b] using b.linearIndependent)).fintype
letI i2 : Fintype (((↑) : S → V) '' Basis.ofVectorSpaceIndex K S) :=
(LinearIndependent.set_finite_of_isNoetherian this).fintype
letI i3 : Fintype (Basis.ofVectorSpaceIndex K S) :=
(LinearIndependent.set_finite_of_isNoetherian
(by simpa [bS] using bS.linearIndependent)).fintype
have : (↑) '' Basis.ofVectorSpaceIndex K S = this.extend (Set.subset_univ _) :=
Set.eq_of_subset_of_card_le (this.subset_extend _)
(by
rw [Set.card_image_of_injective _ Subtype.coe_injective, ← finrank_eq_card_basis bS, ←
finrank_eq_card_basis b, h])
rw [← b.span_eq, b_eq, Basis.coe_extend, Subtype.range_coe, ← this, ← Submodule.coeSubtype,
span_image]
have := bS.span_eq
rw [bS_eq, Basis.coe_ofVectorSpace, Subtype.range_coe] at this
rw [this, Submodule.map_top (Submodule.subtype S), range_subtype]
variable (K)
instance finiteDimensional_self : FiniteDimensional K K := inferInstance
/-- The submodule generated by a finite set is finite-dimensional. -/
theorem span_of_finite {A : Set V} (hA : Set.Finite A) : FiniteDimensional K (Submodule.span K A) :=
Module.Finite.span_of_finite K hA
/-- The submodule generated by a single element is finite-dimensional. -/
instance span_singleton (x : V) : FiniteDimensional K (K ∙ x) :=
Module.Finite.span_singleton K x
/-- The submodule generated by a finset is finite-dimensional. -/
instance span_finset (s : Finset V) : FiniteDimensional K (span K (s : Set V)) :=
Module.Finite.span_finset K s
/-- Pushforwards of finite-dimensional submodules are finite-dimensional. -/
instance (f : V →ₗ[K] V₂) (p : Submodule K V) [FiniteDimensional K p] :
FiniteDimensional K (p.map f) :=
Module.Finite.map _ _
variable {K}
section
open Finset
section
variable {L : Type*} [LinearOrderedField L]
variable {W : Type v} [AddCommGroup W] [Module L W]
/-- A slight strengthening of `exists_nontrivial_relation_sum_zero_of_rank_succ_lt_card`
available when working over an ordered field:
we can ensure a positive coefficient, not just a nonzero coefficient.
-/
theorem exists_relation_sum_zero_pos_coefficient_of_finrank_succ_lt_card [FiniteDimensional L W]
{t : Finset W} (h : finrank L W + 1 < t.card) :
∃ f : W → L, ∑ e ∈ t, f e • e = 0 ∧ ∑ e ∈ t, f e = 0 ∧ ∃ x ∈ t, 0 < f x := by
obtain ⟨f, sum, total, nonzero⟩ :=
Module.exists_nontrivial_relation_sum_zero_of_finrank_succ_lt_card h
exact ⟨f, sum, total, exists_pos_of_sum_zero_of_exists_nonzero f total nonzero⟩
end
end
/-- In a vector space with dimension 1, each set {v} is a basis for `v ≠ 0`. -/
@[simps repr_apply]
noncomputable def basisSingleton (ι : Type*) [Unique ι] (h : finrank K V = 1) (v : V)
(hv : v ≠ 0) : Basis ι K V :=
let b := FiniteDimensional.basisUnique ι h
let h : b.repr v default ≠ 0 := mt FiniteDimensional.basisUnique_repr_eq_zero_iff.mp hv
Basis.ofRepr
{ toFun := fun w => Finsupp.single default (b.repr w default / b.repr v default)
invFun := fun f => f default • v
map_add' := by simp [add_div]
map_smul' := by simp [mul_div]
left_inv := fun w => by
apply_fun b.repr using b.repr.toEquiv.injective
apply_fun Equiv.finsuppUnique
simp only [LinearEquiv.map_smulₛₗ, Finsupp.coe_smul, Finsupp.single_eq_same,
smul_eq_mul, Pi.smul_apply, Equiv.finsuppUnique_apply]
exact div_mul_cancel₀ _ h
right_inv := fun f => by
ext
simp only [LinearEquiv.map_smulₛₗ, Finsupp.coe_smul, Finsupp.single_eq_same,
RingHom.id_apply, smul_eq_mul, Pi.smul_apply]
exact mul_div_cancel_right₀ _ h }
@[simp]
theorem basisSingleton_apply (ι : Type*) [Unique ι] (h : finrank K V = 1) (v : V) (hv : v ≠ 0)
(i : ι) : basisSingleton ι h v hv i = v := by
cases Unique.uniq ‹Unique ι› i
simp [basisSingleton]
@[simp]
theorem range_basisSingleton (ι : Type*) [Unique ι] (h : finrank K V = 1) (v : V) (hv : v ≠ 0) :
Set.range (basisSingleton ι h v hv) = {v} := by rw [Set.range_unique, basisSingleton_apply]
end DivisionRing
section Tower
variable (F K A : Type*) [DivisionRing F] [DivisionRing K] [AddCommGroup A]
variable [Module F K] [Module K A] [Module F A] [IsScalarTower F K A]
theorem trans [FiniteDimensional F K] [FiniteDimensional K A] : FiniteDimensional F A :=
Module.Finite.trans K A
end Tower
end FiniteDimensional
section ZeroRank
variable [DivisionRing K] [AddCommGroup V] [Module K V]
open FiniteDimensional
theorem FiniteDimensional.of_rank_eq_nat {n : ℕ} (h : Module.rank K V = n) :
FiniteDimensional K V :=
Module.finite_of_rank_eq_nat h
@[deprecated (since := "2024-02-02")]
alias finiteDimensional_of_rank_eq_nat := FiniteDimensional.of_rank_eq_nat
theorem FiniteDimensional.of_rank_eq_zero (h : Module.rank K V = 0) : FiniteDimensional K V :=
Module.finite_of_rank_eq_zero h
@[deprecated (since := "2024-02-02")]
alias finiteDimensional_of_rank_eq_zero := FiniteDimensional.of_rank_eq_zero
theorem FiniteDimensional.of_rank_eq_one (h : Module.rank K V = 1) : FiniteDimensional K V :=
Module.finite_of_rank_eq_one h
@[deprecated (since := "2024-02-02")]
alias finiteDimensional_of_rank_eq_one := FiniteDimensional.of_rank_eq_one
variable (K V)
instance finiteDimensional_bot : FiniteDimensional K (⊥ : Submodule K V) :=
of_rank_eq_zero <| by simp
variable {K V}
end ZeroRank
namespace Submodule
open IsNoetherian FiniteDimensional
section DivisionRing
variable [DivisionRing K] [AddCommGroup V] [Module K V]
/-- A submodule is finitely generated if and only if it is finite-dimensional -/
theorem fg_iff_finiteDimensional (s : Submodule K V) : s.FG ↔ FiniteDimensional K s :=
⟨fun h => Module.finite_def.2 <| (fg_top s).2 h, fun h => (fg_top s).1 <| Module.finite_def.1 h⟩
/-- A submodule contained in a finite-dimensional submodule is
finite-dimensional. -/
theorem finiteDimensional_of_le {S₁ S₂ : Submodule K V} [FiniteDimensional K S₂] (h : S₁ ≤ S₂) :
FiniteDimensional K S₁ :=
haveI : IsNoetherian K S₂ := iff_fg.2 inferInstance
iff_fg.1
(IsNoetherian.iff_rank_lt_aleph0.2
(lt_of_le_of_lt (rank_le_of_submodule _ _ h) (rank_lt_aleph0 K S₂)))
/-- The inf of two submodules, the first finite-dimensional, is
finite-dimensional. -/
instance finiteDimensional_inf_left (S₁ S₂ : Submodule K V) [FiniteDimensional K S₁] :
FiniteDimensional K (S₁ ⊓ S₂ : Submodule K V) :=
finiteDimensional_of_le inf_le_left
/-- The inf of two submodules, the second finite-dimensional, is
finite-dimensional. -/
instance finiteDimensional_inf_right (S₁ S₂ : Submodule K V) [FiniteDimensional K S₂] :
FiniteDimensional K (S₁ ⊓ S₂ : Submodule K V) :=
finiteDimensional_of_le inf_le_right
/-- The sup of two finite-dimensional submodules is
finite-dimensional. -/
instance finiteDimensional_sup (S₁ S₂ : Submodule K V) [h₁ : FiniteDimensional K S₁]
[h₂ : FiniteDimensional K S₂] : FiniteDimensional K (S₁ ⊔ S₂ : Submodule K V) := by
unfold FiniteDimensional at *
rw [finite_def] at *
exact (fg_top _).2 (((fg_top S₁).1 h₁).sup ((fg_top S₂).1 h₂))
/-- The submodule generated by a finite supremum of finite dimensional submodules is
finite-dimensional.
Note that strictly this only needs `∀ i ∈ s, FiniteDimensional K (S i)`, but that doesn't
work well with typeclass search. -/
instance finiteDimensional_finset_sup {ι : Type*} (s : Finset ι) (S : ι → Submodule K V)
[∀ i, FiniteDimensional K (S i)] : FiniteDimensional K (s.sup S : Submodule K V) := by
refine
@Finset.sup_induction _ _ _ _ s S (fun i => FiniteDimensional K ↑i) (finiteDimensional_bot K V)
?_ fun i _ => by infer_instance
intro S₁ hS₁ S₂ hS₂
exact Submodule.finiteDimensional_sup S₁ S₂
/-- The submodule generated by a supremum of finite dimensional submodules, indexed by a finite
sort is finite-dimensional. -/
instance finiteDimensional_iSup {ι : Sort*} [Finite ι] (S : ι → Submodule K V)
[∀ i, FiniteDimensional K (S i)] : FiniteDimensional K ↑(⨆ i, S i) := by
cases nonempty_fintype (PLift ι)
rw [← iSup_plift_down, ← Finset.sup_univ_eq_iSup]
exact Submodule.finiteDimensional_finset_sup _ _
end DivisionRing
end Submodule
namespace LinearEquiv
open FiniteDimensional
variable [DivisionRing K] [AddCommGroup V] [Module K V] {V₂ : Type v'} [AddCommGroup V₂]
[Module K V₂]
/-- Finite dimensionality is preserved under linear equivalence. -/
protected theorem finiteDimensional (f : V ≃ₗ[K] V₂) [FiniteDimensional K V] :
FiniteDimensional K V₂ :=
Module.Finite.equiv f
variable {R M M₂ : Type*} [Ring R] [AddCommGroup M] [AddCommGroup M₂]
variable [Module R M] [Module R M₂]
end LinearEquiv
section
variable [DivisionRing K] [AddCommGroup V] [Module K V]
instance finiteDimensional_finsupp {ι : Type*} [Finite ι] [FiniteDimensional K V] :
FiniteDimensional K (ι →₀ V) :=
Module.Finite.finsupp
end
namespace FiniteDimensional
section DivisionRing
variable [DivisionRing K] [AddCommGroup V] [Module K V] {V₂ : Type v'} [AddCommGroup V₂]
[Module K V₂]
/-- If a submodule is contained in a finite-dimensional
submodule with the same or smaller dimension, they are equal. -/
theorem eq_of_le_of_finrank_le {S₁ S₂ : Submodule K V} [FiniteDimensional K S₂] (hle : S₁ ≤ S₂)
(hd : finrank K S₂ ≤ finrank K S₁) : S₁ = S₂ := by
rw [← LinearEquiv.finrank_eq (Submodule.comapSubtypeEquivOfLe hle)] at hd
exact le_antisymm hle (Submodule.comap_subtype_eq_top.1
(eq_top_of_finrank_eq (le_antisymm (comap (Submodule.subtype S₂) S₁).finrank_le hd)))
/-- If a submodule is contained in a finite-dimensional
submodule with the same dimension, they are equal. -/
theorem eq_of_le_of_finrank_eq {S₁ S₂ : Submodule K V} [FiniteDimensional K S₂] (hle : S₁ ≤ S₂)
(hd : finrank K S₁ = finrank K S₂) : S₁ = S₂ :=
eq_of_le_of_finrank_le hle hd.ge
section Subalgebra
variable {K L : Type*} [Field K] [Ring L] [Algebra K L] {F E : Subalgebra K L}
[hfin : FiniteDimensional K E]
/-- If a subalgebra is contained in a finite-dimensional
subalgebra with the same or smaller dimension, they are equal. -/
theorem _root_.Subalgebra.eq_of_le_of_finrank_le (h_le : F ≤ E)
(h_finrank : finrank K E ≤ finrank K F) : F = E :=
haveI : Module.Finite K (Subalgebra.toSubmodule E) := hfin
Subalgebra.toSubmodule_injective <| FiniteDimensional.eq_of_le_of_finrank_le h_le h_finrank
/-- If a subalgebra is contained in a finite-dimensional
subalgebra with the same dimension, they are equal. -/
theorem _root_.Subalgebra.eq_of_le_of_finrank_eq (h_le : F ≤ E)
(h_finrank : finrank K F = finrank K E) : F = E :=
Subalgebra.eq_of_le_of_finrank_le h_le h_finrank.ge
end Subalgebra
end DivisionRing
end FiniteDimensional
namespace LinearMap
open FiniteDimensional
section DivisionRing
variable [DivisionRing K] [AddCommGroup V] [Module K V] {V₂ : Type v'} [AddCommGroup V₂]
[Module K V₂]
/-- On a finite-dimensional space, an injective linear map is surjective. -/
theorem surjective_of_injective [FiniteDimensional K V] {f : V →ₗ[K] V} (hinj : Injective f) :
Surjective f := by
have h := rank_range_of_injective _ hinj
rw [← finrank_eq_rank, ← finrank_eq_rank, natCast_inj] at h
exact range_eq_top.1 (eq_top_of_finrank_eq h)
/-- The image under an onto linear map of a finite-dimensional space is also finite-dimensional. -/
theorem finiteDimensional_of_surjective [FiniteDimensional K V] (f : V →ₗ[K] V₂)
(hf : LinearMap.range f = ⊤) : FiniteDimensional K V₂ :=
Module.Finite.of_surjective f <| range_eq_top.1 hf
/-- The range of a linear map defined on a finite-dimensional space is also finite-dimensional. -/
instance finiteDimensional_range [FiniteDimensional K V] (f : V →ₗ[K] V₂) :
FiniteDimensional K (LinearMap.range f) :=
Module.Finite.range f
/-- On a finite-dimensional space, a linear map is injective if and only if it is surjective. -/
theorem injective_iff_surjective [FiniteDimensional K V] {f : V →ₗ[K] V} :
Injective f ↔ Surjective f :=
⟨surjective_of_injective, fun hsurj =>
let ⟨g, hg⟩ := f.exists_rightInverse_of_surjective (range_eq_top.2 hsurj)
have : Function.RightInverse g f := LinearMap.ext_iff.1 hg
(leftInverse_of_surjective_of_rightInverse (surjective_of_injective this.injective)
this).injective⟩
lemma injOn_iff_surjOn {p : Submodule K V} [FiniteDimensional K p]
{f : V →ₗ[K] V} (h : ∀ x ∈ p, f x ∈ p) :
Set.InjOn f p ↔ Set.SurjOn f p p := by
rw [Set.injOn_iff_injective, ← Set.MapsTo.restrict_surjective_iff h]
change Injective (f.domRestrict p) ↔ Surjective (f.restrict h)
simp [disjoint_iff, ← injective_iff_surjective]
theorem ker_eq_bot_iff_range_eq_top [FiniteDimensional K V] {f : V →ₗ[K] V} :
LinearMap.ker f = ⊥ ↔ LinearMap.range f = ⊤ := by
rw [range_eq_top, ker_eq_bot, injective_iff_surjective]
/-- In a finite-dimensional space, if linear maps are inverse to each other on one side then they
are also inverse to each other on the other side. -/
theorem mul_eq_one_of_mul_eq_one [FiniteDimensional K V] {f g : V →ₗ[K] V} (hfg : f * g = 1) :
g * f = 1 := by
have ginj : Injective g :=
HasLeftInverse.injective ⟨f, fun x => show (f * g) x = (1 : V →ₗ[K] V) x by rw [hfg]⟩
let ⟨i, hi⟩ :=
g.exists_rightInverse_of_surjective (range_eq_top.2 (injective_iff_surjective.1 ginj))
have : f * (g * i) = f * 1 := congr_arg _ hi
rw [← mul_assoc, hfg, one_mul, mul_one] at this; rwa [← this]
/-- In a finite-dimensional space, linear maps are inverse to each other on one side if and only if
they are inverse to each other on the other side. -/
theorem mul_eq_one_comm [FiniteDimensional K V] {f g : V →ₗ[K] V} : f * g = 1 ↔ g * f = 1 :=
⟨mul_eq_one_of_mul_eq_one, mul_eq_one_of_mul_eq_one⟩
/-- In a finite-dimensional space, linear maps are inverse to each other on one side if and only if
they are inverse to each other on the other side. -/
theorem comp_eq_id_comm [FiniteDimensional K V] {f g : V →ₗ[K] V} : f.comp g = id ↔ g.comp f = id :=
mul_eq_one_comm
theorem comap_eq_sup_ker_of_disjoint {p : Submodule K V} [FiniteDimensional K p] {f : V →ₗ[K] V}
(h : ∀ x ∈ p, f x ∈ p) (h' : Disjoint p (ker f)) :
p.comap f = p ⊔ ker f := by
refine le_antisymm (fun x hx ↦ ?_) (sup_le_iff.mpr ⟨h, ker_le_comap _⟩)
obtain ⟨⟨y, hy⟩, hxy⟩ :=
surjective_of_injective ((injective_restrict_iff_disjoint h).mpr h') ⟨f x, hx⟩
replace hxy : f y = f x := by simpa [Subtype.ext_iff] using hxy
exact Submodule.mem_sup.mpr ⟨y, hy, x - y, by simp [hxy], add_sub_cancel y x⟩
theorem ker_comp_eq_of_commute_of_disjoint_ker [FiniteDimensional K V] {f g : V →ₗ[K] V}
(h : Commute f g) (h' : Disjoint (ker f) (ker g)) :
ker (f ∘ₗ g) = ker f ⊔ ker g := by
suffices ∀ x, f x = 0 → f (g x) = 0 by rw [ker_comp, comap_eq_sup_ker_of_disjoint _ h']; simpa
intro x hx
rw [← comp_apply, ← mul_eq_comp, h.eq, mul_apply, hx, _root_.map_zero]
theorem ker_noncommProd_eq_of_supIndep_ker [FiniteDimensional K V] {ι : Type*} {f : ι → V →ₗ[K] V}
(s : Finset ι) (comm) (h : s.SupIndep fun i ↦ ker (f i)) :
ker (s.noncommProd f comm) = ⨆ i ∈ s, ker (f i) := by
classical
induction' s using Finset.induction_on with i s hi ih
· set_option tactic.skipAssignedInstances false in
simpa using LinearMap.ker_id
replace ih : ker (Finset.noncommProd s f <| Set.Pairwise.mono (s.subset_insert i) comm) =
⨆ x ∈ s, ker (f x) := ih _ (h.subset (s.subset_insert i))
rw [Finset.noncommProd_insert_of_not_mem _ _ _ _ hi, mul_eq_comp,
ker_comp_eq_of_commute_of_disjoint_ker]
· simp_rw [Finset.mem_insert_coe, iSup_insert, Finset.mem_coe, ih]
· exact s.noncommProd_commute _ _ _ fun j hj ↦
comm (s.mem_insert_self i) (Finset.mem_insert_of_mem hj) (by aesop)
· replace h := Finset.supIndep_iff_disjoint_erase.mp h i (s.mem_insert_self i)
simpa [ih, hi, Finset.sup_eq_iSup] using h
end DivisionRing
end LinearMap
namespace LinearEquiv
open FiniteDimensional
variable [DivisionRing K] [AddCommGroup V] [Module K V]
variable [FiniteDimensional K V]
/-- The linear equivalence corresponding to an injective endomorphism. -/
noncomputable def ofInjectiveEndo (f : V →ₗ[K] V) (h_inj : Injective f) : V ≃ₗ[K] V :=
LinearEquiv.ofBijective f ⟨h_inj, LinearMap.injective_iff_surjective.mp h_inj⟩
@[simp]
theorem coe_ofInjectiveEndo (f : V →ₗ[K] V) (h_inj : Injective f) :
⇑(ofInjectiveEndo f h_inj) = f :=
rfl
@[simp]
theorem ofInjectiveEndo_right_inv (f : V →ₗ[K] V) (h_inj : Injective f) :
f * (ofInjectiveEndo f h_inj).symm = 1 :=
LinearMap.ext <| (ofInjectiveEndo f h_inj).apply_symm_apply
@[simp]
theorem ofInjectiveEndo_left_inv (f : V →ₗ[K] V) (h_inj : Injective f) :
((ofInjectiveEndo f h_inj).symm : V →ₗ[K] V) * f = 1 :=
LinearMap.ext <| (ofInjectiveEndo f h_inj).symm_apply_apply
end LinearEquiv
namespace LinearMap
variable [DivisionRing K] [AddCommGroup V] [Module K V]
theorem isUnit_iff_ker_eq_bot [FiniteDimensional K V] (f : V →ₗ[K] V) :
IsUnit f ↔ (LinearMap.ker f) = ⊥ := by
constructor
· rintro ⟨u, rfl⟩
exact LinearMap.ker_eq_bot_of_inverse u.inv_mul
· intro h_inj
rw [ker_eq_bot] at h_inj
exact ⟨⟨f, (LinearEquiv.ofInjectiveEndo f h_inj).symm.toLinearMap,
LinearEquiv.ofInjectiveEndo_right_inv f h_inj, LinearEquiv.ofInjectiveEndo_left_inv f h_inj⟩,
rfl⟩
theorem isUnit_iff_range_eq_top [FiniteDimensional K V] (f : V →ₗ[K] V) :
IsUnit f ↔ (LinearMap.range f) = ⊤ := by
rw [isUnit_iff_ker_eq_bot, ker_eq_bot_iff_range_eq_top]
end LinearMap
open Module FiniteDimensional
section
variable [DivisionRing K] [AddCommGroup V] [Module K V]
theorem finrank_zero_iff_forall_zero [FiniteDimensional K V] : finrank K V = 0 ↔ ∀ x : V, x = 0 :=
FiniteDimensional.finrank_zero_iff.trans (subsingleton_iff_forall_eq 0)
/-- If `ι` is an empty type and `V` is zero-dimensional, there is a unique `ι`-indexed basis. -/
noncomputable def basisOfFinrankZero [FiniteDimensional K V] {ι : Type*} [IsEmpty ι]
(hV : finrank K V = 0) : Basis ι K V :=
haveI : Subsingleton V := finrank_zero_iff.1 hV
Basis.empty _
end
section
lemma FiniteDimensional.exists_mul_eq_one (F : Type*) {K : Type*} [Field F] [Ring K] [IsDomain K]
[Algebra F K] [FiniteDimensional F K] {x : K} (H : x ≠ 0) : ∃ y, x * y = 1 := by
have : Function.Surjective (LinearMap.mulLeft F x) :=
LinearMap.injective_iff_surjective.1 fun y z => ((mul_right_inj' H).1 : x * y = x * z → y = z)
exact this 1
/-- A domain that is module-finite as an algebra over a field is a division ring. -/
noncomputable def divisionRingOfFiniteDimensional (F K : Type*) [Field F] [Ring K] [IsDomain K]
[Algebra F K] [FiniteDimensional F K] : DivisionRing K where
__ := ‹IsDomain K›
inv x :=
letI := Classical.decEq K
if H : x = 0 then 0 else Classical.choose <| FiniteDimensional.exists_mul_eq_one F H
mul_inv_cancel x hx := show x * dite _ (h := _) _ = _ by
rw [dif_neg hx]
exact (Classical.choose_spec (FiniteDimensional.exists_mul_eq_one F hx):)
inv_zero := dif_pos rfl
nnqsmul := _
qsmul := _
/-- An integral domain that is module-finite as an algebra over a field is a field. -/
noncomputable def fieldOfFiniteDimensional (F K : Type*) [Field F] [h : CommRing K] [IsDomain K]
[Algebra F K] [FiniteDimensional F K] : Field K :=
{ divisionRingOfFiniteDimensional F K with
toCommRing := h }
end
namespace Submodule
section DivisionRing
variable [DivisionRing K] [AddCommGroup V] [Module K V] {V₂ : Type v'} [AddCommGroup V₂]
[Module K V₂]
theorem finrank_mono [FiniteDimensional K V] : Monotone fun s : Submodule K V => finrank K s :=
fun _ _ => finrank_le_finrank_of_le
end DivisionRing
end Submodule
section DivisionRing
variable [DivisionRing K] [AddCommGroup V] [Module K V]
section Span
open Submodule
theorem finrank_span_singleton {v : V} (hv : v ≠ 0) : finrank K (K ∙ v) = 1 := by
apply le_antisymm
· exact finrank_span_le_card ({v} : Set V)
· rw [Nat.succ_le_iff, finrank_pos_iff]
use ⟨v, mem_span_singleton_self v⟩, 0
simp [hv]
/-- In a one-dimensional space, any vector is a multiple of any nonzero vector -/
lemma exists_smul_eq_of_finrank_eq_one
(h : finrank K V = 1) {x : V} (hx : x ≠ 0) (y : V) :
∃ (c : K), c • x = y := by
have : Submodule.span K {x} = ⊤ := by
have : FiniteDimensional K V := .of_finrank_eq_succ h
apply eq_top_of_finrank_eq
rw [h]
exact finrank_span_singleton hx
have : y ∈ Submodule.span K {x} := by rw [this]; exact mem_top
exact mem_span_singleton.1 this
theorem Set.finrank_mono [FiniteDimensional K V] {s t : Set V} (h : s ⊆ t) :
s.finrank K ≤ t.finrank K :=
Submodule.finrank_mono (span_mono h)
end Span
/-!
We now give characterisations of `finrank K V = 1` and `finrank K V ≤ 1`.
-/
section finrank_eq_one
/-- A vector space with a nonzero vector `v` has dimension 1 iff `v` spans.
-/
theorem finrank_eq_one_iff_of_nonzero (v : V) (nz : v ≠ 0) :
finrank K V = 1 ↔ span K ({v} : Set V) = ⊤ :=
⟨fun h => by simpa using (basisSingleton Unit h v nz).span_eq, fun s =>
finrank_eq_card_basis
(Basis.mk (linearIndependent_singleton nz)
(by
convert s.ge -- Porting note: added `.ge` to make things easier for `convert`
simp))⟩
/-- A module with a nonzero vector `v` has dimension 1 iff every vector is a multiple of `v`.
-/
theorem finrank_eq_one_iff_of_nonzero' (v : V) (nz : v ≠ 0) :
finrank K V = 1 ↔ ∀ w : V, ∃ c : K, c • v = w := by
rw [finrank_eq_one_iff_of_nonzero v nz]
apply span_singleton_eq_top_iff
-- We use the `LinearMap.CompatibleSMul` typeclass here, to encompass two situations:
-- * `A = K`
-- * `[Field K] [Algebra K A] [IsScalarTower K A V] [IsScalarTower K A W]`
theorem surjective_of_nonzero_of_finrank_eq_one {W A : Type*} [Semiring A] [Module A V]
[AddCommGroup W] [Module K W] [Module A W] [LinearMap.CompatibleSMul V W K A]
(h : finrank K W = 1) {f : V →ₗ[A] W} (w : f ≠ 0) : Surjective f := by
change Surjective (f.restrictScalars K)
obtain ⟨v, n⟩ := DFunLike.ne_iff.mp w
intro z
obtain ⟨c, rfl⟩ := (finrank_eq_one_iff_of_nonzero' (f v) n).mp h z
exact ⟨c • v, by simp⟩
end finrank_eq_one
end DivisionRing
section SubalgebraRank
open Module
variable {F E : Type*} [Field F] [Ring E] [Algebra F E]
/-
porting note:
Some of the lemmas in this section can be made faster by adding these short-cut instances
```lean4
instance (S : Subalgebra F E) : AddCommMonoid { x // x ∈ S } := inferInstance
instance (S : Subalgebra F E) : AddCommGroup { x // x ∈ S } := inferInstance
```
However, this approach doesn't scale very well, so we should consider holding off on adding
them until we have no choice.
-/
/-- A `Subalgebra` is `FiniteDimensional` iff it is `FiniteDimensional` as a submodule. -/
theorem Subalgebra.finiteDimensional_toSubmodule {S : Subalgebra F E} :
FiniteDimensional F (Subalgebra.toSubmodule S) ↔ FiniteDimensional F S :=
Iff.rfl
alias ⟨FiniteDimensional.of_subalgebra_toSubmodule, FiniteDimensional.subalgebra_toSubmodule⟩ :=
Subalgebra.finiteDimensional_toSubmodule
instance FiniteDimensional.finiteDimensional_subalgebra [FiniteDimensional F E]
(S : Subalgebra F E) : FiniteDimensional F S :=
FiniteDimensional.of_subalgebra_toSubmodule inferInstance
@[deprecated Subalgebra.finite_bot (since := "2024-04-11")]
theorem Subalgebra.finiteDimensional_bot : FiniteDimensional F (⊥ : Subalgebra F E) :=
Subalgebra.finite_bot
end SubalgebraRank
namespace Module
namespace End
variable [DivisionRing K] [AddCommGroup V] [Module K V]
theorem ker_pow_constant {f : End K V} {k : ℕ}
(h : LinearMap.ker (f ^ k) = LinearMap.ker (f ^ k.succ)) :
∀ m, LinearMap.ker (f ^ k) = LinearMap.ker (f ^ (k + m))
| 0 => by simp
| m + 1 => by
apply le_antisymm
· rw [add_comm, pow_add]
apply LinearMap.ker_le_ker_comp
· rw [ker_pow_constant h m, add_comm m 1, ← add_assoc, pow_add, pow_add f k m,
LinearMap.mul_eq_comp, LinearMap.mul_eq_comp, LinearMap.ker_comp, LinearMap.ker_comp, h,
Nat.add_one]
end End
end Module
|
LinearAlgebra\FreeModule\Basic.lean | /-
Copyright (c) 2021 Riccardo Brasca. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Riccardo Brasca
-/
import Mathlib.Data.Finsupp.Fintype
import Mathlib.LinearAlgebra.TensorProduct.Basis
/-!
# Free modules
We introduce a class `Module.Free R M`, for `R` a `Semiring` and `M` an `R`-module and we provide
several basic instances for this class.
Use `Finsupp.total_id_surjective` to prove that any module is the quotient of a free module.
## Main definition
* `Module.Free R M` : the class of free `R`-modules.
-/
universe u v w z
variable {ι : Type*} (R : Type u) (M : Type v) (N : Type z)
open TensorProduct DirectSum
section Basic
variable [Semiring R] [AddCommMonoid M] [Module R M]
/-- `Module.Free R M` is the statement that the `R`-module `M` is free. -/
class Module.Free : Prop where
exists_basis : Nonempty <| (I : Type v) × Basis I R M
/-- If `M` fits in universe `w`, then freeness is equivalent to existence of a basis in that
universe.
Note that if `M` does not fit in `w`, the reverse direction of this implication is still true as
`Module.Free.of_basis`. -/
theorem Module.free_def [Small.{w,v} M] :
Module.Free R M ↔ ∃ I : Type w, Nonempty (Basis I R M) :=
⟨fun h =>
⟨Shrink (Set.range h.exists_basis.some.2),
⟨(Basis.reindexRange h.exists_basis.some.2).reindex (equivShrink _)⟩⟩,
fun h => ⟨(nonempty_sigma.2 h).map fun ⟨_, b⟩ => ⟨Set.range b, b.reindexRange⟩⟩⟩
theorem Module.free_iff_set : Module.Free R M ↔ ∃ S : Set M, Nonempty (Basis S R M) :=
⟨fun h => ⟨Set.range h.exists_basis.some.2, ⟨Basis.reindexRange h.exists_basis.some.2⟩⟩,
fun ⟨S, hS⟩ => ⟨nonempty_sigma.2 ⟨S, hS⟩⟩⟩
variable {R M}
theorem Module.Free.of_basis {ι : Type w} (b : Basis ι R M) : Module.Free R M :=
(Module.free_def R M).2 ⟨Set.range b, ⟨b.reindexRange⟩⟩
end Basic
namespace Module.Free
section Semiring
variable [Semiring R] [AddCommMonoid M] [Module R M] [Module.Free R M]
variable [AddCommMonoid N] [Module R N]
/-- If `Module.Free R M` then `ChooseBasisIndex R M` is the `ι` which indexes the basis
`ι → M`. Note that this is defined such that this type is finite if `R` is trivial. -/
def ChooseBasisIndex : Type _ :=
((Module.free_iff_set R M).mp ‹_›).choose
/-- There is no hope of computing this, but we add the instance anyway to avoid fumbling with
`open scoped Classical`. -/
noncomputable instance : DecidableEq (ChooseBasisIndex R M) := Classical.decEq _
/-- If `Module.Free R M` then `chooseBasis : ι → M` is the basis.
Here `ι = ChooseBasisIndex R M`. -/
noncomputable def chooseBasis : Basis (ChooseBasisIndex R M) R M :=
((Module.free_iff_set R M).mp ‹_›).choose_spec.some
/-- The isomorphism `M ≃ₗ[R] (ChooseBasisIndex R M →₀ R)`. -/
noncomputable def repr : M ≃ₗ[R] ChooseBasisIndex R M →₀ R :=
(chooseBasis R M).repr
/-- The universal property of free modules: giving a function `(ChooseBasisIndex R M) → N`, for `N`
an `R`-module, is the same as giving an `R`-linear map `M →ₗ[R] N`.
This definition is parameterized over an extra `Semiring S`,
such that `SMulCommClass R S M'` holds.
If `R` is commutative, you can set `S := R`; if `R` is not commutative,
you can recover an `AddEquiv` by setting `S := ℕ`.
See library note [bundled maps over different rings]. -/
noncomputable def constr {S : Type z} [Semiring S] [Module S N] [SMulCommClass R S N] :
(ChooseBasisIndex R M → N) ≃ₗ[S] M →ₗ[R] N :=
Basis.constr (chooseBasis R M) S
instance (priority := 100) noZeroSMulDivisors [NoZeroDivisors R] : NoZeroSMulDivisors R M :=
let ⟨⟨_, b⟩⟩ := exists_basis (R := R) (M := M)
b.noZeroSMulDivisors
instance [Nontrivial M] : Nonempty (Module.Free.ChooseBasisIndex R M) :=
(Module.Free.chooseBasis R M).index_nonempty
theorem infinite [Infinite R] [Nontrivial M] : Infinite M :=
(Equiv.infinite_iff (chooseBasis R M).repr.toEquiv).mpr Finsupp.infinite_of_right
variable {R M N}
theorem of_equiv (e : M ≃ₗ[R] N) : Module.Free R N :=
of_basis <| (chooseBasis R M).map e
/-- A variation of `of_equiv`: the assumption `Module.Free R P` here is explicit rather than an
instance. -/
theorem of_equiv' {P : Type v} [AddCommMonoid P] [Module R P] (_ : Module.Free R P)
(e : P ≃ₗ[R] N) : Module.Free R N :=
of_equiv e
variable (R M N)
/-- The module structure provided by `Semiring.toModule` is free. -/
instance self : Module.Free R R :=
of_basis (Basis.singleton Unit R)
instance prod [Module.Free R N] : Module.Free R (M × N) :=
of_basis <| (chooseBasis R M).prod (chooseBasis R N)
/-- The product of finitely many free modules is free. -/
instance pi (M : ι → Type*) [Finite ι] [∀ i : ι, AddCommMonoid (M i)] [∀ i : ι, Module R (M i)]
[∀ i : ι, Module.Free R (M i)] : Module.Free R (∀ i, M i) :=
let ⟨_⟩ := nonempty_fintype ι
of_basis <| Pi.basis fun i => chooseBasis R (M i)
/-- The module of finite matrices is free. -/
instance matrix {m n : Type*} [Finite m] [Finite n] : Module.Free R (Matrix m n M) :=
Module.Free.pi R _
instance ulift [Free R M] : Free R (ULift M) := of_equiv ULift.moduleEquiv.symm
variable (ι)
/-- The product of finitely many free modules is free (non-dependent version to help with typeclass
search). -/
instance function [Finite ι] : Module.Free R (ι → M) :=
Free.pi _ _
instance finsupp : Module.Free R (ι →₀ M) :=
of_basis (Finsupp.basis fun _ => chooseBasis R M)
variable {ι}
instance (priority := 100) of_subsingleton [Subsingleton N] : Module.Free R N :=
of_basis.{u,z,z} (Basis.empty N : Basis PEmpty R N)
instance (priority := 100) of_subsingleton' [Subsingleton R] : Module.Free R N :=
letI := Module.subsingleton R N
Module.Free.of_subsingleton R N
instance dfinsupp {ι : Type*} (M : ι → Type*) [∀ i : ι, AddCommMonoid (M i)]
[∀ i : ι, Module R (M i)] [∀ i : ι, Module.Free R (M i)] : Module.Free R (Π₀ i, M i) :=
of_basis <| DFinsupp.basis fun i => chooseBasis R (M i)
instance directSum {ι : Type*} (M : ι → Type*) [∀ i : ι, AddCommMonoid (M i)]
[∀ i : ι, Module R (M i)] [∀ i : ι, Module.Free R (M i)] : Module.Free R (⨁ i, M i) :=
Module.Free.dfinsupp R M
end Semiring
section CommSemiring
variable {S} [CommSemiring R] [Semiring S] [Algebra R S] [AddCommMonoid M] [Module R M]
[Module S M] [IsScalarTower R S M] [Module.Free S M]
[AddCommMonoid N] [Module R N] [Module.Free R N]
instance tensor : Module.Free S (M ⊗[R] N) :=
let ⟨bM⟩ := exists_basis (R := S) (M := M)
let ⟨bN⟩ := exists_basis (R := R) (M := N)
of_basis (bM.2.tensorProduct bN.2)
end CommSemiring
end Module.Free
|
LinearAlgebra\FreeModule\Determinant.lean | /-
Copyright (c) 2022 Anne Baanen. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Anne Baanen, Alex J. Best
-/
import Mathlib.LinearAlgebra.Determinant
import Mathlib.LinearAlgebra.FreeModule.Finite.Basic
/-!
# Determinants in free (finite) modules
Quite a lot of our results on determinants (that you might know in vector spaces) will work for all
free (finite) modules over any commutative ring.
## Main results
* `LinearMap.det_zero''`: The determinant of the constant zero map is zero, in a finite free
nontrivial module.
-/
@[simp]
theorem LinearMap.det_zero'' {R M : Type*} [CommRing R] [AddCommGroup M] [Module R M]
[Module.Free R M] [Module.Finite R M] [Nontrivial M] : LinearMap.det (0 : M →ₗ[R] M) = 0 := by
letI : Nonempty (Module.Free.ChooseBasisIndex R M) := (Module.Free.chooseBasis R M).index_nonempty
nontriviality R
exact LinearMap.det_zero' (Module.Free.chooseBasis R M)
|
LinearAlgebra\FreeModule\IdealQuotient.lean | /-
Copyright (c) 2022 Anne Baanen. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Anne Baanen
-/
import Mathlib.LinearAlgebra.FreeModule.Finite.Basic
import Mathlib.LinearAlgebra.FreeModule.PID
import Mathlib.LinearAlgebra.FreeModule.StrongRankCondition
import Mathlib.LinearAlgebra.QuotientPi
import Mathlib.RingTheory.Ideal.Basis
import Mathlib.LinearAlgebra.Dimension.Constructions
/-! # Ideals in free modules over PIDs
## Main results
- `Ideal.quotientEquivPiSpan`: `S ⧸ I`, if `S` is finite free as a module over a PID `R`,
can be written as a product of quotients of `R` by principal ideals.
-/
namespace Ideal
open scoped DirectSum
variable {ι R S : Type*} [CommRing R] [CommRing S] [Algebra R S]
variable [IsDomain R] [IsPrincipalIdealRing R] [IsDomain S] [Finite ι]
/-- We can write the quotient of an ideal over a PID as a product of quotients by principal ideals.
-/
noncomputable def quotientEquivPiSpan (I : Ideal S) (b : Basis ι R S) (hI : I ≠ ⊥) :
(S ⧸ I) ≃ₗ[R] ∀ i, R ⧸ span ({I.smithCoeffs b hI i} : Set R) := by
haveI := Fintype.ofFinite ι
-- Choose `e : S ≃ₗ I` and a basis `b'` for `S` that turns the map
-- `f := ((Submodule.subtype I).restrictScalars R).comp e` into a diagonal matrix:
-- there is an `a : ι → ℤ` such that `f (b' i) = a i • b' i`.
let a := I.smithCoeffs b hI
let b' := I.ringBasis b hI
let ab := I.selfBasis b hI
have ab_eq := I.selfBasis_def b hI
have mem_I_iff : ∀ x, x ∈ I ↔ ∀ i, a i ∣ b'.repr x i := by
intro x
-- Porting note: these lines used to be `simp_rw [ab.mem_ideal_iff', ab_eq]`
rw [ab.mem_ideal_iff']
simp_rw [ab_eq]
have : ∀ (c : ι → R) (i), b'.repr (∑ j : ι, c j • a j • b' j) i = a i * c i := by
intro c i
simp only [← MulAction.mul_smul, b'.repr_sum_self, mul_comm]
constructor
· rintro ⟨c, rfl⟩ i
exact ⟨c i, this c i⟩
· rintro ha
choose c hc using ha
exact ⟨c, b'.ext_elem fun i => Eq.trans (hc i) (this c i).symm⟩
-- Now we map everything through the linear equiv `S ≃ₗ (ι → R)`,
-- which maps `I` to `I' := Π i, a i ℤ`.
let I' : Submodule R (ι → R) := Submodule.pi Set.univ fun i => span ({a i} : Set R)
have : Submodule.map (b'.equivFun : S →ₗ[R] ι → R) (I.restrictScalars R) = I' := by
ext x
simp only [I', Submodule.mem_map, Submodule.mem_pi, mem_span_singleton, Set.mem_univ,
Submodule.restrictScalars_mem, mem_I_iff, smul_eq_mul, forall_true_left, LinearEquiv.coe_coe,
Basis.equivFun_apply]
constructor
· rintro ⟨y, hy, rfl⟩ i
exact hy i
· rintro hdvd
refine ⟨∑ i, x i • b' i, fun i => ?_, ?_⟩ <;> rw [b'.repr_sum_self]
· exact hdvd i
refine ((Submodule.Quotient.restrictScalarsEquiv R I).restrictScalars R).symm.trans
(σ₁₂ := RingHom.id R) (σ₃₂ := RingHom.id R) (re₂₃ := inferInstance) (re₃₂ := inferInstance) ?_
refine (Submodule.Quotient.equiv (I.restrictScalars R) I' b'.equivFun this).trans
(σ₁₂ := RingHom.id R) (σ₃₂ := RingHom.id R) (re₂₃ := inferInstance) (re₃₂ := inferInstance) ?_
classical
let this :=
Submodule.quotientPi (show _ → Submodule R R from fun i => span ({a i} : Set R))
exact this
/-- Ideal quotients over a free finite extension of `ℤ` are isomorphic to a direct product of
`ZMod`. -/
noncomputable def quotientEquivPiZMod (I : Ideal S) (b : Basis ι ℤ S) (hI : I ≠ ⊥) :
S ⧸ I ≃+ ∀ i, ZMod (I.smithCoeffs b hI i).natAbs :=
let a := I.smithCoeffs b hI
let e := I.quotientEquivPiSpan b hI
let e' : (∀ i : ι, ℤ ⧸ span ({a i} : Set ℤ)) ≃+ ∀ i : ι, ZMod (a i).natAbs :=
AddEquiv.piCongrRight fun i => ↑(Int.quotientSpanEquivZMod (a i))
(↑(e : (S ⧸ I) ≃ₗ[ℤ] _) : S ⧸ I ≃+ _).trans e'
/-- A nonzero ideal over a free finite extension of `ℤ` has a finite quotient.
Can't be an instance because of the side condition `I ≠ ⊥`, and more importantly,
because the choice of `Fintype` instance is non-canonical.
-/
noncomputable def fintypeQuotientOfFreeOfNeBot [Module.Free ℤ S] [Module.Finite ℤ S]
(I : Ideal S) (hI : I ≠ ⊥) : Fintype (S ⧸ I) := by
let b := Module.Free.chooseBasis ℤ S
let a := I.smithCoeffs b hI
let e := I.quotientEquivPiZMod b hI
haveI : ∀ i, NeZero (a i).natAbs := fun i =>
⟨Int.natAbs_ne_zero.mpr (smithCoeffs_ne_zero b I hI i)⟩
classical exact Fintype.ofEquiv (∀ i, ZMod (a i).natAbs) e.symm
variable (F : Type*) [CommRing F] [Algebra F R] [Algebra F S] [IsScalarTower F R S]
(b : Basis ι R S) {I : Ideal S} (hI : I ≠ ⊥)
/-- Decompose `S⧸I` as a direct sum of cyclic `R`-modules
(quotients by the ideals generated by Smith coefficients of `I`). -/
noncomputable def quotientEquivDirectSum :
(S ⧸ I) ≃ₗ[F] ⨁ i, R ⧸ span ({I.smithCoeffs b hI i} : Set R) := by
haveI := Fintype.ofFinite ι
-- Porting note: manual construction of `CompatibleSMul` typeclass no longer needed
exact ((I.quotientEquivPiSpan b _).restrictScalars F).trans
(DirectSum.linearEquivFunOnFintype _ _ _).symm
theorem finrank_quotient_eq_sum {ι} [Fintype ι] (b : Basis ι R S) [Nontrivial F]
[∀ i, Module.Free F (R ⧸ span ({I.smithCoeffs b hI i} : Set R))]
[∀ i, Module.Finite F (R ⧸ span ({I.smithCoeffs b hI i} : Set R))] :
FiniteDimensional.finrank F (S ⧸ I) =
∑ i, FiniteDimensional.finrank F (R ⧸ span ({I.smithCoeffs b hI i} : Set R)) := by
-- slow, and dot notation doesn't work
rw [LinearEquiv.finrank_eq <| quotientEquivDirectSum F b hI, FiniteDimensional.finrank_directSum]
end Ideal
|
LinearAlgebra\FreeModule\Norm.lean | /-
Copyright (c) 2023 Junyan Xu. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Junyan Xu
-/
import Mathlib.LinearAlgebra.FreeModule.IdealQuotient
import Mathlib.RingTheory.Norm.Defs
import Mathlib.RingTheory.AdjoinRoot
/-!
# Norms on free modules over principal ideal domains
-/
open Ideal Polynomial
open scoped Polynomial
variable {R S ι : Type*} [CommRing R] [IsDomain R] [IsPrincipalIdealRing R] [CommRing S]
[IsDomain S] [Algebra R S]
section CommRing
variable (F : Type*) [CommRing F] [Algebra F R] [Algebra F S] [IsScalarTower F R S]
/-- For a nonzero element `f` in an algebra `S` over a principal ideal domain `R` that is finite and
free as an `R`-module, the norm of `f` relative to `R` is associated to the product of the Smith
coefficients of the ideal generated by `f`. -/
theorem associated_norm_prod_smith [Fintype ι] (b : Basis ι R S) {f : S} (hf : f ≠ 0) :
Associated (Algebra.norm R f) (∏ i, smithCoeffs b _ (span_singleton_eq_bot.not.2 hf) i) := by
have hI := span_singleton_eq_bot.not.2 hf
let b' := ringBasis b (span {f}) hI
classical
rw [← Matrix.det_diagonal, ← LinearMap.det_toLin b']
let e :=
(b'.equiv ((span {f}).selfBasis b hI) <| Equiv.refl _).trans
((LinearEquiv.coord S S f hf).restrictScalars R)
refine (LinearMap.associated_det_of_eq_comp e _ _ ?_).symm
dsimp only [e, LinearEquiv.trans_apply]
simp_rw [← LinearEquiv.coe_toLinearMap, ← LinearMap.comp_apply, ← LinearMap.ext_iff]
refine b'.ext fun i => ?_
simp_rw [LinearMap.comp_apply, LinearEquiv.coe_toLinearMap, Matrix.toLin_apply, Basis.repr_self,
Finsupp.single_eq_pi_single, Matrix.diagonal_mulVec_single, Pi.single_apply, ite_smul,
zero_smul, Finset.sum_ite_eq', mul_one, if_pos (Finset.mem_univ _), b'.equiv_apply]
change _ = f * _
-- This used to be `rw`, but we need `erw` after leanprover/lean4#2644
erw [mul_comm, ← smul_eq_mul, LinearEquiv.restrictScalars_apply, LinearEquiv.coord_apply_smul,
Ideal.selfBasis_def]
rfl
end CommRing
section Field
variable {F : Type*} [Field F] [Algebra F[X] S] [Finite ι]
instance (b : Basis ι F[X] S) {I : Ideal S} (hI : I ≠ ⊥) (i : ι) :
FiniteDimensional F (F[X] ⧸ span ({I.smithCoeffs b hI i} : Set F[X])) := by
-- Porting note: we need to do this proof in two stages otherwise it times out
-- original proof: (AdjoinRoot.powerBasis <| I.smithCoeffs_ne_zero b hI i).FiniteDimensional
-- The first tactic takes over 10 seconds, spending a lot of time in checking
-- that instances on the quotient commute. My guess is that we unfold
-- operations to the `Quotient.lift` level and then end up comparing huge
-- terms. We should probably make most of the quotient operations
-- irreducible so that they don't expose `Quotient.lift` accidentally.
refine PowerBasis.finite ?_
refine AdjoinRoot.powerBasis ?_
exact I.smithCoeffs_ne_zero b hI i
/-- For a nonzero element `f` in a `F[X]`-module `S`, the dimension of $S/\langle f \rangle$ as an
`F`-vector space is the degree of the norm of `f` relative to `F[X]`. -/
theorem finrank_quotient_span_eq_natDegree_norm [Algebra F S] [IsScalarTower F F[X] S]
(b : Basis ι F[X] S) {f : S} (hf : f ≠ 0) :
FiniteDimensional.finrank F (S ⧸ span ({f} : Set S)) = (Algebra.norm F[X] f).natDegree := by
haveI := Fintype.ofFinite ι
have h := span_singleton_eq_bot.not.2 hf
rw [natDegree_eq_of_degree_eq
(degree_eq_degree_of_associated <| associated_norm_prod_smith b hf)]
rw [natDegree_prod _ _ fun i _ => smithCoeffs_ne_zero b _ h i, finrank_quotient_eq_sum F h b]
-- finrank_quotient_eq_sum slow
congr with i
exact (AdjoinRoot.powerBasis <| smithCoeffs_ne_zero b _ h i).finrank
end Field
|
LinearAlgebra\FreeModule\PID.lean | /-
Copyright (c) 2020 Anne Baanen. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Anne Baanen
-/
import Mathlib.LinearAlgebra.Dimension.StrongRankCondition
import Mathlib.LinearAlgebra.FreeModule.Basic
/-! # Free modules over PID
A free `R`-module `M` is a module with a basis over `R`,
equivalently it is an `R`-module linearly equivalent to `ι →₀ R` for some `ι`.
This file proves a submodule of a free `R`-module of finite rank is also
a free `R`-module of finite rank, if `R` is a principal ideal domain (PID),
i.e. we have instances `[IsDomain R] [IsPrincipalIdealRing R]`.
We express "free `R`-module of finite rank" as a module `M` which has a basis
`b : ι → R`, where `ι` is a `Fintype`.
We call the cardinality of `ι` the rank of `M` in this file;
it would be equal to `finrank R M` if `R` is a field and `M` is a vector space.
## Main results
In this section, `M` is a free and finitely generated `R`-module, and
`N` is a submodule of `M`.
- `Submodule.inductionOnRank`: if `P` holds for `⊥ : Submodule R M` and if
`P N` follows from `P N'` for all `N'` that are of lower rank, then `P` holds
on all submodules
- `Submodule.exists_basis_of_pid`: if `R` is a PID, then `N : Submodule R M` is
free and finitely generated. This is the first part of the structure theorem
for modules.
- `Submodule.smithNormalForm`: if `R` is a PID, then `M` has a basis
`bM` and `N` has a basis `bN` such that `bN i = a i • bM i`.
Equivalently, a linear map `f : M →ₗ M` with `range f = N` can be written as
a matrix in Smith normal form, a diagonal matrix with the coefficients `a i`
along the diagonal.
## Tags
free module, finitely generated module, rank, structure theorem
-/
universe u v
section Ring
variable {R : Type u} {M : Type v} [Ring R] [AddCommGroup M] [Module R M]
variable {ι : Type*} (b : Basis ι R M)
open Submodule.IsPrincipal Submodule
theorem eq_bot_of_generator_maximal_map_eq_zero (b : Basis ι R M) {N : Submodule R M}
{ϕ : M →ₗ[R] R} (hϕ : ∀ ψ : M →ₗ[R] R, ¬N.map ϕ < N.map ψ) [(N.map ϕ).IsPrincipal]
(hgen : generator (N.map ϕ) = (0 : R)) : N = ⊥ := by
rw [Submodule.eq_bot_iff]
intro x hx
refine b.ext_elem fun i ↦ ?_
rw [(eq_bot_iff_generator_eq_zero _).mpr hgen] at hϕ
rw [LinearEquiv.map_zero, Finsupp.zero_apply]
exact
(Submodule.eq_bot_iff _).mp (not_bot_lt_iff.1 <| hϕ (Finsupp.lapply i ∘ₗ ↑b.repr)) _
⟨x, hx, rfl⟩
theorem eq_bot_of_generator_maximal_submoduleImage_eq_zero {N O : Submodule R M} (b : Basis ι R O)
(hNO : N ≤ O) {ϕ : O →ₗ[R] R} (hϕ : ∀ ψ : O →ₗ[R] R, ¬ϕ.submoduleImage N < ψ.submoduleImage N)
[(ϕ.submoduleImage N).IsPrincipal] (hgen : generator (ϕ.submoduleImage N) = 0) : N = ⊥ := by
rw [Submodule.eq_bot_iff]
intro x hx
refine (mk_eq_zero _ _).mp (show (⟨x, hNO hx⟩ : O) = 0 from b.ext_elem fun i ↦ ?_)
rw [(eq_bot_iff_generator_eq_zero _).mpr hgen] at hϕ
rw [LinearEquiv.map_zero, Finsupp.zero_apply]
refine (Submodule.eq_bot_iff _).mp (not_bot_lt_iff.1 <| hϕ (Finsupp.lapply i ∘ₗ ↑b.repr)) _ ?_
exact (LinearMap.mem_submoduleImage_of_le hNO).mpr ⟨x, hx, rfl⟩
end Ring
section IsDomain
variable {ι : Type*} {R : Type*} [CommRing R] [IsDomain R]
variable {M : Type*} [AddCommGroup M] [Module R M] {b : ι → M}
open Submodule.IsPrincipal Set Submodule
theorem dvd_generator_iff {I : Ideal R} [I.IsPrincipal] {x : R} (hx : x ∈ I) :
x ∣ generator I ↔ I = Ideal.span {x} := by
conv_rhs => rw [← span_singleton_generator I]
rw [Ideal.submodule_span_eq, Ideal.span_singleton_eq_span_singleton, ← dvd_dvd_iff_associated,
← mem_iff_generator_dvd]
exact ⟨fun h ↦ ⟨hx, h⟩, fun h ↦ h.2⟩
end IsDomain
section PrincipalIdealDomain
open Submodule.IsPrincipal Set Submodule
variable {ι : Type*} {R : Type*} [CommRing R]
variable {M : Type*} [AddCommGroup M] [Module R M] {b : ι → M}
section StrongRankCondition
variable [IsDomain R] [IsPrincipalIdealRing R]
open Submodule.IsPrincipal
theorem generator_maximal_submoduleImage_dvd {N O : Submodule R M} (hNO : N ≤ O) {ϕ : O →ₗ[R] R}
(hϕ : ∀ ψ : O →ₗ[R] R, ¬ϕ.submoduleImage N < ψ.submoduleImage N)
[(ϕ.submoduleImage N).IsPrincipal] (y : M) (yN : y ∈ N)
(ϕy_eq : ϕ ⟨y, hNO yN⟩ = generator (ϕ.submoduleImage N)) (ψ : O →ₗ[R] R) :
generator (ϕ.submoduleImage N) ∣ ψ ⟨y, hNO yN⟩ := by
let a : R := generator (ϕ.submoduleImage N)
let d : R := IsPrincipal.generator (Submodule.span R {a, ψ ⟨y, hNO yN⟩})
have d_dvd_left : d ∣ a := (mem_iff_generator_dvd _).mp (subset_span (mem_insert _ _))
have d_dvd_right : d ∣ ψ ⟨y, hNO yN⟩ :=
(mem_iff_generator_dvd _).mp (subset_span (mem_insert_of_mem _ (mem_singleton _)))
refine dvd_trans ?_ d_dvd_right
rw [dvd_generator_iff, Ideal.span, ←
span_singleton_generator (Submodule.span R {a, ψ ⟨y, hNO yN⟩})]
· obtain ⟨r₁, r₂, d_eq⟩ : ∃ r₁ r₂ : R, d = r₁ * a + r₂ * ψ ⟨y, hNO yN⟩ := by
obtain ⟨r₁, r₂', hr₂', hr₁⟩ :=
mem_span_insert.mp (IsPrincipal.generator_mem (Submodule.span R {a, ψ ⟨y, hNO yN⟩}))
obtain ⟨r₂, rfl⟩ := mem_span_singleton.mp hr₂'
exact ⟨r₁, r₂, hr₁⟩
let ψ' : O →ₗ[R] R := r₁ • ϕ + r₂ • ψ
have : span R {d} ≤ ψ'.submoduleImage N := by
rw [span_le, singleton_subset_iff, SetLike.mem_coe, LinearMap.mem_submoduleImage_of_le hNO]
refine ⟨y, yN, ?_⟩
change r₁ * ϕ ⟨y, hNO yN⟩ + r₂ * ψ ⟨y, hNO yN⟩ = d
rw [d_eq, ϕy_eq]
refine
le_antisymm (this.trans (le_of_eq ?_)) (Ideal.span_singleton_le_span_singleton.mpr d_dvd_left)
rw [span_singleton_generator]
apply (le_trans _ this).eq_of_not_gt (hϕ ψ')
rw [← span_singleton_generator (ϕ.submoduleImage N)]
exact Ideal.span_singleton_le_span_singleton.mpr d_dvd_left
· exact subset_span (mem_insert _ _)
/-- The induction hypothesis of `Submodule.basisOfPid` and `Submodule.smithNormalForm`.
Basically, it says: let `N ≤ M` be a pair of submodules, then we can find a pair of
submodules `N' ≤ M'` of strictly smaller rank, whose basis we can extend to get a basis
of `N` and `M`. Moreover, if the basis for `M'` is up to scalars a basis for `N'`,
then the basis we find for `M` is up to scalars a basis for `N`.
For `basis_of_pid` we only need the first half and can fix `M = ⊤`,
for `smith_normal_form` we need the full statement,
but must also feed in a basis for `M` using `basis_of_pid` to keep the induction going.
-/
theorem Submodule.basis_of_pid_aux [Finite ι] {O : Type*} [AddCommGroup O] [Module R O]
(M N : Submodule R O) (b'M : Basis ι R M) (N_bot : N ≠ ⊥) (N_le_M : N ≤ M) :
∃ y ∈ M, ∃ a : R, a • y ∈ N ∧ ∃ M' ≤ M, ∃ N' ≤ N,
N' ≤ M' ∧ (∀ (c : R) (z : O), z ∈ M' → c • y + z = 0 → c = 0) ∧
(∀ (c : R) (z : O), z ∈ N' → c • a • y + z = 0 → c = 0) ∧
∀ (n') (bN' : Basis (Fin n') R N'),
∃ bN : Basis (Fin (n' + 1)) R N,
∀ (m') (hn'm' : n' ≤ m') (bM' : Basis (Fin m') R M'),
∃ (hnm : n' + 1 ≤ m' + 1) (bM : Basis (Fin (m' + 1)) R M),
∀ as : Fin n' → R,
(∀ i : Fin n', (bN' i : O) = as i • (bM' (Fin.castLE hn'm' i) : O)) →
∃ as' : Fin (n' + 1) → R,
∀ i : Fin (n' + 1), (bN i : O) = as' i • (bM (Fin.castLE hnm i) : O) := by
-- Let `ϕ` be a maximal projection of `M` onto `R`, in the sense that there is
-- no `ψ` whose image of `N` is larger than `ϕ`'s image of `N`.
have : ∃ ϕ : M →ₗ[R] R, ∀ ψ : M →ₗ[R] R, ¬ϕ.submoduleImage N < ψ.submoduleImage N := by
obtain ⟨P, P_eq, P_max⟩ :=
set_has_maximal_iff_noetherian.mpr (inferInstance : IsNoetherian R R) _
(show (Set.range fun ψ : M →ₗ[R] R ↦ ψ.submoduleImage N).Nonempty from
⟨_, Set.mem_range.mpr ⟨0, rfl⟩⟩)
obtain ⟨ϕ, rfl⟩ := Set.mem_range.mp P_eq
exact ⟨ϕ, fun ψ hψ ↦ P_max _ ⟨_, rfl⟩ hψ⟩
let ϕ := this.choose
have ϕ_max := this.choose_spec
-- Since `ϕ(N)` is an `R`-submodule of the PID `R`,
-- it is principal and generated by some `a`.
let a := generator (ϕ.submoduleImage N)
have a_mem : a ∈ ϕ.submoduleImage N := generator_mem _
-- If `a` is zero, then the submodule is trivial. So let's assume `a ≠ 0`, `N ≠ ⊥`.
by_cases a_zero : a = 0
· have := eq_bot_of_generator_maximal_submoduleImage_eq_zero b'M N_le_M ϕ_max a_zero
contradiction
-- We claim that `ϕ⁻¹ a = y` can be taken as basis element of `N`.
obtain ⟨y, yN, ϕy_eq⟩ := (LinearMap.mem_submoduleImage_of_le N_le_M).mp a_mem
have _ϕy_ne_zero : ϕ ⟨y, N_le_M yN⟩ ≠ 0 := fun h ↦ a_zero (ϕy_eq.symm.trans h)
-- Write `y` as `a • y'` for some `y'`.
have hdvd : ∀ i, a ∣ b'M.coord i ⟨y, N_le_M yN⟩ := fun i ↦
generator_maximal_submoduleImage_dvd N_le_M ϕ_max y yN ϕy_eq (b'M.coord i)
choose c hc using hdvd
cases nonempty_fintype ι
let y' : O := ∑ i, c i • b'M i
have y'M : y' ∈ M := M.sum_mem fun i _ ↦ M.smul_mem (c i) (b'M i).2
have mk_y' : (⟨y', y'M⟩ : M) = ∑ i, c i • b'M i :=
Subtype.ext
(show y' = M.subtype _ by
simp only [map_sum, map_smul]
rfl)
have a_smul_y' : a • y' = y := by
refine Subtype.mk_eq_mk.mp (show (a • ⟨y', y'M⟩ : M) = ⟨y, N_le_M yN⟩ from ?_)
rw [← b'M.sum_repr ⟨y, N_le_M yN⟩, mk_y', Finset.smul_sum]
refine Finset.sum_congr rfl fun i _ ↦ ?_
rw [← mul_smul, ← hc]
rfl
-- We found a `y` and an `a`!
refine ⟨y', y'M, a, a_smul_y'.symm ▸ yN, ?_⟩
have ϕy'_eq : ϕ ⟨y', y'M⟩ = 1 :=
mul_left_cancel₀ a_zero
(calc
a • ϕ ⟨y', y'M⟩ = ϕ ⟨a • y', _⟩ := (ϕ.map_smul a ⟨y', y'M⟩).symm
_ = ϕ ⟨y, N_le_M yN⟩ := by simp only [a_smul_y']
_ = a := ϕy_eq
_ = a * 1 := (mul_one a).symm
)
have ϕy'_ne_zero : ϕ ⟨y', y'M⟩ ≠ 0 := by simpa only [ϕy'_eq] using one_ne_zero
-- `M' := ker (ϕ : M → R)` is smaller than `M` and `N' := ker (ϕ : N → R)` is smaller than `N`.
let M' : Submodule R O := ϕ.ker.map M.subtype
let N' : Submodule R O := (ϕ.comp (inclusion N_le_M)).ker.map N.subtype
have M'_le_M : M' ≤ M := M.map_subtype_le (LinearMap.ker ϕ)
have N'_le_M' : N' ≤ M' := by
intro x hx
simp only [N', mem_map, LinearMap.mem_ker] at hx ⊢
obtain ⟨⟨x, xN⟩, hx, rfl⟩ := hx
exact ⟨⟨x, N_le_M xN⟩, hx, rfl⟩
have N'_le_N : N' ≤ N := N.map_subtype_le (LinearMap.ker (ϕ.comp (inclusion N_le_M)))
-- So fill in those results as well.
refine ⟨M', M'_le_M, N', N'_le_N, N'_le_M', ?_⟩
-- Note that `y'` is orthogonal to `M'`.
have y'_ortho_M' : ∀ (c : R), ∀ z ∈ M', c • y' + z = 0 → c = 0 := by
intro c x xM' hc
obtain ⟨⟨x, xM⟩, hx', rfl⟩ := Submodule.mem_map.mp xM'
rw [LinearMap.mem_ker] at hx'
have hc' : (c • ⟨y', y'M⟩ + ⟨x, xM⟩ : M) = 0 := by exact @Subtype.coe_injective O (· ∈ M) _ _ hc
simpa only [LinearMap.map_add, LinearMap.map_zero, LinearMap.map_smul, smul_eq_mul, add_zero,
mul_eq_zero, ϕy'_ne_zero, hx', or_false_iff] using congr_arg ϕ hc'
-- And `a • y'` is orthogonal to `N'`.
have ay'_ortho_N' : ∀ (c : R), ∀ z ∈ N', c • a • y' + z = 0 → c = 0 := by
intro c z zN' hc
refine (mul_eq_zero.mp (y'_ortho_M' (a * c) z (N'_le_M' zN') ?_)).resolve_left a_zero
rw [mul_comm, mul_smul, hc]
-- So we can extend a basis for `N'` with `y`
refine ⟨y'_ortho_M', ay'_ortho_N', fun n' bN' ↦ ⟨?_, ?_⟩⟩
· refine Basis.mkFinConsOfLE y yN bN' N'_le_N ?_ ?_
· intro c z zN' hc
refine ay'_ortho_N' c z zN' ?_
rwa [← a_smul_y'] at hc
· intro z zN
obtain ⟨b, hb⟩ : _ ∣ ϕ ⟨z, N_le_M zN⟩ := generator_submoduleImage_dvd_of_mem N_le_M ϕ zN
refine ⟨-b, Submodule.mem_map.mpr ⟨⟨_, N.sub_mem zN (N.smul_mem b yN)⟩, ?_, ?_⟩⟩
· refine LinearMap.mem_ker.mpr (show ϕ (⟨z, N_le_M zN⟩ - b • ⟨y, N_le_M yN⟩) = 0 from ?_)
rw [LinearMap.map_sub, LinearMap.map_smul, hb, ϕy_eq, smul_eq_mul, mul_comm, sub_self]
· simp only [sub_eq_add_neg, neg_smul, coeSubtype]
-- And extend a basis for `M'` with `y'`
intro m' hn'm' bM'
refine ⟨Nat.succ_le_succ hn'm', ?_, ?_⟩
· refine Basis.mkFinConsOfLE y' y'M bM' M'_le_M y'_ortho_M' ?_
intro z zM
refine ⟨-ϕ ⟨z, zM⟩, ⟨⟨z, zM⟩ - ϕ ⟨z, zM⟩ • ⟨y', y'M⟩, LinearMap.mem_ker.mpr ?_, ?_⟩⟩
· rw [LinearMap.map_sub, LinearMap.map_smul, ϕy'_eq, smul_eq_mul, mul_one, sub_self]
· rw [LinearMap.map_sub, LinearMap.map_smul, sub_eq_add_neg, neg_smul]
rfl
-- It remains to show the extended bases are compatible with each other.
intro as h
refine ⟨Fin.cons a as, ?_⟩
intro i
rw [Basis.coe_mkFinConsOfLE, Basis.coe_mkFinConsOfLE]
refine Fin.cases ?_ (fun i ↦ ?_) i
· simp only [Fin.cons_zero, Fin.castLE_zero]
exact a_smul_y'.symm
· rw [Fin.castLE_succ]
simp only [Fin.cons_succ, Function.comp_apply, coe_inclusion, map_coe, coeSubtype, h i]
/-- A submodule of a free `R`-module of finite rank is also a free `R`-module of finite rank,
if `R` is a principal ideal domain.
This is a `lemma` to make the induction a bit easier. To actually access the basis,
see `Submodule.basisOfPid`.
See also the stronger version `Submodule.smithNormalForm`.
-/
theorem Submodule.nonempty_basis_of_pid {ι : Type*} [Finite ι] (b : Basis ι R M)
(N : Submodule R M) : ∃ n : ℕ, Nonempty (Basis (Fin n) R N) := by
haveI := Classical.decEq M
cases nonempty_fintype ι
induction N using inductionOnRank b with | ih N ih =>
let b' := (b.reindex (Fintype.equivFin ι)).map (LinearEquiv.ofTop _ rfl).symm
by_cases N_bot : N = ⊥
· subst N_bot
exact ⟨0, ⟨Basis.empty _⟩⟩
obtain ⟨y, -, a, hay, M', -, N', N'_le_N, -, -, ay_ortho, h'⟩ :=
Submodule.basis_of_pid_aux ⊤ N b' N_bot le_top
obtain ⟨n', ⟨bN'⟩⟩ := ih N' N'_le_N _ hay ay_ortho
obtain ⟨bN, _hbN⟩ := h' n' bN'
exact ⟨n' + 1, ⟨bN⟩⟩
/-- A submodule of a free `R`-module of finite rank is also a free `R`-module of finite rank,
if `R` is a principal ideal domain.
See also the stronger version `Submodule.smithNormalForm`.
-/
noncomputable def Submodule.basisOfPid {ι : Type*} [Finite ι] (b : Basis ι R M)
(N : Submodule R M) : Σn : ℕ, Basis (Fin n) R N :=
⟨_, (N.nonempty_basis_of_pid b).choose_spec.some⟩
theorem Submodule.basisOfPid_bot {ι : Type*} [Finite ι] (b : Basis ι R M) :
Submodule.basisOfPid b ⊥ = ⟨0, Basis.empty _⟩ := by
obtain ⟨n, b'⟩ := Submodule.basisOfPid b ⊥
let e : Fin n ≃ Fin 0 := b'.indexEquiv (Basis.empty _ : Basis (Fin 0) R (⊥ : Submodule R M))
obtain rfl : n = 0 := by simpa using Fintype.card_eq.mpr ⟨e⟩
exact Sigma.eq rfl (Basis.eq_of_apply_eq <| finZeroElim)
/-- A submodule inside a free `R`-submodule of finite rank is also a free `R`-module of finite rank,
if `R` is a principal ideal domain.
See also the stronger version `Submodule.smithNormalFormOfLE`.
-/
noncomputable def Submodule.basisOfPidOfLE {ι : Type*} [Finite ι] {N O : Submodule R M}
(hNO : N ≤ O) (b : Basis ι R O) : Σn : ℕ, Basis (Fin n) R N :=
let ⟨n, bN'⟩ := Submodule.basisOfPid b (N.comap O.subtype)
⟨n, bN'.map (Submodule.comapSubtypeEquivOfLe hNO)⟩
/-- A submodule inside the span of a linear independent family is a free `R`-module of finite rank,
if `R` is a principal ideal domain. -/
noncomputable def Submodule.basisOfPidOfLESpan {ι : Type*} [Finite ι] {b : ι → M}
(hb : LinearIndependent R b) {N : Submodule R M} (le : N ≤ Submodule.span R (Set.range b)) :
Σn : ℕ, Basis (Fin n) R N :=
Submodule.basisOfPidOfLE le (Basis.span hb)
/-- A finite type torsion free module over a PID admits a basis. -/
noncomputable def Module.basisOfFiniteTypeTorsionFree [Fintype ι] {s : ι → M}
(hs : span R (range s) = ⊤) [NoZeroSMulDivisors R M] : Σn : ℕ, Basis (Fin n) R M := by
classical
-- We define `N` as the submodule spanned by a maximal linear independent subfamily of `s`
have := exists_maximal_independent R s
let I : Set ι := this.choose
obtain
⟨indepI : LinearIndependent R (s ∘ (fun x => x) : I → M), hI :
∀ i ∉ I, ∃ a : R, a ≠ 0 ∧ a • s i ∈ span R (s '' I)⟩ :=
this.choose_spec
let N := span R (range <| (s ∘ (fun x => x) : I → M))
-- same as `span R (s '' I)` but more convenient
let _sI : I → N := fun i ↦ ⟨s i.1, subset_span (mem_range_self i)⟩
-- `s` restricted to `I` is a basis of `N`
let sI_basis : Basis I R N := Basis.span indepI
-- Our first goal is to build `A ≠ 0` such that `A • M ⊆ N`
have exists_a : ∀ i : ι, ∃ a : R, a ≠ 0 ∧ a • s i ∈ N := by
intro i
by_cases hi : i ∈ I
· use 1, zero_ne_one.symm
rw [one_smul]
exact subset_span (mem_range_self (⟨i, hi⟩ : I))
· simpa [image_eq_range s I] using hI i hi
choose a ha ha' using exists_a
let A := ∏ i, a i
have hA : A ≠ 0 := by
rw [Finset.prod_ne_zero_iff]
simpa using ha
-- `M ≃ A • M` because `M` is torsion free and `A ≠ 0`
let φ : M →ₗ[R] M := LinearMap.lsmul R M A
have : LinearMap.ker φ = ⊥ := @LinearMap.ker_lsmul R M _ _ _ _ _ hA
let ψ := LinearEquiv.ofInjective φ (LinearMap.ker_eq_bot.mp this)
have : LinearMap.range φ ≤ N := by
-- as announced, `A • M ⊆ N`
suffices ∀ i, φ (s i) ∈ N by
rw [LinearMap.range_eq_map, ← hs, map_span_le]
rintro _ ⟨i, rfl⟩
apply this
intro i
calc
(∏ j, a j) • s i = (∏ j ∈ {i}ᶜ, a j) • a i • s i := by
rw [Fintype.prod_eq_prod_compl_mul i, mul_smul]
_ ∈ N := N.smul_mem _ (ha' i)
-- Since a submodule of a free `R`-module is free, we get that `A • M` is free
obtain ⟨n, b : Basis (Fin n) R (LinearMap.range φ)⟩ := Submodule.basisOfPidOfLE this sI_basis
-- hence `M` is free.
exact ⟨n, b.map ψ.symm⟩
theorem Module.free_of_finite_type_torsion_free [_root_.Finite ι] {s : ι → M}
(hs : span R (range s) = ⊤) [NoZeroSMulDivisors R M] : Module.Free R M := by
cases nonempty_fintype ι
obtain ⟨n, b⟩ : Σn, Basis (Fin n) R M := Module.basisOfFiniteTypeTorsionFree hs
exact Module.Free.of_basis b
/-- A finite type torsion free module over a PID admits a basis. -/
noncomputable def Module.basisOfFiniteTypeTorsionFree' [Module.Finite R M]
[NoZeroSMulDivisors R M] : Σn : ℕ, Basis (Fin n) R M :=
Module.basisOfFiniteTypeTorsionFree Module.Finite.exists_fin.choose_spec.choose_spec
instance Module.free_of_finite_type_torsion_free' [Module.Finite R M] [NoZeroSMulDivisors R M] :
Module.Free R M := by
obtain ⟨n, b⟩ : Σn, Basis (Fin n) R M := Module.basisOfFiniteTypeTorsionFree'
exact Module.Free.of_basis b
instance {S : Type*} [CommRing S] [Algebra R S] {I : Ideal S} [hI₁ : Module.Finite R I]
[hI₂ : NoZeroSMulDivisors R I] : Module.Free R I := by
have : Module.Finite R (restrictScalars R I) := hI₁
have : NoZeroSMulDivisors R (restrictScalars R I) := hI₂
change Module.Free R (restrictScalars R I)
exact Module.free_of_finite_type_torsion_free'
theorem Module.free_iff_noZeroSMulDivisors [Module.Finite R M] :
Module.Free R M ↔ NoZeroSMulDivisors R M :=
⟨fun _ ↦ inferInstance, fun _ ↦ inferInstance⟩
end StrongRankCondition
section SmithNormal
/-- A Smith normal form basis for a submodule `N` of a module `M` consists of
bases for `M` and `N` such that the inclusion map `N → M` can be written as a
(rectangular) matrix with `a` along the diagonal: in Smith normal form. -/
-- Porting note(#5171): @[nolint has_nonempty_instance]
structure Basis.SmithNormalForm (N : Submodule R M) (ι : Type*) (n : ℕ) where
/-- The basis of M. -/
bM : Basis ι R M
/-- The basis of N. -/
bN : Basis (Fin n) R N
/-- The mapping between the vectors of the bases. -/
f : Fin n ↪ ι
/-- The (diagonal) entries of the matrix. -/
a : Fin n → R
/-- The SNF relation between the vectors of the bases. -/
snf : ∀ i, (bN i : M) = a i • bM (f i)
namespace Basis.SmithNormalForm
variable {n : ℕ} {N : Submodule R M} (snf : Basis.SmithNormalForm N ι n) (m : N)
lemma repr_eq_zero_of_nmem_range {i : ι} (hi : i ∉ Set.range snf.f) :
snf.bM.repr m i = 0 := by
obtain ⟨m, hm⟩ := m
obtain ⟨c, rfl⟩ := snf.bN.mem_submodule_iff.mp hm
replace hi : ∀ j, snf.f j ≠ i := by simpa using hi
simp [Finsupp.single_apply, hi, snf.snf, map_finsupp_sum]
lemma le_ker_coord_of_nmem_range {i : ι} (hi : i ∉ Set.range snf.f) :
N ≤ LinearMap.ker (snf.bM.coord i) :=
fun m hm ↦ snf.repr_eq_zero_of_nmem_range ⟨m, hm⟩ hi
@[simp] lemma repr_apply_embedding_eq_repr_smul {i : Fin n} :
snf.bM.repr m (snf.f i) = snf.bN.repr (snf.a i • m) i := by
obtain ⟨m, hm⟩ := m
obtain ⟨c, rfl⟩ := snf.bN.mem_submodule_iff.mp hm
replace hm : (⟨Finsupp.sum c fun i t ↦ t • (↑(snf.bN i) : M), hm⟩ : N) =
Finsupp.sum c fun i t ↦ t • ⟨snf.bN i, (snf.bN i).2⟩ := by
ext; change _ = N.subtype _; simp [map_finsupp_sum]
classical
simp_rw [hm, map_smul, map_finsupp_sum, map_smul, Subtype.coe_eta, repr_self,
Finsupp.smul_single, smul_eq_mul, mul_one, Finsupp.sum_single, Finsupp.smul_apply, snf.snf,
map_smul, repr_self, Finsupp.smul_single, smul_eq_mul, mul_one, Finsupp.sum_apply,
Finsupp.single_apply, EmbeddingLike.apply_eq_iff_eq, Finsupp.sum_ite_eq',
Finsupp.mem_support_iff, ite_not, mul_comm, ite_eq_right_iff]
exact fun a ↦ (mul_eq_zero_of_right _ a).symm
@[simp] lemma repr_comp_embedding_eq_smul :
snf.bM.repr m ∘ snf.f = snf.a • (snf.bN.repr m : Fin n → R) := by
ext i
simp [Pi.smul_apply (snf.a i)]
@[simp] lemma coord_apply_embedding_eq_smul_coord {i : Fin n} :
snf.bM.coord (snf.f i) ∘ₗ N.subtype = snf.a i • snf.bN.coord i := by
ext m
simp [Pi.smul_apply (snf.a i)]
/-- Given a Smith-normal-form pair of bases for `N ⊆ M`, and a linear endomorphism `f` of `M`
that preserves `N`, the diagonal of the matrix of the restriction `f` to `N` does not depend on
which of the two bases for `N` is used. -/
@[simp]
lemma toMatrix_restrict_eq_toMatrix [Fintype ι] [DecidableEq ι]
(f : M →ₗ[R] M) (hf : ∀ x, f x ∈ N) (hf' : ∀ x ∈ N, f x ∈ N := fun x _ ↦ hf x) {i : Fin n} :
LinearMap.toMatrix snf.bN snf.bN (LinearMap.restrict f hf') i i =
LinearMap.toMatrix snf.bM snf.bM f (snf.f i) (snf.f i) := by
rw [LinearMap.toMatrix_apply, LinearMap.toMatrix_apply,
snf.repr_apply_embedding_eq_repr_smul ⟨_, (hf _)⟩]
congr
ext
simp [snf.snf]
end Basis.SmithNormalForm
variable [IsDomain R] [IsPrincipalIdealRing R]
/-- If `M` is finite free over a PID `R`, then any submodule `N` is free
and we can find a basis for `M` and `N` such that the inclusion map is a diagonal matrix
in Smith normal form.
See `Submodule.smithNormalFormOfLE` for a version of this theorem that returns
a `Basis.SmithNormalForm`.
This is a strengthening of `Submodule.basisOfPidOfLE`.
-/
theorem Submodule.exists_smith_normal_form_of_le [Finite ι] (b : Basis ι R M) (N O : Submodule R M)
(N_le_O : N ≤ O) :
∃ (n o : ℕ) (hno : n ≤ o) (bO : Basis (Fin o) R O) (bN : Basis (Fin n) R N) (a : Fin n → R),
∀ i, (bN i : M) = a i • bO (Fin.castLE hno i) := by
cases nonempty_fintype ι
induction O using inductionOnRank b generalizing N with | ih M0 ih =>
obtain ⟨m, b'M⟩ := M0.basisOfPid b
by_cases N_bot : N = ⊥
· subst N_bot
exact ⟨0, m, Nat.zero_le _, b'M, Basis.empty _, finZeroElim, finZeroElim⟩
obtain ⟨y, hy, a, _, M', M'_le_M, N', _, N'_le_M', y_ortho, _, h⟩ :=
Submodule.basis_of_pid_aux M0 N b'M N_bot N_le_O
obtain ⟨n', m', hn'm', bM', bN', as', has'⟩ := ih M' M'_le_M y hy y_ortho N' N'_le_M'
obtain ⟨bN, h'⟩ := h n' bN'
obtain ⟨hmn, bM, h''⟩ := h' m' hn'm' bM'
obtain ⟨as, has⟩ := h'' as' has'
exact ⟨_, _, hmn, bM, bN, as, has⟩
/-- If `M` is finite free over a PID `R`, then any submodule `N` is free
and we can find a basis for `M` and `N` such that the inclusion map is a diagonal matrix
in Smith normal form.
See `Submodule.exists_smith_normal_form_of_le` for a version of this theorem that doesn't
need to map `N` into a submodule of `O`.
This is a strengthening of `Submodule.basisOfPidOfLe`.
-/
noncomputable def Submodule.smithNormalFormOfLE [Finite ι] (b : Basis ι R M) (N O : Submodule R M)
(N_le_O : N ≤ O) : Σo n : ℕ, Basis.SmithNormalForm (N.comap O.subtype) (Fin o) n := by
choose n o hno bO bN a snf using N.exists_smith_normal_form_of_le b O N_le_O
refine
⟨o, n, bO, bN.map (comapSubtypeEquivOfLe N_le_O).symm, (Fin.castLEEmb hno), a,
fun i ↦ ?_⟩
ext
simp only [snf, Basis.map_apply, Submodule.comapSubtypeEquivOfLe_symm_apply,
Submodule.coe_smul_of_tower, Fin.castLEEmb_apply]
/-- If `M` is finite free over a PID `R`, then any submodule `N` is free
and we can find a basis for `M` and `N` such that the inclusion map is a diagonal matrix
in Smith normal form.
This is a strengthening of `Submodule.basisOfPid`.
See also `Ideal.smithNormalForm`, which moreover proves that the dimension of
an ideal is the same as the dimension of the whole ring.
-/
noncomputable def Submodule.smithNormalForm [Finite ι] (b : Basis ι R M) (N : Submodule R M) :
Σn : ℕ, Basis.SmithNormalForm N ι n :=
let ⟨m, n, bM, bN, f, a, snf⟩ := N.smithNormalFormOfLE b ⊤ le_top
let bM' := bM.map (LinearEquiv.ofTop _ rfl)
let e := bM'.indexEquiv b
⟨n, bM'.reindex e, bN.map (comapSubtypeEquivOfLe le_top), f.trans e.toEmbedding, a, fun i ↦ by
simp only [bM', snf, Basis.map_apply, LinearEquiv.ofTop_apply, Submodule.coe_smul_of_tower,
Submodule.comapSubtypeEquivOfLe_apply_coe, Basis.reindex_apply,
Equiv.toEmbedding_apply, Function.Embedding.trans_apply, Equiv.symm_apply_apply]⟩
section Ideal
variable {S : Type*} [CommRing S] [IsDomain S] [Algebra R S]
/-- If `S` a finite-dimensional ring extension of a PID `R` which is free as an `R`-module,
then any nonzero `S`-ideal `I` is free as an `R`-submodule of `S`, and we can
find a basis for `S` and `I` such that the inclusion map is a square diagonal
matrix.
See `Ideal.exists_smith_normal_form` for a version of this theorem that doesn't
need to map `I` into a submodule of `R`.
This is a strengthening of `Submodule.basisOfPid`.
-/
noncomputable def Ideal.smithNormalForm [Fintype ι] (b : Basis ι R S) (I : Ideal S) (hI : I ≠ ⊥) :
Basis.SmithNormalForm (I.restrictScalars R) ι (Fintype.card ι) :=
let ⟨n, bS, bI, f, a, snf⟩ := (I.restrictScalars R).smithNormalForm b
have eq := Ideal.rank_eq bS hI (bI.map ((restrictScalarsEquiv R S S I).restrictScalars R))
let e : Fin n ≃ Fin (Fintype.card ι) := Fintype.equivOfCardEq (by rw [eq, Fintype.card_fin])
⟨bS, bI.reindex e, e.symm.toEmbedding.trans f, a ∘ e.symm, fun i ↦ by
simp only [snf, Basis.coe_reindex, Function.Embedding.trans_apply, Equiv.toEmbedding_apply,
(· ∘ ·)]⟩
variable [Finite ι]
/-- If `S` a finite-dimensional ring extension of a PID `R` which is free as an `R`-module,
then any nonzero `S`-ideal `I` is free as an `R`-submodule of `S`, and we can
find a basis for `S` and `I` such that the inclusion map is a square diagonal
matrix.
See also `Ideal.smithNormalForm` for a version of this theorem that returns
a `Basis.SmithNormalForm`.
The definitions `Ideal.ringBasis`, `Ideal.selfBasis`, `Ideal.smithCoeffs` are (noncomputable)
choices of values for this existential quantifier.
-/
theorem Ideal.exists_smith_normal_form (b : Basis ι R S) (I : Ideal S) (hI : I ≠ ⊥) :
∃ (b' : Basis ι R S) (a : ι → R) (ab' : Basis ι R I), ∀ i, (ab' i : S) = a i • b' i := by
cases nonempty_fintype ι
let ⟨bS, bI, f, a, snf⟩ := I.smithNormalForm b hI
let e : Fin (Fintype.card ι) ≃ ι :=
Equiv.ofBijective f
((Fintype.bijective_iff_injective_and_card f).mpr ⟨f.injective, Fintype.card_fin _⟩)
have fe : ∀ i, f (e.symm i) = i := e.apply_symm_apply
exact
⟨bS, a ∘ e.symm, (bI.reindex e).map ((restrictScalarsEquiv R S _ _).restrictScalars R),
fun i ↦ by
simp only [snf, fe, Basis.map_apply, LinearEquiv.restrictScalars_apply R,
Submodule.restrictScalarsEquiv_apply, Basis.coe_reindex, (· ∘ ·)]⟩
/-- If `S` a finite-dimensional ring extension of a PID `R` which is free as an `R`-module,
then any nonzero `S`-ideal `I` is free as an `R`-submodule of `S`, and we can
find a basis for `S` and `I` such that the inclusion map is a square diagonal
matrix; this is the basis for `S`.
See `Ideal.selfBasis` for the basis on `I`,
see `Ideal.smithCoeffs` for the entries of the diagonal matrix
and `Ideal.selfBasis_def` for the proof that the inclusion map forms a square diagonal matrix.
-/
noncomputable def Ideal.ringBasis (b : Basis ι R S) (I : Ideal S) (hI : I ≠ ⊥) : Basis ι R S :=
(Ideal.exists_smith_normal_form b I hI).choose
/-- If `S` a finite-dimensional ring extension of a PID `R` which is free as an `R`-module,
then any nonzero `S`-ideal `I` is free as an `R`-submodule of `S`, and we can
find a basis for `S` and `I` such that the inclusion map is a square diagonal
matrix; this is the basis for `I`.
See `Ideal.ringBasis` for the basis on `S`,
see `Ideal.smithCoeffs` for the entries of the diagonal matrix
and `Ideal.selfBasis_def` for the proof that the inclusion map forms a square diagonal matrix.
-/
noncomputable def Ideal.selfBasis (b : Basis ι R S) (I : Ideal S) (hI : I ≠ ⊥) : Basis ι R I :=
(Ideal.exists_smith_normal_form b I hI).choose_spec.choose_spec.choose
/-- If `S` a finite-dimensional ring extension of a PID `R` which is free as an `R`-module,
then any nonzero `S`-ideal `I` is free as an `R`-submodule of `S`, and we can
find a basis for `S` and `I` such that the inclusion map is a square diagonal
matrix; these are the entries of the diagonal matrix.
See `Ideal.ringBasis` for the basis on `S`,
see `Ideal.selfBasis` for the basis on `I`,
and `Ideal.selfBasis_def` for the proof that the inclusion map forms a square diagonal matrix.
-/
noncomputable def Ideal.smithCoeffs (b : Basis ι R S) (I : Ideal S) (hI : I ≠ ⊥) : ι → R :=
(Ideal.exists_smith_normal_form b I hI).choose_spec.choose
/-- If `S` a finite-dimensional ring extension of a PID `R` which is free as an `R`-module,
then any nonzero `S`-ideal `I` is free as an `R`-submodule of `S`, and we can
find a basis for `S` and `I` such that the inclusion map is a square diagonal
matrix.
-/
@[simp]
theorem Ideal.selfBasis_def (b : Basis ι R S) (I : Ideal S) (hI : I ≠ ⊥) :
∀ i, (Ideal.selfBasis b I hI i : S) = Ideal.smithCoeffs b I hI i • Ideal.ringBasis b I hI i :=
(Ideal.exists_smith_normal_form b I hI).choose_spec.choose_spec.choose_spec
@[simp]
theorem Ideal.smithCoeffs_ne_zero (b : Basis ι R S) (I : Ideal S) (hI : I ≠ ⊥) (i) :
Ideal.smithCoeffs b I hI i ≠ 0 := by
intro hi
apply Basis.ne_zero (Ideal.selfBasis b I hI) i
refine Subtype.coe_injective ?_
simp [hi]
-- Porting note: can be inferred in Lean 4 so no longer necessary
end Ideal
end SmithNormal
end PrincipalIdealDomain
/-- A set of linearly independent vectors in a module `M` over a semiring `S` is also linearly
independent over a subring `R` of `K`. -/
theorem LinearIndependent.restrict_scalars_algebras {R S M ι : Type*} [CommSemiring R] [Semiring S]
[AddCommMonoid M] [Algebra R S] [Module R M] [Module S M] [IsScalarTower R S M]
(hinj : Function.Injective (algebraMap R S)) {v : ι → M} (li : LinearIndependent S v) :
LinearIndependent R v :=
LinearIndependent.restrict_scalars (by rwa [Algebra.algebraMap_eq_smul_one'] at hinj) li
|
LinearAlgebra\FreeModule\StrongRankCondition.lean | /-
Copyright (c) 2021 Riccardo Brasca. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Riccardo Brasca
-/
import Mathlib.RingTheory.FiniteType
import Mathlib.LinearAlgebra.InvariantBasisNumber
/-!
# Strong rank condition for commutative rings
We prove that any nontrivial commutative ring satisfies `StrongRankCondition`, meaning that
if there is an injective linear map `(Fin n → R) →ₗ[R] Fin m → R`, then `n ≤ m`. This implies that
any commutative ring satisfies `InvariantBasisNumber`: the rank of a finitely generated free
module is well defined.
## Main result
* `commRing_strongRankCondition R` : `R` has the `StrongRankCondition`.
The `commRing_strongRankCondition` comes from `CommRing.orzechProperty`, proved in
`Mathlib/RingTheory/FiniteType.lean`, which states that any commutative ring satisfies
the `OrzechProperty`, that is, for any finitely generated
`R`-module `M`, any surjective homomorphism `f : N → M` from a submodule `N` of `M` to `M`
is injective.
## References
* [Orzech, Morris. *Onto endomorphisms are isomorphisms*][orzech1971]
* [Djoković, D. Ž. *Epimorphisms of modules which must be isomorphisms*][djokovic1973]
* [Ribenboim, Paulo. *Épimorphismes de modules qui sont nécessairement
des isomorphismes*][ribenboim1971]
-/
variable (R : Type*) [CommRing R] [Nontrivial R]
/-- Any nontrivial commutative ring satisfies the `StrongRankCondition`. -/
instance (priority := 100) commRing_strongRankCondition : StrongRankCondition R :=
inferInstance
|
LinearAlgebra\FreeModule\Finite\Basic.lean | /-
Copyright (c) 2021 Riccardo Brasca. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Riccardo Brasca
-/
import Mathlib.RingTheory.Finiteness
import Mathlib.LinearAlgebra.FreeModule.Basic
/-!
# Finite and free modules
We provide some instances for finite and free modules.
## Main results
* `Module.Free.ChooseBasisIndex.fintype` : If a free module is finite, then any basis is finite.
* `Module.Finite.of_basis` : A free module with a basis indexed by a `Fintype` is finite.
-/
universe u v w
variable (R : Type u) (M : Type v) (N : Type w)
namespace Module.Free
section Ring
variable [Ring R] [AddCommGroup M] [Module R M] [Module.Free R M]
/-- If a free module is finite, then the arbitrary basis is finite. -/
noncomputable instance ChooseBasisIndex.fintype [Module.Finite R M] :
Fintype (Module.Free.ChooseBasisIndex R M) := by
refine @Fintype.ofFinite _ ?_
cases subsingleton_or_nontrivial R
· have := Module.subsingleton R M
rw [ChooseBasisIndex]
infer_instance
· exact Module.Finite.finite_basis (chooseBasis _ _)
end Ring
section CommRing
variable [CommRing R] [AddCommGroup M] [Module R M] [Module.Free R M]
variable [AddCommGroup N] [Module R N] [Module.Free R N]
variable {R}
/-- A free module with a basis indexed by a `Fintype` is finite. -/
theorem _root_.Module.Finite.of_basis {R M ι : Type*} [Semiring R] [AddCommMonoid M] [Module R M]
[_root_.Finite ι] (b : Basis ι R M) : Module.Finite R M := by
cases nonempty_fintype ι
classical
refine ⟨⟨Finset.univ.image b, ?_⟩⟩
simp only [Set.image_univ, Finset.coe_univ, Finset.coe_image, Basis.span_eq]
instance _root_.Module.Finite.matrix {ι₁ ι₂ : Type*} [_root_.Finite ι₁] [_root_.Finite ι₂] :
Module.Finite R (Matrix ι₁ ι₂ R) := by
cases nonempty_fintype ι₁
cases nonempty_fintype ι₂
exact Module.Finite.of_basis (Pi.basis fun _ => Pi.basisFun R _)
end CommRing
end Module.Free
|
LinearAlgebra\FreeModule\Finite\Matrix.lean | /-
Copyright (c) 2021 Riccardo Brasca. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Riccardo Brasca
-/
import Mathlib.LinearAlgebra.Dimension.LinearMap
import Mathlib.LinearAlgebra.FreeModule.StrongRankCondition
/-!
# Finite and free modules using matrices
We provide some instances for finite and free modules involving matrices.
## Main results
* `Module.Free.linearMap` : if `M` and `N` are finite and free, then `M →ₗ[R] N` is free.
* `Module.Finite.ofBasis` : A free module with a basis indexed by a `Fintype` is finite.
* `Module.Finite.linearMap` : if `M` and `N` are finite and free, then `M →ₗ[R] N`
is finite.
-/
universe u u' v w
variable (R : Type u) (S : Type u') (M : Type v) (N : Type w)
open Module.Free (chooseBasis ChooseBasisIndex)
open FiniteDimensional (finrank)
section Ring
variable [Ring R] [Ring S] [AddCommGroup M] [Module R M] [Module.Free R M] [Module.Finite R M]
variable [AddCommGroup N] [Module R N] [Module S N] [SMulCommClass R S N]
private noncomputable def linearMapEquivFun : (M →ₗ[R] N) ≃ₗ[S] ChooseBasisIndex R M → N :=
(chooseBasis R M).repr.congrLeft N S ≪≫ₗ (Finsupp.lsum S).symm ≪≫ₗ
LinearEquiv.piCongrRight fun _ ↦ LinearMap.ringLmapEquivSelf R S N
instance Module.Free.linearMap [Module.Free S N] : Module.Free S (M →ₗ[R] N) :=
Module.Free.of_equiv (linearMapEquivFun R S M N).symm
instance Module.Finite.linearMap [Module.Finite S N] : Module.Finite S (M →ₗ[R] N) :=
Module.Finite.equiv (linearMapEquivFun R S M N).symm
variable [StrongRankCondition R] [StrongRankCondition S] [Module.Free S N]
open Cardinal
theorem FiniteDimensional.rank_linearMap :
Module.rank S (M →ₗ[R] N) = lift.{w} (Module.rank R M) * lift.{v} (Module.rank S N) := by
rw [(linearMapEquivFun R S M N).rank_eq, rank_fun_eq_lift_mul,
← finrank_eq_card_chooseBasisIndex, ← finrank_eq_rank R, lift_natCast]
/-- The finrank of `M →ₗ[R] N` as an `S`-module is `(finrank R M) * (finrank S N)`. -/
theorem FiniteDimensional.finrank_linearMap :
finrank S (M →ₗ[R] N) = finrank R M * finrank S N := by
simp_rw [finrank, rank_linearMap, toNat_mul, toNat_lift]
variable [Module R S] [SMulCommClass R S S]
theorem FiniteDimensional.rank_linearMap_self :
Module.rank S (M →ₗ[R] S) = lift.{u'} (Module.rank R M) := by
rw [rank_linearMap, rank_self, lift_one, mul_one]
theorem FiniteDimensional.finrank_linearMap_self : finrank S (M →ₗ[R] S) = finrank R M := by
rw [finrank_linearMap, finrank_self, mul_one]
end Ring
section AlgHom
variable (K M : Type*) (L : Type v) [CommRing K] [Ring M] [Algebra K M]
[Module.Free K M] [Module.Finite K M] [CommRing L] [IsDomain L] [Algebra K L]
instance Finite.algHom : Finite (M →ₐ[K] L) :=
(linearIndependent_algHom_toLinearMap K M L).finite
open Cardinal
theorem cardinal_mk_algHom_le_rank : #(M →ₐ[K] L) ≤ lift.{v} (Module.rank K M) := by
convert (linearIndependent_algHom_toLinearMap K M L).cardinal_lift_le_rank
· rw [lift_id]
· have := Module.nontrivial K L
rw [lift_id, FiniteDimensional.rank_linearMap_self]
theorem card_algHom_le_finrank : Nat.card (M →ₐ[K] L) ≤ finrank K M := by
convert toNat_le_toNat (cardinal_mk_algHom_le_rank K M L) ?_
· rw [toNat_lift, finrank]
· rw [lift_lt_aleph0]; have := Module.nontrivial K L; apply rank_lt_aleph0
end AlgHom
section Integer
variable [AddCommGroup M] [Module.Finite ℤ M] [Module.Free ℤ M] [AddCommGroup N]
instance Module.Finite.addMonoidHom [Module.Finite ℤ N] : Module.Finite ℤ (M →+ N) :=
Module.Finite.equiv (addMonoidHomLequivInt ℤ).symm
instance Module.Free.addMonoidHom [Module.Free ℤ N] : Module.Free ℤ (M →+ N) :=
letI : Module.Free ℤ (M →ₗ[ℤ] N) := Module.Free.linearMap _ _ _ _
Module.Free.of_equiv (addMonoidHomLequivInt ℤ).symm
end Integer
theorem Matrix.rank_vecMulVec {K m n : Type u} [CommRing K] [Fintype n]
[DecidableEq n] (w : m → K) (v : n → K) : (Matrix.vecMulVec w v).toLin'.rank ≤ 1 := by
nontriviality K
rw [Matrix.vecMulVec_eq (Fin 1), Matrix.toLin'_mul]
refine le_trans (LinearMap.rank_comp_le_left _ _) ?_
refine (LinearMap.rank_le_domain _).trans_eq ?_
rw [rank_fun', Fintype.card_ofSubsingleton, Nat.cast_one]
|
LinearAlgebra\FreeProduct\Basic.lean | /-
Copyright (c) 2024 Robert Maxton. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Robert Maxton
-/
import Mathlib.Algebra.DirectSum.Basic
import Mathlib.LinearAlgebra.TensorAlgebra.ToTensorPower
/-!
# The free product of $R$-algebras
We define the free product of an indexed collection of (noncommutative) $R$-algebras
`(i : ι) → A i`, with `Algebra R (A i)` for all `i` and `R` a commutative
semiring, as the quotient of the tensor algebra on the direct sum
`⨁ (i : ι), A i` by the relation generated by extending the relation
* `aᵢ ⊗ₜ aᵢ' ~ aᵢ aᵢ'` for all `i : ι` and `aᵢ aᵢ' : A i`
* `1ᵢ ~ 1ⱼ` for `1ᵢ := One.one (A i)` and for all `i, j : ι`.
to the whole tensor algebra in an `R`-linear way.
The main result of this file is the universal property of the free product,
which establishes the free product as the coproduct in the category of
general $R$-algebras. (In the category of commutative $R$-algebras, the coproduct
is just `PiTensorProduct`.)
## Main definitions
* `FreeProduct R A` is the free product of the `R`-algebras `A i`, defined as a quotient
of the tensor algebra on the direct sum of the `A i`.
* `FreeProduct_ofPowers R A` is the free product of the `R`-algebras `A i`, defined as a quotient
of the (infinite) direct sum of tensor powers of the `A i`.
* `lift` is the universal property of the free product.
## Main results
* `equivPowerAlgebra` establishes an equivalence between `FreeProduct R A` and
`FreeProduct_ofPowers R A`.
* `FreeProduct` is the coproduct in the category of `R`-algebras.
## TODO
- Induction principle for `FreeProduct`
-/
universe u v w w'
namespace DirectSum
open scoped DirectSum
/--A variant of `DirectSum.induction_on` that uses `DirectSum.lof` instead of `.of`-/
theorem induction_lon {R : Type*} [Semiring R] {ι: Type*} [DecidableEq ι]
{M : ι → Type*} [(i: ι) → AddCommMonoid <| M i] [(i : ι) → Module R (M i)]
{C: (⨁ i, M i) → Prop} (x : ⨁ i, M i)
(H_zero : C 0)
(H_basic : ∀ i (x : M i), C (lof R ι M i x))
(H_plus : ∀ (x y : ⨁ i, M i), C x → C y → C (x + y)) : C x := by
induction x using DirectSum.induction_on with
| H_zero => exact H_zero
| H_basic => exact H_basic _ _
| H_plus x y hx hy => exact H_plus x y hx hy
end DirectSum
namespace RingQuot
universe uS uA uB
/--If two `R`-algebras are `R`-equivalent and their quotients by a relation `rel` are defined,
then their quotients are also `R`-equivalent.
(Special case of the third isomorphism theorem.)-/
def algEquiv_quot_algEquiv
{R : Type u} [CommSemiring R] {A B : Type v} [Semiring A] [Semiring B]
[Algebra R A] [Algebra R B] (f : A ≃ₐ[R] B) (rel : A → A → Prop) :
RingQuot rel ≃ₐ[R] RingQuot (rel on f.symm) :=
AlgEquiv.ofAlgHom
(RingQuot.liftAlgHom R (s := rel)
⟨AlgHom.comp (RingQuot.mkAlgHom R (rel on f.symm)) f,
fun x y h_rel ↦ by
apply RingQuot.mkAlgHom_rel
unfold_let rel; simpa [Function.onFun]⟩)
((RingQuot.liftAlgHom R (s := rel on f.symm)
⟨AlgHom.comp (RingQuot.mkAlgHom R rel) f.symm,
fun x y h ↦ by apply RingQuot.mkAlgHom_rel; simpa⟩))
(by ext b; simp) (by ext a; simp)
/--If two (semi)rings are equivalent and their quotients by a relation `rel` are defined,
then their quotients are also equivalent.
(Special case of `algEquiv_quot_algEquiv` when `R = ℕ`, which in turn is a special
case of the third isomorphism theorem.)-/
def equiv_quot_equiv {A B : Type v} [Semiring A] [Semiring B] (f : A ≃+* B) (rel : A → A → Prop) :
RingQuot rel ≃+* RingQuot (rel on f.symm) :=
let f_alg : A ≃ₐ[ℕ] B :=
AlgEquiv.ofRingEquiv (f := f) (fun n ↦ by simp)
algEquiv_quot_algEquiv f_alg rel |>.toRingEquiv
end RingQuot
open TensorAlgebra DirectSum TensorPower
variable {I : Type u} [DecidableEq I] {i : I} -- The type of the indexing set
(R : Type v) [CommSemiring R] -- The commutative semiring `R`
(A : I → Type w) [∀ i, Semiring (A i)] [∀ i, Algebra R (A i)] -- The collection of `R`-algebras
{B : Type w'} [Semiring B] [Algebra R B] -- Another `R`-algebra
(maps : {i : I} → A i →ₐ[R] B) -- A family of `R`algebra homomorphisms
namespace LinearAlgebra.FreeProduct
instance : Module R (⨁ i, A i) := by infer_instance
/--The free tensor algebra over a direct sum of `R`-algebras, before
taking the quotient by the free product relation.-/
abbrev FreeTensorAlgebra := TensorAlgebra R (⨁ i, A i)
/--The direct sum of tensor powers of a direct sum of `R`-algebras,
before taking the quotient by the free product relation.-/
abbrev PowerAlgebra := ⨁ (n : ℕ), TensorPower R n (⨁ i, A i)
/--The free tensor algebra and its representation as an infinite direct sum
of tensor powers are (noncomputably) equivalent as `R`-algebras.-/
@[reducible] noncomputable def powerAlgebra_equiv_freeAlgebra :
PowerAlgebra R A ≃ₐ[R] FreeTensorAlgebra R A :=
TensorAlgebra.equivDirectSum.symm
/--The generating equivalence relation for elements of the free tensor algebra
that are identified in the free product.-/
inductive rel : FreeTensorAlgebra R A → FreeTensorAlgebra R A → Prop
| id : ∀ {i : I}, rel (ι R <| lof R I A i 1) 1
| prod : ∀ {i : I} {a₁ a₂ : A i},
rel
(tprod R (⨁ i, A i) 2 (fun | 0 => lof R I A i a₁ | 1 => lof R I A i a₂))
(ι R <| lof R I A i (a₁ * a₂))
/--The generating equivalence relation for elements of the power algebra
that are identified in the free product. -/
@[reducible, simp] def rel' := rel R A on ofDirectSum
theorem rel_id (i : I) : rel R A (ι R <| lof R I A i 1) 1 := rel.id
/--The free product of the collection of `R`-algebras `A i`, as a quotient of
`FreeTensorAlgebra R A`.-/
@[reducible] def _root_.LinearAlgebra.FreeProduct := RingQuot <| FreeProduct.rel R A
/--The free product of the collection of `R`-algebras `A i`, as a quotient of `PowerAlgebra R A`-/
@[reducible] def _root_.LinearAlgebra.FreeProduct_ofPowers := RingQuot <| FreeProduct.rel' R A
/--The `R`-algebra equivalence relating `FreeProduct` and `FreeProduct_ofPowers`-/
noncomputable def equivPowerAlgebra : FreeProduct_ofPowers R A ≃ₐ[R] FreeProduct R A :=
RingQuot.algEquiv_quot_algEquiv
(FreeProduct.powerAlgebra_equiv_freeAlgebra R A |>.symm) (FreeProduct.rel R A)
|>.symm
open RingQuot Function
local infixr:60 " ∘ₐ " => AlgHom.comp
instance instSemiring : Semiring (FreeProduct R A) := by infer_instance
instance instAlgebra : Algebra R (FreeProduct R A) := by infer_instance
/--The canonical quotient map `FreeTensorAlgebra R A →ₐ[R] FreeProduct R A`,
as an `R`-algebra homomorphism.-/
abbrev mkAlgHom : FreeTensorAlgebra R A →ₐ[R] FreeProduct R A :=
RingQuot.mkAlgHom R (rel R A)
/--The canonical linear map from the direct sum of the `A i` to the free product.-/
abbrev ι' : (⨁ i, A i) →ₗ[R] FreeProduct R A :=
(mkAlgHom R A).toLinearMap ∘ₗ TensorAlgebra.ι R (M := ⨁ i, A i)
@[simp] theorem ι_apply (x : ⨁ i, A i) :
⟨Quot.mk (Rel <| rel R A) (TensorAlgebra.ι R x)⟩ = ι' R A x := by
aesop (add simp [ι', mkAlgHom, RingQuot.mkAlgHom, mkRingHom])
/--The injection into the free product of any `1 : A i` is the 1 of the free product.-/
theorem identify_one (i : I) : ι' R A (DirectSum.lof R I A i 1) = 1 := by
suffices ι' R A (DirectSum.lof R I A i 1) = mkAlgHom R A 1 by simpa
exact RingQuot.mkAlgHom_rel R <| rel_id R A (i := i)
/--Multiplication in the free product of the injections of any two `aᵢ aᵢ': A i` for
the same `i` is just the injection of multiplication `aᵢ * aᵢ'` in `A i`.-/
theorem mul_injections (a₁ a₂ : A i) :
ι' R A (DirectSum.lof R I A i a₁) * ι' R A (DirectSum.lof R I A i a₂)
= ι' R A (DirectSum.lof R I A i (a₁ * a₂)) := by
convert RingQuot.mkAlgHom_rel R <| rel.prod
aesop
/--The `i`th canonical injection, from `A i` to the free product, as
a linear map.-/
abbrev lof (i : I) : A i →ₗ[R] FreeProduct R A :=
ι' R A ∘ₗ DirectSum.lof R I A i
/--`lof R A i 1 = 1` for all `i`.-/
theorem lof_map_one (i : I) : lof R A i 1 = 1 := by
rw [lof]; dsimp [mkAlgHom]; exact identify_one R A i
/--The `i`th canonical injection, from `A i` to the free product.-/
irreducible_def ι (i : I) : A i →ₐ[R] FreeProduct R A :=
AlgHom.ofLinearMap (ι' R A ∘ₗ DirectSum.lof R I A i)
(lof_map_one R A i) (mul_injections R A · · |>.symm)
/--The family of canonical injection maps, with `i` left implicit.-/
irreducible_def of {i : I} : A i →ₐ[R] FreeProduct R A := ι R A i
/--Universal property of the free product of algebras:
for every `R`-algebra `B`, every family of maps `maps : (i : I) → (A i →ₐ[R] B)` lifts
to a unique arrow `π` from `FreeProduct R A` such that `π ∘ ι i = maps i`.-/
@[simps] def lift : ({i : I} → A i →ₐ[R] B) ≃ (FreeProduct R A →ₐ[R] B) where
toFun maps :=
RingQuot.liftAlgHom R ⟨
TensorAlgebra.lift R <|
DirectSum.toModule R I B <|
(@maps · |>.toLinearMap),
fun x y r ↦ by
cases r with
| id => simp
| prod => simp⟩
invFun π i := π ∘ₐ ι R A i
left_inv π := by
ext i aᵢ
aesop (add simp [ι, ι'])
right_inv maps := by
ext i a
aesop (add simp [ι, ι'])
/--Universal property of the free product of algebras, property:
for every `R`-algebra `B`, every family of maps `maps : (i : I) → (A i →ₐ[R] B)` lifts
to a unique arrow `π` from `FreeProduct R A` such that `π ∘ ι i = maps i`.-/
theorem lift_comp_ι : (lift R A maps) ∘ₐ (ι R A i) = maps := by
ext a
simp [lift_apply, ι]
@[aesop safe destruct] theorem lift_unique
(f : FreeProduct R A →ₐ[R] B) (h : ∀ i, f ∘ₐ ι R A i = maps) :
f = lift R A maps := by
ext i a; simp_rw [AlgHom.ext_iff] at h; specialize h i a
simp [h.symm, ι]
end LinearAlgebra.FreeProduct
|
LinearAlgebra\Matrix\AbsoluteValue.lean | /-
Copyright (c) 2021 Anne Baanen. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Anne Baanen
-/
import Mathlib.Algebra.Order.BigOperators.Ring.Finset
import Mathlib.Data.Int.AbsoluteValue
import Mathlib.LinearAlgebra.Matrix.Determinant.Basic
/-!
# Absolute values and matrices
This file proves some bounds on matrices involving absolute values.
## Main results
* `Matrix.det_le`: if the entries of an `n × n` matrix are bounded by `x`,
then the determinant is bounded by `n! x^n`
* `Matrix.det_sum_le`: if we have `s` `n × n` matrices and the entries of each
matrix are bounded by `x`, then the determinant of their sum is bounded by `n! (s * x)^n`
* `Matrix.det_sum_smul_le`: if we have `s` `n × n` matrices each multiplied by
a constant bounded by `y`, and the entries of each matrix are bounded by `x`,
then the determinant of the linear combination is bounded by `n! (s * y * x)^n`
-/
open Matrix
namespace Matrix
open Equiv Finset
variable {R S : Type*} [CommRing R] [Nontrivial R] [LinearOrderedCommRing S]
variable {n : Type*} [Fintype n] [DecidableEq n]
theorem det_le {A : Matrix n n R} {abv : AbsoluteValue R S} {x : S} (hx : ∀ i j, abv (A i j) ≤ x) :
abv A.det ≤ Nat.factorial (Fintype.card n) • x ^ Fintype.card n :=
calc
abv A.det = abv (∑ σ : Perm n, Perm.sign σ • ∏ i, A (σ i) i) := congr_arg abv (det_apply _)
_ ≤ ∑ σ : Perm n, abv (Perm.sign σ • ∏ i, A (σ i) i) := abv.sum_le _ _
_ = ∑ σ : Perm n, ∏ i, abv (A (σ i) i) :=
(sum_congr rfl fun σ _ => by rw [abv.map_units_int_smul, abv.map_prod])
_ ≤ ∑ _σ : Perm n, ∏ _i : n, x :=
(sum_le_sum fun _ _ => prod_le_prod (fun _ _ => abv.nonneg _) fun _ _ => hx _ _)
_ = ∑ _σ : Perm n, x ^ Fintype.card n :=
(sum_congr rfl fun _ _ => by rw [prod_const, Finset.card_univ])
_ = Nat.factorial (Fintype.card n) • x ^ Fintype.card n := by
rw [sum_const, Finset.card_univ, Fintype.card_perm]
theorem det_sum_le {ι : Type*} (s : Finset ι) {A : ι → Matrix n n R} {abv : AbsoluteValue R S}
{x : S} (hx : ∀ k i j, abv (A k i j) ≤ x) :
abv (det (∑ k ∈ s, A k)) ≤
Nat.factorial (Fintype.card n) • (Finset.card s • x) ^ Fintype.card n :=
det_le fun i j =>
calc
abv ((∑ k ∈ s, A k) i j) = abv (∑ k ∈ s, A k i j) := by simp only [sum_apply]
_ ≤ ∑ k ∈ s, abv (A k i j) := abv.sum_le _ _
_ ≤ ∑ _k ∈ s, x := sum_le_sum fun k _ => hx k i j
_ = s.card • x := sum_const _
theorem det_sum_smul_le {ι : Type*} (s : Finset ι) {c : ι → R} {A : ι → Matrix n n R}
{abv : AbsoluteValue R S} {x : S} (hx : ∀ k i j, abv (A k i j) ≤ x) {y : S}
(hy : ∀ k, abv (c k) ≤ y) :
abv (det (∑ k ∈ s, c k • A k)) ≤
Nat.factorial (Fintype.card n) • (Finset.card s • y * x) ^ Fintype.card n := by
simpa only [smul_mul_assoc] using
det_sum_le s fun k i j =>
calc
abv (c k * A k i j) = abv (c k) * abv (A k i j) := abv.map_mul _ _
_ ≤ y * x := mul_le_mul (hy k) (hx k i j) (abv.nonneg _) ((abv.nonneg _).trans (hy k))
end Matrix
|
LinearAlgebra\Matrix\Adjugate.lean | /-
Copyright (c) 2019 Anne Baanen. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Anne Baanen
-/
import Mathlib.Algebra.Regular.Basic
import Mathlib.LinearAlgebra.Matrix.MvPolynomial
import Mathlib.LinearAlgebra.Matrix.Polynomial
import Mathlib.RingTheory.Polynomial.Basic
/-!
# Cramer's rule and adjugate matrices
The adjugate matrix is the transpose of the cofactor matrix.
It is calculated with Cramer's rule, which we introduce first.
The vectors returned by Cramer's rule are given by the linear map `cramer`,
which sends a matrix `A` and vector `b` to the vector consisting of the
determinant of replacing the `i`th column of `A` with `b` at index `i`
(written as `(A.update_column i b).det`).
Using Cramer's rule, we can compute for each matrix `A` the matrix `adjugate A`.
The entries of the adjugate are the minors of `A`.
Instead of defining a minor by deleting row `i` and column `j` of `A`, we
replace the `i`th row of `A` with the `j`th basis vector; the resulting matrix
has the same determinant but more importantly equals Cramer's rule applied
to `A` and the `j`th basis vector, simplifying the subsequent proofs.
We prove the adjugate behaves like `det A • A⁻¹`.
## Main definitions
* `Matrix.cramer A b`: the vector output by Cramer's rule on `A` and `b`.
* `Matrix.adjugate A`: the adjugate (or classical adjoint) of the matrix `A`.
## References
* https://en.wikipedia.org/wiki/Cramer's_rule#Finding_inverse_matrix
## Tags
cramer, cramer's rule, adjugate
-/
namespace Matrix
universe u v w
variable {m : Type u} {n : Type v} {α : Type w}
variable [DecidableEq n] [Fintype n] [DecidableEq m] [Fintype m] [CommRing α]
open Matrix Polynomial Equiv Equiv.Perm Finset
section Cramer
/-!
### `cramer` section
Introduce the linear map `cramer` with values defined by `cramerMap`.
After defining `cramerMap` and showing it is linear,
we will restrict our proofs to using `cramer`.
-/
variable (A : Matrix n n α) (b : n → α)
/-- `cramerMap A b i` is the determinant of the matrix `A` with column `i` replaced with `b`,
and thus `cramerMap A b` is the vector output by Cramer's rule on `A` and `b`.
If `A * x = b` has a unique solution in `x`, `cramerMap A` sends the vector `b` to `A.det • x`.
Otherwise, the outcome of `cramerMap` is well-defined but not necessarily useful.
-/
def cramerMap (i : n) : α :=
(A.updateColumn i b).det
theorem cramerMap_is_linear (i : n) : IsLinearMap α fun b => cramerMap A b i :=
{ map_add := det_updateColumn_add _ _
map_smul := det_updateColumn_smul _ _ }
theorem cramer_is_linear : IsLinearMap α (cramerMap A) := by
constructor <;> intros <;> ext i
· apply (cramerMap_is_linear A i).1
· apply (cramerMap_is_linear A i).2
/-- `cramer A b i` is the determinant of the matrix `A` with column `i` replaced with `b`,
and thus `cramer A b` is the vector output by Cramer's rule on `A` and `b`.
If `A * x = b` has a unique solution in `x`, `cramer A` sends the vector `b` to `A.det • x`.
Otherwise, the outcome of `cramer` is well-defined but not necessarily useful.
-/
def cramer (A : Matrix n n α) : (n → α) →ₗ[α] (n → α) :=
IsLinearMap.mk' (cramerMap A) (cramer_is_linear A)
theorem cramer_apply (i : n) : cramer A b i = (A.updateColumn i b).det :=
rfl
theorem cramer_transpose_apply (i : n) : cramer Aᵀ b i = (A.updateRow i b).det := by
rw [cramer_apply, updateColumn_transpose, det_transpose]
theorem cramer_transpose_row_self (i : n) : Aᵀ.cramer (A i) = Pi.single i A.det := by
ext j
rw [cramer_apply, Pi.single_apply]
split_ifs with h
· -- i = j: this entry should be `A.det`
subst h
simp only [updateColumn_transpose, det_transpose, updateRow_eq_self]
· -- i ≠ j: this entry should be 0
rw [updateColumn_transpose, det_transpose]
apply det_zero_of_row_eq h
rw [updateRow_self, updateRow_ne (Ne.symm h)]
theorem cramer_row_self (i : n) (h : ∀ j, b j = A j i) : A.cramer b = Pi.single i A.det := by
rw [← transpose_transpose A, det_transpose]
convert cramer_transpose_row_self Aᵀ i
exact funext h
@[simp]
theorem cramer_one : cramer (1 : Matrix n n α) = 1 := by
-- Porting note: was `ext i j`
refine LinearMap.pi_ext' (fun (i : n) => LinearMap.ext_ring (funext (fun (j : n) => ?_)))
convert congr_fun (cramer_row_self (1 : Matrix n n α) (Pi.single i 1) i _) j
· simp
· intro j
rw [Matrix.one_eq_pi_single, Pi.single_comm]
theorem cramer_smul (r : α) (A : Matrix n n α) :
cramer (r • A) = r ^ (Fintype.card n - 1) • cramer A :=
LinearMap.ext fun _ => funext fun _ => det_updateColumn_smul' _ _ _ _
@[simp]
theorem cramer_subsingleton_apply [Subsingleton n] (A : Matrix n n α) (b : n → α) (i : n) :
cramer A b i = b i := by rw [cramer_apply, det_eq_elem_of_subsingleton _ i, updateColumn_self]
theorem cramer_zero [Nontrivial n] : cramer (0 : Matrix n n α) = 0 := by
ext i j
obtain ⟨j', hj'⟩ : ∃ j', j' ≠ j := exists_ne j
apply det_eq_zero_of_column_eq_zero j'
intro j''
simp [updateColumn_ne hj']
/-- Use linearity of `cramer` to take it out of a summation. -/
theorem sum_cramer {β} (s : Finset β) (f : β → n → α) :
(∑ x ∈ s, cramer A (f x)) = cramer A (∑ x ∈ s, f x) :=
(map_sum (cramer A) ..).symm
/-- Use linearity of `cramer` and vector evaluation to take `cramer A _ i` out of a summation. -/
theorem sum_cramer_apply {β} (s : Finset β) (f : n → β → α) (i : n) :
(∑ x ∈ s, cramer A (fun j => f j x) i) = cramer A (fun j : n => ∑ x ∈ s, f j x) i :=
calc
(∑ x ∈ s, cramer A (fun j => f j x) i) = (∑ x ∈ s, cramer A fun j => f j x) i :=
(Finset.sum_apply i s _).symm
_ = cramer A (fun j : n => ∑ x ∈ s, f j x) i := by
rw [sum_cramer, cramer_apply, cramer_apply]
simp only [updateColumn]
congr with j
congr
apply Finset.sum_apply
theorem cramer_submatrix_equiv (A : Matrix m m α) (e : n ≃ m) (b : n → α) :
cramer (A.submatrix e e) b = cramer A (b ∘ e.symm) ∘ e := by
ext i
simp_rw [Function.comp_apply, cramer_apply, updateColumn_submatrix_equiv,
det_submatrix_equiv_self e, Function.comp]
theorem cramer_reindex (e : m ≃ n) (A : Matrix m m α) (b : n → α) :
cramer (reindex e e A) b = cramer A (b ∘ e) ∘ e.symm :=
cramer_submatrix_equiv _ _ _
end Cramer
section Adjugate
/-!
### `adjugate` section
Define the `adjugate` matrix and a few equations.
These will hold for any matrix over a commutative ring.
-/
/-- The adjugate matrix is the transpose of the cofactor matrix.
Typically, the cofactor matrix is defined by taking minors,
i.e. the determinant of the matrix with a row and column removed.
However, the proof of `mul_adjugate` becomes a lot easier if we use the
matrix replacing a column with a basis vector, since it allows us to use
facts about the `cramer` map.
-/
def adjugate (A : Matrix n n α) : Matrix n n α :=
of fun i => cramer Aᵀ (Pi.single i 1)
theorem adjugate_def (A : Matrix n n α) : adjugate A = of fun i => cramer Aᵀ (Pi.single i 1) :=
rfl
theorem adjugate_apply (A : Matrix n n α) (i j : n) :
adjugate A i j = (A.updateRow j (Pi.single i 1)).det := by
rw [adjugate_def, of_apply, cramer_apply, updateColumn_transpose, det_transpose]
theorem adjugate_transpose (A : Matrix n n α) : (adjugate A)ᵀ = adjugate Aᵀ := by
ext i j
rw [transpose_apply, adjugate_apply, adjugate_apply, updateRow_transpose, det_transpose]
rw [det_apply', det_apply']
apply Finset.sum_congr rfl
intro σ _
congr 1
by_cases h : i = σ j
· -- Everything except `(i , j)` (= `(σ j , j)`) is given by A, and the rest is a single `1`.
congr
ext j'
subst h
have : σ j' = σ j ↔ j' = j := σ.injective.eq_iff
rw [updateRow_apply, updateColumn_apply]
simp_rw [this]
rw [← dite_eq_ite, ← dite_eq_ite]
congr 1 with rfl
rw [Pi.single_eq_same, Pi.single_eq_same]
· -- Otherwise, we need to show that there is a `0` somewhere in the product.
have : (∏ j' : n, updateColumn A j (Pi.single i 1) (σ j') j') = 0 := by
apply prod_eq_zero (mem_univ j)
rw [updateColumn_self, Pi.single_eq_of_ne' h]
rw [this]
apply prod_eq_zero (mem_univ (σ⁻¹ i))
erw [apply_symm_apply σ i, updateRow_self]
apply Pi.single_eq_of_ne
intro h'
exact h ((symm_apply_eq σ).mp h')
@[simp]
theorem adjugate_submatrix_equiv_self (e : n ≃ m) (A : Matrix m m α) :
adjugate (A.submatrix e e) = (adjugate A).submatrix e e := by
ext i j
rw [adjugate_apply, submatrix_apply, adjugate_apply, ← det_submatrix_equiv_self e,
updateRow_submatrix_equiv]
-- Porting note: added
suffices (fun j => Pi.single i 1 (e.symm j)) = Pi.single (e i) 1 by
erw [this]
exact Function.update_comp_equiv _ e.symm _ _
theorem adjugate_reindex (e : m ≃ n) (A : Matrix m m α) :
adjugate (reindex e e A) = reindex e e (adjugate A) :=
adjugate_submatrix_equiv_self _ _
/-- Since the map `b ↦ cramer A b` is linear in `b`, it must be multiplication by some matrix. This
matrix is `A.adjugate`. -/
theorem cramer_eq_adjugate_mulVec (A : Matrix n n α) (b : n → α) :
cramer A b = A.adjugate *ᵥ b := by
nth_rw 2 [← A.transpose_transpose]
rw [← adjugate_transpose, adjugate_def]
have : b = ∑ i, b i • (Pi.single i 1 : n → α) := by
refine (pi_eq_sum_univ b).trans ?_
congr with j
-- Porting note: needed to help `Pi.smul_apply`
simp [Pi.single_apply, eq_comm, Pi.smul_apply (b j)]
conv_lhs =>
rw [this]
ext k
simp [mulVec, dotProduct, mul_comm]
theorem mul_adjugate_apply (A : Matrix n n α) (i j k) :
A i k * adjugate A k j = cramer Aᵀ (Pi.single k (A i k)) j := by
erw [← smul_eq_mul, adjugate, of_apply, ← Pi.smul_apply, ← LinearMap.map_smul, ← Pi.single_smul',
smul_eq_mul, mul_one]
theorem mul_adjugate (A : Matrix n n α) : A * adjugate A = A.det • (1 : Matrix n n α) := by
ext i j
rw [mul_apply, Pi.smul_apply, Pi.smul_apply, one_apply, smul_eq_mul, mul_boole]
simp [mul_adjugate_apply, sum_cramer_apply, cramer_transpose_row_self, Pi.single_apply, eq_comm]
theorem adjugate_mul (A : Matrix n n α) : adjugate A * A = A.det • (1 : Matrix n n α) :=
calc
adjugate A * A = (Aᵀ * adjugate Aᵀ)ᵀ := by
rw [← adjugate_transpose, ← transpose_mul, transpose_transpose]
_ = _ := by rw [mul_adjugate Aᵀ, det_transpose, transpose_smul, transpose_one]
theorem adjugate_smul (r : α) (A : Matrix n n α) :
adjugate (r • A) = r ^ (Fintype.card n - 1) • adjugate A := by
rw [adjugate, adjugate, transpose_smul, cramer_smul]
rfl
/-- A stronger form of **Cramer's rule** that allows us to solve some instances of `A * x = b` even
if the determinant is not a unit. A sufficient (but still not necessary) condition is that `A.det`
divides `b`. -/
@[simp]
theorem mulVec_cramer (A : Matrix n n α) (b : n → α) : A *ᵥ cramer A b = A.det • b := by
rw [cramer_eq_adjugate_mulVec, mulVec_mulVec, mul_adjugate, smul_mulVec_assoc, one_mulVec]
theorem adjugate_subsingleton [Subsingleton n] (A : Matrix n n α) : adjugate A = 1 := by
ext i j
simp [Subsingleton.elim i j, adjugate_apply, det_eq_elem_of_subsingleton _ i, one_apply]
theorem adjugate_eq_one_of_card_eq_one {A : Matrix n n α} (h : Fintype.card n = 1) :
adjugate A = 1 :=
haveI : Subsingleton n := Fintype.card_le_one_iff_subsingleton.mp h.le
adjugate_subsingleton _
@[simp]
theorem adjugate_zero [Nontrivial n] : adjugate (0 : Matrix n n α) = 0 := by
ext i j
obtain ⟨j', hj'⟩ : ∃ j', j' ≠ j := exists_ne j
apply det_eq_zero_of_column_eq_zero j'
intro j''
simp [updateColumn_ne hj']
@[simp]
theorem adjugate_one : adjugate (1 : Matrix n n α) = 1 := by
ext
simp [adjugate_def, Matrix.one_apply, Pi.single_apply, eq_comm]
@[simp]
theorem adjugate_diagonal (v : n → α) :
adjugate (diagonal v) = diagonal fun i => ∏ j ∈ Finset.univ.erase i, v j := by
ext i j
simp only [adjugate_def, cramer_apply, diagonal_transpose, of_apply]
obtain rfl | hij := eq_or_ne i j
· rw [diagonal_apply_eq, diagonal_updateColumn_single, det_diagonal,
prod_update_of_mem (Finset.mem_univ _), sdiff_singleton_eq_erase, one_mul]
· rw [diagonal_apply_ne _ hij]
refine det_eq_zero_of_row_eq_zero j fun k => ?_
obtain rfl | hjk := eq_or_ne k j
· rw [updateColumn_self, Pi.single_eq_of_ne' hij]
· rw [updateColumn_ne hjk, diagonal_apply_ne' _ hjk]
theorem _root_.RingHom.map_adjugate {R S : Type*} [CommRing R] [CommRing S] (f : R →+* S)
(M : Matrix n n R) : f.mapMatrix M.adjugate = Matrix.adjugate (f.mapMatrix M) := by
ext i k
have : Pi.single i (1 : S) = f ∘ Pi.single i 1 := by
rw [← f.map_one]
exact Pi.single_op (fun _ => f) (fun _ => f.map_zero) i (1 : R)
rw [adjugate_apply, RingHom.mapMatrix_apply, map_apply, RingHom.mapMatrix_apply, this, ←
map_updateRow, ← RingHom.mapMatrix_apply, ← RingHom.map_det, ← adjugate_apply]
theorem _root_.AlgHom.map_adjugate {R A B : Type*} [CommSemiring R] [CommRing A] [CommRing B]
[Algebra R A] [Algebra R B] (f : A →ₐ[R] B) (M : Matrix n n A) :
f.mapMatrix M.adjugate = Matrix.adjugate (f.mapMatrix M) :=
f.toRingHom.map_adjugate _
theorem det_adjugate (A : Matrix n n α) : (adjugate A).det = A.det ^ (Fintype.card n - 1) := by
-- get rid of the `- 1`
rcases (Fintype.card n).eq_zero_or_pos with h_card | h_card
· haveI : IsEmpty n := Fintype.card_eq_zero_iff.mp h_card
rw [h_card, Nat.zero_sub, pow_zero, adjugate_subsingleton, det_one]
replace h_card := tsub_add_cancel_of_le h_card.nat_succ_le
-- express `A` as an evaluation of a polynomial in n^2 variables, and solve in the polynomial ring
-- where `A'.det` is non-zero.
let A' := mvPolynomialX n n ℤ
suffices A'.adjugate.det = A'.det ^ (Fintype.card n - 1) by
rw [← mvPolynomialX_mapMatrix_aeval ℤ A, ← AlgHom.map_adjugate, ← AlgHom.map_det, ←
AlgHom.map_det, ← map_pow, this]
apply mul_left_cancel₀ (show A'.det ≠ 0 from det_mvPolynomialX_ne_zero n ℤ)
calc
A'.det * A'.adjugate.det = (A' * adjugate A').det := (det_mul _ _).symm
_ = A'.det ^ Fintype.card n := by rw [mul_adjugate, det_smul, det_one, mul_one]
_ = A'.det * A'.det ^ (Fintype.card n - 1) := by rw [← pow_succ', h_card]
@[simp]
theorem adjugate_fin_zero (A : Matrix (Fin 0) (Fin 0) α) : adjugate A = 0 :=
Subsingleton.elim _ _
@[simp]
theorem adjugate_fin_one (A : Matrix (Fin 1) (Fin 1) α) : adjugate A = 1 :=
adjugate_subsingleton A
theorem adjugate_fin_succ_eq_det_submatrix {n : ℕ} (A : Matrix (Fin n.succ) (Fin n.succ) α) (i j) :
adjugate A i j = (-1) ^ (j + i : ℕ) * det (A.submatrix j.succAbove i.succAbove) := by
simp_rw [adjugate_apply, det_succ_row _ j, updateRow_self, submatrix_updateRow_succAbove]
rw [Fintype.sum_eq_single i fun h hjk => ?_, Pi.single_eq_same, mul_one]
rw [Pi.single_eq_of_ne hjk, mul_zero, zero_mul]
theorem adjugate_fin_two (A : Matrix (Fin 2) (Fin 2) α) :
adjugate A = !![A 1 1, -A 0 1; -A 1 0, A 0 0] := by
ext i j
rw [adjugate_fin_succ_eq_det_submatrix]
fin_cases i <;> fin_cases j <;> simp
@[simp]
theorem adjugate_fin_two_of (a b c d : α) : adjugate !![a, b; c, d] = !![d, -b; -c, a] :=
adjugate_fin_two _
theorem adjugate_fin_three (A : Matrix (Fin 3) (Fin 3) α) :
adjugate A =
!![A 1 1 * A 2 2 - A 1 2 * A 2 1,
-(A 0 1 * A 2 2) + A 0 2 * A 2 1,
A 0 1 * A 1 2 - A 0 2 * A 1 1;
-(A 1 0 * A 2 2) + A 1 2 * A 2 0,
A 0 0 * A 2 2 - A 0 2 * A 2 0,
-(A 0 0 * A 1 2) + A 0 2 * A 1 0;
A 1 0 * A 2 1 - A 1 1 * A 2 0,
-(A 0 0 * A 2 1) + A 0 1 * A 2 0,
A 0 0 * A 1 1 - A 0 1 * A 1 0] := by
ext i j
rw [adjugate_fin_succ_eq_det_submatrix, det_fin_two]
fin_cases i <;> fin_cases j <;> simp [updateRow, Fin.succAbove, Fin.lt_def] <;> ring
@[simp]
theorem adjugate_fin_three_of (a b c d e f g h i : α) :
adjugate !![a, b, c; d, e, f; g, h, i] =
!![ e * i - f * h, -(b * i) + c * h, b * f - c * e;
-(d * i) + f * g, a * i - c * g, -(a * f) + c * d;
d * h - e * g, -(a * h) + b * g, a * e - b * d] :=
adjugate_fin_three _
theorem det_eq_sum_mul_adjugate_row (A : Matrix n n α) (i : n) :
det A = ∑ j : n, A i j * adjugate A j i := by
haveI : Nonempty n := ⟨i⟩
obtain ⟨n', hn'⟩ := Nat.exists_eq_succ_of_ne_zero (Fintype.card_ne_zero : Fintype.card n ≠ 0)
obtain ⟨e⟩ := Fintype.truncEquivFinOfCardEq hn'
let A' := reindex e e A
suffices det A' = ∑ j : Fin n'.succ, A' (e i) j * adjugate A' j (e i) by
simp_rw [A', det_reindex_self, adjugate_reindex, reindex_apply, submatrix_apply, ← e.sum_comp,
Equiv.symm_apply_apply] at this
exact this
rw [det_succ_row A' (e i)]
simp_rw [mul_assoc, mul_left_comm _ (A' _ _), ← adjugate_fin_succ_eq_det_submatrix]
theorem det_eq_sum_mul_adjugate_col (A : Matrix n n α) (j : n) :
det A = ∑ i : n, A i j * adjugate A j i := by
simpa only [det_transpose, ← adjugate_transpose] using det_eq_sum_mul_adjugate_row Aᵀ j
theorem adjugate_conjTranspose [StarRing α] (A : Matrix n n α) : A.adjugateᴴ = adjugate Aᴴ := by
dsimp only [conjTranspose]
have : Aᵀ.adjugate.map star = adjugate (Aᵀ.map star) := (starRingEnd α).map_adjugate Aᵀ
rw [A.adjugate_transpose, this]
theorem isRegular_of_isLeftRegular_det {A : Matrix n n α} (hA : IsLeftRegular A.det) :
IsRegular A := by
constructor
· intro B C h
refine hA.matrix ?_
simp only at h ⊢
rw [← Matrix.one_mul B, ← Matrix.one_mul C, ← Matrix.smul_mul, ← Matrix.smul_mul, ←
adjugate_mul, Matrix.mul_assoc, Matrix.mul_assoc, h]
· intro B C (h : B * A = C * A)
refine hA.matrix ?_
simp only
rw [← Matrix.mul_one B, ← Matrix.mul_one C, ← Matrix.mul_smul, ← Matrix.mul_smul, ←
mul_adjugate, ← Matrix.mul_assoc, ← Matrix.mul_assoc, h]
theorem adjugate_mul_distrib_aux (A B : Matrix n n α) (hA : IsLeftRegular A.det)
(hB : IsLeftRegular B.det) : adjugate (A * B) = adjugate B * adjugate A := by
have hAB : IsLeftRegular (A * B).det := by
rw [det_mul]
exact hA.mul hB
refine (isRegular_of_isLeftRegular_det hAB).left ?_
simp only
rw [mul_adjugate, Matrix.mul_assoc, ← Matrix.mul_assoc B, mul_adjugate,
smul_mul, Matrix.one_mul, mul_smul, mul_adjugate, smul_smul, mul_comm, ← det_mul]
/-- Proof follows from "The trace Cayley-Hamilton theorem" by Darij Grinberg, Section 5.3
-/
theorem adjugate_mul_distrib (A B : Matrix n n α) : adjugate (A * B) = adjugate B * adjugate A := by
let g : Matrix n n α → Matrix n n α[X] := fun M =>
M.map Polynomial.C + (Polynomial.X : α[X]) • (1 : Matrix n n α[X])
let f' : Matrix n n α[X] →+* Matrix n n α := (Polynomial.evalRingHom 0).mapMatrix
have f'_inv : ∀ M, f' (g M) = M := by
intro
ext
simp [f', g]
have f'_adj : ∀ M : Matrix n n α, f' (adjugate (g M)) = adjugate M := by
intro
rw [RingHom.map_adjugate, f'_inv]
have f'_g_mul : ∀ M N : Matrix n n α, f' (g M * g N) = M * N := by
intros M N
rw [RingHom.map_mul, f'_inv, f'_inv]
have hu : ∀ M : Matrix n n α, IsRegular (g M).det := by
intro M
refine Polynomial.Monic.isRegular ?_
simp only [g, Polynomial.Monic.def, ← Polynomial.leadingCoeff_det_X_one_add_C M, add_comm]
rw [← f'_adj, ← f'_adj, ← f'_adj, ← f'.map_mul, ←
adjugate_mul_distrib_aux _ _ (hu A).left (hu B).left, RingHom.map_adjugate,
RingHom.map_adjugate, f'_inv, f'_g_mul]
@[simp]
theorem adjugate_pow (A : Matrix n n α) (k : ℕ) : adjugate (A ^ k) = adjugate A ^ k := by
induction' k with k IH
· simp
· rw [pow_succ', adjugate_mul_distrib, IH, pow_succ]
theorem det_smul_adjugate_adjugate (A : Matrix n n α) :
det A • adjugate (adjugate A) = det A ^ (Fintype.card n - 1) • A := by
have : A * (A.adjugate * A.adjugate.adjugate) =
A * (A.det ^ (Fintype.card n - 1) • (1 : Matrix n n α)) := by
rw [← adjugate_mul_distrib, adjugate_mul, adjugate_smul, adjugate_one]
rwa [← Matrix.mul_assoc, mul_adjugate, Matrix.mul_smul, Matrix.mul_one, Matrix.smul_mul,
Matrix.one_mul] at this
/-- Note that this is not true for `Fintype.card n = 1` since `1 - 2 = 0` and not `-1`. -/
theorem adjugate_adjugate (A : Matrix n n α) (h : Fintype.card n ≠ 1) :
adjugate (adjugate A) = det A ^ (Fintype.card n - 2) • A := by
-- get rid of the `- 2`
cases' h_card : Fintype.card n with n'
· subsingleton [Fintype.card_eq_zero_iff.mp h_card]
cases n'
· exact (h h_card).elim
rw [← h_card]
-- express `A` as an evaluation of a polynomial in n^2 variables, and solve in the polynomial ring
-- where `A'.det` is non-zero.
let A' := mvPolynomialX n n ℤ
suffices adjugate (adjugate A') = det A' ^ (Fintype.card n - 2) • A' by
rw [← mvPolynomialX_mapMatrix_aeval ℤ A, ← AlgHom.map_adjugate, ← AlgHom.map_adjugate, this,
← AlgHom.map_det, ← map_pow (MvPolynomial.aeval _), AlgHom.mapMatrix_apply,
AlgHom.mapMatrix_apply, Matrix.map_smul' _ _ _ (_root_.map_mul _)]
have h_card' : Fintype.card n - 2 + 1 = Fintype.card n - 1 := by simp [h_card]
have is_reg : IsSMulRegular (MvPolynomial (n × n) ℤ) (det A') := fun x y =>
mul_left_cancel₀ (det_mvPolynomialX_ne_zero n ℤ)
apply is_reg.matrix
simp only
rw [smul_smul, ← pow_succ', h_card', det_smul_adjugate_adjugate]
/-- A weaker version of `Matrix.adjugate_adjugate` that uses `Nontrivial`. -/
theorem adjugate_adjugate' (A : Matrix n n α) [Nontrivial n] :
adjugate (adjugate A) = det A ^ (Fintype.card n - 2) • A :=
adjugate_adjugate _ <| Fintype.one_lt_card.ne'
end Adjugate
end Matrix
|
LinearAlgebra\Matrix\Basis.lean | /-
Copyright (c) 2019 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Patrick Massot, Casper Putz, Anne Baanen
-/
import Mathlib.LinearAlgebra.Matrix.Reindex
import Mathlib.LinearAlgebra.Matrix.ToLin
/-!
# Bases and matrices
This file defines the map `Basis.toMatrix` that sends a family of vectors to
the matrix of their coordinates with respect to some basis.
## Main definitions
* `Basis.toMatrix e v` is the matrix whose `i, j`th entry is `e.repr (v j) i`
* `basis.toMatrixEquiv` is `Basis.toMatrix` bundled as a linear equiv
## Main results
* `LinearMap.toMatrix_id_eq_basis_toMatrix`: `LinearMap.toMatrix b c id`
is equal to `Basis.toMatrix b c`
* `Basis.toMatrix_mul_toMatrix`: multiplying `Basis.toMatrix` with another
`Basis.toMatrix` gives a `Basis.toMatrix`
## Tags
matrix, basis
-/
noncomputable section
open LinearMap Matrix Set Submodule
open Matrix
section BasisToMatrix
variable {ι ι' κ κ' : Type*}
variable {R M : Type*} [CommSemiring R] [AddCommMonoid M] [Module R M]
variable {R₂ M₂ : Type*} [CommRing R₂] [AddCommGroup M₂] [Module R₂ M₂]
open Function Matrix
/-- From a basis `e : ι → M` and a family of vectors `v : ι' → M`, make the matrix whose columns
are the vectors `v i` written in the basis `e`. -/
def Basis.toMatrix (e : Basis ι R M) (v : ι' → M) : Matrix ι ι' R := fun i j => e.repr (v j) i
variable (e : Basis ι R M) (v : ι' → M) (i : ι) (j : ι')
namespace Basis
theorem toMatrix_apply : e.toMatrix v i j = e.repr (v j) i :=
rfl
theorem toMatrix_transpose_apply : (e.toMatrix v)ᵀ j = e.repr (v j) :=
funext fun _ => rfl
theorem toMatrix_eq_toMatrix_constr [Fintype ι] [DecidableEq ι] (v : ι → M) :
e.toMatrix v = LinearMap.toMatrix e e (e.constr ℕ v) := by
ext
rw [Basis.toMatrix_apply, LinearMap.toMatrix_apply, Basis.constr_basis]
-- TODO (maybe) Adjust the definition of `Basis.toMatrix` to eliminate the transpose.
theorem coePiBasisFun.toMatrix_eq_transpose [Finite ι] :
((Pi.basisFun R ι).toMatrix : Matrix ι ι R → Matrix ι ι R) = Matrix.transpose := by
ext M i j
rfl
@[simp]
theorem toMatrix_self [DecidableEq ι] : e.toMatrix e = 1 := by
unfold Basis.toMatrix
ext i j
simp [Basis.equivFun, Matrix.one_apply, Finsupp.single_apply, eq_comm]
theorem toMatrix_update [DecidableEq ι'] (x : M) :
e.toMatrix (Function.update v j x) = Matrix.updateColumn (e.toMatrix v) j (e.repr x) := by
ext i' k
rw [Basis.toMatrix, Matrix.updateColumn_apply, e.toMatrix_apply]
split_ifs with h
· rw [h, update_same j x v]
· rw [update_noteq h]
/-- The basis constructed by `unitsSMul` has vectors given by a diagonal matrix. -/
@[simp]
theorem toMatrix_unitsSMul [DecidableEq ι] (e : Basis ι R₂ M₂) (w : ι → R₂ˣ) :
e.toMatrix (e.unitsSMul w) = diagonal ((↑) ∘ w) := by
ext i j
by_cases h : i = j
· simp [h, toMatrix_apply, unitsSMul_apply, Units.smul_def]
· simp [h, toMatrix_apply, unitsSMul_apply, Units.smul_def, Ne.symm h]
/-- The basis constructed by `isUnitSMul` has vectors given by a diagonal matrix. -/
@[simp]
theorem toMatrix_isUnitSMul [DecidableEq ι] (e : Basis ι R₂ M₂) {w : ι → R₂}
(hw : ∀ i, IsUnit (w i)) : e.toMatrix (e.isUnitSMul hw) = diagonal w :=
e.toMatrix_unitsSMul _
theorem toMatrix_smul_left {G} [Group G] [DistribMulAction G M] [SMulCommClass G R M] (g : G) :
(g • e).toMatrix v = e.toMatrix (g⁻¹ • v) := rfl
@[simp]
theorem sum_toMatrix_smul_self [Fintype ι] : ∑ i : ι, e.toMatrix v i j • e i = v j := by
simp_rw [e.toMatrix_apply, e.sum_repr]
theorem toMatrix_smul {R₁ S : Type*} [CommRing R₁] [Ring S] [Algebra R₁ S] [Fintype ι]
[DecidableEq ι] (x : S) (b : Basis ι R₁ S) (w : ι → S) :
(b.toMatrix (x • w)) = (Algebra.leftMulMatrix b x) * (b.toMatrix w) := by
ext
rw [Basis.toMatrix_apply, Pi.smul_apply, smul_eq_mul, ← Algebra.leftMulMatrix_mulVec_repr]
rfl
theorem toMatrix_map_vecMul {S : Type*} [Ring S] [Algebra R S] [Fintype ι] (b : Basis ι R S)
(v : ι' → S) : b ᵥ* ((b.toMatrix v).map <| algebraMap R S) = v := by
ext i
simp_rw [vecMul, dotProduct, Matrix.map_apply, ← Algebra.commutes, ← Algebra.smul_def,
sum_toMatrix_smul_self]
@[simp]
theorem toLin_toMatrix [Finite ι] [Fintype ι'] [DecidableEq ι'] (v : Basis ι' R M) :
Matrix.toLin v e (e.toMatrix v) = LinearMap.id :=
v.ext fun i => by cases nonempty_fintype ι; rw [toLin_self, id_apply, e.sum_toMatrix_smul_self]
/-- From a basis `e : ι → M`, build a linear equivalence between families of vectors `v : ι → M`,
and matrices, making the matrix whose columns are the vectors `v i` written in the basis `e`. -/
def toMatrixEquiv [Fintype ι] (e : Basis ι R M) : (ι → M) ≃ₗ[R] Matrix ι ι R where
toFun := e.toMatrix
map_add' v w := by
ext i j
change _ = _ + _
rw [e.toMatrix_apply, Pi.add_apply, LinearEquiv.map_add]
rfl
map_smul' := by
intro c v
ext i j
dsimp only []
rw [e.toMatrix_apply, Pi.smul_apply, LinearEquiv.map_smul]
rfl
invFun m j := ∑ i, m i j • e i
left_inv := by
intro v
ext j
exact e.sum_toMatrix_smul_self v j
right_inv := by
intro m
ext k l
simp only [e.toMatrix_apply, ← e.equivFun_apply, ← e.equivFun_symm_apply,
LinearEquiv.apply_symm_apply]
variable (R₂) in
theorem restrictScalars_toMatrix [Fintype ι] [DecidableEq ι] {S : Type*} [CommRing S] [Nontrivial S]
[Algebra R₂ S] [Module S M₂] [IsScalarTower R₂ S M₂] [NoZeroSMulDivisors R₂ S]
(b : Basis ι S M₂) (v : ι → span R₂ (Set.range b)) :
(algebraMap R₂ S).mapMatrix ((b.restrictScalars R₂).toMatrix v) =
b.toMatrix (fun i ↦ (v i : M₂)) := by
ext
rw [RingHom.mapMatrix_apply, Matrix.map_apply, Basis.toMatrix_apply,
Basis.restrictScalars_repr_apply, Basis.toMatrix_apply]
end Basis
section MulLinearMapToMatrix
variable {N : Type*} [AddCommMonoid N] [Module R N]
variable (b : Basis ι R M) (b' : Basis ι' R M) (c : Basis κ R N) (c' : Basis κ' R N)
variable (f : M →ₗ[R] N)
open LinearMap
section Fintype
/-- A generalization of `LinearMap.toMatrix_id`. -/
@[simp]
theorem LinearMap.toMatrix_id_eq_basis_toMatrix [Fintype ι] [DecidableEq ι] [Finite ι'] :
LinearMap.toMatrix b b' id = b'.toMatrix b := by
ext i
apply LinearMap.toMatrix_apply
variable [Fintype ι']
@[simp]
theorem basis_toMatrix_mul_linearMap_toMatrix [Finite κ] [Fintype κ'] [DecidableEq ι'] :
c.toMatrix c' * LinearMap.toMatrix b' c' f = LinearMap.toMatrix b' c f :=
(Matrix.toLin b' c).injective <| by
haveI := Classical.decEq κ'
rw [toLin_toMatrix, toLin_mul b' c' c, toLin_toMatrix, c.toLin_toMatrix, LinearMap.id_comp]
theorem basis_toMatrix_mul [Fintype κ] [Finite ι] [DecidableEq κ]
(b₁ : Basis ι R M) (b₂ : Basis ι' R M) (b₃ : Basis κ R N) (A : Matrix ι' κ R) :
b₁.toMatrix b₂ * A = LinearMap.toMatrix b₃ b₁ (toLin b₃ b₂ A) := by
have := basis_toMatrix_mul_linearMap_toMatrix b₃ b₁ b₂ (Matrix.toLin b₃ b₂ A)
rwa [LinearMap.toMatrix_toLin] at this
variable [Finite κ] [Fintype ι]
@[simp]
theorem linearMap_toMatrix_mul_basis_toMatrix [Finite κ'] [DecidableEq ι] [DecidableEq ι'] :
LinearMap.toMatrix b' c' f * b'.toMatrix b = LinearMap.toMatrix b c' f :=
(Matrix.toLin b c').injective <| by
rw [toLin_toMatrix, toLin_mul b b' c', toLin_toMatrix, b'.toLin_toMatrix, LinearMap.comp_id]
theorem basis_toMatrix_mul_linearMap_toMatrix_mul_basis_toMatrix
[Fintype κ'] [DecidableEq ι] [DecidableEq ι'] :
c.toMatrix c' * LinearMap.toMatrix b' c' f * b'.toMatrix b = LinearMap.toMatrix b c f := by
cases nonempty_fintype κ
rw [basis_toMatrix_mul_linearMap_toMatrix, linearMap_toMatrix_mul_basis_toMatrix]
theorem mul_basis_toMatrix [DecidableEq ι] [DecidableEq ι'] (b₁ : Basis ι R M) (b₂ : Basis ι' R M)
(b₃ : Basis κ R N) (A : Matrix κ ι R) :
A * b₁.toMatrix b₂ = LinearMap.toMatrix b₂ b₃ (toLin b₁ b₃ A) := by
cases nonempty_fintype κ
have := linearMap_toMatrix_mul_basis_toMatrix b₂ b₁ b₃ (Matrix.toLin b₁ b₃ A)
rwa [LinearMap.toMatrix_toLin] at this
theorem basis_toMatrix_basisFun_mul (b : Basis ι R (ι → R)) (A : Matrix ι ι R) :
b.toMatrix (Pi.basisFun R ι) * A = of fun i j => b.repr (Aᵀ j) i := by
classical
simp only [basis_toMatrix_mul _ _ (Pi.basisFun R ι), Matrix.toLin_eq_toLin']
ext i j
rw [LinearMap.toMatrix_apply, Matrix.toLin'_apply, Pi.basisFun_apply,
Matrix.mulVec_stdBasis_apply, Matrix.of_apply]
/-- See also `Basis.toMatrix_reindex` which gives the `simp` normal form of this result. -/
theorem Basis.toMatrix_reindex' [DecidableEq ι] [DecidableEq ι'] (b : Basis ι R M) (v : ι' → M)
(e : ι ≃ ι') : (b.reindex e).toMatrix v =
Matrix.reindexAlgEquiv R R e (b.toMatrix (v ∘ e)) := by
ext
simp only [Basis.toMatrix_apply, Basis.repr_reindex, Matrix.reindexAlgEquiv_apply,
Matrix.reindex_apply, Matrix.submatrix_apply, Function.comp_apply, e.apply_symm_apply,
Finsupp.mapDomain_equiv_apply]
end Fintype
/-- A generalization of `Basis.toMatrix_self`, in the opposite direction. -/
@[simp]
theorem Basis.toMatrix_mul_toMatrix {ι'' : Type*} [Fintype ι'] (b'' : ι'' → M) :
b.toMatrix b' * b'.toMatrix b'' = b.toMatrix b'' := by
haveI := Classical.decEq ι
haveI := Classical.decEq ι'
haveI := Classical.decEq ι''
ext i j
simp only [Matrix.mul_apply, Basis.toMatrix_apply, Basis.sum_repr_mul_repr]
/-- `b.toMatrix b'` and `b'.toMatrix b` are inverses. -/
theorem Basis.toMatrix_mul_toMatrix_flip [DecidableEq ι] [Fintype ι'] :
b.toMatrix b' * b'.toMatrix b = 1 := by rw [Basis.toMatrix_mul_toMatrix, Basis.toMatrix_self]
/-- A matrix whose columns form a basis `b'`, expressed w.r.t. a basis `b`, is invertible. -/
def Basis.invertibleToMatrix [DecidableEq ι] [Fintype ι] (b b' : Basis ι R₂ M₂) :
Invertible (b.toMatrix b') :=
⟨b'.toMatrix b, Basis.toMatrix_mul_toMatrix_flip _ _, Basis.toMatrix_mul_toMatrix_flip _ _⟩
@[simp]
theorem Basis.toMatrix_reindex (b : Basis ι R M) (v : ι' → M) (e : ι ≃ ι') :
(b.reindex e).toMatrix v = (b.toMatrix v).submatrix e.symm _root_.id := by
ext
simp only [Basis.toMatrix_apply, Basis.repr_reindex, Matrix.submatrix_apply, _root_.id,
Finsupp.mapDomain_equiv_apply]
@[simp]
theorem Basis.toMatrix_map (b : Basis ι R M) (f : M ≃ₗ[R] N) (v : ι → N) :
(b.map f).toMatrix v = b.toMatrix (f.symm ∘ v) := by
ext
simp only [Basis.toMatrix_apply, Basis.map, LinearEquiv.trans_apply, (· ∘ ·)]
end MulLinearMapToMatrix
end BasisToMatrix
|
LinearAlgebra\Matrix\BilinearForm.lean | /-
Copyright (c) 2020 Anne Baanen. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Anne Baanen, Kexing Ying
-/
import Mathlib.LinearAlgebra.Matrix.Basis
import Mathlib.LinearAlgebra.Matrix.Nondegenerate
import Mathlib.LinearAlgebra.Matrix.NonsingularInverse
import Mathlib.LinearAlgebra.Matrix.ToLinearEquiv
import Mathlib.LinearAlgebra.BilinearForm.Properties
import Mathlib.LinearAlgebra.Matrix.SesquilinearForm
/-!
# Bilinear form
This file defines the conversion between bilinear forms and matrices.
## Main definitions
* `Matrix.toBilin` given a basis define a bilinear form
* `Matrix.toBilin'` define the bilinear form on `n → R`
* `BilinForm.toMatrix`: calculate the matrix coefficients of a bilinear form
* `BilinForm.toMatrix'`: calculate the matrix coefficients of a bilinear form on `n → R`
## Notations
In this file we use the following type variables:
- `M`, `M'`, ... are modules over the commutative semiring `R`,
- `M₁`, `M₁'`, ... are modules over the commutative ring `R₁`,
- `M₂`, `M₂'`, ... are modules over the commutative semiring `R₂`,
- `M₃`, `M₃'`, ... are modules over the commutative ring `R₃`,
- `V`, ... is a vector space over the field `K`.
## Tags
bilinear form, bilin form, BilinearForm, matrix, basis
-/
open LinearMap (BilinForm)
variable {R : Type*} {M : Type*} [CommSemiring R] [AddCommMonoid M] [Module R M]
variable {R₁ : Type*} {M₁ : Type*} [CommRing R₁] [AddCommGroup M₁] [Module R₁ M₁]
variable {R₂ : Type*} {M₂ : Type*} [CommSemiring R₂] [AddCommMonoid M₂] [Module R₂ M₂]
variable {R₃ : Type*} {M₃ : Type*} [CommRing R₃] [AddCommGroup M₃] [Module R₃ M₃]
variable {V : Type*} {K : Type*} [Field K] [AddCommGroup V] [Module K V]
variable {B : BilinForm R M} {B₁ : BilinForm R₁ M₁} {B₂ : BilinForm R₂ M₂}
section Matrix
variable {n o : Type*}
open Finset LinearMap Matrix
open Matrix
/-- The map from `Matrix n n R` to bilinear forms on `n → R`.
This is an auxiliary definition for the equivalence `Matrix.toBilin'`. -/
def Matrix.toBilin'Aux [Fintype n] (M : Matrix n n R₂) : BilinForm R₂ (n → R₂) :=
Matrix.toLinearMap₂'Aux _ _ M
theorem Matrix.toBilin'Aux_stdBasis [Fintype n] [DecidableEq n] (M : Matrix n n R₂) (i j : n) :
M.toBilin'Aux (LinearMap.stdBasis R₂ (fun _ => R₂) i 1)
(LinearMap.stdBasis R₂ (fun _ => R₂) j 1) = M i j :=
Matrix.toLinearMap₂'Aux_stdBasis _ _ _ _ _
/-- The linear map from bilinear forms to `Matrix n n R` given an `n`-indexed basis.
This is an auxiliary definition for the equivalence `Matrix.toBilin'`. -/
def BilinForm.toMatrixAux (b : n → M₂) : BilinForm R₂ M₂ →ₗ[R₂] Matrix n n R₂ :=
LinearMap.toMatrix₂Aux R₂ b b
@[simp]
theorem LinearMap.BilinForm.toMatrixAux_apply (B : BilinForm R₂ M₂) (b : n → M₂) (i j : n) :
-- Porting note: had to hint the base ring even though it should be clear from context...
BilinForm.toMatrixAux (R₂ := R₂) b B i j = B (b i) (b j) :=
LinearMap.toMatrix₂Aux_apply R₂ B _ _ _ _
variable [Fintype n] [Fintype o]
theorem toBilin'Aux_toMatrixAux [DecidableEq n] (B₂ : BilinForm R₂ (n → R₂)) :
-- Porting note: had to hint the base ring even though it should be clear from context...
Matrix.toBilin'Aux (BilinForm.toMatrixAux (R₂ := R₂)
(fun j => stdBasis R₂ (fun _ => R₂) j 1) B₂) = B₂ := by
rw [BilinForm.toMatrixAux, Matrix.toBilin'Aux,
toLinearMap₂'Aux_toMatrix₂Aux]
section ToMatrix'
/-! ### `ToMatrix'` section
This section deals with the conversion between matrices and bilinear forms on `n → R₂`.
-/
variable [DecidableEq n] [DecidableEq o]
/-- The linear equivalence between bilinear forms on `n → R` and `n × n` matrices -/
def LinearMap.BilinForm.toMatrix' : BilinForm R₂ (n → R₂) ≃ₗ[R₂] Matrix n n R₂ :=
LinearMap.toMatrix₂' R₂
@[simp]
theorem LinearMap.BilinForm.toMatrixAux_stdBasis (B : BilinForm R₂ (n → R₂)) :
-- Porting note: had to hint the base ring even though it should be clear from context...
BilinForm.toMatrixAux (R₂ := R₂) (fun j => stdBasis R₂ (fun _ => R₂) j 1) B =
BilinForm.toMatrix' B :=
rfl
/-- The linear equivalence between `n × n` matrices and bilinear forms on `n → R` -/
def Matrix.toBilin' : Matrix n n R₂ ≃ₗ[R₂] BilinForm R₂ (n → R₂) :=
BilinForm.toMatrix'.symm
@[simp]
theorem Matrix.toBilin'Aux_eq (M : Matrix n n R₂) : Matrix.toBilin'Aux M = Matrix.toBilin' M :=
rfl
theorem Matrix.toBilin'_apply (M : Matrix n n R₂) (x y : n → R₂) :
Matrix.toBilin' M x y = ∑ i, ∑ j, x i * M i j * y j :=
(Matrix.toLinearMap₂'_apply _ _ _).trans
(by simp only [smul_eq_mul, mul_assoc, mul_comm, mul_left_comm])
theorem Matrix.toBilin'_apply' (M : Matrix n n R₂) (v w : n → R₂) :
Matrix.toBilin' M v w = Matrix.dotProduct v (M *ᵥ w) := Matrix.toLinearMap₂'_apply' _ _ _
@[simp]
theorem Matrix.toBilin'_stdBasis (M : Matrix n n R₂) (i j : n) :
Matrix.toBilin' M
(LinearMap.stdBasis R₂ (fun _ => R₂) i 1)
(LinearMap.stdBasis R₂ (fun _ => R₂) j 1) = M i j := Matrix.toLinearMap₂'_stdBasis _ _ _
@[simp]
theorem LinearMap.BilinForm.toMatrix'_symm :
(BilinForm.toMatrix'.symm : Matrix n n R₂ ≃ₗ[R₂] _) = Matrix.toBilin' :=
rfl
@[simp]
theorem Matrix.toBilin'_symm :
(Matrix.toBilin'.symm : _ ≃ₗ[R₂] Matrix n n R₂) = BilinForm.toMatrix' :=
BilinForm.toMatrix'.symm_symm
@[simp]
theorem Matrix.toBilin'_toMatrix' (B : BilinForm R₂ (n → R₂)) :
Matrix.toBilin' (BilinForm.toMatrix' B) = B :=
Matrix.toBilin'.apply_symm_apply B
namespace LinearMap
@[simp]
theorem BilinForm.toMatrix'_toBilin' (M : Matrix n n R₂) :
BilinForm.toMatrix' (Matrix.toBilin' M) = M :=
(LinearMap.toMatrix₂' R₂).apply_symm_apply M
@[simp]
theorem BilinForm.toMatrix'_apply (B : BilinForm R₂ (n → R₂)) (i j : n) :
BilinForm.toMatrix' B i j = B (stdBasis R₂ (fun _ => R₂) i 1) (stdBasis R₂ (fun _ => R₂) j 1) :=
LinearMap.toMatrix₂'_apply _ _ _
-- Porting note: dot notation for bundled maps doesn't work in the rest of this section
@[simp]
theorem BilinForm.toMatrix'_comp (B : BilinForm R₂ (n → R₂)) (l r : (o → R₂) →ₗ[R₂] n → R₂) :
BilinForm.toMatrix' (B.comp l r) =
(LinearMap.toMatrix' l)ᵀ * BilinForm.toMatrix' B * LinearMap.toMatrix' r :=
LinearMap.toMatrix₂'_compl₁₂ B _ _
theorem BilinForm.toMatrix'_compLeft (B : BilinForm R₂ (n → R₂)) (f : (n → R₂) →ₗ[R₂] n → R₂) :
BilinForm.toMatrix' (B.compLeft f) = (LinearMap.toMatrix' f)ᵀ * BilinForm.toMatrix' B :=
LinearMap.toMatrix₂'_comp B _
theorem BilinForm.toMatrix'_compRight (B : BilinForm R₂ (n → R₂)) (f : (n → R₂) →ₗ[R₂] n → R₂) :
BilinForm.toMatrix' (B.compRight f) = BilinForm.toMatrix' B * LinearMap.toMatrix' f :=
LinearMap.toMatrix₂'_compl₂ B _
theorem BilinForm.mul_toMatrix'_mul (B : BilinForm R₂ (n → R₂)) (M : Matrix o n R₂)
(N : Matrix n o R₂) : M * BilinForm.toMatrix' B * N =
BilinForm.toMatrix' (B.comp (Matrix.toLin' Mᵀ) (Matrix.toLin' N)) :=
LinearMap.mul_toMatrix₂'_mul B _ _
theorem BilinForm.mul_toMatrix' (B : BilinForm R₂ (n → R₂)) (M : Matrix n n R₂) :
M * BilinForm.toMatrix' B = BilinForm.toMatrix' (B.compLeft (Matrix.toLin' Mᵀ)) :=
LinearMap.mul_toMatrix' B _
theorem BilinForm.toMatrix'_mul (B : BilinForm R₂ (n → R₂)) (M : Matrix n n R₂) :
BilinForm.toMatrix' B * M = BilinForm.toMatrix' (B.compRight (Matrix.toLin' M)) :=
LinearMap.toMatrix₂'_mul B _
end LinearMap
theorem Matrix.toBilin'_comp (M : Matrix n n R₂) (P Q : Matrix n o R₂) :
M.toBilin'.comp (Matrix.toLin' P) (Matrix.toLin' Q) = Matrix.toBilin' (Pᵀ * M * Q) :=
BilinForm.toMatrix'.injective
(by simp only [BilinForm.toMatrix'_comp, BilinForm.toMatrix'_toBilin', toMatrix'_toLin'])
end ToMatrix'
section ToMatrix
/-! ### `ToMatrix` section
This section deals with the conversion between matrices and bilinear forms on
a module with a fixed basis.
-/
variable [DecidableEq n] (b : Basis n R₂ M₂)
/-- `BilinForm.toMatrix b` is the equivalence between `R`-bilinear forms on `M` and
`n`-by-`n` matrices with entries in `R`, if `b` is an `R`-basis for `M`. -/
noncomputable def BilinForm.toMatrix : BilinForm R₂ M₂ ≃ₗ[R₂] Matrix n n R₂ :=
LinearMap.toMatrix₂ b b
/-- `BilinForm.toMatrix b` is the equivalence between `R`-bilinear forms on `M` and
`n`-by-`n` matrices with entries in `R`, if `b` is an `R`-basis for `M`. -/
noncomputable def Matrix.toBilin : Matrix n n R₂ ≃ₗ[R₂] BilinForm R₂ M₂ :=
(BilinForm.toMatrix b).symm
@[simp]
theorem BilinForm.toMatrix_apply (B : BilinForm R₂ M₂) (i j : n) :
BilinForm.toMatrix b B i j = B (b i) (b j) :=
LinearMap.toMatrix₂_apply _ _ B _ _
@[simp]
theorem Matrix.toBilin_apply (M : Matrix n n R₂) (x y : M₂) :
Matrix.toBilin b M x y = ∑ i, ∑ j, b.repr x i * M i j * b.repr y j :=
(Matrix.toLinearMap₂_apply _ _ _ _ _).trans
(by simp only [smul_eq_mul, mul_assoc, mul_comm, mul_left_comm])
-- Not a `simp` lemma since `BilinForm.toMatrix` needs an extra argument
theorem BilinearForm.toMatrixAux_eq (B : BilinForm R₂ M₂) :
BilinForm.toMatrixAux (R₂ := R₂) b B = BilinForm.toMatrix b B :=
LinearMap.toMatrix₂Aux_eq _ _ B
@[simp]
theorem BilinForm.toMatrix_symm : (BilinForm.toMatrix b).symm = Matrix.toBilin b :=
rfl
@[simp]
theorem Matrix.toBilin_symm : (Matrix.toBilin b).symm = BilinForm.toMatrix b :=
(BilinForm.toMatrix b).symm_symm
theorem Matrix.toBilin_basisFun : Matrix.toBilin (Pi.basisFun R₂ n) = Matrix.toBilin' := by
ext M
simp only [coe_comp, coe_single, Function.comp_apply, toBilin_apply, Pi.basisFun_repr,
toBilin'_apply]
theorem BilinForm.toMatrix_basisFun :
BilinForm.toMatrix (Pi.basisFun R₂ n) = BilinForm.toMatrix' := by
rw [BilinForm.toMatrix, BilinForm.toMatrix', LinearMap.toMatrix₂_basisFun]
@[simp]
theorem Matrix.toBilin_toMatrix (B : BilinForm R₂ M₂) :
Matrix.toBilin b (BilinForm.toMatrix b B) = B :=
(Matrix.toBilin b).apply_symm_apply B
@[simp]
theorem BilinForm.toMatrix_toBilin (M : Matrix n n R₂) :
BilinForm.toMatrix b (Matrix.toBilin b M) = M :=
(BilinForm.toMatrix b).apply_symm_apply M
variable {M₂' : Type*} [AddCommMonoid M₂'] [Module R₂ M₂']
variable (c : Basis o R₂ M₂')
variable [DecidableEq o]
-- Cannot be a `simp` lemma because `b` must be inferred.
theorem BilinForm.toMatrix_comp (B : BilinForm R₂ M₂) (l r : M₂' →ₗ[R₂] M₂) :
BilinForm.toMatrix c (B.comp l r) =
(LinearMap.toMatrix c b l)ᵀ * BilinForm.toMatrix b B * LinearMap.toMatrix c b r :=
LinearMap.toMatrix₂_compl₁₂ _ _ _ _ B _ _
theorem BilinForm.toMatrix_compLeft (B : BilinForm R₂ M₂) (f : M₂ →ₗ[R₂] M₂) :
BilinForm.toMatrix b (B.compLeft f) = (LinearMap.toMatrix b b f)ᵀ * BilinForm.toMatrix b B :=
LinearMap.toMatrix₂_comp _ _ _ B _
theorem BilinForm.toMatrix_compRight (B : BilinForm R₂ M₂) (f : M₂ →ₗ[R₂] M₂) :
BilinForm.toMatrix b (B.compRight f) = BilinForm.toMatrix b B * LinearMap.toMatrix b b f :=
LinearMap.toMatrix₂_compl₂ _ _ _ B _
@[simp]
theorem BilinForm.toMatrix_mul_basis_toMatrix (c : Basis o R₂ M₂) (B : BilinForm R₂ M₂) :
(b.toMatrix c)ᵀ * BilinForm.toMatrix b B * b.toMatrix c = BilinForm.toMatrix c B :=
LinearMap.toMatrix₂_mul_basis_toMatrix _ _ _ _ B
theorem BilinForm.mul_toMatrix_mul (B : BilinForm R₂ M₂) (M : Matrix o n R₂) (N : Matrix n o R₂) :
M * BilinForm.toMatrix b B * N =
BilinForm.toMatrix c (B.comp (Matrix.toLin c b Mᵀ) (Matrix.toLin c b N)) :=
LinearMap.mul_toMatrix₂_mul _ _ _ _ B _ _
theorem BilinForm.mul_toMatrix (B : BilinForm R₂ M₂) (M : Matrix n n R₂) :
M * BilinForm.toMatrix b B = BilinForm.toMatrix b (B.compLeft (Matrix.toLin b b Mᵀ)) :=
LinearMap.mul_toMatrix₂ _ _ _ B _
theorem BilinForm.toMatrix_mul (B : BilinForm R₂ M₂) (M : Matrix n n R₂) :
BilinForm.toMatrix b B * M = BilinForm.toMatrix b (B.compRight (Matrix.toLin b b M)) :=
LinearMap.toMatrix₂_mul _ _ _ B _
theorem Matrix.toBilin_comp (M : Matrix n n R₂) (P Q : Matrix n o R₂) :
(Matrix.toBilin b M).comp (toLin c b P) (toLin c b Q) = Matrix.toBilin c (Pᵀ * M * Q) := by
ext x y
rw [Matrix.toBilin, BilinForm.toMatrix, Matrix.toBilin, BilinForm.toMatrix, toMatrix₂_symm,
toMatrix₂_symm, ← Matrix.toLinearMap₂_compl₁₂ b b c c]
simp
end ToMatrix
end Matrix
section MatrixAdjoints
open Matrix
variable {n : Type*} [Fintype n]
variable (b : Basis n R₃ M₃)
variable (J J₃ A A' : Matrix n n R₃)
@[simp]
theorem isAdjointPair_toBilin' [DecidableEq n] :
BilinForm.IsAdjointPair (Matrix.toBilin' J) (Matrix.toBilin' J₃) (Matrix.toLin' A)
(Matrix.toLin' A') ↔
Matrix.IsAdjointPair J J₃ A A' :=
isAdjointPair_toLinearMap₂' _ _ _ _
@[simp]
theorem isAdjointPair_toBilin [DecidableEq n] :
BilinForm.IsAdjointPair (Matrix.toBilin b J) (Matrix.toBilin b J₃) (Matrix.toLin b b A)
(Matrix.toLin b b A') ↔
Matrix.IsAdjointPair J J₃ A A' :=
isAdjointPair_toLinearMap₂ _ _ _ _ _ _
theorem Matrix.isAdjointPair_equiv' [DecidableEq n] (P : Matrix n n R₃) (h : IsUnit P) :
(Pᵀ * J * P).IsAdjointPair (Pᵀ * J * P) A A' ↔
J.IsAdjointPair J (P * A * P⁻¹) (P * A' * P⁻¹) :=
Matrix.isAdjointPair_equiv _ _ _ _ h
variable [DecidableEq n]
/-- The submodule of pair-self-adjoint matrices with respect to bilinear forms corresponding to
given matrices `J`, `J₂`. -/
def pairSelfAdjointMatricesSubmodule' : Submodule R₃ (Matrix n n R₃) :=
(BilinForm.isPairSelfAdjointSubmodule (Matrix.toBilin' J) (Matrix.toBilin' J₃)).map
((LinearMap.toMatrix' : ((n → R₃) →ₗ[R₃] n → R₃) ≃ₗ[R₃] Matrix n n R₃) :
((n → R₃) →ₗ[R₃] n → R₃) →ₗ[R₃] Matrix n n R₃)
theorem mem_pairSelfAdjointMatricesSubmodule' :
A ∈ pairSelfAdjointMatricesSubmodule J J₃ ↔ Matrix.IsAdjointPair J J₃ A A := by
simp only [mem_pairSelfAdjointMatricesSubmodule]
/-- The submodule of self-adjoint matrices with respect to the bilinear form corresponding to
the matrix `J`. -/
def selfAdjointMatricesSubmodule' : Submodule R₃ (Matrix n n R₃) :=
pairSelfAdjointMatricesSubmodule J J
theorem mem_selfAdjointMatricesSubmodule' :
A ∈ selfAdjointMatricesSubmodule J ↔ J.IsSelfAdjoint A := by
simp only [mem_selfAdjointMatricesSubmodule]
/-- The submodule of skew-adjoint matrices with respect to the bilinear form corresponding to
the matrix `J`. -/
def skewAdjointMatricesSubmodule' : Submodule R₃ (Matrix n n R₃) :=
pairSelfAdjointMatricesSubmodule (-J) J
theorem mem_skewAdjointMatricesSubmodule' :
A ∈ skewAdjointMatricesSubmodule J ↔ J.IsSkewAdjoint A := by
simp only [mem_skewAdjointMatricesSubmodule]
end MatrixAdjoints
namespace LinearMap
namespace BilinForm
section Det
open Matrix
variable {A : Type*} [CommRing A] [IsDomain A] [Module A M₃] (B₃ : BilinForm A M₃)
variable {ι : Type*} [DecidableEq ι] [Fintype ι]
theorem _root_.Matrix.nondegenerate_toBilin'_iff_nondegenerate_toBilin {M : Matrix ι ι R₂}
(b : Basis ι R₂ M₂) : M.toBilin'.Nondegenerate ↔ (Matrix.toBilin b M).Nondegenerate :=
(nondegenerate_congr_iff b.equivFun.symm).symm
-- Lemmas transferring nondegeneracy between a matrix and its associated bilinear form
theorem _root_.Matrix.Nondegenerate.toBilin' {M : Matrix ι ι R₃} (h : M.Nondegenerate) :
M.toBilin'.Nondegenerate := fun x hx =>
h.eq_zero_of_ortho fun y => by simpa only [toBilin'_apply'] using hx y
@[simp]
theorem _root_.Matrix.nondegenerate_toBilin'_iff {M : Matrix ι ι R₃} :
M.toBilin'.Nondegenerate ↔ M.Nondegenerate :=
⟨fun h v hv => h v fun w => (M.toBilin'_apply' _ _).trans <| hv w, Matrix.Nondegenerate.toBilin'⟩
theorem _root_.Matrix.Nondegenerate.toBilin {M : Matrix ι ι R₃} (h : M.Nondegenerate)
(b : Basis ι R₃ M₃) : (Matrix.toBilin b M).Nondegenerate :=
(Matrix.nondegenerate_toBilin'_iff_nondegenerate_toBilin b).mp h.toBilin'
@[simp]
theorem _root_.Matrix.nondegenerate_toBilin_iff {M : Matrix ι ι R₃} (b : Basis ι R₃ M₃) :
(Matrix.toBilin b M).Nondegenerate ↔ M.Nondegenerate := by
rw [← Matrix.nondegenerate_toBilin'_iff_nondegenerate_toBilin, Matrix.nondegenerate_toBilin'_iff]
/-! Lemmas transferring nondegeneracy between a bilinear form and its associated matrix -/
@[simp]
theorem nondegenerate_toMatrix'_iff {B : BilinForm R₃ (ι → R₃)} :
B.toMatrix'.Nondegenerate (m := ι) ↔ B.Nondegenerate :=
Matrix.nondegenerate_toBilin'_iff.symm.trans <| (Matrix.toBilin'_toMatrix' B).symm ▸ Iff.rfl
theorem Nondegenerate.toMatrix' {B : BilinForm R₃ (ι → R₃)} (h : B.Nondegenerate) :
B.toMatrix'.Nondegenerate :=
nondegenerate_toMatrix'_iff.mpr h
@[simp]
theorem nondegenerate_toMatrix_iff {B : BilinForm R₃ M₃} (b : Basis ι R₃ M₃) :
(BilinForm.toMatrix b B).Nondegenerate ↔ B.Nondegenerate :=
(Matrix.nondegenerate_toBilin_iff b).symm.trans <| (Matrix.toBilin_toMatrix b B).symm ▸ Iff.rfl
theorem Nondegenerate.toMatrix {B : BilinForm R₃ M₃} (h : B.Nondegenerate) (b : Basis ι R₃ M₃) :
(BilinForm.toMatrix b B).Nondegenerate :=
(nondegenerate_toMatrix_iff b).mpr h
/-! Some shorthands for combining the above with `Matrix.nondegenerate_of_det_ne_zero` -/
theorem nondegenerate_toBilin'_iff_det_ne_zero {M : Matrix ι ι A} :
M.toBilin'.Nondegenerate ↔ M.det ≠ 0 := by
rw [Matrix.nondegenerate_toBilin'_iff, Matrix.nondegenerate_iff_det_ne_zero]
theorem nondegenerate_toBilin'_of_det_ne_zero' (M : Matrix ι ι A) (h : M.det ≠ 0) :
M.toBilin'.Nondegenerate :=
nondegenerate_toBilin'_iff_det_ne_zero.mpr h
theorem nondegenerate_iff_det_ne_zero {B : BilinForm A M₃} (b : Basis ι A M₃) :
B.Nondegenerate ↔ (BilinForm.toMatrix b B).det ≠ 0 := by
rw [← Matrix.nondegenerate_iff_det_ne_zero, nondegenerate_toMatrix_iff]
theorem nondegenerate_of_det_ne_zero (b : Basis ι A M₃) (h : (BilinForm.toMatrix b B₃).det ≠ 0) :
B₃.Nondegenerate :=
(nondegenerate_iff_det_ne_zero b).mpr h
end Det
end BilinForm
end LinearMap
|
LinearAlgebra\Matrix\Block.lean | /-
Copyright (c) 2019 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Patrick Massot, Casper Putz, Anne Baanen, Wen Yang
-/
import Mathlib.LinearAlgebra.Matrix.Transvection
import Mathlib.LinearAlgebra.Matrix.NonsingularInverse
import Mathlib.Tactic.FinCases
/-!
# Block matrices and their determinant
This file defines a predicate `Matrix.BlockTriangular` saying a matrix
is block triangular, and proves the value of the determinant for various
matrices built out of blocks.
## Main definitions
* `Matrix.BlockTriangular` expresses that an `o` by `o` matrix is block triangular,
if the rows and columns are ordered according to some order `b : o → α`
## Main results
* `Matrix.det_of_blockTriangular`: the determinant of a block triangular matrix
is equal to the product of the determinants of all the blocks
* `Matrix.det_of_upperTriangular` and `Matrix.det_of_lowerTriangular`: the determinant of
a triangular matrix is the product of the entries along the diagonal
## Tags
matrix, diagonal, det, block triangular
-/
open Finset Function OrderDual
open Matrix
universe v
variable {α β m n o : Type*} {m' n' : α → Type*}
variable {R : Type v} [CommRing R] {M N : Matrix m m R} {b : m → α}
namespace Matrix
section LT
variable [LT α]
/-- Let `b` map rows and columns of a square matrix `M` to blocks indexed by `α`s. Then
`BlockTriangular M n b` says the matrix is block triangular. -/
def BlockTriangular (M : Matrix m m R) (b : m → α) : Prop :=
∀ ⦃i j⦄, b j < b i → M i j = 0
@[simp]
protected theorem BlockTriangular.submatrix {f : n → m} (h : M.BlockTriangular b) :
(M.submatrix f f).BlockTriangular (b ∘ f) := fun _ _ hij => h hij
theorem blockTriangular_reindex_iff {b : n → α} {e : m ≃ n} :
(reindex e e M).BlockTriangular b ↔ M.BlockTriangular (b ∘ e) := by
refine ⟨fun h => ?_, fun h => ?_⟩
· convert h.submatrix
simp only [reindex_apply, submatrix_submatrix, submatrix_id_id, Equiv.symm_comp_self]
· convert h.submatrix
simp only [comp.assoc b e e.symm, Equiv.self_comp_symm, comp_id]
protected theorem BlockTriangular.transpose :
M.BlockTriangular b → Mᵀ.BlockTriangular (toDual ∘ b) :=
swap
@[simp]
protected theorem blockTriangular_transpose_iff {b : m → αᵒᵈ} :
Mᵀ.BlockTriangular b ↔ M.BlockTriangular (ofDual ∘ b) :=
forall_swap
@[simp]
theorem blockTriangular_zero : BlockTriangular (0 : Matrix m m R) b := fun _ _ _ => rfl
protected theorem BlockTriangular.neg (hM : BlockTriangular M b) : BlockTriangular (-M) b :=
fun _ _ h => neg_eq_zero.2 <| hM h
theorem BlockTriangular.add (hM : BlockTriangular M b) (hN : BlockTriangular N b) :
BlockTriangular (M + N) b := fun i j h => by simp_rw [Matrix.add_apply, hM h, hN h, zero_add]
theorem BlockTriangular.sub (hM : BlockTriangular M b) (hN : BlockTriangular N b) :
BlockTriangular (M - N) b := fun i j h => by simp_rw [Matrix.sub_apply, hM h, hN h, sub_zero]
end LT
section Preorder
variable [Preorder α]
theorem blockTriangular_diagonal [DecidableEq m] (d : m → R) : BlockTriangular (diagonal d) b :=
fun _ _ h => diagonal_apply_ne' d fun h' => ne_of_lt h (congr_arg _ h')
theorem blockTriangular_blockDiagonal' [DecidableEq α] (d : ∀ i : α, Matrix (m' i) (m' i) R) :
BlockTriangular (blockDiagonal' d) Sigma.fst := by
rintro ⟨i, i'⟩ ⟨j, j'⟩ h
apply blockDiagonal'_apply_ne d i' j' fun h' => ne_of_lt h h'.symm
theorem blockTriangular_blockDiagonal [DecidableEq α] (d : α → Matrix m m R) :
BlockTriangular (blockDiagonal d) Prod.snd := by
rintro ⟨i, i'⟩ ⟨j, j'⟩ h
rw [blockDiagonal'_eq_blockDiagonal, blockTriangular_blockDiagonal']
exact h
variable [DecidableEq m]
theorem blockTriangular_one : BlockTriangular (1 : Matrix m m R) b :=
blockTriangular_diagonal _
theorem blockTriangular_stdBasisMatrix {i j : m} (hij : b i ≤ b j) (c : R) :
BlockTriangular (stdBasisMatrix i j c) b := by
intro r s hrs
apply StdBasisMatrix.apply_of_ne
rintro ⟨rfl, rfl⟩
exact (hij.trans_lt hrs).false
theorem blockTriangular_stdBasisMatrix' {i j : m} (hij : b j ≤ b i) (c : R) :
BlockTriangular (stdBasisMatrix i j c) (toDual ∘ b) :=
blockTriangular_stdBasisMatrix (by exact toDual_le_toDual.mpr hij) _
theorem blockTriangular_transvection {i j : m} (hij : b i ≤ b j) (c : R) :
BlockTriangular (transvection i j c) b :=
blockTriangular_one.add (blockTriangular_stdBasisMatrix hij c)
theorem blockTriangular_transvection' {i j : m} (hij : b j ≤ b i) (c : R) :
BlockTriangular (transvection i j c) (OrderDual.toDual ∘ b) :=
blockTriangular_one.add (blockTriangular_stdBasisMatrix' hij c)
end Preorder
section LinearOrder
variable [LinearOrder α]
theorem BlockTriangular.mul [Fintype m] {M N : Matrix m m R} (hM : BlockTriangular M b)
(hN : BlockTriangular N b) : BlockTriangular (M * N) b := by
intro i j hij
apply Finset.sum_eq_zero
intro k _
by_cases hki : b k < b i
· simp_rw [hM hki, zero_mul]
· simp_rw [hN (lt_of_lt_of_le hij (le_of_not_lt hki)), mul_zero]
end LinearOrder
theorem upper_two_blockTriangular [Preorder α] (A : Matrix m m R) (B : Matrix m n R)
(D : Matrix n n R) {a b : α} (hab : a < b) :
BlockTriangular (fromBlocks A B 0 D) (Sum.elim (fun _ => a) fun _ => b) := by
rintro (c | c) (d | d) hcd <;> first | simp [hab.not_lt] at hcd ⊢
/-! ### Determinant -/
variable [DecidableEq m] [Fintype m] [DecidableEq n] [Fintype n]
theorem equiv_block_det (M : Matrix m m R) {p q : m → Prop} [DecidablePred p] [DecidablePred q]
(e : ∀ x, q x ↔ p x) : (toSquareBlockProp M p).det = (toSquareBlockProp M q).det := by
convert Matrix.det_reindex_self (Equiv.subtypeEquivRight e) (toSquareBlockProp M q)
-- Removed `@[simp]` attribute,
-- as the LHS simplifies already to `M.toSquareBlock id i ⟨i, ⋯⟩ ⟨i, ⋯⟩`
theorem det_toSquareBlock_id (M : Matrix m m R) (i : m) : (M.toSquareBlock id i).det = M i i :=
letI : Unique { a // id a = i } := ⟨⟨⟨i, rfl⟩⟩, fun j => Subtype.ext j.property⟩
(det_unique _).trans rfl
theorem det_toBlock (M : Matrix m m R) (p : m → Prop) [DecidablePred p] :
M.det =
(fromBlocks (toBlock M p p) (toBlock M p fun j => ¬p j) (toBlock M (fun j => ¬p j) p) <|
toBlock M (fun j => ¬p j) fun j => ¬p j).det := by
rw [← Matrix.det_reindex_self (Equiv.sumCompl p).symm M]
rw [det_apply', det_apply']
congr; ext σ; congr; ext x
generalize hy : σ x = y
cases x <;> cases y <;>
simp only [Matrix.reindex_apply, toBlock_apply, Equiv.symm_symm, Equiv.sumCompl_apply_inr,
Equiv.sumCompl_apply_inl, fromBlocks_apply₁₁, fromBlocks_apply₁₂, fromBlocks_apply₂₁,
fromBlocks_apply₂₂, Matrix.submatrix_apply]
theorem twoBlockTriangular_det (M : Matrix m m R) (p : m → Prop) [DecidablePred p]
(h : ∀ i, ¬p i → ∀ j, p j → M i j = 0) :
M.det = (toSquareBlockProp M p).det * (toSquareBlockProp M fun i => ¬p i).det := by
rw [det_toBlock M p]
convert det_fromBlocks_zero₂₁ (toBlock M p p) (toBlock M p fun j => ¬p j)
(toBlock M (fun j => ¬p j) fun j => ¬p j)
ext i j
exact h (↑i) i.2 (↑j) j.2
theorem twoBlockTriangular_det' (M : Matrix m m R) (p : m → Prop) [DecidablePred p]
(h : ∀ i, p i → ∀ j, ¬p j → M i j = 0) :
M.det = (toSquareBlockProp M p).det * (toSquareBlockProp M fun i => ¬p i).det := by
rw [M.twoBlockTriangular_det fun i => ¬p i, mul_comm]
· congr 1
exact equiv_block_det _ fun _ => not_not.symm
· simpa only [Classical.not_not] using h
protected theorem BlockTriangular.det [DecidableEq α] [LinearOrder α] (hM : BlockTriangular M b) :
M.det = ∏ a ∈ univ.image b, (M.toSquareBlock b a).det := by
clear N
induction' hs : univ.image b using Finset.strongInduction with s ih generalizing m
subst hs
cases isEmpty_or_nonempty m
· simp
let k := (univ.image b).max' (univ_nonempty.image _)
rw [twoBlockTriangular_det' M fun i => b i = k]
· have : univ.image b = insert k ((univ.image b).erase k) := by
rw [insert_erase]
apply max'_mem
rw [this, prod_insert (not_mem_erase _ _)]
refine congr_arg _ ?_
let b' := fun i : { a // b a ≠ k } => b ↑i
have h' : BlockTriangular (M.toSquareBlockProp fun i => b i ≠ k) b' := hM.submatrix
have hb' : image b' univ = (image b univ).erase k := by
convert image_subtype_ne_univ_eq_image_erase k b
rw [ih _ (erase_ssubset <| max'_mem _ _) h' hb']
refine Finset.prod_congr rfl fun l hl => ?_
let he : { a // b' a = l } ≃ { a // b a = l } :=
haveI hc : ∀ i, b i = l → b i ≠ k := fun i hi => ne_of_eq_of_ne hi (ne_of_mem_erase hl)
Equiv.subtypeSubtypeEquivSubtype @(hc)
simp only [toSquareBlock_def]
erw [← Matrix.det_reindex_self he.symm fun i j : { a // b a = l } => M ↑i ↑j]
rfl
· intro i hi j hj
apply hM
rw [hi]
apply lt_of_le_of_ne _ hj
exact Finset.le_max' (univ.image b) _ (mem_image_of_mem _ (mem_univ _))
theorem BlockTriangular.det_fintype [DecidableEq α] [Fintype α] [LinearOrder α]
(h : BlockTriangular M b) : M.det = ∏ k : α, (M.toSquareBlock b k).det := by
refine h.det.trans (prod_subset (subset_univ _) fun a _ ha => ?_)
have : IsEmpty { i // b i = a } := ⟨fun i => ha <| mem_image.2 ⟨i, mem_univ _, i.2⟩⟩
exact det_isEmpty
theorem det_of_upperTriangular [LinearOrder m] (h : M.BlockTriangular id) :
M.det = ∏ i : m, M i i := by
haveI : DecidableEq R := Classical.decEq _
simp_rw [h.det, image_id, det_toSquareBlock_id]
theorem det_of_lowerTriangular [LinearOrder m] (M : Matrix m m R) (h : M.BlockTriangular toDual) :
M.det = ∏ i : m, M i i := by
rw [← det_transpose]
exact det_of_upperTriangular h.transpose
open Polynomial
theorem matrixOfPolynomials_blockTriangular {n : ℕ} (p : Fin n → R[X])
(h_deg : ∀ i, (p i).natDegree ≤ i) :
Matrix.BlockTriangular (Matrix.of (fun (i j : Fin n) => (p j).coeff i)) id :=
fun _ j h => by
exact coeff_eq_zero_of_natDegree_lt <| Nat.lt_of_le_of_lt (h_deg j) h
theorem det_matrixOfPolynomials {n : ℕ} (p : Fin n → R[X])
(h_deg : ∀ i, (p i).natDegree = i) (h_monic : ∀ i, Monic <| p i) :
(Matrix.of (fun (i j : Fin n) => (p j).coeff i)).det = 1 := by
rw [Matrix.det_of_upperTriangular (Matrix.matrixOfPolynomials_blockTriangular p (fun i ↦
Nat.le_of_eq (h_deg i)))]
convert prod_const_one with x _
rw [Matrix.of_apply, ← h_deg, coeff_natDegree, (h_monic x).leadingCoeff]
/-! ### Invertible -/
theorem BlockTriangular.toBlock_inverse_mul_toBlock_eq_one [LinearOrder α] [Invertible M]
(hM : BlockTriangular M b) (k : α) :
((M⁻¹.toBlock (fun i => b i < k) fun i => b i < k) *
M.toBlock (fun i => b i < k) fun i => b i < k) =
1 := by
let p i := b i < k
have h_sum :
M⁻¹.toBlock p p * M.toBlock p p +
(M⁻¹.toBlock p fun i => ¬p i) * M.toBlock (fun i => ¬p i) p =
1 := by
rw [← toBlock_mul_eq_add, inv_mul_of_invertible M, toBlock_one_self]
have h_zero : M.toBlock (fun i => ¬p i) p = 0 := by
ext i j
simpa using hM (lt_of_lt_of_le j.2 (le_of_not_lt i.2))
simpa [h_zero] using h_sum
/-- The inverse of an upper-left subblock of a block-triangular matrix `M` is the upper-left
subblock of `M⁻¹`. -/
theorem BlockTriangular.inv_toBlock [LinearOrder α] [Invertible M] (hM : BlockTriangular M b)
(k : α) :
(M.toBlock (fun i => b i < k) fun i => b i < k)⁻¹ =
M⁻¹.toBlock (fun i => b i < k) fun i => b i < k :=
inv_eq_left_inv <| hM.toBlock_inverse_mul_toBlock_eq_one k
/-- An upper-left subblock of an invertible block-triangular matrix is invertible. -/
def BlockTriangular.invertibleToBlock [LinearOrder α] [Invertible M] (hM : BlockTriangular M b)
(k : α) : Invertible (M.toBlock (fun i => b i < k) fun i => b i < k) :=
invertibleOfLeftInverse _ ((⅟ M).toBlock (fun i => b i < k) fun i => b i < k) <| by
simpa only [invOf_eq_nonsing_inv] using hM.toBlock_inverse_mul_toBlock_eq_one k
/-- A lower-left subblock of the inverse of a block-triangular matrix is zero. This is a first step
towards `BlockTriangular.inv_toBlock` below. -/
theorem toBlock_inverse_eq_zero [LinearOrder α] [Invertible M] (hM : BlockTriangular M b) (k : α) :
(M⁻¹.toBlock (fun i => k ≤ b i) fun i => b i < k) = 0 := by
let p i := b i < k
let q i := ¬b i < k
have h_sum : M⁻¹.toBlock q p * M.toBlock p p + M⁻¹.toBlock q q * M.toBlock q p = 0 := by
rw [← toBlock_mul_eq_add, inv_mul_of_invertible M, toBlock_one_disjoint]
rw [disjoint_iff_inf_le]
exact fun i h => h.1 h.2
have h_zero : M.toBlock q p = 0 := by
ext i j
simpa using hM (lt_of_lt_of_le j.2 <| le_of_not_lt i.2)
have h_mul_eq_zero : M⁻¹.toBlock q p * M.toBlock p p = 0 := by simpa [h_zero] using h_sum
haveI : Invertible (M.toBlock p p) := hM.invertibleToBlock k
have : (fun i => k ≤ b i) = q := by
ext
exact not_lt.symm
rw [this, ← Matrix.zero_mul (M.toBlock p p)⁻¹, ← h_mul_eq_zero,
mul_inv_cancel_right_of_invertible]
/-- The inverse of a block-triangular matrix is block-triangular. -/
theorem blockTriangular_inv_of_blockTriangular [LinearOrder α] [Invertible M]
(hM : BlockTriangular M b) : BlockTriangular M⁻¹ b := by
clear N
induction' hs : univ.image b using Finset.strongInduction with s ih generalizing m
subst hs
intro i j hij
haveI : Inhabited m := ⟨i⟩
let k := (univ.image b).max' (univ_nonempty.image _)
let b' := fun i : { a // b a < k } => b ↑i
let A := M.toBlock (fun i => b i < k) fun j => b j < k
obtain hbi | hi : b i = k ∨ _ := (le_max' _ (b i) <| mem_image_of_mem _ <| mem_univ _).eq_or_lt
· have : M⁻¹.toBlock (fun i => k ≤ b i) (fun i => b i < k) ⟨i, hbi.ge⟩ ⟨j, hbi ▸ hij⟩ = 0 := by
simp only [toBlock_inverse_eq_zero hM k, Matrix.zero_apply]
simp [this.symm]
haveI : Invertible A := hM.invertibleToBlock _
have hA : A.BlockTriangular b' := hM.submatrix
have hb' : image b' univ ⊂ image b univ := by
convert image_subtype_univ_ssubset_image_univ k b _ (fun a => a < k) (lt_irrefl _)
convert max'_mem (α := α) _ _
have hij' : b' ⟨j, hij.trans hi⟩ < b' ⟨i, hi⟩ := by simp_rw [hij]
simp [hM.inv_toBlock k, (ih (image b' univ) hb' hA rfl hij').symm]
end Matrix
|
LinearAlgebra\Matrix\Circulant.lean | /-
Copyright (c) 2021 Lu-Ming Zhang. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Lu-Ming Zhang
-/
import Mathlib.Algebra.Group.Fin.Basic
import Mathlib.LinearAlgebra.Matrix.Symmetric
import Mathlib.Tactic.Abel
/-!
# Circulant matrices
This file contains the definition and basic results about circulant matrices.
Given a vector `v : n → α` indexed by a type that is endowed with subtraction,
`Matrix.circulant v` is the matrix whose `(i, j)`th entry is `v (i - j)`.
## Main results
- `Matrix.circulant`: the circulant matrix generated by a given vector `v : n → α`.
- `Matrix.circulant_mul`: the product of two circulant matrices `circulant v` and `circulant w` is
the circulant matrix generated by `circulant v *ᵥ w`.
- `Matrix.circulant_mul_comm`: multiplication of circulant matrices commutes when the elements do.
## Implementation notes
`Matrix.Fin.foo` is the `Fin n` version of `Matrix.foo`.
Namely, the index type of the circulant matrices in discussion is `Fin n`.
## Tags
circulant, matrix
-/
variable {α β m n R : Type*}
namespace Matrix
open Function
open Matrix
/-- Given the condition `[Sub n]` and a vector `v : n → α`,
we define `circulant v` to be the circulant matrix generated by `v` of type `Matrix n n α`.
The `(i,j)`th entry is defined to be `v (i - j)`. -/
def circulant [Sub n] (v : n → α) : Matrix n n α :=
of fun i j => v (i - j)
-- TODO: set as an equation lemma for `circulant`, see mathlib4#3024
@[simp]
theorem circulant_apply [Sub n] (v : n → α) (i j) : circulant v i j = v (i - j) := rfl
theorem circulant_col_zero_eq [AddGroup n] (v : n → α) (i : n) : circulant v i 0 = v i :=
congr_arg v (sub_zero _)
theorem circulant_injective [AddGroup n] : Injective (circulant : (n → α) → Matrix n n α) := by
intro v w h
ext k
rw [← circulant_col_zero_eq v, ← circulant_col_zero_eq w, h]
theorem Fin.circulant_injective : ∀ n, Injective fun v : Fin n → α => circulant v
| 0 => by simp [Injective]
| n + 1 => Matrix.circulant_injective
@[simp]
theorem circulant_inj [AddGroup n] {v w : n → α} : circulant v = circulant w ↔ v = w :=
circulant_injective.eq_iff
@[simp]
theorem Fin.circulant_inj {n} {v w : Fin n → α} : circulant v = circulant w ↔ v = w :=
(Fin.circulant_injective n).eq_iff
theorem transpose_circulant [AddGroup n] (v : n → α) :
(circulant v)ᵀ = circulant fun i => v (-i) := by ext; simp
theorem conjTranspose_circulant [Star α] [AddGroup n] (v : n → α) :
(circulant v)ᴴ = circulant (star fun i => v (-i)) := by ext; simp
theorem Fin.transpose_circulant : ∀ {n} (v : Fin n → α), (circulant v)ᵀ = circulant fun i => v (-i)
| 0 => by simp [Injective, eq_iff_true_of_subsingleton]
| n + 1 => Matrix.transpose_circulant
theorem Fin.conjTranspose_circulant [Star α] :
∀ {n} (v : Fin n → α), (circulant v)ᴴ = circulant (star fun i => v (-i))
| 0 => by simp [Injective, eq_iff_true_of_subsingleton]
| n + 1 => Matrix.conjTranspose_circulant
theorem map_circulant [Sub n] (v : n → α) (f : α → β) :
(circulant v).map f = circulant fun i => f (v i) :=
ext fun _ _ => rfl
theorem circulant_neg [Neg α] [Sub n] (v : n → α) : circulant (-v) = -circulant v :=
ext fun _ _ => rfl
@[simp]
theorem circulant_zero (α n) [Zero α] [Sub n] : circulant 0 = (0 : Matrix n n α) :=
ext fun _ _ => rfl
theorem circulant_add [Add α] [Sub n] (v w : n → α) :
circulant (v + w) = circulant v + circulant w :=
ext fun _ _ => rfl
theorem circulant_sub [Sub α] [Sub n] (v w : n → α) :
circulant (v - w) = circulant v - circulant w :=
ext fun _ _ => rfl
/-- The product of two circulant matrices `circulant v` and `circulant w` is
the circulant matrix generated by `circulant v *ᵥ w`. -/
theorem circulant_mul [Semiring α] [Fintype n] [AddGroup n] (v w : n → α) :
circulant v * circulant w = circulant (circulant v *ᵥ w) := by
ext i j
simp only [mul_apply, mulVec, circulant_apply, dotProduct]
refine Fintype.sum_equiv (Equiv.subRight j) _ _ ?_
intro x
simp only [Equiv.subRight_apply, sub_sub_sub_cancel_right]
theorem Fin.circulant_mul [Semiring α] :
∀ {n} (v w : Fin n → α), circulant v * circulant w = circulant (circulant v *ᵥ w)
| 0 => by simp [Injective, eq_iff_true_of_subsingleton]
| n + 1 => Matrix.circulant_mul
/-- Multiplication of circulant matrices commutes when the elements do. -/
theorem circulant_mul_comm [CommSemigroup α] [AddCommMonoid α] [Fintype n] [AddCommGroup n]
(v w : n → α) : circulant v * circulant w = circulant w * circulant v := by
ext i j
simp only [mul_apply, circulant_apply, mul_comm]
refine Fintype.sum_equiv ((Equiv.subLeft i).trans (Equiv.addRight j)) _ _ ?_
intro x
simp only [Equiv.trans_apply, Equiv.subLeft_apply, Equiv.coe_addRight, add_sub_cancel_right,
mul_comm]
congr 2
abel
theorem Fin.circulant_mul_comm [CommSemigroup α] [AddCommMonoid α] :
∀ {n} (v w : Fin n → α), circulant v * circulant w = circulant w * circulant v
| 0 => by simp [Injective]
| n + 1 => Matrix.circulant_mul_comm
/-- `k • circulant v` is another circulant matrix `circulant (k • v)`. -/
theorem circulant_smul [Sub n] [SMul R α] (k : R) (v : n → α) :
circulant (k • v) = k • circulant v := rfl
@[simp]
theorem circulant_single_one (α n) [Zero α] [One α] [DecidableEq n] [AddGroup n] :
circulant (Pi.single 0 1 : n → α) = (1 : Matrix n n α) := by
ext i j
simp [one_apply, Pi.single_apply, sub_eq_zero]
@[simp]
theorem circulant_single (n) [Semiring α] [DecidableEq n] [AddGroup n] [Fintype n] (a : α) :
circulant (Pi.single 0 a : n → α) = scalar n a := by
ext i j
simp [Pi.single_apply, diagonal_apply, sub_eq_zero]
/-- Note we use `↑i = 0` instead of `i = 0` as `Fin 0` has no `0`.
This means that we cannot state this with `Pi.single` as we did with `Matrix.circulant_single`. -/
theorem Fin.circulant_ite (α) [Zero α] [One α] :
∀ n, circulant (fun i => ite (i.1 = 0) 1 0 : Fin n → α) = 1
| 0 => by simp [Injective, eq_iff_true_of_subsingleton]
| n + 1 => by
rw [← circulant_single_one]
congr with j
simp [Pi.single_apply, Fin.ext_iff]
/-- A circulant of `v` is symmetric iff `v` equals its reverse. -/
theorem circulant_isSymm_iff [AddGroup n] {v : n → α} :
(circulant v).IsSymm ↔ ∀ i, v (-i) = v i := by
rw [IsSymm, transpose_circulant, circulant_inj, funext_iff]
theorem Fin.circulant_isSymm_iff : ∀ {n} {v : Fin n → α}, (circulant v).IsSymm ↔ ∀ i, v (-i) = v i
| 0 => by simp [IsSymm.ext_iff, IsEmpty.forall_iff]
| n + 1 => Matrix.circulant_isSymm_iff
/-- If `circulant v` is symmetric, `∀ i j : I, v (- i) = v i`. -/
theorem circulant_isSymm_apply [AddGroup n] {v : n → α} (h : (circulant v).IsSymm) (i : n) :
v (-i) = v i :=
circulant_isSymm_iff.1 h i
theorem Fin.circulant_isSymm_apply {n} {v : Fin n → α} (h : (circulant v).IsSymm) (i : Fin n) :
v (-i) = v i :=
Fin.circulant_isSymm_iff.1 h i
end Matrix
|
LinearAlgebra\Matrix\Diagonal.lean | /-
Copyright (c) 2019 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Patrick Massot, Casper Putz, Anne Baanen
-/
import Mathlib.LinearAlgebra.Dimension.LinearMap
/-!
# Diagonal matrices
This file contains some results on the linear map corresponding to a
diagonal matrix (`range`, `ker` and `rank`).
## Tags
matrix, diagonal, linear_map
-/
noncomputable section
open LinearMap Matrix Set Submodule Matrix
universe u v w
namespace Matrix
section CommSemiring -- Porting note: generalized from `CommRing`
variable {n : Type*} [Fintype n] [DecidableEq n] {R : Type v} [CommSemiring R]
theorem proj_diagonal (i : n) (w : n → R) : (proj i).comp (toLin' (diagonal w)) = w i • proj i :=
LinearMap.ext fun _ => mulVec_diagonal _ _ _
theorem diagonal_comp_stdBasis (w : n → R) (i : n) :
(diagonal w).toLin'.comp (LinearMap.stdBasis R (fun _ : n => R) i) =
w i • LinearMap.stdBasis R (fun _ : n => R) i :=
LinearMap.ext fun x => (diagonal_mulVec_single w _ _).trans (Pi.single_smul' i (w i) x)
theorem diagonal_toLin' (w : n → R) :
toLin' (diagonal w) = LinearMap.pi fun i => w i • LinearMap.proj i :=
LinearMap.ext fun _ => funext fun _ => mulVec_diagonal _ _ _
end CommSemiring
section Semifield
variable {m n : Type*} [Fintype m] [Fintype n] {K : Type u} [Semifield K]
-- maybe try to relax the universe constraint
theorem ker_diagonal_toLin' [DecidableEq m] (w : m → K) :
ker (toLin' (diagonal w)) =
⨆ i ∈ { i | w i = 0 }, LinearMap.range (LinearMap.stdBasis K (fun _ => K) i) := by
rw [← comap_bot, ← iInf_ker_proj, comap_iInf]
have := fun i : m => ker_comp (toLin' (diagonal w)) (proj i)
simp only [comap_iInf, ← this, proj_diagonal, ker_smul']
have : univ ⊆ { i : m | w i = 0 } ∪ { i : m | w i = 0 }ᶜ := by rw [Set.union_compl_self]
exact (iSup_range_stdBasis_eq_iInf_ker_proj K (fun _ : m => K) disjoint_compl_right this
(Set.toFinite _)).symm
theorem range_diagonal [DecidableEq m] (w : m → K) :
LinearMap.range (toLin' (diagonal w)) =
⨆ i ∈ { i | w i ≠ 0 }, LinearMap.range (LinearMap.stdBasis K (fun _ => K) i) := by
dsimp only [mem_setOf_eq]
rw [← Submodule.map_top, ← iSup_range_stdBasis, Submodule.map_iSup]
congr; funext i
rw [← LinearMap.range_comp, diagonal_comp_stdBasis, ← range_smul']
end Semifield
end Matrix
namespace LinearMap
section Field
variable {m n : Type*} [Fintype m] [Fintype n] {K : Type u} [Field K]
theorem rank_diagonal [DecidableEq m] [DecidableEq K] (w : m → K) :
LinearMap.rank (toLin' (diagonal w)) = Fintype.card { i // w i ≠ 0 } := by
have hu : univ ⊆ { i : m | w i = 0 }ᶜ ∪ { i : m | w i = 0 } := by rw [Set.compl_union_self]
have hd : Disjoint { i : m | w i ≠ 0 } { i : m | w i = 0 } := disjoint_compl_left
have B₁ := iSup_range_stdBasis_eq_iInf_ker_proj K (fun _ : m => K) hd hu (Set.toFinite _)
have B₂ := iInfKerProjEquiv K (fun _ ↦ K) hd hu
rw [LinearMap.rank, range_diagonal, B₁, ← @rank_fun' K]
apply LinearEquiv.rank_eq
apply B₂
end Field
end LinearMap
|
LinearAlgebra\Matrix\DotProduct.lean | /-
Copyright (c) 2019 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Patrick Massot, Casper Putz, Anne Baanen
-/
import Mathlib.Algebra.Star.Order
import Mathlib.Data.Matrix.Basic
import Mathlib.LinearAlgebra.StdBasis
/-!
# Dot product of two vectors
This file contains some results on the map `Matrix.dotProduct`, which maps two
vectors `v w : n → R` to the sum of the entrywise products `v i * w i`.
## Main results
* `Matrix.dotProduct_stdBasis_one`: the dot product of `v` with the `i`th
standard basis vector is `v i`
* `Matrix.dotProduct_eq_zero_iff`: if `v`'s' dot product with all `w` is zero,
then `v` is zero
## Tags
matrix, reindex
-/
variable {m n p R : Type*}
namespace Matrix
section Semiring
variable [Semiring R] [Fintype n]
@[simp]
theorem dotProduct_stdBasis_eq_mul [DecidableEq n] (v : n → R) (c : R) (i : n) :
dotProduct v (LinearMap.stdBasis R (fun _ => R) i c) = v i * c := by
rw [dotProduct, Finset.sum_eq_single i, LinearMap.stdBasis_same]
· exact fun _ _ hb => by rw [LinearMap.stdBasis_ne _ _ _ _ hb, mul_zero]
· exact fun hi => False.elim (hi <| Finset.mem_univ _)
-- @[simp] -- Porting note (#10618): simp can prove this
theorem dotProduct_stdBasis_one [DecidableEq n] (v : n → R) (i : n) :
dotProduct v (LinearMap.stdBasis R (fun _ => R) i 1) = v i := by
rw [dotProduct_stdBasis_eq_mul, mul_one]
theorem dotProduct_eq (v w : n → R) (h : ∀ u, dotProduct v u = dotProduct w u) : v = w := by
funext x
classical rw [← dotProduct_stdBasis_one v x, ← dotProduct_stdBasis_one w x, h]
theorem dotProduct_eq_iff {v w : n → R} : (∀ u, dotProduct v u = dotProduct w u) ↔ v = w :=
⟨fun h => dotProduct_eq v w h, fun h _ => h ▸ rfl⟩
theorem dotProduct_eq_zero (v : n → R) (h : ∀ w, dotProduct v w = 0) : v = 0 :=
dotProduct_eq _ _ fun u => (h u).symm ▸ (zero_dotProduct u).symm
theorem dotProduct_eq_zero_iff {v : n → R} : (∀ w, dotProduct v w = 0) ↔ v = 0 :=
⟨fun h => dotProduct_eq_zero v h, fun h w => h.symm ▸ zero_dotProduct w⟩
end Semiring
section OrderedSemiring
variable [OrderedSemiring R] [Fintype n]
lemma dotProduct_nonneg_of_nonneg {v w : n → R} (hv : 0 ≤ v) (hw : 0 ≤ w) : 0 ≤ dotProduct v w :=
Finset.sum_nonneg (fun i _ => mul_nonneg (hv i) (hw i))
lemma dotProduct_le_dotProduct_of_nonneg_right {u v w : n → R} (huv : u ≤ v) (hw : 0 ≤ w) :
dotProduct u w ≤ dotProduct v w :=
Finset.sum_le_sum (fun i _ => mul_le_mul_of_nonneg_right (huv i) (hw i))
lemma dotProduct_le_dotProduct_of_nonneg_left {u v w : n → R} (huv : u ≤ v) (hw : 0 ≤ w) :
dotProduct w u ≤ dotProduct w v :=
Finset.sum_le_sum (fun i _ => mul_le_mul_of_nonneg_left (huv i) (hw i))
end OrderedSemiring
section Self
variable [Fintype m] [Fintype n] [Fintype p]
@[simp]
theorem dotProduct_self_eq_zero [LinearOrderedRing R] {v : n → R} : dotProduct v v = 0 ↔ v = 0 :=
(Finset.sum_eq_zero_iff_of_nonneg fun i _ => mul_self_nonneg (v i)).trans <| by
simp [Function.funext_iff]
section StarOrderedRing
variable [PartialOrder R] [NonUnitalRing R] [StarRing R] [StarOrderedRing R] [NoZeroDivisors R]
/-- Note that this applies to `ℂ` via `Complex.strictOrderedCommRing`. -/
@[simp]
theorem dotProduct_star_self_eq_zero {v : n → R} : dotProduct (star v) v = 0 ↔ v = 0 :=
(Finset.sum_eq_zero_iff_of_nonneg fun i _ => (star_mul_self_nonneg (r := v i) : _)).trans <|
by simp [Function.funext_iff, mul_eq_zero]
/-- Note that this applies to `ℂ` via `Complex.strictOrderedCommRing`. -/
@[simp]
theorem dotProduct_self_star_eq_zero {v : n → R} : dotProduct v (star v) = 0 ↔ v = 0 :=
(Finset.sum_eq_zero_iff_of_nonneg fun i _ => (mul_star_self_nonneg (r := v i) : _)).trans <|
by simp [Function.funext_iff, mul_eq_zero]
@[simp]
lemma conjTranspose_mul_self_eq_zero {n} {A : Matrix m n R} : Aᴴ * A = 0 ↔ A = 0 :=
⟨fun h => Matrix.ext fun i j =>
(congr_fun <| dotProduct_star_self_eq_zero.1 <| Matrix.ext_iff.2 h j j) i,
fun h => h ▸ Matrix.mul_zero _⟩
@[simp]
lemma self_mul_conjTranspose_eq_zero {m} {A : Matrix m n R} : A * Aᴴ = 0 ↔ A = 0 :=
⟨fun h => Matrix.ext fun i j =>
(congr_fun <| dotProduct_self_star_eq_zero.1 <| Matrix.ext_iff.2 h i i) j,
fun h => h ▸ Matrix.zero_mul _⟩
lemma conjTranspose_mul_self_mul_eq_zero {p} (A : Matrix m n R) (B : Matrix n p R) :
(Aᴴ * A) * B = 0 ↔ A * B = 0 := by
refine ⟨fun h => ?_, fun h => by simp only [Matrix.mul_assoc, h, Matrix.mul_zero]⟩
apply_fun (Bᴴ * ·) at h
rwa [Matrix.mul_zero, Matrix.mul_assoc, ← Matrix.mul_assoc, ← conjTranspose_mul,
conjTranspose_mul_self_eq_zero] at h
lemma self_mul_conjTranspose_mul_eq_zero {p} (A : Matrix m n R) (B : Matrix m p R) :
(A * Aᴴ) * B = 0 ↔ Aᴴ * B = 0 := by
simpa only [conjTranspose_conjTranspose] using conjTranspose_mul_self_mul_eq_zero Aᴴ _
lemma mul_self_mul_conjTranspose_eq_zero {p} (A : Matrix m n R) (B : Matrix p m R) :
B * (A * Aᴴ) = 0 ↔ B * A = 0 := by
rw [← conjTranspose_eq_zero, conjTranspose_mul, conjTranspose_mul, conjTranspose_conjTranspose,
self_mul_conjTranspose_mul_eq_zero, ← conjTranspose_mul, conjTranspose_eq_zero]
lemma mul_conjTranspose_mul_self_eq_zero {p} (A : Matrix m n R) (B : Matrix p n R) :
B * (Aᴴ * A) = 0 ↔ B * Aᴴ = 0 := by
simpa only [conjTranspose_conjTranspose] using mul_self_mul_conjTranspose_eq_zero Aᴴ _
lemma conjTranspose_mul_self_mulVec_eq_zero (A : Matrix m n R) (v : n → R) :
(Aᴴ * A) *ᵥ v = 0 ↔ A *ᵥ v = 0 := by
simpa only [← Matrix.col_mulVec, col_eq_zero] using
conjTranspose_mul_self_mul_eq_zero A (col (Fin 1) v)
lemma self_mul_conjTranspose_mulVec_eq_zero (A : Matrix m n R) (v : m → R) :
(A * Aᴴ) *ᵥ v = 0 ↔ Aᴴ *ᵥ v = 0 := by
simpa only [conjTranspose_conjTranspose] using conjTranspose_mul_self_mulVec_eq_zero Aᴴ _
lemma vecMul_conjTranspose_mul_self_eq_zero (A : Matrix m n R) (v : n → R) :
v ᵥ* (Aᴴ * A) = 0 ↔ v ᵥ* Aᴴ = 0 := by
simpa only [← Matrix.row_vecMul, row_eq_zero] using
mul_conjTranspose_mul_self_eq_zero A (row (Fin 1) v)
lemma vecMul_self_mul_conjTranspose_eq_zero (A : Matrix m n R) (v : m → R) :
v ᵥ* (A * Aᴴ) = 0 ↔ v ᵥ* A = 0 := by
simpa only [conjTranspose_conjTranspose] using vecMul_conjTranspose_mul_self_eq_zero Aᴴ _
end StarOrderedRing
end Self
end Matrix
|
LinearAlgebra\Matrix\Dual.lean | /-
Copyright (c) 2019 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Patrick Massot, Casper Putz, Anne Baanen
-/
import Mathlib.LinearAlgebra.Dual
import Mathlib.LinearAlgebra.Matrix.ToLin
/-!
# Dual space, linear maps and matrices.
This file contains some results on the matrix corresponding to the
transpose of a linear map (in the dual space).
## Tags
matrix, linear_map, transpose, dual
-/
open Matrix
section Transpose
variable {K V₁ V₂ ι₁ ι₂ : Type*} [Field K] [AddCommGroup V₁] [Module K V₁] [AddCommGroup V₂]
[Module K V₂] [Fintype ι₁] [Fintype ι₂] [DecidableEq ι₁] [DecidableEq ι₂] {B₁ : Basis ι₁ K V₁}
{B₂ : Basis ι₂ K V₂}
@[simp]
theorem LinearMap.toMatrix_transpose (u : V₁ →ₗ[K] V₂) :
LinearMap.toMatrix B₂.dualBasis B₁.dualBasis (Module.Dual.transpose (R := K) u) =
(LinearMap.toMatrix B₁ B₂ u)ᵀ := by
ext i j
simp only [LinearMap.toMatrix_apply, Module.Dual.transpose_apply, B₁.dualBasis_repr,
B₂.dualBasis_apply, Matrix.transpose_apply, LinearMap.comp_apply]
@[simp]
theorem Matrix.toLin_transpose (M : Matrix ι₁ ι₂ K) : Matrix.toLin B₁.dualBasis B₂.dualBasis Mᵀ =
Module.Dual.transpose (R := K) (Matrix.toLin B₂ B₁ M) := by
apply (LinearMap.toMatrix B₁.dualBasis B₂.dualBasis).injective
rw [LinearMap.toMatrix_toLin, LinearMap.toMatrix_transpose, LinearMap.toMatrix_toLin]
end Transpose
|
LinearAlgebra\Matrix\FiniteDimensional.lean | /-
Copyright (c) 2019 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Patrick Massot, Casper Putz, Anne Baanen
-/
import Mathlib.Data.Matrix.Basic
import Mathlib.LinearAlgebra.FiniteDimensional.Defs
import Mathlib.LinearAlgebra.FreeModule.Finite.Matrix
import Mathlib.LinearAlgebra.Matrix.ToLin
import Mathlib.Algebra.Module.Algebra
/-!
# The finite-dimensional space of matrices
This file shows that `m` by `n` matrices form a finite-dimensional space.
Note that this is proven more generally elsewhere over modules as `Module.Finite.matrix`; this file
exists only to provide an entry in the instance list for `FiniteDimensional`.
## Main definitions
* `Matrix.finiteDimensional`: matrices form a finite dimensional vector space over a field `K`
* `LinearMap.finiteDimensional`
## Tags
matrix, finite dimensional, findim, finrank
-/
universe u v
namespace Matrix
section FiniteDimensional
variable {m n : Type*} {R : Type v} [Field R]
instance finiteDimensional [Finite m] [Finite n] : FiniteDimensional R (Matrix m n R) :=
Module.Finite.matrix
end FiniteDimensional
end Matrix
namespace LinearMap
variable {K : Type*} [Field K]
variable {V : Type*} [AddCommGroup V] [Module K V] [FiniteDimensional K V]
variable {W : Type*} [AddCommGroup W] [Module K W] [FiniteDimensional K W]
instance finiteDimensional : FiniteDimensional K (V →ₗ[K] W) :=
Module.Finite.linearMap _ _ _ _
variable {A : Type*} [Ring A] [Algebra K A] [Module A V] [IsScalarTower K A V] [Module A W]
[IsScalarTower K A W]
/-- Linear maps over a `k`-algebra are finite dimensional (over `k`) if both the source and
target are, as they form a subspace of all `k`-linear maps. -/
instance finiteDimensional' : FiniteDimensional K (V →ₗ[A] W) :=
FiniteDimensional.of_injective (restrictScalarsLinearMap K A V W) (restrictScalars_injective _)
end LinearMap
|
LinearAlgebra\Matrix\Gershgorin.lean | /-
Copyright (c) 2023 Xavier Roblot. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Xavier Roblot
-/
import Mathlib.Analysis.Normed.Field.Basic
import Mathlib.LinearAlgebra.Eigenspace.Basic
import Mathlib.LinearAlgebra.Determinant
/-!
# Gershgorin's circle theorem
This file gives the proof of Gershgorin's circle theorem `eigenvalue_mem_ball` on the eigenvalues
of matrices and some applications.
## Reference
* https://en.wikipedia.org/wiki/Gershgorin_circle_theorem
-/
variable {K n : Type*} [NormedField K] [Fintype n] [DecidableEq n] {A : Matrix n n K}
/-- **Gershgorin's circle theorem**: for any eigenvalue `μ` of a square matrix `A`, there exists an
index `k` such that `μ` lies in the closed ball of center the diagonal term `A k k` and of
radius the sum of the norms `∑ j ≠ k, ‖A k j‖. -/
theorem eigenvalue_mem_ball {μ : K} (hμ : Module.End.HasEigenvalue (Matrix.toLin' A) μ) :
∃ k, μ ∈ Metric.closedBall (A k k) (∑ j ∈ Finset.univ.erase k, ‖A k j‖) := by
cases isEmpty_or_nonempty n
· exfalso
exact hμ Submodule.eq_bot_of_subsingleton
· obtain ⟨v, h_eg, h_nz⟩ := hμ.exists_hasEigenvector
obtain ⟨i, -, h_i⟩ := Finset.exists_mem_eq_sup' Finset.univ_nonempty (fun i => ‖v i‖)
have h_nz : v i ≠ 0 := by
contrapose! h_nz
ext j
rw [Pi.zero_apply, ← norm_le_zero_iff]
refine (h_i ▸ Finset.le_sup' (fun i => ‖v i‖) (Finset.mem_univ j)).trans ?_
exact norm_le_zero_iff.mpr h_nz
have h_le : ∀ j, ‖v j * (v i)⁻¹‖ ≤ 1 := fun j => by
rw [norm_mul, norm_inv, mul_inv_le_iff' (norm_pos_iff.mpr h_nz), one_mul]
exact h_i ▸ Finset.le_sup' (fun i => ‖v i‖) (Finset.mem_univ j)
simp_rw [mem_closedBall_iff_norm']
refine ⟨i, ?_⟩
calc
_ = ‖(A i i * v i - μ * v i) * (v i)⁻¹‖ := by congr; field_simp [h_nz]; ring
_ = ‖(A i i * v i - ∑ j, A i j * v j) * (v i)⁻¹‖ := by
rw [show μ * v i = ∑ x : n, A i x * v x by
rw [← Matrix.dotProduct, ← Matrix.mulVec]
exact (congrFun (Module.End.mem_eigenspace_iff.mp h_eg) i).symm]
_ = ‖(∑ j ∈ Finset.univ.erase i, A i j * v j) * (v i)⁻¹‖ := by
rw [Finset.sum_erase_eq_sub (Finset.mem_univ i), ← neg_sub, neg_mul, norm_neg]
_ ≤ ∑ j ∈ Finset.univ.erase i, ‖A i j‖ * ‖v j * (v i)⁻¹‖ := by
rw [Finset.sum_mul]
exact (norm_sum_le _ _).trans (le_of_eq (by simp_rw [mul_assoc, norm_mul]))
_ ≤ ∑ j ∈ Finset.univ.erase i, ‖A i j‖ :=
(Finset.sum_le_sum fun j _ => mul_le_of_le_one_right (norm_nonneg _) (h_le j))
/-- If `A` is a row strictly dominant diagonal matrix, then it's determinant is nonzero. -/
theorem det_ne_zero_of_sum_row_lt_diag (h : ∀ k, ∑ j ∈ Finset.univ.erase k, ‖A k j‖ < ‖A k k‖) :
A.det ≠ 0 := by
contrapose! h
suffices ∃ k, 0 ∈ Metric.closedBall (A k k) (∑ j ∈ Finset.univ.erase k, ‖A k j‖) by
exact this.imp (fun a h ↦ by rwa [mem_closedBall_iff_norm', sub_zero] at h)
refine eigenvalue_mem_ball ?_
rw [Module.End.HasEigenvalue, Module.End.eigenspace_zero, ne_comm]
exact ne_of_lt (LinearMap.bot_lt_ker_of_det_eq_zero (by rwa [LinearMap.det_toLin']))
/-- If `A` is a column strictly dominant diagonal matrix, then it's determinant is nonzero. -/
theorem det_ne_zero_of_sum_col_lt_diag (h : ∀ k, ∑ i ∈ Finset.univ.erase k, ‖A i k‖ < ‖A k k‖) :
A.det ≠ 0 := by
rw [← Matrix.det_transpose]
exact det_ne_zero_of_sum_row_lt_diag (by simp_rw [Matrix.transpose_apply]; exact h)
|
LinearAlgebra\Matrix\Hermitian.lean | /-
Copyright (c) 2022 Alexander Bentkamp. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Alexander Bentkamp
-/
import Mathlib.Analysis.InnerProductSpace.PiL2
import Mathlib.LinearAlgebra.Matrix.ZPow
/-! # Hermitian matrices
This file defines hermitian matrices and some basic results about them.
See also `IsSelfAdjoint`, which generalizes this definition to other star rings.
## Main definition
* `Matrix.IsHermitian` : a matrix `A : Matrix n n α` is hermitian if `Aᴴ = A`.
## Tags
self-adjoint matrix, hermitian matrix
-/
namespace Matrix
variable {α β : Type*} {m n : Type*} {A : Matrix n n α}
open scoped Matrix
local notation "⟪" x ", " y "⟫" => @inner α _ _ x y
section Star
variable [Star α] [Star β]
/-- A matrix is hermitian if it is equal to its conjugate transpose. On the reals, this definition
captures symmetric matrices. -/
def IsHermitian (A : Matrix n n α) : Prop := Aᴴ = A
instance (A : Matrix n n α) [Decidable (Aᴴ = A)] : Decidable (IsHermitian A) :=
inferInstanceAs <| Decidable (_ = _)
theorem IsHermitian.eq {A : Matrix n n α} (h : A.IsHermitian) : Aᴴ = A := h
protected theorem IsHermitian.isSelfAdjoint {A : Matrix n n α} (h : A.IsHermitian) :
IsSelfAdjoint A := h
-- @[ext] -- Porting note (#11041): incorrect `ext`, not a structure or a lemma proving `x = y`.
theorem IsHermitian.ext {A : Matrix n n α} : (∀ i j, star (A j i) = A i j) → A.IsHermitian := by
intro h; ext i j; exact h i j
theorem IsHermitian.apply {A : Matrix n n α} (h : A.IsHermitian) (i j : n) : star (A j i) = A i j :=
congr_fun (congr_fun h _) _
theorem IsHermitian.ext_iff {A : Matrix n n α} : A.IsHermitian ↔ ∀ i j, star (A j i) = A i j :=
⟨IsHermitian.apply, IsHermitian.ext⟩
@[simp]
theorem IsHermitian.map {A : Matrix n n α} (h : A.IsHermitian) (f : α → β)
(hf : Function.Semiconj f star star) : (A.map f).IsHermitian :=
(conjTranspose_map f hf).symm.trans <| h.eq.symm ▸ rfl
theorem IsHermitian.transpose {A : Matrix n n α} (h : A.IsHermitian) : Aᵀ.IsHermitian := by
rw [IsHermitian, conjTranspose, transpose_map]
exact congr_arg Matrix.transpose h
@[simp]
theorem isHermitian_transpose_iff (A : Matrix n n α) : Aᵀ.IsHermitian ↔ A.IsHermitian :=
⟨by intro h; rw [← transpose_transpose A]; exact IsHermitian.transpose h, IsHermitian.transpose⟩
theorem IsHermitian.conjTranspose {A : Matrix n n α} (h : A.IsHermitian) : Aᴴ.IsHermitian :=
h.transpose.map _ fun _ => rfl
@[simp]
theorem IsHermitian.submatrix {A : Matrix n n α} (h : A.IsHermitian) (f : m → n) :
(A.submatrix f f).IsHermitian := (conjTranspose_submatrix _ _ _).trans (h.symm ▸ rfl)
@[simp]
theorem isHermitian_submatrix_equiv {A : Matrix n n α} (e : m ≃ n) :
(A.submatrix e e).IsHermitian ↔ A.IsHermitian :=
⟨fun h => by simpa using h.submatrix e.symm, fun h => h.submatrix _⟩
end Star
section InvolutiveStar
variable [InvolutiveStar α]
@[simp]
theorem isHermitian_conjTranspose_iff (A : Matrix n n α) : Aᴴ.IsHermitian ↔ A.IsHermitian :=
IsSelfAdjoint.star_iff
/-- A block matrix `A.from_blocks B C D` is hermitian,
if `A` and `D` are hermitian and `Bᴴ = C`. -/
theorem IsHermitian.fromBlocks {A : Matrix m m α} {B : Matrix m n α} {C : Matrix n m α}
{D : Matrix n n α} (hA : A.IsHermitian) (hBC : Bᴴ = C) (hD : D.IsHermitian) :
(A.fromBlocks B C D).IsHermitian := by
have hCB : Cᴴ = B := by rw [← hBC, conjTranspose_conjTranspose]
unfold Matrix.IsHermitian
rw [fromBlocks_conjTranspose, hBC, hCB, hA, hD]
/-- This is the `iff` version of `Matrix.IsHermitian.fromBlocks`. -/
theorem isHermitian_fromBlocks_iff {A : Matrix m m α} {B : Matrix m n α} {C : Matrix n m α}
{D : Matrix n n α} :
(A.fromBlocks B C D).IsHermitian ↔ A.IsHermitian ∧ Bᴴ = C ∧ Cᴴ = B ∧ D.IsHermitian :=
⟨fun h =>
⟨congr_arg toBlocks₁₁ h, congr_arg toBlocks₂₁ h, congr_arg toBlocks₁₂ h,
congr_arg toBlocks₂₂ h⟩,
fun ⟨hA, hBC, _hCB, hD⟩ => IsHermitian.fromBlocks hA hBC hD⟩
end InvolutiveStar
section AddMonoid
variable [AddMonoid α] [StarAddMonoid α] [AddMonoid β] [StarAddMonoid β]
/-- A diagonal matrix is hermitian if the entries are self-adjoint (as a vector) -/
theorem isHermitian_diagonal_of_self_adjoint [DecidableEq n] (v : n → α) (h : IsSelfAdjoint v) :
(diagonal v).IsHermitian :=
(-- TODO: add a `pi.has_trivial_star` instance and remove the `funext`
diagonal_conjTranspose v).trans <| congr_arg _ h
/-- A diagonal matrix is hermitian if each diagonal entry is self-adjoint -/
lemma isHermitian_diagonal_iff [DecidableEq n] {d : n → α} :
IsHermitian (diagonal d) ↔ (∀ i : n, IsSelfAdjoint (d i)) := by
simp [isSelfAdjoint_iff, IsHermitian, conjTranspose, diagonal_transpose, diagonal_map]
/-- A diagonal matrix is hermitian if the entries have the trivial `star` operation
(such as on the reals). -/
@[simp]
theorem isHermitian_diagonal [TrivialStar α] [DecidableEq n] (v : n → α) :
(diagonal v).IsHermitian :=
isHermitian_diagonal_of_self_adjoint _ (IsSelfAdjoint.all _)
@[simp]
theorem isHermitian_zero : (0 : Matrix n n α).IsHermitian :=
IsSelfAdjoint.zero _
@[simp]
theorem IsHermitian.add {A B : Matrix n n α} (hA : A.IsHermitian) (hB : B.IsHermitian) :
(A + B).IsHermitian :=
IsSelfAdjoint.add hA hB
end AddMonoid
section AddCommMonoid
variable [AddCommMonoid α] [StarAddMonoid α]
theorem isHermitian_add_transpose_self (A : Matrix n n α) : (A + Aᴴ).IsHermitian :=
IsSelfAdjoint.add_star_self A
theorem isHermitian_transpose_add_self (A : Matrix n n α) : (Aᴴ + A).IsHermitian :=
IsSelfAdjoint.star_add_self A
end AddCommMonoid
section AddGroup
variable [AddGroup α] [StarAddMonoid α]
@[simp]
theorem IsHermitian.neg {A : Matrix n n α} (h : A.IsHermitian) : (-A).IsHermitian :=
IsSelfAdjoint.neg h
@[simp]
theorem IsHermitian.sub {A B : Matrix n n α} (hA : A.IsHermitian) (hB : B.IsHermitian) :
(A - B).IsHermitian :=
IsSelfAdjoint.sub hA hB
end AddGroup
section NonUnitalSemiring
variable [NonUnitalSemiring α] [StarRing α] [NonUnitalSemiring β] [StarRing β]
/-- Note this is more general than `IsSelfAdjoint.mul_star_self` as `B` can be rectangular. -/
theorem isHermitian_mul_conjTranspose_self [Fintype n] (A : Matrix m n α) :
(A * Aᴴ).IsHermitian := by rw [IsHermitian, conjTranspose_mul, conjTranspose_conjTranspose]
/-- Note this is more general than `IsSelfAdjoint.star_mul_self` as `B` can be rectangular. -/
theorem isHermitian_transpose_mul_self [Fintype m] (A : Matrix m n α) : (Aᴴ * A).IsHermitian := by
rw [IsHermitian, conjTranspose_mul, conjTranspose_conjTranspose]
/-- Note this is more general than `IsSelfAdjoint.conjugate'` as `B` can be rectangular. -/
theorem isHermitian_conjTranspose_mul_mul [Fintype m] {A : Matrix m m α} (B : Matrix m n α)
(hA : A.IsHermitian) : (Bᴴ * A * B).IsHermitian := by
simp only [IsHermitian, conjTranspose_mul, conjTranspose_conjTranspose, hA.eq, Matrix.mul_assoc]
/-- Note this is more general than `IsSelfAdjoint.conjugate` as `B` can be rectangular. -/
theorem isHermitian_mul_mul_conjTranspose [Fintype m] {A : Matrix m m α} (B : Matrix n m α)
(hA : A.IsHermitian) : (B * A * Bᴴ).IsHermitian := by
simp only [IsHermitian, conjTranspose_mul, conjTranspose_conjTranspose, hA.eq, Matrix.mul_assoc]
lemma commute_iff [Fintype n] {A B : Matrix n n α}
(hA : A.IsHermitian) (hB : B.IsHermitian) : Commute A B ↔ (A * B).IsHermitian :=
hA.isSelfAdjoint.commute_iff hB.isSelfAdjoint
end NonUnitalSemiring
section Semiring
variable [Semiring α] [StarRing α] [Semiring β] [StarRing β]
/-- Note this is more general for matrices than `isSelfAdjoint_one` as it does not
require `Fintype n`, which is necessary for `Monoid (Matrix n n R)`. -/
@[simp]
theorem isHermitian_one [DecidableEq n] : (1 : Matrix n n α).IsHermitian :=
conjTranspose_one
theorem IsHermitian.pow [Fintype n] [DecidableEq n] {A : Matrix n n α} (h : A.IsHermitian) (k : ℕ) :
(A ^ k).IsHermitian := IsSelfAdjoint.pow h _
end Semiring
section CommRing
variable [CommRing α] [StarRing α]
theorem IsHermitian.inv [Fintype m] [DecidableEq m] {A : Matrix m m α} (hA : A.IsHermitian) :
A⁻¹.IsHermitian := by simp [IsHermitian, conjTranspose_nonsing_inv, hA.eq]
@[simp]
theorem isHermitian_inv [Fintype m] [DecidableEq m] (A : Matrix m m α) [Invertible A] :
A⁻¹.IsHermitian ↔ A.IsHermitian :=
⟨fun h => by rw [← inv_inv_of_invertible A]; exact IsHermitian.inv h, IsHermitian.inv⟩
theorem IsHermitian.adjugate [Fintype m] [DecidableEq m] {A : Matrix m m α} (hA : A.IsHermitian) :
A.adjugate.IsHermitian := by simp [IsHermitian, adjugate_conjTranspose, hA.eq]
/-- Note that `IsSelfAdjoint.zpow` does not apply to matrices as they are not a division ring. -/
theorem IsHermitian.zpow [Fintype m] [DecidableEq m] {A : Matrix m m α} (h : A.IsHermitian)
(k : ℤ) :
(A ^ k).IsHermitian := by
rw [IsHermitian, conjTranspose_zpow, h]
end CommRing
section RCLike
open RCLike
variable [RCLike α] [RCLike β]
/-- The diagonal elements of a complex hermitian matrix are real. -/
theorem IsHermitian.coe_re_apply_self {A : Matrix n n α} (h : A.IsHermitian) (i : n) :
(re (A i i) : α) = A i i := by rw [← conj_eq_iff_re, ← star_def, ← conjTranspose_apply, h.eq]
/-- The diagonal elements of a complex hermitian matrix are real. -/
theorem IsHermitian.coe_re_diag {A : Matrix n n α} (h : A.IsHermitian) :
(fun i => (re (A.diag i) : α)) = A.diag :=
funext h.coe_re_apply_self
/-- A matrix is hermitian iff the corresponding linear map is self adjoint. -/
theorem isHermitian_iff_isSymmetric [Fintype n] [DecidableEq n] {A : Matrix n n α} :
IsHermitian A ↔ A.toEuclideanLin.IsSymmetric := by
rw [LinearMap.IsSymmetric, (WithLp.equiv 2 (n → α)).symm.surjective.forall₂]
simp only [toEuclideanLin_piLp_equiv_symm, EuclideanSpace.inner_piLp_equiv_symm, toLin'_apply,
star_mulVec, dotProduct_mulVec]
constructor
· rintro (h : Aᴴ = A) x y
rw [h]
· intro h
ext i j
simpa only [(Pi.single_star i 1).symm, ← star_mulVec, mul_one, dotProduct_single,
single_vecMul, star_one, one_mul] using h (Pi.single i 1) (Pi.single j 1)
end RCLike
end Matrix
|
LinearAlgebra\Matrix\HermitianFunctionalCalculus.lean | /-
Copyright (c) 2024 Jon Bannon. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jon Bannon, Jireh Loreaux
-/
import Mathlib.LinearAlgebra.Matrix.Spectrum
import Mathlib.LinearAlgebra.Eigenspace.Matrix
import Mathlib.Analysis.CStarAlgebra.ContinuousFunctionalCalculus.Unique
import Mathlib.Topology.ContinuousFunction.Units
/-!
# Continuous Functional Calculus for Hermitian Matrices
This file defines an instance of the continuous functional calculus for Hermitian matrices over an
`RCLike` field `𝕜`.
## Main Results
- `Matrix.IsHermitian.cfc` : Realization of the functional calculus for a Hermitian matrix
as the triple product `U * diagonal (RCLike.ofReal ∘ f ∘ hA.eigenvalues) * star U` with
`U = eigenvectorUnitary hA`.
- `cfc_eq` : Proof that the above agrees with the continuous functional calculus.
- `Matrix.IsHermitian.instContinuousFunctionalCalculus` : Instance of the continuous functional
calculus for a Hermitian matrix `A` over `𝕜`.
## Tags
spectral theorem, diagonalization theorem, continuous functional calculus
-/
namespace Matrix
variable {n 𝕜 : Type*} [RCLike 𝕜] [Fintype n] [DecidableEq n] {A : Matrix n n 𝕜}
lemma finite_real_spectrum : (spectrum ℝ A).Finite := by
rw [← spectrum.preimage_algebraMap 𝕜]
exact A.finite_spectrum.preimage (NoZeroSMulDivisors.algebraMap_injective ℝ 𝕜).injOn
instance : Finite (spectrum ℝ A) := A.finite_real_spectrum
namespace IsHermitian
variable (hA : IsHermitian A)
/-- The `ℝ`-spectrum of a Hermitian matrix over `RCLike` field is the range of the eigenvalue
function -/
theorem eigenvalues_eq_spectrum_real {a : Matrix n n 𝕜} (ha : IsHermitian a) :
spectrum ℝ a = Set.range (ha.eigenvalues) := by
ext x
conv_lhs => rw [ha.spectral_theorem, unitary.spectrum.unitary_conjugate,
← spectrum.algebraMap_mem_iff 𝕜, spectrum_diagonal, RCLike.algebraMap_eq_ofReal]
simp
/-- The star algebra homomorphism underlying the instance of the continuous functional
calculus of a Hermitian matrix. This is an auxiliary definition and is not intended
for use outside of this file. -/
@[simps]
noncomputable def cfcAux : C(spectrum ℝ A, ℝ) →⋆ₐ[ℝ] (Matrix n n 𝕜) where
toFun := fun g => (eigenvectorUnitary hA : Matrix n n 𝕜) *
diagonal (RCLike.ofReal ∘ g ∘ (fun i ↦ ⟨hA.eigenvalues i, hA.eigenvalues_mem_spectrum_real i⟩))
* star (eigenvectorUnitary hA : Matrix n n 𝕜)
map_one' := by simp [Pi.one_def (f := fun _ : n ↦ 𝕜)]
map_mul' f g := by
have {a b c d e f : Matrix n n 𝕜} : (a * b * c) * (d * e * f) = a * (b * (c * d) * e) * f := by
simp only [mul_assoc]
simp only [this, ContinuousMap.coe_mul, SetLike.coe_mem, unitary.star_mul_self_of_mem, mul_one,
diagonal_mul_diagonal, Function.comp_apply]
congr! with i
simp
map_zero' := by simp [Pi.zero_def (f := fun _ : n ↦ 𝕜)]
map_add' f g := by
simp only [ContinuousMap.coe_add, ← add_mul, ← mul_add, diagonal_add, Function.comp_apply]
congr! with i
simp
commutes' r := by
simp only [Function.comp, algebraMap_apply, smul_eq_mul, mul_one]
rw [← mul_one (algebraMap _ _ _), ← unitary.coe_mul_star_self hA.eigenvectorUnitary,
← Algebra.left_comm, unitary.coe_star, mul_assoc]
congr!
map_star' f := by
simp only [star_trivial, StarMul.star_mul, star_star, star_eq_conjTranspose (diagonal _),
diagonal_conjTranspose, mul_assoc]
congr!
ext
simp
lemma closedEmbedding_cfcAux : ClosedEmbedding hA.cfcAux := by
have h0 : FiniteDimensional ℝ C(spectrum ℝ A, ℝ) :=
FiniteDimensional.of_injective (ContinuousMap.coeFnLinearMap ℝ (M := ℝ)) DFunLike.coe_injective
refine LinearMap.closedEmbedding_of_injective (𝕜 := ℝ) (E := C(spectrum ℝ A, ℝ))
(F := Matrix n n 𝕜) (f := hA.cfcAux) <| LinearMap.ker_eq_bot'.mpr fun f hf ↦ ?_
have h2 :
diagonal (RCLike.ofReal ∘ f ∘ fun i ↦ ⟨hA.eigenvalues i, hA.eigenvalues_mem_spectrum_real i⟩)
= (0 : Matrix n n 𝕜) := by
simp only [LinearMap.coe_coe, cfcAux_apply] at hf
replace hf := congr($(hf) * (eigenvectorUnitary hA : Matrix n n 𝕜))
simp only [mul_assoc, SetLike.coe_mem, unitary.star_mul_self_of_mem, mul_one, zero_mul] at hf
simpa [← mul_assoc] using congr((star hA.eigenvectorUnitary : Matrix n n 𝕜) * $(hf))
ext x
simp only [ContinuousMap.zero_apply]
obtain ⟨x, hx⟩ := x
obtain ⟨i, rfl⟩ := hA.eigenvalues_eq_spectrum_real ▸ hx
rw [← diagonal_zero] at h2
have := (diagonal_eq_diagonal_iff).mp h2
refine RCLike.ofReal_eq_zero.mp (this i)
lemma cfcAux_id : hA.cfcAux (.restrict (spectrum ℝ A) (.id ℝ)) = A := by
conv_rhs => rw [hA.spectral_theorem]
congr!
/-- Instance of the continuous functional calculus for a Hermitian matrix over `𝕜` with
`RCLike 𝕜`. -/
instance instContinuousFunctionalCalculus :
ContinuousFunctionalCalculus ℝ (IsSelfAdjoint : Matrix n n 𝕜 → Prop) where
exists_cfc_of_predicate a ha := by
replace ha : IsHermitian a := ha
refine ⟨ha.cfcAux, ha.closedEmbedding_cfcAux, ha.cfcAux_id, fun f ↦ ?map_spec,
fun f ↦ ?hermitian⟩
case map_spec =>
apply Set.eq_of_subset_of_subset
· rw [← ContinuousMap.spectrum_eq_range f]
apply AlgHom.spectrum_apply_subset
· rw [cfcAux_apply, unitary.spectrum.unitary_conjugate]
rintro - ⟨x , rfl⟩
apply spectrum.of_algebraMap_mem 𝕜
simp only [Function.comp_apply, Set.mem_range, spectrum_diagonal]
obtain ⟨x, hx⟩ := x
obtain ⟨i, rfl⟩ := ha.eigenvalues_eq_spectrum_real ▸ hx
exact ⟨i, rfl⟩
case hermitian =>
simp only [isSelfAdjoint_iff, cfcAux_apply, mul_assoc, star_mul, star_star]
rw [star_eq_conjTranspose, diagonal_conjTranspose]
congr!
simp [Pi.star_def, Function.comp]
predicate_zero := .zero _
instance instUniqueContinuousFunctionalCalculus :
UniqueContinuousFunctionalCalculus ℝ (Matrix n n 𝕜) :=
let _ : NormedRing (Matrix n n 𝕜) := Matrix.linftyOpNormedRing
let _ : NormedAlgebra ℝ (Matrix n n 𝕜) := Matrix.linftyOpNormedAlgebra
inferInstance
/-- The continuous functional calculus of a Hermitian matrix as a triple product using the
spectral theorem. Note that this actually operates on bare functions since every function is
continuous on the spectrum of a matrix, since the spectrum is finite. This is shown to be equal to
the generic continuous functional calculus API in `Matrix.IsHermitian.cfc_eq`. In general, users
should prefer the generic API, especially because it will make rewriting easier. -/
protected noncomputable def cfc (f : ℝ → ℝ) : Matrix n n 𝕜 :=
(eigenvectorUnitary hA : Matrix n n 𝕜) * diagonal (RCLike.ofReal ∘ f ∘ hA.eigenvalues)
* star (eigenvectorUnitary hA : Matrix n n 𝕜)
lemma cfc_eq (f : ℝ → ℝ) : cfc f A = hA.cfc f := by
have hA' : IsSelfAdjoint A := hA
have := cfcHom_eq_of_continuous_of_map_id hA' hA.cfcAux hA.closedEmbedding_cfcAux.continuous
hA.cfcAux_id
rw [cfc_apply f A hA' (by rw [continuousOn_iff_continuous_restrict]; fun_prop), this]
simp only [cfcAux_apply, ContinuousMap.coe_mk, Function.comp, Set.restrict_apply, IsHermitian.cfc]
end IsHermitian
end Matrix
|
LinearAlgebra\Matrix\InvariantBasisNumber.lean | /-
Copyright (c) 2022 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison
-/
import Mathlib.LinearAlgebra.Matrix.ToLin
import Mathlib.LinearAlgebra.InvariantBasisNumber
/-!
# Invertible matrices over a ring with invariant basis number are square.
-/
variable {n m : Type*} [Fintype n] [DecidableEq n] [Fintype m] [DecidableEq m]
variable {R : Type*} [Semiring R] [InvariantBasisNumber R]
open Matrix
theorem Matrix.square_of_invertible (M : Matrix n m R) (N : Matrix m n R) (h : M * N = 1)
(h' : N * M = 1) : Fintype.card n = Fintype.card m :=
card_eq_of_linearEquiv R (Matrix.toLinearEquivRight'OfInv h' h)
|
LinearAlgebra\Matrix\IsDiag.lean | /-
Copyright (c) 2021 Lu-Ming Zhang. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Lu-Ming Zhang
-/
import Mathlib.LinearAlgebra.Matrix.Symmetric
import Mathlib.LinearAlgebra.Matrix.Orthogonal
import Mathlib.Data.Matrix.Kronecker
/-!
# Diagonal matrices
This file contains the definition and basic results about diagonal matrices.
## Main results
- `Matrix.IsDiag`: a proposition that states a given square matrix `A` is diagonal.
## Tags
diag, diagonal, matrix
-/
namespace Matrix
variable {α β R n m : Type*}
open Function
open Matrix Kronecker
/-- `A.IsDiag` means square matrix `A` is a diagonal matrix. -/
def IsDiag [Zero α] (A : Matrix n n α) : Prop :=
Pairwise fun i j => A i j = 0
@[simp]
theorem isDiag_diagonal [Zero α] [DecidableEq n] (d : n → α) : (diagonal d).IsDiag := fun _ _ =>
Matrix.diagonal_apply_ne _
/-- Diagonal matrices are generated by the `Matrix.diagonal` of their `Matrix.diag`. -/
theorem IsDiag.diagonal_diag [Zero α] [DecidableEq n] {A : Matrix n n α} (h : A.IsDiag) :
diagonal (diag A) = A :=
ext fun i j => by
obtain rfl | hij := Decidable.eq_or_ne i j
· rw [diagonal_apply_eq, diag]
· rw [diagonal_apply_ne _ hij, h hij]
/-- `Matrix.IsDiag.diagonal_diag` as an iff. -/
theorem isDiag_iff_diagonal_diag [Zero α] [DecidableEq n] (A : Matrix n n α) :
A.IsDiag ↔ diagonal (diag A) = A :=
⟨IsDiag.diagonal_diag, fun hd => hd ▸ isDiag_diagonal (diag A)⟩
/-- Every matrix indexed by a subsingleton is diagonal. -/
theorem isDiag_of_subsingleton [Zero α] [Subsingleton n] (A : Matrix n n α) : A.IsDiag :=
fun i j h => (h <| Subsingleton.elim i j).elim
/-- Every zero matrix is diagonal. -/
@[simp]
theorem isDiag_zero [Zero α] : (0 : Matrix n n α).IsDiag := fun _ _ _ => rfl
/-- Every identity matrix is diagonal. -/
@[simp]
theorem isDiag_one [DecidableEq n] [Zero α] [One α] : (1 : Matrix n n α).IsDiag := fun _ _ =>
one_apply_ne
theorem IsDiag.map [Zero α] [Zero β] {A : Matrix n n α} (ha : A.IsDiag) {f : α → β} (hf : f 0 = 0) :
(A.map f).IsDiag := by
intro i j h
simp [ha h, hf]
theorem IsDiag.neg [AddGroup α] {A : Matrix n n α} (ha : A.IsDiag) : (-A).IsDiag := by
intro i j h
simp [ha h]
@[simp]
theorem isDiag_neg_iff [AddGroup α] {A : Matrix n n α} : (-A).IsDiag ↔ A.IsDiag :=
⟨fun ha _ _ h => neg_eq_zero.1 (ha h), IsDiag.neg⟩
theorem IsDiag.add [AddZeroClass α] {A B : Matrix n n α} (ha : A.IsDiag) (hb : B.IsDiag) :
(A + B).IsDiag := by
intro i j h
simp [ha h, hb h]
theorem IsDiag.sub [AddGroup α] {A B : Matrix n n α} (ha : A.IsDiag) (hb : B.IsDiag) :
(A - B).IsDiag := by
intro i j h
simp [ha h, hb h]
theorem IsDiag.smul [Monoid R] [AddMonoid α] [DistribMulAction R α] (k : R) {A : Matrix n n α}
(ha : A.IsDiag) : (k • A).IsDiag := by
intro i j h
simp [ha h]
@[simp]
theorem isDiag_smul_one (n) [Semiring α] [DecidableEq n] (k : α) :
(k • (1 : Matrix n n α)).IsDiag :=
isDiag_one.smul k
theorem IsDiag.transpose [Zero α] {A : Matrix n n α} (ha : A.IsDiag) : Aᵀ.IsDiag := fun _ _ h =>
ha h.symm
@[simp]
theorem isDiag_transpose_iff [Zero α] {A : Matrix n n α} : Aᵀ.IsDiag ↔ A.IsDiag :=
⟨IsDiag.transpose, IsDiag.transpose⟩
theorem IsDiag.conjTranspose [Semiring α] [StarRing α] {A : Matrix n n α} (ha : A.IsDiag) :
Aᴴ.IsDiag :=
ha.transpose.map (star_zero _)
@[simp]
theorem isDiag_conjTranspose_iff [Semiring α] [StarRing α] {A : Matrix n n α} :
Aᴴ.IsDiag ↔ A.IsDiag :=
⟨fun ha => by
convert ha.conjTranspose
simp, IsDiag.conjTranspose⟩
theorem IsDiag.submatrix [Zero α] {A : Matrix n n α} (ha : A.IsDiag) {f : m → n}
(hf : Injective f) : (A.submatrix f f).IsDiag := fun _ _ h => ha (hf.ne h)
/-- `(A ⊗ B).IsDiag` if both `A` and `B` are diagonal. -/
theorem IsDiag.kronecker [MulZeroClass α] {A : Matrix m m α} {B : Matrix n n α} (hA : A.IsDiag)
(hB : B.IsDiag) : (A ⊗ₖ B).IsDiag := by
rintro ⟨a, b⟩ ⟨c, d⟩ h
simp only [Prod.mk.inj_iff, Ne, not_and_or] at h
cases' h with hac hbd
· simp [hA hac]
· simp [hB hbd]
theorem IsDiag.isSymm [Zero α] {A : Matrix n n α} (h : A.IsDiag) : A.IsSymm := by
ext i j
by_cases g : i = j; · rw [g, transpose_apply]
simp [h g, h (Ne.symm g)]
/-- The block matrix `A.fromBlocks 0 0 D` is diagonal if `A` and `D` are diagonal. -/
theorem IsDiag.fromBlocks [Zero α] {A : Matrix m m α} {D : Matrix n n α} (ha : A.IsDiag)
(hd : D.IsDiag) : (A.fromBlocks 0 0 D).IsDiag := by
rintro (i | i) (j | j) hij
· exact ha (ne_of_apply_ne _ hij)
· rfl
· rfl
· exact hd (ne_of_apply_ne _ hij)
/-- This is the `iff` version of `Matrix.IsDiag.fromBlocks`. -/
theorem isDiag_fromBlocks_iff [Zero α] {A : Matrix m m α} {B : Matrix m n α} {C : Matrix n m α}
{D : Matrix n n α} : (A.fromBlocks B C D).IsDiag ↔ A.IsDiag ∧ B = 0 ∧ C = 0 ∧ D.IsDiag := by
constructor
· intro h
refine ⟨fun i j hij => ?_, ext fun i j => ?_, ext fun i j => ?_, fun i j hij => ?_⟩
· exact h (Sum.inl_injective.ne hij)
· exact h Sum.inl_ne_inr
· exact h Sum.inr_ne_inl
· exact h (Sum.inr_injective.ne hij)
· rintro ⟨ha, hb, hc, hd⟩
convert IsDiag.fromBlocks ha hd
/-- A symmetric block matrix `A.fromBlocks B C D` is diagonal
if `A` and `D` are diagonal and `B` is `0`. -/
theorem IsDiag.fromBlocks_of_isSymm [Zero α] {A : Matrix m m α} {C : Matrix n m α}
{D : Matrix n n α} (h : (A.fromBlocks 0 C D).IsSymm) (ha : A.IsDiag) (hd : D.IsDiag) :
(A.fromBlocks 0 C D).IsDiag := by
rw [← (isSymm_fromBlocks_iff.1 h).2.1]
exact ha.fromBlocks hd
theorem mul_transpose_self_isDiag_iff_hasOrthogonalRows [Fintype n] [Mul α] [AddCommMonoid α]
{A : Matrix m n α} : (A * Aᵀ).IsDiag ↔ A.HasOrthogonalRows :=
Iff.rfl
theorem transpose_mul_self_isDiag_iff_hasOrthogonalCols [Fintype m] [Mul α] [AddCommMonoid α]
{A : Matrix m n α} : (Aᵀ * A).IsDiag ↔ A.HasOrthogonalCols :=
Iff.rfl
end Matrix
|
LinearAlgebra\Matrix\LDL.lean | /-
Copyright (c) 2022 Alexander Bentkamp. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Alexander Bentkamp
-/
import Mathlib.Analysis.InnerProductSpace.GramSchmidtOrtho
import Mathlib.LinearAlgebra.Matrix.PosDef
/-! # LDL decomposition
This file proves the LDL-decomposition of matrices: Any positive definite matrix `S` can be
decomposed as `S = LDLᴴ` where `L` is a lower-triangular matrix and `D` is a diagonal matrix.
## Main definitions
* `LDL.lower` is the lower triangular matrix `L`.
* `LDL.lowerInv` is the inverse of the lower triangular matrix `L`.
* `LDL.diag` is the diagonal matrix `D`.
## Main result
* `LDL.lower_conj_diag` states that any positive definite matrix can be decomposed as `LDLᴴ`.
## TODO
* Prove that `LDL.lower` is lower triangular from `LDL.lowerInv_triangular`.
-/
variable {𝕜 : Type*} [RCLike 𝕜]
variable {n : Type*} [LinearOrder n] [IsWellOrder n (· < ·)] [LocallyFiniteOrderBot n]
section set_options
set_option quotPrecheck false
local notation "⟪" x ", " y "⟫ₑ" =>
@inner 𝕜 _ _ ((WithLp.equiv 2 _).symm x) ((WithLp.equiv _ _).symm y)
open Matrix
open scoped Matrix ComplexOrder
variable {S : Matrix n n 𝕜} [Fintype n] (hS : S.PosDef)
/-- The inverse of the lower triangular matrix `L` of the LDL-decomposition. It is obtained by
applying Gram-Schmidt-Orthogonalization w.r.t. the inner product induced by `Sᵀ` on the standard
basis vectors `Pi.basisFun`. -/
noncomputable def LDL.lowerInv : Matrix n n 𝕜 :=
@gramSchmidt 𝕜 (n → 𝕜) _ (_ : _) (InnerProductSpace.ofMatrix hS.transpose) n _ _ _
(Pi.basisFun 𝕜 n)
theorem LDL.lowerInv_eq_gramSchmidtBasis :
LDL.lowerInv hS =
((Pi.basisFun 𝕜 n).toMatrix
(@gramSchmidtBasis 𝕜 (n → 𝕜) _ (_ : _) (InnerProductSpace.ofMatrix hS.transpose) n _ _ _
(Pi.basisFun 𝕜 n)))ᵀ := by
letI := NormedAddCommGroup.ofMatrix hS.transpose
letI := InnerProductSpace.ofMatrix hS.transpose
ext i j
rw [LDL.lowerInv, Basis.coePiBasisFun.toMatrix_eq_transpose, coe_gramSchmidtBasis]
rfl
noncomputable instance LDL.invertibleLowerInv : Invertible (LDL.lowerInv hS) := by
rw [LDL.lowerInv_eq_gramSchmidtBasis]
haveI :=
Basis.invertibleToMatrix (Pi.basisFun 𝕜 n)
(@gramSchmidtBasis 𝕜 (n → 𝕜) _ (_ : _) (InnerProductSpace.ofMatrix hS.transpose) n _ _ _
(Pi.basisFun 𝕜 n))
infer_instance
theorem LDL.lowerInv_orthogonal {i j : n} (h₀ : i ≠ j) :
⟪LDL.lowerInv hS i, Sᵀ *ᵥ LDL.lowerInv hS j⟫ₑ = 0 :=
@gramSchmidt_orthogonal 𝕜 _ _ (_ : _) (InnerProductSpace.ofMatrix hS.transpose) _ _ _ _ _ _ _ h₀
/-- The entries of the diagonal matrix `D` of the LDL decomposition. -/
noncomputable def LDL.diagEntries : n → 𝕜 := fun i =>
⟪star (LDL.lowerInv hS i), S *ᵥ star (LDL.lowerInv hS i)⟫ₑ
/-- The diagonal matrix `D` of the LDL decomposition. -/
noncomputable def LDL.diag : Matrix n n 𝕜 :=
Matrix.diagonal (LDL.diagEntries hS)
theorem LDL.lowerInv_triangular {i j : n} (hij : i < j) : LDL.lowerInv hS i j = 0 := by
rw [←
@gramSchmidt_triangular 𝕜 (n → 𝕜) _ (_ : _) (InnerProductSpace.ofMatrix hS.transpose) n _ _ _
i j hij (Pi.basisFun 𝕜 n),
Pi.basisFun_repr, LDL.lowerInv]
/-- Inverse statement of **LDL decomposition**: we can conjugate a positive definite matrix
by some lower triangular matrix and get a diagonal matrix. -/
theorem LDL.diag_eq_lowerInv_conj : LDL.diag hS = LDL.lowerInv hS * S * (LDL.lowerInv hS)ᴴ := by
ext i j
by_cases hij : i = j
· simp only [diag, diagEntries, EuclideanSpace.inner_piLp_equiv_symm, star_star, hij,
diagonal_apply_eq, Matrix.mul_assoc]
rfl
· simp only [LDL.diag, hij, diagonal_apply_ne, Ne, not_false_iff, mul_mul_apply]
rw [conjTranspose, transpose_map, transpose_transpose, dotProduct_mulVec,
(LDL.lowerInv_orthogonal hS fun h : j = i => hij h.symm).symm, ← inner_conj_symm,
mulVec_transpose, EuclideanSpace.inner_piLp_equiv_symm, ← RCLike.star_def, ←
star_dotProduct_star, dotProduct_comm, star_star]
rfl
/-- The lower triangular matrix `L` of the LDL decomposition. -/
noncomputable def LDL.lower :=
(LDL.lowerInv hS)⁻¹
/-- **LDL decomposition**: any positive definite matrix `S` can be
decomposed as `S = LDLᴴ` where `L` is a lower-triangular matrix and `D` is a diagonal matrix. -/
theorem LDL.lower_conj_diag : LDL.lower hS * LDL.diag hS * (LDL.lower hS)ᴴ = S := by
rw [LDL.lower, conjTranspose_nonsing_inv, Matrix.mul_assoc,
Matrix.inv_mul_eq_iff_eq_mul_of_invertible (LDL.lowerInv hS),
Matrix.mul_inv_eq_iff_eq_mul_of_invertible]
exact LDL.diag_eq_lowerInv_conj hS
end set_options
|
LinearAlgebra\Matrix\MvPolynomial.lean | /-
Copyright (c) 2021 Eric Wieser. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Eric Wieser
-/
import Mathlib.Algebra.MvPolynomial.Basic
import Mathlib.Algebra.MvPolynomial.CommRing
import Mathlib.LinearAlgebra.Matrix.Determinant.Basic
/-!
# Matrices of multivariate polynomials
In this file, we prove results about matrices over an mv_polynomial ring.
In particular, we provide `Matrix.mvPolynomialX` which associates every entry of a matrix with a
unique variable.
## Tags
matrix determinant, multivariate polynomial
-/
variable {m n R S : Type*}
namespace Matrix
variable (m n R)
/-- The matrix with variable `X (i,j)` at location `(i,j)`. -/
noncomputable def mvPolynomialX [CommSemiring R] : Matrix m n (MvPolynomial (m × n) R) :=
of fun i j => MvPolynomial.X (i, j)
-- TODO: set as an equation lemma for `mv_polynomial_X`, see mathlib4#3024
@[simp]
theorem mvPolynomialX_apply [CommSemiring R] (i j) :
mvPolynomialX m n R i j = MvPolynomial.X (i, j) :=
rfl
variable {m n R}
/-- Any matrix `A` can be expressed as the evaluation of `Matrix.mvPolynomialX`.
This is of particular use when `MvPolynomial (m × n) R` is an integral domain but `S` is
not, as if the `MvPolynomial.eval₂` can be pulled to the outside of a goal, it can be solved in
under cancellative assumptions. -/
theorem mvPolynomialX_map_eval₂ [CommSemiring R] [CommSemiring S] (f : R →+* S) (A : Matrix m n S) :
(mvPolynomialX m n R).map (MvPolynomial.eval₂ f fun p : m × n => A p.1 p.2) = A :=
ext fun i j => MvPolynomial.eval₂_X _ (fun p : m × n => A p.1 p.2) (i, j)
/-- A variant of `Matrix.mvPolynomialX_map_eval₂` with a bundled `RingHom` on the LHS. -/
theorem mvPolynomialX_mapMatrix_eval [Fintype m] [DecidableEq m] [CommSemiring R]
(A : Matrix m m R) :
(MvPolynomial.eval fun p : m × m => A p.1 p.2).mapMatrix (mvPolynomialX m m R) = A :=
mvPolynomialX_map_eval₂ _ A
variable (R)
/-- A variant of `Matrix.mvPolynomialX_map_eval₂` with a bundled `AlgHom` on the LHS. -/
theorem mvPolynomialX_mapMatrix_aeval [Fintype m] [DecidableEq m] [CommSemiring R] [CommSemiring S]
[Algebra R S] (A : Matrix m m S) :
(MvPolynomial.aeval fun p : m × m => A p.1 p.2).mapMatrix (mvPolynomialX m m R) = A :=
mvPolynomialX_map_eval₂ _ A
variable (m)
/-- In a nontrivial ring, `Matrix.mvPolynomialX m m R` has non-zero determinant. -/
theorem det_mvPolynomialX_ne_zero [DecidableEq m] [Fintype m] [CommRing R] [Nontrivial R] :
det (mvPolynomialX m m R) ≠ 0 := by
intro h_det
have := congr_arg Matrix.det (mvPolynomialX_mapMatrix_eval (1 : Matrix m m R))
rw [det_one, ← RingHom.map_det, h_det, RingHom.map_zero] at this
exact zero_ne_one this
end Matrix
|
LinearAlgebra\Matrix\Nondegenerate.lean | /-
Copyright (c) 2021 Anne Baanen. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Anne Baanen
-/
import Mathlib.Data.Matrix.Basic
import Mathlib.LinearAlgebra.Matrix.Determinant.Basic
import Mathlib.LinearAlgebra.Matrix.Adjugate
/-!
# Matrices associated with non-degenerate bilinear forms
## Main definitions
* `Matrix.Nondegenerate A`: the proposition that when interpreted as a bilinear form, the matrix `A`
is nondegenerate.
-/
namespace Matrix
variable {m R A : Type*} [Fintype m] [CommRing R]
/-- A matrix `M` is nondegenerate if for all `v ≠ 0`, there is a `w ≠ 0` with `w * M * v ≠ 0`. -/
def Nondegenerate (M : Matrix m m R) :=
∀ v, (∀ w, Matrix.dotProduct v (M *ᵥ w) = 0) → v = 0
/-- If `M` is nondegenerate and `w * M * v = 0` for all `w`, then `v = 0`. -/
theorem Nondegenerate.eq_zero_of_ortho {M : Matrix m m R} (hM : Nondegenerate M) {v : m → R}
(hv : ∀ w, Matrix.dotProduct v (M *ᵥ w) = 0) : v = 0 :=
hM v hv
/-- If `M` is nondegenerate and `v ≠ 0`, then there is some `w` such that `w * M * v ≠ 0`. -/
theorem Nondegenerate.exists_not_ortho_of_ne_zero {M : Matrix m m R} (hM : Nondegenerate M)
{v : m → R} (hv : v ≠ 0) : ∃ w, Matrix.dotProduct v (M *ᵥ w) ≠ 0 :=
not_forall.mp (mt hM.eq_zero_of_ortho hv)
variable [CommRing A] [IsDomain A]
/-- If `M` has a nonzero determinant, then `M` as a bilinear form on `n → A` is nondegenerate.
See also `BilinForm.nondegenerateOfDetNeZero'` and `BilinForm.nondegenerateOfDetNeZero`.
-/
theorem nondegenerate_of_det_ne_zero [DecidableEq m] {M : Matrix m m A} (hM : M.det ≠ 0) :
Nondegenerate M := by
intro v hv
ext i
specialize hv (M.cramer (Pi.single i 1))
refine (mul_eq_zero.mp ?_).resolve_right hM
convert hv
simp only [mulVec_cramer M (Pi.single i 1), dotProduct, Pi.smul_apply, smul_eq_mul]
rw [Finset.sum_eq_single i, Pi.single_eq_same, mul_one]
· intro j _ hj
simp [hj]
· intros
have := Finset.mem_univ i
contradiction
theorem eq_zero_of_vecMul_eq_zero [DecidableEq m] {M : Matrix m m A} (hM : M.det ≠ 0) {v : m → A}
(hv : v ᵥ* M = 0) : v = 0 :=
(nondegenerate_of_det_ne_zero hM).eq_zero_of_ortho fun w => by
rw [dotProduct_mulVec, hv, zero_dotProduct]
theorem eq_zero_of_mulVec_eq_zero [DecidableEq m] {M : Matrix m m A} (hM : M.det ≠ 0) {v : m → A}
(hv : M *ᵥ v = 0) : v = 0 :=
eq_zero_of_vecMul_eq_zero (by rwa [det_transpose]) ((vecMul_transpose M v).trans hv)
end Matrix
|
LinearAlgebra\Matrix\NonsingularInverse.lean | /-
Copyright (c) 2019 Anne Baanen. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Anne Baanen, Lu-Ming Zhang
-/
import Mathlib.Data.Matrix.Invertible
import Mathlib.LinearAlgebra.Matrix.Adjugate
import Mathlib.LinearAlgebra.FiniteDimensional.Defs
/-!
# Nonsingular inverses
In this file, we define an inverse for square matrices of invertible determinant.
For matrices that are not square or not of full rank, there is a more general notion of
pseudoinverses which we do not consider here.
The definition of inverse used in this file is the adjugate divided by the determinant.
We show that dividing the adjugate by `det A` (if possible), giving a matrix `A⁻¹` (`nonsing_inv`),
will result in a multiplicative inverse to `A`.
Note that there are at least three different inverses in mathlib:
* `A⁻¹` (`Inv.inv`): alone, this satisfies no properties, although it is usually used in
conjunction with `Group` or `GroupWithZero`. On matrices, this is defined to be zero when no
inverse exists.
* `⅟A` (`invOf`): this is only available in the presence of `[Invertible A]`, which guarantees an
inverse exists.
* `Ring.inverse A`: this is defined on any `MonoidWithZero`, and just like `⁻¹` on matrices, is
defined to be zero when no inverse exists.
We start by working with `Invertible`, and show the main results:
* `Matrix.invertibleOfDetInvertible`
* `Matrix.detInvertibleOfInvertible`
* `Matrix.isUnit_iff_isUnit_det`
* `Matrix.mul_eq_one_comm`
After this we define `Matrix.inv` and show it matches `⅟A` and `Ring.inverse A`.
The rest of the results in the file are then about `A⁻¹`
## References
* https://en.wikipedia.org/wiki/Cramer's_rule#Finding_inverse_matrix
## Tags
matrix inverse, cramer, cramer's rule, adjugate
-/
namespace Matrix
universe u u' v
variable {l : Type*} {m : Type u} {n : Type u'} {α : Type v}
open Matrix Equiv Equiv.Perm Finset
/-! ### Matrices are `Invertible` iff their determinants are -/
section Invertible
variable [Fintype n] [DecidableEq n] [CommRing α]
variable (A : Matrix n n α) (B : Matrix n n α)
/-- If `A.det` has a constructive inverse, produce one for `A`. -/
def invertibleOfDetInvertible [Invertible A.det] : Invertible A where
invOf := ⅟ A.det • A.adjugate
mul_invOf_self := by
rw [mul_smul_comm, mul_adjugate, smul_smul, invOf_mul_self, one_smul]
invOf_mul_self := by
rw [smul_mul_assoc, adjugate_mul, smul_smul, invOf_mul_self, one_smul]
theorem invOf_eq [Invertible A.det] [Invertible A] : ⅟ A = ⅟ A.det • A.adjugate := by
letI := invertibleOfDetInvertible A
convert (rfl : ⅟ A = _)
/-- `A.det` is invertible if `A` has a left inverse. -/
def detInvertibleOfLeftInverse (h : B * A = 1) : Invertible A.det where
invOf := B.det
mul_invOf_self := by rw [mul_comm, ← det_mul, h, det_one]
invOf_mul_self := by rw [← det_mul, h, det_one]
/-- `A.det` is invertible if `A` has a right inverse. -/
def detInvertibleOfRightInverse (h : A * B = 1) : Invertible A.det where
invOf := B.det
mul_invOf_self := by rw [← det_mul, h, det_one]
invOf_mul_self := by rw [mul_comm, ← det_mul, h, det_one]
/-- If `A` has a constructive inverse, produce one for `A.det`. -/
def detInvertibleOfInvertible [Invertible A] : Invertible A.det :=
detInvertibleOfLeftInverse A (⅟ A) (invOf_mul_self _)
theorem det_invOf [Invertible A] [Invertible A.det] : (⅟ A).det = ⅟ A.det := by
letI := detInvertibleOfInvertible A
convert (rfl : _ = ⅟ A.det)
/-- Together `Matrix.detInvertibleOfInvertible` and `Matrix.invertibleOfDetInvertible` form an
equivalence, although both sides of the equiv are subsingleton anyway. -/
@[simps]
def invertibleEquivDetInvertible : Invertible A ≃ Invertible A.det where
toFun := @detInvertibleOfInvertible _ _ _ _ _ A
invFun := @invertibleOfDetInvertible _ _ _ _ _ A
left_inv _ := Subsingleton.elim _ _
right_inv _ := Subsingleton.elim _ _
variable {A B}
theorem mul_eq_one_comm : A * B = 1 ↔ B * A = 1 :=
suffices ∀ A B : Matrix n n α, A * B = 1 → B * A = 1 from ⟨this A B, this B A⟩
fun A B h => by
letI : Invertible B.det := detInvertibleOfLeftInverse _ _ h
letI : Invertible B := invertibleOfDetInvertible B
calc
B * A = B * A * (B * ⅟ B) := by rw [mul_invOf_self, Matrix.mul_one]
_ = B * (A * B * ⅟ B) := by simp only [Matrix.mul_assoc]
_ = B * ⅟ B := by rw [h, Matrix.one_mul]
_ = 1 := mul_invOf_self B
variable (A B)
/-- We can construct an instance of invertible A if A has a left inverse. -/
def invertibleOfLeftInverse (h : B * A = 1) : Invertible A :=
⟨B, h, mul_eq_one_comm.mp h⟩
/-- We can construct an instance of invertible A if A has a right inverse. -/
def invertibleOfRightInverse (h : A * B = 1) : Invertible A :=
⟨B, mul_eq_one_comm.mp h, h⟩
/-- Given a proof that `A.det` has a constructive inverse, lift `A` to `(Matrix n n α)ˣ`-/
def unitOfDetInvertible [Invertible A.det] : (Matrix n n α)ˣ :=
@unitOfInvertible _ _ A (invertibleOfDetInvertible A)
/-- When lowered to a prop, `Matrix.invertibleEquivDetInvertible` forms an `iff`. -/
theorem isUnit_iff_isUnit_det : IsUnit A ↔ IsUnit A.det := by
simp only [← nonempty_invertible_iff_isUnit, (invertibleEquivDetInvertible A).nonempty_congr]
@[simp]
theorem isUnits_det_units (A : (Matrix n n α)ˣ) : IsUnit (A : Matrix n n α).det :=
isUnit_iff_isUnit_det _ |>.mp A.isUnit
/-! #### Variants of the statements above with `IsUnit`-/
theorem isUnit_det_of_invertible [Invertible A] : IsUnit A.det :=
@isUnit_of_invertible _ _ _ (detInvertibleOfInvertible A)
variable {A B}
theorem isUnit_of_left_inverse (h : B * A = 1) : IsUnit A :=
⟨⟨A, B, mul_eq_one_comm.mp h, h⟩, rfl⟩
theorem exists_left_inverse_iff_isUnit : (∃ B, B * A = 1) ↔ IsUnit A :=
⟨fun ⟨_, h⟩ ↦ isUnit_of_left_inverse h, fun h ↦ have := h.invertible; ⟨⅟A, invOf_mul_self' A⟩⟩
theorem isUnit_of_right_inverse (h : A * B = 1) : IsUnit A :=
⟨⟨A, B, h, mul_eq_one_comm.mp h⟩, rfl⟩
theorem exists_right_inverse_iff_isUnit : (∃ B, A * B = 1) ↔ IsUnit A :=
⟨fun ⟨_, h⟩ ↦ isUnit_of_right_inverse h, fun h ↦ have := h.invertible; ⟨⅟A, mul_invOf_self' A⟩⟩
theorem isUnit_det_of_left_inverse (h : B * A = 1) : IsUnit A.det :=
@isUnit_of_invertible _ _ _ (detInvertibleOfLeftInverse _ _ h)
theorem isUnit_det_of_right_inverse (h : A * B = 1) : IsUnit A.det :=
@isUnit_of_invertible _ _ _ (detInvertibleOfRightInverse _ _ h)
theorem det_ne_zero_of_left_inverse [Nontrivial α] (h : B * A = 1) : A.det ≠ 0 :=
(isUnit_det_of_left_inverse h).ne_zero
theorem det_ne_zero_of_right_inverse [Nontrivial α] (h : A * B = 1) : A.det ≠ 0 :=
(isUnit_det_of_right_inverse h).ne_zero
end Invertible
section Inv
variable [Fintype n] [DecidableEq n] [CommRing α]
variable (A : Matrix n n α) (B : Matrix n n α)
theorem isUnit_det_transpose (h : IsUnit A.det) : IsUnit Aᵀ.det := by
rw [det_transpose]
exact h
/-! ### A noncomputable `Inv` instance -/
/-- The inverse of a square matrix, when it is invertible (and zero otherwise). -/
noncomputable instance inv : Inv (Matrix n n α) :=
⟨fun A => Ring.inverse A.det • A.adjugate⟩
theorem inv_def (A : Matrix n n α) : A⁻¹ = Ring.inverse A.det • A.adjugate :=
rfl
theorem nonsing_inv_apply_not_isUnit (h : ¬IsUnit A.det) : A⁻¹ = 0 := by
rw [inv_def, Ring.inverse_non_unit _ h, zero_smul]
theorem nonsing_inv_apply (h : IsUnit A.det) : A⁻¹ = (↑h.unit⁻¹ : α) • A.adjugate := by
rw [inv_def, ← Ring.inverse_unit h.unit, IsUnit.unit_spec]
/-- The nonsingular inverse is the same as `invOf` when `A` is invertible. -/
@[simp]
theorem invOf_eq_nonsing_inv [Invertible A] : ⅟ A = A⁻¹ := by
letI := detInvertibleOfInvertible A
rw [inv_def, Ring.inverse_invertible, invOf_eq]
/-- Coercing the result of `Units.instInv` is the same as coercing first and applying the
nonsingular inverse. -/
@[simp, norm_cast]
theorem coe_units_inv (A : (Matrix n n α)ˣ) : ↑A⁻¹ = (A⁻¹ : Matrix n n α) := by
letI := A.invertible
rw [← invOf_eq_nonsing_inv, invOf_units]
/-- The nonsingular inverse is the same as the general `Ring.inverse`. -/
theorem nonsing_inv_eq_ring_inverse : A⁻¹ = Ring.inverse A := by
by_cases h_det : IsUnit A.det
· cases (A.isUnit_iff_isUnit_det.mpr h_det).nonempty_invertible
rw [← invOf_eq_nonsing_inv, Ring.inverse_invertible]
· have h := mt A.isUnit_iff_isUnit_det.mp h_det
rw [Ring.inverse_non_unit _ h, nonsing_inv_apply_not_isUnit A h_det]
theorem transpose_nonsing_inv : A⁻¹ᵀ = Aᵀ⁻¹ := by
rw [inv_def, inv_def, transpose_smul, det_transpose, adjugate_transpose]
theorem conjTranspose_nonsing_inv [StarRing α] : A⁻¹ᴴ = Aᴴ⁻¹ := by
rw [inv_def, inv_def, conjTranspose_smul, det_conjTranspose, adjugate_conjTranspose,
Ring.inverse_star]
/-- The `nonsing_inv` of `A` is a right inverse. -/
@[simp]
theorem mul_nonsing_inv (h : IsUnit A.det) : A * A⁻¹ = 1 := by
cases (A.isUnit_iff_isUnit_det.mpr h).nonempty_invertible
rw [← invOf_eq_nonsing_inv, mul_invOf_self]
/-- The `nonsing_inv` of `A` is a left inverse. -/
@[simp]
theorem nonsing_inv_mul (h : IsUnit A.det) : A⁻¹ * A = 1 := by
cases (A.isUnit_iff_isUnit_det.mpr h).nonempty_invertible
rw [← invOf_eq_nonsing_inv, invOf_mul_self]
instance [Invertible A] : Invertible A⁻¹ := by
rw [← invOf_eq_nonsing_inv]
infer_instance
@[simp]
theorem inv_inv_of_invertible [Invertible A] : A⁻¹⁻¹ = A := by
simp only [← invOf_eq_nonsing_inv, invOf_invOf]
@[simp]
theorem mul_nonsing_inv_cancel_right (B : Matrix m n α) (h : IsUnit A.det) : B * A * A⁻¹ = B := by
simp [Matrix.mul_assoc, mul_nonsing_inv A h]
@[simp]
theorem mul_nonsing_inv_cancel_left (B : Matrix n m α) (h : IsUnit A.det) : A * (A⁻¹ * B) = B := by
simp [← Matrix.mul_assoc, mul_nonsing_inv A h]
@[simp]
theorem nonsing_inv_mul_cancel_right (B : Matrix m n α) (h : IsUnit A.det) : B * A⁻¹ * A = B := by
simp [Matrix.mul_assoc, nonsing_inv_mul A h]
@[simp]
theorem nonsing_inv_mul_cancel_left (B : Matrix n m α) (h : IsUnit A.det) : A⁻¹ * (A * B) = B := by
simp [← Matrix.mul_assoc, nonsing_inv_mul A h]
@[simp]
theorem mul_inv_of_invertible [Invertible A] : A * A⁻¹ = 1 :=
mul_nonsing_inv A (isUnit_det_of_invertible A)
@[simp]
theorem inv_mul_of_invertible [Invertible A] : A⁻¹ * A = 1 :=
nonsing_inv_mul A (isUnit_det_of_invertible A)
@[simp]
theorem mul_inv_cancel_right_of_invertible (B : Matrix m n α) [Invertible A] : B * A * A⁻¹ = B :=
mul_nonsing_inv_cancel_right A B (isUnit_det_of_invertible A)
@[simp]
theorem mul_inv_cancel_left_of_invertible (B : Matrix n m α) [Invertible A] : A * (A⁻¹ * B) = B :=
mul_nonsing_inv_cancel_left A B (isUnit_det_of_invertible A)
@[simp]
theorem inv_mul_cancel_right_of_invertible (B : Matrix m n α) [Invertible A] : B * A⁻¹ * A = B :=
nonsing_inv_mul_cancel_right A B (isUnit_det_of_invertible A)
@[simp]
theorem inv_mul_cancel_left_of_invertible (B : Matrix n m α) [Invertible A] : A⁻¹ * (A * B) = B :=
nonsing_inv_mul_cancel_left A B (isUnit_det_of_invertible A)
theorem inv_mul_eq_iff_eq_mul_of_invertible (A B C : Matrix n n α) [Invertible A] :
A⁻¹ * B = C ↔ B = A * C :=
⟨fun h => by rw [← h, mul_inv_cancel_left_of_invertible],
fun h => by rw [h, inv_mul_cancel_left_of_invertible]⟩
theorem mul_inv_eq_iff_eq_mul_of_invertible (A B C : Matrix n n α) [Invertible A] :
B * A⁻¹ = C ↔ B = C * A :=
⟨fun h => by rw [← h, inv_mul_cancel_right_of_invertible],
fun h => by rw [h, mul_inv_cancel_right_of_invertible]⟩
lemma inv_mulVec_eq_vec {A : Matrix n n α} [Invertible A]
{u v : n → α} (hM : u = A.mulVec v) : A⁻¹.mulVec u = v := by
rw [hM, Matrix.mulVec_mulVec, Matrix.inv_mul_of_invertible, Matrix.one_mulVec]
lemma mul_right_injective_of_invertible [Invertible A] :
Function.Injective (fun (x : Matrix n m α) => A * x) :=
fun _ _ h => by simpa only [inv_mul_cancel_left_of_invertible] using congr_arg (A⁻¹ * ·) h
lemma mul_left_injective_of_invertible [Invertible A] :
Function.Injective (fun (x : Matrix m n α) => x * A) :=
fun a x hax => by simpa only [mul_inv_cancel_right_of_invertible] using congr_arg (· * A⁻¹) hax
lemma mul_right_inj_of_invertible [Invertible A] {x y : Matrix n m α} : A * x = A * y ↔ x = y :=
(mul_right_injective_of_invertible A).eq_iff
lemma mul_left_inj_of_invertible [Invertible A] {x y : Matrix m n α} : x * A = y * A ↔ x = y :=
(mul_left_injective_of_invertible A).eq_iff
end Inv
section InjectiveMul
variable [Fintype n] [Fintype m] [DecidableEq m] [CommRing α]
lemma mul_left_injective_of_inv (A : Matrix m n α) (B : Matrix n m α) (h : A * B = 1) :
Function.Injective (fun x : Matrix l m α => x * A) := fun _ _ g => by
simpa only [Matrix.mul_assoc, Matrix.mul_one, h] using congr_arg (· * B) g
lemma mul_right_injective_of_inv (A : Matrix m n α) (B : Matrix n m α) (h : A * B = 1) :
Function.Injective (fun x : Matrix m l α => B * x) :=
fun _ _ g => by simpa only [← Matrix.mul_assoc, Matrix.one_mul, h] using congr_arg (A * ·) g
end InjectiveMul
section vecMul
section Semiring
variable {R : Type*} [Semiring R]
theorem vecMul_surjective_iff_exists_left_inverse
[DecidableEq n] [Fintype m] [Finite n] {A : Matrix m n R} :
Function.Surjective A.vecMul ↔ ∃ B : Matrix n m R, B * A = 1 := by
cases nonempty_fintype n
refine ⟨fun h ↦ ?_, fun ⟨B, hBA⟩ y ↦ ⟨y ᵥ* B, by simp [hBA]⟩⟩
choose rows hrows using (h <| Pi.single · 1)
refine ⟨Matrix.of rows, Matrix.ext fun i j => ?_⟩
rw [mul_apply_eq_vecMul, one_eq_pi_single, ← hrows]
rfl
theorem mulVec_surjective_iff_exists_right_inverse
[DecidableEq m] [Finite m] [Fintype n] {A : Matrix m n R} :
Function.Surjective A.mulVec ↔ ∃ B : Matrix n m R, A * B = 1 := by
cases nonempty_fintype m
refine ⟨fun h ↦ ?_, fun ⟨B, hBA⟩ y ↦ ⟨B *ᵥ y, by simp [hBA]⟩⟩
choose cols hcols using (h <| Pi.single · 1)
refine ⟨(Matrix.of cols)ᵀ, Matrix.ext fun i j ↦ ?_⟩
rw [one_eq_pi_single, Pi.single_comm, ← hcols j]
rfl
end Semiring
variable [DecidableEq m] {R K : Type*} [CommRing R] [Field K] [Fintype m]
theorem vecMul_surjective_iff_isUnit {A : Matrix m m R} :
Function.Surjective A.vecMul ↔ IsUnit A := by
rw [vecMul_surjective_iff_exists_left_inverse, exists_left_inverse_iff_isUnit]
theorem mulVec_surjective_iff_isUnit {A : Matrix m m R} :
Function.Surjective A.mulVec ↔ IsUnit A := by
rw [mulVec_surjective_iff_exists_right_inverse, exists_right_inverse_iff_isUnit]
theorem vecMul_injective_iff_isUnit {A : Matrix m m K} :
Function.Injective A.vecMul ↔ IsUnit A := by
refine ⟨fun h ↦ ?_, fun h ↦ ?_⟩
· rw [← vecMul_surjective_iff_isUnit]
exact LinearMap.surjective_of_injective (f := A.vecMulLinear) h
change Function.Injective A.vecMulLinear
rw [← LinearMap.ker_eq_bot, LinearMap.ker_eq_bot']
intro c hc
replace h := h.invertible
simpa using congr_arg A⁻¹.vecMulLinear hc
theorem mulVec_injective_iff_isUnit {A : Matrix m m K} :
Function.Injective A.mulVec ↔ IsUnit A := by
rw [← isUnit_transpose, ← vecMul_injective_iff_isUnit]
simp_rw [vecMul_transpose]
theorem linearIndependent_rows_iff_isUnit {A : Matrix m m K} :
LinearIndependent K (fun i ↦ A i) ↔ IsUnit A := by
rw [← transpose_transpose A, ← mulVec_injective_iff, ← coe_mulVecLin, mulVecLin_transpose,
transpose_transpose, ← vecMul_injective_iff_isUnit, coe_vecMulLinear]
theorem linearIndependent_cols_iff_isUnit {A : Matrix m m K} :
LinearIndependent K (fun i ↦ Aᵀ i) ↔ IsUnit A := by
rw [← transpose_transpose A, isUnit_transpose, linearIndependent_rows_iff_isUnit,
transpose_transpose]
theorem vecMul_surjective_of_invertible (A : Matrix m m R) [Invertible A] :
Function.Surjective A.vecMul :=
vecMul_surjective_iff_isUnit.2 <| isUnit_of_invertible A
theorem mulVec_surjective_of_invertible (A : Matrix m m R) [Invertible A] :
Function.Surjective A.mulVec :=
mulVec_surjective_iff_isUnit.2 <| isUnit_of_invertible A
theorem vecMul_injective_of_invertible (A : Matrix m m K) [Invertible A] :
Function.Injective A.vecMul :=
vecMul_injective_iff_isUnit.2 <| isUnit_of_invertible A
theorem mulVec_injective_of_invertible (A : Matrix m m K) [Invertible A] :
Function.Injective A.mulVec :=
mulVec_injective_iff_isUnit.2 <| isUnit_of_invertible A
theorem linearIndependent_rows_of_invertible (A : Matrix m m K) [Invertible A] :
LinearIndependent K (fun i ↦ A i) :=
linearIndependent_rows_iff_isUnit.2 <| isUnit_of_invertible A
theorem linearIndependent_cols_of_invertible (A : Matrix m m K) [Invertible A] :
LinearIndependent K (fun i ↦ Aᵀ i) :=
linearIndependent_cols_iff_isUnit.2 <| isUnit_of_invertible A
end vecMul
variable [Fintype n] [DecidableEq n] [CommRing α]
variable (A : Matrix n n α) (B : Matrix n n α)
theorem nonsing_inv_cancel_or_zero : A⁻¹ * A = 1 ∧ A * A⁻¹ = 1 ∨ A⁻¹ = 0 := by
by_cases h : IsUnit A.det
· exact Or.inl ⟨nonsing_inv_mul _ h, mul_nonsing_inv _ h⟩
· exact Or.inr (nonsing_inv_apply_not_isUnit _ h)
theorem det_nonsing_inv_mul_det (h : IsUnit A.det) : A⁻¹.det * A.det = 1 := by
rw [← det_mul, A.nonsing_inv_mul h, det_one]
@[simp]
theorem det_nonsing_inv : A⁻¹.det = Ring.inverse A.det := by
by_cases h : IsUnit A.det
· cases h.nonempty_invertible
letI := invertibleOfDetInvertible A
rw [Ring.inverse_invertible, ← invOf_eq_nonsing_inv, det_invOf]
cases isEmpty_or_nonempty n
· rw [det_isEmpty, det_isEmpty, Ring.inverse_one]
· rw [Ring.inverse_non_unit _ h, nonsing_inv_apply_not_isUnit _ h, det_zero ‹_›]
theorem isUnit_nonsing_inv_det (h : IsUnit A.det) : IsUnit A⁻¹.det :=
isUnit_of_mul_eq_one _ _ (A.det_nonsing_inv_mul_det h)
@[simp]
theorem nonsing_inv_nonsing_inv (h : IsUnit A.det) : A⁻¹⁻¹ = A :=
calc
A⁻¹⁻¹ = 1 * A⁻¹⁻¹ := by rw [Matrix.one_mul]
_ = A * A⁻¹ * A⁻¹⁻¹ := by rw [A.mul_nonsing_inv h]
_ = A := by
rw [Matrix.mul_assoc, A⁻¹.mul_nonsing_inv (A.isUnit_nonsing_inv_det h), Matrix.mul_one]
theorem isUnit_nonsing_inv_det_iff {A : Matrix n n α} : IsUnit A⁻¹.det ↔ IsUnit A.det := by
rw [Matrix.det_nonsing_inv, isUnit_ring_inverse]
-- `IsUnit.invertible` lifts the proposition `IsUnit A` to a constructive inverse of `A`.
/-- A version of `Matrix.invertibleOfDetInvertible` with the inverse defeq to `A⁻¹` that is
therefore noncomputable. -/
noncomputable def invertibleOfIsUnitDet (h : IsUnit A.det) : Invertible A :=
⟨A⁻¹, nonsing_inv_mul A h, mul_nonsing_inv A h⟩
/-- A version of `Matrix.unitOfDetInvertible` with the inverse defeq to `A⁻¹` that is therefore
noncomputable. -/
noncomputable def nonsingInvUnit (h : IsUnit A.det) : (Matrix n n α)ˣ :=
@unitOfInvertible _ _ _ (invertibleOfIsUnitDet A h)
theorem unitOfDetInvertible_eq_nonsingInvUnit [Invertible A.det] :
unitOfDetInvertible A = nonsingInvUnit A (isUnit_of_invertible _) := by
ext
rfl
variable {A} {B}
/-- If matrix A is left invertible, then its inverse equals its left inverse. -/
theorem inv_eq_left_inv (h : B * A = 1) : A⁻¹ = B :=
letI := invertibleOfLeftInverse _ _ h
invOf_eq_nonsing_inv A ▸ invOf_eq_left_inv h
/-- If matrix A is right invertible, then its inverse equals its right inverse. -/
theorem inv_eq_right_inv (h : A * B = 1) : A⁻¹ = B :=
inv_eq_left_inv (mul_eq_one_comm.2 h)
section InvEqInv
variable {C : Matrix n n α}
/-- The left inverse of matrix A is unique when existing. -/
theorem left_inv_eq_left_inv (h : B * A = 1) (g : C * A = 1) : B = C := by
rw [← inv_eq_left_inv h, ← inv_eq_left_inv g]
/-- The right inverse of matrix A is unique when existing. -/
theorem right_inv_eq_right_inv (h : A * B = 1) (g : A * C = 1) : B = C := by
rw [← inv_eq_right_inv h, ← inv_eq_right_inv g]
/-- The right inverse of matrix A equals the left inverse of A when they exist. -/
theorem right_inv_eq_left_inv (h : A * B = 1) (g : C * A = 1) : B = C := by
rw [← inv_eq_right_inv h, ← inv_eq_left_inv g]
theorem inv_inj (h : A⁻¹ = B⁻¹) (h' : IsUnit A.det) : A = B := by
refine left_inv_eq_left_inv (mul_nonsing_inv _ h') ?_
rw [h]
refine mul_nonsing_inv _ ?_
rwa [← isUnit_nonsing_inv_det_iff, ← h, isUnit_nonsing_inv_det_iff]
end InvEqInv
variable (A)
@[simp]
theorem inv_zero : (0 : Matrix n n α)⁻¹ = 0 := by
cases' subsingleton_or_nontrivial α with ht ht
· simp [eq_iff_true_of_subsingleton]
rcases (Fintype.card n).zero_le.eq_or_lt with hc | hc
· rw [eq_comm, Fintype.card_eq_zero_iff] at hc
haveI := hc
ext i
exact (IsEmpty.false i).elim
· have hn : Nonempty n := Fintype.card_pos_iff.mp hc
refine nonsing_inv_apply_not_isUnit _ ?_
simp [hn]
noncomputable instance : InvOneClass (Matrix n n α) :=
{ Matrix.one, Matrix.inv with inv_one := inv_eq_left_inv (by simp) }
theorem inv_smul (k : α) [Invertible k] (h : IsUnit A.det) : (k • A)⁻¹ = ⅟ k • A⁻¹ :=
inv_eq_left_inv (by simp [h, smul_smul])
theorem inv_smul' (k : αˣ) (h : IsUnit A.det) : (k • A)⁻¹ = k⁻¹ • A⁻¹ :=
inv_eq_left_inv (by simp [h, smul_smul])
theorem inv_adjugate (A : Matrix n n α) (h : IsUnit A.det) : (adjugate A)⁻¹ = h.unit⁻¹ • A := by
refine inv_eq_left_inv ?_
rw [smul_mul, mul_adjugate, Units.smul_def, smul_smul, h.val_inv_mul, one_smul]
section Diagonal
/-- `diagonal v` is invertible if `v` is -/
def diagonalInvertible {α} [NonAssocSemiring α] (v : n → α) [Invertible v] :
Invertible (diagonal v) :=
Invertible.map (diagonalRingHom n α) v
theorem invOf_diagonal_eq {α} [Semiring α] (v : n → α) [Invertible v] [Invertible (diagonal v)] :
⅟ (diagonal v) = diagonal (⅟ v) := by
letI := diagonalInvertible v
-- Porting note: no longer need `haveI := Invertible.subsingleton (diagonal v)`
convert (rfl : ⅟ (diagonal v) = _)
/-- `v` is invertible if `diagonal v` is -/
def invertibleOfDiagonalInvertible (v : n → α) [Invertible (diagonal v)] : Invertible v where
invOf := diag (⅟ (diagonal v))
invOf_mul_self :=
funext fun i => by
letI : Invertible (diagonal v).det := detInvertibleOfInvertible _
rw [invOf_eq, diag_smul, adjugate_diagonal, diag_diagonal]
dsimp
rw [mul_assoc, prod_erase_mul _ _ (Finset.mem_univ _), ← det_diagonal]
exact mul_invOf_self _
mul_invOf_self :=
funext fun i => by
letI : Invertible (diagonal v).det := detInvertibleOfInvertible _
rw [invOf_eq, diag_smul, adjugate_diagonal, diag_diagonal]
dsimp
rw [mul_left_comm, mul_prod_erase _ _ (Finset.mem_univ _), ← det_diagonal]
exact mul_invOf_self _
/-- Together `Matrix.diagonalInvertible` and `Matrix.invertibleOfDiagonalInvertible` form an
equivalence, although both sides of the equiv are subsingleton anyway. -/
@[simps]
def diagonalInvertibleEquivInvertible (v : n → α) : Invertible (diagonal v) ≃ Invertible v where
toFun := @invertibleOfDiagonalInvertible _ _ _ _ _ _
invFun := @diagonalInvertible _ _ _ _ _ _
left_inv _ := Subsingleton.elim _ _
right_inv _ := Subsingleton.elim _ _
/-- When lowered to a prop, `Matrix.diagonalInvertibleEquivInvertible` forms an `iff`. -/
@[simp]
theorem isUnit_diagonal {v : n → α} : IsUnit (diagonal v) ↔ IsUnit v := by
simp only [← nonempty_invertible_iff_isUnit,
(diagonalInvertibleEquivInvertible v).nonempty_congr]
theorem inv_diagonal (v : n → α) : (diagonal v)⁻¹ = diagonal (Ring.inverse v) := by
rw [nonsing_inv_eq_ring_inverse]
by_cases h : IsUnit v
· have := isUnit_diagonal.mpr h
cases this.nonempty_invertible
cases h.nonempty_invertible
rw [Ring.inverse_invertible, Ring.inverse_invertible, invOf_diagonal_eq]
· have := isUnit_diagonal.not.mpr h
rw [Ring.inverse_non_unit _ h, Pi.zero_def, diagonal_zero, Ring.inverse_non_unit _ this]
end Diagonal
@[simp]
theorem inv_inv_inv (A : Matrix n n α) : A⁻¹⁻¹⁻¹ = A⁻¹ := by
by_cases h : IsUnit A.det
· rw [nonsing_inv_nonsing_inv _ h]
· simp [nonsing_inv_apply_not_isUnit _ h]
/-- The `Matrix` version of `inv_add_inv'` -/
theorem inv_add_inv {A B : Matrix n n α} (h : IsUnit A ↔ IsUnit B) :
A⁻¹ + B⁻¹ = A⁻¹ * (A + B) * B⁻¹ := by
simpa only [nonsing_inv_eq_ring_inverse] using Ring.inverse_add_inverse h
/-- The `Matrix` version of `inv_sub_inv'` -/
theorem inv_sub_inv {A B : Matrix n n α} (h : IsUnit A ↔ IsUnit B) :
A⁻¹ - B⁻¹ = A⁻¹ * (B - A) * B⁻¹ := by
simpa only [nonsing_inv_eq_ring_inverse] using Ring.inverse_sub_inverse h
theorem mul_inv_rev (A B : Matrix n n α) : (A * B)⁻¹ = B⁻¹ * A⁻¹ := by
simp only [inv_def]
rw [Matrix.smul_mul, Matrix.mul_smul, smul_smul, det_mul, adjugate_mul_distrib,
Ring.mul_inverse_rev]
/-- A version of `List.prod_inv_reverse` for `Matrix.inv`. -/
theorem list_prod_inv_reverse : ∀ l : List (Matrix n n α), l.prod⁻¹ = (l.reverse.map Inv.inv).prod
| [] => by rw [List.reverse_nil, List.map_nil, List.prod_nil, inv_one]
| A::Xs => by
rw [List.reverse_cons', List.map_concat, List.prod_concat, List.prod_cons,
mul_inv_rev, list_prod_inv_reverse Xs]
/-- One form of **Cramer's rule**. See `Matrix.mulVec_cramer` for a stronger form. -/
@[simp]
theorem det_smul_inv_mulVec_eq_cramer (A : Matrix n n α) (b : n → α) (h : IsUnit A.det) :
A.det • A⁻¹ *ᵥ b = cramer A b := by
rw [cramer_eq_adjugate_mulVec, A.nonsing_inv_apply h, ← smul_mulVec_assoc, smul_smul,
h.mul_val_inv, one_smul]
/-- One form of **Cramer's rule**. See `Matrix.mulVec_cramer` for a stronger form. -/
@[simp]
theorem det_smul_inv_vecMul_eq_cramer_transpose (A : Matrix n n α) (b : n → α) (h : IsUnit A.det) :
A.det • b ᵥ* A⁻¹ = cramer Aᵀ b := by
rw [← A⁻¹.transpose_transpose, vecMul_transpose, transpose_nonsing_inv, ← det_transpose,
Aᵀ.det_smul_inv_mulVec_eq_cramer _ (isUnit_det_transpose A h)]
/-! ### Inverses of permutated matrices
Note that the simp-normal form of `Matrix.reindex` is `Matrix.submatrix`, so we prove most of these
results about only the latter.
-/
section Submatrix
variable [Fintype m]
variable [DecidableEq m]
/-- `A.submatrix e₁ e₂` is invertible if `A` is -/
def submatrixEquivInvertible (A : Matrix m m α) (e₁ e₂ : n ≃ m) [Invertible A] :
Invertible (A.submatrix e₁ e₂) :=
invertibleOfRightInverse _ ((⅟ A).submatrix e₂ e₁) <| by
rw [Matrix.submatrix_mul_equiv, mul_invOf_self, submatrix_one_equiv]
/-- `A` is invertible if `A.submatrix e₁ e₂` is -/
def invertibleOfSubmatrixEquivInvertible (A : Matrix m m α) (e₁ e₂ : n ≃ m)
[Invertible (A.submatrix e₁ e₂)] : Invertible A :=
invertibleOfRightInverse _ ((⅟ (A.submatrix e₁ e₂)).submatrix e₂.symm e₁.symm) <| by
have : A = (A.submatrix e₁ e₂).submatrix e₁.symm e₂.symm := by simp
-- Porting note: was
-- conv in _ * _ =>
-- congr
-- rw [this]
rw [congr_arg₂ (· * ·) this rfl]
rw [Matrix.submatrix_mul_equiv, mul_invOf_self, submatrix_one_equiv]
theorem invOf_submatrix_equiv_eq (A : Matrix m m α) (e₁ e₂ : n ≃ m) [Invertible A]
[Invertible (A.submatrix e₁ e₂)] : ⅟ (A.submatrix e₁ e₂) = (⅟ A).submatrix e₂ e₁ := by
letI := submatrixEquivInvertible A e₁ e₂
-- Porting note: no longer need `haveI := Invertible.subsingleton (A.submatrix e₁ e₂)`
convert (rfl : ⅟ (A.submatrix e₁ e₂) = _)
/-- Together `Matrix.submatrixEquivInvertible` and
`Matrix.invertibleOfSubmatrixEquivInvertible` form an equivalence, although both sides of the
equiv are subsingleton anyway. -/
@[simps]
def submatrixEquivInvertibleEquivInvertible (A : Matrix m m α) (e₁ e₂ : n ≃ m) :
Invertible (A.submatrix e₁ e₂) ≃ Invertible A where
toFun _ := invertibleOfSubmatrixEquivInvertible A e₁ e₂
invFun _ := submatrixEquivInvertible A e₁ e₂
left_inv _ := Subsingleton.elim _ _
right_inv _ := Subsingleton.elim _ _
/-- When lowered to a prop, `Matrix.invertibleOfSubmatrixEquivInvertible` forms an `iff`. -/
@[simp]
theorem isUnit_submatrix_equiv {A : Matrix m m α} (e₁ e₂ : n ≃ m) :
IsUnit (A.submatrix e₁ e₂) ↔ IsUnit A := by
simp only [← nonempty_invertible_iff_isUnit,
(submatrixEquivInvertibleEquivInvertible A _ _).nonempty_congr]
@[simp]
theorem inv_submatrix_equiv (A : Matrix m m α) (e₁ e₂ : n ≃ m) :
(A.submatrix e₁ e₂)⁻¹ = A⁻¹.submatrix e₂ e₁ := by
by_cases h : IsUnit A
· cases h.nonempty_invertible
letI := submatrixEquivInvertible A e₁ e₂
rw [← invOf_eq_nonsing_inv, ← invOf_eq_nonsing_inv, invOf_submatrix_equiv_eq A]
· have := (isUnit_submatrix_equiv e₁ e₂).not.mpr h
simp_rw [nonsing_inv_eq_ring_inverse, Ring.inverse_non_unit _ h, Ring.inverse_non_unit _ this,
submatrix_zero, Pi.zero_apply]
theorem inv_reindex (e₁ e₂ : n ≃ m) (A : Matrix n n α) : (reindex e₁ e₂ A)⁻¹ = reindex e₂ e₁ A⁻¹ :=
inv_submatrix_equiv A e₁.symm e₂.symm
end Submatrix
/-! ### More results about determinants -/
section Det
variable [Fintype m] [DecidableEq m]
/-- A variant of `Matrix.det_units_conj`. -/
theorem det_conj {M : Matrix m m α} (h : IsUnit M) (N : Matrix m m α) :
det (M * N * M⁻¹) = det N := by rw [← h.unit_spec, ← coe_units_inv, det_units_conj]
/-- A variant of `Matrix.det_units_conj'`. -/
theorem det_conj' {M : Matrix m m α} (h : IsUnit M) (N : Matrix m m α) :
det (M⁻¹ * N * M) = det N := by rw [← h.unit_spec, ← coe_units_inv, det_units_conj']
end Det
end Matrix
|
LinearAlgebra\Matrix\Orthogonal.lean | /-
Copyright (c) 2021 Lu-Ming Zhang. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Lu-Ming Zhang
-/
import Mathlib.Data.Matrix.Basic
/-!
# Orthogonal
This file contains definitions and properties concerning orthogonality of rows and columns.
## Main results
- `matrix.HasOrthogonalRows`:
`A.HasOrthogonalRows` means `A` has orthogonal (with respect to `dotProduct`) rows.
- `matrix.HasOrthogonalCols`:
`A.HasOrthogonalCols` means `A` has orthogonal (with respect to `dotProduct`) columns.
## Tags
orthogonal
-/
namespace Matrix
variable {α n m : Type*}
variable [Mul α] [AddCommMonoid α]
variable (A : Matrix m n α)
open Matrix
/-- `A.HasOrthogonalRows` means matrix `A` has orthogonal rows (with respect to
`Matrix.dotProduct`). -/
def HasOrthogonalRows [Fintype n] : Prop :=
∀ ⦃i₁ i₂⦄, i₁ ≠ i₂ → dotProduct (A i₁) (A i₂) = 0
/-- `A.HasOrthogonalCols` means matrix `A` has orthogonal columns (with respect to
`Matrix.dotProduct`). -/
def HasOrthogonalCols [Fintype m] : Prop :=
HasOrthogonalRows Aᵀ
/-- `Aᵀ` has orthogonal rows iff `A` has orthogonal columns. -/
@[simp]
theorem transpose_hasOrthogonalRows_iff_hasOrthogonalCols [Fintype m] :
Aᵀ.HasOrthogonalRows ↔ A.HasOrthogonalCols :=
Iff.rfl
/-- `Aᵀ` has orthogonal columns iff `A` has orthogonal rows. -/
@[simp]
theorem transpose_hasOrthogonalCols_iff_hasOrthogonalRows [Fintype n] :
Aᵀ.HasOrthogonalCols ↔ A.HasOrthogonalRows :=
Iff.rfl
variable {A}
theorem HasOrthogonalRows.hasOrthogonalCols [Fintype m] (h : Aᵀ.HasOrthogonalRows) :
A.HasOrthogonalCols :=
h
theorem HasOrthogonalCols.transpose_hasOrthogonalRows [Fintype m] (h : A.HasOrthogonalCols) :
Aᵀ.HasOrthogonalRows :=
h
theorem HasOrthogonalCols.hasOrthogonalRows [Fintype n] (h : Aᵀ.HasOrthogonalCols) :
A.HasOrthogonalRows :=
h
theorem HasOrthogonalRows.transpose_hasOrthogonalCols [Fintype n] (h : A.HasOrthogonalRows) :
Aᵀ.HasOrthogonalCols :=
h
end Matrix
|
LinearAlgebra\Matrix\Permutation.lean | /-
Copyright (c) 2020 Anne Baanen. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Anne Baanen
-/
import Mathlib.Data.Matrix.PEquiv
import Mathlib.Data.Set.Card
import Mathlib.LinearAlgebra.Matrix.Determinant.Basic
import Mathlib.LinearAlgebra.Matrix.Trace
/-!
# Permutation matrices
This file defines the matrix associated with a permutation
## Main definitions
- `Equiv.Perm.permMatrix`: the permutation matrix associated with an `Equiv.Perm`
## Main results
- `Matrix.det_permutation`: the determinant is the sign of the permutation
- `Matrix.trace_permutation`: the trace is the number of fixed points of the permutation
-/
open Equiv
variable {n R : Type*} [DecidableEq n] [Fintype n] (σ : Perm n)
variable (R) in
/-- the permutation matrix associated with an `Equiv.Perm` -/
abbrev Equiv.Perm.permMatrix [Zero R] [One R] : Matrix n n R :=
σ.toPEquiv.toMatrix
namespace Matrix
/-- The determinant of a permutation matrix equals its sign. -/
@[simp]
theorem det_permutation [CommRing R] : det (σ.permMatrix R) = Perm.sign σ := by
rw [← Matrix.mul_one (σ.permMatrix R), PEquiv.toPEquiv_mul_matrix,
det_permute, det_one, mul_one]
/-- The trace of a permutation matrix equals the number of fixed points. -/
theorem trace_permutation [AddCommMonoidWithOne R] :
trace (σ.permMatrix R) = (Function.fixedPoints σ).ncard := by
delta trace
simp [toPEquiv_apply, ← Set.ncard_coe_Finset, Function.fixedPoints, Function.IsFixedPt]
end Matrix
|
LinearAlgebra\Matrix\Polynomial.lean | /-
Copyright (c) 2021 Yakov Pechersky. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yakov Pechersky
-/
import Mathlib.Algebra.Polynomial.BigOperators
import Mathlib.Algebra.Polynomial.Degree.Lemmas
import Mathlib.LinearAlgebra.Matrix.Determinant.Basic
import Mathlib.Tactic.ComputeDegree
/-!
# Matrices of polynomials and polynomials of matrices
In this file, we prove results about matrices over a polynomial ring.
In particular, we give results about the polynomial given by
`det (t * I + A)`.
## References
* "The trace Cayley-Hamilton theorem" by Darij Grinberg, Section 5.3
## Tags
matrix determinant, polynomial
-/
open Matrix Polynomial
variable {n α : Type*} [DecidableEq n] [Fintype n] [CommRing α]
open Polynomial Matrix Equiv.Perm
namespace Polynomial
theorem natDegree_det_X_add_C_le (A B : Matrix n n α) :
natDegree (det ((X : α[X]) • A.map C + B.map C : Matrix n n α[X])) ≤ Fintype.card n := by
rw [det_apply]
refine (natDegree_sum_le _ _).trans ?_
refine Multiset.max_le_of_forall_le _ _ ?_
simp only [forall_apply_eq_imp_iff, true_and_iff, Function.comp_apply, Multiset.map_map,
Multiset.mem_map, exists_imp, Finset.mem_univ_val]
intro g
calc
natDegree (sign g • ∏ i : n, (X • A.map C + B.map C : Matrix n n α[X]) (g i) i) ≤
natDegree (∏ i : n, (X • A.map C + B.map C : Matrix n n α[X]) (g i) i) := by
cases' Int.units_eq_one_or (sign g) with sg sg
· rw [sg, one_smul]
· rw [sg, Units.neg_smul, one_smul, natDegree_neg]
_ ≤ ∑ i : n, natDegree (((X : α[X]) • A.map C + B.map C : Matrix n n α[X]) (g i) i) :=
(natDegree_prod_le (Finset.univ : Finset n) fun i : n =>
(X • A.map C + B.map C : Matrix n n α[X]) (g i) i)
_ ≤ Finset.univ.card • 1 := (Finset.sum_le_card_nsmul _ _ 1 fun (i : n) _ => ?_)
_ ≤ Fintype.card n := by simp [mul_one, Algebra.id.smul_eq_mul, Finset.card_univ]
dsimp only [add_apply, smul_apply, map_apply, smul_eq_mul]
compute_degree
theorem coeff_det_X_add_C_zero (A B : Matrix n n α) :
coeff (det ((X : α[X]) • A.map C + B.map C)) 0 = det B := by
rw [det_apply, finset_sum_coeff, det_apply]
refine Finset.sum_congr rfl ?_
rintro g -
convert coeff_smul (R := α) (sign g) _ 0
rw [coeff_zero_prod]
refine Finset.prod_congr rfl ?_
simp
theorem coeff_det_X_add_C_card (A B : Matrix n n α) :
coeff (det ((X : α[X]) • A.map C + B.map C)) (Fintype.card n) = det A := by
rw [det_apply, det_apply, finset_sum_coeff]
refine Finset.sum_congr rfl ?_
simp only [Algebra.id.smul_eq_mul, Finset.mem_univ, RingHom.mapMatrix_apply, forall_true_left,
map_apply, Pi.smul_apply]
intro g
convert coeff_smul (R := α) (sign g) _ _
rw [← mul_one (Fintype.card n)]
convert (coeff_prod_of_natDegree_le (R := α) _ _ _ _).symm
· simp [coeff_C]
· rintro p -
dsimp only [add_apply, smul_apply, map_apply, smul_eq_mul]
compute_degree
theorem leadingCoeff_det_X_one_add_C (A : Matrix n n α) :
leadingCoeff (det ((X : α[X]) • (1 : Matrix n n α[X]) + A.map C)) = 1 := by
cases subsingleton_or_nontrivial α
· simp [eq_iff_true_of_subsingleton]
rw [← @det_one n, ← coeff_det_X_add_C_card _ A, leadingCoeff]
simp only [Matrix.map_one, C_eq_zero, RingHom.map_one]
rcases (natDegree_det_X_add_C_le 1 A).eq_or_lt with h | h
· simp only [RingHom.map_one, Matrix.map_one, C_eq_zero] at h
rw [h]
· -- contradiction. we have a hypothesis that the degree is less than |n|
-- but we know that coeff _ n = 1
have H := coeff_eq_zero_of_natDegree_lt h
rw [coeff_det_X_add_C_card] at H
simp at H
end Polynomial
|
LinearAlgebra\Matrix\PosDef.lean | /-
Copyright (c) 2022 Alexander Bentkamp. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Alexander Bentkamp, Mohanad Ahmed
-/
import Mathlib.LinearAlgebra.Matrix.Spectrum
import Mathlib.LinearAlgebra.QuadraticForm.Basic
/-! # Positive Definite Matrices
This file defines positive (semi)definite matrices and connects the notion to positive definiteness
of quadratic forms. Most results require `𝕜 = ℝ` or `ℂ`.
## Main definitions
* `Matrix.PosDef` : a matrix `M : Matrix n n 𝕜` is positive definite if it is hermitian and `xᴴMx`
is greater than zero for all nonzero `x`.
* `Matrix.PosSemidef` : a matrix `M : Matrix n n 𝕜` is positive semidefinite if it is hermitian
and `xᴴMx` is nonnegative for all `x`.
## Main results
* `Matrix.posSemidef_iff_eq_transpose_mul_self` : a matrix `M : Matrix n n 𝕜` is positive
semidefinite iff it has the form `Bᴴ * B` for some `B`.
* `Matrix.PosSemidef.sqrt` : the unique positive semidefinite square root of a positive semidefinite
matrix. (See `Matrix.PosSemidef.eq_sqrt_of_sq_eq` for the proof of uniqueness.)
-/
open scoped ComplexOrder
namespace Matrix
variable {m n R 𝕜 : Type*}
variable [Fintype m] [Fintype n]
variable [CommRing R] [PartialOrder R] [StarRing R] [StarOrderedRing R]
variable [RCLike 𝕜]
open scoped Matrix
/-!
## Positive semidefinite matrices
-/
/-- A matrix `M : Matrix n n R` is positive semidefinite if it is Hermitian and `xᴴ * M * x` is
nonnegative for all `x`. -/
def PosSemidef (M : Matrix n n R) :=
M.IsHermitian ∧ ∀ x : n → R, 0 ≤ dotProduct (star x) (M *ᵥ x)
/-- A diagonal matrix is positive semidefinite iff its diagonal entries are nonnegative. -/
lemma posSemidef_diagonal_iff [DecidableEq n] {d : n → R} :
PosSemidef (diagonal d) ↔ (∀ i : n, 0 ≤ d i) := by
refine ⟨fun ⟨_, hP⟩ i ↦ by simpa using hP (Pi.single i 1), ?_⟩
refine fun hd ↦ ⟨isHermitian_diagonal_iff.2 fun i ↦ IsSelfAdjoint.of_nonneg (hd i), ?_⟩
refine fun x ↦ Finset.sum_nonneg fun i _ ↦ ?_
simpa only [mulVec_diagonal, mul_assoc] using conjugate_nonneg (hd i) _
namespace PosSemidef
theorem isHermitian {M : Matrix n n R} (hM : M.PosSemidef) : M.IsHermitian :=
hM.1
theorem re_dotProduct_nonneg {M : Matrix n n 𝕜} (hM : M.PosSemidef) (x : n → 𝕜) :
0 ≤ RCLike.re (dotProduct (star x) (M *ᵥ x)) :=
RCLike.nonneg_iff.mp (hM.2 _) |>.1
lemma conjTranspose_mul_mul_same {A : Matrix n n R} (hA : PosSemidef A)
{m : Type*} [Fintype m] (B : Matrix n m R) :
PosSemidef (Bᴴ * A * B) := by
constructor
· exact isHermitian_conjTranspose_mul_mul B hA.1
· intro x
simpa only [star_mulVec, dotProduct_mulVec, vecMul_vecMul] using hA.2 (B *ᵥ x)
lemma mul_mul_conjTranspose_same {A : Matrix n n R} (hA : PosSemidef A)
{m : Type*} [Fintype m] (B : Matrix m n R) :
PosSemidef (B * A * Bᴴ) := by
simpa only [conjTranspose_conjTranspose] using hA.conjTranspose_mul_mul_same Bᴴ
theorem submatrix {M : Matrix n n R} (hM : M.PosSemidef) (e : m → n) :
(M.submatrix e e).PosSemidef := by
classical
rw [(by simp : M = 1 * M * 1), submatrix_mul (he₂ := Function.bijective_id),
submatrix_mul (he₂ := Function.bijective_id), submatrix_id_id]
simpa only [conjTranspose_submatrix, conjTranspose_one] using
conjTranspose_mul_mul_same hM (Matrix.submatrix 1 id e)
theorem transpose {M : Matrix n n R} (hM : M.PosSemidef) : Mᵀ.PosSemidef := by
refine ⟨IsHermitian.transpose hM.1, fun x => ?_⟩
convert hM.2 (star x) using 1
rw [mulVec_transpose, Matrix.dotProduct_mulVec, star_star, dotProduct_comm]
theorem conjTranspose {M : Matrix n n R} (hM : M.PosSemidef) : Mᴴ.PosSemidef := hM.1.symm ▸ hM
protected lemma zero : PosSemidef (0 : Matrix n n R) :=
⟨isHermitian_zero, by simp⟩
protected lemma one [DecidableEq n] : PosSemidef (1 : Matrix n n R) :=
⟨isHermitian_one, fun x => by
rw [one_mulVec]; exact Fintype.sum_nonneg fun i => star_mul_self_nonneg _⟩
protected lemma pow [DecidableEq n] {M : Matrix n n R} (hM : M.PosSemidef) (k : ℕ) :
PosSemidef (M ^ k) :=
match k with
| 0 => .one
| 1 => by simpa using hM
| (k + 2) => by
rw [pow_succ, pow_succ']
simpa only [hM.isHermitian.eq] using (hM.pow k).mul_mul_conjTranspose_same M
protected lemma inv [DecidableEq n] {M : Matrix n n R} (hM : M.PosSemidef) : M⁻¹.PosSemidef := by
by_cases h : IsUnit M.det
· have := (conjTranspose_mul_mul_same hM M⁻¹).conjTranspose
rwa [mul_nonsing_inv_cancel_right _ _ h, conjTranspose_conjTranspose] at this
· rw [nonsing_inv_apply_not_isUnit _ h]
exact .zero
protected lemma zpow [DecidableEq n] {M : Matrix n n R} (hM : M.PosSemidef) (z : ℤ) :
(M ^ z).PosSemidef := by
obtain ⟨n, rfl | rfl⟩ := z.eq_nat_or_neg
· simpa using hM.pow n
· simpa using (hM.pow n).inv
protected lemma add {A : Matrix m m R} {B : Matrix m m R}
(hA : A.PosSemidef) (hB : B.PosSemidef) : (A + B).PosSemidef :=
⟨hA.isHermitian.add hB.isHermitian, fun x => by
rw [add_mulVec, dotProduct_add]
exact add_nonneg (hA.2 x) (hB.2 x)⟩
/-- The eigenvalues of a positive semi-definite matrix are non-negative -/
lemma eigenvalues_nonneg [DecidableEq n] {A : Matrix n n 𝕜}
(hA : Matrix.PosSemidef A) (i : n) : 0 ≤ hA.1.eigenvalues i :=
(hA.re_dotProduct_nonneg _).trans_eq (hA.1.eigenvalues_eq _).symm
section sqrt
variable [DecidableEq n] {A : Matrix n n 𝕜} (hA : PosSemidef A)
/-- The positive semidefinite square root of a positive semidefinite matrix -/
noncomputable def sqrt : Matrix n n 𝕜 :=
hA.1.eigenvectorUnitary.1 * diagonal ((↑) ∘ Real.sqrt ∘ hA.1.eigenvalues) *
(star hA.1.eigenvectorUnitary : Matrix n n 𝕜)
open Lean PrettyPrinter.Delaborator SubExpr in
/-- Custom elaborator to produce output like `(_ : PosSemidef A).sqrt` in the goal view. -/
@[delab app.Matrix.PosSemidef.sqrt]
def delabSqrt : Delab :=
whenPPOption getPPNotation <|
whenNotPPOption getPPAnalysisSkip <|
withOverApp 7 <|
withOptionAtCurrPos `pp.analysis.skip true do
let e ← getExpr
guard <| e.isAppOfArity ``Matrix.PosSemidef.sqrt 7
let optionsPerPos ← withNaryArg 6 do
return (← read).optionsPerPos.setBool (← getPos) `pp.proofs.withType true
withTheReader Context ({· with optionsPerPos}) delab
lemma posSemidef_sqrt : PosSemidef hA.sqrt := by
apply PosSemidef.mul_mul_conjTranspose_same
refine posSemidef_diagonal_iff.mpr fun i ↦ ?_
rw [Function.comp_apply, RCLike.nonneg_iff]
constructor
· simp only [RCLike.ofReal_re]
exact Real.sqrt_nonneg _
· simp only [RCLike.ofReal_im]
@[simp]
lemma sq_sqrt : hA.sqrt ^ 2 = A := by
let C : Matrix n n 𝕜 := hA.1.eigenvectorUnitary
let E := diagonal ((↑) ∘ Real.sqrt ∘ hA.1.eigenvalues : n → 𝕜)
suffices C * (E * (star C * C) * E) * star C = A by
rw [Matrix.PosSemidef.sqrt, pow_two]
simpa only [← mul_assoc] using this
have : E * E = diagonal ((↑) ∘ hA.1.eigenvalues) := by
rw [diagonal_mul_diagonal]
congr! with v
simp [← pow_two, ← RCLike.ofReal_pow, Real.sq_sqrt (hA.eigenvalues_nonneg v)]
simpa [C, this] using hA.1.spectral_theorem.symm
@[simp]
lemma sqrt_mul_self : hA.sqrt * hA.sqrt = A := by rw [← pow_two, sq_sqrt]
lemma eq_of_sq_eq_sq {B : Matrix n n 𝕜} (hB : PosSemidef B) (hAB : A ^ 2 = B ^ 2) : A = B := by
/- This is deceptively hard, much more difficult than the positive *definite* case. We follow a
clever proof due to Koeber and Schäfer. The idea is that if `A ≠ B`, then `A - B` has a nonzero
real eigenvalue, with eigenvector `v`. Then a manipulation using the identity
`A ^ 2 - B ^ 2 = A * (A - B) + (A - B) * B` leads to the conclusion that
`⟨v, A v⟩ + ⟨v, B v⟩ = 0`. Since `A, B` are positive semidefinite, both terms must be zero. Thus
`⟨v, (A - B) v⟩ = 0`, but this is a nonzero scalar multiple of `⟨v, v⟩`, contradiction. -/
by_contra h_ne
let ⟨v, t, ht, hv, hv'⟩ := (hA.1.sub hB.1).exists_eigenvector_of_ne_zero (sub_ne_zero.mpr h_ne)
have h_sum : 0 = t * (star v ⬝ᵥ A *ᵥ v + star v ⬝ᵥ B *ᵥ v) := calc
0 = star v ⬝ᵥ (A ^ 2 - B ^ 2) *ᵥ v := by rw [hAB, sub_self, zero_mulVec, dotProduct_zero]
_ = star v ⬝ᵥ A *ᵥ (A - B) *ᵥ v + star v ⬝ᵥ (A - B) *ᵥ B *ᵥ v := by
rw [mulVec_mulVec, mulVec_mulVec, ← dotProduct_add, ← add_mulVec, mul_sub, sub_mul,
add_sub, sub_add_cancel, pow_two, pow_two]
_ = t * (star v ⬝ᵥ A *ᵥ v) + (star v) ᵥ* (A - B)ᴴ ⬝ᵥ B *ᵥ v := by
rw [hv', mulVec_smul, dotProduct_smul, RCLike.real_smul_eq_coe_mul,
dotProduct_mulVec _ (A - B), hA.1.sub hB.1]
_ = t * (star v ⬝ᵥ A *ᵥ v + star v ⬝ᵥ B *ᵥ v) := by
simp_rw [← star_mulVec, hv', mul_add, ← RCLike.real_smul_eq_coe_mul, ← smul_dotProduct]
congr 2 with i
simp only [Pi.star_apply, Pi.smul_apply, RCLike.real_smul_eq_coe_mul, star_mul',
RCLike.star_def, RCLike.conj_ofReal]
replace h_sum : star v ⬝ᵥ A *ᵥ v + star v ⬝ᵥ B *ᵥ v = 0 := by
rw [eq_comm, ← mul_zero (t : 𝕜)] at h_sum
exact mul_left_cancel₀ (RCLike.ofReal_ne_zero.mpr ht) h_sum
have h_van : star v ⬝ᵥ A *ᵥ v = 0 ∧ star v ⬝ᵥ B *ᵥ v = 0 := by
refine ⟨le_antisymm ?_ (hA.2 v), le_antisymm ?_ (hB.2 v)⟩
· rw [add_comm, add_eq_zero_iff_eq_neg] at h_sum
simpa only [h_sum, neg_nonneg] using hB.2 v
· simpa only [add_eq_zero_iff_eq_neg.mp h_sum, neg_nonneg] using hA.2 v
have aux : star v ⬝ᵥ (A - B) *ᵥ v = 0 := by
rw [sub_mulVec, dotProduct_sub, h_van.1, h_van.2, sub_zero]
rw [hv', dotProduct_smul, RCLike.real_smul_eq_coe_mul, ← mul_zero ↑t] at aux
exact hv <| Matrix.dotProduct_star_self_eq_zero.mp <| mul_left_cancel₀
(RCLike.ofReal_ne_zero.mpr ht) aux
lemma sqrt_sq : (hA.pow 2 : PosSemidef (A ^ 2)).sqrt = A :=
(hA.pow 2).posSemidef_sqrt.eq_of_sq_eq_sq hA (hA.pow 2).sq_sqrt
lemma eq_sqrt_of_sq_eq {B : Matrix n n 𝕜} (hB : PosSemidef B) (hAB : A ^ 2 = B) : A = hB.sqrt := by
subst B
rw [hA.sqrt_sq]
end sqrt
end PosSemidef
@[simp]
theorem posSemidef_submatrix_equiv {M : Matrix n n R} (e : m ≃ n) :
(M.submatrix e e).PosSemidef ↔ M.PosSemidef :=
⟨fun h => by simpa using h.submatrix e.symm, fun h => h.submatrix _⟩
/-- The conjugate transpose of a matrix mulitplied by the matrix is positive semidefinite -/
theorem posSemidef_conjTranspose_mul_self (A : Matrix m n R) : PosSemidef (Aᴴ * A) := by
refine ⟨isHermitian_transpose_mul_self _, fun x => ?_⟩
rw [← mulVec_mulVec, dotProduct_mulVec, vecMul_conjTranspose, star_star]
exact Finset.sum_nonneg fun i _ => star_mul_self_nonneg _
/-- A matrix multiplied by its conjugate transpose is positive semidefinite -/
theorem posSemidef_self_mul_conjTranspose (A : Matrix m n R) : PosSemidef (A * Aᴴ) := by
simpa only [conjTranspose_conjTranspose] using posSemidef_conjTranspose_mul_self Aᴴ
lemma eigenvalues_conjTranspose_mul_self_nonneg (A : Matrix m n 𝕜) [DecidableEq n] (i : n) :
0 ≤ (isHermitian_transpose_mul_self A).eigenvalues i :=
(posSemidef_conjTranspose_mul_self _).eigenvalues_nonneg _
lemma eigenvalues_self_mul_conjTranspose_nonneg (A : Matrix m n 𝕜) [DecidableEq m] (i : m) :
0 ≤ (isHermitian_mul_conjTranspose_self A).eigenvalues i :=
(posSemidef_self_mul_conjTranspose _).eigenvalues_nonneg _
/-- A matrix is positive semidefinite if and only if it has the form `Bᴴ * B` for some `B`. -/
lemma posSemidef_iff_eq_transpose_mul_self {A : Matrix n n 𝕜} :
PosSemidef A ↔ ∃ (B : Matrix n n 𝕜), A = Bᴴ * B := by
classical
refine ⟨fun hA ↦ ⟨hA.sqrt, ?_⟩, fun ⟨B, hB⟩ ↦ (hB ▸ posSemidef_conjTranspose_mul_self B)⟩
simp_rw [← PosSemidef.sq_sqrt hA, pow_two]
rw [hA.posSemidef_sqrt.1]
lemma IsHermitian.posSemidef_of_eigenvalues_nonneg [DecidableEq n] {A : Matrix n n 𝕜}
(hA : IsHermitian A) (h : ∀ i : n, 0 ≤ hA.eigenvalues i) : PosSemidef A := by
rw [hA.spectral_theorem]
refine (posSemidef_diagonal_iff.mpr ?_).mul_mul_conjTranspose_same _
simpa using h
/-- For `A` positive semidefinite, we have `x⋆ A x = 0` iff `A x = 0`. -/
theorem PosSemidef.dotProduct_mulVec_zero_iff
{A : Matrix n n 𝕜} (hA : PosSemidef A) (x : n → 𝕜) :
star x ⬝ᵥ A *ᵥ x = 0 ↔ A *ᵥ x = 0 := by
constructor
· obtain ⟨B, rfl⟩ := posSemidef_iff_eq_transpose_mul_self.mp hA
rw [← Matrix.mulVec_mulVec, dotProduct_mulVec,
vecMul_conjTranspose, star_star, dotProduct_star_self_eq_zero]
intro h0
rw [h0, mulVec_zero]
· intro h0
rw [h0, dotProduct_zero]
/-- For `A` positive semidefinite, we have `x⋆ A x = 0` iff `A x = 0` (linear maps version). -/
theorem PosSemidef.toLinearMap₂'_zero_iff [DecidableEq n]
{A : Matrix n n 𝕜} (hA : PosSemidef A) (x : n → 𝕜) :
Matrix.toLinearMap₂' 𝕜 A (star x) x = 0 ↔ Matrix.toLin' A x = 0 := by
simpa only [toLinearMap₂'_apply', toLin'_apply] using hA.dotProduct_mulVec_zero_iff x
/-!
## Positive definite matrices
-/
/-- A matrix `M : Matrix n n R` is positive definite if it is hermitian
and `xᴴMx` is greater than zero for all nonzero `x`. -/
def PosDef (M : Matrix n n R) :=
M.IsHermitian ∧ ∀ x : n → R, x ≠ 0 → 0 < dotProduct (star x) (M *ᵥ x)
namespace PosDef
theorem isHermitian {M : Matrix n n R} (hM : M.PosDef) : M.IsHermitian :=
hM.1
theorem re_dotProduct_pos {M : Matrix n n 𝕜} (hM : M.PosDef) {x : n → 𝕜} (hx : x ≠ 0) :
0 < RCLike.re (dotProduct (star x) (M *ᵥ x)) :=
RCLike.pos_iff.mp (hM.2 _ hx) |>.1
theorem posSemidef {M : Matrix n n R} (hM : M.PosDef) : M.PosSemidef := by
refine ⟨hM.1, ?_⟩
intro x
by_cases hx : x = 0
· simp only [hx, zero_dotProduct, star_zero, RCLike.zero_re']
exact le_rfl
· exact le_of_lt (hM.2 x hx)
theorem transpose {M : Matrix n n R} (hM : M.PosDef) : Mᵀ.PosDef := by
refine ⟨IsHermitian.transpose hM.1, fun x hx => ?_⟩
convert hM.2 (star x) (star_ne_zero.2 hx) using 1
rw [mulVec_transpose, Matrix.dotProduct_mulVec, star_star, dotProduct_comm]
protected lemma add_posSemidef {A : Matrix m m R} {B : Matrix m m R}
(hA : A.PosDef) (hB : B.PosSemidef) : (A + B).PosDef :=
⟨hA.isHermitian.add hB.isHermitian, fun x hx => by
rw [add_mulVec, dotProduct_add]
exact add_pos_of_pos_of_nonneg (hA.2 x hx) (hB.2 x)⟩
protected lemma posSemidef_add {A : Matrix m m R} {B : Matrix m m R}
(hA : A.PosSemidef) (hB : B.PosDef) : (A + B).PosDef :=
⟨hA.isHermitian.add hB.isHermitian, fun x hx => by
rw [add_mulVec, dotProduct_add]
exact add_pos_of_nonneg_of_pos (hA.2 x) (hB.2 x hx)⟩
protected lemma add {A : Matrix m m R} {B : Matrix m m R}
(hA : A.PosDef) (hB : B.PosDef) : (A + B).PosDef :=
hA.add_posSemidef hB.posSemidef
theorem of_toQuadraticForm' [DecidableEq n] {M : Matrix n n ℝ} (hM : M.IsSymm)
(hMq : M.toQuadraticMap'.PosDef) : M.PosDef := by
refine ⟨hM, fun x hx => ?_⟩
simp only [toQuadraticMap', QuadraticMap.PosDef, LinearMap.BilinMap.toQuadraticMap_apply,
toLinearMap₂'_apply'] at hMq
apply hMq x hx
theorem toQuadraticForm' [DecidableEq n] {M : Matrix n n ℝ} (hM : M.PosDef) :
M.toQuadraticMap'.PosDef := by
intro x hx
simp only [Matrix.toQuadraticMap', LinearMap.BilinMap.toQuadraticMap_apply,
toLinearMap₂'_apply']
apply hM.2 x hx
/-- The eigenvalues of a positive definite matrix are positive -/
lemma eigenvalues_pos [DecidableEq n] {A : Matrix n n 𝕜}
(hA : Matrix.PosDef A) (i : n) : 0 < hA.1.eigenvalues i := by
simp only [hA.1.eigenvalues_eq]
exact hA.re_dotProduct_pos <| hA.1.eigenvectorBasis.orthonormal.ne_zero i
theorem det_pos [DecidableEq n] {M : Matrix n n 𝕜} (hM : M.PosDef) : 0 < det M := by
rw [hM.isHermitian.det_eq_prod_eigenvalues]
apply Finset.prod_pos
intro i _
simpa using hM.eigenvalues_pos i
end PosDef
end Matrix
namespace QuadraticForm
open QuadraticMap
variable {n : Type*} [Fintype n]
theorem posDef_of_toMatrix' [DecidableEq n] {Q : QuadraticForm ℝ (n → ℝ)}
(hQ : Q.toMatrix'.PosDef) : Q.PosDef := by
rw [← toQuadraticMap_associated ℝ Q,
← (LinearMap.toMatrix₂' ℝ).left_inv ((associatedHom (R := ℝ) ℝ) Q)]
exact hQ.toQuadraticForm'
theorem posDef_toMatrix' [DecidableEq n] {Q : QuadraticForm ℝ (n → ℝ)} (hQ : Q.PosDef) :
Q.toMatrix'.PosDef := by
rw [← toQuadraticMap_associated ℝ Q, ←
(LinearMap.toMatrix₂' ℝ).left_inv ((associatedHom (R := ℝ) ℝ) Q)] at hQ
exact .of_toQuadraticForm' (isSymm_toMatrix' Q) hQ
end QuadraticForm
namespace Matrix
variable {𝕜 : Type*} [RCLike 𝕜] {n : Type*} [Fintype n]
/-- A positive definite matrix `M` induces a norm `‖x‖ = sqrt (re xᴴMx)`. -/
noncomputable abbrev NormedAddCommGroup.ofMatrix {M : Matrix n n 𝕜} (hM : M.PosDef) :
NormedAddCommGroup (n → 𝕜) :=
@InnerProductSpace.Core.toNormedAddCommGroup _ _ _ _ _
{ inner := fun x y => dotProduct (star x) (M *ᵥ y)
conj_symm := fun x y => by
dsimp only [Inner.inner]
rw [star_dotProduct, starRingEnd_apply, star_star, star_mulVec, dotProduct_mulVec,
hM.isHermitian.eq]
nonneg_re := fun x => by
by_cases h : x = 0
· simp [h]
· exact le_of_lt (hM.re_dotProduct_pos h)
definite := fun x (hx : dotProduct _ _ = 0) => by
by_contra! h
simpa [hx, lt_irrefl] using hM.re_dotProduct_pos h
add_left := by simp only [star_add, add_dotProduct, eq_self_iff_true, forall_const]
smul_left := fun x y r => by
simp only
rw [← smul_eq_mul, ← smul_dotProduct, starRingEnd_apply, ← star_smul] }
/-- A positive definite matrix `M` induces an inner product `⟪x, y⟫ = xᴴMy`. -/
def InnerProductSpace.ofMatrix {M : Matrix n n 𝕜} (hM : M.PosDef) :
@InnerProductSpace 𝕜 (n → 𝕜) _ (NormedAddCommGroup.ofMatrix hM).toSeminormedAddCommGroup :=
InnerProductSpace.ofCore _
end Matrix
|
LinearAlgebra\Matrix\ProjectiveSpecialLinearGroup.lean | /-
Copyright (c) 2023 Wen Yang. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Wen Yang
-/
import Mathlib.LinearAlgebra.Matrix.SpecialLinearGroup
/-!
# Projective Special Linear Group
## Notation
In the `MatrixGroups` locale:
* `PSL(n, R)` is a shorthand for `Matrix.ProjectiveSpecialLinearGroup (Fin n) R`
-/
namespace Matrix
universe u v
open Matrix LinearMap
open scoped MatrixGroups
variable (n : Type u) [DecidableEq n] [Fintype n] (R : Type v) [CommRing R]
/-- A projective special linear group is the quotient of a special linear group by its center. -/
abbrev ProjectiveSpecialLinearGroup : Type _ :=
SpecialLinearGroup n R ⧸ Subgroup.center (SpecialLinearGroup n R)
/-- `PSL(n, R)` is the projective special linear group `SL(n, R)/Z(SL(n, R))`. -/
scoped[MatrixGroups] notation "PSL(" n ", " R ")" => Matrix.ProjectiveSpecialLinearGroup (Fin n) R
end Matrix
|
LinearAlgebra\Matrix\Reindex.lean | /-
Copyright (c) 2019 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Patrick Massot, Casper Putz, Anne Baanen
-/
import Mathlib.LinearAlgebra.Matrix.Determinant.Basic
/-!
# Changing the index type of a matrix
This file concerns the map `Matrix.reindex`, mapping a `m` by `n` matrix
to an `m'` by `n'` matrix, as long as `m ≃ m'` and `n ≃ n'`.
## Main definitions
* `Matrix.reindexLinearEquiv R A`: `Matrix.reindex` is an `R`-linear equivalence between
`A`-matrices.
* `Matrix.reindexAlgEquiv R`: `Matrix.reindex` is an `R`-algebra equivalence between `R`-matrices.
## Tags
matrix, reindex
-/
namespace Matrix
open Equiv Matrix
variable {l m n o : Type*} {l' m' n' o' : Type*} {m'' n'' : Type*}
variable (R A : Type*)
section AddCommMonoid
variable [Semiring R] [AddCommMonoid A] [Module R A]
/-- The natural map that reindexes a matrix's rows and columns with equivalent types,
`Matrix.reindex`, is a linear equivalence. -/
def reindexLinearEquiv (eₘ : m ≃ m') (eₙ : n ≃ n') : Matrix m n A ≃ₗ[R] Matrix m' n' A :=
{ reindex eₘ eₙ with
map_add' := fun _ _ => rfl
map_smul' := fun _ _ => rfl }
@[simp]
theorem reindexLinearEquiv_apply (eₘ : m ≃ m') (eₙ : n ≃ n') (M : Matrix m n A) :
reindexLinearEquiv R A eₘ eₙ M = reindex eₘ eₙ M :=
rfl
@[simp]
theorem reindexLinearEquiv_symm (eₘ : m ≃ m') (eₙ : n ≃ n') :
(reindexLinearEquiv R A eₘ eₙ).symm = reindexLinearEquiv R A eₘ.symm eₙ.symm :=
rfl
@[simp]
theorem reindexLinearEquiv_refl_refl :
reindexLinearEquiv R A (Equiv.refl m) (Equiv.refl n) = LinearEquiv.refl R _ :=
LinearEquiv.ext fun _ => rfl
theorem reindexLinearEquiv_trans (e₁ : m ≃ m') (e₂ : n ≃ n') (e₁' : m' ≃ m'') (e₂' : n' ≃ n'') :
(reindexLinearEquiv R A e₁ e₂).trans (reindexLinearEquiv R A e₁' e₂') =
(reindexLinearEquiv R A (e₁.trans e₁') (e₂.trans e₂') : _ ≃ₗ[R] _) := by
ext
rfl
theorem reindexLinearEquiv_comp (e₁ : m ≃ m') (e₂ : n ≃ n') (e₁' : m' ≃ m'') (e₂' : n' ≃ n'') :
reindexLinearEquiv R A e₁' e₂' ∘ reindexLinearEquiv R A e₁ e₂ =
reindexLinearEquiv R A (e₁.trans e₁') (e₂.trans e₂') := by
rw [← reindexLinearEquiv_trans]
rfl
theorem reindexLinearEquiv_comp_apply (e₁ : m ≃ m') (e₂ : n ≃ n') (e₁' : m' ≃ m'') (e₂' : n' ≃ n'')
(M : Matrix m n A) :
(reindexLinearEquiv R A e₁' e₂') (reindexLinearEquiv R A e₁ e₂ M) =
reindexLinearEquiv R A (e₁.trans e₁') (e₂.trans e₂') M :=
submatrix_submatrix _ _ _ _ _
theorem reindexLinearEquiv_one [DecidableEq m] [DecidableEq m'] [One A] (e : m ≃ m') :
reindexLinearEquiv R A e e (1 : Matrix m m A) = 1 :=
submatrix_one_equiv e.symm
end AddCommMonoid
section Semiring
variable [Semiring R] [Semiring A] [Module R A]
theorem reindexLinearEquiv_mul [Fintype n] [Fintype n'] (eₘ : m ≃ m') (eₙ : n ≃ n') (eₒ : o ≃ o')
(M : Matrix m n A) (N : Matrix n o A) :
reindexLinearEquiv R A eₘ eₙ M * reindexLinearEquiv R A eₙ eₒ N =
reindexLinearEquiv R A eₘ eₒ (M * N) :=
submatrix_mul_equiv M N _ _ _
theorem mul_reindexLinearEquiv_one [Fintype n] [DecidableEq o] (e₁ : o ≃ n) (e₂ : o ≃ n')
(M : Matrix m n A) :
M * (reindexLinearEquiv R A e₁ e₂ 1) =
reindexLinearEquiv R A (Equiv.refl m) (e₁.symm.trans e₂) M :=
haveI := Fintype.ofEquiv _ e₁.symm
mul_submatrix_one _ _ _
end Semiring
section Algebra
variable [CommSemiring R] [Fintype n] [Fintype m] [DecidableEq m] [DecidableEq n]
[Semiring A] [Algebra R A]
/-- For square matrices with coefficients in an algebra over a commutative semiring, the natural
map that reindexes a matrix's rows and columns with equivalent types,
`Matrix.reindex`, is an equivalence of algebras. -/
def reindexAlgEquiv (e : m ≃ n) : Matrix m m A ≃ₐ[R] Matrix n n A :=
{ reindexLinearEquiv A A e e with
toFun := reindex e e
map_mul' := fun a b => (reindexLinearEquiv_mul A A e e e a b).symm
-- Porting note: `submatrix_smul` needed help
commutes' := fun r => by simp [algebraMap, Algebra.toRingHom, submatrix_smul _ 1] }
@[simp]
theorem reindexAlgEquiv_apply (e : m ≃ n) (M : Matrix m m A) :
reindexAlgEquiv R A e M = reindex e e M :=
rfl
@[simp]
theorem reindexAlgEquiv_symm (e : m ≃ n) : (reindexAlgEquiv R A e).symm =
reindexAlgEquiv R A e.symm :=
rfl
@[simp]
theorem reindexAlgEquiv_refl : reindexAlgEquiv R A (Equiv.refl m) = AlgEquiv.refl :=
AlgEquiv.ext fun _ => rfl
theorem reindexAlgEquiv_mul (e : m ≃ n) (M : Matrix m m A) (N : Matrix m m A) :
reindexAlgEquiv R A e (M * N) = reindexAlgEquiv R A e M * reindexAlgEquiv R A e N :=
_root_.map_mul ..
end Algebra
/-- Reindexing both indices along the same equivalence preserves the determinant.
For the `simp` version of this lemma, see `det_submatrix_equiv_self`.
-/
theorem det_reindexLinearEquiv_self [CommRing R] [Fintype m] [DecidableEq m] [Fintype n]
[DecidableEq n] (e : m ≃ n) (M : Matrix m m R) : det (reindexLinearEquiv R R e e M) = det M :=
det_reindex_self e M
/-- Reindexing both indices along the same equivalence preserves the determinant.
For the `simp` version of this lemma, see `det_submatrix_equiv_self`.
-/
theorem det_reindexAlgEquiv (B : Type*) [CommRing R] [CommRing B] [Algebra R B] [Fintype m]
[DecidableEq m] [Fintype n] [DecidableEq n] (e : m ≃ n) (A : Matrix m m B) :
det (reindexAlgEquiv R B e A) = det A :=
det_reindex_self e A
end Matrix
|
LinearAlgebra\Matrix\SchurComplement.lean | /-
Copyright (c) 2022 Alexander Bentkamp. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Alexander Bentkamp, Eric Wieser, Jeremy Avigad, Johan Commelin
-/
import Mathlib.Data.Matrix.Invertible
import Mathlib.LinearAlgebra.Matrix.NonsingularInverse
import Mathlib.LinearAlgebra.Matrix.PosDef
/-! # 2×2 block matrices and the Schur complement
This file proves properties of 2×2 block matrices `[A B; C D]` that relate to the Schur complement
`D - C*A⁻¹*B`.
Some of the results here generalize to 2×2 matrices in a category, rather than just a ring. A few
results in this direction can be found in the file `CateogryTheory.Preadditive.Biproducts`,
especially the declarations `CategoryTheory.Biprod.gaussian` and `CategoryTheory.Biprod.isoElim`.
Compare with `Matrix.invertibleOfFromBlocks₁₁Invertible`.
## Main results
* `Matrix.det_fromBlocks₁₁`, `Matrix.det_fromBlocks₂₂`: determinant of a block matrix in terms of
the Schur complement.
* `Matrix.invOf_fromBlocks_zero₂₁_eq`, `Matrix.invOf_fromBlocks_zero₁₂_eq`: the inverse of a
block triangular matrix.
* `Matrix.isUnit_fromBlocks_zero₂₁`, `Matrix.isUnit_fromBlocks_zero₁₂`: invertibility of a
block triangular matrix.
* `Matrix.det_one_add_mul_comm`: the **Weinstein–Aronszajn identity**.
* `Matrix.PosSemidef.fromBlocks₁₁` and `Matrix.PosSemidef.fromBlocks₂₂`: If a matrix `A` is
positive definite, then `[A B; Bᴴ D]` is postive semidefinite if and only if `D - Bᴴ A⁻¹ B` is
postive semidefinite.
-/
variable {l m n α : Type*}
namespace Matrix
open scoped Matrix
section CommRing
variable [Fintype l] [Fintype m] [Fintype n]
variable [DecidableEq l] [DecidableEq m] [DecidableEq n]
variable [CommRing α]
/-- LDU decomposition of a block matrix with an invertible top-left corner, using the
Schur complement. -/
theorem fromBlocks_eq_of_invertible₁₁ (A : Matrix m m α) (B : Matrix m n α) (C : Matrix l m α)
(D : Matrix l n α) [Invertible A] :
fromBlocks A B C D =
fromBlocks 1 0 (C * ⅟ A) 1 * fromBlocks A 0 0 (D - C * ⅟ A * B) *
fromBlocks 1 (⅟ A * B) 0 1 := by
simp only [fromBlocks_multiply, Matrix.mul_zero, Matrix.zero_mul, add_zero, zero_add,
Matrix.one_mul, Matrix.mul_one, invOf_mul_self, Matrix.mul_invOf_self_assoc,
Matrix.mul_invOf_mul_self_cancel, Matrix.mul_assoc, add_sub_cancel]
/-- LDU decomposition of a block matrix with an invertible bottom-right corner, using the
Schur complement. -/
theorem fromBlocks_eq_of_invertible₂₂ (A : Matrix l m α) (B : Matrix l n α) (C : Matrix n m α)
(D : Matrix n n α) [Invertible D] :
fromBlocks A B C D =
fromBlocks 1 (B * ⅟ D) 0 1 * fromBlocks (A - B * ⅟ D * C) 0 0 D *
fromBlocks 1 0 (⅟ D * C) 1 :=
(Matrix.reindex (Equiv.sumComm _ _) (Equiv.sumComm _ _)).injective <| by
simpa [reindex_apply, Equiv.sumComm_symm, ← submatrix_mul_equiv _ _ _ (Equiv.sumComm n m), ←
submatrix_mul_equiv _ _ _ (Equiv.sumComm n l), Equiv.sumComm_apply,
fromBlocks_submatrix_sum_swap_sum_swap] using fromBlocks_eq_of_invertible₁₁ D C B A
section Triangular
/-! #### Block triangular matrices -/
/-- An upper-block-triangular matrix is invertible if its diagonal is. -/
def fromBlocksZero₂₁Invertible (A : Matrix m m α) (B : Matrix m n α) (D : Matrix n n α)
[Invertible A] [Invertible D] : Invertible (fromBlocks A B 0 D) :=
invertibleOfLeftInverse _ (fromBlocks (⅟ A) (-(⅟ A * B * ⅟ D)) 0 (⅟ D)) <| by
simp_rw [fromBlocks_multiply, Matrix.mul_zero, Matrix.zero_mul, zero_add, add_zero,
Matrix.neg_mul, invOf_mul_self, Matrix.mul_invOf_mul_self_cancel, add_right_neg,
fromBlocks_one]
/-- A lower-block-triangular matrix is invertible if its diagonal is. -/
def fromBlocksZero₁₂Invertible (A : Matrix m m α) (C : Matrix n m α) (D : Matrix n n α)
[Invertible A] [Invertible D] : Invertible (fromBlocks A 0 C D) :=
invertibleOfLeftInverse _
(fromBlocks (⅟ A) 0 (-(⅟ D * C * ⅟ A))
(⅟ D)) <| by -- a symmetry argument is more work than just copying the proof
simp_rw [fromBlocks_multiply, Matrix.mul_zero, Matrix.zero_mul, zero_add, add_zero,
Matrix.neg_mul, invOf_mul_self, Matrix.mul_invOf_mul_self_cancel, add_left_neg,
fromBlocks_one]
theorem invOf_fromBlocks_zero₂₁_eq (A : Matrix m m α) (B : Matrix m n α) (D : Matrix n n α)
[Invertible A] [Invertible D] [Invertible (fromBlocks A B 0 D)] :
⅟ (fromBlocks A B 0 D) = fromBlocks (⅟ A) (-(⅟ A * B * ⅟ D)) 0 (⅟ D) := by
letI := fromBlocksZero₂₁Invertible A B D
convert (rfl : ⅟ (fromBlocks A B 0 D) = _)
theorem invOf_fromBlocks_zero₁₂_eq (A : Matrix m m α) (C : Matrix n m α) (D : Matrix n n α)
[Invertible A] [Invertible D] [Invertible (fromBlocks A 0 C D)] :
⅟ (fromBlocks A 0 C D) = fromBlocks (⅟ A) 0 (-(⅟ D * C * ⅟ A)) (⅟ D) := by
letI := fromBlocksZero₁₂Invertible A C D
convert (rfl : ⅟ (fromBlocks A 0 C D) = _)
/-- Both diagonal entries of an invertible upper-block-triangular matrix are invertible (by reading
off the diagonal entries of the inverse). -/
def invertibleOfFromBlocksZero₂₁Invertible (A : Matrix m m α) (B : Matrix m n α) (D : Matrix n n α)
[Invertible (fromBlocks A B 0 D)] : Invertible A × Invertible D where
fst :=
invertibleOfLeftInverse _ (⅟ (fromBlocks A B 0 D)).toBlocks₁₁ <| by
have := invOf_mul_self (fromBlocks A B 0 D)
rw [← fromBlocks_toBlocks (⅟ (fromBlocks A B 0 D)), fromBlocks_multiply] at this
replace := congr_arg Matrix.toBlocks₁₁ this
simpa only [Matrix.toBlocks_fromBlocks₁₁, Matrix.mul_zero, add_zero, ← fromBlocks_one] using
this
snd :=
invertibleOfRightInverse _ (⅟ (fromBlocks A B 0 D)).toBlocks₂₂ <| by
have := mul_invOf_self (fromBlocks A B 0 D)
rw [← fromBlocks_toBlocks (⅟ (fromBlocks A B 0 D)), fromBlocks_multiply] at this
replace := congr_arg Matrix.toBlocks₂₂ this
simpa only [Matrix.toBlocks_fromBlocks₂₂, Matrix.zero_mul, zero_add, ← fromBlocks_one] using
this
/-- Both diagonal entries of an invertible lower-block-triangular matrix are invertible (by reading
off the diagonal entries of the inverse). -/
def invertibleOfFromBlocksZero₁₂Invertible (A : Matrix m m α) (C : Matrix n m α) (D : Matrix n n α)
[Invertible (fromBlocks A 0 C D)] : Invertible A × Invertible D where
fst :=
invertibleOfRightInverse _ (⅟ (fromBlocks A 0 C D)).toBlocks₁₁ <| by
have := mul_invOf_self (fromBlocks A 0 C D)
rw [← fromBlocks_toBlocks (⅟ (fromBlocks A 0 C D)), fromBlocks_multiply] at this
replace := congr_arg Matrix.toBlocks₁₁ this
simpa only [Matrix.toBlocks_fromBlocks₁₁, Matrix.zero_mul, add_zero, ← fromBlocks_one] using
this
snd :=
invertibleOfLeftInverse _ (⅟ (fromBlocks A 0 C D)).toBlocks₂₂ <| by
have := invOf_mul_self (fromBlocks A 0 C D)
rw [← fromBlocks_toBlocks (⅟ (fromBlocks A 0 C D)), fromBlocks_multiply] at this
replace := congr_arg Matrix.toBlocks₂₂ this
simpa only [Matrix.toBlocks_fromBlocks₂₂, Matrix.mul_zero, zero_add, ← fromBlocks_one] using
this
/-- `invertibleOfFromBlocksZero₂₁Invertible` and `Matrix.fromBlocksZero₂₁Invertible` form
an equivalence. -/
def fromBlocksZero₂₁InvertibleEquiv (A : Matrix m m α) (B : Matrix m n α) (D : Matrix n n α) :
Invertible (fromBlocks A B 0 D) ≃ Invertible A × Invertible D where
toFun _ := invertibleOfFromBlocksZero₂₁Invertible A B D
invFun i := by
letI := i.1
letI := i.2
exact fromBlocksZero₂₁Invertible A B D
left_inv _ := Subsingleton.elim _ _
right_inv _ := Subsingleton.elim _ _
/-- `invertibleOfFromBlocksZero₁₂Invertible` and `Matrix.fromBlocksZero₁₂Invertible` form
an equivalence. -/
def fromBlocksZero₁₂InvertibleEquiv (A : Matrix m m α) (C : Matrix n m α) (D : Matrix n n α) :
Invertible (fromBlocks A 0 C D) ≃ Invertible A × Invertible D where
toFun _ := invertibleOfFromBlocksZero₁₂Invertible A C D
invFun i := by
letI := i.1
letI := i.2
exact fromBlocksZero₁₂Invertible A C D
left_inv _ := Subsingleton.elim _ _
right_inv _ := Subsingleton.elim _ _
/-- An upper block-triangular matrix is invertible iff both elements of its diagonal are.
This is a propositional form of `Matrix.fromBlocksZero₂₁InvertibleEquiv`. -/
@[simp]
theorem isUnit_fromBlocks_zero₂₁ {A : Matrix m m α} {B : Matrix m n α} {D : Matrix n n α} :
IsUnit (fromBlocks A B 0 D) ↔ IsUnit A ∧ IsUnit D := by
simp only [← nonempty_invertible_iff_isUnit, ← nonempty_prod,
(fromBlocksZero₂₁InvertibleEquiv _ _ _).nonempty_congr]
/-- A lower block-triangular matrix is invertible iff both elements of its diagonal are.
This is a propositional form of `Matrix.fromBlocksZero₁₂InvertibleEquiv` forms an `iff`. -/
@[simp]
theorem isUnit_fromBlocks_zero₁₂ {A : Matrix m m α} {C : Matrix n m α} {D : Matrix n n α} :
IsUnit (fromBlocks A 0 C D) ↔ IsUnit A ∧ IsUnit D := by
simp only [← nonempty_invertible_iff_isUnit, ← nonempty_prod,
(fromBlocksZero₁₂InvertibleEquiv _ _ _).nonempty_congr]
/-- An expression for the inverse of an upper block-triangular matrix, when either both elements of
diagonal are invertible, or both are not. -/
theorem inv_fromBlocks_zero₂₁_of_isUnit_iff (A : Matrix m m α) (B : Matrix m n α) (D : Matrix n n α)
(hAD : IsUnit A ↔ IsUnit D) :
(fromBlocks A B 0 D)⁻¹ = fromBlocks A⁻¹ (-(A⁻¹ * B * D⁻¹)) 0 D⁻¹ := by
by_cases hA : IsUnit A
· have hD := hAD.mp hA
cases hA.nonempty_invertible
cases hD.nonempty_invertible
letI := fromBlocksZero₂₁Invertible A B D
simp_rw [← invOf_eq_nonsing_inv, invOf_fromBlocks_zero₂₁_eq]
· have hD := hAD.not.mp hA
have : ¬IsUnit (fromBlocks A B 0 D) :=
isUnit_fromBlocks_zero₂₁.not.mpr (not_and'.mpr fun _ => hA)
simp_rw [nonsing_inv_eq_ring_inverse, Ring.inverse_non_unit _ hA, Ring.inverse_non_unit _ hD,
Ring.inverse_non_unit _ this, Matrix.zero_mul, neg_zero, fromBlocks_zero]
/-- An expression for the inverse of a lower block-triangular matrix, when either both elements of
diagonal are invertible, or both are not. -/
theorem inv_fromBlocks_zero₁₂_of_isUnit_iff (A : Matrix m m α) (C : Matrix n m α) (D : Matrix n n α)
(hAD : IsUnit A ↔ IsUnit D) :
(fromBlocks A 0 C D)⁻¹ = fromBlocks A⁻¹ 0 (-(D⁻¹ * C * A⁻¹)) D⁻¹ := by
by_cases hA : IsUnit A
· have hD := hAD.mp hA
cases hA.nonempty_invertible
cases hD.nonempty_invertible
letI := fromBlocksZero₁₂Invertible A C D
simp_rw [← invOf_eq_nonsing_inv, invOf_fromBlocks_zero₁₂_eq]
· have hD := hAD.not.mp hA
have : ¬IsUnit (fromBlocks A 0 C D) :=
isUnit_fromBlocks_zero₁₂.not.mpr (not_and'.mpr fun _ => hA)
simp_rw [nonsing_inv_eq_ring_inverse, Ring.inverse_non_unit _ hA, Ring.inverse_non_unit _ hD,
Ring.inverse_non_unit _ this, Matrix.zero_mul, neg_zero, fromBlocks_zero]
end Triangular
/-! ### 2×2 block matrices -/
section Block
/-! #### General 2×2 block matrices-/
/-- A block matrix is invertible if the bottom right corner and the corresponding schur complement
is. -/
def fromBlocks₂₂Invertible (A : Matrix m m α) (B : Matrix m n α) (C : Matrix n m α)
(D : Matrix n n α) [Invertible D] [Invertible (A - B * ⅟ D * C)] :
Invertible (fromBlocks A B C D) := by
-- factor `fromBlocks` via `fromBlocks_eq_of_invertible₂₂`, and state the inverse we expect
convert Invertible.copy' _ _ (fromBlocks (⅟ (A - B * ⅟ D * C)) (-(⅟ (A - B * ⅟ D * C) * B * ⅟ D))
(-(⅟ D * C * ⅟ (A - B * ⅟ D * C))) (⅟ D + ⅟ D * C * ⅟ (A - B * ⅟ D * C) * B * ⅟ D))
(fromBlocks_eq_of_invertible₂₂ _ _ _ _) _
· -- the product is invertible because all the factors are
letI : Invertible (1 : Matrix n n α) := invertibleOne
letI : Invertible (1 : Matrix m m α) := invertibleOne
refine Invertible.mul ?_ (fromBlocksZero₁₂Invertible _ _ _)
exact
Invertible.mul (fromBlocksZero₂₁Invertible _ _ _)
(fromBlocksZero₂₁Invertible _ _ _)
· -- unfold the `Invertible` instances to get the raw factors
show
_ =
fromBlocks 1 0 (-(1 * (⅟ D * C) * 1)) 1 *
(fromBlocks (⅟ (A - B * ⅟ D * C)) (-(⅟ (A - B * ⅟ D * C) * 0 * ⅟ D)) 0 (⅟ D) *
fromBlocks 1 (-(1 * (B * ⅟ D) * 1)) 0 1)
-- combine into a single block matrix
simp only [fromBlocks_multiply, invOf_one, Matrix.one_mul, Matrix.mul_one, Matrix.zero_mul,
Matrix.mul_zero, add_zero, zero_add, neg_zero, Matrix.mul_neg, Matrix.neg_mul, neg_neg, ←
Matrix.mul_assoc, add_comm (⅟D)]
/-- A block matrix is invertible if the top left corner and the corresponding schur complement
is. -/
def fromBlocks₁₁Invertible (A : Matrix m m α) (B : Matrix m n α) (C : Matrix n m α)
(D : Matrix n n α) [Invertible A] [Invertible (D - C * ⅟ A * B)] :
Invertible (fromBlocks A B C D) := by
-- we argue by symmetry
letI := fromBlocks₂₂Invertible D C B A
letI iDCBA :=
submatrixEquivInvertible (fromBlocks D C B A) (Equiv.sumComm _ _) (Equiv.sumComm _ _)
exact
iDCBA.copy' _
(fromBlocks (⅟ A + ⅟ A * B * ⅟ (D - C * ⅟ A * B) * C * ⅟ A) (-(⅟ A * B * ⅟ (D - C * ⅟ A * B)))
(-(⅟ (D - C * ⅟ A * B) * C * ⅟ A)) (⅟ (D - C * ⅟ A * B)))
(fromBlocks_submatrix_sum_swap_sum_swap _ _ _ _).symm
(fromBlocks_submatrix_sum_swap_sum_swap _ _ _ _).symm
theorem invOf_fromBlocks₂₂_eq (A : Matrix m m α) (B : Matrix m n α) (C : Matrix n m α)
(D : Matrix n n α) [Invertible D] [Invertible (A - B * ⅟ D * C)]
[Invertible (fromBlocks A B C D)] :
⅟ (fromBlocks A B C D) =
fromBlocks (⅟ (A - B * ⅟ D * C)) (-(⅟ (A - B * ⅟ D * C) * B * ⅟ D))
(-(⅟ D * C * ⅟ (A - B * ⅟ D * C))) (⅟ D + ⅟ D * C * ⅟ (A - B * ⅟ D * C) * B * ⅟ D) := by
letI := fromBlocks₂₂Invertible A B C D
convert (rfl : ⅟ (fromBlocks A B C D) = _)
theorem invOf_fromBlocks₁₁_eq (A : Matrix m m α) (B : Matrix m n α) (C : Matrix n m α)
(D : Matrix n n α) [Invertible A] [Invertible (D - C * ⅟ A * B)]
[Invertible (fromBlocks A B C D)] :
⅟ (fromBlocks A B C D) =
fromBlocks (⅟ A + ⅟ A * B * ⅟ (D - C * ⅟ A * B) * C * ⅟ A) (-(⅟ A * B * ⅟ (D - C * ⅟ A * B)))
(-(⅟ (D - C * ⅟ A * B) * C * ⅟ A)) (⅟ (D - C * ⅟ A * B)) := by
letI := fromBlocks₁₁Invertible A B C D
convert (rfl : ⅟ (fromBlocks A B C D) = _)
/-- If a block matrix is invertible and so is its bottom left element, then so is the corresponding
Schur complement. -/
def invertibleOfFromBlocks₂₂Invertible (A : Matrix m m α) (B : Matrix m n α) (C : Matrix n m α)
(D : Matrix n n α) [Invertible D] [Invertible (fromBlocks A B C D)] :
Invertible (A - B * ⅟ D * C) := by
suffices Invertible (fromBlocks (A - B * ⅟ D * C) 0 0 D) by
exact (invertibleOfFromBlocksZero₁₂Invertible (A - B * ⅟ D * C) 0 D).1
letI : Invertible (1 : Matrix n n α) := invertibleOne
letI : Invertible (1 : Matrix m m α) := invertibleOne
letI iDC : Invertible (fromBlocks 1 0 (⅟ D * C) 1 : Matrix (m ⊕ n) (m ⊕ n) α) :=
fromBlocksZero₁₂Invertible _ _ _
letI iBD : Invertible (fromBlocks 1 (B * ⅟ D) 0 1 : Matrix (m ⊕ n) (m ⊕ n) α) :=
fromBlocksZero₂₁Invertible _ _ _
letI iBDC := Invertible.copy ‹_› _ (fromBlocks_eq_of_invertible₂₂ A B C D).symm
refine (iBD.mulLeft _).symm ?_
exact (iDC.mulRight _).symm iBDC
/-- If a block matrix is invertible and so is its bottom left element, then so is the corresponding
Schur complement. -/
def invertibleOfFromBlocks₁₁Invertible (A : Matrix m m α) (B : Matrix m n α) (C : Matrix n m α)
(D : Matrix n n α) [Invertible A] [Invertible (fromBlocks A B C D)] :
Invertible (D - C * ⅟ A * B) := by
-- another symmetry argument
letI iABCD' :=
submatrixEquivInvertible (fromBlocks A B C D) (Equiv.sumComm _ _) (Equiv.sumComm _ _)
letI iDCBA := iABCD'.copy _ (fromBlocks_submatrix_sum_swap_sum_swap _ _ _ _).symm
exact invertibleOfFromBlocks₂₂Invertible D C B A
/-- `Matrix.invertibleOfFromBlocks₂₂Invertible` and `Matrix.fromBlocks₂₂Invertible` as an
equivalence. -/
def invertibleEquivFromBlocks₂₂Invertible (A : Matrix m m α) (B : Matrix m n α) (C : Matrix n m α)
(D : Matrix n n α) [Invertible D] :
Invertible (fromBlocks A B C D) ≃ Invertible (A - B * ⅟ D * C) where
toFun _iABCD := invertibleOfFromBlocks₂₂Invertible _ _ _ _
invFun _i_schur := fromBlocks₂₂Invertible _ _ _ _
left_inv _iABCD := Subsingleton.elim _ _
right_inv _i_schur := Subsingleton.elim _ _
/-- `Matrix.invertibleOfFromBlocks₁₁Invertible` and `Matrix.fromBlocks₁₁Invertible` as an
equivalence. -/
def invertibleEquivFromBlocks₁₁Invertible (A : Matrix m m α) (B : Matrix m n α) (C : Matrix n m α)
(D : Matrix n n α) [Invertible A] :
Invertible (fromBlocks A B C D) ≃ Invertible (D - C * ⅟ A * B) where
toFun _iABCD := invertibleOfFromBlocks₁₁Invertible _ _ _ _
invFun _i_schur := fromBlocks₁₁Invertible _ _ _ _
left_inv _iABCD := Subsingleton.elim _ _
right_inv _i_schur := Subsingleton.elim _ _
/-- If the bottom-left element of a block matrix is invertible, then the whole matrix is invertible
iff the corresponding schur complement is. -/
theorem isUnit_fromBlocks_iff_of_invertible₂₂ {A : Matrix m m α} {B : Matrix m n α}
{C : Matrix n m α} {D : Matrix n n α} [Invertible D] :
IsUnit (fromBlocks A B C D) ↔ IsUnit (A - B * ⅟ D * C) := by
simp only [← nonempty_invertible_iff_isUnit,
(invertibleEquivFromBlocks₂₂Invertible A B C D).nonempty_congr]
/-- If the top-right element of a block matrix is invertible, then the whole matrix is invertible
iff the corresponding schur complement is. -/
theorem isUnit_fromBlocks_iff_of_invertible₁₁ {A : Matrix m m α} {B : Matrix m n α}
{C : Matrix n m α} {D : Matrix n n α} [Invertible A] :
IsUnit (fromBlocks A B C D) ↔ IsUnit (D - C * ⅟ A * B) := by
simp only [← nonempty_invertible_iff_isUnit,
(invertibleEquivFromBlocks₁₁Invertible A B C D).nonempty_congr]
end Block
/-! ### Lemmas about `Matrix.det` -/
section Det
/-- Determinant of a 2×2 block matrix, expanded around an invertible top left element in terms of
the Schur complement. -/
theorem det_fromBlocks₁₁ (A : Matrix m m α) (B : Matrix m n α) (C : Matrix n m α)
(D : Matrix n n α) [Invertible A] :
(Matrix.fromBlocks A B C D).det = det A * det (D - C * ⅟ A * B) := by
rw [fromBlocks_eq_of_invertible₁₁ (A := A), det_mul, det_mul, det_fromBlocks_zero₂₁,
det_fromBlocks_zero₂₁, det_fromBlocks_zero₁₂, det_one, det_one, one_mul, one_mul, mul_one]
@[simp]
theorem det_fromBlocks_one₁₁ (B : Matrix m n α) (C : Matrix n m α) (D : Matrix n n α) :
(Matrix.fromBlocks 1 B C D).det = det (D - C * B) := by
haveI : Invertible (1 : Matrix m m α) := invertibleOne
rw [det_fromBlocks₁₁, invOf_one, Matrix.mul_one, det_one, one_mul]
/-- Determinant of a 2×2 block matrix, expanded around an invertible bottom right element in terms
of the Schur complement. -/
theorem det_fromBlocks₂₂ (A : Matrix m m α) (B : Matrix m n α) (C : Matrix n m α)
(D : Matrix n n α) [Invertible D] :
(Matrix.fromBlocks A B C D).det = det D * det (A - B * ⅟ D * C) := by
have : fromBlocks A B C D =
(fromBlocks D C B A).submatrix (Equiv.sumComm _ _) (Equiv.sumComm _ _) := by
ext (i j)
cases i <;> cases j <;> rfl
rw [this, det_submatrix_equiv_self, det_fromBlocks₁₁]
@[simp]
theorem det_fromBlocks_one₂₂ (A : Matrix m m α) (B : Matrix m n α) (C : Matrix n m α) :
(Matrix.fromBlocks A B C 1).det = det (A - B * C) := by
haveI : Invertible (1 : Matrix n n α) := invertibleOne
rw [det_fromBlocks₂₂, invOf_one, Matrix.mul_one, det_one, one_mul]
/-- The **Weinstein–Aronszajn identity**. Note the `1` on the LHS is of shape m×m, while the `1` on
the RHS is of shape n×n. -/
theorem det_one_add_mul_comm (A : Matrix m n α) (B : Matrix n m α) :
det (1 + A * B) = det (1 + B * A) :=
calc
det (1 + A * B) = det (fromBlocks 1 (-A) B 1) := by
rw [det_fromBlocks_one₂₂, Matrix.neg_mul, sub_neg_eq_add]
_ = det (1 + B * A) := by rw [det_fromBlocks_one₁₁, Matrix.mul_neg, sub_neg_eq_add]
/-- Alternate statement of the **Weinstein–Aronszajn identity** -/
theorem det_mul_add_one_comm (A : Matrix m n α) (B : Matrix n m α) :
det (A * B + 1) = det (B * A + 1) := by rw [add_comm, det_one_add_mul_comm, add_comm]
theorem det_one_sub_mul_comm (A : Matrix m n α) (B : Matrix n m α) :
det (1 - A * B) = det (1 - B * A) := by
rw [sub_eq_add_neg, ← Matrix.neg_mul, det_one_add_mul_comm, Matrix.mul_neg, ← sub_eq_add_neg]
/-- A special case of the **Matrix determinant lemma** for when `A = I`. -/
theorem det_one_add_col_mul_row {ι : Type*} [Unique ι] (u v : m → α) :
det (1 + col ι u * row ι v) = 1 + v ⬝ᵥ u := by
rw [det_one_add_mul_comm, det_unique, Pi.add_apply, Pi.add_apply, Matrix.one_apply_eq,
Matrix.row_mul_col_apply]
/-- The **Matrix determinant lemma**
TODO: show the more general version without `hA : IsUnit A.det` as
`(A + col u * row v).det = A.det + v ⬝ᵥ (adjugate A) *ᵥ u`.
-/
theorem det_add_col_mul_row {ι : Type*} [Unique ι]
{A : Matrix m m α} (hA : IsUnit A.det) (u v : m → α) :
(A + col ι u * row ι v).det = A.det * (1 + row ι v * A⁻¹ * col ι u).det := by
nth_rewrite 1 [← Matrix.mul_one A]
rwa [← Matrix.mul_nonsing_inv_cancel_left A (col ι u * row ι v),
← Matrix.mul_add, det_mul, ← Matrix.mul_assoc, det_one_add_mul_comm,
← Matrix.mul_assoc]
/-- A generalization of the **Matrix determinant lemma** -/
theorem det_add_mul {A : Matrix m m α} (U : Matrix m n α)
(V : Matrix n m α) (hA : IsUnit A.det) :
(A + U * V).det = A.det * (1 + V * A⁻¹ * U).det := by
nth_rewrite 1 [← Matrix.mul_one A]
rwa [← Matrix.mul_nonsing_inv_cancel_left A (U * V), ← Matrix.mul_add,
det_mul, ← Matrix.mul_assoc, det_one_add_mul_comm, ← Matrix.mul_assoc]
end Det
end CommRing
/-! ### Lemmas about `ℝ` and `ℂ` and other `StarOrderedRing`s -/
section StarOrderedRing
variable {𝕜 : Type*} [CommRing 𝕜] [PartialOrder 𝕜] [StarRing 𝕜] [StarOrderedRing 𝕜]
scoped infixl:65 " ⊕ᵥ " => Sum.elim
theorem schur_complement_eq₁₁ [Fintype m] [DecidableEq m] [Fintype n] {A : Matrix m m 𝕜}
(B : Matrix m n 𝕜) (D : Matrix n n 𝕜) (x : m → 𝕜) (y : n → 𝕜) [Invertible A]
(hA : A.IsHermitian) :
(star (x ⊕ᵥ y)) ᵥ* (fromBlocks A B Bᴴ D) ⬝ᵥ (x ⊕ᵥ y) =
(star (x + (A⁻¹ * B) *ᵥ y)) ᵥ* A ⬝ᵥ (x + (A⁻¹ * B) *ᵥ y) +
(star y) ᵥ* (D - Bᴴ * A⁻¹ * B) ⬝ᵥ y := by
simp [Function.star_sum_elim, fromBlocks_mulVec, vecMul_fromBlocks, add_vecMul,
dotProduct_mulVec, vecMul_sub, Matrix.mul_assoc, vecMul_mulVec, hA.eq,
conjTranspose_nonsing_inv, star_mulVec]
abel
theorem schur_complement_eq₂₂ [Fintype m] [Fintype n] [DecidableEq n] (A : Matrix m m 𝕜)
(B : Matrix m n 𝕜) {D : Matrix n n 𝕜} (x : m → 𝕜) (y : n → 𝕜) [Invertible D]
(hD : D.IsHermitian) :
(star (x ⊕ᵥ y)) ᵥ* (fromBlocks A B Bᴴ D) ⬝ᵥ (x ⊕ᵥ y) =
(star ((D⁻¹ * Bᴴ) *ᵥ x + y)) ᵥ* D ⬝ᵥ ((D⁻¹ * Bᴴ) *ᵥ x + y) +
(star x) ᵥ* (A - B * D⁻¹ * Bᴴ) ⬝ᵥ x := by
simp [Function.star_sum_elim, fromBlocks_mulVec, vecMul_fromBlocks, add_vecMul,
dotProduct_mulVec, vecMul_sub, Matrix.mul_assoc, vecMul_mulVec, hD.eq,
conjTranspose_nonsing_inv, star_mulVec]
abel
theorem IsHermitian.fromBlocks₁₁ [Fintype m] [DecidableEq m] {A : Matrix m m 𝕜} (B : Matrix m n 𝕜)
(D : Matrix n n 𝕜) (hA : A.IsHermitian) :
(Matrix.fromBlocks A B Bᴴ D).IsHermitian ↔ (D - Bᴴ * A⁻¹ * B).IsHermitian := by
have hBAB : (Bᴴ * A⁻¹ * B).IsHermitian := by
apply isHermitian_conjTranspose_mul_mul
apply hA.inv
rw [isHermitian_fromBlocks_iff]
constructor
· intro h
apply IsHermitian.sub h.2.2.2 hBAB
· intro h
refine ⟨hA, rfl, conjTranspose_conjTranspose B, ?_⟩
rw [← sub_add_cancel D]
apply IsHermitian.add h hBAB
theorem IsHermitian.fromBlocks₂₂ [Fintype n] [DecidableEq n] (A : Matrix m m 𝕜) (B : Matrix m n 𝕜)
{D : Matrix n n 𝕜} (hD : D.IsHermitian) :
(Matrix.fromBlocks A B Bᴴ D).IsHermitian ↔ (A - B * D⁻¹ * Bᴴ).IsHermitian := by
rw [← isHermitian_submatrix_equiv (Equiv.sumComm n m), Equiv.sumComm_apply,
fromBlocks_submatrix_sum_swap_sum_swap]
convert IsHermitian.fromBlocks₁₁ _ _ hD <;> simp
theorem PosSemidef.fromBlocks₁₁ [Fintype m] [DecidableEq m] [Fintype n] {A : Matrix m m 𝕜}
(B : Matrix m n 𝕜) (D : Matrix n n 𝕜) (hA : A.PosDef) [Invertible A] :
(fromBlocks A B Bᴴ D).PosSemidef ↔ (D - Bᴴ * A⁻¹ * B).PosSemidef := by
rw [PosSemidef, IsHermitian.fromBlocks₁₁ _ _ hA.1]
constructor
· refine fun h => ⟨h.1, fun x => ?_⟩
have := h.2 (-((A⁻¹ * B) *ᵥ x) ⊕ᵥ x)
rw [dotProduct_mulVec, schur_complement_eq₁₁ B D _ _ hA.1, neg_add_self, dotProduct_zero,
zero_add] at this
rw [dotProduct_mulVec]; exact this
· refine fun h => ⟨h.1, fun x => ?_⟩
rw [dotProduct_mulVec, ← Sum.elim_comp_inl_inr x, schur_complement_eq₁₁ B D _ _ hA.1]
apply le_add_of_nonneg_of_le
· rw [← dotProduct_mulVec]
apply hA.posSemidef.2
· rw [← dotProduct_mulVec (star (x ∘ Sum.inr))]
apply h.2
theorem PosSemidef.fromBlocks₂₂ [Fintype m] [Fintype n] [DecidableEq n] (A : Matrix m m 𝕜)
(B : Matrix m n 𝕜) {D : Matrix n n 𝕜} (hD : D.PosDef) [Invertible D] :
(fromBlocks A B Bᴴ D).PosSemidef ↔ (A - B * D⁻¹ * Bᴴ).PosSemidef := by
rw [← posSemidef_submatrix_equiv (Equiv.sumComm n m), Equiv.sumComm_apply,
fromBlocks_submatrix_sum_swap_sum_swap]
convert PosSemidef.fromBlocks₁₁ Bᴴ A hD <;>
simp
end StarOrderedRing
end Matrix
|
LinearAlgebra\Matrix\SesquilinearForm.lean | /-
Copyright (c) 2020 Anne Baanen. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Anne Baanen, Kexing Ying, Moritz Doll
-/
import Mathlib.Algebra.GroupWithZero.Action.Opposite
import Mathlib.LinearAlgebra.FinsuppVectorSpace
import Mathlib.LinearAlgebra.Matrix.Basis
import Mathlib.LinearAlgebra.Matrix.Nondegenerate
import Mathlib.LinearAlgebra.Matrix.NonsingularInverse
import Mathlib.LinearAlgebra.Matrix.ToLinearEquiv
import Mathlib.LinearAlgebra.SesquilinearForm
import Mathlib.LinearAlgebra.Basis.Bilinear
/-!
# Sesquilinear form
This file defines the conversion between sesquilinear maps and matrices.
## Main definitions
* `Matrix.toLinearMap₂` given a basis define a bilinear map
* `Matrix.toLinearMap₂'` define the bilinear map on `n → R`
* `LinearMap.toMatrix₂`: calculate the matrix coefficients of a bilinear map
* `LinearMap.toMatrix₂'`: calculate the matrix coefficients of a bilinear map on `n → R`
## TODO
At the moment this is quite a literal port from `Matrix.BilinearForm`. Everything should be
generalized to fully semibilinear forms.
## Tags
Sesquilinear form, Sesquilinear map, matrix, basis
-/
variable {R R₁ S₁ R₂ S₂ M M₁ M₂ M₁' M₂' N₂ n m n' m' ι : Type*}
open Finset LinearMap Matrix
open Matrix
open scoped RightActions
section AuxToLinearMap
variable [Semiring R₁] [Semiring S₁] [Semiring R₂] [Semiring S₂] [AddCommMonoid N₂]
[Module S₁ N₂] [Module S₂ N₂] [SMulCommClass S₂ S₁ N₂]
variable [Fintype n] [Fintype m]
variable (σ₁ : R₁ →+* S₁) (σ₂ : R₂ →+* S₂)
/-- The map from `Matrix n n R` to bilinear maps on `n → R`.
This is an auxiliary definition for the equivalence `Matrix.toLinearMap₂'`. -/
def Matrix.toLinearMap₂'Aux (f : Matrix n m N₂) : (n → R₁) →ₛₗ[σ₁] (m → R₂) →ₛₗ[σ₂] N₂ :=
-- porting note: we don't seem to have `∑ i j` as valid notation yet
mk₂'ₛₗ σ₁ σ₂ (fun (v : n → R₁) (w : m → R₂) => ∑ i, ∑ j, σ₂ (w j) • σ₁ (v i) • f i j)
(fun _ _ _ => by simp only [Pi.add_apply, map_add, smul_add, sum_add_distrib, add_smul])
(fun c v w => by
simp only [Pi.smul_apply, smul_sum, smul_eq_mul, σ₁.map_mul, ← smul_comm _ (σ₁ c),
MulAction.mul_smul])
(fun _ _ _ => by simp only [Pi.add_apply, map_add, add_smul, smul_add, sum_add_distrib])
(fun _ v w => by
simp only [Pi.smul_apply, smul_eq_mul, _root_.map_mul, MulAction.mul_smul, smul_sum])
variable [DecidableEq n] [DecidableEq m]
theorem Matrix.toLinearMap₂'Aux_stdBasis (f : Matrix n m N₂) (i : n) (j : m) :
f.toLinearMap₂'Aux σ₁ σ₂ (LinearMap.stdBasis R₁ (fun _ => R₁) i 1)
(LinearMap.stdBasis R₂ (fun _ => R₂) j 1) = f i j := by
rw [Matrix.toLinearMap₂'Aux, mk₂'ₛₗ_apply]
have : (∑ i', ∑ j', (if i = i' then (1 : S₁) else (0 : S₁)) •
(if j = j' then (1 : S₂) else (0 : S₂)) • f i' j') =
f i j := by
simp_rw [← Finset.smul_sum]
simp only [op_smul_eq_smul, ite_smul, one_smul, zero_smul, sum_ite_eq, mem_univ, ↓reduceIte]
rw [← this]
exact Finset.sum_congr rfl fun _ _ => Finset.sum_congr rfl fun _ _ => by aesop
end AuxToLinearMap
section AuxToMatrix
section CommSemiring
variable [CommSemiring R] [Semiring R₁] [Semiring S₁] [Semiring R₂] [Semiring S₂]
variable [AddCommMonoid M₁] [Module R₁ M₁] [AddCommMonoid M₂] [Module R₂ M₂] [AddCommMonoid N₂]
[Module R N₂] [Module S₁ N₂] [Module S₂ N₂] [SMulCommClass S₁ R N₂] [SMulCommClass S₂ R N₂]
[SMulCommClass S₂ S₁ N₂]
variable {σ₁ : R₁ →+* S₁} {σ₂ : R₂ →+* S₂}
variable (R)
/-- The linear map from sesquilinear maps to `Matrix n m N₂` given an `n`-indexed basis for `M₁`
and an `m`-indexed basis for `M₂`.
This is an auxiliary definition for the equivalence `Matrix.toLinearMapₛₗ₂'`. -/
def LinearMap.toMatrix₂Aux (b₁ : n → M₁) (b₂ : m → M₂) :
(M₁ →ₛₗ[σ₁] M₂ →ₛₗ[σ₂] N₂) →ₗ[R] Matrix n m N₂ where
toFun f := of fun i j => f (b₁ i) (b₂ j)
map_add' _f _g := rfl
map_smul' _f _g := rfl
@[simp]
theorem LinearMap.toMatrix₂Aux_apply (f : M₁ →ₛₗ[σ₁] M₂ →ₛₗ[σ₂] N₂) (b₁ : n → M₁) (b₂ : m → M₂)
(i : n) (j : m) : LinearMap.toMatrix₂Aux R b₁ b₂ f i j = f (b₁ i) (b₂ j) :=
rfl
variable [Fintype n] [Fintype m]
variable [DecidableEq n] [DecidableEq m]
theorem LinearMap.toLinearMap₂'Aux_toMatrix₂Aux (f : (n → R₁) →ₛₗ[σ₁] (m → R₂) →ₛₗ[σ₂] N₂) :
Matrix.toLinearMap₂'Aux σ₁ σ₂
(LinearMap.toMatrix₂Aux R (fun i => stdBasis R₁ (fun _ => R₁) i 1)
(fun j => stdBasis R₂ (fun _ => R₂) j 1) f) =
f := by
refine ext_basis (Pi.basisFun R₁ n) (Pi.basisFun R₂ m) fun i j => ?_
simp_rw [Pi.basisFun_apply, Matrix.toLinearMap₂'Aux_stdBasis, LinearMap.toMatrix₂Aux_apply]
theorem Matrix.toMatrix₂Aux_toLinearMap₂'Aux (f : Matrix n m N₂) :
LinearMap.toMatrix₂Aux R (fun i => LinearMap.stdBasis R₁ (fun _ => R₁) i 1)
(fun j => LinearMap.stdBasis R₂ (fun _ => R₂) j 1) (f.toLinearMap₂'Aux σ₁ σ₂) =
f := by
ext i j
simp_rw [LinearMap.toMatrix₂Aux_apply, Matrix.toLinearMap₂'Aux_stdBasis]
end CommSemiring
end AuxToMatrix
section ToMatrix'
/-! ### Bilinear maps over `n → R`
This section deals with the conversion between matrices and sesquilinear maps on `n → R`.
-/
variable [CommSemiring R] [AddCommMonoid N₂] [Module R N₂] [Semiring R₁] [Semiring R₂]
[Semiring S₁] [Semiring S₂] [Module S₁ N₂] [Module S₂ N₂]
[SMulCommClass S₁ R N₂] [SMulCommClass S₂ R N₂] [SMulCommClass S₂ S₁ N₂]
variable {σ₁ : R₁ →+* S₁} {σ₂ : R₂ →+* S₂}
variable [Fintype n] [Fintype m]
variable [DecidableEq n] [DecidableEq m]
variable (R)
/-- The linear equivalence between sesquilinear maps and `n × m` matrices -/
def LinearMap.toMatrixₛₗ₂' : ((n → R₁) →ₛₗ[σ₁] (m → R₂) →ₛₗ[σ₂] N₂) ≃ₗ[R] Matrix n m N₂ :=
{ LinearMap.toMatrix₂Aux R (fun i => stdBasis R₁ (fun _ => R₁) i 1) fun j =>
stdBasis R₂ (fun _ => R₂) j
1 with
toFun := LinearMap.toMatrix₂Aux R _ _
invFun := Matrix.toLinearMap₂'Aux σ₁ σ₂
left_inv := LinearMap.toLinearMap₂'Aux_toMatrix₂Aux R
right_inv := Matrix.toMatrix₂Aux_toLinearMap₂'Aux R }
/-- The linear equivalence between bilinear maps and `n × m` matrices -/
def LinearMap.toMatrix₂' : ((n → S₁) →ₗ[S₁] (m → S₂) →ₗ[S₂] N₂) ≃ₗ[R] Matrix n m N₂ :=
LinearMap.toMatrixₛₗ₂' R
variable (σ₁ σ₂)
/-- The linear equivalence between `n × n` matrices and sesquilinear maps on `n → R` -/
def Matrix.toLinearMapₛₗ₂' : Matrix n m N₂ ≃ₗ[R] (n → R₁) →ₛₗ[σ₁] (m → R₂) →ₛₗ[σ₂] N₂ :=
(LinearMap.toMatrixₛₗ₂' R).symm
/-- The linear equivalence between `n × n` matrices and bilinear maps on `n → R` -/
def Matrix.toLinearMap₂' : Matrix n m N₂ ≃ₗ[R] (n → S₁) →ₗ[S₁] (m → S₂) →ₗ[S₂] N₂ :=
(LinearMap.toMatrix₂' R).symm
variable {R}
theorem Matrix.toLinearMapₛₗ₂'_aux_eq (M : Matrix n m N₂) :
Matrix.toLinearMap₂'Aux σ₁ σ₂ M = Matrix.toLinearMapₛₗ₂' R σ₁ σ₂ M :=
rfl
theorem Matrix.toLinearMapₛₗ₂'_apply (M : Matrix n m N₂) (x : n → R₁) (y : m → R₂) :
-- porting note: we don't seem to have `∑ i j` as valid notation yet
Matrix.toLinearMapₛₗ₂' R σ₁ σ₂ M x y = ∑ i, ∑ j, σ₁ (x i) • σ₂ (y j) • M i j := by
rw [toLinearMapₛₗ₂', toMatrixₛₗ₂', LinearEquiv.coe_symm_mk, toLinearMap₂'Aux, mk₂'ₛₗ_apply]
apply Finset.sum_congr rfl fun _ _ => Finset.sum_congr rfl fun _ _ => by
rw [smul_comm]
theorem Matrix.toLinearMap₂'_apply (M : Matrix n m N₂) (x : n → S₁) (y : m → S₂) :
-- porting note: we don't seem to have `∑ i j` as valid notation yet
Matrix.toLinearMap₂' R M x y = ∑ i, ∑ j, x i • y j • M i j :=
Finset.sum_congr rfl fun _ _ => Finset.sum_congr rfl fun _ _ => by
rw [RingHom.id_apply, RingHom.id_apply, smul_comm]
theorem Matrix.toLinearMap₂'_apply' {T : Type*} [CommSemiring T] (M : Matrix n m T) (v : n → T)
(w : m → T) : Matrix.toLinearMap₂' T M v w = Matrix.dotProduct v (M *ᵥ w) := by
simp_rw [Matrix.toLinearMap₂'_apply, Matrix.dotProduct, Matrix.mulVec, Matrix.dotProduct]
refine Finset.sum_congr rfl fun _ _ => ?_
rw [Finset.mul_sum]
refine Finset.sum_congr rfl fun _ _ => ?_
rw [smul_eq_mul, smul_eq_mul, mul_comm (w _), ← mul_assoc]
@[simp]
theorem Matrix.toLinearMapₛₗ₂'_stdBasis (M : Matrix n m N₂) (i : n) (j : m) :
Matrix.toLinearMapₛₗ₂' R σ₁ σ₂ M (LinearMap.stdBasis R₁ (fun _ => R₁) i 1)
(LinearMap.stdBasis R₂ (fun _ => R₂) j 1) = M i j :=
Matrix.toLinearMap₂'Aux_stdBasis σ₁ σ₂ M i j
@[simp]
theorem Matrix.toLinearMap₂'_stdBasis (M : Matrix n m N₂) (i : n) (j : m) :
Matrix.toLinearMap₂' R M (LinearMap.stdBasis R (fun _ => R) i 1)
(LinearMap.stdBasis R (fun _ => R) j 1) = M i j :=
Matrix.toLinearMap₂'Aux_stdBasis _ _ M i j
@[simp]
theorem LinearMap.toMatrixₛₗ₂'_symm :
((LinearMap.toMatrixₛₗ₂' R).symm : Matrix n m N₂ ≃ₗ[R] _) = Matrix.toLinearMapₛₗ₂' R σ₁ σ₂ :=
rfl
@[simp]
theorem Matrix.toLinearMapₛₗ₂'_symm :
((Matrix.toLinearMapₛₗ₂' R σ₁ σ₂).symm : _ ≃ₗ[R] Matrix n m N₂) = LinearMap.toMatrixₛₗ₂' R :=
(LinearMap.toMatrixₛₗ₂' R).symm_symm
@[simp]
theorem Matrix.toLinearMapₛₗ₂'_toMatrix' (B : (n → R₁) →ₛₗ[σ₁] (m → R₂) →ₛₗ[σ₂] N₂) :
Matrix.toLinearMapₛₗ₂' R σ₁ σ₂ (LinearMap.toMatrixₛₗ₂' R B) = B :=
(Matrix.toLinearMapₛₗ₂' R σ₁ σ₂).apply_symm_apply B
@[simp]
theorem Matrix.toLinearMap₂'_toMatrix' (B : (n → S₁) →ₗ[S₁] (m → S₂) →ₗ[S₂] N₂) :
Matrix.toLinearMap₂' R (LinearMap.toMatrix₂' R B) = B :=
(Matrix.toLinearMap₂' R).apply_symm_apply B
@[simp]
theorem LinearMap.toMatrix'_toLinearMapₛₗ₂' (M : Matrix n m N₂) :
LinearMap.toMatrixₛₗ₂' R (Matrix.toLinearMapₛₗ₂' R σ₁ σ₂ M) = M :=
(LinearMap.toMatrixₛₗ₂' R).apply_symm_apply M
@[simp]
theorem LinearMap.toMatrix'_toLinearMap₂' (M : Matrix n m N₂) :
LinearMap.toMatrix₂' R (Matrix.toLinearMap₂' R (S₁ := S₁) (S₂ := S₂) M) = M :=
(LinearMap.toMatrixₛₗ₂' R).apply_symm_apply M
@[simp]
theorem LinearMap.toMatrixₛₗ₂'_apply (B : (n → R₁) →ₛₗ[σ₁] (m → R₂) →ₛₗ[σ₂] N₂) (i : n) (j : m) :
LinearMap.toMatrixₛₗ₂' R B i j =
B (stdBasis R₁ (fun _ => R₁) i 1) (stdBasis R₂ (fun _ => R₂) j 1) :=
rfl
@[simp]
theorem LinearMap.toMatrix₂'_apply (B : (n → S₁) →ₗ[S₁] (m → S₂) →ₗ[S₂] N₂) (i : n) (j : m) :
LinearMap.toMatrix₂' R B i j =
B (stdBasis S₁ (fun _ => S₁) i 1) (stdBasis S₂ (fun _ => S₂) j 1) :=
rfl
end ToMatrix'
section CommToMatrix'
-- TODO: Introduce matrix multiplication by matrices of scalars
variable {R : Type*} [CommSemiring R]
variable [Fintype n] [Fintype m]
variable [DecidableEq n] [DecidableEq m]
variable [Fintype n'] [Fintype m']
variable [DecidableEq n'] [DecidableEq m']
@[simp]
theorem LinearMap.toMatrix₂'_compl₁₂ (B : (n → R) →ₗ[R] (m → R) →ₗ[R] R) (l : (n' → R) →ₗ[R] n → R)
(r : (m' → R) →ₗ[R] m → R) :
toMatrix₂' R (B.compl₁₂ l r) = (toMatrix' l)ᵀ * toMatrix₂' R B * toMatrix' r := by
ext i j
simp only [LinearMap.toMatrix₂'_apply, LinearMap.compl₁₂_apply, transpose_apply, Matrix.mul_apply,
LinearMap.toMatrix', LinearEquiv.coe_mk, sum_mul]
rw [sum_comm]
conv_lhs => rw [← LinearMap.sum_repr_mul_repr_mul (Pi.basisFun R n) (Pi.basisFun R m) (l _) (r _)]
rw [Finsupp.sum_fintype]
· apply sum_congr rfl
rintro i' -
rw [Finsupp.sum_fintype]
· apply sum_congr rfl
rintro j' -
simp only [smul_eq_mul, Pi.basisFun_repr, mul_assoc, mul_comm, mul_left_comm,
Pi.basisFun_apply, of_apply]
· intros
simp only [zero_smul, smul_zero]
· intros
simp only [zero_smul, Finsupp.sum_zero]
theorem LinearMap.toMatrix₂'_comp (B : (n → R) →ₗ[R] (m → R) →ₗ[R] R) (f : (n' → R) →ₗ[R] n → R) :
toMatrix₂' R (B.comp f) = (toMatrix' f)ᵀ * toMatrix₂' R B := by
rw [← LinearMap.compl₂_id (B.comp f), ← LinearMap.compl₁₂]
simp
theorem LinearMap.toMatrix₂'_compl₂ (B : (n → R) →ₗ[R] (m → R) →ₗ[R] R) (f : (m' → R) →ₗ[R] m → R) :
toMatrix₂' R (B.compl₂ f) = toMatrix₂' R B * toMatrix' f := by
rw [← LinearMap.comp_id B, ← LinearMap.compl₁₂]
simp
theorem LinearMap.mul_toMatrix₂'_mul (B : (n → R) →ₗ[R] (m → R) →ₗ[R] R) (M : Matrix n' n R)
(N : Matrix m m' R) :
M * toMatrix₂' R B * N = toMatrix₂' R (B.compl₁₂ (toLin' Mᵀ) (toLin' N)) := by
simp
theorem LinearMap.mul_toMatrix' (B : (n → R) →ₗ[R] (m → R) →ₗ[R] R) (M : Matrix n' n R) :
M * toMatrix₂' R B = toMatrix₂' R (B.comp <| toLin' Mᵀ) := by
simp only [B.toMatrix₂'_comp, transpose_transpose, toMatrix'_toLin']
theorem LinearMap.toMatrix₂'_mul (B : (n → R) →ₗ[R] (m → R) →ₗ[R] R) (M : Matrix m m' R) :
toMatrix₂' R B * M = toMatrix₂' R (B.compl₂ <| toLin' M) := by
simp only [B.toMatrix₂'_compl₂, toMatrix'_toLin']
theorem Matrix.toLinearMap₂'_comp (M : Matrix n m R) (P : Matrix n n' R) (Q : Matrix m m' R) :
LinearMap.compl₁₂ (Matrix.toLinearMap₂' R M) (toLin' P) (toLin' Q) =
toLinearMap₂' R (Pᵀ * M * Q) :=
(LinearMap.toMatrix₂' R).injective (by simp)
end CommToMatrix'
section ToMatrix
/-! ### Bilinear maps over arbitrary vector spaces
This section deals with the conversion between matrices and bilinear maps on
a module with a fixed basis.
-/
variable [CommSemiring R]
variable [AddCommMonoid M₁] [Module R M₁] [AddCommMonoid M₂] [Module R M₂] [AddCommMonoid N₂]
[Module R N₂]
variable [DecidableEq n] [Fintype n]
variable [DecidableEq m] [Fintype m]
section
variable (b₁ : Basis n R M₁) (b₂ : Basis m R M₂)
/-- `LinearMap.toMatrix₂ b₁ b₂` is the equivalence between `R`-bilinear maps on `M` and
`n`-by-`m` matrices with entries in `R`, if `b₁` and `b₂` are `R`-bases for `M₁` and `M₂`,
respectively. -/
noncomputable def LinearMap.toMatrix₂ : (M₁ →ₗ[R] M₂ →ₗ[R] N₂) ≃ₗ[R] Matrix n m N₂ :=
(b₁.equivFun.arrowCongr (b₂.equivFun.arrowCongr (LinearEquiv.refl R N₂))).trans
(LinearMap.toMatrix₂' R)
/-- `Matrix.toLinearMap₂ b₁ b₂` is the equivalence between `R`-bilinear maps on `M` and
`n`-by-`m` matrices with entries in `R`, if `b₁` and `b₂` are `R`-bases for `M₁` and `M₂`,
respectively; this is the reverse direction of `LinearMap.toMatrix₂ b₁ b₂`. -/
noncomputable def Matrix.toLinearMap₂ : Matrix n m N₂ ≃ₗ[R] M₁ →ₗ[R] M₂ →ₗ[R] N₂ :=
(LinearMap.toMatrix₂ b₁ b₂).symm
-- We make this and not `LinearMap.toMatrix₂` a `simp` lemma to avoid timeouts
@[simp]
theorem LinearMap.toMatrix₂_apply (B : M₁ →ₗ[R] M₂ →ₗ[R] N₂) (i : n) (j : m) :
LinearMap.toMatrix₂ b₁ b₂ B i j = B (b₁ i) (b₂ j) := by
simp only [toMatrix₂, LinearEquiv.trans_apply, toMatrix₂'_apply, LinearEquiv.arrowCongr_apply,
Basis.equivFun_symm_apply, stdBasis_apply', ite_smul, one_smul, zero_smul, sum_ite_eq, mem_univ,
↓reduceIte, LinearEquiv.refl_apply]
@[simp]
theorem Matrix.toLinearMap₂_apply (M : Matrix n m N₂) (x : M₁) (y : M₂) :
Matrix.toLinearMap₂ b₁ b₂ M x y = ∑ i, ∑ j, b₁.repr x i • b₂.repr y j • M i j :=
Finset.sum_congr rfl fun _ _ => Finset.sum_congr rfl fun _ _ =>
smul_algebra_smul_comm ((RingHom.id R) ((Basis.equivFun b₁) x _))
((RingHom.id R) ((Basis.equivFun b₂) y _)) (M _ _)
-- Not a `simp` lemma since `LinearMap.toMatrix₂` needs an extra argument
theorem LinearMap.toMatrix₂Aux_eq (B : M₁ →ₗ[R] M₂ →ₗ[R] N₂) :
LinearMap.toMatrix₂Aux R b₁ b₂ B = LinearMap.toMatrix₂ b₁ b₂ B :=
Matrix.ext fun i j => by rw [LinearMap.toMatrix₂_apply, LinearMap.toMatrix₂Aux_apply]
@[simp]
theorem LinearMap.toMatrix₂_symm :
(LinearMap.toMatrix₂ b₁ b₂).symm = Matrix.toLinearMap₂ (N₂ := N₂) b₁ b₂ :=
rfl
@[simp]
theorem Matrix.toLinearMap₂_symm :
(Matrix.toLinearMap₂ b₁ b₂).symm = LinearMap.toMatrix₂ (N₂ := N₂) b₁ b₂ :=
(LinearMap.toMatrix₂ b₁ b₂).symm_symm
theorem Matrix.toLinearMap₂_basisFun :
Matrix.toLinearMap₂ (Pi.basisFun R n) (Pi.basisFun R m) =
Matrix.toLinearMap₂' R (N₂ := N₂) := by
ext M
simp only [coe_comp, coe_single, Function.comp_apply, toLinearMap₂_apply, Pi.basisFun_repr,
toLinearMap₂'_apply]
theorem LinearMap.toMatrix₂_basisFun :
LinearMap.toMatrix₂ (Pi.basisFun R n) (Pi.basisFun R m) =
LinearMap.toMatrix₂' R (N₂ := N₂) := by
ext B
rw [LinearMap.toMatrix₂_apply, LinearMap.toMatrix₂'_apply, Pi.basisFun_apply, Pi.basisFun_apply]
@[simp]
theorem Matrix.toLinearMap₂_toMatrix₂ (B : M₁ →ₗ[R] M₂ →ₗ[R] N₂) :
Matrix.toLinearMap₂ b₁ b₂ (LinearMap.toMatrix₂ b₁ b₂ B) = B :=
(Matrix.toLinearMap₂ b₁ b₂).apply_symm_apply B
@[simp]
theorem LinearMap.toMatrix₂_toLinearMap₂ (M : Matrix n m N₂) :
LinearMap.toMatrix₂ b₁ b₂ (Matrix.toLinearMap₂ b₁ b₂ M) = M :=
(LinearMap.toMatrix₂ b₁ b₂).apply_symm_apply M
variable (b₁ : Basis n R M₁) (b₂ : Basis m R M₂)
variable [AddCommMonoid M₁'] [Module R M₁']
variable [AddCommMonoid M₂'] [Module R M₂']
variable (b₁' : Basis n' R M₁')
variable (b₂' : Basis m' R M₂')
variable [Fintype n'] [Fintype m']
variable [DecidableEq n'] [DecidableEq m']
-- Cannot be a `simp` lemma because `b₁` and `b₂` must be inferred.
theorem LinearMap.toMatrix₂_compl₁₂ (B : M₁ →ₗ[R] M₂ →ₗ[R] R) (l : M₁' →ₗ[R] M₁)
(r : M₂' →ₗ[R] M₂) :
LinearMap.toMatrix₂ b₁' b₂' (B.compl₁₂ l r) =
(toMatrix b₁' b₁ l)ᵀ * LinearMap.toMatrix₂ b₁ b₂ B * toMatrix b₂' b₂ r := by
ext i j
simp only [LinearMap.toMatrix₂_apply, compl₁₂_apply, transpose_apply, Matrix.mul_apply,
LinearMap.toMatrix_apply, LinearEquiv.coe_mk, sum_mul]
rw [sum_comm]
conv_lhs => rw [← LinearMap.sum_repr_mul_repr_mul b₁ b₂]
rw [Finsupp.sum_fintype]
· apply sum_congr rfl
rintro i' -
rw [Finsupp.sum_fintype]
· apply sum_congr rfl
rintro j' -
simp only [smul_eq_mul, LinearMap.toMatrix_apply, Basis.equivFun_apply, mul_assoc, mul_comm,
mul_left_comm]
· intros
simp only [zero_smul, smul_zero]
· intros
simp only [zero_smul, Finsupp.sum_zero]
theorem LinearMap.toMatrix₂_comp (B : M₁ →ₗ[R] M₂ →ₗ[R] R) (f : M₁' →ₗ[R] M₁) :
LinearMap.toMatrix₂ b₁' b₂ (B.comp f) =
(toMatrix b₁' b₁ f)ᵀ * LinearMap.toMatrix₂ b₁ b₂ B := by
rw [← LinearMap.compl₂_id (B.comp f), ← LinearMap.compl₁₂, LinearMap.toMatrix₂_compl₁₂ b₁ b₂]
simp
theorem LinearMap.toMatrix₂_compl₂ (B : M₁ →ₗ[R] M₂ →ₗ[R] R) (f : M₂' →ₗ[R] M₂) :
LinearMap.toMatrix₂ b₁ b₂' (B.compl₂ f) =
LinearMap.toMatrix₂ b₁ b₂ B * toMatrix b₂' b₂ f := by
rw [← LinearMap.comp_id B, ← LinearMap.compl₁₂, LinearMap.toMatrix₂_compl₁₂ b₁ b₂]
simp
@[simp]
theorem LinearMap.toMatrix₂_mul_basis_toMatrix (c₁ : Basis n' R M₁) (c₂ : Basis m' R M₂)
(B : M₁ →ₗ[R] M₂ →ₗ[R] R) :
(b₁.toMatrix c₁)ᵀ * LinearMap.toMatrix₂ b₁ b₂ B * b₂.toMatrix c₂ =
LinearMap.toMatrix₂ c₁ c₂ B := by
simp_rw [← LinearMap.toMatrix_id_eq_basis_toMatrix]
rw [← LinearMap.toMatrix₂_compl₁₂, LinearMap.compl₁₂_id_id]
theorem LinearMap.mul_toMatrix₂_mul (B : M₁ →ₗ[R] M₂ →ₗ[R] R) (M : Matrix n' n R)
(N : Matrix m m' R) :
M * LinearMap.toMatrix₂ b₁ b₂ B * N =
LinearMap.toMatrix₂ b₁' b₂' (B.compl₁₂ (toLin b₁' b₁ Mᵀ) (toLin b₂' b₂ N)) := by
simp_rw [LinearMap.toMatrix₂_compl₁₂ b₁ b₂, toMatrix_toLin, transpose_transpose]
theorem LinearMap.mul_toMatrix₂ (B : M₁ →ₗ[R] M₂ →ₗ[R] R) (M : Matrix n' n R) :
M * LinearMap.toMatrix₂ b₁ b₂ B =
LinearMap.toMatrix₂ b₁' b₂ (B.comp (toLin b₁' b₁ Mᵀ)) := by
rw [LinearMap.toMatrix₂_comp b₁, toMatrix_toLin, transpose_transpose]
theorem LinearMap.toMatrix₂_mul (B : M₁ →ₗ[R] M₂ →ₗ[R] R) (M : Matrix m m' R) :
LinearMap.toMatrix₂ b₁ b₂ B * M =
LinearMap.toMatrix₂ b₁ b₂' (B.compl₂ (toLin b₂' b₂ M)) := by
rw [LinearMap.toMatrix₂_compl₂ b₁ b₂, toMatrix_toLin]
theorem Matrix.toLinearMap₂_compl₁₂ (M : Matrix n m R) (P : Matrix n n' R) (Q : Matrix m m' R) :
(Matrix.toLinearMap₂ b₁ b₂ M).compl₁₂ (toLin b₁' b₁ P) (toLin b₂' b₂ Q) =
Matrix.toLinearMap₂ b₁' b₂' (Pᵀ * M * Q) :=
(LinearMap.toMatrix₂ b₁' b₂').injective
(by
simp only [LinearMap.toMatrix₂_compl₁₂ b₁ b₂, LinearMap.toMatrix₂_toLinearMap₂,
toMatrix_toLin])
end
end ToMatrix
/-! ### Adjoint pairs-/
section MatrixAdjoints
open Matrix
variable [CommRing R]
variable [AddCommMonoid M₁] [Module R M₁] [AddCommMonoid M₂] [Module R M₂]
variable [Fintype n] [Fintype n']
variable (b₁ : Basis n R M₁) (b₂ : Basis n' R M₂)
variable (J J₂ : Matrix n n R) (J' : Matrix n' n' R)
variable (A : Matrix n' n R) (A' : Matrix n n' R)
variable (A₁ A₂ : Matrix n n R)
/-- The condition for the matrices `A`, `A'` to be an adjoint pair with respect to the square
matrices `J`, `J₃`. -/
def Matrix.IsAdjointPair :=
Aᵀ * J' = J * A'
/-- The condition for a square matrix `A` to be self-adjoint with respect to the square matrix
`J`. -/
def Matrix.IsSelfAdjoint :=
Matrix.IsAdjointPair J J A₁ A₁
/-- The condition for a square matrix `A` to be skew-adjoint with respect to the square matrix
`J`. -/
def Matrix.IsSkewAdjoint :=
Matrix.IsAdjointPair J J A₁ (-A₁)
variable [DecidableEq n] [DecidableEq n']
@[simp]
theorem isAdjointPair_toLinearMap₂' :
LinearMap.IsAdjointPair (Matrix.toLinearMap₂' R J) (Matrix.toLinearMap₂' R J')
(Matrix.toLin' A) (Matrix.toLin' A') ↔
Matrix.IsAdjointPair J J' A A' := by
rw [isAdjointPair_iff_comp_eq_compl₂]
have h :
∀ B B' : (n → R) →ₗ[R] (n' → R) →ₗ[R] R,
B = B' ↔ LinearMap.toMatrix₂' R B = LinearMap.toMatrix₂' R B' := by
intro B B'
constructor <;> intro h
· rw [h]
· exact (LinearMap.toMatrix₂' R).injective h
simp_rw [h, LinearMap.toMatrix₂'_comp, LinearMap.toMatrix₂'_compl₂,
LinearMap.toMatrix'_toLin', LinearMap.toMatrix'_toLinearMap₂']
rfl
@[simp]
theorem isAdjointPair_toLinearMap₂ :
LinearMap.IsAdjointPair (Matrix.toLinearMap₂ b₁ b₁ J)
(Matrix.toLinearMap₂ b₂ b₂ J') (Matrix.toLin b₁ b₂ A) (Matrix.toLin b₂ b₁ A') ↔
Matrix.IsAdjointPair J J' A A' := by
rw [isAdjointPair_iff_comp_eq_compl₂]
have h :
∀ B B' : M₁ →ₗ[R] M₂ →ₗ[R] R,
B = B' ↔ LinearMap.toMatrix₂ b₁ b₂ B = LinearMap.toMatrix₂ b₁ b₂ B' := by
intro B B'
constructor <;> intro h
· rw [h]
· exact (LinearMap.toMatrix₂ b₁ b₂).injective h
simp_rw [h, LinearMap.toMatrix₂_comp b₂ b₂, LinearMap.toMatrix₂_compl₂ b₁ b₁,
LinearMap.toMatrix_toLin, LinearMap.toMatrix₂_toLinearMap₂]
rfl
theorem Matrix.isAdjointPair_equiv (P : Matrix n n R) (h : IsUnit P) :
(Pᵀ * J * P).IsAdjointPair (Pᵀ * J * P) A₁ A₂ ↔
J.IsAdjointPair J (P * A₁ * P⁻¹) (P * A₂ * P⁻¹) := by
have h' : IsUnit P.det := P.isUnit_iff_isUnit_det.mp h
let u := P.nonsingInvUnit h'
let v := Pᵀ.nonsingInvUnit (P.isUnit_det_transpose h')
let x := A₁ᵀ * Pᵀ * J
let y := J * P * A₂
-- TODO(mathlib4#6607): fix elaboration so `val` isn't needed
suffices x * u.val = v.val * y ↔ (v⁻¹).val * x = y * (u⁻¹).val by
dsimp only [Matrix.IsAdjointPair]
simp only [Matrix.transpose_mul]
simp only [← mul_assoc, P.transpose_nonsing_inv]
-- Porting note: the previous proof used `conv` and was causing timeouts, so we use `convert`
convert this using 2
· rw [mul_assoc, mul_assoc, ← mul_assoc J]
rfl
· rw [mul_assoc, mul_assoc, ← mul_assoc _ _ J]
rfl
rw [Units.eq_mul_inv_iff_mul_eq]
conv_rhs => rw [mul_assoc]
rw [v.inv_mul_eq_iff_eq_mul]
/-- The submodule of pair-self-adjoint matrices with respect to bilinear forms corresponding to
given matrices `J`, `J₂`. -/
def pairSelfAdjointMatricesSubmodule : Submodule R (Matrix n n R) :=
(isPairSelfAdjointSubmodule (Matrix.toLinearMap₂' R J)
(Matrix.toLinearMap₂' R J₂)).map
((LinearMap.toMatrix' : ((n → R) →ₗ[R] n → R) ≃ₗ[R] Matrix n n R) :
((n → R) →ₗ[R] n → R) →ₗ[R] Matrix n n R)
@[simp]
theorem mem_pairSelfAdjointMatricesSubmodule :
A₁ ∈ pairSelfAdjointMatricesSubmodule J J₂ ↔ Matrix.IsAdjointPair J J₂ A₁ A₁ := by
simp only [pairSelfAdjointMatricesSubmodule, LinearEquiv.coe_coe, LinearMap.toMatrix'_apply,
Submodule.mem_map, mem_isPairSelfAdjointSubmodule]
constructor
· rintro ⟨f, hf, hA⟩
have hf' : f = toLin' A₁ := by rw [← hA, Matrix.toLin'_toMatrix']
rw [hf'] at hf
rw [← isAdjointPair_toLinearMap₂']
exact hf
· intro h
refine ⟨toLin' A₁, ?_, LinearMap.toMatrix'_toLin' _⟩
exact (isAdjointPair_toLinearMap₂' _ _ _ _).mpr h
/-- The submodule of self-adjoint matrices with respect to the bilinear form corresponding to
the matrix `J`. -/
def selfAdjointMatricesSubmodule : Submodule R (Matrix n n R) :=
pairSelfAdjointMatricesSubmodule J J
@[simp]
theorem mem_selfAdjointMatricesSubmodule :
A₁ ∈ selfAdjointMatricesSubmodule J ↔ J.IsSelfAdjoint A₁ := by
erw [mem_pairSelfAdjointMatricesSubmodule]
rfl
/-- The submodule of skew-adjoint matrices with respect to the bilinear form corresponding to
the matrix `J`. -/
def skewAdjointMatricesSubmodule : Submodule R (Matrix n n R) :=
pairSelfAdjointMatricesSubmodule (-J) J
@[simp]
theorem mem_skewAdjointMatricesSubmodule :
A₁ ∈ skewAdjointMatricesSubmodule J ↔ J.IsSkewAdjoint A₁ := by
erw [mem_pairSelfAdjointMatricesSubmodule]
simp [Matrix.IsSkewAdjoint, Matrix.IsAdjointPair]
end MatrixAdjoints
namespace LinearMap
/-! ### Nondegenerate bilinear forms-/
section Det
open Matrix
variable [CommRing R₁] [AddCommMonoid M₁] [Module R₁ M₁]
variable [DecidableEq ι] [Fintype ι]
theorem _root_.Matrix.separatingLeft_toLinearMap₂'_iff_separatingLeft_toLinearMap₂
{M : Matrix ι ι R₁} (b : Basis ι R₁ M₁) :
(Matrix.toLinearMap₂' R₁ M).SeparatingLeft (R := R₁) ↔
(Matrix.toLinearMap₂ b b M).SeparatingLeft :=
(separatingLeft_congr_iff b.equivFun.symm b.equivFun.symm).symm
variable (B : M₁ →ₗ[R₁] M₁ →ₗ[R₁] R₁)
-- Lemmas transferring nondegeneracy between a matrix and its associated bilinear form
theorem _root_.Matrix.Nondegenerate.toLinearMap₂' {M : Matrix ι ι R₁} (h : M.Nondegenerate) :
(Matrix.toLinearMap₂' R₁ M).SeparatingLeft (R := R₁) := fun x hx =>
h.eq_zero_of_ortho fun y => by simpa only [toLinearMap₂'_apply'] using hx y
@[simp]
theorem _root_.Matrix.separatingLeft_toLinearMap₂'_iff {M : Matrix ι ι R₁} :
(Matrix.toLinearMap₂' R₁ M).SeparatingLeft (R := R₁) ↔ M.Nondegenerate :=
⟨fun h v hv => h v fun w => (M.toLinearMap₂'_apply' _ _).trans <| hv w,
Matrix.Nondegenerate.toLinearMap₂'⟩
theorem _root_.Matrix.Nondegenerate.toLinearMap₂ {M : Matrix ι ι R₁} (h : M.Nondegenerate)
(b : Basis ι R₁ M₁) : (toLinearMap₂ b b M).SeparatingLeft :=
(Matrix.separatingLeft_toLinearMap₂'_iff_separatingLeft_toLinearMap₂ b).mp h.toLinearMap₂'
@[simp]
theorem _root_.Matrix.separatingLeft_toLinearMap₂_iff {M : Matrix ι ι R₁} (b : Basis ι R₁ M₁) :
(toLinearMap₂ b b M).SeparatingLeft ↔ M.Nondegenerate := by
rw [← Matrix.separatingLeft_toLinearMap₂'_iff_separatingLeft_toLinearMap₂,
Matrix.separatingLeft_toLinearMap₂'_iff]
-- Lemmas transferring nondegeneracy between a bilinear form and its associated matrix
@[simp]
theorem nondegenerate_toMatrix₂'_iff {B : (ι → R₁) →ₗ[R₁] (ι → R₁) →ₗ[R₁] R₁} :
(LinearMap.toMatrix₂' R₁ B).Nondegenerate ↔ B.SeparatingLeft :=
Matrix.separatingLeft_toLinearMap₂'_iff.symm.trans <|
(Matrix.toLinearMap₂'_toMatrix' (R := R₁) B).symm ▸ Iff.rfl
theorem SeparatingLeft.toMatrix₂' {B : (ι → R₁) →ₗ[R₁] (ι → R₁) →ₗ[R₁] R₁} (h : B.SeparatingLeft) :
(LinearMap.toMatrix₂' R₁ B).Nondegenerate :=
nondegenerate_toMatrix₂'_iff.mpr h
@[simp]
theorem nondegenerate_toMatrix_iff {B : M₁ →ₗ[R₁] M₁ →ₗ[R₁] R₁} (b : Basis ι R₁ M₁) :
(toMatrix₂ b b B).Nondegenerate ↔ B.SeparatingLeft :=
(Matrix.separatingLeft_toLinearMap₂_iff b).symm.trans <|
(Matrix.toLinearMap₂_toMatrix₂ b b B).symm ▸ Iff.rfl
theorem SeparatingLeft.toMatrix₂ {B : M₁ →ₗ[R₁] M₁ →ₗ[R₁] R₁} (h : B.SeparatingLeft)
(b : Basis ι R₁ M₁) : (toMatrix₂ b b B).Nondegenerate :=
(nondegenerate_toMatrix_iff b).mpr h
-- Some shorthands for combining the above with `Matrix.nondegenerate_of_det_ne_zero`
variable [IsDomain R₁]
theorem separatingLeft_toLinearMap₂'_iff_det_ne_zero {M : Matrix ι ι R₁} :
(Matrix.toLinearMap₂' R₁ M).SeparatingLeft (R := R₁) ↔ M.det ≠ 0 := by
rw [Matrix.separatingLeft_toLinearMap₂'_iff, Matrix.nondegenerate_iff_det_ne_zero]
theorem separatingLeft_toLinearMap₂'_of_det_ne_zero' (M : Matrix ι ι R₁) (h : M.det ≠ 0) :
(Matrix.toLinearMap₂' R₁ M).SeparatingLeft (R := R₁) :=
separatingLeft_toLinearMap₂'_iff_det_ne_zero.mpr h
theorem separatingLeft_iff_det_ne_zero {B : M₁ →ₗ[R₁] M₁ →ₗ[R₁] R₁} (b : Basis ι R₁ M₁) :
B.SeparatingLeft ↔ (toMatrix₂ b b B).det ≠ 0 := by
rw [← Matrix.nondegenerate_iff_det_ne_zero, nondegenerate_toMatrix_iff]
theorem separatingLeft_of_det_ne_zero {B : M₁ →ₗ[R₁] M₁ →ₗ[R₁] R₁} (b : Basis ι R₁ M₁)
(h : (toMatrix₂ b b B).det ≠ 0) : B.SeparatingLeft :=
(separatingLeft_iff_det_ne_zero b).mpr h
end Det
end LinearMap
|
LinearAlgebra\Matrix\SpecialLinearGroup.lean | /-
Copyright (c) 2020 Anne Baanen. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Anne Baanen, Wen Yang
-/
import Mathlib.LinearAlgebra.GeneralLinearGroup
import Mathlib.LinearAlgebra.Matrix.Adjugate
import Mathlib.LinearAlgebra.Matrix.Transvection
import Mathlib.RingTheory.RootsOfUnity.Basic
/-!
# The Special Linear group $SL(n, R)$
This file defines the elements of the Special Linear group `SpecialLinearGroup n R`, consisting
of all square `R`-matrices with determinant `1` on the fintype `n` by `n`. In addition, we define
the group structure on `SpecialLinearGroup n R` and the embedding into the general linear group
`GeneralLinearGroup R (n → R)`.
## Main definitions
* `Matrix.SpecialLinearGroup` is the type of matrices with determinant 1
* `Matrix.SpecialLinearGroup.group` gives the group structure (under multiplication)
* `Matrix.SpecialLinearGroup.toGL` is the embedding `SLₙ(R) → GLₙ(R)`
## Notation
For `m : ℕ`, we introduce the notation `SL(m,R)` for the special linear group on the fintype
`n = Fin m`, in the locale `MatrixGroups`.
## Implementation notes
The inverse operation in the `SpecialLinearGroup` is defined to be the adjugate
matrix, so that `SpecialLinearGroup n R` has a group structure for all `CommRing R`.
We define the elements of `SpecialLinearGroup` to be matrices, since we need to
compute their determinant. This is in contrast with `GeneralLinearGroup R M`,
which consists of invertible `R`-linear maps on `M`.
We provide `Matrix.SpecialLinearGroup.hasCoeToFun` for convenience, but do not state any
lemmas about it, and use `Matrix.SpecialLinearGroup.coeFn_eq_coe` to eliminate it `⇑` in favor
of a regular `↑` coercion.
## References
* https://en.wikipedia.org/wiki/Special_linear_group
## Tags
matrix group, group, matrix inverse
-/
namespace Matrix
universe u v
open Matrix
open LinearMap
section
variable (n : Type u) [DecidableEq n] [Fintype n] (R : Type v) [CommRing R]
/-- `SpecialLinearGroup n R` is the group of `n` by `n` `R`-matrices with determinant equal to 1.
-/
def SpecialLinearGroup :=
{ A : Matrix n n R // A.det = 1 }
end
@[inherit_doc]
scoped[MatrixGroups] notation "SL(" n ", " R ")" => Matrix.SpecialLinearGroup (Fin n) R
namespace SpecialLinearGroup
variable {n : Type u} [DecidableEq n] [Fintype n] {R : Type v} [CommRing R]
instance hasCoeToMatrix : Coe (SpecialLinearGroup n R) (Matrix n n R) :=
⟨fun A => A.val⟩
/-- In this file, Lean often has a hard time working out the values of `n` and `R` for an expression
like `det ↑A`. Rather than writing `(A : Matrix n n R)` everywhere in this file which is annoyingly
verbose, or `A.val` which is not the simp-normal form for subtypes, we create a local notation
`↑ₘA`. This notation references the local `n` and `R` variables, so is not valid as a global
notation. -/
local notation:1024 "↑ₘ" A:1024 => ((A : SpecialLinearGroup n R) : Matrix n n R)
-- Porting note: moved this section upwards because it used to be not simp-normal.
-- Now it is, since coercion arrows are unfolded.
section CoeFnInstance
/-- This instance is here for convenience, but is literally the same as the coercion from
`hasCoeToMatrix`. -/
instance instCoeFun : CoeFun (SpecialLinearGroup n R) fun _ => n → n → R where coe A := ↑ₘA
end CoeFnInstance
theorem ext_iff (A B : SpecialLinearGroup n R) : A = B ↔ ∀ i j, ↑ₘA i j = ↑ₘB i j :=
Subtype.ext_iff.trans Matrix.ext_iff.symm
@[ext]
theorem ext (A B : SpecialLinearGroup n R) : (∀ i j, ↑ₘA i j = ↑ₘB i j) → A = B :=
(SpecialLinearGroup.ext_iff A B).mpr
instance subsingleton_of_subsingleton [Subsingleton n] : Subsingleton (SpecialLinearGroup n R) := by
refine ⟨fun ⟨A, hA⟩ ⟨B, hB⟩ ↦ ?_⟩
ext i j
rcases isEmpty_or_nonempty n with hn | hn; · exfalso; exact IsEmpty.false i
rw [det_eq_elem_of_subsingleton _ i] at hA hB
simp only [Subsingleton.elim j i, hA, hB]
instance hasInv : Inv (SpecialLinearGroup n R) :=
⟨fun A => ⟨adjugate A, by rw [det_adjugate, A.prop, one_pow]⟩⟩
instance hasMul : Mul (SpecialLinearGroup n R) :=
⟨fun A B => ⟨↑ₘA * ↑ₘB, by rw [det_mul, A.prop, B.prop, one_mul]⟩⟩
instance hasOne : One (SpecialLinearGroup n R) :=
⟨⟨1, det_one⟩⟩
instance : Pow (SpecialLinearGroup n R) ℕ where
pow x n := ⟨↑ₘx ^ n, (det_pow _ _).trans <| x.prop.symm ▸ one_pow _⟩
instance : Inhabited (SpecialLinearGroup n R) :=
⟨1⟩
/-- The transpose of a matrix in `SL(n, R)` -/
def transpose (A : SpecialLinearGroup n R) : SpecialLinearGroup n R :=
⟨A.1.transpose, A.1.det_transpose ▸ A.2⟩
@[inherit_doc]
scoped postfix:1024 "ᵀ" => SpecialLinearGroup.transpose
section CoeLemmas
variable (A B : SpecialLinearGroup n R)
-- Porting note: shouldn't be `@[simp]` because cast+mk gets reduced anyway
theorem coe_mk (A : Matrix n n R) (h : det A = 1) : ↑(⟨A, h⟩ : SpecialLinearGroup n R) = A :=
rfl
@[simp]
theorem coe_inv : ↑ₘA⁻¹ = adjugate A :=
rfl
@[simp]
theorem coe_mul : ↑ₘ(A * B) = ↑ₘA * ↑ₘB :=
rfl
@[simp]
theorem coe_one : ↑ₘ(1 : SpecialLinearGroup n R) = (1 : Matrix n n R) :=
rfl
@[simp]
theorem det_coe : det ↑ₘA = 1 :=
A.2
@[simp]
theorem coe_pow (m : ℕ) : ↑ₘ(A ^ m) = ↑ₘA ^ m :=
rfl
@[simp]
lemma coe_transpose (A : SpecialLinearGroup n R) : ↑ₘAᵀ = (↑ₘA)ᵀ :=
rfl
theorem det_ne_zero [Nontrivial R] (g : SpecialLinearGroup n R) : det ↑ₘg ≠ 0 := by
rw [g.det_coe]
norm_num
theorem row_ne_zero [Nontrivial R] (g : SpecialLinearGroup n R) (i : n) : ↑ₘg i ≠ 0 := fun h =>
g.det_ne_zero <| det_eq_zero_of_row_eq_zero i <| by simp [h]
end CoeLemmas
instance monoid : Monoid (SpecialLinearGroup n R) :=
Function.Injective.monoid (↑) Subtype.coe_injective coe_one coe_mul coe_pow
instance : Group (SpecialLinearGroup n R) :=
{ SpecialLinearGroup.monoid, SpecialLinearGroup.hasInv with
mul_left_inv := fun A => by
ext1
simp [adjugate_mul] }
/-- A version of `Matrix.toLin' A` that produces linear equivalences. -/
def toLin' : SpecialLinearGroup n R →* (n → R) ≃ₗ[R] n → R where
toFun A :=
LinearEquiv.ofLinear (Matrix.toLin' ↑ₘA) (Matrix.toLin' ↑ₘA⁻¹)
(by rw [← toLin'_mul, ← coe_mul, mul_right_inv, coe_one, toLin'_one])
(by rw [← toLin'_mul, ← coe_mul, mul_left_inv, coe_one, toLin'_one])
map_one' := LinearEquiv.toLinearMap_injective Matrix.toLin'_one
map_mul' A B := LinearEquiv.toLinearMap_injective <| Matrix.toLin'_mul ↑ₘA ↑ₘB
theorem toLin'_apply (A : SpecialLinearGroup n R) (v : n → R) :
SpecialLinearGroup.toLin' A v = Matrix.toLin' (↑ₘA) v :=
rfl
theorem toLin'_to_linearMap (A : SpecialLinearGroup n R) :
↑(SpecialLinearGroup.toLin' A) = Matrix.toLin' ↑ₘA :=
rfl
theorem toLin'_symm_apply (A : SpecialLinearGroup n R) (v : n → R) :
A.toLin'.symm v = Matrix.toLin' (↑ₘA⁻¹) v :=
rfl
theorem toLin'_symm_to_linearMap (A : SpecialLinearGroup n R) :
↑A.toLin'.symm = Matrix.toLin' ↑ₘA⁻¹ :=
rfl
theorem toLin'_injective :
Function.Injective ↑(toLin' : SpecialLinearGroup n R →* (n → R) ≃ₗ[R] n → R) := fun _ _ h =>
Subtype.coe_injective <| Matrix.toLin'.injective <| LinearEquiv.toLinearMap_injective.eq_iff.mpr h
/-- `toGL` is the map from the special linear group to the general linear group -/
def toGL : SpecialLinearGroup n R →* GeneralLinearGroup R (n → R) :=
(GeneralLinearGroup.generalLinearEquiv _ _).symm.toMonoidHom.comp toLin'
-- Porting note (#11036): broken dot notation
theorem coe_toGL (A : SpecialLinearGroup n R) : SpecialLinearGroup.toGL A = A.toLin'.toLinearMap :=
rfl
variable {S : Type*} [CommRing S]
/-- A ring homomorphism from `R` to `S` induces a group homomorphism from
`SpecialLinearGroup n R` to `SpecialLinearGroup n S`. -/
@[simps]
def map (f : R →+* S) : SpecialLinearGroup n R →* SpecialLinearGroup n S where
toFun g :=
⟨f.mapMatrix ↑ₘg, by
rw [← f.map_det]
simp [g.prop]⟩
map_one' := Subtype.ext <| f.mapMatrix.map_one
map_mul' x y := Subtype.ext <| f.mapMatrix.map_mul ↑ₘx ↑ₘy
section center
open Subgroup
@[simp]
theorem center_eq_bot_of_subsingleton [Subsingleton n] :
center (SpecialLinearGroup n R) = ⊥ :=
eq_bot_iff.mpr fun x _ ↦ by rw [mem_bot, Subsingleton.elim x 1]
theorem scalar_eq_self_of_mem_center
{A : SpecialLinearGroup n R} (hA : A ∈ center (SpecialLinearGroup n R)) (i : n) :
scalar n (A i i) = A := by
obtain ⟨r : R, hr : scalar n r = A⟩ := mem_range_scalar_of_commute_transvectionStruct fun t ↦
Subtype.ext_iff.mp <| Subgroup.mem_center_iff.mp hA ⟨t.toMatrix, by simp⟩
simp [← congr_fun₂ hr i i, ← hr]
theorem scalar_eq_coe_self_center
(A : center (SpecialLinearGroup n R)) (i : n) :
scalar n ((A : Matrix n n R) i i) = A :=
scalar_eq_self_of_mem_center A.property i
/-- The center of a special linear group of degree `n` is the subgroup of scalar matrices, for which
the scalars are the `n`-th roots of unity. -/
theorem mem_center_iff {A : SpecialLinearGroup n R} :
A ∈ center (SpecialLinearGroup n R) ↔ ∃ (r : R), r ^ (Fintype.card n) = 1 ∧ scalar n r = A := by
rcases isEmpty_or_nonempty n with hn | ⟨⟨i⟩⟩; · exact ⟨by aesop, by simp [Subsingleton.elim A 1]⟩
refine ⟨fun h ↦ ⟨A i i, ?_, ?_⟩, fun ⟨r, _, hr⟩ ↦ Subgroup.mem_center_iff.mpr fun B ↦ ?_⟩
· have : det ((scalar n) (A i i)) = 1 := (scalar_eq_self_of_mem_center h i).symm ▸ A.property
simpa using this
· exact scalar_eq_self_of_mem_center h i
· suffices ↑ₘ(B * A) = ↑ₘ(A * B) from Subtype.val_injective this
simpa only [coe_mul, ← hr] using (scalar_commute (n := n) r (Commute.all r) B).symm
/-- An equivalence of groups, from the center of the special linear group to the roots of unity. -/
@[simps]
def center_equiv_rootsOfUnity' (i : n) :
center (SpecialLinearGroup n R) ≃* rootsOfUnity (Fintype.card n).toPNat' R where
toFun A := rootsOfUnity.mkOfPowEq (↑ₘA i i) <| by
have : Nonempty n := ⟨i⟩
obtain ⟨r, hr, hr'⟩ := mem_center_iff.mp A.property
replace hr' : A.val i i = r := by simp [← hr']
simp [hr, hr']
invFun a := ⟨⟨a • (1 : Matrix n n R), by aesop⟩,
Subgroup.mem_center_iff.mpr fun B ↦ Subtype.val_injective <| by simp [coe_mul]⟩
left_inv A := by
refine SetCoe.ext <| SetCoe.ext ?_
obtain ⟨r, _, hr⟩ := mem_center_iff.mp A.property
simpa [← hr, Submonoid.smul_def, Units.smul_def] using smul_one_eq_diagonal r
right_inv a := by
obtain ⟨⟨a, _⟩, ha⟩ := a
exact SetCoe.ext <| Units.eq_iff.mp <| by simp
map_mul' A B := by
dsimp
ext
simp only [Submonoid.coe_mul, coe_mul, rootsOfUnity.val_mkOfPowEq_coe, Units.val_mul]
rw [← scalar_eq_coe_self_center A i, ← scalar_eq_coe_self_center B i]
simp
open scoped Classical in
/-- An equivalence of groups, from the center of the special linear group to the roots of unity.
See also `center_equiv_rootsOfUnity'`. -/
noncomputable def center_equiv_rootsOfUnity :
center (SpecialLinearGroup n R) ≃* rootsOfUnity (Fintype.card n).toPNat' R :=
(isEmpty_or_nonempty n).by_cases
(fun hn ↦ by
rw [center_eq_bot_of_subsingleton, Fintype.card_eq_zero, Nat.toPNat'_zero, rootsOfUnity_one]
exact MulEquiv.mulEquivOfUnique)
(fun hn ↦ center_equiv_rootsOfUnity' (Classical.arbitrary n))
end center
section cast
/-- Coercion of SL `n` `ℤ` to SL `n` `R` for a commutative ring `R`. -/
instance : Coe (SpecialLinearGroup n ℤ) (SpecialLinearGroup n R) :=
⟨fun x => map (Int.castRingHom R) x⟩
@[simp]
theorem coe_matrix_coe (g : SpecialLinearGroup n ℤ) :
↑(g : SpecialLinearGroup n R) = (↑g : Matrix n n ℤ).map (Int.castRingHom R) :=
map_apply_coe (Int.castRingHom R) g
end cast
section Neg
variable [Fact (Even (Fintype.card n))]
/-- Formal operation of negation on special linear group on even cardinality `n` given by negating
each element. -/
instance instNeg : Neg (SpecialLinearGroup n R) :=
⟨fun g => ⟨-g, by
simpa [(@Fact.out <| Even <| Fintype.card n).neg_one_pow, g.det_coe] using det_smul (↑ₘg) (-1)⟩⟩
@[simp]
theorem coe_neg (g : SpecialLinearGroup n R) : ↑(-g) = -(g : Matrix n n R) :=
rfl
instance : HasDistribNeg (SpecialLinearGroup n R) :=
Function.Injective.hasDistribNeg _ Subtype.coe_injective coe_neg coe_mul
@[simp]
theorem coe_int_neg (g : SpecialLinearGroup n ℤ) : ↑(-g) = (-↑g : SpecialLinearGroup n R) :=
Subtype.ext <| (@RingHom.mapMatrix n _ _ _ _ _ _ (Int.castRingHom R)).map_neg ↑g
end Neg
section SpecialCases
open scoped MatrixGroups
theorem SL2_inv_expl_det (A : SL(2, R)) :
det ![![A.1 1 1, -A.1 0 1], ![-A.1 1 0, A.1 0 0]] = 1 := by
rw [Matrix.det_fin_two, mul_comm]
simp only [cons_val_zero, cons_val_one, head_cons, mul_neg, neg_mul, neg_neg]
have := A.2
rw [Matrix.det_fin_two] at this
convert this
theorem SL2_inv_expl (A : SL(2, R)) :
A⁻¹ = ⟨![![A.1 1 1, -A.1 0 1], ![-A.1 1 0, A.1 0 0]], SL2_inv_expl_det A⟩ := by
ext
have := Matrix.adjugate_fin_two A.1
rw [coe_inv, this]
rfl
theorem fin_two_induction (P : SL(2, R) → Prop)
(h : ∀ (a b c d : R) (hdet : a * d - b * c = 1), P ⟨!![a, b; c, d], by rwa [det_fin_two_of]⟩)
(g : SL(2, R)) : P g := by
obtain ⟨m, hm⟩ := g
convert h (m 0 0) (m 0 1) (m 1 0) (m 1 1) (by rwa [det_fin_two] at hm)
ext i j; fin_cases i <;> fin_cases j <;> rfl
theorem fin_two_exists_eq_mk_of_apply_zero_one_eq_zero {R : Type*} [Field R] (g : SL(2, R))
(hg : (g : Matrix (Fin 2) (Fin 2) R) 1 0 = 0) :
∃ (a b : R) (h : a ≠ 0), g = (⟨!![a, b; 0, a⁻¹], by simp [h]⟩ : SL(2, R)) := by
induction' g using Matrix.SpecialLinearGroup.fin_two_induction with a b c d h_det
replace hg : c = 0 := by simpa using hg
have had : a * d = 1 := by rwa [hg, mul_zero, sub_zero] at h_det
refine ⟨a, b, left_ne_zero_of_mul_eq_one had, ?_⟩
simp_rw [eq_inv_of_mul_eq_one_right had, hg]
lemma isCoprime_row (A : SL(2, R)) (i : Fin 2) : IsCoprime (A i 0) (A i 1) := by
refine match i with
| 0 => ⟨A 1 1, -(A 1 0), ?_⟩
| 1 => ⟨-(A 0 1), A 0 0, ?_⟩ <;>
· simp_rw [det_coe A ▸ det_fin_two A.1]
ring
lemma isCoprime_col (A : SL(2, R)) (j : Fin 2) : IsCoprime (A 0 j) (A 1 j) := by
refine match j with
| 0 => ⟨A 1 1, -(A 0 1), ?_⟩
| 1 => ⟨-(A 1 0), A 0 0, ?_⟩ <;>
· simp_rw [det_coe A ▸ det_fin_two A.1]
ring
end SpecialCases
end SpecialLinearGroup
end Matrix
namespace IsCoprime
open Matrix MatrixGroups SpecialLinearGroup
variable {R : Type*} [CommRing R]
/-- Given any pair of coprime elements of `R`, there exists a matrix in `SL(2, R)` having those
entries as its left or right column. -/
lemma exists_SL2_col {a b : R} (hab : IsCoprime a b) (j : Fin 2) :
∃ g : SL(2, R), g 0 j = a ∧ g 1 j = b := by
obtain ⟨u, v, h⟩ := hab
refine match j with
| 0 => ⟨⟨!![a, -v; b, u], ?_⟩, rfl, rfl⟩
| 1 => ⟨⟨!![v, a; -u, b], ?_⟩, rfl, rfl⟩ <;>
· rw [Matrix.det_fin_two_of, ← h]
ring
/-- Given any pair of coprime elements of `R`, there exists a matrix in `SL(2, R)` having those
entries as its top or bottom row. -/
lemma exists_SL2_row {a b : R} (hab : IsCoprime a b) (i : Fin 2) :
∃ g : SL(2, R), g i 0 = a ∧ g i 1 = b := by
obtain ⟨u, v, h⟩ := hab
refine match i with
| 0 => ⟨⟨!![a, b; -v, u], ?_⟩, rfl, rfl⟩
| 1 => ⟨⟨!![v, -u; a, b], ?_⟩, rfl, rfl⟩ <;>
· rw [Matrix.det_fin_two_of, ← h]
ring
/-- A vector with coprime entries, right-multiplied by a matrix in `SL(2, R)`, has
coprime entries. -/
lemma vecMulSL {v : Fin 2 → R} (hab : IsCoprime (v 0) (v 1)) (A : SL(2, R)) :
IsCoprime ((v ᵥ* A.1) 0) ((v ᵥ* A.1) 1) := by
obtain ⟨g, hg⟩ := hab.exists_SL2_row 0
have : v = g 0 := funext fun t ↦ by { fin_cases t <;> tauto }
simpa only [this] using isCoprime_row (g * A) 0
/-- A vector with coprime entries, left-multiplied by a matrix in `SL(2, R)`, has
coprime entries. -/
lemma mulVecSL {v : Fin 2 → R} (hab : IsCoprime (v 0) (v 1)) (A : SL(2, R)) :
IsCoprime ((A.1 *ᵥ v) 0) ((A.1 *ᵥ v) 1) := by
simpa only [← vecMul_transpose] using hab.vecMulSL A.transpose
end IsCoprime
namespace ModularGroup
open MatrixGroups
open Matrix Matrix.SpecialLinearGroup
local notation:1024 "↑ₘ" A:1024 => ((A : SL(2, ℤ)) : Matrix (Fin 2) (Fin 2) ℤ)
/-- The matrix `S = [[0, -1], [1, 0]]` as an element of `SL(2, ℤ)`.
This element acts naturally on the Euclidean plane as a rotation about the origin by `π / 2`.
This element also acts naturally on the hyperbolic plane as rotation about `i` by `π`. It
represents the Mobiüs transformation `z ↦ -1/z` and is an involutive elliptic isometry. -/
def S : SL(2, ℤ) :=
⟨!![0, -1; 1, 0], by norm_num [Matrix.det_fin_two_of]⟩
/-- The matrix `T = [[1, 1], [0, 1]]` as an element of `SL(2, ℤ)` -/
def T : SL(2, ℤ) :=
⟨!![1, 1; 0, 1], by norm_num [Matrix.det_fin_two_of]⟩
theorem coe_S : ↑ₘS = !![0, -1; 1, 0] :=
rfl
theorem coe_T : ↑ₘT = !![1, 1; 0, 1] :=
rfl
theorem coe_T_inv : ↑ₘT⁻¹ = !![1, -1; 0, 1] := by simp [coe_inv, coe_T, adjugate_fin_two]
theorem coe_T_zpow (n : ℤ) : ↑ₘ(T ^ n) = !![1, n; 0, 1] := by
induction' n using Int.induction_on with n h n h
· rw [zpow_zero, coe_one, Matrix.one_fin_two]
· simp_rw [zpow_add, zpow_one, coe_mul, h, coe_T, Matrix.mul_fin_two]
congrm !![_, ?_; _, _]
rw [mul_one, mul_one, add_comm]
· simp_rw [zpow_sub, zpow_one, coe_mul, h, coe_T_inv, Matrix.mul_fin_two]
congrm !![?_, ?_; _, _] <;> ring
@[simp]
theorem T_pow_mul_apply_one (n : ℤ) (g : SL(2, ℤ)) : ↑ₘ(T ^ n * g) 1 = ↑ₘg 1 := by
ext j
simp [coe_T_zpow, Matrix.vecMul, Matrix.dotProduct, Fin.sum_univ_succ, vecTail]
@[simp]
theorem T_mul_apply_one (g : SL(2, ℤ)) : ↑ₘ(T * g) 1 = ↑ₘg 1 := by
simpa using T_pow_mul_apply_one 1 g
@[simp]
theorem T_inv_mul_apply_one (g : SL(2, ℤ)) : ↑ₘ(T⁻¹ * g) 1 = ↑ₘg 1 := by
simpa using T_pow_mul_apply_one (-1) g
end ModularGroup
|
LinearAlgebra\Matrix\Spectrum.lean | /-
Copyright (c) 2022 Alexander Bentkamp. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Alexander Bentkamp
-/
import Mathlib.Analysis.InnerProductSpace.Spectrum
import Mathlib.Data.Matrix.Rank
import Mathlib.LinearAlgebra.Matrix.Diagonal
import Mathlib.LinearAlgebra.Matrix.Hermitian
import Mathlib.Analysis.CStarAlgebra.Matrix
import Mathlib.Topology.Algebra.Module.FiniteDimension
/-! # Spectral theory of hermitian matrices
This file proves the spectral theorem for matrices. The proof of the spectral theorem is based on
the spectral theorem for linear maps (`LinearMap.IsSymmetric.eigenvectorBasis_apply_self_apply`).
## Tags
spectral theorem, diagonalization theorem-/
namespace Matrix
variable {𝕜 : Type*} [RCLike 𝕜] {n : Type*} [Fintype n]
variable {A : Matrix n n 𝕜}
namespace IsHermitian
section DecidableEq
variable [DecidableEq n]
variable (hA : A.IsHermitian)
/-- The eigenvalues of a hermitian matrix, indexed by `Fin (Fintype.card n)` where `n` is the index
type of the matrix. -/
noncomputable def eigenvalues₀ : Fin (Fintype.card n) → ℝ :=
(isHermitian_iff_isSymmetric.1 hA).eigenvalues finrank_euclideanSpace
/-- The eigenvalues of a hermitian matrix, reusing the index `n` of the matrix entries. -/
noncomputable def eigenvalues : n → ℝ := fun i =>
hA.eigenvalues₀ <| (Fintype.equivOfCardEq (Fintype.card_fin _)).symm i
/-- A choice of an orthonormal basis of eigenvectors of a hermitian matrix. -/
noncomputable def eigenvectorBasis : OrthonormalBasis n 𝕜 (EuclideanSpace 𝕜 n) :=
((isHermitian_iff_isSymmetric.1 hA).eigenvectorBasis finrank_euclideanSpace).reindex
(Fintype.equivOfCardEq (Fintype.card_fin _))
lemma mulVec_eigenvectorBasis (j : n) :
A *ᵥ ⇑(hA.eigenvectorBasis j) = (hA.eigenvalues j) • ⇑(hA.eigenvectorBasis j) := by
simpa only [eigenvectorBasis, OrthonormalBasis.reindex_apply, toEuclideanLin_apply,
RCLike.real_smul_eq_coe_smul (K := 𝕜)] using
congr(⇑$((isHermitian_iff_isSymmetric.1 hA).apply_eigenvectorBasis
finrank_euclideanSpace ((Fintype.equivOfCardEq (Fintype.card_fin _)).symm j)))
/-- The spectrum of a Hermitian matrix `A` coincides with the spectrum of `toEuclideanLin A`. -/
theorem spectrum_toEuclideanLin : spectrum 𝕜 (toEuclideanLin A) = spectrum 𝕜 A :=
AlgEquiv.spectrum_eq
(AlgEquiv.trans
((toEuclideanCLM : Matrix n n 𝕜 ≃⋆ₐ[𝕜] EuclideanSpace 𝕜 n →L[𝕜] EuclideanSpace 𝕜 n) :
Matrix n n 𝕜 ≃ₐ[𝕜] EuclideanSpace 𝕜 n →L[𝕜] EuclideanSpace 𝕜 n)
(Module.End.toContinuousLinearMap (EuclideanSpace 𝕜 n)).symm)
_
/-- Eigenvalues of a hermitian matrix A are in the ℝ spectrum of A. -/
theorem eigenvalues_mem_spectrum_real (i : n) : hA.eigenvalues i ∈ spectrum ℝ A := by
apply spectrum.of_algebraMap_mem 𝕜
rw [← spectrum_toEuclideanLin]
exact LinearMap.IsSymmetric.hasEigenvalue_eigenvalues _ _ _ |>.mem_spectrum
/-- Unitary matrix whose columns are `Matrix.IsHermitian.eigenvectorBasis`. -/
noncomputable def eigenvectorUnitary {𝕜 : Type*} [RCLike 𝕜] {n : Type*}
[Fintype n]{A : Matrix n n 𝕜} [DecidableEq n] (hA : Matrix.IsHermitian A) :
Matrix.unitaryGroup n 𝕜 :=
⟨(EuclideanSpace.basisFun n 𝕜).toBasis.toMatrix (hA.eigenvectorBasis).toBasis,
(EuclideanSpace.basisFun n 𝕜).toMatrix_orthonormalBasis_mem_unitary (eigenvectorBasis hA)⟩
lemma eigenvectorUnitary_coe {𝕜 : Type*} [RCLike 𝕜] {n : Type*} [Fintype n]
{A : Matrix n n 𝕜} [DecidableEq n] (hA : Matrix.IsHermitian A) :
eigenvectorUnitary hA =
(EuclideanSpace.basisFun n 𝕜).toBasis.toMatrix (hA.eigenvectorBasis).toBasis :=
rfl
@[simp]
theorem eigenvectorUnitary_apply (i j : n) :
eigenvectorUnitary hA i j = ⇑(hA.eigenvectorBasis j) i :=
rfl
theorem eigenvectorUnitary_mulVec (j : n) :
eigenvectorUnitary hA *ᵥ Pi.single j 1 = ⇑(hA.eigenvectorBasis j) := by
simp only [mulVec_single, eigenvectorUnitary_apply, mul_one]
theorem star_eigenvectorUnitary_mulVec (j : n) :
(star (eigenvectorUnitary hA : Matrix n n 𝕜)) *ᵥ ⇑(hA.eigenvectorBasis j) = Pi.single j 1 := by
rw [← eigenvectorUnitary_mulVec, mulVec_mulVec, unitary.coe_star_mul_self, one_mulVec]
/-- Unitary diagonalization of a Hermitian matrix. -/
theorem star_mul_self_mul_eq_diagonal :
(star (eigenvectorUnitary hA : Matrix n n 𝕜)) * A * (eigenvectorUnitary hA : Matrix n n 𝕜)
= diagonal (RCLike.ofReal ∘ hA.eigenvalues) := by
apply Matrix.toEuclideanLin.injective
apply Basis.ext (EuclideanSpace.basisFun n 𝕜).toBasis
intro i
simp only [toEuclideanLin_apply, OrthonormalBasis.coe_toBasis, EuclideanSpace.basisFun_apply,
WithLp.equiv_single, ← mulVec_mulVec, eigenvectorUnitary_mulVec, ← mulVec_mulVec,
mulVec_eigenvectorBasis, Matrix.diagonal_mulVec_single, mulVec_smul,
star_eigenvectorUnitary_mulVec, RCLike.real_smul_eq_coe_smul (K := 𝕜), WithLp.equiv_symm_smul,
WithLp.equiv_symm_single, Function.comp_apply, mul_one, WithLp.equiv_symm_single]
apply PiLp.ext
intro j
simp only [PiLp.smul_apply, EuclideanSpace.single_apply, smul_eq_mul, mul_ite, mul_one, mul_zero]
/-- **Diagonalization theorem**, **spectral theorem** for matrices; A hermitian matrix can be
diagonalized by a change of basis. For the spectral theorem on linear maps, see
`LinearMap.IsSymmetric.eigenvectorBasis_apply_self_apply`.-/
theorem spectral_theorem :
A = (eigenvectorUnitary hA : Matrix n n 𝕜) * diagonal (RCLike.ofReal ∘ hA.eigenvalues)
* (star (eigenvectorUnitary hA : Matrix n n 𝕜)) := by
rw [← star_mul_self_mul_eq_diagonal, mul_assoc, mul_assoc,
(Matrix.mem_unitaryGroup_iff).mp (eigenvectorUnitary hA).2, mul_one,
← mul_assoc, (Matrix.mem_unitaryGroup_iff).mp (eigenvectorUnitary hA).2, one_mul]
theorem eigenvalues_eq (i : n) :
(hA.eigenvalues i) = RCLike.re (Matrix.dotProduct (star ⇑(hA.eigenvectorBasis i))
(A *ᵥ ⇑(hA.eigenvectorBasis i))) := by
simp only [mulVec_eigenvectorBasis, dotProduct_smul,← EuclideanSpace.inner_eq_star_dotProduct,
inner_self_eq_norm_sq_to_K, RCLike.smul_re, hA.eigenvectorBasis.orthonormal.1 i,
mul_one, algebraMap.coe_one, one_pow, RCLike.one_re]
/-- The determinant of a hermitian matrix is the product of its eigenvalues. -/
theorem det_eq_prod_eigenvalues : det A = ∏ i, (hA.eigenvalues i : 𝕜) := by
convert congr_arg det hA.spectral_theorem
rw [det_mul_right_comm]
simp
/-- rank of a hermitian matrix is the rank of after diagonalization by the eigenvector unitary -/
lemma rank_eq_rank_diagonal : A.rank = (Matrix.diagonal hA.eigenvalues).rank := by
conv_lhs => rw [hA.spectral_theorem, ← unitary.coe_star]
simp [-isUnit_iff_ne_zero, -unitary.coe_star, rank_diagonal]
/-- rank of a hermitian matrix is the number of nonzero eigenvalues of the hermitian matrix -/
lemma rank_eq_card_non_zero_eigs : A.rank = Fintype.card {i // hA.eigenvalues i ≠ 0} := by
rw [rank_eq_rank_diagonal hA, Matrix.rank_diagonal]
end DecidableEq
/-- A nonzero Hermitian matrix has an eigenvector with nonzero eigenvalue. -/
lemma exists_eigenvector_of_ne_zero (hA : IsHermitian A) (h_ne : A ≠ 0) :
∃ (v : n → 𝕜) (t : ℝ), t ≠ 0 ∧ v ≠ 0 ∧ A *ᵥ v = t • v := by
classical
have : hA.eigenvalues ≠ 0 := by
contrapose! h_ne
have := hA.spectral_theorem
rwa [h_ne, Pi.comp_zero, RCLike.ofReal_zero, (by rfl : Function.const n (0 : 𝕜) = fun _ ↦ 0),
diagonal_zero, mul_zero, zero_mul] at this
obtain ⟨i, hi⟩ := Function.ne_iff.mp this
exact ⟨_, _, hi, hA.eigenvectorBasis.orthonormal.ne_zero i, hA.mulVec_eigenvectorBasis i⟩
end IsHermitian
end Matrix
/-The following were removed as a result of the refactor, since they either were
unused in the library, followed as immediate consequences of, or were replaced by
above results (e.g. results about inverses don't need replacement because their unitary
analogues have replaced them).-/
|
LinearAlgebra\Matrix\Symmetric.lean | /-
Copyright (c) 2021 Lu-Ming Zhang. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Lu-Ming Zhang
-/
import Mathlib.Data.Matrix.Block
/-!
# Symmetric matrices
This file contains the definition and basic results about symmetric matrices.
## Main definition
* `Matrix.isSymm`: a matrix `A : Matrix n n α` is "symmetric" if `Aᵀ = A`.
## Tags
symm, symmetric, matrix
-/
variable {α β n m R : Type*}
namespace Matrix
open Matrix
/-- A matrix `A : Matrix n n α` is "symmetric" if `Aᵀ = A`. -/
def IsSymm (A : Matrix n n α) : Prop :=
Aᵀ = A
instance (A : Matrix n n α) [Decidable (Aᵀ = A)] : Decidable (IsSymm A) :=
inferInstanceAs <| Decidable (_ = _)
theorem IsSymm.eq {A : Matrix n n α} (h : A.IsSymm) : Aᵀ = A :=
h
/-- A version of `Matrix.ext_iff` that unfolds the `Matrix.transpose`. -/
theorem IsSymm.ext_iff {A : Matrix n n α} : A.IsSymm ↔ ∀ i j, A j i = A i j :=
Matrix.ext_iff.symm
/-- A version of `Matrix.ext` that unfolds the `Matrix.transpose`. -/
-- @[ext] -- Porting note: removed attribute
theorem IsSymm.ext {A : Matrix n n α} : (∀ i j, A j i = A i j) → A.IsSymm :=
Matrix.ext
theorem IsSymm.apply {A : Matrix n n α} (h : A.IsSymm) (i j : n) : A j i = A i j :=
IsSymm.ext_iff.1 h i j
theorem isSymm_mul_transpose_self [Fintype n] [CommSemiring α] (A : Matrix n n α) :
(A * Aᵀ).IsSymm :=
transpose_mul _ _
theorem isSymm_transpose_mul_self [Fintype n] [CommSemiring α] (A : Matrix n n α) :
(Aᵀ * A).IsSymm :=
transpose_mul _ _
theorem isSymm_add_transpose_self [AddCommSemigroup α] (A : Matrix n n α) : (A + Aᵀ).IsSymm :=
add_comm _ _
theorem isSymm_transpose_add_self [AddCommSemigroup α] (A : Matrix n n α) : (Aᵀ + A).IsSymm :=
add_comm _ _
@[simp]
theorem isSymm_zero [Zero α] : (0 : Matrix n n α).IsSymm :=
transpose_zero
@[simp]
theorem isSymm_one [DecidableEq n] [Zero α] [One α] : (1 : Matrix n n α).IsSymm :=
transpose_one
theorem IsSymm.pow [CommSemiring α] [Fintype n] [DecidableEq n] {A : Matrix n n α} (h : A.IsSymm)
(k : ℕ) :
(A ^ k).IsSymm := by
rw [IsSymm, transpose_pow, h]
@[simp]
theorem IsSymm.map {A : Matrix n n α} (h : A.IsSymm) (f : α → β) : (A.map f).IsSymm :=
transpose_map.symm.trans (h.symm ▸ rfl)
@[simp]
theorem IsSymm.transpose {A : Matrix n n α} (h : A.IsSymm) : Aᵀ.IsSymm :=
congr_arg _ h
@[simp]
theorem IsSymm.conjTranspose [Star α] {A : Matrix n n α} (h : A.IsSymm) : Aᴴ.IsSymm :=
h.transpose.map _
@[simp]
theorem IsSymm.neg [Neg α] {A : Matrix n n α} (h : A.IsSymm) : (-A).IsSymm :=
(transpose_neg _).trans (congr_arg _ h)
@[simp]
theorem IsSymm.add {A B : Matrix n n α} [Add α] (hA : A.IsSymm) (hB : B.IsSymm) : (A + B).IsSymm :=
(transpose_add _ _).trans (hA.symm ▸ hB.symm ▸ rfl)
@[simp]
theorem IsSymm.sub {A B : Matrix n n α} [Sub α] (hA : A.IsSymm) (hB : B.IsSymm) : (A - B).IsSymm :=
(transpose_sub _ _).trans (hA.symm ▸ hB.symm ▸ rfl)
@[simp]
theorem IsSymm.smul [SMul R α] {A : Matrix n n α} (h : A.IsSymm) (k : R) : (k • A).IsSymm :=
(transpose_smul _ _).trans (congr_arg _ h)
@[simp]
theorem IsSymm.submatrix {A : Matrix n n α} (h : A.IsSymm) (f : m → n) : (A.submatrix f f).IsSymm :=
(transpose_submatrix _ _ _).trans (h.symm ▸ rfl)
/-- The diagonal matrix `diagonal v` is symmetric. -/
@[simp]
theorem isSymm_diagonal [DecidableEq n] [Zero α] (v : n → α) : (diagonal v).IsSymm :=
diagonal_transpose _
/-- A block matrix `A.fromBlocks B C D` is symmetric,
if `A` and `D` are symmetric and `Bᵀ = C`. -/
theorem IsSymm.fromBlocks {A : Matrix m m α} {B : Matrix m n α} {C : Matrix n m α}
{D : Matrix n n α} (hA : A.IsSymm) (hBC : Bᵀ = C) (hD : D.IsSymm) :
(A.fromBlocks B C D).IsSymm := by
have hCB : Cᵀ = B := by
rw [← hBC]
simp
unfold Matrix.IsSymm
rw [fromBlocks_transpose, hA, hCB, hBC, hD]
/-- This is the `iff` version of `Matrix.isSymm.fromBlocks`. -/
theorem isSymm_fromBlocks_iff {A : Matrix m m α} {B : Matrix m n α} {C : Matrix n m α}
{D : Matrix n n α} : (A.fromBlocks B C D).IsSymm ↔ A.IsSymm ∧ Bᵀ = C ∧ Cᵀ = B ∧ D.IsSymm :=
⟨fun h =>
⟨(congr_arg toBlocks₁₁ h : _), (congr_arg toBlocks₂₁ h : _), (congr_arg toBlocks₁₂ h : _),
(congr_arg toBlocks₂₂ h : _)⟩,
fun ⟨hA, hBC, _, hD⟩ => IsSymm.fromBlocks hA hBC hD⟩
end Matrix
|
LinearAlgebra\Matrix\ToLin.lean | /-
Copyright (c) 2019 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Patrick Massot, Casper Putz, Anne Baanen
-/
import Mathlib.Data.Matrix.Block
import Mathlib.Data.Matrix.Notation
import Mathlib.LinearAlgebra.StdBasis
import Mathlib.RingTheory.AlgebraTower
import Mathlib.Algebra.Algebra.Subalgebra.Tower
/-!
# Linear maps and matrices
This file defines the maps to send matrices to a linear map,
and to send linear maps between modules with a finite bases
to matrices. This defines a linear equivalence between linear maps
between finite-dimensional vector spaces and matrices indexed by
the respective bases.
## Main definitions
In the list below, and in all this file, `R` is a commutative ring (semiring
is sometimes enough), `M` and its variations are `R`-modules, `ι`, `κ`, `n` and `m` are finite
types used for indexing.
* `LinearMap.toMatrix`: given bases `v₁ : ι → M₁` and `v₂ : κ → M₂`,
the `R`-linear equivalence from `M₁ →ₗ[R] M₂` to `Matrix κ ι R`
* `Matrix.toLin`: the inverse of `LinearMap.toMatrix`
* `LinearMap.toMatrix'`: the `R`-linear equivalence from `(m → R) →ₗ[R] (n → R)`
to `Matrix m n R` (with the standard basis on `m → R` and `n → R`)
* `Matrix.toLin'`: the inverse of `LinearMap.toMatrix'`
* `algEquivMatrix`: given a basis indexed by `n`, the `R`-algebra equivalence between
`R`-endomorphisms of `M` and `Matrix n n R`
## Issues
This file was originally written without attention to non-commutative rings,
and so mostly only works in the commutative setting. This should be fixed.
In particular, `Matrix.mulVec` gives us a linear equivalence
`Matrix m n R ≃ₗ[R] (n → R) →ₗ[Rᵐᵒᵖ] (m → R)`
while `Matrix.vecMul` gives us a linear equivalence
`Matrix m n R ≃ₗ[Rᵐᵒᵖ] (m → R) →ₗ[R] (n → R)`.
At present, the first equivalence is developed in detail but only for commutative rings
(and we omit the distinction between `Rᵐᵒᵖ` and `R`),
while the second equivalence is developed only in brief, but for not-necessarily-commutative rings.
Naming is slightly inconsistent between the two developments.
In the original (commutative) development `linear` is abbreviated to `lin`,
although this is not consistent with the rest of mathlib.
In the new (non-commutative) development `linear` is not abbreviated, and declarations use `_right`
to indicate they use the right action of matrices on vectors (via `Matrix.vecMul`).
When the two developments are made uniform, the names should be made uniform, too,
by choosing between `linear` and `lin` consistently,
and (presumably) adding `_left` where necessary.
## Tags
linear_map, matrix, linear_equiv, diagonal, det, trace
-/
noncomputable section
open LinearMap Matrix Set Submodule
section ToMatrixRight
variable {R : Type*} [Semiring R]
variable {l m n : Type*}
/-- `Matrix.vecMul M` is a linear map. -/
def Matrix.vecMulLinear [Fintype m] (M : Matrix m n R) : (m → R) →ₗ[R] n → R where
toFun x := x ᵥ* M
map_add' _ _ := funext fun _ ↦ add_dotProduct _ _ _
map_smul' _ _ := funext fun _ ↦ smul_dotProduct _ _ _
@[simp] theorem Matrix.vecMulLinear_apply [Fintype m] (M : Matrix m n R) (x : m → R) :
M.vecMulLinear x = x ᵥ* M := rfl
theorem Matrix.coe_vecMulLinear [Fintype m] (M : Matrix m n R) :
(M.vecMulLinear : _ → _) = M.vecMul := rfl
variable [Fintype m]
@[simp]
theorem Matrix.vecMul_stdBasis [DecidableEq m] (M : Matrix m n R) (i j) :
(LinearMap.stdBasis R (fun _ ↦ R) i 1 ᵥ* M) j = M i j := by
have : (∑ i', (if i = i' then 1 else 0) * M i' j) = M i j := by
simp_rw [boole_mul, Finset.sum_ite_eq, Finset.mem_univ, if_true]
simp only [vecMul, dotProduct]
convert this
split_ifs with h <;> simp only [stdBasis_apply]
· rw [h, Function.update_same]
· rw [Function.update_noteq (Ne.symm h), Pi.zero_apply]
theorem range_vecMulLinear (M : Matrix m n R) :
LinearMap.range M.vecMulLinear = span R (range M) := by
letI := Classical.decEq m
simp_rw [range_eq_map, ← iSup_range_stdBasis, Submodule.map_iSup, range_eq_map, ←
Ideal.span_singleton_one, Ideal.span, Submodule.map_span, image_image, image_singleton,
Matrix.vecMulLinear_apply, iSup_span, range_eq_iUnion, iUnion_singleton_eq_range,
LinearMap.stdBasis, coe_single]
unfold vecMul
simp_rw [single_dotProduct, one_mul]
theorem Matrix.vecMul_injective_iff {R : Type*} [CommRing R] {M : Matrix m n R} :
Function.Injective M.vecMul ↔ LinearIndependent R (fun i ↦ M i) := by
rw [← coe_vecMulLinear]
simp only [← LinearMap.ker_eq_bot, Fintype.linearIndependent_iff, Submodule.eq_bot_iff,
LinearMap.mem_ker, vecMulLinear_apply]
refine ⟨fun h c h0 ↦ congr_fun <| h c ?_, fun h c h0 ↦ funext <| h c ?_⟩
· rw [← h0]
ext i
simp [vecMul, dotProduct]
· rw [← h0]
ext j
simp [vecMul, dotProduct]
section
variable [DecidableEq m]
/-- Linear maps `(m → R) →ₗ[R] (n → R)` are linearly equivalent over `Rᵐᵒᵖ` to `Matrix m n R`,
by having matrices act by right multiplication.
-/
def LinearMap.toMatrixRight' : ((m → R) →ₗ[R] n → R) ≃ₗ[Rᵐᵒᵖ] Matrix m n R where
toFun f i j := f (stdBasis R (fun _ ↦ R) i 1) j
invFun := Matrix.vecMulLinear
right_inv M := by
ext i j
simp only [Matrix.vecMul_stdBasis, Matrix.vecMulLinear_apply]
left_inv f := by
apply (Pi.basisFun R m).ext
intro j; ext i
simp only [Pi.basisFun_apply, Matrix.vecMul_stdBasis, Matrix.vecMulLinear_apply]
map_add' f g := by
ext i j
simp only [Pi.add_apply, LinearMap.add_apply, Matrix.add_apply]
map_smul' c f := by
ext i j
simp only [Pi.smul_apply, LinearMap.smul_apply, RingHom.id_apply, Matrix.smul_apply]
/-- A `Matrix m n R` is linearly equivalent over `Rᵐᵒᵖ` to a linear map `(m → R) →ₗ[R] (n → R)`,
by having matrices act by right multiplication. -/
abbrev Matrix.toLinearMapRight' [DecidableEq m] : Matrix m n R ≃ₗ[Rᵐᵒᵖ] (m → R) →ₗ[R] n → R :=
LinearEquiv.symm LinearMap.toMatrixRight'
@[simp]
theorem Matrix.toLinearMapRight'_apply (M : Matrix m n R) (v : m → R) :
(Matrix.toLinearMapRight') M v = v ᵥ* M := rfl
@[simp]
theorem Matrix.toLinearMapRight'_mul [Fintype l] [DecidableEq l] (M : Matrix l m R)
(N : Matrix m n R) :
Matrix.toLinearMapRight' (M * N) =
(Matrix.toLinearMapRight' N).comp (Matrix.toLinearMapRight' M) :=
LinearMap.ext fun _x ↦ (vecMul_vecMul _ M N).symm
theorem Matrix.toLinearMapRight'_mul_apply [Fintype l] [DecidableEq l] (M : Matrix l m R)
(N : Matrix m n R) (x) :
Matrix.toLinearMapRight' (M * N) x =
Matrix.toLinearMapRight' N (Matrix.toLinearMapRight' M x) :=
(vecMul_vecMul _ M N).symm
@[simp]
theorem Matrix.toLinearMapRight'_one :
Matrix.toLinearMapRight' (1 : Matrix m m R) = LinearMap.id := by
ext
simp [LinearMap.one_apply, stdBasis_apply]
/-- If `M` and `M'` are each other's inverse matrices, they provide an equivalence between `n → A`
and `m → A` corresponding to `M.vecMul` and `M'.vecMul`. -/
@[simps]
def Matrix.toLinearEquivRight'OfInv [Fintype n] [DecidableEq n] {M : Matrix m n R}
{M' : Matrix n m R} (hMM' : M * M' = 1) (hM'M : M' * M = 1) : (n → R) ≃ₗ[R] m → R :=
{ LinearMap.toMatrixRight'.symm M' with
toFun := Matrix.toLinearMapRight' M'
invFun := Matrix.toLinearMapRight' M
left_inv := fun x ↦ by
rw [← Matrix.toLinearMapRight'_mul_apply, hM'M, Matrix.toLinearMapRight'_one, id_apply]
right_inv := fun x ↦ by
dsimp only -- Porting note: needed due to non-flat structures
rw [← Matrix.toLinearMapRight'_mul_apply, hMM', Matrix.toLinearMapRight'_one, id_apply] }
end
end ToMatrixRight
/-!
From this point on, we only work with commutative rings,
and fail to distinguish between `Rᵐᵒᵖ` and `R`.
This should eventually be remedied.
-/
section mulVec
variable {R : Type*} [CommSemiring R]
variable {k l m n : Type*}
/-- `Matrix.mulVec M` is a linear map. -/
def Matrix.mulVecLin [Fintype n] (M : Matrix m n R) : (n → R) →ₗ[R] m → R where
toFun := M.mulVec
map_add' _ _ := funext fun _ ↦ dotProduct_add _ _ _
map_smul' _ _ := funext fun _ ↦ dotProduct_smul _ _ _
theorem Matrix.coe_mulVecLin [Fintype n] (M : Matrix m n R) :
(M.mulVecLin : _ → _) = M.mulVec := rfl
@[simp]
theorem Matrix.mulVecLin_apply [Fintype n] (M : Matrix m n R) (v : n → R) :
M.mulVecLin v = M *ᵥ v :=
rfl
@[simp]
theorem Matrix.mulVecLin_zero [Fintype n] : Matrix.mulVecLin (0 : Matrix m n R) = 0 :=
LinearMap.ext zero_mulVec
@[simp]
theorem Matrix.mulVecLin_add [Fintype n] (M N : Matrix m n R) :
(M + N).mulVecLin = M.mulVecLin + N.mulVecLin :=
LinearMap.ext fun _ ↦ add_mulVec _ _ _
@[simp] theorem Matrix.mulVecLin_transpose [Fintype m] (M : Matrix m n R) :
Mᵀ.mulVecLin = M.vecMulLinear := by
ext; simp [mulVec_transpose]
@[simp] theorem Matrix.vecMulLinear_transpose [Fintype n] (M : Matrix m n R) :
Mᵀ.vecMulLinear = M.mulVecLin := by
ext; simp [vecMul_transpose]
theorem Matrix.mulVecLin_submatrix [Fintype n] [Fintype l] (f₁ : m → k) (e₂ : n ≃ l)
(M : Matrix k l R) :
(M.submatrix f₁ e₂).mulVecLin = funLeft R R f₁ ∘ₗ M.mulVecLin ∘ₗ funLeft _ _ e₂.symm :=
LinearMap.ext fun _ ↦ submatrix_mulVec_equiv _ _ _ _
/-- A variant of `Matrix.mulVecLin_submatrix` that keeps around `LinearEquiv`s. -/
theorem Matrix.mulVecLin_reindex [Fintype n] [Fintype l] (e₁ : k ≃ m) (e₂ : l ≃ n)
(M : Matrix k l R) :
(reindex e₁ e₂ M).mulVecLin =
↑(LinearEquiv.funCongrLeft R R e₁.symm) ∘ₗ
M.mulVecLin ∘ₗ ↑(LinearEquiv.funCongrLeft R R e₂) :=
Matrix.mulVecLin_submatrix _ _ _
variable [Fintype n]
@[simp]
theorem Matrix.mulVecLin_one [DecidableEq n] :
Matrix.mulVecLin (1 : Matrix n n R) = LinearMap.id := by
ext; simp [Matrix.one_apply, Pi.single_apply]
@[simp]
theorem Matrix.mulVecLin_mul [Fintype m] (M : Matrix l m R) (N : Matrix m n R) :
Matrix.mulVecLin (M * N) = (Matrix.mulVecLin M).comp (Matrix.mulVecLin N) :=
LinearMap.ext fun _ ↦ (mulVec_mulVec _ _ _).symm
theorem Matrix.ker_mulVecLin_eq_bot_iff {M : Matrix m n R} :
(LinearMap.ker M.mulVecLin) = ⊥ ↔ ∀ v, M *ᵥ v = 0 → v = 0 := by
simp only [Submodule.eq_bot_iff, LinearMap.mem_ker, Matrix.mulVecLin_apply]
theorem Matrix.mulVec_stdBasis [DecidableEq n] (M : Matrix m n R) (i j) :
(M *ᵥ LinearMap.stdBasis R (fun _ ↦ R) j 1) i = M i j :=
(congr_fun (Matrix.mulVec_single _ _ (1 : R)) i).trans <| mul_one _
@[simp]
theorem Matrix.mulVec_stdBasis_apply [DecidableEq n] (M : Matrix m n R) (j) :
M *ᵥ LinearMap.stdBasis R (fun _ ↦ R) j 1 = Mᵀ j :=
funext fun i ↦ Matrix.mulVec_stdBasis M i j
theorem Matrix.range_mulVecLin (M : Matrix m n R) :
LinearMap.range M.mulVecLin = span R (range Mᵀ) := by
rw [← vecMulLinear_transpose, range_vecMulLinear]
theorem Matrix.mulVec_injective_iff {R : Type*} [CommRing R] {M : Matrix m n R} :
Function.Injective M.mulVec ↔ LinearIndependent R (fun i ↦ Mᵀ i) := by
change Function.Injective (fun x ↦ _) ↔ _
simp_rw [← M.vecMul_transpose, vecMul_injective_iff]
end mulVec
section ToMatrix'
variable {R : Type*} [CommSemiring R]
variable {k l m n : Type*} [DecidableEq n] [Fintype n]
/-- Linear maps `(n → R) →ₗ[R] (m → R)` are linearly equivalent to `Matrix m n R`. -/
def LinearMap.toMatrix' : ((n → R) →ₗ[R] m → R) ≃ₗ[R] Matrix m n R where
toFun f := of fun i j ↦ f (stdBasis R (fun _ ↦ R) j 1) i
invFun := Matrix.mulVecLin
right_inv M := by
ext i j
simp only [Matrix.mulVec_stdBasis, Matrix.mulVecLin_apply, of_apply]
left_inv f := by
apply (Pi.basisFun R n).ext
intro j; ext i
simp only [Pi.basisFun_apply, Matrix.mulVec_stdBasis, Matrix.mulVecLin_apply, of_apply]
map_add' f g := by
ext i j
simp only [Pi.add_apply, LinearMap.add_apply, of_apply, Matrix.add_apply]
map_smul' c f := by
ext i j
simp only [Pi.smul_apply, LinearMap.smul_apply, RingHom.id_apply, of_apply, Matrix.smul_apply]
/-- A `Matrix m n R` is linearly equivalent to a linear map `(n → R) →ₗ[R] (m → R)`.
Note that the forward-direction does not require `DecidableEq` and is `Matrix.vecMulLin`. -/
def Matrix.toLin' : Matrix m n R ≃ₗ[R] (n → R) →ₗ[R] m → R :=
LinearMap.toMatrix'.symm
theorem Matrix.toLin'_apply' (M : Matrix m n R) : Matrix.toLin' M = M.mulVecLin :=
rfl
@[simp]
theorem LinearMap.toMatrix'_symm :
(LinearMap.toMatrix'.symm : Matrix m n R ≃ₗ[R] _) = Matrix.toLin' :=
rfl
@[simp]
theorem Matrix.toLin'_symm :
(Matrix.toLin'.symm : ((n → R) →ₗ[R] m → R) ≃ₗ[R] _) = LinearMap.toMatrix' :=
rfl
@[simp]
theorem LinearMap.toMatrix'_toLin' (M : Matrix m n R) : LinearMap.toMatrix' (Matrix.toLin' M) = M :=
LinearMap.toMatrix'.apply_symm_apply M
@[simp]
theorem Matrix.toLin'_toMatrix' (f : (n → R) →ₗ[R] m → R) :
Matrix.toLin' (LinearMap.toMatrix' f) = f :=
Matrix.toLin'.apply_symm_apply f
@[simp]
theorem LinearMap.toMatrix'_apply (f : (n → R) →ₗ[R] m → R) (i j) :
LinearMap.toMatrix' f i j = f (fun j' ↦ if j' = j then 1 else 0) i := by
simp only [LinearMap.toMatrix', LinearEquiv.coe_mk, of_apply]
refine congr_fun ?_ _ -- Porting note: `congr` didn't do this
congr
ext j'
split_ifs with h
· rw [h, stdBasis_same]
apply stdBasis_ne _ _ _ _ h
@[simp]
theorem Matrix.toLin'_apply (M : Matrix m n R) (v : n → R) : Matrix.toLin' M v = M *ᵥ v :=
rfl
@[simp]
theorem Matrix.toLin'_one : Matrix.toLin' (1 : Matrix n n R) = LinearMap.id :=
Matrix.mulVecLin_one
@[simp]
theorem LinearMap.toMatrix'_id : LinearMap.toMatrix' (LinearMap.id : (n → R) →ₗ[R] n → R) = 1 := by
ext
rw [Matrix.one_apply, LinearMap.toMatrix'_apply, id_apply]
@[simp]
theorem LinearMap.toMatrix'_one : LinearMap.toMatrix' (1 : (n → R) →ₗ[R] n → R) = 1 :=
LinearMap.toMatrix'_id
@[simp]
theorem Matrix.toLin'_mul [Fintype m] [DecidableEq m] (M : Matrix l m R) (N : Matrix m n R) :
Matrix.toLin' (M * N) = (Matrix.toLin' M).comp (Matrix.toLin' N) :=
Matrix.mulVecLin_mul _ _
@[simp]
theorem Matrix.toLin'_submatrix [Fintype l] [DecidableEq l] (f₁ : m → k) (e₂ : n ≃ l)
(M : Matrix k l R) :
Matrix.toLin' (M.submatrix f₁ e₂) =
funLeft R R f₁ ∘ₗ (Matrix.toLin' M) ∘ₗ funLeft _ _ e₂.symm :=
Matrix.mulVecLin_submatrix _ _ _
/-- A variant of `Matrix.toLin'_submatrix` that keeps around `LinearEquiv`s. -/
theorem Matrix.toLin'_reindex [Fintype l] [DecidableEq l] (e₁ : k ≃ m) (e₂ : l ≃ n)
(M : Matrix k l R) :
Matrix.toLin' (reindex e₁ e₂ M) =
↑(LinearEquiv.funCongrLeft R R e₁.symm) ∘ₗ (Matrix.toLin' M) ∘ₗ
↑(LinearEquiv.funCongrLeft R R e₂) :=
Matrix.mulVecLin_reindex _ _ _
/-- Shortcut lemma for `Matrix.toLin'_mul` and `LinearMap.comp_apply` -/
theorem Matrix.toLin'_mul_apply [Fintype m] [DecidableEq m] (M : Matrix l m R) (N : Matrix m n R)
(x) : Matrix.toLin' (M * N) x = Matrix.toLin' M (Matrix.toLin' N x) := by
rw [Matrix.toLin'_mul, LinearMap.comp_apply]
theorem LinearMap.toMatrix'_comp [Fintype l] [DecidableEq l] (f : (n → R) →ₗ[R] m → R)
(g : (l → R) →ₗ[R] n → R) :
LinearMap.toMatrix' (f.comp g) = LinearMap.toMatrix' f * LinearMap.toMatrix' g := by
suffices f.comp g = Matrix.toLin' (LinearMap.toMatrix' f * LinearMap.toMatrix' g) by
rw [this, LinearMap.toMatrix'_toLin']
rw [Matrix.toLin'_mul, Matrix.toLin'_toMatrix', Matrix.toLin'_toMatrix']
theorem LinearMap.toMatrix'_mul [Fintype m] [DecidableEq m] (f g : (m → R) →ₗ[R] m → R) :
LinearMap.toMatrix' (f * g) = LinearMap.toMatrix' f * LinearMap.toMatrix' g :=
LinearMap.toMatrix'_comp f g
@[simp]
theorem LinearMap.toMatrix'_algebraMap (x : R) :
LinearMap.toMatrix' (algebraMap R (Module.End R (n → R)) x) = scalar n x := by
simp [Module.algebraMap_end_eq_smul_id, smul_eq_diagonal_mul]
theorem Matrix.ker_toLin'_eq_bot_iff {M : Matrix n n R} :
LinearMap.ker (Matrix.toLin' M) = ⊥ ↔ ∀ v, M *ᵥ v = 0 → v = 0 :=
Matrix.ker_mulVecLin_eq_bot_iff
theorem Matrix.range_toLin' (M : Matrix m n R) :
LinearMap.range (Matrix.toLin' M) = span R (range Mᵀ) :=
Matrix.range_mulVecLin _
/-- If `M` and `M'` are each other's inverse matrices, they provide an equivalence between `m → A`
and `n → A` corresponding to `M.mulVec` and `M'.mulVec`. -/
@[simps]
def Matrix.toLin'OfInv [Fintype m] [DecidableEq m] {M : Matrix m n R} {M' : Matrix n m R}
(hMM' : M * M' = 1) (hM'M : M' * M = 1) : (m → R) ≃ₗ[R] n → R :=
{ Matrix.toLin' M' with
toFun := Matrix.toLin' M'
invFun := Matrix.toLin' M
left_inv := fun x ↦ by rw [← Matrix.toLin'_mul_apply, hMM', Matrix.toLin'_one, id_apply]
right_inv := fun x ↦ by
simp only
rw [← Matrix.toLin'_mul_apply, hM'M, Matrix.toLin'_one, id_apply] }
/-- Linear maps `(n → R) →ₗ[R] (n → R)` are algebra equivalent to `Matrix n n R`. -/
def LinearMap.toMatrixAlgEquiv' : ((n → R) →ₗ[R] n → R) ≃ₐ[R] Matrix n n R :=
AlgEquiv.ofLinearEquiv LinearMap.toMatrix' LinearMap.toMatrix'_one LinearMap.toMatrix'_mul
/-- A `Matrix n n R` is algebra equivalent to a linear map `(n → R) →ₗ[R] (n → R)`. -/
def Matrix.toLinAlgEquiv' : Matrix n n R ≃ₐ[R] (n → R) →ₗ[R] n → R :=
LinearMap.toMatrixAlgEquiv'.symm
@[simp]
theorem LinearMap.toMatrixAlgEquiv'_symm :
(LinearMap.toMatrixAlgEquiv'.symm : Matrix n n R ≃ₐ[R] _) = Matrix.toLinAlgEquiv' :=
rfl
@[simp]
theorem Matrix.toLinAlgEquiv'_symm :
(Matrix.toLinAlgEquiv'.symm : ((n → R) →ₗ[R] n → R) ≃ₐ[R] _) = LinearMap.toMatrixAlgEquiv' :=
rfl
@[simp]
theorem LinearMap.toMatrixAlgEquiv'_toLinAlgEquiv' (M : Matrix n n R) :
LinearMap.toMatrixAlgEquiv' (Matrix.toLinAlgEquiv' M) = M :=
LinearMap.toMatrixAlgEquiv'.apply_symm_apply M
@[simp]
theorem Matrix.toLinAlgEquiv'_toMatrixAlgEquiv' (f : (n → R) →ₗ[R] n → R) :
Matrix.toLinAlgEquiv' (LinearMap.toMatrixAlgEquiv' f) = f :=
Matrix.toLinAlgEquiv'.apply_symm_apply f
@[simp]
theorem LinearMap.toMatrixAlgEquiv'_apply (f : (n → R) →ₗ[R] n → R) (i j) :
LinearMap.toMatrixAlgEquiv' f i j = f (fun j' ↦ if j' = j then 1 else 0) i := by
simp [LinearMap.toMatrixAlgEquiv']
@[simp]
theorem Matrix.toLinAlgEquiv'_apply (M : Matrix n n R) (v : n → R) :
Matrix.toLinAlgEquiv' M v = M *ᵥ v :=
rfl
-- Porting note: the simpNF linter rejects this, as `simp` already simplifies the lhs
-- to `(1 : (n → R) →ₗ[R] n → R)`.
-- @[simp]
theorem Matrix.toLinAlgEquiv'_one : Matrix.toLinAlgEquiv' (1 : Matrix n n R) = LinearMap.id :=
Matrix.toLin'_one
@[simp]
theorem LinearMap.toMatrixAlgEquiv'_id :
LinearMap.toMatrixAlgEquiv' (LinearMap.id : (n → R) →ₗ[R] n → R) = 1 :=
LinearMap.toMatrix'_id
theorem LinearMap.toMatrixAlgEquiv'_comp (f g : (n → R) →ₗ[R] n → R) :
LinearMap.toMatrixAlgEquiv' (f.comp g) =
LinearMap.toMatrixAlgEquiv' f * LinearMap.toMatrixAlgEquiv' g :=
LinearMap.toMatrix'_comp _ _
theorem LinearMap.toMatrixAlgEquiv'_mul (f g : (n → R) →ₗ[R] n → R) :
LinearMap.toMatrixAlgEquiv' (f * g) =
LinearMap.toMatrixAlgEquiv' f * LinearMap.toMatrixAlgEquiv' g :=
LinearMap.toMatrixAlgEquiv'_comp f g
end ToMatrix'
section ToMatrix
section Finite
variable {R : Type*} [CommSemiring R]
variable {l m n : Type*} [Fintype n] [Finite m] [DecidableEq n]
variable {M₁ M₂ : Type*} [AddCommMonoid M₁] [AddCommMonoid M₂] [Module R M₁] [Module R M₂]
variable (v₁ : Basis n R M₁) (v₂ : Basis m R M₂)
/-- Given bases of two modules `M₁` and `M₂` over a commutative ring `R`, we get a linear
equivalence between linear maps `M₁ →ₗ M₂` and matrices over `R` indexed by the bases. -/
def LinearMap.toMatrix : (M₁ →ₗ[R] M₂) ≃ₗ[R] Matrix m n R :=
LinearEquiv.trans (LinearEquiv.arrowCongr v₁.equivFun v₂.equivFun) LinearMap.toMatrix'
/-- `LinearMap.toMatrix'` is a particular case of `LinearMap.toMatrix`, for the standard basis
`Pi.basisFun R n`. -/
theorem LinearMap.toMatrix_eq_toMatrix' :
LinearMap.toMatrix (Pi.basisFun R n) (Pi.basisFun R n) = LinearMap.toMatrix' :=
rfl
/-- Given bases of two modules `M₁` and `M₂` over a commutative ring `R`, we get a linear
equivalence between matrices over `R` indexed by the bases and linear maps `M₁ →ₗ M₂`. -/
def Matrix.toLin : Matrix m n R ≃ₗ[R] M₁ →ₗ[R] M₂ :=
(LinearMap.toMatrix v₁ v₂).symm
/-- `Matrix.toLin'` is a particular case of `Matrix.toLin`, for the standard basis
`Pi.basisFun R n`. -/
theorem Matrix.toLin_eq_toLin' : Matrix.toLin (Pi.basisFun R n) (Pi.basisFun R m) = Matrix.toLin' :=
rfl
@[simp]
theorem LinearMap.toMatrix_symm : (LinearMap.toMatrix v₁ v₂).symm = Matrix.toLin v₁ v₂ :=
rfl
@[simp]
theorem Matrix.toLin_symm : (Matrix.toLin v₁ v₂).symm = LinearMap.toMatrix v₁ v₂ :=
rfl
@[simp]
theorem Matrix.toLin_toMatrix (f : M₁ →ₗ[R] M₂) :
Matrix.toLin v₁ v₂ (LinearMap.toMatrix v₁ v₂ f) = f := by
rw [← Matrix.toLin_symm, LinearEquiv.apply_symm_apply]
@[simp]
theorem LinearMap.toMatrix_toLin (M : Matrix m n R) :
LinearMap.toMatrix v₁ v₂ (Matrix.toLin v₁ v₂ M) = M := by
rw [← Matrix.toLin_symm, LinearEquiv.symm_apply_apply]
theorem LinearMap.toMatrix_apply (f : M₁ →ₗ[R] M₂) (i : m) (j : n) :
LinearMap.toMatrix v₁ v₂ f i j = v₂.repr (f (v₁ j)) i := by
rw [LinearMap.toMatrix, LinearEquiv.trans_apply, LinearMap.toMatrix'_apply,
LinearEquiv.arrowCongr_apply, Basis.equivFun_symm_apply, Finset.sum_eq_single j, if_pos rfl,
one_smul, Basis.equivFun_apply]
· intro j' _ hj'
rw [if_neg hj', zero_smul]
· intro hj
have := Finset.mem_univ j
contradiction
theorem LinearMap.toMatrix_transpose_apply (f : M₁ →ₗ[R] M₂) (j : n) :
(LinearMap.toMatrix v₁ v₂ f)ᵀ j = v₂.repr (f (v₁ j)) :=
funext fun i ↦ f.toMatrix_apply _ _ i j
theorem LinearMap.toMatrix_apply' (f : M₁ →ₗ[R] M₂) (i : m) (j : n) :
LinearMap.toMatrix v₁ v₂ f i j = v₂.repr (f (v₁ j)) i :=
LinearMap.toMatrix_apply v₁ v₂ f i j
theorem LinearMap.toMatrix_transpose_apply' (f : M₁ →ₗ[R] M₂) (j : n) :
(LinearMap.toMatrix v₁ v₂ f)ᵀ j = v₂.repr (f (v₁ j)) :=
LinearMap.toMatrix_transpose_apply v₁ v₂ f j
/-- This will be a special case of `LinearMap.toMatrix_id_eq_basis_toMatrix`. -/
theorem LinearMap.toMatrix_id : LinearMap.toMatrix v₁ v₁ id = 1 := by
ext i j
simp [LinearMap.toMatrix_apply, Matrix.one_apply, Finsupp.single_apply, eq_comm]
@[simp]
theorem LinearMap.toMatrix_one : LinearMap.toMatrix v₁ v₁ 1 = 1 :=
LinearMap.toMatrix_id v₁
@[simp]
theorem Matrix.toLin_one : Matrix.toLin v₁ v₁ 1 = LinearMap.id := by
rw [← LinearMap.toMatrix_id v₁, Matrix.toLin_toMatrix]
theorem LinearMap.toMatrix_reindexRange [DecidableEq M₁] (f : M₁ →ₗ[R] M₂) (k : m) (i : n) :
LinearMap.toMatrix v₁.reindexRange v₂.reindexRange f ⟨v₂ k, Set.mem_range_self k⟩
⟨v₁ i, Set.mem_range_self i⟩ =
LinearMap.toMatrix v₁ v₂ f k i := by
simp_rw [LinearMap.toMatrix_apply, Basis.reindexRange_self, Basis.reindexRange_repr]
@[simp]
theorem LinearMap.toMatrix_algebraMap (x : R) :
LinearMap.toMatrix v₁ v₁ (algebraMap R (Module.End R M₁) x) = scalar n x := by
simp [Module.algebraMap_end_eq_smul_id, LinearMap.toMatrix_id, smul_eq_diagonal_mul]
theorem LinearMap.toMatrix_mulVec_repr (f : M₁ →ₗ[R] M₂) (x : M₁) :
LinearMap.toMatrix v₁ v₂ f *ᵥ v₁.repr x = v₂.repr (f x) := by
ext i
rw [← Matrix.toLin'_apply, LinearMap.toMatrix, LinearEquiv.trans_apply, Matrix.toLin'_toMatrix',
LinearEquiv.arrowCongr_apply, v₂.equivFun_apply]
congr
exact v₁.equivFun.symm_apply_apply x
@[simp]
theorem LinearMap.toMatrix_basis_equiv [Fintype l] [DecidableEq l] (b : Basis l R M₁)
(b' : Basis l R M₂) :
LinearMap.toMatrix b' b (b'.equiv b (Equiv.refl l) : M₂ →ₗ[R] M₁) = 1 := by
ext i j
simp [LinearMap.toMatrix_apply, Matrix.one_apply, Finsupp.single_apply, eq_comm]
theorem LinearMap.toMatrix_smulBasis_left {G} [Group G] [DistribMulAction G M₁]
[SMulCommClass G R M₁] (g : G) (f : M₁ →ₗ[R] M₂) :
LinearMap.toMatrix (g • v₁) v₂ f =
LinearMap.toMatrix v₁ v₂ (f ∘ₗ DistribMulAction.toLinearMap _ _ g) := by
ext
rw [LinearMap.toMatrix_apply, LinearMap.toMatrix_apply]
dsimp
theorem LinearMap.toMatrix_smulBasis_right {G} [Group G] [DistribMulAction G M₂]
[SMulCommClass G R M₂] (g : G) (f : M₁ →ₗ[R] M₂) :
LinearMap.toMatrix v₁ (g • v₂) f =
LinearMap.toMatrix v₁ v₂ (DistribMulAction.toLinearMap _ _ g⁻¹ ∘ₗ f) := by
ext
rw [LinearMap.toMatrix_apply, LinearMap.toMatrix_apply]
dsimp
end Finite
variable {R : Type*} [CommSemiring R]
variable {l m n : Type*} [Fintype n] [Fintype m] [DecidableEq n]
variable {M₁ M₂ : Type*} [AddCommMonoid M₁] [AddCommMonoid M₂] [Module R M₁] [Module R M₂]
variable (v₁ : Basis n R M₁) (v₂ : Basis m R M₂)
theorem Matrix.toLin_apply (M : Matrix m n R) (v : M₁) :
Matrix.toLin v₁ v₂ M v = ∑ j, (M *ᵥ v₁.repr v) j • v₂ j :=
show v₂.equivFun.symm (Matrix.toLin' M (v₁.repr v)) = _ by
rw [Matrix.toLin'_apply, v₂.equivFun_symm_apply]
@[simp]
theorem Matrix.toLin_self (M : Matrix m n R) (i : n) :
Matrix.toLin v₁ v₂ M (v₁ i) = ∑ j, M j i • v₂ j := by
rw [Matrix.toLin_apply, Finset.sum_congr rfl fun j _hj ↦ ?_]
rw [Basis.repr_self, Matrix.mulVec, dotProduct, Finset.sum_eq_single i, Finsupp.single_eq_same,
mul_one]
· intro i' _ i'_ne
rw [Finsupp.single_eq_of_ne i'_ne.symm, mul_zero]
· intros
have := Finset.mem_univ i
contradiction
variable {M₃ : Type*} [AddCommMonoid M₃] [Module R M₃] (v₃ : Basis l R M₃)
theorem LinearMap.toMatrix_comp [Finite l] [DecidableEq m] (f : M₂ →ₗ[R] M₃) (g : M₁ →ₗ[R] M₂) :
LinearMap.toMatrix v₁ v₃ (f.comp g) =
LinearMap.toMatrix v₂ v₃ f * LinearMap.toMatrix v₁ v₂ g := by
simp_rw [LinearMap.toMatrix, LinearEquiv.trans_apply, LinearEquiv.arrowCongr_comp _ v₂.equivFun,
LinearMap.toMatrix'_comp]
theorem LinearMap.toMatrix_mul (f g : M₁ →ₗ[R] M₁) :
LinearMap.toMatrix v₁ v₁ (f * g) = LinearMap.toMatrix v₁ v₁ f * LinearMap.toMatrix v₁ v₁ g := by
rw [LinearMap.mul_eq_comp, LinearMap.toMatrix_comp v₁ v₁ v₁ f g]
lemma LinearMap.toMatrix_pow (f : M₁ →ₗ[R] M₁) (k : ℕ) :
(toMatrix v₁ v₁ f) ^ k = toMatrix v₁ v₁ (f ^ k) := by
induction k with
| zero => simp
| succ k ih => rw [pow_succ, pow_succ, ih, ← toMatrix_mul]
theorem Matrix.toLin_mul [Finite l] [DecidableEq m] (A : Matrix l m R) (B : Matrix m n R) :
Matrix.toLin v₁ v₃ (A * B) = (Matrix.toLin v₂ v₃ A).comp (Matrix.toLin v₁ v₂ B) := by
apply (LinearMap.toMatrix v₁ v₃).injective
haveI : DecidableEq l := fun _ _ ↦ Classical.propDecidable _
rw [LinearMap.toMatrix_comp v₁ v₂ v₃]
repeat' rw [LinearMap.toMatrix_toLin]
/-- Shortcut lemma for `Matrix.toLin_mul` and `LinearMap.comp_apply`. -/
theorem Matrix.toLin_mul_apply [Finite l] [DecidableEq m] (A : Matrix l m R) (B : Matrix m n R)
(x) : Matrix.toLin v₁ v₃ (A * B) x = (Matrix.toLin v₂ v₃ A) (Matrix.toLin v₁ v₂ B x) := by
rw [Matrix.toLin_mul v₁ v₂, LinearMap.comp_apply]
/-- If `M` and `M` are each other's inverse matrices, `Matrix.toLin M` and `Matrix.toLin M'`
form a linear equivalence. -/
@[simps]
def Matrix.toLinOfInv [DecidableEq m] {M : Matrix m n R} {M' : Matrix n m R} (hMM' : M * M' = 1)
(hM'M : M' * M = 1) : M₁ ≃ₗ[R] M₂ :=
{ Matrix.toLin v₁ v₂ M with
toFun := Matrix.toLin v₁ v₂ M
invFun := Matrix.toLin v₂ v₁ M'
left_inv := fun x ↦ by rw [← Matrix.toLin_mul_apply, hM'M, Matrix.toLin_one, id_apply]
right_inv := fun x ↦ by
simp only
rw [← Matrix.toLin_mul_apply, hMM', Matrix.toLin_one, id_apply] }
/-- Given a basis of a module `M₁` over a commutative ring `R`, we get an algebra
equivalence between linear maps `M₁ →ₗ M₁` and square matrices over `R` indexed by the basis. -/
def LinearMap.toMatrixAlgEquiv : (M₁ →ₗ[R] M₁) ≃ₐ[R] Matrix n n R :=
AlgEquiv.ofLinearEquiv
(LinearMap.toMatrix v₁ v₁) (LinearMap.toMatrix_one v₁) (LinearMap.toMatrix_mul v₁)
/-- Given a basis of a module `M₁` over a commutative ring `R`, we get an algebra
equivalence between square matrices over `R` indexed by the basis and linear maps `M₁ →ₗ M₁`. -/
def Matrix.toLinAlgEquiv : Matrix n n R ≃ₐ[R] M₁ →ₗ[R] M₁ :=
(LinearMap.toMatrixAlgEquiv v₁).symm
@[simp]
theorem LinearMap.toMatrixAlgEquiv_symm :
(LinearMap.toMatrixAlgEquiv v₁).symm = Matrix.toLinAlgEquiv v₁ :=
rfl
@[simp]
theorem Matrix.toLinAlgEquiv_symm :
(Matrix.toLinAlgEquiv v₁).symm = LinearMap.toMatrixAlgEquiv v₁ :=
rfl
@[simp]
theorem Matrix.toLinAlgEquiv_toMatrixAlgEquiv (f : M₁ →ₗ[R] M₁) :
Matrix.toLinAlgEquiv v₁ (LinearMap.toMatrixAlgEquiv v₁ f) = f := by
rw [← Matrix.toLinAlgEquiv_symm, AlgEquiv.apply_symm_apply]
@[simp]
theorem LinearMap.toMatrixAlgEquiv_toLinAlgEquiv (M : Matrix n n R) :
LinearMap.toMatrixAlgEquiv v₁ (Matrix.toLinAlgEquiv v₁ M) = M := by
rw [← Matrix.toLinAlgEquiv_symm, AlgEquiv.symm_apply_apply]
theorem LinearMap.toMatrixAlgEquiv_apply (f : M₁ →ₗ[R] M₁) (i j : n) :
LinearMap.toMatrixAlgEquiv v₁ f i j = v₁.repr (f (v₁ j)) i := by
simp [LinearMap.toMatrixAlgEquiv, LinearMap.toMatrix_apply]
theorem LinearMap.toMatrixAlgEquiv_transpose_apply (f : M₁ →ₗ[R] M₁) (j : n) :
(LinearMap.toMatrixAlgEquiv v₁ f)ᵀ j = v₁.repr (f (v₁ j)) :=
funext fun i ↦ f.toMatrix_apply _ _ i j
theorem LinearMap.toMatrixAlgEquiv_apply' (f : M₁ →ₗ[R] M₁) (i j : n) :
LinearMap.toMatrixAlgEquiv v₁ f i j = v₁.repr (f (v₁ j)) i :=
LinearMap.toMatrixAlgEquiv_apply v₁ f i j
theorem LinearMap.toMatrixAlgEquiv_transpose_apply' (f : M₁ →ₗ[R] M₁) (j : n) :
(LinearMap.toMatrixAlgEquiv v₁ f)ᵀ j = v₁.repr (f (v₁ j)) :=
LinearMap.toMatrixAlgEquiv_transpose_apply v₁ f j
theorem Matrix.toLinAlgEquiv_apply (M : Matrix n n R) (v : M₁) :
Matrix.toLinAlgEquiv v₁ M v = ∑ j, (M *ᵥ v₁.repr v) j • v₁ j :=
show v₁.equivFun.symm (Matrix.toLinAlgEquiv' M (v₁.repr v)) = _ by
rw [Matrix.toLinAlgEquiv'_apply, v₁.equivFun_symm_apply]
@[simp]
theorem Matrix.toLinAlgEquiv_self (M : Matrix n n R) (i : n) :
Matrix.toLinAlgEquiv v₁ M (v₁ i) = ∑ j, M j i • v₁ j :=
Matrix.toLin_self _ _ _ _
theorem LinearMap.toMatrixAlgEquiv_id : LinearMap.toMatrixAlgEquiv v₁ id = 1 := by
simp_rw [LinearMap.toMatrixAlgEquiv, AlgEquiv.ofLinearEquiv_apply, LinearMap.toMatrix_id]
-- Porting note: the simpNF linter rejects this, as `simp` already simplifies the lhs
-- to `(1 : M₁ →ₗ[R] M₁)`.
-- @[simp]
theorem Matrix.toLinAlgEquiv_one : Matrix.toLinAlgEquiv v₁ 1 = LinearMap.id := by
rw [← LinearMap.toMatrixAlgEquiv_id v₁, Matrix.toLinAlgEquiv_toMatrixAlgEquiv]
theorem LinearMap.toMatrixAlgEquiv_reindexRange [DecidableEq M₁] (f : M₁ →ₗ[R] M₁) (k i : n) :
LinearMap.toMatrixAlgEquiv v₁.reindexRange f
⟨v₁ k, Set.mem_range_self k⟩ ⟨v₁ i, Set.mem_range_self i⟩ =
LinearMap.toMatrixAlgEquiv v₁ f k i := by
simp_rw [LinearMap.toMatrixAlgEquiv_apply, Basis.reindexRange_self, Basis.reindexRange_repr]
theorem LinearMap.toMatrixAlgEquiv_comp (f g : M₁ →ₗ[R] M₁) :
LinearMap.toMatrixAlgEquiv v₁ (f.comp g) =
LinearMap.toMatrixAlgEquiv v₁ f * LinearMap.toMatrixAlgEquiv v₁ g := by
simp [LinearMap.toMatrixAlgEquiv, LinearMap.toMatrix_comp v₁ v₁ v₁ f g]
theorem LinearMap.toMatrixAlgEquiv_mul (f g : M₁ →ₗ[R] M₁) :
LinearMap.toMatrixAlgEquiv v₁ (f * g) =
LinearMap.toMatrixAlgEquiv v₁ f * LinearMap.toMatrixAlgEquiv v₁ g := by
rw [LinearMap.mul_eq_comp, LinearMap.toMatrixAlgEquiv_comp v₁ f g]
theorem Matrix.toLinAlgEquiv_mul (A B : Matrix n n R) :
Matrix.toLinAlgEquiv v₁ (A * B) =
(Matrix.toLinAlgEquiv v₁ A).comp (Matrix.toLinAlgEquiv v₁ B) := by
convert Matrix.toLin_mul v₁ v₁ v₁ A B
@[simp]
theorem Matrix.toLin_finTwoProd_apply (a b c d : R) (x : R × R) :
Matrix.toLin (Basis.finTwoProd R) (Basis.finTwoProd R) !![a, b; c, d] x =
(a * x.fst + b * x.snd, c * x.fst + d * x.snd) := by
simp [Matrix.toLin_apply, Matrix.mulVec, Matrix.dotProduct]
theorem Matrix.toLin_finTwoProd (a b c d : R) :
Matrix.toLin (Basis.finTwoProd R) (Basis.finTwoProd R) !![a, b; c, d] =
(a • LinearMap.fst R R R + b • LinearMap.snd R R R).prod
(c • LinearMap.fst R R R + d • LinearMap.snd R R R) :=
LinearMap.ext <| Matrix.toLin_finTwoProd_apply _ _ _ _
@[simp]
theorem toMatrix_distrib_mul_action_toLinearMap (x : R) :
LinearMap.toMatrix v₁ v₁ (DistribMulAction.toLinearMap R M₁ x) =
Matrix.diagonal fun _ ↦ x := by
ext
rw [LinearMap.toMatrix_apply, DistribMulAction.toLinearMap_apply, LinearEquiv.map_smul,
Basis.repr_self, Finsupp.smul_single_one, Finsupp.single_eq_pi_single, Matrix.diagonal_apply,
Pi.single_apply]
lemma LinearMap.toMatrix_prodMap [DecidableEq m] [DecidableEq (n ⊕ m)]
(φ₁ : Module.End R M₁) (φ₂ : Module.End R M₂) :
toMatrix (v₁.prod v₂) (v₁.prod v₂) (φ₁.prodMap φ₂) =
Matrix.fromBlocks (toMatrix v₁ v₁ φ₁) 0 0 (toMatrix v₂ v₂ φ₂) := by
ext (i|i) (j|j) <;> simp [toMatrix]
end ToMatrix
namespace Algebra
section Lmul
variable {R S : Type*} [CommRing R] [Ring S] [Algebra R S]
variable {m : Type*} [Fintype m] [DecidableEq m] (b : Basis m R S)
theorem toMatrix_lmul' (x : S) (i j) :
LinearMap.toMatrix b b (lmul R S x) i j = b.repr (x * b j) i := by
simp only [LinearMap.toMatrix_apply', coe_lmul_eq_mul, LinearMap.mul_apply']
@[simp]
theorem toMatrix_lsmul (x : R) :
LinearMap.toMatrix b b (Algebra.lsmul R R S x) = Matrix.diagonal fun _ ↦ x :=
toMatrix_distrib_mul_action_toLinearMap b x
/-- `leftMulMatrix b x` is the matrix corresponding to the linear map `fun y ↦ x * y`.
`leftMulMatrix_eq_repr_mul` gives a formula for the entries of `leftMulMatrix`.
This definition is useful for doing (more) explicit computations with `LinearMap.mulLeft`,
such as the trace form or norm map for algebras.
-/
noncomputable def leftMulMatrix : S →ₐ[R] Matrix m m R where
toFun x := LinearMap.toMatrix b b (Algebra.lmul R S x)
map_zero' := by
dsimp only -- porting node: needed due to new-style structures
rw [_root_.map_zero, LinearEquiv.map_zero]
map_one' := by
dsimp only -- porting node: needed due to new-style structures
rw [_root_.map_one, LinearMap.toMatrix_one]
map_add' x y := by
dsimp only -- porting node: needed due to new-style structures
rw [map_add, LinearEquiv.map_add]
map_mul' x y := by
dsimp only -- porting node: needed due to new-style structures
rw [_root_.map_mul, LinearMap.toMatrix_mul]
commutes' r := by
dsimp only -- porting node: needed due to new-style structures
ext
rw [lmul_algebraMap, toMatrix_lsmul, algebraMap_eq_diagonal, Pi.algebraMap_def,
Algebra.id.map_eq_self]
theorem leftMulMatrix_apply (x : S) : leftMulMatrix b x = LinearMap.toMatrix b b (lmul R S x) :=
rfl
theorem leftMulMatrix_eq_repr_mul (x : S) (i j) : leftMulMatrix b x i j = b.repr (x * b j) i := by
-- This is defeq to just `toMatrix_lmul' b x i j`,
-- but the unfolding goes a lot faster with this explicit `rw`.
rw [leftMulMatrix_apply, toMatrix_lmul' b x i j]
theorem leftMulMatrix_mulVec_repr (x y : S) :
leftMulMatrix b x *ᵥ b.repr y = b.repr (x * y) :=
(LinearMap.mulLeft R x).toMatrix_mulVec_repr b b y
@[simp]
theorem toMatrix_lmul_eq (x : S) :
LinearMap.toMatrix b b (LinearMap.mulLeft R x) = leftMulMatrix b x :=
rfl
theorem leftMulMatrix_injective : Function.Injective (leftMulMatrix b) := fun x x' h ↦
calc
x = Algebra.lmul R S x 1 := (mul_one x).symm
_ = Algebra.lmul R S x' 1 := by rw [(LinearMap.toMatrix b b).injective h]
_ = x' := mul_one x'
@[simp]
theorem smul_leftMulMatrix {G} [Group G] [DistribMulAction G S]
[SMulCommClass G R S] [SMulCommClass G S S] (g : G) (x) :
leftMulMatrix (g • b) x = leftMulMatrix b x := by
ext
simp_rw [leftMulMatrix_apply, LinearMap.toMatrix_apply, coe_lmul_eq_mul, LinearMap.mul_apply',
Basis.repr_smul, Basis.smul_apply, LinearEquiv.trans_apply,
DistribMulAction.toLinearEquiv_symm_apply, mul_smul_comm, inv_smul_smul]
end Lmul
section LmulTower
variable {R S T : Type*} [CommRing R] [CommRing S] [Ring T]
variable [Algebra R S] [Algebra S T] [Algebra R T] [IsScalarTower R S T]
variable {m n : Type*} [Fintype m] [Fintype n] [DecidableEq m] [DecidableEq n]
variable (b : Basis m R S) (c : Basis n S T)
theorem smulTower_leftMulMatrix (x) (ik jk) :
leftMulMatrix (b.smulTower c) x ik jk =
leftMulMatrix b (leftMulMatrix c x ik.2 jk.2) ik.1 jk.1 := by
simp only [leftMulMatrix_apply, LinearMap.toMatrix_apply, mul_comm, Basis.smulTower_apply,
Basis.smulTower_repr, Finsupp.smul_apply, id.smul_eq_mul, LinearEquiv.map_smul, mul_smul_comm,
coe_lmul_eq_mul, LinearMap.mul_apply']
theorem smulTower_leftMulMatrix_algebraMap (x : S) :
leftMulMatrix (b.smulTower c) (algebraMap _ _ x) = blockDiagonal fun _ ↦ leftMulMatrix b x := by
ext ⟨i, k⟩ ⟨j, k'⟩
rw [smulTower_leftMulMatrix, AlgHom.commutes, blockDiagonal_apply, algebraMap_matrix_apply]
split_ifs with h <;> simp only at h <;> simp [h]
theorem smulTower_leftMulMatrix_algebraMap_eq (x : S) (i j k) :
leftMulMatrix (b.smulTower c) (algebraMap _ _ x) (i, k) (j, k) = leftMulMatrix b x i j := by
rw [smulTower_leftMulMatrix_algebraMap, blockDiagonal_apply_eq]
theorem smulTower_leftMulMatrix_algebraMap_ne (x : S) (i j) {k k'} (h : k ≠ k') :
leftMulMatrix (b.smulTower c) (algebraMap _ _ x) (i, k) (j, k') = 0 := by
rw [smulTower_leftMulMatrix_algebraMap, blockDiagonal_apply_ne _ _ _ h]
end LmulTower
end Algebra
section
variable {R : Type*} [CommRing R] {n : Type*} [DecidableEq n]
variable {M M₁ M₂ : Type*} [AddCommGroup M] [Module R M]
variable [AddCommGroup M₁] [Module R M₁] [AddCommGroup M₂] [Module R M₂]
/-- The natural equivalence between linear endomorphisms of finite free modules and square matrices
is compatible with the algebra structures. -/
def algEquivMatrix' [Fintype n] : Module.End R (n → R) ≃ₐ[R] Matrix n n R :=
{ LinearMap.toMatrix' with
map_mul' := LinearMap.toMatrix'_comp
commutes' := LinearMap.toMatrix'_algebraMap }
/-- A linear equivalence of two modules induces an equivalence of algebras of their
endomorphisms. -/
def LinearEquiv.algConj (e : M₁ ≃ₗ[R] M₂) : Module.End R M₁ ≃ₐ[R] Module.End R M₂ :=
{ e.conj with
map_mul' := fun f g ↦ by apply e.arrowCongr_comp
commutes' := fun r ↦ by
change e.conj (r • LinearMap.id) = r • LinearMap.id
rw [LinearEquiv.map_smul, LinearEquiv.conj_id] }
/-- A basis of a module induces an equivalence of algebras from the endomorphisms of the module to
square matrices. -/
def algEquivMatrix [Fintype n] (h : Basis n R M) : Module.End R M ≃ₐ[R] Matrix n n R :=
h.equivFun.algConj.trans algEquivMatrix'
end
namespace Basis
variable {R M M₁ M₂ ι ι₁ ι₂ : Type*} [CommSemiring R]
variable [AddCommMonoid M] [AddCommMonoid M₁] [AddCommMonoid M₂]
variable [Module R M] [Module R M₁] [Module R M₂]
variable [Fintype ι] [Fintype ι₁] [Fintype ι₂]
variable [DecidableEq ι] [DecidableEq ι₁]
variable (b : Basis ι R M) (b₁ : Basis ι₁ R M₁) (b₂ : Basis ι₂ R M₂)
/-- The standard basis of the space linear maps between two modules
induced by a basis of the domain and codomain.
If `M₁` and `M₂` are modules with basis `b₁` and `b₂` respectively indexed
by finite types `ι₁` and `ι₂`,
then `Basis.linearMap b₁ b₂` is the basis of `M₁ →ₗ[R] M₂` indexed by `ι₂ × ι₁`
where `(i, j)` indexes the linear map that sends `b j` to `b i`
and sends all other basis vectors to `0`. -/
@[simps! (config := .lemmasOnly) repr_apply repr_symm_apply]
noncomputable
def linearMap (b₁ : Basis ι₁ R M₁) (b₂ : Basis ι₂ R M₂) :
Basis (ι₂ × ι₁) R (M₁ →ₗ[R] M₂) :=
(Matrix.stdBasis R ι₂ ι₁).map (LinearMap.toMatrix b₁ b₂).symm
attribute [simp] linearMap_repr_apply
lemma linearMap_apply (ij : ι₂ × ι₁) :
(b₁.linearMap b₂ ij) = (Matrix.toLin b₁ b₂) (Matrix.stdBasis R ι₂ ι₁ ij) := by
simp [linearMap]
lemma linearMap_apply_apply (ij : ι₂ × ι₁) (k : ι₁) :
(b₁.linearMap b₂ ij) (b₁ k) = if ij.2 = k then b₂ ij.1 else 0 := by
have := Classical.decEq ι₂
rw [linearMap_apply, Matrix.stdBasis_eq_stdBasisMatrix, Matrix.toLin_self]
dsimp only [Matrix.stdBasisMatrix]
simp_rw [ite_smul, one_smul, zero_smul, ite_and, Finset.sum_ite_eq, Finset.mem_univ, if_true]
/-- The standard basis of the endomorphism algebra of a module
induced by a basis of the module.
If `M` is a module with basis `b` indexed by a finite type `ι`,
then `Basis.end b` is the basis of `Module.End R M` indexed by `ι × ι`
where `(i, j)` indexes the linear map that sends `b j` to `b i`
and sends all other basis vectors to `0`. -/
@[simps! (config := .lemmasOnly) repr_apply repr_symm_apply]
noncomputable
abbrev _root_.Basis.end (b : Basis ι R M) : Basis (ι × ι) R (Module.End R M) :=
b.linearMap b
attribute [simp] end_repr_apply
lemma end_apply (ij : ι × ι) : (b.end ij) = (Matrix.toLin b b) (Matrix.stdBasis R ι ι ij) :=
linearMap_apply b b ij
lemma end_apply_apply (ij : ι × ι) (k : ι) : (b.end ij) (b k) = if ij.2 = k then b ij.1 else 0 :=
linearMap_apply_apply b b ij k
end Basis
|
LinearAlgebra\Matrix\ToLinearEquiv.lean | /-
Copyright (c) 2019 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Patrick Massot, Casper Putz, Anne Baanen
-/
import Mathlib.LinearAlgebra.Matrix.GeneralLinearGroup.Defs
import Mathlib.LinearAlgebra.Matrix.Nondegenerate
import Mathlib.LinearAlgebra.Matrix.NonsingularInverse
import Mathlib.LinearAlgebra.Matrix.ToLin
import Mathlib.RingTheory.Localization.FractionRing
import Mathlib.RingTheory.Localization.Integer
/-!
# Matrices and linear equivalences
This file gives the map `Matrix.toLinearEquiv` from matrices with invertible determinant,
to linear equivs.
## Main definitions
* `Matrix.toLinearEquiv`: a matrix with an invertible determinant forms a linear equiv
## Main results
* `Matrix.exists_mulVec_eq_zero_iff`: `M` maps some `v ≠ 0` to zero iff `det M = 0`
## Tags
matrix, linear_equiv, determinant, inverse
-/
variable {n : Type*} [Fintype n]
namespace Matrix
section LinearEquiv
open LinearMap
variable {R M : Type*} [CommRing R] [AddCommGroup M] [Module R M]
section ToLinearEquiv'
variable [DecidableEq n]
/-- An invertible matrix yields a linear equivalence from the free module to itself.
See `Matrix.toLinearEquiv` for the same map on arbitrary modules.
-/
def toLinearEquiv' (P : Matrix n n R) (_ : Invertible P) : (n → R) ≃ₗ[R] n → R :=
GeneralLinearGroup.generalLinearEquiv _ _ <|
Matrix.GeneralLinearGroup.toLinear <| unitOfInvertible P
@[simp]
theorem toLinearEquiv'_apply (P : Matrix n n R) (h : Invertible P) :
(P.toLinearEquiv' h : Module.End R (n → R)) = Matrix.toLin' P :=
rfl
@[simp]
theorem toLinearEquiv'_symm_apply (P : Matrix n n R) (h : Invertible P) :
(↑(P.toLinearEquiv' h).symm : Module.End R (n → R)) = Matrix.toLin' (⅟ P) :=
rfl
end ToLinearEquiv'
section ToLinearEquiv
variable (b : Basis n R M)
/-- Given `hA : IsUnit A.det` and `b : Basis R b`, `A.toLinearEquiv b hA` is
the `LinearEquiv` arising from `toLin b b A`.
See `Matrix.toLinearEquiv'` for this result on `n → R`.
-/
@[simps apply]
noncomputable def toLinearEquiv [DecidableEq n] (A : Matrix n n R) (hA : IsUnit A.det) :
M ≃ₗ[R] M where
__ := toLin b b A
toFun := toLin b b A
invFun := toLin b b A⁻¹
left_inv x := by
simp_rw [← LinearMap.comp_apply, ← Matrix.toLin_mul b b b, Matrix.nonsing_inv_mul _ hA,
toLin_one, LinearMap.id_apply]
right_inv x := by
simp_rw [← LinearMap.comp_apply, ← Matrix.toLin_mul b b b, Matrix.mul_nonsing_inv _ hA,
toLin_one, LinearMap.id_apply]
theorem ker_toLin_eq_bot [DecidableEq n] (A : Matrix n n R) (hA : IsUnit A.det) :
LinearMap.ker (toLin b b A) = ⊥ :=
ker_eq_bot.mpr (toLinearEquiv b A hA).injective
theorem range_toLin_eq_top [DecidableEq n] (A : Matrix n n R) (hA : IsUnit A.det) :
LinearMap.range (toLin b b A) = ⊤ :=
range_eq_top.mpr (toLinearEquiv b A hA).surjective
end ToLinearEquiv
section Nondegenerate
open Matrix
/-- This holds for all integral domains (see `Matrix.exists_mulVec_eq_zero_iff`),
not just fields, but it's easier to prove it for the field of fractions first. -/
theorem exists_mulVec_eq_zero_iff_aux {K : Type*} [DecidableEq n] [Field K] {M : Matrix n n K} :
(∃ v ≠ 0, M *ᵥ v = 0) ↔ M.det = 0 := by
constructor
· rintro ⟨v, hv, mul_eq⟩
contrapose! hv
exact eq_zero_of_mulVec_eq_zero hv mul_eq
· contrapose!
intro h
have : Function.Injective (Matrix.toLin' M) := by
simpa only [← LinearMap.ker_eq_bot, ker_toLin'_eq_bot_iff, not_imp_not] using h
have :
M *
LinearMap.toMatrix'
((LinearEquiv.ofInjectiveEndo (Matrix.toLin' M) this).symm : (n → K) →ₗ[K] n → K) =
1 := by
refine Matrix.toLin'.injective (LinearMap.ext fun v => ?_)
rw [Matrix.toLin'_mul, Matrix.toLin'_one, Matrix.toLin'_toMatrix', LinearMap.comp_apply]
exact (LinearEquiv.ofInjectiveEndo (Matrix.toLin' M) this).apply_symm_apply v
exact Matrix.det_ne_zero_of_right_inverse this
theorem exists_mulVec_eq_zero_iff' {A : Type*} (K : Type*) [DecidableEq n] [CommRing A]
[Nontrivial A] [Field K] [Algebra A K] [IsFractionRing A K] {M : Matrix n n A} :
(∃ v ≠ 0, M *ᵥ v = 0) ↔ M.det = 0 := by
have : (∃ v ≠ 0, (algebraMap A K).mapMatrix M *ᵥ v = 0) ↔ _ :=
exists_mulVec_eq_zero_iff_aux
rw [← RingHom.map_det, IsFractionRing.to_map_eq_zero_iff] at this
refine Iff.trans ?_ this; constructor <;> rintro ⟨v, hv, mul_eq⟩
· refine ⟨fun i => algebraMap _ _ (v i), mt (fun h => funext fun i => ?_) hv, ?_⟩
· exact IsFractionRing.to_map_eq_zero_iff.mp (congr_fun h i)
· ext i
refine (RingHom.map_mulVec _ _ _ i).symm.trans ?_
rw [mul_eq, Pi.zero_apply, RingHom.map_zero, Pi.zero_apply]
· letI := Classical.decEq K
obtain ⟨⟨b, hb⟩, ba_eq⟩ :=
IsLocalization.exist_integer_multiples_of_finset (nonZeroDivisors A) (Finset.univ.image v)
choose f hf using ba_eq
refine
⟨fun i => f _ (Finset.mem_image.mpr ⟨i, Finset.mem_univ i, rfl⟩),
mt (fun h => funext fun i => ?_) hv, ?_⟩
· have := congr_arg (algebraMap A K) (congr_fun h i)
rw [hf, Subtype.coe_mk, Pi.zero_apply, RingHom.map_zero, Algebra.smul_def, mul_eq_zero,
IsFractionRing.to_map_eq_zero_iff] at this
exact this.resolve_left (nonZeroDivisors.ne_zero hb)
· ext i
refine IsFractionRing.injective A K ?_
calc
algebraMap A K ((M *ᵥ (fun i : n => f (v i) _)) i) =
((algebraMap A K).mapMatrix M *ᵥ algebraMap _ K b • v) i := ?_
_ = 0 := ?_
_ = algebraMap A K 0 := (RingHom.map_zero _).symm
· simp_rw [RingHom.map_mulVec, mulVec, dotProduct, Function.comp_apply, hf,
RingHom.mapMatrix_apply, Pi.smul_apply, smul_eq_mul, Algebra.smul_def]
· rw [mulVec_smul, mul_eq, Pi.smul_apply, Pi.zero_apply, smul_zero]
theorem exists_mulVec_eq_zero_iff {A : Type*} [DecidableEq n] [CommRing A] [IsDomain A]
{M : Matrix n n A} : (∃ v ≠ 0, M *ᵥ v = 0) ↔ M.det = 0 :=
exists_mulVec_eq_zero_iff' (FractionRing A)
theorem exists_vecMul_eq_zero_iff {A : Type*} [DecidableEq n] [CommRing A] [IsDomain A]
{M : Matrix n n A} : (∃ v ≠ 0, v ᵥ* M = 0) ↔ M.det = 0 := by
simpa only [← M.det_transpose, ← mulVec_transpose] using exists_mulVec_eq_zero_iff
theorem nondegenerate_iff_det_ne_zero {A : Type*} [DecidableEq n] [CommRing A] [IsDomain A]
{M : Matrix n n A} : Nondegenerate M ↔ M.det ≠ 0 := by
rw [ne_eq, ← exists_vecMul_eq_zero_iff]
push_neg
constructor
· intro hM v hv hMv
obtain ⟨w, hwMv⟩ := hM.exists_not_ortho_of_ne_zero hv
simp [dotProduct_mulVec, hMv, zero_dotProduct, ne_eq, not_true] at hwMv
· intro h v hv
refine not_imp_not.mp (h v) (funext fun i => ?_)
simpa only [dotProduct_mulVec, dotProduct_single, mul_one] using hv (Pi.single i 1)
alias ⟨Nondegenerate.det_ne_zero, Nondegenerate.of_det_ne_zero⟩ := nondegenerate_iff_det_ne_zero
end Nondegenerate
end LinearEquiv
section Determinant
/-- A matrix whose nondiagonal entries are negative with the sum of the entries of each
column positive has nonzero determinant. -/
lemma det_ne_zero_of_sum_col_pos [DecidableEq n] {S : Type*} [LinearOrderedCommRing S]
{A : Matrix n n S} (h1 : Pairwise fun i j => A i j < 0) (h2 : ∀ j, 0 < ∑ i, A i j) :
A.det ≠ 0 := by
cases isEmpty_or_nonempty n
· simp
· contrapose! h2
obtain ⟨v, ⟨h_vnz, h_vA⟩⟩ := Matrix.exists_vecMul_eq_zero_iff.mpr h2
wlog h_sup : 0 < Finset.sup' Finset.univ Finset.univ_nonempty v
· refine this h1 inferInstance h2 (-1 • v) ?_ ?_ ?_
· exact smul_ne_zero (by norm_num) h_vnz
· rw [Matrix.vecMul_smul, h_vA, smul_zero]
· obtain ⟨i, hi⟩ := Function.ne_iff.mp h_vnz
simp_rw [Finset.lt_sup'_iff, Finset.mem_univ, true_and] at h_sup ⊢
simp_rw [not_exists, not_lt] at h_sup
refine ⟨i, ?_⟩
rw [Pi.smul_apply, neg_smul, one_smul, Left.neg_pos_iff]
exact Ne.lt_of_le hi (h_sup i)
· obtain ⟨j₀, -, h_j₀⟩ := Finset.exists_mem_eq_sup' Finset.univ_nonempty v
refine ⟨j₀, ?_⟩
rw [← mul_le_mul_left (h_j₀ ▸ h_sup), Finset.mul_sum, mul_zero]
rw [show 0 = ∑ i, v i * A i j₀ from (congrFun h_vA j₀).symm]
refine Finset.sum_le_sum (fun i hi => ?_)
by_cases h : i = j₀
· rw [h]
· exact (mul_le_mul_right_of_neg (h1 h)).mpr (h_j₀ ▸ Finset.le_sup' v hi)
/-- A matrix whose nondiagonal entries are negative with the sum of the entries of each
row positive has nonzero determinant. -/
lemma det_ne_zero_of_sum_row_pos [DecidableEq n] {S : Type*} [LinearOrderedCommRing S]
{A : Matrix n n S} (h1 : Pairwise fun i j => A i j < 0) (h2 : ∀ i, 0 < ∑ j, A i j) :
A.det ≠ 0 := by
rw [← Matrix.det_transpose]
refine det_ne_zero_of_sum_col_pos ?_ ?_
· simp_rw [Matrix.transpose_apply]
exact fun i j h => h1 h.symm
· simp_rw [Matrix.transpose_apply]
exact h2
end Determinant
end Matrix
|
LinearAlgebra\Matrix\Trace.lean | /-
Copyright (c) 2019 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Patrick Massot, Casper Putz, Anne Baanen
-/
import Mathlib.Data.Matrix.Block
import Mathlib.Data.Matrix.RowCol
import Mathlib.Data.Matrix.Notation
/-!
# Trace of a matrix
This file defines the trace of a matrix, the map sending a matrix to the sum of its diagonal
entries.
See also `LinearAlgebra.Trace` for the trace of an endomorphism.
## Tags
matrix, trace, diagonal
-/
open Matrix
namespace Matrix
variable {ι m n p : Type*} {α R S : Type*}
variable [Fintype m] [Fintype n] [Fintype p]
section AddCommMonoid
variable [AddCommMonoid R]
/-- The trace of a square matrix. For more bundled versions, see:
* `Matrix.traceAddMonoidHom`
* `Matrix.traceLinearMap`
-/
def trace (A : Matrix n n R) : R :=
∑ i, diag A i
lemma trace_diagonal {o} [Fintype o] [DecidableEq o] (d : o → R) :
trace (diagonal d) = ∑ i, d i := by
simp only [trace, diag_apply, diagonal_apply_eq]
variable (n R)
@[simp]
theorem trace_zero : trace (0 : Matrix n n R) = 0 :=
(Finset.sum_const (0 : R)).trans <| smul_zero _
variable {n R}
@[simp]
lemma trace_eq_zero_of_isEmpty [IsEmpty n] (A : Matrix n n R) : trace A = 0 := by simp [trace]
@[simp]
theorem trace_add (A B : Matrix n n R) : trace (A + B) = trace A + trace B :=
Finset.sum_add_distrib
@[simp]
theorem trace_smul [Monoid α] [DistribMulAction α R] (r : α) (A : Matrix n n R) :
trace (r • A) = r • trace A :=
Finset.smul_sum.symm
@[simp]
theorem trace_transpose (A : Matrix n n R) : trace Aᵀ = trace A :=
rfl
@[simp]
theorem trace_conjTranspose [StarAddMonoid R] (A : Matrix n n R) : trace Aᴴ = star (trace A) :=
(star_sum _ _).symm
variable (n α R)
/-- `Matrix.trace` as an `AddMonoidHom` -/
@[simps]
def traceAddMonoidHom : Matrix n n R →+ R where
toFun := trace
map_zero' := trace_zero n R
map_add' := trace_add
/-- `Matrix.trace` as a `LinearMap` -/
@[simps]
def traceLinearMap [Semiring α] [Module α R] : Matrix n n R →ₗ[α] R where
toFun := trace
map_add' := trace_add
map_smul' := trace_smul
variable {n α R}
@[simp]
theorem trace_list_sum (l : List (Matrix n n R)) : trace l.sum = (l.map trace).sum :=
map_list_sum (traceAddMonoidHom n R) l
@[simp]
theorem trace_multiset_sum (s : Multiset (Matrix n n R)) : trace s.sum = (s.map trace).sum :=
map_multiset_sum (traceAddMonoidHom n R) s
@[simp]
theorem trace_sum (s : Finset ι) (f : ι → Matrix n n R) :
trace (∑ i ∈ s, f i) = ∑ i ∈ s, trace (f i) :=
map_sum (traceAddMonoidHom n R) f s
theorem _root_.AddMonoidHom.map_trace [AddCommMonoid S] (f : R →+ S) (A : Matrix n n R) :
f (trace A) = trace (f.mapMatrix A) :=
map_sum f (fun i => diag A i) Finset.univ
lemma trace_blockDiagonal [DecidableEq p] (M : p → Matrix n n R) :
trace (blockDiagonal M) = ∑ i, trace (M i) := by
simp [blockDiagonal, trace, Finset.sum_comm (γ := n)]
lemma trace_blockDiagonal' [DecidableEq p] {m : p → Type*} [∀ i, Fintype (m i)]
(M : ∀ i, Matrix (m i) (m i) R) :
trace (blockDiagonal' M) = ∑ i, trace (M i) := by
simp [blockDiagonal', trace, Finset.sum_sigma']
end AddCommMonoid
section AddCommGroup
variable [AddCommGroup R]
@[simp]
theorem trace_sub (A B : Matrix n n R) : trace (A - B) = trace A - trace B :=
Finset.sum_sub_distrib
@[simp]
theorem trace_neg (A : Matrix n n R) : trace (-A) = -trace A :=
Finset.sum_neg_distrib
end AddCommGroup
section One
variable [DecidableEq n] [AddCommMonoidWithOne R]
@[simp]
theorem trace_one : trace (1 : Matrix n n R) = Fintype.card n := by
simp_rw [trace, diag_one, Pi.one_def, Finset.sum_const, nsmul_one, Finset.card_univ]
end One
section Mul
@[simp]
theorem trace_transpose_mul [AddCommMonoid R] [Mul R] (A : Matrix m n R) (B : Matrix n m R) :
trace (Aᵀ * Bᵀ) = trace (A * B) :=
Finset.sum_comm
theorem trace_mul_comm [AddCommMonoid R] [CommSemigroup R] (A : Matrix m n R) (B : Matrix n m R) :
trace (A * B) = trace (B * A) := by rw [← trace_transpose, ← trace_transpose_mul, transpose_mul]
theorem trace_mul_cycle [NonUnitalCommSemiring R] (A : Matrix m n R) (B : Matrix n p R)
(C : Matrix p m R) : trace (A * B * C) = trace (C * A * B) := by
rw [trace_mul_comm, Matrix.mul_assoc]
theorem trace_mul_cycle' [NonUnitalCommSemiring R] (A : Matrix m n R) (B : Matrix n p R)
(C : Matrix p m R) : trace (A * (B * C)) = trace (C * (A * B)) := by
rw [← Matrix.mul_assoc, trace_mul_comm]
@[simp]
theorem trace_col_mul_row {ι : Type*} [Unique ι] [NonUnitalNonAssocSemiring R] (a b : n → R) :
trace (col ι a * row ι b) = dotProduct a b := by
apply Finset.sum_congr rfl
simp [mul_apply]
end Mul
lemma trace_submatrix_succ {n : ℕ} [NonUnitalNonAssocSemiring R]
(M : Matrix (Fin n.succ) (Fin n.succ) R) :
M 0 0 + trace (submatrix M Fin.succ Fin.succ) = trace M := by
delta trace
rw [← (finSuccEquiv n).symm.sum_comp]
simp
section Fin
variable [AddCommMonoid R]
/-! ### Special cases for `Fin n` for low values of `n`
-/
@[simp]
theorem trace_fin_zero (A : Matrix (Fin 0) (Fin 0) R) : trace A = 0 :=
rfl
theorem trace_fin_one (A : Matrix (Fin 1) (Fin 1) R) : trace A = A 0 0 :=
add_zero _
theorem trace_fin_two (A : Matrix (Fin 2) (Fin 2) R) : trace A = A 0 0 + A 1 1 :=
congr_arg (_ + ·) (add_zero (A 1 1))
theorem trace_fin_three (A : Matrix (Fin 3) (Fin 3) R) : trace A = A 0 0 + A 1 1 + A 2 2 := by
rw [← add_zero (A 2 2), add_assoc]
rfl
@[simp]
theorem trace_fin_one_of (a : R) : trace !![a] = a :=
trace_fin_one _
@[simp]
theorem trace_fin_two_of (a b c d : R) : trace !![a, b; c, d] = a + d :=
trace_fin_two _
@[simp]
theorem trace_fin_three_of (a b c d e f g h i : R) :
trace !![a, b, c; d, e, f; g, h, i] = a + e + i :=
trace_fin_three _
end Fin
end Matrix
|
LinearAlgebra\Matrix\Transvection.lean | /-
Copyright (c) 2021 Sébastien Gouëzel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Sébastien Gouëzel
-/
import Mathlib.Data.Matrix.Basis
import Mathlib.Data.Matrix.DMatrix
import Mathlib.LinearAlgebra.Matrix.Determinant.Basic
import Mathlib.LinearAlgebra.Matrix.Reindex
import Mathlib.Tactic.FieldSimp
/-!
# Transvections
Transvections are matrices of the form `1 + stdBasisMatrix i j c`, where `stdBasisMatrix i j c`
is the basic matrix with a `c` at position `(i, j)`. Multiplying by such a transvection on the left
(resp. on the right) amounts to adding `c` times the `j`-th row to the `i`-th row
(resp `c` times the `i`-th column to the `j`-th column). Therefore, they are useful to present
algorithms operating on rows and columns.
Transvections are a special case of *elementary matrices* (according to most references, these also
contain the matrices exchanging rows, and the matrices multiplying a row by a constant).
We show that, over a field, any matrix can be written as `L * D * L'`, where `L` and `L'` are
products of transvections and `D` is diagonal. In other words, one can reduce a matrix to diagonal
form by operations on its rows and columns, a variant of Gauss' pivot algorithm.
## Main definitions and results
* `transvection i j c` is the matrix equal to `1 + stdBasisMatrix i j c`.
* `TransvectionStruct n R` is a structure containing the data of `i, j, c` and a proof that
`i ≠ j`. These are often easier to manipulate than straight matrices, especially in inductive
arguments.
* `exists_list_transvec_mul_diagonal_mul_list_transvec` states that any matrix `M` over a field can
be written in the form `t_1 * ... * t_k * D * t'_1 * ... * t'_l`, where `D` is diagonal and
the `t_i`, `t'_j` are transvections.
* `diagonal_transvection_induction` shows that a property which is true for diagonal matrices and
transvections, and invariant under product, is true for all matrices.
* `diagonal_transvection_induction_of_det_ne_zero` is the same statement over invertible matrices.
## Implementation details
The proof of the reduction results is done inductively on the size of the matrices, reducing an
`(r + 1) × (r + 1)` matrix to a matrix whose last row and column are zeroes, except possibly for
the last diagonal entry. This step is done as follows.
If all the coefficients on the last row and column are zero, there is nothing to do. Otherwise,
one can put a nonzero coefficient in the last diagonal entry by a row or column operation, and then
subtract this last diagonal entry from the other entries in the last row and column to make them
vanish.
This step is done in the type `Fin r ⊕ Unit`, where `Fin r` is useful to choose arbitrarily some
order in which we cancel the coefficients, and the sum structure is useful to use the formalism of
block matrices.
To proceed with the induction, we reindex our matrices to reduce to the above situation.
-/
universe u₁ u₂
namespace Matrix
open Matrix
variable (n p : Type*) (R : Type u₂) {𝕜 : Type*} [Field 𝕜]
variable [DecidableEq n] [DecidableEq p]
variable [CommRing R]
section Transvection
variable {R n} (i j : n)
/-- The transvection matrix `transvection i j c` is equal to the identity plus `c` at position
`(i, j)`. Multiplying by it on the left (as in `transvection i j c * M`) corresponds to adding
`c` times the `j`-th row of `M` to its `i`-th row. Multiplying by it on the right corresponds
to adding `c` times the `i`-th column to the `j`-th column. -/
def transvection (c : R) : Matrix n n R :=
1 + Matrix.stdBasisMatrix i j c
@[simp]
theorem transvection_zero : transvection i j (0 : R) = 1 := by simp [transvection]
section
/-- A transvection matrix is obtained from the identity by adding `c` times the `j`-th row to
the `i`-th row. -/
theorem updateRow_eq_transvection [Finite n] (c : R) :
updateRow (1 : Matrix n n R) i ((1 : Matrix n n R) i + c • (1 : Matrix n n R) j) =
transvection i j c := by
cases nonempty_fintype n
ext a b
by_cases ha : i = a
· by_cases hb : j = b
· simp only [ha, updateRow_self, Pi.add_apply, one_apply, Pi.smul_apply, hb, ↓reduceIte,
smul_eq_mul, mul_one, transvection, add_apply, StdBasisMatrix.apply_same]
· simp only [ha, updateRow_self, Pi.add_apply, one_apply, Pi.smul_apply, hb, ↓reduceIte,
smul_eq_mul, mul_zero, add_zero, transvection, add_apply, and_false, not_false_eq_true,
StdBasisMatrix.apply_of_ne]
· simp only [updateRow_ne, transvection, ha, Ne.symm ha, StdBasisMatrix.apply_of_ne, add_zero,
Algebra.id.smul_eq_mul, Ne, not_false_iff, DMatrix.add_apply, Pi.smul_apply,
mul_zero, false_and_iff, add_apply]
variable [Fintype n]
theorem transvection_mul_transvection_same (h : i ≠ j) (c d : R) :
transvection i j c * transvection i j d = transvection i j (c + d) := by
simp [transvection, Matrix.add_mul, Matrix.mul_add, h, h.symm, add_smul, add_assoc,
stdBasisMatrix_add]
@[simp]
theorem transvection_mul_apply_same (b : n) (c : R) (M : Matrix n n R) :
(transvection i j c * M) i b = M i b + c * M j b := by simp [transvection, Matrix.add_mul]
@[simp]
theorem mul_transvection_apply_same (a : n) (c : R) (M : Matrix n n R) :
(M * transvection i j c) a j = M a j + c * M a i := by
simp [transvection, Matrix.mul_add, mul_comm]
@[simp]
theorem transvection_mul_apply_of_ne (a b : n) (ha : a ≠ i) (c : R) (M : Matrix n n R) :
(transvection i j c * M) a b = M a b := by simp [transvection, Matrix.add_mul, ha]
@[simp]
theorem mul_transvection_apply_of_ne (a b : n) (hb : b ≠ j) (c : R) (M : Matrix n n R) :
(M * transvection i j c) a b = M a b := by simp [transvection, Matrix.mul_add, hb]
@[simp]
theorem det_transvection_of_ne (h : i ≠ j) (c : R) : det (transvection i j c) = 1 := by
rw [← updateRow_eq_transvection i j, det_updateRow_add_smul_self _ h, det_one]
end
variable (R n)
/-- A structure containing all the information from which one can build a nontrivial transvection.
This structure is easier to manipulate than transvections as one has a direct access to all the
relevant fields. -/
-- porting note (#5171): removed @[nolint has_nonempty_instance]
structure TransvectionStruct where
(i j : n)
hij : i ≠ j
c : R
instance [Nontrivial n] : Nonempty (TransvectionStruct n R) := by
choose x y hxy using exists_pair_ne n
exact ⟨⟨x, y, hxy, 0⟩⟩
namespace TransvectionStruct
variable {R n}
/-- Associating to a `transvection_struct` the corresponding transvection matrix. -/
def toMatrix (t : TransvectionStruct n R) : Matrix n n R :=
transvection t.i t.j t.c
@[simp]
theorem toMatrix_mk (i j : n) (hij : i ≠ j) (c : R) :
TransvectionStruct.toMatrix ⟨i, j, hij, c⟩ = transvection i j c :=
rfl
@[simp]
protected theorem det [Fintype n] (t : TransvectionStruct n R) : det t.toMatrix = 1 :=
det_transvection_of_ne _ _ t.hij _
@[simp]
theorem det_toMatrix_prod [Fintype n] (L : List (TransvectionStruct n 𝕜)) :
det (L.map toMatrix).prod = 1 := by
induction' L with t L IH
· simp
· simp [IH]
/-- The inverse of a `TransvectionStruct`, designed so that `t.inv.toMatrix` is the inverse of
`t.toMatrix`. -/
@[simps]
protected def inv (t : TransvectionStruct n R) : TransvectionStruct n R where
i := t.i
j := t.j
hij := t.hij
c := -t.c
section
variable [Fintype n]
theorem inv_mul (t : TransvectionStruct n R) : t.inv.toMatrix * t.toMatrix = 1 := by
rcases t with ⟨_, _, t_hij⟩
simp [toMatrix, transvection_mul_transvection_same, t_hij]
theorem mul_inv (t : TransvectionStruct n R) : t.toMatrix * t.inv.toMatrix = 1 := by
rcases t with ⟨_, _, t_hij⟩
simp [toMatrix, transvection_mul_transvection_same, t_hij]
theorem reverse_inv_prod_mul_prod (L : List (TransvectionStruct n R)) :
(L.reverse.map (toMatrix ∘ TransvectionStruct.inv)).prod * (L.map toMatrix).prod = 1 := by
induction' L with t L IH
· simp
· suffices
(L.reverse.map (toMatrix ∘ TransvectionStruct.inv)).prod * (t.inv.toMatrix * t.toMatrix) *
(L.map toMatrix).prod = 1
by simpa [Matrix.mul_assoc]
simpa [inv_mul] using IH
theorem prod_mul_reverse_inv_prod (L : List (TransvectionStruct n R)) :
(L.map toMatrix).prod * (L.reverse.map (toMatrix ∘ TransvectionStruct.inv)).prod = 1 := by
induction' L with t L IH
· simp
· suffices
t.toMatrix *
((L.map toMatrix).prod * (L.reverse.map (toMatrix ∘ TransvectionStruct.inv)).prod) *
t.inv.toMatrix = 1
by simpa [Matrix.mul_assoc]
simp_rw [IH, Matrix.mul_one, t.mul_inv]
/-- `M` is a scalar matrix if it commutes with every nontrivial transvection (elementary matrix). -/
theorem _root_.Matrix.mem_range_scalar_of_commute_transvectionStruct {M : Matrix n n R}
(hM : ∀ t : TransvectionStruct n R, Commute t.toMatrix M) :
M ∈ Set.range (Matrix.scalar n) := by
refine mem_range_scalar_of_commute_stdBasisMatrix ?_
intro i j hij
simpa [transvection, mul_add, add_mul] using (hM ⟨i, j, hij, 1⟩).eq
theorem _root_.Matrix.mem_range_scalar_iff_commute_transvectionStruct {M : Matrix n n R} :
M ∈ Set.range (Matrix.scalar n) ↔ ∀ t : TransvectionStruct n R, Commute t.toMatrix M := by
refine ⟨fun h t => ?_, mem_range_scalar_of_commute_transvectionStruct⟩
rw [mem_range_scalar_iff_commute_stdBasisMatrix] at h
refine (Commute.one_left M).add_left ?_
convert (h _ _ t.hij).smul_left t.c using 1
rw [smul_stdBasisMatrix, smul_eq_mul, mul_one]
end
open Sum
/-- Given a `TransvectionStruct` on `n`, define the corresponding `TransvectionStruct` on `n ⊕ p`
using the identity on `p`. -/
def sumInl (t : TransvectionStruct n R) : TransvectionStruct (n ⊕ p) R where
i := inl t.i
j := inl t.j
hij := by simp [t.hij]
c := t.c
theorem toMatrix_sumInl (t : TransvectionStruct n R) :
(t.sumInl p).toMatrix = fromBlocks t.toMatrix 0 0 1 := by
cases t
ext a b
cases' a with a a <;> cases' b with b b
· by_cases h : a = b <;> simp [TransvectionStruct.sumInl, transvection, h, stdBasisMatrix]
· simp [TransvectionStruct.sumInl, transvection]
· simp [TransvectionStruct.sumInl, transvection]
· by_cases h : a = b <;> simp [TransvectionStruct.sumInl, transvection, h]
@[simp]
theorem sumInl_toMatrix_prod_mul [Fintype n] [Fintype p] (M : Matrix n n R)
(L : List (TransvectionStruct n R)) (N : Matrix p p R) :
(L.map (toMatrix ∘ sumInl p)).prod * fromBlocks M 0 0 N =
fromBlocks ((L.map toMatrix).prod * M) 0 0 N := by
induction' L with t L IH
· simp
· simp [Matrix.mul_assoc, IH, toMatrix_sumInl, fromBlocks_multiply]
@[simp]
theorem mul_sumInl_toMatrix_prod [Fintype n] [Fintype p] (M : Matrix n n R)
(L : List (TransvectionStruct n R)) (N : Matrix p p R) :
fromBlocks M 0 0 N * (L.map (toMatrix ∘ sumInl p)).prod =
fromBlocks (M * (L.map toMatrix).prod) 0 0 N := by
induction' L with t L IH generalizing M N
· simp
· simp [IH, toMatrix_sumInl, fromBlocks_multiply]
variable {p}
/-- Given a `TransvectionStruct` on `n` and an equivalence between `n` and `p`, define the
corresponding `TransvectionStruct` on `p`. -/
def reindexEquiv (e : n ≃ p) (t : TransvectionStruct n R) : TransvectionStruct p R where
i := e t.i
j := e t.j
hij := by simp [t.hij]
c := t.c
variable [Fintype n] [Fintype p]
theorem toMatrix_reindexEquiv (e : n ≃ p) (t : TransvectionStruct n R) :
(t.reindexEquiv e).toMatrix = reindexAlgEquiv R _ e t.toMatrix := by
rcases t with ⟨t_i, t_j, _⟩
ext a b
simp only [reindexEquiv, transvection, mul_boole, Algebra.id.smul_eq_mul, toMatrix_mk,
submatrix_apply, reindex_apply, DMatrix.add_apply, Pi.smul_apply, reindexAlgEquiv_apply]
by_cases ha : e t_i = a <;> by_cases hb : e t_j = b <;> by_cases hab : a = b <;>
simp [ha, hb, hab, ← e.apply_eq_iff_eq_symm_apply, stdBasisMatrix]
theorem toMatrix_reindexEquiv_prod (e : n ≃ p) (L : List (TransvectionStruct n R)) :
(L.map (toMatrix ∘ reindexEquiv e)).prod = reindexAlgEquiv R _ e (L.map toMatrix).prod := by
induction' L with t L IH
· simp
· simp only [toMatrix_reindexEquiv, IH, Function.comp_apply, List.prod_cons,
reindexAlgEquiv_apply, List.map]
exact (reindexAlgEquiv_mul R _ _ _ _).symm
end TransvectionStruct
end Transvection
/-!
# Reducing matrices by left and right multiplication by transvections
In this section, we show that any matrix can be reduced to diagonal form by left and right
multiplication by transvections (or, equivalently, by elementary operations on lines and columns).
The main step is to kill the last row and column of a matrix in `Fin r ⊕ Unit` with nonzero last
coefficient, by subtracting this coefficient from the other ones. The list of these operations is
recorded in `list_transvec_col M` and `list_transvec_row M`. We have to analyze inductively how
these operations affect the coefficients in the last row and the last column to conclude that they
have the desired effect.
Once this is done, one concludes the reduction by induction on the size
of the matrices, through a suitable reindexing to identify any fintype with `Fin r ⊕ Unit`.
-/
namespace Pivot
variable {R} {r : ℕ} (M : Matrix (Fin r ⊕ Unit) (Fin r ⊕ Unit) 𝕜)
open Unit Sum Fin TransvectionStruct
/-- A list of transvections such that multiplying on the left with these transvections will replace
the last column with zeroes. -/
def listTransvecCol : List (Matrix (Fin r ⊕ Unit) (Fin r ⊕ Unit) 𝕜) :=
List.ofFn fun i : Fin r =>
transvection (inl i) (inr unit) <| -M (inl i) (inr unit) / M (inr unit) (inr unit)
/-- A list of transvections such that multiplying on the right with these transvections will replace
the last row with zeroes. -/
def listTransvecRow : List (Matrix (Fin r ⊕ Unit) (Fin r ⊕ Unit) 𝕜) :=
List.ofFn fun i : Fin r =>
transvection (inr unit) (inl i) <| -M (inr unit) (inl i) / M (inr unit) (inr unit)
@[simp]
theorem length_listTransvecCol : (listTransvecCol M).length = r := by simp [listTransvecCol]
theorem listTransvecCol_get (i : Fin (listTransvecCol M).length) :
(listTransvecCol M).get i =
letI i' := Fin.cast (length_listTransvecCol M) i
transvection (inl i') (inr unit) <| -M (inl i') (inr unit) / M (inr unit) (inr unit) := by
simp [listTransvecCol, Fin.cast]
@[simp]
theorem length_listTransvecRow : (listTransvecRow M).length = r := by simp [listTransvecRow]
theorem listTransvecRow_get (i : Fin (listTransvecRow M).length) :
(listTransvecRow M).get i =
letI i' := Fin.cast (length_listTransvecRow M) i
transvection (inr unit) (inl i') <| -M (inr unit) (inl i') / M (inr unit) (inr unit) := by
simp [listTransvecRow, Fin.cast]
/-- Multiplying by some of the matrices in `listTransvecCol M` does not change the last row. -/
theorem listTransvecCol_mul_last_row_drop (i : Fin r ⊕ Unit) {k : ℕ} (hk : k ≤ r) :
(((listTransvecCol M).drop k).prod * M) (inr unit) i = M (inr unit) i := by
induction hk using Nat.decreasingInduction with
| of_succ n hn IH =>
have hn' : n < (listTransvecCol M).length := by simpa [listTransvecCol] using hn
rw [List.drop_eq_getElem_cons hn']
simpa [listTransvecCol, Matrix.mul_assoc]
| self =>
simp only [length_listTransvecCol, le_refl, List.drop_eq_nil_of_le, List.prod_nil,
Matrix.one_mul]
/-- Multiplying by all the matrices in `listTransvecCol M` does not change the last row. -/
theorem listTransvecCol_mul_last_row (i : Fin r ⊕ Unit) :
((listTransvecCol M).prod * M) (inr unit) i = M (inr unit) i := by
simpa using listTransvecCol_mul_last_row_drop M i (zero_le _)
/-- Multiplying by all the matrices in `listTransvecCol M` kills all the coefficients in the
last column but the last one. -/
theorem listTransvecCol_mul_last_col (hM : M (inr unit) (inr unit) ≠ 0) (i : Fin r) :
((listTransvecCol M).prod * M) (inl i) (inr unit) = 0 := by
suffices H :
∀ k : ℕ,
k ≤ r →
(((listTransvecCol M).drop k).prod * M) (inl i) (inr unit) =
if k ≤ i then 0 else M (inl i) (inr unit) by
simpa only [List.drop, _root_.zero_le, ite_true] using H 0 (zero_le _)
intro k hk
induction hk using Nat.decreasingInduction with
| of_succ n hn IH =>
have hn' : n < (listTransvecCol M).length := by simpa [listTransvecCol] using hn
let n' : Fin r := ⟨n, hn⟩
rw [List.drop_eq_getElem_cons hn']
have A :
(listTransvecCol M)[n] =
transvection (inl n') (inr unit) (-M (inl n') (inr unit) / M (inr unit) (inr unit)) := by
simp [listTransvecCol]
simp only [Matrix.mul_assoc, A, List.prod_cons]
by_cases h : n' = i
· have hni : n = i := by
cases i
simp only [n', Fin.mk_eq_mk] at h
simp [h]
simp only [h, transvection_mul_apply_same, IH, ← hni, add_le_iff_nonpos_right,
listTransvecCol_mul_last_row_drop _ _ hn]
field_simp [hM]
· have hni : n ≠ i := by
rintro rfl
cases i
simp at h
simp only [ne_eq, inl.injEq, Ne.symm h, not_false_eq_true, transvection_mul_apply_of_ne]
rw [IH]
rcases le_or_lt (n + 1) i with (hi | hi)
· simp only [hi, n.le_succ.trans hi, if_true]
· rw [if_neg, if_neg]
· simpa only [hni.symm, not_le, or_false_iff] using Nat.lt_succ_iff_lt_or_eq.1 hi
· simpa only [not_le] using hi
| self =>
simp only [length_listTransvecCol, le_refl, List.drop_eq_nil_of_le, List.prod_nil,
Matrix.one_mul]
rw [if_neg]
simpa only [not_le] using i.2
/-- Multiplying by some of the matrices in `listTransvecRow M` does not change the last column. -/
theorem mul_listTransvecRow_last_col_take (i : Fin r ⊕ Unit) {k : ℕ} (hk : k ≤ r) :
(M * ((listTransvecRow M).take k).prod) i (inr unit) = M i (inr unit) := by
induction' k with k IH
· simp only [Matrix.mul_one, List.take_zero, List.prod_nil, List.take, Matrix.mul_one]
· have hkr : k < r := hk
let k' : Fin r := ⟨k, hkr⟩
have :
(listTransvecRow M)[k]? =
↑(transvection (inr Unit.unit) (inl k')
(-M (inr Unit.unit) (inl k') / M (inr Unit.unit) (inr Unit.unit))) := by
simp only [listTransvecRow, List.ofFnNthVal, hkr, dif_pos, List.getElem?_ofFn]
simp only [List.take_succ, ← Matrix.mul_assoc, this, List.prod_append, Matrix.mul_one,
List.prod_cons, List.prod_nil, Option.toList_some]
rw [mul_transvection_apply_of_ne, IH hkr.le]
simp only [Ne, not_false_iff]
/-- Multiplying by all the matrices in `listTransvecRow M` does not change the last column. -/
theorem mul_listTransvecRow_last_col (i : Fin r ⊕ Unit) :
(M * (listTransvecRow M).prod) i (inr unit) = M i (inr unit) := by
have A : (listTransvecRow M).length = r := by simp [listTransvecRow]
rw [← List.take_length (listTransvecRow M), A]
simpa using mul_listTransvecRow_last_col_take M i le_rfl
/-- Multiplying by all the matrices in `listTransvecRow M` kills all the coefficients in the
last row but the last one. -/
theorem mul_listTransvecRow_last_row (hM : M (inr unit) (inr unit) ≠ 0) (i : Fin r) :
(M * (listTransvecRow M).prod) (inr unit) (inl i) = 0 := by
suffices H :
∀ k : ℕ,
k ≤ r →
(M * ((listTransvecRow M).take k).prod) (inr unit) (inl i) =
if k ≤ i then M (inr unit) (inl i) else 0 by
have A : (listTransvecRow M).length = r := by simp [listTransvecRow]
rw [← List.take_length (listTransvecRow M), A]
have : ¬r ≤ i := by simp
simpa only [this, ite_eq_right_iff] using H r le_rfl
intro k hk
induction' k with n IH
· simp only [if_true, Matrix.mul_one, List.take_zero, zero_le', List.prod_nil, Nat.zero_eq]
· have hnr : n < r := hk
let n' : Fin r := ⟨n, hnr⟩
have A :
(listTransvecRow M)[n]? =
↑(transvection (inr unit) (inl n')
(-M (inr unit) (inl n') / M (inr unit) (inr unit))) := by
simp only [listTransvecRow, List.ofFnNthVal, hnr, dif_pos, List.getElem?_ofFn]
simp only [List.take_succ, A, ← Matrix.mul_assoc, List.prod_append, Matrix.mul_one,
List.prod_cons, List.prod_nil, Option.toList_some]
by_cases h : n' = i
· have hni : n = i := by
cases i
simp only [n', Fin.mk_eq_mk] at h
simp only [h]
have : ¬n.succ ≤ i := by simp only [← hni, n.lt_succ_self, not_le]
simp only [h, mul_transvection_apply_same, List.take, if_false,
mul_listTransvecRow_last_col_take _ _ hnr.le, hni.le, this, if_true, IH hnr.le]
field_simp [hM]
· have hni : n ≠ i := by
rintro rfl
cases i
tauto
simp only [IH hnr.le, Ne, mul_transvection_apply_of_ne, Ne.symm h, inl.injEq,
not_false_eq_true]
rcases le_or_lt (n + 1) i with (hi | hi)
· simp [hi, n.le_succ.trans hi, if_true]
· rw [if_neg, if_neg]
· simpa only [not_le] using hi
· simpa only [hni.symm, not_le, or_false_iff] using Nat.lt_succ_iff_lt_or_eq.1 hi
/-- Multiplying by all the matrices either in `listTransvecCol M` and `listTransvecRow M` kills
all the coefficients in the last row but the last one. -/
theorem listTransvecCol_mul_mul_listTransvecRow_last_col (hM : M (inr unit) (inr unit) ≠ 0)
(i : Fin r) :
((listTransvecCol M).prod * M * (listTransvecRow M).prod) (inr unit) (inl i) = 0 := by
have : listTransvecRow M = listTransvecRow ((listTransvecCol M).prod * M) := by
simp [listTransvecRow, listTransvecCol_mul_last_row]
rw [this]
apply mul_listTransvecRow_last_row
simpa [listTransvecCol_mul_last_row] using hM
/-- Multiplying by all the matrices either in `listTransvecCol M` and `listTransvecRow M` kills
all the coefficients in the last column but the last one. -/
theorem listTransvecCol_mul_mul_listTransvecRow_last_row (hM : M (inr unit) (inr unit) ≠ 0)
(i : Fin r) :
((listTransvecCol M).prod * M * (listTransvecRow M).prod) (inl i) (inr unit) = 0 := by
have : listTransvecCol M = listTransvecCol (M * (listTransvecRow M).prod) := by
simp [listTransvecCol, mul_listTransvecRow_last_col]
rw [this, Matrix.mul_assoc]
apply listTransvecCol_mul_last_col
simpa [mul_listTransvecRow_last_col] using hM
/-- Multiplying by all the matrices either in `listTransvecCol M` and `listTransvecRow M` turns
the matrix in block-diagonal form. -/
theorem isTwoBlockDiagonal_listTransvecCol_mul_mul_listTransvecRow
(hM : M (inr unit) (inr unit) ≠ 0) :
IsTwoBlockDiagonal ((listTransvecCol M).prod * M * (listTransvecRow M).prod) := by
constructor
· ext i j
have : j = unit := by simp only [eq_iff_true_of_subsingleton]
simp [toBlocks₁₂, this, listTransvecCol_mul_mul_listTransvecRow_last_row M hM]
· ext i j
have : i = unit := by simp only [eq_iff_true_of_subsingleton]
simp [toBlocks₂₁, this, listTransvecCol_mul_mul_listTransvecRow_last_col M hM]
/-- There exist two lists of `TransvectionStruct` such that multiplying by them on the left and
on the right makes a matrix block-diagonal, when the last coefficient is nonzero. -/
theorem exists_isTwoBlockDiagonal_of_ne_zero (hM : M (inr unit) (inr unit) ≠ 0) :
∃ L L' : List (TransvectionStruct (Fin r ⊕ Unit) 𝕜),
IsTwoBlockDiagonal ((L.map toMatrix).prod * M * (L'.map toMatrix).prod) := by
let L : List (TransvectionStruct (Fin r ⊕ Unit) 𝕜) :=
List.ofFn fun i : Fin r =>
⟨inl i, inr unit, by simp, -M (inl i) (inr unit) / M (inr unit) (inr unit)⟩
let L' : List (TransvectionStruct (Fin r ⊕ Unit) 𝕜) :=
List.ofFn fun i : Fin r =>
⟨inr unit, inl i, by simp, -M (inr unit) (inl i) / M (inr unit) (inr unit)⟩
refine ⟨L, L', ?_⟩
have A : L.map toMatrix = listTransvecCol M := by simp [L, listTransvecCol, (· ∘ ·)]
have B : L'.map toMatrix = listTransvecRow M := by simp [L', listTransvecRow, (· ∘ ·)]
rw [A, B]
exact isTwoBlockDiagonal_listTransvecCol_mul_mul_listTransvecRow M hM
/-- There exist two lists of `TransvectionStruct` such that multiplying by them on the left and
on the right makes a matrix block-diagonal. -/
theorem exists_isTwoBlockDiagonal_list_transvec_mul_mul_list_transvec
(M : Matrix (Fin r ⊕ Unit) (Fin r ⊕ Unit) 𝕜) :
∃ L L' : List (TransvectionStruct (Fin r ⊕ Unit) 𝕜),
IsTwoBlockDiagonal ((L.map toMatrix).prod * M * (L'.map toMatrix).prod) := by
by_cases H : IsTwoBlockDiagonal M
· refine ⟨List.nil, List.nil, by simpa using H⟩
-- we have already proved this when the last coefficient is nonzero
by_cases hM : M (inr unit) (inr unit) ≠ 0
· exact exists_isTwoBlockDiagonal_of_ne_zero M hM
-- when the last coefficient is zero but there is a nonzero coefficient on the last row or the
-- last column, we will first put this nonzero coefficient in last position, and then argue as
-- above.
push_neg at hM
simp only [not_and_or, IsTwoBlockDiagonal, toBlocks₁₂, toBlocks₂₁, ← Matrix.ext_iff] at H
have : ∃ i : Fin r, M (inl i) (inr unit) ≠ 0 ∨ M (inr unit) (inl i) ≠ 0 := by
cases' H with H H
· contrapose! H
rintro i ⟨⟩
exact (H i).1
· contrapose! H
rintro ⟨⟩ j
exact (H j).2
rcases this with ⟨i, h | h⟩
· let M' := transvection (inr Unit.unit) (inl i) 1 * M
have hM' : M' (inr unit) (inr unit) ≠ 0 := by simpa [M', hM]
rcases exists_isTwoBlockDiagonal_of_ne_zero M' hM' with ⟨L, L', hLL'⟩
rw [Matrix.mul_assoc] at hLL'
refine ⟨L ++ [⟨inr unit, inl i, by simp, 1⟩], L', ?_⟩
simp only [List.map_append, List.prod_append, Matrix.mul_one, toMatrix_mk, List.prod_cons,
List.prod_nil, List.map, Matrix.mul_assoc (L.map toMatrix).prod]
exact hLL'
· let M' := M * transvection (inl i) (inr unit) 1
have hM' : M' (inr unit) (inr unit) ≠ 0 := by simpa [M', hM]
rcases exists_isTwoBlockDiagonal_of_ne_zero M' hM' with ⟨L, L', hLL'⟩
refine ⟨L, ⟨inl i, inr unit, by simp, 1⟩::L', ?_⟩
simp only [← Matrix.mul_assoc, toMatrix_mk, List.prod_cons, List.map]
rw [Matrix.mul_assoc (L.map toMatrix).prod]
exact hLL'
/-- Inductive step for the reduction: if one knows that any size `r` matrix can be reduced to
diagonal form by elementary operations, then one deduces it for matrices over `Fin r ⊕ Unit`. -/
theorem exists_list_transvec_mul_mul_list_transvec_eq_diagonal_induction
(IH :
∀ M : Matrix (Fin r) (Fin r) 𝕜,
∃ (L₀ L₀' : List (TransvectionStruct (Fin r) 𝕜)) (D₀ : Fin r → 𝕜),
(L₀.map toMatrix).prod * M * (L₀'.map toMatrix).prod = diagonal D₀)
(M : Matrix (Fin r ⊕ Unit) (Fin r ⊕ Unit) 𝕜) :
∃ (L L' : List (TransvectionStruct (Fin r ⊕ Unit) 𝕜)) (D : Fin r ⊕ Unit → 𝕜),
(L.map toMatrix).prod * M * (L'.map toMatrix).prod = diagonal D := by
rcases exists_isTwoBlockDiagonal_list_transvec_mul_mul_list_transvec M with ⟨L₁, L₁', hM⟩
let M' := (L₁.map toMatrix).prod * M * (L₁'.map toMatrix).prod
let M'' := toBlocks₁₁ M'
rcases IH M'' with ⟨L₀, L₀', D₀, h₀⟩
set c := M' (inr unit) (inr unit)
refine
⟨L₀.map (sumInl Unit) ++ L₁, L₁' ++ L₀'.map (sumInl Unit),
Sum.elim D₀ fun _ => M' (inr unit) (inr unit), ?_⟩
suffices (L₀.map (toMatrix ∘ sumInl Unit)).prod * M' * (L₀'.map (toMatrix ∘ sumInl Unit)).prod =
diagonal (Sum.elim D₀ fun _ => c) by
simpa [M', c, Matrix.mul_assoc]
have : M' = fromBlocks M'' 0 0 (diagonal fun _ => c) := by
-- Porting note: simplified proof, because `congr` didn't work anymore
rw [← fromBlocks_toBlocks M', hM.1, hM.2]
rfl
rw [this]
simp [h₀]
variable {n p} [Fintype n] [Fintype p]
/-- Reduction to diagonal form by elementary operations is invariant under reindexing. -/
theorem reindex_exists_list_transvec_mul_mul_list_transvec_eq_diagonal (M : Matrix p p 𝕜)
(e : p ≃ n)
(H :
∃ (L L' : List (TransvectionStruct n 𝕜)) (D : n → 𝕜),
(L.map toMatrix).prod * Matrix.reindexAlgEquiv 𝕜 _ e M * (L'.map toMatrix).prod =
diagonal D) :
∃ (L L' : List (TransvectionStruct p 𝕜)) (D : p → 𝕜),
(L.map toMatrix).prod * M * (L'.map toMatrix).prod = diagonal D := by
rcases H with ⟨L₀, L₀', D₀, h₀⟩
refine ⟨L₀.map (reindexEquiv e.symm), L₀'.map (reindexEquiv e.symm), D₀ ∘ e, ?_⟩
have : M = reindexAlgEquiv 𝕜 _ e.symm (reindexAlgEquiv 𝕜 _ e M) := by
simp only [Equiv.symm_symm, submatrix_submatrix, reindex_apply, submatrix_id_id,
Equiv.symm_comp_self, reindexAlgEquiv_apply]
rw [this]
simp only [toMatrix_reindexEquiv_prod, List.map_map, reindexAlgEquiv_apply]
simp only [← reindexAlgEquiv_apply 𝕜, ← reindexAlgEquiv_mul, h₀]
simp only [Equiv.symm_symm, reindex_apply, submatrix_diagonal_equiv, reindexAlgEquiv_apply]
/-- Any matrix can be reduced to diagonal form by elementary operations. Formulated here on `Type 0`
because we will make an induction using `Fin r`.
See `exists_list_transvec_mul_mul_list_transvec_eq_diagonal` for the general version (which follows
from this one and reindexing). -/
theorem exists_list_transvec_mul_mul_list_transvec_eq_diagonal_aux (n : Type) [Fintype n]
[DecidableEq n] (M : Matrix n n 𝕜) :
∃ (L L' : List (TransvectionStruct n 𝕜)) (D : n → 𝕜),
(L.map toMatrix).prod * M * (L'.map toMatrix).prod = diagonal D := by
induction' hn : Fintype.card n with r IH generalizing n M
· refine ⟨List.nil, List.nil, fun _ => 1, ?_⟩
ext i j
rw [Fintype.card_eq_zero_iff] at hn
exact hn.elim' i
· have e : n ≃ Fin r ⊕ Unit := by
refine Fintype.equivOfCardEq ?_
rw [hn]
rw [@Fintype.card_sum (Fin r) Unit _ _]
simp
apply reindex_exists_list_transvec_mul_mul_list_transvec_eq_diagonal M e
apply
exists_list_transvec_mul_mul_list_transvec_eq_diagonal_induction fun N =>
IH (Fin r) N (by simp)
/-- Any matrix can be reduced to diagonal form by elementary operations. -/
theorem exists_list_transvec_mul_mul_list_transvec_eq_diagonal (M : Matrix n n 𝕜) :
∃ (L L' : List (TransvectionStruct n 𝕜)) (D : n → 𝕜),
(L.map toMatrix).prod * M * (L'.map toMatrix).prod = diagonal D := by
have e : n ≃ Fin (Fintype.card n) := Fintype.equivOfCardEq (by simp)
apply reindex_exists_list_transvec_mul_mul_list_transvec_eq_diagonal M e
apply exists_list_transvec_mul_mul_list_transvec_eq_diagonal_aux
/-- Any matrix can be written as the product of transvections, a diagonal matrix, and
transvections. -/
theorem exists_list_transvec_mul_diagonal_mul_list_transvec (M : Matrix n n 𝕜) :
∃ (L L' : List (TransvectionStruct n 𝕜)) (D : n → 𝕜),
M = (L.map toMatrix).prod * diagonal D * (L'.map toMatrix).prod := by
rcases exists_list_transvec_mul_mul_list_transvec_eq_diagonal M with ⟨L, L', D, h⟩
refine ⟨L.reverse.map TransvectionStruct.inv, L'.reverse.map TransvectionStruct.inv, D, ?_⟩
suffices
M =
(L.reverse.map (toMatrix ∘ TransvectionStruct.inv)).prod * (L.map toMatrix).prod * M *
((L'.map toMatrix).prod * (L'.reverse.map (toMatrix ∘ TransvectionStruct.inv)).prod)
by simpa [← h, Matrix.mul_assoc]
rw [reverse_inv_prod_mul_prod, prod_mul_reverse_inv_prod, Matrix.one_mul, Matrix.mul_one]
end Pivot
open Pivot TransvectionStruct
variable {n} [Fintype n]
/-- Induction principle for matrices based on transvections: if a property is true for all diagonal
matrices, all transvections, and is stable under product, then it is true for all matrices. This is
the useful way to say that matrices are generated by diagonal matrices and transvections.
We state a slightly more general version: to prove a property for a matrix `M`, it suffices to
assume that the diagonal matrices we consider have the same determinant as `M`. This is useful to
obtain similar principles for `SLₙ` or `GLₙ`. -/
theorem diagonal_transvection_induction (P : Matrix n n 𝕜 → Prop) (M : Matrix n n 𝕜)
(hdiag : ∀ D : n → 𝕜, det (diagonal D) = det M → P (diagonal D))
(htransvec : ∀ t : TransvectionStruct n 𝕜, P t.toMatrix) (hmul : ∀ A B, P A → P B → P (A * B)) :
P M := by
rcases exists_list_transvec_mul_diagonal_mul_list_transvec M with ⟨L, L', D, h⟩
have PD : P (diagonal D) := hdiag D (by simp [h])
suffices H :
∀ (L₁ L₂ : List (TransvectionStruct n 𝕜)) (E : Matrix n n 𝕜),
P E → P ((L₁.map toMatrix).prod * E * (L₂.map toMatrix).prod) by
rw [h]
apply H L L'
exact PD
intro L₁ L₂ E PE
induction' L₁ with t L₁ IH
· simp only [Matrix.one_mul, List.prod_nil, List.map]
induction' L₂ with t L₂ IH generalizing E
· simpa
· simp only [← Matrix.mul_assoc, List.prod_cons, List.map]
apply IH
exact hmul _ _ PE (htransvec _)
· simp only [Matrix.mul_assoc, List.prod_cons, List.map] at IH ⊢
exact hmul _ _ (htransvec _) IH
/-- Induction principle for invertible matrices based on transvections: if a property is true for
all invertible diagonal matrices, all transvections, and is stable under product of invertible
matrices, then it is true for all invertible matrices. This is the useful way to say that
invertible matrices are generated by invertible diagonal matrices and transvections. -/
theorem diagonal_transvection_induction_of_det_ne_zero (P : Matrix n n 𝕜 → Prop) (M : Matrix n n 𝕜)
(hMdet : det M ≠ 0) (hdiag : ∀ D : n → 𝕜, det (diagonal D) ≠ 0 → P (diagonal D))
(htransvec : ∀ t : TransvectionStruct n 𝕜, P t.toMatrix)
(hmul : ∀ A B, det A ≠ 0 → det B ≠ 0 → P A → P B → P (A * B)) : P M := by
let Q : Matrix n n 𝕜 → Prop := fun N => det N ≠ 0 ∧ P N
have : Q M := by
apply diagonal_transvection_induction Q M
· intro D hD
have detD : det (diagonal D) ≠ 0 := by
rw [hD]
exact hMdet
exact ⟨detD, hdiag _ detD⟩
· intro t
exact ⟨by simp, htransvec t⟩
· intro A B QA QB
exact ⟨by simp [QA.1, QB.1], hmul A B QA.1 QB.1 QA.2 QB.2⟩
exact this.2
end Matrix
|
LinearAlgebra\Matrix\ZPow.lean | /-
Copyright (c) 2021 Yakov Pechersky. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yakov Pechersky
-/
import Mathlib.Data.Int.Bitwise
import Mathlib.LinearAlgebra.Matrix.NonsingularInverse
import Mathlib.LinearAlgebra.Matrix.Symmetric
/-!
# Integer powers of square matrices
In this file, we define integer power of matrices, relying on
the nonsingular inverse definition for negative powers.
## Implementation details
The main definition is a direct recursive call on the integer inductive type,
as provided by the `DivInvMonoid.Pow` default implementation.
The lemma names are taken from `Algebra.GroupWithZero.Power`.
## Tags
matrix inverse, matrix powers
-/
open Matrix
namespace Matrix
variable {n' : Type*} [DecidableEq n'] [Fintype n'] {R : Type*} [CommRing R]
local notation "M" => Matrix n' n' R
noncomputable instance : DivInvMonoid M :=
{ show Monoid M by infer_instance, show Inv M by infer_instance with }
section NatPow
@[simp]
theorem inv_pow' (A : M) (n : ℕ) : A⁻¹ ^ n = (A ^ n)⁻¹ := by
induction' n with n ih
· simp
· rw [pow_succ A, mul_inv_rev, ← ih, ← pow_succ']
theorem pow_sub' (A : M) {m n : ℕ} (ha : IsUnit A.det) (h : n ≤ m) :
A ^ (m - n) = A ^ m * (A ^ n)⁻¹ := by
rw [← tsub_add_cancel_of_le h, pow_add, Matrix.mul_assoc, mul_nonsing_inv,
tsub_add_cancel_of_le h, Matrix.mul_one]
simpa using ha.pow n
theorem pow_inv_comm' (A : M) (m n : ℕ) : A⁻¹ ^ m * A ^ n = A ^ n * A⁻¹ ^ m := by
induction' n with n IH generalizing m
· simp
cases' m with m m
· simp
rcases nonsing_inv_cancel_or_zero A with (⟨h, h'⟩ | h)
· calc
A⁻¹ ^ (m + 1) * A ^ (n + 1) = A⁻¹ ^ m * (A⁻¹ * A) * A ^ n := by
simp only [pow_succ A⁻¹, pow_succ' A, Matrix.mul_assoc]
_ = A ^ n * A⁻¹ ^ m := by simp only [h, Matrix.mul_one, Matrix.one_mul, IH m]
_ = A ^ n * (A * A⁻¹) * A⁻¹ ^ m := by simp only [h', Matrix.mul_one, Matrix.one_mul]
_ = A ^ (n + 1) * A⁻¹ ^ (m + 1) := by
simp only [pow_succ A, pow_succ' A⁻¹, Matrix.mul_assoc]
· simp [h]
end NatPow
section ZPow
open Int
@[simp]
theorem one_zpow : ∀ n : ℤ, (1 : M) ^ n = 1
| (n : ℕ) => by rw [zpow_natCast, one_pow]
| -[n+1] => by rw [zpow_negSucc, one_pow, inv_one]
theorem zero_zpow : ∀ z : ℤ, z ≠ 0 → (0 : M) ^ z = 0
| (n : ℕ), h => by
rw [zpow_natCast, zero_pow]
exact mod_cast h
| -[n+1], _ => by simp [zero_pow n.succ_ne_zero]
theorem zero_zpow_eq (n : ℤ) : (0 : M) ^ n = if n = 0 then 1 else 0 := by
split_ifs with h
· rw [h, zpow_zero]
· rw [zero_zpow _ h]
theorem inv_zpow (A : M) : ∀ n : ℤ, A⁻¹ ^ n = (A ^ n)⁻¹
| (n : ℕ) => by rw [zpow_natCast, zpow_natCast, inv_pow']
| -[n+1] => by rw [zpow_negSucc, zpow_negSucc, inv_pow']
@[simp]
theorem zpow_neg_one (A : M) : A ^ (-1 : ℤ) = A⁻¹ := by
convert DivInvMonoid.zpow_neg' 0 A
simp only [zpow_one, Int.ofNat_zero, Int.ofNat_succ, zpow_eq_pow, zero_add]
@[simp]
theorem zpow_neg_natCast (A : M) (n : ℕ) : A ^ (-n : ℤ) = (A ^ n)⁻¹ := by
cases n
· simp
· exact DivInvMonoid.zpow_neg' _ _
@[deprecated (since := "2024-04-05")] alias zpow_neg_coe_nat := zpow_neg_natCast
theorem _root_.IsUnit.det_zpow {A : M} (h : IsUnit A.det) (n : ℤ) : IsUnit (A ^ n).det := by
cases' n with n n
· simpa using h.pow n
· simpa using h.pow n.succ
theorem isUnit_det_zpow_iff {A : M} {z : ℤ} : IsUnit (A ^ z).det ↔ IsUnit A.det ∨ z = 0 := by
induction' z using Int.induction_on with z _ z _
· simp
· rw [← Int.ofNat_succ, zpow_natCast, det_pow, isUnit_pow_succ_iff, ← Int.ofNat_zero,
Int.ofNat_inj]
simp
· rw [← neg_add', ← Int.ofNat_succ, zpow_neg_natCast, isUnit_nonsing_inv_det_iff, det_pow,
isUnit_pow_succ_iff, neg_eq_zero, ← Int.ofNat_zero, Int.ofNat_inj]
simp
theorem zpow_neg {A : M} (h : IsUnit A.det) : ∀ n : ℤ, A ^ (-n) = (A ^ n)⁻¹
| (n : ℕ) => zpow_neg_natCast _ _
| -[n+1] => by
rw [zpow_negSucc, neg_negSucc, zpow_natCast, nonsing_inv_nonsing_inv]
rw [det_pow]
exact h.pow _
theorem inv_zpow' {A : M} (h : IsUnit A.det) (n : ℤ) : A⁻¹ ^ n = A ^ (-n) := by
rw [zpow_neg h, inv_zpow]
theorem zpow_add_one {A : M} (h : IsUnit A.det) : ∀ n : ℤ, A ^ (n + 1) = A ^ n * A
| (n : ℕ) => by simp only [← Nat.cast_succ, pow_succ, zpow_natCast]
| -[n+1] =>
calc
A ^ (-(n + 1) + 1 : ℤ) = (A ^ n)⁻¹ := by
rw [neg_add, neg_add_cancel_right, zpow_neg h, zpow_natCast]
_ = (A * A ^ n)⁻¹ * A := by
rw [mul_inv_rev, Matrix.mul_assoc, nonsing_inv_mul _ h, Matrix.mul_one]
_ = A ^ (-(n + 1 : ℤ)) * A := by
rw [zpow_neg h, ← Int.ofNat_succ, zpow_natCast, pow_succ']
theorem zpow_sub_one {A : M} (h : IsUnit A.det) (n : ℤ) : A ^ (n - 1) = A ^ n * A⁻¹ :=
calc
A ^ (n - 1) = A ^ (n - 1) * A * A⁻¹ := by
rw [mul_assoc, mul_nonsing_inv _ h, mul_one]
_ = A ^ n * A⁻¹ := by rw [← zpow_add_one h, sub_add_cancel]
theorem zpow_add {A : M} (ha : IsUnit A.det) (m n : ℤ) : A ^ (m + n) = A ^ m * A ^ n := by
induction n using Int.induction_on with
| hz => simp
| hp n ihn => simp only [← add_assoc, zpow_add_one ha, ihn, mul_assoc]
| hn n ihn => rw [zpow_sub_one ha, ← mul_assoc, ← ihn, ← zpow_sub_one ha, add_sub_assoc]
theorem zpow_add_of_nonpos {A : M} {m n : ℤ} (hm : m ≤ 0) (hn : n ≤ 0) :
A ^ (m + n) = A ^ m * A ^ n := by
rcases nonsing_inv_cancel_or_zero A with (⟨h, _⟩ | h)
· exact zpow_add (isUnit_det_of_left_inverse h) m n
· obtain ⟨k, rfl⟩ := exists_eq_neg_ofNat hm
obtain ⟨l, rfl⟩ := exists_eq_neg_ofNat hn
simp_rw [← neg_add, ← Int.ofNat_add, zpow_neg_natCast, ← inv_pow', h, pow_add]
theorem zpow_add_of_nonneg {A : M} {m n : ℤ} (hm : 0 ≤ m) (hn : 0 ≤ n) :
A ^ (m + n) = A ^ m * A ^ n := by
obtain ⟨k, rfl⟩ := eq_ofNat_of_zero_le hm
obtain ⟨l, rfl⟩ := eq_ofNat_of_zero_le hn
rw [← Int.ofNat_add, zpow_natCast, zpow_natCast, zpow_natCast, pow_add]
theorem zpow_one_add {A : M} (h : IsUnit A.det) (i : ℤ) : A ^ (1 + i) = A * A ^ i := by
rw [zpow_add h, zpow_one]
theorem SemiconjBy.zpow_right {A X Y : M} (hx : IsUnit X.det) (hy : IsUnit Y.det)
(h : SemiconjBy A X Y) : ∀ m : ℤ, SemiconjBy A (X ^ m) (Y ^ m)
| (n : ℕ) => by simp [h.pow_right n]
| -[n+1] => by
have hx' : IsUnit (X ^ n.succ).det := by
rw [det_pow]
exact hx.pow n.succ
have hy' : IsUnit (Y ^ n.succ).det := by
rw [det_pow]
exact hy.pow n.succ
rw [zpow_negSucc, zpow_negSucc, nonsing_inv_apply _ hx', nonsing_inv_apply _ hy', SemiconjBy]
refine (isRegular_of_isLeftRegular_det hy'.isRegular.left).left ?_
dsimp only
rw [← mul_assoc, ← (h.pow_right n.succ).eq, mul_assoc, mul_smul,
mul_adjugate, ← Matrix.mul_assoc,
mul_smul (Y ^ _) (↑hy'.unit⁻¹ : R), mul_adjugate, smul_smul, smul_smul, hx'.val_inv_mul,
hy'.val_inv_mul, one_smul, Matrix.mul_one, Matrix.one_mul]
theorem Commute.zpow_right {A B : M} (h : Commute A B) (m : ℤ) : Commute A (B ^ m) := by
rcases nonsing_inv_cancel_or_zero B with (⟨hB, _⟩ | hB)
· refine SemiconjBy.zpow_right ?_ ?_ h _ <;> exact isUnit_det_of_left_inverse hB
· cases m
· simpa using h.pow_right _
· simp [← inv_pow', hB]
theorem Commute.zpow_left {A B : M} (h : Commute A B) (m : ℤ) : Commute (A ^ m) B :=
(Commute.zpow_right h.symm m).symm
theorem Commute.zpow_zpow {A B : M} (h : Commute A B) (m n : ℤ) : Commute (A ^ m) (B ^ n) :=
Commute.zpow_right (Commute.zpow_left h _) _
theorem Commute.zpow_self (A : M) (n : ℤ) : Commute (A ^ n) A :=
Commute.zpow_left (Commute.refl A) _
theorem Commute.self_zpow (A : M) (n : ℤ) : Commute A (A ^ n) :=
Commute.zpow_right (Commute.refl A) _
theorem Commute.zpow_zpow_self (A : M) (m n : ℤ) : Commute (A ^ m) (A ^ n) :=
Commute.zpow_zpow (Commute.refl A) _ _
theorem zpow_add_one_of_ne_neg_one {A : M} : ∀ n : ℤ, n ≠ -1 → A ^ (n + 1) = A ^ n * A
| (n : ℕ), _ => by simp only [pow_succ, ← Nat.cast_succ, zpow_natCast]
| -1, h => absurd rfl h
| -((n : ℕ) + 2), _ => by
rcases nonsing_inv_cancel_or_zero A with (⟨h, _⟩ | h)
· apply zpow_add_one (isUnit_det_of_left_inverse h)
· show A ^ (-((n + 1 : ℕ) : ℤ)) = A ^ (-((n + 2 : ℕ) : ℤ)) * A
simp_rw [zpow_neg_natCast, ← inv_pow', h, zero_pow $ Nat.succ_ne_zero _, zero_mul]
theorem zpow_mul (A : M) (h : IsUnit A.det) : ∀ m n : ℤ, A ^ (m * n) = (A ^ m) ^ n
| (m : ℕ), (n : ℕ) => by rw [zpow_natCast, zpow_natCast, ← pow_mul, ← zpow_natCast, Int.ofNat_mul]
| (m : ℕ), -[n+1] => by
rw [zpow_natCast, zpow_negSucc, ← pow_mul, ofNat_mul_negSucc, zpow_neg_natCast]
| -[m+1], (n : ℕ) => by
rw [zpow_natCast, zpow_negSucc, ← inv_pow', ← pow_mul, negSucc_mul_ofNat, zpow_neg_natCast,
inv_pow']
| -[m+1], -[n+1] => by
rw [zpow_negSucc, zpow_negSucc, negSucc_mul_negSucc, ← Int.ofNat_mul, zpow_natCast, inv_pow', ←
pow_mul, nonsing_inv_nonsing_inv]
rw [det_pow]
exact h.pow _
theorem zpow_mul' (A : M) (h : IsUnit A.det) (m n : ℤ) : A ^ (m * n) = (A ^ n) ^ m := by
rw [mul_comm, zpow_mul _ h]
@[simp, norm_cast]
theorem coe_units_zpow (u : Mˣ) : ∀ n : ℤ, ((u ^ n : Mˣ) : M) = (u : M) ^ n
| (n : ℕ) => by rw [zpow_natCast, zpow_natCast, Units.val_pow_eq_pow_val]
| -[k+1] => by
rw [zpow_negSucc, zpow_negSucc, ← inv_pow, u⁻¹.val_pow_eq_pow_val, ← inv_pow', coe_units_inv]
theorem zpow_ne_zero_of_isUnit_det [Nonempty n'] [Nontrivial R] {A : M} (ha : IsUnit A.det)
(z : ℤ) : A ^ z ≠ 0 := by
have := ha.det_zpow z
contrapose! this
rw [this, det_zero ‹_›]
exact not_isUnit_zero
theorem zpow_sub {A : M} (ha : IsUnit A.det) (z1 z2 : ℤ) : A ^ (z1 - z2) = A ^ z1 / A ^ z2 := by
rw [sub_eq_add_neg, zpow_add ha, zpow_neg ha, div_eq_mul_inv]
theorem Commute.mul_zpow {A B : M} (h : Commute A B) : ∀ i : ℤ, (A * B) ^ i = A ^ i * B ^ i
| (n : ℕ) => by simp [h.mul_pow n]
| -[n+1] => by
rw [zpow_negSucc, zpow_negSucc, zpow_negSucc, ← mul_inv_rev,
h.mul_pow n.succ, (h.pow_pow _ _).eq]
theorem zpow_neg_mul_zpow_self (n : ℤ) {A : M} (h : IsUnit A.det) : A ^ (-n) * A ^ n = 1 := by
rw [zpow_neg h, nonsing_inv_mul _ (h.det_zpow _)]
theorem one_div_pow {A : M} (n : ℕ) : (1 / A) ^ n = 1 / A ^ n := by simp only [one_div, inv_pow']
theorem one_div_zpow {A : M} (n : ℤ) : (1 / A) ^ n = 1 / A ^ n := by simp only [one_div, inv_zpow]
@[simp]
theorem transpose_zpow (A : M) : ∀ n : ℤ, (A ^ n)ᵀ = Aᵀ ^ n
| (n : ℕ) => by rw [zpow_natCast, zpow_natCast, transpose_pow]
| -[n+1] => by rw [zpow_negSucc, zpow_negSucc, transpose_nonsing_inv, transpose_pow]
@[simp]
theorem conjTranspose_zpow [StarRing R] (A : M) : ∀ n : ℤ, (A ^ n)ᴴ = Aᴴ ^ n
| (n : ℕ) => by rw [zpow_natCast, zpow_natCast, conjTranspose_pow]
| -[n+1] => by rw [zpow_negSucc, zpow_negSucc, conjTranspose_nonsing_inv, conjTranspose_pow]
theorem IsSymm.zpow {A : M} (h : A.IsSymm) (k : ℤ) :
(A ^ k).IsSymm := by
rw [IsSymm, transpose_zpow, h]
end ZPow
end Matrix
|
LinearAlgebra\Matrix\Charpoly\Basic.lean | /-
Copyright (c) 2020 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison
-/
import Mathlib.LinearAlgebra.Matrix.Adjugate
import Mathlib.RingTheory.PolynomialAlgebra
/-!
# Characteristic polynomials and the Cayley-Hamilton theorem
We define characteristic polynomials of matrices and
prove the Cayley–Hamilton theorem over arbitrary commutative rings.
See the file `Mathlib/LinearAlgebra/Matrix/Charpoly/Coeff.lean` for corollaries of this theorem.
## Main definitions
* `Matrix.charpoly` is the characteristic polynomial of a matrix.
## Implementation details
We follow a nice proof from http://drorbn.net/AcademicPensieve/2015-12/CayleyHamilton.pdf
-/
noncomputable section
universe u v w
namespace Matrix
open Finset Matrix Polynomial
variable {R S : Type*} [CommRing R] [CommRing S]
variable {m n : Type*} [DecidableEq m] [DecidableEq n] [Fintype m] [Fintype n]
variable (M₁₁ : Matrix m m R) (M₁₂ : Matrix m n R) (M₂₁ : Matrix n m R) (M₂₂ M : Matrix n n R)
variable (i j : n)
/-- The "characteristic matrix" of `M : Matrix n n R` is the matrix of polynomials $t I - M$.
The determinant of this matrix is the characteristic polynomial.
-/
def charmatrix (M : Matrix n n R) : Matrix n n R[X] :=
Matrix.scalar n (X : R[X]) - (C : R →+* R[X]).mapMatrix M
theorem charmatrix_apply :
charmatrix M i j = (Matrix.diagonal fun _ : n => X) i j - C (M i j) :=
rfl
@[simp]
theorem charmatrix_apply_eq : charmatrix M i i = (X : R[X]) - C (M i i) := by
simp only [charmatrix, RingHom.mapMatrix_apply, sub_apply, scalar_apply, map_apply,
diagonal_apply_eq]
@[simp]
theorem charmatrix_apply_ne (h : i ≠ j) : charmatrix M i j = -C (M i j) := by
simp only [charmatrix, RingHom.mapMatrix_apply, sub_apply, scalar_apply, diagonal_apply_ne _ h,
map_apply, sub_eq_neg_self]
theorem matPolyEquiv_charmatrix : matPolyEquiv (charmatrix M) = X - C M := by
ext k i j
simp only [matPolyEquiv_coeff_apply, coeff_sub, Pi.sub_apply]
by_cases h : i = j
· subst h
rw [charmatrix_apply_eq, coeff_sub]
simp only [coeff_X, coeff_C]
split_ifs <;> simp
· rw [charmatrix_apply_ne _ _ _ h, coeff_X, coeff_neg, coeff_C, coeff_C]
split_ifs <;> simp [h]
theorem charmatrix_reindex (e : n ≃ m) :
charmatrix (reindex e e M) = reindex e e (charmatrix M) := by
ext i j x
by_cases h : i = j
all_goals simp [h]
lemma charmatrix_map (M : Matrix n n R) (f : R →+* S) :
charmatrix (M.map f) = (charmatrix M).map (Polynomial.map f) := by
ext i j
by_cases h : i = j <;> simp [h, charmatrix, diagonal]
lemma charmatrix_fromBlocks :
charmatrix (fromBlocks M₁₁ M₁₂ M₂₁ M₂₂) =
fromBlocks (charmatrix M₁₁) (- M₁₂.map C) (- M₂₁.map C) (charmatrix M₂₂) := by
simp only [charmatrix]
ext (i|i) (j|j) : 2 <;> simp [diagonal]
/-- The characteristic polynomial of a matrix `M` is given by $\det (t I - M)$.
-/
def charpoly (M : Matrix n n R) : R[X] :=
(charmatrix M).det
theorem charpoly_reindex (e : n ≃ m)
(M : Matrix n n R) : (reindex e e M).charpoly = M.charpoly := by
unfold Matrix.charpoly
rw [charmatrix_reindex, Matrix.det_reindex_self]
lemma charpoly_map (M : Matrix n n R) (f : R →+* S) :
(M.map f).charpoly = M.charpoly.map f := by
rw [charpoly, charmatrix_map, ← Polynomial.coe_mapRingHom, charpoly, RingHom.map_det,
RingHom.mapMatrix_apply]
@[simp]
lemma charpoly_fromBlocks_zero₁₂ :
(fromBlocks M₁₁ 0 M₂₁ M₂₂).charpoly = (M₁₁.charpoly * M₂₂.charpoly) := by
simp only [charpoly, charmatrix_fromBlocks, Matrix.map_zero _ (Polynomial.C_0), neg_zero,
det_fromBlocks_zero₁₂]
@[simp]
lemma charpoly_fromBlocks_zero₂₁ :
(fromBlocks M₁₁ M₁₂ 0 M₂₂).charpoly = (M₁₁.charpoly * M₂₂.charpoly) := by
simp only [charpoly, charmatrix_fromBlocks, Matrix.map_zero _ (Polynomial.C_0), neg_zero,
det_fromBlocks_zero₂₁]
-- This proof follows http://drorbn.net/AcademicPensieve/2015-12/CayleyHamilton.pdf
/-- The **Cayley-Hamilton Theorem**, that the characteristic polynomial of a matrix,
applied to the matrix itself, is zero.
This holds over any commutative ring.
See `LinearMap.aeval_self_charpoly` for the equivalent statement about endomorphisms.
-/
theorem aeval_self_charpoly (M : Matrix n n R) : aeval M M.charpoly = 0 := by
-- We begin with the fact $χ_M(t) I = adjugate (t I - M) * (t I - M)$,
-- as an identity in `Matrix n n R[X]`.
have h : M.charpoly • (1 : Matrix n n R[X]) = adjugate (charmatrix M) * charmatrix M :=
(adjugate_mul _).symm
-- Using the algebra isomorphism `Matrix n n R[X] ≃ₐ[R] Polynomial (Matrix n n R)`,
-- we have the same identity in `Polynomial (Matrix n n R)`.
apply_fun matPolyEquiv at h
simp only [_root_.map_mul, matPolyEquiv_charmatrix] at h
-- Because the coefficient ring `Matrix n n R` is non-commutative,
-- evaluation at `M` is not multiplicative.
-- However, any polynomial which is a product of the form $N * (t I - M)$
-- is sent to zero, because the evaluation function puts the polynomial variable
-- to the right of any coefficients, so everything telescopes.
apply_fun fun p => p.eval M at h
rw [eval_mul_X_sub_C] at h
-- Now $χ_M (t) I$, when thought of as a polynomial of matrices
-- and evaluated at some `N` is exactly $χ_M (N)$.
rw [matPolyEquiv_smul_one, eval_map] at h
-- Thus we have $χ_M(M) = 0$, which is the desired result.
exact h
end Matrix
|
LinearAlgebra\Matrix\Charpoly\Coeff.lean | /-
Copyright (c) 2020 Aaron Anderson, Jalex Stark. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Aaron Anderson, Jalex Stark
-/
import Mathlib.Algebra.Polynomial.Expand
import Mathlib.Algebra.Polynomial.Laurent
import Mathlib.LinearAlgebra.Matrix.Charpoly.Basic
import Mathlib.LinearAlgebra.Matrix.Reindex
import Mathlib.RingTheory.Polynomial.Nilpotent
/-!
# Characteristic polynomials
We give methods for computing coefficients of the characteristic polynomial.
## Main definitions
- `Matrix.charpoly_degree_eq_dim` proves that the degree of the characteristic polynomial
over a nonzero ring is the dimension of the matrix
- `Matrix.det_eq_sign_charpoly_coeff` proves that the determinant is the constant term of the
characteristic polynomial, up to sign.
- `Matrix.trace_eq_neg_charpoly_coeff` proves that the trace is the negative of the (d-1)th
coefficient of the characteristic polynomial, where d is the dimension of the matrix.
For a nonzero ring, this is the second-highest coefficient.
- `Matrix.charpolyRev` the reverse of the characteristic polynomial.
- `Matrix.reverse_charpoly` characterises the reverse of the characteristic polynomial.
-/
noncomputable section
-- porting note: whenever there was `∏ i : n, X - C (M i i)`, I replaced it with
-- `∏ i : n, (X - C (M i i))`, since otherwise Lean would parse as `(∏ i : n, X) - C (M i i)`
universe u v w z
open Finset Matrix Polynomial
variable {R : Type u} [CommRing R]
variable {n G : Type v} [DecidableEq n] [Fintype n]
variable {α β : Type v} [DecidableEq α]
variable {M : Matrix n n R}
namespace Matrix
theorem charmatrix_apply_natDegree [Nontrivial R] (i j : n) :
(charmatrix M i j).natDegree = ite (i = j) 1 0 := by
by_cases h : i = j <;> simp [h, ← degree_eq_iff_natDegree_eq_of_pos (Nat.succ_pos 0)]
theorem charmatrix_apply_natDegree_le (i j : n) :
(charmatrix M i j).natDegree ≤ ite (i = j) 1 0 := by
split_ifs with h <;> simp [h, natDegree_X_le]
variable (M)
theorem charpoly_sub_diagonal_degree_lt :
(M.charpoly - ∏ i : n, (X - C (M i i))).degree < ↑(Fintype.card n - 1) := by
rw [charpoly, det_apply', ← insert_erase (mem_univ (Equiv.refl n)),
sum_insert (not_mem_erase (Equiv.refl n) univ), add_comm]
simp only [charmatrix_apply_eq, one_mul, Equiv.Perm.sign_refl, id, Int.cast_one,
Units.val_one, add_sub_cancel_right, Equiv.coe_refl]
rw [← mem_degreeLT]
apply Submodule.sum_mem (degreeLT R (Fintype.card n - 1))
intro c hc; rw [← C_eq_intCast, C_mul']
apply Submodule.smul_mem (degreeLT R (Fintype.card n - 1)) ↑↑(Equiv.Perm.sign c)
rw [mem_degreeLT]
apply lt_of_le_of_lt degree_le_natDegree _
rw [Nat.cast_lt]
apply lt_of_le_of_lt _ (Equiv.Perm.fixed_point_card_lt_of_ne_one (ne_of_mem_erase hc))
apply le_trans (Polynomial.natDegree_prod_le univ fun i : n => charmatrix M (c i) i) _
rw [card_eq_sum_ones]; rw [sum_filter]; apply sum_le_sum
intros
apply charmatrix_apply_natDegree_le
theorem charpoly_coeff_eq_prod_coeff_of_le {k : ℕ} (h : Fintype.card n - 1 ≤ k) :
M.charpoly.coeff k = (∏ i : n, (X - C (M i i))).coeff k := by
apply eq_of_sub_eq_zero; rw [← coeff_sub]
apply Polynomial.coeff_eq_zero_of_degree_lt
apply lt_of_lt_of_le (charpoly_sub_diagonal_degree_lt M) ?_
rw [Nat.cast_le]; apply h
theorem det_of_card_zero (h : Fintype.card n = 0) (M : Matrix n n R) : M.det = 1 := by
rw [Fintype.card_eq_zero_iff] at h
suffices M = 1 by simp [this]
ext i
exact h.elim i
theorem charpoly_degree_eq_dim [Nontrivial R] (M : Matrix n n R) :
M.charpoly.degree = Fintype.card n := by
by_cases h : Fintype.card n = 0
· rw [h]
unfold charpoly
rw [det_of_card_zero]
· simp
· assumption
rw [← sub_add_cancel M.charpoly (∏ i : n, (X - C (M i i)))]
-- Porting note: added `↑` in front of `Fintype.card n`
have h1 : (∏ i : n, (X - C (M i i))).degree = ↑(Fintype.card n) := by
rw [degree_eq_iff_natDegree_eq_of_pos (Nat.pos_of_ne_zero h), natDegree_prod']
· simp_rw [natDegree_X_sub_C]
rw [← Finset.card_univ, sum_const, smul_eq_mul, mul_one]
simp_rw [(monic_X_sub_C _).leadingCoeff]
simp
rw [degree_add_eq_right_of_degree_lt]
· exact h1
rw [h1]
apply lt_trans (charpoly_sub_diagonal_degree_lt M)
rw [Nat.cast_lt]
rw [← Nat.pred_eq_sub_one]
apply Nat.pred_lt
apply h
@[simp] theorem charpoly_natDegree_eq_dim [Nontrivial R] (M : Matrix n n R) :
M.charpoly.natDegree = Fintype.card n :=
natDegree_eq_of_degree_eq_some (charpoly_degree_eq_dim M)
theorem charpoly_monic (M : Matrix n n R) : M.charpoly.Monic := by
nontriviality R -- Porting note: was simply `nontriviality`
by_cases h : Fintype.card n = 0
· rw [charpoly, det_of_card_zero h]
apply monic_one
have mon : (∏ i : n, (X - C (M i i))).Monic := by
apply monic_prod_of_monic univ fun i : n => X - C (M i i)
simp [monic_X_sub_C]
rw [← sub_add_cancel (∏ i : n, (X - C (M i i))) M.charpoly] at mon
rw [Monic] at *
rwa [leadingCoeff_add_of_degree_lt] at mon
rw [charpoly_degree_eq_dim]
rw [← neg_sub]
rw [degree_neg]
apply lt_trans (charpoly_sub_diagonal_degree_lt M)
rw [Nat.cast_lt]
rw [← Nat.pred_eq_sub_one]
apply Nat.pred_lt
apply h
/-- See also `Matrix.coeff_charpolyRev_eq_neg_trace`. -/
theorem trace_eq_neg_charpoly_coeff [Nonempty n] (M : Matrix n n R) :
trace M = -M.charpoly.coeff (Fintype.card n - 1) := by
rw [charpoly_coeff_eq_prod_coeff_of_le _ le_rfl, Fintype.card,
prod_X_sub_C_coeff_card_pred univ (fun i : n => M i i) Fintype.card_pos, neg_neg, trace]
simp_rw [diag_apply]
theorem matPolyEquiv_symm_map_eval (M : (Matrix n n R)[X]) (r : R) :
(matPolyEquiv.symm M).map (eval r) = M.eval (scalar n r) := by
suffices ((aeval r).mapMatrix.comp matPolyEquiv.symm.toAlgHom : (Matrix n n R)[X] →ₐ[R] _) =
(eval₂AlgHom' (AlgHom.id R _) (scalar n r)
fun x => (scalar_commute _ (Commute.all _) _).symm) from
DFunLike.congr_fun this M
ext : 1
· ext M : 1
simp [Function.comp]
· simp [smul_eq_diagonal_mul]
theorem matPolyEquiv_eval_eq_map (M : Matrix n n R[X]) (r : R) :
(matPolyEquiv M).eval (scalar n r) = M.map (eval r) := by
simpa only [AlgEquiv.symm_apply_apply] using (matPolyEquiv_symm_map_eval (matPolyEquiv M) r).symm
-- I feel like this should use `Polynomial.algHom_eval₂_algebraMap`
theorem matPolyEquiv_eval (M : Matrix n n R[X]) (r : R) (i j : n) :
(matPolyEquiv M).eval (scalar n r) i j = (M i j).eval r := by
rw [matPolyEquiv_eval_eq_map, map_apply]
theorem eval_det (M : Matrix n n R[X]) (r : R) :
Polynomial.eval r M.det = (Polynomial.eval (scalar n r) (matPolyEquiv M)).det := by
rw [Polynomial.eval, ← coe_eval₂RingHom, RingHom.map_det]
apply congr_arg det
ext
symm
-- Porting note: `exact` was `convert`
exact matPolyEquiv_eval _ _ _ _
theorem det_eq_sign_charpoly_coeff (M : Matrix n n R) :
M.det = (-1) ^ Fintype.card n * M.charpoly.coeff 0 := by
rw [coeff_zero_eq_eval_zero, charpoly, eval_det, matPolyEquiv_charmatrix, ← det_smul]
simp
lemma eval_det_add_X_smul (A : Matrix n n R[X]) (M : Matrix n n R) :
(det (A + (X : R[X]) • M.map C)).eval 0 = (det A).eval 0 := by
simp only [eval_det, map_zero, map_add, eval_add, Algebra.smul_def, _root_.map_mul]
simp only [Algebra.algebraMap_eq_smul_one, matPolyEquiv_smul_one, map_X, X_mul, eval_mul_X,
mul_zero, add_zero]
lemma derivative_det_one_add_X_smul_aux {n} (M : Matrix (Fin n) (Fin n) R) :
(derivative <| det (1 + (X : R[X]) • M.map C)).eval 0 = trace M := by
induction n with
| zero => simp
| succ n IH =>
rw [det_succ_row_zero, map_sum, eval_finset_sum]
simp only [add_apply, smul_apply, map_apply, smul_eq_mul, X_mul_C, submatrix_add,
submatrix_smul, Pi.add_apply, Pi.smul_apply, submatrix_map, derivative_mul, map_add,
derivative_C, zero_mul, derivative_X, mul_one, zero_add, eval_add, eval_mul, eval_C, eval_X,
mul_zero, add_zero, eval_det_add_X_smul, eval_pow, eval_neg, eval_one]
rw [Finset.sum_eq_single 0]
· simp only [Fin.val_zero, pow_zero, derivative_one, eval_zero, one_apply_eq, eval_one,
mul_one, zero_add, one_mul, Fin.succAbove_zero, submatrix_one _ (Fin.succ_injective _),
det_one, IH, trace_submatrix_succ]
· intro i _ hi
cases n with
| zero => exact (hi (Subsingleton.elim i 0)).elim
| succ n =>
simp only [one_apply_ne' hi, eval_zero, mul_zero, zero_add, zero_mul, add_zero]
rw [det_eq_zero_of_column_eq_zero 0, eval_zero, mul_zero]
intro j
rw [submatrix_apply, Fin.succAbove_of_castSucc_lt, one_apply_ne]
· exact (bne_iff_ne (Fin.succ j) (Fin.castSucc 0)).mp rfl
· rw [Fin.castSucc_zero]; exact lt_of_le_of_ne (Fin.zero_le _) hi.symm
· exact fun H ↦ (H <| Finset.mem_univ _).elim
/-- The derivative of `det (1 + M X)` at `0` is the trace of `M`. -/
lemma derivative_det_one_add_X_smul (M : Matrix n n R) :
(derivative <| det (1 + (X : R[X]) • M.map C)).eval 0 = trace M := by
let e := Matrix.reindexLinearEquiv R R (Fintype.equivFin n) (Fintype.equivFin n)
rw [← Matrix.det_reindexLinearEquiv_self R[X] (Fintype.equivFin n)]
convert derivative_det_one_add_X_smul_aux (e M)
· ext; simp [e]
· delta trace
rw [← (Fintype.equivFin n).symm.sum_comp]
simp_rw [e, reindexLinearEquiv_apply, reindex_apply, diag_apply, submatrix_apply]
lemma coeff_det_one_add_X_smul_one (M : Matrix n n R) :
(det (1 + (X : R[X]) • M.map C)).coeff 1 = trace M := by
simp only [← derivative_det_one_add_X_smul, ← coeff_zero_eq_eval_zero,
coeff_derivative, zero_add, Nat.cast_zero, mul_one]
lemma det_one_add_X_smul (M : Matrix n n R) :
det (1 + (X : R[X]) • M.map C) =
(1 : R[X]) + trace M • X + (det (1 + (X : R[X]) • M.map C)).divX.divX * X ^ 2 := by
rw [Algebra.smul_def (trace M), ← C_eq_algebraMap, pow_two, ← mul_assoc, add_assoc,
← add_mul, ← coeff_det_one_add_X_smul_one, ← coeff_divX, add_comm (C _), divX_mul_X_add,
add_comm (1 : R[X]), ← C.map_one]
convert (divX_mul_X_add _).symm
rw [coeff_zero_eq_eval_zero, eval_det_add_X_smul, det_one, eval_one]
/-- The first two terms of the taylor expansion of `det (1 + r • M)` at `r = 0`. -/
lemma det_one_add_smul (r : R) (M : Matrix n n R) :
det (1 + r • M) =
1 + trace M * r + (det (1 + (X : R[X]) • M.map C)).divX.divX.eval r * r ^ 2 := by
simpa [eval_det, ← smul_eq_mul_diagonal] using congr_arg (eval r) (Matrix.det_one_add_X_smul M)
end Matrix
variable {p : ℕ} [Fact p.Prime]
theorem matPolyEquiv_eq_X_pow_sub_C {K : Type*} (k : ℕ) [Field K] (M : Matrix n n K) :
matPolyEquiv ((expand K k : K[X] →+* K[X]).mapMatrix (charmatrix (M ^ k))) =
X ^ k - C (M ^ k) := by
-- Porting note: `i` and `j` are used later on, but were not mentioned in mathlib3
ext m i j
rw [coeff_sub, coeff_C, matPolyEquiv_coeff_apply, RingHom.mapMatrix_apply, Matrix.map_apply,
AlgHom.coe_toRingHom, DMatrix.sub_apply, coeff_X_pow]
by_cases hij : i = j
· rw [hij, charmatrix_apply_eq, map_sub, expand_C, expand_X, coeff_sub, coeff_X_pow, coeff_C]
-- Porting note: the second `Matrix.` was `DMatrix.`
split_ifs with mp m0 <;> simp only [Matrix.one_apply_eq, Matrix.zero_apply]
· rw [charmatrix_apply_ne _ _ _ hij, map_neg, expand_C, coeff_neg, coeff_C]
split_ifs with m0 mp <;>
-- Porting note: again, the first `Matrix.` that was `DMatrix.`
simp only [hij, zero_sub, Matrix.zero_apply, sub_zero, neg_zero, Matrix.one_apply_ne, Ne,
not_false_iff]
namespace Matrix
/-- Any matrix polynomial `p` is equivalent under evaluation to `p %ₘ M.charpoly`; that is, `p`
is equivalent to a polynomial with degree less than the dimension of the matrix. -/
theorem aeval_eq_aeval_mod_charpoly (M : Matrix n n R) (p : R[X]) :
aeval M p = aeval M (p %ₘ M.charpoly) :=
(aeval_modByMonic_eq_self_of_root M.charpoly_monic M.aeval_self_charpoly).symm
/-- Any matrix power can be computed as the sum of matrix powers less than `Fintype.card n`.
TODO: add the statement for negative powers phrased with `zpow`. -/
theorem pow_eq_aeval_mod_charpoly (M : Matrix n n R) (k : ℕ) :
M ^ k = aeval M (X ^ k %ₘ M.charpoly) := by rw [← aeval_eq_aeval_mod_charpoly, map_pow, aeval_X]
section Ideal
theorem coeff_charpoly_mem_ideal_pow {I : Ideal R} (h : ∀ i j, M i j ∈ I) (k : ℕ) :
M.charpoly.coeff k ∈ I ^ (Fintype.card n - k) := by
delta charpoly
rw [Matrix.det_apply, finset_sum_coeff]
apply sum_mem
rintro c -
rw [coeff_smul, Submodule.smul_mem_iff']
have : ∑ x : n, 1 = Fintype.card n := by rw [Finset.sum_const, card_univ, smul_eq_mul, mul_one]
rw [← this]
apply coeff_prod_mem_ideal_pow_tsub
rintro i - (_ | k)
· rw [tsub_zero, pow_one, charmatrix_apply, coeff_sub, ← smul_one_eq_diagonal, smul_apply,
smul_eq_mul, coeff_X_mul_zero, coeff_C_zero, zero_sub]
apply neg_mem -- Porting note: was `rw [neg_mem_iff]`, but Lean could not synth `NegMemClass`
exact h (c i) i
· rw [add_comm, tsub_self_add, pow_zero, Ideal.one_eq_top]
exact Submodule.mem_top
end Ideal
section reverse
open Polynomial
open LaurentPolynomial hiding C
/-- The reverse of the characteristic polynomial of a matrix.
It has some advantages over the characteristic polynomial, including the fact that it can be
extended to infinite dimensions (for appropriate operators). In such settings it is known as the
"characteristic power series". -/
def charpolyRev (M : Matrix n n R) : R[X] := det (1 - (X : R[X]) • M.map C)
lemma reverse_charpoly (M : Matrix n n R) :
M.charpoly.reverse = M.charpolyRev := by
nontriviality R
let t : R[T;T⁻¹] := T 1
let t_inv : R[T;T⁻¹] := T (-1)
let p : R[T;T⁻¹] := det (scalar n t - M.map LaurentPolynomial.C)
let q : R[T;T⁻¹] := det (1 - scalar n t * M.map LaurentPolynomial.C)
have ht : t_inv * t = 1 := by rw [← T_add, add_left_neg, T_zero]
have hp : toLaurentAlg M.charpoly = p := by
simp [p, charpoly, charmatrix, AlgHom.map_det, map_sub, map_smul']
have hq : toLaurentAlg M.charpolyRev = q := by
simp [q, charpolyRev, AlgHom.map_det, map_sub, map_smul', smul_eq_diagonal_mul]
suffices t_inv ^ Fintype.card n * p = invert q by
apply toLaurent_injective
rwa [toLaurent_reverse, ← coe_toLaurentAlg, hp, hq, ← involutive_invert.injective.eq_iff,
_root_.map_mul, involutive_invert p, charpoly_natDegree_eq_dim,
← mul_one (Fintype.card n : ℤ), ← T_pow, map_pow, invert_T, mul_comm]
rw [← det_smul, smul_sub, scalar_apply, ← diagonal_smul, Pi.smul_def, smul_eq_mul, ht,
diagonal_one, invert.map_det]
simp [t, map_smul', smul_eq_diagonal_mul]
@[simp] lemma eval_charpolyRev :
eval 0 M.charpolyRev = 1 := by
rw [charpolyRev, ← coe_evalRingHom, RingHom.map_det, ← det_one (R := R) (n := n)]
have : (1 - (X : R[X]) • M.map C).map (eval 0) = 1 := by
ext i j; rcases eq_or_ne i j with hij | hij <;> simp [hij, one_apply]
congr
@[simp] lemma coeff_charpolyRev_eq_neg_trace (M : Matrix n n R) :
coeff M.charpolyRev 1 = - trace M := by
nontriviality R
cases isEmpty_or_nonempty n
· simp [charpolyRev, coeff_one]
· simp [trace_eq_neg_charpoly_coeff M, ← M.reverse_charpoly, nextCoeff]
lemma isUnit_charpolyRev_of_isNilpotent (hM : IsNilpotent M) :
IsUnit M.charpolyRev := by
obtain ⟨k, hk⟩ := hM
replace hk : 1 - (X : R[X]) • M.map C ∣ 1 := by
convert one_sub_dvd_one_sub_pow ((X : R[X]) • M.map C) k
rw [← C.mapMatrix_apply, smul_pow, ← map_pow, hk, map_zero, smul_zero, sub_zero]
apply isUnit_of_dvd_one
rw [← det_one (R := R[X]) (n := n)]
exact map_dvd detMonoidHom hk
lemma isNilpotent_trace_of_isNilpotent (hM : IsNilpotent M) :
IsNilpotent (trace M) := by
cases isEmpty_or_nonempty n
· simp
suffices IsNilpotent (coeff (charpolyRev M) 1) by simpa using this
exact (isUnit_iff_coeff_isUnit_isNilpotent.mp (isUnit_charpolyRev_of_isNilpotent hM)).2
_ one_ne_zero
lemma isNilpotent_charpoly_sub_pow_of_isNilpotent (hM : IsNilpotent M) :
IsNilpotent (M.charpoly - X ^ (Fintype.card n)) := by
nontriviality R
let p : R[X] := M.charpolyRev
have hp : p - 1 = X * (p /ₘ X) := by
conv_lhs => rw [← modByMonic_add_div p monic_X]
simp [p, modByMonic_X]
have : IsNilpotent (p /ₘ X) :=
(Polynomial.isUnit_iff'.mp (isUnit_charpolyRev_of_isNilpotent hM)).2
have aux : (M.charpoly - X ^ (Fintype.card n)).natDegree ≤ M.charpoly.natDegree :=
le_trans (natDegree_sub_le _ _) (by simp)
rw [← isNilpotent_reflect_iff aux, reflect_sub, ← reverse, M.reverse_charpoly]
simpa [hp]
end reverse
end Matrix
|
LinearAlgebra\Matrix\Charpoly\Eigs.lean | /-
Copyright (c) 2023 Mohanad Ahmed. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mohanad Ahmed
-/
import Mathlib.Algebra.Polynomial.Basic
import Mathlib.FieldTheory.IsAlgClosed.Basic
/-!
# Eigenvalues are characteristic polynomial roots.
In fields we show that:
* `Matrix.det_eq_prod_roots_charpoly_of_splits`: the determinant (in the field of the matrix)
is the product of the roots of the characteristic polynomial if the polynomial splits in the field
of the matrix.
* `Matrix.trace_eq_sum_roots_charpoly_of_splits`: the trace is the sum of the roots of the
characteristic polynomial if the polynomial splits in the field of the matrix.
In an algebraically closed field we show that:
* `Matrix.det_eq_prod_roots_charpoly`: the determinant is the product of the roots of the
characteristic polynomial.
* `Matrix.trace_eq_sum_roots_charpoly`: the trace is the sum of the roots of the
characteristic polynomial.
Note that over other fields such as `ℝ`, these results can be used by using
`A.map (algebraMap ℝ ℂ)` as the matrix, and then applying `RingHom.map_det`.
The two lemmas `Matrix.det_eq_prod_roots_charpoly` and `Matrix.trace_eq_sum_roots_charpoly` are more
commonly stated as trace is the sum of eigenvalues and determinant is the product of eigenvalues.
Mathlib has already defined eigenvalues in `LinearAlgebra.Eigenspace` as the roots of the minimal
polynomial of a linear endomorphism. These do not have correct multiplicity and cannot be used in
the theorems above. Hence we express these theorems in terms of the roots of the characteristic
polynomial directly.
## TODO
The proofs of `det_eq_prod_roots_charpoly_of_splits` and
`trace_eq_sum_roots_charpoly_of_splits` closely resemble
`norm_gen_eq_prod_roots` and `trace_gen_eq_sum_roots` respectively, but the
dependencies are not general enough to unify them. We should refactor
`Polynomial.prod_roots_eq_coeff_zero_of_monic_of_split` and
`Polynomial.sum_roots_eq_nextCoeff_of_monic_of_split` to assume splitting over an arbitrary map.
-/
variable {n : Type*} [Fintype n] [DecidableEq n]
variable {R : Type*} [Field R]
variable {A : Matrix n n R}
open Matrix Polynomial
open scoped Matrix
namespace Matrix
theorem det_eq_prod_roots_charpoly_of_splits (hAps : A.charpoly.Splits (RingHom.id R)) :
A.det = (Matrix.charpoly A).roots.prod := by
rw [det_eq_sign_charpoly_coeff, ← charpoly_natDegree_eq_dim A,
Polynomial.prod_roots_eq_coeff_zero_of_monic_of_split A.charpoly_monic hAps, ← mul_assoc,
← pow_two, pow_right_comm, neg_one_sq, one_pow, one_mul]
theorem trace_eq_sum_roots_charpoly_of_splits (hAps : A.charpoly.Splits (RingHom.id R)) :
A.trace = (Matrix.charpoly A).roots.sum := by
cases' isEmpty_or_nonempty n with h
· rw [Matrix.trace, Fintype.sum_empty, Matrix.charpoly,
det_eq_one_of_card_eq_zero (Fintype.card_eq_zero_iff.2 h), Polynomial.roots_one,
Multiset.empty_eq_zero, Multiset.sum_zero]
· rw [trace_eq_neg_charpoly_coeff, neg_eq_iff_eq_neg,
← Polynomial.sum_roots_eq_nextCoeff_of_monic_of_split A.charpoly_monic hAps, nextCoeff,
charpoly_natDegree_eq_dim, if_neg (Fintype.card_ne_zero : Fintype.card n ≠ 0)]
variable (A)
theorem det_eq_prod_roots_charpoly [IsAlgClosed R] : A.det = (Matrix.charpoly A).roots.prod :=
det_eq_prod_roots_charpoly_of_splits (IsAlgClosed.splits A.charpoly)
theorem trace_eq_sum_roots_charpoly [IsAlgClosed R] : A.trace = (Matrix.charpoly A).roots.sum :=
trace_eq_sum_roots_charpoly_of_splits (IsAlgClosed.splits A.charpoly)
end Matrix
|
LinearAlgebra\Matrix\Charpoly\FiniteField.lean | /-
Copyright (c) 2020 Aaron Anderson, Jalex Stark. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Aaron Anderson, Jalex Stark
-/
import Mathlib.LinearAlgebra.Matrix.Charpoly.Coeff
import Mathlib.FieldTheory.Finite.Basic
import Mathlib.Data.Matrix.CharP
/-!
# Results on characteristic polynomials and traces over finite fields.
-/
noncomputable section
open Polynomial Matrix
open scoped Polynomial
variable {n : Type*} [DecidableEq n] [Fintype n]
@[simp]
theorem FiniteField.Matrix.charpoly_pow_card {K : Type*} [Field K] [Fintype K] (M : Matrix n n K) :
(M ^ Fintype.card K).charpoly = M.charpoly := by
cases (isEmpty_or_nonempty n).symm
· cases' CharP.exists K with p hp; letI := hp
rcases FiniteField.card K p with ⟨⟨k, kpos⟩, ⟨hp, hk⟩⟩
haveI : Fact p.Prime := ⟨hp⟩
dsimp at hk; rw [hk]
apply (frobenius_inj K[X] p).iterate k
repeat' rw [iterate_frobenius (R := K[X])]; rw [← hk]
rw [← FiniteField.expand_card]
unfold charpoly
rw [AlgHom.map_det, ← coe_detMonoidHom, ← (detMonoidHom : Matrix n n K[X] →* K[X]).map_pow]
apply congr_arg det
refine matPolyEquiv.injective ?_
rw [map_pow, matPolyEquiv_charmatrix, hk, sub_pow_char_pow_of_commute, ← C_pow]
· exact (id (matPolyEquiv_eq_X_pow_sub_C (p ^ k) M) : _)
· exact (C M).commute_X
· exact congr_arg _ (Subsingleton.elim _ _)
@[simp]
theorem ZMod.charpoly_pow_card {p : ℕ} [Fact p.Prime] (M : Matrix n n (ZMod p)) :
(M ^ p).charpoly = M.charpoly := by
have h := FiniteField.Matrix.charpoly_pow_card M
rwa [ZMod.card] at h
theorem FiniteField.trace_pow_card {K : Type*} [Field K] [Fintype K] (M : Matrix n n K) :
trace (M ^ Fintype.card K) = trace M ^ Fintype.card K := by
cases isEmpty_or_nonempty n
· simp [Matrix.trace]
rw [Matrix.trace_eq_neg_charpoly_coeff, Matrix.trace_eq_neg_charpoly_coeff,
FiniteField.Matrix.charpoly_pow_card, FiniteField.pow_card]
theorem ZMod.trace_pow_card {p : ℕ} [Fact p.Prime] (M : Matrix n n (ZMod p)) :
trace (M ^ p) = trace M ^ p := by have h := FiniteField.trace_pow_card M; rwa [ZMod.card] at h
|
LinearAlgebra\Matrix\Charpoly\LinearMap.lean | /-
Copyright (c) 2022 Andrew Yang. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Andrew Yang
-/
import Mathlib.LinearAlgebra.Matrix.Charpoly.Coeff
import Mathlib.LinearAlgebra.Matrix.ToLin
/-!
# Cayley-Hamilton theorem for f.g. modules.
Given a fixed finite spanning set `b : ι → M` of an `R`-module `M`, we say that a matrix `M`
represents an endomorphism `f : M →ₗ[R] M` if the matrix as an endomorphism of `ι → R` commutes
with `f` via the projection `(ι → R) →ₗ[R] M` given by `b`.
We show that every endomorphism has a matrix representation, and if `f.range ≤ I • ⊤` for some
ideal `I`, we may furthermore obtain a matrix representation whose entries fall in `I`.
This is used to conclude the Cayley-Hamilton theorem for f.g. modules over arbitrary rings.
-/
variable {ι : Type*} [Fintype ι]
variable {M : Type*} [AddCommGroup M] (R : Type*) [CommRing R] [Module R M] (I : Ideal R)
variable (b : ι → M) (hb : Submodule.span R (Set.range b) = ⊤)
open Polynomial Matrix
/-- The composition of a matrix (as an endomorphism of `ι → R`) with the projection
`(ι → R) →ₗ[R] M`. -/
def PiToModule.fromMatrix [DecidableEq ι] : Matrix ι ι R →ₗ[R] (ι → R) →ₗ[R] M :=
(LinearMap.llcomp R _ _ _ (Fintype.total R R b)).comp algEquivMatrix'.symm.toLinearMap
theorem PiToModule.fromMatrix_apply [DecidableEq ι] (A : Matrix ι ι R) (w : ι → R) :
PiToModule.fromMatrix R b A w = Fintype.total R R b (A *ᵥ w) :=
rfl
theorem PiToModule.fromMatrix_apply_single_one [DecidableEq ι] (A : Matrix ι ι R) (j : ι) :
PiToModule.fromMatrix R b A (Pi.single j 1) = ∑ i : ι, A i j • b i := by
rw [PiToModule.fromMatrix_apply, Fintype.total_apply, Matrix.mulVec_single]
simp_rw [mul_one]
/-- The endomorphisms of `M` acts on `(ι → R) →ₗ[R] M`, and takes the projection
to a `(ι → R) →ₗ[R] M`. -/
def PiToModule.fromEnd : Module.End R M →ₗ[R] (ι → R) →ₗ[R] M :=
LinearMap.lcomp _ _ (Fintype.total R R b)
theorem PiToModule.fromEnd_apply (f : Module.End R M) (w : ι → R) :
PiToModule.fromEnd R b f w = f (Fintype.total R R b w) :=
rfl
theorem PiToModule.fromEnd_apply_single_one [DecidableEq ι] (f : Module.End R M) (i : ι) :
PiToModule.fromEnd R b f (Pi.single i 1) = f (b i) := by
rw [PiToModule.fromEnd_apply]
congr
convert Fintype.total_apply_single (S := R) R b i (1 : R)
rw [one_smul]
theorem PiToModule.fromEnd_injective (hb : Submodule.span R (Set.range b) = ⊤) :
Function.Injective (PiToModule.fromEnd R b) := by
intro x y e
ext m
obtain ⟨m, rfl⟩ : m ∈ LinearMap.range (Fintype.total R R b) := by
rw [(Fintype.range_total R b).trans hb]
exact Submodule.mem_top
exact (LinearMap.congr_fun e m : _)
section
variable {R} [DecidableEq ι]
/-- We say that a matrix represents an endomorphism of `M` if the matrix acting on `ι → R` is
equal to `f` via the projection `(ι → R) →ₗ[R] M` given by a fixed (spanning) set. -/
def Matrix.Represents (A : Matrix ι ι R) (f : Module.End R M) : Prop :=
PiToModule.fromMatrix R b A = PiToModule.fromEnd R b f
variable {b}
theorem Matrix.Represents.congr_fun {A : Matrix ι ι R} {f : Module.End R M} (h : A.Represents b f)
(x) : Fintype.total R R b (A *ᵥ x) = f (Fintype.total R R b x) :=
LinearMap.congr_fun h x
theorem Matrix.represents_iff {A : Matrix ι ι R} {f : Module.End R M} :
A.Represents b f ↔ ∀ x, Fintype.total R R b (A *ᵥ x) = f (Fintype.total R R b x) :=
⟨fun e x => e.congr_fun x, fun H => LinearMap.ext fun x => H x⟩
theorem Matrix.represents_iff' {A : Matrix ι ι R} {f : Module.End R M} :
A.Represents b f ↔ ∀ j, ∑ i : ι, A i j • b i = f (b j) := by
constructor
· intro h i
have := LinearMap.congr_fun h (Pi.single i 1)
rwa [PiToModule.fromEnd_apply_single_one, PiToModule.fromMatrix_apply_single_one] at this
· intro h
-- Porting note: was `ext`
refine LinearMap.pi_ext' (fun i => LinearMap.ext_ring ?_)
simp_rw [LinearMap.comp_apply, LinearMap.coe_single, PiToModule.fromEnd_apply_single_one,
PiToModule.fromMatrix_apply_single_one]
apply h
theorem Matrix.Represents.mul {A A' : Matrix ι ι R} {f f' : Module.End R M} (h : A.Represents b f)
(h' : Matrix.Represents b A' f') : (A * A').Represents b (f * f') := by
delta Matrix.Represents PiToModule.fromMatrix
rw [LinearMap.comp_apply, AlgEquiv.toLinearMap_apply, _root_.map_mul]
ext
dsimp [PiToModule.fromEnd]
rw [← h'.congr_fun, ← h.congr_fun]
rfl
theorem Matrix.Represents.one : (1 : Matrix ι ι R).Represents b 1 := by
delta Matrix.Represents PiToModule.fromMatrix
rw [LinearMap.comp_apply, AlgEquiv.toLinearMap_apply, _root_.map_one]
ext
rfl
theorem Matrix.Represents.add {A A' : Matrix ι ι R} {f f' : Module.End R M} (h : A.Represents b f)
(h' : Matrix.Represents b A' f') : (A + A').Represents b (f + f') := by
delta Matrix.Represents at h h' ⊢; rw [map_add, map_add, h, h']
theorem Matrix.Represents.zero : (0 : Matrix ι ι R).Represents b 0 := by
delta Matrix.Represents
rw [map_zero, map_zero]
theorem Matrix.Represents.smul {A : Matrix ι ι R} {f : Module.End R M} (h : A.Represents b f)
(r : R) : (r • A).Represents b (r • f) := by
delta Matrix.Represents at h ⊢
rw [_root_.map_smul, _root_.map_smul, h]
theorem Matrix.Represents.algebraMap (r : R) :
(algebraMap _ (Matrix ι ι R) r).Represents b (algebraMap _ (Module.End R M) r) := by
simpa only [Algebra.algebraMap_eq_smul_one] using Matrix.Represents.one.smul r
theorem Matrix.Represents.eq {A : Matrix ι ι R} {f f' : Module.End R M} (h : A.Represents b f)
(h' : A.Represents b f') : f = f' :=
PiToModule.fromEnd_injective R b hb (h.symm.trans h')
variable (b R)
/-- The subalgebra of `Matrix ι ι R` that consists of matrices that actually represent
endomorphisms on `M`. -/
def Matrix.isRepresentation : Subalgebra R (Matrix ι ι R) where
carrier := { A | ∃ f : Module.End R M, A.Represents b f }
mul_mem' := fun ⟨f₁, e₁⟩ ⟨f₂, e₂⟩ => ⟨f₁ * f₂, e₁.mul e₂⟩
one_mem' := ⟨1, Matrix.Represents.one⟩
add_mem' := fun ⟨f₁, e₁⟩ ⟨f₂, e₂⟩ => ⟨f₁ + f₂, e₁.add e₂⟩
zero_mem' := ⟨0, Matrix.Represents.zero⟩
algebraMap_mem' r := ⟨algebraMap _ _ r, .algebraMap _⟩
/-- The map sending a matrix to the endomorphism it represents. This is an `R`-algebra morphism. -/
noncomputable def Matrix.isRepresentation.toEnd :
Matrix.isRepresentation R b →ₐ[R] Module.End R M where
toFun A := A.2.choose
map_one' := (1 : Matrix.isRepresentation R b).2.choose_spec.eq hb Matrix.Represents.one
map_mul' A₁ A₂ := (A₁ * A₂).2.choose_spec.eq hb (A₁.2.choose_spec.mul A₂.2.choose_spec)
map_zero' := (0 : Matrix.isRepresentation R b).2.choose_spec.eq hb Matrix.Represents.zero
map_add' A₁ A₂ := (A₁ + A₂).2.choose_spec.eq hb (A₁.2.choose_spec.add A₂.2.choose_spec)
commutes' r :=
(algebraMap _ (Matrix.isRepresentation R b) r).2.choose_spec.eq hb (.algebraMap r)
theorem Matrix.isRepresentation.toEnd_represents (A : Matrix.isRepresentation R b) :
(A : Matrix ι ι R).Represents b (Matrix.isRepresentation.toEnd R b hb A) :=
A.2.choose_spec
theorem Matrix.isRepresentation.eq_toEnd_of_represents (A : Matrix.isRepresentation R b)
{f : Module.End R M} (h : (A : Matrix ι ι R).Represents b f) :
Matrix.isRepresentation.toEnd R b hb A = f :=
A.2.choose_spec.eq hb h
theorem Matrix.isRepresentation.toEnd_exists_mem_ideal (f : Module.End R M) (I : Ideal R)
(hI : LinearMap.range f ≤ I • ⊤) :
∃ M, Matrix.isRepresentation.toEnd R b hb M = f ∧ ∀ i j, M.1 i j ∈ I := by
have : ∀ x, f x ∈ LinearMap.range (Ideal.finsuppTotal ι M I b) := by
rw [Ideal.range_finsuppTotal, hb]
exact fun x => hI (LinearMap.mem_range_self f x)
choose bM' hbM' using this
let A : Matrix ι ι R := fun i j => bM' (b j) i
have : A.Represents b f := by
rw [Matrix.represents_iff']
dsimp [A]
intro j
specialize hbM' (b j)
rwa [Ideal.finsuppTotal_apply_eq_of_fintype] at hbM'
exact
⟨⟨A, f, this⟩, Matrix.isRepresentation.eq_toEnd_of_represents R b hb ⟨A, f, this⟩ this,
fun i j => (bM' (b j) i).prop⟩
theorem Matrix.isRepresentation.toEnd_surjective :
Function.Surjective (Matrix.isRepresentation.toEnd R b hb) := by
intro f
obtain ⟨M, e, -⟩ := Matrix.isRepresentation.toEnd_exists_mem_ideal R b hb f ⊤ (by simp)
exact ⟨M, e⟩
end
/-- The **Cayley-Hamilton Theorem** for f.g. modules over arbitrary rings states that for each
`R`-endomorphism `φ` of an `R`-module `M` such that `φ(M) ≤ I • M` for some ideal `I`, there
exists some `n` and some `aᵢ ∈ Iⁱ` such that `φⁿ + a₁ φⁿ⁻¹ + ⋯ + aₙ = 0`.
This is the version found in Eisenbud 4.3, which is slightly weaker than Matsumura 2.1
(this lacks the constraint on `n`), and is slightly stronger than Atiyah-Macdonald 2.4.
-/
theorem LinearMap.exists_monic_and_coeff_mem_pow_and_aeval_eq_zero_of_range_le_smul
[Module.Finite R M] (f : Module.End R M) (I : Ideal R) (hI : LinearMap.range f ≤ I • ⊤) :
∃ p : R[X], p.Monic ∧ (∀ k, p.coeff k ∈ I ^ (p.natDegree - k)) ∧ Polynomial.aeval f p = 0 := by
classical
cases subsingleton_or_nontrivial R
· exact ⟨0, Polynomial.monic_of_subsingleton _, by simp⟩
obtain ⟨s : Finset M, hs : Submodule.span R (s : Set M) = ⊤⟩ :=
Module.Finite.out (R := R) (M := M)
-- Porting note: `H` was `rfl`
obtain ⟨A, H, h⟩ :=
Matrix.isRepresentation.toEnd_exists_mem_ideal R ((↑) : s → M)
(by rw [Subtype.range_coe_subtype, Finset.setOf_mem, hs]) f I hI
rw [← H]
refine ⟨A.1.charpoly, A.1.charpoly_monic, ?_, ?_⟩
· rw [A.1.charpoly_natDegree_eq_dim]
exact coeff_charpoly_mem_ideal_pow h
· rw [Polynomial.aeval_algHom_apply,
← map_zero (Matrix.isRepresentation.toEnd R ((↑) : s → M) _)]
congr 1
ext1
rw [Polynomial.aeval_subalgebra_coe, Matrix.aeval_self_charpoly, Subalgebra.coe_zero]
theorem LinearMap.exists_monic_and_aeval_eq_zero [Module.Finite R M] (f : Module.End R M) :
∃ p : R[X], p.Monic ∧ Polynomial.aeval f p = 0 :=
(LinearMap.exists_monic_and_coeff_mem_pow_and_aeval_eq_zero_of_range_le_smul R f ⊤ (by simp)).imp
fun p h => h.imp_right And.right
|
LinearAlgebra\Matrix\Charpoly\Minpoly.lean | /-
Copyright (c) 2020 Aaron Anderson, Jalex Stark. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Aaron Anderson, Jalex Stark, Eric Wieser
-/
import Mathlib.LinearAlgebra.Matrix.Charpoly.Coeff
import Mathlib.LinearAlgebra.Matrix.ToLin
import Mathlib.RingTheory.PowerBasis
/-!
# The minimal polynomial divides the characteristic polynomial of a matrix.
This also includes some miscellaneous results about `minpoly` on matrices.
-/
noncomputable section
universe u v w
open Polynomial Matrix
variable {R : Type u} [CommRing R]
variable {n : Type v} [DecidableEq n] [Fintype n]
variable {N : Type w} [AddCommGroup N] [Module R N]
open Finset
namespace Matrix
open Matrix
variable (M : Matrix n n R)
@[simp]
theorem minpoly_toLin' : minpoly R (toLin' M) = minpoly R M :=
minpoly.algEquiv_eq (toLinAlgEquiv' : Matrix n n R ≃ₐ[R] _) M
@[simp]
theorem minpoly_toLin (b : Basis n R N) (M : Matrix n n R) :
minpoly R (toLin b b M) = minpoly R M :=
minpoly.algEquiv_eq (toLinAlgEquiv b : Matrix n n R ≃ₐ[R] _) M
theorem isIntegral : IsIntegral R M :=
⟨M.charpoly, ⟨charpoly_monic M, aeval_self_charpoly M⟩⟩
theorem minpoly_dvd_charpoly {K : Type*} [Field K] (M : Matrix n n K) : minpoly K M ∣ M.charpoly :=
minpoly.dvd _ _ (aeval_self_charpoly M)
end Matrix
namespace LinearMap
@[simp]
theorem minpoly_toMatrix' (f : (n → R) →ₗ[R] n → R) : minpoly R (toMatrix' f) = minpoly R f :=
minpoly.algEquiv_eq (toMatrixAlgEquiv' : _ ≃ₐ[R] Matrix n n R) f
@[simp]
theorem minpoly_toMatrix (b : Basis n R N) (f : N →ₗ[R] N) :
minpoly R (toMatrix b b f) = minpoly R f :=
minpoly.algEquiv_eq (toMatrixAlgEquiv b : _ ≃ₐ[R] Matrix n n R) f
end LinearMap
section PowerBasis
open Algebra
/-- The characteristic polynomial of the map `fun x => a * x` is the minimal polynomial of `a`.
In combination with `det_eq_sign_charpoly_coeff` or `trace_eq_neg_charpoly_coeff`
and a bit of rewriting, this will allow us to conclude the
field norm resp. trace of `x` is the product resp. sum of `x`'s conjugates.
-/
theorem charpoly_leftMulMatrix {S : Type*} [Ring S] [Algebra R S] (h : PowerBasis R S) :
(leftMulMatrix h.basis h.gen).charpoly = minpoly R h.gen := by
cases subsingleton_or_nontrivial R; · subsingleton
apply minpoly.unique' R h.gen (charpoly_monic _)
· apply (injective_iff_map_eq_zero (G := S) (leftMulMatrix _)).mp
(leftMulMatrix_injective h.basis)
rw [← Polynomial.aeval_algHom_apply, aeval_self_charpoly]
refine fun q hq => or_iff_not_imp_left.2 fun h0 => ?_
rw [Matrix.charpoly_degree_eq_dim, Fintype.card_fin] at hq
contrapose! hq; exact h.dim_le_degree_of_root h0 hq
end PowerBasis
|
LinearAlgebra\Matrix\Charpoly\Univ.lean | /-
Copyright (c) 2024 Johan Commelin. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johan Commelin
-/
import Mathlib.Algebra.MvPolynomial.Equiv
import Mathlib.LinearAlgebra.Matrix.Charpoly.Coeff
import Mathlib.RingTheory.MvPolynomial.Homogeneous
/-!
# The universal characteristic polynomial
In this file we define the universal characteristic polynomial `Matrix.charpoly.univ`,
which is the charactistic polynomial of the matrix with entries `Xᵢⱼ`,
and hence has coefficients that are multivariate polynomials.
It is universal in the sense that one obtains the characteristic polynomial of a matrix `M`
by evaluating the coefficients of `univ` at the entries of `M`.
We use it to show that the coeffients of the characteristic polynomial
of a matrix are homogeneous polynomials in the matrix entries.
## Main results
* `Matrix.charpoly.univ`: the universal characteristic polynomial
* `Matrix.charpoly.univ_map_eval₂Hom`: evaluating `univ` on the entries of a matrix `M`
gives the characteristic polynomial of `M`.
* `Matrix.charpoly.univ_coeff_isHomogeneous`:
the `i`-th coefficient of `univ` is a homogeneous polynomial of degree `n - i`.
-/
namespace Matrix.charpoly
variable {R S : Type*} (n : Type*) [CommRing R] [CommRing S] [Fintype n] [DecidableEq n]
variable (f : R →+* S)
variable (R)
/-- The universal characteristic polynomial for `n × n`-matrices,
is the charactistic polynomial of `Matrix.mvPolynomialX n n ℤ` with entries `Xᵢⱼ`.
Its `i`-th coefficient is a homogeneous polynomial of degree `n - i`,
see `Matrix.charpoly.univ_coeff_isHomogeneous`.
By evaluating the coefficients at the entries of a matrix `M`,
one obtains the characteristic polynomial of `M`,
see `Matrix.charpoly.univ_map_eval₂Hom`. -/
noncomputable
abbrev univ : Polynomial (MvPolynomial (n × n) R) :=
charpoly <| mvPolynomialX n n R
variable {R}
open MvPolynomial RingHomClass in
@[simp]
lemma univ_map_eval₂Hom (M : n × n → S) :
(univ R n).map (eval₂Hom f M) = charpoly (Matrix.of M.curry) := by
rw [univ, ← charpoly_map, coe_eval₂Hom, ← mvPolynomialX_map_eval₂ f (Matrix.of M.curry)]
simp only [of_apply, Function.curry_apply, Prod.mk.eta]
lemma univ_map_map :
(univ R n).map (MvPolynomial.map f) = univ S n := by
rw [MvPolynomial.map, univ_map_eval₂Hom]; rfl
@[simp]
lemma univ_coeff_eval₂Hom (M : n × n → S) (i : ℕ) :
MvPolynomial.eval₂Hom f M ((univ R n).coeff i) =
(charpoly (Matrix.of M.curry)).coeff i := by
rw [← univ_map_eval₂Hom n f M, Polynomial.coeff_map]
variable (R)
lemma univ_monic : (univ R n).Monic := charpoly_monic (mvPolynomialX n n R)
-- Porting note (#10618): no @[simp], since simp can prove this
lemma univ_natDegree [Nontrivial R] : (univ R n).natDegree = Fintype.card n :=
charpoly_natDegree_eq_dim (mvPolynomialX n n R)
@[simp]
lemma univ_coeff_card : (univ R n).coeff (Fintype.card n) = 1 := by
suffices Polynomial.coeff (univ ℤ n) (Fintype.card n) = 1 by
rw [← univ_map_map n (Int.castRingHom R), Polynomial.coeff_map, this, _root_.map_one]
rw [← univ_natDegree ℤ n]
exact (univ_monic ℤ n).leadingCoeff
open MvPolynomial in
lemma optionEquivLeft_symm_univ_isHomogeneous :
((optionEquivLeft R (n × n)).symm (univ R n)).IsHomogeneous (Fintype.card n) := by
have aux : Fintype.card n = 0 + ∑ i : n, 1 := by
simp only [zero_add, Finset.sum_const, smul_eq_mul, mul_one, Fintype.card]
simp only [aux, univ, charpoly, charmatrix, scalar_apply, RingHom.mapMatrix_apply, det_apply',
sub_apply, map_apply, of_apply, map_sum, _root_.map_mul, map_intCast, map_prod, map_sub,
optionEquivLeft_symm_apply, Polynomial.aevalTower_C, rename_X, diagonal, mvPolynomialX]
apply IsHomogeneous.sum
rintro i -
apply IsHomogeneous.mul
· apply isHomogeneous_C
· apply IsHomogeneous.prod
rintro j -
by_cases h : i j = j
· simp only [h, ↓reduceIte, Polynomial.aevalTower_X, IsHomogeneous.sub, isHomogeneous_X]
· simp only [h, ↓reduceIte, map_zero, zero_sub, (isHomogeneous_X _ _).neg]
lemma univ_coeff_isHomogeneous (i j : ℕ) (h : i + j = Fintype.card n) :
((univ R n).coeff i).IsHomogeneous j :=
(optionEquivLeft_symm_univ_isHomogeneous R n).coeff_isHomogeneous_of_optionEquivLeft_symm _ _ h
end Matrix.charpoly
|
LinearAlgebra\Matrix\Determinant\Basic.lean | /-
Copyright (c) 2018 Kenny Lau. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kenny Lau, Chris Hughes, Anne Baanen
-/
import Mathlib.Data.Matrix.Block
import Mathlib.Data.Matrix.Notation
import Mathlib.Data.Matrix.RowCol
import Mathlib.GroupTheory.GroupAction.Ring
import Mathlib.GroupTheory.Perm.Fin
import Mathlib.LinearAlgebra.Alternating.Basic
/-!
# Determinant of a matrix
This file defines the determinant of a matrix, `Matrix.det`, and its essential properties.
## Main definitions
- `Matrix.det`: the determinant of a square matrix, as a sum over permutations
- `Matrix.detRowAlternating`: the determinant, as an `AlternatingMap` in the rows of the matrix
## Main results
- `det_mul`: the determinant of `A * B` is the product of determinants
- `det_zero_of_row_eq`: the determinant is zero if there is a repeated row
- `det_block_diagonal`: the determinant of a block diagonal matrix is a product
of the blocks' determinants
## Implementation notes
It is possible to configure `simp` to compute determinants. See the file
`test/matrix.lean` for some examples.
-/
universe u v w z
open Equiv Equiv.Perm Finset Function
namespace Matrix
open Matrix
variable {m n : Type*} [DecidableEq n] [Fintype n] [DecidableEq m] [Fintype m]
variable {R : Type v} [CommRing R]
local notation "ε " σ:arg => ((sign σ : ℤ) : R)
/-- `det` is an `AlternatingMap` in the rows of the matrix. -/
def detRowAlternating : (n → R) [⋀^n]→ₗ[R] R :=
MultilinearMap.alternatization ((MultilinearMap.mkPiAlgebra R n R).compLinearMap LinearMap.proj)
/-- The determinant of a matrix given by the Leibniz formula. -/
abbrev det (M : Matrix n n R) : R :=
detRowAlternating M
theorem det_apply (M : Matrix n n R) : M.det = ∑ σ : Perm n, Equiv.Perm.sign σ • ∏ i, M (σ i) i :=
MultilinearMap.alternatization_apply _ M
-- This is what the old definition was. We use it to avoid having to change the old proofs below
theorem det_apply' (M : Matrix n n R) : M.det = ∑ σ : Perm n, ε σ * ∏ i, M (σ i) i := by
simp [det_apply, Units.smul_def]
@[simp]
theorem det_diagonal {d : n → R} : det (diagonal d) = ∏ i, d i := by
rw [det_apply']
refine (Finset.sum_eq_single 1 ?_ ?_).trans ?_
· rintro σ - h2
cases' not_forall.1 (mt Equiv.ext h2) with x h3
convert mul_zero (ε σ)
apply Finset.prod_eq_zero (mem_univ x)
exact if_neg h3
· simp
· simp
-- @[simp] -- Porting note (#10618): simp can prove this
theorem det_zero (_ : Nonempty n) : det (0 : Matrix n n R) = 0 :=
(detRowAlternating : (n → R) [⋀^n]→ₗ[R] R).map_zero
@[simp]
theorem det_one : det (1 : Matrix n n R) = 1 := by rw [← diagonal_one]; simp [-diagonal_one]
theorem det_isEmpty [IsEmpty n] {A : Matrix n n R} : det A = 1 := by simp [det_apply]
@[simp]
theorem coe_det_isEmpty [IsEmpty n] : (det : Matrix n n R → R) = Function.const _ 1 := by
ext
exact det_isEmpty
theorem det_eq_one_of_card_eq_zero {A : Matrix n n R} (h : Fintype.card n = 0) : det A = 1 :=
haveI : IsEmpty n := Fintype.card_eq_zero_iff.mp h
det_isEmpty
/-- If `n` has only one element, the determinant of an `n` by `n` matrix is just that element.
Although `Unique` implies `DecidableEq` and `Fintype`, the instances might
not be syntactically equal. Thus, we need to fill in the args explicitly. -/
@[simp]
theorem det_unique {n : Type*} [Unique n] [DecidableEq n] [Fintype n] (A : Matrix n n R) :
det A = A default default := by simp [det_apply, univ_unique]
theorem det_eq_elem_of_subsingleton [Subsingleton n] (A : Matrix n n R) (k : n) :
det A = A k k := by
have := uniqueOfSubsingleton k
convert det_unique A
theorem det_eq_elem_of_card_eq_one {A : Matrix n n R} (h : Fintype.card n = 1) (k : n) :
det A = A k k :=
haveI : Subsingleton n := Fintype.card_le_one_iff_subsingleton.mp h.le
det_eq_elem_of_subsingleton _ _
theorem det_mul_aux {M N : Matrix n n R} {p : n → n} (H : ¬Bijective p) :
(∑ σ : Perm n, ε σ * ∏ x, M (σ x) (p x) * N (p x) x) = 0 := by
obtain ⟨i, j, hpij, hij⟩ : ∃ i j, p i = p j ∧ i ≠ j := by
rw [← Finite.injective_iff_bijective, Injective] at H
push_neg at H
exact H
exact
sum_involution (fun σ _ => σ * Equiv.swap i j)
(fun σ _ => by
have : (∏ x, M (σ x) (p x)) = ∏ x, M ((σ * Equiv.swap i j) x) (p x) :=
Fintype.prod_equiv (swap i j) _ _ (by simp [apply_swap_eq_self hpij])
simp [this, sign_swap hij, -sign_swap', prod_mul_distrib])
(fun σ _ _ => (not_congr mul_swap_eq_iff).mpr hij) (fun _ _ => mem_univ _) fun σ _ =>
mul_swap_involutive i j σ
@[simp]
theorem det_mul (M N : Matrix n n R) : det (M * N) = det M * det N :=
calc
det (M * N) = ∑ p : n → n, ∑ σ : Perm n, ε σ * ∏ i, M (σ i) (p i) * N (p i) i := by
simp only [det_apply', mul_apply, prod_univ_sum, mul_sum, Fintype.piFinset_univ]
rw [Finset.sum_comm]
_ =
∑ p ∈ (@univ (n → n) _).filter Bijective,
∑ σ : Perm n, ε σ * ∏ i, M (σ i) (p i) * N (p i) i :=
(Eq.symm <|
sum_subset (filter_subset _ _) fun f _ hbij =>
det_mul_aux <| by simpa only [true_and_iff, mem_filter, mem_univ] using hbij)
_ = ∑ τ : Perm n, ∑ σ : Perm n, ε σ * ∏ i, M (σ i) (τ i) * N (τ i) i :=
sum_bij (fun p h ↦ Equiv.ofBijective p (mem_filter.1 h).2) (fun _ _ ↦ mem_univ _)
(fun _ _ _ _ h ↦ by injection h)
(fun b _ ↦ ⟨b, mem_filter.2 ⟨mem_univ _, b.bijective⟩, coe_fn_injective rfl⟩) fun _ _ ↦ rfl
_ = ∑ σ : Perm n, ∑ τ : Perm n, (∏ i, N (σ i) i) * ε τ * ∏ j, M (τ j) (σ j) := by
simp only [mul_comm, mul_left_comm, prod_mul_distrib, mul_assoc]
_ = ∑ σ : Perm n, ∑ τ : Perm n, (∏ i, N (σ i) i) * (ε σ * ε τ) * ∏ i, M (τ i) i :=
(sum_congr rfl fun σ _ =>
Fintype.sum_equiv (Equiv.mulRight σ⁻¹) _ _ fun τ => by
have : (∏ j, M (τ j) (σ j)) = ∏ j, M ((τ * σ⁻¹) j) j := by
rw [← (σ⁻¹ : _ ≃ _).prod_comp]
simp only [Equiv.Perm.coe_mul, apply_inv_self, Function.comp_apply]
have h : ε σ * ε (τ * σ⁻¹) = ε τ :=
calc
ε σ * ε (τ * σ⁻¹) = ε (τ * σ⁻¹ * σ) := by
rw [mul_comm, sign_mul (τ * σ⁻¹)]
simp only [Int.cast_mul, Units.val_mul]
_ = ε τ := by simp only [inv_mul_cancel_right]
simp_rw [Equiv.coe_mulRight, h]
simp only [this])
_ = det M * det N := by
simp only [det_apply', Finset.mul_sum, mul_comm, mul_left_comm, mul_assoc]
/-- The determinant of a matrix, as a monoid homomorphism. -/
def detMonoidHom : Matrix n n R →* R where
toFun := det
map_one' := det_one
map_mul' := det_mul
@[simp]
theorem coe_detMonoidHom : (detMonoidHom : Matrix n n R → R) = det :=
rfl
/-- On square matrices, `mul_comm` applies under `det`. -/
theorem det_mul_comm (M N : Matrix m m R) : det (M * N) = det (N * M) := by
rw [det_mul, det_mul, mul_comm]
/-- On square matrices, `mul_left_comm` applies under `det`. -/
theorem det_mul_left_comm (M N P : Matrix m m R) : det (M * (N * P)) = det (N * (M * P)) := by
rw [← Matrix.mul_assoc, ← Matrix.mul_assoc, det_mul, det_mul_comm M N, ← det_mul]
/-- On square matrices, `mul_right_comm` applies under `det`. -/
theorem det_mul_right_comm (M N P : Matrix m m R) : det (M * N * P) = det (M * P * N) := by
rw [Matrix.mul_assoc, Matrix.mul_assoc, det_mul, det_mul_comm N P, ← det_mul]
-- TODO(mathlib4#6607): fix elaboration so that the ascription isn't needed
theorem det_units_conj (M : (Matrix m m R)ˣ) (N : Matrix m m R) :
det ((M : Matrix _ _ _) * N * (↑M⁻¹ : Matrix _ _ _)) = det N := by
rw [det_mul_right_comm, Units.mul_inv, one_mul]
-- TODO(mathlib4#6607): fix elaboration so that the ascription isn't needed
theorem det_units_conj' (M : (Matrix m m R)ˣ) (N : Matrix m m R) :
det ((↑M⁻¹ : Matrix _ _ _) * N * (↑M : Matrix _ _ _)) = det N :=
det_units_conj M⁻¹ N
/-- Transposing a matrix preserves the determinant. -/
@[simp]
theorem det_transpose (M : Matrix n n R) : Mᵀ.det = M.det := by
rw [det_apply', det_apply']
refine Fintype.sum_bijective _ inv_involutive.bijective _ _ ?_
intro σ
rw [sign_inv]
congr 1
apply Fintype.prod_equiv σ
simp
/-- Permuting the columns changes the sign of the determinant. -/
theorem det_permute (σ : Perm n) (M : Matrix n n R) :
(M.submatrix σ id).det = Perm.sign σ * M.det :=
((detRowAlternating : (n → R) [⋀^n]→ₗ[R] R).map_perm M σ).trans (by simp [Units.smul_def])
/-- Permuting the rows changes the sign of the determinant. -/
theorem det_permute' (σ : Perm n) (M : Matrix n n R) :
(M.submatrix id σ).det = Perm.sign σ * M.det := by
rw [← det_transpose, transpose_submatrix, det_permute, det_transpose]
/-- Permuting rows and columns with the same equivalence has no effect. -/
@[simp]
theorem det_submatrix_equiv_self (e : n ≃ m) (A : Matrix m m R) :
det (A.submatrix e e) = det A := by
rw [det_apply', det_apply']
apply Fintype.sum_equiv (Equiv.permCongr e)
intro σ
rw [Equiv.Perm.sign_permCongr e σ]
congr 1
apply Fintype.prod_equiv e
intro i
rw [Equiv.permCongr_apply, Equiv.symm_apply_apply, submatrix_apply]
/-- Reindexing both indices along the same equivalence preserves the determinant.
For the `simp` version of this lemma, see `det_submatrix_equiv_self`; this one is unsuitable because
`Matrix.reindex_apply` unfolds `reindex` first.
-/
theorem det_reindex_self (e : m ≃ n) (A : Matrix m m R) : det (reindex e e A) = det A :=
det_submatrix_equiv_self e.symm A
theorem det_smul (A : Matrix n n R) (c : R) : det (c • A) = c ^ Fintype.card n * det A :=
calc
det (c • A) = det ((diagonal fun _ => c) * A) := by rw [smul_eq_diagonal_mul]
_ = det (diagonal fun _ => c) * det A := det_mul _ _
_ = c ^ Fintype.card n * det A := by simp [card_univ]
@[simp]
theorem det_smul_of_tower {α} [Monoid α] [DistribMulAction α R] [IsScalarTower α R R]
[SMulCommClass α R R] (c : α) (A : Matrix n n R) :
det (c • A) = c ^ Fintype.card n • det A := by
rw [← smul_one_smul R c A, det_smul, smul_pow, one_pow, smul_mul_assoc, one_mul]
theorem det_neg (A : Matrix n n R) : det (-A) = (-1) ^ Fintype.card n * det A := by
rw [← det_smul, neg_one_smul]
/-- A variant of `Matrix.det_neg` with scalar multiplication by `Units ℤ` instead of multiplication
by `R`. -/
theorem det_neg_eq_smul (A : Matrix n n R) :
det (-A) = (-1 : Units ℤ) ^ Fintype.card n • det A := by
rw [← det_smul_of_tower, Units.neg_smul, one_smul]
/-- Multiplying each row by a fixed `v i` multiplies the determinant by
the product of the `v`s. -/
theorem det_mul_row (v : n → R) (A : Matrix n n R) :
det (of fun i j => v j * A i j) = (∏ i, v i) * det A :=
calc
det (of fun i j => v j * A i j) = det (A * diagonal v) :=
congr_arg det <| by
ext
simp [mul_comm]
_ = (∏ i, v i) * det A := by rw [det_mul, det_diagonal, mul_comm]
/-- Multiplying each column by a fixed `v j` multiplies the determinant by
the product of the `v`s. -/
theorem det_mul_column (v : n → R) (A : Matrix n n R) :
det (of fun i j => v i * A i j) = (∏ i, v i) * det A :=
MultilinearMap.map_smul_univ _ v A
@[simp]
theorem det_pow (M : Matrix m m R) (n : ℕ) : det (M ^ n) = det M ^ n :=
(detMonoidHom : Matrix m m R →* R).map_pow M n
section HomMap
variable {S : Type w} [CommRing S]
theorem _root_.RingHom.map_det (f : R →+* S) (M : Matrix n n R) :
f M.det = Matrix.det (f.mapMatrix M) := by
simp [Matrix.det_apply', map_sum f, map_prod f]
theorem _root_.RingEquiv.map_det (f : R ≃+* S) (M : Matrix n n R) :
f M.det = Matrix.det (f.mapMatrix M) :=
f.toRingHom.map_det _
theorem _root_.AlgHom.map_det [Algebra R S] {T : Type z} [CommRing T] [Algebra R T] (f : S →ₐ[R] T)
(M : Matrix n n S) : f M.det = Matrix.det (f.mapMatrix M) :=
f.toRingHom.map_det _
theorem _root_.AlgEquiv.map_det [Algebra R S] {T : Type z} [CommRing T] [Algebra R T]
(f : S ≃ₐ[R] T) (M : Matrix n n S) : f M.det = Matrix.det (f.mapMatrix M) :=
f.toAlgHom.map_det _
end HomMap
@[simp]
theorem det_conjTranspose [StarRing R] (M : Matrix m m R) : det Mᴴ = star (det M) :=
((starRingEnd R).map_det _).symm.trans <| congr_arg star M.det_transpose
section DetZero
/-!
### `det_zero` section
Prove that a matrix with a repeated column has determinant equal to zero.
-/
theorem det_eq_zero_of_row_eq_zero {A : Matrix n n R} (i : n) (h : ∀ j, A i j = 0) : det A = 0 :=
(detRowAlternating : (n → R) [⋀^n]→ₗ[R] R).map_coord_zero i (funext h)
theorem det_eq_zero_of_column_eq_zero {A : Matrix n n R} (j : n) (h : ∀ i, A i j = 0) :
det A = 0 := by
rw [← det_transpose]
exact det_eq_zero_of_row_eq_zero j h
variable {M : Matrix n n R} {i j : n}
/-- If a matrix has a repeated row, the determinant will be zero. -/
theorem det_zero_of_row_eq (i_ne_j : i ≠ j) (hij : M i = M j) : M.det = 0 :=
(detRowAlternating : (n → R) [⋀^n]→ₗ[R] R).map_eq_zero_of_eq M hij i_ne_j
/-- If a matrix has a repeated column, the determinant will be zero. -/
theorem det_zero_of_column_eq (i_ne_j : i ≠ j) (hij : ∀ k, M k i = M k j) : M.det = 0 := by
rw [← det_transpose, det_zero_of_row_eq i_ne_j]
exact funext hij
/-- If we repeat a row of a matrix, we get a matrix of determinant zero. -/
theorem det_updateRow_eq_zero (h : i ≠ j) :
(M.updateRow j (M i)).det = 0 := det_zero_of_row_eq h (by simp [h])
/-- If we repeat a column of a matrix, we get a matrix of determinant zero. -/
theorem det_updateColumn_eq_zero (h : i ≠ j) :
(M.updateColumn j (fun k ↦ M k i)).det = 0 := det_zero_of_column_eq h (by simp [h])
end DetZero
theorem det_updateRow_add (M : Matrix n n R) (j : n) (u v : n → R) :
det (updateRow M j <| u + v) = det (updateRow M j u) + det (updateRow M j v) :=
(detRowAlternating : (n → R) [⋀^n]→ₗ[R] R).map_add M j u v
theorem det_updateColumn_add (M : Matrix n n R) (j : n) (u v : n → R) :
det (updateColumn M j <| u + v) = det (updateColumn M j u) + det (updateColumn M j v) := by
rw [← det_transpose, ← updateRow_transpose, det_updateRow_add]
simp [updateRow_transpose, det_transpose]
theorem det_updateRow_smul (M : Matrix n n R) (j : n) (s : R) (u : n → R) :
det (updateRow M j <| s • u) = s * det (updateRow M j u) :=
(detRowAlternating : (n → R) [⋀^n]→ₗ[R] R).map_smul M j s u
theorem det_updateColumn_smul (M : Matrix n n R) (j : n) (s : R) (u : n → R) :
det (updateColumn M j <| s • u) = s * det (updateColumn M j u) := by
rw [← det_transpose, ← updateRow_transpose, det_updateRow_smul]
simp [updateRow_transpose, det_transpose]
theorem det_updateRow_smul' (M : Matrix n n R) (j : n) (s : R) (u : n → R) :
det (updateRow (s • M) j u) = s ^ (Fintype.card n - 1) * det (updateRow M j u) :=
MultilinearMap.map_update_smul _ M j s u
theorem det_updateColumn_smul' (M : Matrix n n R) (j : n) (s : R) (u : n → R) :
det (updateColumn (s • M) j u) = s ^ (Fintype.card n - 1) * det (updateColumn M j u) := by
rw [← det_transpose, ← updateRow_transpose, transpose_smul, det_updateRow_smul']
simp [updateRow_transpose, det_transpose]
theorem det_updateRow_sum_aux (M : Matrix n n R) {j : n} (s : Finset n) (hj : j ∉ s) (c : n → R)
(a : R) :
(M.updateRow j (a • M j + ∑ k ∈ s, (c k) • M k)).det = a • M.det := by
induction s using Finset.induction_on with
| empty => rw [Finset.sum_empty, add_zero, smul_eq_mul, det_updateRow_smul, updateRow_eq_self]
| @insert k _ hk h_ind =>
have h : k ≠ j := fun h ↦ (h ▸ hj) (Finset.mem_insert_self _ _)
rw [Finset.sum_insert hk, add_comm ((c k) • M k), ← add_assoc, det_updateRow_add,
det_updateRow_smul, det_updateRow_eq_zero h, mul_zero, add_zero, h_ind]
exact fun h ↦ hj (Finset.mem_insert_of_mem h)
/-- If we replace a row of a matrix by a linear combination of its rows, then the determinant is
multiplied by the coefficient of that row. -/
theorem det_updateRow_sum (A : Matrix n n R) (j : n) (c : n → R) :
(A.updateRow j (∑ k, (c k) • A k)).det = (c j) • A.det := by
convert det_updateRow_sum_aux A (Finset.univ.erase j) (Finset.univ.not_mem_erase j) c (c j)
rw [← Finset.univ.add_sum_erase _ (Finset.mem_univ j)]
/-- If we replace a column of a matrix by a linear combination of its columns, then the determinant
is multiplied by the coefficient of that column. -/
theorem det_updateColumn_sum (A : Matrix n n R) (j : n) (c : n → R) :
(A.updateColumn j (fun k ↦ ∑ i, (c i) • A k i)).det = (c j) • A.det := by
rw [← det_transpose, ← updateRow_transpose, ← det_transpose A]
convert det_updateRow_sum A.transpose j c
simp only [smul_eq_mul, Finset.sum_apply, Pi.smul_apply, transpose_apply]
section DetEq
/-! ### `det_eq` section
Lemmas showing the determinant is invariant under a variety of operations.
-/
theorem det_eq_of_eq_mul_det_one {A B : Matrix n n R} (C : Matrix n n R) (hC : det C = 1)
(hA : A = B * C) : det A = det B :=
calc
det A = det (B * C) := congr_arg _ hA
_ = det B * det C := det_mul _ _
_ = det B := by rw [hC, mul_one]
theorem det_eq_of_eq_det_one_mul {A B : Matrix n n R} (C : Matrix n n R) (hC : det C = 1)
(hA : A = C * B) : det A = det B :=
calc
det A = det (C * B) := congr_arg _ hA
_ = det C * det B := det_mul _ _
_ = det B := by rw [hC, one_mul]
theorem det_updateRow_add_self (A : Matrix n n R) {i j : n} (hij : i ≠ j) :
det (updateRow A i (A i + A j)) = det A := by
simp [det_updateRow_add,
det_zero_of_row_eq hij (updateRow_self.trans (updateRow_ne hij.symm).symm)]
theorem det_updateColumn_add_self (A : Matrix n n R) {i j : n} (hij : i ≠ j) :
det (updateColumn A i fun k => A k i + A k j) = det A := by
rw [← det_transpose, ← updateRow_transpose, ← det_transpose A]
exact det_updateRow_add_self Aᵀ hij
theorem det_updateRow_add_smul_self (A : Matrix n n R) {i j : n} (hij : i ≠ j) (c : R) :
det (updateRow A i (A i + c • A j)) = det A := by
simp [det_updateRow_add, det_updateRow_smul,
det_zero_of_row_eq hij (updateRow_self.trans (updateRow_ne hij.symm).symm)]
theorem det_updateColumn_add_smul_self (A : Matrix n n R) {i j : n} (hij : i ≠ j) (c : R) :
det (updateColumn A i fun k => A k i + c • A k j) = det A := by
rw [← det_transpose, ← updateRow_transpose, ← det_transpose A]
exact det_updateRow_add_smul_self Aᵀ hij c
theorem det_eq_of_forall_row_eq_smul_add_const_aux {A B : Matrix n n R} {s : Finset n} :
∀ (c : n → R) (_ : ∀ i, i ∉ s → c i = 0) (k : n) (_ : k ∉ s)
(_ : ∀ i j, A i j = B i j + c i * B k j), det A = det B := by
induction s using Finset.induction_on generalizing B with
| empty =>
rintro c hs k - A_eq
have : ∀ i, c i = 0 := by
intro i
specialize hs i
contrapose! hs
simp [hs]
congr
ext i j
rw [A_eq, this, zero_mul, add_zero]
| @insert i s _hi ih =>
intro c hs k hk A_eq
have hAi : A i = B i + c i • B k := funext (A_eq i)
rw [@ih (updateRow B i (A i)) (Function.update c i 0), hAi, det_updateRow_add_smul_self]
· exact mt (fun h => show k ∈ insert i s from h ▸ Finset.mem_insert_self _ _) hk
· intro i' hi'
rw [Function.update_apply]
split_ifs with hi'i
· rfl
· exact hs i' fun h => hi' ((Finset.mem_insert.mp h).resolve_left hi'i)
· exact k
· exact fun h => hk (Finset.mem_insert_of_mem h)
· intro i' j'
rw [updateRow_apply, Function.update_apply]
split_ifs with hi'i
· simp [hi'i]
rw [A_eq, updateRow_ne fun h : k = i => hk <| h ▸ Finset.mem_insert_self k s]
/-- If you add multiples of row `B k` to other rows, the determinant doesn't change. -/
theorem det_eq_of_forall_row_eq_smul_add_const {A B : Matrix n n R} (c : n → R) (k : n)
(hk : c k = 0) (A_eq : ∀ i j, A i j = B i j + c i * B k j) : det A = det B :=
det_eq_of_forall_row_eq_smul_add_const_aux c
(fun i =>
not_imp_comm.mp fun hi =>
Finset.mem_erase.mpr
⟨mt (fun h : i = k => show c i = 0 from h.symm ▸ hk) hi, Finset.mem_univ i⟩)
k (Finset.not_mem_erase k Finset.univ) A_eq
theorem det_eq_of_forall_row_eq_smul_add_pred_aux {n : ℕ} (k : Fin (n + 1)) :
∀ (c : Fin n → R) (_hc : ∀ i : Fin n, k < i.succ → c i = 0)
{M N : Matrix (Fin n.succ) (Fin n.succ) R} (_h0 : ∀ j, M 0 j = N 0 j)
(_hsucc : ∀ (i : Fin n) (j), M i.succ j = N i.succ j + c i * M (Fin.castSucc i) j),
det M = det N := by
refine Fin.induction ?_ (fun k ih => ?_) k <;> intro c hc M N h0 hsucc
· congr
ext i j
refine Fin.cases (h0 j) (fun i => ?_) i
rw [hsucc, hc i (Fin.succ_pos _), zero_mul, add_zero]
set M' := updateRow M k.succ (N k.succ) with hM'
have hM : M = updateRow M' k.succ (M' k.succ + c k • M (Fin.castSucc k)) := by
ext i j
by_cases hi : i = k.succ
· simp [hi, hM', hsucc, updateRow_self]
rw [updateRow_ne hi, hM', updateRow_ne hi]
have k_ne_succ : (Fin.castSucc k) ≠ k.succ := (Fin.castSucc_lt_succ k).ne
have M_k : M (Fin.castSucc k) = M' (Fin.castSucc k) := (updateRow_ne k_ne_succ).symm
rw [hM, M_k, det_updateRow_add_smul_self M' k_ne_succ.symm, ih (Function.update c k 0)]
· intro i hi
rw [Fin.lt_iff_val_lt_val, Fin.coe_castSucc, Fin.val_succ, Nat.lt_succ_iff] at hi
rw [Function.update_apply]
split_ifs with hik
· rfl
exact hc _ (Fin.succ_lt_succ_iff.mpr (lt_of_le_of_ne hi (Ne.symm hik)))
· rwa [hM', updateRow_ne (Fin.succ_ne_zero _).symm]
intro i j
rw [Function.update_apply]
split_ifs with hik
· rw [zero_mul, add_zero, hM', hik, updateRow_self]
rw [hM', updateRow_ne ((Fin.succ_injective _).ne hik), hsucc]
by_cases hik2 : k < i
· simp [hc i (Fin.succ_lt_succ_iff.mpr hik2)]
rw [updateRow_ne]
apply ne_of_lt
rwa [Fin.lt_iff_val_lt_val, Fin.coe_castSucc, Fin.val_succ, Nat.lt_succ_iff, ← not_lt]
/-- If you add multiples of previous rows to the next row, the determinant doesn't change. -/
theorem det_eq_of_forall_row_eq_smul_add_pred {n : ℕ} {A B : Matrix (Fin (n + 1)) (Fin (n + 1)) R}
(c : Fin n → R) (A_zero : ∀ j, A 0 j = B 0 j)
(A_succ : ∀ (i : Fin n) (j), A i.succ j = B i.succ j + c i * A (Fin.castSucc i) j) :
det A = det B :=
det_eq_of_forall_row_eq_smul_add_pred_aux (Fin.last _) c
(fun _ hi => absurd hi (not_lt_of_ge (Fin.le_last _))) A_zero A_succ
/-- If you add multiples of previous columns to the next columns, the determinant doesn't change. -/
theorem det_eq_of_forall_col_eq_smul_add_pred {n : ℕ} {A B : Matrix (Fin (n + 1)) (Fin (n + 1)) R}
(c : Fin n → R) (A_zero : ∀ i, A i 0 = B i 0)
(A_succ : ∀ (i) (j : Fin n), A i j.succ = B i j.succ + c j * A i (Fin.castSucc j)) :
det A = det B := by
rw [← det_transpose A, ← det_transpose B]
exact det_eq_of_forall_row_eq_smul_add_pred c A_zero fun i j => A_succ j i
end DetEq
@[simp]
theorem det_blockDiagonal {o : Type*} [Fintype o] [DecidableEq o] (M : o → Matrix n n R) :
(blockDiagonal M).det = ∏ k, (M k).det := by
-- Rewrite the determinants as a sum over permutations.
simp_rw [det_apply']
-- The right hand side is a product of sums, rewrite it as a sum of products.
rw [Finset.prod_sum]
simp_rw [Finset.prod_attach_univ, Finset.univ_pi_univ]
-- We claim that the only permutations contributing to the sum are those that
-- preserve their second component.
let preserving_snd : Finset (Equiv.Perm (n × o)) :=
Finset.univ.filter fun σ => ∀ x, (σ x).snd = x.snd
have mem_preserving_snd :
∀ {σ : Equiv.Perm (n × o)}, σ ∈ preserving_snd ↔ ∀ x, (σ x).snd = x.snd := fun {σ} =>
Finset.mem_filter.trans ⟨fun h => h.2, fun h => ⟨Finset.mem_univ _, h⟩⟩
rw [← Finset.sum_subset (Finset.subset_univ preserving_snd) _]
-- And that these are in bijection with `o → Equiv.Perm m`.
· refine (Finset.sum_bij (fun σ _ => prodCongrLeft fun k ↦ σ k (mem_univ k)) ?_ ?_ ?_ ?_).symm
· intro σ _
rw [mem_preserving_snd]
rintro ⟨-, x⟩
simp only [prodCongrLeft_apply]
· intro σ _ σ' _ eq
ext x hx k
simp only at eq
have :
∀ k x,
prodCongrLeft (fun k => σ k (Finset.mem_univ _)) (k, x) =
prodCongrLeft (fun k => σ' k (Finset.mem_univ _)) (k, x) :=
fun k x => by rw [eq]
simp only [prodCongrLeft_apply, Prod.mk.inj_iff] at this
exact (this k x).1
· intro σ hσ
rw [mem_preserving_snd] at hσ
have hσ' : ∀ x, (σ⁻¹ x).snd = x.snd := by
intro x
conv_rhs => rw [← Perm.apply_inv_self σ x, hσ]
have mk_apply_eq : ∀ k x, ((σ (x, k)).fst, k) = σ (x, k) := by
intro k x
ext
· simp only
· simp only [hσ]
have mk_inv_apply_eq : ∀ k x, ((σ⁻¹ (x, k)).fst, k) = σ⁻¹ (x, k) := by
intro k x
conv_lhs => rw [← Perm.apply_inv_self σ (x, k)]
ext
· simp only [apply_inv_self]
· simp only [hσ']
refine ⟨fun k _ => ⟨fun x => (σ (x, k)).fst, fun x => (σ⁻¹ (x, k)).fst, ?_, ?_⟩, ?_, ?_⟩
· intro x
simp only [mk_apply_eq, inv_apply_self]
· intro x
simp only [mk_inv_apply_eq, apply_inv_self]
· apply Finset.mem_univ
· ext ⟨k, x⟩
· simp only [coe_fn_mk, prodCongrLeft_apply]
· simp only [prodCongrLeft_apply, hσ]
· intro σ _
rw [Finset.prod_mul_distrib, ← Finset.univ_product_univ, Finset.prod_product_right]
simp only [sign_prodCongrLeft, Units.coe_prod, Int.cast_prod, blockDiagonal_apply_eq,
prodCongrLeft_apply]
· intro σ _ hσ
rw [mem_preserving_snd] at hσ
obtain ⟨⟨k, x⟩, hkx⟩ := not_forall.mp hσ
rw [Finset.prod_eq_zero (Finset.mem_univ (k, x)), mul_zero]
rw [blockDiagonal_apply_ne]
exact hkx
/-- The determinant of a 2×2 block matrix with the lower-left block equal to zero is the product of
the determinants of the diagonal blocks. For the generalization to any number of blocks, see
`Matrix.det_of_upper_triangular`. -/
@[simp]
theorem det_fromBlocks_zero₂₁ (A : Matrix m m R) (B : Matrix m n R) (D : Matrix n n R) :
(Matrix.fromBlocks A B 0 D).det = A.det * D.det := by
classical
simp_rw [det_apply']
convert Eq.symm <|
sum_subset (β := R) (subset_univ ((sumCongrHom m n).range : Set (Perm (m ⊕ n))).toFinset) ?_
· simp_rw [sum_mul_sum, ← sum_product', univ_product_univ]
refine sum_nbij (fun σ ↦ σ.fst.sumCongr σ.snd) ?_ ?_ ?_ ?_
· intro σ₁₂ _
simp only
erw [Set.mem_toFinset, MonoidHom.mem_range]
use σ₁₂
simp only [sumCongrHom_apply]
· intro σ₁ _ σ₂ _
dsimp only
intro h
have h2 : ∀ x, Perm.sumCongr σ₁.fst σ₁.snd x = Perm.sumCongr σ₂.fst σ₂.snd x :=
DFunLike.congr_fun h
simp only [Sum.map_inr, Sum.map_inl, Perm.sumCongr_apply, Sum.forall, Sum.inl.injEq,
Sum.inr.injEq] at h2
ext x
· exact h2.left x
· exact h2.right x
· intro σ hσ
erw [Set.mem_toFinset, MonoidHom.mem_range] at hσ
obtain ⟨σ₁₂, hσ₁₂⟩ := hσ
use σ₁₂
rw [← hσ₁₂]
simp
· simp only [forall_prop_of_true, Prod.forall, mem_univ]
intro σ₁ σ₂
rw [Fintype.prod_sum_type]
simp_rw [Equiv.sumCongr_apply, Sum.map_inr, Sum.map_inl, fromBlocks_apply₁₁,
fromBlocks_apply₂₂]
rw [mul_mul_mul_comm]
congr
rw [sign_sumCongr, Units.val_mul, Int.cast_mul]
· rintro σ - hσn
have h1 : ¬∀ x, ∃ y, Sum.inl y = σ (Sum.inl x) := by
rw [Set.mem_toFinset] at hσn
-- Porting note: golfed
simpa only [Set.MapsTo, Set.mem_range, forall_exists_index, forall_apply_eq_imp_iff] using
mt mem_sumCongrHom_range_of_perm_mapsTo_inl hσn
obtain ⟨a, ha⟩ := not_forall.mp h1
cases' hx : σ (Sum.inl a) with a2 b
· have hn := (not_exists.mp ha) a2
exact absurd hx.symm hn
· rw [Finset.prod_eq_zero (Finset.mem_univ (Sum.inl a)), mul_zero]
rw [hx, fromBlocks_apply₂₁, zero_apply]
/-- The determinant of a 2×2 block matrix with the upper-right block equal to zero is the product of
the determinants of the diagonal blocks. For the generalization to any number of blocks, see
`Matrix.det_of_lower_triangular`. -/
@[simp]
theorem det_fromBlocks_zero₁₂ (A : Matrix m m R) (C : Matrix n m R) (D : Matrix n n R) :
(Matrix.fromBlocks A 0 C D).det = A.det * D.det := by
rw [← det_transpose, fromBlocks_transpose, transpose_zero, det_fromBlocks_zero₂₁, det_transpose,
det_transpose]
/-- Laplacian expansion of the determinant of an `n+1 × n+1` matrix along column 0. -/
theorem det_succ_column_zero {n : ℕ} (A : Matrix (Fin n.succ) (Fin n.succ) R) :
det A = ∑ i : Fin n.succ, (-1) ^ (i : ℕ) * A i 0 * det (A.submatrix i.succAbove Fin.succ) := by
rw [Matrix.det_apply, Finset.univ_perm_fin_succ, ← Finset.univ_product_univ]
simp only [Finset.sum_map, Equiv.toEmbedding_apply, Finset.sum_product, Matrix.submatrix]
refine Finset.sum_congr rfl fun i _ => Fin.cases ?_ (fun i => ?_) i
· simp only [Fin.prod_univ_succ, Matrix.det_apply, Finset.mul_sum,
Equiv.Perm.decomposeFin_symm_apply_zero, Fin.val_zero, one_mul,
Equiv.Perm.decomposeFin.symm_sign, Equiv.swap_self, if_true, id, eq_self_iff_true,
Equiv.Perm.decomposeFin_symm_apply_succ, Fin.succAbove_zero, Equiv.coe_refl, pow_zero,
mul_smul_comm, of_apply]
-- `univ_perm_fin_succ` gives a different embedding of `Perm (Fin n)` into
-- `Perm (Fin n.succ)` than the determinant of the submatrix we want,
-- permute `A` so that we get the correct one.
have : (-1 : R) ^ (i : ℕ) = (Perm.sign i.cycleRange) := by simp [Fin.sign_cycleRange]
rw [Fin.val_succ, pow_succ', this, mul_assoc, mul_assoc, mul_left_comm (ε _),
← det_permute, Matrix.det_apply, Finset.mul_sum, Finset.mul_sum]
-- now we just need to move the corresponding parts to the same place
refine Finset.sum_congr rfl fun σ _ => ?_
rw [Equiv.Perm.decomposeFin.symm_sign, if_neg (Fin.succ_ne_zero i)]
calc
((-1 * Perm.sign σ : ℤ) • ∏ i', A (Perm.decomposeFin.symm (Fin.succ i, σ) i') i') =
(-1 * Perm.sign σ : ℤ) • (A (Fin.succ i) 0 *
∏ i', A ((Fin.succ i).succAbove (Fin.cycleRange i (σ i'))) i'.succ) := by
simp only [Fin.prod_univ_succ, Fin.succAbove_cycleRange,
Equiv.Perm.decomposeFin_symm_apply_zero, Equiv.Perm.decomposeFin_symm_apply_succ]
_ = -1 * (A (Fin.succ i) 0 * (Perm.sign σ : ℤ) •
∏ i', A ((Fin.succ i).succAbove (Fin.cycleRange i (σ i'))) i'.succ) := by
simp [mul_assoc, mul_comm, _root_.neg_mul, one_mul, zsmul_eq_mul, neg_inj, neg_smul,
Fin.succAbove_cycleRange, mul_left_comm]
/-- Laplacian expansion of the determinant of an `n+1 × n+1` matrix along row 0. -/
theorem det_succ_row_zero {n : ℕ} (A : Matrix (Fin n.succ) (Fin n.succ) R) :
det A = ∑ j : Fin n.succ, (-1) ^ (j : ℕ) * A 0 j * det (A.submatrix Fin.succ j.succAbove) := by
rw [← det_transpose A, det_succ_column_zero]
refine Finset.sum_congr rfl fun i _ => ?_
rw [← det_transpose]
simp only [transpose_apply, transpose_submatrix, transpose_transpose]
/-- Laplacian expansion of the determinant of an `n+1 × n+1` matrix along row `i`. -/
theorem det_succ_row {n : ℕ} (A : Matrix (Fin n.succ) (Fin n.succ) R) (i : Fin n.succ) :
det A =
∑ j : Fin n.succ, (-1) ^ (i + j : ℕ) * A i j * det (A.submatrix i.succAbove j.succAbove) := by
simp_rw [pow_add, mul_assoc, ← mul_sum]
have : det A = (-1 : R) ^ (i : ℕ) * (Perm.sign i.cycleRange⁻¹) * det A := by
calc
det A = ↑((-1 : ℤˣ) ^ (i : ℕ) * (-1 : ℤˣ) ^ (i : ℕ) : ℤˣ) * det A := by simp
_ = (-1 : R) ^ (i : ℕ) * (Perm.sign i.cycleRange⁻¹) * det A := by simp [-Int.units_mul_self]
rw [this, mul_assoc]
congr
rw [← det_permute, det_succ_row_zero]
refine Finset.sum_congr rfl fun j _ => ?_
rw [mul_assoc, Matrix.submatrix_apply, submatrix_submatrix, id_comp, Function.comp_def, id]
congr
· rw [Equiv.Perm.inv_def, Fin.cycleRange_symm_zero]
· ext i' j'
rw [Equiv.Perm.inv_def, Matrix.submatrix_apply, Matrix.submatrix_apply,
Fin.cycleRange_symm_succ]
/-- Laplacian expansion of the determinant of an `n+1 × n+1` matrix along column `j`. -/
theorem det_succ_column {n : ℕ} (A : Matrix (Fin n.succ) (Fin n.succ) R) (j : Fin n.succ) :
det A =
∑ i : Fin n.succ, (-1) ^ (i + j : ℕ) * A i j * det (A.submatrix i.succAbove j.succAbove) := by
rw [← det_transpose, det_succ_row _ j]
refine Finset.sum_congr rfl fun i _ => ?_
rw [add_comm, ← det_transpose, transpose_apply, transpose_submatrix, transpose_transpose]
/-- Determinant of 0x0 matrix -/
@[simp]
theorem det_fin_zero {A : Matrix (Fin 0) (Fin 0) R} : det A = 1 :=
det_isEmpty
/-- Determinant of 1x1 matrix -/
theorem det_fin_one (A : Matrix (Fin 1) (Fin 1) R) : det A = A 0 0 :=
det_unique A
theorem det_fin_one_of (a : R) : det !![a] = a :=
det_fin_one _
/-- Determinant of 2x2 matrix -/
theorem det_fin_two (A : Matrix (Fin 2) (Fin 2) R) : det A = A 0 0 * A 1 1 - A 0 1 * A 1 0 := by
simp only [det_succ_row_zero, det_unique, Fin.default_eq_zero, submatrix_apply,
Fin.succ_zero_eq_one, Fin.sum_univ_succ, Fin.val_zero, Fin.zero_succAbove, univ_unique,
Fin.val_succ, Fin.coe_fin_one, Fin.succ_succAbove_zero, sum_singleton]
ring
@[simp]
theorem det_fin_two_of (a b c d : R) : Matrix.det !![a, b; c, d] = a * d - b * c :=
det_fin_two _
/-- Determinant of 3x3 matrix -/
theorem det_fin_three (A : Matrix (Fin 3) (Fin 3) R) :
det A =
A 0 0 * A 1 1 * A 2 2 - A 0 0 * A 1 2 * A 2 1
- A 0 1 * A 1 0 * A 2 2 + A 0 1 * A 1 2 * A 2 0
+ A 0 2 * A 1 0 * A 2 1 - A 0 2 * A 1 1 * A 2 0 := by
simp only [det_succ_row_zero, Nat.odd_iff_not_even, submatrix_apply, Fin.succ_zero_eq_one,
submatrix_submatrix, det_unique, Fin.default_eq_zero, comp_apply, Fin.succ_one_eq_two,
Fin.sum_univ_succ, Fin.val_zero, Fin.zero_succAbove, univ_unique, Fin.val_succ,
Fin.coe_fin_one, Fin.succ_succAbove_zero, sum_singleton, Fin.succ_succAbove_one, even_add_self]
ring
end Matrix
|
LinearAlgebra\Matrix\Determinant\Misc.lean | /-
Copyright (c) 2024 Xavier Roblot. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Xavier Roblot
-/
import Mathlib.LinearAlgebra.Matrix.Determinant.Basic
import Mathlib.Algebra.Ring.NegOnePow
/-!
# Miscellaneous results about determinant
In this file, we collect various formulas about determinant of matrices.
-/
namespace Matrix
variable {R : Type*} [CommRing R]
/-- Let `M` be a `(n+1) × n` matrix whose row sums to zero. Then all the matrices obtained by
deleting one row have the same determinant up to a sign. -/
theorem submatrix_succAbove_det_eq_negOnePow_submatrix_succAbove_det {n : ℕ}
(M : Matrix (Fin (n + 1)) (Fin n) R) (hv : ∑ j, M j = 0) (j₁ j₂ : Fin (n + 1)) :
(M.submatrix (Fin.succAbove j₁) id).det =
Int.negOnePow (j₁ - j₂) • (M.submatrix (Fin.succAbove j₂) id).det := by
suffices ∀ j, (M.submatrix (Fin.succAbove j) id).det =
Int.negOnePow j • (M.submatrix (Fin.succAbove 0) id).det by
rw [this j₁, this j₂, smul_smul, ← Int.negOnePow_add, sub_add_cancel]
intro j
induction j using Fin.induction with
| zero => rw [Fin.val_zero, Nat.cast_zero, Int.negOnePow_zero, one_smul]
| succ i h_ind =>
rw [Fin.val_succ, Nat.cast_add, Nat.cast_one, Int.negOnePow_succ, Units.neg_smul,
← neg_eq_iff_eq_neg, ← neg_one_smul R,
← det_updateRow_sum (M.submatrix i.succ.succAbove id) i (fun _ ↦ -1),
← Fin.coe_castSucc i, ← h_ind]
congr
ext a b
simp_rw [neg_one_smul, updateRow_apply, Finset.sum_neg_distrib, Pi.neg_apply,
Finset.sum_apply, submatrix_apply, id_eq]
split_ifs with h
· replace hv := congr_fun hv b
rw [Fin.sum_univ_succAbove _ i.succ, Pi.add_apply, Finset.sum_apply] at hv
rwa [h, Fin.succAbove_castSucc_self, neg_eq_iff_add_eq_zero, add_comm]
· obtain h|h := ne_iff_lt_or_gt.mp h
· rw [Fin.succAbove_castSucc_of_lt _ _ h,
Fin.succAbove_of_succ_le _ _ (Fin.succ_lt_succ_iff.mpr h).le]
· rw [Fin.succAbove_succ_of_lt _ _ h, Fin.succAbove_castSucc_of_le _ _ h.le]
/-- Let `M` be a `(n+1) × n` matrix whose column sums to zero. Then all the matrices obtained by
deleting one column have the same determinant up to a sign. -/
theorem submatrix_succAbove_det_eq_negOnePow_submatrix_succAbove_det' {n : ℕ}
(M : Matrix (Fin n) (Fin (n + 1)) R) (hv : ∀ i, ∑ j, M i j = 0) (j₁ j₂ : Fin (n + 1)) :
(M.submatrix id (Fin.succAbove j₁)).det =
Int.negOnePow (j₁ - j₂) • (M.submatrix id (Fin.succAbove j₂)).det := by
rw [← det_transpose, transpose_submatrix,
submatrix_succAbove_det_eq_negOnePow_submatrix_succAbove_det M.transpose ?_ j₁ j₂,
← det_transpose, transpose_submatrix, transpose_transpose]
ext
simp_rw [Finset.sum_apply, transpose_apply, hv, Pi.zero_apply]
end Matrix
|
LinearAlgebra\Matrix\GeneralLinearGroup\Basic.lean | /-
Copyright (c) 2021 Chris Birkbeck. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Birkbeck
-/
import Mathlib.LinearAlgebra.Matrix.GeneralLinearGroup.Defs
/-!
# Basic lemmas about the general linear group $GL(n, R)$
This file lists various basic lemmas about the general linear group $GL(n, R)$. For the definitions,
see `LinearAlgebra/Matrix/GeneralLinearGroup/Defs.lean`.
-/
namespace Matrix
section Examples
/-- The matrix [a, -b; b, a] (inspired by multiplication by a complex number); it is an element of
$GL_2(R)$ if `a ^ 2 + b ^ 2` is nonzero. -/
@[simps! (config := .asFn) val]
def planeConformalMatrix {R} [Field R] (a b : R) (hab : a ^ 2 + b ^ 2 ≠ 0) :
Matrix.GeneralLinearGroup (Fin 2) R :=
GeneralLinearGroup.mkOfDetNeZero !![a, -b; b, a] (by simpa [det_fin_two, sq] using hab)
/- TODO: Add Iwasawa matrices `n_x=!![1,x; 0,1]`, `a_t=!![exp(t/2),0;0,exp(-t/2)]` and
`k_θ=!![cos θ, sin θ; -sin θ, cos θ]`
-/
end Examples
end Matrix
|
LinearAlgebra\Matrix\GeneralLinearGroup\Card.lean | /-
Copyright (c) 2024 Thomas Lanard. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Birkbeck, Inna Capdeboscq, Johan Commelin, Thomas Lanard, Peiran Wu
-/
import Mathlib.Data.Matrix.Rank
import Mathlib.FieldTheory.Finite.Basic
import Mathlib.LinearAlgebra.Matrix.GeneralLinearGroup.Defs
/-!
# Cardinal of the general linear group over finite rings
This file computes the cardinal of the general linear group over finite rings.
## Main statements
* `card_linearInependent` gives the cardinal of the set of linearly independent vectors over a
finite dimensional vector space over a finite field.
* `Matrix.card_GL_field` gives the cardinal of the general linear group over a finite field.
-/
open LinearMap
section LinearIndependent
variable {K V : Type*} [DivisionRing K] [AddCommGroup V] [Module K V]
variable [Fintype K] [Finite V]
local notation "q" => Fintype.card K
local notation "n" => FiniteDimensional.finrank K V
attribute [local instance] Fintype.ofFinite in
open Fintype in
/-- The cardinal of the set of linearly independent vectors over a finite dimensional vector space
over a finite field. -/
theorem card_linearIndependent {k : ℕ} (hk : k ≤ n) :
Nat.card { s : Fin k → V // LinearIndependent K s } =
∏ i : Fin k, (q ^ n - q ^ i.val) := by
rw [Nat.card_eq_fintype_card]
induction k with
| zero => simp only [LinearIndependent, Finsupp.total_fin_zero, ker_zero, card_ofSubsingleton,
Finset.univ_eq_empty, Finset.prod_empty]
| succ k ih =>
have (s : { s : Fin k → V // LinearIndependent K s }) :
card ((Submodule.span K (Set.range (s : Fin k → V)))ᶜ : Set (V)) =
(q) ^ n - (q) ^ k := by
rw [card_compl_set, card_eq_pow_finrank (K := K)
(V := ((Submodule.span K (Set.range (s : Fin k → V))) : Set (V)))]
simp only [SetLike.coe_sort_coe, finrank_span_eq_card s.2, card_fin]
rw [card_eq_pow_finrank (K := K)]
simp [card_congr (equiv_linearIndependent k), sum_congr _ _ this, ih (Nat.le_of_succ_le hk),
mul_comm, Fin.prod_univ_succAbove _ k]
end LinearIndependent
namespace Matrix
section field
variable {𝔽 : Type*} [Field 𝔽] [Fintype 𝔽]
local notation "q" => Fintype.card 𝔽
variable (n : ℕ)
/-- Equivalence between `GL n F` and `n` vectors of length `n` that are linearly independent. Given
by sending a matrix to its coloumns. -/
noncomputable def equiv_GL_linearindependent (hn : 0 < n) :
GL (Fin n) 𝔽 ≃ { s : Fin n → Fin n → 𝔽 // LinearIndependent 𝔽 s } where
toFun M := ⟨transpose M, by
apply linearIndependent_iff_card_eq_finrank_span.2
rw [Set.finrank, ← rank_eq_finrank_span_cols, rank_unit]⟩
invFun M := GeneralLinearGroup.mk'' (transpose (M.1)) <| by
have : Nonempty (Fin n) := Fin.pos_iff_nonempty.1 hn
let b := basisOfLinearIndependentOfCardEqFinrank M.2 (by simp)
have := (Pi.basisFun 𝔽 (Fin n)).invertibleToMatrix b
rw [← Basis.coePiBasisFun.toMatrix_eq_transpose,
← coe_basisOfLinearIndependentOfCardEqFinrank M.2]
exact isUnit_det_of_invertible _
left_inv := fun x ↦ Units.ext (ext fun i j ↦ rfl)
right_inv := by exact congrFun rfl
/-- The cardinal of the general linear group over a finite field. -/
theorem card_GL_field :
Nat.card (GL (Fin n) 𝔽) = ∏ i : (Fin n), (q ^ n - q ^ ( i : ℕ )) := by
rcases Nat.eq_zero_or_pos n with rfl | hn
· simp [Nat.card_eq_fintype_card]
· rw [Nat.card_congr (equiv_GL_linearindependent n hn), card_linearIndependent,
FiniteDimensional.finrank_fintype_fun_eq_card, Fintype.card_fin]
simp only [FiniteDimensional.finrank_fintype_fun_eq_card, Fintype.card_fin, le_refl]
end field
end Matrix
|
LinearAlgebra\Matrix\GeneralLinearGroup\Defs.lean | /-
Copyright (c) 2021 Chris Birkbeck. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Birkbeck
-/
import Mathlib.LinearAlgebra.Matrix.NonsingularInverse
import Mathlib.LinearAlgebra.Matrix.SpecialLinearGroup
import Mathlib.Algebra.Ring.Subring.Units
/-!
# The General Linear group $GL(n, R)$
This file defines the elements of the General Linear group `Matrix.GeneralLinearGroup n R`,
consisting of all invertible `n` by `n` `R`-matrices.
## Main definitions
* `Matrix.GeneralLinearGroup` is the type of matrices over R which are units in the matrix ring.
* `Matrix.GLPos` gives the subgroup of matrices with
positive determinant (over a linear ordered ring).
## Tags
matrix group, group, matrix inverse
-/
namespace Matrix
universe u v
open Matrix
open LinearMap
-- disable this instance so we do not accidentally use it in lemmas.
attribute [-instance] SpecialLinearGroup.instCoeFun
/-- `GL n R` is the group of `n` by `n` `R`-matrices with unit determinant.
Defined as a subtype of matrices-/
abbrev GeneralLinearGroup (n : Type u) (R : Type v) [DecidableEq n] [Fintype n] [CommRing R] :
Type _ :=
(Matrix n n R)ˣ
@[inherit_doc] notation "GL" => GeneralLinearGroup
namespace GeneralLinearGroup
variable {n : Type u} [DecidableEq n] [Fintype n] {R : Type v} [CommRing R]
section CoeFnInstance
-- Porting note: this instance was not the simp-normal form in mathlib3 but it is fine in mathlib4
-- because coercions get unfolded.
/-- This instance is here for convenience, but is not the simp-normal form. -/
instance instCoeFun : CoeFun (GL n R) fun _ => n → n → R where
coe A := (A : Matrix n n R)
end CoeFnInstance
/-- The determinant of a unit matrix is itself a unit. -/
@[simps]
def det : GL n R →* Rˣ where
toFun A :=
{ val := (↑A : Matrix n n R).det
inv := (↑A⁻¹ : Matrix n n R).det
val_inv := by rw [← det_mul, A.mul_inv, det_one]
inv_val := by rw [← det_mul, A.inv_mul, det_one] }
map_one' := Units.ext det_one
map_mul' A B := Units.ext <| det_mul _ _
/-- The `GL n R` and `Matrix.GeneralLinearGroup R n` groups are multiplicatively equivalent-/
def toLin : GL n R ≃* LinearMap.GeneralLinearGroup R (n → R) :=
Units.mapEquiv toLinAlgEquiv'.toMulEquiv
/-- Given a matrix with invertible determinant we get an element of `GL n R`-/
def mk' (A : Matrix n n R) (_ : Invertible (Matrix.det A)) : GL n R :=
unitOfDetInvertible A
/-- Given a matrix with unit determinant we get an element of `GL n R`-/
noncomputable def mk'' (A : Matrix n n R) (h : IsUnit (Matrix.det A)) : GL n R :=
nonsingInvUnit A h
/-- Given a matrix with non-zero determinant over a field, we get an element of `GL n K`-/
def mkOfDetNeZero {K : Type*} [Field K] (A : Matrix n n K) (h : Matrix.det A ≠ 0) : GL n K :=
mk' A (invertibleOfNonzero h)
theorem ext_iff (A B : GL n R) : A = B ↔ ∀ i j, (A : Matrix n n R) i j = (B : Matrix n n R) i j :=
Units.ext_iff.trans Matrix.ext_iff.symm
/-- Not marked `@[ext]` as the `ext` tactic already solves this. -/
theorem ext ⦃A B : GL n R⦄ (h : ∀ i j, (A : Matrix n n R) i j = (B : Matrix n n R) i j) : A = B :=
Units.ext <| Matrix.ext h
section CoeLemmas
variable (A B : GL n R)
@[simp]
theorem coe_mul : ↑(A * B) = (↑A : Matrix n n R) * (↑B : Matrix n n R) :=
rfl
@[simp]
theorem coe_one : ↑(1 : GL n R) = (1 : Matrix n n R) :=
rfl
theorem coe_inv : ↑A⁻¹ = (↑A : Matrix n n R)⁻¹ :=
letI := A.invertible
invOf_eq_nonsing_inv (↑A : Matrix n n R)
/-- An element of the matrix general linear group on `(n) [Fintype n]` can be considered as an
element of the endomorphism general linear group on `n → R`. -/
def toLinear : GeneralLinearGroup n R ≃* LinearMap.GeneralLinearGroup R (n → R) :=
Units.mapEquiv Matrix.toLinAlgEquiv'.toRingEquiv.toMulEquiv
-- Note that without the `@` and `‹_›`, Lean infers `fun a b ↦ _inst a b` instead of `_inst` as the
-- decidability argument, which prevents `simp` from obtaining the instance by unification.
-- These `fun a b ↦ _inst a b` terms also appear in the type of `A`, but simp doesn't get confused
-- by them so for now we do not care.
@[simp]
theorem coe_toLinear : (@toLinear n ‹_› ‹_› _ _ A : (n → R) →ₗ[R] n → R) = Matrix.mulVecLin A :=
rfl
-- Porting note: is inserting toLinearEquiv here correct?
@[simp]
theorem toLinear_apply (v : n → R) : (toLinear A).toLinearEquiv v = Matrix.mulVecLin (↑A) v :=
rfl
end CoeLemmas
variable {S T : Type*} [CommRing S] [CommRing T]
/-- A ring homomorphism ``f : R →+* S`` induces a homomorphism ``GLₙ(f) : GLₙ(R) →* GLₙ(S)``. -/
def map (f : R →+* S) : GL n R →* GL n S := Units.map <| (RingHom.mapMatrix f).toMonoidHom
@[simp]
theorem map_id : map (RingHom.id R) = MonoidHom.id (GL n R) :=
rfl
@[simp]
theorem map_comp (f : T →+* R) (g : R →+* S) :
map (g.comp f) = (map g).comp (map (n := n) f) :=
rfl
@[simp]
theorem map_comp_apply (f : T →+* R) (g : R →+* S) (x : GL n T) :
(map g).comp (map f) x = map g (map f x) :=
rfl
end GeneralLinearGroup
namespace SpecialLinearGroup
variable {n : Type u} [DecidableEq n] [Fintype n] {R : Type v} [CommRing R]
-- Porting note: added implementation for the Coe
/-- The map from SL(n) to GL(n) underlying the coercion, forgetting the value of the determinant.
-/
@[coe]
def coeToGL (A : SpecialLinearGroup n R) : GL n R :=
⟨↑A, ↑A⁻¹,
congr_arg ((↑) : _ → Matrix n n R) (mul_right_inv A),
congr_arg ((↑) : _ → Matrix n n R) (mul_left_inv A)⟩
instance hasCoeToGeneralLinearGroup : Coe (SpecialLinearGroup n R) (GL n R) :=
⟨coeToGL⟩
@[simp]
theorem coeToGL_det (g : SpecialLinearGroup n R) :
Matrix.GeneralLinearGroup.det (g : GL n R) = 1 :=
Units.ext g.prop
end SpecialLinearGroup
section
variable {n : Type u} {R : Type v} [DecidableEq n] [Fintype n] [LinearOrderedCommRing R]
section
variable (n R)
/-- This is the subgroup of `nxn` matrices with entries over a
linear ordered ring and positive determinant. -/
def GLPos : Subgroup (GL n R) :=
(Units.posSubgroup R).comap GeneralLinearGroup.det
end
@[simp]
theorem mem_glpos (A : GL n R) : A ∈ GLPos n R ↔ 0 < (Matrix.GeneralLinearGroup.det A : R) :=
Iff.rfl
theorem GLPos.det_ne_zero (A : GLPos n R) : ((A : GL n R) : Matrix n n R).det ≠ 0 :=
ne_of_gt A.prop
end
section Neg
variable {n : Type u} {R : Type v} [DecidableEq n] [Fintype n] [LinearOrderedCommRing R]
[Fact (Even (Fintype.card n))]
/-- Formal operation of negation on general linear group on even cardinality `n` given by negating
each element. -/
instance : Neg (GLPos n R) :=
⟨fun g =>
⟨-g, by
rw [mem_glpos, GeneralLinearGroup.val_det_apply, Units.val_neg, det_neg,
(Fact.out (p := Even <| Fintype.card n)).neg_one_pow, one_mul]
exact g.prop⟩⟩
@[simp]
theorem GLPos.coe_neg_GL (g : GLPos n R) : ↑(-g) = -(g : GL n R) :=
rfl
@[simp]
theorem GLPos.coe_neg (g : GLPos n R) : (↑(-g) : GL n R) = -((g : GL n R) : Matrix n n R) :=
rfl
@[simp]
theorem GLPos.coe_neg_apply (g : GLPos n R) (i j : n) :
((↑(-g) : GL n R) : Matrix n n R) i j = -((g : GL n R) : Matrix n n R) i j :=
rfl
instance : HasDistribNeg (GLPos n R) :=
Subtype.coe_injective.hasDistribNeg _ GLPos.coe_neg_GL (GLPos n R).coe_mul
end Neg
namespace SpecialLinearGroup
variable {n : Type u} [DecidableEq n] [Fintype n] {R : Type v} [LinearOrderedCommRing R]
/-- `Matrix.SpecialLinearGroup n R` embeds into `GL_pos n R` -/
def toGLPos : SpecialLinearGroup n R →* GLPos n R where
toFun A := ⟨(A : GL n R), show 0 < (↑A : Matrix n n R).det from A.prop.symm ▸ zero_lt_one⟩
map_one' := Subtype.ext <| Units.ext <| rfl
map_mul' _ _ := Subtype.ext <| Units.ext <| rfl
instance : Coe (SpecialLinearGroup n R) (GLPos n R) :=
⟨toGLPos⟩
theorem toGLPos_injective : Function.Injective (toGLPos : SpecialLinearGroup n R → GLPos n R) :=
-- Porting note: had to rewrite this to hint the correct types to Lean
-- (It can't find the coercion GLPos n R → Matrix n n R)
Function.Injective.of_comp
(f := fun (A : GLPos n R) ↦ ((A : GL n R) : Matrix n n R))
(show Function.Injective (_ ∘ (toGLPos : SpecialLinearGroup n R → GLPos n R))
from Subtype.coe_injective)
/-- Coercing a `Matrix.SpecialLinearGroup` via `GL_pos` and `GL` is the same as coercing straight to
a matrix. -/
@[simp]
theorem coe_GLPos_coe_GL_coe_matrix (g : SpecialLinearGroup n R) :
(↑(↑(↑g : GLPos n R) : GL n R) : Matrix n n R) = ↑g :=
rfl
@[simp]
theorem coe_to_GLPos_to_GL_det (g : SpecialLinearGroup n R) :
Matrix.GeneralLinearGroup.det ((g : GLPos n R) : GL n R) = 1 :=
Units.ext g.prop
variable [Fact (Even (Fintype.card n))]
@[norm_cast]
theorem coe_GLPos_neg (g : SpecialLinearGroup n R) : ↑(-g) = -(↑g : GLPos n R) :=
Subtype.ext <| Units.ext rfl
end SpecialLinearGroup
end Matrix
|
LinearAlgebra\Multilinear\Basic.lean | /-
Copyright (c) 2020 Sébastien Gouëzel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Sébastien Gouëzel
-/
import Mathlib.Algebra.Algebra.Defs
import Mathlib.Algebra.Order.BigOperators.Group.Finset
import Mathlib.Data.Fintype.BigOperators
import Mathlib.Data.Fintype.Sort
import Mathlib.Data.List.FinRange
import Mathlib.LinearAlgebra.Pi
import Mathlib.Logic.Equiv.Fintype
import Mathlib.Tactic.Abel
/-!
# Multilinear maps
We define multilinear maps as maps from `∀ (i : ι), M₁ i` to `M₂` which are linear in each
coordinate. Here, `M₁ i` and `M₂` are modules over a ring `R`, and `ι` is an arbitrary type
(although some statements will require it to be a fintype). This space, denoted by
`MultilinearMap R M₁ M₂`, inherits a module structure by pointwise addition and multiplication.
## Main definitions
* `MultilinearMap R M₁ M₂` is the space of multilinear maps from `∀ (i : ι), M₁ i` to `M₂`.
* `f.map_smul` is the multiplicativity of the multilinear map `f` along each coordinate.
* `f.map_add` is the additivity of the multilinear map `f` along each coordinate.
* `f.map_smul_univ` expresses the multiplicativity of `f` over all coordinates at the same time,
writing `f (fun i => c i • m i)` as `(∏ i, c i) • f m`.
* `f.map_add_univ` expresses the additivity of `f` over all coordinates at the same time, writing
`f (m + m')` as the sum over all subsets `s` of `ι` of `f (s.piecewise m m')`.
* `f.map_sum` expresses `f (Σ_{j₁} g₁ j₁, ..., Σ_{jₙ} gₙ jₙ)` as the sum of
`f (g₁ (r 1), ..., gₙ (r n))` where `r` ranges over all possible functions.
We also register isomorphisms corresponding to currying or uncurrying variables, transforming a
multilinear function `f` on `n+1` variables into a linear function taking values in multilinear
functions in `n` variables, and into a multilinear function in `n` variables taking values in linear
functions. These operations are called `f.curryLeft` and `f.curryRight` respectively
(with inverses `f.uncurryLeft` and `f.uncurryRight`). These operations induce linear equivalences
between spaces of multilinear functions in `n+1` variables and spaces of linear functions into
multilinear functions in `n` variables (resp. multilinear functions in `n` variables taking values
in linear functions), called respectively `multilinearCurryLeftEquiv` and
`multilinearCurryRightEquiv`.
## Implementation notes
Expressing that a map is linear along the `i`-th coordinate when all other coordinates are fixed
can be done in two (equivalent) different ways:
* fixing a vector `m : ∀ (j : ι - i), M₁ j.val`, and then choosing separately the `i`-th coordinate
* fixing a vector `m : ∀j, M₁ j`, and then modifying its `i`-th coordinate
The second way is more artificial as the value of `m` at `i` is not relevant, but it has the
advantage of avoiding subtype inclusion issues. This is the definition we use, based on
`Function.update` that allows to change the value of `m` at `i`.
Note that the use of `Function.update` requires a `DecidableEq ι` term to appear somewhere in the
statement of `MultilinearMap.map_add'` and `MultilinearMap.map_smul'`. Three possible choices
are:
1. Requiring `DecidableEq ι` as an argument to `MultilinearMap` (as we did originally).
2. Using `Classical.decEq ι` in the statement of `map_add'` and `map_smul'`.
3. Quantifying over all possible `DecidableEq ι` instances in the statement of `map_add'` and
`map_smul'`.
Option 1 works fine, but puts unnecessary constraints on the user (the zero map certainly does not
need decidability). Option 2 looks great at first, but in the common case when `ι = Fin n` it
introduces non-defeq decidability instance diamonds within the context of proving `map_add'` and
`map_smul'`, of the form `Fin.decidableEq n = Classical.decEq (Fin n)`. Option 3 of course does
something similar, but of the form `Fin.decidableEq n = _inst`, which is much easier to clean up
since `_inst` is a free variable and so the equality can just be substituted.
-/
open Function Fin Set
universe uR uS uι v v' v₁ v₂ v₃
variable {R : Type uR} {S : Type uS} {ι : Type uι} {n : ℕ}
{M : Fin n.succ → Type v} {M₁ : ι → Type v₁} {M₂ : Type v₂} {M₃ : Type v₃} {M' : Type v'}
/-- Multilinear maps over the ring `R`, from `∀ i, M₁ i` to `M₂` where `M₁ i` and `M₂` are modules
over `R`. -/
structure MultilinearMap (R : Type uR) {ι : Type uι} (M₁ : ι → Type v₁) (M₂ : Type v₂) [Semiring R]
[∀ i, AddCommMonoid (M₁ i)] [AddCommMonoid M₂] [∀ i, Module R (M₁ i)] [Module R M₂] where
/-- The underlying multivariate function of a multilinear map. -/
toFun : (∀ i, M₁ i) → M₂
/-- A multilinear map is additive in every argument. -/
map_add' :
∀ [DecidableEq ι] (m : ∀ i, M₁ i) (i : ι) (x y : M₁ i),
toFun (update m i (x + y)) = toFun (update m i x) + toFun (update m i y)
/-- A multilinear map is compatible with scalar multiplication in every argument. -/
map_smul' :
∀ [DecidableEq ι] (m : ∀ i, M₁ i) (i : ι) (c : R) (x : M₁ i),
toFun (update m i (c • x)) = c • toFun (update m i x)
-- Porting note: added to avoid a linter timeout.
attribute [nolint simpNF] MultilinearMap.mk.injEq
namespace MultilinearMap
section Semiring
variable [Semiring R] [∀ i, AddCommMonoid (M i)] [∀ i, AddCommMonoid (M₁ i)] [AddCommMonoid M₂]
[AddCommMonoid M₃] [AddCommMonoid M'] [∀ i, Module R (M i)] [∀ i, Module R (M₁ i)] [Module R M₂]
[Module R M₃] [Module R M'] (f f' : MultilinearMap R M₁ M₂)
-- Porting note: Replaced CoeFun with FunLike instance
instance : FunLike (MultilinearMap R M₁ M₂) (∀ i, M₁ i) M₂ where
coe f := f.toFun
coe_injective' := fun f g h ↦ by cases f; cases g; cases h; rfl
initialize_simps_projections MultilinearMap (toFun → apply)
@[simp]
theorem toFun_eq_coe : f.toFun = ⇑f :=
rfl
@[simp]
theorem coe_mk (f : (∀ i, M₁ i) → M₂) (h₁ h₂) : ⇑(⟨f, h₁, h₂⟩ : MultilinearMap R M₁ M₂) = f :=
rfl
theorem congr_fun {f g : MultilinearMap R M₁ M₂} (h : f = g) (x : ∀ i, M₁ i) : f x = g x :=
DFunLike.congr_fun h x
nonrec theorem congr_arg (f : MultilinearMap R M₁ M₂) {x y : ∀ i, M₁ i} (h : x = y) : f x = f y :=
DFunLike.congr_arg f h
theorem coe_injective : Injective ((↑) : MultilinearMap R M₁ M₂ → (∀ i, M₁ i) → M₂) :=
DFunLike.coe_injective
@[norm_cast] -- Porting note (#10618): Removed simp attribute, simp can prove this
theorem coe_inj {f g : MultilinearMap R M₁ M₂} : (f : (∀ i, M₁ i) → M₂) = g ↔ f = g :=
DFunLike.coe_fn_eq
@[ext]
theorem ext {f f' : MultilinearMap R M₁ M₂} (H : ∀ x, f x = f' x) : f = f' :=
DFunLike.ext _ _ H
@[simp]
theorem mk_coe (f : MultilinearMap R M₁ M₂) (h₁ h₂) :
(⟨f, h₁, h₂⟩ : MultilinearMap R M₁ M₂) = f := rfl
@[simp]
protected theorem map_add [DecidableEq ι] (m : ∀ i, M₁ i) (i : ι) (x y : M₁ i) :
f (update m i (x + y)) = f (update m i x) + f (update m i y) :=
f.map_add' m i x y
@[simp]
protected theorem map_smul [DecidableEq ι] (m : ∀ i, M₁ i) (i : ι) (c : R) (x : M₁ i) :
f (update m i (c • x)) = c • f (update m i x) :=
f.map_smul' m i c x
theorem map_coord_zero {m : ∀ i, M₁ i} (i : ι) (h : m i = 0) : f m = 0 := by
classical
have : (0 : R) • (0 : M₁ i) = 0 := by simp
rw [← update_eq_self i m, h, ← this, f.map_smul, zero_smul R (M := M₂)]
@[simp]
theorem map_update_zero [DecidableEq ι] (m : ∀ i, M₁ i) (i : ι) : f (update m i 0) = 0 :=
f.map_coord_zero i (update_same i 0 m)
@[simp]
theorem map_zero [Nonempty ι] : f 0 = 0 := by
obtain ⟨i, _⟩ : ∃ i : ι, i ∈ Set.univ := Set.exists_mem_of_nonempty ι
exact map_coord_zero f i rfl
instance : Add (MultilinearMap R M₁ M₂) :=
⟨fun f f' =>
⟨fun x => f x + f' x, fun m i x y => by simp [add_left_comm, add_assoc], fun m i c x => by
simp [smul_add]⟩⟩
@[simp]
theorem add_apply (m : ∀ i, M₁ i) : (f + f') m = f m + f' m :=
rfl
instance : Zero (MultilinearMap R M₁ M₂) :=
⟨⟨fun _ => 0, fun _ i _ _ => by simp, fun _ i c _ => by simp⟩⟩
instance : Inhabited (MultilinearMap R M₁ M₂) :=
⟨0⟩
@[simp]
theorem zero_apply (m : ∀ i, M₁ i) : (0 : MultilinearMap R M₁ M₂) m = 0 :=
rfl
section SMul
variable {R' A : Type*} [Monoid R'] [Semiring A] [∀ i, Module A (M₁ i)] [DistribMulAction R' M₂]
[Module A M₂] [SMulCommClass A R' M₂]
instance : SMul R' (MultilinearMap A M₁ M₂) :=
⟨fun c f =>
⟨fun m => c • f m, fun m i x y => by simp [smul_add], fun l i x d => by
simp [← smul_comm x c (_ : M₂)]⟩⟩
@[simp]
theorem smul_apply (f : MultilinearMap A M₁ M₂) (c : R') (m : ∀ i, M₁ i) : (c • f) m = c • f m :=
rfl
theorem coe_smul (c : R') (f : MultilinearMap A M₁ M₂) : ⇑(c • f) = c • (⇑ f) :=
rfl
end SMul
instance addCommMonoid : AddCommMonoid (MultilinearMap R M₁ M₂) :=
coe_injective.addCommMonoid _ rfl (fun _ _ => rfl) fun _ _ => rfl
/-- Coercion of a multilinear map to a function as an additive monoid homomorphism. -/
@[simps] def coeAddMonoidHom : MultilinearMap R M₁ M₂ →+ (((i : ι) → M₁ i) → M₂) where
toFun := DFunLike.coe; map_zero' := rfl; map_add' _ _ := rfl
@[simp]
theorem coe_sum {α : Type*} (f : α → MultilinearMap R M₁ M₂) (s : Finset α) :
⇑(∑ a ∈ s, f a) = ∑ a ∈ s, ⇑(f a) :=
map_sum coeAddMonoidHom f s
theorem sum_apply {α : Type*} (f : α → MultilinearMap R M₁ M₂) (m : ∀ i, M₁ i) {s : Finset α} :
(∑ a ∈ s, f a) m = ∑ a ∈ s, f a m := by simp
/-- If `f` is a multilinear map, then `f.toLinearMap m i` is the linear map obtained by fixing all
coordinates but `i` equal to those of `m`, and varying the `i`-th coordinate. -/
@[simps]
def toLinearMap [DecidableEq ι] (m : ∀ i, M₁ i) (i : ι) : M₁ i →ₗ[R] M₂ where
toFun x := f (update m i x)
map_add' x y := by simp
map_smul' c x := by simp
/-- The cartesian product of two multilinear maps, as a multilinear map. -/
@[simps]
def prod (f : MultilinearMap R M₁ M₂) (g : MultilinearMap R M₁ M₃) :
MultilinearMap R M₁ (M₂ × M₃) where
toFun m := (f m, g m)
map_add' m i x y := by simp
map_smul' m i c x := by simp
/-- Combine a family of multilinear maps with the same domain and codomains `M' i` into a
multilinear map taking values in the space of functions `∀ i, M' i`. -/
@[simps]
def pi {ι' : Type*} {M' : ι' → Type*} [∀ i, AddCommMonoid (M' i)] [∀ i, Module R (M' i)]
(f : ∀ i, MultilinearMap R M₁ (M' i)) : MultilinearMap R M₁ (∀ i, M' i) where
toFun m i := f i m
map_add' _ _ _ _ := funext fun j => (f j).map_add _ _ _ _
map_smul' _ _ _ _ := funext fun j => (f j).map_smul _ _ _ _
section
variable (R M₂ M₃)
/-- Equivalence between linear maps `M₂ →ₗ[R] M₃` and one-multilinear maps. -/
@[simps]
def ofSubsingleton [Subsingleton ι] (i : ι) :
(M₂ →ₗ[R] M₃) ≃ MultilinearMap R (fun _ : ι ↦ M₂) M₃ where
toFun f :=
{ toFun := fun x ↦ f (x i)
map_add' := by intros; simp [update_eq_const_of_subsingleton]
map_smul' := by intros; simp [update_eq_const_of_subsingleton] }
invFun f :=
{ toFun := fun x ↦ f fun _ ↦ x
map_add' := fun x y ↦ by simpa [update_eq_const_of_subsingleton] using f.map_add 0 i x y
map_smul' := fun c x ↦ by simpa [update_eq_const_of_subsingleton] using f.map_smul 0 i c x }
left_inv f := rfl
right_inv f := by ext x; refine congr_arg f ?_; exact (eq_const_of_subsingleton _ _).symm
variable (M₁) {M₂}
/-- The constant map is multilinear when `ι` is empty. -/
-- Porting note: Removed [simps] & added simpNF-approved version of the generated lemma manually.
@[simps (config := .asFn)]
def constOfIsEmpty [IsEmpty ι] (m : M₂) : MultilinearMap R M₁ M₂ where
toFun := Function.const _ m
map_add' _ := isEmptyElim
map_smul' _ := isEmptyElim
end
-- Porting note: Included `DFunLike.coe` to avoid strange CoeFun instance for Equiv
/-- Given a multilinear map `f` on `n` variables (parameterized by `Fin n`) and a subset `s` of `k`
of these variables, one gets a new multilinear map on `Fin k` by varying these variables, and fixing
the other ones equal to a given value `z`. It is denoted by `f.restr s hk z`, where `hk` is a
proof that the cardinality of `s` is `k`. The implicit identification between `Fin k` and `s` that
we use is the canonical (increasing) bijection. -/
def restr {k n : ℕ} (f : MultilinearMap R (fun _ : Fin n => M') M₂) (s : Finset (Fin n))
(hk : s.card = k) (z : M') : MultilinearMap R (fun _ : Fin k => M') M₂ where
toFun v := f fun j => if h : j ∈ s then v ((DFunLike.coe (s.orderIsoOfFin hk).symm) ⟨j, h⟩) else z
/- Porting note: The proofs of the following two lemmas used to only use `erw` followed by `simp`,
but it seems `erw` no longer unfolds or unifies well enough to work without more help. -/
map_add' v i x y := by
have : DFunLike.coe (s.orderIsoOfFin hk).symm = (s.orderIsoOfFin hk).toEquiv.symm := rfl
simp only [this]
erw [dite_comp_equiv_update (s.orderIsoOfFin hk).toEquiv,
dite_comp_equiv_update (s.orderIsoOfFin hk).toEquiv,
dite_comp_equiv_update (s.orderIsoOfFin hk).toEquiv]
simp
map_smul' v i c x := by
have : DFunLike.coe (s.orderIsoOfFin hk).symm = (s.orderIsoOfFin hk).toEquiv.symm := rfl
simp only [this]
erw [dite_comp_equiv_update (s.orderIsoOfFin hk).toEquiv,
dite_comp_equiv_update (s.orderIsoOfFin hk).toEquiv]
simp
/-- In the specific case of multilinear maps on spaces indexed by `Fin (n+1)`, where one can build
an element of `∀ (i : Fin (n+1)), M i` using `cons`, one can express directly the additivity of a
multilinear map along the first variable. -/
theorem cons_add (f : MultilinearMap R M M₂) (m : ∀ i : Fin n, M i.succ) (x y : M 0) :
f (cons (x + y) m) = f (cons x m) + f (cons y m) := by
simp_rw [← update_cons_zero x m (x + y), f.map_add, update_cons_zero]
/-- In the specific case of multilinear maps on spaces indexed by `Fin (n+1)`, where one can build
an element of `∀ (i : Fin (n+1)), M i` using `cons`, one can express directly the multiplicativity
of a multilinear map along the first variable. -/
theorem cons_smul (f : MultilinearMap R M M₂) (m : ∀ i : Fin n, M i.succ) (c : R) (x : M 0) :
f (cons (c • x) m) = c • f (cons x m) := by
simp_rw [← update_cons_zero x m (c • x), f.map_smul, update_cons_zero]
/-- In the specific case of multilinear maps on spaces indexed by `Fin (n+1)`, where one can build
an element of `∀ (i : Fin (n+1)), M i` using `snoc`, one can express directly the additivity of a
multilinear map along the first variable. -/
theorem snoc_add (f : MultilinearMap R M M₂)
(m : ∀ i : Fin n, M (castSucc i)) (x y : M (last n)) :
f (snoc m (x + y)) = f (snoc m x) + f (snoc m y) := by
simp_rw [← update_snoc_last x m (x + y), f.map_add, update_snoc_last]
/-- In the specific case of multilinear maps on spaces indexed by `Fin (n+1)`, where one can build
an element of `∀ (i : Fin (n+1)), M i` using `cons`, one can express directly the multiplicativity
of a multilinear map along the first variable. -/
theorem snoc_smul (f : MultilinearMap R M M₂) (m : ∀ i : Fin n, M (castSucc i)) (c : R)
(x : M (last n)) : f (snoc m (c • x)) = c • f (snoc m x) := by
simp_rw [← update_snoc_last x m (c • x), f.map_smul, update_snoc_last]
section
variable {M₁' : ι → Type*} [∀ i, AddCommMonoid (M₁' i)] [∀ i, Module R (M₁' i)]
variable {M₁'' : ι → Type*} [∀ i, AddCommMonoid (M₁'' i)] [∀ i, Module R (M₁'' i)]
/-- If `g` is a multilinear map and `f` is a collection of linear maps,
then `g (f₁ m₁, ..., fₙ mₙ)` is again a multilinear map, that we call
`g.compLinearMap f`. -/
def compLinearMap (g : MultilinearMap R M₁' M₂) (f : ∀ i, M₁ i →ₗ[R] M₁' i) :
MultilinearMap R M₁ M₂ where
toFun m := g fun i => f i (m i)
map_add' m i x y := by
have : ∀ j z, f j (update m i z j) = update (fun k => f k (m k)) i (f i z) j := fun j z =>
Function.apply_update (fun k => f k) _ _ _ _
simp [this]
map_smul' m i c x := by
have : ∀ j z, f j (update m i z j) = update (fun k => f k (m k)) i (f i z) j := fun j z =>
Function.apply_update (fun k => f k) _ _ _ _
simp [this]
@[simp]
theorem compLinearMap_apply (g : MultilinearMap R M₁' M₂) (f : ∀ i, M₁ i →ₗ[R] M₁' i)
(m : ∀ i, M₁ i) : g.compLinearMap f m = g fun i => f i (m i) :=
rfl
/-- Composing a multilinear map twice with a linear map in each argument is
the same as composing with their composition. -/
theorem compLinearMap_assoc (g : MultilinearMap R M₁'' M₂) (f₁ : ∀ i, M₁' i →ₗ[R] M₁'' i)
(f₂ : ∀ i, M₁ i →ₗ[R] M₁' i) :
(g.compLinearMap f₁).compLinearMap f₂ = g.compLinearMap fun i => f₁ i ∘ₗ f₂ i :=
rfl
/-- Composing the zero multilinear map with a linear map in each argument. -/
@[simp]
theorem zero_compLinearMap (f : ∀ i, M₁ i →ₗ[R] M₁' i) :
(0 : MultilinearMap R M₁' M₂).compLinearMap f = 0 :=
ext fun _ => rfl
/-- Composing a multilinear map with the identity linear map in each argument. -/
@[simp]
theorem compLinearMap_id (g : MultilinearMap R M₁' M₂) :
(g.compLinearMap fun _ => LinearMap.id) = g :=
ext fun _ => rfl
/-- Composing with a family of surjective linear maps is injective. -/
theorem compLinearMap_injective (f : ∀ i, M₁ i →ₗ[R] M₁' i) (hf : ∀ i, Surjective (f i)) :
Injective fun g : MultilinearMap R M₁' M₂ => g.compLinearMap f := fun g₁ g₂ h =>
ext fun x => by
simpa [fun i => surjInv_eq (hf i)]
using MultilinearMap.ext_iff.mp h fun i => surjInv (hf i) (x i)
theorem compLinearMap_inj (f : ∀ i, M₁ i →ₗ[R] M₁' i) (hf : ∀ i, Surjective (f i))
(g₁ g₂ : MultilinearMap R M₁' M₂) : g₁.compLinearMap f = g₂.compLinearMap f ↔ g₁ = g₂ :=
(compLinearMap_injective _ hf).eq_iff
/-- Composing a multilinear map with a linear equiv on each argument gives the zero map
if and only if the multilinear map is the zero map. -/
@[simp]
theorem comp_linearEquiv_eq_zero_iff (g : MultilinearMap R M₁' M₂) (f : ∀ i, M₁ i ≃ₗ[R] M₁' i) :
(g.compLinearMap fun i => (f i : M₁ i →ₗ[R] M₁' i)) = 0 ↔ g = 0 := by
set f' := fun i => (f i : M₁ i →ₗ[R] M₁' i)
rw [← zero_compLinearMap f', compLinearMap_inj f' fun i => (f i).surjective]
end
/-- If one adds to a vector `m'` another vector `m`, but only for coordinates in a finset `t`, then
the image under a multilinear map `f` is the sum of `f (s.piecewise m m')` along all subsets `s` of
`t`. This is mainly an auxiliary statement to prove the result when `t = univ`, given in
`map_add_univ`, although it can be useful in its own right as it does not require the index set `ι`
to be finite. -/
theorem map_piecewise_add [DecidableEq ι] (m m' : ∀ i, M₁ i) (t : Finset ι) :
f (t.piecewise (m + m') m') = ∑ s ∈ t.powerset, f (s.piecewise m m') := by
revert m'
refine Finset.induction_on t (by simp) ?_
intro i t hit Hrec m'
have A : (insert i t).piecewise (m + m') m' = update (t.piecewise (m + m') m') i (m i + m' i) :=
t.piecewise_insert _ _ _
have B : update (t.piecewise (m + m') m') i (m' i) = t.piecewise (m + m') m' := by
ext j
by_cases h : j = i
· rw [h]
simp [hit]
· simp [h]
let m'' := update m' i (m i)
have C : update (t.piecewise (m + m') m') i (m i) = t.piecewise (m + m'') m'' := by
ext j
by_cases h : j = i
· rw [h]
simp [m'', hit]
· by_cases h' : j ∈ t <;> simp [m'', h, hit, h']
rw [A, f.map_add, B, C, Finset.sum_powerset_insert hit, Hrec, Hrec, add_comm (_ : M₂)]
congr 1
refine Finset.sum_congr rfl fun s hs => ?_
have : (insert i s).piecewise m m' = s.piecewise m m'' := by
ext j
by_cases h : j = i
· rw [h]
simp [m'', Finset.not_mem_of_mem_powerset_of_not_mem hs hit]
· by_cases h' : j ∈ s <;> simp [m'', h, h']
rw [this]
/-- Additivity of a multilinear map along all coordinates at the same time,
writing `f (m + m')` as the sum of `f (s.piecewise m m')` over all sets `s`. -/
theorem map_add_univ [DecidableEq ι] [Fintype ι] (m m' : ∀ i, M₁ i) :
f (m + m') = ∑ s : Finset ι, f (s.piecewise m m') := by
simpa using f.map_piecewise_add m m' Finset.univ
section ApplySum
variable {α : ι → Type*} (g : ∀ i, α i → M₁ i) (A : ∀ i, Finset (α i))
open Fintype Finset
/-- If `f` is multilinear, then `f (Σ_{j₁ ∈ A₁} g₁ j₁, ..., Σ_{jₙ ∈ Aₙ} gₙ jₙ)` is the sum of
`f (g₁ (r 1), ..., gₙ (r n))` where `r` ranges over all functions with `r 1 ∈ A₁`, ...,
`r n ∈ Aₙ`. This follows from multilinearity by expanding successively with respect to each
coordinate. Here, we give an auxiliary statement tailored for an inductive proof. Use instead
`map_sum_finset`. -/
theorem map_sum_finset_aux [DecidableEq ι] [Fintype ι] {n : ℕ} (h : (∑ i, (A i).card) = n) :
(f fun i => ∑ j ∈ A i, g i j) = ∑ r ∈ piFinset A, f fun i => g i (r i) := by
letI := fun i => Classical.decEq (α i)
induction' n using Nat.strong_induction_on with n IH generalizing A
-- If one of the sets is empty, then all the sums are zero
by_cases Ai_empty : ∃ i, A i = ∅
· rcases Ai_empty with ⟨i, hi⟩
have : ∑ j ∈ A i, g i j = 0 := by rw [hi, Finset.sum_empty]
rw [f.map_coord_zero i this]
have : piFinset A = ∅ := by
refine Finset.eq_empty_of_forall_not_mem fun r hr => ?_
have : r i ∈ A i := mem_piFinset.mp hr i
simp [hi] at this
rw [this, Finset.sum_empty]
push_neg at Ai_empty
-- Otherwise, if all sets are at most singletons, then they are exactly singletons and the result
-- is again straightforward
by_cases Ai_singleton : ∀ i, (A i).card ≤ 1
· have Ai_card : ∀ i, (A i).card = 1 := by
intro i
have pos : Finset.card (A i) ≠ 0 := by simp [Finset.card_eq_zero, Ai_empty i]
have : Finset.card (A i) ≤ 1 := Ai_singleton i
exact le_antisymm this (Nat.succ_le_of_lt (_root_.pos_iff_ne_zero.mpr pos))
have :
∀ r : ∀ i, α i, r ∈ piFinset A → (f fun i => g i (r i)) = f fun i => ∑ j ∈ A i, g i j := by
intro r hr
congr with i
have : ∀ j ∈ A i, g i j = g i (r i) := by
intro j hj
congr
apply Finset.card_le_one_iff.1 (Ai_singleton i) hj
exact mem_piFinset.mp hr i
simp only [Finset.sum_congr rfl this, Finset.mem_univ, Finset.sum_const, Ai_card i, one_nsmul]
simp only [Finset.sum_congr rfl this, Ai_card, card_piFinset, prod_const_one, one_nsmul,
Finset.sum_const]
-- Remains the interesting case where one of the `A i`, say `A i₀`, has cardinality at least 2.
-- We will split into two parts `B i₀` and `C i₀` of smaller cardinality, let `B i = C i = A i`
-- for `i ≠ i₀`, apply the inductive assumption to `B` and `C`, and add up the corresponding
-- parts to get the sum for `A`.
push_neg at Ai_singleton
obtain ⟨i₀, hi₀⟩ : ∃ i, 1 < (A i).card := Ai_singleton
obtain ⟨j₁, j₂, _, hj₂, _⟩ : ∃ j₁ j₂, j₁ ∈ A i₀ ∧ j₂ ∈ A i₀ ∧ j₁ ≠ j₂ :=
Finset.one_lt_card_iff.1 hi₀
let B := Function.update A i₀ (A i₀ \ {j₂})
let C := Function.update A i₀ {j₂}
have B_subset_A : ∀ i, B i ⊆ A i := by
intro i
by_cases hi : i = i₀
· rw [hi]
simp only [B, sdiff_subset, update_same]
· simp only [B, hi, update_noteq, Ne, not_false_iff, Finset.Subset.refl]
have C_subset_A : ∀ i, C i ⊆ A i := by
intro i
by_cases hi : i = i₀
· rw [hi]
simp only [C, hj₂, Finset.singleton_subset_iff, update_same]
· simp only [C, hi, update_noteq, Ne, not_false_iff, Finset.Subset.refl]
-- split the sum at `i₀` as the sum over `B i₀` plus the sum over `C i₀`, to use additivity.
have A_eq_BC :
(fun i => ∑ j ∈ A i, g i j) =
Function.update (fun i => ∑ j ∈ A i, g i j) i₀
((∑ j ∈ B i₀, g i₀ j) + ∑ j ∈ C i₀, g i₀ j) := by
ext i
by_cases hi : i = i₀
· rw [hi, update_same]
have : A i₀ = B i₀ ∪ C i₀ := by
simp only [B, C, Function.update_same, Finset.sdiff_union_self_eq_union]
symm
simp only [hj₂, Finset.singleton_subset_iff, Finset.union_eq_left]
rw [this]
refine Finset.sum_union <| Finset.disjoint_right.2 fun j hj => ?_
have : j = j₂ := by
simpa [C] using hj
rw [this]
simp only [B, mem_sdiff, eq_self_iff_true, not_true, not_false_iff, Finset.mem_singleton,
update_same, and_false_iff]
· simp [hi]
have Beq :
Function.update (fun i => ∑ j ∈ A i, g i j) i₀ (∑ j ∈ B i₀, g i₀ j) = fun i =>
∑ j ∈ B i, g i j := by
ext i
by_cases hi : i = i₀
· rw [hi]
simp only [update_same]
· simp only [B, hi, update_noteq, Ne, not_false_iff]
have Ceq :
Function.update (fun i => ∑ j ∈ A i, g i j) i₀ (∑ j ∈ C i₀, g i₀ j) = fun i =>
∑ j ∈ C i, g i j := by
ext i
by_cases hi : i = i₀
· rw [hi]
simp only [update_same]
· simp only [C, hi, update_noteq, Ne, not_false_iff]
-- Express the inductive assumption for `B`
have Brec : (f fun i => ∑ j ∈ B i, g i j) = ∑ r ∈ piFinset B, f fun i => g i (r i) := by
have : (∑ i, Finset.card (B i)) < ∑ i, Finset.card (A i) := by
refine
Finset.sum_lt_sum (fun i _ => Finset.card_le_card (B_subset_A i))
⟨i₀, Finset.mem_univ _, ?_⟩
have : {j₂} ⊆ A i₀ := by simp [hj₂]
simp only [B, Finset.card_sdiff this, Function.update_same, Finset.card_singleton]
exact Nat.pred_lt (ne_of_gt (lt_trans Nat.zero_lt_one hi₀))
rw [h] at this
exact IH _ this B rfl
-- Express the inductive assumption for `C`
have Crec : (f fun i => ∑ j ∈ C i, g i j) = ∑ r ∈ piFinset C, f fun i => g i (r i) := by
have : (∑ i, Finset.card (C i)) < ∑ i, Finset.card (A i) :=
Finset.sum_lt_sum (fun i _ => Finset.card_le_card (C_subset_A i))
⟨i₀, Finset.mem_univ _, by simp [C, hi₀]⟩
rw [h] at this
exact IH _ this C rfl
have D : Disjoint (piFinset B) (piFinset C) :=
haveI : Disjoint (B i₀) (C i₀) := by simp [B, C]
piFinset_disjoint_of_disjoint B C this
have pi_BC : piFinset A = piFinset B ∪ piFinset C := by
apply Finset.Subset.antisymm
· intro r hr
by_cases hri₀ : r i₀ = j₂
· apply Finset.mem_union_right
refine mem_piFinset.2 fun i => ?_
by_cases hi : i = i₀
· have : r i₀ ∈ C i₀ := by simp [C, hri₀]
rwa [hi]
· simp [C, hi, mem_piFinset.1 hr i]
· apply Finset.mem_union_left
refine mem_piFinset.2 fun i => ?_
by_cases hi : i = i₀
· have : r i₀ ∈ B i₀ := by simp [B, hri₀, mem_piFinset.1 hr i₀]
rwa [hi]
· simp [B, hi, mem_piFinset.1 hr i]
· exact
Finset.union_subset (piFinset_subset _ _ fun i => B_subset_A i)
(piFinset_subset _ _ fun i => C_subset_A i)
rw [A_eq_BC]
simp only [MultilinearMap.map_add, Beq, Ceq, Brec, Crec, pi_BC]
rw [← Finset.sum_union D]
/-- If `f` is multilinear, then `f (Σ_{j₁ ∈ A₁} g₁ j₁, ..., Σ_{jₙ ∈ Aₙ} gₙ jₙ)` is the sum of
`f (g₁ (r 1), ..., gₙ (r n))` where `r` ranges over all functions with `r 1 ∈ A₁`, ...,
`r n ∈ Aₙ`. This follows from multilinearity by expanding successively with respect to each
coordinate. -/
theorem map_sum_finset [DecidableEq ι] [Fintype ι] :
(f fun i => ∑ j ∈ A i, g i j) = ∑ r ∈ piFinset A, f fun i => g i (r i) :=
f.map_sum_finset_aux _ _ rfl
/-- If `f` is multilinear, then `f (Σ_{j₁} g₁ j₁, ..., Σ_{jₙ} gₙ jₙ)` is the sum of
`f (g₁ (r 1), ..., gₙ (r n))` where `r` ranges over all functions `r`. This follows from
multilinearity by expanding successively with respect to each coordinate. -/
theorem map_sum [DecidableEq ι] [Fintype ι] [∀ i, Fintype (α i)] :
(f fun i => ∑ j, g i j) = ∑ r : ∀ i, α i, f fun i => g i (r i) :=
f.map_sum_finset g fun _ => Finset.univ
theorem map_update_sum {α : Type*} [DecidableEq ι] (t : Finset α) (i : ι) (g : α → M₁ i)
(m : ∀ i, M₁ i) : f (update m i (∑ a ∈ t, g a)) = ∑ a ∈ t, f (update m i (g a)) := by
classical
induction' t using Finset.induction with a t has ih h
· simp
· simp [Finset.sum_insert has, ih]
end ApplySum
/-- Restrict the codomain of a multilinear map to a submodule.
This is the multilinear version of `LinearMap.codRestrict`. -/
@[simps]
def codRestrict (f : MultilinearMap R M₁ M₂) (p : Submodule R M₂) (h : ∀ v, f v ∈ p) :
MultilinearMap R M₁ p where
toFun v := ⟨f v, h v⟩
map_add' _ _ _ _ := Subtype.ext <| MultilinearMap.map_add _ _ _ _ _
map_smul' _ _ _ _ := Subtype.ext <| MultilinearMap.map_smul _ _ _ _ _
section RestrictScalar
variable (R)
variable {A : Type*} [Semiring A] [SMul R A] [∀ i : ι, Module A (M₁ i)] [Module A M₂]
[∀ i, IsScalarTower R A (M₁ i)] [IsScalarTower R A M₂]
/-- Reinterpret an `A`-multilinear map as an `R`-multilinear map, if `A` is an algebra over `R`
and their actions on all involved modules agree with the action of `R` on `A`. -/
def restrictScalars (f : MultilinearMap A M₁ M₂) : MultilinearMap R M₁ M₂ where
toFun := f
map_add' := f.map_add
map_smul' m i := (f.toLinearMap m i).map_smul_of_tower
@[simp]
theorem coe_restrictScalars (f : MultilinearMap A M₁ M₂) : ⇑(f.restrictScalars R) = f :=
rfl
end RestrictScalar
section
variable {ι₁ ι₂ ι₃ : Type*}
/-- Transfer the arguments to a map along an equivalence between argument indices.
The naming is derived from `Finsupp.domCongr`, noting that here the permutation applies to the
domain of the domain. -/
@[simps apply]
def domDomCongr (σ : ι₁ ≃ ι₂) (m : MultilinearMap R (fun _ : ι₁ => M₂) M₃) :
MultilinearMap R (fun _ : ι₂ => M₂) M₃ where
toFun v := m fun i => v (σ i)
map_add' v i a b := by
letI := σ.injective.decidableEq
simp_rw [Function.update_apply_equiv_apply v]
rw [m.map_add]
map_smul' v i a b := by
letI := σ.injective.decidableEq
simp_rw [Function.update_apply_equiv_apply v]
rw [m.map_smul]
theorem domDomCongr_trans (σ₁ : ι₁ ≃ ι₂) (σ₂ : ι₂ ≃ ι₃)
(m : MultilinearMap R (fun _ : ι₁ => M₂) M₃) :
m.domDomCongr (σ₁.trans σ₂) = (m.domDomCongr σ₁).domDomCongr σ₂ :=
rfl
theorem domDomCongr_mul (σ₁ : Equiv.Perm ι₁) (σ₂ : Equiv.Perm ι₁)
(m : MultilinearMap R (fun _ : ι₁ => M₂) M₃) :
m.domDomCongr (σ₂ * σ₁) = (m.domDomCongr σ₁).domDomCongr σ₂ :=
rfl
/-- `MultilinearMap.domDomCongr` as an equivalence.
This is declared separately because it does not work with dot notation. -/
@[simps apply symm_apply]
def domDomCongrEquiv (σ : ι₁ ≃ ι₂) :
MultilinearMap R (fun _ : ι₁ => M₂) M₃ ≃+ MultilinearMap R (fun _ : ι₂ => M₂) M₃ where
toFun := domDomCongr σ
invFun := domDomCongr σ.symm
left_inv m := by
ext
simp [domDomCongr]
right_inv m := by
ext
simp [domDomCongr]
map_add' a b := by
ext
simp [domDomCongr]
/-- The results of applying `domDomCongr` to two maps are equal if
and only if those maps are. -/
@[simp]
theorem domDomCongr_eq_iff (σ : ι₁ ≃ ι₂) (f g : MultilinearMap R (fun _ : ι₁ => M₂) M₃) :
f.domDomCongr σ = g.domDomCongr σ ↔ f = g :=
(domDomCongrEquiv σ : _ ≃+ MultilinearMap R (fun _ => M₂) M₃).apply_eq_iff_eq
end
/-! If `{a // P a}` is a subtype of `ι` and if we fix an element `z` of `(i : {a // ¬ P a}) → M₁ i`,
then a multilinear map on `M₁` defines a multilinear map on the restriction of `M₁` to
`{a // P a}`, by fixing the arguments out of `{a // P a}` equal to the values of `z`. -/
lemma domDomRestrict_aux {ι} [DecidableEq ι] (P : ι → Prop) [DecidablePred P] {M₁ : ι → Type*}
[DecidableEq {a // P a}]
(x : (i : {a // P a}) → M₁ i) (z : (i : {a // ¬ P a}) → M₁ i) (i : {a : ι // P a})
(c : M₁ i) : (fun j ↦ if h : P j then Function.update x i c ⟨j, h⟩ else z ⟨j, h⟩) =
Function.update (fun j => if h : P j then x ⟨j, h⟩ else z ⟨j, h⟩) i c := by
ext j
by_cases h : j = i
· rw [h, Function.update_same]
simp only [i.2, update_same, dite_true]
· rw [Function.update_noteq h]
by_cases h' : P j
· simp only [h', ne_eq, Subtype.mk.injEq, dite_true]
have h'' : ¬ ⟨j, h'⟩ = i :=
fun he => by apply_fun (fun x => x.1) at he; exact h he
rw [Function.update_noteq h'']
· simp only [h', ne_eq, Subtype.mk.injEq, dite_false]
lemma domDomRestrict_aux_right {ι} [DecidableEq ι] (P : ι → Prop) [DecidablePred P] {M₁ : ι → Type*}
[DecidableEq {a // ¬ P a}]
(x : (i : {a // P a}) → M₁ i) (z : (i : {a // ¬ P a}) → M₁ i) (i : {a : ι // ¬ P a})
(c : M₁ i) : (fun j ↦ if h : P j then x ⟨j, h⟩ else Function.update z i c ⟨j, h⟩) =
Function.update (fun j => if h : P j then x ⟨j, h⟩ else z ⟨j, h⟩) i c := by
simpa only [dite_not] using domDomRestrict_aux _ z (fun j ↦ x ⟨j.1, not_not.mp j.2⟩) i c
/-- Given a multilinear map `f` on `(i : ι) → M i`, a (decidable) predicate `P` on `ι` and
an element `z` of `(i : {a // ¬ P a}) → M₁ i`, construct a multilinear map on
`(i : {a // P a}) → M₁ i)` whose value at `x` is `f` evaluated at the vector with `i`th coordinate
`x i` if `P i` and `z i` otherwise.
The naming is similar to `MultilinearMap.domDomCongr`: here we are applying the restriction to the
domain of the domain.
For a linear map version, see `MultilinearMap.domDomRestrictₗ`.
-/
def domDomRestrict (f : MultilinearMap R M₁ M₂) (P : ι → Prop) [DecidablePred P]
(z : (i : {a : ι // ¬ P a}) → M₁ i) :
MultilinearMap R (fun (i : {a : ι // P a}) => M₁ i) M₂ where
toFun x := f (fun j ↦ if h : P j then x ⟨j, h⟩ else z ⟨j, h⟩)
map_add' x i a b := by
classical
simp only
repeat (rw [domDomRestrict_aux])
simp only [MultilinearMap.map_add]
map_smul' z i c a := by
classical
simp only
repeat (rw [domDomRestrict_aux])
simp only [MultilinearMap.map_smul]
@[simp]
lemma domDomRestrict_apply (f : MultilinearMap R M₁ M₂) (P : ι → Prop)
[DecidablePred P] (x : (i : {a // P a}) → M₁ i) (z : (i : {a // ¬ P a}) → M₁ i) :
f.domDomRestrict P z x = f (fun j => if h : P j then x ⟨j, h⟩ else z ⟨j, h⟩) := rfl
-- TODO: Should add a ref here when available.
/-- The "derivative" of a multilinear map, as a linear map from `(i : ι) → M₁ i` to `M₂`.
For continuous multilinear maps, this will indeed be the derivative. -/
def linearDeriv [DecidableEq ι] [Fintype ι] (f : MultilinearMap R M₁ M₂)
(x : (i : ι) → M₁ i) : ((i : ι) → M₁ i) →ₗ[R] M₂ :=
∑ i : ι, (f.toLinearMap x i).comp (LinearMap.proj i)
@[simp]
lemma linearDeriv_apply [DecidableEq ι] [Fintype ι] (f : MultilinearMap R M₁ M₂)
(x y : (i : ι) → M₁ i) :
f.linearDeriv x y = ∑ i, f (update x i (y i)) := by
unfold linearDeriv
simp only [LinearMap.coeFn_sum, LinearMap.coe_comp, LinearMap.coe_proj, Finset.sum_apply,
Function.comp_apply, Function.eval, toLinearMap_apply]
end Semiring
end MultilinearMap
namespace LinearMap
variable [Semiring R] [∀ i, AddCommMonoid (M₁ i)] [AddCommMonoid M₂] [AddCommMonoid M₃]
[AddCommMonoid M'] [∀ i, Module R (M₁ i)] [Module R M₂] [Module R M₃] [Module R M']
/-- Composing a multilinear map with a linear map gives again a multilinear map. -/
def compMultilinearMap (g : M₂ →ₗ[R] M₃) (f : MultilinearMap R M₁ M₂) : MultilinearMap R M₁ M₃ where
toFun := g ∘ f
map_add' m i x y := by simp
map_smul' m i c x := by simp
@[simp]
theorem coe_compMultilinearMap (g : M₂ →ₗ[R] M₃) (f : MultilinearMap R M₁ M₂) :
⇑(g.compMultilinearMap f) = g ∘ f :=
rfl
@[simp]
theorem compMultilinearMap_apply (g : M₂ →ₗ[R] M₃) (f : MultilinearMap R M₁ M₂) (m : ∀ i, M₁ i) :
g.compMultilinearMap f m = g (f m) :=
rfl
/-- The multilinear version of `LinearMap.subtype_comp_codRestrict` -/
@[simp]
theorem subtype_compMultilinearMap_codRestrict (f : MultilinearMap R M₁ M₂) (p : Submodule R M₂)
(h) : p.subtype.compMultilinearMap (f.codRestrict p h) = f :=
MultilinearMap.ext fun _ => rfl
/-- The multilinear version of `LinearMap.comp_codRestrict` -/
@[simp]
theorem compMultilinearMap_codRestrict (g : M₂ →ₗ[R] M₃) (f : MultilinearMap R M₁ M₂)
(p : Submodule R M₃) (h) :
(g.codRestrict p h).compMultilinearMap f =
(g.compMultilinearMap f).codRestrict p fun v => h (f v) :=
MultilinearMap.ext fun _ => rfl
variable {ι₁ ι₂ : Type*}
@[simp]
theorem compMultilinearMap_domDomCongr (σ : ι₁ ≃ ι₂) (g : M₂ →ₗ[R] M₃)
(f : MultilinearMap R (fun _ : ι₁ => M') M₂) :
(g.compMultilinearMap f).domDomCongr σ = g.compMultilinearMap (f.domDomCongr σ) := by
ext
simp [MultilinearMap.domDomCongr]
end LinearMap
namespace MultilinearMap
section Semiring
variable [Semiring R] [(i : ι) → AddCommMonoid (M₁ i)] [(i : ι) → Module R (M₁ i)]
[AddCommMonoid M₂] [Module R M₂]
instance [Monoid S] [DistribMulAction S M₂] [Module R M₂] [SMulCommClass R S M₂] :
DistribMulAction S (MultilinearMap R M₁ M₂) :=
coe_injective.distribMulAction coeAddMonoidHom fun _ _ ↦ rfl
section Module
variable [Semiring S] [Module S M₂] [SMulCommClass R S M₂]
/-- The space of multilinear maps over an algebra over `R` is a module over `R`, for the pointwise
addition and scalar multiplication. -/
instance : Module S (MultilinearMap R M₁ M₂) :=
coe_injective.module _ coeAddMonoidHom fun _ _ ↦ rfl
instance [NoZeroSMulDivisors S M₂] : NoZeroSMulDivisors S (MultilinearMap R M₁ M₂) :=
coe_injective.noZeroSMulDivisors _ rfl coe_smul
variable (R S M₁ M₂ M₃)
section OfSubsingleton
variable [AddCommMonoid M₃] [Module S M₃] [Module R M₃] [SMulCommClass R S M₃]
/-- Linear equivalence between linear maps `M₂ →ₗ[R] M₃`
and one-multilinear maps `MultilinearMap R (fun _ : ι ↦ M₂) M₃`. -/
@[simps (config := { simpRhs := true })]
def ofSubsingletonₗ [Subsingleton ι] (i : ι) :
(M₂ →ₗ[R] M₃) ≃ₗ[S] MultilinearMap R (fun _ : ι ↦ M₂) M₃ :=
{ ofSubsingleton R M₂ M₃ i with
map_add' := fun _ _ ↦ rfl
map_smul' := fun _ _ ↦ rfl }
end OfSubsingleton
/-- The dependent version of `MultilinearMap.domDomCongrLinearEquiv`. -/
@[simps apply symm_apply]
def domDomCongrLinearEquiv' {ι' : Type*} (σ : ι ≃ ι') :
MultilinearMap R M₁ M₂ ≃ₗ[S] MultilinearMap R (fun i => M₁ (σ.symm i)) M₂ where
toFun f :=
{ toFun := f ∘ (σ.piCongrLeft' M₁).symm
map_add' := fun m i => by
letI := σ.decidableEq
rw [← σ.apply_symm_apply i]
intro x y
simp only [comp_apply, piCongrLeft'_symm_update, f.map_add]
map_smul' := fun m i c => by
letI := σ.decidableEq
rw [← σ.apply_symm_apply i]
intro x
simp only [Function.comp, piCongrLeft'_symm_update, f.map_smul] }
invFun f :=
{ toFun := f ∘ σ.piCongrLeft' M₁
map_add' := fun m i => by
letI := σ.symm.decidableEq
rw [← σ.symm_apply_apply i]
intro x y
simp only [comp_apply, piCongrLeft'_update, f.map_add]
map_smul' := fun m i c => by
letI := σ.symm.decidableEq
rw [← σ.symm_apply_apply i]
intro x
simp only [Function.comp, piCongrLeft'_update, f.map_smul] }
map_add' f₁ f₂ := by
ext
simp only [Function.comp, coe_mk, add_apply]
map_smul' c f := by
ext
simp only [Function.comp, coe_mk, smul_apply, RingHom.id_apply]
left_inv f := by
ext
simp only [coe_mk, comp_apply, Equiv.symm_apply_apply]
right_inv f := by
ext
simp only [coe_mk, comp_apply, Equiv.apply_symm_apply]
/-- The space of constant maps is equivalent to the space of maps that are multilinear with respect
to an empty family. -/
@[simps]
def constLinearEquivOfIsEmpty [IsEmpty ι] : M₂ ≃ₗ[S] MultilinearMap R M₁ M₂ where
toFun := MultilinearMap.constOfIsEmpty R _
map_add' _ _ := rfl
map_smul' _ _ := rfl
invFun f := f 0
left_inv _ := rfl
right_inv f := ext fun _ => MultilinearMap.congr_arg f <| Subsingleton.elim _ _
variable [AddCommMonoid M₃] [Module R M₃] [Module S M₃] [SMulCommClass R S M₃]
/-- `MultilinearMap.domDomCongr` as a `LinearEquiv`. -/
@[simps apply symm_apply]
def domDomCongrLinearEquiv {ι₁ ι₂} (σ : ι₁ ≃ ι₂) :
MultilinearMap R (fun _ : ι₁ => M₂) M₃ ≃ₗ[S] MultilinearMap R (fun _ : ι₂ => M₂) M₃ :=
{ (domDomCongrEquiv σ :
MultilinearMap R (fun _ : ι₁ => M₂) M₃ ≃+ MultilinearMap R (fun _ : ι₂ => M₂) M₃) with
map_smul' := fun c f => by
ext
simp [MultilinearMap.domDomCongr] }
end Module
end Semiring
section CommSemiring
variable [CommSemiring R] [∀ i, AddCommMonoid (M₁ i)] [∀ i, AddCommMonoid (M i)] [AddCommMonoid M₂]
[∀ i, Module R (M i)] [∀ i, Module R (M₁ i)] [Module R M₂] (f f' : MultilinearMap R M₁ M₂)
section
variable {M₁' : ι → Type*} [Π i, AddCommMonoid (M₁' i)] [Π i, Module R (M₁' i)]
/-- Given a predicate `P`, one may associate to a multilinear map `f` a multilinear map
from the elements satisfying `P` to the multilinear maps on elements not satisfying `P`.
In other words, splitting the variables into two subsets one gets a multilinear map into
multilinear maps.
This is a linear map version of the function `MultilinearMap.domDomRestrict`. -/
def domDomRestrictₗ (f : MultilinearMap R M₁ M₂) (P : ι → Prop) [DecidablePred P] :
MultilinearMap R (fun (i : {a : ι // ¬ P a}) => M₁ i)
(MultilinearMap R (fun (i : {a : ι // P a}) => M₁ i) M₂) where
toFun := fun z ↦ domDomRestrict f P z
map_add' := by
intro h m i x y
classical
ext v
simp [domDomRestrict_aux_right]
map_smul' := by
intro h m i c x
classical
ext v
simp [domDomRestrict_aux_right]
lemma iteratedFDeriv_aux {ι} {M₁ : ι → Type*} {α : Type*} [DecidableEq α]
(s : Set ι) [DecidableEq { x // x ∈ s }] (e : α ≃ s)
(m : α → ((i : ι) → M₁ i)) (a : α) (z : (i : ι) → M₁ i) :
(fun i ↦ update m a z (e.symm i) i) =
(fun i ↦ update (fun j ↦ m (e.symm j) j) (e a) (z (e a)) i) := by
ext i
rcases eq_or_ne a (e.symm i) with rfl | hne
· rw [Equiv.apply_symm_apply e i, update_same, update_same]
· rw [update_noteq hne.symm, update_noteq fun h ↦ (Equiv.symm_apply_apply .. ▸ h ▸ hne) rfl]
/-- One of the components of the iterated derivative of a multilinear map. Given a bijection `e`
between a type `α` (typically `Fin k`) and a subset `s` of `ι`, this component is a multilinear map
of `k` vectors `v₁, ..., vₖ`, mapping them to `f (x₁, (v_{e.symm 2})₂, x₃, ...)`, where at
indices `i` in `s` one uses the `i`-th coordinate of the vector `v_{e.symm i}` and otherwise one
uses the `i`-th coordinate of a reference vector `x`.
This is multilinear in the components of `x` outside of `s`, and in the `v_j`. -/
noncomputable def iteratedFDerivComponent {α : Type*}
(f : MultilinearMap R M₁ M₂) {s : Set ι} (e : α ≃ s) [DecidablePred (· ∈ s)] :
MultilinearMap R (fun (i : {a : ι // a ∉ s}) ↦ M₁ i)
(MultilinearMap R (fun (_ : α) ↦ (∀ i, M₁ i)) M₂) where
toFun := fun z ↦
{ toFun := fun v ↦ domDomRestrictₗ f (fun i ↦ i ∈ s) z (fun i ↦ v (e.symm i) i)
map_add' := by classical simp [iteratedFDeriv_aux]
map_smul' := by classical simp [iteratedFDeriv_aux] }
map_add' := by intros; ext; simp
map_smul' := by intros; ext; simp
open Classical in
/-- The `k`-th iterated derivative of a multilinear map `f` at the point `x`. It is a multilinear
map of `k` vectors `v₁, ..., vₖ` (with the same type as `x`), mapping them
to `∑ f (x₁, (v_{i₁})₂, x₃, ...)`, where at each index `j` one uses either `xⱼ` or one
of the `(vᵢ)ⱼ`, and each `vᵢ` has to be used exactly once.
The sum is parameterized by the embeddings of `Fin k` in the index type `ι` (or, equivalently,
by the subsets `s` of `ι` of cardinality `k` and then the bijections between `Fin k` and `s`).
For the continuous version, see `ContinuousMultilinearMap.iteratedFDeriv`. -/
protected noncomputable def iteratedFDeriv [Fintype ι]
(f : MultilinearMap R M₁ M₂) (k : ℕ) (x : (i : ι) → M₁ i) :
MultilinearMap R (fun (_ : Fin k) ↦ (∀ i, M₁ i)) M₂ :=
∑ e : Fin k ↪ ι, iteratedFDerivComponent f e.toEquivRange (fun i ↦ x i)
/-- If `f` is a collection of linear maps, then the construction `MultilinearMap.compLinearMap`
sending a multilinear map `g` to `g (f₁ ⬝ , ..., fₙ ⬝ )` is linear in `g`. -/
@[simps] def compLinearMapₗ (f : Π (i : ι), M₁ i →ₗ[R] M₁' i) :
(MultilinearMap R M₁' M₂) →ₗ[R] MultilinearMap R M₁ M₂ where
toFun := fun g ↦ g.compLinearMap f
map_add' := fun _ _ ↦ rfl
map_smul' := fun _ _ ↦ rfl
/-- If `f` is a collection of linear maps, then the construction `MultilinearMap.compLinearMap`
sending a multilinear map `g` to `g (f₁ ⬝ , ..., fₙ ⬝ )` is linear in `g` and multilinear in
`f₁, ..., fₙ`. -/
@[simps] def compLinearMapMultilinear :
@MultilinearMap R ι (fun i ↦ M₁ i →ₗ[R] M₁' i)
((MultilinearMap R M₁' M₂) →ₗ[R] MultilinearMap R M₁ M₂) _ _ _
(fun i ↦ LinearMap.module) _ where
toFun := MultilinearMap.compLinearMapₗ
map_add' := by
intro _ f i f₁ f₂
ext g x
change (g fun j ↦ update f i (f₁ + f₂) j <| x j) =
(g fun j ↦ update f i f₁ j <|x j) + g fun j ↦ update f i f₂ j (x j)
let c : Π (i : ι), (M₁ i →ₗ[R] M₁' i) → M₁' i := fun i f ↦ f (x i)
convert g.map_add (fun j ↦ f j (x j)) i (f₁ (x i)) (f₂ (x i)) with j j j
· exact Function.apply_update c f i (f₁ + f₂) j
· exact Function.apply_update c f i f₁ j
· exact Function.apply_update c f i f₂ j
map_smul' := by
intro _ f i a f₀
ext g x
change (g fun j ↦ update f i (a • f₀) j <| x j) = a • g fun j ↦ update f i f₀ j (x j)
let c : Π (i : ι), (M₁ i →ₗ[R] M₁' i) → M₁' i := fun i f ↦ f (x i)
convert g.map_smul (fun j ↦ f j (x j)) i a (f₀ (x i)) with j j j
· exact Function.apply_update c f i (a • f₀) j
· exact Function.apply_update c f i f₀ j
/--
Let `M₁ᵢ` and `M₁ᵢ'` be two families of `R`-modules and `M₂` an `R`-module.
Let us denote `Π i, M₁ᵢ` and `Π i, M₁ᵢ'` by `M` and `M'` respectively.
If `g` is a multilinear map `M' → M₂`, then `g` can be reinterpreted as a multilinear
map from `Π i, M₁ᵢ ⟶ M₁ᵢ'` to `M ⟶ M₂` via `(fᵢ) ↦ v ↦ g(fᵢ vᵢ)`.
-/
@[simps!] def piLinearMap :
MultilinearMap R M₁' M₂ →ₗ[R]
MultilinearMap R (fun i ↦ M₁ i →ₗ[R] M₁' i) (MultilinearMap R M₁ M₂) where
toFun g := (LinearMap.applyₗ g).compMultilinearMap compLinearMapMultilinear
map_add' := by aesop
map_smul' := by aesop
end
/-- If one multiplies by `c i` the coordinates in a finset `s`, then the image under a multilinear
map is multiplied by `∏ i ∈ s, c i`. This is mainly an auxiliary statement to prove the result when
`s = univ`, given in `map_smul_univ`, although it can be useful in its own right as it does not
require the index set `ι` to be finite. -/
theorem map_piecewise_smul [DecidableEq ι] (c : ι → R) (m : ∀ i, M₁ i) (s : Finset ι) :
f (s.piecewise (fun i => c i • m i) m) = (∏ i ∈ s, c i) • f m := by
refine s.induction_on (by simp) ?_
intro j s j_not_mem_s Hrec
have A :
Function.update (s.piecewise (fun i => c i • m i) m) j (m j) =
s.piecewise (fun i => c i • m i) m := by
ext i
by_cases h : i = j
· rw [h]
simp [j_not_mem_s]
· simp [h]
rw [s.piecewise_insert, f.map_smul, A, Hrec]
simp [j_not_mem_s, mul_smul]
/-- Multiplicativity of a multilinear map along all coordinates at the same time,
writing `f (fun i => c i • m i)` as `(∏ i, c i) • f m`. -/
theorem map_smul_univ [Fintype ι] (c : ι → R) (m : ∀ i, M₁ i) :
(f fun i => c i • m i) = (∏ i, c i) • f m := by
classical simpa using map_piecewise_smul f c m Finset.univ
@[simp]
theorem map_update_smul [DecidableEq ι] [Fintype ι] (m : ∀ i, M₁ i) (i : ι) (c : R) (x : M₁ i) :
f (update (c • m) i x) = c ^ (Fintype.card ι - 1) • f (update m i x) := by
have :
f ((Finset.univ.erase i).piecewise (c • update m i x) (update m i x)) =
(∏ _i ∈ Finset.univ.erase i, c) • f (update m i x) :=
map_piecewise_smul f _ _ _
simpa [← Function.update_smul c m] using this
section
variable (R ι)
variable (A : Type*) [CommSemiring A] [Algebra R A] [Fintype ι]
/-- Given an `R`-algebra `A`, `mkPiAlgebra` is the multilinear map on `A^ι` associating
to `m` the product of all the `m i`.
See also `MultilinearMap.mkPiAlgebraFin` for a version that works with a non-commutative
algebra `A` but requires `ι = Fin n`. -/
protected def mkPiAlgebra : MultilinearMap R (fun _ : ι => A) A where
toFun m := ∏ i, m i
map_add' m i x y := by simp [Finset.prod_update_of_mem, add_mul]
map_smul' m i c x := by simp [Finset.prod_update_of_mem]
variable {R A ι}
@[simp]
theorem mkPiAlgebra_apply (m : ι → A) : MultilinearMap.mkPiAlgebra R ι A m = ∏ i, m i :=
rfl
end
section
variable (R n)
variable (A : Type*) [Semiring A] [Algebra R A]
/-- Given an `R`-algebra `A`, `mkPiAlgebraFin` is the multilinear map on `A^n` associating
to `m` the product of all the `m i`.
See also `MultilinearMap.mkPiAlgebra` for a version that assumes `[CommSemiring A]` but works
for `A^ι` with any finite type `ι`. -/
protected def mkPiAlgebraFin : MultilinearMap R (fun _ : Fin n => A) A where
toFun m := (List.ofFn m).prod
map_add' {dec} m i x y := by
rw [Subsingleton.elim dec (by infer_instance)]
have : (List.finRange n).indexOf i < n := by
simpa using List.indexOf_lt_length.2 (List.mem_finRange i)
simp [List.ofFn_eq_map, (List.nodup_finRange n).map_update, List.prod_set, add_mul, this,
mul_add, add_mul]
map_smul' {dec} m i c x := by
rw [Subsingleton.elim dec (by infer_instance)]
have : (List.finRange n).indexOf i < n := by
simpa using List.indexOf_lt_length.2 (List.mem_finRange i)
simp [List.ofFn_eq_map, (List.nodup_finRange n).map_update, List.prod_set, this]
variable {R A n}
@[simp]
theorem mkPiAlgebraFin_apply (m : Fin n → A) :
MultilinearMap.mkPiAlgebraFin R n A m = (List.ofFn m).prod :=
rfl
theorem mkPiAlgebraFin_apply_const (a : A) :
(MultilinearMap.mkPiAlgebraFin R n A fun _ => a) = a ^ n := by simp
end
/-- Given an `R`-multilinear map `f` taking values in `R`, `f.smulRight z` is the map
sending `m` to `f m • z`. -/
def smulRight (f : MultilinearMap R M₁ R) (z : M₂) : MultilinearMap R M₁ M₂ :=
(LinearMap.smulRight LinearMap.id z).compMultilinearMap f
@[simp]
theorem smulRight_apply (f : MultilinearMap R M₁ R) (z : M₂) (m : ∀ i, M₁ i) :
f.smulRight z m = f m • z :=
rfl
variable (R ι)
/-- The canonical multilinear map on `R^ι` when `ι` is finite, associating to `m` the product of
all the `m i` (multiplied by a fixed reference element `z` in the target module). See also
`mkPiAlgebra` for a more general version. -/
protected def mkPiRing [Fintype ι] (z : M₂) : MultilinearMap R (fun _ : ι => R) M₂ :=
(MultilinearMap.mkPiAlgebra R ι R).smulRight z
variable {R ι}
@[simp]
theorem mkPiRing_apply [Fintype ι] (z : M₂) (m : ι → R) :
(MultilinearMap.mkPiRing R ι z : (ι → R) → M₂) m = (∏ i, m i) • z :=
rfl
theorem mkPiRing_apply_one_eq_self [Fintype ι] (f : MultilinearMap R (fun _ : ι => R) M₂) :
MultilinearMap.mkPiRing R ι (f fun _ => 1) = f := by
ext m
have : m = fun i => m i • (1 : R) := by
ext j
simp
conv_rhs => rw [this, f.map_smul_univ]
rfl
theorem mkPiRing_eq_iff [Fintype ι] {z₁ z₂ : M₂} :
MultilinearMap.mkPiRing R ι z₁ = MultilinearMap.mkPiRing R ι z₂ ↔ z₁ = z₂ := by
simp_rw [MultilinearMap.ext_iff, mkPiRing_apply]
constructor <;> intro h
· simpa using h fun _ => 1
· intro x
simp [h]
theorem mkPiRing_zero [Fintype ι] : MultilinearMap.mkPiRing R ι (0 : M₂) = 0 := by
ext; rw [mkPiRing_apply, smul_zero, MultilinearMap.zero_apply]
theorem mkPiRing_eq_zero_iff [Fintype ι] (z : M₂) : MultilinearMap.mkPiRing R ι z = 0 ↔ z = 0 := by
rw [← mkPiRing_zero, mkPiRing_eq_iff]
end CommSemiring
section RangeAddCommGroup
variable [Semiring R] [∀ i, AddCommMonoid (M₁ i)] [AddCommGroup M₂] [∀ i, Module R (M₁ i)]
[Module R M₂] (f g : MultilinearMap R M₁ M₂)
instance : Neg (MultilinearMap R M₁ M₂) :=
⟨fun f => ⟨fun m => -f m, fun m i x y => by simp [add_comm], fun m i c x => by simp⟩⟩
@[simp]
theorem neg_apply (m : ∀ i, M₁ i) : (-f) m = -f m :=
rfl
instance : Sub (MultilinearMap R M₁ M₂) :=
⟨fun f g =>
⟨fun m => f m - g m, fun m i x y => by
simp only [MultilinearMap.map_add, sub_eq_add_neg, neg_add]
abel,
fun m i c x => by simp only [MultilinearMap.map_smul, smul_sub]⟩⟩
@[simp]
theorem sub_apply (m : ∀ i, M₁ i) : (f - g) m = f m - g m :=
rfl
instance : AddCommGroup (MultilinearMap R M₁ M₂) :=
{ MultilinearMap.addCommMonoid with
add_left_neg := fun a => MultilinearMap.ext fun v => add_left_neg _
sub_eq_add_neg := fun a b => MultilinearMap.ext fun v => sub_eq_add_neg _ _
zsmul := fun n f =>
{ toFun := fun m => n • f m
map_add' := fun m i x y => by simp [smul_add]
map_smul' := fun l i x d => by simp [← smul_comm x n (_ : M₂)] }
-- Porting note: changed from `AddCommGroup` to `SubNegMonoid`
zsmul_zero' := fun a => MultilinearMap.ext fun v => SubNegMonoid.zsmul_zero' _
zsmul_succ' := fun z a => MultilinearMap.ext fun v => SubNegMonoid.zsmul_succ' _ _
zsmul_neg' := fun z a => MultilinearMap.ext fun v => SubNegMonoid.zsmul_neg' _ _ }
end RangeAddCommGroup
section AddCommGroup
variable [Semiring R] [∀ i, AddCommGroup (M₁ i)] [AddCommGroup M₂] [∀ i, Module R (M₁ i)]
[Module R M₂] (f : MultilinearMap R M₁ M₂)
@[simp]
theorem map_neg [DecidableEq ι] (m : ∀ i, M₁ i) (i : ι) (x : M₁ i) :
f (update m i (-x)) = -f (update m i x) :=
eq_neg_of_add_eq_zero_left <| by
rw [← MultilinearMap.map_add, add_left_neg, f.map_coord_zero i (update_same i 0 m)]
@[simp]
theorem map_sub [DecidableEq ι] (m : ∀ i, M₁ i) (i : ι) (x y : M₁ i) :
f (update m i (x - y)) = f (update m i x) - f (update m i y) := by
rw [sub_eq_add_neg, sub_eq_add_neg, MultilinearMap.map_add, map_neg]
lemma map_update [DecidableEq ι] (x : (i : ι) → M₁ i) (i : ι) (v : M₁ i) :
f (update x i v) = f x - f (update x i (x i - v)) := by
rw [map_sub, update_eq_self, sub_sub_cancel]
open Finset in
lemma map_sub_map_piecewise [LinearOrder ι] (a b : (i : ι) → M₁ i) (s : Finset ι) :
f a - f (s.piecewise b a) =
∑ i ∈ s, f (fun j ↦ if j ∈ s → j < i then a j else if i = j then a j - b j else b j) := by
refine s.induction_on_min ?_ fun k s hk ih ↦ ?_
· rw [Finset.piecewise_empty, sum_empty, sub_self]
rw [Finset.piecewise_insert, map_update, ← sub_add, ih,
add_comm, sum_insert (lt_irrefl _ <| hk k ·)]
simp_rw [s.mem_insert]
congr 1
· congr; ext i; split_ifs with h₁ h₂
· rw [update_noteq, Finset.piecewise_eq_of_not_mem]
· exact fun h ↦ (hk i h).not_lt (h₁ <| .inr h)
· exact fun h ↦ (h₁ <| .inl h).ne h
· cases h₂
rw [update_same, s.piecewise_eq_of_not_mem _ _ (lt_irrefl _ <| hk k ·)]
· push_neg at h₁
rw [update_noteq (Ne.symm h₂), s.piecewise_eq_of_mem _ _ (h₁.1.resolve_left <| Ne.symm h₂)]
· apply sum_congr rfl; intro i hi; congr; ext j; congr 1; apply propext
simp_rw [imp_iff_not_or, not_or]; apply or_congr_left'
intro h; rw [and_iff_right]; rintro rfl; exact h (hk i hi)
/-- This calculates the differences between the values of a multilinear map at
two arguments that differ on a finset `s` of `ι`. It requires a
linear order on `ι` in order to express the result. -/
lemma map_piecewise_sub_map_piecewise [LinearOrder ι] (a b v : (i : ι) → M₁ i) (s : Finset ι) :
f (s.piecewise a v) - f (s.piecewise b v) = ∑ i ∈ s, f
fun j ↦ if j ∈ s then if j < i then a j else if j = i then a j - b j else b j else v j := by
rw [← s.piecewise_idem_right b a, map_sub_map_piecewise]
refine Finset.sum_congr rfl fun i hi ↦ congr_arg f <| funext fun j ↦ ?_
by_cases hjs : j ∈ s
· rw [if_pos hjs]; by_cases hji : j < i
· rw [if_pos fun _ ↦ hji, if_pos hji, s.piecewise_eq_of_mem _ _ hjs]
rw [if_neg (Classical.not_imp.mpr ⟨hjs, hji⟩), if_neg hji]
obtain rfl | hij := eq_or_ne i j
· rw [if_pos rfl, if_pos rfl, s.piecewise_eq_of_mem _ _ hi]
· rw [if_neg hij, if_neg hij.symm]
· rw [if_neg hjs, if_pos fun h ↦ (hjs h).elim, s.piecewise_eq_of_not_mem _ _ hjs]
open Finset in
lemma map_add_eq_map_add_linearDeriv_add [DecidableEq ι] [Fintype ι] (x h : (i : ι) → M₁ i) :
f (x + h) = f x + f.linearDeriv x h +
∑ s ∈ univ.powerset.filter (2 ≤ ·.card), f (s.piecewise h x) := by
rw [add_comm, map_add_univ, ← Finset.powerset_univ,
← sum_filter_add_sum_filter_not _ (2 ≤ ·.card)]
simp_rw [not_le, Nat.lt_succ, le_iff_lt_or_eq (b := 1), Nat.lt_one_iff, filter_or,
← powersetCard_eq_filter, sum_union (univ.pairwise_disjoint_powersetCard zero_ne_one),
powersetCard_zero, powersetCard_one, sum_singleton, Finset.piecewise_empty, sum_map,
Function.Embedding.coeFn_mk, Finset.piecewise_singleton, linearDeriv_apply, add_comm]
open Finset in
/-- This expresses the difference between the values of a multilinear map
at two points "close to `x`" in terms of the "derivative" of the multilinear map at `x`
and of "second-order" terms. -/
lemma map_add_sub_map_add_sub_linearDeriv [DecidableEq ι] [Fintype ι] (x h h' : (i : ι) → M₁ i) :
f (x + h) - f (x + h') - f.linearDeriv x (h - h') =
∑ s ∈ univ.powerset.filter (2 ≤ ·.card), (f (s.piecewise h x) - f (s.piecewise h' x)) := by
simp_rw [map_add_eq_map_add_linearDeriv_add, add_assoc, add_sub_add_comm, sub_self, zero_add,
← LinearMap.map_sub, add_sub_cancel_left, sum_sub_distrib]
end AddCommGroup
section CommSemiring
variable [CommSemiring R] [∀ i, AddCommMonoid (M₁ i)] [AddCommMonoid M₂] [∀ i, Module R (M₁ i)]
[Module R M₂]
/-- When `ι` is finite, multilinear maps on `R^ι` with values in `M₂` are in bijection with `M₂`,
as such a multilinear map is completely determined by its value on the constant vector made of ones.
We register this bijection as a linear equivalence in `MultilinearMap.piRingEquiv`. -/
protected def piRingEquiv [Fintype ι] : M₂ ≃ₗ[R] MultilinearMap R (fun _ : ι => R) M₂ where
toFun z := MultilinearMap.mkPiRing R ι z
invFun f := f fun _ => 1
map_add' z z' := by
ext m
simp [smul_add]
map_smul' c z := by
ext m
simp [smul_smul, mul_comm]
left_inv z := by simp
right_inv f := f.mkPiRing_apply_one_eq_self
end CommSemiring
end MultilinearMap
section Currying
/-!
### Currying
We associate to a multilinear map in `n+1` variables (i.e., based on `Fin n.succ`) two
curried functions, named `f.curryLeft` (which is a linear map on `E 0` taking values
in multilinear maps in `n` variables) and `f.curryRight` (which is a multilinear map in `n`
variables taking values in linear maps on `E 0`). In both constructions, the variable that is
singled out is `0`, to take advantage of the operations `cons` and `tail` on `Fin n`.
The inverse operations are called `uncurryLeft` and `uncurryRight`.
We also register linear equiv versions of these correspondences, in
`multilinearCurryLeftEquiv` and `multilinearCurryRightEquiv`.
-/
open MultilinearMap
variable [CommSemiring R] [∀ i, AddCommMonoid (M i)] [AddCommMonoid M'] [AddCommMonoid M₂]
[∀ i, Module R (M i)] [Module R M'] [Module R M₂]
/-! #### Left currying -/
/-- Given a linear map `f` from `M 0` to multilinear maps on `n` variables,
construct the corresponding multilinear map on `n+1` variables obtained by concatenating
the variables, given by `m ↦ f (m 0) (tail m)`-/
def LinearMap.uncurryLeft (f : M 0 →ₗ[R] MultilinearMap R (fun i : Fin n => M i.succ) M₂) :
MultilinearMap R M M₂ where
toFun m := f (m 0) (tail m)
map_add' := @fun dec m i x y => by
-- Porting note: `clear` not necessary in Lean 3 due to not being in the instance cache
rw [Subsingleton.elim dec (by clear dec; infer_instance)]; clear dec
by_cases h : i = 0
· subst i
simp only [update_same, map_add, tail_update_zero, MultilinearMap.add_apply]
· simp_rw [update_noteq (Ne.symm h)]
revert x y
rw [← succ_pred i h]
intro x y
rw [tail_update_succ, MultilinearMap.map_add, tail_update_succ, tail_update_succ]
map_smul' := @fun dec m i c x => by
-- Porting note: `clear` not necessary in Lean 3 due to not being in the instance cache
rw [Subsingleton.elim dec (by clear dec; infer_instance)]; clear dec
by_cases h : i = 0
· subst i
simp only [update_same, map_smul, tail_update_zero, MultilinearMap.smul_apply]
· simp_rw [update_noteq (Ne.symm h)]
revert x
rw [← succ_pred i h]
intro x
rw [tail_update_succ, tail_update_succ, MultilinearMap.map_smul]
@[simp]
theorem LinearMap.uncurryLeft_apply (f : M 0 →ₗ[R] MultilinearMap R (fun i : Fin n => M i.succ) M₂)
(m : ∀ i, M i) : f.uncurryLeft m = f (m 0) (tail m) :=
rfl
/-- Given a multilinear map `f` in `n+1` variables, split the first variable to obtain
a linear map into multilinear maps in `n` variables, given by `x ↦ (m ↦ f (cons x m))`. -/
def MultilinearMap.curryLeft (f : MultilinearMap R M M₂) :
M 0 →ₗ[R] MultilinearMap R (fun i : Fin n => M i.succ) M₂ where
toFun x :=
{ toFun := fun m => f (cons x m)
map_add' := @fun dec m i y y' => by
-- Porting note: `clear` not necessary in Lean 3 due to not being in the instance cache
rw [Subsingleton.elim dec (by clear dec; infer_instance)]
simp
map_smul' := @fun dec m i y c => by
-- Porting note: `clear` not necessary in Lean 3 due to not being in the instance cache
rw [Subsingleton.elim dec (by clear dec; infer_instance)]
simp }
map_add' x y := by
ext m
exact cons_add f m x y
map_smul' c x := by
ext m
exact cons_smul f m c x
@[simp]
theorem MultilinearMap.curryLeft_apply (f : MultilinearMap R M M₂) (x : M 0)
(m : ∀ i : Fin n, M i.succ) : f.curryLeft x m = f (cons x m) :=
rfl
@[simp]
theorem LinearMap.curry_uncurryLeft (f : M 0 →ₗ[R] MultilinearMap R (fun i :
Fin n => M i.succ) M₂) : f.uncurryLeft.curryLeft = f := by
ext m x
simp only [tail_cons, LinearMap.uncurryLeft_apply, MultilinearMap.curryLeft_apply]
rw [cons_zero]
@[simp]
theorem MultilinearMap.uncurry_curryLeft (f : MultilinearMap R M M₂) :
f.curryLeft.uncurryLeft = f := by
ext m
simp
variable (R M M₂)
/-- The space of multilinear maps on `∀ (i : Fin (n+1)), M i` is canonically isomorphic to
the space of linear maps from `M 0` to the space of multilinear maps on
`∀ (i : Fin n), M i.succ`, by separating the first variable. We register this isomorphism as a
linear isomorphism in `multilinearCurryLeftEquiv R M M₂`.
The direct and inverse maps are given by `f.uncurryLeft` and `f.curryLeft`. Use these
unless you need the full framework of linear equivs. -/
def multilinearCurryLeftEquiv :
(M 0 →ₗ[R] MultilinearMap R (fun i : Fin n => M i.succ) M₂) ≃ₗ[R] MultilinearMap R M M₂ where
toFun := LinearMap.uncurryLeft
map_add' f₁ f₂ := by
ext m
rfl
map_smul' c f := by
ext m
rfl
invFun := MultilinearMap.curryLeft
left_inv := LinearMap.curry_uncurryLeft
right_inv := MultilinearMap.uncurry_curryLeft
variable {R M M₂}
/-! #### Right currying -/
/-- Given a multilinear map `f` in `n` variables to the space of linear maps from `M (last n)` to
`M₂`, construct the corresponding multilinear map on `n+1` variables obtained by concatenating
the variables, given by `m ↦ f (init m) (m (last n))`-/
def MultilinearMap.uncurryRight
(f : MultilinearMap R (fun i : Fin n => M (castSucc i)) (M (last n) →ₗ[R] M₂)) :
MultilinearMap R M M₂ where
toFun m := f (init m) (m (last n))
map_add' {dec} m i x y := by
-- Porting note: `clear` not necessary in Lean 3 due to not being in the instance cache
rw [Subsingleton.elim dec (by clear dec; infer_instance)]; clear dec
by_cases h : i.val < n
· have : last n ≠ i := Ne.symm (ne_of_lt h)
simp_rw [update_noteq this]
revert x y
rw [(castSucc_castLT i h).symm]
intro x y
rw [init_update_castSucc, MultilinearMap.map_add, init_update_castSucc,
init_update_castSucc, LinearMap.add_apply]
· revert x y
rw [eq_last_of_not_lt h]
intro x y
simp_rw [init_update_last, update_same, LinearMap.map_add]
map_smul' {dec} m i c x := by
-- Porting note: `clear` not necessary in Lean 3 due to not being in the instance cache
rw [Subsingleton.elim dec (by clear dec; infer_instance)]; clear dec
by_cases h : i.val < n
· have : last n ≠ i := Ne.symm (ne_of_lt h)
simp_rw [update_noteq this]
revert x
rw [(castSucc_castLT i h).symm]
intro x
rw [init_update_castSucc, init_update_castSucc, MultilinearMap.map_smul,
LinearMap.smul_apply]
· revert x
rw [eq_last_of_not_lt h]
intro x
simp_rw [update_same, init_update_last, map_smul]
@[simp]
theorem MultilinearMap.uncurryRight_apply
(f : MultilinearMap R (fun i : Fin n => M (castSucc i)) (M (last n) →ₗ[R] M₂))
(m : ∀ i, M i) : f.uncurryRight m = f (init m) (m (last n)) :=
rfl
/-- Given a multilinear map `f` in `n+1` variables, split the last variable to obtain
a multilinear map in `n` variables taking values in linear maps from `M (last n)` to `M₂`, given by
`m ↦ (x ↦ f (snoc m x))`. -/
def MultilinearMap.curryRight (f : MultilinearMap R M M₂) :
MultilinearMap R (fun i : Fin n => M (Fin.castSucc i)) (M (last n) →ₗ[R] M₂) where
toFun m :=
{ toFun := fun x => f (snoc m x)
map_add' := fun x y => by simp_rw [f.snoc_add]
map_smul' := fun c x => by simp only [f.snoc_smul, RingHom.id_apply] }
map_add' := @fun dec m i x y => by
rw [Subsingleton.elim dec (by clear dec; infer_instance)]; clear dec
ext z
change f (snoc (update m i (x + y)) z) = f (snoc (update m i x) z) + f (snoc (update m i y) z)
rw [snoc_update, snoc_update, snoc_update, f.map_add]
map_smul' := @fun dec m i c x => by
rw [Subsingleton.elim dec (by clear dec; infer_instance)]; clear dec
ext z
change f (snoc (update m i (c • x)) z) = c • f (snoc (update m i x) z)
rw [snoc_update, snoc_update, f.map_smul]
@[simp]
theorem MultilinearMap.curryRight_apply (f : MultilinearMap R M M₂)
(m : ∀ i : Fin n, M (castSucc i)) (x : M (last n)) : f.curryRight m x = f (snoc m x) :=
rfl
@[simp]
theorem MultilinearMap.curry_uncurryRight
(f : MultilinearMap R (fun i : Fin n => M (castSucc i)) (M (last n) →ₗ[R] M₂)) :
f.uncurryRight.curryRight = f := by
ext m x
simp only [snoc_last, MultilinearMap.curryRight_apply, MultilinearMap.uncurryRight_apply]
rw [init_snoc]
@[simp]
theorem MultilinearMap.uncurry_curryRight (f : MultilinearMap R M M₂) :
f.curryRight.uncurryRight = f := by
ext m
simp
variable (R M M₂)
/-- The space of multilinear maps on `∀ (i : Fin (n+1)), M i` is canonically isomorphic to
the space of linear maps from the space of multilinear maps on `∀ (i : Fin n), M (castSucc i)` to
the space of linear maps on `M (last n)`, by separating the last variable. We register this
isomorphism as a linear isomorphism in `multilinearCurryRightEquiv R M M₂`.
The direct and inverse maps are given by `f.uncurryRight` and `f.curryRight`. Use these
unless you need the full framework of linear equivs. -/
def multilinearCurryRightEquiv :
MultilinearMap R (fun i : Fin n => M (castSucc i)) (M (last n) →ₗ[R] M₂) ≃ₗ[R]
MultilinearMap R M M₂ where
toFun := MultilinearMap.uncurryRight
map_add' f₁ f₂ := by
ext m
rfl
map_smul' c f := by
ext m
rw [smul_apply]
rfl
invFun := MultilinearMap.curryRight
left_inv := MultilinearMap.curry_uncurryRight
right_inv := MultilinearMap.uncurry_curryRight
namespace MultilinearMap
variable {ι' : Type*} {R M₂}
/-- A multilinear map on `∀ i : ι ⊕ ι', M'` defines a multilinear map on `∀ i : ι, M'`
taking values in the space of multilinear maps on `∀ i : ι', M'`. -/
def currySum (f : MultilinearMap R (fun _ : ι ⊕ ι' => M') M₂) :
MultilinearMap R (fun _ : ι => M') (MultilinearMap R (fun _ : ι' => M') M₂) where
toFun u :=
{ toFun := fun v => f (Sum.elim u v)
map_add' := fun v i x y => by
letI := Classical.decEq ι
simp only [← Sum.update_elim_inr, f.map_add]
map_smul' := fun v i c x => by
letI := Classical.decEq ι
simp only [← Sum.update_elim_inr, f.map_smul] }
map_add' u i x y :=
ext fun v => by
letI := Classical.decEq ι'
simp only [MultilinearMap.coe_mk, add_apply, ← Sum.update_elim_inl, f.map_add]
map_smul' u i c x :=
ext fun v => by
letI := Classical.decEq ι'
simp only [MultilinearMap.coe_mk, smul_apply, ← Sum.update_elim_inl, f.map_smul]
@[simp]
theorem currySum_apply (f : MultilinearMap R (fun _ : ι ⊕ ι' => M') M₂) (u : ι → M')
(v : ι' → M') : f.currySum u v = f (Sum.elim u v) :=
rfl
/-- A multilinear map on `∀ i : ι, M'` taking values in the space of multilinear maps
on `∀ i : ι', M'` defines a multilinear map on `∀ i : ι ⊕ ι', M'`. -/
def uncurrySum (f : MultilinearMap R (fun _ : ι => M') (MultilinearMap R (fun _ : ι' => M') M₂)) :
MultilinearMap R (fun _ : ι ⊕ ι' => M') M₂ where
toFun u := f (u ∘ Sum.inl) (u ∘ Sum.inr)
map_add' u i x y := by
letI := (@Sum.inl_injective ι ι').decidableEq
letI := (@Sum.inr_injective ι ι').decidableEq
cases i <;>
simp only [MultilinearMap.map_add, add_apply, Sum.update_inl_comp_inl,
Sum.update_inl_comp_inr, Sum.update_inr_comp_inl, Sum.update_inr_comp_inr]
map_smul' u i c x := by
letI := (@Sum.inl_injective ι ι').decidableEq
letI := (@Sum.inr_injective ι ι').decidableEq
cases i <;>
simp only [MultilinearMap.map_smul, smul_apply, Sum.update_inl_comp_inl,
Sum.update_inl_comp_inr, Sum.update_inr_comp_inl, Sum.update_inr_comp_inr]
@[simp]
theorem uncurrySum_aux_apply
(f : MultilinearMap R (fun _ : ι => M') (MultilinearMap R (fun _ : ι' => M') M₂))
(u : ι ⊕ ι' → M') : f.uncurrySum u = f (u ∘ Sum.inl) (u ∘ Sum.inr) :=
rfl
variable (ι ι' R M₂ M')
/-- Linear equivalence between the space of multilinear maps on `∀ i : ι ⊕ ι', M'` and the space
of multilinear maps on `∀ i : ι, M'` taking values in the space of multilinear maps
on `∀ i : ι', M'`. -/
def currySumEquiv :
MultilinearMap R (fun _ : ι ⊕ ι' => M') M₂ ≃ₗ[R]
MultilinearMap R (fun _ : ι => M') (MultilinearMap R (fun _ : ι' => M') M₂) where
toFun := currySum
invFun := uncurrySum
left_inv f := ext fun u => by simp
right_inv f := by
ext
simp
map_add' f g := by
ext
rfl
map_smul' c f := by
ext
rfl
variable {ι ι' R M₂ M'}
@[simp]
theorem coe_currySumEquiv : ⇑(currySumEquiv R ι M₂ M' ι') = currySum :=
rfl
-- Porting note: fixed missing letter `y` in name
@[simp]
theorem coe_currySumEquiv_symm : ⇑(currySumEquiv R ι M₂ M' ι').symm = uncurrySum :=
rfl
variable (R M₂ M')
/-- If `s : Finset (Fin n)` is a finite set of cardinality `k` and its complement has cardinality
`l`, then the space of multilinear maps on `fun i : Fin n => M'` is isomorphic to the space of
multilinear maps on `fun i : Fin k => M'` taking values in the space of multilinear maps
on `fun i : Fin l => M'`. -/
def curryFinFinset {k l n : ℕ} {s : Finset (Fin n)} (hk : s.card = k) (hl : sᶜ.card = l) :
MultilinearMap R (fun _ : Fin n => M') M₂ ≃ₗ[R]
MultilinearMap R (fun _ : Fin k => M') (MultilinearMap R (fun _ : Fin l => M') M₂) :=
(domDomCongrLinearEquiv R R M' M₂ (finSumEquivOfFinset hk hl).symm).trans
(currySumEquiv R (Fin k) M₂ M' (Fin l))
variable {R M₂ M'}
@[simp]
theorem curryFinFinset_apply {k l n : ℕ} {s : Finset (Fin n)} (hk : s.card = k) (hl : sᶜ.card = l)
(f : MultilinearMap R (fun _ : Fin n => M') M₂) (mk : Fin k → M') (ml : Fin l → M') :
curryFinFinset R M₂ M' hk hl f mk ml =
f fun i => Sum.elim mk ml ((finSumEquivOfFinset hk hl).symm i) :=
rfl
@[simp]
theorem curryFinFinset_symm_apply {k l n : ℕ} {s : Finset (Fin n)} (hk : s.card = k)
(hl : sᶜ.card = l)
(f : MultilinearMap R (fun _ : Fin k => M') (MultilinearMap R (fun _ : Fin l => M') M₂))
(m : Fin n → M') :
(curryFinFinset R M₂ M' hk hl).symm f m =
f (fun i => m <| finSumEquivOfFinset hk hl (Sum.inl i)) fun i =>
m <| finSumEquivOfFinset hk hl (Sum.inr i) :=
rfl
-- @[simp] -- Porting note: simpNF linter, lhs simplifies, added aux version below
theorem curryFinFinset_symm_apply_piecewise_const {k l n : ℕ} {s : Finset (Fin n)} (hk : s.card = k)
(hl : sᶜ.card = l)
(f : MultilinearMap R (fun _ : Fin k => M') (MultilinearMap R (fun _ : Fin l => M') M₂))
(x y : M') :
(curryFinFinset R M₂ M' hk hl).symm f (s.piecewise (fun _ => x) fun _ => y) =
f (fun _ => x) fun _ => y := by
rw [curryFinFinset_symm_apply]; congr
· ext
rw [finSumEquivOfFinset_inl, Finset.piecewise_eq_of_mem]
apply Finset.orderEmbOfFin_mem
· ext
rw [finSumEquivOfFinset_inr, Finset.piecewise_eq_of_not_mem]
exact Finset.mem_compl.1 (Finset.orderEmbOfFin_mem _ _ _)
@[simp]
theorem curryFinFinset_symm_apply_piecewise_const_aux {k l n : ℕ} {s : Finset (Fin n)}
(hk : s.card = k) (hl : sᶜ.card = l)
(f : MultilinearMap R (fun _ : Fin k => M') (MultilinearMap R (fun _ : Fin l => M') M₂))
(x y : M') :
((⇑f fun _ => x) (fun i => (Finset.piecewise s (fun _ => x) (fun _ => y)
((sᶜ.orderEmbOfFin hl) i))) = f (fun _ => x) fun _ => y) := by
have := curryFinFinset_symm_apply_piecewise_const hk hl f x y
simp only [curryFinFinset_symm_apply, finSumEquivOfFinset_inl, Finset.orderEmbOfFin_mem,
Finset.piecewise_eq_of_mem, finSumEquivOfFinset_inr] at this
exact this
@[simp]
theorem curryFinFinset_symm_apply_const {k l n : ℕ} {s : Finset (Fin n)} (hk : s.card = k)
(hl : sᶜ.card = l)
(f : MultilinearMap R (fun _ : Fin k => M') (MultilinearMap R (fun _ : Fin l => M') M₂))
(x : M') : ((curryFinFinset R M₂ M' hk hl).symm f fun _ => x) = f (fun _ => x) fun _ => x :=
rfl
-- @[simp] -- Porting note: simpNF, lhs simplifies, added aux version below
theorem curryFinFinset_apply_const {k l n : ℕ} {s : Finset (Fin n)} (hk : s.card = k)
(hl : sᶜ.card = l) (f : MultilinearMap R (fun _ : Fin n => M') M₂) (x y : M') :
(curryFinFinset R M₂ M' hk hl f (fun _ => x) fun _ => y) =
f (s.piecewise (fun _ => x) fun _ => y) := by
refine (curryFinFinset_symm_apply_piecewise_const hk hl _ _ _).symm.trans ?_
-- `rw` fails
rw [LinearEquiv.symm_apply_apply]
@[simp]
theorem curryFinFinset_apply_const_aux {k l n : ℕ} {s : Finset (Fin n)} (hk : s.card = k)
(hl : sᶜ.card = l) (f : MultilinearMap R (fun _ : Fin n => M') M₂) (x y : M') :
(f fun i => Sum.elim (fun _ => x) (fun _ => y) ((⇑ (Equiv.symm (finSumEquivOfFinset hk hl))) i))
= f (s.piecewise (fun _ => x) fun _ => y) := by
rw [← curryFinFinset_apply]
apply curryFinFinset_apply_const
end MultilinearMap
end Currying
namespace MultilinearMap
section Submodule
variable [Ring R] [∀ i, AddCommMonoid (M₁ i)] [AddCommMonoid M'] [AddCommMonoid M₂]
[∀ i, Module R (M₁ i)] [Module R M'] [Module R M₂]
/-- The pushforward of an indexed collection of submodule `p i ⊆ M₁ i` by `f : M₁ → M₂`.
Note that this is not a submodule - it is not closed under addition. -/
def map [Nonempty ι] (f : MultilinearMap R M₁ M₂) (p : ∀ i, Submodule R (M₁ i)) :
SubMulAction R M₂ where
carrier := f '' { v | ∀ i, v i ∈ p i }
smul_mem' := fun c _ ⟨x, hx, hf⟩ => by
let ⟨i⟩ := ‹Nonempty ι›
letI := Classical.decEq ι
refine ⟨update x i (c • x i), fun j => if hij : j = i then ?_ else ?_, hf ▸ ?_⟩
· rw [hij, update_same]
exact (p i).smul_mem _ (hx i)
· rw [update_noteq hij]
exact hx j
· rw [f.map_smul, update_eq_self]
/-- The map is always nonempty. This lemma is needed to apply `SubMulAction.zero_mem`. -/
theorem map_nonempty [Nonempty ι] (f : MultilinearMap R M₁ M₂) (p : ∀ i, Submodule R (M₁ i)) :
(map f p : Set M₂).Nonempty :=
⟨f 0, 0, fun i => (p i).zero_mem, rfl⟩
/-- The range of a multilinear map, closed under scalar multiplication. -/
def range [Nonempty ι] (f : MultilinearMap R M₁ M₂) : SubMulAction R M₂ :=
f.map fun _ => ⊤
end Submodule
end MultilinearMap
|
LinearAlgebra\Multilinear\Basis.lean | /-
Copyright (c) 2021 Joseph Myers. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Joseph Myers
-/
import Mathlib.LinearAlgebra.Basis
import Mathlib.LinearAlgebra.Multilinear.Basic
/-!
# Multilinear maps in relation to bases.
This file proves lemmas about the action of multilinear maps on basis vectors.
## TODO
* Refactor the proofs in terms of bases of tensor products, once there is an equivalent of
`Basis.tensorProduct` for `PiTensorProduct`.
-/
open MultilinearMap
variable {R : Type*} {ι : Type*} {n : ℕ} {M : Fin n → Type*} {M₂ : Type*} {M₃ : Type*}
variable [CommSemiring R] [AddCommMonoid M₂] [AddCommMonoid M₃] [∀ i, AddCommMonoid (M i)]
variable [∀ i, Module R (M i)] [Module R M₂] [Module R M₃]
/-- Two multilinear maps indexed by `Fin n` are equal if they are equal when all arguments are
basis vectors. -/
theorem Basis.ext_multilinear_fin {f g : MultilinearMap R M M₂} {ι₁ : Fin n → Type*}
(e : ∀ i, Basis (ι₁ i) R (M i))
(h : ∀ v : ∀ i, ι₁ i, (f fun i => e i (v i)) = g fun i => e i (v i)) : f = g := by
induction' n with m hm
· ext x
convert h finZeroElim
· apply Function.LeftInverse.injective uncurry_curryLeft
refine Basis.ext (e 0) ?_
intro i
apply hm (Fin.tail e)
intro j
convert h (Fin.cons i j)
iterate 2
rw [curryLeft_apply]
congr 1 with x
refine Fin.cases rfl (fun x => ?_) x
dsimp [Fin.tail]
rw [Fin.cons_succ, Fin.cons_succ]
/-- Two multilinear maps indexed by a `Fintype` are equal if they are equal when all arguments
are basis vectors. Unlike `Basis.ext_multilinear_fin`, this only uses a single basis; a
dependently-typed version would still be true, but the proof would need a dependently-typed
version of `dom_dom_congr`. -/
theorem Basis.ext_multilinear [Finite ι] {f g : MultilinearMap R (fun _ : ι => M₂) M₃} {ι₁ : Type*}
(e : Basis ι₁ R M₂) (h : ∀ v : ι → ι₁, (f fun i => e (v i)) = g fun i => e (v i)) : f = g := by
cases nonempty_fintype ι
exact
(domDomCongr_eq_iff (Fintype.equivFin ι) f g).mp
(Basis.ext_multilinear_fin (fun _ => e) fun i => h (i ∘ _))
|
LinearAlgebra\Multilinear\FiniteDimensional.lean | /-
Copyright (c) 2022 Oliver Nash. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Oliver Nash
-/
import Mathlib.LinearAlgebra.Multilinear.Basic
import Mathlib.LinearAlgebra.FreeModule.Finite.Matrix
/-! # Multilinear maps over finite dimensional spaces
The main results are that multilinear maps over finitely-generated, free modules are
finitely-generated and free.
* `Module.Finite.multilinearMap`
* `Module.Free.multilinearMap`
We do not put this in `LinearAlgebra.Multilinear.Basic` to avoid making the imports too large
there.
-/
namespace MultilinearMap
variable {ι R M₂ : Type*} {M₁ : ι → Type*}
variable [Finite ι]
variable [CommRing R] [AddCommGroup M₂] [Module R M₂]
variable [Module.Finite R M₂] [Module.Free R M₂]
-- Porting note: split out from `free_and_finite` because of inscrutable typeclass errors
private theorem free_and_finite_fin (n : ℕ) (N : Fin n → Type*) [∀ i, AddCommGroup (N i)]
[∀ i, Module R (N i)] [∀ i, Module.Finite R (N i)] [∀ i, Module.Free R (N i)] :
Module.Free R (MultilinearMap R N M₂) ∧ Module.Finite R (MultilinearMap R N M₂) := by
induction' n with n ih
· haveI : IsEmpty (Fin Nat.zero) := inferInstanceAs (IsEmpty (Fin 0))
exact
⟨Module.Free.of_equiv (constLinearEquivOfIsEmpty R R N M₂),
Module.Finite.equiv (constLinearEquivOfIsEmpty R R N M₂)⟩
· suffices
Module.Free R (N 0 →ₗ[R] MultilinearMap R (fun i : Fin n => N i.succ) M₂) ∧
Module.Finite R (N 0 →ₗ[R] MultilinearMap R (fun i : Fin n => N i.succ) M₂) by
cases this
exact
⟨Module.Free.of_equiv (multilinearCurryLeftEquiv R N M₂),
Module.Finite.equiv (multilinearCurryLeftEquiv R N M₂)⟩
cases ih fun i => N i.succ
exact ⟨Module.Free.linearMap _ _ _ _, Module.Finite.linearMap _ _ _ _⟩
variable [∀ i, AddCommGroup (M₁ i)] [∀ i, Module R (M₁ i)]
variable [∀ i, Module.Finite R (M₁ i)] [∀ i, Module.Free R (M₁ i)]
-- the induction requires us to show both at once
private theorem free_and_finite :
Module.Free R (MultilinearMap R M₁ M₂) ∧ Module.Finite R (MultilinearMap R M₁ M₂) := by
cases nonempty_fintype ι
have := @free_and_finite_fin R M₂ _ _ _ _ _ (Fintype.card ι)
(fun x => M₁ ((Fintype.equivFin ι).symm x))
cases' this with l r
have e := domDomCongrLinearEquiv' R R M₁ M₂ (Fintype.equivFin ι)
exact ⟨Module.Free.of_equiv e.symm, Module.Finite.equiv e.symm⟩
instance _root_.Module.Finite.multilinearMap : Module.Finite R (MultilinearMap R M₁ M₂) :=
free_and_finite.2
instance _root_.Module.Free.multilinearMap : Module.Free R (MultilinearMap R M₁ M₂) :=
free_and_finite.1
end MultilinearMap
|
LinearAlgebra\Multilinear\TensorProduct.lean | /-
Copyright (c) 2020 Eric Wieser. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Eric Wieser
-/
import Mathlib.LinearAlgebra.Multilinear.Basic
import Mathlib.LinearAlgebra.TensorProduct.Basic
/-!
# Constructions relating multilinear maps and tensor products.
-/
suppress_compilation
namespace MultilinearMap
section DomCoprod
open TensorProduct
variable {R ι₁ ι₂ ι₃ ι₄ : Type*}
variable [CommSemiring R]
variable {N₁ : Type*} [AddCommMonoid N₁] [Module R N₁]
variable {N₂ : Type*} [AddCommMonoid N₂] [Module R N₂]
variable {N : Type*} [AddCommMonoid N] [Module R N]
/-- Given two multilinear maps `(ι₁ → N) → N₁` and `(ι₂ → N) → N₂`, this produces the map
`(ι₁ ⊕ ι₂ → N) → N₁ ⊗ N₂` by taking the coproduct of the domain and the tensor product
of the codomain.
This can be thought of as combining `Equiv.sumArrowEquivProdArrow.symm` with
`TensorProduct.map`, noting that the two operations can't be separated as the intermediate result
is not a `MultilinearMap`.
While this can be generalized to work for dependent `Π i : ι₁, N'₁ i` instead of `ι₁ → N`, doing so
introduces `Sum.elim N'₁ N'₂` types in the result which are difficult to work with and not defeq
to the simple case defined here. See [this zulip thread](
https://leanprover.zulipchat.com/#narrow/stream/217875-Is-there.20code.20for.20X.3F/topic/Instances.20on.20.60sum.2Eelim.20A.20B.20i.60/near/218484619).
-/
@[simps apply]
def domCoprod (a : MultilinearMap R (fun _ : ι₁ => N) N₁)
(b : MultilinearMap R (fun _ : ι₂ => N) N₂) :
MultilinearMap R (fun _ : ι₁ ⊕ ι₂ => N) (N₁ ⊗[R] N₂) where
toFun v := (a fun i => v (Sum.inl i)) ⊗ₜ b fun i => v (Sum.inr i)
map_add' _ i p q := by
letI := (@Sum.inl_injective ι₁ ι₂).decidableEq
letI := (@Sum.inr_injective ι₁ ι₂).decidableEq
cases i <;> simp [TensorProduct.add_tmul, TensorProduct.tmul_add]
map_smul' _ i c p := by
letI := (@Sum.inl_injective ι₁ ι₂).decidableEq
letI := (@Sum.inr_injective ι₁ ι₂).decidableEq
cases i <;> simp [TensorProduct.smul_tmul', TensorProduct.tmul_smul]
/-- A more bundled version of `MultilinearMap.domCoprod` that maps
`((ι₁ → N) → N₁) ⊗ ((ι₂ → N) → N₂)` to `(ι₁ ⊕ ι₂ → N) → N₁ ⊗ N₂`. -/
def domCoprod' :
MultilinearMap R (fun _ : ι₁ => N) N₁ ⊗[R] MultilinearMap R (fun _ : ι₂ => N) N₂ →ₗ[R]
MultilinearMap R (fun _ : ι₁ ⊕ ι₂ => N) (N₁ ⊗[R] N₂) :=
TensorProduct.lift <|
LinearMap.mk₂ R domCoprod
(fun m₁ m₂ n => by
ext
simp only [domCoprod_apply, TensorProduct.add_tmul, add_apply])
(fun c m n => by
ext
simp only [domCoprod_apply, TensorProduct.smul_tmul', smul_apply])
(fun m n₁ n₂ => by
ext
simp only [domCoprod_apply, TensorProduct.tmul_add, add_apply])
fun c m n => by
ext
simp only [domCoprod_apply, TensorProduct.tmul_smul, smul_apply]
@[simp]
theorem domCoprod'_apply (a : MultilinearMap R (fun _ : ι₁ => N) N₁)
(b : MultilinearMap R (fun _ : ι₂ => N) N₂) : domCoprod' (a ⊗ₜ[R] b) = domCoprod a b :=
rfl
/-- When passed an `Equiv.sumCongr`, `MultilinearMap.domDomCongr` distributes over
`MultilinearMap.domCoprod`. -/
theorem domCoprod_domDomCongr_sumCongr (a : MultilinearMap R (fun _ : ι₁ => N) N₁)
(b : MultilinearMap R (fun _ : ι₂ => N) N₂) (σa : ι₁ ≃ ι₃) (σb : ι₂ ≃ ι₄) :
(a.domCoprod b).domDomCongr (σa.sumCongr σb) =
(a.domDomCongr σa).domCoprod (b.domDomCongr σb) :=
rfl
end DomCoprod
end MultilinearMap
|
LinearAlgebra\Projectivization\Basic.lean | /-
Copyright (c) 2022 Adam Topaz. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Adam Topaz
-/
import Mathlib.LinearAlgebra.Dimension.FreeAndStrongRankCondition
import Mathlib.LinearAlgebra.FiniteDimensional.Defs
/-!
# Projective Spaces
This file contains the definition of the projectivization of a vector space over a field,
as well as the bijection between said projectivization and the collection of all one
dimensional subspaces of the vector space.
## Notation
`ℙ K V` is localized notation for `Projectivization K V`, the projectivization of a `K`-vector
space `V`.
## Constructing terms of `ℙ K V`.
We have three ways to construct terms of `ℙ K V`:
- `Projectivization.mk K v hv` where `v : V` and `hv : v ≠ 0`.
- `Projectivization.mk' K v` where `v : { w : V // w ≠ 0 }`.
- `Projectivization.mk'' H h` where `H : Submodule K V` and `h : finrank H = 1`.
## Other definitions
- For `v : ℙ K V`, `v.submodule` gives the corresponding submodule of `V`.
- `Projectivization.equivSubmodule` is the equivalence between `ℙ K V`
and `{ H : Submodule K V // finrank H = 1 }`.
- For `v : ℙ K V`, `v.rep : V` is a representative of `v`.
-/
variable (K V : Type*) [DivisionRing K] [AddCommGroup V] [Module K V]
/-- The setoid whose quotient is the projectivization of `V`. -/
def projectivizationSetoid : Setoid { v : V // v ≠ 0 } :=
(MulAction.orbitRel Kˣ V).comap (↑)
/-- The projectivization of the `K`-vector space `V`.
The notation `ℙ K V` is preferred. -/
def Projectivization := Quotient (projectivizationSetoid K V)
/-- We define notations `ℙ K V` for the projectivization of the `K`-vector space `V`. -/
scoped[LinearAlgebra.Projectivization] notation "ℙ" => Projectivization
namespace Projectivization
open scoped LinearAlgebra.Projectivization
variable {V}
/-- Construct an element of the projectivization from a nonzero vector. -/
def mk (v : V) (hv : v ≠ 0) : ℙ K V :=
Quotient.mk'' ⟨v, hv⟩
/-- A variant of `Projectivization.mk` in terms of a subtype. `mk` is preferred. -/
def mk' (v : { v : V // v ≠ 0 }) : ℙ K V :=
Quotient.mk'' v
@[simp]
theorem mk'_eq_mk (v : { v : V // v ≠ 0 }) : mk' K v = mk K ↑v v.2 := rfl
instance [Nontrivial V] : Nonempty (ℙ K V) :=
let ⟨v, hv⟩ := exists_ne (0 : V)
⟨mk K v hv⟩
variable {K}
/-- Choose a representative of `v : Projectivization K V` in `V`. -/
protected noncomputable def rep (v : ℙ K V) : V :=
v.out'
theorem rep_nonzero (v : ℙ K V) : v.rep ≠ 0 :=
v.out'.2
@[simp]
theorem mk_rep (v : ℙ K V) : mk K v.rep v.rep_nonzero = v := Quotient.out_eq' _
open FiniteDimensional
/-- Consider an element of the projectivization as a submodule of `V`. -/
protected def submodule (v : ℙ K V) : Submodule K V :=
(Quotient.liftOn' v fun v => K ∙ (v : V)) <| by
rintro ⟨a, ha⟩ ⟨b, hb⟩ ⟨x, rfl : x • b = a⟩
exact Submodule.span_singleton_group_smul_eq _ x _
variable (K)
theorem mk_eq_mk_iff (v w : V) (hv : v ≠ 0) (hw : w ≠ 0) :
mk K v hv = mk K w hw ↔ ∃ a : Kˣ, a • w = v :=
Quotient.eq''
/-- Two nonzero vectors go to the same point in projective space if and only if one is
a scalar multiple of the other. -/
theorem mk_eq_mk_iff' (v w : V) (hv : v ≠ 0) (hw : w ≠ 0) :
mk K v hv = mk K w hw ↔ ∃ a : K, a • w = v := by
rw [mk_eq_mk_iff K v w hv hw]
constructor
· rintro ⟨a, ha⟩
exact ⟨a, ha⟩
· rintro ⟨a, ha⟩
refine ⟨Units.mk0 a fun c => hv.symm ?_, ha⟩
rwa [c, zero_smul] at ha
theorem exists_smul_eq_mk_rep (v : V) (hv : v ≠ 0) : ∃ a : Kˣ, a • v = (mk K v hv).rep :=
(mk_eq_mk_iff K _ _ (rep_nonzero _) hv).1 (mk_rep _)
variable {K}
/-- An induction principle for `Projectivization`. Use as `induction v`. -/
@[elab_as_elim, cases_eliminator, induction_eliminator]
theorem ind {P : ℙ K V → Prop} (h : ∀ (v : V) (h : v ≠ 0), P (mk K v h)) : ∀ p, P p :=
Quotient.ind' <| Subtype.rec <| h
@[simp]
theorem submodule_mk (v : V) (hv : v ≠ 0) : (mk K v hv).submodule = K ∙ v :=
rfl
theorem submodule_eq (v : ℙ K V) : v.submodule = K ∙ v.rep := by
conv_lhs => rw [← v.mk_rep]
rfl
theorem finrank_submodule (v : ℙ K V) : finrank K v.submodule = 1 := by
rw [submodule_eq]
exact finrank_span_singleton v.rep_nonzero
instance (v : ℙ K V) : FiniteDimensional K v.submodule := by
rw [← v.mk_rep]
change FiniteDimensional K (K ∙ v.rep)
infer_instance
theorem submodule_injective :
Function.Injective (Projectivization.submodule : ℙ K V → Submodule K V) := fun u v h ↦ by
induction' u using ind with u hu
induction' v using ind with v hv
rw [submodule_mk, submodule_mk, Submodule.span_singleton_eq_span_singleton] at h
exact ((mk_eq_mk_iff K v u hv hu).2 h).symm
variable (K V)
/-- The equivalence between the projectivization and the
collection of subspaces of dimension 1. -/
noncomputable def equivSubmodule : ℙ K V ≃ { H : Submodule K V // finrank K H = 1 } :=
(Equiv.ofInjective _ submodule_injective).trans <| .subtypeEquiv (.refl _) fun H ↦ by
refine ⟨fun ⟨v, hv⟩ ↦ hv ▸ v.finrank_submodule, fun h ↦ ?_⟩
rcases finrank_eq_one_iff'.1 h with ⟨v : H, hv₀, hv : ∀ w : H, _⟩
use mk K (v : V) (Subtype.coe_injective.ne hv₀)
rw [submodule_mk, SetLike.ext'_iff, Submodule.span_singleton_eq_range]
refine (Set.range_subset_iff.2 fun _ ↦ H.smul_mem _ v.2).antisymm fun x hx ↦ ?_
rcases hv ⟨x, hx⟩ with ⟨c, hc⟩
exact ⟨c, congr_arg Subtype.val hc⟩
variable {K V}
/-- Construct an element of the projectivization from a subspace of dimension 1. -/
noncomputable def mk'' (H : Submodule K V) (h : finrank K H = 1) : ℙ K V :=
(equivSubmodule K V).symm ⟨H, h⟩
@[simp]
theorem submodule_mk'' (H : Submodule K V) (h : finrank K H = 1) : (mk'' H h).submodule = H :=
congr_arg Subtype.val <| (equivSubmodule K V).apply_symm_apply ⟨H, h⟩
@[simp]
theorem mk''_submodule (v : ℙ K V) : mk'' v.submodule v.finrank_submodule = v :=
(equivSubmodule K V).symm_apply_apply v
section Map
variable {L W : Type*} [DivisionRing L] [AddCommGroup W] [Module L W]
/-- An injective semilinear map of vector spaces induces a map on projective spaces. -/
def map {σ : K →+* L} (f : V →ₛₗ[σ] W) (hf : Function.Injective f) : ℙ K V → ℙ L W :=
Quotient.map' (fun v => ⟨f v, fun c => v.2 (hf (by simp [c]))⟩)
(by
rintro ⟨u, hu⟩ ⟨v, hv⟩ ⟨a, ha⟩
use Units.map σ.toMonoidHom a
dsimp at ha ⊢
erw [← f.map_smulₛₗ, ha])
theorem map_mk {σ : K →+* L} (f : V →ₛₗ[σ] W) (hf : Function.Injective f) (v : V) (hv : v ≠ 0) :
map f hf (mk K v hv) = mk L (f v) (map_zero f ▸ hf.ne hv) :=
rfl
/-- Mapping with respect to a semilinear map over an isomorphism of fields yields
an injective map on projective spaces. -/
theorem map_injective {σ : K →+* L} {τ : L →+* K} [RingHomInvPair σ τ] (f : V →ₛₗ[σ] W)
(hf : Function.Injective f) : Function.Injective (map f hf) := fun u v h ↦ by
induction' u using ind with u hu; induction' v using ind with v hv
simp only [map_mk, mk_eq_mk_iff'] at h ⊢
rcases h with ⟨a, ha⟩
refine ⟨τ a, hf ?_⟩
rwa [f.map_smulₛₗ, RingHomInvPair.comp_apply_eq₂]
@[simp]
theorem map_id : map (LinearMap.id : V →ₗ[K] V) (LinearEquiv.refl K V).injective = id := by
ext ⟨v⟩
rfl
-- Porting note: removed `@[simp]` because of unusable `hg.comp hf` in the LHS
theorem map_comp {F U : Type*} [Field F] [AddCommGroup U] [Module F U] {σ : K →+* L} {τ : L →+* F}
{γ : K →+* F} [RingHomCompTriple σ τ γ] (f : V →ₛₗ[σ] W) (hf : Function.Injective f)
(g : W →ₛₗ[τ] U) (hg : Function.Injective g) :
map (g.comp f) (hg.comp hf) = map g hg ∘ map f hf := by
ext ⟨v⟩
rfl
end Map
end Projectivization
|
LinearAlgebra\Projectivization\Independence.lean | /-
Copyright (c) 2022 Michael Blyth. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Michael Blyth
-/
import Mathlib.LinearAlgebra.Projectivization.Basic
/-!
# Independence in Projective Space
In this file we define independence and dependence of families of elements in projective space.
## Implementation Details
We use an inductive definition to define the independence of points in projective
space, where the only constructor assumes an independent family of vectors from the
ambient vector space. Similarly for the definition of dependence.
## Results
- A family of elements is dependent if and only if it is not independent.
- Two elements are dependent if and only if they are equal.
# Future Work
- Define collinearity in projective space.
- Prove the axioms of a projective geometry are satisfied by the dependence relation.
- Define projective linear subspaces.
-/
open scoped LinearAlgebra.Projectivization
variable {ι K V : Type*} [DivisionRing K] [AddCommGroup V] [Module K V] {f : ι → ℙ K V}
namespace Projectivization
/-- A linearly independent family of nonzero vectors gives an independent family of points
in projective space. -/
inductive Independent : (ι → ℙ K V) → Prop
| mk (f : ι → V) (hf : ∀ i : ι, f i ≠ 0) (hl : LinearIndependent K f) :
Independent fun i => mk K (f i) (hf i)
/-- A family of points in a projective space is independent if and only if the representative
vectors determined by the family are linearly independent. -/
theorem independent_iff : Independent f ↔ LinearIndependent K (Projectivization.rep ∘ f) := by
refine ⟨?_, fun h => ?_⟩
· rintro ⟨ff, hff, hh⟩
choose a ha using fun i : ι => exists_smul_eq_mk_rep K (ff i) (hff i)
convert hh.units_smul a
ext i
exact (ha i).symm
· convert Independent.mk _ _ h
· simp only [mk_rep, Function.comp_apply]
· intro i
apply rep_nonzero
/-- A family of points in projective space is independent if and only if the family of
submodules which the points determine is independent in the lattice-theoretic sense. -/
theorem independent_iff_completeLattice_independent :
Independent f ↔ CompleteLattice.Independent fun i => (f i).submodule := by
refine ⟨?_, fun h => ?_⟩
· rintro ⟨f, hf, hi⟩
simp only [submodule_mk]
exact (CompleteLattice.independent_iff_linearIndependent_of_ne_zero (R := K) hf).mpr hi
· rw [independent_iff]
refine h.linearIndependent (Projectivization.submodule ∘ f) (fun i => ?_) fun i => ?_
· simpa only [Function.comp_apply, submodule_eq] using Submodule.mem_span_singleton_self _
· exact rep_nonzero (f i)
/-- A linearly dependent family of nonzero vectors gives a dependent family of points
in projective space. -/
inductive Dependent : (ι → ℙ K V) → Prop
| mk (f : ι → V) (hf : ∀ i : ι, f i ≠ 0) (h : ¬LinearIndependent K f) :
Dependent fun i => mk K (f i) (hf i)
/-- A family of points in a projective space is dependent if and only if their
representatives are linearly dependent. -/
theorem dependent_iff : Dependent f ↔ ¬LinearIndependent K (Projectivization.rep ∘ f) := by
refine ⟨?_, fun h => ?_⟩
· rintro ⟨ff, hff, hh1⟩
contrapose! hh1
choose a ha using fun i : ι => exists_smul_eq_mk_rep K (ff i) (hff i)
convert hh1.units_smul a⁻¹
ext i
simp only [← ha, inv_smul_smul, Pi.smul_apply', Pi.inv_apply, Function.comp_apply]
· convert Dependent.mk _ _ h
· simp only [mk_rep, Function.comp_apply]
· exact fun i => rep_nonzero (f i)
/-- Dependence is the negation of independence. -/
theorem dependent_iff_not_independent : Dependent f ↔ ¬Independent f := by
rw [dependent_iff, independent_iff]
/-- Independence is the negation of dependence. -/
theorem independent_iff_not_dependent : Independent f ↔ ¬Dependent f := by
rw [dependent_iff_not_independent, Classical.not_not]
/-- Two points in a projective space are dependent if and only if they are equal. -/
@[simp]
theorem dependent_pair_iff_eq (u v : ℙ K V) : Dependent ![u, v] ↔ u = v := by
rw [dependent_iff_not_independent, independent_iff, linearIndependent_fin2,
Function.comp_apply, Matrix.cons_val_one, Matrix.head_cons, Ne]
simp only [Matrix.cons_val_zero, not_and, not_forall, Classical.not_not, Function.comp_apply,
← mk_eq_mk_iff' K _ _ (rep_nonzero u) (rep_nonzero v), mk_rep, Classical.imp_iff_right_iff]
exact Or.inl (rep_nonzero v)
/-- Two points in a projective space are independent if and only if the points are not equal. -/
@[simp]
theorem independent_pair_iff_neq (u v : ℙ K V) : Independent ![u, v] ↔ u ≠ v := by
rw [independent_iff_not_dependent, dependent_pair_iff_eq u v]
end Projectivization
|
LinearAlgebra\Projectivization\Subspace.lean | /-
Copyright (c) 2022 Michael Blyth. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Michael Blyth
-/
import Mathlib.LinearAlgebra.Projectivization.Basic
/-!
# Subspaces of Projective Space
In this file we define subspaces of a projective space, and show that the subspaces of a projective
space form a complete lattice under inclusion.
## Implementation Details
A subspace of a projective space ℙ K V is defined to be a structure consisting of a subset of
ℙ K V such that if two nonzero vectors in V determine points in ℙ K V which are in the subset, and
the sum of the two vectors is nonzero, then the point determined by the sum of the two vectors is
also in the subset.
## Results
- There is a Galois insertion between the subsets of points of a projective space
and the subspaces of the projective space, which is given by taking the span of the set of points.
- The subspaces of a projective space form a complete lattice under inclusion.
# Future Work
- Show that there is a one-to-one order-preserving correspondence between subspaces of a
projective space and the submodules of the underlying vector space.
-/
variable (K V : Type*) [Field K] [AddCommGroup V] [Module K V]
namespace Projectivization
open scoped LinearAlgebra.Projectivization
/-- A subspace of a projective space is a structure consisting of a set of points such that:
If two nonzero vectors determine points which are in the set, and the sum of the two vectors is
nonzero, then the point determined by the sum is also in the set. -/
@[ext]
structure Subspace where
/-- The set of points. -/
carrier : Set (ℙ K V)
/-- The addition rule. -/
mem_add' (v w : V) (hv : v ≠ 0) (hw : w ≠ 0) (hvw : v + w ≠ 0) :
mk K v hv ∈ carrier → mk K w hw ∈ carrier → mk K (v + w) hvw ∈ carrier
namespace Subspace
variable {K V}
instance : SetLike (Subspace K V) (ℙ K V) where
coe := carrier
coe_injective' A B := by
cases A
cases B
simp
@[simp]
theorem mem_carrier_iff (A : Subspace K V) (x : ℙ K V) : x ∈ A.carrier ↔ x ∈ A :=
Iff.refl _
theorem mem_add (T : Subspace K V) (v w : V) (hv : v ≠ 0) (hw : w ≠ 0) (hvw : v + w ≠ 0) :
Projectivization.mk K v hv ∈ T →
Projectivization.mk K w hw ∈ T → Projectivization.mk K (v + w) hvw ∈ T :=
T.mem_add' v w hv hw hvw
/-- The span of a set of points in a projective space is defined inductively to be the set of points
which contains the original set, and contains all points determined by the (nonzero) sum of two
nonzero vectors, each of which determine points in the span. -/
inductive spanCarrier (S : Set (ℙ K V)) : Set (ℙ K V)
| of (x : ℙ K V) (hx : x ∈ S) : spanCarrier S x
| mem_add (v w : V) (hv : v ≠ 0) (hw : w ≠ 0) (hvw : v + w ≠ 0) :
spanCarrier S (Projectivization.mk K v hv) →
spanCarrier S (Projectivization.mk K w hw) → spanCarrier S (Projectivization.mk K (v + w) hvw)
/-- The span of a set of points in projective space is a subspace. -/
def span (S : Set (ℙ K V)) : Subspace K V where
carrier := spanCarrier S
mem_add' v w hv hw hvw := spanCarrier.mem_add v w hv hw hvw
/-- The span of a set of points contains the set of points. -/
theorem subset_span (S : Set (ℙ K V)) : S ⊆ span S := fun _x hx => spanCarrier.of _ hx
/-- The span of a set of points is a Galois insertion between sets of points of a projective space
and subspaces of the projective space. -/
def gi : GaloisInsertion (span : Set (ℙ K V) → Subspace K V) SetLike.coe where
choice S _hS := span S
gc A B :=
⟨fun h => le_trans (subset_span _) h, by
intro h x hx
induction' hx with y hy
· apply h
assumption
· apply B.mem_add
assumption'⟩
le_l_u S := subset_span _
choice_eq _ _ := rfl
/-- The span of a subspace is the subspace. -/
@[simp]
theorem span_coe (W : Subspace K V) : span ↑W = W :=
GaloisInsertion.l_u_eq gi W
/-- The infimum of two subspaces exists. -/
instance instInf : Inf (Subspace K V) :=
⟨fun A B =>
⟨A ⊓ B, fun _v _w hv hw _hvw h1 h2 =>
⟨A.mem_add _ _ hv hw _ h1.1 h2.1, B.mem_add _ _ hv hw _ h1.2 h2.2⟩⟩⟩
-- Porting note: delete the name of this instance since it causes problem since hasInf is already
-- defined above
/-- Infimums of arbitrary collections of subspaces exist. -/
instance instInfSet : InfSet (Subspace K V) :=
⟨fun A =>
⟨sInf (SetLike.coe '' A), fun v w hv hw hvw h1 h2 t => by
rintro ⟨s, hs, rfl⟩
exact s.mem_add v w hv hw _ (h1 s ⟨s, hs, rfl⟩) (h2 s ⟨s, hs, rfl⟩)⟩⟩
/-- The subspaces of a projective space form a complete lattice. -/
instance : CompleteLattice (Subspace K V) :=
{ __ := completeLatticeOfInf (Subspace K V)
(by
refine fun s => ⟨fun a ha x hx => hx _ ⟨a, ha, rfl⟩, fun a ha x hx E => ?_⟩
rintro ⟨E, hE, rfl⟩
exact ha hE hx)
inf_le_left := fun A B _ hx => (@inf_le_left _ _ A B) hx
inf_le_right := fun A B _ hx => (@inf_le_right _ _ A B) hx
le_inf := fun A B _ h1 h2 _ hx => (le_inf h1 h2) hx }
instance subspaceInhabited : Inhabited (Subspace K V) where default := ⊤
/-- The span of the empty set is the bottom of the lattice of subspaces. -/
@[simp]
theorem span_empty : span (∅ : Set (ℙ K V)) = ⊥ := gi.gc.l_bot
/-- The span of the entire projective space is the top of the lattice of subspaces. -/
@[simp]
theorem span_univ : span (Set.univ : Set (ℙ K V)) = ⊤ := by
rw [eq_top_iff, SetLike.le_def]
intro x _hx
exact subset_span _ (Set.mem_univ x)
/-- The span of a set of points is contained in a subspace if and only if the set of points is
contained in the subspace. -/
theorem span_le_subspace_iff {S : Set (ℙ K V)} {W : Subspace K V} : span S ≤ W ↔ S ⊆ W :=
gi.gc S W
/-- If a set of points is a subset of another set of points, then its span will be contained in the
span of that set. -/
@[mono]
theorem monotone_span : Monotone (span : Set (ℙ K V) → Subspace K V) :=
gi.gc.monotone_l
theorem subset_span_trans {S T U : Set (ℙ K V)} (hST : S ⊆ span T) (hTU : T ⊆ span U) :
S ⊆ span U :=
gi.gc.le_u_l_trans hST hTU
/-- The supremum of two subspaces is equal to the span of their union. -/
theorem span_union (S T : Set (ℙ K V)) : span (S ∪ T) = span S ⊔ span T :=
(@gi K V _ _ _).gc.l_sup
/-- The supremum of a collection of subspaces is equal to the span of the union of the
collection. -/
theorem span_iUnion {ι} (s : ι → Set (ℙ K V)) : span (⋃ i, s i) = ⨆ i, span (s i) :=
(@gi K V _ _ _).gc.l_iSup
/-- The supremum of a subspace and the span of a set of points is equal to the span of the union of
the subspace and the set of points. -/
theorem sup_span {S : Set (ℙ K V)} {W : Subspace K V} : W ⊔ span S = span (W ∪ S) := by
rw [span_union, span_coe]
theorem span_sup {S : Set (ℙ K V)} {W : Subspace K V} : span S ⊔ W = span (S ∪ W) := by
rw [span_union, span_coe]
/-- A point in a projective space is contained in the span of a set of points if and only if the
point is contained in all subspaces of the projective space which contain the set of points. -/
theorem mem_span {S : Set (ℙ K V)} (u : ℙ K V) :
u ∈ span S ↔ ∀ W : Subspace K V, S ⊆ W → u ∈ W := by
simp_rw [← span_le_subspace_iff]
exact ⟨fun hu W hW => hW hu, fun W => W (span S) (le_refl _)⟩
/-- The span of a set of points in a projective space is equal to the infimum of the collection of
subspaces which contain the set. -/
theorem span_eq_sInf {S : Set (ℙ K V)} : span S = sInf { W : Subspace K V| S ⊆ W } := by
ext x
simp_rw [mem_carrier_iff, mem_span x]
refine ⟨fun hx => ?_, fun hx W hW => ?_⟩
· rintro W ⟨T, hT, rfl⟩
exact hx T hT
· exact (@sInf_le _ _ { W : Subspace K V | S ⊆ ↑W } W hW) hx
/-- If a set of points in projective space is contained in a subspace, and that subspace is
contained in the span of the set of points, then the span of the set of points is equal to
the subspace. -/
theorem span_eq_of_le {S : Set (ℙ K V)} {W : Subspace K V} (hS : S ⊆ W) (hW : W ≤ span S) :
span S = W :=
le_antisymm (span_le_subspace_iff.mpr hS) hW
/-- The spans of two sets of points in a projective space are equal if and only if each set of
points is contained in the span of the other set. -/
theorem span_eq_span_iff {S T : Set (ℙ K V)} : span S = span T ↔ S ⊆ span T ∧ T ⊆ span S :=
⟨fun h => ⟨h ▸ subset_span S, h.symm ▸ subset_span T⟩, fun h =>
le_antisymm (span_le_subspace_iff.2 h.1) (span_le_subspace_iff.2 h.2)⟩
end Subspace
end Projectivization
|
LinearAlgebra\QuadraticForm\Basic.lean | /-
Copyright (c) 2020 Anne Baanen. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Anne Baanen, Kexing Ying, Eric Wieser
-/
import Mathlib.LinearAlgebra.FiniteDimensional
import Mathlib.LinearAlgebra.Matrix.Determinant.Basic
import Mathlib.LinearAlgebra.Matrix.SesquilinearForm
import Mathlib.LinearAlgebra.Matrix.Symmetric
import Mathlib.Data.Finset.Sym
import Mathlib.LinearAlgebra.BilinearMap
/-!
# Quadratic maps
This file defines quadratic maps on an `R`-module `M`, taking values in an `R`-module `N`.
An `N`-valued quadratic map on a module `M` over a commutative ring `R` is a map `Q : M → N` such
that:
* `QuadraticMap.map_smul`: `Q (a • x) = (a * a) • Q x`
* `QuadraticMap.polar_add_left`, `QuadraticMap.polar_add_right`,
`QuadraticMap.polar_smul_left`, `QuadraticMap.polar_smul_right`:
the map `QuadraticMap.polar Q := fun x y ↦ Q (x + y) - Q x - Q y` is bilinear.
This notion generalizes to commutative semirings using the approach in [izhakian2016][] which
requires that there be a (possibly non-unique) companion bilinear map `B` such that
`∀ x y, Q (x + y) = Q x + Q y + B x y`. Over a ring, this `B` is precisely `QuadraticMap.polar Q`.
To build a `QuadraticMap` from the `polar` axioms, use `QuadraticMap.ofPolar`.
Quadratic maps come with a scalar multiplication, `(a • Q) x = a • Q x`,
and composition with linear maps `f`, `Q.comp f x = Q (f x)`.
## Main definitions
* `QuadraticMap.ofPolar`: a more familiar constructor that works on rings
* `QuadraticMap.associated`: associated bilinear map
* `QuadraticMap.PosDef`: positive definite quadratic maps
* `QuadraticMap.Anisotropic`: anisotropic quadratic maps
* `QuadraticMap.discr`: discriminant of a quadratic map
* `QuadraticMap.IsOrtho`: orthogonality of vectors with respect to a quadratic map.
## Main statements
* `QuadraticMap.associated_left_inverse`,
* `QuadraticMap.associated_rightInverse`: in a commutative ring where 2 has
an inverse, there is a correspondence between quadratic maps and symmetric
bilinear forms
* `LinearMap.BilinForm.exists_orthogonal_basis`: There exists an orthogonal basis with
respect to any nondegenerate, symmetric bilinear map `B`.
## Notation
In this file, the variable `R` is used when a `CommSemiring` structure is available.
The variable `S` is used when `R` itself has a `•` action.
## Implementation notes
While the definition and many results make sense if we drop commutativity assumptions,
the correct definition of a quadratic maps in the noncommutative setting would require
substantial refactors from the current version, such that $Q(rm) = rQ(m)r^*$ for some
suitable conjugation $r^*$.
The [Zulip thread](https://leanprover.zulipchat.com/#narrow/stream/116395-maths/topic/Quadratic.20Maps/near/395529867)
has some further discusion.
## References
* https://en.wikipedia.org/wiki/Quadratic_form
* https://en.wikipedia.org/wiki/Discriminant#Quadratic_forms
## Tags
quadratic map, homogeneous polynomial, quadratic polynomial
-/
universe u v w
variable {S T : Type*}
variable {R : Type*} {M N P A : Type*}
open LinearMap (BilinMap)
open LinearMap (BilinForm)
section Polar
variable [CommRing R] [AddCommGroup M] [AddCommGroup N]
namespace QuadraticMap
/-- Up to a factor 2, `Q.polar` is the associated bilinear map for a quadratic map `Q`.
Source of this name: https://en.wikipedia.org/wiki/Quadratic_form#Generalization
-/
def polar (f : M → N) (x y : M) :=
f (x + y) - f x - f y
protected theorem map_add (f : M → N) (x y : M) :
f (x + y) = f x + f y + polar f x y := by
rw [polar]
abel
theorem polar_add (f g : M → N) (x y : M) : polar (f + g) x y = polar f x y + polar g x y := by
simp only [polar, Pi.add_apply]
abel
theorem polar_neg (f : M → N) (x y : M) : polar (-f) x y = -polar f x y := by
simp only [polar, Pi.neg_apply, sub_eq_add_neg, neg_add]
theorem polar_smul [Monoid S] [DistribMulAction S N] (f : M → N) (s : S) (x y : M) :
polar (s • f) x y = s • polar f x y := by simp only [polar, Pi.smul_apply, smul_sub]
theorem polar_comm (f : M → N) (x y : M) : polar f x y = polar f y x := by
rw [polar, polar, add_comm, sub_sub, sub_sub, add_comm (f x) (f y)]
/-- Auxiliary lemma to express bilinearity of `QuadraticMap.polar` without subtraction. -/
theorem polar_add_left_iff {f : M → N} {x x' y : M} :
polar f (x + x') y = polar f x y + polar f x' y ↔
f (x + x' + y) + (f x + f x' + f y) = f (x + x') + f (x' + y) + f (y + x) := by
simp only [← add_assoc]
simp only [polar, sub_eq_iff_eq_add, eq_sub_iff_add_eq, sub_add_eq_add_sub, add_sub]
simp only [add_right_comm _ (f y) _, add_right_comm _ (f x') (f x)]
rw [add_comm y x, add_right_comm _ _ (f (x + y)), add_comm _ (f (x + y)),
add_right_comm (f (x + y)), add_left_inj]
theorem polar_comp {F : Type*} [CommRing S] [FunLike F N S] [AddMonoidHomClass F N S]
(f : M → N) (g : F) (x y : M) :
polar (g ∘ f) x y = g (polar f x y) := by
simp only [polar, Pi.smul_apply, Function.comp_apply, map_sub]
end QuadraticMap
end Polar
/-- A quadratic map on a module.
For a more familiar constructor when `R` is a ring, see `QuadraticMap.ofPolar`. -/
structure QuadraticMap (R : Type u) (M : Type v) (N : Type w) [CommSemiring R] [AddCommMonoid M]
[Module R M] [AddCommMonoid N] [Module R N] where
toFun : M → N
toFun_smul : ∀ (a : R) (x : M), toFun (a • x) = (a * a) • toFun x
exists_companion' : ∃ B : BilinMap R M N, ∀ x y, toFun (x + y) = toFun x + toFun y + B x y
section QuadraticForm
variable (R : Type u) (M : Type v) [CommSemiring R] [AddCommMonoid M] [Module R M]
variable (R M) in
/-- A quadratic form on a module. -/
abbrev QuadraticForm : Type _ := QuadraticMap R M R
end QuadraticForm
namespace QuadraticMap
section DFunLike
variable [CommSemiring R] [AddCommMonoid M] [Module R M] [AddCommMonoid N] [Module R N]
variable {Q Q' : QuadraticMap R M N}
instance instFunLike : FunLike (QuadraticMap R M N) M N where
coe := toFun
coe_injective' x y h := by cases x; cases y; congr
/-- Helper instance for when there's too many metavariables to apply
`DFunLike.hasCoeToFun` directly. -/
instance : CoeFun (QuadraticMap R M N) fun _ => M → N :=
⟨DFunLike.coe⟩
variable (Q)
/-- The `simp` normal form for a quadratic map is `DFunLike.coe`, not `toFun`. -/
@[simp]
theorem toFun_eq_coe : Q.toFun = ⇑Q :=
rfl
-- this must come after the coe_to_fun definition
initialize_simps_projections QuadraticMap (toFun → apply)
variable {Q}
@[ext]
theorem ext (H : ∀ x : M, Q x = Q' x) : Q = Q' :=
DFunLike.ext _ _ H
theorem congr_fun (h : Q = Q') (x : M) : Q x = Q' x :=
DFunLike.congr_fun h _
/-- Copy of a `QuadraticMap` with a new `toFun` equal to the old one. Useful to fix definitional
equalities. -/
protected def copy (Q : QuadraticMap R M N) (Q' : M → N) (h : Q' = ⇑Q) : QuadraticMap R M N where
toFun := Q'
toFun_smul := h.symm ▸ Q.toFun_smul
exists_companion' := h.symm ▸ Q.exists_companion'
@[simp]
theorem coe_copy (Q : QuadraticMap R M N) (Q' : M → N) (h : Q' = ⇑Q) : ⇑(Q.copy Q' h) = Q' :=
rfl
theorem copy_eq (Q : QuadraticMap R M N) (Q' : M → N) (h : Q' = ⇑Q) : Q.copy Q' h = Q :=
DFunLike.ext' h
end DFunLike
section CommSemiring
variable [CommSemiring R] [AddCommMonoid M] [Module R M] [AddCommMonoid N] [Module R N]
variable (Q : QuadraticMap R M N)
theorem map_smul (a : R) (x : M) : Q (a • x) = (a * a) • Q x :=
Q.toFun_smul a x
theorem exists_companion : ∃ B : BilinMap R M N, ∀ x y, Q (x + y) = Q x + Q y + B x y :=
Q.exists_companion'
theorem map_add_add_add_map (x y z : M) :
Q (x + y + z) + (Q x + Q y + Q z) = Q (x + y) + Q (y + z) + Q (z + x) := by
obtain ⟨B, h⟩ := Q.exists_companion
rw [add_comm z x]
simp only [h, LinearMap.map_add₂]
abel
theorem map_add_self (x : M) : Q (x + x) = 4 • Q x := by
rw [← two_smul R x, map_smul, ← Nat.cast_smul_eq_nsmul R]
norm_num
-- not @[simp] because it is superseded by `ZeroHomClass.map_zero`
protected theorem map_zero : Q 0 = 0 := by
rw [← @zero_smul R _ _ _ _ (0 : M), map_smul, zero_mul, zero_smul]
instance zeroHomClass : ZeroHomClass (QuadraticMap R M N) M N :=
{ QuadraticMap.instFunLike (R := R) (M := M) (N := N) with map_zero := QuadraticMap.map_zero }
theorem map_smul_of_tower [CommSemiring S] [Algebra S R] [Module S M] [IsScalarTower S R M]
[Module S N] [IsScalarTower S R N] (a : S)
(x : M) : Q (a • x) = (a * a) • Q x := by
rw [← IsScalarTower.algebraMap_smul R a x, map_smul, ← RingHom.map_mul, algebraMap_smul]
end CommSemiring
section CommRing
variable [CommRing R] [AddCommGroup M] [AddCommGroup N]
variable [Module R M] [Module R N] (Q : QuadraticMap R M N)
@[simp]
theorem map_neg (x : M) : Q (-x) = Q x := by
rw [← @neg_one_smul R _ _ _ _ x, map_smul, neg_one_mul, neg_neg, one_smul]
theorem map_sub (x y : M) : Q (x - y) = Q (y - x) := by rw [← neg_sub, map_neg]
@[simp]
theorem polar_zero_left (y : M) : polar Q 0 y = 0 := by
simp only [polar, zero_add, QuadraticMap.map_zero, sub_zero, sub_self]
@[simp]
theorem polar_add_left (x x' y : M) : polar Q (x + x') y = polar Q x y + polar Q x' y :=
polar_add_left_iff.mpr <| Q.map_add_add_add_map x x' y
@[simp]
theorem polar_smul_left (a : R) (x y : M) : polar Q (a • x) y = a • polar Q x y := by
obtain ⟨B, h⟩ := Q.exists_companion
simp_rw [polar, h, Q.map_smul, LinearMap.map_smul₂, sub_sub, add_sub_cancel_left]
@[simp]
theorem polar_neg_left (x y : M) : polar Q (-x) y = -polar Q x y := by
rw [← neg_one_smul R x, polar_smul_left, neg_one_smul]
@[simp]
theorem polar_sub_left (x x' y : M) : polar Q (x - x') y = polar Q x y - polar Q x' y := by
rw [sub_eq_add_neg, sub_eq_add_neg, polar_add_left, polar_neg_left]
@[simp]
theorem polar_zero_right (y : M) : polar Q y 0 = 0 := by
simp only [add_zero, polar, QuadraticMap.map_zero, sub_self]
@[simp]
theorem polar_add_right (x y y' : M) : polar Q x (y + y') = polar Q x y + polar Q x y' := by
rw [polar_comm Q x, polar_comm Q x, polar_comm Q x, polar_add_left]
@[simp]
theorem polar_smul_right (a : R) (x y : M) : polar Q x (a • y) = a • polar Q x y := by
rw [polar_comm Q x, polar_comm Q x, polar_smul_left]
@[simp]
theorem polar_neg_right (x y : M) : polar Q x (-y) = -polar Q x y := by
rw [← neg_one_smul R y, polar_smul_right, neg_one_smul]
@[simp]
theorem polar_sub_right (x y y' : M) : polar Q x (y - y') = polar Q x y - polar Q x y' := by
rw [sub_eq_add_neg, sub_eq_add_neg, polar_add_right, polar_neg_right]
@[simp]
theorem polar_self (x : M) : polar Q x x = 2 • Q x := by
rw [polar, map_add_self, sub_sub, sub_eq_iff_eq_add, ← two_smul ℕ, ← two_smul ℕ, ← mul_smul]
norm_num
/-- `QuadraticMap.polar` as a bilinear map -/
@[simps!]
def polarBilin : BilinMap R M N :=
LinearMap.mk₂ R (polar Q) (polar_add_left Q) (polar_smul_left Q) (polar_add_right Q)
(polar_smul_right Q)
variable [CommSemiring S] [Algebra S R] [Module S M] [IsScalarTower S R M] [Module S N]
[IsScalarTower S R N]
@[simp]
theorem polar_smul_left_of_tower (a : S) (x y : M) : polar Q (a • x) y = a • polar Q x y := by
rw [← IsScalarTower.algebraMap_smul R a x, polar_smul_left, algebraMap_smul]
@[simp]
theorem polar_smul_right_of_tower (a : S) (x y : M) : polar Q x (a • y) = a • polar Q x y := by
rw [← IsScalarTower.algebraMap_smul R a y, polar_smul_right, algebraMap_smul]
/-- An alternative constructor to `QuadraticMap.mk`, for rings where `polar` can be used. -/
@[simps]
def ofPolar (toFun : M → N) (toFun_smul : ∀ (a : R) (x : M), toFun (a • x) = (a * a) • toFun x)
(polar_add_left : ∀ x x' y : M, polar toFun (x + x') y = polar toFun x y + polar toFun x' y)
(polar_smul_left : ∀ (a : R) (x y : M), polar toFun (a • x) y = a • polar toFun x y) :
QuadraticMap R M N :=
{ toFun
toFun_smul
exists_companion' := ⟨LinearMap.mk₂ R (polar toFun) (polar_add_left) (polar_smul_left)
(fun x _ _ ↦ by simp_rw [polar_comm _ x, polar_add_left])
(fun _ _ _ ↦ by rw [polar_comm, polar_smul_left, polar_comm]),
fun _ _ ↦ by
simp only [LinearMap.mk₂_apply]
rw [polar, sub_sub, add_sub_cancel]⟩ }
/-- In a ring the companion bilinear form is unique and equal to `QuadraticMap.polar`. -/
theorem choose_exists_companion : Q.exists_companion.choose = polarBilin Q :=
LinearMap.ext₂ fun x y => by
rw [polarBilin_apply_apply, polar, Q.exists_companion.choose_spec, sub_sub,
add_sub_cancel_left]
protected theorem map_sum {ι} [DecidableEq ι] (Q : QuadraticMap R M N) (s : Finset ι) (f : ι → M) :
Q (∑ i ∈ s, f i) = ∑ i ∈ s, Q (f i) +
∑ ij in s.sym2.filter (¬ ·.IsDiag),
Sym2.lift ⟨fun i j => polar Q (f i) (f j), fun _ _ => polar_comm _ _ _⟩ ij := by
induction s using Finset.cons_induction with
| empty => simp
| cons a s ha ih =>
simp_rw [Finset.sum_cons, QuadraticMap.map_add, ih, add_assoc, Finset.sym2_cons,
Finset.sum_filter, Finset.sum_disjUnion, Finset.sum_map, Finset.sum_cons,
Sym2.mkEmbedding_apply, Sym2.isDiag_iff_proj_eq, not_true, if_false, zero_add, Sym2.lift_mk,
← polarBilin_apply_apply, _root_.map_sum, polarBilin_apply_apply]
congr 2
rw [add_comm]
congr! with i hi
rw [if_pos (ne_of_mem_of_not_mem hi ha).symm]
protected theorem map_sum' {ι} (Q : QuadraticMap R M N) (s : Finset ι) (f : ι → M) :
Q (∑ i ∈ s, f i) =
∑ ij in s.sym2,
Sym2.lift ⟨fun i j => polar Q (f i) (f j), fun _ _ => polar_comm _ _ _⟩ ij
- ∑ i ∈ s, Q (f i) := by
induction s using Finset.cons_induction with
| empty => simp
| cons a s ha ih =>
simp_rw [Finset.sum_cons, QuadraticMap.map_add Q, ih, add_assoc, Finset.sym2_cons,
Finset.sum_disjUnion, Finset.sum_map, Finset.sum_cons, Sym2.mkEmbedding_apply, Sym2.lift_mk,
← polarBilin_apply_apply, _root_.map_sum, polarBilin_apply_apply, polar_self]
abel_nf
end CommRing
section SemiringOperators
variable [CommSemiring R] [AddCommMonoid M] [Module R M] [AddCommMonoid N] [Module R N]
section SMul
variable [Monoid S] [Monoid T] [DistribMulAction S N] [DistribMulAction T N]
variable [SMulCommClass S R N] [SMulCommClass T R N]
/-- `QuadraticMap R M N` inherits the scalar action from any algebra over `R`.
This provides an `R`-action via `Algebra.id`. -/
instance : SMul S (QuadraticMap R M N) :=
⟨fun a Q =>
{ toFun := a • ⇑Q
toFun_smul := fun b x => by
rw [Pi.smul_apply, map_smul, Pi.smul_apply, smul_comm]
exists_companion' :=
let ⟨B, h⟩ := Q.exists_companion
letI := SMulCommClass.symm S R N
⟨a • B, by simp [h]⟩ }⟩
@[simp]
theorem coeFn_smul (a : S) (Q : QuadraticMap R M N) : ⇑(a • Q) = a • ⇑Q :=
rfl
@[simp]
theorem smul_apply (a : S) (Q : QuadraticMap R M N) (x : M) : (a • Q) x = a • Q x :=
rfl
instance [SMulCommClass S T N] : SMulCommClass S T (QuadraticMap R M N) where
smul_comm _s _t _q := ext fun _ => smul_comm _ _ _
instance [SMul S T] [IsScalarTower S T N] : IsScalarTower S T (QuadraticMap R M N) where
smul_assoc _s _t _q := ext fun _ => smul_assoc _ _ _
end SMul
instance : Zero (QuadraticMap R M N) :=
⟨{ toFun := fun _ => 0
toFun_smul := fun a _ => by simp only [smul_zero]
exists_companion' := ⟨0, fun _ _ => by simp only [add_zero, LinearMap.zero_apply]⟩ }⟩
@[simp]
theorem coeFn_zero : ⇑(0 : QuadraticMap R M N) = 0 :=
rfl
@[simp]
theorem zero_apply (x : M) : (0 : QuadraticMap R M N) x = 0 :=
rfl
instance : Inhabited (QuadraticMap R M N) :=
⟨0⟩
instance : Add (QuadraticMap R M N) :=
⟨fun Q Q' =>
{ toFun := Q + Q'
toFun_smul := fun a x => by simp only [Pi.add_apply, smul_add, map_smul]
exists_companion' :=
let ⟨B, h⟩ := Q.exists_companion
let ⟨B', h'⟩ := Q'.exists_companion
⟨B + B', fun x y => by
simp_rw [Pi.add_apply, h, h', LinearMap.add_apply, add_add_add_comm]⟩ }⟩
@[simp]
theorem coeFn_add (Q Q' : QuadraticMap R M N) : ⇑(Q + Q') = Q + Q' :=
rfl
@[simp]
theorem add_apply (Q Q' : QuadraticMap R M N) (x : M) : (Q + Q') x = Q x + Q' x :=
rfl
instance : AddCommMonoid (QuadraticMap R M N) :=
DFunLike.coe_injective.addCommMonoid _ coeFn_zero coeFn_add fun _ _ => coeFn_smul _ _
/-- `@CoeFn (QuadraticMap R M)` as an `AddMonoidHom`.
This API mirrors `AddMonoidHom.coeFn`. -/
@[simps apply]
def coeFnAddMonoidHom : QuadraticMap R M N →+ M → N where
toFun := DFunLike.coe
map_zero' := coeFn_zero
map_add' := coeFn_add
/-- Evaluation on a particular element of the module `M` is an additive map on quadratic maps. -/
@[simps! apply]
def evalAddMonoidHom (m : M) : QuadraticMap R M N →+ N :=
(Pi.evalAddMonoidHom _ m).comp coeFnAddMonoidHom
section Sum
@[simp]
theorem coeFn_sum {ι : Type*} (Q : ι → QuadraticMap R M N) (s : Finset ι) :
⇑(∑ i ∈ s, Q i) = ∑ i ∈ s, ⇑(Q i) :=
map_sum coeFnAddMonoidHom Q s
@[simp]
theorem sum_apply {ι : Type*} (Q : ι → QuadraticMap R M N) (s : Finset ι) (x : M) :
(∑ i ∈ s, Q i) x = ∑ i ∈ s, Q i x :=
map_sum (evalAddMonoidHom x : _ →+ N) Q s
end Sum
instance [Monoid S] [DistribMulAction S N] [SMulCommClass S R N] :
DistribMulAction S (QuadraticMap R M N) where
mul_smul a b Q := ext fun x => by simp only [smul_apply, mul_smul]
one_smul Q := ext fun x => by simp only [QuadraticMap.smul_apply, one_smul]
smul_add a Q Q' := by
ext
simp only [add_apply, smul_apply, smul_add]
smul_zero a := by
ext
simp only [zero_apply, smul_apply, smul_zero]
instance [Semiring S] [Module S N] [SMulCommClass S R N] :
Module S (QuadraticMap R M N) where
zero_smul Q := by
ext
simp only [zero_apply, smul_apply, zero_smul]
add_smul a b Q := by
ext
simp only [add_apply, smul_apply, add_smul]
end SemiringOperators
section RingOperators
variable [CommRing R] [AddCommGroup M] [Module R M] [AddCommGroup N] [Module R N]
instance : Neg (QuadraticMap R M N) :=
⟨fun Q =>
{ toFun := -Q
toFun_smul := fun a x => by simp only [Pi.neg_apply, map_smul, smul_neg]
exists_companion' :=
let ⟨B, h⟩ := Q.exists_companion
⟨-B, fun x y => by simp_rw [Pi.neg_apply, h, LinearMap.neg_apply, neg_add]⟩ }⟩
@[simp]
theorem coeFn_neg (Q : QuadraticMap R M N) : ⇑(-Q) = -Q :=
rfl
@[simp]
theorem neg_apply (Q : QuadraticMap R M N) (x : M) : (-Q) x = -Q x :=
rfl
instance : Sub (QuadraticMap R M N) :=
⟨fun Q Q' => (Q + -Q').copy (Q - Q') (sub_eq_add_neg _ _)⟩
@[simp]
theorem coeFn_sub (Q Q' : QuadraticMap R M N) : ⇑(Q - Q') = Q - Q' :=
rfl
@[simp]
theorem sub_apply (Q Q' : QuadraticMap R M N) (x : M) : (Q - Q') x = Q x - Q' x :=
rfl
instance : AddCommGroup (QuadraticMap R M N) :=
DFunLike.coe_injective.addCommGroup _ coeFn_zero coeFn_add coeFn_neg coeFn_sub
(fun _ _ => coeFn_smul _ _) fun _ _ => coeFn_smul _ _
end RingOperators
section restrictScalars
variable [CommSemiring R] [CommSemiring S] [AddCommMonoid M] [Module R M] [AddCommMonoid N]
[Module R N] [Module S M] [Module S N] [Algebra S R]
variable [IsScalarTower S R M] [IsScalarTower S R N]
/-- If `B : M → N → Pₗ` is `R`-`S` bilinear and `R'` and `S'` are compatible scalar multiplications,
then the restriction of scalars is a `R'`-`S'` bilinear map. -/
@[simps!]
def restrictScalars (Q : QuadraticMap R M N) : QuadraticMap S M N where
toFun x := Q x
toFun_smul a x := by
simp [map_smul_of_tower]
exists_companion' :=
let ⟨B, h⟩ := Q.exists_companion
⟨B.restrictScalars₁₂ (S := R) (R' := S) (S' := S), fun x y => by
simp only [LinearMap.restrictScalars₁₂_apply_apply, h]⟩
end restrictScalars
section Comp
variable [CommSemiring R] [AddCommMonoid M] [Module R M] [AddCommMonoid N] [Module R N]
variable [AddCommMonoid P] [Module R P]
/-- Compose the quadratic map with a linear function on the right. -/
def comp (Q : QuadraticMap R N P) (f : M →ₗ[R] N) : QuadraticMap R M P where
toFun x := Q (f x)
toFun_smul a x := by simp only [map_smul, f.map_smul]
exists_companion' :=
let ⟨B, h⟩ := Q.exists_companion
⟨B.compl₁₂ f f, fun x y => by simp_rw [f.map_add]; exact h (f x) (f y)⟩
@[simp]
theorem comp_apply (Q : QuadraticMap R N P) (f : M →ₗ[R] N) (x : M) : (Q.comp f) x = Q (f x) :=
rfl
/-- Compose a quadratic map with a linear function on the left. -/
@[simps (config := { simpRhs := true })]
def _root_.LinearMap.compQuadraticMap (f : N →ₗ[R] P) (Q : QuadraticMap R M N) :
QuadraticMap R M P where
toFun x := f (Q x)
toFun_smul b x := by simp only [map_smul, f.map_smul]
exists_companion' :=
let ⟨B, h⟩ := Q.exists_companion
⟨B.compr₂ f, fun x y => by simp only [h, map_add, LinearMap.compr₂_apply]⟩
/-- Compose a quadratic map with a linear function on the left. -/
@[simps! (config := { simpRhs := true })]
def _root_.LinearMap.compQuadraticMap' [CommSemiring S] [Algebra S R] [Module S N] [Module S M]
[IsScalarTower S R N] [IsScalarTower S R M] [Module S P]
(f : N →ₗ[S] P) (Q : QuadraticMap R M N) : QuadraticMap S M P :=
_root_.LinearMap.compQuadraticMap f Q.restrictScalars
end Comp
section NonUnitalNonAssocSemiring
variable [CommSemiring R] [NonUnitalNonAssocSemiring A] [AddCommMonoid M] [Module R M]
variable [Module R A] [SMulCommClass R A A] [IsScalarTower R A A]
/-- The product of linear forms is a quadratic form. -/
def linMulLin (f g : M →ₗ[R] A) : QuadraticMap R M A where
toFun := f * g
toFun_smul a x := by
rw [Pi.mul_apply, Pi.mul_apply, LinearMap.map_smulₛₗ, RingHom.id_apply, LinearMap.map_smulₛₗ,
RingHom.id_apply, smul_mul_assoc, mul_smul_comm, ← smul_assoc, (smul_eq_mul R)]
exists_companion' :=
⟨(LinearMap.mul R A).compl₁₂ f g + (LinearMap.mul R A).flip.compl₁₂ g f, fun x y => by
simp only [Pi.mul_apply, map_add, left_distrib, right_distrib, LinearMap.add_apply,
LinearMap.compl₁₂_apply, LinearMap.mul_apply', LinearMap.flip_apply]
abel_nf⟩
@[simp]
theorem linMulLin_apply (f g : M →ₗ[R] A) (x) : linMulLin f g x = f x * g x :=
rfl
@[simp]
theorem add_linMulLin (f g h : M →ₗ[R] A) : linMulLin (f + g) h = linMulLin f h + linMulLin g h :=
ext fun _ => add_mul _ _ _
@[simp]
theorem linMulLin_add (f g h : M →ₗ[R] A) : linMulLin f (g + h) = linMulLin f g + linMulLin f h :=
ext fun _ => mul_add _ _ _
variable {N' : Type*} [AddCommMonoid N'] [Module R N']
@[simp]
theorem linMulLin_comp (f g : M →ₗ[R] A) (h : N' →ₗ[R] M) :
(linMulLin f g).comp h = linMulLin (f.comp h) (g.comp h) :=
rfl
variable {n : Type*}
/-- `sq` is the quadratic form mapping the vector `x : A` to `x * x` -/
@[simps!]
def sq : QuadraticMap R A A :=
linMulLin LinearMap.id LinearMap.id
/-- `proj i j` is the quadratic form mapping the vector `x : n → R` to `x i * x j` -/
def proj (i j : n) : QuadraticMap R (n → A) A :=
linMulLin (@LinearMap.proj _ _ _ (fun _ => A) _ _ i) (@LinearMap.proj _ _ _ (fun _ => A) _ _ j)
@[simp]
theorem proj_apply (i j : n) (x : n → A) : proj (R := R) i j x = x i * x j :=
rfl
end NonUnitalNonAssocSemiring
end QuadraticMap
/-!
### Associated bilinear maps
Over a commutative ring with an inverse of 2, the theory of quadratic maps is
basically identical to that of symmetric bilinear maps. The map from quadratic
maps to bilinear maps giving this identification is called the <`associated`
quadratic map.
-/
namespace LinearMap
namespace BilinMap
open QuadraticMap
open LinearMap (BilinMap)
section Semiring
variable [CommSemiring R] [AddCommMonoid M] [Module R M] [AddCommMonoid N] [Module R N]
variable {N' : Type*} [AddCommMonoid N'] [Module R N']
/-- A bilinear map gives a quadratic map by applying the argument twice. -/
def toQuadraticMap (B : BilinMap R M N) : QuadraticMap R M N where
toFun x := B x x
toFun_smul a x := by simp only [_root_.map_smul, LinearMap.smul_apply, smul_smul]
exists_companion' := ⟨B + LinearMap.flip B, fun x y => by simp [add_add_add_comm, add_comm]⟩
@[simp]
theorem toQuadraticMap_apply (B : BilinMap R M N) (x : M) : B.toQuadraticMap x = B x x :=
rfl
theorem toQuadraticMap_comp_same (B : BilinMap R M N) (f : N' →ₗ[R] M) :
BilinMap.toQuadraticMap (B.compl₁₂ f f) = B.toQuadraticMap.comp f := rfl
section
variable (R M)
@[simp]
theorem toQuadraticMap_zero : (0 : BilinMap R M N).toQuadraticMap = 0 :=
rfl
end
@[simp]
theorem toQuadraticMap_add (B₁ B₂ : BilinMap R M N) :
(B₁ + B₂).toQuadraticMap = B₁.toQuadraticMap + B₂.toQuadraticMap :=
rfl
@[simp]
theorem toQuadraticMap_smul [Monoid S] [DistribMulAction S N] [SMulCommClass S R N]
[SMulCommClass R S N] (a : S)
(B : BilinMap R M N) : (a • B).toQuadraticMap = a • B.toQuadraticMap :=
rfl
section
variable (S R M)
/-- `LinearMap.BilinForm.toQuadraticMap` as an additive homomorphism -/
@[simps]
def toQuadraticMapAddMonoidHom : (BilinMap R M N) →+ QuadraticMap R M N where
toFun := toQuadraticMap
map_zero' := toQuadraticMap_zero _ _
map_add' := toQuadraticMap_add
/-- `LinearMap.BilinForm.toQuadraticMap` as a linear map -/
@[simps!]
def toQuadraticMapLinearMap [Semiring S] [Module S N] [SMulCommClass S R N] [SMulCommClass R S N] :
(BilinMap R M N) →ₗ[S] QuadraticMap R M N where
toFun := toQuadraticMap
map_smul' := toQuadraticMap_smul
map_add' := toQuadraticMap_add
end
@[simp]
theorem toQuadraticMap_list_sum (B : List (BilinMap R M N)) :
B.sum.toQuadraticMap = (B.map toQuadraticMap).sum :=
map_list_sum (toQuadraticMapAddMonoidHom R M) B
@[simp]
theorem toQuadraticMap_multiset_sum (B : Multiset (BilinMap R M N)) :
B.sum.toQuadraticMap = (B.map toQuadraticMap).sum :=
map_multiset_sum (toQuadraticMapAddMonoidHom R M) B
@[simp]
theorem toQuadraticMap_sum {ι : Type*} (s : Finset ι) (B : ι → (BilinMap R M N)) :
(∑ i ∈ s, B i).toQuadraticMap = ∑ i ∈ s, (B i).toQuadraticMap :=
map_sum (toQuadraticMapAddMonoidHom R M) B s
@[simp]
theorem toQuadraticMap_eq_zero {B : BilinMap R M N} :
B.toQuadraticMap = 0 ↔ B.IsAlt :=
QuadraticMap.ext_iff
end Semiring
section Ring
variable [CommRing R] [AddCommGroup M] [AddCommGroup N] [Module R M] [Module R N]
variable {B : BilinMap R M N}
@[simp]
theorem toQuadraticMap_neg (B : BilinMap R M N) : (-B).toQuadraticMap = -B.toQuadraticMap :=
rfl
@[simp]
theorem toQuadraticMap_sub (B₁ B₂ : BilinMap R M N) :
(B₁ - B₂).toQuadraticMap = B₁.toQuadraticMap - B₂.toQuadraticMap :=
rfl
theorem polar_toQuadraticMap (x y : M) : polar (toQuadraticMap B) x y = B x y + B y x := by
simp only [polar, toQuadraticMap_apply, map_add, add_apply, add_assoc, add_comm (B y x) _,
add_sub_cancel_left, sub_eq_add_neg _ (B y y), add_neg_cancel_left]
theorem polarBilin_toQuadraticMap : polarBilin (toQuadraticMap B) = B + flip B :=
LinearMap.ext₂ polar_toQuadraticMap
@[simp] theorem _root_.QuadraticMap.toQuadraticMap_polarBilin (Q : QuadraticMap R M N) :
toQuadraticMap (polarBilin Q) = 2 • Q :=
QuadraticMap.ext fun x => (polar_self _ x).trans <| by simp
theorem _root_.QuadraticMap.polarBilin_injective (h : IsUnit (2 : R)) :
Function.Injective (polarBilin : QuadraticMap R M N → _) := by
intro Q₁ Q₂ h₁₂
apply h.smul_left_cancel.mp
rw [show (2 : R) = (2 : ℕ) by rfl]
simp_rw [Nat.cast_smul_eq_nsmul R, ← QuadraticMap.toQuadraticMap_polarBilin]
exact congrArg toQuadraticMap h₁₂
section
variable {N' : Type*} [AddCommGroup N'] [Module R N']
variable [CommRing S] [Algebra S R] [Module S M] [IsScalarTower S R M]
theorem _root_.QuadraticMap.polarBilin_comp (Q : QuadraticMap R N' N) (f : M →ₗ[R] N') :
polarBilin (Q.comp f) = LinearMap.compl₁₂ (polarBilin Q) f f :=
LinearMap.ext₂ <| fun x y => by simp [polar]
end
variable {N' : Type*} [AddCommGroup N']
theorem _root_.LinearMap.compQuadraticMap_polar [CommSemiring S] [Algebra S R] [Module S N]
[Module S N'] [IsScalarTower S R N] [Module S M] [IsScalarTower S R M] (f : N →ₗ[S] N')
(Q : QuadraticMap R M N) (x y : M) : polar (f.compQuadraticMap' Q) x y = f (polar Q x y) := by
simp [polar]
variable [Module R N']
theorem _root_.LinearMap.compQuadraticMap_polarBilin (f : N →ₗ[R] N') (Q : QuadraticMap R M N) :
(f.compQuadraticMap' Q).polarBilin = Q.polarBilin.compr₂ f := by
ext
rw [polarBilin_apply_apply, compr₂_apply, polarBilin_apply_apply,
LinearMap.compQuadraticMap_polar]
end Ring
end BilinMap
end LinearMap
namespace QuadraticMap
open LinearMap (BilinMap)
section AssociatedHom
variable [CommRing R] [AddCommGroup M] [Module R M] [AddCommGroup N] [Module R N]
variable (S) [CommSemiring S] [Algebra S R]
variable [Module S N] [IsScalarTower S R N]
variable [Invertible (2 : R)] {B₁ : BilinMap R M R}
/-- `associatedHom` is the map that sends a quadratic map on a module `M` over `R` to its
associated symmetric bilinear map. As provided here, this has the structure of an `S`-linear map
where `S` is a commutative subring of `R`.
Over a commutative ring, use `QuadraticMap.associated`, which gives an `R`-linear map. Over a
general ring with no nontrivial distinguished commutative subring, use `QuadraticMap.associated'`,
which gives an additive homomorphism (or more precisely a `ℤ`-linear map.) -/
def associatedHom : QuadraticMap R M N →ₗ[S] (BilinMap R M N) :=
-- TODO: this `center` stuff is vertigial from an incorrect non-commutative version, but we leave
-- it behind to make a future refactor to a *correct* non-commutative version easier in future.
(⟨⅟2, Set.invOf_mem_center (Set.ofNat_mem_center _ _)⟩ : Submonoid.center R) •
{ toFun := polarBilin
map_add' := fun _x _y => LinearMap.ext₂ <| polar_add _ _
map_smul' := fun _c _x => LinearMap.ext₂ <| polar_smul _ _ }
variable (Q : QuadraticMap R M N)
@[simp]
theorem associated_apply (x y : M) : associatedHom S Q x y = ⅟ (2 : R) • (Q (x + y) - Q x - Q y) :=
rfl
@[simp] theorem two_nsmul_associated : 2 • associatedHom S Q = Q.polarBilin := by
ext
dsimp
rw [← smul_assoc, two_nsmul, invOf_two_add_invOf_two, one_smul, polar]
theorem associated_isSymm (Q : QuadraticMap R M R) : (associatedHom S Q).IsSymm := fun x y => by
simp only [associated_apply, sub_eq_add_neg, add_assoc, map_mul, RingHom.id_apply, map_add,
_root_.map_neg, add_comm, add_left_comm]
@[simp]
theorem associated_comp {N' : Type*} [AddCommGroup N'] [Module R N'] (f : N' →ₗ[R] M) :
associatedHom S (Q.comp f) = (associatedHom S Q).compl₁₂ f f := by
ext
simp only [associated_apply, comp_apply, map_add, LinearMap.compl₁₂_apply]
theorem associated_toQuadraticMap (B : BilinMap R M R) (x y : M) :
associatedHom S B.toQuadraticMap x y = ⅟ (2 : R) • (B x y + B y x) := by
simp only [associated_apply, LinearMap.BilinMap.toQuadraticMap_apply, map_add,
LinearMap.add_apply, smul_eq_mul]
abel_nf
theorem associated_left_inverse (h : B₁.IsSymm) : associatedHom S B₁.toQuadraticMap = B₁ :=
LinearMap.ext₂ fun x y => by
rw [associated_toQuadraticMap, ← h.eq x y, RingHom.id_apply, ← two_mul, ← smul_mul_assoc,
smul_eq_mul, invOf_mul_self, one_mul]
-- Porting note: moved from below to golf the next theorem
theorem associated_eq_self_apply (x : M) : associatedHom S Q x x = Q x := by
rw [associated_apply, map_add_self, ← three_add_one_eq_four, ← two_add_one_eq_three, add_smul,
add_smul, one_smul, add_sub_cancel_right, add_sub_cancel_right, two_smul, ← two_smul R,
← smul_assoc]
simp only [smul_eq_mul, invOf_mul_self', one_smul]
theorem toQuadraticMap_associated : (associatedHom S Q).toQuadraticMap = Q :=
QuadraticMap.ext <| associated_eq_self_apply S Q
-- note: usually `rightInverse` lemmas are named the other way around, but this is consistent
-- with historical naming in this file.
theorem associated_rightInverse :
Function.RightInverse (associatedHom S) (BilinMap.toQuadraticMap : _ → QuadraticMap R M R) :=
fun Q => toQuadraticMap_associated S Q
/-- `associated'` is the `ℤ`-linear map that sends a quadratic form on a module `M` over `R` to its
associated symmetric bilinear form. -/
abbrev associated' : QuadraticMap R M R →ₗ[ℤ] BilinMap R M R :=
associatedHom ℤ
/-- Symmetric bilinear forms can be lifted to quadratic forms -/
instance canLift :
CanLift (BilinMap R M R) (QuadraticForm R M) (associatedHom ℕ) LinearMap.IsSymm where
prf B hB := ⟨B.toQuadraticMap, associated_left_inverse _ hB⟩
/-- There exists a non-null vector with respect to any quadratic form `Q` whose associated
bilinear form is non-zero, i.e. there exists `x` such that `Q x ≠ 0`. -/
theorem exists_quadraticForm_ne_zero {Q : QuadraticForm R M}
-- Porting note: added implicit argument
(hB₁ : associated' (R := R) Q ≠ 0) :
∃ x, Q x ≠ 0 := by
rw [← not_forall]
intro h
apply hB₁
rw [(QuadraticMap.ext h : Q = 0), LinearMap.map_zero]
end AssociatedHom
section Associated
variable [CommSemiring S] [CommRing R] [AddCommGroup M] [Algebra S R] [Module R M]
variable [AddCommGroup N] [Module R N] [Module S N] [IsScalarTower S R N]
variable [Invertible (2 : R)]
-- Note: When possible, rather than writing lemmas about `associated`, write a lemma applying to
-- the more general `associatedHom` and place it in the previous section.
/-- `associated` is the linear map that sends a quadratic map over a commutative ring to its
associated symmetric bilinear map. -/
abbrev associated : QuadraticMap R M N →ₗ[R] BilinMap R M N :=
associatedHom R
variable (S) in
theorem coe_associatedHom :
⇑(associatedHom S : QuadraticMap R M N →ₗ[S] BilinMap R M N) = associated :=
rfl
open LinearMap in
@[simp]
theorem associated_linMulLin (f g : M →ₗ[R] R) :
associated (R := R) (linMulLin f g) =
⅟ (2 : R) • ((mul R R).compl₁₂ f g + (mul R R).compl₁₂ g f) := by
ext
simp only [associated_apply, linMulLin_apply, map_add, smul_add, LinearMap.add_apply,
LinearMap.smul_apply, compl₁₂_apply, mul_apply', smul_eq_mul]
ring_nf
open LinearMap in
@[simp]
lemma associated_sq : associated (R := R) sq = mul R R :=
(associated_linMulLin (id) (id)).trans <|
by simp only [smul_add, invOf_two_smul_add_invOf_two_smul]; rfl
end Associated
section IsOrtho
/-! ### Orthogonality -/
section CommSemiring
variable [CommSemiring R] [AddCommMonoid M] [Module R M] [AddCommMonoid N] [Module R N]
{Q : QuadraticMap R M N}
/-- The proposition that two elements of a quadratic map space are orthogonal. -/
def IsOrtho (Q : QuadraticMap R M N) (x y : M) : Prop :=
Q (x + y) = Q x + Q y
theorem isOrtho_def {Q : QuadraticMap R M N} {x y : M} : Q.IsOrtho x y ↔ Q (x + y) = Q x + Q y :=
Iff.rfl
theorem IsOrtho.all (x y : M) : IsOrtho (0 : QuadraticMap R M N) x y := (zero_add _).symm
theorem IsOrtho.zero_left (x : M) : IsOrtho Q (0 : M) x := by simp [isOrtho_def]
theorem IsOrtho.zero_right (x : M) : IsOrtho Q x (0 : M) := by simp [isOrtho_def]
theorem ne_zero_of_not_isOrtho_self {Q : QuadraticMap R M N} (x : M) (hx₁ : ¬Q.IsOrtho x x) :
x ≠ 0 :=
fun hx₂ => hx₁ (hx₂.symm ▸ .zero_left _)
theorem isOrtho_comm {x y : M} : IsOrtho Q x y ↔ IsOrtho Q y x := by simp_rw [isOrtho_def, add_comm]
alias ⟨IsOrtho.symm, _⟩ := isOrtho_comm
theorem _root_.LinearMap.BilinForm.toQuadraticMap_isOrtho [IsCancelAdd R]
[NoZeroDivisors R] [CharZero R] {B : BilinMap R M R} {x y : M} (h : B.IsSymm) :
B.toQuadraticMap.IsOrtho x y ↔ B.IsOrtho x y := by
letI : AddCancelMonoid R := { ‹IsCancelAdd R›, (inferInstanceAs <| AddCommMonoid R) with }
simp_rw [isOrtho_def, LinearMap.isOrtho_def, B.toQuadraticMap_apply, map_add,
LinearMap.add_apply, add_comm _ (B y y), add_add_add_comm _ _ (B y y), add_comm (B y y)]
rw [add_right_eq_self (a := B x x + B y y), ← h, RingHom.id_apply, add_self_eq_zero]
end CommSemiring
section CommRing
variable [CommRing R] [AddCommGroup M] [Module R M] [AddCommGroup N] [Module R N]
{Q : QuadraticMap R M N}
@[simp]
theorem isOrtho_polarBilin {x y : M} : Q.polarBilin.IsOrtho x y ↔ IsOrtho Q x y := by
simp_rw [isOrtho_def, LinearMap.isOrtho_def, polarBilin_apply_apply, polar, sub_sub, sub_eq_zero]
theorem IsOrtho.polar_eq_zero {x y : M} (h : IsOrtho Q x y) : polar Q x y = 0 :=
isOrtho_polarBilin.mpr h
@[simp]
theorem associated_isOrtho [Invertible (2 : R)] {x y : M} :
Q.associated.IsOrtho x y ↔ Q.IsOrtho x y := by
simp_rw [isOrtho_def, LinearMap.isOrtho_def, associated_apply, invOf_smul_eq_iff,
smul_zero, sub_sub, sub_eq_zero]
end CommRing
end IsOrtho
section Anisotropic
section Semiring
variable [CommSemiring R] [AddCommMonoid M] [AddCommMonoid N] [Module R M] [Module R N]
/-- An anisotropic quadratic map is zero only on zero vectors. -/
def Anisotropic (Q : QuadraticMap R M N) : Prop :=
∀ x, Q x = 0 → x = 0
theorem not_anisotropic_iff_exists (Q : QuadraticMap R M N) :
¬Anisotropic Q ↔ ∃ x, x ≠ 0 ∧ Q x = 0 := by
simp only [Anisotropic, not_forall, exists_prop, and_comm]
theorem Anisotropic.eq_zero_iff {Q : QuadraticMap R M N} (h : Anisotropic Q) {x : M} :
Q x = 0 ↔ x = 0 :=
⟨h x, fun h => h.symm ▸ map_zero Q⟩
end Semiring
section Ring
variable [CommRing R] [AddCommGroup M] [Module R M]
/-- The associated bilinear form of an anisotropic quadratic form is nondegenerate. -/
theorem separatingLeft_of_anisotropic [Invertible (2 : R)] (Q : QuadraticMap R M R)
(hB : Q.Anisotropic) :
-- Porting note: added implicit argument
(QuadraticMap.associated' (R := R) Q).SeparatingLeft := fun x hx ↦ hB _ <| by
rw [← hx x]
exact (associated_eq_self_apply _ _ x).symm
end Ring
end Anisotropic
section PosDef
variable {R₂ : Type u} [CommSemiring R₂] [AddCommMonoid M] [Module R₂ M]
variable [PartialOrder N] [AddCommMonoid N] [Module R₂ N]
variable {Q₂ : QuadraticMap R₂ M N}
/-- A positive definite quadratic form is positive on nonzero vectors. -/
def PosDef (Q₂ : QuadraticMap R₂ M N) : Prop :=
∀ x, x ≠ 0 → 0 < Q₂ x
theorem PosDef.smul {R} [LinearOrderedCommRing R] [Module R M] [Module R N] [PosSMulStrictMono R N]
{Q : QuadraticMap R M N} (h : PosDef Q) {a : R} (a_pos : 0 < a) : PosDef (a • Q) :=
fun x hx => smul_pos a_pos (h x hx)
variable {n : Type*}
theorem PosDef.nonneg {Q : QuadraticMap R₂ M N} (hQ : PosDef Q) (x : M) : 0 ≤ Q x :=
(eq_or_ne x 0).elim (fun h => h.symm ▸ (map_zero Q).symm.le) fun h => (hQ _ h).le
theorem PosDef.anisotropic {Q : QuadraticMap R₂ M N} (hQ : Q.PosDef) : Q.Anisotropic :=
fun x hQx => by_contradiction fun hx =>
lt_irrefl (0 : N) <| by
have := hQ _ hx
rw [hQx] at this
exact this
theorem posDef_of_nonneg {Q : QuadraticMap R₂ M N} (h : ∀ x, 0 ≤ Q x) (h0 : Q.Anisotropic) :
PosDef Q :=
fun x hx => lt_of_le_of_ne (h x) (Ne.symm fun hQx => hx <| h0 _ hQx)
theorem posDef_iff_nonneg {Q : QuadraticMap R₂ M N} : PosDef Q ↔ (∀ x, 0 ≤ Q x) ∧ Q.Anisotropic :=
⟨fun h => ⟨h.nonneg, h.anisotropic⟩, fun ⟨n, a⟩ => posDef_of_nonneg n a⟩
theorem PosDef.add [CovariantClass N N (· + ·) (· < ·)]
(Q Q' : QuadraticMap R₂ M N) (hQ : PosDef Q) (hQ' : PosDef Q') :
PosDef (Q + Q') :=
fun x hx => add_pos (hQ x hx) (hQ' x hx)
theorem linMulLinSelfPosDef {R} [LinearOrderedCommRing R] [Module R M] [LinearOrderedSemiring A]
[ExistsAddOfLE A] [Module R A] [SMulCommClass R A A] [IsScalarTower R A A] (f : M →ₗ[R] A)
(hf : LinearMap.ker f = ⊥) : PosDef (linMulLin (A := A) f f) :=
fun _x hx => mul_self_pos.2 fun h => hx <| LinearMap.ker_eq_bot'.mp hf _ h
end PosDef
end QuadraticMap
section
/-!
### Quadratic forms and matrices
Connect quadratic forms and matrices, in order to explicitly compute with them.
The convention is twos out, so there might be a factor 2⁻¹ in the entries of the
matrix.
The determinant of the matrix is the discriminant of the quadratic form.
-/
variable {n : Type w} [Fintype n] [DecidableEq n]
variable [CommRing R] [AddCommMonoid M] [Module R M]
/-- `M.toQuadraticMap'` is the map `fun x ↦ row x * M * col x` as a quadratic form. -/
def Matrix.toQuadraticMap' (M : Matrix n n R) : QuadraticMap R (n → R) R :=
LinearMap.BilinMap.toQuadraticMap (Matrix.toLinearMap₂' R M)
variable [Invertible (2 : R)]
/-- A matrix representation of the quadratic form. -/
def QuadraticMap.toMatrix' (Q : QuadraticMap R (n → R) R) : Matrix n n R :=
LinearMap.toMatrix₂' R (associated Q)
open QuadraticMap
theorem QuadraticMap.toMatrix'_smul (a : R) (Q : QuadraticMap R (n → R) R) :
(a • Q).toMatrix' = a • Q.toMatrix' := by
simp only [toMatrix', LinearEquiv.map_smul, LinearMap.map_smul]
theorem QuadraticMap.isSymm_toMatrix' (Q : QuadraticMap R (n → R) R) : Q.toMatrix'.IsSymm := by
ext i j
rw [toMatrix', Matrix.transpose_apply, LinearMap.toMatrix₂'_apply, LinearMap.toMatrix₂'_apply,
← associated_isSymm, RingHom.id_apply, associated_apply]
end
namespace QuadraticMap
variable {n : Type w} [Fintype n]
variable [CommRing R] [DecidableEq n] [Invertible (2 : R)]
variable {m : Type w} [DecidableEq m] [Fintype m]
open Matrix
@[simp]
theorem toMatrix'_comp (Q : QuadraticMap R (m → R) R) (f : (n → R) →ₗ[R] m → R) :
(Q.comp f).toMatrix' = (LinearMap.toMatrix' f)ᵀ * Q.toMatrix' * (LinearMap.toMatrix' f) := by
ext
simp only [QuadraticMap.associated_comp, LinearMap.toMatrix₂'_compl₁₂, toMatrix']
section Discriminant
variable {Q : QuadraticMap R (n → R) R}
/-- The discriminant of a quadratic form generalizes the discriminant of a quadratic polynomial. -/
def discr (Q : QuadraticMap R (n → R) R) : R :=
Q.toMatrix'.det
theorem discr_smul (a : R) : (a • Q).discr = a ^ Fintype.card n * Q.discr := by
simp only [discr, toMatrix'_smul, Matrix.det_smul]
theorem discr_comp (f : (n → R) →ₗ[R] n → R) :
(Q.comp f).discr = f.toMatrix'.det * f.toMatrix'.det * Q.discr := by
simp only [Matrix.det_transpose, mul_left_comm, QuadraticMap.toMatrix'_comp, mul_comm,
Matrix.det_mul, discr]
end Discriminant
end QuadraticMap
namespace QuadraticMap
end QuadraticMap
namespace LinearMap
namespace BilinForm
open LinearMap (BilinMap)
section Semiring
variable [CommSemiring R] [AddCommMonoid M] [Module R M]
/--
A bilinear form is separating left if the quadratic form it is associated with is anisotropic.
-/
theorem separatingLeft_of_anisotropic {B : BilinForm R M} (hB : B.toQuadraticMap.Anisotropic) :
B.SeparatingLeft := fun x hx => hB _ (hx x)
end Semiring
variable [CommRing R] [AddCommGroup M] [Module R M]
/-- There exists a non-null vector with respect to any symmetric, nonzero bilinear form `B`
on a module `M` over a ring `R` with invertible `2`, i.e. there exists some
`x : M` such that `B x x ≠ 0`. -/
theorem exists_bilinForm_self_ne_zero [htwo : Invertible (2 : R)] {B : BilinForm R M}
(hB₁ : B ≠ 0) (hB₂ : B.IsSymm) : ∃ x, ¬B.IsOrtho x x := by
lift B to QuadraticForm R M using hB₂ with Q
obtain ⟨x, hx⟩ := QuadraticMap.exists_quadraticForm_ne_zero hB₁
exact ⟨x, fun h => hx (Q.associated_eq_self_apply ℕ x ▸ h)⟩
open FiniteDimensional
variable {V : Type u} {K : Type v} [Field K] [AddCommGroup V] [Module K V]
variable [FiniteDimensional K V]
/-- Given a symmetric bilinear form `B` on some vector space `V` over a field `K`
in which `2` is invertible, there exists an orthogonal basis with respect to `B`. -/
theorem exists_orthogonal_basis [hK : Invertible (2 : K)] {B : LinearMap.BilinForm K V}
(hB₂ : B.IsSymm) : ∃ v : Basis (Fin (finrank K V)) K V, B.IsOrthoᵢ v := by
induction' hd : finrank K V with d ih generalizing V
· exact ⟨basisOfFinrankZero hd, fun _ _ _ => map_zero _⟩
haveI := finrank_pos_iff.1 (hd.symm ▸ Nat.succ_pos d : 0 < finrank K V)
-- either the bilinear form is trivial or we can pick a non-null `x`
obtain rfl | hB₁ := eq_or_ne B 0
· let b := FiniteDimensional.finBasis K V
rw [hd] at b
exact ⟨b, fun i j _ => rfl⟩
obtain ⟨x, hx⟩ := exists_bilinForm_self_ne_zero hB₁ hB₂
rw [← Submodule.finrank_add_eq_of_isCompl (isCompl_span_singleton_orthogonal hx).symm,
finrank_span_singleton (ne_zero_of_map hx)] at hd
let B' := B.domRestrict₁₂ (Submodule.orthogonalBilin (K ∙ x) B )
(Submodule.orthogonalBilin (K ∙ x) B )
obtain ⟨v', hv₁⟩ := ih (hB₂.domRestrict _ : B'.IsSymm) (Nat.succ.inj hd)
-- concatenate `x` with the basis obtained by induction
let b :=
Basis.mkFinCons x v'
(by
rintro c y hy hc
rw [add_eq_zero_iff_neg_eq] at hc
rw [← hc, Submodule.neg_mem_iff] at hy
have := (isCompl_span_singleton_orthogonal hx).disjoint
rw [Submodule.disjoint_def] at this
have := this (c • x) (Submodule.smul_mem _ _ <| Submodule.mem_span_singleton_self _) hy
exact (smul_eq_zero.1 this).resolve_right fun h => hx <| h.symm ▸ map_zero _)
(by
intro y
refine ⟨-B x y / B x x, fun z hz => ?_⟩
obtain ⟨c, rfl⟩ := Submodule.mem_span_singleton.1 hz
rw [IsOrtho, map_smul, smul_apply, map_add, map_smul, smul_eq_mul, smul_eq_mul,
div_mul_cancel₀ _ hx, add_neg_self, mul_zero])
refine ⟨b, ?_⟩
rw [Basis.coe_mkFinCons]
intro j i
refine Fin.cases ?_ (fun i => ?_) i <;> refine Fin.cases ?_ (fun j => ?_) j <;> intro hij <;>
simp only [Function.onFun, Fin.cons_zero, Fin.cons_succ, Function.comp_apply]
· exact (hij rfl).elim
· rw [IsOrtho, ← hB₂]
exact (v' j).prop _ (Submodule.mem_span_singleton_self x)
· exact (v' i).prop _ (Submodule.mem_span_singleton_self x)
· exact hv₁ (ne_of_apply_ne _ hij)
end BilinForm
end LinearMap
namespace QuadraticMap
open Finset
variable [CommSemiring R] [AddCommMonoid M] [Module R M] [AddCommMonoid N] [Module R N]
variable {ι : Type*}
/-- Given a quadratic map `Q` and a basis, `basisRepr` is the basis representation of `Q`. -/
noncomputable def basisRepr [Finite ι] (Q : QuadraticMap R M N) (v : Basis ι R M) :
QuadraticMap R (ι → R) N :=
Q.comp v.equivFun.symm
@[simp]
theorem basisRepr_apply [Fintype ι] {v : Basis ι R M} (Q : QuadraticMap R M N) (w : ι → R) :
Q.basisRepr v w = Q (∑ i : ι, w i • v i) := by
rw [← v.equivFun_symm_apply]
rfl
variable [Fintype ι] {v : Basis ι R M}
section
variable (R)
/-- The weighted sum of squares with respect to some weight as a quadratic form.
The weights are applied using `•`; typically this definition is used either with `S = R` or
`[Algebra S R]`, although this is stated more generally. -/
def weightedSumSquares [Monoid S] [DistribMulAction S R] [SMulCommClass S R R] (w : ι → S) :
QuadraticMap R (ι → R) R :=
∑ i : ι, w i • (proj (R := R) (n := ι) i i)
end
@[simp]
theorem weightedSumSquares_apply [Monoid S] [DistribMulAction S R] [SMulCommClass S R R]
(w : ι → S) (v : ι → R) :
weightedSumSquares R w v = ∑ i : ι, w i • (v i * v i) :=
QuadraticMap.sum_apply _ _ _
/-- On an orthogonal basis, the basis representation of `Q` is just a sum of squares. -/
theorem basisRepr_eq_of_iIsOrtho {R M} [CommRing R] [AddCommGroup M] [Module R M]
[Invertible (2 : R)] (Q : QuadraticMap R M R) (v : Basis ι R M)
(hv₂ : (associated (R := R) Q).IsOrthoᵢ v) :
Q.basisRepr v = weightedSumSquares _ fun i => Q (v i) := by
ext w
rw [basisRepr_apply, ← @associated_eq_self_apply R, map_sum, weightedSumSquares_apply]
refine sum_congr rfl fun j hj => ?_
rw [← @associated_eq_self_apply R, LinearMap.map_sum₂, sum_eq_single_of_mem j hj]
· rw [LinearMap.map_smul, LinearMap.map_smul₂, smul_eq_mul, associated_apply, smul_eq_mul,
smul_eq_mul, smul_eq_mul]
ring_nf
· intro i _ hij
rw [LinearMap.map_smul, LinearMap.map_smul₂,
show associatedHom R Q (v i) (v j) = 0 from hv₂ hij, smul_eq_mul, smul_eq_mul,
mul_zero, mul_zero]
end QuadraticMap
|
LinearAlgebra\QuadraticForm\Basis.lean | /-
Copyright (c) 2024 Eric Wieser. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Eric Wieser
-/
import Mathlib.LinearAlgebra.QuadraticForm.Basic
/-!
# Constructing a bilinear map from a quadratic map, given a basis
This file provides an alternative to `QuadraticMap.associated`; unlike that definition, this one
does not require `Invertible (2 : R)`. Unlike that definition, this only works in the presence of
a basis.
-/
namespace QuadraticMap
variable {ι R M N} [LinearOrder ι]
variable [CommRing R] [AddCommGroup M] [AddCommGroup N] [Module R M] [Module R N]
/-- Given an ordered basis, produce a bilinear form associated with the quadratic form.
Unlike `QuadraticMap.associated`, this is not symmetric; however, as a result it can be used even
in characteristic two. When considered as a matrix, the form is triangular. -/
noncomputable def toBilin (Q : QuadraticMap R M N) (bm : Basis ι R M) : LinearMap.BilinMap R M N :=
bm.constr (S := R) fun i =>
bm.constr (S := R) fun j =>
if i = j then Q (bm i) else if i < j then polar Q (bm i) (bm j) else 0
theorem toBilin_apply (Q : QuadraticMap R M N) (bm : Basis ι R M) (i j : ι) :
Q.toBilin bm (bm i) (bm j) =
if i = j then Q (bm i) else if i < j then polar Q (bm i) (bm j) else 0 := by
simp [toBilin]
theorem toQuadraticMap_toBilin (Q : QuadraticMap R M N) (bm : Basis ι R M) :
(Q.toBilin bm).toQuadraticMap = Q := by
ext x
rw [← bm.total_repr x, LinearMap.BilinMap.toQuadraticMap_apply, Finsupp.total_apply,
Finsupp.sum]
simp_rw [LinearMap.map_sum₂, map_sum, LinearMap.map_smul₂, _root_.map_smul, toBilin_apply,
smul_ite, smul_zero, ← Finset.sum_product', ← Finset.diag_union_offDiag,
Finset.sum_union (Finset.disjoint_diag_offDiag _), Finset.sum_diag, if_true]
rw [Finset.sum_ite_of_false, QuadraticMap.map_sum, ← Finset.sum_filter]
· simp_rw [← polar_smul_right _ (bm.repr x <| Prod.snd _),
← polar_smul_left _ (bm.repr x <| Prod.fst _)]
simp_rw [QuadraticMap.map_smul, mul_smul, Finset.sum_sym2_filter_not_isDiag]
rfl
· intro x hx
rw [Finset.mem_offDiag] at hx
simpa using hx.2.2
/-- From a free module, every quadratic map can be built from a bilinear form.
See `BilinMap.not_forall_toQuadraticMap_surjective` for a counterexample when the module is
not free. -/
theorem _root_.LinearMap.BilinMap.toQuadraticMap_surjective [Module.Free R M] :
Function.Surjective (LinearMap.BilinMap.toQuadraticMap : LinearMap.BilinMap R M N → _) := by
intro Q
obtain ⟨ι, b⟩ := Module.Free.exists_basis (R := R) (M := M)
letI : LinearOrder ι := IsWellOrder.linearOrder WellOrderingRel
exact ⟨_, toQuadraticMap_toBilin _ b⟩
end QuadraticMap
|
LinearAlgebra\QuadraticForm\Complex.lean | /-
Copyright (c) 2020 Anne Baanen. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Anne Baanen, Kexing Ying, Eric Wieser
-/
import Mathlib.LinearAlgebra.QuadraticForm.IsometryEquiv
import Mathlib.Analysis.SpecialFunctions.Pow.Complex
/-!
# Quadratic forms over the complex numbers
`equivalent_sum_squares`: A nondegenerate quadratic form over the complex numbers is equivalent to
a sum of squares.
-/
namespace QuadraticForm
open Finset
open QuadraticMap
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 (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
have hw' : ∀ i : ι, (w i : ℂ) ^ (-(1 / 2 : ℂ)) ≠ 0 := by
intro i hi
exact (w i).ne_zero ((Complex.cpow_eq_zero_iff _ _).1 hi).1
convert QuadraticMap.isometryEquivBasisRepr (weightedSumSquares ℂ w')
((Pi.basisFun ℂ ι).unitsSMul fun i => (isUnit_iff_ne_zero.2 <| hw' i).unit)
ext1 v
erw [basisRepr_apply, weightedSumSquares_apply, weightedSumSquares_apply]
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]
· intro i _ hij
rw [Pi.basisFun_apply, LinearMap.stdBasis_apply, Pi.smul_apply, Pi.smul_apply,
Function.update_noteq hij.symm, Pi.zero_apply, smul_eq_mul, smul_eq_mul,
mul_zero, mul_zero]
intro hj'; exact False.elim (hj' hj)
simp_rw [Basis.unitsSMul_apply]
erw [hsum, smul_eq_mul]
split_ifs with h
· simp only [h, zero_smul, zero_mul]
have hww' : w' j = w j := by simp only [w, dif_neg h, Units.val_mk0]
simp (config := {zeta := false}) only [one_mul, Units.val_mk0, smul_eq_mul]
rw [hww']
suffices v j * v j = w j ^ (-(1 / 2 : ℂ)) * w j ^ (-(1 / 2 : ℂ)) * w j * v j * v j by
rw [this]; ring
rw [← Complex.cpow_add _ _ (w j).ne_zero, show -(1 / 2 : ℂ) + -(1 / 2) = -1 by simp [← two_mul],
Complex.cpow_neg_one, inv_mul_cancel (w j).ne_zero, one_mul]
/-- 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 (w : ι → Units ℂ) :
IsometryEquiv (weightedSumSquares ℂ w) (weightedSumSquares ℂ (1 : ι → ℂ)) := by
simpa using isometryEquivSumSquares ((↑) ∘ w)
/-- A nondegenerate quadratic form on the complex numbers is equivalent to
the sum of squares, i.e. `weightedSumSquares` with weight `fun (i : ι) => 1`. -/
theorem equivalent_sum_squares {M : Type*} [AddCommGroup M] [Module ℂ M] [FiniteDimensional ℂ M]
(Q : QuadraticForm ℂ M) (hQ : (associated (R := ℂ) Q).SeparatingLeft) :
Equivalent Q (weightedSumSquares ℂ (1 : Fin (FiniteDimensional.finrank ℂ M) → ℂ)) :=
let ⟨w, ⟨hw₁⟩⟩ := Q.equivalent_weightedSumSquares_units_of_nondegenerate' hQ
⟨hw₁.trans (isometryEquivSumSquaresUnits w)⟩
/-- All nondegenerate quadratic forms on the complex numbers are equivalent. -/
theorem complex_equivalent {M : Type*} [AddCommGroup M] [Module ℂ M] [FiniteDimensional ℂ M]
(Q₁ Q₂ : QuadraticForm ℂ M) (hQ₁ : (associated (R := ℂ) Q₁).SeparatingLeft)
(hQ₂ : (associated (R := ℂ) Q₂).SeparatingLeft) : Equivalent Q₁ Q₂ :=
(Q₁.equivalent_sum_squares hQ₁).trans (Q₂.equivalent_sum_squares hQ₂).symm
end QuadraticForm
|
LinearAlgebra\QuadraticForm\Dual.lean | /-
Copyright (c) 2023 Eric Wieser. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Eric Wieser
-/
import Mathlib.LinearAlgebra.QuadraticForm.IsometryEquiv
import Mathlib.LinearAlgebra.QuadraticForm.Prod
import Mathlib.LinearAlgebra.Dual
/-!
# Quadratic form structures related to `Module.Dual`
## Main definitions
* `LinearMap.dualProd R M`, the bilinear form on `(f, x) : Module.Dual R M × M` defined as
`f x`.
* `QuadraticForm.dualProd R M`, the quadratic form on `(f, x) : Module.Dual R M × M` defined as
`f x`.
* `QuadraticForm.toDualProd : (Q.prod <| -Q) →qᵢ QuadraticForm.dualProd R M` a form-preserving map
from `(Q.prod <| -Q)` to `QuadraticForm.dualProd R M`.
-/
variable (R M N : Type*)
namespace LinearMap
section Semiring
variable [CommSemiring R] [AddCommMonoid M] [Module R M]
/-- The symmetric bilinear form on `Module.Dual R M × M` defined as
`B (f, x) (g, y) = f y + g x`. -/
@[simps!]
def dualProd : LinearMap.BilinForm R (Module.Dual R M × M) :=
(applyₗ.comp (snd R (Module.Dual R M) M)).compl₂ (fst R (Module.Dual R M) M) +
((applyₗ.comp (snd R (Module.Dual R M) M)).compl₂ (fst R (Module.Dual R M) M)).flip
theorem isSymm_dualProd : (dualProd R M).IsSymm := fun _x _y => add_comm _ _
end Semiring
section Ring
variable [CommRing R] [AddCommGroup M] [Module R M]
theorem separatingLeft_dualProd :
(dualProd R M).SeparatingLeft ↔ Function.Injective (Module.Dual.eval R M) := by
classical
rw [separatingLeft_iff_ker_eq_bot, ker_eq_bot]
let e := LinearEquiv.prodComm R _ _ ≪≫ₗ Module.dualProdDualEquivDual R (Module.Dual R M) M
let h_d := e.symm.toLinearMap.comp (dualProd R M)
refine (Function.Injective.of_comp_iff e.symm.injective
(dualProd R M)).symm.trans ?_
rw [← LinearEquiv.coe_toLinearMap, ← coe_comp]
change Function.Injective h_d ↔ _
have : h_d = prodMap id (Module.Dual.eval R M) := by
refine ext fun x => Prod.ext ?_ ?_
· ext
dsimp [e, h_d, Module.Dual.eval, LinearEquiv.prodComm]
simp
· ext
dsimp [e, h_d, Module.Dual.eval, LinearEquiv.prodComm]
simp
rw [this, coe_prodMap]
refine Prod.map_injective.trans ?_
exact and_iff_right Function.injective_id
end Ring
end LinearMap
namespace QuadraticForm
open QuadraticMap
section Semiring
variable [CommSemiring R] [AddCommMonoid M] [AddCommMonoid N] [Module R M] [Module R N]
/-- The quadratic form on `Module.Dual R M × M` defined as `Q (f, x) = f x`. -/
@[simps]
def dualProd : QuadraticForm R (Module.Dual R M × M) where
toFun p := p.1 p.2
toFun_smul a p := by
dsimp only -- Porting note: added
rw [Prod.smul_fst, Prod.smul_snd, LinearMap.smul_apply, LinearMap.map_smul, smul_eq_mul,
smul_eq_mul, smul_eq_mul, mul_assoc]
exists_companion' :=
⟨LinearMap.dualProd R M, fun p q => by
dsimp only -- Porting note: added
rw [LinearMap.dualProd_apply_apply, Prod.fst_add, Prod.snd_add, LinearMap.add_apply, map_add,
map_add, add_right_comm _ (q.1 q.2), add_comm (q.1 p.2) (p.1 q.2), ← add_assoc, ←
add_assoc]⟩
@[simp]
theorem _root_.LinearMap.dualProd.toQuadraticForm :
(LinearMap.dualProd R M).toQuadraticMap = 2 • dualProd R M :=
ext fun _a => (two_nsmul _).symm
variable {R M N}
/-- Any module isomorphism induces a quadratic isomorphism between the corresponding `dual_prod.` -/
@[simps!]
def dualProdIsometry (f : M ≃ₗ[R] N) : (dualProd R M).IsometryEquiv (dualProd R N) where
toLinearEquiv := f.dualMap.symm.prod f
map_app' x := DFunLike.congr_arg x.fst <| f.symm_apply_apply _
/-- `QuadraticForm.dualProd` commutes (isometrically) with `QuadraticForm.prod`. -/
@[simps!]
def dualProdProdIsometry :
(dualProd R (M × N)).IsometryEquiv ((dualProd R M).prod (dualProd R N)) where
toLinearEquiv :=
(Module.dualProdDualEquivDual R M N).symm.prod (LinearEquiv.refl R (M × N)) ≪≫ₗ
LinearEquiv.prodProdProdComm R _ _ M N
map_app' m :=
(m.fst.map_add _ _).symm.trans <| DFunLike.congr_arg m.fst <| Prod.ext (add_zero _) (zero_add _)
end Semiring
section Ring
variable [CommRing R] [AddCommGroup M] [Module R M]
variable {R M}
/-- The isometry sending `(Q.prod <| -Q)` to `(QuadraticForm.dualProd R M)`.
This is `σ` from Proposition 4.8, page 84 of
[*Hermitian K-Theory and Geometric Applications*][hyman1973]; though we swap the order of the pairs.
-/
@[simps!]
def toDualProd (Q : QuadraticForm R M) [Invertible (2 : R)] :
(Q.prod <| -Q) →qᵢ QuadraticForm.dualProd R M where
toLinearMap := LinearMap.prod
(Q.associated.comp (LinearMap.fst _ _ _) + Q.associated.comp (LinearMap.snd _ _ _))
(LinearMap.fst _ _ _ - LinearMap.snd _ _ _)
map_app' x := by
dsimp only [associated, associatedHom]
dsimp only [LinearMap.smul_apply, LinearMap.coe_mk, AddHom.coe_mk, AddHom.toFun_eq_coe,
LinearMap.coe_toAddHom, LinearMap.prod_apply, Pi.prod, LinearMap.add_apply,
LinearMap.coe_comp, Function.comp_apply, LinearMap.fst_apply, LinearMap.snd_apply,
LinearMap.sub_apply, dualProd_apply, polarBilin_apply_apply, prod_apply, neg_apply]
simp [polar_comm _ x.1 x.2, ← sub_add, mul_sub, sub_mul, smul_sub, Submonoid.smul_def, ←
sub_eq_add_neg (Q x.1) (Q x.2)]
/-!
TODO: show that `QuadraticForm.toDualProd` is an `QuadraticForm.IsometryEquiv`
-/
end Ring
end QuadraticForm
|
LinearAlgebra\QuadraticForm\Isometry.lean | /-
Copyright (c) 2023 Eric Wieser. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Eric Wieser
-/
import Mathlib.LinearAlgebra.QuadraticForm.Basic
/-!
# Isometric linear maps
## Main definitions
* `QuadraticMap.Isometry`: `LinearMap`s which map between two different quadratic forms
## Notation
`Q₁ →qᵢ Q₂` is notation for `Q₁.Isometry Q₂`.
-/
variable {ι R M M₁ M₂ M₃ M₄ N : Type*}
namespace QuadraticMap
variable [CommSemiring R]
variable [AddCommMonoid M]
variable [AddCommMonoid M₁] [AddCommMonoid M₂] [AddCommMonoid M₃] [AddCommMonoid M₄]
variable [AddCommMonoid N]
variable [Module R M] [Module R M₁] [Module R M₂] [Module R M₃] [Module R M₄] [Module R N]
/-- An isometry between two quadratic spaces `M₁, Q₁` and `M₂, Q₂` over a ring `R`,
is a linear map between `M₁` and `M₂` that commutes with the quadratic forms. -/
structure Isometry (Q₁ : QuadraticMap R M₁ N) (Q₂ : QuadraticMap R M₂ N) extends M₁ →ₗ[R] M₂ where
/-- The quadratic form agrees across the map. -/
map_app' : ∀ m, Q₂ (toFun m) = Q₁ m
namespace Isometry
@[inherit_doc]
notation:25 Q₁ " →qᵢ " Q₂:0 => Isometry Q₁ Q₂
variable {Q₁ : QuadraticMap R M₁ N} {Q₂ : QuadraticMap R M₂ N}
variable {Q₃ : QuadraticMap R M₃ N} {Q₄ : QuadraticMap R M₄ N}
instance instFunLike : FunLike (Q₁ →qᵢ Q₂) M₁ M₂ where
coe f := f.toLinearMap
coe_injective' f g h := by cases f; cases g; congr; exact DFunLike.coe_injective h
instance instLinearMapClass : LinearMapClass (Q₁ →qᵢ Q₂) R M₁ M₂ where
map_add f := f.toLinearMap.map_add
map_smulₛₗ f := f.toLinearMap.map_smul
theorem toLinearMap_injective :
Function.Injective (Isometry.toLinearMap : (Q₁ →qᵢ Q₂) → M₁ →ₗ[R] M₂) := fun _f _g h =>
DFunLike.coe_injective (congr_arg DFunLike.coe h : _)
@[ext]
theorem ext ⦃f g : Q₁ →qᵢ Q₂⦄ (h : ∀ x, f x = g x) : f = g :=
DFunLike.ext _ _ h
/-- See Note [custom simps projection]. -/
protected def Simps.apply (f : Q₁ →qᵢ Q₂) : M₁ → M₂ := f
initialize_simps_projections Isometry (toFun → apply)
@[simp]
theorem map_app (f : Q₁ →qᵢ Q₂) (m : M₁) : Q₂ (f m) = Q₁ m :=
f.map_app' m
@[simp]
theorem coe_toLinearMap (f : Q₁ →qᵢ Q₂) : ⇑f.toLinearMap = f :=
rfl
/-- The identity isometry from a quadratic form to itself. -/
@[simps!]
def id (Q : QuadraticMap R M N) : Q →qᵢ Q where
__ := LinearMap.id
map_app' _ := rfl
/-- The identity isometry between equal quadratic forms. -/
@[simps!]
def ofEq {Q₁ Q₂ : QuadraticMap R M₁ N} (h : Q₁ = Q₂) : Q₁ →qᵢ Q₂ where
__ := LinearMap.id
map_app' _ := h ▸ rfl
@[simp]
theorem ofEq_rfl {Q : QuadraticMap R M₁ N} : ofEq (rfl : Q = Q) = .id Q := rfl
/-- The composition of two isometries between quadratic forms. -/
@[simps]
def comp (g : Q₂ →qᵢ Q₃) (f : Q₁ →qᵢ Q₂) : Q₁ →qᵢ Q₃ where
toFun x := g (f x)
map_app' x := by rw [← f.map_app, ← g.map_app]
__ := (g.toLinearMap : M₂ →ₗ[R] M₃) ∘ₗ (f.toLinearMap : M₁ →ₗ[R] M₂)
@[simp]
theorem toLinearMap_comp (g : Q₂ →qᵢ Q₃) (f : Q₁ →qᵢ Q₂) :
(g.comp f).toLinearMap = g.toLinearMap.comp f.toLinearMap :=
rfl
@[simp]
theorem id_comp (f : Q₁ →qᵢ Q₂) : (id Q₂).comp f = f :=
ext fun _ => rfl
@[simp]
theorem comp_id (f : Q₁ →qᵢ Q₂) : f.comp (id Q₁) = f :=
ext fun _ => rfl
theorem comp_assoc (h : Q₃ →qᵢ Q₄) (g : Q₂ →qᵢ Q₃) (f : Q₁ →qᵢ Q₂) :
(h.comp g).comp f = h.comp (g.comp f) :=
ext fun _ => rfl
/-- There is a zero map from any module with the zero form. -/
instance : Zero ((0 : QuadraticMap R M₁ N) →qᵢ Q₂) where
zero := { (0 : M₁ →ₗ[R] M₂) with map_app' := fun _ => map_zero _ }
/-- There is a zero map from the trivial module. -/
instance hasZeroOfSubsingleton [Subsingleton M₁] : Zero (Q₁ →qᵢ Q₂) where
zero :=
{ (0 : M₁ →ₗ[R] M₂) with
map_app' := fun m => Subsingleton.elim 0 m ▸ (map_zero _).trans (map_zero _).symm }
/-- Maps into the zero module are trivial -/
instance [Subsingleton M₂] : Subsingleton (Q₁ →qᵢ Q₂) :=
⟨fun _ _ => ext fun _ => Subsingleton.elim _ _⟩
end Isometry
end QuadraticMap
|
LinearAlgebra\QuadraticForm\IsometryEquiv.lean | /-
Copyright (c) 2020 Anne Baanen. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kexing Ying, Eric Wieser
-/
import Mathlib.LinearAlgebra.QuadraticForm.Basic
import Mathlib.LinearAlgebra.QuadraticForm.Isometry
/-!
# Isometric equivalences with respect to quadratic forms
## Main definitions
* `QuadraticForm.IsometryEquiv`: `LinearEquiv`s which map between two different quadratic forms
* `QuadraticForm.Equivalent`: propositional version of the above
## Main results
* `equivalent_weighted_sum_squares`: in finite dimensions, any quadratic form is equivalent to a
parametrization of `QuadraticForm.weightedSumSquares`.
-/
variable {ι R K M M₁ M₂ M₃ V N : Type*}
open QuadraticMap
namespace QuadraticMap
variable [CommSemiring R]
variable [AddCommMonoid M] [AddCommMonoid M₁] [AddCommMonoid M₂] [AddCommMonoid M₃]
[AddCommMonoid N]
variable [Module R M] [Module R M₁] [Module R M₂] [Module R M₃] [Module R N]
/-- An isometric equivalence between two quadratic spaces `M₁, Q₁` and `M₂, Q₂` over a ring `R`,
is a linear equivalence between `M₁` and `M₂` that commutes with the quadratic forms. -/
-- Porting note(#5171): linter not ported yet @[nolint has_nonempty_instance]
structure IsometryEquiv (Q₁ : QuadraticMap R M₁ N) (Q₂ : QuadraticMap R M₂ N)
extends M₁ ≃ₗ[R] M₂ where
map_app' : ∀ m, Q₂ (toFun m) = Q₁ m
/-- Two quadratic forms over a ring `R` are equivalent
if there exists an isometric equivalence between them:
a linear equivalence that transforms one quadratic form into the other. -/
def Equivalent (Q₁ : QuadraticMap R M₁ N) (Q₂ : QuadraticMap R M₂ N) : Prop :=
Nonempty (Q₁.IsometryEquiv Q₂)
namespace IsometryEquiv
variable {Q₁ : QuadraticMap R M₁ N} {Q₂ : QuadraticMap R M₂ N} {Q₃ : QuadraticMap R M₃ N}
instance : EquivLike (Q₁.IsometryEquiv Q₂) M₁ M₂ where
coe f := f.toLinearEquiv
inv f := f.toLinearEquiv.symm
left_inv f := f.toLinearEquiv.left_inv
right_inv f := f.toLinearEquiv.right_inv
coe_injective' f g := by cases f; cases g; simp (config := {contextual := true})
instance : LinearEquivClass (Q₁.IsometryEquiv Q₂) R M₁ M₂ where
map_add f := map_add f.toLinearEquiv
map_smulₛₗ f := map_smulₛₗ f.toLinearEquiv
-- Porting note: was `Coe`
instance : CoeOut (Q₁.IsometryEquiv Q₂) (M₁ ≃ₗ[R] M₂) :=
⟨IsometryEquiv.toLinearEquiv⟩
-- Porting note: syntaut
@[simp]
theorem coe_toLinearEquiv (f : Q₁.IsometryEquiv Q₂) : ⇑(f : M₁ ≃ₗ[R] M₂) = f :=
rfl
@[simp]
theorem map_app (f : Q₁.IsometryEquiv Q₂) (m : M₁) : Q₂ (f m) = Q₁ m :=
f.map_app' m
/-- The identity isometric equivalence between a quadratic form and itself. -/
@[refl]
def refl (Q : QuadraticMap R M N) : Q.IsometryEquiv Q :=
{ LinearEquiv.refl R M with map_app' := fun _ => rfl }
/-- The inverse isometric equivalence of an isometric equivalence between two quadratic forms. -/
@[symm]
def symm (f : Q₁.IsometryEquiv Q₂) : Q₂.IsometryEquiv Q₁ :=
{ (f : M₁ ≃ₗ[R] M₂).symm with
map_app' := by intro m; rw [← f.map_app]; congr; exact f.toLinearEquiv.apply_symm_apply m }
/-- The composition of two isometric equivalences between quadratic forms. -/
@[trans]
def trans (f : Q₁.IsometryEquiv Q₂) (g : Q₂.IsometryEquiv Q₃) : Q₁.IsometryEquiv Q₃ :=
{ (f : M₁ ≃ₗ[R] M₂).trans (g : M₂ ≃ₗ[R] M₃) with
map_app' := by intro m; rw [← f.map_app, ← g.map_app]; rfl }
/-- Isometric equivalences are isometric maps -/
@[simps]
def toIsometry (g : Q₁.IsometryEquiv Q₂) : Q₁ →qᵢ Q₂ where
toFun x := g x
__ := g
end IsometryEquiv
namespace Equivalent
variable {Q₁ : QuadraticMap R M₁ N} {Q₂ : QuadraticMap R M₂ N} {Q₃ : QuadraticMap R M₃ N}
@[refl]
theorem refl (Q : QuadraticMap R M N) : Q.Equivalent Q :=
⟨IsometryEquiv.refl Q⟩
@[symm]
theorem symm (h : Q₁.Equivalent Q₂) : Q₂.Equivalent Q₁ :=
h.elim fun f => ⟨f.symm⟩
@[trans]
theorem trans (h : Q₁.Equivalent Q₂) (h' : Q₂.Equivalent Q₃) : Q₁.Equivalent Q₃ :=
h'.elim <| h.elim fun f g => ⟨f.trans g⟩
end Equivalent
/-- A quadratic form composed with a `LinearEquiv` is isometric to itself. -/
def isometryEquivOfCompLinearEquiv (Q : QuadraticMap R M N) (f : M₁ ≃ₗ[R] M) :
Q.IsometryEquiv (Q.comp (f : M₁ →ₗ[R] M)) :=
{ f.symm with
map_app' := by
intro
simp only [comp_apply, LinearEquiv.coe_coe, LinearEquiv.toFun_eq_coe,
LinearEquiv.apply_symm_apply, f.apply_symm_apply] }
variable [Finite ι]
/-- A quadratic form is isometrically equivalent to its bases representations. -/
noncomputable def isometryEquivBasisRepr (Q : QuadraticMap R M N) (v : Basis ι R M) :
IsometryEquiv Q (Q.basisRepr v) :=
isometryEquivOfCompLinearEquiv Q v.equivFun.symm
end QuadraticMap
namespace QuadraticForm
variable [Field K] [Invertible (2 : K)] [AddCommGroup V] [Module K V]
/-- Given an orthogonal basis, a quadratic form is isometrically equivalent with a weighted sum of
squares. -/
noncomputable def isometryEquivWeightedSumSquares (Q : QuadraticForm K V)
(v : Basis (Fin (FiniteDimensional.finrank K V)) K V)
(hv₁ : (associated (R := K) Q).IsOrthoᵢ v) :
Q.IsometryEquiv (weightedSumSquares K fun i => Q (v i)) := by
let iso := Q.isometryEquivBasisRepr v
refine ⟨iso, fun m => ?_⟩
convert iso.map_app m
rw [basisRepr_eq_of_iIsOrtho _ _ hv₁]
variable [FiniteDimensional K V]
open LinearMap.BilinForm
theorem equivalent_weightedSumSquares (Q : QuadraticForm K V) :
∃ w : Fin (FiniteDimensional.finrank K V) → K, Equivalent Q (weightedSumSquares K w) :=
let ⟨v, hv₁⟩ := exists_orthogonal_basis (associated_isSymm _ Q)
⟨_, ⟨Q.isometryEquivWeightedSumSquares v hv₁⟩⟩
theorem equivalent_weightedSumSquares_units_of_nondegenerate' (Q : QuadraticForm K V)
(hQ : (associated (R := K) Q).SeparatingLeft) :
∃ w : Fin (FiniteDimensional.finrank K V) → Kˣ, Equivalent Q (weightedSumSquares K w) := by
obtain ⟨v, hv₁⟩ := exists_orthogonal_basis (associated_isSymm K Q)
have hv₂ := hv₁.not_isOrtho_basis_self_of_separatingLeft hQ
simp_rw [LinearMap.IsOrtho, associated_eq_self_apply] at hv₂
exact ⟨fun i => Units.mk0 _ (hv₂ i), ⟨Q.isometryEquivWeightedSumSquares v hv₁⟩⟩
end QuadraticForm
|
LinearAlgebra\QuadraticForm\Prod.lean | /-
Copyright (c) 2021 Eric Wieser. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Eric Wieser
-/
import Mathlib.LinearAlgebra.QuadraticForm.IsometryEquiv
/-! # Quadratic form on product and pi types
## Main definitions
* `QuadraticForm.prod Q₁ Q₂`: the quadratic form constructed elementwise on a product
* `QuadraticForm.pi Q`: the quadratic form constructed elementwise on a pi type
## Main results
* `QuadraticForm.Equivalent.prod`, `QuadraticForm.Equivalent.pi`: quadratic forms are equivalent
if their components are equivalent
* `QuadraticForm.nonneg_prod_iff`, `QuadraticForm.nonneg_pi_iff`: quadratic forms are positive-
semidefinite if and only if their components are positive-semidefinite.
* `QuadraticForm.posDef_prod_iff`, `QuadraticForm.posDef_pi_iff`: quadratic forms are positive-
definite if and only if their components are positive-definite.
## Implementation notes
Many of the lemmas in this file could be generalized into results about sums of positive and
non-negative elements, and would generalize to any map `Q` where `Q 0 = 0`, not just quadratic
forms specifically.
-/
universe u v w
variable {ι : Type*} {R : Type*} {M₁ M₂ N₁ N₂ P : Type*} {Mᵢ Nᵢ : ι → Type*}
namespace QuadraticMap
open QuadraticMap
section Prod
section Semiring
variable [CommSemiring R]
variable [AddCommMonoid M₁] [AddCommMonoid M₂] [AddCommMonoid N₁] [AddCommMonoid N₂]
variable [AddCommMonoid P]
variable [Module R M₁] [Module R M₂] [Module R N₁] [Module R N₂] [Module R P]
/-- Construct a quadratic form on a product of two modules from the quadratic form on each module.
-/
@[simps!]
def prod (Q₁ : QuadraticMap R M₁ P) (Q₂ : QuadraticMap R M₂ P) : QuadraticMap R (M₁ × M₂) P :=
Q₁.comp (LinearMap.fst _ _ _) + Q₂.comp (LinearMap.snd _ _ _)
/-- An isometry between quadratic forms generated by `QuadraticForm.prod` can be constructed
from a pair of isometries between the left and right parts. -/
@[simps toLinearEquiv]
def IsometryEquiv.prod
{Q₁ : QuadraticMap R M₁ P} {Q₂ : QuadraticMap R M₂ P}
{Q₁' : QuadraticMap R N₁ P} {Q₂' : QuadraticMap R N₂ P}
(e₁ : Q₁.IsometryEquiv Q₁') (e₂ : Q₂.IsometryEquiv Q₂') :
(Q₁.prod Q₂).IsometryEquiv (Q₁'.prod Q₂') where
map_app' x := congr_arg₂ (· + ·) (e₁.map_app x.1) (e₂.map_app x.2)
toLinearEquiv := LinearEquiv.prod e₁.toLinearEquiv e₂.toLinearEquiv
/-- `LinearMap.inl` as an isometry. -/
@[simps!]
def Isometry.inl (Q₁ : QuadraticMap R M₁ P) (Q₂ : QuadraticMap R M₂ P) : Q₁ →qᵢ (Q₁.prod Q₂) where
toLinearMap := LinearMap.inl R _ _
map_app' m₁ := by simp
/-- `LinearMap.inr` as an isometry. -/
@[simps!]
def Isometry.inr (Q₁ : QuadraticMap R M₁ P) (Q₂ : QuadraticMap R M₂ P) : Q₂ →qᵢ (Q₁.prod Q₂) where
toLinearMap := LinearMap.inr R _ _
map_app' m₁ := by simp
variable (M₂) in
/-- `LinearMap.fst` as an isometry, when the second space has the zero quadratic form. -/
@[simps!]
def Isometry.fst (Q₁ : QuadraticMap R M₁ P) : (Q₁.prod (0 : QuadraticMap R M₂ P)) →qᵢ Q₁ where
toLinearMap := LinearMap.fst R _ _
map_app' m₁ := by simp
variable (M₁) in
/-- `LinearMap.snd` as an isometry, when the first space has the zero quadratic form. -/
@[simps!]
def Isometry.snd (Q₂ : QuadraticMap R M₂ P) : ((0 : QuadraticMap R M₁ P).prod Q₂) →qᵢ Q₂ where
toLinearMap := LinearMap.snd R _ _
map_app' m₁ := by simp
@[simp]
lemma Isometry.fst_comp_inl (Q₁ : QuadraticMap R M₁ P) :
(fst M₂ Q₁).comp (inl Q₁ (0 : QuadraticMap R M₂ P)) = .id _ :=
ext fun _ => rfl
@[simp]
lemma Isometry.snd_comp_inr (Q₂ : QuadraticMap R M₂ P) :
(snd M₁ Q₂).comp (inr (0 : QuadraticMap R M₁ P) Q₂) = .id _ :=
ext fun _ => rfl
@[simp]
lemma Isometry.snd_comp_inl (Q₂ : QuadraticMap R M₂ P) :
(snd M₁ Q₂).comp (inl (0 : QuadraticMap R M₁ P) Q₂) = 0 :=
ext fun _ => rfl
@[simp]
lemma Isometry.fst_comp_inr (Q₁ : QuadraticMap R M₁ P) :
(fst M₂ Q₁).comp (inr Q₁ (0 : QuadraticMap R M₂ P)) = 0 :=
ext fun _ => rfl
theorem Equivalent.prod {Q₁ : QuadraticMap R M₁ P} {Q₂ : QuadraticMap R M₂ P}
{Q₁' : QuadraticMap R N₁ P} {Q₂' : QuadraticMap R N₂ P} (e₁ : Q₁.Equivalent Q₁')
(e₂ : Q₂.Equivalent Q₂') : (Q₁.prod Q₂).Equivalent (Q₁'.prod Q₂') :=
Nonempty.map2 IsometryEquiv.prod e₁ e₂
/-- `LinearEquiv.prodComm` is isometric. -/
@[simps!]
def IsometryEquiv.prodComm (Q₁ : QuadraticMap R M₁ P) (Q₂ : QuadraticMap R M₂ P) :
(Q₁.prod Q₂).IsometryEquiv (Q₂.prod Q₁) where
toLinearEquiv := LinearEquiv.prodComm _ _ _
map_app' _ := add_comm _ _
/-- `LinearEquiv.prodProdProdComm` is isometric. -/
@[simps!]
def IsometryEquiv.prodProdProdComm
(Q₁ : QuadraticMap R M₁ P) (Q₂ : QuadraticMap R M₂ P)
(Q₃ : QuadraticMap R N₁ P) (Q₄ : QuadraticMap R N₂ P) :
((Q₁.prod Q₂).prod (Q₃.prod Q₄)).IsometryEquiv ((Q₁.prod Q₃).prod (Q₂.prod Q₄)) where
toLinearEquiv := LinearEquiv.prodProdProdComm _ _ _ _ _
map_app' _ := add_add_add_comm _ _ _ _
/-- If a product is anisotropic then its components must be. The converse is not true. -/
theorem anisotropic_of_prod
{Q₁ : QuadraticMap R M₁ P} {Q₂ : QuadraticMap R M₂ P} (h : (Q₁.prod Q₂).Anisotropic) :
Q₁.Anisotropic ∧ Q₂.Anisotropic := by
simp_rw [Anisotropic, prod_apply, Prod.forall, Prod.mk_eq_zero] at h
constructor
· intro x hx
refine (h x 0 ?_).1
rw [hx, zero_add, map_zero]
· intro x hx
refine (h 0 x ?_).2
rw [hx, add_zero, map_zero]
theorem nonneg_prod_iff [Preorder P] [CovariantClass P P (· + ·) (· ≤ ·)]
{Q₁ : QuadraticMap R M₁ P} {Q₂ : QuadraticMap R M₂ P} :
(∀ x, 0 ≤ (Q₁.prod Q₂) x) ↔ (∀ x, 0 ≤ Q₁ x) ∧ ∀ x, 0 ≤ Q₂ x := by
simp_rw [Prod.forall, prod_apply]
constructor
· intro h
constructor
· intro x; simpa only [add_zero, map_zero] using h x 0
· intro x; simpa only [zero_add, map_zero] using h 0 x
· rintro ⟨h₁, h₂⟩ x₁ x₂
exact add_nonneg (h₁ x₁) (h₂ x₂)
theorem posDef_prod_iff [PartialOrder P] [CovariantClass P P (· + ·) (· ≤ ·)]
{Q₁ : QuadraticMap R M₁ P} {Q₂ : QuadraticMap R M₂ P} :
(Q₁.prod Q₂).PosDef ↔ Q₁.PosDef ∧ Q₂.PosDef := by
simp_rw [posDef_iff_nonneg, nonneg_prod_iff]
constructor
· rintro ⟨⟨hle₁, hle₂⟩, ha⟩
obtain ⟨ha₁, ha₂⟩ := anisotropic_of_prod ha
exact ⟨⟨hle₁, ha₁⟩, ⟨hle₂, ha₂⟩⟩
· rintro ⟨⟨hle₁, ha₁⟩, ⟨hle₂, ha₂⟩⟩
refine ⟨⟨hle₁, hle₂⟩, ?_⟩
rintro ⟨x₁, x₂⟩ (hx : Q₁ x₁ + Q₂ x₂ = 0)
rw [add_eq_zero_iff' (hle₁ x₁) (hle₂ x₂), ha₁.eq_zero_iff, ha₂.eq_zero_iff] at hx
rwa [Prod.mk_eq_zero]
theorem PosDef.prod [PartialOrder P] [CovariantClass P P (· + ·) (· ≤ ·)]
{Q₁ : QuadraticMap R M₁ P} {Q₂ : QuadraticMap R M₂ P} (h₁ : Q₁.PosDef) (h₂ : Q₂.PosDef) :
(Q₁.prod Q₂).PosDef :=
posDef_prod_iff.mpr ⟨h₁, h₂⟩
theorem IsOrtho.prod {Q₁ : QuadraticMap R M₁ P} {Q₂ : QuadraticMap R M₂ P}
{v w : M₁ × M₂} (h₁ : Q₁.IsOrtho v.1 w.1) (h₂ : Q₂.IsOrtho v.2 w.2) :
(Q₁.prod Q₂).IsOrtho v w :=
(congr_arg₂ HAdd.hAdd h₁ h₂).trans <| add_add_add_comm _ _ _ _
@[simp] theorem IsOrtho.inl_inr {Q₁ : QuadraticMap R M₁ P} {Q₂ : QuadraticMap R M₂ P}
(m₁ : M₁) (m₂ : M₂) :
(Q₁.prod Q₂).IsOrtho (m₁, 0) (0, m₂) :=
QuadraticMap.IsOrtho.prod (.zero_right _) (.zero_left _)
@[simp] theorem IsOrtho.inr_inl {Q₁ : QuadraticMap R M₁ P} {Q₂ : QuadraticMap R M₂ P}
(m₁ : M₁) (m₂ : M₂) :
(Q₁.prod Q₂).IsOrtho (0, m₂) (m₁, 0) := (IsOrtho.inl_inr _ _).symm
@[simp] theorem isOrtho_inl_inl_iff {Q₁ : QuadraticMap R M₁ P} {Q₂ : QuadraticMap R M₂ P}
(m₁ m₁' : M₁) :
(Q₁.prod Q₂).IsOrtho (m₁, 0) (m₁', 0) ↔ Q₁.IsOrtho m₁ m₁' := by
simp [isOrtho_def]
@[simp] theorem isOrtho_inr_inr_iff {Q₁ : QuadraticMap R M₁ P} {Q₂ : QuadraticMap R M₂ P}
(m₂ m₂' : M₂) :
(Q₁.prod Q₂).IsOrtho (0, m₂) (0, m₂') ↔ Q₂.IsOrtho m₂ m₂' := by
simp [isOrtho_def]
end Semiring
section Ring
variable [CommRing R]
variable [AddCommGroup M₁] [AddCommGroup M₂] [AddCommGroup P]
variable [Module R M₁] [Module R M₂] [Module R P]
@[simp] theorem polar_prod (Q₁ : QuadraticMap R M₁ P) (Q₂ : QuadraticMap R M₂ P) (x y : M₁ × M₂) :
polar (Q₁.prod Q₂) x y = polar Q₁ x.1 y.1 + polar Q₂ x.2 y.2 := by
dsimp [polar]
abel
@[simp] theorem polarBilin_prod (Q₁ : QuadraticMap R M₁ P) (Q₂ : QuadraticMap R M₂ P) :
(Q₁.prod Q₂).polarBilin =
Q₁.polarBilin.compl₁₂ (.fst R M₁ M₂) (.fst R M₁ M₂) +
Q₂.polarBilin.compl₁₂ (.snd R M₁ M₂) (.snd R M₁ M₂) :=
LinearMap.ext₂ <| polar_prod _ _
@[simp] theorem associated_prod [Invertible (2 : R)]
(Q₁ : QuadraticMap R M₁ P) (Q₂ : QuadraticMap R M₂ P) :
associated (Q₁.prod Q₂) =
(associated Q₁).compl₁₂ (.fst R M₁ M₂) (.fst R M₁ M₂) +
(associated Q₂).compl₁₂ (.snd R M₁ M₂) (.snd R M₁ M₂) := by
dsimp [associated, associatedHom]
rw [polarBilin_prod, smul_add]
rfl
end Ring
end Prod
section Pi
section Semiring
variable [CommSemiring R]
variable [∀ i, AddCommMonoid (Mᵢ i)] [∀ i, AddCommMonoid (Nᵢ i)] [AddCommMonoid P]
variable [∀ i, Module R (Mᵢ i)] [∀ i, Module R (Nᵢ i)] [Module R P]
/-- Construct a quadratic form on a family of modules from the quadratic form on each module. -/
def pi [Fintype ι] (Q : ∀ i, QuadraticMap R (Mᵢ i) P) : QuadraticMap R (∀ i, Mᵢ i) P :=
∑ i, (Q i).comp (LinearMap.proj i : _ →ₗ[R] Mᵢ i)
@[simp]
theorem pi_apply [Fintype ι] (Q : ∀ i, QuadraticMap R (Mᵢ i) P) (x : ∀ i, Mᵢ i) :
pi Q x = ∑ i, Q i (x i) :=
sum_apply _ _ _
theorem pi_apply_single [Fintype ι] [DecidableEq ι]
(Q : ∀ i, QuadraticMap R (Mᵢ i) P) (i : ι) (m : Mᵢ i) :
pi Q (Pi.single i m) = Q i m := by
rw [pi_apply, Fintype.sum_eq_single i fun j hj => ?_, Pi.single_eq_same]
rw [Pi.single_eq_of_ne hj, map_zero]
/-- An isometry between quadratic forms generated by `QuadraticMap.pi` can be constructed
from a pair of isometries between the left and right parts. -/
@[simps toLinearEquiv]
def IsometryEquiv.pi [Fintype ι]
{Q : ∀ i, QuadraticMap R (Mᵢ i) P} {Q' : ∀ i, QuadraticMap R (Nᵢ i) P}
(e : ∀ i, (Q i).IsometryEquiv (Q' i)) : (pi Q).IsometryEquiv (pi Q') where
map_app' x := by
simp only [pi_apply, LinearEquiv.piCongrRight, LinearEquiv.toFun_eq_coe,
IsometryEquiv.coe_toLinearEquiv, IsometryEquiv.map_app]
toLinearEquiv := LinearEquiv.piCongrRight fun i => (e i : Mᵢ i ≃ₗ[R] Nᵢ i)
/-- `LinearMap.single` as an isometry. -/
@[simps!]
def Isometry.single [Fintype ι] [DecidableEq ι] (Q : ∀ i, QuadraticMap R (Mᵢ i) P) (i : ι) :
Q i →qᵢ pi Q where
toLinearMap := LinearMap.single i
map_app' := pi_apply_single _ _
/-- `LinearMap.proj` as an isometry, when all but one quadratic form is zero. -/
@[simps!]
def Isometry.proj [Fintype ι] [DecidableEq ι] (i : ι) (Q : QuadraticMap R (Mᵢ i) P) :
pi (Pi.single i Q) →qᵢ Q where
toLinearMap := LinearMap.proj i
map_app' m := by
dsimp
rw [pi_apply, Fintype.sum_eq_single i (fun j hij => ?_), Pi.single_eq_same]
rw [Pi.single_eq_of_ne hij, zero_apply]
/-- Note that `QuadraticMap.Isometry.id` would not be well-typed as the RHS. -/
@[simp, nolint simpNF] -- ignore the bogus "Left-hand side does not simplify" lint error
theorem Isometry.proj_comp_single_of_same [Fintype ι] [DecidableEq ι]
(i : ι) (Q : QuadraticMap R (Mᵢ i) P) :
(proj i Q).comp (single _ i) = .ofEq (Pi.single_eq_same _ _) :=
ext fun _ => Pi.single_eq_same _ _
/-- Note that `0 : 0 →qᵢ Q` alone would not be well-typed as the RHS. -/
@[simp]
theorem Isometry.proj_comp_single_of_ne [Fintype ι] [DecidableEq ι]
{i j : ι} (h : i ≠ j) (Q : QuadraticMap R (Mᵢ i) P) :
(proj i Q).comp (single _ j) = (0 : 0 →qᵢ Q).comp (ofEq (Pi.single_eq_of_ne h.symm _)) :=
ext fun _ => Pi.single_eq_of_ne h _
theorem Equivalent.pi [Fintype ι] {Q : ∀ i, QuadraticMap R (Mᵢ i) P}
{Q' : ∀ i, QuadraticMap R (Nᵢ i) P} (e : ∀ i, (Q i).Equivalent (Q' i)) :
(pi Q).Equivalent (pi Q') :=
⟨IsometryEquiv.pi fun i => Classical.choice (e i)⟩
/-- If a family is anisotropic then its components must be. The converse is not true. -/
theorem anisotropic_of_pi [Fintype ι]
{Q : ∀ i, QuadraticMap R (Mᵢ i) P} (h : (pi Q).Anisotropic) : ∀ i, (Q i).Anisotropic := by
simp_rw [Anisotropic, pi_apply, Function.funext_iff, Pi.zero_apply] at h
intro i x hx
classical
have := h (Pi.single i x) ?_ i
· rw [Pi.single_eq_same] at this
exact this
apply Finset.sum_eq_zero
intro j _
by_cases hji : j = i
· subst hji; rw [Pi.single_eq_same, hx]
· rw [Pi.single_eq_of_ne hji, map_zero]
theorem nonneg_pi_iff {P} [Fintype ι] [OrderedAddCommMonoid P] [Module R P]
{Q : ∀ i, QuadraticMap R (Mᵢ i) P} : (∀ x, 0 ≤ pi Q x) ↔ ∀ i x, 0 ≤ Q i x := by
simp_rw [pi, sum_apply, comp_apply, LinearMap.proj_apply]
constructor
-- TODO: does this generalize to a useful lemma independent of `QuadraticMap`?
· intro h i x
classical
convert h (Pi.single i x) using 1
rw [Finset.sum_eq_single_of_mem i (Finset.mem_univ _) fun j _ hji => ?_, Pi.single_eq_same]
rw [Pi.single_eq_of_ne hji, map_zero]
· rintro h x
exact Finset.sum_nonneg fun i _ => h i (x i)
theorem posDef_pi_iff {P} [Fintype ι] [OrderedAddCommMonoid P] [Module R P]
{Q : ∀ i, QuadraticMap R (Mᵢ i) P} : (pi Q).PosDef ↔ ∀ i, (Q i).PosDef := by
simp_rw [posDef_iff_nonneg, nonneg_pi_iff]
constructor
· rintro ⟨hle, ha⟩
intro i
exact ⟨hle i, anisotropic_of_pi ha i⟩
· intro h
refine ⟨fun i => (h i).1, fun x hx => funext fun i => (h i).2 _ ?_⟩
rw [pi_apply, Finset.sum_eq_zero_iff_of_nonneg fun j _ => ?_] at hx
· exact hx _ (Finset.mem_univ _)
exact (h j).1 _
end Semiring
namespace Ring
variable [CommRing R]
variable [∀ i, AddCommGroup (Mᵢ i)] [∀ i, AddCommGroup (Nᵢ i)] [AddCommGroup P]
variable [∀ i, Module R (Mᵢ i)] [∀ i, Module R (Nᵢ i)] [Module R P]
variable [Fintype ι]
@[simp] theorem polar_pi (Q : ∀ i, QuadraticMap R (Mᵢ i) P) (x y : ∀ i, Mᵢ i) :
polar (pi Q) x y = ∑ i, polar (Q i) (x i) (y i) := by
dsimp [polar]
simp_rw [Finset.sum_sub_distrib, pi_apply, Pi.add_apply]
@[simp] theorem polarBilin_pi (Q : ∀ i, QuadraticMap R (Mᵢ i) P) :
(pi Q).polarBilin = ∑ i, (Q i).polarBilin.compl₁₂ (.proj i) (.proj i) :=
LinearMap.ext₂ fun x y => (polar_pi _ _ _).trans <| by simp
@[simp] theorem associated_pi [Invertible (2 : R)] (Q : ∀ i, QuadraticMap R (Mᵢ i) P) :
associated (pi Q) = ∑ i, (Q i).associated.compl₁₂ (.proj i) (.proj i) := by
dsimp [associated, associatedHom]
rw [polarBilin_pi, Finset.smul_sum]
rfl
end Ring
end Pi
end QuadraticMap
|
LinearAlgebra\QuadraticForm\QuadraticModuleCat.lean | /-
Copyright (c) 2023 Eric Wieser. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Eric Wieser
-/
import Mathlib.LinearAlgebra.QuadraticForm.IsometryEquiv
import Mathlib.Algebra.Category.ModuleCat.Basic
/-!
# The category of quadratic modules
-/
open CategoryTheory
universe v u
variable (R : Type u) [CommRing R]
/-- The category of quadratic modules; modules with an associated quadratic form-/
structure QuadraticModuleCat extends ModuleCat.{v} R where
/-- The quadratic form associated with the module. -/
form : QuadraticForm R carrier
variable {R}
namespace QuadraticModuleCat
open QuadraticForm
open QuadraticMap
instance : CoeSort (QuadraticModuleCat.{v} R) (Type v) :=
⟨(·.carrier)⟩
@[simp] theorem moduleCat_of_toModuleCat (X : QuadraticModuleCat.{v} R) :
ModuleCat.of R X.toModuleCat = X.toModuleCat :=
rfl
/-- The object in the category of quadratic R-modules associated to a quadratic R-module. -/
@[simps form]
def of {X : Type v} [AddCommGroup X] [Module R X] (Q : QuadraticForm R X) :
QuadraticModuleCat R where
form := Q
/-- A type alias for `QuadraticForm.LinearIsometry` to avoid confusion between the categorical and
algebraic spellings of composition. -/
@[ext]
structure Hom (V W : QuadraticModuleCat.{v} R) :=
/-- The underlying isometry -/
toIsometry : V.form →qᵢ W.form
lemma Hom.toIsometry_injective (V W : QuadraticModuleCat.{v} R) :
Function.Injective (Hom.toIsometry : Hom V W → _) :=
fun ⟨f⟩ ⟨g⟩ _ => by congr
instance category : Category (QuadraticModuleCat.{v} R) where
Hom M N := Hom M N
id M := ⟨Isometry.id M.form⟩
comp f g := ⟨Isometry.comp g.toIsometry f.toIsometry⟩
id_comp g := Hom.ext <| Isometry.id_comp g.toIsometry
comp_id f := Hom.ext <| Isometry.comp_id f.toIsometry
assoc f g h := Hom.ext <| Isometry.comp_assoc h.toIsometry g.toIsometry f.toIsometry
-- TODO: if `Quiver.Hom` and the instance above were `reducible`, this wouldn't be needed.
@[ext]
lemma hom_ext {M N : QuadraticModuleCat.{v} R} (f g : M ⟶ N) (h : f.toIsometry = g.toIsometry) :
f = g :=
Hom.ext h
/-- Typecheck a `QuadraticForm.Isometry` as a morphism in `Module R`. -/
abbrev ofHom {X : Type v} [AddCommGroup X] [Module R X]
{Q₁ : QuadraticForm R X} {Q₂ : QuadraticForm R X} (f : Q₁ →qᵢ Q₂) :
of Q₁ ⟶ of Q₂ :=
⟨f⟩
@[simp] theorem toIsometry_comp {M N U : QuadraticModuleCat.{v} R} (f : M ⟶ N) (g : N ⟶ U) :
(f ≫ g).toIsometry = g.toIsometry.comp f.toIsometry :=
rfl
@[simp] theorem toIsometry_id {M : QuadraticModuleCat.{v} R} :
Hom.toIsometry (𝟙 M) = Isometry.id _ :=
rfl
instance concreteCategory : ConcreteCategory.{v} (QuadraticModuleCat.{v} R) where
forget :=
{ obj := fun M => M
map := fun f => f.toIsometry }
forget_faithful :=
{ map_injective := fun {M N} => DFunLike.coe_injective.comp <| Hom.toIsometry_injective _ _ }
instance hasForgetToModule : HasForget₂ (QuadraticModuleCat R) (ModuleCat R) where
forget₂ :=
{ obj := fun M => ModuleCat.of R M
map := fun f => f.toIsometry.toLinearMap }
@[simp]
theorem forget₂_obj (X : QuadraticModuleCat R) :
(forget₂ (QuadraticModuleCat R) (ModuleCat R)).obj X = ModuleCat.of R X :=
rfl
@[simp]
theorem forget₂_map (X Y : QuadraticModuleCat R) (f : X ⟶ Y) :
(forget₂ (QuadraticModuleCat R) (ModuleCat R)).map f = f.toIsometry.toLinearMap :=
rfl
variable {X Y Z : Type v}
variable [AddCommGroup X] [Module R X] [AddCommGroup Y] [Module R Y] [AddCommGroup Z] [Module R Z]
variable {Q₁ : QuadraticForm R X} {Q₂ : QuadraticForm R Y} {Q₃ : QuadraticForm R Z}
/-- Build an isomorphism in the category `QuadraticModuleCat R` from a
`QuadraticForm.IsometryEquiv`. -/
@[simps]
def ofIso (e : Q₁.IsometryEquiv Q₂) : QuadraticModuleCat.of Q₁ ≅ QuadraticModuleCat.of Q₂ where
hom := ⟨e.toIsometry⟩
inv := ⟨e.symm.toIsometry⟩
hom_inv_id := Hom.ext <| DFunLike.ext _ _ e.left_inv
inv_hom_id := Hom.ext <| DFunLike.ext _ _ e.right_inv
@[simp] theorem ofIso_refl : ofIso (IsometryEquiv.refl Q₁) = .refl _ :=
rfl
@[simp] theorem ofIso_symm (e : Q₁.IsometryEquiv Q₂) : ofIso e.symm = (ofIso e).symm :=
rfl
@[simp] theorem ofIso_trans (e : Q₁.IsometryEquiv Q₂) (f : Q₂.IsometryEquiv Q₃) :
ofIso (e.trans f) = ofIso e ≪≫ ofIso f :=
rfl
end QuadraticModuleCat
namespace CategoryTheory.Iso
open QuadraticForm
variable {X Y Z : QuadraticModuleCat.{v} R}
/-- Build a `QuadraticForm.IsometryEquiv` from an isomorphism in the category
`QuadraticModuleCat R`. -/
@[simps]
def toIsometryEquiv (i : X ≅ Y) : X.form.IsometryEquiv Y.form where
toFun := i.hom.toIsometry
invFun := i.inv.toIsometry
left_inv x := by
change (i.hom ≫ i.inv).toIsometry x = x
simp
right_inv x := by
change (i.inv ≫ i.hom).toIsometry x = x
simp
map_add' := map_add _
map_smul' := map_smul _
map_app' := QuadraticMap.Isometry.map_app _
@[simp] theorem toIsometryEquiv_refl : toIsometryEquiv (.refl X) = .refl _ :=
rfl
@[simp] theorem toIsometryEquiv_symm (e : X ≅ Y) :
toIsometryEquiv e.symm = (toIsometryEquiv e).symm :=
rfl
@[simp] theorem toIsometryEquiv_trans (e : X ≅ Y) (f : Y ≅ Z) :
toIsometryEquiv (e ≪≫ f) = e.toIsometryEquiv.trans f.toIsometryEquiv :=
rfl
end CategoryTheory.Iso
|
LinearAlgebra\QuadraticForm\Real.lean | /-
Copyright (c) 2020 Anne Baanen. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Anne Baanen, Kexing Ying, Eric Wieser
-/
import Mathlib.LinearAlgebra.QuadraticForm.IsometryEquiv
import Mathlib.Data.Sign
import Mathlib.Algebra.CharP.Invertible
import Mathlib.Analysis.RCLike.Basic
import Mathlib.Data.Complex.Abs
/-!
# Real quadratic forms
Sylvester's law of inertia `equivalent_one_neg_one_weighted_sum_squared`:
A real quadratic form is equivalent to a weighted
sum of squares with the weights being ±1 or 0.
When the real quadratic form is nondegenerate we can take the weights to be ±1,
as in `equivalent_one_zero_neg_one_weighted_sum_squared`.
-/
namespace QuadraticForm
open Finset SignType
open QuadraticMap
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 (w : ι → ℝ) :
IsometryEquiv (weightedSumSquares ℝ w)
(weightedSumSquares ℝ (fun i ↦ (sign (w i) : ℝ))) := by
let u i := if h : w i = 0 then (1 : ℝˣ) else Units.mk0 (w i) h
have hu : ∀ i : ι, 1 / √|(u i : ℝ)| ≠ 0 := fun i ↦
have : (u i : ℝ) ≠ 0 := (u i).ne_zero
by positivity
have hwu : ∀ i, w i / |(u i : ℝ)| = sign (w i) := fun i ↦ by
by_cases hi : w i = 0 <;> field_simp [hi, u]
convert QuadraticMap.isometryEquivBasisRepr (weightedSumSquares ℝ w)
((Pi.basisFun ℝ ι).unitsSMul fun i => .mk0 _ (hu i))
ext1 v
classical
suffices ∑ i, (w i / |(u i : ℝ)|) * v i ^ 2 = ∑ i, w i * (v i ^ 2 * |(u i : ℝ)|⁻¹) by
simpa [basisRepr_apply, Basis.unitsSMul_apply, ← _root_.sq, mul_pow, ← hwu]
exact sum_congr rfl fun j _ ↦ by ring
/-- **Sylvester's law of inertia**: A nondegenerate real quadratic form is equivalent to a weighted
sum of squares with the weights being ±1, `SignType` version. -/
theorem equivalent_sign_ne_zero_weighted_sum_squared {M : Type*} [AddCommGroup M] [Module ℝ M]
[FiniteDimensional ℝ M] (Q : QuadraticForm ℝ M) (hQ : (associated (R := ℝ) Q).SeparatingLeft) :
∃ w : Fin (FiniteDimensional.finrank ℝ M) → SignType,
(∀ i, w i ≠ 0) ∧ Equivalent Q (weightedSumSquares ℝ fun i ↦ (w i : ℝ)) :=
let ⟨w, ⟨hw₁⟩⟩ := Q.equivalent_weightedSumSquares_units_of_nondegenerate' hQ
⟨sign ∘ ((↑) : ℝˣ → ℝ) ∘ w, fun i => sign_ne_zero.2 (w i).ne_zero,
⟨hw₁.trans (isometryEquivSignWeightedSumSquares (((↑) : ℝˣ → ℝ) ∘ w))⟩⟩
/-- **Sylvester's law of inertia**: A nondegenerate real quadratic form is equivalent to a weighted
sum of squares with the weights being ±1. -/
theorem equivalent_one_neg_one_weighted_sum_squared {M : Type*} [AddCommGroup M] [Module ℝ M]
[FiniteDimensional ℝ M] (Q : QuadraticForm ℝ M) (hQ : (associated (R := ℝ) Q).SeparatingLeft) :
∃ w : Fin (FiniteDimensional.finrank ℝ M) → ℝ,
(∀ i, w i = -1 ∨ w i = 1) ∧ Equivalent Q (weightedSumSquares ℝ w) :=
let ⟨w, hw₀, hw⟩ := Q.equivalent_sign_ne_zero_weighted_sum_squared hQ
⟨(w ·), fun i ↦ by cases hi : w i <;> simp_all, hw⟩
/-- **Sylvester's law of inertia**: A real quadratic form is equivalent to a weighted
sum of squares with the weights being ±1 or 0, `SignType` version. -/
theorem equivalent_signType_weighted_sum_squared {M : Type*} [AddCommGroup M] [Module ℝ M]
[FiniteDimensional ℝ M] (Q : QuadraticForm ℝ M) :
∃ w : Fin (FiniteDimensional.finrank ℝ M) → SignType,
Equivalent Q (weightedSumSquares ℝ fun i ↦ (w i : ℝ)) :=
let ⟨w, ⟨hw₁⟩⟩ := Q.equivalent_weightedSumSquares
⟨sign ∘ w, ⟨hw₁.trans (isometryEquivSignWeightedSumSquares w)⟩⟩
/-- **Sylvester's law of inertia**: A real quadratic form is equivalent to a weighted
sum of squares with the weights being ±1 or 0. -/
theorem equivalent_one_zero_neg_one_weighted_sum_squared {M : Type*} [AddCommGroup M] [Module ℝ M]
[FiniteDimensional ℝ M] (Q : QuadraticForm ℝ M) :
∃ w : Fin (FiniteDimensional.finrank ℝ M) → ℝ,
(∀ i, w i = -1 ∨ w i = 0 ∨ w i = 1) ∧ Equivalent Q (weightedSumSquares ℝ w) :=
let ⟨w, hw⟩ := Q.equivalent_signType_weighted_sum_squared
⟨(w ·), fun i ↦ by cases h : w i <;> simp [h], hw⟩
end QuadraticForm
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.